@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/logger.d.ts
ADDED
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A {@link LogSink} that writes log events to the browser or Node.js console,
|
|
3
|
+
* filtering by a configurable verbosity threshold.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```typescript
|
|
7
|
+
* import { logger, ConsoleLogSink } from '@contentful/optimization-api-client/logger'
|
|
8
|
+
*
|
|
9
|
+
* logger.addSink(new ConsoleLogSink('debug'))
|
|
10
|
+
* ```
|
|
11
|
+
*
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
14
|
+
export declare class ConsoleLogSink extends LogSink {
|
|
15
|
+
/** Identifies this sink when registered with the {@link Logger}. */
|
|
16
|
+
name: string;
|
|
17
|
+
/**
|
|
18
|
+
* Minimum log level required for events to be output.
|
|
19
|
+
*
|
|
20
|
+
* @defaultValue 'error'
|
|
21
|
+
*/
|
|
22
|
+
readonly verbosity: LogLevels;
|
|
23
|
+
/**
|
|
24
|
+
* Creates a new ConsoleLogSink.
|
|
25
|
+
*
|
|
26
|
+
* @param verbosity - Minimum log level to output.
|
|
27
|
+
*/
|
|
28
|
+
constructor(verbosity?: LogLevels);
|
|
29
|
+
/**
|
|
30
|
+
* Writes a log event to the console if its level meets the verbosity threshold.
|
|
31
|
+
*
|
|
32
|
+
* @param event - The log event to process.
|
|
33
|
+
* @returns Nothing.
|
|
34
|
+
*/
|
|
35
|
+
ingest(event: LogEvent): void;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Creates a {@link ScopedLogger} that automatically prepends the given location to every log call.
|
|
40
|
+
*
|
|
41
|
+
* @param location - The module or component identifier to prepend.
|
|
42
|
+
* @returns A {@link ScopedLogger} bound to the specified location.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```typescript
|
|
46
|
+
* import { createScopedLogger } from '@contentful/optimization-api-client/logger'
|
|
47
|
+
*
|
|
48
|
+
* const log = createScopedLogger('MyModule')
|
|
49
|
+
* log.info('Initialization complete')
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
52
|
+
* @public
|
|
53
|
+
*/
|
|
54
|
+
export declare function createScopedLogger(location: string): ScopedLogger;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* A log event emitted by the logger package.
|
|
58
|
+
*
|
|
59
|
+
* @public
|
|
60
|
+
*/
|
|
61
|
+
export declare interface LogEvent {
|
|
62
|
+
/** Logger scope name. */
|
|
63
|
+
name: string;
|
|
64
|
+
/** Event severity level. */
|
|
65
|
+
level: LogLevels;
|
|
66
|
+
/** Event payload, where the first entry is the formatted message. */
|
|
67
|
+
messages: unknown[];
|
|
68
|
+
/** Optional additional context attached by sinks or middleware. */
|
|
69
|
+
[other: string]: unknown;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Central logger that routes log events through registered {@link LogSink} instances.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```typescript
|
|
77
|
+
* import { logger } from '@contentful/optimization-api-client/logger'
|
|
78
|
+
*
|
|
79
|
+
* logger.info('MyModule', 'Application started')
|
|
80
|
+
* ```
|
|
81
|
+
*
|
|
82
|
+
* @public
|
|
83
|
+
*/
|
|
84
|
+
declare class Logger {
|
|
85
|
+
/** The logger's identifier, used as the event scope name. */
|
|
86
|
+
readonly name = "@contentful/optimization";
|
|
87
|
+
private readonly PREFIX_PARTS;
|
|
88
|
+
private readonly DELIMITER;
|
|
89
|
+
private sinks;
|
|
90
|
+
private assembleLocationPrefix;
|
|
91
|
+
/**
|
|
92
|
+
* Registers a log sink. If a sink with the same name already exists, it is replaced.
|
|
93
|
+
*
|
|
94
|
+
* @param sink - The {@link LogSink} instance to register.
|
|
95
|
+
* @returns Nothing.
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```typescript
|
|
99
|
+
* import { logger, ConsoleLogSink } from '@contentful/optimization-api-client/logger'
|
|
100
|
+
*
|
|
101
|
+
* logger.addSink(new ConsoleLogSink('debug'))
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
addSink(sink: LogSink): void;
|
|
105
|
+
/**
|
|
106
|
+
* Removes a registered sink by name.
|
|
107
|
+
*
|
|
108
|
+
* @param name - The name of the sink to remove.
|
|
109
|
+
* @returns Nothing.
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```typescript
|
|
113
|
+
* logger.removeSink('ConsoleLogSink')
|
|
114
|
+
* ```
|
|
115
|
+
*/
|
|
116
|
+
removeSink(name: string): void;
|
|
117
|
+
/**
|
|
118
|
+
* Removes all registered sinks.
|
|
119
|
+
*
|
|
120
|
+
* @returns Nothing.
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* ```typescript
|
|
124
|
+
* logger.removeSinks()
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
removeSinks(): void;
|
|
128
|
+
/**
|
|
129
|
+
* Logs a message at the debug level.
|
|
130
|
+
*
|
|
131
|
+
* @param logLocation - The module or component identifier.
|
|
132
|
+
* @param message - The log message.
|
|
133
|
+
* @param args - Additional arguments forwarded in the log event.
|
|
134
|
+
* @returns Nothing.
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ```typescript
|
|
138
|
+
* logger.debug('MyModule', 'Debugging value', someVariable)
|
|
139
|
+
* ```
|
|
140
|
+
*/
|
|
141
|
+
debug(logLocation: string, message: string, ...args: unknown[]): void;
|
|
142
|
+
/**
|
|
143
|
+
* Logs a message at the info level.
|
|
144
|
+
*
|
|
145
|
+
* @param logLocation - The module or component identifier.
|
|
146
|
+
* @param message - The log message.
|
|
147
|
+
* @param args - Additional arguments forwarded in the log event.
|
|
148
|
+
* @returns Nothing.
|
|
149
|
+
*
|
|
150
|
+
* @example
|
|
151
|
+
* ```typescript
|
|
152
|
+
* logger.info('MyModule', 'Operation completed')
|
|
153
|
+
* ```
|
|
154
|
+
*/
|
|
155
|
+
info(logLocation: string, message: string, ...args: unknown[]): void;
|
|
156
|
+
/**
|
|
157
|
+
* Logs a message at the log level.
|
|
158
|
+
*
|
|
159
|
+
* @param logLocation - The module or component identifier.
|
|
160
|
+
* @param message - The log message.
|
|
161
|
+
* @param args - Additional arguments forwarded in the log event.
|
|
162
|
+
* @returns Nothing.
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* ```typescript
|
|
166
|
+
* logger.log('MyModule', 'General log entry')
|
|
167
|
+
* ```
|
|
168
|
+
*/
|
|
169
|
+
log(logLocation: string, message: string, ...args: unknown[]): void;
|
|
170
|
+
/**
|
|
171
|
+
* Logs a message at the warn level.
|
|
172
|
+
*
|
|
173
|
+
* @param logLocation - The module or component identifier.
|
|
174
|
+
* @param message - The log message.
|
|
175
|
+
* @param args - Additional arguments forwarded in the log event.
|
|
176
|
+
* @returns Nothing.
|
|
177
|
+
*
|
|
178
|
+
* @example
|
|
179
|
+
* ```typescript
|
|
180
|
+
* logger.warn('MyModule', 'Deprecated method called')
|
|
181
|
+
* ```
|
|
182
|
+
*/
|
|
183
|
+
warn(logLocation: string, message: string, ...args: unknown[]): void;
|
|
184
|
+
/**
|
|
185
|
+
* Logs a message at the error level.
|
|
186
|
+
*
|
|
187
|
+
* @param logLocation - The module or component identifier.
|
|
188
|
+
* @param message - The log message or Error object.
|
|
189
|
+
* @param args - Additional arguments forwarded in the log event.
|
|
190
|
+
* @returns Nothing.
|
|
191
|
+
*
|
|
192
|
+
* @example
|
|
193
|
+
* ```typescript
|
|
194
|
+
* logger.error('MyModule', new Error('Something failed'))
|
|
195
|
+
* ```
|
|
196
|
+
*/
|
|
197
|
+
error(logLocation: string, message: string | Error, ...args: unknown[]): void;
|
|
198
|
+
/**
|
|
199
|
+
* Logs a message at the fatal level.
|
|
200
|
+
*
|
|
201
|
+
* @param logLocation - The module or component identifier.
|
|
202
|
+
* @param message - The log message or Error object.
|
|
203
|
+
* @param args - Additional arguments forwarded in the log event.
|
|
204
|
+
* @returns Nothing.
|
|
205
|
+
*
|
|
206
|
+
* @example
|
|
207
|
+
* ```typescript
|
|
208
|
+
* logger.fatal('MyModule', new Error('Unrecoverable failure'))
|
|
209
|
+
* ```
|
|
210
|
+
*/
|
|
211
|
+
fatal(logLocation: string, message: string | Error, ...args: unknown[]): void;
|
|
212
|
+
private emit;
|
|
213
|
+
private onLogEvent;
|
|
214
|
+
}
|
|
215
|
+
export { Logger }
|
|
216
|
+
export default Logger;
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Shared singleton {@link Logger} instance used across the SDK.
|
|
220
|
+
*
|
|
221
|
+
* @public
|
|
222
|
+
*/
|
|
223
|
+
export declare const logger: Logger;
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Supported log levels ordered from highest to lowest severity.
|
|
227
|
+
*
|
|
228
|
+
* @public
|
|
229
|
+
*/
|
|
230
|
+
export declare type LogLevels = 'fatal' | 'error' | 'warn' | 'info' | 'debug' | 'log';
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Numeric severity map used for log-level threshold comparisons.
|
|
234
|
+
*
|
|
235
|
+
* @public
|
|
236
|
+
*/
|
|
237
|
+
export declare const logLevelSeverity: Readonly<Record<LogLevels, number>>;
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Abstract base class for log sinks that receive and process log events.
|
|
241
|
+
*
|
|
242
|
+
* @example
|
|
243
|
+
* ```typescript
|
|
244
|
+
* class MyCustomSink extends LogSink {
|
|
245
|
+
* name = 'MyCustomSink'
|
|
246
|
+
*
|
|
247
|
+
* ingest(event: LogEvent): void {
|
|
248
|
+
* // process the event
|
|
249
|
+
* }
|
|
250
|
+
* }
|
|
251
|
+
* ```
|
|
252
|
+
*
|
|
253
|
+
* @public
|
|
254
|
+
*/
|
|
255
|
+
export declare abstract class LogSink {
|
|
256
|
+
/** Display name used to identify this sink for addition and removal. */
|
|
257
|
+
abstract name: string;
|
|
258
|
+
/**
|
|
259
|
+
* Processes an incoming log event.
|
|
260
|
+
*
|
|
261
|
+
* @param event - The log event to process.
|
|
262
|
+
* @returns Nothing.
|
|
263
|
+
*/
|
|
264
|
+
abstract ingest(event: LogEvent): void;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* A location-scoped logger interface whose methods omit the `logLocation` parameter.
|
|
269
|
+
*
|
|
270
|
+
* @public
|
|
271
|
+
*/
|
|
272
|
+
export declare interface ScopedLogger {
|
|
273
|
+
/** Logs at debug level. */
|
|
274
|
+
debug: (message: string, ...args: unknown[]) => void;
|
|
275
|
+
/** Logs at info level. */
|
|
276
|
+
info: (message: string, ...args: unknown[]) => void;
|
|
277
|
+
/** Logs at log level. */
|
|
278
|
+
log: (message: string, ...args: unknown[]) => void;
|
|
279
|
+
/** Logs at warn level. */
|
|
280
|
+
warn: (message: string, ...args: unknown[]) => void;
|
|
281
|
+
/** Logs at error level. */
|
|
282
|
+
error: (message: string | Error, ...args: unknown[]) => void;
|
|
283
|
+
/** Logs at fatal level. */
|
|
284
|
+
fatal: (message: string | Error, ...args: unknown[]) => void;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
export { }
|
package/dist/logger.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ConsoleLogSink, LogSink, Logger, createScopedLogger, default, logLevelSeverity, logger } from "./649.mjs";
|
package/package.json
CHANGED
|
@@ -1,16 +1,41 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentful/optimization-api-client",
|
|
3
|
-
"version": "0.1.0-
|
|
3
|
+
"version": "0.1.0-alpha9",
|
|
4
4
|
"license": "MIT",
|
|
5
|
-
"type": "
|
|
5
|
+
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
7
7
|
"module": "./dist/index.mjs",
|
|
8
8
|
"types": "./dist/index.d.ts",
|
|
9
9
|
"exports": {
|
|
10
10
|
".": {
|
|
11
|
-
"
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
"import": {
|
|
12
|
+
"types": "./dist/index.d.mts",
|
|
13
|
+
"default": "./dist/index.mjs"
|
|
14
|
+
},
|
|
15
|
+
"require": {
|
|
16
|
+
"types": "./dist/index.d.cts",
|
|
17
|
+
"default": "./dist/index.cjs"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"./logger": {
|
|
21
|
+
"import": {
|
|
22
|
+
"types": "./dist/logger.d.mts",
|
|
23
|
+
"default": "./dist/logger.mjs"
|
|
24
|
+
},
|
|
25
|
+
"require": {
|
|
26
|
+
"types": "./dist/logger.d.cts",
|
|
27
|
+
"default": "./dist/logger.cjs"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"./api-schemas": {
|
|
31
|
+
"import": {
|
|
32
|
+
"types": "./dist/api-schemas.d.mts",
|
|
33
|
+
"default": "./dist/api-schemas.mjs"
|
|
34
|
+
},
|
|
35
|
+
"require": {
|
|
36
|
+
"types": "./dist/api-schemas.d.cts",
|
|
37
|
+
"default": "./dist/api-schemas.cjs"
|
|
38
|
+
}
|
|
14
39
|
},
|
|
15
40
|
"./package.json": "./package.json"
|
|
16
41
|
},
|
|
@@ -18,10 +43,8 @@
|
|
|
18
43
|
"dist/**/*"
|
|
19
44
|
],
|
|
20
45
|
"dependencies": {
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"zod": "^4.1.5",
|
|
25
|
-
"@contentful/optimization-api-schemas": "0.1.0-alpha7"
|
|
46
|
+
"es-toolkit": "^1.44.0",
|
|
47
|
+
"zod": "^4.3.6",
|
|
48
|
+
"@contentful/optimization-api-schemas": "0.1.0-alpha9"
|
|
26
49
|
}
|
|
27
50
|
}
|
package/dist/ApiClient.d.ts
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import type { ApiConfig, GlobalApiConfigProperties } from './ApiClientBase';
|
|
2
|
-
import ExperienceApiClient, { type ExperienceApiClientConfig } from './experience';
|
|
3
|
-
import InsightsApiClient, { type InsightsApiClientConfig } from './insights';
|
|
4
|
-
/**
|
|
5
|
-
* Configuration for the high-level {@link ApiClient}.
|
|
6
|
-
*
|
|
7
|
-
* @public
|
|
8
|
-
*/
|
|
9
|
-
export interface ApiClientConfig extends Pick<ApiConfig, GlobalApiConfigProperties> {
|
|
10
|
-
/**
|
|
11
|
-
* Configuration for the personalization (Experience) API client.
|
|
12
|
-
*
|
|
13
|
-
* @remarks
|
|
14
|
-
* Any properties shared with {@link ApiConfig} are taken from the top-level
|
|
15
|
-
* config and overridden by this object when specified.
|
|
16
|
-
*/
|
|
17
|
-
personalization?: Omit<ExperienceApiClientConfig, GlobalApiConfigProperties>;
|
|
18
|
-
/**
|
|
19
|
-
* Configuration for the analytics (Insights) API client.
|
|
20
|
-
*
|
|
21
|
-
* @remarks
|
|
22
|
-
* Any properties shared with {@link ApiConfig} are taken from the top-level
|
|
23
|
-
* config and overridden by this object when specified.
|
|
24
|
-
*/
|
|
25
|
-
analytics?: Omit<InsightsApiClientConfig, GlobalApiConfigProperties>;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Aggregated API client providing access to Experience and Insights APIs.
|
|
29
|
-
*
|
|
30
|
-
* @public
|
|
31
|
-
*
|
|
32
|
-
* @remarks
|
|
33
|
-
* This client encapsulates shared configuration and exposes dedicated
|
|
34
|
-
* sub-clients for personalization and analytics use cases.
|
|
35
|
-
*
|
|
36
|
-
* @example
|
|
37
|
-
* ```ts
|
|
38
|
-
* const client = new ApiClient({
|
|
39
|
-
* clientId: 'org-id',
|
|
40
|
-
* environment: 'main',
|
|
41
|
-
* preview: false,
|
|
42
|
-
* personalization: {
|
|
43
|
-
* // experience-specific overrides
|
|
44
|
-
* },
|
|
45
|
-
* analytics: {
|
|
46
|
-
* // insights-specific overrides
|
|
47
|
-
* },
|
|
48
|
-
* })
|
|
49
|
-
*
|
|
50
|
-
* const profile = await client.experience.getProfile('profile-id')
|
|
51
|
-
* const batch = await client.insights.upsertManyProfiles({ events: batchEvents })
|
|
52
|
-
* ```
|
|
53
|
-
*/
|
|
54
|
-
export default class ApiClient {
|
|
55
|
-
/**
|
|
56
|
-
* Shared configuration applied to both Experience and Insights clients.
|
|
57
|
-
*/
|
|
58
|
-
readonly config: ApiConfig;
|
|
59
|
-
/**
|
|
60
|
-
* Client for personalization and experience-related operations.
|
|
61
|
-
*/
|
|
62
|
-
readonly experience: ExperienceApiClient;
|
|
63
|
-
/**
|
|
64
|
-
* Client for analytics and insights-related operations.
|
|
65
|
-
*/
|
|
66
|
-
readonly insights: InsightsApiClient;
|
|
67
|
-
/**
|
|
68
|
-
* Creates a new aggregated {@link ApiClient} instance.
|
|
69
|
-
*
|
|
70
|
-
* @param config - Global API client configuration with optional per-client overrides.
|
|
71
|
-
*/
|
|
72
|
-
constructor(config: ApiClientConfig);
|
|
73
|
-
}
|
|
74
|
-
//# sourceMappingURL=ApiClient.d.ts.map
|
package/dist/ApiClient.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ApiClient.d.ts","sourceRoot":"","sources":["../src/ApiClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAA;AAC3E,OAAO,mBAAmB,EAAE,EAAE,KAAK,yBAAyB,EAAE,MAAM,cAAc,CAAA;AAClF,OAAO,iBAAiB,EAAE,EAAE,KAAK,uBAAuB,EAAE,MAAM,YAAY,CAAA;AAE5E;;;;GAIG;AACH,MAAM,WAAW,eAAgB,SAAQ,IAAI,CAAC,SAAS,EAAE,yBAAyB,CAAC;IACjF;;;;;;OAMG;IACH,eAAe,CAAC,EAAE,IAAI,CAAC,yBAAyB,EAAE,yBAAyB,CAAC,CAAA;IAE5E;;;;;;OAMG;IACH,SAAS,CAAC,EAAE,IAAI,CAAC,uBAAuB,EAAE,yBAAyB,CAAC,CAAA;CACrE;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,CAAC,OAAO,OAAO,SAAS;IAC5B;;OAEG;IACH,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAA;IAE1B;;OAEG;IACH,QAAQ,CAAC,UAAU,EAAE,mBAAmB,CAAA;IAExC;;OAEG;IACH,QAAQ,CAAC,QAAQ,EAAE,iBAAiB,CAAA;IAEpC;;;;OAIG;gBACS,MAAM,EAAE,eAAe;CAepC"}
|
package/dist/ApiClient.js
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import ExperienceApiClient from './experience';
|
|
2
|
-
import InsightsApiClient from './insights';
|
|
3
|
-
/**
|
|
4
|
-
* Aggregated API client providing access to Experience and Insights APIs.
|
|
5
|
-
*
|
|
6
|
-
* @public
|
|
7
|
-
*
|
|
8
|
-
* @remarks
|
|
9
|
-
* This client encapsulates shared configuration and exposes dedicated
|
|
10
|
-
* sub-clients for personalization and analytics use cases.
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* ```ts
|
|
14
|
-
* const client = new ApiClient({
|
|
15
|
-
* clientId: 'org-id',
|
|
16
|
-
* environment: 'main',
|
|
17
|
-
* preview: false,
|
|
18
|
-
* personalization: {
|
|
19
|
-
* // experience-specific overrides
|
|
20
|
-
* },
|
|
21
|
-
* analytics: {
|
|
22
|
-
* // insights-specific overrides
|
|
23
|
-
* },
|
|
24
|
-
* })
|
|
25
|
-
*
|
|
26
|
-
* const profile = await client.experience.getProfile('profile-id')
|
|
27
|
-
* const batch = await client.insights.upsertManyProfiles({ events: batchEvents })
|
|
28
|
-
* ```
|
|
29
|
-
*/
|
|
30
|
-
export default class ApiClient {
|
|
31
|
-
/**
|
|
32
|
-
* Shared configuration applied to both Experience and Insights clients.
|
|
33
|
-
*/
|
|
34
|
-
config;
|
|
35
|
-
/**
|
|
36
|
-
* Client for personalization and experience-related operations.
|
|
37
|
-
*/
|
|
38
|
-
experience;
|
|
39
|
-
/**
|
|
40
|
-
* Client for analytics and insights-related operations.
|
|
41
|
-
*/
|
|
42
|
-
insights;
|
|
43
|
-
/**
|
|
44
|
-
* Creates a new aggregated {@link ApiClient} instance.
|
|
45
|
-
*
|
|
46
|
-
* @param config - Global API client configuration with optional per-client overrides.
|
|
47
|
-
*/
|
|
48
|
-
constructor(config) {
|
|
49
|
-
const { personalization, analytics, ...apiConfig } = config;
|
|
50
|
-
this.config = apiConfig;
|
|
51
|
-
this.experience = new ExperienceApiClient({
|
|
52
|
-
...apiConfig,
|
|
53
|
-
...personalization,
|
|
54
|
-
});
|
|
55
|
-
this.insights = new InsightsApiClient({
|
|
56
|
-
...apiConfig,
|
|
57
|
-
...analytics,
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
//# sourceMappingURL=ApiClient.js.map
|
package/dist/ApiClient.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ApiClient.js","sourceRoot":"","sources":["../src/ApiClient.ts"],"names":[],"mappings":"AACA,OAAO,mBAAuD,MAAM,cAAc,CAAA;AAClF,OAAO,iBAAmD,MAAM,YAAY,CAAA;AA2B5E;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,CAAC,OAAO,OAAO,SAAS;IAC5B;;OAEG;IACM,MAAM,CAAW;IAE1B;;OAEG;IACM,UAAU,CAAqB;IAExC;;OAEG;IACM,QAAQ,CAAmB;IAEpC;;;;OAIG;IACH,YAAY,MAAuB;QACjC,MAAM,EAAE,eAAe,EAAE,SAAS,EAAE,GAAG,SAAS,EAAE,GAAG,MAAM,CAAA;QAE3D,IAAI,CAAC,MAAM,GAAG,SAAS,CAAA;QAEvB,IAAI,CAAC,UAAU,GAAG,IAAI,mBAAmB,CAAC;YACxC,GAAG,SAAS;YACZ,GAAG,eAAe;SACnB,CAAC,CAAA;QAEF,IAAI,CAAC,QAAQ,GAAG,IAAI,iBAAiB,CAAC;YACpC,GAAG,SAAS;YACZ,GAAG,SAAS;SACb,CAAC,CAAA;IACJ,CAAC;CACF"}
|
package/dist/ApiClientBase.d.ts
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import { type FetchMethod, type ProtectedFetchMethodOptions } from './fetch';
|
|
2
|
-
/**
|
|
3
|
-
* Configuration options for API clients extending {@link ApiClientBase}.
|
|
4
|
-
*
|
|
5
|
-
* @public
|
|
6
|
-
*/
|
|
7
|
-
export interface ApiConfig {
|
|
8
|
-
/**
|
|
9
|
-
* Base URL for the API.
|
|
10
|
-
*
|
|
11
|
-
* @remarks
|
|
12
|
-
* When omitted, the concrete client is expected to construct full URLs
|
|
13
|
-
* internally.
|
|
14
|
-
*/
|
|
15
|
-
baseUrl?: string;
|
|
16
|
-
/**
|
|
17
|
-
* Contentful environment identifier.
|
|
18
|
-
*
|
|
19
|
-
* @remarks
|
|
20
|
-
* Defaults to `main` when not provided.
|
|
21
|
-
*/
|
|
22
|
-
environment?: string;
|
|
23
|
-
/**
|
|
24
|
-
* Options used to configure the underlying protected fetch method.
|
|
25
|
-
*
|
|
26
|
-
* @remarks
|
|
27
|
-
* `apiName` is derived from the client name and must not be provided here.
|
|
28
|
-
*/
|
|
29
|
-
fetchOptions?: Omit<ProtectedFetchMethodOptions, 'apiName'>;
|
|
30
|
-
/**
|
|
31
|
-
* Client identifier used for authentication or tracking.
|
|
32
|
-
*/
|
|
33
|
-
clientId: string;
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Properties that may be shared between global and per-client API configuration.
|
|
37
|
-
*
|
|
38
|
-
* @public
|
|
39
|
-
*/
|
|
40
|
-
export type GlobalApiConfigProperties = 'environment' | 'fetchOptions' | 'clientId';
|
|
41
|
-
/**
|
|
42
|
-
* Base class for API clients that provides shared configuration and error logging.
|
|
43
|
-
*
|
|
44
|
-
* @internal
|
|
45
|
-
*
|
|
46
|
-
* @remarks
|
|
47
|
-
* This abstract class is intended for internal use within the package and
|
|
48
|
-
* should not be treated as part of the public API surface.
|
|
49
|
-
*
|
|
50
|
-
* Concrete API clients should extend this class to inherit consistent logging
|
|
51
|
-
* behavior and fetch configuration.
|
|
52
|
-
*
|
|
53
|
-
* @example
|
|
54
|
-
* ```ts
|
|
55
|
-
* interface MyClientConfig extends ApiConfig {
|
|
56
|
-
* // additional config
|
|
57
|
-
* }
|
|
58
|
-
*
|
|
59
|
-
* class MyClient extends ApiClientBase {
|
|
60
|
-
* constructor(config: MyClientConfig) {
|
|
61
|
-
* super('MyClient', config)
|
|
62
|
-
* }
|
|
63
|
-
*
|
|
64
|
-
* async getSomething() {
|
|
65
|
-
* const response = await this.fetch('https://example.com', { method: 'GET' })
|
|
66
|
-
* return response.json()
|
|
67
|
-
* }
|
|
68
|
-
* }
|
|
69
|
-
* ```
|
|
70
|
-
*/
|
|
71
|
-
declare abstract class ApiClientBase {
|
|
72
|
-
/**
|
|
73
|
-
* Name of the API client, used in log messages and as the `apiName` for fetch.
|
|
74
|
-
*/
|
|
75
|
-
protected readonly name: string;
|
|
76
|
-
/**
|
|
77
|
-
* Client identifier used for authentication or tracking.
|
|
78
|
-
*/
|
|
79
|
-
protected readonly clientId: string;
|
|
80
|
-
/**
|
|
81
|
-
* Contentful environment associated with this client.
|
|
82
|
-
*/
|
|
83
|
-
protected readonly environment: string;
|
|
84
|
-
/**
|
|
85
|
-
* Protected fetch method used by the client to perform HTTP requests.
|
|
86
|
-
*/
|
|
87
|
-
protected readonly fetch: FetchMethod;
|
|
88
|
-
/**
|
|
89
|
-
* Creates a new API client base instance.
|
|
90
|
-
*
|
|
91
|
-
* @param name - Human-readable name of the client (used for logging and `apiName`).
|
|
92
|
-
* @param config - Configuration options for the client.
|
|
93
|
-
*/
|
|
94
|
-
constructor(name: string, { fetchOptions, clientId, environment }: ApiConfig);
|
|
95
|
-
/**
|
|
96
|
-
* Logs errors that occur during API requests with standardized messages.
|
|
97
|
-
*
|
|
98
|
-
* @param error - The error thrown by the underlying operation.
|
|
99
|
-
* @param options - Additional metadata about the request.
|
|
100
|
-
* @param options.requestName - Human-readable name of the request operation.
|
|
101
|
-
*
|
|
102
|
-
* @protected
|
|
103
|
-
*
|
|
104
|
-
* @remarks
|
|
105
|
-
* Abort errors are logged at `warn` level and other errors at `error` level.
|
|
106
|
-
* The log message includes the client name for better debugging context.
|
|
107
|
-
*/
|
|
108
|
-
protected logRequestError(error: unknown, { requestName }: {
|
|
109
|
-
requestName: string;
|
|
110
|
-
}): void;
|
|
111
|
-
}
|
|
112
|
-
export default ApiClientBase;
|
|
113
|
-
//# sourceMappingURL=ApiClientBase.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ApiClientBase.d.ts","sourceRoot":"","sources":["../src/ApiClientBase.ts"],"names":[],"mappings":"AACA,OAAc,EAAE,KAAK,WAAW,EAAE,KAAK,2BAA2B,EAAE,MAAM,SAAS,CAAA;AAWnF;;;;GAIG;AACH,MAAM,WAAW,SAAS;IACxB;;;;;;OAMG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;IAEhB;;;;;OAKG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;IAEpB;;;;;OAKG;IACH,YAAY,CAAC,EAAE,IAAI,CAAC,2BAA2B,EAAE,SAAS,CAAC,CAAA;IAE3D;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAA;CACjB;AAED;;;;GAIG;AACH,MAAM,MAAM,yBAAyB,GAAG,aAAa,GAAG,cAAc,GAAG,UAAU,CAAA;AAEnF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,uBAAe,aAAa;IAC1B;;OAEG;IACH,SAAS,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IAE/B;;OAEG;IACH,SAAS,CAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IAEnC;;OAEG;IACH,SAAS,CAAC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;IAEtC;;OAEG;IACH,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAA;IAErC;;;;;OAKG;gBACS,IAAI,EAAE,MAAM,EAAE,EAAE,YAAY,EAAE,QAAQ,EAAE,WAAW,EAAE,EAAE,SAAS;IAQ5E;;;;;;;;;;;;OAYG;IACH,SAAS,CAAC,eAAe,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE,WAAW,EAAE,EAAE;QAAE,WAAW,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI;CAW1F;AAED,eAAe,aAAa,CAAA"}
|