@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,145 @@
|
|
|
1
|
+
import type { PlanId } from "./plan-limits.js";
|
|
2
|
+
import { type OverageMetric } from "./limit-catalog.js";
|
|
3
|
+
/** An amount in US dollar cents, per month and per year (billed once a year). */
|
|
4
|
+
export interface PlanMoney {
|
|
5
|
+
readonly monthly: number;
|
|
6
|
+
readonly annual: number;
|
|
7
|
+
}
|
|
8
|
+
/** The Agency's growth past its included sites: one more site costs money and raises two ceilings. */
|
|
9
|
+
export interface PlanSiteExtension {
|
|
10
|
+
/** Sites in the plan's price (the plan's `maxSites` quota). */
|
|
11
|
+
readonly includedSites: number;
|
|
12
|
+
/** The most sites with add-ons. */
|
|
13
|
+
readonly maxSites: number;
|
|
14
|
+
readonly extraSitePriceUsdCents: PlanMoney;
|
|
15
|
+
/** What each extra site adds to the monthly renders ceiling. */
|
|
16
|
+
readonly rendersPerExtraSite: number;
|
|
17
|
+
/** What each extra site adds to the monthly submissions ceiling. */
|
|
18
|
+
readonly submissionsPerExtraSite: number;
|
|
19
|
+
}
|
|
20
|
+
/** The price of one plan and its site extension (null when the plan has none). */
|
|
21
|
+
export interface PlanPricing {
|
|
22
|
+
readonly priceUsdCents: PlanMoney;
|
|
23
|
+
readonly siteExtension: PlanSiteExtension | null;
|
|
24
|
+
}
|
|
25
|
+
/** The pricing of every plan, by plan id. Frozen. */
|
|
26
|
+
export declare const planPricing: Readonly<Record<PlanId, PlanPricing>>;
|
|
27
|
+
/** A plan that pays: the only ones that can have an overage. */
|
|
28
|
+
export type PaidPlanId = Exclude<PlanId, "free">;
|
|
29
|
+
/**
|
|
30
|
+
* What one billed unit is: `unit` is one counted thing; `mb` is one megabyte (10^6 bytes) held at the
|
|
31
|
+
* average of the cycle's daily readings (storage: US$ 1,00 per GB-month is 1000 micro USD per MB, a whole number).
|
|
32
|
+
*/
|
|
33
|
+
export type OverageUnit = "unit" | "mb";
|
|
34
|
+
/**
|
|
35
|
+
* The price of one billed metric. Money is in micro US dollars (10^-6 USD) per unit, an integer, so
|
|
36
|
+
* US$ 0,02 per 1.000 renders is exactly 20 per render with no float. Free has no rate: it is cut.
|
|
37
|
+
*/
|
|
38
|
+
export interface OverageRate {
|
|
39
|
+
readonly metric: OverageMetric;
|
|
40
|
+
readonly unit: OverageUnit;
|
|
41
|
+
readonly microUsdPerUnit: Readonly<Record<PaidPlanId, number>>;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* THE SEED of the rate table (TAG-1629, owner 2026-11-14): the tariffs live in the database
|
|
45
|
+
* (`overage_rates`, versions with an effective date, edited by staff with a reason) and this table
|
|
46
|
+
* is only what migration 0081 inserted as version 1 and what every reader falls back to when the
|
|
47
|
+
* database cannot be read. A test compares it with the migration; nothing else reads it for a price.
|
|
48
|
+
*
|
|
49
|
+
* The tariffs of decision 84 (provisional, pendency 76), in micro USD per unit:
|
|
50
|
+
* renders US$ 0,02 per 1.000; SSR renders US$ 0,015 per 1.000; SSR version-day US$ 0,01 (no
|
|
51
|
+
* included amount in v1); build over the weekly limit US$ 0,01; stored submission US$ 0,25 per
|
|
52
|
+
* 1.000; storage US$ 1,00 per GB-month (1000 per MB, raised from 0,35 on 2026-11-15 by the owner; migration 0097, on the average of the cycle's daily readings); extra site US$ 1 (Pro) and US$ 2 (Agency, the existing
|
|
53
|
+
* add-on price, billed on the plan subscription, so its overage rate is informational).
|
|
54
|
+
*/
|
|
55
|
+
export declare const OVERAGE_RATES: Readonly<Record<OverageMetric, OverageRate>>;
|
|
56
|
+
/** The metrics in a fixed order (ledger and Stripe meters follow it). */
|
|
57
|
+
export declare const OVERAGE_METRIC_LIST: readonly OverageMetric[];
|
|
58
|
+
/**
|
|
59
|
+
* The rules around the money of an overage (decision 84, ADR 0067), numbers only:
|
|
60
|
+
* - `minInvoiceUsdCents`: below it the amount carries to the next month.
|
|
61
|
+
* - `lagHours`: the ledger bills what was counted at least this long ago, never the live count.
|
|
62
|
+
* - NO default spending limit (owner, 2026-11-14, TAG-1629): the customer pays what they use. A
|
|
63
|
+
* spending LIMIT is OPTIONAL, set by the customer or by staff, between `spendCapMinUsdCents` and
|
|
64
|
+
* `spendCapMaxUsdCents` (staff: `staffSpendCapMaxUsdCents`). It is a trigger, not a ceiling on the
|
|
65
|
+
* bill: Taggor TRIES to stop the use when the overage reaches it, WITHOUT guarantee, and what was
|
|
66
|
+
* really used is billed. `capNoticePercents` are the e-mails of a limit that exists.
|
|
67
|
+
* - Spend milestones: the customer warns themselves at amounts of overage accrued in a cycle, one
|
|
68
|
+
* e-mail per milestone per cycle. `spendMilestonePercents` are the named steps of the DEFAULT list
|
|
69
|
+
* (percent of the plan's monthly price: 50%, 100%, 200%, 500%); from there it keeps going, doubling
|
|
70
|
+
* from `spendMilestoneDoublingFrom` (1000%, 2000%, 4000%...) up to `maxSpendMilestones` milestones
|
|
71
|
+
* in all (`defaultSpendMilestonePercents`), so a runaway use keeps warning past 500% (TAG-1629
|
|
72
|
+
* review M4). The customer may set their own list of up to `maxSpendMilestones` amounts, each at
|
|
73
|
+
* most `spendMilestoneMaxUsdCents`.
|
|
74
|
+
* - `dunningDays`: how long an unpaid overage invoice is chased before new overage is suspended.
|
|
75
|
+
* - `freeCutMultiple`: Free is cut at this multiple of its number (1x, no grace).
|
|
76
|
+
*/
|
|
77
|
+
export declare const OVERAGE_RULES: Readonly<{
|
|
78
|
+
minInvoiceUsdCents: 100;
|
|
79
|
+
lagHours: 48;
|
|
80
|
+
spendCapMinUsdCents: 100;
|
|
81
|
+
spendCapMaxUsdCents: 1000000;
|
|
82
|
+
staffSpendCapMaxUsdCents: 10000000;
|
|
83
|
+
capNoticePercents: readonly number[];
|
|
84
|
+
spendMilestonePercents: readonly number[];
|
|
85
|
+
spendMilestoneDoublingFrom: 1000;
|
|
86
|
+
maxSpendMilestones: 10;
|
|
87
|
+
spendMilestoneMaxUsdCents: 1000000;
|
|
88
|
+
dunningDays: 14;
|
|
89
|
+
freeCutMultiple: 1;
|
|
90
|
+
}>;
|
|
91
|
+
/**
|
|
92
|
+
* The DEFAULT spend milestones as percents of the plan's monthly price: the named steps, then
|
|
93
|
+
* doubling from `spendMilestoneDoublingFrom` until `maxSpendMilestones` are listed (50, 100, 200, 500,
|
|
94
|
+
* 1000, 2000, 4000, 8000, 16000, 32000). Inputs: none. Output: a new ascending list. Pure.
|
|
95
|
+
*/
|
|
96
|
+
export declare function defaultSpendMilestonePercents(): readonly number[];
|
|
97
|
+
/**
|
|
98
|
+
* The rate of a metric for a paid plan.
|
|
99
|
+
* Inputs: a metric and a plan id. Output: micro USD per unit, or `null` for Free (it never pays an
|
|
100
|
+
* overage). Errors: none. No side effects.
|
|
101
|
+
*/
|
|
102
|
+
export declare function overageMicroUsdPerUnit(metric: OverageMetric, planId: PlanId): number | null;
|
|
103
|
+
/**
|
|
104
|
+
* Which of the forgeable metrics are billed (TAG-1628 review M1 and L2, ADR 0067 item 8; ON since
|
|
105
|
+
* TAG-1629, decision 84 amendment of 2026-11-14). A render and a stored submission can be forged by
|
|
106
|
+
* anyone with the public site key, so they were kept off the bill until a guard existed. The owner
|
|
107
|
+
* decided that a customer pays what was used, so the three metrics are billed; the guard (a spike
|
|
108
|
+
* flag per site, `usage-guard.ts`) no longer holds anything back, it only keeps the Free plan from
|
|
109
|
+
* being cut by forged traffic and warns the customer of an unusual day, and the safety net for a wrong
|
|
110
|
+
* bill is the credit on request (runbook). The switch stays in ONE place: the billing code of the API
|
|
111
|
+
* derives its `OVERAGE_BILLING_FROM_*` constants from it, and the site, the portal and the CLI choose
|
|
112
|
+
* their wording by `isOverageMetricBilled`, so a switch changes the code and every text together. A
|
|
113
|
+
* gate only has an effect while the API's overage mode is not `off`. Changing it is an
|
|
114
|
+
* ADR-level decision, never a drive-by edit.
|
|
115
|
+
*/
|
|
116
|
+
export interface OverageBillingGates {
|
|
117
|
+
/** The renders metric (`loader_hits`). */
|
|
118
|
+
readonly loaderHits: boolean;
|
|
119
|
+
/** The submissions metric and the storage that follows it. */
|
|
120
|
+
readonly submissions: boolean;
|
|
121
|
+
}
|
|
122
|
+
/** The gates as the code ships them: both on (TAG-1629); frozen, the literal types are `true`. */
|
|
123
|
+
export declare const OVERAGE_BILLING_GATES: Readonly<{
|
|
124
|
+
readonly loaderHits: true;
|
|
125
|
+
readonly submissions: true;
|
|
126
|
+
}>;
|
|
127
|
+
/**
|
|
128
|
+
* Whether the excess of a metric is billed automatically (and so spends the customer's cap, raises a
|
|
129
|
+
* cap notice and counts in the cost estimate). Renders when `gates.loaderHits`; submissions and
|
|
130
|
+
* storage when `gates.submissions`; builds, extra sites and SSR always.
|
|
131
|
+
* Inputs: a metric and the gates (default: as shipped). Output: a boolean. Pure.
|
|
132
|
+
*/
|
|
133
|
+
export declare function isOverageMetricBilled(metric: OverageMetric, gates?: OverageBillingGates): boolean;
|
|
134
|
+
/**
|
|
135
|
+
* Whether going past a catalog limit is billed automatically today on a paid plan: the limit is
|
|
136
|
+
* `metered` on Pro (Agency matches) and its metric is billed (`isOverageMetricBilled`). A limit that
|
|
137
|
+
* is `hard` on every plan (a security or per-build cap), an unknown name and a metered limit whose
|
|
138
|
+
* metric's gate is off are all false. The portal and the CLI
|
|
139
|
+
* word a limit row with it.
|
|
140
|
+
* Inputs: a limit name (any string) and the gates (default: as shipped). Output: a boolean. Pure.
|
|
141
|
+
*/
|
|
142
|
+
export declare function isLimitOverageBilled(name: string, gates?: OverageBillingGates): boolean;
|
|
143
|
+
/** The metrics billed today, in the fixed metric order: derived from the gates, never typed. */
|
|
144
|
+
export declare const BILLED_OVERAGE_METRICS: readonly OverageMetric[];
|
|
145
|
+
//# sourceMappingURL=plan-pricing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plan-pricing.d.ts","sourceRoot":"","sources":["../src/plan-pricing.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAkC,KAAK,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAExF,iFAAiF;AACjF,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED,sGAAsG;AACtG,MAAM,WAAW,iBAAiB;IAChC,+DAA+D;IAC/D,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,mCAAmC;IACnC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,sBAAsB,EAAE,SAAS,CAAC;IAC3C,gEAAgE;IAChE,QAAQ,CAAC,mBAAmB,EAAE,MAAM,CAAC;IACrC,oEAAoE;IACpE,QAAQ,CAAC,uBAAuB,EAAE,MAAM,CAAC;CAC1C;AAED,kFAAkF;AAClF,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,aAAa,EAAE,SAAS,CAAC;IAClC,QAAQ,CAAC,aAAa,EAAE,iBAAiB,GAAG,IAAI,CAAC;CAClD;AAmBD,qDAAqD;AACrD,eAAO,MAAM,WAAW,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAI5D,CAAC;AAEH,gEAAgE;AAChE,MAAM,MAAM,UAAU,GAAG,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAEjD;;;GAGG;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,IAAI,C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@
|
|
|
1
|
+
/**
|
|
2
|
+
* What each plan COSTS, the Agency site extension and the overage rates and rules (TAG-1934 P0, from
|
|
3
|
+
* decisions 68 and 71; TAG-1628, decision 84, replaced the cut rule of decisions 69 and 71). Zod-free, frozen, same style as `plan-usage.ts` and `plan-limits.ts`.
|
|
4
|
+
*
|
|
5
|
+
* Why it lives in the contract: the billing catalog (`apps/api/src/domain/billing/plans.ts`) and the
|
|
6
|
+
* public site both need these numbers, and a number written twice drifts. The billing catalog
|
|
7
|
+
* composes its rows from here; the site reads them through its figures registry, so no plan price
|
|
8
|
+
* is typed by hand in site copy.
|
|
9
|
+
*
|
|
10
|
+
* ALL NUMBERS ARE PROVISIONAL until the owner approves the plans and prices
|
|
11
|
+
* (docs/pricing/planos-e-limites-proposta.md v3). Money is US dollar cents (decision 68 item 1).
|
|
12
|
+
* Nothing here charges or cuts; it is a table.
|
|
13
|
+
*
|
|
14
|
+
* TAG-1628 (decision 84, ADR 0067): the overage rate table below (`OVERAGE_RATES`) is the ONE place
|
|
15
|
+
* the price of a unit above the plan is written; the site, the portal, the API and the Stripe
|
|
16
|
+
* prices read it. Rates are PROVISIONAL until the owner answers pendency 76.
|
|
17
|
+
*/
|
|
18
|
+
import { planQuotas } from "./plan-limits.js";
|
|
19
|
+
import { LIMIT_CATALOG, OVERAGE_METRICS } from "./limit-catalog.js";
|
|
20
|
+
const money = (monthly, annual) => Object.freeze({ monthly, annual });
|
|
21
|
+
const table = {
|
|
22
|
+
free: { priceUsdCents: money(0, 0), siteExtension: null },
|
|
23
|
+
pro: { priceUsdCents: money(1400, 14_000), siteExtension: null },
|
|
24
|
+
agency: {
|
|
25
|
+
priceUsdCents: money(4900, 49_000),
|
|
26
|
+
siteExtension: Object.freeze({
|
|
27
|
+
includedSites: planQuotas.agency.maxSites,
|
|
28
|
+
maxSites: 500,
|
|
29
|
+
extraSitePriceUsdCents: money(200, 2000),
|
|
30
|
+
rendersPerExtraSite: 100_000,
|
|
31
|
+
submissionsPerExtraSite: 4000,
|
|
32
|
+
}),
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
/** The pricing of every plan, by plan id. Frozen. */
|
|
36
|
+
export const planPricing = Object.freeze({
|
|
37
|
+
free: Object.freeze(table.free),
|
|
38
|
+
pro: Object.freeze(table.pro),
|
|
39
|
+
agency: Object.freeze(table.agency),
|
|
40
|
+
});
|
|
41
|
+
const bothPaid = (value) => Object.freeze({ pro: value, agency: value });
|
|
42
|
+
/**
|
|
43
|
+
* THE SEED of the rate table (TAG-1629, owner 2026-11-14): the tariffs live in the database
|
|
44
|
+
* (`overage_rates`, versions with an effective date, edited by staff with a reason) and this table
|
|
45
|
+
* is only what migration 0081 inserted as version 1 and what every reader falls back to when the
|
|
46
|
+
* database cannot be read. A test compares it with the migration; nothing else reads it for a price.
|
|
47
|
+
*
|
|
48
|
+
* The tariffs of decision 84 (provisional, pendency 76), in micro USD per unit:
|
|
49
|
+
* renders US$ 0,02 per 1.000; SSR renders US$ 0,015 per 1.000; SSR version-day US$ 0,01 (no
|
|
50
|
+
* included amount in v1); build over the weekly limit US$ 0,01; stored submission US$ 0,25 per
|
|
51
|
+
* 1.000; storage US$ 1,00 per GB-month (1000 per MB, raised from 0,35 on 2026-11-15 by the owner; migration 0097, on the average of the cycle's daily readings); extra site US$ 1 (Pro) and US$ 2 (Agency, the existing
|
|
52
|
+
* add-on price, billed on the plan subscription, so its overage rate is informational).
|
|
53
|
+
*/
|
|
54
|
+
export const OVERAGE_RATES = Object.freeze({
|
|
55
|
+
renders: Object.freeze({ metric: "renders", unit: "unit", microUsdPerUnit: bothPaid(20) }),
|
|
56
|
+
ssr_renders: Object.freeze({
|
|
57
|
+
metric: "ssr_renders",
|
|
58
|
+
unit: "unit",
|
|
59
|
+
microUsdPerUnit: bothPaid(15),
|
|
60
|
+
}),
|
|
61
|
+
ssr_version_days: Object.freeze({
|
|
62
|
+
metric: "ssr_version_days",
|
|
63
|
+
unit: "unit",
|
|
64
|
+
microUsdPerUnit: bothPaid(10_000),
|
|
65
|
+
}),
|
|
66
|
+
builds: Object.freeze({ metric: "builds", unit: "unit", microUsdPerUnit: bothPaid(10_000) }),
|
|
67
|
+
submissions: Object.freeze({
|
|
68
|
+
metric: "submissions",
|
|
69
|
+
unit: "unit",
|
|
70
|
+
microUsdPerUnit: bothPaid(250),
|
|
71
|
+
}),
|
|
72
|
+
storage: Object.freeze({
|
|
73
|
+
metric: "storage",
|
|
74
|
+
unit: "mb",
|
|
75
|
+
microUsdPerUnit: bothPaid(1000),
|
|
76
|
+
}),
|
|
77
|
+
extra_sites: Object.freeze({
|
|
78
|
+
metric: "extra_sites",
|
|
79
|
+
unit: "unit",
|
|
80
|
+
microUsdPerUnit: Object.freeze({ pro: 1_000_000, agency: 2_000_000 }),
|
|
81
|
+
}),
|
|
82
|
+
});
|
|
83
|
+
/** The metrics in a fixed order (ledger and Stripe meters follow it). */
|
|
84
|
+
export const OVERAGE_METRIC_LIST = OVERAGE_METRICS;
|
|
85
|
+
/**
|
|
86
|
+
* The rules around the money of an overage (decision 84, ADR 0067), numbers only:
|
|
87
|
+
* - `minInvoiceUsdCents`: below it the amount carries to the next month.
|
|
88
|
+
* - `lagHours`: the ledger bills what was counted at least this long ago, never the live count.
|
|
89
|
+
* - NO default spending limit (owner, 2026-11-14, TAG-1629): the customer pays what they use. A
|
|
90
|
+
* spending LIMIT is OPTIONAL, set by the customer or by staff, between `spendCapMinUsdCents` and
|
|
91
|
+
* `spendCapMaxUsdCents` (staff: `staffSpendCapMaxUsdCents`). It is a trigger, not a ceiling on the
|
|
92
|
+
* bill: Taggor TRIES to stop the use when the overage reaches it, WITHOUT guarantee, and what was
|
|
93
|
+
* really used is billed. `capNoticePercents` are the e-mails of a limit that exists.
|
|
94
|
+
* - Spend milestones: the customer warns themselves at amounts of overage accrued in a cycle, one
|
|
95
|
+
* e-mail per milestone per cycle. `spendMilestonePercents` are the named steps of the DEFAULT list
|
|
96
|
+
* (percent of the plan's monthly price: 50%, 100%, 200%, 500%); from there it keeps going, doubling
|
|
97
|
+
* from `spendMilestoneDoublingFrom` (1000%, 2000%, 4000%...) up to `maxSpendMilestones` milestones
|
|
98
|
+
* in all (`defaultSpendMilestonePercents`), so a runaway use keeps warning past 500% (TAG-1629
|
|
99
|
+
* review M4). The customer may set their own list of up to `maxSpendMilestones` amounts, each at
|
|
100
|
+
* most `spendMilestoneMaxUsdCents`.
|
|
101
|
+
* - `dunningDays`: how long an unpaid overage invoice is chased before new overage is suspended.
|
|
102
|
+
* - `freeCutMultiple`: Free is cut at this multiple of its number (1x, no grace).
|
|
103
|
+
*/
|
|
104
|
+
export const OVERAGE_RULES = Object.freeze({
|
|
105
|
+
minInvoiceUsdCents: 100,
|
|
106
|
+
lagHours: 48,
|
|
107
|
+
spendCapMinUsdCents: 100,
|
|
108
|
+
spendCapMaxUsdCents: 1_000_000,
|
|
109
|
+
staffSpendCapMaxUsdCents: 10_000_000,
|
|
110
|
+
capNoticePercents: Object.freeze([80, 100]),
|
|
111
|
+
spendMilestonePercents: Object.freeze([50, 100, 200, 500]),
|
|
112
|
+
spendMilestoneDoublingFrom: 1000,
|
|
113
|
+
maxSpendMilestones: 10,
|
|
114
|
+
spendMilestoneMaxUsdCents: 1_000_000,
|
|
115
|
+
dunningDays: 14,
|
|
116
|
+
freeCutMultiple: 1,
|
|
117
|
+
});
|
|
118
|
+
/**
|
|
119
|
+
* The DEFAULT spend milestones as percents of the plan's monthly price: the named steps, then
|
|
120
|
+
* doubling from `spendMilestoneDoublingFrom` until `maxSpendMilestones` are listed (50, 100, 200, 500,
|
|
121
|
+
* 1000, 2000, 4000, 8000, 16000, 32000). Inputs: none. Output: a new ascending list. Pure.
|
|
122
|
+
*/
|
|
123
|
+
export function defaultSpendMilestonePercents() {
|
|
124
|
+
const list = [...OVERAGE_RULES.spendMilestonePercents];
|
|
125
|
+
for (let next = OVERAGE_RULES.spendMilestoneDoublingFrom; list.length < OVERAGE_RULES.maxSpendMilestones; next *= 2) {
|
|
126
|
+
list.push(next);
|
|
127
|
+
}
|
|
128
|
+
return list;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* The rate of a metric for a paid plan.
|
|
132
|
+
* Inputs: a metric and a plan id. Output: micro USD per unit, or `null` for Free (it never pays an
|
|
133
|
+
* overage). Errors: none. No side effects.
|
|
134
|
+
*/
|
|
135
|
+
export function overageMicroUsdPerUnit(metric, planId) {
|
|
136
|
+
// Free has no entry in the table: the lookup, not a comparison by name, makes it unbillable.
|
|
137
|
+
const rates = OVERAGE_RATES[metric].microUsdPerUnit;
|
|
138
|
+
return rates[planId] ?? null;
|
|
139
|
+
}
|
|
140
|
+
/** The gates as the code ships them: both on (TAG-1629); frozen, the literal types are `true`. */
|
|
141
|
+
export const OVERAGE_BILLING_GATES = Object.freeze({
|
|
142
|
+
loaderHits: true,
|
|
143
|
+
submissions: true,
|
|
144
|
+
});
|
|
145
|
+
/**
|
|
146
|
+
* Whether the excess of a metric is billed automatically (and so spends the customer's cap, raises a
|
|
147
|
+
* cap notice and counts in the cost estimate). Renders when `gates.loaderHits`; submissions and
|
|
148
|
+
* storage when `gates.submissions`; builds, extra sites and SSR always.
|
|
149
|
+
* Inputs: a metric and the gates (default: as shipped). Output: a boolean. Pure.
|
|
150
|
+
*/
|
|
151
|
+
export function isOverageMetricBilled(metric, gates = OVERAGE_BILLING_GATES) {
|
|
152
|
+
if (metric === "renders")
|
|
153
|
+
return gates.loaderHits;
|
|
154
|
+
if (metric === "submissions" || metric === "storage")
|
|
155
|
+
return gates.submissions;
|
|
156
|
+
return true;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Whether going past a catalog limit is billed automatically today on a paid plan: the limit is
|
|
160
|
+
* `metered` on Pro (Agency matches) and its metric is billed (`isOverageMetricBilled`). A limit that
|
|
161
|
+
* is `hard` on every plan (a security or per-build cap), an unknown name and a metered limit whose
|
|
162
|
+
* metric's gate is off are all false. The portal and the CLI
|
|
163
|
+
* word a limit row with it.
|
|
164
|
+
* Inputs: a limit name (any string) and the gates (default: as shipped). Output: a boolean. Pure.
|
|
165
|
+
*/
|
|
166
|
+
export function isLimitOverageBilled(name, gates = OVERAGE_BILLING_GATES) {
|
|
167
|
+
const policy = LIMIT_CATALOG.find((spec) => spec.name === name)?.policy.pro;
|
|
168
|
+
return policy?.mode === "metered" && isOverageMetricBilled(policy.metric, gates);
|
|
169
|
+
}
|
|
170
|
+
/** The metrics billed today, in the fixed metric order: derived from the gates, never typed. */
|
|
171
|
+
export const BILLED_OVERAGE_METRICS = Object.freeze(OVERAGE_METRICS.filter((metric) => isOverageMetricBilled(metric)));
|
|
172
|
+
//# sourceMappingURL=plan-pricing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plan-pricing.js","sourceRoot":"","sources":["../src/plan-pricing.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,OAAO,EAAE,aAAa,EAAE,eAAe,EAAsB,MAAM,oBAAoB,CAAC;AA2BxF,MAAM,KAAK,GAAG,CAAC,OAAe,EAAE,MAAc,EAAa,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC;AAEjG,MAAM,KAAK,GAAG;IACZ,IAAI,EAAE,EAAE,aAAa,EAAE,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,aAAa,EAAE,IAAI,EAAE;IACzD,GAAG,EAAE,EAAE,aAAa,EAAE,KAAK,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE,aAAa,EAAE,IAAI,EAAE;IAChE,MAAM,EAAE;QACN,aAAa,EAAE,KAAK,CAAC,IAAI,EAAE,MAAM,CAAC;QAClC,aAAa,EAAE,MAAM,CAAC,MAAM,CAAC;YAC3B,aAAa,EAAE,UAAU,CAAC,MAAM,CAAC,QAAQ;YACzC,QAAQ,EAAE,GAAG;YACb,sBAAs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AC;AAED,gGAAgG;AAChG,MAAM,CAAC,MAAM,sBAAsB,GAA6B,MAAM,CAAC,MAAM,CAC3E,eAAe,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,qBAAqB,CAAC,MAAM,CAAC,CAAC,CAClE,CAAC"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { type PlanId } from "./plan-limits.js";
|
|
2
|
+
/** What one plan allows in a UTC month, and how long submissions are kept. Sizes are bytes. */
|
|
3
|
+
export interface PlanUsage {
|
|
4
|
+
/** Loader deliveries that count toward the plan (`countsTowardUsage`), the proxy of renders. */
|
|
5
|
+
readonly rendersPerMonth: number;
|
|
6
|
+
/** Server renders of `GET /r/` (cache misses the edge rendered) in the month (ADR 0066). */
|
|
7
|
+
readonly ssrRendersPerMonth: number;
|
|
8
|
+
/** Submissions accepted (not spam, not from a staging site). */
|
|
9
|
+
readonly submissionsPerMonth: number;
|
|
10
|
+
/** Bytes the submissions of the workspace hold (the JSON of `data`). */
|
|
11
|
+
readonly storageBytes: number;
|
|
12
|
+
/**
|
|
13
|
+
* The most days a submission lives (decision 68, item 11: 12, 24 and 36 months). A collection
|
|
14
|
+
* may choose fewer days, never more (TAG-713).
|
|
15
|
+
*/
|
|
16
|
+
readonly retentionDays: number;
|
|
17
|
+
}
|
|
18
|
+
/** The usage allowance of every plan, by plan id. Frozen. */
|
|
19
|
+
export declare const planUsage: Readonly<Record<PlanId, PlanUsage>>;
|
|
20
|
+
/** The percentages of an allowance at which a customer is warned (decision 69: 80% and 100%). */
|
|
21
|
+
export declare const USAGE_WARNING_PERCENTS: readonly [80, 100];
|
|
22
|
+
/**
|
|
23
|
+
* Where a count stands against its allowance. `ok` below 80%, `warning` from 80%, `reached` from
|
|
24
|
+
* 100%. Nothing acts on it in this ticket; TAG-1607 adds grace and the rest.
|
|
25
|
+
*/
|
|
26
|
+
export declare const USAGE_LEVELS: readonly ["ok", "warning", "reached"];
|
|
27
|
+
export type UsageLevel = (typeof USAGE_LEVELS)[number];
|
|
28
|
+
/**
|
|
29
|
+
* The share of an allowance a count uses.
|
|
30
|
+
* Inputs: the count and the limit. Output: whole percent, rounded down (so 79.9% is still 79 and
|
|
31
|
+
* does not warn early); 0 for a limit of 0 or less. Errors: none. No side effects.
|
|
32
|
+
*/
|
|
33
|
+
export declare function usagePercent(used: number, limit: number): number;
|
|
34
|
+
/**
|
|
35
|
+
* The level of a count.
|
|
36
|
+
* Inputs: the count and the limit. Output: `reached` at 100% or more, `warning` at 80% or more,
|
|
37
|
+
* `ok` otherwise. Errors: none. No side effects.
|
|
38
|
+
*/
|
|
39
|
+
export declare function usageLevel(used: number, limit: number): UsageLevel;
|
|
40
|
+
/**
|
|
41
|
+
* The rule that marks a site's render count as suspect (security review of TAG-801): the key of a
|
|
42
|
+
* site and its allowed domains are public, so anyone can forge loader hits with a `Referer` and a
|
|
43
|
+
* `User-Agent`. A day with more than `multiplier` times the mean of the `baselineDays` days before
|
|
44
|
+
* it, and at least `minViews`, is a spike. PROVISIONAL, owner-confirmable.
|
|
45
|
+
*
|
|
46
|
+
* What it does NOT catch: a slow ramp (each day under `multiplier` times the days before it) and
|
|
47
|
+
* steady traffic below `minViews` a day. `minViews` here is only the ceiling of the floor; the
|
|
48
|
+
* plan's own floor is `spikeMinViews`, so steady forging is bounded by the plan (at most about
|
|
49
|
+
* `rendersPerMonth` in a month) instead of by a fixed 1,000 a day. The guard is a brake on sudden
|
|
50
|
+
* spikes, not proof of authenticity: nothing may cut a component for renders without a person
|
|
51
|
+
* having looked (TAG-1607).
|
|
52
|
+
*/
|
|
53
|
+
export declare const VIEW_SPIKE_RULE: Readonly<{
|
|
54
|
+
multiplier: 10;
|
|
55
|
+
baselineDays: 7;
|
|
56
|
+
/** The most a day's floor is, whatever the plan; see `spikeMinViews`. */
|
|
57
|
+
minViews: 1000;
|
|
58
|
+
}>;
|
|
59
|
+
/** A spike rule with its own floor. */
|
|
60
|
+
export interface ViewSpikeRule {
|
|
61
|
+
readonly multiplier: number;
|
|
62
|
+
readonly baselineDays: number;
|
|
63
|
+
readonly minViews: number;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* The daily floor of a plan: a day below it is never a spike.
|
|
67
|
+
* Inputs: the plan's renders per month. Output: the lower of `VIEW_SPIKE_RULE.minViews` and a
|
|
68
|
+
* thirtieth of the month (at least 1), so quietly forging the plan's whole month in 30 equal days
|
|
69
|
+
* is a spike on the first day that passes the floor rather than going unseen. Errors: none. No
|
|
70
|
+
* side effects.
|
|
71
|
+
*/
|
|
72
|
+
export declare function spikeMinViews(rendersPerMonth: number): number;
|
|
73
|
+
/**
|
|
74
|
+
* The spike rule of a plan. Inputs: a plan id (unknown: the default plan). Output: the rule with
|
|
75
|
+
* the plan's floor. Errors: none. No side effects.
|
|
76
|
+
*/
|
|
77
|
+
export declare function spikeRuleOf(planId: string | undefined): ViewSpikeRule;
|
|
78
|
+
/** Counted deliveries of one UTC day. */
|
|
79
|
+
export interface DailyViews {
|
|
80
|
+
/** `YYYY-MM-DD`, UTC. */
|
|
81
|
+
readonly day: string;
|
|
82
|
+
readonly views: number;
|
|
83
|
+
}
|
|
84
|
+
/** A day that broke the rule. */
|
|
85
|
+
export interface ViewSpike {
|
|
86
|
+
readonly day: string;
|
|
87
|
+
readonly views: number;
|
|
88
|
+
/** The mean of the baseline days (the days of the window without data count as zero). */
|
|
89
|
+
readonly baselineMean: number;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Every day of a series that is a spike, earliest first.
|
|
93
|
+
* Inputs: the counted views per UTC day (any order; a missing day is zero), the current time, the
|
|
94
|
+
* rule and the first day to examine (default: yesterday, so today, still partial, and yesterday are
|
|
95
|
+
* looked at). Output: the spikes among the days from `from` to today, each day against the mean of
|
|
96
|
+
* the `baselineDays` days before it (possibly none). All of them, not the first: a spike a person
|
|
97
|
+
* already judged `legit` must not hide a later one. A caller that measures a workspace only
|
|
98
|
+
* every few hours passes the first day of the month, so a spike that happened between two visits
|
|
99
|
+
* is still found. Days before the series count as zero: give it `baselineDays` days before `from`.
|
|
100
|
+
* Errors: none. No side effects.
|
|
101
|
+
*/
|
|
102
|
+
export declare function detectViewSpikes(series: readonly DailyViews[], now: Date, rule?: ViewSpikeRule, from?: Date): ViewSpike[];
|
|
103
|
+
/**
|
|
104
|
+
* The first spike of `detectViewSpikes`, or `null`. Same inputs. Errors: none. No side effects.
|
|
105
|
+
*/
|
|
106
|
+
export declare function detectViewSpike(series: readonly DailyViews[], now: Date, rule?: ViewSpikeRule, from?: Date): ViewSpike | null;
|
|
107
|
+
/**
|
|
108
|
+
* The usage allowance of a plan, falling back to the default plan's for an unknown id.
|
|
109
|
+
* Inputs: a plan id or `undefined`. Output: the plan's row. Errors: none. No side effects.
|
|
110
|
+
*/
|
|
111
|
+
export declare function usageOfPlan(planId: string | undefined): PlanUsage;
|
|
112
|
+
//# sourceMappingURL=plan-usage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plan-usage.d.ts","sourceRoot":"","sources":["../src/plan-usage.ts"],"names":[],"mappings":"AAYA,OAAO,EAAuC,KAAK,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAEpF,+FAA+F;AAC/F,MAAM,WAAW,SAAS;IACxB,gGAAgG;IAChG,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IACjC,4FAA4F;IAC5F,QAAQ,CAAC,kBAAkB,EAAE,MAAM,CAAC;IACpC,gEAAgE;IAChE,QAAQ,CAAC,mBAAmB,EAAE,MAAM,CAAC;IACrC,wEAAwE;IACxE,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B;;;OAGG;IACH,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;CAChC;AAKD,6DAA6D;AAC7D,eAAO,MAAM,SAAS,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAKzD,CAAC;AAEF,iGAAiG;AACjG,eAAO,MAAM,sBAAsB,oBAAoC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,EACrC,IAAI,CAAC,EAAE,IAAI,GACV,SAAS,EAAE,CAkBb;AAED;;GAEG;AACH,wBAAgB,eAAe,CAC7B,MAAM,EAAE,SAAS,UAAU,EAAE,EAC7B,GAAG,EAAE,IAAI,EACT,IAAI,GAAE,aAA+B,EACrC,IAAI,CAAC,EAAE,IAAI,GACV,SAAS,GAAG,IAAI,CAElB;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS,CAEjE"}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What each plan allows a workspace to USE in a month and how long it may KEEP submissions
|
|
3
|
+
* (TAG-712, TAG-713), plus the pure rules that read a count against that allowance. Zod-free.
|
|
4
|
+
*
|
|
5
|
+
* The numbers are a PROPOSAL the owner has not approved (docs/pricing/planos-e-limites-proposta.md,
|
|
6
|
+
* decisions 67 to 69): they live only in `planUsage` and in the two rule constants below, so
|
|
7
|
+
* TAG-1603 (the entitlement catalog) replaces this table in one place and nothing else changes.
|
|
8
|
+
* Measuring is all this module supports: a level here never cuts a component or a submission
|
|
9
|
+
* (that is TAG-1607, under decision 69), and a count of renders that looks forged
|
|
10
|
+
* (`detectViewSpike`) is never a ground for any action until a person has reviewed it.
|
|
11
|
+
*/
|
|
12
|
+
import { catalogRows } from "./limit-catalog.js";
|
|
13
|
+
import { DEFAULT_PLAN_ID, PLAN_IDS, isPlanId } from "./plan-limits.js";
|
|
14
|
+
// The rows come from the limit catalog (`limit-catalog.ts`); the types check the `usage` group.
|
|
15
|
+
const table = catalogRows("usage");
|
|
16
|
+
/** The usage allowance of every plan, by plan id. Frozen. */
|
|
17
|
+
export const planUsage = Object.freeze(Object.fromEntries(PLAN_IDS.map((id) => [id, Object.freeze({ ...table[id] })])));
|
|
18
|
+
/** The percentages of an allowance at which a customer is warned (decision 69: 80% and 100%). */
|
|
19
|
+
export const USAGE_WARNING_PERCENTS = Object.freeze([80, 100]);
|
|
20
|
+
/**
|
|
21
|
+
* Where a count stands against its allowance. `ok` below 80%, `warning` from 80%, `reached` from
|
|
22
|
+
* 100%. Nothing acts on it in this ticket; TAG-1607 adds grace and the rest.
|
|
23
|
+
*/
|
|
24
|
+
export const USAGE_LEVELS = ["ok", "warning", "reached"];
|
|
25
|
+
/**
|
|
26
|
+
* The share of an allowance a count uses.
|
|
27
|
+
* Inputs: the count and the limit. Output: whole percent, rounded down (so 79.9% is still 79 and
|
|
28
|
+
* does not warn early); 0 for a limit of 0 or less. Errors: none. No side effects.
|
|
29
|
+
*/
|
|
30
|
+
export function usagePercent(used, limit) {
|
|
31
|
+
if (!(limit > 0) || !(used > 0))
|
|
32
|
+
return 0;
|
|
33
|
+
return Math.floor((used / limit) * 100);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The level of a count.
|
|
37
|
+
* Inputs: the count and the limit. Output: `reached` at 100% or more, `warning` at 80% or more,
|
|
38
|
+
* `ok` otherwise. Errors: none. No side effects.
|
|
39
|
+
*/
|
|
40
|
+
export function usageLevel(used, limit) {
|
|
41
|
+
const percent = usagePercent(used, limit);
|
|
42
|
+
const [warn, reached] = USAGE_WARNING_PERCENTS;
|
|
43
|
+
if (percent >= reached)
|
|
44
|
+
return "reached";
|
|
45
|
+
return percent >= warn ? "warning" : "ok";
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* The rule that marks a site's render count as suspect (security review of TAG-801): the key of a
|
|
49
|
+
* site and its allowed domains are public, so anyone can forge loader hits with a `Referer` and a
|
|
50
|
+
* `User-Agent`. A day with more than `multiplier` times the mean of the `baselineDays` days before
|
|
51
|
+
* it, and at least `minViews`, is a spike. PROVISIONAL, owner-confirmable.
|
|
52
|
+
*
|
|
53
|
+
* What it does NOT catch: a slow ramp (each day under `multiplier` times the days before it) and
|
|
54
|
+
* steady traffic below `minViews` a day. `minViews` here is only the ceiling of the floor; the
|
|
55
|
+
* plan's own floor is `spikeMinViews`, so steady forging is bounded by the plan (at most about
|
|
56
|
+
* `rendersPerMonth` in a month) instead of by a fixed 1,000 a day. The guard is a brake on sudden
|
|
57
|
+
* spikes, not proof of authenticity: nothing may cut a component for renders without a person
|
|
58
|
+
* having looked (TAG-1607).
|
|
59
|
+
*/
|
|
60
|
+
export const VIEW_SPIKE_RULE = Object.freeze({
|
|
61
|
+
multiplier: 10,
|
|
62
|
+
baselineDays: 7,
|
|
63
|
+
/** The most a day's floor is, whatever the plan; see `spikeMinViews`. */
|
|
64
|
+
minViews: 1000,
|
|
65
|
+
});
|
|
66
|
+
/**
|
|
67
|
+
* The daily floor of a plan: a day below it is never a spike.
|
|
68
|
+
* Inputs: the plan's renders per month. Output: the lower of `VIEW_SPIKE_RULE.minViews` and a
|
|
69
|
+
* thirtieth of the month (at least 1), so quietly forging the plan's whole month in 30 equal days
|
|
70
|
+
* is a spike on the first day that passes the floor rather than going unseen. Errors: none. No
|
|
71
|
+
* side effects.
|
|
72
|
+
*/
|
|
73
|
+
export function spikeMinViews(rendersPerMonth) {
|
|
74
|
+
return Math.max(1, Math.min(VIEW_SPIKE_RULE.minViews, Math.floor(rendersPerMonth / 30)));
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* The spike rule of a plan. Inputs: a plan id (unknown: the default plan). Output: the rule with
|
|
78
|
+
* the plan's floor. Errors: none. No side effects.
|
|
79
|
+
*/
|
|
80
|
+
export function spikeRuleOf(planId) {
|
|
81
|
+
return Object.freeze({
|
|
82
|
+
...VIEW_SPIKE_RULE,
|
|
83
|
+
minViews: spikeMinViews(usageOfPlan(planId).rendersPerMonth),
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
87
|
+
function dayKey(time) {
|
|
88
|
+
return new Date(time).toISOString().slice(0, 10);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Every day of a series that is a spike, earliest first.
|
|
92
|
+
* Inputs: the counted views per UTC day (any order; a missing day is zero), the current time, the
|
|
93
|
+
* rule and the first day to examine (default: yesterday, so today, still partial, and yesterday are
|
|
94
|
+
* looked at). Output: the spikes among the days from `from` to today, each day against the mean of
|
|
95
|
+
* the `baselineDays` days before it (possibly none). All of them, not the first: a spike a person
|
|
96
|
+
* already judged `legit` must not hide a later one. A caller that measures a workspace only
|
|
97
|
+
* every few hours passes the first day of the month, so a spike that happened between two visits
|
|
98
|
+
* is still found. Days before the series count as zero: give it `baselineDays` days before `from`.
|
|
99
|
+
* Errors: none. No side effects.
|
|
100
|
+
*/
|
|
101
|
+
export function detectViewSpikes(series, now, rule = VIEW_SPIKE_RULE, from) {
|
|
102
|
+
const byDay = new Map(series.map((entry) => [entry.day, entry.views]));
|
|
103
|
+
const today = Math.floor(now.getTime() / DAY_MS) * DAY_MS;
|
|
104
|
+
const first = from === undefined ? today - DAY_MS : Math.floor(from.getTime() / DAY_MS) * DAY_MS;
|
|
105
|
+
const spikes = [];
|
|
106
|
+
for (let at = first; at <= today; at += DAY_MS) {
|
|
107
|
+
const views = byDay.get(dayKey(at)) ?? 0;
|
|
108
|
+
if (views < rule.minViews)
|
|
109
|
+
continue;
|
|
110
|
+
let sum = 0;
|
|
111
|
+
for (let back = 1; back <= rule.baselineDays; back += 1) {
|
|
112
|
+
sum += byDay.get(dayKey(at - back * DAY_MS)) ?? 0;
|
|
113
|
+
}
|
|
114
|
+
const baselineMean = sum / rule.baselineDays;
|
|
115
|
+
if (views > rule.multiplier * baselineMean) {
|
|
116
|
+
spikes.push({ day: dayKey(at), views, baselineMean });
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return spikes;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* The first spike of `detectViewSpikes`, or `null`. Same inputs. Errors: none. No side effects.
|
|
123
|
+
*/
|
|
124
|
+
export function detectViewSpike(series, now, rule = VIEW_SPIKE_RULE, from) {
|
|
125
|
+
return detectViewSpikes(series, now, rule, from)[0] ?? null;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* The usage allowance of a plan, falling back to the default plan's for an unknown id.
|
|
129
|
+
* Inputs: a plan id or `undefined`. Output: the plan's row. Errors: none. No side effects.
|
|
130
|
+
*/
|
|
131
|
+
export function usageOfPlan(planId) {
|
|
132
|
+
return planUsage[isPlanId(planId) ? planId : DEFAULT_PLAN_ID];
|
|
133
|
+
}
|
|
134
|
+
//# sourceMappingURL=plan-usage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plan-usage.js","sourceRoot":"","sources":["../src/plan-usage.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,QAAQ,EAAe,MAAM,kBAAkB,CAAC;AAmBpF,gGAAgG;AAChG,MAAM,KAAK,GAA8B,WAAW,CAAC,OAAO,CAAC,CAAC;AAE9D,6DAA6D;AAC7D,MAAM,CAAC,MAAM,SAAS,GAAwC,MAAM,CAAC,MAAM,CACzE,MAAM,CAAC,WAAW,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,KAAK,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAG7E,CACF,CAAC;AAEF,iGAAiG;AACjG,MAAM,CAAC,MAAM,sBAAsB,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,GAAG,CAAU,CAAC,CAAC;AAExE;;;GAGG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,IAAI,EAAE,SAAS,EAAE,SAAS,CAAU,CAAC;AAGlE;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAC,IAAY,EAAE,KAAa;IACtD,IAAI,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC;Q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,GAAG,GAAG,IAAI,CAAC,YAAY,CAAC;QAC7C,IAAI,KAAK,GAAG,IAAI,CAAC,UAAU,GAAG,YAAY,EAAE,CAAC;YAC3C,MAAM,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,YAAY,EAAE,CAAC,CAAC;QACxD,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,eAAe,CAC7B,MAA6B,EAC7B,GAAS,EACT,OAAsB,eAAe,EACrC,IAAW;IAEX,OAAO,gBAAgB,CAAC,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC;AAC9D,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,MAA0B;IACpD,OAAO,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC;AAChE,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/** How long a preview link lives after its build finished: seven days. */
|
|
2
|
+
export declare const PREVIEW_TTL_MS: number;
|
|
3
|
+
/** What a token says. */
|
|
4
|
+
export interface PreviewClaims {
|
|
5
|
+
/** The build the link was issued for (`bld_…` public id). */
|
|
6
|
+
readonly buildId: string;
|
|
7
|
+
/** SHA-256 of the build's bundle: the only object the link opens. */
|
|
8
|
+
readonly bundleSha256: string;
|
|
9
|
+
/**
|
|
10
|
+
* The contract version the build's manifest declares (`1.4.0`): the bundle's own definition has
|
|
11
|
+
* none until extraction, and the runtime refuses to mount a component without it, exactly as
|
|
12
|
+
* the loader gets it from the published manifest.
|
|
13
|
+
*/
|
|
14
|
+
readonly contractVersion: string;
|
|
15
|
+
/** Whole seconds since the epoch; the link stops working at this instant. */
|
|
16
|
+
readonly expiresAt: number;
|
|
17
|
+
}
|
|
18
|
+
/** Port: the HMAC-SHA-256 under the signing key (Web Crypto in both Workers). */
|
|
19
|
+
export interface PreviewSigner {
|
|
20
|
+
/** The raw MAC of `message`. Errors: rejects when Web Crypto is unavailable. */
|
|
21
|
+
sign(message: string): Promise<Uint8Array>;
|
|
22
|
+
/** Whether `tag` is the MAC of `message`, compared in constant time. */
|
|
23
|
+
verify(message: string, tag: Uint8Array): Promise<boolean>;
|
|
24
|
+
}
|
|
25
|
+
/** Longest token `verifyPreviewToken` looks at; anything longer is refused unread. */
|
|
26
|
+
export declare const PREVIEW_TOKEN_MAX_LENGTH = 256;
|
|
27
|
+
/**
|
|
28
|
+
* The expiry of a build's link.
|
|
29
|
+
* Inputs: when the build finished, in milliseconds since the epoch. Output: whole seconds since
|
|
30
|
+
* the epoch, `PREVIEW_TTL_MS` later (rounded up). Errors: none. Side effects: none.
|
|
31
|
+
*/
|
|
32
|
+
export declare function previewExpiry(finishedAtMs: number): number;
|
|
33
|
+
/**
|
|
34
|
+
* Whether claims are well formed: a build id, a SHA-256 and a positive whole-second expiry.
|
|
35
|
+
* Inputs: any claims. Output: a boolean. Errors: none. Side effects: none.
|
|
36
|
+
*/
|
|
37
|
+
export declare function isPreviewClaims(claims: PreviewClaims): boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Signs a token.
|
|
40
|
+
* Inputs: the signer and the claims. Output: the token. Errors: `TypeError` for malformed
|
|
41
|
+
* claims (a bug in the caller); rejects with the signer. Side effects: none.
|
|
42
|
+
*/
|
|
43
|
+
export declare function issuePreviewToken(signer: PreviewSigner, claims: PreviewClaims): Promise<string>;
|
|
44
|
+
/**
|
|
45
|
+
* Verifies a token taken from a URL.
|
|
46
|
+
* Inputs: the signer, the token (untrusted) and the current time in milliseconds. Output: the
|
|
47
|
+
* claims, or `undefined` for a token that is malformed, tampered with, signed under another key
|
|
48
|
+
* or expired: the caller answers all of them with the same 404. Errors: none thrown; a signer
|
|
49
|
+
* failure also gives `undefined` (fail closed). Side effects: none.
|
|
50
|
+
*/
|
|
51
|
+
export declare function verifyPreviewToken(signer: PreviewSigner, token: string, nowMs: number): Promise<PreviewClaims | undefined>;
|
|
52
|
+
//# sourceMappingURL=preview-token.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"preview-token.d.ts","sourceRoot":"","sources":["../src/preview-token.ts"],"names":[],"mappings":"AAiBA,0EAA0E;AAC1E,eAAO,MAAM,cAAc,QAA0B,CAAC;AAEtD,yBAAyB;AACzB,MAAM,WAAW,aAAa;IAC5B,6DAA6D;IAC7D,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,qEAAqE;IACrE,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B;;;;OAIG;IACH,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IACjC,6EAA6E;IAC7E,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B;AAED,iFAAiF;AACjF,MAAM,WAAW,aAAa;IAC5B,gFAAgF;IAChF,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;IAC3C,wEAAwE;IACxE,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CAC5D;AASD,sFAAsF;AACtF,eAAO,MAAM,wBAAwB,MAAM,CAAC;AAW5C;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAE1D;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAQ9D;AAED;;;;GAIG;AACH,wBAAsB,iBAAiB,CACrC,MAAM,EAAE,aAAa,EACrB,MAAM,EAAE,aAAa,GACpB,OAAO,CAAC,MAAM,CAAC,CAWjB;AAED;;;;;;GAMG;AACH,wBAAsB,kBAAkB,CACtC,MAAM,EAAE,aAAa,EACrB,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC,CA6BpC"}
|