Skip to main content
Use @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:
See SDK installation for native-module troubleshooting.

Run the complete example

Save this as inventory-demo.mjs:
Success: all assertions pass and you see:

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 with stockPolicy: '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

Last modified on September 20, 2026