@splithub/core 0.1.9 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-MQCAGUUJ.js → chunk-XTJVALWN.js} +337 -44
- package/dist/chunk-XTJVALWN.js.map +1 -0
- package/dist/index.cjs +369 -43
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +120 -7
- package/dist/index.d.ts +120 -7
- package/dist/index.js +46 -1
- package/dist/index.js.map +1 -1
- package/dist/{types-C9OHv2W2.d.cts → types-BibC0pt1.d.cts} +85 -3
- package/dist/{types-C9OHv2W2.d.ts → types-BibC0pt1.d.ts} +85 -3
- package/dist/vite.cjs +8 -1
- package/dist/vite.cjs.map +1 -1
- package/dist/vite.d.cts +1 -1
- package/dist/vite.d.ts +1 -1
- package/dist/vite.js +1 -1
- package/package.json +10 -2
- package/dist/chunk-MQCAGUUJ.js.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -24,7 +24,9 @@ __export(index_exports, {
|
|
|
24
24
|
ConfigError: () => ConfigError,
|
|
25
25
|
EMPTY_OVERRIDES: () => EMPTY_OVERRIDES,
|
|
26
26
|
EventQueue: () => EventQueue,
|
|
27
|
+
HOLDOUT_KEY: () => HOLDOUT_KEY,
|
|
27
28
|
KEYED_FIELDS: () => KEYED_FIELDS,
|
|
29
|
+
LAYER_BUCKETS: () => LAYER_BUCKETS,
|
|
28
30
|
MVT_MAX_COMBINATIONS: () => MVT_MAX_COMBINATIONS,
|
|
29
31
|
MVT_MAX_FACTORS: () => MVT_MAX_FACTORS,
|
|
30
32
|
MVT_MAX_LEVELS: () => MVT_MAX_LEVELS,
|
|
@@ -38,10 +40,12 @@ __export(index_exports, {
|
|
|
38
40
|
browserContext: () => browserContext,
|
|
39
41
|
contextValue: () => contextValue,
|
|
40
42
|
controlVariant: () => controlVariant,
|
|
43
|
+
countsForHoldout: () => countsForHoldout,
|
|
41
44
|
createClient: () => createClient,
|
|
42
45
|
createFetchTransport: () => createFetchTransport,
|
|
43
46
|
debugLog: () => debugLog,
|
|
44
47
|
debugMode: () => debugMode,
|
|
48
|
+
decideRedirect: () => decideRedirect,
|
|
45
49
|
defineConfig: () => defineConfig,
|
|
46
50
|
devNote: () => devNote,
|
|
47
51
|
evaluateCondition: () => evaluateCondition,
|
|
@@ -52,26 +56,36 @@ __export(index_exports, {
|
|
|
52
56
|
getOrCreateVisitorId: () => getOrCreateVisitorId,
|
|
53
57
|
hasVisitorId: () => hasVisitorId,
|
|
54
58
|
hashToUnit: () => hashToUnit,
|
|
59
|
+
holdoutExperiment: () => holdoutExperiment,
|
|
60
|
+
holdoutGroup: () => holdoutGroup,
|
|
61
|
+
inLayer: () => inLayer,
|
|
55
62
|
inSchedule: () => inSchedule,
|
|
56
63
|
isActive: () => isActive,
|
|
64
|
+
isBot: () => isBot,
|
|
57
65
|
isBrowser: () => isBrowser,
|
|
66
|
+
isCrawler: () => isCrawler,
|
|
58
67
|
isDebug: () => isDebug,
|
|
59
68
|
isDevDraft: () => isDevDraft,
|
|
60
69
|
isDevEnvironment: () => isDevEnvironment,
|
|
61
70
|
isRemoteOverrides: () => isRemoteOverrides,
|
|
62
71
|
isSplitHubConfig: () => isSplitHubConfig,
|
|
72
|
+
layerBucket: () => layerBucket,
|
|
63
73
|
matchConditions: () => matchConditions,
|
|
74
|
+
matchPath: () => matchPath,
|
|
75
|
+
measuredGoals: () => measuredGoals,
|
|
64
76
|
murmur3: () => murmur3,
|
|
65
77
|
mvtVariants: () => mvtVariants,
|
|
66
78
|
newId: () => newId,
|
|
67
79
|
newSessionId: () => newSessionId,
|
|
68
80
|
newVisitorId: () => newVisitorId,
|
|
81
|
+
normalizePath: () => normalizePath,
|
|
69
82
|
onDebug: () => onDebug,
|
|
70
83
|
parseCookies: () => parseCookies,
|
|
71
84
|
parseForceParam: () => parseForceParam,
|
|
72
85
|
parseUserAgent: () => parseUserAgent,
|
|
73
86
|
pickVariant: () => pickVariant,
|
|
74
87
|
readRemoteCache: () => readRemoteCache,
|
|
88
|
+
redirectTarget: () => redirectTarget,
|
|
75
89
|
resetDevNotes: () => resetDevNotes,
|
|
76
90
|
resolveOverridesUrl: () => resolveOverridesUrl,
|
|
77
91
|
runFlow: () => runFlow,
|
|
@@ -145,6 +159,28 @@ var TARGET_FIELDS = ["country", "region", "city", "device", "browser", "os", "la
|
|
|
145
159
|
var TARGET_OPS = ["is", "is_not", "contains", "not_contains", "starts_with", "in", "not_in", "matches", "exists", "not_exists"];
|
|
146
160
|
var KEYED_FIELDS = ["query", "cookie"];
|
|
147
161
|
var MAX_STEPS = 64;
|
|
162
|
+
var WEEKDAYS = ["sun", "mon", "tue", "wed", "thu", "fri", "sat"];
|
|
163
|
+
var formatters = /* @__PURE__ */ new Map();
|
|
164
|
+
function localClock(ctx) {
|
|
165
|
+
const d = new Date(ctx.now ?? Date.now());
|
|
166
|
+
const tz = ctx.timezone;
|
|
167
|
+
let f = tz ? formatters.get(tz) : null;
|
|
168
|
+
if (tz && f === void 0) {
|
|
169
|
+
try {
|
|
170
|
+
f = new Intl.DateTimeFormat("en-US", { timeZone: tz, hour: "numeric", hourCycle: "h23", weekday: "short" });
|
|
171
|
+
} catch {
|
|
172
|
+
f = null;
|
|
173
|
+
}
|
|
174
|
+
formatters.set(tz, f);
|
|
175
|
+
}
|
|
176
|
+
if (f) {
|
|
177
|
+
const parts = f.formatToParts(d);
|
|
178
|
+
const hour = Number(parts.find((p) => p.type === "hour")?.value);
|
|
179
|
+
const weekday = WEEKDAYS.indexOf((parts.find((p) => p.type === "weekday")?.value ?? "").slice(0, 3).toLowerCase());
|
|
180
|
+
if (hour >= 0 && hour < 24 && weekday >= 0) return { hour, weekday };
|
|
181
|
+
}
|
|
182
|
+
return { hour: d.getUTCHours(), weekday: d.getUTCDay() };
|
|
183
|
+
}
|
|
148
184
|
function queryParam(url, name) {
|
|
149
185
|
if (!url) return void 0;
|
|
150
186
|
const q = url.indexOf("?");
|
|
@@ -194,16 +230,12 @@ function contextValue(field, key, ctx) {
|
|
|
194
230
|
case "cookie":
|
|
195
231
|
v = key ? ctx.cookies?.[key] : void 0;
|
|
196
232
|
break;
|
|
197
|
-
case "hour":
|
|
198
|
-
|
|
199
|
-
v = d.getUTCHours();
|
|
233
|
+
case "hour":
|
|
234
|
+
v = localClock(ctx).hour;
|
|
200
235
|
break;
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
const d = ctx.now ? new Date(ctx.now) : /* @__PURE__ */ new Date();
|
|
204
|
-
v = ["sun", "mon", "tue", "wed", "thu", "fri", "sat"][d.getUTCDay()];
|
|
236
|
+
case "weekday":
|
|
237
|
+
v = WEEKDAYS[localClock(ctx).weekday];
|
|
205
238
|
break;
|
|
206
|
-
}
|
|
207
239
|
}
|
|
208
240
|
return v === void 0 || v === null ? void 0 : String(v).toLowerCase();
|
|
209
241
|
}
|
|
@@ -338,13 +370,21 @@ function validateFlow(flow, variantKeys) {
|
|
|
338
370
|
}
|
|
339
371
|
return null;
|
|
340
372
|
}
|
|
373
|
+
var BOT_UA = /bot|crawl|spider|slurp|headless|lighthouse|pingdom|facebookexternalhit|google-inspectiontool|bingpreview|mediapartners|ahrefs|semrush|phantomjs|python-requests|curl\/|wget\//i;
|
|
341
374
|
function parseUserAgent(ua) {
|
|
342
375
|
const s = ua ?? "";
|
|
343
|
-
const device =
|
|
376
|
+
const device = BOT_UA.test(s) ? "bot" : /iPad|Tablet|PlayBook|Silk/i.test(s) || /Android/i.test(s) && !/Mobile/i.test(s) ? "tablet" : /Mobi|iPhone|iPod|Android|BlackBerry|Opera Mini|IEMobile/i.test(s) ? "mobile" : "desktop";
|
|
344
377
|
const browser = /Edg\//i.test(s) ? "edge" : /OPR\/|Opera/i.test(s) ? "opera" : /SamsungBrowser/i.test(s) ? "samsung" : /Firefox\//i.test(s) ? "firefox" : /Chrome\/|CriOS/i.test(s) ? "chrome" : /Safari\//i.test(s) && /Version\//i.test(s) ? "safari" : s ? "other" : "unknown";
|
|
345
378
|
const os = /Windows/i.test(s) ? "windows" : /iPhone|iPad|iPod/i.test(s) ? "ios" : /Android/i.test(s) ? "android" : /Mac OS X|Macintosh/i.test(s) ? "macos" : /CrOS/i.test(s) ? "chromeos" : /Linux/i.test(s) ? "linux" : s ? "other" : "unknown";
|
|
346
379
|
return { device, browser, os };
|
|
347
380
|
}
|
|
381
|
+
function isBot(ua) {
|
|
382
|
+
return Boolean(ua) && BOT_UA.test(ua);
|
|
383
|
+
}
|
|
384
|
+
var HTTP_CLIENT_UA = /^(curl|wget|python-requests)\//i;
|
|
385
|
+
function isCrawler(ua) {
|
|
386
|
+
return isBot(ua) && !HTTP_CLIENT_UA.test(ua.trim());
|
|
387
|
+
}
|
|
348
388
|
function parseCookies(header) {
|
|
349
389
|
const out = {};
|
|
350
390
|
for (const part of (header ?? "").split(";")) {
|
|
@@ -371,9 +411,17 @@ function browserContext(extra = {}) {
|
|
|
371
411
|
referrer: typeof document !== "undefined" ? document.referrer || void 0 : void 0,
|
|
372
412
|
url: location.href,
|
|
373
413
|
cookies: typeof document !== "undefined" ? parseCookies(document.cookie) : {},
|
|
414
|
+
timezone: deviceTimezone(),
|
|
374
415
|
...extra
|
|
375
416
|
};
|
|
376
417
|
}
|
|
418
|
+
function deviceTimezone() {
|
|
419
|
+
try {
|
|
420
|
+
return Intl.DateTimeFormat().resolvedOptions().timeZone || void 0;
|
|
421
|
+
} catch {
|
|
422
|
+
return void 0;
|
|
423
|
+
}
|
|
424
|
+
}
|
|
377
425
|
|
|
378
426
|
// src/config.ts
|
|
379
427
|
var KEY_PATTERN = /^[a-z0-9][a-z0-9_-]{0,63}$/;
|
|
@@ -442,7 +490,60 @@ function normalizeVariants(expKey, input) {
|
|
|
442
490
|
}
|
|
443
491
|
return raw.map((v) => ({ ...v, weight: v.weight / total }));
|
|
444
492
|
}
|
|
445
|
-
|
|
493
|
+
var HOLDOUT_KEY = "__holdout";
|
|
494
|
+
var LAYER_BUCKETS = 100;
|
|
495
|
+
function normalizeMetrics(key, input, goals) {
|
|
496
|
+
const m = input.metrics;
|
|
497
|
+
if (!m) return void 0;
|
|
498
|
+
if (!input.goal) throw new ConfigError(`experiment "${key}": metrics need a primary "goal" too.`);
|
|
499
|
+
const seen = /* @__PURE__ */ new Set([input.goal]);
|
|
500
|
+
const check = (goal, where) => {
|
|
501
|
+
if (typeof goal !== "string" || !goals.some((g) => g.key === goal)) throw new ConfigError(`experiment "${key}": metrics.${where} goal "${String(goal)}" is not declared in "goals".`);
|
|
502
|
+
if (seen.has(goal)) throw new ConfigError(`experiment "${key}": goal "${goal}" is listed twice (primary goal and metrics count once each).`);
|
|
503
|
+
seen.add(goal);
|
|
504
|
+
return goal;
|
|
505
|
+
};
|
|
506
|
+
const secondary = (m.secondary ?? []).map((g) => check(g, "secondary"));
|
|
507
|
+
const guardrails = (m.guardrails ?? []).map((g) => {
|
|
508
|
+
const obj = typeof g === "string" ? { goal: g } : g;
|
|
509
|
+
const worse = obj.worse ?? "lower";
|
|
510
|
+
if (worse !== "lower" && worse !== "higher") throw new ConfigError(`experiment "${key}": guardrail "${obj.goal}": worse must be "lower" or "higher".`);
|
|
511
|
+
return { goal: check(obj.goal, "guardrails"), worse };
|
|
512
|
+
});
|
|
513
|
+
if (secondary.length === 0 && guardrails.length === 0) return void 0;
|
|
514
|
+
return { secondary, guardrails };
|
|
515
|
+
}
|
|
516
|
+
function normalizeLayer(key, input, layers) {
|
|
517
|
+
const l = input.layer;
|
|
518
|
+
if (!l) return void 0;
|
|
519
|
+
if (!l.key || !(l.key in layers)) throw new ConfigError(`experiment "${key}": layer "${String(l.key)}" is not declared in "layers".`);
|
|
520
|
+
const [start, end] = Array.isArray(l.range) ? l.range : [NaN, NaN];
|
|
521
|
+
const ok = (n) => typeof n === "number" && Number.isInteger(n) && n >= 0 && n <= LAYER_BUCKETS;
|
|
522
|
+
if (!ok(start) || !ok(end) || !(start < end)) throw new ConfigError(`experiment "${key}": layer.range must be [start, end] with whole numbers 0 <= start < end <= ${LAYER_BUCKETS}.`);
|
|
523
|
+
return { key: l.key, range: [start, end] };
|
|
524
|
+
}
|
|
525
|
+
function assertNoOverlap(experiments) {
|
|
526
|
+
const live = experiments.filter((e) => e.layer && e.status !== "finished");
|
|
527
|
+
for (let i = 0; i < live.length; i++) {
|
|
528
|
+
for (let j = i + 1; j < live.length; j++) {
|
|
529
|
+
const a = live[i];
|
|
530
|
+
const b = live[j];
|
|
531
|
+
if (a.layer.key !== b.layer.key) continue;
|
|
532
|
+
if (a.layer.range[0] < b.layer.range[1] && b.layer.range[0] < a.layer.range[1]) {
|
|
533
|
+
throw new ConfigError(`experiments "${a.key}" and "${b.key}" overlap in layer "${a.layer.key}" ([${a.layer.range.join(", ")}) and [${b.layer.range.join(", ")})). Give each its own range.`);
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
function normalizeHoldout(input, goals) {
|
|
539
|
+
const h = input.holdout;
|
|
540
|
+
if (!h) return null;
|
|
541
|
+
if (typeof h.percent !== "number" || !Number.isFinite(h.percent) || h.percent < 0 || h.percent > 50) throw new ConfigError("holdout.percent must be a number between 0 and 50.");
|
|
542
|
+
if (h.goal && !goals.some((g) => g.key === h.goal)) throw new ConfigError(`holdout.goal "${h.goal}" is not declared in "goals".`);
|
|
543
|
+
if (h.percent === 0) return null;
|
|
544
|
+
return { percent: h.percent, seed: h.seed ?? HOLDOUT_KEY, goal: h.goal ?? goals[0]?.key ?? null };
|
|
545
|
+
}
|
|
546
|
+
function normalizeExperiment(key, input, goals, layers = {}) {
|
|
446
547
|
assertKey("experiment", key);
|
|
447
548
|
const traffic = input.traffic ?? 1;
|
|
448
549
|
if (traffic < 0 || traffic > 1) {
|
|
@@ -457,10 +558,15 @@ function normalizeExperiment(key, input, goals) {
|
|
|
457
558
|
if (input.maxExposures !== void 0 && (!Number.isFinite(input.maxExposures) || input.maxExposures < 1)) {
|
|
458
559
|
throw new ConfigError(`experiment "${key}": maxExposures must be a positive number.`);
|
|
459
560
|
}
|
|
561
|
+
if (input.minDays !== void 0 && !(Number.isInteger(input.minDays) && input.minDays >= 0 && input.minDays <= 30)) {
|
|
562
|
+
throw new ConfigError(`experiment "${key}": minDays must be a whole number from 0 to 30.`);
|
|
563
|
+
}
|
|
460
564
|
for (const [k, v] of Object.entries(input.schedule ?? {})) {
|
|
461
565
|
if (v !== void 0 && Number.isNaN(Date.parse(v))) throw new ConfigError(`experiment "${key}": schedule.${k} must be an ISO date.`);
|
|
462
566
|
}
|
|
463
567
|
const variants = normalizeVariants(key, input);
|
|
568
|
+
const metrics = normalizeMetrics(key, input, goals);
|
|
569
|
+
const layer = normalizeLayer(key, input, layers);
|
|
464
570
|
if (input.flow) {
|
|
465
571
|
const problem = validateFlow(input.flow, variants.map((v) => v.key));
|
|
466
572
|
if (problem) throw new ConfigError(`experiment "${key}": flow: ${problem}`);
|
|
@@ -477,6 +583,9 @@ function normalizeExperiment(key, input, goals) {
|
|
|
477
583
|
variants,
|
|
478
584
|
...input.kind === "mvt" ? { factors: mvtVariants(key, input.factors).factors } : {},
|
|
479
585
|
...input.flow ? { flow: input.flow } : {},
|
|
586
|
+
...metrics ? { metrics } : {},
|
|
587
|
+
...layer ? { layer } : {},
|
|
588
|
+
...input.minDays !== void 0 ? { minDays: input.minDays } : {},
|
|
480
589
|
...input.maxExposures ? { maxExposures: Math.floor(input.maxExposures) } : {},
|
|
481
590
|
...input.schedule && (input.schedule.startAt || input.schedule.endAt) ? { schedule: { startAt: input.schedule.startAt ?? null, endAt: input.schedule.endAt ?? null } } : {}
|
|
482
591
|
};
|
|
@@ -499,9 +608,16 @@ function defineConfig(input) {
|
|
|
499
608
|
description: g.description ?? null
|
|
500
609
|
};
|
|
501
610
|
});
|
|
611
|
+
const layers = {};
|
|
612
|
+
for (const [key, l] of Object.entries(input.layers ?? {})) {
|
|
613
|
+
assertKey("layer", key);
|
|
614
|
+
layers[key] = { seed: l?.seed ?? key };
|
|
615
|
+
}
|
|
502
616
|
const experiments = Object.entries(input.experiments ?? {}).map(
|
|
503
|
-
([key, exp]) => normalizeExperiment(key, exp, goals)
|
|
617
|
+
([key, exp]) => normalizeExperiment(key, exp, goals, layers)
|
|
504
618
|
);
|
|
619
|
+
assertNoOverlap(experiments);
|
|
620
|
+
const holdout = normalizeHoldout(input, goals);
|
|
505
621
|
return {
|
|
506
622
|
project: input.project,
|
|
507
623
|
storage: input.storage,
|
|
@@ -509,6 +625,8 @@ function defineConfig(input) {
|
|
|
509
625
|
runDraftsInDev: input.runDraftsInDev === true,
|
|
510
626
|
goals,
|
|
511
627
|
experiments,
|
|
628
|
+
...Object.keys(layers).length ? { layers } : {},
|
|
629
|
+
...holdout ? { holdout } : {},
|
|
512
630
|
__splithub: 2
|
|
513
631
|
};
|
|
514
632
|
}
|
|
@@ -518,6 +636,40 @@ function isSplitHubConfig(value) {
|
|
|
518
636
|
function getExperiment(config, key) {
|
|
519
637
|
return config.experiments.find((e) => e.key === key);
|
|
520
638
|
}
|
|
639
|
+
function holdoutExperiment(config) {
|
|
640
|
+
const h = config.holdout;
|
|
641
|
+
if (!h) return null;
|
|
642
|
+
const share = h.percent / 100;
|
|
643
|
+
const secondary = config.goals.map((g) => g.key).filter((g) => g !== h.goal);
|
|
644
|
+
return {
|
|
645
|
+
key: HOLDOUT_KEY,
|
|
646
|
+
kind: "component",
|
|
647
|
+
status: "running",
|
|
648
|
+
traffic: 1,
|
|
649
|
+
goal: h.goal,
|
|
650
|
+
seed: h.seed,
|
|
651
|
+
description: `Holdout: ${h.percent}% of visitors see no test at all`,
|
|
652
|
+
match: null,
|
|
653
|
+
variants: [
|
|
654
|
+
{ key: "holdout", weight: share },
|
|
655
|
+
{ key: "enrolled", weight: 1 - share }
|
|
656
|
+
],
|
|
657
|
+
...h.goal && secondary.length ? { metrics: { secondary, guardrails: [] } } : {}
|
|
658
|
+
};
|
|
659
|
+
}
|
|
660
|
+
function measuredGoals(config) {
|
|
661
|
+
const goals = {};
|
|
662
|
+
const metrics = {};
|
|
663
|
+
const all = [...config.experiments];
|
|
664
|
+
const h = holdoutExperiment(config);
|
|
665
|
+
if (h) all.push(h);
|
|
666
|
+
for (const e of all) {
|
|
667
|
+
goals[e.key] = e.goal ?? null;
|
|
668
|
+
const extra = [...e.metrics?.secondary ?? [], ...(e.metrics?.guardrails ?? []).map((g) => g.goal)];
|
|
669
|
+
if (extra.length) metrics[e.key] = extra;
|
|
670
|
+
}
|
|
671
|
+
return { goals, metrics };
|
|
672
|
+
}
|
|
521
673
|
|
|
522
674
|
// src/assignment.ts
|
|
523
675
|
function isDevEnvironment() {
|
|
@@ -544,6 +696,24 @@ function pickVariant(experiment, visitorId) {
|
|
|
544
696
|
}
|
|
545
697
|
return experiment.variants[experiment.variants.length - 1] ?? null;
|
|
546
698
|
}
|
|
699
|
+
function holdoutGroup(config, visitorId) {
|
|
700
|
+
const h = config.holdout;
|
|
701
|
+
if (!h || !(h.percent > 0)) return null;
|
|
702
|
+
return hashToUnit(`${h.seed}:${HOLDOUT_KEY}:${visitorId}`) < h.percent / 100 ? "holdout" : "enrolled";
|
|
703
|
+
}
|
|
704
|
+
function layerBucket(config, layerKey, visitorId) {
|
|
705
|
+
const seed = config.layers?.[layerKey]?.seed ?? layerKey;
|
|
706
|
+
return Math.min(LAYER_BUCKETS - 1, Math.floor(hashToUnit(`${seed}:layer:${layerKey}:${visitorId}`) * LAYER_BUCKETS));
|
|
707
|
+
}
|
|
708
|
+
function inLayer(config, experiment, visitorId) {
|
|
709
|
+
const l = experiment.layer;
|
|
710
|
+
if (!l) return true;
|
|
711
|
+
const b = layerBucket(config, l.key, visitorId);
|
|
712
|
+
return b >= l.range[0] && b < l.range[1];
|
|
713
|
+
}
|
|
714
|
+
function countsForHoldout(a) {
|
|
715
|
+
return a.reason === "assigned" || a.reason === "holdout" || a.reason === "outside_traffic" || a.reason === "targeting" || a.reason === "layer";
|
|
716
|
+
}
|
|
547
717
|
function assign(config, experimentKey, visitorId, options = {}) {
|
|
548
718
|
const experiment = config.experiments.find((e) => e.key === experimentKey);
|
|
549
719
|
if (!experiment) return { experiment: experimentKey, variant: null, reason: "unknown_experiment" };
|
|
@@ -552,10 +722,13 @@ function assign(config, experimentKey, visitorId, options = {}) {
|
|
|
552
722
|
const variant2 = experiment.variants.find((v) => v.key === forced) ?? null;
|
|
553
723
|
if (variant2) return { experiment: experimentKey, variant: variant2, reason: "override" };
|
|
554
724
|
}
|
|
725
|
+
if (options.context?.device === "bot") return { experiment: experimentKey, variant: null, reason: "bot" };
|
|
555
726
|
const devDraft = isDevDraft(config, experiment);
|
|
556
727
|
if (!devDraft && (experiment.status !== "running" || !inSchedule(experiment, options.context?.now))) {
|
|
557
728
|
return { experiment: experimentKey, variant: null, reason: "not_running" };
|
|
558
729
|
}
|
|
730
|
+
if (holdoutGroup(config, visitorId) === "holdout") return { experiment: experimentKey, variant: null, reason: "holdout" };
|
|
731
|
+
if (!inLayer(config, experiment, visitorId)) return { experiment: experimentKey, variant: null, reason: "layer" };
|
|
559
732
|
const reason = devDraft ? "dev" : "assigned";
|
|
560
733
|
if (experiment.flow) {
|
|
561
734
|
const trafficUnit = hashToUnit(`${experiment.seed}:${experiment.key}:traffic:${visitorId}`);
|
|
@@ -581,7 +754,13 @@ function parseForceParam(search) {
|
|
|
581
754
|
const out = {};
|
|
582
755
|
const match = /[?&]sh_force=([^&]+)/.exec(search);
|
|
583
756
|
if (!match || !match[1]) return out;
|
|
584
|
-
|
|
757
|
+
let raw;
|
|
758
|
+
try {
|
|
759
|
+
raw = decodeURIComponent(match[1]);
|
|
760
|
+
} catch {
|
|
761
|
+
return out;
|
|
762
|
+
}
|
|
763
|
+
for (const pair of raw.split(",")) {
|
|
585
764
|
const [exp, variant] = pair.split(":");
|
|
586
765
|
if (exp && variant) out[exp] = variant;
|
|
587
766
|
}
|
|
@@ -612,6 +791,14 @@ function explainAssignment(experiment, a) {
|
|
|
612
791
|
devNote(`${key}:dev`, `"${key}" is a draft. You see it here because runDraftsInDev is on; this visitor gets "${shown}", try ?sh_force=${key}:${others(experiment, shown)} for the others. Visitors see it only after you start it: npx splithub start ${key}`);
|
|
613
792
|
return;
|
|
614
793
|
}
|
|
794
|
+
if (a.reason === "holdout") {
|
|
795
|
+
devNote("holdout", `This visitor is in the holdout, so every test shows its control. Open ?sh_force=${key}:${experiment.variants[1]?.key ?? "variant"} to see a variant.`);
|
|
796
|
+
return;
|
|
797
|
+
}
|
|
798
|
+
if (a.reason === "layer") {
|
|
799
|
+
devNote(`${key}:layer`, `"${key}" shares layer "${experiment.layer?.key}" with other tests and this visitor's bucket belongs to another one, so they see the control.`);
|
|
800
|
+
return;
|
|
801
|
+
}
|
|
615
802
|
if (a.reason !== "not_running") return;
|
|
616
803
|
const second = experiment.variants[1]?.key ?? "variant";
|
|
617
804
|
if (experiment.status === "draft") {
|
|
@@ -707,14 +894,65 @@ function persistExposureSet(set, key = "sh_exposed") {
|
|
|
707
894
|
safeStorage("sessionStorage")?.setItem(key, JSON.stringify([...set]));
|
|
708
895
|
}
|
|
709
896
|
|
|
897
|
+
// src/paths.ts
|
|
898
|
+
function normalizePath(path) {
|
|
899
|
+
return path.length > 1 && path.endsWith("/") ? path.replace(/\/+$/, "") || "/" : path;
|
|
900
|
+
}
|
|
901
|
+
function matchPath(pattern, pathname) {
|
|
902
|
+
if (pattern.endsWith("*")) return pathname.startsWith(pattern.slice(0, -1));
|
|
903
|
+
return normalizePath(pattern) === normalizePath(pathname);
|
|
904
|
+
}
|
|
905
|
+
function redirectTarget(to, currentHref) {
|
|
906
|
+
const current = new URL(currentHref);
|
|
907
|
+
const target = new URL(to, current);
|
|
908
|
+
const own = new Set(target.searchParams.keys());
|
|
909
|
+
current.searchParams.forEach((value, key) => {
|
|
910
|
+
if (!own.has(key)) target.searchParams.append(key, value);
|
|
911
|
+
});
|
|
912
|
+
if (!target.hash) target.hash = current.hash;
|
|
913
|
+
return target;
|
|
914
|
+
}
|
|
915
|
+
|
|
916
|
+
// src/redirect.ts
|
|
917
|
+
function decideRedirect(config, pathname, visitorId, context = {}, overrides = {}, explain) {
|
|
918
|
+
for (const exp of config.experiments) {
|
|
919
|
+
if (exp.kind !== "redirect" || !exp.match || !matchPath(exp.match, pathname)) continue;
|
|
920
|
+
if (!isActive(config, exp, context.now)) {
|
|
921
|
+
explain?.(exp, { experiment: exp.key, variant: null, reason: "not_running" });
|
|
922
|
+
continue;
|
|
923
|
+
}
|
|
924
|
+
const a = assign(config, exp.key, visitorId, { overrides, context });
|
|
925
|
+
explain?.(exp, a);
|
|
926
|
+
if (!a.variant) continue;
|
|
927
|
+
const to = a.variant.to || null;
|
|
928
|
+
const stays = !to || normalizePath(to.split(/[?#]/)[0] ?? "") === normalizePath(pathname);
|
|
929
|
+
return { experiment: exp.key, variant: a.variant.key, to: stays ? null : to, reason: a.reason };
|
|
930
|
+
}
|
|
931
|
+
return null;
|
|
932
|
+
}
|
|
933
|
+
|
|
710
934
|
// src/events.ts
|
|
935
|
+
function beaconUrl(options) {
|
|
936
|
+
if (!options.key) return options.endpoint;
|
|
937
|
+
if (!options.keyInQuery) return null;
|
|
938
|
+
return `${options.endpoint}${options.endpoint.includes("?") ? "&" : "?"}key=${encodeURIComponent(options.key)}`;
|
|
939
|
+
}
|
|
711
940
|
function createFetchTransport(options) {
|
|
712
941
|
return {
|
|
713
942
|
async send(batch, { beacon }) {
|
|
714
943
|
const body = JSON.stringify(batch);
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
944
|
+
const url = beacon && isBrowser() && typeof navigator.sendBeacon === "function" ? beaconUrl(options) : null;
|
|
945
|
+
if (url) {
|
|
946
|
+
let sameOrigin = false;
|
|
947
|
+
try {
|
|
948
|
+
sameOrigin = new URL(url, location.href).origin === location.origin;
|
|
949
|
+
} catch {
|
|
950
|
+
}
|
|
951
|
+
const blob = new Blob([body], { type: sameOrigin ? "application/json" : "text/plain;charset=UTF-8" });
|
|
952
|
+
try {
|
|
953
|
+
if (navigator.sendBeacon(url, blob)) return;
|
|
954
|
+
} catch {
|
|
955
|
+
}
|
|
718
956
|
}
|
|
719
957
|
const headers = { "content-type": "application/json" };
|
|
720
958
|
if (options.key) headers.authorization = `Bearer ${options.key}`;
|
|
@@ -727,37 +965,61 @@ function createFetchTransport(options) {
|
|
|
727
965
|
}
|
|
728
966
|
};
|
|
729
967
|
}
|
|
968
|
+
var MAX_BACKOFF_MS = 3e4;
|
|
730
969
|
var EventQueue = class {
|
|
731
970
|
constructor(options) {
|
|
732
971
|
this.options = options;
|
|
733
972
|
this.pending = [];
|
|
734
973
|
this.retry = [];
|
|
974
|
+
this.attempts = 0;
|
|
735
975
|
this.timer = null;
|
|
976
|
+
this.backoffUntil = 0;
|
|
736
977
|
this.unbind = null;
|
|
737
978
|
this.maxBatch = options.maxBatch ?? 20;
|
|
738
979
|
this.flushInterval = options.flushInterval ?? 2e3;
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
}
|
|
980
|
+
this.maxQueue = options.maxQueue ?? 200;
|
|
981
|
+
this.maxAttempts = options.maxAttempts ?? 5;
|
|
982
|
+
}
|
|
983
|
+
bind() {
|
|
984
|
+
if (this.unbind || !isBrowser()) return;
|
|
985
|
+
const onHidden = () => {
|
|
986
|
+
if (document.visibilityState === "hidden") void this.flush(true);
|
|
987
|
+
};
|
|
988
|
+
const onPageHide = () => void this.flush(true);
|
|
989
|
+
document.addEventListener("visibilitychange", onHidden);
|
|
990
|
+
window.addEventListener("pagehide", onPageHide);
|
|
991
|
+
this.unbind = () => {
|
|
992
|
+
document.removeEventListener("visibilitychange", onHidden);
|
|
993
|
+
window.removeEventListener("pagehide", onPageHide);
|
|
994
|
+
};
|
|
995
|
+
}
|
|
996
|
+
schedule(delay) {
|
|
997
|
+
if (this.timer) return;
|
|
998
|
+
this.timer = setTimeout(() => {
|
|
999
|
+
this.timer = null;
|
|
1000
|
+
void this.flush(false);
|
|
1001
|
+
}, delay);
|
|
747
1002
|
}
|
|
748
1003
|
push(event) {
|
|
1004
|
+
this.bind();
|
|
749
1005
|
this.pending.push(event);
|
|
750
|
-
|
|
1006
|
+
const overflow = this.size - this.maxQueue;
|
|
1007
|
+
if (overflow > 0) {
|
|
1008
|
+
const fromRetry = Math.min(overflow, this.retry.length);
|
|
1009
|
+
this.retry.splice(0, fromRetry);
|
|
1010
|
+
this.pending.splice(0, overflow - fromRetry);
|
|
1011
|
+
}
|
|
1012
|
+
const waiting = Date.now() < this.backoffUntil;
|
|
1013
|
+
if (!waiting && this.pending.length >= this.maxBatch) {
|
|
751
1014
|
void this.flush(false);
|
|
752
1015
|
return;
|
|
753
1016
|
}
|
|
754
|
-
|
|
755
|
-
this.timer = setTimeout(() => void this.flush(false), this.flushInterval);
|
|
756
|
-
}
|
|
1017
|
+
this.schedule(waiting ? this.backoffUntil - Date.now() : this.flushInterval);
|
|
757
1018
|
}
|
|
758
1019
|
get size() {
|
|
759
1020
|
return this.pending.length + this.retry.length;
|
|
760
1021
|
}
|
|
1022
|
+
/** Send everything now. `beacon` is for page hide: it ignores the backoff, since the page is going away. */
|
|
761
1023
|
async flush(beacon = false) {
|
|
762
1024
|
if (this.timer) {
|
|
763
1025
|
clearTimeout(this.timer);
|
|
@@ -770,15 +1032,31 @@ var EventQueue = class {
|
|
|
770
1032
|
const batch = { project: this.options.project, sdk: this.options.sdk, events };
|
|
771
1033
|
try {
|
|
772
1034
|
await this.options.transport.send(batch, { beacon });
|
|
1035
|
+
this.attempts = 0;
|
|
1036
|
+
this.backoffUntil = 0;
|
|
773
1037
|
} catch (error) {
|
|
774
1038
|
const status = error.status;
|
|
775
|
-
|
|
1039
|
+
const refused = status !== void 0 && status >= 400 && status < 500 && status !== 408 && status !== 429;
|
|
1040
|
+
this.attempts += 1;
|
|
1041
|
+
if (!refused && this.attempts < this.maxAttempts) {
|
|
1042
|
+
this.retry = events.slice(-this.maxQueue);
|
|
1043
|
+
const base = Math.min(MAX_BACKOFF_MS, 1e3 * 2 ** (this.attempts - 1));
|
|
1044
|
+
const delay = Math.round(base / 2 + Math.random() * (base / 2));
|
|
1045
|
+
this.backoffUntil = Date.now() + delay;
|
|
1046
|
+
this.schedule(delay);
|
|
1047
|
+
} else {
|
|
1048
|
+
this.attempts = 0;
|
|
1049
|
+
this.backoffUntil = 0;
|
|
1050
|
+
}
|
|
776
1051
|
this.options.onError?.(error);
|
|
777
1052
|
}
|
|
778
1053
|
}
|
|
1054
|
+
/** Stop the timer and the page listeners. Pending events stay; a later `push` binds again. */
|
|
779
1055
|
destroy() {
|
|
780
1056
|
this.unbind?.();
|
|
1057
|
+
this.unbind = null;
|
|
781
1058
|
if (this.timer) clearTimeout(this.timer);
|
|
1059
|
+
this.timer = null;
|
|
782
1060
|
}
|
|
783
1061
|
};
|
|
784
1062
|
|
|
@@ -861,10 +1139,14 @@ function applyRemoteOverrides(config, overrides) {
|
|
|
861
1139
|
const added = (overrides.added ?? []).filter((e) => e && typeof e.key === "string" && !known.has(e.key) && Array.isArray(e.variants) && e.variants.length >= 2);
|
|
862
1140
|
const knownGoals = new Set(config.goals.map((g) => g.key));
|
|
863
1141
|
const addedGoals = (overrides.goals ?? []).filter((g) => g && typeof g.key === "string" && !knownGoals.has(g.key));
|
|
864
|
-
|
|
1142
|
+
const holdout = !config.holdout && validHoldout(overrides.holdout) ? overrides.holdout : null;
|
|
1143
|
+
const layers = overrides.layers && typeof overrides.layers === "object" ? { ...overrides.layers, ...config.layers ?? {} } : null;
|
|
1144
|
+
if (Object.keys(patches).length === 0 && added.length === 0 && addedGoals.length === 0 && !holdout && !layers) return config;
|
|
865
1145
|
const merged = [...config.experiments, ...added.map((e) => ({ ...e, origin: "dashboard" }))];
|
|
866
1146
|
return {
|
|
867
1147
|
...config,
|
|
1148
|
+
...holdout ? { holdout } : {},
|
|
1149
|
+
...layers ? { layers } : {},
|
|
868
1150
|
goals: addedGoals.length ? [...config.goals, ...addedGoals] : config.goals,
|
|
869
1151
|
experiments: merged.map((e) => {
|
|
870
1152
|
const o = patches[e.key];
|
|
@@ -872,6 +1154,9 @@ function applyRemoteOverrides(config, overrides) {
|
|
|
872
1154
|
})
|
|
873
1155
|
};
|
|
874
1156
|
}
|
|
1157
|
+
function validHoldout(h) {
|
|
1158
|
+
return Boolean(h) && typeof h.percent === "number" && h.percent > 0 && h.percent <= 50 && typeof h.seed === "string";
|
|
1159
|
+
}
|
|
875
1160
|
function isRemoteOverrides(value) {
|
|
876
1161
|
return Boolean(value) && typeof value === "object" && typeof value.version === "number" && typeof value.experiments === "object";
|
|
877
1162
|
}
|
|
@@ -964,9 +1249,15 @@ function createClient(config, options = {}) {
|
|
|
964
1249
|
config = effective;
|
|
965
1250
|
const hadVisitor = browser && !options.visitorId ? hasVisitorId(config.visitorKey) : void 0;
|
|
966
1251
|
const visitorId = options.visitorId ?? (browser ? getOrCreateVisitorId(config.visitorKey) : "server");
|
|
1252
|
+
const noVisitor = !browser && !options.visitorId;
|
|
967
1253
|
const sessionId = options.sessionId ?? (browser ? getOrCreateSessionId() : "server");
|
|
968
|
-
const contextFor = (g) =>
|
|
1254
|
+
const contextFor = (g) => {
|
|
1255
|
+
if (!browser) return { ...g ?? {}, ...options.context ?? {} };
|
|
1256
|
+
const forPage = g?.timezone ? { ...g, timezone: void 0 } : g;
|
|
1257
|
+
return browserContext({ ...stripUndefined(forPage ?? {}), ...hadVisitor === void 0 ? {} : { visitor: hadVisitor ? "returning" : "new" }, ...options.context ?? {} });
|
|
1258
|
+
};
|
|
969
1259
|
let context = contextFor(geo);
|
|
1260
|
+
const isBot2 = () => context.device === "bot";
|
|
970
1261
|
const overrides = {
|
|
971
1262
|
...browser ? parseForceParam(location.search) : {},
|
|
972
1263
|
...options.overrides ?? {}
|
|
@@ -981,7 +1272,10 @@ function createClient(config, options = {}) {
|
|
|
981
1272
|
held.add(key);
|
|
982
1273
|
debugLog(kind, message);
|
|
983
1274
|
};
|
|
984
|
-
const transport = options.transport ?? createFetchTransport(
|
|
1275
|
+
const transport = options.transport ?? createFetchTransport({
|
|
1276
|
+
...resolveEndpoint(config),
|
|
1277
|
+
keyInQuery: options.keyInQuery ?? (config.storage.mode === "cloud" && !config.storage.endpoint)
|
|
1278
|
+
});
|
|
985
1279
|
const queue = new EventQueue({
|
|
986
1280
|
project: config.project,
|
|
987
1281
|
sdk: `core/${SDK_VERSION}`,
|
|
@@ -990,13 +1284,29 @@ function createClient(config, options = {}) {
|
|
|
990
1284
|
});
|
|
991
1285
|
const exposed = browser ? sessionExposureSet() : /* @__PURE__ */ new Set();
|
|
992
1286
|
const currentUrl = () => browser ? location.pathname + location.search : void 0;
|
|
1287
|
+
const markHoldout = (ts) => {
|
|
1288
|
+
const group = holdoutGroup(config, visitorId);
|
|
1289
|
+
if (!group || noVisitor) return;
|
|
1290
|
+
const dedupKey = `${HOLDOUT_KEY}:${group}`;
|
|
1291
|
+
if (exposed.has(dedupKey)) return;
|
|
1292
|
+
if (devLocal) {
|
|
1293
|
+
hold(`x:${HOLDOUT_KEY}`, "exposure", `${HOLDOUT_KEY} / ${group} not sent: development never sends to the cloud`);
|
|
1294
|
+
return;
|
|
1295
|
+
}
|
|
1296
|
+
exposed.add(dedupKey);
|
|
1297
|
+
if (browser) persistExposureSet(exposed);
|
|
1298
|
+
const event = { id: newId("e_"), type: "exposure", exp: HOLDOUT_KEY, var: group, vid: visitorId, sid: sessionId, ts, url: currentUrl() };
|
|
1299
|
+
debugLog("exposure", `${HOLDOUT_KEY} / ${group} recorded`, event);
|
|
1300
|
+
queue.push(event);
|
|
1301
|
+
};
|
|
993
1302
|
let pending = waitFor !== null;
|
|
994
1303
|
const waiting = [];
|
|
995
1304
|
const listeners = /* @__PURE__ */ new Set();
|
|
996
1305
|
const sendExposure = (experimentKey, ts) => {
|
|
997
1306
|
const a = client.assignment(experimentKey);
|
|
1307
|
+
if (config.holdout && countsForHoldout(a)) markHoldout(ts);
|
|
998
1308
|
if (!a.variant || a.reason === "override") return;
|
|
999
|
-
if (devLocal) {
|
|
1309
|
+
if (typeof __SPLITHUB_LITE__ === "undefined" && devLocal) {
|
|
1000
1310
|
devNote("dev-events", DEV_NOTE);
|
|
1001
1311
|
hold(`x:${experimentKey}`, "exposure", `${experimentKey} / ${a.variant.key} not sent: development never sends to the cloud`);
|
|
1002
1312
|
return;
|
|
@@ -1010,10 +1320,11 @@ function createClient(config, options = {}) {
|
|
|
1010
1320
|
queue.push(event);
|
|
1011
1321
|
};
|
|
1012
1322
|
const sendGoal = (goal, props, ts) => {
|
|
1323
|
+
if (isBot2()) return;
|
|
1013
1324
|
if (!config.goals.some((g) => g.key === goal)) {
|
|
1014
1325
|
warn(`goal "${goal}" is not declared in splithub.config.ts; sending anyway.`);
|
|
1015
1326
|
}
|
|
1016
|
-
if (devLocal) {
|
|
1327
|
+
if (typeof __SPLITHUB_LITE__ === "undefined" && devLocal) {
|
|
1017
1328
|
devNote("dev-events", DEV_NOTE);
|
|
1018
1329
|
hold(`g:${goal}`, "goal", `${goal} not sent: development never sends to the cloud`);
|
|
1019
1330
|
return;
|
|
@@ -1062,8 +1373,9 @@ function createClient(config, options = {}) {
|
|
|
1062
1373
|
},
|
|
1063
1374
|
assignment(experimentKey) {
|
|
1064
1375
|
if (pending) return { experiment: experimentKey, variant: null, reason: "pending" };
|
|
1065
|
-
|
|
1066
|
-
|
|
1376
|
+
let a = assign(config, experimentKey, visitorId, { overrides, context });
|
|
1377
|
+
if (noVisitor && a.variant && a.reason !== "override") a = { experiment: experimentKey, variant: null, reason: "no_visitor" };
|
|
1378
|
+
if (typeof __SPLITHUB_LITE__ === "undefined") explainAssignment(getExperiment(config, experimentKey), a);
|
|
1067
1379
|
if (isDebug() && !decided.has(experimentKey)) {
|
|
1068
1380
|
decided.add(experimentKey);
|
|
1069
1381
|
const exp = getExperiment(config, experimentKey);
|
|
@@ -1100,7 +1412,7 @@ function createClient(config, options = {}) {
|
|
|
1100
1412
|
return (a.variant ?? experiment.variants[0]).value;
|
|
1101
1413
|
},
|
|
1102
1414
|
track(goal, props) {
|
|
1103
|
-
if (disabled) return;
|
|
1415
|
+
if (disabled || isBot2()) return;
|
|
1104
1416
|
if (pending) waiting.push({ goal, ...props ? { props } : {}, ts: Date.now() });
|
|
1105
1417
|
else sendGoal(goal, props, Date.now());
|
|
1106
1418
|
},
|
|
@@ -1111,12 +1423,12 @@ function createClient(config, options = {}) {
|
|
|
1111
1423
|
const ts = Date.now();
|
|
1112
1424
|
void ready.then(() => {
|
|
1113
1425
|
if (disabled) return;
|
|
1114
|
-
for (const goal of config.goals) if (goal.type === "pageview" && matchPath(goal, current)) sendGoal(goal.key, void 0, ts);
|
|
1426
|
+
for (const goal of config.goals) if (goal.type === "pageview" && goal.path && matchPath(goal.path, current)) sendGoal(goal.key, void 0, ts);
|
|
1115
1427
|
});
|
|
1116
1428
|
return;
|
|
1117
1429
|
}
|
|
1118
1430
|
for (const goal of config.goals) {
|
|
1119
|
-
if (goal.type === "pageview" && matchPath(goal, current)) {
|
|
1431
|
+
if (goal.type === "pageview" && goal.path && matchPath(goal.path, current)) {
|
|
1120
1432
|
debugLog("pageview", `${current} matches goal ${goal.key}`);
|
|
1121
1433
|
client.track(goal.key);
|
|
1122
1434
|
}
|
|
@@ -1141,6 +1453,8 @@ function createClient(config, options = {}) {
|
|
|
1141
1453
|
return () => target.removeEventListener("click", onClick, true);
|
|
1142
1454
|
},
|
|
1143
1455
|
flush: () => queue.flush(false),
|
|
1456
|
+
// Unbinds the page listeners; pending events are kept and a later event binds again,
|
|
1457
|
+
// so a provider may destroy on unmount even under StrictMode's double mount.
|
|
1144
1458
|
destroy: () => queue.destroy()
|
|
1145
1459
|
};
|
|
1146
1460
|
if (browser && isDebug()) {
|
|
@@ -1149,6 +1463,9 @@ function createClient(config, options = {}) {
|
|
|
1149
1463
|
}
|
|
1150
1464
|
return client;
|
|
1151
1465
|
}
|
|
1466
|
+
function stripUndefined(o) {
|
|
1467
|
+
return Object.fromEntries(Object.entries(o).filter(([, v]) => v !== void 0));
|
|
1468
|
+
}
|
|
1152
1469
|
function withTimeout(p, ms) {
|
|
1153
1470
|
return new Promise((resolve) => {
|
|
1154
1471
|
const t = setTimeout(() => resolve(null), ms);
|
|
@@ -1164,11 +1481,6 @@ function withTimeout(p, ms) {
|
|
|
1164
1481
|
);
|
|
1165
1482
|
});
|
|
1166
1483
|
}
|
|
1167
|
-
function matchPath(goal, path) {
|
|
1168
|
-
if (!goal.path) return false;
|
|
1169
|
-
if (goal.path.endsWith("*")) return path.startsWith(goal.path.slice(0, -1));
|
|
1170
|
-
return goal.path === path;
|
|
1171
|
-
}
|
|
1172
1484
|
var warned = /* @__PURE__ */ new Set();
|
|
1173
1485
|
function warn(message) {
|
|
1174
1486
|
if (warned.has(message)) return;
|
|
@@ -1184,7 +1496,9 @@ function warnUnknown(key) {
|
|
|
1184
1496
|
ConfigError,
|
|
1185
1497
|
EMPTY_OVERRIDES,
|
|
1186
1498
|
EventQueue,
|
|
1499
|
+
HOLDOUT_KEY,
|
|
1187
1500
|
KEYED_FIELDS,
|
|
1501
|
+
LAYER_BUCKETS,
|
|
1188
1502
|
MVT_MAX_COMBINATIONS,
|
|
1189
1503
|
MVT_MAX_FACTORS,
|
|
1190
1504
|
MVT_MAX_LEVELS,
|
|
@@ -1198,10 +1512,12 @@ function warnUnknown(key) {
|
|
|
1198
1512
|
browserContext,
|
|
1199
1513
|
contextValue,
|
|
1200
1514
|
controlVariant,
|
|
1515
|
+
countsForHoldout,
|
|
1201
1516
|
createClient,
|
|
1202
1517
|
createFetchTransport,
|
|
1203
1518
|
debugLog,
|
|
1204
1519
|
debugMode,
|
|
1520
|
+
decideRedirect,
|
|
1205
1521
|
defineConfig,
|
|
1206
1522
|
devNote,
|
|
1207
1523
|
evaluateCondition,
|
|
@@ -1212,26 +1528,36 @@ function warnUnknown(key) {
|
|
|
1212
1528
|
getOrCreateVisitorId,
|
|
1213
1529
|
hasVisitorId,
|
|
1214
1530
|
hashToUnit,
|
|
1531
|
+
holdoutExperiment,
|
|
1532
|
+
holdoutGroup,
|
|
1533
|
+
inLayer,
|
|
1215
1534
|
inSchedule,
|
|
1216
1535
|
isActive,
|
|
1536
|
+
isBot,
|
|
1217
1537
|
isBrowser,
|
|
1538
|
+
isCrawler,
|
|
1218
1539
|
isDebug,
|
|
1219
1540
|
isDevDraft,
|
|
1220
1541
|
isDevEnvironment,
|
|
1221
1542
|
isRemoteOverrides,
|
|
1222
1543
|
isSplitHubConfig,
|
|
1544
|
+
layerBucket,
|
|
1223
1545
|
matchConditions,
|
|
1546
|
+
matchPath,
|
|
1547
|
+
measuredGoals,
|
|
1224
1548
|
murmur3,
|
|
1225
1549
|
mvtVariants,
|
|
1226
1550
|
newId,
|
|
1227
1551
|
newSessionId,
|
|
1228
1552
|
newVisitorId,
|
|
1553
|
+
normalizePath,
|
|
1229
1554
|
onDebug,
|
|
1230
1555
|
parseCookies,
|
|
1231
1556
|
parseForceParam,
|
|
1232
1557
|
parseUserAgent,
|
|
1233
1558
|
pickVariant,
|
|
1234
1559
|
readRemoteCache,
|
|
1560
|
+
redirectTarget,
|
|
1235
1561
|
resetDevNotes,
|
|
1236
1562
|
resolveOverridesUrl,
|
|
1237
1563
|
runFlow,
|