Recipes

Short, working starting points. Each says when to use it, shows the least code that works, and links to the reference. They all use one small chat app: a tenant with the schema from the first recipe.

october is plain GraphQL over HTTP, with a bearer token for the user. So you can call it from a page in the browser, from your own server or a script, and from an AI agent. Pick the recipe that matches where your code runs.

Start from zero#

When: you have no account and no tenant yet.

First choose your tenant's name: lower case, like acme-chat (letters, digits and dashes, starting with a letter, at most 25 characters). The server makes the tenant's slug, its name in every URL, from the name and a short random ending, like acme-chat-k3f9q, so your name never collides with anyone else's. october init prints the slug. Every recipe here writes it as <slug>: put yours in its place.

  1. Make your account in the browser at october.sombra.so/sign-in: an email address and a six-digit code. It is free. The CLI logs in to this account; it doesn't make one.

  2. Install the CLI (it needs Node.js 22 or newer) and log in:

    Lang
    Text
    npm i -g @october1/cli
    october login

    It opens your browser at a link with a code (or prints them): check the code and approve the login. october logout logs out again. (Or run any command without installing: npx -y @october1/cli login.)

  3. Write schema.edn:

    Lang
    EDN
    {:entities
     {:messages
      {:attrs       {:text {:type :string :min 1 :max 2000 :trim? true}}
       :order       [:created-at :desc]
       :permissions {:view   true
                     :create [(authenticated? ?user)]
                     :update [(created-by ?e ?user)]
                     :delete [(created-by ?e ?user)]}}}}
  4. Create the tenant, by name. It prints the tenant's slug: use it from here on. --demo hands sign-in codes back in the response, so you can test without email. Turn it off (october demo <slug> off) before real people use the app.

    Lang
    Text
    october init <name> --demo
  5. Change the schema later: edit the file, then check, plan and push.

    Lang
    Text
    october check
    october plan <slug>
    october push <slug> --yes

The API is now at https://october.sombra.so/t/<slug>/graphql, and its GraphQL schema at https://october.sombra.so/t/<slug>/schema.graphql.

Reference: the guide, cli.md, schema.md.

A page in the browser#

When: a static page (no build step) that signs a user in, shows data live and writes. The page's origin must be allowed first:

Lang
Text
october origins <slug> --add http://localhost:5173
Lang
HTML
<ul id="messages"></ul>
<form id="send"><input name="text" required> <button>Send</button></form>

<script type="module">
  import { init } from "https://october.sombra.so/october-client.js";

  const db = init({ url: "https://october.sombra.so", tenant: "<slug>" });

  // sign in by email code (the client keeps the session in localStorage)
  if (!db.auth.signedIn) {
    const email = prompt("Your email");
    const { demoCode } = await db.auth.sendMagicCode({ email });
    const code = demoCode ?? prompt("The code from your email");   // demoCode: demo mode only
    await db.auth.signInWithMagicCode({ email, code });
  }

  // read, live: the first result, then a new one on every change
  db.subscribe(`{ messages(first: 50) { items { id text } } }`, {}, ({ data, errors }) => {
    if (errors || !data) return console.warn(errors);
    document.querySelector("#messages").replaceChildren(
      ...data.messages.items.map((m) => Object.assign(document.createElement("li"), { textContent: m.text })));
  });

  // write: retried safely, never twice
  document.querySelector("#send").onsubmit = async (e) => {
    e.preventDefault();
    await db.mutate(`mutation ($input: MessageCreateInput!) { createMessage(input: $input) { id } }`,
      { input: { text: e.target.text.value } });
    e.target.reset();
  };
</script>

With a bundler, npm install @october1/client and import from "@october1/client" instead.

Reference: client.md, api.md.

React#

When: a React app. The client's React entry point adds two hooks: useQuery (live) and useAuth.

Lang
Text
npm install @october1/client react
Lang
JSX
import { init } from "@october1/client/react";

