Files
2026-05-27 23:29:53 +01:00

3.3 KiB

Tasks: enterprise-api-plugin-customs

Change ID: enterprise-api-plugin-customs Package: @suaveplan/api-plugin-customs Target path: api/logistics/api-plugin-customs Prerequisite packages on Verdaccio: @suaveplan/api, @suaveplan/api-shared, @suaveplan/api-plugin-auth, @suaveplan/api-plugin-database, @suaveplan/api-plugin-logistics, @suaveplan/events, @suaveplan/idempotency, @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/logistics/api-plugin-customs/; package.json v0.0.0, "sideEffects": ["src/events.ts"]; standard tooling.
  • Types: CustomsDeclaration, BorderHold, HsCode, DutyPayment, IntrastatReport, CustomsConfig (Zod — remove stub z.object({})).
  • Errors: 6-code union + registration. Test + doc.
  • Events: CustomsEventMap module augmentation — proper declaration, no as Parameters<...>[0] cast. Covers all 5 event types listed in proposal. Remove the spurious startup event emission from onInit.

2. SurrealQL

  • customs_declaration.surql, border_hold.surql, hs_code.surql (reference data), duty_payment.surql, intrastat_report.surql. tenantId indexes.

3. Services (all .test.ts + .md)

  • DeclarationService: submitDeclaration (link to shipmentId from logistics), getDeclaration, listDeclarations, clearDeclaration, rejectDeclaration. State machine enforcement. Emit events; audit-log.
  • BorderHoldService: placeHold, releaseHold, listHolds. Audit-logged.
  • HsCodeService: lookup(description) — fuzzy search in hs_code reference table; getHsCode(code).
  • DutyService: recordDutyPayment, listDutyPayments(declarationId).
  • IntrastatService: generateReport(period: string) — aggregate trade data for EU Intrastat submission; submitReport.

4. Routes

  • Full route coverage for all 5 service areas.
  • All write routes: requireAuth + idempotency + audit.
  • Route .test.ts + .md.

5. Plugin factory + integration tests + publish

  • createCustomsPlugin: definePlugin, dependencies: ["database", "auth"], migrationsPath: "./surql".
  • onInit does NOT emit any placeholder event on startup.
  • Integration: submit declaration → border hold → release → clear (real SurrealDB).
  • bunx turbo lint typecheck test --filter=@suaveplan/api-plugin-customs — green; 100% coverage.
  • bun scripts/publish.ts --package @suaveplan/api-plugin-customs.
  • Archive → openspec/archive/2026-04-24-enterprise-api-plugin-customs/.