@jack-kernel/sdk 1.0.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 (68) hide show
  1. package/README.md +757 -0
  2. package/dist/cjs/agent.js +321 -0
  3. package/dist/cjs/agent.js.map +1 -0
  4. package/dist/cjs/cache.js +58 -0
  5. package/dist/cjs/cache.js.map +1 -0
  6. package/dist/cjs/client.js +196 -0
  7. package/dist/cjs/client.js.map +1 -0
  8. package/dist/cjs/costs.js +104 -0
  9. package/dist/cjs/costs.js.map +1 -0
  10. package/dist/cjs/errors.js +287 -0
  11. package/dist/cjs/errors.js.map +1 -0
  12. package/dist/cjs/execution.js +385 -0
  13. package/dist/cjs/execution.js.map +1 -0
  14. package/dist/cjs/index.js +256 -0
  15. package/dist/cjs/index.js.map +1 -0
  16. package/dist/cjs/intents.js +185 -0
  17. package/dist/cjs/intents.js.map +1 -0
  18. package/dist/cjs/serialization.js +164 -0
  19. package/dist/cjs/serialization.js.map +1 -0
  20. package/dist/cjs/types.js +31 -0
  21. package/dist/cjs/types.js.map +1 -0
  22. package/dist/cjs/validation.js +114 -0
  23. package/dist/cjs/validation.js.map +1 -0
  24. package/dist/esm/agent.js +317 -0
  25. package/dist/esm/agent.js.map +1 -0
  26. package/dist/esm/cache.js +54 -0
  27. package/dist/esm/cache.js.map +1 -0
  28. package/dist/esm/client.js +192 -0
  29. package/dist/esm/client.js.map +1 -0
  30. package/dist/esm/costs.js +100 -0
  31. package/dist/esm/costs.js.map +1 -0
  32. package/dist/esm/errors.js +278 -0
  33. package/dist/esm/errors.js.map +1 -0
  34. package/dist/esm/execution.js +381 -0
  35. package/dist/esm/execution.js.map +1 -0
  36. package/dist/esm/index.js +236 -0
  37. package/dist/esm/index.js.map +1 -0
  38. package/dist/esm/intents.js +181 -0
  39. package/dist/esm/intents.js.map +1 -0
  40. package/dist/esm/serialization.js +159 -0
  41. package/dist/esm/serialization.js.map +1 -0
  42. package/dist/esm/types.js +28 -0
  43. package/dist/esm/types.js.map +1 -0
  44. package/dist/esm/validation.js +111 -0
  45. package/dist/esm/validation.js.map +1 -0
  46. package/dist/types/agent.d.ts +171 -0
  47. package/dist/types/agent.d.ts.map +1 -0
  48. package/dist/types/cache.d.ts +25 -0
  49. package/dist/types/cache.d.ts.map +1 -0
  50. package/dist/types/client.d.ts +46 -0
  51. package/dist/types/client.d.ts.map +1 -0
  52. package/dist/types/costs.d.ts +91 -0
  53. package/dist/types/costs.d.ts.map +1 -0
  54. package/dist/types/errors.d.ts +242 -0
  55. package/dist/types/errors.d.ts.map +1 -0
  56. package/dist/types/execution.d.ts +145 -0
  57. package/dist/types/execution.d.ts.map +1 -0
  58. package/dist/types/index.d.ts +205 -0
  59. package/dist/types/index.d.ts.map +1 -0
  60. package/dist/types/intents.d.ts +158 -0
  61. package/dist/types/intents.d.ts.map +1 -0
  62. package/dist/types/serialization.d.ts +82 -0
  63. package/dist/types/serialization.d.ts.map +1 -0
  64. package/dist/types/types.d.ts +302 -0
  65. package/dist/types/types.d.ts.map +1 -0
  66. package/dist/types/validation.d.ts +40 -0
  67. package/dist/types/validation.d.ts.map +1 -0
  68. package/package.json +56 -0
