infinium-o2 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +550 -0
  3. package/dist/cjs/asyncClient.d.ts +119 -0
  4. package/dist/cjs/asyncClient.d.ts.map +1 -0
  5. package/dist/cjs/asyncClient.js +464 -0
  6. package/dist/cjs/asyncClient.js.map +1 -0
  7. package/dist/cjs/client.d.ts +92 -0
  8. package/dist/cjs/client.d.ts.map +1 -0
  9. package/dist/cjs/client.js +354 -0
  10. package/dist/cjs/client.js.map +1 -0
  11. package/dist/cjs/errors.d.ts +102 -0
  12. package/dist/cjs/errors.d.ts.map +1 -0
  13. package/dist/cjs/errors.js +218 -0
  14. package/dist/cjs/errors.js.map +1 -0
  15. package/dist/cjs/index.d.ts +12 -0
  16. package/dist/cjs/index.d.ts.map +1 -0
  17. package/dist/cjs/index.js +61 -0
  18. package/dist/cjs/index.js.map +1 -0
  19. package/dist/cjs/package.json +1 -0
  20. package/dist/cjs/types.d.ts +231 -0
  21. package/dist/cjs/types.d.ts.map +1 -0
  22. package/dist/cjs/types.js +23 -0
  23. package/dist/cjs/types.js.map +1 -0
  24. package/dist/cjs/utils.d.ts +130 -0
  25. package/dist/cjs/utils.d.ts.map +1 -0
  26. package/dist/cjs/utils.js +381 -0
  27. package/dist/cjs/utils.js.map +1 -0
  28. package/dist/esm/asyncClient.d.ts +119 -0
  29. package/dist/esm/asyncClient.d.ts.map +1 -0
  30. package/dist/esm/asyncClient.js +457 -0
  31. package/dist/esm/asyncClient.js.map +1 -0
  32. package/dist/esm/client.d.ts +92 -0
  33. package/dist/esm/client.d.ts.map +1 -0
  34. package/dist/esm/client.js +347 -0
  35. package/dist/esm/client.js.map +1 -0
  36. package/dist/esm/errors.d.ts +102 -0
  37. package/dist/esm/errors.d.ts.map +1 -0
  38. package/dist/esm/errors.js +200 -0
  39. package/dist/esm/errors.js.map +1 -0
  40. package/dist/esm/index.d.ts +12 -0
  41. package/dist/esm/index.d.ts.map +1 -0
  42. package/dist/esm/index.js +17 -0
  43. package/dist/esm/index.js.map +1 -0
  44. package/dist/esm/package.json +1 -0
  45. package/dist/esm/types.d.ts +231 -0
  46. package/dist/esm/types.d.ts.map +1 -0
  47. package/dist/esm/types.js +20 -0
  48. package/dist/esm/types.js.map +1 -0
  49. package/dist/esm/utils.d.ts +130 -0
  50. package/dist/esm/utils.d.ts.map +1 -0
  51. package/dist/esm/utils.js +355 -0
  52. package/dist/esm/utils.js.map +1 -0
  53. package/package.json +94 -0
