@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/dist/index.d.mts 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
- * Personalization and Analytics products.
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 personalization and analytics use cases.
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
- * personalization: {
27
+ * experience: {
41
28
  * // experience-specific overrides
42
29
  * },
43
- * analytics: {
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 personalization and experience-related operations.
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 analytics and insights-related operations.
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
- * should not be treated as part of the public API surface.
76
+ * must not be treated as part of the public API surface.
90
77
  *
91
- * Concrete API clients should extend this class to inherit consistent logging
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 personalization (Experience) API client.
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
- personalization?: Omit<ExperienceApiClientConfig, GlobalApiConfigProperties>;
154
+ experience?: Omit<ExperienceApiClientConfig, GlobalApiConfigProperties>;
168
155
  /**
169
- * Configuration for the analytics (Insights) API client.
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
- analytics?: Omit<InsightsApiClientConfig, GlobalApiConfigProperties>;
162
+ insights?: Omit<InsightsApiClientConfig, GlobalApiConfigProperties>;
176
163
  }
177
164
 
178
165
  /**
179
- * Configuration options for API clients extending {@link ApiClientBase}.
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
- * @internal
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
- * Arguments for constructing component click events.
235
+ * Parameters used when creating a profile.
248
236
  *
249
237
  * @public
250
238
  */
251
- export declare type ComponentClickBuilderArgs = z.infer<typeof ComponentClickBuilderArgs_2>;
252
-
253
- declare const ComponentClickBuilderArgs_2: z.ZodMiniObject<{
254
- campaign: z.ZodMiniOptional<z.ZodMiniObject<{
255
- name: z.ZodMiniOptional<z.ZodMiniString<string>>;
256
- source: z.ZodMiniOptional<z.ZodMiniString<string>>;
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
- * Arguments for constructing component click events.
247
+ * Creates a {@link FetchMethod} that combines timeout and retry protection.
295
248
  *
296
- * @public
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
- * @public
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
- * @public
353
- */
354
- declare type ComponentHoverBuilderArgs = z.infer<typeof ComponentHoverBuilderArgs_2>;
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
- * @public
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
- * @public
407
- */
408
- declare type ComponentInteractionBuilderArgsBase = z.infer<typeof ComponentInteractionBuilderArgsBase_2>;
409
-
410
- /**
411
- * Arguments for constructing component view events.
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 type ComponentViewBuilderArgs = z.infer<typeof ComponentViewBuilderArgs_2>;
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
- * Arguments for constructing component view events.
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 type ComponentViewBuilderArgs = z.infer<typeof ComponentViewBuilderArgs_2>;
309
+ export declare function createRetryFetchMethod({ apiName, fetchMethod, intervalTimeout, onFailedAttempt, retries, }?: RetryFetchMethodOptions): FetchMethod;
466
310
 
467
311
  /**
468
- * Parameters used when creating a profile.
312
+ * Creates a {@link FetchMethod} that aborts requests after a configurable timeout.
469
313
  *
470
- * @internal
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
- * @defaultValue
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
- * path: '',
486
- * query: {},
487
- * referrer: '',
488
- * search: '',
489
- * title: '',
490
- * url: '',
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
- * @remarks
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 const DEFAULT_PAGE_PROPERTIES: {
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
- * Helper class for building analytics and personalization events.
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 class coordinates configuration and argument validation to produce
513
- * strongly-typed event payloads compatible with
514
- * `@contentful/optimization-api-schemas`.
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
- * @see {@link EventBuilderConfig}
364
+ * Extends `ApiClientBase`.
517
365
  *
518
366
  * @public
519
367
  */
520
- export declare class EventBuilder {
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
- * Channel value attached to each event.
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
- library: Library;
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
- * Function that provides the locale when available.
379
+ * Creates a new {@link ExperienceApiClient} instance.
541
380
  *
542
- * @internal
381
+ * @param config - Configuration for the Experience API client.
543
382
  */
544
- getLocale: () => string | undefined;
383
+ constructor(config: ExperienceApiClientConfig);
545
384
  /**
546
- * Function that provides baseline page properties.
385
+ * Update the default Experience API locale used when request options omit `locale`.
547
386
  *
548
- * @internal
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
- * @internal
389
+ * @public
555
390
  */
556
- getUserAgent: () => string | undefined;
391
+ setLocale(locale: ExperienceApiClientRequestOptions['locale']): void;
557
392
  /**
558
- * Creates a new {@link EventBuilder} instance.
393
+ * Retrieves a profile by ID.
559
394
  *
560
- * @param config - Configuration used to customize event payloads.
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
- * @remarks
563
- * Callers are expected to reuse a single instance when possible to avoid
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 builder = new EventBuilder({
569
- * channel: 'web',
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
- constructor(config: EventBuilderConfig);
409
+ getProfile(id: string, options?: Omit<ExperienceApiClientRequestOptions, 'preflight' | 'plainText'>): Promise<OptimizationData>;
575
410
  /**
576
- * Builds the universal event properties shared across all event types.
411
+ * Sends a POST request to mutate a profile or profiles.
577
412
  *
578
- * @param args - Arguments overriding the default context values.
579
- * @returns A fully populated {@link UniversalEventProperties} object.
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
- * @remarks
582
- * This method is used internally by the specific event-builder methods
583
- * (e.g. {@link EventBuilder.buildPageView}).
416
+ * @internal
584
417
  */
585
- protected buildUniversalEventProperties({ campaign, locale, location, page, screen, userAgent, }: UniversalEventBuilderArgs): UniversalEventProperties;
586
- private buildEntryComponentBase;
418
+ private makeProfileMutationRequest;
587
419
  /**
588
- * Builds a component view event payload for a Contentful entry-based component.
420
+ * Creates a profile and returns the resulting optimization data.
589
421
  *
590
- * @param args - {@link ComponentViewBuilderArgs} arguments describing the component view.
591
- * @returns A {@link ComponentViewEvent} describing the view.
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 event = builder.buildComponentView({
596
- * componentId: 'entry-123',
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
- buildComponentView(args: ComponentViewBuilderArgs): ComponentViewEvent;
436
+ createProfile({ events }: CreateProfileParams, options?: ExperienceApiClientRequestOptions): Promise<OptimizationData>;
607
437
  /**
608
- * Builds a component click event payload for a Contentful entry-based component.
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
- * @param args - {@link ComponentClickBuilderArgs} arguments describing the component click.
611
- * @returns A {@link ComponentClickEvent} describing the click.
444
+ * @throws Error
445
+ * Thrown if `profileId` is missing or the underlying request fails.
612
446
  *
613
447
  * @example
614
448
  * ```ts
615
- * const event = builder.buildComponentClick({
616
- * componentId: 'entry-123',
617
- * experienceId: 'personalization-123',
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
- buildComponentClick(args: ComponentClickBuilderArgs): ComponentClickEvent;
455
+ updateProfile({ profileId, events }: UpdateProfileParams, options?: ExperienceApiClientRequestOptions): Promise<OptimizationData>;
625
456
  /**
626
- * Builds a component hover event payload for a Contentful entry-based component.
457
+ * Creates or updates a profile depending on whether a `profileId` is provided.
627
458
  *
628
- * @param args - {@link ComponentHoverBuilderArgs} arguments describing the component hover.
629
- * @returns A {@link ComponentHoverEvent} describing the hover.
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
- * const event = builder.buildComponentHover({
634
- * componentId: 'entry-123',
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
- * @public
468
+ * // Update
469
+ * await client.upsertProfile({ profileId: 'profile-id', events })
470
+ * ```
643
471
  */
644
- buildComponentHover(args: ComponentHoverBuilderArgs): ComponentHoverEvent;
472
+ upsertProfile({ profileId, events }: UpsertProfileParams, options?: ExperienceApiClientRequestOptions): Promise<OptimizationData>;
645
473
  /**
646
- * Builds a component view event payload for a Custom Flag component.
474
+ * Sends multiple events to the Ninetailed Experience API to upsert many profiles.
647
475
  *
648
- * @param args - {@link ComponentViewBuilderArgs} arguments describing the Custom Flag view.
649
- * @returns A {@link ComponentViewEvent} describing the view.
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
- * This is a specialized variant of {@link EventBuilder.buildComponentView}
653
- * that sets `componentType` to `'Variable'`.
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 event = builder.buildFlagView({
658
- * componentId: 'feature-flag-key',
659
- * componentViewId: crypto.randomUUID(),
660
- * experienceId: 'personalization-123',
661
- * viewDurationMs: 1_000,
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
- buildFlagView(args: ComponentViewBuilderArgs): ComponentViewEvent;
497
+ upsertManyProfiles({ events }: BatchUpdateProfileParams, options?: ExperienceApiClientRequestOptions): Promise<BatchExperienceResponseData['profiles']>;
668
498
  /**
669
- * Builds an identify event payload to associate a user ID with traits.
499
+ * Constructs a request URL with query parameters derived from request options.
670
500
  *
671
- * @param args - {@link IdentifyBuilderArgs} arguments describing the identified user.
672
- * @returns An {@link IdentifyEvent} payload.
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
- * @remarks
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
- buildIdentify(args: IdentifyBuilderArgs): IdentifyEvent;
507
+ private constructUrl;
690
508
  /**
691
- * Builds a page view event payload.
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
- * The title always falls back to {@link DEFAULT_PAGE_PROPERTIES}.title when undefined.
511
+ * @param options - Request options that can influence headers.
512
+ * @returns A record of HTTP headers to send with the request.
702
513
  *
703
- * @example
704
- * ```ts
705
- * const event = builder.buildPageView({
706
- * properties: {
707
- * title: 'Homepage',
708
- * },
709
- * })
710
- * ```
711
- *
712
- * @public
514
+ * @internal
713
515
  */
714
- buildPageView(args?: PageViewBuilderArgs): PageViewEvent;
516
+ private constructHeaders;
715
517
  /**
716
- * Builds a screen view event payload.
518
+ * Constructs the `options` section of the request body for profile mutations.
717
519
  *
718
- * @param args - {@link ScreenViewBuilderArgs} arguments for the screen view event.
719
- * @returns A {@link ScreenViewEvent} payload.
520
+ * @param options - Request options that can specify enabled features.
521
+ * @returns Experience API body options including feature flags.
720
522
  *
721
- * @example
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
- buildScreenView(args: ScreenViewBuilderArgs): ScreenViewEvent;
525
+ private readonly constructBodyOptions;
734
526
  /**
735
- * Builds a track event payload for arbitrary user actions.
527
+ * Construct and validate the singular Experience mutation request payload.
736
528
  *
737
- * @param args - {@link TrackBuilderArgs} arguments describing the tracked event.
738
- * @returns A {@link TrackEvent} payload.
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
- * @example
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
- buildTrack(args: TrackBuilderArgs): TrackEvent_2;
535
+ private constructExperienceRequestBody;
751
536
  }
752
537
 
753
538
  /**
754
- * Configuration options for creating an {@link EventBuilder} instance.
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
- * @example
761
- * ```ts
762
- * const builder = new EventBuilder({
763
- * app: { name: 'my-app', version: '1.0.0' },
764
- * channel: 'web',
765
- * library: { name: '@contentful/optimization-sdk', version: '1.2.3' },
766
- * getLocale: () => navigator.language,
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 EventBuilderConfig {
551
+ export declare interface ExperienceApiClientRequestOptions {
781
552
  /**
782
- * The application definition used to attribute events to a specific consumer app.
553
+ * Enabled features (for example, `"ip-enrichment"`) for the API to use for this request.
783
554
  *
784
555
  * @remarks
785
- * When not provided, events will not contain app metadata in their context.
556
+ * When omitted, the API can apply a default set of features.
786
557
  */
787
- app?: App;
558
+ enabledFeatures?: Feature[];
788
559
  /**
789
- * The channel that identifies where events originate from (e.g. web, mobile).
560
+ * IP address to override the API behavior for IP analysis.
790
561
  *
791
- * @see {@link Channel}
562
+ * @remarks
563
+ * Commonly used in ESR or SSR environments, as the API otherwise uses
564
+ * the server IP.
792
565
  */
793
- channel: Channel;
566
+ ip?: string;
794
567
  /**
795
- * The client library metadata that is attached to all events.
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
- * This is typically used to record the library name and version.
572
+ * When omitted, the API can use a server-side default.
799
573
  */
800
- library: Library;
574
+ locale?: string;
801
575
  /**
802
- * Function used to resolve the locale for outgoing events.
576
+ * When `true`, sends performance-critical endpoints in plain text.
803
577
  *
804
578
  * @remarks
805
- * If not provided, the builder falls back to the default `'en-US'`. Locale
806
- * values supplied directly as arguments to event builder methods take
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
- getLocale?: () => string | undefined;
582
+ plainText?: boolean;
812
583
  /**
813
- * Function that returns the current page properties.
584
+ * When `true`, instructs the API to aggregate a new profile state but not store it.
814
585
  *
815
586
  * @remarks
816
- * Page properties are currently added to the context of all events, as well
817
- * as the `properties` of the page event. When specified, all properties of
818
- * the `Page` type are required, but may contain empty values.
819
- *
820
- * @returns A {@link Page} object containing information about the current page.
821
- * @see {@link Page}
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
- getPageProperties?: () => Page;
636
+ apiName?: string;
824
637
  /**
825
- * Function used to obtain the current user agent string when applicable.
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
- getUserAgent?: () => string | undefined;
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
- * Default base URL for the Experience API.
652
+ * Properties that can be shared between global and per-client API configuration.
834
653
  *
835
654
  * @public
836
655
  */
837
- export declare const EXPERIENCE_BASE_URL = "https://experience.ninetailed.co/";
656
+ export declare type GlobalApiConfigProperties = 'environment' | 'fetchOptions' | 'clientId';
838
657
 
839
658
  /**
840
- * Client for interacting with the Experience API.
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 responsible for reading and mutating Ninetailed profiles
844
- * using the Experience API.
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 client = new ExperienceApiClient({
674
+ * const insightsClient = new InsightsApiClient({
849
675
  * clientId: 'org-id',
850
676
  * environment: 'main',
851
677
  * })
852
678
  *
853
- * const profile = await client.getProfile('profile-id')
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
- * @see {@link ApiClientBase}
693
+ * Extends `ApiClientBase`.
857
694
  *
858
695
  * @public
859
696
  */
860
- declare class ExperienceApiClient extends ApiClientBase {
697
+ export declare class InsightsApiClient extends ApiClientBase {
861
698
  /**
862
- * Base URL used for Experience API requests.
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 ExperienceApiClient} instance.
703
+ * Creates a new {@link InsightsApiClient} instance.
872
704
  *
873
- * @param config - Configuration for the Experience API client.
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: ExperienceApiClientConfig);
715
+ constructor(config: InsightsApiClientConfig);
876
716
  /**
877
- * Retrieves a profile by ID.
717
+ * Sends batches of insights events to the Ninetailed Insights API.
878
718
  *
879
- * @param id - The profile ID to retrieve.
880
- * @param options - Optional request options. `preflight` and `plainText` are not allowed here.
881
- * @returns The current optimization data for the profile.
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
- * @throws {@link Error}
884
- * Thrown if `id` is missing or the underlying request fails.
885
- *
886
- * @example
887
- * ```ts
888
- * const profile = await client.getProfile('profile-id', {
889
- * locale: 'en-US',
890
- * })
891
- * ```
892
- */
893
- getProfile(id: string, options?: Omit<RequestOptions, 'preflight' | 'plainText'>): Promise<OptimizationData>;
894
- /**
895
- * Sends a POST request to mutate a profile or profiles.
896
- *
897
- * @param request - Mutation request options including URL, body, and request options.
898
- * @returns The raw {@link Response} from the underlying fetch.
899
- *
900
- * @internal
901
- */
902
- private makeProfileMutationRequest;
903
- /**
904
- * Creates a profile and returns the resulting optimization data.
905
- *
906
- * @param params - Parameters containing the events to aggregate into the profile.
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
- declare const TrackBuilderArgs_2: z.ZodMiniObject<{
1529
- campaign: z.ZodMiniOptional<z.ZodMiniObject<{
1530
- name: z.ZodMiniOptional<z.ZodMiniString<string>>;
1531
- source: z.ZodMiniOptional<z.ZodMiniString<string>>;
1532
- medium: z.ZodMiniOptional<z.ZodMiniString<string>>;
1533
- term: z.ZodMiniOptional<z.ZodMiniString<string>>;
1534
- content: z.ZodMiniOptional<z.ZodMiniString<string>>;
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
- * Arguments for constructing track events.
1569
- *
1570
- * @public
1571
- */
1572
- declare type TrackBuilderArgs = z.infer<typeof TrackBuilderArgs_2>;
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
- * Arguments used to construct the universal (shared) portion of all events.
1576
- *
1577
- * @public
1578
- */
1579
- export declare type UniversalEventBuilderArgs = z.infer<typeof UniversalEventBuilderArgs_2>;
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
- declare const UniversalEventBuilderArgs_2: z.ZodMiniObject<{
1582
- campaign: z.ZodMiniOptional<z.ZodMiniObject<{
1583
- name: z.ZodMiniOptional<z.ZodMiniString<string>>;
1584
- source: z.ZodMiniOptional<z.ZodMiniString<string>>;
1585
- medium: z.ZodMiniOptional<z.ZodMiniString<string>>;
1586
- term: z.ZodMiniOptional<z.ZodMiniString<string>>;
1587
- content: z.ZodMiniOptional<z.ZodMiniString<string>>;
1588
- }, z.core.$strip>>;
1589
- locale: z.ZodMiniOptional<z.ZodMiniString<string>>;
1590
- location: z.ZodMiniOptional<z.ZodMiniObject<{
1591
- coordinates: z.ZodMiniOptional<z.ZodMiniObject<{
1592
- latitude: z.ZodMiniNumber<number>;
1593
- longitude: z.ZodMiniNumber<number>;
1594
- }, z.core.$strip>>;
1595
- city: z.ZodMiniOptional<z.ZodMiniString<string>>;
1596
- postalCode: z.ZodMiniOptional<z.ZodMiniString<string>>;
1597
- region: z.ZodMiniOptional<z.ZodMiniString<string>>;
1598
- regionCode: z.ZodMiniOptional<z.ZodMiniString<string>>;
1599
- country: z.ZodMiniOptional<z.ZodMiniString<string>>;
1600
- countryCode: z.ZodMiniOptional<z.ZodMiniString<string>>;
1601
- continent: z.ZodMiniOptional<z.ZodMiniString<string>>;
1602
- timezone: z.ZodMiniOptional<z.ZodMiniString<string>>;
1603
- }, z.core.$strip>>;
1604
- page: z.ZodMiniOptional<z.ZodMiniObject<{
1605
- path: z.ZodMiniString<string>;
1606
- query: z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniString<string>>;
1607
- referrer: z.ZodMiniString<string>;
1608
- search: z.ZodMiniString<string>;
1609
- title: z.ZodMiniOptional<z.ZodMiniString<string>>;
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
- * Arguments used to construct the universal (shared) portion of all events.
1620
- *
1621
- * @public
1622
- */
1623
- declare type UniversalEventBuilderArgs = z.infer<typeof UniversalEventBuilderArgs_2>;
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
- * Parameters used when updating an existing profile.
1627
- *
1628
- * @internal
1629
- */
1630
- declare interface UpdateProfileParams extends CreateProfileParams {
1631
- /**
1632
- * ID of the profile to update.
1633
- */
1634
- profileId: string;
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
- * Parameters used when creating or updating a profile.
1639
- *
1640
- * @internal
1641
- */
1642
- declare interface UpsertProfileParams extends CreateProfileParams {
1643
- /**
1644
- * Optional ID of the profile; when omitted, a new profile is created.
1645
- */
1646
- profileId?: string;
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
- export { }
868
+ export { }