@contentful/optimization-core 0.1.0-alpha → 0.1.0-alpha11
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/README.md +329 -93
- package/dist/160.mjs +3 -0
- package/dist/260.mjs +14 -0
- package/dist/260.mjs.map +1 -0
- package/dist/499.mjs +4 -0
- package/dist/632.mjs +5 -0
- package/dist/632.mjs.map +1 -0
- package/dist/942.mjs +2 -0
- package/dist/api-client.cjs +60 -0
- package/dist/api-client.cjs.map +1 -0
- package/dist/api-client.d.cts +4 -0
- package/dist/api-client.d.mts +4 -0
- package/dist/api-client.d.ts +4 -0
- package/dist/api-client.mjs +2 -0
- package/dist/api-schemas.cjs +63 -0
- package/dist/api-schemas.cjs.map +1 -0
- package/dist/api-schemas.d.cts +4 -0
- package/dist/api-schemas.d.mts +4 -0
- package/dist/api-schemas.d.ts +4 -0
- package/dist/api-schemas.mjs +2 -0
- package/dist/constants.cjs +78 -0
- package/dist/constants.cjs.map +1 -0
- package/dist/constants.d.cts +88 -0
- package/dist/constants.d.mts +88 -0
- package/dist/constants.d.ts +88 -0
- package/dist/constants.mjs +1 -0
- package/dist/index.cjs +1509 -1715
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2523 -0
- package/dist/index.d.mts +2523 -0
- package/dist/index.d.ts +2523 -15
- package/dist/index.mjs +1215 -1362
- package/dist/index.mjs.map +1 -1
- package/dist/logger.cjs +67 -0
- package/dist/logger.cjs.map +1 -0
- package/dist/logger.d.cts +8 -0
- package/dist/logger.d.mts +8 -0
- package/dist/logger.d.ts +8 -0
- package/dist/logger.mjs +2 -0
- package/dist/symbols.cjs +42 -0
- package/dist/symbols.cjs.map +1 -0
- package/dist/symbols.d.cts +10 -0
- package/dist/symbols.d.mts +10 -0
- package/dist/symbols.d.ts +10 -0
- package/dist/symbols.mjs +1 -0
- package/package.json +78 -12
- package/dist/Consent.d.ts +0 -44
- package/dist/Consent.d.ts.map +0 -1
- package/dist/Consent.js +0 -2
- package/dist/Consent.js.map +0 -1
- package/dist/CoreBase.d.ts +0 -161
- package/dist/CoreBase.d.ts.map +0 -1
- package/dist/CoreBase.js +0 -151
- package/dist/CoreBase.js.map +0 -1
- package/dist/CoreStateful.d.ts +0 -142
- package/dist/CoreStateful.d.ts.map +0 -1
- package/dist/CoreStateful.js +0 -137
- package/dist/CoreStateful.js.map +0 -1
- package/dist/CoreStateless.d.ts +0 -53
- package/dist/CoreStateless.d.ts.map +0 -1
- package/dist/CoreStateless.js +0 -43
- package/dist/CoreStateless.js.map +0 -1
- package/dist/ProductBase.d.ts +0 -83
- package/dist/ProductBase.d.ts.map +0 -1
- package/dist/ProductBase.js +0 -50
- package/dist/ProductBase.js.map +0 -1
- package/dist/analytics/AnalyticsBase.d.ts +0 -35
- package/dist/analytics/AnalyticsBase.d.ts.map +0 -1
- package/dist/analytics/AnalyticsBase.js +0 -13
- package/dist/analytics/AnalyticsBase.js.map +0 -1
- package/dist/analytics/AnalyticsStateful.d.ts +0 -138
- package/dist/analytics/AnalyticsStateful.d.ts.map +0 -1
- package/dist/analytics/AnalyticsStateful.js +0 -179
- package/dist/analytics/AnalyticsStateful.js.map +0 -1
- package/dist/analytics/AnalyticsStateless.d.ts +0 -48
- package/dist/analytics/AnalyticsStateless.d.ts.map +0 -1
- package/dist/analytics/AnalyticsStateless.js +0 -61
- package/dist/analytics/AnalyticsStateless.js.map +0 -1
- package/dist/analytics/index.d.ts +0 -5
- package/dist/analytics/index.d.ts.map +0 -1
- package/dist/analytics/index.js +0 -5
- package/dist/analytics/index.js.map +0 -1
- package/dist/global-constants.d.ts +0 -18
- package/dist/global-constants.d.ts.map +0 -1
- package/dist/global-constants.js +0 -18
- package/dist/global-constants.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -15
- package/dist/index.js.map +0 -1
- package/dist/lib/decorators/guardedBy.d.ts +0 -113
- package/dist/lib/decorators/guardedBy.d.ts.map +0 -1
- package/dist/lib/decorators/guardedBy.js +0 -143
- package/dist/lib/decorators/guardedBy.js.map +0 -1
- package/dist/lib/decorators/index.d.ts +0 -2
- package/dist/lib/decorators/index.d.ts.map +0 -1
- package/dist/lib/decorators/index.js +0 -2
- package/dist/lib/decorators/index.js.map +0 -1
- package/dist/lib/interceptor/InterceptorManager.d.ts +0 -127
- package/dist/lib/interceptor/InterceptorManager.d.ts.map +0 -1
- package/dist/lib/interceptor/InterceptorManager.js +0 -125
- package/dist/lib/interceptor/InterceptorManager.js.map +0 -1
- package/dist/lib/interceptor/index.d.ts +0 -2
- package/dist/lib/interceptor/index.d.ts.map +0 -1
- package/dist/lib/interceptor/index.js +0 -2
- package/dist/lib/interceptor/index.js.map +0 -1
- package/dist/lib/value-presence/ValuePresence.d.ts +0 -123
- package/dist/lib/value-presence/ValuePresence.d.ts.map +0 -1
- package/dist/lib/value-presence/ValuePresence.js +0 -141
- package/dist/lib/value-presence/ValuePresence.js.map +0 -1
- package/dist/lib/value-presence/index.d.ts +0 -2
- package/dist/lib/value-presence/index.d.ts.map +0 -1
- package/dist/lib/value-presence/index.js +0 -2
- package/dist/lib/value-presence/index.js.map +0 -1
- package/dist/personalization/PersonalizationBase.d.ts +0 -184
- package/dist/personalization/PersonalizationBase.d.ts.map +0 -1
- package/dist/personalization/PersonalizationBase.js +0 -76
- package/dist/personalization/PersonalizationBase.js.map +0 -1
- package/dist/personalization/PersonalizationStateful.d.ts +0 -226
- package/dist/personalization/PersonalizationStateful.d.ts.map +0 -1
- package/dist/personalization/PersonalizationStateful.js +0 -297
- package/dist/personalization/PersonalizationStateful.js.map +0 -1
- package/dist/personalization/PersonalizationStateless.d.ts +0 -74
- package/dist/personalization/PersonalizationStateless.d.ts.map +0 -1
- package/dist/personalization/PersonalizationStateless.js +0 -98
- package/dist/personalization/PersonalizationStateless.js.map +0 -1
- package/dist/personalization/index.d.ts +0 -6
- package/dist/personalization/index.d.ts.map +0 -1
- package/dist/personalization/index.js +0 -6
- package/dist/personalization/index.js.map +0 -1
- package/dist/personalization/resolvers/FlagsResolver.d.ts +0 -35
- package/dist/personalization/resolvers/FlagsResolver.d.ts.map +0 -1
- package/dist/personalization/resolvers/FlagsResolver.js +0 -47
- package/dist/personalization/resolvers/FlagsResolver.js.map +0 -1
- package/dist/personalization/resolvers/MergeTagValueResolver.d.ts +0 -74
- package/dist/personalization/resolvers/MergeTagValueResolver.d.ts.map +0 -1
- package/dist/personalization/resolvers/MergeTagValueResolver.js +0 -109
- package/dist/personalization/resolvers/MergeTagValueResolver.js.map +0 -1
- package/dist/personalization/resolvers/PersonalizedEntryResolver.d.ts +0 -142
- package/dist/personalization/resolvers/PersonalizedEntryResolver.d.ts.map +0 -1
- package/dist/personalization/resolvers/PersonalizedEntryResolver.js +0 -196
- package/dist/personalization/resolvers/PersonalizedEntryResolver.js.map +0 -1
- package/dist/personalization/resolvers/index.d.ts +0 -7
- package/dist/personalization/resolvers/index.d.ts.map +0 -1
- package/dist/personalization/resolvers/index.js +0 -7
- package/dist/personalization/resolvers/index.js.map +0 -1
- package/dist/signals.d.ts +0 -35
- package/dist/signals.d.ts.map +0 -1
- package/dist/signals.js +0 -30
- package/dist/signals.js.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1,1805 +1,1599 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __webpack_modules__ = {
|
|
3
|
-
"./src/
|
|
4
|
-
__webpack_require__
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var logger__rspack_import_1 = __webpack_require__("../../lib/logger/dist/index.mjs");
|
|
9
|
-
var _global_constants__rspack_import_3 = __webpack_require__("./src/global-constants.ts");
|
|
10
|
-
var _lib_interceptor__rspack_import_2 = __webpack_require__("./src/lib/interceptor/InterceptorManager.ts");
|
|
11
|
-
class CoreBase {
|
|
12
|
-
api;
|
|
13
|
-
eventBuilder;
|
|
14
|
-
config;
|
|
15
|
-
interceptors = {
|
|
16
|
-
event: new _lib_interceptor__rspack_import_2.v(),
|
|
17
|
-
state: new _lib_interceptor__rspack_import_2.v()
|
|
18
|
-
};
|
|
19
|
-
constructor(config){
|
|
20
|
-
this.config = config;
|
|
21
|
-
const { analytics, personalization, eventBuilder, logLevel, environment, clientId } = config;
|
|
22
|
-
logger__rspack_import_1.vF.addSink(new logger__rspack_import_1.vg(logLevel));
|
|
23
|
-
const apiConfig = {
|
|
24
|
-
...analytics,
|
|
25
|
-
...personalization,
|
|
26
|
-
clientId,
|
|
27
|
-
environment
|
|
28
|
-
};
|
|
29
|
-
this.api = new _contentful_optimization_api_client__rspack_import_0.ApiClient(apiConfig);
|
|
30
|
-
this.eventBuilder = new _contentful_optimization_api_client__rspack_import_0.EventBuilder(eventBuilder ?? {
|
|
31
|
-
channel: 'server',
|
|
32
|
-
library: {
|
|
33
|
-
name: 'Optimization Core',
|
|
34
|
-
version: _global_constants__rspack_import_3.E
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
getCustomFlag(name, changes) {
|
|
39
|
-
return this.personalization.getCustomFlag(name, changes);
|
|
40
|
-
}
|
|
41
|
-
personalizeEntry(entry, personalizations) {
|
|
42
|
-
return this.personalization.personalizeEntry(entry, personalizations);
|
|
43
|
-
}
|
|
44
|
-
getMergeTagValue(embeddedEntryNodeTarget, profile) {
|
|
45
|
-
return this.personalization.getMergeTagValue(embeddedEntryNodeTarget, profile);
|
|
46
|
-
}
|
|
47
|
-
async identify(payload) {
|
|
48
|
-
return await this.personalization.identify(payload);
|
|
3
|
+
"./src/api-schemas.ts" (__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
4
|
+
var _contentful_optimization_api_client_api_schemas__rspack_import_0 = __webpack_require__("@contentful/optimization-api-client/api-schemas");
|
|
5
|
+
if (__webpack_require__.o(_contentful_optimization_api_client_api_schemas__rspack_import_0, "PartialProfile")) __webpack_require__.d(__webpack_exports__, {
|
|
6
|
+
PartialProfile: function() {
|
|
7
|
+
return _contentful_optimization_api_client_api_schemas__rspack_import_0.PartialProfile;
|
|
49
8
|
}
|
|
50
|
-
async page(payload) {
|
|
51
|
-
return await this.personalization.page(payload);
|
|
52
|
-
}
|
|
53
|
-
async screen(payload) {
|
|
54
|
-
return await this.personalization.screen(payload);
|
|
55
|
-
}
|
|
56
|
-
async track(payload) {
|
|
57
|
-
return await this.personalization.track(payload);
|
|
58
|
-
}
|
|
59
|
-
async trackComponentView(payload, duplicationScope) {
|
|
60
|
-
if (payload.sticky) return await this.personalization.trackComponentView(payload, duplicationScope);
|
|
61
|
-
await this.analytics.trackComponentView(payload, duplicationScope);
|
|
62
|
-
}
|
|
63
|
-
async trackFlagView(payload, duplicationScope) {
|
|
64
|
-
await this.analytics.trackFlagView(payload, duplicationScope);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
const __rspack_default_export = CoreBase;
|
|
68
|
-
},
|
|
69
|
-
"./src/CoreStateful.ts" (__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
70
|
-
__webpack_require__.d(__webpack_exports__, {
|
|
71
|
-
A: ()=>__rspack_default_export
|
|
72
9
|
});
|
|
73
|
-
var _analytics__rspack_import_0 = __webpack_require__("./src/analytics/index.ts");
|
|
74
|
-
var _CoreBase__rspack_import_1 = __webpack_require__("./src/CoreBase.ts");
|
|
75
|
-
var _personalization__rspack_import_2 = __webpack_require__("./src/personalization/index.ts");
|
|
76
|
-
var _signals__rspack_import_3 = __webpack_require__("./src/signals.ts");
|
|
77
|
-
class CoreStateful extends _CoreBase__rspack_import_1.A {
|
|
78
|
-
analytics;
|
|
79
|
-
personalization;
|
|
80
|
-
constructor(config){
|
|
81
|
-
super(config);
|
|
82
|
-
const { allowedEventTypes, defaults, getAnonymousId, preventedComponentEvents } = config;
|
|
83
|
-
if (defaults?.consent !== void 0) {
|
|
84
|
-
const { consent: defaultConsent } = defaults;
|
|
85
|
-
_signals__rspack_import_3.vJ.value = defaultConsent;
|
|
86
|
-
}
|
|
87
|
-
this.analytics = new _analytics__rspack_import_0.R({
|
|
88
|
-
api: this.api,
|
|
89
|
-
builder: this.eventBuilder,
|
|
90
|
-
config: {
|
|
91
|
-
allowedEventTypes,
|
|
92
|
-
preventedComponentEvents,
|
|
93
|
-
defaults: {
|
|
94
|
-
consent: defaults?.consent,
|
|
95
|
-
profile: defaults?.profile
|
|
96
|
-
}
|
|
97
|
-
},
|
|
98
|
-
interceptors: this.interceptors
|
|
99
|
-
});
|
|
100
|
-
this.personalization = new _personalization__rspack_import_2.$C({
|
|
101
|
-
api: this.api,
|
|
102
|
-
builder: this.eventBuilder,
|
|
103
|
-
config: {
|
|
104
|
-
allowedEventTypes,
|
|
105
|
-
getAnonymousId,
|
|
106
|
-
preventedComponentEvents,
|
|
107
|
-
defaults: {
|
|
108
|
-
consent: defaults?.consent,
|
|
109
|
-
changes: defaults?.changes,
|
|
110
|
-
profile: defaults?.profile,
|
|
111
|
-
personalizations: defaults?.personalizations
|
|
112
|
-
}
|
|
113
|
-
},
|
|
114
|
-
interceptors: this.interceptors
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
get states() {
|
|
118
|
-
return {
|
|
119
|
-
consent: (0, _signals__rspack_import_3.br)(_signals__rspack_import_3.vJ),
|
|
120
|
-
eventStream: (0, _signals__rspack_import_3.br)(_signals__rspack_import_3.f0),
|
|
121
|
-
flags: (0, _signals__rspack_import_3.br)(_signals__rspack_import_3.Mv),
|
|
122
|
-
personalizations: (0, _signals__rspack_import_3.br)(_signals__rspack_import_3.wh),
|
|
123
|
-
profile: (0, _signals__rspack_import_3.br)(_signals__rspack_import_3.ME)
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
reset() {
|
|
127
|
-
(0, _signals__rspack_import_3.vA)(()=>{
|
|
128
|
-
_signals__rspack_import_3.f0.value = void 0;
|
|
129
|
-
_signals__rspack_import_3.Ao.value = void 0;
|
|
130
|
-
_signals__rspack_import_3.ME.value = void 0;
|
|
131
|
-
_signals__rspack_import_3.wh.value = void 0;
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
async flush() {
|
|
135
|
-
await this.analytics.flush();
|
|
136
|
-
await this.personalization.flush();
|
|
137
|
-
}
|
|
138
|
-
consent(accept) {
|
|
139
|
-
_signals__rspack_import_3.vJ.value = accept;
|
|
140
|
-
}
|
|
141
|
-
online(isOnline) {
|
|
142
|
-
_signals__rspack_import_3.WD.value = isOnline;
|
|
143
|
-
}
|
|
144
|
-
registerPreviewPanel(previewPanel) {
|
|
145
|
-
previewPanel.signals = _signals__rspack_import_3.QO;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
const __rspack_default_export = CoreStateful;
|
|
149
10
|
},
|
|
150
|
-
"./src/
|
|
11
|
+
"./src/constants.ts" (__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
151
12
|
__webpack_require__.d(__webpack_exports__, {
|
|
152
|
-
|
|
13
|
+
ANONYMOUS_ID_COOKIE: ()=>ANONYMOUS_ID_COOKIE,
|
|
14
|
+
ANONYMOUS_ID_COOKIE_LEGACY: ()=>ANONYMOUS_ID_COOKIE_LEGACY,
|
|
15
|
+
ANONYMOUS_ID_KEY: ()=>ANONYMOUS_ID_KEY,
|
|
16
|
+
ANONYMOUS_ID_KEY_LEGACY: ()=>ANONYMOUS_ID_KEY_LEGACY,
|
|
17
|
+
CHANGES_CACHE_KEY: ()=>CHANGES_CACHE_KEY,
|
|
18
|
+
CONSENT_KEY: ()=>CONSENT_KEY,
|
|
19
|
+
DEBUG_FLAG_KEY: ()=>DEBUG_FLAG_KEY,
|
|
20
|
+
OPTIMIZATION_CORE_SDK_NAME: ()=>OPTIMIZATION_CORE_SDK_NAME,
|
|
21
|
+
OPTIMIZATION_CORE_SDK_VERSION: ()=>OPTIMIZATION_CORE_SDK_VERSION,
|
|
22
|
+
PROFILE_CACHE_KEY: ()=>PROFILE_CACHE_KEY,
|
|
23
|
+
SELECTED_OPTIMIZATIONS_CACHE_KEY: ()=>SELECTED_OPTIMIZATIONS_CACHE_KEY
|
|
153
24
|
});
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
interceptors: this.interceptors
|
|
166
|
-
});
|
|
167
|
-
this.personalization = new _personalization__rspack_import_2.jL({
|
|
168
|
-
api: this.api,
|
|
169
|
-
builder: this.eventBuilder,
|
|
170
|
-
interceptors: this.interceptors
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
const __rspack_default_export = CoreStateless;
|
|
25
|
+
const OPTIMIZATION_CORE_SDK_VERSION = "0.1.0-alpha11";
|
|
26
|
+
const OPTIMIZATION_CORE_SDK_NAME = "@contentful/optimization-core";
|
|
27
|
+
const ANONYMOUS_ID_COOKIE = 'ctfl-opt-aid';
|
|
28
|
+
const ANONYMOUS_ID_KEY = '__ctfl_opt_anonymous_id__';
|
|
29
|
+
const CONSENT_KEY = '__ctfl_opt_consent__';
|
|
30
|
+
const CHANGES_CACHE_KEY = '__ctfl_opt_changes__';
|
|
31
|
+
const DEBUG_FLAG_KEY = '__ctfl_opt_debug__';
|
|
32
|
+
const PROFILE_CACHE_KEY = '__ctfl_opt_profile__';
|
|
33
|
+
const SELECTED_OPTIMIZATIONS_CACHE_KEY = '__ctfl_opt_selected-optimizations__';
|
|
34
|
+
const ANONYMOUS_ID_COOKIE_LEGACY = 'ntaid';
|
|
35
|
+
const ANONYMOUS_ID_KEY_LEGACY = '__nt_anonymous_id__';
|
|
175
36
|
},
|
|
176
|
-
"./src/
|
|
37
|
+
"./src/symbols.ts" (__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
177
38
|
__webpack_require__.d(__webpack_exports__, {
|
|
178
|
-
|
|
39
|
+
PREVIEW_PANEL_SIGNALS_SYMBOL: ()=>PREVIEW_PANEL_SIGNALS_SYMBOL,
|
|
40
|
+
PREVIEW_PANEL_SIGNAL_FNS_SYMBOL: ()=>PREVIEW_PANEL_SIGNAL_FNS_SYMBOL
|
|
179
41
|
});
|
|
180
|
-
|
|
181
|
-
const
|
|
182
|
-
'page',
|
|
183
|
-
'identify'
|
|
184
|
-
];
|
|
185
|
-
class ProductBase {
|
|
186
|
-
allowedEventTypes;
|
|
187
|
-
builder;
|
|
188
|
-
api;
|
|
189
|
-
duplicationDetector;
|
|
190
|
-
interceptors;
|
|
191
|
-
constructor(options){
|
|
192
|
-
const { api, builder, config, interceptors } = options;
|
|
193
|
-
this.allowedEventTypes = config?.allowedEventTypes ?? defaultAllowedEvents;
|
|
194
|
-
this.api = api;
|
|
195
|
-
this.builder = builder;
|
|
196
|
-
this.duplicationDetector = new _lib_value_presence_ValuePresence__rspack_import_0.A(config?.preventedComponentEvents);
|
|
197
|
-
this.interceptors = interceptors;
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
const __rspack_default_export = ProductBase;
|
|
42
|
+
const PREVIEW_PANEL_SIGNALS_SYMBOL = Symbol.for('ctfl.optimization.preview.signals');
|
|
43
|
+
const PREVIEW_PANEL_SIGNAL_FNS_SYMBOL = Symbol.for('ctfl.optimization.preview.signalFns');
|
|
201
44
|
},
|
|
202
|
-
"
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
45
|
+
"@contentful/optimization-api-client/api-schemas" (module) {
|
|
46
|
+
module.exports = require("@contentful/optimization-api-client/api-schemas");
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
var __webpack_module_cache__ = {};
|
|
50
|
+
function __webpack_require__(moduleId) {
|
|
51
|
+
var cachedModule = __webpack_module_cache__[moduleId];
|
|
52
|
+
if (void 0 !== cachedModule) return cachedModule.exports;
|
|
53
|
+
var module = __webpack_module_cache__[moduleId] = {
|
|
54
|
+
exports: {}
|
|
55
|
+
};
|
|
56
|
+
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
57
|
+
return module.exports;
|
|
58
|
+
}
|
|
59
|
+
(()=>{
|
|
60
|
+
__webpack_require__.n = (module)=>{
|
|
61
|
+
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
62
|
+
__webpack_require__.d(getter, {
|
|
63
|
+
a: getter
|
|
206
64
|
});
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
function assertValidReturnValue(kind, value) {
|
|
296
|
-
var type = typeof value;
|
|
297
|
-
if (1 === kind) {
|
|
298
|
-
if ("object" !== type || null === value) throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");
|
|
299
|
-
if (void 0 !== value.get) assertCallable(value.get, "accessor.get");
|
|
300
|
-
if (void 0 !== value.set) assertCallable(value.set, "accessor.set");
|
|
301
|
-
if (void 0 !== value.init) assertCallable(value.init, "accessor.init");
|
|
302
|
-
} else if ("function" !== type) {
|
|
303
|
-
var hint;
|
|
304
|
-
hint = 0 === kind ? "field" : 10 === kind ? "class" : "method";
|
|
305
|
-
throw new TypeError(hint + " decorators must return a function or void 0");
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
function applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata) {
|
|
309
|
-
var decs = decInfo[0];
|
|
310
|
-
var desc, init, value;
|
|
311
|
-
if (isPrivate) desc = 0 === kind || 1 === kind ? {
|
|
312
|
-
get: decInfo[3],
|
|
313
|
-
set: decInfo[4]
|
|
314
|
-
} : 3 === kind ? {
|
|
315
|
-
get: decInfo[3]
|
|
316
|
-
} : 4 === kind ? {
|
|
317
|
-
set: decInfo[3]
|
|
318
|
-
} : {
|
|
319
|
-
value: decInfo[3]
|
|
65
|
+
return getter;
|
|
66
|
+
};
|
|
67
|
+
})();
|
|
68
|
+
(()=>{
|
|
69
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
70
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
71
|
+
enumerable: true,
|
|
72
|
+
get: definition[key]
|
|
73
|
+
});
|
|
74
|
+
};
|
|
75
|
+
})();
|
|
76
|
+
(()=>{
|
|
77
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
78
|
+
})();
|
|
79
|
+
(()=>{
|
|
80
|
+
__webpack_require__.r = (exports1)=>{
|
|
81
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
82
|
+
value: 'Module'
|
|
83
|
+
});
|
|
84
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
85
|
+
value: true
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
})();
|
|
89
|
+
var __webpack_exports__ = {};
|
|
90
|
+
(()=>{
|
|
91
|
+
__webpack_require__.r(__webpack_exports__);
|
|
92
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
93
|
+
HoverBuilderArgs: ()=>HoverBuilderArgs,
|
|
94
|
+
ANONYMOUS_ID_KEY: ()=>constants.ANONYMOUS_ID_KEY,
|
|
95
|
+
OPTIMIZATION_CORE_SDK_NAME: ()=>constants.OPTIMIZATION_CORE_SDK_NAME,
|
|
96
|
+
OPTIMIZATION_CORE_SDK_VERSION: ()=>constants.OPTIMIZATION_CORE_SDK_VERSION,
|
|
97
|
+
DEFAULT_PAGE_PROPERTIES: ()=>DEFAULT_PAGE_PROPERTIES,
|
|
98
|
+
PROFILE_CACHE_KEY: ()=>constants.PROFILE_CACHE_KEY,
|
|
99
|
+
SELECTED_OPTIMIZATIONS_CACHE_KEY: ()=>constants.SELECTED_OPTIMIZATIONS_CACHE_KEY,
|
|
100
|
+
PageViewBuilderArgs: ()=>PageViewBuilderArgs,
|
|
101
|
+
ScreenViewBuilderArgs: ()=>ScreenViewBuilderArgs,
|
|
102
|
+
batch: ()=>signals_core_namespaceObject.batch,
|
|
103
|
+
toObservable: ()=>toObservable,
|
|
104
|
+
InterceptorManager: ()=>InterceptorManager,
|
|
105
|
+
CONSENT_KEY: ()=>constants.CONSENT_KEY,
|
|
106
|
+
FlagViewBuilderArgs: ()=>FlagViewBuilderArgs,
|
|
107
|
+
signals: ()=>signals,
|
|
108
|
+
TrackBuilderArgs: ()=>TrackBuilderArgs,
|
|
109
|
+
ViewBuilderArgs: ()=>ViewBuilderArgs,
|
|
110
|
+
toDistinctObservable: ()=>toDistinctObservable,
|
|
111
|
+
ANONYMOUS_ID_KEY_LEGACY: ()=>constants.ANONYMOUS_ID_KEY_LEGACY,
|
|
112
|
+
CoreStateless: ()=>src_CoreStateless,
|
|
113
|
+
PREVIEW_PANEL_SIGNAL_FNS_SYMBOL: ()=>symbols.PREVIEW_PANEL_SIGNAL_FNS_SYMBOL,
|
|
114
|
+
CoreStateful: ()=>src_CoreStateful,
|
|
115
|
+
MergeTagValueResolver: ()=>resolvers_MergeTagValueResolver,
|
|
116
|
+
signalFns: ()=>signalFns,
|
|
117
|
+
DEBUG_FLAG_KEY: ()=>constants.DEBUG_FLAG_KEY,
|
|
118
|
+
IdentifyBuilderArgs: ()=>IdentifyBuilderArgs,
|
|
119
|
+
FlagsResolver: ()=>resolvers_FlagsResolver,
|
|
120
|
+
ANONYMOUS_ID_COOKIE_LEGACY: ()=>constants.ANONYMOUS_ID_COOKIE_LEGACY,
|
|
121
|
+
ANONYMOUS_ID_COOKIE: ()=>constants.ANONYMOUS_ID_COOKIE,
|
|
122
|
+
ClickBuilderArgs: ()=>ClickBuilderArgs,
|
|
123
|
+
OptimizedEntryResolver: ()=>resolvers_OptimizedEntryResolver,
|
|
124
|
+
UniversalEventBuilderArgs: ()=>UniversalEventBuilderArgs,
|
|
125
|
+
EntryInteractionBuilderArgsBase: ()=>EntryInteractionBuilderArgsBase,
|
|
126
|
+
effect: ()=>signals_core_namespaceObject.effect,
|
|
127
|
+
CoreStatelessRequestScope: ()=>CoreStatelessRequestScope,
|
|
128
|
+
PREVIEW_PANEL_SIGNALS_SYMBOL: ()=>symbols.PREVIEW_PANEL_SIGNALS_SYMBOL,
|
|
129
|
+
guardedBy: ()=>guardedBy,
|
|
130
|
+
CHANGES_CACHE_KEY: ()=>constants.CHANGES_CACHE_KEY,
|
|
131
|
+
EventBuilder: ()=>events_EventBuilder
|
|
132
|
+
});
|
|
133
|
+
const signals_core_namespaceObject = require("@preact/signals-core");
|
|
134
|
+
const external_es_toolkit_namespaceObject = require("es-toolkit");
|
|
135
|
+
function isNonNullish(value) {
|
|
136
|
+
return null != value;
|
|
137
|
+
}
|
|
138
|
+
function toError(value) {
|
|
139
|
+
if (value instanceof Error) return value;
|
|
140
|
+
return new Error(`Subscriber threw non-Error value: ${String(value)}`);
|
|
141
|
+
}
|
|
142
|
+
function toObservable(s) {
|
|
143
|
+
return {
|
|
144
|
+
get current () {
|
|
145
|
+
return (0, external_es_toolkit_namespaceObject.cloneDeep)(s.value);
|
|
146
|
+
},
|
|
147
|
+
subscribe (next) {
|
|
148
|
+
const dispose = (0, signals_core_namespaceObject.effect)(()=>{
|
|
149
|
+
next((0, external_es_toolkit_namespaceObject.cloneDeep)(s.value));
|
|
150
|
+
});
|
|
151
|
+
return {
|
|
152
|
+
unsubscribe: dispose
|
|
320
153
|
};
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
154
|
+
},
|
|
155
|
+
subscribeOnce (next) {
|
|
156
|
+
let closed = false;
|
|
157
|
+
let isEffectActive = false;
|
|
158
|
+
let dispose = ()=>void 0;
|
|
159
|
+
const stop = ()=>{
|
|
160
|
+
if (closed) return;
|
|
161
|
+
closed = true;
|
|
162
|
+
if (isEffectActive) dispose();
|
|
325
163
|
};
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
init = newValue.init;
|
|
337
|
-
get = newValue.get || value.get;
|
|
338
|
-
set = newValue.set || value.set;
|
|
339
|
-
value = {
|
|
340
|
-
get: get,
|
|
341
|
-
set: set
|
|
342
|
-
};
|
|
343
|
-
} else value = newValue;
|
|
344
|
-
}
|
|
345
|
-
} else for(var i = decs.length - 1; i >= 0; i--){
|
|
346
|
-
var dec = decs[i];
|
|
347
|
-
newValue = memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
|
|
348
|
-
if (void 0 !== newValue) {
|
|
349
|
-
assertValidReturnValue(kind, newValue);
|
|
350
|
-
var newInit;
|
|
351
|
-
if (0 === kind) newInit = newValue;
|
|
352
|
-
else if (1 === kind) {
|
|
353
|
-
newInit = newValue.init;
|
|
354
|
-
get = newValue.get || value.get;
|
|
355
|
-
set = newValue.set || value.set;
|
|
356
|
-
value = {
|
|
357
|
-
get: get,
|
|
358
|
-
set: set
|
|
359
|
-
};
|
|
360
|
-
} else value = newValue;
|
|
361
|
-
if (void 0 !== newInit) if (void 0 === init) init = newInit;
|
|
362
|
-
else if ("function" == typeof init) init = [
|
|
363
|
-
init,
|
|
364
|
-
newInit
|
|
365
|
-
];
|
|
366
|
-
else init.push(newInit);
|
|
164
|
+
dispose = (0, signals_core_namespaceObject.effect)(()=>{
|
|
165
|
+
if (closed) return;
|
|
166
|
+
const { value } = s;
|
|
167
|
+
if (!isNonNullish(value)) return;
|
|
168
|
+
closed = true;
|
|
169
|
+
let callbackError = null;
|
|
170
|
+
try {
|
|
171
|
+
next((0, external_es_toolkit_namespaceObject.cloneDeep)(value));
|
|
172
|
+
} catch (error) {
|
|
173
|
+
callbackError = toError(error);
|
|
367
174
|
}
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
if (
|
|
371
|
-
return init;
|
|
372
|
-
};
|
|
373
|
-
else if ("function" != typeof init) {
|
|
374
|
-
var ownInitializers = init;
|
|
375
|
-
init = function(instance, init) {
|
|
376
|
-
var value = init;
|
|
377
|
-
for(var i = 0; i < ownInitializers.length; i++)value = ownInitializers[i].call(instance, value);
|
|
378
|
-
return value;
|
|
379
|
-
};
|
|
380
|
-
} else {
|
|
381
|
-
var originalInitializer = init;
|
|
382
|
-
init = function(instance, init) {
|
|
383
|
-
return originalInitializer.call(instance, init);
|
|
384
|
-
};
|
|
385
|
-
}
|
|
386
|
-
ret.push(init);
|
|
387
|
-
}
|
|
388
|
-
if (0 !== kind) {
|
|
389
|
-
if (1 === kind) {
|
|
390
|
-
desc.get = value.get;
|
|
391
|
-
desc.set = value.set;
|
|
392
|
-
} else if (2 === kind) desc.value = value;
|
|
393
|
-
else if (3 === kind) desc.get = value;
|
|
394
|
-
else if (4 === kind) desc.set = value;
|
|
395
|
-
if (isPrivate) if (1 === kind) {
|
|
396
|
-
ret.push(function(instance, args) {
|
|
397
|
-
return value.get.call(instance, args);
|
|
398
|
-
});
|
|
399
|
-
ret.push(function(instance, args) {
|
|
400
|
-
return value.set.call(instance, args);
|
|
401
|
-
});
|
|
402
|
-
} else if (2 === kind) ret.push(value);
|
|
403
|
-
else ret.push(function(instance, args) {
|
|
404
|
-
return value.call(instance, args);
|
|
405
|
-
});
|
|
406
|
-
else Object.defineProperty(base, name, desc);
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
function applyMemberDecs(Class, decInfos, metadata) {
|
|
410
|
-
var ret = [];
|
|
411
|
-
var protoInitializers;
|
|
412
|
-
var staticInitializers;
|
|
413
|
-
var existingProtoNonFields = new Map();
|
|
414
|
-
var existingStaticNonFields = new Map();
|
|
415
|
-
for(var i = 0; i < decInfos.length; i++){
|
|
416
|
-
var decInfo = decInfos[i];
|
|
417
|
-
if (Array.isArray(decInfo)) {
|
|
418
|
-
var kind = decInfo[1];
|
|
419
|
-
var name = decInfo[2];
|
|
420
|
-
var isPrivate = decInfo.length > 3;
|
|
421
|
-
var isStatic = kind >= 5;
|
|
422
|
-
var base;
|
|
423
|
-
var initializers;
|
|
424
|
-
if (isStatic) {
|
|
425
|
-
base = Class;
|
|
426
|
-
kind -= 5;
|
|
427
|
-
staticInitializers = staticInitializers || [];
|
|
428
|
-
initializers = staticInitializers;
|
|
429
|
-
} else {
|
|
430
|
-
base = Class.prototype;
|
|
431
|
-
protoInitializers = protoInitializers || [];
|
|
432
|
-
initializers = protoInitializers;
|
|
433
|
-
}
|
|
434
|
-
if (0 !== kind && !isPrivate) {
|
|
435
|
-
var existingNonFields = isStatic ? existingStaticNonFields : existingProtoNonFields;
|
|
436
|
-
var existingKind = existingNonFields.get(name) || 0;
|
|
437
|
-
if (true === existingKind || 3 === existingKind && 4 !== kind || 4 === existingKind && 3 !== kind) throw new Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: " + name);
|
|
438
|
-
if (!existingKind && kind > 2) existingNonFields.set(name, kind);
|
|
439
|
-
else existingNonFields.set(name, true);
|
|
440
|
-
}
|
|
441
|
-
applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata);
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
pushInitializers(ret, protoInitializers);
|
|
445
|
-
pushInitializers(ret, staticInitializers);
|
|
446
|
-
return ret;
|
|
447
|
-
}
|
|
448
|
-
function pushInitializers(ret, initializers) {
|
|
449
|
-
if (initializers) ret.push(function(instance) {
|
|
450
|
-
for(var i = 0; i < initializers.length; i++)initializers[i].call(instance);
|
|
451
|
-
return instance;
|
|
175
|
+
if (isEffectActive) dispose();
|
|
176
|
+
else queueMicrotask(dispose);
|
|
177
|
+
if (callbackError) throw callbackError;
|
|
452
178
|
});
|
|
179
|
+
isEffectActive = true;
|
|
180
|
+
return {
|
|
181
|
+
unsubscribe: stop
|
|
182
|
+
};
|
|
453
183
|
}
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
} finally{
|
|
471
|
-
decoratorFinishedRef.v = true;
|
|
472
|
-
}
|
|
473
|
-
if (void 0 !== nextNewClass) {
|
|
474
|
-
assertValidReturnValue(10, nextNewClass);
|
|
475
|
-
newClass = nextNewClass;
|
|
476
|
-
}
|
|
477
|
-
}
|
|
478
|
-
return [
|
|
479
|
-
defineMetadata(newClass, metadata),
|
|
480
|
-
function() {
|
|
481
|
-
for(var i = 0; i < initializers.length; i++)initializers[i].call(newClass);
|
|
482
|
-
}
|
|
483
|
-
];
|
|
484
|
-
}
|
|
485
|
-
}
|
|
486
|
-
function defineMetadata(Class, metadata) {
|
|
487
|
-
return Object.defineProperty(Class, Symbol.metadata || Symbol.for("Symbol.metadata"), {
|
|
488
|
-
configurable: true,
|
|
489
|
-
enumerable: true,
|
|
490
|
-
value: metadata
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
function toDistinctObservable(s, isEqual) {
|
|
187
|
+
const observable = toObservable(s);
|
|
188
|
+
return {
|
|
189
|
+
get current () {
|
|
190
|
+
return observable.current;
|
|
191
|
+
},
|
|
192
|
+
subscribe (next) {
|
|
193
|
+
let hasPrevious = false;
|
|
194
|
+
let previous = (0, external_es_toolkit_namespaceObject.cloneDeep)(observable.current);
|
|
195
|
+
return observable.subscribe((value)=>{
|
|
196
|
+
if (hasPrevious && isEqual(previous, value)) return;
|
|
197
|
+
hasPrevious = true;
|
|
198
|
+
previous = (0, external_es_toolkit_namespaceObject.cloneDeep)(value);
|
|
199
|
+
next(value);
|
|
491
200
|
});
|
|
201
|
+
},
|
|
202
|
+
subscribeOnce (next) {
|
|
203
|
+
return observable.subscribeOnce(next);
|
|
492
204
|
}
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
const signals_changes = (0, signals_core_namespaceObject.signal)();
|
|
208
|
+
const blockedEvent = (0, signals_core_namespaceObject.signal)();
|
|
209
|
+
const consent = (0, signals_core_namespaceObject.signal)();
|
|
210
|
+
const signals_event = (0, signals_core_namespaceObject.signal)();
|
|
211
|
+
const online = (0, signals_core_namespaceObject.signal)(true);
|
|
212
|
+
const previewPanelAttached = (0, signals_core_namespaceObject.signal)(false);
|
|
213
|
+
const previewPanelOpen = (0, signals_core_namespaceObject.signal)(false);
|
|
214
|
+
const signals_selectedOptimizations = (0, signals_core_namespaceObject.signal)();
|
|
215
|
+
const canOptimize = (0, signals_core_namespaceObject.computed)(()=>void 0 !== signals_selectedOptimizations.value);
|
|
216
|
+
const signals_profile = (0, signals_core_namespaceObject.signal)();
|
|
217
|
+
const signals = {
|
|
218
|
+
blockedEvent,
|
|
219
|
+
changes: signals_changes,
|
|
220
|
+
consent,
|
|
221
|
+
event: signals_event,
|
|
222
|
+
online,
|
|
223
|
+
previewPanelAttached,
|
|
224
|
+
previewPanelOpen,
|
|
225
|
+
selectedOptimizations: signals_selectedOptimizations,
|
|
226
|
+
canOptimize,
|
|
227
|
+
profile: signals_profile
|
|
228
|
+
};
|
|
229
|
+
const signalFns = {
|
|
230
|
+
batch: signals_core_namespaceObject.batch,
|
|
231
|
+
computed: signals_core_namespaceObject.computed,
|
|
232
|
+
effect: signals_core_namespaceObject.effect,
|
|
233
|
+
untracked: signals_core_namespaceObject.untracked
|
|
234
|
+
};
|
|
235
|
+
var constants = __webpack_require__("./src/constants.ts");
|
|
236
|
+
const optimization_api_client_namespaceObject = require("@contentful/optimization-api-client");
|
|
237
|
+
const logger_namespaceObject = require("@contentful/optimization-api-client/logger");
|
|
238
|
+
var api_schemas_ = __webpack_require__("@contentful/optimization-api-client/api-schemas");
|
|
239
|
+
const object_namespaceObject = require("es-toolkit/object");
|
|
240
|
+
const mini_namespaceObject = require("zod/mini");
|
|
241
|
+
const UniversalEventBuilderArgs = mini_namespaceObject.object({
|
|
242
|
+
campaign: mini_namespaceObject.optional(api_schemas_.Campaign),
|
|
243
|
+
locale: mini_namespaceObject.optional(mini_namespaceObject.string()),
|
|
244
|
+
location: mini_namespaceObject.optional(api_schemas_.GeoLocation),
|
|
245
|
+
page: mini_namespaceObject.optional(api_schemas_.Page),
|
|
246
|
+
screen: mini_namespaceObject.optional(api_schemas_.Screen),
|
|
247
|
+
userAgent: mini_namespaceObject.optional(mini_namespaceObject.string())
|
|
248
|
+
});
|
|
249
|
+
const EntryInteractionBuilderArgsBase = mini_namespaceObject.extend(UniversalEventBuilderArgs, {
|
|
250
|
+
componentId: mini_namespaceObject.string(),
|
|
251
|
+
experienceId: mini_namespaceObject.optional(mini_namespaceObject.string()),
|
|
252
|
+
variantIndex: mini_namespaceObject.optional(mini_namespaceObject.number())
|
|
253
|
+
});
|
|
254
|
+
const ViewBuilderArgs = mini_namespaceObject.extend(EntryInteractionBuilderArgsBase, {
|
|
255
|
+
sticky: mini_namespaceObject.optional(mini_namespaceObject.boolean()),
|
|
256
|
+
viewId: mini_namespaceObject.string(),
|
|
257
|
+
viewDurationMs: mini_namespaceObject.number()
|
|
258
|
+
});
|
|
259
|
+
const FlagViewBuilderArgs = mini_namespaceObject.extend(EntryInteractionBuilderArgsBase, {
|
|
260
|
+
viewId: mini_namespaceObject.optional(mini_namespaceObject.string()),
|
|
261
|
+
viewDurationMs: mini_namespaceObject.optional(mini_namespaceObject.number())
|
|
262
|
+
});
|
|
263
|
+
const ClickBuilderArgs = EntryInteractionBuilderArgsBase;
|
|
264
|
+
const HoverBuilderArgs = mini_namespaceObject.extend(EntryInteractionBuilderArgsBase, {
|
|
265
|
+
hoverId: mini_namespaceObject.string(),
|
|
266
|
+
hoverDurationMs: mini_namespaceObject.number()
|
|
267
|
+
});
|
|
268
|
+
const IdentifyBuilderArgs = mini_namespaceObject.extend(UniversalEventBuilderArgs, {
|
|
269
|
+
traits: mini_namespaceObject.optional(api_schemas_.Traits),
|
|
270
|
+
userId: mini_namespaceObject.string()
|
|
271
|
+
});
|
|
272
|
+
const PageViewBuilderArgs = mini_namespaceObject.extend(UniversalEventBuilderArgs, {
|
|
273
|
+
properties: mini_namespaceObject.optional(mini_namespaceObject.partial(api_schemas_.Page))
|
|
274
|
+
});
|
|
275
|
+
const ScreenViewBuilderArgs = mini_namespaceObject.extend(UniversalEventBuilderArgs, {
|
|
276
|
+
name: mini_namespaceObject.string(),
|
|
277
|
+
properties: api_schemas_.Properties
|
|
278
|
+
});
|
|
279
|
+
const TrackBuilderArgs = mini_namespaceObject.extend(UniversalEventBuilderArgs, {
|
|
280
|
+
event: mini_namespaceObject.string(),
|
|
281
|
+
properties: mini_namespaceObject.optional(mini_namespaceObject.prefault(api_schemas_.Properties, {}))
|
|
282
|
+
});
|
|
283
|
+
const DEFAULT_PAGE_PROPERTIES = {
|
|
284
|
+
path: '',
|
|
285
|
+
query: {},
|
|
286
|
+
referrer: '',
|
|
287
|
+
search: '',
|
|
288
|
+
title: '',
|
|
289
|
+
url: ''
|
|
290
|
+
};
|
|
291
|
+
class EventBuilder {
|
|
292
|
+
app;
|
|
293
|
+
channel;
|
|
294
|
+
library;
|
|
295
|
+
getLocale;
|
|
296
|
+
getPageProperties;
|
|
297
|
+
getUserAgent;
|
|
298
|
+
constructor(config){
|
|
299
|
+
const { app, channel, library, getLocale, getPageProperties, getUserAgent } = config;
|
|
300
|
+
this.app = app;
|
|
301
|
+
this.channel = channel;
|
|
302
|
+
this.library = library;
|
|
303
|
+
this.getLocale = getLocale ?? (()=>'en-US');
|
|
304
|
+
this.getPageProperties = getPageProperties ?? (()=>DEFAULT_PAGE_PROPERTIES);
|
|
305
|
+
this.getUserAgent = getUserAgent ?? (()=>void 0);
|
|
306
|
+
}
|
|
307
|
+
buildUniversalEventProperties({ campaign = {}, locale, location, page, screen, userAgent }) {
|
|
308
|
+
const timestamp = new Date().toISOString();
|
|
309
|
+
return {
|
|
310
|
+
channel: this.channel,
|
|
311
|
+
context: {
|
|
312
|
+
app: this.app,
|
|
313
|
+
campaign,
|
|
314
|
+
gdpr: {
|
|
315
|
+
isConsentGiven: true
|
|
316
|
+
},
|
|
317
|
+
library: this.library,
|
|
318
|
+
locale: locale ?? this.getLocale() ?? 'en-US',
|
|
319
|
+
location,
|
|
320
|
+
page: page ?? this.getPageProperties(),
|
|
321
|
+
screen,
|
|
322
|
+
userAgent: userAgent ?? this.getUserAgent()
|
|
323
|
+
},
|
|
324
|
+
messageId: crypto.randomUUID(),
|
|
325
|
+
originalTimestamp: timestamp,
|
|
326
|
+
sentAt: timestamp,
|
|
327
|
+
timestamp
|
|
504
328
|
};
|
|
505
329
|
}
|
|
506
|
-
|
|
507
|
-
return
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
onBlocked: 'onBlockedByDuplication'
|
|
514
|
-
}), _dec1 = (0, guardedBy.i)('hasConsent', {
|
|
515
|
-
onBlocked: 'onBlockedByConsent'
|
|
516
|
-
}), _dec2 = (0, guardedBy.i)('isNotDuplicated', {
|
|
517
|
-
onBlocked: 'onBlockedByDuplication'
|
|
518
|
-
}), _dec3 = (0, guardedBy.i)('hasConsent', {
|
|
519
|
-
onBlocked: 'onBlockedByConsent'
|
|
520
|
-
});
|
|
521
|
-
class AnalyticsStateful extends analytics_AnalyticsBase {
|
|
522
|
-
static{
|
|
523
|
-
({ e: [_initProto] } = _apply_decs_2203_r(this, [
|
|
524
|
-
[
|
|
525
|
-
[
|
|
526
|
-
_dec,
|
|
527
|
-
_dec1
|
|
528
|
-
],
|
|
529
|
-
2,
|
|
530
|
-
"trackComponentView"
|
|
531
|
-
],
|
|
532
|
-
[
|
|
533
|
-
[
|
|
534
|
-
_dec2,
|
|
535
|
-
_dec3
|
|
536
|
-
],
|
|
537
|
-
2,
|
|
538
|
-
"trackFlagView"
|
|
539
|
-
]
|
|
540
|
-
], []));
|
|
541
|
-
}
|
|
542
|
-
queue = (_initProto(this), new Map());
|
|
543
|
-
states = {
|
|
544
|
-
eventStream: (0, signals.br)(signals.f0),
|
|
545
|
-
profile: (0, signals.br)(signals.ME)
|
|
330
|
+
buildEntryInteractionBase(universal, componentId, experienceId, variantIndex) {
|
|
331
|
+
return {
|
|
332
|
+
...this.buildUniversalEventProperties(universal),
|
|
333
|
+
componentType: 'Entry',
|
|
334
|
+
componentId,
|
|
335
|
+
experienceId,
|
|
336
|
+
variantIndex: variantIndex ?? 0
|
|
546
337
|
};
|
|
547
|
-
constructor(options){
|
|
548
|
-
const { api, builder, config, interceptors } = options;
|
|
549
|
-
super({
|
|
550
|
-
api,
|
|
551
|
-
builder,
|
|
552
|
-
config,
|
|
553
|
-
interceptors
|
|
554
|
-
});
|
|
555
|
-
const { defaults } = config ?? {};
|
|
556
|
-
if (defaults?.profile !== void 0) {
|
|
557
|
-
const { profile: defaultProfile } = defaults;
|
|
558
|
-
signals.ME.value = defaultProfile;
|
|
559
|
-
}
|
|
560
|
-
(0, signals.QZ)(()=>{
|
|
561
|
-
const id = signals.ME.value?.id;
|
|
562
|
-
logger.info(`Analytics ${signals.vJ.value ? 'will' : 'will not'} be collected due to consent (${signals.vJ.value})`);
|
|
563
|
-
logger.debug(`Profile ${id && `with ID ${id}`} has been ${id ? 'set' : 'cleared'}`);
|
|
564
|
-
});
|
|
565
|
-
(0, signals.QZ)(()=>{
|
|
566
|
-
if (signals.WD.value) this.flush();
|
|
567
|
-
});
|
|
568
|
-
}
|
|
569
|
-
reset() {
|
|
570
|
-
(0, signals.vA)(()=>{
|
|
571
|
-
signals.f0.value = void 0;
|
|
572
|
-
signals.ME.value = void 0;
|
|
573
|
-
});
|
|
574
|
-
}
|
|
575
|
-
hasConsent(name) {
|
|
576
|
-
return !!signals.vJ.value || (this.allowedEventTypes ?? []).includes('trackComponentView' === name || 'trackFlagView' === name ? 'component' : name);
|
|
577
|
-
}
|
|
578
|
-
onBlockedByConsent(name, payload) {
|
|
579
|
-
logger.warn(`Event "${name}" was blocked due to lack of consent; payload: ${JSON.stringify(payload)}`);
|
|
580
|
-
}
|
|
581
|
-
isNotDuplicated(_name, payload) {
|
|
582
|
-
const [{ componentId: value }, duplicationScope] = payload;
|
|
583
|
-
const isDuplicated = this.duplicationDetector.isPresent(duplicationScope, value);
|
|
584
|
-
if (!isDuplicated) this.duplicationDetector.addValue(duplicationScope, value);
|
|
585
|
-
return !isDuplicated;
|
|
586
|
-
}
|
|
587
|
-
onBlockedByDuplication(name, payload) {
|
|
588
|
-
const componentType = 'trackFlagView' === name ? 'flag' : 'component';
|
|
589
|
-
logger.debug(`Duplicate "${componentType} view" event detected, skipping; payload: ${JSON.stringify(payload)}`);
|
|
590
|
-
}
|
|
591
|
-
async trackComponentView(payload, _duplicationScope = '') {
|
|
592
|
-
logger.info(`Processing "component view" event for ${payload.componentId}`);
|
|
593
|
-
await this.enqueueEvent(this.builder.buildComponentView(payload));
|
|
594
|
-
}
|
|
595
|
-
async trackFlagView(payload, _duplicationScope = '') {
|
|
596
|
-
logger.debug(`Processing "flag view" event for ${payload.componentId}`);
|
|
597
|
-
await this.enqueueEvent(this.builder.buildFlagView(payload));
|
|
598
|
-
}
|
|
599
|
-
async enqueueEvent(event) {
|
|
600
|
-
const { value: profile } = signals.ME;
|
|
601
|
-
if (!profile) return void logger.warn('Attempting to emit an event without an Optimization profile');
|
|
602
|
-
const intercepted = await this.interceptors.event.run(event);
|
|
603
|
-
const validEvent = optimization_api_client_.InsightsEvent.parse(intercepted);
|
|
604
|
-
logger.debug(`Queueing ${validEvent.type} event for profile ${profile.id}`, validEvent);
|
|
605
|
-
const profileEventQueue = this.queue.get(profile);
|
|
606
|
-
signals.f0.value = validEvent;
|
|
607
|
-
if (profileEventQueue) profileEventQueue.push(validEvent);
|
|
608
|
-
else this.queue.set(profile, [
|
|
609
|
-
validEvent
|
|
610
|
-
]);
|
|
611
|
-
await this.flushMaxEvents();
|
|
612
|
-
}
|
|
613
|
-
async flushMaxEvents() {
|
|
614
|
-
if (this.queue.values().toArray().flat().length >= MAX_QUEUED_EVENTS) await this.flush();
|
|
615
|
-
}
|
|
616
|
-
async flush() {
|
|
617
|
-
logger.debug('Flushing event queue');
|
|
618
|
-
const batches = [];
|
|
619
|
-
this.queue.forEach((events, profile)=>batches.push({
|
|
620
|
-
profile,
|
|
621
|
-
events
|
|
622
|
-
}));
|
|
623
|
-
if (!batches.length) return;
|
|
624
|
-
const sendSuccess = await this.api.insights.sendBatchEvents(batches);
|
|
625
|
-
if (sendSuccess) this.queue.clear();
|
|
626
|
-
}
|
|
627
338
|
}
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
const parsed = optimization_api_client_.ComponentViewEvent.parse(intercepted);
|
|
637
|
-
await this.sendBatchEvent(parsed, profile);
|
|
638
|
-
}
|
|
639
|
-
async trackFlagView(args) {
|
|
640
|
-
AnalyticsStateless_logger.debug('Processing "flag view" event');
|
|
641
|
-
const { profile, ...builderArgs } = args;
|
|
642
|
-
const event = this.builder.buildFlagView(builderArgs);
|
|
643
|
-
const intercepted = await this.interceptors.event.run(event);
|
|
644
|
-
const parsed = optimization_api_client_.ComponentViewEvent.parse(intercepted);
|
|
645
|
-
await this.sendBatchEvent(parsed, profile);
|
|
646
|
-
}
|
|
647
|
-
async sendBatchEvent(event, profile) {
|
|
648
|
-
const batchEvent = optimization_api_client_.BatchInsightsEventArray.parse([
|
|
649
|
-
{
|
|
650
|
-
profile,
|
|
651
|
-
events: [
|
|
652
|
-
event
|
|
653
|
-
]
|
|
654
|
-
}
|
|
655
|
-
]);
|
|
656
|
-
await this.api.insights.sendBatchEvents(batchEvent);
|
|
657
|
-
}
|
|
339
|
+
buildView(args) {
|
|
340
|
+
const { componentId, viewId, experienceId, variantIndex, viewDurationMs, ...universal } = (0, api_schemas_.parseWithFriendlyError)(ViewBuilderArgs, args);
|
|
341
|
+
return {
|
|
342
|
+
...this.buildEntryInteractionBase(universal, componentId, experienceId, variantIndex),
|
|
343
|
+
type: 'component',
|
|
344
|
+
viewId,
|
|
345
|
+
viewDurationMs
|
|
346
|
+
};
|
|
658
347
|
}
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
T: ()=>ANONYMOUS_ID_COOKIE
|
|
665
|
-
});
|
|
666
|
-
const OPTIMIZATION_CORE_SDK_VERSION = "0.1.0-alpha";
|
|
667
|
-
const ANONYMOUS_ID_COOKIE = 'ctfl-opt-aid';
|
|
668
|
-
},
|
|
669
|
-
"./src/lib/decorators/guardedBy.ts" (__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
670
|
-
__webpack_require__.d(__webpack_exports__, {
|
|
671
|
-
i: ()=>guardedBy
|
|
672
|
-
});
|
|
673
|
-
const isFunction = (v)=>'function' == typeof v;
|
|
674
|
-
const nameToString = (name)=>'string' == typeof name ? name : 'symbol' == typeof name ? name.description ?? String(name) : String(name);
|
|
675
|
-
const isOnBlockedKey = (v)=>'string' == typeof v || 'symbol' == typeof v;
|
|
676
|
-
const isAsyncFunction = (fn)=>'[object AsyncFunction]' === Object.prototype.toString.call(fn);
|
|
677
|
-
function guardedBy(predicateName, opts) {
|
|
678
|
-
return function(_value, context) {
|
|
679
|
-
const decoratedName = nameToString(context.name);
|
|
680
|
-
context.addInitializer(function() {
|
|
681
|
-
const originalUnknown = Reflect.get(this, context.name);
|
|
682
|
-
if (!isFunction(originalUnknown)) return;
|
|
683
|
-
const original = originalUnknown;
|
|
684
|
-
const originalIsAsync = isAsyncFunction(original);
|
|
685
|
-
const resolvePredicate = (self)=>{
|
|
686
|
-
const { [predicateName]: cand } = self;
|
|
687
|
-
if (!isFunction(cand)) throw new TypeError(`@guardedBy expects predicate "${String(predicateName)}" to be a synchronous function.`);
|
|
688
|
-
return cand;
|
|
689
|
-
};
|
|
690
|
-
const computeAllowed = (self, args)=>{
|
|
691
|
-
const pred = resolvePredicate(self);
|
|
692
|
-
const ok = Boolean(pred.call(self, decoratedName, args));
|
|
693
|
-
return opts?.invert === true ? !ok : ok;
|
|
694
|
-
};
|
|
695
|
-
const runOnBlocked = (self, args)=>{
|
|
696
|
-
const { onBlocked } = opts ?? {};
|
|
697
|
-
if (void 0 === onBlocked) return;
|
|
698
|
-
if (isFunction(onBlocked)) return void onBlocked.call(self, decoratedName, args);
|
|
699
|
-
if (isOnBlockedKey(onBlocked)) {
|
|
700
|
-
const { [onBlocked]: handlerCandidate } = self;
|
|
701
|
-
if (isFunction(handlerCandidate)) handlerCandidate.call(self, decoratedName, args);
|
|
702
|
-
}
|
|
703
|
-
};
|
|
704
|
-
const blockedReturn = ()=>originalIsAsync ? Promise.resolve(void 0) : void 0;
|
|
705
|
-
const wrapped = function(...args) {
|
|
706
|
-
if (!computeAllowed(this, args)) {
|
|
707
|
-
runOnBlocked(this, args);
|
|
708
|
-
return blockedReturn();
|
|
709
|
-
}
|
|
710
|
-
return original.call(this, ...args);
|
|
711
|
-
};
|
|
712
|
-
Reflect.set(this, context.name, wrapped);
|
|
713
|
-
});
|
|
348
|
+
buildClick(args) {
|
|
349
|
+
const { componentId, experienceId, variantIndex, ...universal } = (0, api_schemas_.parseWithFriendlyError)(ClickBuilderArgs, args);
|
|
350
|
+
return {
|
|
351
|
+
...this.buildEntryInteractionBase(universal, componentId, experienceId, variantIndex),
|
|
352
|
+
type: 'component_click'
|
|
714
353
|
};
|
|
715
354
|
}
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
355
|
+
buildHover(args) {
|
|
356
|
+
const { hoverId, componentId, experienceId, hoverDurationMs, variantIndex, ...universal } = (0, api_schemas_.parseWithFriendlyError)(HoverBuilderArgs, args);
|
|
357
|
+
return {
|
|
358
|
+
...this.buildEntryInteractionBase(universal, componentId, experienceId, variantIndex),
|
|
359
|
+
type: 'component_hover',
|
|
360
|
+
hoverId,
|
|
361
|
+
hoverDurationMs
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
buildFlagView(args) {
|
|
365
|
+
const { componentId, experienceId, variantIndex, viewId, viewDurationMs, ...universal } = (0, api_schemas_.parseWithFriendlyError)(FlagViewBuilderArgs, args);
|
|
366
|
+
return {
|
|
367
|
+
...this.buildEntryInteractionBase(universal, componentId, experienceId, variantIndex),
|
|
368
|
+
...void 0 === viewDurationMs ? {} : {
|
|
369
|
+
viewDurationMs
|
|
370
|
+
},
|
|
371
|
+
...void 0 === viewId ? {} : {
|
|
372
|
+
viewId
|
|
373
|
+
},
|
|
374
|
+
type: 'component',
|
|
375
|
+
componentType: 'Variable'
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
buildIdentify(args) {
|
|
379
|
+
const { traits = {}, userId, ...universal } = (0, api_schemas_.parseWithFriendlyError)(IdentifyBuilderArgs, args);
|
|
380
|
+
return {
|
|
381
|
+
...this.buildUniversalEventProperties(universal),
|
|
382
|
+
type: 'identify',
|
|
383
|
+
traits,
|
|
384
|
+
userId
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
buildPageView(args = {}) {
|
|
388
|
+
const { properties = {}, ...universal } = (0, api_schemas_.parseWithFriendlyError)(PageViewBuilderArgs, args);
|
|
389
|
+
const pageProperties = this.getPageProperties();
|
|
390
|
+
const merged = (0, object_namespaceObject.merge)({
|
|
391
|
+
...pageProperties,
|
|
392
|
+
title: pageProperties.title ?? DEFAULT_PAGE_PROPERTIES.title
|
|
393
|
+
}, properties);
|
|
394
|
+
const { context: { screen: _, ...universalContext }, ...universalProperties } = this.buildUniversalEventProperties(universal);
|
|
395
|
+
const context = (0, api_schemas_.parseWithFriendlyError)(api_schemas_.PageEventContext, universalContext);
|
|
396
|
+
return {
|
|
397
|
+
...universalProperties,
|
|
398
|
+
context,
|
|
399
|
+
type: 'page',
|
|
400
|
+
properties: merged
|
|
401
|
+
};
|
|
402
|
+
}
|
|
403
|
+
buildScreenView(args) {
|
|
404
|
+
const { name, properties, ...universal } = (0, api_schemas_.parseWithFriendlyError)(ScreenViewBuilderArgs, args);
|
|
405
|
+
const { context: { page: _, ...universalContext }, ...universalProperties } = this.buildUniversalEventProperties(universal);
|
|
406
|
+
const context = (0, api_schemas_.parseWithFriendlyError)(api_schemas_.ScreenEventContext, universalContext);
|
|
407
|
+
return {
|
|
408
|
+
...universalProperties,
|
|
409
|
+
context,
|
|
410
|
+
type: 'screen',
|
|
411
|
+
name,
|
|
412
|
+
properties
|
|
413
|
+
};
|
|
414
|
+
}
|
|
415
|
+
buildTrack(args) {
|
|
416
|
+
const { event, properties = {}, ...universal } = (0, api_schemas_.parseWithFriendlyError)(TrackBuilderArgs, args);
|
|
417
|
+
return {
|
|
418
|
+
...this.buildUniversalEventProperties(universal),
|
|
419
|
+
type: 'track',
|
|
420
|
+
event,
|
|
421
|
+
properties
|
|
422
|
+
};
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
const events_EventBuilder = EventBuilder;
|
|
426
|
+
class InterceptorManager {
|
|
427
|
+
interceptors = new Map();
|
|
428
|
+
nextId = 0;
|
|
429
|
+
add(interceptor) {
|
|
430
|
+
const { nextId: id } = this;
|
|
431
|
+
this.nextId += 1;
|
|
432
|
+
this.interceptors.set(id, interceptor);
|
|
433
|
+
return id;
|
|
434
|
+
}
|
|
435
|
+
remove(id) {
|
|
436
|
+
return this.interceptors.delete(id);
|
|
437
|
+
}
|
|
438
|
+
clear() {
|
|
439
|
+
this.interceptors.clear();
|
|
440
|
+
}
|
|
441
|
+
count() {
|
|
442
|
+
return this.interceptors.size;
|
|
443
|
+
}
|
|
444
|
+
async run(input) {
|
|
445
|
+
const fns = Array.from(this.interceptors.values());
|
|
446
|
+
let acc = input;
|
|
447
|
+
for (const fn of fns)acc = await fn((0, external_es_toolkit_namespaceObject.cloneDeep)(acc));
|
|
448
|
+
return acc;
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
const FlagsResolver = {
|
|
452
|
+
resolve (changes) {
|
|
453
|
+
if (!changes) return {};
|
|
454
|
+
return changes.reduce((acc, { key, value })=>{
|
|
455
|
+
const actualValue = 'object' == typeof value && null !== value && 'value' in value && 'object' == typeof value.value ? value.value : value;
|
|
456
|
+
acc[key] = actualValue;
|
|
749
457
|
return acc;
|
|
750
|
-
}
|
|
458
|
+
}, {});
|
|
751
459
|
}
|
|
752
|
-
}
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
#map;
|
|
765
|
-
constructor(defaultMap){
|
|
766
|
-
const map = new Map();
|
|
767
|
-
if (defaultMap) Object.entries(defaultMap).map(([scope, values])=>map.set(scope.length ? scope : void 0, new Set(values)));
|
|
768
|
-
this.#map = map;
|
|
769
|
-
}
|
|
770
|
-
isPresent(scope, value) {
|
|
771
|
-
return this.#map.get(scope)?.has(value) ?? false;
|
|
772
|
-
}
|
|
773
|
-
addValue(scope, value) {
|
|
774
|
-
const values = this.#map.get(scope);
|
|
775
|
-
if (values) values.add(value);
|
|
776
|
-
else this.#map.set(scope, new Set([
|
|
777
|
-
value
|
|
778
|
-
]));
|
|
779
|
-
}
|
|
780
|
-
removeValue(scope, value) {
|
|
781
|
-
this.#map.get(scope)?.delete(value);
|
|
782
|
-
}
|
|
783
|
-
reset(scope) {
|
|
784
|
-
if (void 0 !== scope) this.#map.get(scope)?.clear();
|
|
785
|
-
else this.#map.clear();
|
|
786
|
-
}
|
|
460
|
+
};
|
|
461
|
+
const resolvers_FlagsResolver = FlagsResolver;
|
|
462
|
+
const logger = (0, logger_namespaceObject.createScopedLogger)('Optimization');
|
|
463
|
+
const RESOLUTION_WARNING_BASE = 'Could not resolve Merge Tag value:';
|
|
464
|
+
const getAtPath = (value, path)=>{
|
|
465
|
+
if (!value || 'object' != typeof value) return;
|
|
466
|
+
if (!path) return value;
|
|
467
|
+
let current = value;
|
|
468
|
+
const segments = path.split('.').filter(Boolean);
|
|
469
|
+
for (const segment of segments){
|
|
470
|
+
if (!current || 'object' != typeof current && 'function' != typeof current) return;
|
|
471
|
+
current = Reflect.get(current, segment);
|
|
787
472
|
}
|
|
788
|
-
|
|
789
|
-
}
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
}
|
|
818
|
-
personalizeEntry(entry, personalizations) {
|
|
819
|
-
return resolvers.z8.resolve(entry, personalizations);
|
|
820
|
-
}
|
|
821
|
-
getMergeTagValue(embeddedEntryNodeTarget, profile) {
|
|
822
|
-
return resolvers.cv.resolve(embeddedEntryNodeTarget, profile);
|
|
823
|
-
}
|
|
473
|
+
return current;
|
|
474
|
+
};
|
|
475
|
+
const MergeTagValueResolver = {
|
|
476
|
+
normalizeSelectors (id) {
|
|
477
|
+
return id.split('_').map((_path, index, paths)=>{
|
|
478
|
+
const dotPath = paths.slice(0, index).join('.');
|
|
479
|
+
const underScorePath = paths.slice(index).join('_');
|
|
480
|
+
return [
|
|
481
|
+
dotPath,
|
|
482
|
+
underScorePath
|
|
483
|
+
].filter((path)=>'' !== path).join('.');
|
|
484
|
+
});
|
|
485
|
+
},
|
|
486
|
+
getValueFromProfile (id, profile) {
|
|
487
|
+
const selectors = MergeTagValueResolver.normalizeSelectors(id);
|
|
488
|
+
const matchingSelector = selectors.find((selector)=>getAtPath(profile, selector));
|
|
489
|
+
if (!matchingSelector) return;
|
|
490
|
+
const value = getAtPath(profile, matchingSelector);
|
|
491
|
+
if (!value || 'string' != typeof value && 'number' != typeof value && 'boolean' != typeof value) return;
|
|
492
|
+
return `${value}`;
|
|
493
|
+
},
|
|
494
|
+
resolve (mergeTagEntry, profile) {
|
|
495
|
+
if (!(0, api_schemas_.isMergeTagEntry)(mergeTagEntry)) return void logger.warn(`${RESOLUTION_WARNING_BASE} supplied entry is not a Merge Tag entry`);
|
|
496
|
+
const { fields: { nt_fallback: fallback } } = mergeTagEntry;
|
|
497
|
+
if (!api_schemas_.Profile.safeParse(profile).success) {
|
|
498
|
+
logger.warn(`${RESOLUTION_WARNING_BASE} no valid profile`);
|
|
499
|
+
return fallback;
|
|
500
|
+
}
|
|
501
|
+
return MergeTagValueResolver.getValueFromProfile(mergeTagEntry.fields.nt_mergetag_id, profile) ?? fallback;
|
|
824
502
|
}
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
}
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
assertValidReturnValue(kind, newValue);
|
|
945
|
-
if (0 === kind) init = newValue;
|
|
946
|
-
else if (1 === kind) {
|
|
947
|
-
init = newValue.init;
|
|
948
|
-
get = newValue.get || value.get;
|
|
949
|
-
set = newValue.set || value.set;
|
|
950
|
-
value = {
|
|
951
|
-
get: get,
|
|
952
|
-
set: set
|
|
953
|
-
};
|
|
954
|
-
} else value = newValue;
|
|
955
|
-
}
|
|
956
|
-
} else for(var i = decs.length - 1; i >= 0; i--){
|
|
957
|
-
var dec = decs[i];
|
|
958
|
-
newValue = memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
|
|
959
|
-
if (void 0 !== newValue) {
|
|
960
|
-
assertValidReturnValue(kind, newValue);
|
|
961
|
-
var newInit;
|
|
962
|
-
if (0 === kind) newInit = newValue;
|
|
963
|
-
else if (1 === kind) {
|
|
964
|
-
newInit = newValue.init;
|
|
965
|
-
get = newValue.get || value.get;
|
|
966
|
-
set = newValue.set || value.set;
|
|
967
|
-
value = {
|
|
968
|
-
get: get,
|
|
969
|
-
set: set
|
|
970
|
-
};
|
|
971
|
-
} else value = newValue;
|
|
972
|
-
if (void 0 !== newInit) if (void 0 === init) init = newInit;
|
|
973
|
-
else if ("function" == typeof init) init = [
|
|
974
|
-
init,
|
|
975
|
-
newInit
|
|
976
|
-
];
|
|
977
|
-
else init.push(newInit);
|
|
978
|
-
}
|
|
979
|
-
}
|
|
980
|
-
if (0 === kind || 1 === kind) {
|
|
981
|
-
if (void 0 === init) init = function(instance, init) {
|
|
982
|
-
return init;
|
|
983
|
-
};
|
|
984
|
-
else if ("function" != typeof init) {
|
|
985
|
-
var ownInitializers = init;
|
|
986
|
-
init = function(instance, init) {
|
|
987
|
-
var value = init;
|
|
988
|
-
for(var i = 0; i < ownInitializers.length; i++)value = ownInitializers[i].call(instance, value);
|
|
989
|
-
return value;
|
|
990
|
-
};
|
|
991
|
-
} else {
|
|
992
|
-
var originalInitializer = init;
|
|
993
|
-
init = function(instance, init) {
|
|
994
|
-
return originalInitializer.call(instance, init);
|
|
995
|
-
};
|
|
996
|
-
}
|
|
997
|
-
ret.push(init);
|
|
503
|
+
};
|
|
504
|
+
const resolvers_MergeTagValueResolver = MergeTagValueResolver;
|
|
505
|
+
const OptimizedEntryResolver_logger = (0, logger_namespaceObject.createScopedLogger)('Optimization');
|
|
506
|
+
const OptimizedEntryResolver_RESOLUTION_WARNING_BASE = 'Could not resolve optimized entry variant:';
|
|
507
|
+
function resolve(entry, selectedOptimizations) {
|
|
508
|
+
OptimizedEntryResolver_logger.debug(`Resolving optimized entry for baseline entry ${entry.sys.id}`);
|
|
509
|
+
if (!selectedOptimizations?.length) {
|
|
510
|
+
OptimizedEntryResolver_logger.warn(`${OptimizedEntryResolver_RESOLUTION_WARNING_BASE} no selectedOptimizations exist for the current profile`);
|
|
511
|
+
return {
|
|
512
|
+
entry
|
|
513
|
+
};
|
|
514
|
+
}
|
|
515
|
+
if (!(0, api_schemas_.isOptimizedEntry)(entry)) {
|
|
516
|
+
OptimizedEntryResolver_logger.warn(`${OptimizedEntryResolver_RESOLUTION_WARNING_BASE} entry ${entry.sys.id} is not optimized`);
|
|
517
|
+
return {
|
|
518
|
+
entry
|
|
519
|
+
};
|
|
520
|
+
}
|
|
521
|
+
const optimizationEntry = OptimizedEntryResolver.getOptimizationEntry({
|
|
522
|
+
optimizedEntry: entry,
|
|
523
|
+
selectedOptimizations
|
|
524
|
+
}, true);
|
|
525
|
+
if (!optimizationEntry) {
|
|
526
|
+
OptimizedEntryResolver_logger.warn(`${OptimizedEntryResolver_RESOLUTION_WARNING_BASE} could not find an optimization entry for ${entry.sys.id}`);
|
|
527
|
+
return {
|
|
528
|
+
entry
|
|
529
|
+
};
|
|
530
|
+
}
|
|
531
|
+
const selectedOptimization = OptimizedEntryResolver.getSelectedOptimization({
|
|
532
|
+
optimizationEntry,
|
|
533
|
+
selectedOptimizations
|
|
534
|
+
}, true);
|
|
535
|
+
const selectedVariantIndex = selectedOptimization?.variantIndex ?? 0;
|
|
536
|
+
if (0 === selectedVariantIndex) {
|
|
537
|
+
OptimizedEntryResolver_logger.debug(`Resolved optimization entry for entry ${entry.sys.id} is baseline`);
|
|
538
|
+
return {
|
|
539
|
+
entry
|
|
540
|
+
};
|
|
541
|
+
}
|
|
542
|
+
const selectedVariant = OptimizedEntryResolver.getSelectedVariant({
|
|
543
|
+
optimizedEntry: entry,
|
|
544
|
+
optimizationEntry,
|
|
545
|
+
selectedVariantIndex
|
|
546
|
+
}, true);
|
|
547
|
+
if (!selectedVariant) {
|
|
548
|
+
OptimizedEntryResolver_logger.warn(`${OptimizedEntryResolver_RESOLUTION_WARNING_BASE} could not find a valid replacement variant entry for ${entry.sys.id}`);
|
|
549
|
+
return {
|
|
550
|
+
entry
|
|
551
|
+
};
|
|
552
|
+
}
|
|
553
|
+
const selectedVariantEntry = OptimizedEntryResolver.getSelectedVariantEntry({
|
|
554
|
+
optimizationEntry,
|
|
555
|
+
selectedVariant
|
|
556
|
+
}, true);
|
|
557
|
+
if (selectedVariantEntry) OptimizedEntryResolver_logger.debug(`Entry ${entry.sys.id} has been resolved to variant entry ${selectedVariantEntry.sys.id}`);
|
|
558
|
+
else {
|
|
559
|
+
OptimizedEntryResolver_logger.warn(`${OptimizedEntryResolver_RESOLUTION_WARNING_BASE} could not find a valid replacement variant entry for ${entry.sys.id}`);
|
|
560
|
+
return {
|
|
561
|
+
entry
|
|
562
|
+
};
|
|
563
|
+
}
|
|
564
|
+
return {
|
|
565
|
+
entry: selectedVariantEntry,
|
|
566
|
+
selectedOptimization
|
|
567
|
+
};
|
|
568
|
+
}
|
|
569
|
+
const OptimizedEntryResolver = {
|
|
570
|
+
getOptimizationEntry ({ optimizedEntry, selectedOptimizations }, skipValidation = false) {
|
|
571
|
+
if (!skipValidation && (!selectedOptimizations.length || !(0, api_schemas_.isOptimizedEntry)(optimizedEntry))) return;
|
|
572
|
+
const optimizationEntry = optimizedEntry.fields.nt_experiences.filter((maybeOptimization)=>(0, api_schemas_.isOptimizationEntry)(maybeOptimization)).find((optimizationEntry)=>selectedOptimizations.some(({ experienceId })=>experienceId === optimizationEntry.fields.nt_experience_id));
|
|
573
|
+
return optimizationEntry;
|
|
574
|
+
},
|
|
575
|
+
getSelectedOptimization ({ optimizationEntry, selectedOptimizations }, skipValidation = false) {
|
|
576
|
+
if (!skipValidation && (!selectedOptimizations.length || !(0, api_schemas_.isOptimizationEntry)(optimizationEntry))) return;
|
|
577
|
+
const selectedOptimization = selectedOptimizations.find(({ experienceId })=>experienceId === optimizationEntry.fields.nt_experience_id);
|
|
578
|
+
return selectedOptimization;
|
|
579
|
+
},
|
|
580
|
+
getSelectedVariant ({ optimizedEntry, optimizationEntry, selectedVariantIndex }, skipValidation = false) {
|
|
581
|
+
if (!skipValidation && (!(0, api_schemas_.isOptimizedEntry)(optimizedEntry) || !(0, api_schemas_.isOptimizationEntry)(optimizationEntry))) return;
|
|
582
|
+
const relevantVariants = (0, api_schemas_.normalizeOptimizationConfig)(optimizationEntry.fields.nt_config).components.filter((component)=>(0, api_schemas_.isEntryReplacementComponent)(component) && !component.baseline.hidden).find((component)=>component.baseline.id === optimizedEntry.sys.id)?.variants;
|
|
583
|
+
if (!relevantVariants?.length) return;
|
|
584
|
+
return relevantVariants.at(selectedVariantIndex - 1);
|
|
585
|
+
},
|
|
586
|
+
getSelectedVariantEntry ({ optimizationEntry, selectedVariant }, skipValidation = false) {
|
|
587
|
+
if (!skipValidation && (!(0, api_schemas_.isOptimizationEntry)(optimizationEntry) || !(0, api_schemas_.isEntryReplacementVariant)(selectedVariant))) return;
|
|
588
|
+
const selectedVariantEntry = optimizationEntry.fields.nt_variants?.find((variant)=>variant.sys.id === selectedVariant.id);
|
|
589
|
+
return (0, api_schemas_.isEntry)(selectedVariantEntry) ? selectedVariantEntry : void 0;
|
|
590
|
+
},
|
|
591
|
+
resolve
|
|
592
|
+
};
|
|
593
|
+
const resolvers_OptimizedEntryResolver = OptimizedEntryResolver;
|
|
594
|
+
class CoreBase {
|
|
595
|
+
api;
|
|
596
|
+
eventBuilder;
|
|
597
|
+
config;
|
|
598
|
+
flagsResolver = resolvers_FlagsResolver;
|
|
599
|
+
mergeTagValueResolver = resolvers_MergeTagValueResolver;
|
|
600
|
+
optimizedEntryResolver = resolvers_OptimizedEntryResolver;
|
|
601
|
+
interceptors = {
|
|
602
|
+
event: new InterceptorManager(),
|
|
603
|
+
state: new InterceptorManager()
|
|
604
|
+
};
|
|
605
|
+
constructor(config, api = {}){
|
|
606
|
+
this.config = config;
|
|
607
|
+
const { eventBuilder, logLevel, environment, clientId, fetchOptions } = config;
|
|
608
|
+
logger_namespaceObject.logger.addSink(new logger_namespaceObject.ConsoleLogSink(logLevel));
|
|
609
|
+
const apiConfig = {
|
|
610
|
+
clientId,
|
|
611
|
+
environment,
|
|
612
|
+
fetchOptions,
|
|
613
|
+
experience: api.experience,
|
|
614
|
+
insights: api.insights
|
|
615
|
+
};
|
|
616
|
+
this.api = new optimization_api_client_namespaceObject.ApiClient(apiConfig);
|
|
617
|
+
this.eventBuilder = new events_EventBuilder(eventBuilder ?? {
|
|
618
|
+
channel: 'server',
|
|
619
|
+
library: {
|
|
620
|
+
name: constants.OPTIMIZATION_CORE_SDK_NAME,
|
|
621
|
+
version: constants.OPTIMIZATION_CORE_SDK_VERSION
|
|
998
622
|
}
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
623
|
+
});
|
|
624
|
+
}
|
|
625
|
+
getFlag(name, changes) {
|
|
626
|
+
return this.flagsResolver.resolve(changes)[name];
|
|
627
|
+
}
|
|
628
|
+
resolveOptimizedEntry(entry, selectedOptimizations) {
|
|
629
|
+
return this.optimizedEntryResolver.resolve(entry, selectedOptimizations);
|
|
630
|
+
}
|
|
631
|
+
getMergeTagValue(embeddedEntryNodeTarget, profile) {
|
|
632
|
+
return this.mergeTagValueResolver.resolve(embeddedEntryNodeTarget, profile);
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
const src_CoreBase = CoreBase;
|
|
636
|
+
const predicate_namespaceObject = require("es-toolkit/predicate");
|
|
637
|
+
const coreLogger = (0, logger_namespaceObject.createScopedLogger)('CoreStateful');
|
|
638
|
+
const CONSENT_EVENT_TYPE_MAP = {
|
|
639
|
+
trackView: 'component',
|
|
640
|
+
trackFlagView: 'component',
|
|
641
|
+
trackClick: 'component_click',
|
|
642
|
+
trackHover: 'component_hover'
|
|
643
|
+
};
|
|
644
|
+
class CoreStatefulEventEmitter extends src_CoreBase {
|
|
645
|
+
flagObservables = new Map();
|
|
646
|
+
getFlag(name, changes = signals_changes.value) {
|
|
647
|
+
const value = super.getFlag(name, changes);
|
|
648
|
+
const payload = this.buildFlagViewBuilderArgs(name, changes);
|
|
649
|
+
this.trackFlagView(payload).catch((error)=>{
|
|
650
|
+
logger_namespaceObject.logger.warn(`Failed to emit "flag view" event for "${name}"`, String(error));
|
|
651
|
+
});
|
|
652
|
+
return value;
|
|
653
|
+
}
|
|
654
|
+
resolveOptimizedEntry(entry, selectedOptimizations = signals_selectedOptimizations.value) {
|
|
655
|
+
return super.resolveOptimizedEntry(entry, selectedOptimizations);
|
|
656
|
+
}
|
|
657
|
+
getMergeTagValue(embeddedEntryNodeTarget, profile = signals_profile.value) {
|
|
658
|
+
return super.getMergeTagValue(embeddedEntryNodeTarget, profile);
|
|
659
|
+
}
|
|
660
|
+
async identify(payload) {
|
|
661
|
+
const { profile, ...builderArgs } = payload;
|
|
662
|
+
return await this.sendExperienceEvent('identify', [
|
|
663
|
+
payload
|
|
664
|
+
], this.eventBuilder.buildIdentify(builderArgs), profile);
|
|
665
|
+
}
|
|
666
|
+
async page(payload = {}) {
|
|
667
|
+
const { profile, ...builderArgs } = payload;
|
|
668
|
+
return await this.sendExperienceEvent('page', [
|
|
669
|
+
payload
|
|
670
|
+
], this.eventBuilder.buildPageView(builderArgs), profile);
|
|
671
|
+
}
|
|
672
|
+
async screen(payload) {
|
|
673
|
+
const { profile, ...builderArgs } = payload;
|
|
674
|
+
return await this.sendExperienceEvent('screen', [
|
|
675
|
+
payload
|
|
676
|
+
], this.eventBuilder.buildScreenView(builderArgs), profile);
|
|
677
|
+
}
|
|
678
|
+
async track(payload) {
|
|
679
|
+
const { profile, ...builderArgs } = payload;
|
|
680
|
+
return await this.sendExperienceEvent('track', [
|
|
681
|
+
payload
|
|
682
|
+
], this.eventBuilder.buildTrack(builderArgs), profile);
|
|
683
|
+
}
|
|
684
|
+
async trackView(payload) {
|
|
685
|
+
const { profile, ...builderArgs } = payload;
|
|
686
|
+
let result;
|
|
687
|
+
if (payload.sticky) result = await this.sendExperienceEvent('trackView', [
|
|
688
|
+
payload
|
|
689
|
+
], this.eventBuilder.buildView(builderArgs), profile);
|
|
690
|
+
await this.sendInsightsEvent('trackView', [
|
|
691
|
+
payload
|
|
692
|
+
], this.eventBuilder.buildView(builderArgs), profile);
|
|
693
|
+
return result;
|
|
694
|
+
}
|
|
695
|
+
async trackClick(payload) {
|
|
696
|
+
await this.sendInsightsEvent('trackClick', [
|
|
697
|
+
payload
|
|
698
|
+
], this.eventBuilder.buildClick(payload));
|
|
699
|
+
}
|
|
700
|
+
async trackHover(payload) {
|
|
701
|
+
await this.sendInsightsEvent('trackHover', [
|
|
702
|
+
payload
|
|
703
|
+
], this.eventBuilder.buildHover(payload));
|
|
704
|
+
}
|
|
705
|
+
async trackFlagView(payload) {
|
|
706
|
+
await this.sendInsightsEvent('trackFlagView', [
|
|
707
|
+
payload
|
|
708
|
+
], this.eventBuilder.buildFlagView(payload));
|
|
709
|
+
}
|
|
710
|
+
hasConsent(name) {
|
|
711
|
+
const { [name]: mappedEventType } = CONSENT_EVENT_TYPE_MAP;
|
|
712
|
+
const isAllowed = void 0 !== mappedEventType ? this.allowedEventTypes.includes(mappedEventType) : this.allowedEventTypes.some((eventType)=>eventType === name);
|
|
713
|
+
return !!consent.value || isAllowed;
|
|
714
|
+
}
|
|
715
|
+
onBlockedByConsent(name, args) {
|
|
716
|
+
coreLogger.warn(`Event "${name}" was blocked due to lack of consent; payload: ${JSON.stringify(args)}`);
|
|
717
|
+
this.reportBlockedEvent('consent', name, args);
|
|
718
|
+
}
|
|
719
|
+
async sendExperienceEvent(method, args, event, _profile) {
|
|
720
|
+
if (!this.hasConsent(method)) return void this.onBlockedByConsent(method, args);
|
|
721
|
+
return await this.experienceQueue.send(event);
|
|
722
|
+
}
|
|
723
|
+
async sendInsightsEvent(method, args, event, _profile) {
|
|
724
|
+
if (!this.hasConsent(method)) return void this.onBlockedByConsent(method, args);
|
|
725
|
+
await this.insightsQueue.send(event);
|
|
726
|
+
}
|
|
727
|
+
buildFlagViewBuilderArgs(name, changes = signals_changes.value) {
|
|
728
|
+
const change = changes?.find((candidate)=>candidate.key === name);
|
|
729
|
+
return {
|
|
730
|
+
componentId: name,
|
|
731
|
+
experienceId: change?.meta.experienceId,
|
|
732
|
+
variantIndex: change?.meta.variantIndex
|
|
733
|
+
};
|
|
734
|
+
}
|
|
735
|
+
getFlagObservable(name) {
|
|
736
|
+
const existingObservable = this.flagObservables.get(name);
|
|
737
|
+
if (existingObservable) return existingObservable;
|
|
738
|
+
const trackFlagView = this.trackFlagView.bind(this);
|
|
739
|
+
const buildFlagViewBuilderArgs = this.buildFlagViewBuilderArgs.bind(this);
|
|
740
|
+
const valueSignal = signalFns.computed(()=>super.getFlag(name, signals_changes.value));
|
|
741
|
+
const distinctObservable = toDistinctObservable(valueSignal, predicate_namespaceObject.isEqual);
|
|
742
|
+
const trackedObservable = {
|
|
743
|
+
get current () {
|
|
744
|
+
const { current: value } = distinctObservable;
|
|
745
|
+
const payload = buildFlagViewBuilderArgs(name, signals_changes.value);
|
|
746
|
+
trackFlagView(payload).catch((error)=>{
|
|
747
|
+
logger_namespaceObject.logger.warn(`Failed to emit "flag view" event for "${name}"`, String(error));
|
|
748
|
+
});
|
|
749
|
+
return value;
|
|
750
|
+
},
|
|
751
|
+
subscribe: (next)=>distinctObservable.subscribe((value)=>{
|
|
752
|
+
const payload = buildFlagViewBuilderArgs(name, signals_changes.value);
|
|
753
|
+
trackFlagView(payload).catch((error)=>{
|
|
754
|
+
logger_namespaceObject.logger.warn(`Failed to emit "flag view" event for "${name}"`, String(error));
|
|
1009
755
|
});
|
|
1010
|
-
|
|
1011
|
-
|
|
756
|
+
next(value);
|
|
757
|
+
}),
|
|
758
|
+
subscribeOnce: (next)=>distinctObservable.subscribeOnce((value)=>{
|
|
759
|
+
const payload = buildFlagViewBuilderArgs(name, signals_changes.value);
|
|
760
|
+
trackFlagView(payload).catch((error)=>{
|
|
761
|
+
logger_namespaceObject.logger.warn(`Failed to emit "flag view" event for "${name}"`, String(error));
|
|
1012
762
|
});
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
return value.call(instance, args);
|
|
1016
|
-
});
|
|
1017
|
-
else Object.defineProperty(base, name, desc);
|
|
1018
|
-
}
|
|
1019
|
-
}
|
|
1020
|
-
function applyMemberDecs(Class, decInfos, metadata) {
|
|
1021
|
-
var ret = [];
|
|
1022
|
-
var protoInitializers;
|
|
1023
|
-
var staticInitializers;
|
|
1024
|
-
var existingProtoNonFields = new Map();
|
|
1025
|
-
var existingStaticNonFields = new Map();
|
|
1026
|
-
for(var i = 0; i < decInfos.length; i++){
|
|
1027
|
-
var decInfo = decInfos[i];
|
|
1028
|
-
if (Array.isArray(decInfo)) {
|
|
1029
|
-
var kind = decInfo[1];
|
|
1030
|
-
var name = decInfo[2];
|
|
1031
|
-
var isPrivate = decInfo.length > 3;
|
|
1032
|
-
var isStatic = kind >= 5;
|
|
1033
|
-
var base;
|
|
1034
|
-
var initializers;
|
|
1035
|
-
if (isStatic) {
|
|
1036
|
-
base = Class;
|
|
1037
|
-
kind -= 5;
|
|
1038
|
-
staticInitializers = staticInitializers || [];
|
|
1039
|
-
initializers = staticInitializers;
|
|
1040
|
-
} else {
|
|
1041
|
-
base = Class.prototype;
|
|
1042
|
-
protoInitializers = protoInitializers || [];
|
|
1043
|
-
initializers = protoInitializers;
|
|
1044
|
-
}
|
|
1045
|
-
if (0 !== kind && !isPrivate) {
|
|
1046
|
-
var existingNonFields = isStatic ? existingStaticNonFields : existingProtoNonFields;
|
|
1047
|
-
var existingKind = existingNonFields.get(name) || 0;
|
|
1048
|
-
if (true === existingKind || 3 === existingKind && 4 !== kind || 4 === existingKind && 3 !== kind) throw new Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: " + name);
|
|
1049
|
-
if (!existingKind && kind > 2) existingNonFields.set(name, kind);
|
|
1050
|
-
else existingNonFields.set(name, true);
|
|
1051
|
-
}
|
|
1052
|
-
applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata);
|
|
1053
|
-
}
|
|
1054
|
-
}
|
|
1055
|
-
pushInitializers(ret, protoInitializers);
|
|
1056
|
-
pushInitializers(ret, staticInitializers);
|
|
1057
|
-
return ret;
|
|
1058
|
-
}
|
|
1059
|
-
function pushInitializers(ret, initializers) {
|
|
1060
|
-
if (initializers) ret.push(function(instance) {
|
|
1061
|
-
for(var i = 0; i < initializers.length; i++)initializers[i].call(instance);
|
|
1062
|
-
return instance;
|
|
1063
|
-
});
|
|
1064
|
-
}
|
|
1065
|
-
function applyClassDecs(targetClass, classDecs, metadata) {
|
|
1066
|
-
if (classDecs.length > 0) {
|
|
1067
|
-
var initializers = [];
|
|
1068
|
-
var newClass = targetClass;
|
|
1069
|
-
var name = targetClass.name;
|
|
1070
|
-
for(var i = classDecs.length - 1; i >= 0; i--){
|
|
1071
|
-
var decoratorFinishedRef = {
|
|
1072
|
-
v: false
|
|
1073
|
-
};
|
|
1074
|
-
try {
|
|
1075
|
-
var nextNewClass = classDecs[i](newClass, {
|
|
1076
|
-
kind: "class",
|
|
1077
|
-
name: name,
|
|
1078
|
-
addInitializer: createAddInitializerMethod(initializers, decoratorFinishedRef),
|
|
1079
|
-
metadata
|
|
1080
|
-
});
|
|
1081
|
-
} finally{
|
|
1082
|
-
decoratorFinishedRef.v = true;
|
|
1083
|
-
}
|
|
1084
|
-
if (void 0 !== nextNewClass) {
|
|
1085
|
-
assertValidReturnValue(10, nextNewClass);
|
|
1086
|
-
newClass = nextNewClass;
|
|
1087
|
-
}
|
|
1088
|
-
}
|
|
1089
|
-
return [
|
|
1090
|
-
defineMetadata(newClass, metadata),
|
|
1091
|
-
function() {
|
|
1092
|
-
for(var i = 0; i < initializers.length; i++)initializers[i].call(newClass);
|
|
1093
|
-
}
|
|
1094
|
-
];
|
|
1095
|
-
}
|
|
1096
|
-
}
|
|
1097
|
-
function defineMetadata(Class, metadata) {
|
|
1098
|
-
return Object.defineProperty(Class, Symbol.metadata || Symbol.for("Symbol.metadata"), {
|
|
1099
|
-
configurable: true,
|
|
1100
|
-
enumerable: true,
|
|
1101
|
-
value: metadata
|
|
1102
|
-
});
|
|
1103
|
-
}
|
|
1104
|
-
return function(targetClass, memberDecs, classDecs, parentClass) {
|
|
1105
|
-
if (void 0 !== parentClass) var parentMetadata = parentClass[Symbol.metadata || Symbol.for("Symbol.metadata")];
|
|
1106
|
-
var metadata = Object.create(void 0 === parentMetadata ? null : parentMetadata);
|
|
1107
|
-
var e = applyMemberDecs(targetClass, memberDecs, metadata);
|
|
1108
|
-
if (!classDecs.length) defineMetadata(targetClass, metadata);
|
|
1109
|
-
return {
|
|
1110
|
-
e: e,
|
|
1111
|
-
get c () {
|
|
1112
|
-
return applyClassDecs(targetClass, classDecs, metadata);
|
|
1113
|
-
}
|
|
1114
|
-
};
|
|
763
|
+
next(value);
|
|
764
|
+
})
|
|
1115
765
|
};
|
|
766
|
+
this.flagObservables.set(name, trackedObservable);
|
|
767
|
+
return trackedObservable;
|
|
1116
768
|
}
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
_dec = (0, guardedBy.i)('hasConsent', {
|
|
1123
|
-
onBlocked: 'onBlockedByConsent'
|
|
1124
|
-
}), _dec1 = (0, guardedBy.i)('hasConsent', {
|
|
1125
|
-
onBlocked: 'onBlockedByConsent'
|
|
1126
|
-
}), _dec2 = (0, guardedBy.i)('hasConsent', {
|
|
1127
|
-
onBlocked: 'onBlockedByConsent'
|
|
1128
|
-
}), _dec3 = (0, guardedBy.i)('hasConsent', {
|
|
1129
|
-
onBlocked: 'onBlockedByConsent'
|
|
1130
|
-
}), _dec4 = (0, guardedBy.i)('isNotDuplicated', {
|
|
1131
|
-
onBlocked: 'onBlockedByDuplication'
|
|
1132
|
-
}), _dec5 = (0, guardedBy.i)('hasConsent', {
|
|
1133
|
-
onBlocked: 'onBlockedByConsent'
|
|
1134
|
-
});
|
|
1135
|
-
class PersonalizationStateful extends personalization_PersonalizationBase {
|
|
1136
|
-
static{
|
|
1137
|
-
({ e: [_initProto] } = _apply_decs_2203_r(this, [
|
|
1138
|
-
[
|
|
1139
|
-
_dec,
|
|
1140
|
-
2,
|
|
1141
|
-
"identify"
|
|
1142
|
-
],
|
|
1143
|
-
[
|
|
1144
|
-
_dec1,
|
|
1145
|
-
2,
|
|
1146
|
-
"page"
|
|
1147
|
-
],
|
|
1148
|
-
[
|
|
1149
|
-
_dec2,
|
|
1150
|
-
2,
|
|
1151
|
-
"screen"
|
|
1152
|
-
],
|
|
1153
|
-
[
|
|
1154
|
-
_dec3,
|
|
1155
|
-
2,
|
|
1156
|
-
"track"
|
|
1157
|
-
],
|
|
1158
|
-
[
|
|
1159
|
-
[
|
|
1160
|
-
_dec4,
|
|
1161
|
-
_dec5
|
|
1162
|
-
],
|
|
1163
|
-
2,
|
|
1164
|
-
"trackComponentView"
|
|
1165
|
-
]
|
|
1166
|
-
], []));
|
|
1167
|
-
}
|
|
1168
|
-
offlineQueue = (_initProto(this), new Set());
|
|
1169
|
-
states = {
|
|
1170
|
-
eventStream: (0, signals.br)(signals.f0),
|
|
1171
|
-
flags: (0, signals.br)(signals.Mv),
|
|
1172
|
-
profile: (0, signals.br)(signals.ME),
|
|
1173
|
-
personalizations: (0, signals.br)(signals.wh)
|
|
769
|
+
reportBlockedEvent(reason, method, args) {
|
|
770
|
+
const event = {
|
|
771
|
+
reason,
|
|
772
|
+
method,
|
|
773
|
+
args
|
|
1174
774
|
};
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
api,
|
|
1180
|
-
builder,
|
|
1181
|
-
config,
|
|
1182
|
-
interceptors
|
|
1183
|
-
});
|
|
1184
|
-
const { defaults, getAnonymousId } = config ?? {};
|
|
1185
|
-
if (defaults) {
|
|
1186
|
-
const { changes: defaultChanges, personalizations: defaultPersonalizations, profile: defaultProfile } = defaults;
|
|
1187
|
-
(0, signals.vA)(()=>{
|
|
1188
|
-
signals.Ao.value = defaultChanges;
|
|
1189
|
-
signals.wh.value = defaultPersonalizations;
|
|
1190
|
-
signals.ME.value = defaultProfile;
|
|
1191
|
-
});
|
|
1192
|
-
}
|
|
1193
|
-
if (defaults?.consent !== void 0) {
|
|
1194
|
-
const { consent: defaultConsent } = defaults;
|
|
1195
|
-
signals.vJ.value = defaultConsent;
|
|
1196
|
-
}
|
|
1197
|
-
this.getAnonymousId = getAnonymousId ?? (()=>void 0);
|
|
1198
|
-
(0, signals.QZ)(()=>{
|
|
1199
|
-
logger.debug(`Profile ${signals.ME.value && `with ID ${signals.ME.value.id}`} has been ${signals.ME.value ? 'set' : 'cleared'}`);
|
|
1200
|
-
});
|
|
1201
|
-
(0, signals.QZ)(()=>{
|
|
1202
|
-
logger.debug(`Variants have been ${signals.wh.value?.length ? 'populated' : 'cleared'}`);
|
|
1203
|
-
});
|
|
1204
|
-
(0, signals.QZ)(()=>{
|
|
1205
|
-
logger.info(`Personalization ${signals.vJ.value ? 'will' : 'will not'} take effect due to consent (${signals.vJ.value})`);
|
|
1206
|
-
});
|
|
1207
|
-
(0, signals.QZ)(()=>{
|
|
1208
|
-
if (signals.WD.value) this.flush();
|
|
1209
|
-
});
|
|
775
|
+
try {
|
|
776
|
+
this.onEventBlocked?.(event);
|
|
777
|
+
} catch (error) {
|
|
778
|
+
coreLogger.warn(`onEventBlocked callback failed for method "${method}"`, error);
|
|
1210
779
|
}
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
780
|
+
blockedEvent.value = event;
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
const src_CoreStatefulEventEmitter = CoreStatefulEventEmitter;
|
|
784
|
+
const toPositiveInt = (value, fallback)=>{
|
|
785
|
+
if (!Number.isFinite(value) || void 0 === value || value < 1) return fallback;
|
|
786
|
+
return Math.floor(value);
|
|
787
|
+
};
|
|
788
|
+
const toRatio = (value, fallback)=>{
|
|
789
|
+
if (!Number.isFinite(value) || void 0 === value) return fallback;
|
|
790
|
+
return Math.min(1, Math.max(0, value));
|
|
791
|
+
};
|
|
792
|
+
const DEFAULT_QUEUE_FLUSH_POLICY = {
|
|
793
|
+
flushIntervalMs: 30000,
|
|
794
|
+
baseBackoffMs: 500,
|
|
795
|
+
maxBackoffMs: 30000,
|
|
796
|
+
jitterRatio: 0.2,
|
|
797
|
+
maxConsecutiveFailures: 8,
|
|
798
|
+
circuitOpenMs: 120000
|
|
799
|
+
};
|
|
800
|
+
const resolveQueueFlushPolicy = (policy, defaults = DEFAULT_QUEUE_FLUSH_POLICY)=>{
|
|
801
|
+
const configuredPolicy = policy ?? {};
|
|
802
|
+
const baseBackoffMs = toPositiveInt(configuredPolicy.baseBackoffMs, defaults.baseBackoffMs);
|
|
803
|
+
const maxBackoffMs = Math.max(baseBackoffMs, toPositiveInt(configuredPolicy.maxBackoffMs, defaults.maxBackoffMs));
|
|
804
|
+
return {
|
|
805
|
+
flushIntervalMs: toPositiveInt(configuredPolicy.flushIntervalMs, defaults.flushIntervalMs),
|
|
806
|
+
baseBackoffMs,
|
|
807
|
+
maxBackoffMs,
|
|
808
|
+
jitterRatio: toRatio(configuredPolicy.jitterRatio, defaults.jitterRatio),
|
|
809
|
+
maxConsecutiveFailures: toPositiveInt(configuredPolicy.maxConsecutiveFailures, defaults.maxConsecutiveFailures),
|
|
810
|
+
circuitOpenMs: toPositiveInt(configuredPolicy.circuitOpenMs, defaults.circuitOpenMs),
|
|
811
|
+
onCircuitOpen: configuredPolicy.onCircuitOpen,
|
|
812
|
+
onFlushFailure: configuredPolicy.onFlushFailure,
|
|
813
|
+
onFlushRecovered: configuredPolicy.onFlushRecovered
|
|
814
|
+
};
|
|
815
|
+
};
|
|
816
|
+
const computeQueueFlushRetryDelayMs = (options)=>{
|
|
817
|
+
const { consecutiveFailures, policy: { baseBackoffMs, jitterRatio, maxBackoffMs } } = options;
|
|
818
|
+
const exponential = baseBackoffMs * 2 ** Math.max(0, consecutiveFailures - 1);
|
|
819
|
+
const capped = Math.min(maxBackoffMs, exponential);
|
|
820
|
+
const jitter = capped * jitterRatio * Math.random();
|
|
821
|
+
return Math.round(capped + jitter);
|
|
822
|
+
};
|
|
823
|
+
const createQueueFlushFailureWindow = (options)=>{
|
|
824
|
+
const { consecutiveFailures, failureTimestamp, retryDelayMs, policy: { maxConsecutiveFailures, circuitOpenMs } } = options;
|
|
825
|
+
if (consecutiveFailures < maxConsecutiveFailures) return {
|
|
826
|
+
openedCircuit: false,
|
|
827
|
+
retryDelayMs,
|
|
828
|
+
nextFlushAllowedAt: failureTimestamp + retryDelayMs,
|
|
829
|
+
circuitOpenUntil: 0
|
|
830
|
+
};
|
|
831
|
+
const circuitOpenUntil = failureTimestamp + circuitOpenMs;
|
|
832
|
+
return {
|
|
833
|
+
openedCircuit: true,
|
|
834
|
+
retryDelayMs: circuitOpenMs,
|
|
835
|
+
nextFlushAllowedAt: circuitOpenUntil,
|
|
836
|
+
circuitOpenUntil
|
|
837
|
+
};
|
|
838
|
+
};
|
|
839
|
+
const STATEFUL_RUNTIME_LOCK_KEY = '__ctfl_optimization_stateful_runtime_lock__';
|
|
840
|
+
const getStatefulRuntimeLock = ()=>{
|
|
841
|
+
const singletonGlobal = globalThis;
|
|
842
|
+
singletonGlobal[STATEFUL_RUNTIME_LOCK_KEY] ??= {
|
|
843
|
+
owner: void 0
|
|
844
|
+
};
|
|
845
|
+
return singletonGlobal[STATEFUL_RUNTIME_LOCK_KEY];
|
|
846
|
+
};
|
|
847
|
+
const acquireStatefulRuntimeSingleton = (owner)=>{
|
|
848
|
+
const lock = getStatefulRuntimeLock();
|
|
849
|
+
if (lock.owner) throw new Error(`Stateful Optimization SDK already initialized (${lock.owner}). Only one stateful instance is supported per runtime.`);
|
|
850
|
+
lock.owner = owner;
|
|
851
|
+
};
|
|
852
|
+
const releaseStatefulRuntimeSingleton = (owner)=>{
|
|
853
|
+
const lock = getStatefulRuntimeLock();
|
|
854
|
+
if (lock.owner === owner) lock.owner = void 0;
|
|
855
|
+
};
|
|
856
|
+
class QueueFlushRuntime {
|
|
857
|
+
circuitOpenUntil = 0;
|
|
858
|
+
flushFailureCount = 0;
|
|
859
|
+
flushInFlight = false;
|
|
860
|
+
nextFlushAllowedAt = 0;
|
|
861
|
+
onCallbackError;
|
|
862
|
+
onRetry;
|
|
863
|
+
policy;
|
|
864
|
+
retryTimer;
|
|
865
|
+
constructor(options){
|
|
866
|
+
const { onCallbackError, onRetry, policy } = options;
|
|
867
|
+
this.policy = policy;
|
|
868
|
+
this.onRetry = onRetry;
|
|
869
|
+
this.onCallbackError = onCallbackError;
|
|
870
|
+
}
|
|
871
|
+
reset() {
|
|
872
|
+
this.clearScheduledRetry();
|
|
873
|
+
this.circuitOpenUntil = 0;
|
|
874
|
+
this.flushFailureCount = 0;
|
|
875
|
+
this.flushInFlight = false;
|
|
876
|
+
this.nextFlushAllowedAt = 0;
|
|
877
|
+
}
|
|
878
|
+
clearScheduledRetry() {
|
|
879
|
+
if (void 0 === this.retryTimer) return;
|
|
880
|
+
clearTimeout(this.retryTimer);
|
|
881
|
+
this.retryTimer = void 0;
|
|
882
|
+
}
|
|
883
|
+
shouldSkip(options) {
|
|
884
|
+
const { force, isOnline } = options;
|
|
885
|
+
if (this.flushInFlight) return true;
|
|
886
|
+
if (force) return false;
|
|
887
|
+
if (!isOnline) return true;
|
|
888
|
+
const now = Date.now();
|
|
889
|
+
if (this.nextFlushAllowedAt > now) return true;
|
|
890
|
+
if (this.circuitOpenUntil > now) return true;
|
|
891
|
+
return false;
|
|
892
|
+
}
|
|
893
|
+
markFlushStarted() {
|
|
894
|
+
this.flushInFlight = true;
|
|
895
|
+
}
|
|
896
|
+
markFlushFinished() {
|
|
897
|
+
this.flushInFlight = false;
|
|
898
|
+
}
|
|
899
|
+
handleFlushSuccess() {
|
|
900
|
+
const { flushFailureCount: previousConsecutiveFailures } = this;
|
|
901
|
+
this.clearScheduledRetry();
|
|
902
|
+
this.circuitOpenUntil = 0;
|
|
903
|
+
this.flushFailureCount = 0;
|
|
904
|
+
this.nextFlushAllowedAt = 0;
|
|
905
|
+
if (previousConsecutiveFailures <= 0) return;
|
|
906
|
+
this.safeInvoke('onFlushRecovered', {
|
|
907
|
+
consecutiveFailures: previousConsecutiveFailures
|
|
908
|
+
});
|
|
909
|
+
}
|
|
910
|
+
handleFlushFailure(options) {
|
|
911
|
+
const { queuedBatches, queuedEvents } = options;
|
|
912
|
+
this.flushFailureCount += 1;
|
|
913
|
+
const retryDelayMs = computeQueueFlushRetryDelayMs({
|
|
914
|
+
consecutiveFailures: this.flushFailureCount,
|
|
915
|
+
policy: this.policy
|
|
916
|
+
});
|
|
917
|
+
const failureTimestamp = Date.now();
|
|
918
|
+
const failureContext = {
|
|
919
|
+
consecutiveFailures: this.flushFailureCount,
|
|
920
|
+
queuedBatches,
|
|
921
|
+
queuedEvents,
|
|
922
|
+
retryDelayMs
|
|
923
|
+
};
|
|
924
|
+
this.safeInvoke('onFlushFailure', failureContext);
|
|
925
|
+
const failureWindow = createQueueFlushFailureWindow({
|
|
926
|
+
consecutiveFailures: this.flushFailureCount,
|
|
927
|
+
failureTimestamp,
|
|
928
|
+
retryDelayMs,
|
|
929
|
+
policy: this.policy
|
|
930
|
+
});
|
|
931
|
+
const { circuitOpenUntil, nextFlushAllowedAt, openedCircuit, retryDelayMs: scheduledRetryDelayMs } = failureWindow;
|
|
932
|
+
this.nextFlushAllowedAt = nextFlushAllowedAt;
|
|
933
|
+
if (openedCircuit) {
|
|
934
|
+
this.circuitOpenUntil = circuitOpenUntil;
|
|
935
|
+
this.safeInvoke('onCircuitOpen', {
|
|
936
|
+
...failureContext,
|
|
937
|
+
retryDelayMs: scheduledRetryDelayMs
|
|
1217
938
|
});
|
|
1218
939
|
}
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
const isDuplicated = this.duplicationDetector.isPresent(duplicationScope, value);
|
|
1237
|
-
if (!isDuplicated) this.duplicationDetector.addValue(duplicationScope, value);
|
|
1238
|
-
return !isDuplicated;
|
|
1239
|
-
}
|
|
1240
|
-
onBlockedByDuplication(_name, payload) {
|
|
1241
|
-
logger.debug(`Duplicate "component view" event detected, skipping; payload: ${JSON.stringify(payload)}`);
|
|
1242
|
-
}
|
|
1243
|
-
async identify(payload) {
|
|
1244
|
-
logger.info('Sending "identify" event');
|
|
1245
|
-
const event = this.builder.buildIdentify(payload);
|
|
1246
|
-
return await this.sendOrEnqueueEvent(event);
|
|
1247
|
-
}
|
|
1248
|
-
async page(payload) {
|
|
1249
|
-
logger.info('Sending "page" event');
|
|
1250
|
-
const event = this.builder.buildPageView(payload);
|
|
1251
|
-
return await this.sendOrEnqueueEvent(event);
|
|
1252
|
-
}
|
|
1253
|
-
async screen(payload) {
|
|
1254
|
-
logger.info(`Sending "screen" event for "${payload.name}"`);
|
|
1255
|
-
const event = this.builder.buildScreenView(payload);
|
|
1256
|
-
return await this.sendOrEnqueueEvent(event);
|
|
1257
|
-
}
|
|
1258
|
-
async track(payload) {
|
|
1259
|
-
logger.info(`Sending "track" event "${payload.event}"`);
|
|
1260
|
-
const event = this.builder.buildTrack(payload);
|
|
1261
|
-
return await this.sendOrEnqueueEvent(event);
|
|
1262
|
-
}
|
|
1263
|
-
async trackComponentView(payload, _duplicationScope = '') {
|
|
1264
|
-
logger.info(`Sending "track personalization" event for ${payload.componentId}`);
|
|
1265
|
-
const event = this.builder.buildComponentView(payload);
|
|
1266
|
-
return await this.sendOrEnqueueEvent(event);
|
|
1267
|
-
}
|
|
1268
|
-
async sendOrEnqueueEvent(event) {
|
|
1269
|
-
const intercepted = await this.interceptors.event.run(event);
|
|
1270
|
-
const validEvent = optimization_api_client_.ExperienceEvent.parse(intercepted);
|
|
1271
|
-
signals.f0.value = validEvent;
|
|
1272
|
-
if (signals.WD.value) return await this.upsertProfile([
|
|
1273
|
-
validEvent
|
|
1274
|
-
]);
|
|
1275
|
-
logger.debug(`Queueing ${validEvent.type} event`, validEvent);
|
|
1276
|
-
this.offlineQueue.add(validEvent);
|
|
1277
|
-
}
|
|
1278
|
-
async flush() {
|
|
1279
|
-
if (0 === this.offlineQueue.size) return;
|
|
1280
|
-
logger.debug('Flushing offline event queue');
|
|
1281
|
-
await this.upsertProfile(Array.from(this.offlineQueue));
|
|
1282
|
-
this.offlineQueue.clear();
|
|
1283
|
-
}
|
|
1284
|
-
async upsertProfile(events) {
|
|
1285
|
-
const anonymousId = this.getAnonymousId();
|
|
1286
|
-
if (anonymousId) logger.debug(`Anonymous ID found: ${anonymousId}`);
|
|
1287
|
-
const data = await this.api.experience.upsertProfile({
|
|
1288
|
-
profileId: anonymousId ?? signals.ME.value?.id,
|
|
1289
|
-
events
|
|
1290
|
-
});
|
|
1291
|
-
await this.updateOutputSignals(data);
|
|
1292
|
-
return data;
|
|
940
|
+
this.scheduleRetry(scheduledRetryDelayMs);
|
|
941
|
+
}
|
|
942
|
+
scheduleRetry(delayMs) {
|
|
943
|
+
this.clearScheduledRetry();
|
|
944
|
+
this.retryTimer = setTimeout(()=>{
|
|
945
|
+
this.retryTimer = void 0;
|
|
946
|
+
this.onRetry();
|
|
947
|
+
}, delayMs);
|
|
948
|
+
}
|
|
949
|
+
safeInvoke(...args) {
|
|
950
|
+
const [callbackName, payload] = args;
|
|
951
|
+
try {
|
|
952
|
+
if ('onFlushRecovered' === callbackName) return void this.policy.onFlushRecovered?.(payload);
|
|
953
|
+
if ('onCircuitOpen' === callbackName) return void this.policy.onCircuitOpen?.(payload);
|
|
954
|
+
this.policy.onFlushFailure?.(payload);
|
|
955
|
+
} catch (error) {
|
|
956
|
+
this.onCallbackError?.(callbackName, error);
|
|
1293
957
|
}
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
958
|
+
}
|
|
959
|
+
}
|
|
960
|
+
const ExperienceQueue_coreLogger = (0, logger_namespaceObject.createScopedLogger)('CoreStateful');
|
|
961
|
+
class ExperienceQueue {
|
|
962
|
+
experienceApi;
|
|
963
|
+
eventInterceptors;
|
|
964
|
+
flushRuntime;
|
|
965
|
+
getAnonymousId;
|
|
966
|
+
offlineMaxEvents;
|
|
967
|
+
onOfflineDrop;
|
|
968
|
+
queuedExperienceEvents = new Set();
|
|
969
|
+
stateInterceptors;
|
|
970
|
+
constructor(options){
|
|
971
|
+
const { experienceApi, eventInterceptors, flushPolicy, getAnonymousId, offlineMaxEvents, onOfflineDrop, stateInterceptors } = options;
|
|
972
|
+
this.experienceApi = experienceApi;
|
|
973
|
+
this.eventInterceptors = eventInterceptors;
|
|
974
|
+
this.getAnonymousId = getAnonymousId;
|
|
975
|
+
this.offlineMaxEvents = offlineMaxEvents;
|
|
976
|
+
this.onOfflineDrop = onOfflineDrop;
|
|
977
|
+
this.stateInterceptors = stateInterceptors;
|
|
978
|
+
this.flushRuntime = new QueueFlushRuntime({
|
|
979
|
+
policy: flushPolicy,
|
|
980
|
+
onRetry: ()=>{
|
|
981
|
+
this.flush();
|
|
982
|
+
},
|
|
983
|
+
onCallbackError: (callbackName, error)=>{
|
|
984
|
+
ExperienceQueue_coreLogger.warn(`Experience flush policy callback "${callbackName}" failed`, error);
|
|
985
|
+
}
|
|
986
|
+
});
|
|
987
|
+
}
|
|
988
|
+
clearScheduledRetry() {
|
|
989
|
+
this.flushRuntime.clearScheduledRetry();
|
|
990
|
+
}
|
|
991
|
+
async send(event) {
|
|
992
|
+
const intercepted = await this.eventInterceptors.run(event);
|
|
993
|
+
const validEvent = (0, api_schemas_.parseWithFriendlyError)(api_schemas_.ExperienceEvent, intercepted);
|
|
994
|
+
signals_event.value = validEvent;
|
|
995
|
+
if (online.value) return await this.upsertProfile([
|
|
996
|
+
validEvent
|
|
997
|
+
]);
|
|
998
|
+
ExperienceQueue_coreLogger.debug(`Queueing ${validEvent.type} event`, validEvent);
|
|
999
|
+
this.enqueueEvent(validEvent);
|
|
1000
|
+
}
|
|
1001
|
+
async flush(options = {}) {
|
|
1002
|
+
const { force = false } = options;
|
|
1003
|
+
if (this.flushRuntime.shouldSkip({
|
|
1004
|
+
force,
|
|
1005
|
+
isOnline: !!online.value
|
|
1006
|
+
})) return;
|
|
1007
|
+
if (0 === this.queuedExperienceEvents.size) return void this.flushRuntime.clearScheduledRetry();
|
|
1008
|
+
ExperienceQueue_coreLogger.debug('Flushing offline Experience event queue');
|
|
1009
|
+
const queuedEvents = Array.from(this.queuedExperienceEvents);
|
|
1010
|
+
this.flushRuntime.markFlushStarted();
|
|
1011
|
+
try {
|
|
1012
|
+
const sendSuccess = await this.tryUpsertQueuedEvents(queuedEvents);
|
|
1013
|
+
if (sendSuccess) {
|
|
1014
|
+
queuedEvents.forEach((queuedEvent)=>{
|
|
1015
|
+
this.queuedExperienceEvents.delete(queuedEvent);
|
|
1016
|
+
});
|
|
1017
|
+
this.flushRuntime.handleFlushSuccess();
|
|
1018
|
+
} else this.flushRuntime.handleFlushFailure({
|
|
1019
|
+
queuedBatches: this.queuedExperienceEvents.size > 0 ? 1 : 0,
|
|
1020
|
+
queuedEvents: this.queuedExperienceEvents.size
|
|
1301
1021
|
});
|
|
1022
|
+
} finally{
|
|
1023
|
+
this.flushRuntime.markFlushFinished();
|
|
1302
1024
|
}
|
|
1303
1025
|
}
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
const
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1026
|
+
enqueueEvent(event) {
|
|
1027
|
+
let droppedEvents = [];
|
|
1028
|
+
if (this.queuedExperienceEvents.size >= this.offlineMaxEvents) {
|
|
1029
|
+
const dropCount = this.queuedExperienceEvents.size - this.offlineMaxEvents + 1;
|
|
1030
|
+
droppedEvents = this.dropOldestEvents(dropCount);
|
|
1031
|
+
if (droppedEvents.length > 0) ExperienceQueue_coreLogger.warn(`Dropped ${droppedEvents.length} oldest offline event(s) due to queue limit (${this.offlineMaxEvents})`);
|
|
1032
|
+
}
|
|
1033
|
+
this.queuedExperienceEvents.add(event);
|
|
1034
|
+
if (droppedEvents.length > 0) this.invokeOfflineDropCallback({
|
|
1035
|
+
droppedCount: droppedEvents.length,
|
|
1036
|
+
droppedEvents,
|
|
1037
|
+
maxEvents: this.offlineMaxEvents,
|
|
1038
|
+
queuedEvents: this.queuedExperienceEvents.size
|
|
1039
|
+
});
|
|
1040
|
+
}
|
|
1041
|
+
dropOldestEvents(count) {
|
|
1042
|
+
const droppedEvents = [];
|
|
1043
|
+
for(let index = 0; index < count; index += 1){
|
|
1044
|
+
const oldestEvent = this.queuedExperienceEvents.values().next();
|
|
1045
|
+
if (oldestEvent.done) break;
|
|
1046
|
+
this.queuedExperienceEvents.delete(oldestEvent.value);
|
|
1047
|
+
droppedEvents.push(oldestEvent.value);
|
|
1048
|
+
}
|
|
1049
|
+
return droppedEvents;
|
|
1050
|
+
}
|
|
1051
|
+
invokeOfflineDropCallback(context) {
|
|
1052
|
+
try {
|
|
1053
|
+
this.onOfflineDrop?.(context);
|
|
1054
|
+
} catch (error) {
|
|
1055
|
+
ExperienceQueue_coreLogger.warn('Offline queue drop callback failed', error);
|
|
1330
1056
|
}
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
return
|
|
1057
|
+
}
|
|
1058
|
+
async tryUpsertQueuedEvents(events) {
|
|
1059
|
+
try {
|
|
1060
|
+
await this.upsertProfile(events);
|
|
1061
|
+
return true;
|
|
1062
|
+
} catch (error) {
|
|
1063
|
+
ExperienceQueue_coreLogger.warn('Experience queue flush request threw an error', error);
|
|
1064
|
+
return false;
|
|
1336
1065
|
}
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1066
|
+
}
|
|
1067
|
+
async upsertProfile(events) {
|
|
1068
|
+
const anonymousId = this.getAnonymousId();
|
|
1069
|
+
if (anonymousId) ExperienceQueue_coreLogger.debug(`Anonymous ID found: ${anonymousId}`);
|
|
1070
|
+
const data = await this.experienceApi.upsertProfile({
|
|
1071
|
+
profileId: anonymousId ?? signals_profile.value?.id,
|
|
1072
|
+
events
|
|
1073
|
+
});
|
|
1074
|
+
await this.updateOutputSignals(data);
|
|
1075
|
+
return data;
|
|
1076
|
+
}
|
|
1077
|
+
async updateOutputSignals(data) {
|
|
1078
|
+
const intercepted = await this.stateInterceptors.run(data);
|
|
1079
|
+
const { changes, profile, selectedOptimizations } = intercepted;
|
|
1080
|
+
(0, signals_core_namespaceObject.batch)(()=>{
|
|
1081
|
+
if (!(0, predicate_namespaceObject.isEqual)(signals_changes.value, changes)) signals_changes.value = changes;
|
|
1082
|
+
if (!(0, predicate_namespaceObject.isEqual)(signals_profile.value, profile)) signals_profile.value = profile;
|
|
1083
|
+
if (!(0, predicate_namespaceObject.isEqual)(signals_selectedOptimizations.value, selectedOptimizations)) signals_selectedOptimizations.value = selectedOptimizations;
|
|
1084
|
+
});
|
|
1085
|
+
}
|
|
1086
|
+
}
|
|
1087
|
+
const InsightsQueue_coreLogger = (0, logger_namespaceObject.createScopedLogger)('CoreStateful');
|
|
1088
|
+
const MAX_QUEUED_INSIGHTS_EVENTS = 25;
|
|
1089
|
+
class InsightsQueue {
|
|
1090
|
+
eventInterceptors;
|
|
1091
|
+
flushIntervalMs;
|
|
1092
|
+
flushRuntime;
|
|
1093
|
+
insightsApi;
|
|
1094
|
+
queuedInsightsByProfile = new Map();
|
|
1095
|
+
insightsPeriodicFlushTimer;
|
|
1096
|
+
constructor(options){
|
|
1097
|
+
const { eventInterceptors, flushPolicy, insightsApi } = options;
|
|
1098
|
+
const { flushIntervalMs } = flushPolicy;
|
|
1099
|
+
this.eventInterceptors = eventInterceptors;
|
|
1100
|
+
this.flushIntervalMs = flushIntervalMs;
|
|
1101
|
+
this.insightsApi = insightsApi;
|
|
1102
|
+
this.flushRuntime = new QueueFlushRuntime({
|
|
1103
|
+
policy: flushPolicy,
|
|
1104
|
+
onRetry: ()=>{
|
|
1105
|
+
this.flush();
|
|
1106
|
+
},
|
|
1107
|
+
onCallbackError: (callbackName, error)=>{
|
|
1108
|
+
InsightsQueue_coreLogger.warn(`Insights flush policy callback "${callbackName}" failed`, error);
|
|
1109
|
+
}
|
|
1110
|
+
});
|
|
1111
|
+
}
|
|
1112
|
+
clearScheduledRetry() {
|
|
1113
|
+
this.flushRuntime.clearScheduledRetry();
|
|
1114
|
+
}
|
|
1115
|
+
clearPeriodicFlushTimer() {
|
|
1116
|
+
if (void 0 === this.insightsPeriodicFlushTimer) return;
|
|
1117
|
+
clearInterval(this.insightsPeriodicFlushTimer);
|
|
1118
|
+
this.insightsPeriodicFlushTimer = void 0;
|
|
1119
|
+
}
|
|
1120
|
+
async send(event) {
|
|
1121
|
+
const { value: profile } = signals_profile;
|
|
1122
|
+
if (!profile) return void InsightsQueue_coreLogger.warn('Attempting to emit an event without an Optimization profile');
|
|
1123
|
+
const intercepted = await this.eventInterceptors.run(event);
|
|
1124
|
+
const validEvent = (0, api_schemas_.parseWithFriendlyError)(api_schemas_.InsightsEvent, intercepted);
|
|
1125
|
+
InsightsQueue_coreLogger.debug(`Queueing ${validEvent.type} event for profile ${profile.id}`, validEvent);
|
|
1126
|
+
const queuedProfileEvents = this.queuedInsightsByProfile.get(profile.id);
|
|
1127
|
+
signals_event.value = validEvent;
|
|
1128
|
+
if (queuedProfileEvents) {
|
|
1129
|
+
queuedProfileEvents.profile = profile;
|
|
1130
|
+
queuedProfileEvents.events.push(validEvent);
|
|
1131
|
+
} else this.queuedInsightsByProfile.set(profile.id, {
|
|
1132
|
+
profile,
|
|
1133
|
+
events: [
|
|
1134
|
+
validEvent
|
|
1135
|
+
]
|
|
1136
|
+
});
|
|
1137
|
+
this.ensurePeriodicFlushTimer();
|
|
1138
|
+
if (this.getQueuedEventCount() >= MAX_QUEUED_INSIGHTS_EVENTS) await this.flush();
|
|
1139
|
+
this.reconcilePeriodicFlushTimer();
|
|
1140
|
+
}
|
|
1141
|
+
async flush(options = {}) {
|
|
1142
|
+
const { force = false } = options;
|
|
1143
|
+
if (this.flushRuntime.shouldSkip({
|
|
1144
|
+
force,
|
|
1145
|
+
isOnline: !!online.value
|
|
1146
|
+
})) return;
|
|
1147
|
+
InsightsQueue_coreLogger.debug('Flushing insights event queue');
|
|
1148
|
+
const batches = this.createBatches();
|
|
1149
|
+
if (!batches.length) {
|
|
1150
|
+
this.flushRuntime.clearScheduledRetry();
|
|
1151
|
+
this.reconcilePeriodicFlushTimer();
|
|
1152
|
+
return;
|
|
1153
|
+
}
|
|
1154
|
+
this.flushRuntime.markFlushStarted();
|
|
1155
|
+
try {
|
|
1156
|
+
const sendSuccess = await this.trySendBatches(batches);
|
|
1157
|
+
if (sendSuccess) {
|
|
1158
|
+
this.queuedInsightsByProfile.clear();
|
|
1159
|
+
this.flushRuntime.handleFlushSuccess();
|
|
1160
|
+
} else this.flushRuntime.handleFlushFailure({
|
|
1161
|
+
queuedBatches: batches.length,
|
|
1162
|
+
queuedEvents: this.getQueuedEventCount()
|
|
1344
1163
|
});
|
|
1345
|
-
|
|
1164
|
+
} finally{
|
|
1165
|
+
this.flushRuntime.markFlushFinished();
|
|
1166
|
+
this.reconcilePeriodicFlushTimer();
|
|
1346
1167
|
}
|
|
1347
1168
|
}
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
z8: ()=>resolvers_PersonalizedEntryResolver
|
|
1355
|
-
});
|
|
1356
|
-
const FlagsResolver = {
|
|
1357
|
-
resolve (changes) {
|
|
1358
|
-
if (!changes) return {};
|
|
1359
|
-
return changes.reduce((acc, { key, value })=>{
|
|
1360
|
-
const actualValue = 'object' == typeof value && null !== value && 'value' in value && 'object' == typeof value.value ? value.value : value;
|
|
1361
|
-
acc[key] = actualValue;
|
|
1362
|
-
return acc;
|
|
1363
|
-
}, {});
|
|
1364
|
-
}
|
|
1365
|
-
};
|
|
1366
|
-
const resolvers_FlagsResolver = FlagsResolver;
|
|
1367
|
-
var optimization_api_client_ = __webpack_require__("@contentful/optimization-api-client");
|
|
1368
|
-
const compat_namespaceObject = require("es-toolkit/compat");
|
|
1369
|
-
var dist = __webpack_require__("../../lib/logger/dist/index.mjs");
|
|
1370
|
-
const logger = (0, dist.zP)('Personalization');
|
|
1371
|
-
const RESOLUTION_WARNING_BASE = 'Could not resolve Merge Tag value:';
|
|
1372
|
-
const MergeTagValueResolver = {
|
|
1373
|
-
isMergeTagEntry (embeddedEntryNodeTarget) {
|
|
1374
|
-
return optimization_api_client_.MergeTagEntry.safeParse(embeddedEntryNodeTarget).success;
|
|
1375
|
-
},
|
|
1376
|
-
normalizeSelectors (id) {
|
|
1377
|
-
return id.split('_').map((_path, index, paths)=>{
|
|
1378
|
-
const dotPath = paths.slice(0, index).join('.');
|
|
1379
|
-
const underScorePath = paths.slice(index).join('_');
|
|
1380
|
-
return [
|
|
1381
|
-
dotPath,
|
|
1382
|
-
underScorePath
|
|
1383
|
-
].filter((path)=>'' !== path).join('.');
|
|
1169
|
+
createBatches() {
|
|
1170
|
+
const batches = [];
|
|
1171
|
+
this.queuedInsightsByProfile.forEach(({ profile, events })=>{
|
|
1172
|
+
batches.push({
|
|
1173
|
+
profile,
|
|
1174
|
+
events
|
|
1384
1175
|
});
|
|
1385
|
-
}
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
resolve (mergeTagEntry, profile) {
|
|
1395
|
-
if (!MergeTagValueResolver.isMergeTagEntry(mergeTagEntry)) return void logger.warn(`${RESOLUTION_WARNING_BASE} supplied entry is not a Merge Tag entry`);
|
|
1396
|
-
const { fields: { nt_fallback: fallback } } = mergeTagEntry;
|
|
1397
|
-
if (!optimization_api_client_.Profile.safeParse(profile).success) {
|
|
1398
|
-
logger.warn(`${RESOLUTION_WARNING_BASE} no valid profile`);
|
|
1399
|
-
return fallback;
|
|
1400
|
-
}
|
|
1401
|
-
return MergeTagValueResolver.getValueFromProfile(mergeTagEntry.fields.nt_mergetag_id, profile) ?? fallback;
|
|
1176
|
+
});
|
|
1177
|
+
return batches;
|
|
1178
|
+
}
|
|
1179
|
+
async trySendBatches(batches) {
|
|
1180
|
+
try {
|
|
1181
|
+
return await this.insightsApi.sendBatchEvents(batches);
|
|
1182
|
+
} catch (error) {
|
|
1183
|
+
InsightsQueue_coreLogger.warn('Insights queue flush request threw an error', error);
|
|
1184
|
+
return false;
|
|
1402
1185
|
}
|
|
1186
|
+
}
|
|
1187
|
+
getQueuedEventCount() {
|
|
1188
|
+
let queuedCount = 0;
|
|
1189
|
+
this.queuedInsightsByProfile.forEach(({ events })=>{
|
|
1190
|
+
queuedCount += events.length;
|
|
1191
|
+
});
|
|
1192
|
+
return queuedCount;
|
|
1193
|
+
}
|
|
1194
|
+
ensurePeriodicFlushTimer() {
|
|
1195
|
+
if (void 0 !== this.insightsPeriodicFlushTimer) return;
|
|
1196
|
+
if (0 === this.getQueuedEventCount()) return;
|
|
1197
|
+
this.insightsPeriodicFlushTimer = setInterval(()=>{
|
|
1198
|
+
this.flush();
|
|
1199
|
+
}, this.flushIntervalMs);
|
|
1200
|
+
}
|
|
1201
|
+
reconcilePeriodicFlushTimer() {
|
|
1202
|
+
if (this.getQueuedEventCount() > 0) return void this.ensurePeriodicFlushTimer();
|
|
1203
|
+
this.clearPeriodicFlushTimer();
|
|
1204
|
+
}
|
|
1205
|
+
}
|
|
1206
|
+
var symbols = __webpack_require__("./src/symbols.ts");
|
|
1207
|
+
const CoreStateful_coreLogger = (0, logger_namespaceObject.createScopedLogger)('CoreStateful');
|
|
1208
|
+
const DEFAULT_ALLOWED_EVENT_TYPES = [
|
|
1209
|
+
'identify',
|
|
1210
|
+
'page',
|
|
1211
|
+
'screen'
|
|
1212
|
+
];
|
|
1213
|
+
const OFFLINE_QUEUE_MAX_EVENTS = 100;
|
|
1214
|
+
const hasDefinedValues = (record)=>Object.values(record).some((value)=>void 0 !== value);
|
|
1215
|
+
const createStatefulExperienceApiConfig = (api)=>{
|
|
1216
|
+
if (void 0 === api) return;
|
|
1217
|
+
const experienceConfig = {
|
|
1218
|
+
baseUrl: api.experienceBaseUrl,
|
|
1219
|
+
enabledFeatures: api.enabledFeatures,
|
|
1220
|
+
ip: api.ip,
|
|
1221
|
+
locale: api.locale,
|
|
1222
|
+
plainText: api.plainText,
|
|
1223
|
+
preflight: api.preflight
|
|
1403
1224
|
};
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
return personalizationEntry;
|
|
1412
|
-
},
|
|
1413
|
-
getSelectedPersonalization ({ personalizationEntry, selectedPersonalizations }, skipValidation = false) {
|
|
1414
|
-
if (!skipValidation && (!selectedPersonalizations.length || !(0, optimization_api_client_.isPersonalizationEntry)(personalizationEntry))) return;
|
|
1415
|
-
const selectedPersonalization = selectedPersonalizations.find(({ experienceId })=>experienceId === personalizationEntry.fields.nt_experience_id);
|
|
1416
|
-
return selectedPersonalization;
|
|
1417
|
-
},
|
|
1418
|
-
getSelectedVariant ({ personalizedEntry, personalizationEntry, selectedVariantIndex }, skipValidation = false) {
|
|
1419
|
-
if (!skipValidation && (!(0, optimization_api_client_.isPersonalizedEntry)(personalizedEntry) || !(0, optimization_api_client_.isPersonalizationEntry)(personalizationEntry))) return;
|
|
1420
|
-
const relevantVariants = personalizationEntry.fields.nt_config?.components?.filter((component)=>(0, optimization_api_client_.isEntryReplacementComponent)(component) && !component.baseline.hidden).find((component)=>component.baseline.id === personalizedEntry.sys.id)?.variants;
|
|
1421
|
-
if (!relevantVariants?.length) return;
|
|
1422
|
-
return relevantVariants.at(selectedVariantIndex - 1);
|
|
1423
|
-
},
|
|
1424
|
-
getSelectedVariantEntry ({ personalizationEntry, selectedVariant }, skipValidation = false) {
|
|
1425
|
-
if (!skipValidation && (!(0, optimization_api_client_.isPersonalizationEntry)(personalizationEntry) || !(0, optimization_api_client_.isEntryReplacementVariant)(selectedVariant))) return;
|
|
1426
|
-
const selectedVariantEntry = personalizationEntry.fields.nt_variants?.find((variant)=>variant.sys.id === selectedVariant.id);
|
|
1427
|
-
return (0, optimization_api_client_.isEntry)(selectedVariantEntry) ? selectedVariantEntry : void 0;
|
|
1428
|
-
},
|
|
1429
|
-
resolve (entry, selectedPersonalizations) {
|
|
1430
|
-
PersonalizedEntryResolver_logger.debug(`Resolving personalized entry for baseline entry ${entry.sys.id}`);
|
|
1431
|
-
if (!selectedPersonalizations?.length) {
|
|
1432
|
-
PersonalizedEntryResolver_logger.warn(`${PersonalizedEntryResolver_RESOLUTION_WARNING_BASE} no selectedPersonalizations exist for the current profile`);
|
|
1433
|
-
return {
|
|
1434
|
-
entry
|
|
1435
|
-
};
|
|
1436
|
-
}
|
|
1437
|
-
if (!(0, optimization_api_client_.isPersonalizedEntry)(entry)) {
|
|
1438
|
-
PersonalizedEntryResolver_logger.warn(`${PersonalizedEntryResolver_RESOLUTION_WARNING_BASE} entry ${entry.sys.id} is not personalized`);
|
|
1439
|
-
return {
|
|
1440
|
-
entry
|
|
1441
|
-
};
|
|
1442
|
-
}
|
|
1443
|
-
const personalizationEntry = PersonalizedEntryResolver.getPersonalizationEntry({
|
|
1444
|
-
personalizedEntry: entry,
|
|
1445
|
-
selectedPersonalizations
|
|
1446
|
-
}, true);
|
|
1447
|
-
if (!personalizationEntry) {
|
|
1448
|
-
PersonalizedEntryResolver_logger.warn(`${PersonalizedEntryResolver_RESOLUTION_WARNING_BASE} could not find a personalization entry for ${entry.sys.id}`);
|
|
1449
|
-
return {
|
|
1450
|
-
entry
|
|
1451
|
-
};
|
|
1452
|
-
}
|
|
1453
|
-
const selectedPersonalization = PersonalizedEntryResolver.getSelectedPersonalization({
|
|
1454
|
-
personalizationEntry,
|
|
1455
|
-
selectedPersonalizations
|
|
1456
|
-
}, true);
|
|
1457
|
-
const selectedVariantIndex = selectedPersonalization?.variantIndex ?? 0;
|
|
1458
|
-
if (0 === selectedVariantIndex) {
|
|
1459
|
-
PersonalizedEntryResolver_logger.debug(`Resolved personalization entry for entry ${entry.sys.id} is baseline`);
|
|
1460
|
-
return {
|
|
1461
|
-
entry
|
|
1462
|
-
};
|
|
1463
|
-
}
|
|
1464
|
-
const selectedVariant = PersonalizedEntryResolver.getSelectedVariant({
|
|
1465
|
-
personalizedEntry: entry,
|
|
1466
|
-
personalizationEntry,
|
|
1467
|
-
selectedVariantIndex
|
|
1468
|
-
}, true);
|
|
1469
|
-
if (!selectedVariant) {
|
|
1470
|
-
PersonalizedEntryResolver_logger.warn(`${PersonalizedEntryResolver_RESOLUTION_WARNING_BASE} could not find a valid replacement variant entry for ${entry.sys.id}`);
|
|
1471
|
-
return {
|
|
1472
|
-
entry
|
|
1473
|
-
};
|
|
1474
|
-
}
|
|
1475
|
-
const selectedVariantEntry = PersonalizedEntryResolver.getSelectedVariantEntry({
|
|
1476
|
-
personalizationEntry,
|
|
1477
|
-
selectedVariant
|
|
1478
|
-
}, true);
|
|
1479
|
-
if (selectedVariantEntry) PersonalizedEntryResolver_logger.debug(`Entry ${entry.sys.id} has been resolved to variant entry ${selectedVariantEntry.sys.id}`);
|
|
1480
|
-
else {
|
|
1481
|
-
PersonalizedEntryResolver_logger.warn(`${PersonalizedEntryResolver_RESOLUTION_WARNING_BASE} could not find a valid replacement variant entry for ${entry.sys.id}`);
|
|
1482
|
-
return {
|
|
1483
|
-
entry
|
|
1484
|
-
};
|
|
1485
|
-
}
|
|
1486
|
-
return {
|
|
1487
|
-
entry: selectedVariantEntry,
|
|
1488
|
-
personalization: selectedPersonalization
|
|
1489
|
-
};
|
|
1490
|
-
}
|
|
1225
|
+
return hasDefinedValues(experienceConfig) ? experienceConfig : void 0;
|
|
1226
|
+
};
|
|
1227
|
+
const createStatefulInsightsApiConfig = (api)=>{
|
|
1228
|
+
if (void 0 === api) return;
|
|
1229
|
+
const insightsConfig = {
|
|
1230
|
+
baseUrl: api.insightsBaseUrl,
|
|
1231
|
+
beaconHandler: api.beaconHandler
|
|
1491
1232
|
};
|
|
1492
|
-
|
|
1493
|
-
}
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
ME: ()=>profile,
|
|
1499
|
-
f0: ()=>signals_event,
|
|
1500
|
-
QO: ()=>signals,
|
|
1501
|
-
Mv: ()=>flags,
|
|
1502
|
-
br: ()=>toObservable,
|
|
1503
|
-
vJ: ()=>consent,
|
|
1504
|
-
Ao: ()=>changes,
|
|
1505
|
-
QZ: ()=>signals_core_namespaceObject.effect,
|
|
1506
|
-
wh: ()=>personalizations
|
|
1233
|
+
return hasDefinedValues(insightsConfig) ? insightsConfig : void 0;
|
|
1234
|
+
};
|
|
1235
|
+
const resolveQueuePolicy = (policy)=>({
|
|
1236
|
+
flush: resolveQueueFlushPolicy(policy?.flush),
|
|
1237
|
+
offlineMaxEvents: toPositiveInt(policy?.offlineMaxEvents, OFFLINE_QUEUE_MAX_EVENTS),
|
|
1238
|
+
onOfflineDrop: policy?.onOfflineDrop
|
|
1507
1239
|
});
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
}
|
|
1527
|
-
};
|
|
1528
|
-
}
|
|
1529
|
-
const signals = {
|
|
1530
|
-
changes,
|
|
1531
|
-
consent,
|
|
1532
|
-
event: signals_event,
|
|
1533
|
-
flags,
|
|
1534
|
-
online,
|
|
1535
|
-
personalizations,
|
|
1536
|
-
profile
|
|
1240
|
+
let statefulInstanceCounter = 0;
|
|
1241
|
+
class CoreStateful extends src_CoreStatefulEventEmitter {
|
|
1242
|
+
singletonOwner;
|
|
1243
|
+
destroyed = false;
|
|
1244
|
+
allowedEventTypes;
|
|
1245
|
+
experienceQueue;
|
|
1246
|
+
insightsQueue;
|
|
1247
|
+
onEventBlocked;
|
|
1248
|
+
states = {
|
|
1249
|
+
blockedEventStream: toObservable(blockedEvent),
|
|
1250
|
+
flag: (name)=>this.getFlagObservable(name),
|
|
1251
|
+
consent: toObservable(consent),
|
|
1252
|
+
eventStream: toObservable(signals_event),
|
|
1253
|
+
canOptimize: toObservable(canOptimize),
|
|
1254
|
+
selectedOptimizations: toObservable(signals_selectedOptimizations),
|
|
1255
|
+
previewPanelAttached: toObservable(previewPanelAttached),
|
|
1256
|
+
previewPanelOpen: toObservable(previewPanelOpen),
|
|
1257
|
+
profile: toObservable(signals_profile)
|
|
1537
1258
|
};
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
}
|
|
1571
|
-
addSink(sink) {
|
|
1572
|
-
this.sinks = [
|
|
1573
|
-
...this.sinks.filter((existingSink)=>existingSink.name !== sink.name),
|
|
1574
|
-
sink
|
|
1575
|
-
];
|
|
1576
|
-
}
|
|
1577
|
-
removeSink(name) {
|
|
1578
|
-
this.sinks = this.sinks.filter((sink)=>sink.name !== name);
|
|
1579
|
-
}
|
|
1580
|
-
removeSinks() {
|
|
1581
|
-
this.sinks = [];
|
|
1582
|
-
}
|
|
1583
|
-
debug(logLocation, message, ...args) {
|
|
1584
|
-
this.diary.debug(`${this.assembleLocationPrefix(logLocation)} ${message}`, ...args);
|
|
1585
|
-
}
|
|
1586
|
-
info(logLocation, message, ...args) {
|
|
1587
|
-
this.diary.info(`${this.assembleLocationPrefix(logLocation)} ${message}`, ...args);
|
|
1588
|
-
}
|
|
1589
|
-
log(logLocation, message, ...args) {
|
|
1590
|
-
this.diary.log(`${this.assembleLocationPrefix(logLocation)} ${message}`, ...args);
|
|
1591
|
-
}
|
|
1592
|
-
warn(logLocation, message, ...args) {
|
|
1593
|
-
this.diary.warn(`${this.assembleLocationPrefix(logLocation)} ${message}`, ...args);
|
|
1594
|
-
}
|
|
1595
|
-
error(logLocation, message, ...args) {
|
|
1596
|
-
this.diary.error(`${this.assembleLocationPrefix(logLocation)} ${message}`, ...args);
|
|
1597
|
-
}
|
|
1598
|
-
fatal(logLocation, message, ...args) {
|
|
1599
|
-
this.diary.fatal(`${this.assembleLocationPrefix(logLocation)} ${message}`, ...args);
|
|
1600
|
-
}
|
|
1601
|
-
onLogEvent(event) {
|
|
1602
|
-
this.sinks.forEach((sink)=>{
|
|
1603
|
-
sink.ingest(event);
|
|
1259
|
+
constructor(config){
|
|
1260
|
+
super(config, {
|
|
1261
|
+
experience: createStatefulExperienceApiConfig(config.api),
|
|
1262
|
+
insights: createStatefulInsightsApiConfig(config.api)
|
|
1263
|
+
});
|
|
1264
|
+
this.singletonOwner = `CoreStateful#${++statefulInstanceCounter}`;
|
|
1265
|
+
acquireStatefulRuntimeSingleton(this.singletonOwner);
|
|
1266
|
+
try {
|
|
1267
|
+
const { allowedEventTypes, defaults, getAnonymousId, onEventBlocked, queuePolicy } = config;
|
|
1268
|
+
const { changes: defaultChanges, consent: defaultConsent, selectedOptimizations: defaultSelectedOptimizations, profile: defaultProfile } = defaults ?? {};
|
|
1269
|
+
const resolvedQueuePolicy = resolveQueuePolicy(queuePolicy);
|
|
1270
|
+
this.allowedEventTypes = allowedEventTypes ?? DEFAULT_ALLOWED_EVENT_TYPES;
|
|
1271
|
+
this.onEventBlocked = onEventBlocked;
|
|
1272
|
+
this.insightsQueue = new InsightsQueue({
|
|
1273
|
+
eventInterceptors: this.interceptors.event,
|
|
1274
|
+
flushPolicy: resolvedQueuePolicy.flush,
|
|
1275
|
+
insightsApi: this.api.insights
|
|
1276
|
+
});
|
|
1277
|
+
this.experienceQueue = new ExperienceQueue({
|
|
1278
|
+
experienceApi: this.api.experience,
|
|
1279
|
+
eventInterceptors: this.interceptors.event,
|
|
1280
|
+
flushPolicy: resolvedQueuePolicy.flush,
|
|
1281
|
+
getAnonymousId: getAnonymousId ?? (()=>void 0),
|
|
1282
|
+
offlineMaxEvents: resolvedQueuePolicy.offlineMaxEvents,
|
|
1283
|
+
onOfflineDrop: resolvedQueuePolicy.onOfflineDrop,
|
|
1284
|
+
stateInterceptors: this.interceptors.state
|
|
1285
|
+
});
|
|
1286
|
+
if (void 0 !== defaultConsent) consent.value = defaultConsent;
|
|
1287
|
+
(0, signals_core_namespaceObject.batch)(()=>{
|
|
1288
|
+
if (void 0 !== defaultChanges) signals_changes.value = defaultChanges;
|
|
1289
|
+
if (void 0 !== defaultSelectedOptimizations) signals_selectedOptimizations.value = defaultSelectedOptimizations;
|
|
1290
|
+
if (void 0 !== defaultProfile) signals_profile.value = defaultProfile;
|
|
1604
1291
|
});
|
|
1292
|
+
this.initializeEffects();
|
|
1293
|
+
} catch (error) {
|
|
1294
|
+
releaseStatefulRuntimeSingleton(this.singletonOwner);
|
|
1295
|
+
throw error;
|
|
1605
1296
|
}
|
|
1606
1297
|
}
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
}
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
}
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
fatal: (message, ...args)=>{
|
|
1626
|
-
logger.fatal(location, message, ...args);
|
|
1627
|
-
}
|
|
1628
|
-
};
|
|
1298
|
+
initializeEffects() {
|
|
1299
|
+
(0, signals_core_namespaceObject.effect)(()=>{
|
|
1300
|
+
CoreStateful_coreLogger.debug(`Profile ${signals_profile.value && `with ID ${signals_profile.value.id}`} has been ${signals_profile.value ? 'set' : 'cleared'}`);
|
|
1301
|
+
});
|
|
1302
|
+
(0, signals_core_namespaceObject.effect)(()=>{
|
|
1303
|
+
CoreStateful_coreLogger.debug(`Variants have been ${signals_selectedOptimizations.value?.length ? 'populated' : 'cleared'}`);
|
|
1304
|
+
});
|
|
1305
|
+
(0, signals_core_namespaceObject.effect)(()=>{
|
|
1306
|
+
CoreStateful_coreLogger.info(`Core ${consent.value ? 'will' : 'will not'} emit gated events due to consent (${consent.value})`);
|
|
1307
|
+
});
|
|
1308
|
+
(0, signals_core_namespaceObject.effect)(()=>{
|
|
1309
|
+
if (!online.value) return;
|
|
1310
|
+
this.insightsQueue.clearScheduledRetry();
|
|
1311
|
+
this.experienceQueue.clearScheduledRetry();
|
|
1312
|
+
this.flushQueues({
|
|
1313
|
+
force: true
|
|
1314
|
+
});
|
|
1315
|
+
});
|
|
1629
1316
|
}
|
|
1630
|
-
|
|
1317
|
+
async flushQueues(options = {}) {
|
|
1318
|
+
await this.insightsQueue.flush(options);
|
|
1319
|
+
await this.experienceQueue.flush(options);
|
|
1631
1320
|
}
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
}
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
}
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1321
|
+
destroy() {
|
|
1322
|
+
if (this.destroyed) return;
|
|
1323
|
+
this.destroyed = true;
|
|
1324
|
+
this.insightsQueue.flush({
|
|
1325
|
+
force: true
|
|
1326
|
+
}).catch((error)=>{
|
|
1327
|
+
logger_namespaceObject.logger.warn('Failed to flush insights queue during destroy()', String(error));
|
|
1328
|
+
});
|
|
1329
|
+
this.experienceQueue.flush({
|
|
1330
|
+
force: true
|
|
1331
|
+
}).catch((error)=>{
|
|
1332
|
+
logger_namespaceObject.logger.warn('Failed to flush Experience queue during destroy()', String(error));
|
|
1333
|
+
});
|
|
1334
|
+
this.insightsQueue.clearPeriodicFlushTimer();
|
|
1335
|
+
releaseStatefulRuntimeSingleton(this.singletonOwner);
|
|
1336
|
+
}
|
|
1337
|
+
reset() {
|
|
1338
|
+
(0, signals_core_namespaceObject.batch)(()=>{
|
|
1339
|
+
blockedEvent.value = void 0;
|
|
1340
|
+
signals_event.value = void 0;
|
|
1341
|
+
signals_changes.value = void 0;
|
|
1342
|
+
signals_profile.value = void 0;
|
|
1343
|
+
signals_selectedOptimizations.value = void 0;
|
|
1344
|
+
});
|
|
1345
|
+
}
|
|
1346
|
+
async flush() {
|
|
1347
|
+
await this.flushQueues();
|
|
1348
|
+
}
|
|
1349
|
+
consent(accept) {
|
|
1350
|
+
consent.value = accept;
|
|
1351
|
+
}
|
|
1352
|
+
get online() {
|
|
1353
|
+
return online.value ?? false;
|
|
1354
|
+
}
|
|
1355
|
+
set online(isOnline) {
|
|
1356
|
+
online.value = isOnline;
|
|
1357
|
+
}
|
|
1358
|
+
registerPreviewPanel(previewPanel) {
|
|
1359
|
+
Reflect.set(previewPanel, symbols.PREVIEW_PANEL_SIGNALS_SYMBOL, signals);
|
|
1360
|
+
Reflect.set(previewPanel, symbols.PREVIEW_PANEL_SIGNAL_FNS_SYMBOL, signalFns);
|
|
1665
1361
|
}
|
|
1666
1362
|
}
|
|
1667
|
-
|
|
1668
|
-
var
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
}
|
|
1678
|
-
(()=>{
|
|
1679
|
-
__webpack_require__.n = (module)=>{
|
|
1680
|
-
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
1681
|
-
__webpack_require__.d(getter, {
|
|
1682
|
-
a: getter
|
|
1683
|
-
});
|
|
1684
|
-
return getter;
|
|
1363
|
+
const src_CoreStateful = CoreStateful;
|
|
1364
|
+
var api_schemas = __webpack_require__("./src/api-schemas.ts");
|
|
1365
|
+
const TRACK_CLICK_PROFILE_ERROR = 'CoreStateless.forRequest().trackClick() requires `payload.profile.id` for Insights delivery.';
|
|
1366
|
+
const TRACK_HOVER_PROFILE_ERROR = 'CoreStateless.forRequest().trackHover() requires `payload.profile.id` for Insights delivery.';
|
|
1367
|
+
const TRACK_FLAG_VIEW_PROFILE_ERROR = 'CoreStateless.forRequest().trackFlagView() requires `payload.profile.id` for Insights delivery.';
|
|
1368
|
+
const NON_STICKY_TRACK_VIEW_PROFILE_ERROR = 'CoreStateless.forRequest().trackView() requires `payload.profile.id` when `payload.sticky` is not `true`.';
|
|
1369
|
+
const STICKY_TRACK_VIEW_PROFILE_ERROR = 'CoreStateless.forRequest().trackView() could not derive a profile from the sticky Experience response. Pass `payload.profile.id` explicitly if you need a fallback.';
|
|
1370
|
+
const requireInsightsProfile = (profile, errorMessage)=>{
|
|
1371
|
+
if (void 0 !== profile) return profile;
|
|
1372
|
+
throw new Error(errorMessage);
|
|
1685
1373
|
};
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1374
|
+
class CoreStatelessRequestScope {
|
|
1375
|
+
core;
|
|
1376
|
+
options;
|
|
1377
|
+
constructor(core, options = {}){
|
|
1378
|
+
this.core = core;
|
|
1379
|
+
this.options = Object.freeze({
|
|
1380
|
+
...options
|
|
1381
|
+
});
|
|
1382
|
+
}
|
|
1383
|
+
async identify(payload) {
|
|
1384
|
+
const { profile, ...builderArgs } = payload;
|
|
1385
|
+
return await this.sendExperienceEvent(this.core.eventBuilder.buildIdentify(builderArgs), profile);
|
|
1386
|
+
}
|
|
1387
|
+
async page(payload = {}) {
|
|
1388
|
+
const { profile, ...builderArgs } = payload;
|
|
1389
|
+
return await this.sendExperienceEvent(this.core.eventBuilder.buildPageView(builderArgs), profile);
|
|
1390
|
+
}
|
|
1391
|
+
async screen(payload) {
|
|
1392
|
+
const { profile, ...builderArgs } = payload;
|
|
1393
|
+
return await this.sendExperienceEvent(this.core.eventBuilder.buildScreenView(builderArgs), profile);
|
|
1394
|
+
}
|
|
1395
|
+
async track(payload) {
|
|
1396
|
+
const { profile, ...builderArgs } = payload;
|
|
1397
|
+
return await this.sendExperienceEvent(this.core.eventBuilder.buildTrack(builderArgs), profile);
|
|
1398
|
+
}
|
|
1399
|
+
async trackView(payload) {
|
|
1400
|
+
const { profile, ...builderArgs } = payload;
|
|
1401
|
+
let result;
|
|
1402
|
+
let insightsProfile = profile;
|
|
1403
|
+
if (payload.sticky) {
|
|
1404
|
+
result = await this.sendExperienceEvent(this.core.eventBuilder.buildView(builderArgs), profile);
|
|
1405
|
+
const { profile: responseProfile } = result;
|
|
1406
|
+
insightsProfile = responseProfile;
|
|
1407
|
+
}
|
|
1408
|
+
await this.sendInsightsEvent(this.core.eventBuilder.buildView(builderArgs), requireInsightsProfile(insightsProfile, payload.sticky ? STICKY_TRACK_VIEW_PROFILE_ERROR : NON_STICKY_TRACK_VIEW_PROFILE_ERROR));
|
|
1409
|
+
return result;
|
|
1410
|
+
}
|
|
1411
|
+
async trackClick(payload) {
|
|
1412
|
+
const { profile, ...builderArgs } = payload;
|
|
1413
|
+
await this.sendInsightsEvent(this.core.eventBuilder.buildClick(builderArgs), requireInsightsProfile(profile, TRACK_CLICK_PROFILE_ERROR));
|
|
1414
|
+
}
|
|
1415
|
+
async trackHover(payload) {
|
|
1416
|
+
const { profile, ...builderArgs } = payload;
|
|
1417
|
+
await this.sendInsightsEvent(this.core.eventBuilder.buildHover(builderArgs), requireInsightsProfile(profile, TRACK_HOVER_PROFILE_ERROR));
|
|
1418
|
+
}
|
|
1419
|
+
async trackFlagView(payload) {
|
|
1420
|
+
const { profile, ...builderArgs } = payload;
|
|
1421
|
+
await this.sendInsightsEvent(this.core.eventBuilder.buildFlagView(builderArgs), requireInsightsProfile(profile, TRACK_FLAG_VIEW_PROFILE_ERROR));
|
|
1422
|
+
}
|
|
1423
|
+
async sendExperienceEvent(event, profile) {
|
|
1424
|
+
const intercepted = await this.core.interceptors.event.run(event);
|
|
1425
|
+
const validEvent = (0, api_schemas_.parseWithFriendlyError)(api_schemas_.ExperienceEvent, intercepted);
|
|
1426
|
+
return await this.core.api.experience.upsertProfile({
|
|
1427
|
+
profileId: profile?.id,
|
|
1428
|
+
events: [
|
|
1429
|
+
validEvent
|
|
1430
|
+
]
|
|
1431
|
+
}, this.options);
|
|
1432
|
+
}
|
|
1433
|
+
async sendInsightsEvent(event, profile) {
|
|
1434
|
+
const intercepted = await this.core.interceptors.event.run(event);
|
|
1435
|
+
const validEvent = (0, api_schemas_.parseWithFriendlyError)(api_schemas_.InsightsEvent, intercepted);
|
|
1436
|
+
const batchEvent = (0, api_schemas_.parseWithFriendlyError)(api_schemas_.BatchInsightsEventArray, [
|
|
1437
|
+
{
|
|
1438
|
+
profile: (0, api_schemas_.parseWithFriendlyError)(api_schemas.PartialProfile, profile),
|
|
1439
|
+
events: [
|
|
1440
|
+
validEvent
|
|
1441
|
+
]
|
|
1442
|
+
}
|
|
1443
|
+
]);
|
|
1444
|
+
await this.core.api.insights.sendBatchEvents(batchEvent);
|
|
1445
|
+
}
|
|
1446
|
+
}
|
|
1447
|
+
const CoreStateless_hasDefinedValues = (record)=>Object.values(record).some((value)=>void 0 !== value);
|
|
1448
|
+
const createStatelessExperienceApiConfig = (api)=>{
|
|
1449
|
+
if (void 0 === api) return;
|
|
1450
|
+
const experienceConfig = {
|
|
1451
|
+
baseUrl: api.experienceBaseUrl,
|
|
1452
|
+
enabledFeatures: api.enabledFeatures
|
|
1453
|
+
};
|
|
1454
|
+
return CoreStateless_hasDefinedValues(experienceConfig) ? experienceConfig : void 0;
|
|
1693
1455
|
};
|
|
1694
|
-
|
|
1695
|
-
(
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
__webpack_require__.r = (exports1)=>{
|
|
1700
|
-
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
1701
|
-
value: 'Module'
|
|
1702
|
-
});
|
|
1703
|
-
Object.defineProperty(exports1, '__esModule', {
|
|
1704
|
-
value: true
|
|
1705
|
-
});
|
|
1456
|
+
const createStatelessInsightsApiConfig = (api)=>{
|
|
1457
|
+
if (api?.insightsBaseUrl === void 0) return;
|
|
1458
|
+
return {
|
|
1459
|
+
baseUrl: api.insightsBaseUrl
|
|
1460
|
+
};
|
|
1706
1461
|
};
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
(
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1462
|
+
class CoreStateless extends src_CoreBase {
|
|
1463
|
+
constructor(config){
|
|
1464
|
+
super(config, {
|
|
1465
|
+
experience: createStatelessExperienceApiConfig(config.api),
|
|
1466
|
+
insights: createStatelessInsightsApiConfig(config.api)
|
|
1467
|
+
});
|
|
1468
|
+
}
|
|
1469
|
+
forRequest(options = {}) {
|
|
1470
|
+
return new CoreStatelessRequestScope(this, options);
|
|
1471
|
+
}
|
|
1472
|
+
}
|
|
1473
|
+
const src_CoreStateless = CoreStateless;
|
|
1474
|
+
const isFunction = (v)=>'function' == typeof v;
|
|
1475
|
+
const nameToString = (name)=>'string' == typeof name ? name : 'symbol' == typeof name ? name.description ?? String(name) : String(name);
|
|
1476
|
+
const isOnBlockedKey = (v)=>'string' == typeof v || 'symbol' == typeof v;
|
|
1477
|
+
const isAsyncFunction = (fn)=>'[object AsyncFunction]' === Object.prototype.toString.call(fn);
|
|
1478
|
+
function guardedBy(predicateName, opts) {
|
|
1479
|
+
return function(_value, context) {
|
|
1480
|
+
const decoratedName = nameToString(context.name);
|
|
1481
|
+
context.addInitializer(function() {
|
|
1482
|
+
const originalUnknown = Reflect.get(this, context.name);
|
|
1483
|
+
if (!isFunction(originalUnknown)) return;
|
|
1484
|
+
const original = originalUnknown;
|
|
1485
|
+
const originalIsAsync = isAsyncFunction(original);
|
|
1486
|
+
const resolvePredicate = (self)=>{
|
|
1487
|
+
const { [predicateName]: cand } = self;
|
|
1488
|
+
if (!isFunction(cand)) throw new TypeError(`@guardedBy expects predicate "${String(predicateName)}" to be a synchronous function.`);
|
|
1489
|
+
return cand;
|
|
1490
|
+
};
|
|
1491
|
+
const computeAllowed = (self, args)=>{
|
|
1492
|
+
const pred = resolvePredicate(self);
|
|
1493
|
+
const ok = Boolean(pred.call(self, decoratedName, args));
|
|
1494
|
+
return opts?.invert === true ? !ok : ok;
|
|
1495
|
+
};
|
|
1496
|
+
const runOnBlocked = (self, args)=>{
|
|
1497
|
+
const { onBlocked } = opts ?? {};
|
|
1498
|
+
if (void 0 === onBlocked) return;
|
|
1499
|
+
if (isFunction(onBlocked)) return void onBlocked.call(self, decoratedName, args);
|
|
1500
|
+
if (isOnBlockedKey(onBlocked)) {
|
|
1501
|
+
const { [onBlocked]: handlerCandidate } = self;
|
|
1502
|
+
if (isFunction(handlerCandidate)) handlerCandidate.call(self, decoratedName, args);
|
|
1503
|
+
}
|
|
1504
|
+
};
|
|
1505
|
+
const blockedReturn = ()=>originalIsAsync ? Promise.resolve(void 0) : void 0;
|
|
1506
|
+
const wrapped = function(...args) {
|
|
1507
|
+
if (!computeAllowed(this, args)) {
|
|
1508
|
+
runOnBlocked(this, args);
|
|
1509
|
+
return blockedReturn();
|
|
1510
|
+
}
|
|
1511
|
+
return original.call(this, ...args);
|
|
1512
|
+
};
|
|
1513
|
+
Reflect.set(this, context.name, wrapped);
|
|
1514
|
+
});
|
|
1515
|
+
};
|
|
1516
|
+
}
|
|
1757
1517
|
})();
|
|
1758
1518
|
exports.ANONYMOUS_ID_COOKIE = __webpack_exports__.ANONYMOUS_ID_COOKIE;
|
|
1759
|
-
exports.
|
|
1760
|
-
exports.
|
|
1761
|
-
exports.
|
|
1519
|
+
exports.ANONYMOUS_ID_COOKIE_LEGACY = __webpack_exports__.ANONYMOUS_ID_COOKIE_LEGACY;
|
|
1520
|
+
exports.ANONYMOUS_ID_KEY = __webpack_exports__.ANONYMOUS_ID_KEY;
|
|
1521
|
+
exports.ANONYMOUS_ID_KEY_LEGACY = __webpack_exports__.ANONYMOUS_ID_KEY_LEGACY;
|
|
1522
|
+
exports.CHANGES_CACHE_KEY = __webpack_exports__.CHANGES_CACHE_KEY;
|
|
1523
|
+
exports.CONSENT_KEY = __webpack_exports__.CONSENT_KEY;
|
|
1524
|
+
exports.ClickBuilderArgs = __webpack_exports__.ClickBuilderArgs;
|
|
1762
1525
|
exports.CoreStateful = __webpack_exports__.CoreStateful;
|
|
1763
1526
|
exports.CoreStateless = __webpack_exports__.CoreStateless;
|
|
1527
|
+
exports.CoreStatelessRequestScope = __webpack_exports__.CoreStatelessRequestScope;
|
|
1528
|
+
exports.DEBUG_FLAG_KEY = __webpack_exports__.DEBUG_FLAG_KEY;
|
|
1529
|
+
exports.DEFAULT_PAGE_PROPERTIES = __webpack_exports__.DEFAULT_PAGE_PROPERTIES;
|
|
1530
|
+
exports.EntryInteractionBuilderArgsBase = __webpack_exports__.EntryInteractionBuilderArgsBase;
|
|
1531
|
+
exports.EventBuilder = __webpack_exports__.EventBuilder;
|
|
1532
|
+
exports.FlagViewBuilderArgs = __webpack_exports__.FlagViewBuilderArgs;
|
|
1764
1533
|
exports.FlagsResolver = __webpack_exports__.FlagsResolver;
|
|
1534
|
+
exports.HoverBuilderArgs = __webpack_exports__.HoverBuilderArgs;
|
|
1535
|
+
exports.IdentifyBuilderArgs = __webpack_exports__.IdentifyBuilderArgs;
|
|
1765
1536
|
exports.InterceptorManager = __webpack_exports__.InterceptorManager;
|
|
1766
|
-
exports.LogSink = __webpack_exports__.LogSink;
|
|
1767
|
-
exports.Logger = __webpack_exports__.Logger;
|
|
1768
1537
|
exports.MergeTagValueResolver = __webpack_exports__.MergeTagValueResolver;
|
|
1538
|
+
exports.OPTIMIZATION_CORE_SDK_NAME = __webpack_exports__.OPTIMIZATION_CORE_SDK_NAME;
|
|
1769
1539
|
exports.OPTIMIZATION_CORE_SDK_VERSION = __webpack_exports__.OPTIMIZATION_CORE_SDK_VERSION;
|
|
1770
|
-
exports.
|
|
1771
|
-
exports.
|
|
1772
|
-
exports.
|
|
1773
|
-
exports.
|
|
1540
|
+
exports.OptimizedEntryResolver = __webpack_exports__.OptimizedEntryResolver;
|
|
1541
|
+
exports.PREVIEW_PANEL_SIGNALS_SYMBOL = __webpack_exports__.PREVIEW_PANEL_SIGNALS_SYMBOL;
|
|
1542
|
+
exports.PREVIEW_PANEL_SIGNAL_FNS_SYMBOL = __webpack_exports__.PREVIEW_PANEL_SIGNAL_FNS_SYMBOL;
|
|
1543
|
+
exports.PROFILE_CACHE_KEY = __webpack_exports__.PROFILE_CACHE_KEY;
|
|
1544
|
+
exports.PageViewBuilderArgs = __webpack_exports__.PageViewBuilderArgs;
|
|
1545
|
+
exports.SELECTED_OPTIMIZATIONS_CACHE_KEY = __webpack_exports__.SELECTED_OPTIMIZATIONS_CACHE_KEY;
|
|
1546
|
+
exports.ScreenViewBuilderArgs = __webpack_exports__.ScreenViewBuilderArgs;
|
|
1547
|
+
exports.TrackBuilderArgs = __webpack_exports__.TrackBuilderArgs;
|
|
1548
|
+
exports.UniversalEventBuilderArgs = __webpack_exports__.UniversalEventBuilderArgs;
|
|
1549
|
+
exports.ViewBuilderArgs = __webpack_exports__.ViewBuilderArgs;
|
|
1774
1550
|
exports.batch = __webpack_exports__.batch;
|
|
1775
|
-
exports.createScopedLogger = __webpack_exports__.createScopedLogger;
|
|
1776
1551
|
exports.effect = __webpack_exports__.effect;
|
|
1777
1552
|
exports.guardedBy = __webpack_exports__.guardedBy;
|
|
1778
|
-
exports.
|
|
1553
|
+
exports.signalFns = __webpack_exports__.signalFns;
|
|
1779
1554
|
exports.signals = __webpack_exports__.signals;
|
|
1555
|
+
exports.toDistinctObservable = __webpack_exports__.toDistinctObservable;
|
|
1556
|
+
exports.toObservable = __webpack_exports__.toObservable;
|
|
1780
1557
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
1781
1558
|
"ANONYMOUS_ID_COOKIE",
|
|
1782
|
-
"
|
|
1783
|
-
"
|
|
1784
|
-
"
|
|
1559
|
+
"ANONYMOUS_ID_COOKIE_LEGACY",
|
|
1560
|
+
"ANONYMOUS_ID_KEY",
|
|
1561
|
+
"ANONYMOUS_ID_KEY_LEGACY",
|
|
1562
|
+
"CHANGES_CACHE_KEY",
|
|
1563
|
+
"CONSENT_KEY",
|
|
1564
|
+
"ClickBuilderArgs",
|
|
1785
1565
|
"CoreStateful",
|
|
1786
1566
|
"CoreStateless",
|
|
1567
|
+
"CoreStatelessRequestScope",
|
|
1568
|
+
"DEBUG_FLAG_KEY",
|
|
1569
|
+
"DEFAULT_PAGE_PROPERTIES",
|
|
1570
|
+
"EntryInteractionBuilderArgsBase",
|
|
1571
|
+
"EventBuilder",
|
|
1572
|
+
"FlagViewBuilderArgs",
|
|
1787
1573
|
"FlagsResolver",
|
|
1574
|
+
"HoverBuilderArgs",
|
|
1575
|
+
"IdentifyBuilderArgs",
|
|
1788
1576
|
"InterceptorManager",
|
|
1789
|
-
"LogSink",
|
|
1790
|
-
"Logger",
|
|
1791
1577
|
"MergeTagValueResolver",
|
|
1578
|
+
"OPTIMIZATION_CORE_SDK_NAME",
|
|
1792
1579
|
"OPTIMIZATION_CORE_SDK_VERSION",
|
|
1793
|
-
"
|
|
1794
|
-
"
|
|
1795
|
-
"
|
|
1796
|
-
"
|
|
1580
|
+
"OptimizedEntryResolver",
|
|
1581
|
+
"PREVIEW_PANEL_SIGNALS_SYMBOL",
|
|
1582
|
+
"PREVIEW_PANEL_SIGNAL_FNS_SYMBOL",
|
|
1583
|
+
"PROFILE_CACHE_KEY",
|
|
1584
|
+
"PageViewBuilderArgs",
|
|
1585
|
+
"SELECTED_OPTIMIZATIONS_CACHE_KEY",
|
|
1586
|
+
"ScreenViewBuilderArgs",
|
|
1587
|
+
"TrackBuilderArgs",
|
|
1588
|
+
"UniversalEventBuilderArgs",
|
|
1589
|
+
"ViewBuilderArgs",
|
|
1797
1590
|
"batch",
|
|
1798
|
-
"createScopedLogger",
|
|
1799
1591
|
"effect",
|
|
1800
1592
|
"guardedBy",
|
|
1801
|
-
"
|
|
1802
|
-
"signals"
|
|
1593
|
+
"signalFns",
|
|
1594
|
+
"signals",
|
|
1595
|
+
"toDistinctObservable",
|
|
1596
|
+
"toObservable"
|
|
1803
1597
|
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
1804
1598
|
Object.defineProperty(exports, '__esModule', {
|
|
1805
1599
|
value: true
|