Collections

Orders and Events

Orders collection, event stream, and lifecycle operations.

Orders collection

Path

tenants/{tenantId}/locations/{locationId}/orders/{orderId}

Operations

  • createOrder(input, locationId?)
  • getOrder(orderId, locationId?)
  • listOrders(locationId?, options?)
  • subscribeOrders(listener, options?, locationId?)
  • updateOrderStatus(input)

createOrder

Writes an order document and a created event in a transaction.

Returns:

  • { orderId, eventId }
const { orderId, eventId } = await client.createOrder({
  source: "delivery",
  channel: "wolt",
  totals: { subtotal: 12, tax: 2.88, discounts: 0, total: 14.88 },
  items: [{ productId: "latte", nameSnapshot: "Latte", qty: 1, unitPriceSnapshot: 12 }],
  idempotencyKey: "ord-100-create",
})

updateOrderStatus

Validates transition rules, updates status + statusUpdatedAt, and appends a status_changed event.

Returns:

  • { eventId }
await client.updateOrderStatus({
  orderId: "ord_100",
  toStatus: "in_prep",
  payload: { station: "kitchen_2" },
  idempotencyKey: "ord-100-in_prep",
})

Order events collection

Path

tenants/{tenantId}/locations/{locationId}/orders/{orderId}/events/{eventId}

Operations

  • createOrder(...) (writes created event)
  • updateOrderStatus(...) (writes status_changed event)
  • appendOrderEvent(orderId, event, locationId?) (writes custom event)
await client.appendOrderEvent("ord_100", {
  type: "driver_assigned",
  payload: { driverId: "drv_7" },
  idempotencyKey: "ord-100-driver-assigned",
})

Idempotency

For retry-safe writes, pass idempotencyKey in:

  • createOrder
  • updateOrderStatus
  • appendOrderEvent

When provided, the key is used to derive a stable event ID.

Read and stream examples

const order = await client.getOrder("ord_100")

const recentOpenOrders = await client.listOrders(undefined, {
  where: [{ fieldPath: "status", op: "==", value: "new" }],
  orderBy: [{ fieldPath: "createdAt", direction: "desc" }],
  limit: 20,
})

const unsubscribe = client.subscribeOrders((docs) => {
  console.log("live orders:", docs.length)
})

// later
unsubscribe()
Copyright © 2026