@contentful/optimization-api-client 0.1.0-alpha9 → 1.0.1
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 +105 -248
- package/THIRD_PARTY_NOTICES.txt +2038 -0
- package/dist/index.cjs +78 -219
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +478 -1259
- package/dist/index.d.mts +478 -1259
- package/dist/index.d.ts +478 -1259
- package/dist/index.mjs +63 -213
- package/dist/index.mjs.map +1 -1
- package/package.json +18 -5
package/dist/index.d.cts
CHANGED
|
@@ -3,44 +3,31 @@
|
|
|
3
3
|
*
|
|
4
4
|
* The Contentful Optimization API Client Library provides methods for
|
|
5
5
|
* interfacing with Contentful's Experience and Insights APIs, which serve its
|
|
6
|
-
*
|
|
6
|
+
* Optimization and Analytics products.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import { App } from '@contentful/optimization-api-schemas';
|
|
10
9
|
import { BatchExperienceEventArray } from '@contentful/optimization-api-schemas';
|
|
11
10
|
import { BatchExperienceResponseData } from '@contentful/optimization-api-schemas';
|
|
12
11
|
import { BatchInsightsEventArray } from '@contentful/optimization-api-schemas';
|
|
13
|
-
import { Channel } from '@contentful/optimization-api-schemas';
|
|
14
|
-
import { ComponentClickEvent } from '@contentful/optimization-api-schemas';
|
|
15
|
-
import { ComponentHoverEvent } from '@contentful/optimization-api-schemas';
|
|
16
|
-
import { ComponentViewEvent } from '@contentful/optimization-api-schemas';
|
|
17
12
|
import { ExperienceEventArray } from '@contentful/optimization-api-schemas';
|
|
18
|
-
import { IdentifyEvent } from '@contentful/optimization-api-schemas';
|
|
19
|
-
import { Library } from '@contentful/optimization-api-schemas';
|
|
20
13
|
import { OptimizationData } from '@contentful/optimization-api-schemas';
|
|
21
|
-
import { Page } from '@contentful/optimization-api-schemas';
|
|
22
|
-
import { PageViewEvent } from '@contentful/optimization-api-schemas';
|
|
23
|
-
import { ScreenViewEvent } from '@contentful/optimization-api-schemas';
|
|
24
|
-
import { TrackEvent as TrackEvent_2 } from '@contentful/optimization-api-schemas';
|
|
25
|
-
import { UniversalEventProperties } from '@contentful/optimization-api-schemas';
|
|
26
|
-
import * as z from 'zod/mini';
|
|
27
14
|
|
|
28
15
|
/**
|
|
29
16
|
* Aggregated API client providing access to Experience and Insights APIs.
|
|
30
17
|
*
|
|
31
18
|
* @remarks
|
|
32
19
|
* This client encapsulates shared configuration and exposes dedicated
|
|
33
|
-
* sub-clients for
|
|
20
|
+
* sub-clients for experience and insights use cases.
|
|
34
21
|
*
|
|
35
22
|
* @example
|
|
36
23
|
* ```ts
|
|
37
24
|
* const client = new ApiClient({
|
|
38
25
|
* clientId: 'org-id',
|
|
39
26
|
* environment: 'main',
|
|
40
|
-
*
|
|
27
|
+
* experience: {
|
|
41
28
|
* // experience-specific overrides
|
|
42
29
|
* },
|
|
43
|
-
*
|
|
30
|
+
* insights: {
|
|
44
31
|
* // insights-specific overrides
|
|
45
32
|
* },
|
|
46
33
|
* })
|
|
@@ -62,13 +49,13 @@ export declare class ApiClient {
|
|
|
62
49
|
*/
|
|
63
50
|
readonly config: ApiConfig;
|
|
64
51
|
/**
|
|
65
|
-
* Client for
|
|
52
|
+
* Client for experience-related operations.
|
|
66
53
|
*
|
|
67
54
|
* @see {@link ExperienceApiClient}
|
|
68
55
|
*/
|
|
69
56
|
readonly experience: ExperienceApiClient;
|
|
70
57
|
/**
|
|
71
|
-
* Client for
|
|
58
|
+
* Client for insights-related operations.
|
|
72
59
|
*
|
|
73
60
|
* @see {@link InsightsApiClient}
|
|
74
61
|
*/
|
|
@@ -86,9 +73,9 @@ export declare class ApiClient {
|
|
|
86
73
|
*
|
|
87
74
|
* @remarks
|
|
88
75
|
* This abstract class is intended for internal use within the package and
|
|
89
|
-
*
|
|
76
|
+
* must not be treated as part of the public API surface.
|
|
90
77
|
*
|
|
91
|
-
* Concrete API clients
|
|
78
|
+
* Concrete API clients must extend this class to inherit consistent logging
|
|
92
79
|
* behavior and fetch configuration.
|
|
93
80
|
*
|
|
94
81
|
* @example
|
|
@@ -158,25 +145,25 @@ declare abstract class ApiClientBase {
|
|
|
158
145
|
*/
|
|
159
146
|
export declare interface ApiClientConfig extends Pick<ApiConfig, GlobalApiConfigProperties> {
|
|
160
147
|
/**
|
|
161
|
-
* Configuration for the
|
|
148
|
+
* Configuration for the Experience API client.
|
|
162
149
|
*
|
|
163
150
|
* @remarks
|
|
164
151
|
* Shared fields (`clientId`, `environment`, `fetchOptions`) are inherited
|
|
165
152
|
* from top-level config; this object is for Experience-specific options.
|
|
166
153
|
*/
|
|
167
|
-
|
|
154
|
+
experience?: Omit<ExperienceApiClientConfig, GlobalApiConfigProperties>;
|
|
168
155
|
/**
|
|
169
|
-
* Configuration for the
|
|
156
|
+
* Configuration for the Insights API client.
|
|
170
157
|
*
|
|
171
158
|
* @remarks
|
|
172
159
|
* Shared fields (`clientId`, `environment`, `fetchOptions`) are inherited
|
|
173
160
|
* from top-level config; this object is for Insights-specific options.
|
|
174
161
|
*/
|
|
175
|
-
|
|
162
|
+
insights?: Omit<InsightsApiClientConfig, GlobalApiConfigProperties>;
|
|
176
163
|
}
|
|
177
164
|
|
|
178
165
|
/**
|
|
179
|
-
* Configuration options for API clients extending
|
|
166
|
+
* Configuration options for API clients extending `ApiClientBase`.
|
|
180
167
|
*
|
|
181
168
|
* @public
|
|
182
169
|
*/
|
|
@@ -213,7 +200,7 @@ export declare interface ApiConfig {
|
|
|
213
200
|
*
|
|
214
201
|
* @public
|
|
215
202
|
*/
|
|
216
|
-
declare interface BaseFetchMethodOptions {
|
|
203
|
+
export declare interface BaseFetchMethodOptions {
|
|
217
204
|
/**
|
|
218
205
|
* Human-readable name of the API being called.
|
|
219
206
|
*
|
|
@@ -226,7 +213,8 @@ declare interface BaseFetchMethodOptions {
|
|
|
226
213
|
*
|
|
227
214
|
* @remarks
|
|
228
215
|
* This is useful for providing polyfills, mocks, or instrumented fetch
|
|
229
|
-
* implementations.
|
|
216
|
+
* implementations. It is required in runtimes that do not provide
|
|
217
|
+
* `globalThis.fetch`.
|
|
230
218
|
*/
|
|
231
219
|
fetchMethod?: FetchMethod;
|
|
232
220
|
}
|
|
@@ -234,9 +222,9 @@ declare interface BaseFetchMethodOptions {
|
|
|
234
222
|
/**
|
|
235
223
|
* Parameters used when performing a batch profile update.
|
|
236
224
|
*
|
|
237
|
-
* @
|
|
225
|
+
* @public
|
|
238
226
|
*/
|
|
239
|
-
declare interface BatchUpdateProfileParams {
|
|
227
|
+
export declare interface BatchUpdateProfileParams {
|
|
240
228
|
/**
|
|
241
229
|
* Batch of events to process.
|
|
242
230
|
*/
|
|
@@ -244,1406 +232,637 @@ declare interface BatchUpdateProfileParams {
|
|
|
244
232
|
}
|
|
245
233
|
|
|
246
234
|
/**
|
|
247
|
-
*
|
|
235
|
+
* Parameters used when creating a profile.
|
|
248
236
|
*
|
|
249
237
|
* @public
|
|
250
238
|
*/
|
|
251
|
-
export declare
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
medium: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
258
|
-
term: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
259
|
-
content: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
260
|
-
}, z.core.$strip>>;
|
|
261
|
-
locale: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
262
|
-
location: z.ZodMiniOptional<z.ZodMiniObject<{
|
|
263
|
-
coordinates: z.ZodMiniOptional<z.ZodMiniObject<{
|
|
264
|
-
latitude: z.ZodMiniNumber<number>;
|
|
265
|
-
longitude: z.ZodMiniNumber<number>;
|
|
266
|
-
}, z.core.$strip>>;
|
|
267
|
-
city: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
268
|
-
postalCode: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
269
|
-
region: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
270
|
-
regionCode: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
271
|
-
country: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
272
|
-
countryCode: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
273
|
-
continent: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
274
|
-
timezone: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
275
|
-
}, z.core.$strip>>;
|
|
276
|
-
page: z.ZodMiniOptional<z.ZodMiniObject<{
|
|
277
|
-
path: z.ZodMiniString<string>;
|
|
278
|
-
query: z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniString<string>>;
|
|
279
|
-
referrer: z.ZodMiniString<string>;
|
|
280
|
-
search: z.ZodMiniString<string>;
|
|
281
|
-
title: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
282
|
-
url: z.ZodMiniString<string>;
|
|
283
|
-
}, z.core.$catchall<z.ZodMiniJSONSchema>>>;
|
|
284
|
-
screen: z.ZodMiniOptional<z.ZodMiniObject<{
|
|
285
|
-
name: z.ZodMiniString<string>;
|
|
286
|
-
}, z.core.$catchall<z.ZodMiniJSONSchema>>>;
|
|
287
|
-
userAgent: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
288
|
-
componentId: z.ZodMiniString<string>;
|
|
289
|
-
experienceId: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
290
|
-
variantIndex: z.ZodMiniOptional<z.ZodMiniNumber<number>>;
|
|
291
|
-
}, z.core.$strip>;
|
|
239
|
+
export declare interface CreateProfileParams {
|
|
240
|
+
/**
|
|
241
|
+
* Events used to aggregate the profile state.
|
|
242
|
+
*/
|
|
243
|
+
events: ExperienceEventArray;
|
|
244
|
+
}
|
|
292
245
|
|
|
293
246
|
/**
|
|
294
|
-
*
|
|
247
|
+
* Creates a {@link FetchMethod} that combines timeout and retry protection.
|
|
295
248
|
*
|
|
296
|
-
* @
|
|
297
|
-
|
|
298
|
-
declare type ComponentClickBuilderArgs = z.infer<typeof ComponentClickBuilderArgs_2>;
|
|
299
|
-
|
|
300
|
-
/**
|
|
301
|
-
* Arguments for constructing component hover events.
|
|
249
|
+
* @param options - Configuration options for both timeout and retry behavior.
|
|
250
|
+
* @returns A {@link FetchMethod} that applies timeout and retry logic to requests.
|
|
302
251
|
*
|
|
303
|
-
* @
|
|
304
|
-
|
|
305
|
-
export declare type ComponentHoverBuilderArgs = z.infer<typeof ComponentHoverBuilderArgs_2>;
|
|
306
|
-
|
|
307
|
-
declare const ComponentHoverBuilderArgs_2: z.ZodMiniObject<{
|
|
308
|
-
campaign: z.ZodMiniOptional<z.ZodMiniObject<{
|
|
309
|
-
name: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
310
|
-
source: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
311
|
-
medium: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
312
|
-
term: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
313
|
-
content: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
314
|
-
}, z.core.$strip>>;
|
|
315
|
-
locale: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
316
|
-
location: z.ZodMiniOptional<z.ZodMiniObject<{
|
|
317
|
-
coordinates: z.ZodMiniOptional<z.ZodMiniObject<{
|
|
318
|
-
latitude: z.ZodMiniNumber<number>;
|
|
319
|
-
longitude: z.ZodMiniNumber<number>;
|
|
320
|
-
}, z.core.$strip>>;
|
|
321
|
-
city: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
322
|
-
postalCode: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
323
|
-
region: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
324
|
-
regionCode: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
325
|
-
country: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
326
|
-
countryCode: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
327
|
-
continent: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
328
|
-
timezone: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
329
|
-
}, z.core.$strip>>;
|
|
330
|
-
page: z.ZodMiniOptional<z.ZodMiniObject<{
|
|
331
|
-
path: z.ZodMiniString<string>;
|
|
332
|
-
query: z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniString<string>>;
|
|
333
|
-
referrer: z.ZodMiniString<string>;
|
|
334
|
-
search: z.ZodMiniString<string>;
|
|
335
|
-
title: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
336
|
-
url: z.ZodMiniString<string>;
|
|
337
|
-
}, z.core.$catchall<z.ZodMiniJSONSchema>>>;
|
|
338
|
-
screen: z.ZodMiniOptional<z.ZodMiniObject<{
|
|
339
|
-
name: z.ZodMiniString<string>;
|
|
340
|
-
}, z.core.$catchall<z.ZodMiniJSONSchema>>>;
|
|
341
|
-
userAgent: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
342
|
-
componentId: z.ZodMiniString<string>;
|
|
343
|
-
experienceId: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
344
|
-
variantIndex: z.ZodMiniOptional<z.ZodMiniNumber<number>>;
|
|
345
|
-
componentHoverId: z.ZodMiniString<string>;
|
|
346
|
-
hoverDurationMs: z.ZodMiniNumber<number>;
|
|
347
|
-
}, z.core.$strip>;
|
|
348
|
-
|
|
349
|
-
/**
|
|
350
|
-
* Arguments for constructing component hover events.
|
|
252
|
+
* @throws Error
|
|
253
|
+
* Rethrows the original error after logging, including abort errors.
|
|
351
254
|
*
|
|
352
|
-
* @
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
/**
|
|
357
|
-
* Arguments shared by component view, click, and hover events.
|
|
255
|
+
* @remarks
|
|
256
|
+
* The resulting method first wraps the base fetch with a timeout (via
|
|
257
|
+
* {@link createTimeoutFetchMethod}), then applies retry behavior (via
|
|
258
|
+
* {@link createRetryFetchMethod}).
|
|
358
259
|
*
|
|
359
|
-
*
|
|
360
|
-
*/
|
|
361
|
-
export declare type ComponentInteractionBuilderArgsBase = z.infer<typeof ComponentInteractionBuilderArgsBase_2>;
|
|
362
|
-
|
|
363
|
-
declare const ComponentInteractionBuilderArgsBase_2: z.ZodMiniObject<{
|
|
364
|
-
campaign: z.ZodMiniOptional<z.ZodMiniObject<{
|
|
365
|
-
name: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
366
|
-
source: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
367
|
-
medium: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
368
|
-
term: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
369
|
-
content: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
370
|
-
}, z.core.$strip>>;
|
|
371
|
-
locale: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
372
|
-
location: z.ZodMiniOptional<z.ZodMiniObject<{
|
|
373
|
-
coordinates: z.ZodMiniOptional<z.ZodMiniObject<{
|
|
374
|
-
latitude: z.ZodMiniNumber<number>;
|
|
375
|
-
longitude: z.ZodMiniNumber<number>;
|
|
376
|
-
}, z.core.$strip>>;
|
|
377
|
-
city: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
378
|
-
postalCode: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
379
|
-
region: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
380
|
-
regionCode: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
381
|
-
country: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
382
|
-
countryCode: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
383
|
-
continent: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
384
|
-
timezone: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
385
|
-
}, z.core.$strip>>;
|
|
386
|
-
page: z.ZodMiniOptional<z.ZodMiniObject<{
|
|
387
|
-
path: z.ZodMiniString<string>;
|
|
388
|
-
query: z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniString<string>>;
|
|
389
|
-
referrer: z.ZodMiniString<string>;
|
|
390
|
-
search: z.ZodMiniString<string>;
|
|
391
|
-
title: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
392
|
-
url: z.ZodMiniString<string>;
|
|
393
|
-
}, z.core.$catchall<z.ZodMiniJSONSchema>>>;
|
|
394
|
-
screen: z.ZodMiniOptional<z.ZodMiniObject<{
|
|
395
|
-
name: z.ZodMiniString<string>;
|
|
396
|
-
}, z.core.$catchall<z.ZodMiniJSONSchema>>>;
|
|
397
|
-
userAgent: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
398
|
-
componentId: z.ZodMiniString<string>;
|
|
399
|
-
experienceId: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
400
|
-
variantIndex: z.ZodMiniOptional<z.ZodMiniNumber<number>>;
|
|
401
|
-
}, z.core.$strip>;
|
|
402
|
-
|
|
403
|
-
/**
|
|
404
|
-
* Arguments shared by component view, click, and hover events.
|
|
260
|
+
* If an error is thrown during configuration or request execution, it is logged.
|
|
405
261
|
*
|
|
406
|
-
* @
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
*
|
|
262
|
+
* @example
|
|
263
|
+
* ```ts
|
|
264
|
+
* const fetchProtected = createProtectedFetchMethod({
|
|
265
|
+
* apiName: 'Optimization',
|
|
266
|
+
* requestTimeout: 4000,
|
|
267
|
+
* retries: 2,
|
|
268
|
+
* })
|
|
269
|
+
*
|
|
270
|
+
* const response = await fetchProtected('https://example.com/experiences', {
|
|
271
|
+
* method: 'GET',
|
|
272
|
+
* })
|
|
273
|
+
* ```
|
|
412
274
|
*
|
|
413
275
|
* @public
|
|
414
276
|
*/
|
|
415
|
-
export declare
|
|
416
|
-
|
|
417
|
-
declare const ComponentViewBuilderArgs_2: z.ZodMiniObject<{
|
|
418
|
-
campaign: z.ZodMiniOptional<z.ZodMiniObject<{
|
|
419
|
-
name: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
420
|
-
source: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
421
|
-
medium: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
422
|
-
term: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
423
|
-
content: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
424
|
-
}, z.core.$strip>>;
|
|
425
|
-
locale: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
426
|
-
location: z.ZodMiniOptional<z.ZodMiniObject<{
|
|
427
|
-
coordinates: z.ZodMiniOptional<z.ZodMiniObject<{
|
|
428
|
-
latitude: z.ZodMiniNumber<number>;
|
|
429
|
-
longitude: z.ZodMiniNumber<number>;
|
|
430
|
-
}, z.core.$strip>>;
|
|
431
|
-
city: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
432
|
-
postalCode: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
433
|
-
region: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
434
|
-
regionCode: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
435
|
-
country: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
436
|
-
countryCode: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
437
|
-
continent: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
438
|
-
timezone: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
439
|
-
}, z.core.$strip>>;
|
|
440
|
-
page: z.ZodMiniOptional<z.ZodMiniObject<{
|
|
441
|
-
path: z.ZodMiniString<string>;
|
|
442
|
-
query: z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniString<string>>;
|
|
443
|
-
referrer: z.ZodMiniString<string>;
|
|
444
|
-
search: z.ZodMiniString<string>;
|
|
445
|
-
title: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
446
|
-
url: z.ZodMiniString<string>;
|
|
447
|
-
}, z.core.$catchall<z.ZodMiniJSONSchema>>>;
|
|
448
|
-
screen: z.ZodMiniOptional<z.ZodMiniObject<{
|
|
449
|
-
name: z.ZodMiniString<string>;
|
|
450
|
-
}, z.core.$catchall<z.ZodMiniJSONSchema>>>;
|
|
451
|
-
userAgent: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
452
|
-
componentId: z.ZodMiniString<string>;
|
|
453
|
-
experienceId: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
454
|
-
variantIndex: z.ZodMiniOptional<z.ZodMiniNumber<number>>;
|
|
455
|
-
sticky: z.ZodMiniOptional<z.ZodMiniBoolean<boolean>>;
|
|
456
|
-
componentViewId: z.ZodMiniString<string>;
|
|
457
|
-
viewDurationMs: z.ZodMiniNumber<number>;
|
|
458
|
-
}, z.core.$strip>;
|
|
277
|
+
export declare function createProtectedFetchMethod(options: ProtectedFetchMethodOptions): FetchMethod;
|
|
459
278
|
|
|
460
279
|
/**
|
|
461
|
-
*
|
|
280
|
+
* Creates a {@link FetchMethod} that retries failed requests according to the
|
|
281
|
+
* provided configuration.
|
|
282
|
+
*
|
|
283
|
+
* @param options - Configuration options that control retry behavior.
|
|
284
|
+
* @returns A {@link FetchMethod} that automatically retries qualifying failures.
|
|
285
|
+
*
|
|
286
|
+
* @throws Error
|
|
287
|
+
* Thrown when the request cannot be retried and no successful response is obtained.
|
|
288
|
+
*
|
|
289
|
+
* @remarks
|
|
290
|
+
* This wrapper uses a lightweight internal retry loop and an {@link AbortController}
|
|
291
|
+
* to cancel pending requests when a non-retriable error occurs.
|
|
292
|
+
*
|
|
293
|
+
* @example
|
|
294
|
+
* ```ts
|
|
295
|
+
* const fetchWithRetry = createRetryFetchMethod({
|
|
296
|
+
* apiName: 'Optimization',
|
|
297
|
+
* retries: 3,
|
|
298
|
+
* intervalTimeout: 200,
|
|
299
|
+
* onFailedAttempt: ({ attemptNumber, retriesLeft }) => {
|
|
300
|
+
* console.warn(`Attempt ${attemptNumber} failed. Retries left: ${retriesLeft}`)
|
|
301
|
+
* },
|
|
302
|
+
* })
|
|
303
|
+
*
|
|
304
|
+
* const response = await fetchWithRetry('https://example.com', { method: 'GET' })
|
|
305
|
+
* ```
|
|
462
306
|
*
|
|
463
307
|
* @public
|
|
464
308
|
*/
|
|
465
|
-
declare
|
|
309
|
+
export declare function createRetryFetchMethod({ apiName, fetchMethod, intervalTimeout, onFailedAttempt, retries, }?: RetryFetchMethodOptions): FetchMethod;
|
|
466
310
|
|
|
467
311
|
/**
|
|
468
|
-
*
|
|
312
|
+
* Creates a {@link FetchMethod} that aborts requests after a configurable timeout.
|
|
469
313
|
*
|
|
470
|
-
* @
|
|
471
|
-
|
|
472
|
-
declare interface CreateProfileParams {
|
|
473
|
-
/**
|
|
474
|
-
* Events used to aggregate the profile state.
|
|
475
|
-
*/
|
|
476
|
-
events: ExperienceEventArray;
|
|
477
|
-
}
|
|
478
|
-
|
|
479
|
-
/**
|
|
480
|
-
* Default page properties used when no explicit page information is available.
|
|
314
|
+
* @param options - Configuration options controlling timeout behavior.
|
|
315
|
+
* @returns A {@link FetchMethod} that enforces a timeout for each request.
|
|
481
316
|
*
|
|
482
|
-
* @
|
|
317
|
+
* @remarks
|
|
318
|
+
* When a timeout occurs, the request is aborted using an {@link AbortController}.
|
|
319
|
+
* If `onRequestTimeout` is not provided, an error is logged by the package logger.
|
|
320
|
+
*
|
|
321
|
+
* @example
|
|
483
322
|
* ```ts
|
|
484
|
-
* {
|
|
485
|
-
*
|
|
486
|
-
*
|
|
487
|
-
*
|
|
488
|
-
*
|
|
489
|
-
*
|
|
490
|
-
*
|
|
491
|
-
*
|
|
323
|
+
* const fetchWithTimeout = createTimeoutFetchMethod({
|
|
324
|
+
* apiName: 'Optimization',
|
|
325
|
+
* requestTimeout: 5000,
|
|
326
|
+
* onRequestTimeout: ({ apiName }) => {
|
|
327
|
+
* console.warn(`${apiName} request timed out`)
|
|
328
|
+
* },
|
|
329
|
+
* })
|
|
330
|
+
*
|
|
331
|
+
* const response = await fetchWithTimeout('https://example.com', { method: 'GET' })
|
|
492
332
|
* ```
|
|
493
333
|
*
|
|
494
|
-
* @
|
|
495
|
-
* Values are required by the API; values may not be `undefined`. Empty values are valid.
|
|
334
|
+
* @see {@link TimeoutFetchMethodOptions}
|
|
496
335
|
*
|
|
497
336
|
* @public
|
|
498
337
|
*/
|
|
499
|
-
export declare
|
|
500
|
-
path: string;
|
|
501
|
-
query: {};
|
|
502
|
-
referrer: string;
|
|
503
|
-
search: string;
|
|
504
|
-
title: string;
|
|
505
|
-
url: string;
|
|
506
|
-
};
|
|
338
|
+
export declare function createTimeoutFetchMethod({ apiName, fetchMethod, onRequestTimeout, requestTimeout, }?: TimeoutFetchMethodOptions): FetchMethod;
|
|
507
339
|
|
|
508
340
|
/**
|
|
509
|
-
*
|
|
341
|
+
* Default base URL for the Experience API.
|
|
342
|
+
*
|
|
343
|
+
* @public
|
|
344
|
+
*/
|
|
345
|
+
export declare const EXPERIENCE_BASE_URL = "https://experience.ninetailed.co/";
|
|
346
|
+
|
|
347
|
+
/**
|
|
348
|
+
* Client for interacting with the Experience API.
|
|
510
349
|
*
|
|
511
350
|
* @remarks
|
|
512
|
-
* This
|
|
513
|
-
*
|
|
514
|
-
*
|
|
351
|
+
* This client is responsible for reading and mutating Ninetailed profiles
|
|
352
|
+
* using the Experience API.
|
|
353
|
+
*
|
|
354
|
+
* @example
|
|
355
|
+
* ```ts
|
|
356
|
+
* const client = new ExperienceApiClient({
|
|
357
|
+
* clientId: 'org-id',
|
|
358
|
+
* environment: 'main',
|
|
359
|
+
* })
|
|
360
|
+
*
|
|
361
|
+
* const profile = await client.getProfile('profile-id')
|
|
362
|
+
* ```
|
|
515
363
|
*
|
|
516
|
-
*
|
|
364
|
+
* Extends `ApiClientBase`.
|
|
517
365
|
*
|
|
518
366
|
* @public
|
|
519
367
|
*/
|
|
520
|
-
export declare class
|
|
521
|
-
/**
|
|
522
|
-
* Application metadata attached to each event.
|
|
523
|
-
*
|
|
524
|
-
* @internal
|
|
525
|
-
*/
|
|
526
|
-
app?: App;
|
|
368
|
+
export declare class ExperienceApiClient extends ApiClientBase {
|
|
527
369
|
/**
|
|
528
|
-
*
|
|
529
|
-
*
|
|
530
|
-
* @internal
|
|
531
|
-
*/
|
|
532
|
-
channel: Channel;
|
|
533
|
-
/**
|
|
534
|
-
* Library metadata attached to each event.
|
|
535
|
-
*
|
|
536
|
-
* @internal
|
|
370
|
+
* Base URL used for Experience API requests.
|
|
537
371
|
*/
|
|
538
|
-
|
|
372
|
+
protected readonly baseUrl: string;
|
|
373
|
+
private readonly enabledFeatures?;
|
|
374
|
+
private readonly ip?;
|
|
375
|
+
private locale?;
|
|
376
|
+
private readonly plainText?;
|
|
377
|
+
private readonly preflight?;
|
|
539
378
|
/**
|
|
540
|
-
*
|
|
379
|
+
* Creates a new {@link ExperienceApiClient} instance.
|
|
541
380
|
*
|
|
542
|
-
* @
|
|
381
|
+
* @param config - Configuration for the Experience API client.
|
|
543
382
|
*/
|
|
544
|
-
|
|
383
|
+
constructor(config: ExperienceApiClientConfig);
|
|
545
384
|
/**
|
|
546
|
-
*
|
|
385
|
+
* Update the default Experience API locale used when request options omit `locale`.
|
|
547
386
|
*
|
|
548
|
-
* @
|
|
549
|
-
*/
|
|
550
|
-
getPageProperties: () => Page;
|
|
551
|
-
/**
|
|
552
|
-
* Function that provides the user agent string when available.
|
|
387
|
+
* @param locale - Next default Experience API locale.
|
|
553
388
|
*
|
|
554
|
-
* @
|
|
389
|
+
* @public
|
|
555
390
|
*/
|
|
556
|
-
|
|
391
|
+
setLocale(locale: ExperienceApiClientRequestOptions['locale']): void;
|
|
557
392
|
/**
|
|
558
|
-
*
|
|
393
|
+
* Retrieves a profile by ID.
|
|
559
394
|
*
|
|
560
|
-
* @param
|
|
395
|
+
* @param id - The profile ID to retrieve.
|
|
396
|
+
* @param options - Optional request options. `preflight` and `plainText` are not allowed here.
|
|
397
|
+
* @returns The current optimization data for the profile.
|
|
561
398
|
*
|
|
562
|
-
* @
|
|
563
|
-
*
|
|
564
|
-
* repeatedly reconfiguring the builder.
|
|
399
|
+
* @throws Error
|
|
400
|
+
* Thrown if `id` is missing or the underlying request fails.
|
|
565
401
|
*
|
|
566
402
|
* @example
|
|
567
403
|
* ```ts
|
|
568
|
-
* const
|
|
569
|
-
*
|
|
570
|
-
* library: { name: '@contentful/optimization-sdk', version: '1.0.0' },
|
|
404
|
+
* const profile = await client.getProfile('profile-id', {
|
|
405
|
+
* locale: 'en-US',
|
|
571
406
|
* })
|
|
572
407
|
* ```
|
|
573
408
|
*/
|
|
574
|
-
|
|
409
|
+
getProfile(id: string, options?: Omit<ExperienceApiClientRequestOptions, 'preflight' | 'plainText'>): Promise<OptimizationData>;
|
|
575
410
|
/**
|
|
576
|
-
*
|
|
411
|
+
* Sends a POST request to mutate a profile or profiles.
|
|
577
412
|
*
|
|
578
|
-
* @param
|
|
579
|
-
* @returns
|
|
413
|
+
* @param request - Mutation request options including URL, body, and request options.
|
|
414
|
+
* @returns The raw {@link Response} from the underlying fetch.
|
|
580
415
|
*
|
|
581
|
-
* @
|
|
582
|
-
* This method is used internally by the specific event-builder methods
|
|
583
|
-
* (e.g. {@link EventBuilder.buildPageView}).
|
|
416
|
+
* @internal
|
|
584
417
|
*/
|
|
585
|
-
|
|
586
|
-
private buildEntryComponentBase;
|
|
418
|
+
private makeProfileMutationRequest;
|
|
587
419
|
/**
|
|
588
|
-
*
|
|
420
|
+
* Creates a profile and returns the resulting optimization data.
|
|
589
421
|
*
|
|
590
|
-
* @param
|
|
591
|
-
* @
|
|
422
|
+
* @param params - Parameters containing the events to aggregate into the profile.
|
|
423
|
+
* @param options - Optional request options.
|
|
424
|
+
* @returns The optimization data for the newly created profile.
|
|
425
|
+
*
|
|
426
|
+
* @remarks
|
|
427
|
+
* The returned profile ID can be used for subsequent update requests.
|
|
592
428
|
*
|
|
593
429
|
* @example
|
|
594
430
|
* ```ts
|
|
595
|
-
* const
|
|
596
|
-
*
|
|
597
|
-
* componentViewId: crypto.randomUUID(),
|
|
598
|
-
* experienceId: 'personalization-123',
|
|
599
|
-
* variantIndex: 1,
|
|
600
|
-
* viewDurationMs: 1_000,
|
|
431
|
+
* const data = await client.createProfile({
|
|
432
|
+
* events: [{ type: 'identify', userId: 'user-123' }],
|
|
601
433
|
* })
|
|
602
434
|
* ```
|
|
603
|
-
*
|
|
604
|
-
* @public
|
|
605
435
|
*/
|
|
606
|
-
|
|
436
|
+
createProfile({ events }: CreateProfileParams, options?: ExperienceApiClientRequestOptions): Promise<OptimizationData>;
|
|
607
437
|
/**
|
|
608
|
-
*
|
|
438
|
+
* Updates an existing profile with the given profile ID.
|
|
439
|
+
*
|
|
440
|
+
* @param params - Parameters including the profile ID and events.
|
|
441
|
+
* @param options - Optional request options.
|
|
442
|
+
* @returns The updated optimization data for the profile.
|
|
609
443
|
*
|
|
610
|
-
* @
|
|
611
|
-
*
|
|
444
|
+
* @throws Error
|
|
445
|
+
* Thrown if `profileId` is missing or the underlying request fails.
|
|
612
446
|
*
|
|
613
447
|
* @example
|
|
614
448
|
* ```ts
|
|
615
|
-
* const
|
|
616
|
-
*
|
|
617
|
-
*
|
|
618
|
-
* variantIndex: 1,
|
|
449
|
+
* const data = await client.updateProfile({
|
|
450
|
+
* profileId: 'profile-id',
|
|
451
|
+
* events: [{ type: 'track', event: 'viewed_video' }],
|
|
619
452
|
* })
|
|
620
453
|
* ```
|
|
621
|
-
*
|
|
622
|
-
* @public
|
|
623
454
|
*/
|
|
624
|
-
|
|
455
|
+
updateProfile({ profileId, events }: UpdateProfileParams, options?: ExperienceApiClientRequestOptions): Promise<OptimizationData>;
|
|
625
456
|
/**
|
|
626
|
-
*
|
|
457
|
+
* Creates or updates a profile depending on whether a `profileId` is provided.
|
|
627
458
|
*
|
|
628
|
-
* @param
|
|
629
|
-
* @
|
|
459
|
+
* @param params - Parameters including optional profile ID and events.
|
|
460
|
+
* @param options - Optional request options.
|
|
461
|
+
* @returns The resulting optimization data.
|
|
630
462
|
*
|
|
631
463
|
* @example
|
|
632
464
|
* ```ts
|
|
633
|
-
*
|
|
634
|
-
*
|
|
635
|
-
* componentHoverId: crypto.randomUUID(),
|
|
636
|
-
* experienceId: 'personalization-123',
|
|
637
|
-
* hoverDurationMs: 1_000,
|
|
638
|
-
* variantIndex: 1,
|
|
639
|
-
* })
|
|
640
|
-
* ```
|
|
465
|
+
* // Create
|
|
466
|
+
* await client.upsertProfile({ events })
|
|
641
467
|
*
|
|
642
|
-
*
|
|
468
|
+
* // Update
|
|
469
|
+
* await client.upsertProfile({ profileId: 'profile-id', events })
|
|
470
|
+
* ```
|
|
643
471
|
*/
|
|
644
|
-
|
|
472
|
+
upsertProfile({ profileId, events }: UpsertProfileParams, options?: ExperienceApiClientRequestOptions): Promise<OptimizationData>;
|
|
645
473
|
/**
|
|
646
|
-
*
|
|
474
|
+
* Sends multiple events to the Ninetailed Experience API to upsert many profiles.
|
|
647
475
|
*
|
|
648
|
-
* @param
|
|
649
|
-
* @
|
|
476
|
+
* @param params - Parameters containing the batch of events.
|
|
477
|
+
* @param options - Optional request options.
|
|
478
|
+
* @returns The list of profiles affected by the batch operation.
|
|
650
479
|
*
|
|
651
480
|
* @remarks
|
|
652
|
-
*
|
|
653
|
-
*
|
|
481
|
+
* Batch requests must contain at least one event. Every event must contain
|
|
482
|
+
* an anonymous ID. Profiles will be created or updated according to the
|
|
483
|
+
* anonymous ID.
|
|
484
|
+
*
|
|
485
|
+
* This method is intended to be used from server environments.
|
|
654
486
|
*
|
|
655
487
|
* @example
|
|
656
488
|
* ```ts
|
|
657
|
-
* const
|
|
658
|
-
*
|
|
659
|
-
*
|
|
660
|
-
*
|
|
661
|
-
*
|
|
489
|
+
* const profiles = await client.upsertManyProfiles({
|
|
490
|
+
* events: [
|
|
491
|
+
* { anonymousId: 'anon-1', type: 'identify', ... },
|
|
492
|
+
* { anonymousId: 'anon-2', type: 'identify', ... },
|
|
493
|
+
* ],
|
|
662
494
|
* })
|
|
663
495
|
* ```
|
|
664
|
-
*
|
|
665
|
-
* @public
|
|
666
496
|
*/
|
|
667
|
-
|
|
497
|
+
upsertManyProfiles({ events }: BatchUpdateProfileParams, options?: ExperienceApiClientRequestOptions): Promise<BatchExperienceResponseData['profiles']>;
|
|
668
498
|
/**
|
|
669
|
-
*
|
|
499
|
+
* Constructs a request URL with query parameters derived from request options.
|
|
670
500
|
*
|
|
671
|
-
* @param
|
|
672
|
-
* @
|
|
501
|
+
* @param path - Path relative to the Experience API base URL.
|
|
502
|
+
* @param options - Request options that can influence query parameters.
|
|
503
|
+
* @returns The fully constructed URL as a string.
|
|
673
504
|
*
|
|
674
|
-
* @
|
|
675
|
-
* - Traits are merged by the API; only specified properties may be overwritten.
|
|
676
|
-
* - The User ID is consumer-specified and should not contain the value of any
|
|
677
|
-
* ID generated by the Experience API.
|
|
678
|
-
*
|
|
679
|
-
* @example
|
|
680
|
-
* ```ts
|
|
681
|
-
* const event = builder.buildIdentify({
|
|
682
|
-
* userId: 'user-123',
|
|
683
|
-
* traits: { plan: 'pro' },
|
|
684
|
-
* })
|
|
685
|
-
* ```
|
|
686
|
-
*
|
|
687
|
-
* @public
|
|
505
|
+
* @internal
|
|
688
506
|
*/
|
|
689
|
-
|
|
507
|
+
private constructUrl;
|
|
690
508
|
/**
|
|
691
|
-
*
|
|
692
|
-
*
|
|
693
|
-
* @param args - Optional {@link PageViewBuilderArgs} overrides for the page view event.
|
|
694
|
-
* @returns A {@link PageViewEvent} payload.
|
|
695
|
-
*
|
|
696
|
-
* @remarks
|
|
697
|
-
* Page properties are created by merging:
|
|
698
|
-
* 1. The base page properties from {@link EventBuilderConfig.getPageProperties}, and
|
|
699
|
-
* 2. The partial `properties` argument passed in.
|
|
509
|
+
* Constructs request headers based on request options and default configuration.
|
|
700
510
|
*
|
|
701
|
-
*
|
|
511
|
+
* @param options - Request options that can influence headers.
|
|
512
|
+
* @returns A record of HTTP headers to send with the request.
|
|
702
513
|
*
|
|
703
|
-
* @
|
|
704
|
-
* ```ts
|
|
705
|
-
* const event = builder.buildPageView({
|
|
706
|
-
* properties: {
|
|
707
|
-
* title: 'Homepage',
|
|
708
|
-
* },
|
|
709
|
-
* })
|
|
710
|
-
* ```
|
|
711
|
-
*
|
|
712
|
-
* @public
|
|
514
|
+
* @internal
|
|
713
515
|
*/
|
|
714
|
-
|
|
516
|
+
private constructHeaders;
|
|
715
517
|
/**
|
|
716
|
-
*
|
|
518
|
+
* Constructs the `options` section of the request body for profile mutations.
|
|
717
519
|
*
|
|
718
|
-
* @param
|
|
719
|
-
* @returns
|
|
520
|
+
* @param options - Request options that can specify enabled features.
|
|
521
|
+
* @returns Experience API body options including feature flags.
|
|
720
522
|
*
|
|
721
|
-
* @
|
|
722
|
-
* ```ts
|
|
723
|
-
* const event = builder.buildScreenView({
|
|
724
|
-
* name: 'home',
|
|
725
|
-
* properties: {
|
|
726
|
-
* title: 'Home Screen',
|
|
727
|
-
* },
|
|
728
|
-
* })
|
|
729
|
-
* ```
|
|
730
|
-
*
|
|
731
|
-
* @public
|
|
523
|
+
* @internal
|
|
732
524
|
*/
|
|
733
|
-
|
|
525
|
+
private readonly constructBodyOptions;
|
|
734
526
|
/**
|
|
735
|
-
*
|
|
527
|
+
* Construct and validate the singular Experience mutation request payload.
|
|
736
528
|
*
|
|
737
|
-
* @param
|
|
738
|
-
* @
|
|
529
|
+
* @param events - Events for the Experience API to evaluate.
|
|
530
|
+
* @param options - Request options that can contribute body options.
|
|
531
|
+
* @returns Validated singular Experience request body.
|
|
739
532
|
*
|
|
740
|
-
* @
|
|
741
|
-
* ```ts
|
|
742
|
-
* const event = builder.buildTrack({
|
|
743
|
-
* event: 'button_clicked',
|
|
744
|
-
* properties: { id: 'primary-cta', location: 'hero' },
|
|
745
|
-
* })
|
|
746
|
-
* ```
|
|
747
|
-
*
|
|
748
|
-
* @public
|
|
533
|
+
* @internal
|
|
749
534
|
*/
|
|
750
|
-
|
|
535
|
+
private constructExperienceRequestBody;
|
|
751
536
|
}
|
|
752
537
|
|
|
753
538
|
/**
|
|
754
|
-
* Configuration
|
|
755
|
-
*
|
|
756
|
-
* @remarks
|
|
757
|
-
* The configuration is typically provided by the host application to adapt
|
|
758
|
-
* event payloads to the runtime environment (browser, framework, etc.).
|
|
539
|
+
* Configuration for {@link ExperienceApiClient}.
|
|
759
540
|
*
|
|
760
|
-
* @
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
*
|
|
767
|
-
* getPageProperties: () => ({
|
|
768
|
-
* path: window.location.pathname,
|
|
769
|
-
* url: window.location.href,
|
|
770
|
-
* title: document.title,
|
|
771
|
-
* query: {},
|
|
772
|
-
* referrer: document.referrer,
|
|
773
|
-
* search: window.location.search,
|
|
774
|
-
* }),
|
|
775
|
-
* })
|
|
776
|
-
* ```
|
|
541
|
+
* @public
|
|
542
|
+
*/
|
|
543
|
+
export declare interface ExperienceApiClientConfig extends ApiConfig, ExperienceApiClientRequestOptions {
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
/**
|
|
547
|
+
* Options that control how requests to the Experience API are handled.
|
|
777
548
|
*
|
|
778
549
|
* @public
|
|
779
550
|
*/
|
|
780
|
-
export declare interface
|
|
551
|
+
export declare interface ExperienceApiClientRequestOptions {
|
|
781
552
|
/**
|
|
782
|
-
*
|
|
553
|
+
* Enabled features (for example, `"ip-enrichment"`) for the API to use for this request.
|
|
783
554
|
*
|
|
784
555
|
* @remarks
|
|
785
|
-
* When
|
|
556
|
+
* When omitted, the API can apply a default set of features.
|
|
786
557
|
*/
|
|
787
|
-
|
|
558
|
+
enabledFeatures?: Feature[];
|
|
788
559
|
/**
|
|
789
|
-
*
|
|
560
|
+
* IP address to override the API behavior for IP analysis.
|
|
790
561
|
*
|
|
791
|
-
* @
|
|
562
|
+
* @remarks
|
|
563
|
+
* Commonly used in ESR or SSR environments, as the API otherwise uses
|
|
564
|
+
* the server IP.
|
|
792
565
|
*/
|
|
793
|
-
|
|
566
|
+
ip?: string;
|
|
794
567
|
/**
|
|
795
|
-
*
|
|
568
|
+
* Experience API `locale` query parameter used to translate profile location fields such as
|
|
569
|
+
* `location.city` and `location.country`.
|
|
796
570
|
*
|
|
797
571
|
* @remarks
|
|
798
|
-
*
|
|
572
|
+
* When omitted, the API can use a server-side default.
|
|
799
573
|
*/
|
|
800
|
-
|
|
574
|
+
locale?: string;
|
|
801
575
|
/**
|
|
802
|
-
*
|
|
576
|
+
* When `true`, sends performance-critical endpoints in plain text.
|
|
803
577
|
*
|
|
804
578
|
* @remarks
|
|
805
|
-
*
|
|
806
|
-
*
|
|
807
|
-
* precedence.
|
|
808
|
-
*
|
|
809
|
-
* @returns The locale string (e.g. `'en-US'`), or `undefined` if unavailable.
|
|
579
|
+
* The Ninetailed API accepts certain endpoints in plain text to avoid CORS
|
|
580
|
+
* preflight requests, which can improve performance in browser environments.
|
|
810
581
|
*/
|
|
811
|
-
|
|
582
|
+
plainText?: boolean;
|
|
812
583
|
/**
|
|
813
|
-
*
|
|
584
|
+
* When `true`, instructs the API to aggregate a new profile state but not store it.
|
|
814
585
|
*
|
|
815
586
|
* @remarks
|
|
816
|
-
*
|
|
817
|
-
*
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
587
|
+
* This is commonly used in ESR or SSR environments where you want to
|
|
588
|
+
* preview the result without persisting changes.
|
|
589
|
+
*/
|
|
590
|
+
preflight?: boolean;
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
/**
|
|
594
|
+
* Feature flags supported by the Experience API.
|
|
595
|
+
*
|
|
596
|
+
* @internal
|
|
597
|
+
*/
|
|
598
|
+
export declare type Feature = 'ip-enrichment' | 'location';
|
|
599
|
+
|
|
600
|
+
/**
|
|
601
|
+
* Signature of a fetch method used by the API clients.
|
|
602
|
+
*
|
|
603
|
+
* @param url - The request URL.
|
|
604
|
+
* @param init - Initialization options passed to `fetch`.
|
|
605
|
+
* @returns A promise that resolves with the {@link Response}.
|
|
606
|
+
*
|
|
607
|
+
* @remarks
|
|
608
|
+
* This abstraction allows the underlying implementation to be replaced,
|
|
609
|
+
* for example in tests or different runtime environments.
|
|
610
|
+
*
|
|
611
|
+
* @example
|
|
612
|
+
* ```ts
|
|
613
|
+
* const method: FetchMethod = async (input, init) => {
|
|
614
|
+
* return fetch(input, init)
|
|
615
|
+
* }
|
|
616
|
+
* ```
|
|
617
|
+
*
|
|
618
|
+
* @public
|
|
619
|
+
*/
|
|
620
|
+
export declare type FetchInput = string | Request;
|
|
621
|
+
|
|
622
|
+
export declare type FetchMethod = (input: FetchInput, init?: RequestInit) => Promise<Response>;
|
|
623
|
+
|
|
624
|
+
/**
|
|
625
|
+
* Options passed to callback functions invoked by fetch wrappers.
|
|
626
|
+
*
|
|
627
|
+
* @remarks
|
|
628
|
+
* Not all fields are guaranteed to be present in all callback scenarios.
|
|
629
|
+
*
|
|
630
|
+
* @public
|
|
631
|
+
*/
|
|
632
|
+
export declare interface FetchMethodCallbackOptions {
|
|
633
|
+
/**
|
|
634
|
+
* Name of the API associated with the request.
|
|
822
635
|
*/
|
|
823
|
-
|
|
636
|
+
apiName?: string;
|
|
824
637
|
/**
|
|
825
|
-
*
|
|
826
|
-
*
|
|
827
|
-
* @returns A user agent string, or `undefined` if unavailable.
|
|
638
|
+
* Error that caused the callback to be invoked, if available.
|
|
828
639
|
*/
|
|
829
|
-
|
|
640
|
+
error?: Error;
|
|
641
|
+
/**
|
|
642
|
+
* The current attempt number (for retry callbacks).
|
|
643
|
+
*/
|
|
644
|
+
attemptNumber?: number;
|
|
645
|
+
/**
|
|
646
|
+
* Number of retry attempts remaining (for retry callbacks).
|
|
647
|
+
*/
|
|
648
|
+
retriesLeft?: number;
|
|
830
649
|
}
|
|
831
650
|
|
|
832
651
|
/**
|
|
833
|
-
*
|
|
652
|
+
* Properties that can be shared between global and per-client API configuration.
|
|
834
653
|
*
|
|
835
654
|
* @public
|
|
836
655
|
*/
|
|
837
|
-
export declare
|
|
656
|
+
export declare type GlobalApiConfigProperties = 'environment' | 'fetchOptions' | 'clientId';
|
|
838
657
|
|
|
839
658
|
/**
|
|
840
|
-
*
|
|
659
|
+
* Default base URL for the Insights ingest API.
|
|
660
|
+
*
|
|
661
|
+
* @public
|
|
662
|
+
*/
|
|
663
|
+
export declare const INSIGHTS_BASE_URL = "https://ingest.insights.ninetailed.co/";
|
|
664
|
+
|
|
665
|
+
/**
|
|
666
|
+
* Client for sending analytics and insights events to the Ninetailed Insights API.
|
|
841
667
|
*
|
|
842
668
|
* @remarks
|
|
843
|
-
* This client is
|
|
844
|
-
*
|
|
669
|
+
* This client is optimized for sending batched events, optionally using a
|
|
670
|
+
* custom beacon-like sender for last-chance lifecycle delivery.
|
|
845
671
|
*
|
|
846
672
|
* @example
|
|
847
673
|
* ```ts
|
|
848
|
-
* const
|
|
674
|
+
* const insightsClient = new InsightsApiClient({
|
|
849
675
|
* clientId: 'org-id',
|
|
850
676
|
* environment: 'main',
|
|
851
677
|
* })
|
|
852
678
|
*
|
|
853
|
-
*
|
|
679
|
+
* await insightsClient.sendBatchEvents([
|
|
680
|
+
* {
|
|
681
|
+
* profile: { id: 'profile-123', ... },
|
|
682
|
+
* events: [
|
|
683
|
+
* {
|
|
684
|
+
* type: 'track',
|
|
685
|
+
* event: 'button_clicked',
|
|
686
|
+
* properties: { id: 'primary-cta' },
|
|
687
|
+
* },
|
|
688
|
+
* ],
|
|
689
|
+
* }
|
|
690
|
+
* ])
|
|
854
691
|
* ```
|
|
855
692
|
*
|
|
856
|
-
*
|
|
693
|
+
* Extends `ApiClientBase`.
|
|
857
694
|
*
|
|
858
695
|
* @public
|
|
859
696
|
*/
|
|
860
|
-
declare class
|
|
697
|
+
export declare class InsightsApiClient extends ApiClientBase {
|
|
861
698
|
/**
|
|
862
|
-
* Base URL used for
|
|
699
|
+
* Base URL used for Insights API requests.
|
|
863
700
|
*/
|
|
864
701
|
protected readonly baseUrl: string;
|
|
865
|
-
private readonly enabledFeatures?;
|
|
866
|
-
private readonly ip?;
|
|
867
|
-
private readonly locale?;
|
|
868
|
-
private readonly plainText?;
|
|
869
|
-
private readonly preflight?;
|
|
870
702
|
/**
|
|
871
|
-
* Creates a new {@link
|
|
703
|
+
* Creates a new {@link InsightsApiClient} instance.
|
|
872
704
|
*
|
|
873
|
-
* @param config - Configuration for the
|
|
705
|
+
* @param config - Configuration for the Insights API client.
|
|
706
|
+
*
|
|
707
|
+
* @example
|
|
708
|
+
* ```ts
|
|
709
|
+
* const client = new InsightsApiClient({
|
|
710
|
+
* clientId: 'org-id',
|
|
711
|
+
* environment: 'main',
|
|
712
|
+
* })
|
|
713
|
+
* ```
|
|
874
714
|
*/
|
|
875
|
-
constructor(config:
|
|
715
|
+
constructor(config: InsightsApiClientConfig);
|
|
876
716
|
/**
|
|
877
|
-
*
|
|
717
|
+
* Sends batches of insights events to the Ninetailed Insights API.
|
|
878
718
|
*
|
|
879
|
-
* @param
|
|
880
|
-
* @param options - Optional request options
|
|
881
|
-
* @returns
|
|
719
|
+
* @param batches - Array of event batches to send.
|
|
720
|
+
* @param options - Optional request options, including a per-call `beacon` sender.
|
|
721
|
+
* @returns `true` when the event batch is successfully queued by the beacon
|
|
722
|
+
* sender or a direct request is successfully sent, `false` otherwise.
|
|
882
723
|
*
|
|
883
|
-
* @
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
* @param options - Optional request options.
|
|
908
|
-
* @returns The optimization data for the newly created profile.
|
|
909
|
-
*
|
|
910
|
-
* @remarks
|
|
911
|
-
* The returned profile ID can be used for subsequent update requests.
|
|
912
|
-
*
|
|
913
|
-
* @example
|
|
914
|
-
* ```ts
|
|
915
|
-
* const data = await client.createProfile({
|
|
916
|
-
* events: [{ type: 'identify', userId: 'user-123' }],
|
|
917
|
-
* })
|
|
918
|
-
* ```
|
|
919
|
-
*/
|
|
920
|
-
createProfile({ events }: CreateProfileParams, options?: RequestOptions): Promise<OptimizationData>;
|
|
921
|
-
/**
|
|
922
|
-
* Updates an existing profile with the given profile ID.
|
|
923
|
-
*
|
|
924
|
-
* @param params - Parameters including the profile ID and events.
|
|
925
|
-
* @param options - Optional request options.
|
|
926
|
-
* @returns The updated optimization data for the profile.
|
|
927
|
-
*
|
|
928
|
-
* @throws {@link Error}
|
|
929
|
-
* Thrown if `profileId` is missing or the underlying request fails.
|
|
930
|
-
*
|
|
931
|
-
* @example
|
|
932
|
-
* ```ts
|
|
933
|
-
* const data = await client.updateProfile({
|
|
934
|
-
* profileId: 'profile-id',
|
|
935
|
-
* events: [{ type: 'track', event: 'viewed_video' }],
|
|
936
|
-
* })
|
|
937
|
-
* ```
|
|
938
|
-
*/
|
|
939
|
-
updateProfile({ profileId, events }: UpdateProfileParams, options?: RequestOptions): Promise<OptimizationData>;
|
|
940
|
-
/**
|
|
941
|
-
* Creates or updates a profile depending on whether a `profileId` is provided.
|
|
942
|
-
*
|
|
943
|
-
* @param params - Parameters including optional profile ID and events.
|
|
944
|
-
* @param options - Optional request options.
|
|
945
|
-
* @returns The resulting optimization data.
|
|
946
|
-
*
|
|
947
|
-
* @example
|
|
948
|
-
* ```ts
|
|
949
|
-
* // Create
|
|
950
|
-
* await client.upsertProfile({ events })
|
|
951
|
-
*
|
|
952
|
-
* // Update
|
|
953
|
-
* await client.upsertProfile({ profileId: 'profile-id', events })
|
|
954
|
-
* ```
|
|
955
|
-
*/
|
|
956
|
-
upsertProfile({ profileId, events }: UpsertProfileParams, options?: RequestOptions): Promise<OptimizationData>;
|
|
957
|
-
/**
|
|
958
|
-
* Sends multiple events to the Ninetailed Experience API to upsert many profiles.
|
|
959
|
-
*
|
|
960
|
-
* @param params - Parameters containing the batch of events.
|
|
961
|
-
* @param options - Optional request options.
|
|
962
|
-
* @returns The list of profiles affected by the batch operation.
|
|
963
|
-
*
|
|
964
|
-
* @remarks
|
|
965
|
-
* Batch requests must contain at least one event. Every event must contain
|
|
966
|
-
* an anonymous ID. Profiles will be created or updated according to the
|
|
967
|
-
* anonymous ID.
|
|
968
|
-
*
|
|
969
|
-
* This method is intended to be used from server environments.
|
|
970
|
-
*
|
|
971
|
-
* @example
|
|
972
|
-
* ```ts
|
|
973
|
-
* const profiles = await client.upsertManyProfiles({
|
|
974
|
-
* events: [
|
|
975
|
-
* { anonymousId: 'anon-1', type: 'identify', ... },
|
|
976
|
-
* { anonymousId: 'anon-2', type: 'identify', ... },
|
|
977
|
-
* ],
|
|
978
|
-
* })
|
|
979
|
-
* ```
|
|
980
|
-
*/
|
|
981
|
-
upsertManyProfiles({ events }: BatchUpdateProfileParams, options?: RequestOptions): Promise<BatchExperienceResponseData['profiles']>;
|
|
982
|
-
/**
|
|
983
|
-
* Constructs a request URL with query parameters derived from request options.
|
|
984
|
-
*
|
|
985
|
-
* @param path - Path relative to the Experience API base URL.
|
|
986
|
-
* @param options - Request options that may influence query parameters.
|
|
987
|
-
* @returns The fully constructed URL as a string.
|
|
988
|
-
*
|
|
989
|
-
* @internal
|
|
990
|
-
*/
|
|
991
|
-
private constructUrl;
|
|
992
|
-
/**
|
|
993
|
-
* Constructs request headers based on request options and default configuration.
|
|
994
|
-
*
|
|
995
|
-
* @param options - Request options that may influence headers.
|
|
996
|
-
* @returns A record of HTTP headers to send with the request.
|
|
997
|
-
*
|
|
998
|
-
* @internal
|
|
999
|
-
*/
|
|
1000
|
-
private constructHeaders;
|
|
1001
|
-
/**
|
|
1002
|
-
* Constructs the `options` section of the request body for profile mutations.
|
|
1003
|
-
*
|
|
1004
|
-
* @param options - Request options that may specify enabled features.
|
|
1005
|
-
* @returns Experience API body options including feature flags.
|
|
1006
|
-
*
|
|
1007
|
-
* @internal
|
|
1008
|
-
*/
|
|
1009
|
-
private readonly constructBodyOptions;
|
|
1010
|
-
/**
|
|
1011
|
-
* Construct and validate the singular Experience mutation request payload.
|
|
1012
|
-
*
|
|
1013
|
-
* @param events - Events that should be evaluated by the Experience API.
|
|
1014
|
-
* @param options - Request options that may contribute body options.
|
|
1015
|
-
* @returns Validated singular Experience request body.
|
|
1016
|
-
*
|
|
1017
|
-
* @internal
|
|
1018
|
-
*/
|
|
1019
|
-
private constructExperienceRequestBody;
|
|
1020
|
-
}
|
|
1021
|
-
|
|
1022
|
-
/**
|
|
1023
|
-
* Configuration for {@link ExperienceApiClient}.
|
|
1024
|
-
*
|
|
1025
|
-
* @public
|
|
1026
|
-
*/
|
|
1027
|
-
export declare interface ExperienceApiClientConfig extends ApiConfig, RequestOptions {
|
|
1028
|
-
}
|
|
1029
|
-
|
|
1030
|
-
/**
|
|
1031
|
-
* Feature flags supported by the Experience API.
|
|
1032
|
-
*
|
|
1033
|
-
* @internal
|
|
1034
|
-
*/
|
|
1035
|
-
declare type Feature = 'ip-enrichment' | 'location';
|
|
1036
|
-
|
|
1037
|
-
/**
|
|
1038
|
-
* Signature of a fetch method used by the API clients.
|
|
1039
|
-
*
|
|
1040
|
-
* @param url - The request URL.
|
|
1041
|
-
* @param init - Initialization options passed to `fetch`.
|
|
1042
|
-
* @returns A promise that resolves with the {@link Response}.
|
|
1043
|
-
*
|
|
1044
|
-
* @remarks
|
|
1045
|
-
* This abstraction allows the underlying implementation to be replaced,
|
|
1046
|
-
* for example in tests or different runtime environments.
|
|
1047
|
-
*
|
|
1048
|
-
* @example
|
|
1049
|
-
* ```ts
|
|
1050
|
-
* const method: FetchMethod = async (url, init) => {
|
|
1051
|
-
* return fetch(url, init)
|
|
1052
|
-
* }
|
|
1053
|
-
* ```
|
|
1054
|
-
*
|
|
1055
|
-
* @public
|
|
1056
|
-
*/
|
|
1057
|
-
declare type FetchMethod = (url: string | URL, init: RequestInit) => Promise<Response>;
|
|
1058
|
-
|
|
1059
|
-
/**
|
|
1060
|
-
* Options passed to callback functions invoked by fetch wrappers.
|
|
1061
|
-
*
|
|
1062
|
-
* @remarks
|
|
1063
|
-
* Not all fields are guaranteed to be present in all callback scenarios.
|
|
1064
|
-
*
|
|
1065
|
-
* @public
|
|
1066
|
-
*/
|
|
1067
|
-
declare interface FetchMethodCallbackOptions {
|
|
1068
|
-
/**
|
|
1069
|
-
* Name of the API associated with the request.
|
|
1070
|
-
*/
|
|
1071
|
-
apiName?: string;
|
|
1072
|
-
/**
|
|
1073
|
-
* Error that caused the callback to be invoked, if available.
|
|
1074
|
-
*/
|
|
1075
|
-
error?: Error;
|
|
1076
|
-
/**
|
|
1077
|
-
* The current attempt number (for retry callbacks).
|
|
1078
|
-
*/
|
|
1079
|
-
attemptNumber?: number;
|
|
1080
|
-
/**
|
|
1081
|
-
* Number of retry attempts remaining (for retry callbacks).
|
|
1082
|
-
*/
|
|
1083
|
-
retriesLeft?: number;
|
|
1084
|
-
}
|
|
1085
|
-
|
|
1086
|
-
/**
|
|
1087
|
-
* Properties that may be shared between global and per-client API configuration.
|
|
1088
|
-
*
|
|
1089
|
-
* @public
|
|
1090
|
-
*/
|
|
1091
|
-
export declare type GlobalApiConfigProperties = 'environment' | 'fetchOptions' | 'clientId';
|
|
1092
|
-
|
|
1093
|
-
/**
|
|
1094
|
-
* Arguments for constructing identify events.
|
|
1095
|
-
*
|
|
1096
|
-
* @remarks
|
|
1097
|
-
* Traits are merged by the API; only specified properties may be overwritten.
|
|
1098
|
-
*
|
|
1099
|
-
* @public
|
|
1100
|
-
*/
|
|
1101
|
-
export declare type IdentifyBuilderArgs = z.infer<typeof IdentifyBuilderArgs_2>;
|
|
1102
|
-
|
|
1103
|
-
declare const IdentifyBuilderArgs_2: z.ZodMiniObject<{
|
|
1104
|
-
campaign: z.ZodMiniOptional<z.ZodMiniObject<{
|
|
1105
|
-
name: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
1106
|
-
source: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
1107
|
-
medium: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
1108
|
-
term: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
1109
|
-
content: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
1110
|
-
}, z.core.$strip>>;
|
|
1111
|
-
locale: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
1112
|
-
location: z.ZodMiniOptional<z.ZodMiniObject<{
|
|
1113
|
-
coordinates: z.ZodMiniOptional<z.ZodMiniObject<{
|
|
1114
|
-
latitude: z.ZodMiniNumber<number>;
|
|
1115
|
-
longitude: z.ZodMiniNumber<number>;
|
|
1116
|
-
}, z.core.$strip>>;
|
|
1117
|
-
city: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
1118
|
-
postalCode: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
1119
|
-
region: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
1120
|
-
regionCode: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
1121
|
-
country: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
1122
|
-
countryCode: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
1123
|
-
continent: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
1124
|
-
timezone: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
1125
|
-
}, z.core.$strip>>;
|
|
1126
|
-
page: z.ZodMiniOptional<z.ZodMiniObject<{
|
|
1127
|
-
path: z.ZodMiniString<string>;
|
|
1128
|
-
query: z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniString<string>>;
|
|
1129
|
-
referrer: z.ZodMiniString<string>;
|
|
1130
|
-
search: z.ZodMiniString<string>;
|
|
1131
|
-
title: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
1132
|
-
url: z.ZodMiniString<string>;
|
|
1133
|
-
}, z.core.$catchall<z.ZodMiniJSONSchema>>>;
|
|
1134
|
-
screen: z.ZodMiniOptional<z.ZodMiniObject<{
|
|
1135
|
-
name: z.ZodMiniString<string>;
|
|
1136
|
-
}, z.core.$catchall<z.ZodMiniJSONSchema>>>;
|
|
1137
|
-
userAgent: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
1138
|
-
traits: z.ZodMiniOptional<z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniJSONSchema>>;
|
|
1139
|
-
userId: z.ZodMiniString<string>;
|
|
1140
|
-
}, z.core.$strip>;
|
|
1141
|
-
|
|
1142
|
-
/**
|
|
1143
|
-
* Arguments for constructing identify events.
|
|
1144
|
-
*
|
|
1145
|
-
* @remarks
|
|
1146
|
-
* Traits are merged by the API; only specified properties may be overwritten.
|
|
1147
|
-
*
|
|
1148
|
-
* @public
|
|
1149
|
-
*/
|
|
1150
|
-
declare type IdentifyBuilderArgs = z.infer<typeof IdentifyBuilderArgs_2>;
|
|
1151
|
-
|
|
1152
|
-
/**
|
|
1153
|
-
* Default base URL for the Insights ingest API.
|
|
1154
|
-
*
|
|
1155
|
-
* @public
|
|
1156
|
-
*/
|
|
1157
|
-
export declare const INSIGHTS_BASE_URL = "https://ingest.insights.ninetailed.co/";
|
|
1158
|
-
|
|
1159
|
-
/**
|
|
1160
|
-
* Client for sending analytics and insights events to the Ninetailed Insights API.
|
|
1161
|
-
*
|
|
1162
|
-
* @remarks
|
|
1163
|
-
* This client is optimized for sending batched events, optionally using a
|
|
1164
|
-
* custom beacon-like handler when available.
|
|
1165
|
-
*
|
|
1166
|
-
* @example
|
|
1167
|
-
* ```ts
|
|
1168
|
-
* const insightsClient = new InsightsApiClient({
|
|
1169
|
-
* clientId: 'org-id',
|
|
1170
|
-
* environment: 'main',
|
|
1171
|
-
* })
|
|
1172
|
-
*
|
|
1173
|
-
* await insightsClient.sendBatchEvents([
|
|
1174
|
-
* {
|
|
1175
|
-
* profile: { id: 'profile-123', ... },
|
|
1176
|
-
* events: [
|
|
1177
|
-
* {
|
|
1178
|
-
* type: 'track',
|
|
1179
|
-
* event: 'button_clicked',
|
|
1180
|
-
* properties: { id: 'primary-cta' },
|
|
1181
|
-
* },
|
|
1182
|
-
* ],
|
|
1183
|
-
* }
|
|
1184
|
-
* ])
|
|
1185
|
-
* ```
|
|
1186
|
-
*
|
|
1187
|
-
* @see {@link ApiClientBase}
|
|
1188
|
-
*
|
|
1189
|
-
* @public
|
|
1190
|
-
*/
|
|
1191
|
-
declare class InsightsApiClient extends ApiClientBase {
|
|
1192
|
-
/**
|
|
1193
|
-
* Base URL used for Insights API requests.
|
|
1194
|
-
*/
|
|
1195
|
-
protected readonly baseUrl: string;
|
|
1196
|
-
/**
|
|
1197
|
-
* Optional handler used to enqueue events via the Beacon API or a similar mechanism.
|
|
1198
|
-
*/
|
|
1199
|
-
private readonly beaconHandler;
|
|
1200
|
-
/**
|
|
1201
|
-
* Creates a new {@link InsightsApiClient} instance.
|
|
1202
|
-
*
|
|
1203
|
-
* @param config - Configuration for the Insights API client.
|
|
1204
|
-
*
|
|
1205
|
-
* @example
|
|
1206
|
-
* ```ts
|
|
1207
|
-
* const client = new InsightsApiClient({
|
|
1208
|
-
* clientId: 'org-id',
|
|
1209
|
-
* environment: 'main',
|
|
1210
|
-
* beaconHandler: (url, data) => {
|
|
1211
|
-
* return navigator.sendBeacon(url.toString(), JSON.stringify(data))
|
|
1212
|
-
* },
|
|
1213
|
-
* })
|
|
1214
|
-
* ```
|
|
1215
|
-
*/
|
|
1216
|
-
constructor(config: InsightsApiClientConfig);
|
|
1217
|
-
/**
|
|
1218
|
-
* Sends batches of insights events to the Ninetailed Insights API.
|
|
1219
|
-
*
|
|
1220
|
-
* @param batches - Array of event batches to send.
|
|
1221
|
-
* @param options - Optional request options, including a per-call `beaconHandler`.
|
|
1222
|
-
* @returns `true` when the event batch is successfully queued by the beacon
|
|
1223
|
-
* handler or a direct request is successfully sent, `false` otherwise.
|
|
1224
|
-
*
|
|
1225
|
-
* @remarks
|
|
1226
|
-
* If a `beaconHandler` is provided (either in the method call or in the
|
|
1227
|
-
* client configuration) it will be invoked first. When the handler returns
|
|
1228
|
-
* `true`, the events are considered successfully queued and no network
|
|
1229
|
-
* request is made by this method.
|
|
1230
|
-
*
|
|
1231
|
-
* If the handler is missing or returns `false`, the events are emitted
|
|
1232
|
-
* immediately via `fetch`.
|
|
1233
|
-
*
|
|
1234
|
-
* @example
|
|
1235
|
-
* ```ts
|
|
1236
|
-
* const success = await insightsClient.sendBatchEvents(batches)
|
|
1237
|
-
* ```
|
|
1238
|
-
*
|
|
1239
|
-
* @example
|
|
1240
|
-
* ```ts
|
|
1241
|
-
* // Override beaconHandler for a single call
|
|
1242
|
-
* const success = await insightsClient.sendBatchEvents(batches, {
|
|
1243
|
-
* beaconHandler: (url, data) => {
|
|
1244
|
-
* return navigator.sendBeacon(url.toString(), JSON.stringify(data))
|
|
1245
|
-
* },
|
|
1246
|
-
* })
|
|
1247
|
-
* ```
|
|
1248
|
-
*/
|
|
1249
|
-
sendBatchEvents(batches: BatchInsightsEventArray, options?: RequestOptions_2): Promise<boolean>;
|
|
1250
|
-
}
|
|
1251
|
-
|
|
1252
|
-
/**
|
|
1253
|
-
* Configuration for {@link InsightsApiClient}.
|
|
1254
|
-
*
|
|
1255
|
-
* @public
|
|
1256
|
-
*/
|
|
1257
|
-
export declare interface InsightsApiClientConfig extends ApiConfig, RequestOptions_2 {
|
|
1258
|
-
}
|
|
1259
|
-
|
|
1260
|
-
/**
|
|
1261
|
-
* Arguments for constructing page view events.
|
|
1262
|
-
*
|
|
1263
|
-
* @remarks
|
|
1264
|
-
* Any properties passed here are merged with the base page properties from
|
|
1265
|
-
* {@link EventBuilderConfig.getPageProperties}.
|
|
1266
|
-
*
|
|
1267
|
-
* @public
|
|
1268
|
-
*/
|
|
1269
|
-
export declare type PageViewBuilderArgs = z.infer<typeof PageViewBuilderArgs_2>;
|
|
1270
|
-
|
|
1271
|
-
declare const PageViewBuilderArgs_2: z.ZodMiniObject<{
|
|
1272
|
-
campaign: z.ZodMiniOptional<z.ZodMiniObject<{
|
|
1273
|
-
name: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
1274
|
-
source: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
1275
|
-
medium: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
1276
|
-
term: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
1277
|
-
content: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
1278
|
-
}, z.core.$strip>>;
|
|
1279
|
-
locale: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
1280
|
-
location: z.ZodMiniOptional<z.ZodMiniObject<{
|
|
1281
|
-
coordinates: z.ZodMiniOptional<z.ZodMiniObject<{
|
|
1282
|
-
latitude: z.ZodMiniNumber<number>;
|
|
1283
|
-
longitude: z.ZodMiniNumber<number>;
|
|
1284
|
-
}, z.core.$strip>>;
|
|
1285
|
-
city: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
1286
|
-
postalCode: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
1287
|
-
region: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
1288
|
-
regionCode: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
1289
|
-
country: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
1290
|
-
countryCode: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
1291
|
-
continent: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
1292
|
-
timezone: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
1293
|
-
}, z.core.$strip>>;
|
|
1294
|
-
page: z.ZodMiniOptional<z.ZodMiniObject<{
|
|
1295
|
-
path: z.ZodMiniString<string>;
|
|
1296
|
-
query: z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniString<string>>;
|
|
1297
|
-
referrer: z.ZodMiniString<string>;
|
|
1298
|
-
search: z.ZodMiniString<string>;
|
|
1299
|
-
title: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
1300
|
-
url: z.ZodMiniString<string>;
|
|
1301
|
-
}, z.core.$catchall<z.ZodMiniJSONSchema>>>;
|
|
1302
|
-
screen: z.ZodMiniOptional<z.ZodMiniObject<{
|
|
1303
|
-
name: z.ZodMiniString<string>;
|
|
1304
|
-
}, z.core.$catchall<z.ZodMiniJSONSchema>>>;
|
|
1305
|
-
userAgent: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
1306
|
-
properties: z.ZodMiniOptional<z.ZodMiniObject<{
|
|
1307
|
-
path: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
1308
|
-
query: z.ZodMiniOptional<z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniString<string>>>;
|
|
1309
|
-
referrer: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
1310
|
-
search: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
1311
|
-
title: z.ZodMiniOptional<z.ZodMiniOptional<z.ZodMiniString<string>>>;
|
|
1312
|
-
url: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
1313
|
-
}, z.core.$catchall<z.ZodMiniJSONSchema>>>;
|
|
1314
|
-
}, z.core.$strip>;
|
|
1315
|
-
|
|
1316
|
-
/**
|
|
1317
|
-
* Arguments for constructing page view events.
|
|
1318
|
-
*
|
|
1319
|
-
* @remarks
|
|
1320
|
-
* Any properties passed here are merged with the base page properties from
|
|
1321
|
-
* {@link EventBuilderConfig.getPageProperties}.
|
|
1322
|
-
*
|
|
1323
|
-
* @public
|
|
1324
|
-
*/
|
|
1325
|
-
declare type PageViewBuilderArgs = z.infer<typeof PageViewBuilderArgs_2>;
|
|
1326
|
-
|
|
1327
|
-
/**
|
|
1328
|
-
* Options for {@link createProtectedFetchMethod}, combining timeout and retry behavior.
|
|
1329
|
-
*
|
|
1330
|
-
* @see {@link RetryFetchMethodOptions}
|
|
1331
|
-
* @see {@link TimeoutFetchMethodOptions}
|
|
1332
|
-
*
|
|
1333
|
-
* @public
|
|
1334
|
-
*/
|
|
1335
|
-
declare interface ProtectedFetchMethodOptions extends RetryFetchMethodOptions, TimeoutFetchMethodOptions {
|
|
1336
|
-
}
|
|
1337
|
-
|
|
1338
|
-
/**
|
|
1339
|
-
* Options that control how requests to the Experience API are handled.
|
|
1340
|
-
*
|
|
1341
|
-
* @internal
|
|
1342
|
-
*/
|
|
1343
|
-
declare interface RequestOptions {
|
|
1344
|
-
/**
|
|
1345
|
-
* Enabled features (for example, `"ip-enrichment"`) which the API should use for this request.
|
|
1346
|
-
*
|
|
1347
|
-
* @remarks
|
|
1348
|
-
* When omitted, a default set of features may be applied.
|
|
1349
|
-
*/
|
|
1350
|
-
enabledFeatures?: Feature[];
|
|
1351
|
-
/**
|
|
1352
|
-
* IP address to override the API behavior for IP analysis.
|
|
1353
|
-
*
|
|
1354
|
-
* @remarks
|
|
1355
|
-
* Commonly used in ESR or SSR environments, as the API would otherwise use
|
|
1356
|
-
* the server IP.
|
|
1357
|
-
*/
|
|
1358
|
-
ip?: string;
|
|
1359
|
-
/**
|
|
1360
|
-
* Locale used to translate `location.city` and `location.country`.
|
|
1361
|
-
*
|
|
1362
|
-
* @remarks
|
|
1363
|
-
* When omitted, a server-side default may be used.
|
|
1364
|
-
*/
|
|
1365
|
-
locale?: string;
|
|
1366
|
-
/**
|
|
1367
|
-
* When `true`, sends performance-critical endpoints in plain text.
|
|
1368
|
-
*
|
|
1369
|
-
* @remarks
|
|
1370
|
-
* The Ninetailed API accepts certain endpoints in plain text to avoid CORS
|
|
1371
|
-
* preflight requests, which can improve performance in browser environments.
|
|
1372
|
-
*/
|
|
1373
|
-
plainText?: boolean;
|
|
1374
|
-
/**
|
|
1375
|
-
* When `true`, instructs the API to aggregate a new profile state but not store it.
|
|
1376
|
-
*
|
|
1377
|
-
* @remarks
|
|
1378
|
-
* This is commonly used in ESR or SSR environments where you want to
|
|
1379
|
-
* preview the result without persisting changes.
|
|
1380
|
-
*/
|
|
1381
|
-
preflight?: boolean;
|
|
1382
|
-
}
|
|
1383
|
-
|
|
1384
|
-
/**
|
|
1385
|
-
* Options that control how Insights events are sent.
|
|
1386
|
-
*
|
|
1387
|
-
* @internal
|
|
1388
|
-
*/
|
|
1389
|
-
declare interface RequestOptions_2 {
|
|
1390
|
-
/**
|
|
1391
|
-
* Handler used to enqueue events via the Beacon API or a similar mechanism.
|
|
1392
|
-
*
|
|
1393
|
-
* @param url - Target URL for the batched events.
|
|
1394
|
-
* @param data - Array of batched insights events to be sent.
|
|
1395
|
-
* @returns `true` if the events were successfully queued, `false` otherwise.
|
|
1396
|
-
*
|
|
1397
|
-
* @remarks
|
|
1398
|
-
* When provided, this handler is preferred over direct `fetch` calls. If it
|
|
1399
|
-
* returns `false`, the client falls back to emitting events immediately via
|
|
1400
|
-
* `fetch`.
|
|
1401
|
-
*/
|
|
1402
|
-
beaconHandler?: (url: string | URL, data: BatchInsightsEventArray) => boolean;
|
|
1403
|
-
}
|
|
1404
|
-
|
|
1405
|
-
/**
|
|
1406
|
-
* Configuration options for {@link createRetryFetchMethod}.
|
|
1407
|
-
*
|
|
1408
|
-
* @public
|
|
1409
|
-
*/
|
|
1410
|
-
declare interface RetryFetchMethodOptions extends BaseFetchMethodOptions {
|
|
1411
|
-
/**
|
|
1412
|
-
* Delay (in milliseconds) between retry attempts.
|
|
1413
|
-
*
|
|
1414
|
-
* @defaultValue `0`
|
|
1415
|
-
*/
|
|
1416
|
-
intervalTimeout?: number;
|
|
1417
|
-
/**
|
|
1418
|
-
* Callback invoked whenever a retry attempt fails.
|
|
1419
|
-
*
|
|
1420
|
-
* @param options - Information about the failed attempt.
|
|
1421
|
-
*
|
|
1422
|
-
* @remarks
|
|
1423
|
-
* This callback is invoked with additional metadata such as the attempt
|
|
1424
|
-
* number and the number of retries left.
|
|
1425
|
-
*/
|
|
1426
|
-
onFailedAttempt?: (options: FetchMethodCallbackOptions) => void;
|
|
1427
|
-
/**
|
|
1428
|
-
* Maximum number of retry attempts.
|
|
1429
|
-
*
|
|
1430
|
-
* @defaultValue `1`
|
|
1431
|
-
*/
|
|
1432
|
-
retries?: number;
|
|
1433
|
-
}
|
|
1434
|
-
|
|
1435
|
-
/**
|
|
1436
|
-
* Arguments for constructing screen view events.
|
|
1437
|
-
*
|
|
1438
|
-
* @remarks
|
|
1439
|
-
* Any properties passed here are merged with the base screen properties from
|
|
1440
|
-
* {@link EventBuilderConfig.getScreenProperties}.
|
|
1441
|
-
*
|
|
1442
|
-
* @public
|
|
1443
|
-
*/
|
|
1444
|
-
export declare type ScreenViewBuilderArgs = z.infer<typeof ScreenViewBuilderArgs_2>;
|
|
1445
|
-
|
|
1446
|
-
declare const ScreenViewBuilderArgs_2: z.ZodMiniObject<{
|
|
1447
|
-
campaign: z.ZodMiniOptional<z.ZodMiniObject<{
|
|
1448
|
-
name: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
1449
|
-
source: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
1450
|
-
medium: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
1451
|
-
term: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
1452
|
-
content: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
1453
|
-
}, z.core.$strip>>;
|
|
1454
|
-
locale: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
1455
|
-
location: z.ZodMiniOptional<z.ZodMiniObject<{
|
|
1456
|
-
coordinates: z.ZodMiniOptional<z.ZodMiniObject<{
|
|
1457
|
-
latitude: z.ZodMiniNumber<number>;
|
|
1458
|
-
longitude: z.ZodMiniNumber<number>;
|
|
1459
|
-
}, z.core.$strip>>;
|
|
1460
|
-
city: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
1461
|
-
postalCode: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
1462
|
-
region: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
1463
|
-
regionCode: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
1464
|
-
country: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
1465
|
-
countryCode: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
1466
|
-
continent: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
1467
|
-
timezone: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
1468
|
-
}, z.core.$strip>>;
|
|
1469
|
-
page: z.ZodMiniOptional<z.ZodMiniObject<{
|
|
1470
|
-
path: z.ZodMiniString<string>;
|
|
1471
|
-
query: z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniString<string>>;
|
|
1472
|
-
referrer: z.ZodMiniString<string>;
|
|
1473
|
-
search: z.ZodMiniString<string>;
|
|
1474
|
-
title: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
1475
|
-
url: z.ZodMiniString<string>;
|
|
1476
|
-
}, z.core.$catchall<z.ZodMiniJSONSchema>>>;
|
|
1477
|
-
screen: z.ZodMiniOptional<z.ZodMiniObject<{
|
|
1478
|
-
name: z.ZodMiniString<string>;
|
|
1479
|
-
}, z.core.$catchall<z.ZodMiniJSONSchema>>>;
|
|
1480
|
-
userAgent: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
1481
|
-
name: z.ZodMiniString<string>;
|
|
1482
|
-
properties: z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniJSONSchema>;
|
|
1483
|
-
}, z.core.$strip>;
|
|
1484
|
-
|
|
1485
|
-
/**
|
|
1486
|
-
* Arguments for constructing screen view events.
|
|
1487
|
-
*
|
|
1488
|
-
* @remarks
|
|
1489
|
-
* Any properties passed here are merged with the base screen properties from
|
|
1490
|
-
* {@link EventBuilderConfig.getScreenProperties}.
|
|
1491
|
-
*
|
|
1492
|
-
* @public
|
|
1493
|
-
*/
|
|
1494
|
-
declare type ScreenViewBuilderArgs = z.infer<typeof ScreenViewBuilderArgs_2>;
|
|
1495
|
-
|
|
1496
|
-
/**
|
|
1497
|
-
* Configuration options for {@link createTimeoutFetchMethod}.
|
|
1498
|
-
*
|
|
1499
|
-
* @public
|
|
1500
|
-
*/
|
|
1501
|
-
declare interface TimeoutFetchMethodOptions extends BaseFetchMethodOptions {
|
|
1502
|
-
/**
|
|
1503
|
-
* Callback invoked when a request exceeds the configured timeout.
|
|
1504
|
-
*
|
|
1505
|
-
* @param options - Information about the timed-out request.
|
|
1506
|
-
*
|
|
1507
|
-
* @remarks
|
|
1508
|
-
* If this callback is not provided, a default error is logged.
|
|
1509
|
-
*
|
|
1510
|
-
* @see {@link FetchMethodCallbackOptions}
|
|
1511
|
-
*/
|
|
1512
|
-
onRequestTimeout?: (options: FetchMethodCallbackOptions) => void;
|
|
1513
|
-
/**
|
|
1514
|
-
* Maximum time (in milliseconds) to wait for a response before aborting the request.
|
|
1515
|
-
*
|
|
1516
|
-
* @defaultValue `3000`
|
|
1517
|
-
*/
|
|
1518
|
-
requestTimeout?: number;
|
|
1519
|
-
}
|
|
1520
|
-
|
|
1521
|
-
/**
|
|
1522
|
-
* Arguments for constructing track events.
|
|
1523
|
-
*
|
|
1524
|
-
* @public
|
|
1525
|
-
*/
|
|
1526
|
-
export declare type TrackBuilderArgs = z.infer<typeof TrackBuilderArgs_2>;
|
|
724
|
+
* @remarks
|
|
725
|
+
* If a `beacon` sender is provided, it will be invoked first with the
|
|
726
|
+
* serialized request body. When the sender returns `true`, the events are
|
|
727
|
+
* considered successfully queued and no network request is made by this
|
|
728
|
+
* method.
|
|
729
|
+
*
|
|
730
|
+
* If the sender is missing, returns `false`, or throws, the events are
|
|
731
|
+
* emitted immediately via `fetch`.
|
|
732
|
+
*
|
|
733
|
+
* @example
|
|
734
|
+
* ```ts
|
|
735
|
+
* const success = await insightsClient.sendBatchEvents(batches)
|
|
736
|
+
* ```
|
|
737
|
+
*
|
|
738
|
+
* @example
|
|
739
|
+
* ```ts
|
|
740
|
+
* // Use Beacon for a last-chance lifecycle flush
|
|
741
|
+
* const success = await insightsClient.sendBatchEvents(batches, {
|
|
742
|
+
* beacon: (url, body) => navigator.sendBeacon(url, body),
|
|
743
|
+
* })
|
|
744
|
+
* ```
|
|
745
|
+
*/
|
|
746
|
+
sendBatchEvents(batches: BatchInsightsEventArray, options?: InsightsApiClientRequestOptions): Promise<boolean>;
|
|
747
|
+
}
|
|
1527
748
|
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
}, z.core.$strip>>;
|
|
1536
|
-
locale: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
1537
|
-
location: z.ZodMiniOptional<z.ZodMiniObject<{
|
|
1538
|
-
coordinates: z.ZodMiniOptional<z.ZodMiniObject<{
|
|
1539
|
-
latitude: z.ZodMiniNumber<number>;
|
|
1540
|
-
longitude: z.ZodMiniNumber<number>;
|
|
1541
|
-
}, z.core.$strip>>;
|
|
1542
|
-
city: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
1543
|
-
postalCode: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
1544
|
-
region: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
1545
|
-
regionCode: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
1546
|
-
country: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
1547
|
-
countryCode: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
1548
|
-
continent: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
1549
|
-
timezone: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
1550
|
-
}, z.core.$strip>>;
|
|
1551
|
-
page: z.ZodMiniOptional<z.ZodMiniObject<{
|
|
1552
|
-
path: z.ZodMiniString<string>;
|
|
1553
|
-
query: z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniString<string>>;
|
|
1554
|
-
referrer: z.ZodMiniString<string>;
|
|
1555
|
-
search: z.ZodMiniString<string>;
|
|
1556
|
-
title: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
1557
|
-
url: z.ZodMiniString<string>;
|
|
1558
|
-
}, z.core.$catchall<z.ZodMiniJSONSchema>>>;
|
|
1559
|
-
screen: z.ZodMiniOptional<z.ZodMiniObject<{
|
|
1560
|
-
name: z.ZodMiniString<string>;
|
|
1561
|
-
}, z.core.$catchall<z.ZodMiniJSONSchema>>>;
|
|
1562
|
-
userAgent: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
1563
|
-
event: z.ZodMiniString<string>;
|
|
1564
|
-
properties: z.ZodMiniOptional<z.ZodMiniPrefault<z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniJSONSchema>>>;
|
|
1565
|
-
}, z.core.$strip>;
|
|
749
|
+
/**
|
|
750
|
+
* Configuration for {@link InsightsApiClient}.
|
|
751
|
+
*
|
|
752
|
+
* @public
|
|
753
|
+
*/
|
|
754
|
+
export declare interface InsightsApiClientConfig extends ApiConfig {
|
|
755
|
+
}
|
|
1566
756
|
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
757
|
+
/**
|
|
758
|
+
* Options that control how Insights events are sent.
|
|
759
|
+
*
|
|
760
|
+
* @public
|
|
761
|
+
*/
|
|
762
|
+
export declare interface InsightsApiClientRequestOptions {
|
|
763
|
+
/**
|
|
764
|
+
* Sender used to enqueue serialized events via the Beacon API or a similar mechanism.
|
|
765
|
+
*
|
|
766
|
+
* @param url - Target URL for the batched events.
|
|
767
|
+
* @param body - Serialized batched insights events to be sent.
|
|
768
|
+
* @returns `true` if the events were successfully queued, `false` otherwise.
|
|
769
|
+
*
|
|
770
|
+
* @remarks
|
|
771
|
+
* This option is intended for last-chance lifecycle delivery. If it returns
|
|
772
|
+
* `false` or throws, the client falls back to emitting events immediately via
|
|
773
|
+
* `fetch` with `keepalive`.
|
|
774
|
+
*/
|
|
775
|
+
beacon?: (url: string, body: string) => boolean;
|
|
776
|
+
}
|
|
1573
777
|
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
778
|
+
/**
|
|
779
|
+
* Options for {@link createProtectedFetchMethod}, combining timeout and retry behavior.
|
|
780
|
+
*
|
|
781
|
+
* @see {@link RetryFetchMethodOptions}
|
|
782
|
+
* @see {@link TimeoutFetchMethodOptions}
|
|
783
|
+
*
|
|
784
|
+
* @public
|
|
785
|
+
*/
|
|
786
|
+
export declare interface ProtectedFetchMethodOptions extends RetryFetchMethodOptions, TimeoutFetchMethodOptions {
|
|
787
|
+
}
|
|
1580
788
|
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
url: z.ZodMiniString<string>;
|
|
1611
|
-
}, z.core.$catchall<z.ZodMiniJSONSchema>>>;
|
|
1612
|
-
screen: z.ZodMiniOptional<z.ZodMiniObject<{
|
|
1613
|
-
name: z.ZodMiniString<string>;
|
|
1614
|
-
}, z.core.$catchall<z.ZodMiniJSONSchema>>>;
|
|
1615
|
-
userAgent: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
1616
|
-
}, z.core.$strip>;
|
|
789
|
+
/**
|
|
790
|
+
* Configuration options for {@link createRetryFetchMethod}.
|
|
791
|
+
*
|
|
792
|
+
* @public
|
|
793
|
+
*/
|
|
794
|
+
export declare interface RetryFetchMethodOptions extends BaseFetchMethodOptions {
|
|
795
|
+
/**
|
|
796
|
+
* Delay (in milliseconds) between retry attempts.
|
|
797
|
+
*
|
|
798
|
+
* @defaultValue `0`
|
|
799
|
+
*/
|
|
800
|
+
intervalTimeout?: number;
|
|
801
|
+
/**
|
|
802
|
+
* Callback invoked whenever a retry attempt fails.
|
|
803
|
+
*
|
|
804
|
+
* @param options - Information about the failed attempt.
|
|
805
|
+
*
|
|
806
|
+
* @remarks
|
|
807
|
+
* This callback is invoked with additional metadata such as the attempt
|
|
808
|
+
* number and the number of retries left.
|
|
809
|
+
*/
|
|
810
|
+
onFailedAttempt?: (options: FetchMethodCallbackOptions) => void;
|
|
811
|
+
/**
|
|
812
|
+
* Maximum number of retry attempts.
|
|
813
|
+
*
|
|
814
|
+
* @defaultValue `1`
|
|
815
|
+
*/
|
|
816
|
+
retries?: number;
|
|
817
|
+
}
|
|
1617
818
|
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
819
|
+
/**
|
|
820
|
+
* Configuration options for {@link createTimeoutFetchMethod}.
|
|
821
|
+
*
|
|
822
|
+
* @public
|
|
823
|
+
*/
|
|
824
|
+
export declare interface TimeoutFetchMethodOptions extends BaseFetchMethodOptions {
|
|
825
|
+
/**
|
|
826
|
+
* Callback invoked when a request exceeds the configured timeout.
|
|
827
|
+
*
|
|
828
|
+
* @param options - Information about the timed-out request.
|
|
829
|
+
*
|
|
830
|
+
* @remarks
|
|
831
|
+
* If this callback is not provided, a default error is logged.
|
|
832
|
+
*
|
|
833
|
+
* @see {@link FetchMethodCallbackOptions}
|
|
834
|
+
*/
|
|
835
|
+
onRequestTimeout?: (options: FetchMethodCallbackOptions) => void;
|
|
836
|
+
/**
|
|
837
|
+
* Maximum time (in milliseconds) to wait for a response before aborting the request.
|
|
838
|
+
*
|
|
839
|
+
* @defaultValue `3000`
|
|
840
|
+
*/
|
|
841
|
+
requestTimeout?: number;
|
|
842
|
+
}
|
|
1624
843
|
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
844
|
+
/**
|
|
845
|
+
* Parameters used when updating an existing profile.
|
|
846
|
+
*
|
|
847
|
+
* @public
|
|
848
|
+
*/
|
|
849
|
+
export declare interface UpdateProfileParams extends CreateProfileParams {
|
|
850
|
+
/**
|
|
851
|
+
* ID of the profile to update.
|
|
852
|
+
*/
|
|
853
|
+
profileId: string;
|
|
854
|
+
}
|
|
1636
855
|
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
856
|
+
/**
|
|
857
|
+
* Parameters used when creating or updating a profile.
|
|
858
|
+
*
|
|
859
|
+
* @public
|
|
860
|
+
*/
|
|
861
|
+
export declare interface UpsertProfileParams extends CreateProfileParams {
|
|
862
|
+
/**
|
|
863
|
+
* Optional ID of the profile; when omitted, a new profile is created.
|
|
864
|
+
*/
|
|
865
|
+
profileId?: string;
|
|
866
|
+
}
|
|
1648
867
|
|
|
1649
|
-
|
|
868
|
+
export { }
|