@coframe/sdk 1.1.46 → 1.1.48

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.
@@ -300,9 +300,11 @@ const generateUUID = () => {
300
300
  const cryptoObject = (_a = getGlobalScope()) === null || _a === void 0 ? void 0 : _a.crypto;
301
301
  if (cryptoObject === null || cryptoObject === void 0 ? void 0 : cryptoObject.randomUUID)
302
302
  return cryptoObject.randomUUID();
303
+ const randomByte = (cryptoObject === null || cryptoObject === void 0 ? void 0 : cryptoObject.getRandomValues)
304
+ ? () => cryptoObject.getRandomValues(new Uint8Array(1))[0]
305
+ : () => Math.floor(Math.random() * 256);
303
306
  return `${1e7}${ -1e3}${ -4e3}${ -8e3}${ -1e11}`.replace(/[018]/g, (c) => {
304
- var _a, _b;
305
- const randomValue = (_b = (_a = cryptoObject === null || cryptoObject === void 0 ? void 0 : cryptoObject.getRandomValues) === null || _a === void 0 ? void 0 : _a.call(cryptoObject, new Uint8Array(1))[0]) !== null && _b !== void 0 ? _b : 0;
307
+ const randomValue = randomByte();
306
308
  return (c ^
307
309
  (randomValue & (15 >> (c / 4)))).toString(16);
308
310
  });
@@ -369,16 +371,30 @@ const getOrGenerateUserToken = () => {
369
371
  const setUserTokenCookie = (uuid, logger) => {
370
372
  setCookie(USER_TOKEN_COOKIE_KEY, uuid, logger);
371
373
  };
374
+ const VISIT_BOUNDARY_MS = 2 * 60 * 60 * 1000;
375
+ function startsNewVisit(lastVisitTime, now) {
376
+ return !lastVisitTime || now - lastVisitTime > VISIT_BOUNDARY_MS;
377
+ }
378
+ function nextVisitCount(existing, lastVisitTime, now) {
379
+ return startsNewVisit(lastVisitTime, now) ? existing + 1 : existing;
380
+ }
381
+ function parseNonNegativeInt(raw) {
382
+ if (!raw || !/^\d+$/.test(raw))
383
+ return undefined;
384
+ const parsed = Number(raw);
385
+ return parsed <= 9007199254740991 ? parsed : undefined;
386
+ }
387
+ function parseVisitCount(raw) {
388
+ var _a;
389
+ return (_a = parseNonNegativeInt(raw)) !== null && _a !== void 0 ? _a : 0;
390
+ }
372
391
  const trackVisitCookie = (logger) => {
373
- const visitCountString = getCookie(VISIT_COUNT_COOKIE_KEY);
374
- const lastVisitTime = Number.parseInt(getCookie(LAST_VISIT_TIME_KEY), 10);
392
+ const existing = parseVisitCount(getCookie(VISIT_COUNT_COOKIE_KEY));
393
+ const lastVisitTime = parseVisitCount(getCookie(LAST_VISIT_TIME_KEY));
375
394
  const currentTime = Date.now();
376
- const twoHours = 2 * 60 * 60 * 1000;
377
- if (!lastVisitTime || currentTime - lastVisitTime > twoHours) {
378
- const visitCount = visitCountString
379
- ? Number.parseInt(visitCountString, 10) + 1
380
- : 1;
381
- setCookie(VISIT_COUNT_COOKIE_KEY, visitCount.toString(), logger);
395
+ const next = nextVisitCount(existing, lastVisitTime, currentTime);
396
+ if (next !== existing) {
397
+ setCookie(VISIT_COUNT_COOKIE_KEY, next.toString(), logger);
382
398
  setCookie(LAST_VISIT_TIME_KEY, currentTime.toString(), logger);
383
399
  }
384
400
  };
@@ -2067,6 +2083,7 @@ const applyVariantChanges = (variantElements, currentUrl, logger, nonce, lifecyc
2067
2083
  ? lifecycleContext.runtime.createVariantSession({
2068
2084
  batchId: lifecycleContext.batchId,
2069
2085
  variantId: variant.id,
2086
+ experimentId: variant.experiment_id,
2070
2087
  })
2071
2088
  : null;
2072
2089
  if (!variant.modifications ||
@@ -2104,7 +2121,7 @@ const applyVariantChanges = (variantElements, currentUrl, logger, nonce, lifecyc
2104
2121
  });
2105
2122
  }
2106
2123
  else if (selectedElement instanceof HTMLElement) {
2107
- selectedElement.setAttribute('coframe-exp-id', variant.id);
2124
+ selectedElement.setAttribute('coframe-exp-id', variant.experiment_id);
2108
2125
  }
2109
2126
  }
2110
2127
  return true;
@@ -2290,6 +2307,16 @@ function murmurHash3_x86_32(key, seed) {
2290
2307
  return h1 >>> 0;
2291
2308
  }
2292
2309
 
2310
+ function parseLaneCookie(raw) {
2311
+ if (!raw)
2312
+ return {};
2313
+ try {
2314
+ return parseClaims(decodeURIComponent(raw));
2315
+ }
2316
+ catch (_a) {
2317
+ return parseClaims(raw);
2318
+ }
2319
+ }
2293
2320
  function parseClaims(raw) {
2294
2321
  if (!raw)
2295
2322
  return {};
@@ -2723,7 +2750,7 @@ function checkAllAudiences(metadata, ctx) {
2723
2750
  const audience = ctx.project.audiences[audienceId];
2724
2751
  if (!audience)
2725
2752
  continue;
2726
- const activated = checkActivationCondition(audience.selector, ctx.personalizationHeaders, ctx.currentPageUrl, ctx.languages, ctx.browserPlatform, ctx.userToken, ctx.userVisitCount, (js, args) => executeJs(js, args, { isExpression: true, nonce: ctx.nonce }), ctx.logger);
2753
+ const activated = checkActivationCondition(audience.selector, ctx.personalizationHeaders, ctx.currentPageUrl, ctx.languages, ctx.browserPlatform, ctx.userToken, ctx.userVisitCount, ctx.runJsFunction, ctx.logger);
2727
2754
  if (activated === false)
2728
2755
  return false;
2729
2756
  if (activated !== true)
@@ -2731,8 +2758,12 @@ function checkAllAudiences(metadata, ctx) {
2731
2758
  }
2732
2759
  return result;
2733
2760
  }
2734
- async function getVariantsAndElements(personalizationHeaders, project, previewVariantId, userToken, currentPageUrl, languages, browserPlatform, logger, nonce, laneClaims = {}, silentFallback = false, chooseCmabVariants) {
2735
- var _a;
2761
+ function audiencesPass(metadata, ctx) {
2762
+ const result = checkAllAudiences(metadata, ctx);
2763
+ return ctx.unknownIsInactive ? result === true : result !== false;
2764
+ }
2765
+ async function getVariantsAndElements(personalizationHeaders, project, previewVariantId, userToken, currentPageUrl, languages, browserPlatform, logger, nonce, laneClaims = {}, silentFallback = false, chooseCmabVariants, userVisitCountOverride, runtime = {}) {
2766
+ var _a, _b;
2736
2767
  const experimentsInfo = [];
2737
2768
  const cloakBot = !!((_a = project.settings) === null || _a === void 0 ? void 0 : _a.bot_cloaking_enabled) &&
2738
2769
  personalizationHeaders['x-is-bot'] === 'true';
@@ -2744,7 +2775,11 @@ async function getVariantsAndElements(personalizationHeaders, project, previewVa
2744
2775
  laneClaims: meClaims,
2745
2776
  };
2746
2777
  };
2747
- const userVisitCount = Number.parseInt(getCookie(VISIT_COUNT_COOKIE_KEY) || '0', 10);
2778
+ const userVisitCount = userVisitCountOverride !== null && userVisitCountOverride !== void 0 ? userVisitCountOverride : parseVisitCount(getCookie(VISIT_COUNT_COOKIE_KEY));
2779
+ const evaluateJsFunctions = (_b = runtime.evaluateJsFunctions) !== null && _b !== void 0 ? _b : true;
2780
+ const runJsFunction = evaluateJsFunctions
2781
+ ? (js, args) => executeJs(js, args, { isExpression: true, nonce })
2782
+ : undefined;
2748
2783
  const ctx = {
2749
2784
  project,
2750
2785
  personalizationHeaders,
@@ -2753,8 +2788,9 @@ async function getVariantsAndElements(personalizationHeaders, project, previewVa
2753
2788
  languages,
2754
2789
  browserPlatform,
2755
2790
  userVisitCount,
2756
- nonce,
2757
2791
  logger,
2792
+ runJsFunction,
2793
+ unknownIsInactive: !evaluateJsFunctions,
2758
2794
  };
2759
2795
  const validatedClaims = validateClaims(laneClaims, project.lanes);
2760
2796
  const previewVariantIds = splitPreviewVariantIds(previewVariantId);
@@ -2809,27 +2845,24 @@ function activateFrames(ctx) {
2809
2845
  return ctx.project.frames.filter((frame) => {
2810
2846
  if (!frame.experiments)
2811
2847
  return false;
2812
- const frameActivated = checkActivationCondition(frame.activation_condition, ctx.personalizationHeaders, ctx.currentPageUrl, ctx.languages, ctx.browserPlatform, ctx.userToken, ctx.userVisitCount, (js, args) => executeJs(js, args, { isExpression: true, nonce: ctx.nonce }), ctx.logger);
2813
- if (!frameActivated)
2814
- return false;
2815
- return true;
2848
+ const frameActivated = checkActivationCondition(frame.activation_condition, ctx.personalizationHeaders, ctx.currentPageUrl, ctx.languages, ctx.browserPlatform, ctx.userToken, ctx.userVisitCount, ctx.runJsFunction, ctx.logger);
2849
+ return ctx.unknownIsInactive ? frameActivated === true : !!frameActivated;
2816
2850
  });
2817
2851
  }
2818
2852
  async function assignFrames(activeFrames, validatedClaims, ctx, chooseCmabVariants) {
2819
- var _a;
2853
+ var _a, _b, _c;
2820
2854
  const { project, userToken, logger } = ctx;
2821
2855
  const experimentsInfo = [];
2822
2856
  const variantsAndElements = [];
2823
- const evalAudiences = (metadata) => checkAllAudiences(metadata, ctx) !== false;
2824
2857
  const audiencePass = new Map();
2825
2858
  const reachableByLane = {};
2826
2859
  for (const frame of activeFrames) {
2827
- for (const experiment of frame.experiments) {
2860
+ for (const experiment of (_a = frame.experiments) !== null && _a !== void 0 ? _a : []) {
2828
2861
  const metadata = experiment.metadata;
2829
2862
  const laneIds = experimentLaneIds(metadata);
2830
2863
  if (laneIds.length === 0)
2831
2864
  continue;
2832
- const passes = evalAudiences(metadata);
2865
+ const passes = audiencesPass(metadata, ctx);
2833
2866
  audiencePass.set(metadata.experiment_id, passes);
2834
2867
  if (passes) {
2835
2868
  for (const laneId of laneIds) {
@@ -2846,7 +2879,7 @@ async function assignFrames(activeFrames, validatedClaims, ctx, chooseCmabVarian
2846
2879
  let hasActivatedFrames = false;
2847
2880
  for (const frame of activeFrames) {
2848
2881
  let atLeastOneExperimentWasActivated = false;
2849
- for (const experiment of frame.experiments) {
2882
+ for (const experiment of (_b = frame.experiments) !== null && _b !== void 0 ? _b : []) {
2850
2883
  if (atLeastOneExperimentWasActivated)
2851
2884
  break;
2852
2885
  const metadata = experiment.metadata;
@@ -2856,7 +2889,7 @@ async function assignFrames(activeFrames, validatedClaims, ctx, chooseCmabVarian
2856
2889
  continue;
2857
2890
  let activated = audiencePass.get(metadata.experiment_id);
2858
2891
  if (activated === undefined) {
2859
- activated = evalAudiences(metadata);
2892
+ activated = audiencesPass(metadata, ctx);
2860
2893
  }
2861
2894
  if (!activated)
2862
2895
  continue;
@@ -2912,7 +2945,7 @@ async function assignFrames(activeFrames, validatedClaims, ctx, chooseCmabVarian
2912
2945
  try {
2913
2946
  mlVariantIds = await chooseCmabVariants(Array.from(cmabMetadataById.values()), userToken);
2914
2947
  }
2915
- catch (_b) {
2948
+ catch (_d) {
2916
2949
  mlVariantIds = new Map();
2917
2950
  }
2918
2951
  }
@@ -2923,7 +2956,7 @@ async function assignFrames(activeFrames, validatedClaims, ctx, chooseCmabVarian
2923
2956
  }
2924
2957
  const { metadata, variants, elements } = entry;
2925
2958
  let mlVariantId = metadata.type === 'CMAB'
2926
- ? ((_a = mlVariantIds.get(metadata.experiment_id)) !== null && _a !== void 0 ? _a : null)
2959
+ ? ((_c = mlVariantIds.get(metadata.experiment_id)) !== null && _c !== void 0 ? _c : null)
2927
2960
  : null;
2928
2961
  if (mlVariantId && !variants.some((v) => v.id === mlVariantId)) {
2929
2962
  logger.warn(`CMAB variant ${mlVariantId} not in experiment ${metadata.experiment_id}`, 'cmab_variant_not_found', { experiment_id: metadata.experiment_id });
@@ -2976,9 +3009,12 @@ async function previewVariants(previewVariantIds, validatedClaims, ctx, silentFa
2976
3009
  return uniqueByVariantId([...rolledOutVariants, ...requestedVariants]);
2977
3010
  }
2978
3011
  function findVariants(frames, variantIds) {
2979
- return frames.flatMap((frame) => frame.experiments.flatMap((experiment) => experiment.variants
2980
- .filter((variant) => variantIds.includes(variant.id))
2981
- .map((variant) => ({ variant, elements: frame.elements }))));
3012
+ return frames.flatMap((frame) => {
3013
+ var _a;
3014
+ return ((_a = frame.experiments) !== null && _a !== void 0 ? _a : []).flatMap((experiment) => experiment.variants
3015
+ .filter((variant) => variantIds.includes(variant.id))
3016
+ .map((variant) => ({ variant, elements: frame.elements })));
3017
+ });
2982
3018
  }
2983
3019
  function uniqueByVariantId(items) {
2984
3020
  const seen = {};
@@ -2990,10 +3026,13 @@ function uniqueByVariantId(items) {
2990
3026
  });
2991
3027
  }
2992
3028
  function keepRolledOutExperiments(frames) {
2993
- return frames.map((frame) => ({
2994
- ...frame,
2995
- experiments: frame.experiments.filter((experiment) => experiment.metadata.serving_mode === 'winner'),
2996
- }));
3029
+ return frames.map((frame) => {
3030
+ var _a;
3031
+ return ({
3032
+ ...frame,
3033
+ experiments: ((_a = frame.experiments) !== null && _a !== void 0 ? _a : []).filter((experiment) => experiment.metadata.serving_mode === 'winner'),
3034
+ });
3035
+ });
2997
3036
  }
2998
3037
 
2999
3038
  function buildSessionContext(isInitialApply) {
@@ -3664,6 +3703,7 @@ async function resolveProject(Coframe, previewVariantId, isSessionVariant, confi
3664
3703
  const queuedHeaders = getQueuedPersonalizationHeaders();
3665
3704
  let personalizationHeaders = queuedHeaders;
3666
3705
  let project = isSessionVariant ? undefined : projectData === null || projectData === void 0 ? void 0 : projectData.project;
3706
+ const assignmentContext = project ? projectData === null || projectData === void 0 ? void 0 : projectData.assignmentContext : undefined;
3667
3707
  if (!project) {
3668
3708
  const edgeResult = await fetchProject(config.projectUrl, Coframe.projectId, config.currentUrl || getCurrentPageUrl(), undefined, config.userContext, previewVariantId || undefined, undefined, (_b = config.referrer) !== null && _b !== void 0 ? _b : getBrowserReferrer());
3669
3709
  personalizationHeaders = mergeClientHeaders(queuedHeaders, edgeResult === null || edgeResult === void 0 ? void 0 : edgeResult.personalizationHeaders);
@@ -3680,6 +3720,7 @@ async function resolveProject(Coframe, previewVariantId, isSessionVariant, confi
3680
3720
  return {
3681
3721
  project,
3682
3722
  personalizationHeaders: personalizationHeaders,
3723
+ ...(assignmentContext ? { assignmentContext } : {}),
3683
3724
  };
3684
3725
  }
3685
3726
 
@@ -4157,7 +4198,7 @@ function setupListeners(Coframe, executionStartTime) {
4157
4198
  for (const variantElement of Coframe.variantsAndElements || []) {
4158
4199
  const variant = variantElement.variant;
4159
4200
  if (!experiencedCoframeIds.has(variant.id)) {
4160
- const elements = document.querySelectorAll(`[coframe-exp-id="${variant.id}"]`);
4201
+ const elements = document.querySelectorAll(`[coframe-exp-id="${variant.experiment_id}"]`);
4161
4202
  for (const el of Array.from(elements)) {
4162
4203
  if (isElementVisible(el)) {
4163
4204
  el.setAttribute('coframe-experienced', 'true');
@@ -4451,18 +4492,12 @@ function setupSPANavigation(Coframe, project, config, previewVariantId, isSessio
4451
4492
  }
4452
4493
  function readLaneClaims() {
4453
4494
  const cookie = getCookie(LANE_COOKIE_KEY);
4454
- if (cookie) {
4455
- try {
4456
- return parseClaims(decodeURIComponent(cookie));
4457
- }
4458
- catch (_a) {
4459
- return parseClaims(cookie);
4460
- }
4461
- }
4495
+ if (cookie)
4496
+ return parseLaneCookie(cookie);
4462
4497
  try {
4463
4498
  return parseClaims(localStorage.getItem(LANE_COOKIE_KEY));
4464
4499
  }
4465
- catch (_b) {
4500
+ catch (_a) {
4466
4501
  return {};
4467
4502
  }
4468
4503
  }
@@ -4477,14 +4512,17 @@ function persistLaneClaims(claims, logger) {
4477
4512
  setCookie(LANE_COOKIE_KEY, encodeURIComponent(serialized), logger);
4478
4513
  }
4479
4514
  }
4480
- function createApplyVariants(Coframe, config, previewVariantId, isSessionVariant, executionStartTime, analytics, laneStore, runtime) {
4515
+ function createApplyVariants(Coframe, config, previewVariantId, isSessionVariant, executionStartTime, analytics, laneStore, runtime, initialAssignmentContext) {
4481
4516
  let isFirstApply = true;
4517
+ let snapshotContext = initialAssignmentContext;
4482
4518
  let applicationId = 0;
4483
4519
  const apply = async (pageUrl, pageProject, personalizationHeaders, signal, deadline) => {
4484
- var _a, _b;
4520
+ var _a, _b, _c, _d;
4485
4521
  const currentApplication = ++applicationId;
4486
4522
  if (signal === null || signal === void 0 ? void 0 : signal.aborted)
4487
4523
  return 'skipped';
4524
+ const assignmentContext = snapshotContext;
4525
+ snapshotContext = undefined;
4488
4526
  const preview = resolvePreview(pageUrl, previewVariantId, isSessionVariant);
4489
4527
  const chooseCmabVariants = createCmabVariantBatchChooser({
4490
4528
  projectId: Coframe.projectId,
@@ -4495,7 +4533,7 @@ function createApplyVariants(Coframe, config, previewVariantId, isSessionVariant
4495
4533
  disableRemoteAssignment: Boolean(config.projectUrl || config.ingestUrl),
4496
4534
  userContext: config.userContext,
4497
4535
  });
4498
- const { variantsAndElements, experimentsInfo, hasActivatedFrames, laneClaims, } = await getVariantsAndElements(personalizationHeaders, pageProject, preview.previewVariantId, Coframe.userToken, pageUrl, getBrowserLanguages(), getBrowserPlatform(), Coframe.logger, config.nonce, laneStore.claims, preview.isSessionVariant, chooseCmabVariants);
4536
+ const { variantsAndElements, experimentsInfo, hasActivatedFrames, laneClaims, } = await getVariantsAndElements(personalizationHeaders, pageProject, preview.previewVariantId, Coframe.userToken, pageUrl, (_b = assignmentContext === null || assignmentContext === void 0 ? void 0 : assignmentContext.languages) !== null && _b !== void 0 ? _b : getBrowserLanguages(), (_c = assignmentContext === null || assignmentContext === void 0 ? void 0 : assignmentContext.browserPlatform) !== null && _c !== void 0 ? _c : getBrowserPlatform(), Coframe.logger, config.nonce, laneStore.claims, preview.isSessionVariant, chooseCmabVariants, assignmentContext === null || assignmentContext === void 0 ? void 0 : assignmentContext.userVisitCount);
4499
4537
  if ((signal === null || signal === void 0 ? void 0 : signal.aborted) ||
4500
4538
  currentApplication !== applicationId ||
4501
4539
  (runtime === null || runtime === void 0 ? void 0 : runtime.isDestroyed()) ||
@@ -4503,7 +4541,7 @@ function createApplyVariants(Coframe, config, previewVariantId, isSessionVariant
4503
4541
  return 'skipped';
4504
4542
  if (!signal &&
4505
4543
  runtime &&
4506
- ((_b = pageProject === null || pageProject === void 0 ? void 0 : pageProject.settings) === null || _b === void 0 ? void 0 : _b.mutation_observer_active) &&
4544
+ ((_d = pageProject === null || pageProject === void 0 ? void 0 : pageProject.settings) === null || _d === void 0 ? void 0 : _d.mutation_observer_active) &&
4507
4545
  !urlsMatch(pageUrl, getCurrentPageUrl(), true))
4508
4546
  return 'stale-route';
4509
4547
  if (!signal && runtime) {
@@ -4549,7 +4587,7 @@ function createApplyVariants(Coframe, config, previewVariantId, isSessionVariant
4549
4587
  async function modifyPage(Coframe, configResult, projectResult, analytics, lifecycle) {
4550
4588
  var _a;
4551
4589
  const { config, timeoutMs, previewVariantId, isSessionVariant, integrationStartTime, executionStartTime, } = configResult;
4552
- const { project: cdnProject, personalizationHeaders } = projectResult;
4590
+ const { project: cdnProject, personalizationHeaders, assignmentContext, } = projectResult;
4553
4591
  const revealCoordinator = (_a = lifecycle === null || lifecycle === void 0 ? void 0 : lifecycle.revealCoordinator) !== null && _a !== void 0 ? _a : createRevealCoordinator(revealPage, logRevealListenerError(() => Coframe.logger));
4554
4592
  const runtime = lifecycle === null || lifecycle === void 0 ? void 0 : lifecycle.runtime;
4555
4593
  if (runtime && config.waitForHydration) {
@@ -4575,7 +4613,7 @@ async function modifyPage(Coframe, configResult, projectResult, analytics, lifec
4575
4613
  if (!(await ensureBody(Coframe, cdnProject, timeoutMs, config.nonce, revealCoordinator, () => !(runtime === null || runtime === void 0 ? void 0 : runtime.isDestroyed()))))
4576
4614
  return;
4577
4615
  const laneStore = { claims: readLaneClaims() };
4578
- const applier = createApplyVariants(Coframe, config, previewVariantId, isSessionVariant, executionStartTime, analytics, laneStore, runtime);
4616
+ const applier = createApplyVariants(Coframe, config, previewVariantId, isSessionVariant, executionStartTime, analytics, laneStore, runtime, assignmentContext);
4579
4617
  const initialUrl = getCurrentPageUrl();
4580
4618
  if (runtime) {
4581
4619
  const runtimeUrl = runtime.getState().currentUrl;
@@ -5178,6 +5216,9 @@ function injectOptions(options) {
5178
5216
  projectData: {
5179
5217
  project: options.projectData.project,
5180
5218
  personalizationHeaders: (_a = options.projectData.personalizationHeaders) !== null && _a !== void 0 ? _a : {},
5219
+ ...(options.projectData.assignmentContext
5220
+ ? { assignmentContext: options.projectData.assignmentContext }
5221
+ : {}),
5181
5222
  },
5182
5223
  });
5183
5224
  }
@@ -5387,6 +5428,7 @@ function createVariantSession(options) {
5387
5428
  getPageState: () => ({ ...options.getPageState() }),
5388
5429
  getState: () => ({ ...state }),
5389
5430
  getVariantId: () => state.variantId,
5431
+ getExperimentId: () => options.experimentId,
5390
5432
  onPage: (event, handler) => subscribe(event, handler, false),
5391
5433
  oncePage: (event, handler) => subscribe(event, handler, true),
5392
5434
  ready() {
@@ -5746,6 +5788,7 @@ function createPageRuntime(options) {
5746
5788
  const session = createVariantSession({
5747
5789
  sessionId: createId(),
5748
5790
  variantId: input.variantId,
5791
+ experimentId: input.experimentId,
5749
5792
  batchId: batch.batchId,
5750
5793
  routeVersion: batch.routeVersion,
5751
5794
  getPageState: () => ({ ...state }),
@@ -34,9 +34,11 @@ const generateUUID = () => {
34
34
  const cryptoObject = (_a = getGlobalScope()) === null || _a === void 0 ? void 0 : _a.crypto;
35
35
  if (cryptoObject === null || cryptoObject === void 0 ? void 0 : cryptoObject.randomUUID)
36
36
  return cryptoObject.randomUUID();
37
+ const randomByte = (cryptoObject === null || cryptoObject === void 0 ? void 0 : cryptoObject.getRandomValues)
38
+ ? () => cryptoObject.getRandomValues(new Uint8Array(1))[0]
39
+ : () => Math.floor(Math.random() * 256);
37
40
  return `${1e7}${ -1e3}${ -4e3}${ -8e3}${ -1e11}`.replace(/[018]/g, (c) => {
38
- var _a, _b;
39
- const randomValue = (_b = (_a = cryptoObject === null || cryptoObject === void 0 ? void 0 : cryptoObject.getRandomValues) === null || _a === void 0 ? void 0 : _a.call(cryptoObject, new Uint8Array(1))[0]) !== null && _b !== void 0 ? _b : 0;
41
+ const randomValue = randomByte();
40
42
  return (c ^
41
43
  (randomValue & (15 >> (c / 4)))).toString(16);
42
44
  });
@@ -32,9 +32,11 @@ const generateUUID = () => {
32
32
  const cryptoObject = (_a = getGlobalScope()) === null || _a === void 0 ? void 0 : _a.crypto;
33
33
  if (cryptoObject === null || cryptoObject === void 0 ? void 0 : cryptoObject.randomUUID)
34
34
  return cryptoObject.randomUUID();
35
+ const randomByte = (cryptoObject === null || cryptoObject === void 0 ? void 0 : cryptoObject.getRandomValues)
36
+ ? () => cryptoObject.getRandomValues(new Uint8Array(1))[0]
37
+ : () => Math.floor(Math.random() * 256);
35
38
  return `${1e7}${ -1e3}${ -4e3}${ -8e3}${ -1e11}`.replace(/[018]/g, (c) => {
36
- var _a, _b;
37
- const randomValue = (_b = (_a = cryptoObject === null || cryptoObject === void 0 ? void 0 : cryptoObject.getRandomValues) === null || _a === void 0 ? void 0 : _a.call(cryptoObject, new Uint8Array(1))[0]) !== null && _b !== void 0 ? _b : 0;
39
+ const randomValue = randomByte();
38
40
  return (c ^
39
41
  (randomValue & (15 >> (c / 4)))).toString(16);
40
42
  });