@contentful/optimization-core 0.1.0-alpha
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/LICENSE +21 -0
- package/README.md +408 -0
- package/dist/Consent.d.ts +44 -0
- package/dist/Consent.d.ts.map +1 -0
- package/dist/Consent.js +2 -0
- package/dist/Consent.js.map +1 -0
- package/dist/CoreBase.d.ts +161 -0
- package/dist/CoreBase.d.ts.map +1 -0
- package/dist/CoreBase.js +151 -0
- package/dist/CoreBase.js.map +1 -0
- package/dist/CoreStateful.d.ts +142 -0
- package/dist/CoreStateful.d.ts.map +1 -0
- package/dist/CoreStateful.js +137 -0
- package/dist/CoreStateful.js.map +1 -0
- package/dist/CoreStateless.d.ts +53 -0
- package/dist/CoreStateless.d.ts.map +1 -0
- package/dist/CoreStateless.js +43 -0
- package/dist/CoreStateless.js.map +1 -0
- package/dist/ProductBase.d.ts +83 -0
- package/dist/ProductBase.d.ts.map +1 -0
- package/dist/ProductBase.js +50 -0
- package/dist/ProductBase.js.map +1 -0
- package/dist/analytics/AnalyticsBase.d.ts +35 -0
- package/dist/analytics/AnalyticsBase.d.ts.map +1 -0
- package/dist/analytics/AnalyticsBase.js +13 -0
- package/dist/analytics/AnalyticsBase.js.map +1 -0
- package/dist/analytics/AnalyticsStateful.d.ts +138 -0
- package/dist/analytics/AnalyticsStateful.d.ts.map +1 -0
- package/dist/analytics/AnalyticsStateful.js +179 -0
- package/dist/analytics/AnalyticsStateful.js.map +1 -0
- package/dist/analytics/AnalyticsStateless.d.ts +48 -0
- package/dist/analytics/AnalyticsStateless.d.ts.map +1 -0
- package/dist/analytics/AnalyticsStateless.js +61 -0
- package/dist/analytics/AnalyticsStateless.js.map +1 -0
- package/dist/analytics/index.d.ts +5 -0
- package/dist/analytics/index.d.ts.map +1 -0
- package/dist/analytics/index.js +5 -0
- package/dist/analytics/index.js.map +1 -0
- package/dist/global-constants.d.ts +18 -0
- package/dist/global-constants.d.ts.map +1 -0
- package/dist/global-constants.js +18 -0
- package/dist/global-constants.js.map +1 -0
- package/dist/index.cjs +1808 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +1535 -0
- package/dist/index.mjs.map +1 -0
- package/dist/lib/decorators/guardedBy.d.ts +113 -0
- package/dist/lib/decorators/guardedBy.d.ts.map +1 -0
- package/dist/lib/decorators/guardedBy.js +143 -0
- package/dist/lib/decorators/guardedBy.js.map +1 -0
- package/dist/lib/decorators/index.d.ts +2 -0
- package/dist/lib/decorators/index.d.ts.map +1 -0
- package/dist/lib/decorators/index.js +2 -0
- package/dist/lib/decorators/index.js.map +1 -0
- package/dist/lib/interceptor/InterceptorManager.d.ts +127 -0
- package/dist/lib/interceptor/InterceptorManager.d.ts.map +1 -0
- package/dist/lib/interceptor/InterceptorManager.js +125 -0
- package/dist/lib/interceptor/InterceptorManager.js.map +1 -0
- package/dist/lib/interceptor/index.d.ts +2 -0
- package/dist/lib/interceptor/index.d.ts.map +1 -0
- package/dist/lib/interceptor/index.js +2 -0
- package/dist/lib/interceptor/index.js.map +1 -0
- package/dist/lib/value-presence/ValuePresence.d.ts +123 -0
- package/dist/lib/value-presence/ValuePresence.d.ts.map +1 -0
- package/dist/lib/value-presence/ValuePresence.js +141 -0
- package/dist/lib/value-presence/ValuePresence.js.map +1 -0
- package/dist/lib/value-presence/index.d.ts +2 -0
- package/dist/lib/value-presence/index.d.ts.map +1 -0
- package/dist/lib/value-presence/index.js +2 -0
- package/dist/lib/value-presence/index.js.map +1 -0
- package/dist/personalization/PersonalizationBase.d.ts +184 -0
- package/dist/personalization/PersonalizationBase.d.ts.map +1 -0
- package/dist/personalization/PersonalizationBase.js +76 -0
- package/dist/personalization/PersonalizationBase.js.map +1 -0
- package/dist/personalization/PersonalizationStateful.d.ts +226 -0
- package/dist/personalization/PersonalizationStateful.d.ts.map +1 -0
- package/dist/personalization/PersonalizationStateful.js +297 -0
- package/dist/personalization/PersonalizationStateful.js.map +1 -0
- package/dist/personalization/PersonalizationStateless.d.ts +74 -0
- package/dist/personalization/PersonalizationStateless.d.ts.map +1 -0
- package/dist/personalization/PersonalizationStateless.js +98 -0
- package/dist/personalization/PersonalizationStateless.js.map +1 -0
- package/dist/personalization/index.d.ts +6 -0
- package/dist/personalization/index.d.ts.map +1 -0
- package/dist/personalization/index.js +6 -0
- package/dist/personalization/index.js.map +1 -0
- package/dist/personalization/resolvers/FlagsResolver.d.ts +35 -0
- package/dist/personalization/resolvers/FlagsResolver.d.ts.map +1 -0
- package/dist/personalization/resolvers/FlagsResolver.js +47 -0
- package/dist/personalization/resolvers/FlagsResolver.js.map +1 -0
- package/dist/personalization/resolvers/MergeTagValueResolver.d.ts +74 -0
- package/dist/personalization/resolvers/MergeTagValueResolver.d.ts.map +1 -0
- package/dist/personalization/resolvers/MergeTagValueResolver.js +109 -0
- package/dist/personalization/resolvers/MergeTagValueResolver.js.map +1 -0
- package/dist/personalization/resolvers/PersonalizedEntryResolver.d.ts +142 -0
- package/dist/personalization/resolvers/PersonalizedEntryResolver.d.ts.map +1 -0
- package/dist/personalization/resolvers/PersonalizedEntryResolver.js +196 -0
- package/dist/personalization/resolvers/PersonalizedEntryResolver.js.map +1 -0
- package/dist/personalization/resolvers/index.d.ts +7 -0
- package/dist/personalization/resolvers/index.d.ts.map +1 -0
- package/dist/personalization/resolvers/index.js +7 -0
- package/dist/personalization/resolvers/index.js.map +1 -0
- package/dist/signals.d.ts +35 -0
- package/dist/signals.d.ts.map +1 -0
- package/dist/signals.js +30 -0
- package/dist/signals.js.map +1 -0
- package/package.json +29 -0
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,1535 @@
|
|
|
1
|
+
import * as __rspack_external__contentful_optimization_api_client_cba5a7ee from "@contentful/optimization-api-client";
|
|
2
|
+
import { batch, computed, effect, signal } from "@preact/signals-core";
|
|
3
|
+
import { get as compat_get } from "es-toolkit/compat";
|
|
4
|
+
import { diary, enable } from "diary";
|
|
5
|
+
import { compare } from "diary/utils";
|
|
6
|
+
import { isEqual } from "es-toolkit";
|
|
7
|
+
const FlagsResolver = {
|
|
8
|
+
resolve (changes) {
|
|
9
|
+
if (!changes) return {};
|
|
10
|
+
return changes.reduce((acc, { key, value })=>{
|
|
11
|
+
const actualValue = 'object' == typeof value && null !== value && 'value' in value && 'object' == typeof value.value ? value.value : value;
|
|
12
|
+
acc[key] = actualValue;
|
|
13
|
+
return acc;
|
|
14
|
+
}, {});
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
const resolvers_FlagsResolver = FlagsResolver;
|
|
18
|
+
class Logger {
|
|
19
|
+
name = '@contentful/optimization';
|
|
20
|
+
PREFIX_PARTS = [
|
|
21
|
+
'Ctfl',
|
|
22
|
+
'O10n'
|
|
23
|
+
];
|
|
24
|
+
DELIMITER = ':';
|
|
25
|
+
diary;
|
|
26
|
+
sinks = [];
|
|
27
|
+
constructor(){
|
|
28
|
+
this.diary = diary(this.name, this.onLogEvent.bind(this));
|
|
29
|
+
enable(this.name);
|
|
30
|
+
}
|
|
31
|
+
assembleLocationPrefix(logLocation) {
|
|
32
|
+
return `[${[
|
|
33
|
+
...this.PREFIX_PARTS,
|
|
34
|
+
logLocation
|
|
35
|
+
].join(this.DELIMITER)}]`;
|
|
36
|
+
}
|
|
37
|
+
addSink(sink) {
|
|
38
|
+
this.sinks = [
|
|
39
|
+
...this.sinks.filter((existingSink)=>existingSink.name !== sink.name),
|
|
40
|
+
sink
|
|
41
|
+
];
|
|
42
|
+
}
|
|
43
|
+
removeSink(name) {
|
|
44
|
+
this.sinks = this.sinks.filter((sink)=>sink.name !== name);
|
|
45
|
+
}
|
|
46
|
+
removeSinks() {
|
|
47
|
+
this.sinks = [];
|
|
48
|
+
}
|
|
49
|
+
debug(logLocation, message, ...args) {
|
|
50
|
+
this.diary.debug(`${this.assembleLocationPrefix(logLocation)} ${message}`, ...args);
|
|
51
|
+
}
|
|
52
|
+
info(logLocation, message, ...args) {
|
|
53
|
+
this.diary.info(`${this.assembleLocationPrefix(logLocation)} ${message}`, ...args);
|
|
54
|
+
}
|
|
55
|
+
log(logLocation, message, ...args) {
|
|
56
|
+
this.diary.log(`${this.assembleLocationPrefix(logLocation)} ${message}`, ...args);
|
|
57
|
+
}
|
|
58
|
+
warn(logLocation, message, ...args) {
|
|
59
|
+
this.diary.warn(`${this.assembleLocationPrefix(logLocation)} ${message}`, ...args);
|
|
60
|
+
}
|
|
61
|
+
error(logLocation, message, ...args) {
|
|
62
|
+
this.diary.error(`${this.assembleLocationPrefix(logLocation)} ${message}`, ...args);
|
|
63
|
+
}
|
|
64
|
+
fatal(logLocation, message, ...args) {
|
|
65
|
+
this.diary.fatal(`${this.assembleLocationPrefix(logLocation)} ${message}`, ...args);
|
|
66
|
+
}
|
|
67
|
+
onLogEvent(event) {
|
|
68
|
+
this.sinks.forEach((sink)=>{
|
|
69
|
+
sink.ingest(event);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
const logger = new Logger();
|
|
74
|
+
function createScopedLogger(location) {
|
|
75
|
+
return {
|
|
76
|
+
debug: (message, ...args)=>{
|
|
77
|
+
logger.debug(location, message, ...args);
|
|
78
|
+
},
|
|
79
|
+
info: (message, ...args)=>{
|
|
80
|
+
logger.info(location, message, ...args);
|
|
81
|
+
},
|
|
82
|
+
log: (message, ...args)=>{
|
|
83
|
+
logger.log(location, message, ...args);
|
|
84
|
+
},
|
|
85
|
+
warn: (message, ...args)=>{
|
|
86
|
+
logger.warn(location, message, ...args);
|
|
87
|
+
},
|
|
88
|
+
error: (message, ...args)=>{
|
|
89
|
+
logger.error(location, message, ...args);
|
|
90
|
+
},
|
|
91
|
+
fatal: (message, ...args)=>{
|
|
92
|
+
logger.fatal(location, message, ...args);
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
class LogSink {
|
|
97
|
+
}
|
|
98
|
+
const src_LogSink = LogSink;
|
|
99
|
+
const consoleMap = {
|
|
100
|
+
debug: (...args)=>{
|
|
101
|
+
console.debug(...args);
|
|
102
|
+
},
|
|
103
|
+
info: (...args)=>{
|
|
104
|
+
console.info(...args);
|
|
105
|
+
},
|
|
106
|
+
log: (...args)=>{
|
|
107
|
+
console.log(...args);
|
|
108
|
+
},
|
|
109
|
+
warn: (...args)=>{
|
|
110
|
+
console.warn(...args);
|
|
111
|
+
},
|
|
112
|
+
error: (...args)=>{
|
|
113
|
+
console.error(...args);
|
|
114
|
+
},
|
|
115
|
+
fatal: (...args)=>{
|
|
116
|
+
console.error(...args);
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
const COMPARISON_EQUALITY = 0;
|
|
120
|
+
class ConsoleLogSink extends src_LogSink {
|
|
121
|
+
name = 'ConsoleLogSink';
|
|
122
|
+
verbosity;
|
|
123
|
+
constructor(verbosity){
|
|
124
|
+
super();
|
|
125
|
+
this.verbosity = verbosity ?? 'error';
|
|
126
|
+
}
|
|
127
|
+
ingest(event) {
|
|
128
|
+
if (compare(this.verbosity, event.level) > COMPARISON_EQUALITY) return;
|
|
129
|
+
consoleMap[event.level](...event.messages);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
const MergeTagValueResolver_logger = createScopedLogger('Personalization');
|
|
133
|
+
const RESOLUTION_WARNING_BASE = 'Could not resolve Merge Tag value:';
|
|
134
|
+
const MergeTagValueResolver = {
|
|
135
|
+
isMergeTagEntry (embeddedEntryNodeTarget) {
|
|
136
|
+
return __rspack_external__contentful_optimization_api_client_cba5a7ee.MergeTagEntry.safeParse(embeddedEntryNodeTarget).success;
|
|
137
|
+
},
|
|
138
|
+
normalizeSelectors (id) {
|
|
139
|
+
return id.split('_').map((_path, index, paths)=>{
|
|
140
|
+
const dotPath = paths.slice(0, index).join('.');
|
|
141
|
+
const underScorePath = paths.slice(index).join('_');
|
|
142
|
+
return [
|
|
143
|
+
dotPath,
|
|
144
|
+
underScorePath
|
|
145
|
+
].filter((path)=>'' !== path).join('.');
|
|
146
|
+
});
|
|
147
|
+
},
|
|
148
|
+
getValueFromProfile (id, profile) {
|
|
149
|
+
const selectors = MergeTagValueResolver.normalizeSelectors(id);
|
|
150
|
+
const matchingSelector = selectors.find((selector)=>compat_get(profile, selector));
|
|
151
|
+
if (!matchingSelector) return;
|
|
152
|
+
const value = compat_get(profile, matchingSelector);
|
|
153
|
+
if (!value || 'string' != typeof value && 'number' != typeof value && 'boolean' != typeof value) return;
|
|
154
|
+
return `${value}`;
|
|
155
|
+
},
|
|
156
|
+
resolve (mergeTagEntry, profile) {
|
|
157
|
+
if (!MergeTagValueResolver.isMergeTagEntry(mergeTagEntry)) return void MergeTagValueResolver_logger.warn(`${RESOLUTION_WARNING_BASE} supplied entry is not a Merge Tag entry`);
|
|
158
|
+
const { fields: { nt_fallback: fallback } } = mergeTagEntry;
|
|
159
|
+
if (!__rspack_external__contentful_optimization_api_client_cba5a7ee.Profile.safeParse(profile).success) {
|
|
160
|
+
MergeTagValueResolver_logger.warn(`${RESOLUTION_WARNING_BASE} no valid profile`);
|
|
161
|
+
return fallback;
|
|
162
|
+
}
|
|
163
|
+
return MergeTagValueResolver.getValueFromProfile(mergeTagEntry.fields.nt_mergetag_id, profile) ?? fallback;
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
const resolvers_MergeTagValueResolver = MergeTagValueResolver;
|
|
167
|
+
const PersonalizedEntryResolver_logger = createScopedLogger('Personalization');
|
|
168
|
+
const PersonalizedEntryResolver_RESOLUTION_WARNING_BASE = 'Could not resolve personalized entry variant:';
|
|
169
|
+
const PersonalizedEntryResolver = {
|
|
170
|
+
getPersonalizationEntry ({ personalizedEntry, selectedPersonalizations }, skipValidation = false) {
|
|
171
|
+
if (!skipValidation && (!selectedPersonalizations.length || !(0, __rspack_external__contentful_optimization_api_client_cba5a7ee.isPersonalizedEntry)(personalizedEntry))) return;
|
|
172
|
+
const personalizationEntry = personalizedEntry.fields.nt_experiences.filter((maybePersonalization)=>(0, __rspack_external__contentful_optimization_api_client_cba5a7ee.isPersonalizationEntry)(maybePersonalization)).find((personalizationEntry)=>selectedPersonalizations.some(({ experienceId })=>experienceId === personalizationEntry.fields.nt_experience_id));
|
|
173
|
+
return personalizationEntry;
|
|
174
|
+
},
|
|
175
|
+
getSelectedPersonalization ({ personalizationEntry, selectedPersonalizations }, skipValidation = false) {
|
|
176
|
+
if (!skipValidation && (!selectedPersonalizations.length || !(0, __rspack_external__contentful_optimization_api_client_cba5a7ee.isPersonalizationEntry)(personalizationEntry))) return;
|
|
177
|
+
const selectedPersonalization = selectedPersonalizations.find(({ experienceId })=>experienceId === personalizationEntry.fields.nt_experience_id);
|
|
178
|
+
return selectedPersonalization;
|
|
179
|
+
},
|
|
180
|
+
getSelectedVariant ({ personalizedEntry, personalizationEntry, selectedVariantIndex }, skipValidation = false) {
|
|
181
|
+
if (!skipValidation && (!(0, __rspack_external__contentful_optimization_api_client_cba5a7ee.isPersonalizedEntry)(personalizedEntry) || !(0, __rspack_external__contentful_optimization_api_client_cba5a7ee.isPersonalizationEntry)(personalizationEntry))) return;
|
|
182
|
+
const relevantVariants = personalizationEntry.fields.nt_config?.components?.filter((component)=>(0, __rspack_external__contentful_optimization_api_client_cba5a7ee.isEntryReplacementComponent)(component) && !component.baseline.hidden).find((component)=>component.baseline.id === personalizedEntry.sys.id)?.variants;
|
|
183
|
+
if (!relevantVariants?.length) return;
|
|
184
|
+
return relevantVariants.at(selectedVariantIndex - 1);
|
|
185
|
+
},
|
|
186
|
+
getSelectedVariantEntry ({ personalizationEntry, selectedVariant }, skipValidation = false) {
|
|
187
|
+
if (!skipValidation && (!(0, __rspack_external__contentful_optimization_api_client_cba5a7ee.isPersonalizationEntry)(personalizationEntry) || !(0, __rspack_external__contentful_optimization_api_client_cba5a7ee.isEntryReplacementVariant)(selectedVariant))) return;
|
|
188
|
+
const selectedVariantEntry = personalizationEntry.fields.nt_variants?.find((variant)=>variant.sys.id === selectedVariant.id);
|
|
189
|
+
return (0, __rspack_external__contentful_optimization_api_client_cba5a7ee.isEntry)(selectedVariantEntry) ? selectedVariantEntry : void 0;
|
|
190
|
+
},
|
|
191
|
+
resolve (entry, selectedPersonalizations) {
|
|
192
|
+
PersonalizedEntryResolver_logger.debug(`Resolving personalized entry for baseline entry ${entry.sys.id}`);
|
|
193
|
+
if (!selectedPersonalizations?.length) {
|
|
194
|
+
PersonalizedEntryResolver_logger.warn(`${PersonalizedEntryResolver_RESOLUTION_WARNING_BASE} no selectedPersonalizations exist for the current profile`);
|
|
195
|
+
return {
|
|
196
|
+
entry
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
if (!(0, __rspack_external__contentful_optimization_api_client_cba5a7ee.isPersonalizedEntry)(entry)) {
|
|
200
|
+
PersonalizedEntryResolver_logger.warn(`${PersonalizedEntryResolver_RESOLUTION_WARNING_BASE} entry ${entry.sys.id} is not personalized`);
|
|
201
|
+
return {
|
|
202
|
+
entry
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
const personalizationEntry = PersonalizedEntryResolver.getPersonalizationEntry({
|
|
206
|
+
personalizedEntry: entry,
|
|
207
|
+
selectedPersonalizations
|
|
208
|
+
}, true);
|
|
209
|
+
if (!personalizationEntry) {
|
|
210
|
+
PersonalizedEntryResolver_logger.warn(`${PersonalizedEntryResolver_RESOLUTION_WARNING_BASE} could not find a personalization entry for ${entry.sys.id}`);
|
|
211
|
+
return {
|
|
212
|
+
entry
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
const selectedPersonalization = PersonalizedEntryResolver.getSelectedPersonalization({
|
|
216
|
+
personalizationEntry,
|
|
217
|
+
selectedPersonalizations
|
|
218
|
+
}, true);
|
|
219
|
+
const selectedVariantIndex = selectedPersonalization?.variantIndex ?? 0;
|
|
220
|
+
if (0 === selectedVariantIndex) {
|
|
221
|
+
PersonalizedEntryResolver_logger.debug(`Resolved personalization entry for entry ${entry.sys.id} is baseline`);
|
|
222
|
+
return {
|
|
223
|
+
entry
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
const selectedVariant = PersonalizedEntryResolver.getSelectedVariant({
|
|
227
|
+
personalizedEntry: entry,
|
|
228
|
+
personalizationEntry,
|
|
229
|
+
selectedVariantIndex
|
|
230
|
+
}, true);
|
|
231
|
+
if (!selectedVariant) {
|
|
232
|
+
PersonalizedEntryResolver_logger.warn(`${PersonalizedEntryResolver_RESOLUTION_WARNING_BASE} could not find a valid replacement variant entry for ${entry.sys.id}`);
|
|
233
|
+
return {
|
|
234
|
+
entry
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
const selectedVariantEntry = PersonalizedEntryResolver.getSelectedVariantEntry({
|
|
238
|
+
personalizationEntry,
|
|
239
|
+
selectedVariant
|
|
240
|
+
}, true);
|
|
241
|
+
if (selectedVariantEntry) PersonalizedEntryResolver_logger.debug(`Entry ${entry.sys.id} has been resolved to variant entry ${selectedVariantEntry.sys.id}`);
|
|
242
|
+
else {
|
|
243
|
+
PersonalizedEntryResolver_logger.warn(`${PersonalizedEntryResolver_RESOLUTION_WARNING_BASE} could not find a valid replacement variant entry for ${entry.sys.id}`);
|
|
244
|
+
return {
|
|
245
|
+
entry
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
return {
|
|
249
|
+
entry: selectedVariantEntry,
|
|
250
|
+
personalization: selectedPersonalization
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
const resolvers_PersonalizedEntryResolver = PersonalizedEntryResolver;
|
|
255
|
+
const signals_changes = signal();
|
|
256
|
+
const consent = signal();
|
|
257
|
+
const signals_event = signal();
|
|
258
|
+
const flags = computed(()=>resolvers_FlagsResolver.resolve(signals_changes.value ?? []));
|
|
259
|
+
const online = signal(true);
|
|
260
|
+
const signals_personalizations = signal();
|
|
261
|
+
const signals_profile = signal();
|
|
262
|
+
function toObservable(s) {
|
|
263
|
+
return {
|
|
264
|
+
subscribe (next) {
|
|
265
|
+
const dispose = effect(()=>{
|
|
266
|
+
next(s.value);
|
|
267
|
+
});
|
|
268
|
+
return {
|
|
269
|
+
unsubscribe: dispose
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
const signals = {
|
|
275
|
+
changes: signals_changes,
|
|
276
|
+
consent: consent,
|
|
277
|
+
event: signals_event,
|
|
278
|
+
flags: flags,
|
|
279
|
+
online: online,
|
|
280
|
+
personalizations: signals_personalizations,
|
|
281
|
+
profile: signals_profile
|
|
282
|
+
};
|
|
283
|
+
const isFunction = (v)=>'function' == typeof v;
|
|
284
|
+
const nameToString = (name)=>'string' == typeof name ? name : 'symbol' == typeof name ? name.description ?? String(name) : String(name);
|
|
285
|
+
const isOnBlockedKey = (v)=>'string' == typeof v || 'symbol' == typeof v;
|
|
286
|
+
const isAsyncFunction = (fn)=>'[object AsyncFunction]' === Object.prototype.toString.call(fn);
|
|
287
|
+
function guardedBy(predicateName, opts) {
|
|
288
|
+
return function(_value, context) {
|
|
289
|
+
const decoratedName = nameToString(context.name);
|
|
290
|
+
context.addInitializer(function() {
|
|
291
|
+
const originalUnknown = Reflect.get(this, context.name);
|
|
292
|
+
if (!isFunction(originalUnknown)) return;
|
|
293
|
+
const original = originalUnknown;
|
|
294
|
+
const originalIsAsync = isAsyncFunction(original);
|
|
295
|
+
const resolvePredicate = (self)=>{
|
|
296
|
+
const { [predicateName]: cand } = self;
|
|
297
|
+
if (!isFunction(cand)) throw new TypeError(`@guardedBy expects predicate "${String(predicateName)}" to be a synchronous function.`);
|
|
298
|
+
return cand;
|
|
299
|
+
};
|
|
300
|
+
const computeAllowed = (self, args)=>{
|
|
301
|
+
const pred = resolvePredicate(self);
|
|
302
|
+
const ok = Boolean(pred.call(self, decoratedName, args));
|
|
303
|
+
return opts?.invert === true ? !ok : ok;
|
|
304
|
+
};
|
|
305
|
+
const runOnBlocked = (self, args)=>{
|
|
306
|
+
const { onBlocked } = opts ?? {};
|
|
307
|
+
if (void 0 === onBlocked) return;
|
|
308
|
+
if (isFunction(onBlocked)) return void onBlocked.call(self, decoratedName, args);
|
|
309
|
+
if (isOnBlockedKey(onBlocked)) {
|
|
310
|
+
const { [onBlocked]: handlerCandidate } = self;
|
|
311
|
+
if (isFunction(handlerCandidate)) handlerCandidate.call(self, decoratedName, args);
|
|
312
|
+
}
|
|
313
|
+
};
|
|
314
|
+
const blockedReturn = ()=>originalIsAsync ? Promise.resolve(void 0) : void 0;
|
|
315
|
+
const wrapped = function(...args) {
|
|
316
|
+
if (!computeAllowed(this, args)) {
|
|
317
|
+
runOnBlocked(this, args);
|
|
318
|
+
return blockedReturn();
|
|
319
|
+
}
|
|
320
|
+
return original.call(this, ...args);
|
|
321
|
+
};
|
|
322
|
+
Reflect.set(this, context.name, wrapped);
|
|
323
|
+
});
|
|
324
|
+
};
|
|
325
|
+
}
|
|
326
|
+
class ValuePresence {
|
|
327
|
+
#map;
|
|
328
|
+
constructor(defaultMap){
|
|
329
|
+
const map = new Map();
|
|
330
|
+
if (defaultMap) Object.entries(defaultMap).map(([scope, values])=>map.set(scope.length ? scope : void 0, new Set(values)));
|
|
331
|
+
this.#map = map;
|
|
332
|
+
}
|
|
333
|
+
isPresent(scope, value) {
|
|
334
|
+
return this.#map.get(scope)?.has(value) ?? false;
|
|
335
|
+
}
|
|
336
|
+
addValue(scope, value) {
|
|
337
|
+
const values = this.#map.get(scope);
|
|
338
|
+
if (values) values.add(value);
|
|
339
|
+
else this.#map.set(scope, new Set([
|
|
340
|
+
value
|
|
341
|
+
]));
|
|
342
|
+
}
|
|
343
|
+
removeValue(scope, value) {
|
|
344
|
+
this.#map.get(scope)?.delete(value);
|
|
345
|
+
}
|
|
346
|
+
reset(scope) {
|
|
347
|
+
if (void 0 !== scope) this.#map.get(scope)?.clear();
|
|
348
|
+
else this.#map.clear();
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
const value_presence_ValuePresence = ValuePresence;
|
|
352
|
+
const defaultAllowedEvents = [
|
|
353
|
+
'page',
|
|
354
|
+
'identify'
|
|
355
|
+
];
|
|
356
|
+
class ProductBase {
|
|
357
|
+
allowedEventTypes;
|
|
358
|
+
builder;
|
|
359
|
+
api;
|
|
360
|
+
duplicationDetector;
|
|
361
|
+
interceptors;
|
|
362
|
+
constructor(options){
|
|
363
|
+
const { api, builder, config, interceptors } = options;
|
|
364
|
+
this.allowedEventTypes = config?.allowedEventTypes ?? defaultAllowedEvents;
|
|
365
|
+
this.api = api;
|
|
366
|
+
this.builder = builder;
|
|
367
|
+
this.duplicationDetector = new value_presence_ValuePresence(config?.preventedComponentEvents);
|
|
368
|
+
this.interceptors = interceptors;
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
const src_ProductBase = ProductBase;
|
|
372
|
+
class AnalyticsBase extends src_ProductBase {
|
|
373
|
+
}
|
|
374
|
+
const analytics_AnalyticsBase = AnalyticsBase;
|
|
375
|
+
function applyDecs2203RFactory() {
|
|
376
|
+
function createAddInitializerMethod(initializers, decoratorFinishedRef) {
|
|
377
|
+
return function(initializer) {
|
|
378
|
+
assertNotFinished(decoratorFinishedRef, "addInitializer");
|
|
379
|
+
assertCallable(initializer, "An initializer");
|
|
380
|
+
initializers.push(initializer);
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
function memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value) {
|
|
384
|
+
var kindStr;
|
|
385
|
+
switch(kind){
|
|
386
|
+
case 1:
|
|
387
|
+
kindStr = "accessor";
|
|
388
|
+
break;
|
|
389
|
+
case 2:
|
|
390
|
+
kindStr = "method";
|
|
391
|
+
break;
|
|
392
|
+
case 3:
|
|
393
|
+
kindStr = "getter";
|
|
394
|
+
break;
|
|
395
|
+
case 4:
|
|
396
|
+
kindStr = "setter";
|
|
397
|
+
break;
|
|
398
|
+
default:
|
|
399
|
+
kindStr = "field";
|
|
400
|
+
}
|
|
401
|
+
var ctx = {
|
|
402
|
+
kind: kindStr,
|
|
403
|
+
name: isPrivate ? "#" + name : name,
|
|
404
|
+
static: isStatic,
|
|
405
|
+
private: isPrivate,
|
|
406
|
+
metadata: metadata
|
|
407
|
+
};
|
|
408
|
+
var decoratorFinishedRef = {
|
|
409
|
+
v: false
|
|
410
|
+
};
|
|
411
|
+
ctx.addInitializer = createAddInitializerMethod(initializers, decoratorFinishedRef);
|
|
412
|
+
var get, set;
|
|
413
|
+
if (0 === kind) if (isPrivate) {
|
|
414
|
+
get = desc.get;
|
|
415
|
+
set = desc.set;
|
|
416
|
+
} else {
|
|
417
|
+
get = function() {
|
|
418
|
+
return this[name];
|
|
419
|
+
};
|
|
420
|
+
set = function(v) {
|
|
421
|
+
this[name] = v;
|
|
422
|
+
};
|
|
423
|
+
}
|
|
424
|
+
else if (2 === kind) get = function() {
|
|
425
|
+
return desc.value;
|
|
426
|
+
};
|
|
427
|
+
else {
|
|
428
|
+
if (1 === kind || 3 === kind) get = function() {
|
|
429
|
+
return desc.get.call(this);
|
|
430
|
+
};
|
|
431
|
+
if (1 === kind || 4 === kind) set = function(v) {
|
|
432
|
+
desc.set.call(this, v);
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
ctx.access = get && set ? {
|
|
436
|
+
get: get,
|
|
437
|
+
set: set
|
|
438
|
+
} : get ? {
|
|
439
|
+
get: get
|
|
440
|
+
} : {
|
|
441
|
+
set: set
|
|
442
|
+
};
|
|
443
|
+
try {
|
|
444
|
+
return dec(value, ctx);
|
|
445
|
+
} finally{
|
|
446
|
+
decoratorFinishedRef.v = true;
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
function assertNotFinished(decoratorFinishedRef, fnName) {
|
|
450
|
+
if (decoratorFinishedRef.v) throw new Error("attempted to call " + fnName + " after decoration was finished");
|
|
451
|
+
}
|
|
452
|
+
function assertCallable(fn, hint) {
|
|
453
|
+
if ("function" != typeof fn) throw new TypeError(hint + " must be a function");
|
|
454
|
+
}
|
|
455
|
+
function assertValidReturnValue(kind, value) {
|
|
456
|
+
var type = typeof value;
|
|
457
|
+
if (1 === kind) {
|
|
458
|
+
if ("object" !== type || null === value) throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");
|
|
459
|
+
if (void 0 !== value.get) assertCallable(value.get, "accessor.get");
|
|
460
|
+
if (void 0 !== value.set) assertCallable(value.set, "accessor.set");
|
|
461
|
+
if (void 0 !== value.init) assertCallable(value.init, "accessor.init");
|
|
462
|
+
} else if ("function" !== type) {
|
|
463
|
+
var hint;
|
|
464
|
+
hint = 0 === kind ? "field" : 10 === kind ? "class" : "method";
|
|
465
|
+
throw new TypeError(hint + " decorators must return a function or void 0");
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
function applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata) {
|
|
469
|
+
var decs = decInfo[0];
|
|
470
|
+
var desc, init, value;
|
|
471
|
+
if (isPrivate) desc = 0 === kind || 1 === kind ? {
|
|
472
|
+
get: decInfo[3],
|
|
473
|
+
set: decInfo[4]
|
|
474
|
+
} : 3 === kind ? {
|
|
475
|
+
get: decInfo[3]
|
|
476
|
+
} : 4 === kind ? {
|
|
477
|
+
set: decInfo[3]
|
|
478
|
+
} : {
|
|
479
|
+
value: decInfo[3]
|
|
480
|
+
};
|
|
481
|
+
else if (0 !== kind) desc = Object.getOwnPropertyDescriptor(base, name);
|
|
482
|
+
if (1 === kind) value = {
|
|
483
|
+
get: desc.get,
|
|
484
|
+
set: desc.set
|
|
485
|
+
};
|
|
486
|
+
else if (2 === kind) value = desc.value;
|
|
487
|
+
else if (3 === kind) value = desc.get;
|
|
488
|
+
else if (4 === kind) value = desc.set;
|
|
489
|
+
var newValue, get, set;
|
|
490
|
+
if ("function" == typeof decs) {
|
|
491
|
+
newValue = memberDec(decs, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
|
|
492
|
+
if (void 0 !== newValue) {
|
|
493
|
+
assertValidReturnValue(kind, newValue);
|
|
494
|
+
if (0 === kind) init = newValue;
|
|
495
|
+
else if (1 === kind) {
|
|
496
|
+
init = newValue.init;
|
|
497
|
+
get = newValue.get || value.get;
|
|
498
|
+
set = newValue.set || value.set;
|
|
499
|
+
value = {
|
|
500
|
+
get: get,
|
|
501
|
+
set: set
|
|
502
|
+
};
|
|
503
|
+
} else value = newValue;
|
|
504
|
+
}
|
|
505
|
+
} else for(var i = decs.length - 1; i >= 0; i--){
|
|
506
|
+
var dec = decs[i];
|
|
507
|
+
newValue = memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
|
|
508
|
+
if (void 0 !== newValue) {
|
|
509
|
+
assertValidReturnValue(kind, newValue);
|
|
510
|
+
var newInit;
|
|
511
|
+
if (0 === kind) newInit = newValue;
|
|
512
|
+
else if (1 === kind) {
|
|
513
|
+
newInit = newValue.init;
|
|
514
|
+
get = newValue.get || value.get;
|
|
515
|
+
set = newValue.set || value.set;
|
|
516
|
+
value = {
|
|
517
|
+
get: get,
|
|
518
|
+
set: set
|
|
519
|
+
};
|
|
520
|
+
} else value = newValue;
|
|
521
|
+
if (void 0 !== newInit) if (void 0 === init) init = newInit;
|
|
522
|
+
else if ("function" == typeof init) init = [
|
|
523
|
+
init,
|
|
524
|
+
newInit
|
|
525
|
+
];
|
|
526
|
+
else init.push(newInit);
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
if (0 === kind || 1 === kind) {
|
|
530
|
+
if (void 0 === init) init = function(instance, init) {
|
|
531
|
+
return init;
|
|
532
|
+
};
|
|
533
|
+
else if ("function" != typeof init) {
|
|
534
|
+
var ownInitializers = init;
|
|
535
|
+
init = function(instance, init) {
|
|
536
|
+
var value = init;
|
|
537
|
+
for(var i = 0; i < ownInitializers.length; i++)value = ownInitializers[i].call(instance, value);
|
|
538
|
+
return value;
|
|
539
|
+
};
|
|
540
|
+
} else {
|
|
541
|
+
var originalInitializer = init;
|
|
542
|
+
init = function(instance, init) {
|
|
543
|
+
return originalInitializer.call(instance, init);
|
|
544
|
+
};
|
|
545
|
+
}
|
|
546
|
+
ret.push(init);
|
|
547
|
+
}
|
|
548
|
+
if (0 !== kind) {
|
|
549
|
+
if (1 === kind) {
|
|
550
|
+
desc.get = value.get;
|
|
551
|
+
desc.set = value.set;
|
|
552
|
+
} else if (2 === kind) desc.value = value;
|
|
553
|
+
else if (3 === kind) desc.get = value;
|
|
554
|
+
else if (4 === kind) desc.set = value;
|
|
555
|
+
if (isPrivate) if (1 === kind) {
|
|
556
|
+
ret.push(function(instance, args) {
|
|
557
|
+
return value.get.call(instance, args);
|
|
558
|
+
});
|
|
559
|
+
ret.push(function(instance, args) {
|
|
560
|
+
return value.set.call(instance, args);
|
|
561
|
+
});
|
|
562
|
+
} else if (2 === kind) ret.push(value);
|
|
563
|
+
else ret.push(function(instance, args) {
|
|
564
|
+
return value.call(instance, args);
|
|
565
|
+
});
|
|
566
|
+
else Object.defineProperty(base, name, desc);
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
function applyMemberDecs(Class, decInfos, metadata) {
|
|
570
|
+
var ret = [];
|
|
571
|
+
var protoInitializers;
|
|
572
|
+
var staticInitializers;
|
|
573
|
+
var existingProtoNonFields = new Map();
|
|
574
|
+
var existingStaticNonFields = new Map();
|
|
575
|
+
for(var i = 0; i < decInfos.length; i++){
|
|
576
|
+
var decInfo = decInfos[i];
|
|
577
|
+
if (Array.isArray(decInfo)) {
|
|
578
|
+
var kind = decInfo[1];
|
|
579
|
+
var name = decInfo[2];
|
|
580
|
+
var isPrivate = decInfo.length > 3;
|
|
581
|
+
var isStatic = kind >= 5;
|
|
582
|
+
var base;
|
|
583
|
+
var initializers;
|
|
584
|
+
if (isStatic) {
|
|
585
|
+
base = Class;
|
|
586
|
+
kind -= 5;
|
|
587
|
+
staticInitializers = staticInitializers || [];
|
|
588
|
+
initializers = staticInitializers;
|
|
589
|
+
} else {
|
|
590
|
+
base = Class.prototype;
|
|
591
|
+
protoInitializers = protoInitializers || [];
|
|
592
|
+
initializers = protoInitializers;
|
|
593
|
+
}
|
|
594
|
+
if (0 !== kind && !isPrivate) {
|
|
595
|
+
var existingNonFields = isStatic ? existingStaticNonFields : existingProtoNonFields;
|
|
596
|
+
var existingKind = existingNonFields.get(name) || 0;
|
|
597
|
+
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);
|
|
598
|
+
if (!existingKind && kind > 2) existingNonFields.set(name, kind);
|
|
599
|
+
else existingNonFields.set(name, true);
|
|
600
|
+
}
|
|
601
|
+
applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata);
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
pushInitializers(ret, protoInitializers);
|
|
605
|
+
pushInitializers(ret, staticInitializers);
|
|
606
|
+
return ret;
|
|
607
|
+
}
|
|
608
|
+
function pushInitializers(ret, initializers) {
|
|
609
|
+
if (initializers) ret.push(function(instance) {
|
|
610
|
+
for(var i = 0; i < initializers.length; i++)initializers[i].call(instance);
|
|
611
|
+
return instance;
|
|
612
|
+
});
|
|
613
|
+
}
|
|
614
|
+
function applyClassDecs(targetClass, classDecs, metadata) {
|
|
615
|
+
if (classDecs.length > 0) {
|
|
616
|
+
var initializers = [];
|
|
617
|
+
var newClass = targetClass;
|
|
618
|
+
var name = targetClass.name;
|
|
619
|
+
for(var i = classDecs.length - 1; i >= 0; i--){
|
|
620
|
+
var decoratorFinishedRef = {
|
|
621
|
+
v: false
|
|
622
|
+
};
|
|
623
|
+
try {
|
|
624
|
+
var nextNewClass = classDecs[i](newClass, {
|
|
625
|
+
kind: "class",
|
|
626
|
+
name: name,
|
|
627
|
+
addInitializer: createAddInitializerMethod(initializers, decoratorFinishedRef),
|
|
628
|
+
metadata
|
|
629
|
+
});
|
|
630
|
+
} finally{
|
|
631
|
+
decoratorFinishedRef.v = true;
|
|
632
|
+
}
|
|
633
|
+
if (void 0 !== nextNewClass) {
|
|
634
|
+
assertValidReturnValue(10, nextNewClass);
|
|
635
|
+
newClass = nextNewClass;
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
return [
|
|
639
|
+
defineMetadata(newClass, metadata),
|
|
640
|
+
function() {
|
|
641
|
+
for(var i = 0; i < initializers.length; i++)initializers[i].call(newClass);
|
|
642
|
+
}
|
|
643
|
+
];
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
function defineMetadata(Class, metadata) {
|
|
647
|
+
return Object.defineProperty(Class, Symbol.metadata || Symbol.for("Symbol.metadata"), {
|
|
648
|
+
configurable: true,
|
|
649
|
+
enumerable: true,
|
|
650
|
+
value: metadata
|
|
651
|
+
});
|
|
652
|
+
}
|
|
653
|
+
return function(targetClass, memberDecs, classDecs, parentClass) {
|
|
654
|
+
if (void 0 !== parentClass) var parentMetadata = parentClass[Symbol.metadata || Symbol.for("Symbol.metadata")];
|
|
655
|
+
var metadata = Object.create(void 0 === parentMetadata ? null : parentMetadata);
|
|
656
|
+
var e = applyMemberDecs(targetClass, memberDecs, metadata);
|
|
657
|
+
if (!classDecs.length) defineMetadata(targetClass, metadata);
|
|
658
|
+
return {
|
|
659
|
+
e: e,
|
|
660
|
+
get c () {
|
|
661
|
+
return applyClassDecs(targetClass, classDecs, metadata);
|
|
662
|
+
}
|
|
663
|
+
};
|
|
664
|
+
};
|
|
665
|
+
}
|
|
666
|
+
function _apply_decs_2203_r(targetClass, memberDecs, classDecs, parentClass) {
|
|
667
|
+
return (_apply_decs_2203_r = applyDecs2203RFactory())(targetClass, memberDecs, classDecs, parentClass);
|
|
668
|
+
}
|
|
669
|
+
var _dec, _dec1, _dec2, _dec3, _initProto;
|
|
670
|
+
const AnalyticsStateful_logger = createScopedLogger('Analytics');
|
|
671
|
+
const MAX_QUEUED_EVENTS = 25;
|
|
672
|
+
_dec = guardedBy('isNotDuplicated', {
|
|
673
|
+
onBlocked: 'onBlockedByDuplication'
|
|
674
|
+
}), _dec1 = guardedBy('hasConsent', {
|
|
675
|
+
onBlocked: 'onBlockedByConsent'
|
|
676
|
+
}), _dec2 = guardedBy('isNotDuplicated', {
|
|
677
|
+
onBlocked: 'onBlockedByDuplication'
|
|
678
|
+
}), _dec3 = guardedBy('hasConsent', {
|
|
679
|
+
onBlocked: 'onBlockedByConsent'
|
|
680
|
+
});
|
|
681
|
+
class AnalyticsStateful extends analytics_AnalyticsBase {
|
|
682
|
+
static{
|
|
683
|
+
({ e: [_initProto] } = _apply_decs_2203_r(this, [
|
|
684
|
+
[
|
|
685
|
+
[
|
|
686
|
+
_dec,
|
|
687
|
+
_dec1
|
|
688
|
+
],
|
|
689
|
+
2,
|
|
690
|
+
"trackComponentView"
|
|
691
|
+
],
|
|
692
|
+
[
|
|
693
|
+
[
|
|
694
|
+
_dec2,
|
|
695
|
+
_dec3
|
|
696
|
+
],
|
|
697
|
+
2,
|
|
698
|
+
"trackFlagView"
|
|
699
|
+
]
|
|
700
|
+
], []));
|
|
701
|
+
}
|
|
702
|
+
queue = (_initProto(this), new Map());
|
|
703
|
+
states = {
|
|
704
|
+
eventStream: toObservable(signals_event),
|
|
705
|
+
profile: toObservable(signals_profile)
|
|
706
|
+
};
|
|
707
|
+
constructor(options){
|
|
708
|
+
const { api, builder, config, interceptors } = options;
|
|
709
|
+
super({
|
|
710
|
+
api,
|
|
711
|
+
builder,
|
|
712
|
+
config,
|
|
713
|
+
interceptors
|
|
714
|
+
});
|
|
715
|
+
const { defaults } = config ?? {};
|
|
716
|
+
if (defaults?.profile !== void 0) {
|
|
717
|
+
const { profile: defaultProfile } = defaults;
|
|
718
|
+
signals_profile.value = defaultProfile;
|
|
719
|
+
}
|
|
720
|
+
effect(()=>{
|
|
721
|
+
const id = signals_profile.value?.id;
|
|
722
|
+
AnalyticsStateful_logger.info(`Analytics ${consent.value ? 'will' : 'will not'} be collected due to consent (${consent.value})`);
|
|
723
|
+
AnalyticsStateful_logger.debug(`Profile ${id && `with ID ${id}`} has been ${id ? 'set' : 'cleared'}`);
|
|
724
|
+
});
|
|
725
|
+
effect(()=>{
|
|
726
|
+
if (online.value) this.flush();
|
|
727
|
+
});
|
|
728
|
+
}
|
|
729
|
+
reset() {
|
|
730
|
+
batch(()=>{
|
|
731
|
+
signals_event.value = void 0;
|
|
732
|
+
signals_profile.value = void 0;
|
|
733
|
+
});
|
|
734
|
+
}
|
|
735
|
+
hasConsent(name) {
|
|
736
|
+
return !!consent.value || (this.allowedEventTypes ?? []).includes('trackComponentView' === name || 'trackFlagView' === name ? 'component' : name);
|
|
737
|
+
}
|
|
738
|
+
onBlockedByConsent(name, payload) {
|
|
739
|
+
AnalyticsStateful_logger.warn(`Event "${name}" was blocked due to lack of consent; payload: ${JSON.stringify(payload)}`);
|
|
740
|
+
}
|
|
741
|
+
isNotDuplicated(_name, payload) {
|
|
742
|
+
const [{ componentId: value }, duplicationScope] = payload;
|
|
743
|
+
const isDuplicated = this.duplicationDetector.isPresent(duplicationScope, value);
|
|
744
|
+
if (!isDuplicated) this.duplicationDetector.addValue(duplicationScope, value);
|
|
745
|
+
return !isDuplicated;
|
|
746
|
+
}
|
|
747
|
+
onBlockedByDuplication(name, payload) {
|
|
748
|
+
const componentType = 'trackFlagView' === name ? 'flag' : 'component';
|
|
749
|
+
AnalyticsStateful_logger.debug(`Duplicate "${componentType} view" event detected, skipping; payload: ${JSON.stringify(payload)}`);
|
|
750
|
+
}
|
|
751
|
+
async trackComponentView(payload, _duplicationScope = '') {
|
|
752
|
+
AnalyticsStateful_logger.info(`Processing "component view" event for ${payload.componentId}`);
|
|
753
|
+
await this.enqueueEvent(this.builder.buildComponentView(payload));
|
|
754
|
+
}
|
|
755
|
+
async trackFlagView(payload, _duplicationScope = '') {
|
|
756
|
+
AnalyticsStateful_logger.debug(`Processing "flag view" event for ${payload.componentId}`);
|
|
757
|
+
await this.enqueueEvent(this.builder.buildFlagView(payload));
|
|
758
|
+
}
|
|
759
|
+
async enqueueEvent(event) {
|
|
760
|
+
const { value: profile } = signals_profile;
|
|
761
|
+
if (!profile) return void AnalyticsStateful_logger.warn('Attempting to emit an event without an Optimization profile');
|
|
762
|
+
const intercepted = await this.interceptors.event.run(event);
|
|
763
|
+
const validEvent = __rspack_external__contentful_optimization_api_client_cba5a7ee.InsightsEvent.parse(intercepted);
|
|
764
|
+
AnalyticsStateful_logger.debug(`Queueing ${validEvent.type} event for profile ${profile.id}`, validEvent);
|
|
765
|
+
const profileEventQueue = this.queue.get(profile);
|
|
766
|
+
signals_event.value = validEvent;
|
|
767
|
+
if (profileEventQueue) profileEventQueue.push(validEvent);
|
|
768
|
+
else this.queue.set(profile, [
|
|
769
|
+
validEvent
|
|
770
|
+
]);
|
|
771
|
+
await this.flushMaxEvents();
|
|
772
|
+
}
|
|
773
|
+
async flushMaxEvents() {
|
|
774
|
+
if (this.queue.values().toArray().flat().length >= MAX_QUEUED_EVENTS) await this.flush();
|
|
775
|
+
}
|
|
776
|
+
async flush() {
|
|
777
|
+
AnalyticsStateful_logger.debug('Flushing event queue');
|
|
778
|
+
const batches = [];
|
|
779
|
+
this.queue.forEach((events, profile)=>batches.push({
|
|
780
|
+
profile,
|
|
781
|
+
events
|
|
782
|
+
}));
|
|
783
|
+
if (!batches.length) return;
|
|
784
|
+
const sendSuccess = await this.api.insights.sendBatchEvents(batches);
|
|
785
|
+
if (sendSuccess) this.queue.clear();
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
const analytics_AnalyticsStateful = AnalyticsStateful;
|
|
789
|
+
const AnalyticsStateless_logger = createScopedLogger('Analytics');
|
|
790
|
+
class AnalyticsStateless extends analytics_AnalyticsBase {
|
|
791
|
+
async trackComponentView(args) {
|
|
792
|
+
AnalyticsStateless_logger.info('Processing "component view" event');
|
|
793
|
+
const { profile, ...builderArgs } = args;
|
|
794
|
+
const event = this.builder.buildComponentView(builderArgs);
|
|
795
|
+
const intercepted = await this.interceptors.event.run(event);
|
|
796
|
+
const parsed = __rspack_external__contentful_optimization_api_client_cba5a7ee.ComponentViewEvent.parse(intercepted);
|
|
797
|
+
await this.sendBatchEvent(parsed, profile);
|
|
798
|
+
}
|
|
799
|
+
async trackFlagView(args) {
|
|
800
|
+
AnalyticsStateless_logger.debug('Processing "flag view" event');
|
|
801
|
+
const { profile, ...builderArgs } = args;
|
|
802
|
+
const event = this.builder.buildFlagView(builderArgs);
|
|
803
|
+
const intercepted = await this.interceptors.event.run(event);
|
|
804
|
+
const parsed = __rspack_external__contentful_optimization_api_client_cba5a7ee.ComponentViewEvent.parse(intercepted);
|
|
805
|
+
await this.sendBatchEvent(parsed, profile);
|
|
806
|
+
}
|
|
807
|
+
async sendBatchEvent(event, profile) {
|
|
808
|
+
const batchEvent = __rspack_external__contentful_optimization_api_client_cba5a7ee.BatchInsightsEventArray.parse([
|
|
809
|
+
{
|
|
810
|
+
profile,
|
|
811
|
+
events: [
|
|
812
|
+
event
|
|
813
|
+
]
|
|
814
|
+
}
|
|
815
|
+
]);
|
|
816
|
+
await this.api.insights.sendBatchEvents(batchEvent);
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
const analytics_AnalyticsStateless = AnalyticsStateless;
|
|
820
|
+
const OPTIMIZATION_CORE_SDK_VERSION = "0.1.0-alpha";
|
|
821
|
+
const ANONYMOUS_ID_COOKIE = 'ctfl-opt-aid';
|
|
822
|
+
class InterceptorManager {
|
|
823
|
+
interceptors = new Map();
|
|
824
|
+
nextId = 0;
|
|
825
|
+
add(interceptor) {
|
|
826
|
+
const { nextId: id } = this;
|
|
827
|
+
this.nextId += 1;
|
|
828
|
+
this.interceptors.set(id, interceptor);
|
|
829
|
+
return id;
|
|
830
|
+
}
|
|
831
|
+
remove(id) {
|
|
832
|
+
return this.interceptors.delete(id);
|
|
833
|
+
}
|
|
834
|
+
clear() {
|
|
835
|
+
this.interceptors.clear();
|
|
836
|
+
}
|
|
837
|
+
count() {
|
|
838
|
+
return this.interceptors.size;
|
|
839
|
+
}
|
|
840
|
+
async run(input) {
|
|
841
|
+
const fns = Array.from(this.interceptors.values());
|
|
842
|
+
let acc = input;
|
|
843
|
+
for (const fn of fns)acc = await fn(acc);
|
|
844
|
+
return acc;
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
class CoreBase {
|
|
848
|
+
api;
|
|
849
|
+
eventBuilder;
|
|
850
|
+
config;
|
|
851
|
+
interceptors = {
|
|
852
|
+
event: new InterceptorManager(),
|
|
853
|
+
state: new InterceptorManager()
|
|
854
|
+
};
|
|
855
|
+
constructor(config){
|
|
856
|
+
this.config = config;
|
|
857
|
+
const { analytics, personalization, eventBuilder, logLevel, environment, clientId } = config;
|
|
858
|
+
logger.addSink(new ConsoleLogSink(logLevel));
|
|
859
|
+
const apiConfig = {
|
|
860
|
+
...analytics,
|
|
861
|
+
...personalization,
|
|
862
|
+
clientId,
|
|
863
|
+
environment
|
|
864
|
+
};
|
|
865
|
+
this.api = new __rspack_external__contentful_optimization_api_client_cba5a7ee.ApiClient(apiConfig);
|
|
866
|
+
this.eventBuilder = new __rspack_external__contentful_optimization_api_client_cba5a7ee.EventBuilder(eventBuilder ?? {
|
|
867
|
+
channel: 'server',
|
|
868
|
+
library: {
|
|
869
|
+
name: 'Optimization Core',
|
|
870
|
+
version: OPTIMIZATION_CORE_SDK_VERSION
|
|
871
|
+
}
|
|
872
|
+
});
|
|
873
|
+
}
|
|
874
|
+
getCustomFlag(name, changes) {
|
|
875
|
+
return this.personalization.getCustomFlag(name, changes);
|
|
876
|
+
}
|
|
877
|
+
personalizeEntry(entry, personalizations) {
|
|
878
|
+
return this.personalization.personalizeEntry(entry, personalizations);
|
|
879
|
+
}
|
|
880
|
+
getMergeTagValue(embeddedEntryNodeTarget, profile) {
|
|
881
|
+
return this.personalization.getMergeTagValue(embeddedEntryNodeTarget, profile);
|
|
882
|
+
}
|
|
883
|
+
async identify(payload) {
|
|
884
|
+
return await this.personalization.identify(payload);
|
|
885
|
+
}
|
|
886
|
+
async page(payload) {
|
|
887
|
+
return await this.personalization.page(payload);
|
|
888
|
+
}
|
|
889
|
+
async screen(payload) {
|
|
890
|
+
return await this.personalization.screen(payload);
|
|
891
|
+
}
|
|
892
|
+
async track(payload) {
|
|
893
|
+
return await this.personalization.track(payload);
|
|
894
|
+
}
|
|
895
|
+
async trackComponentView(payload, duplicationScope) {
|
|
896
|
+
if (payload.sticky) return await this.personalization.trackComponentView(payload, duplicationScope);
|
|
897
|
+
await this.analytics.trackComponentView(payload, duplicationScope);
|
|
898
|
+
}
|
|
899
|
+
async trackFlagView(payload, duplicationScope) {
|
|
900
|
+
await this.analytics.trackFlagView(payload, duplicationScope);
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
const src_CoreBase = CoreBase;
|
|
904
|
+
class PersonalizationBase extends src_ProductBase {
|
|
905
|
+
flagsResolver = resolvers_FlagsResolver;
|
|
906
|
+
mergeTagValueResolver = resolvers_MergeTagValueResolver;
|
|
907
|
+
personalizedEntryResolver = resolvers_PersonalizedEntryResolver;
|
|
908
|
+
getCustomFlag(name, changes) {
|
|
909
|
+
return resolvers_FlagsResolver.resolve(changes)[name];
|
|
910
|
+
}
|
|
911
|
+
personalizeEntry(entry, personalizations) {
|
|
912
|
+
return resolvers_PersonalizedEntryResolver.resolve(entry, personalizations);
|
|
913
|
+
}
|
|
914
|
+
getMergeTagValue(embeddedEntryNodeTarget, profile) {
|
|
915
|
+
return resolvers_MergeTagValueResolver.resolve(embeddedEntryNodeTarget, profile);
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
const personalization_PersonalizationBase = PersonalizationBase;
|
|
919
|
+
function PersonalizationStateful_applyDecs2203RFactory() {
|
|
920
|
+
function createAddInitializerMethod(initializers, decoratorFinishedRef) {
|
|
921
|
+
return function(initializer) {
|
|
922
|
+
assertNotFinished(decoratorFinishedRef, "addInitializer");
|
|
923
|
+
assertCallable(initializer, "An initializer");
|
|
924
|
+
initializers.push(initializer);
|
|
925
|
+
};
|
|
926
|
+
}
|
|
927
|
+
function memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value) {
|
|
928
|
+
var kindStr;
|
|
929
|
+
switch(kind){
|
|
930
|
+
case 1:
|
|
931
|
+
kindStr = "accessor";
|
|
932
|
+
break;
|
|
933
|
+
case 2:
|
|
934
|
+
kindStr = "method";
|
|
935
|
+
break;
|
|
936
|
+
case 3:
|
|
937
|
+
kindStr = "getter";
|
|
938
|
+
break;
|
|
939
|
+
case 4:
|
|
940
|
+
kindStr = "setter";
|
|
941
|
+
break;
|
|
942
|
+
default:
|
|
943
|
+
kindStr = "field";
|
|
944
|
+
}
|
|
945
|
+
var ctx = {
|
|
946
|
+
kind: kindStr,
|
|
947
|
+
name: isPrivate ? "#" + name : name,
|
|
948
|
+
static: isStatic,
|
|
949
|
+
private: isPrivate,
|
|
950
|
+
metadata: metadata
|
|
951
|
+
};
|
|
952
|
+
var decoratorFinishedRef = {
|
|
953
|
+
v: false
|
|
954
|
+
};
|
|
955
|
+
ctx.addInitializer = createAddInitializerMethod(initializers, decoratorFinishedRef);
|
|
956
|
+
var get, set;
|
|
957
|
+
if (0 === kind) if (isPrivate) {
|
|
958
|
+
get = desc.get;
|
|
959
|
+
set = desc.set;
|
|
960
|
+
} else {
|
|
961
|
+
get = function() {
|
|
962
|
+
return this[name];
|
|
963
|
+
};
|
|
964
|
+
set = function(v) {
|
|
965
|
+
this[name] = v;
|
|
966
|
+
};
|
|
967
|
+
}
|
|
968
|
+
else if (2 === kind) get = function() {
|
|
969
|
+
return desc.value;
|
|
970
|
+
};
|
|
971
|
+
else {
|
|
972
|
+
if (1 === kind || 3 === kind) get = function() {
|
|
973
|
+
return desc.get.call(this);
|
|
974
|
+
};
|
|
975
|
+
if (1 === kind || 4 === kind) set = function(v) {
|
|
976
|
+
desc.set.call(this, v);
|
|
977
|
+
};
|
|
978
|
+
}
|
|
979
|
+
ctx.access = get && set ? {
|
|
980
|
+
get: get,
|
|
981
|
+
set: set
|
|
982
|
+
} : get ? {
|
|
983
|
+
get: get
|
|
984
|
+
} : {
|
|
985
|
+
set: set
|
|
986
|
+
};
|
|
987
|
+
try {
|
|
988
|
+
return dec(value, ctx);
|
|
989
|
+
} finally{
|
|
990
|
+
decoratorFinishedRef.v = true;
|
|
991
|
+
}
|
|
992
|
+
}
|
|
993
|
+
function assertNotFinished(decoratorFinishedRef, fnName) {
|
|
994
|
+
if (decoratorFinishedRef.v) throw new Error("attempted to call " + fnName + " after decoration was finished");
|
|
995
|
+
}
|
|
996
|
+
function assertCallable(fn, hint) {
|
|
997
|
+
if ("function" != typeof fn) throw new TypeError(hint + " must be a function");
|
|
998
|
+
}
|
|
999
|
+
function assertValidReturnValue(kind, value) {
|
|
1000
|
+
var type = typeof value;
|
|
1001
|
+
if (1 === kind) {
|
|
1002
|
+
if ("object" !== type || null === value) throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");
|
|
1003
|
+
if (void 0 !== value.get) assertCallable(value.get, "accessor.get");
|
|
1004
|
+
if (void 0 !== value.set) assertCallable(value.set, "accessor.set");
|
|
1005
|
+
if (void 0 !== value.init) assertCallable(value.init, "accessor.init");
|
|
1006
|
+
} else if ("function" !== type) {
|
|
1007
|
+
var hint;
|
|
1008
|
+
hint = 0 === kind ? "field" : 10 === kind ? "class" : "method";
|
|
1009
|
+
throw new TypeError(hint + " decorators must return a function or void 0");
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
function applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata) {
|
|
1013
|
+
var decs = decInfo[0];
|
|
1014
|
+
var desc, init, value;
|
|
1015
|
+
if (isPrivate) desc = 0 === kind || 1 === kind ? {
|
|
1016
|
+
get: decInfo[3],
|
|
1017
|
+
set: decInfo[4]
|
|
1018
|
+
} : 3 === kind ? {
|
|
1019
|
+
get: decInfo[3]
|
|
1020
|
+
} : 4 === kind ? {
|
|
1021
|
+
set: decInfo[3]
|
|
1022
|
+
} : {
|
|
1023
|
+
value: decInfo[3]
|
|
1024
|
+
};
|
|
1025
|
+
else if (0 !== kind) desc = Object.getOwnPropertyDescriptor(base, name);
|
|
1026
|
+
if (1 === kind) value = {
|
|
1027
|
+
get: desc.get,
|
|
1028
|
+
set: desc.set
|
|
1029
|
+
};
|
|
1030
|
+
else if (2 === kind) value = desc.value;
|
|
1031
|
+
else if (3 === kind) value = desc.get;
|
|
1032
|
+
else if (4 === kind) value = desc.set;
|
|
1033
|
+
var newValue, get, set;
|
|
1034
|
+
if ("function" == typeof decs) {
|
|
1035
|
+
newValue = memberDec(decs, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
|
|
1036
|
+
if (void 0 !== newValue) {
|
|
1037
|
+
assertValidReturnValue(kind, newValue);
|
|
1038
|
+
if (0 === kind) init = newValue;
|
|
1039
|
+
else if (1 === kind) {
|
|
1040
|
+
init = newValue.init;
|
|
1041
|
+
get = newValue.get || value.get;
|
|
1042
|
+
set = newValue.set || value.set;
|
|
1043
|
+
value = {
|
|
1044
|
+
get: get,
|
|
1045
|
+
set: set
|
|
1046
|
+
};
|
|
1047
|
+
} else value = newValue;
|
|
1048
|
+
}
|
|
1049
|
+
} else for(var i = decs.length - 1; i >= 0; i--){
|
|
1050
|
+
var dec = decs[i];
|
|
1051
|
+
newValue = memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
|
|
1052
|
+
if (void 0 !== newValue) {
|
|
1053
|
+
assertValidReturnValue(kind, newValue);
|
|
1054
|
+
var newInit;
|
|
1055
|
+
if (0 === kind) newInit = newValue;
|
|
1056
|
+
else if (1 === kind) {
|
|
1057
|
+
newInit = newValue.init;
|
|
1058
|
+
get = newValue.get || value.get;
|
|
1059
|
+
set = newValue.set || value.set;
|
|
1060
|
+
value = {
|
|
1061
|
+
get: get,
|
|
1062
|
+
set: set
|
|
1063
|
+
};
|
|
1064
|
+
} else value = newValue;
|
|
1065
|
+
if (void 0 !== newInit) if (void 0 === init) init = newInit;
|
|
1066
|
+
else if ("function" == typeof init) init = [
|
|
1067
|
+
init,
|
|
1068
|
+
newInit
|
|
1069
|
+
];
|
|
1070
|
+
else init.push(newInit);
|
|
1071
|
+
}
|
|
1072
|
+
}
|
|
1073
|
+
if (0 === kind || 1 === kind) {
|
|
1074
|
+
if (void 0 === init) init = function(instance, init) {
|
|
1075
|
+
return init;
|
|
1076
|
+
};
|
|
1077
|
+
else if ("function" != typeof init) {
|
|
1078
|
+
var ownInitializers = init;
|
|
1079
|
+
init = function(instance, init) {
|
|
1080
|
+
var value = init;
|
|
1081
|
+
for(var i = 0; i < ownInitializers.length; i++)value = ownInitializers[i].call(instance, value);
|
|
1082
|
+
return value;
|
|
1083
|
+
};
|
|
1084
|
+
} else {
|
|
1085
|
+
var originalInitializer = init;
|
|
1086
|
+
init = function(instance, init) {
|
|
1087
|
+
return originalInitializer.call(instance, init);
|
|
1088
|
+
};
|
|
1089
|
+
}
|
|
1090
|
+
ret.push(init);
|
|
1091
|
+
}
|
|
1092
|
+
if (0 !== kind) {
|
|
1093
|
+
if (1 === kind) {
|
|
1094
|
+
desc.get = value.get;
|
|
1095
|
+
desc.set = value.set;
|
|
1096
|
+
} else if (2 === kind) desc.value = value;
|
|
1097
|
+
else if (3 === kind) desc.get = value;
|
|
1098
|
+
else if (4 === kind) desc.set = value;
|
|
1099
|
+
if (isPrivate) if (1 === kind) {
|
|
1100
|
+
ret.push(function(instance, args) {
|
|
1101
|
+
return value.get.call(instance, args);
|
|
1102
|
+
});
|
|
1103
|
+
ret.push(function(instance, args) {
|
|
1104
|
+
return value.set.call(instance, args);
|
|
1105
|
+
});
|
|
1106
|
+
} else if (2 === kind) ret.push(value);
|
|
1107
|
+
else ret.push(function(instance, args) {
|
|
1108
|
+
return value.call(instance, args);
|
|
1109
|
+
});
|
|
1110
|
+
else Object.defineProperty(base, name, desc);
|
|
1111
|
+
}
|
|
1112
|
+
}
|
|
1113
|
+
function applyMemberDecs(Class, decInfos, metadata) {
|
|
1114
|
+
var ret = [];
|
|
1115
|
+
var protoInitializers;
|
|
1116
|
+
var staticInitializers;
|
|
1117
|
+
var existingProtoNonFields = new Map();
|
|
1118
|
+
var existingStaticNonFields = new Map();
|
|
1119
|
+
for(var i = 0; i < decInfos.length; i++){
|
|
1120
|
+
var decInfo = decInfos[i];
|
|
1121
|
+
if (Array.isArray(decInfo)) {
|
|
1122
|
+
var kind = decInfo[1];
|
|
1123
|
+
var name = decInfo[2];
|
|
1124
|
+
var isPrivate = decInfo.length > 3;
|
|
1125
|
+
var isStatic = kind >= 5;
|
|
1126
|
+
var base;
|
|
1127
|
+
var initializers;
|
|
1128
|
+
if (isStatic) {
|
|
1129
|
+
base = Class;
|
|
1130
|
+
kind -= 5;
|
|
1131
|
+
staticInitializers = staticInitializers || [];
|
|
1132
|
+
initializers = staticInitializers;
|
|
1133
|
+
} else {
|
|
1134
|
+
base = Class.prototype;
|
|
1135
|
+
protoInitializers = protoInitializers || [];
|
|
1136
|
+
initializers = protoInitializers;
|
|
1137
|
+
}
|
|
1138
|
+
if (0 !== kind && !isPrivate) {
|
|
1139
|
+
var existingNonFields = isStatic ? existingStaticNonFields : existingProtoNonFields;
|
|
1140
|
+
var existingKind = existingNonFields.get(name) || 0;
|
|
1141
|
+
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);
|
|
1142
|
+
if (!existingKind && kind > 2) existingNonFields.set(name, kind);
|
|
1143
|
+
else existingNonFields.set(name, true);
|
|
1144
|
+
}
|
|
1145
|
+
applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata);
|
|
1146
|
+
}
|
|
1147
|
+
}
|
|
1148
|
+
pushInitializers(ret, protoInitializers);
|
|
1149
|
+
pushInitializers(ret, staticInitializers);
|
|
1150
|
+
return ret;
|
|
1151
|
+
}
|
|
1152
|
+
function pushInitializers(ret, initializers) {
|
|
1153
|
+
if (initializers) ret.push(function(instance) {
|
|
1154
|
+
for(var i = 0; i < initializers.length; i++)initializers[i].call(instance);
|
|
1155
|
+
return instance;
|
|
1156
|
+
});
|
|
1157
|
+
}
|
|
1158
|
+
function applyClassDecs(targetClass, classDecs, metadata) {
|
|
1159
|
+
if (classDecs.length > 0) {
|
|
1160
|
+
var initializers = [];
|
|
1161
|
+
var newClass = targetClass;
|
|
1162
|
+
var name = targetClass.name;
|
|
1163
|
+
for(var i = classDecs.length - 1; i >= 0; i--){
|
|
1164
|
+
var decoratorFinishedRef = {
|
|
1165
|
+
v: false
|
|
1166
|
+
};
|
|
1167
|
+
try {
|
|
1168
|
+
var nextNewClass = classDecs[i](newClass, {
|
|
1169
|
+
kind: "class",
|
|
1170
|
+
name: name,
|
|
1171
|
+
addInitializer: createAddInitializerMethod(initializers, decoratorFinishedRef),
|
|
1172
|
+
metadata
|
|
1173
|
+
});
|
|
1174
|
+
} finally{
|
|
1175
|
+
decoratorFinishedRef.v = true;
|
|
1176
|
+
}
|
|
1177
|
+
if (void 0 !== nextNewClass) {
|
|
1178
|
+
assertValidReturnValue(10, nextNewClass);
|
|
1179
|
+
newClass = nextNewClass;
|
|
1180
|
+
}
|
|
1181
|
+
}
|
|
1182
|
+
return [
|
|
1183
|
+
defineMetadata(newClass, metadata),
|
|
1184
|
+
function() {
|
|
1185
|
+
for(var i = 0; i < initializers.length; i++)initializers[i].call(newClass);
|
|
1186
|
+
}
|
|
1187
|
+
];
|
|
1188
|
+
}
|
|
1189
|
+
}
|
|
1190
|
+
function defineMetadata(Class, metadata) {
|
|
1191
|
+
return Object.defineProperty(Class, Symbol.metadata || Symbol.for("Symbol.metadata"), {
|
|
1192
|
+
configurable: true,
|
|
1193
|
+
enumerable: true,
|
|
1194
|
+
value: metadata
|
|
1195
|
+
});
|
|
1196
|
+
}
|
|
1197
|
+
return function(targetClass, memberDecs, classDecs, parentClass) {
|
|
1198
|
+
if (void 0 !== parentClass) var parentMetadata = parentClass[Symbol.metadata || Symbol.for("Symbol.metadata")];
|
|
1199
|
+
var metadata = Object.create(void 0 === parentMetadata ? null : parentMetadata);
|
|
1200
|
+
var e = applyMemberDecs(targetClass, memberDecs, metadata);
|
|
1201
|
+
if (!classDecs.length) defineMetadata(targetClass, metadata);
|
|
1202
|
+
return {
|
|
1203
|
+
e: e,
|
|
1204
|
+
get c () {
|
|
1205
|
+
return applyClassDecs(targetClass, classDecs, metadata);
|
|
1206
|
+
}
|
|
1207
|
+
};
|
|
1208
|
+
};
|
|
1209
|
+
}
|
|
1210
|
+
function PersonalizationStateful_apply_decs_2203_r(targetClass, memberDecs, classDecs, parentClass) {
|
|
1211
|
+
return (PersonalizationStateful_apply_decs_2203_r = PersonalizationStateful_applyDecs2203RFactory())(targetClass, memberDecs, classDecs, parentClass);
|
|
1212
|
+
}
|
|
1213
|
+
var PersonalizationStateful_dec, PersonalizationStateful_dec1, PersonalizationStateful_dec2, PersonalizationStateful_dec3, _dec4, _dec5, PersonalizationStateful_initProto;
|
|
1214
|
+
const PersonalizationStateful_logger = createScopedLogger('Personalization');
|
|
1215
|
+
PersonalizationStateful_dec = guardedBy('hasConsent', {
|
|
1216
|
+
onBlocked: 'onBlockedByConsent'
|
|
1217
|
+
}), PersonalizationStateful_dec1 = guardedBy('hasConsent', {
|
|
1218
|
+
onBlocked: 'onBlockedByConsent'
|
|
1219
|
+
}), PersonalizationStateful_dec2 = guardedBy('hasConsent', {
|
|
1220
|
+
onBlocked: 'onBlockedByConsent'
|
|
1221
|
+
}), PersonalizationStateful_dec3 = guardedBy('hasConsent', {
|
|
1222
|
+
onBlocked: 'onBlockedByConsent'
|
|
1223
|
+
}), _dec4 = guardedBy('isNotDuplicated', {
|
|
1224
|
+
onBlocked: 'onBlockedByDuplication'
|
|
1225
|
+
}), _dec5 = guardedBy('hasConsent', {
|
|
1226
|
+
onBlocked: 'onBlockedByConsent'
|
|
1227
|
+
});
|
|
1228
|
+
class PersonalizationStateful extends personalization_PersonalizationBase {
|
|
1229
|
+
static{
|
|
1230
|
+
({ e: [PersonalizationStateful_initProto] } = PersonalizationStateful_apply_decs_2203_r(this, [
|
|
1231
|
+
[
|
|
1232
|
+
PersonalizationStateful_dec,
|
|
1233
|
+
2,
|
|
1234
|
+
"identify"
|
|
1235
|
+
],
|
|
1236
|
+
[
|
|
1237
|
+
PersonalizationStateful_dec1,
|
|
1238
|
+
2,
|
|
1239
|
+
"page"
|
|
1240
|
+
],
|
|
1241
|
+
[
|
|
1242
|
+
PersonalizationStateful_dec2,
|
|
1243
|
+
2,
|
|
1244
|
+
"screen"
|
|
1245
|
+
],
|
|
1246
|
+
[
|
|
1247
|
+
PersonalizationStateful_dec3,
|
|
1248
|
+
2,
|
|
1249
|
+
"track"
|
|
1250
|
+
],
|
|
1251
|
+
[
|
|
1252
|
+
[
|
|
1253
|
+
_dec4,
|
|
1254
|
+
_dec5
|
|
1255
|
+
],
|
|
1256
|
+
2,
|
|
1257
|
+
"trackComponentView"
|
|
1258
|
+
]
|
|
1259
|
+
], []));
|
|
1260
|
+
}
|
|
1261
|
+
offlineQueue = (PersonalizationStateful_initProto(this), new Set());
|
|
1262
|
+
states = {
|
|
1263
|
+
eventStream: toObservable(signals_event),
|
|
1264
|
+
flags: toObservable(flags),
|
|
1265
|
+
profile: toObservable(signals_profile),
|
|
1266
|
+
personalizations: toObservable(signals_personalizations)
|
|
1267
|
+
};
|
|
1268
|
+
getAnonymousId;
|
|
1269
|
+
constructor(options){
|
|
1270
|
+
const { api, builder, config, interceptors } = options;
|
|
1271
|
+
super({
|
|
1272
|
+
api,
|
|
1273
|
+
builder,
|
|
1274
|
+
config,
|
|
1275
|
+
interceptors
|
|
1276
|
+
});
|
|
1277
|
+
const { defaults, getAnonymousId } = config ?? {};
|
|
1278
|
+
if (defaults) {
|
|
1279
|
+
const { changes: defaultChanges, personalizations: defaultPersonalizations, profile: defaultProfile } = defaults;
|
|
1280
|
+
batch(()=>{
|
|
1281
|
+
signals_changes.value = defaultChanges;
|
|
1282
|
+
signals_personalizations.value = defaultPersonalizations;
|
|
1283
|
+
signals_profile.value = defaultProfile;
|
|
1284
|
+
});
|
|
1285
|
+
}
|
|
1286
|
+
if (defaults?.consent !== void 0) {
|
|
1287
|
+
const { consent: defaultConsent } = defaults;
|
|
1288
|
+
consent.value = defaultConsent;
|
|
1289
|
+
}
|
|
1290
|
+
this.getAnonymousId = getAnonymousId ?? (()=>void 0);
|
|
1291
|
+
effect(()=>{
|
|
1292
|
+
PersonalizationStateful_logger.debug(`Profile ${signals_profile.value && `with ID ${signals_profile.value.id}`} has been ${signals_profile.value ? 'set' : 'cleared'}`);
|
|
1293
|
+
});
|
|
1294
|
+
effect(()=>{
|
|
1295
|
+
PersonalizationStateful_logger.debug(`Variants have been ${signals_personalizations.value?.length ? 'populated' : 'cleared'}`);
|
|
1296
|
+
});
|
|
1297
|
+
effect(()=>{
|
|
1298
|
+
PersonalizationStateful_logger.info(`Personalization ${consent.value ? 'will' : 'will not'} take effect due to consent (${consent.value})`);
|
|
1299
|
+
});
|
|
1300
|
+
effect(()=>{
|
|
1301
|
+
if (online.value) this.flush();
|
|
1302
|
+
});
|
|
1303
|
+
}
|
|
1304
|
+
reset() {
|
|
1305
|
+
batch(()=>{
|
|
1306
|
+
signals_changes.value = void 0;
|
|
1307
|
+
signals_event.value = void 0;
|
|
1308
|
+
signals_profile.value = void 0;
|
|
1309
|
+
signals_personalizations.value = void 0;
|
|
1310
|
+
});
|
|
1311
|
+
}
|
|
1312
|
+
getCustomFlag(name, changes = signals_changes.value) {
|
|
1313
|
+
return super.getCustomFlag(name, changes);
|
|
1314
|
+
}
|
|
1315
|
+
personalizeEntry(entry, personalizations = signals_personalizations.value) {
|
|
1316
|
+
return super.personalizeEntry(entry, personalizations);
|
|
1317
|
+
}
|
|
1318
|
+
getMergeTagValue(embeddedEntryNodeTarget, profile = signals_profile.value) {
|
|
1319
|
+
return super.getMergeTagValue(embeddedEntryNodeTarget, profile);
|
|
1320
|
+
}
|
|
1321
|
+
hasConsent(name) {
|
|
1322
|
+
return !!consent.value || (this.allowedEventTypes ?? []).includes('trackComponentView' === name || 'trackFlagView' === name ? 'component' : name);
|
|
1323
|
+
}
|
|
1324
|
+
onBlockedByConsent(name, payload) {
|
|
1325
|
+
PersonalizationStateful_logger.warn(`Event "${name}" was blocked due to lack of consent; payload: ${JSON.stringify(payload)}`);
|
|
1326
|
+
}
|
|
1327
|
+
isNotDuplicated(_name, payload) {
|
|
1328
|
+
const [{ componentId: value }, duplicationScope] = payload;
|
|
1329
|
+
const isDuplicated = this.duplicationDetector.isPresent(duplicationScope, value);
|
|
1330
|
+
if (!isDuplicated) this.duplicationDetector.addValue(duplicationScope, value);
|
|
1331
|
+
return !isDuplicated;
|
|
1332
|
+
}
|
|
1333
|
+
onBlockedByDuplication(_name, payload) {
|
|
1334
|
+
PersonalizationStateful_logger.debug(`Duplicate "component view" event detected, skipping; payload: ${JSON.stringify(payload)}`);
|
|
1335
|
+
}
|
|
1336
|
+
async identify(payload) {
|
|
1337
|
+
PersonalizationStateful_logger.info('Sending "identify" event');
|
|
1338
|
+
const event = this.builder.buildIdentify(payload);
|
|
1339
|
+
return await this.sendOrEnqueueEvent(event);
|
|
1340
|
+
}
|
|
1341
|
+
async page(payload) {
|
|
1342
|
+
PersonalizationStateful_logger.info('Sending "page" event');
|
|
1343
|
+
const event = this.builder.buildPageView(payload);
|
|
1344
|
+
return await this.sendOrEnqueueEvent(event);
|
|
1345
|
+
}
|
|
1346
|
+
async screen(payload) {
|
|
1347
|
+
PersonalizationStateful_logger.info(`Sending "screen" event for "${payload.name}"`);
|
|
1348
|
+
const event = this.builder.buildScreenView(payload);
|
|
1349
|
+
return await this.sendOrEnqueueEvent(event);
|
|
1350
|
+
}
|
|
1351
|
+
async track(payload) {
|
|
1352
|
+
PersonalizationStateful_logger.info(`Sending "track" event "${payload.event}"`);
|
|
1353
|
+
const event = this.builder.buildTrack(payload);
|
|
1354
|
+
return await this.sendOrEnqueueEvent(event);
|
|
1355
|
+
}
|
|
1356
|
+
async trackComponentView(payload, _duplicationScope = '') {
|
|
1357
|
+
PersonalizationStateful_logger.info(`Sending "track personalization" event for ${payload.componentId}`);
|
|
1358
|
+
const event = this.builder.buildComponentView(payload);
|
|
1359
|
+
return await this.sendOrEnqueueEvent(event);
|
|
1360
|
+
}
|
|
1361
|
+
async sendOrEnqueueEvent(event) {
|
|
1362
|
+
const intercepted = await this.interceptors.event.run(event);
|
|
1363
|
+
const validEvent = __rspack_external__contentful_optimization_api_client_cba5a7ee.ExperienceEvent.parse(intercepted);
|
|
1364
|
+
signals_event.value = validEvent;
|
|
1365
|
+
if (online.value) return await this.upsertProfile([
|
|
1366
|
+
validEvent
|
|
1367
|
+
]);
|
|
1368
|
+
PersonalizationStateful_logger.debug(`Queueing ${validEvent.type} event`, validEvent);
|
|
1369
|
+
this.offlineQueue.add(validEvent);
|
|
1370
|
+
}
|
|
1371
|
+
async flush() {
|
|
1372
|
+
if (0 === this.offlineQueue.size) return;
|
|
1373
|
+
PersonalizationStateful_logger.debug('Flushing offline event queue');
|
|
1374
|
+
await this.upsertProfile(Array.from(this.offlineQueue));
|
|
1375
|
+
this.offlineQueue.clear();
|
|
1376
|
+
}
|
|
1377
|
+
async upsertProfile(events) {
|
|
1378
|
+
const anonymousId = this.getAnonymousId();
|
|
1379
|
+
if (anonymousId) PersonalizationStateful_logger.debug(`Anonymous ID found: ${anonymousId}`);
|
|
1380
|
+
const data = await this.api.experience.upsertProfile({
|
|
1381
|
+
profileId: anonymousId ?? signals_profile.value?.id,
|
|
1382
|
+
events
|
|
1383
|
+
});
|
|
1384
|
+
await this.updateOutputSignals(data);
|
|
1385
|
+
return data;
|
|
1386
|
+
}
|
|
1387
|
+
async updateOutputSignals(data) {
|
|
1388
|
+
const intercepted = await this.interceptors.state.run(data);
|
|
1389
|
+
const { changes, personalizations, profile } = intercepted;
|
|
1390
|
+
batch(()=>{
|
|
1391
|
+
if (!isEqual(signals_changes.value, changes)) signals_changes.value = changes;
|
|
1392
|
+
if (!isEqual(signals_profile.value, profile)) signals_profile.value = profile;
|
|
1393
|
+
if (!isEqual(signals_personalizations.value, personalizations)) signals_personalizations.value = personalizations;
|
|
1394
|
+
});
|
|
1395
|
+
}
|
|
1396
|
+
}
|
|
1397
|
+
const personalization_PersonalizationStateful = PersonalizationStateful;
|
|
1398
|
+
const PersonalizationStateless_logger = createScopedLogger('Personalization');
|
|
1399
|
+
class PersonalizationStateless extends personalization_PersonalizationBase {
|
|
1400
|
+
async identify(payload) {
|
|
1401
|
+
PersonalizationStateless_logger.info('Sending "identify" event');
|
|
1402
|
+
const { profile, ...builderArgs } = payload;
|
|
1403
|
+
const event = __rspack_external__contentful_optimization_api_client_cba5a7ee.IdentifyEvent.parse(this.builder.buildIdentify(builderArgs));
|
|
1404
|
+
return await this.upsertProfile(event, profile);
|
|
1405
|
+
}
|
|
1406
|
+
async page(payload) {
|
|
1407
|
+
PersonalizationStateless_logger.info('Sending "page" event');
|
|
1408
|
+
const { profile, ...builderArgs } = payload;
|
|
1409
|
+
const event = __rspack_external__contentful_optimization_api_client_cba5a7ee.PageViewEvent.parse(this.builder.buildPageView(builderArgs));
|
|
1410
|
+
return await this.upsertProfile(event, profile);
|
|
1411
|
+
}
|
|
1412
|
+
async screen(payload) {
|
|
1413
|
+
PersonalizationStateless_logger.info(`Sending "screen" event for "${payload.name}"`);
|
|
1414
|
+
const { profile, ...builderArgs } = payload;
|
|
1415
|
+
const event = __rspack_external__contentful_optimization_api_client_cba5a7ee.ScreenViewEvent.parse(this.builder.buildScreenView(builderArgs));
|
|
1416
|
+
return await this.upsertProfile(event, profile);
|
|
1417
|
+
}
|
|
1418
|
+
async track(payload) {
|
|
1419
|
+
PersonalizationStateless_logger.info(`Sending "track" event "${payload.event}"`);
|
|
1420
|
+
const { profile, ...builderArgs } = payload;
|
|
1421
|
+
const event = __rspack_external__contentful_optimization_api_client_cba5a7ee.TrackEvent.parse(this.builder.buildTrack(builderArgs));
|
|
1422
|
+
return await this.upsertProfile(event, profile);
|
|
1423
|
+
}
|
|
1424
|
+
async trackComponentView(payload) {
|
|
1425
|
+
PersonalizationStateless_logger.info('Sending "track personalization" event');
|
|
1426
|
+
const { profile, ...builderArgs } = payload;
|
|
1427
|
+
const event = __rspack_external__contentful_optimization_api_client_cba5a7ee.ComponentViewEvent.parse(this.builder.buildComponentView(builderArgs));
|
|
1428
|
+
return await this.upsertProfile(event, profile);
|
|
1429
|
+
}
|
|
1430
|
+
async upsertProfile(event, profile) {
|
|
1431
|
+
const intercepted = await this.interceptors.event.run(event);
|
|
1432
|
+
const data = await this.api.experience.upsertProfile({
|
|
1433
|
+
profileId: profile?.id,
|
|
1434
|
+
events: [
|
|
1435
|
+
intercepted
|
|
1436
|
+
]
|
|
1437
|
+
});
|
|
1438
|
+
return data;
|
|
1439
|
+
}
|
|
1440
|
+
}
|
|
1441
|
+
const personalization_PersonalizationStateless = PersonalizationStateless;
|
|
1442
|
+
class CoreStateful extends src_CoreBase {
|
|
1443
|
+
analytics;
|
|
1444
|
+
personalization;
|
|
1445
|
+
constructor(config){
|
|
1446
|
+
super(config);
|
|
1447
|
+
const { allowedEventTypes, defaults, getAnonymousId, preventedComponentEvents } = config;
|
|
1448
|
+
if (defaults?.consent !== void 0) {
|
|
1449
|
+
const { consent: defaultConsent } = defaults;
|
|
1450
|
+
consent.value = defaultConsent;
|
|
1451
|
+
}
|
|
1452
|
+
this.analytics = new analytics_AnalyticsStateful({
|
|
1453
|
+
api: this.api,
|
|
1454
|
+
builder: this.eventBuilder,
|
|
1455
|
+
config: {
|
|
1456
|
+
allowedEventTypes,
|
|
1457
|
+
preventedComponentEvents,
|
|
1458
|
+
defaults: {
|
|
1459
|
+
consent: defaults?.consent,
|
|
1460
|
+
profile: defaults?.profile
|
|
1461
|
+
}
|
|
1462
|
+
},
|
|
1463
|
+
interceptors: this.interceptors
|
|
1464
|
+
});
|
|
1465
|
+
this.personalization = new personalization_PersonalizationStateful({
|
|
1466
|
+
api: this.api,
|
|
1467
|
+
builder: this.eventBuilder,
|
|
1468
|
+
config: {
|
|
1469
|
+
allowedEventTypes,
|
|
1470
|
+
getAnonymousId,
|
|
1471
|
+
preventedComponentEvents,
|
|
1472
|
+
defaults: {
|
|
1473
|
+
consent: defaults?.consent,
|
|
1474
|
+
changes: defaults?.changes,
|
|
1475
|
+
profile: defaults?.profile,
|
|
1476
|
+
personalizations: defaults?.personalizations
|
|
1477
|
+
}
|
|
1478
|
+
},
|
|
1479
|
+
interceptors: this.interceptors
|
|
1480
|
+
});
|
|
1481
|
+
}
|
|
1482
|
+
get states() {
|
|
1483
|
+
return {
|
|
1484
|
+
consent: toObservable(consent),
|
|
1485
|
+
eventStream: toObservable(signals_event),
|
|
1486
|
+
flags: toObservable(flags),
|
|
1487
|
+
personalizations: toObservable(signals_personalizations),
|
|
1488
|
+
profile: toObservable(signals_profile)
|
|
1489
|
+
};
|
|
1490
|
+
}
|
|
1491
|
+
reset() {
|
|
1492
|
+
batch(()=>{
|
|
1493
|
+
signals_event.value = void 0;
|
|
1494
|
+
signals_changes.value = void 0;
|
|
1495
|
+
signals_profile.value = void 0;
|
|
1496
|
+
signals_personalizations.value = void 0;
|
|
1497
|
+
});
|
|
1498
|
+
}
|
|
1499
|
+
async flush() {
|
|
1500
|
+
await this.analytics.flush();
|
|
1501
|
+
await this.personalization.flush();
|
|
1502
|
+
}
|
|
1503
|
+
consent(accept) {
|
|
1504
|
+
consent.value = accept;
|
|
1505
|
+
}
|
|
1506
|
+
online(isOnline) {
|
|
1507
|
+
online.value = isOnline;
|
|
1508
|
+
}
|
|
1509
|
+
registerPreviewPanel(previewPanel) {
|
|
1510
|
+
previewPanel.signals = signals;
|
|
1511
|
+
}
|
|
1512
|
+
}
|
|
1513
|
+
const src_CoreStateful = CoreStateful;
|
|
1514
|
+
class CoreStateless extends src_CoreBase {
|
|
1515
|
+
analytics;
|
|
1516
|
+
personalization;
|
|
1517
|
+
constructor(config){
|
|
1518
|
+
super(config);
|
|
1519
|
+
this.analytics = new analytics_AnalyticsStateless({
|
|
1520
|
+
api: this.api,
|
|
1521
|
+
builder: this.eventBuilder,
|
|
1522
|
+
interceptors: this.interceptors
|
|
1523
|
+
});
|
|
1524
|
+
this.personalization = new personalization_PersonalizationStateless({
|
|
1525
|
+
api: this.api,
|
|
1526
|
+
builder: this.eventBuilder,
|
|
1527
|
+
interceptors: this.interceptors
|
|
1528
|
+
});
|
|
1529
|
+
}
|
|
1530
|
+
}
|
|
1531
|
+
const src_CoreStateless = CoreStateless;
|
|
1532
|
+
export * from "@contentful/optimization-api-client";
|
|
1533
|
+
export { ANONYMOUS_ID_COOKIE, ConsoleLogSink, InterceptorManager, Logger, OPTIMIZATION_CORE_SDK_VERSION, analytics_AnalyticsStateful as AnalyticsStateful, analytics_AnalyticsStateless as AnalyticsStateless, batch, createScopedLogger, effect, guardedBy, logger, personalization_PersonalizationStateful as PersonalizationStateful, personalization_PersonalizationStateless as PersonalizationStateless, resolvers_FlagsResolver as FlagsResolver, resolvers_MergeTagValueResolver as MergeTagValueResolver, resolvers_PersonalizedEntryResolver as PersonalizedEntryResolver, signals, src_CoreStateful as CoreStateful, src_CoreStateless as CoreStateless, src_LogSink as LogSink, value_presence_ValuePresence as ValuePresence };
|
|
1534
|
+
|
|
1535
|
+
//# sourceMappingURL=index.mjs.map
|