@contentful/optimization-core 0.1.0-alpha7 → 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.
- package/README.md +221 -31
- package/dist/260.mjs +14 -0
- package/dist/260.mjs.map +1 -0
- package/dist/499.mjs +4 -0
- package/dist/632.mjs +5 -0
- package/dist/632.mjs.map +1 -0
- package/dist/808.mjs +2 -0
- package/dist/942.mjs +2 -0
- package/dist/api-client.cjs +60 -0
- package/dist/api-client.cjs.map +1 -0
- package/dist/api-client.d.cts +4 -0
- package/dist/api-client.d.mts +4 -0
- package/dist/api-client.d.ts +4 -0
- package/dist/api-client.mjs +2 -0
- package/dist/api-schemas.cjs +60 -0
- package/dist/api-schemas.cjs.map +1 -0
- package/dist/api-schemas.d.cts +4 -0
- package/dist/api-schemas.d.mts +4 -0
- package/dist/api-schemas.d.ts +4 -0
- package/dist/api-schemas.mjs +2 -0
- package/dist/constants.cjs +78 -0
- package/dist/constants.cjs.map +1 -0
- package/dist/{global-constants.d.ts → constants.d.cts} +88 -67
- package/dist/{global-constants.js → constants.d.mts} +88 -69
- package/dist/constants.d.ts +88 -0
- package/dist/constants.mjs +1 -0
- package/dist/index.cjs +1833 -1706
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2432 -0
- package/dist/index.d.mts +2432 -0
- package/dist/index.d.ts +2432 -15
- package/dist/index.mjs +617 -341
- package/dist/index.mjs.map +1 -1
- package/dist/logger.cjs +67 -0
- package/dist/logger.cjs.map +1 -0
- package/dist/logger.d.cts +8 -0
- package/dist/logger.d.mts +8 -0
- package/dist/logger.d.ts +8 -0
- package/dist/logger.mjs +2 -0
- package/dist/symbols.cjs +42 -0
- package/dist/symbols.cjs.map +1 -0
- package/dist/symbols.d.cts +10 -0
- package/dist/symbols.d.mts +10 -0
- package/dist/symbols.d.ts +10 -0
- package/dist/symbols.mjs +1 -0
- package/package.json +65 -12
- package/dist/Consent.d.ts +0 -44
- package/dist/Consent.d.ts.map +0 -1
- package/dist/Consent.js +0 -2
- package/dist/Consent.js.map +0 -1
- package/dist/CoreBase.d.ts +0 -161
- package/dist/CoreBase.d.ts.map +0 -1
- package/dist/CoreBase.js +0 -151
- package/dist/CoreBase.js.map +0 -1
- package/dist/CoreStateful.d.ts +0 -144
- package/dist/CoreStateful.d.ts.map +0 -1
- package/dist/CoreStateful.js +0 -141
- package/dist/CoreStateful.js.map +0 -1
- package/dist/CoreStateless.d.ts +0 -53
- package/dist/CoreStateless.d.ts.map +0 -1
- package/dist/CoreStateless.js +0 -43
- package/dist/CoreStateless.js.map +0 -1
- package/dist/ProductBase.d.ts +0 -83
- package/dist/ProductBase.d.ts.map +0 -1
- package/dist/ProductBase.js +0 -50
- package/dist/ProductBase.js.map +0 -1
- package/dist/analytics/AnalyticsBase.d.ts +0 -35
- package/dist/analytics/AnalyticsBase.d.ts.map +0 -1
- package/dist/analytics/AnalyticsBase.js +0 -13
- package/dist/analytics/AnalyticsBase.js.map +0 -1
- package/dist/analytics/AnalyticsStateful.d.ts +0 -138
- package/dist/analytics/AnalyticsStateful.d.ts.map +0 -1
- package/dist/analytics/AnalyticsStateful.js +0 -179
- package/dist/analytics/AnalyticsStateful.js.map +0 -1
- package/dist/analytics/AnalyticsStateless.d.ts +0 -48
- package/dist/analytics/AnalyticsStateless.d.ts.map +0 -1
- package/dist/analytics/AnalyticsStateless.js +0 -61
- package/dist/analytics/AnalyticsStateless.js.map +0 -1
- package/dist/analytics/index.d.ts +0 -5
- package/dist/analytics/index.d.ts.map +0 -1
- package/dist/analytics/index.js +0 -5
- package/dist/analytics/index.js.map +0 -1
- package/dist/global-constants.d.ts.map +0 -1
- package/dist/global-constants.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -15
- package/dist/index.js.map +0 -1
- package/dist/lib/decorators/guardedBy.d.ts +0 -113
- package/dist/lib/decorators/guardedBy.d.ts.map +0 -1
- package/dist/lib/decorators/guardedBy.js +0 -143
- package/dist/lib/decorators/guardedBy.js.map +0 -1
- package/dist/lib/decorators/index.d.ts +0 -2
- package/dist/lib/decorators/index.d.ts.map +0 -1
- package/dist/lib/decorators/index.js +0 -2
- package/dist/lib/decorators/index.js.map +0 -1
- package/dist/lib/interceptor/InterceptorManager.d.ts +0 -127
- package/dist/lib/interceptor/InterceptorManager.d.ts.map +0 -1
- package/dist/lib/interceptor/InterceptorManager.js +0 -125
- package/dist/lib/interceptor/InterceptorManager.js.map +0 -1
- package/dist/lib/interceptor/index.d.ts +0 -2
- package/dist/lib/interceptor/index.d.ts.map +0 -1
- package/dist/lib/interceptor/index.js +0 -2
- package/dist/lib/interceptor/index.js.map +0 -1
- package/dist/lib/value-presence/ValuePresence.d.ts +0 -123
- package/dist/lib/value-presence/ValuePresence.d.ts.map +0 -1
- package/dist/lib/value-presence/ValuePresence.js +0 -141
- package/dist/lib/value-presence/ValuePresence.js.map +0 -1
- package/dist/lib/value-presence/index.d.ts +0 -2
- package/dist/lib/value-presence/index.d.ts.map +0 -1
- package/dist/lib/value-presence/index.js +0 -2
- package/dist/lib/value-presence/index.js.map +0 -1
- package/dist/personalization/PersonalizationBase.d.ts +0 -184
- package/dist/personalization/PersonalizationBase.d.ts.map +0 -1
- package/dist/personalization/PersonalizationBase.js +0 -76
- package/dist/personalization/PersonalizationBase.js.map +0 -1
- package/dist/personalization/PersonalizationStateful.d.ts +0 -226
- package/dist/personalization/PersonalizationStateful.d.ts.map +0 -1
- package/dist/personalization/PersonalizationStateful.js +0 -297
- package/dist/personalization/PersonalizationStateful.js.map +0 -1
- package/dist/personalization/PersonalizationStateless.d.ts +0 -74
- package/dist/personalization/PersonalizationStateless.d.ts.map +0 -1
- package/dist/personalization/PersonalizationStateless.js +0 -98
- package/dist/personalization/PersonalizationStateless.js.map +0 -1
- package/dist/personalization/index.d.ts +0 -6
- package/dist/personalization/index.d.ts.map +0 -1
- package/dist/personalization/index.js +0 -6
- package/dist/personalization/index.js.map +0 -1
- package/dist/personalization/resolvers/FlagsResolver.d.ts +0 -35
- package/dist/personalization/resolvers/FlagsResolver.d.ts.map +0 -1
- package/dist/personalization/resolvers/FlagsResolver.js +0 -47
- package/dist/personalization/resolvers/FlagsResolver.js.map +0 -1
- package/dist/personalization/resolvers/MergeTagValueResolver.d.ts +0 -74
- package/dist/personalization/resolvers/MergeTagValueResolver.d.ts.map +0 -1
- package/dist/personalization/resolvers/MergeTagValueResolver.js +0 -109
- package/dist/personalization/resolvers/MergeTagValueResolver.js.map +0 -1
- package/dist/personalization/resolvers/PersonalizedEntryResolver.d.ts +0 -142
- package/dist/personalization/resolvers/PersonalizedEntryResolver.d.ts.map +0 -1
- package/dist/personalization/resolvers/PersonalizedEntryResolver.js +0 -196
- package/dist/personalization/resolvers/PersonalizedEntryResolver.js.map +0 -1
- package/dist/personalization/resolvers/index.d.ts +0 -7
- package/dist/personalization/resolvers/index.d.ts.map +0 -1
- package/dist/personalization/resolvers/index.js +0 -7
- package/dist/personalization/resolvers/index.js.map +0 -1
- package/dist/signals.d.ts +0 -42
- package/dist/signals.d.ts.map +0 -1
- package/dist/signals.js +0 -36
- package/dist/signals.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,15 +1,2432 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Optimization Core SDK — platform-agnostic personalization and analytics.
|
|
3
|
+
*
|
|
4
|
+
* @packageDocumentation
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { ApiClient } from '@contentful/optimization-api-client';
|
|
8
|
+
import { ApiClientConfig } from '@contentful/optimization-api-client';
|
|
9
|
+
import { batch } from '@preact/signals-core';
|
|
10
|
+
import type { ChainModifiers } from 'contentful';
|
|
11
|
+
import { ChangeArray } from '@contentful/optimization-api-client/api-schemas';
|
|
12
|
+
import { ComponentClickBuilderArgs } from '@contentful/optimization-api-client';
|
|
13
|
+
import { ComponentHoverBuilderArgs } from '@contentful/optimization-api-client';
|
|
14
|
+
import { ComponentViewBuilderArgs } from '@contentful/optimization-api-client';
|
|
15
|
+
import { computed } from '@preact/signals-core';
|
|
16
|
+
import { effect } from '@preact/signals-core';
|
|
17
|
+
import type { Entry } from 'contentful';
|
|
18
|
+
import { EntryReplacementVariant } from '@contentful/optimization-api-schemas';
|
|
19
|
+
import { EntryReplacementVariant as EntryReplacementVariant_2 } from '@contentful/optimization-api-client/api-schemas';
|
|
20
|
+
import type { EntrySkeletonType } from 'contentful';
|
|
21
|
+
import { EventBuilder } from '@contentful/optimization-api-client';
|
|
22
|
+
import { EventBuilderConfig } from '@contentful/optimization-api-client';
|
|
23
|
+
import { ExperienceApiClientConfig } from '@contentful/optimization-api-client';
|
|
24
|
+
import { ExperienceEvent } from '@contentful/optimization-api-client/api-schemas';
|
|
25
|
+
import { ExperienceEventArray } from '@contentful/optimization-api-client/api-schemas';
|
|
26
|
+
import type { ExperienceEventType } from '@contentful/optimization-api-client/api-schemas';
|
|
27
|
+
import { Flags } from '@contentful/optimization-api-client/api-schemas';
|
|
28
|
+
import { GlobalApiConfigProperties } from '@contentful/optimization-api-client';
|
|
29
|
+
import { IdentifyBuilderArgs } from '@contentful/optimization-api-client';
|
|
30
|
+
import { InsightsApiClientConfig } from '@contentful/optimization-api-client';
|
|
31
|
+
import { InsightsEvent } from '@contentful/optimization-api-client/api-schemas';
|
|
32
|
+
import type { InsightsEventType } from '@contentful/optimization-api-client/api-schemas';
|
|
33
|
+
import { Json } from '@contentful/optimization-api-client/api-schemas';
|
|
34
|
+
import type { LocaleCode } from 'contentful';
|
|
35
|
+
import type { LogLevels } from '@contentful/optimization-api-client/logger';
|
|
36
|
+
import { MergeTagEntry } from '@contentful/optimization-api-client/api-schemas';
|
|
37
|
+
import { OptimizationData } from '@contentful/optimization-api-client/api-schemas';
|
|
38
|
+
import { PageViewBuilderArgs } from '@contentful/optimization-api-client';
|
|
39
|
+
import { PartialProfile } from '@contentful/optimization-api-client/api-schemas';
|
|
40
|
+
import { PersonalizationEntry } from '@contentful/optimization-api-schemas';
|
|
41
|
+
import { PersonalizationEntry as PersonalizationEntry_2 } from '@contentful/optimization-api-client/api-schemas';
|
|
42
|
+
import { PersonalizedEntry } from '@contentful/optimization-api-schemas';
|
|
43
|
+
import { PersonalizedEntry as PersonalizedEntry_2 } from '@contentful/optimization-api-client/api-schemas';
|
|
44
|
+
import { Profile } from '@contentful/optimization-api-client/api-schemas';
|
|
45
|
+
import { ReadonlySignal } from '@preact/signals-core';
|
|
46
|
+
import { ScreenViewBuilderArgs } from '@contentful/optimization-api-client';
|
|
47
|
+
import { SelectedPersonalization } from '@contentful/optimization-api-client/api-schemas';
|
|
48
|
+
import { SelectedPersonalization as SelectedPersonalization_2 } from '@contentful/optimization-api-schemas';
|
|
49
|
+
import { SelectedPersonalizationArray } from '@contentful/optimization-api-client/api-schemas';
|
|
50
|
+
import { Signal } from '@preact/signals-core';
|
|
51
|
+
import { TrackBuilderArgs } from '@contentful/optimization-api-client';
|
|
52
|
+
import { untracked } from '@preact/signals-core';
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Base class for analytics implementations (internal).
|
|
56
|
+
*
|
|
57
|
+
* @internal
|
|
58
|
+
* @remarks
|
|
59
|
+
* Concrete analytics classes should implement the component/flag view tracking
|
|
60
|
+
* methods below. This base is not part of the public API.
|
|
61
|
+
*/
|
|
62
|
+
declare abstract class AnalyticsBase extends ProductBase {
|
|
63
|
+
/**
|
|
64
|
+
* Track a UI component view event.
|
|
65
|
+
*
|
|
66
|
+
* @param payload - Component view builder arguments.
|
|
67
|
+
* @returns A promise that resolves when processing is complete (or `void`).
|
|
68
|
+
*/
|
|
69
|
+
abstract trackComponentView(payload: ComponentViewBuilderArgs): Promise<void> | void;
|
|
70
|
+
/**
|
|
71
|
+
* Track a UI component click event.
|
|
72
|
+
*
|
|
73
|
+
* @param payload - Component click builder arguments.
|
|
74
|
+
* @returns A promise that resolves when processing is complete (or `void`).
|
|
75
|
+
*/
|
|
76
|
+
abstract trackComponentClick(payload: ComponentClickBuilderArgs): Promise<void> | void;
|
|
77
|
+
/**
|
|
78
|
+
* Track a UI component hover event.
|
|
79
|
+
*
|
|
80
|
+
* @param payload - Component hover builder arguments.
|
|
81
|
+
* @returns A promise that resolves when processing is complete (or `void`).
|
|
82
|
+
*/
|
|
83
|
+
abstract trackComponentHover(payload: ComponentHoverBuilderArgs): Promise<void> | void;
|
|
84
|
+
/**
|
|
85
|
+
* Track a flag (feature) view event.
|
|
86
|
+
*
|
|
87
|
+
* @param payload - Flag view builder arguments.
|
|
88
|
+
* @returns A promise that resolves when processing is complete (or `void`).
|
|
89
|
+
*/
|
|
90
|
+
abstract trackFlagView(payload: ComponentViewBuilderArgs): Promise<void> | void;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Configuration for the stateful analytics implementation.
|
|
95
|
+
*
|
|
96
|
+
* @public
|
|
97
|
+
*/
|
|
98
|
+
export declare interface AnalyticsProductConfig extends ProductConfig {
|
|
99
|
+
/**
|
|
100
|
+
* Default signal values applied on initialization.
|
|
101
|
+
*/
|
|
102
|
+
defaults?: AnalyticsProductConfigDefaults;
|
|
103
|
+
/**
|
|
104
|
+
* Policy that controls stateful queue flush retries, backoff, and circuit
|
|
105
|
+
* behavior after repeated failures.
|
|
106
|
+
*/
|
|
107
|
+
queuePolicy?: QueueFlushPolicy;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Default analytics state values applied at construction time.
|
|
112
|
+
*
|
|
113
|
+
* @public
|
|
114
|
+
*/
|
|
115
|
+
export declare interface AnalyticsProductConfigDefaults {
|
|
116
|
+
/** Whether analytics collection is allowed by default. */
|
|
117
|
+
consent?: boolean;
|
|
118
|
+
/** Default profile to associate with events. */
|
|
119
|
+
profile?: Profile;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Analytics implementation that maintains local state (consent, profile) and
|
|
124
|
+
* queues events until flushed or the queue reaches a maximum size.
|
|
125
|
+
*
|
|
126
|
+
* @remarks
|
|
127
|
+
* Repeated flush failures are managed by the configured {@link QueueFlushPolicy}
|
|
128
|
+
* using bounded backoff and a temporary circuit-open window.
|
|
129
|
+
*
|
|
130
|
+
* @public
|
|
131
|
+
*/
|
|
132
|
+
export declare class AnalyticsStateful extends AnalyticsBase implements ConsentGuard {
|
|
133
|
+
/** In-memory queue keyed by stable profile identifier. */
|
|
134
|
+
private readonly queue;
|
|
135
|
+
/** Shared queue flush retry runtime state machine. */
|
|
136
|
+
private readonly flushRuntime;
|
|
137
|
+
/** Exposed observable state references. */
|
|
138
|
+
readonly states: AnalyticsStates;
|
|
139
|
+
/**
|
|
140
|
+
* Create a new stateful analytics instance.
|
|
141
|
+
*
|
|
142
|
+
* @param options - Options to configure the analytics product for stateful environments.
|
|
143
|
+
* @example
|
|
144
|
+
* ```ts
|
|
145
|
+
* const analytics = new AnalyticsStateful({ api, builder, config: { defaults: { consent: true } }, interceptors })
|
|
146
|
+
* ```
|
|
147
|
+
*/
|
|
148
|
+
constructor(options: AnalyticsStatefulOptions);
|
|
149
|
+
/**
|
|
150
|
+
* Reset analytics‑related signals and the last emitted event.
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* ```ts
|
|
154
|
+
* analytics.reset()
|
|
155
|
+
* ```
|
|
156
|
+
*/
|
|
157
|
+
reset(): void;
|
|
158
|
+
/**
|
|
159
|
+
* Determine whether the named operation is permitted based on consent and
|
|
160
|
+
* allowed event type configuration.
|
|
161
|
+
*
|
|
162
|
+
* @param name - The method name; component view/flag methods are normalized
|
|
163
|
+
* to `'component'`, component click methods are normalized to `'component_click'`,
|
|
164
|
+
* and component hover methods are normalized to `'component_hover'` for
|
|
165
|
+
* allow‑list checks.
|
|
166
|
+
* @returns `true` if the operation is permitted; otherwise `false`.
|
|
167
|
+
* @example
|
|
168
|
+
* ```ts
|
|
169
|
+
* if (analytics.hasConsent('track')) { ... }
|
|
170
|
+
* ```
|
|
171
|
+
*/
|
|
172
|
+
hasConsent(name: string): boolean;
|
|
173
|
+
/**
|
|
174
|
+
* Hook invoked when an operation is blocked due to missing consent.
|
|
175
|
+
*
|
|
176
|
+
* @param name - The blocked operation name.
|
|
177
|
+
* @param payload - The original arguments supplied to the operation.
|
|
178
|
+
* @example
|
|
179
|
+
* ```ts
|
|
180
|
+
* analytics.onBlockedByConsent('track', [payload])
|
|
181
|
+
* ```
|
|
182
|
+
*/
|
|
183
|
+
onBlockedByConsent(name: string, payload: readonly unknown[]): void;
|
|
184
|
+
/**
|
|
185
|
+
* Queue a component view event for the active profile.
|
|
186
|
+
*
|
|
187
|
+
* @param payload - Component view builder arguments.
|
|
188
|
+
* @returns A promise that resolves when the event has been queued.
|
|
189
|
+
* @example
|
|
190
|
+
* ```ts
|
|
191
|
+
* await analytics.trackComponentView({ componentId: 'hero-banner' })
|
|
192
|
+
* ```
|
|
193
|
+
*/
|
|
194
|
+
trackComponentView(payload: ComponentViewBuilderArgs): Promise<void>;
|
|
195
|
+
/**
|
|
196
|
+
* Queue a component click event for the active profile.
|
|
197
|
+
*
|
|
198
|
+
* @param payload - Component click builder arguments.
|
|
199
|
+
* @returns A promise that resolves when the event has been queued.
|
|
200
|
+
* @example
|
|
201
|
+
* ```ts
|
|
202
|
+
* await analytics.trackComponentClick({ componentId: 'hero-banner' })
|
|
203
|
+
* ```
|
|
204
|
+
*/
|
|
205
|
+
trackComponentClick(payload: ComponentClickBuilderArgs): Promise<void>;
|
|
206
|
+
/**
|
|
207
|
+
* Queue a component hover event for the active profile.
|
|
208
|
+
*
|
|
209
|
+
* @param payload - Component hover builder arguments.
|
|
210
|
+
* @returns A promise that resolves when the event has been queued.
|
|
211
|
+
* @example
|
|
212
|
+
* ```ts
|
|
213
|
+
* await analytics.trackComponentHover({ componentId: 'hero-banner' })
|
|
214
|
+
* ```
|
|
215
|
+
*/
|
|
216
|
+
trackComponentHover(payload: ComponentHoverBuilderArgs): Promise<void>;
|
|
217
|
+
/**
|
|
218
|
+
* Queue a flag view event for the active profile.
|
|
219
|
+
*
|
|
220
|
+
* @param payload - Flag view builder arguments.
|
|
221
|
+
* @returns A promise that resolves when the event has been queued.
|
|
222
|
+
* @example
|
|
223
|
+
* ```ts
|
|
224
|
+
* await analytics.trackFlagView({ componentId: 'feature-flag-123' })
|
|
225
|
+
* ```
|
|
226
|
+
*/
|
|
227
|
+
trackFlagView(payload: ComponentViewBuilderArgs): Promise<void>;
|
|
228
|
+
/**
|
|
229
|
+
* Intercept, validate, and place an event into the profile‑scoped queue; then
|
|
230
|
+
* trigger a size‑based flush if necessary.
|
|
231
|
+
*
|
|
232
|
+
* @param event - The event to enqueue.
|
|
233
|
+
*/
|
|
234
|
+
private enqueueEvent;
|
|
235
|
+
/**
|
|
236
|
+
* Flush the queue automatically when the total number of queued events
|
|
237
|
+
* reaches {@link MAX_QUEUED_EVENTS}.
|
|
238
|
+
*/
|
|
239
|
+
private flushMaxEvents;
|
|
240
|
+
/**
|
|
241
|
+
* Send all queued events grouped by profile and clear the queue.
|
|
242
|
+
*
|
|
243
|
+
* @param options - Optional flush controls.
|
|
244
|
+
* @param options.force - When `true`, bypass offline/backoff/circuit gates and attempt immediately.
|
|
245
|
+
* @remarks Only under rare circumstances should there be more than one
|
|
246
|
+
* profile in a stateful application.
|
|
247
|
+
* @example
|
|
248
|
+
* ```ts
|
|
249
|
+
* await analytics.flush()
|
|
250
|
+
* ```
|
|
251
|
+
*/
|
|
252
|
+
flush(options?: {
|
|
253
|
+
force?: boolean;
|
|
254
|
+
}): Promise<void>;
|
|
255
|
+
/**
|
|
256
|
+
* Apply default stateful analytics values when provided.
|
|
257
|
+
*
|
|
258
|
+
* @param defaults - Optional defaults for analytics state.
|
|
259
|
+
*/
|
|
260
|
+
private applyDefaults;
|
|
261
|
+
/**
|
|
262
|
+
* Initialize reactive effects for consent/profile logging and online flushes.
|
|
263
|
+
*/
|
|
264
|
+
private initializeEffects;
|
|
265
|
+
/**
|
|
266
|
+
* Build batch payloads grouped by profile from the in-memory queue.
|
|
267
|
+
*
|
|
268
|
+
* @returns Grouped batch payloads.
|
|
269
|
+
*/
|
|
270
|
+
private createBatches;
|
|
271
|
+
/**
|
|
272
|
+
* Attempt to send queued batches to the Insights API.
|
|
273
|
+
*
|
|
274
|
+
* @param batches - Batches to send.
|
|
275
|
+
* @returns `true` when send succeeds; otherwise `false`.
|
|
276
|
+
*/
|
|
277
|
+
private trySendBatches;
|
|
278
|
+
/**
|
|
279
|
+
* Compute the total number of queued events across all profiles.
|
|
280
|
+
*
|
|
281
|
+
* @returns Total queued event count.
|
|
282
|
+
*/
|
|
283
|
+
private getQueuedEventCount;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Options for configuring {@link AnalyticsStateful} functionality.
|
|
288
|
+
*
|
|
289
|
+
* @public
|
|
290
|
+
* @see {@link ProductBaseOptions}
|
|
291
|
+
*/
|
|
292
|
+
export declare type AnalyticsStatefulOptions = ProductBaseOptions & {
|
|
293
|
+
/** Configuration specific to the Analytics product */
|
|
294
|
+
config?: AnalyticsProductConfig;
|
|
295
|
+
};
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* Stateless analytics implementation that sends each event immediately in a
|
|
299
|
+
* single‑event batch.
|
|
300
|
+
*
|
|
301
|
+
* @public
|
|
302
|
+
*/
|
|
303
|
+
export declare class AnalyticsStateless extends AnalyticsBase {
|
|
304
|
+
/**
|
|
305
|
+
* Build, intercept, validate, and send a component view event.
|
|
306
|
+
*
|
|
307
|
+
* @param args - {@link TrackComponentViewArgs} used to build the event. Includes an
|
|
308
|
+
* optional partial profile.
|
|
309
|
+
* @returns A promise that resolves once the batch has been sent.
|
|
310
|
+
* @example
|
|
311
|
+
* ```ts
|
|
312
|
+
* await analytics.trackComponentView({ componentId: 'hero-banner', profile: { id: 'user-1' } })
|
|
313
|
+
* ```
|
|
314
|
+
*/
|
|
315
|
+
trackComponentView(args: TrackComponentViewArgs): Promise<void>;
|
|
316
|
+
/**
|
|
317
|
+
* Build, intercept, validate, and send a component click event.
|
|
318
|
+
*
|
|
319
|
+
* @param args - {@link TrackComponentClickArgs} used to build the event. Includes an
|
|
320
|
+
* optional partial profile.
|
|
321
|
+
* @returns A promise that resolves once the batch has been sent.
|
|
322
|
+
* @example
|
|
323
|
+
* ```ts
|
|
324
|
+
* await analytics.trackComponentClick({ componentId: 'hero-banner', profile: { id: 'user-1' } })
|
|
325
|
+
* ```
|
|
326
|
+
*/
|
|
327
|
+
trackComponentClick(args: TrackComponentClickArgs): Promise<void>;
|
|
328
|
+
/**
|
|
329
|
+
* Build, intercept, validate, and send a component hover event.
|
|
330
|
+
*
|
|
331
|
+
* @param args - {@link TrackComponentHoverArgs} used to build the event. Includes an
|
|
332
|
+
* optional partial profile.
|
|
333
|
+
* @returns A promise that resolves once the batch has been sent.
|
|
334
|
+
* @example
|
|
335
|
+
* ```ts
|
|
336
|
+
* await analytics.trackComponentHover({ componentId: 'hero-banner', profile: { id: 'user-1' } })
|
|
337
|
+
* ```
|
|
338
|
+
*/
|
|
339
|
+
trackComponentHover(args: TrackComponentHoverArgs): Promise<void>;
|
|
340
|
+
/**
|
|
341
|
+
* Build, intercept, validate, and send a flag view event.
|
|
342
|
+
*
|
|
343
|
+
* @param args - {@link TrackComponentViewArgs} used to build the event. Includes an
|
|
344
|
+
* optional partial profile.
|
|
345
|
+
* @returns A promise that resolves once the batch has been sent.
|
|
346
|
+
* @example
|
|
347
|
+
* ```ts
|
|
348
|
+
* await analytics.trackFlagView({ componentId: 'feature-flag-123' })
|
|
349
|
+
* ```
|
|
350
|
+
*/
|
|
351
|
+
trackFlagView(args: TrackComponentViewArgs): Promise<void>;
|
|
352
|
+
/**
|
|
353
|
+
* Send a single {@link AnalyticsEvent} wrapped in a one‑item batch.
|
|
354
|
+
*
|
|
355
|
+
* @param event - The event to send.
|
|
356
|
+
* @param profile - Optional partial profile to attach to the batch.
|
|
357
|
+
* @returns A promise that resolves when the API call completes.
|
|
358
|
+
* @internal
|
|
359
|
+
*/
|
|
360
|
+
private sendBatchEvent;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
/**
|
|
364
|
+
* Observables exposed by the stateful analytics product.
|
|
365
|
+
*
|
|
366
|
+
* @public
|
|
367
|
+
*/
|
|
368
|
+
export declare interface AnalyticsStates {
|
|
369
|
+
/** Observable stream of the latest blocked event payload (or `undefined`). */
|
|
370
|
+
blockedEventStream: Observable<BlockedEvent | undefined>;
|
|
371
|
+
/** Observable stream of the latest {@link AnalyticsEvent} or {@link PersonalizationEvent} (or `undefined`). */
|
|
372
|
+
eventStream: Observable<InsightsEvent | ExperienceEvent | undefined>;
|
|
373
|
+
/** Observable stream of the active {@link Profile} (or `undefined`). */
|
|
374
|
+
profile: Observable<Profile | undefined>;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
/**
|
|
378
|
+
* Anonymous-ID cookie name used by the Optimization Core.
|
|
379
|
+
*
|
|
380
|
+
* @public
|
|
381
|
+
* @remarks
|
|
382
|
+
* This constant represents the cookie key used by the Optimization Framework
|
|
383
|
+
* to persist an anonymous identifier for tracking personalization and analytics
|
|
384
|
+
* events when no explicit profile is known.
|
|
385
|
+
*
|
|
386
|
+
* @example
|
|
387
|
+
* ```ts
|
|
388
|
+
* import { ANONYMOUS_ID_COOKIE } from '@contentful/optimization-core/constants'
|
|
389
|
+
* const profileId = request.cookies[ANONYMOUS_ID_COOKIE]
|
|
390
|
+
* ```
|
|
391
|
+
*/
|
|
392
|
+
export declare const ANONYMOUS_ID_COOKIE = "ctfl-opt-aid";
|
|
393
|
+
|
|
394
|
+
/**
|
|
395
|
+
* Legacy anoynmous ID cookie key for migration from experience.js
|
|
396
|
+
*
|
|
397
|
+
* @internal
|
|
398
|
+
*/
|
|
399
|
+
export declare const ANONYMOUS_ID_COOKIE_LEGACY = "ntaid";
|
|
400
|
+
|
|
401
|
+
/**
|
|
402
|
+
* Storage key for the anonymous identifier.
|
|
403
|
+
*
|
|
404
|
+
* @internal
|
|
405
|
+
*/
|
|
406
|
+
export declare const ANONYMOUS_ID_KEY = "__ctfl_opt_anonymous_id__";
|
|
407
|
+
|
|
408
|
+
/**
|
|
409
|
+
* Legacy anoynmous ID storage key for migration from experience.js
|
|
410
|
+
*
|
|
411
|
+
* @internal
|
|
412
|
+
*/
|
|
413
|
+
export declare const ANONYMOUS_ID_KEY_LEGACY = "__nt_anonymous_id__";
|
|
414
|
+
|
|
415
|
+
export { batch }
|
|
416
|
+
|
|
417
|
+
/**
|
|
418
|
+
* Payload emitted when event processing is blocked.
|
|
419
|
+
*
|
|
420
|
+
* @public
|
|
421
|
+
*/
|
|
422
|
+
export declare interface BlockedEvent {
|
|
423
|
+
/** Why the event was blocked. */
|
|
424
|
+
reason: BlockedEventReason;
|
|
425
|
+
/** Product that blocked the event. */
|
|
426
|
+
product: BlockedEventProduct;
|
|
427
|
+
/** Method name that was blocked. */
|
|
428
|
+
method: string;
|
|
429
|
+
/** Original arguments passed to the blocked method call. */
|
|
430
|
+
args: readonly unknown[];
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
declare const blockedEvent: Signal<BlockedEvent | undefined>;
|
|
434
|
+
|
|
435
|
+
/**
|
|
436
|
+
* Product that blocked the event.
|
|
437
|
+
*
|
|
438
|
+
* @public
|
|
439
|
+
*/
|
|
440
|
+
export declare type BlockedEventProduct = 'analytics' | 'personalization';
|
|
441
|
+
|
|
442
|
+
/**
|
|
443
|
+
* Reasons why an event was blocked before being sent.
|
|
444
|
+
*
|
|
445
|
+
* @public
|
|
446
|
+
*/
|
|
447
|
+
export declare type BlockedEventReason = 'consent';
|
|
448
|
+
|
|
449
|
+
/**
|
|
450
|
+
* A callback invoked when a method call is blocked by {@link guardedBy}.
|
|
451
|
+
*
|
|
452
|
+
* @param methodName - The name of the method that was attempted.
|
|
453
|
+
* @param args - The readonly array of arguments supplied to the blocked call.
|
|
454
|
+
* @returns Nothing.
|
|
455
|
+
*
|
|
456
|
+
* @public
|
|
457
|
+
*/
|
|
458
|
+
declare type BlockHandler = (methodName: string, args: readonly unknown[]) => void;
|
|
459
|
+
|
|
460
|
+
declare const changes: Signal<ChangeArray | undefined>;
|
|
461
|
+
|
|
462
|
+
/**
|
|
463
|
+
* Storage key for cached Custom Flags.
|
|
464
|
+
*
|
|
465
|
+
* @internal
|
|
466
|
+
*/
|
|
467
|
+
export declare const CHANGES_CACHE_KEY = "__ctfl_opt_changes__";
|
|
468
|
+
|
|
469
|
+
declare const consent: Signal<boolean | undefined>;
|
|
470
|
+
|
|
471
|
+
/**
|
|
472
|
+
* Storage key for the persisted consent status.
|
|
473
|
+
*
|
|
474
|
+
* @internal
|
|
475
|
+
*/
|
|
476
|
+
export declare const CONSENT_KEY = "__ctfl_opt_consent__";
|
|
477
|
+
|
|
478
|
+
/**
|
|
479
|
+
* Controller for updating the current consent state.
|
|
480
|
+
*
|
|
481
|
+
* @internal
|
|
482
|
+
* @remarks
|
|
483
|
+
* Intended for internal wiring between Core classes and the consent signal/store.
|
|
484
|
+
*/
|
|
485
|
+
declare interface ConsentController {
|
|
486
|
+
/**
|
|
487
|
+
* Update the runtime consent state.
|
|
488
|
+
*
|
|
489
|
+
* @param accept - `true` when the user has granted consent; `false` otherwise.
|
|
490
|
+
*/
|
|
491
|
+
consent: (accept: boolean) => void;
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
/**
|
|
495
|
+
* Contract implemented by classes that gate operations based on consent.
|
|
496
|
+
*
|
|
497
|
+
* @internal
|
|
498
|
+
* @remarks
|
|
499
|
+
* These methods are consumed by the `@guardedBy` decorator to decide whether to
|
|
500
|
+
* proceed with an operation and how to report blocked calls.
|
|
501
|
+
*/
|
|
502
|
+
declare interface ConsentGuard {
|
|
503
|
+
/**
|
|
504
|
+
* Determine whether the named operation is permitted given current consent and
|
|
505
|
+
* any allow‑list configuration.
|
|
506
|
+
*
|
|
507
|
+
* @param name - Logical operation/method name (e.g., `'track'`, `'page'`).
|
|
508
|
+
* @returns `true` if the operation may proceed; otherwise `false`.
|
|
509
|
+
* @remarks
|
|
510
|
+
* The mapping between method names and event type strings may be product‑specific.
|
|
511
|
+
*/
|
|
512
|
+
hasConsent: (name: string) => boolean;
|
|
513
|
+
/**
|
|
514
|
+
* Hook invoked when an operation is blocked due to missing consent.
|
|
515
|
+
*
|
|
516
|
+
* @param name - The blocked operation/method name.
|
|
517
|
+
* @param args - The original call arguments, provided for diagnostics/telemetry.
|
|
518
|
+
* @returns Nothing. Implementations typically log and/or emit diagnostics.
|
|
519
|
+
*/
|
|
520
|
+
onBlockedByConsent: (name: string, args: unknown[]) => void;
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
/**
|
|
524
|
+
* Internal base that wires the API client, event builder, and logging.
|
|
525
|
+
*
|
|
526
|
+
* @internal
|
|
527
|
+
*/
|
|
528
|
+
declare abstract class CoreBase implements ResolverMethods {
|
|
529
|
+
/** Product implementation for analytics. */
|
|
530
|
+
protected abstract _analytics: AnalyticsBase;
|
|
531
|
+
/** Product implementation for personalization. */
|
|
532
|
+
protected abstract _personalization: PersonalizationBase;
|
|
533
|
+
/** Shared Optimization API client instance. */
|
|
534
|
+
readonly api: ApiClient;
|
|
535
|
+
/** Shared event builder instance. */
|
|
536
|
+
readonly eventBuilder: EventBuilder;
|
|
537
|
+
/** Resolved core configuration (minus any name metadata). */
|
|
538
|
+
readonly config: Omit<CoreConfig, 'name'>;
|
|
539
|
+
/** Lifecycle interceptors for events and state updates. */
|
|
540
|
+
readonly interceptors: LifecycleInterceptors;
|
|
541
|
+
/**
|
|
542
|
+
* Create the core with API client and logging preconfigured.
|
|
543
|
+
*
|
|
544
|
+
* @param config - Core configuration including API and builder options.
|
|
545
|
+
* @example
|
|
546
|
+
* ```ts
|
|
547
|
+
* const sdk = new CoreStateless({ clientId: 'abc123', environment: 'prod' })
|
|
548
|
+
* ```
|
|
549
|
+
*/
|
|
550
|
+
constructor(config: CoreConfig);
|
|
551
|
+
/**
|
|
552
|
+
* Static {@link FlagsResolver | resolver} for evaluating personalized
|
|
553
|
+
* custom flags.
|
|
554
|
+
*/
|
|
555
|
+
get flagsResolver(): typeof FlagsResolver;
|
|
556
|
+
/**
|
|
557
|
+
* Static {@link MergeTagValueResolver | resolver} that returns values
|
|
558
|
+
* sourced from a user profile based on a Contentful Merge Tag entry.
|
|
559
|
+
*/
|
|
560
|
+
get mergeTagValueResolver(): typeof MergeTagValueResolver;
|
|
561
|
+
/**
|
|
562
|
+
* Static {@link PersonalizedEntryResolver | resolver } for personalized
|
|
563
|
+
* Contentful entries (e.g., entry variants targeted to a profile audience).
|
|
564
|
+
*
|
|
565
|
+
* @remarks
|
|
566
|
+
* Used by higher-level personalization flows to materialize entry content
|
|
567
|
+
* prior to event emission.
|
|
568
|
+
*/
|
|
569
|
+
get personalizedEntryResolver(): typeof PersonalizedEntryResolver;
|
|
570
|
+
/**
|
|
571
|
+
* Get the value of a custom flag derived from a set of optimization changes.
|
|
572
|
+
*
|
|
573
|
+
* @param name - The flag key to resolve.
|
|
574
|
+
* @param changes - Optional change list to resolve from.
|
|
575
|
+
* @returns The resolved JSON value for the flag if available.
|
|
576
|
+
* @remarks
|
|
577
|
+
* This is a convenience wrapper around personalization’s flag resolution.
|
|
578
|
+
* @example
|
|
579
|
+
* ```ts
|
|
580
|
+
* const darkMode = core.getCustomFlag('dark-mode', data.changes)
|
|
581
|
+
* ```
|
|
582
|
+
*/
|
|
583
|
+
getCustomFlag(name: string, changes?: ChangeArray): Json;
|
|
584
|
+
/**
|
|
585
|
+
* Get all resolved custom flags derived from a set of optimization changes.
|
|
586
|
+
*
|
|
587
|
+
* @param changes - Optional change list to resolve from.
|
|
588
|
+
* @returns The resolved custom flag map.
|
|
589
|
+
* @remarks
|
|
590
|
+
* This is a convenience wrapper around personalization’s flag resolution.
|
|
591
|
+
* @example
|
|
592
|
+
* ```ts
|
|
593
|
+
* const flags = core.getCustomFlags(data.changes)
|
|
594
|
+
* ```
|
|
595
|
+
*/
|
|
596
|
+
getCustomFlags(changes?: ChangeArray): Flags;
|
|
597
|
+
/**
|
|
598
|
+
* Resolve a Contentful entry to the appropriate personalized variant (or
|
|
599
|
+
* return the baseline entry if no matching variant is selected).
|
|
600
|
+
*
|
|
601
|
+
* @typeParam S - Entry skeleton type.
|
|
602
|
+
* @typeParam M - Chain modifiers.
|
|
603
|
+
* @typeParam L - Locale code.
|
|
604
|
+
* @param entry - The baseline entry to resolve.
|
|
605
|
+
* @param personalizations - Optional selection array for the current profile.
|
|
606
|
+
* @returns {@link ResolvedData} containing the resolved entry and
|
|
607
|
+
* personalization metadata (if any).
|
|
608
|
+
* @example
|
|
609
|
+
* ```ts
|
|
610
|
+
* const { entry, personalization } = core.personalizeEntry(baselineEntry, data.personalizations)
|
|
611
|
+
* ```
|
|
612
|
+
*/
|
|
613
|
+
personalizeEntry<S extends EntrySkeletonType, M extends ChainModifiers = ChainModifiers, L extends LocaleCode = LocaleCode>(entry: Entry<S, M, L>, personalizations?: SelectedPersonalizationArray): ResolvedData<S, M, L>;
|
|
614
|
+
/**
|
|
615
|
+
* Resolve a merge-tag value from the given entry node and profile.
|
|
616
|
+
*
|
|
617
|
+
* @param embeddedEntryNodeTarget - The merge-tag entry node to resolve.
|
|
618
|
+
* @param profile - Optional profile used for value lookup.
|
|
619
|
+
* @returns The resolved value (typically a string) or `undefined` if not found.
|
|
620
|
+
* @example
|
|
621
|
+
* ```ts
|
|
622
|
+
* const name = core.getMergeTagValue(mergeTagNode, profile)
|
|
623
|
+
* ```
|
|
624
|
+
*/
|
|
625
|
+
getMergeTagValue(embeddedEntryNodeTarget: MergeTagEntry, profile?: Profile): string | undefined;
|
|
626
|
+
/**
|
|
627
|
+
* Convenience wrapper for sending an `identify` event via personalization.
|
|
628
|
+
*
|
|
629
|
+
* @param payload - Identify builder arguments.
|
|
630
|
+
* @returns The resulting {@link OptimizationData} for the identified user.
|
|
631
|
+
* @example
|
|
632
|
+
* ```ts
|
|
633
|
+
* const data = await core.identify({ userId: 'user-123', traits: { plan: 'pro' } })
|
|
634
|
+
* ```
|
|
635
|
+
*/
|
|
636
|
+
identify(payload: IdentifyBuilderArgs & {
|
|
637
|
+
profile?: PartialProfile;
|
|
638
|
+
}): Promise<OptimizationData | undefined>;
|
|
639
|
+
/**
|
|
640
|
+
* Convenience wrapper for sending a `page` event via personalization.
|
|
641
|
+
*
|
|
642
|
+
* @param payload - Page view builder arguments.
|
|
643
|
+
* @returns The evaluated {@link OptimizationData} for this page view.
|
|
644
|
+
* @example
|
|
645
|
+
* ```ts
|
|
646
|
+
* const data = await core.page({ properties: { title: 'Home' } })
|
|
647
|
+
* ```
|
|
648
|
+
*/
|
|
649
|
+
page(payload: PageViewBuilderArgs & {
|
|
650
|
+
profile?: PartialProfile;
|
|
651
|
+
}): Promise<OptimizationData | undefined>;
|
|
652
|
+
/**
|
|
653
|
+
* Convenience wrapper for sending a `screen` event via personalization.
|
|
654
|
+
*
|
|
655
|
+
* @param payload - Screen view builder arguments.
|
|
656
|
+
* @returns The evaluated {@link OptimizationData} for this screen view.
|
|
657
|
+
* @example
|
|
658
|
+
* ```ts
|
|
659
|
+
* const data = await core.screen({ name: 'HomeScreen' })
|
|
660
|
+
* ```
|
|
661
|
+
*/
|
|
662
|
+
screen(payload: ScreenViewBuilderArgs & {
|
|
663
|
+
profile?: PartialProfile;
|
|
664
|
+
}): Promise<OptimizationData | undefined>;
|
|
665
|
+
/**
|
|
666
|
+
* Convenience wrapper for sending a custom `track` event via personalization.
|
|
667
|
+
*
|
|
668
|
+
* @param payload - Track builder arguments.
|
|
669
|
+
* @returns The evaluated {@link OptimizationData} for this event.
|
|
670
|
+
* @example
|
|
671
|
+
* ```ts
|
|
672
|
+
* const data = await core.track({ event: 'button_click', properties: { label: 'Buy' } })
|
|
673
|
+
* ```
|
|
674
|
+
*/
|
|
675
|
+
track(payload: TrackBuilderArgs & {
|
|
676
|
+
profile?: PartialProfile;
|
|
677
|
+
}): Promise<OptimizationData | undefined>;
|
|
678
|
+
/**
|
|
679
|
+
* Track a component view in both personalization and analytics.
|
|
680
|
+
*
|
|
681
|
+
* @param payload - Component view builder arguments. When `payload.sticky` is
|
|
682
|
+
* `true`, the event will also be sent via personalization as a sticky
|
|
683
|
+
* component view.
|
|
684
|
+
* @returns A promise that resolves when all delegated calls complete.
|
|
685
|
+
* @remarks
|
|
686
|
+
* The sticky behavior is delegated to personalization; analytics is always
|
|
687
|
+
* invoked regardless of `sticky`.
|
|
688
|
+
* @example
|
|
689
|
+
* ```ts
|
|
690
|
+
* await core.trackComponentView({ componentId: 'hero-banner', sticky: true })
|
|
691
|
+
* ```
|
|
692
|
+
*/
|
|
693
|
+
trackComponentView(payload: ComponentViewBuilderArgs & {
|
|
694
|
+
profile?: PartialProfile;
|
|
695
|
+
}): Promise<OptimizationData | undefined>;
|
|
696
|
+
/**
|
|
697
|
+
* Track a component click via analytics.
|
|
698
|
+
*
|
|
699
|
+
* @param payload - Component click builder arguments.
|
|
700
|
+
* @returns A promise that resolves when processing completes.
|
|
701
|
+
* @example
|
|
702
|
+
* ```ts
|
|
703
|
+
* await core.trackComponentClick({ componentId: 'hero-banner' })
|
|
704
|
+
* ```
|
|
705
|
+
*/
|
|
706
|
+
trackComponentClick(payload: ComponentClickBuilderArgs): Promise<void>;
|
|
707
|
+
/**
|
|
708
|
+
* Track a component hover via analytics.
|
|
709
|
+
*
|
|
710
|
+
* @param payload - Component hover builder arguments.
|
|
711
|
+
* @returns A promise that resolves when processing completes.
|
|
712
|
+
* @example
|
|
713
|
+
* ```ts
|
|
714
|
+
* await core.trackComponentHover({ componentId: 'hero-banner' })
|
|
715
|
+
* ```
|
|
716
|
+
*/
|
|
717
|
+
trackComponentHover(payload: ComponentHoverBuilderArgs): Promise<void>;
|
|
718
|
+
/**
|
|
719
|
+
* Track a feature flag view via analytics.
|
|
720
|
+
*
|
|
721
|
+
* @param payload - Component view builder arguments used to build the flag view event.
|
|
722
|
+
* @returns A promise that resolves when processing completes.
|
|
723
|
+
* @example
|
|
724
|
+
* ```ts
|
|
725
|
+
* await core.trackFlagView({ componentId: 'feature-flag-123' })
|
|
726
|
+
* ```
|
|
727
|
+
*/
|
|
728
|
+
trackFlagView(payload: ComponentViewBuilderArgs): Promise<void>;
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
/**
|
|
732
|
+
* Options for configuring the {@link CoreBase} runtime and underlying clients.
|
|
733
|
+
*
|
|
734
|
+
* @public
|
|
735
|
+
*/
|
|
736
|
+
export declare interface CoreConfig extends Pick<ApiClientConfig, GlobalApiConfigProperties> {
|
|
737
|
+
/**
|
|
738
|
+
* Configuration for the personalization (Experience) API client.
|
|
739
|
+
*/
|
|
740
|
+
personalization?: Omit<ExperienceApiClientConfig, GlobalApiConfigProperties>;
|
|
741
|
+
/**
|
|
742
|
+
* Configuration for the analytics (Insights) API client.
|
|
743
|
+
*/
|
|
744
|
+
analytics?: Omit<InsightsApiClientConfig, GlobalApiConfigProperties>;
|
|
745
|
+
/**
|
|
746
|
+
* Event builder configuration (channel/library metadata, etc.).
|
|
747
|
+
*/
|
|
748
|
+
eventBuilder?: EventBuilderConfig;
|
|
749
|
+
/** Minimum log level for the default console sink. */
|
|
750
|
+
logLevel?: LogLevels;
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
/**
|
|
754
|
+
* Default values used to preconfigure the stateful core and products.
|
|
755
|
+
*
|
|
756
|
+
* @public
|
|
757
|
+
*/
|
|
758
|
+
export declare interface CoreConfigDefaults {
|
|
759
|
+
/** Global consent default applied at construction time. */
|
|
760
|
+
consent?: boolean;
|
|
761
|
+
/** Default active profile used for personalization and analytics. */
|
|
762
|
+
profile?: Profile;
|
|
763
|
+
/** Initial diff of changes produced by the service. */
|
|
764
|
+
changes?: ChangeArray;
|
|
765
|
+
/** Preselected personalization variants (e.g., winning treatments). */
|
|
766
|
+
personalizations?: SelectedPersonalizationArray;
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
/**
|
|
770
|
+
* Core runtime that constructs stateful product instances and exposes shared
|
|
771
|
+
* states, including consent, blocked events, and the event stream.
|
|
772
|
+
*
|
|
773
|
+
* @remarks
|
|
774
|
+
* Extends {@link CoreBase} with stateful capabilities, including
|
|
775
|
+
* consent management via {@link ConsentController}.
|
|
776
|
+
* @see {@link CoreBase}
|
|
777
|
+
* @see {@link ConsentController}
|
|
778
|
+
* @public
|
|
779
|
+
*/
|
|
780
|
+
export declare class CoreStateful extends CoreBase implements ConsentController {
|
|
781
|
+
private readonly singletonOwner;
|
|
782
|
+
private destroyed;
|
|
783
|
+
/** Stateful analytics product. */
|
|
784
|
+
protected _analytics: AnalyticsStateful;
|
|
785
|
+
/** Stateful personalization product. */
|
|
786
|
+
protected _personalization: PersonalizationStateful;
|
|
787
|
+
/**
|
|
788
|
+
* Create a stateful core with optional default consent and product defaults.
|
|
789
|
+
*
|
|
790
|
+
* @param config - Core and defaults configuration.
|
|
791
|
+
* @example
|
|
792
|
+
* ```ts
|
|
793
|
+
* const core = new CoreStateful({
|
|
794
|
+
* clientId: 'app',
|
|
795
|
+
* environment: 'prod',
|
|
796
|
+
* defaults: { consent: true }
|
|
797
|
+
* })
|
|
798
|
+
* core.consent(true)
|
|
799
|
+
* ```
|
|
800
|
+
*/
|
|
801
|
+
constructor(config: CoreStatefulConfig);
|
|
802
|
+
/**
|
|
803
|
+
* Release singleton ownership for stateful runtime usage.
|
|
804
|
+
*
|
|
805
|
+
* @remarks
|
|
806
|
+
* This method is idempotent and should be called when a stateful SDK instance
|
|
807
|
+
* is no longer needed (e.g. tests, hot reload, explicit teardown).
|
|
808
|
+
*/
|
|
809
|
+
destroy(): void;
|
|
810
|
+
/**
|
|
811
|
+
* Expose merged observable state for consumers.
|
|
812
|
+
*
|
|
813
|
+
* @returns The combined {@link CoreStates} observable object.
|
|
814
|
+
*/
|
|
815
|
+
get states(): CoreStates;
|
|
816
|
+
/**
|
|
817
|
+
* Reset internal state. Consent and preview panel state are intentionally preserved.
|
|
818
|
+
*
|
|
819
|
+
* @remarks
|
|
820
|
+
* Resetting personalization also resets analytics dependencies as a
|
|
821
|
+
* consequence of the current shared-state design.
|
|
822
|
+
* @example
|
|
823
|
+
* ```ts
|
|
824
|
+
* core.reset()
|
|
825
|
+
* ```
|
|
826
|
+
*/
|
|
827
|
+
reset(): void;
|
|
828
|
+
/**
|
|
829
|
+
* Flush the queues for both the analytics and personalization products.
|
|
830
|
+
* @remarks
|
|
831
|
+
* The personalization queue is only populated if events have been triggered
|
|
832
|
+
* while a device is offline.
|
|
833
|
+
* @example
|
|
834
|
+
* ```ts
|
|
835
|
+
* await core.flush()
|
|
836
|
+
* ```
|
|
837
|
+
*/
|
|
838
|
+
flush(): Promise<void>;
|
|
839
|
+
/**
|
|
840
|
+
* Update consent state
|
|
841
|
+
*
|
|
842
|
+
* @param accept - `true` if the user has granted consent; `false` otherwise.
|
|
843
|
+
* @example
|
|
844
|
+
* ```ts
|
|
845
|
+
* core.consent(true)
|
|
846
|
+
* ```
|
|
847
|
+
*/
|
|
848
|
+
consent(accept: boolean): void;
|
|
849
|
+
/**
|
|
850
|
+
* Read current online state.
|
|
851
|
+
*
|
|
852
|
+
* @example
|
|
853
|
+
* ```ts
|
|
854
|
+
* if (this.online) {
|
|
855
|
+
* await this.flush()
|
|
856
|
+
* }
|
|
857
|
+
* ```
|
|
858
|
+
*/
|
|
859
|
+
protected get online(): boolean;
|
|
860
|
+
/**
|
|
861
|
+
* Update online state.
|
|
862
|
+
*
|
|
863
|
+
* @param isOnline - `true` if the runtime is online; `false` otherwise.
|
|
864
|
+
* @example
|
|
865
|
+
* ```ts
|
|
866
|
+
* this.online = navigator.onLine
|
|
867
|
+
* ```
|
|
868
|
+
*/
|
|
869
|
+
protected set online(isOnline: boolean);
|
|
870
|
+
/**
|
|
871
|
+
* Register a preview panel compatible object to receive direct signal access.
|
|
872
|
+
* This enables the preview panel to modify SDK state for testing and simulation.
|
|
873
|
+
*
|
|
874
|
+
* @param previewPanel - An object implementing PreviewPanelSignalObject
|
|
875
|
+
* @remarks
|
|
876
|
+
* This method is intended for use by the Preview Panel component.
|
|
877
|
+
* Direct signal access allows immediate state updates without API calls.
|
|
878
|
+
* @example
|
|
879
|
+
* ```ts
|
|
880
|
+
* const previewBridge: PreviewPanelSignalObject = {}
|
|
881
|
+
* core.registerPreviewPanel(previewBridge)
|
|
882
|
+
* ```
|
|
883
|
+
*/
|
|
884
|
+
registerPreviewPanel(previewPanel: PreviewPanelSignalObject): void;
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
/**
|
|
888
|
+
* Stateful analytics configuration.
|
|
889
|
+
*
|
|
890
|
+
* @public
|
|
891
|
+
*/
|
|
892
|
+
export declare type CoreStatefulAnalyticsConfig = NonNullable<CoreConfig['analytics']> & {
|
|
893
|
+
/**
|
|
894
|
+
* Queue policy for stateful analytics event buffering and flush retries.
|
|
895
|
+
*
|
|
896
|
+
* @see {@link AnalyticsProductConfig.queuePolicy}
|
|
897
|
+
*/
|
|
898
|
+
queuePolicy?: AnalyticsProductConfig['queuePolicy'];
|
|
899
|
+
};
|
|
900
|
+
|
|
901
|
+
/**
|
|
902
|
+
* Configuration for {@link CoreStateful}.
|
|
903
|
+
*
|
|
904
|
+
* @public
|
|
905
|
+
* @see {@link CoreConfig}
|
|
906
|
+
*/
|
|
907
|
+
export declare interface CoreStatefulConfig extends CoreConfig {
|
|
908
|
+
/**
|
|
909
|
+
* Configuration for the analytics (Insights) API client plus stateful queue behavior.
|
|
910
|
+
*/
|
|
911
|
+
analytics?: CoreStatefulAnalyticsConfig;
|
|
912
|
+
/**
|
|
913
|
+
* Configuration for the personalization (Experience) API client plus stateful queue behavior.
|
|
914
|
+
*/
|
|
915
|
+
personalization?: CoreStatefulPersonalizationConfig;
|
|
916
|
+
/**
|
|
917
|
+
* Allow-listed event type strings permitted when consent is not set.
|
|
918
|
+
*
|
|
919
|
+
* @see {@link ProductConfig.allowedEventTypes}
|
|
920
|
+
*/
|
|
921
|
+
allowedEventTypes?: ProductConfig['allowedEventTypes'];
|
|
922
|
+
/** Optional set of default values applied on initialization. */
|
|
923
|
+
defaults?: CoreConfigDefaults;
|
|
924
|
+
/** Function used to obtain an anonymous user identifier. */
|
|
925
|
+
getAnonymousId?: PersonalizationProductConfig['getAnonymousId'];
|
|
926
|
+
/**
|
|
927
|
+
* Callback invoked whenever an event call is blocked by checks.
|
|
928
|
+
*/
|
|
929
|
+
onEventBlocked?: ProductConfig['onEventBlocked'];
|
|
930
|
+
}
|
|
931
|
+
|
|
932
|
+
/**
|
|
933
|
+
* Stateful personalization configuration.
|
|
934
|
+
*
|
|
935
|
+
* @public
|
|
936
|
+
*/
|
|
937
|
+
export declare type CoreStatefulPersonalizationConfig = NonNullable<CoreConfig['personalization']> & {
|
|
938
|
+
/**
|
|
939
|
+
* Queue policy for stateful personalization offline event buffering.
|
|
940
|
+
*
|
|
941
|
+
* @see {@link PersonalizationProductConfig.queuePolicy}
|
|
942
|
+
*/
|
|
943
|
+
queuePolicy?: PersonalizationProductConfig['queuePolicy'];
|
|
944
|
+
};
|
|
945
|
+
|
|
946
|
+
/**
|
|
947
|
+
* Core runtime that constructs product instances for stateless environments.
|
|
948
|
+
*
|
|
949
|
+
* @public
|
|
950
|
+
* @see {@link CoreBase}
|
|
951
|
+
*/
|
|
952
|
+
export declare class CoreStateless extends CoreBase {
|
|
953
|
+
/** Stateless analytics product. */
|
|
954
|
+
protected _analytics: AnalyticsStateless;
|
|
955
|
+
/** Stateless personalization product. */
|
|
956
|
+
protected _personalization: PersonalizationStateless;
|
|
957
|
+
/**
|
|
958
|
+
* Create a stateless core. Product instances share the same API client and
|
|
959
|
+
* event builder configured in {@link CoreBase}.
|
|
960
|
+
*
|
|
961
|
+
* @param config - Stateless Core configuration.
|
|
962
|
+
* @example
|
|
963
|
+
* ```ts
|
|
964
|
+
* const sdk = new CoreStateless({ clientId: 'app', environment: 'prod' })
|
|
965
|
+
* core.trackFlagView({ componentId: 'hero' })
|
|
966
|
+
* ```
|
|
967
|
+
*/
|
|
968
|
+
constructor(config: CoreStatelessConfig);
|
|
969
|
+
}
|
|
970
|
+
|
|
971
|
+
/**
|
|
972
|
+
* Configuration for the Node-specific Optimization SDK.
|
|
973
|
+
*
|
|
974
|
+
* @public
|
|
975
|
+
* @remarks
|
|
976
|
+
* This configuration extends {@link CoreConfig} but allows partial overrides
|
|
977
|
+
* of the event-builder configuration. SDKs commonly inject their own library
|
|
978
|
+
* metadata or channel definitions.
|
|
979
|
+
*/
|
|
980
|
+
export declare interface CoreStatelessConfig extends CoreConfig {
|
|
981
|
+
/**
|
|
982
|
+
* Override configuration for the analytics (Insights) API client. Omits
|
|
983
|
+
* `beaconHandler`.
|
|
984
|
+
*/
|
|
985
|
+
analytics?: Omit<CoreConfig['analytics'], 'beaconHandler'>;
|
|
986
|
+
/**
|
|
987
|
+
* Overrides for the event builder configuration. Omits methods that are only
|
|
988
|
+
* useful in stateful environments.
|
|
989
|
+
*/
|
|
990
|
+
eventBuilder?: Omit<EventBuilderConfig, 'getLocale' | 'getPageProperties' | 'getUserAgent'>;
|
|
991
|
+
}
|
|
992
|
+
|
|
993
|
+
/**
|
|
994
|
+
* Combined observable state exposed by the stateful core.
|
|
995
|
+
*
|
|
996
|
+
* @public
|
|
997
|
+
* @see {@link AnalyticsStates}
|
|
998
|
+
* @see {@link PersonalizationStates}
|
|
999
|
+
*/
|
|
1000
|
+
export declare interface CoreStates extends AnalyticsStates, PersonalizationStates {
|
|
1001
|
+
/** Current consent value (if any). */
|
|
1002
|
+
consent: Observable<boolean | undefined>;
|
|
1003
|
+
/** Whether the preview panel has been attached to the host runtime. */
|
|
1004
|
+
previewPanelAttached: Observable<boolean>;
|
|
1005
|
+
/** Whether the preview panel is currently open in the host runtime. */
|
|
1006
|
+
previewPanelOpen: Observable<boolean>;
|
|
1007
|
+
/** Stream of the most recent blocked event payload. */
|
|
1008
|
+
blockedEventStream: Observable<BlockedEvent | undefined>;
|
|
1009
|
+
/** Stream of the most recent event emitted (analytics or personalization). */
|
|
1010
|
+
eventStream: Observable<InsightsEvent | ExperienceEvent | undefined>;
|
|
1011
|
+
}
|
|
1012
|
+
|
|
1013
|
+
/**
|
|
1014
|
+
* Storage key for the debug flag toggle.
|
|
1015
|
+
*
|
|
1016
|
+
* @internal
|
|
1017
|
+
*/
|
|
1018
|
+
export declare const DEBUG_FLAG_KEY = "__ctfl_opt_debug__";
|
|
1019
|
+
|
|
1020
|
+
export { effect }
|
|
1021
|
+
|
|
1022
|
+
declare const event_2: Signal<InsightsEvent | ExperienceEvent | undefined>;
|
|
1023
|
+
|
|
1024
|
+
/**
|
|
1025
|
+
* Union of all event {@link AnalyticsEventType | type keys} that this package may emit.
|
|
1026
|
+
*
|
|
1027
|
+
* @public
|
|
1028
|
+
*/
|
|
1029
|
+
declare type EventType = InsightsEventType | ExperienceEventType;
|
|
1030
|
+
|
|
1031
|
+
declare const flags: ReadonlySignal<Flags | undefined>;
|
|
1032
|
+
|
|
1033
|
+
/**
|
|
1034
|
+
* Resolves a {@link Flags} map from a list of optimization changes.
|
|
1035
|
+
*
|
|
1036
|
+
* @public
|
|
1037
|
+
* @remarks
|
|
1038
|
+
* Given an Optimization {@link ChangeArray}, this utility flattens the list into a
|
|
1039
|
+
* simple key–value object suitable for quick lookups in client code. When `changes`
|
|
1040
|
+
* is `undefined`, an empty object is returned. If a change value is wrapped in an
|
|
1041
|
+
* object like `{ value: { ... } }`, this resolver unwraps it to the underlying object.
|
|
1042
|
+
*/
|
|
1043
|
+
export declare const FlagsResolver: {
|
|
1044
|
+
/**
|
|
1045
|
+
* Build a flattened map of flag keys to values from a change list.
|
|
1046
|
+
*
|
|
1047
|
+
* @param changes - The change list returned by the optimization service.
|
|
1048
|
+
* @returns A map of flag keys to their resolved values.
|
|
1049
|
+
* @example
|
|
1050
|
+
* ```ts
|
|
1051
|
+
* const flags = FlagsResolver.resolve(data.changes)
|
|
1052
|
+
* if (flags['theme'] === 'dark') enableDarkMode()
|
|
1053
|
+
* ```
|
|
1054
|
+
* @example
|
|
1055
|
+
* // Handles wrapped values produced by the API
|
|
1056
|
+
* ```ts
|
|
1057
|
+
* const flags = FlagsResolver.resolve([
|
|
1058
|
+
* { type: 'Variable', key: 'price', value: { value: { amount: 10, currency: 'USD' } } }
|
|
1059
|
+
* ])
|
|
1060
|
+
* console.log(flags.price.amount) // 10
|
|
1061
|
+
* ```
|
|
1062
|
+
*/
|
|
1063
|
+
resolve(changes?: ChangeArray): Flags;
|
|
1064
|
+
};
|
|
1065
|
+
|
|
1066
|
+
/**
|
|
1067
|
+
* Decorator factory that **guards** class methods behind a synchronous predicate.
|
|
1068
|
+
*
|
|
1069
|
+
* When a decorated method is invoked:
|
|
1070
|
+
* - If the predicate returns a value that evaluates to **allowed** (see `invert`), the original
|
|
1071
|
+
* method is executed and its result is returned.
|
|
1072
|
+
* - If the call is **blocked**, the optional `onBlocked` hook is invoked (if configured) and:
|
|
1073
|
+
* - `undefined` is returned for sync methods; or
|
|
1074
|
+
* - `Promise<undefined>` is returned for async methods (to preserve `await` compatibility).
|
|
1075
|
+
*
|
|
1076
|
+
* @typeParam T - The instance type that owns both the predicate and the decorated method.
|
|
1077
|
+
*
|
|
1078
|
+
* @param predicateName - The name (string or symbol) of a **synchronous** instance method on `this`
|
|
1079
|
+
* that acts as the predicate. It is called as `this[predicateName](methodName, argsArray)`.
|
|
1080
|
+
* @param opts - Optional {@link GuardedByOptions | options} to configure inversion and `onBlocked`.
|
|
1081
|
+
*
|
|
1082
|
+
* @returns A methods-only class decorator compatible with Stage-3 decorators that wraps the method.
|
|
1083
|
+
*
|
|
1084
|
+
* @throws TypeError
|
|
1085
|
+
* Thrown at initialization time (first instance construction) if `predicateName` does not resolve
|
|
1086
|
+
* to a **synchronous function** on the instance.
|
|
1087
|
+
*
|
|
1088
|
+
* @remarks
|
|
1089
|
+
* - This is a **methods-only** decorator; applying it to accessors/fields is a no-op.
|
|
1090
|
+
* - The decorator preserves the original method's sync/async shape.
|
|
1091
|
+
* - The predicate is invoked with `(decoratedMethodName, argsArray)` to support context-aware checks.
|
|
1092
|
+
*
|
|
1093
|
+
* @example
|
|
1094
|
+
* Here, `canRun` allows the call when it returns truthy:
|
|
1095
|
+
* ```ts
|
|
1096
|
+
* class Runner {
|
|
1097
|
+
* canRun(method: string, _args: readonly unknown[]) { return method !== 'stop'; }
|
|
1098
|
+
*
|
|
1099
|
+
* @guardedBy<Runner>('canRun')
|
|
1100
|
+
* go() { console.log('running'); }
|
|
1101
|
+
* }
|
|
1102
|
+
* ```
|
|
1103
|
+
*
|
|
1104
|
+
* @example
|
|
1105
|
+
* Invert the predicate and call a handler on block:
|
|
1106
|
+
* ```ts
|
|
1107
|
+
* class Door {
|
|
1108
|
+
* isLocked() { return true } // truthy means "locked"
|
|
1109
|
+
* onBlocked(method: string) { console.warn(`${method} blocked`) }
|
|
1110
|
+
*
|
|
1111
|
+
* @guardedBy<Door>('isLocked', { invert: true, onBlocked: 'onBlocked' })
|
|
1112
|
+
* open() { /* ... *\/ }
|
|
1113
|
+
* }
|
|
1114
|
+
* ```
|
|
1115
|
+
*
|
|
1116
|
+
* @public
|
|
1117
|
+
*/
|
|
1118
|
+
export declare function guardedBy<T extends object>(predicateName: keyof T & (string | symbol), opts?: GuardedByOptions<T>): GuardedByFunction<T>;
|
|
1119
|
+
|
|
1120
|
+
/**
|
|
1121
|
+
* The original method implementation.
|
|
1122
|
+
*
|
|
1123
|
+
* @typeParam A - The parameter tuple of the original method.
|
|
1124
|
+
* @typeParam R - The return type of the original method.
|
|
1125
|
+
* @param value - The method being decorated.
|
|
1126
|
+
* @param context - The Stage-3 decorator context for a class method.
|
|
1127
|
+
* @returns Nothing.
|
|
1128
|
+
*
|
|
1129
|
+
* @remarks
|
|
1130
|
+
* Users do not call this directly; it's returned by {@link guardedBy}.
|
|
1131
|
+
*
|
|
1132
|
+
* @internal
|
|
1133
|
+
*/
|
|
1134
|
+
declare type GuardedByFunction<T extends object> = <A extends readonly unknown[], R>(value: (...args: A) => R, context: ClassMethodDecoratorContext<T, (...args: A) => R>) => void;
|
|
1135
|
+
|
|
1136
|
+
/**
|
|
1137
|
+
* Options that tweak the behavior of {@link guardedBy}.
|
|
1138
|
+
*
|
|
1139
|
+
* @typeParam T - The instance type on which the decorator is applied.
|
|
1140
|
+
*
|
|
1141
|
+
* @public
|
|
1142
|
+
*/
|
|
1143
|
+
declare interface GuardedByOptions<T extends object> {
|
|
1144
|
+
/**
|
|
1145
|
+
* Inverts the predicate result.
|
|
1146
|
+
*
|
|
1147
|
+
* When `true`, a truthy predicate result **blocks** the method.
|
|
1148
|
+
* When `false` (default) or omitted, a truthy predicate result **allows** the method.
|
|
1149
|
+
*
|
|
1150
|
+
* @defaultValue `false`
|
|
1151
|
+
* @remarks
|
|
1152
|
+
* This option is useful when the predicate expresses a *forbid* condition
|
|
1153
|
+
* (e.g. "isLocked" or "isDestroyed") rather than an *allow* condition.
|
|
1154
|
+
*/
|
|
1155
|
+
readonly invert?: boolean;
|
|
1156
|
+
/**
|
|
1157
|
+
* Either a function to call when a method is blocked, or the name/symbol of
|
|
1158
|
+
* an instance method on `this` to call when blocked.
|
|
1159
|
+
*
|
|
1160
|
+
* Both forms are **synchronous** and receive `(methodName, argsArray)`.
|
|
1161
|
+
* If omitted, blocked calls fail silently (i.e., return `undefined` or
|
|
1162
|
+
* `Promise<undefined>` for async methods).
|
|
1163
|
+
*
|
|
1164
|
+
* @remarks
|
|
1165
|
+
* - If a property key is supplied and the instance does not have a callable at that key,
|
|
1166
|
+
* the hook is ignored.
|
|
1167
|
+
* - The hook **must not** be `async`; any async work should be scheduled manually.
|
|
1168
|
+
*/
|
|
1169
|
+
readonly onBlocked?: BlockHandler | (keyof T & (string | symbol));
|
|
1170
|
+
}
|
|
1171
|
+
|
|
1172
|
+
/**
|
|
1173
|
+
* A function that receives a value of type `T` and returns a (possibly async)
|
|
1174
|
+
* value of the same type `T`. The input is marked as `readonly` to discourage
|
|
1175
|
+
* mutation of the original object.
|
|
1176
|
+
*
|
|
1177
|
+
* @typeParam T - The value type intercepted and returned.
|
|
1178
|
+
* @param value - The current (readonly) value in the interception chain.
|
|
1179
|
+
* @returns The next value for the chain, either directly or via a promise.
|
|
1180
|
+
* @remarks Implementations SHOULD avoid mutating `value` and instead return a
|
|
1181
|
+
* new or safely-updated instance.
|
|
1182
|
+
* @see {@link InterceptorManager}
|
|
1183
|
+
* @public
|
|
1184
|
+
*/
|
|
1185
|
+
export declare type Interceptor<T> = (value: Readonly<T>) => MaybePromise<T>;
|
|
1186
|
+
|
|
1187
|
+
/**
|
|
1188
|
+
* Manages a list of interceptors and provides a way to run them in sequence.
|
|
1189
|
+
*
|
|
1190
|
+
* Interceptors are executed in insertion order. Each interceptor receives the
|
|
1191
|
+
* result of the previous interceptor (or the initial input for the first one)
|
|
1192
|
+
* and may return a new value synchronously or asynchronously.
|
|
1193
|
+
*
|
|
1194
|
+
* @typeParam T - The value type processed by the interceptors.
|
|
1195
|
+
* @remarks This class snapshots the current interceptor list at invocation time
|
|
1196
|
+
* so additions/removals during `run` do not affect the in-flight execution.
|
|
1197
|
+
* @example
|
|
1198
|
+
* ```ts
|
|
1199
|
+
* const mgr = new InterceptorManager<number>();
|
|
1200
|
+
* const id = mgr.add((n) => n + 1);
|
|
1201
|
+
* const final = await mgr.run(1); // 2
|
|
1202
|
+
* mgr.remove(id);
|
|
1203
|
+
* ```
|
|
1204
|
+
* @public
|
|
1205
|
+
*/
|
|
1206
|
+
export declare class InterceptorManager<T> {
|
|
1207
|
+
/**
|
|
1208
|
+
* The registry of interceptors keyed by their insertion id.
|
|
1209
|
+
*
|
|
1210
|
+
* @privateRemarks Internal storage; use {@link add}, {@link remove}, and
|
|
1211
|
+
* {@link clear} to manage contents.
|
|
1212
|
+
* @readonly
|
|
1213
|
+
* @defaultValue `new Map()`
|
|
1214
|
+
*/
|
|
1215
|
+
private readonly interceptors;
|
|
1216
|
+
/**
|
|
1217
|
+
* The next numeric id to assign to an added interceptor.
|
|
1218
|
+
*
|
|
1219
|
+
* @privateRemarks Used only to generate unique, monotonically increasing ids.
|
|
1220
|
+
* @defaultValue `0`
|
|
1221
|
+
*/
|
|
1222
|
+
private nextId;
|
|
1223
|
+
/**
|
|
1224
|
+
* Add an interceptor and return its identifier.
|
|
1225
|
+
*
|
|
1226
|
+
* @param interceptor - The interceptor function to register.
|
|
1227
|
+
* @returns The numeric id that can later be used with {@link remove}.
|
|
1228
|
+
* @remarks Interceptors are executed in the order they are added.
|
|
1229
|
+
* @example
|
|
1230
|
+
* ```ts
|
|
1231
|
+
* const id = manager.add(async (value) => transform(value));
|
|
1232
|
+
* ```
|
|
1233
|
+
* @public
|
|
1234
|
+
*/
|
|
1235
|
+
add(interceptor: Interceptor<T>): number;
|
|
1236
|
+
/**
|
|
1237
|
+
* Remove an interceptor by its identifier.
|
|
1238
|
+
*
|
|
1239
|
+
* @param id - The id previously returned by {@link add}.
|
|
1240
|
+
* @returns `true` if an interceptor was removed; otherwise `false`.
|
|
1241
|
+
* @example
|
|
1242
|
+
* ```ts
|
|
1243
|
+
* const removed = manager.remove(id);
|
|
1244
|
+
* ```
|
|
1245
|
+
* @public
|
|
1246
|
+
*/
|
|
1247
|
+
remove(id: number): boolean;
|
|
1248
|
+
/**
|
|
1249
|
+
* Remove all registered interceptors.
|
|
1250
|
+
*
|
|
1251
|
+
* @returns Nothing.
|
|
1252
|
+
* @remarks After calling this, {@link count} will return `0`.
|
|
1253
|
+
* @example
|
|
1254
|
+
* ```ts
|
|
1255
|
+
* manager.clear();
|
|
1256
|
+
* ```
|
|
1257
|
+
* @public
|
|
1258
|
+
*/
|
|
1259
|
+
clear(): void;
|
|
1260
|
+
/**
|
|
1261
|
+
* Get the number of currently registered interceptors.
|
|
1262
|
+
*
|
|
1263
|
+
* @returns The count of interceptors.
|
|
1264
|
+
* @example
|
|
1265
|
+
* ```ts
|
|
1266
|
+
* if (manager.count() === 0) { /* ... *\/ }
|
|
1267
|
+
* ```
|
|
1268
|
+
* @public
|
|
1269
|
+
*/
|
|
1270
|
+
count(): number;
|
|
1271
|
+
/**
|
|
1272
|
+
* Run all interceptors in sequence on an input value and return the final result.
|
|
1273
|
+
*
|
|
1274
|
+
* Supports both sync and async interceptors; the return type is always `Promise<T>`
|
|
1275
|
+
* for consistency.
|
|
1276
|
+
*
|
|
1277
|
+
* @param input - The initial value to pass to the first interceptor.
|
|
1278
|
+
* @returns A promise resolving to the final value after all interceptors have run.
|
|
1279
|
+
* @throws May rethrow any error thrown by an interceptor. <!-- Intentionally vague: error type depends on interceptor implementation -->
|
|
1280
|
+
* @remarks The interceptor list is snapshotted at invocation time; changes to
|
|
1281
|
+
* the registry during execution do not affect the running sequence.
|
|
1282
|
+
* @example
|
|
1283
|
+
* ```ts
|
|
1284
|
+
* const result = await manager.run(initial);
|
|
1285
|
+
* ```
|
|
1286
|
+
* @public
|
|
1287
|
+
*/
|
|
1288
|
+
run(input: T): Promise<T>;
|
|
1289
|
+
}
|
|
1290
|
+
|
|
1291
|
+
/**
|
|
1292
|
+
* Lifecycle container for event and state interceptors.
|
|
1293
|
+
*
|
|
1294
|
+
* @public
|
|
1295
|
+
*/
|
|
1296
|
+
export declare interface LifecycleInterceptors {
|
|
1297
|
+
/** Interceptors invoked for individual events prior to validation/sending. */
|
|
1298
|
+
event: InterceptorManager<InsightsEvent | ExperienceEvent>;
|
|
1299
|
+
/** Interceptors invoked before optimization state updates. */
|
|
1300
|
+
state: InterceptorManager<OptimizationData>;
|
|
1301
|
+
}
|
|
1302
|
+
|
|
1303
|
+
/**
|
|
1304
|
+
* A utility type representing a value that may be synchronously available or
|
|
1305
|
+
* produced asynchronously.
|
|
1306
|
+
*
|
|
1307
|
+
* @typeParam T - The resolved value type.
|
|
1308
|
+
* @public
|
|
1309
|
+
*/
|
|
1310
|
+
declare type MaybePromise<T> = T | Promise<T>;
|
|
1311
|
+
|
|
1312
|
+
/**
|
|
1313
|
+
* Resolves merge tag values from a {@link Profile}.
|
|
1314
|
+
*
|
|
1315
|
+
* @public
|
|
1316
|
+
* @remarks
|
|
1317
|
+
* *Merge tags* are references to user profile data that may be embedded in content
|
|
1318
|
+
* and expanded at runtime. This resolver normalizes the merge-tag identifier into
|
|
1319
|
+
* a set of candidate selectors and searches the profile for a matching value.
|
|
1320
|
+
* Result values are returned as strings; numeric/boolean primitives are stringified.
|
|
1321
|
+
*/
|
|
1322
|
+
export declare const MergeTagValueResolver: {
|
|
1323
|
+
/**
|
|
1324
|
+
* Generate a list of candidate selectors for a merge-tag ID.
|
|
1325
|
+
*
|
|
1326
|
+
* @param id - Merge-tag identifier (segments separated by `_`).
|
|
1327
|
+
* @returns Array of dot-path selectors to try against a profile.
|
|
1328
|
+
* @example
|
|
1329
|
+
* ```ts
|
|
1330
|
+
* // "profile_name_first" -> [
|
|
1331
|
+
* // 'profile',
|
|
1332
|
+
* // 'profile.name',
|
|
1333
|
+
* // 'profile.name.first'
|
|
1334
|
+
* // ]
|
|
1335
|
+
* const selectors = MergeTagValueResolver.normalizeSelectors('profile_name_first')
|
|
1336
|
+
* ```
|
|
1337
|
+
*/
|
|
1338
|
+
normalizeSelectors(id: string): string[];
|
|
1339
|
+
/**
|
|
1340
|
+
* Look up a merge-tag value from a profile using normalized selectors.
|
|
1341
|
+
*
|
|
1342
|
+
* @param id - Merge-tag identifier.
|
|
1343
|
+
* @param profile - Profile from which to resolve the value.
|
|
1344
|
+
* @returns A stringified primitive if found; otherwise `undefined`.
|
|
1345
|
+
* @remarks
|
|
1346
|
+
* Only string/number/boolean primitives are returned; objects/arrays are ignored.
|
|
1347
|
+
* @example
|
|
1348
|
+
* ```ts
|
|
1349
|
+
* const value = MergeTagValueResolver.getValueFromProfile('user_email', profile)
|
|
1350
|
+
* if (value) sendEmailTo(value)
|
|
1351
|
+
* ```
|
|
1352
|
+
*/
|
|
1353
|
+
getValueFromProfile(id: string, profile?: Profile): string | undefined;
|
|
1354
|
+
/**
|
|
1355
|
+
* Resolve the display value for a merge-tag entry using the provided profile,
|
|
1356
|
+
* falling back to the entry's configured `nt_fallback` when necessary.
|
|
1357
|
+
*
|
|
1358
|
+
* @param mergeTagEntry - The merge-tag entry to resolve.
|
|
1359
|
+
* @param profile - Optional profile used for lookup.
|
|
1360
|
+
* @returns The resolved string, or `undefined` if the entry is invalid and no
|
|
1361
|
+
* fallback is available.
|
|
1362
|
+
* @example
|
|
1363
|
+
* ```ts
|
|
1364
|
+
* const text = MergeTagValueResolver.resolve(entry, profile)
|
|
1365
|
+
* render(text ?? 'Guest')
|
|
1366
|
+
* ```
|
|
1367
|
+
*/
|
|
1368
|
+
resolve(mergeTagEntry: MergeTagEntry | undefined, profile?: Profile): string | undefined;
|
|
1369
|
+
};
|
|
1370
|
+
|
|
1371
|
+
declare interface Observable<T> {
|
|
1372
|
+
subscribe: (next: (v: T) => void) => Subscription;
|
|
1373
|
+
}
|
|
1374
|
+
|
|
1375
|
+
declare const online: Signal<boolean | undefined>;
|
|
1376
|
+
|
|
1377
|
+
/**
|
|
1378
|
+
* The package name of the Optimization Core SDK, injected at build time.
|
|
1379
|
+
*
|
|
1380
|
+
* @public
|
|
1381
|
+
*/
|
|
1382
|
+
export declare const OPTIMIZATION_CORE_SDK_NAME: string;
|
|
1383
|
+
|
|
1384
|
+
/**
|
|
1385
|
+
* The current version of the Optimization Core SDK, injected at build time.
|
|
1386
|
+
*
|
|
1387
|
+
* @public
|
|
1388
|
+
*/
|
|
1389
|
+
export declare const OPTIMIZATION_CORE_SDK_VERSION: string;
|
|
1390
|
+
|
|
1391
|
+
/**
|
|
1392
|
+
* Internal base for personalization products.
|
|
1393
|
+
*
|
|
1394
|
+
* @internal
|
|
1395
|
+
* @remarks
|
|
1396
|
+
* Concrete implementations should extend this class to expose public methods for
|
|
1397
|
+
* identify, page, and track events. This base wires in shared singleton
|
|
1398
|
+
* resolvers used to fetch/resolve personalized data.
|
|
1399
|
+
*/
|
|
1400
|
+
export declare abstract class PersonalizationBase extends ProductBase implements ResolverMethods {
|
|
1401
|
+
/**
|
|
1402
|
+
* Static {@link FlagsResolver | resolver} for evaluating personalized
|
|
1403
|
+
* custom flags.
|
|
1404
|
+
*/
|
|
1405
|
+
readonly flagsResolver: {
|
|
1406
|
+
resolve(changes?: ChangeArray): Flags;
|
|
1407
|
+
};
|
|
1408
|
+
/**
|
|
1409
|
+
* Static {@link MergeTagValueResolver | resolver} that returns values
|
|
1410
|
+
* sourced from a user profile based on a Contentful Merge Tag entry.
|
|
1411
|
+
*/
|
|
1412
|
+
readonly mergeTagValueResolver: {
|
|
1413
|
+
normalizeSelectors(id: string): string[];
|
|
1414
|
+
getValueFromProfile(id: string, profile?: Profile): string | undefined;
|
|
1415
|
+
resolve(mergeTagEntry: MergeTagEntry | undefined, profile?: Profile): string | undefined;
|
|
1416
|
+
};
|
|
1417
|
+
/**
|
|
1418
|
+
* Static {@link PersonalizedEntryResolver | resolver } for personalized
|
|
1419
|
+
* Contentful entries (e.g., entry variants targeted to a profile audience).
|
|
1420
|
+
*
|
|
1421
|
+
* @remarks
|
|
1422
|
+
* Used by higher-level personalization flows to materialize entry content
|
|
1423
|
+
* prior to event emission.
|
|
1424
|
+
*/
|
|
1425
|
+
readonly personalizedEntryResolver: {
|
|
1426
|
+
getPersonalizationEntry({ personalizedEntry, selectedPersonalizations, }: {
|
|
1427
|
+
personalizedEntry: PersonalizedEntry;
|
|
1428
|
+
selectedPersonalizations: SelectedPersonalizationArray;
|
|
1429
|
+
}, skipValidation?: boolean): PersonalizationEntry | undefined;
|
|
1430
|
+
getSelectedPersonalization({ personalizationEntry, selectedPersonalizations, }: {
|
|
1431
|
+
personalizationEntry: PersonalizationEntry;
|
|
1432
|
+
selectedPersonalizations: SelectedPersonalizationArray;
|
|
1433
|
+
}, skipValidation?: boolean): SelectedPersonalization_2 | undefined;
|
|
1434
|
+
getSelectedVariant({ personalizedEntry, personalizationEntry, selectedVariantIndex, }: {
|
|
1435
|
+
personalizedEntry: PersonalizedEntry;
|
|
1436
|
+
personalizationEntry: PersonalizationEntry;
|
|
1437
|
+
selectedVariantIndex: number;
|
|
1438
|
+
}, skipValidation?: boolean): EntryReplacementVariant | undefined;
|
|
1439
|
+
getSelectedVariantEntry<S extends EntrySkeletonType, M extends ChainModifiers = ChainModifiers, L extends LocaleCode = string>({ personalizationEntry, selectedVariant, }: {
|
|
1440
|
+
personalizationEntry: PersonalizationEntry;
|
|
1441
|
+
selectedVariant: EntryReplacementVariant;
|
|
1442
|
+
}, skipValidation?: boolean): Entry<S, M, L> | undefined;
|
|
1443
|
+
resolve<S extends EntrySkeletonType, M extends ChainModifiers = ChainModifiers, L extends LocaleCode = string>(entry: Entry<S, M, L>, selectedPersonalizations?: SelectedPersonalizationArray): ResolvedData<S, M, L>;
|
|
1444
|
+
};
|
|
1445
|
+
/**
|
|
1446
|
+
* Get the specified Custom Flag's value from the supplied changes.
|
|
1447
|
+
* @param name - The name/key of the Custom Flag.
|
|
1448
|
+
* @param changes - Optional changes array.
|
|
1449
|
+
* @returns The current value of the Custom Flag if found.
|
|
1450
|
+
* @remarks
|
|
1451
|
+
* The changes array can be sourced from the data returned when emitting any
|
|
1452
|
+
* personalization event.
|
|
1453
|
+
* */
|
|
1454
|
+
getCustomFlag(name: string, changes?: ChangeArray): Json;
|
|
1455
|
+
/**
|
|
1456
|
+
* Get all resolved Custom Flags from the supplied changes.
|
|
1457
|
+
* @param changes - Optional changes array.
|
|
1458
|
+
* @returns The resolved Custom Flag map.
|
|
1459
|
+
* @remarks
|
|
1460
|
+
* The changes array can be sourced from the data returned when emitting any
|
|
1461
|
+
* personalization event.
|
|
1462
|
+
* */
|
|
1463
|
+
getCustomFlags(changes?: ChangeArray): Flags;
|
|
1464
|
+
/**
|
|
1465
|
+
* Resolve a Contentful entry to a personalized variant using the current
|
|
1466
|
+
* or provided selected personalizations.
|
|
1467
|
+
*
|
|
1468
|
+
* @typeParam S - Entry skeleton type.
|
|
1469
|
+
* @typeParam M - Chain modifiers.
|
|
1470
|
+
* @typeParam L - Locale code.
|
|
1471
|
+
* @param entry - The entry to personalize.
|
|
1472
|
+
* @param personalizations - Optional selected personalizations.
|
|
1473
|
+
* @returns The resolved entry data.
|
|
1474
|
+
* @remarks
|
|
1475
|
+
* Selected personalizations can be sourced from the data returned when emitting any
|
|
1476
|
+
* personalization event.
|
|
1477
|
+
*/
|
|
1478
|
+
personalizeEntry<S extends EntrySkeletonType, M extends ChainModifiers = ChainModifiers, L extends LocaleCode = LocaleCode>(entry: Entry<S, M, L>, personalizations?: SelectedPersonalizationArray): ResolvedData<S, M, L>;
|
|
1479
|
+
/**
|
|
1480
|
+
* Resolve a merge tag to a value based on the current (or provided) profile.
|
|
1481
|
+
*
|
|
1482
|
+
* @param embeddedEntryNodeTarget - The merge tag entry node to resolve.
|
|
1483
|
+
* @param profile - Optional profile.
|
|
1484
|
+
* @returns The resolved value (type depends on the tag).
|
|
1485
|
+
* @remarks
|
|
1486
|
+
* Merge tags are references to profile data that can be substituted into content. The
|
|
1487
|
+
* profile can be sourced from the data returned when emitting any personalization event.
|
|
1488
|
+
*/
|
|
1489
|
+
getMergeTagValue(embeddedEntryNodeTarget: MergeTagEntry, profile?: Profile): string | undefined;
|
|
1490
|
+
/**
|
|
1491
|
+
* Identify the current profile/visitor to associate traits with a profile.
|
|
1492
|
+
*
|
|
1493
|
+
* @param payload - Identify builder payload.
|
|
1494
|
+
* @returns The resulting {@link OptimizationData} for the identified user if the device is online.
|
|
1495
|
+
*/
|
|
1496
|
+
abstract identify(payload: IdentifyBuilderArgs): Promise<OptimizationData | undefined>;
|
|
1497
|
+
/**
|
|
1498
|
+
* Record a page view.
|
|
1499
|
+
*
|
|
1500
|
+
* @param payload - Page view builder payload.
|
|
1501
|
+
* @returns The evaluated {@link OptimizationData} for this page view if the device is online.
|
|
1502
|
+
*/
|
|
1503
|
+
abstract page(payload: PageViewBuilderArgs): Promise<OptimizationData | undefined>;
|
|
1504
|
+
/**
|
|
1505
|
+
* Record a screen view.
|
|
1506
|
+
*
|
|
1507
|
+
* @param payload - Screen view builder payload.
|
|
1508
|
+
* @returns The evaluated {@link OptimizationData} for this screen view if the device is online.
|
|
1509
|
+
*/
|
|
1510
|
+
abstract screen(payload: ScreenViewBuilderArgs): Promise<OptimizationData | undefined>;
|
|
1511
|
+
/**
|
|
1512
|
+
* Record a custom track event.
|
|
1513
|
+
*
|
|
1514
|
+
* @param payload - Track builder payload.
|
|
1515
|
+
* @returns The evaluated {@link OptimizationData} for this event if the device is online.
|
|
1516
|
+
*/
|
|
1517
|
+
abstract track(payload: TrackBuilderArgs): Promise<OptimizationData | undefined>;
|
|
1518
|
+
/**
|
|
1519
|
+
* Record a "sticky" component view.
|
|
1520
|
+
*
|
|
1521
|
+
* @param payload - "Sticky" component view builder payload.
|
|
1522
|
+
* @returns The evaluated {@link OptimizationData} for this component view if the device is online.
|
|
1523
|
+
* @remarks
|
|
1524
|
+
* This method is intended to be called only when a component is considered
|
|
1525
|
+
* "sticky".
|
|
1526
|
+
*/
|
|
1527
|
+
abstract trackComponentView(payload: ComponentViewBuilderArgs): Promise<OptimizationData | undefined>;
|
|
1528
|
+
}
|
|
1529
|
+
|
|
1530
|
+
/**
|
|
1531
|
+
* Context payload emitted when offline personalization events are dropped due to queue bounds.
|
|
1532
|
+
*
|
|
1533
|
+
* @public
|
|
1534
|
+
*/
|
|
1535
|
+
export declare interface PersonalizationOfflineQueueDropContext {
|
|
1536
|
+
/** Number of dropped events. */
|
|
1537
|
+
droppedCount: number;
|
|
1538
|
+
/** Dropped events in oldest-first order. */
|
|
1539
|
+
droppedEvents: ExperienceEventArray;
|
|
1540
|
+
/** Configured queue max size. */
|
|
1541
|
+
maxEvents: number;
|
|
1542
|
+
/** Queue size after enqueueing the current event. */
|
|
1543
|
+
queuedEvents: number;
|
|
1544
|
+
}
|
|
1545
|
+
|
|
1546
|
+
/**
|
|
1547
|
+
* Configuration for {@link PersonalizationStateful}.
|
|
1548
|
+
*
|
|
1549
|
+
* @public
|
|
1550
|
+
*/
|
|
1551
|
+
export declare interface PersonalizationProductConfig extends ProductConfig {
|
|
1552
|
+
/** Default signal values applied during initialization. */
|
|
1553
|
+
defaults?: PersonalizationProductConfigDefaults;
|
|
1554
|
+
/**
|
|
1555
|
+
* Policy that controls the offline personalization queue size and drop telemetry.
|
|
1556
|
+
*/
|
|
1557
|
+
queuePolicy?: PersonalizationQueuePolicy;
|
|
1558
|
+
/**
|
|
1559
|
+
* Function used to obtain an anonymous user identifier.
|
|
1560
|
+
*
|
|
1561
|
+
* @remarks
|
|
1562
|
+
* If a `getAnonymousId` function has been provided, the returned value will
|
|
1563
|
+
* take precedence over the `id` property of the current {@link Profile}
|
|
1564
|
+
* signal value
|
|
1565
|
+
*
|
|
1566
|
+
* @returns A string identifier, or `undefined` if no anonymous ID is available.
|
|
1567
|
+
*/
|
|
1568
|
+
getAnonymousId?: () => string | undefined;
|
|
1569
|
+
}
|
|
1570
|
+
|
|
1571
|
+
/**
|
|
1572
|
+
* Default state values for {@link PersonalizationStateful} applied at construction time.
|
|
1573
|
+
*
|
|
1574
|
+
* @public
|
|
1575
|
+
*/
|
|
1576
|
+
export declare interface PersonalizationProductConfigDefaults {
|
|
1577
|
+
/** Whether personalization is allowed by default. */
|
|
1578
|
+
consent?: boolean;
|
|
1579
|
+
/** Initial diff of changes produced by the service. */
|
|
1580
|
+
changes?: ChangeArray;
|
|
1581
|
+
/** Default active profile used for personalization. */
|
|
1582
|
+
profile?: Profile;
|
|
1583
|
+
/** Preselected personalization variants (e.g., winning treatments). */
|
|
1584
|
+
personalizations?: SelectedPersonalizationArray;
|
|
1585
|
+
}
|
|
1586
|
+
|
|
1587
|
+
/**
|
|
1588
|
+
* Policy options for the stateful personalization offline queue.
|
|
1589
|
+
*
|
|
1590
|
+
* @public
|
|
1591
|
+
*/
|
|
1592
|
+
export declare interface PersonalizationQueuePolicy {
|
|
1593
|
+
/**
|
|
1594
|
+
* Maximum number of personalization events retained while offline.
|
|
1595
|
+
*/
|
|
1596
|
+
maxEvents?: number;
|
|
1597
|
+
/**
|
|
1598
|
+
* Callback invoked whenever oldest events are dropped due to queue bounds.
|
|
1599
|
+
*/
|
|
1600
|
+
onDrop?: (context: PersonalizationOfflineQueueDropContext) => void;
|
|
1601
|
+
/**
|
|
1602
|
+
* Policy that controls offline queue flush retries, backoff, and circuit
|
|
1603
|
+
* behavior after repeated failures.
|
|
1604
|
+
*/
|
|
1605
|
+
flushPolicy?: QueueFlushPolicy;
|
|
1606
|
+
}
|
|
1607
|
+
|
|
1608
|
+
declare const personalizations: Signal<{
|
|
1609
|
+
experienceId: string;
|
|
1610
|
+
variantIndex: number;
|
|
1611
|
+
variants: Record<string, string>;
|
|
1612
|
+
sticky?: boolean | undefined;
|
|
1613
|
+
}[] | undefined>;
|
|
1614
|
+
|
|
1615
|
+
/**
|
|
1616
|
+
* Storage key for cached selected personalizations.
|
|
1617
|
+
*
|
|
1618
|
+
* @internal
|
|
1619
|
+
*/
|
|
1620
|
+
export declare const PERSONALIZATIONS_CACHE_KEY = "__ctfl_opt_personalizations__";
|
|
1621
|
+
|
|
1622
|
+
/**
|
|
1623
|
+
* Stateful personalization product that manages consent, profile, flags, and
|
|
1624
|
+
* selected variants while emitting Experience events and updating state.
|
|
1625
|
+
*
|
|
1626
|
+
* @public
|
|
1627
|
+
* @remarks
|
|
1628
|
+
* The class maintains reactive signals and exposes read‑only observables via
|
|
1629
|
+
* {@link PersonalizationStateful.states}. Events are validated via schema parsers and
|
|
1630
|
+
* run through interceptors before being submitted. Resulting state is merged
|
|
1631
|
+
* back into signals.
|
|
1632
|
+
*/
|
|
1633
|
+
export declare class PersonalizationStateful extends PersonalizationBase implements ConsentGuard {
|
|
1634
|
+
/** In-memory ordered queue for offline personalization events. */
|
|
1635
|
+
private readonly offlineQueue;
|
|
1636
|
+
/** Resolved offline queue policy values. */
|
|
1637
|
+
private readonly queuePolicy;
|
|
1638
|
+
/** Shared queue flush retry runtime state machine. */
|
|
1639
|
+
private readonly flushRuntime;
|
|
1640
|
+
/** Exposed observable state references. */
|
|
1641
|
+
readonly states: PersonalizationStates;
|
|
1642
|
+
/**
|
|
1643
|
+
* Function that provides an anonymous ID when available.
|
|
1644
|
+
*
|
|
1645
|
+
* @internal
|
|
1646
|
+
*/
|
|
1647
|
+
getAnonymousId: () => string | undefined;
|
|
1648
|
+
/**
|
|
1649
|
+
* Create a new stateful personalization instance.
|
|
1650
|
+
*
|
|
1651
|
+
* @param options - Options to configure the personalization product for stateful environments.
|
|
1652
|
+
* @example
|
|
1653
|
+
* ```ts
|
|
1654
|
+
* const personalization = new PersonalizationStateful({ api, builder, config: { getAnonymousId }, interceptors })
|
|
1655
|
+
* ```
|
|
1656
|
+
*/
|
|
1657
|
+
constructor(options: PersonalizationStatefulOptions);
|
|
1658
|
+
/**
|
|
1659
|
+
* Reset stateful signals managed by this product.
|
|
1660
|
+
*
|
|
1661
|
+
* @remarks
|
|
1662
|
+
* Clears `changes`, `profile`, and selected `personalizations`.
|
|
1663
|
+
* @example
|
|
1664
|
+
* ```ts
|
|
1665
|
+
* personalization.reset()
|
|
1666
|
+
* ```
|
|
1667
|
+
*/
|
|
1668
|
+
reset(): void;
|
|
1669
|
+
/**
|
|
1670
|
+
* Get the specified Custom Flag's value (derived from the signal).
|
|
1671
|
+
* @param name - The name or key of the Custom Flag.
|
|
1672
|
+
* @returns The current value of the Custom Flag if found.
|
|
1673
|
+
* @example
|
|
1674
|
+
* ```ts
|
|
1675
|
+
* const flagValue = personalization.getCustomFlag('dark-mode')
|
|
1676
|
+
* ```
|
|
1677
|
+
* */
|
|
1678
|
+
getCustomFlag(name: string, changes?: ChangeArray | undefined): Json;
|
|
1679
|
+
/**
|
|
1680
|
+
* Get all resolved Custom Flags (derived from the signal).
|
|
1681
|
+
* @param changes - Optional changes array; defaults to the current signal value.
|
|
1682
|
+
* @returns The resolved Custom Flag map.
|
|
1683
|
+
* @example
|
|
1684
|
+
* ```ts
|
|
1685
|
+
* const flags = personalization.getCustomFlags()
|
|
1686
|
+
* ```
|
|
1687
|
+
*/
|
|
1688
|
+
getCustomFlags(changes?: ChangeArray | undefined): Flags;
|
|
1689
|
+
/**
|
|
1690
|
+
* Resolve a Contentful entry to a personalized variant using the current
|
|
1691
|
+
* or provided selections.
|
|
1692
|
+
*
|
|
1693
|
+
* @typeParam S - Entry skeleton type.
|
|
1694
|
+
* @typeParam M - Chain modifiers.
|
|
1695
|
+
* @typeParam L - Locale code.
|
|
1696
|
+
* @param entry - The entry to personalize.
|
|
1697
|
+
* @param personalizations - Optional selections; defaults to the current signal value.
|
|
1698
|
+
* @returns The resolved entry data.
|
|
1699
|
+
* @example
|
|
1700
|
+
* ```ts
|
|
1701
|
+
* const { entry } = personalization.personalizeEntry(baselineEntry)
|
|
1702
|
+
* ```
|
|
1703
|
+
*/
|
|
1704
|
+
personalizeEntry<S extends EntrySkeletonType, M extends ChainModifiers = ChainModifiers, L extends LocaleCode = LocaleCode>(entry: Entry<S, M, L>, personalizations?: SelectedPersonalizationArray | undefined): ResolvedData<S, M, L>;
|
|
1705
|
+
/**
|
|
1706
|
+
* Resolve a merge tag to a value based on the current (or provided) profile.
|
|
1707
|
+
*
|
|
1708
|
+
* @param embeddedEntryNodeTarget - The merge‑tag entry node to resolve.
|
|
1709
|
+
* @param profile - Optional profile; defaults to the current signal value.
|
|
1710
|
+
* @returns The resolved value (type depends on the tag).
|
|
1711
|
+
* @remarks
|
|
1712
|
+
* Merge tags are references to profile data that can be substituted into content.
|
|
1713
|
+
* @example
|
|
1714
|
+
* ```ts
|
|
1715
|
+
* const name = personalization.getMergeTagValue(mergeTagNode)
|
|
1716
|
+
* ```
|
|
1717
|
+
*/
|
|
1718
|
+
getMergeTagValue(embeddedEntryNodeTarget: MergeTagEntry, profile?: Profile | undefined): string | undefined;
|
|
1719
|
+
/**
|
|
1720
|
+
* Determine whether the named operation is permitted based on consent and
|
|
1721
|
+
* allowed event type configuration.
|
|
1722
|
+
*
|
|
1723
|
+
* @param name - Method name; `trackComponentView` is normalized to
|
|
1724
|
+
* `'component'` for allow‑list checks.
|
|
1725
|
+
* @returns `true` if the operation is permitted; otherwise `false`.
|
|
1726
|
+
* @example
|
|
1727
|
+
* ```ts
|
|
1728
|
+
* if (personalization.hasConsent('track')) { ... }
|
|
1729
|
+
* ```
|
|
1730
|
+
*/
|
|
1731
|
+
hasConsent(name: string): boolean;
|
|
1732
|
+
/**
|
|
1733
|
+
* Hook invoked when an operation is blocked due to missing consent.
|
|
1734
|
+
*
|
|
1735
|
+
* @param name - The blocked operation name.
|
|
1736
|
+
* @param payload - The original arguments supplied to the operation.
|
|
1737
|
+
* @example
|
|
1738
|
+
* ```ts
|
|
1739
|
+
* personalization.onBlockedByConsent('track', [payload])
|
|
1740
|
+
* ```
|
|
1741
|
+
*/
|
|
1742
|
+
onBlockedByConsent(name: string, payload: readonly unknown[]): void;
|
|
1743
|
+
/**
|
|
1744
|
+
* Identify the current profile/visitor to associate traits with a profile
|
|
1745
|
+
* and update optimization state.
|
|
1746
|
+
*
|
|
1747
|
+
* @param payload - Identify builder payload.
|
|
1748
|
+
* @returns The resulting {@link OptimizationData} for the identified user.
|
|
1749
|
+
* @example
|
|
1750
|
+
* ```ts
|
|
1751
|
+
* const data = await personalization.identify({ userId: 'user-123' })
|
|
1752
|
+
* ```
|
|
1753
|
+
*/
|
|
1754
|
+
identify(payload: IdentifyBuilderArgs): Promise<OptimizationData | undefined>;
|
|
1755
|
+
/**
|
|
1756
|
+
* Record a page view and update optimization state.
|
|
1757
|
+
*
|
|
1758
|
+
* @param payload - Page view builder payload.
|
|
1759
|
+
* @returns The evaluated {@link OptimizationData} for this page view.
|
|
1760
|
+
* @example
|
|
1761
|
+
* ```ts
|
|
1762
|
+
* const data = await personalization.page({ properties: { title: 'Home' } })
|
|
1763
|
+
* ```
|
|
1764
|
+
*/
|
|
1765
|
+
page(payload: PageViewBuilderArgs): Promise<OptimizationData | undefined>;
|
|
1766
|
+
/**
|
|
1767
|
+
* Record a screen view and update optimization state.
|
|
1768
|
+
*
|
|
1769
|
+
* @param payload - Screen view builder payload.
|
|
1770
|
+
* @returns The evaluated {@link OptimizationData} for this screen view.
|
|
1771
|
+
* @example
|
|
1772
|
+
* ```ts
|
|
1773
|
+
* const data = await personalization.screen({ name: 'HomeScreen' })
|
|
1774
|
+
* ```
|
|
1775
|
+
*/
|
|
1776
|
+
screen(payload: ScreenViewBuilderArgs): Promise<OptimizationData | undefined>;
|
|
1777
|
+
/**
|
|
1778
|
+
* Record a custom track event and update optimization state.
|
|
1779
|
+
*
|
|
1780
|
+
* @param payload - Track builder payload.
|
|
1781
|
+
* @returns The evaluated {@link OptimizationData} for this event.
|
|
1782
|
+
* @example
|
|
1783
|
+
* ```ts
|
|
1784
|
+
* const data = await personalization.track({ event: 'button_click' })
|
|
1785
|
+
* ```
|
|
1786
|
+
*/
|
|
1787
|
+
track(payload: TrackBuilderArgs): Promise<OptimizationData | undefined>;
|
|
1788
|
+
/**
|
|
1789
|
+
* Record a "sticky" component view and update optimization state.
|
|
1790
|
+
*
|
|
1791
|
+
* @param payload - Component view builder payload.
|
|
1792
|
+
* @returns The evaluated {@link OptimizationData} for this component view.
|
|
1793
|
+
* @example
|
|
1794
|
+
* ```ts
|
|
1795
|
+
* const data = await personalization.trackComponentView({ componentId: 'hero-banner' })
|
|
1796
|
+
* ```
|
|
1797
|
+
*/
|
|
1798
|
+
trackComponentView(payload: ComponentViewBuilderArgs): Promise<OptimizationData | undefined>;
|
|
1799
|
+
/**
|
|
1800
|
+
* Intercept, validate, and place an event into the offline event queue; then
|
|
1801
|
+
* trigger a size‑based flush if necessary.
|
|
1802
|
+
*
|
|
1803
|
+
* @param event - The event to enqueue.
|
|
1804
|
+
*/
|
|
1805
|
+
private sendOrEnqueueEvent;
|
|
1806
|
+
/**
|
|
1807
|
+
* Enqueue an offline event, dropping oldest events first when queue bounds are reached.
|
|
1808
|
+
*
|
|
1809
|
+
* @param event - Event to enqueue.
|
|
1810
|
+
*/
|
|
1811
|
+
private enqueueOfflineEvent;
|
|
1812
|
+
/**
|
|
1813
|
+
* Drop oldest offline events from the queue.
|
|
1814
|
+
*
|
|
1815
|
+
* @param count - Number of oldest events to drop.
|
|
1816
|
+
* @returns Dropped events in oldest-first order.
|
|
1817
|
+
*/
|
|
1818
|
+
private dropOldestOfflineEvents;
|
|
1819
|
+
/**
|
|
1820
|
+
* Invoke offline queue drop callback in a fault-tolerant manner.
|
|
1821
|
+
*
|
|
1822
|
+
* @param context - Drop callback payload.
|
|
1823
|
+
*/
|
|
1824
|
+
private invokeQueueDropCallback;
|
|
1825
|
+
/**
|
|
1826
|
+
* Flush the offline queue
|
|
1827
|
+
*
|
|
1828
|
+
* @param options - Optional flush controls.
|
|
1829
|
+
* @param options.force - When `true`, bypass offline/backoff/circuit gates and attempt immediately.
|
|
1830
|
+
*
|
|
1831
|
+
* @example
|
|
1832
|
+
* ```ts
|
|
1833
|
+
* await personalization.flush()
|
|
1834
|
+
*/
|
|
1835
|
+
flush(options?: {
|
|
1836
|
+
force?: boolean;
|
|
1837
|
+
}): Promise<void>;
|
|
1838
|
+
/**
|
|
1839
|
+
* Flush queued offline events using retry/circuit guards.
|
|
1840
|
+
*
|
|
1841
|
+
* @param options - Flush controls.
|
|
1842
|
+
* @param options.force - When true, bypass online/backoff/circuit gates.
|
|
1843
|
+
*/
|
|
1844
|
+
private flushOfflineQueue;
|
|
1845
|
+
/**
|
|
1846
|
+
* Attempt to send queued events to the Experience API.
|
|
1847
|
+
*
|
|
1848
|
+
* @param events - Snapshot of queued events to send.
|
|
1849
|
+
* @returns `true` when send succeeds; otherwise `false`.
|
|
1850
|
+
*/
|
|
1851
|
+
private tryUpsertQueuedEvents;
|
|
1852
|
+
/**
|
|
1853
|
+
* Submit events to the Experience API, updating output signals with the
|
|
1854
|
+
* returned state.
|
|
1855
|
+
*
|
|
1856
|
+
* @param events - The events to submit.
|
|
1857
|
+
* @returns The {@link OptimizationData} returned by the service.
|
|
1858
|
+
* @internal
|
|
1859
|
+
* @privateRemarks
|
|
1860
|
+
* If a `getAnonymousId` function has been provided, the returned value will
|
|
1861
|
+
* take precedence over the `id` property of the current {@link Profile}
|
|
1862
|
+
* signal value
|
|
1863
|
+
*/
|
|
1864
|
+
private upsertProfile;
|
|
1865
|
+
/**
|
|
1866
|
+
* Apply returned optimization state to local signals after interceptor processing.
|
|
1867
|
+
*
|
|
1868
|
+
* @param data - Optimization state returned by the service.
|
|
1869
|
+
* @internal
|
|
1870
|
+
*/
|
|
1871
|
+
private updateOutputSignals;
|
|
1872
|
+
}
|
|
1873
|
+
|
|
1874
|
+
/**
|
|
1875
|
+
* Options for configuring {@link PersonalizationStateful} functionality.
|
|
1876
|
+
*
|
|
1877
|
+
* @public
|
|
1878
|
+
* @see {@link ProductBaseOptions}
|
|
1879
|
+
*/
|
|
1880
|
+
export declare type PersonalizationStatefulOptions = ProductBaseOptions & {
|
|
1881
|
+
/** Configuration specific to the Personalization product */
|
|
1882
|
+
config?: PersonalizationProductConfig;
|
|
1883
|
+
};
|
|
1884
|
+
|
|
1885
|
+
/**
|
|
1886
|
+
* Stateless personalization implementation that immediately validates and sends
|
|
1887
|
+
* a single event to the Experience API, upserting the profile as needed.
|
|
1888
|
+
*
|
|
1889
|
+
* @public
|
|
1890
|
+
* @remarks
|
|
1891
|
+
* Each public method constructs a strongly-typed event via the shared builder,
|
|
1892
|
+
* runs it through event interceptors, and performs a profile upsert using the
|
|
1893
|
+
* Experience API. If an anonymous ID is available from the builder, it will be
|
|
1894
|
+
* preferred as the `profileId` unless an explicit profile is provided.
|
|
1895
|
+
*/
|
|
1896
|
+
export declare class PersonalizationStateless extends PersonalizationBase {
|
|
1897
|
+
/**
|
|
1898
|
+
* Identify the current profile/visitor to associate traits with a profile.
|
|
1899
|
+
*
|
|
1900
|
+
* @param payload - Identify builder arguments with an optional partial
|
|
1901
|
+
* profile to attach to the upsert request.
|
|
1902
|
+
* @returns The resulting {@link OptimizationData} for the identified user.
|
|
1903
|
+
* @example
|
|
1904
|
+
* ```ts
|
|
1905
|
+
* const data = await personalization.identify({ userId: 'user-123', profile: { id: 'anon-1' } })
|
|
1906
|
+
* ```
|
|
1907
|
+
*/
|
|
1908
|
+
identify(payload: IdentifyBuilderArgs & {
|
|
1909
|
+
profile?: PartialProfile;
|
|
1910
|
+
}): Promise<OptimizationData>;
|
|
1911
|
+
/**
|
|
1912
|
+
* Record a page view.
|
|
1913
|
+
*
|
|
1914
|
+
* @param payload - Page view builder arguments with an optional partial profile.
|
|
1915
|
+
* @returns The evaluated {@link OptimizationData} for this page view.
|
|
1916
|
+
* @example
|
|
1917
|
+
* ```ts
|
|
1918
|
+
* const data = await personalization.page({ properties: { title: 'Home' }, profile: { id: 'anon-1' } })
|
|
1919
|
+
* ```
|
|
1920
|
+
*/
|
|
1921
|
+
page(payload: PageViewBuilderArgs & {
|
|
1922
|
+
profile?: PartialProfile;
|
|
1923
|
+
}): Promise<OptimizationData>;
|
|
1924
|
+
/**
|
|
1925
|
+
* Record a screen view.
|
|
1926
|
+
*
|
|
1927
|
+
* @param payload - Screen view builder arguments with an optional partial profile.
|
|
1928
|
+
* @returns The evaluated {@link OptimizationData} for this screen view.
|
|
1929
|
+
* @example
|
|
1930
|
+
* ```ts
|
|
1931
|
+
* const data = await personalization.screen({ name: 'HomeScreen', profile: { id: 'anon-1' } })
|
|
1932
|
+
* ```
|
|
1933
|
+
*/
|
|
1934
|
+
screen(payload: ScreenViewBuilderArgs & {
|
|
1935
|
+
profile?: PartialProfile;
|
|
1936
|
+
}): Promise<OptimizationData>;
|
|
1937
|
+
/**
|
|
1938
|
+
* Record a custom track event.
|
|
1939
|
+
*
|
|
1940
|
+
* @param payload - Track builder arguments with an optional partial profile.
|
|
1941
|
+
* @returns The evaluated {@link OptimizationData} for this event.
|
|
1942
|
+
* @example
|
|
1943
|
+
* ```ts
|
|
1944
|
+
* const data = await personalization.track({ event: 'purchase', profile: { id: 'anon-1' } })
|
|
1945
|
+
* ```
|
|
1946
|
+
*/
|
|
1947
|
+
track(payload: TrackBuilderArgs & {
|
|
1948
|
+
profile?: PartialProfile;
|
|
1949
|
+
}): Promise<OptimizationData>;
|
|
1950
|
+
/**
|
|
1951
|
+
* Record a "sticky" component view.
|
|
1952
|
+
*
|
|
1953
|
+
* @param payload - Component view builder arguments with an optional partial profile.
|
|
1954
|
+
* @returns The evaluated {@link OptimizationData} for this component view.
|
|
1955
|
+
* @example
|
|
1956
|
+
* ```ts
|
|
1957
|
+
* const data = await personalization.trackComponentView({ componentId: 'hero', profile: { id: 'anon-1' } })
|
|
1958
|
+
* ```
|
|
1959
|
+
*/
|
|
1960
|
+
trackComponentView(payload: ComponentViewBuilderArgs & {
|
|
1961
|
+
profile?: PartialProfile;
|
|
1962
|
+
}): Promise<OptimizationData>;
|
|
1963
|
+
/**
|
|
1964
|
+
* Intercept, validate, and upsert the profile with a single personalization
|
|
1965
|
+
* event.
|
|
1966
|
+
*
|
|
1967
|
+
* @param event - The {@link PersonalizationEvent} to submit.
|
|
1968
|
+
* @param profile - Optional partial profile. If omitted, the anonymous ID from
|
|
1969
|
+
* the builder (when present) is used as the `profileId`.
|
|
1970
|
+
* @returns The {@link OptimizationData} returned by the Experience API.
|
|
1971
|
+
* @internal
|
|
1972
|
+
*/
|
|
1973
|
+
private upsertProfile;
|
|
1974
|
+
}
|
|
1975
|
+
|
|
1976
|
+
/**
|
|
1977
|
+
* Observables exposed by {@link PersonalizationStateful} that mirror internal signals.
|
|
1978
|
+
*
|
|
1979
|
+
* @public
|
|
1980
|
+
*/
|
|
1981
|
+
export declare interface PersonalizationStates {
|
|
1982
|
+
/** Observable stream of the latest blocked event payload (or `undefined`). */
|
|
1983
|
+
blockedEventStream: Observable<BlockedEvent | undefined>;
|
|
1984
|
+
/** Observable stream of the latest {@link AnalyticsEvent} or {@link PersonalizationEvent} (or `undefined`). */
|
|
1985
|
+
eventStream: Observable<InsightsEvent | ExperienceEvent | undefined>;
|
|
1986
|
+
/** Live view of effective flags for the current profile (if available). */
|
|
1987
|
+
flags: Observable<Flags | undefined>;
|
|
1988
|
+
/** Live view of the current profile. */
|
|
1989
|
+
profile: Observable<Profile | undefined>;
|
|
1990
|
+
/** Live view of selected personalizations (variants). */
|
|
1991
|
+
personalizations: Observable<SelectedPersonalizationArray | undefined>;
|
|
1992
|
+
}
|
|
1993
|
+
|
|
1994
|
+
/**
|
|
1995
|
+
* Resolve a personalized Contentful entry to the correct variant for the current
|
|
1996
|
+
* selections.
|
|
1997
|
+
*
|
|
1998
|
+
* @public
|
|
1999
|
+
* @remarks
|
|
2000
|
+
* Given a baseline {@link PersonalizedEntry} and a set of selected personalizations
|
|
2001
|
+
* (variants per experience), this resolver finds the matching replacement variant
|
|
2002
|
+
* for the component configured against the baseline entry.
|
|
2003
|
+
*
|
|
2004
|
+
* **Variant indexing**: `variantIndex` in {@link SelectedPersonalization} is treated as
|
|
2005
|
+
* 1‑based (index 1 = first variant). A value of `0` indicates baseline.
|
|
2006
|
+
*/
|
|
2007
|
+
export declare const PersonalizedEntryResolver: {
|
|
2008
|
+
/**
|
|
2009
|
+
* Find the personalization entry corresponding to one of the selected experiences.
|
|
2010
|
+
*
|
|
2011
|
+
* @param params - Object containing the baseline personalized entry and the selections.
|
|
2012
|
+
* @param skipValidation - When `true`, skip type/shape validation for perf.
|
|
2013
|
+
* @returns The matching {@link PersonalizationEntry}, or `undefined` if not found/invalid.
|
|
2014
|
+
* @remarks
|
|
2015
|
+
* A personalization entry is a personalization configuration object supplied in a
|
|
2016
|
+
* `PersonalizedEntry.nt_experiences` array. A personalized entry may relate to
|
|
2017
|
+
* multiple personalizations.
|
|
2018
|
+
* @example
|
|
2019
|
+
* ```ts
|
|
2020
|
+
* const personalizationEntry = PersonalizedEntryResolver.getPersonalizationEntry({
|
|
2021
|
+
* personalizedEntry: entry,
|
|
2022
|
+
* selectedPersonalizations
|
|
2023
|
+
* })
|
|
2024
|
+
* ```
|
|
2025
|
+
*/
|
|
2026
|
+
getPersonalizationEntry({ personalizedEntry, selectedPersonalizations, }: {
|
|
2027
|
+
personalizedEntry: PersonalizedEntry_2;
|
|
2028
|
+
selectedPersonalizations: SelectedPersonalizationArray;
|
|
2029
|
+
}, skipValidation?: boolean): PersonalizationEntry_2 | undefined;
|
|
2030
|
+
/**
|
|
2031
|
+
* Look up the selection metadata for a specific personalization entry.
|
|
2032
|
+
*
|
|
2033
|
+
* @param params - Object with the target personalization entry and selections.
|
|
2034
|
+
* @param skipValidation - When `true`, skip type checks.
|
|
2035
|
+
* @returns The matching {@link SelectedPersonalization}, if present.
|
|
2036
|
+
* @remarks
|
|
2037
|
+
* Selected personalizations are supplied by the Experience API in the
|
|
2038
|
+
* `experiences` response data property.
|
|
2039
|
+
* @example
|
|
2040
|
+
* ```ts
|
|
2041
|
+
* const selectedPersonalization = PersonalizedEntryResolver.getSelectedPersonalization({
|
|
2042
|
+
* personalizationEntry,
|
|
2043
|
+
* selectedPersonalizations
|
|
2044
|
+
* })
|
|
2045
|
+
* ```
|
|
2046
|
+
*/
|
|
2047
|
+
getSelectedPersonalization({ personalizationEntry, selectedPersonalizations, }: {
|
|
2048
|
+
personalizationEntry: PersonalizationEntry_2;
|
|
2049
|
+
selectedPersonalizations: SelectedPersonalizationArray;
|
|
2050
|
+
}, skipValidation?: boolean): SelectedPersonalization | undefined;
|
|
2051
|
+
/**
|
|
2052
|
+
* Get the replacement variant config for the given selection index.
|
|
2053
|
+
*
|
|
2054
|
+
* @param params - Baseline entry, personalization entry, and 1‑based variant index.
|
|
2055
|
+
* @param skipValidation - When `true`, skip type checks.
|
|
2056
|
+
* @returns The {@link EntryReplacementVariant} for the component, if any.
|
|
2057
|
+
* @remarks
|
|
2058
|
+
* Entry replacement variants are variant configurations specified in a
|
|
2059
|
+
* personalization configuration component's `variants` array supplied by the
|
|
2060
|
+
* personalized entry via its `nt_config` field.
|
|
2061
|
+
* @example
|
|
2062
|
+
* ```ts
|
|
2063
|
+
* const selectedVariant = PersonalizedEntryResolver.getSelectedVariant({
|
|
2064
|
+
* personalizedEntry: entry,
|
|
2065
|
+
* personalizationEntry,
|
|
2066
|
+
* selectedVariantIndex: 2 // second variant (1‑based)
|
|
2067
|
+
* })
|
|
2068
|
+
* ```
|
|
2069
|
+
*/
|
|
2070
|
+
getSelectedVariant({ personalizedEntry, personalizationEntry, selectedVariantIndex, }: {
|
|
2071
|
+
personalizedEntry: PersonalizedEntry_2;
|
|
2072
|
+
personalizationEntry: PersonalizationEntry_2;
|
|
2073
|
+
selectedVariantIndex: number;
|
|
2074
|
+
}, skipValidation?: boolean): EntryReplacementVariant_2 | undefined;
|
|
2075
|
+
/**
|
|
2076
|
+
* Resolve the concrete Contentful entry that corresponds to a selected variant.
|
|
2077
|
+
*
|
|
2078
|
+
* @typeParam S - Entry skeleton type.
|
|
2079
|
+
* @typeParam M - Chain modifiers.
|
|
2080
|
+
* @typeParam L - Locale code.
|
|
2081
|
+
* @param params - Personalization entry and selected variant.
|
|
2082
|
+
* @param skipValidation - When `true`, skip type checks.
|
|
2083
|
+
* @returns The resolved entry typed as {@link Entry} or `undefined`.
|
|
2084
|
+
* @remarks
|
|
2085
|
+
* A personalized entry will resolve either to the baseline (the entry
|
|
2086
|
+
* supplied as `personalizedEntry`) or the selected variant.
|
|
2087
|
+
* @example
|
|
2088
|
+
* ```ts
|
|
2089
|
+
* const selectedVariantEntry = PersonalizedEntryResolver.getSelectedVariantEntry<{ fields: unknown }>({
|
|
2090
|
+
* personalizationEntry,
|
|
2091
|
+
* selectedVariant
|
|
2092
|
+
* })
|
|
2093
|
+
* ```
|
|
2094
|
+
*/
|
|
2095
|
+
getSelectedVariantEntry<S extends EntrySkeletonType, M extends ChainModifiers = ChainModifiers, L extends LocaleCode = string>({ personalizationEntry, selectedVariant, }: {
|
|
2096
|
+
personalizationEntry: PersonalizationEntry_2;
|
|
2097
|
+
selectedVariant: EntryReplacementVariant_2;
|
|
2098
|
+
}, skipValidation?: boolean): Entry<S, M, L> | undefined;
|
|
2099
|
+
/**
|
|
2100
|
+
* Resolve the selected entry (baseline or variant) for a personalized entry
|
|
2101
|
+
* and optional selected personalizations, returning both the entry and the
|
|
2102
|
+
* personalization metadata.
|
|
2103
|
+
*
|
|
2104
|
+
* @typeParam S - Entry skeleton type.
|
|
2105
|
+
* @typeParam M - Chain modifiers.
|
|
2106
|
+
* @typeParam L - Locale code.
|
|
2107
|
+
* @param entry - The baseline personalized entry.
|
|
2108
|
+
* @param selectedPersonalizations - Optional selections for the current profile.
|
|
2109
|
+
* @returns An object containing the resolved entry and (if chosen) the selection.
|
|
2110
|
+
* @example
|
|
2111
|
+
* ```ts
|
|
2112
|
+
* const { entry: personalizedEntry, personalization } = PersonalizedEntryResolver.resolve(entry, selections)
|
|
2113
|
+
* if (personalization) console.log('Variant index', personalization.variantIndex)
|
|
2114
|
+
* ```
|
|
2115
|
+
*/
|
|
2116
|
+
resolve<S extends EntrySkeletonType, M extends ChainModifiers = ChainModifiers, L extends LocaleCode = string>(entry: Entry<S, M, L>, selectedPersonalizations?: SelectedPersonalizationArray): ResolvedData<S, M, L>;
|
|
2117
|
+
};
|
|
2118
|
+
|
|
2119
|
+
export declare const PREVIEW_PANEL_SIGNAL_FNS_SYMBOL: unique symbol;
|
|
2120
|
+
|
|
2121
|
+
/**
|
|
2122
|
+
* Well-known symbols used by the preview panel bridge.
|
|
2123
|
+
*
|
|
2124
|
+
* @public
|
|
2125
|
+
*/
|
|
2126
|
+
export declare const PREVIEW_PANEL_SIGNALS_SYMBOL: unique symbol;
|
|
2127
|
+
|
|
2128
|
+
declare const previewPanelAttached: Signal<boolean>;
|
|
2129
|
+
|
|
2130
|
+
declare const previewPanelOpen: Signal<boolean>;
|
|
2131
|
+
|
|
2132
|
+
/**
|
|
2133
|
+
* Symbol-keyed signal bridge shared between core and first-party preview tooling.
|
|
2134
|
+
*
|
|
2135
|
+
* @public
|
|
2136
|
+
*/
|
|
2137
|
+
export declare interface PreviewPanelSignalObject {
|
|
2138
|
+
/** Signals instance populated by {@link CoreStateful.registerPreviewPanel}. */
|
|
2139
|
+
[PREVIEW_PANEL_SIGNALS_SYMBOL]?: Signals | null | undefined;
|
|
2140
|
+
/** Signal helper functions populated by {@link CoreStateful.registerPreviewPanel}. */
|
|
2141
|
+
[PREVIEW_PANEL_SIGNAL_FNS_SYMBOL]?: SignalFns | null | undefined;
|
|
2142
|
+
}
|
|
2143
|
+
|
|
2144
|
+
/**
|
|
2145
|
+
* Shared base for all product implementations.
|
|
2146
|
+
*
|
|
2147
|
+
* @internal
|
|
2148
|
+
* @remarks
|
|
2149
|
+
* This abstract class is not exported as part of the public API surface.
|
|
2150
|
+
* Concrete implementations (e.g., analytics) should extend this class and
|
|
2151
|
+
* expose their own public methods.
|
|
2152
|
+
*/
|
|
2153
|
+
declare abstract class ProductBase {
|
|
2154
|
+
/**
|
|
2155
|
+
* Allow‑list of event {@link AnalyticsEventType | type keys} permitted when consent is not present.
|
|
2156
|
+
*/
|
|
2157
|
+
protected readonly allowedEventTypes?: string[];
|
|
2158
|
+
/** Event builder used to construct strongly‑typed events. */
|
|
2159
|
+
protected readonly builder: EventBuilder;
|
|
2160
|
+
/** Optimization API client used to send events to the Experience and Insights APIs. */
|
|
2161
|
+
protected readonly api: ApiClient;
|
|
2162
|
+
/** Interceptors that can mutate/augment outgoing events or optimization state. */
|
|
2163
|
+
readonly interceptors: LifecycleInterceptors;
|
|
2164
|
+
/** Optional callback invoked when an event call is blocked. */
|
|
2165
|
+
protected readonly onEventBlocked?: ProductConfig['onEventBlocked'];
|
|
2166
|
+
/**
|
|
2167
|
+
* Creates a new product base instance.
|
|
2168
|
+
*
|
|
2169
|
+
* @param options - Options for configuring the functionality common among products.
|
|
2170
|
+
*/
|
|
2171
|
+
constructor(options: ProductBaseOptions);
|
|
2172
|
+
/**
|
|
2173
|
+
* Publish blocked event metadata to both callback and blocked event signal.
|
|
2174
|
+
*
|
|
2175
|
+
* @param reason - Reason the method call was blocked.
|
|
2176
|
+
* @param product - Product that blocked the method call.
|
|
2177
|
+
* @param method - Name of the blocked method.
|
|
2178
|
+
* @param args - Original blocked call arguments.
|
|
2179
|
+
*/
|
|
2180
|
+
protected reportBlockedEvent(reason: BlockedEventReason, product: BlockedEventProduct, method: string, args: readonly unknown[]): void;
|
|
2181
|
+
}
|
|
2182
|
+
|
|
2183
|
+
/**
|
|
2184
|
+
* Options for configuring the common functionality of {@link ProductBase} descendents.
|
|
2185
|
+
*
|
|
2186
|
+
* @public
|
|
2187
|
+
*/
|
|
2188
|
+
declare interface ProductBaseOptions {
|
|
2189
|
+
/** Optimization API client. */
|
|
2190
|
+
api: ApiClient;
|
|
2191
|
+
/** Event builder for constructing events. */
|
|
2192
|
+
builder: EventBuilder;
|
|
2193
|
+
/** Optional configuration for allow‑lists and guard callbacks. */
|
|
2194
|
+
config?: ProductConfig;
|
|
2195
|
+
/** Lifecycle container for event and state interceptors. */
|
|
2196
|
+
interceptors: LifecycleInterceptors;
|
|
2197
|
+
}
|
|
2198
|
+
|
|
2199
|
+
/**
|
|
2200
|
+
* Common configuration for all product implementations.
|
|
2201
|
+
*
|
|
2202
|
+
* @public
|
|
2203
|
+
*/
|
|
2204
|
+
declare interface ProductConfig {
|
|
2205
|
+
/**
|
|
2206
|
+
* The set of event type strings that are allowed to be sent even if consent is
|
|
2207
|
+
* not granted.
|
|
2208
|
+
*
|
|
2209
|
+
* @defaultValue `['identify', 'page', 'screen']`
|
|
2210
|
+
* @remarks These types are compared against the `type` property of events.
|
|
2211
|
+
*/
|
|
2212
|
+
allowedEventTypes?: EventType[];
|
|
2213
|
+
/**
|
|
2214
|
+
* Callback invoked whenever an event call is blocked by guards.
|
|
2215
|
+
*
|
|
2216
|
+
* @remarks
|
|
2217
|
+
* This callback is best-effort. Any exception thrown by the callback is
|
|
2218
|
+
* swallowed to keep event handling fault tolerant.
|
|
2219
|
+
*/
|
|
2220
|
+
onEventBlocked?: (event: BlockedEvent) => void;
|
|
2221
|
+
}
|
|
2222
|
+
|
|
2223
|
+
declare const profile: Signal<Profile | undefined>;
|
|
2224
|
+
|
|
2225
|
+
/**
|
|
2226
|
+
* Storage key for cached profile data.
|
|
2227
|
+
*
|
|
2228
|
+
* @internal
|
|
2229
|
+
*/
|
|
2230
|
+
export declare const PROFILE_CACHE_KEY = "__ctfl_opt_profile__";
|
|
2231
|
+
|
|
2232
|
+
/**
|
|
2233
|
+
* Context payload emitted when a queue flush fails.
|
|
2234
|
+
*
|
|
2235
|
+
* @public
|
|
2236
|
+
*/
|
|
2237
|
+
declare interface QueueFlushFailureContext {
|
|
2238
|
+
/** Number of consecutive failed flush attempts. */
|
|
2239
|
+
consecutiveFailures: number;
|
|
2240
|
+
/** Number of queued batches at the time of the failed attempt. */
|
|
2241
|
+
queuedBatches: number;
|
|
2242
|
+
/** Number of queued events at the time of the failed attempt. */
|
|
2243
|
+
queuedEvents: number;
|
|
2244
|
+
/** Delay before the next retry attempt is scheduled. */
|
|
2245
|
+
retryDelayMs: number;
|
|
2246
|
+
}
|
|
2247
|
+
|
|
2248
|
+
/**
|
|
2249
|
+
* Policy options for controlling queue flush retry behavior.
|
|
2250
|
+
*
|
|
2251
|
+
* @public
|
|
2252
|
+
*/
|
|
2253
|
+
declare interface QueueFlushPolicy {
|
|
2254
|
+
/**
|
|
2255
|
+
* Base retry backoff delay in milliseconds.
|
|
2256
|
+
*
|
|
2257
|
+
* @defaultValue `500`
|
|
2258
|
+
*/
|
|
2259
|
+
baseBackoffMs?: number;
|
|
2260
|
+
/**
|
|
2261
|
+
* Maximum retry backoff delay in milliseconds.
|
|
2262
|
+
*
|
|
2263
|
+
* @defaultValue `30000`
|
|
2264
|
+
*/
|
|
2265
|
+
maxBackoffMs?: number;
|
|
2266
|
+
/**
|
|
2267
|
+
* Jitter ratio applied to retry delay to avoid synchronized retries.
|
|
2268
|
+
*
|
|
2269
|
+
* @remarks
|
|
2270
|
+
* Value is clamped to `[0, 1]`.
|
|
2271
|
+
*
|
|
2272
|
+
* @defaultValue `0.2`
|
|
2273
|
+
*/
|
|
2274
|
+
jitterRatio?: number;
|
|
2275
|
+
/**
|
|
2276
|
+
* Consecutive failures threshold before opening the circuit window.
|
|
2277
|
+
*
|
|
2278
|
+
* @defaultValue `8`
|
|
2279
|
+
*/
|
|
2280
|
+
maxConsecutiveFailures?: number;
|
|
2281
|
+
/**
|
|
2282
|
+
* Duration in milliseconds to wait before retrying after circuit opens.
|
|
2283
|
+
*
|
|
2284
|
+
* @defaultValue `120000`
|
|
2285
|
+
*/
|
|
2286
|
+
circuitOpenMs?: number;
|
|
2287
|
+
/**
|
|
2288
|
+
* Callback invoked after each failed flush attempt.
|
|
2289
|
+
*/
|
|
2290
|
+
onFlushFailure?: (context: QueueFlushFailureContext) => void;
|
|
2291
|
+
/**
|
|
2292
|
+
* Callback invoked when the circuit opens after consecutive failures.
|
|
2293
|
+
*/
|
|
2294
|
+
onCircuitOpen?: (context: QueueFlushFailureContext) => void;
|
|
2295
|
+
/**
|
|
2296
|
+
* Callback invoked when a flush succeeds after previous failures.
|
|
2297
|
+
*/
|
|
2298
|
+
onFlushRecovered?: (context: QueueFlushRecoveredContext) => void;
|
|
2299
|
+
}
|
|
2300
|
+
|
|
2301
|
+
/**
|
|
2302
|
+
* Context payload emitted when a failed queue flush sequence recovers.
|
|
2303
|
+
*
|
|
2304
|
+
* @public
|
|
2305
|
+
*/
|
|
2306
|
+
declare interface QueueFlushRecoveredContext {
|
|
2307
|
+
/** Consecutive failure count that existed immediately before recovery. */
|
|
2308
|
+
consecutiveFailures: number;
|
|
2309
|
+
}
|
|
2310
|
+
|
|
2311
|
+
/**
|
|
2312
|
+
* Result returned by {@link PersonalizedEntryResolver.resolve}.
|
|
2313
|
+
*
|
|
2314
|
+
* @typeParam S - Entry skeleton type.
|
|
2315
|
+
* @typeParam M - Chain modifiers.
|
|
2316
|
+
* @typeParam L - Locale code.
|
|
2317
|
+
* @public
|
|
2318
|
+
*/
|
|
2319
|
+
export declare interface ResolvedData<S extends EntrySkeletonType, M extends ChainModifiers = ChainModifiers, L extends LocaleCode = LocaleCode> {
|
|
2320
|
+
/** The baseline or resolved variant entry. */
|
|
2321
|
+
entry: Entry<S, M, L>;
|
|
2322
|
+
/** The selected personalization metadata, if a non‑baseline variant was chosen. */
|
|
2323
|
+
personalization?: SelectedPersonalization;
|
|
2324
|
+
}
|
|
2325
|
+
|
|
2326
|
+
/**
|
|
2327
|
+
* These methods assist in resolving values via Resolvers
|
|
2328
|
+
*
|
|
2329
|
+
* @internal
|
|
2330
|
+
* @privateRemarks
|
|
2331
|
+
* This interface exists to document that the included methods should not be
|
|
2332
|
+
* considered static.
|
|
2333
|
+
*/
|
|
2334
|
+
export declare interface ResolverMethods {
|
|
2335
|
+
/**
|
|
2336
|
+
* Get the specified Custom Flag's value from the supplied changes.
|
|
2337
|
+
* @param name - The name or key of the Custom Flag.
|
|
2338
|
+
* @param changes - Optional changes array.
|
|
2339
|
+
* @returns The current value of the Custom Flag if found.
|
|
2340
|
+
* @remarks
|
|
2341
|
+
* The changes array can be sourced from the data returned when emitting any
|
|
2342
|
+
* personalization event.
|
|
2343
|
+
* */
|
|
2344
|
+
getCustomFlag: (name: string, changes?: ChangeArray) => Json;
|
|
2345
|
+
/**
|
|
2346
|
+
* Get all resolved Custom Flags from the supplied changes.
|
|
2347
|
+
* @param changes - Optional changes array.
|
|
2348
|
+
* @returns The resolved Custom Flag map.
|
|
2349
|
+
* @remarks
|
|
2350
|
+
* The changes array can be sourced from the data returned when emitting any
|
|
2351
|
+
* personalization event.
|
|
2352
|
+
* */
|
|
2353
|
+
getCustomFlags: (changes?: ChangeArray) => Flags;
|
|
2354
|
+
/**
|
|
2355
|
+
* Resolve a Contentful entry to a personalized variant using the current
|
|
2356
|
+
* or provided selected personalizations.
|
|
2357
|
+
*
|
|
2358
|
+
* @typeParam S - Entry skeleton type.
|
|
2359
|
+
* @typeParam M - Chain modifiers.
|
|
2360
|
+
* @typeParam L - Locale code.
|
|
2361
|
+
* @param entry - The entry to personalize.
|
|
2362
|
+
* @param personalizations - Optional selections.
|
|
2363
|
+
* @returns The resolved entry data.
|
|
2364
|
+
* @remarks
|
|
2365
|
+
* Selected personalizations can be sourced from the data returned when emitting any
|
|
2366
|
+
* personalization event.
|
|
2367
|
+
*/
|
|
2368
|
+
personalizeEntry: <S extends EntrySkeletonType, M extends ChainModifiers, L extends LocaleCode>(entry: Entry<S, M, L>, personalizations?: SelectedPersonalizationArray) => ResolvedData<S, M, L>;
|
|
2369
|
+
/**
|
|
2370
|
+
* Resolve a merge tag to a value based on the current (or provided) profile.
|
|
2371
|
+
*
|
|
2372
|
+
* @param embeddedEntryNodeTarget - The merge‑tag entry node to resolve.
|
|
2373
|
+
* @param profile - Optional profile.
|
|
2374
|
+
* @returns The resolved value (type depends on the tag).
|
|
2375
|
+
* @remarks
|
|
2376
|
+
* Merge tags are references to profile data that can be substituted into content. The
|
|
2377
|
+
* profile can be sourced from the data returned when emitting any personalization event.
|
|
2378
|
+
*/
|
|
2379
|
+
getMergeTagValue: (embeddedEntryNodeTarget: MergeTagEntry, profile?: Profile) => string | undefined;
|
|
2380
|
+
}
|
|
2381
|
+
|
|
2382
|
+
export { Signal }
|
|
2383
|
+
|
|
2384
|
+
export declare interface SignalFns {
|
|
2385
|
+
batch: typeof batch;
|
|
2386
|
+
computed: typeof computed;
|
|
2387
|
+
effect: typeof effect;
|
|
2388
|
+
untracked: typeof untracked;
|
|
2389
|
+
}
|
|
2390
|
+
|
|
2391
|
+
export declare const signalFns: SignalFns;
|
|
2392
|
+
|
|
2393
|
+
export declare interface Signals {
|
|
2394
|
+
blockedEvent: typeof blockedEvent;
|
|
2395
|
+
changes: typeof changes;
|
|
2396
|
+
consent: typeof consent;
|
|
2397
|
+
event: typeof event_2;
|
|
2398
|
+
flags: typeof flags;
|
|
2399
|
+
online: typeof online;
|
|
2400
|
+
previewPanelAttached: typeof previewPanelAttached;
|
|
2401
|
+
previewPanelOpen: typeof previewPanelOpen;
|
|
2402
|
+
personalizations: typeof personalizations;
|
|
2403
|
+
profile: typeof profile;
|
|
2404
|
+
}
|
|
2405
|
+
|
|
2406
|
+
export declare const signals: Signals;
|
|
2407
|
+
|
|
2408
|
+
declare interface Subscription {
|
|
2409
|
+
unsubscribe: () => void;
|
|
2410
|
+
}
|
|
2411
|
+
|
|
2412
|
+
export declare type TrackComponentClickArgs = ComponentClickBuilderArgs & {
|
|
2413
|
+
profile?: PartialProfile;
|
|
2414
|
+
};
|
|
2415
|
+
|
|
2416
|
+
export declare type TrackComponentHoverArgs = ComponentHoverBuilderArgs & {
|
|
2417
|
+
profile?: PartialProfile;
|
|
2418
|
+
};
|
|
2419
|
+
|
|
2420
|
+
/**
|
|
2421
|
+
* Arguments for tracking a component/flag view in stateless mode.
|
|
2422
|
+
*
|
|
2423
|
+
* @public
|
|
2424
|
+
* @remarks
|
|
2425
|
+
* The `profile` is optional; when omitted, the APIs may infer identity via
|
|
2426
|
+
* other means.
|
|
2427
|
+
*/
|
|
2428
|
+
export declare type TrackComponentViewArgs = ComponentViewBuilderArgs & {
|
|
2429
|
+
profile?: PartialProfile;
|
|
2430
|
+
};
|
|
2431
|
+
|
|
2432
|
+
export { }
|