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