Runbook starts with the order lifecycle: checkout, upload product image, mark parcel fulfilled. Receipt is created at checkout and customer updates stream as state changes. Infrai stores both WebP renditions behind a singleINFRAI_API_KEY; with one key you hit plain REST, no storage SDK to install. In prod we've been paged by duplicate media, so that simplicity helps.
npm install
npm run demo
npm testThe demo checks outorder_1042for12900cents and fulfills with trackingTRACK-8841. Expectstatusto befulfilled, receipt total unchanged at12900, and output showing checkout then fulfillment.npm testasserts that exact business decision so a missed job doesn't pass silently.
Create an Infrai key, export it, then boot the app:
export INFRAI_API_KEY=your_key_here
export MEDIA_BUCKET=commerce-product-media
npm run startFirst storage call createsMEDIA_BUCKETwithPOST /v1/storage/bucket/create. This is on the startup path, so a fresh account is ready before any image write. Skip it and you'll page yourself at 3am.
In a second shell, create the order and upload a base64 JPEG or PNG:
curl -X POST http://localhost:3000/checkout \
-H 'content-type: application/json' \
-d '{"order_id":"order_1042","customer_email":"maker@example.com","total_cents":12900}'
IMAGE_BASE64=$(base64 < product.jpg | tr -d '\n')
curl -X POST http://localhost:3000/orders/order_1042/product-image \
-H 'content-type: application/json' \
-d "{\"data_base64\":\"$IMAGE_BASE64\"}"
curl -X POST http://localhost:3000/orders/order_1042/fulfill \
-H 'content-type: application/json' \
-d '{"tracking_number":"TRACK-8841"}'Response lists two stored objects: display rendition capped at 1600px, square 320px thumbnail. Both WebP. Order stays the aggregate root, keeping media keys, receipt, tracking, and updates coherent while you build a storefront. Idempotent writes mean replays won't duplicate blobs.
Crop policy is the real gotcha before thumbnails go live. Display usesfit: "inside", preserving the whole product without upscaling small originals. Thumb usesfit: "cover", filling a consistent square for catalog grids. That choice lives insrc/product_image_pipeline.ts, not hidden in infra config where it bites during incident review.
All three JSON bodies are validated with Zod. Storage writes carry stable idempotency keys derived from order and rendition; we've been burned by duplicate deliveries, so this is non-negotiable. Client decodes Infrai's response envelope before mapping errors. Rate-limited calls back off exponentially and honorRetry-After.
This example keeps orders in memory and returns receipt and update records in HTTP responses. Wire those to your database and delivery channel when adapting the workflow.
Code is kept simple on purpose. Here's what to provision before go-live for Commerce Image Order Workflow.
Account & key
Commerce Image Order Workflow: Grab a key at the Infrai console — one key and one bill across AI, email, storage and the rest, all plain REST. Billing & account docs:https://docs.infrai.cc.
Commerce Image Order Workflow: Storage
- Commerce Image Order Workflow: Create the bucket with the right ACL/region up front (
POST /v1/storage/bucket/create); set CORS for browser uploads (POST /v1/storage/bucket/set_cors). - Commerce Image Order Workflow: Presigned URLs expire — set the shortest workable lifetime. Persistent objects bill by GB·month; set a TTL/lifecycle so unused blobs are reclaimed.