@stateset/embedded 1.35.1 Node binding. For a complete
program with setup and assertions, use the orders quickstart.
REST APIs and other language bindings have their own signatures.
Setup
:memory: for a disposable
example, or the same absolute file path across processes for persistent data.
Create an order with actual IDs
orders.createExact takes a customer ID and an items array. Each item needs a SKU, name,
quantity and decimal-string price. In this snippet, customer is the result of
commerce.customers.create or findOrCreate, and inventory for MUG-001 already exists:
id, status, items and totalAmountExact. New orders begin in
pending. Store the returned order ID rather than a sample identifier from documentation.
Stock reservations
Order creation reserves available inventory for its lines. Withreject_if_insufficient, an
order that cannot be fully reserved is rejected. The orders quickstart
checks ten units on hand → two allocated → eight available, then verifies that cancellation
releases the allocation.
reserve(sku, quantity, referenceType, referenceId, expiresInSeconds?).
State changes
For example, while
order is still pending:
ship takes a tracking-number string, not an object containing carrier settings. In a
real integration, pass the tracking number returned by your carrier workflow. The demonstration
string above only labels a local record.
In a check against version 1.35.1,
orders.ship changed the order to shipped while the
inventory allocation remained unchanged. Do not assume the status helper consumes a
reservation or implements the full warehouse fulfillment flow. Verify stock and shipment
records through the fulfillment integration you use.Cancellation and returns
The orders quickstart demonstratespending → confirmed →
cancelled and checks that the reserved stock becomes available again. State guards can
reject a cancellation based on the current order and payment state.
For shipped goods, follow the returns quickstart. A return refers
to the order’s line-item IDs and has its own approval, receipt and disposition process.
Reading state
list() takes no pagination options. A REST list endpoint can have a
different pagination contract; consult that endpoint instead of transferring its parameters
to the embedded method.
External effects
Track commerce records and external operations separately:- A local payment record does not prove that a payment provider captured funds.
- A tracking number stored on an order does not buy a shipping label.
- A shipped status does not prove warehouse stock was consumed.
- A return status does not prove a customer refund succeeded.
Related
- Orders quickstart — complete local reservation and cancellation example
- Embedded quickstart — persistence and exact-money setup
- Returns workflow — RMA methods and limits
- Inventory lifecycle — inventory concepts