@uniformdev/context 12.2.1-alpha.142 → 12.2.1-alpha.177

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
@@ -1,179 +1,6 @@
1
- import { c as components, e as external } from './v2-manifest.swagger-d0899723';
2
- import * as mitt from 'mitt';
3
-
4
- declare type StorageCommand<TID extends string = string, TData = unknown> = {
5
- type: TID;
6
- data: TData;
7
- };
8
- /** Commands that can be issued to alter the storage of Uniform Context data */
9
- declare type StorageCommands = ModifyScoreCommand | ModifySessionScoreCommand | SetConsentCommand | SetQuirkCommand | SetTestCommand | IdentifyCommand;
10
- /**
11
- * Changes the visitor's permanent score for a given dimension
12
- */
13
- declare type ModifyScoreCommand = StorageCommand<'modscore', {
14
- dimension: string;
15
- delta: number;
16
- }>;
17
- /**
18
- * Changes the visitor's session (time-based) score for a given dimension
19
- */
20
- declare type ModifySessionScoreCommand = StorageCommand<'modscoreS', {
21
- dimension: string;
22
- delta: number;
23
- }>;
24
- /**
25
- * Changes the visitor's storage consent setting.
26
- * Setting consent to false will trigger deletion of any stored data for the visitor.
27
- * Scores are still collected in-memory when consent is false; just not persisted.
28
- */
29
- declare type SetConsentCommand = StorageCommand<'consent', boolean>;
30
- /** Sets a permanent quirk key and value for the visitor */
31
- declare type SetQuirkCommand = StorageCommand<'setquirk', {
32
- key: string;
33
- value: string;
34
- }>;
35
- /** Sets a specific variant as being this visitor's variant on an A/B test */
36
- declare type SetTestCommand = StorageCommand<'settest', {
37
- test: string;
38
- variant: string;
39
- }>;
40
- /**
41
- * Identifies the visitor as being a specific unique identifier.
42
- * NOTE: this only has an effect when using an external cross-device transition storage system.
43
- * NOTE: you cannot read the identified visitor ID back from the storage system once it is set.
44
- */
45
- declare type IdentifyCommand = StorageCommand<'identify', {
46
- identity: string;
47
- }>;
48
-
49
- declare type Quirks = {
50
- [key: string]: string;
51
- };
52
- declare type Tests = {
53
- [key: string]: string;
54
- };
55
- declare type ScoreVector = {
56
- [key: string]: number;
57
- };
58
- declare type EnrichmentData = {
59
- /** Enrichment category name */
60
- cat: string;
61
- /** Enrichment key value */
62
- key: string;
63
- /** Strength value (amount of score added when viewing content) */
64
- str: number;
65
- };
66
- declare type EventData = {
67
- event: string;
68
- payload?: any;
69
- };
70
- declare type VisitorData = {
71
- /** Quirk key-value data */
72
- quirks: Quirks;
73
- /** A/B test variant selections */
74
- tests: Tests;
75
- /** Personalization score data for the current session (merge with all time for totals) */
76
- sessionScores: ScoreVector;
77
- /** Personalization score data for all time (merge with session for totals) */
78
- scores: ScoreVector;
79
- /**
80
- * Whether consent has been given to store the visitor data
81
- * If false or not set: visitor data is stored in memory and is lost if the browser refreshes
82
- * If true: visitor data is stored in localStorage and any other transition storage if registered
83
- */
84
- consent?: boolean;
85
- /**
86
- * Whether the visitor has been assigned to the personalization control group -
87
- * visitors who are not shown personalization. If this is true, all scores will be zeroed,
88
- * and score updates will be ignored. This has no effect on quirks or tests.
89
- *
90
- * If this value is not set, a random roll will be performed to determine membership,
91
- * based on the control group size.
92
- */
93
- controlGroup?: boolean;
94
- };
95
- declare const emptyVisitorData: () => VisitorData;
96
- declare type ContextState = {
97
- cookies: Record<string, string>;
98
- url: URL;
99
- quirks: Quirks;
100
- enrichments: EnrichmentData[];
101
- events: EventData[];
102
- };
103
- declare type ContextStateUpdate = {
104
- state: Partial<ContextState>;
105
- previousState: Partial<ContextState>;
106
- visitor: VisitorData;
107
- scores: ScoreVector;
108
- };
109
-
110
- declare type TransitionDataStoreOptions = {
111
- initialData?: Partial<VisitorData>;
112
- };
113
- declare type ServerToClientTransitionState = Pick<Partial<VisitorData>, 'quirks' | 'tests'>;
114
- declare const SERVER_STATE_ID = "__UNIFORM_DATA__";
115
- declare type TransitionDataStoreEvents = {
116
- /**
117
- * Fired when the data is updated asynchronously
118
- * (i.e. a promise resolves with new data from a backend)
119
- *
120
- * NOT fired for synchronous updates (e.g. calling updateData()), unless this also results in an async update of the data afterwards.
121
- * NOT fired if an asynchronous update does not result in any change compared to the last known data.
122
- */
123
- dataUpdatedAsync: Partial<VisitorData>;
124
- };
125
- declare abstract class TransitionDataStore {
126
- #private;
127
- constructor({ initialData }: TransitionDataStoreOptions);
128
- get data(): Partial<VisitorData> | undefined;
129
- /**
130
- * Subscribe to events from the transition storage
131
- */
132
- readonly events: {
133
- on: {
134
- <Key extends "dataUpdatedAsync">(type: Key, handler: mitt.Handler<TransitionDataStoreEvents[Key]>): void;
135
- (type: "*", handler: mitt.WildcardHandler<TransitionDataStoreEvents>): void;
136
- };
137
- off: {
138
- <Key_1 extends "dataUpdatedAsync">(type: Key_1, handler?: mitt.Handler<TransitionDataStoreEvents[Key_1]> | undefined): void;
139
- (type: "*", handler: mitt.WildcardHandler<TransitionDataStoreEvents>): void;
140
- };
141
- };
142
- /**
143
- * Updates data in the transition storage.
144
- * @param commands Commands to execute against existing stored value (event based stores)
145
- * @param computedValue Pre-computed new value against existing value (object based stores)
146
- * @returns Resolved promise when the data has been updated
147
- */
148
- updateData(commands: StorageCommands[], computedValue: VisitorData): Promise<void>;
149
- /**
150
- * Deletes a visitor's stored data, forgetting them.
151
- * @param fromAllDevices - false: logout from this device ID. true: forget all data about the visitor and their identity.
152
- */
153
- delete(fromAllDevices?: boolean): Promise<void>;
154
- /**
155
- * Deletes a visitor's stored data, forgetting them.
156
- * Important: do not emit any async score update events from this function.
157
- * @param fromAllDevices - false: logout from this device ID. true: forget all data about the visitor and their identity.
158
- */
159
- abstract handleDelete(fromAllDevices?: boolean): Promise<void>;
160
- /**
161
- * Updates visitor data in the transition store.
162
- *
163
- * NOTE: The updated data is optimistically stored in TransitionDataStore automatically,
164
- * so unless the updated data is _changed_ by the backend data store, there is no need
165
- * to emit async score changed events when the visitor data is done updating.
166
- */
167
- abstract handleUpdateData(commands: StorageCommands[], computedValue: VisitorData): Promise<void>;
168
- protected signalAsyncDataUpdate(newScores: Partial<VisitorData>): void;
169
- /**
170
- * When we load on the client side after a server side rendering has occurred (server to client transition),
171
- * we can have a page script (ID: __UNIFORM_DATA__) that contains the computed visitor data from the SSR/edge render.
172
- * This data is injected into the first render to allow score syncing and the server to request commands be applied
173
- * to the client side data store.
174
- */
175
- getClientTransitionState(): ServerToClientTransitionState | undefined;
176
- }
1
+ import { C as CookieAdapter, T as TransitionDataStore, S as StorageCommands, V as VisitorData, a as TransitionDataStoreOptions, D as DecayFunction, O as OutputSeverity, L as LogDrain, b as ContextPlugin, c as CriteriaEvaluator, d as StringMatch, e as ScoreVector, A as AggregateDimension, f as VariantMatchCriteria } from './types-1ad8439c';
2
+ export { A as AggregateDimension, l as AggregateDimensionInput, a7 as BehaviorTag, Z as Context, Y as ContextEvents, U as ContextOptions, b as ContextPlugin, q as ContextState, r as ContextStateUpdate, C as CookieAdapter, c as CriteriaEvaluator, D as DecayFunction, z as DecayOptions, af as DevToolsActions, aj as DevToolsDataEvent, ag as DevToolsEvent, ah as DevToolsEvents, an as DevToolsForgetEvent, ak as DevToolsHelloEvent, ai as DevToolsLogEvent, am as DevToolsRawCommandsEvent, ae as DevToolsState, ad as DevToolsUiVersion, al as DevToolsUpdateEvent, a6 as DimensionMatch, E as EnrichmentCategory, n as EnrichmentData, o as EventData, G as GroupCriteriaEvaluator, I as IdentifyCommand, L as LogDrain, a1 as LogMessage, _ as LogMessages, M as ManifestInstance, g as ManifestV2, a0 as MessageFunc, t as ModifyScoreCommand, u as ModifySessionScoreCommand, N as NumberMatch, O as OutputSeverity, W as PersonalizationEvent, P as PersonalizationManifest, a4 as PersonalizeOptions, a9 as PersonalizedResult, a8 as PersonalizedVariant, Q as Quirks, K as SERVER_STATE_ID, e as ScoreVector, J as ServerToClientTransitionState, v as SetConsentCommand, y as SetControlGroupCommand, w as SetQuirkCommand, x as SetTestCommand, $ as Severity, h as Signal, j as SignalCriteria, i as SignalCriteriaGroup, s as StorageCommand, S as StorageCommands, d as StringMatch, ac as TaggedContent, k as TestDefinition, X as TestEvent, a3 as TestOptions, ab as TestResult, aa as TestVariant, m as Tests, T as TransitionDataStore, R as TransitionDataStoreEvents, a as TransitionDataStoreOptions, f as VariantMatchCriteria, V as VisitorData, H as VisitorDataStore, F as VisitorDataStoreEvents, B as VisitorDataStoreOptions, p as emptyVisitorData, a5 as personalizeVariations, a2 as testVariations } from './types-1ad8439c';
3
+ import 'mitt';
177
4
 
