@ar.io/sdk 3.22.0-alpha.5 → 3.22.0-alpha.6
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 +0 -47
- package/bundles/web.bundle.min.js +70 -75
- package/lib/cjs/common/turbo.js +24 -14
- package/lib/cjs/utils/processes.js +8 -9
- package/lib/cjs/version.js +1 -1
- package/lib/esm/common/turbo.js +23 -13
- package/lib/esm/utils/processes.js +8 -9
- package/lib/esm/version.js +1 -1
- package/lib/types/common/turbo.d.ts +5 -7
- package/lib/types/utils/processes.d.ts +4 -3
- package/lib/types/version.d.ts +1 -1
- package/package.json +4 -16
- package/lib/cjs/common/http.js +0 -40
- package/lib/cjs/utils/http-client.js +0 -48
- package/lib/esm/common/http.js +0 -36
- package/lib/esm/utils/http-client.js +0 -41
- package/lib/types/common/http.d.ts +0 -17
- package/lib/types/utils/http-client.d.ts +0 -24
package/lib/cjs/common/turbo.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TurboArNSPaymentProviderAuthenticated = exports.TurboArNSPaymentProviderUnauthenticated = exports.TurboArNSPaymentFactory = void 0;
|
|
3
|
+
exports.TurboArNSPaymentProviderAuthenticated = exports.TurboArNSPaymentProviderUnauthenticated = exports.TurboArNSPaymentFactory = exports.defaultHeaders = void 0;
|
|
4
4
|
exports.signedRequestHeadersFromSigner = signedRequestHeadersFromSigner;
|
|
5
5
|
exports.isTurboArNSSigner = isTurboArNSSigner;
|
|
6
6
|
/**
|
|
@@ -19,13 +19,16 @@ exports.isTurboArNSSigner = isTurboArNSSigner;
|
|
|
19
19
|
* limitations under the License.
|
|
20
20
|
*/
|
|
21
21
|
const arbundles_1 = require("@dha-team/arbundles");
|
|
22
|
-
const uuid_1 = require("uuid");
|
|
23
22
|
const token_js_1 = require("../types/token.js");
|
|
24
23
|
const base64_js_1 = require("../utils/base64.js");
|
|
25
|
-
const http_client_js_1 = require("../utils/http-client.js");
|
|
26
24
|
const url_js_1 = require("../utils/url.js");
|
|
25
|
+
const version_js_1 = require("../version.js");
|
|
27
26
|
const logger_js_1 = require("./logger.js");
|
|
28
|
-
|
|
27
|
+
exports.defaultHeaders = {
|
|
28
|
+
'x-source-version': `${version_js_1.version}`,
|
|
29
|
+
'x-source-identifier': 'ar-io-sdk',
|
|
30
|
+
};
|
|
31
|
+
async function signedRequestHeadersFromSigner({ signer, nonce = crypto.randomUUID(), }) {
|
|
29
32
|
let signature = undefined;
|
|
30
33
|
let publicKey = undefined;
|
|
31
34
|
const signatureType = isWanderArweaveBrowserSigner(signer)
|
|
@@ -85,18 +88,16 @@ async function signedRequestHeadersFromSigner({ signer, nonce = (0, uuid_1.v4)()
|
|
|
85
88
|
}
|
|
86
89
|
class TurboArNSPaymentFactory {
|
|
87
90
|
static init(config) {
|
|
88
|
-
const { signer, paymentUrl,
|
|
91
|
+
const { signer, paymentUrl, logger } = config ?? {};
|
|
89
92
|
if (signer !== undefined) {
|
|
90
93
|
return new TurboArNSPaymentProviderAuthenticated({
|
|
91
94
|
signer,
|
|
92
95
|
paymentUrl,
|
|
93
|
-
axios,
|
|
94
96
|
logger,
|
|
95
97
|
});
|
|
96
98
|
}
|
|
97
99
|
return new TurboArNSPaymentProviderUnauthenticated({
|
|
98
100
|
paymentUrl,
|
|
99
|
-
axios,
|
|
100
101
|
logger,
|
|
101
102
|
});
|
|
102
103
|
}
|
|
@@ -105,11 +106,9 @@ exports.TurboArNSPaymentFactory = TurboArNSPaymentFactory;
|
|
|
105
106
|
// Base class for unauthenticated operations
|
|
106
107
|
class TurboArNSPaymentProviderUnauthenticated {
|
|
107
108
|
paymentUrl;
|
|
108
|
-
axios;
|
|
109
109
|
logger;
|
|
110
|
-
constructor({ paymentUrl = 'https://payment.ardrive.io',
|
|
110
|
+
constructor({ paymentUrl = 'https://payment.ardrive.io', logger = logger_js_1.Logger.default, }) {
|
|
111
111
|
this.paymentUrl = paymentUrl;
|
|
112
|
-
this.axios = axios;
|
|
113
112
|
this.logger = logger;
|
|
114
113
|
}
|
|
115
114
|
async getArNSPriceDetails({ intent, name, quantity, type, years, }) {
|
|
@@ -121,7 +120,12 @@ class TurboArNSPaymentProviderUnauthenticated {
|
|
|
121
120
|
years,
|
|
122
121
|
},
|
|
123
122
|
});
|
|
124
|
-
const
|
|
123
|
+
const response = await fetch(url, {
|
|
124
|
+
method: 'GET',
|
|
125
|
+
headers: exports.defaultHeaders,
|
|
126
|
+
});
|
|
127
|
+
const status = response.status;
|
|
128
|
+
const data = (await response.json());
|
|
125
129
|
this.logger.debug('getArNSPriceDetails', {
|
|
126
130
|
intent,
|
|
127
131
|
name,
|
|
@@ -171,12 +175,18 @@ class TurboArNSPaymentProviderAuthenticated extends TurboArNSPaymentProviderUnau
|
|
|
171
175
|
referrer,
|
|
172
176
|
},
|
|
173
177
|
});
|
|
174
|
-
const
|
|
178
|
+
const signedHeaders = await signedRequestHeadersFromSigner({
|
|
175
179
|
signer: this.signer,
|
|
176
180
|
});
|
|
177
|
-
const
|
|
178
|
-
|
|
181
|
+
const response = await fetch(url, {
|
|
182
|
+
method: 'POST',
|
|
183
|
+
headers: {
|
|
184
|
+
...exports.defaultHeaders,
|
|
185
|
+
...signedHeaders,
|
|
186
|
+
},
|
|
179
187
|
});
|
|
188
|
+
const status = response.status;
|
|
189
|
+
const data = (await response.json());
|
|
180
190
|
this.logger.debug('Initiated ArNS purchase', {
|
|
181
191
|
intent,
|
|
182
192
|
name,
|
|
@@ -18,7 +18,6 @@ exports.fetchAllArNSRecords = exports.ArNSEventEmitter = exports.getANTProcesses
|
|
|
18
18
|
*/
|
|
19
19
|
const aoconnect_1 = require("@permaweb/aoconnect");
|
|
20
20
|
const eventemitter3_1 = require("eventemitter3");
|
|
21
|
-
const plimit_lit_1 = require("plimit-lit");
|
|
22
21
|
const ant_registry_js_1 = require("../common/ant-registry.js");
|
|
23
22
|
const ant_js_1 = require("../common/ant.js");
|
|
24
23
|
const index_js_1 = require("../common/index.js");
|
|
@@ -49,22 +48,23 @@ function timeout(ms, promise) {
|
|
|
49
48
|
});
|
|
50
49
|
});
|
|
51
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* @deprecated This is an inefficient way to get ArNS records for a wallet address. Use getArNSRecordsForAddress instead.
|
|
53
|
+
*/
|
|
52
54
|
class ArNSEventEmitter extends eventemitter3_1.EventEmitter {
|
|
53
55
|
contract;
|
|
54
|
-
timeoutMs;
|
|
55
|
-
throttle;
|
|
56
|
+
timeoutMs;
|
|
56
57
|
logger;
|
|
57
58
|
strict;
|
|
58
59
|
antAoClient;
|
|
59
60
|
constructor({ contract = io_js_1.ARIO.init({
|
|
60
61
|
processId: constants_js_1.ARIO_MAINNET_PROCESS_ID,
|
|
61
|
-
}), timeoutMs = 60_000,
|
|
62
|
+
}), timeoutMs = 60_000, logger = logger_js_1.Logger.default, strict = false, antAoClient = (0, aoconnect_1.connect)({
|
|
62
63
|
MODE: 'legacy',
|
|
63
64
|
}), } = {}) {
|
|
64
65
|
super();
|
|
65
66
|
this.contract = contract;
|
|
66
67
|
this.timeoutMs = timeoutMs;
|
|
67
|
-
this.throttle = (0, plimit_lit_1.pLimit)(concurrency);
|
|
68
68
|
this.logger = logger;
|
|
69
69
|
this.strict = strict;
|
|
70
70
|
this.antAoClient = antAoClient;
|
|
@@ -99,7 +99,7 @@ class ArNSEventEmitter extends eventemitter3_1.EventEmitter {
|
|
|
99
99
|
const idCount = Object.keys(uniqueContractProcessIds).length;
|
|
100
100
|
this.emit('progress', 0, idCount);
|
|
101
101
|
// check the contract owner and controllers
|
|
102
|
-
await Promise.all(Object.keys(uniqueContractProcessIds).map(async (processId, i) =>
|
|
102
|
+
await Promise.all(Object.keys(uniqueContractProcessIds).map(async (processId, i) => {
|
|
103
103
|
if (uniqueContractProcessIds[processId].state !== undefined) {
|
|
104
104
|
this.emit('progress', i + 1, idCount);
|
|
105
105
|
return;
|
|
@@ -115,13 +115,12 @@ class ArNSEventEmitter extends eventemitter3_1.EventEmitter {
|
|
|
115
115
|
this.emit('error', `Error getting state for process ${processId}: ${e}`);
|
|
116
116
|
return undefined;
|
|
117
117
|
}));
|
|
118
|
-
if (state?.Owner === address ||
|
|
119
|
-
state?.Controllers.includes(address)) {
|
|
118
|
+
if (state?.Owner === address || state?.Controllers.includes(address)) {
|
|
120
119
|
uniqueContractProcessIds[processId].state = state;
|
|
121
120
|
this.emit('process', processId, uniqueContractProcessIds[processId]);
|
|
122
121
|
}
|
|
123
122
|
this.emit('progress', i + 1, idCount);
|
|
124
|
-
}))
|
|
123
|
+
}));
|
|
125
124
|
this.emit('end', uniqueContractProcessIds);
|
|
126
125
|
}
|
|
127
126
|
}
|
package/lib/cjs/version.js
CHANGED
package/lib/esm/common/turbo.js
CHANGED
|
@@ -14,13 +14,16 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
import { ArconnectSigner, ArweaveSigner, EthereumSigner, InjectedEthereumSigner, SignatureConfig, } from '@dha-team/arbundles';
|
|
17
|
-
import { v4 as uuidv4 } from 'uuid';
|
|
18
17
|
import { mARIOToken } from '../types/token.js';
|
|
19
18
|
import { toB64Url } from '../utils/base64.js';
|
|
20
|
-
import { createAxiosInstance } from '../utils/http-client.js';
|
|
21
19
|
import { urlWithSearchParams } from '../utils/url.js';
|
|
20
|
+
import { version } from '../version.js';
|
|
22
21
|
import { Logger } from './logger.js';
|
|
23
|
-
export
|
|
22
|
+
export const defaultHeaders = {
|
|
23
|
+
'x-source-version': `${version}`,
|
|
24
|
+
'x-source-identifier': 'ar-io-sdk',
|
|
25
|
+
};
|
|
26
|
+
export async function signedRequestHeadersFromSigner({ signer, nonce = crypto.randomUUID(), }) {
|
|
24
27
|
let signature = undefined;
|
|
25
28
|
let publicKey = undefined;
|
|
26
29
|
const signatureType = isWanderArweaveBrowserSigner(signer)
|
|
@@ -80,18 +83,16 @@ export async function signedRequestHeadersFromSigner({ signer, nonce = uuidv4(),
|
|
|
80
83
|
}
|
|
81
84
|
export class TurboArNSPaymentFactory {
|
|
82
85
|
static init(config) {
|
|
83
|
-
const { signer, paymentUrl,
|
|
86
|
+
const { signer, paymentUrl, logger } = config ?? {};
|
|
84
87
|
if (signer !== undefined) {
|
|
85
88
|
return new TurboArNSPaymentProviderAuthenticated({
|
|
86
89
|
signer,
|
|
87
90
|
paymentUrl,
|
|
88
|
-
axios,
|
|
89
91
|
logger,
|
|
90
92
|
});
|
|
91
93
|
}
|
|
92
94
|
return new TurboArNSPaymentProviderUnauthenticated({
|
|
93
95
|
paymentUrl,
|
|
94
|
-
axios,
|
|
95
96
|
logger,
|
|
96
97
|
});
|
|
97
98
|
}
|
|
@@ -99,11 +100,9 @@ export class TurboArNSPaymentFactory {
|
|
|
99
100
|
// Base class for unauthenticated operations
|
|
100
101
|
export class TurboArNSPaymentProviderUnauthenticated {
|
|
101
102
|
paymentUrl;
|
|
102
|
-
axios;
|
|
103
103
|
logger;
|
|
104
|
-
constructor({ paymentUrl = 'https://payment.ardrive.io',
|
|
104
|
+
constructor({ paymentUrl = 'https://payment.ardrive.io', logger = Logger.default, }) {
|
|
105
105
|
this.paymentUrl = paymentUrl;
|
|
106
|
-
this.axios = axios;
|
|
107
106
|
this.logger = logger;
|
|
108
107
|
}
|
|
109
108
|
async getArNSPriceDetails({ intent, name, quantity, type, years, }) {
|
|
@@ -115,7 +114,12 @@ export class TurboArNSPaymentProviderUnauthenticated {
|
|
|
115
114
|
years,
|
|
116
115
|
},
|
|
117
116
|
});
|
|
118
|
-
const
|
|
117
|
+
const response = await fetch(url, {
|
|
118
|
+
method: 'GET',
|
|
119
|
+
headers: defaultHeaders,
|
|
120
|
+
});
|
|
121
|
+
const status = response.status;
|
|
122
|
+
const data = (await response.json());
|
|
119
123
|
this.logger.debug('getArNSPriceDetails', {
|
|
120
124
|
intent,
|
|
121
125
|
name,
|
|
@@ -164,12 +168,18 @@ export class TurboArNSPaymentProviderAuthenticated extends TurboArNSPaymentProvi
|
|
|
164
168
|
referrer,
|
|
165
169
|
},
|
|
166
170
|
});
|
|
167
|
-
const
|
|
171
|
+
const signedHeaders = await signedRequestHeadersFromSigner({
|
|
168
172
|
signer: this.signer,
|
|
169
173
|
});
|
|
170
|
-
const
|
|
171
|
-
|
|
174
|
+
const response = await fetch(url, {
|
|
175
|
+
method: 'POST',
|
|
176
|
+
headers: {
|
|
177
|
+
...defaultHeaders,
|
|
178
|
+
...signedHeaders,
|
|
179
|
+
},
|
|
172
180
|
});
|
|
181
|
+
const status = response.status;
|
|
182
|
+
const data = (await response.json());
|
|
173
183
|
this.logger.debug('Initiated ArNS purchase', {
|
|
174
184
|
intent,
|
|
175
185
|
name,
|
|
@@ -15,7 +15,6 @@
|
|
|
15
15
|
*/
|
|
16
16
|
import { connect } from '@permaweb/aoconnect';
|
|
17
17
|
import { EventEmitter } from 'eventemitter3';
|
|
18
|
-
import { pLimit } from 'plimit-lit';
|
|
19
18
|
import { ANTRegistry } from '../common/ant-registry.js';
|
|
20
19
|
import { ANT } from '../common/ant.js';
|
|
21
20
|
import { AOProcess } from '../common/index.js';
|
|
@@ -45,22 +44,23 @@ function timeout(ms, promise) {
|
|
|
45
44
|
});
|
|
46
45
|
});
|
|
47
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* @deprecated This is an inefficient way to get ArNS records for a wallet address. Use getArNSRecordsForAddress instead.
|
|
49
|
+
*/
|
|
48
50
|
export class ArNSEventEmitter extends EventEmitter {
|
|
49
51
|
contract;
|
|
50
|
-
timeoutMs;
|
|
51
|
-
throttle;
|
|
52
|
+
timeoutMs;
|
|
52
53
|
logger;
|
|
53
54
|
strict;
|
|
54
55
|
antAoClient;
|
|
55
56
|
constructor({ contract = ARIO.init({
|
|
56
57
|
processId: ARIO_MAINNET_PROCESS_ID,
|
|
57
|
-
}), timeoutMs = 60_000,
|
|
58
|
+
}), timeoutMs = 60_000, logger = Logger.default, strict = false, antAoClient = connect({
|
|
58
59
|
MODE: 'legacy',
|
|
59
60
|
}), } = {}) {
|
|
60
61
|
super();
|
|
61
62
|
this.contract = contract;
|
|
62
63
|
this.timeoutMs = timeoutMs;
|
|
63
|
-
this.throttle = pLimit(concurrency);
|
|
64
64
|
this.logger = logger;
|
|
65
65
|
this.strict = strict;
|
|
66
66
|
this.antAoClient = antAoClient;
|
|
@@ -95,7 +95,7 @@ export class ArNSEventEmitter extends EventEmitter {
|
|
|
95
95
|
const idCount = Object.keys(uniqueContractProcessIds).length;
|
|
96
96
|
this.emit('progress', 0, idCount);
|
|
97
97
|
// check the contract owner and controllers
|
|
98
|
-
await Promise.all(Object.keys(uniqueContractProcessIds).map(async (processId, i) =>
|
|
98
|
+
await Promise.all(Object.keys(uniqueContractProcessIds).map(async (processId, i) => {
|
|
99
99
|
if (uniqueContractProcessIds[processId].state !== undefined) {
|
|
100
100
|
this.emit('progress', i + 1, idCount);
|
|
101
101
|
return;
|
|
@@ -111,13 +111,12 @@ export class ArNSEventEmitter extends EventEmitter {
|
|
|
111
111
|
this.emit('error', `Error getting state for process ${processId}: ${e}`);
|
|
112
112
|
return undefined;
|
|
113
113
|
}));
|
|
114
|
-
if (state?.Owner === address ||
|
|
115
|
-
state?.Controllers.includes(address)) {
|
|
114
|
+
if (state?.Owner === address || state?.Controllers.includes(address)) {
|
|
116
115
|
uniqueContractProcessIds[processId].state = state;
|
|
117
116
|
this.emit('process', processId, uniqueContractProcessIds[processId]);
|
|
118
117
|
}
|
|
119
118
|
this.emit('progress', i + 1, idCount);
|
|
120
|
-
}))
|
|
119
|
+
}));
|
|
121
120
|
this.emit('end', uniqueContractProcessIds);
|
|
122
121
|
}
|
|
123
122
|
}
|
package/lib/esm/version.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { AxiosInstance, RawAxiosRequestHeaders } from 'axios';
|
|
2
1
|
import { AoMessageResult, TransactionId, TurboArNSSigner } from '../types/common.js';
|
|
3
2
|
import { AoTokenCostParams } from '../types/io.js';
|
|
4
3
|
import { mARIOToken } from '../types/token.js';
|
|
@@ -6,15 +5,15 @@ import { ILogger } from './logger.js';
|
|
|
6
5
|
export interface TurboUnauthenticatedConfig {
|
|
7
6
|
paymentUrl?: string;
|
|
8
7
|
logger?: ILogger;
|
|
9
|
-
axios?: AxiosInstance;
|
|
10
8
|
}
|
|
11
9
|
export interface TurboAuthenticatedConfig extends TurboUnauthenticatedConfig {
|
|
12
10
|
signer: TurboArNSSigner;
|
|
13
11
|
}
|
|
12
|
+
export declare const defaultHeaders: Record<string, string>;
|
|
14
13
|
export declare function signedRequestHeadersFromSigner({ signer, nonce, }: {
|
|
15
14
|
signer: TurboArNSSigner;
|
|
16
15
|
nonce?: string;
|
|
17
|
-
}): Promise<
|
|
16
|
+
}): Promise<Record<string, string>>;
|
|
18
17
|
export type ArNSPurchaseReceipt = AoTokenCostParams & {
|
|
19
18
|
wincQty: string;
|
|
20
19
|
mARIOQty: string;
|
|
@@ -39,16 +38,15 @@ export interface ArNSAuthenticatedPaymentProvider extends ArNSPaymentProvider {
|
|
|
39
38
|
}
|
|
40
39
|
export declare class TurboArNSPaymentFactory {
|
|
41
40
|
static init(): TurboArNSPaymentProviderUnauthenticated;
|
|
42
|
-
static init({ paymentUrl,
|
|
41
|
+
static init({ paymentUrl, logger, }: TurboUnauthenticatedConfig & {
|
|
43
42
|
signer?: TurboArNSSigner;
|
|
44
43
|
}): TurboArNSPaymentProviderUnauthenticated;
|
|
45
|
-
static init({ signer, paymentUrl,
|
|
44
|
+
static init({ signer, paymentUrl, logger, }: TurboAuthenticatedConfig): TurboArNSPaymentProviderAuthenticated;
|
|
46
45
|
}
|
|
47
46
|
export declare class TurboArNSPaymentProviderUnauthenticated implements ArNSPaymentProvider {
|
|
48
47
|
protected readonly paymentUrl: string;
|
|
49
|
-
protected readonly axios: AxiosInstance;
|
|
50
48
|
protected readonly logger: ILogger;
|
|
51
|
-
constructor({ paymentUrl,
|
|
49
|
+
constructor({ paymentUrl, logger, }: TurboUnauthenticatedConfig);
|
|
52
50
|
getArNSPriceDetails({ intent, name, quantity, type, years, }: AoTokenCostParams): Promise<{
|
|
53
51
|
winc: string;
|
|
54
52
|
mARIO: mARIOToken;
|
|
@@ -9,17 +9,18 @@ export declare const getANTProcessesOwnedByWallet: ({ address, registry, }: {
|
|
|
9
9
|
address: WalletAddress;
|
|
10
10
|
registry?: AoANTRegistryRead;
|
|
11
11
|
}) => Promise<ProcessId[]>;
|
|
12
|
+
/**
|
|
13
|
+
* @deprecated This is an inefficient way to get ArNS records for a wallet address. Use getArNSRecordsForAddress instead.
|
|
14
|
+
*/
|
|
12
15
|
export declare class ArNSEventEmitter extends EventEmitter {
|
|
13
16
|
protected contract: AoARIORead;
|
|
14
17
|
private timeoutMs;
|
|
15
|
-
private throttle;
|
|
16
18
|
private logger;
|
|
17
19
|
private strict;
|
|
18
20
|
private antAoClient;
|
|
19
|
-
constructor({ contract, timeoutMs,
|
|
21
|
+
constructor({ contract, timeoutMs, logger, strict, antAoClient, }?: {
|
|
20
22
|
contract?: AoARIORead;
|
|
21
23
|
timeoutMs?: number;
|
|
22
|
-
concurrency?: number;
|
|
23
24
|
logger?: ILogger;
|
|
24
25
|
strict?: boolean;
|
|
25
26
|
antAoClient?: AoClient;
|
package/lib/types/version.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ar.io/sdk",
|
|
3
|
-
"version": "3.22.0-alpha.
|
|
3
|
+
"version": "3.22.0-alpha.6",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/ar-io/ar-io-sdk.git"
|
|
@@ -100,10 +100,11 @@
|
|
|
100
100
|
"@typescript-eslint/eslint-plugin": "^5.62.0",
|
|
101
101
|
"@typescript-eslint/parser": "^6.4.0",
|
|
102
102
|
"arconnect": "^1.0.3",
|
|
103
|
+
"axios": "^1.13.2",
|
|
103
104
|
"c8": "^10.1.3",
|
|
104
105
|
"dotenv": "^16.4.5",
|
|
105
106
|
"dotenv-cli": "^7.4.2",
|
|
106
|
-
"esbuild": "^0.
|
|
107
|
+
"esbuild": "^0.27.0",
|
|
107
108
|
"esbuild-plugin-polyfill-node": "^0.3.0",
|
|
108
109
|
"eslint": "^8.47.0",
|
|
109
110
|
"eslint-config-prettier": "^9.0.0",
|
|
@@ -131,22 +132,9 @@
|
|
|
131
132
|
"@dha-team/arbundles": "^1.0.1",
|
|
132
133
|
"@permaweb/aoconnect": "0.0.68",
|
|
133
134
|
"arweave": "1.15.5",
|
|
134
|
-
"axios": "1.12.0",
|
|
135
|
-
"axios-retry": "^4.3.0",
|
|
136
135
|
"commander": "^12.1.0",
|
|
137
136
|
"eventemitter3": "^5.0.1",
|
|
138
|
-
"
|
|
139
|
-
"prompts": "^2.4.2",
|
|
140
|
-
"uuid": "^11.1.0",
|
|
141
|
-
"zod": "^3.23.8"
|
|
142
|
-
},
|
|
143
|
-
"peerDependencies": {
|
|
144
|
-
"winston": "^3.13.0"
|
|
145
|
-
},
|
|
146
|
-
"peerDependenciesMeta": {
|
|
147
|
-
"winston": {
|
|
148
|
-
"optional": true
|
|
149
|
-
}
|
|
137
|
+
"prompts": "^2.4.2"
|
|
150
138
|
},
|
|
151
139
|
"lint-staged": {
|
|
152
140
|
"**/*.{ts,js,mjs,cjs,md,json}": [
|
package/lib/cjs/common/http.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AxiosHTTPService = void 0;
|
|
4
|
-
const http_client_js_1 = require("../utils/http-client.js");
|
|
5
|
-
const error_js_1 = require("./error.js");
|
|
6
|
-
const logger_js_1 = require("./logger.js");
|
|
7
|
-
class AxiosHTTPService {
|
|
8
|
-
axios;
|
|
9
|
-
logger;
|
|
10
|
-
constructor({ url, logger = logger_js_1.Logger.default, }) {
|
|
11
|
-
this.logger = logger;
|
|
12
|
-
this.axios = (0, http_client_js_1.createAxiosInstance)({
|
|
13
|
-
axiosConfig: {
|
|
14
|
-
baseURL: url,
|
|
15
|
-
},
|
|
16
|
-
logger: this.logger,
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
async get({ endpoint, signal, allowedStatuses = [200, 202], headers, params, }) {
|
|
20
|
-
this.logger.debug(`Get request to endpoint: ${endpoint} with params ${JSON.stringify(params, undefined, 2)}`);
|
|
21
|
-
const { status, statusText, data } = await this.axios.get(endpoint, {
|
|
22
|
-
headers,
|
|
23
|
-
signal,
|
|
24
|
-
params,
|
|
25
|
-
});
|
|
26
|
-
this.logger.debug(`Response status: ${status} ${statusText}`);
|
|
27
|
-
if (!allowedStatuses.includes(status)) {
|
|
28
|
-
switch (status) {
|
|
29
|
-
case 404:
|
|
30
|
-
throw new error_js_1.NotFound(statusText);
|
|
31
|
-
case 400:
|
|
32
|
-
throw new error_js_1.FailedRequestError(status, statusText);
|
|
33
|
-
default:
|
|
34
|
-
throw new error_js_1.UnknownError(statusText);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
return data;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
exports.AxiosHTTPService = AxiosHTTPService;
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.createAxiosInstance = void 0;
|
|
7
|
-
/**
|
|
8
|
-
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
|
|
9
|
-
*
|
|
10
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
11
|
-
* you may not use this file except in compliance with the License.
|
|
12
|
-
* You may obtain a copy of the License at
|
|
13
|
-
*
|
|
14
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
15
|
-
*
|
|
16
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
17
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
18
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
19
|
-
* See the License for the specific language governing permissions and
|
|
20
|
-
* limitations under the License.
|
|
21
|
-
*/
|
|
22
|
-
const axios_1 = __importDefault(require("axios"));
|
|
23
|
-
const axios_retry_1 = __importDefault(require("axios-retry"));
|
|
24
|
-
const logger_js_1 = require("../common/logger.js");
|
|
25
|
-
const version_js_1 = require("../version.js");
|
|
26
|
-
const createAxiosInstance = ({ axiosConfig = {}, logger = logger_js_1.Logger.default, retryConfig = {
|
|
27
|
-
retries: 5,
|
|
28
|
-
retryDelay: axios_retry_1.default.exponentialDelay,
|
|
29
|
-
retryCondition: (error) => axios_retry_1.default.isRetryableError(error),
|
|
30
|
-
onRetry(retryCount, error, requestConfig) {
|
|
31
|
-
logger.error(`Retrying request ${requestConfig.url} attempt ${retryCount}`, error);
|
|
32
|
-
},
|
|
33
|
-
}, } = {}) => {
|
|
34
|
-
const axiosInstance = axios_1.default.create({
|
|
35
|
-
...axiosConfig,
|
|
36
|
-
maxRedirects: 0,
|
|
37
|
-
headers: {
|
|
38
|
-
...axiosConfig.headers,
|
|
39
|
-
'x-source-version': `${version_js_1.version}`,
|
|
40
|
-
'x-source-identifier': 'ar-io-sdk',
|
|
41
|
-
},
|
|
42
|
-
validateStatus: () => true, // don't throw on non-200 status codes
|
|
43
|
-
});
|
|
44
|
-
// add retries
|
|
45
|
-
(0, axios_retry_1.default)(axiosInstance, retryConfig);
|
|
46
|
-
return axiosInstance;
|
|
47
|
-
};
|
|
48
|
-
exports.createAxiosInstance = createAxiosInstance;
|
package/lib/esm/common/http.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { createAxiosInstance } from '../utils/http-client.js';
|
|
2
|
-
import { FailedRequestError, NotFound, UnknownError } from './error.js';
|
|
3
|
-
import { Logger } from './logger.js';
|
|
4
|
-
export class AxiosHTTPService {
|
|
5
|
-
axios;
|
|
6
|
-
logger;
|
|
7
|
-
constructor({ url, logger = Logger.default, }) {
|
|
8
|
-
this.logger = logger;
|
|
9
|
-
this.axios = createAxiosInstance({
|
|
10
|
-
axiosConfig: {
|
|
11
|
-
baseURL: url,
|
|
12
|
-
},
|
|
13
|
-
logger: this.logger,
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
async get({ endpoint, signal, allowedStatuses = [200, 202], headers, params, }) {
|
|
17
|
-
this.logger.debug(`Get request to endpoint: ${endpoint} with params ${JSON.stringify(params, undefined, 2)}`);
|
|
18
|
-
const { status, statusText, data } = await this.axios.get(endpoint, {
|
|
19
|
-
headers,
|
|
20
|
-
signal,
|
|
21
|
-
params,
|
|
22
|
-
});
|
|
23
|
-
this.logger.debug(`Response status: ${status} ${statusText}`);
|
|
24
|
-
if (!allowedStatuses.includes(status)) {
|
|
25
|
-
switch (status) {
|
|
26
|
-
case 404:
|
|
27
|
-
throw new NotFound(statusText);
|
|
28
|
-
case 400:
|
|
29
|
-
throw new FailedRequestError(status, statusText);
|
|
30
|
-
default:
|
|
31
|
-
throw new UnknownError(statusText);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
return data;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
* you may not use this file except in compliance with the License.
|
|
6
|
-
* You may obtain a copy of the License at
|
|
7
|
-
*
|
|
8
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
*
|
|
10
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
* See the License for the specific language governing permissions and
|
|
14
|
-
* limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
import axios from 'axios';
|
|
17
|
-
import axiosRetry from 'axios-retry';
|
|
18
|
-
import { Logger } from '../common/logger.js';
|
|
19
|
-
import { version } from '../version.js';
|
|
20
|
-
export const createAxiosInstance = ({ axiosConfig = {}, logger = Logger.default, retryConfig = {
|
|
21
|
-
retries: 5,
|
|
22
|
-
retryDelay: axiosRetry.exponentialDelay,
|
|
23
|
-
retryCondition: (error) => axiosRetry.isRetryableError(error),
|
|
24
|
-
onRetry(retryCount, error, requestConfig) {
|
|
25
|
-
logger.error(`Retrying request ${requestConfig.url} attempt ${retryCount}`, error);
|
|
26
|
-
},
|
|
27
|
-
}, } = {}) => {
|
|
28
|
-
const axiosInstance = axios.create({
|
|
29
|
-
...axiosConfig,
|
|
30
|
-
maxRedirects: 0,
|
|
31
|
-
headers: {
|
|
32
|
-
...axiosConfig.headers,
|
|
33
|
-
'x-source-version': `${version}`,
|
|
34
|
-
'x-source-identifier': 'ar-io-sdk',
|
|
35
|
-
},
|
|
36
|
-
validateStatus: () => true, // don't throw on non-200 status codes
|
|
37
|
-
});
|
|
38
|
-
// add retries
|
|
39
|
-
axiosRetry(axiosInstance, retryConfig);
|
|
40
|
-
return axiosInstance;
|
|
41
|
-
};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { HTTPClient } from '../types/index.js';
|
|
2
|
-
import { ILogger } from './logger.js';
|
|
3
|
-
export declare class AxiosHTTPService implements HTTPClient {
|
|
4
|
-
private axios;
|
|
5
|
-
private logger;
|
|
6
|
-
constructor({ url, logger, }: {
|
|
7
|
-
url: string;
|
|
8
|
-
logger?: ILogger;
|
|
9
|
-
});
|
|
10
|
-
get<I, K>({ endpoint, signal, allowedStatuses, headers, params, }: {
|
|
11
|
-
endpoint: string;
|
|
12
|
-
signal?: AbortSignal;
|
|
13
|
-
allowedStatuses?: number[];
|
|
14
|
-
headers?: Record<string, string>;
|
|
15
|
-
params?: I;
|
|
16
|
-
}): Promise<K>;
|
|
17
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
* you may not use this file except in compliance with the License.
|
|
6
|
-
* You may obtain a copy of the License at
|
|
7
|
-
*
|
|
8
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
*
|
|
10
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
* See the License for the specific language governing permissions and
|
|
14
|
-
* limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
import { AxiosInstance, AxiosRequestConfig } from 'axios';
|
|
17
|
-
import { IAxiosRetryConfig } from 'axios-retry';
|
|
18
|
-
import { ILogger } from '../common/logger.js';
|
|
19
|
-
export interface AxiosInstanceParameters {
|
|
20
|
-
axiosConfig?: Omit<AxiosRequestConfig, 'validateStatus'>;
|
|
21
|
-
retryConfig?: IAxiosRetryConfig;
|
|
22
|
-
logger?: ILogger;
|
|
23
|
-
}
|
|
24
|
-
export declare const createAxiosInstance: ({ axiosConfig, logger, retryConfig, }?: AxiosInstanceParameters) => AxiosInstance;
|