@contentful/optimization-core 0.1.0-alpha → 0.1.0-alpha11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (149) hide show
  1. package/README.md +329 -93
  2. package/dist/160.mjs +3 -0
  3. package/dist/260.mjs +14 -0
  4. package/dist/260.mjs.map +1 -0
  5. package/dist/499.mjs +4 -0
  6. package/dist/632.mjs +5 -0
  7. package/dist/632.mjs.map +1 -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 +63 -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/constants.d.cts +88 -0
  24. package/dist/constants.d.mts +88 -0
  25. package/dist/constants.d.ts +88 -0
  26. package/dist/constants.mjs +1 -0
  27. package/dist/index.cjs +1509 -1715
  28. package/dist/index.cjs.map +1 -1
  29. package/dist/index.d.cts +2523 -0
  30. package/dist/index.d.mts +2523 -0
  31. package/dist/index.d.ts +2523 -15
  32. package/dist/index.mjs +1215 -1362
  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 +78 -12
  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 -142
  56. package/dist/CoreStateful.d.ts.map +0 -1
  57. package/dist/CoreStateful.js +0 -137
  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 +0 -18
  84. package/dist/global-constants.d.ts.map +0 -1
  85. package/dist/global-constants.js +0 -18
  86. package/dist/global-constants.js.map +0 -1
  87. package/dist/index.d.ts.map +0 -1
  88. package/dist/index.js +0 -15
  89. package/dist/index.js.map +0 -1
  90. package/dist/lib/decorators/guardedBy.d.ts +0 -113
  91. package/dist/lib/decorators/guardedBy.d.ts.map +0 -1
  92. package/dist/lib/decorators/guardedBy.js +0 -143
  93. package/dist/lib/decorators/guardedBy.js.map +0 -1
  94. package/dist/lib/decorators/index.d.ts +0 -2
  95. package/dist/lib/decorators/index.d.ts.map +0 -1
  96. package/dist/lib/decorators/index.js +0 -2
  97. package/dist/lib/decorators/index.js.map +0 -1
  98. package/dist/lib/interceptor/InterceptorManager.d.ts +0 -127
  99. package/dist/lib/interceptor/InterceptorManager.d.ts.map +0 -1
  100. package/dist/lib/interceptor/InterceptorManager.js +0 -125
  101. package/dist/lib/interceptor/InterceptorManager.js.map +0 -1
  102. package/dist/lib/interceptor/index.d.ts +0 -2
  103. package/dist/lib/interceptor/index.d.ts.map +0 -1
  104. package/dist/lib/interceptor/index.js +0 -2
  105. package/dist/lib/interceptor/index.js.map +0 -1
  106. package/dist/lib/value-presence/ValuePresence.d.ts +0 -123
  107. package/dist/lib/value-presence/ValuePresence.d.ts.map +0 -1
  108. package/dist/lib/value-presence/ValuePresence.js +0 -141
  109. package/dist/lib/value-presence/ValuePresence.js.map +0 -1
  110. package/dist/lib/value-presence/index.d.ts +0 -2
  111. package/dist/lib/value-presence/index.d.ts.map +0 -1
  112. package/dist/lib/value-presence/index.js +0 -2
  113. package/dist/lib/value-presence/index.js.map +0 -1
  114. package/dist/personalization/PersonalizationBase.d.ts +0 -184
  115. package/dist/personalization/PersonalizationBase.d.ts.map +0 -1
  116. package/dist/personalization/PersonalizationBase.js +0 -76
  117. package/dist/personalization/PersonalizationBase.js.map +0 -1
  118. package/dist/personalization/PersonalizationStateful.d.ts +0 -226
  119. package/dist/personalization/PersonalizationStateful.d.ts.map +0 -1
  120. package/dist/personalization/PersonalizationStateful.js +0 -297
  121. package/dist/personalization/PersonalizationStateful.js.map +0 -1
  122. package/dist/personalization/PersonalizationStateless.d.ts +0 -74
  123. package/dist/personalization/PersonalizationStateless.d.ts.map +0 -1
  124. package/dist/personalization/PersonalizationStateless.js +0 -98
  125. package/dist/personalization/PersonalizationStateless.js.map +0 -1
  126. package/dist/personalization/index.d.ts +0 -6
  127. package/dist/personalization/index.d.ts.map +0 -1
  128. package/dist/personalization/index.js +0 -6
  129. package/dist/personalization/index.js.map +0 -1
  130. package/dist/personalization/resolvers/FlagsResolver.d.ts +0 -35
  131. package/dist/personalization/resolvers/FlagsResolver.d.ts.map +0 -1
  132. package/dist/personalization/resolvers/FlagsResolver.js +0 -47
  133. package/dist/personalization/resolvers/FlagsResolver.js.map +0 -1
  134. package/dist/personalization/resolvers/MergeTagValueResolver.d.ts +0 -74
  135. package/dist/personalization/resolvers/MergeTagValueResolver.d.ts.map +0 -1
  136. package/dist/personalization/resolvers/MergeTagValueResolver.js +0 -109
  137. package/dist/personalization/resolvers/MergeTagValueResolver.js.map +0 -1
  138. package/dist/personalization/resolvers/PersonalizedEntryResolver.d.ts +0 -142
  139. package/dist/personalization/resolvers/PersonalizedEntryResolver.d.ts.map +0 -1
  140. package/dist/personalization/resolvers/PersonalizedEntryResolver.js +0 -196
  141. package/dist/personalization/resolvers/PersonalizedEntryResolver.js.map +0 -1
  142. package/dist/personalization/resolvers/index.d.ts +0 -7
  143. package/dist/personalization/resolvers/index.d.ts.map +0 -1
  144. package/dist/personalization/resolvers/index.js +0 -7
  145. package/dist/personalization/resolvers/index.js.map +0 -1
  146. package/dist/signals.d.ts +0 -35
  147. package/dist/signals.d.ts.map +0 -1
  148. package/dist/signals.js +0 -30
  149. package/dist/signals.js.map +0 -1