178
5
  declare type CookieTransitionDataStoreOptions = {
179
6
  cookieAdapter: CookieAdapter;
@@ -223,377 +50,32 @@ declare type LinearDecayOptions = {
223
50
  */
224
51
  declare function createLinearDecay(options?: LinearDecayOptions): DecayFunction;
225
52
 
226
- declare type CookieAdapter = {
227
- get: (name: string) => string | undefined;
228
- set: (name: string, value: string) => void;
229
- remove: (name: string) => void;
230
- };
231
- declare type DecayOptions = {
232
- now: number;
233
- lastUpd: number | undefined;
234
- scores: ScoreVector;
235
- sessionScores: ScoreVector;
236
- };
237
53
  /**
238
- * Computes decay of visitor scores over time.
239
- * NOTE: it is expected that this function mutates the incoming score vectors,
240
- * if it needs to apply score decay. The data store ensures immutability already.
54
+ * Creates a new log drain that will log to the console.
55
+ * The log drain will only log event IDs, but is much smaller than the
56
+ * debug log drain.
241
57
  *
242
- * @returns true if any decay was applied, false otherwise
58
+ * NOTE: you probably want enableConsoleLogDrain() instead of this function.
59
+ */
60
+ declare function createConsoleLogDrain(level: OutputSeverity): LogDrain;
61
+ /**
62
+ * Enables logging Context events to the browser console.
63
+ * Lightweight events with only the event ID are emitted.
243
64
  */
244
- declare type DecayFunction = (options: DecayOptions) => boolean;
65
+ declare function enableConsoleLogDrain(level: OutputSeverity): ContextPlugin;
245
66
 
246
- /** Content that is tagged for adding enrichment score when triggered by behavior (i.e. being shown that content) */
247
- declare type BehaviorTag = {
248
- beh?: EnrichmentData[];
249
- };
250
- /** Defines the shape of a personalized content variant */
251
- declare type PersonalizedVariant = {
252
- /** A unique identifier for this variation */
253
- id: string;
254
- /** Match criteria for this variation */
255
- pz?: VariantMatchCriteria;
256
- };
257
- /** The result of computing personalized content from variations */
258
- declare type PersonalizedResult<TVariant> = {
259
- /** Whether or not this result contains a personalized result */
260
- personalized: boolean;
261
- /** Matching variations */
262
- variations: Array<TVariant>;
263
- };
264
- /** Defines the shape of a A/B test variant */
265
- declare type TestVariant = {
266
- /** The identifier for this variant. This value persisted to storage when a variant is selected. */
267
- id: string;
268
- /**
269
- * A number between 0 and 100 representing what percentage of visitors will be selected for this variant.
270
- * If not provided, this variant will be selected in equal proportion to other variants without an explicit distribution.
271
- */
272
- testDistribution?: number;
273
- };
274
- /** The result of computing an A/B test result */
275
- declare type TestResult<TVariant> = {
276
- /** The selected variation */
277
- result: TVariant | undefined;
278
- };
279
- /** Defines the shape of arbitrarily tagged content where the tag can be for a test, behaviour, or personalization */
280
- declare type TaggedContent = PersonalizedVariant & TestVariant & BehaviorTag & {
281
- /** @deprecated no longer used */
282
- intents?: IntentTagVector;
283
- };
284
67
  /**
285
- * A vector keyed by intent ID which contains magnitude and configuration data for each intent ID that has been tagged
286
- * @deprecated no longer used
68
+ * Creates a new log drain that will log full debug messages to the console.
69
+ * The debug log drain adds significant bundle size, but is useful for debugging.
70
+ *
71
+ * NOTE: you probably want enableDebugConsoleLogDrain() instead of this function.
287
72
  */
288
- declare type IntentTagVector = Record<string, IntentTagAxis>;
73
+ declare function createDebugConsoleLogDrain(level: OutputSeverity): LogDrain;
289
74
  /**
290
- * An individual intent tag magnitude value in an IntentTagVector
291
- * @deprecated no longer used
75
+ * Enables logging Context events to the browser console.
76
+ * Lightweight events with only the event ID are emitted.
292
77
  */
293
- interface IntentTagAxis {
294
- /** If this is true, don't use this intent tag when calculating personalization. If false or unspecified, personalization is allowed. */
295
- noPn?: boolean;
296
- /** If this is true, don't use this intent tag when calculating behavior. If false or unspecified, behavior is allowed. */
297
- noBeh?: boolean;
298
- /**
299
- * If this is true, ANY strength in the tagged intent will result in selecting this variant to personalize,
300
- * regardless of other intents' strengths. If more than one tag is override,
301
- * they are sorted normally.
302
- */
303
- override?: boolean;
304
- /**
305
- * Sets the minimum visitor score required to trigger this variation.
306
- * If more than one intent tag matches, the one with the highest threshold will win.
307
- */
308
- threshold?: number;
309
- /** Strength of the intent tag. If unspecified, IntentTagStrength.Normal should be inferred */
310
- str?: number | string;
311
- }
312
-
313
- declare type PersonalizeOptions<TVariant> = {
314
- /** Name of placement */
315
- name?: string;
316
- /** Possible variants to place */
317
- variations: Iterable<TVariant>;
318
- /** Maximum number of variants to place (default: 1) */
319
- take?: number;
320
- };
321
- declare function personalizeVariations<TVariant extends PersonalizedVariant>({ context, variations, take, }: PersonalizeOptions<TVariant> & {
322
- context: Context;
323
- }): PersonalizedResult<TVariant>;
324
-
325
- declare function evaluateVariantMatch(match: VariantMatchCriteria | undefined | null, vec: ScoreVector): boolean;
326
-
327
- declare type VariantMatchCriteria = {
328
- /**
329
- * Operation for match criteria
330
- *
331
- * @defaultValue `&`
332
- */
333
- op?: '&' | '|';
334
- crit: DimensionMatch[];
335
- };
336
- declare type DimensionMatch = {
337
- /**
338
- * Left hand side of the match expression (name of dimension in score vector)
339
- * NOTE: if the dimension is not present in the score vector, it will be treated as if it has a value of 0
340
- */
341
- l: string;
342
- /**
343
- * Operator of the match expression
344
- * Whole-vector (RHS only) operators - these do not require a `r` or `rDim` set:
345
- * +: `l` is the strongest dimension in the score vector
346
- * -: `l` is the weakest dimension in the score vector. This does not match if the dimension has no score at all.
347
- *
348
- * Comparison operators:
349
- * >: `l` is greater than the right hand side expression
350
- * >= : `l` is greater than or equal to the right hand side expression
351
- * <: `l` is less than the right hand side expression
352
- * <= : `l` is less than or equal to the right hand side expression
353
- * =: `l` is equal to the right hand side expression
354
- * !=: `l` is not equal to the right hand side expression
355
- */
356
- op: '+' | '-' | '>' | '>=' | '<' | '<=' | '=' | '!=';
357
- /**
358
- * Right hand side of the match expression (not required for op = + or - which have no right side)
359
- * This value is treated as a constant value, if it is present. If it's a string, it is parsed to an integer.
360
- * To reference another score dimension as the RHS, use the `rDim` property instead.
361
- * `r` and `rDim` are mutually exclusive; if both are specified, then `rDim` wins.
362
- */
363
- r?: number | string;
364
- /**
365
- * Right hand side of the match expression (not required for op = + or - which have no right side)
366
- * This value is treated as a reference to another score dimension, if it is present in the score vector.
367
- * If the referenced dimension is NOT present in the score vector, the match will always be false.
368
- * To reference a constant value instead as the RHS, use the `r` property instead.
369
- * `r` and `rDim` are mutually exclusive; if both are specified, then `rDim` wins.
370
- */
371
- rDim?: string;
372
- };
373
-
374
- declare type TestOptions<TVariant extends TestVariant> = {
375
- /** The name of the test that is being run, must be included in the manifest. */
376
- name: string;
377
- /** Variations that are being tested. */
378
- variations: TVariant[];
379
- };
380
- declare const testVariations: <TVariant extends TestVariant>({ name, context, variations, }: TestOptions<TVariant> & {
381
- context: Context;
382
- }) => TestResult<TVariant>;
383
-
384
- declare type ContextOptions = {
385
- manifest: ManifestV2;
386
- } & Omit<VisitorDataStoreOptions, 'manifest'>;
387
- declare type PersonalizationEvent = {
388
- name: string;
389
- variantIds: string[];
390
- control: boolean | undefined;
391
- };
392
- declare type TestEvent = {
393
- name: string;
394
- variantId: string | undefined;
395
- control: boolean | undefined;
396
- };
397
- declare type ContextEvents = {
398
- /**
399
- * Fired when the scores are updated.
400
- * The event is NOT fired if an update does not result in any score changes.
401
- * The result is merged between session and permanent data.
402
- */
403
- scoresUpdated: Readonly<ScoreVector>;
404
- /**
405
- * Fired when quirk data changes. Not fired if no changes to quirks are made
406
- * (e.g. setting it to the same value it already has)
407
- */
408
- quirksUpdated: Quirks;
409
- /** Fired when a log message is emitted from Context */
410
- log: LogMessage;
411
- /** Test variant has been selected */
412
- testResult: TestEvent;
413
- /** Personalization variants have been selected */
414
- personalizationResult: PersonalizationEvent;
415
- };
416
- declare class Context implements Context {
417
- #private;
418
- constructor(options: ContextOptions);
419
- get scores(): Readonly<ScoreVector>;
420
- /**
421
- * Subscribe to events
422
- */
423
- readonly events: {
424
- on: {
425
- <Key extends keyof ContextEvents>(type: Key, handler: mitt.Handler<ContextEvents[Key]>): void;
426
- (type: "*", handler: mitt.WildcardHandler<ContextEvents>): void;
427
- };
428
- off: {
429
- <Key_1 extends keyof ContextEvents>(type: Key_1, handler?: mitt.Handler<ContextEvents[Key_1]> | undefined): void;
430
- (type: "*", handler: mitt.WildcardHandler<ContextEvents>): void;
431
- };
432
- };
433
- readonly storage: VisitorDataStore;
434
- update(newData: Partial<ContextState>): Promise<void>;
435
- getTestVariantId(testName: string): string | null | undefined;
436
- setTestVariantId(testName: string, variantId: string): void;
437
- /**
438
- * Writes a message to the Context log sink.
439
- * Used by Uniform internal SDK; not intended for public use.
440
- */
441
- log(...message: LogMessage): void;
442
- /** Executes an A/B test with a given set of variants, showing the visitor's assigned variant (or selecting one to assign, if none is set yet) */
443
- test<TVariant extends TestVariant>(options: TestOptions<TVariant>): TestResult<TVariant>;
444
- /** Executes a personalized placement with a given set of variants */
445
- personalize<TVariant extends PersonalizedVariant>(options: PersonalizeOptions<TVariant>): PersonalizedResult<TVariant>;
446
- /**
447
- * Forgets the visitor's data and resets the Context to its initial state.
448
- * @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
449
- */
450
- forget(fromAllDevices: boolean): Promise<void>;
451
- }
452
-
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'];
78
+ declare function enableDebugConsoleLogDrain(level: OutputSeverity): ContextPlugin;
597
79
 
598
80
  declare const cookieEvaluator: CriteriaEvaluator;
599
81
 
@@ -608,25 +90,16 @@ declare const eventEvaluator: CriteriaEvaluator;
608
90
 
609
91
  declare const pageVisitedEvaluator: CriteriaEvaluator;
610
92
 
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
93
  /** Tests if a StringMatch matches a string value */
625
94
  declare function isStringMatch(lhs: string | null | undefined, match: StringMatch): boolean;
626
95
 
627
96
  /** Computes aggregated scores based on other dimensions */
628
97
  declare function computeAggregateDimensions(primitiveScores: ScoreVector, aggregates: Record<string, AggregateDimension>): ScoreVector;
629
98
 
99
+ declare function getEnrichmentVectorKey(category: string, value: string): string;
100
+
101
+ declare function evaluateVariantMatch(match: VariantMatchCriteria | undefined | null, vec: ScoreVector): boolean;
102
+
630
103
  declare enum ScriptType {
631
104
  ListStart = "nesi-list-start",
632
105
  ListEnd = "nesi-list-end",
@@ -644,4 +117,12 @@ declare type EdgeTestComponentOptions = {
644
117
  };
645
118
  declare const EdgeNodeTagName = "nesitag";
646
119
 
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 };
120
+ /**
121
+ * Enables a Context instance to feed data to the Uniform Context DevTools.
122
+ * DevTools can be hosted either as a Chromium extension, or as a standalone
123
+ * React app within a page and receive data once this plugin has been activated.
124
+ * @returns Function that when invoked detaches the event listeners and disables DevTools.
125
+ */
126
+ declare function enableContextDevTools(): ContextPlugin;
127
+
128
+ export { CookieTransitionDataStore, CookieTransitionDataStoreOptions, EdgeNodeTagName, EdgePersonalizeComponentOptions, EdgeTestComponentOptions, EdgeTransitionDataStore, EdgeTransitionDataStoreOptions, LinearDecayOptions, ScriptType, computeAggregateDimensions, cookieEvaluator, createConsoleLogDrain, createDebugConsoleLogDrain, createLinearDecay, enableConsoleLogDrain, enableContextDevTools, enableDebugConsoleLogDrain, evaluateVariantMatch, eventEvaluator, getEnrichmentVectorKey, isStringMatch, pageViewCountDimension, pageViewCountEvaluator, pageVisitedEvaluator, queryStringEvaluator, quirkEvaluator };