@uniformdev/context 20.6.1 → 20.6.2-alpha.10
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.mts +1 -1
- package/dist/api/api.d.ts +1 -1
- package/dist/index.d.mts +33 -4
- package/dist/index.d.ts +33 -4
- package/dist/index.esm.js +211 -39
- package/dist/index.js +216 -40
- package/dist/index.mjs +211 -39
- package/dist/{types-EJl31yuP.d.mts → types-CzIkFCDD.d.mts} +96 -24
- package/dist/{types-EJl31yuP.d.ts → types-CzIkFCDD.d.ts} +96 -24
- package/package.json +2 -2
@@ -859,6 +859,10 @@ type LogMessages = {
|
|
859
859
|
}>;
|
860
860
|
/** Final result for a personalized variation */
|
861
861
|
303: MessageFunc<boolean>;
|
862
|
+
/** Personalization algorithm not found */
|
863
|
+
304: MessageFunc<{
|
864
|
+
algorithm: string;
|
865
|
+
}>;
|
862
866
|
/** A/B test placement executing */
|
863
867
|
400: MessageFunc<string>;
|
864
868
|
/** A/B Test definition did not exist */
|
@@ -898,23 +902,34 @@ type LogMessageSingle<TID extends keyof LogMessages = keyof LogMessages> = [
|
|
898
902
|
type LogMessageGroup<TID extends keyof LogMessages = keyof LogMessages> = [severity: Severity, id: TID, group: 'GROUP', ...args: Parameters<LogMessages[TID]>] | [severity: Severity, id: TID, group: 'ENDGROUP'];
|
899
903
|
type LogDrain = (message: LogMessage) => void;
|
900
904
|
|
901
|
-
|
905
|
+
/** Data for a personalization variation using the top-down criteria selection algorithm */
|
906
|
+
interface VariantMatchCriteria extends VariationMatchMetadata {
|
902
907
|
/**
|
903
908
|
* Operation for match criteria
|
904
909
|
*
|
905
910
|
* @defaultValue `&`
|
906
911
|
*/
|
907
912
|
op?: '&' | '|';
|
908
|
-
crit: DimensionMatch
|
909
|
-
/**
|
910
|
-
* Name of the variant for analytics tracking.
|
911
|
-
*/
|
912
|
-
name?: string;
|
913
|
+
crit: Array<DimensionMatch | QuirkMatch>;
|
913
914
|
/**
|
914
915
|
* Control group percentage for the variant.
|
915
916
|
*/
|
916
917
|
control?: number;
|
917
|
-
}
|
918
|
+
}
|
919
|
+
/** Data for a personalization variation using the TODO selection algorithm */
|
920
|
+
interface VariationMatchDimensionCriteria extends VariationMatchMetadata {
|
921
|
+
/** The dimension this content is relevant to */
|
922
|
+
dim: string | undefined;
|
923
|
+
}
|
924
|
+
/** Data that must exist on a personalization variation regardless of selection algorithm */
|
925
|
+
interface VariationMatchMetadata {
|
926
|
+
/**
|
927
|
+
* Name of the variation for analytics tracking.
|
928
|
+
* NOTE: name is optional for backwards compatibility, but it is HIGHLY recommended to specify a name
|
929
|
+
* as the default fallback is not helpfully named and is reliant on the order of the variations array.
|
930
|
+
*/
|
931
|
+
name?: string;
|
932
|
+
}
|
918
933
|
type DimensionMatch = {
|
919
934
|
/**
|
920
935
|
* Left hand side of the match expression (name of dimension in score vector)
|
@@ -953,17 +968,48 @@ type DimensionMatch = {
|
|
953
968
|
*/
|
954
969
|
rDim?: string;
|
955
970
|
};
|
971
|
+
type QuirkMatch = {
|
972
|
+
/**
|
973
|
+
* Type of match expression; 'q' discriminates quirk matches from dimension matches
|
974
|
+
*/
|
975
|
+
t: 'q';
|
976
|
+
/**
|
977
|
+
* Left hand side of the match expression (name of quirk)
|
978
|
+
* NOTE: if the quirk is not present
|
979
|
+
*/
|
980
|
+
l: string;
|
981
|
+
/**
|
982
|
+
* Operator of the match expression
|
983
|
+
* Comparison operators:
|
984
|
+
* =: `l` is equal to the right hand side expression
|
985
|
+
* !=: `l` is not equal to the right hand side expression
|
986
|
+
*/
|
987
|
+
op: '=' | '!=';
|
988
|
+
/**
|
989
|
+
* Right hand side of the match expression
|
990
|
+
* This value is treated as a constant value, if it is present. If it's a string, it is parsed to an integer.
|
991
|
+
* To reference another score dimension as the RHS, use the `rDim` property instead.
|
992
|
+
* `r` and `rDim` are mutually exclusive; if both are specified, then `rDim` wins.
|
993
|
+
*/
|
994
|
+
r: string;
|
995
|
+
/**
|
996
|
+
* Only here to maintain object compatibility with DimensionMatch.
|
997
|
+
* Completely ignored.
|
998
|
+
* @deprecated this is not used with QuirkMatch.
|
999
|
+
*/
|
1000
|
+
rDim?: string;
|
1001
|
+
};
|
956
1002
|
|
957
1003
|
/** Content that is tagged for adding enrichment score when triggered by behavior (i.e. being shown that content) */
|
958
1004
|
type BehaviorTag = {
|
959
1005
|
beh?: EnrichmentData[];
|
960
1006
|
};
|
961
1007
|
/** Defines the shape of a personalized content variant */
|
962
|
-
type PersonalizedVariant = {
|
1008
|
+
type PersonalizedVariant<TCriteria = VariantMatchCriteria> = {
|
963
1009
|
/** A unique identifier for this variation */
|
964
1010
|
id: string;
|
965
1011
|
/** Match criteria for this variation */
|
966
|
-
pz?:
|
1012
|
+
pz?: TCriteria;
|
967
1013
|
};
|
968
1014
|
/** The result of computing personalized content from variations */
|
969
1015
|
type PersonalizedResult<TVariant> = {
|
@@ -971,6 +1017,7 @@ type PersonalizedResult<TVariant> = {
|
|
971
1017
|
personalized: boolean;
|
972
1018
|
/** Matching variations */
|
973
1019
|
variations: Array<TVariant & {
|
1020
|
+
/** Whether the visitor is part of this variation's local control group (also true if part of global control group) */
|
974
1021
|
control: boolean;
|
975
1022
|
}>;
|
976
1023
|
};
|
@@ -995,19 +1042,28 @@ type TestResult<TVariant> = {
|
|
995
1042
|
*/
|
996
1043
|
variantAssigned: boolean;
|
997
1044
|
};
|
998
|
-
|
999
|
-
|
1045
|
+
interface PersonalizeOptions<TVariant> {
|
1046
|
+
/** Name of placement (sent to analytics) */
|
1047
|
+
name: string;
|
1048
|
+
/** Possible variations to place */
|
1049
|
+
variations: Iterable<TVariant>;
|
1050
|
+
/** Maximum number of variants to place (default: 1) */
|
1051
|
+
take?: number;
|
1052
|
+
/** Name of the personalization selection algorithm to use. Defaults to top-down criteria when not specified. */
|
1053
|
+
algorithm?: string;
|
1054
|
+
}
|
1055
|
+
interface PersonalizationSelectionAlgorithmOptions<TCriteria, TVariant extends PersonalizedVariant<TCriteria> = PersonalizedVariant<TCriteria>> {
|
1000
1056
|
/** Name of placement (sent to analytics) */
|
1001
1057
|
name: string;
|
1002
|
-
/** Possible
|
1058
|
+
/** Possible variations to place */
|
1003
1059
|
variations: Iterable<TVariant>;
|
1004
1060
|
/** Maximum number of variants to place (default: 1) */
|
1005
1061
|
take?: number;
|
1062
|
+
/** Callback for logging messages */
|
1006
1063
|
onLogMessage?: (message: LogMessage) => void;
|
1007
|
-
|
1008
|
-
declare function personalizeVariations<TVariant extends PersonalizedVariant>({ name, context, variations, take, onLogMessage, }: PersonalizeOptions<TVariant> & {
|
1064
|
+
/** Context instance */
|
1009
1065
|
context: Context;
|
1010
|
-
}
|
1066
|
+
}
|
1011
1067
|
|
1012
1068
|
type TestOptions<TVariant extends TestVariant> = {
|
1013
1069
|
/** The name of the test that is being run, must be included in the manifest. */
|
@@ -1022,18 +1078,31 @@ declare const testVariations: <TVariant extends TestVariant>({ name, context, va
|
|
1022
1078
|
|
1023
1079
|
declare const CONTEXTUAL_EDITING_TEST_NAME = "contextual_editing_test";
|
1024
1080
|
declare const CONTEXTUAL_EDITING_TEST_SELECTED_VARIANT_ID = "contextual_editing_test_selected_variant";
|
1081
|
+
type PersonalizationSelectionAlgorithm<TCriteria = unknown> = (options: PersonalizationSelectionAlgorithmOptions<TCriteria>) => PersonalizedResult<PersonalizedVariant<TCriteria>>;
|
1082
|
+
type PersonalizationSelectionAlgorithms<TCriteria = unknown> = Record<string, PersonalizationSelectionAlgorithm<TCriteria>>;
|
1025
1083
|
/**
|
1026
1084
|
* Defines a plugin for Uniform Context.
|
1027
1085
|
* The plugin should attach event handlers in its creation function.
|
1028
1086
|
* @returns A function that detaches any event handlers when called
|
1029
1087
|
*/
|
1030
1088
|
type ContextPlugin = {
|
1089
|
+
/** Defines a log drain for the plugin, which all log messages are sent to */
|
1031
1090
|
logDrain?: LogDrain;
|
1091
|
+
/** Initializes the plugin (attach event handlers here if needed) */
|
1032
1092
|
init?: (context: Context) => () => void;
|
1093
|
+
/** Plugin-specific actions to perform when a user is forgotten */
|
1033
1094
|
forget?: () => Promise<void> | void;
|
1095
|
+
/** Plugin-specific actions to perform when the visitor context is updated */
|
1034
1096
|
update?: (newData: Partial<ContextState>) => Promise<void> | void;
|
1097
|
+
/**
|
1098
|
+
* Allows the plugin to register named personalization selection algorithms
|
1099
|
+
*
|
1100
|
+
* Important: the `default` and `strongestMatch` algorithms are automatically registered.
|
1101
|
+
* We strongly advise against replacing these.
|
1102
|
+
*/
|
1103
|
+
personalizationSelectionAlgorithms?: PersonalizationSelectionAlgorithms<any>;
|
1035
1104
|
};
|
1036
|
-
|
1105
|
+
interface ContextOptions extends Omit<VisitorDataStoreOptions, 'manifest' | 'onServerTransitionScoresReceived'> {
|
1037
1106
|
/** The Context Manifest to load (from the Context API) */
|
1038
1107
|
manifest: ManifestV2;
|
1039
1108
|
/**
|
@@ -1050,16 +1119,19 @@ type ContextOptions = {
|
|
1050
1119
|
* `true`: personalization is not run at all unless storage consent is given
|
1051
1120
|
*/
|
1052
1121
|
requireConsentForPersonalization?: boolean;
|
1053
|
-
}
|
1122
|
+
}
|
1123
|
+
type PersonalizationEventVariantId = {
|
1124
|
+
/** The variant ID that was selected */
|
1125
|
+
id: string;
|
1126
|
+
/** Whether the visitor is part of this variant's local control group (also true if part of global control group) */
|
1127
|
+
control: boolean;
|
1128
|
+
};
|
1054
1129
|
/** Emitted when a personalization runs */
|
1055
1130
|
type PersonalizationEvent = {
|
1056
1131
|
/** Name of the personalized placement */
|
1057
1132
|
name: string;
|
1058
1133
|
/** Selected variant ID(s) */
|
1059
|
-
variantIds:
|
1060
|
-
id: string;
|
1061
|
-
control: boolean;
|
1062
|
-
}[];
|
1134
|
+
variantIds: PersonalizationEventVariantId[];
|
1063
1135
|
/** Whether the user was part of the control group (and did not receive any personalization) */
|
1064
1136
|
control: boolean | undefined;
|
1065
1137
|
/**
|
@@ -1113,7 +1185,7 @@ interface ContextInstance {
|
|
1113
1185
|
setTestVariantId(testName: string, variantId: string): void;
|
1114
1186
|
log(...message: LogMessage): void;
|
1115
1187
|
test<TVariant extends TestVariant>(options: TestOptions<TVariant>): TestResult<TVariant>;
|
1116
|
-
personalize<TVariant extends PersonalizedVariant
|
1188
|
+
personalize<TVariant extends PersonalizedVariant<any>>(options: PersonalizeOptions<TVariant>): PersonalizedResult<TVariant>;
|
1117
1189
|
forget(fromAllDevices: boolean): Promise<void>;
|
1118
1190
|
getServerToClientTransitionState(): ServerToClientTransitionState;
|
1119
1191
|
readonly manifest: ManifestInstance;
|
@@ -1178,7 +1250,7 @@ declare class Context implements ContextInstance {
|
|
1178
1250
|
/** 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) */
|
1179
1251
|
test<TVariant extends TestVariant>(options: TestOptions<TVariant>): TestResult<TVariant>;
|
1180
1252
|
/** Executes a personalized placement with a given set of variants */
|
1181
|
-
personalize<TVariant extends PersonalizedVariant
|
1253
|
+
personalize<TVariant extends PersonalizedVariant<any>>(options: PersonalizeOptions<TVariant>): PersonalizedResult<TVariant>;
|
1182
1254
|
/**
|
1183
1255
|
* Forgets the visitor's data and resets the Context to its initial state.
|
1184
1256
|
* @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
|
@@ -1265,4 +1337,4 @@ declare global {
|
|
1265
1337
|
}
|
1266
1338
|
}
|
1267
1339
|
|
1268
|
-
export { type
|
1340
|
+
export { type ManifestV2 as $, type AggregateDimension as A, type DevToolsLogEvent as B, type ContextPlugin as C, type DecayFunction as D, type DevToolsDataEvent as E, type DevToolsHelloEvent as F, type DevToolsUpdateEvent as G, type DevToolsRawCommandsEvent as H, type DevToolsForgetEvent as I, type LogMessages as J, type Severity as K, type LogDrain as L, type MessageCategory as M, type MessageFunc as N, type OutputSeverity as O, type PersonalizedVariant as P, type Quirks as Q, type LogMessageSingle as R, type ScoreVector as S, TransitionDataStore as T, type LogMessageGroup as U, type VisitorData as V, ManifestInstance as W, GroupCriteriaEvaluator as X, type CriteriaEvaluatorResult as Y, type CriteriaEvaluatorParameters as Z, type SignalData as _, type StorageCommands as a, type PersonalizationManifest as a0, type Signal as a1, type SignalCriteriaGroup as a2, type SignalCriteria as a3, type EnrichmentCategory as a4, type NumberMatch as a5, type TestDefinition as a6, type AggregateDimensionInput as a7, type TestOptions as a8, testVariations as a9, type EnrichmentData as aA, type PersonalizeControlVariant as aB, type PersonalizeVariants as aC, type EventData as aD, emptyVisitorData as aE, type ContextState as aF, type ContextStateUpdate as aG, type GoalStateUpdate as aH, type paths as aI, type VariationMatchMetadata as aa, type DimensionMatch as ab, type QuirkMatch as ac, type BehaviorTag as ad, type TestVariant as ae, type TestResult as af, type StorageCommand as ag, type SetGoalCommand as ah, type ModifyScoreCommand as ai, type ModifySessionScoreCommand as aj, type SetConsentCommand as ak, type SetQuirkCommand as al, type SetTestCommand as am, type IdentifyCommand as an, type SetControlGroupCommand as ao, type SetPersonalizeVariantControlCommand as ap, areCommandsEqual as aq, type ServerToClientTransitionState as ar, SERVER_STATE_ID as as, type TransitionDataStoreEvents as at, type DecayOptions as au, type VisitorDataStoreOptions as av, type VisitorDataStoreEvents as aw, VisitorDataStore as ax, type Tests as ay, type Goals as az, type TransitionDataStoreOptions as b, type CriteriaEvaluator as c, type StringMatch as d, type VariantMatchCriteria as e, type LogMessage as f, type PersonalizeOptions as g, Context as h, type PersonalizedResult as i, type VariationMatchDimensionCriteria as j, type PersonalizationSelectionAlgorithmOptions as k, type DevToolsEvents as l, CONTEXTUAL_EDITING_TEST_NAME as m, CONTEXTUAL_EDITING_TEST_SELECTED_VARIANT_ID as n, type PersonalizationSelectionAlgorithm as o, type PersonalizationSelectionAlgorithms as p, type ContextOptions as q, type PersonalizationEventVariantId as r, type PersonalizationEvent as s, type TestEvent as t, type ContextEvents as u, type ContextInstance as v, type DevToolsUiVersion as w, type DevToolsState as x, type DevToolsActions as y, type DevToolsEvent as z };
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@uniformdev/context",
|
3
|
-
"version": "20.6.
|
3
|
+
"version": "20.6.2-alpha.10+ff8a28da1a",
|
4
4
|
"description": "Uniform Context core package",
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
6
6
|
"main": "./dist/index.js",
|
@@ -68,5 +68,5 @@
|
|
68
68
|
"publishConfig": {
|
69
69
|
"access": "public"
|
70
70
|
},
|
71
|
-
"gitHead": "
|
71
|
+
"gitHead": "ff8a28da1a7c11416e5585bc4cb66032bcb6ab53"
|
72
72
|
}
|