3.3 KiB
3.3 KiB
Tasks: enterprise-api-plugin-webhook
Change ID: enterprise-api-plugin-webhook
Package: @suaveplan/api-plugin-webhook
Target path: api/comms/api-plugin-webhook
Prerequisite packages on Verdaccio: @suaveplan/api, @suaveplan/api-shared, @suaveplan/api-plugin-auth, @suaveplan/api-plugin-database, @suaveplan/webhook-client, @suaveplan/events, @suaveplan/audit-logging, @suaveplan/rate-limiter, @suaveplan/error
0. Pre-flight (non-negotiable)
- 0.1 Confirm clean working tree (
git statusreports nothing) and no in-flight worktrees with uncommitted work (git worktree listthengit statusin each) - 0.2 If any worktrees exist under
.claude/worktrees/, account for each one: still-active agent, work-pending-merge, or stale-and-prune. Stale worktrees MUST be removed (git worktree remove) before opening a new one — code that has been lost twice on main is the failure mode this guards against. - 0.3 Confirm the package set in
MANIFEST.mdmatchesfind packages -maxdepth 3 -name package.jsoncount. Drift here means a prior change archived without regenerating the manifest.
1. Scaffold + types + errors + events
- Create
api/comms/api-plugin-webhook/;package.jsonv0.0.0; standard tooling. - Types:
WebhookEndpoint,WebhookDelivery,WebhookPluginConfig(Zod). - Errors: 5-code union + metadata + registration. Test + doc.
- Events:
WebhookPluginEventMap(webhook:delivered, webhook:failed, webhook:endpoint:created, webhook:endpoint:paused).
2. SurrealQL
webhook_endpoint.surql(url, secret, eventTypes, paused, tenantId),webhook_delivery.surql(endpointId, payload, status, attempts, responseStatus).
3. Services (each .test.ts + .md)
- EndpointService:
createEndpoint(validate URL via@suaveplan/domain-normalizer),updateEndpoint,deleteEndpoint,getEndpoint,listEndpoints,pauseEndpoint,resumeEndpoint. - DeliveryService:
deliver(endpointId, eventType, payload)— skip if paused; sign via@suaveplan/webhook-client; record delivery attempt; retry on failure; emit events; audit-log. listDeliveries(endpointId),replayDelivery(deliveryId).- Subscribe to all bus events in
onInit; fan out to matching endpoints.
4. Routes
GET/POST /webhooks/endpoints,GET/PATCH/DELETE /webhooks/endpoints/:id—requireAuth.GET /webhooks/endpoints/:id/deliveries—requireAuth.POST /webhooks/endpoints/:id/replay/:deliveryId—requireAuth+ rate-limit.POST /webhooks/endpoints/:id/pause,resume—requireAuth.- Route
.test.ts+.md.
5. Plugin factory + integration tests + publish
createWebhookPlugin:definePlugin,dependencies: ["database", "auth"],migrationsPath: "./surql".onInit: subscribe to bus events; capture subscription disposers foronClose.onClose: detach all bus subscriptions.- Integration: create endpoint → trigger bus event → delivery recorded → replay delivery (real SurrealDB).
bunx turbo lint typecheck test --filter=@suaveplan/api-plugin-webhook— green; 100% coverage.bun scripts/publish.ts --package @suaveplan/api-plugin-webhook.- Archive →
openspec/archive/2026-04-24-enterprise-api-plugin-webhook/.