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,77 @@
# OpenSpec Change: enterprise-api-plugin-gtap
- **Change ID**: enterprise-api-plugin-gtap
- **Package**: `@suaveplan/api-plugin-gtap`
- **Category**: api/logistics
- **Target path**: `api/logistics/api-plugin-gtap`
- **Status**: PROPOSED
- **Date**: 2026-04-24
- **Reference spec**: `/mnt/s/web/suaveplan/enterprise/api-plugin-gtap.md`
---
## Summary
Deliver `@suaveplan/api-plugin-gtap` on the genesis branch from scratch at enterprise quality. Global Trade Automation Platform (GTAP) integration bridge: import/export license management, tariff classification (HS code + origin), sanctioned-party screening (OFAC/EU/UN lists via pluggable `SanctionScreenAdapter`), certificate-of-origin generation, preferential-trade-agreement (PTA) eligibility checking, and AEO (Authorised Economic Operator) status tracking. Routes under `/gtap`. Per-table SurrealQL. Events: `gtap:sanction:hit`, `gtap:certificate:issued`, `gtap:license:expired`.
---
## Available workspace deps on genesis
| Package | Role |
|---|---|
| `@suaveplan/api` (`workspace:^`) | `definePlugin` |
| `@suaveplan/api-shared` (`workspace:^`) | Helpers |
| `@suaveplan/api-plugin-auth` (`workspace:^`) | `requireAuth`, `requireRole` |
| `@suaveplan/api-plugin-database` (`workspace:^`) | SurrealDB |
| `@suaveplan/api-plugin-customs` (`workspace:^`) | HS code reference |
| `@suaveplan/audit-logging` (`workspace:^`) | Sanction hit + license audit |
| `@suaveplan/events` (`workspace:^`) | Event bus |
| `@suaveplan/error` (`workspace:^`) | `GtapError` hierarchy |
| `hono` + `@hono/zod-openapi` + `zod` | Routes |
| `@opentelemetry/api` | OTel |
---
## Public API surface
```ts
function createGtapPlugin(config?: GtapConfig): PluginDescriptor
interface SanctionScreenAdapter { screen(entity: ScreenRequest): Promise<ScreenResult> }
// Routes: /gtap/licenses, /gtap/screen, /gtap/certificates,
// /gtap/pta-eligibility, /gtap/aeo-status
```
### Error codes
```ts
type GtapErrorCode =
| "GTAP_LICENSE_NOT_FOUND"
| "GTAP_LICENSE_EXPIRED"
| "GTAP_SANCTION_HIT"
| "GTAP_CERTIFICATE_NOT_FOUND"
| "GTAP_PTA_NOT_ELIGIBLE"
```
---
## File layout
```text
api/logistics/api-plugin-gtap/
package.json tsconfig.json vitest.config.ts
surql/ (trade_license, sanction_screening_log, certificate_of_origin, aeo_status tables)
src/
index.ts events.ts types/ errors/
adapters/sanction-screen.port.ts
services/license/ services/screening/ services/certificate/
services/pta/ services/aeo/
routes/gtap/
tests/integration.test.ts
```
---
## Impact
Prerequisites: `@suaveplan/api`, `@suaveplan/api-plugin-auth`, `@suaveplan/api-plugin-database`, `@suaveplan/api-plugin-customs`, `@suaveplan/audit-logging`.

View File

@@ -0,0 +1,60 @@
# 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/`.