@coframe/sdk 1.1.47 → 1.1.49

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
  };
@@ -2105,7 +2121,13 @@ const applyVariantChanges = (variantElements, currentUrl, logger, nonce, lifecyc
2105
2121
  });
2106
2122
  }
2107
2123
  else if (selectedElement instanceof HTMLElement) {
2108
- selectedElement.setAttribute('coframe-exp-id', variant.experiment_id);
2124
+ const listAttribute = 'coframe-experiment-ids';
2125
+ const listed = selectedElement.getAttribute(listAttribute);
2126
+ const experimentIds = listed ? listed.split(',') : [];
2127
+ if (experimentIds.indexOf(variant.experiment_id) === -1) {
2128
+ experimentIds.push(variant.experiment_id);
2129
+ selectedElement.setAttribute(listAttribute, experimentIds.join(','));
2130
+ }
2109
2131
  }
2110
2132
  }
2111
2133
  return true;
@@ -2291,6 +2313,16 @@ function murmurHash3_x86_32(key, seed) {
2291
2313
  return h1 >>> 0;
2292
2314
  }
2293
2315
 
2316
+ function parseLaneCookie(raw) {
2317
+ if (!raw)
2318
+ return {};
2319
+ try {
2320
+ return parseClaims(decodeURIComponent(raw));
2321
+ }
2322
+ catch (_a) {
2323
+ return parseClaims(raw);
2324
+ }
2325
+ }
2294
2326
  function parseClaims(raw) {
2295
2327
  if (!raw)
2296
2328
  return {};
@@ -2724,7 +2756,7 @@ function checkAllAudiences(metadata, ctx) {
2724
2756
  const audience = ctx.project.audiences[audienceId];
2725
2757
  if (!audience)
2726
2758
  continue;
2727
- 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);
2759
+ const activated = checkActivationCondition(audience.selector, ctx.personalizationHeaders, ctx.currentPageUrl, ctx.languages, ctx.browserPlatform, ctx.userToken, ctx.userVisitCount, ctx.runJsFunction, ctx.logger);
2728
2760
  if (activated === false)
2729
2761
  return false;
2730
2762
  if (activated !== true)
@@ -2732,8 +2764,12 @@ function checkAllAudiences(metadata, ctx) {
2732
2764
  }
2733
2765
  return result;
2734
2766
  }
