@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,158 @@
|
|
|
1
|
+
import { registerCommand } from '@open-mercato/shared/lib/commands'
|
|
2
|
+
import type { CommandHandler, CommandRuntimeContext } from '@open-mercato/shared/lib/commands'
|
|
3
|
+
import type { EntityManager } from '@mikro-orm/core'
|
|
4
|
+
import type { EventBus } from '@open-mercato/events'
|
|
5
|
+
import { TrackingJob } from '../data/entities'
|
|
6
|
+
import { generatePollSchedule, getNextPollDate } from '../lib/schedule-generator'
|
|
7
|
+
import type { TrackingJobCreateInput } from '../data/validators'
|
|
8
|
+
|
|
9
|
+
function ensureScope(ctx: CommandRuntimeContext, tenantId: string, organizationId: string) {
|
|
10
|
+
if (ctx.auth?.tenantId && ctx.auth.tenantId !== tenantId) {
|
|
11
|
+
throw new Error('Tenant mismatch')
|
|
12
|
+
}
|
|
13
|
+
if (!ctx.auth?.isSuperAdmin && ctx.auth?.organizationId && ctx.auth.organizationId !== organizationId) {
|
|
14
|
+
throw new Error('Organization mismatch')
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const createTrackingJob: CommandHandler<TrackingJobCreateInput, { id: string }> = {
|
|
19
|
+
id: 'shipment_tracking.tracking_job.create',
|
|
20
|
+
|
|
21
|
+
async execute(input, ctx) {
|
|
22
|
+
ensureScope(ctx, input.tenantId, input.organizationId)
|
|
23
|
+
|
|
24
|
+
const em = ctx.container.resolve<EntityManager>('em').fork()
|
|
25
|
+
const eventBus = ctx.container.resolve<EventBus>('eventBus')
|
|
26
|
+
|
|
27
|
+
// Generate schedule if not provided
|
|
28
|
+
const schedule = input.schedule ?? generatePollSchedule({})
|
|
29
|
+
const nextPollAt = getNextPollDate(schedule)
|
|
30
|
+
|
|
31
|
+
const job = em.create(TrackingJob, {
|
|
32
|
+
organizationId: input.organizationId,
|
|
33
|
+
tenantId: input.tenantId,
|
|
34
|
+
carrierCode: input.carrierCode,
|
|
35
|
+
referenceType: input.referenceType,
|
|
36
|
+
referenceValue: input.referenceValue,
|
|
37
|
+
originUnlocode: input.originUnlocode,
|
|
38
|
+
destinationUnlocode: input.destinationUnlocode,
|
|
39
|
+
status: 'active',
|
|
40
|
+
schedule,
|
|
41
|
+
nextPollAt,
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
await em.flush()
|
|
45
|
+
|
|
46
|
+
await eventBus.emit('shipment_tracking.tracking_job.created', {
|
|
47
|
+
id: job.id,
|
|
48
|
+
carrierCode: job.carrierCode,
|
|
49
|
+
referenceType: job.referenceType,
|
|
50
|
+
referenceValue: job.referenceValue,
|
|
51
|
+
tenantId: input.tenantId,
|
|
52
|
+
organizationId: input.organizationId,
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
return { id: job.id }
|
|
56
|
+
},
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const pauseTrackingJob: CommandHandler<{ id: string; tenantId: string; organizationId: string }, { id: string }> = {
|
|
60
|
+
id: 'shipment_tracking.tracking_job.pause',
|
|
61
|
+
|
|
62
|
+
async execute(input, ctx) {
|
|
63
|
+
ensureScope(ctx, input.tenantId, input.organizationId)
|
|
64
|
+
|
|
65
|
+
const em = ctx.container.resolve<EntityManager>('em').fork()
|
|
66
|
+
const eventBus = ctx.container.resolve<EventBus>('eventBus')
|
|
67
|
+
|
|
68
|
+
const job = await em.findOne(TrackingJob, {
|
|
69
|
+
id: input.id,
|
|
70
|
+
tenantId: input.tenantId,
|
|
71
|
+
organizationId: input.organizationId,
|
|
72
|
+
})
|
|
73
|
+
if (!job) throw new Error('Tracking job not found')
|
|
74
|
+
|
|
75
|
+
job.status = 'paused'
|
|
76
|
+
await em.flush()
|
|
77
|
+
|
|
78
|
+
await eventBus.emit('shipment_tracking.tracking_job.updated', {
|
|
79
|
+
id: job.id,
|
|
80
|
+
status: 'paused',
|
|
81
|
+
tenantId: input.tenantId,
|
|
82
|
+
organizationId: input.organizationId,
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
return { id: job.id }
|
|
86
|
+
},
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const resumeTrackingJob: CommandHandler<{ id: string; tenantId: string; organizationId: string }, { id: string }> = {
|
|
90
|
+
id: 'shipment_tracking.tracking_job.resume',
|
|
91
|
+
|
|
92
|
+
async execute(input, ctx) {
|
|
93
|
+
ensureScope(ctx, input.tenantId, input.organizationId)
|
|
94
|
+
|
|
95
|
+
const em = ctx.container.resolve<EntityManager>('em').fork()
|
|
96
|
+
const eventBus = ctx.container.resolve<EventBus>('eventBus')
|
|
97
|
+
|
|
98
|
+
const job = await em.findOne(TrackingJob, {
|
|
99
|
+
id: input.id,
|
|
100
|
+
tenantId: input.tenantId,
|
|
101
|
+
organizationId: input.organizationId,
|
|
102
|
+
})
|
|
103
|
+
if (!job) throw new Error('Tracking job not found')
|
|
104
|
+
|
|
105
|
+
job.status = 'active'
|
|
106
|
+
|
|
107
|
+
// Recalculate next poll from schedule
|
|
108
|
+
if (job.schedule) {
|
|
109
|
+
job.nextPollAt = getNextPollDate(job.schedule)
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
await em.flush()
|
|
113
|
+
|
|
114
|
+
await eventBus.emit('shipment_tracking.tracking_job.updated', {
|
|
115
|
+
id: job.id,
|
|
116
|
+
status: 'active',
|
|
117
|
+
tenantId: input.tenantId,
|
|
118
|
+
organizationId: input.organizationId,
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
return { id: job.id }
|
|
122
|
+
},
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const deactivateTrackingJob: CommandHandler<{ id: string; tenantId: string; organizationId: string }, { id: string }> = {
|
|
126
|
+
id: 'shipment_tracking.tracking_job.deactivate',
|
|
127
|
+
|
|
128
|
+
async execute(input, ctx) {
|
|
129
|
+
ensureScope(ctx, input.tenantId, input.organizationId)
|
|
130
|
+
|
|
131
|
+
const em = ctx.container.resolve<EntityManager>('em').fork()
|
|
132
|
+
const eventBus = ctx.container.resolve<EventBus>('eventBus')
|
|
133
|
+
|
|
134
|
+
const job = await em.findOne(TrackingJob, {
|
|
135
|
+
id: input.id,
|
|
136
|
+
tenantId: input.tenantId,
|
|
137
|
+
organizationId: input.organizationId,
|
|
138
|
+
})
|
|
139
|
+
if (!job) throw new Error('Tracking job not found')
|
|
140
|
+
|
|
141
|
+
job.status = 'deactivated'
|
|
142
|
+
job.nextPollAt = null
|
|
143
|
+
await em.flush()
|
|
144
|
+
|
|
145
|
+
await eventBus.emit('shipment_tracking.tracking_job.completed', {
|
|
146
|
+
id: job.id,
|
|
147
|
+
tenantId: input.tenantId,
|
|
148
|
+
organizationId: input.organizationId,
|
|
149
|
+
})
|
|
150
|
+
|
|
151
|
+
return { id: job.id }
|
|
152
|
+
},
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
registerCommand(createTrackingJob)
|
|
156
|
+
registerCommand(pauseTrackingJob)
|
|
157
|
+
registerCommand(resumeTrackingJob)
|
|
158
|
+
registerCommand(deactivateTrackingJob)
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import { registerCommand } from '@open-mercato/shared/lib/commands'
|
|
2
|
+
import type { CommandHandler, CommandRuntimeContext } from '@open-mercato/shared/lib/commands'
|
|
3
|
+
import type { EntityManager } from '@mikro-orm/postgresql'
|
|
4
|
+
import type { EventBus } from '@open-mercato/events'
|
|
5
|
+
import type { TrackingService } from '../services/trackingService'
|
|
6
|
+
import { Shipment } from '../data/entities'
|
|
7
|
+
import { evaluatePreArrivalUpgrade } from '../lib/status-machine'
|
|
8
|
+
import { getPrimaryTimestampValue } from '../lib/timestamp-utils'
|
|
9
|
+
|
|
10
|
+
function ensureScope(ctx: CommandRuntimeContext, tenantId: string, organizationId?: string) {
|
|
11
|
+
if (ctx.auth?.tenantId && ctx.auth.tenantId !== tenantId) {
|
|
12
|
+
throw new Error('Tenant mismatch')
|
|
13
|
+
}
|
|
14
|
+
if (organizationId && !ctx.auth?.isSuperAdmin && ctx.auth?.organizationId && ctx.auth.organizationId !== organizationId) {
|
|
15
|
+
throw new Error('Organization mismatch')
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
type PollAllInput = {
|
|
20
|
+
tenantId: string
|
|
21
|
+
organizationId?: string
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
type PollAllResult = {
|
|
25
|
+
polled: number
|
|
26
|
+
newEvents: number
|
|
27
|
+
failed: number
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Command to poll all active tracking jobs for a tenant/organization.
|
|
32
|
+
* This is called by the scheduler for daily re-polling.
|
|
33
|
+
*/
|
|
34
|
+
const pollAllActiveJobs: CommandHandler<PollAllInput, PollAllResult> = {
|
|
35
|
+
id: 'shipment_tracking.tracking.poll_all',
|
|
36
|
+
|
|
37
|
+
async execute(input, ctx) {
|
|
38
|
+
ensureScope(ctx, input.tenantId, input.organizationId)
|
|
39
|
+
|
|
40
|
+
const trackingService = ctx.container.resolve<TrackingService>('shipmentTrackingService')
|
|
41
|
+
|
|
42
|
+
const result = await trackingService.pollAllActiveJobs(input.tenantId, input.organizationId)
|
|
43
|
+
|
|
44
|
+
console.log('[shipment-tracking:poll_all] Command completed:', {
|
|
45
|
+
tenantId: input.tenantId,
|
|
46
|
+
organizationId: input.organizationId,
|
|
47
|
+
...result,
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
return result
|
|
51
|
+
},
|
|
52
|
+
|
|
53
|
+
buildLog({ result, input }) {
|
|
54
|
+
return {
|
|
55
|
+
actionLabel: 'Poll all tracking jobs',
|
|
56
|
+
resourceKind: 'shipment_tracking.tracking',
|
|
57
|
+
resourceId: input.organizationId ?? input.tenantId,
|
|
58
|
+
tenantId: input.tenantId,
|
|
59
|
+
organizationId: input.organizationId,
|
|
60
|
+
details: {
|
|
61
|
+
polled: result.polled,
|
|
62
|
+
newEvents: result.newEvents,
|
|
63
|
+
failed: result.failed,
|
|
64
|
+
},
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
type PollSingleInput = {
|
|
70
|
+
jobId: string
|
|
71
|
+
tenantId: string
|
|
72
|
+
organizationId: string
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
type PollSingleResult = {
|
|
76
|
+
newEvents: number
|
|
77
|
+
shipmentsCreated: number
|
|
78
|
+
shipmentsUpdated: number
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Command to poll a single tracking job.
|
|
83
|
+
* Can be called manually to trigger an immediate poll.
|
|
84
|
+
*/
|
|
85
|
+
const pollSingleJob: CommandHandler<PollSingleInput, PollSingleResult> = {
|
|
86
|
+
id: 'shipment_tracking.tracking.poll_single',
|
|
87
|
+
|
|
88
|
+
async execute(input, ctx) {
|
|
89
|
+
ensureScope(ctx, input.tenantId, input.organizationId)
|
|
90
|
+
|
|
91
|
+
const trackingService = ctx.container.resolve<TrackingService>('shipmentTrackingService')
|
|
92
|
+
|
|
93
|
+
const result = await trackingService.pollTrackingJob(input.jobId)
|
|
94
|
+
|
|
95
|
+
return {
|
|
96
|
+
newEvents: result.newEvents,
|
|
97
|
+
shipmentsCreated: result.shipmentsCreated,
|
|
98
|
+
shipmentsUpdated: result.shipmentsUpdated,
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
|
|
102
|
+
buildLog({ result, input }) {
|
|
103
|
+
return {
|
|
104
|
+
actionLabel: 'Poll tracking job',
|
|
105
|
+
resourceKind: 'shipment_tracking.tracking_job',
|
|
106
|
+
resourceId: input.jobId,
|
|
107
|
+
tenantId: input.tenantId,
|
|
108
|
+
organizationId: input.organizationId,
|
|
109
|
+
details: {
|
|
110
|
+
newEvents: result.newEvents,
|
|
111
|
+
shipmentsCreated: result.shipmentsCreated,
|
|
112
|
+
shipmentsUpdated: result.shipmentsUpdated,
|
|
113
|
+
},
|
|
114
|
+
}
|
|
115
|
+
},
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
type EvaluatePreArrivalInput = {
|
|
119
|
+
tenantId: string
|
|
120
|
+
organizationId?: string
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
type EvaluatePreArrivalResult = {
|
|
124
|
+
evaluated: number
|
|
125
|
+
upgraded: number
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Command to evaluate IN_TRANSIT shipments for PRE_ARRIVAL status upgrade.
|
|
130
|
+
* This is called by the scheduler to check shipments approaching their destination.
|
|
131
|
+
*
|
|
132
|
+
* A shipment is upgraded to PRE_ARRIVAL when:
|
|
133
|
+
* - Current status is IN_TRANSIT
|
|
134
|
+
* - ETA is within 7 days
|
|
135
|
+
* - No ATA (actual arrival) yet
|
|
136
|
+
*/
|
|
137
|
+
const evaluatePreArrival: CommandHandler<EvaluatePreArrivalInput, EvaluatePreArrivalResult> = {
|
|
138
|
+
id: 'shipment_tracking.tracking.evaluate_pre_arrival',
|
|
139
|
+
|
|
140
|
+
async execute(input, ctx) {
|
|
141
|
+
ensureScope(ctx, input.tenantId, input.organizationId)
|
|
142
|
+
|
|
143
|
+
const em = ctx.container.resolve<EntityManager>('em')
|
|
144
|
+
const eventBus = ctx.container.resolve<EventBus>('eventBus')
|
|
145
|
+
|
|
146
|
+
// Find all IN_TRANSIT shipments for the tenant/organization
|
|
147
|
+
const filters: Record<string, unknown> = {
|
|
148
|
+
tenantId: input.tenantId,
|
|
149
|
+
status: 'IN_TRANSIT',
|
|
150
|
+
deletedAt: null,
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if (input.organizationId) {
|
|
154
|
+
filters.organizationId = input.organizationId
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const shipments = await em.find(Shipment, filters)
|
|
158
|
+
|
|
159
|
+
let upgraded = 0
|
|
160
|
+
|
|
161
|
+
for (const shipment of shipments) {
|
|
162
|
+
const eta = getPrimaryTimestampValue(shipment.etaTimestamps)
|
|
163
|
+
const ata = getPrimaryTimestampValue(shipment.ataTimestamps)
|
|
164
|
+
|
|
165
|
+
const newStatus = evaluatePreArrivalUpgrade(shipment.status, { eta, ata })
|
|
166
|
+
|
|
167
|
+
if (newStatus !== shipment.status) {
|
|
168
|
+
const previousStatus = shipment.status
|
|
169
|
+
shipment.status = newStatus
|
|
170
|
+
|
|
171
|
+
// Emit status_changed event
|
|
172
|
+
await eventBus.emit('shipment_tracking.shipment.status_changed', {
|
|
173
|
+
id: shipment.id,
|
|
174
|
+
previousStatus,
|
|
175
|
+
newStatus,
|
|
176
|
+
tenantId: shipment.tenantId,
|
|
177
|
+
organizationId: shipment.organizationId,
|
|
178
|
+
})
|
|
179
|
+
|
|
180
|
+
// Emit pre_arrival lifecycle event
|
|
181
|
+
await eventBus.emit('shipment_tracking.shipment.pre_arrival', {
|
|
182
|
+
id: shipment.id,
|
|
183
|
+
tenantId: shipment.tenantId,
|
|
184
|
+
organizationId: shipment.organizationId,
|
|
185
|
+
})
|
|
186
|
+
|
|
187
|
+
// Emit updated event
|
|
188
|
+
await eventBus.emit('shipment_tracking.shipment.updated', {
|
|
189
|
+
id: shipment.id,
|
|
190
|
+
tenantId: shipment.tenantId,
|
|
191
|
+
organizationId: shipment.organizationId,
|
|
192
|
+
})
|
|
193
|
+
|
|
194
|
+
upgraded++
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
await em.flush()
|
|
199
|
+
|
|
200
|
+
console.log('[shipment-tracking:evaluate_pre_arrival] Command completed:', {
|
|
201
|
+
tenantId: input.tenantId,
|
|
202
|
+
organizationId: input.organizationId,
|
|
203
|
+
evaluated: shipments.length,
|
|
204
|
+
upgraded,
|
|
205
|
+
})
|
|
206
|
+
|
|
207
|
+
return {
|
|
208
|
+
evaluated: shipments.length,
|
|
209
|
+
upgraded,
|
|
210
|
+
}
|
|
211
|
+
},
|
|
212
|
+
|
|
213
|
+
buildLog({ result, input }) {
|
|
214
|
+
return {
|
|
215
|
+
actionLabel: 'Evaluate PRE_ARRIVAL status',
|
|
216
|
+
resourceKind: 'shipment_tracking.tracking',
|
|
217
|
+
resourceId: input.organizationId ?? input.tenantId,
|
|
218
|
+
tenantId: input.tenantId,
|
|
219
|
+
organizationId: input.organizationId,
|
|
220
|
+
details: {
|
|
221
|
+
evaluated: result.evaluated,
|
|
222
|
+
upgraded: result.upgraded,
|
|
223
|
+
},
|
|
224
|
+
}
|
|
225
|
+
},
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
registerCommand(pollAllActiveJobs)
|
|
229
|
+
registerCommand(pollSingleJob)
|
|
230
|
+
registerCommand(evaluatePreArrival)
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { registerCommand } from '@open-mercato/shared/lib/commands'
|
|
2
|
+
import type { CommandHandler, CommandRuntimeContext } from '@open-mercato/shared/lib/commands'
|
|
3
|
+
import type { EntityManager } from '@mikro-orm/postgresql'
|
|
4
|
+
import { findOneWithDecryption, findWithDecryption } from '@open-mercato/shared/lib/encryption/find'
|
|
5
|
+
import { Webhook, WebhookDelivery } from '../data/entities'
|
|
6
|
+
import type { WebhookCreateInput, WebhookUpdateInput } from '../data/validators'
|
|
7
|
+
import { dispatchWebhook } from '../lib/webhook-dispatcher'
|
|
8
|
+
|
|
9
|
+
function ensureScope(ctx: CommandRuntimeContext, tenantId: string, organizationId: string) {
|
|
10
|
+
if (ctx.auth?.tenantId && ctx.auth.tenantId !== tenantId) {
|
|
11
|
+
throw new Error('Tenant mismatch')
|
|
12
|
+
}
|
|
13
|
+
if (!ctx.auth?.isSuperAdmin && ctx.auth?.organizationId && ctx.auth.organizationId !== organizationId) {
|
|
14
|
+
throw new Error('Organization mismatch')
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const createWebhook: CommandHandler<WebhookCreateInput, { id: string }> = {
|
|
19
|
+
id: 'shipment_tracking.webhook.create',
|
|
20
|
+
|
|
21
|
+
async execute(input, ctx) {
|
|
22
|
+
ensureScope(ctx, input.tenantId, input.organizationId)
|
|
23
|
+
|
|
24
|
+
const em = ctx.container.resolve<EntityManager>('em').fork()
|
|
25
|
+
|
|
26
|
+
const webhook = em.create(Webhook, {
|
|
27
|
+
organizationId: input.organizationId,
|
|
28
|
+
tenantId: input.tenantId,
|
|
29
|
+
url: input.url,
|
|
30
|
+
eventsSubscribed: input.eventsSubscribed,
|
|
31
|
+
hmacSecret: input.hmacSecret ?? null,
|
|
32
|
+
isActive: input.isActive ?? true,
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
await em.flush()
|
|
36
|
+
|
|
37
|
+
return { id: webhook.id }
|
|
38
|
+
},
|
|
39
|
+
|
|
40
|
+
async undo({ input, ctx }) {
|
|
41
|
+
const em = ctx.container.resolve<EntityManager>('em').fork()
|
|
42
|
+
const webhooks = await findWithDecryption(em, Webhook, {
|
|
43
|
+
tenantId: input.tenantId,
|
|
44
|
+
organizationId: input.organizationId,
|
|
45
|
+
}, { orderBy: { createdAt: 'desc' }, limit: 1 })
|
|
46
|
+
const webhook = webhooks[0]
|
|
47
|
+
if (webhook) {
|
|
48
|
+
em.remove(webhook)
|
|
49
|
+
await em.flush()
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const updateWebhook: CommandHandler<WebhookUpdateInput, { id: string }> = {
|
|
55
|
+
id: 'shipment_tracking.webhook.update',
|
|
56
|
+
|
|
57
|
+
async execute(input, ctx) {
|
|
58
|
+
const em = ctx.container.resolve<EntityManager>('em').fork()
|
|
59
|
+
|
|
60
|
+
const webhook = await findOneWithDecryption(em, Webhook, { id: input.id })
|
|
61
|
+
if (!webhook) throw new Error('Webhook not found')
|
|
62
|
+
|
|
63
|
+
ensureScope(ctx, webhook.tenantId, webhook.organizationId)
|
|
64
|
+
|
|
65
|
+
if (input.url !== undefined) webhook.url = input.url
|
|
66
|
+
if (input.eventsSubscribed !== undefined) webhook.eventsSubscribed = input.eventsSubscribed
|
|
67
|
+
if (input.hmacSecret !== undefined) webhook.hmacSecret = input.hmacSecret
|
|
68
|
+
if (input.isActive !== undefined) webhook.isActive = input.isActive
|
|
69
|
+
|
|
70
|
+
await em.flush()
|
|
71
|
+
|
|
72
|
+
return { id: webhook.id }
|
|
73
|
+
},
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const deleteWebhook: CommandHandler<{ id: string; tenantId: string; organizationId: string }, { id: string }> = {
|
|
77
|
+
id: 'shipment_tracking.webhook.delete',
|
|
78
|
+
|
|
79
|
+
async execute(input, ctx) {
|
|
80
|
+
ensureScope(ctx, input.tenantId, input.organizationId)
|
|
81
|
+
|
|
82
|
+
const em = ctx.container.resolve<EntityManager>('em').fork()
|
|
83
|
+
|
|
84
|
+
const webhook = await findOneWithDecryption(em, Webhook, { id: input.id })
|
|
85
|
+
if (!webhook) throw new Error('Webhook not found')
|
|
86
|
+
|
|
87
|
+
em.remove(webhook)
|
|
88
|
+
await em.flush()
|
|
89
|
+
|
|
90
|
+
return { id: input.id }
|
|
91
|
+
},
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const testWebhook: CommandHandler<
|
|
95
|
+
{ id: string; tenantId: string; organizationId: string },
|
|
96
|
+
{ success: boolean; deliveryId: string }
|
|
97
|
+
> = {
|
|
98
|
+
id: 'shipment_tracking.webhook.test',
|
|
99
|
+
|
|
100
|
+
async execute(input, ctx) {
|
|
101
|
+
ensureScope(ctx, input.tenantId, input.organizationId)
|
|
102
|
+
|
|
103
|
+
const em = ctx.container.resolve<EntityManager>('em').fork()
|
|
104
|
+
|
|
105
|
+
const webhook = await findOneWithDecryption(em, Webhook, { id: input.id })
|
|
106
|
+
if (!webhook) throw new Error('Webhook not found')
|
|
107
|
+
|
|
108
|
+
if (!webhook.isActive) {
|
|
109
|
+
throw new Error('Webhook is inactive')
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// Build test payload
|
|
113
|
+
const testPayload = {
|
|
114
|
+
type: 'test',
|
|
115
|
+
event: 'webhook.test',
|
|
116
|
+
message: 'This is a test webhook delivery from Shipment Tracking',
|
|
117
|
+
timestamp: new Date().toISOString(),
|
|
118
|
+
webhookId: webhook.id,
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// Create delivery record
|
|
122
|
+
// Use getReference to create a managed reference since webhook may be detached after decryption
|
|
123
|
+
const delivery = em.create(WebhookDelivery, {
|
|
124
|
+
webhook: em.getReference(Webhook, webhook.id),
|
|
125
|
+
eventType: 'webhook.test',
|
|
126
|
+
status: 'pending',
|
|
127
|
+
payload: testPayload,
|
|
128
|
+
retryCount: 0,
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
em.persist(delivery)
|
|
132
|
+
await em.flush()
|
|
133
|
+
|
|
134
|
+
// Dispatch synchronously for immediate feedback
|
|
135
|
+
const result = await dispatchWebhook({
|
|
136
|
+
url: webhook.url,
|
|
137
|
+
payload: testPayload,
|
|
138
|
+
hmacSecret: webhook.hmacSecret,
|
|
139
|
+
})
|
|
140
|
+
|
|
141
|
+
// Update delivery record with result
|
|
142
|
+
delivery.responseStatus = result.responseStatus ?? null
|
|
143
|
+
delivery.responseBody = result.responseBody ?? null
|
|
144
|
+
delivery.status = result.success ? 'success' : 'failed'
|
|
145
|
+
delivery.errorMessage = result.errorMessage ?? null
|
|
146
|
+
await em.flush()
|
|
147
|
+
|
|
148
|
+
if (!result.success) {
|
|
149
|
+
throw new Error(result.errorMessage || 'Webhook delivery failed')
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
return { success: true, deliveryId: delivery.id }
|
|
153
|
+
},
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
registerCommand(createWebhook)
|
|
157
|
+
registerCommand(updateWebhook)
|
|
158
|
+
registerCommand(deleteWebhook)
|
|
159
|
+
registerCommand(testWebhook)
|