Example tenant · examples/acme
Acme: an order sync, with a portal on top.
The first example most people read. A shop's orders go to an ERP every five minutes or the moment they're placed, large ones wait for approval, and customers follow their own orders in a portal.
How the tenant fits together
What's in it.
One TypeScript file and two small React apps. Short enough to read in a sitting, and it touches most of the platform.
| Part | What it does |
|---|---|
| Connections | The shop's order API, the ERP's import API, and a chat webhook for failures. Where each points is set per workspace |
| Order sync | Every five minutes, new orders go from the shop to the ERP, one sync at a time, with three retries |
| Order webhook | The moment the shop takes an order, it's sent to the ERP, checked against a shared secret first |
| Order flow | Two ways in, a check, and a branch: anything over 1,000 waits for approval. Every order is recorded with how it ended |
| Failure handler | A script started when any run fails for the last time: the place to open a ticket or page someone |
| Contact form | A form the platform serves. Messages are kept in a table and announced as an event |
| Portal | A React app where staff see every order and customers see and request their own |
| Public page | A React app anyone can open, showing the notices staff write |
| Invoices | A screen built from widgets, where finance sees every invoice and each customer their company's |
Two ways an order arrives, no way it arrives twice.
The sync runs on a schedule and the webhook runs the moment an order is placed, so the same order can reach the ERP both ways. Both send it with the same key, and the ERP ignores a key it has seen.
- That's what makes the retries safe: a second attempt is a no-op, not a duplicate.
concurrency: 1stops two syncs overlapping.- The batch size is a variable, so it can differ between dev and production.
export const receiveOrder = defineScript({
path: "orders/receive",
connections: [erp],
secrets: ["SHOP_WEBHOOK_SECRET"],
timeoutSeconds: 30,
retries: { limit: 2, delaySeconds: 5 },
async run(input, ctx) {
if (input.secret !== (await ctx.secret("SHOP_WEBHOOK_SECRET")))
throw new Error("The request did not carry the shared secret.");
const erpApi = await ctx.connection("erp");
await erpApi.post("/import/orders", input.order, {
headers: { "idempotency-key": `order-${input.order.id}` },
});
// …
},
}); Shortened from examples/acme. A shop that signs its requests could use the webhook's own signature check instead.
Public, customers, staff: one set of bindings.
Who may open what is written beside everything else. Staff need nothing extra, since their roles already let them read. Customers and the public are given exactly what they need.
- Customers open the portal and read the orders table, where each sees only the orders they own.
- Customers may start one script, the one that records an order they ask for, written as theirs.
- Anyone, signed in or not, may open the public page and read the notices, and nothing else.
defineBinding({ path: "access/customers-portal",
role: "portal_user", principal: { type: "end_users" }, resource: portal });
defineBinding({ path: "access/customers-orders",
role: "portal_user", principal: { type: "end_users" }, resource: orders });
defineBinding({ path: "access/customers-request",
role: orderRequester, principal: { type: "end_users" }, resource: requestOrder });
/** Binding to `anonymous` is what makes the page and the notices public. */
defineBinding({ path: "access/public-page",
role: publicReader, principal: { type: "anonymous" }, resource: publicPage });
defineBinding({ path: "access/public-notices",
role: publicReader, principal: { type: "anonymous" }, resource: notices }); A contact form with no script of its own.
The form is served by the platform. Its two steps are ready-made: one writes a row, one publishes an event. Each is handed the one table or event it works on, and reaches nothing else.
- Four fields, a select among them, a button label and a thank-you message.
- Sending the same page twice starts one run, and the form is limited per visitor.
- Mail would be one more ready-made step, handed an SMTP connection.
form: trigger.form({
title: "Get in touch",
fields: [
{ name: "name", label: "Your name", type: "text", required: true },
{ name: "email", label: "Email", type: "email" },
{ name: "about", type: "select", options: ["An order", "An invoice", "Something else"] },
{ name: "message", label: "Your message", type: "textarea", required: true },
],
success: "Thank you. Your message has reached us.",
}),
keep: step.script("core/table-write", { …, with: { tables: [messages] } }),
tell: step.script("core/publish-event", { …, with: { events: [messageReceived] } }), Deploy it in a minute.
The first deploy tells you which connections and secrets the workspace still needs. Bind them in the console, point them at sandboxes, and deploy again.
volvel buildlists everything the bundle holds before anything is uploaded.volvel runsshows the sync's runs as they happen.
$ volvel login --url http://localhost:8080 --token <api key>
$ cd examples/acme
$ volvel build
$ volvel deploy --tenant <slug> --workspace <slug>
$ volvel runs --tenant <slug> --workspace <slug> Related
Start with the example most people read first.
Acme is in the repository: one file of TypeScript and two small apps.