@uniformdev/context 12.2.1-alpha.135 → 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/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[];
@@ -322,7 +555,7 @@ declare function personalizeVariations<TVariant extends PersonalizedVariant>({ c
322
555
  context: Context;
323
556
  }): PersonalizedResult<TVariant>;
324
557
 
325
- declare function evaluateVariantMatch(match: VariantMatchCriteria, vec: ScoreVector): boolean;
558
+ declare function evaluateVariantMatch(match: VariantMatchCriteria | undefined | null, vec: ScoreVector): boolean;
326
559
 
327
560
  declare type VariantMatchCriteria = {
328
561
  /**
@@ -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
- } & Omit<VisitorDataStoreOptions, 'manifest'>;
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
- /** Fired when a log message is emitted from Context */
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
- export { AggregateDimension, AggregateDimensionInput, BehaviorTag, Context, ContextEvents, ContextOptions, ContextState, ContextStateUpdate, CookieAdapter, CookieTransitionDataStore, CookieTransitionDataStoreOptions, CriteriaEvaluator, DecayFunction, DecayOptions, DimensionMatch, EdgeNodeTagName, EdgePersonalizeComponentOptions, EdgeTestComponentOptions, EdgeTransitionDataStore, EdgeTransitionDataStoreOptions, EnrichmentCategory, EnrichmentData, EventData, GroupCriteriaEvaluator, IdentifyCommand, LinearDecayOptions, LogDrain, LogMessage, LogMessages, ManifestInstance, ManifestV2, MessageFunc, ModifyScoreCommand, ModifySessionScoreCommand, NumberMatch, 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, consoleLogDrain, cookieEvaluator, createLinearDecay, debugConsoleLogDrain, emptyVisitorData, evaluateVariantMatch, eventEvaluator, isStringMatch, pageViewCountDimension, pageViewCountEvaluator, pageVisitedEvaluator, personalizeVariations, queryStringEvaluator, quirkEvaluator, testVariations };
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 };