@uniformdev/next-app-router 20.74.6-alpha.6 → 20.74.6-alpha.7.sha-23d7a1d929
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/{UniformComposition-BWxMuY7i.d.ts → UniformComposition-DBO-oo7J.d.ts} +7 -2
- package/dist/{UniformComposition-Bo6UsTDC.d.mts → UniformComposition-le6UEB_r.d.mts} +7 -2
- package/dist/cache.d.mts +2 -2
- package/dist/cache.d.ts +2 -2
- package/dist/cache.js +3 -1
- package/dist/cache.mjs +3 -1
- package/dist/{client-DRMp2gpi.d.mts → client-BElN_CWD.d.mts} +6 -0
- package/dist/{client-DRMp2gpi.d.ts → client-BElN_CWD.d.ts} +6 -0
- package/dist/compat.d.mts +3 -3
- package/dist/compat.d.ts +3 -3
- package/dist/component.d.mts +2 -2
- package/dist/component.d.ts +2 -2
- package/dist/component.js +31 -15
- package/dist/component.mjs +18 -2
- package/dist/handler.js +6 -3
- package/dist/handler.mjs +6 -3
- package/dist/index.d.mts +7 -7
- package/dist/index.d.ts +7 -7
- package/dist/index.esm.js +3243 -486
- package/dist/index.js +3251 -497
- package/dist/index.mjs +3243 -486
- package/dist/middleware.d.mts +1 -1
- package/dist/middleware.d.ts +1 -1
- package/dist/middleware.js +174 -214
- package/dist/middleware.mjs +171 -211
- package/dist/{resolveRouteFromCode-Bhz8EJBu.d.ts → resolveRouteFromCode-BOvjIvM2.d.ts} +1 -1
- package/dist/{resolveRouteFromCode-C0dkUV2T.d.mts → resolveRouteFromCode-CuJ4JHeb.d.mts} +1 -1
- package/package.json +10 -10
package/dist/index.esm.js
CHANGED
|
@@ -390,6 +390,195 @@ var require_retry2 = __commonJS({
|
|
|
390
390
|
}
|
|
391
391
|
});
|
|
392
392
|
|
|
393
|
+
// ../../node_modules/.pnpm/rfdc@1.4.1/node_modules/rfdc/index.js
|
|
394
|
+
var require_rfdc = __commonJS({
|
|
395
|
+
"../../node_modules/.pnpm/rfdc@1.4.1/node_modules/rfdc/index.js"(exports, module) {
|
|
396
|
+
"use strict";
|
|
397
|
+
module.exports = rfdc4;
|
|
398
|
+
function copyBuffer(cur) {
|
|
399
|
+
if (cur instanceof Buffer) {
|
|
400
|
+
return Buffer.from(cur);
|
|
401
|
+
}
|
|
402
|
+
return new cur.constructor(cur.buffer.slice(), cur.byteOffset, cur.length);
|
|
403
|
+
}
|
|
404
|
+
function rfdc4(opts) {
|
|
405
|
+
opts = opts || {};
|
|
406
|
+
if (opts.circles) return rfdcCircles(opts);
|
|
407
|
+
const constructorHandlers = /* @__PURE__ */ new Map();
|
|
408
|
+
constructorHandlers.set(Date, (o) => new Date(o));
|
|
409
|
+
constructorHandlers.set(Map, (o, fn) => new Map(cloneArray(Array.from(o), fn)));
|
|
410
|
+
constructorHandlers.set(Set, (o, fn) => new Set(cloneArray(Array.from(o), fn)));
|
|
411
|
+
if (opts.constructorHandlers) {
|
|
412
|
+
for (const handler2 of opts.constructorHandlers) {
|
|
413
|
+
constructorHandlers.set(handler2[0], handler2[1]);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
let handler = null;
|
|
417
|
+
return opts.proto ? cloneProto : clone2;
|
|
418
|
+
function cloneArray(a, fn) {
|
|
419
|
+
const keys = Object.keys(a);
|
|
420
|
+
const a2 = new Array(keys.length);
|
|
421
|
+
for (let i = 0; i < keys.length; i++) {
|
|
422
|
+
const k = keys[i];
|
|
423
|
+
const cur = a[k];
|
|
424
|
+
if (typeof cur !== "object" || cur === null) {
|
|
425
|
+
a2[k] = cur;
|
|
426
|
+
} else if (cur.constructor !== Object && (handler = constructorHandlers.get(cur.constructor))) {
|
|
427
|
+
a2[k] = handler(cur, fn);
|
|
428
|
+
} else if (ArrayBuffer.isView(cur)) {
|
|
429
|
+
a2[k] = copyBuffer(cur);
|
|
430
|
+
} else {
|
|
431
|
+
a2[k] = fn(cur);
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
return a2;
|
|
435
|
+
}
|
|
436
|
+
function clone2(o) {
|
|
437
|
+
if (typeof o !== "object" || o === null) return o;
|
|
438
|
+
if (Array.isArray(o)) return cloneArray(o, clone2);
|
|
439
|
+
if (o.constructor !== Object && (handler = constructorHandlers.get(o.constructor))) {
|
|
440
|
+
return handler(o, clone2);
|
|
441
|
+
}
|
|
442
|
+
const o2 = {};
|
|
443
|
+
for (const k in o) {
|
|
444
|
+
if (Object.hasOwnProperty.call(o, k) === false) continue;
|
|
445
|
+
const cur = o[k];
|
|
446
|
+
if (typeof cur !== "object" || cur === null) {
|
|
447
|
+
o2[k] = cur;
|
|
448
|
+
} else if (cur.constructor !== Object && (handler = constructorHandlers.get(cur.constructor))) {
|
|
449
|
+
o2[k] = handler(cur, clone2);
|
|
450
|
+
} else if (ArrayBuffer.isView(cur)) {
|
|
451
|
+
o2[k] = copyBuffer(cur);
|
|
452
|
+
} else {
|
|
453
|
+
o2[k] = clone2(cur);
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
return o2;
|
|
457
|
+
}
|
|
458
|
+
function cloneProto(o) {
|
|
459
|
+
if (typeof o !== "object" || o === null) return o;
|
|
460
|
+
if (Array.isArray(o)) return cloneArray(o, cloneProto);
|
|
461
|
+
if (o.constructor !== Object && (handler = constructorHandlers.get(o.constructor))) {
|
|
462
|
+
return handler(o, cloneProto);
|
|
463
|
+
}
|
|
464
|
+
const o2 = {};
|
|
465
|
+
for (const k in o) {
|
|
466
|
+
const cur = o[k];
|
|
467
|
+
if (typeof cur !== "object" || cur === null) {
|
|
468
|
+
o2[k] = cur;
|
|
469
|
+
} else if (cur.constructor !== Object && (handler = constructorHandlers.get(cur.constructor))) {
|
|
470
|
+
o2[k] = handler(cur, cloneProto);
|
|
471
|
+
} else if (ArrayBuffer.isView(cur)) {
|
|
472
|
+
o2[k] = copyBuffer(cur);
|
|
473
|
+
} else {
|
|
474
|
+
o2[k] = cloneProto(cur);
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
return o2;
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
function rfdcCircles(opts) {
|
|
481
|
+
const refs = [];
|
|
482
|
+
const refsNew = [];
|
|
483
|
+
const constructorHandlers = /* @__PURE__ */ new Map();
|
|
484
|
+
constructorHandlers.set(Date, (o) => new Date(o));
|
|
485
|
+
constructorHandlers.set(Map, (o, fn) => new Map(cloneArray(Array.from(o), fn)));
|
|
486
|
+
constructorHandlers.set(Set, (o, fn) => new Set(cloneArray(Array.from(o), fn)));
|
|
487
|
+
if (opts.constructorHandlers) {
|
|
488
|
+
for (const handler2 of opts.constructorHandlers) {
|
|
489
|
+
constructorHandlers.set(handler2[0], handler2[1]);
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
let handler = null;
|
|
493
|
+
return opts.proto ? cloneProto : clone2;
|
|
494
|
+
function cloneArray(a, fn) {
|
|
495
|
+
const keys = Object.keys(a);
|
|
496
|
+
const a2 = new Array(keys.length);
|
|
497
|
+
for (let i = 0; i < keys.length; i++) {
|
|
498
|
+
const k = keys[i];
|
|
499
|
+
const cur = a[k];
|
|
500
|
+
if (typeof cur !== "object" || cur === null) {
|
|
501
|
+
a2[k] = cur;
|
|
502
|
+
} else if (cur.constructor !== Object && (handler = constructorHandlers.get(cur.constructor))) {
|
|
503
|
+
a2[k] = handler(cur, fn);
|
|
504
|
+
} else if (ArrayBuffer.isView(cur)) {
|
|
505
|
+
a2[k] = copyBuffer(cur);
|
|
506
|
+
} else {
|
|
507
|
+
const index = refs.indexOf(cur);
|
|
508
|
+
if (index !== -1) {
|
|
509
|
+
a2[k] = refsNew[index];
|
|
510
|
+
} else {
|
|
511
|
+
a2[k] = fn(cur);
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
return a2;
|
|
516
|
+
}
|
|
517
|
+
function clone2(o) {
|
|
518
|
+
if (typeof o !== "object" || o === null) return o;
|
|
519
|
+
if (Array.isArray(o)) return cloneArray(o, clone2);
|
|
520
|
+
if (o.constructor !== Object && (handler = constructorHandlers.get(o.constructor))) {
|
|
521
|
+
return handler(o, clone2);
|
|
522
|
+
}
|
|
523
|
+
const o2 = {};
|
|
524
|
+
refs.push(o);
|
|
525
|
+
refsNew.push(o2);
|
|
526
|
+
for (const k in o) {
|
|
527
|
+
if (Object.hasOwnProperty.call(o, k) === false) continue;
|
|
528
|
+
const cur = o[k];
|
|
529
|
+
if (typeof cur !== "object" || cur === null) {
|
|
530
|
+
o2[k] = cur;
|
|
531
|
+
} else if (cur.constructor !== Object && (handler = constructorHandlers.get(cur.constructor))) {
|
|
532
|
+
o2[k] = handler(cur, clone2);
|
|
533
|
+
} else if (ArrayBuffer.isView(cur)) {
|
|
534
|
+
o2[k] = copyBuffer(cur);
|
|
535
|
+
} else {
|
|
536
|
+
const i = refs.indexOf(cur);
|
|
537
|
+
if (i !== -1) {
|
|
538
|
+
o2[k] = refsNew[i];
|
|
539
|
+
} else {
|
|
540
|
+
o2[k] = clone2(cur);
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
refs.pop();
|
|
545
|
+
refsNew.pop();
|
|
546
|
+
return o2;
|
|
547
|
+
}
|
|
548
|
+
function cloneProto(o) {
|
|
549
|
+
if (typeof o !== "object" || o === null) return o;
|
|
550
|
+
if (Array.isArray(o)) return cloneArray(o, cloneProto);
|
|
551
|
+
if (o.constructor !== Object && (handler = constructorHandlers.get(o.constructor))) {
|
|
552
|
+
return handler(o, cloneProto);
|
|
553
|
+
}
|
|
554
|
+
const o2 = {};
|
|
555
|
+
refs.push(o);
|
|
556
|
+
refsNew.push(o2);
|
|
557
|
+
for (const k in o) {
|
|
558
|
+
const cur = o[k];
|
|
559
|
+
if (typeof cur !== "object" || cur === null) {
|
|
560
|
+
o2[k] = cur;
|
|
561
|
+
} else if (cur.constructor !== Object && (handler = constructorHandlers.get(cur.constructor))) {
|
|
562
|
+
o2[k] = handler(cur, cloneProto);
|
|
563
|
+
} else if (ArrayBuffer.isView(cur)) {
|
|
564
|
+
o2[k] = copyBuffer(cur);
|
|
565
|
+
} else {
|
|
566
|
+
const i = refs.indexOf(cur);
|
|
567
|
+
if (i !== -1) {
|
|
568
|
+
o2[k] = refsNew[i];
|
|
569
|
+
} else {
|
|
570
|
+
o2[k] = cloneProto(cur);
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
refs.pop();
|
|
575
|
+
refsNew.pop();
|
|
576
|
+
return o2;
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
});
|
|
581
|
+
|
|
393
582
|
// src/index.ts
|
|
394
583
|
import "server-only";
|
|
395
584
|
|
|
@@ -1446,15 +1635,15 @@ var CanvasClient = class extends ApiClient {
|
|
|
1446
1635
|
/** Updates or creates a Canvas component definition */
|
|
1447
1636
|
async updateComposition(body, options) {
|
|
1448
1637
|
const fetchUri = this.createUrl(CANVAS_URL2);
|
|
1449
|
-
const
|
|
1638
|
+
const headers2 = {};
|
|
1450
1639
|
if (options == null ? void 0 : options.ifUnmodifiedSince) {
|
|
1451
|
-
|
|
1640
|
+
headers2["x-if-unmodified-since"] = options.ifUnmodifiedSince;
|
|
1452
1641
|
}
|
|
1453
1642
|
const { response } = await this.apiClientWithResponse(fetchUri, {
|
|
1454
1643
|
method: "PUT",
|
|
1455
1644
|
body: JSON.stringify({ ...body, projectId: this.options.projectId }),
|
|
1456
1645
|
expectNoContent: true,
|
|
1457
|
-
headers
|
|
1646
|
+
headers: headers2
|
|
1458
1647
|
});
|
|
1459
1648
|
return { modified: response.headers.get("x-modified-at") };
|
|
1460
1649
|
}
|
|
@@ -1552,15 +1741,15 @@ var _ContentClient = class _ContentClient2 extends ApiClient {
|
|
|
1552
1741
|
}
|
|
1553
1742
|
async upsertEntry(body, options) {
|
|
1554
1743
|
const fetchUri = this.createUrl(__privateGet3(_ContentClient2, _entriesUrl));
|
|
1555
|
-
const
|
|
1744
|
+
const headers2 = {};
|
|
1556
1745
|
if (options == null ? void 0 : options.ifUnmodifiedSince) {
|
|
1557
|
-
|
|
1746
|
+
headers2["x-if-unmodified-since"] = options.ifUnmodifiedSince;
|
|
1558
1747
|
}
|
|
1559
1748
|
const { response } = await this.apiClientWithResponse(fetchUri, {
|
|
1560
1749
|
method: "PUT",
|
|
1561
1750
|
body: JSON.stringify({ ...body, projectId: this.options.projectId }),
|
|
1562
1751
|
expectNoContent: true,
|
|
1563
|
-
headers
|
|
1752
|
+
headers: headers2
|
|
1564
1753
|
});
|
|
1565
1754
|
return { modified: response.headers.get("x-modified-at") };
|
|
1566
1755
|
}
|
|
@@ -1871,7 +2060,8 @@ function walkNodeTree(node, visitor, options) {
|
|
|
1871
2060
|
"_dataResources",
|
|
1872
2061
|
"_overridability",
|
|
1873
2062
|
"_overrides",
|
|
1874
|
-
"_patternDataResources"
|
|
2063
|
+
"_patternDataResources",
|
|
2064
|
+
"_patternOptedInQueryStrings"
|
|
1875
2065
|
];
|
|
1876
2066
|
propertiesToCheck.forEach((property) => {
|
|
1877
2067
|
if (!replacementComponent[property]) {
|
|
@@ -2057,7 +2247,155 @@ var BlockFormatError = class _BlockFormatError extends Error {
|
|
|
2057
2247
|
function createVariableReference(variableName) {
|
|
2058
2248
|
return `\${${variableName.replace(/([${}])/g, "\\$1")}}`;
|
|
2059
2249
|
}
|
|
2250
|
+
function evaluateVisibilityCriteriaGroup(options) {
|
|
2251
|
+
const { criteriaGroup, simplifyCriteria } = options;
|
|
2252
|
+
const earlyExitResult = criteriaGroup.op === "&" || !criteriaGroup.op ? false : true;
|
|
2253
|
+
let hasIndeterminateClauses = false;
|
|
2254
|
+
for (let index = criteriaGroup.clauses.length - 1; index >= 0; index--) {
|
|
2255
|
+
const clause = criteriaGroup.clauses[index];
|
|
2256
|
+
const criteriaResult = evaluateCriterion(clause, options);
|
|
2257
|
+
if (criteriaResult === null) {
|
|
2258
|
+
hasIndeterminateClauses = true;
|
|
2259
|
+
} else if (criteriaResult === earlyExitResult) {
|
|
2260
|
+
return earlyExitResult;
|
|
2261
|
+
} else if (criteriaResult !== null && simplifyCriteria) {
|
|
2262
|
+
criteriaGroup.clauses.splice(index, 1);
|
|
2263
|
+
}
|
|
2264
|
+
}
|
|
2265
|
+
return hasIndeterminateClauses ? null : !earlyExitResult;
|
|
2266
|
+
}
|
|
2267
|
+
function evaluateCriterion(clause, rootOptions) {
|
|
2268
|
+
var _a;
|
|
2269
|
+
if ("clauses" in clause) {
|
|
2270
|
+
return evaluateVisibilityCriteriaGroup({
|
|
2271
|
+
...rootOptions,
|
|
2272
|
+
criteriaGroup: clause
|
|
2273
|
+
});
|
|
2274
|
+
}
|
|
2275
|
+
const lhs = (_a = clause.source) != null ? _a : clause.rule;
|
|
2276
|
+
const rhs = Array.isArray(clause.value) ? clause.value : clause.value !== void 0 ? [clause.value] : void 0;
|
|
2277
|
+
if (typeof lhs === "string" && hasReferencedVariables(lhs) > 0 || (rhs == null ? void 0 : rhs.some((rhv) => typeof rhv === "string" && hasReferencedVariables(rhv) > 0))) {
|
|
2278
|
+
return null;
|
|
2279
|
+
}
|
|
2280
|
+
const rule = rootOptions.rules[clause.rule];
|
|
2281
|
+
if (rule) {
|
|
2282
|
+
return rule(clause);
|
|
2283
|
+
}
|
|
2284
|
+
return null;
|
|
2285
|
+
}
|
|
2286
|
+
function evaluateNodeVisibilityParameter({
|
|
2287
|
+
parameter,
|
|
2288
|
+
...evaluateGroupOptions
|
|
2289
|
+
}) {
|
|
2290
|
+
if (parameter == null ? void 0 : parameter.explicitlyHidden) {
|
|
2291
|
+
return false;
|
|
2292
|
+
}
|
|
2293
|
+
if (!(parameter == null ? void 0 : parameter.criteria)) {
|
|
2294
|
+
return true;
|
|
2295
|
+
}
|
|
2296
|
+
const result = evaluateVisibilityCriteriaGroup({
|
|
2297
|
+
...evaluateGroupOptions,
|
|
2298
|
+
criteriaGroup: parameter.criteria
|
|
2299
|
+
});
|
|
2300
|
+
return result;
|
|
2301
|
+
}
|
|
2060
2302
|
var CANVAS_VIZ_CONTROL_PARAM = "$viz";
|
|
2303
|
+
var isEvaluator = (criteria, matchValue) => {
|
|
2304
|
+
if (Array.isArray(criteria)) {
|
|
2305
|
+
return criteria.includes(matchValue);
|
|
2306
|
+
}
|
|
2307
|
+
return criteria === matchValue;
|
|
2308
|
+
};
|
|
2309
|
+
var containsEvaluator = (criteria, matchValue) => {
|
|
2310
|
+
if (Array.isArray(criteria)) {
|
|
2311
|
+
return criteria.some((criterion) => matchValue.includes(criterion));
|
|
2312
|
+
}
|
|
2313
|
+
return matchValue.includes(criteria);
|
|
2314
|
+
};
|
|
2315
|
+
var startsWithEvaluator = (criteria, matchValue) => {
|
|
2316
|
+
if (Array.isArray(criteria)) {
|
|
2317
|
+
return criteria.some((criterion) => matchValue.startsWith(criterion));
|
|
2318
|
+
}
|
|
2319
|
+
return matchValue.startsWith(criteria);
|
|
2320
|
+
};
|
|
2321
|
+
var endsWithEvaluator = (criteria, matchValue) => {
|
|
2322
|
+
if (Array.isArray(criteria)) {
|
|
2323
|
+
return criteria.some((criterion) => matchValue.endsWith(criterion));
|
|
2324
|
+
}
|
|
2325
|
+
return matchValue.endsWith(criteria);
|
|
2326
|
+
};
|
|
2327
|
+
var emptyEvaluator = (_, matchValue) => {
|
|
2328
|
+
return matchValue === "";
|
|
2329
|
+
};
|
|
2330
|
+
var stringOperatorEvaluators = {
|
|
2331
|
+
is: isEvaluator,
|
|
2332
|
+
has: containsEvaluator,
|
|
2333
|
+
startswith: startsWithEvaluator,
|
|
2334
|
+
endswith: endsWithEvaluator,
|
|
2335
|
+
empty: emptyEvaluator
|
|
2336
|
+
};
|
|
2337
|
+
var numericOperatorEvaluators = {
|
|
2338
|
+
gt: (left, right) => left > right,
|
|
2339
|
+
lt: (left, right) => left < right
|
|
2340
|
+
};
|
|
2341
|
+
function evaluateNumericOperator(criteria, matchValue) {
|
|
2342
|
+
const { op, value } = criteria;
|
|
2343
|
+
const evaluator = numericOperatorEvaluators[op];
|
|
2344
|
+
if (!evaluator) {
|
|
2345
|
+
return null;
|
|
2346
|
+
}
|
|
2347
|
+
if (typeof matchValue === "string" && matchValue.trim() === "" || typeof value === "string" && value.trim() === "") {
|
|
2348
|
+
return false;
|
|
2349
|
+
}
|
|
2350
|
+
const leftNum = Number(matchValue);
|
|
2351
|
+
const rightNum = Number(value);
|
|
2352
|
+
if (isNaN(leftNum) || isNaN(rightNum)) {
|
|
2353
|
+
return false;
|
|
2354
|
+
}
|
|
2355
|
+
return evaluator(leftNum, rightNum);
|
|
2356
|
+
}
|
|
2357
|
+
function evaluateStringMatch(criteria, matchValue, allow) {
|
|
2358
|
+
const { op, value } = criteria;
|
|
2359
|
+
if (allow && !allow.has(op)) {
|
|
2360
|
+
return null;
|
|
2361
|
+
}
|
|
2362
|
+
if (op in numericOperatorEvaluators) {
|
|
2363
|
+
return evaluateNumericOperator(criteria, matchValue);
|
|
2364
|
+
}
|
|
2365
|
+
let opMatch = op;
|
|
2366
|
+
const negation = op.startsWith("!");
|
|
2367
|
+
if (negation) {
|
|
2368
|
+
opMatch = opMatch.slice(1);
|
|
2369
|
+
}
|
|
2370
|
+
const evaluator = stringOperatorEvaluators[opMatch];
|
|
2371
|
+
if (!evaluator) {
|
|
2372
|
+
return null;
|
|
2373
|
+
}
|
|
2374
|
+
const result = evaluator(value, matchValue);
|
|
2375
|
+
return negation ? !result : result;
|
|
2376
|
+
}
|
|
2377
|
+
var quirksVisibilityOperators = /* @__PURE__ */ new Set([
|
|
2378
|
+
"is",
|
|
2379
|
+
"!is",
|
|
2380
|
+
"has",
|
|
2381
|
+
"!has",
|
|
2382
|
+
"startswith",
|
|
2383
|
+
"!startswith",
|
|
2384
|
+
"endswith",
|
|
2385
|
+
"!endswith",
|
|
2386
|
+
"empty",
|
|
2387
|
+
"!empty"
|
|
2388
|
+
]);
|
|
2389
|
+
var CANVAS_VIZ_QUIRKS_RULE = "$qk";
|
|
2390
|
+
function createQuirksVisibilityRule(quirks) {
|
|
2391
|
+
return {
|
|
2392
|
+
[CANVAS_VIZ_QUIRKS_RULE]: (criterion) => {
|
|
2393
|
+
const { source } = criterion;
|
|
2394
|
+
const quirkValue = source ? quirks[source] : void 0;
|
|
2395
|
+
return evaluateStringMatch(criterion, quirkValue != null ? quirkValue : "", quirksVisibilityOperators);
|
|
2396
|
+
}
|
|
2397
|
+
};
|
|
2398
|
+
}
|
|
2061
2399
|
var _baseUrl;
|
|
2062
2400
|
var _IntegrationPropertyEditorsClient = class _IntegrationPropertyEditorsClient2 extends ApiClient {
|
|
2063
2401
|
constructor(options) {
|
|
@@ -2501,7 +2839,7 @@ var buildCanvasClientOptions = (options) => {
|
|
|
2501
2839
|
limitPolicy: createLimitPolicy2({
|
|
2502
2840
|
limit: 6
|
|
2503
2841
|
}),
|
|
2504
|
-
fetch: (req,
|
|
2842
|
+
fetch: (req, init2) => {
|
|
2505
2843
|
let requestedUrl;
|
|
2506
2844
|
if (typeof req === "string") {
|
|
2507
2845
|
requestedUrl = new URL(req);
|
|
@@ -2528,10 +2866,10 @@ var buildCanvasClientOptions = (options) => {
|
|
|
2528
2866
|
}
|
|
2529
2867
|
const { cache: fetchCache, revalidate } = determineFetchCacheOptions(cache2);
|
|
2530
2868
|
return fetch(req, {
|
|
2531
|
-
...
|
|
2869
|
+
...init2,
|
|
2532
2870
|
cache: fetchCache,
|
|
2533
2871
|
headers: {
|
|
2534
|
-
...
|
|
2872
|
+
...init2 == null ? void 0 : init2.headers,
|
|
2535
2873
|
"x-bypass-cache": typeof cache2.bypassCache !== "undefined" ? cache2.bypassCache.toString() : "false"
|
|
2536
2874
|
},
|
|
2537
2875
|
next: {
|
|
@@ -2580,12 +2918,12 @@ var getManifestClient = (options) => {
|
|
|
2580
2918
|
limitPolicy: createLimitPolicy2({
|
|
2581
2919
|
limit: 6
|
|
2582
2920
|
}),
|
|
2583
|
-
fetch: (req,
|
|
2921
|
+
fetch: (req, init2) => {
|
|
2584
2922
|
const { cache: fetchCache, revalidate } = determineFetchCacheOptions(cache2);
|
|
2585
2923
|
return fetch(req, {
|
|
2586
|
-
...
|
|
2924
|
+
...init2,
|
|
2587
2925
|
headers: {
|
|
2588
|
-
...
|
|
2926
|
+
...init2 == null ? void 0 : init2.headers,
|
|
2589
2927
|
"x-bypass-cache": typeof cache2.bypassCache !== "undefined" ? cache2.bypassCache.toString() : "false"
|
|
2590
2928
|
},
|
|
2591
2929
|
cache: fetchCache,
|
|
@@ -2922,12 +3260,12 @@ var getProjectMapClient = (options) => {
|
|
|
2922
3260
|
limitPolicy: createLimitPolicy2({
|
|
2923
3261
|
limit: 6
|
|
2924
3262
|
}),
|
|
2925
|
-
fetch: (req,
|
|
3263
|
+
fetch: (req, init2) => {
|
|
2926
3264
|
const { cache: fetchCache, revalidate } = determineFetchCacheOptions(cache2);
|
|
2927
3265
|
return fetch(req, {
|
|
2928
|
-
...
|
|
3266
|
+
...init2,
|
|
2929
3267
|
headers: {
|
|
2930
|
-
...
|
|
3268
|
+
...init2 == null ? void 0 : init2.headers,
|
|
2931
3269
|
"x-bypass-cache": typeof cache2.bypassCache !== "undefined" ? cache2.bypassCache.toString() : "false"
|
|
2932
3270
|
},
|
|
2933
3271
|
cache: fetchCache,
|
|
@@ -2963,7 +3301,7 @@ var getRouteClient = (options) => {
|
|
|
2963
3301
|
limitPolicy: createLimitPolicy2({
|
|
2964
3302
|
limit: 6
|
|
2965
3303
|
}),
|
|
2966
|
-
fetch: (req,
|
|
3304
|
+
fetch: (req, init2) => {
|
|
2967
3305
|
let requestedUrl;
|
|
2968
3306
|
if (typeof req === "string") {
|
|
2969
3307
|
requestedUrl = new URL(req);
|
|
@@ -2975,9 +3313,9 @@ var getRouteClient = (options) => {
|
|
|
2975
3313
|
const tags = getRouteCacheTags(requestedUrl);
|
|
2976
3314
|
const { cache: fetchCache, revalidate } = determineFetchCacheOptions(cache2);
|
|
2977
3315
|
return fetch(req, {
|
|
2978
|
-
...
|
|
3316
|
+
...init2,
|
|
2979
3317
|
headers: {
|
|
2980
|
-
...
|
|
3318
|
+
...init2 == null ? void 0 : init2.headers,
|
|
2981
3319
|
"x-bypass-cache": typeof cache2.bypassCache !== "undefined" ? cache2.bypassCache.toString() : "false"
|
|
2982
3320
|
},
|
|
2983
3321
|
cache: fetchCache,
|
|
@@ -2998,115 +3336,2836 @@ import {
|
|
|
2998
3336
|
resolveRuleFromPageState
|
|
2999
3337
|
} from "@uniformdev/next-app-router-shared";
|
|
3000
3338
|
import { notFound } from "next/navigation";
|
|
3001
|
-
import
|
|
3339
|
+
import React4, { createElement as createElement2, Fragment as Fragment2, Suspense } from "react";
|
|
3002
3340
|
|
|
3003
|
-
// src/data/
|
|
3004
|
-
import {
|
|
3005
|
-
|
|
3006
|
-
|
|
3007
|
-
|
|
3008
|
-
|
|
3009
|
-
|
|
3010
|
-
|
|
3011
|
-
|
|
3012
|
-
|
|
3341
|
+
// src/data/evaluate/evaluateDraftPageState.ts
|
|
3342
|
+
import { cookies, headers } from "next/headers";
|
|
3343
|
+
|
|
3344
|
+
// ../../node_modules/.pnpm/dequal@2.0.3/node_modules/dequal/lite/index.mjs
|
|
3345
|
+
var has = Object.prototype.hasOwnProperty;
|
|
3346
|
+
function dequal(foo, bar) {
|
|
3347
|
+
var ctor, len;
|
|
3348
|
+
if (foo === bar) return true;
|
|
3349
|
+
if (foo && bar && (ctor = foo.constructor) === bar.constructor) {
|
|
3350
|
+
if (ctor === Date) return foo.getTime() === bar.getTime();
|
|
3351
|
+
if (ctor === RegExp) return foo.toString() === bar.toString();
|
|
3352
|
+
if (ctor === Array) {
|
|
3353
|
+
if ((len = foo.length) === bar.length) {
|
|
3354
|
+
while (len-- && dequal(foo[len], bar[len])) ;
|
|
3355
|
+
}
|
|
3356
|
+
return len === -1;
|
|
3013
3357
|
}
|
|
3014
|
-
|
|
3015
|
-
|
|
3016
|
-
|
|
3017
|
-
|
|
3018
|
-
|
|
3019
|
-
|
|
3020
|
-
|
|
3021
|
-
|
|
3022
|
-
|
|
3023
|
-
|
|
3024
|
-
}
|
|
3358
|
+
if (!ctor || typeof foo === "object") {
|
|
3359
|
+
len = 0;
|
|
3360
|
+
for (ctor in foo) {
|
|
3361
|
+
if (has.call(foo, ctor) && ++len && !has.call(bar, ctor)) return false;
|
|
3362
|
+
if (!(ctor in bar) || !dequal(foo[ctor], bar[ctor])) return false;
|
|
3363
|
+
}
|
|
3364
|
+
return Object.keys(bar).length === len;
|
|
3365
|
+
}
|
|
3366
|
+
}
|
|
3367
|
+
return foo !== foo && bar !== bar;
|
|
3368
|
+
}
|
|
3025
3369
|
|
|
3026
|
-
//
|
|
3027
|
-
|
|
3028
|
-
|
|
3029
|
-
|
|
3030
|
-
var
|
|
3031
|
-
|
|
3032
|
-
|
|
3033
|
-
isRoot,
|
|
3034
|
-
slotName,
|
|
3035
|
-
slotIndex,
|
|
3036
|
-
slots,
|
|
3037
|
-
pageState,
|
|
3038
|
-
composition,
|
|
3039
|
-
compositionContext
|
|
3040
|
-
}) => {
|
|
3041
|
-
var _a, _b;
|
|
3042
|
-
const parameters = (_a = component.parameters) != null ? _a : {};
|
|
3043
|
-
const componentProps = {
|
|
3044
|
-
parameters: Object.keys(parameters).reduce((acc, cur) => {
|
|
3045
|
-
acc[cur] = {
|
|
3046
|
-
parameterId: cur,
|
|
3047
|
-
...parameters[cur]
|
|
3048
|
-
};
|
|
3049
|
-
return acc;
|
|
3050
|
-
}, {}),
|
|
3051
|
-
component: {
|
|
3052
|
-
_id: component._id,
|
|
3053
|
-
_parentId: (_b = parent == null ? void 0 : parent._id) != null ? _b : null,
|
|
3054
|
-
slotName,
|
|
3055
|
-
slotIndex: isRoot ? void 0 : slotIndex
|
|
3056
|
-
},
|
|
3057
|
-
type: component.type,
|
|
3058
|
-
variant: component.variant,
|
|
3059
|
-
slots,
|
|
3060
|
-
context: {
|
|
3061
|
-
isContextualEditing: pageState.compositionState === CANVAS_EDITOR_STATE,
|
|
3062
|
-
_id: composition._id,
|
|
3063
|
-
state: pageState.compositionState,
|
|
3064
|
-
type: composition.type,
|
|
3065
|
-
pageState,
|
|
3066
|
-
matchedRoute: compositionContext.matchedRoute,
|
|
3067
|
-
dynamicInputs: compositionContext.dynamicInputs
|
|
3370
|
+
// ../../node_modules/.pnpm/js-cookie@3.0.8/node_modules/js-cookie/dist/js.cookie.mjs
|
|
3371
|
+
function assign(target) {
|
|
3372
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
3373
|
+
var source = arguments[i];
|
|
3374
|
+
for (var key in source) {
|
|
3375
|
+
if (key === "__proto__") continue;
|
|
3376
|
+
target[key] = source[key];
|
|
3068
3377
|
}
|
|
3069
|
-
}
|
|
3070
|
-
return
|
|
3378
|
+
}
|
|
3379
|
+
return target;
|
|
3380
|
+
}
|
|
3381
|
+
var defaultConverter = {
|
|
3382
|
+
read: function(value) {
|
|
3383
|
+
if (value[0] === '"') {
|
|
3384
|
+
value = value.slice(1, -1);
|
|
3385
|
+
}
|
|
3386
|
+
return value.replace(/(%[\dA-F]{2})+/gi, decodeURIComponent);
|
|
3387
|
+
},
|
|
3388
|
+
write: function(value) {
|
|
3389
|
+
return encodeURIComponent(value).replace(
|
|
3390
|
+
/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,
|
|
3391
|
+
decodeURIComponent
|
|
3392
|
+
);
|
|
3393
|
+
}
|
|
3071
3394
|
};
|
|
3072
|
-
|
|
3073
|
-
|
|
3074
|
-
|
|
3075
|
-
|
|
3076
|
-
}
|
|
3077
|
-
|
|
3078
|
-
|
|
3079
|
-
|
|
3080
|
-
|
|
3081
|
-
|
|
3082
|
-
|
|
3083
|
-
|
|
3084
|
-
|
|
3085
|
-
|
|
3395
|
+
function init(converter, defaultAttributes) {
|
|
3396
|
+
function set(name, value, attributes) {
|
|
3397
|
+
if (typeof document === "undefined") {
|
|
3398
|
+
return;
|
|
3399
|
+
}
|
|
3400
|
+
attributes = assign({}, defaultAttributes, attributes);
|
|
3401
|
+
if (typeof attributes.expires === "number") {
|
|
3402
|
+
attributes.expires = new Date(Date.now() + attributes.expires * 864e5);
|
|
3403
|
+
}
|
|
3404
|
+
if (attributes.expires) {
|
|
3405
|
+
attributes.expires = attributes.expires.toUTCString();
|
|
3406
|
+
}
|
|
3407
|
+
name = encodeURIComponent(name).replace(/%(2[346B]|5E|60|7C)/g, decodeURIComponent).replace(/[()]/g, escape);
|
|
3408
|
+
var stringifiedAttributes = "";
|
|
3409
|
+
for (var attributeName in attributes) {
|
|
3410
|
+
if (!attributes[attributeName]) {
|
|
3411
|
+
continue;
|
|
3412
|
+
}
|
|
3413
|
+
stringifiedAttributes += "; " + attributeName;
|
|
3414
|
+
if (attributes[attributeName] === true) {
|
|
3415
|
+
continue;
|
|
3416
|
+
}
|
|
3417
|
+
stringifiedAttributes += "=" + attributes[attributeName].split(";")[0];
|
|
3418
|
+
}
|
|
3419
|
+
return document.cookie = name + "=" + converter.write(value, name) + stringifiedAttributes;
|
|
3420
|
+
}
|
|
3421
|
+
function get(name) {
|
|
3422
|
+
if (typeof document === "undefined" || arguments.length && !name) {
|
|
3423
|
+
return;
|
|
3424
|
+
}
|
|
3425
|
+
var cookies2 = document.cookie ? document.cookie.split("; ") : [];
|
|
3426
|
+
var jar = {};
|
|
3427
|
+
for (var i = 0; i < cookies2.length; i++) {
|
|
3428
|
+
var parts = cookies2[i].split("=");
|
|
3429
|
+
var value = parts.slice(1).join("=");
|
|
3430
|
+
try {
|
|
3431
|
+
var found = decodeURIComponent(parts[0]);
|
|
3432
|
+
if (!(found in jar)) jar[found] = converter.read(value, found);
|
|
3433
|
+
if (name === found) {
|
|
3434
|
+
break;
|
|
3435
|
+
}
|
|
3436
|
+
} catch (_e) {
|
|
3437
|
+
}
|
|
3438
|
+
}
|
|
3439
|
+
return name ? jar[name] : jar;
|
|
3440
|
+
}
|
|
3441
|
+
return Object.create(
|
|
3442
|
+
{
|
|
3443
|
+
set,
|
|
3444
|
+
get,
|
|
3445
|
+
remove: function(name, attributes) {
|
|
3446
|
+
set(
|
|
3447
|
+
name,
|
|
3448
|
+
"",
|
|
3449
|
+
assign({}, attributes, {
|
|
3450
|
+
expires: -1
|
|
3451
|
+
})
|
|
3452
|
+
);
|
|
3453
|
+
},
|
|
3454
|
+
withAttributes: function(attributes) {
|
|
3455
|
+
return init(this.converter, assign({}, this.attributes, attributes));
|
|
3456
|
+
},
|
|
3457
|
+
withConverter: function(converter2) {
|
|
3458
|
+
return init(assign({}, this.converter, converter2), this.attributes);
|
|
3459
|
+
}
|
|
3460
|
+
},
|
|
3461
|
+
{
|
|
3462
|
+
attributes: { value: Object.freeze(defaultAttributes) },
|
|
3463
|
+
converter: { value: Object.freeze(converter) }
|
|
3464
|
+
}
|
|
3465
|
+
);
|
|
3466
|
+
}
|
|
3467
|
+
var api = init(defaultConverter, { path: "/" });
|
|
3468
|
+
|
|
3469
|
+
// ../../node_modules/.pnpm/mitt@3.0.1/node_modules/mitt/dist/mitt.mjs
|
|
3470
|
+
function mitt_default(n) {
|
|
3471
|
+
return { all: n = n || /* @__PURE__ */ new Map(), on: function(t, e) {
|
|
3472
|
+
var i = n.get(t);
|
|
3473
|
+
i ? i.push(e) : n.set(t, [e]);
|
|
3474
|
+
}, off: function(t, e) {
|
|
3475
|
+
var i = n.get(t);
|
|
3476
|
+
i && (e ? i.splice(i.indexOf(e) >>> 0, 1) : n.set(t, []));
|
|
3477
|
+
}, emit: function(t, e) {
|
|
3478
|
+
var i = n.get(t);
|
|
3479
|
+
i && i.slice().map(function(n2) {
|
|
3480
|
+
n2(e);
|
|
3481
|
+
}), (i = n.get("*")) && i.slice().map(function(n2) {
|
|
3482
|
+
n2(t, e);
|
|
3483
|
+
});
|
|
3484
|
+
} };
|
|
3485
|
+
}
|
|
3486
|
+
|
|
3487
|
+
// ../context/dist/index.mjs
|
|
3488
|
+
var import_rfdc = __toESM(require_rfdc(), 1);
|
|
3489
|
+
var import_rfdc2 = __toESM(require_rfdc(), 1);
|
|
3490
|
+
var import_rfdc3 = __toESM(require_rfdc(), 1);
|
|
3491
|
+
var __defProp3 = Object.defineProperty;
|
|
3492
|
+
var __typeError5 = (msg) => {
|
|
3493
|
+
throw TypeError(msg);
|
|
3086
3494
|
};
|
|
3087
|
-
var
|
|
3088
|
-
|
|
3089
|
-
|
|
3090
|
-
|
|
3091
|
-
|
|
3092
|
-
|
|
3495
|
+
var __defNormalProp3 = (obj, key, value) => key in obj ? __defProp3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3496
|
+
var __publicField3 = (obj, key, value) => __defNormalProp3(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
3497
|
+
var __accessCheck5 = (obj, member, msg) => member.has(obj) || __typeError5("Cannot " + msg);
|
|
3498
|
+
var __privateGet5 = (obj, member, getter) => (__accessCheck5(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
3499
|
+
var __privateAdd5 = (obj, member, value) => member.has(obj) ? __typeError5("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
3500
|
+
var __privateSet3 = (obj, member, value, setter) => (__accessCheck5(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
3501
|
+
var __privateMethod2 = (obj, member, method) => (__accessCheck5(obj, member, "access private method"), method);
|
|
3502
|
+
function computeAggregateDimensions(primitiveScores, aggregates) {
|
|
3503
|
+
const result = { ...primitiveScores };
|
|
3504
|
+
for (const aggregateDimension in aggregates) {
|
|
3505
|
+
const aggregateScore = computeAggregateDimension(
|
|
3506
|
+
primitiveScores,
|
|
3507
|
+
aggregateDimension,
|
|
3508
|
+
aggregates,
|
|
3509
|
+
/* @__PURE__ */ new Set([aggregateDimension])
|
|
3510
|
+
);
|
|
3511
|
+
if (aggregateScore !== 0) {
|
|
3512
|
+
result[aggregateDimension] = aggregateScore;
|
|
3513
|
+
}
|
|
3514
|
+
}
|
|
3515
|
+
return result;
|
|
3516
|
+
}
|
|
3517
|
+
function computeAggregateDimension(primitiveScores, aggregateDimension, allAggregates, visitedDimensions) {
|
|
3093
3518
|
var _a;
|
|
3094
|
-
|
|
3519
|
+
let aggregateScore = 0;
|
|
3520
|
+
for (const input of allAggregates[aggregateDimension].inputs) {
|
|
3521
|
+
let currentScore = (_a = primitiveScores[input.dim]) != null ? _a : 0;
|
|
3522
|
+
if (!currentScore) {
|
|
3523
|
+
const aggRef = allAggregates[input.dim];
|
|
3524
|
+
if (aggRef) {
|
|
3525
|
+
if (visitedDimensions.has(input.dim)) {
|
|
3526
|
+
continue;
|
|
3527
|
+
}
|
|
3528
|
+
const newVisited = new Set(visitedDimensions);
|
|
3529
|
+
newVisited.add(input.dim);
|
|
3530
|
+
currentScore = computeAggregateDimension(primitiveScores, input.dim, allAggregates, newVisited);
|
|
3531
|
+
}
|
|
3532
|
+
}
|
|
3533
|
+
if (currentScore !== 0) {
|
|
3534
|
+
if (input.sign === "c") {
|
|
3535
|
+
aggregateScore = 0;
|
|
3536
|
+
break;
|
|
3537
|
+
} else if (input.sign === "-") {
|
|
3538
|
+
aggregateScore -= currentScore;
|
|
3539
|
+
} else {
|
|
3540
|
+
aggregateScore += currentScore;
|
|
3541
|
+
}
|
|
3542
|
+
}
|
|
3543
|
+
}
|
|
3544
|
+
return aggregateScore;
|
|
3545
|
+
}
|
|
3546
|
+
var ENR_SEPARATOR = "_";
|
|
3547
|
+
var _id;
|
|
3548
|
+
var SignalGoalEvaluator = class {
|
|
3549
|
+
constructor(options) {
|
|
3550
|
+
__privateAdd5(this, _id);
|
|
3551
|
+
__privateSet3(this, _id, options.id);
|
|
3552
|
+
}
|
|
3553
|
+
get id() {
|
|
3554
|
+
return __privateGet5(this, _id);
|
|
3555
|
+
}
|
|
3556
|
+
evaluate({ scores, quirks }) {
|
|
3557
|
+
const score = scores == null ? void 0 : scores[__privateGet5(this, _id)];
|
|
3558
|
+
const key = `goal_${__privateGet5(this, _id)}_triggered`;
|
|
3559
|
+
const hasGoalTriggered = (quirks == null ? void 0 : quirks[key]) === "1";
|
|
3095
3560
|
return {
|
|
3096
|
-
|
|
3097
|
-
|
|
3098
|
-
test
|
|
3561
|
+
key,
|
|
3562
|
+
triggered: typeof score === "number" && !hasGoalTriggered
|
|
3099
3563
|
};
|
|
3100
3564
|
}
|
|
3101
|
-
|
|
3102
|
-
|
|
3103
|
-
|
|
3104
|
-
|
|
3105
|
-
|
|
3106
|
-
|
|
3107
|
-
|
|
3108
|
-
|
|
3109
|
-
|
|
3565
|
+
};
|
|
3566
|
+
_id = /* @__PURE__ */ new WeakMap();
|
|
3567
|
+
var _evaluator;
|
|
3568
|
+
var _onLogMessage;
|
|
3569
|
+
var SignalInstance = class {
|
|
3570
|
+
constructor(data, evaluator, onLogMessage) {
|
|
3571
|
+
__privateAdd5(this, _evaluator);
|
|
3572
|
+
__privateAdd5(this, _onLogMessage);
|
|
3573
|
+
__publicField3(this, "signal");
|
|
3574
|
+
this.signal = data;
|
|
3575
|
+
__privateSet3(this, _evaluator, evaluator);
|
|
3576
|
+
__privateSet3(this, _onLogMessage, onLogMessage);
|
|
3577
|
+
}
|
|
3578
|
+
/** Computes storage update commands to take based on a state update and the signal's criteria */
|
|
3579
|
+
computeSignal(update, commands) {
|
|
3580
|
+
const isAtCap = update.scores[this.signal.id] >= this.signal.cap;
|
|
3581
|
+
if (isAtCap && this.signal.dur !== "t") {
|
|
3582
|
+
return;
|
|
3583
|
+
}
|
|
3584
|
+
const criteriaMatchUpdate = __privateGet5(this, _evaluator).evaluate(
|
|
3585
|
+
update,
|
|
3586
|
+
this.signal.crit,
|
|
3587
|
+
commands,
|
|
3588
|
+
this.signal,
|
|
3589
|
+
__privateGet5(this, _onLogMessage)
|
|
3590
|
+
);
|
|
3591
|
+
const scoreCommand = this.signal.dur === "s" || this.signal.dur === "t" ? "modscoreS" : "modscore";
|
|
3592
|
+
if (!criteriaMatchUpdate.changed) {
|
|
3593
|
+
return;
|
|
3594
|
+
}
|
|
3595
|
+
if (criteriaMatchUpdate.result) {
|
|
3596
|
+
commands.push({
|
|
3597
|
+
type: scoreCommand,
|
|
3598
|
+
data: { dimension: this.signal.id, delta: this.signal.str }
|
|
3599
|
+
});
|
|
3600
|
+
} else if (this.signal.dur === "t") {
|
|
3601
|
+
const sessionScore = update.visitor.sessionScores[this.signal.id];
|
|
3602
|
+
if (sessionScore) {
|
|
3603
|
+
commands.push({
|
|
3604
|
+
type: scoreCommand,
|
|
3605
|
+
data: { dimension: this.signal.id, delta: -sessionScore }
|
|
3606
|
+
});
|
|
3607
|
+
}
|
|
3608
|
+
}
|
|
3609
|
+
}
|
|
3610
|
+
};
|
|
3611
|
+
_evaluator = /* @__PURE__ */ new WeakMap();
|
|
3612
|
+
_onLogMessage = /* @__PURE__ */ new WeakMap();
|
|
3613
|
+
var rollForControlGroup = (value) => {
|
|
3614
|
+
let control = value;
|
|
3615
|
+
if (control >= 1) {
|
|
3616
|
+
control = control / 100;
|
|
3617
|
+
}
|
|
3618
|
+
return Math.random() < control;
|
|
3619
|
+
};
|
|
3620
|
+
var _mf;
|
|
3621
|
+
var _signalInstances;
|
|
3622
|
+
var _goalEvaluators;
|
|
3623
|
+
var _onLogMessage2;
|
|
3624
|
+
var ManifestInstance = class {
|
|
3625
|
+
constructor({
|
|
3626
|
+
manifest,
|
|
3627
|
+
evaluator = new GroupCriteriaEvaluator({}),
|
|
3628
|
+
onLogMessage = () => {
|
|
3629
|
+
}
|
|
3630
|
+
}) {
|
|
3631
|
+
__publicField3(this, "data");
|
|
3632
|
+
__privateAdd5(this, _mf);
|
|
3633
|
+
__privateAdd5(this, _signalInstances);
|
|
3634
|
+
__privateAdd5(this, _goalEvaluators, []);
|
|
3635
|
+
__privateAdd5(this, _onLogMessage2);
|
|
3636
|
+
var _a, _b, _c, _d, _e;
|
|
3637
|
+
__privateSet3(this, _mf, (_a = manifest.project) != null ? _a : {});
|
|
3638
|
+
this.data = manifest;
|
|
3639
|
+
__privateSet3(this, _signalInstances, Object.entries((_c = (_b = __privateGet5(this, _mf).pz) == null ? void 0 : _b.sig) != null ? _c : []).map(
|
|
3640
|
+
([id, signal]) => new SignalInstance({ ...signal, id }, evaluator, onLogMessage)
|
|
3641
|
+
));
|
|
3642
|
+
Object.entries((_e = (_d = __privateGet5(this, _mf).pz) == null ? void 0 : _d.sig) != null ? _e : []).forEach(([id, signal]) => {
|
|
3643
|
+
if (signal.conversion) {
|
|
3644
|
+
__privateGet5(this, _goalEvaluators).push(new SignalGoalEvaluator({ id, signal }));
|
|
3645
|
+
}
|
|
3646
|
+
});
|
|
3647
|
+
__privateSet3(this, _onLogMessage2, onLogMessage);
|
|
3648
|
+
}
|
|
3649
|
+
rollForControlGroup() {
|
|
3650
|
+
var _a;
|
|
3651
|
+
return rollForControlGroup(((_a = __privateGet5(this, _mf).pz) == null ? void 0 : _a.control) || 0);
|
|
3652
|
+
}
|
|
3653
|
+
getTest(name) {
|
|
3654
|
+
var _a;
|
|
3655
|
+
return (_a = __privateGet5(this, _mf).test) == null ? void 0 : _a[name];
|
|
3656
|
+
}
|
|
3657
|
+
computeSignals(update) {
|
|
3658
|
+
const commands = [];
|
|
3659
|
+
__privateGet5(this, _onLogMessage2).call(this, ["debug", 200, "GROUP"]);
|
|
3660
|
+
try {
|
|
3661
|
+
__privateGet5(this, _signalInstances).forEach((signal) => {
|
|
3662
|
+
__privateGet5(this, _onLogMessage2).call(this, ["debug", 201, "GROUP", signal.signal]);
|
|
3663
|
+
try {
|
|
3664
|
+
signal.computeSignal(update, commands);
|
|
3665
|
+
} finally {
|
|
3666
|
+
__privateGet5(this, _onLogMessage2).call(this, ["debug", 201, "ENDGROUP"]);
|
|
3667
|
+
}
|
|
3668
|
+
});
|
|
3669
|
+
} finally {
|
|
3670
|
+
__privateGet5(this, _onLogMessage2).call(this, ["debug", 200, "ENDGROUP"]);
|
|
3671
|
+
}
|
|
3672
|
+
return commands;
|
|
3673
|
+
}
|
|
3674
|
+
computeGoals(data) {
|
|
3675
|
+
const commands = [];
|
|
3676
|
+
__privateGet5(this, _goalEvaluators).forEach((evaluator) => {
|
|
3677
|
+
const { triggered, key } = evaluator.evaluate(data);
|
|
3678
|
+
if (triggered) {
|
|
3679
|
+
commands.push({
|
|
3680
|
+
type: "setgoal",
|
|
3681
|
+
data: {
|
|
3682
|
+
goal: evaluator.id
|
|
3683
|
+
}
|
|
3684
|
+
});
|
|
3685
|
+
commands.push({
|
|
3686
|
+
type: "setquirk",
|
|
3687
|
+
data: {
|
|
3688
|
+
key,
|
|
3689
|
+
value: "1"
|
|
3690
|
+
}
|
|
3691
|
+
});
|
|
3692
|
+
}
|
|
3693
|
+
});
|
|
3694
|
+
return commands;
|
|
3695
|
+
}
|
|
3696
|
+
/**
|
|
3697
|
+
* Computes aggregated scores based on other dimensions
|
|
3698
|
+
*/
|
|
3699
|
+
computeAggregateDimensions(primitiveScores) {
|
|
3700
|
+
var _a, _b;
|
|
3701
|
+
return computeAggregateDimensions(primitiveScores, (_b = (_a = __privateGet5(this, _mf).pz) == null ? void 0 : _a.agg) != null ? _b : {});
|
|
3702
|
+
}
|
|
3703
|
+
getDimensionByKey(scoreKey) {
|
|
3704
|
+
var _a, _b, _c, _d;
|
|
3705
|
+
const enrichmentIndex = scoreKey.indexOf(ENR_SEPARATOR);
|
|
3706
|
+
if (enrichmentIndex <= 0) {
|
|
3707
|
+
return (_b = (_a = __privateGet5(this, _mf).pz) == null ? void 0 : _a.sig) == null ? void 0 : _b[scoreKey];
|
|
3708
|
+
}
|
|
3709
|
+
return (_d = (_c = __privateGet5(this, _mf).pz) == null ? void 0 : _c.enr) == null ? void 0 : _d[scoreKey.substring(0, enrichmentIndex)];
|
|
3710
|
+
}
|
|
3711
|
+
getAggregateDimensionByKey(scoreKey) {
|
|
3712
|
+
var _a, _b;
|
|
3713
|
+
return (_b = (_a = __privateGet5(this, _mf).pz) == null ? void 0 : _a.agg) == null ? void 0 : _b[scoreKey];
|
|
3714
|
+
}
|
|
3715
|
+
};
|
|
3716
|
+
_mf = /* @__PURE__ */ new WeakMap();
|
|
3717
|
+
_signalInstances = /* @__PURE__ */ new WeakMap();
|
|
3718
|
+
_goalEvaluators = /* @__PURE__ */ new WeakMap();
|
|
3719
|
+
_onLogMessage2 = /* @__PURE__ */ new WeakMap();
|
|
3720
|
+
function isStringMatch(lhs, match) {
|
|
3721
|
+
var _a, _b, _c, _d, _e, _f;
|
|
3722
|
+
const type = (_a = match == null ? void 0 : match.op) != null ? _a : "=";
|
|
3723
|
+
if (match.op === "*") {
|
|
3724
|
+
return lhs !== null && typeof lhs !== "undefined";
|
|
3725
|
+
}
|
|
3726
|
+
if (match.op === "!*") {
|
|
3727
|
+
return lhs === null || typeof lhs === "undefined";
|
|
3728
|
+
}
|
|
3729
|
+
if (!("rhs" in match)) {
|
|
3730
|
+
throw new Error(`Match expression is required for match type ${type}`);
|
|
3731
|
+
}
|
|
3732
|
+
const caseSensitive = (_b = match.cs) != null ? _b : false;
|
|
3733
|
+
const localRhs = (caseSensitive ? lhs != null ? lhs : "" : caseDesensitize(lhs)).toString();
|
|
3734
|
+
const localLhs = (caseSensitive ? match.rhs : caseDesensitize(match.rhs)).toString();
|
|
3735
|
+
switch (type) {
|
|
3736
|
+
case "=":
|
|
3737
|
+
return localRhs === localLhs;
|
|
3738
|
+
case "!=":
|
|
3739
|
+
return localRhs !== localLhs;
|
|
3740
|
+
case "~":
|
|
3741
|
+
return (_c = localRhs.includes(localLhs)) != null ? _c : false;
|
|
3742
|
+
case "!~":
|
|
3743
|
+
return !((_d = localRhs.includes(localLhs)) != null ? _d : true);
|
|
3744
|
+
case "//":
|
|
3745
|
+
return new RegExp(match.rhs.toString(), caseSensitive ? "" : "i").test((_e = lhs == null ? void 0 : lhs.toString()) != null ? _e : "");
|
|
3746
|
+
case "!//":
|
|
3747
|
+
return !new RegExp(match.rhs.toString(), caseSensitive ? "" : "i").test((_f = lhs == null ? void 0 : lhs.toString()) != null ? _f : "");
|
|
3748
|
+
default:
|
|
3749
|
+
throw new Error(`Unknown match type ${type}.`);
|
|
3750
|
+
}
|
|
3751
|
+
}
|
|
3752
|
+
function explainStringMatch(lhs, match) {
|
|
3753
|
+
const cs = "cs" in match ? match.cs : false;
|
|
3754
|
+
return `'${cs ? lhs : lhs == null ? void 0 : lhs.toString().toUpperCase()}' ${explainStringMatchCriteria(match)}`;
|
|
3755
|
+
}
|
|
3756
|
+
function explainStringMatchCriteria(match) {
|
|
3757
|
+
if ("rhs" in match) {
|
|
3758
|
+
return `${match.op} '${match.cs ? match.rhs : match.rhs.toString().toUpperCase()}'`;
|
|
3759
|
+
}
|
|
3760
|
+
return `${match.op === "*" ? "exists" : "does not exist"}`;
|
|
3761
|
+
}
|
|
3762
|
+
function caseDesensitize(value) {
|
|
3763
|
+
var _a, _b;
|
|
3764
|
+
return (_b = (_a = value == null ? void 0 : value.toString()) == null ? void 0 : _a.toUpperCase()) != null ? _b : "";
|
|
3765
|
+
}
|
|
3766
|
+
var cookieEvaluator = ({ update, criteria, onLogMessage }) => {
|
|
3767
|
+
var _a, _b;
|
|
3768
|
+
if (criteria.type !== "CK") {
|
|
3769
|
+
return { result: false, changed: false };
|
|
3770
|
+
}
|
|
3771
|
+
const changed = !dequal(cleanCookies(update.state.cookies), cleanCookies((_a = update.previousState) == null ? void 0 : _a.cookies));
|
|
3772
|
+
const value = (_b = update.state.cookies) == null ? void 0 : _b[criteria.cookieName];
|
|
3773
|
+
const result = isStringMatch(value, criteria.match);
|
|
3774
|
+
const finalResult = { result, changed };
|
|
3775
|
+
onLogMessage == null ? void 0 : onLogMessage([
|
|
3776
|
+
"debug",
|
|
3777
|
+
203,
|
|
3778
|
+
{ criteria, result: finalResult, explanation: explainStringMatch(value, criteria.match) }
|
|
3779
|
+
]);
|
|
3780
|
+
return finalResult;
|
|
3781
|
+
};
|
|
3782
|
+
function cleanCookies(cookie) {
|
|
3783
|
+
if (!cookie) {
|
|
3784
|
+
return void 0;
|
|
3785
|
+
}
|
|
3786
|
+
if (!cookie.ufvd) {
|
|
3787
|
+
return cookie;
|
|
3788
|
+
}
|
|
3789
|
+
const { ufvd, ...rest } = cookie;
|
|
3790
|
+
return rest;
|
|
3791
|
+
}
|
|
3792
|
+
var currentPageEvaluator = ({ update, criteria, onLogMessage }) => {
|
|
3793
|
+
var _a, _b, _c;
|
|
3794
|
+
if (criteria.type !== "PV") {
|
|
3795
|
+
return { result: false, changed: false };
|
|
3796
|
+
}
|
|
3797
|
+
const value = (_a = update.state.url) == null ? void 0 : _a.pathname;
|
|
3798
|
+
const hasUrlChanged = !update.previousState || (value == null ? void 0 : value.toString()) !== ((_c = (_b = update.previousState.url) == null ? void 0 : _b.pathname) == null ? void 0 : _c.toString());
|
|
3799
|
+
const result = isStringMatch(value, criteria.path);
|
|
3800
|
+
const finalResult = { result, changed: hasUrlChanged };
|
|
3801
|
+
onLogMessage == null ? void 0 : onLogMessage([
|
|
3802
|
+
"debug",
|
|
3803
|
+
203,
|
|
3804
|
+
{ criteria, result: finalResult, explanation: explainStringMatch(value, criteria.path) }
|
|
3805
|
+
]);
|
|
3806
|
+
return finalResult;
|
|
3807
|
+
};
|
|
3808
|
+
var eventEvaluator = ({ update, criteria, onLogMessage }) => {
|
|
3809
|
+
var _a, _b, _c;
|
|
3810
|
+
if (criteria.type !== "EVT") {
|
|
3811
|
+
return { result: false, changed: false };
|
|
3812
|
+
}
|
|
3813
|
+
const result = (_b = (_a = update.state.events) == null ? void 0 : _a.some((event) => isStringMatch(event.event, criteria.event))) != null ? _b : false;
|
|
3814
|
+
const finalResult = { result, changed: result };
|
|
3815
|
+
onLogMessage == null ? void 0 : onLogMessage([
|
|
3816
|
+
"debug",
|
|
3817
|
+
203,
|
|
3818
|
+
{
|
|
3819
|
+
criteria,
|
|
3820
|
+
result: finalResult,
|
|
3821
|
+
explanation: `'${(_c = update.state.events) == null ? void 0 : _c.join("', '")}' ${explainStringMatchCriteria(criteria.event)}`
|
|
3822
|
+
}
|
|
3823
|
+
]);
|
|
3824
|
+
return finalResult;
|
|
3825
|
+
};
|
|
3826
|
+
function getEnrichmentVectorKey(category, value) {
|
|
3827
|
+
return `${category}${ENR_SEPARATOR}${value}`;
|
|
3828
|
+
}
|
|
3829
|
+
function isNumberMatch(lhs, match) {
|
|
3830
|
+
var _a;
|
|
3831
|
+
if (typeof lhs === "undefined" || lhs === null) {
|
|
3832
|
+
return false;
|
|
3833
|
+
}
|
|
3834
|
+
const lhsValue = Number(lhs);
|
|
3835
|
+
if (isNaN(lhsValue)) {
|
|
3836
|
+
return false;
|
|
3837
|
+
}
|
|
3838
|
+
switch ((_a = match == null ? void 0 : match.op) != null ? _a : "=") {
|
|
3839
|
+
case "=":
|
|
3840
|
+
return lhsValue === match.rhs;
|
|
3841
|
+
case "!=":
|
|
3842
|
+
return lhsValue !== match.rhs;
|
|
3843
|
+
case ">":
|
|
3844
|
+
return lhsValue > match.rhs;
|
|
3845
|
+
case "<":
|
|
3846
|
+
return lhsValue < match.rhs;
|
|
3847
|
+
default:
|
|
3848
|
+
console.warn(`Unknown match type ${match.op} is false.`);
|
|
3849
|
+
return false;
|
|
3850
|
+
}
|
|
3851
|
+
}
|
|
3852
|
+
function explainNumberMatch(lhs, match) {
|
|
3853
|
+
return `${lhs} ${explainNumberMatchCriteria(match)}`;
|
|
3854
|
+
}
|
|
3855
|
+
function explainNumberMatchCriteria(match) {
|
|
3856
|
+
return `${match.op} ${match.rhs}`;
|
|
3857
|
+
}
|
|
3858
|
+
var pageViewCountDimension = getEnrichmentVectorKey("$pvc", "v");
|
|
3859
|
+
var pageViewCountEvaluator = ({ update, criteria, commands, onLogMessage }) => {
|
|
3860
|
+
var _a, _b;
|
|
3861
|
+
if (criteria.type !== "PVC") {
|
|
3862
|
+
return { result: false, changed: false };
|
|
3863
|
+
}
|
|
3864
|
+
const hasUrlChanged = Boolean(
|
|
3865
|
+
update.state.url && (!update.previousState || ((_a = update.state.url) == null ? void 0 : _a.toString()) !== ((_b = update.previousState.url) == null ? void 0 : _b.toString()))
|
|
3866
|
+
);
|
|
3867
|
+
const existingValueNumber = update.visitor.sessionScores[pageViewCountDimension] || 0;
|
|
3868
|
+
const updatedCount = existingValueNumber + 1;
|
|
3869
|
+
const finalResult = { result: false, changed: hasUrlChanged };
|
|
3870
|
+
const hasExistingPageViewIncrementCommand = commands.some(
|
|
3871
|
+
(c) => c.type === "modscoreS" && c.data.dimension === pageViewCountDimension
|
|
3872
|
+
);
|
|
3873
|
+
if (hasUrlChanged && !hasExistingPageViewIncrementCommand) {
|
|
3874
|
+
commands.push({
|
|
3875
|
+
type: "modscoreS",
|
|
3876
|
+
data: {
|
|
3877
|
+
dimension: pageViewCountDimension,
|
|
3878
|
+
delta: 1
|
|
3879
|
+
}
|
|
3880
|
+
});
|
|
3881
|
+
}
|
|
3882
|
+
if (isNumberMatch(updatedCount, criteria.match)) {
|
|
3883
|
+
finalResult.result = true;
|
|
3884
|
+
}
|
|
3885
|
+
onLogMessage == null ? void 0 : onLogMessage([
|
|
3886
|
+
"debug",
|
|
3887
|
+
203,
|
|
3888
|
+
{ criteria, result: finalResult, explanation: explainNumberMatch(updatedCount, criteria.match) }
|
|
3889
|
+
]);
|
|
3890
|
+
return finalResult;
|
|
3891
|
+
};
|
|
3892
|
+
pageViewCountEvaluator.alwaysExecute = true;
|
|
3893
|
+
var queryStringEvaluator = ({ update, criteria, onLogMessage }) => {
|
|
3894
|
+
var _a, _b, _c, _d, _e;
|
|
3895
|
+
if (criteria.type !== "QS") {
|
|
3896
|
+
return { result: false, changed: false };
|
|
3897
|
+
}
|
|
3898
|
+
const hasQueryChanged = !update.previousState || ((_b = (_a = update.state.url) == null ? void 0 : _a.searchParams) == null ? void 0 : _b.toString()) !== ((_d = (_c = update.previousState.url) == null ? void 0 : _c.searchParams) == null ? void 0 : _d.toString());
|
|
3899
|
+
const value = (_e = update.state.url) == null ? void 0 : _e.searchParams.get(criteria.queryName);
|
|
3900
|
+
const result = isStringMatch(value, criteria.match);
|
|
3901
|
+
const finalResult = { result, changed: hasQueryChanged };
|
|
3902
|
+
onLogMessage == null ? void 0 : onLogMessage([
|
|
3903
|
+
"debug",
|
|
3904
|
+
203,
|
|
3905
|
+
{ criteria, result: finalResult, explanation: explainStringMatch(value, criteria.match) }
|
|
3906
|
+
]);
|
|
3907
|
+
return finalResult;
|
|
3908
|
+
};
|
|
3909
|
+
var quirkEvaluator = ({ update, criteria, signal, onLogMessage }) => {
|
|
3910
|
+
var _a;
|
|
3911
|
+
if (criteria.type !== "QK") {
|
|
3912
|
+
return { result: false, changed: false };
|
|
3913
|
+
}
|
|
3914
|
+
if (typeof document === "undefined" && update.scores[signal.id] > 0) {
|
|
3915
|
+
return { result: true, changed: false };
|
|
3916
|
+
}
|
|
3917
|
+
const visitorValue = update.visitor.quirks[criteria.key];
|
|
3918
|
+
const updateValue = (_a = update.state.quirks) == null ? void 0 : _a[criteria.key];
|
|
3919
|
+
const value = updateValue != null ? updateValue : visitorValue;
|
|
3920
|
+
const changed = Boolean(updateValue !== void 0 && visitorValue !== updateValue);
|
|
3921
|
+
const result = isStringMatch(value, criteria.match);
|
|
3922
|
+
const finalResult = { result, changed };
|
|
3923
|
+
onLogMessage == null ? void 0 : onLogMessage([
|
|
3924
|
+
"debug",
|
|
3925
|
+
203,
|
|
3926
|
+
{ criteria, result: finalResult, explanation: explainStringMatch(value, criteria.match) }
|
|
3927
|
+
]);
|
|
3928
|
+
return finalResult;
|
|
3929
|
+
};
|
|
3930
|
+
var _evaluators;
|
|
3931
|
+
var GroupCriteriaEvaluator = class {
|
|
3932
|
+
constructor(criteriaEvaluators) {
|
|
3933
|
+
__privateAdd5(this, _evaluators);
|
|
3934
|
+
__privateSet3(this, _evaluators, criteriaEvaluators);
|
|
3935
|
+
}
|
|
3936
|
+
evaluate(update, crit, commands, signal, onLogMessage) {
|
|
3937
|
+
const hasMultipleClauses = crit.clauses.length > 1;
|
|
3938
|
+
if (hasMultipleClauses) {
|
|
3939
|
+
onLogMessage == null ? void 0 : onLogMessage(["debug", 202, "GROUP", crit]);
|
|
3940
|
+
}
|
|
3941
|
+
try {
|
|
3942
|
+
const earlyExitEvaluatorResult = crit.op === "&" || !crit.op ? false : true;
|
|
3943
|
+
let earlyExitResult = null;
|
|
3944
|
+
let isAnyChanged = false;
|
|
3945
|
+
for (const criteria of crit.clauses) {
|
|
3946
|
+
let result;
|
|
3947
|
+
if (criteria.type === "G") {
|
|
3948
|
+
result = this.evaluate(update, criteria, commands, signal, onLogMessage);
|
|
3949
|
+
} else {
|
|
3950
|
+
const evaluator = __privateGet5(this, _evaluators)[criteria.type];
|
|
3951
|
+
if (earlyExitResult && !evaluator.alwaysExecute) {
|
|
3952
|
+
continue;
|
|
3953
|
+
}
|
|
3954
|
+
if (!evaluator) {
|
|
3955
|
+
throw new Error(`${criteria.type} signal criteria not registered`);
|
|
3956
|
+
}
|
|
3957
|
+
result = evaluator({ update, criteria, commands, signal, onLogMessage });
|
|
3958
|
+
}
|
|
3959
|
+
if (result.changed) {
|
|
3960
|
+
isAnyChanged = true;
|
|
3961
|
+
}
|
|
3962
|
+
if (!earlyExitResult && result.result === earlyExitEvaluatorResult) {
|
|
3963
|
+
earlyExitResult = { result: earlyExitEvaluatorResult, changed: isAnyChanged };
|
|
3964
|
+
}
|
|
3965
|
+
}
|
|
3966
|
+
const finalResult = earlyExitResult != null ? earlyExitResult : { result: !earlyExitEvaluatorResult, changed: isAnyChanged };
|
|
3967
|
+
if (hasMultipleClauses) {
|
|
3968
|
+
onLogMessage == null ? void 0 : onLogMessage(["debug", 204, finalResult]);
|
|
3969
|
+
}
|
|
3970
|
+
return finalResult;
|
|
3971
|
+
} finally {
|
|
3972
|
+
if (hasMultipleClauses) {
|
|
3973
|
+
onLogMessage == null ? void 0 : onLogMessage(["debug", 202, "ENDGROUP"]);
|
|
3974
|
+
}
|
|
3975
|
+
}
|
|
3976
|
+
}
|
|
3977
|
+
};
|
|
3978
|
+
_evaluators = /* @__PURE__ */ new WeakMap();
|
|
3979
|
+
function evaluateVariantMatch(variantId, match, vec, onLogMessage, quirks) {
|
|
3980
|
+
onLogMessage == null ? void 0 : onLogMessage(["info", 301, "GROUP", { id: variantId, op: match == null ? void 0 : match.op }]);
|
|
3981
|
+
let result;
|
|
3982
|
+
try {
|
|
3983
|
+
if (!(match == null ? void 0 : match.crit)) {
|
|
3984
|
+
onLogMessage == null ? void 0 : onLogMessage(["info", 302, { matched: true, description: "default variation" }]);
|
|
3985
|
+
result = true;
|
|
3986
|
+
} else if (!match.op || match.op === "&") {
|
|
3987
|
+
result = match.crit.every((c) => evaluateMatch(c, vec, quirks != null ? quirks : {}, onLogMessage));
|
|
3988
|
+
} else {
|
|
3989
|
+
result = match.crit.some((c) => evaluateMatch(c, vec, quirks != null ? quirks : {}, onLogMessage));
|
|
3990
|
+
}
|
|
3991
|
+
onLogMessage == null ? void 0 : onLogMessage(["info", 303, result]);
|
|
3992
|
+
} finally {
|
|
3993
|
+
onLogMessage == null ? void 0 : onLogMessage(["info", 301, "ENDGROUP"]);
|
|
3994
|
+
}
|
|
3995
|
+
return result;
|
|
3996
|
+
}
|
|
3997
|
+
function evaluateMatch(crit, vec, quirks, onLogMessage) {
|
|
3998
|
+
if ("t" in crit && crit.t === "q") {
|
|
3999
|
+
return evaluateQuirkMatch(crit, quirks, onLogMessage);
|
|
4000
|
+
} else {
|
|
4001
|
+
return evaluateDimensionMatch(crit, vec, onLogMessage);
|
|
4002
|
+
}
|
|
4003
|
+
}
|
|
4004
|
+
function evaluateDimensionMatch(crit, vec, onLogMessage) {
|
|
4005
|
+
var _a, _b;
|
|
4006
|
+
const { l: lhs, op } = crit;
|
|
4007
|
+
const lhsScore = (_a = vec[lhs]) != null ? _a : 0;
|
|
4008
|
+
if (op === "^") {
|
|
4009
|
+
const [cat] = lhs.split(ENR_SEPARATOR);
|
|
4010
|
+
let topVectorName = void 0;
|
|
4011
|
+
let topScore = 0;
|
|
4012
|
+
Object.keys(vec).forEach((vectorName) => {
|
|
4013
|
+
if (vectorName.startsWith(`${cat}${ENR_SEPARATOR}`)) {
|
|
4014
|
+
const score = vec[vectorName];
|
|
4015
|
+
if (score > topScore) {
|
|
4016
|
+
topVectorName = vectorName;
|
|
4017
|
+
topScore = score;
|
|
4018
|
+
}
|
|
4019
|
+
}
|
|
4020
|
+
});
|
|
4021
|
+
const result = topVectorName === lhs;
|
|
4022
|
+
onLogMessage == null ? void 0 : onLogMessage([
|
|
4023
|
+
"info",
|
|
4024
|
+
302,
|
|
4025
|
+
{
|
|
4026
|
+
matched: result,
|
|
4027
|
+
description: `${crit.l} has the highest score in the category`
|
|
4028
|
+
}
|
|
4029
|
+
]);
|
|
4030
|
+
return result;
|
|
4031
|
+
} else if (op === "+") {
|
|
4032
|
+
const result = Math.max(...Object.values(vec)) === lhsScore && lhsScore > 0;
|
|
4033
|
+
onLogMessage == null ? void 0 : onLogMessage([
|
|
4034
|
+
"info",
|
|
4035
|
+
302,
|
|
4036
|
+
{
|
|
4037
|
+
matched: result,
|
|
4038
|
+
description: `${crit.l} has the highest score`
|
|
4039
|
+
}
|
|
4040
|
+
]);
|
|
4041
|
+
return result;
|
|
4042
|
+
} else if (op === "-") {
|
|
4043
|
+
const result = Math.min(...Object.values(vec)) === lhsScore && lhsScore > 0;
|
|
4044
|
+
onLogMessage == null ? void 0 : onLogMessage([
|
|
4045
|
+
"info",
|
|
4046
|
+
302,
|
|
4047
|
+
{
|
|
4048
|
+
matched: result,
|
|
4049
|
+
description: `${crit.l} has the lowest non-zero score`
|
|
4050
|
+
}
|
|
4051
|
+
]);
|
|
4052
|
+
return result;
|
|
4053
|
+
}
|
|
4054
|
+
let rhsScore;
|
|
4055
|
+
if (crit.rDim) {
|
|
4056
|
+
rhsScore = vec[crit.rDim] || 0;
|
|
4057
|
+
} else {
|
|
4058
|
+
rhsScore = parseInt(crit.r, 10);
|
|
4059
|
+
}
|
|
4060
|
+
if (isNaN(rhsScore)) {
|
|
4061
|
+
onLogMessage == null ? void 0 : onLogMessage([
|
|
4062
|
+
"info",
|
|
4063
|
+
302,
|
|
4064
|
+
{
|
|
4065
|
+
matched: false,
|
|
4066
|
+
description: `${(_b = crit.rDim) != null ? _b : crit.r} has no score value`
|
|
4067
|
+
}
|
|
4068
|
+
]);
|
|
4069
|
+
return false;
|
|
4070
|
+
}
|
|
4071
|
+
if (op === ">") {
|
|
4072
|
+
const result = lhsScore > rhsScore;
|
|
4073
|
+
explainScore(onLogMessage, result, crit, lhsScore, rhsScore);
|
|
4074
|
+
return result;
|
|
4075
|
+
} else if (op === ">=") {
|
|
4076
|
+
const result = lhsScore >= rhsScore;
|
|
4077
|
+
explainScore(onLogMessage, result, crit, lhsScore, rhsScore);
|
|
4078
|
+
return result;
|
|
4079
|
+
} else if (op === "<") {
|
|
4080
|
+
const result = lhsScore < rhsScore;
|
|
4081
|
+
explainScore(onLogMessage, result, crit, lhsScore, rhsScore);
|
|
4082
|
+
return result;
|
|
4083
|
+
} else if (op === "<=") {
|
|
4084
|
+
const result = lhsScore <= rhsScore;
|
|
4085
|
+
explainScore(onLogMessage, result, crit, lhsScore, rhsScore);
|
|
4086
|
+
return result;
|
|
4087
|
+
} else if (op === "=") {
|
|
4088
|
+
const result = lhsScore === rhsScore;
|
|
4089
|
+
explainScore(onLogMessage, result, crit, lhsScore, rhsScore);
|
|
4090
|
+
return result;
|
|
4091
|
+
} else if (op === "!=") {
|
|
4092
|
+
const result = lhsScore !== rhsScore;
|
|
4093
|
+
explainScore(onLogMessage, result, crit, lhsScore, rhsScore);
|
|
4094
|
+
return result;
|
|
4095
|
+
} else {
|
|
4096
|
+
onLogMessage == null ? void 0 : onLogMessage([
|
|
4097
|
+
"error",
|
|
4098
|
+
302,
|
|
4099
|
+
{
|
|
4100
|
+
matched: false,
|
|
4101
|
+
description: `${crit.l} ${crit.op} ${crit.rDim ? `${crit.rDim}` : crit.r}: Unknown op ${crit.op}.`
|
|
4102
|
+
}
|
|
4103
|
+
]);
|
|
4104
|
+
return false;
|
|
4105
|
+
}
|
|
4106
|
+
}
|
|
4107
|
+
function evaluateQuirkMatch(crit, quirks, onLogMessage) {
|
|
4108
|
+
var _a;
|
|
4109
|
+
const { l: targetQuirk, op, r: targetValue } = crit;
|
|
4110
|
+
const targetQuirkValue = (_a = quirks[targetQuirk]) != null ? _a : "";
|
|
4111
|
+
if (op === "=") {
|
|
4112
|
+
const result = targetQuirkValue === targetValue;
|
|
4113
|
+
explainQuirk(onLogMessage, result, crit, targetQuirkValue);
|
|
4114
|
+
return result;
|
|
4115
|
+
} else if (op === "!=") {
|
|
4116
|
+
const result = targetQuirkValue !== targetValue;
|
|
4117
|
+
explainQuirk(onLogMessage, result, crit, targetQuirkValue);
|
|
4118
|
+
return result;
|
|
4119
|
+
} else {
|
|
4120
|
+
onLogMessage == null ? void 0 : onLogMessage([
|
|
4121
|
+
"error",
|
|
4122
|
+
302,
|
|
4123
|
+
{
|
|
4124
|
+
matched: false,
|
|
4125
|
+
description: `Quirk ${crit.l} ${crit.op} ${crit.r}: Unknown quirk op ${crit.op}.`
|
|
4126
|
+
}
|
|
4127
|
+
]);
|
|
4128
|
+
return false;
|
|
4129
|
+
}
|
|
4130
|
+
}
|
|
4131
|
+
function explainScore(onLogMessage, result, crit, lhsScore, rhsScore) {
|
|
4132
|
+
onLogMessage == null ? void 0 : onLogMessage([
|
|
4133
|
+
"info",
|
|
4134
|
+
302,
|
|
4135
|
+
{
|
|
4136
|
+
matched: result,
|
|
4137
|
+
description: `${crit.l}[${lhsScore}] ${crit.op} ${crit.rDim ? `${crit.rDim}[${rhsScore}]` : crit.r}`
|
|
4138
|
+
}
|
|
4139
|
+
]);
|
|
4140
|
+
}
|
|
4141
|
+
function explainQuirk(onLogMessage, result, crit, lhs) {
|
|
4142
|
+
onLogMessage == null ? void 0 : onLogMessage([
|
|
4143
|
+
"info",
|
|
4144
|
+
302,
|
|
4145
|
+
{
|
|
4146
|
+
matched: result,
|
|
4147
|
+
description: `Quirk ${crit.l}[${lhs}] ${crit.op} ${crit.r}`
|
|
4148
|
+
}
|
|
4149
|
+
]);
|
|
4150
|
+
}
|
|
4151
|
+
var TOP_DOWN_CRITERIA_PERSONALIZATION_ALGORITHM = "default";
|
|
4152
|
+
function topDownCriteriaPersonalizationSelectionAlgorithm({
|
|
4153
|
+
name,
|
|
4154
|
+
context,
|
|
4155
|
+
variations,
|
|
4156
|
+
take = 1,
|
|
4157
|
+
onLogMessage
|
|
4158
|
+
}) {
|
|
4159
|
+
var _a, _b, _c;
|
|
4160
|
+
onLogMessage == null ? void 0 : onLogMessage(["info", 300, "GROUP", { name, take }]);
|
|
4161
|
+
try {
|
|
4162
|
+
const variationMatches = [];
|
|
4163
|
+
const defaultVariations = [];
|
|
4164
|
+
const needsConsentToPersonalize = context.requireConsentForPersonalization;
|
|
4165
|
+
const personalizationAllowed = !needsConsentToPersonalize || context.storage.data.consent;
|
|
4166
|
+
for (const variation of variations) {
|
|
4167
|
+
const isInvalidFormat = variation.pz && (typeof variation.pz !== "object" || variation.pz === null || !("crit" in variation.pz && Array.isArray(variation.pz.crit)));
|
|
4168
|
+
let validVariation;
|
|
4169
|
+
if (isInvalidFormat) {
|
|
4170
|
+
const { pz, ...validParts } = variation;
|
|
4171
|
+
validVariation = validParts;
|
|
4172
|
+
} else {
|
|
4173
|
+
validVariation = variation;
|
|
4174
|
+
}
|
|
4175
|
+
if ((_a = validVariation.pz) == null ? void 0 : _a.crit.length) {
|
|
4176
|
+
if (personalizationAllowed && variationMatches.length !== take && evaluateVariantMatch(variation.id, validVariation.pz, context.scores, onLogMessage, context.quirks)) {
|
|
4177
|
+
variationMatches.push(validVariation);
|
|
4178
|
+
}
|
|
4179
|
+
} else {
|
|
4180
|
+
defaultVariations.push(validVariation);
|
|
4181
|
+
}
|
|
4182
|
+
}
|
|
4183
|
+
const result = [];
|
|
4184
|
+
for (let i = 0; i < variationMatches.length; i++) {
|
|
4185
|
+
let isControl = (_b = context.storage.data.controlGroup) != null ? _b : false;
|
|
4186
|
+
const variation = variationMatches[i];
|
|
4187
|
+
if (!isControl && typeof ((_c = variation.pz) == null ? void 0 : _c.control) === "number") {
|
|
4188
|
+
isControl = context.getPersonalizeVariantControl(name, i);
|
|
4189
|
+
if (typeof isControl === "undefined") {
|
|
4190
|
+
isControl = rollForControlGroup(variation.pz.control);
|
|
4191
|
+
context.storage.updateData([
|
|
4192
|
+
{
|
|
4193
|
+
type: "setpersonalizecontrol",
|
|
4194
|
+
data: {
|
|
4195
|
+
personlizationName: name,
|
|
4196
|
+
index: i,
|
|
4197
|
+
control: isControl
|
|
4198
|
+
}
|
|
4199
|
+
}
|
|
4200
|
+
]);
|
|
4201
|
+
}
|
|
4202
|
+
}
|
|
4203
|
+
let variantToAdd = variation;
|
|
4204
|
+
if (isControl) {
|
|
4205
|
+
const defaultReplacement = defaultVariations.shift();
|
|
4206
|
+
if (defaultReplacement) {
|
|
4207
|
+
variantToAdd = {
|
|
4208
|
+
...defaultReplacement,
|
|
4209
|
+
id: variation.id
|
|
4210
|
+
};
|
|
4211
|
+
} else {
|
|
4212
|
+
variantToAdd = void 0;
|
|
4213
|
+
}
|
|
4214
|
+
}
|
|
4215
|
+
if (variantToAdd) {
|
|
4216
|
+
result.push({ ...variantToAdd, control: isControl });
|
|
4217
|
+
}
|
|
4218
|
+
}
|
|
4219
|
+
while (result.length < take && defaultVariations.length) {
|
|
4220
|
+
result.push({ ...defaultVariations.shift(), control: false });
|
|
4221
|
+
}
|
|
4222
|
+
const personalized = result.some((v) => {
|
|
4223
|
+
var _a2;
|
|
4224
|
+
return (_a2 = v.pz) == null ? void 0 : _a2.crit.length;
|
|
4225
|
+
});
|
|
4226
|
+
return {
|
|
4227
|
+
personalized,
|
|
4228
|
+
variations: result
|
|
4229
|
+
};
|
|
4230
|
+
} finally {
|
|
4231
|
+
onLogMessage == null ? void 0 : onLogMessage(["info", 300, "ENDGROUP"]);
|
|
4232
|
+
}
|
|
4233
|
+
}
|
|
4234
|
+
var STRONGEST_SCORE_PERSONALIZATION_ALGORITHM = "ssc";
|
|
4235
|
+
function strongestScorePersonalizationSelectionAlgorithm({
|
|
4236
|
+
name,
|
|
4237
|
+
context,
|
|
4238
|
+
variations,
|
|
4239
|
+
take = 1,
|
|
4240
|
+
onLogMessage
|
|
4241
|
+
}) {
|
|
4242
|
+
var _a, _b;
|
|
4243
|
+
onLogMessage == null ? void 0 : onLogMessage(["info", 300, "GROUP", { name, take }]);
|
|
4244
|
+
try {
|
|
4245
|
+
const variationMatches = [];
|
|
4246
|
+
const defaultVariations = [];
|
|
4247
|
+
const needsConsentToPersonalize = context.requireConsentForPersonalization;
|
|
4248
|
+
const isInGlobalControlGroup = (_a = context.storage.data.controlGroup) != null ? _a : false;
|
|
4249
|
+
const personalizationAllowed = !needsConsentToPersonalize || context.storage.data.consent;
|
|
4250
|
+
let originalIndex = 0;
|
|
4251
|
+
for (const variation of variations) {
|
|
4252
|
+
const isInvalidFormat = variation.pz && typeof variation.pz !== "object";
|
|
4253
|
+
let validVariation;
|
|
4254
|
+
if (isInvalidFormat) {
|
|
4255
|
+
const { pz, ...validParts } = variation;
|
|
4256
|
+
validVariation = validParts;
|
|
4257
|
+
} else {
|
|
4258
|
+
validVariation = variation;
|
|
4259
|
+
}
|
|
4260
|
+
if ((_b = validVariation.pz) == null ? void 0 : _b.dim) {
|
|
4261
|
+
if (!personalizationAllowed) {
|
|
4262
|
+
continue;
|
|
4263
|
+
}
|
|
4264
|
+
const score = context.scores[validVariation.pz.dim];
|
|
4265
|
+
if (score === void 0 || score <= 0) {
|
|
4266
|
+
continue;
|
|
4267
|
+
}
|
|
4268
|
+
variationMatches.push({ variation: validVariation, score, originalIndex });
|
|
4269
|
+
originalIndex++;
|
|
4270
|
+
} else {
|
|
4271
|
+
defaultVariations.push(validVariation);
|
|
4272
|
+
}
|
|
4273
|
+
}
|
|
4274
|
+
variationMatches.sort((a, b) => {
|
|
4275
|
+
const scoreComparison = b.score - a.score;
|
|
4276
|
+
if (scoreComparison === 0) {
|
|
4277
|
+
return a.originalIndex - b.originalIndex;
|
|
4278
|
+
}
|
|
4279
|
+
return scoreComparison;
|
|
4280
|
+
});
|
|
4281
|
+
const result = [];
|
|
4282
|
+
for (let i = 0; i < variationMatches.length; i++) {
|
|
4283
|
+
const variationMatch = variationMatches[i];
|
|
4284
|
+
let variantToAdd = variationMatch.variation;
|
|
4285
|
+
if (i >= take) {
|
|
4286
|
+
continue;
|
|
4287
|
+
}
|
|
4288
|
+
if (isInGlobalControlGroup) {
|
|
4289
|
+
const defaultReplacement = defaultVariations.shift();
|
|
4290
|
+
if (defaultReplacement) {
|
|
4291
|
+
variantToAdd = {
|
|
4292
|
+
...defaultReplacement,
|
|
4293
|
+
id: variationMatch.variation.id
|
|
4294
|
+
};
|
|
4295
|
+
} else {
|
|
4296
|
+
variantToAdd = void 0;
|
|
4297
|
+
}
|
|
4298
|
+
}
|
|
4299
|
+
if (variantToAdd) {
|
|
4300
|
+
result.push({ ...variantToAdd, control: isInGlobalControlGroup });
|
|
4301
|
+
}
|
|
4302
|
+
}
|
|
4303
|
+
while (result.length < take && defaultVariations.length) {
|
|
4304
|
+
result.push({ ...defaultVariations.shift(), control: false });
|
|
4305
|
+
}
|
|
4306
|
+
return {
|
|
4307
|
+
personalized: variationMatches.length > 0 && !isInGlobalControlGroup,
|
|
4308
|
+
variations: result
|
|
4309
|
+
};
|
|
4310
|
+
} finally {
|
|
4311
|
+
onLogMessage == null ? void 0 : onLogMessage(["info", 300, "ENDGROUP"]);
|
|
4312
|
+
}
|
|
4313
|
+
}
|
|
4314
|
+
var normalizeVariationDistributions = (variations) => {
|
|
4315
|
+
const { values, total, missingDistribution } = variations.reduce(
|
|
4316
|
+
(previous, current) => {
|
|
4317
|
+
if (current.testDistribution) {
|
|
4318
|
+
previous.total += current.testDistribution;
|
|
4319
|
+
} else {
|
|
4320
|
+
++previous.missingDistribution;
|
|
4321
|
+
}
|
|
4322
|
+
previous.values.push(current.testDistribution);
|
|
4323
|
+
return previous;
|
|
4324
|
+
},
|
|
4325
|
+
{
|
|
4326
|
+
values: [],
|
|
4327
|
+
total: 0,
|
|
4328
|
+
missingDistribution: 0
|
|
4329
|
+
}
|
|
4330
|
+
);
|
|
4331
|
+
if (total > 100) {
|
|
4332
|
+
const autoScaleFactor = 100 / total;
|
|
4333
|
+
values.forEach((value, index) => {
|
|
4334
|
+
if (typeof value === "number") {
|
|
4335
|
+
values[index] = value * autoScaleFactor;
|
|
4336
|
+
}
|
|
4337
|
+
});
|
|
4338
|
+
} else if (total < 100) {
|
|
4339
|
+
const remainder = 100 - total;
|
|
4340
|
+
const missingSlice = remainder / missingDistribution;
|
|
4341
|
+
values.forEach((value, index) => {
|
|
4342
|
+
if (typeof value === "undefined") {
|
|
4343
|
+
values[index] = missingSlice;
|
|
4344
|
+
}
|
|
4345
|
+
});
|
|
4346
|
+
}
|
|
4347
|
+
return values;
|
|
4348
|
+
};
|
|
4349
|
+
var testVariations = ({
|
|
4350
|
+
name,
|
|
4351
|
+
context,
|
|
4352
|
+
variations,
|
|
4353
|
+
onLogMessage
|
|
4354
|
+
}) => {
|
|
4355
|
+
onLogMessage == null ? void 0 : onLogMessage(["info", 400, "GROUP", name]);
|
|
4356
|
+
try {
|
|
4357
|
+
let selectedVariant;
|
|
4358
|
+
const selectedVariantId = context.getTestVariantId(name);
|
|
4359
|
+
if (selectedVariantId === null) {
|
|
4360
|
+
onLogMessage == null ? void 0 : onLogMessage(["error", 401, name]);
|
|
4361
|
+
return { result: void 0, variantAssigned: false };
|
|
4362
|
+
}
|
|
4363
|
+
if (selectedVariantId) {
|
|
4364
|
+
selectedVariant = variations.find((variation) => variation.id === selectedVariantId);
|
|
4365
|
+
if (!selectedVariant) {
|
|
4366
|
+
onLogMessage == null ? void 0 : onLogMessage([
|
|
4367
|
+
"warn",
|
|
4368
|
+
402,
|
|
4369
|
+
{ missingVariant: selectedVariantId, variants: variations.map((v) => v.id) }
|
|
4370
|
+
]);
|
|
4371
|
+
}
|
|
4372
|
+
}
|
|
4373
|
+
if (!selectedVariant) {
|
|
4374
|
+
const distributions = normalizeVariationDistributions(variations);
|
|
4375
|
+
const random = Math.random() * 100;
|
|
4376
|
+
let distributionOffset = 0;
|
|
4377
|
+
selectedVariant = variations.find((variant, index) => {
|
|
4378
|
+
const distribution = distributions[index];
|
|
4379
|
+
if (random >= distributionOffset && random < distributionOffset + distribution) {
|
|
4380
|
+
return variant;
|
|
4381
|
+
}
|
|
4382
|
+
distributionOffset += distribution;
|
|
4383
|
+
});
|
|
4384
|
+
if (selectedVariant) {
|
|
4385
|
+
onLogMessage == null ? void 0 : onLogMessage(["info", 403, selectedVariant.id]);
|
|
4386
|
+
context.setTestVariantId(name, selectedVariant.id);
|
|
4387
|
+
}
|
|
4388
|
+
}
|
|
4389
|
+
if (selectedVariant) {
|
|
4390
|
+
onLogMessage == null ? void 0 : onLogMessage(["info", 404, selectedVariant.id]);
|
|
4391
|
+
if (selectedVariant.control === void 0) {
|
|
4392
|
+
selectedVariant.control = variations.findIndex((variation) => variation.id === selectedVariantId) === 0;
|
|
4393
|
+
}
|
|
4394
|
+
}
|
|
4395
|
+
return {
|
|
4396
|
+
result: selectedVariant,
|
|
4397
|
+
variantAssigned: !selectedVariantId
|
|
4398
|
+
};
|
|
4399
|
+
} finally {
|
|
4400
|
+
onLogMessage == null ? void 0 : onLogMessage(["info", 400, "ENDGROUP"]);
|
|
4401
|
+
}
|
|
4402
|
+
};
|
|
4403
|
+
var areCommandsEqual = (a, b) => {
|
|
4404
|
+
if (a.type !== b.type) {
|
|
4405
|
+
return false;
|
|
4406
|
+
}
|
|
4407
|
+
return dequal(a, b);
|
|
4408
|
+
};
|
|
4409
|
+
var SERVER_STATE_ID = "__UNIFORM_DATA__";
|
|
4410
|
+
var _data;
|
|
4411
|
+
var _initialData;
|
|
4412
|
+
var _mitt;
|
|
4413
|
+
var TransitionDataStore = class {
|
|
4414
|
+
constructor({ initialData }) {
|
|
4415
|
+
__privateAdd5(this, _data);
|
|
4416
|
+
__privateAdd5(this, _initialData);
|
|
4417
|
+
__privateAdd5(this, _mitt, mitt_default());
|
|
4418
|
+
__publicField3(this, "events", {
|
|
4419
|
+
on: __privateGet5(this, _mitt).on,
|
|
4420
|
+
off: __privateGet5(this, _mitt).off
|
|
4421
|
+
});
|
|
4422
|
+
if (initialData) {
|
|
4423
|
+
__privateSet3(this, _data, initialData);
|
|
4424
|
+
__privateSet3(this, _initialData, initialData);
|
|
4425
|
+
}
|
|
4426
|
+
}
|
|
4427
|
+
get data() {
|
|
4428
|
+
return __privateGet5(this, _data);
|
|
4429
|
+
}
|
|
4430
|
+
get initialData() {
|
|
4431
|
+
return __privateGet5(this, _initialData);
|
|
4432
|
+
}
|
|
4433
|
+
/**
|
|
4434
|
+
* Updates data in the transition storage.
|
|
4435
|
+
* @param commands - Commands to execute against existing stored value (event based stores)
|
|
4436
|
+
* @param computedValue - Pre-computed new value against existing value (object based stores)
|
|
4437
|
+
* @returns Resolved promise when the data has been updated
|
|
4438
|
+
*/
|
|
4439
|
+
updateData(commands, computedValue) {
|
|
4440
|
+
__privateSet3(this, _data, computedValue);
|
|
4441
|
+
return this.handleUpdateData(commands, computedValue);
|
|
4442
|
+
}
|
|
4443
|
+
/**
|
|
4444
|
+
* Deletes a visitor's stored data, forgetting them.
|
|
4445
|
+
* @param fromAllDevices - false: logout from this device ID. true: forget all data about the visitor and their identity.
|
|
4446
|
+
*/
|
|
4447
|
+
async delete(fromAllDevices) {
|
|
4448
|
+
__privateSet3(this, _data, void 0);
|
|
4449
|
+
await this.handleDelete(fromAllDevices);
|
|
4450
|
+
}
|
|
4451
|
+
signalAsyncDataUpdate(newScores) {
|
|
4452
|
+
if (dequal(this.data, newScores)) {
|
|
4453
|
+
return;
|
|
4454
|
+
}
|
|
4455
|
+
__privateSet3(this, _data, newScores);
|
|
4456
|
+
__privateGet5(this, _mitt).emit("dataUpdatedAsync", newScores);
|
|
4457
|
+
}
|
|
4458
|
+
/**
|
|
4459
|
+
* When we load on the client side after a server side rendering has occurred (server to client transition),
|
|
4460
|
+
* we can have a page script (ID: __UNIFORM_DATA__) that contains the computed visitor data from the SSR/edge render.
|
|
4461
|
+
* This data is injected into the first render to allow score syncing and the server to request commands be applied
|
|
4462
|
+
* to the client side data store.
|
|
4463
|
+
*/
|
|
4464
|
+
getClientTransitionState() {
|
|
4465
|
+
if (typeof document === "undefined") {
|
|
4466
|
+
return;
|
|
4467
|
+
}
|
|
4468
|
+
const matchesElement = document.getElementById(SERVER_STATE_ID);
|
|
4469
|
+
return (matchesElement == null ? void 0 : matchesElement.textContent) ? JSON.parse(matchesElement.textContent) : void 0;
|
|
4470
|
+
}
|
|
4471
|
+
};
|
|
4472
|
+
_data = /* @__PURE__ */ new WeakMap();
|
|
4473
|
+
_initialData = /* @__PURE__ */ new WeakMap();
|
|
4474
|
+
_mitt = /* @__PURE__ */ new WeakMap();
|
|
4475
|
+
var alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
4476
|
+
var b2s = alphabet.split("");
|
|
4477
|
+
var s2b = new Array(123);
|
|
4478
|
+
for (let i = 0; i < alphabet.length; i++) {
|
|
4479
|
+
s2b[alphabet.charCodeAt(i)] = i;
|
|
4480
|
+
}
|
|
4481
|
+
var ntob = (number) => {
|
|
4482
|
+
if (number < 0) return `-${ntob(-number)}`;
|
|
4483
|
+
let lo = number >>> 0;
|
|
4484
|
+
let hi = number / 4294967296 >>> 0;
|
|
4485
|
+
let right = "";
|
|
4486
|
+
while (hi > 0) {
|
|
4487
|
+
right = b2s[63 & lo] + right;
|
|
4488
|
+
lo >>>= 6;
|
|
4489
|
+
lo |= (63 & hi) << 26;
|
|
4490
|
+
hi >>>= 6;
|
|
4491
|
+
}
|
|
4492
|
+
let left = "";
|
|
4493
|
+
do {
|
|
4494
|
+
left = b2s[63 & lo] + left;
|
|
4495
|
+
lo >>>= 6;
|
|
4496
|
+
} while (lo > 0);
|
|
4497
|
+
return left + right;
|
|
4498
|
+
};
|
|
4499
|
+
var bton = (base64) => {
|
|
4500
|
+
let number = 0;
|
|
4501
|
+
const sign = base64.charAt(0) === "-" ? 1 : 0;
|
|
4502
|
+
for (let i = sign; i < base64.length; i++) {
|
|
4503
|
+
number = number * 64 + s2b[base64.charCodeAt(i)];
|
|
4504
|
+
}
|
|
4505
|
+
return sign ? -number : number;
|
|
4506
|
+
};
|
|
4507
|
+
var ssr = typeof document === "undefined";
|
|
4508
|
+
var UNIFORM_DEFAULT_COOKIE_NAME = "ufvd";
|
|
4509
|
+
var UNIFORM_DEFAULT_QUIRK_COOKIE_NAME = `ufvdqk`;
|
|
4510
|
+
var _cookieName;
|
|
4511
|
+
var _quirkCookieName;
|
|
4512
|
+
var _cookieAttributes;
|
|
4513
|
+
var _quirksEnabled;
|
|
4514
|
+
var CookieTransitionDataStore = class extends TransitionDataStore {
|
|
4515
|
+
constructor({
|
|
4516
|
+
serverCookieValue,
|
|
4517
|
+
experimental_quirksEnabled,
|
|
4518
|
+
quirkCookieValue,
|
|
4519
|
+
quirkCookieName = UNIFORM_DEFAULT_QUIRK_COOKIE_NAME,
|
|
4520
|
+
cookieName = UNIFORM_DEFAULT_COOKIE_NAME,
|
|
4521
|
+
cookieAttributes = { sameSite: "lax" }
|
|
4522
|
+
}) {
|
|
4523
|
+
super({
|
|
4524
|
+
initialData: ssr ? parseScoreCookie(serverCookieValue, experimental_quirksEnabled ? quirkCookieValue : void 0) : void 0
|
|
4525
|
+
});
|
|
4526
|
+
__privateAdd5(this, _cookieName);
|
|
4527
|
+
__privateAdd5(this, _quirkCookieName);
|
|
4528
|
+
__privateAdd5(this, _cookieAttributes);
|
|
4529
|
+
__privateAdd5(this, _quirksEnabled);
|
|
4530
|
+
__privateSet3(this, _cookieName, cookieName);
|
|
4531
|
+
__privateSet3(this, _cookieAttributes, cookieAttributes);
|
|
4532
|
+
__privateSet3(this, _quirkCookieName, quirkCookieName);
|
|
4533
|
+
__privateSet3(this, _quirksEnabled, experimental_quirksEnabled || false);
|
|
4534
|
+
}
|
|
4535
|
+
handleDelete() {
|
|
4536
|
+
if (ssr) return Promise.resolve();
|
|
4537
|
+
api.remove(__privateGet5(this, _cookieName));
|
|
4538
|
+
return Promise.resolve();
|
|
4539
|
+
}
|
|
4540
|
+
async handleUpdateData(_, computedValue) {
|
|
4541
|
+
if (ssr) return;
|
|
4542
|
+
if (computedValue.consent) {
|
|
4543
|
+
api.set(__privateGet5(this, _cookieName), serializeCookie(computedValue), __privateGet5(this, _cookieAttributes));
|
|
4544
|
+
if (__privateGet5(this, _quirksEnabled) && Object.keys(computedValue.quirks || {}).length) {
|
|
4545
|
+
const quirkCookieValue = serializeQuirks(computedValue.quirks || {});
|
|
4546
|
+
api.set(__privateGet5(this, _quirkCookieName), quirkCookieValue, __privateGet5(this, _cookieAttributes));
|
|
4547
|
+
}
|
|
4548
|
+
} else {
|
|
4549
|
+
api.remove(__privateGet5(this, _cookieName));
|
|
4550
|
+
if (__privateGet5(this, _quirksEnabled)) {
|
|
4551
|
+
api.remove(__privateGet5(this, _quirkCookieName));
|
|
4552
|
+
}
|
|
4553
|
+
}
|
|
4554
|
+
}
|
|
4555
|
+
};
|
|
4556
|
+
_cookieName = /* @__PURE__ */ new WeakMap();
|
|
4557
|
+
_quirkCookieName = /* @__PURE__ */ new WeakMap();
|
|
4558
|
+
_cookieAttributes = /* @__PURE__ */ new WeakMap();
|
|
4559
|
+
_quirksEnabled = /* @__PURE__ */ new WeakMap();
|
|
4560
|
+
var TYPE_SEP = "~";
|
|
4561
|
+
var PAIR_SEP = "!";
|
|
4562
|
+
var KV_SEP = "-";
|
|
4563
|
+
var QUIRK_SEP = "!!";
|
|
4564
|
+
function parseScoreCookie(cookieValue, quirkCookieValue) {
|
|
4565
|
+
if (!cookieValue) return;
|
|
4566
|
+
const types = cookieValue.split(TYPE_SEP);
|
|
4567
|
+
if (types.length > 5) return;
|
|
4568
|
+
const [abTestData, sessionScores, visitorScores, controlGroup, personalizeVariants] = types;
|
|
4569
|
+
const data = {
|
|
4570
|
+
// this is true since we're reading a cookie, which wouldn't exist if consent wasn't given
|
|
4571
|
+
consent: true,
|
|
4572
|
+
sessionScores: decodeCookieType(parseCookieScores(sessionScores)),
|
|
4573
|
+
scores: decodeCookieType(parseCookieScores(visitorScores)),
|
|
4574
|
+
tests: parseCookieType(abTestData),
|
|
4575
|
+
controlGroup: controlGroup === "1",
|
|
4576
|
+
personalizeVariants: decodePersonalizeVariants(personalizeVariants)
|
|
4577
|
+
};
|
|
4578
|
+
if (quirkCookieValue) {
|
|
4579
|
+
data.quirks = parseQuirkCookie(quirkCookieValue);
|
|
4580
|
+
}
|
|
4581
|
+
return data;
|
|
4582
|
+
}
|
|
4583
|
+
function parseQuirkCookie(quirkCookieValue) {
|
|
4584
|
+
const pairs = quirkCookieValue.split(QUIRK_SEP);
|
|
4585
|
+
const splitPairs = pairs.map((pair) => {
|
|
4586
|
+
const sep = pair.indexOf(KV_SEP);
|
|
4587
|
+
if (sep === -1) {
|
|
4588
|
+
return void 0;
|
|
4589
|
+
}
|
|
4590
|
+
return [pair.slice(0, sep), pair.slice(sep + 1)];
|
|
4591
|
+
});
|
|
4592
|
+
const areAllPairsValid = splitPairs.every((pair) => pair !== void 0);
|
|
4593
|
+
if (!areAllPairsValid) {
|
|
4594
|
+
return {};
|
|
4595
|
+
}
|
|
4596
|
+
return splitPairs.reduce((acc, cur) => {
|
|
4597
|
+
const [key, value] = cur;
|
|
4598
|
+
acc[key] = value;
|
|
4599
|
+
return acc;
|
|
4600
|
+
}, {});
|
|
4601
|
+
}
|
|
4602
|
+
function parseCookieScores(type) {
|
|
4603
|
+
if (!type) {
|
|
4604
|
+
return {};
|
|
4605
|
+
}
|
|
4606
|
+
const pairs = type.split(PAIR_SEP).map((pair) => pair.split(KV_SEP));
|
|
4607
|
+
return pairs.reduce((acc, cur) => {
|
|
4608
|
+
if (cur.length < 2) return acc;
|
|
4609
|
+
const key = cur.slice(0, -1).join(KV_SEP);
|
|
4610
|
+
acc[key] = cur[cur.length - 1];
|
|
4611
|
+
return acc;
|
|
4612
|
+
}, {});
|
|
4613
|
+
}
|
|
4614
|
+
function parseCookieType(type) {
|
|
4615
|
+
if (!type) {
|
|
4616
|
+
return {};
|
|
4617
|
+
}
|
|
4618
|
+
const pairs = type.split(PAIR_SEP).map((pair) => pair.split(KV_SEP));
|
|
4619
|
+
return pairs.reduce((acc, cur) => {
|
|
4620
|
+
if (cur.length < 2) return acc;
|
|
4621
|
+
acc[cur[0]] = cur.slice(1).join("-");
|
|
4622
|
+
return acc;
|
|
4623
|
+
}, {});
|
|
4624
|
+
}
|
|
4625
|
+
function decodeCookieType(type) {
|
|
4626
|
+
return Object.entries(type).reduce((acc, [key, value]) => {
|
|
4627
|
+
acc[key] = bton(value);
|
|
4628
|
+
return acc;
|
|
4629
|
+
}, {});
|
|
4630
|
+
}
|
|
4631
|
+
function serializeCookie(data) {
|
|
4632
|
+
return [
|
|
4633
|
+
serializeCookieType(data.tests),
|
|
4634
|
+
serializeCookieType(encodeCookieType(data.sessionScores)),
|
|
4635
|
+
serializeCookieType(encodeCookieType(data.scores)),
|
|
4636
|
+
data.controlGroup ? "1" : "0",
|
|
4637
|
+
serializePersonalizeVariants(data)
|
|
4638
|
+
].join(TYPE_SEP);
|
|
4639
|
+
}
|
|
4640
|
+
function serializePersonalizeVariants({
|
|
4641
|
+
personalizeVariants
|
|
4642
|
+
}) {
|
|
4643
|
+
const data = {};
|
|
4644
|
+
if (typeof personalizeVariants === "object") {
|
|
4645
|
+
Object.keys(personalizeVariants).forEach((personalizationName) => {
|
|
4646
|
+
const results = [];
|
|
4647
|
+
const variants = personalizeVariants[personalizationName];
|
|
4648
|
+
variants.forEach((variant) => {
|
|
4649
|
+
results.push(`${variant.index}:${variant.control ? "1" : "0"}`);
|
|
4650
|
+
});
|
|
4651
|
+
data[personalizationName] = results.join(",");
|
|
4652
|
+
});
|
|
4653
|
+
}
|
|
4654
|
+
const serialized = serializeCookieType(data);
|
|
4655
|
+
return serialized;
|
|
4656
|
+
}
|
|
4657
|
+
function decodePersonalizeVariants(data) {
|
|
4658
|
+
const parsed = parseCookieType(data);
|
|
4659
|
+
const keys = Object.keys(parsed);
|
|
4660
|
+
if (!keys.length) {
|
|
4661
|
+
return void 0;
|
|
4662
|
+
}
|
|
4663
|
+
const results = {};
|
|
4664
|
+
Object.keys(parsed).forEach((k) => {
|
|
4665
|
+
const variants = parsed[k].split(",");
|
|
4666
|
+
const key = decodeURIComponent(k);
|
|
4667
|
+
results[key] = variants.map((variant) => {
|
|
4668
|
+
const [index, control] = variant.split(":");
|
|
4669
|
+
return {
|
|
4670
|
+
index: parseInt(index, 10),
|
|
4671
|
+
control: control === "1"
|
|
4672
|
+
};
|
|
4673
|
+
});
|
|
4674
|
+
});
|
|
4675
|
+
return results;
|
|
4676
|
+
}
|
|
4677
|
+
function encodeCookieType(type) {
|
|
4678
|
+
return Object.entries(type).reduce((acc, [key, value]) => {
|
|
4679
|
+
acc[key] = ntob(value);
|
|
4680
|
+
return acc;
|
|
4681
|
+
}, {});
|
|
4682
|
+
}
|
|
4683
|
+
function serializeCookieType(type) {
|
|
4684
|
+
return Object.entries(type).map((kv) => kv.join(KV_SEP)).join(PAIR_SEP);
|
|
4685
|
+
}
|
|
4686
|
+
function serializeQuirks(quirks) {
|
|
4687
|
+
return Object.entries(quirks).map((kv) => kv.join(KV_SEP)).join(QUIRK_SEP);
|
|
4688
|
+
}
|
|
4689
|
+
var _EdgeTransitionDataStore_instances;
|
|
4690
|
+
var fetchData_fn;
|
|
4691
|
+
_EdgeTransitionDataStore_instances = /* @__PURE__ */ new WeakSet();
|
|
4692
|
+
fetchData_fn = async function() {
|
|
4693
|
+
const serviceData = await new Promise((resolve) => {
|
|
4694
|
+
setTimeout(() => {
|
|
4695
|
+
resolve(void 0);
|
|
4696
|
+
}, 2e3);
|
|
4697
|
+
});
|
|
4698
|
+
if (serviceData) {
|
|
4699
|
+
this.signalAsyncDataUpdate(serviceData);
|
|
4700
|
+
}
|
|
4701
|
+
};
|
|
4702
|
+
var emptyVisitorData = () => ({
|
|
4703
|
+
quirks: {},
|
|
4704
|
+
scores: {},
|
|
4705
|
+
sessionScores: {},
|
|
4706
|
+
tests: {},
|
|
4707
|
+
goals: {},
|
|
4708
|
+
consent: false,
|
|
4709
|
+
controlGroup: false,
|
|
4710
|
+
personalizeVariants: {}
|
|
4711
|
+
});
|
|
4712
|
+
var clone = (0, import_rfdc.default)();
|
|
4713
|
+
function applyCommandsToData(commands, state) {
|
|
4714
|
+
const newData = state ? clone(state) : emptyVisitorData();
|
|
4715
|
+
commands.forEach((command) => {
|
|
4716
|
+
var _a, _b, _c;
|
|
4717
|
+
switch (command.type) {
|
|
4718
|
+
case "consent":
|
|
4719
|
+
newData.consent = command.data;
|
|
4720
|
+
break;
|
|
4721
|
+
case "setquirk":
|
|
4722
|
+
newData.quirks[command.data.key] = command.data.value;
|
|
4723
|
+
break;
|
|
4724
|
+
case "settest":
|
|
4725
|
+
newData.tests[command.data.test] = command.data.variant;
|
|
4726
|
+
break;
|
|
4727
|
+
case "modscore":
|
|
4728
|
+
const delta = Number(command.data.delta);
|
|
4729
|
+
if (isNaN(delta)) {
|
|
4730
|
+
throw new Error("Non-number delta received");
|
|
4731
|
+
}
|
|
4732
|
+
const existing = (_a = newData.scores[command.data.dimension]) != null ? _a : 0;
|
|
4733
|
+
newData.scores[command.data.dimension] = existing + delta;
|
|
4734
|
+
break;
|
|
4735
|
+
case "modscoreS":
|
|
4736
|
+
const deltaS = Number(command.data.delta);
|
|
4737
|
+
if (isNaN(deltaS)) {
|
|
4738
|
+
throw new Error("Non-number delta received");
|
|
4739
|
+
}
|
|
4740
|
+
const existingS = (_b = newData.sessionScores[command.data.dimension]) != null ? _b : 0;
|
|
4741
|
+
newData.sessionScores[command.data.dimension] = existingS + deltaS;
|
|
4742
|
+
break;
|
|
4743
|
+
case "identify":
|
|
4744
|
+
break;
|
|
4745
|
+
case "setcontrol":
|
|
4746
|
+
newData.controlGroup = command.data;
|
|
4747
|
+
break;
|
|
4748
|
+
case "setpersonalizecontrol":
|
|
4749
|
+
if (!newData.personalizeVariants) {
|
|
4750
|
+
newData.personalizeVariants = {};
|
|
4751
|
+
}
|
|
4752
|
+
if (!newData.personalizeVariants[command.data.personlizationName]) {
|
|
4753
|
+
newData.personalizeVariants[command.data.personlizationName] = [];
|
|
4754
|
+
}
|
|
4755
|
+
const existingDef = newData.personalizeVariants[command.data.personlizationName].find(
|
|
4756
|
+
(i) => i.index === command.data.index
|
|
4757
|
+
);
|
|
4758
|
+
if (!existingDef) {
|
|
4759
|
+
newData.personalizeVariants[command.data.personlizationName].push({
|
|
4760
|
+
index: command.data.index,
|
|
4761
|
+
control: command.data.control
|
|
4762
|
+
});
|
|
4763
|
+
} else {
|
|
4764
|
+
console.warn("Overwriting existing control group definition is not allowed");
|
|
4765
|
+
}
|
|
4766
|
+
break;
|
|
4767
|
+
case "setgoal":
|
|
4768
|
+
newData.goals = (_c = newData.goals) != null ? _c : {};
|
|
4769
|
+
newData.goals[command.data.goal] = true;
|
|
4770
|
+
break;
|
|
4771
|
+
default:
|
|
4772
|
+
throw new Error(`Unknown command`);
|
|
4773
|
+
}
|
|
4774
|
+
});
|
|
4775
|
+
return newData;
|
|
4776
|
+
}
|
|
4777
|
+
var _LocalStorage_instances;
|
|
4778
|
+
var key_fn;
|
|
4779
|
+
var LocalStorage = class {
|
|
4780
|
+
constructor(partitionKey) {
|
|
4781
|
+
__publicField3(this, "partitionKey", partitionKey);
|
|
4782
|
+
__privateAdd5(this, _LocalStorage_instances);
|
|
4783
|
+
__publicField3(this, "inMemoryFallback", {});
|
|
4784
|
+
__publicField3(this, "hasLocalStorageObject", typeof document !== "undefined" && typeof localStorage !== "undefined");
|
|
4785
|
+
}
|
|
4786
|
+
get(key) {
|
|
4787
|
+
const keyValue = __privateMethod2(this, _LocalStorage_instances, key_fn).call(this, key);
|
|
4788
|
+
const fallbackValue = this.inMemoryFallback[keyValue];
|
|
4789
|
+
if (!this.hasLocalStorageObject || fallbackValue) {
|
|
4790
|
+
return fallbackValue;
|
|
4791
|
+
}
|
|
4792
|
+
try {
|
|
4793
|
+
const value = localStorage.getItem(keyValue);
|
|
4794
|
+
return value ? JSON.parse(value) : void 0;
|
|
4795
|
+
} catch (e) {
|
|
4796
|
+
return fallbackValue;
|
|
4797
|
+
}
|
|
4798
|
+
}
|
|
4799
|
+
set(key, value, storageConsent) {
|
|
4800
|
+
const keyValue = __privateMethod2(this, _LocalStorage_instances, key_fn).call(this, key);
|
|
4801
|
+
this.inMemoryFallback[keyValue] = value;
|
|
4802
|
+
if (!this.hasLocalStorageObject || !storageConsent) {
|
|
4803
|
+
return;
|
|
4804
|
+
}
|
|
4805
|
+
try {
|
|
4806
|
+
localStorage.setItem(keyValue, JSON.stringify(value));
|
|
4807
|
+
} catch (e) {
|
|
4808
|
+
console.warn(e);
|
|
4809
|
+
}
|
|
4810
|
+
}
|
|
4811
|
+
delete(key, leaveInMemory) {
|
|
4812
|
+
const keyValue = __privateMethod2(this, _LocalStorage_instances, key_fn).call(this, key);
|
|
4813
|
+
if (!leaveInMemory) {
|
|
4814
|
+
delete this.inMemoryFallback[keyValue];
|
|
4815
|
+
}
|
|
4816
|
+
try {
|
|
4817
|
+
localStorage.removeItem(keyValue);
|
|
4818
|
+
} catch (e) {
|
|
4819
|
+
}
|
|
4820
|
+
}
|
|
4821
|
+
};
|
|
4822
|
+
_LocalStorage_instances = /* @__PURE__ */ new WeakSet();
|
|
4823
|
+
key_fn = function(key) {
|
|
4824
|
+
return this.partitionKey ? `${this.partitionKey}.${key}` : key;
|
|
4825
|
+
};
|
|
4826
|
+
var STORAGE_KEY = "ufvisitor";
|
|
4827
|
+
var _mitt2;
|
|
4828
|
+
var _persist;
|
|
4829
|
+
var _visitTimeout;
|
|
4830
|
+
var _options;
|
|
4831
|
+
var _VisitorDataStore_instances;
|
|
4832
|
+
var currentData_get;
|
|
4833
|
+
var replaceData_fn;
|
|
4834
|
+
var setVisitTimeout_fn;
|
|
4835
|
+
var isExpired_fn;
|
|
4836
|
+
var handleCaps_fn;
|
|
4837
|
+
var defaultData_fn;
|
|
4838
|
+
var VisitorDataStore = class {
|
|
4839
|
+
constructor(options) {
|
|
4840
|
+
__privateAdd5(this, _VisitorDataStore_instances);
|
|
4841
|
+
__privateAdd5(this, _mitt2, mitt_default());
|
|
4842
|
+
__privateAdd5(this, _persist);
|
|
4843
|
+
__privateAdd5(this, _visitTimeout);
|
|
4844
|
+
__privateAdd5(this, _options);
|
|
4845
|
+
__publicField3(this, "events", {
|
|
4846
|
+
on: __privateGet5(this, _mitt2).on,
|
|
4847
|
+
off: __privateGet5(this, _mitt2).off
|
|
4848
|
+
});
|
|
4849
|
+
__privateSet3(this, _options, options);
|
|
4850
|
+
__privateSet3(this, _persist, new LocalStorage(options.partitionKey));
|
|
4851
|
+
if (!__privateGet5(this, _VisitorDataStore_instances, currentData_get)) {
|
|
4852
|
+
__privateMethod2(this, _VisitorDataStore_instances, replaceData_fn).call(this, __privateMethod2(this, _VisitorDataStore_instances, defaultData_fn).call(this), true);
|
|
4853
|
+
}
|
|
4854
|
+
if (options.transitionStore) {
|
|
4855
|
+
const serverToClientTransitionState = options.transitionStore.getClientTransitionState();
|
|
4856
|
+
if (serverToClientTransitionState && options.onServerTransitionReceived) {
|
|
4857
|
+
options.onServerTransitionReceived(serverToClientTransitionState);
|
|
4858
|
+
}
|
|
4859
|
+
options.transitionStore.events.on("dataUpdatedAsync", (data) => {
|
|
4860
|
+
__privateMethod2(this, _VisitorDataStore_instances, replaceData_fn).call(this, {
|
|
4861
|
+
...__privateGet5(this, _VisitorDataStore_instances, currentData_get).visitorData,
|
|
4862
|
+
...data
|
|
4863
|
+
});
|
|
4864
|
+
});
|
|
4865
|
+
const transitionData = options.transitionStore.data;
|
|
4866
|
+
if (transitionData) {
|
|
4867
|
+
__privateMethod2(this, _VisitorDataStore_instances, replaceData_fn).call(
|
|
4868
|
+
this,
|
|
4869
|
+
// we know _currentData is not empty because we inited it above if it was
|
|
4870
|
+
{ ...__privateGet5(this, _VisitorDataStore_instances, currentData_get).visitorData, ...transitionData },
|
|
4871
|
+
true
|
|
4872
|
+
);
|
|
4873
|
+
}
|
|
4874
|
+
}
|
|
4875
|
+
}
|
|
4876
|
+
/** Gets the current visitor data. This property is always up to date. */
|
|
4877
|
+
get data() {
|
|
4878
|
+
var _a, _b, _c;
|
|
4879
|
+
const data = (_a = __privateGet5(this, _VisitorDataStore_instances, currentData_get)) != null ? _a : { visitorData: __privateMethod2(this, _VisitorDataStore_instances, defaultData_fn).call(this), updated: (/* @__PURE__ */ new Date()).getTime() };
|
|
4880
|
+
if (__privateMethod2(this, _VisitorDataStore_instances, isExpired_fn).call(this, data)) {
|
|
4881
|
+
const { sessionScores, ...newData } = data.visitorData;
|
|
4882
|
+
__privateMethod2(this, _VisitorDataStore_instances, replaceData_fn).call(this, { ...newData, sessionScores: {} });
|
|
4883
|
+
(_c = (_b = __privateGet5(this, _options)).onLogMessage) == null ? void 0 : _c.call(_b, ["info", 120]);
|
|
4884
|
+
return __privateGet5(this, _VisitorDataStore_instances, currentData_get).visitorData;
|
|
4885
|
+
}
|
|
4886
|
+
return data.visitorData;
|
|
4887
|
+
}
|
|
4888
|
+
get decayEnabled() {
|
|
4889
|
+
return !!__privateGet5(this, _options).decay;
|
|
4890
|
+
}
|
|
4891
|
+
get options() {
|
|
4892
|
+
return __privateGet5(this, _options);
|
|
4893
|
+
}
|
|
4894
|
+
/** Push data update command(s) into the visitor data */
|
|
4895
|
+
async updateData(commands) {
|
|
4896
|
+
var _a, _b, _c;
|
|
4897
|
+
if (commands.length === 0) {
|
|
4898
|
+
return;
|
|
4899
|
+
}
|
|
4900
|
+
(_b = (_a = __privateGet5(this, _options)).onLogMessage) == null ? void 0 : _b.call(_a, ["debug", 101, commands]);
|
|
4901
|
+
const newData = applyCommandsToData(commands, this.data);
|
|
4902
|
+
if (commands.some((c) => c.type === "consent" && !c.data)) {
|
|
4903
|
+
__privateGet5(this, _persist).delete(STORAGE_KEY, true);
|
|
4904
|
+
}
|
|
4905
|
+
__privateMethod2(this, _VisitorDataStore_instances, replaceData_fn).call(this, newData);
|
|
4906
|
+
await ((_c = __privateGet5(this, _options).transitionStore) == null ? void 0 : _c.updateData(commands, __privateGet5(this, _VisitorDataStore_instances, currentData_get).visitorData));
|
|
4907
|
+
__privateGet5(this, _mitt2).emit("commandsExecuted", commands);
|
|
4908
|
+
}
|
|
4909
|
+
/**
|
|
4910
|
+
* Deletes visitor data (forgetting them)
|
|
4911
|
+
* In most cases you should use forget() on the Context instead of this function, which also clears the Context state.
|
|
4912
|
+
* @param fromAllDevices - for an identified user, whether to delete all their data (for the entire account) - true, or data for this device (sign out) - false
|
|
4913
|
+
*/
|
|
4914
|
+
async delete(fromAllDevices) {
|
|
4915
|
+
var _a, _b, _c, _d, _e;
|
|
4916
|
+
(_b = (_a = __privateGet5(this, _options)).onLogMessage) == null ? void 0 : _b.call(_a, ["info", 103, "GROUP", fromAllDevices]);
|
|
4917
|
+
try {
|
|
4918
|
+
__privateGet5(this, _persist).delete(STORAGE_KEY, false);
|
|
4919
|
+
await ((_c = __privateGet5(this, _options).transitionStore) == null ? void 0 : _c.delete(fromAllDevices));
|
|
4920
|
+
__privateMethod2(this, _VisitorDataStore_instances, replaceData_fn).call(this, __privateMethod2(this, _VisitorDataStore_instances, defaultData_fn).call(this));
|
|
4921
|
+
} finally {
|
|
4922
|
+
(_e = (_d = __privateGet5(this, _options)).onLogMessage) == null ? void 0 : _e.call(_d, ["info", 103, "ENDGROUP"]);
|
|
4923
|
+
}
|
|
4924
|
+
}
|
|
4925
|
+
};
|
|
4926
|
+
_mitt2 = /* @__PURE__ */ new WeakMap();
|
|
4927
|
+
_persist = /* @__PURE__ */ new WeakMap();
|
|
4928
|
+
_visitTimeout = /* @__PURE__ */ new WeakMap();
|
|
4929
|
+
_options = /* @__PURE__ */ new WeakMap();
|
|
4930
|
+
_VisitorDataStore_instances = /* @__PURE__ */ new WeakSet();
|
|
4931
|
+
currentData_get = function() {
|
|
4932
|
+
return __privateGet5(this, _persist).get(STORAGE_KEY);
|
|
4933
|
+
};
|
|
4934
|
+
replaceData_fn = function(data, quiet = false) {
|
|
4935
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
4936
|
+
const oldData = __privateGet5(this, _VisitorDataStore_instances, currentData_get);
|
|
4937
|
+
const now = Date.now();
|
|
4938
|
+
__privateMethod2(this, _VisitorDataStore_instances, handleCaps_fn).call(this, data.scores);
|
|
4939
|
+
__privateMethod2(this, _VisitorDataStore_instances, handleCaps_fn).call(this, data.sessionScores);
|
|
4940
|
+
(_b = (_a = __privateGet5(this, _options)).decay) == null ? void 0 : _b.call(_a, {
|
|
4941
|
+
now,
|
|
4942
|
+
lastUpd: oldData == null ? void 0 : oldData.updated,
|
|
4943
|
+
scores: data.scores,
|
|
4944
|
+
sessionScores: data.sessionScores,
|
|
4945
|
+
onLogMessage: __privateGet5(this, _options).onLogMessage
|
|
4946
|
+
});
|
|
4947
|
+
const haveScoresChanged = !dequal(oldData == null ? void 0 : oldData.visitorData.scores, data.scores);
|
|
4948
|
+
const haveSessionScoresChanged = !dequal(oldData == null ? void 0 : oldData.visitorData.sessionScores, data.sessionScores);
|
|
4949
|
+
const haveQuirksChanged = !dequal(oldData == null ? void 0 : oldData.visitorData.quirks, data.quirks);
|
|
4950
|
+
const haveTestsChanged = !dequal(oldData == null ? void 0 : oldData.visitorData.tests, data.tests);
|
|
4951
|
+
const haveGoalsChanged = !dequal(oldData == null ? void 0 : oldData.visitorData.goals, data.goals);
|
|
4952
|
+
const updatedData = {
|
|
4953
|
+
updated: now,
|
|
4954
|
+
visitorData: data
|
|
4955
|
+
};
|
|
4956
|
+
__privateMethod2(this, _VisitorDataStore_instances, setVisitTimeout_fn).call(this);
|
|
4957
|
+
__privateGet5(this, _persist).set(STORAGE_KEY, updatedData, !!data.consent);
|
|
4958
|
+
(_d = (_c = __privateGet5(this, _options)).onLogMessage) == null ? void 0 : _d.call(_c, ["debug", 102, data]);
|
|
4959
|
+
if (!quiet) {
|
|
4960
|
+
if (haveScoresChanged || haveSessionScoresChanged) {
|
|
4961
|
+
__privateGet5(this, _mitt2).emit("scoresUpdated", data);
|
|
4962
|
+
}
|
|
4963
|
+
if (haveQuirksChanged) {
|
|
4964
|
+
__privateGet5(this, _mitt2).emit("quirksUpdated", data);
|
|
4965
|
+
}
|
|
4966
|
+
if (haveTestsChanged) {
|
|
4967
|
+
__privateGet5(this, _mitt2).emit("testsUpdated", data);
|
|
4968
|
+
}
|
|
4969
|
+
if (((_e = oldData == null ? void 0 : oldData.visitorData) == null ? void 0 : _e.consent) !== data.consent) {
|
|
4970
|
+
__privateGet5(this, _mitt2).emit("consentUpdated", data);
|
|
4971
|
+
}
|
|
4972
|
+
if (((_f = oldData == null ? void 0 : oldData.visitorData) == null ? void 0 : _f.controlGroup) !== data.controlGroup) {
|
|
4973
|
+
__privateGet5(this, _mitt2).emit("controlGroupUpdated", data);
|
|
4974
|
+
(_i = (_h = __privateGet5(this, _options)).onLogMessage) == null ? void 0 : _i.call(_h, ["debug", 104, (_g = data.controlGroup) != null ? _g : false]);
|
|
4975
|
+
}
|
|
4976
|
+
if (haveGoalsChanged) {
|
|
4977
|
+
const newGoalKeys = Object.keys((_j = data.goals) != null ? _j : {});
|
|
4978
|
+
for (let i = 0; i < newGoalKeys.length; i++) {
|
|
4979
|
+
const key = newGoalKeys[i];
|
|
4980
|
+
if (!((_k = oldData == null ? void 0 : oldData.visitorData.goals) == null ? void 0 : _k[key])) {
|
|
4981
|
+
__privateGet5(this, _mitt2).emit("goalConverted", { goalId: key });
|
|
4982
|
+
}
|
|
4983
|
+
}
|
|
4984
|
+
}
|
|
4985
|
+
}
|
|
4986
|
+
};
|
|
4987
|
+
setVisitTimeout_fn = function() {
|
|
4988
|
+
if (typeof document === "undefined" || !__privateGet5(this, _options).visitLifespan) {
|
|
4989
|
+
return;
|
|
4990
|
+
}
|
|
4991
|
+
if (__privateGet5(this, _visitTimeout)) {
|
|
4992
|
+
window.clearTimeout(__privateGet5(this, _visitTimeout));
|
|
4993
|
+
}
|
|
4994
|
+
__privateSet3(this, _visitTimeout, window.setTimeout(() => {
|
|
4995
|
+
this.data;
|
|
4996
|
+
}, __privateGet5(this, _options).visitLifespan + 50));
|
|
4997
|
+
};
|
|
4998
|
+
isExpired_fn = function(data) {
|
|
4999
|
+
const expires = __privateGet5(this, _options).visitLifespan;
|
|
5000
|
+
return expires ? data.updated + expires < Date.now() : false;
|
|
5001
|
+
};
|
|
5002
|
+
handleCaps_fn = function(scores) {
|
|
5003
|
+
var _a, _b;
|
|
5004
|
+
if (!__privateGet5(this, _options).manifest) {
|
|
5005
|
+
return;
|
|
5006
|
+
}
|
|
5007
|
+
for (const dim in scores) {
|
|
5008
|
+
const score = scores[dim];
|
|
5009
|
+
const dimDef = __privateGet5(this, _options).manifest.getDimensionByKey(dim);
|
|
5010
|
+
if (!dimDef) {
|
|
5011
|
+
continue;
|
|
5012
|
+
}
|
|
5013
|
+
if (score > dimDef.cap) {
|
|
5014
|
+
(_b = (_a = __privateGet5(this, _options)).onLogMessage) == null ? void 0 : _b.call(_a, ["debug", 110, { dim, score, cap: dimDef.cap }]);
|
|
5015
|
+
scores[dim] = dimDef.cap;
|
|
5016
|
+
}
|
|
5017
|
+
}
|
|
5018
|
+
};
|
|
5019
|
+
defaultData_fn = function() {
|
|
5020
|
+
var _a, _b, _c;
|
|
5021
|
+
return {
|
|
5022
|
+
...emptyVisitorData(),
|
|
5023
|
+
consent: (_a = __privateGet5(this, _options).defaultConsent) != null ? _a : false,
|
|
5024
|
+
controlGroup: (_c = (_b = __privateGet5(this, _options).manifest) == null ? void 0 : _b.rollForControlGroup()) != null ? _c : false
|
|
5025
|
+
};
|
|
5026
|
+
};
|
|
5027
|
+
var CONTEXTUAL_EDITING_TEST_NAME = "contextual_editing_test";
|
|
5028
|
+
var CONTEXTUAL_EDITING_TEST_SELECTED_VARIANT_ID = "contextual_editing_test_selected_variant";
|
|
5029
|
+
var _personalizationSelectionAlgorithms;
|
|
5030
|
+
var _serverTransitionState;
|
|
5031
|
+
var _scores;
|
|
5032
|
+
var _state;
|
|
5033
|
+
var _pzCache;
|
|
5034
|
+
var _plugins;
|
|
5035
|
+
var _commands;
|
|
5036
|
+
var _requireConsentForPersonalization;
|
|
5037
|
+
var _mitt3;
|
|
5038
|
+
var _Context_instances;
|
|
5039
|
+
var emitTest_fn;
|
|
5040
|
+
var updateGoals_fn;
|
|
5041
|
+
var updateComputedScores_fn;
|
|
5042
|
+
var calculateScores_fn;
|
|
5043
|
+
var Context = class {
|
|
5044
|
+
constructor(options) {
|
|
5045
|
+
__privateAdd5(this, _Context_instances);
|
|
5046
|
+
__publicField3(this, "manifest");
|
|
5047
|
+
__privateAdd5(this, _personalizationSelectionAlgorithms);
|
|
5048
|
+
__privateAdd5(this, _serverTransitionState);
|
|
5049
|
+
__privateAdd5(this, _scores, {});
|
|
5050
|
+
__privateAdd5(this, _state);
|
|
5051
|
+
__privateAdd5(this, _pzCache, {});
|
|
5052
|
+
__privateAdd5(this, _plugins);
|
|
5053
|
+
__privateAdd5(this, _commands);
|
|
5054
|
+
__privateAdd5(this, _requireConsentForPersonalization);
|
|
5055
|
+
__privateAdd5(this, _mitt3, mitt_default());
|
|
5056
|
+
__publicField3(this, "events", {
|
|
5057
|
+
on: __privateGet5(this, _mitt3).on,
|
|
5058
|
+
off: __privateGet5(this, _mitt3).off
|
|
5059
|
+
});
|
|
5060
|
+
__publicField3(this, "storage");
|
|
5061
|
+
var _a, _b, _c;
|
|
5062
|
+
const { manifest, ...storageOptions } = options;
|
|
5063
|
+
__privateSet3(this, _state, {});
|
|
5064
|
+
__privateSet3(this, _plugins, options.plugins);
|
|
5065
|
+
__privateSet3(this, _requireConsentForPersonalization, options.requireConsentForPersonalization);
|
|
5066
|
+
if (typeof options.transitionStore !== "undefined") {
|
|
5067
|
+
__privateSet3(this, _commands, []);
|
|
5068
|
+
}
|
|
5069
|
+
__privateSet3(this, _personalizationSelectionAlgorithms, {
|
|
5070
|
+
[TOP_DOWN_CRITERIA_PERSONALIZATION_ALGORITHM]: topDownCriteriaPersonalizationSelectionAlgorithm,
|
|
5071
|
+
[STRONGEST_SCORE_PERSONALIZATION_ALGORITHM]: strongestScorePersonalizationSelectionAlgorithm
|
|
5072
|
+
});
|
|
5073
|
+
(_a = __privateGet5(this, _plugins)) == null ? void 0 : _a.forEach((plugin) => {
|
|
5074
|
+
if (!plugin.personalizationSelectionAlgorithms) {
|
|
5075
|
+
return;
|
|
5076
|
+
}
|
|
5077
|
+
__privateSet3(this, _personalizationSelectionAlgorithms, {
|
|
5078
|
+
...__privateGet5(this, _personalizationSelectionAlgorithms),
|
|
5079
|
+
...plugin.personalizationSelectionAlgorithms
|
|
5080
|
+
});
|
|
5081
|
+
});
|
|
5082
|
+
(_b = __privateGet5(this, _plugins)) == null ? void 0 : _b.forEach((plugin) => {
|
|
5083
|
+
if (!plugin.logDrain) {
|
|
5084
|
+
return;
|
|
5085
|
+
}
|
|
5086
|
+
__privateGet5(this, _mitt3).on("log", plugin.logDrain);
|
|
5087
|
+
});
|
|
5088
|
+
__privateGet5(this, _mitt3).emit("log", ["info", 1, "GROUP"]);
|
|
5089
|
+
try {
|
|
5090
|
+
this.manifest = new ManifestInstance({
|
|
5091
|
+
onLogMessage: (message) => __privateGet5(this, _mitt3).emit("log", message),
|
|
5092
|
+
manifest,
|
|
5093
|
+
evaluator: new GroupCriteriaEvaluator({
|
|
5094
|
+
CK: cookieEvaluator,
|
|
5095
|
+
QS: queryStringEvaluator,
|
|
5096
|
+
QK: quirkEvaluator,
|
|
5097
|
+
PVC: pageViewCountEvaluator,
|
|
5098
|
+
EVT: eventEvaluator,
|
|
5099
|
+
PV: currentPageEvaluator
|
|
5100
|
+
})
|
|
5101
|
+
});
|
|
5102
|
+
this.storage = new VisitorDataStore({
|
|
5103
|
+
...storageOptions,
|
|
5104
|
+
manifest: this.manifest,
|
|
5105
|
+
onServerTransitionReceived: (state) => {
|
|
5106
|
+
__privateSet3(this, _serverTransitionState, state);
|
|
5107
|
+
if (state.ssv) {
|
|
5108
|
+
__privateSet3(this, _scores, state.ssv);
|
|
5109
|
+
__privateGet5(this, _mitt3).emit("log", ["debug", 130, state]);
|
|
5110
|
+
}
|
|
5111
|
+
if (state.compositionMetadata) {
|
|
5112
|
+
__privateGet5(this, _state).compositionMetadata = state.compositionMetadata;
|
|
5113
|
+
}
|
|
5114
|
+
},
|
|
5115
|
+
onLogMessage: (message) => __privateGet5(this, _mitt3).emit("log", message)
|
|
5116
|
+
});
|
|
5117
|
+
this.storage.events.on("scoresUpdated", __privateMethod2(this, _Context_instances, updateComputedScores_fn).bind(this));
|
|
5118
|
+
if (!__privateGet5(this, _serverTransitionState)) {
|
|
5119
|
+
__privateMethod2(this, _Context_instances, updateComputedScores_fn).call(this, this.storage.data);
|
|
5120
|
+
}
|
|
5121
|
+
this.storage.events.on("quirksUpdated", (quirks) => {
|
|
5122
|
+
const updates = this.manifest.computeSignals({
|
|
5123
|
+
scores: __privateGet5(this, _scores),
|
|
5124
|
+
state: __privateGet5(this, _state),
|
|
5125
|
+
previousState: __privateGet5(this, _state),
|
|
5126
|
+
visitor: this.storage.data
|
|
5127
|
+
});
|
|
5128
|
+
__privateMethod2(this, _Context_instances, updateGoals_fn).call(this, {
|
|
5129
|
+
quirks: quirks.quirks,
|
|
5130
|
+
scores: void 0
|
|
5131
|
+
});
|
|
5132
|
+
this.storage.updateData(updates);
|
|
5133
|
+
__privateGet5(this, _mitt3).emit("quirksUpdated", quirks.quirks);
|
|
5134
|
+
__privateGet5(this, _mitt3).emit("log", ["info", 4, quirks.quirks]);
|
|
5135
|
+
});
|
|
5136
|
+
(_c = __privateGet5(this, _plugins)) == null ? void 0 : _c.forEach((plugin) => {
|
|
5137
|
+
if (!plugin.init) {
|
|
5138
|
+
return;
|
|
5139
|
+
}
|
|
5140
|
+
plugin.init(this);
|
|
5141
|
+
});
|
|
5142
|
+
} finally {
|
|
5143
|
+
__privateGet5(this, _mitt3).emit("log", ["info", 1, "ENDGROUP"]);
|
|
5144
|
+
}
|
|
5145
|
+
if (typeof window !== "undefined") {
|
|
5146
|
+
window.__UNIFORM_CONTEXTUAL_EDITING_CONTEXT__ = this;
|
|
5147
|
+
}
|
|
5148
|
+
}
|
|
5149
|
+
/** Gets the current visitor's dimension score vector. */
|
|
5150
|
+
get scores() {
|
|
5151
|
+
return __privateGet5(this, _scores);
|
|
5152
|
+
}
|
|
5153
|
+
/** Gets the current visitor's quirks values. */
|
|
5154
|
+
get quirks() {
|
|
5155
|
+
var _a, _b;
|
|
5156
|
+
return (_b = (_a = __privateGet5(this, _serverTransitionState)) == null ? void 0 : _a.quirks) != null ? _b : this.storage.data.quirks;
|
|
5157
|
+
}
|
|
5158
|
+
get requireConsentForPersonalization() {
|
|
5159
|
+
return __privateGet5(this, _requireConsentForPersonalization);
|
|
5160
|
+
}
|
|
5161
|
+
/**
|
|
5162
|
+
* Updates the Context with new data of any sort, such as
|
|
5163
|
+
* new URLs, cookies, quirks, and enrichments.
|
|
5164
|
+
*
|
|
5165
|
+
* Only properties that are set in the data parameter will be updated,
|
|
5166
|
+
* for example if passing `url` but not `cookies`, the last known state of cookies will be preserved.
|
|
5167
|
+
*
|
|
5168
|
+
* Properties that do not result in a changed state,
|
|
5169
|
+
* i.e. pushing the same URL or cookies as before,
|
|
5170
|
+
* will NOT result in a recomputation of signal state.
|
|
5171
|
+
*/
|
|
5172
|
+
async update(newData) {
|
|
5173
|
+
var _a, _b, _c, _d, _e;
|
|
5174
|
+
const commands = [];
|
|
5175
|
+
const newServerSideTests = {};
|
|
5176
|
+
if ((_a = __privateGet5(this, _serverTransitionState)) == null ? void 0 : _a.quirks) {
|
|
5177
|
+
newData = {
|
|
5178
|
+
...newData,
|
|
5179
|
+
quirks: {
|
|
5180
|
+
...__privateGet5(this, _serverTransitionState).quirks,
|
|
5181
|
+
...newData.quirks || {}
|
|
5182
|
+
}
|
|
5183
|
+
};
|
|
5184
|
+
}
|
|
5185
|
+
if ((_b = __privateGet5(this, _serverTransitionState)) == null ? void 0 : _b.tests) {
|
|
5186
|
+
const testEntries = Object.entries(__privateGet5(this, _serverTransitionState).tests);
|
|
5187
|
+
if (testEntries.length > 0) {
|
|
5188
|
+
const validTests = [];
|
|
5189
|
+
testEntries.forEach(([testName, testVariantId]) => {
|
|
5190
|
+
if (!this.storage.data.tests[testName]) {
|
|
5191
|
+
validTests.push([testName, testVariantId]);
|
|
5192
|
+
newServerSideTests[testName] = testVariantId;
|
|
5193
|
+
}
|
|
5194
|
+
});
|
|
5195
|
+
commands.push(
|
|
5196
|
+
...validTests.map(([key, value]) => ({
|
|
5197
|
+
type: "settest",
|
|
5198
|
+
data: { test: key, variant: value }
|
|
5199
|
+
}))
|
|
5200
|
+
);
|
|
5201
|
+
}
|
|
5202
|
+
}
|
|
5203
|
+
if ((_c = __privateGet5(this, _serverTransitionState)) == null ? void 0 : _c.personalizeVariants) {
|
|
5204
|
+
Object.keys(__privateGet5(this, _serverTransitionState).personalizeVariants).forEach((personalizationName) => {
|
|
5205
|
+
const variants = __privateGet5(this, _serverTransitionState).personalizeVariants[personalizationName];
|
|
5206
|
+
variants.forEach((e) => {
|
|
5207
|
+
commands.push({
|
|
5208
|
+
type: "setpersonalizecontrol",
|
|
5209
|
+
data: { personlizationName: personalizationName, index: e.index, control: e.control }
|
|
5210
|
+
});
|
|
5211
|
+
});
|
|
5212
|
+
});
|
|
5213
|
+
}
|
|
5214
|
+
try {
|
|
5215
|
+
__privateGet5(this, _mitt3).emit("log", [
|
|
5216
|
+
"info",
|
|
5217
|
+
2,
|
|
5218
|
+
"GROUP",
|
|
5219
|
+
{
|
|
5220
|
+
...newData,
|
|
5221
|
+
// need to convert url to string so it can be json serialized
|
|
5222
|
+
// to go over postMessage to chrome extension
|
|
5223
|
+
url: (_d = newData.url) == null ? void 0 : _d.toString()
|
|
5224
|
+
}
|
|
5225
|
+
]);
|
|
5226
|
+
if (newData.quirks) {
|
|
5227
|
+
commands.push(
|
|
5228
|
+
...Object.entries(newData.quirks).map(([key, value]) => ({
|
|
5229
|
+
type: "setquirk",
|
|
5230
|
+
data: { key, value }
|
|
5231
|
+
}))
|
|
5232
|
+
);
|
|
5233
|
+
}
|
|
5234
|
+
if (newData.enrichments) {
|
|
5235
|
+
newData.enrichments.forEach((enrichment) => {
|
|
5236
|
+
const dimension = getEnrichmentVectorKey(enrichment.cat, enrichment.key);
|
|
5237
|
+
const dimData = this.manifest.getDimensionByKey(dimension);
|
|
5238
|
+
if (dimData) {
|
|
5239
|
+
commands.push({
|
|
5240
|
+
type: "modscore",
|
|
5241
|
+
data: {
|
|
5242
|
+
dimension,
|
|
5243
|
+
delta: enrichment.str
|
|
5244
|
+
}
|
|
5245
|
+
});
|
|
5246
|
+
} else {
|
|
5247
|
+
__privateGet5(this, _mitt3).emit("log", ["warn", 5, enrichment]);
|
|
5248
|
+
}
|
|
5249
|
+
});
|
|
5250
|
+
}
|
|
5251
|
+
const effectiveNewStateForSignalComputation = {
|
|
5252
|
+
...__privateGet5(this, _state),
|
|
5253
|
+
...newData
|
|
5254
|
+
};
|
|
5255
|
+
commands.push(
|
|
5256
|
+
...this.manifest.computeSignals({
|
|
5257
|
+
state: effectiveNewStateForSignalComputation,
|
|
5258
|
+
previousState: __privateGet5(this, _state),
|
|
5259
|
+
visitor: this.storage.data,
|
|
5260
|
+
// re-compute using scores from storage instead of the current scores since
|
|
5261
|
+
// server transition scores might have adjusted values already integrated into them,
|
|
5262
|
+
// which causes issues when you are near limits.
|
|
5263
|
+
scores: __privateGet5(this, _serverTransitionState) ? __privateMethod2(this, _Context_instances, calculateScores_fn).call(this, this.storage.data) : __privateGet5(this, _scores)
|
|
5264
|
+
})
|
|
5265
|
+
);
|
|
5266
|
+
const previousCompositionMetadata = __privateGet5(this, _state).compositionMetadata;
|
|
5267
|
+
__privateSet3(this, _state, {
|
|
5268
|
+
...__privateGet5(this, _state),
|
|
5269
|
+
...newData
|
|
5270
|
+
});
|
|
5271
|
+
if (newData.compositionMetadata && // deep equal is not too bad, as we only have 1 level of depth in dynamic inputs
|
|
5272
|
+
!dequal(previousCompositionMetadata, __privateGet5(this, _state).compositionMetadata)) {
|
|
5273
|
+
__privateGet5(this, _mitt3).emit("canvasDataUpdated", __privateGet5(this, _state).compositionMetadata);
|
|
5274
|
+
__privateGet5(this, _state).compositionMetadata = newData.compositionMetadata;
|
|
5275
|
+
}
|
|
5276
|
+
await this.storage.updateData(commands);
|
|
5277
|
+
if (__privateGet5(this, _serverTransitionState)) {
|
|
5278
|
+
await this.processServerCommands({
|
|
5279
|
+
serverCommands: __privateGet5(this, _serverTransitionState).commands,
|
|
5280
|
+
commands
|
|
5281
|
+
});
|
|
5282
|
+
__privateMethod2(this, _Context_instances, updateComputedScores_fn).call(this, this.storage.data);
|
|
5283
|
+
Object.entries(newServerSideTests).forEach(([testName, testVariantId]) => {
|
|
5284
|
+
__privateMethod2(this, _Context_instances, emitTest_fn).call(this, {
|
|
5285
|
+
name: testName,
|
|
5286
|
+
variantId: testVariantId,
|
|
5287
|
+
variantAssigned: true,
|
|
5288
|
+
control: false,
|
|
5289
|
+
compositionMetadata: void 0
|
|
5290
|
+
});
|
|
5291
|
+
});
|
|
5292
|
+
const haveQuirksChanged = __privateGet5(this, _serverTransitionState) && !dequal(__privateGet5(this, _serverTransitionState).quirks, this.storage.data.quirks);
|
|
5293
|
+
__privateSet3(this, _serverTransitionState, void 0);
|
|
5294
|
+
if (haveQuirksChanged) {
|
|
5295
|
+
__privateGet5(this, _mitt3).emit("quirksUpdated", this.storage.data.quirks);
|
|
5296
|
+
}
|
|
5297
|
+
__privateGet5(this, _mitt3).emit("log", ["debug", 131]);
|
|
5298
|
+
}
|
|
5299
|
+
if (__privateGet5(this, _plugins)) {
|
|
5300
|
+
for (let i = 0; i < __privateGet5(this, _plugins).length; i++) {
|
|
5301
|
+
const plugin = __privateGet5(this, _plugins)[i];
|
|
5302
|
+
if (!plugin.update) {
|
|
5303
|
+
continue;
|
|
5304
|
+
}
|
|
5305
|
+
await plugin.update(newData, __privateGet5(this, _scores));
|
|
5306
|
+
}
|
|
5307
|
+
}
|
|
5308
|
+
(_e = __privateGet5(this, _commands)) == null ? void 0 : _e.push(...commands);
|
|
5309
|
+
} finally {
|
|
5310
|
+
__privateGet5(this, _mitt3).emit("log", ["info", 2, "ENDGROUP"]);
|
|
5311
|
+
}
|
|
5312
|
+
}
|
|
5313
|
+
async processServerCommands({
|
|
5314
|
+
serverCommands,
|
|
5315
|
+
commands
|
|
5316
|
+
}) {
|
|
5317
|
+
if (!(serverCommands == null ? void 0 : serverCommands.length)) {
|
|
5318
|
+
return;
|
|
5319
|
+
}
|
|
5320
|
+
const notExecutedCommands = [];
|
|
5321
|
+
serverCommands.forEach((serverCommand) => {
|
|
5322
|
+
const found = commands.find((command) => {
|
|
5323
|
+
return areCommandsEqual(command, serverCommand);
|
|
5324
|
+
});
|
|
5325
|
+
if (!found) {
|
|
5326
|
+
notExecutedCommands.push(serverCommand);
|
|
5327
|
+
}
|
|
5328
|
+
});
|
|
5329
|
+
if (notExecutedCommands.length > 0) {
|
|
5330
|
+
await this.storage.updateData(notExecutedCommands);
|
|
5331
|
+
}
|
|
5332
|
+
}
|
|
5333
|
+
/** use test() instead */
|
|
5334
|
+
getTestVariantId(testName) {
|
|
5335
|
+
var _a, _b, _c, _d;
|
|
5336
|
+
const definition = this.manifest.getTest(testName);
|
|
5337
|
+
if (!definition) {
|
|
5338
|
+
__privateGet5(this, _mitt3).emit("log", ["warn", 401, testName]);
|
|
5339
|
+
return null;
|
|
5340
|
+
}
|
|
5341
|
+
return (_d = (_c = definition.wv) != null ? _c : (_b = (_a = __privateGet5(this, _serverTransitionState)) == null ? void 0 : _a.tests) == null ? void 0 : _b[testName]) != null ? _d : this.storage.data.tests[testName];
|
|
5342
|
+
}
|
|
5343
|
+
/** use test() instead */
|
|
5344
|
+
setTestVariantId(testName, variantId) {
|
|
5345
|
+
this.storage.updateData([
|
|
5346
|
+
{
|
|
5347
|
+
type: "settest",
|
|
5348
|
+
data: {
|
|
5349
|
+
test: testName,
|
|
5350
|
+
variant: variantId
|
|
5351
|
+
}
|
|
5352
|
+
}
|
|
5353
|
+
]);
|
|
5354
|
+
}
|
|
5355
|
+
getPersonalizeVariantControl(name, index) {
|
|
5356
|
+
var _a, _b, _c;
|
|
5357
|
+
const source = (_b = (_a = __privateGet5(this, _serverTransitionState)) == null ? void 0 : _a.personalizeVariants) != null ? _b : this.storage.data.personalizeVariants;
|
|
5358
|
+
const variants = (_c = source == null ? void 0 : source[name]) != null ? _c : [];
|
|
5359
|
+
const variant = variants.find((v) => v.index === index);
|
|
5360
|
+
return variant == null ? void 0 : variant.control;
|
|
5361
|
+
}
|
|
5362
|
+
/**
|
|
5363
|
+
* Writes a message to the Context log sink.
|
|
5364
|
+
* Used by Uniform internal SDK; not intended for public use.
|
|
5365
|
+
*/
|
|
5366
|
+
log(...message) {
|
|
5367
|
+
__privateGet5(this, _mitt3).emit("log", message);
|
|
5368
|
+
}
|
|
5369
|
+
/** Executes an A/B test with a given set of variants, showing the visitor's assigned variant (or selecting one to assign, if none is set yet) */
|
|
5370
|
+
test(options) {
|
|
5371
|
+
var _a, _b, _c, _d, _e;
|
|
5372
|
+
if (options.name === CONTEXTUAL_EDITING_TEST_NAME) {
|
|
5373
|
+
const selectedVariant = (_a = options.variations.find((variant) => variant.id === CONTEXTUAL_EDITING_TEST_SELECTED_VARIANT_ID)) != null ? _a : options.variations.at(-1);
|
|
5374
|
+
const value2 = {
|
|
5375
|
+
result: selectedVariant,
|
|
5376
|
+
variantAssigned: false
|
|
5377
|
+
};
|
|
5378
|
+
return value2;
|
|
5379
|
+
}
|
|
5380
|
+
const value = testVariations({
|
|
5381
|
+
...options,
|
|
5382
|
+
context: this,
|
|
5383
|
+
onLogMessage: (message) => __privateGet5(this, _mitt3).emit("log", message)
|
|
5384
|
+
});
|
|
5385
|
+
__privateMethod2(this, _Context_instances, emitTest_fn).call(this, {
|
|
5386
|
+
name: options.name,
|
|
5387
|
+
variantId: (_c = (_b = value.result) == null ? void 0 : _b.id) != null ? _c : void 0,
|
|
5388
|
+
variantAssigned: value.variantAssigned,
|
|
5389
|
+
control: (_e = (_d = value.result) == null ? void 0 : _d.control) != null ? _e : false,
|
|
5390
|
+
compositionMetadata: options.compositionMetadata
|
|
5391
|
+
});
|
|
5392
|
+
return value;
|
|
5393
|
+
}
|
|
5394
|
+
/** Executes a personalized placement with a given set of variants */
|
|
5395
|
+
personalize(options) {
|
|
5396
|
+
var _a;
|
|
5397
|
+
const algorithmName = (_a = options.algorithm) != null ? _a : TOP_DOWN_CRITERIA_PERSONALIZATION_ALGORITHM;
|
|
5398
|
+
const algorithm = __privateGet5(this, _personalizationSelectionAlgorithms)[algorithmName];
|
|
5399
|
+
if (!algorithm) {
|
|
5400
|
+
__privateGet5(this, _mitt3).emit("log", ["warn", 304, { algorithm: algorithmName }]);
|
|
5401
|
+
return {
|
|
5402
|
+
personalized: false,
|
|
5403
|
+
variations: []
|
|
5404
|
+
};
|
|
5405
|
+
}
|
|
5406
|
+
const value = algorithm({
|
|
5407
|
+
...options,
|
|
5408
|
+
context: this,
|
|
5409
|
+
onLogMessage: (message) => __privateGet5(this, _mitt3).emit("log", message)
|
|
5410
|
+
});
|
|
5411
|
+
const previousPlacement = __privateGet5(this, _pzCache)[options.name];
|
|
5412
|
+
const eventData = {
|
|
5413
|
+
name: options.name,
|
|
5414
|
+
variantIds: value.variations.map((variation) => ({
|
|
5415
|
+
id: variation.id || "Unknown",
|
|
5416
|
+
control: variation.control
|
|
5417
|
+
})),
|
|
5418
|
+
control: this.storage.data.controlGroup,
|
|
5419
|
+
changed: true,
|
|
5420
|
+
compositionMetadata: options.compositionMetadata
|
|
5421
|
+
};
|
|
5422
|
+
if (previousPlacement && dequal(eventData.variantIds, previousPlacement)) {
|
|
5423
|
+
eventData.changed = false;
|
|
5424
|
+
}
|
|
5425
|
+
__privateGet5(this, _mitt3).emit("personalizationResult", eventData);
|
|
5426
|
+
__privateGet5(this, _pzCache)[options.name] = eventData.variantIds;
|
|
5427
|
+
return value;
|
|
5428
|
+
}
|
|
5429
|
+
/**
|
|
5430
|
+
* Forgets the visitor's data and resets the Context to its initial state.
|
|
5431
|
+
* @param fromAllDevices - for an identified user, whether to delete all their data (for the entire account) - true, or data for this device (sign out) - false
|
|
5432
|
+
*/
|
|
5433
|
+
async forget(fromAllDevices) {
|
|
5434
|
+
const previousCompositionMetadata = __privateGet5(this, _state).compositionMetadata;
|
|
5435
|
+
__privateSet3(this, _state, {
|
|
5436
|
+
compositionMetadata: previousCompositionMetadata
|
|
5437
|
+
});
|
|
5438
|
+
if (__privateGet5(this, _plugins)) {
|
|
5439
|
+
for (let i = 0; i < __privateGet5(this, _plugins).length; i++) {
|
|
5440
|
+
const plugin = __privateGet5(this, _plugins)[i];
|
|
5441
|
+
if (!plugin.forget) {
|
|
5442
|
+
continue;
|
|
5443
|
+
}
|
|
5444
|
+
await plugin.forget();
|
|
5445
|
+
}
|
|
5446
|
+
}
|
|
5447
|
+
await this.storage.delete(fromAllDevices);
|
|
5448
|
+
}
|
|
5449
|
+
/**
|
|
5450
|
+
* Computes server to client transition state.
|
|
5451
|
+
*
|
|
5452
|
+
* Removes state from server-to-client if it came in initial state (cookies) to avoid double tracking on the client.
|
|
5453
|
+
*/
|
|
5454
|
+
getServerToClientTransitionState() {
|
|
5455
|
+
const transitionState = {
|
|
5456
|
+
quirks: this.storage.data.quirks,
|
|
5457
|
+
ssv: __privateGet5(this, _scores),
|
|
5458
|
+
tests: {},
|
|
5459
|
+
personalizeVariants: this.storage.data.personalizeVariants,
|
|
5460
|
+
commands: __privateGet5(this, _commands),
|
|
5461
|
+
compositionMetadata: __privateGet5(this, _state).compositionMetadata
|
|
5462
|
+
};
|
|
5463
|
+
const allTests = this.storage.data.tests;
|
|
5464
|
+
Object.entries(allTests).map(([testName, testValue]) => {
|
|
5465
|
+
var _a, _b, _c;
|
|
5466
|
+
if (((_c = (_b = (_a = this.storage.options.transitionStore) == null ? void 0 : _a.initialData) == null ? void 0 : _b.tests) == null ? void 0 : _c[testName]) !== allTests[testName] && transitionState.tests) {
|
|
5467
|
+
transitionState.tests[testName] = testValue;
|
|
5468
|
+
}
|
|
5469
|
+
});
|
|
5470
|
+
return transitionState;
|
|
5471
|
+
}
|
|
5472
|
+
/** @deprecated Internal API for test event processing; not for public use. */
|
|
5473
|
+
internal_processTestEvent(event) {
|
|
5474
|
+
if (event.variantId) {
|
|
5475
|
+
this.setTestVariantId(event.name, event.variantId);
|
|
5476
|
+
__privateMethod2(this, _Context_instances, emitTest_fn).call(this, event);
|
|
5477
|
+
}
|
|
5478
|
+
}
|
|
5479
|
+
/** @deprecated Internal API for personalization event processing; not for public use. */
|
|
5480
|
+
internal_processPersonalizationEvent(event) {
|
|
5481
|
+
__privateGet5(this, _pzCache)[event.name] = event.variantIds;
|
|
5482
|
+
__privateGet5(this, _mitt3).emit("personalizationResult", event);
|
|
5483
|
+
}
|
|
5484
|
+
/**
|
|
5485
|
+
* Gets the current canvas data
|
|
5486
|
+
*/
|
|
5487
|
+
getCompositionMetadata() {
|
|
5488
|
+
return __privateGet5(this, _state).compositionMetadata;
|
|
5489
|
+
}
|
|
5490
|
+
/**
|
|
5491
|
+
* Updates the canvas data and emits a canvasDataUpdated event
|
|
5492
|
+
*/
|
|
5493
|
+
async updateCompositionMetadata(newData) {
|
|
5494
|
+
const currentCanvas = __privateGet5(this, _state).compositionMetadata || {};
|
|
5495
|
+
const updatedCanvas = { ...currentCanvas, ...newData };
|
|
5496
|
+
if (!dequal(currentCanvas, updatedCanvas)) {
|
|
5497
|
+
__privateSet3(this, _state, {
|
|
5498
|
+
...__privateGet5(this, _state),
|
|
5499
|
+
compositionMetadata: updatedCanvas
|
|
5500
|
+
});
|
|
5501
|
+
__privateGet5(this, _mitt3).emit("canvasDataUpdated", updatedCanvas);
|
|
5502
|
+
__privateGet5(this, _mitt3).emit("log", ["info", 4, "Canvas data updated"]);
|
|
5503
|
+
}
|
|
5504
|
+
}
|
|
5505
|
+
};
|
|
5506
|
+
_personalizationSelectionAlgorithms = /* @__PURE__ */ new WeakMap();
|
|
5507
|
+
_serverTransitionState = /* @__PURE__ */ new WeakMap();
|
|
5508
|
+
_scores = /* @__PURE__ */ new WeakMap();
|
|
5509
|
+
_state = /* @__PURE__ */ new WeakMap();
|
|
5510
|
+
_pzCache = /* @__PURE__ */ new WeakMap();
|
|
5511
|
+
_plugins = /* @__PURE__ */ new WeakMap();
|
|
5512
|
+
_commands = /* @__PURE__ */ new WeakMap();
|
|
5513
|
+
_requireConsentForPersonalization = /* @__PURE__ */ new WeakMap();
|
|
5514
|
+
_mitt3 = /* @__PURE__ */ new WeakMap();
|
|
5515
|
+
_Context_instances = /* @__PURE__ */ new WeakSet();
|
|
5516
|
+
emitTest_fn = function(event) {
|
|
5517
|
+
__privateGet5(this, _mitt3).emit("testResult", event);
|
|
5518
|
+
};
|
|
5519
|
+
updateGoals_fn = async function(data) {
|
|
5520
|
+
const goalCommands = this.manifest.computeGoals(data);
|
|
5521
|
+
if (goalCommands.length !== 0) {
|
|
5522
|
+
await this.storage.updateData(goalCommands);
|
|
5523
|
+
}
|
|
5524
|
+
};
|
|
5525
|
+
updateComputedScores_fn = function(newData) {
|
|
5526
|
+
const newScores = __privateMethod2(this, _Context_instances, calculateScores_fn).call(this, newData);
|
|
5527
|
+
const newScoresHaveChanged = !dequal(newScores, __privateGet5(this, _scores));
|
|
5528
|
+
if (newScoresHaveChanged) {
|
|
5529
|
+
__privateSet3(this, _scores, newScores);
|
|
5530
|
+
__privateMethod2(this, _Context_instances, updateGoals_fn).call(this, {
|
|
5531
|
+
scores: __privateGet5(this, _scores),
|
|
5532
|
+
quirks: void 0
|
|
5533
|
+
});
|
|
5534
|
+
__privateGet5(this, _mitt3).emit("scoresUpdated", newScores);
|
|
5535
|
+
__privateGet5(this, _mitt3).emit("log", ["info", 3, newScores]);
|
|
5536
|
+
}
|
|
5537
|
+
};
|
|
5538
|
+
calculateScores_fn = function(newData) {
|
|
5539
|
+
var _a;
|
|
5540
|
+
let newScores = { ...newData.scores };
|
|
5541
|
+
for (const session in newData.sessionScores) {
|
|
5542
|
+
newScores[session] = ((_a = newScores[session]) != null ? _a : 0) + newData.sessionScores[session];
|
|
5543
|
+
}
|
|
5544
|
+
newScores = this.manifest.computeAggregateDimensions(newScores);
|
|
5545
|
+
return newScores;
|
|
5546
|
+
};
|
|
5547
|
+
var dc = (0, import_rfdc2.default)();
|
|
5548
|
+
var dc2 = (0, import_rfdc3.default)();
|
|
5549
|
+
|
|
5550
|
+
// src/config/helpers.ts
|
|
5551
|
+
import config from "@uniformdev/next-app-router/config/resolved";
|
|
5552
|
+
var getDisabledDevTools = () => {
|
|
5553
|
+
var _a;
|
|
5554
|
+
if (typeof ((_a = config.context) == null ? void 0 : _a.disableDevTools) === "boolean") {
|
|
5555
|
+
return config.context.disableDevTools;
|
|
5556
|
+
}
|
|
5557
|
+
return false;
|
|
5558
|
+
};
|
|
5559
|
+
var getDefaultConsent = () => {
|
|
5560
|
+
if (typeof config.defaultConsent === "boolean") {
|
|
5561
|
+
return config.defaultConsent;
|
|
5562
|
+
}
|
|
5563
|
+
return false;
|
|
5564
|
+
};
|
|
5565
|
+
var getQuirkSerialization = () => {
|
|
5566
|
+
if (typeof config.quirkSerialization === "boolean") {
|
|
5567
|
+
return config.quirkSerialization;
|
|
5568
|
+
}
|
|
5569
|
+
return true;
|
|
5570
|
+
};
|
|
5571
|
+
var getMiddlewareRuntimeCache = () => {
|
|
5572
|
+
if (process.env.NODE_ENV === "development" && !process.env.RUNTIME_CACHE_ENDPOINT) {
|
|
5573
|
+
return false;
|
|
5574
|
+
}
|
|
5575
|
+
if (typeof config.middlewareRuntimeCache === "boolean") {
|
|
5576
|
+
return config.middlewareRuntimeCache;
|
|
5577
|
+
}
|
|
5578
|
+
return true;
|
|
5579
|
+
};
|
|
5580
|
+
var getDisableSwrMiddlewareCache = () => {
|
|
5581
|
+
var _a;
|
|
5582
|
+
if (typeof ((_a = config.experimental) == null ? void 0 : _a.disableSwrMiddlewareCache) === "boolean") {
|
|
5583
|
+
return config.experimental.disableSwrMiddlewareCache;
|
|
5584
|
+
}
|
|
5585
|
+
return false;
|
|
5586
|
+
};
|
|
5587
|
+
|
|
5588
|
+
// src/middleware/context/index.ts
|
|
5589
|
+
var createOnDemandContext = async (options) => {
|
|
5590
|
+
var _a;
|
|
5591
|
+
const manifest = await options.dataClient.getManifest({ source: (_a = options.source) != null ? _a : "middleware" });
|
|
5592
|
+
if (!manifest) {
|
|
5593
|
+
console.error("Uniform manifest not found, falling back to empty manifest");
|
|
5594
|
+
}
|
|
5595
|
+
return new OnDemandContext({
|
|
5596
|
+
...options,
|
|
5597
|
+
manifest: manifest != null ? manifest : { project: {} },
|
|
5598
|
+
defaultConsent: options.defaultConsent
|
|
5599
|
+
});
|
|
5600
|
+
};
|
|
5601
|
+
var _options2;
|
|
5602
|
+
var OnDemandContext = class {
|
|
5603
|
+
constructor(options) {
|
|
5604
|
+
__privateAdd(this, _options2);
|
|
5605
|
+
__privateSet(this, _options2, options);
|
|
5606
|
+
}
|
|
5607
|
+
async getContext() {
|
|
5608
|
+
var _a, _b, _c;
|
|
5609
|
+
if (!this._context) {
|
|
5610
|
+
const uniformCookie = __privateGet(this, _options2).cookies.get(UNIFORM_DEFAULT_COOKIE_NAME);
|
|
5611
|
+
const quirkCookie = __privateGet(this, _options2).cookies.get(UNIFORM_DEFAULT_QUIRK_COOKIE_NAME);
|
|
5612
|
+
this._context = new Context({
|
|
5613
|
+
manifest: __privateGet(this, _options2).manifest,
|
|
5614
|
+
defaultConsent: (_a = __privateGet(this, _options2).defaultConsent) != null ? _a : getDefaultConsent(),
|
|
5615
|
+
transitionStore: new CookieTransitionDataStore({
|
|
5616
|
+
serverCookieValue: (_b = uniformCookie == null ? void 0 : uniformCookie.value) != null ? _b : "",
|
|
5617
|
+
experimental_quirksEnabled: getQuirkSerialization(),
|
|
5618
|
+
quirkCookieValue: (_c = quirkCookie == null ? void 0 : quirkCookie.value) != null ? _c : ""
|
|
5619
|
+
})
|
|
5620
|
+
});
|
|
5621
|
+
}
|
|
5622
|
+
return this._context;
|
|
5623
|
+
}
|
|
5624
|
+
};
|
|
5625
|
+
_options2 = new WeakMap();
|
|
5626
|
+
|
|
5627
|
+
// src/utils/quirks.ts
|
|
5628
|
+
var buildQuirksFromHeaders = (headers2) => {
|
|
5629
|
+
const headerToQuirkKey = {
|
|
5630
|
+
"x-vercel-ip-country": "vc-country",
|
|
5631
|
+
"x-vercel-ip-country-region": "vc-region",
|
|
5632
|
+
"x-vercel-ip-city": "vc-city"
|
|
5633
|
+
};
|
|
5634
|
+
return Object.entries(headerToQuirkKey).reduce((acc, [headerName, quirkKey]) => {
|
|
5635
|
+
const value = headers2.get(headerName);
|
|
5636
|
+
if (value) {
|
|
5637
|
+
acc[quirkKey] = value;
|
|
5638
|
+
}
|
|
5639
|
+
return acc;
|
|
5640
|
+
}, {});
|
|
5641
|
+
};
|
|
5642
|
+
|
|
5643
|
+
// src/data/client.ts
|
|
5644
|
+
import { getCache, waitUntil } from "@vercel/functions";
|
|
5645
|
+
var MANIFEST_CACHE_KEY = "uniform-manifest";
|
|
5646
|
+
var DefaultDataClient = class {
|
|
5647
|
+
async getManifest(options) {
|
|
5648
|
+
const cache2 = options.source === "middleware" && getMiddlewareRuntimeCache() ? getCache() : null;
|
|
5649
|
+
if (cache2) {
|
|
5650
|
+
const cachedManifest = await cache2.get(MANIFEST_CACHE_KEY);
|
|
5651
|
+
if (cachedManifest) {
|
|
5652
|
+
return cachedManifest;
|
|
5653
|
+
}
|
|
5654
|
+
}
|
|
5655
|
+
const manifest = await getManifest({
|
|
5656
|
+
cache: isDevelopmentEnvironment() ? {
|
|
5657
|
+
type: "no-cache",
|
|
5658
|
+
bypassCache: true
|
|
5659
|
+
} : {
|
|
5660
|
+
type: "force-cache"
|
|
5661
|
+
}
|
|
5662
|
+
});
|
|
5663
|
+
if (cache2) {
|
|
5664
|
+
waitUntil(
|
|
5665
|
+
(async () => {
|
|
5666
|
+
await cache2.set(MANIFEST_CACHE_KEY, manifest, {
|
|
5667
|
+
tags: generateManifestCacheTags()
|
|
5668
|
+
});
|
|
5669
|
+
})()
|
|
5670
|
+
);
|
|
5671
|
+
}
|
|
5672
|
+
return manifest;
|
|
5673
|
+
}
|
|
5674
|
+
async getRouteFromApi({
|
|
5675
|
+
route,
|
|
5676
|
+
routeClient,
|
|
5677
|
+
enableRuntimeCache,
|
|
5678
|
+
disableSwrCache
|
|
5679
|
+
}) {
|
|
5680
|
+
const newCacheKey = `uniform-route-${route.state}-${route.releaseId}-${route.path}`;
|
|
5681
|
+
const oldCacheKey = `uniform-route-old-${route.state}-${route.releaseId}-${route.path}`;
|
|
5682
|
+
const cache2 = enableRuntimeCache ? getCache() : null;
|
|
5683
|
+
const cacheNewRoute = async (result2) => {
|
|
5684
|
+
if (cache2 && result2.type === "composition") {
|
|
5685
|
+
const tags = generateRouteCacheTags({ path: route.path });
|
|
5686
|
+
await cache2.set(newCacheKey, result2, {
|
|
5687
|
+
tags
|
|
5688
|
+
});
|
|
5689
|
+
}
|
|
5690
|
+
};
|
|
5691
|
+
const cacheOldRoute = async (result2) => {
|
|
5692
|
+
if (cache2 && result2.type === "composition" && !disableSwrCache) {
|
|
5693
|
+
const tags = generateRouteCacheTags({ path: route.path, old: true });
|
|
5694
|
+
await cache2.set(oldCacheKey, result2, {
|
|
5695
|
+
tags
|
|
5696
|
+
});
|
|
5697
|
+
}
|
|
5698
|
+
};
|
|
5699
|
+
if (cache2) {
|
|
5700
|
+
const [cachedRoute, oldCachedRoute] = await Promise.all([
|
|
5701
|
+
cache2.get(newCacheKey),
|
|
5702
|
+
disableSwrCache ? null : cache2.get(oldCacheKey)
|
|
5703
|
+
]);
|
|
5704
|
+
if (cachedRoute) {
|
|
5705
|
+
return cachedRoute;
|
|
5706
|
+
}
|
|
5707
|
+
if (oldCachedRoute) {
|
|
5708
|
+
waitUntil(
|
|
5709
|
+
(async () => {
|
|
5710
|
+
const result2 = await routeClient.get(route);
|
|
5711
|
+
await cacheNewRoute(result2);
|
|
5712
|
+
})()
|
|
5713
|
+
);
|
|
5714
|
+
return oldCachedRoute;
|
|
5715
|
+
}
|
|
5716
|
+
}
|
|
5717
|
+
const result = await routeClient.get(route);
|
|
5718
|
+
waitUntil(
|
|
5719
|
+
(async () => {
|
|
5720
|
+
await Promise.all([
|
|
5721
|
+
cacheNewRoute(result),
|
|
5722
|
+
disableSwrCache ? Promise.resolve() : cacheOldRoute(result)
|
|
5723
|
+
]);
|
|
5724
|
+
})()
|
|
5725
|
+
);
|
|
5726
|
+
return result;
|
|
5727
|
+
}
|
|
5728
|
+
async getRoute(options) {
|
|
5729
|
+
if (options.source === "middleware") {
|
|
5730
|
+
return this.getRouteMiddleware(options);
|
|
5731
|
+
}
|
|
5732
|
+
return this.getRoutePageState(options);
|
|
5733
|
+
}
|
|
5734
|
+
async enhanceRoute(_options3) {
|
|
5735
|
+
}
|
|
5736
|
+
async getRouteMiddleware(options) {
|
|
5737
|
+
const routeClient = getRouteClient({
|
|
5738
|
+
searchParams: options.searchParams,
|
|
5739
|
+
draftModeEnabled: options.draftModeEnabled
|
|
5740
|
+
});
|
|
5741
|
+
const resolvedRoute = await this.getRouteFromApi({
|
|
5742
|
+
source: "middleware",
|
|
5743
|
+
route: options.route,
|
|
5744
|
+
routeClient,
|
|
5745
|
+
// The runtime cache is keyed on the route path. Development bypasses it so an author sees
|
|
5746
|
+
// an edit right away, the same way the fetch cache is bypassed for development.
|
|
5747
|
+
enableRuntimeCache: options.route.state === CANVAS_PUBLISHED_STATE && getMiddlewareRuntimeCache() && !isDevelopmentEnvironment(),
|
|
5748
|
+
disableSwrCache: getDisableSwrMiddlewareCache()
|
|
5749
|
+
});
|
|
5750
|
+
if (resolvedRoute.type === "composition") {
|
|
5751
|
+
await this.enhanceRoute({
|
|
5752
|
+
source: "middleware",
|
|
5753
|
+
parameters: options.route,
|
|
5754
|
+
route: resolvedRoute,
|
|
5755
|
+
routeClient,
|
|
5756
|
+
keys: void 0
|
|
5757
|
+
});
|
|
5758
|
+
}
|
|
5759
|
+
return {
|
|
5760
|
+
route: resolvedRoute
|
|
5761
|
+
};
|
|
5762
|
+
}
|
|
5763
|
+
async getRoutePageState(options) {
|
|
5764
|
+
const shouldBypassCache = options.pageState.compositionState !== CANVAS_PUBLISHED_STATE || isDevelopmentEnvironment();
|
|
5765
|
+
const routeClient = getRouteClient({
|
|
5766
|
+
cache: shouldBypassCache ? {
|
|
5767
|
+
type: "no-cache",
|
|
5768
|
+
bypassCache: true
|
|
5769
|
+
} : {
|
|
5770
|
+
type: "force-cache"
|
|
5771
|
+
}
|
|
5772
|
+
});
|
|
5773
|
+
const originalRoute = {
|
|
5774
|
+
path: options.pageState.routePath,
|
|
5775
|
+
state: options.pageState.compositionState,
|
|
5776
|
+
dataSourceVariant: getDataSourceVariantFromRouteGetParams({}, options.pageState.compositionState),
|
|
5777
|
+
withComponentIDs: true,
|
|
5778
|
+
releaseId: options.pageState.releaseId,
|
|
5779
|
+
locale: options.pageState.locale,
|
|
5780
|
+
ignoreRedirects: shouldIgnoreRedirects({ state: options.pageState.compositionState })
|
|
5781
|
+
};
|
|
5782
|
+
const resolvedRoute = await this.getRouteFromApi({
|
|
5783
|
+
source: "pageState",
|
|
5784
|
+
route: originalRoute,
|
|
5785
|
+
routeClient,
|
|
5786
|
+
enableRuntimeCache: false,
|
|
5787
|
+
disableSwrCache: false
|
|
5788
|
+
});
|
|
5789
|
+
if (resolvedRoute.type === "composition") {
|
|
5790
|
+
await this.enhanceRoute({
|
|
5791
|
+
source: "pageState",
|
|
5792
|
+
parameters: originalRoute,
|
|
5793
|
+
route: resolvedRoute,
|
|
5794
|
+
routeClient,
|
|
5795
|
+
keys: options.pageState.keys
|
|
5796
|
+
});
|
|
5797
|
+
}
|
|
5798
|
+
return {
|
|
5799
|
+
route: resolvedRoute
|
|
5800
|
+
};
|
|
5801
|
+
}
|
|
5802
|
+
};
|
|
5803
|
+
var expireMiddlewareCacheTag = async (tag) => {
|
|
5804
|
+
const cache2 = getMiddlewareRuntimeCache() ? getCache() : null;
|
|
5805
|
+
if (cache2) {
|
|
5806
|
+
await cache2.expireTag(tag);
|
|
5807
|
+
} else {
|
|
5808
|
+
console.warn("Middleware cache is not enabled, cannot clear cache tag", tag);
|
|
5809
|
+
}
|
|
5810
|
+
};
|
|
5811
|
+
|
|
5812
|
+
// src/middleware/composition/evaluate/evaluateRunnables.ts
|
|
5813
|
+
import {
|
|
5814
|
+
evaluatePersonalization,
|
|
5815
|
+
evaluateTest
|
|
5816
|
+
} from "@uniformdev/next-app-router-shared";
|
|
5817
|
+
var evaluateRunnables = async ({
|
|
5818
|
+
runnables,
|
|
5819
|
+
context,
|
|
5820
|
+
compositionContext,
|
|
5821
|
+
isPrefetch
|
|
5822
|
+
}) => {
|
|
5823
|
+
var _a;
|
|
5824
|
+
const result = {
|
|
5825
|
+
components: {},
|
|
5826
|
+
rules: void 0
|
|
5827
|
+
};
|
|
5828
|
+
const runnablesToProcess = runnables.filter((item2) => item2.variantId === void 0);
|
|
5829
|
+
let item;
|
|
5830
|
+
while (item = runnablesToProcess.shift()) {
|
|
5831
|
+
if (item.type === "test" && isPrefetch) {
|
|
5832
|
+
continue;
|
|
5833
|
+
}
|
|
5834
|
+
if (item.type === "test") {
|
|
5835
|
+
const testResult = evaluateTest({
|
|
5836
|
+
context,
|
|
5837
|
+
test: item.result,
|
|
5838
|
+
compositionContext
|
|
5839
|
+
});
|
|
5840
|
+
if (testResult.index !== null) {
|
|
5841
|
+
result.components[item._id] = {
|
|
5842
|
+
indexes: [testResult.index]
|
|
5843
|
+
};
|
|
5844
|
+
if (testResult.componentId) {
|
|
5845
|
+
const dependentRunnables = runnables.filter((r) => r.variantId === testResult.componentId);
|
|
5846
|
+
runnablesToProcess.push(...dependentRunnables);
|
|
5847
|
+
}
|
|
5848
|
+
}
|
|
5849
|
+
} else if (item.type === "personalization") {
|
|
5850
|
+
const personalizationResult = evaluatePersonalization({
|
|
5851
|
+
context,
|
|
5852
|
+
personalization: item.result,
|
|
5853
|
+
compositionContext
|
|
5854
|
+
});
|
|
5855
|
+
if (personalizationResult.indexes.length) {
|
|
5856
|
+
result.components[item._id] = {
|
|
5857
|
+
indexes: personalizationResult.indexes
|
|
5858
|
+
};
|
|
5859
|
+
}
|
|
5860
|
+
if (personalizationResult.componentIds.length) {
|
|
5861
|
+
const dependentRunnables = runnables.filter(
|
|
5862
|
+
(r) => r.variantId && personalizationResult.componentIds.includes(r.variantId)
|
|
5863
|
+
);
|
|
5864
|
+
runnablesToProcess.push(...dependentRunnables);
|
|
5865
|
+
}
|
|
5866
|
+
} else if (item.type === "visibility") {
|
|
5867
|
+
const rules = createQuirksVisibilityRule(context.quirks);
|
|
5868
|
+
const isVisible = evaluateNodeVisibilityParameter({
|
|
5869
|
+
rules,
|
|
5870
|
+
parameter: item.rules
|
|
5871
|
+
});
|
|
5872
|
+
if (isVisible !== null) {
|
|
5873
|
+
result.rules = (_a = result.rules) != null ? _a : {};
|
|
5874
|
+
result.rules[item._id] = isVisible;
|
|
5875
|
+
}
|
|
5876
|
+
}
|
|
5877
|
+
}
|
|
5878
|
+
return result;
|
|
5879
|
+
};
|
|
5880
|
+
|
|
5881
|
+
// src/data/extract/extractRunnables.ts
|
|
5882
|
+
import { getRuleId } from "@uniformdev/next-app-router-shared";
|
|
5883
|
+
|
|
5884
|
+
// src/data/extract/extractPersonalization.ts
|
|
5885
|
+
import {
|
|
5886
|
+
extractPersonalizationName
|
|
5887
|
+
} from "@uniformdev/next-app-router-shared";
|
|
5888
|
+
var extractPersonalization = ({
|
|
5889
|
+
component
|
|
5890
|
+
}) => {
|
|
5891
|
+
var _a, _b, _c;
|
|
5892
|
+
const trackingEventName = extractPersonalizationName({ component });
|
|
5893
|
+
const countParameter = (_a = component.parameters) == null ? void 0 : _a.count;
|
|
5894
|
+
const algorithmParameter = (_b = component.parameters) == null ? void 0 : _b.algorithm;
|
|
5895
|
+
const count = countParameter == null ? void 0 : countParameter.value;
|
|
5896
|
+
const algorithm = algorithmParameter == null ? void 0 : algorithmParameter.value;
|
|
5897
|
+
let parsedCount;
|
|
5898
|
+
if (typeof count === "string") {
|
|
5899
|
+
parsedCount = parseInt(count, 10);
|
|
5900
|
+
} else if (typeof count !== "number") {
|
|
5901
|
+
parsedCount = void 0;
|
|
5902
|
+
} else {
|
|
5903
|
+
parsedCount = count || 1;
|
|
5904
|
+
}
|
|
5905
|
+
const slot = ((_c = component.slots) == null ? void 0 : _c[CANVAS_PERSONALIZE_SLOT]) || [];
|
|
5906
|
+
const componentVariations = mapSlotToPersonalizedVariations(
|
|
5907
|
+
slot
|
|
5908
|
+
).map((variant, index) => {
|
|
5909
|
+
const slotComponent = slot[index];
|
|
5910
|
+
if (!slotComponent) {
|
|
5911
|
+
throw new Error(`Slot component not found for index ${index}`);
|
|
5912
|
+
}
|
|
5913
|
+
return {
|
|
5914
|
+
...variant,
|
|
5915
|
+
index,
|
|
5916
|
+
componentId: slotComponent._id
|
|
5917
|
+
};
|
|
5918
|
+
});
|
|
5919
|
+
return {
|
|
5920
|
+
name: trackingEventName,
|
|
5921
|
+
take: parsedCount,
|
|
5922
|
+
variations: componentVariations,
|
|
5923
|
+
algorithm
|
|
5924
|
+
};
|
|
5925
|
+
};
|
|
5926
|
+
|
|
5927
|
+
// src/data/extract/extractTest.ts
|
|
5928
|
+
import { extractTestName } from "@uniformdev/next-app-router-shared";
|
|
5929
|
+
var extractTest = ({ component }) => {
|
|
5930
|
+
var _a;
|
|
5931
|
+
const testName = extractTestName({ component });
|
|
5932
|
+
const slot = ((_a = component.slots) == null ? void 0 : _a[CANVAS_TEST_SLOT]) || [];
|
|
5933
|
+
const componentVariations = mapSlotToTestVariations(slot).map((variation, index) => {
|
|
5934
|
+
const slotComponent = slot[index];
|
|
5935
|
+
if (!slotComponent) {
|
|
5936
|
+
throw new Error(`Slot component not found for index ${index}`);
|
|
5937
|
+
}
|
|
5938
|
+
return {
|
|
5939
|
+
...variation,
|
|
5940
|
+
index,
|
|
5941
|
+
componentId: slotComponent._id
|
|
5942
|
+
};
|
|
5943
|
+
});
|
|
5944
|
+
return {
|
|
5945
|
+
name: testName,
|
|
5946
|
+
variations: componentVariations
|
|
5947
|
+
};
|
|
5948
|
+
};
|
|
5949
|
+
|
|
5950
|
+
// src/data/extract/extractRunnables.ts
|
|
5951
|
+
var findAncestorVariant = (ancestorsAndSelf) => {
|
|
5952
|
+
for (let i = 0; i < ancestorsAndSelf.length; i++) {
|
|
5953
|
+
const node = ancestorsAndSelf[i];
|
|
5954
|
+
if (node.type === "slot" && (node.parentSlot === CANVAS_PERSONALIZE_SLOT || node.parentSlot === CANVAS_TEST_SLOT)) {
|
|
5955
|
+
return node.node._id;
|
|
5956
|
+
}
|
|
5957
|
+
}
|
|
5958
|
+
return void 0;
|
|
5959
|
+
};
|
|
5960
|
+
var extractRunnables = (composition) => {
|
|
5961
|
+
const runnable = [];
|
|
5962
|
+
walkNodeTree(composition, (node) => {
|
|
5963
|
+
var _a, _b;
|
|
5964
|
+
if (node.type === "component") {
|
|
5965
|
+
const component = node.node;
|
|
5966
|
+
const visibilityRules = (_b = (_a = component.parameters) == null ? void 0 : _a[CANVAS_VIZ_CONTROL_PARAM]) == null ? void 0 : _b.value;
|
|
5967
|
+
if (component.type === CANVAS_TEST_TYPE) {
|
|
5968
|
+
const test = extractTest({ component });
|
|
5969
|
+
runnable.push({
|
|
5970
|
+
_id: component._id,
|
|
5971
|
+
variantId: findAncestorVariant(node.ancestorsAndSelf),
|
|
5972
|
+
type: "test",
|
|
5973
|
+
result: test
|
|
5974
|
+
});
|
|
5975
|
+
} else if (component.type === CANVAS_PERSONALIZE_TYPE) {
|
|
5976
|
+
const personalize = extractPersonalization({ component });
|
|
5977
|
+
runnable.push({
|
|
5978
|
+
type: "personalization",
|
|
5979
|
+
variantId: findAncestorVariant(node.ancestorsAndSelf),
|
|
5980
|
+
_id: component._id,
|
|
5981
|
+
result: personalize
|
|
5982
|
+
});
|
|
5983
|
+
}
|
|
5984
|
+
if (visibilityRules) {
|
|
5985
|
+
runnable.push({
|
|
5986
|
+
type: "visibility",
|
|
5987
|
+
_id: getRuleId(visibilityRules),
|
|
5988
|
+
variantId: findAncestorVariant(node.ancestorsAndSelf),
|
|
5989
|
+
rules: visibilityRules
|
|
5990
|
+
});
|
|
5991
|
+
}
|
|
5992
|
+
}
|
|
5993
|
+
});
|
|
5994
|
+
return runnable;
|
|
5995
|
+
};
|
|
5996
|
+
|
|
5997
|
+
// src/data/evaluate/evaluatePageState.ts
|
|
5998
|
+
var evaluatePageState = async ({
|
|
5999
|
+
composition,
|
|
6000
|
+
matchedRoute,
|
|
6001
|
+
dynamicInputs,
|
|
6002
|
+
pageState,
|
|
6003
|
+
context
|
|
6004
|
+
}) => {
|
|
6005
|
+
const extracted = extractRunnables(composition);
|
|
6006
|
+
const result = await evaluateRunnables({
|
|
6007
|
+
runnables: extracted,
|
|
6008
|
+
context,
|
|
6009
|
+
isPrefetch: pageState.isPrefetch,
|
|
6010
|
+
compositionContext: {
|
|
6011
|
+
_id: composition._id,
|
|
6012
|
+
type: composition.type,
|
|
6013
|
+
state: pageState.compositionState,
|
|
6014
|
+
isContextualEditing: pageState.compositionState === CANVAS_EDITOR_STATE,
|
|
6015
|
+
matchedRoute,
|
|
6016
|
+
dynamicInputs,
|
|
6017
|
+
pageState: {
|
|
6018
|
+
...pageState,
|
|
6019
|
+
// empty for now, we need to pass composition metadata down to evaluateRunnables for Context events enrichment
|
|
6020
|
+
components: {},
|
|
6021
|
+
rules: void 0
|
|
6022
|
+
}
|
|
6023
|
+
}
|
|
6024
|
+
});
|
|
6025
|
+
const allComponentIds = extracted.filter((r) => r.type === "test" || r.type === "personalization").map((r) => r._id);
|
|
6026
|
+
return {
|
|
6027
|
+
...result,
|
|
6028
|
+
allComponentIds
|
|
6029
|
+
};
|
|
6030
|
+
};
|
|
6031
|
+
|
|
6032
|
+
// src/data/evaluate/evaluateDraftPageState.ts
|
|
6033
|
+
var REQUEST_ORIGIN_PLACEHOLDER = "http://uniform.local";
|
|
6034
|
+
var evaluateDraftPageState = async ({
|
|
6035
|
+
pageState,
|
|
6036
|
+
composition,
|
|
6037
|
+
matchedRoute,
|
|
6038
|
+
dynamicInputs,
|
|
6039
|
+
dataClient
|
|
6040
|
+
}) => {
|
|
6041
|
+
var _a;
|
|
6042
|
+
const isPublished = pageState.compositionState === CANVAS_PUBLISHED_STATE;
|
|
6043
|
+
const isAlreadyEvaluated = Object.keys(pageState.components).length > 0 || Boolean(pageState.rules);
|
|
6044
|
+
if (isPublished || isAlreadyEvaluated) {
|
|
6045
|
+
return pageState;
|
|
6046
|
+
}
|
|
6047
|
+
const [requestCookies, requestHeaders] = await Promise.all([cookies(), headers()]);
|
|
6048
|
+
const onDemandContext = await createOnDemandContext({
|
|
6049
|
+
source: "pageState",
|
|
6050
|
+
cookies: requestCookies,
|
|
6051
|
+
dataClient: dataClient != null ? dataClient : new DefaultDataClient(),
|
|
6052
|
+
defaultConsent: pageState.defaultConsent
|
|
6053
|
+
});
|
|
6054
|
+
const context = await onDemandContext.getContext();
|
|
6055
|
+
await context.update({
|
|
6056
|
+
url: new URL((_a = pageState.requestPath) != null ? _a : pageState.routePath, REQUEST_ORIGIN_PLACEHOLDER),
|
|
6057
|
+
cookies: requestCookies.getAll().reduce(
|
|
6058
|
+
(acc, cookie) => {
|
|
6059
|
+
acc[cookie.name] = cookie.value;
|
|
6060
|
+
return acc;
|
|
6061
|
+
},
|
|
6062
|
+
{}
|
|
6063
|
+
),
|
|
6064
|
+
// Same precedence as the middleware: header-derived quirks first, then the custom quirks
|
|
6065
|
+
// the consumer passed to `handleUniformRoute`, which win on conflict.
|
|
6066
|
+
quirks: {
|
|
6067
|
+
...buildQuirksFromHeaders(requestHeaders),
|
|
6068
|
+
...pageState.quirks
|
|
6069
|
+
}
|
|
6070
|
+
});
|
|
6071
|
+
const { components, rules } = await evaluatePageState({
|
|
6072
|
+
composition,
|
|
6073
|
+
matchedRoute,
|
|
6074
|
+
dynamicInputs,
|
|
6075
|
+
pageState,
|
|
6076
|
+
context
|
|
6077
|
+
});
|
|
6078
|
+
return {
|
|
6079
|
+
...pageState,
|
|
6080
|
+
components,
|
|
6081
|
+
rules
|
|
6082
|
+
};
|
|
6083
|
+
};
|
|
6084
|
+
|
|
6085
|
+
// src/components/ComponentProps.ts
|
|
6086
|
+
import {
|
|
6087
|
+
resolveComponentFromPageState
|
|
6088
|
+
} from "@uniformdev/next-app-router-shared";
|
|
6089
|
+
var createComponentProps = ({
|
|
6090
|
+
component,
|
|
6091
|
+
parent,
|
|
6092
|
+
isRoot,
|
|
6093
|
+
slotName,
|
|
6094
|
+
slotIndex,
|
|
6095
|
+
slots,
|
|
6096
|
+
pageState,
|
|
6097
|
+
composition,
|
|
6098
|
+
compositionContext
|
|
6099
|
+
}) => {
|
|
6100
|
+
var _a, _b;
|
|
6101
|
+
const parameters = (_a = component.parameters) != null ? _a : {};
|
|
6102
|
+
const componentProps = {
|
|
6103
|
+
parameters: Object.keys(parameters).reduce((acc, cur) => {
|
|
6104
|
+
acc[cur] = {
|
|
6105
|
+
parameterId: cur,
|
|
6106
|
+
...parameters[cur]
|
|
6107
|
+
};
|
|
6108
|
+
return acc;
|
|
6109
|
+
}, {}),
|
|
6110
|
+
component: {
|
|
6111
|
+
_id: component._id,
|
|
6112
|
+
_parentId: (_b = parent == null ? void 0 : parent._id) != null ? _b : null,
|
|
6113
|
+
slotName,
|
|
6114
|
+
slotIndex: isRoot ? void 0 : slotIndex
|
|
6115
|
+
},
|
|
6116
|
+
type: component.type,
|
|
6117
|
+
variant: component.variant,
|
|
6118
|
+
slots,
|
|
6119
|
+
context: {
|
|
6120
|
+
isContextualEditing: pageState.compositionState === CANVAS_EDITOR_STATE,
|
|
6121
|
+
_id: composition._id,
|
|
6122
|
+
state: pageState.compositionState,
|
|
6123
|
+
type: composition.type,
|
|
6124
|
+
pageState,
|
|
6125
|
+
matchedRoute: compositionContext.matchedRoute,
|
|
6126
|
+
dynamicInputs: compositionContext.dynamicInputs
|
|
6127
|
+
}
|
|
6128
|
+
};
|
|
6129
|
+
return componentProps;
|
|
6130
|
+
};
|
|
6131
|
+
var createPersonalizeComponentProps = ({
|
|
6132
|
+
common,
|
|
6133
|
+
componentId,
|
|
6134
|
+
pageState
|
|
6135
|
+
}) => {
|
|
6136
|
+
var _a;
|
|
6137
|
+
const component = resolveComponentFromPageState({
|
|
6138
|
+
pageState,
|
|
6139
|
+
componentId
|
|
6140
|
+
});
|
|
6141
|
+
return {
|
|
6142
|
+
...common,
|
|
6143
|
+
indexes: (_a = component == null ? void 0 : component.indexes) != null ? _a : []
|
|
6144
|
+
};
|
|
6145
|
+
};
|
|
6146
|
+
var createTestComponentProps = ({
|
|
6147
|
+
common,
|
|
6148
|
+
componentId,
|
|
6149
|
+
pageState,
|
|
6150
|
+
test
|
|
6151
|
+
}) => {
|
|
6152
|
+
var _a;
|
|
6153
|
+
if (pageState.isPrefetch) {
|
|
6154
|
+
return {
|
|
6155
|
+
...common,
|
|
6156
|
+
index: void 0,
|
|
6157
|
+
test
|
|
6158
|
+
};
|
|
6159
|
+
}
|
|
6160
|
+
const component = resolveComponentFromPageState({
|
|
6161
|
+
pageState,
|
|
6162
|
+
componentId
|
|
6163
|
+
});
|
|
6164
|
+
const [testIndex] = (_a = component == null ? void 0 : component.indexes) != null ? _a : [];
|
|
6165
|
+
return {
|
|
6166
|
+
...common,
|
|
6167
|
+
index: testIndex,
|
|
6168
|
+
test
|
|
3110
6169
|
};
|
|
3111
6170
|
};
|
|
3112
6171
|
|
|
@@ -3175,61 +6234,9 @@ var Test = ({ index, slots, test, component, context: compositionContext }) => {
|
|
|
3175
6234
|
return createElement(Fragment, void 0, [indexToShow == null ? void 0 : indexToShow.component, eventElement]);
|
|
3176
6235
|
};
|
|
3177
6236
|
|
|
3178
|
-
// src/components/UniformCompositionWrapper.tsx
|
|
3179
|
-
import { deserializeEvaluationResult } from "@uniformdev/next-app-router-shared";
|
|
3180
|
-
import React2, { Fragment as Fragment2, Suspense } from "react";
|
|
3181
|
-
var UniformCompositionWrapper = ({
|
|
3182
|
-
code,
|
|
3183
|
-
children
|
|
3184
|
-
}) => {
|
|
3185
|
-
const data = deserializeEvaluationResult({ input: code });
|
|
3186
|
-
const WrapperComponent = data.compositionState === CANVAS_EDITOR_STATE || data.compositionState === CANVAS_DRAFT_STATE ? Suspense : Fragment2;
|
|
3187
|
-
return /* @__PURE__ */ React2.createElement(WrapperComponent, null, children);
|
|
3188
|
-
};
|
|
3189
|
-
|
|
3190
6237
|
// src/components/UniformContext.tsx
|
|
3191
6238
|
import { DefaultUniformClientContext } from "@uniformdev/next-app-router-client";
|
|
3192
|
-
import
|
|
3193
|
-
|
|
3194
|
-
// src/config/helpers.ts
|
|
3195
|
-
import config from "@uniformdev/next-app-router/config/resolved";
|
|
3196
|
-
var getDisabledDevTools = () => {
|
|
3197
|
-
var _a;
|
|
3198
|
-
if (typeof ((_a = config.context) == null ? void 0 : _a.disableDevTools) === "boolean") {
|
|
3199
|
-
return config.context.disableDevTools;
|
|
3200
|
-
}
|
|
3201
|
-
return false;
|
|
3202
|
-
};
|
|
3203
|
-
var getDefaultConsent = () => {
|
|
3204
|
-
if (typeof config.defaultConsent === "boolean") {
|
|
3205
|
-
return config.defaultConsent;
|
|
3206
|
-
}
|
|
3207
|
-
return false;
|
|
3208
|
-
};
|
|
3209
|
-
var getQuirkSerialization = () => {
|
|
3210
|
-
if (typeof config.quirkSerialization === "boolean") {
|
|
3211
|
-
return config.quirkSerialization;
|
|
3212
|
-
}
|
|
3213
|
-
return true;
|
|
3214
|
-
};
|
|
3215
|
-
var getMiddlewareRuntimeCache = () => {
|
|
3216
|
-
if (process.env.NODE_ENV === "development" && !process.env.RUNTIME_CACHE_ENDPOINT) {
|
|
3217
|
-
return false;
|
|
3218
|
-
}
|
|
3219
|
-
if (typeof config.middlewareRuntimeCache === "boolean") {
|
|
3220
|
-
return config.middlewareRuntimeCache;
|
|
3221
|
-
}
|
|
3222
|
-
return true;
|
|
3223
|
-
};
|
|
3224
|
-
var getDisableSwrMiddlewareCache = () => {
|
|
3225
|
-
var _a;
|
|
3226
|
-
if (typeof ((_a = config.experimental) == null ? void 0 : _a.disableSwrMiddlewareCache) === "boolean") {
|
|
3227
|
-
return config.experimental.disableSwrMiddlewareCache;
|
|
3228
|
-
}
|
|
3229
|
-
return false;
|
|
3230
|
-
};
|
|
3231
|
-
|
|
3232
|
-
// src/components/UniformContext.tsx
|
|
6239
|
+
import React2 from "react";
|
|
3233
6240
|
var UniformContext = async ({ clientContextComponent, result }) => {
|
|
3234
6241
|
var _a;
|
|
3235
6242
|
const manifest = await getManifest({
|
|
@@ -3245,7 +6252,7 @@ var UniformContext = async ({ clientContextComponent, result }) => {
|
|
|
3245
6252
|
const disableDevTools = getDisabledDevTools();
|
|
3246
6253
|
const defaultConsent = (_a = result == null ? void 0 : result.pageState.defaultConsent) != null ? _a : getDefaultConsent();
|
|
3247
6254
|
const experimentalQuirkSerialization = getQuirkSerialization();
|
|
3248
|
-
return /* @__PURE__ */
|
|
6255
|
+
return /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement(
|
|
3249
6256
|
ContextComponent,
|
|
3250
6257
|
{
|
|
3251
6258
|
manifest,
|
|
@@ -3259,18 +6266,18 @@ var UniformContext = async ({ clientContextComponent, result }) => {
|
|
|
3259
6266
|
|
|
3260
6267
|
// src/components/VisibilityRulesWrapper.tsx
|
|
3261
6268
|
import { VisibilityRulesWrapperClient } from "@uniformdev/next-app-router-client";
|
|
3262
|
-
import
|
|
6269
|
+
import React3 from "react";
|
|
3263
6270
|
var VisibilityRulesWrapper = ({
|
|
3264
6271
|
parameter,
|
|
3265
6272
|
initialIsVisible,
|
|
3266
6273
|
children
|
|
3267
6274
|
}) => {
|
|
3268
|
-
return /* @__PURE__ */
|
|
6275
|
+
return /* @__PURE__ */ React3.createElement(VisibilityRulesWrapperClient, { parameter, initialIsVisible }, children);
|
|
3269
6276
|
};
|
|
3270
6277
|
|
|
3271
6278
|
// src/components/UniformComposition.tsx
|
|
3272
6279
|
function UniformComposition({ code, ...props }) {
|
|
3273
|
-
return /* @__PURE__ */
|
|
6280
|
+
return /* @__PURE__ */ React4.createElement(UniformCompositionInner, { code, ...props });
|
|
3274
6281
|
}
|
|
3275
6282
|
async function UniformCompositionInner({
|
|
3276
6283
|
code,
|
|
@@ -3281,7 +6288,7 @@ async function UniformCompositionInner({
|
|
|
3281
6288
|
clientContextComponent,
|
|
3282
6289
|
dataClient
|
|
3283
6290
|
}) {
|
|
3284
|
-
var _a, _b;
|
|
6291
|
+
var _a, _b, _c;
|
|
3285
6292
|
const result = await resolveRoute({
|
|
3286
6293
|
code,
|
|
3287
6294
|
dataClient
|
|
@@ -3289,8 +6296,15 @@ async function UniformCompositionInner({
|
|
|
3289
6296
|
if (!(result == null ? void 0 : result.route) || ((_a = result == null ? void 0 : result.route) == null ? void 0 : _a.type) !== "composition") {
|
|
3290
6297
|
notFound();
|
|
3291
6298
|
}
|
|
3292
|
-
const {
|
|
6299
|
+
const { route } = result;
|
|
3293
6300
|
const composition = result.route.compositionApiResponse.composition;
|
|
6301
|
+
const pageState = await evaluateDraftPageState({
|
|
6302
|
+
pageState: result.pageState,
|
|
6303
|
+
composition,
|
|
6304
|
+
matchedRoute: route.matchedRoute,
|
|
6305
|
+
dynamicInputs: (_b = route.dynamicInputs) != null ? _b : {},
|
|
6306
|
+
dataClient
|
|
6307
|
+
});
|
|
3294
6308
|
applyEditableParameters({
|
|
3295
6309
|
composition,
|
|
3296
6310
|
state: route.compositionApiResponse.state
|
|
@@ -3302,7 +6316,7 @@ async function UniformCompositionInner({
|
|
|
3302
6316
|
state: pageState.compositionState,
|
|
3303
6317
|
isContextualEditing: pageState.compositionState === CANVAS_EDITOR_STATE,
|
|
3304
6318
|
matchedRoute: route.matchedRoute,
|
|
3305
|
-
dynamicInputs: (
|
|
6319
|
+
dynamicInputs: (_c = route.dynamicInputs) != null ? _c : {},
|
|
3306
6320
|
pageState
|
|
3307
6321
|
};
|
|
3308
6322
|
const [resolved] = resolveComponents({
|
|
@@ -3318,7 +6332,7 @@ async function UniformCompositionInner({
|
|
|
3318
6332
|
composition,
|
|
3319
6333
|
compositionContext
|
|
3320
6334
|
});
|
|
3321
|
-
return /* @__PURE__ */
|
|
6335
|
+
return /* @__PURE__ */ React4.createElement(React4.Fragment, null, resolved, /* @__PURE__ */ React4.createElement(Suspense, null, /* @__PURE__ */ React4.createElement(
|
|
3322
6336
|
UniformContext,
|
|
3323
6337
|
{
|
|
3324
6338
|
clientContextComponent,
|
|
@@ -3328,7 +6342,7 @@ async function UniformCompositionInner({
|
|
|
3328
6342
|
route
|
|
3329
6343
|
}
|
|
3330
6344
|
}
|
|
3331
|
-
)), (pageState.compositionState === CANVAS_EDITOR_STATE || pageState.compositionState === CANVAS_DRAFT_STATE) && /* @__PURE__ */
|
|
6345
|
+
)), (pageState.compositionState === CANVAS_EDITOR_STATE || pageState.compositionState === CANVAS_DRAFT_STATE) && /* @__PURE__ */ React4.createElement(UniformScript, null));
|
|
3332
6346
|
}
|
|
3333
6347
|
var resolveComponents = ({
|
|
3334
6348
|
target,
|
|
@@ -3406,7 +6420,7 @@ var resolveComponents = ({
|
|
|
3406
6420
|
let element = null;
|
|
3407
6421
|
if (wrapInSuspense) {
|
|
3408
6422
|
element = createElement2(
|
|
3409
|
-
|
|
6423
|
+
Suspense,
|
|
3410
6424
|
{
|
|
3411
6425
|
key,
|
|
3412
6426
|
fallback: typeof wrapInSuspense === "boolean" || typeof (wrapInSuspense == null ? void 0 : wrapInSuspense.fallback) === "undefined" ? void 0 : createElement2(wrapInSuspense.fallback)
|
|
@@ -3477,7 +6491,7 @@ var resolveComponents = ({
|
|
|
3477
6491
|
);
|
|
3478
6492
|
}
|
|
3479
6493
|
return createElement2(
|
|
3480
|
-
|
|
6494
|
+
Fragment2,
|
|
3481
6495
|
{
|
|
3482
6496
|
key: !isRoot ? `${slotName}-${componentIndex}` : void 0
|
|
3483
6497
|
},
|
|
@@ -3578,154 +6592,59 @@ var resolveSlots = ({
|
|
|
3578
6592
|
|
|
3579
6593
|
// src/components/UniformPlayground.tsx
|
|
3580
6594
|
import { draftMode } from "next/headers";
|
|
3581
|
-
import
|
|
6595
|
+
import React5 from "react";
|
|
3582
6596
|
|
|
3583
6597
|
// src/data/resolvePlaygroundRoute.ts
|
|
3584
|
-
import { deserializeEvaluationResult
|
|
3585
|
-
var resolvePlaygroundRoute = async ({ code }) => {
|
|
3586
|
-
const pageState =
|
|
3587
|
-
const canvasClient = getCompositionDeliveryClient({
|
|
3588
|
-
cache: {
|
|
3589
|
-
type: "no-cache"
|
|
3590
|
-
}
|
|
3591
|
-
});
|
|
3592
|
-
let composition = void 0;
|
|
3593
|
-
try {
|
|
3594
|
-
composition = await canvasClient.get({
|
|
3595
|
-
compositionId: pageState.routePath,
|
|
3596
|
-
state: pageState.compositionState,
|
|
3597
|
-
withComponentIDs: true
|
|
3598
|
-
});
|
|
3599
|
-
} catch (e) {
|
|
3600
|
-
console.warn(
|
|
3601
|
-
`Failed to get composition ${pageState.routePath} with state ${pageState.compositionState}`,
|
|
3602
|
-
e
|
|
3603
|
-
);
|
|
3604
|
-
}
|
|
3605
|
-
if (!composition) {
|
|
3606
|
-
return {
|
|
3607
|
-
code,
|
|
3608
|
-
pageState,
|
|
3609
|
-
route: void 0
|
|
3610
|
-
};
|
|
3611
|
-
}
|
|
3612
|
-
return {
|
|
3613
|
-
code,
|
|
3614
|
-
pageState,
|
|
3615
|
-
route: {
|
|
3616
|
-
type: "composition",
|
|
3617
|
-
compositionApiResponse: composition,
|
|
3618
|
-
matchedRoute: "composition"
|
|
3619
|
-
}
|
|
3620
|
-
};
|
|
3621
|
-
};
|
|
3622
|
-
|
|
3623
|
-
// src/components/UniformPlayground.tsx
|
|
3624
|
-
var UniformPlayground = async ({ resolveRoute, ...rest }) => {
|
|
3625
|
-
const isDraftMode = (await draftMode()).isEnabled;
|
|
3626
|
-
if (!isDraftMode) {
|
|
3627
|
-
return /* @__PURE__ */ React6.createElement("div", null, /* @__PURE__ */ React6.createElement("h1", null, "Playground is only available in draft mode"));
|
|
3628
|
-
}
|
|
3629
|
-
return /* @__PURE__ */ React6.createElement(UniformComposition, { ...rest, resolveRoute: resolvePlaygroundRoute });
|
|
3630
|
-
};
|
|
3631
|
-
|
|
3632
|
-
// src/components/generateStaticParams.ts
|
|
3633
|
-
import { serializeEvaluationResult } from "@uniformdev/next-app-router-shared";
|
|
3634
|
-
|
|
3635
|
-
// src/data/extract/extractRunnables.ts
|
|
3636
|
-
import { getRuleId } from "@uniformdev/next-app-router-shared";
|
|
3637
|
-
|
|
3638
|
-
// src/data/extract/extractPersonalization.ts
|
|
3639
|
-
import {
|
|
3640
|
-
extractPersonalizationName
|
|
3641
|
-
} from "@uniformdev/next-app-router-shared";
|
|
3642
|
-
var extractPersonalization = ({
|
|
3643
|
-
component
|
|
3644
|
-
}) => {
|
|
3645
|
-
var _a, _b, _c;
|
|
3646
|
-
const trackingEventName = extractPersonalizationName({ component });
|
|
3647
|
-
const countParameter = (_a = component.parameters) == null ? void 0 : _a.count;
|
|
3648
|
-
const algorithmParameter = (_b = component.parameters) == null ? void 0 : _b.algorithm;
|
|
3649
|
-
const count = countParameter == null ? void 0 : countParameter.value;
|
|
3650
|
-
const algorithm = algorithmParameter == null ? void 0 : algorithmParameter.value;
|
|
3651
|
-
let parsedCount;
|
|
3652
|
-
if (typeof count === "string") {
|
|
3653
|
-
parsedCount = parseInt(count, 10);
|
|
3654
|
-
} else if (typeof count !== "number") {
|
|
3655
|
-
parsedCount = void 0;
|
|
3656
|
-
} else {
|
|
3657
|
-
parsedCount = count || 1;
|
|
3658
|
-
}
|
|
3659
|
-
const slot = ((_c = component.slots) == null ? void 0 : _c[CANVAS_PERSONALIZE_SLOT]) || [];
|
|
3660
|
-
const componentVariations = mapSlotToPersonalizedVariations(
|
|
3661
|
-
slot
|
|
3662
|
-
).map((variant, index) => {
|
|
3663
|
-
const slotComponent = slot[index];
|
|
3664
|
-
if (!slotComponent) {
|
|
3665
|
-
throw new Error(`Slot component not found for index ${index}`);
|
|
6598
|
+
import { deserializeEvaluationResult } from "@uniformdev/next-app-router-shared";
|
|
6599
|
+
var resolvePlaygroundRoute = async ({ code }) => {
|
|
6600
|
+
const pageState = deserializeEvaluationResult({ input: code });
|
|
6601
|
+
const canvasClient = getCompositionDeliveryClient({
|
|
6602
|
+
cache: {
|
|
6603
|
+
type: "no-cache"
|
|
3666
6604
|
}
|
|
6605
|
+
});
|
|
6606
|
+
let composition = void 0;
|
|
6607
|
+
try {
|
|
6608
|
+
composition = await canvasClient.get({
|
|
6609
|
+
compositionId: pageState.routePath,
|
|
6610
|
+
state: pageState.compositionState,
|
|
6611
|
+
withComponentIDs: true
|
|
6612
|
+
});
|
|
6613
|
+
} catch (e) {
|
|
6614
|
+
console.warn(
|
|
6615
|
+
`Failed to get composition ${pageState.routePath} with state ${pageState.compositionState}`,
|
|
6616
|
+
e
|
|
6617
|
+
);
|
|
6618
|
+
}
|
|
6619
|
+
if (!composition) {
|
|
3667
6620
|
return {
|
|
3668
|
-
|
|
3669
|
-
|
|
3670
|
-
|
|
6621
|
+
code,
|
|
6622
|
+
pageState,
|
|
6623
|
+
route: void 0
|
|
3671
6624
|
};
|
|
3672
|
-
}
|
|
6625
|
+
}
|
|
3673
6626
|
return {
|
|
3674
|
-
|
|
3675
|
-
|
|
3676
|
-
|
|
3677
|
-
|
|
6627
|
+
code,
|
|
6628
|
+
pageState,
|
|
6629
|
+
route: {
|
|
6630
|
+
type: "composition",
|
|
6631
|
+
compositionApiResponse: composition,
|
|
6632
|
+
matchedRoute: "composition"
|
|
6633
|
+
}
|
|
3678
6634
|
};
|
|
3679
6635
|
};
|
|
3680
6636
|
|
|
3681
|
-
// src/
|
|
3682
|
-
var
|
|
3683
|
-
|
|
3684
|
-
|
|
3685
|
-
|
|
3686
|
-
return node.node._id;
|
|
3687
|
-
}
|
|
6637
|
+
// src/components/UniformPlayground.tsx
|
|
6638
|
+
var UniformPlayground = async ({ resolveRoute, ...rest }) => {
|
|
6639
|
+
const isDraftMode = (await draftMode()).isEnabled;
|
|
6640
|
+
if (!isDraftMode) {
|
|
6641
|
+
return /* @__PURE__ */ React5.createElement("div", null, /* @__PURE__ */ React5.createElement("h1", null, "Playground is only available in draft mode"));
|
|
3688
6642
|
}
|
|
3689
|
-
return
|
|
3690
|
-
};
|
|
3691
|
-
var extractRunnables = (composition) => {
|
|
3692
|
-
const runnable = [];
|
|
3693
|
-
walkNodeTree(composition, (node) => {
|
|
3694
|
-
var _a, _b;
|
|
3695
|
-
if (node.type === "component") {
|
|
3696
|
-
const component = node.node;
|
|
3697
|
-
const visibilityRules = (_b = (_a = component.parameters) == null ? void 0 : _a[CANVAS_VIZ_CONTROL_PARAM]) == null ? void 0 : _b.value;
|
|
3698
|
-
if (component.type === CANVAS_TEST_TYPE) {
|
|
3699
|
-
const test = extractTest({ component });
|
|
3700
|
-
runnable.push({
|
|
3701
|
-
_id: component._id,
|
|
3702
|
-
variantId: findAncestorVariant(node.ancestorsAndSelf),
|
|
3703
|
-
type: "test",
|
|
3704
|
-
result: test
|
|
3705
|
-
});
|
|
3706
|
-
} else if (component.type === CANVAS_PERSONALIZE_TYPE) {
|
|
3707
|
-
const personalize = extractPersonalization({ component });
|
|
3708
|
-
runnable.push({
|
|
3709
|
-
type: "personalization",
|
|
3710
|
-
variantId: findAncestorVariant(node.ancestorsAndSelf),
|
|
3711
|
-
_id: component._id,
|
|
3712
|
-
result: personalize
|
|
3713
|
-
});
|
|
3714
|
-
}
|
|
3715
|
-
if (visibilityRules) {
|
|
3716
|
-
runnable.push({
|
|
3717
|
-
type: "visibility",
|
|
3718
|
-
_id: getRuleId(visibilityRules),
|
|
3719
|
-
variantId: findAncestorVariant(node.ancestorsAndSelf),
|
|
3720
|
-
rules: visibilityRules
|
|
3721
|
-
});
|
|
3722
|
-
}
|
|
3723
|
-
}
|
|
3724
|
-
});
|
|
3725
|
-
return runnable;
|
|
6643
|
+
return /* @__PURE__ */ React5.createElement(UniformComposition, { ...rest, resolveRoute: resolvePlaygroundRoute });
|
|
3726
6644
|
};
|
|
3727
6645
|
|
|
3728
6646
|
// src/components/generateStaticParams.ts
|
|
6647
|
+
import { serializeEvaluationResult } from "@uniformdev/next-app-router-shared";
|
|
3729
6648
|
var createUniformPlaygroundStaticParams = async (options) => {
|
|
3730
6649
|
var _a;
|
|
3731
6650
|
const { paths } = options;
|
|
@@ -3978,173 +6897,6 @@ function generateAllGroupPermutations(groups) {
|
|
|
3978
6897
|
return combineAcrossGroups(perGroupSelections);
|
|
3979
6898
|
}
|
|
3980
6899
|
|
|
3981
|
-
// src/data/client.ts
|
|
3982
|
-
import { getCache, waitUntil } from "@vercel/functions";
|
|
3983
|
-
var MANIFEST_CACHE_KEY = "uniform-manifest";
|
|
3984
|
-
var DefaultDataClient = class {
|
|
3985
|
-
async getManifest(options) {
|
|
3986
|
-
const cache2 = options.source === "middleware" && getMiddlewareRuntimeCache() ? getCache() : null;
|
|
3987
|
-
if (cache2) {
|
|
3988
|
-
const cachedManifest = await cache2.get(MANIFEST_CACHE_KEY);
|
|
3989
|
-
if (cachedManifest) {
|
|
3990
|
-
return cachedManifest;
|
|
3991
|
-
}
|
|
3992
|
-
}
|
|
3993
|
-
const manifest = await getManifest({
|
|
3994
|
-
cache: isDevelopmentEnvironment() ? {
|
|
3995
|
-
type: "no-cache",
|
|
3996
|
-
bypassCache: true
|
|
3997
|
-
} : {
|
|
3998
|
-
type: "force-cache"
|
|
3999
|
-
}
|
|
4000
|
-
});
|
|
4001
|
-
if (cache2) {
|
|
4002
|
-
waitUntil(
|
|
4003
|
-
(async () => {
|
|
4004
|
-
await cache2.set(MANIFEST_CACHE_KEY, manifest, {
|
|
4005
|
-
tags: generateManifestCacheTags()
|
|
4006
|
-
});
|
|
4007
|
-
})()
|
|
4008
|
-
);
|
|
4009
|
-
}
|
|
4010
|
-
return manifest;
|
|
4011
|
-
}
|
|
4012
|
-
async getRouteFromApi({
|
|
4013
|
-
route,
|
|
4014
|
-
routeClient,
|
|
4015
|
-
enableRuntimeCache,
|
|
4016
|
-
disableSwrCache
|
|
4017
|
-
}) {
|
|
4018
|
-
const newCacheKey = `uniform-route-${route.state}-${route.releaseId}-${route.path}`;
|
|
4019
|
-
const oldCacheKey = `uniform-route-old-${route.state}-${route.releaseId}-${route.path}`;
|
|
4020
|
-
const cache2 = enableRuntimeCache ? getCache() : null;
|
|
4021
|
-
const cacheNewRoute = async (result2) => {
|
|
4022
|
-
if (cache2 && result2.type === "composition") {
|
|
4023
|
-
const tags = generateRouteCacheTags({ path: route.path });
|
|
4024
|
-
await cache2.set(newCacheKey, result2, {
|
|
4025
|
-
tags
|
|
4026
|
-
});
|
|
4027
|
-
}
|
|
4028
|
-
};
|
|
4029
|
-
const cacheOldRoute = async (result2) => {
|
|
4030
|
-
if (cache2 && result2.type === "composition" && !disableSwrCache) {
|
|
4031
|
-
const tags = generateRouteCacheTags({ path: route.path, old: true });
|
|
4032
|
-
await cache2.set(oldCacheKey, result2, {
|
|
4033
|
-
tags
|
|
4034
|
-
});
|
|
4035
|
-
}
|
|
4036
|
-
};
|
|
4037
|
-
if (cache2) {
|
|
4038
|
-
const [cachedRoute, oldCachedRoute] = await Promise.all([
|
|
4039
|
-
cache2.get(newCacheKey),
|
|
4040
|
-
disableSwrCache ? null : cache2.get(oldCacheKey)
|
|
4041
|
-
]);
|
|
4042
|
-
if (cachedRoute) {
|
|
4043
|
-
return cachedRoute;
|
|
4044
|
-
}
|
|
4045
|
-
if (oldCachedRoute) {
|
|
4046
|
-
waitUntil(
|
|
4047
|
-
(async () => {
|
|
4048
|
-
const result2 = await routeClient.get(route);
|
|
4049
|
-
await cacheNewRoute(result2);
|
|
4050
|
-
})()
|
|
4051
|
-
);
|
|
4052
|
-
return oldCachedRoute;
|
|
4053
|
-
}
|
|
4054
|
-
}
|
|
4055
|
-
const result = await routeClient.get(route);
|
|
4056
|
-
waitUntil(
|
|
4057
|
-
(async () => {
|
|
4058
|
-
await Promise.all([
|
|
4059
|
-
cacheNewRoute(result),
|
|
4060
|
-
disableSwrCache ? Promise.resolve() : cacheOldRoute(result)
|
|
4061
|
-
]);
|
|
4062
|
-
})()
|
|
4063
|
-
);
|
|
4064
|
-
return result;
|
|
4065
|
-
}
|
|
4066
|
-
async getRoute(options) {
|
|
4067
|
-
if (options.source === "middleware") {
|
|
4068
|
-
return this.getRouteMiddleware(options);
|
|
4069
|
-
}
|
|
4070
|
-
return this.getRoutePageState(options);
|
|
4071
|
-
}
|
|
4072
|
-
async enhanceRoute(_options) {
|
|
4073
|
-
}
|
|
4074
|
-
async getRouteMiddleware(options) {
|
|
4075
|
-
const routeClient = getRouteClient({
|
|
4076
|
-
searchParams: options.searchParams,
|
|
4077
|
-
draftModeEnabled: options.draftModeEnabled
|
|
4078
|
-
});
|
|
4079
|
-
const resolvedRoute = await this.getRouteFromApi({
|
|
4080
|
-
source: "middleware",
|
|
4081
|
-
route: options.route,
|
|
4082
|
-
routeClient,
|
|
4083
|
-
enableRuntimeCache: options.route.state === CANVAS_PUBLISHED_STATE && getMiddlewareRuntimeCache(),
|
|
4084
|
-
disableSwrCache: getDisableSwrMiddlewareCache()
|
|
4085
|
-
});
|
|
4086
|
-
if (resolvedRoute.type === "composition") {
|
|
4087
|
-
await this.enhanceRoute({
|
|
4088
|
-
source: "middleware",
|
|
4089
|
-
parameters: options.route,
|
|
4090
|
-
route: resolvedRoute,
|
|
4091
|
-
routeClient,
|
|
4092
|
-
keys: void 0
|
|
4093
|
-
});
|
|
4094
|
-
}
|
|
4095
|
-
return {
|
|
4096
|
-
route: resolvedRoute
|
|
4097
|
-
};
|
|
4098
|
-
}
|
|
4099
|
-
async getRoutePageState(options) {
|
|
4100
|
-
const shouldBypassCache = options.pageState.compositionState !== CANVAS_PUBLISHED_STATE || isDevelopmentEnvironment();
|
|
4101
|
-
const routeClient = getRouteClient({
|
|
4102
|
-
cache: shouldBypassCache ? {
|
|
4103
|
-
type: "no-cache",
|
|
4104
|
-
bypassCache: true
|
|
4105
|
-
} : {
|
|
4106
|
-
type: "force-cache"
|
|
4107
|
-
}
|
|
4108
|
-
});
|
|
4109
|
-
const originalRoute = {
|
|
4110
|
-
path: options.pageState.routePath,
|
|
4111
|
-
state: options.pageState.compositionState,
|
|
4112
|
-
dataSourceVariant: getDataSourceVariantFromRouteGetParams({}, options.pageState.compositionState),
|
|
4113
|
-
withComponentIDs: true,
|
|
4114
|
-
releaseId: options.pageState.releaseId,
|
|
4115
|
-
locale: options.pageState.locale,
|
|
4116
|
-
ignoreRedirects: shouldIgnoreRedirects({ state: options.pageState.compositionState })
|
|
4117
|
-
};
|
|
4118
|
-
const resolvedRoute = await this.getRouteFromApi({
|
|
4119
|
-
source: "pageState",
|
|
4120
|
-
route: originalRoute,
|
|
4121
|
-
routeClient,
|
|
4122
|
-
enableRuntimeCache: false,
|
|
4123
|
-
disableSwrCache: false
|
|
4124
|
-
});
|
|
4125
|
-
if (resolvedRoute.type === "composition") {
|
|
4126
|
-
await this.enhanceRoute({
|
|
4127
|
-
source: "pageState",
|
|
4128
|
-
parameters: originalRoute,
|
|
4129
|
-
route: resolvedRoute,
|
|
4130
|
-
routeClient,
|
|
4131
|
-
keys: options.pageState.keys
|
|
4132
|
-
});
|
|
4133
|
-
}
|
|
4134
|
-
return {
|
|
4135
|
-
route: resolvedRoute
|
|
4136
|
-
};
|
|
4137
|
-
}
|
|
4138
|
-
};
|
|
4139
|
-
var expireMiddlewareCacheTag = async (tag) => {
|
|
4140
|
-
const cache2 = getMiddlewareRuntimeCache() ? getCache() : null;
|
|
4141
|
-
if (cache2) {
|
|
4142
|
-
await cache2.expireTag(tag);
|
|
4143
|
-
} else {
|
|
4144
|
-
console.warn("Middleware cache is not enabled, cannot clear cache tag", tag);
|
|
4145
|
-
}
|
|
4146
|
-
};
|
|
4147
|
-
|
|
4148
6900
|
// src/data/precomputeComposition.ts
|
|
4149
6901
|
import {
|
|
4150
6902
|
extractPersonalizationName as extractPersonalizationName2,
|
|
@@ -4218,12 +6970,12 @@ var precomputeComposition = ({
|
|
|
4218
6970
|
};
|
|
4219
6971
|
|
|
4220
6972
|
// src/data/resolveRouteFromCode.ts
|
|
4221
|
-
import { deserializeEvaluationResult as
|
|
6973
|
+
import { deserializeEvaluationResult as deserializeEvaluationResult2 } from "@uniformdev/next-app-router-shared";
|
|
4222
6974
|
var resolveRouteFromCode = async ({
|
|
4223
6975
|
code,
|
|
4224
6976
|
dataClient: providedDataClient
|
|
4225
6977
|
}) => {
|
|
4226
|
-
const pageState =
|
|
6978
|
+
const pageState = deserializeEvaluationResult2({ input: code });
|
|
4227
6979
|
const dataClient = providedDataClient != null ? providedDataClient : new DefaultDataClient();
|
|
4228
6980
|
const { route } = await dataClient.getRoute({
|
|
4229
6981
|
source: "pageState",
|
|
@@ -4335,3 +7087,8 @@ export {
|
|
|
4335
7087
|
resolveRouteFromCode,
|
|
4336
7088
|
serverContext
|
|
4337
7089
|
};
|
|
7090
|
+
/*! Bundled license information:
|
|
7091
|
+
|
|
7092
|
+
js-cookie/dist/js.cookie.mjs:
|
|
7093
|
+
(*! js-cookie v3.0.8 | MIT *)
|
|
7094
|
+
*/
|