# Building Sessions apps — the guide for agents > Sessions apps put your UI inside Sessions — the booking and management platform for fitness, sport and wellness businesses. An app is a set of extensions; each extension renders into named places ("targets") in the staff admin and on the buyer-facing session sheet (including a business’s embedded schedule on its own website). Extensions are JavaScript modules that run in a sandboxed Web Worker, render with a small set of `sessions-*` elements that Sessions draws with its own design system, read data through a *live query*, write through `api.mutate`, and never hold a credential. This document is complete on its own: follow it and you can build, type-check, push and publish an app. It is generated from the same sources as the human docs at https://go.sessions.website/build/apps. Canonical URL: https://go.sessions.website/build/apps/llms.txt. Extension API version: `2026-09`. Human docs, page by page: - Overview — https://go.sessions.website/build/apps - CLI (layout, config files, commands, types, translations, icon, CI) — https://go.sessions.website/build/apps/cli - Targets — https://go.sessions.website/build/apps/targets - Components (one page per element) — https://go.sessions.website/build/apps/components - Extension API (live queries, mutations, metadata, localization, schema) — https://go.sessions.website/build/apps/api - Preact & React (hooks, signals, one model per extension) — https://go.sessions.website/build/apps/frameworks - Tutorial: build the Music app step by step — https://go.sessions.website/build/apps/tutorial ## Quick start ```bash mkdir my-app && cd my-app npm init -y npm install --save-dev github:SessionsCode/Sessions#sessions-apps/v0.1.0 preact # write sessions.app.json, extensions//sessions.extension.json and a module per target npx sessions login # opens the browser once; stores a developer token npx sessions types # validate .graphql files, write *.graphql.d.ts npx sessions build # type + bundle every target into .sessions/build/ npx sessions push --publish # upload a new version and make it live ``` Then, in Sessions: the business’s Settings → Apps → Install app → your app’s handle. Open any session to see it. ## Concepts - **App** — a container you own, named by a global, permanent `handle` (lowercase letters, digits, hyphens), with a name, description and icon. A business installs an app. `private` apps are installable only by their owner into businesses they are staff of; `default` apps (Sessions’ own) render for every business with no install. - **Extension** — one feature of an app (a directory under `extensions/`). It declares the targets it renders into, and ships its GraphQL documents and translations. - **Target** — a named place in the Sessions UI. Each target gets its own **module** (a file whose default export renders it) and optionally a **live query**. Names are DNS-style: `...`. The surface is `business` (staff admin) or `public` (buyers). The slot is `block` (a card of your own) or `row` (rows inside a list the page already draws, no card). - **Version** — every `sessions push` makes a new, immutable version of each extension (modules, live queries, translations). `sessions publish` (or `push --publish`) makes the latest the one businesses run. Pushing never changes what businesses see until you publish. - **Live query** — a GraphQL query you ship with a target. Sessions stores it with the version, runs it for you (as the viewer, beside the target’s subject) before your module renders, and runs it again as the data changes — after every `api.mutate` and whenever the page refreshes its own data. The module reads the result as `api.query`, a signal. It never fetches. - **Sandbox** — modules run in a Web Worker with a remote DOM. They never touch the host page and never see cookies or tokens; `api` is the only way out — `fetch`, `XMLHttpRequest` and `WebSocket` are blocked by the sandbox, and `import()` only reaches Sessions-hosted extension modules. Anything that is not an `sessions-*` element is ignored. There is no styling API: the host picks colours, spacing and fonts. ## Install `@sessions/apps` One development dependency: the extension API and types, the `sessions-*` elements, `@sessions/apps/preact`, `@sessions/apps/react`, and the `sessions` CLI (Node 22.18+). It is published privately as git tags of the `SessionsCode/Sessions` repository — install an exact tag with git credentials that can clone it (SSH key, or `gh auth setup-git`). There are no semver ranges; upgrading is changing the tag. ```bash npm install --save-dev github:SessionsCode/Sessions#sessions-apps/v0.1.0 preact # or: pnpm add -D github:SessionsCode/Sessions#sessions-apps/v0.1.0 preact # React instead: npm install --save-dev github:SessionsCode/Sessions#sessions-apps/v0.1.0 react react-dom ``` `preact`, `react` and `react-dom` are optional peer dependencies; install only the framework you use (a DOM-only app needs neither). Prefer Preact: every bundle is downloaded by the people who see it. ## Project layout ```text my-app/ ├── package.json ├── tsconfig.json ├── .gitignore # node_modules, .sessions, *.graphql.d.ts ├── sessions.app.json ├── assets/icon.png # square, ≥512×512, ≤5 MB (PNG, JPEG or WebP) └── extensions/ └── / ├── sessions.extension.json ├── SessionThingQuery.graphql # the live query (named by "query") ├── SaveThingMutation.graphql # a mutation, imported by a business module ├── *.graphql.d.ts # generated by `sessions types`; git-ignored ├── business.tsx # module for business.session.details.block ├── public.tsx # module for public.session.detail-list.row └── translations/ ├── en.json # the fallback language — always ship it ├── fr.json └── es.json ``` `tsconfig.json` is for type-checking only (the CLI bundles with esbuild): `"moduleResolution": "Bundler"`, `"strict": true`, `"noEmit": true`, `"allowImportingTsExtensions": true`, `"allowArbitraryExtensions": true` (so TypeScript reads `*.graphql.d.ts`), and for Preact `"jsx": "react-jsx", "jsxImportSource": "preact"`. Exclude `.sessions`. ### `sessions.app.json` - `handle` (required) — global and permanent; the first push creates the app under it. Handles that already exist belong to their owner (`sessions-music` is Sessions’). - `name` (required, up to 40 characters), `description` (up to 140) — what businesses see in their Apps settings. - `icon` — path to a square PNG/JPEG/WebP, relative to the app root. `sessions push` uploads it when the file changed since the last upload from this project (hash in `.sessions/state.json`). Draw it edge to edge; Sessions rounds the corners. - `extensions` — globs of extension directories; default `["extensions/*"]`. ### `sessions.extension.json` - `handle` (required, unique in the app), `name` (required, up to 40 characters; heads the extension’s card), `description` (up to 80 — one line under the name; say what it does, not how). - `targets` (required) — an array of `{ "target": "", "module": "./file.tsx", "query": "./SomeQuery.graphql" }`. `query` is optional. Give every target its own module: each is bundled separately, so buyers never download staff code. ## Targets ### `business.session.details.block` A block of your UI on the staff-facing page for one session, where a business manages who is coming and how the session runs. - Surface: `business` · Slot: `block` · API type: `BusinessSessionDetailsBlockApi` - Subject: The `Session` the page is for. - Viewer: Always a member of the business’s staff — the host refuses an extension API request for this target from anyone else. - Writes: yes — `setMetadata`, `deleteMetadata` - Docs: https://go.sessions.website/build/apps/targets/business.session.details.block Where it renders: - At the foot of the staff session page, after the built-in sections. - At the foot of the activity overview for a single-date activity, which stands in for its one session. - Sessions’ default apps render first, then installed apps in install order — each extension in its own card, headed by the app’s icon, the extension’s name and “From ”. - The card’s “…” menu opens the app’s page in the business’s settings (`/settings/apps/`); for admins it can also hide the extension for the business, or uninstall the app. A hidden extension stops rendering on the next page load. Adds to the standard `api`: - `api.session`: `{readonly id: string}` — The session this block renders beside. `id` is a `Session` global id — the same session the `session` root of the extension API resolves to. - `api.mutate(operation, options?)`: `(operation: string, options?: {variables?}) => Promise<{data: Data | null; errors?}>` — Runs a mutation on the extension API as the signed-in staff member, attributed to your extension. `api.query` re-resolves afterwards on its own. Guidance: - Lead with the state the staff member came to see, then the controls to change it. - Write under your app’s metadata namespace, `app..…`; a buyer-facing target of the same extension can read it back. - Report the outcome of a mutation with `api.ui.toast` — the block is not a page and has no room for a success banner. ### `public.session.detail-list.row` Rows of your own in the list of facts on the buyer-facing detail sheet for one session — on the business’s public page and in its embedded schedule on its own website. - Surface: `public` · Slot: `row` · API type: `PublicSessionDetailListRowApi` - Subject: The `Session` the sheet is showing. - Viewer: Anyone: a signed-in customer or an anonymous visitor (`viewer` is null in the extension API). - Writes: no — read-only, `api.mutate` does not exist - Docs: https://go.sessions.website/build/apps/targets/public.session.detail-list.row Where it renders: - In the session sheet’s “See more” sheet, as a group of rows after the session’s detail list (price, time, location, …), drawn exactly like the rows around it — no card, no heading. The sheet’s face offers a “See more” row after the location that names your app, so a buyer knows what is there. - In the same place on the `` and `` embeds on a business’s own website. - Render `` elements. While your extension starts, the host holds one placeholder row in your place, so the sheet doesn’t grow when your row arrives; render `` yourself only for a wait of your own after that. Render nothing when you have nothing to say: the placeholder folds smoothly away. Adds to the standard `api`: - `api.session`: `{readonly id: string}` — The session this block renders beside. `id` is a `Session` global id — the same session the `session` root of the extension API resolves to. Guidance: - Read-only: the API has no `mutate`, and the extension API refuses mutations for this target. - Buyers see this on a phone first — one row per fact, with a short title and at most a one-line subtitle. - This module ships to every buyer who opens the sheet, so keep it separate from your staff-facing module and keep it small. ## The `api` object A module’s default export is `extension(target, render)`. In the DOM flavour `render(root, api)` receives a remote-DOM `root` to append `sessions-*` elements to; in Preact/React `render(api)` returns JSX. Naming the target types `api` exactly — `api.mutate` exists only on `business.*` targets. Every target’s `api` has: - `api.target`: `UIExtensionTarget` — The target this module is rendering into — the literal name, so it narrows the rest of the API. - `api.version`: `'2026-09'` — The extension API version the host speaks. - `api.app`: `{id: string; handle: string; name: string}` — The app this extension belongs to. - `api.extension`: `{id: string; handle: string; name: string}` — This extension. - `api.localization.locale`: `ReadonlySignal` — The viewer’s BCP 47 locale (`en`, `fr-CA`). A signal: it changes when the viewer switches language without a reload, so read `.value` or `.subscribe` to it. - `api.localization.translate(key, replacements?)`: `(key: string, replacements?: Record) => string` — One of your own strings, from the `translations/.json` files pushed with the extension, in the viewer’s locale. `key` is a dot path; `{{name}}` placeholders are filled from `replacements`; a plural object is chosen by `replacements.count`. Falls back to the language, then `en`, then the key itself. - `api.localization.formatNumber / formatDate / formatCurrency`: `(value, options?) => string` — `Intl` formatting in the viewer’s locale: `formatNumber(value, options?)`, `formatDate(value, options?)` (a `Date`, an ISO string or epoch milliseconds; pass `timeZone` for the business’s wall-clock time), and `formatCurrency(amount, currency)` with `amount` in major units. - `api.query`: `ReadonlySignal` — The result of the target’s live query — the GraphQL query you ship with the target, which Sessions stores, runs for you, and runs again as the data changes (after every `api.mutate`, and whenever the host page refreshes its own data). A signal: read `.value` while rendering to re-render with it. `{}` when the target declares no query. - `api.ui.toast(message, options?)`: `(message: string, options?: {tone?: 'critical'}) => void` — Shows a toast on the host page, in the host’s own style. ## Live queries 1. Write the query in a `.graphql` file in the extension directory, e.g. `SessionNoteQuery.graphql` with `query SessionNote { … }`. 2. Name it with `"query": "./SessionNoteQuery.graphql"` beside the target in `sessions.extension.json`. Several targets may share one. 3. `sessions types` (also run by `build`/`push`) validates it against the extension API and writes `SessionNoteQuery.graphql.d.ts` exporting `SessionNoteQueryData`. 4. Read it: Preact/React `const {session} = useQuery()`; DOM `api.query.value` / `api.query.subscribe(render)`. Rules: the query runs as the viewer, beside the target’s subject — `session` resolves to the session the target renders beside (it is nullable in the types; use `session?.`). It re-runs after every `api.mutate` (whose promise resolves once it has, so clearing a draft on success is safe) and when the host page refreshes, so never copy it into your own state — derive from it. A target without a query gets `{}`. ## Mutations and GraphQL documents Business targets only. Put each mutation in its own `.graphql` file and import it from the module that runs it; the build validates it (errors stop the build with `file:line:column`) and refuses a mutation that ends up in a `public.*` target’s bundle. ```tsx import saveNote from './SaveNoteMutation.graphql'; const result = await api.mutate(saveNote, { variables: {owner: {id: api.session.id}, value: note}, }); // Two kinds of failure — check both. A failed mutation resolves; it does not throw. const message = result.errors?.[0]?.message ?? result.data?.setMetadata.errors[0]?.message; // In a form's submit handler, throw: the host shows the message and the form stays dirty. if (message) throw new Error(message); // Don't update local state from the result: the live query re-runs on its own. ``` ## Saving: let the host draw the Save Never draw your own Save button under an editor. Put the fields in a `
`, set `dirty` while they hold changes the viewer has not saved, and save in `onSubmit`. The host draws the Save where it belongs: on a staff page, the page’s own Save in its header (in the bottom bar on a phone), which saves every dirty form on the page — yours and other apps’ — with one press; on a surface with no page Save, a compact Save at your form’s foot. It stays loading until your handler’s promise settles. To report a failure, throw an `Error` whose message the viewer can read; the host shows it and the form stays dirty. When the save lands, clear your draft so `dirty` turns off. Success needs no toast of yours: the host confirms it. ```tsx const draft = useSignal(null); // null: showing what is saved async function save() { const result = await api.mutate(saveNote, {variables: {owner, value: draft.value}}); const message = result.errors?.[0]?.message; if (message) throw new Error(message); draft.value = null; } return ( (draft.value = value)} /> ); ``` A one-press action that is not an edit — connect, remove, send — is still a ` Open playlist ``` Docs: https://go.sessions.website/build/apps/components/section ### Typography #### `` · `` A heading at the level the surrounding section implies. Renders a heading one level below the block it sits in, so an extension never breaks the page outline. Prefer `sessions-section` with a `heading` attribute for a titled group. ```tsx What to bring ``` Docs: https://go.sessions.website/build/apps/components/heading #### `` · `` Inline text. Body text. Use `emphasis` and `tone` rather than styling; the host picks colours that pass contrast on every brand. Attributes (component props are the camelCase names): - `emphasis` — Weight and prominence. One of `subdued`, `strong`. - `tone` — A semantic colour. One of `critical`. - `size` — Text size. One of `small`, `base`. ```tsx Bring a mat and water. ``` Docs: https://go.sessions.website/build/apps/components/text #### `` · `` An inline text link. A link inside a sentence. Absolute URLs open in a new tab; a Sessions path navigates in place. Attributes (component props are the camelCase names): - `to` (required) — The destination: an `https:`, `http:`, `mailto:` or `tel:` URL, or a Sessions path. Any other scheme renders a link to nowhere. ```tsx See the house rules. ``` Docs: https://go.sessions.website/build/apps/components/link ### Actions #### `` · ` ``` Docs: https://go.sessions.website/build/apps/components/button #### `` · `` A callout with a heading and a body. For a status the reader should notice: an outage, a success, a warning. Keep the body to a sentence. Attributes (component props are the camelCase names): - `heading` (required) — The bold leading label. - `tone` — The banner tone. One of `info`, `positive`, `critical`, `celebration`. ```tsx Buyers see it on the session sheet. ``` Docs: https://go.sessions.website/build/apps/components/banner #### `` · `` A small status label. A compact tag beside a title or in a row. Attributes (component props are the camelCase names): - `tone` — The badge tone. One of `accent`, `highlight`, `positive`, `attention`, `info`, `celebration`, `caution`. ```tsx Connected ``` Docs: https://go.sessions.website/build/apps/components/badge #### `` · `` An image with an accessible description. Pass intrinsic `width` and `height` (or an `aspect-ratio`) so the host reserves space before the image loads. Attributes (component props are the camelCase names): - `src` (required) — The image URL. - `alt` (required) — The accessible description. - `width` — Intrinsic width in pixels. - `height` — Intrinsic height in pixels. - `aspect-ratio` — A forced aspect ratio, e.g. `1.5`. - `fit` — How the image fills its box. One of `cover`, `contain`. - `muted` (boolean) — Grayscale and dimmed — a logo for something not connected yet. Removing it animates the image back to full colour. ```tsx Album cover ``` Docs: https://go.sessions.website/build/apps/components/image #### `` · `` A Spotify, Apple Music or YouTube player in a sandboxed frame. Frames a player — a playlist, a video — sandboxed, with autoplay and encrypted media allowed. Only these origins are framed: `https://open.spotify.com`, `https://embed.music.apple.com`, `https://www.youtube.com` and `https://www.youtube-nocookie.com`. Any other URL or scheme renders nothing (and logs a warning in development), because the frame sits inside a staff or signed-in buyer page. It grows open and fades in when `src` is set and collapses when `src` is removed, so keep the element mounted and change `src`. Attributes (component props are the camelCase names): - `src` — The player URL to frame, on one of the allowed origins. - `height` — The frame height in CSS pixels. Default `320`. - `title` — An accessible name for the frame. ```tsx ``` Docs: https://go.sessions.website/build/apps/components/embed #### `` · `` Stacks `sessions-disclosure` rows with dividers between them. Wrap a set of disclosures — one per service, one per option — so they read as one list. ```tsx … … ``` Docs: https://go.sessions.website/build/apps/components/disclosure-group #### `` · `` A row that expands to reveal its children. Keep the `open` attribute in your own state and toggle it in the `toggle` handler. A `media` child (a small `sessions-image`) leads the row; an `accessory` child (an `sessions-switch`) sits at its end, in place of the expand chevron. Attributes (component props are the camelCase names): - `title` (required) — The row title. - `subtitle` — A secondary line under the title. - `open` (boolean) — Whether the content is revealed. Events (`on` props receive the detail): - `toggle` — The header was pressed. Detail: undefined. Slots: - `slot="media"` — A logo or icon at the start of the row, drawn at 24px. - `slot="accessory"` — A control at the end of the row, operated independently of the toggle. ```tsx model.toggle('spotify')} > Spotify model.connect(on)} /> 1. Opener · 2. Deep cut · 3. Encore ``` Docs: https://go.sessions.website/build/apps/components/disclosure ### Forms #### `` · `` A single-line (or multiline) text input. Controlled by you: set `value`, listen for `input` (every keystroke) or `change` (the committed value), and set `error` to show a validation message under it. Attributes (component props are the camelCase names): - `label` — The field label. - `label-visibility` — `hidden` keeps the label for screen readers but draws none. One of `visible`, `hidden`. - `value` — The current value. - `placeholder` — Hint text when empty. - `type` — The HTML input type. One of `text`, `email`, `url`, `number`, `tel`. - `help-text` — Guidance under the field. - `error` — A validation message; the field turns critical. - `disabled` (boolean) — Non-interactive. - `multiline` (boolean) — A textarea instead of an input. - `select-on-paste` (boolean) — Selects the whole value after a paste, so a wrong link is one keystroke from replaced. Events (`on` props receive the detail): - `input` — Every keystroke. Detail: string — the new value. - `change` — The committed value. Detail: string — the new value. - `focus` — The field gained focus. Detail: undefined. - `blur` — The field lost focus. Detail: undefined. Slots: - `slot="accessory"` — Inside the field at its end — a small `sessions-button`, such as a Save that appears once the value changes. ```tsx model.setDraft(value)} /> ``` Docs: https://go.sessions.website/build/apps/components/text-field #### `` · `
` Fields saved together, with the host’s Save. Set `dirty` while the form holds changes the viewer has not saved, and the host offers a Save for it: on a staff page, the page’s own Save — in its header, or the bottom bar on a phone — which saves every dirty form on the page at once; anywhere else, a compact Save at the form’s foot. Draw no Save of your own. The Save stays loading until the `submit` handler’s promise settles. To report a failure, throw an `Error` with a message the viewer can read: the host shows it and the form stays dirty. Clear `dirty` once the save lands. Enter in a single-line field also submits; a form with no `dirty` can still carry its own `sessions-button type="submit"` (a field’s accessory, say). Attributes (component props are the camelCase names): - `dirty` (boolean) — The form holds unsaved changes: the host shows a Save for it until it is cleared. Events (`on` props receive the detail): - `submit` — The form was submitted. Return a promise to keep the Save loading; throw to report a failure. Detail: undefined. ```tsx model.save()}> model.setDraft(value)} /> ``` Docs: https://go.sessions.website/build/apps/components/form #### `` · ` setService(value)}> ``` Docs: https://go.sessions.website/build/apps/components/select #### `` · ` ``` Docs: https://go.sessions.website/build/apps/components/option #### `` · `` An on/off toggle with a label. Controlled: keep `checked` in your state and flip it in the `change` handler. Attributes (component props are the camelCase names): - `label` — The switch label. - `checked` (boolean) — On. - `help-text` — A line under the label. - `disabled` (boolean) — Non-interactive. Events (`on` props receive the detail): - `change` — The switch was flipped. Detail: boolean — the new state. ```tsx (visible.value = checked)} /> ``` Docs: https://go.sessions.website/build/apps/components/switch ### Rows #### `` · `` One row in a list of facts — what a `*.row` target renders. Drawn exactly like the rows around it (price, time, location on the session sheet). The text is the title; an `icon` child leads it. With an `https:` `href` the row opens it in a new tab and ends with an outbound arrow. Outside a row target it renders as a plain line. Attributes (component props are the camelCase names): - `subtitle` — A subdued line under the title. - `subtitle-lines` — How many lines the subtitle may wrap to. One of `1`, `2`. - `href` — An `https:` URL the row opens in a new tab. Slots: - `slot="icon"` — A small `sessions-image` at the start of the row, drawn at 18px. ```tsx Morning flow ``` Docs: https://go.sessions.website/build/apps/components/detail-row #### `` · `` A detail row while its title loads. Print what you already know — the icon, the subtitle — and shimmer only the title, so the row does not move when it resolves. Attributes (component props are the camelCase names): - `subtitle` — A subdued line under the title. - `title-width` — The placeholder title’s width, e.g. `42%`. - `subtitle-width` — With no `subtitle`, a placeholder subtitle of this width. Slots: - `slot="icon"` — A small `sessions-image` at the start of the row. ```tsx ``` Docs: https://go.sessions.website/build/apps/components/detail-row-skeleton ### Loading #### `` · `` A text placeholder while data loads. Render the shape of what is coming, in the same box, then replace it — never a spinner. Attributes (component props are the camelCase names): - `lines` — How many lines. - `width` — A CSS width for the line(s). ```tsx ``` Docs: https://go.sessions.website/build/apps/components/skeleton-text #### `` · `` A heading placeholder while data loads. Pairs with `sessions-skeleton-text` for a section that is still resolving. Attributes (component props are the camelCase names): - `width` — A CSS width. ```tsx ``` Docs: https://go.sessions.website/build/apps/components/skeleton-heading ## Preact & React Both entries export the same API: `extension`, every component, and the hooks `useApi()`, `useQuery()`, `useTranslate()`, `useLocale()`, `useModel(create, deps?)`, `useSignal`, `useComputed`, `useSignalEffect`, `useSignalValue`, plus the signal primitives `signal`, `computed`, `effect`, `batch`, `untracked` (from `@preact/signals-core` — import them from `@sessions/apps/preact` or `/react`, never a second copy) and the `Api` type. - **Signals.** In Preact, reading `signal.value` while rendering subscribes the component. In React it does not: read with `useSignalValue(signal)` (have a model expose one `computed` of everything the view needs). - **One model per extension.** Keep state and actions in one class made once with `useModel((api: MyApi) => new MyModel(api))`, where `type MyApi = Api<'business.session.details.block', MyQueryData>`. Private signals hold state; getters read them (so components subscribe to what they read); methods change state (in `batch` when several change) and call `api.mutate`. Derive saved data from `api.query` with `computed` — never copy it. An optional `start({signal})` method runs after mount; stop work when `signal` aborts. This mirrors how Sessions’ own pages keep a model per page. - React DOM needs a few browser shims in the sandbox; `@sessions/apps/react` installs them. Inline styles are ignored. ## CLI - `sessions login` — authorize this machine in the browser (the page is `/build/cli/authorize`); stores a developer token in `~/.sessions/credentials.json`. - `sessions logout` — revoke and forget the token. `sessions whoami` — who is signed in. - `sessions types` — validate every `.graphql` document and write `*.graphql.d.ts`. - `sessions build` — types, then bundle every target into `.sessions/build//.js`. - `sessions push` — build; create the app and new extensions if needed; upload the icon if it changed; upload a new draft version of each extension (modules, live queries, translations). `--publish` publishes too. - `sessions publish` — make the latest pushed version of every extension live. - CI: set `SESSIONS_ACCESS_TOKEN` to a developer token (mint one with `sessions login`, copy it from `~/.sessions/credentials.json`) and run `npx sessions push --publish`. `SESSIONS_API_URL` overrides the origin (default `https://go.sessions.website`). ## What businesses control - Install / uninstall a private app from Settings → Apps (`/settings/apps`); each app has a page at `/settings/apps/` with its icon, description, extensions and targets. - A `*.block` target’s card is headed by the app icon, the extension name and “From ”, with a “…” menu: View app, and for admins Hide and Uninstall . Hidden extensions stop rendering on the next page load. Default apps can be hidden, not uninstalled. - A `*.row` target has no chrome: render ``s (and `` while loading) or nothing. ## Rules and pitfalls - One module per target; never put staff-only logic behind a runtime check in a `public.*` module (every buyer downloads it). - Public targets are read-only and the viewer may be anonymous (`viewer` is null). - Write and read metadata only under `app..` (other names read as null). `setMetadata` refuses an empty value — call `deleteMetadata` to clear a field. - Render nothing (return `null`, or leave `root` empty) when there is nothing to show — especially in row targets, where the host’s placeholder row then folds away. - Never fetch, and never store a copy of the live query; derive from `api.query`. - Check both `result.errors` and the mutation’s own `errors` list; a failure resolves, it does not throw. In a form’s `submit` handler, throw an `Error` with the message; from a button, report with `api.ui.toast(message, {tone: 'critical'})`. - Never draw a Save (least of all a full-width one) under an editor: a `
` gets the host’s Save. See “Saving”. - Put every user-facing string in `translations/*.json` with `en.json` present; use placeholders and plural objects, not concatenation. - Only `sessions-*` elements render; no CSS, no classes, no inline styles. Use `emphasis`, `tone`, `size` and layout elements instead. - Use skeleton elements (`sessions-skeleton-text`, `sessions-detail-row-skeleton`) for loading states, not spinners. - `session` in a live query is nullable in the generated types — use optional chaining. - Run `sessions types` after editing any `.graphql` file, and git-ignore `*.graphql.d.ts` and `.sessions/`. - Pushing is safe; only publishing changes what businesses run. Versions are immutable. ## Extension API schema The complete schema live queries and mutations run against (`/@/api/graphql/extensions`; the host sends every request for you with `X-Sessions-Extension` and `X-Sessions-Extension-Subject` headers — never call it yourself). ```graphql """ The GraphQL API a UI extension talks to from inside its sandbox — through `api.query` (the extension's *live query*: a GraphQL query the developer ships with a target, which Sessions stores, runs for them, and re-runs as the data changes) and `api.mutate` (an ad-hoc mutation). It is deliberately small and *scoped*: every operation runs as one extension instance, for one business, and — when the target has one — beside one subject (a session). The host attributes the request to the extension, so an extension never handles a credential. Executed at `/@/api/graphql/extensions` on the business and public hosts. Distinct from the public and business HTTP APIs, which are documented separately. """ schema { query: Query mutation: Mutation } "An ISO 8601 date-time string, e.g. `2026-09-24T18:30:00.000Z`." scalar DateTime "An absolute `http(s)` URL." scalar URL "A reference to another node by its id." input EntityRef { id: ID! } type OperationError { "The argument that caused the error, or null for the operation as a whole." field: String message: String! } """ Where in the Sessions UI an extension renders, e.g. `business.session.details.block` or `public.session.detail-list.row` — the names an extension declares in `sessions.extension.json`. """ scalar UIExtensionTarget type Query { "The extension instance this operation runs as." extension: ExtensionContext! "The business the extension is rendering for." business: Business! """ The session the extension renders beside. Set for the `business.session.details.block` and `public.session.detail-list.row` targets; null for a target with no session subject. """ session: Session """ The person looking at the extension. Null for an anonymous visitor on a public target; always set on an admin target. """ viewer: Viewer } "Which extension is asking, and where it is rendering." type ExtensionContext { "The `UIExtensionInstance` id the host rendered." id: ID! target: UIExtensionTarget! "The extension API version the running module declared." apiVersion: String! app: App! extension: AppExtension! } type App { id: ID! handle: String! name: String! } type AppExtension { id: ID! handle: String! name: String! } type Business { id: ID! handle: String! name: String! "IANA timezone identifier the business schedules in, e.g. `America/Toronto`." timezone: String! "The business's public page." url: URL! } type Session { id: ID! startAt: DateTime endAt: DateTime isCancelled: Boolean! activity: Activity! """ One metadata field on the session, by its reverse-DNS name. Falls back to the activity's field of the same name when the session stores nothing under it, the way the buyer-facing surfaces read it. Null when neither does — and when the app may not read the name: - an app reads its own `app..…` names on every target; - a `default` (Sessions-owned) app also reads any name on a `business.*` target, and Sessions' public names (`website.sessions.…` and the well-known `sessions.…` fields) on a `public.*` target. A legacy `sessions.website.…` name reads the `website.sessions.…` row. """ metadata(name: String!): MetadataField """ The music playlist attached to the session, resolved from Sessions' own `website.sessions..playlist.id` metadata (`spotify`, `apple-music`, `youtube`; the first that holds a usable value wins). Null when none does. Selecting `name` looks the playlist up on the streaming service (cached, best-effort). """ playlist: SessionPlaylist "The buyer-facing session page." url: URL! } type Activity { id: ID! name: String! "The activity type, e.g. `yoga`, `basketball`, `music.lesson`." type: String """ One metadata field on the activity, by its reverse-DNS name. Null when none is stored, or when the app may not read the name — the same rule as `Session.metadata`. """ metadata(name: String!): MetadataField } """ A metadata field stored on a resource under one reverse-DNS name. A scalar field has one value; a list field has several, in order. """ type MetadataField { name: String! "The first (for a scalar field, the only) stored value." value: String "Every stored value, in order." values: [String!]! } "The external music streaming service hosting a session playlist." enum SessionPlaylistService { spotify appleMusic youtube } "A music playlist a business attached to a session." type SessionPlaylist { service: SessionPlaylistService! "The playlist's public page on the streaming service." url: URL! """ The playlist's display name, looked up on the service. Null when it is private, deleted, or the lookup fails — fall back to a generic label. """ name: String } type Viewer { id: ID! name: String! "Whether the viewer is on the business's staff." isStaff: Boolean! } type Mutation { """ Store one scalar metadata value on the session or activity the extension renders beside. An app may only write names under its own namespace, `app..…` — a `default` (Sessions-owned) app may write any name. Requires a staff viewer. """ setMetadata( owner: EntityRef! name: String! value: String! ): SetMetadataResult! """ Remove a metadata value the extension's app owns. Same namespace rule as `setMetadata`. Requires a staff viewer. """ deleteMetadata(owner: EntityRef!, name: String!): DeleteMetadataResult! } type SetMetadataResult { value: String errors: [OperationError!]! } type DeleteMetadataResult { deleted: Boolean! errors: [OperationError!]! } ``` ## Complete example: the Music app Sessions’ own Music app, verbatim (it is a `default` app, so it writes `website.sessions.*` names — a private app would use `app..*`). A staff picker (`business.session.details.block`) built on a signal-backed model, and a buyer row (`public.session.detail-list.row`). `services.ts` (not shown) lists the three services with each one’s `metadataName`, logo, embed URL and link parser. Walkthrough: https://go.sessions.website/build/apps/tutorial. ### sessions.app.json ```json { "handle": "sessions-music", "name": "Music", "description": "A playlist for every session, for your staff and the people who book.", "icon": "./assets/icon.png", "extensions": ["extensions/*"] } ``` ### extensions/playlist/sessions.extension.json ```json { "handle": "playlist", "name": "Playlist", "description": "Share a playlist with your customers.", "targets": [ { "target": "business.session.details.block", "module": "./business.tsx", "query": "./SessionPlaylistQuery.graphql" }, { "target": "public.session.detail-list.row", "module": "./public.tsx", "query": "./SessionPlaylistQuery.graphql" } ] } ``` ### extensions/playlist/SessionPlaylistQuery.graphql ```graphql # The live query both targets read. Sessions stores it with the extension, # runs it for the session each target renders beside, and runs it again when # the data changes — after every `api.mutate`, for one. # # Music is Sessions' own `default` app, so it keeps the reverse-DNS names # Sessions itself reads (`website.sessions.*`). A private app would use its # own `app..*` names instead. query SessionPlaylist { session { id spotify: metadata(name: "website.sessions.spotify.playlist.id") { value } appleMusic: metadata(name: "website.sessions.apple-music.playlist.id") { value } youtube: metadata(name: "website.sessions.youtube.playlist.id") { value } # The connected playlist, resolved: which service, its public URL, and # its name as the service reports it (null when the lookup fails). playlist { service url name } } } ``` ### extensions/playlist/SetPlaylistMutation.graphql ```graphql mutation SetPlaylist($owner: EntityRef!, $name: String!, $value: String!) { setMetadata(owner: $owner, name: $name, value: $value) { value errors { field message } } } ``` ### extensions/playlist/PlaylistModel.ts ```ts import { batch, computed, signal, type Api, type Signal, } from '@sessions/apps/preact'; import deletePlaylist from './DeletePlaylistMutation.graphql'; import setPlaylist from './SetPlaylistMutation.graphql'; import type {SessionPlaylistQueryData} from './SessionPlaylistQuery.graphql'; import { SERVICES, samePlaylist, type Service, type ServiceKey, } from './services.ts'; export type MusicApi = Api< 'business.session.details.block', SessionPlaylistQueryData >; /** * Everything the staff picker knows and does, made once per render from the * extension's API (see `useModel` in `business.tsx`). State lives in * signals; components read the getters while rendering and re-render when * they change. The saved playlist is never copied: it is read from the live * query, which Sessions re-runs after every mutation. */ export class PlaylistModel { readonly #api: MusicApi; readonly #drafts: Record> = { spotify: signal(''), appleMusic: signal(''), youtube: signal(''), }; readonly #expanded = signal(null); readonly #previewId = signal(null); readonly #running = signal(0); /** The id saved for each service, from the live query. */ readonly #saved = computed(() => { const session = this.#api.query.value.session; return { spotify: session?.spotify?.value ?? null, appleMusic: session?.appleMusic?.value ?? null, youtube: session?.youtube?.value ?? null, } satisfies Record; }); constructor(api: MusicApi) { this.#api = api; const saved = this.#saved.peek(); const connected = SERVICES.find((service) => saved[service.key]); batch(() => { for (const service of SERVICES) { const id = saved[service.key]; this.#drafts[service.key].value = id ? service.playlistUrl(id) : ''; } this.#expanded.value = connected?.key ?? null; this.#previewId.value = connected ? saved[connected.key] : null; }); } // #region Reading saved(key: ServiceKey): string | null { return this.#saved.value[key]; } /** * The saved playlist's name as its service reports it, from the live * query's resolved `session.playlist`; null until it is saved, or when the * service does not say (a private playlist, a failed lookup). */ savedName(key: ServiceKey): string | null { const playlist = this.#api.query.value.session?.playlist; return playlist?.service === key ? (playlist.name ?? null) : null; } /** The service with a saved playlist; the picker keeps at most one. */ get connected(): ServiceKey | null { return SERVICES.find((service) => this.saved(service.key))?.key ?? null; } draft(key: ServiceKey): string { return this.#drafts[key].value; } hasChanged(key: ServiceKey): boolean { const service = SERVICES.find((entry) => entry.key === key)!; return !samePlaylist(service, this.draft(key), this.saved(key) ?? ''); } get expanded(): ServiceKey | null { return this.#expanded.value; } /** The playlist being previewed in the open service's embed. */ get previewId(): string | null { return this.#previewId.value; } get isSaving(): boolean { return this.#running.value > 0; } // #endregion // #region Editing setDraft(key: ServiceKey, value: string) { this.#drafts[key].value = value; } setExpanded(key: ServiceKey | null) { this.#expanded.value = key; } /** Preview whatever the field holds, once the person leaves it. */ previewDraft(service: Service) { const id = service.parseId(this.draft(service.key)); this.#previewId.value = id || null; } // #endregion // #region Saving /** Saves the field's playlist, or removes it when the field is empty. */ async save(service: Service) { const id = service.parseId(this.draft(service.key)); if (id) { // The field keeps showing a link people recognise — the playlist's // own page — while the session stores just the id. batch(() => { this.#drafts[service.key].value = service.playlistUrl(id); this.#previewId.value = id; }); await this.#mutate(() => this.#api.mutate(setPlaylist, { variables: { owner: this.#owner, name: service.metadataName, value: id, }, }), ); } else { this.#previewId.value = null; await this.#remove(service); } } /** Switching a service on turns the connected one off. */ async select(service: Service) { const connected = this.connected; if (connected != null && connected !== service.key) { const previous = SERVICES.find((entry) => entry.key === connected)!; this.#clear(previous.key); await this.#remove(previous); } this.#expanded.value = service.key; } async deselect(service: Service) { this.#clear(service.key); await this.#remove(service); this.#expanded.value = null; } #clear(key: ServiceKey) { batch(() => { this.#drafts[key].value = ''; this.#previewId.value = null; }); } #remove(service: Service) { return this.#mutate(() => this.#api.mutate(deletePlaylist, { variables: {owner: this.#owner, name: service.metadataName}, }), ); } get #owner() { return {id: this.#api.session.id}; } /** * Runs one mutation, keeping `isSaving` up while it does, and says so in a * toast when it fails — a failed save resolves like any other. */ async #mutate( run: () => Promise<{ data?: unknown; errors?: readonly {readonly message: string}[]; }>, ) { this.#running.value += 1; try { const result = await run(); const payload = Object.values( (result.data ?? {}) as Record< string, {errors?: readonly {message: string}[]} | null >, )[0]; const message = result.errors?.[0]?.message ?? payload?.errors?.[0]?.message; if (message) this.#api.ui.toast(message, {tone: 'critical'}); } finally { this.#running.value -= 1; } } // #endregion } ``` ### extensions/playlist/business.tsx ```tsx import { extension, useModel, useTranslate, Button, Disclosure, DisclosureGroup, Embed, Form, Image, Stack, Switch, TextField, } from '@sessions/apps/preact'; import {PlaylistModel, type MusicApi} from './PlaylistModel.ts'; import {SERVICES, type Service} from './services.ts'; /** * The staff side: one row per service, each with a switch. Turning a service * on opens it to paste a playlist link, saves it on the session, and previews * the playlist below; only one service is connected at a time. */ export default extension('business.session.details.block', () => ( )); function MusicPicker() { // One model for the extension, made once from its API. const model = useModel((api: MusicApi) => new PlaylistModel(api)); return ( {SERVICES.map((service) => ( ))} ); } function ServiceDisclosure({ model, service, }: { model: PlaylistModel; service: Service; }) { const translate = useTranslate(); const connected = model.saved(service.key) != null; const name = connected ? model.savedName(service.key) : null; const open = model.expanded === service.key; const previewId = open ? model.previewId : null; return ( { if (open) model.setExpanded(null); else void model.select(service); }} > {service.name} { if (checked) void model.select(service); else void model.deselect(service); }} /> model.save(service)}> model.setDraft(service.key, value)} onBlur={() => model.previewDraft(service)} > {model.hasChanged(service.key) ? ( ) : null} ); } ``` ### extensions/playlist/public.tsx ```tsx import { extension, useQuery, useTranslate, DetailRow, Image, } from '@sessions/apps/preact'; import type {SessionPlaylistQueryData} from './SessionPlaylistQuery.graphql'; import {serviceFor} from './services.ts'; /** * The buyer side: one row in the session sheet's details — the playlist's * name, the service under it, and a link out. Renders nothing (so the row * isn't there) when the session has no playlist. */ export default extension('public.session.detail-list.row', () => ( )); function PlaylistRow() { const {session} = useQuery(); const translate = useTranslate(); const playlist = session?.playlist; const service = playlist ? serviceFor(playlist.service) : null; if (playlist == null || service == null) return null; return ( {playlist.name ?? translate('playlist')} ); } ``` ### extensions/playlist/translations/en.json ```json { "status": { "connected": "Connected", "connectedTo": "Connected · {{name}}", "notConnected": "Not connected", "pasteToConnect": "Paste a link to connect" }, "link": { "label": "Playlist URL or ID", "placeholder": "Paste a {{service}} playlist link…" }, "save": "Save", "saving": "Saving…", "playlist": "Playlist" } ```