Skip to main content

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​

PiecePath
Shipmentsrc/modules/operations/shipment
Tracking featuresrc/modules/operations/shipment-tracking
Courier mastersrc/modules/operations/courier
NDR listenerndr-shipment.listener.ts
Schema43-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.

JobQueueTrigger
poll-shipment-trackingshipment_tracking_queueCron 0 */3 * * *
refresh-shipment-trackingsameShipmentController

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​

  1. Shipment consignment: If shipment has positive dimensions (lengthMm > 0 && breadthMm > 0 && heightMm > 0), these represent the packed parcel and take immediate precedence (dimensionSource: 'ORDER').
  2. Order dimensions: If the order header carries dimensions (order.lengthMm > 0 ...), they are used (dimensionSource: 'ORDER').
  3. 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').
  4. Tenant default package setting: If neither parcel, order, nor single product provide dimensions, falls back to TenantSetting.packageLengthMm, packageBreadthMm, and packageHeightMm (dimensionSource: 'TENANT_SETTING').
  5. Validation gate: If dimensions cannot be resolved from any of the above sources, resolveStrictShipmentSpecs throws BadRequestException('shipment.error.dimensionsRequired'). (The read-only variant resolveShipmentSpecsSafely returns null).

Weight Priority Waterfall​

  1. 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').
  2. Order weight: If order.weightGrams > 0, it is used as the estimated order weight (weightSource: 'ORDER').
  3. 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 selects max(catalogDeadWeight, volumetricWeight) to protect against carrier under-declaration penalties (PRODUCT_MASTER if dead weight is higher, else VOLUMETRIC).
  4. 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 (or PUT /v1/operations/shipments/:id). This updates the Shipment record directly (weightGrams, lengthMm, breadthMm, heightMm).
  • Query enrichment: FulfillmentQueryService.getById enriches the response with packageSpecs resolved 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​

  1. Warehouse Courier Mappings (WarehouseCourierLocation): Pickup and facility identifiers are strictly warehouse-centric. A courier account does not store pickup nicknames in its general configuration.
  2. Forward vs. Reverse Eligibility:
    • Outbound forward dispatches check that the assigned courier mapping has supportsForward: true.
    • Return / reverse pickups pass isReturn: true to CourierAllocationService, verifying both courier.supportsReverse: true and whMapping.supportsReverse: true.
  3. Strict Booking Enforcement: When calling ship(), all courier strategies query WarehouseCourierLocation.findUnique({ courierId_warehouseId: { courierId, warehouseId } }). If unconfigured, the operation fails fast with 400 Bad Request directing 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.