# 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 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-gtap/`; `package.json` v0.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` — `SanctionScreenAdapter` interface + stub implementation. - [ ] **LicenseService**: `createLicense`, `getLicense`, `listLicenses`, `expireLicense`. Scheduled expiry check emits `gtap:license:expired`. - [ ] **ScreeningService**: `screenEntity(request)` — calls adapter; persist `SanctionScreeningLog` (immutable); emit `gtap:sanction:hit` if match; audit-log. - [ ] **CertificateService**: `issueCertificate`, `getCertificate`. Emit `gtap: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 for `onClose`). - [ ] 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/`.