@gradial/aci 0.1.52-rc.9 → 0.1.52

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 (254) hide show
  1. package/CHANGELOG.md +126 -0
  2. package/README.md +86 -5
  3. package/dist/astro/error-page.js +1 -0
  4. package/dist/astro/index.js +4 -0
  5. package/dist/astro/page.d.ts +5 -2
  6. package/dist/astro/page.js +35 -23
  7. package/dist/astro/preview.js +2 -17
  8. package/dist/audience-data-models.d.ts +308 -197
  9. package/dist/audience-data-models.js +313 -51
  10. package/dist/cli/compile-registry.mjs +6 -34
  11. package/dist/cli/mintlify-render.mjs +8 -0
  12. package/dist/collect/aci.js +1 -1
  13. package/dist/collect/aci.js.sha256 +1 -1
  14. package/dist/collect/api.d.ts +6 -7
  15. package/dist/collect/api.js +21 -8
  16. package/dist/collect/assignments.d.ts +7 -9
  17. package/dist/collect/assignments.js +23 -32
  18. package/dist/collect/batcher.d.ts +9 -7
  19. package/dist/collect/batcher.js +6 -5
  20. package/dist/collect/consent/envelope.d.ts +7 -1
  21. package/dist/collect/consent/envelope.js +3 -1
  22. package/dist/collect/consent/mapping.d.ts +2 -0
  23. package/dist/collect/consent/mapping.js +1 -0
  24. package/dist/collect/consenthold.d.ts +38 -0
  25. package/dist/collect/consenthold.js +82 -0
  26. package/dist/collect/declarative.js +7 -5
  27. package/dist/collect/gapbuffer.d.ts +13 -4
  28. package/dist/collect/gapbuffer.js +21 -10
  29. package/dist/collect/index.js +78 -21
  30. package/dist/collect/pageviews.d.ts +11 -11
  31. package/dist/collect/pageviews.js +27 -22
  32. package/dist/consent-banner/index.d.ts +17 -0
  33. package/dist/consent-banner/index.js +23 -0
  34. package/dist/content/index.d.ts +2 -1
  35. package/dist/content/index.js +4 -1
  36. package/dist/content/provider.d.ts +16 -2
  37. package/dist/content/provider.js +5 -1
  38. package/dist/content/resolve-slots.d.ts +24 -2
  39. package/dist/content/resolve-slots.js +127 -21
  40. package/dist/content/types.d.ts +5 -1
  41. package/dist/edge/expression-capabilities.v1.d.ts +106 -0
  42. package/dist/edge/expression-capabilities.v1.js +165 -0
  43. package/dist/index.d.ts +1 -2
  44. package/dist/index.js +0 -1
  45. package/dist/internal/domain/edge/identity.d.ts +47 -4
  46. package/dist/internal/domain/edge/identity.js +130 -26
  47. package/dist/internal/domain/edge/index.d.ts +1 -1
  48. package/dist/internal/domain/edge/index.js +1 -1
  49. package/dist/internal/domain/edge/mimic_token.d.ts +14 -0
  50. package/dist/internal/domain/edge/mimic_token.js +125 -0
  51. package/dist/internal/domain/edge/personalization-core.d.ts +61 -22
  52. package/dist/internal/domain/edge/personalization-core.js +790 -200
  53. package/dist/internal/domain/edge/personalization_index.d.ts +17 -0
  54. package/dist/internal/domain/edge/personalization_index.js +55 -0
  55. package/dist/internal/domain/edge/resolve.js +76 -39
  56. package/dist/internal/domain/edge/testdata/flat_only_validator_v1.d.ts +10 -0
  57. package/dist/internal/domain/edge/testdata/flat_only_validator_v1.js +253 -0
  58. package/dist/internal/domain/edge/types.d.ts +82 -78
  59. package/dist/internal/domain/edge/types.js +3 -3
  60. package/dist/internal/domain/edge/variant_key.d.ts +4 -0
  61. package/dist/internal/domain/edge/variant_key.js +56 -0
  62. package/dist/internal/platform/collectionstore/errors.d.ts +24 -0
  63. package/dist/internal/platform/collectionstore/errors.js +48 -0
  64. package/dist/mintlify/blocks.d.ts +6 -0
  65. package/dist/mintlify/blocks.js +201 -0
  66. package/dist/mintlify/config.d.ts +3 -0
  67. package/dist/mintlify/config.js +77 -0
  68. package/dist/mintlify/index.d.ts +3 -0
  69. package/dist/mintlify/index.js +2 -0
  70. package/dist/mintlify/json.d.ts +8 -0
  71. package/dist/mintlify/json.js +37 -0
  72. package/dist/mintlify/materialize.d.ts +14 -0
  73. package/dist/mintlify/materialize.js +254 -0
  74. package/dist/mintlify/types.d.ts +74 -0
  75. package/dist/mintlify/types.js +1 -0
  76. package/dist/mintlify/validate.d.ts +7 -0
  77. package/dist/mintlify/validate.js +256 -0
  78. package/dist/next/assignments-navigation.d.ts +4 -0
  79. package/dist/next/assignments-navigation.js +18 -0
  80. package/dist/next/assignments-script.d.ts +3 -2
  81. package/dist/next/assignments-script.js +5 -5
  82. package/dist/next/error-pages.d.ts +4 -0
  83. package/dist/next/error-pages.js +4 -0
  84. package/dist/next/error-seat-payload.d.ts +2 -1
  85. package/dist/next/error-seat-payload.js +14 -24
  86. package/dist/next/error-seat.js +7 -2
  87. package/dist/next/index.d.ts +1 -1
  88. package/dist/next/index.js +3 -1
  89. package/dist/next/page.d.ts +2 -1
  90. package/dist/next/page.js +15 -4
  91. package/dist/next/release-context.d.ts +30 -0
  92. package/dist/next/release-context.js +56 -0
  93. package/dist/next/render.d.ts +1 -1
  94. package/dist/next/render.js +15 -5
  95. package/dist/next/server.d.ts +9 -3
  96. package/dist/next/server.js +17 -32
  97. package/dist/preview/core.d.ts +1 -0
  98. package/dist/preview/core.js +27 -0
  99. package/dist/react/VideoPlayer.d.ts +3 -3
  100. package/dist/react/index.d.ts +3 -3
  101. package/dist/registry.d.ts +4 -2
  102. package/dist/testing/conformance/checks.d.ts +2 -2
  103. package/dist/testing/conformance/checks.js +2 -0
  104. package/dist/testing/conformance/index.d.ts +1 -0
  105. package/dist/testing/conformance/index.js +1 -0
  106. package/dist/testing/conformance/next-stubs.d.ts +6 -0
  107. package/dist/testing/conformance/next-stubs.js +9 -0
  108. package/dist/testing/conformance/preset.d.ts +3 -2
  109. package/dist/testing/conformance/preset.js +15 -8
  110. package/dist/testing/conformance/root-identity.d.ts +31 -0
  111. package/dist/testing/conformance/root-identity.js +361 -0
  112. package/dist/testing/conformance/stubs/next-image.d.ts +7 -0
  113. package/dist/testing/conformance/stubs/next-image.js +5 -0
  114. package/dist/testing/conformance/stubs/next-link.d.ts +7 -0
  115. package/dist/testing/conformance/stubs/next-link.js +4 -0
  116. package/dist/testing/conformance/types.d.ts +5 -2
  117. package/dist/testing/index.d.ts +1 -1
  118. package/dist/testing/index.js +4 -3
  119. package/dist/types/block-ref.js +2 -2
  120. package/dist/types/component.d.ts +9 -0
  121. package/dist/types/config.d.ts +0 -1
  122. package/dist/types/index.d.ts +0 -1
  123. package/dist/types/index.js +0 -1
  124. package/dist/types/page.d.ts +0 -1
  125. package/migrations/conformance-registry.md +22 -0
  126. package/migrations/experiment-goal-ids.md +43 -0
  127. package/package.json +21 -7
  128. package/src/cli/compile-registry.mjs +6 -30
  129. package/src/cli/mintlify-render.mjs +9 -0
  130. package/src/types/block-ref.test.ts +16 -1
  131. package/src/types/block-ref.ts +2 -2
  132. package/src/types/component.ts +10 -0
  133. package/src/types/config.ts +0 -1
  134. package/src/types/index.ts +0 -1
  135. package/src/types/page.ts +0 -1
  136. package/templates/astro/starter-content/src/components/chrome/Footer.astro +5 -3
  137. package/templates/astro/starter-content/src/components/chrome/Header.astro +5 -3
  138. package/templates/astro/starter-content/src/components/elements/Button.astro +5 -2
  139. package/templates/astro/starter-content/src/components/elements/ButtonBlock.astro +5 -3
  140. package/templates/astro/starter-content/src/components/sections/ContainerSection.astro +4 -3
  141. package/templates/astro/starter-content/src/components/sections/FeatureCard.astro +4 -3
  142. package/templates/astro/starter-content/src/components/sections/FeatureGrid.astro +4 -3
  143. package/templates/astro/starter-content/src/components/sections/HomeHero.astro +5 -3
  144. package/templates/astro/starter-content/src/components/sections/PersonalizationChoice.astro +4 -3
  145. package/templates/astro/starter-content/src/components/sections/StatsBar.astro +4 -3
  146. package/templates/astro/starter-content/src/fixtures/sections.ts +1 -1
  147. package/templates/astro/starter-content/src/stories/CompositionStoryFrame.astro +7 -2
  148. package/templates/astro/template/.aci.yaml.tmpl +0 -1
  149. package/templates/astro/template/package.json.tmpl +5 -5
  150. package/templates/astro/template/src/layouts/SiteLayout.astro +2 -2
  151. package/templates/common/.agents/skills/aci/SKILL.md +58 -1
  152. package/templates/common/.agents/skills/authoring/SKILL.md +194 -42
  153. package/templates/common/.agents/skills/authoring/references/block-registry.md +19 -3
  154. package/templates/common/.agents/skills/authoring/references/contracts.md +9 -30
  155. package/templates/common/.agents/skills/authoring/references/repo-structure.md +5 -4
  156. package/templates/common/.agents/skills/authoring/references/sdk-server-functions.md +3 -3
  157. package/templates/common/.agents/skills/dam-delivery/SKILL.md +216 -0
  158. package/templates/common/.agents/skills/dam-delivery/references/permalink-grammar.md +167 -0
  159. package/templates/common/.agents/skills/migration/references/canon-migration.md +18 -67
  160. package/templates/common/.agents/skills/migration/references/selector-map.md +1 -1
  161. package/templates/common/.content/fragments/navbar/_index.json +24 -0
  162. package/templates/common/.content/fragments/site-footer/_index.json +61 -0
  163. package/templates/common/.content/pages/404/_index.json +4 -2
  164. package/templates/common/.content/pages/_index.json +0 -1
  165. package/templates/common/.content/pages/error/_index.json +4 -2
  166. package/templates/common/.content/schemas/site.schema.json +11 -1
  167. package/templates/common/.content/templates/error.json +24 -0
  168. package/templates/common/.content/templates/home.json +28 -0
  169. package/templates/common/.content/templates/site.json +8 -0
  170. package/templates/common/.content/templates/standard.json +24 -0
  171. package/templates/common/.nvmrc +1 -1
  172. package/templates/common/starter-content/.content/config/site.json +1 -1
  173. package/templates/common/starter-content/.content/dam/README.md +74 -0
  174. package/templates/common/starter-content/.content/dam/folders/seed/{ast_site_about_hero → 000000000000000000000000101}/asset.json +1 -1
  175. package/templates/common/starter-content/.content/dam/folders/seed/{ast_site_home_hero → 000000000000000000000000102}/asset.json +1 -1
  176. package/templates/common/starter-content/.content/pages/404/_index.json +1 -2
  177. package/templates/common/starter-content/.content/pages/{home/_index.json → _index.json} +14 -3
  178. package/templates/common/starter-content/.content/pages/about/_index.json +2 -2
  179. package/templates/common/starter-content/.content/pages/error/_index.json +1 -2
  180. package/templates/common/starter-content/.content/patterns/components/button.json +2 -2
  181. package/templates/common/starter-content/.content/patterns/components/container.json +8 -3
  182. package/templates/common/starter-content/.content/patterns/components/feature_card.json +2 -2
  183. package/templates/common/starter-content/.content/patterns/components/feature_grid.json +5 -3
  184. package/templates/common/starter-content/.content/patterns/components/home_hero.json +2 -2
  185. package/templates/common/starter-content/.content/patterns/components/personalization_choice.json +2 -2
  186. package/templates/common/starter-content/.content/patterns/components/site-footer.json +2 -2
  187. package/templates/common/starter-content/.content/patterns/components/site-navigation.json +2 -2
  188. package/templates/common/starter-content/.content/patterns/components/stats_bar.json +2 -2
  189. package/templates/common/starter-content/.content/schemas/site.schema.json +11 -1
  190. package/templates/nextjs/starter-content/src/components/chrome/Footer.tsx +4 -3
  191. package/templates/nextjs/starter-content/src/components/chrome/Header.tsx +4 -3
  192. package/templates/nextjs/starter-content/src/components/elements/Button.tsx +4 -3
  193. package/templates/nextjs/starter-content/src/components/elements/ButtonBlock.tsx +4 -3
  194. package/templates/nextjs/starter-content/src/components/sections/ContainerSection.tsx +4 -2
  195. package/templates/nextjs/starter-content/src/components/sections/FeatureCard.tsx +4 -3
  196. package/templates/nextjs/starter-content/src/components/sections/FeatureGrid.tsx +4 -2
  197. package/templates/nextjs/starter-content/src/components/sections/HomeHero.tsx +4 -3
  198. package/templates/nextjs/starter-content/src/components/sections/PersonalizationChoice.tsx +4 -2
  199. package/templates/nextjs/starter-content/src/components/sections/StatsBar.tsx +4 -3
  200. package/templates/nextjs/template/.aci.yaml +0 -1
  201. package/templates/nextjs/template/.aci.yaml.tmpl +0 -1
  202. package/templates/nextjs/template/package.json.tmpl +4 -3
  203. package/templates/nextjs/template/src/app/_components/c15t-bridge.ts +30 -0
  204. package/templates/nextjs/template/src/app/_components/c15t-consent-ui.tsx +37 -0
  205. package/templates/nextjs/template/src/app/_components/consent-manager.css +63 -0
  206. package/templates/nextjs/template/src/app/_components/consent-manager.tsx +76 -0
  207. package/templates/nextjs/template/src/app/fonts/inter/OFL.txt +93 -0
  208. package/templates/nextjs/template/src/app/fonts/inter/inter-latin.woff2 +0 -0
  209. package/templates/nextjs/template/src/app/fonts/space-grotesk/OFL.txt +93 -0
  210. package/templates/nextjs/template/src/app/fonts/space-grotesk/space-grotesk-latin.woff2 +0 -0
  211. package/templates/nextjs/template/src/app/layout.tsx +12 -7
  212. package/templates/nextjs/template/tests/conformance.test.ts.tmpl +1 -0
  213. package/dist/define-layout.d.ts +0 -6
  214. package/dist/define-layout.js +0 -14
  215. package/dist/edge/personalization-core.d.ts +0 -11
  216. package/dist/edge/personalization-core.js +0 -269
  217. package/dist/internal/domain/edge/compose.d.ts +0 -24
  218. package/dist/internal/domain/edge/compose.js +0 -89
  219. package/dist/internal/domain/edge/record/codec.d.ts +0 -71
  220. package/dist/internal/domain/edge/record/codec.js +0 -401
  221. package/dist/next/collect-route.d.ts +0 -19
  222. package/dist/next/collect-route.js +0 -459
  223. package/dist/next/edge-config.d.ts +0 -1
  224. package/dist/next/edge-config.js +0 -92
  225. package/dist/next/envelope-digest.d.ts +0 -21
  226. package/dist/next/envelope-digest.js +0 -58
  227. package/dist/next/middleware.d.ts +0 -40
  228. package/dist/next/middleware.js +0 -475
  229. package/dist/next/personalization-host.d.ts +0 -134
  230. package/dist/next/personalization-host.js +0 -270
  231. package/dist/next/root-layout.d.ts +0 -4
  232. package/dist/next/root-layout.js +0 -5
  233. package/dist/next/vercel-collect-sdk-route.d.ts +0 -27
  234. package/dist/next/vercel-collect-sdk-route.js +0 -181
  235. package/dist/next/vercel-edge-projection-v1.d.ts +0 -24
  236. package/dist/next/vercel-edge-projection-v1.js +0 -880
  237. package/dist/next/vercel-personalization.d.ts +0 -4
  238. package/dist/next/vercel-personalization.js +0 -4
  239. package/dist/next/vercel-s3-personalization.d.ts +0 -79
  240. package/dist/next/vercel-s3-personalization.js +0 -570
  241. package/dist/types/layout.d.ts +0 -24
  242. package/src/types/layout.ts +0 -29
  243. package/templates/astro/starter-content/src/render/RenderPage.astro +0 -67
  244. package/templates/astro/template/src/cms/contracts/layouts/index.ts +0 -18
  245. package/templates/common/starter-content/.content/patterns/layouts/default.json +0 -14
  246. package/templates/nextjs/starter-content/src/components/elements/AtomicBlock.tsx +0 -13
  247. package/templates/nextjs/template/src/cms/contracts/layouts/index.ts +0 -16
  248. /package/dist/{types/layout.js → cli/mintlify-render.d.mts} +0 -0
  249. /package/templates/common/starter-content/.content/dam/folders/seed/{ast_site_home_hero → 000000000000000000000000101}/editorial.json +0 -0
  250. /package/templates/common/starter-content/.content/dam/folders/seed/{ast_site_about_hero → 000000000000000000000000101}/governance.json +0 -0
  251. /package/templates/common/starter-content/.content/dam/folders/seed/{ast_site_home_hero → 000000000000000000000000101}/versions/v0001.json +0 -0
  252. /package/templates/common/starter-content/.content/dam/folders/seed/{ast_site_about_hero → 000000000000000000000000102}/editorial.json +0 -0
  253. /package/templates/common/starter-content/.content/dam/folders/seed/{ast_site_home_hero → 000000000000000000000000102}/governance.json +0 -0
  254. /package/templates/common/starter-content/.content/dam/folders/seed/{ast_site_about_hero → 000000000000000000000000102}/versions/v0001.json +0 -0
