@taggor/contract 0.0.0-stage → 0.1.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.
Files changed (339) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +61 -2
  3. package/dist/.tsbuildinfo +1 -0
  4. package/dist/artifact-keys.d.ts +169 -0
  5. package/dist/artifact-keys.d.ts.map +1 -0
  6. package/dist/artifact-keys.js +195 -0
  7. package/dist/artifact-keys.js.map +1 -0
  8. package/dist/assets.d.ts +72 -0
  9. package/dist/assets.d.ts.map +1 -0
  10. package/dist/assets.js +94 -0
  11. package/dist/assets.js.map +1 -0
  12. package/dist/bounded-path.d.ts +29 -0
  13. package/dist/bounded-path.d.ts.map +1 -0
  14. package/dist/bounded-path.js +57 -0
  15. package/dist/bounded-path.js.map +1 -0
  16. package/dist/bounded.d.ts +47 -0
  17. package/dist/bounded.d.ts.map +1 -0
  18. package/dist/bounded.js +93 -0
  19. package/dist/bounded.js.map +1 -0
  20. package/dist/build-diagnostic.d.ts +89 -0
  21. package/dist/build-diagnostic.d.ts.map +1 -0
  22. package/dist/build-diagnostic.js +91 -0
  23. package/dist/build-diagnostic.js.map +1 -0
  24. package/dist/component-types.d.ts +61 -0
  25. package/dist/component-types.d.ts.map +1 -0
  26. package/dist/component-types.js +277 -0
  27. package/dist/component-types.js.map +1 -0
  28. package/dist/consent-text.d.ts +31 -0
  29. package/dist/consent-text.d.ts.map +1 -0
  30. package/dist/consent-text.js +41 -0
  31. package/dist/consent-text.js.map +1 -0
  32. package/dist/contract-version.d.ts +150 -0
  33. package/dist/contract-version.d.ts.map +1 -0
  34. package/dist/contract-version.js +198 -0
  35. package/dist/contract-version.js.map +1 -0
  36. package/dist/credential-fields.d.ts +31 -0
  37. package/dist/credential-fields.d.ts.map +1 -0
  38. package/dist/credential-fields.js +36 -0
  39. package/dist/credential-fields.js.map +1 -0
  40. package/dist/css-tokens.d.ts +46 -0
  41. package/dist/css-tokens.d.ts.map +1 -0
  42. package/dist/css-tokens.js +189 -0
  43. package/dist/css-tokens.js.map +1 -0
  44. package/dist/css-value.d.ts +42 -0
  45. package/dist/css-value.d.ts.map +1 -0
  46. package/dist/css-value.js +78 -0
  47. package/dist/css-value.js.map +1 -0
  48. package/dist/data-api.d.ts +127 -0
  49. package/dist/data-api.d.ts.map +1 -0
  50. package/dist/data-api.js +167 -0
  51. package/dist/data-api.js.map +1 -0
  52. package/dist/denylist-keys.d.ts +19 -0
  53. package/dist/denylist-keys.d.ts.map +1 -0
  54. package/dist/denylist-keys.js +48 -0
  55. package/dist/denylist-keys.js.map +1 -0
  56. package/dist/diagnostic-catalog.d.ts +1402 -0
  57. package/dist/diagnostic-catalog.d.ts.map +1 -0
  58. package/dist/diagnostic-catalog.js +1311 -0
  59. package/dist/diagnostic-catalog.js.map +1 -0
  60. package/dist/dom-members.snapshot.d.ts +33 -0
  61. package/dist/dom-members.snapshot.d.ts.map +1 -0
  62. package/dist/dom-members.snapshot.js +760 -0
  63. package/dist/dom-members.snapshot.js.map +1 -0
  64. package/dist/early-loading.d.ts +27 -0
  65. package/dist/early-loading.d.ts.map +1 -0
  66. package/dist/early-loading.js +44 -0
  67. package/dist/early-loading.js.map +1 -0
  68. package/dist/error-catalog.d.ts +749 -0
  69. package/dist/error-catalog.d.ts.map +1 -0
  70. package/dist/error-catalog.js +720 -0
  71. package/dist/error-catalog.js.map +1 -0
  72. package/dist/executable-config.d.ts +35 -0
  73. package/dist/executable-config.d.ts.map +1 -0
  74. package/dist/executable-config.js +44 -0
  75. package/dist/executable-config.js.map +1 -0
  76. package/dist/freeze.d.ts +17 -0
  77. package/dist/freeze.d.ts.map +1 -0
  78. package/dist/freeze.js +29 -0
  79. package/dist/freeze.js.map +1 -0
  80. package/dist/gunzip.d.ts +33 -0
  81. package/dist/gunzip.d.ts.map +1 -0
  82. package/dist/gunzip.js +330 -0
  83. package/dist/gunzip.js.map +1 -0
  84. package/dist/hostname.d.ts +74 -0
  85. package/dist/hostname.d.ts.map +1 -0
  86. package/dist/hostname.js +215 -0
  87. package/dist/hostname.js.map +1 -0
  88. package/dist/human-actions.d.ts +49 -0
  89. package/dist/human-actions.d.ts.map +1 -0
  90. package/dist/human-actions.js +272 -0
  91. package/dist/human-actions.js.map +1 -0
  92. package/dist/index.d.ts +72 -0
  93. package/dist/index.d.ts.map +1 -0
  94. package/dist/index.js +72 -0
  95. package/dist/index.js.map +1 -0
  96. package/dist/json-schema.d.ts +108 -0
  97. package/dist/json-schema.d.ts.map +1 -0
  98. package/dist/json-schema.js +240 -0
  99. package/dist/json-schema.js.map +1 -0
  100. package/dist/key-checksum.d.ts +33 -0
  101. package/dist/key-checksum.d.ts.map +1 -0
  102. package/dist/key-checksum.js +67 -0
  103. package/dist/key-checksum.js.map +1 -0
  104. package/dist/libraries.d.ts +60 -0
  105. package/dist/libraries.d.ts.map +1 -0
  106. package/dist/libraries.js +120 -0
  107. package/dist/libraries.js.map +1 -0
  108. package/dist/limit-catalog.d.ts +371 -0
  109. package/dist/limit-catalog.d.ts.map +1 -0
  110. package/dist/limit-catalog.js +414 -0
  111. package/dist/limit-catalog.js.map +1 -0
  112. package/dist/limits.d.ts +167 -0
  113. package/dist/limits.d.ts.map +1 -0
  114. package/dist/limits.js +175 -0
  115. package/dist/limits.js.map +1 -0
  116. package/dist/locale-tag.d.ts +21 -0
  117. package/dist/locale-tag.d.ts.map +1 -0
  118. package/dist/locale-tag.js +21 -0
  119. package/dist/locale-tag.js.map +1 -0
  120. package/dist/make-diagnostic.d.ts +74 -0
  121. package/dist/make-diagnostic.d.ts.map +1 -0
  122. package/dist/make-diagnostic.js +100 -0
  123. package/dist/make-diagnostic.js.map +1 -0
  124. package/dist/manifest-compat-diagnostics.d.ts +23 -0
  125. package/dist/manifest-compat-diagnostics.d.ts.map +1 -0
  126. package/dist/manifest-compat-diagnostics.js +150 -0
  127. package/dist/manifest-compat-diagnostics.js.map +1 -0
  128. package/dist/manifest-compat.d.ts +58 -0
  129. package/dist/manifest-compat.d.ts.map +1 -0
  130. package/dist/manifest-compat.js +377 -0
  131. package/dist/manifest-compat.js.map +1 -0
  132. package/dist/manifest.d.ts +1769 -0
  133. package/dist/manifest.d.ts.map +1 -0
  134. package/dist/manifest.js +421 -0
  135. package/dist/manifest.js.map +1 -0
  136. package/dist/metering.d.ts +126 -0
  137. package/dist/metering.d.ts.map +1 -0
  138. package/dist/metering.js +147 -0
  139. package/dist/metering.js.map +1 -0
  140. package/dist/migrate.d.ts +70 -0
  141. package/dist/migrate.d.ts.map +1 -0
  142. package/dist/migrate.js +159 -0
  143. package/dist/migrate.js.map +1 -0
  144. package/dist/names.d.ts +37 -0
  145. package/dist/names.d.ts.map +1 -0
  146. package/dist/names.js +55 -0
  147. package/dist/names.js.map +1 -0
  148. package/dist/overage-pricing.d.ts +89 -0
  149. package/dist/overage-pricing.d.ts.map +1 -0
  150. package/dist/overage-pricing.js +170 -0
  151. package/dist/overage-pricing.js.map +1 -0
  152. package/dist/plan-ids.d.ts +10 -0
  153. package/dist/plan-ids.d.ts.map +1 -0
  154. package/dist/plan-ids.js +8 -0
  155. package/dist/plan-ids.js.map +1 -0
  156. package/dist/plan-limits.d.ts +138 -0
  157. package/dist/plan-limits.d.ts.map +1 -0
  158. package/dist/plan-limits.js +112 -0
  159. package/dist/plan-limits.js.map +1 -0
  160. package/dist/plan-pricing.d.ts +145 -0
  161. package/dist/plan-pricing.d.ts.map +1 -0
  162. package/dist/plan-pricing.js +172 -0
  163. package/dist/plan-pricing.js.map +1 -0
  164. package/dist/plan-usage.d.ts +112 -0
  165. package/dist/plan-usage.d.ts.map +1 -0
  166. package/dist/plan-usage.js +134 -0
  167. package/dist/plan-usage.js.map +1 -0
  168. package/dist/preview-token.d.ts +52 -0
  169. package/dist/preview-token.d.ts.map +1 -0
  170. package/dist/preview-token.js +106 -0
  171. package/dist/preview-token.js.map +1 -0
  172. package/dist/prop-names.d.ts +51 -0
  173. package/dist/prop-names.d.ts.map +1 -0
  174. package/dist/prop-names.js +150 -0
  175. package/dist/prop-names.js.map +1 -0
  176. package/dist/prop-type-docs.d.ts +20 -0
  177. package/dist/prop-type-docs.d.ts.map +1 -0
  178. package/dist/prop-type-docs.js +89 -0
  179. package/dist/prop-type-docs.js.map +1 -0
  180. package/dist/prop-types.d.ts +97 -0
  181. package/dist/prop-types.d.ts.map +1 -0
  182. package/dist/prop-types.js +299 -0
  183. package/dist/prop-types.js.map +1 -0
  184. package/dist/props.d.ts +996 -0
  185. package/dist/props.d.ts.map +1 -0
  186. package/dist/props.js +183 -0
  187. package/dist/props.js.map +1 -0
  188. package/dist/proto-guard.d.ts +29 -0
  189. package/dist/proto-guard.d.ts.map +1 -0
  190. package/dist/proto-guard.js +79 -0
  191. package/dist/proto-guard.js.map +1 -0
  192. package/dist/runtime-errors.d.ts +42 -0
  193. package/dist/runtime-errors.d.ts.map +1 -0
  194. package/dist/runtime-errors.js +42 -0
  195. package/dist/runtime-errors.js.map +1 -0
  196. package/dist/runtime-pointers.d.ts +58 -0
  197. package/dist/runtime-pointers.d.ts.map +1 -0
  198. package/dist/runtime-pointers.js +84 -0
  199. package/dist/runtime-pointers.js.map +1 -0
  200. package/dist/secret-scan.d.ts +191 -0
  201. package/dist/secret-scan.d.ts.map +1 -0
  202. package/dist/secret-scan.js +542 -0
  203. package/dist/secret-scan.js.map +1 -0
  204. package/dist/semver.d.ts +89 -0
  205. package/dist/semver.d.ts.map +1 -0
  206. package/dist/semver.js +400 -0
  207. package/dist/semver.js.map +1 -0
  208. package/dist/server-key.d.ts +68 -0
  209. package/dist/server-key.d.ts.map +1 -0
  210. package/dist/server-key.js +150 -0
  211. package/dist/server-key.js.map +1 -0
  212. package/dist/site-manifest-keys.d.ts +107 -0
  213. package/dist/site-manifest-keys.d.ts.map +1 -0
  214. package/dist/site-manifest-keys.js +146 -0
  215. package/dist/site-manifest-keys.js.map +1 -0
  216. package/dist/site-manifest.d.ts +286 -0
  217. package/dist/site-manifest.d.ts.map +1 -0
  218. package/dist/site-manifest.js +100 -0
  219. package/dist/site-manifest.js.map +1 -0
  220. package/dist/source-archive.d.ts +119 -0
  221. package/dist/source-archive.d.ts.map +1 -0
  222. package/dist/source-archive.js +644 -0
  223. package/dist/source-archive.js.map +1 -0
  224. package/dist/source-package-corpus.d.ts +55 -0
  225. package/dist/source-package-corpus.d.ts.map +1 -0
  226. package/dist/source-package-corpus.js +303 -0
  227. package/dist/source-package-corpus.js.map +1 -0
  228. package/dist/source-package.d.ts +227 -0
  229. package/dist/source-package.d.ts.map +1 -0
  230. package/dist/source-package.js +361 -0
  231. package/dist/source-package.js.map +1 -0
  232. package/dist/source-secrets.d.ts +21 -0
  233. package/dist/source-secrets.d.ts.map +1 -0
  234. package/dist/source-secrets.js +43 -0
  235. package/dist/source-secrets.js.map +1 -0
  236. package/dist/ssr-cap.d.ts +61 -0
  237. package/dist/ssr-cap.d.ts.map +1 -0
  238. package/dist/ssr-cap.js +107 -0
  239. package/dist/ssr-cap.js.map +1 -0
  240. package/dist/ssr-kv.d.ts +18 -0
  241. package/dist/ssr-kv.d.ts.map +1 -0
  242. package/dist/ssr-kv.js +18 -0
  243. package/dist/ssr-kv.js.map +1 -0
  244. package/dist/ssr-version-ledger.d.ts +53 -0
  245. package/dist/ssr-version-ledger.d.ts.map +1 -0
  246. package/dist/ssr-version-ledger.js +88 -0
  247. package/dist/ssr-version-ledger.js.map +1 -0
  248. package/dist/style-references.d.ts +58 -0
  249. package/dist/style-references.d.ts.map +1 -0
  250. package/dist/style-references.js +241 -0
  251. package/dist/style-references.js.map +1 -0
  252. package/dist/tag-name.d.ts +87 -0
  253. package/dist/tag-name.d.ts.map +1 -0
  254. package/dist/tag-name.js +222 -0
  255. package/dist/tag-name.js.map +1 -0
  256. package/dist/tar-writer.d.ts +74 -0
  257. package/dist/tar-writer.d.ts.map +1 -0
  258. package/dist/tar-writer.js +148 -0
  259. package/dist/tar-writer.js.map +1 -0
  260. package/dist/testing.d.ts +11 -0
  261. package/dist/testing.d.ts.map +1 -0
  262. package/dist/testing.js +11 -0
  263. package/dist/testing.js.map +1 -0
  264. package/dist/text-codec.d.ts +36 -0
  265. package/dist/text-codec.d.ts.map +1 -0
  266. package/dist/text-codec.js +32 -0
  267. package/dist/text-codec.js.map +1 -0
  268. package/dist/url-value.d.ts +41 -0
  269. package/dist/url-value.d.ts.map +1 -0
  270. package/dist/url-value.js +147 -0
  271. package/dist/url-value.js.map +1 -0
  272. package/dist/usage-guard.d.ts +99 -0
  273. package/dist/usage-guard.d.ts.map +1 -0
  274. package/dist/usage-guard.js +104 -0
  275. package/dist/usage-guard.js.map +1 -0
  276. package/dist/usage-mirror.d.ts +55 -0
  277. package/dist/usage-mirror.d.ts.map +1 -0
  278. package/dist/usage-mirror.js +52 -0
  279. package/dist/usage-mirror.js.map +1 -0
  280. package/dist/value-check.d.ts +88 -0
  281. package/dist/value-check.d.ts.map +1 -0
  282. package/dist/value-check.js +279 -0
  283. package/dist/value-check.js.map +1 -0
  284. package/dist/value-patterns.d.ts +9 -0
  285. package/dist/value-patterns.d.ts.map +1 -0
  286. package/dist/value-patterns.js +17 -0
  287. package/dist/value-patterns.js.map +1 -0
  288. package/dist/value-schema.d.ts +796 -0
  289. package/dist/value-schema.d.ts.map +1 -0
  290. package/dist/value-schema.js +231 -0
  291. package/dist/value-schema.js.map +1 -0
  292. package/dist/zod-free.d.ts +59 -0
  293. package/dist/zod-free.d.ts.map +1 -0
  294. package/dist/zod-free.js +57 -0
  295. package/dist/zod-free.js.map +1 -0
  296. package/package.json +75 -3
  297. package/schema/DEPLOYED +12 -0
  298. package/schema/build-diagnostic.v1.json +63 -0
  299. package/schema/component-manifest.v1.json +1000 -0
  300. package/schema/data-api.v1.json +194 -0
  301. package/schema/library-manifest.v1.json +60 -0
  302. package/schema/published/SHA256SUMS +36 -0
  303. package/schema/published/build-diagnostic/v1.10.json +83 -0
  304. package/schema/published/build-diagnostic/v1.3.json +83 -0
  305. package/schema/published/build-diagnostic/v1.4.json +83 -0
  306. package/schema/published/build-diagnostic/v1.5.json +83 -0
  307. package/schema/published/build-diagnostic/v1.6.json +83 -0
  308. package/schema/published/build-diagnostic/v1.7.json +83 -0
  309. package/schema/published/build-diagnostic/v1.8.json +83 -0
  310. package/schema/published/build-diagnostic/v1.9.json +83 -0
  311. package/schema/published/component-manifest/v1.10.json +1443 -0
  312. package/schema/published/component-manifest/v1.3.json +1411 -0
  313. package/schema/published/component-manifest/v1.4.json +1419 -0
  314. package/schema/published/component-manifest/v1.5.json +1437 -0
  315. package/schema/published/component-manifest/v1.6.json +1437 -0
  316. package/schema/published/component-manifest/v1.7.json +1437 -0
  317. package/schema/published/component-manifest/v1.8.json +1437 -0
  318. package/schema/published/component-manifest/v1.9.json +1437 -0
  319. package/schema/published/data-api/v1.10.json +282 -0
  320. package/schema/published/data-api/v1.3.json +281 -0
  321. package/schema/published/data-api/v1.4.json +281 -0
  322. package/schema/published/data-api/v1.5.json +281 -0
  323. package/schema/published/data-api/v1.6.json +281 -0
  324. package/schema/published/data-api/v1.7.json +281 -0
  325. package/schema/published/data-api/v1.8.json +282 -0
  326. package/schema/published/data-api/v1.9.json +282 -0
  327. package/schema/published/library-manifest/v1.10.json +68 -0
  328. package/schema/published/library-manifest/v1.5.json +68 -0
  329. package/schema/published/library-manifest/v1.6.json +68 -0
  330. package/schema/published/library-manifest/v1.7.json +68 -0
  331. package/schema/published/library-manifest/v1.8.json +68 -0
  332. package/schema/published/library-manifest/v1.9.json +68 -0
  333. package/schema/published/taggor-config/v1.10.json +56 -0
  334. package/schema/published/taggor-config/v1.5.json +56 -0
  335. package/schema/published/taggor-config/v1.6.json +56 -0
  336. package/schema/published/taggor-config/v1.7.json +56 -0
  337. package/schema/published/taggor-config/v1.8.json +56 -0
  338. package/schema/published/taggor-config/v1.9.json +56 -0
  339. package/schema/taggor-config.v1.json +39 -0
