@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,381 @@
1
+ /**
2
+ * Execution tracking for the JACK SDK
3
+ *
4
+ * This module provides the ExecutionTracker class for polling intent status
5
+ * and waiting for specific execution states.
6
+ *
7
+ * Requirements: 2.1, 2.5
8
+ */
9
+ import { ExecutionStatus } from './types.js';
10
+ import { TimeoutError } from './errors.js';
11
+ /**
12
+ * Manager for execution tracking operations
13
+ *
14
+ * Provides methods to poll intent status, wait for specific statuses,
15
+ * and track execution progress with configurable timeouts.
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * const client = new JackClient({ baseUrl: 'https://api.jack.example' });
20
+ * const tracker = new ExecutionTracker(client);
21
+ *
22
+ * // Wait for intent to settle
23
+ * const intent = await tracker.waitForStatus(
24
+ * 'JK-ABC123456',
25
+ * ExecutionStatus.SETTLED,
26
+ * { timeout: 120000 }
27
+ * );
28
+ *
29
+ * console.log('Settlement tx:', intent.settlementTx);
30
+ * ```
31
+ */
32
+ export class ExecutionTracker {
33
+ client;
34
+ /**
35
+ * Creates a new ExecutionTracker
36
+ *
37
+ * @param client - The JackClient instance to use for API requests
38
+ */
39
+ constructor(client) {
40
+ this.client = client;
41
+ }
42
+ /**
43
+ * Get current status of an intent
44
+ *
45
+ * Queries the JACK API for the current intent status. This is a single
46
+ * request that returns the intent's current state without polling.
47
+ * This method delegates to the IntentManager's get() method.
48
+ *
49
+ * @param intentId - The intent ID to query (format: JK-[A-Z0-9]{9})
50
+ * @returns Promise resolving to the complete Intent object
51
+ * @throws APIError if the intent is not found (404) or other API error
52
+ * @throws NetworkError if the network request fails
53
+ *
54
+ * @example
55
+ * ```typescript
56
+ * const intent = await tracker.getStatus('JK-ABC123456');
57
+ * console.log('Current status:', intent.status);
58
+ * ```
59
+ *
60
+ * **Validates: Requirement 2.1**
61
+ */
62
+ async getStatus(intentId) {
63
+ return this.client.get(`/api/intents/${intentId}`);
64
+ }
65
+ /**
66
+ * Wait for intent to reach a specific status
67
+ *
68
+ * Polls the intent status at regular intervals until it reaches one of the
69
+ * target statuses or the timeout is exceeded. This is useful for waiting
70
+ * for intent completion or specific state transitions.
71
+ *
72
+ * The polling loop will stop when:
73
+ * - The intent reaches one of the target statuses
74
+ * - The timeout is exceeded (throws TimeoutError)
75
+ * - An API error occurs (throws APIError)
76
+ *
77
+ * @param intentId - The intent ID to poll
78
+ * @param targetStatus - Single status or array of statuses to wait for
79
+ * @param options - Polling configuration (interval, timeout, stopStatuses)
80
+ * @returns Promise resolving to the Intent when target status is reached
81
+ * @throws TimeoutError if timeout is exceeded before reaching target status
82
+ * @throws APIError if the API returns an error
83
+ * @throws NetworkError if the network request fails
84
+ *
85
+ * @example
86
+ * ```typescript
87
+ * // Wait for settlement with custom timeout
88
+ * const intent = await tracker.waitForStatus(
89
+ * 'JK-ABC123456',
90
+ * ExecutionStatus.SETTLED,
91
+ * { interval: 3000, timeout: 120000 }
92
+ * );
93
+ *
94
+ * // Wait for any terminal status
95
+ * const intent = await tracker.waitForStatus(
96
+ * 'JK-ABC123456',
97
+ * [ExecutionStatus.SETTLED, ExecutionStatus.ABORTED, ExecutionStatus.EXPIRED]
98
+ * );
99
+ * ```
100
+ *
101
+ * **Validates: Requirement 2.5**
102
+ */
103
+ async waitForStatus(intentId, targetStatus, options) {
104
+ const interval = options?.interval ?? 2000;
105
+ const timeout = options?.timeout ?? 60000;
106
+ const targetStatuses = Array.isArray(targetStatus) ? targetStatus : [targetStatus];
107
+ const startTime = Date.now();
108
+ while (true) {
109
+ // Check if timeout exceeded
110
+ const elapsed = Date.now() - startTime;
111
+ if (elapsed >= timeout) {
112
+ throw new TimeoutError(`Timeout waiting for intent ${intentId} to reach status ${targetStatuses.join(' or ')}`, timeout, { intentId, targetStatuses, elapsed });
113
+ }
114
+ // Get current status
115
+ const intent = await this.getStatus(intentId);
116
+ // Check if we've reached target status
117
+ if (targetStatuses.includes(intent.status)) {
118
+ return intent;
119
+ }
120
+ // Check if we should stop polling based on stopStatuses
121
+ if (options?.stopStatuses && options.stopStatuses.includes(intent.status)) {
122
+ return intent;
123
+ }
124
+ // Wait before next poll
125
+ await this.sleep(interval);
126
+ }
127
+ }
128
+ /**
129
+ * Create a watcher for continuous intent status updates
130
+ *
131
+ * Returns an ExecutionWatcher that polls the intent status at regular
132
+ * intervals and emits events when the status changes. This is useful for
133
+ * real-time monitoring of intent execution.
134
+ *
135
+ * The watcher will continue polling until:
136
+ * - stop() is called
137
+ * - A terminal status is reached (SETTLED, ABORTED, EXPIRED)
138
+ * - An error occurs (emitted via onError callback)
139
+ *
140
+ * @param intentId - The intent ID to watch
141
+ * @param options - Polling configuration (interval, timeout)
142
+ * @returns ExecutionWatcher instance with event callbacks
143
+ *
144
+ * @example
145
+ * ```typescript
146
+ * const watcher = tracker.watch('JK-ABC123456', { interval: 3000 });
147
+ *
148
+ * watcher.onUpdate((intent) => {
149
+ * console.log('Status updated:', intent.status);
150
+ * });
151
+ *
152
+ * watcher.onComplete((intent) => {
153
+ * console.log('Intent completed:', intent.settlementTx);
154
+ * watcher.stop();
155
+ * });
156
+ *
157
+ * watcher.onError((error) => {
158
+ * console.error('Polling error:', error);
159
+ * });
160
+ * ```
161
+ *
162
+ * **Validates: Requirements 2.2, 8.3**
163
+ */
164
+ watch(intentId, options) {
165
+ return new ExecutionWatcherImpl(this, intentId, options);
166
+ }
167
+ /**
168
+ * Sleep for specified milliseconds
169
+ *
170
+ * @param ms - Milliseconds to sleep
171
+ * @returns Promise that resolves after the specified delay
172
+ */
173
+ sleep(ms) {
174
+ return new Promise(resolve => setTimeout(resolve, ms));
175
+ }
176
+ }
177
+ /**
178
+ * Implementation of ExecutionWatcher for continuous intent monitoring
179
+ *
180
+ * This class implements the event emitter pattern for watching intent status
181
+ * changes. It polls the API at regular intervals and emits events when the
182
+ * status changes or when terminal states are reached.
183
+ *
184
+ * Requirements: 2.2, 8.3
185
+ */
186
+ class ExecutionWatcherImpl {
187
+ intentId;
188
+ tracker;
189
+ interval;
190
+ timeout;
191
+ startTime;
192
+ updateCallbacks = [];
193
+ errorCallbacks = [];
194
+ completeCallbacks = [];
195
+ isRunning = false;
196
+ isStopped = false;
197
+ timeoutHandle = null;
198
+ lastStatus = null;
199
+ /**
200
+ * Creates a new ExecutionWatcher
201
+ *
202
+ * @param tracker - The ExecutionTracker instance to use for polling
203
+ * @param intentId - The intent ID to watch
204
+ * @param options - Polling configuration
205
+ */
206
+ constructor(tracker, intentId, options) {
207
+ this.tracker = tracker;
208
+ this.intentId = intentId;
209
+ this.interval = options?.interval ?? 2000;
210
+ this.timeout = options?.timeout ?? 60000;
211
+ this.startTime = Date.now();
212
+ // Start polling immediately
213
+ this.startPolling();
214
+ }
215
+ /**
216
+ * Register callback for status updates
217
+ *
218
+ * The callback is invoked whenever the intent status changes. Multiple
219
+ * callbacks can be registered and will all be invoked in order.
220
+ *
221
+ * @param callback - Function to call with updated intent
222
+ */
223
+ onUpdate(callback) {
224
+ this.updateCallbacks.push(callback);
225
+ }
226
+ /**
227
+ * Register callback for errors
228
+ *
229
+ * The callback is invoked when an error occurs during polling (e.g.,
230
+ * network error, API error, timeout). Multiple callbacks can be registered.
231
+ *
232
+ * @param callback - Function to call with error
233
+ */
234
+ onError(callback) {
235
+ this.errorCallbacks.push(callback);
236
+ }
237
+ /**
238
+ * Register callback for completion
239
+ *
240
+ * The callback is invoked when the intent reaches a terminal status
241
+ * (SETTLED, ABORTED, or EXPIRED). Multiple callbacks can be registered.
242
+ * After completion, polling stops automatically.
243
+ *
244
+ * @param callback - Function to call with final intent state
245
+ */
246
+ onComplete(callback) {
247
+ this.completeCallbacks.push(callback);
248
+ }
249
+ /**
250
+ * Stop watching and clean up resources
251
+ *
252
+ * Stops the polling loop and clears all callbacks. This method is
253
+ * idempotent and can be called multiple times safely.
254
+ */
255
+ stop() {
256
+ this.isStopped = true;
257
+ this.isRunning = false;
258
+ if (this.timeoutHandle) {
259
+ clearTimeout(this.timeoutHandle);
260
+ this.timeoutHandle = null;
261
+ }
262
+ // Clear all callbacks to prevent memory leaks
263
+ this.updateCallbacks = [];
264
+ this.errorCallbacks = [];
265
+ this.completeCallbacks = [];
266
+ }
267
+ /**
268
+ * Alias for stop() to implement Subscription interface
269
+ */
270
+ unsubscribe() {
271
+ this.stop();
272
+ }
273
+ /**
274
+ * Start the polling loop
275
+ */
276
+ startPolling() {
277
+ if (this.isStopped || this.isRunning) {
278
+ return;
279
+ }
280
+ this.isRunning = true;
281
+ this.poll();
282
+ }
283
+ /**
284
+ * Execute a single poll iteration
285
+ */
286
+ async poll() {
287
+ if (this.isStopped || !this.isRunning) {
288
+ return;
289
+ }
290
+ try {
291
+ // Check if timeout exceeded
292
+ const elapsed = Date.now() - this.startTime;
293
+ if (elapsed >= this.timeout) {
294
+ const error = new TimeoutError(`Timeout watching intent ${this.intentId}`, this.timeout, { intentId: this.intentId, elapsed });
295
+ this.emitError(error);
296
+ this.stop();
297
+ return;
298
+ }
299
+ // Get current status
300
+ const intent = await this.tracker.getStatus(this.intentId);
301
+ // Check if status changed
302
+ const statusChanged = this.lastStatus !== null && this.lastStatus !== intent.status;
303
+ this.lastStatus = intent.status;
304
+ // Emit update if status changed
305
+ if (statusChanged) {
306
+ this.emitUpdate(intent);
307
+ }
308
+ // Check if we've reached a terminal status
309
+ const terminalStatuses = [
310
+ ExecutionStatus.SETTLED,
311
+ ExecutionStatus.ABORTED,
312
+ ExecutionStatus.EXPIRED
313
+ ];
314
+ if (terminalStatuses.includes(intent.status)) {
315
+ this.emitComplete(intent);
316
+ this.stop();
317
+ return;
318
+ }
319
+ // Schedule next poll
320
+ this.scheduleNextPoll();
321
+ }
322
+ catch (error) {
323
+ this.emitError(error instanceof Error ? error : new Error(String(error)));
324
+ this.stop();
325
+ }
326
+ }
327
+ /**
328
+ * Schedule the next poll iteration
329
+ */
330
+ scheduleNextPoll() {
331
+ if (this.isStopped || !this.isRunning) {
332
+ return;
333
+ }
334
+ this.timeoutHandle = setTimeout(() => {
335
+ this.poll();
336
+ }, this.interval);
337
+ }
338
+ /**
339
+ * Emit update event to all registered callbacks
340
+ */
341
+ emitUpdate(intent) {
342
+ for (const callback of this.updateCallbacks) {
343
+ try {
344
+ callback(intent);
345
+ }
346
+ catch (error) {
347
+ // Catch errors in callbacks to prevent them from breaking the polling loop
348
+ console.error('Error in onUpdate callback:', error);
349
+ }
350
+ }
351
+ }
352
+ /**
353
+ * Emit error event to all registered callbacks
354
+ */
355
+ emitError(error) {
356
+ for (const callback of this.errorCallbacks) {
357
+ try {
358
+ callback(error);
359
+ }
360
+ catch (err) {
361
+ // Catch errors in callbacks
362
+ console.error('Error in onError callback:', err);
363
+ }
364
+ }
365
+ }
366
+ /**
367
+ * Emit complete event to all registered callbacks
368
+ */
369
+ emitComplete(intent) {
370
+ for (const callback of this.completeCallbacks) {
371
+ try {
372
+ callback(intent);
373
+ }
374
+ catch (error) {
375
+ // Catch errors in callbacks
376
+ console.error('Error in onComplete callback:', error);
377
+ }
378
+ }
379
+ }
380
+ }
381
+ //# sourceMappingURL=execution.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"execution.js","sourceRoot":"","sources":["../../src/execution.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,eAAe,EAAwD,MAAM,YAAY,CAAC;AACnG,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAG3C;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,OAAO,gBAAgB;IACV,MAAM,CAAa;IAEpC;;;;OAIG;IACH,YAAY,MAAkB;QAC5B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED;;;;;;;;;;;;;;;;;;;OAmBG;IACH,KAAK,CAAC,SAAS,CAAC,QAAgB;QAC9B,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAS,gBAAgB,QAAQ,EAAE,CAAC,CAAC;IAC7D,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAqCG;IACH,KAAK,CAAC,aAAa,CACjB,QAAgB,EAChB,YAAiD,EACjD,OAAqB;QAErB,MAAM,QAAQ,GAAG,OAAO,EAAE,QAAQ,IAAI,IAAI,CAAC;QAC3C,MAAM,OAAO,GAAG,OAAO,EAAE,OAAO,IAAI,KAAK,CAAC;QAC1C,MAAM,cAAc,GAAG,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC;QAEnF,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAE7B,OAAO,IAAI,EAAE,CAAC;YACZ,4BAA4B;YAC5B,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS,CAAC;YACvC,IAAI,OAAO,IAAI,OAAO,EAAE,CAAC;gBACvB,MAAM,IAAI,YAAY,CACpB,8B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IACH,CAAC;IAED;;OAEG;IACK,SAAS,CAAC,KAAY;QAC5B,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;YAC3C,IAAI,CAAC;gBACH,QAAQ,CAAC,KAAK,CAAC,CAAC;YAClB,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,4BAA4B;gBAC5B,OAAO,CAAC,KAAK,CAAC,4BAA4B,EAAE,GAAG,CAAC,CAAC;YACnD,CAAC;QACH,CAAC;IACH,CAAC;IAED;;OAEG;IACK,YAAY,CAAC,MAAc;QACjC,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,iBAAiB,EAAE,CAAC;YAC9C,IAAI,CAAC;gBACH,QAAQ,CAAC,MAAM,CAAC,CAAC;YACnB,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,4BAA4B;gBAC5B,OAAO,CAAC,KAAK,CAAC,+BAA+B,EAAE,KAAK,CAAC,CAAC;YACxD,CAAC;QACH,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,236 @@
1
+ // Re-export enums
2
+ export { ExecutionStatus } from './types.js';
3
+ // Re-export all error classes
4
+ export { JackError, NetworkError, APIError, ValidationError, TimeoutError, RetryError } from './errors.js';
5
+ // Re-export serialization functions
6
+ export { getTypedData, serializeIntentParams, parseIntentParams } from './serialization.js';
7
+ // Re-export validation functions
8
+ export { validateIntentParams } from './validation.js';
9
+ // Re-export IntentManager
10
+ export { IntentManager } from './intents.js';
11
+ // Re-export ExecutionTracker
12
+ export { ExecutionTracker } from './execution.js';
13
+ // Re-export CostTracker
14
+ export { CostTracker } from './costs.js';
15
+ // Re-export AgentUtils
16
+ export { AgentUtils } from './agent.js';
17
+ // Re-export JackClient
18
+ export { JackClient } from './client.js';
19
+ // Import manager classes
20
+ import { JackClient } from './client.js';
21
+ import { IntentManager } from './intents.js';
22
+ import { ExecutionTracker } from './execution.js';
23
+ import { CostTracker } from './costs.js';
24
+ import { AgentUtils } from './agent.js';
25
+ // Import types and enums for use in this file
26
+ import { ExecutionStatus } from './types.js';
27
+ /**
28
+ * Main SDK class for JACK cross-chain execution kernel
29
+ *
30
+ * Provides a comprehensive, type-safe interface for interacting with the JACK system.
31
+ * Initializes all managers (intents, execution, costs, agent) and exposes them as
32
+ * public readonly properties. Also provides convenience methods for common operations.
33
+ *
34
+ * @example
35
+ * ```typescript
36
+ * // Initialize SDK
37
+ * const sdk = new JACK_SDK({ baseUrl: 'https://api.jack.example' });
38
+ *
39
+ * // Create and submit intent
40
+ * const typedData = sdk.intents.getTypedData(params);
41
+ * const signature = await wallet.signTypedData(typedData);
42
+ * const intentId = await sdk.submitIntent(params, signature);
43
+ *
44
+ * // Track execution
45
+ * const intent = await sdk.waitForSettlement(intentId);
46
+ * console.log('Settlement tx:', intent.settlementTx);
47
+ *
48
+ * // Access managers directly
49
+ * const costs = await sdk.costs.getCosts();
50
+ * const results = await sdk.agent.batchSubmit([...]);
51
+ * ```
52
+ *
53
+ * **Validates: Requirements 1.1, 1.2, 1.3, 1.4, 2.5**
54
+ */
55
+ export class JACK_SDK {
56
+ /**
57
+ * Intent management - create, submit, query intents
58
+ */
59
+ intents;
60
+ /**
61
+ * Execution tracking - poll status, wait for completion
62
+ */
63
+ execution;
64
+ /**
65
+ * Cost tracking - query costs and budgets
66
+ */
67
+ costs;
68
+ /**
69
+ * Agent utilities - batch operations, subscriptions
70
+ */
71
+ agent;
72
+ /**
73
+ * Internal HTTP client (exposed for advanced use cases)
74
+ */
75
+ client;
76
+ /**
77
+ * Creates a new JACK_SDK instance
78
+ *
79
+ * Initializes all managers with the provided configuration. The configuration
80
+ * includes the base URL for the API and optional settings for timeout, retries,
81
+ * caching, and custom headers.
82
+ *
83
+ * @param config - Client configuration (baseUrl required, other options optional)
84
+ * @throws ValidationError if configuration is invalid
85
+ *
86
+ * @example
87
+ * ```typescript
88
+ * // Basic initialization
89
+ * const sdk = new JACK_SDK({ baseUrl: 'https://api.jack.example' });
90
+ *
91
+ * // With custom configuration
92
+ * const sdk = new JACK_SDK({
93
+ * baseUrl: 'https://api.jack.example',
94
+ * timeout: 60000,
95
+ * maxRetries: 5,
96
+ * enableCache: true,
97
+ * cacheTTL: 120000,
98
+ * headers: { 'Authorization': 'Bearer token' }
99
+ * });
100
+ * ```
101
+ */
102
+ constructor(config) {
103
+ // Initialize core HTTP client
104
+ this.client = new JackClient(config);
105
+ // Initialize all managers
106
+ this.intents = new IntentManager(this.client);
107
+ this.execution = new ExecutionTracker(this.client);
108
+ this.costs = new CostTracker(this.client);
109
+ this.agent = new AgentUtils(this.client);
110
+ }
111
+ /**
112
+ * Convenience method: Submit a signed intent
113
+ *
114
+ * Delegates to IntentManager.submit(). This is a convenience method
115
+ * for the most common operation - submitting a signed intent.
116
+ *
117
+ * @param params - Intent parameters
118
+ * @param signature - EIP-712 signature from wallet
119
+ * @returns Promise resolving to the intent ID
120
+ * @throws ValidationError if parameters are invalid
121
+ * @throws APIError if the API returns an error
122
+ * @throws NetworkError if the network request fails
123
+ *
124
+ * @example
125
+ * ```typescript
126
+ * const intentId = await sdk.submitIntent(params, signature);
127
+ * console.log('Intent submitted:', intentId);
128
+ * ```
129
+ *
130
+ * **Validates: Requirement 1.2**
131
+ */
132
+ async submitIntent(params, signature) {
133
+ return this.intents.submit(params, signature);
134
+ }
135
+ /**
136
+ * Convenience method: Get a single intent by ID
137
+ *
138
+ * Delegates to IntentManager.get(). This is a convenience method
139
+ * for querying a single intent's current state.
140
+ *
141
+ * @param intentId - The intent ID to query
142
+ * @returns Promise resolving to the complete Intent object
143
+ * @throws APIError if the intent is not found or other API error
144
+ * @throws NetworkError if the network request fails
145
+ *
146
+ * @example
147
+ * ```typescript
148
+ * const intent = await sdk.getIntent('JK-ABC123456');
149
+ * console.log('Status:', intent.status);
150
+ * ```
151
+ *
152
+ * **Validates: Requirement 1.3**
153
+ */
154
+ async getIntent(intentId) {
155
+ return this.intents.get(intentId);
156
+ }
157
+ /**
158
+ * Convenience method: List all intents
159
+ *
160
+ * Delegates to IntentManager.list(). This is a convenience method
161
+ * for retrieving all intents.
162
+ *
163
+ * @returns Promise resolving to an array of Intent objects
164
+ * @throws APIError if the API returns an error
165
+ * @throws NetworkError if the network request fails
166
+ *
167
+ * @example
168
+ * ```typescript
169
+ * const intents = await sdk.listIntents();
170
+ * console.log(`Found ${intents.length} intents`);
171
+ * ```
172
+ *
173
+ * **Validates: Requirement 1.4**
174
+ */
175
+ async listIntents() {
176
+ return this.intents.list();
177
+ }
178
+ /**
179
+ * Convenience method: Wait for intent to settle
180
+ *
181
+ * Polls the intent status until it reaches SETTLED status or the timeout
182
+ * is exceeded. This is a convenience method that wraps ExecutionTracker.waitForStatus()
183
+ * with sensible defaults for waiting for settlement.
184
+ *
185
+ * @param intentId - The intent ID to wait for
186
+ * @param timeout - Maximum time to wait in milliseconds (default: 120000 = 2 minutes)
187
+ * @returns Promise resolving to the Intent when settled
188
+ * @throws TimeoutError if timeout is exceeded before settlement
189
+ * @throws APIError if the API returns an error
190
+ * @throws NetworkError if the network request fails
191
+ *
192
+ * @example
193
+ * ```typescript
194
+ * // Wait with default timeout (2 minutes)
195
+ * const intent = await sdk.waitForSettlement('JK-ABC123456');
196
+ * console.log('Settlement tx:', intent.settlementTx);
197
+ *
198
+ * // Wait with custom timeout (5 minutes)
199
+ * const intent = await sdk.waitForSettlement('JK-ABC123456', 300000);
200
+ * ```
201
+ *
202
+ * **Validates: Requirement 2.5**
203
+ */
204
+ async waitForSettlement(intentId, timeout = 120000) {
205
+ return this.execution.waitForStatus(intentId, ExecutionStatus.SETTLED, { timeout, interval: 2000 });
206
+ }
207
+ /**
208
+ * Legacy method: Get execution status
209
+ *
210
+ * @deprecated Use sdk.getIntent() or sdk.execution.getStatus() instead
211
+ *
212
+ * This method is kept for backward compatibility with existing dashboard code.
213
+ * It delegates to the execution tracker's getStatus method.
214
+ *
215
+ * @param intentId - The intent ID to query
216
+ * @returns Promise resolving to the Intent object
217
+ */
218
+ async getExecutionStatus(intentId) {
219
+ return this.execution.getStatus(intentId);
220
+ }
221
+ /**
222
+ * Legacy method: Get intent typed data
223
+ *
224
+ * @deprecated Use sdk.intents.getTypedData() instead
225
+ *
226
+ * This method is kept for backward compatibility with existing dashboard code.
227
+ * It delegates to the intent manager's getTypedData method.
228
+ *
229
+ * @param params - Intent parameters
230
+ * @returns EIP-712 TypedData object
231
+ */
232
+ getIntentTypedData(params) {
233
+ return this.intents.getTypedData(params);
234
+ }
235
+ }
236
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AA+BA,kBAAkB;AAClB,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAE7C,8BAA8B;AAC9B,OAAO,EACL,SAAS,EACT,YAAY,EACZ,QAAQ,EACR,eAAe,EACf,YAAY,EACZ,UAAU,EACX,MAAM,aAAa,CAAC;AAErB,oCAAoC;AACpC,OAAO,EACL,YAAY,EACZ,qBAAqB,EACrB,iBAAiB,EAClB,MAAM,oBAAoB,CAAC;AAE5B,iCAAiC;AACjC,OAAO,EACL,oBAAoB,EACrB,MAAM,iBAAiB,CAAC;AAEzB,0BAA0B;AAC1B,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE7C,6BAA6B;AAC7B,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAElD,wBAAwB;AACxB,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEzC,uBAAuB;AACvB,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAExC,uBAAuB;AACvB,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,yBAAyB;AACzB,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO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