@freighttech/shipment-tracking 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/NOTICE +25 -0
- package/dist/generated/entities/bic_config/index.js +21 -0
- package/dist/generated/entities/bic_config/index.js.map +7 -0
- package/dist/generated/entities/carrier_config/index.js +27 -0
- package/dist/generated/entities/carrier_config/index.js.map +7 -0
- package/dist/generated/entities/location_override/index.js +33 -0
- package/dist/generated/entities/location_override/index.js.map +7 -0
- package/dist/generated/entities/shipment/index.js +73 -0
- package/dist/generated/entities/shipment/index.js.map +7 -0
- package/dist/generated/entities/ships_go_config/index.js +31 -0
- package/dist/generated/entities/ships_go_config/index.js.map +7 -0
- package/dist/generated/entities/tracking_event/index.js +101 -0
- package/dist/generated/entities/tracking_event/index.js.map +7 -0
- package/dist/generated/entities/tracking_job/index.js +47 -0
- package/dist/generated/entities/tracking_job/index.js.map +7 -0
- package/dist/generated/entities/webhook/index.js +25 -0
- package/dist/generated/entities/webhook/index.js.map +7 -0
- package/dist/generated/entities/webhook_delivery/index.js +25 -0
- package/dist/generated/entities/webhook_delivery/index.js.map +7 -0
- package/dist/generated/entities.ids.generated.js +21 -0
- package/dist/generated/entities.ids.generated.js.map +7 -0
- package/dist/index.js +41 -0
- package/dist/index.js.map +7 -0
- package/dist/modules/shipment_tracking/acl.js +22 -0
- package/dist/modules/shipment_tracking/acl.js.map +7 -0
- package/dist/modules/shipment_tracking/api/bic-configs/route.js +176 -0
- package/dist/modules/shipment_tracking/api/bic-configs/route.js.map +7 -0
- package/dist/modules/shipment_tracking/api/bic-configs/test/route.js +95 -0
- package/dist/modules/shipment_tracking/api/bic-configs/test/route.js.map +7 -0
- package/dist/modules/shipment_tracking/api/cargo-events/route.js +93 -0
- package/dist/modules/shipment_tracking/api/cargo-events/route.js.map +7 -0
- package/dist/modules/shipment_tracking/api/carrier-configs/route.js +139 -0
- package/dist/modules/shipment_tracking/api/carrier-configs/route.js.map +7 -0
- package/dist/modules/shipment_tracking/api/dashboard/ships-map/route.js +177 -0
- package/dist/modules/shipment_tracking/api/dashboard/ships-map/route.js.map +7 -0
- package/dist/modules/shipment_tracking/api/location-overrides/route.js +179 -0
- package/dist/modules/shipment_tracking/api/location-overrides/route.js.map +7 -0
- package/dist/modules/shipment_tracking/api/openapi.js +27 -0
- package/dist/modules/shipment_tracking/api/openapi.js.map +7 -0
- package/dist/modules/shipment_tracking/api/shipments/route.js +192 -0
- package/dist/modules/shipment_tracking/api/shipments/route.js.map +7 -0
- package/dist/modules/shipment_tracking/api/shipsgo-configs/route.js +185 -0
- package/dist/modules/shipment_tracking/api/shipsgo-configs/route.js.map +7 -0
- package/dist/modules/shipment_tracking/api/tracking-jobs/route.js +144 -0
- package/dist/modules/shipment_tracking/api/tracking-jobs/route.js.map +7 -0
- package/dist/modules/shipment_tracking/api/tracking-jobs/sync/route.js +107 -0
- package/dist/modules/shipment_tracking/api/tracking-jobs/sync/route.js.map +7 -0
- package/dist/modules/shipment_tracking/api/utils.js +12 -0
- package/dist/modules/shipment_tracking/api/utils.js.map +7 -0
- package/dist/modules/shipment_tracking/api/webhooks/deliveries/route.js +76 -0
- package/dist/modules/shipment_tracking/api/webhooks/deliveries/route.js.map +7 -0
- package/dist/modules/shipment_tracking/api/webhooks/route.js +135 -0
- package/dist/modules/shipment_tracking/api/webhooks/route.js.map +7 -0
- package/dist/modules/shipment_tracking/api/webhooks/test/route.js +71 -0
- package/dist/modules/shipment_tracking/api/webhooks/test/route.js.map +7 -0
- package/dist/modules/shipment_tracking/assets/carriers/cma_cgm.png +0 -0
- package/dist/modules/shipment_tracking/assets/carriers/cosco.png +0 -0
- package/dist/modules/shipment_tracking/assets/carriers/evergreen.png +0 -0
- package/dist/modules/shipment_tracking/assets/carriers/hapag_lloyd.png +0 -0
- package/dist/modules/shipment_tracking/assets/carriers/maersk.png +0 -0
- package/dist/modules/shipment_tracking/assets/carriers/msc.png +0 -0
- package/dist/modules/shipment_tracking/assets/carriers/one.png +0 -0
- package/dist/modules/shipment_tracking/assets/carriers/oocl.png +0 -0
- package/dist/modules/shipment_tracking/assets/carriers/yang_ming.png +0 -0
- package/dist/modules/shipment_tracking/assets/carriers/zim.png +0 -0
- package/dist/modules/shipment_tracking/assets/index.js +52 -0
- package/dist/modules/shipment_tracking/assets/index.js.map +7 -0
- package/dist/modules/shipment_tracking/backend/carrier-configs/page.js +621 -0
- package/dist/modules/shipment_tracking/backend/carrier-configs/page.js.map +7 -0
- package/dist/modules/shipment_tracking/backend/carrier-configs/page.meta.js +19 -0
- package/dist/modules/shipment_tracking/backend/carrier-configs/page.meta.js.map +7 -0
- package/dist/modules/shipment_tracking/backend/location-overrides/page.js +198 -0
- package/dist/modules/shipment_tracking/backend/location-overrides/page.js.map +7 -0
- package/dist/modules/shipment_tracking/backend/location-overrides/page.meta.js +19 -0
- package/dist/modules/shipment_tracking/backend/location-overrides/page.meta.js.map +7 -0
- package/dist/modules/shipment_tracking/backend/shipment-tracking/page.js +279 -0
- package/dist/modules/shipment_tracking/backend/shipment-tracking/page.js.map +7 -0
- package/dist/modules/shipment_tracking/backend/shipment-tracking/page.meta.js +19 -0
- package/dist/modules/shipment_tracking/backend/shipment-tracking/page.meta.js.map +7 -0
- package/dist/modules/shipment_tracking/backend/tracking-jobs/page.js +10 -0
- package/dist/modules/shipment_tracking/backend/tracking-jobs/page.js.map +7 -0
- package/dist/modules/shipment_tracking/backend/tracking-jobs/page.meta.js +19 -0
- package/dist/modules/shipment_tracking/backend/tracking-jobs/page.meta.js.map +7 -0
- package/dist/modules/shipment_tracking/backend/webhooks/page.js +198 -0
- package/dist/modules/shipment_tracking/backend/webhooks/page.js.map +7 -0
- package/dist/modules/shipment_tracking/backend/webhooks/page.meta.js +19 -0
- package/dist/modules/shipment_tracking/backend/webhooks/page.meta.js.map +7 -0
- package/dist/modules/shipment_tracking/ce.js +52 -0
- package/dist/modules/shipment_tracking/ce.js.map +7 -0
- package/dist/modules/shipment_tracking/cli.js +229 -0
- package/dist/modules/shipment_tracking/cli.js.map +7 -0
- package/dist/modules/shipment_tracking/commands/bic-configs.js +66 -0
- package/dist/modules/shipment_tracking/commands/bic-configs.js.map +7 -0
- package/dist/modules/shipment_tracking/commands/carrier-configs.js +65 -0
- package/dist/modules/shipment_tracking/commands/carrier-configs.js.map +7 -0
- package/dist/modules/shipment_tracking/commands/index.js +9 -0
- package/dist/modules/shipment_tracking/commands/index.js.map +7 -0
- package/dist/modules/shipment_tracking/commands/location-overrides.js +93 -0
- package/dist/modules/shipment_tracking/commands/location-overrides.js.map +7 -0
- package/dist/modules/shipment_tracking/commands/shipments.js +200 -0
- package/dist/modules/shipment_tracking/commands/shipments.js.map +7 -0
- package/dist/modules/shipment_tracking/commands/shipsgo-configs.js +75 -0
- package/dist/modules/shipment_tracking/commands/shipsgo-configs.js.map +7 -0
- package/dist/modules/shipment_tracking/commands/tracking-jobs.js +120 -0
- package/dist/modules/shipment_tracking/commands/tracking-jobs.js.map +7 -0
- package/dist/modules/shipment_tracking/commands/tracking.js +140 -0
- package/dist/modules/shipment_tracking/commands/tracking.js.map +7 -0
- package/dist/modules/shipment_tracking/commands/webhooks.js +115 -0
- package/dist/modules/shipment_tracking/commands/webhooks.js.map +7 -0
- package/dist/modules/shipment_tracking/components/CombinedTimestampCell.js +168 -0
- package/dist/modules/shipment_tracking/components/CombinedTimestampCell.js.map +7 -0
- package/dist/modules/shipment_tracking/components/FacilityLocationInput.js +202 -0
- package/dist/modules/shipment_tracking/components/FacilityLocationInput.js.map +7 -0
- package/dist/modules/shipment_tracking/components/LocationOverrideDrawer.js +501 -0
- package/dist/modules/shipment_tracking/components/LocationOverrideDrawer.js.map +7 -0
- package/dist/modules/shipment_tracking/components/ShipmentDetailsDrawer.js +818 -0
- package/dist/modules/shipment_tracking/components/ShipmentDetailsDrawer.js.map +7 -0
- package/dist/modules/shipment_tracking/components/ShipmentDrawer.js +404 -0
- package/dist/modules/shipment_tracking/components/ShipmentDrawer.js.map +7 -0
- package/dist/modules/shipment_tracking/components/ShipsGoConfigSection.js +200 -0
- package/dist/modules/shipment_tracking/components/ShipsGoConfigSection.js.map +7 -0
- package/dist/modules/shipment_tracking/components/TimestampCell.js +108 -0
- package/dist/modules/shipment_tracking/components/TimestampCell.js.map +7 -0
- package/dist/modules/shipment_tracking/components/TrackingJobDrawer.js +343 -0
- package/dist/modules/shipment_tracking/components/TrackingJobDrawer.js.map +7 -0
- package/dist/modules/shipment_tracking/components/VesselTrackingMap.js +496 -0
- package/dist/modules/shipment_tracking/components/VesselTrackingMap.js.map +7 -0
- package/dist/modules/shipment_tracking/components/WebhookDrawer.js +332 -0
- package/dist/modules/shipment_tracking/components/WebhookDrawer.js.map +7 -0
- package/dist/modules/shipment_tracking/data/entities.js +686 -0
- package/dist/modules/shipment_tracking/data/entities.js.map +7 -0
- package/dist/modules/shipment_tracking/data/validators.js +434 -0
- package/dist/modules/shipment_tracking/data/validators.js.map +7 -0
- package/dist/modules/shipment_tracking/di.js +60 -0
- package/dist/modules/shipment_tracking/di.js.map +7 -0
- package/dist/modules/shipment_tracking/encryption.js +12 -0
- package/dist/modules/shipment_tracking/encryption.js.map +7 -0
- package/dist/modules/shipment_tracking/events.js +87 -0
- package/dist/modules/shipment_tracking/events.js.map +7 -0
- package/dist/modules/shipment_tracking/hooks/useVesselTracking.js +137 -0
- package/dist/modules/shipment_tracking/hooks/useVesselTracking.js.map +7 -0
- package/dist/modules/shipment_tracking/i18n/de.json +327 -0
- package/dist/modules/shipment_tracking/i18n/en.json +327 -0
- package/dist/modules/shipment_tracking/i18n/es.json +327 -0
- package/dist/modules/shipment_tracking/i18n/pl.json +327 -0
- package/dist/modules/shipment_tracking/index.js +15 -0
- package/dist/modules/shipment_tracking/index.js.map +7 -0
- package/dist/modules/shipment_tracking/lib/adapters/cma-cgm.js +66 -0
- package/dist/modules/shipment_tracking/lib/adapters/cma-cgm.js.map +7 -0
- package/dist/modules/shipment_tracking/lib/adapters/cosco-types.js +1 -0
- package/dist/modules/shipment_tracking/lib/adapters/cosco-types.js.map +7 -0
- package/dist/modules/shipment_tracking/lib/adapters/cosco.js +236 -0
- package/dist/modules/shipment_tracking/lib/adapters/cosco.js.map +7 -0
- package/dist/modules/shipment_tracking/lib/adapters/evergreen.js +87 -0
- package/dist/modules/shipment_tracking/lib/adapters/evergreen.js.map +7 -0
- package/dist/modules/shipment_tracking/lib/adapters/hapag-lloyd.js +68 -0
- package/dist/modules/shipment_tracking/lib/adapters/hapag-lloyd.js.map +7 -0
- package/dist/modules/shipment_tracking/lib/adapters/index.js +20 -0
- package/dist/modules/shipment_tracking/lib/adapters/index.js.map +7 -0
- package/dist/modules/shipment_tracking/lib/adapters/maersk.js +84 -0
- package/dist/modules/shipment_tracking/lib/adapters/maersk.js.map +7 -0
- package/dist/modules/shipment_tracking/lib/adapters/msc.js +170 -0
- package/dist/modules/shipment_tracking/lib/adapters/msc.js.map +7 -0
- package/dist/modules/shipment_tracking/lib/adapters/zim.js +85 -0
- package/dist/modules/shipment_tracking/lib/adapters/zim.js.map +7 -0
- package/dist/modules/shipment_tracking/lib/audit-helpers.js +20 -0
- package/dist/modules/shipment_tracking/lib/audit-helpers.js.map +7 -0
- package/dist/modules/shipment_tracking/lib/auth/base64url.js +8 -0
- package/dist/modules/shipment_tracking/lib/auth/base64url.js.map +7 -0
- package/dist/modules/shipment_tracking/lib/auth/oauth-client.js +38 -0
- package/dist/modules/shipment_tracking/lib/auth/oauth-client.js.map +7 -0
- package/dist/modules/shipment_tracking/lib/background.js +15 -0
- package/dist/modules/shipment_tracking/lib/background.js.map +7 -0
- package/dist/modules/shipment_tracking/lib/bic-api-client.js +106 -0
- package/dist/modules/shipment_tracking/lib/bic-api-client.js.map +7 -0
- package/dist/modules/shipment_tracking/lib/carrier-adapter.js +17 -0
- package/dist/modules/shipment_tracking/lib/carrier-adapter.js.map +7 -0
- package/dist/modules/shipment_tracking/lib/current-vessel.js +149 -0
- package/dist/modules/shipment_tracking/lib/current-vessel.js.map +7 -0
- package/dist/modules/shipment_tracking/lib/dcsa-event-mapping.js +124 -0
- package/dist/modules/shipment_tracking/lib/dcsa-event-mapping.js.map +7 -0
- package/dist/modules/shipment_tracking/lib/dcsa-event-parser.js +112 -0
- package/dist/modules/shipment_tracking/lib/dcsa-event-parser.js.map +7 -0
- package/dist/modules/shipment_tracking/lib/dcsa-params.js +16 -0
- package/dist/modules/shipment_tracking/lib/dcsa-params.js.map +7 -0
- package/dist/modules/shipment_tracking/lib/empty-return.js +48 -0
- package/dist/modules/shipment_tracking/lib/empty-return.js.map +7 -0
- package/dist/modules/shipment_tracking/lib/location-overrides.js +85 -0
- package/dist/modules/shipment_tracking/lib/location-overrides.js.map +7 -0
- package/dist/modules/shipment_tracking/lib/location-types.js +59 -0
- package/dist/modules/shipment_tracking/lib/location-types.js.map +7 -0
- package/dist/modules/shipment_tracking/lib/logger.js +113 -0
- package/dist/modules/shipment_tracking/lib/logger.js.map +7 -0
- package/dist/modules/shipment_tracking/lib/poi-event-processor.js +183 -0
- package/dist/modules/shipment_tracking/lib/poi-event-processor.js.map +7 -0
- package/dist/modules/shipment_tracking/lib/poi-nats-config.js +52 -0
- package/dist/modules/shipment_tracking/lib/poi-nats-config.js.map +7 -0
- package/dist/modules/shipment_tracking/lib/poi-types.js +43 -0
- package/dist/modules/shipment_tracking/lib/poi-types.js.map +7 -0
- package/dist/modules/shipment_tracking/lib/rate-limiter.js +31 -0
- package/dist/modules/shipment_tracking/lib/rate-limiter.js.map +7 -0
- package/dist/modules/shipment_tracking/lib/route-extraction.js +187 -0
- package/dist/modules/shipment_tracking/lib/route-extraction.js.map +7 -0
- package/dist/modules/shipment_tracking/lib/route-inference.js +106 -0
- package/dist/modules/shipment_tracking/lib/route-inference.js.map +7 -0
- package/dist/modules/shipment_tracking/lib/schedule-generator.js +63 -0
- package/dist/modules/shipment_tracking/lib/schedule-generator.js.map +7 -0
- package/dist/modules/shipment_tracking/lib/shipsgo-client.js +143 -0
- package/dist/modules/shipment_tracking/lib/shipsgo-client.js.map +7 -0
- package/dist/modules/shipment_tracking/lib/shipsgo-mapper.js +204 -0
- package/dist/modules/shipment_tracking/lib/shipsgo-mapper.js.map +7 -0
- package/dist/modules/shipment_tracking/lib/status-machine.js +131 -0
- package/dist/modules/shipment_tracking/lib/status-machine.js.map +7 -0
- package/dist/modules/shipment_tracking/lib/time-extraction.js +41 -0
- package/dist/modules/shipment_tracking/lib/time-extraction.js.map +7 -0
- package/dist/modules/shipment_tracking/lib/timestamp-utils.js +100 -0
- package/dist/modules/shipment_tracking/lib/timestamp-utils.js.map +7 -0
- package/dist/modules/shipment_tracking/lib/vessel-api.js +111 -0
- package/dist/modules/shipment_tracking/lib/vessel-api.js.map +7 -0
- package/dist/modules/shipment_tracking/lib/vessel-cache.js +50 -0
- package/dist/modules/shipment_tracking/lib/vessel-cache.js.map +7 -0
- package/dist/modules/shipment_tracking/lib/vessel-extraction.js +13 -0
- package/dist/modules/shipment_tracking/lib/vessel-extraction.js.map +7 -0
- package/dist/modules/shipment_tracking/lib/webhook-dispatcher.js +62 -0
- package/dist/modules/shipment_tracking/lib/webhook-dispatcher.js.map +7 -0
- package/dist/modules/shipment_tracking/migrations/Migration20260422161208_shipment_tracking.js +48 -0
- package/dist/modules/shipment_tracking/migrations/Migration20260422161208_shipment_tracking.js.map +7 -0
- package/dist/modules/shipment_tracking/migrations/Migration20260529120000_shipment_tracking_poi_region_names.js +15 -0
- package/dist/modules/shipment_tracking/migrations/Migration20260529120000_shipment_tracking_poi_region_names.js.map +7 -0
- package/dist/modules/shipment_tracking/migrations/Migration20260821120000_shipment_tracking_shipsgo.js +47 -0
- package/dist/modules/shipment_tracking/migrations/Migration20260821120000_shipment_tracking_shipsgo.js.map +7 -0
- package/dist/modules/shipment_tracking/notifications.js +145 -0
- package/dist/modules/shipment_tracking/notifications.js.map +7 -0
- package/dist/modules/shipment_tracking/services/carrierRegistry.js +24 -0
- package/dist/modules/shipment_tracking/services/carrierRegistry.js.map +7 -0
- package/dist/modules/shipment_tracking/services/poiNatsService.js +397 -0
- package/dist/modules/shipment_tracking/services/poiNatsService.js.map +7 -0
- package/dist/modules/shipment_tracking/services/shipsGoProvider.js +163 -0
- package/dist/modules/shipment_tracking/services/shipsGoProvider.js.map +7 -0
- package/dist/modules/shipment_tracking/services/trackingService.js +1283 -0
- package/dist/modules/shipment_tracking/services/trackingService.js.map +7 -0
- package/dist/modules/shipment_tracking/services/webhookService.js +263 -0
- package/dist/modules/shipment_tracking/services/webhookService.js.map +7 -0
- package/dist/modules/shipment_tracking/setup.js +72 -0
- package/dist/modules/shipment_tracking/setup.js.map +7 -0
- package/dist/modules/shipment_tracking/subscribers/cargo-event-created.js +60 -0
- package/dist/modules/shipment_tracking/subscribers/cargo-event-created.js.map +7 -0
- package/dist/modules/shipment_tracking/subscribers/dcsa-event-webhook-dispatch.js +58 -0
- package/dist/modules/shipment_tracking/subscribers/dcsa-event-webhook-dispatch.js.map +7 -0
- package/dist/modules/shipment_tracking/subscribers/poi-event-notification.js +82 -0
- package/dist/modules/shipment_tracking/subscribers/poi-event-notification.js.map +7 -0
- package/dist/modules/shipment_tracking/subscribers/poi-event-webhook-dispatch.js +53 -0
- package/dist/modules/shipment_tracking/subscribers/poi-event-webhook-dispatch.js.map +7 -0
- package/dist/modules/shipment_tracking/subscribers/shipment-status-changed.js +28 -0
- package/dist/modules/shipment_tracking/subscribers/shipment-status-changed.js.map +7 -0
- package/dist/modules/shipment_tracking/subscribers/terminal-event-ingest.js +67 -0
- package/dist/modules/shipment_tracking/subscribers/terminal-event-ingest.js.map +7 -0
- package/dist/modules/shipment_tracking/subscribers/tracking-job-initial-poll.js +30 -0
- package/dist/modules/shipment_tracking/subscribers/tracking-job-initial-poll.js.map +7 -0
- package/dist/modules/shipment_tracking/subscribers/tracking-job-webhook-dispatch.js +19 -0
- package/dist/modules/shipment_tracking/subscribers/tracking-job-webhook-dispatch.js.map +7 -0
- package/dist/modules/shipment_tracking/tables/index.js +6 -0
- package/dist/modules/shipment_tracking/tables/index.js.map +7 -0
- package/dist/modules/shipment_tracking/tables/tracking_job/table.client.js +284 -0
- package/dist/modules/shipment_tracking/tables/tracking_job/table.client.js.map +7 -0
- package/dist/modules/shipment_tracking/tables/tracking_job/table.js +36 -0
- package/dist/modules/shipment_tracking/tables/tracking_job/table.js.map +7 -0
- package/dist/modules/shipment_tracking/widgets/dashboard/ships-map/config.js +25 -0
- package/dist/modules/shipment_tracking/widgets/dashboard/ships-map/config.js.map +7 -0
- package/dist/modules/shipment_tracking/widgets/dashboard/ships-map/widget.client.js +355 -0
- package/dist/modules/shipment_tracking/widgets/dashboard/ships-map/widget.client.js.map +7 -0
- package/dist/modules/shipment_tracking/widgets/dashboard/ships-map/widget.js +26 -0
- package/dist/modules/shipment_tracking/widgets/dashboard/ships-map/widget.js.map +7 -0
- package/dist/types/assets.d.js +1 -0
- package/dist/types/assets.d.js.map +7 -0
- package/generated/entities/bic_config/index.ts +20 -0
- package/generated/entities/carrier_config/index.ts +23 -0
- package/generated/entities/location_override/index.ts +26 -0
- package/generated/entities/shipment/index.ts +46 -0
- package/generated/entities/ships_go_config/index.ts +25 -0
- package/generated/entities/tracking_event/index.ts +60 -0
- package/generated/entities/tracking_job/index.ts +33 -0
- package/generated/entities/webhook/index.ts +22 -0
- package/generated/entities/webhook_delivery/index.ts +22 -0
- package/generated/entities.ids.generated.ts +47 -0
- package/package.json +81 -0
- package/src/index.ts +39 -0
- package/src/modules/shipment_tracking/__integration__/TC-TRACK-410-shipsgo-config-api.spec.ts +133 -0
- package/src/modules/shipment_tracking/__integration__/meta.ts +4 -0
- package/src/modules/shipment_tracking/__tests__/empty-return-stop.test.ts +231 -0
- package/src/modules/shipment_tracking/__tests__/fixtures/hapag-lloyd-transship-container.json +702 -0
- package/src/modules/shipment_tracking/__tests__/fixtures/index.ts +434 -0
- package/src/modules/shipment_tracking/__tests__/fixtures/maersk-multi-transship-completed.json +1518 -0
- package/src/modules/shipment_tracking/__tests__/fixtures/maersk-transship-intransit.json +558 -0
- package/src/modules/shipment_tracking/__tests__/fixtures/msc-direct.json +222 -0
- package/src/modules/shipment_tracking/__tests__/fixtures/msc-multi-transship-completed.json +974 -0
- package/src/modules/shipment_tracking/__tests__/fixtures/msc-multi.json +4846 -0
- package/src/modules/shipment_tracking/__tests__/fixtures/msc-transship.json +409 -0
- package/src/modules/shipment_tracking/__tests__/fixtures/poi-events.json +240 -0
- package/src/modules/shipment_tracking/__tests__/fixtures/synthetic/index.ts +138 -0
- package/src/modules/shipment_tracking/__tests__/fixtures/synthetic-eta-updates.json +288 -0
- package/src/modules/shipment_tracking/__tests__/fixtures/synthetic-route-inference.json +201 -0
- package/src/modules/shipment_tracking/__tests__/fixtures/synthetic-voyage-progression.json +410 -0
- package/src/modules/shipment_tracking/__tests__/shipsgo-air-mapper.test.ts +157 -0
- package/src/modules/shipment_tracking/__tests__/shipsgo-client.test.ts +155 -0
- package/src/modules/shipment_tracking/__tests__/shipsgo-mapper.test.ts +201 -0
- package/src/modules/shipment_tracking/__tests__/shipsgo-poll.test.ts +357 -0
- package/src/modules/shipment_tracking/__tests__/shipsgo-provider.test.ts +364 -0
- package/src/modules/shipment_tracking/__tests__/trackingService.integration.test.ts +2248 -0
- package/src/modules/shipment_tracking/__tests__/webhookPayload.test.ts +151 -0
- package/src/modules/shipment_tracking/acl.ts +18 -0
- package/src/modules/shipment_tracking/api/bic-configs/route.ts +206 -0
- package/src/modules/shipment_tracking/api/bic-configs/test/route.ts +108 -0
- package/src/modules/shipment_tracking/api/cargo-events/route.ts +101 -0
- package/src/modules/shipment_tracking/api/carrier-configs/route.ts +142 -0
- package/src/modules/shipment_tracking/api/dashboard/ships-map/route.ts +246 -0
- package/src/modules/shipment_tracking/api/location-overrides/route.ts +185 -0
- package/src/modules/shipment_tracking/api/openapi.ts +28 -0
- package/src/modules/shipment_tracking/api/shipments/route.ts +197 -0
- package/src/modules/shipment_tracking/api/shipsgo-configs/route.ts +215 -0
- package/src/modules/shipment_tracking/api/tracking-jobs/route.ts +149 -0
- package/src/modules/shipment_tracking/api/tracking-jobs/sync/route.ts +116 -0
- package/src/modules/shipment_tracking/api/utils.ts +10 -0
- package/src/modules/shipment_tracking/api/webhooks/deliveries/route.ts +82 -0
- package/src/modules/shipment_tracking/api/webhooks/route.ts +138 -0
- package/src/modules/shipment_tracking/api/webhooks/test/route.ts +84 -0
- package/src/modules/shipment_tracking/assets/carriers/cma_cgm.png +0 -0
- package/src/modules/shipment_tracking/assets/carriers/cosco.png +0 -0
- package/src/modules/shipment_tracking/assets/carriers/evergreen.png +0 -0
- package/src/modules/shipment_tracking/assets/carriers/hapag_lloyd.png +0 -0
- package/src/modules/shipment_tracking/assets/carriers/maersk.png +0 -0
- package/src/modules/shipment_tracking/assets/carriers/msc.png +0 -0
- package/src/modules/shipment_tracking/assets/carriers/one.png +0 -0
- package/src/modules/shipment_tracking/assets/carriers/oocl.png +0 -0
- package/src/modules/shipment_tracking/assets/carriers/yang_ming.png +0 -0
- package/src/modules/shipment_tracking/assets/carriers/zim.png +0 -0
- package/src/modules/shipment_tracking/assets/index.ts +66 -0
- package/src/modules/shipment_tracking/backend/carrier-configs/page.meta.ts +16 -0
- package/src/modules/shipment_tracking/backend/carrier-configs/page.tsx +782 -0
- package/src/modules/shipment_tracking/backend/location-overrides/page.meta.ts +16 -0
- package/src/modules/shipment_tracking/backend/location-overrides/page.tsx +241 -0
- package/src/modules/shipment_tracking/backend/shipment-tracking/page.meta.ts +16 -0
- package/src/modules/shipment_tracking/backend/shipment-tracking/page.tsx +340 -0
- package/src/modules/shipment_tracking/backend/tracking-jobs/page.meta.ts +16 -0
- package/src/modules/shipment_tracking/backend/tracking-jobs/page.tsx +16 -0
- package/src/modules/shipment_tracking/backend/webhooks/page.meta.ts +16 -0
- package/src/modules/shipment_tracking/backend/webhooks/page.tsx +228 -0
- package/src/modules/shipment_tracking/ce.ts +48 -0
- package/src/modules/shipment_tracking/cli.ts +321 -0
- package/src/modules/shipment_tracking/commands/bic-configs.ts +94 -0
- package/src/modules/shipment_tracking/commands/carrier-configs.ts +89 -0
- package/src/modules/shipment_tracking/commands/index.ts +8 -0
- package/src/modules/shipment_tracking/commands/location-overrides.ts +119 -0
- package/src/modules/shipment_tracking/commands/shipments.ts +247 -0
- package/src/modules/shipment_tracking/commands/shipsgo-configs.ts +101 -0
- package/src/modules/shipment_tracking/commands/tracking-jobs.ts +158 -0
- package/src/modules/shipment_tracking/commands/tracking.ts +230 -0
- package/src/modules/shipment_tracking/commands/webhooks.ts +159 -0
- package/src/modules/shipment_tracking/components/CombinedTimestampCell.tsx +236 -0
- package/src/modules/shipment_tracking/components/FacilityLocationInput.tsx +235 -0
- package/src/modules/shipment_tracking/components/LocationOverrideDrawer.tsx +586 -0
- package/src/modules/shipment_tracking/components/ShipmentDetailsDrawer.tsx +1364 -0
- package/src/modules/shipment_tracking/components/ShipmentDrawer.tsx +498 -0
- package/src/modules/shipment_tracking/components/ShipsGoConfigSection.tsx +266 -0
- package/src/modules/shipment_tracking/components/TimestampCell.tsx +146 -0
- package/src/modules/shipment_tracking/components/TrackingJobDrawer.tsx +467 -0
- package/src/modules/shipment_tracking/components/VesselTrackingMap.tsx +761 -0
- package/src/modules/shipment_tracking/components/WebhookDrawer.tsx +434 -0
- package/src/modules/shipment_tracking/data/entities.ts +748 -0
- package/src/modules/shipment_tracking/data/validators.ts +523 -0
- package/src/modules/shipment_tracking/di.ts +73 -0
- package/src/modules/shipment_tracking/encryption.ts +17 -0
- package/src/modules/shipment_tracking/events.ts +122 -0
- package/src/modules/shipment_tracking/hooks/useVesselTracking.ts +297 -0
- package/src/modules/shipment_tracking/i18n/de.json +327 -0
- package/src/modules/shipment_tracking/i18n/en.json +327 -0
- package/src/modules/shipment_tracking/i18n/es.json +327 -0
- package/src/modules/shipment_tracking/i18n/pl.json +327 -0
- package/src/modules/shipment_tracking/index.ts +13 -0
- package/src/modules/shipment_tracking/lib/__tests__/dcsa-event-mapping.test.ts +385 -0
- package/src/modules/shipment_tracking/lib/__tests__/dcsa-event-parser.test.ts +398 -0
- package/src/modules/shipment_tracking/lib/__tests__/empty-return.test.ts +174 -0
- package/src/modules/shipment_tracking/lib/__tests__/poi-event-processor.test.ts +699 -0
- package/src/modules/shipment_tracking/lib/__tests__/route-inference.test.ts +402 -0
- package/src/modules/shipment_tracking/lib/__tests__/status-machine.test.ts +447 -0
- package/src/modules/shipment_tracking/lib/__tests__/time-extraction.test.ts +331 -0
- package/src/modules/shipment_tracking/lib/__tests__/timestamp-utils.test.ts +260 -0
- package/src/modules/shipment_tracking/lib/__tests__/vessel-api.test.ts +125 -0
- package/src/modules/shipment_tracking/lib/__tests__/vessel-extraction.test.ts +108 -0
- package/src/modules/shipment_tracking/lib/adapters/cma-cgm.ts +84 -0
- package/src/modules/shipment_tracking/lib/adapters/cosco-types.ts +145 -0
- package/src/modules/shipment_tracking/lib/adapters/cosco.ts +314 -0
- package/src/modules/shipment_tracking/lib/adapters/evergreen.ts +107 -0
- package/src/modules/shipment_tracking/lib/adapters/hapag-lloyd.ts +88 -0
- package/src/modules/shipment_tracking/lib/adapters/index.ts +18 -0
- package/src/modules/shipment_tracking/lib/adapters/maersk.ts +104 -0
- package/src/modules/shipment_tracking/lib/adapters/msc.ts +223 -0
- package/src/modules/shipment_tracking/lib/adapters/zim.ts +106 -0
- package/src/modules/shipment_tracking/lib/audit-helpers.ts +29 -0
- package/src/modules/shipment_tracking/lib/auth/base64url.ts +4 -0
- package/src/modules/shipment_tracking/lib/auth/oauth-client.ts +53 -0
- package/src/modules/shipment_tracking/lib/background.ts +24 -0
- package/src/modules/shipment_tracking/lib/bic-api-client.ts +199 -0
- package/src/modules/shipment_tracking/lib/carrier-adapter.ts +136 -0
- package/src/modules/shipment_tracking/lib/current-vessel.ts +274 -0
- package/src/modules/shipment_tracking/lib/dcsa-event-mapping.ts +202 -0
- package/src/modules/shipment_tracking/lib/dcsa-event-parser.ts +163 -0
- package/src/modules/shipment_tracking/lib/dcsa-params.ts +14 -0
- package/src/modules/shipment_tracking/lib/empty-return.ts +122 -0
- package/src/modules/shipment_tracking/lib/location-overrides.ts +150 -0
- package/src/modules/shipment_tracking/lib/location-types.ts +154 -0
- package/src/modules/shipment_tracking/lib/logger.ts +195 -0
- package/src/modules/shipment_tracking/lib/poi-event-processor.ts +302 -0
- package/src/modules/shipment_tracking/lib/poi-nats-config.ts +134 -0
- package/src/modules/shipment_tracking/lib/poi-types.ts +198 -0
- package/src/modules/shipment_tracking/lib/rate-limiter.ts +58 -0
- package/src/modules/shipment_tracking/lib/route-extraction.ts +439 -0
- package/src/modules/shipment_tracking/lib/route-inference.ts +238 -0
- package/src/modules/shipment_tracking/lib/schedule-generator.ts +92 -0
- package/src/modules/shipment_tracking/lib/shipsgo-client.ts +350 -0
- package/src/modules/shipment_tracking/lib/shipsgo-mapper.ts +296 -0
- package/src/modules/shipment_tracking/lib/status-machine.ts +230 -0
- package/src/modules/shipment_tracking/lib/time-extraction.ts +85 -0
- package/src/modules/shipment_tracking/lib/timestamp-utils.ts +244 -0
- package/src/modules/shipment_tracking/lib/vessel-api.ts +299 -0
- package/src/modules/shipment_tracking/lib/vessel-cache.ts +102 -0
- package/src/modules/shipment_tracking/lib/vessel-extraction.ts +39 -0
- package/src/modules/shipment_tracking/lib/webhook-dispatcher.ts +93 -0
- package/src/modules/shipment_tracking/migrations/.snapshot-open-mercato.json +2914 -0
- package/src/modules/shipment_tracking/migrations/Migration20260422161208_shipment_tracking.ts +60 -0
- package/src/modules/shipment_tracking/migrations/Migration20260529120000_shipment_tracking_poi_region_names.ts +22 -0
- package/src/modules/shipment_tracking/migrations/Migration20260821120000_shipment_tracking_shipsgo.ts +65 -0
- package/src/modules/shipment_tracking/notifications.ts +151 -0
- package/src/modules/shipment_tracking/services/carrierRegistry.ts +29 -0
- package/src/modules/shipment_tracking/services/poiNatsService.ts +526 -0
- package/src/modules/shipment_tracking/services/shipsGoProvider.ts +231 -0
- package/src/modules/shipment_tracking/services/trackingService.ts +1777 -0
- package/src/modules/shipment_tracking/services/webhookService.ts +347 -0
- package/src/modules/shipment_tracking/setup.ts +99 -0
- package/src/modules/shipment_tracking/subscribers/__tests__/terminal-event-ingest.test.ts +141 -0
- package/src/modules/shipment_tracking/subscribers/cargo-event-created.ts +115 -0
- package/src/modules/shipment_tracking/subscribers/dcsa-event-webhook-dispatch.ts +115 -0
- package/src/modules/shipment_tracking/subscribers/poi-event-notification.ts +144 -0
- package/src/modules/shipment_tracking/subscribers/poi-event-webhook-dispatch.ts +94 -0
- package/src/modules/shipment_tracking/subscribers/shipment-status-changed.ts +41 -0
- package/src/modules/shipment_tracking/subscribers/terminal-event-ingest.ts +109 -0
- package/src/modules/shipment_tracking/subscribers/tracking-job-initial-poll.ts +53 -0
- package/src/modules/shipment_tracking/subscribers/tracking-job-webhook-dispatch.ts +50 -0
- package/src/modules/shipment_tracking/tables/index.ts +4 -0
- package/src/modules/shipment_tracking/tables/tracking_job/table.client.tsx +337 -0
- package/src/modules/shipment_tracking/tables/tracking_job/table.ts +34 -0
- package/src/modules/shipment_tracking/widgets/dashboard/ships-map/config.ts +32 -0
- package/src/modules/shipment_tracking/widgets/dashboard/ships-map/widget.client.tsx +448 -0
- package/src/modules/shipment_tracking/widgets/dashboard/ships-map/widget.ts +25 -0
- package/src/types/assets.d.ts +5 -0
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { createModuleEvents } from '@open-mercato/shared/modules/events'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Shipment Tracking Module Events
|
|
5
|
+
*
|
|
6
|
+
* Event Emission Granularity:
|
|
7
|
+
* ───────────────────────────────────────────────────────────────────────────────
|
|
8
|
+
* PER SHIPMENT (Container):
|
|
9
|
+
* - Shipment CRUD/Lifecycle events are emitted once per shipment entity.
|
|
10
|
+
* - A booking with 5 containers will trigger 5 events.
|
|
11
|
+
* - Includes: shipment.*, transport.*, equipment.*, poi.*
|
|
12
|
+
*
|
|
13
|
+
* PER TRACKING JOB (BOL/Booking):
|
|
14
|
+
* - Tracking job events are emitted once per tracking job, regardless of
|
|
15
|
+
* how many containers are in the booking.
|
|
16
|
+
* - Includes: tracking_job.*
|
|
17
|
+
*
|
|
18
|
+
* PER TRACKING EVENT (Raw Event Record):
|
|
19
|
+
* - tracking_event.created is emitted per raw event record from carriers.
|
|
20
|
+
* - Contains equipmentReference for the specific container.
|
|
21
|
+
*
|
|
22
|
+
* NOTE: For notifications, POI events emit per-shipment which can cause
|
|
23
|
+
* duplicate notifications for multi-container bookings. The notification
|
|
24
|
+
* subscriber should deduplicate by bookingNumber/bolNumber.
|
|
25
|
+
* ───────────────────────────────────────────────────────────────────────────────
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
const events = [
|
|
29
|
+
// ─── Shipment CRUD ─────────────────────────────────────────────
|
|
30
|
+
// Emitted PER SHIPMENT (container) - booking with N containers = N events
|
|
31
|
+
{ id: 'shipment_tracking.shipment.created', label: 'Shipment Created', entity: 'shipment', category: 'crud' },
|
|
32
|
+
{ id: 'shipment_tracking.shipment.updated', label: 'Shipment Updated', entity: 'shipment', category: 'crud' },
|
|
33
|
+
{ id: 'shipment_tracking.shipment.deleted', label: 'Shipment Deleted', entity: 'shipment', category: 'crud' },
|
|
34
|
+
|
|
35
|
+
// ─── Shipment Lifecycle ────────────────────────────────────────
|
|
36
|
+
// Emitted PER SHIPMENT (container) - booking with N containers = N events
|
|
37
|
+
{ id: 'shipment_tracking.shipment.status_changed', label: 'Shipment Status Changed', entity: 'shipment', category: 'lifecycle' },
|
|
38
|
+
{ id: 'shipment_tracking.shipment.booked', label: 'Shipment Booked', entity: 'shipment', category: 'lifecycle' },
|
|
39
|
+
{ id: 'shipment_tracking.shipment.pre_arrival', label: 'Shipment Pre-Arrival', entity: 'shipment', category: 'lifecycle' },
|
|
40
|
+
{ id: 'shipment_tracking.shipment.delivered', label: 'Shipment Delivered', entity: 'shipment', category: 'lifecycle' },
|
|
41
|
+
|
|
42
|
+
// ─── Transport Events (DCSA TRANSPORT) ─────────────────────────
|
|
43
|
+
// Emitted PER SHIPMENT when shipment ETA/ETD is updated
|
|
44
|
+
// Vessel/transport movement events per DCSA T&T standard
|
|
45
|
+
{ id: 'shipment_tracking.transport.departed', label: 'Transport Departed', entity: 'shipment', category: 'lifecycle' },
|
|
46
|
+
{ id: 'shipment_tracking.transport.arrived', label: 'Transport Arrived', entity: 'shipment', category: 'lifecycle' },
|
|
47
|
+
{ id: 'shipment_tracking.transport.eta_updated', label: 'ETA Updated', entity: 'shipment', category: 'lifecycle' },
|
|
48
|
+
{ id: 'shipment_tracking.transport.etd_updated', label: 'ETD Updated', entity: 'shipment', category: 'lifecycle' },
|
|
49
|
+
{ id: 'shipment_tracking.transport.omitted', label: 'Port Omitted', entity: 'shipment', category: 'lifecycle' },
|
|
50
|
+
|
|
51
|
+
// ─── Equipment Events (DCSA EQUIPMENT) ─────────────────────────
|
|
52
|
+
// Emitted PER CONTAINER - tied to specific equipmentReference
|
|
53
|
+
// Container handling events per DCSA T&T standard
|
|
54
|
+
{ id: 'shipment_tracking.equipment.loaded', label: 'Container Loaded', entity: 'tracking_event', category: 'lifecycle' },
|
|
55
|
+
{ id: 'shipment_tracking.equipment.discharged', label: 'Container Discharged', entity: 'tracking_event', category: 'lifecycle' },
|
|
56
|
+
{ id: 'shipment_tracking.equipment.gate_in', label: 'Container Gate In', entity: 'tracking_event', category: 'lifecycle' },
|
|
57
|
+
{ id: 'shipment_tracking.equipment.gate_out', label: 'Container Gate Out', entity: 'tracking_event', category: 'lifecycle' },
|
|
58
|
+
{ id: 'shipment_tracking.equipment.available_pickup', label: 'Available for Pickup', entity: 'tracking_event', category: 'lifecycle' },
|
|
59
|
+
{ id: 'shipment_tracking.equipment.customs_released', label: 'Customs Released', entity: 'tracking_event', category: 'lifecycle' },
|
|
60
|
+
{ id: 'shipment_tracking.equipment.inspected', label: 'Container Inspected', entity: 'tracking_event', category: 'lifecycle' },
|
|
61
|
+
|
|
62
|
+
// NOTE: air (mode='air') milestones are NOT separate events. The ShipsGo
|
|
63
|
+
// mapper translates air movements onto the DCSA departure/arrival/delivery
|
|
64
|
+
// codes, so an air shipment already emits the shared transport.*/shipment.*
|
|
65
|
+
// lifecycle events the notification system consumes. Dedicated air.* events
|
|
66
|
+
// would need their own emit path + subscribers and would double-fire; add
|
|
67
|
+
// them only when a consumer genuinely needs the RCS/MAN/RCF granularity.
|
|
68
|
+
|
|
69
|
+
// ─── Tracking Events (generic) ─────────────────────────────────
|
|
70
|
+
// Emitted PER RAW EVENT from carrier API (contains equipmentReference)
|
|
71
|
+
{ id: 'shipment_tracking.tracking_event.created', label: 'Tracking Event Created', entity: 'tracking_event', category: 'crud' },
|
|
72
|
+
|
|
73
|
+
// ─── Internal Events (excluded from webhook triggers) ──────────
|
|
74
|
+
// Emitted PER TRACKING JOB (BOL/Booking) - once regardless of container count
|
|
75
|
+
// Tracking jobs - internal system events
|
|
76
|
+
{ id: 'shipment_tracking.tracking_job.created', label: 'Tracking Job Created', entity: 'tracking_job', category: 'crud', excludeFromTriggers: true },
|
|
77
|
+
{ id: 'shipment_tracking.tracking_job.updated', label: 'Tracking Job Updated', entity: 'tracking_job', category: 'crud', excludeFromTriggers: true },
|
|
78
|
+
{ id: 'shipment_tracking.tracking_job.failed', label: 'Tracking Job Failed', entity: 'tracking_job', category: 'lifecycle', excludeFromTriggers: true },
|
|
79
|
+
{ id: 'shipment_tracking.tracking_job.completed', label: 'Tracking Job Completed', entity: 'tracking_job', category: 'lifecycle', excludeFromTriggers: true },
|
|
80
|
+
|
|
81
|
+
// Webhook delivery - internal infrastructure events
|
|
82
|
+
{ id: 'shipment_tracking.webhook.delivery_success', label: 'Webhook Delivery Success', entity: 'webhook_delivery', category: 'lifecycle', excludeFromTriggers: true },
|
|
83
|
+
{ id: 'shipment_tracking.webhook.delivery_failed', label: 'Webhook Delivery Failed', entity: 'webhook_delivery', category: 'lifecycle', excludeFromTriggers: true },
|
|
84
|
+
|
|
85
|
+
// ─── Tracking Job Poll Events ──────────────────────────────────
|
|
86
|
+
// Emitted PER TRACKING JOB
|
|
87
|
+
{ id: 'shipment_tracking.tracking_job.poll_failed', label: 'Tracking Job Poll Failed', entity: 'tracking_job', category: 'lifecycle', excludeFromTriggers: true },
|
|
88
|
+
|
|
89
|
+
// ─── Tracking Job POI Events (for notifications) ───────────────
|
|
90
|
+
// Emitted PER TRACKING JOB (BOL/Booking) - once regardless of container count
|
|
91
|
+
// Used for in-app notifications to avoid duplicates for multi-container bookings
|
|
92
|
+
{ id: 'shipment_tracking.tracking_job.poi.port_arrival', label: 'Tracking Job - Port Arrival', entity: 'tracking_job', category: 'lifecycle' },
|
|
93
|
+
{ id: 'shipment_tracking.tracking_job.poi.port_proximity_arrival', label: 'Tracking Job - Approaching Port', entity: 'tracking_job', category: 'lifecycle' },
|
|
94
|
+
{ id: 'shipment_tracking.tracking_job.poi.port_departure', label: 'Tracking Job - Port Departure', entity: 'tracking_job', category: 'lifecycle' },
|
|
95
|
+
{ id: 'shipment_tracking.tracking_job.poi.terminal_arrival', label: 'Tracking Job - Terminal Arrival', entity: 'tracking_job', category: 'lifecycle' },
|
|
96
|
+
{ id: 'shipment_tracking.tracking_job.poi.terminal_proximity_arrival', label: 'Tracking Job - Approaching Terminal', entity: 'tracking_job', category: 'lifecycle' },
|
|
97
|
+
{ id: 'shipment_tracking.tracking_job.poi.terminal_departure', label: 'Tracking Job - Terminal Departure', entity: 'tracking_job', category: 'lifecycle' },
|
|
98
|
+
{ id: 'shipment_tracking.tracking_job.poi.waypoint_reached', label: 'Tracking Job - Waypoint Reached', entity: 'tracking_job', category: 'lifecycle' },
|
|
99
|
+
|
|
100
|
+
// ─── POI Proximity Events (AIS) ─────────────────────────────────
|
|
101
|
+
// Emitted PER SHIPMENT (container) - a vessel arrival triggers N events for N containers
|
|
102
|
+
// Real-time vessel position events from AIS POI detector
|
|
103
|
+
// NOTE: Notification subscribers should deduplicate by bookingNumber/bolNumber
|
|
104
|
+
{ id: 'shipment_tracking.poi.port_arrival', label: 'Vessel Port Arrival (AIS)', entity: 'tracking_event', category: 'lifecycle' },
|
|
105
|
+
{ id: 'shipment_tracking.poi.port_proximity_arrival', label: 'Vessel Approaching Port (AIS)', entity: 'tracking_event', category: 'lifecycle' },
|
|
106
|
+
{ id: 'shipment_tracking.poi.port_departure', label: 'Vessel Port Departure (AIS)', entity: 'tracking_event', category: 'lifecycle' },
|
|
107
|
+
{ id: 'shipment_tracking.poi.terminal_arrival', label: 'Vessel Terminal Arrival (AIS)', entity: 'tracking_event', category: 'lifecycle' },
|
|
108
|
+
{ id: 'shipment_tracking.poi.terminal_proximity_arrival', label: 'Vessel Approaching Terminal (AIS)', entity: 'tracking_event', category: 'lifecycle' },
|
|
109
|
+
{ id: 'shipment_tracking.poi.terminal_departure', label: 'Vessel Terminal Departure (AIS)', entity: 'tracking_event', category: 'lifecycle' },
|
|
110
|
+
{ id: 'shipment_tracking.poi.waypoint_reached', label: 'Vessel Waypoint Reached (AIS)', entity: 'tracking_event', category: 'lifecycle' },
|
|
111
|
+
] as const
|
|
112
|
+
|
|
113
|
+
export const eventsConfig = createModuleEvents({
|
|
114
|
+
moduleId: 'shipment_tracking',
|
|
115
|
+
events,
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
export const emitShipmentTrackingEvent = eventsConfig.emit
|
|
119
|
+
|
|
120
|
+
export type ShipmentTrackingEventId = typeof events[number]['id']
|
|
121
|
+
|
|
122
|
+
export default eventsConfig
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* React hooks for vessel tracking with real-time position and trace data.
|
|
5
|
+
*
|
|
6
|
+
* Features:
|
|
7
|
+
* - useVessel: Fetch vessel info with auto-refresh
|
|
8
|
+
* - useVesselTrace: Fetch trace with viewport bounding box filter
|
|
9
|
+
* - useDebouncedBounds: Debounce map viewport changes
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { useState, useEffect, useCallback, useMemo } from 'react'
|
|
13
|
+
import { useQuery } from '@tanstack/react-query'
|
|
14
|
+
import {
|
|
15
|
+
fetchVessel,
|
|
16
|
+
fetchVesselTrace,
|
|
17
|
+
fetchPois,
|
|
18
|
+
type VesselInfo,
|
|
19
|
+
type TraceResponse,
|
|
20
|
+
type BoundingBox,
|
|
21
|
+
type TimeRange,
|
|
22
|
+
type PoiInfo,
|
|
23
|
+
} from '../lib/vessel-api'
|
|
24
|
+
|
|
25
|
+
// ─── useVessel ───────────────────────────────────────────────
|
|
26
|
+
|
|
27
|
+
interface UseVesselOptions {
|
|
28
|
+
/** Enable auto-refresh (default: true) */
|
|
29
|
+
autoRefresh?: boolean
|
|
30
|
+
/** Auto-refresh interval in ms (default: 30000) */
|
|
31
|
+
refreshInterval?: number
|
|
32
|
+
/** Enable the query (default: true) */
|
|
33
|
+
enabled?: boolean
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Hook to fetch vessel information by IMO number.
|
|
38
|
+
* Auto-refreshes every 30 seconds by default.
|
|
39
|
+
*/
|
|
40
|
+
export function useVessel(
|
|
41
|
+
vesselImo: string | null | undefined,
|
|
42
|
+
options: UseVesselOptions = {}
|
|
43
|
+
) {
|
|
44
|
+
const { autoRefresh = true, refreshInterval = 30_000, enabled = true } = options
|
|
45
|
+
|
|
46
|
+
return useQuery<VesselInfo | null, Error>({
|
|
47
|
+
queryKey: ['vessel-info', vesselImo],
|
|
48
|
+
queryFn: () => fetchVessel(vesselImo!),
|
|
49
|
+
enabled: enabled && !!vesselImo,
|
|
50
|
+
staleTime: refreshInterval,
|
|
51
|
+
refetchInterval: autoRefresh ? refreshInterval : false,
|
|
52
|
+
retry: 2,
|
|
53
|
+
})
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// ─── useDebouncedBounds ──────────────────────────────────────
|
|
57
|
+
|
|
58
|
+
interface UseDebouncedBoundsResult {
|
|
59
|
+
/** Current bounds (updated immediately) */
|
|
60
|
+
bounds: BoundingBox | null
|
|
61
|
+
/** Debounced bounds (updated after delay) */
|
|
62
|
+
debouncedBounds: BoundingBox | null
|
|
63
|
+
/** Update bounds - call this on map viewport change */
|
|
64
|
+
setBounds: (bounds: BoundingBox | null) => void
|
|
65
|
+
/** Whether bounds are currently being debounced */
|
|
66
|
+
isDebouncing: boolean
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Hook to debounce map viewport bounds changes.
|
|
71
|
+
* Prevents excessive API calls when user is panning/zooming.
|
|
72
|
+
*
|
|
73
|
+
* @param delay - Debounce delay in ms (default: 500)
|
|
74
|
+
*/
|
|
75
|
+
export function useDebouncedBounds(delay = 500): UseDebouncedBoundsResult {
|
|
76
|
+
const [bounds, setBounds] = useState<BoundingBox | null>(null)
|
|
77
|
+
const [debouncedBounds, setDebouncedBounds] = useState<BoundingBox | null>(null)
|
|
78
|
+
const [isDebouncing, setIsDebouncing] = useState(false)
|
|
79
|
+
|
|
80
|
+
useEffect(() => {
|
|
81
|
+
if (!bounds) {
|
|
82
|
+
setDebouncedBounds(null)
|
|
83
|
+
setIsDebouncing(false)
|
|
84
|
+
return
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
setIsDebouncing(true)
|
|
88
|
+
const timer = setTimeout(() => {
|
|
89
|
+
setDebouncedBounds(bounds)
|
|
90
|
+
setIsDebouncing(false)
|
|
91
|
+
}, delay)
|
|
92
|
+
|
|
93
|
+
return () => {
|
|
94
|
+
clearTimeout(timer)
|
|
95
|
+
}
|
|
96
|
+
}, [bounds, delay])
|
|
97
|
+
|
|
98
|
+
return { bounds, debouncedBounds, setBounds, isDebouncing }
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// ─── useVesselTrace ──────────────────────────────────────────
|
|
102
|
+
|
|
103
|
+
interface UseVesselTraceOptions {
|
|
104
|
+
/** Maximum number of trace points to fetch (default: 2000) */
|
|
105
|
+
limit?: number
|
|
106
|
+
/** Stale time in ms (default: 60000) */
|
|
107
|
+
staleTime?: number
|
|
108
|
+
/** Enable the query (default: true) */
|
|
109
|
+
enabled?: boolean
|
|
110
|
+
/** Start time filter (ISO 8601) - limits trace to events after this date */
|
|
111
|
+
from?: string
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Hook to fetch vessel trace (position history) within a bounding box.
|
|
116
|
+
* Only fetches when bounds are provided (debounce with useDebouncedBounds).
|
|
117
|
+
*/
|
|
118
|
+
export function useVesselTrace(
|
|
119
|
+
vesselImo: string | null | undefined,
|
|
120
|
+
bounds: BoundingBox | null,
|
|
121
|
+
options: UseVesselTraceOptions = {}
|
|
122
|
+
) {
|
|
123
|
+
const { limit = 2000, staleTime = 60_000, enabled = true, from } = options
|
|
124
|
+
|
|
125
|
+
// Memoize bounds to prevent unnecessary refetches
|
|
126
|
+
const boundsKey = useMemo(() => {
|
|
127
|
+
if (!bounds) return null
|
|
128
|
+
// Round to 3 decimal places to prevent micro-changes from triggering refetch
|
|
129
|
+
return `${bounds.north.toFixed(3)},${bounds.south.toFixed(3)},${bounds.east.toFixed(3)},${bounds.west.toFixed(3)}`
|
|
130
|
+
}, [bounds])
|
|
131
|
+
|
|
132
|
+
// Build time range if from is provided
|
|
133
|
+
const timeRange: TimeRange | undefined = from ? { from } : undefined
|
|
134
|
+
|
|
135
|
+
return useQuery<TraceResponse, Error>({
|
|
136
|
+
queryKey: ['vessel-trace', vesselImo, boundsKey, limit, from],
|
|
137
|
+
queryFn: () => fetchVesselTrace(vesselImo!, bounds ?? undefined, limit, timeRange),
|
|
138
|
+
enabled: enabled && !!vesselImo && !!bounds,
|
|
139
|
+
staleTime,
|
|
140
|
+
retry: 1,
|
|
141
|
+
})
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// ─── usePois ─────────────────────────────────────────────────
|
|
145
|
+
|
|
146
|
+
interface UsePoisOptions {
|
|
147
|
+
/** Maximum number of POIs to fetch (default: 1000) */
|
|
148
|
+
limit?: number
|
|
149
|
+
/** Stale time in ms (default: 300000 — POIs are near-static) */
|
|
150
|
+
staleTime?: number
|
|
151
|
+
/** Enable the query (default: true). Gate this on zoom to avoid clutter/over-fetch. */
|
|
152
|
+
enabled?: boolean
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Hook to fetch points of interest within a bounding box.
|
|
157
|
+
* Only fetches when bounds are provided and `enabled` is true (gate on zoom level).
|
|
158
|
+
*/
|
|
159
|
+
export function usePois(
|
|
160
|
+
bounds: BoundingBox | null,
|
|
161
|
+
options: UsePoisOptions = {}
|
|
162
|
+
) {
|
|
163
|
+
const { limit = 1000, staleTime = 300_000, enabled = true } = options
|
|
164
|
+
|
|
165
|
+
// Round bounds so micro pan/zoom doesn't re-trigger; reuses the trace pattern.
|
|
166
|
+
const boundsKey = useMemo(() => {
|
|
167
|
+
if (!bounds) return null
|
|
168
|
+
return `${bounds.north.toFixed(2)},${bounds.south.toFixed(2)},${bounds.east.toFixed(2)},${bounds.west.toFixed(2)}`
|
|
169
|
+
}, [bounds])
|
|
170
|
+
|
|
171
|
+
return useQuery<PoiInfo[], Error>({
|
|
172
|
+
queryKey: ['pois', boundsKey, limit],
|
|
173
|
+
queryFn: async () => {
|
|
174
|
+
// Waypoints are open-water grid markers — exclude them at the source. The API `type`
|
|
175
|
+
// filter is single-value, so request the real-place types in parallel and merge.
|
|
176
|
+
const results = await Promise.all(
|
|
177
|
+
(['PORT', 'TERMINAL', 'PORT_GEOMETRIC_CENTER'] as const).map((type) =>
|
|
178
|
+
fetchPois(bounds ?? undefined, { type, limit }),
|
|
179
|
+
),
|
|
180
|
+
)
|
|
181
|
+
const seen = new Set<string>()
|
|
182
|
+
return results.flat().filter((poi) => {
|
|
183
|
+
if (seen.has(poi.code)) return false
|
|
184
|
+
seen.add(poi.code)
|
|
185
|
+
return true
|
|
186
|
+
})
|
|
187
|
+
},
|
|
188
|
+
enabled: enabled && !!bounds,
|
|
189
|
+
staleTime,
|
|
190
|
+
retry: 1,
|
|
191
|
+
})
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// ─── useVesselTracking (combined) ────────────────────────────
|
|
195
|
+
|
|
196
|
+
interface UseVesselTrackingOptions {
|
|
197
|
+
/** Auto-refresh vessel position (default: true) */
|
|
198
|
+
autoRefresh?: boolean
|
|
199
|
+
/** Vessel refresh interval in ms (default: 30000) */
|
|
200
|
+
vesselRefreshInterval?: number
|
|
201
|
+
/** Trace fetch limit (default: 2000) */
|
|
202
|
+
traceLimit?: number
|
|
203
|
+
/** Bounds debounce delay in ms (default: 500) */
|
|
204
|
+
boundsDebounceDelay?: number
|
|
205
|
+
/** Start time filter for trace (ISO 8601) - limits trace to events after this date */
|
|
206
|
+
traceFrom?: string
|
|
207
|
+
/** Fetch POIs for the current viewport (default: false) */
|
|
208
|
+
enablePois?: boolean
|
|
209
|
+
/** Max POIs to fetch per viewport (default: 1000) */
|
|
210
|
+
poiLimit?: number
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
interface UseVesselTrackingResult {
|
|
214
|
+
/** Vessel info */
|
|
215
|
+
vessel: VesselInfo | null | undefined
|
|
216
|
+
/** Whether vessel is loading */
|
|
217
|
+
isVesselLoading: boolean
|
|
218
|
+
/** Vessel fetch error */
|
|
219
|
+
vesselError: Error | null
|
|
220
|
+
/** Trace data */
|
|
221
|
+
trace: TraceResponse | undefined
|
|
222
|
+
/** Whether trace is loading */
|
|
223
|
+
isTraceLoading: boolean
|
|
224
|
+
/** Trace fetch error */
|
|
225
|
+
traceError: Error | null
|
|
226
|
+
/** Whether bounds are being debounced */
|
|
227
|
+
isDebouncing: boolean
|
|
228
|
+
/** Current viewport bounds */
|
|
229
|
+
bounds: BoundingBox | null
|
|
230
|
+
/** Update bounds (call on map viewport change) */
|
|
231
|
+
setBounds: (bounds: BoundingBox | null) => void
|
|
232
|
+
/** POIs within the current viewport (empty unless enablePois) */
|
|
233
|
+
pois: PoiInfo[] | undefined
|
|
234
|
+
/** Whether POIs are loading */
|
|
235
|
+
isPoisLoading: boolean
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Combined hook for vessel tracking with map integration.
|
|
240
|
+
* Handles vessel info, trace, and debounced bounds in one hook.
|
|
241
|
+
*/
|
|
242
|
+
export function useVesselTracking(
|
|
243
|
+
vesselImo: string | null | undefined,
|
|
244
|
+
options: UseVesselTrackingOptions = {}
|
|
245
|
+
): UseVesselTrackingResult {
|
|
246
|
+
const {
|
|
247
|
+
autoRefresh = true,
|
|
248
|
+
vesselRefreshInterval = 30_000,
|
|
249
|
+
traceLimit = 2000,
|
|
250
|
+
boundsDebounceDelay = 500,
|
|
251
|
+
traceFrom,
|
|
252
|
+
enablePois = false,
|
|
253
|
+
poiLimit = 1000,
|
|
254
|
+
} = options
|
|
255
|
+
|
|
256
|
+
const { bounds, debouncedBounds, setBounds, isDebouncing } = useDebouncedBounds(boundsDebounceDelay)
|
|
257
|
+
|
|
258
|
+
const {
|
|
259
|
+
data: vessel,
|
|
260
|
+
isLoading: isVesselLoading,
|
|
261
|
+
error: vesselError,
|
|
262
|
+
} = useVessel(vesselImo, {
|
|
263
|
+
autoRefresh,
|
|
264
|
+
refreshInterval: vesselRefreshInterval,
|
|
265
|
+
})
|
|
266
|
+
|
|
267
|
+
const {
|
|
268
|
+
data: trace,
|
|
269
|
+
isLoading: isTraceLoading,
|
|
270
|
+
error: traceError,
|
|
271
|
+
} = useVesselTrace(vesselImo, debouncedBounds, {
|
|
272
|
+
limit: traceLimit,
|
|
273
|
+
from: traceFrom,
|
|
274
|
+
})
|
|
275
|
+
|
|
276
|
+
const {
|
|
277
|
+
data: pois,
|
|
278
|
+
isLoading: isPoisLoading,
|
|
279
|
+
} = usePois(debouncedBounds, {
|
|
280
|
+
enabled: enablePois,
|
|
281
|
+
limit: poiLimit,
|
|
282
|
+
})
|
|
283
|
+
|
|
284
|
+
return {
|
|
285
|
+
vessel,
|
|
286
|
+
isVesselLoading,
|
|
287
|
+
vesselError: vesselError ?? null,
|
|
288
|
+
trace,
|
|
289
|
+
isTraceLoading,
|
|
290
|
+
traceError: traceError ?? null,
|
|
291
|
+
isDebouncing,
|
|
292
|
+
bounds,
|
|
293
|
+
setBounds,
|
|
294
|
+
pois,
|
|
295
|
+
isPoisLoading,
|
|
296
|
+
}
|
|
297
|
+
}
|