Reference
Order Lifecycle
Order status transitions and idempotent event writes.
Status transitions
Allowed transitions:
new -> acceptedaccepted -> in_prepin_prep -> readyready -> completednew | accepted | in_prep | ready -> cancelled
Terminal states:
completedcancelled
Validate transitions
Use canTransitionOrderStatus before mutation if your UI needs local guards.
import { canTransitionOrderStatus } from "@frappes/firebase"
const allowed = canTransitionOrderStatus("accepted", "in_prep") // true
Update status
await client.updateOrderStatus({
orderId: "ord_123",
toStatus: "ready",
idempotencyKey: "ord_123-ready-v1",
payload: { station: "kitchen_2" },
})
updateOrderStatus will:
- read current order in a transaction
- reject invalid transitions
- update status and
statusUpdatedAt - append a
status_changedevent
Custom events
await client.appendOrderEvent("ord_123", {
type: "driver_assigned",
payload: { driverId: "drv_77" },
idempotencyKey: "ord_123-driver_assigned-v1",
})
If you pass idempotencyKey, the event ID is derived from it (sanitized for Firestore-safe IDs).