@contentful/optimization-api-client 0.1.0-alpha7 → 0.1.0-alpha9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +55 -24
- package/dist/199.mjs +2 -0
- package/dist/649.mjs +131 -0
- package/dist/649.mjs.map +1 -0
- package/dist/api-schemas.cjs +60 -0
- package/dist/api-schemas.cjs.map +1 -0
- package/dist/api-schemas.d.cts +4 -0
- package/dist/api-schemas.d.mts +4 -0
- package/dist/api-schemas.d.ts +4 -0
- package/dist/api-schemas.mjs +2 -0
- package/dist/index.cjs +588 -575
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1649 -0
- package/dist/index.d.mts +1649 -0
- package/dist/index.d.ts +1649 -8
- package/dist/index.mjs +103 -136
- package/dist/index.mjs.map +1 -1
- package/dist/logger.cjs +207 -0
- package/dist/logger.cjs.map +1 -0
- package/dist/logger.d.cts +287 -0
- package/dist/logger.d.mts +287 -0
- package/dist/logger.d.ts +287 -0
- package/dist/logger.mjs +1 -0
- package/package.json +33 -10
- package/dist/ApiClient.d.ts +0 -74
- package/dist/ApiClient.d.ts.map +0 -1
- package/dist/ApiClient.js +0 -61
- package/dist/ApiClient.js.map +0 -1
- package/dist/ApiClientBase.d.ts +0 -113
- package/dist/ApiClientBase.d.ts.map +0 -1
- package/dist/ApiClientBase.js +0 -94
- package/dist/ApiClientBase.js.map +0 -1
- package/dist/builders/EventBuilder.d.ts +0 -589
- package/dist/builders/EventBuilder.d.ts.map +0 -1
- package/dist/builders/EventBuilder.js +0 -349
- package/dist/builders/EventBuilder.js.map +0 -1
- package/dist/builders/index.d.ts +0 -3
- package/dist/builders/index.d.ts.map +0 -1
- package/dist/builders/index.js +0 -3
- package/dist/builders/index.js.map +0 -1
- package/dist/experience/ExperienceApiClient.d.ts +0 -267
- package/dist/experience/ExperienceApiClient.d.ts.map +0 -1
- package/dist/experience/ExperienceApiClient.js +0 -324
- package/dist/experience/ExperienceApiClient.js.map +0 -1
- package/dist/experience/index.d.ts +0 -4
- package/dist/experience/index.d.ts.map +0 -1
- package/dist/experience/index.js +0 -4
- package/dist/experience/index.js.map +0 -1
- package/dist/fetch/Fetch.d.ts +0 -96
- package/dist/fetch/Fetch.d.ts.map +0 -1
- package/dist/fetch/Fetch.js +0 -27
- package/dist/fetch/Fetch.js.map +0 -1
- package/dist/fetch/createProtectedFetchMethod.d.ts +0 -40
- package/dist/fetch/createProtectedFetchMethod.d.ts.map +0 -1
- package/dist/fetch/createProtectedFetchMethod.js +0 -53
- package/dist/fetch/createProtectedFetchMethod.js.map +0 -1
- package/dist/fetch/createRetryFetchMethod.d.ts +0 -60
- package/dist/fetch/createRetryFetchMethod.d.ts.map +0 -1
- package/dist/fetch/createRetryFetchMethod.js +0 -138
- package/dist/fetch/createRetryFetchMethod.js.map +0 -1
- package/dist/fetch/createTimeoutFetchMethod.d.ts +0 -51
- package/dist/fetch/createTimeoutFetchMethod.d.ts.map +0 -1
- package/dist/fetch/createTimeoutFetchMethod.js +0 -51
- package/dist/fetch/createTimeoutFetchMethod.js.map +0 -1
- package/dist/fetch/index.d.ts +0 -7
- package/dist/fetch/index.d.ts.map +0 -1
- package/dist/fetch/index.js +0 -7
- package/dist/fetch/index.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -8
- package/dist/index.js.map +0 -1
- package/dist/insights/InsightsApiClient.d.ts +0 -130
- package/dist/insights/InsightsApiClient.d.ts.map +0 -1
- package/dist/insights/InsightsApiClient.js +0 -143
- package/dist/insights/InsightsApiClient.js.map +0 -1
- package/dist/insights/index.d.ts +0 -4
- package/dist/insights/index.d.ts.map +0 -1
- package/dist/insights/index.js +0 -4
- package/dist/insights/index.js.map +0 -1
package/dist/index.mjs
CHANGED
|
@@ -1,88 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { diary, enable } from "diary";
|
|
3
|
-
import "diary/utils";
|
|
4
|
-
import p_retry from "p-retry";
|
|
5
|
-
import { merge } from "es-toolkit";
|
|
1
|
+
import { merge } from "es-toolkit/object";
|
|
6
2
|
import { boolean as mini_boolean, extend, number, object, optional, partial, prefault, string } from "zod/mini";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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');
|
|
3
|
+
import { createScopedLogger } from "./649.mjs";
|
|
4
|
+
import { __rspack_external__contentful_optimization_api_schemas_66dcf407 } from "./199.mjs";
|
|
5
|
+
const logger = createScopedLogger('ApiClient:Retry');
|
|
86
6
|
const DEFAULT_INTERVAL_TIMEOUT = 0;
|
|
87
7
|
const DEFAULT_RETRY_COUNT = 1;
|
|
88
8
|
const RETRY_RESPONSE_STATUS = 503;
|
|
@@ -102,44 +22,55 @@ function createRetryFetchCallback({ apiName = 'Optimization', controller, fetchM
|
|
|
102
22
|
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
23
|
if (!response.ok) {
|
|
104
24
|
const httpError = new Error(`Request to "${url.toString()}" failed with status: [${response.status}] ${response.statusText} - traceparent: ${response.headers.get('traceparent')}`);
|
|
105
|
-
|
|
25
|
+
logger.error('Request failed with non-OK status:', httpError);
|
|
106
26
|
controller.abort();
|
|
107
27
|
return;
|
|
108
28
|
}
|
|
109
|
-
|
|
29
|
+
logger.debug(`Response from "${url.toString()}":`, response);
|
|
110
30
|
return response;
|
|
111
31
|
} catch (error) {
|
|
112
32
|
if (error instanceof HttpError && error.status === RETRY_RESPONSE_STATUS) throw error;
|
|
113
|
-
|
|
33
|
+
logger.error(`Request to "${url.toString()}" failed:`, error);
|
|
114
34
|
controller.abort();
|
|
115
35
|
}
|
|
116
36
|
};
|
|
117
37
|
}
|
|
38
|
+
async function delayRetry(intervalTimeout) {
|
|
39
|
+
if (intervalTimeout <= 0) return;
|
|
40
|
+
const { promise, resolve } = Promise.withResolvers();
|
|
41
|
+
setTimeout(()=>{
|
|
42
|
+
resolve(void 0);
|
|
43
|
+
}, intervalTimeout);
|
|
44
|
+
await promise;
|
|
45
|
+
}
|
|
118
46
|
function createRetryFetchMethod({ apiName = 'Optimization', fetchMethod = fetch, intervalTimeout = DEFAULT_INTERVAL_TIMEOUT, onFailedAttempt, retries = DEFAULT_RETRY_COUNT } = {}) {
|
|
119
47
|
return async (url, init)=>{
|
|
120
48
|
const controller = new AbortController();
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
49
|
+
const maxAttempts = retries + 1;
|
|
50
|
+
const attemptFetch = createRetryFetchCallback({
|
|
51
|
+
apiName,
|
|
52
|
+
controller,
|
|
53
|
+
fetchMethod,
|
|
54
|
+
init,
|
|
55
|
+
url
|
|
56
|
+
});
|
|
57
|
+
for(let attemptNumber = 1; attemptNumber <= maxAttempts; attemptNumber++)try {
|
|
58
|
+
const response = await attemptFetch();
|
|
59
|
+
if (response) return response;
|
|
60
|
+
break;
|
|
61
|
+
} catch (error) {
|
|
62
|
+
if (!(error instanceof HttpError) || error.status !== RETRY_RESPONSE_STATUS) throw error;
|
|
63
|
+
const retriesLeft = maxAttempts - attemptNumber;
|
|
64
|
+
onFailedAttempt?.({
|
|
124
65
|
apiName,
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
url
|
|
129
|
-
}), {
|
|
130
|
-
minTimeout: intervalTimeout,
|
|
131
|
-
onFailedAttempt: (options)=>onFailedAttempt?.({
|
|
132
|
-
...options,
|
|
133
|
-
apiName
|
|
134
|
-
}),
|
|
135
|
-
retries,
|
|
136
|
-
signal: controller.signal
|
|
66
|
+
error,
|
|
67
|
+
attemptNumber,
|
|
68
|
+
retriesLeft
|
|
137
69
|
});
|
|
138
|
-
|
|
139
|
-
|
|
70
|
+
if (0 === retriesLeft) throw error;
|
|
71
|
+
await delayRetry(intervalTimeout);
|
|
140
72
|
}
|
|
141
|
-
|
|
142
|
-
return retryResponse;
|
|
73
|
+
throw new Error(`${apiName} API request to "${url.toString()}" may not be retried.`);
|
|
143
74
|
};
|
|
144
75
|
}
|
|
145
76
|
const createTimeoutFetchMethod_logger = createScopedLogger('ApiClient:Timeout');
|
|
@@ -231,7 +162,7 @@ class ExperienceApiClient extends src_ApiClientBase {
|
|
|
231
162
|
const response = await this.fetch(this.constructUrl(`v2/organizations/${this.clientId}/environments/${this.environment}/profiles/${id}`, options), {
|
|
232
163
|
method: 'GET'
|
|
233
164
|
});
|
|
234
|
-
const { data: { changes, experiences, profile } } = __rspack_external__contentful_optimization_api_schemas_66dcf407.ExperienceResponse
|
|
165
|
+
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
166
|
const data = {
|
|
236
167
|
changes,
|
|
237
168
|
personalizations: experiences,
|
|
@@ -257,10 +188,7 @@ class ExperienceApiClient extends src_ApiClientBase {
|
|
|
257
188
|
async createProfile({ events }, options = {}) {
|
|
258
189
|
const requestName = 'Create Profile';
|
|
259
190
|
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
|
-
};
|
|
191
|
+
const body = this.constructExperienceRequestBody(events, options);
|
|
264
192
|
ExperienceApiClient_logger.debug(`"${requestName}" request body:`, body);
|
|
265
193
|
try {
|
|
266
194
|
const response = await this.makeProfileMutationRequest({
|
|
@@ -268,7 +196,7 @@ class ExperienceApiClient extends src_ApiClientBase {
|
|
|
268
196
|
body,
|
|
269
197
|
options
|
|
270
198
|
});
|
|
271
|
-
const { data: { changes, experiences, profile } } = __rspack_external__contentful_optimization_api_schemas_66dcf407.ExperienceResponse
|
|
199
|
+
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
200
|
const data = {
|
|
273
201
|
changes,
|
|
274
202
|
personalizations: experiences,
|
|
@@ -287,10 +215,7 @@ class ExperienceApiClient extends src_ApiClientBase {
|
|
|
287
215
|
if (!profileId) throw new Error('Valid profile ID required.');
|
|
288
216
|
const requestName = 'Update Profile';
|
|
289
217
|
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
|
-
};
|
|
218
|
+
const body = this.constructExperienceRequestBody(events, options);
|
|
294
219
|
ExperienceApiClient_logger.debug(`"${requestName}" request body:`, body);
|
|
295
220
|
try {
|
|
296
221
|
const response = await this.makeProfileMutationRequest({
|
|
@@ -298,7 +223,7 @@ class ExperienceApiClient extends src_ApiClientBase {
|
|
|
298
223
|
body,
|
|
299
224
|
options
|
|
300
225
|
});
|
|
301
|
-
const { data: { changes, experiences, profile } } = __rspack_external__contentful_optimization_api_schemas_66dcf407.ExperienceResponse
|
|
226
|
+
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
227
|
const data = {
|
|
303
228
|
changes,
|
|
304
229
|
personalizations: experiences,
|
|
@@ -325,10 +250,10 @@ class ExperienceApiClient extends src_ApiClientBase {
|
|
|
325
250
|
async upsertManyProfiles({ events }, options = {}) {
|
|
326
251
|
const requestName = 'Upsert Many Profiles';
|
|
327
252
|
ExperienceApiClient_logger.info(`Sending "${requestName}" request`);
|
|
328
|
-
const body = {
|
|
329
|
-
events
|
|
253
|
+
const body = (0, __rspack_external__contentful_optimization_api_schemas_66dcf407.parseWithFriendlyError)(__rspack_external__contentful_optimization_api_schemas_66dcf407.BatchExperienceRequestData, {
|
|
254
|
+
events,
|
|
330
255
|
options: this.constructBodyOptions(options)
|
|
331
|
-
};
|
|
256
|
+
});
|
|
332
257
|
ExperienceApiClient_logger.debug(`"${requestName}" request body:`, body);
|
|
333
258
|
try {
|
|
334
259
|
const response = await this.makeProfileMutationRequest({
|
|
@@ -339,7 +264,7 @@ class ExperienceApiClient extends src_ApiClientBase {
|
|
|
339
264
|
...options
|
|
340
265
|
}
|
|
341
266
|
});
|
|
342
|
-
const { data: { profiles } } = __rspack_external__contentful_optimization_api_schemas_66dcf407.BatchExperienceResponse
|
|
267
|
+
const { data: { profiles } } = (0, __rspack_external__contentful_optimization_api_schemas_66dcf407.parseWithFriendlyError)(__rspack_external__contentful_optimization_api_schemas_66dcf407.BatchExperienceResponse, await response.json());
|
|
343
268
|
ExperienceApiClient_logger.debug(`"${requestName}" request successfully completed`);
|
|
344
269
|
return profiles;
|
|
345
270
|
} catch (error) {
|
|
@@ -373,6 +298,12 @@ class ExperienceApiClient extends src_ApiClientBase {
|
|
|
373
298
|
];
|
|
374
299
|
return bodyOptions;
|
|
375
300
|
};
|
|
301
|
+
constructExperienceRequestBody(events, options) {
|
|
302
|
+
return __rspack_external__contentful_optimization_api_schemas_66dcf407.ExperienceRequestData.parse({
|
|
303
|
+
events: (0, __rspack_external__contentful_optimization_api_schemas_66dcf407.parseWithFriendlyError)(__rspack_external__contentful_optimization_api_schemas_66dcf407.ExperienceEventArray, events),
|
|
304
|
+
options: this.constructBodyOptions(options)
|
|
305
|
+
});
|
|
306
|
+
}
|
|
376
307
|
}
|
|
377
308
|
const experience = ExperienceApiClient;
|
|
378
309
|
const InsightsApiClient_logger = createScopedLogger('ApiClient:Insights');
|
|
@@ -389,7 +320,7 @@ class InsightsApiClient extends src_ApiClientBase {
|
|
|
389
320
|
async sendBatchEvents(batches, options = {}) {
|
|
390
321
|
const { beaconHandler = this.beaconHandler } = options;
|
|
391
322
|
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
|
|
323
|
+
const body = (0, __rspack_external__contentful_optimization_api_schemas_66dcf407.parseWithFriendlyError)(__rspack_external__contentful_optimization_api_schemas_66dcf407.BatchInsightsEventArray, batches);
|
|
393
324
|
if ('function' == typeof beaconHandler) {
|
|
394
325
|
InsightsApiClient_logger.debug('Queueing events via beaconHandler');
|
|
395
326
|
const beaconSuccessfullyQueued = beaconHandler(url, body);
|
|
@@ -424,7 +355,12 @@ class ApiClient {
|
|
|
424
355
|
experience;
|
|
425
356
|
insights;
|
|
426
357
|
constructor(config){
|
|
427
|
-
const { personalization, analytics,
|
|
358
|
+
const { personalization, analytics, clientId, environment, fetchOptions } = config;
|
|
359
|
+
const apiConfig = {
|
|
360
|
+
clientId,
|
|
361
|
+
environment,
|
|
362
|
+
fetchOptions
|
|
363
|
+
};
|
|
428
364
|
this.config = apiConfig;
|
|
429
365
|
this.experience = new experience({
|
|
430
366
|
...apiConfig,
|
|
@@ -444,11 +380,20 @@ const UniversalEventBuilderArgs = object({
|
|
|
444
380
|
screen: optional(__rspack_external__contentful_optimization_api_schemas_66dcf407.Screen),
|
|
445
381
|
userAgent: optional(string())
|
|
446
382
|
});
|
|
447
|
-
const
|
|
383
|
+
const ComponentInteractionBuilderArgsBase = extend(UniversalEventBuilderArgs, {
|
|
448
384
|
componentId: string(),
|
|
449
385
|
experienceId: optional(string()),
|
|
450
|
-
variantIndex: optional(number())
|
|
451
|
-
|
|
386
|
+
variantIndex: optional(number())
|
|
387
|
+
});
|
|
388
|
+
const ComponentViewBuilderArgs = extend(ComponentInteractionBuilderArgsBase, {
|
|
389
|
+
sticky: optional(mini_boolean()),
|
|
390
|
+
componentViewId: string(),
|
|
391
|
+
viewDurationMs: number()
|
|
392
|
+
});
|
|
393
|
+
const ComponentClickBuilderArgs = ComponentInteractionBuilderArgsBase;
|
|
394
|
+
const ComponentHoverBuilderArgs = extend(ComponentInteractionBuilderArgsBase, {
|
|
395
|
+
componentHoverId: string(),
|
|
396
|
+
hoverDurationMs: number()
|
|
452
397
|
});
|
|
453
398
|
const IdentifyBuilderArgs = extend(UniversalEventBuilderArgs, {
|
|
454
399
|
traits: optional(__rspack_external__contentful_optimization_api_schemas_66dcf407.Traits),
|
|
@@ -512,17 +457,40 @@ class EventBuilder {
|
|
|
512
457
|
timestamp
|
|
513
458
|
};
|
|
514
459
|
}
|
|
515
|
-
|
|
516
|
-
const { componentId, experienceId, variantIndex, ...universal } = ComponentViewBuilderArgs.parse(args);
|
|
460
|
+
buildEntryComponentBase(universal, componentId, experienceId, variantIndex) {
|
|
517
461
|
return {
|
|
518
462
|
...this.buildUniversalEventProperties(universal),
|
|
519
|
-
type: 'component',
|
|
520
463
|
componentType: 'Entry',
|
|
521
464
|
componentId,
|
|
522
465
|
experienceId,
|
|
523
466
|
variantIndex: variantIndex ?? 0
|
|
524
467
|
};
|
|
525
468
|
}
|
|
469
|
+
buildComponentView(args) {
|
|
470
|
+
const { componentId, componentViewId, experienceId, variantIndex, viewDurationMs, ...universal } = (0, __rspack_external__contentful_optimization_api_schemas_66dcf407.parseWithFriendlyError)(ComponentViewBuilderArgs, args);
|
|
471
|
+
return {
|
|
472
|
+
...this.buildEntryComponentBase(universal, componentId, experienceId, variantIndex),
|
|
473
|
+
type: 'component',
|
|
474
|
+
componentViewId,
|
|
475
|
+
viewDurationMs
|
|
476
|
+
};
|
|
477
|
+
}
|
|
478
|
+
buildComponentClick(args) {
|
|
479
|
+
const { componentId, experienceId, variantIndex, ...universal } = (0, __rspack_external__contentful_optimization_api_schemas_66dcf407.parseWithFriendlyError)(ComponentClickBuilderArgs, args);
|
|
480
|
+
return {
|
|
481
|
+
...this.buildEntryComponentBase(universal, componentId, experienceId, variantIndex),
|
|
482
|
+
type: 'component_click'
|
|
483
|
+
};
|
|
484
|
+
}
|
|
485
|
+
buildComponentHover(args) {
|
|
486
|
+
const { componentHoverId, componentId, experienceId, hoverDurationMs, variantIndex, ...universal } = (0, __rspack_external__contentful_optimization_api_schemas_66dcf407.parseWithFriendlyError)(ComponentHoverBuilderArgs, args);
|
|
487
|
+
return {
|
|
488
|
+
...this.buildEntryComponentBase(universal, componentId, experienceId, variantIndex),
|
|
489
|
+
type: 'component_hover',
|
|
490
|
+
componentHoverId,
|
|
491
|
+
hoverDurationMs
|
|
492
|
+
};
|
|
493
|
+
}
|
|
526
494
|
buildFlagView(args) {
|
|
527
495
|
return {
|
|
528
496
|
...this.buildComponentView(args),
|
|
@@ -530,7 +498,7 @@ class EventBuilder {
|
|
|
530
498
|
};
|
|
531
499
|
}
|
|
532
500
|
buildIdentify(args) {
|
|
533
|
-
const { traits = {}, userId, ...universal } =
|
|
501
|
+
const { traits = {}, userId, ...universal } = (0, __rspack_external__contentful_optimization_api_schemas_66dcf407.parseWithFriendlyError)(IdentifyBuilderArgs, args);
|
|
534
502
|
return {
|
|
535
503
|
...this.buildUniversalEventProperties(universal),
|
|
536
504
|
type: 'identify',
|
|
@@ -539,14 +507,14 @@ class EventBuilder {
|
|
|
539
507
|
};
|
|
540
508
|
}
|
|
541
509
|
buildPageView(args = {}) {
|
|
542
|
-
const { properties = {}, ...universal } =
|
|
510
|
+
const { properties = {}, ...universal } = (0, __rspack_external__contentful_optimization_api_schemas_66dcf407.parseWithFriendlyError)(PageViewBuilderArgs, args);
|
|
543
511
|
const pageProperties = this.getPageProperties();
|
|
544
512
|
const merged = merge({
|
|
545
513
|
...pageProperties,
|
|
546
514
|
title: pageProperties.title ?? DEFAULT_PAGE_PROPERTIES.title
|
|
547
515
|
}, properties);
|
|
548
516
|
const { context: { screen: _, ...universalContext }, ...universalProperties } = this.buildUniversalEventProperties(universal);
|
|
549
|
-
const context = __rspack_external__contentful_optimization_api_schemas_66dcf407.PageEventContext
|
|
517
|
+
const context = (0, __rspack_external__contentful_optimization_api_schemas_66dcf407.parseWithFriendlyError)(__rspack_external__contentful_optimization_api_schemas_66dcf407.PageEventContext, universalContext);
|
|
550
518
|
return {
|
|
551
519
|
...universalProperties,
|
|
552
520
|
context,
|
|
@@ -555,9 +523,9 @@ class EventBuilder {
|
|
|
555
523
|
};
|
|
556
524
|
}
|
|
557
525
|
buildScreenView(args) {
|
|
558
|
-
const { name, properties, ...universal } =
|
|
526
|
+
const { name, properties, ...universal } = (0, __rspack_external__contentful_optimization_api_schemas_66dcf407.parseWithFriendlyError)(ScreenViewBuilderArgs, args);
|
|
559
527
|
const { context: { page: _, ...universalContext }, ...universalProperties } = this.buildUniversalEventProperties(universal);
|
|
560
|
-
const context = __rspack_external__contentful_optimization_api_schemas_66dcf407.ScreenEventContext
|
|
528
|
+
const context = (0, __rspack_external__contentful_optimization_api_schemas_66dcf407.parseWithFriendlyError)(__rspack_external__contentful_optimization_api_schemas_66dcf407.ScreenEventContext, universalContext);
|
|
561
529
|
return {
|
|
562
530
|
...universalProperties,
|
|
563
531
|
context,
|
|
@@ -567,7 +535,7 @@ class EventBuilder {
|
|
|
567
535
|
};
|
|
568
536
|
}
|
|
569
537
|
buildTrack(args) {
|
|
570
|
-
const { event, properties = {}, ...universal } =
|
|
538
|
+
const { event, properties = {}, ...universal } = (0, __rspack_external__contentful_optimization_api_schemas_66dcf407.parseWithFriendlyError)(TrackBuilderArgs, args);
|
|
571
539
|
return {
|
|
572
540
|
...this.buildUniversalEventProperties(universal),
|
|
573
541
|
type: 'track',
|
|
@@ -577,7 +545,6 @@ class EventBuilder {
|
|
|
577
545
|
}
|
|
578
546
|
}
|
|
579
547
|
const builders_EventBuilder = EventBuilder;
|
|
580
|
-
export * from "@contentful/optimization-api-schemas";
|
|
581
548
|
export { ApiClient, DEFAULT_PAGE_PROPERTIES, EXPERIENCE_BASE_URL, INSIGHTS_BASE_URL, builders_EventBuilder as EventBuilder };
|
|
582
549
|
|
|
583
550
|
//# sourceMappingURL=index.mjs.map
|