@decocms/blocks 8.18.1 → 8.19.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/dist/v8/client.js CHANGED
@@ -189,17 +189,7 @@ function copyVisitor(visitor) {
189
189
  if (typeof visitor !== "object" || visitor === null || typeof visitor.id !== "string") {
190
190
  return null;
191
191
  }
192
- const strings = (value) => Array.isArray(value) ? value.filter((entry) => typeof entry === "string") : [];
193
- const copy = {
194
- id: visitor.id,
195
- active: Object.freeze(strings(visitor.active)),
196
- inactiveDrawn: Object.freeze(strings(visitor.inactiveDrawn)),
197
- pct: Object.freeze(Object.assign(Object.create(null), visitor.pct)),
198
- };
199
- if (typeof visitor.exp === "object" && visitor.exp !== null) {
200
- copy.exp = Object.freeze(Object.assign(Object.create(null), visitor.exp));
201
- }
202
- return Object.freeze(copy);
192
+ return Object.freeze({ id: visitor.id });
203
193
  }
204
194
  function asCMSError(error) {
205
195
  return isResolutionError(error) ? error : errors.blockFailed("<unknown>", [], error);
@@ -1 +1 @@
1
- {"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/v8/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EACL,SAAS,EAET,gBAAgB,EAChB,QAAQ,EACR,IAAI,GACL,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,kBAAkB,EAAE,oBAAoB,EAAkB,MAAM,cAAc,CAAC;AACxF,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAExD,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAY,OAAO,EAAkB,MAAM,UAAU,CAAC;AACxE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAoCzC,6EAA6E;AAC7E,MAAM,CAAC,MAAM,YAAY,GACvB,gGAAgG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C,IAAI,EAAqC,EAAE,CAC7D,aAAa,CAAC,IAAI,CAAC,CACN,CAAC;AAClB,CAAC;AAED;;;GAGG;AACH,SAAS,WAAW,CAAC,OAAmC;IACtD,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,KAAK,IAAI,IAAI,OAAO,OAAO,CAAC,EAAE,KAAK,QAAQ,EAAE,CAAC;QACtF,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,OAAO,CAAC,EAAE,EAAE,CAAC,CAAC;AAC3C,CAAC;AAED,SAAS,UAAU,CAAC,KAAc;IAChC,OAAO,iBAAiB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,WAAW,EAAE,EAAE,EAAE,KAAK,CAAC,CAAC;AACvF,CAAC"}
@@ -14,45 +14,27 @@
14
14
  * storage in an app) and hands it to `cms.client({ visitor })`; the built-in
15
15
  * `split-traffic` calls `assign` with it.
16
16
  *
17
- * The stored form is v7's `deco_segment` (the same fields and encoding; names
18
- * sorted by code unit rather than v7's `localeCompare`) plus an `id`, so a
19
- * visitor carried over from v7 keeps the group v7 put them in and analytics
20
- * keeps reading the cookie it already reads. A visitor is written once, when
21
- * it has no id; v7's stored assignments are read and honoured, never rewritten.
17
+ * A visitor is only its id, stored as is in the `deco_vid` cookie and written
18
+ * once, on a first visit. v7's `deco_segment` is neither read nor written:
19
+ * its stored decisions aren't honoured, and a visitor who has only it gets a
20
+ * new id.
22
21
  */
23
22
  /** The saved block `experiments`: each test's name and the whole percentage of visitors in it, 0–100. */
24
23
  export type Experiments = Record<string, number>;
25
24
  /** What a visitor got: each test's name and whether they are in it. */
26
25
  export type Assignments = Record<string, boolean>;
27
- /**
28
- * Who is visiting: an id every assignment is computed from, plus the
29
- * assignments v7 stored (`active`, `inactiveDrawn`, `pct`, `exp`), which are honoured and
30
- * carried, never rewritten.
31
- */
26
+ /** Who is visiting: an id every assignment is computed from, and nothing else. */
32
27
  export interface Visitor {
33
- /**
34
- * 16 random bytes as 22 base64url characters, drawn once per visitor. `""`
35
- * for a visitor with no id of its own (one built from a cache key's
36
- * assignments), which is in only the tests `active` names.
37
- */
28
+ /** 16 random bytes as 22 base64url characters, drawn once per visitor. */
38
29
  id: string;
39
- /** Tests v7 put this visitor in. */
40
- active: string[];
41
- /** Tests v7 left this visitor out of. */
42
- inactiveDrawn: string[];
43
- /** The percentage each of v7's decisions was made at. */
44
- pct: Record<string, number>;
45
- /** v7's N-way decisions. Never read; carried as they are. */
46
- exp?: Record<string, string>;
47
30
  }
48
31
  /** What `readVisitor` answers. */
49
32
  export interface VisitorFromRequest {
50
33
  /** The request's visitor, or a new one when it had none. */
51
34
  visitor: Visitor;
52
35
  /**
53
- * The `Set-Cookie` line to send when the visitor had no id (a first visit,
54
- * or a v7 visitor getting theirs); `null` otherwise. Never send it from a
55
- * preview.
36
+ * The `Set-Cookie` line to send when the visitor had no id (a first
37
+ * visit); `null` otherwise. Never send it from a preview.
56
38
  */
57
39
  cookie: string | null;
58
40
  }
@@ -63,28 +45,21 @@ interface RequestWithHeaders {
63
45
  get(name: string): string | null;
64
46
  };
65
47
  }
66
- /** A new visitor: a fresh id and nothing else. */
48
+ /** A new visitor: a fresh id. */
67
49
  export declare function newVisitor(): Visitor;
68
50
  /**
69
- * A visitor out of its stored form (what `serializeVisitor` wrote, the value
70
- * of the `deco_segment` cookie). `null` when the text is missing, doesn't
71
- * read, or holds no id (a v7 value: `readVisitor` gives it one, keeping its
72
- * decisions). Never throws.
51
+ * A visitor out of its stored form (what `serializeVisitor` wrote: the value
52
+ * of the `deco_vid` cookie or of `x-deco-visitor`). `null` when the text is
53
+ * missing or isn't an id. Never throws.
73
54
  */
74
55
  export declare function parseVisitor(text: string | null | undefined): Visitor | null;
75
- /**
76
- * The visitor's stored form: v7's `btoa(encodeURIComponent(JSON.stringify(...)))`,
77
- * with a fixed key order and names sorted, so two equal visitors give
78
- * byte-equal values. Under 2KB: past it, v7's entries are dropped, first the
79
- * ones the id reproduces anyway.
80
- */
56
+ /** The visitor's stored form: its id. */
81
57
  export declare function serializeVisitor(visitor: Visitor): string;
82
58
  /**
83
- * The web helper: the visitor out of a request's `deco_segment` cookie, and
84
- * the `Set-Cookie` line to send back when it had no id (a first visit, or a
85
- * v7 visitor, whose decisions are kept). The cookie isn't `HttpOnly` (the
86
- * analytics script reads it, as in v7) and is `Secure` unless the request
87
- * came over plain http. Never throws.
59
+ * The web helper: the visitor out of a request's `deco_vid` cookie, and the
60
+ * `Set-Cookie` line to send back when it had none (a first visit). The cookie
61
+ * isn't `HttpOnly`, so a script on the page can read the id, and is `Secure`
62
+ * unless the request came over plain http. Never throws.
88
63
  */
89
64
  export declare function readVisitor(request: RequestWithHeaders): VisitorFromRequest;
90
65
  /**
@@ -93,14 +68,9 @@ export declare function readVisitor(request: RequestWithHeaders): VisitorFromReq
93
68
  * A visitor is in a test when their roll for it (a fixed number in [0, 100)
94
69
  * from the test's name and their id) is under its percentage, so 0 puts
95
70
  * nobody in, 100 everybody, and raising a percentage only adds people. A
96
- * fractional percentage is rounded. An assignment v7 stored is honoured while
97
- * the percentage it was made at holds (a missing or `-1` percentage, v7's
98
- * "any", included); once it moves, a v7 visitor in a test that grows stays
99
- * in and one out of a test that shrinks stays out. Without a visitor every
100
- * test is `false`. A visitor without an id (`""`, as a page built from a
101
- * cache key's assignments gives one) has no roll: it is in exactly the tests
102
- * its stored `active` and `pct` keep it in. Entries that aren't finite numbers are
103
- * left out. Pure; never throws.
71
+ * fractional percentage is rounded. Without a visitor, or with an id that
72
+ * isn't 22 base64url characters, every test is `false`. Entries that aren't
73
+ * finite numbers are left out. Pure; never throws.
104
74
  */
105
75
  export declare function assign(experiments: Experiments | null | undefined, visitor: Visitor | null | undefined): Assignments;
106
76
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"experiments.d.ts","sourceRoot":"","sources":["../../src/v8/experiments.ts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B,MAAM,CACpB,WAAW,EAAE,WAAW,GAAG,IAAI,GAAG,SAAS,EAC3C,OAAO,EAAE,OAAO,GAAG,IAAI,GAAG,SAAS,GAClC,WAAW,CAWb"}
@@ -14,164 +14,48 @@
14
14
  * storage in an app) and hands it to `cms.client({ visitor })`; the built-in
15
15
  * `split-traffic` calls `assign` with it.
16
16
  *
