Apps
Build an app whose extensions render inside Sessions — on the staff session page, in the list of facts on the buyer’s session sheet, and in a business’s embedded schedule — drawn by the Sessions design system, fed by a live query, and with no credentials to hold.
One package
Everything is in @sessions/apps, your one development dependency: the extension API and its types, the sessions-* elements, the Preact and React bindings, and the sessions command that signs you in, types your GraphQL, bundles, pushes and publishes.
For now it is published privately, as git tags of the Sessions repository: install an exact tag such as github:SessionsCode/Sessions#sessions-apps/v0.1.0. Anyone who can clone the repository can install it; upgrading is changing the tag.
Write extensions against the DOM, or as components with @sessions/apps/preact or @sessions/apps/react — add the framework beside it and nothing else.
# @sessions/apps is published as git tags of the Sessions repository.
# Pin an exact tag; anyone who can clone the repository can install it.
npm install --save-dev github:SessionsCode/Sessions#sessions-apps/v0.1.0 preact
npx sessions login{
"name": "studio-notes",
"private": true,
"type": "module",
"scripts": {
"types": "sessions types",
"build": "sessions build",
"push": "sessions push",
"publish:app": "sessions publish"
},
"devDependencies": {
"@sessions/apps": "github:SessionsCode/Sessions#sessions-apps/v0.1.0",
"preact": "^10.29.0"
}
}Apps, extensions, targets
An app is a container you own, named by a global handle, with a name, a description and an icon. It groups extensions and is what a business installs.
An extension is one feature of your app — a session note, a playlist picker. It declares the targets it renders into, and ships its own GraphQL documents and translations.
A target is a named place in the Sessions UI, like business.session.details.block. Each target gets its own module — a file whose default export renders it — and, optionally, a live query.
A business installs your app from its Apps settings, and every extension in it starts rendering for that business. Sessions’ own default apps render for every business with no install.
import {
extension,
useApi,
useQuery,
useSignal,
useTranslate,
Button,
Stack,
TextField,
} from '@sessions/apps/preact';
import saveNote from './SaveNoteMutation.graphql';
import type {SessionNoteQueryData} from './SessionNoteQuery.graphql';
export default extension('business.session.details.block', () => <NoteEditor />);
function NoteEditor() {
const api = useApi<'business.session.details.block'>();
const {session} = useQuery<SessionNoteQueryData>();
const translate = useTranslate();
// Signals: reading `.value` while rendering re-renders on change.
const draft = useSignal(session?.note?.value ?? '');
const saving = useSignal(false);
async function save() {
saving.value = true;
// Typed by the .graphql.d.ts: variables are checked, data is typed.
const result = await api.mutate(saveNote, {
variables: {owner: {id: api.session.id}, value: draft.value},
});
saving.value = false;
const failed = result.errors != null || !!result.data?.setMetadata.errors.length;
api.ui.toast(translate(failed ? 'saveFailed' : 'saved'), {
tone: failed ? 'critical' : undefined,
});
}
return (
<Stack gap="small">
<TextField
label={translate('label', {activity: session?.activity.name ?? ''})}
value={draft.value}
multiline
onInput={(value) => (draft.value = value)}
/>
<Button emphasis="strong" loading={saving.value} onClick={save}>
{translate('save')}
</Button>
</Stack>
);
}A target’s module
A module’s default export is a function of root and api. root is a remote DOM element — append sessions-* elements, or render Preact or React components — and the host draws them as real Sessions components. Wrap it in extension(target, …) to get the target’s exact api type.
On a business target, api.mutate(document, options) runs a mutation as the signed-in staff member, attributed to your extension. api.ui.toast(message) shows a toast in the host’s own style.
fetch, XMLHttpRequest and WebSocket are blocked, and import() reaches only Sessions-hosted extension modules.Live queries
A live query is a GraphQL query you ship with a target. Sessions stores it with each version, runs it for you — as the viewer, beside the target’s subject — before your module renders, and runs it again whenever the data changes: after every api.mutate, and whenever the page refreshes its own data.
Your module reads the result as api.query, a signal. It never fetches, never holds a token, and never goes stale — a component that reads it renders again when it changes.
Put the query in a .graphql file, name it with query in sessions.extension.json, and sessions types writes its TypeScript types beside it.
# The live query: Sessions stores it with the extension, runs it for the
# session each target renders beside, and runs it again when the data
# changes. The module reads the result as `api.query`.
query SessionNote {
session {
id
activity {
name
}
note: metadata(name: "app.studio-notes.note") {
value
}
}
}Your words, in every language
Sessions speaks English, French and Spanish, and your extension can too. Put a translations/<locale>.json file in the extension for each language; the CLI pushes them with every version, and api.localization.translate(key) picks the viewer’s.
The files work like Sessions’ own: nested keys read as dot paths, {{name}} placeholders, and plurals chosen by count. A missing string falls back to the language, then to English, then to its key.
{
"label": "Note for {{activity}}",
"save": "Save note",
"saved": "Note saved",
"saveFailed": "Couldn’t save the note",
"fromTheDesk": "From the front desk"
}Targets
Where an extension can render today. Each target has its own page with the API it gets.
What a business sees
An app belongs to the business that runs it: staff decide what renders on their pages.
InstallBlocks*.block target draws each extension in its own card, headed by your app’s icon, the extension’s name and “From <app>”. A *.row target draws your rows among the page’s own, with no card at all.Hide/settings/apps/<handle>), and lets an admin hide one extension for the business — from the menu or with a switch on that page. A hidden extension stops rendering on the next load.UninstallIcon"icon" in sessions.app.json names a square PNG, JPEG or WebP. sessions push uploads it when it changes, and it heads your cards and your app’s page.Ship it
The sessions command types your GraphQL, bundles each target into its own module, pushes a draft version with its live queries and translations, and publishes it when you say so. Every push is a new immutable version; publishing decides which one businesses run.
Reference
Everything an app can do, in the order you’ll need it.
sessions-* elements, one page each: what it’s for, its attributes, events and slots, and a preview.APILive queries, mutations, metadata, localization — and the scoped schema behind them.FrameworksPreact and React: the hooks, signals, and one model per extension.TutorialBuild the Music app from an empty folder, one step at a time.