@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,89 @@
|
|
|
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 } from '@open-mercato/shared/lib/encryption/find'
|
|
5
|
+
import { CarrierConfig } from '../data/entities'
|
|
6
|
+
import type { CarrierConfigCreateInput, CarrierConfigUpdateInput } from '../data/validators'
|
|
7
|
+
|
|
8
|
+
function ensureScope(ctx: CommandRuntimeContext, tenantId: string, organizationId: string) {
|
|
9
|
+
if (ctx.auth?.tenantId && ctx.auth.tenantId !== tenantId) {
|
|
10
|
+
throw new Error('Tenant mismatch')
|
|
11
|
+
}
|
|
12
|
+
if (!ctx.auth?.isSuperAdmin && ctx.auth?.organizationId && ctx.auth.organizationId !== organizationId) {
|
|
13
|
+
throw new Error('Organization mismatch')
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const createCarrierConfig: CommandHandler<CarrierConfigCreateInput, { id: string }> = {
|
|
18
|
+
id: 'shipment_tracking.carrier_config.create',
|
|
19
|
+
|
|
20
|
+
async execute(input, ctx) {
|
|
21
|
+
ensureScope(ctx, input.tenantId, input.organizationId)
|
|
22
|
+
|
|
23
|
+
const em = ctx.container.resolve<EntityManager>('em').fork()
|
|
24
|
+
|
|
25
|
+
const carrierConfig = em.create(CarrierConfig, {
|
|
26
|
+
organizationId: input.organizationId,
|
|
27
|
+
tenantId: input.tenantId,
|
|
28
|
+
carrierCode: input.carrierCode,
|
|
29
|
+
apiEndpoint: input.apiEndpoint ?? null,
|
|
30
|
+
authConfig: input.authConfig ?? null,
|
|
31
|
+
rateLimitRequests: input.rateLimitRequests ?? 60,
|
|
32
|
+
rateLimitWindowSeconds: input.rateLimitWindowSeconds ?? 60,
|
|
33
|
+
isActive: input.isActive ?? true,
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
await em.flush()
|
|
37
|
+
|
|
38
|
+
return { id: carrierConfig.id }
|
|
39
|
+
},
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const updateCarrierConfig: CommandHandler<CarrierConfigUpdateInput, { id: string }> = {
|
|
43
|
+
id: 'shipment_tracking.carrier_config.update',
|
|
44
|
+
|
|
45
|
+
async execute(input, ctx) {
|
|
46
|
+
const em = ctx.container.resolve<EntityManager>('em').fork()
|
|
47
|
+
|
|
48
|
+
const carrierConfig = await findOneWithDecryption(em, CarrierConfig, { id: input.id, deletedAt: null })
|
|
49
|
+
if (!carrierConfig) throw new Error('Carrier config not found')
|
|
50
|
+
|
|
51
|
+
ensureScope(ctx, carrierConfig.tenantId, carrierConfig.organizationId)
|
|
52
|
+
|
|
53
|
+
if (input.apiEndpoint !== undefined) carrierConfig.apiEndpoint = input.apiEndpoint
|
|
54
|
+
if (input.authConfig !== undefined) carrierConfig.authConfig = input.authConfig
|
|
55
|
+
if (input.rateLimitRequests !== undefined) carrierConfig.rateLimitRequests = input.rateLimitRequests
|
|
56
|
+
if (input.rateLimitWindowSeconds !== undefined) carrierConfig.rateLimitWindowSeconds = input.rateLimitWindowSeconds
|
|
57
|
+
if (input.isActive !== undefined) carrierConfig.isActive = input.isActive
|
|
58
|
+
|
|
59
|
+
await em.flush()
|
|
60
|
+
|
|
61
|
+
return { id: carrierConfig.id }
|
|
62
|
+
},
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const deleteCarrierConfig: CommandHandler<{ id: string; tenantId: string; organizationId: string }, { id: string }> = {
|
|
66
|
+
id: 'shipment_tracking.carrier_config.delete',
|
|
67
|
+
|
|
68
|
+
async execute(input, ctx) {
|
|
69
|
+
const em = ctx.container.resolve<EntityManager>('em').fork()
|
|
70
|
+
|
|
71
|
+
// Fetch first, then validate scope (same pattern as update)
|
|
72
|
+
const carrierConfig = await findOneWithDecryption(em, CarrierConfig, {
|
|
73
|
+
id: input.id,
|
|
74
|
+
deletedAt: null,
|
|
75
|
+
})
|
|
76
|
+
if (!carrierConfig) throw new Error('Carrier config not found')
|
|
77
|
+
|
|
78
|
+
ensureScope(ctx, carrierConfig.tenantId, carrierConfig.organizationId)
|
|
79
|
+
|
|
80
|
+
carrierConfig.deletedAt = new Date()
|
|
81
|
+
await em.flush()
|
|
82
|
+
|
|
83
|
+
return { id: carrierConfig.id }
|
|
84
|
+
},
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
registerCommand(createCarrierConfig)
|
|
88
|
+
registerCommand(updateCarrierConfig)
|
|
89
|
+
registerCommand(deleteCarrierConfig)
|
|
@@ -0,0 +1,119 @@
|
|
|
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 } from '@open-mercato/shared/lib/encryption/find'
|
|
5
|
+
import { LocationOverride } from '../data/entities'
|
|
6
|
+
import type { LocationOverrideCreateInput, LocationOverrideUpdateInput } from '../data/validators'
|
|
7
|
+
|
|
8
|
+
function ensureScope(ctx: CommandRuntimeContext, tenantId: string, organizationId: string) {
|
|
9
|
+
if (ctx.auth?.tenantId && ctx.auth.tenantId !== tenantId) {
|
|
10
|
+
throw new Error('Tenant mismatch')
|
|
11
|
+
}
|
|
12
|
+
if (!ctx.auth?.isSuperAdmin && ctx.auth?.organizationId && ctx.auth.organizationId !== organizationId) {
|
|
13
|
+
throw new Error('Organization mismatch')
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const createLocationOverride: CommandHandler<LocationOverrideCreateInput, { id: string }> = {
|
|
18
|
+
id: 'shipment_tracking.location_override.create',
|
|
19
|
+
|
|
20
|
+
async execute(input, ctx) {
|
|
21
|
+
ensureScope(ctx, input.tenantId, input.organizationId)
|
|
22
|
+
|
|
23
|
+
const em = ctx.container.resolve<EntityManager>('em').fork()
|
|
24
|
+
|
|
25
|
+
const override = em.create(LocationOverride, {
|
|
26
|
+
organizationId: input.organizationId,
|
|
27
|
+
tenantId: input.tenantId,
|
|
28
|
+
carrierCode: input.carrierCode?.toUpperCase() ?? null,
|
|
29
|
+
unlocode: input.unlocode.toUpperCase(),
|
|
30
|
+
facilityCode: input.facilityCode,
|
|
31
|
+
facilityCodeListProvider: input.facilityCodeListProvider,
|
|
32
|
+
overrideData: input.overrideData,
|
|
33
|
+
description: input.description ?? null,
|
|
34
|
+
isActive: input.isActive ?? true,
|
|
35
|
+
createdByUserId: ctx.auth?.userId ?? null,
|
|
36
|
+
updatedByUserId: ctx.auth?.userId ?? null,
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
await em.flush()
|
|
40
|
+
|
|
41
|
+
return { id: override.id }
|
|
42
|
+
},
|
|
43
|
+
|
|
44
|
+
async undo({ input, ctx }) {
|
|
45
|
+
const em = ctx.container.resolve<EntityManager>('em').fork()
|
|
46
|
+
const override = await findOneWithDecryption(em, LocationOverride, {
|
|
47
|
+
tenantId: input.tenantId,
|
|
48
|
+
organizationId: input.organizationId,
|
|
49
|
+
unlocode: input.unlocode,
|
|
50
|
+
facilityCode: input.facilityCode,
|
|
51
|
+
facilityCodeListProvider: input.facilityCodeListProvider,
|
|
52
|
+
carrierCode: input.carrierCode ?? null,
|
|
53
|
+
})
|
|
54
|
+
if (override) {
|
|
55
|
+
em.remove(override)
|
|
56
|
+
await em.flush()
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const updateLocationOverride: CommandHandler<LocationOverrideUpdateInput, { id: string }> = {
|
|
62
|
+
id: 'shipment_tracking.location_override.update',
|
|
63
|
+
|
|
64
|
+
async execute(input, ctx) {
|
|
65
|
+
const em = ctx.container.resolve<EntityManager>('em').fork()
|
|
66
|
+
|
|
67
|
+
const override = await findOneWithDecryption(em, LocationOverride, { id: input.id })
|
|
68
|
+
if (!override) throw new Error('Location override not found')
|
|
69
|
+
|
|
70
|
+
ensureScope(ctx, override.tenantId, override.organizationId)
|
|
71
|
+
|
|
72
|
+
if (input.carrierCode !== undefined) override.carrierCode = input.carrierCode?.toUpperCase() ?? null
|
|
73
|
+
if (input.unlocode !== undefined) override.unlocode = input.unlocode.toUpperCase()
|
|
74
|
+
if (input.facilityCode !== undefined) override.facilityCode = input.facilityCode
|
|
75
|
+
if (input.facilityCodeListProvider !== undefined) override.facilityCodeListProvider = input.facilityCodeListProvider
|
|
76
|
+
if (input.overrideData !== undefined) override.overrideData = input.overrideData
|
|
77
|
+
if (input.description !== undefined) override.description = input.description
|
|
78
|
+
if (input.isActive !== undefined) override.isActive = input.isActive
|
|
79
|
+
override.updatedByUserId = ctx.auth?.userId ?? null
|
|
80
|
+
|
|
81
|
+
await em.flush()
|
|
82
|
+
|
|
83
|
+
return { id: override.id }
|
|
84
|
+
},
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const deleteLocationOverride: CommandHandler<{ id: string; tenantId: string; organizationId: string }, { id: string }> = {
|
|
88
|
+
id: 'shipment_tracking.location_override.delete',
|
|
89
|
+
|
|
90
|
+
async execute(input, ctx) {
|
|
91
|
+
ensureScope(ctx, input.tenantId, input.organizationId)
|
|
92
|
+
|
|
93
|
+
const em = ctx.container.resolve<EntityManager>('em').fork()
|
|
94
|
+
|
|
95
|
+
const override = await findOneWithDecryption(em, LocationOverride, { id: input.id })
|
|
96
|
+
if (!override) throw new Error('Location override not found')
|
|
97
|
+
|
|
98
|
+
// Soft delete
|
|
99
|
+
override.deletedAt = new Date()
|
|
100
|
+
override.updatedByUserId = ctx.auth?.userId ?? null
|
|
101
|
+
await em.flush()
|
|
102
|
+
|
|
103
|
+
return { id: input.id }
|
|
104
|
+
},
|
|
105
|
+
|
|
106
|
+
async undo({ input, ctx }) {
|
|
107
|
+
const em = ctx.container.resolve<EntityManager>('em').fork()
|
|
108
|
+
const override = await em.findOne(LocationOverride, { id: input.id })
|
|
109
|
+
if (override) {
|
|
110
|
+
override.deletedAt = null
|
|
111
|
+
override.updatedByUserId = ctx.auth?.userId ?? null
|
|
112
|
+
await em.flush()
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
registerCommand(createLocationOverride)
|
|
118
|
+
registerCommand(updateLocationOverride)
|
|
119
|
+
registerCommand(deleteLocationOverride)
|
|
@@ -0,0 +1,247 @@
|
|
|
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 { Shipment, TrackingJob } from '../data/entities'
|
|
6
|
+
import type { ShipmentCreateInput, ShipmentUpdateInput } from '../data/validators'
|
|
7
|
+
import { createTimestampEntry, addTimestampEntry } from '../lib/timestamp-utils'
|
|
8
|
+
import type { TimestampSource } 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 (!ctx.auth?.isSuperAdmin && ctx.auth?.organizationId && ctx.auth.organizationId !== organizationId) {
|
|
15
|
+
throw new Error('Organization mismatch')
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const createShipment: CommandHandler<ShipmentCreateInput, { id: string }> = {
|
|
20
|
+
id: 'shipment_tracking.shipment.create',
|
|
21
|
+
|
|
22
|
+
async execute(input, ctx) {
|
|
23
|
+
ensureScope(ctx, input.tenantId, input.organizationId)
|
|
24
|
+
|
|
25
|
+
const em = ctx.container.resolve<EntityManager>('em').fork()
|
|
26
|
+
const eventBus = ctx.container.resolve<EventBus>('eventBus')
|
|
27
|
+
|
|
28
|
+
// If trackingJobId is provided, verify it exists
|
|
29
|
+
let trackingJob: TrackingJob | null = null
|
|
30
|
+
if (input.trackingJobId) {
|
|
31
|
+
trackingJob = await em.findOne(TrackingJob, {
|
|
32
|
+
id: input.trackingJobId,
|
|
33
|
+
tenantId: input.tenantId,
|
|
34
|
+
organizationId: input.organizationId,
|
|
35
|
+
deletedAt: null,
|
|
36
|
+
})
|
|
37
|
+
if (!trackingJob) throw new Error('Tracking job not found')
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const shipment = em.create(Shipment, {
|
|
41
|
+
organizationId: input.organizationId,
|
|
42
|
+
tenantId: input.tenantId,
|
|
43
|
+
trackingJob: trackingJob ?? undefined,
|
|
44
|
+
carrierCode: input.carrierCode ?? null,
|
|
45
|
+
containerNumber: input.containerNumber ?? null,
|
|
46
|
+
bookingNumber: input.bookingNumber ?? null,
|
|
47
|
+
bolNumber: input.bolNumber ?? null,
|
|
48
|
+
// Multi-source timestamp arrays
|
|
49
|
+
etdTimestamps: input.etdTimestamps ?? null,
|
|
50
|
+
etaTimestamps: input.etaTimestamps ?? null,
|
|
51
|
+
atdTimestamps: input.atdTimestamps ?? null,
|
|
52
|
+
ataTimestamps: input.ataTimestamps ?? null,
|
|
53
|
+
// Location data (JSONB)
|
|
54
|
+
originLocation: input.originLocation ?? null,
|
|
55
|
+
destinationLocation: input.destinationLocation ?? null,
|
|
56
|
+
vesselName: input.vesselName ?? null,
|
|
57
|
+
vesselImo: input.vesselImo ?? null,
|
|
58
|
+
voyageNumber: input.voyageNumber ?? null,
|
|
59
|
+
extra: input.extra ?? null,
|
|
60
|
+
createdByUserId: ctx.auth?.userId ?? null,
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
await em.flush()
|
|
64
|
+
|
|
65
|
+
await eventBus.emit('shipment_tracking.shipment.created', {
|
|
66
|
+
id: shipment.id,
|
|
67
|
+
containerNumber: shipment.containerNumber,
|
|
68
|
+
trackingJobId: trackingJob?.id ?? null,
|
|
69
|
+
tenantId: input.tenantId,
|
|
70
|
+
organizationId: input.organizationId,
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
return { id: shipment.id }
|
|
74
|
+
},
|
|
75
|
+
|
|
76
|
+
buildLog({ result, input }) {
|
|
77
|
+
return {
|
|
78
|
+
actionLabel: 'Create shipment',
|
|
79
|
+
resourceKind: 'shipment_tracking.shipment',
|
|
80
|
+
resourceId: result.id,
|
|
81
|
+
tenantId: input.tenantId,
|
|
82
|
+
organizationId: input.organizationId,
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
|
|
86
|
+
async undo({ logEntry, ctx }) {
|
|
87
|
+
const shipmentId = logEntry?.resourceId
|
|
88
|
+
if (!shipmentId) return
|
|
89
|
+
const em = ctx.container.resolve<EntityManager>('em').fork()
|
|
90
|
+
// Use nativeUpdate to avoid identity map issues
|
|
91
|
+
const now = new Date()
|
|
92
|
+
await em.nativeUpdate(Shipment, { id: shipmentId, deletedAt: null }, { deletedAt: now, updatedAt: now })
|
|
93
|
+
},
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const updateShipment: CommandHandler<ShipmentUpdateInput, { id: string }> = {
|
|
97
|
+
id: 'shipment_tracking.shipment.update',
|
|
98
|
+
|
|
99
|
+
async execute(input, ctx) {
|
|
100
|
+
const em = ctx.container.resolve<EntityManager>('em').fork()
|
|
101
|
+
const eventBus = ctx.container.resolve<EventBus>('eventBus')
|
|
102
|
+
|
|
103
|
+
const shipment = await em.findOne(Shipment, { id: input.id, deletedAt: null })
|
|
104
|
+
if (!shipment) throw new Error('Shipment not found')
|
|
105
|
+
|
|
106
|
+
ensureScope(ctx, shipment.tenantId, shipment.organizationId)
|
|
107
|
+
|
|
108
|
+
const previousStatus = shipment.status
|
|
109
|
+
|
|
110
|
+
// Handle trackingJobId change
|
|
111
|
+
if (input.trackingJobId !== undefined) {
|
|
112
|
+
if (input.trackingJobId === null) {
|
|
113
|
+
shipment.trackingJob = null
|
|
114
|
+
} else {
|
|
115
|
+
const trackingJob = await em.findOne(TrackingJob, {
|
|
116
|
+
id: input.trackingJobId,
|
|
117
|
+
tenantId: shipment.tenantId,
|
|
118
|
+
organizationId: shipment.organizationId,
|
|
119
|
+
deletedAt: null,
|
|
120
|
+
})
|
|
121
|
+
if (!trackingJob) throw new Error('Tracking job not found')
|
|
122
|
+
shipment.trackingJob = trackingJob
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (input.carrierCode !== undefined) shipment.carrierCode = input.carrierCode
|
|
127
|
+
if (input.containerNumber !== undefined) shipment.containerNumber = input.containerNumber
|
|
128
|
+
if (input.bookingNumber !== undefined) shipment.bookingNumber = input.bookingNumber
|
|
129
|
+
if (input.bolNumber !== undefined) shipment.bolNumber = input.bolNumber
|
|
130
|
+
if (input.status !== undefined) shipment.status = input.status
|
|
131
|
+
|
|
132
|
+
// Multi-source timestamp arrays - can replace entire arrays
|
|
133
|
+
if (input.etdTimestamps !== undefined) shipment.etdTimestamps = input.etdTimestamps
|
|
134
|
+
if (input.etaTimestamps !== undefined) shipment.etaTimestamps = input.etaTimestamps
|
|
135
|
+
if (input.atdTimestamps !== undefined) shipment.atdTimestamps = input.atdTimestamps
|
|
136
|
+
if (input.ataTimestamps !== undefined) shipment.ataTimestamps = input.ataTimestamps
|
|
137
|
+
|
|
138
|
+
// Convenience: add single timestamp entries (e.g., manual overrides)
|
|
139
|
+
if (input.addEtdTimestamp) {
|
|
140
|
+
const entry = createTimestampEntry(
|
|
141
|
+
input.addEtdTimestamp.value,
|
|
142
|
+
input.addEtdTimestamp.offset ?? null,
|
|
143
|
+
input.addEtdTimestamp.source as TimestampSource,
|
|
144
|
+
input.addEtdTimestamp.sourceEventId,
|
|
145
|
+
)
|
|
146
|
+
shipment.etdTimestamps = addTimestampEntry(shipment.etdTimestamps, entry)
|
|
147
|
+
}
|
|
148
|
+
if (input.addEtaTimestamp) {
|
|
149
|
+
const entry = createTimestampEntry(
|
|
150
|
+
input.addEtaTimestamp.value,
|
|
151
|
+
input.addEtaTimestamp.offset ?? null,
|
|
152
|
+
input.addEtaTimestamp.source as TimestampSource,
|
|
153
|
+
input.addEtaTimestamp.sourceEventId,
|
|
154
|
+
)
|
|
155
|
+
shipment.etaTimestamps = addTimestampEntry(shipment.etaTimestamps, entry)
|
|
156
|
+
}
|
|
157
|
+
if (input.addAtdTimestamp) {
|
|
158
|
+
const entry = createTimestampEntry(
|
|
159
|
+
input.addAtdTimestamp.value,
|
|
160
|
+
input.addAtdTimestamp.offset ?? null,
|
|
161
|
+
input.addAtdTimestamp.source as TimestampSource,
|
|
162
|
+
input.addAtdTimestamp.sourceEventId,
|
|
163
|
+
)
|
|
164
|
+
shipment.atdTimestamps = addTimestampEntry(shipment.atdTimestamps, entry)
|
|
165
|
+
}
|
|
166
|
+
if (input.addAtaTimestamp) {
|
|
167
|
+
const entry = createTimestampEntry(
|
|
168
|
+
input.addAtaTimestamp.value,
|
|
169
|
+
input.addAtaTimestamp.offset ?? null,
|
|
170
|
+
input.addAtaTimestamp.source as TimestampSource,
|
|
171
|
+
input.addAtaTimestamp.sourceEventId,
|
|
172
|
+
)
|
|
173
|
+
shipment.ataTimestamps = addTimestampEntry(shipment.ataTimestamps, entry)
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// Location data
|
|
177
|
+
if (input.originLocation !== undefined) shipment.originLocation = input.originLocation
|
|
178
|
+
if (input.destinationLocation !== undefined) shipment.destinationLocation = input.destinationLocation
|
|
179
|
+
if (input.vesselName !== undefined) shipment.vesselName = input.vesselName
|
|
180
|
+
if (input.vesselImo !== undefined) shipment.vesselImo = input.vesselImo
|
|
181
|
+
if (input.voyageNumber !== undefined) shipment.voyageNumber = input.voyageNumber
|
|
182
|
+
if (input.extra !== undefined) shipment.extra = input.extra
|
|
183
|
+
|
|
184
|
+
await em.flush()
|
|
185
|
+
|
|
186
|
+
await eventBus.emit('shipment_tracking.shipment.updated', {
|
|
187
|
+
id: shipment.id,
|
|
188
|
+
tenantId: shipment.tenantId,
|
|
189
|
+
organizationId: shipment.organizationId,
|
|
190
|
+
})
|
|
191
|
+
|
|
192
|
+
if (input.status && previousStatus !== input.status) {
|
|
193
|
+
await eventBus.emit('shipment_tracking.shipment.status_changed', {
|
|
194
|
+
id: shipment.id,
|
|
195
|
+
previousStatus,
|
|
196
|
+
newStatus: input.status,
|
|
197
|
+
tenantId: shipment.tenantId,
|
|
198
|
+
organizationId: shipment.organizationId,
|
|
199
|
+
})
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
return { id: shipment.id }
|
|
203
|
+
},
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
const deleteShipment: CommandHandler<{ id: string; tenantId: string; organizationId: string }, { id: string }> = {
|
|
207
|
+
id: 'shipment_tracking.shipment.delete',
|
|
208
|
+
|
|
209
|
+
async execute(input, ctx) {
|
|
210
|
+
ensureScope(ctx, input.tenantId, input.organizationId)
|
|
211
|
+
|
|
212
|
+
const em = ctx.container.resolve<EntityManager>('em').fork()
|
|
213
|
+
const eventBus = ctx.container.resolve<EventBus>('eventBus')
|
|
214
|
+
|
|
215
|
+
// First verify the shipment exists and is not already deleted
|
|
216
|
+
const shipment = await em.findOne(Shipment, { id: input.id, deletedAt: null })
|
|
217
|
+
if (!shipment) throw new Error('Shipment not found')
|
|
218
|
+
|
|
219
|
+
const shipmentId = shipment.id
|
|
220
|
+
const tenantId = shipment.tenantId
|
|
221
|
+
const organizationId = shipment.organizationId
|
|
222
|
+
|
|
223
|
+
// Use nativeUpdate to avoid any MikroORM identity map issues
|
|
224
|
+
const now = new Date()
|
|
225
|
+
const affected = await em.nativeUpdate(
|
|
226
|
+
Shipment,
|
|
227
|
+
{ id: shipmentId, deletedAt: null },
|
|
228
|
+
{ deletedAt: now, updatedAt: now },
|
|
229
|
+
)
|
|
230
|
+
|
|
231
|
+
if (affected === 0) {
|
|
232
|
+
throw new Error('Shipment not found or already deleted')
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
await eventBus.emit('shipment_tracking.shipment.deleted', {
|
|
236
|
+
id: shipmentId,
|
|
237
|
+
tenantId,
|
|
238
|
+
organizationId,
|
|
239
|
+
})
|
|
240
|
+
|
|
241
|
+
return { id: shipmentId }
|
|
242
|
+
},
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
registerCommand(createShipment)
|
|
246
|
+
registerCommand(updateShipment)
|
|
247
|
+
registerCommand(deleteShipment)
|
|
@@ -0,0 +1,101 @@
|
|
|
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 } from '@open-mercato/shared/lib/encryption/find'
|
|
5
|
+
import { ShipsGoConfig } from '../data/entities'
|
|
6
|
+
import type { ShipsGoConfigUpsertInput } from '../data/validators'
|
|
7
|
+
|
|
8
|
+
function ensureScope(ctx: CommandRuntimeContext, tenantId: string, organizationId: string) {
|
|
9
|
+
if (ctx.auth?.tenantId && ctx.auth.tenantId !== tenantId) {
|
|
10
|
+
throw new Error('Tenant mismatch')
|
|
11
|
+
}
|
|
12
|
+
if (!ctx.auth?.isSuperAdmin && ctx.auth?.organizationId && ctx.auth.organizationId !== organizationId) {
|
|
13
|
+
throw new Error('Organization mismatch')
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Upsert the ShipsGo config — one row per organization/tenant. The api_token
|
|
19
|
+
* sentinel '__UNCHANGED__' leaves the stored (encrypted) token intact so the
|
|
20
|
+
* UI can round-trip without ever seeing the plaintext.
|
|
21
|
+
*/
|
|
22
|
+
const upsertShipsGoConfig: CommandHandler<ShipsGoConfigUpsertInput, { id: string }> = {
|
|
23
|
+
id: 'shipment_tracking.shipsgo_config.upsert',
|
|
24
|
+
|
|
25
|
+
async execute(input, ctx) {
|
|
26
|
+
ensureScope(ctx, input.tenantId, input.organizationId)
|
|
27
|
+
|
|
28
|
+
const em = ctx.container.resolve<EntityManager>('em').fork()
|
|
29
|
+
|
|
30
|
+
let config = await findOneWithDecryption(
|
|
31
|
+
em,
|
|
32
|
+
ShipsGoConfig,
|
|
33
|
+
{ organizationId: input.organizationId, tenantId: input.tenantId },
|
|
34
|
+
{},
|
|
35
|
+
{ tenantId: input.tenantId, organizationId: input.organizationId },
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
if (config) {
|
|
39
|
+
config.isEnabled = input.isEnabled
|
|
40
|
+
if (input.apiToken && input.apiToken !== '__UNCHANGED__') {
|
|
41
|
+
config.apiToken = input.apiToken
|
|
42
|
+
}
|
|
43
|
+
config.baseUrl = input.baseUrl ?? 'https://api.shipsgo.com/v2'
|
|
44
|
+
config.oceanEnabled = input.oceanEnabled
|
|
45
|
+
config.airEnabled = input.airEnabled
|
|
46
|
+
config.rateLimitRequests = input.rateLimitRequests
|
|
47
|
+
config.rateLimitWindowSeconds = input.rateLimitWindowSeconds
|
|
48
|
+
// Re-configuring after a soft delete revives the row.
|
|
49
|
+
config.isActive = true
|
|
50
|
+
config.deletedAt = null
|
|
51
|
+
} else {
|
|
52
|
+
config = em.create(ShipsGoConfig, {
|
|
53
|
+
organizationId: input.organizationId,
|
|
54
|
+
tenantId: input.tenantId,
|
|
55
|
+
isEnabled: input.isEnabled,
|
|
56
|
+
apiToken: input.apiToken,
|
|
57
|
+
baseUrl: input.baseUrl ?? 'https://api.shipsgo.com/v2',
|
|
58
|
+
oceanEnabled: input.oceanEnabled,
|
|
59
|
+
airEnabled: input.airEnabled,
|
|
60
|
+
rateLimitRequests: input.rateLimitRequests,
|
|
61
|
+
rateLimitWindowSeconds: input.rateLimitWindowSeconds,
|
|
62
|
+
})
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
await em.flush()
|
|
66
|
+
|
|
67
|
+
return { id: config.id }
|
|
68
|
+
},
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const deleteShipsGoConfig: CommandHandler<{ tenantId: string; organizationId: string }, { success: boolean }> = {
|
|
72
|
+
id: 'shipment_tracking.shipsgo_config.delete',
|
|
73
|
+
|
|
74
|
+
async execute(input, ctx) {
|
|
75
|
+
ensureScope(ctx, input.tenantId, input.organizationId)
|
|
76
|
+
|
|
77
|
+
const em = ctx.container.resolve<EntityManager>('em').fork()
|
|
78
|
+
|
|
79
|
+
const config = await findOneWithDecryption(
|
|
80
|
+
em,
|
|
81
|
+
ShipsGoConfig,
|
|
82
|
+
{ organizationId: input.organizationId, tenantId: input.tenantId },
|
|
83
|
+
{},
|
|
84
|
+
{ tenantId: input.tenantId, organizationId: input.organizationId },
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
if (config) {
|
|
88
|
+
// Soft-delete: preserve the row (and its encrypted token) for audit, and
|
|
89
|
+
// stop it driving tracking. resolveConfig filters `deletedAt: null`, so a
|
|
90
|
+
// soft-deleted config falls back to the platform env account like no row.
|
|
91
|
+
config.isActive = false
|
|
92
|
+
config.deletedAt = new Date()
|
|
93
|
+
await em.flush()
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return { success: true }
|
|
97
|
+
},
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
registerCommand(upsertShipsGoConfig)
|
|
101
|
+
registerCommand(deleteShipsGoConfig)
|