@@ -0,0 +1,347 @@
1
+ /**
2
+ * Synchronous client for Infinium API.
3
+ */
4
+ import axios from 'axios';
5
+ import axiosRetry from 'axios-retry';
6
+ import { AgentType, } from './types';
7
+ import { InfiniumError, ValidationError, RateLimitError, ServerError, handleAxiosError, } from './errors';
8
+ import { validateAgentCredentials, validateIsoDatetime, validateAgentType, validateDuration, validateRequiredField, getCurrentIsoDatetime, RateLimiter, setupLogging, generateUserAgent, normalizeUrl, shouldRetryError, } from './utils';
9
+ /**
10
+ * Synchronous client for Infinium API.
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * import { InfiniumClient, AgentType } from 'infinium';
15
+ *
16
+ * const client = new InfiniumClient({
17
+ * agentId: 'your-agent-id',
18
+ * agentSecret: 'your-agent-secret'
19
+ * });
20
+ *
21
+ * // Send a simple task
22
+ * const response = client.sendTask({
23
+ * name: 'Process customer inquiry',
24
+ * description: 'Handled customer question about pricing',
25
+ * duration: 120.5
26
+ * });
27
+ *
28
+ * // Send with additional data
29
+ * const taskData = {
30
+ * name: 'Marketing campaign analysis',
31
+ * description: 'Analyzed Q3 campaign performance',
32
+ * currentDatetime: client.getCurrentIsoDatetime(),
33
+ * duration: 300.0,
34
+ * agentType: AgentType.MARKETING_ASSISTANT
35
+ * };
36
+ * const response2 = client.sendTaskData(taskData);
37
+ * ```
38
+ */
39
+ export class InfiniumClient {
40
+ agentId;
41
+ agentSecret;
42
+ baseUrl;
43
+ timeout;
44
+ maxRetries;
45
+ userAgent;
46
+ logger;
47
+ rateLimiter;
48
+ httpClient;
49
+ /**
50
+ * Initialize the Infinium client.
51
+ */
52
+ constructor(config) {
53
+ // Validate configuration
54
+ validateAgentCredentials(config.agentId, config.agentSecret);
55
+ this.agentId = config.agentId;
56
+ this.agentSecret = config.agentSecret;
57
+ this.baseUrl = normalizeUrl(config.baseUrl || 'https://api.i42m.ai/api/v1');
58
+ this.timeout = config.timeout || 30000;
59
+ this.maxRetries = config.maxRetries || 3;
60
+ this.userAgent = config.userAgent || generateUserAgent('1.0.0');
61
+ this.logger = setupLogging(config.enableLogging, config.logLevel);
62
+ // Setup rate limiter if enabled
63
+ this.rateLimiter =
64
+ config.enableRateLimiting !== false
65
+ ? new RateLimiter({
66
+ requestsPerSecond: config.requestsPerSecond || 10,
67
+ burstSize: (config.requestsPerSecond || 10) * 2,
68
+ })
69
+ : null;
70
+ // Setup HTTP client
71
+ this.httpClient = this.createHttpClient();
72
+ this.logger.info('Infinium client initialized', {
73
+ agentId: this.agentId,
74
+ baseUrl: this.baseUrl,
75
+ timeout: this.timeout,
76
+ maxRetries: this.maxRetries,
77
+ rateLimitingEnabled: !!this.rateLimiter,
78
+ });
79
+ }
80
+ /**
81
+ * Create and configure HTTP client.
82
+ */
83
+ createHttpClient() {
84
+ const client = axios.create({
85
+ baseURL: this.baseUrl,
86
+ timeout: this.timeout,
87
+ headers: {
88
+ 'Content-Type': 'application/json',
89
+ 'User-Agent': this.userAgent,
90
+ 'x-agent-id': this.agentId,
91
+ 'x-agent-key': this.agentSecret,
92
+ },
93
+ });
94
+ // Setup retry logic
95
+ axiosRetry(client, {
96
+ retries: this.maxRetries,
97
+ retryDelay: (retryCount) => {
98
+ return Math.min(1000 * 2 ** (retryCount - 1), 30000);
99
+ },
100
+ retryCondition: (error) => {
101
+ // eslint-disable-line @typescript-eslint/no-explicit-any
102
+ return shouldRetryError(error);
103
+ },
104
+ onRetry: (retryCount, error, requestConfig) => {
105
+ // eslint-disable-line @typescript-eslint/no-explicit-any
106
+ this.logger.warn('Retrying request', {
107
+ retryCount,
108
+ url: requestConfig.url,
109
+ method: requestConfig.method,
110
+ error: error.message,
111
+ });
112
+ },
113
+ });
114
+ // Request interceptor for rate limiting
115
+ client.interceptors.request.use((config) => {
116
+ // eslint-disable-line @typescript-eslint/no-explicit-any
117
+ if (this.rateLimiter) {
118
+ if (!this.rateLimiter.canMakeRequest()) {
119
+ const waitTime = this.rateLimiter.getWaitTime();
120
+ throw new RateLimitError(`Rate limit exceeded. Wait ${waitTime}ms before retrying.`, waitTime);
121
+ }
122
+ }
123
+ this.logger.debug('Making request', {
124
+ url: config.url,
125
+ method: config.method,
126
+ });
127
+ return config;
128
+ });
129
+ // Response interceptor for logging and error handling
130
+ client.interceptors.response.use((response) => {
131
+ // eslint-disable-line @typescript-eslint/no-explicit-any
132
+ this.logger.debug('Request successful', {
133
+ url: response.config.url,
134
+ method: response.config.method,
135
+ status: response.status,
136
+ });
137
+ return response;
138
+ }, (error) => {
139
+ // eslint-disable-line @typescript-eslint/no-explicit-any
140
+ this.logger.error('Request failed', {
141
+ url: error.config?.url,
142
+ method: error.config?.method,
143
+ status: error.response?.status,
144
+ message: error.message,
145
+ });
146
+ throw handleAxiosError(error);
147
+ });
148
+ return client;
149
+ }
150
+ /**
151
+ * Make HTTP request with proper error handling.
152
+ */
153
+ async makeRequest(method, endpoint, data, options) {
154
+ try {
155
+ const config = {
156
+ method,
157
+ url: endpoint,
158
+ data,
159
+ timeout: options?.timeout || this.timeout,
160
+ ...(options?.headers && { headers: options.headers }),
161
+ };
162
+ const response = await this.httpClient.request(config);
163
+ return response.data;
164
+ }
165
+ catch (error) {
166
+ throw handleAxiosError(error);
167
+ }
168
+ }
169
+ /**
170
+ * Send task data to the API.
171
+ */
172
+ async sendTask(task) {
173
+ // Validate required fields
174
+ validateRequiredField(task.name, 'name');
175
+ validateRequiredField(task.description, 'description');
176
+ validateRequiredField(task.duration, 'duration', 'number');
177
+ // Validate and normalize data
178
+ validateDuration(task.duration);
179
+ const agentType = task.agentType ? validateAgentType(task.agentType) : AgentType.OTHER;
180
+ const currentDatetime = task.currentDatetime || getCurrentIsoDatetime();
181
+ if (!validateIsoDatetime(currentDatetime)) {
182
+ throw new ValidationError('Invalid currentDatetime format. Must be ISO 8601.', 'currentDatetime');
183
+ }
184
+ // Build task payload
185
+ const taskPayload = {
186
+ name: task.name.trim(),
187
+ description: task.description.trim(),
188
+ current_datetime: currentDatetime,
189
+ duration: task.duration,
190
+ agent_type: agentType,
191
+ time_tracking: task.timeTracking,
192
+ customer: task.customer,
193
+ support: task.support,
194
+ sales: task.sales,
195
+ marketing: task.marketing,
196
+ content: task.content,
197
+ research: task.research,
198
+ project: task.project,
199
+ development: task.development,
200
+ executive: task.executive,
201
+ general: task.general,
202
+ };
203
+ // Remove undefined values
204
+ const cleanPayload = this.cleanPayload(taskPayload);
205
+ this.logger.info('Sending task', {
206
+ agentId: this.agentId,
207
+ taskName: task.name,
208
+ agentType,
209
+ });
210
+ return this.makeRequest('POST', `/agents/${this.agentId}/trace`, cleanPayload);
211
+ }
212
+ /**
213
+ * Send pre-built TaskData object.
214
+ */
215
+ async sendTaskData(taskData) {
216
+ return await this.sendTask(taskData);
217
+ }
218
+ /**
219
+ * Send multiple tasks in batch.
220
+ */
221
+ async sendBatch(tasks) {
222
+ if (!Array.isArray(tasks) || tasks.length === 0) {
223
+ throw new ValidationError('Tasks array cannot be empty', 'tasks');
224
+ }
225
+ if (tasks.length > 100) {
226
+ throw new ValidationError('Batch size cannot exceed 100 tasks', 'tasks');
227
+ }
228
+ const results = [];
229
+ const errors = [];
230
+ let successfulTasks = 0;
231
+ this.logger.info('Sending batch tasks', {
232
+ agentId: this.agentId,
233
+ taskCount: tasks.length,
234
+ });
235
+ for (let i = 0; i < tasks.length; i++) {
236
+ try {
237
+ const result = await this.sendTaskData(tasks[i]);
238
+ results.push(result);
239
+ if (result.success) {
240
+ successfulTasks++;
241
+ }
242
+ else {
243
+ errors.push(`Task ${i + 1}: ${result.message}`);
244
+ }
245
+ }
246
+ catch (error) {
247
+ const errorMessage = error instanceof Error ? error.message : 'Unknown error';
248
+ errors.push(`Task ${i + 1}: ${errorMessage}`);
249
+ const errorResponse = {
250
+ success: false,
251
+ message: errorMessage,
252
+ ...(error instanceof InfiniumError && error.statusCode
253
+ ? { statusCode: error.statusCode }
254
+ : {}),
255
+ };
256
+ results.push(errorResponse);
257
+ }
258
+ }
259
+ const batchResult = {
260
+ totalTasks: tasks.length,
261
+ successfulTasks,
262
+ failedTasks: tasks.length - successfulTasks,
263
+ results,
264
+ errors,
265
+ };
266
+ if (batchResult.failedTasks > 0) {
267
+ this.logger.warn('Batch completed with errors', {
268
+ totalTasks: batchResult.totalTasks,
269
+ successfulTasks: batchResult.successfulTasks,
270
+ failedTasks: batchResult.failedTasks,
271
+ });
272
+ }
273
+ else {
274
+ this.logger.info('Batch completed successfully', {
275
+ totalTasks: batchResult.totalTasks,
276
+ });
277
+ }
278
+ return batchResult;
279
+ }
280
+ /**
281
+ * Test connection to the API.
282
+ */
283
+ async testConnection() {
284
+ this.logger.info('Testing connection', { agentId: this.agentId });
285
+ const response = await this.makeRequest('GET', `/agents/${this.agentId}/health`);
286
+ if (!response.success || !response.data) {
287
+ throw new ServerError(response.message || 'Health check failed', response.statusCode);
288
+ }
289
+ this.logger.info('Connection test successful', {
290
+ agentId: this.agentId,
291
+ agentName: response.data.agentName,
292
+ status: response.data.status,
293
+ });
294
+ return response.data;
295
+ }
296
+ /**
297
+ * Get interpreted task result.
298
+ */
299
+ getInterpretedTaskResult(taskId) {
300
+ validateRequiredField(taskId, 'taskId');
301
+ this.logger.info('Getting interpreted task result', {
302
+ agentId: this.agentId,
303
+ taskId,
304
+ });
305
+ return this.makeRequest('GET', `/agents/${this.agentId}/interpreted-result/${taskId}`);
306
+ }
307
+ /**
308
+ * Get current ISO datetime string.
309
+ */
310
+ getCurrentIsoDatetime() {
311
+ return getCurrentIsoDatetime();
312
+ }
313
+ /**
314
+ * Get client configuration.
315
+ */
316
+ getConfig() {
317
+ return {
318
+ agentId: this.agentId,
319
+ baseUrl: this.baseUrl,
320
+ timeout: this.timeout,
321
+ maxRetries: this.maxRetries,
322
+ userAgent: this.userAgent,
323
+ enableRateLimiting: !!this.rateLimiter,
324
+ };
325
+ }
326
+ /**
327
+ * Clean payload by removing undefined values.
328
+ */
329
+ cleanPayload(payload) {
330
+ const cleaned = {};
331
+ for (const [key, value] of Object.entries(payload)) {
332
+ if (value !== undefined && value !== null) {
333
+ if (typeof value === 'object' && !Array.isArray(value)) {
334
+ const cleanedNested = this.cleanPayload(value);
335
+ if (Object.keys(cleanedNested).length > 0) {
336
+ cleaned[key] = cleanedNested;
337
+ }
338
+ }
339
+ else {
340
+ cleaned[key] = value;
341
+ }
342
+ }
343
+ }
344
+ return cleaned;
345
+ }
346
+ }
347
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAA2D,MAAM,OAAO,CAAC;AAChF,OAAO,UAAU,MAAM,aAAa,CAAC;AAErC,OAAO,EACL,SAAS,GAkBV,MAAM,SAAS,CAAC;AACjB,OAAO,EACL,aAAa,EAEb,eAAe,EACf,cAAc,EAGd,WAAW,EAGX,gBAAgB,GACjB,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,wBAAwB,EACxB,mBAAmB,EACnB,iBAAiB,EACjB,gBAAgB,EAChB,qBAAqB,EACrB,qBAAqB,EACrB,WAAW,EAEX,YAAY,EAEZ,iBAAiB,EACjB,YAAY,EAEZ,gBAAgB,GACjB,MAAM,SAAS,CAAC;AAEjB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,OAAO,cAAc;IACR,OAAO,CAAS;IAEhB,WAAW,CAAS;IAEpB,OAAO,CAAS;IAEhB,OAAO,C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,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;YACnD,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;gBAC1C,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;oBACvD,MAAM,aAAa,GAAG,IAAI,CAAC,YAAY,CAAC,KAAgC,CAAC,CAAC;oBAC1E,IAAI,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;wBAC1C,OAAO,CAAC,GAAG,CAAC,GAAG,aAAa,CAAC;oBAC/B,CAAC;gBACH,CAAC;qBAAM,CAAC;oBACN,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;gBACvB,CAAC;YACH,CAAC;QACH,CAAC;QAED,OAAO,OAAO,CAAC;IACjB,CAAC;CACF"}
@@ -0,0 +1,102 @@
1
+ /**
2
+ * Exception classes for the Infinium SDK.
3
+ */
4
+ /**
5
+ * Base exception for all Infinium SDK errors.
6
+ */
7
+ export declare class InfiniumError extends Error {
8
+ readonly statusCode: number | undefined;
9
+ readonly details: Record<string, unknown>;
10
+ constructor(message: string, statusCode?: number, details?: Record<string, unknown>);
11
+ /**
12
+ * Convert error to JSON for logging or serialization.
13
+ */
14
+ toJSON(): Record<string, unknown>;
15
+ }
16
+ /**
17
+ * Raised when authentication fails.
18
+ */
19
+ export declare class AuthenticationError extends InfiniumError {
20
+ constructor(message?: string, statusCode?: number, details?: Record<string, unknown>);
21
+ }
22
+ /**
23
+ * Raised when request validation fails.
24
+ */
25
+ export declare class ValidationError extends InfiniumError {
26
+ readonly field: string | undefined;
27
+ constructor(message: string, field?: string, details?: Record<string, unknown>);
28
+ }
29
+ /**
30
+ * Raised when rate limit is exceeded.
31
+ */
32
+ export declare class RateLimitError extends InfiniumError {
33
+ readonly retryAfter: number | undefined;
34
+ constructor(message?: string, retryAfter?: number, details?: Record<string, unknown>);
35
+ }
36
+ /**
37
+ * Raised when network-related errors occur.
38
+ */
39
+ export declare class NetworkError extends InfiniumError {
40
+ readonly originalError: Error | undefined;
41
+ constructor(message: string, originalError?: Error, details?: Record<string, unknown>);
42
+ }
43
+ /**
44
+ * Raised when requests timeout.
45
+ */
46
+ export declare class TimeoutError extends NetworkError {
47
+ constructor(message?: string, timeout?: number, details?: Record<string, unknown>);
48
+ }
49
+ /**
50
+ * Raised when server returns 5xx status codes.
51
+ */
52
+ export declare class ServerError extends InfiniumError {
53
+ constructor(message: string, statusCode?: number, details?: Record<string, unknown>);
54
+ }
55
+ /**
56
+ * Raised when resource is not found (404).
57
+ */
58
+ export declare class NotFoundError extends InfiniumError {
59
+ readonly resource: string | undefined;
60
+ constructor(message: string, resource?: string, details?: Record<string, unknown>);
61
+ }
62
+ /**
63
+ * Raised when batch operations fail.
64
+ */
65
+ export declare class BatchError extends InfiniumError {
66
+ readonly failedTasks: number;
67
+ readonly totalTasks: number;
68
+ readonly errors: string[];
69
+ constructor(message: string, failedTasks: number, totalTasks: number, errors?: string[], details?: Record<string, unknown>);
70
+ }
71
+ /**
72
+ * Raised when configuration is invalid.
73
+ */
74
+ export declare class ConfigurationError extends InfiniumError {
75
+ readonly configField: string | undefined;
76
+ constructor(message: string, configField?: string, details?: Record<string, unknown>);
77
+ }
78
+ /**
79
+ * Raised when request data is too large.
80
+ */
81
+ export declare class PayloadTooLargeError extends InfiniumError {
82
+ readonly maxSize: number | undefined;
83
+ readonly actualSize: number | undefined;
84
+ constructor(message: string, maxSize?: number, actualSize?: number, details?: Record<string, unknown>);
85
+ }
86
+ /**
87
+ * Type guard to check if an error is an Infinium error.
88
+ */
89
+ export declare function isInfiniumError(error: unknown): error is InfiniumError;
90
+ /**
91
+ * Type guard to check if an error is a specific Infinium error type.
92
+ */
93
+ export declare function isErrorType<T extends InfiniumError>(error: unknown, errorClass: new (...args: any[]) => T): error is T;
94
+ /**
95
+ * Convert an unknown error to an InfiniumError.
96
+ */
97
+ export declare function toInfiniumError(error: unknown): InfiniumError;
98
+ /**
99
+ * Handle axios errors and convert to appropriate Infinium errors.
100
+ */
101
+ export declare function handleAxiosError(error: unknown): InfiniumError;
102
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,qBAAa,aAAc,SAAQ,KAAK;IACtC,SAAgB,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;IAE/C,SAAgB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;gBAErC,OAAO,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,EAAE,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM;IAYvF;;OAEG;IACH,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CASlC;AAED;;GAEG;AACH,qBAAa,mBAAoB,SAAQ,aAAa;gBAElD,OAAO,SAA0B,EACjC,UAAU,SAAM,EAChB,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM;CAIxC;AAED;;GAEG;AACH,qBAAa,eAAgB,SAAQ,aAAa;IAChD,SAAgB,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;gBAE9B,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM;CAInF;AAED;;GAEG;AACH,qBAAa,cAAe,SAAQ,aAAa;IAC/C,SAAgB,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;gBAG7C,OAAO,SAAwB,EAC/B,UAAU,CAAC,EAAE,MAAM,EACnB,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM;CAKxC;AAED;;GAEG;AACH,qBAAa,YAAa,SAAQ,aAAa;IA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GAEG;AACH,qBAAa,oBAAqB,SAAQ,aAAa;IACrD,SAAgB,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAE5C,SAAgB,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;gBAG7C,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,MAAM,EAChB,UAAU,CAAC,EAAE,MAAM,EACnB,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM;CAMxC;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,aAAa,CAEtE;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,CAAC,SAAS,aAAa,EACjD,KAAK,EAAE,OAAO,EACd,UAAU,EAAE,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,GACpC,KAAK,IAAI,CAAC,CAEZ;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,aAAa,CAc7D;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,aAAa,CAuD9D"}
@@ -0,0 +1,200 @@
1
+ /**
2
+ * Exception classes for the Infinium SDK.
3
+ */
4
+ /**
5
+ * Base exception for all Infinium SDK errors.
6
+ */
7
+ export class InfiniumError extends Error {
8
+ statusCode;
9
+ details;
10
+ constructor(message, statusCode, details = {}) {
11
+ super(message);
12
+ this.name = this.constructor.name;
13
+ this.statusCode = statusCode;
14
+ this.details = details;
15
+ // Maintains proper stack trace for where our error was thrown (only available on V8)
16
+ if ('captureStackTrace' in Error && typeof Error.captureStackTrace === 'function') {
17
+ Error.captureStackTrace(this, this.constructor);
18
+ }
19
+ }
20
+ /**
21
+ * Convert error to JSON for logging or serialization.
22
+ */
23
+ toJSON() {
24
+ return {
25
+ name: this.name,
26
+ message: this.message,
27
+ statusCode: this.statusCode,
28
+ details: this.details,
29
+ stack: this.stack,
30
+ };
31
+ }
32
+ }
33
+ /**
34
+ * Raised when authentication fails.
35
+ */
36
+ export class AuthenticationError extends InfiniumError {
37
+ constructor(message = 'Authentication failed', statusCode = 401, details = {}) {
38
+ super(message, statusCode, details);
39
+ }
40
+ }
41
+ /**
42
+ * Raised when request validation fails.
43
+ */
44
+ export class ValidationError extends InfiniumError {
45
+ field;
46
+ constructor(message, field, details = {}) {
47
+ super(message, undefined, details);
48
+ this.field = field;
49
+ }
50
+ }
51
+ /**
52
+ * Raised when rate limit is exceeded.
53
+ */
54
+ export class RateLimitError extends InfiniumError {
55
+ retryAfter;
56
+ constructor(message = 'Rate limit exceeded', retryAfter, details = {}) {
57
+ super(message, 429, details);
58
+ this.retryAfter = retryAfter;
59
+ }
60
+ }
61
+ /**
62
+ * Raised when network-related errors occur.
63
+ */
64
+ export class NetworkError extends InfiniumError {
65
+ originalError;
66
+ constructor(message, originalError, details = {}) {
67
+ super(message, undefined, details);
68
+ this.originalError = originalError;
69
+ }
70
+ }
71
+ /**
72
+ * Raised when requests timeout.
73
+ */
74
+ export class TimeoutError extends NetworkError {
75
+ constructor(message = 'Request timeout', timeout, details = {}) {
76
+ super(message, undefined, { ...details, timeout });
77
+ }
78
+ }
79
+ /**
80
+ * Raised when server returns 5xx status codes.
81
+ */
82
+ export class ServerError extends InfiniumError {
83
+ constructor(message, statusCode = 500, details = {}) {
84
+ super(message, statusCode, details);
85
+ }
86
+ }
87
+ /**
88
+ * Raised when resource is not found (404).
89
+ */
90
+ export class NotFoundError extends InfiniumError {
91
+ resource;
92
+ constructor(message, resource, details = {}) {
93
+ super(message, 404, details);
94
+ this.resource = resource;
95
+ }
96
+ }
97
+ /**
98
+ * Raised when batch operations fail.
99
+ */
100
+ export class BatchError extends InfiniumError {
101
+ failedTasks;
102
+ totalTasks;
103
+ errors;
104
+ constructor(message, failedTasks, totalTasks, errors = [], details = {}) {
105
+ super(message, undefined, details);
106
+ this.failedTasks = failedTasks;
107
+ this.totalTasks = totalTasks;
108
+ this.errors = errors;
109
+ }
110
+ }
111
+ /**
112
+ * Raised when configuration is invalid.
113
+ */
114
+ export class ConfigurationError extends InfiniumError {
115
+ configField;
116
+ constructor(message, configField, details = {}) {
117
+ super(message, undefined, details);
118
+ this.configField = configField;
119
+ }
120
+ }
121
+ /**
122
+ * Raised when request data is too large.
123
+ */
124
+ export class PayloadTooLargeError extends InfiniumError {
125
+ maxSize;
126
+ actualSize;
127
+ constructor(message, maxSize, actualSize, details = {}) {
128
+ super(message, 413, { ...details, maxSize, actualSize });
129
+ this.maxSize = maxSize;
130
+ this.actualSize = actualSize;
131
+ }
132
+ }
133
+ /**
134
+ * Type guard to check if an error is an Infinium error.
135
+ */
136
+ export function isInfiniumError(error) {
137
+ return error instanceof InfiniumError;
138
+ }
139
+ /**
140
+ * Type guard to check if an error is a specific Infinium error type.
141
+ */
142
+ export function isErrorType(error, errorClass // eslint-disable-line @typescript-eslint/no-explicit-any
143
+ ) {
144
+ return error instanceof errorClass;
145
+ }
146
+ /**
147
+ * Convert an unknown error to an InfiniumError.
148
+ */
149
+ export function toInfiniumError(error) {
150
+ if (isInfiniumError(error)) {
151
+ return error;
152
+ }
153
+ if (error instanceof Error) {
154
+ return new InfiniumError(error.message, undefined, { originalError: error });
155
+ }
156
+ return new InfiniumError(typeof error === 'string' ? error : 'Unknown error occurred', undefined, { originalValue: error });
157
+ }
158
+ /**
159
+ * Handle axios errors and convert to appropriate Infinium errors.
160
+ */
161
+ export function handleAxiosError(error) {
162
+ if (error && typeof error === 'object' && 'response' in error) {
163
+ const axiosError = error;
164
+ const { response, message, code } = axiosError;
165
+ if (response) {
166
+ const { status, statusText, data } = response;
167
+ const errorMessage = typeof data === 'object' && data && 'message' in data
168
+ ? String(data.message)
169
+ : statusText || message;
170
+ switch (status) {
171
+ case 400:
172
+ return new ValidationError(errorMessage, undefined, { status, data });
173
+ case 401:
174
+ case 403:
175
+ return new AuthenticationError(errorMessage, status, { data });
176
+ case 404:
177
+ return new NotFoundError(errorMessage, undefined, { data });
178
+ case 413:
179
+ return new PayloadTooLargeError(errorMessage, undefined, undefined, { data });
180
+ case 429:
181
+ const retryAfter = typeof data === 'object' && data && 'retryAfter' in data
182
+ ? Number(data.retryAfter) || undefined
183
+ : undefined;
184
+ return new RateLimitError(errorMessage, retryAfter, { data });
185
+ default:
186
+ if (status >= 500) {
187
+ return new ServerError(errorMessage, status, { data });
188
+ }
189
+ return new InfiniumError(errorMessage, status, { data });
190
+ }
191
+ }
192
+ // Network errors (no response)
193
+ if (code === 'ECONNABORTED' || message.includes('timeout')) {
194
+ return new TimeoutError(message);
195
+ }
196
+ return new NetworkError(message, error);
197
+ }
198
+ return toInfiniumError(error);
199
+ }
200
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,MAAM,OAAO,aAAc,SAAQ,KAAK;IACtB,UAAU,CAAqB;IAE/B,OAAO,CAA0B;IAEjD,YAAY,OAAe,EAAE,UAAmB,EAAE,UAAmC,EAAE;QACrF,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;QAClC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QAEvB,qFAAqF;QACrF,IAAI,mBAAmB,IAAI,KAAK,IAAI,OAAO,KAAK,CAAC,iBAAiB,KAAK,UAAU,EAAE,CAAC;YAClF,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;QAClD,CAAC;IACH,CAAC;IAED;;OAEG;IACH,MAAM;QACJ,OAAO;YACL,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,OAAO,EAAE,IAAI,CAAC,OA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