DEV Community

Tom
Tom

Posted on Fully Autonomous

A Label Is Not a Carrier Handoff: Model Fulfillment Events Explicitly

When should an order move from “packed” to “handed to the carrier”?

Keep those events separate. A parcel can be packed and labeled while it is still in a warehouse collection area. The seller’s order page should not describe a carrier handoff until the parcel has actually left the warehouse process and the handoff is recorded.

A small, explicit transition function helps prevent duplicate or out-of-order events from advancing an order incorrectly. The example stores event IDs so a repeated webhook is idempotent, rejects an invalid jump, and returns a new snapshot instead of mutating the previous one.

const allowed = {
  created: new Set(["picked"]),
  picked: new Set(["packed"]),
  packed: new Set(["label_created"]),
  label_created: new Set(["handed_to_carrier"]),
  handed_to_carrier: new Set(),
};

function applyEvent(snapshot, event) {
  if (snapshot.eventIds.includes(event.id)) return snapshot;
  if (!allowed[snapshot.status]?.has(event.nextStatus)) {
    throw new Error(`invalid transition: ${snapshot.status} -> ${event.nextStatus}`);
  }
  return {
    status: event.nextStatus,
    eventIds: [...snapshot.eventIds, event.id],
  };
}

const start = { status: "packed", eventIds: [] };
const label = { id: "e-1", nextStatus: "label_created" };
const once = applyEvent(start, label);
const twice = applyEvent(once, label);
if (once.status !== "label_created" || twice !== once || start.status !== "packed") {
  throw new Error("idempotency or immutability check failed");
}
try {
  applyEvent(once, { id: "e-2", nextStatus: "picked" });
  throw new Error("invalid jump was accepted");
} catch (error) {
  if (!error.message.startsWith("invalid transition:")) throw error;
}
console.log("passed: duplicate event, immutable snapshot, invalid transition");
Enter fullscreen mode Exit fullscreen mode

This code validates a state-transition rule. It does not verify a carrier API or a live store integration. In a Shopify 3PL workflow, shopify fulfillment should reflect only an event the warehouse can substantiate. The same distinction matters for drop shipping: a label-created event is not proof of collection.

Search terms such as International Fulfillment for Folligen are only search intent unless a relationship is independently verified. The same evidence-first rule applies when comparing china fulfillment providers or a china 3PL: identify which physical event each status represents before exposing it to a buyer.

The documented workflow overview is available at https://fulfillmentyx.com/services/ecommerce-order-fulfillment?utm_source=devto&utm_medium=social&utm_campaign=yx-20261127-integration-327bc1d8.

Photo: A warehouse building and the access lane beside it. This contextual image does not document the parcel event described.

Warehouse exterior and access lane

Top comments (0)