stableflow-ai-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.
- package/LICENSE +22 -0
- package/README.md +228 -0
- package/dist/index.d.mts +549 -0
- package/dist/index.d.ts +549 -0
- package/dist/index.js +626 -0
- package/dist/index.mjs +582 -0
- package/package.json +64 -0
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,582 @@
|
|
|
1
|
+
var __typeError = (msg) => {
|
|
2
|
+
throw TypeError(msg);
|
|
3
|
+
};
|
|
4
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
5
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
6
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
7
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
8
|
+
|
|
9
|
+
// src/core/ApiError.ts
|
|
10
|
+
var ApiError = class extends Error {
|
|
11
|
+
constructor(request2, response, message) {
|
|
12
|
+
super(message);
|
|
13
|
+
this.name = "ApiError";
|
|
14
|
+
this.url = response.url;
|
|
15
|
+
this.status = response.status;
|
|
16
|
+
this.statusText = response.statusText;
|
|
17
|
+
this.body = response.body;
|
|
18
|
+
this.request = request2;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// src/core/CancelablePromise.ts
|
|
23
|
+
var CancelError = class extends Error {
|
|
24
|
+
constructor(message) {
|
|
25
|
+
super(message);
|
|
26
|
+
this.name = "CancelError";
|
|
27
|
+
}
|
|
28
|
+
get isCancelled() {
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
var _isResolved, _isRejected, _isCancelled, _cancelHandlers, _promise, _resolve, _reject;
|
|
33
|
+
var CancelablePromise = class {
|
|
34
|
+
constructor(executor) {
|
|
35
|
+
__privateAdd(this, _isResolved);
|
|
36
|
+
__privateAdd(this, _isRejected);
|
|
37
|
+
__privateAdd(this, _isCancelled);
|
|
38
|
+
__privateAdd(this, _cancelHandlers);
|
|
39
|
+
__privateAdd(this, _promise);
|
|
40
|
+
__privateAdd(this, _resolve);
|
|
41
|
+
__privateAdd(this, _reject);
|
|
42
|
+
__privateSet(this, _isResolved, false);
|
|
43
|
+
__privateSet(this, _isRejected, false);
|
|
44
|
+
__privateSet(this, _isCancelled, false);
|
|
45
|
+
__privateSet(this, _cancelHandlers, []);
|
|
46
|
+
__privateSet(this, _promise, new Promise((resolve2, reject) => {
|
|
47
|
+
__privateSet(this, _resolve, resolve2);
|
|
48
|
+
__privateSet(this, _reject, reject);
|
|
49
|
+
const onResolve = (value) => {
|
|
50
|
+
if (__privateGet(this, _isResolved) || __privateGet(this, _isRejected) || __privateGet(this, _isCancelled)) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
__privateSet(this, _isResolved, true);
|
|
54
|
+
if (__privateGet(this, _resolve)) __privateGet(this, _resolve).call(this, value);
|
|
55
|
+
};
|
|
56
|
+
const onReject = (reason) => {
|
|
57
|
+
if (__privateGet(this, _isResolved) || __privateGet(this, _isRejected) || __privateGet(this, _isCancelled)) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
__privateSet(this, _isRejected, true);
|
|
61
|
+
if (__privateGet(this, _reject)) __privateGet(this, _reject).call(this, reason);
|
|
62
|
+
};
|
|
63
|
+
const onCancel = (cancelHandler) => {
|
|
64
|
+
if (__privateGet(this, _isResolved) || __privateGet(this, _isRejected) || __privateGet(this, _isCancelled)) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
__privateGet(this, _cancelHandlers).push(cancelHandler);
|
|
68
|
+
};
|
|
69
|
+
Object.defineProperty(onCancel, "isResolved", {
|
|
70
|
+
get: () => __privateGet(this, _isResolved)
|
|
71
|
+
});
|
|
72
|
+
Object.defineProperty(onCancel, "isRejected", {
|
|
73
|
+
get: () => __privateGet(this, _isRejected)
|
|
74
|
+
});
|
|
75
|
+
Object.defineProperty(onCancel, "isCancelled", {
|
|
76
|
+
get: () => __privateGet(this, _isCancelled)
|
|
77
|
+
});
|
|
78
|
+
return executor(onResolve, onReject, onCancel);
|
|
79
|
+
}));
|
|
80
|
+
}
|
|
81
|
+
get [Symbol.toStringTag]() {
|
|
82
|
+
return "Cancellable Promise";
|
|
83
|
+
}
|
|
84
|
+
then(onFulfilled, onRejected) {
|
|
85
|
+
return __privateGet(this, _promise).then(onFulfilled, onRejected);
|
|
86
|
+
}
|
|
87
|
+
catch(onRejected) {
|
|
88
|
+
return __privateGet(this, _promise).catch(onRejected);
|
|
89
|
+
}
|
|
90
|
+
finally(onFinally) {
|
|
91
|
+
return __privateGet(this, _promise).finally(onFinally);
|
|
92
|
+
}
|
|
93
|
+
cancel() {
|
|
94
|
+
if (__privateGet(this, _isResolved) || __privateGet(this, _isRejected) || __privateGet(this, _isCancelled)) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
__privateSet(this, _isCancelled, true);
|
|
98
|
+
if (__privateGet(this, _cancelHandlers).length) {
|
|
99
|
+
try {
|
|
100
|
+
for (const cancelHandler of __privateGet(this, _cancelHandlers)) {
|
|
101
|
+
cancelHandler();
|
|
102
|
+
}
|
|
103
|
+
} catch (error) {
|
|
104
|
+
console.warn("Cancellation threw an error", error);
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
__privateGet(this, _cancelHandlers).length = 0;
|
|
109
|
+
if (__privateGet(this, _reject)) __privateGet(this, _reject).call(this, new CancelError("Request aborted"));
|
|
110
|
+
}
|
|
111
|
+
get isCancelled() {
|
|
112
|
+
return __privateGet(this, _isCancelled);
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
_isResolved = new WeakMap();
|
|
116
|
+
_isRejected = new WeakMap();
|
|
117
|
+
_isCancelled = new WeakMap();
|
|
118
|
+
_cancelHandlers = new WeakMap();
|
|
119
|
+
_promise = new WeakMap();
|
|
120
|
+
_resolve = new WeakMap();
|
|
121
|
+
_reject = new WeakMap();
|
|
122
|
+
|
|
123
|
+
// src/core/OpenAPI.ts
|
|
124
|
+
var OpenAPI = {
|
|
125
|
+
BASE: "https://api.stableflow.ai",
|
|
126
|
+
VERSION: "1.0.0",
|
|
127
|
+
WITH_CREDENTIALS: false,
|
|
128
|
+
CREDENTIALS: "include",
|
|
129
|
+
TOKEN: void 0,
|
|
130
|
+
USERNAME: void 0,
|
|
131
|
+
PASSWORD: void 0,
|
|
132
|
+
HEADERS: void 0,
|
|
133
|
+
ENCODE_PATH: void 0
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
// src/models/GetExecutionStatusResponse.ts
|
|
137
|
+
var GetExecutionStatusResponse;
|
|
138
|
+
((GetExecutionStatusResponse2) => {
|
|
139
|
+
let status;
|
|
140
|
+
((status2) => {
|
|
141
|
+
status2["KNOWN_DEPOSIT_TX"] = "KNOWN_DEPOSIT_TX";
|
|
142
|
+
status2["PENDING_DEPOSIT"] = "PENDING_DEPOSIT";
|
|
143
|
+
status2["INCOMPLETE_DEPOSIT"] = "INCOMPLETE_DEPOSIT";
|
|
144
|
+
status2["PROCESSING"] = "PROCESSING";
|
|
145
|
+
status2["SUCCESS"] = "SUCCESS";
|
|
146
|
+
status2["REFUNDED"] = "REFUNDED";
|
|
147
|
+
status2["FAILED"] = "FAILED";
|
|
148
|
+
})(status = GetExecutionStatusResponse2.status || (GetExecutionStatusResponse2.status = {}));
|
|
149
|
+
})(GetExecutionStatusResponse || (GetExecutionStatusResponse = {}));
|
|
150
|
+
|
|
151
|
+
// src/models/QuoteRequest.ts
|
|
152
|
+
var QuoteRequest;
|
|
153
|
+
((QuoteRequest2) => {
|
|
154
|
+
let depositMode;
|
|
155
|
+
((depositMode2) => {
|
|
156
|
+
depositMode2["SIMPLE"] = "SIMPLE";
|
|
157
|
+
depositMode2["MEMO"] = "MEMO";
|
|
158
|
+
})(depositMode = QuoteRequest2.depositMode || (QuoteRequest2.depositMode = {}));
|
|
159
|
+
let swapType;
|
|
160
|
+
((swapType2) => {
|
|
161
|
+
swapType2["EXACT_INPUT"] = "EXACT_INPUT";
|
|
162
|
+
swapType2["EXACT_OUTPUT"] = "EXACT_OUTPUT";
|
|
163
|
+
swapType2["FLEX_INPUT"] = "FLEX_INPUT";
|
|
164
|
+
})(swapType = QuoteRequest2.swapType || (QuoteRequest2.swapType = {}));
|
|
165
|
+
let depositType;
|
|
166
|
+
((depositType2) => {
|
|
167
|
+
depositType2["ORIGIN_CHAIN"] = "ORIGIN_CHAIN";
|
|
168
|
+
depositType2["INTENTS"] = "INTENTS";
|
|
169
|
+
})(depositType = QuoteRequest2.depositType || (QuoteRequest2.depositType = {}));
|
|
170
|
+
let refundType;
|
|
171
|
+
((refundType2) => {
|
|
172
|
+
refundType2["ORIGIN_CHAIN"] = "ORIGIN_CHAIN";
|
|
173
|
+
refundType2["INTENTS"] = "INTENTS";
|
|
174
|
+
})(refundType = QuoteRequest2.refundType || (QuoteRequest2.refundType = {}));
|
|
175
|
+
let recipientType;
|
|
176
|
+
((recipientType2) => {
|
|
177
|
+
recipientType2["DESTINATION_CHAIN"] = "DESTINATION_CHAIN";
|
|
178
|
+
recipientType2["INTENTS"] = "INTENTS";
|
|
179
|
+
})(recipientType = QuoteRequest2.recipientType || (QuoteRequest2.recipientType = {}));
|
|
180
|
+
})(QuoteRequest || (QuoteRequest = {}));
|
|
181
|
+
|
|
182
|
+
// src/models/SubmitDepositTxResponse.ts
|
|
183
|
+
var SubmitDepositTxResponse;
|
|
184
|
+
((SubmitDepositTxResponse2) => {
|
|
185
|
+
let status;
|
|
186
|
+
((status2) => {
|
|
187
|
+
status2["KNOWN_DEPOSIT_TX"] = "KNOWN_DEPOSIT_TX";
|
|
188
|
+
status2["PENDING_DEPOSIT"] = "PENDING_DEPOSIT";
|
|
189
|
+
status2["INCOMPLETE_DEPOSIT"] = "INCOMPLETE_DEPOSIT";
|
|
190
|
+
status2["PROCESSING"] = "PROCESSING";
|
|
191
|
+
status2["SUCCESS"] = "SUCCESS";
|
|
192
|
+
status2["REFUNDED"] = "REFUNDED";
|
|
193
|
+
status2["FAILED"] = "FAILED";
|
|
194
|
+
})(status = SubmitDepositTxResponse2.status || (SubmitDepositTxResponse2.status = {}));
|
|
195
|
+
})(SubmitDepositTxResponse || (SubmitDepositTxResponse = {}));
|
|
196
|
+
|
|
197
|
+
// src/models/TokenResponse.ts
|
|
198
|
+
var TokenResponse;
|
|
199
|
+
((TokenResponse2) => {
|
|
200
|
+
let blockchain;
|
|
201
|
+
((blockchain2) => {
|
|
202
|
+
blockchain2["NEAR"] = "near";
|
|
203
|
+
blockchain2["ETH"] = "eth";
|
|
204
|
+
blockchain2["BASE"] = "base";
|
|
205
|
+
blockchain2["ARB"] = "arb";
|
|
206
|
+
blockchain2["BTC"] = "btc";
|
|
207
|
+
blockchain2["SOL"] = "sol";
|
|
208
|
+
blockchain2["TON"] = "ton";
|
|
209
|
+
blockchain2["DOGE"] = "doge";
|
|
210
|
+
blockchain2["XRP"] = "xrp";
|
|
211
|
+
blockchain2["ZEC"] = "zec";
|
|
212
|
+
blockchain2["GNOSIS"] = "gnosis";
|
|
213
|
+
blockchain2["BERA"] = "bera";
|
|
214
|
+
blockchain2["BSC"] = "bsc";
|
|
215
|
+
blockchain2["POL"] = "pol";
|
|
216
|
+
blockchain2["TRON"] = "tron";
|
|
217
|
+
blockchain2["SUI"] = "sui";
|
|
218
|
+
blockchain2["OP"] = "op";
|
|
219
|
+
blockchain2["AVAX"] = "avax";
|
|
220
|
+
blockchain2["CARDANO"] = "cardano";
|
|
221
|
+
})(blockchain = TokenResponse2.blockchain || (TokenResponse2.blockchain = {}));
|
|
222
|
+
})(TokenResponse || (TokenResponse = {}));
|
|
223
|
+
|
|
224
|
+
// src/core/request.ts
|
|
225
|
+
import axios from "axios";
|
|
226
|
+
import FormData from "form-data";
|
|
227
|
+
var isDefined = (value) => {
|
|
228
|
+
return value !== void 0 && value !== null;
|
|
229
|
+
};
|
|
230
|
+
var isString = (value) => {
|
|
231
|
+
return typeof value === "string";
|
|
232
|
+
};
|
|
233
|
+
var isStringWithValue = (value) => {
|
|
234
|
+
return isString(value) && value !== "";
|
|
235
|
+
};
|
|
236
|
+
var isBlob = (value) => {
|
|
237
|
+
return typeof value === "object" && typeof value.type === "string" && typeof value.stream === "function" && typeof value.arrayBuffer === "function" && typeof value.constructor === "function" && typeof value.constructor.name === "string" && /^(Blob|File)$/.test(value.constructor.name) && /^(Blob|File)$/.test(value[Symbol.toStringTag]);
|
|
238
|
+
};
|
|
239
|
+
var isFormData = (value) => {
|
|
240
|
+
return value instanceof FormData;
|
|
241
|
+
};
|
|
242
|
+
var isSuccess = (status) => {
|
|
243
|
+
return status >= 200 && status < 300;
|
|
244
|
+
};
|
|
245
|
+
var base64 = (str) => {
|
|
246
|
+
try {
|
|
247
|
+
return btoa(str);
|
|
248
|
+
} catch (err) {
|
|
249
|
+
return Buffer.from(str).toString("base64");
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
var getQueryString = (params) => {
|
|
253
|
+
const qs = [];
|
|
254
|
+
const append = (key, value) => {
|
|
255
|
+
qs.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`);
|
|
256
|
+
};
|
|
257
|
+
const process = (key, value) => {
|
|
258
|
+
if (isDefined(value)) {
|
|
259
|
+
if (Array.isArray(value)) {
|
|
260
|
+
value.forEach((v) => {
|
|
261
|
+
process(key, v);
|
|
262
|
+
});
|
|
263
|
+
} else if (typeof value === "object") {
|
|
264
|
+
Object.entries(value).forEach(([k, v]) => {
|
|
265
|
+
process(`${key}[${k}]`, v);
|
|
266
|
+
});
|
|
267
|
+
} else {
|
|
268
|
+
append(key, value);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
Object.entries(params).forEach(([key, value]) => {
|
|
273
|
+
process(key, value);
|
|
274
|
+
});
|
|
275
|
+
if (qs.length > 0) {
|
|
276
|
+
return `?${qs.join("&")}`;
|
|
277
|
+
}
|
|
278
|
+
return "";
|
|
279
|
+
};
|
|
280
|
+
var getUrl = (config, options) => {
|
|
281
|
+
const encoder = config.ENCODE_PATH || encodeURI;
|
|
282
|
+
const path = options.url.replace("{api-version}", config.VERSION).replace(/{(.*?)}/g, (substring, group) => {
|
|
283
|
+
if (options.path?.hasOwnProperty(group)) {
|
|
284
|
+
return encoder(String(options.path[group]));
|
|
285
|
+
}
|
|
286
|
+
return substring;
|
|
287
|
+
});
|
|
288
|
+
const url = `${config.BASE}${path}`;
|
|
289
|
+
if (options.query) {
|
|
290
|
+
return `${url}${getQueryString(options.query)}`;
|
|
291
|
+
}
|
|
292
|
+
return url;
|
|
293
|
+
};
|
|
294
|
+
var getFormData = (options) => {
|
|
295
|
+
if (options.formData) {
|
|
296
|
+
const formData = new FormData();
|
|
297
|
+
const process = (key, value) => {
|
|
298
|
+
if (isString(value) || isBlob(value)) {
|
|
299
|
+
formData.append(key, value);
|
|
300
|
+
} else {
|
|
301
|
+
formData.append(key, JSON.stringify(value));
|
|
302
|
+
}
|
|
303
|
+
};
|
|
304
|
+
Object.entries(options.formData).filter(([_, value]) => isDefined(value)).forEach(([key, value]) => {
|
|
305
|
+
if (Array.isArray(value)) {
|
|
306
|
+
value.forEach((v) => process(key, v));
|
|
307
|
+
} else {
|
|
308
|
+
process(key, value);
|
|
309
|
+
}
|
|
310
|
+
});
|
|
311
|
+
return formData;
|
|
312
|
+
}
|
|
313
|
+
return void 0;
|
|
314
|
+
};
|
|
315
|
+
var resolve = async (options, resolver) => {
|
|
316
|
+
if (typeof resolver === "function") {
|
|
317
|
+
return resolver(options);
|
|
318
|
+
}
|
|
319
|
+
return resolver;
|
|
320
|
+
};
|
|
321
|
+
var getHeaders = async (config, options, formData) => {
|
|
322
|
+
const [token, username, password, additionalHeaders] = await Promise.all([
|
|
323
|
+
resolve(options, config.TOKEN),
|
|
324
|
+
resolve(options, config.USERNAME),
|
|
325
|
+
resolve(options, config.PASSWORD),
|
|
326
|
+
resolve(options, config.HEADERS)
|
|
327
|
+
]);
|
|
328
|
+
const formHeaders = typeof formData?.getHeaders === "function" && formData?.getHeaders() || {};
|
|
329
|
+
const headers = Object.entries({
|
|
330
|
+
Accept: "application/json",
|
|
331
|
+
...additionalHeaders,
|
|
332
|
+
...options.headers,
|
|
333
|
+
...formHeaders
|
|
334
|
+
}).filter(([_, value]) => isDefined(value)).reduce((headers2, [key, value]) => ({
|
|
335
|
+
...headers2,
|
|
336
|
+
[key]: String(value)
|
|
337
|
+
}), {});
|
|
338
|
+
if (isStringWithValue(token)) {
|
|
339
|
+
headers["Authorization"] = `Bearer ${token}`;
|
|
340
|
+
}
|
|
341
|
+
if (isStringWithValue(username) && isStringWithValue(password)) {
|
|
342
|
+
const credentials = base64(`${username}:${password}`);
|
|
343
|
+
headers["Authorization"] = `Basic ${credentials}`;
|
|
344
|
+
}
|
|
345
|
+
if (options.body !== void 0) {
|
|
346
|
+
if (options.mediaType) {
|
|
347
|
+
headers["Content-Type"] = options.mediaType;
|
|
348
|
+
} else if (isBlob(options.body)) {
|
|
349
|
+
headers["Content-Type"] = options.body.type || "application/octet-stream";
|
|
350
|
+
} else if (isString(options.body)) {
|
|
351
|
+
headers["Content-Type"] = "text/plain";
|
|
352
|
+
} else if (!isFormData(options.body)) {
|
|
353
|
+
headers["Content-Type"] = "application/json";
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
return headers;
|
|
357
|
+
};
|
|
358
|
+
var getRequestBody = (options) => {
|
|
359
|
+
if (options.body) {
|
|
360
|
+
return options.body;
|
|
361
|
+
}
|
|
362
|
+
return void 0;
|
|
363
|
+
};
|
|
364
|
+
var sendRequest = async (config, options, url, body, formData, headers, onCancel, axiosClient) => {
|
|
365
|
+
const source = axios.CancelToken.source();
|
|
366
|
+
const requestConfig = {
|
|
367
|
+
url,
|
|
368
|
+
headers,
|
|
369
|
+
data: body ?? formData,
|
|
370
|
+
method: options.method,
|
|
371
|
+
withCredentials: config.WITH_CREDENTIALS,
|
|
372
|
+
withXSRFToken: config.CREDENTIALS === "include" ? config.WITH_CREDENTIALS : false,
|
|
373
|
+
cancelToken: source.token
|
|
374
|
+
};
|
|
375
|
+
onCancel(() => source.cancel("The user aborted a request."));
|
|
376
|
+
try {
|
|
377
|
+
return await axiosClient.request(requestConfig);
|
|
378
|
+
} catch (error) {
|
|
379
|
+
const axiosError = error;
|
|
380
|
+
if (axiosError.response) {
|
|
381
|
+
return axiosError.response;
|
|
382
|
+
}
|
|
383
|
+
throw error;
|
|
384
|
+
}
|
|
385
|
+
};
|
|
386
|
+
var getResponseHeader = (response, responseHeader) => {
|
|
387
|
+
if (responseHeader) {
|
|
388
|
+
const content = response.headers[responseHeader];
|
|
389
|
+
if (isString(content)) {
|
|
390
|
+
return content;
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
return void 0;
|
|
394
|
+
};
|
|
395
|
+
var getResponseBody = (response) => {
|
|
396
|
+
if (response.status !== 204) {
|
|
397
|
+
return response.data;
|
|
398
|
+
}
|
|
399
|
+
return void 0;
|
|
400
|
+
};
|
|
401
|
+
var catchErrorCodes = (options, result) => {
|
|
402
|
+
const errors = {
|
|
403
|
+
400: "Bad Request",
|
|
404
|
+
401: "Unauthorized",
|
|
405
|
+
403: "Forbidden",
|
|
406
|
+
404: "Not Found",
|
|
407
|
+
500: "Internal Server Error",
|
|
408
|
+
502: "Bad Gateway",
|
|
409
|
+
503: "Service Unavailable",
|
|
410
|
+
...options.errors
|
|
411
|
+
};
|
|
412
|
+
const error = errors[result.status];
|
|
413
|
+
if (error) {
|
|
414
|
+
throw new ApiError(options, result, error);
|
|
415
|
+
}
|
|
416
|
+
if (!result.ok) {
|
|
417
|
+
const errorStatus = result.status ?? "unknown";
|
|
418
|
+
const errorStatusText = result.statusText ?? "unknown";
|
|
419
|
+
const errorBody = (() => {
|
|
420
|
+
try {
|
|
421
|
+
return JSON.stringify(result.body, null, 2);
|
|
422
|
+
} catch (e) {
|
|
423
|
+
return void 0;
|
|
424
|
+
}
|
|
425
|
+
})();
|
|
426
|
+
throw new ApiError(
|
|
427
|
+
options,
|
|
428
|
+
result,
|
|
429
|
+
`Generic Error: status: ${errorStatus}; status text: ${errorStatusText}; body: ${errorBody}`
|
|
430
|
+
);
|
|
431
|
+
}
|
|
432
|
+
};
|
|
433
|
+
var request = (config, options, axiosClient = axios) => {
|
|
434
|
+
return new CancelablePromise(async (resolve2, reject, onCancel) => {
|
|
435
|
+
try {
|
|
436
|
+
const url = getUrl(config, options);
|
|
437
|
+
const formData = getFormData(options);
|
|
438
|
+
const body = getRequestBody(options);
|
|
439
|
+
const headers = await getHeaders(config, options, formData);
|
|
440
|
+
console.log("\n\u{1F535} ========== API Request ==========");
|
|
441
|
+
console.log("Method:", options.method);
|
|
442
|
+
console.log("URL:", url);
|
|
443
|
+
console.log("Headers:", JSON.stringify(headers, null, 2));
|
|
444
|
+
if (body) {
|
|
445
|
+
console.log("Body:", JSON.stringify(body, null, 2));
|
|
446
|
+
}
|
|
447
|
+
if (formData) {
|
|
448
|
+
console.log("FormData:", formData);
|
|
449
|
+
}
|
|
450
|
+
console.log("====================================\n");
|
|
451
|
+
if (!onCancel.isCancelled) {
|
|
452
|
+
const response = await sendRequest(config, options, url, body, formData, headers, onCancel, axiosClient);
|
|
453
|
+
const responseBody = getResponseBody(response);
|
|
454
|
+
const responseHeader = getResponseHeader(response, options.responseHeader);
|
|
455
|
+
const result = {
|
|
456
|
+
url,
|
|
457
|
+
ok: isSuccess(response.status),
|
|
458
|
+
status: response.status,
|
|
459
|
+
statusText: response.statusText,
|
|
460
|
+
body: responseHeader ?? responseBody
|
|
461
|
+
};
|
|
462
|
+
console.log("\n\u{1F7E2} ========== API Response ==========");
|
|
463
|
+
console.log("Status:", response.status, response.statusText);
|
|
464
|
+
console.log("Response Headers:", JSON.stringify(response.headers, null, 2));
|
|
465
|
+
console.log("Response Body:", JSON.stringify(responseBody, null, 2));
|
|
466
|
+
console.log("=====================================\n");
|
|
467
|
+
catchErrorCodes(options, result);
|
|
468
|
+
resolve2(result.body);
|
|
469
|
+
}
|
|
470
|
+
} catch (error) {
|
|
471
|
+
console.log("\n\u{1F534} ========== API Error ==========");
|
|
472
|
+
console.log("Error:", error);
|
|
473
|
+
if (error instanceof ApiError) {
|
|
474
|
+
console.log("Status:", error.status);
|
|
475
|
+
console.log("Status Text:", error.statusText);
|
|
476
|
+
console.log("URL:", error.url);
|
|
477
|
+
console.log("Body:", JSON.stringify(error.body, null, 2));
|
|
478
|
+
}
|
|
479
|
+
console.log("==================================\n");
|
|
480
|
+
reject(error);
|
|
481
|
+
}
|
|
482
|
+
});
|
|
483
|
+
};
|
|
484
|
+
|
|
485
|
+
// src/services/SFA.ts
|
|
486
|
+
var SFA = class {
|
|
487
|
+
/**
|
|
488
|
+
* Get supported tokens
|
|
489
|
+
* Retrieves a list of tokens currently supported by the StableFlow AI API for asset swaps.
|
|
490
|
+
*
|
|
491
|
+
* Each token entry includes its blockchain, contract address (if available), price in USD, and other metadata such as symbol and decimals.
|
|
492
|
+
* @returns TokenResponse
|
|
493
|
+
* @throws ApiError
|
|
494
|
+
*/
|
|
495
|
+
static getTokens() {
|
|
496
|
+
return request(OpenAPI, {
|
|
497
|
+
method: "GET",
|
|
498
|
+
url: "/v0/tokens"
|
|
499
|
+
});
|
|
500
|
+
}
|
|
501
|
+
/**
|
|
502
|
+
* Request a swap quote
|
|
503
|
+
* Generates a swap quote based on input parameters such as the assets, amount, slippage tolerance, and recipient/refund information.
|
|
504
|
+
*
|
|
505
|
+
* Returns pricing details, estimated time, and a unique **deposit address** to which tokens must be transferred to initiate the swap.
|
|
506
|
+
*
|
|
507
|
+
* You can set the `dry` parameter to `true` to simulate the quote request **without generating a deposit address** or initiating the swap process. This is useful for previewing swap parameters or validating input data without committing to an actual swap.
|
|
508
|
+
*
|
|
509
|
+
* This endpoint is the first required step in the swap process.
|
|
510
|
+
* @param requestBody
|
|
511
|
+
* @returns QuoteResponse
|
|
512
|
+
* @throws ApiError
|
|
513
|
+
*/
|
|
514
|
+
static getQuote(requestBody) {
|
|
515
|
+
return request(OpenAPI, {
|
|
516
|
+
method: "POST",
|
|
517
|
+
url: "/v0/quote",
|
|
518
|
+
body: requestBody,
|
|
519
|
+
mediaType: "application/json",
|
|
520
|
+
errors: {
|
|
521
|
+
400: `Bad Request - Invalid input data`,
|
|
522
|
+
401: `Unauthorized - JWT token is invalid`
|
|
523
|
+
}
|
|
524
|
+
});
|
|
525
|
+
}
|
|
526
|
+
/**
|
|
527
|
+
* Check swap execution status
|
|
528
|
+
* Retrieves the current status of a swap using the unique deposit address from the quote, if quote response included deposit memo, it is required as well.
|
|
529
|
+
*
|
|
530
|
+
* The response includes the state of the swap (e.g., pending, processing, success, refunded) and any associated swap and transaction details.
|
|
531
|
+
* @param depositAddress
|
|
532
|
+
* @param depositMemo
|
|
533
|
+
* @returns GetExecutionStatusResponse
|
|
534
|
+
* @throws ApiError
|
|
535
|
+
*/
|
|
536
|
+
static getExecutionStatus(depositAddress, depositMemo) {
|
|
537
|
+
return request(OpenAPI, {
|
|
538
|
+
method: "GET",
|
|
539
|
+
url: "/v0/status",
|
|
540
|
+
query: {
|
|
541
|
+
"depositAddress": depositAddress,
|
|
542
|
+
"depositMemo": depositMemo
|
|
543
|
+
},
|
|
544
|
+
errors: {
|
|
545
|
+
401: `Unauthorized - JWT token is invalid`,
|
|
546
|
+
404: `Deposit address not found`
|
|
547
|
+
}
|
|
548
|
+
});
|
|
549
|
+
}
|
|
550
|
+
/**
|
|
551
|
+
* Submit deposit transaction hash
|
|
552
|
+
* Optionally notifies the StableFlow AI service that a deposit has been sent to the specified address, using the blockchain transaction hash.
|
|
553
|
+
*
|
|
554
|
+
* This step can speed up swap processing by allowing the system to preemptively verify the deposit.
|
|
555
|
+
* @param requestBody
|
|
556
|
+
* @returns SubmitDepositTxResponse
|
|
557
|
+
* @throws ApiError
|
|
558
|
+
*/
|
|
559
|
+
static submitDepositTx(requestBody) {
|
|
560
|
+
return request(OpenAPI, {
|
|
561
|
+
method: "POST",
|
|
562
|
+
url: "/v0/deposit/submit",
|
|
563
|
+
body: requestBody,
|
|
564
|
+
mediaType: "application/json",
|
|
565
|
+
errors: {
|
|
566
|
+
400: `Bad Request - Invalid input data`,
|
|
567
|
+
401: `Unauthorized - JWT token is invalid`
|
|
568
|
+
}
|
|
569
|
+
});
|
|
570
|
+
}
|
|
571
|
+
};
|
|
572
|
+
export {
|
|
573
|
+
ApiError,
|
|
574
|
+
CancelError,
|
|
575
|
+
CancelablePromise,
|
|
576
|
+
GetExecutionStatusResponse,
|
|
577
|
+
OpenAPI,
|
|
578
|
+
QuoteRequest,
|
|
579
|
+
SFA,
|
|
580
|
+
SubmitDepositTxResponse,
|
|
581
|
+
TokenResponse
|
|
582
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "stableflow-ai-sdk",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "TypeScript SDK for StableFlow AI API - Cross-chain token swap solution",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.mjs",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"require": "./dist/index.js",
|
|
12
|
+
"import": "./dist/index.mjs"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"README.md",
|
|
18
|
+
"LICENSE"
|
|
19
|
+
],
|
|
20
|
+
"engines": {
|
|
21
|
+
"node": ">=16"
|
|
22
|
+
},
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "tsup src/index.ts --format cjs,esm --dts --clean",
|
|
25
|
+
"clean": "rm -rf dist node_modules",
|
|
26
|
+
"dev": "tsup src/index.ts --format cjs,esm --dts --watch",
|
|
27
|
+
"prepublishOnly": "npm run build",
|
|
28
|
+
"test": "echo \"No tests specified\" && exit 0"
|
|
29
|
+
},
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "https://github.com/stableflow-ai/stableflow-ai-sdk.git"
|
|
33
|
+
},
|
|
34
|
+
"bugs": {
|
|
35
|
+
"url": "https://github.com/stableflow-ai/stableflow-ai-sdk/issues"
|
|
36
|
+
},
|
|
37
|
+
"homepage": "https://github.com/stableflow-ai/stableflow-ai-sdk#readme",
|
|
38
|
+
"keywords": [
|
|
39
|
+
"stableflow",
|
|
40
|
+
"ai",
|
|
41
|
+
"sdk",
|
|
42
|
+
"typescript",
|
|
43
|
+
"swap",
|
|
44
|
+
"cross-chain",
|
|
45
|
+
"defi",
|
|
46
|
+
"blockchain",
|
|
47
|
+
"bridge",
|
|
48
|
+
"usdt",
|
|
49
|
+
"ethereum",
|
|
50
|
+
"arbitrum",
|
|
51
|
+
"polygon"
|
|
52
|
+
],
|
|
53
|
+
"author": "StableFlow AI",
|
|
54
|
+
"license": "MIT",
|
|
55
|
+
"devDependencies": {
|
|
56
|
+
"tsup": "^8.0.2",
|
|
57
|
+
"typescript": "^5.4.2"
|
|
58
|
+
},
|
|
59
|
+
"dependencies": {
|
|
60
|
+
"axios": "^1.6.8",
|
|
61
|
+
"form-data": "^4.0.0"
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|