@uniformdev/context 12.2.1-alpha.143 → 12.2.1-alpha.170
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/api/api.d.ts +4 -1
- package/dist/api/api.js +2 -2
- package/dist/api/api.mjs +1 -1
- package/dist/chunk-JKQJOIRC.mjs +2 -0
- package/dist/chunk-KZPEO35A.mjs +1 -0
- package/dist/cli/cli.js +55 -21
- package/dist/cli/cli.mjs +54 -20
- package/dist/index.d.ts +332 -181
- package/dist/index.esm.js +3 -3
- package/dist/index.js +3 -3
- package/dist/index.mjs +3 -3
- package/package.json +4 -4
- package/dist/chunk-TRWANXVF.mjs +0 -1
- package/dist/chunk-WLJXJJSU.mjs +0 -2
package/dist/index.d.ts
CHANGED
@@ -110,7 +110,14 @@ declare type ContextStateUpdate = {
|
|
110
110
|
declare type TransitionDataStoreOptions = {
|
111
111
|
initialData?: Partial<VisitorData>;
|
112
112
|
};
|
113
|
-
declare type ServerToClientTransitionState = Pick<Partial<VisitorData>, 'quirks' | 'tests'
|
113
|
+
declare type ServerToClientTransitionState = Pick<Partial<VisitorData>, 'quirks' | 'tests'> & {
|
114
|
+
/**
|
115
|
+
* Server Score Vector - the resultant scores _on the server side_ after the server/edge render completes
|
116
|
+
* Note that the client side does not trust these scores; they are only used until it's done with initial
|
117
|
+
* recomputation.
|
118
|
+
*/
|
119
|
+
ssv?: ScoreVector;
|
120
|
+
};
|
114
121
|
declare const SERVER_STATE_ID = "__UNIFORM_DATA__";
|
115
122
|
declare type TransitionDataStoreEvents = {
|
116
123
|
/**
|
@@ -243,6 +250,232 @@ declare type DecayOptions = {
|
|
243
250
|
*/
|
244
251
|
declare type DecayFunction = (options: DecayOptions) => boolean;
|
245
252
|
|
253
|
+
/**
|
254
|
+
* Creates a new log drain that will log to the console.
|
255
|
+
* The log drain will only log event IDs, but is much smaller than the
|
256
|
+
* debug log drain.
|
257
|
+
*
|
258
|
+
* NOTE: you probably want enableConsoleLogDrain() instead of this function.
|
259
|
+
*/
|
260
|
+
declare function createConsoleLogDrain(level: OutputSeverity): LogDrain;
|
261
|
+
/**
|
262
|
+
* Enables logging Context events to the browser console.
|
263
|
+
* Lightweight events with only the event ID are emitted.
|
264
|
+
*/
|
265
|
+
declare function enableConsoleLogDrain(level: OutputSeverity): ContextPlugin;
|
266
|
+
|
267
|
+
/** Defines all error codes and their parameter(s) */
|
268
|
+
declare type LogMessages = {
|
269
|
+
/** Context constructed */
|
270
|
+
1: MessageFunc;
|
271
|
+
/** Context received data update */
|
272
|
+
2: MessageFunc<Partial<Omit<ContextState, 'url'> & {
|
273
|
+
url: string;
|
274
|
+
}>>;
|
275
|
+
/** Context emitted new score vector */
|
276
|
+
3: MessageFunc<ScoreVector>;
|
277
|
+
/** Context emitted updated quirks */
|
278
|
+
4: MessageFunc<Quirks>;
|
279
|
+
/** Storage received update commands */
|
280
|
+
101: MessageFunc<StorageCommands[]>;
|
281
|
+
/** Storage data was updated */
|
282
|
+
102: MessageFunc<VisitorData>;
|
283
|
+
/** Storage data was deleted bool: fromAllDevices */
|
284
|
+
103: MessageFunc<boolean>;
|
285
|
+
/** Storage score was truncated to its cap */
|
286
|
+
110: MessageFunc<{
|
287
|
+
dim: string;
|
288
|
+
score: number;
|
289
|
+
cap: number;
|
290
|
+
}>;
|
291
|
+
/** Storage visitor data expired and was cleared */
|
292
|
+
120: MessageFunc;
|
293
|
+
/** Server to client transition score data was loaded */
|
294
|
+
130: MessageFunc<ScoreVector>;
|
295
|
+
/** Placement does not have a name */
|
296
|
+
301: MessageFunc;
|
297
|
+
/** Test did not exist */
|
298
|
+
401: MessageFunc<string>;
|
299
|
+
/** Previously shown test variant no longer in variant data */
|
300
|
+
402: MessageFunc<{
|
301
|
+
test: string;
|
302
|
+
variant: string;
|
303
|
+
}>;
|
304
|
+
/** gtag was not present on the page to emit events to */
|
305
|
+
700: MessageFunc;
|
306
|
+
/** Enabled gtag event signal redirection */
|
307
|
+
701: MessageFunc;
|
308
|
+
};
|
309
|
+
|
310
|
+
declare type Severity = 'debug' | 'info' | 'warn' | 'error';
|
311
|
+
declare type OutputSeverity = Severity | 'none';
|
312
|
+
declare type MessageFunc<TArg = void> = (arg: TArg) => [string, string, ...any];
|
313
|
+
declare type LogMessage<TID extends keyof LogMessages = keyof LogMessages> = [
|
314
|
+
severity: Severity,
|
315
|
+
id: TID,
|
316
|
+
...args: Parameters<LogMessages[TID]>
|
317
|
+
];
|
318
|
+
declare type LogDrain = (message: LogMessage) => void;
|
319
|
+
|
320
|
+
/**
|
321
|
+
* Creates a new log drain that will log full debug messages to the console.
|
322
|
+
* The debug log drain adds significant bundle size, but is useful for debugging.
|
323
|
+
*
|
324
|
+
* NOTE: you probably want enableDebugConsoleLogDrain() instead of this function.
|
325
|
+
*/
|
326
|
+
declare function createDebugConsoleLogDrain(level: OutputSeverity): LogDrain;
|
327
|
+
/**
|
328
|
+
* Enables logging Context events to the browser console.
|
329
|
+
* Lightweight events with only the event ID are emitted.
|
330
|
+
*/
|
331
|
+
declare function enableDebugConsoleLogDrain(level: OutputSeverity): ContextPlugin;
|
332
|
+
|
333
|
+
declare type VisitorDataStoreOptions = {
|
334
|
+
/** Transition storage used to transfer server or edge side execution state to the client. Unused for client side only. */
|
335
|
+
transitionStore?: TransitionDataStore;
|
336
|
+
/** Duration of a 'visit' measured by this number of milliseconds without performing any updates */
|
337
|
+
visitLifespan?: number;
|
338
|
+
/** Personalization manifest data. If set, the data store will automatically apply score caps in the manifest data. */
|
339
|
+
manifest?: ManifestInstance;
|
340
|
+
/** Allows decaying of scores over time based on time between visits. Default: no decay */
|
341
|
+
decay?: DecayFunction;
|
342
|
+
/**
|
343
|
+
* Sets the default value of storage consent for new unknown visitors.
|
344
|
+
* If storage consent is not given, only in-memory data will be stored which is lost when the browser leaves the page.
|
345
|
+
* @default false - consent is not given for new visitors until they explicitly give it with an update command
|
346
|
+
*/
|
347
|
+
defaultConsent?: boolean;
|
348
|
+
/**
|
349
|
+
* Function called when server-to-client transfer state is loaded and contains server-side computed scores.
|
350
|
+
* These scores are used as a temporary shim for the current scores on the client side, until score computation
|
351
|
+
* is completed the first time (which occurs when the current url is fed into the Context).
|
352
|
+
*
|
353
|
+
* Because the feed of the URL may be marginally delayed (for example in React it's in an effect so it's a second render),
|
354
|
+
* one render might be done with _no_ scores unless we dropped the server scores in temporarily, resulting in a flash of unpersonalized content.
|
355
|
+
*/
|
356
|
+
onServerTransitionScoresReceived?: (ssv: ScoreVector) => void;
|
357
|
+
/** Called when a log message is emitted from the data store */
|
358
|
+
onLogMessage?: (message: LogMessage) => void;
|
359
|
+
};
|
360
|
+
declare type VisitorDataStoreEvents = {
|
361
|
+
/**
|
362
|
+
* Fired when the stored data is updated.
|
363
|
+
* This is fired for any update, whether from integrated or transition storage.
|
364
|
+
* The event is NOT fired if an update does not result in any score changes.
|
365
|
+
*/
|
366
|
+
scoresUpdated: Pick<VisitorData, 'scores' | 'sessionScores'>;
|
367
|
+
/**
|
368
|
+
* Fired when stored quirks are updated.
|
369
|
+
* This is fired for any update, whether from integrated or transition storage.
|
370
|
+
* The event is NOT fired if an update does not result in any quirk changes.
|
371
|
+
*/
|
372
|
+
quirksUpdated: Pick<VisitorData, 'quirks'>;
|
373
|
+
/**
|
374
|
+
* Fired when test variant selection is updated.
|
375
|
+
*/
|
376
|
+
testsUpdated: Pick<VisitorData, 'tests'>;
|
377
|
+
/**
|
378
|
+
* Fired when storage consent is changed
|
379
|
+
*/
|
380
|
+
consentUpdated: Pick<VisitorData, 'consent'>;
|
381
|
+
/**
|
382
|
+
* Fired when visitor control group membership is changed
|
383
|
+
*/
|
384
|
+
controlGroupUpdated: Pick<VisitorData, 'controlGroup'>;
|
385
|
+
};
|
386
|
+
declare class VisitorDataStore {
|
387
|
+
#private;
|
388
|
+
constructor(options: VisitorDataStoreOptions);
|
389
|
+
/** Gets the current visitor data. This property is always up to date. */
|
390
|
+
get data(): VisitorData;
|
391
|
+
get decayEnabled(): boolean;
|
392
|
+
/**
|
393
|
+
* Subscribe to events from storage
|
394
|
+
*/
|
395
|
+
readonly events: {
|
396
|
+
on: {
|
397
|
+
<Key extends keyof VisitorDataStoreEvents>(type: Key, handler: mitt.Handler<VisitorDataStoreEvents[Key]>): void;
|
398
|
+
(type: "*", handler: mitt.WildcardHandler<VisitorDataStoreEvents>): void;
|
399
|
+
};
|
400
|
+
off: {
|
401
|
+
<Key_1 extends keyof VisitorDataStoreEvents>(type: Key_1, handler?: mitt.Handler<VisitorDataStoreEvents[Key_1]> | undefined): void;
|
402
|
+
(type: "*", handler: mitt.WildcardHandler<VisitorDataStoreEvents>): void;
|
403
|
+
};
|
404
|
+
};
|
405
|
+
/** Push data update command(s) into the visitor data */
|
406
|
+
updateData(commands: StorageCommands[]): Promise<void>;
|
407
|
+
/**
|
408
|
+
* Deletes visitor data (forgetting them)
|
409
|
+
* In most cases you should use forget() on the Context instead of this function, which also clears the Context state.
|
410
|
+
* @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
|
411
|
+
*/
|
412
|
+
delete(fromAllDevices: boolean): Promise<void>;
|
413
|
+
}
|
414
|
+
|
415
|
+
declare class ManifestInstance {
|
416
|
+
#private;
|
417
|
+
readonly data: ManifestV2;
|
418
|
+
constructor({ manifest, evaluator, }: {
|
419
|
+
manifest: ManifestV2;
|
420
|
+
evaluator?: GroupCriteriaEvaluator;
|
421
|
+
});
|
422
|
+
rollForControlGroup(): boolean;
|
423
|
+
getTest(name: string): TestDefinition | undefined;
|
424
|
+
computeSignals(update: ContextStateUpdate): StorageCommands[];
|
425
|
+
/**
|
426
|
+
* Computes aggregated scores based on other dimensions
|
427
|
+
*/
|
428
|
+
computeAggregateDimensions(primitiveScores: ScoreVector): ScoreVector;
|
429
|
+
getDimensionByKey(scoreKey: string): EnrichmentCategory | Signal | undefined;
|
430
|
+
}
|
431
|
+
|
432
|
+
declare type SharedTypes = external['uniform-context-types.swagger.yml']['components']['schemas'];
|
433
|
+
declare type ManifestV2 = components['schemas']['ManifestV2'];
|
434
|
+
declare type PersonalizationManifest = components['schemas']['PersonalizationManifest'];
|
435
|
+
declare type Signal = SharedTypes['Signal'];
|
436
|
+
declare type SignalCriteriaGroup = SharedTypes['SignalCriteriaGroup'];
|
437
|
+
declare type SignalCriteria = SharedTypes['SignalCriteria'];
|
438
|
+
declare type EnrichmentCategory = SharedTypes['EnrichmentCategory'];
|
439
|
+
declare type StringMatch = SharedTypes['StringMatch'];
|
440
|
+
declare type NumberMatch = SharedTypes['NumberMatch'];
|
441
|
+
declare type TestDefinition = SharedTypes['Test'];
|
442
|
+
declare type AggregateDimension = SharedTypes['AggregateDimension'];
|
443
|
+
declare type AggregateDimensionInput = SharedTypes['AggregateDimensionInput'];
|
444
|
+
|
445
|
+
declare const cookieEvaluator: CriteriaEvaluator;
|
446
|
+
|
447
|
+
declare const pageViewCountDimension: string;
|
448
|
+
declare const pageViewCountEvaluator: CriteriaEvaluator;
|
449
|
+
|
450
|
+
declare const queryStringEvaluator: CriteriaEvaluator;
|
451
|
+
|
452
|
+
declare const quirkEvaluator: CriteriaEvaluator;
|
453
|
+
|
454
|
+
declare const eventEvaluator: CriteriaEvaluator;
|
455
|
+
|
456
|
+
declare const pageVisitedEvaluator: CriteriaEvaluator;
|
457
|
+
|
458
|
+
/**
|
459
|
+
* A type that evaluates a signal criteria type and
|
460
|
+
* decides if it matches the current Context state or not.
|
461
|
+
* @returns {boolean} - true for a match, false for no match
|
462
|
+
* */
|
463
|
+
declare type CriteriaEvaluator = (update: ContextStateUpdate, criteria: SignalCriteria, commands: StorageCommands[], signal: Signal, dimension: string) => boolean;
|
464
|
+
|
465
|
+
declare class GroupCriteriaEvaluator {
|
466
|
+
#private;
|
467
|
+
constructor(criteriaEvaluators: Record<string, CriteriaEvaluator>);
|
468
|
+
evaluate(update: ContextStateUpdate, crit: SignalCriteriaGroup, commands: StorageCommands[], signal: Signal, dimension: string): boolean;
|
469
|
+
}
|
470
|
+
|
471
|
+
/** Tests if a StringMatch matches a string value */
|
472
|
+
declare function isStringMatch(lhs: string | null | undefined, match: StringMatch): boolean;
|
473
|
+
|
474
|
+
/** Computes aggregated scores based on other dimensions */
|
475
|
+
declare function computeAggregateDimensions(primitiveScores: ScoreVector, aggregates: Record<string, AggregateDimension>): ScoreVector;
|
476
|
+
|
477
|
+
declare function getEnrichmentVectorKey(category: string, value: string): string;
|
478
|
+
|
246
479
|
/** Content that is tagged for adding enrichment score when triggered by behavior (i.e. being shown that content) */
|
247
480
|
declare type BehaviorTag = {
|
248
481
|
beh?: EnrichmentData[];
|
@@ -381,9 +614,27 @@ declare const testVariations: <TVariant extends TestVariant>({ name, context, va
|
|
381
614
|
context: Context;
|
382
615
|
}) => TestResult<TVariant>;
|
383
616
|
|
617
|
+
/**
|
618
|
+
* Defines a plugin for Uniform Context.
|
619
|
+
* The plugin should attach event handlers in its creation function.
|
620
|
+
* @returns A function that detaches any event handlers when called
|
621
|
+
*/
|
622
|
+
declare type ContextPlugin = {
|
623
|
+
logDrain?: LogDrain;
|
624
|
+
init?: (context: Context) => () => void;
|
625
|
+
};
|
384
626
|
declare type ContextOptions = {
|
627
|
+
/** The Context Manifest to load (from the Context API) */
|
385
628
|
manifest: ManifestV2;
|
386
|
-
|
629
|
+
/**
|
630
|
+
* Context plugins to load at initialize time.
|
631
|
+
* Plugins that hook to the log event should be added here so that they can catch init-time log message events.
|
632
|
+
*
|
633
|
+
* Note that the Context passed to the plugin is not yet fully initialized, and is intended for event handler attachment
|
634
|
+
* only - don't call scores, update, etc on it. If you need to call these methods immediately, attach your plugin after initialisation.
|
635
|
+
*/
|
636
|
+
plugins?: Array<ContextPlugin>;
|
637
|
+
} & Omit<VisitorDataStoreOptions, 'manifest' | 'onServerTransitionScoresReceived'>;
|
387
638
|
declare type PersonalizationEvent = {
|
388
639
|
name: string;
|
389
640
|
variantIds: string[];
|
@@ -406,7 +657,11 @@ declare type ContextEvents = {
|
|
406
657
|
* (e.g. setting it to the same value it already has)
|
407
658
|
*/
|
408
659
|
quirksUpdated: Quirks;
|
409
|
-
/**
|
660
|
+
/**
|
661
|
+
* Fired when a log message is emitted from Context
|
662
|
+
* Note that event handlers attached to this event will not catch events
|
663
|
+
* logged during initialisation of the Context unless they are attached as plugins to the constructor.
|
664
|
+
*/
|
410
665
|
log: LogMessage;
|
411
666
|
/** Test variant has been selected */
|
412
667
|
testResult: TestEvent;
|
@@ -415,6 +670,7 @@ declare type ContextEvents = {
|
|
415
670
|
};
|
416
671
|
declare class Context implements Context {
|
417
672
|
#private;
|
673
|
+
readonly manifest: ManifestInstance;
|
418
674
|
constructor(options: ContextOptions);
|
419
675
|
get scores(): Readonly<ScoreVector>;
|
420
676
|
/**
|
@@ -450,183 +706,6 @@ declare class Context implements Context {
|
|
450
706
|
forget(fromAllDevices: boolean): Promise<void>;
|
451
707
|
}
|
452
708
|
|
453
|
-
/** Defines all error codes and their parameter(s) */
|
454
|
-
declare type LogMessages = {
|
455
|
-
/** Context constructed */
|
456
|
-
1: MessageFunc<{
|
457
|
-
options: ContextOptions;
|
458
|
-
scores: ScoreVector;
|
459
|
-
}>;
|
460
|
-
/** Context received data update */
|
461
|
-
2: MessageFunc<Partial<ContextState>>;
|
462
|
-
/** Context emitted new score vector */
|
463
|
-
3: MessageFunc<ScoreVector>;
|
464
|
-
/** Context emitted updated quirks */
|
465
|
-
4: MessageFunc<Quirks>;
|
466
|
-
/** Storage received update commands */
|
467
|
-
101: MessageFunc<StorageCommands[]>;
|
468
|
-
/** Storage data was updated */
|
469
|
-
102: MessageFunc<VisitorData>;
|
470
|
-
/** Storage data was deleted bool: fromAllDevices */
|
471
|
-
103: MessageFunc<boolean>;
|
472
|
-
/** Storage score was truncated to its cap */
|
473
|
-
110: MessageFunc<{
|
474
|
-
dim: string;
|
475
|
-
score: number;
|
476
|
-
cap: number;
|
477
|
-
}>;
|
478
|
-
/** Storage visitor data expired and was cleared */
|
479
|
-
120: MessageFunc;
|
480
|
-
/** Placement does not have a name */
|
481
|
-
301: MessageFunc;
|
482
|
-
/** Test did not exist */
|
483
|
-
401: MessageFunc<string>;
|
484
|
-
/** Previously shown test variant no longer in variant data */
|
485
|
-
402: MessageFunc<{
|
486
|
-
test: string;
|
487
|
-
variant: string;
|
488
|
-
}>;
|
489
|
-
/** gtag was not present on the page to emit events to */
|
490
|
-
700: MessageFunc;
|
491
|
-
/** Enabled gtag event signal redirection */
|
492
|
-
701: MessageFunc;
|
493
|
-
};
|
494
|
-
|
495
|
-
declare type Severity = 'debug' | 'info' | 'warn' | 'error';
|
496
|
-
declare type MessageFunc<TArg = void> = (arg: TArg) => [string, string, ...any];
|
497
|
-
declare type LogMessage<TID extends keyof LogMessages = keyof LogMessages> = [
|
498
|
-
severity: Severity,
|
499
|
-
id: TID,
|
500
|
-
...args: Parameters<LogMessages[TID]>
|
501
|
-
];
|
502
|
-
declare type LogDrain = (message: LogMessage) => void;
|
503
|
-
|
504
|
-
declare const consoleLogDrain: LogDrain;
|
505
|
-
|
506
|
-
declare const debugConsoleLogDrain: LogDrain;
|
507
|
-
|
508
|
-
declare type VisitorDataStoreOptions = {
|
509
|
-
/** Transition storage used to transfer server or edge side execution state to the client. Unused for client side only. */
|
510
|
-
transitionStore?: TransitionDataStore;
|
511
|
-
/** Duration of a 'visit' measured by this number of milliseconds without performing any updates */
|
512
|
-
visitLifespan?: number;
|
513
|
-
/** Personalization manifest data. If set, the data store will automatically apply score caps in the manifest data. */
|
514
|
-
manifest?: ManifestInstance;
|
515
|
-
/** Allows decaying of scores over time based on time between visits. Default: no decay */
|
516
|
-
decay?: DecayFunction;
|
517
|
-
/**
|
518
|
-
* Sets the default value of storage consent for new unknown visitors.
|
519
|
-
* If storage consent is not given, only in-memory data will be stored which is lost when the browser leaves the page.
|
520
|
-
* @default false - consent is not given for new visitors until they explicitly give it with an update command
|
521
|
-
*/
|
522
|
-
defaultConsent?: boolean;
|
523
|
-
};
|
524
|
-
declare type VisitorDataStoreEvents = {
|
525
|
-
/**
|
526
|
-
* Fired when the stored data is updated.
|
527
|
-
* This is fired for any update, whether from integrated or transition storage.
|
528
|
-
* The event is NOT fired if an update does not result in any score changes.
|
529
|
-
*/
|
530
|
-
scoresUpdated: Pick<VisitorData, 'scores' | 'sessionScores'>;
|
531
|
-
/**
|
532
|
-
* Fired when stored quirks are updated.
|
533
|
-
* This is fired for any update, whether from integrated or transition storage.
|
534
|
-
* The event is NOT fired if an update does not result in any quirk changes.
|
535
|
-
*/
|
536
|
-
quirksUpdated: Pick<VisitorData, 'quirks'>;
|
537
|
-
/** Fired when a log message is emitted from the data store */
|
538
|
-
log: LogMessage;
|
539
|
-
};
|
540
|
-
declare class VisitorDataStore {
|
541
|
-
#private;
|
542
|
-
constructor(options: VisitorDataStoreOptions);
|
543
|
-
/** Gets the current visitor data. This property is always up to date. */
|
544
|
-
get data(): VisitorData;
|
545
|
-
/**
|
546
|
-
* Subscribe to events from storage
|
547
|
-
*/
|
548
|
-
readonly events: {
|
549
|
-
on: {
|
550
|
-
<Key extends keyof VisitorDataStoreEvents>(type: Key, handler: mitt.Handler<VisitorDataStoreEvents[Key]>): void;
|
551
|
-
(type: "*", handler: mitt.WildcardHandler<VisitorDataStoreEvents>): void;
|
552
|
-
};
|
553
|
-
off: {
|
554
|
-
<Key_1 extends keyof VisitorDataStoreEvents>(type: Key_1, handler?: mitt.Handler<VisitorDataStoreEvents[Key_1]> | undefined): void;
|
555
|
-
(type: "*", handler: mitt.WildcardHandler<VisitorDataStoreEvents>): void;
|
556
|
-
};
|
557
|
-
};
|
558
|
-
/** Push data update command(s) into the visitor data */
|
559
|
-
updateData(commands: StorageCommands[]): Promise<void>;
|
560
|
-
/**
|
561
|
-
* Deletes visitor data (forgetting them)
|
562
|
-
* In most cases you should use forget() on the Context instead of this function, which also clears the Context state.
|
563
|
-
* @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
|
564
|
-
*/
|
565
|
-
delete(fromAllDevices: boolean): Promise<void>;
|
566
|
-
}
|
567
|
-
|
568
|
-
declare class ManifestInstance {
|
569
|
-
#private;
|
570
|
-
constructor({ manifest, evaluator, }: {
|
571
|
-
manifest: ManifestV2;
|
572
|
-
evaluator?: GroupCriteriaEvaluator;
|
573
|
-
});
|
574
|
-
rollForControlGroup(): boolean;
|
575
|
-
getTest(name: string): TestDefinition | undefined;
|
576
|
-
computeSignals(update: ContextStateUpdate): StorageCommands[];
|
577
|
-
/**
|
578
|
-
* Computes aggregated scores based on other dimensions
|
579
|
-
*/
|
580
|
-
computeAggregateDimensions(primitiveScores: ScoreVector): ScoreVector;
|
581
|
-
getDimensionByKey(scoreKey: string): EnrichmentCategory | Signal | undefined;
|
582
|
-
static getEnrichmentVectorKey(category: string, value: string): string;
|
583
|
-
}
|
584
|
-
|
585
|
-
declare type SharedTypes = external['uniform-context-types.swagger.yml']['components']['schemas'];
|
586
|
-
declare type ManifestV2 = components['schemas']['ManifestV2'];
|
587
|
-
declare type PersonalizationManifest = components['schemas']['PersonalizationManifest'];
|
588
|
-
declare type Signal = SharedTypes['Signal'];
|
589
|
-
declare type SignalCriteriaGroup = SharedTypes['SignalCriteriaGroup'];
|
590
|
-
declare type SignalCriteria = SharedTypes['SignalCriteria'];
|
591
|
-
declare type EnrichmentCategory = SharedTypes['EnrichmentCategory'];
|
592
|
-
declare type StringMatch = SharedTypes['StringMatch'];
|
593
|
-
declare type NumberMatch = SharedTypes['NumberMatch'];
|
594
|
-
declare type TestDefinition = SharedTypes['Test'];
|
595
|
-
declare type AggregateDimension = SharedTypes['AggregateDimension'];
|
596
|
-
declare type AggregateDimensionInput = SharedTypes['AggregateDimensionInput'];
|
597
|
-
|
598
|
-
declare const cookieEvaluator: CriteriaEvaluator;
|
599
|
-
|
600
|
-
declare const pageViewCountDimension: string;
|
601
|
-
declare const pageViewCountEvaluator: CriteriaEvaluator;
|
602
|
-
|
603
|
-
declare const queryStringEvaluator: CriteriaEvaluator;
|
604
|
-
|
605
|
-
declare const quirkEvaluator: CriteriaEvaluator;
|
606
|
-
|
607
|
-
declare const eventEvaluator: CriteriaEvaluator;
|
608
|
-
|
609
|
-
declare const pageVisitedEvaluator: CriteriaEvaluator;
|
610
|
-
|
611
|
-
/**
|
612
|
-
* A type that evaluates a signal criteria type and
|
613
|
-
* decides if it matches the current Context state or not.
|
614
|
-
* @returns {boolean} - true for a match, false for no match
|
615
|
-
* */
|
616
|
-
declare type CriteriaEvaluator = (update: ContextStateUpdate, criteria: SignalCriteria, commands: StorageCommands[], signal: Signal, dimension: string) => boolean;
|
617
|
-
|
618
|
-
declare class GroupCriteriaEvaluator {
|
619
|
-
#private;
|
620
|
-
constructor(criteriaEvaluators: Record<string, CriteriaEvaluator>);
|
621
|
-
evaluate(update: ContextStateUpdate, crit: SignalCriteriaGroup, commands: StorageCommands[], signal: Signal, dimension: string): boolean;
|
622
|
-
}
|
623
|
-
|
624
|
-
/** Tests if a StringMatch matches a string value */
|
625
|
-
declare function isStringMatch(lhs: string | null | undefined, match: StringMatch): boolean;
|
626
|
-
|
627
|
-
/** Computes aggregated scores based on other dimensions */
|
628
|
-
declare function computeAggregateDimensions(primitiveScores: ScoreVector, aggregates: Record<string, AggregateDimension>): ScoreVector;
|
629
|
-
|
630
709
|
declare enum ScriptType {
|
631
710
|
ListStart = "nesi-list-start",
|
632
711
|
ListEnd = "nesi-list-end",
|
@@ -644,4 +723,76 @@ declare type EdgeTestComponentOptions = {
|
|
644
723
|
};
|
645
724
|
declare const EdgeNodeTagName = "nesitag";
|
646
725
|
|
647
|
-
|
726
|
+
/**
|
727
|
+
* The version of the DevTools UI to load when in Chromium extension context.
|
728
|
+
* 1: Uniform Optimize.
|
729
|
+
* 2: Uniform Context.
|
730
|
+
*/
|
731
|
+
declare type DevToolsUiVersion = 1 | 2;
|
732
|
+
/**
|
733
|
+
* The data state provided to the devtools for rendering.
|
734
|
+
*/
|
735
|
+
declare type DevToolsState = {
|
736
|
+
/** Current computed visitor scores (includes aggregates) */
|
737
|
+
scores: Readonly<ScoreVector>;
|
738
|
+
/** Current visitor data (includes quirks, raw scores, tests, consent, etc) */
|
739
|
+
data: Readonly<VisitorData>;
|
740
|
+
/** Personalization events that have fired since devtools started */
|
741
|
+
personalizations: Array<PersonalizationEvent>;
|
742
|
+
/** Test events that have fired since devtools started */
|
743
|
+
tests: Array<TestEvent>;
|
744
|
+
/** The Context manifest */
|
745
|
+
manifest: ManifestV2;
|
746
|
+
};
|
747
|
+
/** Mutations the DevTools can take on the data it receives */
|
748
|
+
declare type DevToolsActions = {
|
749
|
+
/** Standard updates; maps to Context.update() */
|
750
|
+
update: (newData: Partial<ContextState>) => Promise<void>;
|
751
|
+
/** Raw updates to the storage subsystem. Maps to Context.storage.updateData() */
|
752
|
+
rawUpdate: (commands: StorageCommands[]) => Promise<void>;
|
753
|
+
/** Forget the current visitor and clear data on this device */
|
754
|
+
forget: () => Promise<void>;
|
755
|
+
};
|
756
|
+
declare type DevToolsEvent<Type extends string = string, TEventData = unknown> = {
|
757
|
+
/** The integration ID that is required */
|
758
|
+
type: Type;
|
759
|
+
} & TEventData;
|
760
|
+
declare type DevToolsEvents = DevToolsLogEvent | DevToolsDataEvent | DevToolsHelloEvent | DevToolsUpdateEvent | DevToolsRawCommandsEvent | DevToolsForgetEvent;
|
761
|
+
/** A log message emitted as an event to the browser extension */
|
762
|
+
declare type DevToolsLogEvent = DevToolsEvent<'uniform:context:log', {
|
763
|
+
message: LogMessage;
|
764
|
+
}>;
|
765
|
+
/** Emitted when data is updated in Context to the devtools */
|
766
|
+
declare type DevToolsDataEvent = DevToolsEvent<'uniform:context:data', {
|
767
|
+
data: DevToolsState;
|
768
|
+
}>;
|
769
|
+
/** A hello message emitted as an event from the browser extension to test if the page contains Context */
|
770
|
+
declare type DevToolsHelloEvent = DevToolsEvent<'uniform:context:hello', {
|
771
|
+
uiVersion: DevToolsUiVersion;
|
772
|
+
}>;
|
773
|
+
/** Devtools requests a normal update cycle (regular data update, re-eval signals, etc) */
|
774
|
+
declare type DevToolsUpdateEvent = DevToolsEvent<'uniform-in:context:update', {
|
775
|
+
newData: Partial<ContextState>;
|
776
|
+
}>;
|
777
|
+
/** Devtools requests a raw update cycle (explicitly set scores of dimensions in durations, etc) */
|
778
|
+
declare type DevToolsRawCommandsEvent = DevToolsEvent<'uniform-in:context:commands', {
|
779
|
+
commands: StorageCommands[];
|
780
|
+
}>;
|
781
|
+
/** A request to forget me from the DevTools */
|
782
|
+
declare type DevToolsForgetEvent = DevToolsEvent<'uniform-in:context:forget', unknown>;
|
783
|
+
declare global {
|
784
|
+
interface Window {
|
785
|
+
/** Window var set by enableContextDevTools() to enable embedded devtools to receive Context instance and attach events to it. */
|
786
|
+
__UNIFORM_DEVTOOLS_CONTEXT_INSTANCE__?: Context;
|
787
|
+
}
|
788
|
+
}
|
789
|
+
|
790
|
+
/**
|
791
|
+
* Enables a Context instance to feed data to the Uniform Context DevTools.
|
792
|
+
* DevTools can be hosted either as a Chromium extension, or as a standalone
|
793
|
+
* React app within a page and receive data once this plugin has been activated.
|
794
|
+
* @returns Function that when invoked detaches the event listeners and disables DevTools.
|
795
|
+
*/
|
796
|
+
declare function enableContextDevTools(): ContextPlugin;
|
797
|
+
|
798
|
+
export { AggregateDimension, AggregateDimensionInput, BehaviorTag, Context, ContextEvents, ContextOptions, ContextPlugin, ContextState, ContextStateUpdate, CookieAdapter, CookieTransitionDataStore, CookieTransitionDataStoreOptions, CriteriaEvaluator, DecayFunction, DecayOptions, DevToolsActions, DevToolsDataEvent, DevToolsEvent, DevToolsEvents, DevToolsForgetEvent, DevToolsHelloEvent, DevToolsLogEvent, DevToolsRawCommandsEvent, DevToolsState, DevToolsUiVersion, DevToolsUpdateEvent, DimensionMatch, EdgeNodeTagName, EdgePersonalizeComponentOptions, EdgeTestComponentOptions, EdgeTransitionDataStore, EdgeTransitionDataStoreOptions, EnrichmentCategory, EnrichmentData, EventData, GroupCriteriaEvaluator, IdentifyCommand, LinearDecayOptions, LogDrain, LogMessage, LogMessages, ManifestInstance, ManifestV2, MessageFunc, ModifyScoreCommand, ModifySessionScoreCommand, NumberMatch, OutputSeverity, PersonalizationEvent, PersonalizationManifest, PersonalizeOptions, PersonalizedResult, PersonalizedVariant, Quirks, SERVER_STATE_ID, ScoreVector, ScriptType, ServerToClientTransitionState, SetConsentCommand, SetQuirkCommand, SetTestCommand, Severity, Signal, SignalCriteria, SignalCriteriaGroup, StorageCommand, StorageCommands, StringMatch, TaggedContent, TestDefinition, TestEvent, TestOptions, TestResult, TestVariant, Tests, TransitionDataStore, TransitionDataStoreEvents, TransitionDataStoreOptions, VariantMatchCriteria, VisitorData, VisitorDataStore, VisitorDataStoreEvents, VisitorDataStoreOptions, computeAggregateDimensions, cookieEvaluator, createConsoleLogDrain, createDebugConsoleLogDrain, createLinearDecay, emptyVisitorData, enableConsoleLogDrain, enableContextDevTools, enableDebugConsoleLogDrain, evaluateVariantMatch, eventEvaluator, getEnrichmentVectorKey, isStringMatch, pageViewCountDimension, pageViewCountEvaluator, pageVisitedEvaluator, personalizeVariations, queryStringEvaluator, quirkEvaluator, testVariations };
|
package/dist/index.esm.js
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
import{b as y,c as s,d as u,e as m,f as h}from"./chunk-TRWANXVF.mjs";function nt(i,t){let e={...i};for(let r in t){let o=at(i,r,t,new Set([r]));o!==0&&(e[r]=o)}return e}function at(i,t,e,r){var n;let o=0;for(let a of e[t].inputs){let c=(n=i[a.dim])!=null?n:0;if(!c&&e[a.dim]){if(r.has(a.dim))continue;let f=new Set(r);f.add(a.dim),c=at(i,a.dim,e,f)}if(c!==0)if(a.sign==="c"){o=0;break}else a.sign==="-"?o-=c:o+=c}return o}var A,k,X=class{constructor(t,e,r){u(this,A,void 0);u(this,k,void 0);y(this,"signal");m(this,k,t),this.signal=e,m(this,A,r)}computeSignals(t,e){if(t.scores[s(this,k)]>=this.signal.cap&&this.signal.dur!=="t")return;let o=s(this,A).evaluate(t,this.signal.crit,e,this.signal,s(this,k)),n=this.signal.dur==="s"||this.signal.dur==="t"?"modscoreS":"modscore";if(o)e.push({type:n,data:{dimension:s(this,k),delta:this.signal.str}});else if(this.signal.dur==="t"){let a=t.visitor.sessionScores[s(this,k)];a&&e.push({type:n,data:{dimension:s(this,k),delta:-a}})}}};A=new WeakMap,k=new WeakMap;var ct="_",C,$,R=class{constructor({manifest:t,evaluator:e=new N({})}){u(this,C,void 0);u(this,$,void 0);var r,o,n;m(this,C,(r=t.project)!=null?r:{}),m(this,$,Object.entries((n=(o=s(this,C).pz)==null?void 0:o.sig)!=null?n:[]).map(([a,c])=>new X(a,c,e)))}rollForControlGroup(){var t,e;return Math.random()<((e=(t=s(this,C).pz)==null?void 0:t.control)!=null?e:0)}getTest(t){var e;return(e=s(this,C).test)==null?void 0:e[t]}computeSignals(t){let e=[];return s(this,$).forEach(r=>{r.computeSignals(t,e)}),e}computeAggregateDimensions(t){var e,r;return nt(t,(r=(e=s(this,C).pz)==null?void 0:e.agg)!=null?r:{})}getDimensionByKey(t){var r,o,n,a;let e=t.indexOf(ct);return e<=0?(o=(r=s(this,C).pz)==null?void 0:r.sig)==null?void 0:o[t]:(a=(n=s(this,C).pz)==null?void 0:n.enr)==null?void 0:a[t.substring(0,e)]}static getEnrichmentVectorKey(t,e){return`${t}${ct}${e}`}};C=new WeakMap,$=new WeakMap;var ut=(i,t)=>{var o;if(t.type!=="CK")return!1;let e=(o=i.state.cookies)==null?void 0:o[t.cookieName];return x(e,t.match)};function dt(i,t){var r;if(typeof i=="undefined"||i===null)return!1;let e=Number(i);if(isNaN(e))return!1;switch((r=t==null?void 0:t.op)!=null?r:"="){case"=":return e===t.rhs;case"!=":return e!==t.rhs;case">":return e>t.rhs;case"<":return e<t.rhs;default:return console.warn(`Unknown match type ${t.op} is false.`),!1}}var Z=R.getEnrichmentVectorKey("$pvc","v"),lt=(i,t,e)=>{var a,c;if(t.type!=="PVC")return!1;let r=!i.previousState||((a=i.state.url)==null?void 0:a.toString())!==((c=i.previousState.url)==null?void 0:c.toString()),n=(i.visitor.sessionScores[Z]||0)+1;if(dt(n,t.match)){let d=e.some(f=>f.type==="modscoreS"&&f.data.dimension===Z);return r&&!d&&e.push({type:"modscoreS",data:{dimension:Z,delta:1}}),!0}return!1};var pt=(i,t)=>{var r;if(t.type!=="QS")return!1;let e=(r=i.state.url)==null?void 0:r.searchParams.get(t.queryName);return x(e,t.match)};var mt=(i,t,e,r,o)=>{if(t.type!=="QK")return!1;if(typeof window=="undefined"&&r.dur==="t"&&i.scores[o]>0)return!0;let n=i.visitor.quirks[t.key];return x(n,t.match)};var ft=(i,t)=>{var e,r;return t.type!=="EVT"?!1:(r=(e=i.state.events)==null?void 0:e.some(o=>x(o.event,t.event)))!=null?r:!1};var gt=(i,t)=>{var e;return t.type!=="PV"?!1:x((e=i.state.url)==null?void 0:e.pathname,t.path)};var G,N=class{constructor(t){u(this,G,void 0);m(this,G,t)}evaluate(t,e,r,o,n){let a=!(e.op==="&"||!e.op);for(let c of e.clauses){let d;if(c.type==="G")d=this.evaluate(t,c,r,o,n);else{let f=s(this,G)[c.type];if(!f)throw new Error(`${c.type} signal criteria not registered`);d=f(t,c,r,o,n)}if(d===a)return a}return!a}};G=new WeakMap;function x(i,t){var a,c,d,f;let e=(a=t==null?void 0:t.op)!=null?a:"=";if(t.op==="*")return i!==null&&typeof i!="undefined";if(t.op==="!*")return i===null||typeof i=="undefined";if(!("rhs"in t))throw new Error(`Match expression is required for match type ${e}`);let r=(c=t.cs)!=null?c:!1,o=r?i!=null?i:"":ht(i),n=r?t.rhs:ht(t.rhs);switch(e){case"=":return o===n;case"!=":return o!==n;case"~":return(d=o.includes(n))!=null?d:!1;case"!~":return!((f=o.includes(n))!=null?f:!0);case"//":return new RegExp(t.rhs,r?"":"i").test(i!=null?i:"");case"!//":return!new RegExp(t.rhs,r?"":"i").test(i!=null?i:"");default:throw new Error(`Unknown match type ${e}.`)}}function ht(i){var t;return(t=i==null?void 0:i.toUpperCase())!=null?t:""}var K=()=>({quirks:{},scores:{},sessionScores:{},tests:{},consent:!1,controlGroup:!1});import Ot from"mitt";import{dequal as Ut}from"dequal/lite";var It="__UNIFORM_DATA__",T,q,j=class{constructor({initialData:t}){u(this,T,void 0);u(this,q,Ot());y(this,"events",{on:s(this,q).on,off:s(this,q).off});t&&m(this,T,t)}get data(){return s(this,T)}updateData(t,e){return m(this,T,e),this.handleUpdateData(t,e)}async delete(t){m(this,T,void 0),await this.handleDelete(t)}signalAsyncDataUpdate(t){Ut(this.data,t)||(m(this,T,t),s(this,q).emit("dataUpdatedAsync",t))}getClientTransitionState(){if(typeof document=="undefined")return;let t=document.getElementById(It);return(t==null?void 0:t.textContent)?JSON.parse(t.textContent):void 0}};T=new WeakMap,q=new WeakMap;import{ntob as Rt,bton as qt}from"number-to-base64";var St=typeof window=="undefined",O,U,Lt=class extends j{constructor({cookieAdapter:t,cookieName:e="ufvd"}){super({initialData:St?zt(t.get(e)):void 0});u(this,O,void 0);u(this,U,void 0);m(this,O,e),m(this,U,t)}handleDelete(){return s(this,U).remove(s(this,O)),Promise.resolve()}async handleUpdateData(t,e){St||(e.consent?s(this,U).set(s(this,O),At(e)):s(this,U).remove(s(this,O)))}};O=new WeakMap,U=new WeakMap;var yt="~",vt="!",Dt="-";function zt(i){if(!i)return;let t=i.split(yt);if(t.length>3)return;let[e,r,o]=t;return{consent:!0,sessionScores:Vt(tt(r)),scores:Vt(tt(o)),tests:tt(e)}}function tt(i){return i.split(vt).map(e=>e.split(Dt)).reduce((e,r)=>(r.length!==2||(e[r[0]]=r[1]),e),{})}function Vt(i){return Object.entries(i).reduce((t,[e,r])=>(t[e]=qt(r),t),{})}function At(i){return[et(i.tests),et(Ct(i.sessionScores)),et(Ct(i.scores))].join(yt)}function Ct(i){return Object.entries(i).reduce((t,[e,r])=>(t[e]=Rt(r),t),{})}function et(i){return Object.entries(i).map(t=>t.join(Dt)).join(vt)}var J,Nt,$t=class extends j{constructor({cookieAdapter:t,visitorIdCookieName:e="ufvi",...r}){super(r);u(this,J);r.initialData||h(this,J,Nt).call(this).catch(o=>{console.error(o)})}handleDelete(t){throw new Error("Method not implemented.")}async handleUpdateData(t){let e=await new Promise(r=>{setTimeout(()=>{r(void 0)},2e3)});e&&this.signalAsyncDataUpdate(e)}};J=new WeakSet,Nt=async function(){let t=await new Promise(e=>{setTimeout(()=>{e(void 0)},2e3)});t&&this.signalAsyncDataUpdate(t)};function Ae(i){let{gracePeriod:t=864e5,decayRate:e=1/30,decayCap:r=.95}=i!=null?i:{};return function({now:n,lastUpd:a,scores:c,sessionScores:d}){if(typeof a!="number")return!1;let M=n-a-t;if(M<=0)return!1;let Q=M/864e5,W=1-Math.min(r,Q*e);return W<=0?!1:(xt(c,W),xt(d,W),!0)}}function xt(i,t){for(let e in i)i[e]*=t}import _t from"mitt";import{dequal as it}from"dequal/lite";var rt=class{constructor(){y(this,"inMemoryFallback",{});y(this,"hasLocalStorageObject",typeof localStorage!="undefined")}get(t){let e=this.inMemoryFallback[t];if(!this.hasLocalStorageObject||e)return e;try{let r=localStorage.getItem(t);return r?JSON.parse(r):void 0}catch(r){return e}}set(t,e,r){if(this.inMemoryFallback[t]=e,!(!this.hasLocalStorageObject||!r))try{localStorage.setItem(t,JSON.stringify(e))}catch(o){console.warn(o)}}delete(t,e){e||delete this.inMemoryFallback[t];try{localStorage.removeItem(t)}catch(r){}}};import Gt from"rfdc";var jt=Gt();function kt(i,t,e){let r=t?jt(t):K();return i.forEach(o=>{var n,a;switch(o.type){case"consent":r.consent=o.data;break;case"setquirk":r.quirks[o.data.key]=o.data.value;break;case"settest":r.tests[o.data.test]=o.data.variant;break;case"modscore":if(e)break;let c=(n=r.scores[o.data.dimension])!=null?n:0;r.scores[o.data.dimension]=c+o.data.delta;break;case"modscoreS":if(e)break;let d=(a=r.sessionScores[o.data.dimension])!=null?a:0;r.sessionScores[o.data.dimension]=d+o.data.delta;break;case"identify":break;default:throw new Error("Unknown command")}}),r}var B="ufvisitor",v,I,z,S,D,w,b,L,Y,Ft,H,Qt,_,bt,F,Et,ot=class{constructor(t){u(this,D);u(this,b);u(this,Y);u(this,H);u(this,_);u(this,F);u(this,v,_t());u(this,I,new rt);u(this,z,void 0);u(this,S,void 0);y(this,"events",{on:s(this,v).on,off:s(this,v).off});if(m(this,S,t),s(this,D,w)||h(this,b,L).call(this,h(this,F,Et).call(this),!0),t.transitionStore){let e=t.transitionStore.getClientTransitionState();e&&e.quirks&&this.updateData(Object.entries(e.quirks).map(([o,n])=>({type:"setquirk",data:{key:o,value:n}}))),t.transitionStore.events.on("dataUpdatedAsync",o=>{h(this,b,L).call(this,{...s(this,D,w).visitorData,...o})});let r=t.transitionStore.data;r&&h(this,b,L).call(this,{...s(this,D,w).visitorData,...r},!0)}}get data(){let t=s(this,D,w);if(h(this,H,Qt).call(this,t)){let{sessionScores:e,...r}=t.visitorData;return h(this,b,L).call(this,{...r,sessionScores:{}}),s(this,v).emit("log",["info",120]),s(this,D,w).visitorData}return t.visitorData}async updateData(t){var r,o;if(t.length===0)return;s(this,v).emit("log",["debug",101,t]);let e=kt(t,this.data,(r=s(this,D,w))==null?void 0:r.visitorData.controlGroup);t.some(n=>n.type==="consent"&&!n.data)&&s(this,I).delete(B,!0),h(this,b,L).call(this,e),await((o=s(this,S).transitionStore)==null?void 0:o.updateData(t,s(this,D,w).visitorData))}async delete(t){var e;s(this,I).delete(B,!1),await((e=s(this,S).transitionStore)==null?void 0:e.delete(t)),s(this,v).emit("log",["info",103,t]),h(this,b,L).call(this,h(this,F,Et).call(this))}};v=new WeakMap,I=new WeakMap,z=new WeakMap,S=new WeakMap,D=new WeakSet,w=function(){return s(this,I).get(B)},b=new WeakSet,L=function(t,e=!1){var f,M;let r=s(this,D,w),o=Date.now();h(this,_,bt).call(this,t.scores),h(this,_,bt).call(this,t.sessionScores),(M=(f=s(this,S)).decay)==null||M.call(f,{now:o,lastUpd:r==null?void 0:r.updated,scores:t.scores,sessionScores:t.sessionScores});let n=!it(r==null?void 0:r.visitorData.scores,t.scores),a=!it(r==null?void 0:r.visitorData.sessionScores,t.sessionScores),c=!it(r==null?void 0:r.visitorData.quirks,t.quirks),d={updated:o,visitorData:t};h(this,Y,Ft).call(this),s(this,I).set(B,d,!!t.consent),s(this,v).emit("log",["debug",102,t]),e||((n||a)&&s(this,v).emit("scoresUpdated",t),c&&s(this,v).emit("quirksUpdated",t))},Y=new WeakSet,Ft=function(){typeof window=="undefined"||!s(this,S).visitLifespan||(s(this,z)&&window.clearTimeout(s(this,z)),m(this,z,window.setTimeout(()=>{this.data},s(this,S).visitLifespan+50)))},H=new WeakSet,Qt=function(t){let e=s(this,S).visitLifespan;return e?t.updated+e<Date.now():!1},_=new WeakSet,bt=function(t){if(!!s(this,S).manifest)for(let e in t){let r=t[e],o=s(this,S).manifest.getDimensionByKey(e);!o||r>o.cap&&(s(this,v).emit("log",["debug",110,{dim:e,score:r,cap:o.cap}]),t[e]=o.cap)}},F=new WeakSet,Et=function(){var t,e,r;return{...K(),consent:(t=s(this,S).defaultConsent)!=null?t:!1,controlGroup:(r=(e=s(this,S).manifest)==null?void 0:e.rollForControlGroup())!=null?r:!1}};import Jt from"mitt";function Tt({context:i,variations:t,take:e=1}){var c;let r=(c=i.storage.data.controlGroup)!=null?c:!1,o=[],n=!1,a=i.scores;for(let d of t){if(o.length===e)break;if(!d.pz){o.push(d);continue}!r&&wt(d.pz,a)&&(n=!0,o.push(d))}return{personalized:n,variations:o}}function wt(i,t){return(i==null?void 0:i.crit)?!i.op||i.op==="&"?i.crit.every(e=>Pt(e,t)):i.crit.some(e=>Pt(e,t)):!0}function Pt(i,t){var a;let{op:e,l:r}=i,o=(a=t[r])!=null?a:0;if(e==="+")return Math.max(...Object.values(t))===o&&o>0;if(e==="-")return Math.min(...Object.values(t))===o&&o>0;let n=i.rDim?t[i.rDim]:i.r;if(n===void 0)return!1;if(e===">")return o>n;if(e===">=")return o>=n;if(e==="<")return o<n;if(e==="<=")return o<=n;if(e==="=")return o===n;if(e==="!=")return o!==n;throw new Error(`Unknown op: ${e}`)}var Kt=i=>{let{values:t,total:e,missingDistribution:r}=i.reduce((o,n)=>(n.testDistribution?o.total+=n.testDistribution:++o.missingDistribution,o.values.push(n.testDistribution),o),{values:[],total:0,missingDistribution:0});if(e>100)throw new Error(`Total distribution ${e} is over the maximum 100.`);if(e<100){let n=(100-e)/r;t.forEach((a,c)=>{typeof a=="undefined"&&(t[c]=n)})}return t},st=({name:i,context:t,variations:e})=>{var n;let r,o=t.getTestVariantId(i);if(o===null)return{result:void 0};if(o&&(r=e.find(a=>a.id===o),r||t.log("warn",401,{test:i,variant:o})),!r){let a=Kt(e),c=Math.floor(Math.random()*100),d=0;r=e.find((f,M)=>{let Q=a[M];if(c>d&&c<=d+Q)return f;d+=Q}),r&&t.setTestVariantId(i,(n=r.id)!=null?n:"Unknown")}return{result:r}};var E,P,V,g,Bt=class{constructor(t){u(this,E,void 0);u(this,P,{});u(this,V,void 0);u(this,g,Jt());y(this,"events",{on:s(this,g).on,off:s(this,g).off});y(this,"storage");let{manifest:e,...r}=t;m(this,V,{}),m(this,E,new R({manifest:e,evaluator:new N({CK:ut,QS:pt,QK:mt,PVC:lt,EVT:ft,PV:gt})})),this.storage=new ot({manifest:s(this,E),...r}),this.storage.events.on("log",(...n)=>s(this,g).emit("log",...n));let o=n=>{var c;let a={...n.scores};for(let d in n.sessionScores)a[d]=((c=a[d])!=null?c:0)+n.sessionScores[d];a=s(this,E).computeAggregateDimensions(a),m(this,P,a),s(this,g).emit("scoresUpdated",a),s(this,g).emit("log",["info",3,a])};this.storage.events.on("scoresUpdated",o),o(this.storage.data),this.storage.events.on("quirksUpdated",n=>{let a=s(this,E).computeSignals({scores:s(this,P),state:s(this,V),previousState:s(this,V),visitor:this.storage.data});this.storage.updateData(a),s(this,g).emit("quirksUpdated",n.quirks),s(this,g).emit("log",["info",4,n.quirks])}),s(this,g).emit("log",["debug",1,{options:t,scores:s(this,P)}])}get scores(){return s(this,P)}async update(t){let e=[];s(this,g).emit("log",["info",2,t]),t.quirks&&(e.push(...Object.entries(t.quirks).map(([o,n])=>({type:"setquirk",data:{key:o,value:n}}))),t.quirks=void 0),t.enrichments&&(e.push(...t.enrichments.map(o=>({type:"modscore",data:{dimension:R.getEnrichmentVectorKey(o.cat,o.key),delta:o.str}}))),t.enrichments=void 0);let r=s(this,V);m(this,V,{...s(this,V),...t}),e.push(...s(this,E).computeSignals({state:s(this,V),previousState:r,visitor:this.storage.data,scores:s(this,P)})),await this.storage.updateData(e)}getTestVariantId(t){var r;let e=s(this,E).getTest(t);return e?(r=e.wv)!=null?r:this.storage.data.tests[t]:(s(this,g).emit("log",["warn",401,t]),null)}setTestVariantId(t,e){this.storage.updateData([{type:"settest",data:{test:t,variant:e}}])}log(...t){s(this,g).emit("log",t)}test(t){var r;let e=st({...t,context:this});return s(this,g).emit("testResult",{name:t.name,variantId:(r=e.result)==null?void 0:r.id,control:this.storage.data.controlGroup}),e}personalize(t){let e=Tt({...t,context:this});return t.name?s(this,g).emit("personalizationResult",{name:t.name,variantIds:e.variations.map(r=>{var o;return(o=r.id)!=null?o:"Unknown"}),control:this.storage.data.controlGroup}):this.log("warn",301),e}async forget(t){m(this,V,{}),await this.storage.delete(t)}};E=new WeakMap,P=new WeakMap,V=new WeakMap,g=new WeakMap;var Dr=([i,t,...e])=>{console[i](`\u{1F94B} [${i}] Uniform event ID ${t}
|
2
|
-
`,...
|
3
|
-
`,...
|
1
|
+
import{d as v,e as n,f as m,g,h as y,i as u}from"./chunk-KZPEO35A.mjs";u();u();u();function gt(r,t){let e={...r};for(let o in t){let i=ht(r,o,t,new Set([o]));i!==0&&(e[o]=i)}return e}function ht(r,t,e,o){var s;let i=0;for(let a of e[t].inputs){let c=(s=r[a.dim])!=null?s:0;if(!c&&e[a.dim]){if(o.has(a.dim))continue;let f=new Set(o);f.add(a.dim),c=ht(r,a.dim,e,f)}if(c!==0)if(a.sign==="c"){i=0;break}else a.sign==="-"?i-=c:i+=c}return i}u();var K="_";u();var N,k,et=class{constructor(t,e,o){m(this,N,void 0);m(this,k,void 0);v(this,"signal");g(this,k,t),this.signal=e,g(this,N,o)}computeSignals(t,e){if(t.scores[n(this,k)]>=this.signal.cap&&this.signal.dur!=="t")return;let i=n(this,N).evaluate(t,this.signal.crit,e,this.signal,n(this,k)),s=this.signal.dur==="s"||this.signal.dur==="t"?"modscoreS":"modscore";if(i)e.push({type:s,data:{dimension:n(this,k),delta:this.signal.str}});else if(this.signal.dur==="t"){let a=t.visitor.sessionScores[n(this,k)];a&&e.push({type:s,data:{dimension:n(this,k),delta:-a}})}}};N=new WeakMap,k=new WeakMap;var b,$,rt=class{constructor({manifest:t,evaluator:e=new G({})}){v(this,"data");m(this,b,void 0);m(this,$,void 0);var o,i,s;g(this,b,(o=t.project)!=null?o:{}),this.data=t,g(this,$,Object.entries((s=(i=n(this,b).pz)==null?void 0:i.sig)!=null?s:[]).map(([a,c])=>new et(a,c,e)))}rollForControlGroup(){var t,e;return Math.random()<((e=(t=n(this,b).pz)==null?void 0:t.control)!=null?e:0)}getTest(t){var e;return(e=n(this,b).test)==null?void 0:e[t]}computeSignals(t){let e=[];return n(this,$).forEach(o=>{o.computeSignals(t,e)}),e}computeAggregateDimensions(t){var e,o;return gt(t,(o=(e=n(this,b).pz)==null?void 0:e.agg)!=null?o:{})}getDimensionByKey(t){var o,i,s,a;let e=t.indexOf(K);return e<=0?(i=(o=n(this,b).pz)==null?void 0:o.sig)==null?void 0:i[t]:(a=(s=n(this,b).pz)==null?void 0:s.enr)==null?void 0:a[t.substring(0,e)]}};b=new WeakMap,$=new WeakMap;u();var St=(r,t)=>{var i;if(t.type!=="CK")return!1;let e=(i=r.state.cookies)==null?void 0:i[t.cookieName];return E(e,t.match)};u();u();function vt(r,t){var o;if(typeof r=="undefined"||r===null)return!1;let e=Number(r);if(isNaN(e))return!1;switch((o=t==null?void 0:t.op)!=null?o:"="){case"=":return e===t.rhs;case"!=":return e!==t.rhs;case">":return e>t.rhs;case"<":return e<t.rhs;default:return console.warn(`Unknown match type ${t.op} is false.`),!1}}u();function J(r,t){return`${r}${K}${t}`}var ot=J("$pvc","v"),yt=(r,t,e)=>{var a,c;if(t.type!=="PVC")return!1;let o=!r.previousState||((a=r.state.url)==null?void 0:a.toString())!==((c=r.previousState.url)==null?void 0:c.toString()),s=(r.visitor.sessionScores[ot]||0)+1;if(vt(s,t.match)){let d=e.some(f=>f.type==="modscoreS"&&f.data.dimension===ot);return o&&!d&&e.push({type:"modscoreS",data:{dimension:ot,delta:1}}),!0}return!1};u();var Dt=(r,t)=>{var o;if(t.type!=="QS")return!1;let e=(o=r.state.url)==null?void 0:o.searchParams.get(t.queryName);return E(e,t.match)};u();var Ct=(r,t,e,o,i)=>{if(t.type!=="QK")return!1;if(typeof window=="undefined"&&o.dur==="t"&&r.scores[i]>0)return!0;let s=r.visitor.quirks[t.key];return E(s,t.match)};u();var Vt=(r,t)=>{var e,o;return t.type!=="EVT"?!1:(o=(e=r.state.events)==null?void 0:e.some(i=>E(i.event,t.event)))!=null?o:!1};u();var xt=(r,t)=>{var e;return t.type!=="PV"?!1:E((e=r.state.url)==null?void 0:e.pathname,t.path)};u();var _,G=class{constructor(t){m(this,_,void 0);g(this,_,t)}evaluate(t,e,o,i,s){let a=!(e.op==="&"||!e.op);for(let c of e.clauses){let d;if(c.type==="G")d=this.evaluate(t,c,o,i,s);else{let f=n(this,_)[c.type];if(!f)throw new Error(`${c.type} signal criteria not registered`);d=f(t,c,o,i,s)}if(d===a)return a}return!a}};_=new WeakMap;u();function E(r,t){var a,c,d,f;let e=(a=t==null?void 0:t.op)!=null?a:"=";if(t.op==="*")return r!==null&&typeof r!="undefined";if(t.op==="!*")return r===null||typeof r=="undefined";if(!("rhs"in t))throw new Error(`Match expression is required for match type ${e}`);let o=(c=t.cs)!=null?c:!1,i=o?r!=null?r:"":bt(r),s=o?t.rhs:bt(t.rhs);switch(e){case"=":return i===s;case"!=":return i!==s;case"~":return(d=i.includes(s))!=null?d:!1;case"!~":return!((f=i.includes(s))!=null?f:!0);case"//":return new RegExp(t.rhs,o?"":"i").test(r!=null?r:"");case"!//":return!new RegExp(t.rhs,o?"":"i").test(r!=null?r:"");default:throw new Error(`Unknown match type ${e}.`)}}function bt(r){var t;return(t=r==null?void 0:r.toUpperCase())!=null?t:""}u();var B=()=>({quirks:{},scores:{},sessionScores:{},tests:{},consent:!1,controlGroup:!1});u();u();import _t from"mitt";import{dequal as jt}from"dequal/lite";var Ft="__UNIFORM_DATA__",P,I,j=class{constructor({initialData:t}){m(this,P,void 0);m(this,I,_t());v(this,"events",{on:n(this,I).on,off:n(this,I).off});t&&g(this,P,t)}get data(){return n(this,P)}updateData(t,e){return g(this,P,e),this.handleUpdateData(t,e)}async delete(t){g(this,P,void 0),await this.handleDelete(t)}signalAsyncDataUpdate(t){jt(this.data,t)||(g(this,P,t),n(this,I).emit("dataUpdatedAsync",t))}getClientTransitionState(){if(typeof document=="undefined")return;let t=document.getElementById(Ft);return(t==null?void 0:t.textContent)?JSON.parse(t.textContent):void 0}};P=new WeakMap,I=new WeakMap;u();var it="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",Et=it.split(""),Tt=new Array(123);for(let r=0;r<it.length;r++)Tt[it.charCodeAt(r)]=r;var nt=r=>{if(r<0)return`-${nt(-r)}`;let t=r>>>0,e=r/4294967296>>>0,o="";for(;e>0;)o=Et[63&t]+o,t>>>=6,t|=(63&e)<<26,e>>>=6;let i="";do i=Et[63&t]+i,t>>>=6;while(t>0);return i+o},kt=r=>{let t=0,e=r.charAt(0)==="-"?1:0;for(let o=e;o<r.length;o++)t=t*64+Tt[r.charCodeAt(o)];return e?-t:t};var wt=typeof window=="undefined",R,L,Qt=class extends j{constructor({cookieAdapter:t,cookieName:e="ufvd"}){super({initialData:wt?Kt(t.get(e)):void 0});m(this,R,void 0);m(this,L,void 0);g(this,R,e),g(this,L,t)}handleDelete(){return n(this,L).remove(n(this,R)),Promise.resolve()}async handleUpdateData(t,e){wt||(e.consent?n(this,L).set(n(this,R),Jt(e)):n(this,L).remove(n(this,R)))}};R=new WeakMap,L=new WeakMap;var Pt="~",Mt="!",Ot="-";function Kt(r){if(!r)return;let t=r.split(Pt);if(t.length>3)return;let[e,o,i]=t;return{consent:!0,sessionScores:Rt(st(o)),scores:Rt(st(i)),tests:st(e)}}function st(r){return r.split(Mt).map(e=>e.split(Ot)).reduce((e,o)=>(o.length!==2||(e[o[0]]=o[1]),e),{})}function Rt(r){return Object.entries(r).reduce((t,[e,o])=>(t[e]=kt(o),t),{})}function Jt(r){return[at(r.tests),at(Lt(r.sessionScores)),at(Lt(r.scores))].join(Pt)}function Lt(r){return Object.entries(r).reduce((t,[e,o])=>(t[e]=nt(o),t),{})}function at(r){return Object.entries(r).map(t=>t.join(Ot)).join(Mt)}u();var H,Ht,Bt=class extends j{constructor({cookieAdapter:t,visitorIdCookieName:e="ufvi",...o}){super(o);m(this,H);o.initialData||y(this,H,Ht).call(this).catch(i=>{console.error(i)})}handleDelete(t){throw new Error("Method not implemented.")}async handleUpdateData(t){let e=await new Promise(o=>{setTimeout(()=>{o(void 0)},2e3)});e&&this.signalAsyncDataUpdate(e)}};H=new WeakSet,Ht=async function(){let t=await new Promise(e=>{setTimeout(()=>{e(void 0)},2e3)});t&&this.signalAsyncDataUpdate(t)};u();function tr(r){let{gracePeriod:t=864e5,decayRate:e=1/30,decayCap:o=.95}=r!=null?r:{};return function({now:s,lastUpd:a,scores:c,sessionScores:d}){if(typeof a!="number")return!1;let x=s-a-t;if(x<=0)return!1;let D=x/864e5,A=1-Math.min(o,D*e);return A<=0?!1:(Ut(c,A),Ut(d,A),!0)}}function Ut(r,t){for(let e in r)r[e]*=t}u();import Wt from"mitt";import{dequal as Y}from"dequal/lite";u();var ut=class{constructor(){v(this,"inMemoryFallback",{});v(this,"hasLocalStorageObject",typeof localStorage!="undefined")}get(t){let e=this.inMemoryFallback[t];if(!this.hasLocalStorageObject||e)return e;try{let o=localStorage.getItem(t);return o?JSON.parse(o):void 0}catch(o){return e}}set(t,e,o){if(this.inMemoryFallback[t]=e,!(!this.hasLocalStorageObject||!o))try{localStorage.setItem(t,JSON.stringify(e))}catch(i){console.warn(i)}}delete(t,e){e||delete this.inMemoryFallback[t];try{localStorage.removeItem(t)}catch(o){}}};u();import Yt from"rfdc";var Xt=Yt();function At(r,t,e){let o=t?Xt(t):B();return r.forEach(i=>{var s,a;switch(i.type){case"consent":o.consent=i.data;break;case"setquirk":o.quirks[i.data.key]=i.data.value;break;case"settest":o.tests[i.data.test]=i.data.variant;break;case"modscore":if(e)break;let c=(s=o.scores[i.data.dimension])!=null?s:0;o.scores[i.data.dimension]=c+i.data.delta;break;case"modscoreS":if(e)break;let d=(a=o.sessionScores[i.data.dimension])!=null?a:0;o.sessionScores[i.data.dimension]=d+i.data.delta;break;case"identify":break;default:throw new Error("Unknown command")}}),o}var X="ufvisitor",T,U,q,h,C,M,w,z,W,Zt,Z,te,F,It,Q,zt,ct=class{constructor(t){m(this,C);m(this,w);m(this,W);m(this,Z);m(this,F);m(this,Q);m(this,T,Wt());m(this,U,new ut);m(this,q,void 0);m(this,h,void 0);v(this,"events",{on:n(this,T).on,off:n(this,T).off});if(g(this,h,t),n(this,C,M)||y(this,w,z).call(this,y(this,Q,zt).call(this),!0),t.transitionStore){let e=t.transitionStore.getClientTransitionState();if(e){let i=[];e.quirks&&i.push(...Object.entries(e.quirks).map(([s,a])=>({type:"setquirk",data:{key:s,value:a}}))),e.tests&&i.push(...Object.entries(e.tests).map(([s,a])=>({type:"settest",data:{test:s,variant:a}}))),this.updateData(i),e.ssv&&t.onServerTransitionScoresReceived&&t.onServerTransitionScoresReceived(e.ssv)}t.transitionStore.events.on("dataUpdatedAsync",i=>{y(this,w,z).call(this,{...n(this,C,M).visitorData,...i})});let o=t.transitionStore.data;o&&y(this,w,z).call(this,{...n(this,C,M).visitorData,...o},!0)}}get data(){var e,o;let t=n(this,C,M);if(y(this,Z,te).call(this,t)){let{sessionScores:i,...s}=t.visitorData;return y(this,w,z).call(this,{...s,sessionScores:{}}),(o=(e=n(this,h)).onLogMessage)==null||o.call(e,["info",120]),n(this,C,M).visitorData}return t.visitorData}get decayEnabled(){return!!n(this,h).decay}async updateData(t){var o,i,s,a;if(t.length===0)return;(i=(o=n(this,h)).onLogMessage)==null||i.call(o,["debug",101,t]);let e=At(t,this.data,(s=n(this,C,M))==null?void 0:s.visitorData.controlGroup);t.some(c=>c.type==="consent"&&!c.data)&&n(this,U).delete(X,!0),y(this,w,z).call(this,e),await((a=n(this,h).transitionStore)==null?void 0:a.updateData(t,n(this,C,M).visitorData))}async delete(t){var e,o,i;n(this,U).delete(X,!1),await((e=n(this,h).transitionStore)==null?void 0:e.delete(t)),y(this,w,z).call(this,y(this,Q,zt).call(this)),(i=(o=n(this,h)).onLogMessage)==null||i.call(o,["info",103,t])}};T=new WeakMap,U=new WeakMap,q=new WeakMap,h=new WeakMap,C=new WeakSet,M=function(){return n(this,U).get(X)},w=new WeakSet,z=function(t,e=!1){var x,D,A,pt,ft,mt;let o=n(this,C,M),i=Date.now();y(this,F,It).call(this,t.scores),y(this,F,It).call(this,t.sessionScores),(D=(x=n(this,h)).decay)==null||D.call(x,{now:i,lastUpd:o==null?void 0:o.updated,scores:t.scores,sessionScores:t.sessionScores});let s=!Y(o==null?void 0:o.visitorData.scores,t.scores),a=!Y(o==null?void 0:o.visitorData.sessionScores,t.sessionScores),c=!Y(o==null?void 0:o.visitorData.quirks,t.quirks),d=!Y(o==null?void 0:o.visitorData.tests,t.tests),f={updated:i,visitorData:t};y(this,W,Zt).call(this),n(this,U).set(X,f,!!t.consent),(pt=(A=n(this,h)).onLogMessage)==null||pt.call(A,["debug",102,t]),e||((s||a)&&n(this,T).emit("scoresUpdated",t),c&&n(this,T).emit("quirksUpdated",t),d&&n(this,T).emit("testsUpdated",t),((ft=o==null?void 0:o.visitorData)==null?void 0:ft.consent)!==t.consent&&n(this,T).emit("consentUpdated",t),((mt=o==null?void 0:o.visitorData)==null?void 0:mt.controlGroup)!==t.controlGroup&&n(this,T).emit("controlGroupUpdated",t))},W=new WeakSet,Zt=function(){typeof window=="undefined"||!n(this,h).visitLifespan||(n(this,q)&&window.clearTimeout(n(this,q)),g(this,q,window.setTimeout(()=>{this.data},n(this,h).visitLifespan+50)))},Z=new WeakSet,te=function(t){let e=n(this,h).visitLifespan;return e?t.updated+e<Date.now():!1},F=new WeakSet,It=function(t){var e,o;if(!!n(this,h).manifest)for(let i in t){let s=t[i],a=n(this,h).manifest.getDimensionByKey(i);!a||s>a.cap&&((o=(e=n(this,h)).onLogMessage)==null||o.call(e,["debug",110,{dim:i,score:s,cap:a.cap}]),t[i]=a.cap)}},Q=new WeakSet,zt=function(){var t,e,o;return{...B(),consent:(t=n(this,h).defaultConsent)!=null?t:!1,controlGroup:(o=(e=n(this,h).manifest)==null?void 0:e.rollForControlGroup())!=null?o:!1}};u();import re from"mitt";u();u();function qt({context:r,variations:t,take:e=1}){var c,d;let o=(c=r.storage.data.controlGroup)!=null?c:!1,i=[],s=!1,a=r.scores;for(let f of t){if(i.length===e)break;if(!((d=f.pz)==null?void 0:d.crit.length)){i.push(f);continue}!o&&Nt(f.pz,a)&&(s=!0,i.push(f))}return{personalized:s,variations:i}}u();function Nt(r,t){return(r==null?void 0:r.crit)?!r.op||r.op==="&"?r.crit.every(e=>$t(e,t)):r.crit.some(e=>$t(e,t)):!0}function $t(r,t){var a;let{op:e,l:o}=r,i=(a=t[o])!=null?a:0;if(e==="+")return Math.max(...Object.values(t))===i&&i>0;if(e==="-")return Math.min(...Object.values(t))===i&&i>0;let s=r.rDim?t[r.rDim]:r.r;if(s===void 0)return!1;if(e===">")return i>s;if(e===">=")return i>=s;if(e==="<")return i<s;if(e==="<=")return i<=s;if(e==="=")return i===s;if(e==="!=")return i!==s;throw new Error(`Unknown op: ${e}`)}u();var ee=r=>{let{values:t,total:e,missingDistribution:o}=r.reduce((i,s)=>(s.testDistribution?i.total+=s.testDistribution:++i.missingDistribution,i.values.push(s.testDistribution),i),{values:[],total:0,missingDistribution:0});if(e>100)throw new Error(`Total distribution ${e} is over the maximum 100.`);if(e<100){let s=(100-e)/o;t.forEach((a,c)=>{typeof a=="undefined"&&(t[c]=s)})}return t},dt=({name:r,context:t,variations:e})=>{var s;let o,i=t.getTestVariantId(r);if(i===null)return{result:void 0};if(i&&(o=e.find(a=>a.id===i),o||t.log("warn",401,{test:r,variant:i})),!o){let a=ee(e),c=Math.floor(Math.random()*100),d=0;o=e.find((f,x)=>{let D=a[x];if(c>d&&c<=d+D)return f;d+=D}),o&&t.setTestVariantId(r,(s=o.id)!=null?s:"Unknown")}return{result:o}};var O,V,S,oe=class{constructor(t){v(this,"manifest");m(this,O,{});m(this,V,void 0);m(this,S,re());v(this,"events",{on:n(this,S).on,off:n(this,S).off});v(this,"storage");var a,c;let{manifest:e,...o}=t;g(this,V,{}),(a=t.plugins)==null||a.forEach(d=>{!d.logDrain||n(this,S).on("log",d.logDrain)}),this.manifest=new rt({manifest:e,evaluator:new G({CK:St,QS:Dt,QK:Ct,PVC:yt,EVT:Vt,PV:xt})});let i=!1;this.storage=new ct({...o,manifest:this.manifest,onServerTransitionScoresReceived:d=>{g(this,O,d),i=!0,n(this,S).emit("log",["debug",130,d])},onLogMessage:d=>n(this,S).emit("log",d)});let s=d=>{var x;let f={...d.scores};for(let D in d.sessionScores)f[D]=((x=f[D])!=null?x:0)+d.sessionScores[D];f=this.manifest.computeAggregateDimensions(f),g(this,O,f),n(this,S).emit("scoresUpdated",f),n(this,S).emit("log",["info",3,f])};this.storage.events.on("scoresUpdated",s),i||s(this.storage.data),this.storage.events.on("quirksUpdated",d=>{let f=this.manifest.computeSignals({scores:n(this,O),state:n(this,V),previousState:n(this,V),visitor:this.storage.data});this.storage.updateData(f),n(this,S).emit("quirksUpdated",d.quirks),n(this,S).emit("log",["info",4,d.quirks])}),n(this,S).emit("log",["debug",1]),(c=t.plugins)==null||c.forEach(d=>{!d.init||d.init(this)})}get scores(){return n(this,O)}async update(t){var i;let e=[];n(this,S).emit("log",["info",2,{...t,url:(i=t.url)==null?void 0:i.toString()}]),t.quirks&&(e.push(...Object.entries(t.quirks).map(([s,a])=>({type:"setquirk",data:{key:s,value:a}}))),t.quirks=void 0),t.enrichments&&(e.push(...t.enrichments.map(s=>({type:"modscore",data:{dimension:J(s.cat,s.key),delta:s.str}}))),t.enrichments=void 0);let o=n(this,V);g(this,V,{...n(this,V),...t}),e.push(...this.manifest.computeSignals({state:n(this,V),previousState:o,visitor:this.storage.data,scores:n(this,O)})),await this.storage.updateData(e)}getTestVariantId(t){var o;let e=this.manifest.getTest(t);return e?(o=e.wv)!=null?o:this.storage.data.tests[t]:(n(this,S).emit("log",["warn",401,t]),null)}setTestVariantId(t,e){this.storage.updateData([{type:"settest",data:{test:t,variant:e}}])}log(...t){n(this,S).emit("log",t)}test(t){var o;let e=dt({...t,context:this});return n(this,S).emit("testResult",{name:t.name,variantId:(o=e.result)==null?void 0:o.id,control:this.storage.data.controlGroup}),e}personalize(t){let e=qt({...t,context:this});return t.name?n(this,S).emit("personalizationResult",{name:t.name,variantIds:e.variations.map(o=>{var i;return(i=o.id)!=null?i:"Unknown"}),control:this.storage.data.controlGroup}):this.log("warn",301),e}async forget(t){g(this,V,{}),await this.storage.delete(t)}};O=new WeakMap,V=new WeakMap,S=new WeakMap;u();u();function tt(r,t){if(r==="none")return!1;switch(t){case"debug":return r==="debug";case"info":return r==="info"||r==="debug";case"warn":return r==="warn"||r==="info"||r==="debug";case"error":return r==="debug"||"info";default:return!1}}function ie(r){return([t,e,...o])=>{!tt(r,t)||console[t](`\u{1F94B} [${t}] Uniform event ID ${e}
|
2
|
+
`,...o.map(i=>JSON.stringify(i,null,2)))}}function qr(r){return{logDrain:ie(r)}}u();u();var Gt={1:()=>["tracker","constructed"],2:r=>["tracker","received data update",r],3:r=>["tracker","new score vector",r],4:r=>["tracker","updated quirks",r],101:r=>["storage","received update commands",r],102:r=>["storage","data was updated",r],103:r=>["storage",`data was deleted ${r?"from all devices":"from this device"}`],110:({dim:r,cap:t,score:e})=>["storage",`${r} score ${e} exceeded cap ${t}. Rounded down.`],120:()=>["storage","visitor data expired and was cleared"],130:r=>["storage","server to client transition score data was loaded; it will persist until the next update event occurs",r],301:()=>["placement","Missing `name` field on personalization. Analytics events will not be triggered."],401:r=>["testing",`${r} was unknown; it will not be run.`],402:({test:r,variant:t})=>["testing",`${r} no longer has visitor's variant ${t}; it will be removed.`],700:()=>["gtag","gtag is not defined, skipping analytics event emission. Ensure you have added the gtag script to your page."],701:()=>["gtag","enabled gtag event signal redirection"]};function ne(r){return([t,e,...o])=>{if(!tt(r,t))return;let i=Gt[e],s=`\u{1F94B} [${new Date().toLocaleTimeString()}][${t}]`;i||console[t](`${s} unknown message ID ${e} - ensure all Uniform packages are the same version`,...o);let[a,c,...d]=i(...o);console[t](`${s}[${a}] ${c} (Event ID: ${e})
|
3
|
+
`,...d.map(f=>JSON.stringify(f,null,2)))}}function jr(r){return{logDrain:ne(r)}}u();var se=(c=>(c.ListStart="nesi-list-start",c.ListEnd="nesi-list-end",c.ListItem="nesi-list-item-html",c.ListItemSettings="nesi-list-item-settings",c.TestStart="nesi-test-start",c.TestEnd="nesi-test-end",c.Unknown="unknown",c))(se||{}),Qr="nesitag";u();var lt=typeof top!="undefined";function Jr(){return{logDrain:r=>{!lt||top==null||top.postMessage({type:"uniform:context:log",message:r},window.location.origin)},init:r=>{let t=[],e=[];lt&&(window.__UNIFORM_DEVTOOLS_CONTEXT_INSTANCE__=r,top==null||top.addEventListener("message",async a=>{if(!a.data)return;let c=a.data;await ae(c,r)}),top==null||top.postMessage({type:"uniform:context:hello",uiVersion:2},window.location.origin));let o=()=>{!lt||top==null||top.postMessage({type:"uniform:context:data",data:{scores:r.scores,data:r.storage.data,manifest:r.manifest.data,personalizations:t,tests:e}},window.location.origin)},i=a=>{t.push(a),o()},s=a=>{e.push(a),o()};return r.events.on("personalizationResult",i),r.events.on("testResult",s),r.storage.events.on("*",o),()=>{r.storage.events.off("*",o),r.events.off("personalizationResult",i),r.events.off("testResult",s)}}}}async function ae(r,t){r.type==="uniform-in:context:update"&&r.newData&&await t.update(r.newData),r.type==="uniform-in:context:commands"&&r.commands&&Array.isArray(r.commands)&&await t.storage.updateData(r.commands),r.type==="uniform-in:context:forget"&&await t.forget(!1)}export{oe as Context,Qt as CookieTransitionDataStore,Qr as EdgeNodeTagName,Bt as EdgeTransitionDataStore,G as GroupCriteriaEvaluator,rt as ManifestInstance,Ft as SERVER_STATE_ID,se as ScriptType,j as TransitionDataStore,ct as VisitorDataStore,gt as computeAggregateDimensions,St as cookieEvaluator,ie as createConsoleLogDrain,ne as createDebugConsoleLogDrain,tr as createLinearDecay,B as emptyVisitorData,qr as enableConsoleLogDrain,Jr as enableContextDevTools,jr as enableDebugConsoleLogDrain,Nt as evaluateVariantMatch,Vt as eventEvaluator,J as getEnrichmentVectorKey,E as isStringMatch,ot as pageViewCountDimension,yt as pageViewCountEvaluator,xt as pageVisitedEvaluator,qt as personalizeVariations,Dt as queryStringEvaluator,Ct as quirkEvaluator,dt as testVariations};
|