@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,136 @@
|
|
|
1
|
+
import type { TrackingEventType, TrackingEventClassifierCode, TrackingEventSource, TrackingReferenceType } from '../data/entities'
|
|
2
|
+
import type { SealInfo } from './route-extraction'
|
|
3
|
+
|
|
4
|
+
export type { SealInfo } from './route-extraction'
|
|
5
|
+
|
|
6
|
+
export type DocumentReference = {
|
|
7
|
+
type: string // BKG, TRD, SHI, CBR, ARN, VGM, etc.
|
|
8
|
+
value: string
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export type CarrierFetchedEvent = {
|
|
12
|
+
// ─── Event Source ──────────────────────────────────────────────
|
|
13
|
+
source: TrackingEventSource
|
|
14
|
+
sourceEventId: string // Original ID from the source system (e.g., DCSA eventId)
|
|
15
|
+
|
|
16
|
+
// ─── Core Event Fields ─────────────────────────────────────────
|
|
17
|
+
eventType: TrackingEventType
|
|
18
|
+
eventCode: string
|
|
19
|
+
eventClassifierCode?: TrackingEventClassifierCode | null
|
|
20
|
+
eventDateTime: Date
|
|
21
|
+
eventDateTimeOffset?: string | null
|
|
22
|
+
description?: string | null
|
|
23
|
+
rawData?: Record<string, unknown> | null
|
|
24
|
+
|
|
25
|
+
// ─── Equipment Fields (DCSA EQUIPMENT events) ──────────────────
|
|
26
|
+
equipmentReference?: string | null // Container number (BIC ISO)
|
|
27
|
+
isoEquipmentCode?: string | null // Container type (22G1, 45R1, etc.)
|
|
28
|
+
emptyIndicatorCode?: 'EMPTY' | 'LADEN' | null
|
|
29
|
+
isTransshipmentMove?: boolean | null
|
|
30
|
+
|
|
31
|
+
// ─── Location Fields ───────────────────────────────────────────
|
|
32
|
+
locationName?: string | null
|
|
33
|
+
locationUnlocode?: string | null
|
|
34
|
+
locationCountry?: string | null
|
|
35
|
+
facilityCode?: string | null // Terminal/depot code (SMDG/BIC)
|
|
36
|
+
facilityCodeListProvider?: 'SMDG' | 'BIC' | null
|
|
37
|
+
facilityTypeCode?: string | null // POTE, DEPO, CLOC, COFS, etc.
|
|
38
|
+
facilityAddress?: string | null // Full address string (from DCSA otherFacility)
|
|
39
|
+
latitude?: number | null
|
|
40
|
+
longitude?: number | null
|
|
41
|
+
|
|
42
|
+
// ─── Transport Call Fields ─────────────────────────────────────
|
|
43
|
+
transportCallReference?: string | null
|
|
44
|
+
modeOfTransport?: 'VESSEL' | 'RAIL' | 'TRUCK' | 'BARGE' | 'AIR' | null
|
|
45
|
+
vesselName?: string | null
|
|
46
|
+
vesselImo?: string | null
|
|
47
|
+
voyageNumber?: string | null
|
|
48
|
+
carrierServiceCode?: string | null
|
|
49
|
+
carrierExportVoyageNumber?: string | null
|
|
50
|
+
carrierImportVoyageNumber?: string | null
|
|
51
|
+
universalServiceReference?: string | null
|
|
52
|
+
universalExportVoyageReference?: string | null
|
|
53
|
+
universalImportVoyageReference?: string | null
|
|
54
|
+
portVisitReference?: string | null
|
|
55
|
+
|
|
56
|
+
// ─── Document References ───────────────────────────────────────
|
|
57
|
+
relatedDocumentReferences?: DocumentReference[] | null
|
|
58
|
+
|
|
59
|
+
// ─── Metadata Fields ───────────────────────────────────────────
|
|
60
|
+
eventCreatedDateTime?: Date | null
|
|
61
|
+
retractedEventId?: string | null
|
|
62
|
+
publisherName?: string | null
|
|
63
|
+
publisherRole?: string | null // CA, AG, VSL, TR, etc.
|
|
64
|
+
|
|
65
|
+
// ─── Additional Event Fields ───────────────────────────────────
|
|
66
|
+
delayReasonCode?: string | null // SMDG delay reason code
|
|
67
|
+
changeRemark?: string | null
|
|
68
|
+
seals?: SealInfo[] | null
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export type CarrierAdapterTestResult = {
|
|
72
|
+
success: boolean
|
|
73
|
+
message: string
|
|
74
|
+
latencyMs?: number
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export type CarrierFetchResult = {
|
|
78
|
+
events: CarrierFetchedEvent[]
|
|
79
|
+
containerNumber?: string | null
|
|
80
|
+
bookingNumber?: string | null
|
|
81
|
+
bolNumber?: string | null
|
|
82
|
+
vesselName?: string | null
|
|
83
|
+
vesselImo?: string | null
|
|
84
|
+
// ─── Air (mode='air') ──────────────────────────────────────────
|
|
85
|
+
// Air shipments have no container/vessel; identity is the AWB + flight/airline.
|
|
86
|
+
awbNumber?: string | null
|
|
87
|
+
flightNumber?: string | null
|
|
88
|
+
airlineCode?: string | null
|
|
89
|
+
airlineName?: string | null
|
|
90
|
+
/** ShipsGo top-level air status (NEW/BOOKED/EN_ROUTE/LANDED/DELIVERED/…). */
|
|
91
|
+
airStatus?: string | null
|
|
92
|
+
/**
|
|
93
|
+
* Provider shipment-level metadata that has no dedicated column — merged into
|
|
94
|
+
* `Shipment.extra`. Ocean: ShipsGo route summary (POL/POD + dates, transit
|
|
95
|
+
* time, CO2, transshipments). Air: cargo (pieces/weight/volume) + status_extended.
|
|
96
|
+
*/
|
|
97
|
+
extra?: Record<string, unknown> | null
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Extracts booking and BOL numbers from DCSA document references across all events.
|
|
102
|
+
* BKG = Booking reference, TRD/SHI = Transport Document / Shipping Instruction (BOL).
|
|
103
|
+
*/
|
|
104
|
+
export function extractDocumentReferences(events: CarrierFetchedEvent[]): {
|
|
105
|
+
bookingNumber: string | null
|
|
106
|
+
bolNumber: string | null
|
|
107
|
+
} {
|
|
108
|
+
let bookingNumber: string | null = null
|
|
109
|
+
let bolNumber: string | null = null
|
|
110
|
+
for (const event of events) {
|
|
111
|
+
if (!event.relatedDocumentReferences) continue
|
|
112
|
+
for (const ref of event.relatedDocumentReferences) {
|
|
113
|
+
if (!bookingNumber && ref.type === 'BKG' && ref.value) bookingNumber = ref.value
|
|
114
|
+
if (!bolNumber && (ref.type === 'TRD' || ref.type === 'SHI') && ref.value) bolNumber = ref.value
|
|
115
|
+
if (bookingNumber && bolNumber) return { bookingNumber, bolNumber }
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return { bookingNumber, bolNumber }
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export interface CarrierAdapter {
|
|
122
|
+
readonly carrierCode: string
|
|
123
|
+
readonly supportedReferenceTypes: TrackingReferenceType[]
|
|
124
|
+
|
|
125
|
+
fetchEvents(input: {
|
|
126
|
+
referenceType: TrackingReferenceType
|
|
127
|
+
referenceValue: string
|
|
128
|
+
apiEndpoint?: string | null
|
|
129
|
+
authConfig?: Record<string, unknown> | null
|
|
130
|
+
}): Promise<CarrierFetchResult>
|
|
131
|
+
|
|
132
|
+
testConnection(input: {
|
|
133
|
+
apiEndpoint?: string | null
|
|
134
|
+
authConfig?: Record<string, unknown> | null
|
|
135
|
+
}): Promise<CarrierAdapterTestResult>
|
|
136
|
+
}
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Current vessel derivation utilities for shipment tracking.
|
|
3
|
+
*
|
|
4
|
+
* Determines which vessel the container is currently on (or waiting for)
|
|
5
|
+
* based on shipment progress through route stops.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { RouteStopEntry, CargoEventEntry } from './route-extraction'
|
|
9
|
+
|
|
10
|
+
// ─── Types ───────────────────────────────────────────────────
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Container's current tracking status.
|
|
14
|
+
*/
|
|
15
|
+
export type VesselTrackingStatus =
|
|
16
|
+
| 'in_transit' // Container is on a vessel moving between ports
|
|
17
|
+
| 'at_port' // Container is at a port (waiting for next vessel or just arrived)
|
|
18
|
+
| 'not_departed' // Container hasn't started journey yet (at origin)
|
|
19
|
+
| 'delivered' // Container has arrived at final destination
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Information about the current or planned vessel for tracking.
|
|
23
|
+
*/
|
|
24
|
+
export interface CurrentVesselInfo {
|
|
25
|
+
/** Current or planned vessel name */
|
|
26
|
+
vesselName: string | null
|
|
27
|
+
/** Current or planned vessel IMO for tracking */
|
|
28
|
+
vesselImo: string | null
|
|
29
|
+
/** Container's current status */
|
|
30
|
+
status: VesselTrackingStatus
|
|
31
|
+
/** Current leg info (if in transit) */
|
|
32
|
+
currentLeg?: {
|
|
33
|
+
fromPort: string
|
|
34
|
+
toPort: string
|
|
35
|
+
}
|
|
36
|
+
/** Port name where container currently is (if at_port or not_departed) */
|
|
37
|
+
currentPort?: string
|
|
38
|
+
/** Whether the vessel shown is planned (not yet departed) vs currently carrying container */
|
|
39
|
+
isPlannedVessel: boolean
|
|
40
|
+
/** Start date for trace - ATD from departure port (in_transit) or 7 days ago (planned) */
|
|
41
|
+
traceFrom?: string
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// ─── Helper Functions ────────────────────────────────────────
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Returns ISO 8601 date string for 7 days ago.
|
|
48
|
+
* Used as default trace start time for planned vessels.
|
|
49
|
+
*/
|
|
50
|
+
function getSevenDaysAgo(): string {
|
|
51
|
+
const date = new Date()
|
|
52
|
+
date.setDate(date.getDate() - 7)
|
|
53
|
+
return date.toISOString()
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// ─── Helper Functions ────────────────────────────────────────
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Finds the last vessel that carried the container by searching route stops backwards.
|
|
60
|
+
* Used for delivered shipments to show which vessel completed the journey.
|
|
61
|
+
*/
|
|
62
|
+
function findLastVesselFromStops(
|
|
63
|
+
routeStops: RouteStopEntry[],
|
|
64
|
+
cargoEvents: CargoEventEntry[] | null | undefined
|
|
65
|
+
): { vesselName: string | null; vesselImo: string | null } {
|
|
66
|
+
// Work backwards from the last stop to find a stop with vessel info
|
|
67
|
+
for (let i = routeStops.length - 1; i >= 0; i--) {
|
|
68
|
+
const stop = routeStops[i]
|
|
69
|
+
if (stop.vesselName) {
|
|
70
|
+
const vesselImo = stop.vesselImo || findVesselImoFromEvents(stop.vesselName, cargoEvents)
|
|
71
|
+
return { vesselName: stop.vesselName, vesselImo }
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return { vesselName: null, vesselImo: null }
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// ─── Main Function ───────────────────────────────────────────
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Determines the current vessel based on shipment progress through route stops.
|
|
81
|
+
*
|
|
82
|
+
* Algorithm:
|
|
83
|
+
* 1. If final destination has ATA → Container delivered, no vessel to track
|
|
84
|
+
* 2. Find the latest stop with ATD where next stop doesn't have ATA
|
|
85
|
+
* → Container is in transit on this leg's vessel
|
|
86
|
+
* 3. Find stop with ATA but no ATD (container at port waiting)
|
|
87
|
+
* → Return next leg's planned vessel if available
|
|
88
|
+
* 4. No stops have ATD → Container not departed yet
|
|
89
|
+
* → Return first leg's planned vessel
|
|
90
|
+
*
|
|
91
|
+
* @param routeStops - Array of route stops from shipment
|
|
92
|
+
* @param cargoEvents - Array of cargo events (used to find vessel IMO if not in stops)
|
|
93
|
+
* @param fallbackVessel - Fallback vessel info from shipment entity
|
|
94
|
+
* @returns CurrentVesselInfo with vessel details and status
|
|
95
|
+
*/
|
|
96
|
+
export function getCurrentVessel(
|
|
97
|
+
routeStops: RouteStopEntry[] | null | undefined,
|
|
98
|
+
cargoEvents: CargoEventEntry[] | null | undefined,
|
|
99
|
+
fallbackVessel?: { vesselName?: string | null; vesselImo?: string | null }
|
|
100
|
+
): CurrentVesselInfo {
|
|
101
|
+
// Default result when no data available
|
|
102
|
+
const defaultResult: CurrentVesselInfo = {
|
|
103
|
+
vesselName: fallbackVessel?.vesselName ?? null,
|
|
104
|
+
vesselImo: fallbackVessel?.vesselImo ?? null,
|
|
105
|
+
status: 'not_departed',
|
|
106
|
+
isPlannedVessel: true,
|
|
107
|
+
traceFrom: getSevenDaysAgo(),
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (!routeStops || routeStops.length === 0) {
|
|
111
|
+
return defaultResult
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// Check if container is delivered (final destination has ATA)
|
|
115
|
+
const destination = routeStops.find((s) => s.type === 'destination')
|
|
116
|
+
if (destination?.ata) {
|
|
117
|
+
// Find the last vessel that carried the container (for display purposes)
|
|
118
|
+
// Work backwards from destination to find a stop with vessel info
|
|
119
|
+
const lastVesselInfo = findLastVesselFromStops(routeStops, cargoEvents)
|
|
120
|
+
return {
|
|
121
|
+
vesselName: lastVesselInfo.vesselName,
|
|
122
|
+
vesselImo: lastVesselInfo.vesselImo,
|
|
123
|
+
status: 'delivered',
|
|
124
|
+
currentPort: destination.location,
|
|
125
|
+
isPlannedVessel: false,
|
|
126
|
+
// No traceFrom needed for delivered containers (map not shown)
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// Find where the container currently is
|
|
131
|
+
// Look for the latest stop with ATD where the next stop doesn't have ATA yet
|
|
132
|
+
for (let i = routeStops.length - 1; i >= 0; i--) {
|
|
133
|
+
const stop = routeStops[i]
|
|
134
|
+
const nextStop = routeStops[i + 1]
|
|
135
|
+
|
|
136
|
+
// Case 1: Stop has ATD and next stop exists but doesn't have ATA
|
|
137
|
+
// → Container is in transit between these stops
|
|
138
|
+
if (stop.atd && nextStop && !nextStop.ata) {
|
|
139
|
+
const vesselImo = stop.vesselImo || findVesselImoFromEvents(stop.vesselName, cargoEvents) || fallbackVessel?.vesselImo || null
|
|
140
|
+
return {
|
|
141
|
+
vesselName: stop.vesselName ?? null,
|
|
142
|
+
vesselImo,
|
|
143
|
+
status: 'in_transit',
|
|
144
|
+
currentLeg: {
|
|
145
|
+
fromPort: stop.location,
|
|
146
|
+
toPort: nextStop.location,
|
|
147
|
+
},
|
|
148
|
+
isPlannedVessel: false,
|
|
149
|
+
traceFrom: stop.atd, // Use ATD from departure port
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// Case 2: Stop has ATA but no ATD (container is at this port)
|
|
154
|
+
// → Return the next leg's vessel as planned vessel
|
|
155
|
+
if (stop.ata && !stop.atd) {
|
|
156
|
+
// Look for next stop's vessel
|
|
157
|
+
if (nextStop) {
|
|
158
|
+
const vesselImo =
|
|
159
|
+
nextStop.vesselImo || findVesselImoFromEvents(nextStop.vesselName, cargoEvents) || fallbackVessel?.vesselImo || null
|
|
160
|
+
return {
|
|
161
|
+
vesselName: nextStop.vesselName ?? null,
|
|
162
|
+
vesselImo,
|
|
163
|
+
status: 'at_port',
|
|
164
|
+
currentPort: stop.location,
|
|
165
|
+
isPlannedVessel: true,
|
|
166
|
+
traceFrom: getSevenDaysAgo(), // Last 7 days for planned vessel
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
// At final stop but no ATA on destination (shouldn't happen normally)
|
|
170
|
+
return {
|
|
171
|
+
vesselName: null,
|
|
172
|
+
vesselImo: null,
|
|
173
|
+
status: 'at_port',
|
|
174
|
+
currentPort: stop.location,
|
|
175
|
+
isPlannedVessel: false,
|
|
176
|
+
traceFrom: getSevenDaysAgo(),
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// Case 3: No stops have ATD → Container hasn't departed yet
|
|
182
|
+
// Return first leg's vessel as planned
|
|
183
|
+
const origin = routeStops[0]
|
|
184
|
+
const vesselImo = origin?.vesselImo || findVesselImoFromEvents(origin?.vesselName, cargoEvents)
|
|
185
|
+
|
|
186
|
+
return {
|
|
187
|
+
vesselName: origin?.vesselName ?? fallbackVessel?.vesselName ?? null,
|
|
188
|
+
vesselImo: vesselImo ?? fallbackVessel?.vesselImo ?? null,
|
|
189
|
+
status: 'not_departed',
|
|
190
|
+
currentPort: origin?.location,
|
|
191
|
+
isPlannedVessel: true,
|
|
192
|
+
traceFrom: getSevenDaysAgo(), // Last 7 days for planned vessel
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// ─── More Helper Functions ───────────────────────────────────
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Find vessel IMO from cargo events by vessel name.
|
|
200
|
+
* Used when RouteStopEntry only has vesselName but needs IMO.
|
|
201
|
+
*
|
|
202
|
+
* @param vesselName - Vessel name to search for
|
|
203
|
+
* @param events - Array of cargo events
|
|
204
|
+
* @returns Vessel IMO if found, null otherwise
|
|
205
|
+
*/
|
|
206
|
+
export function findVesselImoFromEvents(
|
|
207
|
+
vesselName: string | null | undefined,
|
|
208
|
+
events: CargoEventEntry[] | null | undefined
|
|
209
|
+
): string | null {
|
|
210
|
+
if (!vesselName || !events || events.length === 0) {
|
|
211
|
+
return null
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// Find any event with matching vessel name that has an IMO
|
|
215
|
+
const eventWithImo = events.find(
|
|
216
|
+
(e) => e.vesselName === vesselName && e.vesselImo
|
|
217
|
+
)
|
|
218
|
+
|
|
219
|
+
return eventWithImo?.vesselImo ?? null
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Get a human-readable description of the current vessel status.
|
|
224
|
+
* Useful for UI display.
|
|
225
|
+
*
|
|
226
|
+
* @param info - Current vessel info
|
|
227
|
+
* @returns Status description object with keys for i18n
|
|
228
|
+
*/
|
|
229
|
+
export function getVesselStatusDescription(info: CurrentVesselInfo): {
|
|
230
|
+
key: string
|
|
231
|
+
params?: Record<string, string>
|
|
232
|
+
} {
|
|
233
|
+
switch (info.status) {
|
|
234
|
+
case 'in_transit':
|
|
235
|
+
return {
|
|
236
|
+
key: 'shipment_tracking.map.inTransit',
|
|
237
|
+
params: {
|
|
238
|
+
destination: info.currentLeg?.toPort ?? '',
|
|
239
|
+
},
|
|
240
|
+
}
|
|
241
|
+
case 'at_port':
|
|
242
|
+
if (info.vesselName) {
|
|
243
|
+
return {
|
|
244
|
+
key: 'shipment_tracking.map.atPortAwaitingVessel',
|
|
245
|
+
params: {
|
|
246
|
+
port: info.currentPort ?? '',
|
|
247
|
+
vessel: info.vesselName,
|
|
248
|
+
},
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
return {
|
|
252
|
+
key: 'shipment_tracking.map.atPort',
|
|
253
|
+
params: {
|
|
254
|
+
port: info.currentPort ?? '',
|
|
255
|
+
},
|
|
256
|
+
}
|
|
257
|
+
case 'not_departed':
|
|
258
|
+
if (info.vesselName) {
|
|
259
|
+
return {
|
|
260
|
+
key: 'shipment_tracking.map.awaitingDeparture',
|
|
261
|
+
params: {
|
|
262
|
+
vessel: info.vesselName,
|
|
263
|
+
},
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
return {
|
|
267
|
+
key: 'shipment_tracking.map.notDeparted',
|
|
268
|
+
}
|
|
269
|
+
case 'delivered':
|
|
270
|
+
return {
|
|
271
|
+
key: 'shipment_tracking.map.delivered',
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import type { TrackingEventType, TrackingEventClassifierCode } from '../data/entities'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* DCSA Track & Trace Event Code Mapping
|
|
5
|
+
*
|
|
6
|
+
* Maps DCSA standard event codes to internal webhook event types.
|
|
7
|
+
* Reference: DCSA T&T v3.0 specification
|
|
8
|
+
*
|
|
9
|
+
* Event Types:
|
|
10
|
+
* - TRANSPORT: Vessel/transport movement events (ARRI, DEPA, OMIT)
|
|
11
|
+
* - EQUIPMENT: Container handling events (LOAD, DISC, GTIN, GTOT, etc.)
|
|
12
|
+
* - SHIPMENT: Document lifecycle events (not typically from carrier tracking)
|
|
13
|
+
*
|
|
14
|
+
* Event Classifiers:
|
|
15
|
+
* - ACT: Actual (event has happened)
|
|
16
|
+
* - PLN: Planned
|
|
17
|
+
* - EST: Estimated
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
export type DcsaWebhookEventType =
|
|
21
|
+
// Transport events
|
|
22
|
+
| 'shipment_tracking.transport.departed'
|
|
23
|
+
| 'shipment_tracking.transport.arrived'
|
|
24
|
+
| 'shipment_tracking.transport.eta_updated'
|
|
25
|
+
| 'shipment_tracking.transport.etd_updated'
|
|
26
|
+
| 'shipment_tracking.transport.omitted'
|
|
27
|
+
// Equipment events
|
|
28
|
+
| 'shipment_tracking.equipment.loaded'
|
|
29
|
+
| 'shipment_tracking.equipment.discharged'
|
|
30
|
+
| 'shipment_tracking.equipment.gate_in'
|
|
31
|
+
| 'shipment_tracking.equipment.gate_out'
|
|
32
|
+
| 'shipment_tracking.equipment.available_pickup'
|
|
33
|
+
| 'shipment_tracking.equipment.customs_released'
|
|
34
|
+
| 'shipment_tracking.equipment.inspected'
|
|
35
|
+
// Shipment lifecycle
|
|
36
|
+
| 'shipment_tracking.shipment.booked'
|
|
37
|
+
| 'shipment_tracking.shipment.delivered'
|
|
38
|
+
// Generic fallback
|
|
39
|
+
| 'shipment_tracking.tracking_event.created'
|
|
40
|
+
|
|
41
|
+
export type EventMappingInput = {
|
|
42
|
+
eventType: TrackingEventType
|
|
43
|
+
eventCode: string
|
|
44
|
+
eventClassifierCode?: TrackingEventClassifierCode | null
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Maps a DCSA cargo event to the appropriate webhook event type.
|
|
49
|
+
*
|
|
50
|
+
* @param input - The cargo event details from carrier API
|
|
51
|
+
* @returns The internal webhook event type to emit
|
|
52
|
+
*/
|
|
53
|
+
export function mapDcsaEventToWebhookType(input: EventMappingInput): DcsaWebhookEventType {
|
|
54
|
+
const { eventType, eventCode, eventClassifierCode } = input
|
|
55
|
+
const code = eventCode.toUpperCase()
|
|
56
|
+
const isActual = eventClassifierCode === 'ACT'
|
|
57
|
+
const isEstimatedOrPlanned = eventClassifierCode === 'EST' || eventClassifierCode === 'PLN'
|
|
58
|
+
|
|
59
|
+
// ─── Transport Events ──────────────────────────────────────────
|
|
60
|
+
if (eventType === 'TRANSPORT') {
|
|
61
|
+
switch (code) {
|
|
62
|
+
case 'DEPA': // Departure
|
|
63
|
+
if (isActual) return 'shipment_tracking.transport.departed'
|
|
64
|
+
if (isEstimatedOrPlanned) return 'shipment_tracking.transport.etd_updated'
|
|
65
|
+
return 'shipment_tracking.transport.etd_updated' // Default to ETD update
|
|
66
|
+
case 'ARRI': // Arrival
|
|
67
|
+
if (isActual) return 'shipment_tracking.transport.arrived'
|
|
68
|
+
if (isEstimatedOrPlanned) return 'shipment_tracking.transport.eta_updated'
|
|
69
|
+
return 'shipment_tracking.transport.eta_updated' // Default to ETA update
|
|
70
|
+
case 'OMIT': // Port omitted
|
|
71
|
+
return 'shipment_tracking.transport.omitted'
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// ─── Equipment Events ──────────────────────────────────────────
|
|
76
|
+
if (eventType === 'EQUIPMENT') {
|
|
77
|
+
switch (code) {
|
|
78
|
+
// Loading/Discharge
|
|
79
|
+
case 'LOAD': // Loaded onto vessel
|
|
80
|
+
return 'shipment_tracking.equipment.loaded'
|
|
81
|
+
case 'DISC': // Discharged from vessel
|
|
82
|
+
return 'shipment_tracking.equipment.discharged'
|
|
83
|
+
|
|
84
|
+
// Gate movements
|
|
85
|
+
case 'GTIN': // Gate in
|
|
86
|
+
return 'shipment_tracking.equipment.gate_in'
|
|
87
|
+
case 'GTOT': // Gate out (terminal)
|
|
88
|
+
return 'shipment_tracking.equipment.gate_out'
|
|
89
|
+
|
|
90
|
+
// Availability
|
|
91
|
+
case 'AVPU': // Available for pick-up
|
|
92
|
+
return 'shipment_tracking.equipment.available_pickup'
|
|
93
|
+
case 'AVDO': // Available for drop-off (less common, map to gate_in context)
|
|
94
|
+
return 'shipment_tracking.equipment.gate_in'
|
|
95
|
+
|
|
96
|
+
// Customs
|
|
97
|
+
case 'CUSR': // Customs released
|
|
98
|
+
return 'shipment_tracking.equipment.customs_released'
|
|
99
|
+
case 'CUSS': // Customs selected for scan
|
|
100
|
+
case 'CUSI': // Customs selected for inspection
|
|
101
|
+
return 'shipment_tracking.equipment.inspected'
|
|
102
|
+
|
|
103
|
+
// Inspection
|
|
104
|
+
case 'INSP': // Inspected
|
|
105
|
+
return 'shipment_tracking.equipment.inspected'
|
|
106
|
+
|
|
107
|
+
// Delivery
|
|
108
|
+
case 'DLVR': // Delivered
|
|
109
|
+
if (isActual) return 'shipment_tracking.shipment.delivered'
|
|
110
|
+
break
|
|
111
|
+
|
|
112
|
+
// Pick-up/Drop-off (physical movement)
|
|
113
|
+
case 'PICK': // Pick-up
|
|
114
|
+
return 'shipment_tracking.equipment.gate_out'
|
|
115
|
+
case 'DROP': // Drop-off
|
|
116
|
+
return 'shipment_tracking.equipment.gate_in'
|
|
117
|
+
|
|
118
|
+
// Stuffing/Stripping
|
|
119
|
+
case 'STUF': // Stuffed (cargo loaded into container)
|
|
120
|
+
case 'STRP': // Stripped (cargo unloaded from container)
|
|
121
|
+
// These are container content events, map to generic
|
|
122
|
+
break
|
|
123
|
+
|
|
124
|
+
// Sealing
|
|
125
|
+
case 'RSEA': // Resealed
|
|
126
|
+
case 'RMVD': // Seal removed
|
|
127
|
+
// Seal events, map to generic
|
|
128
|
+
break
|
|
129
|
+
|
|
130
|
+
// Transshipment crossing
|
|
131
|
+
case 'CROS': // Crossed (transshipment)
|
|
132
|
+
// Map to discharge as it indicates container moved
|
|
133
|
+
return 'shipment_tracking.equipment.discharged'
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// ─── Shipment Events ───────────────────────────────────────────
|
|
138
|
+
if (eventType === 'SHIPMENT') {
|
|
139
|
+
// Shipment events are typically document-related (booking, BL issuance)
|
|
140
|
+
// These come from different APIs, not container tracking
|
|
141
|
+
// Map common booking-related codes
|
|
142
|
+
switch (code) {
|
|
143
|
+
case 'CONF': // Confirmed
|
|
144
|
+
case 'BOOK': // Booked (non-standard but common)
|
|
145
|
+
return 'shipment_tracking.shipment.booked'
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// ─── Fallback ──────────────────────────────────────────────────
|
|
150
|
+
return 'shipment_tracking.tracking_event.created'
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Determines if a tracking event represents a significant milestone
|
|
155
|
+
* that warrants a specific webhook event (vs generic tracking_event.created).
|
|
156
|
+
*/
|
|
157
|
+
export function isSignificantMilestone(input: EventMappingInput): boolean {
|
|
158
|
+
const webhookType = mapDcsaEventToWebhookType(input)
|
|
159
|
+
return webhookType !== 'shipment_tracking.tracking_event.created'
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* DCSA Equipment Event Type Codes reference
|
|
164
|
+
*/
|
|
165
|
+
export const DCSA_EQUIPMENT_EVENT_CODES = {
|
|
166
|
+
LOAD: 'Loaded onto transport',
|
|
167
|
+
DISC: 'Discharged from transport',
|
|
168
|
+
GTIN: 'Gated in (entered facility)',
|
|
169
|
+
GTOT: 'Gated out (terminal)',
|
|
170
|
+
STUF: 'Stuffed (cargo loaded into container)',
|
|
171
|
+
STRP: 'Stripped (cargo removed from container)',
|
|
172
|
+
PICK: 'Pick-up by consignee/trucker',
|
|
173
|
+
DROP: 'Drop-off at facility',
|
|
174
|
+
INSP: 'Inspected',
|
|
175
|
+
RSEA: 'Resealed',
|
|
176
|
+
RMVD: 'Seal removed',
|
|
177
|
+
AVPU: 'Available for pick-up',
|
|
178
|
+
AVDO: 'Available for drop-off',
|
|
179
|
+
CUSS: 'Customs selected for scan',
|
|
180
|
+
CUSI: 'Customs selected for inspection',
|
|
181
|
+
CUSR: 'Customs released',
|
|
182
|
+
CROS: 'Crossed (transshipment)',
|
|
183
|
+
DLVR: 'Delivered to consignee',
|
|
184
|
+
} as const
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* DCSA Transport Event Type Codes reference
|
|
188
|
+
*/
|
|
189
|
+
export const DCSA_TRANSPORT_EVENT_CODES = {
|
|
190
|
+
ARRI: 'Arrived at location',
|
|
191
|
+
DEPA: 'Departed from location',
|
|
192
|
+
OMIT: 'Port/location omitted from schedule',
|
|
193
|
+
} as const
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* DCSA Event Classifier Codes reference
|
|
197
|
+
*/
|
|
198
|
+
export const DCSA_EVENT_CLASSIFIERS = {
|
|
199
|
+
ACT: 'Actual (event has occurred)',
|
|
200
|
+
PLN: 'Planned',
|
|
201
|
+
EST: 'Estimated',
|
|
202
|
+
} as const
|