@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,448 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Ships Map dashboard widget — fleet-level overview of every vessel currently carrying the
|
|
5
|
+
* organization's tracked containers, plus ports where at-rest cargo waits. Read-only overlay
|
|
6
|
+
* over the `shipment_tracking.dashboard.ships_map` aggregation route.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import * as React from 'react'
|
|
10
|
+
import Link from 'next/link'
|
|
11
|
+
import { GoogleMap, useJsApiLoader, MarkerF, InfoWindowF } from '@react-google-maps/api'
|
|
12
|
+
import { Ship, Anchor, X } from 'lucide-react'
|
|
13
|
+
import type { DashboardWidgetComponentProps } from '@open-mercato/shared/modules/dashboard/widgets'
|
|
14
|
+
import { apiCall } from '@freighttech/ui/backend/utils/apiCall'
|
|
15
|
+
import { Spinner } from '@freighttech/ui/primitives/spinner'
|
|
16
|
+
import { useT } from '@open-mercato/shared/lib/i18n/context'
|
|
17
|
+
import type { ShipsMapResponse, ShipsMapMarker } from '../../../data/validators'
|
|
18
|
+
import { DEFAULT_SETTINGS, hydrateShipsMapSettings, type ShipsMapSettings } from './config'
|
|
19
|
+
|
|
20
|
+
// ─── Types ───────────────────────────────────────────────────
|
|
21
|
+
|
|
22
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
23
|
+
type GoogleMapInstance = any
|
|
24
|
+
|
|
25
|
+
// ─── Map configuration (shared look with VesselTrackingMap) ──
|
|
26
|
+
|
|
27
|
+
const containerStyle: React.CSSProperties = { width: '100%', height: '100%' }
|
|
28
|
+
|
|
29
|
+
const mapOptions: Record<string, unknown> = {
|
|
30
|
+
zoomControl: true,
|
|
31
|
+
mapTypeControl: false,
|
|
32
|
+
scaleControl: false,
|
|
33
|
+
streetViewControl: false,
|
|
34
|
+
rotateControl: false,
|
|
35
|
+
fullscreenControl: false,
|
|
36
|
+
disableDefaultUI: false,
|
|
37
|
+
gestureHandling: 'cooperative',
|
|
38
|
+
// Muted gray-pastel skin: soft slate water, near-white land, faint borders, hidden POIs/
|
|
39
|
+
// transit and road labels for an uncluttered overview tile.
|
|
40
|
+
styles: [
|
|
41
|
+
{ elementType: 'geometry', stylers: [{ color: '#f3f4f6' }] },
|
|
42
|
+
{ elementType: 'labels.text.fill', stylers: [{ color: '#9aa0a6' }] },
|
|
43
|
+
{ elementType: 'labels.text.stroke', stylers: [{ color: '#ffffff' }, { weight: 2 }] },
|
|
44
|
+
{ featureType: 'water', elementType: 'geometry', stylers: [{ color: '#dde3ea' }] },
|
|
45
|
+
{ featureType: 'water', elementType: 'labels.text.fill', stylers: [{ color: '#aab2bd' }] },
|
|
46
|
+
{ featureType: 'landscape', elementType: 'geometry', stylers: [{ color: '#f1f2f4' }] },
|
|
47
|
+
{ featureType: 'road', elementType: 'geometry', stylers: [{ color: '#e7e9ed' }] },
|
|
48
|
+
{ featureType: 'road', elementType: 'labels', stylers: [{ visibility: 'off' }] },
|
|
49
|
+
{ featureType: 'administrative', elementType: 'geometry.stroke', stylers: [{ color: '#d6d9df' }] },
|
|
50
|
+
{ featureType: 'administrative.country', elementType: 'geometry.stroke', stylers: [{ color: '#c6cad1' }] },
|
|
51
|
+
{ featureType: 'administrative.land_parcel', stylers: [{ visibility: 'off' }] },
|
|
52
|
+
{ featureType: 'poi', stylers: [{ visibility: 'off' }] },
|
|
53
|
+
{ featureType: 'transit', stylers: [{ visibility: 'off' }] },
|
|
54
|
+
],
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Top-down container-ship silhouette (pointing north), shared with VesselTrackingMap.
|
|
58
|
+
const CONTAINER_SHIP_PATH = `
|
|
59
|
+
M 12 2 L 8 7 L 8 30 Q 8 32, 10 32 L 10 34 L 14 34 L 14 32 Q 16 32, 16 30 L 16 7 L 12 2 Z
|
|
60
|
+
M 10 32 L 10 36 L 14 36 L 14 32 Z
|
|
61
|
+
`
|
|
62
|
+
|
|
63
|
+
// ─── Data loading ────────────────────────────────────────────
|
|
64
|
+
|
|
65
|
+
async function loadShipsMap(): Promise<ShipsMapResponse> {
|
|
66
|
+
const call = await apiCall<ShipsMapResponse>('/api/shipment_tracking/dashboard/ships-map')
|
|
67
|
+
if (!call.ok) {
|
|
68
|
+
const message =
|
|
69
|
+
typeof (call.result as Record<string, unknown> | null)?.error === 'string'
|
|
70
|
+
? ((call.result as Record<string, unknown>).error as string)
|
|
71
|
+
: `Request failed with status ${call.status}`
|
|
72
|
+
throw new Error(message)
|
|
73
|
+
}
|
|
74
|
+
return call.result ?? { markers: [], unresolvedCount: 0, generatedAt: new Date().toISOString() }
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// ─── Helpers ─────────────────────────────────────────────────
|
|
78
|
+
|
|
79
|
+
function formatRelativeTime(dateString: string | null, t: ReturnType<typeof useT>): string {
|
|
80
|
+
if (!dateString) return ''
|
|
81
|
+
const date = new Date(dateString)
|
|
82
|
+
if (Number.isNaN(date.getTime())) return ''
|
|
83
|
+
const diffMs = Date.now() - date.getTime()
|
|
84
|
+
const diffMinutes = Math.floor(diffMs / 60000)
|
|
85
|
+
const diffHours = Math.floor(diffMinutes / 60)
|
|
86
|
+
const diffDays = Math.floor(diffHours / 24)
|
|
87
|
+
if (diffMinutes < 1) return t('shipment_tracking.map.justNow', 'Just now')
|
|
88
|
+
if (diffMinutes < 60) return t('shipment_tracking.map.minutesAgo', '{{count}} min ago', { count: diffMinutes })
|
|
89
|
+
if (diffHours < 24) return t('shipment_tracking.map.hoursAgo', '{{count}}h ago', { count: diffHours })
|
|
90
|
+
return t('shipment_tracking.map.daysAgo', '{{count}}d ago', { count: diffDays })
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function markerKey(marker: ShipsMapMarker, index: number): string {
|
|
94
|
+
return marker.kind === 'vessel' ? `vessel:${marker.imo}` : `port:${marker.unlocode ?? index}`
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// ─── Settings panel ──────────────────────────────────────────
|
|
98
|
+
|
|
99
|
+
function SettingsPanel({
|
|
100
|
+
settings,
|
|
101
|
+
onSettingsChange,
|
|
102
|
+
}: {
|
|
103
|
+
settings: ShipsMapSettings
|
|
104
|
+
onSettingsChange: (next: ShipsMapSettings) => void
|
|
105
|
+
}) {
|
|
106
|
+
const t = useT()
|
|
107
|
+
const update = (patch: Partial<ShipsMapSettings>) => onSettingsChange({ ...settings, ...patch })
|
|
108
|
+
const inputClass =
|
|
109
|
+
'w-full rounded-md border border-border bg-background px-2 py-1 text-body-regular-sm text-foreground'
|
|
110
|
+
return (
|
|
111
|
+
<div className="space-y-3">
|
|
112
|
+
<label className="block space-y-1">
|
|
113
|
+
<span className="text-body-medium-sm text-muted-foreground">
|
|
114
|
+
{t('shipment_tracking.dashboard.ships_map.settings.zoom', 'Default zoom')}
|
|
115
|
+
</span>
|
|
116
|
+
<input
|
|
117
|
+
type="number"
|
|
118
|
+
min={1}
|
|
119
|
+
max={20}
|
|
120
|
+
value={settings.defaultZoom}
|
|
121
|
+
onChange={(e) => update({ defaultZoom: Number(e.target.value) })}
|
|
122
|
+
className={inputClass}
|
|
123
|
+
/>
|
|
124
|
+
</label>
|
|
125
|
+
<div className="grid grid-cols-2 gap-3">
|
|
126
|
+
<label className="block space-y-1">
|
|
127
|
+
<span className="text-body-medium-sm text-muted-foreground">
|
|
128
|
+
{t('shipment_tracking.dashboard.ships_map.settings.centerLat', 'Center latitude')}
|
|
129
|
+
</span>
|
|
130
|
+
<input
|
|
131
|
+
type="number"
|
|
132
|
+
step="0.1"
|
|
133
|
+
value={settings.centerLat}
|
|
134
|
+
onChange={(e) => update({ centerLat: Number(e.target.value) })}
|
|
135
|
+
className={inputClass}
|
|
136
|
+
/>
|
|
137
|
+
</label>
|
|
138
|
+
<label className="block space-y-1">
|
|
139
|
+
<span className="text-body-medium-sm text-muted-foreground">
|
|
140
|
+
{t('shipment_tracking.dashboard.ships_map.settings.centerLng', 'Center longitude')}
|
|
141
|
+
</span>
|
|
142
|
+
<input
|
|
143
|
+
type="number"
|
|
144
|
+
step="0.1"
|
|
145
|
+
value={settings.centerLng}
|
|
146
|
+
onChange={(e) => update({ centerLng: Number(e.target.value) })}
|
|
147
|
+
className={inputClass}
|
|
148
|
+
/>
|
|
149
|
+
</label>
|
|
150
|
+
</div>
|
|
151
|
+
<label className="block space-y-1">
|
|
152
|
+
<span className="text-body-medium-sm text-muted-foreground">
|
|
153
|
+
{t('shipment_tracking.dashboard.ships_map.settings.autoRefresh', 'Auto-refresh (seconds, 0 = off)')}
|
|
154
|
+
</span>
|
|
155
|
+
<input
|
|
156
|
+
type="number"
|
|
157
|
+
min={0}
|
|
158
|
+
value={settings.autoRefreshSeconds}
|
|
159
|
+
onChange={(e) => update({ autoRefreshSeconds: Number(e.target.value) })}
|
|
160
|
+
className={inputClass}
|
|
161
|
+
/>
|
|
162
|
+
</label>
|
|
163
|
+
</div>
|
|
164
|
+
)
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// ─── Widget ──────────────────────────────────────────────────
|
|
168
|
+
|
|
169
|
+
const ShipsMapWidget: React.FC<DashboardWidgetComponentProps<ShipsMapSettings>> = ({
|
|
170
|
+
mode,
|
|
171
|
+
settings,
|
|
172
|
+
onSettingsChange,
|
|
173
|
+
refreshToken,
|
|
174
|
+
onRefreshStateChange,
|
|
175
|
+
}) => {
|
|
176
|
+
const t = useT()
|
|
177
|
+
const hydrated = React.useMemo(() => hydrateShipsMapSettings(settings ?? DEFAULT_SETTINGS), [settings])
|
|
178
|
+
|
|
179
|
+
const { isLoaded, loadError } = useJsApiLoader({
|
|
180
|
+
id: 'google-map-script',
|
|
181
|
+
googleMapsApiKey: process.env.NEXT_PUBLIC_GOOGLE_MAPS_API_KEY || '',
|
|
182
|
+
})
|
|
183
|
+
|
|
184
|
+
const [data, setData] = React.useState<ShipsMapResponse | null>(null)
|
|
185
|
+
const [loading, setLoading] = React.useState(true)
|
|
186
|
+
const [error, setError] = React.useState<string | null>(null)
|
|
187
|
+
const [map, setMap] = React.useState<GoogleMapInstance | null>(null)
|
|
188
|
+
const [selected, setSelected] = React.useState<string | null>(null)
|
|
189
|
+
|
|
190
|
+
const refresh = React.useCallback(async () => {
|
|
191
|
+
onRefreshStateChange?.(true)
|
|
192
|
+
setLoading(true)
|
|
193
|
+
setError(null)
|
|
194
|
+
try {
|
|
195
|
+
setData(await loadShipsMap())
|
|
196
|
+
} catch (err) {
|
|
197
|
+
console.error('Failed to load ships map widget data', err)
|
|
198
|
+
setError(t('shipment_tracking.dashboard.ships_map.error', 'Failed to load ships map'))
|
|
199
|
+
} finally {
|
|
200
|
+
setLoading(false)
|
|
201
|
+
onRefreshStateChange?.(false)
|
|
202
|
+
}
|
|
203
|
+
}, [onRefreshStateChange, t])
|
|
204
|
+
|
|
205
|
+
// Initial load + manual refresh via the card's refresh button.
|
|
206
|
+
React.useEffect(() => {
|
|
207
|
+
if (mode === 'settings') return
|
|
208
|
+
refresh().catch(() => {})
|
|
209
|
+
}, [refresh, refreshToken, mode])
|
|
210
|
+
|
|
211
|
+
// Auto-refresh.
|
|
212
|
+
React.useEffect(() => {
|
|
213
|
+
if (mode === 'settings') return
|
|
214
|
+
if (!hydrated.autoRefreshSeconds || hydrated.autoRefreshSeconds <= 0) return
|
|
215
|
+
const id = setInterval(() => {
|
|
216
|
+
refresh().catch(() => {})
|
|
217
|
+
}, hydrated.autoRefreshSeconds * 1000)
|
|
218
|
+
return () => clearInterval(id)
|
|
219
|
+
}, [hydrated.autoRefreshSeconds, refresh, mode])
|
|
220
|
+
|
|
221
|
+
// Fit bounds to all markers once the map and data are ready.
|
|
222
|
+
React.useEffect(() => {
|
|
223
|
+
if (!map || !isLoaded || typeof window === 'undefined') return
|
|
224
|
+
const markers = data?.markers ?? []
|
|
225
|
+
if (markers.length === 0) return
|
|
226
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
227
|
+
const google = (window as any).google
|
|
228
|
+
if (!google) return
|
|
229
|
+
if (markers.length === 1) {
|
|
230
|
+
map.setCenter(markers[0].position)
|
|
231
|
+
map.setZoom(Math.max(hydrated.defaultZoom, 5))
|
|
232
|
+
return
|
|
233
|
+
}
|
|
234
|
+
const bounds = new google.maps.LatLngBounds()
|
|
235
|
+
markers.forEach((m) => bounds.extend(m.position))
|
|
236
|
+
map.fitBounds(bounds, 48)
|
|
237
|
+
}, [map, isLoaded, data, hydrated.defaultZoom])
|
|
238
|
+
|
|
239
|
+
const shipIconFactory = React.useCallback(
|
|
240
|
+
(heading: number | null) => {
|
|
241
|
+
if (!isLoaded || typeof window === 'undefined') return undefined
|
|
242
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
243
|
+
const google = (window as any).google
|
|
244
|
+
if (!google) return undefined
|
|
245
|
+
return {
|
|
246
|
+
path: CONTAINER_SHIP_PATH,
|
|
247
|
+
fillColor: '#0f172a',
|
|
248
|
+
fillOpacity: 0.95,
|
|
249
|
+
strokeColor: '#ffffff',
|
|
250
|
+
strokeWeight: 1.5,
|
|
251
|
+
scale: 1.0,
|
|
252
|
+
rotation: heading ?? 0,
|
|
253
|
+
anchor: new google.maps.Point(12, 18),
|
|
254
|
+
}
|
|
255
|
+
},
|
|
256
|
+
[isLoaded],
|
|
257
|
+
)
|
|
258
|
+
|
|
259
|
+
const portIcon = React.useMemo(() => {
|
|
260
|
+
if (!isLoaded || typeof window === 'undefined') return undefined
|
|
261
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
262
|
+
const google = (window as any).google
|
|
263
|
+
if (!google) return undefined
|
|
264
|
+
return {
|
|
265
|
+
path: google.maps.SymbolPath.CIRCLE,
|
|
266
|
+
scale: 7,
|
|
267
|
+
fillColor: '#059669',
|
|
268
|
+
fillOpacity: 0.95,
|
|
269
|
+
strokeColor: '#ffffff',
|
|
270
|
+
strokeWeight: 2,
|
|
271
|
+
}
|
|
272
|
+
}, [isLoaded])
|
|
273
|
+
|
|
274
|
+
const infoWindowOptions = React.useMemo(() => {
|
|
275
|
+
if (!isLoaded || typeof window === 'undefined') return undefined
|
|
276
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
277
|
+
const google = (window as any).google
|
|
278
|
+
if (!google) return undefined
|
|
279
|
+
return { headerDisabled: true, pixelOffset: new google.maps.Size(0, -6), maxWidth: 280 }
|
|
280
|
+
}, [isLoaded])
|
|
281
|
+
|
|
282
|
+
// ─── Settings mode ─────────────────────────────────────────
|
|
283
|
+
if (mode === 'settings') {
|
|
284
|
+
return <SettingsPanel settings={hydrated} onSettingsChange={onSettingsChange} />
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
// ─── Error / map-load states ───────────────────────────────
|
|
288
|
+
if (loadError) {
|
|
289
|
+
return (
|
|
290
|
+
<div className="flex h-64 items-center justify-center rounded-lg border border-border bg-muted">
|
|
291
|
+
<p className="text-body-regular-sm text-muted-foreground">
|
|
292
|
+
{t('shipment_tracking.map.loadError', 'Failed to load map')}
|
|
293
|
+
</p>
|
|
294
|
+
</div>
|
|
295
|
+
)
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
if (error) {
|
|
299
|
+
return (
|
|
300
|
+
<div className="flex h-64 items-center justify-center rounded-lg border border-border bg-muted">
|
|
301
|
+
<p className="text-body-regular-sm text-destructive">{error}</p>
|
|
302
|
+
</div>
|
|
303
|
+
)
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
const markers = data?.markers ?? []
|
|
307
|
+
const vesselCount = markers.filter((m) => m.kind === 'vessel').length
|
|
308
|
+
const showSpinner = !isLoaded || (loading && !data)
|
|
309
|
+
const isEmpty = !showSpinner && markers.length === 0
|
|
310
|
+
|
|
311
|
+
return (
|
|
312
|
+
<div className="space-y-2">
|
|
313
|
+
{/* Header: counts + unresolved hint */}
|
|
314
|
+
<div className="flex items-center justify-between gap-2">
|
|
315
|
+
<div className="flex items-center gap-1.5 text-body-medium-sm text-foreground">
|
|
316
|
+
<Ship className="h-4 w-4 text-blue-500" />
|
|
317
|
+
<span>
|
|
318
|
+
{t('shipment_tracking.dashboard.ships_map.vesselCount', '{{count}} ships', { count: vesselCount })}
|
|
319
|
+
</span>
|
|
320
|
+
</div>
|
|
321
|
+
{data && data.unresolvedCount > 0 && (
|
|
322
|
+
<span className="text-body-regular-xs text-muted-foreground">
|
|
323
|
+
{t('shipment_tracking.dashboard.ships_map.unresolved', '{{count}} without position', {
|
|
324
|
+
count: data.unresolvedCount,
|
|
325
|
+
})}
|
|
326
|
+
</span>
|
|
327
|
+
)}
|
|
328
|
+
</div>
|
|
329
|
+
|
|
330
|
+
<div className="relative h-72 overflow-hidden rounded-lg border border-border">
|
|
331
|
+
{showSpinner && (
|
|
332
|
+
<div className="absolute inset-0 z-10 flex flex-col items-center justify-center gap-2 bg-muted">
|
|
333
|
+
<Spinner className="h-6 w-6" />
|
|
334
|
+
<span className="text-body-regular-sm text-muted-foreground">
|
|
335
|
+
{t('shipment_tracking.dashboard.ships_map.loading', 'Loading map…')}
|
|
336
|
+
</span>
|
|
337
|
+
</div>
|
|
338
|
+
)}
|
|
339
|
+
|
|
340
|
+
{isEmpty && (
|
|
341
|
+
<div className="absolute inset-0 z-10 flex flex-col items-center justify-center gap-2 bg-muted">
|
|
342
|
+
<Ship className="h-8 w-8 text-muted-foreground" />
|
|
343
|
+
<span className="text-body-regular-sm text-muted-foreground">
|
|
344
|
+
{t('shipment_tracking.dashboard.ships_map.empty', 'No active vessels')}
|
|
345
|
+
</span>
|
|
346
|
+
</div>
|
|
347
|
+
)}
|
|
348
|
+
|
|
349
|
+
{isLoaded && (
|
|
350
|
+
<GoogleMap
|
|
351
|
+
mapContainerStyle={containerStyle}
|
|
352
|
+
center={{ lat: hydrated.centerLat, lng: hydrated.centerLng }}
|
|
353
|
+
zoom={hydrated.defaultZoom}
|
|
354
|
+
onLoad={(m) => setMap(m)}
|
|
355
|
+
onUnmount={() => setMap(null)}
|
|
356
|
+
options={mapOptions}
|
|
357
|
+
>
|
|
358
|
+
{markers.map((marker, index) => {
|
|
359
|
+
const key = markerKey(marker, index)
|
|
360
|
+
return (
|
|
361
|
+
<MarkerF
|
|
362
|
+
key={key}
|
|
363
|
+
position={marker.position}
|
|
364
|
+
icon={marker.kind === 'vessel' ? shipIconFactory(marker.heading) : portIcon}
|
|
365
|
+
title={marker.kind === 'vessel' ? marker.name ?? marker.imo : marker.portName ?? undefined}
|
|
366
|
+
zIndex={marker.kind === 'vessel' ? 2000 : 1000}
|
|
367
|
+
onClick={() => setSelected(key)}
|
|
368
|
+
/>
|
|
369
|
+
)
|
|
370
|
+
})}
|
|
371
|
+
|
|
372
|
+
{markers.map((marker, index) => {
|
|
373
|
+
const key = markerKey(marker, index)
|
|
374
|
+
if (selected !== key) return null
|
|
375
|
+
return (
|
|
376
|
+
<InfoWindowF
|
|
377
|
+
key={`iw:${key}`}
|
|
378
|
+
position={marker.position}
|
|
379
|
+
onCloseClick={() => setSelected(null)}
|
|
380
|
+
options={infoWindowOptions}
|
|
381
|
+
>
|
|
382
|
+
<div className="relative min-w-[180px] max-w-[260px] pr-5 text-slate-800">
|
|
383
|
+
<button
|
|
384
|
+
type="button"
|
|
385
|
+
onClick={() => setSelected(null)}
|
|
386
|
+
aria-label={t('shipment_tracking.map.close', 'Close')}
|
|
387
|
+
className="absolute right-0 top-0 flex h-5 w-5 items-center justify-center rounded text-slate-400 hover:bg-slate-100 hover:text-slate-700"
|
|
388
|
+
>
|
|
389
|
+
<X className="h-3.5 w-3.5" />
|
|
390
|
+
</button>
|
|
391
|
+
|
|
392
|
+
{marker.kind === 'vessel' ? (
|
|
393
|
+
<div className="mb-1.5">
|
|
394
|
+
<div className="flex items-center gap-1.5">
|
|
395
|
+
<Ship className="h-3.5 w-3.5 text-blue-500" />
|
|
396
|
+
<span className="text-sm font-semibold leading-tight text-slate-900">
|
|
397
|
+
{marker.name ?? t('shipment_tracking.map.unknown', 'Unknown')}
|
|
398
|
+
</span>
|
|
399
|
+
</div>
|
|
400
|
+
<div className="mt-0.5 font-mono text-[11px] text-slate-400">IMO {marker.imo}</div>
|
|
401
|
+
{marker.destination && (
|
|
402
|
+
<div className="mt-0.5 text-xs text-slate-500">→ {marker.destination}</div>
|
|
403
|
+
)}
|
|
404
|
+
{marker.updatedAt && (
|
|
405
|
+
<div className="text-[11px] text-slate-400">
|
|
406
|
+
{formatRelativeTime(marker.updatedAt, t)}
|
|
407
|
+
</div>
|
|
408
|
+
)}
|
|
409
|
+
</div>
|
|
410
|
+
) : (
|
|
411
|
+
<div className="mb-1.5">
|
|
412
|
+
<div className="flex items-center gap-1.5">
|
|
413
|
+
<Anchor className="h-3.5 w-3.5 text-emerald-600" />
|
|
414
|
+
<span className="text-sm font-semibold leading-tight text-slate-900">
|
|
415
|
+
{marker.portName ?? t('shipment_tracking.map.unknown', 'Unknown')}
|
|
416
|
+
</span>
|
|
417
|
+
</div>
|
|
418
|
+
{marker.unlocode && (
|
|
419
|
+
<div className="mt-0.5 font-mono text-[11px] text-slate-400">{marker.unlocode}</div>
|
|
420
|
+
)}
|
|
421
|
+
</div>
|
|
422
|
+
)}
|
|
423
|
+
|
|
424
|
+
<div className="space-y-0.5 border-t border-slate-100 pt-1.5">
|
|
425
|
+
{marker.shipments.map((s) => (
|
|
426
|
+
<Link
|
|
427
|
+
key={s.id}
|
|
428
|
+
href={`/backend/shipment-tracking?shipment=${s.id}`}
|
|
429
|
+
className="block truncate text-xs text-blue-600 hover:underline"
|
|
430
|
+
title={s.containerNumber ?? s.id}
|
|
431
|
+
>
|
|
432
|
+
{s.containerNumber ?? s.id}
|
|
433
|
+
{s.destinationLocation ? ` · ${s.destinationLocation}` : ''}
|
|
434
|
+
</Link>
|
|
435
|
+
))}
|
|
436
|
+
</div>
|
|
437
|
+
</div>
|
|
438
|
+
</InfoWindowF>
|
|
439
|
+
)
|
|
440
|
+
})}
|
|
441
|
+
</GoogleMap>
|
|
442
|
+
)}
|
|
443
|
+
</div>
|
|
444
|
+
</div>
|
|
445
|
+
)
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
export default ShipsMapWidget
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { lazyDashboardWidget, type DashboardWidgetModule } from '@open-mercato/shared/modules/dashboard/widgets'
|
|
2
|
+
import { DEFAULT_SETTINGS, hydrateShipsMapSettings, type ShipsMapSettings } from './config'
|
|
3
|
+
|
|
4
|
+
const ShipsMapWidget = lazyDashboardWidget(() => import('./widget.client'))
|
|
5
|
+
|
|
6
|
+
const widget: DashboardWidgetModule<ShipsMapSettings> = {
|
|
7
|
+
metadata: {
|
|
8
|
+
id: 'shipment_tracking.dashboard.ships_map',
|
|
9
|
+
title: 'Ships Map',
|
|
10
|
+
description: 'Live positions of every vessel carrying your tracked containers, on one map.',
|
|
11
|
+
features: ['dashboards.view', 'shipment_tracking.dashboard.ships_map.view'],
|
|
12
|
+
defaultSize: 'lg',
|
|
13
|
+
defaultEnabled: false,
|
|
14
|
+
defaultSettings: DEFAULT_SETTINGS,
|
|
15
|
+
tags: ['fms', 'shipment_tracking', 'map'],
|
|
16
|
+
category: 'shipment_tracking',
|
|
17
|
+
icon: 'ship',
|
|
18
|
+
supportsRefresh: true,
|
|
19
|
+
},
|
|
20
|
+
Widget: ShipsMapWidget,
|
|
21
|
+
hydrateSettings: hydrateShipsMapSettings,
|
|
22
|
+
dehydrateSettings: (settings) => settings,
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export default widget
|