@sprig-technologies/sprig-browser 2.23.0 → 2.23.1

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,3 +1,176 @@
1
+ declare enum NOTIFICATION_TYPES {
2
+ ACTIVATE = "ACTIVATE:experiment, user_id,attributes, variation, event",
3
+ DECISION = "DECISION:type, userId, attributes, decisionInfo",
4
+ LOG_EVENT = "LOG_EVENT:logEvent",
5
+ OPTIMIZELY_CONFIG_UPDATE = "OPTIMIZELY_CONFIG_UPDATE",
6
+ TRACK = "TRACK:event_key, user_id, attributes, event_tags, event"
7
+ }
8
+
9
+ declare type UserAttributes = {
10
+ [name: string]: any;
11
+ };
12
+ declare type EventTags = {
13
+ [key: string]: string | number | null;
14
+ };
15
+ interface ListenerPayload {
16
+ userId: string;
17
+ attributes?: UserAttributes;
18
+ }
19
+ declare type NotificationListener<T extends ListenerPayload> = (notificationData: T) => void;
20
+ interface NotificationCenter {
21
+ addNotificationListener<T extends ListenerPayload>(notificationType: string, callback: NotificationListener<T>): number;
22
+ removeNotificationListener(listenerId: number): boolean;
23
+ clearAllNotificationListeners(): void;
24
+ clearNotificationListeners(notificationType: NOTIFICATION_TYPES): void;
25
+ }
26
+ declare enum OptimizelyDecideOption {
27
+ DISABLE_DECISION_EVENT = "DISABLE_DECISION_EVENT",
28
+ ENABLED_FLAGS_ONLY = "ENABLED_FLAGS_ONLY",
29
+ IGNORE_USER_PROFILE_SERVICE = "IGNORE_USER_PROFILE_SERVICE",
30
+ INCLUDE_REASONS = "INCLUDE_REASONS",
31
+ EXCLUDE_VARIABLES = "EXCLUDE_VARIABLES"
32
+ }
33
+ /**
34
+ * Optimizely Config Entities
35
+ */
36
+ interface OptimizelyExperiment {
37
+ id: string;
38
+ key: string;
39
+ audiences: string;
40
+ variationsMap: {
41
+ [variationKey: string]: OptimizelyVariation;
42
+ };
43
+ }
44
+ interface OptimizelyVariable {
45
+ id: string;
46
+ key: string;
47
+ type: string;
48
+ value: string;
49
+ }
50
+ interface Client {
51
+ notificationCenter: NotificationCenter;
52
+ createUserContext(userId: string, attributes?: UserAttributes): OptimizelyUserContext | null;
53
+ activate(experimentKey: string, userId: string, attributes?: UserAttributes): string | null;
54
+ track(eventKey: string, userId: string, attributes?: UserAttributes, eventTags?: EventTags): void;
55
+ getVariation(experimentKey: string, userId: string, attributes?: UserAttributes): string | null;
56
+ setForcedVariation(experimentKey: string, userId: string, variationKey: string | null): boolean;
57
+ getForcedVariation(experimentKey: string, userId: string): string | null;
58
+ isFeatureEnabled(featureKey: string, userId: string, attributes?: UserAttributes): boolean;
59
+ getEnabledFeatures(userId: string, attributes?: UserAttributes): string[];
60
+ getFeatureVariable(featureKey: string, variableKey: string, userId: string, attributes?: UserAttributes): unknown;
61
+ getFeatureVariableBoolean(featureKey: string, variableKey: string, userId: string, attributes?: UserAttributes): boolean | null;
62
+ getFeatureVariableDouble(featureKey: string, variableKey: string, userId: string, attributes?: UserAttributes): number | null;
63
+ getFeatureVariableInteger(featureKey: string, variableKey: string, userId: string, attributes?: UserAttributes): number | null;
64
+ getFeatureVariableString(featureKey: string, variableKey: string, userId: string, attributes?: UserAttributes): string | null;
65
+ getFeatureVariableJSON(featureKey: string, variableKey: string, userId: string, attributes?: UserAttributes): unknown;
66
+ getAllFeatureVariables(featureKey: string, userId: string, attributes?: UserAttributes): {
67
+ [variableKey: string]: unknown;
68
+ } | null;
69
+ getOptimizelyConfig(): OptimizelyConfig | null;
70
+ onReady(options?: {
71
+ timeout?: number;
72
+ }): Promise<{
73
+ success: boolean;
74
+ reason?: string;
75
+ }>;
76
+ close(): Promise<{
77
+ success: boolean;
78
+ reason?: string;
79
+ }>;
80
+ }
81
+ declare type OptimizelyExperimentsMap = {
82
+ [experimentKey: string]: OptimizelyExperiment;
83
+ };
84
+ declare type OptimizelyVariablesMap = {
85
+ [variableKey: string]: OptimizelyVariable;
86
+ };
87
+ declare type OptimizelyFeaturesMap = {
88
+ [featureKey: string]: OptimizelyFeature;
89
+ };
90
+ declare type OptimizelyAttribute = {
91
+ id: string;
92
+ key: string;
93
+ };
94
+ declare type OptimizelyAudience = {
95
+ id: string;
96
+ name: string;
97
+ conditions: string;
98
+ };
99
+ declare type OptimizelyEvent = {
100
+ id: string;
101
+ key: string;
102
+ experimentsIds: string[];
103
+ };
104
+ interface OptimizelyFeature {
105
+ id: string;
106
+ key: string;
107
+ experimentRules: OptimizelyExperiment[];
108
+ deliveryRules: OptimizelyExperiment[];
109
+ variablesMap: OptimizelyVariablesMap;
110
+ /**
111
+ * @deprecated Use experimentRules and deliveryRules
112
+ */
113
+ experimentsMap: OptimizelyExperimentsMap;
114
+ }
115
+ interface OptimizelyVariation {
116
+ id: string;
117
+ key: string;
118
+ featureEnabled?: boolean;
119
+ variablesMap: OptimizelyVariablesMap;
120
+ }
121
+ interface OptimizelyConfig {
122
+ environmentKey: string;
123
+ sdkKey: string;
124
+ revision: string;
125
+ /**
126
+ * This experimentsMap is for experiments of legacy projects only.
127
+ * For flag projects, experiment keys are not guaranteed to be unique
128
+ * across multiple flags, so this map may not include all experiments
129
+ * when keys conflict.
130
+ */
131
+ experimentsMap: OptimizelyExperimentsMap;
132
+ featuresMap: OptimizelyFeaturesMap;
133
+ attributes: OptimizelyAttribute[];
134
+ audiences: OptimizelyAudience[];
135
+ events: OptimizelyEvent[];
136
+ getDatafile(): string;
137
+ }
138
+ interface OptimizelyUserContext {
139
+ getUserId(): string;
140
+ getAttributes(): UserAttributes;
141
+ setAttribute(key: string, value: unknown): void;
142
+ decide(key: string, options?: OptimizelyDecideOption[]): OptimizelyDecision;
143
+ decideForKeys(keys: string[], options?: OptimizelyDecideOption[]): {
144
+ [key: string]: OptimizelyDecision;
145
+ };
146
+ decideAll(options?: OptimizelyDecideOption[]): {
147
+ [key: string]: OptimizelyDecision;
148
+ };
149
+ trackEvent(eventName: string, eventTags?: EventTags): void;
150
+ setForcedDecision(context: OptimizelyDecisionContext, decision: OptimizelyForcedDecision): boolean;
151
+ getForcedDecision(context: OptimizelyDecisionContext): OptimizelyForcedDecision | null;
152
+ removeForcedDecision(context: OptimizelyDecisionContext): boolean;
153
+ removeAllForcedDecisions(): boolean;
154
+ }
155
+ interface OptimizelyDecision {
156
+ variationKey: string | null;
157
+ enabled: boolean;
158
+ variables: {
159
+ [variableKey: string]: unknown;
160
+ };
161
+ ruleKey: string | null;
162
+ flagKey: string;
163
+ userContext: OptimizelyUserContext;
164
+ reasons: string[];
165
+ }
166
+ interface OptimizelyDecisionContext {
167
+ flagKey: string;
168
+ ruleKey?: string;
169
+ }
170
+ interface OptimizelyForcedDecision {
171
+ variationKey: string;
172
+ }
173
+
1
174
  declare type EventMap = {
2
175
  [eventName: string]: Array<unknown>;
3
176
  };
@@ -729,6 +902,11 @@ declare enum SurveyState {
729
902
  NoSurvey = "no survey"
730
903
  }
731
904
 
905
+ interface Experiment {
906
+ id: string;
907
+ variation?: string;
908
+ }
909
+
732
910
  declare type QueueItem = [string, ...unknown[]] | (() => void);
733
911
  declare class SprigQueue {
734
912
  paused: boolean;
@@ -857,7 +1035,11 @@ declare namespace sprigConfig {
857
1035
  }) => IdentifyResult;
858
1036
  identifyAndTrack: (payload: TrackPayload) => IdentifyResult;
859
1037
  importLaunchDarklyData: (data: Record<string, number>) => void;
860
- integrateOptimizely: (strData: string) => void;
1038
+ integrateOptimizely: (
1039
+ strData: string | { experiments: Experiment[] },
1040
+ isOverride?: boolean
1041
+ ) => void;
1042
+ integrateOptimizelyClient: (client: Client) => void;
861
1043
  logoutUser: () => void;
862
1044
  mute: () => void;
863
1045
  previewSurvey: (surveyTemplateId: UUID) => void;