@uniformdev/context 12.2.1-alpha.171 → 12.2.1-alpha.184
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 +17 -2
- package/dist/api/api.js +2 -2
- package/dist/api/api.mjs +1 -1
- package/dist/chunk-GU2YFM6V.mjs +1 -0
- package/dist/cli/cli.js +37 -36
- package/dist/cli/cli.mjs +36 -35
- package/dist/index.d.ts +4 -674
- package/dist/index.esm.js +3 -3
- package/dist/index.js +3 -3
- package/dist/index.mjs +3 -3
- package/dist/types-1ad8439c.d.ts +987 -0
- package/package.json +3 -3
- package/dist/v2-manifest.swagger-d0899723.d.ts +0 -285
package/dist/index.d.ts
CHANGED
@@ -1,186 +1,6 @@
|
|
1
|
-
import { c as
|
2
|
-
|
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
|
-
/**
|
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
|
-
};
|
121
|
-
declare const SERVER_STATE_ID = "__UNIFORM_DATA__";
|
122
|
-
declare type TransitionDataStoreEvents = {
|
123
|
-
/**
|
124
|
-
* Fired when the data is updated asynchronously
|
125
|
-
* (i.e. a promise resolves with new data from a backend)
|
126
|
-
*
|
127
|
-
* NOT fired for synchronous updates (e.g. calling updateData()), unless this also results in an async update of the data afterwards.
|
128
|
-
* NOT fired if an asynchronous update does not result in any change compared to the last known data.
|
129
|
-
*/
|
130
|
-
dataUpdatedAsync: Partial<VisitorData>;
|
131
|
-
};
|
132
|
-
declare abstract class TransitionDataStore {
|
133
|
-
#private;
|
134
|
-
constructor({ initialData }: TransitionDataStoreOptions);
|
135
|
-
get data(): Partial<VisitorData> | undefined;
|
136
|
-
/**
|
137
|
-
* Subscribe to events from the transition storage
|
138
|
-
*/
|
139
|
-
readonly events: {
|
140
|
-
on: {
|
141
|
-
<Key extends "dataUpdatedAsync">(type: Key, handler: mitt.Handler<TransitionDataStoreEvents[Key]>): void;
|
142
|
-
(type: "*", handler: mitt.WildcardHandler<TransitionDataStoreEvents>): void;
|
143
|
-
};
|
144
|
-
off: {
|
145
|
-
<Key_1 extends "dataUpdatedAsync">(type: Key_1, handler?: mitt.Handler<TransitionDataStoreEvents[Key_1]> | undefined): void;
|
146
|
-
(type: "*", handler: mitt.WildcardHandler<TransitionDataStoreEvents>): void;
|
147
|
-
};
|
148
|
-
};
|
149
|
-
/**
|
150
|
-
* Updates data in the transition storage.
|
151
|
-
* @param commands Commands to execute against existing stored value (event based stores)
|
152
|
-
* @param computedValue Pre-computed new value against existing value (object based stores)
|
153
|
-
* @returns Resolved promise when the data has been updated
|
154
|
-
*/
|
155
|
-
updateData(commands: StorageCommands[], computedValue: VisitorData): Promise<void>;
|
156
|
-
/**
|
157
|
-
* Deletes a visitor's stored data, forgetting them.
|
158
|
-
* @param fromAllDevices - false: logout from this device ID. true: forget all data about the visitor and their identity.
|
159
|
-
*/
|
160
|
-
delete(fromAllDevices?: boolean): Promise<void>;
|
161
|
-
/**
|
162
|
-
* Deletes a visitor's stored data, forgetting them.
|
163
|
-
* Important: do not emit any async score update events from this function.
|
164
|
-
* @param fromAllDevices - false: logout from this device ID. true: forget all data about the visitor and their identity.
|
165
|
-
*/
|
166
|
-
abstract handleDelete(fromAllDevices?: boolean): Promise<void>;
|
167
|
-
/**
|
168
|
-
* Updates visitor data in the transition store.
|
169
|
-
*
|
170
|
-
* NOTE: The updated data is optimistically stored in TransitionDataStore automatically,
|
171
|
-
* so unless the updated data is _changed_ by the backend data store, there is no need
|
172
|
-
* to emit async score changed events when the visitor data is done updating.
|
173
|
-
*/
|
174
|
-
abstract handleUpdateData(commands: StorageCommands[], computedValue: VisitorData): Promise<void>;
|
175
|
-
protected signalAsyncDataUpdate(newScores: Partial<VisitorData>): void;
|
176
|
-
/**
|
177
|
-
* When we load on the client side after a server side rendering has occurred (server to client transition),
|
178
|
-
* we can have a page script (ID: __UNIFORM_DATA__) that contains the computed visitor data from the SSR/edge render.
|
179
|
-
* This data is injected into the first render to allow score syncing and the server to request commands be applied
|
180
|
-
* to the client side data store.
|
181
|
-
*/
|
182
|
-
getClientTransitionState(): ServerToClientTransitionState | undefined;
|
183
|
-
}
|
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';
|
184
4
|
|
185
5
|
declare type CookieTransitionDataStoreOptions = {
|
186
6
|
cookieAdapter: CookieAdapter;
|
@@ -230,26 +50,6 @@ declare type LinearDecayOptions = {
|
|
230
50
|
*/
|
231
51
|
declare function createLinearDecay(options?: LinearDecayOptions): DecayFunction;
|
232
52
|
|
233
|
-
declare type CookieAdapter = {
|
234
|
-
get: (name: string) => string | undefined;
|
235
|
-
set: (name: string, value: string) => void;
|
236
|
-
remove: (name: string) => void;
|
237
|
-
};
|
238
|
-
declare type DecayOptions = {
|
239
|
-
now: number;
|
240
|
-
lastUpd: number | undefined;
|
241
|
-
scores: ScoreVector;
|
242
|
-
sessionScores: ScoreVector;
|
243
|
-
};
|
244
|
-
/**
|
245
|
-
* Computes decay of visitor scores over time.
|
246
|
-
* NOTE: it is expected that this function mutates the incoming score vectors,
|
247
|
-
* if it needs to apply score decay. The data store ensures immutability already.
|
248
|
-
*
|
249
|
-
* @returns true if any decay was applied, false otherwise
|
250
|
-
*/
|
251
|
-
declare type DecayFunction = (options: DecayOptions) => boolean;
|
252
|
-
|
253
53
|
/**
|
254
54
|
* Creates a new log drain that will log to the console.
|
255
55
|
* The log drain will only log event IDs, but is much smaller than the
|
@@ -264,59 +64,6 @@ declare function createConsoleLogDrain(level: OutputSeverity): LogDrain;
|
|
264
64
|
*/
|
265
65
|
declare function enableConsoleLogDrain(level: OutputSeverity): ContextPlugin;
|
266
66
|
|
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
67
|
/**
|
321
68
|
* Creates a new log drain that will log full debug messages to the console.
|
322
69
|
* The debug log drain adds significant bundle size, but is useful for debugging.
|
@@ -330,118 +77,6 @@ declare function createDebugConsoleLogDrain(level: OutputSeverity): LogDrain;
|
|
330
77
|
*/
|
331
78
|
declare function enableDebugConsoleLogDrain(level: OutputSeverity): ContextPlugin;
|
332
79
|
|
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
80
|
declare const cookieEvaluator: CriteriaEvaluator;
|
446
81
|
|
447
82
|
declare const pageViewCountDimension: string;
|
@@ -455,19 +90,6 @@ declare const eventEvaluator: CriteriaEvaluator;
|
|
455
90
|
|
456
91
|
declare const pageVisitedEvaluator: CriteriaEvaluator;
|
457
92
|
|
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
93
|
/** Tests if a StringMatch matches a string value */
|
472
94
|
declare function isStringMatch(lhs: string | null | undefined, match: StringMatch): boolean;
|
473
95
|
|
@@ -476,236 +98,8 @@ declare function computeAggregateDimensions(primitiveScores: ScoreVector, aggreg
|
|
476
98
|
|
477
99
|
declare function getEnrichmentVectorKey(category: string, value: string): string;
|
478
100
|
|
479
|
-
/** Content that is tagged for adding enrichment score when triggered by behavior (i.e. being shown that content) */
|
480
|
-
declare type BehaviorTag = {
|
481
|
-
beh?: EnrichmentData[];
|
482
|
-
};
|
483
|
-
/** Defines the shape of a personalized content variant */
|
484
|
-
declare type PersonalizedVariant = {
|
485
|
-
/** A unique identifier for this variation */
|
486
|
-
id: string;
|
487
|
-
/** Match criteria for this variation */
|
488
|
-
pz?: VariantMatchCriteria;
|
489
|
-
};
|
490
|
-
/** The result of computing personalized content from variations */
|
491
|
-
declare type PersonalizedResult<TVariant> = {
|
492
|
-
/** Whether or not this result contains a personalized result */
|
493
|
-
personalized: boolean;
|
494
|
-
/** Matching variations */
|
495
|
-
variations: Array<TVariant>;
|
496
|
-
};
|
497
|
-
/** Defines the shape of a A/B test variant */
|
498
|
-
declare type TestVariant = {
|
499
|
-
/** The identifier for this variant. This value persisted to storage when a variant is selected. */
|
500
|
-
id: string;
|
501
|
-
/**
|
502
|
-
* A number between 0 and 100 representing what percentage of visitors will be selected for this variant.
|
503
|
-
* If not provided, this variant will be selected in equal proportion to other variants without an explicit distribution.
|
504
|
-
*/
|
505
|
-
testDistribution?: number;
|
506
|
-
};
|
507
|
-
/** The result of computing an A/B test result */
|
508
|
-
declare type TestResult<TVariant> = {
|
509
|
-
/** The selected variation */
|
510
|
-
result: TVariant | undefined;
|
511
|
-
};
|
512
|
-
/** Defines the shape of arbitrarily tagged content where the tag can be for a test, behaviour, or personalization */
|
513
|
-
declare type TaggedContent = PersonalizedVariant & TestVariant & BehaviorTag & {
|
514
|
-
/** @deprecated no longer used */
|
515
|
-
intents?: IntentTagVector;
|
516
|
-
};
|
517
|
-
/**
|
518
|
-
* A vector keyed by intent ID which contains magnitude and configuration data for each intent ID that has been tagged
|
519
|
-
* @deprecated no longer used
|
520
|
-
*/
|
521
|
-
declare type IntentTagVector = Record<string, IntentTagAxis>;
|
522
|
-
/**
|
523
|
-
* An individual intent tag magnitude value in an IntentTagVector
|
524
|
-
* @deprecated no longer used
|
525
|
-
*/
|
526
|
-
interface IntentTagAxis {
|
527
|
-
/** If this is true, don't use this intent tag when calculating personalization. If false or unspecified, personalization is allowed. */
|
528
|
-
noPn?: boolean;
|
529
|
-
/** If this is true, don't use this intent tag when calculating behavior. If false or unspecified, behavior is allowed. */
|
530
|
-
noBeh?: boolean;
|
531
|
-
/**
|
532
|
-
* If this is true, ANY strength in the tagged intent will result in selecting this variant to personalize,
|
533
|
-
* regardless of other intents' strengths. If more than one tag is override,
|
534
|
-
* they are sorted normally.
|
535
|
-
*/
|
536
|
-
override?: boolean;
|
537
|
-
/**
|
538
|
-
* Sets the minimum visitor score required to trigger this variation.
|
539
|
-
* If more than one intent tag matches, the one with the highest threshold will win.
|
540
|
-
*/
|
541
|
-
threshold?: number;
|
542
|
-
/** Strength of the intent tag. If unspecified, IntentTagStrength.Normal should be inferred */
|
543
|
-
str?: number | string;
|
544
|
-
}
|
545
|
-
|
546
|
-
declare type PersonalizeOptions<TVariant> = {
|
547
|
-
/** Name of placement */
|
548
|
-
name?: string;
|
549
|
-
/** Possible variants to place */
|
550
|
-
variations: Iterable<TVariant>;
|
551
|
-
/** Maximum number of variants to place (default: 1) */
|
552
|
-
take?: number;
|
553
|
-
};
|
554
|
-
declare function personalizeVariations<TVariant extends PersonalizedVariant>({ context, variations, take, }: PersonalizeOptions<TVariant> & {
|
555
|
-
context: Context;
|
556
|
-
}): PersonalizedResult<TVariant>;
|
557
|
-
|
558
101
|
declare function evaluateVariantMatch(match: VariantMatchCriteria | undefined | null, vec: ScoreVector): boolean;
|
559
102
|
|
560
|
-
declare type VariantMatchCriteria = {
|
561
|
-
/**
|
562
|
-
* Operation for match criteria
|
563
|
-
*
|
564
|
-
* @defaultValue `&`
|
565
|
-
*/
|
566
|
-
op?: '&' | '|';
|
567
|
-
crit: DimensionMatch[];
|
568
|
-
};
|
569
|
-
declare type DimensionMatch = {
|
570
|
-
/**
|
571
|
-
* Left hand side of the match expression (name of dimension in score vector)
|
572
|
-
* NOTE: if the dimension is not present in the score vector, it will be treated as if it has a value of 0
|
573
|
-
*/
|
574
|
-
l: string;
|
575
|
-
/**
|
576
|
-
* Operator of the match expression
|
577
|
-
* Whole-vector (RHS only) operators - these do not require a `r` or `rDim` set:
|
578
|
-
* +: `l` is the strongest dimension in the score vector
|
579
|
-
* -: `l` is the weakest dimension in the score vector. This does not match if the dimension has no score at all.
|
580
|
-
*
|
581
|
-
* Comparison operators:
|
582
|
-
* >: `l` is greater than the right hand side expression
|
583
|
-
* >= : `l` is greater than or equal to the right hand side expression
|
584
|
-
* <: `l` is less than the right hand side expression
|
585
|
-
* <= : `l` is less than or equal to the right hand side expression
|
586
|
-
* =: `l` is equal to the right hand side expression
|
587
|
-
* !=: `l` is not equal to the right hand side expression
|
588
|
-
*/
|
589
|
-
op: '+' | '-' | '>' | '>=' | '<' | '<=' | '=' | '!=';
|
590
|
-
/**
|
591
|
-
* Right hand side of the match expression (not required for op = + or - which have no right side)
|
592
|
-
* This value is treated as a constant value, if it is present. If it's a string, it is parsed to an integer.
|
593
|
-
* To reference another score dimension as the RHS, use the `rDim` property instead.
|
594
|
-
* `r` and `rDim` are mutually exclusive; if both are specified, then `rDim` wins.
|
595
|
-
*/
|
596
|
-
r?: number | string;
|
597
|
-
/**
|
598
|
-
* Right hand side of the match expression (not required for op = + or - which have no right side)
|
599
|
-
* This value is treated as a reference to another score dimension, if it is present in the score vector.
|
600
|
-
* If the referenced dimension is NOT present in the score vector, the match will always be false.
|
601
|
-
* To reference a constant value instead as the RHS, use the `r` property instead.
|
602
|
-
* `r` and `rDim` are mutually exclusive; if both are specified, then `rDim` wins.
|
603
|
-
*/
|
604
|
-
rDim?: string;
|
605
|
-
};
|
606
|
-
|
607
|
-
declare type TestOptions<TVariant extends TestVariant> = {
|
608
|
-
/** The name of the test that is being run, must be included in the manifest. */
|
609
|
-
name: string;
|
610
|
-
/** Variations that are being tested. */
|
611
|
-
variations: TVariant[];
|
612
|
-
};
|
613
|
-
declare const testVariations: <TVariant extends TestVariant>({ name, context, variations, }: TestOptions<TVariant> & {
|
614
|
-
context: Context;
|
615
|
-
}) => TestResult<TVariant>;
|
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
|
-
};
|
626
|
-
declare type ContextOptions = {
|
627
|
-
/** The Context Manifest to load (from the Context API) */
|
628
|
-
manifest: ManifestV2;
|
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'>;
|
638
|
-
declare type PersonalizationEvent = {
|
639
|
-
name: string;
|
640
|
-
variantIds: string[];
|
641
|
-
control: boolean | undefined;
|
642
|
-
};
|
643
|
-
declare type TestEvent = {
|
644
|
-
name: string;
|
645
|
-
variantId: string | undefined;
|
646
|
-
control: boolean | undefined;
|
647
|
-
};
|
648
|
-
declare type ContextEvents = {
|
649
|
-
/**
|
650
|
-
* Fired when the scores are updated.
|
651
|
-
* The event is NOT fired if an update does not result in any score changes.
|
652
|
-
* The result is merged between session and permanent data.
|
653
|
-
*/
|
654
|
-
scoresUpdated: Readonly<ScoreVector>;
|
655
|
-
/**
|
656
|
-
* Fired when quirk data changes. Not fired if no changes to quirks are made
|
657
|
-
* (e.g. setting it to the same value it already has)
|
658
|
-
*/
|
659
|
-
quirksUpdated: Quirks;
|
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
|
-
*/
|
665
|
-
log: LogMessage;
|
666
|
-
/** Test variant has been selected */
|
667
|
-
testResult: TestEvent;
|
668
|
-
/** Personalization variants have been selected */
|
669
|
-
personalizationResult: PersonalizationEvent;
|
670
|
-
};
|
671
|
-
declare class Context implements Context {
|
672
|
-
#private;
|
673
|
-
readonly manifest: ManifestInstance;
|
674
|
-
constructor(options: ContextOptions);
|
675
|
-
get scores(): Readonly<ScoreVector>;
|
676
|
-
/**
|
677
|
-
* Subscribe to events
|
678
|
-
*/
|
679
|
-
readonly events: {
|
680
|
-
on: {
|
681
|
-
<Key extends keyof ContextEvents>(type: Key, handler: mitt.Handler<ContextEvents[Key]>): void;
|
682
|
-
(type: "*", handler: mitt.WildcardHandler<ContextEvents>): void;
|
683
|
-
};
|
684
|
-
off: {
|
685
|
-
<Key_1 extends keyof ContextEvents>(type: Key_1, handler?: mitt.Handler<ContextEvents[Key_1]> | undefined): void;
|
686
|
-
(type: "*", handler: mitt.WildcardHandler<ContextEvents>): void;
|
687
|
-
};
|
688
|
-
};
|
689
|
-
readonly storage: VisitorDataStore;
|
690
|
-
update(newData: Partial<ContextState>): Promise<void>;
|
691
|
-
getTestVariantId(testName: string): string | null | undefined;
|
692
|
-
setTestVariantId(testName: string, variantId: string): void;
|
693
|
-
/**
|
694
|
-
* Writes a message to the Context log sink.
|
695
|
-
* Used by Uniform internal SDK; not intended for public use.
|
696
|
-
*/
|
697
|
-
log(...message: LogMessage): void;
|
698
|
-
/** 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) */
|
699
|
-
test<TVariant extends TestVariant>(options: TestOptions<TVariant>): TestResult<TVariant>;
|
700
|
-
/** Executes a personalized placement with a given set of variants */
|
701
|
-
personalize<TVariant extends PersonalizedVariant>(options: PersonalizeOptions<TVariant>): PersonalizedResult<TVariant>;
|
702
|
-
/**
|
703
|
-
* Forgets the visitor's data and resets the Context to its initial state.
|
704
|
-
* @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
|
705
|
-
*/
|
706
|
-
forget(fromAllDevices: boolean): Promise<void>;
|
707
|
-
}
|
708
|
-
|
709
103
|
declare enum ScriptType {
|
710
104
|
ListStart = "nesi-list-start",
|
711
105
|
ListEnd = "nesi-list-end",
|
@@ -723,70 +117,6 @@ declare type EdgeTestComponentOptions = {
|
|
723
117
|
};
|
724
118
|
declare const EdgeNodeTagName = "nesitag";
|
725
119
|
|
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
120
|
/**
|
791
121
|
* Enables a Context instance to feed data to the Uniform Context DevTools.
|
792
122
|
* DevTools can be hosted either as a Chromium extension, or as a standalone
|
@@ -795,4 +125,4 @@ declare global {
|
|
795
125
|
*/
|
796
126
|
declare function enableContextDevTools(): ContextPlugin;
|
797
127
|
|
798
|
-
export {
|
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 };
|