17
- * The stored form is v7's `deco_segment` (the same fields and encoding; names
18
- * sorted by code unit rather than v7's `localeCompare`) plus an `id`, so a
19
- * visitor carried over from v7 keeps the group v7 put them in and analytics
20
- * keeps reading the cookie it already reads. A visitor is written once, when
21
- * it has no id; v7's stored assignments are read and honoured, never rewritten.
17
+ * A visitor is only its id, stored as is in the `deco_vid` cookie and written
18
+ * once, on a first visit. v7's `deco_segment` is neither read nor written:
19
+ * its stored decisions aren't honoured, and a visitor who has only it gets a
20
+ * new id.
22
21
  */
23
22
  import { newId, roll } from "./bucketing.js";
24
- /** The visitor's stored form, v7's name for it. */
25
- const VISITOR_COOKIE = "deco_segment";
23
+ /** The visitor's cookie: the id, as is. */
24
+ const VISITOR_COOKIE = "deco_vid";
26
25
  /** One year: the id is the visitor, and it should outlive any single test. */
27
26
  const VISITOR_COOKIE_MAX_AGE = 60 * 60 * 24 * 365;
28
- /**
29
- * A cookie over this stays out of every request. An id plus 50 of v7's
30
- * decisions fits well under it; past it, `serializeVisitor` drops entries,
31
- * the ones the id reproduces first.
32
- */
33
- const COOKIE_BUDGET = 2048;
34
27
  const ID_RE = /^[A-Za-z0-9_-]{22}$/;
35
- /**
36
- * A record with no prototype, so a name such as `__proto__` is an ordinary
37
- * key: decided, written and read back like any other.
38
- */
39
- function record() {
40
- return Object.create(null);
41
- }
42
- function emptyStored() {
43
- return { active: [], inactiveDrawn: [], pct: record() };
44
- }
45
- function stringList(value) {
46
- if (!Array.isArray(value))
47
- return [];
48
- return value.filter((entry) => typeof entry === "string");
49
- }
50
- function pctRecord(value) {
51
- const out = record();
52
- if (typeof value !== "object" || value === null)
53
- return out;
54
- for (const [name, pct] of Object.entries(value)) {
55
- if (typeof pct === "number" && Number.isFinite(pct))
56
- out[name] = pct;
57
- }
58
- return out;
59
- }
60
- function expRecord(value) {
61
- if (typeof value !== "object" || value === null)
28
+ /** The id in a stored value, or `undefined`. Tolerates surrounding spaces and percent-encoding. */
29
+ function idOf(text) {
30
+ if (typeof text !== "string")
62
31
  return undefined;
63
- const out = record();
64
- for (const [name, variant] of Object.entries(value)) {
65
- if (typeof variant === "string")
66
- out[name] = variant;
67
- }
68
- return Object.keys(out).length > 0 ? out : undefined;
69
- }
70
- /**
71
- * A stored value, with or without an id; `null` when it doesn't read. Never
72
- * throws. The value may arrive percent-encoded (some cookie APIs encode what
73
- * they write; base64 never holds a `%`, so decoding first is always safe).
74
- * Entries of the wrong type are dropped, and an id that is not 22 base64url
75
- * characters is treated as absent.
76
- */
77
- function parseStored(text) {
78
- if (typeof text !== "string" || text === "")
79
- return null;
32
+ let value = text.trim();
80
33
  try {
81
- const parsed = JSON.parse(decodeURIComponent(atob(decodeURIComponent(text.trim()))));
82
- if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed))
83
- return null;
84
- const body = parsed;
85
- const stored = {
86
- active: stringList(body.active),
87
- inactiveDrawn: stringList(body.inactiveDrawn),
88
- pct: pctRecord(body.pct),
89
- };
90
- if (typeof body.id === "string" && ID_RE.test(body.id))
91
- stored.id = body.id;
92
- const exp = expRecord(body.exp);
93
- if (exp)
94
- stored.exp = exp;
95
- return stored;
34
+ value = decodeURIComponent(value);
96
35
  }
97
36
  catch {
98
- return null;
37
+ return undefined;
99
38
  }
39
+ return ID_RE.test(value) ? value : undefined;
100
40
  }
101
- /** A new visitor: a fresh id and nothing else. */
41
+ /** A new visitor: a fresh id. */
102
42
  export function newVisitor() {
103
- return { id: newId(), active: [], inactiveDrawn: [], pct: record() };
43
+ return { id: newId() };
104
44
  }
105
45
  /**
106
- * A visitor out of its stored form (what `serializeVisitor` wrote, the value
107
- * of the `deco_segment` cookie). `null` when the text is missing, doesn't
108
- * read, or holds no id (a v7 value: `readVisitor` gives it one, keeping its
109
- * decisions). Never throws.
46
+ * A visitor out of its stored form (what `serializeVisitor` wrote: the value
47
+ * of the `deco_vid` cookie or of `x-deco-visitor`). `null` when the text is
48
+ * missing or isn't an id. Never throws.
110
49
  */
111
50
  export function parseVisitor(text) {
112
- const stored = parseStored(text);
113
- return stored?.id === undefined ? null : stored;
51
+ const id = idOf(text);
52
+ return id === undefined ? null : { id };
114
53
  }
115
- /**
116
- * The visitor's stored form: v7's `btoa(encodeURIComponent(JSON.stringify(...)))`,
117
- * with a fixed key order and names sorted, so two equal visitors give
118
- * byte-equal values. Under 2KB: past it, v7's entries are dropped, first the
119
- * ones the id reproduces anyway.
120
- */
54
+ /** The visitor's stored form: its id. */
121
55
  export function serializeVisitor(visitor) {
122
- const active = [...visitor.active].sort();
123
- const inactiveDrawn = [...visitor.inactiveDrawn].sort();
124
- const dropped = new Set();
125
- const encode = () => {
126
- const stillActive = active.filter((name) => !dropped.has(name));
127
- const stillInactive = inactiveDrawn.filter((name) => !dropped.has(name));
128
- const pct = record();
129
- for (const name of Object.keys(visitor.pct).sort()) {
130
- // v7 kept a `pct` beside its N-way names too, and `exp` is carried
131
- // untouched, so their fingerprint is carried with it.
132
- const listed = stillActive.includes(name) ||
133
- stillInactive.includes(name) ||
134
- (visitor.exp !== undefined && Object.hasOwn(visitor.exp, name));
135
- if (listed)
136
- pct[name] = visitor.pct[name];
137
- }
138
- const body = {
139
- active: stillActive,
140
- inactiveDrawn: stillInactive,
141
- pct,
142
- };
143
- if (visitor.id !== undefined)
144
- body.id = visitor.id;
145
- if (visitor.exp !== undefined)
146
- body.exp = visitor.exp;
147
- return btoa(encodeURIComponent(JSON.stringify(body)));
148
- };
149
- let value = encode();
150
- if (value.length <= COOKIE_BUDGET)
151
- return value;
152
- // Over budget. A dropped entry is decided by the roll from then on, which
153
- // keeps the decision only when the stored one already agrees with the roll.
154
- // So drop those first, and the others only if the value is still too big.
155
- const reproducible = (name) => {
156
- const pct = visitor.pct[name];
157
- if (typeof pct !== "number")
158
- return false;
159
- return active.includes(name) === roll(name, visitor.id) < pct;
160
- };
161
- for (const name of [
162
- ...inactiveDrawn.filter(reproducible),
163
- ...active.filter(reproducible),
164
- ...inactiveDrawn.filter((name) => !reproducible(name)),
165
- ...active.filter((name) => !reproducible(name)),
166
- ]) {
167
- if (value.length <= COOKIE_BUDGET)
168
- break;
169
- dropped.add(name);
170
- value = encode();
171
- }
172
- return value;
56
+ return visitor.id;
173
57
  }
174
- /** The raw `deco_segment` value out of a `Cookie` header. */
58
+ /** The raw `deco_vid` value out of a `Cookie` header. */
175
59
  function readCookie(cookies) {
176
60
  if (!cookies)
177
61
  return undefined;
@@ -197,11 +81,10 @@ function isPlainHttp(url) {
197
81
  }
198
82
  }
199
83
  /**
200
- * The web helper: the visitor out of a request's `deco_segment` cookie, and
201
- * the `Set-Cookie` line to send back when it had no id (a first visit, or a
202
- * v7 visitor, whose decisions are kept). The cookie isn't `HttpOnly` (the
203
- * analytics script reads it, as in v7) and is `Secure` unless the request
204
- * came over plain http. Never throws.
84
+ * The web helper: the visitor out of a request's `deco_vid` cookie, and the
85
+ * `Set-Cookie` line to send back when it had none (a first visit). The cookie
86
+ * isn't `HttpOnly`, so a script on the page can read the id, and is `Secure`
87
+ * unless the request came over plain http. Never throws.
205
88
  */
