3.4 KiB
3.4 KiB
Tasks: enterprise-api-plugin-port-tracking
Change ID: enterprise-api-plugin-port-tracking
Package: @suaveplan/api-plugin-port-tracking
Target path: api/logistics/api-plugin-port-tracking
Prerequisite packages on Verdaccio: @suaveplan/api, @suaveplan/api-shared, @suaveplan/api-plugin-auth, @suaveplan/api-plugin-database, @suaveplan/api-plugin-logistics, @suaveplan/datetime, @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-port-tracking/;package.jsonv0.0.0; standard tooling. - Types:
Vessel,VesselPosition,Port,Berth,Arrival,CargoManifest,AisAdapter,PortTrackingConfig(Zod). - Errors: 4-code union + registration. Test + doc.
- Events:
PortTrackingEventMap(port:vessel:arrived, port:vessel:departed, port:ais:update).
2. SurrealQL
vessel.surql,port.surql,berth.surql,arrival.surql,cargo_manifest.surql. tenantId + mmsi indexes.
3. AIS adapter + services (all .test.ts + .md)
src/adapters/ais.port.ts—AisAdapterinterface + stub implementation for tests.- VesselService:
getVessel(mmsi),updatePosition(mmsi, pos),listVessels. Subscribe to AIS updates inonInitvia adapter. - PortService:
getPort(code),listPorts,getArrivals(portCode, dateRange). - BerthService:
allocateBerth,releaseBerth. Conflict detection. - ManifestService:
createManifest,updateManifest,getManifest. Link to logistics shipment. - EtaService:
calculateEta(mmsi, destinationPort)using current position + speed via@suaveplan/datetime.
4. Routes
GET /port-tracking/vessels/:mmsi—requireAuth.GET /port-tracking/ports/:portCode,GET /port-tracking/ports/:portCode/arrivals—requireAuth.GET/POST /port-tracking/manifests,GET /port-tracking/manifests/:id—requireAuth.GET /port-tracking/vessels/:mmsi/eta?destination=—requireAuth.- Route
.test.ts+.md.
5. Plugin factory + integration tests + publish
createPortTrackingPlugin(aisAdapter?, config?):definePlugin,dependencies: ["database", "auth"],migrationsPath: "./surql".onInit: subscribe to AIS adapter updates; capture disposers foronClose.- Integration: vessel position update → arrival recorded → manifest linked to shipment (real SurrealDB + stub AIS adapter).
bunx turbo lint typecheck test --filter=@suaveplan/api-plugin-port-tracking— green; 100% coverage.bun scripts/publish.ts --package @suaveplan/api-plugin-port-tracking.- Archive →
openspec/archive/2026-04-24-enterprise-api-plugin-port-tracking/.