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