@contentful/optimization-api-client 0.1.0-alpha → 0.1.0-alpha11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/README.md +70 -95
  2. package/dist/199.mjs +2 -0
  3. package/dist/649.mjs +131 -0
  4. package/dist/649.mjs.map +1 -0
  5. package/dist/api-schemas.cjs +60 -0
  6. package/dist/api-schemas.cjs.map +1 -0
  7. package/dist/api-schemas.d.cts +4 -0
  8. package/dist/api-schemas.d.mts +4 -0
  9. package/dist/api-schemas.d.ts +4 -0
  10. package/dist/api-schemas.mjs +2 -0
  11. package/dist/index.cjs +425 -580
  12. package/dist/index.cjs.map +1 -1
  13. package/dist/index.d.cts +865 -0
  14. package/dist/index.d.mts +865 -0
  15. package/dist/index.d.ts +865 -8
  16. package/dist/index.mjs +67 -277
  17. package/dist/index.mjs.map +1 -1
  18. package/dist/logger.cjs +207 -0
  19. package/dist/logger.cjs.map +1 -0
  20. package/dist/logger.d.cts +287 -0
  21. package/dist/logger.d.mts +287 -0
  22. package/dist/logger.d.ts +287 -0
  23. package/dist/logger.mjs +1 -0
  24. package/package.json +46 -10
  25. package/dist/ApiClient.d.ts +0 -74
  26. package/dist/ApiClient.d.ts.map +0 -1
  27. package/dist/ApiClient.js +0 -61
  28. package/dist/ApiClient.js.map +0 -1
  29. package/dist/ApiClientBase.d.ts +0 -113
  30. package/dist/ApiClientBase.d.ts.map +0 -1
  31. package/dist/ApiClientBase.js +0 -94
  32. package/dist/ApiClientBase.js.map +0 -1
  33. package/dist/builders/EventBuilder.d.ts +0 -589
  34. package/dist/builders/EventBuilder.d.ts.map +0 -1
  35. package/dist/builders/EventBuilder.js +0 -349
  36. package/dist/builders/EventBuilder.js.map +0 -1
  37. package/dist/builders/index.d.ts +0 -3
  38. package/dist/builders/index.d.ts.map +0 -1
  39. package/dist/builders/index.js +0 -3
  40. package/dist/builders/index.js.map +0 -1
  41. package/dist/experience/ExperienceApiClient.d.ts +0 -267
  42. package/dist/experience/ExperienceApiClient.d.ts.map +0 -1
  43. package/dist/experience/ExperienceApiClient.js +0 -324
  44. package/dist/experience/ExperienceApiClient.js.map +0 -1
  45. package/dist/experience/index.d.ts +0 -4
  46. package/dist/experience/index.d.ts.map +0 -1
  47. package/dist/experience/index.js +0 -4
  48. package/dist/experience/index.js.map +0 -1
  49. package/dist/fetch/Fetch.d.ts +0 -96
  50. package/dist/fetch/Fetch.d.ts.map +0 -1
  51. package/dist/fetch/Fetch.js +0 -27
  52. package/dist/fetch/Fetch.js.map +0 -1
  53. package/dist/fetch/createProtectedFetchMethod.d.ts +0 -40
  54. package/dist/fetch/createProtectedFetchMethod.d.ts.map +0 -1
  55. package/dist/fetch/createProtectedFetchMethod.js +0 -53
  56. package/dist/fetch/createProtectedFetchMethod.js.map +0 -1
  57. package/dist/fetch/createRetryFetchMethod.d.ts +0 -60
  58. package/dist/fetch/createRetryFetchMethod.d.ts.map +0 -1
  59. package/dist/fetch/createRetryFetchMethod.js +0 -138
  60. package/dist/fetch/createRetryFetchMethod.js.map +0 -1
  61. package/dist/fetch/createTimeoutFetchMethod.d.ts +0 -51
  62. package/dist/fetch/createTimeoutFetchMethod.d.ts.map +0 -1
  63. package/dist/fetch/createTimeoutFetchMethod.js +0 -51
  64. package/dist/fetch/createTimeoutFetchMethod.js.map +0 -1
  65. package/dist/fetch/index.d.ts +0 -7
  66. package/dist/fetch/index.d.ts.map +0 -1
  67. package/dist/fetch/index.js +0 -7
  68. package/dist/fetch/index.js.map +0 -1
  69. package/dist/index.d.ts.map +0 -1
  70. package/dist/index.js +0 -8
  71. package/dist/index.js.map +0 -1
  72. package/dist/insights/InsightsApiClient.d.ts +0 -130
  73. package/dist/insights/InsightsApiClient.d.ts.map +0 -1
  74. package/dist/insights/InsightsApiClient.js +0 -142
  75. package/dist/insights/InsightsApiClient.js.map +0 -1
  76. package/dist/insights/index.d.ts +0 -4
  77. package/dist/insights/index.d.ts.map +0 -1
  78. package/dist/insights/index.js +0 -4
  79. package/dist/insights/index.js.map +0 -1
