Skip to Content
Config SystemDefining Apps

Defining Apps

Apps are pluggable units delivered by manifest URL. Declare which apps your project installs (and how they map onto your models) in the apps block of foir.config.ts. The CLI reconciles platform state against this declaration on every foir push.

For background on what apps are, see Apps.

App Interface

interface AppInput { /** https URL to the manifest JSON. */ source: string; /** Opaque settings forwarded to the app's middleware. Shape is driven by manifest's settings_schema. */ settings?: Record<string, unknown>; /** The sign-in the install pairs with the app. `false` pairs none; left out, the pairing is left alone. */ userSignIn?: string | false; mappings?: { /** Mapping from manifest source-type names to project models. `false` declines an optional one. */ sources?: Record<string, AppSourceMappingInput | false>; /** Mapping from manifest sink-contract names to project models. `false` declines an optional one. */ sinks?: Record<string, AppSinkMappingInput | false>; /** Per-placement field choice for TARGET_FIELD placements with field_selected_at_install=true. */ placementFields?: Record<string, AppPlacementFieldChoiceInput>; }; } interface AppSourceMappingInput { /** Project model key the source type maps to. */ toModel: string; /** Field key on the model that's the natural-key for upserts. */ naturalKey: string; /** Map from manifest field name → project model field key. */ fields: Record<string, string>; /** Where the app offers it: 'reference' reads the host's fields live, 'sync' keeps a copy. Omit to leave the choice alone. */ mode?: 'sync' | 'reference'; } interface AppSinkMappingInput { toModel: string; naturalKey: string; fields: Record<string, string>; } interface AppPlacementFieldChoiceInput { /** Resolved model key (or "*"). */ model: string; /** Project field key the placement attaches to. */ field: string; }

The top-level apps field is Record<string, AppInput> keyed by app name. The key under apps.<name> must match the manifest’s name field exactly.

Basic Example

