@ar.io/sdk 3.11.0-alpha.5 → 3.11.0-alpha.7
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/bundles/web.bundle.min.js +61 -61
- package/lib/cjs/common/io.js +12 -3
- package/lib/cjs/common/wayfinder/gateways.js +19 -8
- package/lib/cjs/common/wayfinder/index.js +1 -1
- package/lib/cjs/common/wayfinder/routers/priority.js +11 -20
- package/lib/cjs/common/wayfinder/routers/priority.test.js +5 -5
- package/lib/cjs/common/wayfinder/routers/random.js +2 -2
- package/lib/cjs/common/wayfinder/routers/random.test.js +5 -84
- package/lib/cjs/common/wayfinder/routers/{fixed.js → static.js} +5 -5
- package/lib/cjs/common/wayfinder/routers/{fixed.test.js → static.test.js} +4 -4
- package/lib/cjs/common/wayfinder/wayfinder.js +2 -2
- package/lib/cjs/common/wayfinder/wayfinder.test.js +36 -48
- package/lib/cjs/utils/arweave.js +1 -1
- package/lib/cjs/version.js +1 -1
- package/lib/esm/common/io.js +12 -3
- package/lib/esm/common/wayfinder/gateways.js +17 -6
- package/lib/esm/common/wayfinder/index.js +1 -1
- package/lib/esm/common/wayfinder/routers/priority.js +11 -20
- package/lib/esm/common/wayfinder/routers/priority.test.js +5 -5
- package/lib/esm/common/wayfinder/routers/random.js +2 -2
- package/lib/esm/common/wayfinder/routers/random.test.js +5 -84
- package/lib/esm/common/wayfinder/routers/{fixed.js → static.js} +3 -3
- package/lib/esm/common/wayfinder/routers/{fixed.test.js → static.test.js} +4 -4
- package/lib/esm/common/wayfinder/wayfinder.js +3 -3
- package/lib/esm/common/wayfinder/wayfinder.test.js +36 -48
- package/lib/esm/utils/arweave.js +1 -1
- package/lib/esm/version.js +1 -1
- package/lib/types/common/io.d.ts +2 -6
- package/lib/types/common/wayfinder/gateways.d.ts +16 -7
- package/lib/types/common/wayfinder/index.d.ts +1 -1
- package/lib/types/common/wayfinder/routers/priority.d.ts +8 -12
- package/lib/types/common/wayfinder/routers/{fixed.d.ts → static.d.ts} +3 -3
- package/lib/types/version.d.ts +1 -1
- package/package.json +1 -1
- package/lib/cjs/cli/wayfinder.js +0 -34
- package/lib/esm/cli/wayfinder.js +0 -32
- package/lib/types/common/wayfinder/routers/fixed.test.d.ts +0 -1
- /package/lib/types/{cli/wayfinder.d.ts → common/wayfinder/routers/static.test.d.ts} +0 -0
package/lib/cjs/common/io.js
CHANGED
|
@@ -51,6 +51,10 @@ class ARIO {
|
|
|
51
51
|
...config,
|
|
52
52
|
process: new ao_process_js_1.AOProcess({
|
|
53
53
|
processId: constants_js_1.ARIO_MAINNET_PROCESS_ID,
|
|
54
|
+
ao: (0, aoconnect_1.connect)({
|
|
55
|
+
CU_URL: 'https://cu.ardrive.io',
|
|
56
|
+
...config?.process?.ao,
|
|
57
|
+
}),
|
|
54
58
|
}),
|
|
55
59
|
});
|
|
56
60
|
}
|
|
@@ -921,7 +925,10 @@ class ARIOWriteable extends ARIOReadable {
|
|
|
921
925
|
}
|
|
922
926
|
return this.paymentProvider.initiateArNSPurchase({
|
|
923
927
|
intent: 'Buy-Name',
|
|
924
|
-
|
|
928
|
+
name: params.name,
|
|
929
|
+
years: params.years,
|
|
930
|
+
type: params.type,
|
|
931
|
+
processId: params.processId,
|
|
925
932
|
});
|
|
926
933
|
}
|
|
927
934
|
const { tags = [] } = options || {};
|
|
@@ -985,7 +992,8 @@ class ARIOWriteable extends ARIOReadable {
|
|
|
985
992
|
}
|
|
986
993
|
return this.paymentProvider.initiateArNSPurchase({
|
|
987
994
|
intent: 'Extend-Lease',
|
|
988
|
-
|
|
995
|
+
name: params.name,
|
|
996
|
+
years: params.years,
|
|
989
997
|
});
|
|
990
998
|
}
|
|
991
999
|
const { tags = [] } = options || {};
|
|
@@ -1008,7 +1016,8 @@ class ARIOWriteable extends ARIOReadable {
|
|
|
1008
1016
|
}
|
|
1009
1017
|
return this.paymentProvider.initiateArNSPurchase({
|
|
1010
1018
|
intent: 'Increase-Undername-Limit',
|
|
1011
|
-
|
|
1019
|
+
quantity: params.increaseCount,
|
|
1020
|
+
name: params.name,
|
|
1012
1021
|
});
|
|
1013
1022
|
}
|
|
1014
1023
|
const { tags = [] } = options || {};
|
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SimpleCacheGatewaysProvider = exports.StaticGatewaysProvider = exports.
|
|
4
|
-
class
|
|
3
|
+
exports.SimpleCacheGatewaysProvider = exports.StaticGatewaysProvider = exports.NetworkGatewaysProvider = void 0;
|
|
4
|
+
class NetworkGatewaysProvider {
|
|
5
5
|
ario;
|
|
6
|
-
|
|
6
|
+
sortBy;
|
|
7
|
+
sortOrder;
|
|
8
|
+
limit;
|
|
9
|
+
filter;
|
|
10
|
+
constructor({ ario, sortBy = 'operatorStake', sortOrder = 'desc', limit = 1000, filter = (g) => g.status === 'joined', }) {
|
|
7
11
|
this.ario = ario;
|
|
12
|
+
this.sortBy = sortBy;
|
|
13
|
+
this.sortOrder = sortOrder;
|
|
14
|
+
this.limit = limit;
|
|
15
|
+
this.filter = filter;
|
|
8
16
|
}
|
|
9
17
|
async getGateways() {
|
|
10
18
|
let cursor;
|
|
@@ -12,9 +20,11 @@ class ARIOGatewaysProvider {
|
|
|
12
20
|
const gateways = [];
|
|
13
21
|
do {
|
|
14
22
|
try {
|
|
15
|
-
const { items: newGateways, nextCursor } = await this.ario.getGateways({
|
|
23
|
+
const { items: newGateways = [], nextCursor } = await this.ario.getGateways({
|
|
16
24
|
limit: 1000,
|
|
17
25
|
cursor,
|
|
26
|
+
sortBy: this.sortBy,
|
|
27
|
+
sortOrder: this.sortOrder,
|
|
18
28
|
});
|
|
19
29
|
gateways.push(...newGateways);
|
|
20
30
|
cursor = nextCursor;
|
|
@@ -30,14 +40,15 @@ class ARIOGatewaysProvider {
|
|
|
30
40
|
}
|
|
31
41
|
} while (cursor !== undefined && attempts < 3);
|
|
32
42
|
// filter out any gateways that are not joined
|
|
33
|
-
|
|
43
|
+
const filteredGateways = gateways.filter(this.filter).slice(0, this.limit);
|
|
44
|
+
return filteredGateways.map((g) => new URL(`${g.settings.protocol}://${g.settings.fqdn}:${g.settings.port}`));
|
|
34
45
|
}
|
|
35
46
|
}
|
|
36
|
-
exports.
|
|
47
|
+
exports.NetworkGatewaysProvider = NetworkGatewaysProvider;
|
|
37
48
|
class StaticGatewaysProvider {
|
|
38
49
|
gateways;
|
|
39
50
|
constructor({ gateways }) {
|
|
40
|
-
this.gateways = gateways;
|
|
51
|
+
this.gateways = gateways.map((g) => new URL(g));
|
|
41
52
|
}
|
|
42
53
|
async getGateways() {
|
|
43
54
|
return this.gateways;
|
|
@@ -62,7 +73,7 @@ class SimpleCacheGatewaysProvider {
|
|
|
62
73
|
try {
|
|
63
74
|
// preserve the cache if the fetch fails
|
|
64
75
|
const allGateways = await this.gatewaysProvider.getGateways();
|
|
65
|
-
this.gatewaysCache = allGateways
|
|
76
|
+
this.gatewaysCache = allGateways;
|
|
66
77
|
this.lastUpdated = now;
|
|
67
78
|
}
|
|
68
79
|
catch (error) {
|
|
@@ -33,6 +33,6 @@ __exportStar(require("./wayfinder.js"), exports);
|
|
|
33
33
|
// routers
|
|
34
34
|
__exportStar(require("./routers/random.js"), exports);
|
|
35
35
|
__exportStar(require("./routers/priority.js"), exports);
|
|
36
|
-
__exportStar(require("./routers/
|
|
36
|
+
__exportStar(require("./routers/static.js"), exports);
|
|
37
37
|
// gateways providers
|
|
38
38
|
__exportStar(require("./gateways.js"), exports);
|
|
@@ -2,37 +2,28 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PriorityGatewayRouter = void 0;
|
|
4
4
|
const random_js_1 = require("../../../utils/random.js");
|
|
5
|
+
const gateways_js_1 = require("../gateways.js");
|
|
5
6
|
// TODO: one of N where N are in the last time window have met certain performance thresholds
|
|
6
7
|
// TODO: look at bitorrent routing protocols for inspiration
|
|
7
8
|
// TODO: router that looks at local stats/metrics and adjusts based on those
|
|
8
9
|
class PriorityGatewayRouter {
|
|
9
10
|
name = 'priority';
|
|
10
11
|
gatewaysProvider;
|
|
11
|
-
limit
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
this.sortBy = sortBy;
|
|
19
|
-
this.sortOrder = sortOrder;
|
|
20
|
-
this.blocklist = blocklist;
|
|
12
|
+
constructor({ ario, sortBy, sortOrder, limit, }) {
|
|
13
|
+
this.gatewaysProvider = new gateways_js_1.NetworkGatewaysProvider({
|
|
14
|
+
ario,
|
|
15
|
+
sortBy,
|
|
16
|
+
sortOrder,
|
|
17
|
+
limit,
|
|
18
|
+
});
|
|
21
19
|
}
|
|
22
20
|
async getTargetGateway() {
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
!this.blocklist.includes(gateway.settings.fqdn));
|
|
26
|
-
const sortedGateways = gateways
|
|
27
|
-
.sort(this.sortOrder === 'asc'
|
|
28
|
-
? (a, b) => a[this.sortBy] - b[this.sortBy]
|
|
29
|
-
: (a, b) => b[this.sortBy] - a[this.sortBy])
|
|
30
|
-
.slice(0, this.limit);
|
|
31
|
-
const targetGateway = sortedGateways[(0, random_js_1.randomInt)(0, sortedGateways.length)];
|
|
21
|
+
const gateways = await this.gatewaysProvider.getGateways();
|
|
22
|
+
const targetGateway = gateways[(0, random_js_1.randomInt)(0, gateways.length)];
|
|
32
23
|
if (targetGateway === undefined) {
|
|
33
24
|
throw new Error('No target gateway found');
|
|
34
25
|
}
|
|
35
|
-
return
|
|
26
|
+
return targetGateway;
|
|
36
27
|
}
|
|
37
28
|
}
|
|
38
29
|
exports.PriorityGatewayRouter = PriorityGatewayRouter;
|
|
@@ -129,13 +129,13 @@ const priority_js_1 = require("./priority.js");
|
|
|
129
129
|
},
|
|
130
130
|
},
|
|
131
131
|
];
|
|
132
|
-
const
|
|
133
|
-
getGateways: async () => mockGateways,
|
|
132
|
+
const mockArIOClient = {
|
|
133
|
+
getGateways: async () => ({ items: mockGateways }),
|
|
134
134
|
};
|
|
135
135
|
(0, node_test_1.it)('should prioritize gateway with highest success rate when using successRate weight', async () => {
|
|
136
136
|
const router = new priority_js_1.PriorityGatewayRouter({
|
|
137
|
-
|
|
138
|
-
sortBy: '
|
|
137
|
+
ario: mockArIOClient,
|
|
138
|
+
sortBy: 'operatorStake',
|
|
139
139
|
sortOrder: 'desc',
|
|
140
140
|
limit: 1,
|
|
141
141
|
});
|
|
@@ -144,7 +144,7 @@ const priority_js_1 = require("./priority.js");
|
|
|
144
144
|
});
|
|
145
145
|
(0, node_test_1.it)('should prioritize gateway with lowest latency when using latency weight', async () => {
|
|
146
146
|
const router = new priority_js_1.PriorityGatewayRouter({
|
|
147
|
-
|
|
147
|
+
ario: mockArIOClient,
|
|
148
148
|
sortBy: 'operatorStake',
|
|
149
149
|
sortOrder: 'desc',
|
|
150
150
|
limit: 1,
|
|
@@ -12,12 +12,12 @@ class RandomGatewayRouter {
|
|
|
12
12
|
}
|
|
13
13
|
async getTargetGateway() {
|
|
14
14
|
const allGateways = await this.gatewaysProvider.getGateways();
|
|
15
|
-
const gateways = allGateways.filter((g) =>
|
|
15
|
+
const gateways = allGateways.filter((g) => !this.blocklist.includes(g.hostname));
|
|
16
16
|
const targetGateway = gateways[(0, random_js_1.randomInt)(0, gateways.length)];
|
|
17
17
|
if (targetGateway === undefined) {
|
|
18
18
|
throw new Error('No target gateway found');
|
|
19
19
|
}
|
|
20
|
-
return
|
|
20
|
+
return targetGateway;
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
exports.RandomGatewayRouter = RandomGatewayRouter;
|
|
@@ -5,88 +5,9 @@ const node_test_1 = require("node:test");
|
|
|
5
5
|
const random_js_1 = require("./random.js");
|
|
6
6
|
(0, node_test_1.describe)('RandomRouter', () => {
|
|
7
7
|
const mockGateways = [
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
port: 443,
|
|
12
|
-
protocol: 'https',
|
|
13
|
-
allowDelegatedStaking: false,
|
|
14
|
-
delegateRewardShareRatio: 0.5,
|
|
15
|
-
allowedDelegates: [],
|
|
16
|
-
minDelegatedStake: 0,
|
|
17
|
-
autoStake: false,
|
|
18
|
-
properties: '',
|
|
19
|
-
label: '',
|
|
20
|
-
note: '',
|
|
21
|
-
},
|
|
22
|
-
gatewayAddress: 'addr1',
|
|
23
|
-
observerAddress: 'addr1',
|
|
24
|
-
totalDelegatedStake: 1000,
|
|
25
|
-
startTimestamp: 0,
|
|
26
|
-
endTimestamp: 0,
|
|
27
|
-
operatorStake: 100,
|
|
28
|
-
status: 'joined',
|
|
29
|
-
weights: {
|
|
30
|
-
normalizedCompositeWeight: 0.5,
|
|
31
|
-
stakeWeight: 0.5,
|
|
32
|
-
tenureWeight: 0.5,
|
|
33
|
-
gatewayPerformanceRatio: 0.5,
|
|
34
|
-
observerPerformanceRatio: 0.5,
|
|
35
|
-
compositeWeight: 0.5,
|
|
36
|
-
gatewayRewardRatioWeight: 0.5,
|
|
37
|
-
observerRewardRatioWeight: 0.5,
|
|
38
|
-
},
|
|
39
|
-
stats: {
|
|
40
|
-
passedConsecutiveEpochs: 10,
|
|
41
|
-
failedConsecutiveEpochs: 5,
|
|
42
|
-
totalEpochCount: 15,
|
|
43
|
-
passedEpochCount: 10,
|
|
44
|
-
failedEpochCount: 5,
|
|
45
|
-
observedEpochCount: 15,
|
|
46
|
-
prescribedEpochCount: 20,
|
|
47
|
-
},
|
|
48
|
-
},
|
|
49
|
-
{
|
|
50
|
-
settings: {
|
|
51
|
-
fqdn: 'gateway2.net',
|
|
52
|
-
port: 443,
|
|
53
|
-
protocol: 'https',
|
|
54
|
-
allowDelegatedStaking: false,
|
|
55
|
-
delegateRewardShareRatio: 0.5,
|
|
56
|
-
allowedDelegates: [],
|
|
57
|
-
minDelegatedStake: 0,
|
|
58
|
-
autoStake: false,
|
|
59
|
-
properties: '',
|
|
60
|
-
label: '',
|
|
61
|
-
note: '',
|
|
62
|
-
},
|
|
63
|
-
gatewayAddress: 'addr2',
|
|
64
|
-
observerAddress: 'addr2',
|
|
65
|
-
totalDelegatedStake: 0,
|
|
66
|
-
startTimestamp: 0,
|
|
67
|
-
endTimestamp: 0,
|
|
68
|
-
operatorStake: 0,
|
|
69
|
-
status: 'leaving',
|
|
70
|
-
weights: {
|
|
71
|
-
normalizedCompositeWeight: 0.5,
|
|
72
|
-
stakeWeight: 0.5,
|
|
73
|
-
tenureWeight: 0.5,
|
|
74
|
-
gatewayPerformanceRatio: 0.5,
|
|
75
|
-
observerPerformanceRatio: 0.5,
|
|
76
|
-
compositeWeight: 0.5,
|
|
77
|
-
gatewayRewardRatioWeight: 0.5,
|
|
78
|
-
observerRewardRatioWeight: 0.5,
|
|
79
|
-
},
|
|
80
|
-
stats: {
|
|
81
|
-
passedConsecutiveEpochs: 10,
|
|
82
|
-
failedConsecutiveEpochs: 5,
|
|
83
|
-
totalEpochCount: 15,
|
|
84
|
-
passedEpochCount: 10,
|
|
85
|
-
failedEpochCount: 5,
|
|
86
|
-
observedEpochCount: 15,
|
|
87
|
-
prescribedEpochCount: 20,
|
|
88
|
-
},
|
|
89
|
-
},
|
|
8
|
+
new URL('https://gateway1.net'),
|
|
9
|
+
new URL('https://gateway2.net'),
|
|
10
|
+
new URL('https://gateway3.net'),
|
|
90
11
|
];
|
|
91
12
|
const mockGatewaysProvider = {
|
|
92
13
|
getGateways: async () => mockGateways,
|
|
@@ -95,10 +16,10 @@ const random_js_1 = require("./random.js");
|
|
|
95
16
|
const router = new random_js_1.RandomGatewayRouter({
|
|
96
17
|
gatewaysProvider: mockGatewaysProvider,
|
|
97
18
|
});
|
|
98
|
-
//
|
|
19
|
+
// random gateway should be one of the mock gateways
|
|
99
20
|
for (let i = 0; i < 10; i++) {
|
|
100
21
|
const result = await router.getTargetGateway();
|
|
101
|
-
node_assert_1.strict.
|
|
22
|
+
node_assert_1.strict.ok(mockGateways.includes(result));
|
|
102
23
|
}
|
|
103
24
|
});
|
|
104
25
|
});
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
class
|
|
5
|
-
name = '
|
|
3
|
+
exports.StaticGatewayRouter = void 0;
|
|
4
|
+
class StaticGatewayRouter {
|
|
5
|
+
name = 'static';
|
|
6
6
|
gateway;
|
|
7
7
|
constructor({ gateway }) {
|
|
8
|
-
this.gateway = gateway;
|
|
8
|
+
this.gateway = new URL(gateway);
|
|
9
9
|
}
|
|
10
10
|
async getTargetGateway() {
|
|
11
11
|
return this.gateway;
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
|
-
exports.
|
|
14
|
+
exports.StaticGatewayRouter = StaticGatewayRouter;
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const node_assert_1 = require("node:assert");
|
|
4
4
|
const node_test_1 = require("node:test");
|
|
5
|
-
const
|
|
6
|
-
(0, node_test_1.describe)('
|
|
5
|
+
const static_js_1 = require("./static.js");
|
|
6
|
+
(0, node_test_1.describe)('StaticGatewayRouter', () => {
|
|
7
7
|
(0, node_test_1.it)('should return the provided gateway', async () => {
|
|
8
|
-
const router = new
|
|
9
|
-
gateway:
|
|
8
|
+
const router = new static_js_1.StaticGatewayRouter({
|
|
9
|
+
gateway: 'http://test-gateway.net',
|
|
10
10
|
});
|
|
11
11
|
const result = await router.getTargetGateway();
|
|
12
12
|
node_assert_1.strict.deepStrictEqual(result, new URL('http://test-gateway.net'));
|
|
@@ -7,7 +7,7 @@ const gateways_js_1 = require("./gateways.js");
|
|
|
7
7
|
const random_js_1 = require("./routers/random.js");
|
|
8
8
|
// known regexes for wayfinder urls
|
|
9
9
|
exports.arnsRegex = /^[a-z0-9_-]{1,51}$/;
|
|
10
|
-
exports.txIdRegex = /^[
|
|
10
|
+
exports.txIdRegex = /^[A-Za-z0-9_-]{43}$/;
|
|
11
11
|
/**
|
|
12
12
|
* Core function to resolve a wayfinder url against a target gateway
|
|
13
13
|
* @param originalUrl - the wayfinder url to resolve
|
|
@@ -181,7 +181,7 @@ class Wayfinder {
|
|
|
181
181
|
// TODO: consider changing router to routingStrategy or strategy
|
|
182
182
|
router = new random_js_1.RandomGatewayRouter({
|
|
183
183
|
// optionally use a cache gateways provider to reduce the number of requests to the contract
|
|
184
|
-
gatewaysProvider: new gateways_js_1.
|
|
184
|
+
gatewaysProvider: new gateways_js_1.NetworkGatewaysProvider({ ario: io_js_1.ARIO.mainnet() }),
|
|
185
185
|
}), httpClient, logger = logger_js_1.Logger.default,
|
|
186
186
|
// TODO: add verifier interface that provides a verifyDataHash function
|
|
187
187
|
// TODO: stats provider
|
|
@@ -8,23 +8,14 @@ const got_1 = __importDefault(require("got"));
|
|
|
8
8
|
const node_assert_1 = __importDefault(require("node:assert"));
|
|
9
9
|
const consumers_1 = require("node:stream/consumers");
|
|
10
10
|
const node_test_1 = require("node:test");
|
|
11
|
+
const logger_js_1 = require("../../common/logger.js");
|
|
11
12
|
const random_js_1 = require("./routers/random.js");
|
|
12
13
|
const wayfinder_js_1 = require("./wayfinder.js");
|
|
13
|
-
const
|
|
14
|
-
status: 'joined',
|
|
15
|
-
gatewayAddress: 'arweave',
|
|
16
|
-
operatorStake: 1000,
|
|
17
|
-
totalDelegatedStake: 1000,
|
|
18
|
-
startTimestamp: 1000,
|
|
19
|
-
settings: {
|
|
20
|
-
protocol: 'https',
|
|
21
|
-
fqdn: 'arweave.net',
|
|
22
|
-
port: 443,
|
|
23
|
-
},
|
|
24
|
-
};
|
|
14
|
+
const gatewayUrl = 'permagate.io';
|
|
25
15
|
const stubbedGatewaysProvider = {
|
|
26
|
-
getGateways: async () => [
|
|
16
|
+
getGateways: async () => [new URL(`https://${gatewayUrl}`)],
|
|
27
17
|
};
|
|
18
|
+
logger_js_1.Logger.default.setLogLevel('debug');
|
|
28
19
|
(0, node_test_1.describe)('Wayfinder', () => {
|
|
29
20
|
(0, node_test_1.describe)('http wrapper', () => {
|
|
30
21
|
(0, node_test_1.describe)('fetch', () => {
|
|
@@ -38,7 +29,7 @@ const stubbedGatewaysProvider = {
|
|
|
38
29
|
});
|
|
39
30
|
});
|
|
40
31
|
(0, node_test_1.it)('should fetch the data using the selected gateway', async () => {
|
|
41
|
-
const nativeFetch = await fetch(
|
|
32
|
+
const nativeFetch = await fetch(`https://ao.${gatewayUrl}`);
|
|
42
33
|
const response = await wayfinder.request('ar://ao');
|
|
43
34
|
node_assert_1.default.strictEqual(response.status, 200);
|
|
44
35
|
node_assert_1.default.strictEqual(response.status, nativeFetch.status);
|
|
@@ -46,44 +37,48 @@ const stubbedGatewaysProvider = {
|
|
|
46
37
|
const arnsHeaders = Array.from(response.headers.entries()).filter(([key]) => key.startsWith('x-arns-'));
|
|
47
38
|
const nativeFetchHeaders = Array.from(nativeFetch.headers.entries()).filter(([key]) => key.startsWith('x-arns-'));
|
|
48
39
|
node_assert_1.default.deepStrictEqual(arnsHeaders, nativeFetchHeaders);
|
|
49
|
-
|
|
40
|
+
});
|
|
41
|
+
(0, node_test_1.it)('should fetch a tx id using the selected gateway', async () => {
|
|
42
|
+
const nativeFetch = await fetch(`https://${gatewayUrl}/KKmRbIfrc7wiLcG0zvY1etlO0NBx1926dSCksxCIN3A`,
|
|
43
|
+
// follow redirects
|
|
44
|
+
{ redirect: 'follow' });
|
|
45
|
+
const response = await wayfinder.request('ar://KKmRbIfrc7wiLcG0zvY1etlO0NBx1926dSCksxCIN3A', { redirect: 'follow' });
|
|
46
|
+
node_assert_1.default.strictEqual(response.status, 200);
|
|
47
|
+
node_assert_1.default.strictEqual(response.status, nativeFetch.status);
|
|
50
48
|
});
|
|
51
49
|
(0, node_test_1.it)('should route a non-ar:// url as a normal fetch', async () => {
|
|
52
50
|
const [nativeFetch, response] = await Promise.all([
|
|
53
|
-
fetch(
|
|
51
|
+
fetch(`https://${gatewayUrl}/`, {
|
|
54
52
|
method: 'HEAD',
|
|
55
53
|
}),
|
|
56
|
-
wayfinder.request(
|
|
54
|
+
wayfinder.request(`https://${gatewayUrl}/`, {
|
|
57
55
|
method: 'HEAD',
|
|
58
56
|
}),
|
|
59
57
|
]);
|
|
60
58
|
node_assert_1.default.strictEqual(response.status, 200);
|
|
61
59
|
node_assert_1.default.strictEqual(response.status, nativeFetch.status);
|
|
62
60
|
// TODO: ensure the headers are the same excluding unique headers
|
|
63
|
-
node_assert_1.default.deepStrictEqual(await response.text(), await nativeFetch.text());
|
|
64
61
|
});
|
|
65
|
-
for (const api of ['/info', '/
|
|
62
|
+
for (const api of ['/info', '/block/current']) {
|
|
66
63
|
(0, node_test_1.it)(`supports native arweave node apis ${api}`, async () => {
|
|
67
64
|
const [nativeFetch, response] = await Promise.all([
|
|
68
|
-
fetch(`https
|
|
69
|
-
wayfinder.request(`ar
|
|
65
|
+
fetch(`https://${gatewayUrl}${api}`),
|
|
66
|
+
wayfinder.request(`ar://${api}`),
|
|
70
67
|
]);
|
|
71
68
|
node_assert_1.default.strictEqual(response.status, 200);
|
|
72
69
|
node_assert_1.default.strictEqual(response.status, nativeFetch.status);
|
|
73
70
|
// TODO: ensure the headers are the same excluding unique headers
|
|
74
|
-
node_assert_1.default.deepStrictEqual(await response.text(), await nativeFetch.text());
|
|
75
71
|
});
|
|
76
72
|
}
|
|
77
|
-
for (const api of ['/ar-io/info'
|
|
73
|
+
for (const api of ['/ar-io/info']) {
|
|
78
74
|
(0, node_test_1.it)(`supports native ario node gateway apis ${api}`, async () => {
|
|
79
75
|
const [nativeFetch, response] = await Promise.all([
|
|
80
|
-
fetch(`https
|
|
76
|
+
fetch(`https://${gatewayUrl}${api}`),
|
|
81
77
|
wayfinder.request(`ar:///${api}`),
|
|
82
78
|
]);
|
|
83
79
|
node_assert_1.default.strictEqual(response.status, 200);
|
|
84
80
|
node_assert_1.default.strictEqual(response.status, nativeFetch.status);
|
|
85
81
|
// TODO: ensure the headers are the same excluding unique headers
|
|
86
|
-
node_assert_1.default.deepStrictEqual(await response.text(), await nativeFetch.text());
|
|
87
82
|
});
|
|
88
83
|
}
|
|
89
84
|
(0, node_test_1.it)('supports a post request to graphql', async () => {
|
|
@@ -122,14 +117,13 @@ const stubbedGatewaysProvider = {
|
|
|
122
117
|
});
|
|
123
118
|
node_assert_1.default.strictEqual(response.status, 200);
|
|
124
119
|
});
|
|
125
|
-
|
|
120
|
+
node_test_1.it.skip('returns the error from the target gateway if the route is not found', async () => {
|
|
126
121
|
const [nativeFetch, response] = await Promise.all([
|
|
127
|
-
fetch(
|
|
128
|
-
wayfinder.request('
|
|
122
|
+
fetch(`https://${gatewayUrl}/ar-io/not-found`),
|
|
123
|
+
wayfinder.request('ar:///not-found'),
|
|
129
124
|
]);
|
|
130
125
|
node_assert_1.default.strictEqual(response.status, nativeFetch.status);
|
|
131
126
|
node_assert_1.default.strictEqual(response.statusText, nativeFetch.statusText);
|
|
132
|
-
node_assert_1.default.deepStrictEqual(await response.text(), await nativeFetch.text());
|
|
133
127
|
});
|
|
134
128
|
});
|
|
135
129
|
(0, node_test_1.describe)('axios', () => {
|
|
@@ -144,7 +138,7 @@ const stubbedGatewaysProvider = {
|
|
|
144
138
|
});
|
|
145
139
|
(0, node_test_1.it)('should fetch the data using axios default function against the target gateway', async () => {
|
|
146
140
|
const [nativeAxios, response] = await Promise.all([
|
|
147
|
-
(0, axios_1.default)(
|
|
141
|
+
(0, axios_1.default)(`https://ao.${gatewayUrl}`),
|
|
148
142
|
wayfinder.request('ar://ao'),
|
|
149
143
|
]);
|
|
150
144
|
node_assert_1.default.strictEqual(response.status, 200);
|
|
@@ -155,11 +149,10 @@ const stubbedGatewaysProvider = {
|
|
|
155
149
|
.filter(([key]) => key.startsWith('x-arns-'));
|
|
156
150
|
const nativeAxiosHeaders = Object.entries(nativeAxios.headers).filter(([key]) => key.startsWith('x-arns-'));
|
|
157
151
|
node_assert_1.default.deepStrictEqual(arnsHeaders.sort(), nativeAxiosHeaders.sort());
|
|
158
|
-
node_assert_1.default.deepStrictEqual(response.data, nativeAxios.data);
|
|
159
152
|
});
|
|
160
153
|
(0, node_test_1.it)('should fetch the data using the axios.get method against the target gateway', async () => {
|
|
161
154
|
const [nativeAxios, response] = await Promise.all([
|
|
162
|
-
axios_1.default.get(
|
|
155
|
+
axios_1.default.get(`https://ao.${gatewayUrl}`),
|
|
163
156
|
wayfinder.request.get('ar://ao'),
|
|
164
157
|
]);
|
|
165
158
|
node_assert_1.default.strictEqual(response.status, 200);
|
|
@@ -170,43 +163,39 @@ const stubbedGatewaysProvider = {
|
|
|
170
163
|
.filter(([key]) => key.startsWith('x-arns-'));
|
|
171
164
|
const nativeAxiosHeaders = Object.entries(nativeAxios.headers).filter(([key]) => key.startsWith('x-arns-'));
|
|
172
165
|
node_assert_1.default.deepStrictEqual(arnsHeaders.sort(), nativeAxiosHeaders.sort());
|
|
173
|
-
node_assert_1.default.deepStrictEqual(response.data, nativeAxios.data);
|
|
174
166
|
});
|
|
175
167
|
(0, node_test_1.it)('should route a non-ar:// url as a normal axios request', async () => {
|
|
176
168
|
const [nativeAxios, response] = await Promise.all([
|
|
177
|
-
(0, axios_1.default)(
|
|
178
|
-
wayfinder.request(
|
|
169
|
+
(0, axios_1.default)(`https://${gatewayUrl}/`),
|
|
170
|
+
wayfinder.request(`https://${gatewayUrl}/`),
|
|
179
171
|
]);
|
|
180
172
|
node_assert_1.default.strictEqual(response.status, 200);
|
|
181
173
|
node_assert_1.default.strictEqual(response.status, nativeAxios.status);
|
|
182
|
-
node_assert_1.default.deepStrictEqual(response.data, nativeAxios.data);
|
|
183
174
|
// TODO: ensure the headers are the same excluding unique headers
|
|
184
175
|
});
|
|
185
|
-
for (const api of ['/info', '/
|
|
176
|
+
for (const api of ['/info', '/block/current']) {
|
|
186
177
|
(0, node_test_1.it)(`supports native arweave node apis ${api}`, async () => {
|
|
187
178
|
const [nativeAxios, response] = await Promise.all([
|
|
188
|
-
(0, axios_1.default)(`https
|
|
189
|
-
wayfinder.request(`ar
|
|
179
|
+
(0, axios_1.default)(`https://${gatewayUrl}${api}`),
|
|
180
|
+
wayfinder.request(`ar://${api}`),
|
|
190
181
|
]);
|
|
191
182
|
node_assert_1.default.strictEqual(response.status, 200);
|
|
192
183
|
node_assert_1.default.strictEqual(response.status, nativeAxios.status);
|
|
193
184
|
// TODO: ensure the headers are the same excluding unique headers
|
|
194
|
-
node_assert_1.default.deepStrictEqual(response.data, nativeAxios.data);
|
|
195
185
|
});
|
|
196
186
|
}
|
|
197
187
|
for (const api of ['/ar-io/info', '/ar-io/__gateway_metrics']) {
|
|
198
188
|
(0, node_test_1.it)(`supports native ario node gateway apis ${api}`, async () => {
|
|
199
189
|
const [nativeAxios, response] = await Promise.all([
|
|
200
|
-
(0, axios_1.default)(`https
|
|
190
|
+
(0, axios_1.default)(`https://${gatewayUrl}${api}`),
|
|
201
191
|
wayfinder.request(`ar:///${api}`),
|
|
202
192
|
]);
|
|
203
193
|
node_assert_1.default.strictEqual(response.status, 200);
|
|
204
194
|
node_assert_1.default.strictEqual(response.status, nativeAxios.status);
|
|
205
195
|
// TODO: ensure the headers are the same excluding unique headers
|
|
206
|
-
node_assert_1.default.deepStrictEqual(response.data, nativeAxios.data);
|
|
207
196
|
});
|
|
208
197
|
}
|
|
209
|
-
|
|
198
|
+
node_test_1.it.skip('should return the error from the target gateway if the route is not found', async () => {
|
|
210
199
|
const axiosInstance = axios_1.default.create({
|
|
211
200
|
validateStatus: () => true, // don't throw so we can compare axios result with wrapped axios result
|
|
212
201
|
});
|
|
@@ -217,11 +206,10 @@ const stubbedGatewaysProvider = {
|
|
|
217
206
|
}),
|
|
218
207
|
});
|
|
219
208
|
const [nativeAxios, response] = await Promise.all([
|
|
220
|
-
axiosInstance(
|
|
221
|
-
wayfinder.request('
|
|
209
|
+
axiosInstance(`https://${gatewayUrl}/ar-io/not-found`),
|
|
210
|
+
wayfinder.request('ar:///not-found'),
|
|
222
211
|
]);
|
|
223
212
|
node_assert_1.default.strictEqual(response.status, nativeAxios.status);
|
|
224
|
-
node_assert_1.default.strictEqual(response.data, nativeAxios.data);
|
|
225
213
|
});
|
|
226
214
|
});
|
|
227
215
|
(0, node_test_1.describe)('got', () => {
|
|
@@ -236,7 +224,7 @@ const stubbedGatewaysProvider = {
|
|
|
236
224
|
});
|
|
237
225
|
(0, node_test_1.it)('should fetch the data using the got default function against the target gateway', async () => {
|
|
238
226
|
const [nativeGot, response] = await Promise.all([
|
|
239
|
-
(0, got_1.default)(
|
|
227
|
+
(0, got_1.default)(`https://ao.${gatewayUrl}`),
|
|
240
228
|
wayfinder.request('ar://ao'),
|
|
241
229
|
]);
|
|
242
230
|
node_assert_1.default.strictEqual(response.statusCode, 200);
|
|
@@ -244,7 +232,7 @@ const stubbedGatewaysProvider = {
|
|
|
244
232
|
node_assert_1.default.deepStrictEqual(response.body, nativeGot.body);
|
|
245
233
|
});
|
|
246
234
|
(0, node_test_1.it)('should stream the data using got.stream against the selected target gateway', async () => {
|
|
247
|
-
const nativeBuffer = await (0, consumers_1.buffer)(await got_1.default.stream(
|
|
235
|
+
const nativeBuffer = await (0, consumers_1.buffer)(await got_1.default.stream(`https://ao.${gatewayUrl}`, { decompress: false }));
|
|
248
236
|
const wayfinderBuffer = await (0, consumers_1.buffer)(await wayfinder.request.stream('ar://ao', { decompress: false }));
|
|
249
237
|
node_assert_1.default.deepStrictEqual(wayfinderBuffer, nativeBuffer);
|
|
250
238
|
});
|
package/lib/cjs/utils/arweave.js
CHANGED
|
@@ -118,7 +118,7 @@ const getEpochDataFromGqlFallback = async ({ ao, epochIndex, processId = constan
|
|
|
118
118
|
if (!messageResult) {
|
|
119
119
|
continue;
|
|
120
120
|
}
|
|
121
|
-
for (const message of messageResult
|
|
121
|
+
for (const message of messageResult?.Messages ?? []) {
|
|
122
122
|
const data = JSON.parse(message.Data);
|
|
123
123
|
const tags = message.Tags;
|
|
124
124
|
// check if the message results include epoch-distribution-notice for the requested epoch index
|
package/lib/cjs/version.js
CHANGED
package/lib/esm/common/io.js
CHANGED
|
@@ -48,6 +48,10 @@ export class ARIO {
|
|
|
48
48
|
...config,
|
|
49
49
|
process: new AOProcess({
|
|
50
50
|
processId: ARIO_MAINNET_PROCESS_ID,
|
|
51
|
+
ao: connect({
|
|
52
|
+
CU_URL: 'https://cu.ardrive.io',
|
|
53
|
+
...config?.process?.ao,
|
|
54
|
+
}),
|
|
51
55
|
}),
|
|
52
56
|
});
|
|
53
57
|
}
|
|
@@ -916,7 +920,10 @@ export class ARIOWriteable extends ARIOReadable {
|
|
|
916
920
|
}
|
|
917
921
|
return this.paymentProvider.initiateArNSPurchase({
|
|
918
922
|
intent: 'Buy-Name',
|
|
919
|
-
|
|
923
|
+
name: params.name,
|
|
924
|
+
years: params.years,
|
|
925
|
+
type: params.type,
|
|
926
|
+
processId: params.processId,
|
|
920
927
|
});
|
|
921
928
|
}
|
|
922
929
|
const { tags = [] } = options || {};
|
|
@@ -980,7 +987,8 @@ export class ARIOWriteable extends ARIOReadable {
|
|
|
980
987
|
}
|
|
981
988
|
return this.paymentProvider.initiateArNSPurchase({
|
|
982
989
|
intent: 'Extend-Lease',
|
|
983
|
-
|
|
990
|
+
name: params.name,
|
|
991
|
+
years: params.years,
|
|
984
992
|
});
|
|
985
993
|
}
|
|
986
994
|
const { tags = [] } = options || {};
|
|
@@ -1003,7 +1011,8 @@ export class ARIOWriteable extends ARIOReadable {
|
|
|
1003
1011
|
}
|
|
1004
1012
|
return this.paymentProvider.initiateArNSPurchase({
|
|
1005
1013
|
intent: 'Increase-Undername-Limit',
|
|
1006
|
-
|
|
1014
|
+
quantity: params.increaseCount,
|
|
1015
|
+
name: params.name,
|
|
1007
1016
|
});
|
|
1008
1017
|
}
|
|
1009
1018
|
const { tags = [] } = options || {};
|