@@ -1,401 +0,0 @@
1
- // Compact JSON codec for edge-decisioning route records and classification data.
2
- //
3
- // project(): canonical → compact (short field names via alias table, omit defaults)
4
- // expand(): compact → canonical (reverse, never throws — returns INVALID sentinel on failure)
5
- //
6
- // Laws (property-tested):
7
- // expand(project(r)) ≡ normalize(r)
8
- // expand() never throws — malformed input → INVALID
9
- // Unknown field code on expand = invalid data (→ base + alarm)
10
- //
11
- // The alias table is the single source of truth (schema/alias-table.v1.json).
12
- // These codecs are hand-written from it; cross-language round-trip tests
13
- // enforce drift between the Go and TS implementations.
14
- //
15
- // Failure is represented by the exported INVALID sentinel (a unique object).
16
- // Expand functions return the value directly on success, or INVALID on failure.
17
- // Callers check `result === INVALID`. This avoids the {ok,value,reason}
18
- // wrapper in the byte-constrained runtime.
19
- // ── INVALID sentinel ─────────────────────────────────────────────────
20
- /**
21
- * Unique sentinel object returned by expand functions on failure.
22
- * Callers check `result === INVALID`. Never throws.
23
- */
24
- export const INVALID = Symbol();
25
- const te = new TextEncoder();
26
- // ── Alias table (hand-mirrored from schema/alias-table.v1.json) ──────
27
- const FIELD_ALIASES = {
28
- schema: 's', path: 'p', dispatch: 'd', variants: 'v', experiments: 'x',
29
- priority: 'pr', kind: 'k', rule: 'r', all: 'a', any: 'n', field: 'f',
30
- operator: 'o', value: 'w', audiences: 'au', segments: 'sg',
31
- classification: 'c', arms: 'ar', id: 'id', status: 'st',
32
- allocationVersion: 'av', salt: 'sl', allocationBasisPoints: 'ab',
33
- variantKey: 'vk', variantValues: 'vv', artifactPath: 'ap',
34
- displayName: 'dn', primaryGoalId: 'pg', goalIds: 'gl', role: 'ro',
35
- };
36
- const DISPATCH_KIND_TO_COMPACT = {
37
- 'static-direct': 's',
38
- };
39
- const DISPATCH_KIND_FROM_COMPACT = {
40
- s: 'static-direct',
41
- };
42
- const OPERATOR_TO_COMPACT = {
43
- equals: 'eq', contains: 'ct', startsWith: 'sw', exists: 'ex',
44
- };
45
- const OPERATOR_FROM_COMPACT = {
46
- eq: 'equals', ct: 'contains', sw: 'startsWith', ex: 'exists',
47
- };
48
- const EXPERIMENT_STATUS_TO_COMPACT = {
49
- running: 'r', paused: 'p', completed: 'd',
50
- };
51
- const EXPERIMENT_STATUS_FROM_COMPACT = {
52
- r: 'running', p: 'paused', d: 'completed',
53
- };
54
- const EXPERIMENT_KIND_TO_COMPACT = {
55
- ab: 'a', abn: 'n',
56
- };
57
- const EXPERIMENT_KIND_FROM_COMPACT = {
58
- a: 'ab', n: 'abn',
59
- };
60
- // Compact type guard — reduces minified bytes vs repeated typeof+null+isArray checks
61
- function isObj(v) {
62
- return typeof v === 'object' && v !== null && !Array.isArray(v);
63
- }
64
- function projectDispatch(dispatch) {
65
- if (dispatch.kind !== 'static-direct' || !dispatch.artifactPath) {
66
- throw new Error('edge dispatch must name one static artifact');
67
- }
68
- return { k: DISPATCH_KIND_TO_COMPACT[dispatch.kind], ap: dispatch.artifactPath };
69
- }
70
- function expandDispatch(raw) {
71
- if (raw == null)
72
- return undefined;
73
- if (!isObj(raw))
74
- return INVALID;
75
- const kind = DISPATCH_KIND_FROM_COMPACT[raw.k];
76
- const artifactPath = raw.ap;
77
- if (kind !== 'static-direct' || typeof artifactPath !== 'string' || artifactPath.length === 0)
78
- return INVALID;
79
- return { kind, artifactPath };
80
- }
81
- function projectCondition(cond) {
82
- if (!cond || !cond.field || !cond.operator)
83
- return null;
84
- const compactOp = OPERATOR_TO_COMPACT[cond.operator];
85
- if (!compactOp)
86
- return null;
87
- const result = { f: cond.field, o: compactOp };
88
- if (cond.operator !== 'exists' && cond.value !== undefined)
89
- result.w = cond.value;
90
- return result;
91
- }
92
- function expandCondition(raw) {
93
- if (!isObj(raw))
94
- return INVALID;
95
- const f = raw.f;
96
- const co = raw.o;
97
- if (typeof f !== 'string')
98
- return INVALID;
99
- const op = OPERATOR_FROM_COMPACT[co];
100
- if (!op)
101
- return INVALID;
102
- const c = { field: f, operator: op };
103
- if (op !== 'exists' && raw.w !== undefined)
104
- c.value = raw.w;
105
- return c;
106
- }
107
- function projectRule(rule) {
108
- if (!rule)
109
- return undefined;
110
- const result = {};
111
- if (rule.all && rule.all.length > 0)
112
- result.a = rule.all.map(projectCondition).filter((c) => c !== null);
113
- if (rule.any && rule.any.length > 0)
114
- result.n = rule.any.map(projectCondition).filter((c) => c !== null);
115
- if (!result.a && !result.n)
116
- return undefined;
117
- return result;
118
- }
119
- function expandRule(raw) {
120
- if (raw == null)
121
- return undefined;
122
- if (!isObj(raw))
123
- return INVALID;
124
- const rule = {};
125
- if (Array.isArray(raw.a))
126
- for (const c of raw.a) {
127
- const r = expandCondition(c);
128
- if (r === INVALID)
129
- return INVALID;
130
- if (r)
131
- (rule.all = rule.all || []).push(r);
132
- }
133
- if (Array.isArray(raw.n))
134
- for (const c of raw.n) {
135
- const r = expandCondition(c);
136
- if (r === INVALID)
137
- return INVALID;
138
- if (r)
139
- (rule.any = rule.any || []).push(r);
140
- }
141
- if (!rule.all && !rule.any)
142
- return undefined;
143
- return rule;
144
- }
145
- function projectVariant(variant) {
146
- const result = {};
147
- if (variant.priority)
148
- result.pr = variant.priority;
149
- if (variant.rule)
150
- result.r = projectRule(variant.rule);
151
- result.d = projectDispatch(variant.dispatch);
152
- if (variant.variantValues && Object.keys(variant.variantValues).length > 0)
153
- result.vv = variant.variantValues;
154
- return result;
155
- }
156
- function expandVariant(raw) {
157
- if (!isObj(raw))
158
- return INVALID;
159
- const obj = raw;
160
- if (obj.d === undefined)
161
- return INVALID;
162
- const dispatchResult = expandDispatch(obj.d);
163
- if (dispatchResult === INVALID || !dispatchResult)
164
- return INVALID;
165
- const variant = { variantKey: '', dispatch: dispatchResult };
166
- if (typeof obj.pr === 'number')
167
- variant.priority = obj.pr;
168
- if (obj.r !== undefined) {
169
- const ruleResult = expandRule(obj.r);
170
- if (ruleResult === INVALID)
171
- return INVALID;
172
- if (ruleResult)
173
- variant.rule = ruleResult;
174
- }
175
- if (isObj(obj.vv))
176
- variant.variantValues = obj.vv;
177
- return variant;
178
- }
179
- export function projectRouteRecord(entry) {
180
- const result = { p: entry.pattern, d: projectDispatch(entry.dispatch) };
181
- result.s = 1;
182
- if (entry.variants && Object.keys(entry.variants).length > 0) {
183
- result.v = {};
184
- for (const [key, variant] of Object.entries(entry.variants))
185
- result.v[key] = projectVariant(variant);
186
- }
187
- return result;
188
- }
189
- export function expandRouteRecord(raw) {
190
- if (!isObj(raw))
191
- return INVALID;
192
- const obj = raw;
193
- if (obj.s !== undefined && obj.s !== 1)
194
- return INVALID;
195
- const path = obj.p;
196
- if (typeof path !== 'string')
197
- return INVALID;
198
- if (obj.d === undefined)
199
- return INVALID;
200
- const dispatchResult = expandDispatch(obj.d);
201
- if (dispatchResult === INVALID || !dispatchResult)
202
- return INVALID;
203
- const entry = { pattern: path, priority: 0, dispatch: dispatchResult };
204
- if (obj.v !== undefined) {
205
- if (!isObj(obj.v))
206
- return INVALID;
207
- entry.variants = {};
208
- for (const [key, variantRaw] of Object.entries(obj.v)) {
209
- const variantResult = expandVariant(variantRaw);
210
- if (variantResult === INVALID)
211
- return INVALID;
212
- const variant = variantResult;
213
- variant.variantKey = key;
214
- if (!variant.variantValues)
215
- variant.variantValues = variantValuesFromKey(key);
216
- entry.variants[key] = variant;
217
- }
218
- }
219
- return entry;
220
- }
221
- export function projectClassificationData(data) {
222
- const result = {};
223
- if (data.audiences && Object.keys(data.audiences).length > 0) {
224
- result.au = {};
225
- for (const [key, def] of Object.entries(data.audiences)) {
226
- const entry = {};
227
- const rule = projectRule(def.rule);
228
- if (rule)
229
- entry.r = rule;
230
- result.au[key] = entry;
231
- }
232
- }
233
- if (data.segments && Object.keys(data.segments).length > 0) {
234
- result.sg = {};
235
- for (const [key, def] of Object.entries(data.segments)) {
236
- const entry = {};
237
- const rule = projectRule(def.rule);
238
- if (rule)
239
- entry.r = rule;
240
- result.sg[key] = entry;
241
- }
242
- }
243
- if (data.experiments && Object.keys(data.experiments).length > 0) {
244
- result.x = {};
245
- for (const [key, exp] of Object.entries(data.experiments))
246
- result.x[key] = projectExperiment(exp);
247
- }
248
- return result;
249
- }
250
- function projectExperiment(exp) {
251
- const result = { id: exp.id };
252
- if (exp.status) {
253
- const c = EXPERIMENT_STATUS_TO_COMPACT[exp.status];
254
- if (c)
255
- result.st = c;
256
- }
257
- if (exp.kind) {
258
- const c = EXPERIMENT_KIND_TO_COMPACT[exp.kind];
259
- if (c)
260
- result.k = c;
261
- }
262
- if (exp.allocationVersion)
263
- result.av = exp.allocationVersion;
264
- if (exp.salt)
265
- result.sl = exp.salt;
266
- if (exp.priority)
267
- result.pr = exp.priority;
268
- if (exp.arms && exp.arms.length > 0) {
269
- result.ar = exp.arms.map((arm) => {
270
- const ca = { id: arm.id };
271
- if (arm.allocationBasisPoints)
272
- ca.ab = arm.allocationBasisPoints;
273
- if (arm.variantKey)
274
- ca.vk = arm.variantKey;
275
- return ca;
276
- });
277
- }
278
- return result;
279
- }
280
- export function expandClassificationData(raw) {
281
- if (!isObj(raw))
282
- return INVALID;
283
- const obj = raw;
284
- const data = { audiences: {}, segments: {}, experiments: {} };
285
- if (obj.au !== undefined) {
286
- if (!isObj(obj.au))
287
- return INVALID;
288
- for (const [key, defRaw] of Object.entries(obj.au)) {
289
- if (!isObj(defRaw))
290
- return INVALID;
291
- const ruleResult = expandRule(defRaw.r);
292
- if (ruleResult === INVALID)
293
- return INVALID;
294
- data.audiences[key] = { rule: ruleResult || { all: [] } };
295
- }
296
- }
297
- if (obj.sg !== undefined) {
298
- if (!isObj(obj.sg))
299
- return INVALID;
300
- for (const [key, defRaw] of Object.entries(obj.sg)) {
301
- if (!isObj(defRaw))
302
- return INVALID;
303
- const ruleResult = expandRule(defRaw.r);
304
- if (ruleResult === INVALID)
305
- return INVALID;
306
- data.segments[key] = { rule: ruleResult || { all: [] } };
307
- }
308
- }
309
- if (obj.x !== undefined) {
310
- if (!isObj(obj.x))
311
- return INVALID;
312
- for (const [key, expRaw] of Object.entries(obj.x)) {
313
- const expResult = expandExperiment(expRaw);
314
- if (expResult === INVALID)
315
- return INVALID;
316
- data.experiments[key] = expResult;
317
- }
318
- }
319
- return data;
320
- }
321
- function expandExperiment(raw) {
322
- if (!isObj(raw))
323
- return INVALID;
324
- const obj = raw;
325
- const id = obj.id;
326
- if (typeof id !== 'string')
327
- return INVALID;
328
- const exp = { id, status: 'running', kind: 'ab', arms: [] };
329
- if (typeof obj.st === 'string') {
330
- const expanded = EXPERIMENT_STATUS_FROM_COMPACT[obj.st];
331
- if (!expanded)
332
- return INVALID;
333
- exp.status = expanded;
334
- }
335
- if (typeof obj.k === 'string') {
336
- const expanded = EXPERIMENT_KIND_FROM_COMPACT[obj.k];
337
- if (!expanded)
338
- return INVALID;
339
- exp.kind = expanded;
340
- }
341
- if (typeof obj.av === 'string')
342
- exp.allocationVersion = obj.av;
343
- if (typeof obj.sl === 'string')
344
- exp.salt = obj.sl;
345
- if (typeof obj.pr === 'number')
346
- exp.priority = obj.pr;
347
- if (Array.isArray(obj.ar)) {
348
- exp.arms = [];
349
- for (const armRaw of obj.ar) {
350
- if (!isObj(armRaw))
351
- return INVALID;
352
- const armObj = armRaw;
353
- if (typeof armObj.id !== 'string')
354
- return INVALID;
355
- exp.arms.push({
356
- id: armObj.id,
357
- allocationBasisPoints: typeof armObj.ab === 'number' ? armObj.ab : 0,
358
- variantKey: typeof armObj.vk === 'string' ? armObj.vk : '',
359
- });
360
- }
361
- }
362
- return exp;
363
- }
364
- // ── Marker (tri-state: record | marker | absent) ─────────────────────
365
- export const MARKER = '{"s":1,"e":1}';
366
- export function isMarker(raw) {
367
- return raw === MARKER;
368
- }
369
- // ── Serialization helpers ────────────────────────────────────────────
370
- export function canonicalSerialize(value) {
371
- return JSON.stringify(sortKeys(value));
372
- }
373
- function sortKeys(value) {
374
- if (value === null || typeof value !== 'object')
375
- return value;
376
- if (Array.isArray(value))
377
- return value.map(sortKeys);
378
- const sorted = {};
379
- for (const key of Object.keys(value).sort())
380
- sorted[key] = sortKeys(value[key]);
381
- return sorted;
382
- }
383
- // ── VariantKey parsing ───────────────────────────────────────────────
384
- export function variantValuesFromKey(key) {
385
- const values = {};
386
- for (const part of String(key || '').replace(/&/g, ';').split(';')) {
387
- const sep = part.indexOf('=');
388
- if (sep > 0)
389
- values[part.slice(0, sep).trim()] = part.slice(sep + 1).trim();
390
- }
391
- return values;
392
- }
393
- // ── Path hashing (FNV-1a-32, hex 16 chars) ───────────────────────────
394
- export function pathHash16(path) {
395
- let hash = 0x811c9dc5;
396
- for (const byte of te.encode(path)) {
397
- hash ^= byte;
398
- hash = Math.imul(hash, 0x01000193) >>> 0;
399
- }
400
- return hash.toString(16).padStart(8, '0') + '00000000';
401
- }
@@ -1,19 +0,0 @@
1
- import { type IdentitySigningKeys, type PersonalizationCollectionStore } from './personalization-host.js';
2
- export interface PersonalizationCollectRouteConfig {
3
- siteId: string;
4
- store: PersonalizationCollectionStore;
5
- identityKeys: IdentitySigningKeys;
6
- /**
7
- * Claims verify keys (kid -> secret) for withdrawal EVIDENCE
8
- * (anonymous-experiments REQ-6): suppression fires only when the request
9
- * presents a signature-verified aci_claims cookie — presence alone is
10
- * spoofable, and under universal minting an unverified trigger would
11
- * suppress every reject-all visitor. Empty = evidence never verifies =
12
- * suppression disabled (fails safe).
13
- */
14
- claimsKeys?: Record<string, string>;
15
- retentionSeconds?: number;
16
- secureCookies?: boolean;
17
- now?: () => Date;
18
- }
19
- export declare function createPersonalizationCollectRoute(config: PersonalizationCollectRouteConfig): (request: Request) => Promise<Response>;