@contentful/optimization-api-client 0.1.0-alpha8 → 1.0.0

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