@@ -0,0 +1,317 @@
1
+ /**
2
+ * Agent utilities for the JACK SDK
3
+ *
4
+ * This module provides the AgentUtils class with high-level abstractions
5
+ * for batch operations, dry-run validation, policy enforcement, and
6
+ * event subscriptions for automated agent systems.
7
+ *
8
+ * Requirements: 8.1, 8.2, 8.3, 8.4, 8.5
9
+ */
10
+ import { IntentManager } from './intents.js';
11
+ import { ExecutionTracker } from './execution.js';
12
+ import { validateIntentParams } from './validation.js';
13
+ /**
14
+ * Utilities for agent-based intent orchestration
15
+ *
16
+ * Provides batch operations, dry-run validation, policy enforcement,
17
+ * and multi-intent subscriptions for automated systems.
18
+ *
19
+ * @example
20
+ * ```typescript
21
+ * const client = new JackClient({ baseUrl: 'https://api.jack.example' });
22
+ * const agent = new AgentUtils(client);
23
+ *
24
+ * // Batch submit multiple intents
25
+ * const results = await agent.batchSubmit([
26
+ * { params: intent1, signature: sig1 },
27
+ * { params: intent2, signature: sig2 }
28
+ * ]);
29
+ *
30
+ * results.forEach(result => {
31
+ * if (result.success) {
32
+ * console.log('Submitted:', result.intentId);
33
+ * } else {
34
+ * console.error('Failed:', result.error);
35
+ * }
36
+ * });
37
+ * ```
38
+ */
39
+ export class AgentUtils {
40
+ client;
41
+ intentManager;
42
+ executionTracker;
43
+ /**
44
+ * Creates a new AgentUtils instance
45
+ *
46
+ * @param client - The JackClient instance to use for API requests
47
+ */
48
+ constructor(client) {
49
+ this.client = client;
50
+ this.intentManager = new IntentManager(client);
51
+ this.executionTracker = new ExecutionTracker(client);
52
+ }
53
+ /**
54
+ * Submit multiple intents in parallel
55
+ *
56
+ * Uses Promise.allSettled() to submit all intents concurrently,
57
+ * ensuring that failures in individual submissions don't affect others.
58
+ * The result array length always matches the input array length,
59
+ * with each result corresponding to the same index in the input.
60
+ *
61
+ * @param intents - Array of intent parameters and signatures to submit
62
+ * @returns Promise resolving to array of BatchSubmitResult objects
63
+ *
64
+ * @example
65
+ * ```typescript
66
+ * const results = await agent.batchSubmit([
67
+ * { params: intent1, signature: sig1 },
68
+ * { params: intent2, signature: sig2 },
69
+ * { params: intent3, signature: sig3 }
70
+ * ]);
71
+ *
72
+ * // Results array has same length as input
73
+ * console.log(results.length); // 3
74
+ *
75
+ * // Check individual results
76
+ * results.forEach((result, index) => {
77
+ * if (result.success) {
78
+ * console.log(`Intent ${index} submitted: ${result.intentId}`);
79
+ * } else {
80
+ * console.error(`Intent ${index} failed:`, result.error?.message);
81
+ * }
82
+ * });
83
+ *
84
+ * // Count successes and failures
85
+ * const successes = results.filter(r => r.success).length;
86
+ * const failures = results.filter(r => !r.success).length;
87
+ * console.log(`${successes} succeeded, ${failures} failed`);
88
+ * ```
89
+ *
90
+ * **Validates: Requirements 8.1, 8.2**
91
+ */
92
+ async batchSubmit(intents) {
93
+ // Submit all intents in parallel using Promise.allSettled
94
+ // This ensures all submissions are attempted regardless of individual failures
95
+ const promises = intents.map(async ({ params, signature }) => {
96
+ return this.intentManager.submit(params, signature);
97
+ });
98
+ const results = await Promise.allSettled(promises);
99
+ // Transform PromiseSettledResult to BatchSubmitResult
100
+ // Ensure result array length matches input array length
101
+ return results.map((result, index) => {
102
+ if (result.status === 'fulfilled') {
103
+ return {
104
+ intentId: result.value,
105
+ success: true
106
+ };
107
+ }
108
+ else {
109
+ return {
110
+ intentId: '', // Empty string for failed submissions
111
+ success: false,
112
+ error: result.reason instanceof Error ? result.reason : new Error(String(result.reason))
113
+ };
114
+ }
115
+ });
116
+ }
117
+ /**
118
+ * Simulate intent execution without submission
119
+ *
120
+ * Validates intent parameters and estimates costs without actually
121
+ * submitting the intent to the API. Useful for testing and validation.
122
+ *
123
+ * @param params - Intent parameters to validate
124
+ * @returns Promise resolving to DryRunResult with validation status
125
+ *
126
+ * @example
127
+ * ```typescript
128
+ * const result = await agent.dryRun(params);
129
+ * if (result.valid) {
130
+ * console.log('Estimated cost:', result.estimatedCost);
131
+ * } else {
132
+ * console.error('Validation errors:', result.errors);
133
+ * }
134
+ * ```
135
+ *
136
+ * **Validates: Requirement 8.4**
137
+ */
138
+ async dryRun(params) {
139
+ const validation = validateIntentParams(params);
140
+ if (!validation.valid) {
141
+ return {
142
+ valid: false,
143
+ errors: validation.errors
144
+ };
145
+ }
146
+ // In a real implementation, this might call an API endpoint
147
+ // to get cost estimates. For now, we just return validation status.
148
+ return {
149
+ valid: true,
150
+ estimatedCost: undefined, // Could be populated by API call
151
+ errors: []
152
+ };
153
+ }
154
+ /**
155
+ * Validate intent parameters against policy rules
156
+ *
157
+ * Checks that intent parameters comply with the specified policy,
158
+ * including amount limits, allowed chains, tokens, and deadline constraints.
159
+ *
160
+ * @param params - Intent parameters to validate
161
+ * @param policy - Policy rules to enforce
162
+ * @returns ValidationResult with valid flag and error messages
163
+ *
164
+ * @example
165
+ * ```typescript
166
+ * const policy: Policy = {
167
+ * maxAmountIn: '1000000000',
168
+ * allowedSourceChains: ['arbitrum', 'optimism'],
169
+ * allowedDestinationChains: ['base', 'ethereum'],
170
+ * maxDeadlineOffset: 3600000 // 1 hour
171
+ * };
172
+ *
173
+ * const result = agent.validatePolicy(params, policy);
174
+ * if (!result.valid) {
175
+ * console.error('Policy violations:', result.errors);
176
+ * }
177
+ * ```
178
+ *
179
+ * **Validates: Requirement 8.5**
180
+ */
181
+ validatePolicy(params, policy) {
182
+ const errors = [];
183
+ // Check maximum amount in
184
+ if (policy.maxAmountIn !== undefined) {
185
+ const maxAmount = BigInt(policy.maxAmountIn);
186
+ const amount = BigInt(params.amountIn);
187
+ if (amount > maxAmount) {
188
+ errors.push(`Amount in ${params.amountIn} exceeds maximum ${policy.maxAmountIn}`);
189
+ }
190
+ }
191
+ // Check minimum amount out
192
+ if (policy.minAmountOut !== undefined) {
193
+ const minAmount = BigInt(policy.minAmountOut);
194
+ const amount = BigInt(params.minAmountOut);
195
+ if (amount < minAmount) {
196
+ errors.push(`Minimum amount out ${params.minAmountOut} is below policy minimum ${policy.minAmountOut}`);
197
+ }
198
+ }
199
+ // Check allowed source chains
200
+ if (policy.allowedSourceChains !== undefined) {
201
+ if (!policy.allowedSourceChains.includes(params.sourceChain)) {
202
+ errors.push(`Source chain ${params.sourceChain} is not in allowed list: ${policy.allowedSourceChains.join(', ')}`);
203
+ }
204
+ }
205
+ // Check allowed destination chains
206
+ if (policy.allowedDestinationChains !== undefined) {
207
+ if (!policy.allowedDestinationChains.includes(params.destinationChain)) {
208
+ errors.push(`Destination chain ${params.destinationChain} is not in allowed list: ${policy.allowedDestinationChains.join(', ')}`);
209
+ }
210
+ }
211
+ // Check allowed input tokens
212
+ if (policy.allowedTokensIn !== undefined) {
213
+ if (!policy.allowedTokensIn.includes(params.tokenIn)) {
214
+ errors.push(`Input token ${params.tokenIn} is not in allowed list`);
215
+ }
216
+ }
217
+ // Check allowed output tokens
218
+ if (policy.allowedTokensOut !== undefined) {
219
+ if (!policy.allowedTokensOut.includes(params.tokenOut)) {
220
+ errors.push(`Output token ${params.tokenOut} is not in allowed list`);
221
+ }
222
+ }
223
+ // Check maximum deadline offset
224
+ if (policy.maxDeadlineOffset !== undefined) {
225
+ const now = Date.now();
226
+ const deadlineOffset = params.deadline - now;
227
+ if (deadlineOffset > policy.maxDeadlineOffset) {
228
+ errors.push(`Deadline offset ${deadlineOffset}ms exceeds maximum ${policy.maxDeadlineOffset}ms`);
229
+ }
230
+ }
231
+ return {
232
+ valid: errors.length === 0,
233
+ errors
234
+ };
235
+ }
236
+ /**
237
+ * Subscribe to status changes for multiple intents
238
+ *
239
+ * Polls multiple intents in parallel and invokes the callback whenever
240
+ * any intent's status changes. Returns a Subscription object that can
241
+ * be used to unsubscribe and stop polling.
242
+ *
243
+ * @param intentIds - Array of intent IDs to monitor
244
+ * @param callback - Function to call when any intent status changes
245
+ * @param options - Polling options (interval, timeout)
246
+ * @returns Subscription object with unsubscribe() method
247
+ *
248
+ * @example
249
+ * ```typescript
250
+ * const subscription = agent.subscribeToUpdates(
251
+ * ['JK-ABC123456', 'JK-DEF789012'],
252
+ * (intentId, intent) => {
253
+ * console.log(`${intentId} status changed to ${intent.status}`);
254
+ * },
255
+ * { interval: 5000 }
256
+ * );
257
+ *
258
+ * // Later, stop polling
259
+ * subscription.unsubscribe();
260
+ * ```
261
+ *
262
+ * **Validates: Requirement 8.3**
263
+ */
264
+ subscribeToUpdates(intentIds, callback, options) {
265
+ const interval = options?.interval ?? 2000;
266
+ const timeout = options?.timeout;
267
+ const startTime = Date.now();
268
+ // Track last known status for each intent
269
+ const lastStatuses = new Map();
270
+ let intervalId = null;
271
+ let stopped = false;
272
+ const poll = async () => {
273
+ if (stopped)
274
+ return;
275
+ // Check timeout
276
+ if (timeout && Date.now() - startTime > timeout) {
277
+ stopped = true;
278
+ if (intervalId)
279
+ clearInterval(intervalId);
280
+ return;
281
+ }
282
+ // Poll all intents in parallel
283
+ const promises = intentIds.map(async (intentId) => {
284
+ try {
285
+ const intent = await this.intentManager.get(intentId);
286
+ // Check if status changed
287
+ const lastStatus = lastStatuses.get(intentId);
288
+ if (lastStatus !== intent.status) {
289
+ lastStatuses.set(intentId, intent.status);
290
+ callback(intentId, intent);
291
+ }
292
+ }
293
+ catch (error) {
294
+ // Silently ignore errors in polling
295
+ // In a production implementation, might want to expose error callbacks
296
+ }
297
+ });
298
+ await Promise.allSettled(promises);
299
+ };
300
+ // Start polling
301
+ intervalId = setInterval(poll, interval);
302
+ // Do initial poll
303
+ poll().catch(() => {
304
+ // Ignore initial poll errors
305
+ });
306
+ return {
307
+ unsubscribe() {
308
+ stopped = true;
309
+ if (intervalId) {
310
+ clearInterval(intervalId);
311
+ intervalId = null;
312
+ }
313
+ }
314
+ };
315
+ }
316
+ }
317
+ //# sourceMappingURL=agent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent.js","sourceRoot":"","sources":["../../src/agent.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAaH,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAEvD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,OAAO,UAAU;IACJ,MAAM,CAAa;IACnB,aAAa,CAAgB;IAC7B,gBAAgB,CAAmB;IAEpD;;;;OAIG;IACH,YAAY,MAAkB;QAC5B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,aAAa,GAAG,IAAI,aAAa,CAAC,MAAM,CAAC,CAAC;QAC/C,IAAI,CAAC,gBAAgB,GAAG,IAAI,gBAAgB,CAAC,MAAM,CAAC,CAAC;IACvD,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAsCG;IACH,KAAK,CAAC,WAAW,CACf,OAA2D;QAE3D,0DAA0D;QAC1D,+E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,CAAC;oBAC7B,CAAC;gBACH,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACf,oCAAoC;oBACpC,uEAAuE;gBACzE,CAAC;YACH,CAAC,CAAC,CAAC;YAEH,MAAM,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;QACrC,CAAC,CAAC;QAEF,gBAAgB;QAChB,UAAU,GAAG,WAAW,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;QAEzC,kBAAkB;QAClB,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE;YAChB,6BAA6B;QAC/B,CAAC,CAAC,CAAC;QAEH,OAAO;YACL,WAAW;gBACT,OAAO,GAAG,IAAI,CAAC;gBACf,IAAI,UAAU,EAAE,CAAC;oBACf,aAAa,CAAC,UAAU,CAAC,CAAC;oBAC1B,UAAU,GAAG,IAAI,CAAC;gBACpB,CAAC;YACH,CAAC;SACF,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Simple in-memory cache with TTL support
3
+ */
4
+ export class Cache {
5
+ store = new Map();
6
+ defaultTTL;
7
+ constructor(defaultTTL = 60000) {
8
+ this.defaultTTL = defaultTTL;
9
+ }
10
+ /**
11
+ * Get value from cache if not expired
12
+ */
13
+ get(key) {
14
+ const entry = this.store.get(key);
15
+ if (!entry) {
16
+ return null;
17
+ }
18
+ // Check if expired
19
+ if (Date.now() > entry.expiresAt) {
20
+ this.store.delete(key);
21
+ return null;
22
+ }
23
+ return entry.value;
24
+ }
25
+ /**
26
+ * Set value in cache with TTL
27
+ */
28
+ set(key, value, ttl) {
29
+ const expiresAt = Date.now() + (ttl ?? this.defaultTTL);
30
+ this.store.set(key, { value, expiresAt });
31
+ }
32
+ /**
33
+ * Clear cache entries matching pattern
34
+ */
35
+ clear(pattern) {
36
+ if (!pattern) {
37
+ this.store.clear();
38
+ return;
39
+ }
40
+ const regex = new RegExp(pattern);
41
+ for (const key of this.store.keys()) {
42
+ if (regex.test(key)) {
43
+ this.store.delete(key);
44
+ }
45
+ }
46
+ }
47
+ /**
48
+ * Get cache size
49
+ */
50
+ size() {
51
+ return this.store.size;
52
+ }
53
+ }
54
+ //# sourceMappingURL=cache.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cache.js","sourceRoot":"","sources":["../../src/cache.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,OAAO,KAAK;IACR,KAAK,GAA4B,IAAI,GAAG,EAAE,CAAC;IAClC,UAAU,CAAS;IAEpC,YAAY,aAAqB,KAAK;QACpC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;IAED;;OAEG;IACH,GAAG,CAAI,GAAW;QAChB,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAElC,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,OAAO,IAAI,CAAC;QACd,CAAC;QAED,mBAAmB;QACnB,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC,SAAS,EAAE,CAAC;YACjC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YACvB,OAAO,IAAI,CAAC;QACd,CAAC;QAED,OAAO,KAAK,CAAC,KAAU,CAAC;IAC1B,CAAC;IAED;;OAEG;IACH,GAAG,CAAI,GAAW,EAAE,KAAQ,EAAE,GAAY;QACxC,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,IAAI,IAAI,CAAC,UAAU,CAAC,CAAC;QACxD,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC;IAC5C,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,OAAgB;QACpB,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;YACnB,OAAO;QACT,CAAC;QAED,MAAM,KAAK,GAAG,IAAI,MAAM,CAAC,OAAO,CAAC,CAAC;QAClC,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,EAAE,CAAC;YACpC,IAAI,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;gBACpB,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YACzB,CAAC;QACH,CAAC;IACH,CAAC;IAED;;OAEG;IACH,IAAI;QACF,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;IACzB,CAAC;CACF"}
@@ -0,0 +1,192 @@
1
+ import { NetworkError, APIError, ValidationError, TimeoutError, RetryError } from './errors.js';
2
+ import { Cache } from './cache.js';
3
+ /**
4
+ * Core HTTP client for JACK API with retry logic, timeout handling, and caching
5
+ */
6
+ export class JackClient {
7
+ config;
8
+ cache;
9
+ constructor(config) {
10
+ this.validateConfig(config);
11
+ this.config = {
12
+ baseUrl: config.baseUrl,
13
+ timeout: config.timeout ?? 30000,
14
+ maxRetries: config.maxRetries ?? 3,
15
+ retryDelay: config.retryDelay ?? 1000,
16
+ retryBackoff: config.retryBackoff ?? 2,
17
+ enableCache: config.enableCache ?? true,
18
+ cacheTTL: config.cacheTTL ?? 60000,
19
+ headers: config.headers ?? {},
20
+ };
21
+ this.cache = new Cache(this.config.cacheTTL);
22
+ }
23
+ /**
24
+ * Validate client configuration
25
+ */
26
+ validateConfig(config) {
27
+ const errors = [];
28
+ if (!config.baseUrl || config.baseUrl.trim() === '') {
29
+ errors.push('baseUrl is required and cannot be empty');
30
+ }
31
+ if (config.timeout !== undefined && config.timeout <= 0) {
32
+ errors.push('timeout must be positive');
33
+ }
34
+ if (config.maxRetries !== undefined && config.maxRetries < 0) {
35
+ errors.push('maxRetries cannot be negative');
36
+ }
37
+ if (config.retryDelay !== undefined && config.retryDelay < 0) {
38
+ errors.push('retryDelay cannot be negative');
39
+ }
40
+ if (config.retryBackoff !== undefined && config.retryBackoff < 1) {
41
+ errors.push('retryBackoff must be >= 1');
42
+ }
43
+ if (config.cacheTTL !== undefined && config.cacheTTL < 0) {
44
+ errors.push('cacheTTL cannot be negative');
45
+ }
46
+ if (errors.length > 0) {
47
+ throw new ValidationError('Invalid client configuration', errors);
48
+ }
49
+ }
50
+ /**
51
+ * Perform GET request with caching support
52
+ */
53
+ async get(path, options) {
54
+ const cacheKey = this.getCacheKey(path, options);
55
+ // Check cache if enabled
56
+ if (this.config.enableCache && !options?.skipCache) {
57
+ const cached = this.cache.get(cacheKey);
58
+ if (cached !== null) {
59
+ return cached;
60
+ }
61
+ }
62
+ // Execute request with retry
63
+ const result = await this.executeWithRetry(() => this.executeRequest('GET', path, undefined, options));
64
+ // Cache successful GET responses
65
+ if (this.config.enableCache && !options?.skipCache) {
66
+ this.cache.set(cacheKey, result);
67
+ }
68
+ return result;
69
+ }
70
+ /**
71
+ * Perform POST request (never cached)
72
+ */
73
+ async post(path, body, options) {
74
+ return this.executeWithRetry(() => this.executeRequest('POST', path, body, options));
75
+ }
76
+ /**
77
+ * Clear cache entries matching pattern
78
+ */
79
+ clearCache(pattern) {
80
+ this.cache.clear(pattern);
81
+ }
82
+ /**
83
+ * Generate cache key from URL and options
84
+ */
85
+ getCacheKey(path, options) {
86
+ const params = options?.params ? JSON.stringify(options.params) : '';
87
+ return `${path}${params}`;
88
+ }
89
+ /**
90
+ * Execute HTTP request with timeout
91
+ */
92
+ async executeRequest(method, path, body, options) {
93
+ const url = `${this.config.baseUrl}${path}`;
94
+ const timeout = options?.timeout ?? this.config.timeout;
95
+ // Create abort controller for timeout
96
+ const controller = new AbortController();
97
+ const timeoutId = setTimeout(() => controller.abort(), timeout);
98
+ try {
99
+ const headers = {
100
+ 'Content-Type': 'application/json',
101
+ ...this.config.headers,
102
+ ...options?.headers,
103
+ };
104
+ const response = await fetch(url, {
105
+ method,
106
+ headers,
107
+ body: body ? JSON.stringify(body) : undefined,
108
+ signal: controller.signal,
109
+ });
110
+ clearTimeout(timeoutId);
111
+ if (!response.ok) {
112
+ const errorBody = await response.text();
113
+ let errorMessage;
114
+ try {
115
+ const errorJson = JSON.parse(errorBody);
116
+ errorMessage = errorJson.message || errorJson.error || response.statusText;
117
+ }
118
+ catch {
119
+ errorMessage = errorBody || response.statusText;
120
+ }
121
+ throw new APIError(errorMessage, response.status, errorBody);
122
+ }
123
+ const data = await response.json();
124
+ return data;
125
+ }
126
+ catch (error) {
127
+ clearTimeout(timeoutId);
128
+ if (error instanceof APIError) {
129
+ throw error;
130
+ }
131
+ if (error instanceof Error) {
132
+ if (error.name === 'AbortError') {
133
+ throw new TimeoutError(`Request timed out after ${timeout}ms`, timeout);
134
+ }
135
+ throw new NetworkError(`Network request failed: ${error.message}`, error);
136
+ }
137
+ throw new NetworkError('Unknown network error', new Error(String(error)));
138
+ }
139
+ }
140
+ /**
141
+ * Execute function with retry logic and exponential backoff
142
+ */
143
+ async executeWithRetry(fn) {
144
+ let lastError = null;
145
+ let delay = this.config.retryDelay;
146
+ for (let attempt = 0; attempt <= this.config.maxRetries; attempt++) {
147
+ try {
148
+ return await fn();
149
+ }
150
+ catch (error) {
151
+ lastError = error;
152
+ // Don't retry on non-retryable errors - throw immediately
153
+ if (error instanceof APIError && !this.isRetryable(error)) {
154
+ throw error;
155
+ }
156
+ if (error instanceof ValidationError) {
157
+ throw error;
158
+ }
159
+ if (error instanceof TimeoutError) {
160
+ throw error;
161
+ }
162
+ // Don't retry if we've exhausted attempts
163
+ if (attempt === this.config.maxRetries) {
164
+ // If maxRetries is 0, throw the original error, not RetryError
165
+ if (this.config.maxRetries === 0) {
166
+ throw error;
167
+ }
168
+ break;
169
+ }
170
+ // Wait before retrying
171
+ await this.sleep(delay);
172
+ delay *= this.config.retryBackoff;
173
+ }
174
+ }
175
+ // All retries exhausted
176
+ throw new RetryError(`Request failed after ${this.config.maxRetries + 1} attempts`, this.config.maxRetries + 1, lastError);
177
+ }
178
+ /**
179
+ * Check if error is retryable
180
+ */
181
+ isRetryable(error) {
182
+ // Retry on 5xx server errors and 429 rate limit
183
+ return error.statusCode >= 500 || error.statusCode === 429;
184
+ }
185
+ /**
186
+ * Sleep for specified milliseconds
187
+ */
188
+ sleep(ms) {
189
+ return new Promise(resolve => setTimeout(resolve, ms));
190
+ }
191
+ }
192
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,eAAe,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEhG,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC;;GAEG;AACH,MAAM,OAAO,UAAU;IACJ,MAAM,CAAyB;IAC/B,KAAK,CAAQ;IAE9B,YAAY,MAAoB;QAC9B,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;QAE5B,IAAI,CAAC,MAAM,GAAG;YACZ,OAAO,EAAE,MAAM,CAAC,OAAO;YACvB,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,KAAK;YAChC,UAAU,EAAE,MAAM,CAAC,UAAU,IAAI,CAAC;YAClC,UAAU,EAAE,MAAM,CAAC,UAAU,IAAI,IAAI;YACrC,YAAY,EAAE,MAAM,CAAC,YAAY,IAAI,CAAC;YACtC,WAAW,EAAE,MAAM,CAAC,WAAW,IAAI,IAAI;YACvC,QAAQ,EAAE,MAAM,CAAC,QAAQ,IAAI,KAAK;YAClC,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,EAAE;SAC9B,CAAC;QAEF,IAAI,CAAC,KAAK,GAAG,IAAI,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAC/C,CAAC;IAED;;OAEG;IACK,cAAc,CAAC,MAAoB;QACzC,MAAM,MAAM,GAAa,EAAE,CAAC;QAE5B,IAAI,CAAC,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,OAAO,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