package/dist/index.mjs CHANGED
@@ -1,88 +1,6 @@
1
- import * as __rspack_external__contentful_optimization_api_schemas_66dcf407 from "@contentful/optimization-api-schemas";
2
- import { diary, enable } from "diary";
3
- import "diary/utils";
4
- import p_retry from "p-retry";
5
- import { merge } from "es-toolkit";
6
- import { boolean as mini_boolean, extend, number, object, optional, partial, prefault, string } from "zod/mini";
7
- class Logger {
8
- name = '@contentful/optimization';
9
- PREFIX_PARTS = [
10
- 'Ctfl',
11
- 'O10n'
12
- ];
13
- DELIMITER = ':';
14
- diary;
15
- sinks = [];
16
- constructor(){
17
- this.diary = diary(this.name, this.onLogEvent.bind(this));
18
- enable(this.name);
19
- }
20
- assembleLocationPrefix(logLocation) {
21
- return `[${[
22
- ...this.PREFIX_PARTS,
23
- logLocation
24
- ].join(this.DELIMITER)}]`;
25
- }
26
- addSink(sink) {
27
- this.sinks = [
28
- ...this.sinks.filter((existingSink)=>existingSink.name !== sink.name),
29
- sink
30
- ];
31
- }
32
- removeSink(name) {
33
- this.sinks = this.sinks.filter((sink)=>sink.name !== name);
34
- }
35
- removeSinks() {
36
- this.sinks = [];
37
- }
38
- debug(logLocation, message, ...args) {
39
- this.diary.debug(`${this.assembleLocationPrefix(logLocation)} ${message}`, ...args);
40
- }
41
- info(logLocation, message, ...args) {
42
- this.diary.info(`${this.assembleLocationPrefix(logLocation)} ${message}`, ...args);
43
- }
44
- log(logLocation, message, ...args) {
45
- this.diary.log(`${this.assembleLocationPrefix(logLocation)} ${message}`, ...args);
46
- }
47
- warn(logLocation, message, ...args) {
48
- this.diary.warn(`${this.assembleLocationPrefix(logLocation)} ${message}`, ...args);
49
- }
50
- error(logLocation, message, ...args) {
51
- this.diary.error(`${this.assembleLocationPrefix(logLocation)} ${message}`, ...args);
52
- }
53
- fatal(logLocation, message, ...args) {
54
- this.diary.fatal(`${this.assembleLocationPrefix(logLocation)} ${message}`, ...args);
55
- }
56
- onLogEvent(event) {
57
- this.sinks.forEach((sink)=>{
58
- sink.ingest(event);
59
- });
60
- }
61
- }
62
- const logger = new Logger();
63
- function createScopedLogger(location) {
64
- return {
65
- debug: (message, ...args)=>{
66
- logger.debug(location, message, ...args);
67
- },
68
- info: (message, ...args)=>{
69
- logger.info(location, message, ...args);
70
- },
71
- log: (message, ...args)=>{
72
- logger.log(location, message, ...args);
73
- },
74
- warn: (message, ...args)=>{
75
- logger.warn(location, message, ...args);
76
- },
77
- error: (message, ...args)=>{
78
- logger.error(location, message, ...args);
79
- },
80
- fatal: (message, ...args)=>{
81
- logger.fatal(location, message, ...args);
82
- }
83
- };
84
- }
85
- const createRetryFetchMethod_logger = createScopedLogger('ApiClient:Retry');
1
+ import { createScopedLogger } from "./649.mjs";
2
+ import { __rspack_external__contentful_optimization_api_schemas_66dcf407 } from "./199.mjs";
3
+ const logger = createScopedLogger('ApiClient:Retry');
86
4
  const DEFAULT_INTERVAL_TIMEOUT = 0;
