@contentful/optimization-api-client 0.1.0-alpha10 → 0.1.0-alpha12

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.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
- * 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
  */
@@ -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
  *
@@ -234,9 +221,9 @@ declare interface BaseFetchMethodOptions {
234
221
  /**
235
222
  * Parameters used when performing a batch profile update.
236
223
  *
237
- * @internal
224
+ * @public
238
225
  */
239
- declare interface BatchUpdateProfileParams {
226
+ export declare interface BatchUpdateProfileParams {
240
227
  /**
241
228
  * Batch of events to process.
242
229
  */
@@ -244,1406 +231,635 @@ declare interface BatchUpdateProfileParams {
244
231
  }
245
232
 
246
233
  /**
247
- * Arguments for constructing component click events.
234
+ * Parameters used when creating a profile.
248
235
  *
249
236
  * @public
250
237
  */
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>;
238
+ export declare interface CreateProfileParams {
239
+ /**
240
+ * Events used to aggregate the profile state.
241
+ */
242
+ events: ExperienceEventArray;
243
+ }
292
244
 
293
245
  /**
294
- * Arguments for constructing component click events.
246
+ * Creates a {@link FetchMethod} that combines timeout and retry protection.
295
247
  *
296
- * @public
297
- */
298
- declare type ComponentClickBuilderArgs = z.infer<typeof ComponentClickBuilderArgs_2>;
299
-
300
- /**
301
- * Arguments for constructing component hover events.
248
+ * @param options - Configuration options for both timeout and retry behavior.
249
+ * @returns A {@link FetchMethod} that applies timeout and retry logic to requests.
302
250
  *
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.
251
+ * @throws Error
252
+ * Rethrows the original error after logging, including abort errors.
351
253
  *
352
- * @public
353
- */
354
- declare type ComponentHoverBuilderArgs = z.infer<typeof ComponentHoverBuilderArgs_2>;
355
-
356
- /**
357
- * Arguments shared by component view, click, and hover events.
254
+ * @remarks
255
+ * The resulting method first wraps the base fetch with a timeout (via
256
+ * {@link createTimeoutFetchMethod}), then applies retry behavior (via
257
+ * {@link createRetryFetchMethod}).
358
258
  *
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.
259
+ * If an error is thrown during configuration or request execution, it is logged.
405
260
  *
406
- * @public
407
- */
408
- declare type ComponentInteractionBuilderArgsBase = z.infer<typeof ComponentInteractionBuilderArgsBase_2>;
409
-
410
- /**
411
- * Arguments for constructing component view events.
261
+ * @example
262
+ * ```ts
263
+ * const fetchProtected = createProtectedFetchMethod({
264
+ * apiName: 'Optimization',
265
+ * requestTimeout: 4000,
266
+ * retries: 2,
267
+ * })
268
+ *
269
+ * const response = await fetchProtected('https://example.com/experiences', {
270
+ * method: 'GET',
271
+ * })
272
+ * ```
412
273
  *
413
274
  * @public
414
275
  */
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>;
276
+ export declare function createProtectedFetchMethod(options: ProtectedFetchMethodOptions): FetchMethod;
459
277
 
460
278
  /**
461
- * Arguments for constructing component view events.
279
+ * Creates a {@link FetchMethod} that retries failed requests according to the
280
+ * provided configuration.
281
+ *
282
+ * @param options - Configuration options that control retry behavior.
283
+ * @returns A {@link FetchMethod} that automatically retries qualifying failures.
284
+ *
285
+ * @throws Error
286
+ * Thrown when the request cannot be retried and no successful response is obtained.
287
+ *
288
+ * @remarks
289
+ * This wrapper uses a lightweight internal retry loop and an {@link AbortController}
290
+ * to cancel pending requests when a non-retriable error occurs.
291
+ *
292
+ * @example
293
+ * ```ts
294
+ * const fetchWithRetry = createRetryFetchMethod({
295
+ * apiName: 'Optimization',
296
+ * retries: 3,
297
+ * intervalTimeout: 200,
298
+ * onFailedAttempt: ({ attemptNumber, retriesLeft }) => {
299
+ * console.warn(`Attempt ${attemptNumber} failed. Retries left: ${retriesLeft}`)
300
+ * },
301
+ * })
302
+ *
303
+ * const response = await fetchWithRetry('https://example.com', { method: 'GET' })
304
+ * ```
462
305
  *
463
306
  * @public
464
307
  */
465
- declare type ComponentViewBuilderArgs = z.infer<typeof ComponentViewBuilderArgs_2>;
308
+ export declare function createRetryFetchMethod({ apiName, fetchMethod, intervalTimeout, onFailedAttempt, retries, }?: RetryFetchMethodOptions): FetchMethod;
466
309
 
467
310
  /**
468
- * Parameters used when creating a profile.
311
+ * Creates a {@link FetchMethod} that aborts requests after a configurable timeout.
469
312
  *
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.
313
+ * @param options - Configuration options controlling timeout behavior.
314
+ * @returns A {@link FetchMethod} that enforces a timeout for each request.
481
315
  *
482
- * @defaultValue
316
+ * @remarks
317
+ * When a timeout occurs, the request is aborted using an {@link AbortController}.
318
+ * If `onRequestTimeout` is not provided, an error is logged by the package logger.
319
+ *
320
+ * @example
483
321
  * ```ts
484
- * {
485
- * path: '',
486
- * query: {},
487
- * referrer: '',
488
- * search: '',
489
- * title: '',
490
- * url: '',
491
- * }
322
+ * const fetchWithTimeout = createTimeoutFetchMethod({
323
+ * apiName: 'Optimization',
324
+ * requestTimeout: 5000,
325
+ * onRequestTimeout: ({ apiName }) => {
326
+ * console.warn(`${apiName} request timed out`)
327
+ * },
328
+ * })
329
+ *
330
+ * const response = await fetchWithTimeout('https://example.com', { method: 'GET' })
492
331
  * ```
493
332
  *
494
- * @remarks
495
- * Values are required by the API; values may not be `undefined`. Empty values are valid.
333
+ * @see {@link TimeoutFetchMethodOptions}
496
334
  *
497
335
  * @public
498
336
  */
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
- };
337
+ export declare function createTimeoutFetchMethod({ apiName, fetchMethod, onRequestTimeout, requestTimeout, }?: TimeoutFetchMethodOptions): FetchMethod;
507
338
 
508
339
  /**
509
- * Helper class for building analytics and personalization events.
340
+ * Default base URL for the Experience API.
341
+ *
342
+ * @public
343
+ */
344
+ export declare const EXPERIENCE_BASE_URL = "https://experience.ninetailed.co/";
345
+
346
+ /**
347
+ * Client for interacting with the Experience API.
510
348
  *
511
349
  * @remarks
512
- * This class coordinates configuration and argument validation to produce
513
- * strongly-typed event payloads compatible with
514
- * `@contentful/optimization-api-schemas`.
350
+ * This client is responsible for reading and mutating Ninetailed profiles
351
+ * using the Experience API.
352
+ *
353
+ * @example
354
+ * ```ts
355
+ * const client = new ExperienceApiClient({
356
+ * clientId: 'org-id',
357
+ * environment: 'main',
358
+ * })
359
+ *
360
+ * const profile = await client.getProfile('profile-id')
361
+ * ```
515
362
  *
516
- * @see {@link EventBuilderConfig}
363
+ * Extends `ApiClientBase`.
517
364
  *
518
365
  * @public
519
366
  */
520
- export declare class EventBuilder {
367
+ export declare class ExperienceApiClient extends ApiClientBase {
521
368
  /**
522
- * Application metadata attached to each event.
523
- *
524
- * @internal
525
- */
526
- app?: App;
527
- /**
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
537
- */
538
- library: Library;
539
- /**
540
- * Function that provides the locale when available.
541
- *
542
- * @internal
543
- */
544
- getLocale: () => string | undefined;
545
- /**
546
- * Function that provides baseline page properties.
547
- *
548
- * @internal
369
+ * Base URL used for Experience API requests.
549
370
  */
550
- getPageProperties: () => Page;
371
+ protected readonly baseUrl: string;
372
+ private readonly enabledFeatures?;
373
+ private readonly ip?;
374
+ private readonly locale?;
375
+ private readonly plainText?;
376
+ private readonly preflight?;
551
377
  /**
552
- * Function that provides the user agent string when available.
378
+ * Creates a new {@link ExperienceApiClient} instance.
553
379
  *
554
- * @internal
380
+ * @param config - Configuration for the Experience API client.
555
381
  */
556
- getUserAgent: () => string | undefined;
382
+ constructor(config: ExperienceApiClientConfig);
557
383
  /**
558
- * Creates a new {@link EventBuilder} instance.
384
+ * Retrieves a profile by ID.
559
385
  *
560
- * @param config - Configuration used to customize event payloads.
386
+ * @param id - The profile ID to retrieve.
387
+ * @param options - Optional request options. `preflight` and `plainText` are not allowed here.
388
+ * @returns The current optimization data for the profile.
561
389
  *
562
- * @remarks
563
- * Callers are expected to reuse a single instance when possible to avoid
564
- * repeatedly reconfiguring the builder.
390
+ * @throws Error
391
+ * Thrown if `id` is missing or the underlying request fails.
565
392
  *
566
393
  * @example
567
394
  * ```ts
568
- * const builder = new EventBuilder({
569
- * channel: 'web',
570
- * library: { name: '@contentful/optimization-sdk', version: '1.0.0' },
395
+ * const profile = await client.getProfile('profile-id', {
396
+ * locale: 'en-US',
571
397
  * })
572
398
  * ```
573
399
  */
574
- constructor(config: EventBuilderConfig);
400
+ getProfile(id: string, options?: Omit<ExperienceApiClientRequestOptions, 'preflight' | 'plainText'>): Promise<OptimizationData>;
575
401
  /**
576
- * Builds the universal event properties shared across all event types.
402
+ * Sends a POST request to mutate a profile or profiles.
577
403
  *
578
- * @param args - Arguments overriding the default context values.
579
- * @returns A fully populated {@link UniversalEventProperties} object.
404
+ * @param request - Mutation request options including URL, body, and request options.
405
+ * @returns The raw {@link Response} from the underlying fetch.
580
406
  *
581
- * @remarks
582
- * This method is used internally by the specific event-builder methods
583
- * (e.g. {@link EventBuilder.buildPageView}).
407
+ * @internal
584
408
  */
585
- protected buildUniversalEventProperties({ campaign, locale, location, page, screen, userAgent, }: UniversalEventBuilderArgs): UniversalEventProperties;
586
- private buildEntryComponentBase;
409
+ private makeProfileMutationRequest;
587
410
  /**
588
- * Builds a component view event payload for a Contentful entry-based component.
411
+ * Creates a profile and returns the resulting optimization data.
589
412
  *
590
- * @param args - {@link ComponentViewBuilderArgs} arguments describing the component view.
591
- * @returns A {@link ComponentViewEvent} describing the view.
413
+ * @param params - Parameters containing the events to aggregate into the profile.
414
+ * @param options - Optional request options.
415
+ * @returns The optimization data for the newly created profile.
416
+ *
417
+ * @remarks
418
+ * The returned profile ID can be used for subsequent update requests.
592
419
  *
593
420
  * @example
594
421
  * ```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,
422
+ * const data = await client.createProfile({
423
+ * events: [{ type: 'identify', userId: 'user-123' }],
601
424
  * })
602
425
  * ```
603
- *
604
- * @public
605
426
  */
606
- buildComponentView(args: ComponentViewBuilderArgs): ComponentViewEvent;
427
+ createProfile({ events }: CreateProfileParams, options?: ExperienceApiClientRequestOptions): Promise<OptimizationData>;
607
428
  /**
608
- * Builds a component click event payload for a Contentful entry-based component.
429
+ * Updates an existing profile with the given profile ID.
609
430
  *
610
- * @param args - {@link ComponentClickBuilderArgs} arguments describing the component click.
611
- * @returns A {@link ComponentClickEvent} describing the click.
431
+ * @param params - Parameters including the profile ID and events.
432
+ * @param options - Optional request options.
433
+ * @returns The updated optimization data for the profile.
434
+ *
435
+ * @throws Error
436
+ * Thrown if `profileId` is missing or the underlying request fails.
612
437
  *
613
438
  * @example
614
439
  * ```ts
615
- * const event = builder.buildComponentClick({
616
- * componentId: 'entry-123',
617
- * experienceId: 'personalization-123',
618
- * variantIndex: 1,
440
+ * const data = await client.updateProfile({
441
+ * profileId: 'profile-id',
442
+ * events: [{ type: 'track', event: 'viewed_video' }],
619
443
  * })
620
444
  * ```
621
- *
622
- * @public
623
445
  */
624
- buildComponentClick(args: ComponentClickBuilderArgs): ComponentClickEvent;
446
+ updateProfile({ profileId, events }: UpdateProfileParams, options?: ExperienceApiClientRequestOptions): Promise<OptimizationData>;
625
447
  /**
626
- * Builds a component hover event payload for a Contentful entry-based component.
448
+ * Creates or updates a profile depending on whether a `profileId` is provided.
627
449
  *
628
- * @param args - {@link ComponentHoverBuilderArgs} arguments describing the component hover.
629
- * @returns A {@link ComponentHoverEvent} describing the hover.
450
+ * @param params - Parameters including optional profile ID and events.
451
+ * @param options - Optional request options.
452
+ * @returns The resulting optimization data.
630
453
  *
631
454
  * @example
632
455
  * ```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
- * ```
456
+ * // Create
457
+ * await client.upsertProfile({ events })
641
458
  *
642
- * @public
459
+ * // Update
460
+ * await client.upsertProfile({ profileId: 'profile-id', events })
461
+ * ```
643
462
  */
644
- buildComponentHover(args: ComponentHoverBuilderArgs): ComponentHoverEvent;
463
+ upsertProfile({ profileId, events }: UpsertProfileParams, options?: ExperienceApiClientRequestOptions): Promise<OptimizationData>;
645
464
  /**
646
- * Builds a component view event payload for a Custom Flag component.
465
+ * Sends multiple events to the Ninetailed Experience API to upsert many profiles.
647
466
  *
648
- * @param args - {@link ComponentViewBuilderArgs} arguments describing the Custom Flag view.
649
- * @returns A {@link ComponentViewEvent} describing the view.
467
+ * @param params - Parameters containing the batch of events.
468
+ * @param options - Optional request options.
469
+ * @returns The list of profiles affected by the batch operation.
650
470
  *
651
471
  * @remarks
652
- * This is a specialized variant of {@link EventBuilder.buildComponentView}
653
- * that sets `componentType` to `'Variable'`.
472
+ * Batch requests must contain at least one event. Every event must contain
473
+ * an anonymous ID. Profiles will be created or updated according to the
474
+ * anonymous ID.
475
+ *
476
+ * This method is intended to be used from server environments.
654
477
  *
655
478
  * @example
656
479
  * ```ts
657
- * const event = builder.buildFlagView({
658
- * componentId: 'feature-flag-key',
659
- * componentViewId: crypto.randomUUID(),
660
- * experienceId: 'personalization-123',
661
- * viewDurationMs: 1_000,
480
+ * const profiles = await client.upsertManyProfiles({
481
+ * events: [
482
+ * { anonymousId: 'anon-1', type: 'identify', ... },
483
+ * { anonymousId: 'anon-2', type: 'identify', ... },
484
+ * ],
662
485
  * })
663
486
  * ```
664
- *
665
- * @public
666
487
  */
667
- buildFlagView(args: ComponentViewBuilderArgs): ComponentViewEvent;
488
+ upsertManyProfiles({ events }: BatchUpdateProfileParams, options?: ExperienceApiClientRequestOptions): Promise<BatchExperienceResponseData['profiles']>;
668
489
  /**
669
- * Builds an identify event payload to associate a user ID with traits.
670
- *
671
- * @param args - {@link IdentifyBuilderArgs} arguments describing the identified user.
672
- * @returns An {@link IdentifyEvent} payload.
490
+ * Constructs a request URL with query parameters derived from request options.
673
491
  *
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.
492
+ * @param path - Path relative to the Experience API base URL.
493
+ * @param options - Request options that may influence query parameters.
494
+ * @returns The fully constructed URL as a string.
678
495
  *
679
- * @example
680
- * ```ts
681
- * const event = builder.buildIdentify({
682
- * userId: 'user-123',
683
- * traits: { plan: 'pro' },
684
- * })
685
- * ```
686
- *
687
- * @public
496
+ * @internal
688
497
  */
689
- buildIdentify(args: IdentifyBuilderArgs): IdentifyEvent;
498
+ private constructUrl;
690
499
  /**
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.
500
+ * Constructs request headers based on request options and default configuration.
695
501
  *
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.
700
- *
701
- * The title always falls back to {@link DEFAULT_PAGE_PROPERTIES}.title when undefined.
502
+ * @param options - Request options that may influence headers.
503
+ * @returns A record of HTTP headers to send with the request.
702
504
  *
703
- * @example
704
- * ```ts
705
- * const event = builder.buildPageView({
706
- * properties: {
707
- * title: 'Homepage',
708
- * },
709
- * })
710
- * ```
711
- *
712
- * @public
505
+ * @internal
713
506
  */
714
- buildPageView(args?: PageViewBuilderArgs): PageViewEvent;
507
+ private constructHeaders;
715
508
  /**
716
- * Builds a screen view event payload.
509
+ * Constructs the `options` section of the request body for profile mutations.
717
510
  *
718
- * @param args - {@link ScreenViewBuilderArgs} arguments for the screen view event.
719
- * @returns A {@link ScreenViewEvent} payload.
511
+ * @param options - Request options that may specify enabled features.
512
+ * @returns Experience API body options including feature flags.
720
513
  *
721
- * @example
722
- * ```ts
723
- * const event = builder.buildScreenView({
724
- * name: 'home',
725
- * properties: {
726
- * title: 'Home Screen',
727
- * },
728
- * })
729
- * ```
730
- *
731
- * @public
514
+ * @internal
732
515
  */
733
- buildScreenView(args: ScreenViewBuilderArgs): ScreenViewEvent;
516
+ private readonly constructBodyOptions;
734
517
  /**
735
- * Builds a track event payload for arbitrary user actions.
518
+ * Construct and validate the singular Experience mutation request payload.
736
519
  *
737
- * @param args - {@link TrackBuilderArgs} arguments describing the tracked event.
738
- * @returns A {@link TrackEvent} payload.
520
+ * @param events - Events that should be evaluated by the Experience API.
521
+ * @param options - Request options that may contribute body options.
522
+ * @returns Validated singular Experience request body.
739
523
  *
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
524
+ * @internal
749
525
  */
750
- buildTrack(args: TrackBuilderArgs): TrackEvent_2;
526
+ private constructExperienceRequestBody;
751
527
  }
752
528
 
753
529
  /**
754
- * Configuration options for creating an {@link EventBuilder} instance.
530
+ * Configuration for {@link ExperienceApiClient}.
755
531
  *
756
- * @remarks
757
- * The configuration is typically provided by the host application to adapt
758
- * event payloads to the runtime environment (browser, framework, etc.).
759
- *
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
- * ```
532
+ * @public
533
+ */
534
+ export declare interface ExperienceApiClientConfig extends ApiConfig, ExperienceApiClientRequestOptions {
535
+ }
536
+
537
+ /**
538
+ * Options that control how requests to the Experience API are handled.
777
539
  *
778
540
  * @public
779
541
  */
780
- export declare interface EventBuilderConfig {
542
+ export declare interface ExperienceApiClientRequestOptions {
781
543
  /**
782
- * The application definition used to attribute events to a specific consumer app.
544
+ * Enabled features (for example, `"ip-enrichment"`) which the API should use for this request.
783
545
  *
784
546
  * @remarks
785
- * When not provided, events will not contain app metadata in their context.
547
+ * When omitted, a default set of features may be applied.
786
548
  */
787
- app?: App;
549
+ enabledFeatures?: Feature[];
788
550
  /**
789
- * The channel that identifies where events originate from (e.g. web, mobile).
551
+ * IP address to override the API behavior for IP analysis.
790
552
  *
791
- * @see {@link Channel}
553
+ * @remarks
554
+ * Commonly used in ESR or SSR environments, as the API would otherwise use
555
+ * the server IP.
792
556
  */
793
- channel: Channel;
557
+ ip?: string;
794
558
  /**
795
- * The client library metadata that is attached to all events.
559
+ * Locale used to translate `location.city` and `location.country`.
796
560
  *
797
561
  * @remarks
798
- * This is typically used to record the library name and version.
562
+ * When omitted, a server-side default may be used.
799
563
  */
800
- library: Library;
564
+ locale?: string;
801
565
  /**
802
- * Function used to resolve the locale for outgoing events.
566
+ * When `true`, sends performance-critical endpoints in plain text.
803
567
  *
804
568
  * @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.
569
+ * The Ninetailed API accepts certain endpoints in plain text to avoid CORS
570
+ * preflight requests, which can improve performance in browser environments.
810
571
  */
811
- getLocale?: () => string | undefined;
572
+ plainText?: boolean;
812
573
  /**
813
- * Function that returns the current page properties.
574
+ * When `true`, instructs the API to aggregate a new profile state but not store it.
814
575
  *
815
576
  * @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}
577
+ * This is commonly used in ESR or SSR environments where you want to
578
+ * preview the result without persisting changes.
579
+ */
580
+ preflight?: boolean;
581
+ }
582
+
583
+ /**
584
+ * Feature flags supported by the Experience API.
585
+ *
586
+ * @internal
587
+ */
588
+ export declare type Feature = 'ip-enrichment' | 'location';
589
+
590
+ /**
591
+ * Signature of a fetch method used by the API clients.
592
+ *
593
+ * @param url - The request URL.
594
+ * @param init - Initialization options passed to `fetch`.
595
+ * @returns A promise that resolves with the {@link Response}.
596
+ *
597
+ * @remarks
598
+ * This abstraction allows the underlying implementation to be replaced,
599
+ * for example in tests or different runtime environments.
600
+ *
601
+ * @example
602
+ * ```ts
603
+ * const method: FetchMethod = async (url, init) => {
604
+ * return fetch(url, init)
605
+ * }
606
+ * ```
607
+ *
608
+ * @public
609
+ */
610
+ export declare type FetchMethod = (url: string | URL, init: RequestInit) => Promise<Response>;
611
+
612
+ /**
613
+ * Options passed to callback functions invoked by fetch wrappers.
614
+ *
615
+ * @remarks
616
+ * Not all fields are guaranteed to be present in all callback scenarios.
617
+ *
618
+ * @public
619
+ */
620
+ export declare interface FetchMethodCallbackOptions {
621
+ /**
622
+ * Name of the API associated with the request.
623
+ */
624
+ apiName?: string;
625
+ /**
626
+ * Error that caused the callback to be invoked, if available.
822
627
  */
823
- getPageProperties?: () => Page;
628
+ error?: Error;
824
629
  /**
825
- * Function used to obtain the current user agent string when applicable.
826
- *
827
- * @returns A user agent string, or `undefined` if unavailable.
630
+ * The current attempt number (for retry callbacks).
828
631
  */
829
- getUserAgent?: () => string | undefined;
632
+ attemptNumber?: number;
633
+ /**
634
+ * Number of retry attempts remaining (for retry callbacks).
635
+ */
636
+ retriesLeft?: number;
830
637
  }
831
638
 
832
639
  /**
833
- * Default base URL for the Experience API.
640
+ * Properties that may be shared between global and per-client API configuration.
834
641
  *
835
642
  * @public
836
643
  */
837
- export declare const EXPERIENCE_BASE_URL = "https://experience.ninetailed.co/";
644
+ export declare type GlobalApiConfigProperties = 'environment' | 'fetchOptions' | 'clientId';
838
645
 
839
646
  /**
840
- * Client for interacting with the Experience API.
647
+ * Default base URL for the Insights ingest API.
648
+ *
649
+ * @public
650
+ */
651
+ export declare const INSIGHTS_BASE_URL = "https://ingest.insights.ninetailed.co/";
652
+
653
+ /**
654
+ * Client for sending analytics and insights events to the Ninetailed Insights API.
841
655
  *
842
656
  * @remarks
843
- * This client is responsible for reading and mutating Ninetailed profiles
844
- * using the Experience API.
657
+ * This client is optimized for sending batched events, optionally using a
658
+ * custom beacon-like handler when available.
845
659
  *
846
660
  * @example
847
661
  * ```ts
848
- * const client = new ExperienceApiClient({
662
+ * const insightsClient = new InsightsApiClient({
849
663
  * clientId: 'org-id',
850
664
  * environment: 'main',
851
665
  * })
852
666
  *
853
- * const profile = await client.getProfile('profile-id')
667
+ * await insightsClient.sendBatchEvents([
668
+ * {
669
+ * profile: { id: 'profile-123', ... },
670
+ * events: [
671
+ * {
672
+ * type: 'track',
673
+ * event: 'button_clicked',
674
+ * properties: { id: 'primary-cta' },
675
+ * },
676
+ * ],
677
+ * }
678
+ * ])
854
679
  * ```
855
680
  *
856
- * @see {@link ApiClientBase}
681
+ * Extends `ApiClientBase`.
857
682
  *
858
683
  * @public
859
684
  */
860
- declare class ExperienceApiClient extends ApiClientBase {
685
+ export declare class InsightsApiClient extends ApiClientBase {
861
686
  /**
862
- * Base URL used for Experience API requests.
687
+ * Base URL used for Insights API requests.
863
688
  */
864
689
  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
690
  /**
871
- * Creates a new {@link ExperienceApiClient} instance.
691
+ * Optional handler used to enqueue events via the Beacon API or a similar mechanism.
692
+ */
693
+ private readonly beaconHandler;
694
+ /**
695
+ * Creates a new {@link InsightsApiClient} instance.
872
696
  *
873
- * @param config - Configuration for the Experience API client.
697
+ * @param config - Configuration for the Insights API client.
698
+ *
699
+ * @example
700
+ * ```ts
701
+ * const client = new InsightsApiClient({
702
+ * clientId: 'org-id',
703
+ * environment: 'main',
704
+ * beaconHandler: (url, data) => {
705
+ * return navigator.sendBeacon(url.toString(), JSON.stringify(data))
706
+ * },
707
+ * })
708
+ * ```
874
709
  */
875
- constructor(config: ExperienceApiClientConfig);
710
+ constructor(config: InsightsApiClientConfig);
876
711
  /**
877
- * Retrieves a profile by ID.
712
+ * Sends batches of insights events to the Ninetailed Insights API.
878
713
  *
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.
714
+ * @param batches - Array of event batches to send.
715
+ * @param options - Optional request options, including a per-call `beaconHandler`.
716
+ * @returns `true` when the event batch is successfully queued by the beacon
717
+ * handler or a direct request is successfully sent, `false` otherwise.
882
718
  *
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>;
719
+ * @remarks
720
+ * If a `beaconHandler` is provided (either in the method call or in the
721
+ * client configuration) it will be invoked first. When the handler returns
722
+ * `true`, the events are considered successfully queued and no network
723
+ * request is made by this method.
724
+ *
725
+ * If the handler is missing or returns `false`, the events are emitted
726
+ * immediately via `fetch`.
727
+ *
728
+ * @example
729
+ * ```ts
730
+ * const success = await insightsClient.sendBatchEvents(batches)
731
+ * ```
732
+ *
733
+ * @example
734
+ * ```ts
735
+ * // Override beaconHandler for a single call
736
+ * const success = await insightsClient.sendBatchEvents(batches, {
737
+ * beaconHandler: (url, data) => {
738
+ * return navigator.sendBeacon(url.toString(), JSON.stringify(data))
739
+ * },
740
+ * })
741
+ * ```
742
+ */
743
+ sendBatchEvents(batches: BatchInsightsEventArray, options?: InsightsApiClientRequestOptions): Promise<boolean>;
744
+ }
1527
745
 
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>;
746
+ /**
747
+ * Configuration for {@link InsightsApiClient}.
748
+ *
749
+ * @public
750
+ */
751
+ export declare interface InsightsApiClientConfig extends ApiConfig, InsightsApiClientRequestOptions {
752
+ }
1566
753
 
1567
- /**
1568
- * Arguments for constructing track events.
1569
- *
1570
- * @public
1571
- */
1572
- declare type TrackBuilderArgs = z.infer<typeof TrackBuilderArgs_2>;
754
+ /**
755
+ * Options that control how Insights events are sent.
756
+ *
757
+ * @public
758
+ */
759
+ export declare interface InsightsApiClientRequestOptions {
760
+ /**
761
+ * Handler used to enqueue events via the Beacon API or a similar mechanism.
762
+ *
763
+ * @param url - Target URL for the batched events.
764
+ * @param data - Array of batched insights events to be sent.
765
+ * @returns `true` if the events were successfully queued, `false` otherwise.
766
+ *
767
+ * @remarks
768
+ * When provided, this handler is preferred over direct `fetch` calls. If it
769
+ * returns `false`, the client falls back to emitting events immediately via
770
+ * `fetch`.
771
+ */
772
+ beaconHandler?: (url: string | URL, data: BatchInsightsEventArray) => boolean;
773
+ }
1573
774
 
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>;
775
+ /**
776
+ * Options for {@link createProtectedFetchMethod}, combining timeout and retry behavior.
777
+ *
778
+ * @see {@link RetryFetchMethodOptions}
779
+ * @see {@link TimeoutFetchMethodOptions}
780
+ *
781
+ * @public
782
+ */
783
+ export declare interface ProtectedFetchMethodOptions extends RetryFetchMethodOptions, TimeoutFetchMethodOptions {
784
+ }
1580
785
 
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>;
786
+ /**
787
+ * Configuration options for {@link createRetryFetchMethod}.
788
+ *
789
+ * @public
790
+ */
791
+ export declare interface RetryFetchMethodOptions extends BaseFetchMethodOptions {
792
+ /**
793
+ * Delay (in milliseconds) between retry attempts.
794
+ *
795
+ * @defaultValue `0`
796
+ */
797
+ intervalTimeout?: number;
798
+ /**
799
+ * Callback invoked whenever a retry attempt fails.
800
+ *
801
+ * @param options - Information about the failed attempt.
802
+ *
803
+ * @remarks
804
+ * This callback is invoked with additional metadata such as the attempt
805
+ * number and the number of retries left.
806
+ */
807
+ onFailedAttempt?: (options: FetchMethodCallbackOptions) => void;
808
+ /**
809
+ * Maximum number of retry attempts.
810
+ *
811
+ * @defaultValue `1`
812
+ */
813
+ retries?: number;
814
+ }
1617
815
 
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>;
816
+ /**
817
+ * Configuration options for {@link createTimeoutFetchMethod}.
818
+ *
819
+ * @public
820
+ */
821
+ export declare interface TimeoutFetchMethodOptions extends BaseFetchMethodOptions {
822
+ /**
823
+ * Callback invoked when a request exceeds the configured timeout.
824
+ *
825
+ * @param options - Information about the timed-out request.
826
+ *
827
+ * @remarks
828
+ * If this callback is not provided, a default error is logged.
829
+ *
830
+ * @see {@link FetchMethodCallbackOptions}
831
+ */
832
+ onRequestTimeout?: (options: FetchMethodCallbackOptions) => void;
833
+ /**
834
+ * Maximum time (in milliseconds) to wait for a response before aborting the request.
835
+ *
836
+ * @defaultValue `3000`
837
+ */
838
+ requestTimeout?: number;
839
+ }
1624
840
 
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
- }
841
+ /**
842
+ * Parameters used when updating an existing profile.
843
+ *
844
+ * @public
845
+ */
846
+ export declare interface UpdateProfileParams extends CreateProfileParams {
847
+ /**
848
+ * ID of the profile to update.
849
+ */
850
+ profileId: string;
851
+ }
1636
852
 
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
- }
853
+ /**
854
+ * Parameters used when creating or updating a profile.
855
+ *
856
+ * @public
857
+ */
858
+ export declare interface UpsertProfileParams extends CreateProfileParams {
859
+ /**
860
+ * Optional ID of the profile; when omitted, a new profile is created.
861
+ */
862
+ profileId?: string;
863
+ }
1648
864
 
1649
- export { }
865
+ export { }