Initial Commit

This commit is contained in:
2026-05-27 23:29:53 +01:00
commit fbc70f96e6
10000 changed files with 1102152 additions and 0 deletions

View File

@@ -0,0 +1,77 @@
# OpenSpec Change: enterprise-api-plugin-webhook
- **Change ID**: enterprise-api-plugin-webhook
- **Package**: `@suaveplan/api-plugin-webhook`
- **Category**: api/comms
- **Target path**: `api/comms/api-plugin-webhook`
- **Status**: PROPOSED
- **Date**: 2026-04-24
- **Reference spec**: `/mnt/s/web/suaveplan/enterprise/api-plugin-webhook.md`
---
## Summary
Deliver `@suaveplan/api-plugin-webhook` on the genesis branch from scratch at enterprise quality. Outbound webhook management plugin: endpoint CRUD (URL + secret + subscribed event types), delivery engine via `@suaveplan/webhook-client` (HMAC-SHA256 signing + retry), delivery log, manual replay, pause/resume per endpoint, and fan-out subscriptions. Routes under `/webhooks`. Per-table SurrealQL. Typed bus events: `webhook:delivered`, `webhook:failed`, `webhook:endpoint:created`.
---
## Available workspace deps on genesis
| Package | Role |
|---|---|
| `@suaveplan/api` (`workspace:^`) | `definePlugin` |
| `@suaveplan/api-shared` (`workspace:^`) | Helpers |
| `@suaveplan/api-plugin-auth` (`workspace:^`) | `requireAuth` |
| `@suaveplan/api-plugin-database` (`workspace:^`) | SurrealDB |
| `@suaveplan/webhook-client` (`workspace:^`) | HMAC signing + delivery |
| `@suaveplan/events` (`workspace:^`) | Bus subscriptions |
| `@suaveplan/error` (`workspace:^`) | `WebhookPluginError` hierarchy |
| `@suaveplan/audit-logging` (`workspace:^`) | Delivery audit |
| `@suaveplan/rate-limiter` (`workspace:^`) | Rate limits |
| `hono` + `@hono/zod-openapi` + `zod` | Routes |
| `@opentelemetry/api` | OTel |
---
## Public API surface
```ts
function createWebhookPlugin(config?: WebhookPluginConfig): PluginDescriptor
// Services: EndpointService, DeliveryService
// Routes: /webhooks/endpoints, /webhooks/endpoints/:id,
// /webhooks/endpoints/:id/deliveries, /webhooks/endpoints/:id/replay/:deliveryId,
// /webhooks/endpoints/:id/pause, /webhooks/endpoints/:id/resume
```
### Error codes
```ts
type WebhookPluginErrorCode =
| "WEBHOOK_ENDPOINT_NOT_FOUND"
| "WEBHOOK_DELIVERY_NOT_FOUND"
| "WEBHOOK_ENDPOINT_PAUSED"
| "WEBHOOK_INVALID_URL"
| "WEBHOOK_DELIVERY_FAILED"
```
---
## File layout
```text
api/comms/api-plugin-webhook/
package.json tsconfig.json vitest.config.ts
surql/ (webhook_endpoint, webhook_delivery tables)
src/
index.ts events.ts types/ errors/
services/endpoint/ services/delivery/
routes/webhooks/
tests/integration.test.ts
```
---
## Impact
Prerequisites: `@suaveplan/api`, `@suaveplan/api-plugin-auth`, `@suaveplan/api-plugin-database`, `@suaveplan/webhook-client`, `@suaveplan/events`, `@suaveplan/audit-logging`.

View File

@@ -0,0 +1,58 @@
# 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 status` reports nothing) and no in-flight worktrees with uncommitted work (`git worktree list` then `git status` in 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.md` matches `find packages -maxdepth 3 -name package.json` count. Drift here means a prior change archived without regenerating the manifest.
## 1. Scaffold + types + errors + events
- [ ] Create `api/comms/api-plugin-webhook/`; `package.json` v0.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 for `onClose`.
- [ ] `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/`.