87
5
  const DEFAULT_RETRY_COUNT = 1;
88
6
  const RETRY_RESPONSE_STATUS = 503;
@@ -102,44 +20,55 @@ function createRetryFetchCallback({ apiName = 'Optimization', controller, fetchM
102
20
  if (response.status === RETRY_RESPONSE_STATUS) throw new HttpError(`${apiName} API request to "${url.toString()}" failed with status: "[${response.status}] ${response.statusText}".`, RETRY_RESPONSE_STATUS);
103
21
  if (!response.ok) {
104
22
  const httpError = new Error(`Request to "${url.toString()}" failed with status: [${response.status}] ${response.statusText} - traceparent: ${response.headers.get('traceparent')}`);
105
- createRetryFetchMethod_logger.error('Request failed with non-OK status:', httpError);
23
+ logger.error('Request failed with non-OK status:', httpError);
106
24
  controller.abort();
107
25
  return;
108
26
  }
109
- createRetryFetchMethod_logger.debug(`Response from "${url.toString()}":`, response);
27
+ logger.debug(`Response from "${url.toString()}":`, response);
110
28
  return response;
111
29
  } catch (error) {
112
30
  if (error instanceof HttpError && error.status === RETRY_RESPONSE_STATUS) throw error;
113
- createRetryFetchMethod_logger.error(`Request to "${url.toString()}" failed:`, error);
31
+ logger.error(`Request to "${url.toString()}" failed:`, error);
114
32
  controller.abort();
115
33
  }
116
34
  };
117
35
  }
