Skip to Content
Config SystemConfiguration Reference

Configuration Reference

Complete reference for the foir.config.ts file format, all available interfaces, and helper functions.

ApplyConfigInput

The top-level config object passed to defineConfig. This is the shape of your entire config file.

interface ApplyConfigInput { key: string; // Unique identifier for this config name: string; // Display name configType?: string; // Config type identifier force?: boolean; // Force reinstall (delete and recreate) /** Base URL prepended to relative operation endpoints at push time. */ operationBaseUrl?: string; /** Project pin + declarative project-level settings. */ project?: ApplyConfigProjectInput; models?: ApplyConfigModelInput[]; // Content models operations?: ApplyConfigOperationInput[]; // Operation endpoints contextDimensions?: ApplyConfigContextDimensionInput[]; // Targeting axes locales?: ApplyConfigLocaleInput[]; // Project locales variantCatalog?: ApplyConfigVariantCatalogEntryInput[]; // Named targeting definitions schedules?: ApplyConfigScheduleInput[]; // Cron schedules hooks?: ApplyConfigHookInput[]; // Lifecycle hooks authProviders?: ApplyConfigAuthProviderInput[]; // Auth providers authClients?: ApplyConfigAuthClientInput[]; // the apps hosted sign-in signs people in to placements?: ApplyConfigPlacementInput[]; // Editor placements apiKeys?: ApplyConfigApiKeyInput[]; // API keys provisioned at push time userRoles?: ApplyConfigUserRoleInput[]; // User roles (what a signed-in user may do) /** The project's agents. See /ai/agents. */ agents?: ApplyConfigAgentInput[]; /** What every agent of the project is told first. See /ai/agents#the-project-brief. */ brief?: ApplyConfigBriefInput; /** Per-project app installations, keyed by app name. See /config/apps. */ apps?: Record<string, AppInput>; /** W3C design tokens document for this project. See /config/design-tokens. */ designTokens?: ApplyConfigDesignTokensInput; /** The project's default sign-in page. See /auth/your-sign-in-page. */ loginPage?: LoginPageConfig; /** Transactional email wording, keyed by the action that sends it. */ emailCopy?: ApplyConfigEmailCopyInput[]; /** The project's own transactional email sender (a vault ref, never a key). */ projectEmail?: ApplyConfigProjectEmailInput; description?: string; // Free text on the config row direction?: string; // 'READ' (default), 'write', 'bidirectional' connectionDomain?: string; // The domain a connector-shaped config talks to }

All arrays/maps are optional. Include only what your project needs.

A key this type does not declare is a compile error, deliberately. It used to end in [key: string]: unknown, so anything was accepted — and a block spelled organisations instead of organizations, or one from a release your CLI does not have, type-checked, serialised, was accepted by the platform’s equally tolerant parse and was applied by nothing. Nothing errored. The push said “applied”. If you are reaching for a family that is not here, the name is wrong or the family does not exist.

The platform reports the same thing from its side, because a manifest also reaches it from hand-written JSON and older CLIs: foir push lists every top-level block the server did not recognise, on the dry run as well as the apply. It is a warning rather than a failure — a newer platform may know a block yours does not, so refusing would make every rollout order a breaking change.

Named Projects

A config can declare several full projects by name instead of one, so the same commit is pushed to staging and then to production the way a codebase moves between environments. They are ordinary projects: each has its own users, keys, installs and data, so a rehearsal on staging can write, dispatch and charge without touching production. The platform never learns that they are related.

import { defineConfig } from '@foir/cli/configs'; export default defineConfig({ projects: { production: { id: 'prj_storefront', tenantId: 'ten_studio', name: 'Storefront', envFile: '.env.production', destinations: { storefront: 'https://shop.example.com', checkout: 'https://shop.example.com/api/checkout', }, }, staging: { id: 'prj_storefront_staging', tenantId: 'ten_studio', name: 'Storefront (staging)', envFile: '.env.staging', destinations: { storefront: 'https://staging.shop.example.com', checkout: 'https://staging.shop.example.com/api/checkout', }, }, }, manifest: ({ destinations }) => ({ key: 'storefront', name: 'Storefront', project: { settings: { appBaseUrl: destinations.storefront } }, models: [{ key: 'order', name: 'Order', access: { ownerPlane: 'user' }, fields: [] }], operations: [{ key: 'checkout', name: 'Checkout', endpoint: destinations.checkout }], apiKeys: [ { name: 'Storefront', kind: 'publishable', envVar: 'FOIR_PUBLIC_KEY', grants: ['records:read'], baselineGrants: ['records:read', 'operations:execute:checkout'], }, ], }), });

Each entry in projects is:

Member
idrequiredThe project’s id.
tenantIdrequiredThe id of its tenant.
nameoptionalA name for output.
envFilerequiredWhere this project’s minted keys and signing secrets are written, relative to the config. Two projects may not share one.
apiUrloptionalThe control plane the project lives on. Omit for the production control plane.
destinationsrequiredThe values that may differ between projects, under names the manifest reads them by. Every project supplies the same names.

manifest is called once per declared project with { name, destinations } and returns the same shape a single-project config does, less the pin: project carries only settings, because the id and tenant come from the entry.

Only destinations may differ. On every push the CLI resolves the manifest for every declared project and compares them. A difference in any field that is not a destination, such as a model’s ownerPlane set from the project name, a quota, or a model one project has and the other does not, refuses the push before anything is sent, naming the field and both values. The fields that are destinations are marked in the contract and listed in the generated reference: operation endpoints and operationBaseUrl, auth client redirect URIs, allowed origins, custom domains and post-login URL, placement URL and allowed origin, appBaseUrl, the from name, reply-to and support addresses, the project email sender, app settings, and email copy links.

Selecting one. A command acts in the project --project <name> or FOIR_PROJECT=<name> selects, and there is no default: with projects declared, every command that resolves a target refuses and lists the names, on a terminal and in CI alike. --project-id, --tenant-id, --profile and their variables are refused beside declared projects, because each would name a project around the declaration. foir context show reports which named project is selected and how.

The control plane. A command acting in a named project sends to the project’s apiUrl (or the production control plane when it declares none). A command pointed elsewhere with --api-url or FOIR_API_URL, or holding a session minted elsewhere, is refused with both hosts named, unless --allow-control-plane-mismatch says the difference is intended.

An API key belongs to one project. A command run with FOIR_API_KEY acts in the key’s project, and the platform refuses a request whose key belongs to a different project or workspace from the one the command names, with both named. So a CI job whose staging and production keys were swapped fails on its first command instead of pushing --project production into staging.

Env files. A push writes the minted keys and both signing-secret names to the selected project’s envFile and to no other file, so staging and then production leaves each file holding only its own project’s values. --env is refused beside named projects, because the file is part of the declaration. A config with the singular project writes to .env (or --env) as always.

Drift. A push to a named project fails when the project holds a model, operation, hook, cron schedule or context dimension that the config does not declare and no other config or app owns, most often something added in that project’s console, and lists it. --prune deletes it, after the usual confirmation (or --allow-delete in CI); --no-prune is refused. A definition already waiting for a release to delete it is not drift: the push leaves it to the release that carries it. A key needs each family’s own write and read to delete that family’s rows this way (operations:write and operations:read for operations, models:write and models:read for models, and so on). Each push records the hash of the manifest it applied, taken without destinations so two projects holding one commit hold one hash, and foir projects status prints every project’s recorded hash and drift side by side.

What a push is asked for

A push takes configs:write and configs:read, because it reads the config it changes, and beside them the write and the read of each family it would write. Whoever pushes is asked: a signed-in console user by their role, a key by its own list.

Family in the configTo write it, a console user holdsTo write it, a key holdsTo read it, either holds
modelsmodels:writemodels:writemodels:read
userRolesroles:writeroles:writeroles:read
authProviderssigninproviders:writesigninproviders:writesigninproviders:read
operationsoperations:writeoperations:writeoperations:read
hookshooks:writehooks:writehooks:read
schedulesschedules:writeschedules:writeschedules:read
contextDimensions, locales, variantCatalog, emailCopysettings:writesettings:writesettings:read
designTokensdesigntokens:writedesigntokens:writedesigntokens:read
loginPage, and an auth client’s loginPageloginpages:writeloginpages:writeloginpages:read
agentsagents:writeagents:writeagents:read
briefbrief:writebrief:writebrief:read
projectEmailprojects:writeprojects:write, which a key bound to a project cannot holdprojects:read
project.settingsprojects:writeprojects:write, which a key bound to a project cannot holdprojects:read
authClientsauthclients:writeA key cannot push theseauthclients:read

configs:write and configs:read alone push none of these families. A push that lacks a family’s write or its read is refused before anything is written, and the refusal names the family and the permission. A role is still given only what its pusher holds, and so is an operation.

Two things in a config are kept beside or above the project a push stands in, and a permission held in that project does not reach them. project.settings and projectEmail are kept on the project’s own row, which is written by a console user whose role holds projects:write, themselves or through an agent they are signed in to. A key holds no role, so a key is refused them. Email copy declared with scope: 'workspace' is shared by every project in the workspace, so it is written by whoever holds settings:write across the workspace, and a role given in one project, a key and an agent are refused it.

A family’s write does not stand for its read. A push reads what the project holds of a family to decide what to write in it: to tell a create from an update, and to find what leaving something out would delete. That read is asked of whoever pushes. A key made to push a family holds both.

A family counts as written when the config declares it, and when a push that prunes would delete rows of it the config owns. A push that touches none of a family’s rows is not asked for that family and reads nothing of it. The Project manager and Workspace manager roles hold every one of these.

Three families are reported on and written by the CLI through their own commands: apiKeys, apps, and an auth client’s customDomains. The plan says what will happen to them, and reads what the project holds to say so. It takes apikeys:read for apiKeys, apps:read for apps, and authclients:read with domains:read for customDomains.

Organizations

A push never creates, moves, suspends or deletes an organization, and there is no organizations block. Organizations are management state, like a user or a credential: they are created by your team, by a user signing up through self-serve registration, or by a provisioning call, and they are suspended and deleted by deliberate acts with their own confirmations and their own audit trail.

The reason is this file’s own prune rule. A family a manifest omits is a family whose resources the config owns and no longer wants, so an organizations family would mean that pushing a config without one destroys every tenant in the project — every row, every user, every credential — because a file did not mention them, with no way for that same manifest to put the rows back.

What is manifest-shaped is the project’s policy about organizations, and it lives under project.settings:

SettingWhat it decides
organizationSignupEnabledWhether a signed-in user may register an organization of their own. Default false.
organizationSignupRoleThe role key that organization’s founder is given. Sign-up refuses without it.
organizationAssignableRolesThe roles an organization’s own staffer may hand out. The ceiling on what any organization can become, set by the party that is not inside it.
organizationUsersWhere somebody who signs up at an organization stands: 'joined' (the default) makes them a user of that organization, and 'everyone' makes them a user of the project, so every organization that shares its sign-in can find, email and sign them in. An organization can choose for itself. Changing it moves nobody.
organizationOwnPoolWhether a new top-level organization keeps its own users, so the same email address there is a different person. Default false. Whoever creates one can still choose, and one made inside another shares its parent’s.
organizationJoiningWho may join an organization without an invitation, for one that chooses nothing of its own: 'invitation' (the default), 'open' (somebody who can already sign in at its page joins by signing in there) or 'request' (signing in there asks, and its staff approve or decline). Nobody from another organization’s sign-in can join this way.

organizationAssignableRoles is tri-state: omit it to leave the stored list alone, give a non-empty array to set it, and give an empty array to take the capability away from every organization in the project. Every key must name a live role; the platform refuses the whole list rather than dropping one it cannot resolve, because a list that quietly lost an entry is a capability you believe you granted and did not.

foir pull writes the list only when there is one. A project that has declared none pulls no key at all rather than an empty array — pulling [] would put a revoke instruction into your config and run it on every push.

A credential can be confined to one organization: see confining a key to an organization below. foir push is refused to such a credential, because applying a configuration writes the project’s own configuration, which sits above every organization. Definitions an organization owns are written while standing in it; see definitions inherit down.

Helper Functions

Every helper function provides TypeScript IntelliSense and compile-time validation. They accept and return the same object, so using them is optional but recommended.

defineConfig

Wraps the top-level config object.

import { defineConfig } from '@foir/cli/configs'; export default defineConfig({ key: 'my-app', name: 'My App', models: [...], operations: [...], });

defineModel

Defines a content model with typed fields.

import { defineModel } from '@foir/cli/configs'; const page = defineModel({ key: 'page', name: 'Page', fields: [ { key: 'title', type: 'text', label: 'Title', required: true }, ], lookups: [ { keyBy: ['slug'] }, // fetch by slug; see /config/models#lookups ], });

defineField

Defines a single field definition. Useful when building fields programmatically or reusing field definitions across models.

import { defineField } from '@foir/cli/configs'; const titleField = defineField({ key: 'title', type: 'text', label: 'Title', required: true, placeholder: 'Enter a title...', queryable: true, // allow where/orderBy on this field guarded: { write: true }, // written only with records:write:<model>.title });

Set queryable: true to allow filtering and sorting on a field (the platform rejects sorts on non-queryable fields). Set guarded to take a side of the field out of its model’s grants: a guarded side is read or written only by a holder of records:read:<model>.<field> or records:write:<model>.<field>. Omit it for a field that follows its model. A field’s access list is refused on push by name. See Defining Models.

defineSelectField

Defines a select field. Required for select fields because they need a typed optionModelKey pointing at a model whose records become the options. Plain defineField({ type: 'select' }) is rejected.

import { defineSelectField } from '@foir/cli/configs'; const status = defineSelectField({ key: 'status', type: 'select', label: 'Status', required: true, config: { optionModelKey: 'status-option', // a model with records like 'draft', 'published' multiple: false, }, });

defineEnumField

Defines an enum field — the inline-choice type. Options are declared inline as an { label, value } array. (For options drawn from another model’s records, use defineSelectField instead.)

import { defineEnumField } from '@foir/cli/configs'; const status = defineEnumField({ key: 'status', type: 'enum', label: 'Status', required: true, config: { options: [ { value: 'draft', label: 'Draft' }, { value: 'published', label: 'Published' }, ], multiple: false, default: 'draft', }, });

An option’s value is the wire value. It is what a record stores, the GraphQL enum value the data API reads and writes it as, what GET /v1/manifest lists and what foir types generates, all as one string: orderSlip is served as orderSlip, so app code compares against the value the config declares. The human-readable text belongs in label.

So a value has to be a valid GraphQL enum value: letters, digits and underscores ([_A-Za-z][_0-9A-Za-z]*), not starting with two underscores, and not true, false or null. A push refuses a value outside that, such as us-east, 1 or 2:1, and refuses two values that would be served under one name, naming the value and the rule. Write usEast or us_east, and put US East in the label.

The rule judges only the values a push adds. A value the model already holds keeps working, even one written before the rule: the data API serves it with only what the rule forbids rewritten (top-left as top_left, 1 as _1), and a push that declares it again is not refused for it. To bring such a value inside the rule, rename it in the config and declare a remapValues migration from the old value to the new one, which rewrites the records that store it. The refusal names that way out.

defineOperation

Defines an HTTP endpoint for custom logic.

import { defineOperation } from '@foir/cli/configs'; const syncOp = defineOperation({ key: 'sync-data', name: 'Sync Data', description: 'Syncs records to external system', endpoint: '/sync/all', });

defineHook

Defines a lifecycle hook that triggers an operation on content events.

import { defineHook } from '@foir/cli/configs'; const hook = defineHook({ key: 'sync-on-create', name: 'Sync on create', event: 'RECORD_CREATED', operationKey: 'redirect-sync', filter: { modelKey: 'redirect' }, });

definePlacement

Defines a custom editor panel.

import { definePlacement } from '@foir/cli/configs'; const editorTab = definePlacement({ type: 'main-editor', url: '/', modelKeys: ['page'], tabName: 'Custom Editor', });

defineSchedule

Defines a cron schedule for an operation.

import { defineSchedule } from '@foir/cli/configs'; const nightly = defineSchedule({ operationKey: 'sync-data', cron: '0 2 * * *', timezone: 'America/New_York', enabled: true, });

Add each: 'organization' and a fire starts one run in every active organization of the project, each confined to its own. See Running in every organization.

defineContextDimension

Defines a targeting axis a variant can be selected on. See Segments and context dimensions.

import { defineContextDimension } from '@foir/cli/configs'; const vip = defineContextDimension({ key: 'vip-users', name: 'VIP Users', description: 'High-value users', sourceType: 'segment', evaluationRules: { type: 'condition', left: { type: 'field', path: 'totalSpend' }, operator: 'greater_than', right: { type: 'literal', value: 500 }, }, });

defineVariantCatalogEntry

Defines a named targeting definition. Reconciled create/update only — an entry left out of the manifest is not deleted. See Variant catalog.

import { defineVariantCatalogEntry } from '@foir/cli/configs'; const vips = defineVariantCatalogEntry({ key: 'vip', name: 'VIP', description: 'Content shown to high-value users', targetingRules: { type: 'condition', left: { type: 'field', path: 'segment.vip-users' }, operator: 'equals', right: { type: 'literal', value: true }, }, priority: 10, isActive: true, });

defineLocale

Defines a project locale. Reconciled create/update only. See Localization.

import { defineLocale } from '@foir/cli/configs'; const fr = defineLocale({ locale: 'fr-CA', displayName: 'French (Canada)', nativeName: 'Français (Canada)', fallbackLocale: 'fr', isActive: true, });

defineEmailCopy

Overrides the wording of one transactional email. actionKey names a send path, and the platform refuses one it does not recognise — a row written under a typo would be read by nothing. scope: 'workspace' writes the override once for every project in the workspace.

Reconciled create/update only: a workspace override is shared, so an omission must not delete what another project’s manifest declares. Remove one in the console.

A key that holds settings:write and settings:read pushes its project’s copy, so a CI push can carry it, and so does an agent acting for someone who holds them. Workspace copy is shared by every project in the workspace, so a push that declares scope: 'workspace' is written by whoever holds settings:write across the workspace. A role given in one project, a key and an agent hold it in one project and are refused. Push it signed in on a role given across the workspace.

import { defineEmailCopy } from '@foir/cli/configs'; const welcome = defineEmailCopy({ actionKey: 'email.project.welcome', locale: 'en', scope: 'project', subject: 'Welcome to Acme', heading: "You're in", body: 'Your account is ready. Sign in whenever you like.', ctas: [{ label: 'Sign in', url: 'https://acme.example/sign-in' }], });

defineAuthProvider

Defines an authentication provider.

import { defineAuthProvider } from '@foir/cli/configs'; const auth = defineAuthProvider({ key: 'google-oauth', name: 'Google OAuth', type: 'oauth2', config: { clientId: process.env.GOOGLE_CLIENT_ID, allowedDomains: ['example.com'], }, enabled: true, isDefault: false, priority: 10, });

defineAuthClient

Defines an auth client: an app, yours or a tool someone else runs, that signs your project’s users in through hosted sign-in, starting at /oauth/authorize and exchanging the code at /oauth/token. foir push is scoped to one project, so the auth clients a config declares sign in that project’s users.

import { defineAuthClient } from '@foir/cli/configs'; const storefront = defineAuthClient({ clientId: 'eide-clothing-storefront', name: 'Eide Clothing', redirectUris: ['https://eide.clothing/auth/callback'], grants: ['records:read', 'records:write:order'], // the most a sign-in through this app may carry loginMethods: { password: true, otp: false, disabledProviders: ['apple'], // hide these project providers on this auth client only }, });
interface ApplyConfigAuthClientInput { clientId: string; // Public auth client slug, unique per project name: string; // Display name on the hosted sign-in redirectUris: string[]; // Allow-listed exact redirect URIs grants: string[]; // The most a sign-in may carry; ['*'] is not narrowed, [] is nothing loginMethods?: { // Per-client login method filter (override-down only) password?: boolean; // Show password tab (default true) otp?: boolean; // Show OTP tab (default true) disabledProviders?: string[]; // Provider keys to hide on this auth client }; customDomains?: string[]; // White-label login domains, e.g. ['login.acme.com'] postLoginUrl?: string; // Where a bare custom-domain login lands (front-door) firstParty?: boolean; // The project's own app: nobody is asked to agree to it initiateLoginUri?: string; // Where your app's sign-in starts, for invitations and resets orgId?: string; // The organization it signs people in to, or '' for the whole project promptsForOrganization?: boolean; // Ask which organization, for an app of the whole project logo?: ApplyConfigAuthClientLogo; // Shown with its name on the consent screen homepageUrl?: string; // https; the consent screen links its name here confidential?: boolean; // A server that keeps a client secret allowedOrigins?: string[]; // Origins allowed a browser session, e.g. ['https://app.acme.com'] loginPage?: LoginPageConfig; // This app's own sign-in page }

promptsForOrganization makes a sign-in through an app of the whole project ask somebody who may enter more than one place which organization they are going to, and tells the app in the ID token (org_id). Leave it off for an app whose people act across organizations at once. See Where a person may go.

initiateLoginUri is an address in your app that starts its sign-in. Foir’s hosted pages send a user there after they accept an invitation or reset their password, so they arrive back in your app. See Invitations and resets that start outside your app.

customDomains lets you serve the hosted sign-in from your own domain instead of auth.foir.io. foir push registers each domain (creating a pending row and a DNS challenge) and prunes any you remove from the list; verification is a separate step — add the CNAME and _foir-challenge TXT records the push output prints, then verify. See Custom Domains.

Registering, verifying or removing a domain needs the domains:write permission, which the Project manager and Workspace manager roles both confer. A narrower role that doesn’t hold it will still apply the rest of the manifest normally — only the customDomains entry fails. Creating the auth client itself needs authclients:write, conferred by the same two roles. See Team Members.

redirectUris are matched exactly, including the path and any query string, so list each deployment in full. A wildcard is refused on push rather than stored, because a pattern only ever matches its own literal text: it looks like an allow-list entry and covers nothing. Fragments and embedded credentials are refused too.

Loopback is the one exception to exact match, and it is deliberately port-agnostic. A native client or CLI cannot reserve a port in advance — it binds whatever is free and starts a listener — so a registered http entry on a literal 127.0.0.1 or [::1] matches any port on that host (RFC 8252 §7.3). Register the portless form:

redirectUris: ['http://127.0.0.1/callback']

Everything else still has to match exactly: the scheme, the host, the path, the query string and the fragment. So http://127.0.0.1/callback matches http://127.0.0.1:53114/callback but not http://127.0.0.1/cb.

Three things this does not do:

  • localhost is not loopback here. It resolves through DNS and can be pointed elsewhere, which 127.0.0.1 and ::1 cannot. Register the literal address.
  • https loopback keeps its exact port. The carve-out is for the scheme that has no certificate to offer; an https entry is matched like any other.
  • Userinfo is refused on both sides. A registered entry carrying credentials and a request carrying them both fail the match.

An auth client that registers no loopback entry can never be redirected to one, so this widens nothing for a web app.

allowedOrigins lists the origins your app runs on, and is what lets a browser exchange the first-party session cookie for an access token — the backend-less SPA flow in SPA (no backend). They are exact origins, matched the same way redirectUris are: scheme and host (and port, if it isn’t 443), https only, no wildcards and no paths.

Note: There is no domain-wide default, deliberately. Granting every origin on acme.com would also grant a subdomain you no longer control, or one serving user-generated content — either of which could then mint your users’ access tokens. If you list no origins, the browser session simply doesn’t work; the hosted sign-in code flow is unaffected.

Omitting the key leaves the list untouched on push; passing [] clears it.

So auth clients, their login methods, their white-label domains, and the origins allowed a browser session are all declared in foir.config.ts alongside the rest of your project.

defineDesignTokens

Defines a W3C Design Tokens document for the project. The CLI applies it verbatim and references like {font.size.display1} are preserved on disk. See Design Tokens for the full shape.

import { defineDesignTokens } from '@foir/cli/configs'; const tokens = defineDesignTokens({ color: { brand: { primary: { $value: '#2c4433', $type: 'color' } } }, font: { size: { display1: { $value: '48px', $type: 'dimension' } } }, });

defineSecrets

Secrets are declared separately in a foir.secrets.ts file (not in foir.config.ts) and reconciled with foir secrets push. defineSecrets is the type-safe identity helper for that file:

import { defineSecrets } from '@foir/cli/configs'; export default defineSecrets({ secrets: [ { ownerKind: 'project', label: 'deepl_api_key' }, ], });

Plaintext lives in a sibling local.foir.secrets.ts (gitignored) keyed by label, or in env vars. Production never runs the reconciler: your team sets production secrets through the console.

Field Types

The following field types are available for model field definitions:

TypeDescription
textSingle- or multi-line text (set config.widget: 'textarea' for multi-line)
proseTranslatable rich text; config.allowedTypes admits models and media inline
integerWhole numbers — counts, quantities, order
decimalExact decimals, carried as a string — money, rates, measurements
booleanYes/no toggle
dateDate picker (can include time)
enumInline {label, value} choices — see defineEnumField
selectRecord-backed choice (optionModelKey) — see defineSelectField
referenceReference to another record
modelEmbedded value of an inline model
imageImage upload with alt text and focal point
videoVideo upload with poster and HLS streaming
fileGeneric file upload
listOrdered list of items (itemType controls the inner type)
jsonRaw JSON

See Field Types for detailed descriptions of each type.

Complete Example

This is the full config for the Cloudflare KV Redirect extension, showing models, operations, hooks, and placements working together:

import { defineConfig } from '@foir/cli/configs'; export default defineConfig({ key: 'cloudflare-kv', name: 'Cloudflare KV Redirector', configType: 'cloudflare-kv', models: [ { key: 'redirect', name: 'Redirect', fields: [ { key: 'displayName', type: 'text', label: 'Display Name', required: false, }, { key: 'sourcePattern', type: 'text', label: 'Source Pattern', required: true, }, { key: 'targetPattern', type: 'text', label: 'Target Pattern', required: true, }, { key: 'statusCode', type: 'enum', label: 'Status Code', required: true, config: { options: [ { value: 'http301', label: '301 - Permanent Redirect' }, { value: 'http302', label: '302 - Temporary Redirect' }, { value: 'http307', label: '307 - Temporary Redirect (preserve method)' }, { value: 'http308', label: '308 - Permanent Redirect (preserve method)' }, ], }, }, { key: 'priority', type: 'integer', label: 'Priority', required: false, }, { key: 'activeFrom', type: 'date', label: 'Active From', required: false, }, { key: 'activeTo', type: 'date', label: 'Active Until', required: false, }, { key: 'reason', type: 'enum', label: 'Reason', required: false, config: { options: [ { value: 'migration', label: 'Site Migration' }, { value: 'rebrand', label: 'Rebrand / Rename' }, { value: 'campaign', label: 'Marketing Campaign' }, { value: 'discontinued', label: 'Discontinued Content' }, { value: 'seo', label: 'SEO Optimization' }, { value: 'other', label: 'Other' }, ], }, }, ], }, ], hooks: [ { key: 'sync-on-create', name: 'Sync on redirect create', event: 'RECORD_CREATED', operationKey: 'redirect-sync', filter: { modelKey: 'redirect' }, }, { key: 'sync-on-update', name: 'Sync on redirect update', event: 'RECORD_UPDATED', operationKey: 'redirect-sync', filter: { modelKey: 'redirect' }, }, { key: 'sync-on-delete', name: 'Sync on redirect delete', event: 'RECORD_DELETED', operationKey: 'redirect-sync', filter: { modelKey: 'redirect' }, }, ], operations: [ { key: 'redirect-sync', name: 'Sync Redirects to Edge', description: 'Syncs redirect records to Cloudflare KV', endpoint: '/sync/all', }, { key: 'redirect-sync-status', name: 'Get Sync Status', description: 'Returns current sync metadata for display in the editor', endpoint: '/sync/status', }, { key: 'redirect-undeploy', name: 'Undeploy Edge Redirects', description: 'Tear down Cloudflare Worker and KV namespace', endpoint: '/deploy/destroy', }, ], placements: [ { type: 'main-editor', url: '/', modelKeys: ['redirect'], hideContentTab: true, tabName: 'Redirect Editor', }, ], });

ApiKey Provisioning

apiKeys declares API keys the CLI provisions during foir push. The created key value is written into your project’s .env file under the named environment variable so your application can pick it up immediately.

interface ApplyConfigApiKeyInput { /** Display name (e.g. "Tilly iOS"). */ name: string; /** What the key is for: 'publishable' sits in a page or an app, 'server' is held by the server that renders your pages, 'admin' is a machine's own. */ kind: 'publishable' | 'server' | 'admin'; /** Env var the CLI writes the key value to (e.g. "FOIR_PUBLIC_KEY"). */ envVar: string; /** What the key holds. Declared for every key. An admin key may hold ["*"]. */ grants: string[]; /** What a publishable or a server key gives whoever comes through it. Nothing is filled in. See below. */ baselineGrants?: string[]; /** An admin key only: how long it lives from the push that makes it, e.g. "90d". See below. */ expiresIn?: string; /** The models whose records the key reads. See below. */ allowedModels?: string[]; /** The key reads the records of every model, those added later among them. See below. */ allModels?: boolean; /** Restrict file uploads: "image/png", "image/*", or IMAGE, VIDEO, FILE. */ allowedFileTypes?: string[]; /** Confine the key to one organization of this project, by id. */ org?: string; }

kind accepts exactly 'publishable', 'server' and 'admin'. You choose what each key is for, and the platform holds the key to what that kind may hold and give (Credentials). Any other word is refused before anything is sent, naming every offending key, and nothing is written. A typo is never read as a kind.

A key declared with keyType is refused the same way, and told to declare kind. 'public' is 'publishable'. 'secret' is 'admin' for a key a machine of your own holds, and 'server' for a key the server that renders your pages holds.

A key’s kind never changes. A config that declares another kind for a key that already exists is refused, naming the key, and no key is written. A different kind is a different key: declare it under a new name, deploy it, and remove the old one. That refusal comes when the keys are reconciled, after the rest of the config has been applied, so the models, operations and hooks in that push are live. Fix the config and re-run; the push is idempotent over what already applied.

An admin key’s expiry

An admin key expires. Declared without expiresIn it is given 90 days from the push that makes it. expiresIn takes a number of days, such as '30d', up to '365d'. A publishable or a server key never expires, and one declared with expiresIn is refused before anything is sent.

expiresIn is read when the key is made. A push never renews a key that exists: renew it with foir api-keys renew <id>, so that a key is kept alive by somebody deciding to and not by a pipeline that happens to run. See An admin key expires.

What a key gives

A key holds one list and gives another. grants is what the key holds: the most anyone may do through it. baselineGrants is what it gives whoever comes through it: a caller with nobody signed in, and a signed-in user beneath their role, on a publishable or a server key. An admin key gives nobody anything, and one declared with baselineGrants is refused.

Nothing is filled in. A key declared without baselineGrants gives a visitor nothing, whatever it holds. A publishable key holding records:read and no baselineGrants is a key no visitor can read with. Name each read a visitor needs:

apiKeys: [ { name: 'Storefront', kind: 'publishable', envVar: 'FOIR_PUBLIC_KEY', grants: ['records:read', 'search:read'], baselineGrants: ['records:read', 'search:read', 'operations:execute:checkout'], allModels: true, }, ],

A visitor may be given a read, and two forms that each name one thing the same config declares:

  • records:create:<model> creates rows of one model, owned by nobody
  • operations:execute:<operation> runs one named operation

The push checks both lists before anything is sent, against the platform’s own list of what a key of that kind may hold and give. A wildcard on a publishable or a server key, an update, delete or publish given to a visitor, or an unnamed records:create is refused, naming the key. So is an entry naming a model or an operation the config does not declare.

A push sets each declared list on the existing key in place, as it does the key’s models and allowedFileTypes: the key keeps its id and its secret, and nothing is written to the env file. The change is live at once. A credential is never held for a release, and the push plan says so. Leave baselineGrants off to keep whatever the key gives (for instance a list set in the console); declare [] to leave it giving nothing.

The push says when a key gives nothing. The plan names each new publishable or server key that would give a visitor nothing, and the push prints what the platform says about every key it wrote.

The plan names each key the push makes or changes. A dry run and the push itself print the key’s name, its kind, and what it holds and gives before and after. For an admin key the plan also says when it expires: the date a key that exists already has, which a push never moves, or the date a new one is given.

A push stops at two things, before anything is sent, and a dry run stops at the same two. One is a key that exists and would be left holding nothing: pass --allow-key-holding-nothing "<name>" if that is meant. The other is a key declared as another kind than the key that exists. A key’s kind never changes, so declare the new kind under a new name.

Keys declared by scopes

A key is declared by grants and baselineGrants, and by nothing else. A config that still declares a key’s scopes or anonymousScopes is refused before anything is sent, naming what to declare. So is a key that declares no grants: nothing is filled in, and it would be minted holding nothing.

A grant stands for itself, so name each permission a key needs. A name that is not a permission in the catalogue is refused, and where it is a name a permission had before the catalogue, the refusal says what it is written as now. A key that existed before the two lists was also given designtokens:read: declare it if the key reads your design tokens, because a push sets a key’s grants to exactly what the config declares.

Which models a key reads

A key reads the records of the models it names in allowedModels, or of every model when it declares allModels: true. Every model is a choice you write down: a key that declares neither reads no model’s records. It keeps everything else it holds, such as running an operation or reading your design tokens. Declaring both is refused before anything is sent.

allModels: true covers models you add later. allowedModels covers the models it names and no others. A push sets either on the existing key in place.

When a release removes the last model a key names, the key loses that name, so a model added later under the same key is not given to it. The key keeps its other grants. If records were all it reached, it is switched off as well. Either way, whoever made the key is emailed, or the workspace’s managers when its maker has no address. Declare its models again, or allModels: true, and push.

Restricting what a key uploads

allowedFileTypes confines the files a key may upload. Each entry is one of:

  • an exact MIME type, such as application/pdf
  • a whole type, such as image/*
  • IMAGE, VIDEO or FILE, the categories the dashboard offers. FILE is every type that is neither an image nor a video.

Matching ignores case and any parameters on the type. An entry that is none of these fails the push, naming the entry. Leaving the list off confines nothing.

The platform checks the list twice. uploadFile refuses a declared content type the list does not admit, and when the bytes land the platform reads the start of them and refuses when what was actually uploaded is not admitted, whatever type was declared. A refused upload’s object is removed. The refusal is PERMISSION_DENIED and names the list, for example this api key's allowed_file_types (image/*) do not include the uploaded bytes, which are "application/pdf" (declared "image/png").

An admin key that manages keys

An admin key may hold apikeys:read and apikeys:write, so a machine of your own can issue and rotate keys for its own project. Everything it creates or acts on is capped at what it holds itself, its allowedModels and allowedFileTypes, as described in Keys that manage keys. Neither a publishable key, a server key nor a key with org set can hold either scope, and the platform refuses a key declared that way, naming the scope.

Confining a key to an organization

org takes an organization id — the same value foir api-keys create --confine-to-org takes. An organization is identified by a minted id, the way a project and a tenant are; names are not unique, so a name would not resolve to one organization. A confined key reads that organization’s rows, the rows of every organization nested under it and the project-shared tier, and writes only into its own organization and the organization-owned records that organization owns. The confinement travels on the credential, so nothing downstream can widen it.

It is part of the key’s IDENTITY, not just its configuration. Two organizations may each have a key named Storefront, so foir push matches a declared key on its name and its organization. A manifest that declared one and left org off would be matched against a project-level key of the same name instead.

Set on create only. A key’s organization cannot be changed afterwards — a manifest that moved one would be asking a live credential to change which tenant it belongs to, which is a new key rather than an edit.

An org that names nothing in the project fails the whole push before anything is written, and the error names both the key and the organization.

apiKeys: [ { name: 'Storefront', org: 'org_d72zr40bcbei7ddgwwc96zft', kind: 'publishable', envVar: 'ACME_PUBLIC_KEY', grants: ['records:read'], baselineGrants: ['records:read'], allModels: true, }, ],
export default defineConfig({ key: 'tilly', name: 'Tilly', apiKeys: [ { name: 'Tilly iOS', kind: 'publishable', envVar: 'TILLY_PUBLIC_KEY', // allowedModels is what bounds the key to these two models. A key that // names no model, and does not declare allModels: true, reads no // model's records. // Nobody uses this app without signing in, so the key gives a visitor // nothing: no baselineGrants. grants: ['records:read', 'records:write'], allowedModels: ['tilly_note', 'tilly_block'], }, { name: 'Tilly CRM sync', kind: 'admin', envVar: 'TILLY_ADMIN_KEY', grants: ['*'], expiresIn: '90d', }, ], });

Roles

userRoles declares the roles. A role’s grants are what a signed-in user who holds it may do, and they are what a user access token carries. Reconciled by foir push (matched by key within the project: declared keys are created or updated in place, and roles present on the platform but absent from the config are left untouched, never disabled).

A role is declared by its grants, in the permission catalogue’s names, and by nothing else. A config that still declares permissions is refused before anything is sent, naming what to declare.

A consumer app’s publishable key gives a visitor no write and no execute beyond what its own list names, so the source of those is the user’s role. Without a role, a user has only what the key gives a visitor. Declare a single isDefault: true role to give every user the baseline they need:

interface ApplyConfigUserRoleInput { /** Stable key, unique per project (e.g. "default"). */ key: string; /** Display name (e.g. "Member"). */ name: string; /** What the role gives users who hold it, as grants in the permission catalogue's names. */ grants: string[]; /** When true, every user inherits this role with no per-user assignment. */ isDefault?: boolean; }
export default defineConfig({ key: 'tilly', name: 'Tilly', userRoles: [ { key: 'default', name: 'Member', // Their own orders, and running checkout. Each grant stands for itself. grants: ['records:read:order', 'records:write:order', 'records:create:order', 'operations:execute:checkout'], isDefault: true, }, { key: 'staff', name: 'Staff', // The bare verb runs every operation the key exposes. grants: ['records:read:order', 'records:write:order', 'records:create:order', 'operations:execute'], }, ], });

operations:execute runs every operation the key exposes, and operations:execute:<operation-key> runs that one alone, so the default role above lets every user check out while only a user holding the staff role runs the rest. A role naming an operation the project does not have is refused at push, naming the role and the operation.

A guarded field takes the grant that names it. A role reaches a guarded field with records:read:<model>.<field> or records:write:<model>.<field>, and the grants on its model don’t reach it. self:* is retired: a role that names it is refused, and the refusal says what to write.

Each grant stands for itself. Changing a record and creating one are two grants: a role that should do both lists records:write:<model> and records:create:<model>, and a role may hold either without the other. Reading every user’s records is records:read.all, semantic search is embeddings:read and embeddings:write, and staffing an organization is members:read and members:write. The Role Permissions page lists every grant a role may give.

A push puts on a role only what the person pushing holds themselves. Whoever does not hold records:delete is refused a push that adds it to a role, by name.

A changed role reaches a signed-in user on their next token refresh. Refresh re-resolves the user’s scopes from their roles as they stand, so there is no need to sign in again.

The same operations are available imperatively via the foir roles CLI command (list, create, update, disable, assign, revoke, assignments).

Apps

Per-project app installations live under the top-level apps key. Each entry maps a manifest URL to the project’s models and any per-project settings. See Defining Apps for the full reference.

interface AppInput { source: string; // https URL to the manifest JSON settings?: Record<string, unknown>; userSignIn?: string | false; // sign-in key; false pairs none; omitted leaves it alone mappings?: { sources?: Record<string, AppSourceMappingInput>; sinks?: Record<string, AppSinkMappingInput>; placementFields?: Record<string, AppPlacementFieldChoiceInput>; }; } interface AppSourceMappingInput { toModel: string; naturalKey: string; fields: Record<string, string>; // app-field-name → model-field-key } interface AppSinkMappingInput { toModel: string; naturalKey: string; fields: Record<string, string>; } interface AppPlacementFieldChoiceInput { model: string; field: string; }

Project Settings

The top-level project key pins the config to a project (guarding against pushing one folder’s config into another) and carries declarative project-level settings. The pin (id / tenantId) is reconciled by foir push; foir pull populates the settings block from live project state. Omit settings to leave the platform settings untouched.

foir push applies the settings in the same transaction as every other family, so a push that is refused anywhere leaves them as they were, and reports them as the project settings family: updated when a declared value changes, unchanged when the project already holds it. A key the platform does not recognise, or a value of the wrong type, refuses the push rather than being ignored. The settings take projects:write, and are kept on the project’s own row, which is written by a console user whose role holds it, themselves or through an agent they are signed in to: an API key is refused a manifest that carries them. projectEmail (the sender address and the Resend key reference) is kept on the same row and takes the same. A custom from address needs a Resend key.

interface ApplyConfigProjectInput { id: string; // Project id this folder is bound to tenantId: string; // Tenant id of the bound project name?: string; // Human-friendly name for diff readability settings?: ApplyConfigProjectSettingsInput; } interface ApplyConfigProjectSettingsInput { displayName?: string; // Name in the project's emails and sign-in page logoUrl?: string; // Public logo URL (the project's emails) primaryColor?: string; // Accent hex in the project's emails fromName?: string; // "From" name on the project's emails replyTo?: string; // "Reply-To" address supportEmail?: string; // Support email in email footers appBaseUrl?: string; // Public base URL; links in the project's emails are built from this termsUrl?: string; // https; every sign-in page links to it in its footer privacyUrl?: string; // https; every sign-in page links to it in its footer welcomeEmailEnabled?: boolean; // Welcome email on registration (default true) signupMode?: 'public' | 'restricted' | 'waitlist' | 'closed'; // Self-serve signup mode (default 'public') signupRestrictions?: SignupRestrictionsInput; // Email hygiene + lists, public mode only passwordEnabled?: boolean; // Email/password sign-in (default true) otpEnabled?: boolean; // Email one-time-code login (default false) locksAccountsAfterFailedSignIns?: boolean; // Ten wrong passwords lock the address everywhere for an hour (default false) organizationSignupEnabled?: boolean; // Users may register their own organization (default false) organizationSignupRole?: string; // Role key a self-registered organization's founder holds organizationAssignableRoles?: string[]; // Roles an organization's staffer may hand out; [] revokes organizationUsers?: 'joined' | 'everyone'; // Where somebody who signs up at an organization stands (default 'joined') organizationOwnPool?: boolean; // New top-level organizations keep their own users (default false) organizationJoining?: 'invitation' | 'open' | 'request'; // Who may join an organization without an invitation (default 'invitation') anonymousNotesEnabled?: boolean; // Take notes from visitors who are not signed in (default false) noteScreenshotsEnabled?: boolean; // A signed-in user's note may carry a screenshot (default true) sites?: SiteInput[]; // The project's own websites; [] removes them all } interface SiteInput { origin: string; // Exact https origin, such as 'https://www.example.com' name?: string; // Default: its host allowEditing?: boolean; // May frame the console's field editor (default false) } interface SignupRestrictionsInput { blockSubaddresses?: boolean; // Require the canonical inbox form blockDisposable?: boolean; // Reject known disposable domains allowlist?: string[]; // Non-empty allowlist is exclusive and beats the blocklist blocklist?: string[]; // Exact address, whole domain, or *.domain.com }

signupMode decides what self-serve registration does. public accepts anyone who is not refused by signupRestrictions, restricted accepts only an invited email, waitlist queues the request for approval instead of creating an account, and closed turns self-serve signup off. See Signup modes for what each does to sign-up through the API.

signupRestrictions applies to public mode only. blockSubaddresses requires the canonical inbox form, so a subaddress tag, a Gmail dot variant and the googlemail alias domain all resolve to the address they belong to. List patterns are an exact address (user@domain.com), a whole domain (domain.com), or wildcard subdomains (*.domain.com).

sites lists the project’s own websites. It is the whole list: a push replaces the project’s sites with it, [] removes them all, and leaving the key out leaves them alone. A site is matched to the project’s by its origin, so a push that changes a site’s name or allowEditing changes that site, and foir pull writes the list back without ids. Each origin is an exact https origin, a host and an optional port with no path, and the push refuses the whole list for one it cannot read. allowEditing lets the site frame the console’s field editor, so somebody signed in edits a field in place on it. A site that may frame a signed-in editor may also trick someone into clicking it, so allow it only on a site you control. Like every project setting, a change takes effect with the project’s next release.

settings: { sites: [ { name: 'Marketing', origin: 'https://www.example.com', allowEditing: true }, { origin: 'https://shop.example.com' }, ], },

Auth Clients

authClients registers the apps that sign your project’s users in through hosted sign-in. See defineAuthClient above for the full shape and example.

Design Tokens

designTokens carries a W3C Design Tokens document for the project, applied verbatim by foir push. See Design Tokens and defineDesignTokens.

Secrets

Secrets are not part of foir.config.ts. They are declared in a foir.secrets.ts file with defineSecrets and reconciled with foir secrets push.

Next Steps

Last updated on