@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,467 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import * as React from 'react'
|
|
4
|
+
import { useState, useCallback, useEffect } from 'react'
|
|
5
|
+
import { useQueryClient } from '@tanstack/react-query'
|
|
6
|
+
import { Radar, Ship, Package, FileText, MapPin } from 'lucide-react'
|
|
7
|
+
import {
|
|
8
|
+
Sheet,
|
|
9
|
+
SheetContent,
|
|
10
|
+
SheetHeader,
|
|
11
|
+
SheetTitle,
|
|
12
|
+
SheetDescription,
|
|
13
|
+
} from '@freighttech/ui/primitives/sheet'
|
|
14
|
+
import { Button } from '@freighttech/ui/primitives/button'
|
|
15
|
+
import { Input } from '@freighttech/ui/primitives/input'
|
|
16
|
+
import { Label } from '@freighttech/ui/primitives/label'
|
|
17
|
+
import { Spinner } from '@freighttech/ui/primitives/spinner'
|
|
18
|
+
import { apiCall } from '@freighttech/ui/backend/utils/apiCall'
|
|
19
|
+
import { flash } from '@freighttech/ui/backend/FlashMessages'
|
|
20
|
+
import { useT } from '@open-mercato/shared/lib/i18n/context'
|
|
21
|
+
|
|
22
|
+
// Reference type options
|
|
23
|
+
const REFERENCE_TYPES = [
|
|
24
|
+
{ id: 'container', label: 'Container Number', icon: Package },
|
|
25
|
+
{ id: 'booking', label: 'Booking Number', icon: FileText },
|
|
26
|
+
{ id: 'bol', label: 'Bill of Lading', icon: FileText },
|
|
27
|
+
] as const
|
|
28
|
+
|
|
29
|
+
type ReferenceType = typeof REFERENCE_TYPES[number]['id']
|
|
30
|
+
|
|
31
|
+
interface CarrierOption {
|
|
32
|
+
carrierCode: string
|
|
33
|
+
isActive: boolean
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
interface TrackingJobFormData {
|
|
37
|
+
carrierCode: string
|
|
38
|
+
referenceType: ReferenceType
|
|
39
|
+
referenceValue: string
|
|
40
|
+
originUnlocode: string
|
|
41
|
+
destinationUnlocode: string
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
interface TrackingJobData {
|
|
45
|
+
id: string
|
|
46
|
+
carrierCode: string
|
|
47
|
+
referenceType: ReferenceType
|
|
48
|
+
referenceValue: string
|
|
49
|
+
originUnlocode: string
|
|
50
|
+
destinationUnlocode: string
|
|
51
|
+
status: string
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
interface TrackingJobDrawerProps {
|
|
55
|
+
open: boolean
|
|
56
|
+
onOpenChange: (open: boolean) => void
|
|
57
|
+
mode: 'create' | 'edit'
|
|
58
|
+
trackingJobId?: string
|
|
59
|
+
onSaved?: (trackingJob: { id: string }) => void
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const initialFormData: TrackingJobFormData = {
|
|
63
|
+
carrierCode: '',
|
|
64
|
+
referenceType: 'container',
|
|
65
|
+
referenceValue: '',
|
|
66
|
+
originUnlocode: '',
|
|
67
|
+
destinationUnlocode: '',
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function TrackingJobDrawer({
|
|
71
|
+
open,
|
|
72
|
+
onOpenChange,
|
|
73
|
+
mode,
|
|
74
|
+
trackingJobId,
|
|
75
|
+
onSaved,
|
|
76
|
+
}: TrackingJobDrawerProps) {
|
|
77
|
+
const t = useT()
|
|
78
|
+
const queryClient = useQueryClient()
|
|
79
|
+
const [isSubmitting, setIsSubmitting] = useState(false)
|
|
80
|
+
const [formData, setFormData] = useState<TrackingJobFormData>(initialFormData)
|
|
81
|
+
const [carriers, setCarriers] = useState<CarrierOption[]>([])
|
|
82
|
+
const [isLoadingCarriers, setIsLoadingCarriers] = useState(false)
|
|
83
|
+
const [isLoadingJob, setIsLoadingJob] = useState(mode === 'edit' && !!trackingJobId)
|
|
84
|
+
|
|
85
|
+
// Fetch available carriers on open
|
|
86
|
+
useEffect(() => {
|
|
87
|
+
if (!open) return
|
|
88
|
+
|
|
89
|
+
setIsLoadingCarriers(true)
|
|
90
|
+
apiCall<{ items: CarrierOption[] }>('/api/shipment_tracking/carrier-configs?isActive=true&pageSize=100')
|
|
91
|
+
.then((response) => {
|
|
92
|
+
if (response.ok && response.result?.items) {
|
|
93
|
+
setCarriers(response.result.items)
|
|
94
|
+
}
|
|
95
|
+
})
|
|
96
|
+
.catch(() => {
|
|
97
|
+
// Silently fail - user will see empty carrier list
|
|
98
|
+
})
|
|
99
|
+
.finally(() => {
|
|
100
|
+
setIsLoadingCarriers(false)
|
|
101
|
+
})
|
|
102
|
+
}, [open])
|
|
103
|
+
|
|
104
|
+
// Fetch and populate form when opening in edit mode
|
|
105
|
+
useEffect(() => {
|
|
106
|
+
if (!open) return
|
|
107
|
+
|
|
108
|
+
if (mode === 'create') {
|
|
109
|
+
setFormData(initialFormData)
|
|
110
|
+
setIsLoadingJob(false)
|
|
111
|
+
return
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// Edit mode - fetch the tracking job data
|
|
115
|
+
if (mode === 'edit' && trackingJobId) {
|
|
116
|
+
setIsLoadingJob(true)
|
|
117
|
+
apiCall<{ items: TrackingJobData[] }>(`/api/shipment_tracking/tracking-jobs?id=${trackingJobId}`)
|
|
118
|
+
.then((response) => {
|
|
119
|
+
if (response.ok && response.result?.items?.[0]) {
|
|
120
|
+
const data = response.result.items[0]
|
|
121
|
+
setFormData({
|
|
122
|
+
carrierCode: data.carrierCode || '',
|
|
123
|
+
referenceType: data.referenceType || 'container',
|
|
124
|
+
referenceValue: data.referenceValue || '',
|
|
125
|
+
originUnlocode: data.originUnlocode || '',
|
|
126
|
+
destinationUnlocode: data.destinationUnlocode || '',
|
|
127
|
+
})
|
|
128
|
+
}
|
|
129
|
+
})
|
|
130
|
+
.catch(() => {
|
|
131
|
+
// Silently fail - form will show empty
|
|
132
|
+
})
|
|
133
|
+
.finally(() => {
|
|
134
|
+
setIsLoadingJob(false)
|
|
135
|
+
})
|
|
136
|
+
}
|
|
137
|
+
}, [open, mode, trackingJobId])
|
|
138
|
+
|
|
139
|
+
// Handle form submission
|
|
140
|
+
const handleSubmit = useCallback(
|
|
141
|
+
async (e: React.FormEvent) => {
|
|
142
|
+
e.preventDefault()
|
|
143
|
+
setIsSubmitting(true)
|
|
144
|
+
|
|
145
|
+
try {
|
|
146
|
+
// Validate carrier
|
|
147
|
+
if (!formData.carrierCode) {
|
|
148
|
+
flash(t('shipment_tracking.tracking_jobs.validation.carrierRequired', 'Carrier is required'), 'error')
|
|
149
|
+
setIsSubmitting(false)
|
|
150
|
+
return
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// Validate reference value
|
|
154
|
+
if (!formData.referenceValue.trim()) {
|
|
155
|
+
flash(t('shipment_tracking.tracking_jobs.validation.referenceValueRequired', 'Reference value is required'), 'error')
|
|
156
|
+
setIsSubmitting(false)
|
|
157
|
+
return
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// Validate UN/LOCODE format (2 letters + 3 alphanumeric) - only if provided
|
|
161
|
+
const unLocodePattern = /^[A-Z]{2}[A-Z0-9]{3}$/
|
|
162
|
+
const originValue = formData.originUnlocode.trim().toUpperCase()
|
|
163
|
+
const destinationValue = formData.destinationUnlocode.trim().toUpperCase()
|
|
164
|
+
|
|
165
|
+
if (originValue && !unLocodePattern.test(originValue)) {
|
|
166
|
+
flash(t('shipment_tracking.tracking_jobs.validation.invalidOriginUnlocode', 'Invalid origin UN/LOCODE format (e.g., CNYTN)'), 'error')
|
|
167
|
+
setIsSubmitting(false)
|
|
168
|
+
return
|
|
169
|
+
}
|
|
170
|
+
if (destinationValue && !unLocodePattern.test(destinationValue)) {
|
|
171
|
+
flash(t('shipment_tracking.tracking_jobs.validation.invalidDestinationUnlocode', 'Invalid destination UN/LOCODE format (e.g., PLGDN)'), 'error')
|
|
172
|
+
setIsSubmitting(false)
|
|
173
|
+
return
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// Build payload - only include ports if provided
|
|
177
|
+
const payload: Record<string, unknown> = {
|
|
178
|
+
carrierCode: formData.carrierCode,
|
|
179
|
+
referenceType: formData.referenceType,
|
|
180
|
+
referenceValue: formData.referenceValue.trim().toUpperCase(),
|
|
181
|
+
}
|
|
182
|
+
if (originValue) payload.originUnlocode = originValue
|
|
183
|
+
if (destinationValue) payload.destinationUnlocode = destinationValue
|
|
184
|
+
|
|
185
|
+
let response: { ok: boolean; result?: { id: string; error?: string } | null }
|
|
186
|
+
|
|
187
|
+
if (mode === 'edit' && trackingJobId) {
|
|
188
|
+
// Edit mode is limited - can only update certain fields
|
|
189
|
+
response = await apiCall<{ id: string; error?: string }>(
|
|
190
|
+
`/api/shipment_tracking/tracking-jobs`,
|
|
191
|
+
{
|
|
192
|
+
method: 'PUT',
|
|
193
|
+
headers: { 'Content-Type': 'application/json' },
|
|
194
|
+
body: JSON.stringify({ id: trackingJobId, ...payload }),
|
|
195
|
+
}
|
|
196
|
+
)
|
|
197
|
+
} else {
|
|
198
|
+
response = await apiCall<{ id: string; error?: string }>(
|
|
199
|
+
'/api/shipment_tracking/tracking-jobs',
|
|
200
|
+
{
|
|
201
|
+
method: 'POST',
|
|
202
|
+
headers: { 'Content-Type': 'application/json' },
|
|
203
|
+
body: JSON.stringify(payload),
|
|
204
|
+
}
|
|
205
|
+
)
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
if (response.ok && response.result?.id) {
|
|
209
|
+
flash(
|
|
210
|
+
mode === 'edit'
|
|
211
|
+
? t('shipment_tracking.tracking_jobs.flash.updated', 'Tracking job updated successfully')
|
|
212
|
+
: t('shipment_tracking.tracking_jobs.flash.created', 'Tracking job created successfully'),
|
|
213
|
+
'success'
|
|
214
|
+
)
|
|
215
|
+
queryClient.invalidateQueries({ queryKey: ['shipment_tracking_tracking_jobs'] })
|
|
216
|
+
queryClient.invalidateQueries({ queryKey: ['shipment_tracking_tracking_job', trackingJobId] })
|
|
217
|
+
onSaved?.({ id: response.result.id })
|
|
218
|
+
onOpenChange(false)
|
|
219
|
+
} else {
|
|
220
|
+
flash(response.result?.error || t('shipment_tracking.tracking_jobs.flash.saveFailed', 'Failed to save tracking job'), 'error')
|
|
221
|
+
}
|
|
222
|
+
} catch (error) {
|
|
223
|
+
flash(error instanceof Error ? error.message : t('shipment_tracking.tracking_jobs.flash.saveFailed', 'Failed to save tracking job'), 'error')
|
|
224
|
+
} finally {
|
|
225
|
+
setIsSubmitting(false)
|
|
226
|
+
}
|
|
227
|
+
},
|
|
228
|
+
[formData, mode, trackingJobId, queryClient, onSaved, onOpenChange, t]
|
|
229
|
+
)
|
|
230
|
+
|
|
231
|
+
// Handle keyboard shortcuts
|
|
232
|
+
const handleKeyDown = useCallback(
|
|
233
|
+
(e: React.KeyboardEvent) => {
|
|
234
|
+
if (e.key === 'Enter' && (e.metaKey || e.ctrlKey)) {
|
|
235
|
+
e.preventDefault()
|
|
236
|
+
handleSubmit(e as unknown as React.FormEvent)
|
|
237
|
+
}
|
|
238
|
+
if (e.key === 'Escape') {
|
|
239
|
+
onOpenChange(false)
|
|
240
|
+
}
|
|
241
|
+
},
|
|
242
|
+
[handleSubmit, onOpenChange]
|
|
243
|
+
)
|
|
244
|
+
|
|
245
|
+
const title = mode === 'edit'
|
|
246
|
+
? t('shipment_tracking.tracking_jobs.edit', 'Edit Tracking Job')
|
|
247
|
+
: t('shipment_tracking.tracking_jobs.create', 'Create Tracking Job')
|
|
248
|
+
|
|
249
|
+
const selectedReferenceType = REFERENCE_TYPES.find((rt) => rt.id === formData.referenceType)
|
|
250
|
+
const ReferenceIcon = selectedReferenceType?.icon ?? Package
|
|
251
|
+
|
|
252
|
+
if (mode === 'edit' && isLoadingJob) {
|
|
253
|
+
return (
|
|
254
|
+
<Sheet open={open} onOpenChange={onOpenChange}>
|
|
255
|
+
<SheetContent
|
|
256
|
+
className="flex flex-col p-0"
|
|
257
|
+
style={{ width: '450px', maxWidth: '450px' }}
|
|
258
|
+
overlayClassName="backdrop-blur-none"
|
|
259
|
+
>
|
|
260
|
+
<div className="flex flex-col items-center justify-center h-48 gap-2">
|
|
261
|
+
<Spinner className="h-6 w-6" />
|
|
262
|
+
<span className="text-sm text-gray-500">{t('shipment_tracking.tracking_jobs.loading', 'Loading tracking job...')}</span>
|
|
263
|
+
</div>
|
|
264
|
+
</SheetContent>
|
|
265
|
+
</Sheet>
|
|
266
|
+
)
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
return (
|
|
270
|
+
<Sheet open={open} onOpenChange={onOpenChange}>
|
|
271
|
+
<SheetContent
|
|
272
|
+
className="flex flex-col p-0"
|
|
273
|
+
style={{ width: '450px', maxWidth: '450px' }}
|
|
274
|
+
overlayClassName="backdrop-blur-none"
|
|
275
|
+
onKeyDown={handleKeyDown}
|
|
276
|
+
>
|
|
277
|
+
<div className="flex-shrink-0 p-6 pb-4 border-b">
|
|
278
|
+
<SheetHeader>
|
|
279
|
+
<SheetTitle className="flex items-center gap-2">
|
|
280
|
+
<Radar className="h-5 w-5" />
|
|
281
|
+
{title}
|
|
282
|
+
</SheetTitle>
|
|
283
|
+
<SheetDescription>
|
|
284
|
+
{t('shipment_tracking.tracking_jobs.drawer.description', 'Create a tracking job to monitor shipments. The system will automatically poll the carrier for updates and create shipments for discovered containers.')}
|
|
285
|
+
</SheetDescription>
|
|
286
|
+
</SheetHeader>
|
|
287
|
+
</div>
|
|
288
|
+
|
|
289
|
+
<form onSubmit={handleSubmit} className="flex flex-col flex-1 min-h-0">
|
|
290
|
+
<div className="flex-1 overflow-y-auto p-6 space-y-6">
|
|
291
|
+
{/* Carrier Selection */}
|
|
292
|
+
<div className="space-y-4">
|
|
293
|
+
<div className="flex items-center gap-2 text-sm font-medium text-foreground">
|
|
294
|
+
<Ship className="h-4 w-4" />
|
|
295
|
+
{t('shipment_tracking.tracking_jobs.drawer.carrier', 'Carrier')}
|
|
296
|
+
</div>
|
|
297
|
+
<div className="space-y-2">
|
|
298
|
+
<Label htmlFor="carrierCode">{t('shipment_tracking.tracking_jobs.fields.carrierCode', 'Carrier')} *</Label>
|
|
299
|
+
<select
|
|
300
|
+
id="carrierCode"
|
|
301
|
+
value={formData.carrierCode}
|
|
302
|
+
onChange={(e) => setFormData({ ...formData, carrierCode: e.target.value })}
|
|
303
|
+
disabled={mode === 'edit'}
|
|
304
|
+
className="flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-sm transition-colors placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50"
|
|
305
|
+
>
|
|
306
|
+
<option value="">
|
|
307
|
+
{isLoadingCarriers ? t('common.loading', 'Loading...') : t('shipment_tracking.tracking_jobs.drawer.selectCarrier', 'Select a carrier')}
|
|
308
|
+
</option>
|
|
309
|
+
{carriers.map((carrier) => (
|
|
310
|
+
<option key={carrier.carrierCode} value={carrier.carrierCode}>
|
|
311
|
+
{carrier.carrierCode.toUpperCase()}
|
|
312
|
+
</option>
|
|
313
|
+
))}
|
|
314
|
+
</select>
|
|
315
|
+
{carriers.length === 0 && !isLoadingCarriers && (
|
|
316
|
+
<p className="text-xs text-amber-600">
|
|
317
|
+
{t('shipment_tracking.tracking_jobs.drawer.noCarriers', 'No carriers configured. Add carrier configurations first.')}
|
|
318
|
+
</p>
|
|
319
|
+
)}
|
|
320
|
+
</div>
|
|
321
|
+
</div>
|
|
322
|
+
|
|
323
|
+
{/* Reference Section */}
|
|
324
|
+
<div className="space-y-4">
|
|
325
|
+
<div className="flex items-center gap-2 text-sm font-medium text-foreground">
|
|
326
|
+
<ReferenceIcon className="h-4 w-4" />
|
|
327
|
+
{t('shipment_tracking.tracking_jobs.drawer.reference', 'Reference')}
|
|
328
|
+
</div>
|
|
329
|
+
|
|
330
|
+
{/* Reference Type */}
|
|
331
|
+
<div className="space-y-2">
|
|
332
|
+
<Label htmlFor="referenceType">{t('shipment_tracking.tracking_jobs.fields.referenceType', 'Reference Type')} *</Label>
|
|
333
|
+
<select
|
|
334
|
+
id="referenceType"
|
|
335
|
+
value={formData.referenceType}
|
|
336
|
+
onChange={(e) => setFormData({ ...formData, referenceType: e.target.value as ReferenceType })}
|
|
337
|
+
disabled={mode === 'edit'}
|
|
338
|
+
className="flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-sm transition-colors placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50"
|
|
339
|
+
>
|
|
340
|
+
{REFERENCE_TYPES.map((refType) => (
|
|
341
|
+
<option key={refType.id} value={refType.id}>
|
|
342
|
+
{t(`shipment_tracking.tracking_jobs.referenceTypes.${refType.id}`, refType.label)}
|
|
343
|
+
</option>
|
|
344
|
+
))}
|
|
345
|
+
</select>
|
|
346
|
+
<p className="text-xs text-muted-foreground">
|
|
347
|
+
{formData.referenceType === 'container'
|
|
348
|
+
? t('shipment_tracking.tracking_jobs.drawer.containerHint', 'Enter the container number (e.g., MSBU1234567).')
|
|
349
|
+
: formData.referenceType === 'booking'
|
|
350
|
+
? t('shipment_tracking.tracking_jobs.drawer.bookingHint', 'Enter the booking number. Multiple containers may be discovered.')
|
|
351
|
+
: t('shipment_tracking.tracking_jobs.drawer.bolHint', 'Enter the Bill of Lading number.')}
|
|
352
|
+
</p>
|
|
353
|
+
</div>
|
|
354
|
+
|
|
355
|
+
{/* Reference Value */}
|
|
356
|
+
<div className="space-y-2">
|
|
357
|
+
<Label htmlFor="referenceValue">{t('shipment_tracking.tracking_jobs.fields.referenceValue', 'Reference Value')} *</Label>
|
|
358
|
+
<Input
|
|
359
|
+
id="referenceValue"
|
|
360
|
+
type="text"
|
|
361
|
+
placeholder={
|
|
362
|
+
formData.referenceType === 'container'
|
|
363
|
+
? 'MSBU1234567'
|
|
364
|
+
: formData.referenceType === 'booking'
|
|
365
|
+
? '123456789'
|
|
366
|
+
: 'MEDUN1234567'
|
|
367
|
+
}
|
|
368
|
+
value={formData.referenceValue}
|
|
369
|
+
onChange={(e) => setFormData({ ...formData, referenceValue: e.target.value.toUpperCase() })}
|
|
370
|
+
disabled={mode === 'edit'}
|
|
371
|
+
className="uppercase"
|
|
372
|
+
autoComplete="off"
|
|
373
|
+
/>
|
|
374
|
+
</div>
|
|
375
|
+
</div>
|
|
376
|
+
|
|
377
|
+
{/* Route Section - Origin & Destination (Optional - auto-detected from events) */}
|
|
378
|
+
<div className="space-y-4">
|
|
379
|
+
<div className="flex items-center gap-2 text-sm font-medium text-foreground">
|
|
380
|
+
<MapPin className="h-4 w-4" />
|
|
381
|
+
{t('shipment_tracking.tracking_jobs.drawer.route', 'Route')}
|
|
382
|
+
<span className="text-xs font-normal text-muted-foreground">
|
|
383
|
+
({t('shipment_tracking.tracking_jobs.drawer.optional', 'optional')})
|
|
384
|
+
</span>
|
|
385
|
+
</div>
|
|
386
|
+
|
|
387
|
+
<div className="grid grid-cols-2 gap-4">
|
|
388
|
+
{/* Origin UN/LOCODE */}
|
|
389
|
+
<div className="space-y-2">
|
|
390
|
+
<Label htmlFor="originUnlocode">{t('shipment_tracking.tracking_jobs.fields.originUnlocode', 'Origin Port')}</Label>
|
|
391
|
+
<Input
|
|
392
|
+
id="originUnlocode"
|
|
393
|
+
type="text"
|
|
394
|
+
placeholder="CNYTN"
|
|
395
|
+
value={formData.originUnlocode}
|
|
396
|
+
onChange={(e) => setFormData({ ...formData, originUnlocode: e.target.value.toUpperCase() })}
|
|
397
|
+
disabled={mode === 'edit'}
|
|
398
|
+
className="uppercase"
|
|
399
|
+
autoComplete="off"
|
|
400
|
+
maxLength={5}
|
|
401
|
+
/>
|
|
402
|
+
</div>
|
|
403
|
+
|
|
404
|
+
{/* Destination UN/LOCODE */}
|
|
405
|
+
<div className="space-y-2">
|
|
406
|
+
<Label htmlFor="destinationUnlocode">{t('shipment_tracking.tracking_jobs.fields.destinationUnlocode', 'Destination Port')}</Label>
|
|
407
|
+
<Input
|
|
408
|
+
id="destinationUnlocode"
|
|
409
|
+
type="text"
|
|
410
|
+
placeholder="PLGDN"
|
|
411
|
+
value={formData.destinationUnlocode}
|
|
412
|
+
onChange={(e) => setFormData({ ...formData, destinationUnlocode: e.target.value.toUpperCase() })}
|
|
413
|
+
disabled={mode === 'edit'}
|
|
414
|
+
className="uppercase"
|
|
415
|
+
autoComplete="off"
|
|
416
|
+
maxLength={5}
|
|
417
|
+
/>
|
|
418
|
+
</div>
|
|
419
|
+
</div>
|
|
420
|
+
|
|
421
|
+
<div className="rounded-lg border border-amber-200 bg-amber-50 p-3">
|
|
422
|
+
<p className="text-xs text-amber-800">
|
|
423
|
+
{t('shipment_tracking.tracking_jobs.drawer.autoDetectHint', 'If not provided, origin and destination will be automatically detected from tracking events (EST/ACT arrivals and departures).')}
|
|
424
|
+
</p>
|
|
425
|
+
</div>
|
|
426
|
+
</div>
|
|
427
|
+
|
|
428
|
+
{/* Info box for booking/BOL tracking */}
|
|
429
|
+
{formData.referenceType !== 'container' && (
|
|
430
|
+
<div className="rounded-lg border border-blue-200 bg-blue-50 p-4">
|
|
431
|
+
<h4 className="text-sm font-medium text-blue-900 mb-1">
|
|
432
|
+
{t('shipment_tracking.tracking_jobs.drawer.multiContainerTitle', 'Multi-Container Tracking')}
|
|
433
|
+
</h4>
|
|
434
|
+
<p className="text-xs text-blue-700">
|
|
435
|
+
{t('shipment_tracking.tracking_jobs.drawer.multiContainerDescription', 'When tracking by booking or BOL, the system will automatically discover all containers associated with this reference and create individual shipment records for each one.')}
|
|
436
|
+
</p>
|
|
437
|
+
</div>
|
|
438
|
+
)}
|
|
439
|
+
</div>
|
|
440
|
+
|
|
441
|
+
{/* Sticky footer */}
|
|
442
|
+
<div className="flex-shrink-0 border-t bg-background p-6">
|
|
443
|
+
<div className="flex justify-end gap-3">
|
|
444
|
+
<Button type="button" variant="outline" onClick={() => onOpenChange(false)}>
|
|
445
|
+
{t('common.cancel', 'Cancel')}
|
|
446
|
+
</Button>
|
|
447
|
+
<Button type="submit" disabled={isSubmitting || carriers.length === 0}>
|
|
448
|
+
{isSubmitting ? (
|
|
449
|
+
<>
|
|
450
|
+
<Spinner className="mr-2 h-4 w-4" />
|
|
451
|
+
{t('common.saving', 'Saving...')}
|
|
452
|
+
</>
|
|
453
|
+
) : mode === 'edit' ? (
|
|
454
|
+
t('common.saveChanges', 'Save Changes')
|
|
455
|
+
) : (
|
|
456
|
+
t('shipment_tracking.tracking_jobs.create', 'Create Tracking Job')
|
|
457
|
+
)}
|
|
458
|
+
</Button>
|
|
459
|
+
</div>
|
|
460
|
+
</div>
|
|
461
|
+
</form>
|
|
462
|
+
</SheetContent>
|
|
463
|
+
</Sheet>
|
|
464
|
+
)
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
export type { TrackingJobDrawerProps, TrackingJobData }
|