@@ -1,226 +0,0 @@
1
- import { type InsightsEvent as AnalyticsEvent, type ChangeArray, type ComponentViewBuilderArgs, type Flags, type IdentifyBuilderArgs, type Json, type MergeTagEntry, type OptimizationData, type PageViewBuilderArgs, ExperienceEvent as PersonalizationEvent, type Profile, type ScreenViewBuilderArgs, type SelectedPersonalizationArray, type TrackBuilderArgs } from '@contentful/optimization-api-client';
2
- import type { ChainModifiers, Entry, EntrySkeletonType, LocaleCode } from 'contentful';
3
- import type { ConsentGuard } from '../Consent';
4
- import type { ProductBaseOptions, ProductConfig } from '../ProductBase';
5
- import { type Observable } from '../signals';
6
- import PersonalizationBase from './PersonalizationBase';
7
- import type { ResolvedData } from './resolvers';
8
- /**
9
- * Default state values for {@link PersonalizationStateful} applied at construction time.
10
- *
11
- * @public
12
- */
13
- export interface PersonalizationProductConfigDefaults {
14
- /** Whether personalization is allowed by default. */
15
- consent?: boolean;
16
- /** Initial diff of changes produced by the service. */
17
- changes?: ChangeArray;
18
- /** Default active profile used for personalization. */
19
- profile?: Profile;
20
- /** Preselected personalization variants (e.g., winning treatments). */
21
- personalizations?: SelectedPersonalizationArray;
22
- }
23
- /**
24
- * Configuration for {@link PersonalizationStateful}.
25
- *
26
- * @public
27
- */
28
- export interface PersonalizationProductConfig extends ProductConfig {
29
- /** Default signal values applied during initialization. */
30
- defaults?: PersonalizationProductConfigDefaults;
31
- /**
32
- * Function used to obtain an anonymous user identifier.
33
- *
34
- * @remarks
35
- * If a `getAnonymousId` function has been provided, the returned value will
36
- * take precedence over the `id` property of the current {@link Profile}
37
- * signal value
38
- *
39
- * @returns A string identifier, or `undefined` if no anonymous ID is available.
40
- */
41
- getAnonymousId?: () => string | undefined;
42
- }
43
- /**
44
- * Observables exposed by {@link PersonalizationStateful} that mirror internal signals.
45
- *
46
- * @public
47
- */
48
- export interface PersonalizationStates {
49
- /** Observable stream of the latest {@link AnalyticsEvent} or {@link PersonalizationEvent} (or `undefined`). */
50
- eventStream: Observable<AnalyticsEvent | PersonalizationEvent | undefined>;
51
- /** Live view of effective flags for the current profile (if available). */
52
- flags: Observable<Flags | undefined>;
53
- /** Live view of the current profile. */
54
- profile: Observable<Profile | undefined>;
55
- /** Live view of selected personalizations (variants). */
56
- personalizations: Observable<SelectedPersonalizationArray | undefined>;
57
- }
58
- /**
59
- * Options for configuring {@link PersonalizationStateful} functionality.
60
- *
61
- * @public
62
- * @see {@link ProductBaseOptions}
63
- */
64
- export type PersonalizationStatefulOptions = ProductBaseOptions & {
65
- /** Configuration specific to the Personalization product */
66
- config?: PersonalizationProductConfig;
67
- };
68
- /**
69
- * Stateful personalization product that manages consent, profile, flags, and
70
- * selected variants while emitting Experience events and updating state.
71
- *
72
- * @public
73
- * @remarks
74
- * The class maintains reactive signals and exposes read‑only observables via
75
- * {@link PersonalizationStateful.states}. Events are validated via schema parsers and
76
- * run through interceptors before being submitted. Resulting state is merged
77
- * back into signals.
78
- */
79
- declare class PersonalizationStateful extends PersonalizationBase implements ConsentGuard {
80
- /** In‑memory queue for offline events keyed by profile. */
81
- private readonly offlineQueue;
82
- /** Exposed observable state references. */
83
- readonly states: PersonalizationStates;
84
- /**
85
- * Function that provides an anonymous ID when available.
86
- *
87
- * @internal
88
- */
89
- getAnonymousId: () => string | undefined;
90
- /**
91
- * Create a new stateful personalization instance.
92
- *
93
- * @param options - Options to configure the personalization product for stateful environments.
94
- */
95
- constructor(options: PersonalizationStatefulOptions);
96
- /**
97
- * Reset stateful signals managed by this product.
98
- *
99
- * @remarks
100
- * Clears `changes`, `profile`, and selected `personalizations`.
101
- */
102
- reset(): void;
103
- /**
104
- * Get the specified Custom Flag's value (derived from the signal).
105
- * @param name - The name or key of the Custom Flag.
106
- * @returns The current value of the Custom Flag if found.
107
- * */
108
- getCustomFlag(name: string, changes?: ChangeArray | undefined): Json;
109
- /**
110
- * Resolve a Contentful entry to a personalized variant using the current
111
- * or provided selections.
112
- *
113
- * @typeParam S - Entry skeleton type.
114
- * @typeParam M - Chain modifiers.
115
- * @typeParam L - Locale code.
116
- * @param entry - The entry to personalize.
117
- * @param personalizations - Optional selections; defaults to the current signal value.
118
- * @returns The resolved entry data.
119
- */
120
- personalizeEntry<S extends EntrySkeletonType, M extends ChainModifiers = ChainModifiers, L extends LocaleCode = LocaleCode>(entry: Entry<S, M, L>, personalizations?: SelectedPersonalizationArray | undefined): ResolvedData<S, M, L>;
121
- /**
122
- * Resolve a merge tag to a value based on the current (or provided) profile.
123
- *
124
- * @param embeddedEntryNodeTarget - The merge‑tag entry node to resolve.
125
- * @param profile - Optional profile; defaults to the current signal value.
126
- * @returns The resolved value (type depends on the tag).
127
- * @remarks
128
- * Merge tags are references to profile data that can be substituted into content.
129
- */
130
- getMergeTagValue(embeddedEntryNodeTarget: MergeTagEntry, profile?: Profile | undefined): unknown;
131
- /**
132
- * Determine whether the named operation is permitted based on consent and
133
- * allowed event type configuration.
134
- *
135
- * @param name - Method name; `trackComponentView` is normalized to
136
- * `'component'` for allow‑list checks.
137
- * @returns `true` if the operation is permitted; otherwise `false`.
138
- */
139
- hasConsent(name: string): boolean;
140
- /**
141
- * Hook invoked when an operation is blocked due to missing consent.
142
- *
143
- * @param name - The blocked operation name.
144
- * @param payload - The original arguments supplied to the operation.
145
- */
146
- onBlockedByConsent(name: string, payload: unknown[]): void;
147
- /**
148
- * Guard used to suppress duplicate component view events for the same
149
- * component based on a duplication key and the component identifier.
150
- *
151
- * @param _name - Operation name (unused).
152
- * @param payload - Tuple `[builderArgs, duplicationScope]`.
153
- * @returns `true` if the event is NOT a duplicate and should proceed.
154
- */
155
- isNotDuplicated(_name: string, payload: [ComponentViewBuilderArgs, string]): boolean;
156
- /**
157
- * Hook invoked when an operation is blocked by the duplication guard.
158
- *
159
- * @param _name - The blocked operation name (unused).
160
- * @param payload - The original arguments supplied to the operation.
161
- */
162
- onBlockedByDuplication(_name: string, payload: unknown[]): void;
163
- /**
164
- * Identify the current profile/visitor to associate traits with a profile
165
- * and update optimization state.
166
- *
167
- * @param payload - Identify builder payload.
168
- * @returns The resulting {@link OptimizationData} for the identified user.
169
- */
170
- identify(payload: IdentifyBuilderArgs): Promise<OptimizationData | undefined>;
171
- /**
172
- * Record a page view and update optimization state.
173
- *
174
- * @param payload - Page view builder payload.
175
- * @returns The evaluated {@link OptimizationData} for this page view.
176
- */
177
- page(payload: PageViewBuilderArgs): Promise<OptimizationData | undefined>;
178
- /**
179
- * Record a screen view and update optimization state.
180
- *
181
- * @param payload - Screen view builder payload.
182
- * @returns The evaluated {@link OptimizationData} for this screen view.
183
- */
184
- screen(payload: ScreenViewBuilderArgs): Promise<OptimizationData | undefined>;
185
- /**
186
- * Record a custom track event and update optimization state.
187
- *
188
- * @param payload - Track builder payload.
189
- * @returns The evaluated {@link OptimizationData} for this event.
190
- */
191
- track(payload: TrackBuilderArgs): Promise<OptimizationData | undefined>;
192
- trackComponentView(payload: ComponentViewBuilderArgs, _duplicationScope?: string): Promise<OptimizationData | undefined>;
193
- /**
194
- * Intercept, validate, and place an event into the offline eventd queue; then
195
- * trigger a size‑based flush if necessary.
196
- *
197
- * @param event - The event to enqueue.
198
- */
199
- private sendOrEnqueueEvent;
200
- /**
201
- * Flush the offline queue
202
- */
203
- flush(): Promise<void>;
204
- /**
205
- * Submit events to the Experience API, updating output signals with the
206
- * returned state.
207
- *
208
- * @param events - The events to submit.
209
- * @returns The {@link OptimizationData} returned by the service.
210
- * @internal
211
- * @privateRemarks
212
- * If a `getAnonymousId` function has been provided, the returned value will
213
- * take precedence over the `id` property of the current {@link Profile}
214
- * signal value
215
- */
216
- private upsertProfile;
217
- /**
218
- * Apply returned optimization state to local signals after interceptor processing.
219
- *
220
- * @param data - Optimization state returned by the service.
221
- * @internal
222
- */
223
- private updateOutputSignals;
224
- }
225
- export default PersonalizationStateful;
226
- //# sourceMappingURL=PersonalizationStateful.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PersonalizationStateful.d.ts","sourceRoot":"","sources":["../../src/personalization/PersonalizationStateful.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,aAAa,IAAI,cAAc,EACpC,KAAK,WAAW,EAChB,KAAK,wBAAwB,EAC7B,KAAK,KAAK,EACV,KAAK,mBAAmB,EACxB,KAAK,IAAI,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,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,IAAI;IAM1D;;;;;;;OAOG;IACH,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,wBAAwB,EAAE,MAAM,CAAC,GAAG,OAAO;IAUpF;;;;;OAKG;IACH,sBAAsB,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,IAAI;IAM/D;;;;;;OAMG;IAEG,QAAQ,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,gBAAgB,GAAG,SAAS,CAAC;IAQnF;;;;;OAKG;IAEG,IAAI,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,gBAAgB,GAAG,SAAS,CAAC;IAQ/E;;;;;OAKG;IAEG,MAAM,CAAC,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC,gBAAgB,GAAG,SAAS,CAAC;IAQnF;;;;;OAKG;IAEG,KAAK,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,GAAG,SAAS,CAAC;IAiBvE,kBAAkB,CACtB,OAAO,EAAE,wBAAwB,EACjC,iBAAiB,SAAK,GACrB,OAAO,CAAC,gBAAgB,GAAG,SAAS,CAAC;IAQxC;;;;;OAKG;YACW,kBAAkB;IAkBhC;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAU5B;;;;;;;;;;;OAWG;YACW,aAAa;IAc3B;;;;;OAKG;YACW,mBAAmB;CAYlC;AAED,eAAe,uBAAuB,CAAA"}
@@ -1,297 +0,0 @@
1
- import { ExperienceEvent as PersonalizationEvent, } from '@contentful/optimization-api-client';
2
- import { isEqual } from 'es-toolkit';
3
- import { createScopedLogger } from 'logger';
4
- import { guardedBy } from '../lib/decorators';
5
- import { batch, changes as changesSignal, consent as consentSignal, effect, event as eventSignal, flags as flagsSignal, online as onlineSignal, personalizations as personalizationsSignal, profile as profileSignal, toObservable, } from '../signals';
6
- import PersonalizationBase from './PersonalizationBase';
7
- const logger = createScopedLogger('Personalization');
8
- /**
9
- * Stateful personalization product that manages consent, profile, flags, and
10
- * selected variants while emitting Experience events and updating state.
11
- *
12
- * @public
13
- * @remarks
14
- * The class maintains reactive signals and exposes read‑only observables via
15
- * {@link PersonalizationStateful.states}. Events are validated via schema parsers and
16
- * run through interceptors before being submitted. Resulting state is merged
17
- * back into signals.
18
- */
19
- class PersonalizationStateful extends PersonalizationBase {
20
- /** In‑memory queue for offline events keyed by profile. */
21
- offlineQueue = new Set();
22
- /** Exposed observable state references. */
23
- states = {
24
- eventStream: toObservable(eventSignal),
25
- flags: toObservable(flagsSignal),
26
- profile: toObservable(profileSignal),
27
- personalizations: toObservable(personalizationsSignal),
28
- };
29
- /**
30
- * Function that provides an anonymous ID when available.
31
- *
32
- * @internal
33
- */
34
- getAnonymousId;
35
- /**
36
- * Create a new stateful personalization instance.
37
- *
38
- * @param options - Options to configure the personalization product for stateful environments.
39
- */
40
- constructor(options) {
41
- const { api, builder, config, interceptors } = options;
42
- super({ api, builder, config, interceptors });
43
- const { defaults, getAnonymousId } = config ?? {};
44
- if (defaults) {
45
- const { changes: defaultChanges, personalizations: defaultPersonalizations, profile: defaultProfile, } = defaults;
46
- batch(() => {
47
- changesSignal.value = defaultChanges;
48
- personalizationsSignal.value = defaultPersonalizations;
49
- profileSignal.value = defaultProfile;
50
- });
51
- }
52
- if (defaults?.consent !== undefined) {
53
- const { consent: defaultConsent } = defaults;
54
- consentSignal.value = defaultConsent;
55
- }
56
- this.getAnonymousId = getAnonymousId ?? (() => undefined);
57
- // Log signal changes for observability
58
- effect(() => {
59
- logger.debug(`Profile ${profileSignal.value && `with ID ${profileSignal.value.id}`} has been ${profileSignal.value ? 'set' : 'cleared'}`);
60
- });
61
- effect(() => {
62
- logger.debug(`Variants have been ${personalizationsSignal.value?.length ? 'populated' : 'cleared'}`);
63
- });
64
- effect(() => {
65
- logger.info(`Personalization ${consentSignal.value ? 'will' : 'will not'} take effect due to consent (${consentSignal.value})`);
66
- });
67
- effect(() => {
68
- if (onlineSignal.value)
69
- void this.flush();
70
- });
71
- }
72
- /**
73
- * Reset stateful signals managed by this product.
74
- *
75
- * @remarks
76
- * Clears `changes`, `profile`, and selected `personalizations`.
77
- */
78
- reset() {
79
- batch(() => {
80
- changesSignal.value = undefined;
81
- eventSignal.value = undefined;
82
- profileSignal.value = undefined;
83
- personalizationsSignal.value = undefined;
84
- });
85
- }
86
- /**
87
- * Get the specified Custom Flag's value (derived from the signal).
88
- * @param name - The name or key of the Custom Flag.
89
- * @returns The current value of the Custom Flag if found.
90
- * */
91
- getCustomFlag(name, changes = changesSignal.value) {
92
- return super.getCustomFlag(name, changes);
93
- }
94
- /**
95
- * Resolve a Contentful entry to a personalized variant using the current
96
- * or provided selections.
97
- *
98
- * @typeParam S - Entry skeleton type.
99
- * @typeParam M - Chain modifiers.
100
- * @typeParam L - Locale code.
101
- * @param entry - The entry to personalize.
102
- * @param personalizations - Optional selections; defaults to the current signal value.
103
- * @returns The resolved entry data.
104
- */
105
- personalizeEntry(entry, personalizations = personalizationsSignal.value) {
106
- return super.personalizeEntry(entry, personalizations);
107
- }
108
- /**
109
- * Resolve a merge tag to a value based on the current (or provided) profile.
110
- *
111
- * @param embeddedEntryNodeTarget - The merge‑tag entry node to resolve.
112
- * @param profile - Optional profile; defaults to the current signal value.
113
- * @returns The resolved value (type depends on the tag).
114
- * @remarks
115
- * Merge tags are references to profile data that can be substituted into content.
116
- */
117
- getMergeTagValue(embeddedEntryNodeTarget, profile = profileSignal.value) {
118
- return super.getMergeTagValue(embeddedEntryNodeTarget, profile);
119
- }
120
- /**
121
- * Determine whether the named operation is permitted based on consent and
122
- * allowed event type configuration.
123
- *
124
- * @param name - Method name; `trackComponentView` is normalized to
125
- * `'component'` for allow‑list checks.
126
- * @returns `true` if the operation is permitted; otherwise `false`.
127
- */
128
- hasConsent(name) {
129
- return (!!consentSignal.value ||
130
- (this.allowedEventTypes ?? []).includes(name === 'trackComponentView' || name === 'trackFlagView' ? 'component' : name));
131
- }
132
- /**
133
- * Hook invoked when an operation is blocked due to missing consent.
134
- *
135
- * @param name - The blocked operation name.
136
- * @param payload - The original arguments supplied to the operation.
137
- */
138
- onBlockedByConsent(name, payload) {
139
- logger.warn(`Event "${name}" was blocked due to lack of consent; payload: ${JSON.stringify(payload)}`);
140
- }
141
- /**
142
- * Guard used to suppress duplicate component view events for the same
143
- * component based on a duplication key and the component identifier.
144
- *
145
- * @param _name - Operation name (unused).
146
- * @param payload - Tuple `[builderArgs, duplicationScope]`.
147
- * @returns `true` if the event is NOT a duplicate and should proceed.
148
- */
149
- isNotDuplicated(_name, payload) {
150
- const [{ componentId: value }, duplicationScope] = payload;
151
- const isDuplicated = this.duplicationDetector.isPresent(duplicationScope, value);
152
- if (!isDuplicated)
153
- this.duplicationDetector.addValue(duplicationScope, value);
154
- return !isDuplicated;
155
- }
156
- /**
157
- * Hook invoked when an operation is blocked by the duplication guard.
158
- *
159
- * @param _name - The blocked operation name (unused).
160
- * @param payload - The original arguments supplied to the operation.
161
- */
162
- onBlockedByDuplication(_name, payload) {
163
- logger.debug(`Duplicate "component view" event detected, skipping; payload: ${JSON.stringify(payload)}`);
164
- }
165
- /**
166
- * Identify the current profile/visitor to associate traits with a profile
167
- * and update optimization state.
168
- *
169
- * @param payload - Identify builder payload.
170
- * @returns The resulting {@link OptimizationData} for the identified user.
171
- */
172
- @guardedBy('hasConsent', { onBlocked: 'onBlockedByConsent' })
173
- async identify(payload) {
174
- logger.info('Sending "identify" event');
175
- const event = this.builder.buildIdentify(payload);
176
- return await this.sendOrEnqueueEvent(event);
177
- }
178
- /**
179
- * Record a page view and update optimization state.
180
- *
181
- * @param payload - Page view builder payload.
182
- * @returns The evaluated {@link OptimizationData} for this page view.
183
- */
184
- @guardedBy('hasConsent', { onBlocked: 'onBlockedByConsent' })
185
- async page(payload) {
186
- logger.info('Sending "page" event');
187
- const event = this.builder.buildPageView(payload);
188
- return await this.sendOrEnqueueEvent(event);
189
- }
190
- /**
191
- * Record a screen view and update optimization state.
192
- *
193
- * @param payload - Screen view builder payload.
194
- * @returns The evaluated {@link OptimizationData} for this screen view.
195
- */
196
- @guardedBy('hasConsent', { onBlocked: 'onBlockedByConsent' })
197
- async screen(payload) {
198
- logger.info(`Sending "screen" event for "${payload.name}"`);
199
- const event = this.builder.buildScreenView(payload);
200
- return await this.sendOrEnqueueEvent(event);
201
- }
202
- /**
203
- * Record a custom track event and update optimization state.
204
- *
205
- * @param payload - Track builder payload.
206
- * @returns The evaluated {@link OptimizationData} for this event.
207
- */
208
- @guardedBy('hasConsent', { onBlocked: 'onBlockedByConsent' })
209
- async track(payload) {
210
- logger.info(`Sending "track" event "${payload.event}"`);
211
- const event = this.builder.buildTrack(payload);
212
- return await this.sendOrEnqueueEvent(event);
213
- }
214
- @guardedBy('isNotDuplicated', { onBlocked: 'onBlockedByDuplication' })
215
- @guardedBy('hasConsent', { onBlocked: 'onBlockedByConsent' })
216
- /**
217
- * Record a "sticky" component view and update optimization state.
218
- *
219
- * @param payload - Component view builder payload.
220
- * @param _duplicationScope - Optional duplication scope key used to suppress duplicates.
221
- * @returns The evaluated {@link OptimizationData} for this component view.
222
- */
223
- async trackComponentView(payload, _duplicationScope = '') {
224
- logger.info(`Sending "track personalization" event for ${payload.componentId}`);
225
- const event = this.builder.buildComponentView(payload);
226
- return await this.sendOrEnqueueEvent(event);
227
- }
228
- /**
229
- * Intercept, validate, and place an event into the offline eventd queue; then
230
- * trigger a size‑based flush if necessary.
231
- *
232
- * @param event - The event to enqueue.
233
- */
234
- async sendOrEnqueueEvent(event) {
235
- const intercepted = await this.interceptors.event.run(event);
236
- const validEvent = PersonalizationEvent.parse(intercepted);
237
- eventSignal.value = validEvent;
238
- if (onlineSignal.value)
239
- return await this.upsertProfile([validEvent]);
240
- logger.debug(`Queueing ${validEvent.type} event`, validEvent);
241
- this.offlineQueue.add(validEvent);
242
- return undefined;
243
- }
244
- /**
245
- * Flush the offline queue
246
- */
247
- async flush() {
248
- if (this.offlineQueue.size === 0)
249
- return;
250
- logger.debug('Flushing offline event queue');
251
- await this.upsertProfile(Array.from(this.offlineQueue));
252
- this.offlineQueue.clear();
253
- }
254
- /**
255
- * Submit events to the Experience API, updating output signals with the
256
- * returned state.
257
- *
258
- * @param events - The events to submit.
259
- * @returns The {@link OptimizationData} returned by the service.
260
- * @internal
261
- * @privateRemarks
262
- * If a `getAnonymousId` function has been provided, the returned value will
263
- * take precedence over the `id` property of the current {@link Profile}
264
- * signal value
265
- */
266
- async upsertProfile(events) {
267
- const anonymousId = this.getAnonymousId();
268
- if (anonymousId)
269
- logger.debug(`Anonymous ID found: ${anonymousId}`);
270
- const data = await this.api.experience.upsertProfile({
271
- profileId: anonymousId ?? profileSignal.value?.id,
272
- events,
273
- });
274
- await this.updateOutputSignals(data);
275
- return data;
276
- }
277
- /**
278
- * Apply returned optimization state to local signals after interceptor processing.
279
- *
280
- * @param data - Optimization state returned by the service.
281
- * @internal
282
- */
283
- async updateOutputSignals(data) {
284
- const intercepted = await this.interceptors.state.run(data);
285
- const { changes, personalizations, profile } = intercepted;
286
- batch(() => {
287
- if (!isEqual(changesSignal.value, changes))
288
- changesSignal.value = changes;
289
- if (!isEqual(profileSignal.value, profile))
290
- profileSignal.value = profile;
291
- if (!isEqual(personalizationsSignal.value, personalizations))
292
- personalizationsSignal.value = personalizations;
293
- });
294
- }
295
- }
296
- export default PersonalizationStateful;
297
- //# sourceMappingURL=PersonalizationStateful.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PersonalizationStateful.js","sourceRoot":"","sources":["../../src/personalization/PersonalizationStateful.ts"],"names":[],"mappings":"AAAA,OAAO,EAUL,eAAe,IAAI,oBAAoB,GAMxC,MAAM,qCAAqC,CAAA;AAE5C,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AACpC,OAAO,EAAE,kBAAkB,EAAE,MAAM,QAAQ,CAAA;AAE3C,OAAO,EAAE,SAAS,EAAE,MAAM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AAI,CAAC,YAAY,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;QAE3D,MAAM,EAAE,OAAO,EAAE,gBAAgB,EAAE,OAAO,EAAE,GAAG,WAAW,CAAA;QAE1D,KAAK,CAAC,GAAG,EAAE;YACT,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,KAAK,EAAE,OAAO,CAAC;gBAAE,aAAa,CAAC,KAAK,GAAG,OAAO,CAAA;YACzE,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,KAAK,EAAE,OAAO,CAAC;gBAAE,aAAa,CAAC,KAAK,GAAG,OAAO,CAAA;YACzE,IAAI,CAAC,OAAO,CAAC,sBAAsB,CAAC,KAAK,EAAE,gBAAgB,CAAC;gBAC1D,sBAAsB,CAAC,KAAK,GAAG,gBAAgB,CAAA;QACnD,CAAC,CAAC,CAAA;IACJ,CAAC;CACF;AAED,eAAe,uBAAuB,CAAA"}
@@ -1,74 +0,0 @@
1
- import { type ComponentViewBuilderArgs, type IdentifyBuilderArgs, type OptimizationData, type PageViewBuilderArgs, type PartialProfile, type ScreenViewBuilderArgs, type TrackBuilderArgs } from '@contentful/optimization-api-client';
2
- import PersonalizationBase from './PersonalizationBase';
3
- /**
4
- * Stateless personalization implementation that immediately validates and sends
5
- * a single event to the Experience API, upserting the profile as needed.
6
- *
7
- * @public
8
- * @remarks
9
- * Each public method constructs a strongly-typed event via the shared builder,
10
- * runs it through event interceptors, and performs a profile upsert using the
11
- * Experience API. If an anonymous ID is available from the builder, it will be
12
- * preferred as the `profileId` unless an explicit profile is provided.
13
- */
14
- declare class PersonalizationStateless extends PersonalizationBase {
15
- /**
16
- * Identify the current profile/visitor to associate traits with a profile.
17
- *
18
- * @param payload - Identify builder arguments with an optional partial
19
- * profile to attach to the upsert request.
20
- * @returns The resulting {@link OptimizationData} for the identified user.
21
- */
22
- identify(payload: IdentifyBuilderArgs & {
23
- profile?: PartialProfile;
24
- }): Promise<OptimizationData>;
25
- /**
26
- * Record a page view.
27
- *
28
- * @param payload - Page view builder arguments with an optional partial profile.
29
- * @returns The evaluated {@link OptimizationData} for this page view.
30
- */
31
- page(payload: PageViewBuilderArgs & {
32
- profile?: PartialProfile;
33
- }): Promise<OptimizationData>;
34
- /**
35
- * Record a screen view.
36
- *
37
- * @param payload - Screen view builder arguments with an optional partial profile.
38
- * @returns The evaluated {@link OptimizationData} for this screen view.
39
- */
40
- screen(payload: ScreenViewBuilderArgs & {
41
- profile?: PartialProfile;
42
- }): Promise<OptimizationData>;
43
- /**
44
- * Record a custom track event.
45
- *
46
- * @param payload - Track builder arguments with an optional partial profile.
47
- * @returns The evaluated {@link OptimizationData} for this event.
48
- */
49
- track(payload: TrackBuilderArgs & {
50
- profile?: PartialProfile;
51
- }): Promise<OptimizationData>;
52
- /**
53
- * Record a "sticky" component view.
54
- *
55
- * @param payload - Component view builder arguments with an optional partial profile.
56
- * @returns The evaluated {@link OptimizationData} for this component view.
57
- */
58
- trackComponentView(payload: ComponentViewBuilderArgs & {
59
- profile?: PartialProfile;
60
- }): Promise<OptimizationData>;
61
- /**
62
- * Intercept, validate, and upsert the profile with a single personalization
63
- * event.
64
- *
65
- * @param event - The {@link PersonalizationEvent} to submit.
66
- * @param profile - Optional partial profile. If omitted, the anonymous ID from
67
- * the builder (when present) is used as the `profileId`.
68
- * @returns The {@link OptimizationData} returned by the Experience API.
69
- * @internal
70
- */
71
- private upsertProfile;
72
- }
73
- export default PersonalizationStateless;
74
- //# sourceMappingURL=PersonalizationStateless.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PersonalizationStateless.d.ts","sourceRoot":"","sources":["../../src/personalization/PersonalizationStateless.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,wBAAwB,EAE7B,KAAK,mBAAmB,EAExB,KAAK,gBAAgB,EACrB,KAAK,mBAAmB,EAExB,KAAK,cAAc,EAEnB,KAAK,qBAAqB,EAE1B,KAAK,gBAAgB,EAEtB,MAAM,qCAAqC,CAAA;AAE5C,OAAO,mBAAmB,MAAM,uBAAuB,CAAA;AAIvD;;;;;;;;;;GAUG;AACH,cAAM,wBAAyB,SAAQ,mBAAmB;IACxD;;;;;;OAMG;IACG,QAAQ,CACZ,OAAO,EAAE,mBAAmB,GAAG;QAAE,OAAO,CAAC,EAAE,cAAc,CAAA;KAAE,GAC1D,OAAO,CAAC,gBAAgB,CAAC;IAU5B;;;;;OAKG;IACG,IAAI,CACR,OAAO,EAAE,mBAAmB,GAAG;QAAE,OAAO,CAAC,EAAE,cAAc,CAAA;KAAE,GAC1D,OAAO,CAAC,gBAAgB,CAAC;IAU5B;;;;;OAKG;IACG,MAAM,CACV,OAAO,EAAE,qBAAqB,GAAG;QAAE,OAAO,CAAC,EAAE,cAAc,CAAA;KAAE,GAC5D,OAAO,CAAC,gBAAgB,CAAC;IAU5B;;;;;OAKG;IACG,KAAK,CAAC,OAAO,EAAE,gBAAgB,GAAG;QAAE,OAAO,CAAC,EAAE,cAAc,CAAA;KAAE,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAUhG;;;;;OAKG;IACG,kBAAkB,CACtB,OAAO,EAAE,wBAAwB,GAAG;QAAE,OAAO,CAAC,EAAE,cAAc,CAAA;KAAE,GAC/D,OAAO,CAAC,gBAAgB,CAAC;IAU5B;;;;;;;;;OASG;YACW,aAAa;CAa5B;AAED,eAAe,wBAAwB,CAAA"}