跳到主要内容

std/billing

std/billing

导入自 @norbital-ai/std/billing

repository-health:allow SEM_PARALLEL -- index is the barrel over rate-card and schemas; the public surface, not a second implementation.

AI_METERED_PRICES const

const AI_METERED_PRICES: readonly [{ readonly id: "ai-provider-cost-micros-monthly"; readonly name: "AI usage"; readonly description: "Provider-reported request cost converted from USD to micro-SGD at the published billing rate, which loads provider credit fees, FX, payment processing and margin onto the conversion. Token counts and model remain attached to every event for audit."; readonly model: "metered"; readonly meterId: "bolt_ai_cost_sgd_micros_v1"; readonly stripePriceIds: { readonly sandbox: "price_1Ty8XqLvWjJB44nUyTvOAuYp"; readonly production: "price_1TyCvvLlQVSVzCBMS9rUyU0V"; }; readonly unitAmountDecimal:…

The metered AI usage price: provider cost converted to micro-SGD at the published rate.

源码: packages/std/src/billing/index.ts:122

AI_SGD_PER_PROVIDER_USD const

const AI_SGD_PER_PROVIDER_USD: 2.6

SGD charged per US dollar of provider spend.

AI is not priced from a token table of our own. The provider reports what a call cost and that figure is converted with this rate, so the meter tracks provider pricing directly and moves with it instead of needing a re-audit every time a model's price changes.

The rate is a loaded one, not a currency conversion. Spot USD/SGD is well under half of it; the rest is deliberate cover for everything between what a provider charges us and what reaches the bank — the fee on buying provider credit, FX spread on top of spot, card and payout fees on the tenant's invoice, and a margin over all of it. Every one of those moves on somebody else's schedule, so the cover is set generously rather than tracked.

It stays one number and not a chain of multipliers. A factored form lived here, evaluated to 1.55, and was called by nothing while the meter that reaches Stripe charged 2.60 — two answers to the same question, the uninvoiced one looking every bit as authoritative. A split that is not itself billed is documentation, and documentation belongs in this comment rather than in arithmetic that can drift away from the price.

源码: packages/std/src/billing/rate-card.ts:45

AI_USAGE_METER_ID const

const AI_USAGE_METER_ID: "bolt_ai_cost_sgd_micros_v1"

The meter AI usage is reported to, in micro-SGD of converted provider cost.

源码: packages/std/src/billing/index.ts:25

BILLING_ACCESS_TIERS const

const BILLING_ACCESS_TIERS: readonly ["standard", "builder"]

The workspace access tiers.

源码: packages/std/src/billing/rate-card.ts:8

BILLING_CURRENCY const

const BILLING_CURRENCY: "SGD"

The currency every price and invoice is stated in.

源码: packages/std/src/billing/rate-card.ts:2

BILLING_RATE_CARD_VERSION const

const BILLING_RATE_CARD_VERSION: "2026-08-18"

The date the current rate card took effect.

源码: packages/std/src/billing/rate-card.ts:5

BillingAccessTier type

type BillingAccessTier = (typeof BILLING_ACCESS_TIERS)[number];

A workspace access tier: standard or builder.

源码: packages/std/src/billing/rate-card.ts:10

BillingCatalogue type

type BillingCatalogue = Schema.Schema.Type<typeof BillingCatalogueSchema>;

The billing catalogue: its currency and products.

成员

名称类型说明
currencySchema.Literal<"SGD">
productsSchema.$Array<Schema.Struct<{ readonly id: Schema.String; readonly name: Schema.String; readonly description: Schema.String; readonly prices: Schema.$Array<Schema.Struct<{ readonly id: Schema.String; readonly name: Schema.String; readonly description: Schema.String; readonly model: Schema.Literals<readonly ["flat", "per_seat", "metered"]>; readonly interval: Schema.Literals<readonly ["month", "ye…

源码: packages/std/src/billing/schemas.ts:97

BillingCatalogueInterval type

type BillingCatalogueInterval = Schema.Schema.Type<typeof BillingCatalogueIntervalSchema>;

A price's billing interval: month or year.

源码: packages/std/src/billing/schemas.ts:11

BillingCatalogueIntervalSchema const

const BillingCatalogueIntervalSchema: Schema.Literals<readonly ["month", "year"]>

The Stripe catalogue surfaces (plans, prices, products) are declared here without a transport dependency, with the shape owned once by these schemas — a host that pushes the catalogue to Stripe decodes from the same source of truth the type is derived from.

源码: packages/std/src/billing/schemas.ts:9

BillingCataloguePlan type

type BillingCataloguePlan = Schema.Schema.Type<typeof BillingCataloguePlanSchema>;

A plan: the base subscription's id, trial days and whether promotion codes are allowed.

成员

名称类型说明
idSchema.String
trialDaysSchema.Number
allowPromotionCodesSchema.Boolean

源码: packages/std/src/billing/schemas.ts:78

BillingCataloguePlanSchema const

const BillingCataloguePlanSchema: Schema.Struct<{ readonly id: Schema.String; readonly trialDays: Schema.Number; readonly allowPromotionCodes: Schema.Boolean; }>

A plan is the base subscription: a flat fee plus the metered prices in the same product. The paywall checkout subscribes the plan plus every metered price as separate subscription items, so what a plan names is the trial, not seat licensing. There is no seat model: the base fee is stated once per workspace, whatever the headcount.

源码: packages/std/src/billing/schemas.ts:72

BillingCataloguePrice type

type BillingCataloguePrice = Schema.Schema.Type<typeof BillingCataloguePriceSchema>;

One catalogue price: its model and interval, whether checkout subscribes it, its Stripe ids, and a flat amount or a metered unit amount and meter.

成员

名称类型说明
idSchema.String
nameSchema.String
modelSchema.Literals<readonly ["flat", "per_seat", "metered"]>
descriptionSchema.String
intervalSchema.Literals<readonly ["month", "year"]>
checkoutSchema.Boolean
stripePriceIdsSchema.Struct<{ readonly sandbox: Schema.NullishOr<Schema.String>; readonly production: Schema.NullishOr<Schema.String>; }>
amount?Schema.optional<Schema.String>
unitAmountDecimal?Schema.optional<Schema.String>
meterId?Schema.optional<Schema.String>
dimensions?Schema.optional<Schema.$Record<Schema.String, Schema.String>>
tiersMode?Schema.optional<Schema.Literals<readonly ["graduated", "volume"]>>
tiers?Schema.optional<Schema.$Array<Schema.Struct<{ readonly upTo: Schema.Union<readonly [Schema.Number, Schema.Literal<"inf">]>; readonly amount: Schema.String; }>>>

源码: packages/std/src/billing/schemas.ts:64

BillingCataloguePriceModel type

type BillingCataloguePriceModel = Schema.Schema.Type<typeof BillingCataloguePriceModelSchema>;

A price's model: flat, per_seat or metered.

源码: packages/std/src/billing/schemas.ts:16

BillingCataloguePriceModelSchema const

const BillingCataloguePriceModelSchema: Schema.Literals<readonly ["flat", "per_seat", "metered"]>

The schema of a price's model: flat, per_seat or metered.

源码: packages/std/src/billing/schemas.ts:14

BillingCataloguePriceSchema const

const BillingCataloguePriceSchema: Schema.Struct<{ readonly id: Schema.String; readonly name: Schema.String; readonly description: Schema.String; readonly model: Schema.Literals<readonly ["flat", "per_seat", "metered"]>; readonly interval: Schema.Literals<readonly ["month", "year"]>; readonly checkout: Schema.Boolean; readonly stripePriceIds: Schema.Struct<{ readonly sandbox: Schema.NullishOr<Schema.String>; readonly production: Schema.NullishOr<Schema.String>; }>; readonly amount: Schema.optional<Schema.String>; readonly unitAmountDecimal: Schema.optional<Schema.String>; readonly meterId: Schema.optional<Schema.String>; reado…

The schema of one catalogue price; hosts decode a catalogue with it before pushing it to Stripe.

源码: packages/std/src/billing/schemas.ts:46

BillingCatalogueProduct type

type BillingCatalogueProduct = Schema.Schema.Type<typeof BillingCatalogueProductSchema>;

A catalogue product: its name and description, prices and plans.

成员

名称类型说明
idSchema.String
nameSchema.String
descriptionSchema.String
pricesSchema.$Array<Schema.Struct<{ readonly id: Schema.String; readonly name: Schema.String; readonly description: Schema.String; readonly model: Schema.Literals<readonly ["flat", "per_seat", "metered"]>; readonly interval: Schema.Literals<readonly ["month", "year"]>; readonly checkout: Schema.Boolean; readonly stripePriceIds: Schema.Struct<{ readonly sandbox: Schema.NullishOr<Schema.String>; readonly…
plansSchema.$Array<Schema.Struct<{ readonly id: Schema.String; readonly trialDays: Schema.Number; readonly allowPromotionCodes: Schema.Boolean; }>>

源码: packages/std/src/billing/schemas.ts:89

BillingCatalogueProductSchema const

const BillingCatalogueProductSchema: Schema.Struct<{ readonly id: Schema.String; readonly name: Schema.String; readonly description: Schema.String; readonly prices: Schema.$Array<Schema.Struct<{ readonly id: Schema.String; readonly name: Schema.String; readonly description: Schema.String; readonly model: Schema.Literals<readonly ["flat", "per_seat", "metered"]>; readonly interval: Schema.Literals<readonly ["month", "year"]>; readonly checkout: Schema.Boolean; readonly stripePriceIds: Schema.Struct<{ readonly sandbox: Schema.NullishOr<Schema.String>; readonly production: Schema.NullishOr<Schema.String>; }>; readonly amount: Schem…

The schema of a catalogue product: its prices and plans.

源码: packages/std/src/billing/schemas.ts:81

BillingCatalogueProviderPriceIds type

type BillingCatalogueProviderPriceIds = Schema.Schema.Type<typeof BillingCatalogueProviderPriceIdsSchema>;

A price's Stripe price id in the sandbox and in production (null where not created).

成员

名称类型说明
sandboxSchema.NullishOr<Schema.String>
productionSchema.NullishOr<Schema.String>

源码: packages/std/src/billing/schemas.ts:41

BillingCatalogueProviderPriceIdsSchema const

const BillingCatalogueProviderPriceIdsSchema: Schema.Struct<{ readonly sandbox: Schema.NullishOr<Schema.String>; readonly production: Schema.NullishOr<Schema.String>; }>

The schema of a price's Stripe ids per environment.

源码: packages/std/src/billing/schemas.ts:36

BillingCatalogueSchema const

const BillingCatalogueSchema: Schema.Struct<{ readonly currency: Schema.Literal<"SGD">; readonly products: Schema.$Array<Schema.Struct<{ readonly id: Schema.String; readonly name: Schema.String; readonly description: Schema.String; readonly prices: Schema.$Array<Schema.Struct<{ readonly id: Schema.String; readonly name: Schema.String; readonly description: Schema.String; readonly model: Schema.Literals<readonly ["flat", "per_seat", "metered"]>; readonly interval: Schema.Literals<readonly ["month", "year"]>; readonly checkout: Schema.Boolean; readonly stripePriceIds: Schema.Struct<{ readonly sandbox: Schema.NullishOr<Schem…

The schema of the whole billing catalogue.

源码: packages/std/src/billing/schemas.ts:92

BillingCatalogueTier type

type BillingCatalogueTier = Schema.Schema.Type<typeof BillingCatalogueTierSchema>;

One price tier: the quantity it runs upTo (or inf) and its amount.

成员

名称类型说明
upToSchema.Union<readonly [Schema.Number, Schema.Literal<"inf">]>
amountSchema.String

源码: packages/std/src/billing/schemas.ts:26

BillingCatalogueTierSchema const

const BillingCatalogueTierSchema: Schema.Struct<{ readonly upTo: Schema.Union<readonly [Schema.Number, Schema.Literal<"inf">]>; readonly amount: Schema.String; }>

The schema of one price tier: the quantity it runs upTo (or inf) and its amount.

源码: packages/std/src/billing/schemas.ts:21

BillingProviderEnvironment type

type BillingProviderEnvironment = Schema.Schema.Type<typeof BillingProviderEnvironmentSchema>;

A billing provider environment: sandbox or production.

源码: packages/std/src/billing/schemas.ts:31

BillingProviderEnvironmentSchema const

const BillingProviderEnvironmentSchema: Schema.Literals<readonly ["sandbox", "production"]>

The schema of a billing provider environment: sandbox or production.

源码: packages/std/src/billing/schemas.ts:29

COMPUTE_SGD_PER_SECOND const

const COMPUTE_SGD_PER_SECOND: 0.0005

Tenant-visible usage prices. Compute is worker-thread event-loop utilization (ELU) active time, billed in seconds. Memory has no separate usage meter or per-worker hard wall; its infrastructure cost is included in the compute price. Disc and files are GB-months converted to GB-hours over a 730-hour month.

源码: packages/std/src/billing/rate-card.ts:18

CURRENCY_MINOR_UNITS_PER_MAJOR_UNIT const

const CURRENCY_MINOR_UNITS_PER_MAJOR_UNIT: 100

Cents per dollar of the billing currency.

源码: packages/std/src/billing/index.ts:20

DEFAULT_BILLING_TRIAL_DAYS const

const DEFAULT_BILLING_TRIAL_DAYS: 30

The trial length of the platform plan, in days.

源码: packages/std/src/billing/index.ts:18

DISC_SGD_PER_GB_MONTH const

const DISC_SGD_PER_GB_MONTH: 3

Tenant database storage price, SGD per GB-month.

源码: packages/std/src/billing/rate-card.ts:20

EXTERNAL_CLOUD_RATE_CARD_USD const

const EXTERNAL_CLOUD_RATE_CARD_USD: { readonly neonComputePerCuHour: 0.106; readonly neonStoragePerGbMonth: 0.35; readonly neonRestorePerGbMonth: 0.2; readonly neonExtraBranchPerHour: 0.002; readonly r2StoragePerGbMonth: 0.015; readonly r2ClassAPerMillion: 4.5; readonly r2ClassBPerMillion: 0.36; }

What the external providers (Neon, R2) charge, in USD, for capacity planning; not a customer price.

成员

名称类型说明
neonComputePerCuHour0.106
neonStoragePerGbMonth0.35
neonRestorePerGbMonth0.2
neonExtraBranchPerHour0.002
r2StoragePerGbMonth0.015
r2ClassAPerMillion4.5
r2ClassBPerMillion0.36

源码: packages/std/src/billing/rate-card.ts:66

FILES_SGD_PER_GB_MONTH const

const FILES_SGD_PER_GB_MONTH: 0.25

Tenant object storage price, SGD per GB-month.

源码: packages/std/src/billing/rate-card.ts:22

HOURS_PER_BILLING_MONTH const

const HOURS_PER_BILLING_MONTH: 730

Hours in a billing month, for converting GB-months to GB-hours.

源码: packages/std/src/billing/rate-card.ts:24

LATEST_CATALOGUE const

const LATEST_CATALOGUE: { readonly currency: "SGD"; readonly products: readonly [{ readonly id: "platform"; readonly name: "Norbital Platform"; readonly description: "A flat base fee per workspace, plus separately metered compute, disc, files, and AI usage."; readonly prices: readonly [{ readonly id: "platform-base-monthly"; readonly name: "Workspace base"; readonly description: "SGD 10.00 per workspace per month, flat \u2014 unchanged by headcount or usage."; readonly model: "flat"; readonly interval: "month"; readonly checkout: true; readonly stripePriceIds: { readonly sandbox: "price_1U97ONLvWjJB44nUrKDVveY3"; re…

The current billing catalogue, as hosts push it to Stripe.

成员

名称类型说明
currency"SGD"
productsreadonly [{ readonly id: "platform"; readonly name: "Norbital Platform"; readonly description: "A flat base fee per workspace, plus separately metered compute, disc, files, and AI usage."; readonly prices: readonly [{ readonly id: "platform-base-monthly"; readonly name: "Workspace base"; readonly description: "SGD 10.00 per workspace per month, flat — unchanged by headcount or usage."; readonly m…

源码: packages/std/src/billing/index.ts:229

LATEST_CATALOGUE_PLANS const

const LATEST_CATALOGUE_PLANS: readonly { readonly id: string; readonly trialDays: number; readonly allowPromotionCodes: boolean; }[]

Every plan of the current catalogue.

源码: packages/std/src/billing/index.ts:225

LATEST_CATALOGUE_PRICES const

const LATEST_CATALOGUE_PRICES: readonly { readonly id: string; readonly name: string; readonly model: "flat" | "metered" | "per_seat"; readonly description: string; readonly interval: "month" | "year"; readonly checkout: boolean; readonly stripePriceIds: { readonly sandbox: string | null | undefined; readonly production: string | null | undefined; }; readonly amount?: string | undefined; readonly unitAmountDecimal?: string | undefined; readonly meterId?: string | undefined; readonly dimensions?: { readonly [x: string]: string; } | undefined; readonly tiersMode?: "graduated" | "volume" | undefined; readonly tiers?: readonly…

Every price of the current catalogue.

源码: packages/std/src/billing/index.ts:207

LATEST_CATALOGUE_PRODUCTS const

const LATEST_CATALOGUE_PRODUCTS: readonly [{ readonly id: "platform"; readonly name: "Norbital Platform"; readonly description: "A flat base fee per workspace, plus separately metered compute, disc, files, and AI usage."; readonly prices: readonly [{ readonly id: "platform-base-monthly"; readonly name: "Workspace base"; readonly description: "SGD 10.00 per workspace per month, flat \u2014 unchanged by headcount or usage."; readonly model: "flat"; readonly interval: "month"; readonly checkout: true; readonly stripePriceIds: { readonly sandbox: "price_1U97ONLvWjJB44nUrKDVveY3"; readonly production: null; }; readonly amount: "1…

The current catalogue's products: the platform product with its flat base fee and its compute, disc, files and AI meters.

源码: packages/std/src/billing/index.ts:143

LOCAL_CLOUD_RATE_CARD const

const LOCAL_CLOUD_RATE_CARD: { readonly serverMonthlyCostSgd: 149.99; readonly hoursPerMonth: 730; readonly cpuCores: 6; readonly ramGb: 32; readonly diskGb: 894; readonly allocation: { readonly cpu: 0.4; readonly ram: 0.35; readonly disk: 0.25; }; }

Local bare-metal cost allocation, kept for capacity planning. It is not a customer-facing meter split: the compute price includes RAM cost, while measured usage remains worker-thread ELU active time.

成员

名称类型说明
serverMonthlyCostSgd149.99
hoursPerMonth730
cpuCores6
ramGb32
diskGb894
allocation{ readonly cpu: 0.4; readonly ram: 0.35; readonly disk: 0.25; }

源码: packages/std/src/billing/rate-card.ts:52

PLATFORM_BASE_SGD_PER_MONTH const

const PLATFORM_BASE_SGD_PER_MONTH: number

The flat base fee in major units — the catalogue amount, not a second literal beside it.

源码: packages/std/src/billing/index.ts:119

PLATFORM_FLAT_PRICES const

const PLATFORM_FLAT_PRICES: readonly [{ readonly id: "platform-base-monthly"; readonly name: "Workspace base"; readonly description: "SGD 10.00 per workspace per month, flat \u2014 unchanged by headcount or usage."; readonly model: "flat"; readonly interval: "month"; readonly checkout: true; readonly stripePriceIds: { readonly sandbox: "price_1U97ONLvWjJB44nUrKDVveY3"; readonly production: null; }; readonly amount: "10.00"; }]

The flat platform fee, per workspace, per month, as a real Stripe price. Checkout subscribes it as line_items[0] with the metered prices after it, so the base is invoiced on the same subscription as the usage it gates. amount is major units, the figure the pricing page reads.

源码: packages/std/src/billing/index.ts:102

PLATFORM_PRODUCT_ID const

const PLATFORM_PRODUCT_ID: "platform"

The id of the platform product and of its one plan in the catalogue.

源码: packages/std/src/billing/index.ts:22

USAGE_METER_IDS const

const USAGE_METER_IDS: { readonly compute: "bolt_compute_seconds_v1"; readonly disc: "bolt_disc_gb_hours_v1"; readonly files: "bolt_files_gb_hours_v1"; readonly ai: "bolt_ai_cost_sgd_micros_v1"; }

The meter id of each metered usage: compute, disc, files and AI.

成员

名称类型说明
compute"bolt_compute_seconds_v1"
disc"bolt_disc_gb_hours_v1"
files"bolt_files_gb_hours_v1"
ai"bolt_ai_cost_sgd_micros_v1"

源码: packages/std/src/billing/index.ts:48

USAGE_METER_UNITS const

const USAGE_METER_UNITS: { readonly compute: "millisecond"; readonly disc: "micro-GB-hour"; readonly files: "micro-GB-hour"; readonly ai: "micro-SGD"; }

The unit each meter counts in (milliseconds, micro-GB-hours, micro-SGD).

成员

名称类型说明
compute"millisecond"
disc"micro-GB-hour"
files"micro-GB-hour"
ai"micro-SGD"

源码: packages/std/src/billing/index.ts:56

aiProviderCostSgdMicros function

function aiProviderCostSgdMicros(providerCostUsd: number): number

What a tenant owes for one turn, in micro-SGD, given what the provider charged for it in USD.

The single conversion for AI spend: the ledger prices an observation with it, the Stripe meter reports the quantity it returns, and the agent panel shows a conversation's total through it.

参数

名称类型说明
providerCostUsdnumber

源码: packages/std/src/billing/index.ts:69

calculateCatalogueMeterCostSgdMicros function

function calculateCatalogueMeterCostSgdMicros(meterId: string, quantity: number): number

The cost in micro-SGD of quantity units of a meter at the current catalogue's unit price; throws on a negative or fractional quantity or an unknown meter.

参数

名称类型说明
meterIdstring
quantitynumber

源码: packages/std/src/billing/index.ts:213

formatBillingAmountFromMinorUnits function

function formatBillingAmountFromMinorUnits(amountMinorUnits: string | number, options?: { minimumFractionDigits?: number; maximumFractionDigits?: number; }): string

An amount in cents as display text in the billing currency.

参数

名称类型说明
amountMinorUnitsstring | number
options?{ minimumFractionDigits?: number; maximumFractionDigits?: number; }

示例

formatBillingAmountFromMinorUnits(1000) // 'SGD 10'

源码: packages/std/src/billing/index.ts:81