59 lines
3.5 KiB
Markdown
59 lines
3.5 KiB
Markdown
# Tasks: enterprise-api-plugin-contacts
|
|
|
|
**Change ID**: enterprise-api-plugin-contacts
|
|
**Package**: `@suaveplan/api-plugin-contacts`
|
|
**Target path**: `api/comms/api-plugin-contacts`
|
|
**Prerequisite packages on Verdaccio**: `@suaveplan/api`, `@suaveplan/api-shared`, `@suaveplan/api-plugin-auth`, `@suaveplan/api-plugin-database`, `@suaveplan/dedup`, `@suaveplan/domain-normalizer`, `@suaveplan/suppression`, `@suaveplan/data-masking`, `@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-contacts/`; `package.json` v0.0.0; standard tooling.
|
|
- [ ] Types: `Contact`, `ContactCustomField`, `ContactTag`, `ContactList`, `GdprConsent`, `ContactsPluginConfig` (Zod).
|
|
- [ ] Errors: 5-code union + metadata + registration. Test + doc.
|
|
- [ ] Events: `ContactsEventMap` (contacts:created, contacts:updated, contacts:merged, contacts:deleted).
|
|
|
|
---
|
|
|
|
## 2. SurrealQL
|
|
|
|
- [ ] `contact.surql`, `contact_custom_field.surql`, `contact_tag.surql`, `contact_list.surql`, `contact_list_member.surql`, `gdpr_consent.surql`. tenantId indexes; email unique index per tenant.
|
|
|
|
---
|
|
|
|
## 3. Services (each `.test.ts` + `.md`)
|
|
|
|
- [ ] **ContactService**: `createContact` (email normalised via `@suaveplan/domain-normalizer`), `updateContact`, `deleteContact`, `getContact`, `listContacts` (filterable by tag/list/suppression status).
|
|
- [ ] **ListService**: `createList`, `updateList`, `deleteList`, `addContactToList`, `removeContactFromList`, `listLists`.
|
|
- [ ] **ImportService**: parse CSV; normalise emails; check dedup via `@suaveplan/dedup`; bulk upsert; return import summary.
|
|
- [ ] **ExportService**: query contacts; mask PII fields via `@suaveplan/data-masking`; export to CSV.
|
|
- [ ] **DeduplicationService**: `findDuplicates(contactId)`, `mergeContacts(sourceId, targetId)`. Emit `contacts:merged`; update suppression records.
|
|
|
|
---
|
|
|
|
## 4. Routes
|
|
|
|
- [ ] `GET/POST /contacts`, `GET/PATCH/DELETE /contacts/:id` — `requireAuth`.
|
|
- [ ] `POST /contacts/import` — `requireAuth` + rate-limit.
|
|
- [ ] `GET /contacts/export` — `requireAuth`.
|
|
- [ ] `POST /contacts/:id/suppress`, `DELETE /contacts/:id/suppress` — `requireAuth` + audit.
|
|
- [ ] `GET/POST /contacts/lists`, `PATCH/DELETE /contacts/lists/:id` — `requireAuth`.
|
|
- [ ] Route `.test.ts` + `.md`.
|
|
|
|
---
|
|
|
|
## 5. Plugin factory + integration tests + publish
|
|
|
|
- [ ] `createContactsPlugin`: `definePlugin`, `dependencies: ["database", "auth"]`, `migrationsPath: "./surql"`.
|
|
- [ ] Integration: create contacts → import CSV → dedup merge → export masked CSV (real SurrealDB).
|
|
- [ ] `bunx turbo lint typecheck test --filter=@suaveplan/api-plugin-contacts` — green; 100% coverage.
|
|
- [ ] `bun scripts/publish.ts --package @suaveplan/api-plugin-contacts`.
|
|
- [ ] Archive → `openspec/archive/2026-04-24-enterprise-api-plugin-contacts/`.
|