Skip to content

    Reference02

    Configuration

    Every key of bounda.config.ts, what it does and its default.

    bounda.config.ts exports defineConfig({...}) from @bounda-dev/core/config. boot() reads it, and createApp takes the same object; createTestApp does not read it. The configuration is checked when the app is created: an unknown key, a value of the wrong type or a duration it cannot read throws a ConfigurationError that lists every problem with its path.

    TypeScript
    import { defineConfig } from "@bounda-dev/core/config";
    import { postgresql } from "@bounda-dev/postgresql";
    export default defineConfig({
    storage: postgresql({ url: process.env.DATABASE_URL! }),
    ports: { order: { notifier: "smtp" } },
    runtime: { role: "worker", policies: { timeout: "1m" } },
    });

    A project that serves several tenants, each its own database, exports a function of the tenant instead: defineConfig(({ tenant }) => ({ storage: postgresql({ url, schema: tenant }) })). boot(), the CLI and the React Router host call it with the tenant they serve, BOUNDA_TENANT or --tenant naming it, default without either; configForTenant({ config, tenant }) does the same for code of your own. See tenants. Such a project may also export tenants, a list of the tenants it serves or a function that resolves to one, which commands that go through every tenant reach beside those its stores list, as bounda forget-ledger prune --all-tenants bounda tenant-key rewrap-master, status and remove-stale do, and so does forgetTenant in an app boot() creates, which removes the copies of the tenant’s key those stores hold; loadProject hands it as tenants(), and boot({ config, tenants }) takes it with a configuration given directly.

    Durations are a number of milliseconds or a string: a number followed by ms, s, m, h or d ("250ms", "1.5s", "7d"). A duration read from the environment is a string, which the types refuse; wrap it with asDuration(process.env.X ?? "1m"), which checks it.

    • storage, required. The adapter that holds the store: sqlite({...}), postgresql({...}) or cloudflare(), whose binding names the Durable Object binding the Worker reaches it through, "STORE" by default. See adapters.
    • readModels, default {}. A different adapter for some read models, by read model name: { orderSummary: postgresql({ url: READ_URL }) }. The rest stay in storage. Under a storage that declares a location, each must declare one under the same legal regime, or another with a safeguard.
    • ports, default {}. The implementation each port uses, by module and port: { order: { notifier: "smtp" } }. A port with one implementation may be left out; one with several must be named. The names are typed from the project. See ports.
    • runtime. How the app runs.

    Every adapter takes location, none by default: where its database keeps the data, such as "eu". cloudflare() takes its jurisdiction instead, and defineTenantKeyStore and defineForgetLedger take a location as their second argument, and so does defineKeyWrapper; masterKey takes it beside from.

    TypeScript
    const location = "eu";
    export default defineConfig({
    storage: postgresql({ url: process.env.DATABASE_URL!, location }),
    readModels: { search: sqlite({ url: process.env.SEARCH_URL!, location }) },
    runtime: {
    personalData: {
    keyWrapper: masterKey({ from: "BOUNDA_MASTER_KEY", location }),
    tenantKeys: postgresql({ url: process.env.TENANT_KEYS_URL!, location }),
    },
    },
    });
    • A location is a country by its ISO 3166-1 alpha-2 code in lower case, such as "de", "ch" or "us", or an area: "eu" (the European Union), "eea" (the European Economic Area), "fedramp" and "fedramp-high" (the Durable Object jurisdictions of FedRAMP data centres in the United States), and "global" (anywhere in the world, as Workers KV keeps what it holds). The type is DataLocation. The app refuses to start on any other value, "DE", "EU" and "uk" included, rather than guess where it is: a wrong guess would hide a transfer.
    • Locations are compared by the legal regime each is under for chapter V of the GDPR, which regimeOf answers: the European Economic Area for "eu", "eea" and the country of every member state, including the parts ISO codes apart where the GDPR applies, the Åland Islands ("ax") and the outermost regions of France ("gf", "gp", "mf", "mq", "re", "yt"); the United States for "us", "fedramp" and "fedramp-high"; each other country its own; and none for "global". Keeping data in "de" under a storage in "eu", or in "fedramp" under one in "us", is no transfer; in "ch" under one in "eu" it is.
    • The location storage declares is the app’s. The app refuses to start, with ConfigurationError, and bounda personal-data inventory to draw the record, on a read model in readModels, personalData.keyWrapper, personalData.tenantKeys or personalData.forgetLedger.store that declares none, or one under another regime without a safeguard: each carries the persons’ data, or the key that opens it, wherever it is kept, and encryption protects data from a transfer only while its keys stay behind. A storage in "global" is refused too: it places the app’s data in no jurisdiction to judge the rest against.
    • A storage that declares none holds nothing else to one, and each store says its own.
    • The record of processing states each one’s location next to everything kept there, the master key’s included, and lists every store of personal data, and the key wrapper, that declares none as a finding, which makes the command exit 1.
    • Bounda cannot see where a server, a file or a process is, so a location is taken at its word; on Cloudflare an object checks its own jurisdiction, but not where a Worker’s secrets are kept. A local file, memory() and masterKey declare where the host runs, and the app’s processes run where its storage is.
    • create-bounda writes "eu". See transfers out of the EEA.

    A store may be kept under another legal regime than storage’s when a safeguard of chapter V of the GDPR allows the transfer: every adapter, masterKey, defineKeyWrapper, defineTenantKeyStore and defineForgetLedger take safeguard beside location, one of "adequacy" (article 45), "standard-contractual-clauses" (46(2)(c)), "binding-corporate-rules" (47), "code-of-conduct" (46(2)(e)) or "certification" (46(2)(f)), as recipients declare theirs. Here the keys are held in Switzerland, under its adequacy decision, and the data in the EU:

    TypeScript
    export default defineConfig({
    storage: postgresql({ url: process.env.DATABASE_URL!, location: "eu" }),
    runtime: {
    personalData: {
    keyWrapper: masterKey({ from: "BOUNDA_MASTER_KEY", location: "ch", safeguard: "adequacy" }),
    tenantKeys: postgresql({
    url: process.env.TENANT_KEYS_URL!,
    location: "ch",
    safeguard: "adequacy",
    }),
    },
    },
    });
    • The types take a safeguard only beside a location, and "adequacy" only beside a location an adequacy decision covers (AdequateLocation), with its adequacyScope where that decision covers some providers alone (PartiallyAdequateLocation). The app refuses to start, with ConfigurationError, on a store kept under another regime without a safeguard, on a safeguard under storage’s regime, which is no transfer, on a safeguard on storage itself or under a storage that declares no location, which leaves nothing to tell a transfer by, and on a derogation: article 49 allows one for occasional transfers alone, never for data kept somewhere as long as the app runs.
    • "adequacy" is taken for a country of ADEQUATE_COUNTRIES, those the European Commission has adopted an adequacy decision for (Andorra, Argentina, Brazil, Canada, the Faroe Islands, Guernsey, Israel, the Isle of Man, Japan, Jersey, New Zealand, the Republic of Korea, Switzerland, the United Kingdom, the United States and Uruguay, as of November 2026), and for the European Economic Area under a storage outside it; never for "global". The decisions for Canada and the United States cover some recipients alone, as partial adequacy decisions says.
    • Bounda checks that list against the Commission’s own every week, and a new decision, a review that changes what one covers or a revocation reaches ADEQUATE_COUNTRIES in the next release. Until you upgrade, a newly covered country takes another safeguard. A revoked one leaves the list in that release, and an app that declares adequacy for it, on a store or a recipient, no longer type-checks nor starts until it declares another.
    • Bounda also checks every week, on EUR-Lex, that each decision of the list is still in force: a decision repealed, annulled or expired, even before the Commission’s page says so, and an act in force that reads as a decision Bounda does not know (a new one, a renewal, an amendment) fail the check, and a decision whose validity ends within six months warns of it.
    • The record of processing names each transfer, the legal regime it goes to, its safeguard and its article, next to everything kept there, as article 30(1)(e) asks, and each person’s export lists it in transfers, as article 15(2) asks, each with its location, safeguard, article, regime and partialAdequacy, the regime regimeOf names: a store in "fedramp" is under "US".
    • The safeguard itself, the clauses signed and the transfer impact assessment are yours: Bounda states what you declare. On Cloudflare, the keeper takes a jurisdiction of its own.

    Two decisions of ADEQUATE_COUNTRIES cover some recipients in their country alone, and PARTIAL_ADEQUACY carries each as data: the decision, its celex number on EUR-Lex, whom it covers, the condition the recipient, or the provider that keeps a store, must meet, and the scope that names it.

    Country Decision Covers adequacyScope
    Canada ("ca") Commission Decision 2002/2/EC recipients subject to PIPEDA, as private-sector organisations are for what they handle in commercial activities "pipeda"
    United States ("us", "fedramp", "fedramp-high") Commission Implementing Decision (EU) 2023/1795 organisations on the Data Privacy Framework List, with an active certification that covers the data, human resources data or other "data-privacy-framework"

    A store kept there, or a recipient there, rests on "adequacy" only beside the decision’s adequacyScope, which says you verified the condition:

    TypeScript
    export default defineConfig({
    storage: postgresql({ url: process.env.DATABASE_URL!, location: "eu" }),
    readModels: {
    search: postgresql({
    url: process.env.SEARCH_URL!,
    location: "us",
    safeguard: "adequacy",
    adequacyScope: "data-privacy-framework",
    }),
    },
    });
    • Article 45(1) lets a decision cover “one or more specified sectors” of a country, and these two cover recipients, not the country: the Data Privacy Framework decision covers transfers to organisations on its list alone, and the Canadian one recipients subject to PIPEDA alone. Outside that scope there is no adequacy decision for the transfer, which article 44 then allows only on an appropriate safeguard of article 46, such as standard contractual clauses, with the transfer impact assessment they come with. adequacy alone in these countries asserts a fact about the provider that Bounda cannot see, so the types and the app ask you to state it, under articles 5(2) and 24, rather than read it into a country name.
    • The types take adequacyScope only beside "adequacy" in one of these locations, and only that location’s scope. The app refuses to start, with a ConfigurationError that names the decision and its condition, on "adequacy" there without it or with another country’s, and on an adequacyScope anywhere else.
    • Bounda does not look the provider up: being on the list, and staying on it (a Data Privacy Framework certification is renewed every year), is yours to verify while the transfer lasts. The record of processing names, next to the transfer, the decision and what to verify, so a review of the record asks it again; each person’s export and a tenant’s export give partialAdequacy, the decision of PARTIAL_ADEQUACY, on every such transfer, and null on any other.
    • The Commission’s list writes these scopes after the two names, and the weekly check fails when they change, as when a decision becomes one for the whole country.
    • role, default "all". What app.start() runs in this process: "all" and "worker" run the dispatcher and the scheduled-command worker, "web" runs neither. See roles.
    • commands.timeout, default "30s". How long one run of a command handler may take. Past it the dispatch rejects with HANDLER_TIMEOUT, the handler’s signal aborts and nothing it returns is stored. Loading the aggregate and storing its events do not count.
    • commands.concurrencyRetries, default 3. How many times a command runs again when its append finds the stream moved, before a ConcurrencyError reaches the caller. Each run gets its own timeout.
    • commands.idempotencyKeyLifetime, default "24h". How long a command dispatched with an idempotencyKey is remembered, so a dispatch with the same key answers the same. Past it the key is free again, and the scheduled-command worker purges the record. See idempotent commands.
    • policies.timeout, default "30s". How long one run of a policy handler may take. Past it the run is abandoned: its commands still running stop, later ones are refused with REACTION_ABANDONED, and its signal aborts.
    • policies.retry, default exponential, 3 attempts, 1 s to 30 s. How a failed policy run, or a failed command scheduled with delay, is retried. Under overrides, a policy run takes the setting of the aggregate the policy belongs to, and a scheduled command that of the aggregate it is for. See retry.
    • policies.maxChainDepth, default 25. How many hops a chain of reactions may take from the command that started it before a command is refused with CHAIN_DEPTH_EXCEEDED. Reaching it usually means two policies answer each other.
    • processes.timeout, default "7d". How long a process stays open before at-timeout.ts runs, for a process whose config declares no timeout.
    • processes.handlerTimeout, default "30s". How long one run of a process handler, for an event or a deadline, may take. Past it the run is abandoned, as a policy’s is.
    • processes.retry, default the same as policies.retry’s, not what policies.retry is set to. How a failed process step or deadline is retried.

    Each time limit also decides how long a claim lasts, so how soon another instance runs again what a stopped one left: see delivery guarantees.

    • dispatcher.pollInterval, default "100ms". How long the dispatcher waits between passes when it polls, and the pace of the scheduled-command worker, whose pass reads when the next command is due and claims only once one is.
    • dispatcher.idleInterval, default "30s". With an adapter that pushes notifications (PostgreSQL), how long an idle dispatcher waits for one before polling anyway. Ignored without notifications.
    • dispatcher.batchSize, default 100. Events read per subscriber per pass.
    • dispatcher.projectionBatchTime, default "250ms". How long a projection batch keeps its transaction open before it commits what it has and leaves the rest for the next one. Rebuilds honour it.
    • dispatcher.backoff.baseDelay, .maxDelay, default "1s", "30s". How long background passes leave a subscriber alone after a failed batch: baseDelay after the first failure, doubling up to maxDelay. A batch that goes through resets it. See a projection that keeps failing.
    • dispatcher.catchUp.timeout, .pollInterval, default "2s", "15ms". How long catchUpReadModels({ through }), and read-your-writes with it, waits for the read models a command changed, and how often it looks while another process holds them. Past timeout it logs a warning and the request reads what is there.
    • personalData.retention, none by default. How long, a duration or whole calendar months or years such as "6y", a person may go without an event of the app’s aggregates naming them before the runtime forgets them, as forget does, with reason: "retention", every category but those an erasure exemption keeps: the retention of the default category. Each category app/personal-data.ts declares has its own retention besides, see categories. Without either, nobody is forgotten for inactivity and nothing is recorded for it. A person with any restriction is left alone until it is lifted; one active again after being forgotten starts a new clock. Turning it on applies it to the history: whoever was already inactive for that long is forgotten in the first passes. It is app-wide and has no override per aggregate: a person’s events span aggregates, so their inactivity is one clock, not one per aggregate. See retention.
    • personalData.keyWrapper, required when the registry marks a field personal, except over memory(). Wraps the tenant’s key, which wraps every person’s key and the database’s in turn, so no copy opens a personal field without the master key: masterKey({ from: "BOUNDA_MASTER_KEY", previous: [...] }) names the environment variables that hold the current master key and the ones used before, 32 random bytes in base64 each (openssl rand -base64 32), read from the host’s environment when the app starts; a variable missing or malformed fails the start with ConfigurationError. A KMS or a vault is given through defineKeyWrapper. Both take a location, where the host or the KMS keeps the master key, which a storage that declares one requires to be the same. Versions of the tenant’s key wrapped under a previous master key are rewrapped by the worker in the background. memory() brings a master key of its own, gone with the process. See where the keys live.
    • personalData.tenantKeys, required with keyWrapper, except over memory(). Where the tenant’s key lives, apart from the storage’s database: an adapter pointed at another database, such as sqlite({ path: "./keys/tenant-keys.db" }) or postgresql({ url: TENANT_KEYS_URL }), a store from defineTenantKeyStore, or on Cloudflare durableObjectTenantKeys({ storage }), in the app’s jurisdiction, or kvTenantKeys({ binding }), for an app that names none. An adapter that points at the storage’s own database fails the start, and so, under a storage that declares a location, does a store that declares none, or another without a safeguard: defineTenantKeyStore(create, { location, safeguard }) declares one’s. forgetTenant destroys the key there, and the copies a move left in stores the configuration no longer names (see moving a tenant’s key). See the tenant key store.
    • personalData.forgetLedger, none by default. Where every forgetting is recorded outside the database, before it commits, by person’s id, event id, time, reason and the fingerprints of the keys it destroys, and how the app reconciles with it. Without it, a restored backup brings back everyone forgotten after it was taken. See backups. It holds:
      • store, required. The ledger: an adapter pointed at another database than storage, such as sqlite({ path: "./ledger/forget-ledger.db" }) or postgresql({ url }), which creates its bounda_forget_ledger table there on first use, with bounda_forget_ledger_marks for the mark that tells a restore made while the app was stopped and bounda_forget_ledger_fence for each tenant’s fence; durableObjectForgetLedger({ storage }) or, for an app that names no jurisdiction, kvForgetLedger({ binding }) from @bounda-dev/cloudflare on Cloudflare; or a ledger of your own through defineForgetLedger, whose location option declares where it keeps its entries, as the record of processing states it and a storage that declares a location requires. Every forgetting writes its intention to it before it commits, and the runtime copies every PersonalDataForgotten to it again from the stream in the background. An adapter pointing at the storage’s own database fails the start.
      • reconcileEvery, 5m by default (DEFAULT_FORGET_LEDGER_RECONCILE_EVERY_MS in @bounda-dev/core/config). The app reads the ledger when it starts and, while it runs, again this often, one instance a round, and commits again, under its own id, time and reason, each forgetting the database does not hold whose person still holds a key it names: one a restored backup rolled back, or one whose commit never happened; a restore the instances find reconciles at once. A Durable Object only runs a round on the passes it wakes for anyway; it reconciles on every start.
      • strict, false by default. When false, a forgetting whose intention the ledger does not take is logged and commits all the same, for the stream to copy later, but for one the ledger’s fence refuses, the tenant frozen or forgotten, which fails either way, and a ledger that cannot be read at start, or a reconciliation longer than timeout, does not fail it: the app logs an error and reconciles in the background, and getLag() reports forgetLedger: { reconciled: false } meanwhile. When true, nothing is forgotten that the ledger has not recorded: a forgetting whose intention it does not take fails with FORGET_LEDGER_UNAVAILABLE and forgets nobody, so trying again is safe; and the start waits for the reconciliation however long it takes, and a ledger it cannot read fails it with FORGET_LEDGER_UNRECONCILED. bounda forgotten needs neither, since it reads the event store alone.
      • keepFor, none by default. How long an entry is kept after the forgetting; set it longer than the oldest backup you can restore. The instance that runs a periodic round prunes the older entries after it, so a SQL ledger is pruned only while an app of the tenant runs; KV expires each key on its own, and bounda forget-ledger expire gives the keys written before keepFor was set theirs. Without it entries are kept until their tenant is forgotten and every recipient of its data told, which clears a tenant’s entries whatever keepFor says.
      • timeout, 10s by default (DEFAULT_FORGET_LEDGER_TIMEOUT_MS in @bounda-dev/core/config). How long each call to the ledger may take before it is given up with FORGET_LEDGER_TIMEOUT, and how long a start that is not strict waits for the reconciliation.
    • deadLetters.retention, 30d by default (DEFAULT_DEAD_LETTER_RETENTION_MS in @bounda-dev/core/config). How long a dead letter is kept once it was retried or discarded. Past it, the scheduled-command worker removes it, its error text and payload with it; a failed letter is never removed. A letter that names a person whose processing is restricted stays until the restriction is lifted, unless what it holds of them no longer opens, their key gone, since nothing of theirs is left in it to keep. A process instance whose letter was discarded stays given up after the letter is gone. It is app-wide. See keeping resolved letters.
    • subscriberFailures.retention, 30d by default (DEFAULT_SUBSCRIBER_FAILURE_RETENTION_MS in @bounda-dev/core/config). How long the last failure of a subscriber is kept once the subscriber got past it, or, for a subscriber the app no longer runs, once it last failed on it. Past it, the scheduled-command worker removes it, its error text with it; a failure a subscriber is still stuck on stays. A failure whose text is sealed under a person whose processing is restricted stays until the restriction is lifted, unless the text no longer opens, its person forgotten, since nothing of theirs is left in it to keep. It is app-wide. See error text.
    • telemetry.errorText, "omit" by default. Whether the runtime’s log lines and spans carry the text of an error. With "omit" they carry its class and its code alone: the message of an error a handler throws may quote personal data it read, and logs and traces keep it in the clear, where forget never reaches. Errors whose message Bounda writes from names and ids alone, such as ConcurrencyError or a dead letter not found, keep it. "include" adds the message and the stack of every error, for development; createTestApp and the dev server of @bounda-dev/react-router default to it, and bounda --error-text turns it on for one command. The environment variable BOUNDA_ERROR_TEXT overrides it, as .dev.vars does in development on Cloudflare. See error text.
    • overrides, default {}. Settings for one aggregate, by aggregate name: commands.timeout, policies and processes with the keys above, and snapshot. What an override leaves out comes from the app’s settings.
    • overrides.<aggregate>.snapshot, none by default. Opts the aggregate into snapshots of its state, written in the background and loaded from instead of the stream’s first event:
      • every, required. A stream is snapshotted each time its version reaches a multiple of every.
      • verify, default 0.01. The share of the loads from a snapshot, 0 to 1, checked against a fold of the whole stream. A snapshot that folds to another state is logged, dropped and not used. An app from createTestApp checks every load and throws SnapshotError instead.
      • version, default 1. Part of what a snapshot is valid for, next to the stateFingerprint the generator computes from the modules that shape the state. Raise it to retire every snapshot of the aggregate when the fold changed through something the fingerprint cannot see, such as a package or a module behind a path alias.

    A process can set its own lifetime in its config, ({ events }) => ({ startedBy: [...], timeout: "48h" }), which wins over processes.timeout and over an override.

    policies.retry and processes.retry take the same shape. strategy is required whenever retry is given; the other keys fall back to the defaults.

    Key Default What it does
    strategy "exponential" "none" gives up on the first failure; "fixed" waits baseDelay each time; "linear" waits baseDelay times the retry number; "exponential" doubles baseDelay with each retry.
    maxAttempts 3 Runs in all, the first one included, before the failure becomes a dead letter.
    baseDelay "1s" The first wait.
    maxDelay "30s" No wait is longer than this.

    Only failures that may pass are retried. A rejection is an answer, not a failure; a payload that does not validate, a missing module, a broken configuration, a chain that went too deep or events that do not fit the aggregate (VALIDATION_FAILED, NOT_FOUND, INVALID_CONFIGURATION, CHAIN_DEPTH_EXCEEDED, CREATION_ORDER) become a dead letter at once, since they would fail the same way again. See errors.

    TypeScript
    runtime: {
    policies: { retry: { strategy: "exponential", maxAttempts: 5, maxDelay: "2m" } },
    overrides: {
    // a policy whose command can never succeed on a second try; the commands scheduled for
    // `order` are not retried either
    order: { policies: { retry: { strategy: "none" } } },
    },
    },
    • React Router: the bounda() Vite plugin takes consistency and debounceMs; see its options.
    • Cloudflare: createBoundaObject takes passesPerAlarm, createWorker takes tenantOf and consistency, and connect takes consistency; see the Cloudflare adapter. With React Router, app/tenant.ts names the tenant; see on Cloudflare.
    • Tests: createTestApp takes its own ports and config; see testing.