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,84 @@
# OpenSpec Change: enterprise-api-plugin-notifications
- **Change ID**: enterprise-api-plugin-notifications
- **Package**: `@suaveplan/api-plugin-notifications`
- **Category**: api/comms
- **Target path**: `api/comms/api-plugin-notifications`
- **Status**: PROPOSED
- **Date**: 2026-04-24
- **Reference spec**: `/mnt/s/web/suaveplan/enterprise/api-plugin-notifications.md`
---
## Summary
Deliver `@suaveplan/api-plugin-notifications` on the genesis branch from scratch at enterprise quality. Multi-channel notification delivery plugin: in-app (stored + delivered over SSE), email (via pluggable `EmailProvider`), SMS (via pluggable `SmsProvider`), and push (Web Push). Template rendering via `@suaveplan/templates`. User preference management (per-channel opt-in/out). Delivery tracking with retry via `@suaveplan/retry`. Routes under `/notifications`. Per-table SurrealQL. Typed bus events: `notification:sent`, `notification:failed`, `notification:read`.
---
## 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/templates` (`workspace:^`) | Notification template rendering |
| `@suaveplan/suppression` (`workspace:^`) | Email/SMS suppression |
| `@suaveplan/retry` (`workspace:^`) | Delivery retry |
| `@suaveplan/events` (`workspace:^`) | Event bus |
| `@suaveplan/error` (`workspace:^`) | `NotificationError` hierarchy |
| `@suaveplan/rate-limiter` (`workspace:^`) | Send rate limits |
| `hono` + `@hono/zod-openapi` + `zod` | Routes |
| `@opentelemetry/api` | OTel |
---
## Public API surface
```ts
function createNotificationsPlugin(config?: NotificationsPluginConfig): PluginDescriptor
interface NotificationService {
send(notification: SendNotificationInput): Promise<NotificationRecord>
markRead(notificationId: string, userId: string): Promise<void>
listNotifications(userId: string, query: NotificationQuery): Promise<NotificationRecord[]>
getUnreadCount(userId: string): Promise<number>
updatePreferences(userId: string, prefs: NotificationPreferences): Promise<void>
getPreferences(userId: string): Promise<NotificationPreferences>
}
```
### Error codes
```ts
type NotificationErrorCode =
| "NOTIFICATION_NOT_FOUND"
| "NOTIFICATION_CHANNEL_DISABLED"
| "NOTIFICATION_SUPPRESSED"
| "NOTIFICATION_DELIVERY_FAILED"
| "NOTIFICATION_TEMPLATE_NOT_FOUND"
```
---
## File layout
```text
api/comms/api-plugin-notifications/
package.json tsconfig.json vitest.config.ts
surql/ (notification, notification_preference tables)
src/
index.ts events.ts types/ errors/
adapters/email.port.ts adapters/sms.port.ts adapters/push.port.ts
services/notification/ services/preferences/ services/delivery/
routes/notifications/
tests/integration.test.ts
```
---
## Impact
Prerequisites: `@suaveplan/api`, `@suaveplan/api-plugin-auth`, `@suaveplan/api-plugin-database`, `@suaveplan/templates`, `@suaveplan/suppression`, `@suaveplan/retry`.

View File

@@ -0,0 +1,64 @@
# Tasks: enterprise-api-plugin-notifications
**Change ID**: enterprise-api-plugin-notifications
**Package**: `@suaveplan/api-plugin-notifications`
**Target path**: `api/comms/api-plugin-notifications`
**Prerequisite packages on Verdaccio**: `@suaveplan/api`, `@suaveplan/api-shared`, `@suaveplan/api-plugin-auth`, `@suaveplan/api-plugin-database`, `@suaveplan/templates`, `@suaveplan/suppression`, `@suaveplan/retry`, `@suaveplan/events`, `@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-notifications/`; `package.json` v0.0.0; standard tooling.
- [ ] Types: `NotificationRecord`, `SendNotificationInput`, `NotificationQuery`, `NotificationPreferences`, `NotificationsPluginConfig` (Zod).
- [ ] Errors: 5-code union + metadata + registration. Test + doc.
- [ ] Events: `NotificationEventMap` (notification:sent, notification:failed, notification:read).
---
## 2. SurrealQL
- [ ] `notification.surql`, `notification_preference.surql`. tenantId + userId indexes.
---
## 3. Adapter ports
- [ ] `src/adapters/email.port.ts` — `EmailProvider` interface: `send(to, subject, html, text)`.
- [ ] `src/adapters/sms.port.ts` — `SmsProvider` interface: `send(to, body)`.
- [ ] `src/adapters/push.port.ts` — `PushProvider` interface: `send(subscription, payload)`.
- [ ] Each port: `.test.ts` using a real stub implementation (no mocks).
---
## 4. Services (each `.test.ts` + `.md`)
- [ ] **NotificationService**: `send` — check preferences + suppression list; route to channel adapter(s); persist `NotificationRecord`; emit event.
- [ ] **DeliveryService**: wraps each channel send with `@suaveplan/retry`; on exhausted retries marks record as `failed`; emits `notification:failed`.
- [ ] **PreferencesService**: `getPreferences`, `updatePreferences`.
---
## 5. Routes
- [ ] `GET /notifications` — `requireAuth`; list + pagination.
- [ ] `POST /notifications/:id/read` — `requireAuth`.
- [ ] `GET /notifications/unread-count` — `requireAuth`.
- [ ] `GET/PATCH /notifications/preferences` — `requireAuth`.
- [ ] Route `.test.ts` + `.md`.
---
## 6. Plugin factory + integration tests + publish
- [ ] `createNotificationsPlugin`: `definePlugin`, `dependencies: ["database", "auth"]`, `migrationsPath: "./surql"`.
- [ ] Integration: send in-app notification → mark read → check unread count; suppressed email skipped (real SurrealDB).
- [ ] `bunx turbo lint typecheck test --filter=@suaveplan/api-plugin-notifications` — green; 100% coverage.
- [ ] `bun scripts/publish.ts --package @suaveplan/api-plugin-notifications`.
- [ ] Archive → `openspec/archive/2026-04-24-enterprise-api-plugin-notifications/`.