@krizaka/settings

中文文档
0.6.0发布于 2026/11/01Apache-2.0TypeScriptES Module构建来源已验证

A Krizaka product's configuration as data: a typed registry (flags, integers, choices, subsets, bilingual texts), resolved user over workspace over global over default, changed by an administrator with an audit line for every change, the price catalogue (

原始使用文档

@krizaka/settings

A product's configuration as data: a typed registry of settings (flags, integers, choices, subsets, bilingual texts), resolved user → workspace → global → default, changed by an administrator without a redeploy, every change leaving an audit line (who, what, when, before, after). A JSON-safe description of the registry is what an admin screen draws from.

import { emitMigration } from "@krizaka/db";
import { defineSettings, flag, integer, dbSettings, settingsSchema, GLOBAL, WORKSPACE_SCOPES } from "@krizaka/settings";

const settings = defineSettings({ "features.apiKeys": flag("features", true, WORKSPACE_SCOPES), "limits.maxFileMb": integer("limits", 10, { min: 1, max: 10, unit: "MB" }) } as const);
emitMigration(settingsSchema, 1, { tables: {} }); // commit the SQL once, in your migrations (idempotent)
const service = dbSettings(settings, { query, workspaceOf, clock: () => performance.now() });
await service.get("features.apiKeys", { userId });            // typed: boolean
await service.set({ id: adminId, label: email }, GLOBAL, "features.apiKeys", false, now);

Schema. The tables are a @krizaka/db module (settings), version 1 byte-identical to the SQL this package shipped before, so a product that has them adopts with no DDL change: adoptMigration(settingsSchema, 1, context) writes the marker only, emitMigration(…) writes the SQL for a database that lacks them. The old migration function stays, @deprecated, for one minor. The price versions are the module settings_prices (pricesSchema). What stays in the product: its registry (the keys, groups, defaults), the checks it makes at its own boundary (« the server refuses what is off »), who may be an administrator, the HTTP routes. The clock is passed in; nothing here reads it.

Prices — the catalogue (ADR-009)

A product's prices are data too: a typed catalogue of entries (product.plan, unit, amount in cents or « on quote », CAD, before taxes, availability public · internal · founder-limited · preparing, named limits). The product's former pricing module becomes the seed; its administrator changes an entry by scheduling a version from a date (now or later, never the past), and every change writes an audit line in settings_audit (price.<product>.<plan>). A subscription records the version it was sold at (versionId) and keeps it.

import { AVAILABILITY, definePrices, findTypedPrices, priceCatalogue, pricesMigration, priceStore, publicCatalogue, UNIT } from "@krizaka/settings";

const prices = definePrices([
  { product: "akinaza", plan: "starter", unit: UNIT.month, amountCents: 4500, availability: AVAILABILITY.founderLimited, limits: { founderCap: 20 } },
  { product: "akinaza", plan: "scale", unit: UNIT.month, amountCents: 9900, availability: AVAILABILITY.preparing },
]);
await db.query(pricesMigration()); // once, in your migrations (idempotent; includes the settings' tables)
const catalogue = priceCatalogue(prices, priceStore({ query }));
const shown = publicCatalogue(await catalogue.catalogue(now));   // a public page: never internal, « en préparation » without a figure
await catalogue.schedule({ id: adminId, label: email }, "akinaza.starter", { amountCents: 4900 }, effectiveFrom, now);
const sold = await catalogue.version(subscription.priceVersionId); // the price it was sold at, forever
expect(findTypedPrices(messages)).toEqual([]);                    // a product's test: no amount typed in a message

describePrices(catalogue, now) is the JSON-safe description an admin screen draws (with what is already scheduled); memoryPriceStore() serves tests. The amount reaches the processor through @krizaka/payments, by the entry's key.

postgresSettings was the first name of dbSettings; it stays as a @deprecated alias for one minor and leaves in the next major.

版本与发布记录

@krizaka/settings 共发布 9 个版本,首次发布于 2026/10/23;过去 12 个月发布了 9 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.6.0latest2026/11/011 天前
0.5.22026/10/304 天前
0.5.12026/10/295 天前
0.5.02026/10/277 天前
0.4.02026/10/277 天前
0.3.02026/10/268 天前

关于 @krizaka/settings 的常见问题

@krizaka/settings 是什么?

Krizaka产品的配置作为数据:类型化注册表(标志、整数、选项、子集、双语文本)、解析用户/工作空间/全局/默认、由管理员对每次更改进行审计行更改、价格目录(

如何安装 @krizaka/settings?

在项目目录运行 npm install @krizaka/settings,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:zod(>=3.23)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@krizaka/settings 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@krizaka/settings 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@krizaka/settings 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@krizaka/settings 可以商用吗?

@krizaka/settings 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@krizaka/settings 还在维护吗?

最新版本 0.6.0 发布于 2026/11/01(1 天前);至今共发布 9 个版本,其中过去 12 个月发布了 9 个;首次发布于 2026/10/23。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。