206
89
  export function readVisitor(request) {
207
90
  let header = null;
@@ -211,10 +94,10 @@ export function readVisitor(request) {
211
94
  catch {
212
95
  header = null;
213
96
  }
214
- const stored = parseStored(readCookie(header));
215
- if (stored?.id !== undefined)
97
+ const stored = parseVisitor(readCookie(header));
98
+ if (stored !== null)
216
99
  return { visitor: stored, cookie: null };
217
- const visitor = { ...(stored ?? emptyStored()), id: newId() };
100
+ const visitor = newVisitor();
218
101
  const parts = [
219
102
  `${VISITOR_COOKIE}=${serializeVisitor(visitor)}`,
220
103
  "Path=/",
@@ -228,65 +111,28 @@ export function readVisitor(request) {
228
111
  function roundPct(allocation) {
229
112
  return Math.round(Math.min(100, Math.max(0, allocation)));
230
113
  }
231
- /**
232
- * A v7 decision after the percentage moved: raising a percentage never
233
- * removes anyone v7 put in, and lowering it never adds anyone v7 left out.
234
- * Otherwise the roll decides, as for any visitor.
235
- */
236
- function keptFromV7(stored, from, to) {
237
- if (to === from)
238
- return stored;
239
- if (stored && to > from)
240
- return true;
241
- if (!stored && to < from)
242
- return false;
243
- return undefined;
244
- }
245
114
  /**
246
115
  * This visitor's answer for every test: `true` when they are in it.
247
116
  *
248
117
  * A visitor is in a test when their roll for it (a fixed number in [0, 100)
249
118
  * from the test's name and their id) is under its percentage, so 0 puts
250
119
  * nobody in, 100 everybody, and raising a percentage only adds people. A
251
- * fractional percentage is rounded. An assignment v7 stored is honoured while
252
- * the percentage it was made at holds (a missing or `-1` percentage, v7's
253
- * "any", included); once it moves, a v7 visitor in a test that grows stays
254
- * in and one out of a test that shrinks stays out. Without a visitor every
255
- * test is `false`. A visitor without an id (`""`, as a page built from a
256
- * cache key's assignments gives one) has no roll: it is in exactly the tests
257
- * its stored `active` and `pct` keep it in. Entries that aren't finite numbers are
258
- * left out. Pure; never throws.
120
+ * fractional percentage is rounded. Without a visitor, or with an id that
121
+ * isn't 22 base64url characters, every test is `false`. Entries that aren't
122
+ * finite numbers are left out. Pure; never throws.
259
123
  */
260
124
  export function assign(experiments, visitor) {
261
- const assignments = record();
125
+ const assignments = Object.create(null);
262
126
  if (typeof experiments !== "object" || experiments === null)
263
127
  return assignments;
264
128
  const id = visitor !== null && typeof visitor === "object" ? visitor.id : undefined;
265
129
  const known = typeof id === "string" && ID_RE.test(id);
266
- const v = visitor !== null && typeof visitor === "object" ? visitor : {};
267
130
  for (const name of Object.keys(experiments).sort()) {
268
131
  const allocation = experiments[name];
269
132
  if (typeof allocation !== "number" || !Number.isFinite(allocation))
270
133
  continue;
271
- const pct = roundPct(allocation);
272
- const stored = list(v.active).includes(name)
273
- ? true
274
- : list(v.inactiveDrawn).includes(name)
275
- ? false
276
- : undefined;
277
- // v7 wrote `round(traffic * 100)` here, and its own reader treated a
278
- // missing or negative entry as "matches anything".
279
- const raw = isRecord(v.pct) && Object.hasOwn(v.pct, name) ? v.pct[name] : undefined;
280
- const from = typeof raw === "number" && Number.isFinite(raw) && raw >= 0 ? roundPct(raw) : pct;
281
- const kept = stored === undefined ? undefined : keptFromV7(stored, from, pct);
282
- assignments[name] = kept ?? (known && roll(name, id) < pct);
134
+ assignments[name] = known && roll(name, id) < roundPct(allocation);
283
135
  }
284
136
  return assignments;
285
137
  }
286
- function list(value) {
287
- return Array.isArray(value) ? value : [];
288
- }
289
- function isRecord(value) {
290
- return typeof value === "object" && value !== null;
291
- }
292
138
  //# sourceMappingURL=experiments.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"experiments.js","sourceRoot":"","sources":["../../src/v8/experiments.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAgD7C,mDAAmD;AACnD,MAAM,cAAc,GAAG,cAAc,CAAC;AAEtC,8EAA8E;AAC9E,MAAM,sBAAsB,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,GAAG,CAAC;AAElD;;;;GAIG;AACH,MAAM,aAAa,GAAG,IAAI,CAAC;AAE3B,MAAM,KAAK,GAAG,qBAAqB,CAAC;AAKpC;;;GAGG;AACH,SAAS,MAAM;IACb,OAAO,MAAM,CAAC,MAAM,CAAC,IAAI,CAAsB,CAAC;AAClD,CAAC;AAED,SAAS,WAAW;IAClB,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,aAAa,EAAE,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,EAAE,CAAC;AAC1D,CAAC;AAED,SAAS,UAAU,CAAC,KAAc;IAChC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IACrC,OAAO,KAAK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2C,EAC3C,OAAmC;IAEnC,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAgB,CAAC;IACvD,IAAI,OAAO,WAAW,KAAK,QAAQ,IAAI,WAAW,KAAK,IAAI;QAAE,OAAO,WAAW,CAAC;IAChF,MAAM,EAAE,GAAG,OAAO,KAAK,IAAI,IAAI,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;IACpF,MAAM,KAAK,GAAG,OAAO,EAAE,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACvD,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC;QACnD,MAAM,UAAU,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC;QACrC,IAAI,OAAO,UAAU,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC;YAAE,SAAS;QAC7E,WAAW,CAAC,IAAI,CAAC,GAAG,KAAK,IAAI,IAAI,CAAC,IAAI,EAAE,EAAY,CAAC,GAAG,QAAQ,CAAC,UAAU,CAAC,CAAC;IAC/E,CAAC;IACD,OAAO,WAAW,CAAC;AACrB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decocms/blocks",
3
- "version": "8.18.1",
3
+ "version": "8.19.0",
4
4
  "type": "module",
5
5
  "engines": {
6
6
  "node": ">=24"
@@ -80,7 +80,7 @@ or curl-able.
80
80
  ## 5. Cache (→ **deco-storefront-caching**)
81
81
 
82
82
  - [ ] 🔴 **A signed-in shopper never gets a stored anonymous page**; nothing per-user is stored.
83
- - [ ] 🟡 Anonymous pages set no cookie except the first-visit `deco_segment`, and the second request is `X-Cache: HIT`.
83
+ - [ ] 🟡 Anonymous pages set no cookie except the first-visit `deco_vid`, and the second request is `X-Cache: HIT`.
84
84
  - [ ] 🟡 The cache key drops the paid-media parameters your traffic carries.
85
85
  - [ ] 🟡 A failed loader marks the page degraded (`x-deco-degraded`) instead of caching "not found".
86
86
 
@@ -137,7 +137,7 @@ navigation.
137
137
  |---|---|---|
138
138
  | M1 | Browser heap stays flat over 10 SPA navigations | DevTools Memory |
139
139
  | M2 | Minicart open/close 10× leaves the heap flat | heap snapshots before and after |
140
- | M3 | Anonymous pages send no `Set-Cookie` except the first-visit `deco_segment` | `curl -sI` without cookies |
140
+ | M3 | Anonymous pages send no `Set-Cookie` except the first-visit `deco_vid` | `curl -sI` without cookies |
141
141
  | M4 | The second anonymous request is a cache hit | `X-Cache: HIT` from the site's page cache (**deco-storefront-caching**) |
142
142
  | M5 | Lazy sections load their chunk only when needed | network panel while scrolling |
143
143
 
@@ -169,8 +169,8 @@ if [ -n "$CAND" ]; then
169
169
 
170
170
  # the first-visit visitor cookie, the split cookie and Cloudflare's own are expected
171
171
  h=$(cc -o /dev/null -D - "$CAND/" | tr -d '\r')
172
- sc=$(echo "$h" | grep -i '^set-cookie:' | grep -viE '^set-cookie: *(deco_segment|_deco_bucket|__cf_bm|_cfuvid|cf_clearance)=')
173
- [ -z "$sc" ] && pass "anonymous / sets no cookie besides deco_segment" ||
172
+ sc=$(echo "$h" | grep -i '^set-cookie:' | grep -viE '^set-cookie: *(deco_vid|_deco_bucket|__cf_bm|_cfuvid|cf_clearance)=')
173
+ [ -z "$sc" ] && pass "anonymous / sets no cookie besides deco_vid" ||
174
174
  { warn "anonymous / sets other cookies: a page cache must not store it"; echo "$sc" | cut -c1-90 | show; }
175
175
  echo "$h" | grep -qi '^x-robots-tag:.*noindex' && fail "/ sends X-Robots-Tag noindex" || pass "/ has no X-Robots-Tag noindex"
176
176
  xc=$(cc -o /dev/null -D - "$CAND/" | tr -d '\r' | grep -iE '^(x-cache|cf-cache-status):' | tr '\n' ' ')
@@ -31,7 +31,7 @@ example disagree, the example wins.
31
31
  ## The shape of a request
32
32
 
33
33
  1. `proxy.ts` decides once: the version (a Studio link's draft or old
34
- release, on an allowed host), the visitor (`deco_segment` cookie) and every
34
+ release, on an allowed host), the visitor (`deco_vid` cookie) and every
35
35
  test and campaign on or off.
36
36
  2. A published CMS page is rewritten to `/_assignments/<segment>/<path>`. The
37
37
  page reads no request, so Next caches it (ISR).
@@ -10,7 +10,7 @@ fresh.
10
10
  | Step | Function (`@decocms/nextjs/proxy`) | Result |
11
11
  |---|---|---|
12
12
  | Version | `decideDraft(proxyCms, request)` | A Studio link's draft or old release on an allowed host, its preview moment (`__at`) and switched tests and campaigns (`__test`, `__campaign`), the cookie to set |
13
- | Visitor | `decideVisitor(request, draft)` | The `deco_segment` cookie, or a new visitor. Its cookie is sent on a first visit only, never when the request renders a draft or an old release |
13
+ | Visitor | `decideVisitor(request, draft)` | The `deco_vid` cookie, or a new visitor. Its cookie is sent on a first visit only, never when the request renders a draft or an old release |
14
14
  | Tests and campaigns | `decideAssignments(proxyCms, draft, visitor)` | Each test of the saved `experiments` block on or off, each campaign of the saved `campaigns` block running or not. Missing blocks give none, never an error |
15
15
 
16
16
  It forwards them to the page on request headers, always removing copies sent
@@ -37,7 +37,7 @@ the spec follows a TTL change instead of failing on it.
37
37
  | Returning visitor | A cart or checkout cookie alone does not make the page private |
38
38
  | Tracking params | `utm_*`, `gclid`, `fbclid`: 200, no `location`, same `x-cache-segment`, HIT once warm |
39
39
  | No poisoning | A value sent in `gclid` never appears in the clean URL's HTML |
40
- | No cookies on cached pages | A public page answers no `set-cookie` except `deco_segment` on a first visit |
40
+ | No cookies on cached pages | A public page answers no `set-cookie` except `deco_vid` on a first visit |
41
41
  | Payload | Raw HTML under a budget; a marker of heavy data (a schema.org type you trim) under a count |
42
42
  | Assets | A fingerprinted asset is `public, max-age=31536000, immutable` |
43
43
  | CLS | Home and a listing under 0.1 on desktop and mobile |
@@ -27,7 +27,7 @@ done
27
27
  ```
28
28
 
29
29
  Expect on the second request: `x-cache: HIT`, the profile you meant, `x-cache-version:
30
- <build>.<revision>`, `vary: Accept-Encoding`, no `set-cookie` other than `deco_segment` on a first
30
+ <build>.<revision>`, `vary: Accept-Encoding`, no `set-cookie` other than `deco_vid` on a first
31
31
  visit (and the cookies in your `SAFE_COOKIES`, if a render set one). A `BYPASS` comes with `x-cache-reason`; `egress-traps.md` maps each reason to a cause.
32
32
 
33
33
  After a deploy or a publish, `x-cache-version` changes and the first request is a `MISS` again.
@@ -41,7 +41,7 @@ You do not write these. Do not add a second copy of them in `pageCache`.
41
41
  | Previews | Always render. Answer `Cache-Control: max-age=0, no-cache, must-revalidate`, `Vary: Cookie`, `noindex`, and `CDN-Cache-Control: no-store`. |
42
42
  | `Authorization` | The page renders and answers `private, no-cache, no-store, must-revalidate`, whatever the app set. |
43
43
  | Default CDN header | Any response without `CDN-Cache-Control` leaves with `CDN-Cache-Control: no-store`. |
44
- | Visitor cookie | `deco_segment` is set on a first visit only, and appended after `pageCache` answers. A stored copy never carries it; a visitor served from the cache still gets theirs. |
44
+ | Visitor cookie | `deco_vid` is set on a first visit only, and appended after `pageCache` answers. A stored copy never carries it; a visitor served from the cache still gets theirs. |
45
45
  | `Set-Cookie` | One header per cookie (name + Domain + Path). |
46
46
  | Fingerprinted assets | `public, max-age=31536000, immutable`, `Vary: Accept-Encoding`. Also under `/fonts/`. |
47
47
  | CMS redirects | Answered before your `routes` and before `pageCache`. See `egress-traps.md`. |
@@ -38,7 +38,7 @@ No option turns these off.
38
38
  release.
39
39
  - **The CMS redirects**, for `GET`/`HEAD` page requests, before anything else. Server-function
40
40
  calls, assets and `/_build` are not redirected.
41
- - **The visitor and the tests.** It reads the visitor (`deco_segment` cookie, or a new one) and
41
+ - **The visitor and the tests.** It reads the visitor (`deco_vid` cookie, or a new one) and
42
42
  decides each test and campaign once, then hands them to the app on request headers it strips
43
43
  from incoming requests (below). The visitor cookie goes out on a first visit only, and never on a request that renders a draft
44
44
  or an old release.
@@ -4,7 +4,7 @@ From the site migrations; the sites and what the commit hashes refer to are list
4
4
 
5
5
  - **`transpilePackages: ['@decocms/blocks']`** only while the installed package's `exports` point at `.ts` source (see `manual-steps.md`, step 1); `8.1.0` ships `dist/` and needs none. A linked local checkout ships `dist/` and hides the difference; so does every parity run made against it.
6
6
  - **Drafts on Pages Router SSG pages** (no proxy available, as on FastStore; `@decocms/nextjs` is for the App Router): Next 16's compiled pages runtimes inline `tryGetPreviewData`, so a `require.cache` patch never runs. See `faststore.md`.
7
- - **Drafts come from `@decocms/nextjs`.** Don't hand-write the draft proxy, the draft route or the Studio bridge. In `proxy.ts`: 404 direct hits on the internal route (`isDraftRoutePath`), `decideDraft(proxyCms, request)`, then `decideVisitor(request, draft)` and `decideAssignments(proxyCms, draft, visitor)`, then `rewriteToDraftRoute(request, draft, visitor, assignments)` or `NextResponse.next({ request: { headers: assignmentsRequestHeaders(visitorRequestHeaders(draftRequestHeaders(request, draft), visitor), assignments) } })`, and `applyVisitor(applyDraft(response, draft), visitor)` for the cookies and the preview headers (`max-age=0, no-cache, must-revalidate`, noindex) (`@decocms/nextjs/proxy`). The visitor (the `deco_segment` cookie, v7's format plus an id) is what the saved `experiments` block decides A/B tests for; the proxy decides each test and campaign once (`decideAssignments`, forwarded with `assignmentsRequestHeaders`), `bindDraft` binds what it decided and `contentClient` builds `cms.client({ version, experiments, campaigns })` (`draftProxy` does all of it). On the dynamic `src/app/%5Fdraft/[[...path]]` route and in a layout that reads content: `bindDraft(cms, { searchParams })` and `contentClient(cms)` (`@decocms/nextjs/server`), with `<DraftPreviewIndicator />` on the page. A cached page can't read a request, which is why drafted requests go to that dynamic route; published CMS pages are ISR with `export const revalidate = 600` (Next renders a stored page again in the background on the first request after it is 10 minutes old, so a cached page is about that stale, which is accepted), never `force-static`, on the assignments route where the proxy decides the tests and campaigns and the page renders that (`await assignedClient(cms, segment)`). The package's README has the files in full.
7
+ - **Drafts come from `@decocms/nextjs`.** Don't hand-write the draft proxy, the draft route or the Studio bridge. In `proxy.ts`: 404 direct hits on the internal route (`isDraftRoutePath`), `decideDraft(proxyCms, request)`, then `decideVisitor(request, draft)` and `decideAssignments(proxyCms, draft, visitor)`, then `rewriteToDraftRoute(request, draft, visitor, assignments)` or `NextResponse.next({ request: { headers: assignmentsRequestHeaders(visitorRequestHeaders(draftRequestHeaders(request, draft), visitor), assignments) } })`, and `applyVisitor(applyDraft(response, draft), visitor)` for the cookies and the preview headers (`max-age=0, no-cache, must-revalidate`, noindex) (`@decocms/nextjs/proxy`). The visitor (the `deco_vid` cookie, holding only its id) is what the saved `experiments` block decides A/B tests for; the proxy decides each test and campaign once (`decideAssignments`, forwarded with `assignmentsRequestHeaders`), `bindDraft` binds what it decided and `contentClient` builds `cms.client({ version, experiments, campaigns })` (`draftProxy` does all of it). On the dynamic `src/app/%5Fdraft/[[...path]]` route and in a layout that reads content: `bindDraft(cms, { searchParams })` and `contentClient(cms)` (`@decocms/nextjs/server`), with `<DraftPreviewIndicator />` on the page. A cached page can't read a request, which is why drafted requests go to that dynamic route; published CMS pages are ISR with `export const revalidate = 600` (Next renders a stored page again in the background on the first request after it is 10 minutes old, so a cached page is about that stale, which is accepted), never `force-static`, on the assignments route where the proxy decides the tests and campaigns and the page renders that (`await assignedClient(cms, segment)`). The package's README has the files in full.
8
8
  - **Same CMS options in the proxy and the pages.** Keep `createCMS`'s options in one module both handles import (`cmsConfig`, with `site`): the proxy decides on the hosts Studio writes into the release metadata, and `bindDraft` checks again against the same ones.
9
9
  - **Keep the block map out of the proxy.** The proxy only touches the CMS for a request with `?__draft=` or the draft cookie, but it is bundled whole. Give it its own `createCMS` handle with `blocks: {}` and the same options as the app's (one shared options module, since a second call with other options keeps the first): the draft check reads only the `CMS` settings block, so the block map, its section loaders and what they import (a GraphQL engine) leave the proxy bundle. Measured on one store: 2.2 MB to 1.5 MB, traced files 3,245 to 364. The content module still lands there.
10
10
  - **`next start -H 127.0.0.1`** makes Next treat the draft rewrite as an external URL, and the request comes back through the proxy. Bind the default host in local checks; production hostnames aren't affected.
@@ -53,7 +53,7 @@ export function reportTestsAndDates(root: string, report: Report): void {
53
53
  report.manual.push({
54
54
  step: "content",
55
55
  subject: "A/B tests",
56
- message: `v7's random matchers (in ${quoted([...tests].map((n) => files[n] ?? n))}) weren't moved: put each test in the saved block experiments (type split-traffic) under its saved-block name, so visitors keep their groups and results carry over, and point its rules at { "__resolveType": "experiment", "name": … } (Run an A/B test, ${RUN_AN_AB_TEST})`,
56
+ message: `v7's random matchers (in ${quoted([...tests].map((n) => files[n] ?? n))}) weren't moved: put each test in the saved block experiments (type split-traffic) under its saved-block name, so its results carry over (visitors are drawn again: v8 neither reads nor writes v7's deco_segment cookie, and @decocms/compat-v7 has no random matcher), and point its rules at { "__resolveType": "experiment", "name": … } (Run an A/B test, ${RUN_AN_AB_TEST})`,
57
57
  });
58
58
  reportAssignment(root, report);
59
59
  }
@@ -1,12 +1,11 @@
1
1
  /**
2
2
  * v7's website matchers in the block map. `@decocms/compat-v7/matchers` has
3
3
  * each one with v7's results, taking the request explicitly; the binding's
4
- * compat subpath gives that request (`matcherContext()`, with one A/B
5
- * decision list per request). The block map registers each matcher the
6
- * content uses under its v7 name. v7's random matcher isn't one of them, so
7
- * the binding is the only writer of the visitor's `deco_segment`: its tests
8
- * move by hand into the saved block `experiments`, as do date windows into
9
- * `campaigns` (the content step reports both, ./experiments.ts).
4
+ * compat subpath gives that request (`matcherContext()`). The block map
5
+ * registers each matcher the content uses under its v7 name. v7's random
6
+ * matcher isn't one of them (compat-v7 has none): its tests move by hand into
7
+ * the saved block `experiments`, read by the `experiment` rule, as do date
8
+ * windows into `campaigns` (the content step reports both, ./experiments.ts).
10
9
  */
11
10
  import type { Framework } from "./framework";
12
11
 
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: deco-variants
3
- description: "Variants on @decocms/blocks 8: the built-in multivariate block ({ rule, value } with lazy values, first true rule wins, later rules never run), the built-in rules always, never, experiment and campaign, A/B tests as the saved block experiments (split-traffic: a percentage per test, a sticky visitor id in the deco_segment cookie, @decocms/blocks/experiments) and scheduled content as the saved block campaigns (calendar), v7's matchers from @decocms/compat-v7/matchers (device, cookie, host, pathname, queryString, location, multi, sticky random), custom rules in the block map, previewing a variant, a test or a moment from a Studio draft link (__variant, __test, __campaign, __at), and keeping variant pages cacheable (assignmentsKey, one cache entry per set of assignments). Load it for A/B tests, scheduled or segmented content, a variant that never shows or always shows, matcher bugs after a v7 migration, or a variant page that misses the cache."
3
+ description: "Variants on @decocms/blocks 8: the built-in multivariate block ({ rule, value } with lazy values, first true rule wins, later rules never run), the built-in rules always, never, experiment and campaign, A/B tests as the saved block experiments (split-traffic: a percentage per test, a sticky visitor id in the deco_vid cookie, @decocms/blocks/experiments) and scheduled content as the saved block campaigns (calendar), v7's matchers from @decocms/compat-v7/matchers (device, cookie, host, pathname, queryString, location, multi; v7's random moves to experiments), custom rules in the block map, previewing a variant, a test or a moment from a Studio draft link (__variant, __test, __campaign, __at), and keeping variant pages cacheable (assignmentsKey, one cache entry per set of assignments). Load it for A/B tests, scheduled or segmented content, a variant that never shows or always shows, matcher bugs after a v7 migration, or a variant page that misses the cache."
4
4
  ---
5
5
 
6
6
  # Variants on @decocms/blocks 8
@@ -17,7 +17,7 @@ Code is in `packages/blocks/src/v8/builtins/` (`multivariate.ts`, `matchers.ts`,
17
17
  |---|---|
18
18
  | [`references/multivariate.md`](./references/multivariate.md) | Writing or reading variant JSON; a variant never shows, always shows, or a slot is empty; `deco check` says "a variant's value must be a lazy block"; v7 `website/flags/multivariate*.ts` content |
19
19
  | [`references/experiments-and-campaigns.md`](./references/experiments-and-campaigns.md) | Setting up an A/B test or a scheduled promotion; ramping a test; a campaign that never starts; `deco check` says "no test" or "no campaign"; tagging analytics with the test arm |
20
- | [`references/v7-matchers.md`](./references/v7-matchers.md) | Content migrated from v7 uses `website/matchers/device.ts`, `cookie.ts`, `location.ts`, `random.ts` and others; `UNKNOWN_BLOCK` on a v7 matcher; wiring `matcherContext` and the `deco_segment` cookie |
20
+ | [`references/v7-matchers.md`](./references/v7-matchers.md) | Content migrated from v7 uses `website/matchers/device.ts`, `cookie.ts`, `location.ts`, `random.ts` and others; `UNKNOWN_BLOCK` on a v7 matcher; wiring `matcherContext`; moving a v7 random test to `experiments` |
21
21
  | [`references/custom-matchers.md`](./references/custom-matchers.md) | Writing a site's own rule; a rule that needs the request, the visitor or the date; a rule that does not appear in Studio's rule picker |
22
22
  | [`references/draft-preview.md`](./references/draft-preview.md) | Previewing one variant, a test switched on, or a future date from a Studio link; a preview link that shows the saved content instead |
23
23
  | [`references/caching-variants.md`](./references/caching-variants.md) | A page with variants misses the cache or shows the wrong variant from cache; deciding whether a rule is safe behind a page cache; purging variant pages |
@@ -43,7 +43,7 @@ With the saved block `experiments` set to `{ "__resolveType": "split-traffic", "
43
43
  - Order is the logic. Put narrow rules first and `always` last. With no `always`, a visitor that matches no rule gets `undefined` for that slot.
44
44
  - Prefer `experiment` and `campaign` over request-reading rules. The binding decides them once at the edge and the page cache keys on them. A rule that reads a cookie, a header or the location changes the page by something the cache key does not hold (see [`caching-variants.md`](./references/caching-variants.md)).
45
45
  - Keep a test's name stable. A visitor's side is a hash of the test name and their id, so renaming a test re-draws everyone.
46
- - Run one A/B system per site. The saved block `experiments` and v7's sticky `random` both write `deco_segment`.
46
+ - A/B tests live only in the saved block `experiments`. v7's `random` has no port: move each v7 random test there, with `experiment` rules.
47
47
 
48
48
  ## Reading results
49
49
 
@@ -8,7 +8,7 @@ This page covers the variant side of caching. The `deco-storefront-caching` skil
8
8
 
9
9
  On every page and server-function request, before any cache lookup, the binding:
10
10
 
11
- 1. reads the visitor (`readVisitor`: the `deco_segment` cookie, or a new visitor with a fresh id);
11
+ 1. reads the visitor (`readVisitor`: the `deco_vid` cookie, or a new visitor with a fresh id);
12
12
  2. decides every test of `experiments` and every campaign of `campaigns` for that visitor and that moment;
13
13
  3. hands those **assignments** to the cache and to the page, which renders exactly them and decides nothing again.
14
14
 
@@ -28,8 +28,6 @@ On v7, a cached page decided the variant for every new visitor who hit it until
28
28
 
29
29
  v8's `experiment` rule does not have this problem. Each new visitor gets an id and a roll at the edge before the cache lookup, and the lookup uses their assignments. Two new visitors on different sides read different entries.
30
30
 
31
- v7's sticky `random` from `@decocms/compat-v7` still decides during render. A response that sets `deco_segment` must never be stored, so a visitor's first page of a random test is always rendered fresh. Then `cohortSegment(request)` puts their group in the key. Moving the test into `experiments` removes both costs.
32
-
33
31
  ## Rule by rule
34
32
 
35
33
  | Rule | In the key? | What to do |
@@ -41,7 +39,6 @@ v7's sticky `random` from `@decocms/compat-v7` still decides during render. A re
41
39
  | `queryString` (compat) | Depends on your key | The example drops tracking parameters (`utm_*` and the like) from the key, so a rule on them shows one visitor's variant to another |
42
40
  | `host` (compat) | Depends on your key | The example keys on the full URL, host included. Safe only when your key does too |
43
41
  | `cookie`, `location` (compat) | No | Add the value to the key, skip caching for those pages, or personalize in the browser |
44
- | `random` (compat) | Through `cohortSegment` | See above; prefer `experiments` |
45
42
  | A custom rule that reads the request | No | Same as `cookie` |
46
43
  | A custom rule on `currentClient().date` | No | The page keeps the variant of the moment it was cached until it expires. Use a campaign instead |
47
44
 
@@ -56,7 +53,7 @@ Signed-in, cart and account content belongs in option 3 or uncached. Never put a
56
53
  ## Checklist: a variant page misses the cache or shows the wrong arm
57
54
 
58
55
  1. **Is it a preview?** A `?__draft=` link or the draft cookie never reaches `pageCache` (see [`draft-preview.md`](./draft-preview.md)).
59
- 2. **Does the response set a cookie?** The worker-entry example never stores a response that sets one (other than `_deco_bucket`). The worker adds the visitor's own cookie after `pageCache`, so that one does not count. v7's `deco_segment` writer from compat does count.
56
+ 2. **Does the response set a cookie?** The worker-entry example never stores a response that sets one (other than `_deco_bucket`). The worker adds the visitor's own cookie after `pageCache`, so that one does not count.
60
57
  3. **Does a rule read the request?** List the rules on the page (follow saved rule blocks too) and check each against the table above.
61
58
  4. **How many tests are running?** `2^n` entries per page split the hits.
62
59
  5. **Is the wrong arm stable for one URL?** A rule reads something that is not in the key. Compare the same URL with two different values of the suspect cookie or header.
@@ -26,7 +26,7 @@ Put the control last, under `always`.
26
26
 
27
27
  ### How a visitor is assigned
28
28
 
29
- - A visitor has an id: 16 random bytes as 22 base64url characters, stored in the `deco_segment` cookie for a year. The cookie is not `HttpOnly`, so an analytics script can read it.
29
+ - A visitor has an id: 16 random bytes as 22 base64url characters, stored in the `deco_vid` cookie for a year. The cookie is not `HttpOnly`, so an analytics script can read it.
30
30
  - For each test, the visitor's roll is a hash of `<test name>:<id>` (MurmurHash3, in `bucketing.ts`), a fixed number from 0 to 99.99. The visitor is in the test when the roll is below the percentage.
31
31
  - Nothing per test is stored. One id serves every test, a new test needs no new state, and two tests are independent of each other.
32
32
  - The decision is the same on a server, in a browser and in an app: `assign(experiments, visitor)` is a pure function.
@@ -56,7 +56,7 @@ This gives a safe launch path:
56
56
 
57
57
  ### Visitors from v7
58
58
 
59
- The cookie keeps v7's name and format. A v7 visitor gets an id on their next visit, and v7's stored decisions are honoured while the percentage they were made at holds. After it moves, a v7 visitor in a test that grows stays in, and one out of a test that shrinks stays out. To keep a v7 random test's groups, move it into `experiments` under the same name (the `deco-v7-to-v8-migration` skill reports each one). Do not also register v7's `random` matcher: two writers of `deco_segment` undo each other.
59
+ v8 neither reads nor writes v7's `deco_segment` cookie, so its stored decisions are not honoured: a visitor with only that cookie is a first visit, with a new id, and is drawn again. Move each v7 random test into `experiments` under the same name, so its results keep their name (the `deco-v7-to-v8-migration` skill reports each one); `@decocms/compat-v7` has no `random` to register.
60
60
 
61
61
  ## Campaigns
62
62
 
@@ -99,6 +99,6 @@ v8 decides who sees what. It does not record conversions, and its analytics modu
99
99
 
100
100
  - On TanStack, `requestAssignments()` from `@decocms/tanstack/server` returns each test on or off for the request, as the worker decided it. Pass the arms the page rendered to your analytics events.
101
101
  - On any binding, the page's own client gives the same answer: `const [tests] = await client.resolve("experiments")` gives each test's name and `true` or `false`, never a percentage.
102
- - In the browser, the `deco_segment` cookie holds the visitor; `parseVisitor` and `assign` from `@decocms/blocks/experiments` give the same answer as the server for a given `experiments` block.
102
+ - In the browser, the `deco_vid` cookie holds the visitor; `parseVisitor` and `assign` from `@decocms/blocks/experiments` give the same answer as the server for a given `experiments` block.
103
103
 
104
104
  Count users, not sessions: the id is per visitor. Then use the `ab-testing` skill in decocms/skills to plan the sample size, check the sample ratio and read significance.
@@ -37,7 +37,7 @@ What follows from that:
37
37
 
38
38
  - **Order is the logic.** Narrow rules first, `always` last. A `never` rule is how the editor hides a variant.
39
39
  - **No fallback, no value.** Without an `always` at the end, a visitor that matches nothing gets `undefined`. Sometimes that is the goal ("desktop only"), often it is a bug.
40
- - **Later rules have no side effects.** A rule after the winner never runs. With v7's sticky `random`, that means no draw and no cookie for that test on this request, as in v7.
40
+ - **Later rules have no side effects.** A rule after the winner never runs.
41
41
  - **Rules run in sequence, not in parallel.** Each async rule waits for the one before it. A slow rule early in the list delays the whole slot. The built-in `experiment` and `campaign` read a saved block once per client, however many rules ask.
42
42
  - **Results are memoized per request.** The resolver keeps one result per block function and inputs for the life of a client, so two identical rules on one page run once. Treat results as read-only.
43
43
  - **A rule that throws fails the block** with `BLOCK_FAILED`. v7's matchers from `@decocms/compat-v7/matchers` catch their own errors and answer `false`, as v7 did. A site's own rule should do the same if a failure should mean "no match" (see [`custom-matchers.md`](./custom-matchers.md)).
@@ -15,7 +15,6 @@ Use them for content migrated from v7. For new A/B tests and dates, prefer the b
15
15
  | `queryString` | `website/matchers/queryString.ts` | Query parameters, with `Exists`, `Equals`, `Greater`, `GreaterOrEquals`, `Lesser`, `LesserOrEquals`, `Includes` |
16
16
  | `location` | `website/matchers/location.ts` | Country, region, city or coordinates, included or excluded. Reads the `cf-*` headers, then the Workers `request.cf`, then the `__cf_geo_*` cookies |
17
17
  | `multi` | `website/matchers/multi.ts` | `op: "and"` or `"or"` over its `matchers`. No rules matches everyone |
18
- | `random` | `website/matchers/random.ts` | v7's sticky random: a `traffic` share (0 to 1, default 0.5) keyed on a `cohort` |
19
18
  | `environment` | `website/matchers/environment.ts` | Always throws: it read the process environment, which no v8 package does. Register your own rule under that name |
20
19
 
21
20
  `always` and `never` are v8 built-ins, and v7's names for them are aliases (see [`multivariate.md`](./multivariate.md)). v7's date matcher became the `campaign` rule and the saved block `campaigns`.
@@ -29,42 +28,31 @@ Every matcher except `multi` and `environment` takes the request as a second arg
29
28
  ```ts
30
29
  // the block map
31
30
  import type { Blocks } from "@decocms/blocks";
32
- import { device, type DeviceProps, random, type RandomProps } from "@decocms/compat-v7/matchers";
31
+ import { device, type DeviceProps } from "@decocms/compat-v7/matchers";
33
32
  import { matcherContext } from "@decocms/compat-v7/tanstack/server";
34
33
 
35
34
  export default {
36
35
  "website/matchers/device.ts": (props: DeviceProps) => device(props, matcherContext()),
37
- "website/matchers/random.ts": (props: RandomProps) => random(props, matcherContext()),
38
36
  } satisfies Blocks;
39
37
  ```
40
38
 
41
- - `matcherContext(pageUrl?)` gives the matcher the request being served (TanStack Start's `getRequest()`), the page's URL and one `flags` array per request.
39
+ - `matcherContext(pageUrl?)` gives the matcher the request being served (TanStack Start's `getRequest()`) and the page's URL, one context per request and URL.
42
40
  - On a client-side navigation the request is the server-function call, not the page. Pass the page's URL there: `matcherContext(new URL(href, request.url))`. Without it, the call throws instead of matching `/_serverFn/…`.
43
- - After the page resolved, in the page's server function, call `commitSegmentCookie()` to set `deco_segment` with the decisions `random` made. It sets nothing when the cookie already says the same.
44
- - `cohortSegment(request)` gives v7's A/B split of the cache key (`{ abf: <token> }` for a visitor in a test, `{}` otherwise). Spread it into the segment of the site's page cache.
45
41
 
46
42
  ## Wiring on Next.js
47
43
 
48
44
  ```ts
49
45
  // the block map
50
46
  import { matcherContext } from "@decocms/compat-v7/nextjs/server";
51
- "website/matchers/random.ts": async (props: RandomProps) => random(props, await matcherContext()),
47
+ "website/matchers/device.ts": async (props: DeviceProps) => device(props, await matcherContext()),
52
48
  ```
53
49
 
54
50
  - The matchers need the page's URL. Forward it from the proxy with `pageUrlRequestHeaders` from `@decocms/compat-v7/nextjs/proxy`, or pass it to `matcherContext(url)`.
55
- - Render `<SegmentCookie />` from `@decocms/compat-v7/nextjs/server` as the last child of the page, after the content resolved. A server component cannot set a cookie, so it renders a one-line script (and an effect after a client-side navigation) that sets it.
56
51
  - A page that reads the request is dynamic: Next never shares it between visitors. Keep a CDN in front from caching it too.
57
52
 
58
- ## The sticky `random`
53
+ ## v7's `random`
59
54
 
60
- - A visitor keeps their group through `deco_segment` until the traffic share changes, then is drawn again once. The draw is `Math.random()`, as in v7.
61
- - The cookie is keyed on the **cohort**: in v7, the name of the saved matcher block. A v8 block does not know its own name, so the name travels in the `cohort` prop. Set it to the v7 saved block's name. The migration script does not register `random` or fill `cohort`: it reports each random test to move into `experiments`. A random rule written inline uses `website/matchers/random.ts` as its cohort, as v7 did.
62
- - Keep the cohort when changing the share. Renaming it puts every visitor in a new test.
63
- - `decideRandom(props, request)` returns `{ value, isFresh, setCookie }` when you need the decision and the cookie together.
64
- - A response that sets `deco_segment` must not be cached for other visitors.
65
- - Inside `multi`, a `random` is sticky too. v7 drew it again on every request.
66
-
67
- The better path for a v7 random test is to move it into the saved block `experiments` under the same name, so visitors keep their groups and the binding owns the cookie. Do not run both on one site.
55
+ `@decocms/compat-v7` has no `random`, and v8 neither reads nor writes v7's `deco_segment` cookie. A rule of type `website/matchers/random.ts` fails with `UNKNOWN_BLOCK` until it is moved: put the test in the saved block `experiments` (type `split-traffic`, a whole percentage 0 to 100; v7's `traffic: 0.3` is `30`) under the v7 saved block's name, and write each rule as `{ "__resolveType": "experiment", "name": "<test>" }` (see [`experiments-and-campaigns.md`](./experiments-and-campaigns.md)). Visitors are drawn again on v8. The migration script reports each random test to move.
68
56
 
69
57
  ## The legacy-origin split
70
58
 
package/src/v8/client.ts CHANGED
@@ -251,18 +251,7 @@ function copyVisitor(visitor: Visitor | null | undefined): Visitor | null {
251
251
  if (typeof visitor !== "object" || visitor === null || typeof visitor.id !== "string") {
252
252
  return null;
253
253
  }
254
- const strings = (value: unknown): string[] =>
255
- Array.isArray(value) ? value.filter((entry) => typeof entry === "string") : [];
256
- const copy: Visitor = {
257
- id: visitor.id,
258
- active: Object.freeze(strings(visitor.active)) as string[],
259
- inactiveDrawn: Object.freeze(strings(visitor.inactiveDrawn)) as string[],
260
- pct: Object.freeze(Object.assign(Object.create(null), visitor.pct)),
261
- };
262
- if (typeof visitor.exp === "object" && visitor.exp !== null) {
263
- copy.exp = Object.freeze(Object.assign(Object.create(null), visitor.exp));
264
- }
265
- return Object.freeze(copy);
254
+ return Object.freeze({ id: visitor.id });
266
255
  }
267
256
 
268
257
  function asCMSError(error: unknown): CMSError {
@@ -14,11 +14,10 @@
14
14
  * storage in an app) and hands it to `cms.client({ visitor })`; the built-in
15
15
  * `split-traffic` calls `assign` with it.
16
16
  *
17
- * The stored form is v7's `deco_segment` (the same fields and encoding; names
18
- * sorted by code unit rather than v7's `localeCompare`) plus an `id`, so a
19
- * visitor carried over from v7 keeps the group v7 put them in and analytics
20
- * keeps reading the cookie it already reads. A visitor is written once, when
21
- * it has no id; v7's stored assignments are read and honoured, never rewritten.
17
+ * A visitor is only its id, stored as is in the `deco_vid` cookie and written
18
+ * once, on a first visit. v7's `deco_segment` is neither read nor written:
19
+ * its stored decisions aren't honoured, and a visitor who has only it gets a
20
+ * new id.
22
21
  */
23
22
 
24
23
  import { newId, roll } from "./bucketing.ts";
@@ -29,26 +28,10 @@ export type Experiments = Record<string, number>;
29
28
  /** What a visitor got: each test's name and whether they are in it. */
30
29
  export type Assignments = Record<string, boolean>;
31
30
 
32
- /**
33
- * Who is visiting: an id every assignment is computed from, plus the
34
- * assignments v7 stored (`active`, `inactiveDrawn`, `pct`, `exp`), which are honoured and
35
- * carried, never rewritten.
36
- */
31
+ /** Who is visiting: an id every assignment is computed from, and nothing else. */
37
32
  export interface Visitor {
38
- /**
39
- * 16 random bytes as 22 base64url characters, drawn once per visitor. `""`
40
- * for a visitor with no id of its own (one built from a cache key's
41
- * assignments), which is in only the tests `active` names.
42
- */
33
+ /** 16 random bytes as 22 base64url characters, drawn once per visitor. */
43
34
  id: string;
44
- /** Tests v7 put this visitor in. */
45
- active: string[];
46
- /** Tests v7 left this visitor out of. */
47
- inactiveDrawn: string[];
48
- /** The percentage each of v7's decisions was made at. */
49
- pct: Record<string, number>;
50
- /** v7's N-way decisions. Never read; carried as they are. */
51
- exp?: Record<string, string>;
52
35
  }
53
36
 
54
37
  /** What `readVisitor` answers. */
@@ -56,9 +39,8 @@ export interface VisitorFromRequest {
56
39
  /** The request's visitor, or a new one when it had none. */
57
40
  visitor: Visitor;
58
41
  /**
59
- * The `Set-Cookie` line to send when the visitor had no id (a first visit,
60
- * or a v7 visitor getting theirs); `null` otherwise. Never send it from a
61
- * preview.
42
+ * The `Set-Cookie` line to send when the visitor had no id (a first
43
+ * visit); `null` otherwise. Never send it from a preview.
62
44
  */
63
45
  cookie: string | null;
64
46
  }
@@ -69,161 +51,47 @@ interface RequestWithHeaders {
69
51
  headers: { get(name: string): string | null };
70
52
  }
71
53
 
72
- /** The visitor's stored form, v7's name for it. */
73
- const VISITOR_COOKIE = "deco_segment";
54
+ /** The visitor's cookie: the id, as is. */
55
+ const VISITOR_COOKIE = "deco_vid";
74
56
 
75
57
  /** One year: the id is the visitor, and it should outlive any single test. */
76
58
  const VISITOR_COOKIE_MAX_AGE = 60 * 60 * 24 * 365;
77
59
 
78
- /**
79
- * A cookie over this stays out of every request. An id plus 50 of v7's
80
- * decisions fits well under it; past it, `serializeVisitor` drops entries,
81
- * the ones the id reproduces first.
82
- */
83
- const COOKIE_BUDGET = 2048;
84
-
85
60
  const ID_RE = /^[A-Za-z0-9_-]{22}$/;
86
61
 
87
- /** A stored visitor before it is known to have an id. */
88
- type Stored = Omit<Visitor, "id"> & { id?: string };
89
-
90
- /**
91
- * A record with no prototype, so a name such as `__proto__` is an ordinary
92
- * key: decided, written and read back like any other.
93
- */
94
- function record<T>(): Record<string, T> {
95
- return Object.create(null) as Record<string, T>;
96
- }
97
-
98
- function emptyStored(): Stored {
99
- return { active: [], inactiveDrawn: [], pct: record() };
100
- }
101
-
102
- function stringList(value: unknown): string[] {
103
- if (!Array.isArray(value)) return [];
104
- return value.filter((entry): entry is string => typeof entry === "string");
105
- }
106
-
107
- function pctRecord(value: unknown): Record<string, number> {
108
- const out = record<number>();
109
- if (typeof value !== "object" || value === null) return out;
110
- for (const [name, pct] of Object.entries(value as Record<string, unknown>)) {
111
- if (typeof pct === "number" && Number.isFinite(pct)) out[name] = pct;
112
- }
113
- return out;
114
- }
115
-
116
- function expRecord(value: unknown): Record<string, string> | undefined {
117
- if (typeof value !== "object" || value === null) return undefined;
118
- const out = record<string>();
119
- for (const [name, variant] of Object.entries(value as Record<string, unknown>)) {
120
- if (typeof variant === "string") out[name] = variant;
121
- }
122
- return Object.keys(out).length > 0 ? out : undefined;
123
- }
124
-
125
- /**
126
- * A stored value, with or without an id; `null` when it doesn't read. Never
127
- * throws. The value may arrive percent-encoded (some cookie APIs encode what
128
- * they write; base64 never holds a `%`, so decoding first is always safe).
129
- * Entries of the wrong type are dropped, and an id that is not 22 base64url
130
- * characters is treated as absent.
131
- */
132
- function parseStored(text: string | null | undefined): Stored | null {
133
- if (typeof text !== "string" || text === "") return null;
62
+ /** The id in a stored value, or `undefined`. Tolerates surrounding spaces and percent-encoding. */
63
+ function idOf(text: string | null | undefined): string | undefined {
64
+ if (typeof text !== "string") return undefined;
65
+ let value = text.trim();
134
66
  try {
135
- const parsed: unknown = JSON.parse(decodeURIComponent(atob(decodeURIComponent(text.trim()))));
136
- if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) return null;
137
- const body = parsed as Record<string, unknown>;
138
- const stored: Stored = {
139
- active: stringList(body.active),
140
- inactiveDrawn: stringList(body.inactiveDrawn),
141
- pct: pctRecord(body.pct),
142
- };
143
- if (typeof body.id === "string" && ID_RE.test(body.id)) stored.id = body.id;
144
- const exp = expRecord(body.exp);
145
- if (exp) stored.exp = exp;
146
- return stored;
67
+ value = decodeURIComponent(value);
147
68
  } catch {
148
- return null;
69
+ return undefined;
149
70
  }
71
+ return ID_RE.test(value) ? value : undefined;
150
72
  }
151
73
 
152
- /** A new visitor: a fresh id and nothing else. */
74
+ /** A new visitor: a fresh id. */
153
75
  export function newVisitor(): Visitor {
154
- return { id: newId(), active: [], inactiveDrawn: [], pct: record() };
76
+ return { id: newId() };
155
77
  }
156
78
 
157
79
  /**
158
- * A visitor out of its stored form (what `serializeVisitor` wrote, the value
159
- * of the `deco_segment` cookie). `null` when the text is missing, doesn't
160
- * read, or holds no id (a v7 value: `readVisitor` gives it one, keeping its
161
- * decisions). Never throws.
80
+ * A visitor out of its stored form (what `serializeVisitor` wrote: the value
81
+ * of the `deco_vid` cookie or of `x-deco-visitor`). `null` when the text is
82
+ * missing or isn't an id. Never throws.
162
83
  */
163
84
  export function parseVisitor(text: string | null | undefined): Visitor | null {
164
- const stored = parseStored(text);
165
- return stored?.id === undefined ? null : (stored as Visitor);
85
+ const id = idOf(text);
86
+ return id === undefined ? null : { id };
166
87
  }
167
88
 
168
- /**
169
- * The visitor's stored form: v7's `btoa(encodeURIComponent(JSON.stringify(...)))`,
170
- * with a fixed key order and names sorted, so two equal visitors give
171
- * byte-equal values. Under 2KB: past it, v7's entries are dropped, first the
172
- * ones the id reproduces anyway.
173
- */
89
+ /** The visitor's stored form: its id. */
174
90
  export function serializeVisitor(visitor: Visitor): string {
175
- const active = [...visitor.active].sort();
176
- const inactiveDrawn = [...visitor.inactiveDrawn].sort();
177
- const dropped = new Set<string>();
178
-
179
- const encode = (): string => {
180
- const stillActive = active.filter((name) => !dropped.has(name));
181
- const stillInactive = inactiveDrawn.filter((name) => !dropped.has(name));
182
- const pct = record<number>();
183
- for (const name of Object.keys(visitor.pct).sort()) {
184
- // v7 kept a `pct` beside its N-way names too, and `exp` is carried
185
- // untouched, so their fingerprint is carried with it.
186
- const listed =
187
- stillActive.includes(name) ||
188
- stillInactive.includes(name) ||
189
- (visitor.exp !== undefined && Object.hasOwn(visitor.exp, name));
190
- if (listed) pct[name] = visitor.pct[name] as number;
191
- }
192
- const body: Record<string, unknown> = {
193
- active: stillActive,
194
- inactiveDrawn: stillInactive,
195
- pct,
196
- };
197
- if (visitor.id !== undefined) body.id = visitor.id;
198
- if (visitor.exp !== undefined) body.exp = visitor.exp;
199
- return btoa(encodeURIComponent(JSON.stringify(body)));
200
- };
201
-
202
- let value = encode();
203
- if (value.length <= COOKIE_BUDGET) return value;
204
-
205
- // Over budget. A dropped entry is decided by the roll from then on, which
206
- // keeps the decision only when the stored one already agrees with the roll.
207
- // So drop those first, and the others only if the value is still too big.
208
- const reproducible = (name: string): boolean => {
209
- const pct = visitor.pct[name];
210
- if (typeof pct !== "number") return false;
211
- return active.includes(name) === roll(name, visitor.id) < pct;
212
- };
213
- for (const name of [
214
- ...inactiveDrawn.filter(reproducible),
215
- ...active.filter(reproducible),
216
- ...inactiveDrawn.filter((name) => !reproducible(name)),
217
- ...active.filter((name) => !reproducible(name)),
218
- ]) {
219
- if (value.length <= COOKIE_BUDGET) break;
220
- dropped.add(name);
221
- value = encode();
222
- }
223
- return value;
91
+ return visitor.id;
224
92
  }
225
93
 
226
- /** The raw `deco_segment` value out of a `Cookie` header. */
94
+ /** The raw `deco_vid` value out of a `Cookie` header. */
227
95
  function readCookie(cookies: string | null): string | undefined {
228
96
  if (!cookies) return undefined;
229
97
  for (const part of cookies.split(";")) {
@@ -246,11 +114,10 @@ function isPlainHttp(url: string | undefined): boolean {
246
114
  }
247
115
 
248
116
  /**
249
- * The web helper: the visitor out of a request's `deco_segment` cookie, and
250
- * the `Set-Cookie` line to send back when it had no id (a first visit, or a
251
- * v7 visitor, whose decisions are kept). The cookie isn't `HttpOnly` (the
252
- * analytics script reads it, as in v7) and is `Secure` unless the request
253
- * came over plain http. Never throws.
117
+ * The web helper: the visitor out of a request's `deco_vid` cookie, and the
118
+ * `Set-Cookie` line to send back when it had none (a first visit). The cookie
119
+ * isn't `HttpOnly`, so a script on the page can read the id, and is `Secure`
120
+ * unless the request came over plain http. Never throws.
254
121
  */
255
122
  export function readVisitor(request: RequestWithHeaders): VisitorFromRequest {
256
123
  let header: string | null = null;
@@ -259,9 +126,9 @@ export function readVisitor(request: RequestWithHeaders): VisitorFromRequest {
259
126
  } catch {
260
127
  header = null;
261
128
  }
262
- const stored = parseStored(readCookie(header));
263
- if (stored?.id !== undefined) return { visitor: stored as Visitor, cookie: null };
264
- const visitor: Visitor = { ...(stored ?? emptyStored()), id: newId() };
129
+ const stored = parseVisitor(readCookie(header));
130
+ if (stored !== null) return { visitor: stored, cookie: null };
131
+ const visitor = newVisitor();
265
132
  const parts = [
266
133
  `${VISITOR_COOKIE}=${serializeVisitor(visitor)}`,
267
134
  "Path=/",
@@ -276,65 +143,28 @@ function roundPct(allocation: number): number {
276
143
  return Math.round(Math.min(100, Math.max(0, allocation)));
277
144
  }
278
145
 
279
- /**
280
- * A v7 decision after the percentage moved: raising a percentage never
281
- * removes anyone v7 put in, and lowering it never adds anyone v7 left out.
282
- * Otherwise the roll decides, as for any visitor.
283
- */
284
- function keptFromV7(stored: boolean, from: number, to: number): boolean | undefined {
285
- if (to === from) return stored;
286
- if (stored && to > from) return true;
287
- if (!stored && to < from) return false;
288
- return undefined;
289
- }
290
-
291
146
  /**
292
147
  * This visitor's answer for every test: `true` when they are in it.
293
148
  *
294
149
  * A visitor is in a test when their roll for it (a fixed number in [0, 100)
295
150
  * from the test's name and their id) is under its percentage, so 0 puts
296
151
  * nobody in, 100 everybody, and raising a percentage only adds people. A
297
- * fractional percentage is rounded. An assignment v7 stored is honoured while
298
- * the percentage it was made at holds (a missing or `-1` percentage, v7's
299
- * "any", included); once it moves, a v7 visitor in a test that grows stays
300
- * in and one out of a test that shrinks stays out. Without a visitor every
301
- * test is `false`. A visitor without an id (`""`, as a page built from a
302
- * cache key's assignments gives one) has no roll: it is in exactly the tests
303
- * its stored `active` and `pct` keep it in. Entries that aren't finite numbers are
304
- * left out. Pure; never throws.
152
+ * fractional percentage is rounded. Without a visitor, or with an id that
153
+ * isn't 22 base64url characters, every test is `false`. Entries that aren't
154
+ * finite numbers are left out. Pure; never throws.
305
155
  */
306
156
  export function assign(
307
157
  experiments: Experiments | null | undefined,
308
158
  visitor: Visitor | null | undefined,
309
159
  ): Assignments {
310
- const assignments = record<boolean>();
160
+ const assignments = Object.create(null) as Assignments;
311
161
  if (typeof experiments !== "object" || experiments === null) return assignments;
312
162
  const id = visitor !== null && typeof visitor === "object" ? visitor.id : undefined;
313
163
  const known = typeof id === "string" && ID_RE.test(id);
314
- const v: Partial<Visitor> = visitor !== null && typeof visitor === "object" ? visitor : {};
315
164
  for (const name of Object.keys(experiments).sort()) {
316
165
  const allocation = experiments[name];
317
166
  if (typeof allocation !== "number" || !Number.isFinite(allocation)) continue;
318
- const pct = roundPct(allocation);
319
- const stored = list(v.active).includes(name)
320
- ? true
321
- : list(v.inactiveDrawn).includes(name)
322
- ? false
323
- : undefined;
324
- // v7 wrote `round(traffic * 100)` here, and its own reader treated a
325
- // missing or negative entry as "matches anything".
326
- const raw = isRecord(v.pct) && Object.hasOwn(v.pct, name) ? v.pct[name] : undefined;
327
- const from = typeof raw === "number" && Number.isFinite(raw) && raw >= 0 ? roundPct(raw) : pct;
328
- const kept = stored === undefined ? undefined : keptFromV7(stored, from, pct);
329
- assignments[name] = kept ?? (known && roll(name, id as string) < pct);
167
+ assignments[name] = known && roll(name, id as string) < roundPct(allocation);
330
168
  }
331
169
  return assignments;
332
170
  }
333
-
334
- function list(value: unknown): string[] {
335
- return Array.isArray(value) ? value : [];
336
- }
337
-
338
- function isRecord(value: unknown): value is Record<string, unknown> {
339
- return typeof value === "object" && value !== null;
340
- }