@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,197 @@
|
|
|
1
|
+
import { makeCrudRoute } from '@open-mercato/shared/lib/crud/factory'
|
|
2
|
+
import { z } from 'zod'
|
|
3
|
+
import { Shipment } from '../../data/entities'
|
|
4
|
+
import { shipmentListSchema, shipmentCreateSchema, shipmentUpdateSchema } from '../../data/validators'
|
|
5
|
+
import { escapeLikePattern } from '@open-mercato/shared/lib/db/escapeLikePattern'
|
|
6
|
+
import {
|
|
7
|
+
createShipmentTrackingCrudOpenApi,
|
|
8
|
+
createPagedListResponseSchema,
|
|
9
|
+
defaultOkResponseSchema,
|
|
10
|
+
} from '../openapi'
|
|
11
|
+
import { withScopedPayload } from '../utils'
|
|
12
|
+
import { resolveTranslations } from '@open-mercato/shared/lib/i18n/server'
|
|
13
|
+
|
|
14
|
+
const rawBodySchema = z.object({}).passthrough()
|
|
15
|
+
|
|
16
|
+
type ShipmentListQuery = z.infer<typeof shipmentListSchema>
|
|
17
|
+
|
|
18
|
+
const routeMetadata = {
|
|
19
|
+
GET: { requireAuth: true, requireFeatures: ['shipment_tracking.shipments.view'] },
|
|
20
|
+
POST: { requireAuth: true, requireFeatures: ['shipment_tracking.shipments.manage'] },
|
|
21
|
+
PUT: { requireAuth: true, requireFeatures: ['shipment_tracking.shipments.manage'] },
|
|
22
|
+
DELETE: { requireAuth: true, requireFeatures: ['shipment_tracking.shipments.manage'] },
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const listFields = [
|
|
26
|
+
'id',
|
|
27
|
+
'status',
|
|
28
|
+
'carrierCode',
|
|
29
|
+
'containerNumber',
|
|
30
|
+
'bookingNumber',
|
|
31
|
+
'isoEquipmentCode',
|
|
32
|
+
'bolNumber',
|
|
33
|
+
// Multi-source timestamp arrays
|
|
34
|
+
'etdTimestamps',
|
|
35
|
+
'etaTimestamps',
|
|
36
|
+
'atdTimestamps',
|
|
37
|
+
'ataTimestamps',
|
|
38
|
+
// Location data (JSONB)
|
|
39
|
+
'originLocation',
|
|
40
|
+
'destinationLocation',
|
|
41
|
+
// Vessel info
|
|
42
|
+
'vesselName',
|
|
43
|
+
'vesselImo',
|
|
44
|
+
'voyageNumber',
|
|
45
|
+
'eventCount',
|
|
46
|
+
// Denormalized route & events (JSONB)
|
|
47
|
+
'routeStops',
|
|
48
|
+
'cargoEvents',
|
|
49
|
+
// Aggregated seals (JSONB)
|
|
50
|
+
'seals',
|
|
51
|
+
// Tracking job relation (for fetching events - kept for backward compatibility)
|
|
52
|
+
'trackingJob',
|
|
53
|
+
'createdAt',
|
|
54
|
+
'updatedAt',
|
|
55
|
+
]
|
|
56
|
+
|
|
57
|
+
const buildFilters = (query: ShipmentListQuery): Record<string, unknown> => {
|
|
58
|
+
const filters: Record<string, unknown> = { deletedAt: null }
|
|
59
|
+
|
|
60
|
+
if (query.id) {
|
|
61
|
+
filters.id = query.id
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const search = query.search?.trim()
|
|
65
|
+
if (search && search.length > 0) {
|
|
66
|
+
const escaped = escapeLikePattern(search)
|
|
67
|
+
const pattern = `%${escaped}%`
|
|
68
|
+
filters.$or = [
|
|
69
|
+
{ containerNumber: { $ilike: pattern } },
|
|
70
|
+
{ bookingNumber: { $ilike: pattern } },
|
|
71
|
+
{ bolNumber: { $ilike: pattern } },
|
|
72
|
+
{ carrierCode: { $ilike: pattern } },
|
|
73
|
+
{ vesselName: { $ilike: pattern } },
|
|
74
|
+
// HEDGE-101 — JSONB nested property search, as NESTED OBJECTS.
|
|
75
|
+
//
|
|
76
|
+
// `origin_location` / `destination_location` are `jsonb` columns, not
|
|
77
|
+
// relations. A dotted string key (`'originLocation.name'`) is read by
|
|
78
|
+
// MikroORM as a RELATION PATH, so it emitted a condition against a table
|
|
79
|
+
// that was never joined and the query died with
|
|
80
|
+
// `missing FROM-clause entry for table "originLocation"` — a hard 500 on
|
|
81
|
+
// every keystroke. The nested-object form is what compiles to
|
|
82
|
+
// `"origin_location"->>'name'`.
|
|
83
|
+
//
|
|
84
|
+
// The condition is only added when `q` is non-empty, which is why the
|
|
85
|
+
// route looked healthy until the first search: this path had never worked.
|
|
86
|
+
{ originLocation: { name: { $ilike: pattern } } },
|
|
87
|
+
{ originLocation: { unlocode: { $ilike: pattern } } },
|
|
88
|
+
{ destinationLocation: { name: { $ilike: pattern } } },
|
|
89
|
+
{ destinationLocation: { unlocode: { $ilike: pattern } } },
|
|
90
|
+
]
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (query.status) {
|
|
94
|
+
filters.status = query.status
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (query.carrierCode) {
|
|
98
|
+
filters.carrierCode = query.carrierCode
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return filters
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const crud = makeCrudRoute({
|
|
105
|
+
metadata: routeMetadata,
|
|
106
|
+
orm: {
|
|
107
|
+
entity: Shipment,
|
|
108
|
+
idField: 'id',
|
|
109
|
+
orgField: 'organizationId',
|
|
110
|
+
tenantField: 'tenantId',
|
|
111
|
+
softDeleteField: 'deletedAt',
|
|
112
|
+
},
|
|
113
|
+
list: {
|
|
114
|
+
schema: shipmentListSchema,
|
|
115
|
+
fields: listFields,
|
|
116
|
+
sortFieldMap: {
|
|
117
|
+
id: 'id',
|
|
118
|
+
status: 'status',
|
|
119
|
+
carrierCode: 'carrier_code',
|
|
120
|
+
containerNumber: 'container_number',
|
|
121
|
+
bookingNumber: 'booking_number',
|
|
122
|
+
createdAt: 'created_at',
|
|
123
|
+
updatedAt: 'updated_at',
|
|
124
|
+
},
|
|
125
|
+
buildFilters: async (query) => buildFilters(query),
|
|
126
|
+
},
|
|
127
|
+
actions: {
|
|
128
|
+
create: {
|
|
129
|
+
commandId: 'shipment_tracking.shipment.create',
|
|
130
|
+
schema: rawBodySchema,
|
|
131
|
+
mapInput: async ({ raw, ctx }) => {
|
|
132
|
+
const { translate } = await resolveTranslations()
|
|
133
|
+
const scoped = withScopedPayload(raw ?? {}, ctx, translate)
|
|
134
|
+
return shipmentCreateSchema.parse(scoped)
|
|
135
|
+
},
|
|
136
|
+
response: ({ result }) => ({ id: result?.id ?? null }),
|
|
137
|
+
status: 201,
|
|
138
|
+
},
|
|
139
|
+
update: {
|
|
140
|
+
commandId: 'shipment_tracking.shipment.update',
|
|
141
|
+
schema: rawBodySchema,
|
|
142
|
+
mapInput: async ({ raw, ctx }) => {
|
|
143
|
+
const { translate } = await resolveTranslations()
|
|
144
|
+
const scoped = withScopedPayload(raw ?? {}, ctx, translate)
|
|
145
|
+
return shipmentUpdateSchema.parse(scoped)
|
|
146
|
+
},
|
|
147
|
+
response: ({ result }) => ({ id: result?.id ?? null }),
|
|
148
|
+
status: 200,
|
|
149
|
+
},
|
|
150
|
+
delete: {
|
|
151
|
+
commandId: 'shipment_tracking.shipment.delete',
|
|
152
|
+
schema: rawBodySchema,
|
|
153
|
+
mapInput: async ({ raw, ctx }) => {
|
|
154
|
+
const { translate } = await resolveTranslations()
|
|
155
|
+
const body = (raw as any)?.body ?? raw ?? {}
|
|
156
|
+
const scoped = withScopedPayload(body, ctx, translate)
|
|
157
|
+
return { id: body.id, ...scoped }
|
|
158
|
+
},
|
|
159
|
+
response: ({ result }) => ({ id: result?.id ?? null }),
|
|
160
|
+
status: 200,
|
|
161
|
+
},
|
|
162
|
+
},
|
|
163
|
+
})
|
|
164
|
+
|
|
165
|
+
export const openApi = createShipmentTrackingCrudOpenApi({
|
|
166
|
+
resourceName: 'Shipment',
|
|
167
|
+
pluralName: 'Shipments',
|
|
168
|
+
querySchema: shipmentListSchema,
|
|
169
|
+
listResponseSchema: createPagedListResponseSchema(z.object({
|
|
170
|
+
id: z.string().uuid(),
|
|
171
|
+
status: z.string(),
|
|
172
|
+
carrierCode: z.string().nullable(),
|
|
173
|
+
containerNumber: z.string().nullable(),
|
|
174
|
+
bookingNumber: z.string().nullable(),
|
|
175
|
+
bolNumber: z.string().nullable(),
|
|
176
|
+
})),
|
|
177
|
+
create: {
|
|
178
|
+
schema: rawBodySchema,
|
|
179
|
+
description: 'Creates a new shipment.',
|
|
180
|
+
},
|
|
181
|
+
update: {
|
|
182
|
+
schema: rawBodySchema,
|
|
183
|
+
responseSchema: defaultOkResponseSchema,
|
|
184
|
+
description: 'Updates an existing shipment by id.',
|
|
185
|
+
},
|
|
186
|
+
del: {
|
|
187
|
+
schema: z.object({ id: z.string().uuid() }),
|
|
188
|
+
responseSchema: defaultOkResponseSchema,
|
|
189
|
+
description: 'Soft-deletes a shipment by id.',
|
|
190
|
+
},
|
|
191
|
+
})
|
|
192
|
+
|
|
193
|
+
export const metadata = crud.metadata
|
|
194
|
+
export const GET = crud.GET
|
|
195
|
+
export const POST = crud.POST
|
|
196
|
+
export const PUT = crud.PUT
|
|
197
|
+
export const DELETE = crud.DELETE
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { NextRequest, NextResponse } from 'next/server'
|
|
2
|
+
import { z } from 'zod'
|
|
3
|
+
import type { EntityManager } from '@mikro-orm/postgresql'
|
|
4
|
+
import { createRequestContainer } from '@open-mercato/shared/lib/di/container'
|
|
5
|
+
import { getAuthFromRequest } from '@open-mercato/shared/lib/auth/server'
|
|
6
|
+
import { resolveOrganizationScopeForRequest } from '@open-mercato/core/modules/directory/utils/organizationScope'
|
|
7
|
+
import type { CommandBus } from '@open-mercato/shared/lib/commands'
|
|
8
|
+
import { findOneWithDecryption } from '@open-mercato/shared/lib/encryption/find'
|
|
9
|
+
import { ShipsGoConfig } from '../../data/entities'
|
|
10
|
+
import { shipsGoConfigUpsertSchema } from '../../data/validators'
|
|
11
|
+
import {
|
|
12
|
+
createShipmentTrackingCrudOpenApi,
|
|
13
|
+
defaultOkResponseSchema,
|
|
14
|
+
} from '../openapi'
|
|
15
|
+
|
|
16
|
+
// ─── Metadata ────────────────────────────────────────────────
|
|
17
|
+
|
|
18
|
+
export const metadata = {
|
|
19
|
+
GET: { requireAuth: true, requireFeatures: ['shipment_tracking.shipsgo_config.view'] },
|
|
20
|
+
PUT: { requireAuth: true, requireFeatures: ['shipment_tracking.shipsgo_config.manage'] },
|
|
21
|
+
DELETE: { requireAuth: true, requireFeatures: ['shipment_tracking.shipsgo_config.manage'] },
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// ─── OpenAPI ─────────────────────────────────────────────────
|
|
25
|
+
|
|
26
|
+
const upsertSchema = z.object({
|
|
27
|
+
isEnabled: z.boolean(),
|
|
28
|
+
apiToken: z.string(),
|
|
29
|
+
baseUrl: z.string().optional(),
|
|
30
|
+
oceanEnabled: z.boolean().optional(),
|
|
31
|
+
airEnabled: z.boolean().optional(),
|
|
32
|
+
rateLimitRequests: z.number().optional(),
|
|
33
|
+
rateLimitWindowSeconds: z.number().optional(),
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
const shipsGoConfigResponseSchema = z.object({
|
|
37
|
+
id: z.string().uuid(),
|
|
38
|
+
organizationId: z.string().uuid(),
|
|
39
|
+
tenantId: z.string().uuid(),
|
|
40
|
+
isEnabled: z.boolean(),
|
|
41
|
+
baseUrl: z.string(),
|
|
42
|
+
oceanEnabled: z.boolean(),
|
|
43
|
+
airEnabled: z.boolean(),
|
|
44
|
+
rateLimitRequests: z.number(),
|
|
45
|
+
rateLimitWindowSeconds: z.number(),
|
|
46
|
+
createdAt: z.string(),
|
|
47
|
+
updatedAt: z.string(),
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
export const openApi = createShipmentTrackingCrudOpenApi({
|
|
51
|
+
resourceName: 'ShipsGoConfig',
|
|
52
|
+
pluralName: 'ShipsGoConfigs',
|
|
53
|
+
querySchema: z.object({}),
|
|
54
|
+
listResponseSchema: z.object({ config: shipsGoConfigResponseSchema.nullable() }),
|
|
55
|
+
update: {
|
|
56
|
+
schema: upsertSchema,
|
|
57
|
+
responseSchema: defaultOkResponseSchema,
|
|
58
|
+
description: 'Creates or updates the ShipsGo API configuration for the current organization.',
|
|
59
|
+
},
|
|
60
|
+
del: {
|
|
61
|
+
schema: z.object({}),
|
|
62
|
+
responseSchema: defaultOkResponseSchema,
|
|
63
|
+
description: 'Deletes the ShipsGo API configuration.',
|
|
64
|
+
},
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
// ─── GET - Retrieve current config ───────────────────────────
|
|
68
|
+
|
|
69
|
+
export async function GET(request: NextRequest) {
|
|
70
|
+
const auth = await getAuthFromRequest(request)
|
|
71
|
+
|
|
72
|
+
if (!auth?.orgId || !auth?.tenantId) {
|
|
73
|
+
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const container = await createRequestContainer()
|
|
77
|
+
const scope = await resolveOrganizationScopeForRequest({ container, auth, request })
|
|
78
|
+
const em = container.resolve('em') as EntityManager
|
|
79
|
+
|
|
80
|
+
const organizationId = scope?.selectedId ?? auth.orgId
|
|
81
|
+
const tenantId = auth.tenantId
|
|
82
|
+
|
|
83
|
+
const config = await findOneWithDecryption(
|
|
84
|
+
em,
|
|
85
|
+
ShipsGoConfig,
|
|
86
|
+
{ organizationId, tenantId, deletedAt: null },
|
|
87
|
+
{},
|
|
88
|
+
{ tenantId, organizationId },
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
if (!config) {
|
|
92
|
+
return NextResponse.json({ config: null })
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// Return config without the API token
|
|
96
|
+
return NextResponse.json({
|
|
97
|
+
config: {
|
|
98
|
+
id: config.id,
|
|
99
|
+
organizationId: config.organizationId,
|
|
100
|
+
tenantId: config.tenantId,
|
|
101
|
+
isEnabled: config.isEnabled,
|
|
102
|
+
// apiToken is NOT included for security
|
|
103
|
+
baseUrl: config.baseUrl,
|
|
104
|
+
oceanEnabled: config.oceanEnabled,
|
|
105
|
+
airEnabled: config.airEnabled,
|
|
106
|
+
rateLimitRequests: config.rateLimitRequests,
|
|
107
|
+
rateLimitWindowSeconds: config.rateLimitWindowSeconds,
|
|
108
|
+
createdAt: config.createdAt.toISOString(),
|
|
109
|
+
updatedAt: config.updatedAt.toISOString(),
|
|
110
|
+
},
|
|
111
|
+
})
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// ─── PUT - Upsert config ─────────────────────────────────────
|
|
115
|
+
|
|
116
|
+
export async function PUT(request: NextRequest) {
|
|
117
|
+
const auth = await getAuthFromRequest(request)
|
|
118
|
+
|
|
119
|
+
if (!auth?.orgId || !auth?.tenantId) {
|
|
120
|
+
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
let body: unknown
|
|
124
|
+
try {
|
|
125
|
+
body = await request.json()
|
|
126
|
+
} catch {
|
|
127
|
+
return NextResponse.json({ error: 'Invalid JSON body' }, { status: 400 })
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const container = await createRequestContainer()
|
|
131
|
+
const scope = await resolveOrganizationScopeForRequest({ container, auth, request })
|
|
132
|
+
const commandBus = container.resolve('commandBus') as CommandBus
|
|
133
|
+
|
|
134
|
+
const organizationId = scope?.selectedId ?? auth.orgId
|
|
135
|
+
const tenantId = auth.tenantId
|
|
136
|
+
|
|
137
|
+
try {
|
|
138
|
+
const input = shipsGoConfigUpsertSchema.parse({
|
|
139
|
+
...(body as object),
|
|
140
|
+
organizationId,
|
|
141
|
+
tenantId,
|
|
142
|
+
})
|
|
143
|
+
|
|
144
|
+
const { result } = await commandBus.execute<typeof input, { id: string }>(
|
|
145
|
+
'shipment_tracking.shipsgo_config.upsert',
|
|
146
|
+
{
|
|
147
|
+
input,
|
|
148
|
+
ctx: {
|
|
149
|
+
container,
|
|
150
|
+
auth,
|
|
151
|
+
organizationScope: scope,
|
|
152
|
+
selectedOrganizationId: organizationId ?? null,
|
|
153
|
+
organizationIds: scope?.filterIds ?? (organizationId ? [organizationId] : null),
|
|
154
|
+
request,
|
|
155
|
+
},
|
|
156
|
+
metadata: {
|
|
157
|
+
tenantId: tenantId ?? null,
|
|
158
|
+
organizationId: organizationId ?? null,
|
|
159
|
+
resourceKind: 'shipment_tracking.shipsgo_config',
|
|
160
|
+
},
|
|
161
|
+
}
|
|
162
|
+
)
|
|
163
|
+
|
|
164
|
+
return NextResponse.json({ id: result?.id ?? null })
|
|
165
|
+
} catch (err) {
|
|
166
|
+
console.error('[shipsgo-configs] PUT error:', err)
|
|
167
|
+
const message = err instanceof Error ? err.message : 'Failed to save ShipsGo config'
|
|
168
|
+
return NextResponse.json({ error: message }, { status: 400 })
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// ─── DELETE - Remove config ──────────────────────────────────
|
|
173
|
+
|
|
174
|
+
export async function DELETE(request: NextRequest) {
|
|
175
|
+
const auth = await getAuthFromRequest(request)
|
|
176
|
+
|
|
177
|
+
if (!auth?.orgId || !auth?.tenantId) {
|
|
178
|
+
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const container = await createRequestContainer()
|
|
182
|
+
const scope = await resolveOrganizationScopeForRequest({ container, auth, request })
|
|
183
|
+
const commandBus = container.resolve('commandBus') as CommandBus
|
|
184
|
+
|
|
185
|
+
const organizationId = scope?.selectedId ?? auth.orgId
|
|
186
|
+
const tenantId = auth.tenantId
|
|
187
|
+
|
|
188
|
+
try {
|
|
189
|
+
await commandBus.execute<{ organizationId: string; tenantId: string }, { success: boolean }>(
|
|
190
|
+
'shipment_tracking.shipsgo_config.delete',
|
|
191
|
+
{
|
|
192
|
+
input: { organizationId, tenantId },
|
|
193
|
+
ctx: {
|
|
194
|
+
container,
|
|
195
|
+
auth,
|
|
196
|
+
organizationScope: scope,
|
|
197
|
+
selectedOrganizationId: organizationId ?? null,
|
|
198
|
+
organizationIds: scope?.filterIds ?? (organizationId ? [organizationId] : null),
|
|
199
|
+
request,
|
|
200
|
+
},
|
|
201
|
+
metadata: {
|
|
202
|
+
tenantId: tenantId ?? null,
|
|
203
|
+
organizationId: organizationId ?? null,
|
|
204
|
+
resourceKind: 'shipment_tracking.shipsgo_config',
|
|
205
|
+
},
|
|
206
|
+
}
|
|
207
|
+
)
|
|
208
|
+
|
|
209
|
+
return NextResponse.json({ success: true })
|
|
210
|
+
} catch (err) {
|
|
211
|
+
console.error('[shipsgo-configs] DELETE error:', err)
|
|
212
|
+
const message = err instanceof Error ? err.message : 'Failed to delete ShipsGo config'
|
|
213
|
+
return NextResponse.json({ error: message }, { status: 400 })
|
|
214
|
+
}
|
|
215
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { makeCrudRoute } from '@open-mercato/shared/lib/crud/factory'
|
|
2
|
+
import { z } from 'zod'
|
|
3
|
+
import { TrackingJob } from '../../data/entities'
|
|
4
|
+
import { trackingJobListSchema, trackingJobCreateSchema, trackingJobUpdateSchema } from '../../data/validators'
|
|
5
|
+
import {
|
|
6
|
+
createShipmentTrackingCrudOpenApi,
|
|
7
|
+
createPagedListResponseSchema,
|
|
8
|
+
defaultOkResponseSchema,
|
|
9
|
+
} from '../openapi'
|
|
10
|
+
import { withScopedPayload } from '../utils'
|
|
11
|
+
import { resolveTranslations } from '@open-mercato/shared/lib/i18n/server'
|
|
12
|
+
|
|
13
|
+
const rawBodySchema = z.object({}).passthrough()
|
|
14
|
+
|
|
15
|
+
type TrackingJobListQuery = z.infer<typeof trackingJobListSchema>
|
|
16
|
+
|
|
17
|
+
const routeMetadata = {
|
|
18
|
+
GET: { requireAuth: true, requireFeatures: ['shipment_tracking.tracking_jobs.view'] },
|
|
19
|
+
POST: { requireAuth: true, requireFeatures: ['shipment_tracking.tracking_jobs.manage'] },
|
|
20
|
+
PUT: { requireAuth: true, requireFeatures: ['shipment_tracking.tracking_jobs.manage'] },
|
|
21
|
+
DELETE: { requireAuth: true, requireFeatures: ['shipment_tracking.tracking_jobs.manage'] },
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const listFields = [
|
|
25
|
+
'id',
|
|
26
|
+
'carrierCode',
|
|
27
|
+
'referenceType',
|
|
28
|
+
'referenceValue',
|
|
29
|
+
'status',
|
|
30
|
+
'nextPollAt',
|
|
31
|
+
'lastPollAt',
|
|
32
|
+
'retryCount',
|
|
33
|
+
'createdAt',
|
|
34
|
+
'updatedAt',
|
|
35
|
+
]
|
|
36
|
+
|
|
37
|
+
const buildFilters = (query: TrackingJobListQuery): Record<string, unknown> => {
|
|
38
|
+
const filters: Record<string, unknown> = {}
|
|
39
|
+
|
|
40
|
+
if (query.status) {
|
|
41
|
+
filters.status = query.status
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (query.carrierCode) {
|
|
45
|
+
filters.carrierCode = query.carrierCode
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (query.referenceType) {
|
|
49
|
+
filters.referenceType = query.referenceType
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (query.referenceValue) {
|
|
53
|
+
filters.referenceValue = query.referenceValue
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return filters
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const crud = makeCrudRoute({
|
|
60
|
+
metadata: routeMetadata,
|
|
61
|
+
orm: {
|
|
62
|
+
entity: TrackingJob,
|
|
63
|
+
idField: 'id',
|
|
64
|
+
orgField: 'organizationId',
|
|
65
|
+
tenantField: 'tenantId',
|
|
66
|
+
},
|
|
67
|
+
list: {
|
|
68
|
+
schema: trackingJobListSchema,
|
|
69
|
+
fields: listFields,
|
|
70
|
+
sortFieldMap: {
|
|
71
|
+
id: 'id',
|
|
72
|
+
carrierCode: 'carrier_code',
|
|
73
|
+
status: 'status',
|
|
74
|
+
nextPollAt: 'next_poll_at',
|
|
75
|
+
lastPollAt: 'last_poll_at',
|
|
76
|
+
createdAt: 'created_at',
|
|
77
|
+
},
|
|
78
|
+
buildFilters: async (query) => buildFilters(query),
|
|
79
|
+
},
|
|
80
|
+
actions: {
|
|
81
|
+
create: {
|
|
82
|
+
commandId: 'shipment_tracking.tracking_job.create',
|
|
83
|
+
schema: rawBodySchema,
|
|
84
|
+
mapInput: async ({ raw, ctx }) => {
|
|
85
|
+
const { translate } = await resolveTranslations()
|
|
86
|
+
const scoped = withScopedPayload(raw ?? {}, ctx, translate)
|
|
87
|
+
return trackingJobCreateSchema.parse(scoped)
|
|
88
|
+
},
|
|
89
|
+
response: ({ result }) => ({ id: result?.id ?? null }),
|
|
90
|
+
status: 201,
|
|
91
|
+
},
|
|
92
|
+
update: {
|
|
93
|
+
commandId: 'shipment_tracking.tracking_job.pause',
|
|
94
|
+
schema: rawBodySchema,
|
|
95
|
+
mapInput: async ({ raw, ctx }) => {
|
|
96
|
+
const { translate } = await resolveTranslations()
|
|
97
|
+
const scoped = withScopedPayload(raw ?? {}, ctx, translate)
|
|
98
|
+
return trackingJobUpdateSchema.parse(scoped)
|
|
99
|
+
},
|
|
100
|
+
response: ({ result }) => ({ id: result?.id ?? null }),
|
|
101
|
+
status: 200,
|
|
102
|
+
},
|
|
103
|
+
delete: {
|
|
104
|
+
commandId: 'shipment_tracking.tracking_job.deactivate',
|
|
105
|
+
schema: rawBodySchema,
|
|
106
|
+
mapInput: async ({ raw, ctx }) => {
|
|
107
|
+
const { translate } = await resolveTranslations()
|
|
108
|
+
const scoped = withScopedPayload(raw ?? {}, ctx, translate)
|
|
109
|
+
const id = (raw as any)?.body?.id ?? (raw as any)?.query?.id
|
|
110
|
+
return { id, ...scoped }
|
|
111
|
+
},
|
|
112
|
+
response: ({ result }) => ({ id: result?.id ?? null }),
|
|
113
|
+
status: 200,
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
export const openApi = createShipmentTrackingCrudOpenApi({
|
|
119
|
+
resourceName: 'TrackingJob',
|
|
120
|
+
pluralName: 'TrackingJobs',
|
|
121
|
+
querySchema: trackingJobListSchema,
|
|
122
|
+
listResponseSchema: createPagedListResponseSchema(z.object({
|
|
123
|
+
id: z.string().uuid(),
|
|
124
|
+
carrierCode: z.string(),
|
|
125
|
+
referenceType: z.string(),
|
|
126
|
+
referenceValue: z.string(),
|
|
127
|
+
status: z.string(),
|
|
128
|
+
})),
|
|
129
|
+
create: {
|
|
130
|
+
schema: rawBodySchema,
|
|
131
|
+
description: 'Creates a new tracking job. The system will auto-discover containers from carrier events.',
|
|
132
|
+
},
|
|
133
|
+
update: {
|
|
134
|
+
schema: rawBodySchema,
|
|
135
|
+
responseSchema: defaultOkResponseSchema,
|
|
136
|
+
description: 'Pauses a tracking job.',
|
|
137
|
+
},
|
|
138
|
+
del: {
|
|
139
|
+
schema: z.object({ id: z.string().uuid() }),
|
|
140
|
+
responseSchema: defaultOkResponseSchema,
|
|
141
|
+
description: 'Deactivates a tracking job.',
|
|
142
|
+
},
|
|
143
|
+
})
|
|
144
|
+
|
|
145
|
+
export const metadata = crud.metadata
|
|
146
|
+
export const GET = crud.GET
|
|
147
|
+
export const POST = crud.POST
|
|
148
|
+
export const PUT = crud.PUT
|
|
149
|
+
export const DELETE = crud.DELETE
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { NextRequest, NextResponse } from 'next/server'
|
|
2
|
+
import { z } from 'zod'
|
|
3
|
+
import { createRequestContainer } from '@open-mercato/shared/lib/di/container'
|
|
4
|
+
import { getAuthFromRequest } from '@open-mercato/shared/lib/auth/server'
|
|
5
|
+
import { resolveOrganizationScopeForRequest } from '@open-mercato/core/modules/directory/utils/organizationScope'
|
|
6
|
+
import type { CommandBus } from '@open-mercato/shared/lib/commands'
|
|
7
|
+
|
|
8
|
+
export const metadata = {
|
|
9
|
+
POST: { requireAuth: true, requireFeatures: ['shipment_tracking.tracking_jobs.manage'] },
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const syncSchema = z.object({
|
|
13
|
+
id: z.string().uuid(),
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
export const openApi = {
|
|
17
|
+
POST: {
|
|
18
|
+
operationId: 'triggerTrackingJobSync',
|
|
19
|
+
summary: 'Trigger sync for a tracking job',
|
|
20
|
+
description: 'Immediately polls the carrier for new events on the specified tracking job.',
|
|
21
|
+
tags: ['ShipmentTracking'],
|
|
22
|
+
requestBody: {
|
|
23
|
+
content: {
|
|
24
|
+
'application/json': {
|
|
25
|
+
schema: {
|
|
26
|
+
type: 'object',
|
|
27
|
+
required: ['id'],
|
|
28
|
+
properties: {
|
|
29
|
+
id: { type: 'string', format: 'uuid' },
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
responses: {
|
|
36
|
+
200: {
|
|
37
|
+
description: 'Sync result',
|
|
38
|
+
content: {
|
|
39
|
+
'application/json': {
|
|
40
|
+
schema: {
|
|
41
|
+
type: 'object',
|
|
42
|
+
properties: {
|
|
43
|
+
newEvents: { type: 'number' },
|
|
44
|
+
shipmentsCreated: { type: 'number' },
|
|
45
|
+
shipmentsUpdated: { type: 'number' },
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export async function POST(request: NextRequest) {
|
|
56
|
+
const auth = await getAuthFromRequest(request)
|
|
57
|
+
|
|
58
|
+
if (!auth || !auth.orgId || !auth.tenantId) {
|
|
59
|
+
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
let body: unknown
|
|
63
|
+
try {
|
|
64
|
+
body = await request.json()
|
|
65
|
+
} catch {
|
|
66
|
+
return NextResponse.json({ error: 'Invalid JSON body' }, { status: 400 })
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const parsed = syncSchema.safeParse(body)
|
|
70
|
+
if (!parsed.success) {
|
|
71
|
+
return NextResponse.json(
|
|
72
|
+
{ error: 'Invalid request', details: parsed.error.flatten() },
|
|
73
|
+
{ status: 400 },
|
|
74
|
+
)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const container = await createRequestContainer()
|
|
78
|
+
const scope = await resolveOrganizationScopeForRequest({ container, auth, request })
|
|
79
|
+
const commandBus = container.resolve('commandBus') as CommandBus
|
|
80
|
+
|
|
81
|
+
const selectedOrgId = scope?.selectedId ?? auth.orgId
|
|
82
|
+
const tenantId = auth.tenantId
|
|
83
|
+
|
|
84
|
+
try {
|
|
85
|
+
const { result } = await commandBus.execute<
|
|
86
|
+
{ jobId: string; tenantId: string; organizationId: string },
|
|
87
|
+
{ newEvents: number; shipmentsCreated: number; shipmentsUpdated: number }
|
|
88
|
+
>('shipment_tracking.tracking.poll_single', {
|
|
89
|
+
input: {
|
|
90
|
+
jobId: parsed.data.id,
|
|
91
|
+
tenantId,
|
|
92
|
+
organizationId: selectedOrgId,
|
|
93
|
+
},
|
|
94
|
+
ctx: {
|
|
95
|
+
container,
|
|
96
|
+
auth,
|
|
97
|
+
organizationScope: scope,
|
|
98
|
+
selectedOrganizationId: selectedOrgId ?? null,
|
|
99
|
+
organizationIds: scope?.filterIds ?? (selectedOrgId ? [selectedOrgId] : null),
|
|
100
|
+
request,
|
|
101
|
+
},
|
|
102
|
+
metadata: {
|
|
103
|
+
tenantId: tenantId ?? null,
|
|
104
|
+
organizationId: selectedOrgId ?? null,
|
|
105
|
+
resourceKind: 'shipment_tracking.tracking_job',
|
|
106
|
+
resourceId: parsed.data.id,
|
|
107
|
+
},
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
return NextResponse.json(result)
|
|
111
|
+
} catch (error) {
|
|
112
|
+
console.error('[tracking-jobs/sync] error:', error)
|
|
113
|
+
const message = error instanceof Error ? error.message : 'Failed to sync tracking job'
|
|
114
|
+
return NextResponse.json({ error: message }, { status: 400 })
|
|
115
|
+
}
|
|
116
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { createScopedApiHelpers } from '@open-mercato/shared/lib/api/scoped'
|
|
2
|
+
|
|
3
|
+
const { withScopedPayload, parseScopedCommandInput } = createScopedApiHelpers({
|
|
4
|
+
messages: {
|
|
5
|
+
tenantRequired: { key: 'shipment_tracking.errors.tenant_required', fallback: 'Tenant context is required' },
|
|
6
|
+
organizationRequired: { key: 'shipment_tracking.errors.organization_required', fallback: 'Organization context is required' },
|
|
7
|
+
},
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
export { withScopedPayload, parseScopedCommandInput }
|