@sardis/sdk 0.2.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.
- package/CHANGELOG.md +47 -0
- package/LICENSE +21 -0
- package/README.md +439 -0
- package/dist/browser/index.js +7049 -0
- package/dist/browser/index.js.map +1 -0
- package/dist/browser/sardis.umd.js +7071 -0
- package/dist/browser/sardis.umd.js.map +1 -0
- package/dist/cjs/client.js +644 -0
- package/dist/cjs/client.js.map +1 -0
- package/dist/cjs/demo.js +699 -0
- package/dist/cjs/demo.js.map +1 -0
- package/dist/cjs/errors.js +630 -0
- package/dist/cjs/errors.js.map +1 -0
- package/dist/cjs/index.js +131 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/integrations/index.js +21 -0
- package/dist/cjs/integrations/index.js.map +1 -0
- package/dist/cjs/integrations/langchain.js +339 -0
- package/dist/cjs/integrations/langchain.js.map +1 -0
- package/dist/cjs/integrations/openai.js +505 -0
- package/dist/cjs/integrations/openai.js.map +1 -0
- package/dist/cjs/integrations/vercel-ai.js +198 -0
- package/dist/cjs/integrations/vercel-ai.js.map +1 -0
- package/dist/cjs/resources/a2a.js +158 -0
- package/dist/cjs/resources/a2a.js.map +1 -0
- package/dist/cjs/resources/agents.js +142 -0
- package/dist/cjs/resources/agents.js.map +1 -0
- package/dist/cjs/resources/base.js +124 -0
- package/dist/cjs/resources/base.js.map +1 -0
- package/dist/cjs/resources/cards.js +43 -0
- package/dist/cjs/resources/cards.js.map +1 -0
- package/dist/cjs/resources/holds.js +64 -0
- package/dist/cjs/resources/holds.js.map +1 -0
- package/dist/cjs/resources/index.js +31 -0
- package/dist/cjs/resources/index.js.map +1 -0
- package/dist/cjs/resources/ledger.js +43 -0
- package/dist/cjs/resources/ledger.js.map +1 -0
- package/dist/cjs/resources/marketplace.js +88 -0
- package/dist/cjs/resources/marketplace.js.map +1 -0
- package/dist/cjs/resources/payments.js +33 -0
- package/dist/cjs/resources/payments.js.map +1 -0
- package/dist/cjs/resources/policies.js +31 -0
- package/dist/cjs/resources/policies.js.map +1 -0
- package/dist/cjs/resources/transactions.js +37 -0
- package/dist/cjs/resources/transactions.js.map +1 -0
- package/dist/cjs/resources/ucp.js +133 -0
- package/dist/cjs/resources/ucp.js.map +1 -0
- package/dist/cjs/resources/wallets.js +109 -0
- package/dist/cjs/resources/wallets.js.map +1 -0
- package/dist/cjs/resources/webhooks.js +81 -0
- package/dist/cjs/resources/webhooks.js.map +1 -0
- package/dist/cjs/types.js +11 -0
- package/dist/cjs/types.js.map +1 -0
- package/dist/client.d.ts +419 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +637 -0
- package/dist/client.js.map +1 -0
- package/dist/demo.d.ts +335 -0
- package/dist/demo.d.ts.map +1 -0
- package/dist/demo.js +694 -0
- package/dist/demo.js.map +1 -0
- package/dist/errors.d.ts +522 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +612 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +83 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +85 -0
- package/dist/index.js.map +1 -0
- package/dist/integrations/index.d.ts +4 -0
- package/dist/integrations/index.d.ts.map +1 -0
- package/dist/integrations/index.js +5 -0
- package/dist/integrations/index.js.map +1 -0
- package/dist/integrations/langchain.d.ts +68 -0
- package/dist/integrations/langchain.d.ts.map +1 -0
- package/dist/integrations/langchain.js +335 -0
- package/dist/integrations/langchain.js.map +1 -0
- package/dist/integrations/openai.d.ts +97 -0
- package/dist/integrations/openai.d.ts.map +1 -0
- package/dist/integrations/openai.js +467 -0
- package/dist/integrations/openai.js.map +1 -0
- package/dist/integrations/vercel-ai.d.ts +180 -0
- package/dist/integrations/vercel-ai.d.ts.map +1 -0
- package/dist/integrations/vercel-ai.js +194 -0
- package/dist/integrations/vercel-ai.js.map +1 -0
- package/dist/resources/a2a.d.ts +254 -0
- package/dist/resources/a2a.d.ts.map +1 -0
- package/dist/resources/a2a.js +154 -0
- package/dist/resources/a2a.js.map +1 -0
- package/dist/resources/agents.d.ts +111 -0
- package/dist/resources/agents.d.ts.map +1 -0
- package/dist/resources/agents.js +138 -0
- package/dist/resources/agents.js.map +1 -0
- package/dist/resources/base.d.ts +115 -0
- package/dist/resources/base.d.ts.map +1 -0
- package/dist/resources/base.js +120 -0
- package/dist/resources/base.js.map +1 -0
- package/dist/resources/cards.d.ts +19 -0
- package/dist/resources/cards.d.ts.map +1 -0
- package/dist/resources/cards.js +39 -0
- package/dist/resources/cards.js.map +1 -0
- package/dist/resources/holds.d.ts +44 -0
- package/dist/resources/holds.d.ts.map +1 -0
- package/dist/resources/holds.js +60 -0
- package/dist/resources/holds.js.map +1 -0
- package/dist/resources/index.d.ts +16 -0
- package/dist/resources/index.d.ts.map +1 -0
- package/dist/resources/index.js +16 -0
- package/dist/resources/index.js.map +1 -0
- package/dist/resources/ledger.d.ts +38 -0
- package/dist/resources/ledger.d.ts.map +1 -0
- package/dist/resources/ledger.js +39 -0
- package/dist/resources/ledger.js.map +1 -0
- package/dist/resources/marketplace.d.ts +60 -0
- package/dist/resources/marketplace.d.ts.map +1 -0
- package/dist/resources/marketplace.js +84 -0
- package/dist/resources/marketplace.js.map +1 -0
- package/dist/resources/payments.d.ts +24 -0
- package/dist/resources/payments.d.ts.map +1 -0
- package/dist/resources/payments.js +29 -0
- package/dist/resources/payments.js.map +1 -0
- package/dist/resources/policies.d.ts +23 -0
- package/dist/resources/policies.d.ts.map +1 -0
- package/dist/resources/policies.js +27 -0
- package/dist/resources/policies.js.map +1 -0
- package/dist/resources/transactions.d.ts +32 -0
- package/dist/resources/transactions.d.ts.map +1 -0
- package/dist/resources/transactions.js +33 -0
- package/dist/resources/transactions.js.map +1 -0
- package/dist/resources/ucp.d.ts +218 -0
- package/dist/resources/ucp.d.ts.map +1 -0
- package/dist/resources/ucp.js +129 -0
- package/dist/resources/ucp.js.map +1 -0
- package/dist/resources/wallets.d.ts +71 -0
- package/dist/resources/wallets.d.ts.map +1 -0
- package/dist/resources/wallets.js +105 -0
- package/dist/resources/wallets.js.map +1 -0
- package/dist/resources/webhooks.d.ts +57 -0
- package/dist/resources/webhooks.d.ts.map +1 -0
- package/dist/resources/webhooks.js +77 -0
- package/dist/resources/webhooks.js.map +1 -0
- package/dist/types.d.ts +1045 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +10 -0
- package/dist/types.js.map +1 -0
- package/package.json +114 -0
package/dist/client.js
ADDED
|
@@ -0,0 +1,637 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sardis TypeScript SDK Client
|
|
3
|
+
*
|
|
4
|
+
* Production-grade client for the Sardis stablecoin execution layer API.
|
|
5
|
+
* Features include:
|
|
6
|
+
* - Request cancellation via AbortController
|
|
7
|
+
* - Request/response interceptors
|
|
8
|
+
* - Automatic retry with exponential backoff
|
|
9
|
+
* - Automatic token refresh
|
|
10
|
+
* - Configurable timeouts
|
|
11
|
+
* - Comprehensive error handling
|
|
12
|
+
*
|
|
13
|
+
* @packageDocumentation
|
|
14
|
+
*/
|
|
15
|
+
import axios from 'axios';
|
|
16
|
+
import { APIError, AuthenticationError, RateLimitError, TimeoutError, AbortError, NetworkError, SardisErrorCode, } from './errors.js';
|
|
17
|
+
import { PaymentsResource } from './resources/payments.js';
|
|
18
|
+
import { HoldsResource } from './resources/holds.js';
|
|
19
|
+
import { WebhooksResource } from './resources/webhooks.js';
|
|
20
|
+
import { MarketplaceResource } from './resources/marketplace.js';
|
|
21
|
+
import { TransactionsResource } from './resources/transactions.js';
|
|
22
|
+
import { LedgerResource } from './resources/ledger.js';
|
|
23
|
+
import { WalletsResource } from './resources/wallets.js';
|
|
24
|
+
import { AgentsResource } from './resources/agents.js';
|
|
25
|
+
import { CardsResource } from './resources/cards.js';
|
|
26
|
+
import { PoliciesResource } from './resources/policies.js';
|
|
27
|
+
import { UCPResource } from './resources/ucp.js';
|
|
28
|
+
import { A2AResource } from './resources/a2a.js';
|
|
29
|
+
/** Default API base URL */
|
|
30
|
+
const DEFAULT_BASE_URL = 'https://api.sardis.network';
|
|
31
|
+
/** Default request timeout in milliseconds */
|
|
32
|
+
const DEFAULT_TIMEOUT = 30000;
|
|
33
|
+
/** Default connection timeout in milliseconds */
|
|
34
|
+
const DEFAULT_CONNECT_TIMEOUT = 10000;
|
|
35
|
+
/** Default maximum retry attempts */
|
|
36
|
+
const DEFAULT_MAX_RETRIES = 3;
|
|
37
|
+
/** Default retry delay in milliseconds */
|
|
38
|
+
const DEFAULT_RETRY_DELAY = 1000;
|
|
39
|
+
/** SDK version for User-Agent header */
|
|
40
|
+
const SDK_VERSION = '0.2.0';
|
|
41
|
+
/**
|
|
42
|
+
* Sardis API Client
|
|
43
|
+
*
|
|
44
|
+
* The main entry point for interacting with the Sardis API. Provides access
|
|
45
|
+
* to all API resources through typed methods and handles authentication,
|
|
46
|
+
* retries, and error handling.
|
|
47
|
+
*
|
|
48
|
+
* @example Basic usage
|
|
49
|
+
* ```typescript
|
|
50
|
+
* import { SardisClient } from '@sardis/sdk';
|
|
51
|
+
*
|
|
52
|
+
* const client = new SardisClient({
|
|
53
|
+
* apiKey: 'your-api-key',
|
|
54
|
+
* });
|
|
55
|
+
*
|
|
56
|
+
* // Execute a payment
|
|
57
|
+
* const result = await client.payments.executeMandate(mandate);
|
|
58
|
+
*
|
|
59
|
+
* // Create a hold
|
|
60
|
+
* const hold = await client.holds.create({
|
|
61
|
+
* wallet_id: 'wallet_123',
|
|
62
|
+
* amount: '100.00',
|
|
63
|
+
* });
|
|
64
|
+
* ```
|
|
65
|
+
*
|
|
66
|
+
* @example With request cancellation
|
|
67
|
+
* ```typescript
|
|
68
|
+
* const controller = new AbortController();
|
|
69
|
+
*
|
|
70
|
+
* // Cancel after 5 seconds
|
|
71
|
+
* setTimeout(() => controller.abort(), 5000);
|
|
72
|
+
*
|
|
73
|
+
* try {
|
|
74
|
+
* const result = await client.payments.executeMandate(mandate, {
|
|
75
|
+
* signal: controller.signal,
|
|
76
|
+
* });
|
|
77
|
+
* } catch (error) {
|
|
78
|
+
* if (error instanceof AbortError) {
|
|
79
|
+
* console.log('Request was cancelled');
|
|
80
|
+
* }
|
|
81
|
+
* }
|
|
82
|
+
* ```
|
|
83
|
+
*
|
|
84
|
+
* @example With interceptors
|
|
85
|
+
* ```typescript
|
|
86
|
+
* const client = new SardisClient({ apiKey: 'your-api-key' });
|
|
87
|
+
*
|
|
88
|
+
* // Add request logging
|
|
89
|
+
* client.addRequestInterceptor({
|
|
90
|
+
* onRequest: (config) => {
|
|
91
|
+
* console.log(`Requesting ${config.method} ${config.url}`);
|
|
92
|
+
* return config;
|
|
93
|
+
* },
|
|
94
|
+
* });
|
|
95
|
+
*
|
|
96
|
+
* // Add response logging
|
|
97
|
+
* client.addResponseInterceptor({
|
|
98
|
+
* onResponse: (response) => {
|
|
99
|
+
* console.log(`Response: ${response.status}`);
|
|
100
|
+
* return response;
|
|
101
|
+
* },
|
|
102
|
+
* });
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
export class SardisClient {
|
|
106
|
+
/**
|
|
107
|
+
* Creates a new SardisClient instance.
|
|
108
|
+
*
|
|
109
|
+
* @param options - Client configuration options
|
|
110
|
+
* @throws {Error} If API key is not provided
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* ```typescript
|
|
114
|
+
* const client = new SardisClient({
|
|
115
|
+
* apiKey: process.env.SARDIS_API_KEY,
|
|
116
|
+
* timeout: 60000, // 60 second timeout
|
|
117
|
+
* maxRetries: 5,
|
|
118
|
+
* retryDelay: 2000,
|
|
119
|
+
* });
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
122
|
+
constructor(options) {
|
|
123
|
+
/** @internal Request interceptors */
|
|
124
|
+
this.requestInterceptors = [];
|
|
125
|
+
/** @internal Response interceptors */
|
|
126
|
+
this.responseInterceptors = [];
|
|
127
|
+
if (!options.apiKey) {
|
|
128
|
+
throw new Error('API key is required');
|
|
129
|
+
}
|
|
130
|
+
this.apiKey = options.apiKey;
|
|
131
|
+
this.baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\/$/, '');
|
|
132
|
+
this.timeout = options.timeout ?? DEFAULT_TIMEOUT;
|
|
133
|
+
this.connectTimeout = options.connectTimeout ?? DEFAULT_CONNECT_TIMEOUT;
|
|
134
|
+
// Configure retry settings
|
|
135
|
+
this.retryConfig = {
|
|
136
|
+
maxRetries: options.maxRetries ?? DEFAULT_MAX_RETRIES,
|
|
137
|
+
retryDelay: options.retryDelay ?? DEFAULT_RETRY_DELAY,
|
|
138
|
+
maxRetryDelay: options.maxRetryDelay ?? 30000,
|
|
139
|
+
retryOn: options.retryOn ?? [408, 429, 500, 502, 503, 504],
|
|
140
|
+
retryOnNetworkError: options.retryOnNetworkError ?? true,
|
|
141
|
+
};
|
|
142
|
+
// Configure token refresh
|
|
143
|
+
this.tokenRefreshConfig = options.tokenRefresh;
|
|
144
|
+
// Create axios instance
|
|
145
|
+
this.http = axios.create({
|
|
146
|
+
baseURL: this.baseUrl,
|
|
147
|
+
timeout: this.timeout,
|
|
148
|
+
headers: {
|
|
149
|
+
'X-API-Key': this.apiKey,
|
|
150
|
+
'Content-Type': 'application/json',
|
|
151
|
+
'User-Agent': `@sardis/sdk/${SDK_VERSION}`,
|
|
152
|
+
},
|
|
153
|
+
});
|
|
154
|
+
// Initialize resources
|
|
155
|
+
this.payments = new PaymentsResource(this);
|
|
156
|
+
this.holds = new HoldsResource(this);
|
|
157
|
+
this.cards = new CardsResource(this);
|
|
158
|
+
this.policies = new PoliciesResource(this);
|
|
159
|
+
this.webhooks = new WebhooksResource(this);
|
|
160
|
+
this.marketplace = new MarketplaceResource(this);
|
|
161
|
+
this.transactions = new TransactionsResource(this);
|
|
162
|
+
this.ledger = new LedgerResource(this);
|
|
163
|
+
this.wallets = new WalletsResource(this);
|
|
164
|
+
this.agents = new AgentsResource(this);
|
|
165
|
+
this.ucp = new UCPResource(this);
|
|
166
|
+
this.a2a = new A2AResource(this);
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Adds a request interceptor.
|
|
170
|
+
*
|
|
171
|
+
* Request interceptors are called before each request is sent and can
|
|
172
|
+
* modify the request configuration or throw an error to cancel the request.
|
|
173
|
+
*
|
|
174
|
+
* @param interceptor - The interceptor to add
|
|
175
|
+
* @returns A function to remove the interceptor
|
|
176
|
+
*
|
|
177
|
+
* @example
|
|
178
|
+
* ```typescript
|
|
179
|
+
* const removeInterceptor = client.addRequestInterceptor({
|
|
180
|
+
* onRequest: (config) => {
|
|
181
|
+
* config.headers['X-Custom-Header'] = 'value';
|
|
182
|
+
* return config;
|
|
183
|
+
* },
|
|
184
|
+
* onError: (error) => {
|
|
185
|
+
* console.error('Request interceptor error:', error);
|
|
186
|
+
* throw error;
|
|
187
|
+
* },
|
|
188
|
+
* });
|
|
189
|
+
*
|
|
190
|
+
* // Later, remove the interceptor
|
|
191
|
+
* removeInterceptor();
|
|
192
|
+
* ```
|
|
193
|
+
*/
|
|
194
|
+
addRequestInterceptor(interceptor) {
|
|
195
|
+
this.requestInterceptors.push(interceptor);
|
|
196
|
+
return () => {
|
|
197
|
+
const index = this.requestInterceptors.indexOf(interceptor);
|
|
198
|
+
if (index !== -1) {
|
|
199
|
+
this.requestInterceptors.splice(index, 1);
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Adds a response interceptor.
|
|
205
|
+
*
|
|
206
|
+
* Response interceptors are called after each response is received and can
|
|
207
|
+
* modify the response or throw an error.
|
|
208
|
+
*
|
|
209
|
+
* @param interceptor - The interceptor to add
|
|
210
|
+
* @returns A function to remove the interceptor
|
|
211
|
+
*
|
|
212
|
+
* @example
|
|
213
|
+
* ```typescript
|
|
214
|
+
* const removeInterceptor = client.addResponseInterceptor({
|
|
215
|
+
* onResponse: (response) => {
|
|
216
|
+
* // Log all responses
|
|
217
|
+
* console.log(`${response.config.method} ${response.config.url}: ${response.status}`);
|
|
218
|
+
* return response;
|
|
219
|
+
* },
|
|
220
|
+
* onError: (error) => {
|
|
221
|
+
* // Transform errors
|
|
222
|
+
* if (error.response?.status === 404) {
|
|
223
|
+
* throw new NotFoundError('Resource', 'unknown');
|
|
224
|
+
* }
|
|
225
|
+
* throw error;
|
|
226
|
+
* },
|
|
227
|
+
* });
|
|
228
|
+
* ```
|
|
229
|
+
*/
|
|
230
|
+
addResponseInterceptor(interceptor) {
|
|
231
|
+
this.responseInterceptors.push(interceptor);
|
|
232
|
+
return () => {
|
|
233
|
+
const index = this.responseInterceptors.indexOf(interceptor);
|
|
234
|
+
if (index !== -1) {
|
|
235
|
+
this.responseInterceptors.splice(index, 1);
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Updates the API key used for authentication.
|
|
241
|
+
*
|
|
242
|
+
* @param apiKey - The new API key
|
|
243
|
+
*
|
|
244
|
+
* @example
|
|
245
|
+
* ```typescript
|
|
246
|
+
* // Update API key after token refresh
|
|
247
|
+
* client.setApiKey(newApiKey);
|
|
248
|
+
* ```
|
|
249
|
+
*/
|
|
250
|
+
setApiKey(apiKey) {
|
|
251
|
+
this.apiKey = apiKey;
|
|
252
|
+
// Update the default headers on the axios instance
|
|
253
|
+
this.http.defaults.headers['X-API-Key'] = apiKey;
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Gets the current API key.
|
|
257
|
+
*
|
|
258
|
+
* @returns The current API key
|
|
259
|
+
*/
|
|
260
|
+
getApiKey() {
|
|
261
|
+
return this.apiKey;
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Makes an HTTP request with retry logic, interceptors, and cancellation support.
|
|
265
|
+
*
|
|
266
|
+
* @typeParam T - The expected response type
|
|
267
|
+
* @param method - HTTP method
|
|
268
|
+
* @param path - API path
|
|
269
|
+
* @param options - Request options including params, data, and signal
|
|
270
|
+
* @returns The response data
|
|
271
|
+
*
|
|
272
|
+
* @throws {AuthenticationError} If authentication fails
|
|
273
|
+
* @throws {RateLimitError} If rate limit is exceeded
|
|
274
|
+
* @throws {TimeoutError} If request times out
|
|
275
|
+
* @throws {AbortError} If request is cancelled
|
|
276
|
+
* @throws {NetworkError} If network error occurs
|
|
277
|
+
* @throws {APIError} If API returns an error response
|
|
278
|
+
*
|
|
279
|
+
* @example
|
|
280
|
+
* ```typescript
|
|
281
|
+
* const result = await client.request<PaymentResponse>('POST', '/payments', {
|
|
282
|
+
* data: paymentData,
|
|
283
|
+
* signal: abortController.signal,
|
|
284
|
+
* });
|
|
285
|
+
* ```
|
|
286
|
+
*/
|
|
287
|
+
async request(method, path, options) {
|
|
288
|
+
const config = {
|
|
289
|
+
method,
|
|
290
|
+
url: path,
|
|
291
|
+
params: options?.params,
|
|
292
|
+
data: options?.data,
|
|
293
|
+
signal: options?.signal,
|
|
294
|
+
timeout: options?.timeout ?? this.timeout,
|
|
295
|
+
headers: {
|
|
296
|
+
'X-API-Key': this.apiKey,
|
|
297
|
+
},
|
|
298
|
+
_retryCount: 0,
|
|
299
|
+
_startTime: Date.now(),
|
|
300
|
+
};
|
|
301
|
+
// Apply request interceptors
|
|
302
|
+
let processedConfig = config;
|
|
303
|
+
for (const interceptor of this.requestInterceptors) {
|
|
304
|
+
try {
|
|
305
|
+
if (interceptor.onRequest) {
|
|
306
|
+
processedConfig = await interceptor.onRequest(processedConfig);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
catch (error) {
|
|
310
|
+
if (interceptor.onError) {
|
|
311
|
+
await interceptor.onError(error);
|
|
312
|
+
}
|
|
313
|
+
throw error;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
return this.executeWithRetry(processedConfig);
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Executes a request with retry logic.
|
|
320
|
+
* @internal
|
|
321
|
+
*/
|
|
322
|
+
async executeWithRetry(config) {
|
|
323
|
+
const retryCount = config._retryCount ?? 0;
|
|
324
|
+
try {
|
|
325
|
+
// Check for abort signal
|
|
326
|
+
if (config.signal?.aborted) {
|
|
327
|
+
throw new AbortError();
|
|
328
|
+
}
|
|
329
|
+
const response = await this.http.request(config);
|
|
330
|
+
// Apply response interceptors
|
|
331
|
+
let processedResponse = response;
|
|
332
|
+
for (const interceptor of this.responseInterceptors) {
|
|
333
|
+
try {
|
|
334
|
+
if (interceptor.onResponse) {
|
|
335
|
+
processedResponse = await interceptor.onResponse(processedResponse);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
catch (error) {
|
|
339
|
+
if (interceptor.onError) {
|
|
340
|
+
await interceptor.onError(error);
|
|
341
|
+
}
|
|
342
|
+
throw error;
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
return processedResponse.data;
|
|
346
|
+
}
|
|
347
|
+
catch (error) {
|
|
348
|
+
// Handle abort
|
|
349
|
+
if (axios.isCancel(error) || error.name === 'AbortError') {
|
|
350
|
+
throw new AbortError();
|
|
351
|
+
}
|
|
352
|
+
// Check if signal was aborted during request
|
|
353
|
+
if (config.signal?.aborted) {
|
|
354
|
+
throw new AbortError();
|
|
355
|
+
}
|
|
356
|
+
if (axios.isAxiosError(error)) {
|
|
357
|
+
const axiosError = error;
|
|
358
|
+
// Handle rate limiting
|
|
359
|
+
if (axiosError.response?.status === 429) {
|
|
360
|
+
const retryAfter = this.parseRetryAfter(axiosError.response.headers);
|
|
361
|
+
const resetAt = axiosError.response.headers['x-ratelimit-reset']
|
|
362
|
+
? new Date(parseInt(axiosError.response.headers['x-ratelimit-reset']) * 1000)
|
|
363
|
+
: undefined;
|
|
364
|
+
if (retryCount < this.retryConfig.maxRetries) {
|
|
365
|
+
const delay = retryAfter ? retryAfter * 1000 : this.calculateRetryDelay(retryCount);
|
|
366
|
+
await this.sleep(delay);
|
|
367
|
+
return this.executeWithRetry({
|
|
368
|
+
...config,
|
|
369
|
+
_retryCount: retryCount + 1,
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
throw new RateLimitError('Rate limit exceeded', retryAfter, parseInt(axiosError.response.headers['x-ratelimit-limit']), parseInt(axiosError.response.headers['x-ratelimit-remaining']), resetAt);
|
|
373
|
+
}
|
|
374
|
+
// Handle authentication errors
|
|
375
|
+
if (axiosError.response?.status === 401) {
|
|
376
|
+
// Try token refresh if configured
|
|
377
|
+
if (this.tokenRefreshConfig && retryCount === 0) {
|
|
378
|
+
try {
|
|
379
|
+
const newToken = await this.tokenRefreshConfig.refreshToken();
|
|
380
|
+
this.setApiKey(newToken);
|
|
381
|
+
// Update the request config headers with the new token
|
|
382
|
+
const updatedConfig = {
|
|
383
|
+
...config,
|
|
384
|
+
headers: {
|
|
385
|
+
...config.headers,
|
|
386
|
+
'X-API-Key': newToken,
|
|
387
|
+
},
|
|
388
|
+
_retryCount: retryCount + 1,
|
|
389
|
+
};
|
|
390
|
+
return this.executeWithRetry(updatedConfig);
|
|
391
|
+
}
|
|
392
|
+
catch {
|
|
393
|
+
throw new AuthenticationError('Token refresh failed', SardisErrorCode.TOKEN_REFRESH_FAILED);
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
throw new AuthenticationError();
|
|
397
|
+
}
|
|
398
|
+
// Handle timeout
|
|
399
|
+
if (axiosError.code === 'ECONNABORTED' || axiosError.code === 'ETIMEDOUT') {
|
|
400
|
+
if (retryCount < this.retryConfig.maxRetries) {
|
|
401
|
+
const delay = this.calculateRetryDelay(retryCount);
|
|
402
|
+
await this.sleep(delay);
|
|
403
|
+
return this.executeWithRetry({
|
|
404
|
+
...config,
|
|
405
|
+
_retryCount: retryCount + 1,
|
|
406
|
+
});
|
|
407
|
+
}
|
|
408
|
+
throw new TimeoutError('Request timed out', config.timeout);
|
|
409
|
+
}
|
|
410
|
+
// Handle other API errors
|
|
411
|
+
if (axiosError.response?.status && axiosError.response.status >= 400) {
|
|
412
|
+
// Check if should retry
|
|
413
|
+
if (this.retryConfig.retryOn.includes(axiosError.response.status) &&
|
|
414
|
+
retryCount < this.retryConfig.maxRetries) {
|
|
415
|
+
const delay = this.calculateRetryDelay(retryCount);
|
|
416
|
+
await this.sleep(delay);
|
|
417
|
+
return this.executeWithRetry({
|
|
418
|
+
...config,
|
|
419
|
+
_retryCount: retryCount + 1,
|
|
420
|
+
});
|
|
421
|
+
}
|
|
422
|
+
const headers = {};
|
|
423
|
+
Object.entries(axiosError.response.headers).forEach(([key, value]) => {
|
|
424
|
+
if (typeof value === 'string') {
|
|
425
|
+
headers[key] = value;
|
|
426
|
+
}
|
|
427
|
+
});
|
|
428
|
+
throw APIError.fromResponse(axiosError.response.status, axiosError.response.data || {}, headers);
|
|
429
|
+
}
|
|
430
|
+
// Handle network errors
|
|
431
|
+
if (!axiosError.response) {
|
|
432
|
+
if (this.retryConfig.retryOnNetworkError && retryCount < this.retryConfig.maxRetries) {
|
|
433
|
+
const delay = this.calculateRetryDelay(retryCount);
|
|
434
|
+
await this.sleep(delay);
|
|
435
|
+
return this.executeWithRetry({
|
|
436
|
+
...config,
|
|
437
|
+
_retryCount: retryCount + 1,
|
|
438
|
+
});
|
|
439
|
+
}
|
|
440
|
+
throw new NetworkError(axiosError.message || 'Network error occurred', axiosError, SardisErrorCode.NETWORK_ERROR);
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
throw error;
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
/**
|
|
447
|
+
* Parses the Retry-After header value.
|
|
448
|
+
* @internal
|
|
449
|
+
*/
|
|
450
|
+
parseRetryAfter(headers) {
|
|
451
|
+
const retryAfter = headers['retry-after'];
|
|
452
|
+
if (!retryAfter)
|
|
453
|
+
return undefined;
|
|
454
|
+
// Check if it's a number (seconds)
|
|
455
|
+
const seconds = parseInt(retryAfter, 10);
|
|
456
|
+
if (!isNaN(seconds)) {
|
|
457
|
+
return seconds;
|
|
458
|
+
}
|
|
459
|
+
// Check if it's an HTTP date
|
|
460
|
+
const date = Date.parse(retryAfter);
|
|
461
|
+
if (!isNaN(date)) {
|
|
462
|
+
return Math.max(0, Math.ceil((date - Date.now()) / 1000));
|
|
463
|
+
}
|
|
464
|
+
return undefined;
|
|
465
|
+
}
|
|
466
|
+
/**
|
|
467
|
+
* Calculates retry delay with exponential backoff and jitter.
|
|
468
|
+
* @internal
|
|
469
|
+
*/
|
|
470
|
+
calculateRetryDelay(retryCount) {
|
|
471
|
+
// Exponential backoff with jitter
|
|
472
|
+
const exponentialDelay = this.retryConfig.retryDelay * Math.pow(2, retryCount);
|
|
473
|
+
const jitter = Math.random() * 0.3 * exponentialDelay;
|
|
474
|
+
const delay = exponentialDelay + jitter;
|
|
475
|
+
return Math.min(delay, this.retryConfig.maxRetryDelay);
|
|
476
|
+
}
|
|
477
|
+
/**
|
|
478
|
+
* Creates an async iterator for paginated responses.
|
|
479
|
+
*
|
|
480
|
+
* @typeParam T - The item type in the paginated response
|
|
481
|
+
* @param fetchPage - Function to fetch a page of results
|
|
482
|
+
* @param options - Pagination options
|
|
483
|
+
* @returns An async iterator that yields items from all pages
|
|
484
|
+
*
|
|
485
|
+
* @example
|
|
486
|
+
* ```typescript
|
|
487
|
+
* const iterator = client.paginate<Agent>(
|
|
488
|
+
* async (params) => {
|
|
489
|
+
* const response = await client.agents.list(params);
|
|
490
|
+
* return {
|
|
491
|
+
* data: response,
|
|
492
|
+
* hasMore: response.length === params.limit,
|
|
493
|
+
* nextCursor: response[response.length - 1]?.id,
|
|
494
|
+
* };
|
|
495
|
+
* },
|
|
496
|
+
* { limit: 100 }
|
|
497
|
+
* );
|
|
498
|
+
*
|
|
499
|
+
* for await (const agent of iterator) {
|
|
500
|
+
* console.log(agent.name);
|
|
501
|
+
* }
|
|
502
|
+
* ```
|
|
503
|
+
*/
|
|
504
|
+
async *paginate(fetchPage, options = {}) {
|
|
505
|
+
let cursor = options.cursor;
|
|
506
|
+
let hasMore = true;
|
|
507
|
+
const limit = options.limit ?? 100;
|
|
508
|
+
while (hasMore) {
|
|
509
|
+
const response = await fetchPage({ ...options, limit, cursor });
|
|
510
|
+
for (const item of response.data) {
|
|
511
|
+
yield item;
|
|
512
|
+
}
|
|
513
|
+
hasMore = response.hasMore;
|
|
514
|
+
cursor = response.nextCursor;
|
|
515
|
+
if (!cursor) {
|
|
516
|
+
hasMore = false;
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
/**
|
|
521
|
+
* Creates an async iterator that collects all paginated results into an array.
|
|
522
|
+
*
|
|
523
|
+
* @typeParam T - The item type in the paginated response
|
|
524
|
+
* @param fetchPage - Function to fetch a page of results
|
|
525
|
+
* @param options - Pagination options
|
|
526
|
+
* @returns Promise that resolves to an array of all items
|
|
527
|
+
*
|
|
528
|
+
* @example
|
|
529
|
+
* ```typescript
|
|
530
|
+
* const allAgents = await client.paginateAll<Agent>(
|
|
531
|
+
* async (params) => {
|
|
532
|
+
* const response = await client.agents.list(params);
|
|
533
|
+
* return {
|
|
534
|
+
* data: response,
|
|
535
|
+
* hasMore: response.length === params.limit,
|
|
536
|
+
* nextCursor: response[response.length - 1]?.id,
|
|
537
|
+
* };
|
|
538
|
+
* }
|
|
539
|
+
* );
|
|
540
|
+
* console.log(`Found ${allAgents.length} agents`);
|
|
541
|
+
* ```
|
|
542
|
+
*/
|
|
543
|
+
async paginateAll(fetchPage, options = {}) {
|
|
544
|
+
const results = [];
|
|
545
|
+
for await (const item of this.paginate(fetchPage, options)) {
|
|
546
|
+
results.push(item);
|
|
547
|
+
}
|
|
548
|
+
return results;
|
|
549
|
+
}
|
|
550
|
+
/**
|
|
551
|
+
* Checks API health status.
|
|
552
|
+
*
|
|
553
|
+
* @param options - Request options
|
|
554
|
+
* @returns Health status response
|
|
555
|
+
*
|
|
556
|
+
* @example
|
|
557
|
+
* ```typescript
|
|
558
|
+
* const health = await client.health();
|
|
559
|
+
* console.log(`API status: ${health.status}, version: ${health.version}`);
|
|
560
|
+
* ```
|
|
561
|
+
*/
|
|
562
|
+
async health(options) {
|
|
563
|
+
return this.request('GET', '/health', options);
|
|
564
|
+
}
|
|
565
|
+
/**
|
|
566
|
+
* Executes multiple operations in a batch.
|
|
567
|
+
*
|
|
568
|
+
* @typeParam T - The response type for each operation
|
|
569
|
+
* @param operations - Array of operations to execute
|
|
570
|
+
* @param options - Batch options
|
|
571
|
+
* @returns Array of results (either success or error for each operation)
|
|
572
|
+
*
|
|
573
|
+
* @example
|
|
574
|
+
* ```typescript
|
|
575
|
+
* const results = await client.batch([
|
|
576
|
+
* { method: 'GET', path: '/api/v2/wallets/wallet_1' },
|
|
577
|
+
* { method: 'GET', path: '/api/v2/wallets/wallet_2' },
|
|
578
|
+
* { method: 'GET', path: '/api/v2/wallets/wallet_3' },
|
|
579
|
+
* ], { concurrency: 3 });
|
|
580
|
+
*
|
|
581
|
+
* results.forEach((result, i) => {
|
|
582
|
+
* if (result.success) {
|
|
583
|
+
* console.log(`Operation ${i}: ${result.data}`);
|
|
584
|
+
* } else {
|
|
585
|
+
* console.error(`Operation ${i} failed: ${result.error}`);
|
|
586
|
+
* }
|
|
587
|
+
* });
|
|
588
|
+
* ```
|
|
589
|
+
*/
|
|
590
|
+
async batch(operations, options) {
|
|
591
|
+
const concurrency = options?.concurrency ?? 5;
|
|
592
|
+
const stopOnError = options?.stopOnError ?? false;
|
|
593
|
+
const signal = options?.signal;
|
|
594
|
+
const results = [];
|
|
595
|
+
let stopped = false;
|
|
596
|
+
// Process in chunks
|
|
597
|
+
for (let i = 0; i < operations.length && !stopped; i += concurrency) {
|
|
598
|
+
if (signal?.aborted) {
|
|
599
|
+
throw new AbortError();
|
|
600
|
+
}
|
|
601
|
+
const chunk = operations.slice(i, i + concurrency);
|
|
602
|
+
const chunkResults = await Promise.all(chunk.map(async (op) => {
|
|
603
|
+
if (stopped) {
|
|
604
|
+
return { success: false, error: new AbortError('Batch stopped') };
|
|
605
|
+
}
|
|
606
|
+
try {
|
|
607
|
+
const data = await this.request(op.method, op.path, {
|
|
608
|
+
params: op.params,
|
|
609
|
+
data: op.data,
|
|
610
|
+
signal,
|
|
611
|
+
});
|
|
612
|
+
return { success: true, data };
|
|
613
|
+
}
|
|
614
|
+
catch (error) {
|
|
615
|
+
// If any request was aborted due to signal, throw immediately
|
|
616
|
+
if (error instanceof AbortError && signal?.aborted) {
|
|
617
|
+
throw error;
|
|
618
|
+
}
|
|
619
|
+
if (stopOnError) {
|
|
620
|
+
stopped = true;
|
|
621
|
+
}
|
|
622
|
+
return { success: false, error: error };
|
|
623
|
+
}
|
|
624
|
+
}));
|
|
625
|
+
results.push(...chunkResults);
|
|
626
|
+
}
|
|
627
|
+
return results;
|
|
628
|
+
}
|
|
629
|
+
/**
|
|
630
|
+
* Sleep utility for retry delays.
|
|
631
|
+
* @internal
|
|
632
|
+
*/
|
|
633
|
+
sleep(ms) {
|
|
634
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAuE,MAAM,OAAO,CAAC;AAC5F,OAAO,EACL,QAAQ,EACR,mBAAmB,EACnB,cAAc,EACd,YAAY,EACZ,UAAU,EACV,YAAY,EACZ,eAAe,GAChB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EA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