@taggor/contract 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +61 -2
- package/dist/.tsbuildinfo +1 -0
- package/dist/artifact-keys.d.ts +169 -0
- package/dist/artifact-keys.d.ts.map +1 -0
- package/dist/artifact-keys.js +195 -0
- package/dist/artifact-keys.js.map +1 -0
- package/dist/assets.d.ts +72 -0
- package/dist/assets.d.ts.map +1 -0
- package/dist/assets.js +94 -0
- package/dist/assets.js.map +1 -0
- package/dist/bounded-path.d.ts +29 -0
- package/dist/bounded-path.d.ts.map +1 -0
- package/dist/bounded-path.js +57 -0
- package/dist/bounded-path.js.map +1 -0
- package/dist/bounded.d.ts +47 -0
- package/dist/bounded.d.ts.map +1 -0
- package/dist/bounded.js +93 -0
- package/dist/bounded.js.map +1 -0
- package/dist/build-diagnostic.d.ts +89 -0
- package/dist/build-diagnostic.d.ts.map +1 -0
- package/dist/build-diagnostic.js +91 -0
- package/dist/build-diagnostic.js.map +1 -0
- package/dist/component-types.d.ts +61 -0
- package/dist/component-types.d.ts.map +1 -0
- package/dist/component-types.js +277 -0
- package/dist/component-types.js.map +1 -0
- package/dist/consent-text.d.ts +31 -0
- package/dist/consent-text.d.ts.map +1 -0
- package/dist/consent-text.js +41 -0
- package/dist/consent-text.js.map +1 -0
- package/dist/contract-version.d.ts +150 -0
- package/dist/contract-version.d.ts.map +1 -0
- package/dist/contract-version.js +198 -0
- package/dist/contract-version.js.map +1 -0
- package/dist/credential-fields.d.ts +31 -0
- package/dist/credential-fields.d.ts.map +1 -0
- package/dist/credential-fields.js +36 -0
- package/dist/credential-fields.js.map +1 -0
- package/dist/css-tokens.d.ts +46 -0
- package/dist/css-tokens.d.ts.map +1 -0
- package/dist/css-tokens.js +189 -0
- package/dist/css-tokens.js.map +1 -0
- package/dist/css-value.d.ts +42 -0
- package/dist/css-value.d.ts.map +1 -0
- package/dist/css-value.js +78 -0
- package/dist/css-value.js.map +1 -0
- package/dist/data-api.d.ts +127 -0
- package/dist/data-api.d.ts.map +1 -0
- package/dist/data-api.js +167 -0
- package/dist/data-api.js.map +1 -0
- package/dist/denylist-keys.d.ts +19 -0
- package/dist/denylist-keys.d.ts.map +1 -0
- package/dist/denylist-keys.js +48 -0
- package/dist/denylist-keys.js.map +1 -0
- package/dist/diagnostic-catalog.d.ts +1402 -0
- package/dist/diagnostic-catalog.d.ts.map +1 -0
- package/dist/diagnostic-catalog.js +1311 -0
- package/dist/diagnostic-catalog.js.map +1 -0
- package/dist/dom-members.snapshot.d.ts +33 -0
- package/dist/dom-members.snapshot.d.ts.map +1 -0
- package/dist/dom-members.snapshot.js +760 -0
- package/dist/dom-members.snapshot.js.map +1 -0
- package/dist/early-loading.d.ts +27 -0
- package/dist/early-loading.d.ts.map +1 -0
- package/dist/early-loading.js +44 -0
- package/dist/early-loading.js.map +1 -0
- package/dist/error-catalog.d.ts +749 -0
- package/dist/error-catalog.d.ts.map +1 -0
- package/dist/error-catalog.js +720 -0
- package/dist/error-catalog.js.map +1 -0
- package/dist/executable-config.d.ts +35 -0
- package/dist/executable-config.d.ts.map +1 -0
- package/dist/executable-config.js +44 -0
- package/dist/executable-config.js.map +1 -0
- package/dist/freeze.d.ts +17 -0
- package/dist/freeze.d.ts.map +1 -0
- package/dist/freeze.js +29 -0
- package/dist/freeze.js.map +1 -0
- package/dist/gunzip.d.ts +33 -0
- package/dist/gunzip.d.ts.map +1 -0
- package/dist/gunzip.js +330 -0
- package/dist/gunzip.js.map +1 -0
- package/dist/hostname.d.ts +74 -0
- package/dist/hostname.d.ts.map +1 -0
- package/dist/hostname.js +215 -0
- package/dist/hostname.js.map +1 -0
- package/dist/human-actions.d.ts +49 -0
- package/dist/human-actions.d.ts.map +1 -0
- package/dist/human-actions.js +272 -0
- package/dist/human-actions.js.map +1 -0
- package/dist/index.d.ts +73 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +73 -0
- package/dist/index.js.map +1 -0
- package/dist/json-schema.d.ts +108 -0
- package/dist/json-schema.d.ts.map +1 -0
- package/dist/json-schema.js +240 -0
- package/dist/json-schema.js.map +1 -0
- package/dist/key-checksum.d.ts +33 -0
- package/dist/key-checksum.d.ts.map +1 -0
- package/dist/key-checksum.js +67 -0
- package/dist/key-checksum.js.map +1 -0
- package/dist/libraries.d.ts +60 -0
- package/dist/libraries.d.ts.map +1 -0
- package/dist/libraries.js +120 -0
- package/dist/libraries.js.map +1 -0
- package/dist/limit-catalog.d.ts +381 -0
- package/dist/limit-catalog.d.ts.map +1 -0
- package/dist/limit-catalog.js +429 -0
- package/dist/limit-catalog.js.map +1 -0
- package/dist/limits.d.ts +167 -0
- package/dist/limits.d.ts.map +1 -0
- package/dist/limits.js +175 -0
- package/dist/limits.js.map +1 -0
- package/dist/locale-tag.d.ts +21 -0
- package/dist/locale-tag.d.ts.map +1 -0
- package/dist/locale-tag.js +21 -0
- package/dist/locale-tag.js.map +1 -0
- package/dist/make-diagnostic.d.ts +74 -0
- package/dist/make-diagnostic.d.ts.map +1 -0
- package/dist/make-diagnostic.js +100 -0
- package/dist/make-diagnostic.js.map +1 -0
- package/dist/manifest-compat-diagnostics.d.ts +23 -0
- package/dist/manifest-compat-diagnostics.d.ts.map +1 -0
- package/dist/manifest-compat-diagnostics.js +150 -0
- package/dist/manifest-compat-diagnostics.js.map +1 -0
- package/dist/manifest-compat.d.ts +58 -0
- package/dist/manifest-compat.d.ts.map +1 -0
- package/dist/manifest-compat.js +377 -0
- package/dist/manifest-compat.js.map +1 -0
- package/dist/manifest.d.ts +1769 -0
- package/dist/manifest.d.ts.map +1 -0
- package/dist/manifest.js +421 -0
- package/dist/manifest.js.map +1 -0
- package/dist/metering.d.ts +126 -0
- package/dist/metering.d.ts.map +1 -0
- package/dist/metering.js +147 -0
- package/dist/metering.js.map +1 -0
- package/dist/migrate.d.ts +70 -0
- package/dist/migrate.d.ts.map +1 -0
- package/dist/migrate.js +159 -0
- package/dist/migrate.js.map +1 -0
- package/dist/money.d.ts +41 -0
- package/dist/money.d.ts.map +1 -0
- package/dist/money.js +52 -0
- package/dist/money.js.map +1 -0
- package/dist/names.d.ts +37 -0
- package/dist/names.d.ts.map +1 -0
- package/dist/names.js +55 -0
- package/dist/names.js.map +1 -0
- package/dist/overage-pricing.d.ts +89 -0
- package/dist/overage-pricing.d.ts.map +1 -0
- package/dist/overage-pricing.js +170 -0
- package/dist/overage-pricing.js.map +1 -0
- package/dist/plan-ids.d.ts +10 -0
- package/dist/plan-ids.d.ts.map +1 -0
- package/dist/plan-ids.js +8 -0
- package/dist/plan-ids.js.map +1 -0
- package/dist/plan-limits.d.ts +138 -0
- package/dist/plan-limits.d.ts.map +1 -0
- package/dist/plan-limits.js +112 -0
- package/dist/plan-limits.js.map +1 -0
- package/dist/plan-pricing.d.ts +145 -0
- package/dist/plan-pricing.d.ts.map +1 -0
- package/dist/plan-pricing.js +172 -0
- package/dist/plan-pricing.js.map +1 -0
- package/dist/plan-usage.d.ts +112 -0
- package/dist/plan-usage.d.ts.map +1 -0
- package/dist/plan-usage.js +134 -0
- package/dist/plan-usage.js.map +1 -0
- package/dist/preview-token.d.ts +52 -0
- package/dist/preview-token.d.ts.map +1 -0
- package/dist/preview-token.js +106 -0
- package/dist/preview-token.js.map +1 -0
- package/dist/prop-names.d.ts +51 -0
- package/dist/prop-names.d.ts.map +1 -0
- package/dist/prop-names.js +150 -0
- package/dist/prop-names.js.map +1 -0
- package/dist/prop-type-docs.d.ts +20 -0
- package/dist/prop-type-docs.d.ts.map +1 -0
- package/dist/prop-type-docs.js +89 -0
- package/dist/prop-type-docs.js.map +1 -0
- package/dist/prop-types.d.ts +97 -0
- package/dist/prop-types.d.ts.map +1 -0
- package/dist/prop-types.js +299 -0
- package/dist/prop-types.js.map +1 -0
- package/dist/props.d.ts +996 -0
- package/dist/props.d.ts.map +1 -0
- package/dist/props.js +183 -0
- package/dist/props.js.map +1 -0
- package/dist/proto-guard.d.ts +29 -0
- package/dist/proto-guard.d.ts.map +1 -0
- package/dist/proto-guard.js +79 -0
- package/dist/proto-guard.js.map +1 -0
- package/dist/runtime-errors.d.ts +42 -0
- package/dist/runtime-errors.d.ts.map +1 -0
- package/dist/runtime-errors.js +42 -0
- package/dist/runtime-errors.js.map +1 -0
- package/dist/runtime-pointers.d.ts +58 -0
- package/dist/runtime-pointers.d.ts.map +1 -0
- package/dist/runtime-pointers.js +84 -0
- package/dist/runtime-pointers.js.map +1 -0
- package/dist/secret-scan.d.ts +191 -0
- package/dist/secret-scan.d.ts.map +1 -0
- package/dist/secret-scan.js +542 -0
- package/dist/secret-scan.js.map +1 -0
- package/dist/semver.d.ts +89 -0
- package/dist/semver.d.ts.map +1 -0
- package/dist/semver.js +400 -0
- package/dist/semver.js.map +1 -0
- package/dist/server-key.d.ts +68 -0
- package/dist/server-key.d.ts.map +1 -0
- package/dist/server-key.js +150 -0
- package/dist/server-key.js.map +1 -0
- package/dist/site-manifest-keys.d.ts +107 -0
- package/dist/site-manifest-keys.d.ts.map +1 -0
- package/dist/site-manifest-keys.js +146 -0
- package/dist/site-manifest-keys.js.map +1 -0
- package/dist/site-manifest.d.ts +286 -0
- package/dist/site-manifest.d.ts.map +1 -0
- package/dist/site-manifest.js +100 -0
- package/dist/site-manifest.js.map +1 -0
- package/dist/source-archive.d.ts +119 -0
- package/dist/source-archive.d.ts.map +1 -0
- package/dist/source-archive.js +644 -0
- package/dist/source-archive.js.map +1 -0
- package/dist/source-package-corpus.d.ts +55 -0
- package/dist/source-package-corpus.d.ts.map +1 -0
- package/dist/source-package-corpus.js +303 -0
- package/dist/source-package-corpus.js.map +1 -0
- package/dist/source-package.d.ts +227 -0
- package/dist/source-package.d.ts.map +1 -0
- package/dist/source-package.js +361 -0
- package/dist/source-package.js.map +1 -0
- package/dist/source-secrets.d.ts +21 -0
- package/dist/source-secrets.d.ts.map +1 -0
- package/dist/source-secrets.js +43 -0
- package/dist/source-secrets.js.map +1 -0
- package/dist/ssr-cap.d.ts +61 -0
- package/dist/ssr-cap.d.ts.map +1 -0
- package/dist/ssr-cap.js +107 -0
- package/dist/ssr-cap.js.map +1 -0
- package/dist/ssr-kv.d.ts +18 -0
- package/dist/ssr-kv.d.ts.map +1 -0
- package/dist/ssr-kv.js +18 -0
- package/dist/ssr-kv.js.map +1 -0
- package/dist/ssr-version-ledger.d.ts +53 -0
- package/dist/ssr-version-ledger.d.ts.map +1 -0
- package/dist/ssr-version-ledger.js +88 -0
- package/dist/ssr-version-ledger.js.map +1 -0
- package/dist/style-references.d.ts +58 -0
- package/dist/style-references.d.ts.map +1 -0
- package/dist/style-references.js +241 -0
- package/dist/style-references.js.map +1 -0
- package/dist/tag-name.d.ts +87 -0
- package/dist/tag-name.d.ts.map +1 -0
- package/dist/tag-name.js +222 -0
- package/dist/tag-name.js.map +1 -0
- package/dist/tar-writer.d.ts +74 -0
- package/dist/tar-writer.d.ts.map +1 -0
- package/dist/tar-writer.js +148 -0
- package/dist/tar-writer.js.map +1 -0
- package/dist/testing.d.ts +11 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +11 -0
- package/dist/testing.js.map +1 -0
- package/dist/text-codec.d.ts +36 -0
- package/dist/text-codec.d.ts.map +1 -0
- package/dist/text-codec.js +32 -0
- package/dist/text-codec.js.map +1 -0
- package/dist/url-value.d.ts +41 -0
- package/dist/url-value.d.ts.map +1 -0
- package/dist/url-value.js +147 -0
- package/dist/url-value.js.map +1 -0
- package/dist/usage-guard.d.ts +99 -0
- package/dist/usage-guard.d.ts.map +1 -0
- package/dist/usage-guard.js +104 -0
- package/dist/usage-guard.js.map +1 -0
- package/dist/usage-mirror.d.ts +55 -0
- package/dist/usage-mirror.d.ts.map +1 -0
- package/dist/usage-mirror.js +52 -0
- package/dist/usage-mirror.js.map +1 -0
- package/dist/value-check.d.ts +88 -0
- package/dist/value-check.d.ts.map +1 -0
- package/dist/value-check.js +279 -0
- package/dist/value-check.js.map +1 -0
- package/dist/value-patterns.d.ts +9 -0
- package/dist/value-patterns.d.ts.map +1 -0
- package/dist/value-patterns.js +17 -0
- package/dist/value-patterns.js.map +1 -0
- package/dist/value-schema.d.ts +796 -0
- package/dist/value-schema.d.ts.map +1 -0
- package/dist/value-schema.js +231 -0
- package/dist/value-schema.js.map +1 -0
- package/dist/zod-free.d.ts +60 -0
- package/dist/zod-free.d.ts.map +1 -0
- package/dist/zod-free.js +59 -0
- package/dist/zod-free.js.map +1 -0
- package/package.json +75 -3
- package/schema/DEPLOYED +12 -0
- package/schema/build-diagnostic.v1.json +63 -0
- package/schema/component-manifest.v1.json +1000 -0
- package/schema/data-api.v1.json +194 -0
- package/schema/library-manifest.v1.json +60 -0
- package/schema/published/SHA256SUMS +36 -0
- package/schema/published/build-diagnostic/v1.10.json +83 -0
- package/schema/published/build-diagnostic/v1.3.json +83 -0
- package/schema/published/build-diagnostic/v1.4.json +83 -0
- package/schema/published/build-diagnostic/v1.5.json +83 -0
- package/schema/published/build-diagnostic/v1.6.json +83 -0
- package/schema/published/build-diagnostic/v1.7.json +83 -0
- package/schema/published/build-diagnostic/v1.8.json +83 -0
- package/schema/published/build-diagnostic/v1.9.json +83 -0
- package/schema/published/component-manifest/v1.10.json +1443 -0
- package/schema/published/component-manifest/v1.3.json +1411 -0
- package/schema/published/component-manifest/v1.4.json +1419 -0
- package/schema/published/component-manifest/v1.5.json +1437 -0
- package/schema/published/component-manifest/v1.6.json +1437 -0
- package/schema/published/component-manifest/v1.7.json +1437 -0
- package/schema/published/component-manifest/v1.8.json +1437 -0
- package/schema/published/component-manifest/v1.9.json +1437 -0
- package/schema/published/data-api/v1.10.json +282 -0
- package/schema/published/data-api/v1.3.json +281 -0
- package/schema/published/data-api/v1.4.json +281 -0
- package/schema/published/data-api/v1.5.json +281 -0
- package/schema/published/data-api/v1.6.json +281 -0
- package/schema/published/data-api/v1.7.json +281 -0
- package/schema/published/data-api/v1.8.json +282 -0
- package/schema/published/data-api/v1.9.json +282 -0
- package/schema/published/library-manifest/v1.10.json +68 -0
- package/schema/published/library-manifest/v1.5.json +68 -0
- package/schema/published/library-manifest/v1.6.json +68 -0
- package/schema/published/library-manifest/v1.7.json +68 -0
- package/schema/published/library-manifest/v1.8.json +68 -0
- package/schema/published/library-manifest/v1.9.json +68 -0
- package/schema/published/taggor-config/v1.10.json +56 -0
- package/schema/published/taggor-config/v1.5.json +56 -0
- package/schema/published/taggor-config/v1.6.json +56 -0
- package/schema/published/taggor-config/v1.7.json +56 -0
- package/schema/published/taggor-config/v1.8.json +56 -0
- package/schema/published/taggor-config/v1.9.json +56 -0
- package/schema/taggor-config.v1.json +39 -0
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The overage rate table as DATA (TAG-1629, owner decision of 2026-11-14): one row per
|
|
3
|
+
* (metric, paid plan, version) with the instant it starts to apply, in micro US dollars. The rows
|
|
4
|
+
* live in the database (`overage_rates`) and staff edits them; `OVERAGE_RATES` in `plan-pricing.ts`
|
|
5
|
+
* is only the seed of version 1. This module is the pure part every reader shares: the row shape,
|
|
6
|
+
* the lookup "which rate applies at this instant", the seed rows, and the public JSON of
|
|
7
|
+
* `GET /v1/pricing` with its parser (the static site reads it at build time, the portal and the
|
|
8
|
+
* CLI at run time). Zod-free, no I/O, no clock.
|
|
9
|
+
*
|
|
10
|
+
* Safety rule: a lookup that finds no rate answers `null`, and a `null` rate means "do not bill"
|
|
11
|
+
* (the callers alert); nothing here ever invents a price.
|
|
12
|
+
*/
|
|
13
|
+
import { type OverageMetric } from "./limit-catalog.js";
|
|
14
|
+
import { type OverageUnit, type PaidPlanId } from "./plan-pricing.js";
|
|
15
|
+
/** The paid plans a rate row can name. */
|
|
16
|
+
export declare const OVERAGE_RATE_PLANS: readonly PaidPlanId[];
|
|
17
|
+
/** One version of one rate. Money in micro USD per billing unit, a whole number. */
|
|
18
|
+
export interface OverageRateVersion {
|
|
19
|
+
readonly metric: OverageMetric;
|
|
20
|
+
readonly plan: PaidPlanId;
|
|
21
|
+
/** 1 is the seed; each change of the same (metric, plan) adds one. */
|
|
22
|
+
readonly version: number;
|
|
23
|
+
readonly microUsdPerUnit: number;
|
|
24
|
+
/** The instant the rate starts to apply (inclusive). */
|
|
25
|
+
readonly effectiveFrom: Date;
|
|
26
|
+
}
|
|
27
|
+
/** The instant of the seed rows: the beginning of time, so the seed always applies until replaced. */
|
|
28
|
+
export declare const SEED_EFFECTIVE_FROM: Date;
|
|
29
|
+
/**
|
|
30
|
+
* The rows migration 0081 seeds, built from `OVERAGE_RATES`. Output: one row per metric and paid
|
|
31
|
+
* plan, version 1, in the metric order. Pure.
|
|
32
|
+
*/
|
|
33
|
+
export declare function seedRateVersions(): readonly OverageRateVersion[];
|
|
34
|
+
/** What a billing computation reads: the rate that applies, and which version it was. */
|
|
35
|
+
export interface OverageRateTable {
|
|
36
|
+
/** Micro USD per unit for a metric on a plan id; `null` when none applies (Free, unknown, missing). */
|
|
37
|
+
rateOf(metric: OverageMetric, planId: string): number | null;
|
|
38
|
+
/** The version of the rate that applies, `null` when none does. */
|
|
39
|
+
versionOf(metric: OverageMetric, planId: string): number | null;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Builds the table that applies at an instant from every known version.
|
|
43
|
+
* Inputs: the rows (any order, any number per metric and plan) and the instant. Output: the table;
|
|
44
|
+
* for each (metric, plan) the row with the greatest `effectiveFrom` not after `at` wins, a tie goes
|
|
45
|
+
* to the higher version. Errors: none. Pure.
|
|
46
|
+
*/
|
|
47
|
+
export declare function rateTableAt(rows: readonly OverageRateVersion[], at: Date): OverageRateTable;
|
|
48
|
+
/** The table of the seed (what every reader falls back to when the database cannot be read). */
|
|
49
|
+
export declare const SEED_RATE_TABLE: OverageRateTable;
|
|
50
|
+
/** One row of the public pricing JSON. */
|
|
51
|
+
export interface PublicRate {
|
|
52
|
+
readonly metric: OverageMetric;
|
|
53
|
+
readonly plan: PaidPlanId;
|
|
54
|
+
readonly unit: OverageUnit;
|
|
55
|
+
readonly microUsdPerUnit: number;
|
|
56
|
+
readonly version: number;
|
|
57
|
+
/** ISO 8601 instant; the seed rows carry `1970-01-01T00:00:00.000Z`. */
|
|
58
|
+
readonly effectiveFrom: string;
|
|
59
|
+
}
|
|
60
|
+
/** What `GET /v1/pricing` answers: the rates in force and the ones already scheduled. */
|
|
61
|
+
export interface PublicPricing {
|
|
62
|
+
readonly rates: readonly PublicRate[];
|
|
63
|
+
readonly upcoming: readonly PublicRate[];
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* The public pricing from every known version.
|
|
67
|
+
* Inputs: the rows and the instant. Output: `rates` (one per metric and plan, in force at `at`) and
|
|
68
|
+
* `upcoming` (versions that start later, soonest first). Pure.
|
|
69
|
+
*/
|
|
70
|
+
export declare function publicPricingAt(rows: readonly OverageRateVersion[], at: Date): PublicPricing;
|
|
71
|
+
/** The seed as a public pricing: the fallback of the static site when the API is down. Pure. */
|
|
72
|
+
export declare function seedPublicPricing(): PublicPricing;
|
|
73
|
+
/**
|
|
74
|
+
* Parses the JSON of `GET /v1/pricing` (snake_case keys) into a `PublicPricing`.
|
|
75
|
+
* Inputs: the decoded body. Output: the pricing, or `null` when the shape is wrong or any metric
|
|
76
|
+
* and plan has no rate in force (a page must never be built from a partial table). Pure.
|
|
77
|
+
*/
|
|
78
|
+
export declare function parsePublicPricing(body: unknown): PublicPricing | null;
|
|
79
|
+
/** The wire form of a public pricing (snake_case), the inverse of `parsePublicPricing`. Pure. */
|
|
80
|
+
export declare function publicPricingJson(pricing: PublicPricing): {
|
|
81
|
+
readonly rates: readonly Record<string, unknown>[];
|
|
82
|
+
readonly upcoming: readonly Record<string, unknown>[];
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* The rate table a public pricing describes, for the texts that read rates by metric and plan.
|
|
86
|
+
* Inputs: the pricing. Output: a table over `rates` (the ones in force). Pure.
|
|
87
|
+
*/
|
|
88
|
+
export declare function rateTableOfPricing(pricing: PublicPricing): OverageRateTable;
|
|
89
|
+
//# s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A0C;AAC1C,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC;IAC/B,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAC1B,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;IAC3B,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IACjC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,wEAAwE;IACxE,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;CAChC;AAED,yFAAyF;AACzF,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,KAAK,EAAE,SAAS,UAAU,EAAE,CAAC;IACtC,QAAQ,CAAC,QAAQ,EAAE,SAAS,UAAU,EAAE,CAAC;CAC1C;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,SAAS,kBAAkB,EAAE,EAAE,EAAE,EAAE,IAAI,GAAG,aAAa,CAuB5F;AAED,gGAAgG;AAChG,wBAAgB,iBAAiB,IAAI,aAAa,CAEjD;AA2BD;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,OAAO,GAAG,aAAa,GAAG,IAAI,CActE;AAED,iGAAiG;AACjG,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,aAAa,GAAG;IACzD,QAAQ,CAAC,KAAK,EAAE,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC;IACnD,QAAQ,CAAC,QAAQ,EAAE,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC;CACvD,CAUA;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,aAAa,GAAG,gBAAgB,CAW3E"}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The overage rate table as DATA (TAG-1629, owner decision of 2026-11-14): one row per
|
|
3
|
+
* (metric, paid plan, version) with the instant it starts to apply, in micro US dollars. The rows
|
|
4
|
+
* live in the database (`overage_rates`) and staff edits them; `OVERAGE_RATES` in `plan-pricing.ts`
|
|
5
|
+
* is only the seed of version 1. This module is the pure part every reader shares: the row shape,
|
|
6
|
+
* the lookup "which rate applies at this instant", the seed rows, and the public JSON of
|
|
7
|
+
* `GET /v1/pricing` with its parser (the static site reads it at build time, the portal and the
|
|
8
|
+
* CLI at run time). Zod-free, no I/O, no clock.
|
|
9
|
+
*
|
|
10
|
+
* Safety rule: a lookup that finds no rate answers `null`, and a `null` rate means "do not bill"
|
|
11
|
+
* (the callers alert); nothing here ever invents a price.
|
|
12
|
+
*/
|
|
13
|
+
import { OVERAGE_METRICS } from "./limit-catalog.js";
|
|
14
|
+
import { OVERAGE_RATES } from "./plan-pricing.js";
|
|
15
|
+
/** The paid plans a rate row can name. */
|
|
16
|
+
export const OVERAGE_RATE_PLANS = Object.freeze(["pro", "agency"]);
|
|
17
|
+
/** The instant of the seed rows: the beginning of time, so the seed always applies until replaced. */
|
|
18
|
+
export const SEED_EFFECTIVE_FROM = new Date(0);
|
|
19
|
+
/**
|
|
20
|
+
* The rows migration 0081 seeds, built from `OVERAGE_RATES`. Output: one row per metric and paid
|
|
21
|
+
* plan, version 1, in the metric order. Pure.
|
|
22
|
+
*/
|
|
23
|
+
export function seedRateVersions() {
|
|
24
|
+
return OVERAGE_METRICS.flatMap((metric) => OVERAGE_RATE_PLANS.map((plan) => ({
|
|
25
|
+
metric,
|
|
26
|
+
plan,
|
|
27
|
+
version: 1,
|
|
28
|
+
microUsdPerUnit: OVERAGE_RATES[metric].microUsdPerUnit[plan],
|
|
29
|
+
effectiveFrom: SEED_EFFECTIVE_FROM,
|
|
30
|
+
})));
|
|
31
|
+
}
|
|
32
|
+
/** The map key of a (metric, plan id) pair. */
|
|
33
|
+
const rateKey = (metric, planId) => [metric, planId].join(":");
|
|
34
|
+
/**
|
|
35
|
+
* Builds the table that applies at an instant from every known version.
|
|
36
|
+
* Inputs: the rows (any order, any number per metric and plan) and the instant. Output: the table;
|
|
37
|
+
* for each (metric, plan) the row with the greatest `effectiveFrom` not after `at` wins, a tie goes
|
|
38
|
+
* to the higher version. Errors: none. Pure.
|
|
39
|
+
*/
|
|
40
|
+
export function rateTableAt(rows, at) {
|
|
41
|
+
const best = new Map();
|
|
42
|
+
for (const row of rows) {
|
|
43
|
+
if (row.effectiveFrom.getTime() > at.getTime())
|
|
44
|
+
continue;
|
|
45
|
+
const key = rateKey(row.metric, row.plan);
|
|
46
|
+
const held = best.get(key);
|
|
47
|
+
if (held === undefined ||
|
|
48
|
+
row.effectiveFrom.getTime() > held.effectiveFrom.getTime() ||
|
|
49
|
+
(row.effectiveFrom.getTime() === held.effectiveFrom.getTime() && row.version > held.version)) {
|
|
50
|
+
best.set(key, row);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const find = (metric, planId) => best.get(rateKey(metric, planId));
|
|
54
|
+
return {
|
|
55
|
+
rateOf: (metric, planId) => find(metric, planId)?.microUsdPerUnit ?? null,
|
|
56
|
+
versionOf: (metric, planId) => find(metric, planId)?.version ?? null,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
/** The table of the seed (what every reader falls back to when the database cannot be read). */
|
|
60
|
+
export const SEED_RATE_TABLE = rateTableAt(seedRateVersions(), new Date());
|
|
61
|
+
/**
|
|
62
|
+
* The public pricing from every known version.
|
|
63
|
+
* Inputs: the rows and the instant. Output: `rates` (one per metric and plan, in force at `at`) and
|
|
64
|
+
* `upcoming` (versions that start later, soonest first). Pure.
|
|
65
|
+
*/
|
|
66
|
+
export function publicPricingAt(rows, at) {
|
|
67
|
+
const table = rateTableAt(rows, at);
|
|
68
|
+
const toPublic = (row) => ({
|
|
69
|
+
metric: row.metric,
|
|
70
|
+
plan: row.plan,
|
|
71
|
+
unit: OVERAGE_RATES[row.metric].unit,
|
|
72
|
+
microUsdPerUnit: row.microUsdPerUnit,
|
|
73
|
+
version: row.version,
|
|
74
|
+
effectiveFrom: row.effectiveFrom.toISOString(),
|
|
75
|
+
});
|
|
76
|
+
const inForce = [];
|
|
77
|
+
for (const metric of OVERAGE_METRICS) {
|
|
78
|
+
for (const plan of OVERAGE_RATE_PLANS) {
|
|
79
|
+
const version = table.versionOf(metric, plan);
|
|
80
|
+
const row = rows.find((r) => r.metric === metric && r.plan === plan && r.version === version);
|
|
81
|
+
if (row !== undefined)
|
|
82
|
+
inForce.push(toPublic(row));
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
const upcoming = rows
|
|
86
|
+
.filter((row) => row.effectiveFrom.getTime() > at.getTime())
|
|
87
|
+
.sort((a, b) => a.effectiveFrom.getTime() - b.effectiveFrom.getTime())
|
|
88
|
+
.map(toPublic);
|
|
89
|
+
return { rates: inForce, upcoming };
|
|
90
|
+
}
|
|
91
|
+
/** The seed as a public pricing: the fallback of the static site when the API is down. Pure. */
|
|
92
|
+
export function seedPublicPricing() {
|
|
93
|
+
return publicPricingAt(seedRateVersions(), new Date());
|
|
94
|
+
}
|
|
95
|
+
const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
96
|
+
function parseRate(value) {
|
|
97
|
+
if (!isRecord(value))
|
|
98
|
+
return null;
|
|
99
|
+
const { metric, plan, unit, micro_usd_per_unit: micro, version, effective_from: from } = value;
|
|
100
|
+
if (typeof metric !== "string" || !OVERAGE_METRICS.includes(metric)) {
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
const paidPlan = OVERAGE_RATE_PLANS.find((candidate) => candidate === plan);
|
|
104
|
+
if (paidPlan === undefined)
|
|
105
|
+
return null;
|
|
106
|
+
if (unit !== "unit" && unit !== "mb")
|
|
107
|
+
return null;
|
|
108
|
+
if (typeof micro !== "number" || !Number.isSafeInteger(micro) || micro < 0)
|
|
109
|
+
return null;
|
|
110
|
+
if (typeof version !== "number" || !Number.isInteger(version) || version < 1)
|
|
111
|
+
return null;
|
|
112
|
+
if (typeof from !== "string" || Number.isNaN(Date.parse(from)))
|
|
113
|
+
return null;
|
|
114
|
+
return {
|
|
115
|
+
metric: metric,
|
|
116
|
+
plan: paidPlan,
|
|
117
|
+
unit,
|
|
118
|
+
microUsdPerUnit: micro,
|
|
119
|
+
version,
|
|
120
|
+
effectiveFrom: new Date(from).toISOString(),
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Parses the JSON of `GET /v1/pricing` (snake_case keys) into a `PublicPricing`.
|
|
125
|
+
* Inputs: the decoded body. Output: the pricing, or `null` when the shape is wrong or any metric
|
|
126
|
+
* and plan has no rate in force (a page must never be built from a partial table). Pure.
|
|
127
|
+
*/
|
|
128
|
+
export function parsePublicPricing(body) {
|
|
129
|
+
if (!isRecord(body) || !Array.isArray(body["rates"]) || !Array.isArray(body["upcoming"])) {
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
const rates = body["rates"].map(parseRate);
|
|
133
|
+
const upcoming = body["upcoming"].map(parseRate);
|
|
134
|
+
if (rates.includes(null) || upcoming.includes(null))
|
|
135
|
+
return null;
|
|
136
|
+
const good = rates;
|
|
137
|
+
for (const metric of OVERAGE_METRICS) {
|
|
138
|
+
for (const plan of OVERAGE_RATE_PLANS) {
|
|
139
|
+
if (!good.some((r) => r.metric === metric && r.plan === plan))
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return { rates: good, upcoming: upcoming };
|
|
144
|
+
}
|
|
145
|
+
/** The wire form of a public pricing (snake_case), the inverse of `parsePublicPricing`. Pure. */
|
|
146
|
+
export function publicPricingJson(pricing) {
|
|
147
|
+
const wire = (r) => ({
|
|
148
|
+
metric: r.metric,
|
|
149
|
+
plan: r.plan,
|
|
150
|
+
unit: r.unit,
|
|
151
|
+
micro_usd_per_unit: r.microUsdPerUnit,
|
|
152
|
+
version: r.version,
|
|
153
|
+
effective_from: r.effectiveFrom,
|
|
154
|
+
});
|
|
155
|
+
return { rates: pricing.rates.map(wire), upcoming: pricing.upcoming.map(wire) };
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* The rate table a public pricing describes, for the texts that read rates by metric and plan.
|
|
159
|
+
* Inputs: the pricing. Output: a table over `rates` (the ones in force). Pure.
|
|
160
|
+
*/
|
|
161
|
+
export function rateTableOfPricing(pricing) {
|
|
162
|
+
return rateTableAt(pricing.rates.map((r) => ({
|
|
163
|
+
metric: r.metric,
|
|
164
|
+
plan: r.plan,
|
|
165
|
+
version: r.version,
|
|
166
|
+
microUsdPerUnit: r.microUsdPerUnit,
|
|
167
|
+
effectiveFrom: new Date(r.effectiveFrom),
|
|
168
|
+
})), new Date(8.64e15));
|
|
169
|
+
}
|
|
170
|
+
//# sourceMappingURL=overage-pricing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"overage-pricing.js","sourceRoot":"","sources":["../src/overage-pricing.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,eAAe,EAAsB,MAAM,oBAAoB,CAAC;AACzE,OAAO,EAAE,aAAa,EAAqC,MAAM,mBAAmB,CAAC;AAErF,0CAA0C;AAC1C,MAAM,CAAC,MAAM,kBAAkB,GAA0B,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC;AAa1F,sGAAsG;AACtG,MAAM,CAAC,MAAM,mBAAmB,GAAG,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC;AAE/C;;;GAGG;AACH,MAAM,UAAU,gBAAgB;IAC9B,OAAO,eAAe,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE,CACxC,kBAAkB,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QAChC,MAAM;QACN,IAAI;QACJ,OAAO,EAAE,CAAC;QACV,eAAe,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC,eAAe,CAAC,IAAI,CAAC;QAC5D,aAAa,EAAE,mBAAmB;KACnC,CAAC,CAAC,CACJ,CAAC;AACJ,CAAC;AAUD,+C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a,EAAE,IAAI,IAAI,CAAC,CAAC,CAAC,aAAa,CAAC;KACzC,CAAC,CAAC,EACH,IAAI,IAAI,CAAC,OAAO,CAAC,CAClB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The plan ids, apart from every table that has a row per plan (TAG-1627): the limit catalog
|
|
3
|
+
* (`limit-catalog.ts`) and `planLimits` both need them, and neither may import the other first.
|
|
4
|
+
* Zod-free.
|
|
5
|
+
*/
|
|
6
|
+
/** The plans. A new plan is added here, with its default in every entry of the limit catalog. */
|
|
7
|
+
export declare const PLAN_IDS: readonly ["free", "pro", "agency"];
|
|
8
|
+
/** One plan. */
|
|
9
|
+
export type PlanId = (typeof PLAN_IDS)[number];
|
|
10
|
+
//# sourceMappingURL=plan-ids.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plan-ids.d.ts","sourceRoot":"","sources":["../src/plan-ids.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,iGAAiG;AACjG,eAAO,MAAM,QAAQ,oCAAoD,CAAC;AAE1E,gBAAgB;AAChB,MAAM,MAAM,MAAM,GAAG,CAAC,OAAO,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC"}
|
package/dist/plan-ids.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The plan ids, apart from every table that has a row per plan (TAG-1627): the limit catalog
|
|
3
|
+
* (`limit-catalog.ts`) and `planLimits` both need them, and neither may import the other first.
|
|
4
|
+
* Zod-free.
|
|
5
|
+
*/
|
|
6
|
+
/** The plans. A new plan is added here, with its default in every entry of the limit catalog. */
|
|
7
|
+
export const PLAN_IDS = Object.freeze(["free", "pro", "agency"]);
|
|
8
|
+
//# sourceMappingURL=plan-ids.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plan-ids.js","sourceRoot":"","sources":["../src/plan-ids.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,iGAAiG;AACjG,MAAM,CAAC,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,QAAQ,CAAU,CAAC,CAAC"}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { PLAN_IDS, type PlanId } from "./plan-ids.js";
|
|
2
|
+
export { PLAN_IDS, type PlanId };
|
|
3
|
+
/** The plan of a workspace without one (and of every build until workspaces have plans). */
|
|
4
|
+
export declare const DEFAULT_PLAN_ID: PlanId;
|
|
5
|
+
/** What one plan allows. Sizes are bytes, durations milliseconds. */
|
|
6
|
+
export interface PlanLimits {
|
|
7
|
+
/** One whole build; past it the build fails with `BUILD_TIMEOUT`. */
|
|
8
|
+
readonly buildTimeoutMs: number;
|
|
9
|
+
/** The compressed source package. */
|
|
10
|
+
readonly maxSourceBytes: number;
|
|
11
|
+
/** Regular files in the source package. */
|
|
12
|
+
readonly maxFiles: number;
|
|
13
|
+
/** Distinct packages the component's own files import by name (`preact`, `@taggor/component`). */
|
|
14
|
+
readonly maxDependencies: number;
|
|
15
|
+
/** What visitors download: the bundle and the CSS together. */
|
|
16
|
+
readonly maxOutputBytes: number;
|
|
17
|
+
/**
|
|
18
|
+
* One asset file a component imports (TAG-410: an image or a WOFF2 font, as stored), at most the
|
|
19
|
+
* contract's `ASSET_LIMITS.assetMaxBytes`; over it the build fails with `ASSET_TOO_LARGE`.
|
|
20
|
+
*/
|
|
21
|
+
readonly maxAssetBytes: number;
|
|
22
|
+
/** All the asset files one component imports together (TAG-410, `ASSET_TOO_LARGE`). */
|
|
23
|
+
readonly maxAssetsBytes: number;
|
|
24
|
+
/**
|
|
25
|
+
* Builds a workspace may queue in a rolling 7-day window (the API's `POST /builds`, decision 78):
|
|
26
|
+
* one limit, one window, no hourly or daily sublimit beside it (decision 79).
|
|
27
|
+
*/
|
|
28
|
+
readonly buildsPerWeek: number;
|
|
29
|
+
/** Builds of one workspace running at once; always fewer than the container instances. */
|
|
30
|
+
readonly concurrentBuilds: number;
|
|
31
|
+
}
|
|
32
|
+
/** The names of the limits of a plan. */
|
|
33
|
+
export type PlanLimitName = keyof PlanLimits;
|
|
34
|
+
/**
|
|
35
|
+
* The limits of every plan, by plan id.
|
|
36
|
+
*
|
|
37
|
+
* Inputs: none. Output: deeply frozen rows. Errors: none. Side effects: none.
|
|
38
|
+
*/
|
|
39
|
+
export declare const planLimits: Readonly<Record<PlanId, PlanLimits>>;
|
|
40
|
+
/**
|
|
41
|
+
* Whether a value names a plan.
|
|
42
|
+
*
|
|
43
|
+
* Inputs: any value. Output: `true` for a key of `planLimits` (not inherited names such as
|
|
44
|
+
* `constructor`). Errors: none. Side effects: none.
|
|
45
|
+
*/
|
|
46
|
+
export declare function isPlanId(value: unknown): value is PlanId;
|
|
47
|
+
/**
|
|
48
|
+
* The limits of a plan, falling back to the default plan.
|
|
49
|
+
*
|
|
50
|
+
* Inputs: a plan id, or `undefined` for a workspace (or build) without one. Output: that plan's
|
|
51
|
+
* row, `planLimits[DEFAULT_PLAN_ID]` for `undefined` or an unknown id. Errors: none. Side
|
|
52
|
+
* effects: none.
|
|
53
|
+
*/
|
|
54
|
+
export declare function limitsOfPlan(planId: string | undefined): {
|
|
55
|
+
readonly planId: PlanId;
|
|
56
|
+
readonly limits: PlanLimits;
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* The plan with the lowest value above `current` for one limit, so a `LIMIT_EXCEEDED` diagnostic
|
|
60
|
+
* can say how to raise it.
|
|
61
|
+
*
|
|
62
|
+
* Inputs: the limit, the value the build had and (for tests) the table. Output: the plan id and
|
|
63
|
+
* its value, or `undefined` when no plan allows more. Errors: none. Side effects: none.
|
|
64
|
+
*/
|
|
65
|
+
export declare function planAbove(limit: PlanLimitName, current: number, plans?: Readonly<Record<string, PlanLimits>>): {
|
|
66
|
+
readonly planId: string;
|
|
67
|
+
readonly value: number;
|
|
68
|
+
} | undefined;
|
|
69
|
+
/**
|
|
70
|
+
* Whole seconds from `now` to the next UTC midnight (at least 1): the `Retry-After` of every
|
|
71
|
+
* per-UTC-day limit.
|
|
72
|
+
*
|
|
73
|
+
* Inputs: the current time. Output: seconds. Errors: none. Side effects: none.
|
|
74
|
+
*/
|
|
75
|
+
export declare function secondsUntilNextUtcDay(now: Date): number;
|
|
76
|
+
/** The window of `buildsPerWeek`: a rolling 7 days (decision 78). */
|
|
77
|
+
export declare const BUILD_WINDOW_MS: number;
|
|
78
|
+
/** When a full build window frees a place, and how long a client waits for it. */
|
|
79
|
+
export interface BuildWindowReset {
|
|
80
|
+
readonly resetsAt: Date;
|
|
81
|
+
/** Whole seconds from now to `resetsAt`, at least 1: the `Retry-After` of the 429. */
|
|
82
|
+
readonly retryAfterSeconds: number;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* When the rolling 7-day window frees one place (`POST /builds` answers 429 with
|
|
86
|
+
* `Retry-After: retryAfterSeconds` at the limit).
|
|
87
|
+
*
|
|
88
|
+
* Inputs: the creation moment of the build that must age out for one more to fit (the
|
|
89
|
+
* `used - limit + 1`-th oldest of the window; the registry finds it) and the current time.
|
|
90
|
+
* Output: that moment plus 7 days and the whole seconds to wait (at least 1). Errors: none. Side
|
|
91
|
+
* effects: none.
|
|
92
|
+
*/
|
|
93
|
+
export declare function buildWindowReset(freeingBuildCreatedAt: Date, now: Date): BuildWindowReset;
|
|
94
|
+
/** What each plan allows a workspace to HOLD (as opposed to `PlanLimits`, what one build may use). */
|
|
95
|
+
export interface PlanQuotas {
|
|
96
|
+
/** Sites (not deleted) at once; `POST /v1/sites` answers 409 `site_quota_exceeded` past it (TAG-622). */
|
|
97
|
+
readonly maxSites: number;
|
|
98
|
+
/** Unrevoked API keys at once; `POST /v1/api-keys` answers 409 `api_key_quota_exceeded` past it (TAG-924). */
|
|
99
|
+
readonly activeApiKeys: number;
|
|
100
|
+
/**
|
|
101
|
+
* Unrevoked API keys one admin or member may have created at once (TAG-2293); an owner is bound
|
|
102
|
+
* by `activeApiKeys` only. Past it, `POST /v1/api-keys` answers 409 `api_key_quota_exceeded`.
|
|
103
|
+
*/
|
|
104
|
+
readonly activeApiKeysPerCreator: number;
|
|
105
|
+
/**
|
|
106
|
+
* Places of `activeApiKeys` that only an owner may fill (TAG-2293), so no admin or member, even
|
|
107
|
+
* several together, can leave the owner without a place to create a key.
|
|
108
|
+
*/
|
|
109
|
+
readonly ownerReservedApiKeys: number;
|
|
110
|
+
/**
|
|
111
|
+
* Components attached to one site at once (TAG-1623, decision 77); an attach past it answers 409
|
|
112
|
+
* `site_component_limit`. PROVISIONAL until the owner approves the plans (TAG-1602). It only
|
|
113
|
+
* stops a NEW attach: after a downgrade, what is attached stays served (golden rule 2). The
|
|
114
|
+
* highest value is the platform ceiling `SITE_MANIFEST_MAX_COMPONENTS` (site-manifest.ts).
|
|
115
|
+
*/
|
|
116
|
+
readonly componentsPerSite: number;
|
|
117
|
+
/**
|
|
118
|
+
* Network origins one version may declare in `permissions.connect` (TAG-1625, the old trust
|
|
119
|
+
* level's `connectOrigins`); a version past it is refused with 402 `plan_limit_reached` before
|
|
120
|
+
* the INSERT. PROVISIONAL until the owner approves the plans (TAG-1602).
|
|
121
|
+
*/
|
|
122
|
+
readonly connectOriginsPerVersion: number;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* The quotas of every plan, by plan id; kept apart from `planLimits` because the builder wording
|
|
126
|
+
* (`LIMIT_EXCEEDED` diagnostics) covers every key of that one.
|
|
127
|
+
*
|
|
128
|
+
* Inputs: none. Output: deeply frozen rows. Errors: none. Side effects: none.
|
|
129
|
+
*/
|
|
130
|
+
export declare const planQuotas: Readonly<Record<PlanId, PlanQuotas>>;
|
|
131
|
+
/**
|
|
132
|
+
* The quotas of a plan, falling back to the default plan.
|
|
133
|
+
*
|
|
134
|
+
* Inputs: a plan id or `undefined`. Output: that plan's row, the default plan's for `undefined` or
|
|
135
|
+
* an unknown id. Errors: none. Side effects: none.
|
|
136
|
+
*/
|
|
137
|
+
export declare function quotasOfPlan(planId: string | undefined): PlanQuotas;
|
|
138
|
+
//# sourceMappingURL=plan-limits.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plan-limits.d.ts","sourceRoot":"","sources":["../src/plan-limits.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,QAAQ,EAAE,KAAK,MAAM,EAAE,MAAM,eAAe,CAAC;AAEtD,OAAO,EAAE,QAAQ,EAAE,KAAK,MAAM,EAAE,CAAC;AAEjC,4FAA4F;AAC5F,eAAO,MAAM,eAAe,EAAE,MAAe,CAAC;AAE9C,qEAAqE;AACrE,MAAM,WAAW,UAAU;IACzB,qEAAqE;IACrE,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,qCAAqC;IACrC,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,2CAA2C;IAC3C,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,kGAAkG;IAClG,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IACjC,+DAA+D;IAC/D,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC;;;OAGG;IACH,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,uFAAuF;IACvF,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC;;;OAGG;IACH,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,0FAA0F;IAC1F,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;CACnC;AAED,yCAAyC;AACzC,MAAM,MAAM,aAAa,GAAG,MAAM,UAAU,CAAC;AAM7C;;;;GAIG;AACH,eAAO,MAAM,UAAU,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAqB,CAAC;AAElF;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAExD;AAED;;;;;;GAMG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AC3C;AAID;;;;;GAKG;AACH,eAAO,MAAM,UAAU,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAA0B,CAAC;AAEvF;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,GAAG,UAAU,CAEnE"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `planLimits` (TAG-413): the single table of what each plan allows a workspace to build. Zod-free.
|
|
3
|
+
*
|
|
4
|
+
* The builder reads it for every build (timeout, source size, files, dependencies, output size,
|
|
5
|
+
* asset sizes since TAG-410, builds at once) and the API reads it before queueing one (builds per
|
|
6
|
+
* rolling week, `POST /builds` answers 429 with `Retry-After` past it, TAG-909, TAG-1624). Billing (E16, TAG-1603) reuses the same rows for its
|
|
7
|
+
* entitlements, so a limit lives here once. It sits in the contract because both the API and the
|
|
8
|
+
* builder already depend on it, and the customer's agent sees these numbers in the
|
|
9
|
+
* `LIMIT_EXCEEDED` diagnostics.
|
|
10
|
+
*
|
|
11
|
+
* The values are provisional until the owner approves the plans and prices (TAG-1602): today
|
|
12
|
+
* there is one plan, `free`, with the limits every build already had (TAG-401, TAG-1705), so
|
|
13
|
+
* nothing gets stricter. The builder's platform ceilings (`BUILD_LIMIT_BOUNDS`, tuned with the
|
|
14
|
+
* `TAGGOR_BUILD_MAX_*` variables) still cap every plan: a plan only lowers a limit, never raises
|
|
15
|
+
* it past what one container instance holds.
|
|
16
|
+
*/
|
|
17
|
+
import { deepFreeze } from "./freeze.js";
|
|
18
|
+
import { catalogRows } from "./limit-catalog.js";
|
|
19
|
+
import { PLAN_IDS } from "./plan-ids.js";
|
|
20
|
+
export { PLAN_IDS };
|
|
21
|
+
/** The plan of a workspace without one (and of every build until workspaces have plans). */
|
|
22
|
+
export const DEFAULT_PLAN_ID = "free";
|
|
23
|
+
// The rows come from the limit catalog (`limit-catalog.ts`), the one place that holds the numbers
|
|
24
|
+
// (decision 79). The types check that the catalog's `build` group is exactly `PlanLimits`.
|
|
25
|
+
const table = catalogRows("build");
|
|
26
|
+
/**
|
|
27
|
+
* The limits of every plan, by plan id.
|
|
28
|
+
*
|
|
29
|
+
* Inputs: none. Output: deeply frozen rows. Errors: none. Side effects: none.
|
|
30
|
+
*/
|
|
31
|
+
export const planLimits = deepFreeze(table);
|
|
32
|
+
/**
|
|
33
|
+
* Whether a value names a plan.
|
|
34
|
+
*
|
|
35
|
+
* Inputs: any value. Output: `true` for a key of `planLimits` (not inherited names such as
|
|
36
|
+
* `constructor`). Errors: none. Side effects: none.
|
|
37
|
+
*/
|
|
38
|
+
export function isPlanId(value) {
|
|
39
|
+
return typeof value === "string" && Object.hasOwn(planLimits, value);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* The limits of a plan, falling back to the default plan.
|
|
43
|
+
*
|
|
44
|
+
* Inputs: a plan id, or `undefined` for a workspace (or build) without one. Output: that plan's
|
|
45
|
+
* row, `planLimits[DEFAULT_PLAN_ID]` for `undefined` or an unknown id. Errors: none. Side
|
|
46
|
+
* effects: none.
|
|
47
|
+
*/
|
|
48
|
+
export function limitsOfPlan(planId) {
|
|
49
|
+
const id = isPlanId(planId) ? planId : DEFAULT_PLAN_ID;
|
|
50
|
+
return { planId: id, limits: planLimits[id] };
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* The plan with the lowest value above `current` for one limit, so a `LIMIT_EXCEEDED` diagnostic
|
|
54
|
+
* can say how to raise it.
|
|
55
|
+
*
|
|
56
|
+
* Inputs: the limit, the value the build had and (for tests) the table. Output: the plan id and
|
|
57
|
+
* its value, or `undefined` when no plan allows more. Errors: none. Side effects: none.
|
|
58
|
+
*/
|
|
59
|
+
export function planAbove(limit, current, plans = planLimits) {
|
|
60
|
+
let best;
|
|
61
|
+
for (const [planId, limits] of Object.entries(plans)) {
|
|
62
|
+
const value = limits[limit];
|
|
63
|
+
if (value > current && (best === undefined || value < best.value))
|
|
64
|
+
best = { planId, value };
|
|
65
|
+
}
|
|
66
|
+
return best;
|
|
67
|
+
}
|
|
68
|
+
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
69
|
+
/**
|
|
70
|
+
* Whole seconds from `now` to the next UTC midnight (at least 1): the `Retry-After` of every
|
|
71
|
+
* per-UTC-day limit.
|
|
72
|
+
*
|
|
73
|
+
* Inputs: the current time. Output: seconds. Errors: none. Side effects: none.
|
|
74
|
+
*/
|
|
75
|
+
export function secondsUntilNextUtcDay(now) {
|
|
76
|
+
const nextMidnight = (Math.floor(now.getTime() / DAY_MS) + 1) * DAY_MS;
|
|
77
|
+
return Math.max(1, Math.ceil((nextMidnight - now.getTime()) / 1000));
|
|
78
|
+
}
|
|
79
|
+
/** The window of `buildsPerWeek`: a rolling 7 days (decision 78). */
|
|
80
|
+
export const BUILD_WINDOW_MS = 7 * DAY_MS;
|
|
81
|
+
/**
|
|
82
|
+
* When the rolling 7-day window frees one place (`POST /builds` answers 429 with
|
|
83
|
+
* `Retry-After: retryAfterSeconds` at the limit).
|
|
84
|
+
*
|
|
85
|
+
* Inputs: the creation moment of the build that must age out for one more to fit (the
|
|
86
|
+
* `used - limit + 1`-th oldest of the window; the registry finds it) and the current time.
|
|
87
|
+
* Output: that moment plus 7 days and the whole seconds to wait (at least 1). Errors: none. Side
|
|
88
|
+
* effects: none.
|
|
89
|
+
*/
|
|
90
|
+
export function buildWindowReset(freeingBuildCreatedAt, now) {
|
|
91
|
+
const resetsAt = new Date(freeingBuildCreatedAt.getTime() + BUILD_WINDOW_MS);
|
|
92
|
+
const retryAfterSeconds = Math.max(1, Math.ceil((resetsAt.getTime() - now.getTime()) / 1000));
|
|
93
|
+
return { resetsAt, retryAfterSeconds };
|
|
94
|
+
}
|
|
95
|
+
const quotaTable = catalogRows("quota");
|
|
96
|
+
/**
|
|
97
|
+
* The quotas of every plan, by plan id; kept apart from `planLimits` because the builder wording
|
|
98
|
+
* (`LIMIT_EXCEEDED` diagnostics) covers every key of that one.
|
|
99
|
+
*
|
|
100
|
+
* Inputs: none. Output: deeply frozen rows. Errors: none. Side effects: none.
|
|
101
|
+
*/
|
|
102
|
+
export const planQuotas = deepFreeze(quotaTable);
|
|
103
|
+
/**
|
|
104
|
+
* The quotas of a plan, falling back to the default plan.
|
|
105
|
+
*
|
|
106
|
+
* Inputs: a plan id or `undefined`. Output: that plan's row, the default plan's for `undefined` or
|
|
107
|
+
* an unknown id. Errors: none. Side effects: none.
|
|
108
|
+
*/
|
|
109
|
+
export function quotasOfPlan(planId) {
|
|
110
|
+
return planQuotas[isPlanId(planId) ? planId : DEFAULT_PLAN_ID];
|
|
111
|
+
}
|
|
112
|
+
//# sourceMappingURL=plan-limits.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plan-limits.js","sourceRoot":"","sources":["../src/plan-limits.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,QAAQ,EAAe,MAAM,eAAe,CAAC;AAEtD,OAAO,EAAE,QAAQ,EAAe,CAAC;AAEjC,4FAA4F;AAC5F,MAAM,CAAC,MAAM,eAAe,GAAW,MAAM,CAAC;AAiC9C,kGAAkG;AAClG,2FAA2F;AAC3F,MAAM,KAAK,GAA+B,WAAW,CAAC,OAAO,CAAC,CAAC;AAE/D;;;;GAIG;AACH,MAAM,CAAC,MAAM,UAAU,GAAyC,UAAU,CAAC,KAAK,CAAC,CAAC;AAElF;;;;;GAKG;AACH,MAAM,UAAU,QAAQ,CAAC,KAAc;IACrC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;AACvE,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAAC,MAA0B;IAIrD,MAAM,EAAE,GAAG,QAAQ,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