36
+ async function delayRetry(intervalTimeout) {
37
+ if (intervalTimeout <= 0) return;
38
+ const { promise, resolve } = Promise.withResolvers();
39
+ setTimeout(()=>{
40
+ resolve(void 0);
41
+ }, intervalTimeout);
42
+ await promise;
43
+ }
118
44
  function createRetryFetchMethod({ apiName = 'Optimization', fetchMethod = fetch, intervalTimeout = DEFAULT_INTERVAL_TIMEOUT, onFailedAttempt, retries = DEFAULT_RETRY_COUNT } = {}) {
119
45
  return async (url, init)=>{
120
46
  const controller = new AbortController();
121
- let retryResponse;
122
- try {
123
- retryResponse = await p_retry(createRetryFetchCallback({
47
+ const maxAttempts = retries + 1;
48
+ const attemptFetch = createRetryFetchCallback({
49
+ apiName,
50
+ controller,
51
+ fetchMethod,
52
+ init,
53
+ url
54
+ });
55
+ for(let attemptNumber = 1; attemptNumber <= maxAttempts; attemptNumber++)try {
56
+ const response = await attemptFetch();
57
+ if (response) return response;
58
+ break;
59
+ } catch (error) {
60
+ if (!(error instanceof HttpError) || error.status !== RETRY_RESPONSE_STATUS) throw error;
61
+ const retriesLeft = maxAttempts - attemptNumber;
62
+ onFailedAttempt?.({
124
63
  apiName,
125
- controller,
126
- fetchMethod,
127
- init,
128
- url
129
- }), {
130
- minTimeout: intervalTimeout,
131
- onFailedAttempt: (options)=>onFailedAttempt?.({
132
- ...options,
133
- apiName
134
- }),
135
- retries,
136
- signal: controller.signal
64
+ error,
65
+ attemptNumber,
66
+ retriesLeft
137
67
  });
138
- } catch (error) {
139
- if (!(error instanceof Error) || 'AbortError' !== error.name) throw error;
68
+ if (0 === retriesLeft) throw error;
69
+ await delayRetry(intervalTimeout);
140
70
  }
141
- if (!retryResponse) throw new Error(`${apiName} API request to "${url.toString()}" may not be retried.`);
142
- return retryResponse;
71
+ throw new Error(`${apiName} API request to "${url.toString()}" may not be retried.`);
143
72
  };
144
73
  }
145
74
  const createTimeoutFetchMethod_logger = createScopedLogger('ApiClient:Timeout');
@@ -231,10 +160,10 @@ class ExperienceApiClient extends src_ApiClientBase {
231
160
  const response = await this.fetch(this.constructUrl(`v2/organizations/${this.clientId}/environments/${this.environment}/profiles/${id}`, options), {
232
161
  method: 'GET'
233
162
  });
234
- const { data: { changes, experiences, profile } } = __rspack_external__contentful_optimization_api_schemas_66dcf407.ExperienceResponse.parse(await response.json());
163
+ const { data: { changes, experiences, profile } } = (0, __rspack_external__contentful_optimization_api_schemas_66dcf407.parseWithFriendlyError)(__rspack_external__contentful_optimization_api_schemas_66dcf407.ExperienceResponse, await response.json());
235
164
  const data = {
236
165
  changes,
237
- personalizations: experiences,
166
+ selectedOptimizations: experiences,
238
167
  profile
239
168
  };
240
169
  ExperienceApiClient_logger.debug(`"${requestName}" request successfully completed`);
@@ -257,10 +186,7 @@ class ExperienceApiClient extends src_ApiClientBase {
257
186
  async createProfile({ events }, options = {}) {
258
187
  const requestName = 'Create Profile';
259
188
  ExperienceApiClient_logger.info(`Sending "${requestName}" request`);
260
- const body = {
261
- events: __rspack_external__contentful_optimization_api_schemas_66dcf407.ExperienceEventArray.parse(events),
262
- options: this.constructBodyOptions(options)
263
- };
189
+ const body = this.constructExperienceRequestBody(events, options);
264
190
  ExperienceApiClient_logger.debug(`"${requestName}" request body:`, body);
265
191
  try {
266
192
  const response = await this.makeProfileMutationRequest({
@@ -268,10 +194,10 @@ class ExperienceApiClient extends src_ApiClientBase {
268
194
  body,
269
195
  options
270
196
  });
271
- const { data: { changes, experiences, profile } } = __rspack_external__contentful_optimization_api_schemas_66dcf407.ExperienceResponse.parse(await response.json());
197
+ const { data: { changes, experiences, profile } } = (0, __rspack_external__contentful_optimization_api_schemas_66dcf407.parseWithFriendlyError)(__rspack_external__contentful_optimization_api_schemas_66dcf407.ExperienceResponse, await response.json());
272
198
  const data = {
273
199
  changes,
274
- personalizations: experiences,
200
+ selectedOptimizations: experiences,
275
201
  profile
276
202
  };
277
203
  ExperienceApiClient_logger.debug(`"${requestName}" request successfully completed`);
@@ -287,10 +213,7 @@ class ExperienceApiClient extends src_ApiClientBase {
287
213
  if (!profileId) throw new Error('Valid profile ID required.');
288
214
  const requestName = 'Update Profile';
289
215
  ExperienceApiClient_logger.info(`Sending "${requestName}" request`);
290
- const body = {
291
- events: __rspack_external__contentful_optimization_api_schemas_66dcf407.ExperienceEventArray.parse(events),
292
- options: this.constructBodyOptions(options)
293
- };
216
+ const body = this.constructExperienceRequestBody(events, options);
294
217
  ExperienceApiClient_logger.debug(`"${requestName}" request body:`, body);
295
218
  try {
296
219
  const response = await this.makeProfileMutationRequest({
@@ -298,10 +221,10 @@ class ExperienceApiClient extends src_ApiClientBase {
298
221
  body,
299
222
  options
300
223
  });
301
- const { data: { changes, experiences, profile } } = __rspack_external__contentful_optimization_api_schemas_66dcf407.ExperienceResponse.parse(await response.json());
224
+ const { data: { changes, experiences, profile } } = (0, __rspack_external__contentful_optimization_api_schemas_66dcf407.parseWithFriendlyError)(__rspack_external__contentful_optimization_api_schemas_66dcf407.ExperienceResponse, await response.json());
302
225
  const data = {
303
226
  changes,
304
- personalizations: experiences,
227
+ selectedOptimizations: experiences,
305
228
  profile
306
229
  };
307
230
  ExperienceApiClient_logger.debug(`"${requestName}" request successfully completed`);
@@ -325,10 +248,10 @@ class ExperienceApiClient extends src_ApiClientBase {
325
248
  async upsertManyProfiles({ events }, options = {}) {
326
249
  const requestName = 'Upsert Many Profiles';
327
250
  ExperienceApiClient_logger.info(`Sending "${requestName}" request`);
328
- const body = {
329
- events: __rspack_external__contentful_optimization_api_schemas_66dcf407.ExperienceEventArray.parse(events),
251
+ const body = (0, __rspack_external__contentful_optimization_api_schemas_66dcf407.parseWithFriendlyError)(__rspack_external__contentful_optimization_api_schemas_66dcf407.BatchExperienceRequestData, {
252
+ events,
330
253
  options: this.constructBodyOptions(options)
331
- };
254
+ });
332
255
  ExperienceApiClient_logger.debug(`"${requestName}" request body:`, body);
333
256
  try {
334
257
  const response = await this.makeProfileMutationRequest({
@@ -339,7 +262,7 @@ class ExperienceApiClient extends src_ApiClientBase {
339
262
  ...options
340
263
  }
341
264
  });
342
- const { data: { profiles } } = __rspack_external__contentful_optimization_api_schemas_66dcf407.BatchExperienceResponse.parse(await response.json());
265
+ const { data: { profiles } } = (0, __rspack_external__contentful_optimization_api_schemas_66dcf407.parseWithFriendlyError)(__rspack_external__contentful_optimization_api_schemas_66dcf407.BatchExperienceResponse, await response.json());
343
266
  ExperienceApiClient_logger.debug(`"${requestName}" request successfully completed`);
344
267
  return profiles;
345
268
  } catch (error) {
@@ -373,8 +296,13 @@ class ExperienceApiClient extends src_ApiClientBase {
373
296
  ];
374
297
  return bodyOptions;
375
298
  };
299
+ constructExperienceRequestBody(events, options) {
300
+ return __rspack_external__contentful_optimization_api_schemas_66dcf407.ExperienceRequestData.parse({
301
+ events: (0, __rspack_external__contentful_optimization_api_schemas_66dcf407.parseWithFriendlyError)(__rspack_external__contentful_optimization_api_schemas_66dcf407.ExperienceEventArray, events),
302
+ options: this.constructBodyOptions(options)
303
+ });
304
+ }
376
305
  }
377
- const experience = ExperienceApiClient;
378
306
  const InsightsApiClient_logger = createScopedLogger('ApiClient:Insights');
379
307
  const INSIGHTS_BASE_URL = 'https://ingest.insights.ninetailed.co/';
380
308
  class InsightsApiClient extends src_ApiClientBase {
@@ -383,13 +311,13 @@ class InsightsApiClient extends src_ApiClientBase {
383
311
  constructor(config){
384
312
  super('Insights', config);
385
313
  const { baseUrl, beaconHandler } = config;
386
- this.baseUrl = baseUrl ?? INSIGHTS_BASE_URL;
314
+ this.baseUrl = baseUrl || INSIGHTS_BASE_URL;
387
315
  this.beaconHandler = beaconHandler;
388
316
  }
389
317
  async sendBatchEvents(batches, options = {}) {
390
318
  const { beaconHandler = this.beaconHandler } = options;
391
319
  const url = new URL(`v1/organizations/${this.clientId}/environments/${this.environment}/events`, this.baseUrl);
392
- const body = __rspack_external__contentful_optimization_api_schemas_66dcf407.BatchInsightsEventArray.parse(batches);
320
+ const body = (0, __rspack_external__contentful_optimization_api_schemas_66dcf407.parseWithFriendlyError)(__rspack_external__contentful_optimization_api_schemas_66dcf407.BatchInsightsEventArray, batches);
393
321
  if ('function' == typeof beaconHandler) {
394
322
  InsightsApiClient_logger.debug('Queueing events via beaconHandler');
395
323
  const beaconSuccessfullyQueued = beaconHandler(url, body);
@@ -418,166 +346,28 @@ class InsightsApiClient extends src_ApiClientBase {
418
346
  }
419
347
  }
420
348
  }
421
- const insights = InsightsApiClient;
422
349
  class ApiClient {
423
350
  config;
424
351
  experience;
425
352
  insights;
426
353
  constructor(config){
427
- const { personalization, analytics, ...apiConfig } = config;
354
+ const { experience, insights, clientId, environment, fetchOptions } = config;
355
+ const apiConfig = {
356
+ clientId,
357
+ environment,
358
+ fetchOptions
359
+ };
428
360
  this.config = apiConfig;
429
- this.experience = new experience({
361
+ this.experience = new ExperienceApiClient({
430
362
  ...apiConfig,
431
- ...personalization
363
+ ...experience
432
364
  });
433
- this.insights = new insights({
365
+ this.insights = new InsightsApiClient({
434
366
  ...apiConfig,
435
- ...analytics
367
+ ...insights
436
368
  });
437
369
  }
438
370
  }
439
- const UniversalEventBuilderArgs = object({
440
- campaign: optional(__rspack_external__contentful_optimization_api_schemas_66dcf407.Campaign),
441
- locale: optional(string()),
442
- location: optional(__rspack_external__contentful_optimization_api_schemas_66dcf407.GeoLocation),
443
- page: optional(__rspack_external__contentful_optimization_api_schemas_66dcf407.Page),
444
- screen: optional(__rspack_external__contentful_optimization_api_schemas_66dcf407.Screen),
445
- userAgent: optional(string())
446
- });
447
- const ComponentViewBuilderArgs = extend(UniversalEventBuilderArgs, {
448
- componentId: string(),
449
- experienceId: optional(string()),
450
- variantIndex: optional(number()),
451
- sticky: optional(mini_boolean())
452
- });
453
- const IdentifyBuilderArgs = extend(UniversalEventBuilderArgs, {
454
- traits: optional(__rspack_external__contentful_optimization_api_schemas_66dcf407.Traits),
455
- userId: string()
456
- });
457
- const PageViewBuilderArgs = extend(UniversalEventBuilderArgs, {
458
- properties: optional(partial(__rspack_external__contentful_optimization_api_schemas_66dcf407.Page))
459
- });
460
- const ScreenViewBuilderArgs = extend(UniversalEventBuilderArgs, {
461
- name: string(),
462
- properties: __rspack_external__contentful_optimization_api_schemas_66dcf407.Properties
463
- });
464
- const TrackBuilderArgs = extend(UniversalEventBuilderArgs, {
465
- event: string(),
466
- properties: optional(prefault(__rspack_external__contentful_optimization_api_schemas_66dcf407.Properties, {}))
467
- });
468
- const DEFAULT_PAGE_PROPERTIES = {
469
- path: '',
470
- query: {},
471
- referrer: '',
472
- search: '',
473
- title: '',
474
- url: ''
475
- };
476
- class EventBuilder {
477
- app;
478
- channel;
479
- library;
480
- getLocale;
481
- getPageProperties;
482
- getUserAgent;
483
- constructor(config){
484
- const { app, channel, library, getLocale, getPageProperties, getUserAgent } = config;
485
- this.app = app;
486
- this.channel = channel;
487
- this.library = library;
488
- this.getLocale = getLocale ?? (()=>'en-US');
489
- this.getPageProperties = getPageProperties ?? (()=>DEFAULT_PAGE_PROPERTIES);
490
- this.getUserAgent = getUserAgent ?? (()=>void 0);
491
- }
492
- buildUniversalEventProperties({ campaign = {}, locale, location, page, screen, userAgent }) {
493
- const timestamp = new Date().toISOString();
494
- return {
495
- channel: this.channel,
496
- context: {
497
- app: this.app,
498
- campaign,
499
- gdpr: {
500
- isConsentGiven: true
501
- },
502
- library: this.library,
503
- locale: locale ?? this.getLocale() ?? 'en-US',
504
- location,
505
- page: page ?? this.getPageProperties(),
506
- screen,
507
- userAgent: userAgent ?? this.getUserAgent()
508
- },
509
- messageId: crypto.randomUUID(),
510
- originalTimestamp: timestamp,
511
- sentAt: timestamp,
512
- timestamp
513
- };
514
- }
515
- buildComponentView(args) {
516
- const { componentId, experienceId, variantIndex, ...universal } = ComponentViewBuilderArgs.parse(args);
517
- return {
518
- ...this.buildUniversalEventProperties(universal),
519
- type: 'component',
520
- componentType: 'Entry',
521
- componentId,
522
- experienceId,
523
- variantIndex: variantIndex ?? 0
524
- };
525
- }
526
- buildFlagView(args) {
527
- return {
528
- ...this.buildComponentView(args),
529
- componentType: 'Variable'
530
- };
531
- }
532
- buildIdentify(args) {
533
- const { traits = {}, userId, ...universal } = IdentifyBuilderArgs.parse(args);
534
- return {
535
- ...this.buildUniversalEventProperties(universal),
536
- type: 'identify',
537
- traits,
538
- userId
539
- };
540
- }
541
- buildPageView(args = {}) {
542
- const { properties = {}, ...universal } = PageViewBuilderArgs.parse(args);
543
- const pageProperties = this.getPageProperties();
544
- const merged = merge({
545
- ...pageProperties,
546
- title: pageProperties.title ?? DEFAULT_PAGE_PROPERTIES.title
547
- }, properties);
548
- const { context: { screen: _, ...universalContext }, ...universalProperties } = this.buildUniversalEventProperties(universal);
549
- const context = __rspack_external__contentful_optimization_api_schemas_66dcf407.PageEventContext.parse(universalContext);
550
- return {
551
- ...universalProperties,
552
- context,
553
- type: 'page',
554
- properties: merged
555
- };
556
- }
557
- buildScreenView(args) {
558
- const { name, properties, ...universal } = ScreenViewBuilderArgs.parse(args);
559
- const { context: { page: _, ...universalContext }, ...universalProperties } = this.buildUniversalEventProperties(universal);
560
- const context = __rspack_external__contentful_optimization_api_schemas_66dcf407.ScreenEventContext.parse(universalContext);
561
- return {
562
- ...universalProperties,
563
- context,
564
- type: 'screen',
565
- name,
566
- properties
567
- };
568
- }
569
- buildTrack(args) {
570
- const { event, properties = {}, ...universal } = TrackBuilderArgs.parse(args);
571
- return {
572
- ...this.buildUniversalEventProperties(universal),
573
- type: 'track',
574
- event,
575
- properties
576
- };
577
- }
578
- }
579
- const builders_EventBuilder = EventBuilder;
580
- export * from "@contentful/optimization-api-schemas";
581
- export { ApiClient, DEFAULT_PAGE_PROPERTIES, EXPERIENCE_BASE_URL, INSIGHTS_BASE_URL, builders_EventBuilder as EventBuilder };
371
+ export { ApiClient, EXPERIENCE_BASE_URL, ExperienceApiClient, INSIGHTS_BASE_URL, InsightsApiClient, createProtectedFetchMethod, createRetryFetchMethod, createTimeoutFetchMethod };
582
372
 
583
373
  //# sourceMappingURL=index.mjs.map