@ardrive/turbo-sdk 1.31.0-alpha.2 → 1.31.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/README.md +2 -2
- package/bundles/web.bundle.min.js +241 -459
- package/lib/cjs/common/chunked.js +15 -9
- package/lib/cjs/common/http.js +39 -4
- package/lib/cjs/common/payment.js +2 -1
- package/lib/cjs/common/upload.js +1 -4
- package/lib/cjs/utils/axiosClient.js +3 -37
- package/lib/cjs/version.js +1 -1
- package/lib/esm/common/chunked.js +16 -10
- package/lib/esm/common/http.js +40 -5
- package/lib/esm/common/payment.js +2 -1
- package/lib/esm/common/upload.js +1 -4
- package/lib/esm/utils/axiosClient.js +3 -14
- package/lib/esm/version.js +1 -1
- package/lib/types/common/chunked.d.ts.map +1 -1
- package/lib/types/common/http.d.ts +5 -3
- package/lib/types/common/http.d.ts.map +1 -1
- package/lib/types/common/payment.d.ts +1 -1
- package/lib/types/common/payment.d.ts.map +1 -1
- package/lib/types/common/upload.d.ts +2 -2
- package/lib/types/common/upload.d.ts.map +1 -1
- package/lib/types/types.d.ts +2 -2
- package/lib/types/types.d.ts.map +1 -1
- package/lib/types/utils/axiosClient.d.ts +8 -4
- package/lib/types/utils/axiosClient.d.ts.map +1 -1
- package/lib/types/version.d.ts +1 -1
- package/package.json +2 -3
|
@@ -29,6 +29,8 @@ const logger_js_1 = require("./logger.js");
|
|
|
29
29
|
const fiveMiB = 5 * 1024 * 1024; // 5 MiB
|
|
30
30
|
const fiveHundredMiB = fiveMiB * 100; // 500 MiB
|
|
31
31
|
exports.defaultMaxChunkConcurrency = 5;
|
|
32
|
+
// Limit uploaders to protect server
|
|
33
|
+
const absoluteMaxChunkConcurrency = 256;
|
|
32
34
|
exports.maxChunkByteCount = fiveHundredMiB;
|
|
33
35
|
exports.minChunkByteCount = fiveMiB;
|
|
34
36
|
exports.defaultChunkByteCount = exports.minChunkByteCount;
|
|
@@ -78,8 +80,9 @@ class ChunkedUploader {
|
|
|
78
80
|
}
|
|
79
81
|
if (Number.isNaN(maxChunkConcurrency) ||
|
|
80
82
|
!Number.isInteger(maxChunkConcurrency) ||
|
|
81
|
-
maxChunkConcurrency < 1
|
|
82
|
-
|
|
83
|
+
maxChunkConcurrency < 1 ||
|
|
84
|
+
maxChunkConcurrency > absoluteMaxChunkConcurrency) {
|
|
85
|
+
throw new Error('Invalid max chunk concurrency. Must be an integer of at least 1 and at most 256.');
|
|
83
86
|
}
|
|
84
87
|
if (Number.isNaN(chunkByteCount) ||
|
|
85
88
|
!Number.isInteger(chunkByteCount) ||
|
|
@@ -212,17 +215,17 @@ class ChunkedUploader {
|
|
|
212
215
|
async finalizeUpload(uploadId, dataItemByteCount, paidBy, signal) {
|
|
213
216
|
// Wait up to 1 minute per GiB of data for the upload to finalize
|
|
214
217
|
const fileSizeInGiB = Math.ceil(this.toGiB(dataItemByteCount));
|
|
215
|
-
const defaultMaxWaitTimeMins = fileSizeInGiB;
|
|
216
|
-
const maxWaitTimeMs = this.maxFinalizeMs ?? defaultMaxWaitTimeMins * 60 * 1000;
|
|
218
|
+
const defaultMaxWaitTimeMins = fileSizeInGiB * 2.5;
|
|
219
|
+
const maxWaitTimeMs = this.maxFinalizeMs ?? Math.floor(defaultMaxWaitTimeMins * 60 * 1000);
|
|
217
220
|
const minimumWaitPerStepMs =
|
|
218
221
|
// Per step, files smaller than 100MB will wait 2 second,
|
|
219
222
|
dataItemByteCount < 1024 * 1024 * 100
|
|
220
223
|
? 2000
|
|
221
|
-
: // files smaller than 3 GiB will wait
|
|
224
|
+
: // files smaller than 3 GiB will wait 4 seconds,
|
|
222
225
|
dataItemByteCount < 1024 * 1024 * 1024 * 3
|
|
223
|
-
?
|
|
224
|
-
: // and larger files will wait 1 second per GiB with max of
|
|
225
|
-
Math.max(
|
|
226
|
+
? 4000
|
|
227
|
+
: // and larger files will wait 1.5 second per GiB with max of 15 seconds
|
|
228
|
+
Math.max(1500 * fileSizeInGiB, 15000);
|
|
226
229
|
const paidByHeader = {};
|
|
227
230
|
if (paidBy !== undefined) {
|
|
228
231
|
paidByHeader['x-paid-by'] = Array.isArray(paidBy)
|
|
@@ -239,7 +242,7 @@ class ChunkedUploader {
|
|
|
239
242
|
},
|
|
240
243
|
signal,
|
|
241
244
|
});
|
|
242
|
-
this.logger.debug(`Confirming upload to Turbo with uploadId ${uploadId} for up to ${
|
|
245
|
+
this.logger.debug(`Confirming upload to Turbo with uploadId ${uploadId} for up to ${maxWaitTimeMs / 1000 / 60} minutes.`);
|
|
243
246
|
const startTime = Date.now();
|
|
244
247
|
const cutoffTime = startTime + maxWaitTimeMs;
|
|
245
248
|
let attempts = 0;
|
|
@@ -270,6 +273,9 @@ class ChunkedUploader {
|
|
|
270
273
|
if (response.status === 'UNDERFUNDED') {
|
|
271
274
|
throw new errors_js_1.FailedRequestError(`Insufficient balance`, 402);
|
|
272
275
|
}
|
|
276
|
+
if (types_js_1.multipartFailedStatus.includes(response.status)) {
|
|
277
|
+
throw new errors_js_1.FailedRequestError(`Upload failed with multi-part status ${response.status}`);
|
|
278
|
+
}
|
|
273
279
|
}
|
|
274
280
|
throw new Error(`Upload multi-part finalization has timed out for Upload ID ${uploadId}`);
|
|
275
281
|
}
|
package/lib/cjs/common/http.js
CHANGED
|
@@ -17,27 +17,34 @@ exports.TurboHTTPService = void 0;
|
|
|
17
17
|
* limitations under the License.
|
|
18
18
|
*/
|
|
19
19
|
const axios_1 = require("axios");
|
|
20
|
+
const node_stream_1 = require("node:stream");
|
|
20
21
|
const axiosClient_js_1 = require("../utils/axiosClient.js");
|
|
22
|
+
const common_js_1 = require("../utils/common.js");
|
|
21
23
|
const errors_js_1 = require("../utils/errors.js");
|
|
22
24
|
class TurboHTTPService {
|
|
23
|
-
constructor({ url, retryConfig, logger, }) {
|
|
25
|
+
constructor({ url, logger, retryConfig = (0, axiosClient_js_1.defaultRetryConfig)(logger), }) {
|
|
24
26
|
this.logger = logger;
|
|
25
27
|
this.axios = (0, axiosClient_js_1.createAxiosInstance)({
|
|
26
28
|
axiosConfig: {
|
|
27
29
|
baseURL: url,
|
|
28
30
|
maxRedirects: 0, // prevents backpressure issues when uploading larger streams via https
|
|
29
31
|
},
|
|
30
|
-
retryConfig,
|
|
31
32
|
logger: this.logger,
|
|
32
33
|
});
|
|
34
|
+
this.retryConfig = retryConfig;
|
|
33
35
|
}
|
|
34
36
|
async get({ endpoint, signal, allowedStatuses = [200, 202], headers, }) {
|
|
35
|
-
return this.
|
|
37
|
+
return this.retryRequest(() => this.axios.get(endpoint, { headers, signal }), allowedStatuses);
|
|
36
38
|
}
|
|
37
39
|
async post({ endpoint, signal, allowedStatuses = [200, 202], headers, data, }) {
|
|
38
40
|
// Buffer and Readable → keep Axios (streams work fine there)
|
|
39
41
|
if (!(data instanceof ReadableStream)) {
|
|
40
|
-
|
|
42
|
+
if (data instanceof node_stream_1.Readable) {
|
|
43
|
+
return this.tryRequest(
|
|
44
|
+
// Can't retry a Readable stream that has already been partially consumed
|
|
45
|
+
() => this.axios.post(endpoint, data, { headers, signal }), allowedStatuses);
|
|
46
|
+
}
|
|
47
|
+
return this.retryRequest(() => this.axios.post(endpoint, data, { headers, signal }), allowedStatuses);
|
|
41
48
|
}
|
|
42
49
|
// Browser ReadableStream → use fetch with progressive enhancement of duplex
|
|
43
50
|
// Note: fetch does not support streams in Safari and Firefox, so we convert to Blob
|
|
@@ -95,6 +102,34 @@ class TurboHTTPService {
|
|
|
95
102
|
throw error;
|
|
96
103
|
}
|
|
97
104
|
}
|
|
105
|
+
async retryRequest(request, allowedStatuses) {
|
|
106
|
+
let attempt = 0;
|
|
107
|
+
let lastError;
|
|
108
|
+
while (attempt < this.retryConfig.retries) {
|
|
109
|
+
try {
|
|
110
|
+
const resp = await this.tryRequest(request, allowedStatuses);
|
|
111
|
+
return resp;
|
|
112
|
+
}
|
|
113
|
+
catch (error) {
|
|
114
|
+
if (error instanceof errors_js_1.FailedRequestError) {
|
|
115
|
+
lastError = error;
|
|
116
|
+
this.retryConfig.onRetry(attempt + 1, error);
|
|
117
|
+
if (error.status !== undefined &&
|
|
118
|
+
error.status >= 400 &&
|
|
119
|
+
error.status < 500) {
|
|
120
|
+
// If it's a client error, we can stop retrying
|
|
121
|
+
throw error;
|
|
122
|
+
}
|
|
123
|
+
await (0, common_js_1.sleep)(this.retryConfig.retryDelay(attempt + 1));
|
|
124
|
+
attempt++;
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
throw error;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
throw new errors_js_1.FailedRequestError('Max retries reached - ' + lastError?.message, lastError?.status);
|
|
132
|
+
}
|
|
98
133
|
}
|
|
99
134
|
exports.TurboHTTPService = TurboHTTPService;
|
|
100
135
|
async function toFetchBody(data) {
|
|
@@ -17,13 +17,14 @@ exports.TurboAuthenticatedPaymentService = exports.TurboUnauthenticatedPaymentSe
|
|
|
17
17
|
* limitations under the License.
|
|
18
18
|
*/
|
|
19
19
|
const bignumber_js_1 = require("bignumber.js");
|
|
20
|
+
const axiosClient_js_1 = require("../utils/axiosClient.js");
|
|
20
21
|
const http_js_1 = require("./http.js");
|
|
21
22
|
const logger_js_1 = require("./logger.js");
|
|
22
23
|
const index_js_1 = require("./token/index.js");
|
|
23
24
|
exports.developmentPaymentServiceURL = 'https://payment.ardrive.dev';
|
|
24
25
|
exports.defaultPaymentServiceURL = 'https://payment.ardrive.io';
|
|
25
26
|
class TurboUnauthenticatedPaymentService {
|
|
26
|
-
constructor({ url = exports.defaultPaymentServiceURL,
|
|
27
|
+
constructor({ url = exports.defaultPaymentServiceURL, logger = logger_js_1.TurboWinstonLogger.default, retryConfig = (0, axiosClient_js_1.defaultRetryConfig)(logger), token = 'arweave', }) {
|
|
27
28
|
this.logger = logger;
|
|
28
29
|
this.httpService = new http_js_1.TurboHTTPService({
|
|
29
30
|
url: `${url}/v1`,
|
package/lib/cjs/common/upload.js
CHANGED
|
@@ -235,10 +235,7 @@ class TurboAuthenticatedBaseUploadService extends TurboUnauthenticatedUploadServ
|
|
|
235
235
|
resolve();
|
|
236
236
|
});
|
|
237
237
|
});
|
|
238
|
-
await Promise.race([
|
|
239
|
-
(0, common_js_1.sleep)(retryDelay(retries, error)),
|
|
240
|
-
abortEventPromise,
|
|
241
|
-
]);
|
|
238
|
+
await Promise.race([(0, common_js_1.sleep)(retryDelay(retries)), abortEventPromise]);
|
|
242
239
|
}
|
|
243
240
|
}
|
|
244
241
|
const msg = `Failed to upload file after ${retries + 1} attempts\n${lastError instanceof Error ? lastError.message : lastError}`;
|
|
@@ -1,27 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
4
|
};
|
|
@@ -42,8 +19,7 @@ exports.createAxiosInstance = exports.defaultRetryConfig = exports.defaultReques
|
|
|
42
19
|
* See the License for the specific language governing permissions and
|
|
43
20
|
* limitations under the License.
|
|
44
21
|
*/
|
|
45
|
-
const axios_1 =
|
|
46
|
-
const axios_retry_1 = __importDefault(require("axios-retry"));
|
|
22
|
+
const axios_1 = __importDefault(require("axios"));
|
|
47
23
|
const logger_js_1 = require("../common/logger.js");
|
|
48
24
|
const version_js_1 = require("../version.js");
|
|
49
25
|
exports.defaultRequestHeaders = {
|
|
@@ -51,19 +27,14 @@ exports.defaultRequestHeaders = {
|
|
|
51
27
|
'x-turbo-source-identifier': 'turbo-sdk',
|
|
52
28
|
};
|
|
53
29
|
const defaultRetryConfig = (logger = logger_js_1.TurboWinstonLogger.default) => ({
|
|
54
|
-
retryDelay:
|
|
30
|
+
retryDelay: (retryCount) => Math.min(1000 * 2 ** (retryCount - 1), 30 * 1000), // exponential backoff up to 30s
|
|
55
31
|
retries: 5,
|
|
56
|
-
retryCondition: (error) => {
|
|
57
|
-
return (!(error instanceof axios_1.CanceledError) &&
|
|
58
|
-
axios_retry_1.default.isIdempotentRequestError(error) &&
|
|
59
|
-
axios_retry_1.default.isNetworkError(error));
|
|
60
|
-
},
|
|
61
32
|
onRetry: (retryCount, error) => {
|
|
62
33
|
logger.debug(`Request failed, ${error}. Retry attempt #${retryCount}...`);
|
|
63
34
|
},
|
|
64
35
|
});
|
|
65
36
|
exports.defaultRetryConfig = defaultRetryConfig;
|
|
66
|
-
const createAxiosInstance = ({
|
|
37
|
+
const createAxiosInstance = ({ axiosConfig = {}, } = {}) => {
|
|
67
38
|
const axiosInstance = axios_1.default.create({
|
|
68
39
|
...axiosConfig,
|
|
69
40
|
headers: {
|
|
@@ -73,11 +44,6 @@ const createAxiosInstance = ({ logger = logger_js_1.TurboWinstonLogger.default,
|
|
|
73
44
|
adapter: 'fetch',
|
|
74
45
|
validateStatus: () => true, // don't throw on non-200 status codes
|
|
75
46
|
});
|
|
76
|
-
if (retryConfig.retries !== undefined && retryConfig.retries > 0) {
|
|
77
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
78
|
-
// @ts-ignore
|
|
79
|
-
(0, axios_retry_1.default)(axiosInstance, retryConfig);
|
|
80
|
-
}
|
|
81
47
|
return axiosInstance;
|
|
82
48
|
};
|
|
83
49
|
exports.createAxiosInstance = createAxiosInstance;
|
package/lib/cjs/version.js
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
*/
|
|
16
16
|
import { CanceledError } from 'axios';
|
|
17
17
|
import { pLimit } from 'plimit-lit';
|
|
18
|
-
import { validChunkingModes, } from '../types.js';
|
|
18
|
+
import { multipartFailedStatus, validChunkingModes, } from '../types.js';
|
|
19
19
|
import { sleep } from '../utils/common.js';
|
|
20
20
|
import { FailedRequestError } from '../utils/errors.js';
|
|
21
21
|
import { TurboEventEmitter, createStreamWithUploadEvents } from './events.js';
|
|
@@ -23,6 +23,8 @@ import { TurboWinstonLogger } from './logger.js';
|
|
|
23
23
|
const fiveMiB = 5 * 1024 * 1024; // 5 MiB
|
|
24
24
|
const fiveHundredMiB = fiveMiB * 100; // 500 MiB
|
|
25
25
|
export const defaultMaxChunkConcurrency = 5;
|
|
26
|
+
// Limit uploaders to protect server
|
|
27
|
+
const absoluteMaxChunkConcurrency = 256;
|
|
26
28
|
export const maxChunkByteCount = fiveHundredMiB;
|
|
27
29
|
export const minChunkByteCount = fiveMiB;
|
|
28
30
|
export const defaultChunkByteCount = minChunkByteCount;
|
|
@@ -72,8 +74,9 @@ export class ChunkedUploader {
|
|
|
72
74
|
}
|
|
73
75
|
if (Number.isNaN(maxChunkConcurrency) ||
|
|
74
76
|
!Number.isInteger(maxChunkConcurrency) ||
|
|
75
|
-
maxChunkConcurrency < 1
|
|
76
|
-
|
|
77
|
+
maxChunkConcurrency < 1 ||
|
|
78
|
+
maxChunkConcurrency > absoluteMaxChunkConcurrency) {
|
|
79
|
+
throw new Error('Invalid max chunk concurrency. Must be an integer of at least 1 and at most 256.');
|
|
77
80
|
}
|
|
78
81
|
if (Number.isNaN(chunkByteCount) ||
|
|
79
82
|
!Number.isInteger(chunkByteCount) ||
|
|
@@ -206,17 +209,17 @@ export class ChunkedUploader {
|
|
|
206
209
|
async finalizeUpload(uploadId, dataItemByteCount, paidBy, signal) {
|
|
207
210
|
// Wait up to 1 minute per GiB of data for the upload to finalize
|
|
208
211
|
const fileSizeInGiB = Math.ceil(this.toGiB(dataItemByteCount));
|
|
209
|
-
const defaultMaxWaitTimeMins = fileSizeInGiB;
|
|
210
|
-
const maxWaitTimeMs = this.maxFinalizeMs ?? defaultMaxWaitTimeMins * 60 * 1000;
|
|
212
|
+
const defaultMaxWaitTimeMins = fileSizeInGiB * 2.5;
|
|
213
|
+
const maxWaitTimeMs = this.maxFinalizeMs ?? Math.floor(defaultMaxWaitTimeMins * 60 * 1000);
|
|
211
214
|
const minimumWaitPerStepMs =
|
|
212
215
|
// Per step, files smaller than 100MB will wait 2 second,
|
|
213
216
|
dataItemByteCount < 1024 * 1024 * 100
|
|
214
217
|
? 2000
|
|
215
|
-
: // files smaller than 3 GiB will wait
|
|
218
|
+
: // files smaller than 3 GiB will wait 4 seconds,
|
|
216
219
|
dataItemByteCount < 1024 * 1024 * 1024 * 3
|
|
217
|
-
?
|
|
218
|
-
: // and larger files will wait 1 second per GiB with max of
|
|
219
|
-
Math.max(
|
|
220
|
+
? 4000
|
|
221
|
+
: // and larger files will wait 1.5 second per GiB with max of 15 seconds
|
|
222
|
+
Math.max(1500 * fileSizeInGiB, 15000);
|
|
220
223
|
const paidByHeader = {};
|
|
221
224
|
if (paidBy !== undefined) {
|
|
222
225
|
paidByHeader['x-paid-by'] = Array.isArray(paidBy)
|
|
@@ -233,7 +236,7 @@ export class ChunkedUploader {
|
|
|
233
236
|
},
|
|
234
237
|
signal,
|
|
235
238
|
});
|
|
236
|
-
this.logger.debug(`Confirming upload to Turbo with uploadId ${uploadId} for up to ${
|
|
239
|
+
this.logger.debug(`Confirming upload to Turbo with uploadId ${uploadId} for up to ${maxWaitTimeMs / 1000 / 60} minutes.`);
|
|
237
240
|
const startTime = Date.now();
|
|
238
241
|
const cutoffTime = startTime + maxWaitTimeMs;
|
|
239
242
|
let attempts = 0;
|
|
@@ -264,6 +267,9 @@ export class ChunkedUploader {
|
|
|
264
267
|
if (response.status === 'UNDERFUNDED') {
|
|
265
268
|
throw new FailedRequestError(`Insufficient balance`, 402);
|
|
266
269
|
}
|
|
270
|
+
if (multipartFailedStatus.includes(response.status)) {
|
|
271
|
+
throw new FailedRequestError(`Upload failed with multi-part status ${response.status}`);
|
|
272
|
+
}
|
|
267
273
|
}
|
|
268
274
|
throw new Error(`Upload multi-part finalization has timed out for Upload ID ${uploadId}`);
|
|
269
275
|
}
|
package/lib/esm/common/http.js
CHANGED
|
@@ -14,27 +14,34 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
import { AxiosError, CanceledError } from 'axios';
|
|
17
|
-
import {
|
|
17
|
+
import { Readable } from 'node:stream';
|
|
18
|
+
import { createAxiosInstance, defaultRetryConfig, } from '../utils/axiosClient.js';
|
|
19
|
+
import { sleep } from '../utils/common.js';
|
|
18
20
|
import { FailedRequestError } from '../utils/errors.js';
|
|
19
21
|
export class TurboHTTPService {
|
|
20
|
-
constructor({ url,
|
|
22
|
+
constructor({ url, logger, retryConfig = defaultRetryConfig(logger), }) {
|
|
21
23
|
this.logger = logger;
|
|
22
24
|
this.axios = createAxiosInstance({
|
|
23
25
|
axiosConfig: {
|
|
24
26
|
baseURL: url,
|
|
25
27
|
maxRedirects: 0, // prevents backpressure issues when uploading larger streams via https
|
|
26
28
|
},
|
|
27
|
-
retryConfig,
|
|
28
29
|
logger: this.logger,
|
|
29
30
|
});
|
|
31
|
+
this.retryConfig = retryConfig;
|
|
30
32
|
}
|
|
31
33
|
async get({ endpoint, signal, allowedStatuses = [200, 202], headers, }) {
|
|
32
|
-
return this.
|
|
34
|
+
return this.retryRequest(() => this.axios.get(endpoint, { headers, signal }), allowedStatuses);
|
|
33
35
|
}
|
|
34
36
|
async post({ endpoint, signal, allowedStatuses = [200, 202], headers, data, }) {
|
|
35
37
|
// Buffer and Readable → keep Axios (streams work fine there)
|
|
36
38
|
if (!(data instanceof ReadableStream)) {
|
|
37
|
-
|
|
39
|
+
if (data instanceof Readable) {
|
|
40
|
+
return this.tryRequest(
|
|
41
|
+
// Can't retry a Readable stream that has already been partially consumed
|
|
42
|
+
() => this.axios.post(endpoint, data, { headers, signal }), allowedStatuses);
|
|
43
|
+
}
|
|
44
|
+
return this.retryRequest(() => this.axios.post(endpoint, data, { headers, signal }), allowedStatuses);
|
|
38
45
|
}
|
|
39
46
|
// Browser ReadableStream → use fetch with progressive enhancement of duplex
|
|
40
47
|
// Note: fetch does not support streams in Safari and Firefox, so we convert to Blob
|
|
@@ -92,6 +99,34 @@ export class TurboHTTPService {
|
|
|
92
99
|
throw error;
|
|
93
100
|
}
|
|
94
101
|
}
|
|
102
|
+
async retryRequest(request, allowedStatuses) {
|
|
103
|
+
let attempt = 0;
|
|
104
|
+
let lastError;
|
|
105
|
+
while (attempt < this.retryConfig.retries) {
|
|
106
|
+
try {
|
|
107
|
+
const resp = await this.tryRequest(request, allowedStatuses);
|
|
108
|
+
return resp;
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
if (error instanceof FailedRequestError) {
|
|
112
|
+
lastError = error;
|
|
113
|
+
this.retryConfig.onRetry(attempt + 1, error);
|
|
114
|
+
if (error.status !== undefined &&
|
|
115
|
+
error.status >= 400 &&
|
|
116
|
+
error.status < 500) {
|
|
117
|
+
// If it's a client error, we can stop retrying
|
|
118
|
+
throw error;
|
|
119
|
+
}
|
|
120
|
+
await sleep(this.retryConfig.retryDelay(attempt + 1));
|
|
121
|
+
attempt++;
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
throw error;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
throw new FailedRequestError('Max retries reached - ' + lastError?.message, lastError?.status);
|
|
129
|
+
}
|
|
95
130
|
}
|
|
96
131
|
async function toFetchBody(data) {
|
|
97
132
|
if (!navigator.userAgent.includes('Firefox') &&
|
|
@@ -14,13 +14,14 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
import { BigNumber } from 'bignumber.js';
|
|
17
|
+
import { defaultRetryConfig } from '../utils/axiosClient.js';
|
|
17
18
|
import { TurboHTTPService } from './http.js';
|
|
18
19
|
import { TurboWinstonLogger } from './logger.js';
|
|
19
20
|
import { exponentMap, tokenToBaseMap } from './token/index.js';
|
|
20
21
|
export const developmentPaymentServiceURL = 'https://payment.ardrive.dev';
|
|
21
22
|
export const defaultPaymentServiceURL = 'https://payment.ardrive.io';
|
|
22
23
|
export class TurboUnauthenticatedPaymentService {
|
|
23
|
-
constructor({ url = defaultPaymentServiceURL,
|
|
24
|
+
constructor({ url = defaultPaymentServiceURL, logger = TurboWinstonLogger.default, retryConfig = defaultRetryConfig(logger), token = 'arweave', }) {
|
|
24
25
|
this.logger = logger;
|
|
25
26
|
this.httpService = new TurboHTTPService({
|
|
26
27
|
url: `${url}/v1`,
|
package/lib/esm/common/upload.js
CHANGED
|
@@ -231,10 +231,7 @@ export class TurboAuthenticatedBaseUploadService extends TurboUnauthenticatedUpl
|
|
|
231
231
|
resolve();
|
|
232
232
|
});
|
|
233
233
|
});
|
|
234
|
-
await Promise.race([
|
|
235
|
-
sleep(retryDelay(retries, error)),
|
|
236
|
-
abortEventPromise,
|
|
237
|
-
]);
|
|
234
|
+
await Promise.race([sleep(retryDelay(retries)), abortEventPromise]);
|
|
238
235
|
}
|
|
239
236
|
}
|
|
240
237
|
const msg = `Failed to upload file after ${retries + 1} attempts\n${lastError instanceof Error ? lastError.message : lastError}`;
|
|
@@ -13,8 +13,7 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
import axios
|
|
17
|
-
import axiosRetry from 'axios-retry';
|
|
16
|
+
import axios from 'axios';
|
|
18
17
|
import { TurboWinstonLogger } from '../common/logger.js';
|
|
19
18
|
import { version } from '../version.js';
|
|
20
19
|
export const defaultRequestHeaders = {
|
|
@@ -22,18 +21,13 @@ export const defaultRequestHeaders = {
|
|
|
22
21
|
'x-turbo-source-identifier': 'turbo-sdk',
|
|
23
22
|
};
|
|
24
23
|
export const defaultRetryConfig = (logger = TurboWinstonLogger.default) => ({
|
|
25
|
-
retryDelay:
|
|
24
|
+
retryDelay: (retryCount) => Math.min(1000 * 2 ** (retryCount - 1), 30 * 1000), // exponential backoff up to 30s
|
|
26
25
|
retries: 5,
|
|
27
|
-
retryCondition: (error) => {
|
|
28
|
-
return (!(error instanceof CanceledError) &&
|
|
29
|
-
axiosRetry.isIdempotentRequestError(error) &&
|
|
30
|
-
axiosRetry.isNetworkError(error));
|
|
31
|
-
},
|
|
32
26
|
onRetry: (retryCount, error) => {
|
|
33
27
|
logger.debug(`Request failed, ${error}. Retry attempt #${retryCount}...`);
|
|
34
28
|
},
|
|
35
29
|
});
|
|
36
|
-
export const createAxiosInstance = ({
|
|
30
|
+
export const createAxiosInstance = ({ axiosConfig = {}, } = {}) => {
|
|
37
31
|
const axiosInstance = axios.create({
|
|
38
32
|
...axiosConfig,
|
|
39
33
|
headers: {
|
|
@@ -43,10 +37,5 @@ export const createAxiosInstance = ({ logger = TurboWinstonLogger.default, axios
|
|
|
43
37
|
adapter: 'fetch',
|
|
44
38
|
validateStatus: () => true, // don't throw on non-200 status codes
|
|
45
39
|
});
|
|
46
|
-
if (retryConfig.retries !== undefined && retryConfig.retries > 0) {
|
|
47
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
48
|
-
// @ts-ignore
|
|
49
|
-
axiosRetry(axiosInstance, retryConfig);
|
|
50
|
-
}
|
|
51
40
|
return axiosInstance;
|
|
52
41
|
};
|
package/lib/esm/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chunked.d.ts","sourceRoot":"","sources":["../../../src/common/chunked.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAElC,OAAO,EACL,SAAS,
|
|
1
|
+
{"version":3,"file":"chunked.d.ts","sourceRoot":"","sources":["../../../src/common/chunked.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAElC,OAAO,EACL,SAAS,EAET,iBAAiB,EACjB,WAAW,EAEX,2BAA2B,EAC3B,0BAA0B,EAG3B,MAAM,aAAa,CAAC;AAIrB,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAK7C,eAAO,MAAM,0BAA0B,IAAI,CAAC;AAK5C,eAAO,MAAM,iBAAiB,QAAiB,CAAC;AAChD,eAAO,MAAM,iBAAiB,QAAU,CAAC;AACzC,eAAO,MAAM,qBAAqB,QAAoB,CAAC;AAKvD;;;GAGG;AACH,qBAAa,eAAe;IAC1B,OAAO,CAAC,cAAc,CAAS;IAC/B,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAS;IAC7C,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAqB;IACnD,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAmB;IACxC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAS;IAC/B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAc;IAErC,SAAgB,sBAAsB,EAAE,OAAO,CAAC;IAChD,OAAO,CAAC,eAAe,CAAS;gBAEpB,EACV,IAAI,EACJ,KAAK,EACL,mBAAgD,EAChD,aAAa,EACb,cAAsC,EACtC,MAAmC,EACnC,YAAqB,EACrB,iBAAiB,GAClB,EAAE;QACD,aAAa,CAAC,EAAE,MAAM,CAAC;QACvB,IAAI,EAAE,gBAAgB,CAAC;QACvB,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,EAAE,WAAW,CAAC;QACpB,cAAc,CAAC,EAAE,MAAM,CAAC;QACxB,mBAAmB,CAAC,EAAE,MAAM,CAAC;QAC7B,YAAY,CAAC,EAAE,iBAAiB,CAAC;QACjC,iBAAiB,EAAE,SAAS,CAAC;KAC9B;IAqBD,OAAO,CAAC,iBAAiB;IAoBzB,OAAO,CAAC,iBAAiB;IAwDzB;;OAEG;YACW,UAAU;IAqBX,MAAM,CAAC,EAClB,mBAAmB,EACnB,qBAAqB,EACrB,YAAY,EACZ,MAAM,EACN,MAAM,GACP,EAAE,0BAA0B,GAAG,OAAO,CAAC,2BAA2B,CAAC;IAwHpE,OAAO,CAAC,KAAK;YAIC,cAAc;CAoG7B;AAED;;;GAGG;AACH,wBAAuB,eAAe,CACpC,MAAM,EAAE,QAAQ,GAAG,cAAc,CAAC,UAAU,CAAC,EAC7C,cAAc,EAAE,MAAM,GACrB,cAAc,CAAC,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC,CAMvC;AACD,wBAAuB,uBAAuB,CAC5C,MAAM,EAAE,QAAQ,EAChB,cAAc,EAAE,MAAM,GACrB,cAAc,CAAC,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC,CAkDvC;AAED,wBAAuB,6BAA6B,CAClD,MAAM,EAAE,cAAc,CAAC,UAAU,CAAC,EAClC,cAAc,EAAE,MAAM,GACrB,cAAc,CAAC,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC,CAyDvC"}
|
|
@@ -14,15 +14,16 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
import { AxiosInstance } from 'axios';
|
|
17
|
-
import { IAxiosRetryConfig } from 'axios-retry';
|
|
18
17
|
import { Readable } from 'node:stream';
|
|
19
18
|
import { TurboHTTPServiceInterface, TurboLogger, TurboSignedRequestHeaders } from '../types.js';
|
|
19
|
+
import { RetryConfig } from '../utils/axiosClient.js';
|
|
20
20
|
export declare class TurboHTTPService implements TurboHTTPServiceInterface {
|
|
21
21
|
protected axios: AxiosInstance;
|
|
22
22
|
protected logger: TurboLogger;
|
|
23
|
-
|
|
23
|
+
protected retryConfig: RetryConfig;
|
|
24
|
+
constructor({ url, logger, retryConfig, }: {
|
|
24
25
|
url: string;
|
|
25
|
-
retryConfig
|
|
26
|
+
retryConfig: RetryConfig;
|
|
26
27
|
logger: TurboLogger;
|
|
27
28
|
});
|
|
28
29
|
get<T>({ endpoint, signal, allowedStatuses, headers, }: {
|
|
@@ -39,5 +40,6 @@ export declare class TurboHTTPService implements TurboHTTPServiceInterface {
|
|
|
39
40
|
data: Readable | Buffer | ReadableStream | Uint8Array;
|
|
40
41
|
}): Promise<T>;
|
|
41
42
|
private tryRequest;
|
|
43
|
+
private retryRequest;
|
|
42
44
|
}
|
|
43
45
|
//# sourceMappingURL=http.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../../src/common/http.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAc,aAAa,EAAgC,MAAM,OAAO,CAAC;AAChF,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../../src/common/http.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAc,aAAa,EAAgC,MAAM,OAAO,CAAC;AAChF,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,OAAO,EACL,yBAAyB,EACzB,WAAW,EACX,yBAAyB,EAC1B,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,WAAW,EAGZ,MAAM,yBAAyB,CAAC;AAIjC,qBAAa,gBAAiB,YAAW,yBAAyB;IAChE,SAAS,CAAC,KAAK,EAAE,aAAa,CAAC;IAC/B,SAAS,CAAC,MAAM,EAAE,WAAW,CAAC;IAC9B,SAAS,CAAC,WAAW,EAAE,WAAW,CAAC;gBAEvB,EACV,GAAG,EACH,MAAM,EACN,WAAwC,GACzC,EAAE;QACD,GAAG,EAAE,MAAM,CAAC;QACZ,WAAW,EAAE,WAAW,CAAC;QACzB,MAAM,EAAE,WAAW,CAAC;KACrB;IAYK,GAAG,CAAC,CAAC,EAAE,EACX,QAAQ,EACR,MAAM,EACN,eAA4B,EAC5B,OAAO,GACR,EAAE;QACD,QAAQ,EAAE,MAAM,CAAC;QACjB,MAAM,CAAC,EAAE,WAAW,CAAC;QACrB,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;QAC3B,OAAO,CAAC,EAAE,OAAO,CAAC,yBAAyB,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;KACvE,GAAG,OAAO,CAAC,CAAC,CAAC;IAOR,IAAI,CAAC,CAAC,EAAE,EACZ,QAAQ,EACR,MAAM,EACN,eAA4B,EAC5B,OAAO,EACP,IAAI,GACL,EAAE;QACD,QAAQ,EAAE,MAAM,CAAC;QACjB,MAAM,CAAC,EAAE,WAAW,CAAC;QACrB,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;QAC3B,OAAO,CAAC,EAAE,OAAO,CAAC,yBAAyB,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACtE,IAAI,EAAE,QAAQ,GAAG,MAAM,GAAG,cAAc,GAAG,UAAU,CAAC;KACvD,GAAG,OAAO,CAAC,CAAC,CAAC;YA2DA,UAAU;YA2BV,YAAY;CAqC3B"}
|
|
@@ -6,7 +6,7 @@ export declare class TurboUnauthenticatedPaymentService implements TurboUnauthen
|
|
|
6
6
|
protected readonly httpService: TurboHTTPService;
|
|
7
7
|
protected logger: TurboLogger;
|
|
8
8
|
protected readonly token: TokenType;
|
|
9
|
-
constructor({ url,
|
|
9
|
+
constructor({ url, logger, retryConfig, token, }: TurboUnauthenticatedPaymentServiceConfiguration);
|
|
10
10
|
getBalance(address: string): Promise<TurboBalanceResponse>;
|
|
11
11
|
getFiatRates(): Promise<TurboRatesResponse>;
|
|
12
12
|
getFiatToAR({ currency, }: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"payment.d.ts","sourceRoot":"","sources":["../../../src/common/payment.ts"],"names":[],"mappings":"AAiBA,OAAO,EACL,QAAQ,EACR,+BAA+B,EAE/B,UAAU,EACV,SAAS,EAET,6CAA6C,EAC7C,yCAAyC,EACzC,oBAAoB,EACpB,0BAA0B,EAC1B,4BAA4B,EAC5B,sBAAsB,EACtB,uBAAuB,EACvB,uBAAuB,EACvB,mBAAmB,EACnB,iCAAiC,EACjC,qBAAqB,EACrB,yBAAyB,EAEzB,WAAW,EACX,wBAAwB,EACxB,0BAA0B,EAE1B,kBAAkB,EAClB,kBAAkB,EAClB,yBAAyB,EACzB,yBAAyB,EACzB,+BAA+B,EAC/B,+CAA+C,EAC/C,2CAA2C,EAC3C,sBAAsB,EACtB,wBAAwB,EACxB,uBAAuB,EACvB,yBAAyB,EACzB,WAAW,EACZ,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"payment.d.ts","sourceRoot":"","sources":["../../../src/common/payment.ts"],"names":[],"mappings":"AAiBA,OAAO,EACL,QAAQ,EACR,+BAA+B,EAE/B,UAAU,EACV,SAAS,EAET,6CAA6C,EAC7C,yCAAyC,EACzC,oBAAoB,EACpB,0BAA0B,EAC1B,4BAA4B,EAC5B,sBAAsB,EACtB,uBAAuB,EACvB,uBAAuB,EACvB,mBAAmB,EACnB,iCAAiC,EACjC,qBAAqB,EACrB,yBAAyB,EAEzB,WAAW,EACX,wBAAwB,EACxB,0BAA0B,EAE1B,kBAAkB,EAClB,kBAAkB,EAClB,yBAAyB,EACzB,yBAAyB,EACzB,+BAA+B,EAC/B,+CAA+C,EAC/C,2CAA2C,EAC3C,sBAAsB,EACtB,wBAAwB,EACxB,uBAAuB,EACvB,yBAAyB,EACzB,WAAW,EACZ,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,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MAAM,CAAC;KACtB,GAAG,OAAO,CAAC,+BAA+B,CAAC;IAK/B,cAAc,CAAC,EAC1B,MAAM,EACN,UAAe,GAChB,EAAE,sBAAsB,GAAG,OAAO,CAAC,wBAAwB,CAAC;IAQhD,qBAAqB,CAChC,MAAM,EAAE,0BAA0B,GACjC,OAAO,CAAC,4BAA4B,CAAC;YAI1B,sBAAsB;IAYvB,eAAe,CAAC,EAC3B,aAAiB,EACjB,WAAW,EAAE,YAAY,GAC1B,EAAE,yBAAyB,GAAG,OAAO,CAAC,uBAAuB,CAAC;CA+ChE"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { IAxiosRetryConfig } from 'axios-retry';
|
|
2
1
|
import { Readable } from 'node:stream';
|
|
3
2
|
import { ArweaveManifest, CreditShareApproval, TokenType, TurboAbortSignal, TurboAuthenticatedUploadServiceConfiguration, TurboAuthenticatedUploadServiceInterface, TurboChunkingParams, TurboCreateCreditShareApprovalParams, TurboDataItemSigner, TurboFileFactory, TurboLogger, TurboRevokeCreditsParams, TurboUnauthenticatedUploadServiceConfiguration, TurboUnauthenticatedUploadServiceInterface, TurboUploadAndSigningEmitterEvents, TurboUploadDataItemResponse, TurboUploadEmitterEvents, TurboUploadFileParams, TurboUploadFolderParams, TurboUploadFolderResponse, UploadDataInput, UploadSignedDataItemParams } from '../types.js';
|
|
3
|
+
import { RetryConfig } from '../utils/axiosClient.js';
|
|
4
4
|
import { TurboHTTPService } from './http.js';
|
|
5
5
|
export type TurboUploadConfig = TurboFileFactory & TurboAbortSignal & TurboUploadEmitterEvents;
|
|
6
6
|
export declare const creditSharingTagNames: {
|
|
@@ -15,7 +15,7 @@ export declare class TurboUnauthenticatedUploadService implements TurboUnauthent
|
|
|
15
15
|
protected httpService: TurboHTTPService;
|
|
16
16
|
protected logger: TurboLogger;
|
|
17
17
|
protected token: TokenType;
|
|
18
|
-
protected retryConfig:
|
|
18
|
+
protected retryConfig: RetryConfig;
|
|
19
19
|
constructor({ url, logger, retryConfig, token, }: TurboUnauthenticatedUploadServiceConfiguration);
|
|
20
20
|
uploadSignedDataItem({ dataItemStreamFactory, dataItemSizeFactory, dataItemOpts, signal, events, }: UploadSignedDataItemParams): Promise<TurboUploadDataItemResponse>;
|
|
21
21
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upload.d.ts","sourceRoot":"","sources":["../../../src/common/upload.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"upload.d.ts","sourceRoot":"","sources":["../../../src/common/upload.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAGvC,OAAO,EACL,eAAe,EACf,mBAAmB,EAEnB,SAAS,EACT,gBAAgB,EAChB,4CAA4C,EAC5C,wCAAwC,EACxC,mBAAmB,EACnB,oCAAoC,EACpC,mBAAmB,EACnB,gBAAgB,EAChB,WAAW,EACX,wBAAwB,EACxB,8CAA8C,EAC9C,0CAA0C,EAC1C,kCAAkC,EAClC,2BAA2B,EAC3B,wBAAwB,EACxB,qBAAqB,EAGrB,uBAAuB,EACvB,yBAAyB,EACzB,eAAe,EACf,0BAA0B,EAC3B,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,WAAW,EAAsB,MAAM,yBAAyB,CAAC;AAK1E,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAG7C,MAAM,MAAM,iBAAiB,GAAG,gBAAgB,GAC9C,gBAAgB,GAChB,wBAAwB,CAAC;AAc3B,eAAO,MAAM,qBAAqB;;;;;CAKjC,CAAC;AAEF,eAAO,MAAM,2BAA2B,+BAA+B,CAAC;AACxE,eAAO,MAAM,uBAAuB,8BAA8B,CAAC;AAEnE,qBAAa,iCACX,YAAW,0CAA0C;IAErD,SAAS,CAAC,WAAW,EAAE,gBAAgB,CAAC;IACxC,SAAS,CAAC,MAAM,EAAE,WAAW,CAAC;IAC9B,SAAS,CAAC,KAAK,EAAE,SAAS,C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AQ,CAAC,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,QAAQ,GAAG,cAAc;IAC7E,QAAQ,CAAC,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM;IACjD,QAAQ,CAAC,eAAe,CACtB,IAAI,EAAE,MAAM,GAAG,IAAI,EACnB,MAAM,EAAE,uBAAuB,GAC9B,MAAM;IACT,QAAQ,CAAC,oBAAoB,CAC3B,cAAc,EAAE,MAAM,GACrB,QAAQ,GAAG,cAAc;IAE5B,OAAO,CAAC,cAAc;IActB;;;;;;;;OAQG;IACG,YAAY,CAChB,MAAM,EAAE,uBAAuB,GAC9B,OAAO,CAAC,yBAAyB,CAAC;IAkHxB,YAAY,CAAC,EACxB,eAAe,EACf,kBAAkB,EAClB,gBAAgB,GACjB,EAAE,oCAAoC,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAqCzD,aAAa,CAAC,EACzB,cAAc,GACf,EAAE,wBAAwB,GAAG,OAAO,CAAC,mBAAmB,EAAE,CAAC;CAwB7D"}
|
package/lib/types/types.d.ts
CHANGED
|
@@ -14,7 +14,6 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
import { ArconnectSigner, ArweaveSigner, DataItemCreateOptions, EthereumSigner, HexInjectedSolanaSigner, HexSolanaSigner, InjectedEthereumSigner } from '@dha-team/arbundles';
|
|
17
|
-
import { IAxiosRetryConfig } from 'axios-retry';
|
|
18
17
|
import { BigNumber } from 'bignumber.js';
|
|
19
18
|
import { JsonRpcSigner } from 'ethers';
|
|
20
19
|
import { Readable } from 'node:stream';
|
|
@@ -22,6 +21,7 @@ import { CurrencyMap } from './common/currency.js';
|
|
|
22
21
|
import { TurboEventEmitter } from './common/events.js';
|
|
23
22
|
import { JWKInterface } from './common/jwk.js';
|
|
24
23
|
import { TurboWinstonLogger } from './common/logger.js';
|
|
24
|
+
import { RetryConfig } from './utils/axiosClient.js';
|
|
25
25
|
export type Base64String = string;
|
|
26
26
|
export type NativeAddress = string;
|
|
27
27
|
export type ByteCount = number;
|
|
@@ -320,7 +320,7 @@ type TurboAuthConfiguration = {
|
|
|
320
320
|
};
|
|
321
321
|
type TurboServiceConfiguration = {
|
|
322
322
|
url?: string;
|
|
323
|
-
retryConfig?:
|
|
323
|
+
retryConfig?: RetryConfig;
|
|
324
324
|
logger?: TurboLogger;
|
|
325
325
|
token?: TokenType;
|
|
326
326
|
};
|