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,80 @@
# OpenSpec Change: enterprise-api-plugin-port-tracking
- **Change ID**: enterprise-api-plugin-port-tracking
- **Package**: `@suaveplan/api-plugin-port-tracking`
- **Category**: api/logistics
- **Target path**: `api/logistics/api-plugin-port-tracking`
- **Status**: PROPOSED
- **Date**: 2026-04-24
- **Reference spec**: `/mnt/s/web/suaveplan/enterprise/api-plugin-port-tracking.md`
---
## Summary
Deliver `@suaveplan/api-plugin-port-tracking` on the genesis branch from scratch at enterprise quality. Maritime port and vessel tracking plugin: vessel position (AIS data ingestion via pluggable `AisAdapter`), port arrival/departure tracking, berth scheduling, cargo manifest management, estimated-time-of-arrival (ETA) calculations, and integration with `@suaveplan/api-plugin-logistics` for sea-freight shipment correlation. Routes under `/port-tracking`. Per-table SurrealQL. Events: `port:vessel:arrived`, `port:vessel:departed`, `port:ais:update`.
---
## Available workspace deps on genesis
| Package | Role |
|---|---|
| `@suaveplan/api` (`workspace:^`) | `definePlugin` |
| `@suaveplan/api-shared` (`workspace:^`) | Helpers |
| `@suaveplan/api-plugin-auth` (`workspace:^`) | `requireAuth` |
| `@suaveplan/api-plugin-database` (`workspace:^`) | SurrealDB |
| `@suaveplan/api-plugin-logistics` (`workspace:^`) | Shipment correlation |
| `@suaveplan/datetime` (`workspace:^`) | ETA calculations |
| `@suaveplan/events` (`workspace:^`) | Event bus |
| `@suaveplan/error` (`workspace:^`) | `PortTrackingError` hierarchy |
| `hono` + `@hono/zod-openapi` + `zod` | Routes |
| `@opentelemetry/api` | OTel |
---
## Public API surface
```ts
function createPortTrackingPlugin(aisAdapter?: AisAdapter, config?: PortTrackingConfig): PluginDescriptor
interface AisAdapter {
getVesselPosition(mmsi: string): Promise<VesselPosition>
subscribePositionUpdates(mmsi: string, callback: (pos: VesselPosition) => void): () => void
}
// Routes: GET /port-tracking/vessels/:mmsi, GET /port-tracking/ports/:portCode,
// GET /port-tracking/ports/:portCode/arrivals, GET /port-tracking/manifests/:id
```
### Error codes
```ts
type PortTrackingErrorCode =
| "PORT_VESSEL_NOT_FOUND"
| "PORT_AIS_UNAVAILABLE"
| "PORT_CODE_NOT_FOUND"
| "PORT_BERTH_CONFLICT"
```
---
## File layout
```text
api/logistics/api-plugin-port-tracking/
package.json tsconfig.json vitest.config.ts
surql/ (vessel, port, berth, arrival, cargo_manifest tables)
src/
index.ts events.ts types/ errors/
adapters/ais.port.ts
services/vessel/ services/port/ services/berth/ services/manifest/ services/eta/
routes/port-tracking/
tests/integration.test.ts
```
---
## Impact
Prerequisites: `@suaveplan/api`, `@suaveplan/api-plugin-auth`, `@suaveplan/api-plugin-database`, `@suaveplan/api-plugin-logistics`, `@suaveplan/datetime`.

View File

@@ -0,0 +1,59 @@
# 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 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-port-tracking/`; `package.json` v0.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` — `AisAdapter` interface + stub implementation for tests.
- [ ] **VesselService**: `getVessel(mmsi)`, `updatePosition(mmsi, pos)`, `listVessels`. Subscribe to AIS updates in `onInit` via 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 for `onClose`.
- [ ] 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/`.