Shipping
Overview
Shipments, tracking scans, non-delivery reports, freight audit, and claims. Carrier HTTP clients live under src/integrations, not in the courier master-data module.
Code map
| Piece | Path |
|---|---|
| Shipment | src/modules/operations/shipment |
| Tracking feature | src/modules/operations/shipment-tracking |
| Courier master | src/modules/operations/courier |
| NDR listener | ndr-shipment.listener.ts |
| Schema | 43-shipment.prisma |
Entities: Shipment, ShipmentItem, ShipmentTracking, ShipmentNdrEvent, ShipmentFreightAudit, ShipmentClaim, Courier, WarehouseCourierLocation.
Strategies found
integrationCode values with a strategy class: SHP, SHPINTL, DLH, BLD, BLDINTL, FDX, DTDC, SHWY, STP, PTR, ITL.
Seed codes with no strategy class found: NIP, PIK, SHYP, ARMX, AMZ. Whether they are placeholders is unknown.
Events and queues
shipment.status.changed is an outbox event. Consumers: fulfillment, NDR, return shipment. See Events.
| Job | Queue | Trigger |
|---|---|---|
poll-shipment-tracking | shipment_tracking_queue | Cron 0 */3 * * * |
refresh-shipment-tracking | same | ShipmentController |
Courier webhooks (Shiprocket, Shipway, iThink, and others that call WebhookQueue) enter webhook_queue.
ShipmentExceptionScheduler ticks every minute. Its body was not fully read.
Business rules
Package Dimension & Weight Resolution
Shipment booking, courier rate comparison, and fulfillment drafts require canonical parcel measurements. Dimension and weight resolution is centralized in resolveStrictShipmentSpecs and follows a strict, column-first priority waterfall:
Dimensions Priority Waterfall
- Shipment consignment: If
shipmenthas positive dimensions (lengthMm > 0 && breadthMm > 0 && heightMm > 0), these represent the packed parcel and take immediate precedence (dimensionSource: 'ORDER'). - Order dimensions: If the order header carries dimensions (
order.lengthMm > 0 ...), they are used (dimensionSource: 'ORDER'). - Single-product catalog master: If the order consists of a single line item with quantity 1 and the product has catalog dimensions (
product.lengthMm > 0 ...), they are applied (dimensionSource: 'PRODUCT_MASTER'). - Tenant default package setting: If neither parcel, order, nor single product provide dimensions, falls back to
TenantSetting.packageLengthMm,packageBreadthMm, andpackageHeightMm(dimensionSource: 'TENANT_SETTING'). - Validation gate: If dimensions cannot be resolved from any of the above sources,
resolveStrictShipmentSpecsthrowsBadRequestException('shipment.error.dimensionsRequired'). (The read-only variantresolveShipmentSpecsSafelyreturnsnull).
Weight Priority Waterfall
- Shipment weight: If
shipment.weightGrams > 0(e.g., weighed by operator or saved in draft), it is used as the physical package weight (weightSource: 'ORDER'). - Order weight: If
order.weightGrams > 0, it is used as the estimated order weight (weightSource: 'ORDER'). - Catalog dead weight vs. volumetric: If catalog products carry weights, aggregate dead weight is computed as
sum(quantity * product.weightGrams). Volumetric weight is calculated using standard divisor formula(L_mm * B_mm * H_mm) / 5000. If dead weight is present, the resolver selectsmax(catalogDeadWeight, volumetricWeight)to protect against carrier under-declaration penalties (PRODUCT_MASTERif dead weight is higher, elseVOLUMETRIC). - Volumetric weight: If no actual or catalog dead weight exists, the resolved dimensions derive volumetric weight (
weightSource: 'VOLUMETRIC').
Package Draft & Update Flow
- Unit selection: In the admin order and shipping forms, weight and dimension values are interpreted in the selected units. Switching the unit selector keeps the entered number; it does not convert it. Enter a new number when changing units. The API stores canonical grams and millimetres after submission.
- Updating dimensions: Warehouse bench operators edit package weight or dimensions via
PUT /v1/operations/fulfillment-orders/batch/dimensions(orPUT /v1/operations/shipments/:id). This updates theShipmentrecord directly (weightGrams,lengthMm,breadthMm,heightMm). - Query enrichment:
FulfillmentQueryService.getByIdenriches the response withpackageSpecsresolved from the active forward shipment, ensuring draft edits are preserved and do not revert to initial order estimates upon page refresh.
Courier Allocation & Warehouse Facility Resolution
- Warehouse Courier Mappings (
WarehouseCourierLocation): Pickup and facility identifiers are strictly warehouse-centric. A courier account does not store pickup nicknames in its general configuration. - Forward vs. Reverse Eligibility:
- Outbound forward dispatches check that the assigned courier mapping has
supportsForward: true. - Return / reverse pickups pass
isReturn: truetoCourierAllocationService, verifying bothcourier.supportsReverse: trueandwhMapping.supportsReverse: true.
- Outbound forward dispatches check that the assigned courier mapping has
- Strict Booking Enforcement: When calling
ship(), all courier strategies queryWarehouseCourierLocation.findUnique({ courierId_warehouseId: { courierId, warehouseId } }). If unconfigured, the operation fails fast with400 Bad Requestdirecting the user to configure the location in Warehouse Couriers settings. There is no fallback to arbitrary global configs.
NDR Event Handling
NDR writes NdrEventType rows inside a transaction, triggered from shipment.status.changed.
Unknown: whether a webhook and the 3-hour poller can apply the same scan twice. Deduping would depend on a tracking-event unique key. That key was not verified.
Failure scenarios
Carrier calls are partial-failure heavy. See Couriers and Labels.
API surface
Shipment and NDR controllers, plus per-carrier ship/cancel/track routes. OpenAPI for fields.