@contentful/optimization-core 0.1.0-alpha8 → 0.1.0-alpha9

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