@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.
Files changed (79) hide show
  1. package/README.md +55 -24
  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 +588 -575
  12. package/dist/index.cjs.map +1 -1
  13. package/dist/index.d.cts +1649 -0
  14. package/dist/index.d.mts +1649 -0
  15. package/dist/index.d.ts +1649 -8
  16. package/dist/index.mjs +103 -136
  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 +33 -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 -143
  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
@@ -1,94 +0,0 @@
1
- import { createScopedLogger } from 'logger';
2
- import Fetch from './fetch';
3
- const logger = createScopedLogger('ApiClient');
4
- /**
5
- * Default Contentful environment used when none is explicitly provided.
6
- *
7
- * @internal
8
- */
9
- const DEFAULT_ENVIRONMENT = 'main';
10
- /**
11
- * Base class for API clients that provides shared configuration and error logging.
12
- *
13
- * @internal
14
- *
15
- * @remarks
16
- * This abstract class is intended for internal use within the package and
17
- * should not be treated as part of the public API surface.
18
- *
19
- * Concrete API clients should extend this class to inherit consistent logging
20
- * behavior and fetch configuration.
21
- *
22
- * @example
23
- * ```ts
24
- * interface MyClientConfig extends ApiConfig {
25
- * // additional config
26
- * }
27
- *
28
- * class MyClient extends ApiClientBase {
29
- * constructor(config: MyClientConfig) {
30
- * super('MyClient', config)
31
- * }
32
- *
33
- * async getSomething() {
34
- * const response = await this.fetch('https://example.com', { method: 'GET' })
35
- * return response.json()
36
- * }
37
- * }
38
- * ```
39
- */
40
- class ApiClientBase {
41
- /**
42
- * Name of the API client, used in log messages and as the `apiName` for fetch.
43
- */
44
- name;
45
- /**
46
- * Client identifier used for authentication or tracking.
47
- */
48
- clientId;
49
- /**
50
- * Contentful environment associated with this client.
51
- */
52
- environment;
53
- /**
54
- * Protected fetch method used by the client to perform HTTP requests.
55
- */
56
- fetch;
57
- /**
58
- * Creates a new API client base instance.
59
- *
60
- * @param name - Human-readable name of the client (used for logging and `apiName`).
61
- * @param config - Configuration options for the client.
62
- */
63
- constructor(name, { fetchOptions, clientId, environment }) {
64
- this.clientId = clientId;
65
- this.environment = environment ?? DEFAULT_ENVIRONMENT;
66
- this.name = name;
67
- this.fetch = Fetch.create({ ...(fetchOptions ?? {}), apiName: name });
68
- }
69
- /**
70
- * Logs errors that occur during API requests with standardized messages.
71
- *
72
- * @param error - The error thrown by the underlying operation.
73
- * @param options - Additional metadata about the request.
74
- * @param options.requestName - Human-readable name of the request operation.
75
- *
76
- * @protected
77
- *
78
- * @remarks
79
- * Abort errors are logged at `warn` level and other errors at `error` level.
80
- * The log message includes the client name for better debugging context.
81
- */
82
- logRequestError(error, { requestName }) {
83
- if (error instanceof Error) {
84
- if (error.name === 'AbortError') {
85
- logger.warn(`[${this.name}] "${requestName}" request aborted due to network issues. This request may not be retried.`);
86
- }
87
- else {
88
- logger.error(`[${this.name}] "${requestName}" request failed:`, error);
89
- }
90
- }
91
- }
92
- }
93
- export default ApiClientBase;
94
- //# sourceMappingURL=ApiClientBase.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ApiClientBase.js","sourceRoot":"","sources":["../src/ApiClientBase.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,QAAQ,CAAA;AAC3C,OAAO,KAA6D,MAAM,SAAS,CAAA;AAEnF,MAAM,MAAM,GAAG,kBAAkB,CAAC,WAAW,CAAC,CAAA;AAE9C;;;;GAIG;AACH,MAAM,mBAAmB,GAAG,MAAM,CAAA;AA8ClC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAe,aAAa;IAC1B;;OAEG;IACgB,IAAI,CAAQ;IAE/B;;OAEG;IACgB,QAAQ,CAAQ;IAEnC;;OAEG;IACgB,WAAW,CAAQ;IAEtC;;OAEG;IACgB,KAAK,CAAa;IAErC;;;;;OAKG;IACH,YAAY,IAAY,EAAE,EAAE,YAAY,EAAE,QAAQ,EAAE,WAAW,EAAa;QAC1E,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;QACxB,IAAI,CAAC,WAAW,GAAG,WAAW,IAAI,mBAAmB,CAAA;QACrD,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAEhB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,EAAE,GAAG,CAAC,YAAY,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAA;IACvE,CAAC;IAED;;;;;;;;;;;;OAYG;IACO,eAAe,CAAC,KAAc,EAAE,EAAE,WAAW,EAA2B;QAChF,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;YAC3B,IAAI,KAAK,CAAC,IAAI,KAAK,YAAY,EAAE,CAAC;gBAChC,MAAM,CAAC,IAAI,CACT,IAAI,IAAI,CAAC,IAAI,MAAM,WAAW,2EAA2E,CAC1G,CAAA;YACH,CAAC;iBAAM,CAAC;gBACN,MAAM,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC,IAAI,MAAM,WAAW,mBAAmB,EAAE,KAAK,CAAC,CAAA;YACxE,CAAC;QACH,CAAC;IACH,CAAC;CACF;AAED,eAAe,aAAa,CAAA"}
@@ -1,589 +0,0 @@
1
- import { type App, type Channel, type ComponentViewEvent, type IdentifyEvent, type Library, Page, type PageViewEvent, type ScreenViewEvent, type TrackEvent, type UniversalEventProperties } from '@contentful/optimization-api-schemas';
2
- import * as z from 'zod/mini';
3
- /**
4
- * Configuration options for creating an {@link EventBuilder} instance.
5
- *
6
- * @public
7
- * @remarks
8
- * The configuration is typically provided by the host application to adapt
9
- * event payloads to the runtime environment (browser, framework, etc.).
10
- *
11
- * @example
12
- * ```ts
13
- * const builder = new EventBuilder({
14
- * app: { name: 'my-app', version: '1.0.0' },
15
- * channel: 'web',
16
- * library: { name: '@contentful/optimization-sdk', version: '1.2.3' },
17
- * getLocale: () => navigator.language,
18
- * getPageProperties: () => ({
19
- * path: window.location.pathname,
20
- * url: window.location.href,
21
- * title: document.title,
22
- * query: {},
23
- * referrer: document.referrer,
24
- * search: window.location.search,
25
- * }),
26
- * })
27
- * ```
28
- */
29
- export interface EventBuilderConfig {
30
- /**
31
- * The application definition used to attribute events to a specific consumer app.
32
- *
33
- * @remarks
34
- * When not provided, events will not contain app metadata in their context.
35
- */
36
- app?: App;
37
- /**
38
- * The channel that identifies where events originate from (e.g. web, mobile).
39
- *
40
- * @see {@link Channel}
41
- */
42
- channel: Channel;
43
- /**
44
- * The client library metadata that is attached to all events.
45
- *
46
- * @remarks
47
- * This is typically used to record the library name and version.
48
- */
49
- library: Library;
50
- /**
51
- * Function used to resolve the locale for outgoing events.
52
- *
53
- * @remarks
54
- * If not provided, the builder falls back to the default `'en-US'`. Locale
55
- * values supplied directly as arguments to event builder methods take
56
- * precedence.
57
- *
58
- * @returns The locale string (e.g. `'en-US'`), or `undefined` if unavailable.
59
- */
60
- getLocale?: () => string | undefined;
61
- /**
62
- * Function that returns the current page properties.
63
- *
64
- * @remarks
65
- * Page properties are currently added to the context of all events, as well
66
- * as the `properties` of the page event. When specified, all properties of
67
- * the `Page` type are required, but may contain empty values.
68
- *
69
- * @returns A {@link Page} object containing information about the current page.
70
- * @see {@link Page}
71
- */
72
- getPageProperties?: () => Page;
73
- /**
74
- * Function used to obtain the current user agent string when applicable.
75
- *
76
- * @returns A user agent string, or `undefined` if unavailable.
77
- */
78
- getUserAgent?: () => string | undefined;
79
- }
80
- declare const UniversalEventBuilderArgs: z.ZodMiniObject<{
81
- campaign: z.ZodMiniOptional<z.ZodMiniObject<{
82
- name: z.ZodMiniOptional<z.ZodMiniString<string>>;
83
- source: z.ZodMiniOptional<z.ZodMiniString<string>>;
84
- medium: z.ZodMiniOptional<z.ZodMiniString<string>>;
85
- term: z.ZodMiniOptional<z.ZodMiniString<string>>;
86
- content: z.ZodMiniOptional<z.ZodMiniString<string>>;
87
- }, z.core.$strip>>;
88
- locale: z.ZodMiniOptional<z.ZodMiniString<string>>;
89
- location: z.ZodMiniOptional<z.ZodMiniObject<{
90
- coordinates: z.ZodMiniOptional<z.ZodMiniObject<{
91
- latitude: z.ZodMiniNumber<number>;
92
- longitude: z.ZodMiniNumber<number>;
93
- }, z.core.$strip>>;
94
- city: z.ZodMiniOptional<z.ZodMiniString<string>>;
95
- postalCode: z.ZodMiniOptional<z.ZodMiniString<string>>;
96
- region: z.ZodMiniOptional<z.ZodMiniString<string>>;
97
- regionCode: z.ZodMiniOptional<z.ZodMiniString<string>>;
98
- country: z.ZodMiniOptional<z.ZodMiniString<string>>;
99
- countryCode: z.ZodMiniOptional<z.ZodMiniString<string>>;
100
- continent: z.ZodMiniOptional<z.ZodMiniString<string>>;
101
- timezone: z.ZodMiniOptional<z.ZodMiniString<string>>;
102
- }, z.core.$strip>>;
103
- page: z.ZodMiniOptional<z.ZodMiniObject<{
104
- path: z.ZodMiniString<string>;
105
- query: z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniString<string>>;
106
- referrer: z.ZodMiniString<string>;
107
- search: z.ZodMiniString<string>;
108
- title: z.ZodMiniOptional<z.ZodMiniString<string>>;
109
- url: z.ZodMiniString<string>;
110
- }, z.core.$catchall<z.ZodMiniJSONSchema>>>;
111
- screen: z.ZodMiniOptional<z.ZodMiniObject<{
112
- name: z.ZodMiniString<string>;
113
- }, z.core.$catchall<z.ZodMiniJSONSchema>>>;
114
- userAgent: z.ZodMiniOptional<z.ZodMiniString<string>>;
115
- }, z.core.$strip>;
116
- /**
117
- * Arguments used to construct the universal (shared) portion of all events.
118
- *
119
- * @public
120
- */
121
- export type UniversalEventBuilderArgs = z.infer<typeof UniversalEventBuilderArgs>;
122
- declare const ComponentViewBuilderArgs: z.ZodMiniObject<{
123
- campaign: z.ZodMiniOptional<z.ZodMiniObject<{
124
- name: z.ZodMiniOptional<z.ZodMiniString<string>>;
125
- source: z.ZodMiniOptional<z.ZodMiniString<string>>;
126
- medium: z.ZodMiniOptional<z.ZodMiniString<string>>;
127
- term: z.ZodMiniOptional<z.ZodMiniString<string>>;
128
- content: z.ZodMiniOptional<z.ZodMiniString<string>>;
129
- }, z.core.$strip>>;
130
- locale: z.ZodMiniOptional<z.ZodMiniString<string>>;
131
- location: z.ZodMiniOptional<z.ZodMiniObject<{
132
- coordinates: z.ZodMiniOptional<z.ZodMiniObject<{
133
- latitude: z.ZodMiniNumber<number>;
134
- longitude: z.ZodMiniNumber<number>;
135
- }, z.core.$strip>>;
136
- city: z.ZodMiniOptional<z.ZodMiniString<string>>;
137
- postalCode: z.ZodMiniOptional<z.ZodMiniString<string>>;
138
- region: z.ZodMiniOptional<z.ZodMiniString<string>>;
139
- regionCode: z.ZodMiniOptional<z.ZodMiniString<string>>;
140
- country: z.ZodMiniOptional<z.ZodMiniString<string>>;
141
- countryCode: z.ZodMiniOptional<z.ZodMiniString<string>>;
142
- continent: z.ZodMiniOptional<z.ZodMiniString<string>>;
143
- timezone: z.ZodMiniOptional<z.ZodMiniString<string>>;
144
- }, z.core.$strip>>;
145
- page: z.ZodMiniOptional<z.ZodMiniObject<{
146
- path: z.ZodMiniString<string>;
147
- query: z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniString<string>>;
148
- referrer: z.ZodMiniString<string>;
149
- search: z.ZodMiniString<string>;
150
- title: z.ZodMiniOptional<z.ZodMiniString<string>>;
151
- url: z.ZodMiniString<string>;
152
- }, z.core.$catchall<z.ZodMiniJSONSchema>>>;
153
- screen: z.ZodMiniOptional<z.ZodMiniObject<{
154
- name: z.ZodMiniString<string>;
155
- }, z.core.$catchall<z.ZodMiniJSONSchema>>>;
156
- userAgent: z.ZodMiniOptional<z.ZodMiniString<string>>;
157
- componentId: z.ZodMiniString<string>;
158
- experienceId: z.ZodMiniOptional<z.ZodMiniString<string>>;
159
- variantIndex: z.ZodMiniOptional<z.ZodMiniNumber<number>>;
160
- sticky: z.ZodMiniOptional<z.ZodMiniBoolean<boolean>>;
161
- }, z.core.$strip>;
162
- /**
163
- * Arguments for constructing component view events.
164
- *
165
- * @public
166
- */
167
- export type ComponentViewBuilderArgs = z.infer<typeof ComponentViewBuilderArgs>;
168
- declare const IdentifyBuilderArgs: z.ZodMiniObject<{
169
- campaign: z.ZodMiniOptional<z.ZodMiniObject<{
170
- name: z.ZodMiniOptional<z.ZodMiniString<string>>;
171
- source: z.ZodMiniOptional<z.ZodMiniString<string>>;
172
- medium: z.ZodMiniOptional<z.ZodMiniString<string>>;
173
- term: z.ZodMiniOptional<z.ZodMiniString<string>>;
174
- content: z.ZodMiniOptional<z.ZodMiniString<string>>;
175
- }, z.core.$strip>>;
176
- locale: z.ZodMiniOptional<z.ZodMiniString<string>>;
177
- location: z.ZodMiniOptional<z.ZodMiniObject<{
178
- coordinates: z.ZodMiniOptional<z.ZodMiniObject<{
179
- latitude: z.ZodMiniNumber<number>;
180
- longitude: z.ZodMiniNumber<number>;
181
- }, z.core.$strip>>;
182
- city: z.ZodMiniOptional<z.ZodMiniString<string>>;
183
- postalCode: z.ZodMiniOptional<z.ZodMiniString<string>>;
184
- region: z.ZodMiniOptional<z.ZodMiniString<string>>;
185
- regionCode: z.ZodMiniOptional<z.ZodMiniString<string>>;
186
- country: z.ZodMiniOptional<z.ZodMiniString<string>>;
187
- countryCode: z.ZodMiniOptional<z.ZodMiniString<string>>;
188
- continent: z.ZodMiniOptional<z.ZodMiniString<string>>;
189
- timezone: z.ZodMiniOptional<z.ZodMiniString<string>>;
190
- }, z.core.$strip>>;
191
- page: z.ZodMiniOptional<z.ZodMiniObject<{
192
- path: z.ZodMiniString<string>;
193
- query: z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniString<string>>;
194
- referrer: z.ZodMiniString<string>;
195
- search: z.ZodMiniString<string>;
196
- title: z.ZodMiniOptional<z.ZodMiniString<string>>;
197
- url: z.ZodMiniString<string>;
198
- }, z.core.$catchall<z.ZodMiniJSONSchema>>>;
199
- screen: z.ZodMiniOptional<z.ZodMiniObject<{
200
- name: z.ZodMiniString<string>;
201
- }, z.core.$catchall<z.ZodMiniJSONSchema>>>;
202
- userAgent: z.ZodMiniOptional<z.ZodMiniString<string>>;
203
- traits: z.ZodMiniOptional<z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniJSONSchema>>;
204
- userId: z.ZodMiniString<string>;
205
- }, z.core.$strip>;
206
- /**
207
- * Arguments for constructing identify events.
208
- *
209
- * @public
210
- * @remarks
211
- * Traits are merged by the API; only specified properties may be overwritten.
212
- */
213
- export type IdentifyBuilderArgs = z.infer<typeof IdentifyBuilderArgs>;
214
- declare const PageViewBuilderArgs: z.ZodMiniObject<{
215
- campaign: z.ZodMiniOptional<z.ZodMiniObject<{
216
- name: z.ZodMiniOptional<z.ZodMiniString<string>>;
217
- source: z.ZodMiniOptional<z.ZodMiniString<string>>;
218
- medium: z.ZodMiniOptional<z.ZodMiniString<string>>;
219
- term: z.ZodMiniOptional<z.ZodMiniString<string>>;
220
- content: z.ZodMiniOptional<z.ZodMiniString<string>>;
221
- }, z.core.$strip>>;
222
- locale: z.ZodMiniOptional<z.ZodMiniString<string>>;
223
- location: z.ZodMiniOptional<z.ZodMiniObject<{
224
- coordinates: z.ZodMiniOptional<z.ZodMiniObject<{
225
- latitude: z.ZodMiniNumber<number>;
226
- longitude: z.ZodMiniNumber<number>;
227
- }, z.core.$strip>>;
228
- city: z.ZodMiniOptional<z.ZodMiniString<string>>;
229
- postalCode: z.ZodMiniOptional<z.ZodMiniString<string>>;
230
- region: z.ZodMiniOptional<z.ZodMiniString<string>>;
231
- regionCode: z.ZodMiniOptional<z.ZodMiniString<string>>;
232
- country: z.ZodMiniOptional<z.ZodMiniString<string>>;
233
- countryCode: z.ZodMiniOptional<z.ZodMiniString<string>>;
234
- continent: z.ZodMiniOptional<z.ZodMiniString<string>>;
235
- timezone: z.ZodMiniOptional<z.ZodMiniString<string>>;
236
- }, z.core.$strip>>;
237
- page: z.ZodMiniOptional<z.ZodMiniObject<{
238
- path: z.ZodMiniString<string>;
239
- query: z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniString<string>>;
240
- referrer: z.ZodMiniString<string>;
241
- search: z.ZodMiniString<string>;
242
- title: z.ZodMiniOptional<z.ZodMiniString<string>>;
243
- url: z.ZodMiniString<string>;
244
- }, z.core.$catchall<z.ZodMiniJSONSchema>>>;
245
- screen: z.ZodMiniOptional<z.ZodMiniObject<{
246
- name: z.ZodMiniString<string>;
247
- }, z.core.$catchall<z.ZodMiniJSONSchema>>>;
248
- userAgent: z.ZodMiniOptional<z.ZodMiniString<string>>;
249
- properties: z.ZodMiniOptional<z.ZodMiniObject<{
250
- path: z.ZodMiniOptional<z.ZodMiniString<string>>;
251
- query: z.ZodMiniOptional<z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniString<string>>>;
252
- referrer: z.ZodMiniOptional<z.ZodMiniString<string>>;
253
- search: z.ZodMiniOptional<z.ZodMiniString<string>>;
254
- title: z.ZodMiniOptional<z.ZodMiniOptional<z.ZodMiniString<string>>>;
255
- url: z.ZodMiniOptional<z.ZodMiniString<string>>;
256
- }, z.core.$catchall<z.ZodMiniJSONSchema>>>;
257
- }, z.core.$strip>;
258
- /**
259
- * Arguments for constructing page view events.
260
- *
261
- * @public
262
- * @remarks
263
- * Any properties passed here are merged with the base page properties from
264
- * {@link EventBuilderConfig.getPageProperties}.
265
- */
266
- export type PageViewBuilderArgs = z.infer<typeof PageViewBuilderArgs>;
267
- declare const ScreenViewBuilderArgs: z.ZodMiniObject<{
268
- campaign: z.ZodMiniOptional<z.ZodMiniObject<{
269
- name: z.ZodMiniOptional<z.ZodMiniString<string>>;
270
- source: z.ZodMiniOptional<z.ZodMiniString<string>>;
271
- medium: z.ZodMiniOptional<z.ZodMiniString<string>>;
272
- term: z.ZodMiniOptional<z.ZodMiniString<string>>;
273
- content: z.ZodMiniOptional<z.ZodMiniString<string>>;
274
- }, z.core.$strip>>;
275
- locale: z.ZodMiniOptional<z.ZodMiniString<string>>;
276
- location: z.ZodMiniOptional<z.ZodMiniObject<{
277
- coordinates: z.ZodMiniOptional<z.ZodMiniObject<{
278
- latitude: z.ZodMiniNumber<number>;
279
- longitude: z.ZodMiniNumber<number>;
280
- }, z.core.$strip>>;
281
- city: z.ZodMiniOptional<z.ZodMiniString<string>>;
282
- postalCode: z.ZodMiniOptional<z.ZodMiniString<string>>;
283
- region: z.ZodMiniOptional<z.ZodMiniString<string>>;
284
- regionCode: z.ZodMiniOptional<z.ZodMiniString<string>>;
285
- country: z.ZodMiniOptional<z.ZodMiniString<string>>;
286
- countryCode: z.ZodMiniOptional<z.ZodMiniString<string>>;
287
- continent: z.ZodMiniOptional<z.ZodMiniString<string>>;
288
- timezone: z.ZodMiniOptional<z.ZodMiniString<string>>;
289
- }, z.core.$strip>>;
290
- page: z.ZodMiniOptional<z.ZodMiniObject<{
291
- path: z.ZodMiniString<string>;
292
- query: z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniString<string>>;
293
- referrer: z.ZodMiniString<string>;
294
- search: z.ZodMiniString<string>;
295
- title: z.ZodMiniOptional<z.ZodMiniString<string>>;
296
- url: z.ZodMiniString<string>;
297
- }, z.core.$catchall<z.ZodMiniJSONSchema>>>;
298
- screen: z.ZodMiniOptional<z.ZodMiniObject<{
299
- name: z.ZodMiniString<string>;
300
- }, z.core.$catchall<z.ZodMiniJSONSchema>>>;
301
- userAgent: z.ZodMiniOptional<z.ZodMiniString<string>>;
302
- name: z.ZodMiniString<string>;
303
- properties: z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniJSONSchema>;
304
- }, z.core.$strip>;
305
- /**
306
- * Arguments for constructing screen view events.
307
- *
308
- * @public
309
- * @remarks
310
- * Any properties passed here are merged with the base screen properties from
311
- * {@link EventBuilderConfig.getScreenProperties}.
312
- */
313
- export type ScreenViewBuilderArgs = z.infer<typeof ScreenViewBuilderArgs>;
314
- declare const TrackBuilderArgs: z.ZodMiniObject<{
315
- campaign: z.ZodMiniOptional<z.ZodMiniObject<{
316
- name: z.ZodMiniOptional<z.ZodMiniString<string>>;
317
- source: z.ZodMiniOptional<z.ZodMiniString<string>>;
318
- medium: z.ZodMiniOptional<z.ZodMiniString<string>>;
319
- term: z.ZodMiniOptional<z.ZodMiniString<string>>;
320
- content: z.ZodMiniOptional<z.ZodMiniString<string>>;
321
- }, z.core.$strip>>;
322
- locale: z.ZodMiniOptional<z.ZodMiniString<string>>;
323
- location: z.ZodMiniOptional<z.ZodMiniObject<{
324
- coordinates: z.ZodMiniOptional<z.ZodMiniObject<{
325
- latitude: z.ZodMiniNumber<number>;
326
- longitude: z.ZodMiniNumber<number>;
327
- }, z.core.$strip>>;
328
- city: z.ZodMiniOptional<z.ZodMiniString<string>>;
329
- postalCode: z.ZodMiniOptional<z.ZodMiniString<string>>;
330
- region: z.ZodMiniOptional<z.ZodMiniString<string>>;
331
- regionCode: z.ZodMiniOptional<z.ZodMiniString<string>>;
332
- country: z.ZodMiniOptional<z.ZodMiniString<string>>;
333
- countryCode: z.ZodMiniOptional<z.ZodMiniString<string>>;
334
- continent: z.ZodMiniOptional<z.ZodMiniString<string>>;
335
- timezone: z.ZodMiniOptional<z.ZodMiniString<string>>;
336
- }, z.core.$strip>>;
337
- page: z.ZodMiniOptional<z.ZodMiniObject<{
338
- path: z.ZodMiniString<string>;
339
- query: z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniString<string>>;
340
- referrer: z.ZodMiniString<string>;
341
- search: z.ZodMiniString<string>;
342
- title: z.ZodMiniOptional<z.ZodMiniString<string>>;
343
- url: z.ZodMiniString<string>;
344
- }, z.core.$catchall<z.ZodMiniJSONSchema>>>;
345
- screen: z.ZodMiniOptional<z.ZodMiniObject<{
346
- name: z.ZodMiniString<string>;
347
- }, z.core.$catchall<z.ZodMiniJSONSchema>>>;
348
- userAgent: z.ZodMiniOptional<z.ZodMiniString<string>>;
349
- event: z.ZodMiniString<string>;
350
- properties: z.ZodMiniOptional<z.ZodMiniPrefault<z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniJSONSchema>>>;
351
- }, z.core.$strip>;
352
- /**
353
- * Arguments for constructing track events.
354
- *
355
- * @public
356
- */
357
- export type TrackBuilderArgs = z.infer<typeof TrackBuilderArgs>;
358
- /**
359
- * Default page properties used when no explicit page information is available.
360
- *
361
- * @public
362
- *
363
- * @defaultValue
364
- * ```ts
365
- * {
366
- * path: '',
367
- * query: {},
368
- * referrer: '',
369
- * search: '',
370
- * title: '',
371
- * url: '',
372
- * }
373
- * ```
374
- *
375
- * @remarks
376
- * Values are required by the API; values may not be `undefined`. Empty values are valid.
377
- */
378
- export declare const DEFAULT_PAGE_PROPERTIES: {
379
- path: string;
380
- query: {};
381
- referrer: string;
382
- search: string;
383
- title: string;
384
- url: string;
385
- };
386
- /**
387
- * Internal helper class for building analytics and personalization events.
388
- *
389
- * @remarks
390
- * This class coordinates configuration and argument validation to produce
391
- * strongly-typed event payloads compatible with
392
- * `@contentful/optimization-api-schemas`.
393
- *
394
- * @public
395
- */
396
- declare class EventBuilder {
397
- /**
398
- * Application metadata attached to each event.
399
- *
400
- * @internal
401
- */
402
- app?: App;
403
- /**
404
- * Channel value attached to each event.
405
- *
406
- * @internal
407
- */
408
- channel: Channel;
409
- /**
410
- * Library metadata attached to each event.
411
- *
412
- * @internal
413
- */
414
- library: Library;
415
- /**
416
- * Function that provides the locale when available.
417
- *
418
- * @internal
419
- */
420
- getLocale: () => string | undefined;
421
- /**
422
- * Function that provides baseline page properties.
423
- *
424
- * @internal
425
- */
426
- getPageProperties: () => Page;
427
- /**
428
- * Function that provides the user agent string when available.
429
- *
430
- * @internal
431
- */
432
- getUserAgent: () => string | undefined;
433
- /**
434
- * Creates a new {@link EventBuilder} instance.
435
- *
436
- * @param config - Configuration used to customize event payloads.
437
- *
438
- * @internal
439
- * @remarks
440
- * Callers are expected to reuse a single instance when possible to avoid
441
- * repeatedly reconfiguring the builder.
442
- *
443
- * @example
444
- * ```ts
445
- * const builder = new EventBuilder({
446
- * channel: 'web',
447
- * library: { name: '@contentful/optimization-sdk', version: '1.0.0' },
448
- * })
449
- * ```
450
- */
451
- constructor(config: EventBuilderConfig);
452
- /**
453
- * Builds the universal event properties shared across all event types.
454
- *
455
- * @param args - Arguments overriding the default context values.
456
- * @returns A fully populated {@link UniversalEventProperties} object.
457
- *
458
- * @protected
459
- *
460
- * @remarks
461
- * This method is used internally by the specific event-builder methods
462
- * (e.g. {@link EventBuilder.buildPageView}).
463
- */
464
- protected buildUniversalEventProperties({ campaign, locale, location, page, screen, userAgent, }: UniversalEventBuilderArgs): UniversalEventProperties;
465
- /**
466
- * Builds a component view event payload for a Contentful entry-based component.
467
- *
468
- * @param args - {@link ComponentViewBuilderArgs} arguments describing the component view.
469
- * @returns A {@link ComponentViewEvent} describing the view.
470
- *
471
- * @public
472
- *
473
- * @example
474
- * ```ts
475
- * const event = builder.buildComponentView({
476
- * componentId: 'entry-123',
477
- * experienceId: 'personalization-123',
478
- * variantIndex: 1,
479
- * })
480
- * ```
481
- */
482
- buildComponentView(args: ComponentViewBuilderArgs): ComponentViewEvent;
483
- /**
484
- * Builds a component view event payload for a Custom Flag component.
485
- *
486
- * @param args - {@link ComponentViewBuilderArgs} arguments describing the Custom Flag view.
487
- * @returns A {@link ComponentViewEvent} describing the view.
488
- *
489
- * @public
490
- *
491
- * @remarks
492
- * This is a specialized variant of {@link EventBuilder.buildComponentView}
493
- * that sets `componentType` to `'Variable'`.
494
- *
495
- * @example
496
- * ```ts
497
- * const event = builder.buildFlagView({
498
- * componentId: 'feature-flag-key',
499
- * experienceId: 'personalization-123',
500
- * })
501
- * ```
502
- */
503
- buildFlagView(args: ComponentViewBuilderArgs): ComponentViewEvent;
504
- /**
505
- * Builds an identify event payload to associate a user ID with traits.
506
- *
507
- * @param args - {@link IdentifyBuilderArgs} arguments describing the identified user.
508
- * @returns An {@link IdentifyEvent} payload.
509
- *
510
- * @public
511
- *
512
- * @remarks
513
- * - Traits are merged by the API; only specified properties may be overwritten.
514
- * - The User ID is consumer-specified and should not contain the value of any
515
- * ID generated by the Experience API.
516
- *
517
- * @example
518
- * ```ts
519
- * const event = builder.buildIdentify({
520
- * userId: 'user-123',
521
- * traits: { plan: 'pro' },
522
- * })
523
- * ```
524
- */
525
- buildIdentify(args: IdentifyBuilderArgs): IdentifyEvent;
526
- /**
527
- * Builds a page view event payload.
528
- *
529
- * @param args - Optional {@link PageViewBuilderArgs} overrides for the page view event.
530
- * @returns A {@link PageViewEvent} payload.
531
- *
532
- * @public
533
- *
534
- * @remarks
535
- * Page properties are created by merging:
536
- * 1. The base page properties from {@link EventBuilderConfig.getPageProperties}, and
537
- * 2. The partial `properties` argument passed in.
538
- *
539
- * The title always falls back to {@link DEFAULT_PAGE_PROPERTIES}.title when undefined.
540
- *
541
- * @example
542
- * ```ts
543
- * const event = builder.buildPageView({
544
- * properties: {
545
- * title: 'Homepage',
546
- * },
547
- * })
548
- * ```
549
- */
550
- buildPageView(args?: PageViewBuilderArgs): PageViewEvent;
551
- /**
552
- * Builds a screen view event payload.
553
- *
554
- * @param args - {@link ScreenViewBuilderArgs} arguments for the screen view event.
555
- * @returns A {@link ScreenViewEvent} payload.
556
- *
557
- * @public
558
- *
559
- * @example
560
- * ```ts
561
- * const event = builder.buildScreenView({
562
- * name: 'home',
563
- * properties: {
564
- * title: 'Home Screen',
565
- * },
566
- * })
567
- * ```
568
- */
569
- buildScreenView(args: ScreenViewBuilderArgs): ScreenViewEvent;
570
- /**
571
- * Builds a track event payload for arbitrary user actions.
572
- *
573
- * @param args - {@link TrackBuilderArgs} arguments describing the tracked event.
574
- * @returns A {@link TrackEvent} payload.
575
- *
576
- * @public
577
- *
578
- * @example
579
- * ```ts
580
- * const event = builder.buildTrack({
581
- * event: 'button_clicked',
582
- * properties: { id: 'primary-cta', location: 'hero' },
583
- * })
584
- * ```
585
- */
586
- buildTrack(args: TrackBuilderArgs): TrackEvent;
587
- }
588
- export default EventBuilder;
589
- //# sourceMappingURL=EventBuilder.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"EventBuilder.d.ts","sourceRoot":"","sources":["../../src/builders/EventBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,GAAG,EAER,KAAK,OAAO,EACZ,KAAK,kBAAkB,EAEvB,KAAK,aAAa,EAClB,KAAK,OAAO,EACZ,IAAI,EAEJ,KAAK,aAAa,EAIlB,KAAK,eAAe,EACpB,KAAK,UAAU,EAEf,KAAK,wBAAwB,EAC9B,MAAM,sCAAsC,CAAA;AAE7C,OAAO,KAAK,CAAC,MAAM,UAAU,CAAA;AAE7B;;;;;;;;;;;;;;;;;;;;;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