const db = init({ url: "https://october.sombra.so", tenant: "<slug>" });
const MESSAGES = `{ messages(first: 50) { items { id text } } }`;
const SEND = `mutation ($input: MessageCreateInput!) { createMessage(input: $input) { id } }`;

export function Chat() {
  const { isLoading, error, data } = db.useQuery(MESSAGES);   // re-renders on every change
  const { user } = db.useAuth();
  if (isLoading) return <p>Loading…</p>;
  if (error) return <p>{error.message}</p>;
  return (
    <>
      <ul>{data.messages.items.map((m) => <li key={m.id}>{m.text}</li>)}</ul>
      {user && <button onClick={() => db.mutate(SEND, { input: { text: "Hi" } })}>Say hi</button>}
    </>
  );
}

Sign-in is the same as on a page: db.auth.sendMagicCode and db.auth.signInWithMagicCode.

Reference: client.md.

Your own server (Node)#

When: your app has a server (Express, Hono, a Next.js route, a serverless function) that reads or writes october as part of handling a request.

The server acts as the signed-in user. The browser keeps the user's session and sends its access token with each call to your server; the server passes that token on to october, so october applies the user's permissions. With no token, the server reads what anonymous callers may see. A server never keeps one user's token for other requests.

In the browser, send the token only when there is one (signed out, getToken() is null, and a Bearer null header would be refused):

Lang
JavaScript
// db is the page's client (see the recipes above)
const token = await db.auth.getToken();
await fetch("/api/messages", {
  method: "POST",
  headers: { "Content-Type": "application/json", ...(token ? { Authorization: "Bearer " + token } : {}) },
  body: JSON.stringify({ text: "Hello from the page" }),
});

On the server, plain fetch is enough. This is a Next.js route handler (app/api/messages/route.js); the same code works in Hono, Remix and other runtimes with Request and Response:

Lang
JavaScript
const OCTOBER = "https://october.sombra.so/t/<slug>/graphql";

/** Runs a GraphQL request as the caller whose Authorization header it passes on (none: anonymous). */
async function gql(authorization, query, variables) {
  const res = await fetch(OCTOBER, {
    method: "POST",
    headers: { "Content-Type": "application/json", ...(authorization ? { Authorization: authorization } : {}) },
    body: JSON.stringify({ query, variables }),
  });
  if (res.status === 401) return { status: 401, error: "UNAUTHENTICATED" };   // the token expired or the session ended
  if (!res.ok) return { status: 502, error: "october answered " + res.status };   // 429 or 503 (with Retry-After), a proxy error, ...
  const { data, errors } = await res.json();
  if (errors?.some((e) => e.extensions?.code === "UNAUTHENTICATED")) return { status: 401, error: "UNAUTHENTICATED" };   // needs a signed-in user
  if (errors) return { status: 400, errors };
  return { status: 200, data };
}

export async function POST(request) {
  const { text } = await request.json();
  // your server's own work goes here: checks, calls to other services, ...
  const { status, data, ...error } = await gql(
    request.headers.get("authorization"),   // "Bearer <the user's access token>", or null
    "mutation ($input: MessageCreateInput!) { createMessage(input: $input) { id text } }",
    { input: { text } });
  return status === 200 ? Response.json(data.createMessage) : Response.json(error, { status });
}
  • A GraphQL answer is HTTP 200 even when it has errors: read them. A token that has expired or ended is an HTTP 401.
  • The server doesn't refresh the user's token. It passes the 401 back, and the page's client gets a fresh token and calls again.
  • To retry a write safely, send an Idempotency-Key header, and the same key on the retry.
  • @october1/client works in Node too, and retries for you. On a server, make one client per request, never a signed-in client at module level: client.md shows how, for Express and Next.js.

Reference: client.md, api-sign-in.md, api-mutations.md.

A script that acts on its own#

When: a script, a cron job or a worker that reads or writes without a user in front of it.

october has no service tokens yet. A script signs in as an app user of its own, with an email code, and that user's permissions apply. Give it only the access it needs, for example with a role (october roles).