@@ -0,0 +1,147 @@
1
+ /**
2
+ * The metering contract of the loader hit point (TAG-801): the one place that names what the edge
3
+ * writes per loader delivery and what counts toward a plan's usage, shared by the writer
4
+ * (apps/edge, domain/loader-hit.ts) and the readers (the API's usage reader; TAG-712 and TAG-1603
5
+ * build the quotas on it).
6
+ *
7
+ * Point layout of the `loader_hits` dataset (TAG-1823: a request writes a DELIVERY point, with no ASN and no
8
+ * visitor identifier, and a separate NETWORK point, with the ASN and `doubles[0] = 0`; `blobs[3]` is reserved and
9
+ * always empty, it held the visitor hash until TAG-1823; only the delivery count under a honored `Sec-GPC: 1`), append-only (a reader of an older layout keeps
10
+ * working): `indexes[0]` site key; `blobs[0]` hostname; `blobs[1]` allowance; `blobs[2]` traffic
11
+ * class; `doubles[0]` 1 (a delivery; sampling weights come from `_sample_interval`);
12
+ * `doubles[1]` the number of components the delivered manifest offered; since TAG-1730 also
13
+ * `blobs[3]` reserved (always empty) and `blobs[4]` the ASN of a network point (the anomaly guard, `usage-guard.ts`).
14
+ *
15
+ * Privacy (golden rule 6): none of it identifies a visitor. The traffic class is derived from the
16
+ * `User-Agent` in memory and only the class is kept.
17
+ */
18
+ /**
19
+ * The header the API sets when it reads a site's loader itself (`?preload=true` needs the runtime
20
+ * version the loader names, TAG-335). The edge does not record a hit point for such a request: it
21
+ * is not a page loading the snippet, and counting it would make the installation check say
22
+ * "detected" before any page has the snippet. No secret guards it on purpose: sending it can only
23
+ * LOWER the counts of the caller's own non-visitor requests (a real visitor never sends it, and
24
+ * nothing is authorized or unlocked by it), so there is nothing to gain by forging it.
25
+ */
26
+ export const INTERNAL_READ_HEADER = "x-taggor-internal-read";
27
+ /** Whether the page's hostname is on the site's allowlist; `unknown` when there is no usable one. */
28
+ export const HOST_ALLOWANCES = ["allowed", "blocked", "unknown"];
29
+ /** The traffic class of a delivery: a bot never counts toward a plan, it is kept for audit. */
30
+ export const TRAFFIC_CLASSES = ["human", "bot"];
31
+ /**
32
+ * Whether a delivery counts toward the plan usage: the page's hostname is not known to be off the
33
+ * allowlist and the traffic is not a bot. `unknown` (no usable `Referer`) COUNTS: the domain gate
34
+ * in the browser judges `location.hostname`, so the components mount on such a page, and not
35
+ * counting it would let `referrerpolicy="no-referrer"` escape the plan's ceiling. Only `blocked`
36
+ * (a hostname the site does not allow) and bots are left out, kept for audit.
37
+ * Inputs: the two stored dimensions. Output: true when it counts. Errors: none. No side effects.
38
+ */
39
+ export function countsTowardUsage(allowance, traffic) {
40
+ return allowance !== "blocked" && traffic === "human";
41
+ }
42
+ /**
43
+ * The first instant of the UTC month of a date, the start of a usage window (plans are monthly;
44
+ * one clock for every reader, so the edge, the API and the invoice agree).
45
+ * Inputs: a date. Output: a new date at day 1, 00:00:00.000 UTC. Errors: none. No side effects.
46
+ */
47
+ export function usageMonthStart(date) {
48
+ return new Date(Date.UTC(date.getUTCFullYear(), date.getUTCMonth(), 1));
49
+ }
50
+ /**
51
+ * The kinds of event the browser can report to `POST /e/<siteKey>` (TAG-816), the layout of the
52
+ * `component_events` dataset (append-only): `indexes[0]` site key; `blobs[0]` kind; `blobs[1]` the
53
+ * component tag; `blobs[2]` the published version hash; `blobs[3]` the hostname of the page's
54
+ * `Origin`; `blobs[4]` traffic class; `blobs[5]` the event name (`""` for `render`);
55
+ * `blobs[6]` the visitor's country (ISO 3166-1 alpha-2 from the platform, `""` when unknown) and
56
+ * `blobs[7]` a coarse device class (`DEVICE_CLASSES`, derived from the user agent on the edge);
57
+ * `doubles[0]` 1 (one point per event; sampling weights come from `_sample_interval`). No IP, no
58
+ * visitor identifier, no city or region, no path, no user agent. `render` is the aggregate count; the rest are
59
+ * interactions and are not stored when the visitor sends a privacy signal the site honors.
60
+ */
61
+ export const COMPONENT_EVENT_KINDS = [
62
+ "render",
63
+ "interaction",
64
+ "custom",
65
+ "error",
66
+ "conversion",
67
+ ];
68
+ /**
69
+ * The server-render points of `GET /r/<siteKey>/<tag>` (spike, ADR 0066, no ticket), written by the
70
+ * edge itself into the same `component_events` dataset with the same layout: `indexes[0]` site key;
71
+ * `blobs[0]` the kind; `blobs[1]` the component tag; `blobs[2]` the version hash; every other blob
72
+ * `""` (no hostname, traffic class, name, country nor device: the caller is the customer's server,
73
+ * and nothing of the visitor reaches the route); `doubles[0]` 1. `ssr_render` is a render the edge
74
+ * performed (a cache miss that produced a fragment), the count `ssrRendersPerMonth` reads; `ssr_hit`
75
+ * is a fragment served from the colo cache, metered only (`SSR_FAILED_POINT_KIND` below is the third kind,
76
+ * outside this list). The distinct versions rendered per day are
77
+ * NOT read from these points (sampling can drop a rare version): see `ssr-version-ledger.ts`. They are
78
+ * NOT in `COMPONENT_EVENT_KINDS`, so `POST /e/` refuses them and a browser cannot forge one, and the
79
+ * metrics readers, which name their kinds, never count them.
80
+ */
81
+ export const SSR_POINT_KINDS = ["ssr_render", "ssr_hit"];
82
+ /**
83
+ * The kind of a render that gave no fragment (TAG-635): written by the edge with the same layout,
84
+ * for staff queries and alerts. Not in `SSR_POINT_KINDS` on purpose: that list is what the API's
85
+ * usage reader asks for, and a failed render is never counted or billed.
86
+ */
87
+ export const SSR_FAILED_POINT_KIND = "ssr_failed";
88
+ /**
89
+ * The coarse device class of an event (TAG-816), derived from the `User-Agent` on the edge, which
90
+ * keeps only the class: `mobile` (a phone), `tablet`, `desktop`, or `other` (a bot, a library, no
91
+ * header, anything not recognized). Four values, so the dataset's cardinality stays four.
92
+ */
93
+ export const DEVICE_CLASSES = ["mobile", "desktop", "tablet", "other"];
94
+ /**
95
+ * The smallest `eventSampleRate` a manifest may declare (TAG-819): one event in a thousand, so the
96
+ * weight of a sent event (`1 / rate`) never passes 1000 and one forged or lucky event cannot stand
97
+ * for an unbounded count.
98
+ */
99
+ export const EVENT_SAMPLE_RATE_MIN = 0.001;
100
+ /**
101
+ * The kinds the browser never samples (TAG-819): the render count, the `error` reports of the
102
+ * runtime (rare, and a sample would hide a failing release) and the `conversion` (the result the
103
+ * customer measures). Only `interaction` and `custom` follow `eventSampleRate`.
104
+ */
105
+ export const UNSAMPLED_EVENT_KINDS = [
106
+ "render",
107
+ "error",
108
+ "conversion",
109
+ ];
110
+ /** A rate the manifest may declare: finite and within `[EVENT_SAMPLE_RATE_MIN, 1]`. */
111
+ function usableRate(rate) {
112
+ return typeof rate === "number" && rate >= EVENT_SAMPLE_RATE_MIN && rate <= 1;
113
+ }
114
+ /**
115
+ * Whether the browser sends one event of this kind, given the component's `eventSampleRate`
116
+ * (TAG-819). A kind that is never sampled, an undeclared rate and a rate outside its bounds always
117
+ * send (a bad value must never silently drop events). Otherwise the event is sent with
118
+ * probability `rate`.
119
+ * Inputs: the kind, the declared rate (or `undefined`) and a draw in `[0, 1)` (`Math.random()` in
120
+ * the browser, a seeded draw in tests). Output: true to send. Errors: none. Pure.
121
+ */
122
+ export function shouldSendEvent(kind, rate, draw) {
123
+ if (UNSAMPLED_EVENT_KINDS.includes(kind) || !usableRate(rate))
124
+ return true;
125
+ return draw < rate;
126
+ }
127
+ /**
128
+ * How many real events one stored event stands for (TAG-819): `1 / rate` for a sampled kind, and 1
129
+ * for a kind that is never sampled or a rate that is not usable. The edge writes it as
130
+ * `doubles[0]` from the rate of the STORED manifest, never from the request, so a visitor cannot
131
+ * claim a weight; summing the weights over the sent events estimates the real total.
132
+ * Inputs: the kind and the declared rate. Output: the weight, at least 1 and at most
133
+ * `1 / EVENT_SAMPLE_RATE_MIN`. Errors: none. Pure.
134
+ */
135
+ export function eventWeight(kind, rate) {
136
+ if (UNSAMPLED_EVENT_KINDS.includes(kind) || !usableRate(rate))
137
+ return 1;
138
+ return 1 / rate;
139
+ }
140
+ /**
141
+ * The most beacons of one kind (`interaction` or `custom`) a component sends in one page view
142
+ * (TAG-820), counted in the SDK's data transport: a component that emits on every keystroke or
143
+ * slider move cannot flood the visitor's network or the dataset. Sampling (`shouldSendEvent`)
144
+ * applies on top; the edge's flood keys stay the technical protection.
145
+ */
146
+ export const EVENT_BEACON_CAP_PER_PAGE = 30;
147
+ //# sourceMappingURL=metering.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"metering.js","sourceRoot":"","sources":["../src/metering.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;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AAO,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,IAAI,qBAAqB,IAAI,IAAI,IAAI,CAAC,CAAC;AAChF,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,eAAe,CAC7B,IAAwB,EACxB,IAAwB,EACxB,IAAY;IAEZ,IAAI,qBAAqB,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC;IAC3E,OAAO,IAAI,GAAG,IAAI,CAAC;AACrB,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,WAAW,CAAC,IAAwB,EAAE,IAAwB;IAC5E,IAAI,qBAAqB,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;QAAE,OAAO,CAAC,CAAC;IACxE,OAAO,CAAC,GAAG,IAAI,CAAC;AAClB,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,EAAE,CAAC"}
@@ -0,0 +1,70 @@
1
+ /** A manifest as plain decoded JSON, before or after a migration step. */
2
+ export type ManifestDocument = Record<string, unknown>;
3
+ /**
4
+ * One migration step between consecutive majors. `migrate` receives a private copy it may
5
+ * change or return as is, and must set `contractVersion` to a version of major `to`.
6
+ */
7
+ export interface ManifestMigration {
8
+ readonly from: number;
9
+ readonly to: number;
10
+ readonly migrate: (manifest: ManifestDocument) => ManifestDocument;
11
+ }
12
+ /**
13
+ * The migration steps of this release, oldest first. Empty while v1 is the only major.
14
+ *
15
+ * Inputs: none. Output: frozen data. Errors: none. Side effects: none.
16
+ */
17
+ export declare const MANIFEST_MIGRATIONS: readonly ManifestMigration[];
18
+ /**
19
+ * Why `migrateManifest` refused, stable for callers and logs (TAG-220):
20
+ * - `not-an-object`: the input (or what its `toJSON` produced) is not a JSON object;
21
+ * - `proto-key`, `too-large`: see `findOwnProtoKey`, checked on the input and again on the copy;
22
+ * - `unreadable`: reading or copying the input threw (a throwing getter, proxy or `toJSON`, a
23
+ * nesting too deep to serialize): it is not decoded JSON;
24
+ * - `bad-version`, `newer-major`: `contractVersion` is malformed or newer than the target;
25
+ * - `missing-step`, `bad-step`: the chain lacks a step, or a step returned no object of major
26
+ * `step.to`;
27
+ * - `step-failed`: a step threw. That is a bug of the step, not of the input: it is reported
28
+ * with this distinct reason instead of being thrown, so the host page and the API stay up, and
29
+ * the compatibility test fails on it like on any other refusal.
30
+ */
31
+ export type ManifestMigrationFailure = "not-an-object" | "proto-key" | "too-large" | "unreadable" | "bad-version" | "newer-major" | "missing-step" | "bad-step" | "step-failed";
32
+ /** Result of `migrateManifest`; never thrown. */
33
+ export type ManifestMigrationResult = {
34
+ readonly ok: true;
35
+ readonly manifest: ManifestDocument;
36
+ /** Major the input was written for, and major of `manifest`. */
37
+ readonly from: number;
38
+ readonly to: number;
39
+ } | {
40
+ readonly ok: false;
41
+ readonly reason: ManifestMigrationFailure;
42
+ readonly message: string;
43
+ /**
44
+ * Only on `step-failed`: the value the step threw, for the builder or the API to log with
45
+ * its stack on the server. Non-enumerable, so `JSON.stringify` (an API response, the
46
+ * portal) never carries it; never show it to the customer.
47
+ */
48
+ readonly cause?: unknown;
49
+ };
50
+ /** Options of `migrateManifest`; the defaults are this release's target and steps. */
51
+ export interface MigrateOptions {
52
+ readonly to?: number;
53
+ readonly migrations?: readonly ManifestMigration[];
54
+ }
55
+ /**
56
+ * Migrates a manifest to a target contract major, one step per major.
57
+ *
58
+ * Inputs: decoded JSON (typically `JSON.parse` output) and optional `{ to, migrations }`
59
+ * (defaults: `CONTRACT_MAJOR`, `MANIFEST_MIGRATIONS`). Output: `{ ok: true, manifest, from, to }`
60
+ * where `manifest` is a deep copy, migrated when `from < to` (the copy is returned as is when the
61
+ * input is already of major `to`); or `{ ok: false, reason, message }` (see
62
+ * `ManifestMigrationFailure`). Everything after the copy, the version included, is read from the
63
+ * copy, which is scanned again: a getter or `toJSON` cannot show the scan one thing and the steps
64
+ * another. Messages never quote input values, and paths are bounded (`findOwnProtoKey`).
65
+ * Errors: never throws, also when a step throws (`step-failed`, with the thrown value in the
66
+ * non-enumerable `cause`) or the input throws a hostile value. Side effects: none on the input
67
+ * beyond invoking its getters and `toJSON` once each through the scan and the copy.
68
+ */
69
+ export declare function migrateManifest(input: unknown, options?: MigrateOptions): ManifestMigrationResult;
70
+ //# sourceMappingURL=migrate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migrate.d.ts","sourceRoot":"","sources":["../src/migrate.ts"],"names":[],"mappings":"AAuBA,0EAA0E;AAC1E,MAAM,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAEvD;;;GAGG;AACH,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE,gBAAgB,KAAK,gBAAgB,CAAC;CACpE;AAED;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,EAAE,SAAS,iBAAiB,EAAsB,CAAC;AAEnF;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,wBAAwB,GAChC,eAAe,GACf,WAAW,GACX,WAAW,GACX,YAAY,GACZ,aAAa,GACb,aAAa,GACb,cAAc,GACd,UAAU,GACV,aAAa,CAAC;AAElB,iDAAiD;AACjD,MAAM,MAAM,uBAAuB,GAC/B;IACE,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;IAClB,QAAQ,CAAC,QAAQ,EAAE,gBAAgB,CAAC;IACpC,gEAAgE;IAChE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;CACrB,GACD;IACE,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IACnB,QAAQ,CAAC,MAAM,EAAE,wBAAwB,CAAC;IAC1C,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB;;;;OAIG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;CAC1B,CAAC;AAEN,sFAAsF;AACtF,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,UAAU,CAAC,EAAE,SAAS,iBAAiB,EAAE,CAAC;CACpD;AAqED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,OAAO,EACd,OAAO,GAAE,cAAmB,GAC3B,uBAAuB,CAmEzB"}
@@ -0,0 +1,159 @@
1
+ /**
2
+ * Migration of manifests between contract majors (TAG-207, ADR 0019).
3
+ *
4
+ * When a major ships, the change that bumps `CONTRACT_MAJOR` adds one step `from: N, to: N + 1`
5
+ * to `MANIFEST_MIGRATIONS`: a pure function from a manifest of major N to an equivalent manifest
6
+ * of major N + 1 (renames, removed fields mapped to their replacement, new required fields given
7
+ * their old implicit value). `migrateManifest` chains the steps. The compatibility test
8
+ * (compat.test.ts) runs every fixture of an older major through it and requires the result to
9
+ * pass the current schema, so a major cannot ship without its migration.
10
+ *
11
+ * A migration is applied when a manifest is read for a new build or for display, never written
12
+ * back over a published version: published versions are immutable and are only rebuilt by an
13
+ * explicit action of the customer (golden rule 3).
14
+ *
15
+ * The input is untrusted (golden rule 5) and the runtime may call this on a host page (golden rule
16
+ * 2), so it never throws (TAG-220): every refusal is a result with a stable `reason`.
17
+ *
18
+ * Zod-free and pure. The output is not validated here: callers parse it (`parseManifest`).
19
+ */
20
+ import { CONTRACT_MAJOR, parseContractVersion } from "./contract-version.js";
21
+ import { MANIFEST_LIMITS } from "./limits.js";
22
+ import { PROTO_SCAN_MAX_NODES, findOwnProtoKey } from "./proto-guard.js";
23
+ /**
24
+ * The migration steps of this release, oldest first. Empty while v1 is the only major.
25
+ *
26
+ * Inputs: none. Output: frozen data. Errors: none. Side effects: none.
27
+ */
28
+ export const MANIFEST_MIGRATIONS = Object.freeze([]);
29
+ function isDocument(value) {
30
+ return typeof value === "object" && value !== null && !Array.isArray(value);
31
+ }
32
+ function failure(reason, message) {
33
+ return { ok: false, reason, message };
34
+ }
35
+ /** A name worth echoing: a short identifier such as `TypeError`. */
36
+ const SAFE_ERROR_NAME = /^[A-Za-z][A-Za-z0-9]{0,63}$/;
37
+ /**
38
+ * Name of a caught value, for a message that never echoes input data. The value may come from the
39
+ * input (a throwing `toJSON` or getter): `instanceof` runs a Proxy's `getPrototypeOf` trap and
40
+ * `.name` may be a getter, both of which can throw, so they run inside a try and the name is
41
+ * echoed only when it is a short identifier (TAG-220).
42
+ */
43
+ function errorName(error) {
44
+ try {
45
+ if (error instanceof Error) {
46
+ const name = error.name;
47
+ if (typeof name === "string" && SAFE_ERROR_NAME.test(name))
48
+ return name;
49
+ }
50
+ }
51
+ catch {
52
+ // A hostile thrown value: fall through to the fixed name.
53
+ }
54
+ return "unknown";
55
+ }
56
+ /** Refuses a value that is not a JSON object or holds an own `__proto__` (or is too large). */
57
+ function checkDocument(value, what) {
58
+ if (!isDocument(value))
59
+ return failure("not-an-object", `${what} must be a JSON object`);
60
+ const finding = findOwnProtoKey(value);
61
+ if (finding !== undefined) {
62
+ return failure(finding.reason, `${finding.path || what}: ${finding.message}`);
63
+ }
64
+ return { ok: true, document: value };
65
+ }
66
+ /**
67
+ * Deep copy of decoded JSON through a JSON round trip, bounded like the text `parseManifestJson`
68
+ * accepts: the replacer counts every value (`toJSON` results and sparse array holes included)
69
+ * against `PROTO_SCAN_MAX_NODES`, and the characters of every key and string against
70
+ * `MANIFEST_LIMITS.maxJsonLength`, since one long string referenced many times would otherwise
71
+ * be written out many times. A valid manifest's keys and strings fit, because each takes at least
72
+ * its own length in the JSON text. Throws `stop` when a bound is passed; anything else thrown
73
+ * comes from the input (`toJSON`, getters) or from `JSON.stringify` itself.
74
+ */
75
+ function copyOf(input, stop) {
76
+ let values = 0;
77
+ let characters = 0;
78
+ const text = JSON.stringify(input, function (key, value) {
79
+ values += 1;
80
+ // Array indices reach the replacer as keys but are not written to the text.
81
+ if (!Array.isArray(this))
82
+ characters += key.length;
83
+ if (typeof value === "string")
84
+ characters += value.length;
85
+ if (values > PROTO_SCAN_MAX_NODES || characters > MANIFEST_LIMITS.maxJsonLength)
86
+ throw stop;
87
+ return value;
88
+ });
89
+ return JSON.parse(text);
90
+ }
91
+ /**
92
+ * Migrates a manifest to a target contract major, one step per major.
93
+ *
94
+ * Inputs: decoded JSON (typically `JSON.parse` output) and optional `{ to, migrations }`
95
+ * (defaults: `CONTRACT_MAJOR`, `MANIFEST_MIGRATIONS`). Output: `{ ok: true, manifest, from, to }`
96
+ * where `manifest` is a deep copy, migrated when `from < to` (the copy is returned as is when the
97
+ * input is already of major `to`); or `{ ok: false, reason, message }` (see
98
+ * `ManifestMigrationFailure`). Everything after the copy, the version included, is read from the
99
+ * copy, which is scanned again: a getter or `toJSON` cannot show the scan one thing and the steps
100
+ * another. Messages never quote input values, and paths are bounded (`findOwnProtoKey`).
101
+ * Errors: never throws, also when a step throws (`step-failed`, with the thrown value in the
102
+ * non-enumerable `cause`) or the input throws a hostile value. Side effects: none on the input
103
+ * beyond invoking its getters and `toJSON` once each through the scan and the copy.
104
+ */
105
+ export function migrateManifest(input, options = {}) {
106
+ const target = options.to ?? CONTRACT_MAJOR;
107
+ const migrations = options.migrations ?? MANIFEST_MIGRATIONS;
108
+ let manifest;
109
+ // Compared by identity: `instanceof` on a hostile thrown value could run a Proxy trap.
110
+ const stop = new Error("copy budget exceeded");
111
+ try {
112
+ // The first scan refuses what is too large before JSON.stringify walks it (a sparse array of
113
+ // length 2**32 - 1 used to throw a RangeError here); the second one checks what the copy
114
+ // really holds, since a toJSON may produce anything (TAG-220).
115
+ const scanned = checkDocument(input, "manifest");
116
+ if (!scanned.ok)
117
+ return scanned;
118
+ const copied = checkDocument(copyOf(scanned.document, stop), "manifest (as serialized)");
119
+ if (!copied.ok)
120
+ return copied;
121
+ manifest = copied.document;
122
+ }
123
+ catch (error) {
124
+ if (error === stop) {
125
+ return failure("too-large", `manifest serializes to more than ${String(PROTO_SCAN_MAX_NODES)} values or ${String(MANIFEST_LIMITS.maxJsonLength)} characters of keys and strings`);
126
+ }
127
+ return failure("unreadable", `manifest cannot be read as JSON (${errorName(error)})`);
128
+ }
129
+ const version = parseContractVersion(manifest["contractVersion"]);
130
+ if (version === undefined) {
131
+ return failure("bad-version", "contractVersion must be a semantic version major.minor.patch to migrate");
132
+ }
133
+ if (version.major > target) {
134
+ return failure("newer-major", `contract v${String(version.major)} is newer than the migration target v${String(target)}`);
135
+ }
136
+ for (let major = version.major; major < target; major += 1) {
137
+ const step = migrations.find((candidate) => candidate.from === major);
138
+ if (step?.to !== major + 1) {
139
+ return failure("missing-step", `no migration from contract v${String(major)} to v${String(major + 1)}`);
140
+ }
141
+ let migrated;
142
+ try {
143
+ migrated = step.migrate(manifest);
144
+ }
145
+ catch (error) {
146
+ const refusal = failure("step-failed", `the migration from v${String(step.from)} to v${String(step.to)} threw ${errorName(error)}`);
147
+ return Object.defineProperty(refusal, "cause", { value: error, enumerable: false });
148
+ }
149
+ const migratedVersion = isDocument(migrated)
150
+ ? parseContractVersion(migrated["contractVersion"])
151
+ : undefined;
152
+ if (!isDocument(migrated) || migratedVersion?.major !== step.to) {
153
+ return failure("bad-step", `the migration from v${String(step.from)} must set contractVersion to a v${String(step.to)} version`);
154
+ }
155
+ manifest = migrated;
156
+ }
157
+ return { ok: true, manifest, from: version.major, to: target };
158
+ }
159
+ //# sourceMappingURL=migrate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migrate.js","sourceRoot":"","sources":["../src/migrate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAC7E,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,oBAAoB,EAAE,eAA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-201): component name, prop, event, slot, part, CSS
3
+ * variable, collection and field names. Custom element tags live in `tag-name.ts` (TAG-204).
4
+ *
5
+ * Every rule is a plain regular expression, so the generated JSON Schema enforces exactly what Zod
6
+ * enforces (no refinement that only Zod would see). Lookaheads carry the deny lists (prop names
7
+ * that would collide with the host element). The prop name rules themselves live in the Zod-free
8
+ * `prop-names.ts` (TAG-205), which the runtime may import.
9
+ */
10
+ import * as z from "zod";
11
+ /** Kebab-case member name: events, slots, parts, collections, track events, component name. */
12
+ export declare const KEBAB_NAME_PATTERN: RegExp;
13
+ /**
14
+ * `Object.prototype` members a field name must not be (TAG-205): validators and consumers read
15
+ * `value[name]`, which finds the inherited member when the field is absent (Zod's object schema
16
+ * then rejects every value without a `toString` field, and component code may call it).
17
+ */
18
+ export declare const OBJECT_MEMBER_NAMES: readonly string[];
19
+ /** snake_case name: collection fields and track props, which travel in the snake_case data API. */
20
+ export declare const SNAKE_NAME_PATTERN: RegExp;
21
+ /** Field of a declared object value (prop or event detail): a JS identifier without `$`. */
22
+ export declare const FIELD_NAME_PATTERN: RegExp;
23
+ /** Public CSS custom property, written in full (`--fs-primary-color`). */
24
+ export declare const CSS_VAR_NAME_PATTERN: RegExp;
25
+ /** Component name: kebab-case slug, unique per workspace (uniqueness is checked by the API). */
26
+ export declare const componentNameSchema: z.ZodString;
27
+ /** Prop name; its attribute is the kebab-case form (`maxValue` → `max-value`). */
28
+ export declare const propNameSchema: z.ZodString;
29
+ /** Event, slot, part, collection and track event name. */
30
+ export declare const memberNameSchema: z.ZodString;
31
+ /** Collection field and track prop name. */
32
+ export declare const snakeNameSchema: z.ZodString;
33
+ /** Field of a declared object value. */
34
+ export declare const fieldNameSchema: z.ZodString;
35
+ /** Public CSS custom property name. */
36
+ export declare const cssVarNameSchema: z.ZodString;
37
+ //# sourceMappingURL=names.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"names.d.ts","sourceRoot":"","sources":["../src/names.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AAsBzB,+FAA+F;AAC/F,eAAO,MAAM,kBAAkB,QAAgC,CAAC;AAEhE;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,EAAE,SAAS,MAAM,EAEhD,CAAC;AAIF,mGAAmG;AACnG,eAAO,MAAM,kBAAkB,QAAoE,CAAC;AAEpG,4FAA4F;AAC5F,eAAO,MAAM,kBAAkB,QAA4D,CAAC;AAE5F,0EAA0E;AAC1E,eAAO,MAAM,oBAAoB,QAAkC,CAAC;AAEpE,gGAAgG;AAChG,eAAO,MAAM,mBAAmB,aAID,CAAC;AAEhC,kFAAkF;AAClF,eAAO,MAAM,cAAc,aAID,CAAC;AAE3B,0DAA0D;AAC1D,eAAO,MAAM,gBAAgB,aAID,CAAC;AAE7B,4CAA4C;AAC5C,eAAO,MAAM,eAAe,aAID,CAAC;AAE5B,wCAAwC;AACxC,eAAO,MAAM,eAAe,aAID,CAAC;AAE5B,uCAAuC;AACvC,eAAO,MAAM,gBAAgB,aAID,CAAC"}
package/dist/names.js ADDED
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Identifier schemas of component contract v1 (TAG-201): component name, prop, event, slot, part, CSS
3
+ * variable, collection and field names. Custom element tags live in `tag-name.ts` (TAG-204).
4
+ *
5
+ * Every rule is a plain regular expression, so the generated JSON Schema enforces exactly what Zod
6
+ * enforces (no refinement that only Zod would see). Lookaheads carry the deny lists (prop names
7
+ * that would collide with the host element). The prop name rules themselves live in the Zod-free
8
+ * `prop-names.ts` (TAG-205), which the runtime may import.
9
+ */
10
+ import * as z from "zod";
11
+ import { DOM_MEMBER_SNAPSHOT } from "./dom-members.snapshot.js";
12
+ import { MANIFEST_LIMITS } from "./limits.js";
13
+ import { PROP_NAME_PATTERN } from "./prop-names.js";
14
+ /**
15
+ * Builds a bounded string schema checked by one pattern.
16
+ *
17
+ * Inputs: the pattern, the error message shown when it fails, and the maximum length.
18
+ * Output: a Zod string schema (min length 1). Errors: none at build time. Side effects: none.
19
+ */
20
+ function patternString(pattern, message, maxLength) {
21
+ return z
22
+ .string()
23
+ .min(1, { error: message })
24
+ .max(maxLength, { error: `must be at most ${String(maxLength)} characters` })
25
+ .regex(pattern, { error: message });
26
+ }
27
+ const KEBAB_BODY = "[a-z][a-z0-9]*(?:-[a-z0-9]+)*";
28
+ /** Kebab-case member name: events, slots, parts, collections, track events, component name. */
29
+ export const KEBAB_NAME_PATTERN = new RegExp(`^${KEBAB_BODY}$`);
30
+ /**
31
+ * `Object.prototype` members a field name must not be (TAG-205): validators and consumers read
32
+ * `value[name]`, which finds the inherited member when the field is absent (Zod's object schema
33
+ * then rejects every value without a `toString` field, and component code may call it).
34
+ */
35
+ export const OBJECT_MEMBER_NAMES = Object.freeze(DOM_MEMBER_SNAPSHOT.prototypes.Object.filter((name) => /^[a-zA-Z]/.test(name)));
36
+ const NOT_OBJECT_MEMBER = `(?!(?:${OBJECT_MEMBER_NAMES.join("|")})$)`;
37
+ /** snake_case name: collection fields and track props, which travel in the snake_case data API. */
38
+ export const SNAKE_NAME_PATTERN = new RegExp(`^${NOT_OBJECT_MEMBER}[a-z][a-z0-9]*(?:_[a-z0-9]+)*$`);
39
+ /** Field of a declared object value (prop or event detail): a JS identifier without `$`. */
40
+ export const FIELD_NAME_PATTERN = new RegExp(`^${NOT_OBJECT_MEMBER}[a-zA-Z][a-zA-Z0-9_]*$`);
41
+ /** Public CSS custom property, written in full (`--fs-primary-color`). */
42
+ export const CSS_VAR_NAME_PATTERN = new RegExp(`^--${KEBAB_BODY}$`);
43
+ /** Component name: kebab-case slug, unique per workspace (uniqueness is checked by the API). */
44
+ export const componentNameSchema = patternString(KEBAB_NAME_PATTERN, "name must be kebab-case: lowercase ASCII letters and digits separated by single hyphens, starting with a letter", MANIFEST_LIMITS.nameMaxLength).meta({ id: "ComponentName" });
45
+ /** Prop name; its attribute is the kebab-case form (`maxValue` → `max-value`). */
46
+ export const propNameSchema = patternString(PROP_NAME_PATTERN, 'prop name must be lowerCamelCase, must not start with "on", "aria" or "data" followed by an uppercase letter or digit, and must not be a reserved host element member', MANIFEST_LIMITS.memberNameMaxLength).meta({ id: "PropName" });
47
+ /** Event, slot, part, collection and track event name. */
48
+ export const memberNameSchema = patternString(KEBAB_NAME_PATTERN, "name must be kebab-case: lowercase ASCII letters and digits separated by single hyphens, starting with a letter", MANIFEST_LIMITS.memberNameMaxLength).meta({ id: "MemberName" });
49
+ /** Collection field and track prop name. */
50
+ export const snakeNameSchema = patternString(SNAKE_NAME_PATTERN, "field name must be snake_case: lowercase ASCII letters and digits separated by single underscores, starting with a letter, and not an Object.prototype member (constructor)", MANIFEST_LIMITS.memberNameMaxLength).meta({ id: "SnakeName" });
51
+ /** Field of a declared object value. */
52
+ export const fieldNameSchema = patternString(FIELD_NAME_PATTERN, "field name must start with an ASCII letter, contain only ASCII letters, digits and underscores, and not be an Object.prototype member (constructor, toString, valueOf…)", MANIFEST_LIMITS.memberNameMaxLength).meta({ id: "FieldName" });
53
+ /** Public CSS custom property name. */
54
+ export const cssVarNameSchema = patternString(CSS_VAR_NAME_PATTERN, 'CSS variable name must be "--" followed by a kebab-case name', MANIFEST_LIMITS.cssVarNameMaxLength).meta({ id: "CssVarName" });
55
+ //# sourceMappingURL=names.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"names.js","sourceRoot":"","sources":["../src/names.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AAEzB,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAEpD;;;;;GAKG;AACH,SAAS,aAAa,CAAC,OAAe,EAAE,OAAe,EAAE,SAAiB;IACxE,OAAO,CAAC;SACL,MAAM,EAAE;SACR,GAAG,CAAC,CAAC,EAAE,EAA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jB,uKAAuK,EACvK,eAAe,CAAC,mBAAmB,CACpC,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC;AAE3B,0DAA0D;AAC1D,MAAM,CAAC,MAAM,gBAAgB,GAAG,aAAa,CAC3C,kBAAkB,EAClB,iHAAiH,EACjH,eAAe,CAAC,mBAAmB,CACpC,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,YAAY,EAAE,CAAC,CAAC;AAE7B,4CAA4C;AAC5C,MAAM,CAAC,MAAM,eAAe,GAAG,aAAa,CAC1C,kBAAkB,EAClB,6KAA6K,EAC7K,eAAe,CAAC,mBAAmB,CACpC,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,WAAW,EAAE,CAAC,CAAC;AAE5B,wCAAwC;AACxC,MAAM,CAAC,MAAM,eAAe,GAAG,aAAa,CAC1C,kBAAkB,EAClB,yKAAyK,EACzK,eAAe,CAAC,mBAAmB,CACpC,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,WAAW,EAAE,CAAC,CAAC;AAE5B,uCAAuC;AACvC,MAAM,CAAC,MAAM,gBAAgB,GAAG,aAAa,CAC3C,oBAAoB,EACpB,8DAA8D,EAC9D,eAAe,CAAC,mBAAmB,CACpC,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,YAAY,EAAE,CAAC,CAAC"}
@@ -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
+ //# sourceMappingURL=overage-pricing.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"overage-pricing.d.ts","sourceRoot":"","sources":["../src/overage-pricing.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAmB,KAAK,aAAa,EAAE,MAAM,oBAAoB,CAAC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