3.5 KiB
3.5 KiB
Tasks: enterprise-api-plugin-gtap
Change ID: enterprise-api-plugin-gtap
Package: @suaveplan/api-plugin-gtap
Target path: api/logistics/api-plugin-gtap
Prerequisite packages on Verdaccio: @suaveplan/api, @suaveplan/api-shared, @suaveplan/api-plugin-auth, @suaveplan/api-plugin-database, @suaveplan/api-plugin-customs, @suaveplan/audit-logging, @suaveplan/events, @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/logistics/api-plugin-gtap/;package.jsonv0.0.0; standard tooling. - Types:
TradeLicense,SanctionScreeningLog,ScreenRequest,ScreenResult,CertificateOfOrigin,PtaEligibility,AeoStatus,GtapConfig(Zod). - Errors: 5-code union + registration. Test + doc.
- Events:
GtapEventMap(gtap:sanction:hit, gtap:certificate:issued, gtap:license:expired).
2. SurrealQL
trade_license.surql,sanction_screening_log.surql(immutable append-only),certificate_of_origin.surql,aeo_status.surql. tenantId indexes.
3. Adapter + services (all .test.ts + .md)
src/adapters/sanction-screen.port.ts—SanctionScreenAdapterinterface + stub implementation.- LicenseService:
createLicense,getLicense,listLicenses,expireLicense. Scheduled expiry check emitsgtap:license:expired. - ScreeningService:
screenEntity(request)— calls adapter; persistSanctionScreeningLog(immutable); emitgtap:sanction:hitif match; audit-log. - CertificateService:
issueCertificate,getCertificate. Emitgtap:certificate:issued. - PtaService:
checkEligibility(hsCode, originCountry, destinationCountry)— check preferential trade agreements. - AeoService:
getAeoStatus(entityId),updateAeoStatus.
4. Routes
GET/POST /gtap/licenses,PATCH /gtap/licenses/:id—requireAuth+requireRole("TRADE_COMPLIANCE").POST /gtap/screen—requireAuth+ audit (every sanction screen is logged).GET/POST /gtap/certificates—requireAuth.GET /gtap/pta-eligibility—requireAuth.GET /gtap/aeo-status/:entityId—requireAuth.- Route
.test.ts+.md.
5. Plugin factory + integration tests + publish
createGtapPlugin:definePlugin,dependencies: ["database", "auth"],migrationsPath: "./surql".onInit: start license expiry scheduler (disposer foronClose).- Integration: create license → screen entity (sanction hit) → issue certificate → PTA check (real SurrealDB + stub adapter).
bunx turbo lint typecheck test --filter=@suaveplan/api-plugin-gtap— green; 100% coverage.bun scripts/publish.ts --package @suaveplan/api-plugin-gtap.- Archive →
openspec/archive/2026-04-24-enterprise-api-plugin-gtap/.