2735
- async function getVariantsAndElements(personalizationHeaders, project, previewVariantId, userToken, currentPageUrl, languages, browserPlatform, logger, nonce, laneClaims = {}, silentFallback = false, chooseCmabVariants) {
2736
- var _a;
2767
+ function audiencesPass(metadata, ctx) {
2768
+ const result = checkAllAudiences(metadata, ctx);
2769
+ return ctx.unknownIsInactive ? result === true : result !== false;
2770
+ }
2771
+ async function getVariantsAndElements(personalizationHeaders, project, previewVariantId, userToken, currentPageUrl, languages, browserPlatform, logger, nonce, laneClaims = {}, silentFallback = false, chooseCmabVariants, userVisitCountOverride, runtime = {}) {
2772
+ var _a, _b;
2737
2773
  const experimentsInfo = [];
2738
2774
  const cloakBot = !!((_a = project.settings) === null || _a === void 0 ? void 0 : _a.bot_cloaking_enabled) &&
2739
2775
  personalizationHeaders['x-is-bot'] === 'true';
@@ -2745,7 +2781,11 @@ async function getVariantsAndElements(personalizationHeaders, project, previewVa
2745
2781
  laneClaims: meClaims,
2746
2782
  };
2747
2783
  };
2748
- const userVisitCount = Number.parseInt(getCookie(VISIT_COUNT_COOKIE_KEY) || '0', 10);
2784
+ const userVisitCount = userVisitCountOverride !== null && userVisitCountOverride !== void 0 ? userVisitCountOverride : parseVisitCount(getCookie(VISIT_COUNT_COOKIE_KEY));
2785
+ const evaluateJsFunctions = (_b = runtime.evaluateJsFunctions) !== null && _b !== void 0 ? _b : true;
2786
+ const runJsFunction = evaluateJsFunctions
2787
+ ? (js, args) => executeJs(js, args, { isExpression: true, nonce })
2788
+ : undefined;
2749
2789
  const ctx = {
2750
2790
  project,
2751
2791
  personalizationHeaders,
@@ -2754,8 +2794,9 @@ async function getVariantsAndElements(personalizationHeaders, project, previewVa
2754
2794
  languages,
2755
2795
  browserPlatform,
2756
2796
  userVisitCount,
2757
- nonce,
2758
2797
  logger,
2798
+ runJsFunction,
2799
+ unknownIsInactive: !evaluateJsFunctions,
2759
2800
  };
2760
2801
  const validatedClaims = validateClaims(laneClaims, project.lanes);
2761
2802
  const previewVariantIds = splitPreviewVariantIds(previewVariantId);
@@ -2810,27 +2851,24 @@ function activateFrames(ctx) {
2810
2851
  return ctx.project.frames.filter((frame) => {
2811
2852
  if (!frame.experiments)
2812
2853
  return false;
2813
- 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);
2814
- if (!frameActivated)
2815
- return false;
2816
- return true;
2854
+ const frameActivated = checkActivationCondition(frame.activation_condition, ctx.personalizationHeaders, ctx.currentPageUrl, ctx.languages, ctx.browserPlatform, ctx.userToken, ctx.userVisitCount, ctx.runJsFunction, ctx.logger);
2855
+ return ctx.unknownIsInactive ? frameActivated === true : !!frameActivated;
2817
2856
  });
2818
2857
  }
2819
2858
  async function assignFrames(activeFrames, validatedClaims, ctx, chooseCmabVariants) {
2820
- var _a;
2859
+ var _a, _b, _c;
2821
2860
  const { project, userToken, logger } = ctx;
2822
2861
  const experimentsInfo = [];
2823
2862
  const variantsAndElements = [];
2824
- const evalAudiences = (metadata) => checkAllAudiences(metadata, ctx) !== false;
2825
2863
  const audiencePass = new Map();
2826
2864
  const reachableByLane = {};
2827
2865
  for (const frame of activeFrames) {
2828
- for (const experiment of frame.experiments) {
2866
+ for (const experiment of (_a = frame.experiments) !== null && _a !== void 0 ? _a : []) {
2829
2867
  const metadata = experiment.metadata;
2830
2868
  const laneIds = experimentLaneIds(metadata);
2831
2869
  if (laneIds.length === 0)
2832
2870
  continue;
2833
- const passes = evalAudiences(metadata);
2871
+ const passes = audiencesPass(metadata, ctx);
2834
2872
  audiencePass.set(metadata.experiment_id, passes);
2835
2873
  if (passes) {
2836
2874
  for (const laneId of laneIds) {
@@ -2847,7 +2885,7 @@ async function assignFrames(activeFrames, validatedClaims, ctx, chooseCmabVarian
2847
2885
  let hasActivatedFrames = false;
2848
2886
  for (const frame of activeFrames) {
2849
2887
  let atLeastOneExperimentWasActivated = false;
2850
- for (const experiment of frame.experiments) {
2888
+ for (const experiment of (_b = frame.experiments) !== null && _b !== void 0 ? _b : []) {
2851
2889
  if (atLeastOneExperimentWasActivated)
2852
2890
  break;
2853
2891
  const metadata = experiment.metadata;
@@ -2857,7 +2895,7 @@ async function assignFrames(activeFrames, validatedClaims, ctx, chooseCmabVarian
2857
2895
  continue;
2858
2896
  let activated = audiencePass.get(metadata.experiment_id);
2859
2897
  if (activated === undefined) {
2860
- activated = evalAudiences(metadata);
2898
+ activated = audiencesPass(metadata, ctx);
2861
2899
  }
2862
2900
  if (!activated)
2863
2901
  continue;
@@ -2913,7 +2951,7 @@ async function assignFrames(activeFrames, validatedClaims, ctx, chooseCmabVarian
2913
2951
  try {
2914
2952
  mlVariantIds = await chooseCmabVariants(Array.from(cmabMetadataById.values()), userToken);
2915
2953
  }
2916
- catch (_b) {
2954
+ catch (_d) {
2917
2955
  mlVariantIds = new Map();
2918
2956
  }
2919
2957
  }
@@ -2924,7 +2962,7 @@ async function assignFrames(activeFrames, validatedClaims, ctx, chooseCmabVarian
2924
2962
  }
2925
2963
  const { metadata, variants, elements } = entry;
2926
2964
  let mlVariantId = metadata.type === 'CMAB'
2927
- ? ((_a = mlVariantIds.get(metadata.experiment_id)) !== null && _a !== void 0 ? _a : null)
2965
+ ? ((_c = mlVariantIds.get(metadata.experiment_id)) !== null && _c !== void 0 ? _c : null)
2928
2966
  : null;
2929
2967
  if (mlVariantId && !variants.some((v) => v.id === mlVariantId)) {
2930
2968
  logger.warn(`CMAB variant ${mlVariantId} not in experiment ${metadata.experiment_id}`, 'cmab_variant_not_found', { experiment_id: metadata.experiment_id });
@@ -2977,9 +3015,12 @@ async function previewVariants(previewVariantIds, validatedClaims, ctx, silentFa
2977
3015
  return uniqueByVariantId([...rolledOutVariants, ...requestedVariants]);
2978
3016
  }
2979
3017
  function findVariants(frames, variantIds) {
2980
- return frames.flatMap((frame) => frame.experiments.flatMap((experiment) => experiment.variants
2981
- .filter((variant) => variantIds.includes(variant.id))
2982
- .map((variant) => ({ variant, elements: frame.elements }))));
3018
+ return frames.flatMap((frame) => {
3019
+ var _a;
3020
+ return ((_a = frame.experiments) !== null && _a !== void 0 ? _a : []).flatMap((experiment) => experiment.variants
3021
+ .filter((variant) => variantIds.includes(variant.id))
3022
+ .map((variant) => ({ variant, elements: frame.elements })));
3023
+ });
2983
3024
  }
2984
3025
  function uniqueByVariantId(items) {
2985
3026
  const seen = {};
@@ -2991,10 +3032,13 @@ function uniqueByVariantId(items) {
2991
3032
  });
2992
3033
  }
2993
3034
  function keepRolledOutExperiments(frames) {
2994
- return frames.map((frame) => ({
2995
- ...frame,
2996
- experiments: frame.experiments.filter((experiment) => experiment.metadata.serving_mode === 'winner'),
2997
- }));
3035
+ return frames.map((frame) => {
3036
+ var _a;
3037
+ return ({
3038
+ ...frame,
3039
+ experiments: ((_a = frame.experiments) !== null && _a !== void 0 ? _a : []).filter((experiment) => experiment.metadata.serving_mode === 'winner'),
3040
+ });
3041
+ });
2998
3042
  }
2999
3043
 
3000
3044
  function buildSessionContext(isInitialApply) {
@@ -3665,6 +3709,7 @@ async function resolveProject(Coframe, previewVariantId, isSessionVariant, confi
3665
3709
  const queuedHeaders = getQueuedPersonalizationHeaders();
3666
3710
  let personalizationHeaders = queuedHeaders;
3667
3711
  let project = isSessionVariant ? undefined : projectData === null || projectData === void 0 ? void 0 : projectData.project;
3712
+ const assignmentContext = project ? projectData === null || projectData === void 0 ? void 0 : projectData.assignmentContext : undefined;
3668
3713
  if (!project) {
3669
3714
  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());
3670
3715
  personalizationHeaders = mergeClientHeaders(queuedHeaders, edgeResult === null || edgeResult === void 0 ? void 0 : edgeResult.personalizationHeaders);
@@ -3681,6 +3726,7 @@ async function resolveProject(Coframe, previewVariantId, isSessionVariant, confi
3681
3726
  return {
3682
3727
  project,
3683
3728
  personalizationHeaders: personalizationHeaders,
3729
+ ...(assignmentContext ? { assignmentContext } : {}),
3684
3730
  };
3685
3731
  }
3686
3732
 
@@ -4158,8 +4204,11 @@ function setupListeners(Coframe, executionStartTime) {
4158
4204
  for (const variantElement of Coframe.variantsAndElements || []) {
4159
4205
  const variant = variantElement.variant;
4160
4206
  if (!experiencedCoframeIds.has(variant.id)) {
4161
- const elements = document.querySelectorAll(`[coframe-exp-id="${variant.experiment_id}"]`);
4207
+ const elements = document.querySelectorAll('[coframe-experiment-ids]');
4162
4208
  for (const el of Array.from(elements)) {
4209
+ const experimentIds = (el.getAttribute('coframe-experiment-ids') || '').split(',');
4210
+ if (experimentIds.indexOf(variant.experiment_id) === -1)
4211
+ continue;
4163
4212
  if (isElementVisible(el)) {
4164
4213
  el.setAttribute('coframe-experienced', 'true');
4165
4214
  experiencedCoframeIds.add(variant.id);
@@ -4452,18 +4501,12 @@ function setupSPANavigation(Coframe, project, config, previewVariantId, isSessio
4452
4501
  }
4453
4502
  function readLaneClaims() {
4454
4503
  const cookie = getCookie(LANE_COOKIE_KEY);
4455
- if (cookie) {
4456
- try {
4457
- return parseClaims(decodeURIComponent(cookie));
4458
- }
4459
- catch (_a) {
4460
- return parseClaims(cookie);
4461
- }
4462
- }
4504
+ if (cookie)
4505
+ return parseLaneCookie(cookie);
4463
4506
  try {
4464
4507
  return parseClaims(localStorage.getItem(LANE_COOKIE_KEY));
4465
4508
  }
4466
- catch (_b) {
4509
+ catch (_a) {
4467
4510
  return {};
4468
4511
  }
4469
4512
  }
@@ -4478,14 +4521,17 @@ function persistLaneClaims(claims, logger) {
4478
4521
  setCookie(LANE_COOKIE_KEY, encodeURIComponent(serialized), logger);
4479
4522
  }
4480
4523
  }
4481
- function createApplyVariants(Coframe, config, previewVariantId, isSessionVariant, executionStartTime, analytics, laneStore, runtime) {
4524
+ function createApplyVariants(Coframe, config, previewVariantId, isSessionVariant, executionStartTime, analytics, laneStore, runtime, initialAssignmentContext) {
4482
4525
  let isFirstApply = true;
4526
+ let snapshotContext = initialAssignmentContext;
4483
4527
  let applicationId = 0;
4484
4528
  const apply = async (pageUrl, pageProject, personalizationHeaders, signal, deadline) => {
4485
- var _a, _b;
4529
+ var _a, _b, _c, _d;
4486
4530
  const currentApplication = ++applicationId;
4487
4531
  if (signal === null || signal === void 0 ? void 0 : signal.aborted)
4488
4532
  return 'skipped';
4533
+ const assignmentContext = snapshotContext;
4534
+ snapshotContext = undefined;
4489
4535
  const preview = resolvePreview(pageUrl, previewVariantId, isSessionVariant);
4490
4536
  const chooseCmabVariants = createCmabVariantBatchChooser({
4491
4537
  projectId: Coframe.projectId,
@@ -4496,7 +4542,7 @@ function createApplyVariants(Coframe, config, previewVariantId, isSessionVariant
4496
4542
  disableRemoteAssignment: Boolean(config.projectUrl || config.ingestUrl),
4497
4543
  userContext: config.userContext,
4498
4544
  });
4499
- 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);
4545
+ 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);
4500
4546
  if ((signal === null || signal === void 0 ? void 0 : signal.aborted) ||
4501
4547
  currentApplication !== applicationId ||
4502
4548
  (runtime === null || runtime === void 0 ? void 0 : runtime.isDestroyed()) ||
@@ -4504,7 +4550,7 @@ function createApplyVariants(Coframe, config, previewVariantId, isSessionVariant
4504
4550
  return 'skipped';
4505
4551
  if (!signal &&
4506
4552
  runtime &&
4507
- ((_b = pageProject === null || pageProject === void 0 ? void 0 : pageProject.settings) === null || _b === void 0 ? void 0 : _b.mutation_observer_active) &&
4553
+ ((_d = pageProject === null || pageProject === void 0 ? void 0 : pageProject.settings) === null || _d === void 0 ? void 0 : _d.mutation_observer_active) &&
4508
4554
  !urlsMatch(pageUrl, getCurrentPageUrl(), true))
4509
4555
  return 'stale-route';
4510
4556
  if (!signal && runtime) {
@@ -4550,7 +4596,7 @@ function createApplyVariants(Coframe, config, previewVariantId, isSessionVariant
4550
4596
  async function modifyPage(Coframe, configResult, projectResult, analytics, lifecycle) {
4551
4597
  var _a;
4552
4598
  const { config, timeoutMs, previewVariantId, isSessionVariant, integrationStartTime, executionStartTime, } = configResult;
4553
- const { project: cdnProject, personalizationHeaders } = projectResult;
4599
+ const { project: cdnProject, personalizationHeaders, assignmentContext, } = projectResult;
4554
4600
  const revealCoordinator = (_a = lifecycle === null || lifecycle === void 0 ? void 0 : lifecycle.revealCoordinator) !== null && _a !== void 0 ? _a : createRevealCoordinator(revealPage, logRevealListenerError(() => Coframe.logger));
4555
4601
  const runtime = lifecycle === null || lifecycle === void 0 ? void 0 : lifecycle.runtime;
4556
4602
  if (runtime && config.waitForHydration) {
@@ -4576,7 +4622,7 @@ async function modifyPage(Coframe, configResult, projectResult, analytics, lifec
4576
4622
  if (!(await ensureBody(Coframe, cdnProject, timeoutMs, config.nonce, revealCoordinator, () => !(runtime === null || runtime === void 0 ? void 0 : runtime.isDestroyed()))))
4577
4623
  return;
4578
4624
  const laneStore = { claims: readLaneClaims() };
4579
- const applier = createApplyVariants(Coframe, config, previewVariantId, isSessionVariant, executionStartTime, analytics, laneStore, runtime);
4625
+ const applier = createApplyVariants(Coframe, config, previewVariantId, isSessionVariant, executionStartTime, analytics, laneStore, runtime, assignmentContext);
4580
4626
  const initialUrl = getCurrentPageUrl();
4581
4627
  if (runtime) {
4582
4628
  const runtimeUrl = runtime.getState().currentUrl;
@@ -5179,6 +5225,9 @@ function injectOptions(options) {
5179
5225
  projectData: {
5180
5226
  project: options.projectData.project,
5181
5227
  personalizationHeaders: (_a = options.projectData.personalizationHeaders) !== null && _a !== void 0 ? _a : {},
5228
+ ...(options.projectData.assignmentContext
5229
+ ? { assignmentContext: options.projectData.assignmentContext }
5230
+ : {}),
5182
5231
  },
5183
5232
  });
5184
5233
  }
@@ -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
  });