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