@stateset/embedded 1.35.1 to explore stock availability in a fresh in-memory
database. This example needs no API key or external service. Every stock change has an
assertion, so a successful run verifies the behavior as well as showing the calls.
Prerequisites
Use Node.js 20.20.0+ and npm 10+. In a new directory:Run the complete example
Save this asinventory-demo.mjs:
Understand the quantities
The returned quantities are strings.
initialQuantity, the reservation quantity, and the
adjustment delta are numbers in this version of the Node API.
A rejected hold leaves the existing stock unchanged. Releasing the first reservation restores
availability. Confirming the second keeps its two units allocated: confirmation does not
ship goods, decrement on-hand stock, or release the hold. The final adjustment records one
damaged unit; it is a separate inventory correction.
Choose who owns the reservation
This example creates manual checkout holds. In the orders quickstart, order creation withstockPolicy: 'reject_if_insufficient' already reserves the order’s units.
Do not add another manual hold for those same units without an explicit handoff strategy.
reserve takes positional arguments: SKU, quantity, reference type, reference ID, and an
optional lifetime in seconds. Here, 300 gives the pending hold an expiration timestamp five
minutes after creation. A reference ID links a hold to your workflow; this example does not
establish it as an idempotency key. Save the returned reservation ID before later operations.
For expiration handling and method signatures, see the
inventory lifecycle reference.
Troubleshooting
Next steps
- Manufacturing: record production batches and inspect stock separately.
- Warehouse receiving: record partial inbound quantities and verify the separate inventory boundary.
- Order reservations and cancellation: let the order workflow manage its own stock holds.
- Inventory lifecycle: check method signatures and integration boundaries.
- Persisted embedded quickstart: inspect records from a second process.