The first sign-in needs a person: run the script once in a terminal and type the code emailed to the script's address (in demo mode the code comes back in the response). The session is then kept in a file, and later runs, from cron too, reuse it until it ends: 30 days after that sign-in at most, or sooner if it is signed out. Then run the script by hand again.

Lang
JavaScript
// node script.mjs   (Node 20 or later; npm install @october1/client)
import { init } from "@october1/client";
import { readFileSync, writeFileSync, rmSync } from "node:fs";
import { createInterface } from "node:readline/promises";

const FILE = ".october-session.json";   // keep it secret, like a password
const storage = {
  getItem: () => { try { return readFileSync(FILE, "utf8"); } catch { return null; } },
  setItem: (_key, value) => writeFileSync(FILE, value, { mode: 0o600 }),
  removeItem: () => rmSync(FILE, { force: true }),
};
const db = init({ url: "https://october.sombra.so", tenant: "<slug>", storage });

if (!db.auth.signedIn) {
  if (!process.stdin.isTTY) throw new Error("Not signed in: run this script once in a terminal");
  const email = "reports@example.com";
  const { demoCode } = await db.auth.sendMagicCode({ email });
  let code = demoCode;   // demo mode only; otherwise the code is emailed
  if (!code) {
    const rl = createInterface({ input: process.stdin, output: process.stdout });
    code = await rl.question("The code from your email: ");
    rl.close();
  }
  await db.auth.signInWithMagicCode({ email, code });
}

await db.mutate(`mutation ($input: MessageCreateInput!) { createMessage(input: $input) { id } }`,
  { input: { text: "Nightly report: all good" } });
const { messages } = await db.query(`{ messages(first: 5) { items { text } } }`);
console.log(messages.items);

The client refreshes the session's tokens as it goes and writes each new pair to the file. When the session has ended, the client signs out, and the file is removed.

Reference: client.md, api-sign-in.md.

curl#

When: you want to try the API by hand, or call it from a language without a client. Reads and writes are a JSON POST to /graphql.

Read, as an anonymous caller:

Lang
Text
curl -s https://october.sombra.so/t/<slug>/graphql -H 'Content-Type: application/json' \
  -d '{"query": "{ messages(first: 5) { items { id text createdAt } } }"}'

Sign in. The first call emails a code (in demo mode it answers the code as demo_code); the second answers access_token, which lasts 15 minutes:

Lang
Text
curl -s https://october.sombra.so/t/<slug>/runtime/auth/send_magic_code \
  -H 'Content-Type: application/json' -d '{"email": "you@example.com"}'
curl -s https://october.sombra.so/t/<slug>/runtime/auth/verify_magic_code \
  -H 'Content-Type: application/json' -d '{"email": "you@example.com", "code": "123456"}'

Write, as that user:

Lang
Text
curl -s https://october.sombra.so/t/<slug>/graphql -H 'Content-Type: application/json' \
  -H "Authorization: Bearer $ACCESS_TOKEN" -H "Idempotency-Key: $(uuidgen)" \
  -d '{"query": "mutation ($input: MessageCreateInput!) { createMessage(input: $input) { id text } }",
       "variables": {"input": {"text": "Hello from curl"}}}'

See everything the schema generated, with a GET:

Lang
Text
curl -s https://october.sombra.so/t/<slug>/schema.graphql

Reference: api.md, api-sign-in.md, api-mutations.md.

An AI agent (MCP)#

When: an agent (Claude Code, Cursor, any MCP client) should read and write the app's data. Every tenant is an MCP server at https://october.sombra.so/t/<slug>/mcp. The agent works as the user whose access token it carries, under the same rules as the GraphQL API.

Get an access token as in the curl recipe, then, in Claude Code:

Lang
Text
claude mcp add --transport http <slug> https://october.sombra.so/t/<slug>/mcp \
  --header "Authorization: Bearer <access token>"

An access token lasts 15 minutes; long-lived tokens for agents are not there yet.

To have an agent build the app itself, give it the setup prompt, or point it at https://october.sombra.so/llms.txt, which lists these docs as Markdown.

Reference: api-mcp.md.