@uniformdev/context 14.2.1-alpha.145 → 14.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/api/api.d.ts +4 -4
- package/dist/cli/cli.d.ts +2 -2
- package/dist/{contextTypes-7f24fc7c.d.ts → contextTypes-572b0d33.d.ts} +1 -1
- package/dist/index.d.ts +23 -18
- package/dist/index.esm.js +3 -3
- package/dist/index.js +3 -3
- package/dist/index.mjs +3 -3
- package/dist/{types-c81df08a.d.ts → types-5f88cc63.d.ts} +138 -93
- package/dist/{types-d77228a6.d.ts → types-ef0eef65.d.ts} +137 -64
- package/dist/{v2-manifest.swagger-d0899723.d.ts → v2-manifest.swagger-ff2af13e.d.ts} +9 -0
- package/package.json +4 -3
@@ -1,4 +1,4 @@
|
|
1
|
-
import { c as components, e as external } from './v2-manifest.swagger-
|
1
|
+
import { c as components, e as external } from './v2-manifest.swagger-ff2af13e';
|
2
2
|
import * as mitt from 'mitt';
|
3
3
|
|
4
4
|
declare type StorageCommand<TID extends string = string, TData = unknown> = {
|
@@ -192,20 +192,65 @@ declare abstract class TransitionDataStore {
|
|
192
192
|
getClientTransitionState(): ServerToClientTransitionState | undefined;
|
193
193
|
}
|
194
194
|
|
195
|
-
declare type
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
195
|
+
declare type SharedTypes = external['uniform-context-types.swagger.yml']['components']['schemas'];
|
196
|
+
declare type ManifestV2 = components['schemas']['ManifestV2'];
|
197
|
+
declare type PersonalizationManifest = components['schemas']['PersonalizationManifest'];
|
198
|
+
declare type Signal = SharedTypes['Signal'];
|
199
|
+
declare type SignalCriteriaGroup = SharedTypes['SignalCriteriaGroup'];
|
200
|
+
declare type SignalCriteria = SharedTypes['SignalCriteria'];
|
201
|
+
declare type EnrichmentCategory = SharedTypes['EnrichmentCategory'];
|
202
|
+
declare type StringMatch = SharedTypes['StringMatch'];
|
203
|
+
declare type NumberMatch = SharedTypes['NumberMatch'];
|
204
|
+
declare type TestDefinition = SharedTypes['Test'];
|
205
|
+
declare type AggregateDimension = SharedTypes['AggregateDimension'];
|
206
|
+
declare type AggregateDimensionInput = SharedTypes['AggregateDimensionInput'];
|
207
|
+
|
208
|
+
/**
|
209
|
+
* The result of evaluating a signal criteria.
|
210
|
+
*/
|
211
|
+
declare type CriteriaEvaluatorResult = {
|
212
|
+
/** Whether the criteria evaluated to true or not */
|
213
|
+
result: boolean;
|
214
|
+
/**
|
215
|
+
* Whether the value of the criteria changed from the previous state
|
216
|
+
* If ALL criteria on a signal have NOT changed, the signal is skipped
|
217
|
+
* and its score is left alone.
|
218
|
+
*/
|
219
|
+
changed: boolean;
|
220
|
+
};
|
221
|
+
declare type CriteriaEvaluatorParameters = {
|
222
|
+
/** The update being made to the Context state */
|
223
|
+
update: ContextStateUpdate;
|
224
|
+
/** Current criteria to evaluate the update against */
|
225
|
+
criteria: SignalCriteria;
|
226
|
+
/**
|
227
|
+
* The storage commands that will be executed by this update.
|
228
|
+
* If the evaluation requires custom commands, push them into this parameter.
|
229
|
+
* NOTE: needing to use this is very rare and should be avoided if possible.
|
230
|
+
*/
|
231
|
+
commands: StorageCommands[];
|
232
|
+
/** The parent signal containing the criteria we are evaluating */
|
233
|
+
signal: SignalData;
|
234
|
+
/** Function to emit log notices to the Context log */
|
235
|
+
onLogMessage?: (message: LogMessage) => void;
|
236
|
+
};
|
237
|
+
declare type SignalData = Signal & {
|
238
|
+
id: string;
|
200
239
|
};
|
201
240
|
/**
|
202
|
-
*
|
203
|
-
*
|
204
|
-
* if it needs to apply score decay. The data store ensures immutability already.
|
205
|
-
*
|
206
|
-
* @returns true if any decay was applied, false otherwise
|
241
|
+
* A type that evaluates a signal criteria type and
|
242
|
+
* decides if it matches the current Context state or not.
|
207
243
|
*/
|
208
|
-
declare type
|
244
|
+
declare type CriteriaEvaluator = ((parameters: CriteriaEvaluatorParameters) => CriteriaEvaluatorResult) & {
|
245
|
+
/** If true the criteria will always execute even if a short-circuit would normally skip it */
|
246
|
+
alwaysExecute?: boolean;
|
247
|
+
};
|
248
|
+
|
249
|
+
declare class GroupCriteriaEvaluator {
|
250
|
+
#private;
|
251
|
+
constructor(criteriaEvaluators: Record<string, CriteriaEvaluator>);
|
252
|
+
evaluate(update: ContextStateUpdate, crit: SignalCriteriaGroup, commands: StorageCommands[], signal: SignalData, onLogMessage?: (message: LogMessage) => void): CriteriaEvaluatorResult;
|
253
|
+
}
|
209
254
|
|
210
255
|
/** Defines all error codes and their parameter(s) */
|
211
256
|
declare type LogMessages = {
|
@@ -227,6 +272,8 @@ declare type LogMessages = {
|
|
227
272
|
102: MessageFunc<VisitorData>;
|
228
273
|
/** Storage data was deleted bool: fromAllDevices */
|
229
274
|
103: MessageFunc<boolean>;
|
275
|
+
/** Visitor was assigned or removed from control group */
|
276
|
+
104: MessageFunc<boolean>;
|
230
277
|
/** Storage score was truncated to its cap */
|
231
278
|
110: MessageFunc<{
|
232
279
|
dim: string;
|
@@ -239,13 +286,51 @@ declare type LogMessages = {
|
|
239
286
|
130: MessageFunc<ScoreVector>;
|
240
287
|
/** Server to client transition data was discarded */
|
241
288
|
131: MessageFunc;
|
242
|
-
/**
|
289
|
+
/** Decay function executed */
|
290
|
+
140: MessageFunc<string>;
|
291
|
+
/** Signals evaluation beginning */
|
292
|
+
200: MessageFunc;
|
293
|
+
/** Evaluation of a specific signal beginning */
|
294
|
+
201: MessageFunc<SignalData>;
|
295
|
+
/** Evaluation of a group beginning */
|
296
|
+
202: MessageFunc<SignalCriteriaGroup>;
|
297
|
+
203: MessageFunc<{
|
298
|
+
criteria: SignalCriteria;
|
299
|
+
result: CriteriaEvaluatorResult;
|
300
|
+
explanation: string;
|
301
|
+
}>;
|
302
|
+
/** Result of evaluating a criteria group */
|
303
|
+
204: MessageFunc<CriteriaEvaluatorResult>;
|
304
|
+
/** Personalization placement executing */
|
305
|
+
300: MessageFunc<{
|
306
|
+
name: string;
|
307
|
+
take?: number;
|
308
|
+
}>;
|
309
|
+
/** Personalization placement testing variation */
|
310
|
+
301: MessageFunc<{
|
311
|
+
id: string;
|
312
|
+
op?: string;
|
313
|
+
}>;
|
314
|
+
/** Processed a personalization criteria */
|
315
|
+
302: MessageFunc<{
|
316
|
+
matched: boolean;
|
317
|
+
description: string;
|
318
|
+
}>;
|
319
|
+
/** Final result for a personalized variation */
|
320
|
+
303: MessageFunc<boolean>;
|
321
|
+
/** A/B test placement executing */
|
322
|
+
400: MessageFunc<string>;
|
323
|
+
/** A/B Test definition did not exist */
|
243
324
|
401: MessageFunc<string>;
|
244
325
|
/** Previously shown test variant no longer in variant data */
|
245
326
|
402: MessageFunc<{
|
246
|
-
|
247
|
-
|
327
|
+
missingVariant: string;
|
328
|
+
variants: string[];
|
248
329
|
}>;
|
330
|
+
/** Selected a new A/B test variation */
|
331
|
+
403: MessageFunc<string>;
|
332
|
+
/** Displaying A/B test variation */
|
333
|
+
404: MessageFunc<string>;
|
249
334
|
/** gtag was not present on the page to emit events to */
|
250
335
|
700: MessageFunc;
|
251
336
|
/** Enabled gtag event signal redirection */
|
@@ -253,15 +338,41 @@ declare type LogMessages = {
|
|
253
338
|
};
|
254
339
|
|
255
340
|
declare type Severity = 'debug' | 'info' | 'warn' | 'error';
|
341
|
+
declare type MessageCategory = 'context' | 'storage' | 'testing' | 'personalization' | 'gtag' | 'signals';
|
256
342
|
declare type OutputSeverity = Severity | 'none';
|
257
|
-
declare type MessageFunc<TArg = void> = (arg: TArg) => [
|
258
|
-
|
343
|
+
declare type MessageFunc<TArg = void> = (arg: TArg) => [
|
344
|
+
/** Category of the message */
|
345
|
+
MessageCategory,
|
346
|
+
/** Log message text */
|
347
|
+
string,
|
348
|
+
/** Log message */
|
349
|
+
...unknown[]
|
350
|
+
];
|
351
|
+
declare type LogMessage = LogMessageSingle | LogMessageGroup;
|
352
|
+
declare type LogMessageSingle<TID extends keyof LogMessages = keyof LogMessages> = [
|
259
353
|
severity: Severity,
|
260
354
|
id: TID,
|
261
355
|
...args: Parameters<LogMessages[TID]>
|
262
356
|
];
|
357
|
+
declare type LogMessageGroup<TID extends keyof LogMessages = keyof LogMessages> = [severity: Severity, id: TID, group: 'GROUP', ...args: Parameters<LogMessages[TID]>] | [severity: Severity, id: TID, group: 'ENDGROUP'];
|
263
358
|
declare type LogDrain = (message: LogMessage) => void;
|
264
359
|
|
360
|
+
declare type DecayOptions = {
|
361
|
+
now: number;
|
362
|
+
lastUpd: number | undefined;
|
363
|
+
scores: ScoreVector;
|
364
|
+
sessionScores: ScoreVector;
|
365
|
+
onLogMessage?: (message: LogMessage) => void;
|
366
|
+
};
|
367
|
+
/**
|
368
|
+
* Computes decay of visitor scores over time.
|
369
|
+
* NOTE: it is expected that this function mutates the incoming score vectors,
|
370
|
+
* if it needs to apply score decay. The data store ensures immutability already.
|
371
|
+
*
|
372
|
+
* @returns true if any decay was applied, false otherwise
|
373
|
+
*/
|
374
|
+
declare type DecayFunction = (options: DecayOptions) => boolean;
|
375
|
+
|
265
376
|
declare type VisitorDataStoreOptions = {
|
266
377
|
/** Transition storage used to transfer server or edge side execution state to the client. Unused for client side only. */
|
267
378
|
transitionStore?: TransitionDataStore;
|
@@ -347,9 +458,10 @@ declare class VisitorDataStore {
|
|
347
458
|
declare class ManifestInstance {
|
348
459
|
#private;
|
349
460
|
readonly data: ManifestV2;
|
350
|
-
constructor({ manifest, evaluator, }: {
|
461
|
+
constructor({ manifest, evaluator, onLogMessage, }: {
|
351
462
|
manifest: ManifestV2;
|
352
463
|
evaluator?: GroupCriteriaEvaluator;
|
464
|
+
onLogMessage?: (message: LogMessage) => void;
|
353
465
|
});
|
354
466
|
rollForControlGroup(): boolean;
|
355
467
|
getTest(name: string): TestDefinition | undefined;
|
@@ -361,44 +473,6 @@ declare class ManifestInstance {
|
|
361
473
|
getDimensionByKey(scoreKey: string): EnrichmentCategory | Signal | undefined;
|
362
474
|
}
|
363
475
|
|
364
|
-
declare type SharedTypes = external['uniform-context-types.swagger.yml']['components']['schemas'];
|
365
|
-
declare type ManifestV2 = components['schemas']['ManifestV2'];
|
366
|
-
declare type PersonalizationManifest = components['schemas']['PersonalizationManifest'];
|
367
|
-
declare type Signal = SharedTypes['Signal'];
|
368
|
-
declare type SignalCriteriaGroup = SharedTypes['SignalCriteriaGroup'];
|
369
|
-
declare type SignalCriteria = SharedTypes['SignalCriteria'];
|
370
|
-
declare type EnrichmentCategory = SharedTypes['EnrichmentCategory'];
|
371
|
-
declare type StringMatch = SharedTypes['StringMatch'];
|
372
|
-
declare type NumberMatch = SharedTypes['NumberMatch'];
|
373
|
-
declare type TestDefinition = SharedTypes['Test'];
|
374
|
-
declare type AggregateDimension = SharedTypes['AggregateDimension'];
|
375
|
-
declare type AggregateDimensionInput = SharedTypes['AggregateDimensionInput'];
|
376
|
-
|
377
|
-
/**
|
378
|
-
* The result of evaluating a signal criteria.
|
379
|
-
*/
|
380
|
-
declare type CriteriaEvaluatorResult = {
|
381
|
-
/** Whether the criteria evaluated to true or not */
|
382
|
-
result: boolean;
|
383
|
-
/**
|
384
|
-
* Whether the value of the criteria changed from the previous state
|
385
|
-
* If ALL criteria on a signal have NOT changed, the signal is skipped
|
386
|
-
* and its score is left alone.
|
387
|
-
*/
|
388
|
-
changed: boolean;
|
389
|
-
};
|
390
|
-
/**
|
391
|
-
* A type that evaluates a signal criteria type and
|
392
|
-
* decides if it matches the current Context state or not.
|
393
|
-
*/
|
394
|
-
declare type CriteriaEvaluator = (update: ContextStateUpdate, criteria: SignalCriteria, commands: StorageCommands[], signal: Signal, dimension: string) => CriteriaEvaluatorResult;
|
395
|
-
|
396
|
-
declare class GroupCriteriaEvaluator {
|
397
|
-
#private;
|
398
|
-
constructor(criteriaEvaluators: Record<string, CriteriaEvaluator>);
|
399
|
-
evaluate(update: ContextStateUpdate, crit: SignalCriteriaGroup, commands: StorageCommands[], signal: Signal, dimension: string): CriteriaEvaluatorResult;
|
400
|
-
}
|
401
|
-
|
402
476
|
/** Content that is tagged for adding enrichment score when triggered by behavior (i.e. being shown that content) */
|
403
477
|
declare type BehaviorTag = {
|
404
478
|
beh?: EnrichmentData[];
|
@@ -438,39 +512,6 @@ declare type TestResult<TVariant> = {
|
|
438
512
|
*/
|
439
513
|
variantAssigned: boolean;
|
440
514
|
};
|
441
|
-
/** Defines the shape of arbitrarily tagged content where the tag can be for a test, behaviour, or personalization */
|
442
|
-
declare type TaggedContent = PersonalizedVariant & TestVariant & BehaviorTag & {
|
443
|
-
/** @deprecated no longer used */
|
444
|
-
intents?: IntentTagVector;
|
445
|
-
};
|
446
|
-
/**
|
447
|
-
* A vector keyed by intent ID which contains magnitude and configuration data for each intent ID that has been tagged
|
448
|
-
* @deprecated no longer used
|
449
|
-
*/
|
450
|
-
declare type IntentTagVector = Record<string, IntentTagAxis>;
|
451
|
-
/**
|
452
|
-
* An individual intent tag magnitude value in an IntentTagVector
|
453
|
-
* @deprecated no longer used
|
454
|
-
*/
|
455
|
-
interface IntentTagAxis {
|
456
|
-
/** If this is true, don't use this intent tag when calculating personalization. If false or unspecified, personalization is allowed. */
|
457
|
-
noPn?: boolean;
|
458
|
-
/** If this is true, don't use this intent tag when calculating behavior. If false or unspecified, behavior is allowed. */
|
459
|
-
noBeh?: boolean;
|
460
|
-
/**
|
461
|
-
* If this is true, ANY strength in the tagged intent will result in selecting this variant to personalize,
|
462
|
-
* regardless of other intents' strengths. If more than one tag is override,
|
463
|
-
* they are sorted normally.
|
464
|
-
*/
|
465
|
-
override?: boolean;
|
466
|
-
/**
|
467
|
-
* Sets the minimum visitor score required to trigger this variation.
|
468
|
-
* If more than one intent tag matches, the one with the highest threshold will win.
|
469
|
-
*/
|
470
|
-
threshold?: number;
|
471
|
-
/** Strength of the intent tag. If unspecified, IntentTagStrength.Normal should be inferred */
|
472
|
-
str?: number | string;
|
473
|
-
}
|
474
515
|
|
475
516
|
declare type PersonalizeOptions<TVariant> = {
|
476
517
|
/** Name of placement (sent to analytics) */
|
@@ -479,8 +520,9 @@ declare type PersonalizeOptions<TVariant> = {
|
|
479
520
|
variations: Iterable<TVariant>;
|
480
521
|
/** Maximum number of variants to place (default: 1) */
|
481
522
|
take?: number;
|
523
|
+
onLogMessage?: (message: LogMessage) => void;
|
482
524
|
};
|
483
|
-
declare function personalizeVariations<TVariant extends PersonalizedVariant>({ context, variations, take, }: PersonalizeOptions<TVariant> & {
|
525
|
+
declare function personalizeVariations<TVariant extends PersonalizedVariant>({ name, context, variations, take, onLogMessage, }: PersonalizeOptions<TVariant> & {
|
484
526
|
context: Context;
|
485
527
|
}): PersonalizedResult<TVariant>;
|
486
528
|
|
@@ -537,8 +579,9 @@ declare type TestOptions<TVariant extends TestVariant> = {
|
|
537
579
|
/** Variations that are being tested. */
|
538
580
|
variations: TVariant[];
|
539
581
|
};
|
540
|
-
declare const testVariations: <TVariant extends TestVariant>({ name, context, variations, }: TestOptions<TVariant> & {
|
582
|
+
declare const testVariations: <TVariant extends TestVariant>({ name, context, variations, onLogMessage, }: TestOptions<TVariant> & {
|
541
583
|
context: Context;
|
584
|
+
onLogMessage?: ((message: LogMessage) => void) | undefined;
|
542
585
|
}) => TestResult<TVariant>;
|
543
586
|
|
544
587
|
/**
|
@@ -607,7 +650,7 @@ declare type ContextEvents = {
|
|
607
650
|
* Note that event handlers attached to this event will not catch events
|
608
651
|
* logged during initialisation of the Context unless they are attached as plugins to the constructor.
|
609
652
|
*/
|
610
|
-
log: LogMessage;
|
653
|
+
log: LogMessage | LogMessageGroup;
|
611
654
|
/** Test variant has been selected */
|
612
655
|
testResult: TestEvent;
|
613
656
|
/** Personalization variants have been selected */
|
@@ -642,7 +685,9 @@ declare class Context implements Context {
|
|
642
685
|
* will NOT result in a recomputation of signal state.
|
643
686
|
*/
|
644
687
|
update(newData: Partial<ContextState>): Promise<void>;
|
688
|
+
/** use test() instead */
|
645
689
|
getTestVariantId(testName: string): string | null | undefined;
|
690
|
+
/** use test() instead */
|
646
691
|
setTestVariantId(testName: string, variantId: string): void;
|
647
692
|
/**
|
648
693
|
* Writes a message to the Context log sink.
|
@@ -724,4 +769,4 @@ declare global {
|
|
724
769
|
}
|
725
770
|
}
|
726
771
|
|
727
|
-
export {
|
772
|
+
export { ContextEvents as $, AggregateDimension as A, SetTestCommand as B, ContextPlugin as C, DecayFunction as D, EnrichmentCategory as E, SetControlGroupCommand as F, GroupCriteriaEvaluator as G, DecayOptions as H, IdentifyCommand as I, VisitorDataStoreOptions as J, VisitorDataStoreEvents as K, LogDrain as L, ManifestInstance as M, NumberMatch as N, OutputSeverity as O, PersonalizationManifest as P, Quirks as Q, VisitorDataStore as R, StorageCommands as S, TransitionDataStore as T, ServerToClientTransitionState as U, VisitorData as V, SERVER_STATE_ID as W, TransitionDataStoreEvents as X, ContextOptions as Y, PersonalizationEvent as Z, TestEvent as _, TransitionDataStoreOptions as a, Context as a0, LogMessages as a1, Severity as a2, MessageCategory as a3, MessageFunc as a4, LogMessageSingle as a5, LogMessageGroup as a6, testVariations as a7, TestOptions as a8, PersonalizeOptions as a9, personalizeVariations as aa, DimensionMatch as ab, BehaviorTag as ac, PersonalizedVariant as ad, PersonalizedResult as ae, TestVariant as af, TestResult as ag, DevToolsUiVersion as ah, DevToolsState as ai, DevToolsActions as aj, DevToolsEvent as ak, DevToolsEvents as al, DevToolsLogEvent as am, DevToolsDataEvent as an, DevToolsHelloEvent as ao, DevToolsUpdateEvent as ap, DevToolsRawCommandsEvent as aq, DevToolsForgetEvent as ar, CriteriaEvaluator as b, StringMatch as c, ScoreVector as d, VariantMatchCriteria as e, LogMessage as f, ManifestV2 as g, Signal as h, SignalCriteriaGroup as i, SignalCriteria as j, TestDefinition as k, AggregateDimensionInput as l, CriteriaEvaluatorResult as m, CriteriaEvaluatorParameters as n, SignalData as o, Tests as p, EnrichmentData as q, EventData as r, emptyVisitorData as s, ContextState as t, ContextStateUpdate as u, StorageCommand as v, ModifyScoreCommand as w, ModifySessionScoreCommand as x, SetConsentCommand as y, SetQuirkCommand as z };
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { c as components, e as external } from './v2-manifest.swagger-
|
1
|
+
import { c as components, e as external } from './v2-manifest.swagger-ff2af13e';
|
2
2
|
import * as mitt from 'mitt';
|
3
3
|
|
4
4
|
declare type StorageCommand<TID extends string = string, TData = unknown> = {
|
@@ -192,25 +192,65 @@ declare abstract class TransitionDataStore {
|
|
192
192
|
getClientTransitionState(): ServerToClientTransitionState | undefined;
|
193
193
|
}
|
194
194
|
|
195
|
-
declare type
|
196
|
-
|
197
|
-
|
198
|
-
|
195
|
+
declare type SharedTypes = external['uniform-context-types.swagger.yml']['components']['schemas'];
|
196
|
+
declare type ManifestV2 = components['schemas']['ManifestV2'];
|
197
|
+
declare type PersonalizationManifest = components['schemas']['PersonalizationManifest'];
|
198
|
+
declare type Signal = SharedTypes['Signal'];
|
199
|
+
declare type SignalCriteriaGroup = SharedTypes['SignalCriteriaGroup'];
|
200
|
+
declare type SignalCriteria = SharedTypes['SignalCriteria'];
|
201
|
+
declare type EnrichmentCategory = SharedTypes['EnrichmentCategory'];
|
202
|
+
declare type StringMatch = SharedTypes['StringMatch'];
|
203
|
+
declare type NumberMatch = SharedTypes['NumberMatch'];
|
204
|
+
declare type TestDefinition = SharedTypes['Test'];
|
205
|
+
declare type AggregateDimension = SharedTypes['AggregateDimension'];
|
206
|
+
declare type AggregateDimensionInput = SharedTypes['AggregateDimensionInput'];
|
207
|
+
|
208
|
+
/**
|
209
|
+
* The result of evaluating a signal criteria.
|
210
|
+
*/
|
211
|
+
declare type CriteriaEvaluatorResult = {
|
212
|
+
/** Whether the criteria evaluated to true or not */
|
213
|
+
result: boolean;
|
214
|
+
/**
|
215
|
+
* Whether the value of the criteria changed from the previous state
|
216
|
+
* If ALL criteria on a signal have NOT changed, the signal is skipped
|
217
|
+
* and its score is left alone.
|
218
|
+
*/
|
219
|
+
changed: boolean;
|
199
220
|
};
|
200
|
-
declare type
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
221
|
+
declare type CriteriaEvaluatorParameters = {
|
222
|
+
/** The update being made to the Context state */
|
223
|
+
update: ContextStateUpdate;
|
224
|
+
/** Current criteria to evaluate the update against */
|
225
|
+
criteria: SignalCriteria;
|
226
|
+
/**
|
227
|
+
* The storage commands that will be executed by this update.
|
228
|
+
* If the evaluation requires custom commands, push them into this parameter.
|
229
|
+
* NOTE: needing to use this is very rare and should be avoided if possible.
|
230
|
+
*/
|
231
|
+
commands: StorageCommands[];
|
232
|
+
/** The parent signal containing the criteria we are evaluating */
|
233
|
+
signal: SignalData;
|
234
|
+
/** Function to emit log notices to the Context log */
|
235
|
+
onLogMessage?: (message: LogMessage) => void;
|
236
|
+
};
|
237
|
+
declare type SignalData = Signal & {
|
238
|
+
id: string;
|
205
239
|
};
|
206
240
|
/**
|
207
|
-
*
|
208
|
-
*
|
209
|
-
* if it needs to apply score decay. The data store ensures immutability already.
|
210
|
-
*
|
211
|
-
* @returns true if any decay was applied, false otherwise
|
241
|
+
* A type that evaluates a signal criteria type and
|
242
|
+
* decides if it matches the current Context state or not.
|
212
243
|
*/
|
213
|
-
declare type
|
244
|
+
declare type CriteriaEvaluator = ((parameters: CriteriaEvaluatorParameters) => CriteriaEvaluatorResult) & {
|
245
|
+
/** If true the criteria will always execute even if a short-circuit would normally skip it */
|
246
|
+
alwaysExecute?: boolean;
|
247
|
+
};
|
248
|
+
|
249
|
+
declare class GroupCriteriaEvaluator {
|
250
|
+
#private;
|
251
|
+
constructor(criteriaEvaluators: Record<string, CriteriaEvaluator>);
|
252
|
+
evaluate(update: ContextStateUpdate, crit: SignalCriteriaGroup, commands: StorageCommands[], signal: SignalData, onLogMessage?: (message: LogMessage) => void): CriteriaEvaluatorResult;
|
253
|
+
}
|
214
254
|
|
215
255
|
/** Defines all error codes and their parameter(s) */
|
216
256
|
declare type LogMessages = {
|
@@ -232,6 +272,8 @@ declare type LogMessages = {
|
|
232
272
|
102: MessageFunc<VisitorData>;
|
233
273
|
/** Storage data was deleted bool: fromAllDevices */
|
234
274
|
103: MessageFunc<boolean>;
|
275
|
+
/** Visitor was assigned or removed from control group */
|
276
|
+
104: MessageFunc<boolean>;
|
235
277
|
/** Storage score was truncated to its cap */
|
236
278
|
110: MessageFunc<{
|
237
279
|
dim: string;
|
@@ -244,13 +286,51 @@ declare type LogMessages = {
|
|
244
286
|
130: MessageFunc<ScoreVector>;
|
245
287
|
/** Server to client transition data was discarded */
|
246
288
|
131: MessageFunc;
|
247
|
-
/**
|
289
|
+
/** Decay function executed */
|
290
|
+
140: MessageFunc<string>;
|
291
|
+
/** Signals evaluation beginning */
|
292
|
+
200: MessageFunc;
|
293
|
+
/** Evaluation of a specific signal beginning */
|
294
|
+
201: MessageFunc<SignalData>;
|
295
|
+
/** Evaluation of a group beginning */
|
296
|
+
202: MessageFunc<SignalCriteriaGroup>;
|
297
|
+
203: MessageFunc<{
|
298
|
+
criteria: SignalCriteria;
|
299
|
+
result: CriteriaEvaluatorResult;
|
300
|
+
explanation: string;
|
301
|
+
}>;
|
302
|
+
/** Result of evaluating a criteria group */
|
303
|
+
204: MessageFunc<CriteriaEvaluatorResult>;
|
304
|
+
/** Personalization placement executing */
|
305
|
+
300: MessageFunc<{
|
306
|
+
name: string;
|
307
|
+
take?: number;
|
308
|
+
}>;
|
309
|
+
/** Personalization placement testing variation */
|
310
|
+
301: MessageFunc<{
|
311
|
+
id: string;
|
312
|
+
op?: string;
|
313
|
+
}>;
|
314
|
+
/** Processed a personalization criteria */
|
315
|
+
302: MessageFunc<{
|
316
|
+
matched: boolean;
|
317
|
+
description: string;
|
318
|
+
}>;
|
319
|
+
/** Final result for a personalized variation */
|
320
|
+
303: MessageFunc<boolean>;
|
321
|
+
/** A/B test placement executing */
|
322
|
+
400: MessageFunc<string>;
|
323
|
+
/** A/B Test definition did not exist */
|
248
324
|
401: MessageFunc<string>;
|
249
325
|
/** Previously shown test variant no longer in variant data */
|
250
326
|
402: MessageFunc<{
|
251
|
-
|
252
|
-
|
327
|
+
missingVariant: string;
|
328
|
+
variants: string[];
|
253
329
|
}>;
|
330
|
+
/** Selected a new A/B test variation */
|
331
|
+
403: MessageFunc<string>;
|
332
|
+
/** Displaying A/B test variation */
|
333
|
+
404: MessageFunc<string>;
|
254
334
|
/** gtag was not present on the page to emit events to */
|
255
335
|
700: MessageFunc;
|
256
336
|
/** Enabled gtag event signal redirection */
|
@@ -258,15 +338,41 @@ declare type LogMessages = {
|
|
258
338
|
};
|
259
339
|
|
260
340
|
declare type Severity = 'debug' | 'info' | 'warn' | 'error';
|
341
|
+
declare type MessageCategory = 'context' | 'storage' | 'testing' | 'personalization' | 'gtag' | 'signals';
|
261
342
|
declare type OutputSeverity = Severity | 'none';
|
262
|
-
declare type MessageFunc<TArg = void> = (arg: TArg) => [
|
263
|
-
|
343
|
+
declare type MessageFunc<TArg = void> = (arg: TArg) => [
|
344
|
+
/** Category of the message */
|
345
|
+
MessageCategory,
|
346
|
+
/** Log message text */
|
347
|
+
string,
|
348
|
+
/** Log message */
|
349
|
+
...unknown[]
|
350
|
+
];
|
351
|
+
declare type LogMessage = LogMessageSingle | LogMessageGroup;
|
352
|
+
declare type LogMessageSingle<TID extends keyof LogMessages = keyof LogMessages> = [
|
264
353
|
severity: Severity,
|
265
354
|
id: TID,
|
266
355
|
...args: Parameters<LogMessages[TID]>
|
267
356
|
];
|
357
|
+
declare type LogMessageGroup<TID extends keyof LogMessages = keyof LogMessages> = [severity: Severity, id: TID, group: 'GROUP', ...args: Parameters<LogMessages[TID]>] | [severity: Severity, id: TID, group: 'ENDGROUP'];
|
268
358
|
declare type LogDrain = (message: LogMessage) => void;
|
269
359
|
|
360
|
+
declare type DecayOptions = {
|
361
|
+
now: number;
|
362
|
+
lastUpd: number | undefined;
|
363
|
+
scores: ScoreVector;
|
364
|
+
sessionScores: ScoreVector;
|
365
|
+
onLogMessage?: (message: LogMessage) => void;
|
366
|
+
};
|
367
|
+
/**
|
368
|
+
* Computes decay of visitor scores over time.
|
369
|
+
* NOTE: it is expected that this function mutates the incoming score vectors,
|
370
|
+
* if it needs to apply score decay. The data store ensures immutability already.
|
371
|
+
*
|
372
|
+
* @returns true if any decay was applied, false otherwise
|
373
|
+
*/
|
374
|
+
declare type DecayFunction = (options: DecayOptions) => boolean;
|
375
|
+
|
270
376
|
declare type VisitorDataStoreOptions = {
|
271
377
|
/** Transition storage used to transfer server or edge side execution state to the client. Unused for client side only. */
|
272
378
|
transitionStore?: TransitionDataStore;
|
@@ -352,9 +458,10 @@ declare class VisitorDataStore {
|
|
352
458
|
declare class ManifestInstance {
|
353
459
|
#private;
|
354
460
|
readonly data: ManifestV2;
|
355
|
-
constructor({ manifest, evaluator, }: {
|
461
|
+
constructor({ manifest, evaluator, onLogMessage, }: {
|
356
462
|
manifest: ManifestV2;
|
357
463
|
evaluator?: GroupCriteriaEvaluator;
|
464
|
+
onLogMessage?: (message: LogMessage) => void;
|
358
465
|
});
|
359
466
|
rollForControlGroup(): boolean;
|
360
467
|
getTest(name: string): TestDefinition | undefined;
|
@@ -366,44 +473,6 @@ declare class ManifestInstance {
|
|
366
473
|
getDimensionByKey(scoreKey: string): EnrichmentCategory | Signal | undefined;
|
367
474
|
}
|
368
475
|
|
369
|
-
declare type SharedTypes = external['uniform-context-types.swagger.yml']['components']['schemas'];
|
370
|
-
declare type ManifestV2 = components['schemas']['ManifestV2'];
|
371
|
-
declare type PersonalizationManifest = components['schemas']['PersonalizationManifest'];
|
372
|
-
declare type Signal = SharedTypes['Signal'];
|
373
|
-
declare type SignalCriteriaGroup = SharedTypes['SignalCriteriaGroup'];
|
374
|
-
declare type SignalCriteria = SharedTypes['SignalCriteria'];
|
375
|
-
declare type EnrichmentCategory = SharedTypes['EnrichmentCategory'];
|
376
|
-
declare type StringMatch = SharedTypes['StringMatch'];
|
377
|
-
declare type NumberMatch = SharedTypes['NumberMatch'];
|
378
|
-
declare type TestDefinition = SharedTypes['Test'];
|
379
|
-
declare type AggregateDimension = SharedTypes['AggregateDimension'];
|
380
|
-
declare type AggregateDimensionInput = SharedTypes['AggregateDimensionInput'];
|
381
|
-
|
382
|
-
/**
|
383
|
-
* The result of evaluating a signal criteria.
|
384
|
-
*/
|
385
|
-
declare type CriteriaEvaluatorResult = {
|
386
|
-
/** Whether the criteria evaluated to true or not */
|
387
|
-
result: boolean;
|
388
|
-
/**
|
389
|
-
* Whether the value of the criteria changed from the previous state
|
390
|
-
* If ALL criteria on a signal have NOT changed, the signal is skipped
|
391
|
-
* and its score is left alone.
|
392
|
-
*/
|
393
|
-
changed: boolean;
|
394
|
-
};
|
395
|
-
/**
|
396
|
-
* A type that evaluates a signal criteria type and
|
397
|
-
* decides if it matches the current Context state or not.
|
398
|
-
*/
|
399
|
-
declare type CriteriaEvaluator = (update: ContextStateUpdate, criteria: SignalCriteria, commands: StorageCommands[], signal: Signal, dimension: string) => CriteriaEvaluatorResult;
|
400
|
-
|
401
|
-
declare class GroupCriteriaEvaluator {
|
402
|
-
#private;
|
403
|
-
constructor(criteriaEvaluators: Record<string, CriteriaEvaluator>);
|
404
|
-
evaluate(update: ContextStateUpdate, crit: SignalCriteriaGroup, commands: StorageCommands[], signal: Signal, dimension: string): CriteriaEvaluatorResult;
|
405
|
-
}
|
406
|
-
|
407
476
|
/** Content that is tagged for adding enrichment score when triggered by behavior (i.e. being shown that content) */
|
408
477
|
declare type BehaviorTag = {
|
409
478
|
beh?: EnrichmentData[];
|
@@ -484,8 +553,9 @@ declare type PersonalizeOptions<TVariant> = {
|
|
484
553
|
variations: Iterable<TVariant>;
|
485
554
|
/** Maximum number of variants to place (default: 1) */
|
486
555
|
take?: number;
|
556
|
+
onLogMessage?: (message: LogMessage) => void;
|
487
557
|
};
|
488
|
-
declare function personalizeVariations<TVariant extends PersonalizedVariant>({ context, variations, take, }: PersonalizeOptions<TVariant> & {
|
558
|
+
declare function personalizeVariations<TVariant extends PersonalizedVariant>({ name, context, variations, take, onLogMessage, }: PersonalizeOptions<TVariant> & {
|
489
559
|
context: Context;
|
490
560
|
}): PersonalizedResult<TVariant>;
|
491
561
|
|
@@ -542,8 +612,9 @@ declare type TestOptions<TVariant extends TestVariant> = {
|
|
542
612
|
/** Variations that are being tested. */
|
543
613
|
variations: TVariant[];
|
544
614
|
};
|
545
|
-
declare const testVariations: <TVariant extends TestVariant>({ name, context, variations, }: TestOptions<TVariant> & {
|
615
|
+
declare const testVariations: <TVariant extends TestVariant>({ name, context, variations, onLogMessage, }: TestOptions<TVariant> & {
|
546
616
|
context: Context;
|
617
|
+
onLogMessage?: ((message: LogMessage) => void) | undefined;
|
547
618
|
}) => TestResult<TVariant>;
|
548
619
|
|
549
620
|
/**
|
@@ -612,7 +683,7 @@ declare type ContextEvents = {
|
|
612
683
|
* Note that event handlers attached to this event will not catch events
|
613
684
|
* logged during initialisation of the Context unless they are attached as plugins to the constructor.
|
614
685
|
*/
|
615
|
-
log: LogMessage;
|
686
|
+
log: LogMessage | LogMessageGroup;
|
616
687
|
/** Test variant has been selected */
|
617
688
|
testResult: TestEvent;
|
618
689
|
/** Personalization variants have been selected */
|
@@ -647,7 +718,9 @@ declare class Context implements Context {
|
|
647
718
|
* will NOT result in a recomputation of signal state.
|
648
719
|
*/
|
649
720
|
update(newData: Partial<ContextState>): Promise<void>;
|
721
|
+
/** use test() instead */
|
650
722
|
getTestVariantId(testName: string): string | null | undefined;
|
723
|
+
/** use test() instead */
|
651
724
|
setTestVariantId(testName: string, variantId: string): void;
|
652
725
|
/**
|
653
726
|
* Writes a message to the Context log sink.
|
@@ -729,4 +802,4 @@ declare global {
|
|
729
802
|
}
|
730
803
|
}
|
731
804
|
|
732
|
-
export {
|
805
|
+
export { ContextEvents as $, AggregateDimension as A, SetTestCommand as B, ContextPlugin as C, DecayFunction as D, EnrichmentCategory as E, SetControlGroupCommand as F, GroupCriteriaEvaluator as G, DecayOptions as H, IdentifyCommand as I, VisitorDataStoreOptions as J, VisitorDataStoreEvents as K, LogDrain as L, ManifestInstance as M, NumberMatch as N, OutputSeverity as O, PersonalizationManifest as P, Quirks as Q, VisitorDataStore as R, StorageCommands as S, TransitionDataStore as T, ServerToClientTransitionState as U, VisitorData as V, SERVER_STATE_ID as W, TransitionDataStoreEvents as X, ContextOptions as Y, PersonalizationEvent as Z, TestEvent as _, TransitionDataStoreOptions as a, Context as a0, LogMessages as a1, Severity as a2, MessageCategory as a3, MessageFunc as a4, LogMessageSingle as a5, LogMessageGroup as a6, testVariations as a7, TestOptions as a8, PersonalizeOptions as a9, personalizeVariations as aa, DimensionMatch as ab, BehaviorTag as ac, PersonalizedVariant as ad, PersonalizedResult as ae, TestVariant as af, TestResult as ag, TaggedContent as ah, DevToolsUiVersion as ai, DevToolsState as aj, DevToolsActions as ak, DevToolsEvent as al, DevToolsEvents as am, DevToolsLogEvent as an, DevToolsDataEvent as ao, DevToolsHelloEvent as ap, DevToolsUpdateEvent as aq, DevToolsRawCommandsEvent as ar, DevToolsForgetEvent as as, CriteriaEvaluator as b, StringMatch as c, ScoreVector as d, VariantMatchCriteria as e, LogMessage as f, ManifestV2 as g, Signal as h, SignalCriteriaGroup as i, SignalCriteria as j, TestDefinition as k, AggregateDimensionInput as l, CriteriaEvaluatorResult as m, CriteriaEvaluatorParameters as n, SignalData as o, Tests as p, EnrichmentData as q, EventData as r, emptyVisitorData as s, ContextState as t, ContextStateUpdate as u, StorageCommand as v, ModifyScoreCommand as w, ModifySessionScoreCommand as x, SetConsentCommand as y, SetQuirkCommand as z };
|
@@ -41,6 +41,15 @@ interface components {
|
|
41
41
|
schemas: {
|
42
42
|
ManifestV2: {
|
43
43
|
project: {
|
44
|
+
/**
|
45
|
+
* Format: uuid
|
46
|
+
* @description is not present unless getting a preview manifest
|
47
|
+
*/
|
48
|
+
id?: string;
|
49
|
+
/** @description is not present unless getting a preview manifest */
|
50
|
+
name?: string;
|
51
|
+
/** @description is not present unless getting a preview manifest */
|
52
|
+
ui_version?: number;
|
44
53
|
pz?: components["schemas"]["PersonalizationManifest"];
|
45
54
|
/** @description A/B test settings */
|
46
55
|
test?: {
|