@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,498 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import * as React from 'react'
|
|
4
|
+
import { useState, useCallback, useEffect } from 'react'
|
|
5
|
+
import { useQuery, useQueryClient } from '@tanstack/react-query'
|
|
6
|
+
import { Ship, Anchor, Calendar, Package } 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
|
+
import { FacilityLocationInput, type FacilityLocationInputValue } from './FacilityLocationInput'
|
|
22
|
+
import type { FacilityLocation } from '../lib/location-types'
|
|
23
|
+
|
|
24
|
+
interface ShipmentFormData {
|
|
25
|
+
carrierCode: string
|
|
26
|
+
containerNumber: string
|
|
27
|
+
bookingNumber: string
|
|
28
|
+
bolNumber: string
|
|
29
|
+
etd: string
|
|
30
|
+
eta: string
|
|
31
|
+
originLocation: FacilityLocationInputValue | null
|
|
32
|
+
destinationLocation: FacilityLocationInputValue | null
|
|
33
|
+
vesselName: string
|
|
34
|
+
vesselImo: string
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
type TimestampEntry = {
|
|
38
|
+
value: string
|
|
39
|
+
offset: string | null
|
|
40
|
+
source: string
|
|
41
|
+
updatedAt: string
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
interface ShipmentData {
|
|
45
|
+
id: string
|
|
46
|
+
carrierCode?: string | null
|
|
47
|
+
containerNumber?: string | null
|
|
48
|
+
bookingNumber?: string | null
|
|
49
|
+
bolNumber?: string | null
|
|
50
|
+
// Multi-source timestamp arrays
|
|
51
|
+
etdTimestamps?: TimestampEntry[] | null
|
|
52
|
+
etaTimestamps?: TimestampEntry[] | null
|
|
53
|
+
atdTimestamps?: TimestampEntry[] | null
|
|
54
|
+
ataTimestamps?: TimestampEntry[] | null
|
|
55
|
+
// Location data (JSONB)
|
|
56
|
+
originLocation?: FacilityLocation | null
|
|
57
|
+
destinationLocation?: FacilityLocation | null
|
|
58
|
+
vesselName?: string | null
|
|
59
|
+
vesselImo?: string | null
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Helper to get primary timestamp value from array (latest updatedAt wins)
|
|
63
|
+
function getPrimaryTimestamp(timestamps: TimestampEntry[] | null | undefined): string | null {
|
|
64
|
+
if (!timestamps || timestamps.length === 0) return null
|
|
65
|
+
const latest = timestamps.reduce((best, entry) =>
|
|
66
|
+
entry.updatedAt > best.updatedAt ? entry : best
|
|
67
|
+
)
|
|
68
|
+
return latest.value
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
interface ShipmentDrawerProps {
|
|
72
|
+
open: boolean
|
|
73
|
+
onOpenChange: (open: boolean) => void
|
|
74
|
+
mode: 'create' | 'edit'
|
|
75
|
+
shipmentId?: string
|
|
76
|
+
onSaved?: (shipment: { id: string }) => void
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const initialFormData: ShipmentFormData = {
|
|
80
|
+
carrierCode: '',
|
|
81
|
+
containerNumber: '',
|
|
82
|
+
bookingNumber: '',
|
|
83
|
+
bolNumber: '',
|
|
84
|
+
etd: '',
|
|
85
|
+
eta: '',
|
|
86
|
+
originLocation: null,
|
|
87
|
+
destinationLocation: null,
|
|
88
|
+
vesselName: '',
|
|
89
|
+
vesselImo: '',
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function formatDateForInput(dateString: string | null | undefined): string {
|
|
93
|
+
if (!dateString) return ''
|
|
94
|
+
const date = new Date(dateString)
|
|
95
|
+
if (Number.isNaN(date.getTime())) return ''
|
|
96
|
+
return date.toISOString().split('T')[0]
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export function ShipmentDrawer({
|
|
100
|
+
open,
|
|
101
|
+
onOpenChange,
|
|
102
|
+
mode,
|
|
103
|
+
shipmentId,
|
|
104
|
+
onSaved,
|
|
105
|
+
}: ShipmentDrawerProps) {
|
|
106
|
+
const t = useT()
|
|
107
|
+
const queryClient = useQueryClient()
|
|
108
|
+
const [isSubmitting, setIsSubmitting] = useState(false)
|
|
109
|
+
const [formData, setFormData] = useState<ShipmentFormData>(initialFormData)
|
|
110
|
+
|
|
111
|
+
// Fetch shipment data for edit mode
|
|
112
|
+
const { data: shipmentData, isLoading: isLoadingShipment } = useQuery({
|
|
113
|
+
queryKey: ['shipment_tracking_shipment', shipmentId],
|
|
114
|
+
queryFn: async () => {
|
|
115
|
+
if (!shipmentId) return null
|
|
116
|
+
const response = await apiCall<{ items: Record<string, unknown>[] }>(`/api/shipment_tracking/shipments?id=${shipmentId}`)
|
|
117
|
+
if (!response.ok) throw new Error('Failed to load shipment')
|
|
118
|
+
const items = response.result?.items ?? []
|
|
119
|
+
// Find the item matching the requested ID (API may return multiple items)
|
|
120
|
+
const item = items.find((i) => i.id === shipmentId) ?? items[0]
|
|
121
|
+
if (!item) return null
|
|
122
|
+
|
|
123
|
+
// Normalize API response (handle both camelCase and snake_case)
|
|
124
|
+
return {
|
|
125
|
+
id: item.id as string,
|
|
126
|
+
carrierCode: (item.carrierCode ?? item.carrier_code) as string | null,
|
|
127
|
+
containerNumber: (item.containerNumber ?? item.container_number) as string | null,
|
|
128
|
+
bookingNumber: (item.bookingNumber ?? item.booking_number) as string | null,
|
|
129
|
+
bolNumber: (item.bolNumber ?? item.bol_number) as string | null,
|
|
130
|
+
etdTimestamps: (item.etdTimestamps ?? item.etd_timestamps) as TimestampEntry[] | null,
|
|
131
|
+
etaTimestamps: (item.etaTimestamps ?? item.eta_timestamps) as TimestampEntry[] | null,
|
|
132
|
+
atdTimestamps: (item.atdTimestamps ?? item.atd_timestamps) as TimestampEntry[] | null,
|
|
133
|
+
ataTimestamps: (item.ataTimestamps ?? item.ata_timestamps) as TimestampEntry[] | null,
|
|
134
|
+
originLocation: (item.originLocation ?? item.origin_location) as FacilityLocation | null,
|
|
135
|
+
destinationLocation: (item.destinationLocation ?? item.destination_location) as FacilityLocation | null,
|
|
136
|
+
vesselName: (item.vesselName ?? item.vessel_name) as string | null,
|
|
137
|
+
vesselImo: (item.vesselImo ?? item.vessel_imo) as string | null,
|
|
138
|
+
} as ShipmentData
|
|
139
|
+
},
|
|
140
|
+
enabled: mode === 'edit' && !!shipmentId && open,
|
|
141
|
+
})
|
|
142
|
+
|
|
143
|
+
// Reset form when drawer opens/closes or mode changes
|
|
144
|
+
useEffect(() => {
|
|
145
|
+
if (!open) return
|
|
146
|
+
|
|
147
|
+
if (mode === 'edit') {
|
|
148
|
+
// In edit mode, only set form data once we have the shipment data
|
|
149
|
+
// Don't reset to initial while loading
|
|
150
|
+
if (shipmentData) {
|
|
151
|
+
// Extract primary timestamp values from arrays
|
|
152
|
+
const primaryEtd = getPrimaryTimestamp(shipmentData.etdTimestamps)
|
|
153
|
+
const primaryEta = getPrimaryTimestamp(shipmentData.etaTimestamps)
|
|
154
|
+
|
|
155
|
+
setFormData({
|
|
156
|
+
carrierCode: shipmentData.carrierCode || '',
|
|
157
|
+
containerNumber: shipmentData.containerNumber || '',
|
|
158
|
+
bookingNumber: shipmentData.bookingNumber || '',
|
|
159
|
+
bolNumber: shipmentData.bolNumber || '',
|
|
160
|
+
etd: formatDateForInput(primaryEtd),
|
|
161
|
+
eta: formatDateForInput(primaryEta),
|
|
162
|
+
originLocation: shipmentData.originLocation || null,
|
|
163
|
+
destinationLocation: shipmentData.destinationLocation || null,
|
|
164
|
+
vesselName: shipmentData.vesselName || '',
|
|
165
|
+
vesselImo: shipmentData.vesselImo || '',
|
|
166
|
+
})
|
|
167
|
+
}
|
|
168
|
+
// If shipmentData is null/undefined, we're still loading - don't reset
|
|
169
|
+
} else {
|
|
170
|
+
// In create mode, always reset to initial
|
|
171
|
+
setFormData(initialFormData)
|
|
172
|
+
}
|
|
173
|
+
}, [open, mode, shipmentData])
|
|
174
|
+
|
|
175
|
+
// Handle form submission
|
|
176
|
+
const handleSubmit = useCallback(
|
|
177
|
+
async (e: React.FormEvent) => {
|
|
178
|
+
e.preventDefault()
|
|
179
|
+
setIsSubmitting(true)
|
|
180
|
+
|
|
181
|
+
try {
|
|
182
|
+
// Validate that at least one reference number is provided
|
|
183
|
+
if (!formData.containerNumber && !formData.bookingNumber && !formData.bolNumber) {
|
|
184
|
+
flash(t('shipment_tracking.errors.referenceRequired', 'At least one of container number, booking number, or BOL number is required'), 'error')
|
|
185
|
+
setIsSubmitting(false)
|
|
186
|
+
return
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// Build timestamp entries for ETD/ETA if provided
|
|
190
|
+
// For create: include full timestamp arrays
|
|
191
|
+
// For edit: use addEtdTimestamp/addEtaTimestamp to append manual entries
|
|
192
|
+
const buildManualTimestamp = (dateStr: string) => {
|
|
193
|
+
if (!dateStr) return undefined
|
|
194
|
+
// Convert date input (YYYY-MM-DD) to ISO datetime at midnight UTC
|
|
195
|
+
const isoValue = new Date(dateStr + 'T00:00:00Z').toISOString()
|
|
196
|
+
return {
|
|
197
|
+
value: isoValue,
|
|
198
|
+
offset: 'Z' as const,
|
|
199
|
+
source: 'manual' as const,
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const etdEntry = buildManualTimestamp(formData.etd)
|
|
204
|
+
const etaEntry = buildManualTimestamp(formData.eta)
|
|
205
|
+
|
|
206
|
+
// Clean up location objects - only include if they have meaningful data
|
|
207
|
+
const cleanLocation = (loc: FacilityLocationInputValue | null): FacilityLocation | null => {
|
|
208
|
+
if (!loc) return null
|
|
209
|
+
// A location is meaningful if it has a name or unlocode
|
|
210
|
+
if (!loc.name && !loc.unlocode) return null
|
|
211
|
+
return {
|
|
212
|
+
name: loc.name || loc.unlocode || 'Unknown',
|
|
213
|
+
unlocode: loc.unlocode || null,
|
|
214
|
+
countryCode: loc.countryCode || (loc.unlocode?.slice(0, 2) ?? null),
|
|
215
|
+
facilityCode: loc.facilityCode || null,
|
|
216
|
+
facilityCodeListProvider: loc.facilityCodeListProvider || null,
|
|
217
|
+
facilityTypeCode: loc.facilityTypeCode || null,
|
|
218
|
+
address: loc.address || null,
|
|
219
|
+
coords: loc.coords || null,
|
|
220
|
+
operatorName: loc.operatorName || null,
|
|
221
|
+
source: 'manual',
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
const payload: Record<string, unknown> = {
|
|
226
|
+
carrierCode: formData.carrierCode || undefined,
|
|
227
|
+
containerNumber: formData.containerNumber || undefined,
|
|
228
|
+
bookingNumber: formData.bookingNumber || undefined,
|
|
229
|
+
bolNumber: formData.bolNumber || undefined,
|
|
230
|
+
originLocation: cleanLocation(formData.originLocation),
|
|
231
|
+
destinationLocation: cleanLocation(formData.destinationLocation),
|
|
232
|
+
vesselName: formData.vesselName || undefined,
|
|
233
|
+
vesselImo: formData.vesselImo || undefined,
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
if (mode === 'edit') {
|
|
237
|
+
// For updates, use addEtdTimestamp/addEtaTimestamp to append manual entries
|
|
238
|
+
if (etdEntry) payload.addEtdTimestamp = etdEntry
|
|
239
|
+
if (etaEntry) payload.addEtaTimestamp = etaEntry
|
|
240
|
+
} else {
|
|
241
|
+
// For create, build full timestamp arrays with updatedAt
|
|
242
|
+
const now = new Date().toISOString()
|
|
243
|
+
if (etdEntry) {
|
|
244
|
+
payload.etdTimestamps = [{ ...etdEntry, updatedAt: now }]
|
|
245
|
+
}
|
|
246
|
+
if (etaEntry) {
|
|
247
|
+
payload.etaTimestamps = [{ ...etaEntry, updatedAt: now }]
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
let response: { ok: boolean; result?: { id: string; error?: string } | null }
|
|
252
|
+
|
|
253
|
+
if (mode === 'edit' && shipmentId) {
|
|
254
|
+
response = await apiCall<{ id: string; error?: string }>(
|
|
255
|
+
`/api/shipment_tracking/shipments`,
|
|
256
|
+
{
|
|
257
|
+
method: 'PUT',
|
|
258
|
+
headers: { 'Content-Type': 'application/json' },
|
|
259
|
+
body: JSON.stringify({ id: shipmentId, ...payload }),
|
|
260
|
+
}
|
|
261
|
+
)
|
|
262
|
+
} else {
|
|
263
|
+
response = await apiCall<{ id: string; error?: string }>(
|
|
264
|
+
'/api/shipment_tracking/shipments',
|
|
265
|
+
{
|
|
266
|
+
method: 'POST',
|
|
267
|
+
headers: { 'Content-Type': 'application/json' },
|
|
268
|
+
body: JSON.stringify(payload),
|
|
269
|
+
}
|
|
270
|
+
)
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
if (response.ok && response.result?.id) {
|
|
274
|
+
flash(
|
|
275
|
+
mode === 'edit'
|
|
276
|
+
? t('shipment_tracking.shipments.flash.updated', 'Shipment updated successfully')
|
|
277
|
+
: t('shipment_tracking.shipments.flash.created', 'Shipment created successfully'),
|
|
278
|
+
'success'
|
|
279
|
+
)
|
|
280
|
+
queryClient.invalidateQueries({ queryKey: ['shipment_tracking_shipments'] })
|
|
281
|
+
queryClient.invalidateQueries({ queryKey: ['shipment_tracking_shipment', shipmentId] })
|
|
282
|
+
onSaved?.({ id: response.result.id })
|
|
283
|
+
onOpenChange(false)
|
|
284
|
+
} else {
|
|
285
|
+
flash(response.result?.error || t('shipment_tracking.shipments.flash.saveFailed', 'Failed to save shipment'), 'error')
|
|
286
|
+
}
|
|
287
|
+
} catch (error) {
|
|
288
|
+
flash(error instanceof Error ? error.message : t('shipment_tracking.shipments.flash.saveFailed', 'Failed to save shipment'), 'error')
|
|
289
|
+
} finally {
|
|
290
|
+
setIsSubmitting(false)
|
|
291
|
+
}
|
|
292
|
+
},
|
|
293
|
+
[formData, mode, shipmentId, queryClient, onSaved, onOpenChange, t]
|
|
294
|
+
)
|
|
295
|
+
|
|
296
|
+
// Handle keyboard shortcuts
|
|
297
|
+
const handleKeyDown = useCallback(
|
|
298
|
+
(e: React.KeyboardEvent) => {
|
|
299
|
+
if (e.key === 'Enter' && (e.metaKey || e.ctrlKey)) {
|
|
300
|
+
e.preventDefault()
|
|
301
|
+
handleSubmit(e as unknown as React.FormEvent)
|
|
302
|
+
}
|
|
303
|
+
if (e.key === 'Escape') {
|
|
304
|
+
onOpenChange(false)
|
|
305
|
+
}
|
|
306
|
+
},
|
|
307
|
+
[handleSubmit, onOpenChange]
|
|
308
|
+
)
|
|
309
|
+
|
|
310
|
+
const title = mode === 'edit'
|
|
311
|
+
? t('shipment_tracking.shipments.edit', 'Edit Shipment')
|
|
312
|
+
: t('shipment_tracking.shipments.create', 'Create Shipment')
|
|
313
|
+
|
|
314
|
+
if (mode === 'edit' && isLoadingShipment) {
|
|
315
|
+
return (
|
|
316
|
+
<Sheet open={open} onOpenChange={onOpenChange}>
|
|
317
|
+
<SheetContent
|
|
318
|
+
className="flex flex-col p-0"
|
|
319
|
+
style={{ width: '550px', maxWidth: '550px' }}
|
|
320
|
+
overlayClassName="backdrop-blur-none"
|
|
321
|
+
>
|
|
322
|
+
<div className="flex flex-col items-center justify-center h-48 gap-2">
|
|
323
|
+
<Spinner className="h-6 w-6" />
|
|
324
|
+
<span className="text-sm text-gray-500">{t('shipment_tracking.shipments.loading', 'Loading shipment...')}</span>
|
|
325
|
+
</div>
|
|
326
|
+
</SheetContent>
|
|
327
|
+
</Sheet>
|
|
328
|
+
)
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
return (
|
|
332
|
+
<Sheet open={open} onOpenChange={onOpenChange}>
|
|
333
|
+
<SheetContent
|
|
334
|
+
className="flex flex-col p-0"
|
|
335
|
+
style={{ width: '550px', maxWidth: '550px' }}
|
|
336
|
+
overlayClassName="backdrop-blur-none"
|
|
337
|
+
onKeyDown={handleKeyDown}
|
|
338
|
+
>
|
|
339
|
+
<div className="flex-shrink-0 p-6 pb-4 border-b">
|
|
340
|
+
<SheetHeader>
|
|
341
|
+
<SheetTitle className="flex items-center gap-2">
|
|
342
|
+
<Ship className="h-5 w-5" />
|
|
343
|
+
{title}
|
|
344
|
+
</SheetTitle>
|
|
345
|
+
<SheetDescription>
|
|
346
|
+
{t('shipment_tracking.shipments.drawer.description', 'Enter shipment details for tracking. At least one reference number is required.')}
|
|
347
|
+
</SheetDescription>
|
|
348
|
+
</SheetHeader>
|
|
349
|
+
</div>
|
|
350
|
+
|
|
351
|
+
<form onSubmit={handleSubmit} className="flex flex-col flex-1 min-h-0">
|
|
352
|
+
<div className="flex-1 overflow-y-auto p-6 space-y-6">
|
|
353
|
+
{/* Reference Numbers Section */}
|
|
354
|
+
<div className="space-y-4">
|
|
355
|
+
<div className="flex items-center gap-2 text-sm font-medium text-foreground">
|
|
356
|
+
<Package className="h-4 w-4" />
|
|
357
|
+
{t('shipment_tracking.shipments.drawer.referenceNumbers', 'Reference Numbers')}
|
|
358
|
+
</div>
|
|
359
|
+
<div className="grid grid-cols-1 gap-4">
|
|
360
|
+
<div className="space-y-2">
|
|
361
|
+
<Label htmlFor="containerNumber">{t('shipment_tracking.shipments.fields.containerNumber', 'Container Number')}</Label>
|
|
362
|
+
<Input
|
|
363
|
+
id="containerNumber"
|
|
364
|
+
placeholder="ABCD1234567"
|
|
365
|
+
value={formData.containerNumber}
|
|
366
|
+
onChange={(e) => setFormData({ ...formData, containerNumber: e.target.value.toUpperCase() })}
|
|
367
|
+
/>
|
|
368
|
+
</div>
|
|
369
|
+
<div className="grid grid-cols-2 gap-4">
|
|
370
|
+
<div className="space-y-2">
|
|
371
|
+
<Label htmlFor="bookingNumber">{t('shipment_tracking.shipments.fields.bookingNumber', 'Booking Number')}</Label>
|
|
372
|
+
<Input
|
|
373
|
+
id="bookingNumber"
|
|
374
|
+
placeholder="BKG123456"
|
|
375
|
+
value={formData.bookingNumber}
|
|
376
|
+
onChange={(e) => setFormData({ ...formData, bookingNumber: e.target.value })}
|
|
377
|
+
/>
|
|
378
|
+
</div>
|
|
379
|
+
<div className="space-y-2">
|
|
380
|
+
<Label htmlFor="bolNumber">{t('shipment_tracking.shipments.fields.bolNumber', 'BOL Number')}</Label>
|
|
381
|
+
<Input
|
|
382
|
+
id="bolNumber"
|
|
383
|
+
placeholder="BOL123456"
|
|
384
|
+
value={formData.bolNumber}
|
|
385
|
+
onChange={(e) => setFormData({ ...formData, bolNumber: e.target.value })}
|
|
386
|
+
/>
|
|
387
|
+
</div>
|
|
388
|
+
</div>
|
|
389
|
+
</div>
|
|
390
|
+
</div>
|
|
391
|
+
|
|
392
|
+
{/* Carrier & Vessel Section */}
|
|
393
|
+
<div className="space-y-4">
|
|
394
|
+
<div className="flex items-center gap-2 text-sm font-medium text-foreground">
|
|
395
|
+
<Anchor className="h-4 w-4" />
|
|
396
|
+
{t('shipment_tracking.shipments.drawer.carrierVessel', 'Carrier & Vessel')}
|
|
397
|
+
</div>
|
|
398
|
+
<div className="grid grid-cols-2 gap-4">
|
|
399
|
+
<div className="space-y-2">
|
|
400
|
+
<Label htmlFor="carrierCode">{t('shipment_tracking.shipments.fields.carrierCode', 'Carrier Code')}</Label>
|
|
401
|
+
<Input
|
|
402
|
+
id="carrierCode"
|
|
403
|
+
placeholder="MAEU"
|
|
404
|
+
value={formData.carrierCode}
|
|
405
|
+
onChange={(e) => setFormData({ ...formData, carrierCode: e.target.value.toUpperCase() })}
|
|
406
|
+
/>
|
|
407
|
+
</div>
|
|
408
|
+
<div className="space-y-2">
|
|
409
|
+
<Label htmlFor="vesselName">{t('shipment_tracking.shipments.fields.vesselName', 'Vessel Name')}</Label>
|
|
410
|
+
<Input
|
|
411
|
+
id="vesselName"
|
|
412
|
+
placeholder="Ever Given"
|
|
413
|
+
value={formData.vesselName}
|
|
414
|
+
onChange={(e) => setFormData({ ...formData, vesselName: e.target.value })}
|
|
415
|
+
/>
|
|
416
|
+
</div>
|
|
417
|
+
</div>
|
|
418
|
+
<div className="space-y-2">
|
|
419
|
+
<Label htmlFor="vesselImo">{t('shipment_tracking.shipments.fields.vesselImo', 'Vessel IMO')}</Label>
|
|
420
|
+
<Input
|
|
421
|
+
id="vesselImo"
|
|
422
|
+
placeholder="9811000"
|
|
423
|
+
value={formData.vesselImo}
|
|
424
|
+
onChange={(e) => setFormData({ ...formData, vesselImo: e.target.value })}
|
|
425
|
+
/>
|
|
426
|
+
</div>
|
|
427
|
+
</div>
|
|
428
|
+
|
|
429
|
+
{/* Origin Section */}
|
|
430
|
+
<FacilityLocationInput
|
|
431
|
+
label={t('shipment_tracking.shipments.drawer.origin', 'Origin')}
|
|
432
|
+
value={formData.originLocation}
|
|
433
|
+
onChange={(loc) => setFormData({ ...formData, originLocation: loc })}
|
|
434
|
+
/>
|
|
435
|
+
|
|
436
|
+
{/* Destination Section */}
|
|
437
|
+
<FacilityLocationInput
|
|
438
|
+
label={t('shipment_tracking.shipments.drawer.destination', 'Destination')}
|
|
439
|
+
value={formData.destinationLocation}
|
|
440
|
+
onChange={(loc) => setFormData({ ...formData, destinationLocation: loc })}
|
|
441
|
+
/>
|
|
442
|
+
|
|
443
|
+
{/* Schedule Section */}
|
|
444
|
+
<div className="space-y-4">
|
|
445
|
+
<div className="flex items-center gap-2 text-sm font-medium text-foreground">
|
|
446
|
+
<Calendar className="h-4 w-4" />
|
|
447
|
+
{t('shipment_tracking.shipments.drawer.schedule', 'Schedule')}
|
|
448
|
+
</div>
|
|
449
|
+
<div className="grid grid-cols-2 gap-4">
|
|
450
|
+
<div className="space-y-2">
|
|
451
|
+
<Label htmlFor="etd">{t('shipment_tracking.shipments.fields.etd', 'ETD')}</Label>
|
|
452
|
+
<Input
|
|
453
|
+
id="etd"
|
|
454
|
+
type="date"
|
|
455
|
+
value={formData.etd}
|
|
456
|
+
onChange={(e) => setFormData({ ...formData, etd: e.target.value })}
|
|
457
|
+
/>
|
|
458
|
+
</div>
|
|
459
|
+
<div className="space-y-2">
|
|
460
|
+
<Label htmlFor="eta">{t('shipment_tracking.shipments.fields.eta', 'ETA')}</Label>
|
|
461
|
+
<Input
|
|
462
|
+
id="eta"
|
|
463
|
+
type="date"
|
|
464
|
+
value={formData.eta}
|
|
465
|
+
onChange={(e) => setFormData({ ...formData, eta: e.target.value })}
|
|
466
|
+
/>
|
|
467
|
+
</div>
|
|
468
|
+
</div>
|
|
469
|
+
</div>
|
|
470
|
+
</div>
|
|
471
|
+
|
|
472
|
+
{/* Sticky footer */}
|
|
473
|
+
<div className="flex-shrink-0 border-t bg-background p-6">
|
|
474
|
+
<div className="flex justify-end gap-3">
|
|
475
|
+
<Button type="button" variant="outline" onClick={() => onOpenChange(false)}>
|
|
476
|
+
{t('common.cancel', 'Cancel')}
|
|
477
|
+
</Button>
|
|
478
|
+
<Button type="submit" disabled={isSubmitting}>
|
|
479
|
+
{isSubmitting ? (
|
|
480
|
+
<>
|
|
481
|
+
<Spinner className="mr-2 h-4 w-4" />
|
|
482
|
+
{t('common.saving', 'Saving...')}
|
|
483
|
+
</>
|
|
484
|
+
) : mode === 'edit' ? (
|
|
485
|
+
t('common.saveChanges', 'Save Changes')
|
|
486
|
+
) : (
|
|
487
|
+
t('shipment_tracking.shipments.create', 'Create Shipment')
|
|
488
|
+
)}
|
|
489
|
+
</Button>
|
|
490
|
+
</div>
|
|
491
|
+
</div>
|
|
492
|
+
</form>
|
|
493
|
+
</SheetContent>
|
|
494
|
+
</Sheet>
|
|
495
|
+
)
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
export type { ShipmentDrawerProps, ShipmentData }
|