import { defineConfig } from '@foir/cli/configs'; export default defineConfig({ key: 'bobs-country-bunker', name: "Bob's Country Bunker", models: [ { key: 'product', name: 'Product', fields: [ { key: 'title', type: 'text', label: 'Title', required: true }, { key: 'handle', type: 'text', label: 'Handle', required: true }, { key: 'vendor', type: 'text', label: 'Vendor' }, { key: 'priceRange', type: 'json', label: 'Price range' }, { key: 'editorial', type: 'prose', label: 'Editorial copy' }, ], }, ], apps: { shopify: { source: 'https://apps.example.com/shopify/manifest.json', settings: { shop: 'bobscountrybunker.myshopify.com', apiVersion: '2025-10', }, mappings: { sources: { product: { toModel: 'product', naturalKey: 'handle', fields: { title: 'title', handle: 'handle', vendor: 'vendor', priceRange: 'priceRange', }, }, // This manifest marks `user` optional. Declining it is a line you // write, not a line you leave out: see Optional sources below. user: false, }, }, }, }, });

Optional sources and sinks

A manifest can mark a source or sink optional, which means an install may leave it unmapped. Shopify’s user source is the case this exists for: a project decides whether it wants user records at all.

Declining one is something you write, not something you leave out.

sources: { product: { toModel: 'product', naturalKey: 'handle', fields: { /* … */ } }, user: false, // this project does not sync users }

An optional name that is neither mapped nor set to false fails the push, and the error names both spellings. That is deliberate: silence would have to mean one of “I decided against this” or “I forgot”, and the second one is a user who believes a data type is syncing when it is not. There is no signal that distinguishes them after the fact, so the push asks.

Declining submits nothing for that name rather than an empty mapping. The platform drops the operations, hooks and placements whose $placeholders reference an unmapped optional source, so its grants disappear with them and no token is ever minted carrying it.

Changing a mapped optional source to false and pushing is a removal: the mapping goes, and so do the operations and grants that hung off it. foir pull writes false for an optional source your install declined, so a pull followed by a push is a no-op rather than an error.

foir push

The user sign-in

An app whose own system has users finds them in your project by who they are when they sign in, never by their email address. Which of your project’s sign-ins those users come through is the install’s to say, and it is one choice for the whole install: see Users of the app’s own system.

apps: { shopify: { source: 'https://apps.example.com/shopify/manifest.json', userSignIn: 'shopify', // the key of a sign-in under authProviders mappings: { /* … */ }, }, }

The value is the key of an OAuth or OIDC sign-in the project serves: one that has been released and is enabled. A sign-in a push has only just declared under authProviders is a draft until it is released (foir release publish), and the platform refuses to pair a sign-in its users cannot yet use. Release it, then push the pairing.

There are three things a config can say, and they are not the same:

In the configWhat a push does
userSignIn: 'shopify'Pairs that sign-in
userSignIn: falsePairs none
nothingLeaves the install’s pairing as it stands

Leaving the line out never removes a pairing. A user can pair a sign-in in the console and a config that does not mention it will not undo that on the next push. Removing a pairing is something you write.

The platform refuses to remove the pairing from a running install while a feature that works through it is on, and says which feature. Turn the feature off first, or pair another sign-in.

foir pull writes userSignIn for an install that pairs one, and writes nothing for an install that pairs none.

The CLI:

  1. Fetches the manifest from source
  2. Validates it
  3. Compares the supplied mappings to what the manifest declares
  4. Installs the app (or updates it, if already installed)
  5. Records the pushed mappings as a snapshot for three-way merge on the next push

After install, credentials still need to be written separately: foir.config.ts never carries secrets. For OAuth apps, click Set up on the app’s detail page, then Authorize. For API-key apps, fill the form in the app’s Credentials section.

Sources vs sinks

Source types describe inbound data the app can deliver to your project (Shopify products, Stripe customers, GitHub issues). Sink contracts describe outbound data the app needs to read from your project to push elsewhere (Cloudflare redirects, Algolia search docs).

The mapping shape is the same for both: which project model receives or supplies the data, what field is the natural key, and which app-side field name corresponds to which model field key. A source can also say mode: 'reference' to read the host’s fields live where the app offers it, or 'sync' to keep a copy.

apps: { redirector: { source: 'https://redirector.example.com/manifest.json', settings: { cloudflareZone: 'bobscountrybunker.com', workerName: 'foir-redirects-bcb', }, mappings: { sinks: { redirect: { toModel: 'redirect', naturalKey: 'sourcePattern', fields: { source: 'sourcePattern', target: 'targetPattern', status: 'statusCode', priority: 'priority', activeFrom: 'activeFrom', activeTo: 'activeTo', }, }, }, }, }, },

Field-level placement choices

If the manifest declares a TARGET_FIELD placement with field_selected_at_install: true, the project must supply a field choice keyed by the placement key:

apps: { 'color-picker': { source: 'https://color-picker.example.com/manifest.json', mappings: { placementFields: { // Manifest declared a placement with key="picker" and // field_selected_at_install=true. picker: { model: 'product', field: 'accentColor', }, }, }, }, },

The same app can be installed in multiple projects with different field choices — that’s the whole point of deferring the choice to install time.

Multiple apps

Declare any number of apps. Each entry is independent:

apps: { shopify: { source: 'https://apps.example.com/shopify/manifest.json', settings: { shop: 'bobscountrybunker.myshopify.com' }, mappings: { sources: { product: { /* ... */ } } }, }, redirector: { source: 'https://redirector.example.com/manifest.json', settings: { cloudflareZone: 'bobscountrybunker.com', workerName: 'foir-redirects-bcb' }, mappings: { sinks: { redirect: { /* ... */ } } }, }, 'color-picker': { source: 'https://color-picker.example.com/manifest.json', mappings: { placementFields: { picker: { model: 'product', field: 'accentColor' } }, }, }, },

Diff-aware push (three-way merge)

foir push records the pushed mappings payload as a snapshot on the platform. On the next push, the CLI does a three-way merge:

  • The base is what was last pushed
  • The theirs is what’s currently on the platform (which the console may have edited via the UI)
  • The ours is what your foir.config.ts says now

The paired sign-in is merged the same way, when the config names one: a pairing changed in the console since the last push stands if the config has not changed, and is a conflict if the config changed it to something else.

Conflicts surface as errors — the CLI doesn’t silently clobber console-side edits. Resolve by either editing your config to match, or pulling the console’s state into your config (foir pull writes the current mappings back). This is what makes foir push safe even when managers also click around in the dashboard.

Pulling app state back

foir pull

…writes the live app mappings back into your foir.config.ts so committed code is the source of truth again. Use this whenever a manager has edited mappings via the UI and you want to bring those edits into version control.

Push order

Within a single push, the CLI:

  1. Pushes models, operations, hooks, schedules, context dimensions, auth providers, placements, API keys (project-owned resources)
  2. Then pushes apps — install or update each app in declaration order

This ordering matters: the project’s models need to exist before app mappings can resolve. If your config references a model under apps.<name>.mappings.sources.X.toModel, that model must also be declared in the same config (or already exist on the platform).

Validation rules

The CLI rejects a push that would leave the platform in an invalid state:

  • Every declared source type and sink contract in the manifest must have a mapping
  • The target model must exist (declared in this config or already on the platform)
  • The target model must have every field referenced in fields
  • An optional source or sink must be answered, not skipped: map it, or set it to false to decline it. Leaving the name out entirely fails the push — there are three states here, not two, and “not mentioned” is not one of them
  • Every placement with field_selected_at_install: true must have a placementFields entry

Errors surface with structured paths so you can fix them in your config:

apps.shopify: missing mappings in foir.config.ts: source user (optional: map it, or write `user: false` to decline it)

Next Steps

Last updated on