Skip to content

tenant-settings

Per-tenant Currency + Locale defaults, exposed as two config keys (tenant-settings:config:currency, tenant-settings:config:locale) that surface in the self-populating Settings-Hub via mask. Pair with defineCreateWithTenantDefaults to auto-fill a money field’s currency or a locale field on create instead of hard-coding a literal per entity.

From recipes-tenant-settings — the smallest working mount:

// Consuming tenant-settings: an `invoice` entity whose `amount` (money) and
// `language` (locale) are auto-filled from the tenant's currency/locale
// setting when the caller omits them — instead of hard-coding "EUR"/"en" on
// the field, the mistake this recipe exists to prevent (solon#P19).
import { defineCreateWithTenantDefaults } from "@cosmicdrift/kumiko-bundled-features/tenant-settings";
import {
createEntity,
createMoneyField,
createSelectField,
createTextField,
defineFeature,
} from "@cosmicdrift/kumiko-framework/engine";
export const invoiceEntity = createEntity({
table: "read_invoices",
fields: {
title: createTextField({ personal: false, reason: "is_business_data", required: true }),
amount: createMoneyField({ required: true }),
language: createSelectField({ options: ["en", "de", "fr"] as const }),
},
});
const ACCESS = { roles: ["Admin"] } as const;
export const invoiceFeature = defineFeature("invoice", (r) => {
r.entity({ name: "invoice", ...invoiceEntity });
r.writeHandler(
defineCreateWithTenantDefaults("invoice", invoiceEntity, {
access: ACCESS,
currencyFields: ["amount"],
localeField: "language",
}),
);
});

📄 On GitHub: samples/recipes/tenant-settings/src/feature.ts

tenant-settings feature preview

What this feature needs to run (Requires).

flowchart TB
  n_tenant_settings["tenant-settings"]
  subgraph how_reqs["Requires"]
    n_config["config"]
  end
  n_config --> n_tenant_settings

Start with recipes-tenant-settings for a step-by-step walkthrough with runnable code and integration tests.

  • Requires: config
  • Activation: always on (not toggleable)

Per-tenant config keys, set via the tenant-admin UI or a seed. 🔒 = encrypted at rest.

KeyTypeDefaultScopeWho can writeWho can read
currencyselect (EUR | USD | GBP | CHF | JPY | SEK | NOK | DKK | PLN | CZK | CAD | AUD | NZD | CNY | INR)EURtenantTenantAdmin, Admin, SystemAdminall
localeselect (de | en | es)entenantTenantAdmin, Admin, SystemAdminall