@ar.io/sdk 3.10.0-alpha.5 → 3.10.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.
Files changed (54) hide show
  1. package/bundles/web.bundle.min.js +60 -60
  2. package/lib/cjs/common/index.js +2 -0
  3. package/lib/cjs/common/wayfinder/gateways.js +75 -0
  4. package/lib/cjs/common/wayfinder/index.js +36 -0
  5. package/lib/cjs/common/wayfinder/routers/fixed.js +14 -0
  6. package/lib/cjs/common/wayfinder/routers/fixed.test.js +14 -0
  7. package/lib/cjs/common/wayfinder/routers/priority.js +38 -0
  8. package/lib/cjs/common/wayfinder/routers/priority.test.js +155 -0
  9. package/lib/cjs/common/wayfinder/routers/random.js +23 -0
  10. package/lib/cjs/common/wayfinder/routers/random.test.js +104 -0
  11. package/lib/cjs/common/wayfinder/routers/simple-cache.js +25 -0
  12. package/lib/cjs/common/wayfinder/routers/simple-cache.test.js +41 -0
  13. package/lib/cjs/common/wayfinder/wayfinder.js +194 -0
  14. package/lib/cjs/common/wayfinder/wayfinder.test.js +254 -0
  15. package/lib/cjs/types/index.js +1 -0
  16. package/lib/cjs/types/wayfinder.js +2 -0
  17. package/lib/cjs/version.js +1 -1
  18. package/lib/esm/common/index.js +2 -0
  19. package/lib/esm/common/wayfinder/gateways.js +69 -0
  20. package/lib/esm/common/wayfinder/index.js +20 -0
  21. package/lib/esm/common/wayfinder/routers/fixed.js +10 -0
  22. package/lib/esm/common/wayfinder/routers/fixed.test.js +12 -0
  23. package/lib/esm/common/wayfinder/routers/priority.js +34 -0
  24. package/lib/esm/common/wayfinder/routers/priority.test.js +153 -0
  25. package/lib/esm/common/wayfinder/routers/random.js +19 -0
  26. package/lib/esm/common/wayfinder/routers/random.test.js +102 -0
  27. package/lib/esm/common/wayfinder/routers/simple-cache.js +21 -0
  28. package/lib/esm/common/wayfinder/routers/simple-cache.test.js +39 -0
  29. package/lib/esm/common/wayfinder/wayfinder.js +187 -0
  30. package/lib/esm/common/wayfinder/wayfinder.test.js +249 -0
  31. package/lib/esm/types/index.js +1 -0
  32. package/lib/esm/types/wayfinder.js +1 -0
  33. package/lib/esm/version.js +1 -1
  34. package/lib/types/common/index.d.ts +1 -0
  35. package/lib/types/common/io.d.ts +0 -1
  36. package/lib/types/common/wayfinder/gateways.d.ts +44 -0
  37. package/lib/types/common/wayfinder/index.d.ts +19 -0
  38. package/lib/types/common/wayfinder/routers/fixed.d.ts +25 -0
  39. package/lib/types/common/wayfinder/routers/fixed.test.d.ts +1 -0
  40. package/lib/types/common/wayfinder/routers/priority.d.ts +34 -0
  41. package/lib/types/common/wayfinder/routers/priority.test.d.ts +1 -0
  42. package/lib/types/common/wayfinder/routers/random.d.ts +28 -0
  43. package/lib/types/common/wayfinder/routers/random.test.d.ts +1 -0
  44. package/lib/types/common/wayfinder/routers/simple-cache.d.ts +29 -0
  45. package/lib/types/common/wayfinder/routers/simple-cache.test.d.ts +1 -0
  46. package/lib/types/common/wayfinder/wayfinder.d.ts +106 -0
  47. package/lib/types/common/wayfinder/wayfinder.test.d.ts +1 -0
  48. package/lib/types/types/index.d.ts +1 -0
  49. package/lib/types/types/io.d.ts +1 -0
  50. package/lib/types/types/token.d.ts +1 -0
  51. package/lib/types/types/wayfinder.d.ts +20 -0
  52. package/lib/types/utils/base64.d.ts +1 -0
  53. package/lib/types/version.d.ts +1 -1
  54. package/package.json +4 -3
@@ -0,0 +1,249 @@
1
+ import axios from 'axios';
2
+ import got from 'got';
3
+ import assert from 'node:assert';
4
+ import { buffer } from 'node:stream/consumers';
5
+ import { before, describe, it } from 'node:test';
6
+ import { RandomGatewayRouter } from './routers/random.js';
7
+ import { Wayfinder } from './wayfinder.js';
8
+ const stubbedGateway = {
9
+ status: 'joined',
10
+ gatewayAddress: 'arweave',
11
+ operatorStake: 1000,
12
+ totalDelegatedStake: 1000,
13
+ startTimestamp: 1000,
14
+ settings: {
15
+ protocol: 'https',
16
+ fqdn: 'arweave.net',
17
+ port: 443,
18
+ },
19
+ };
20
+ const stubbedGatewaysProvider = {
21
+ getGateways: async () => [stubbedGateway],
22
+ };
23
+ describe('Wayfinder', () => {
24
+ describe('http wrapper', () => {
25
+ describe('fetch', () => {
26
+ let wayfinder;
27
+ before(() => {
28
+ wayfinder = new Wayfinder({
29
+ httpClient: fetch,
30
+ router: new RandomGatewayRouter({
31
+ gatewaysProvider: stubbedGatewaysProvider,
32
+ }),
33
+ });
34
+ });
35
+ it('should fetch the data using the selected gateway', async () => {
36
+ const nativeFetch = await fetch('https://ao.arweave.net');
37
+ const response = await wayfinder.request('ar://ao');
38
+ assert.strictEqual(response.status, 200);
39
+ assert.strictEqual(response.status, nativeFetch.status);
40
+ // assert the arns headers are the same
41
+ const arnsHeaders = Array.from(response.headers.entries()).filter(([key]) => key.startsWith('x-arns-'));
42
+ const nativeFetchHeaders = Array.from(nativeFetch.headers.entries()).filter(([key]) => key.startsWith('x-arns-'));
43
+ assert.deepStrictEqual(arnsHeaders, nativeFetchHeaders);
44
+ assert.deepStrictEqual(await response.text(), await nativeFetch.text());
45
+ });
46
+ it('should route a non-ar:// url as a normal fetch', async () => {
47
+ const [nativeFetch, response] = await Promise.all([
48
+ fetch('https://arweave.net/', {
49
+ method: 'HEAD',
50
+ }),
51
+ wayfinder.request('https://arweave.net/', {
52
+ method: 'HEAD',
53
+ }),
54
+ ]);
55
+ assert.strictEqual(response.status, 200);
56
+ assert.strictEqual(response.status, nativeFetch.status);
57
+ // TODO: ensure the headers are the same excluding unique headers
58
+ assert.deepStrictEqual(await response.text(), await nativeFetch.text());
59
+ });
60
+ for (const api of ['/info', '/metrics', '/block/current']) {
61
+ it(`supports native arweave node apis ${api}`, async () => {
62
+ const [nativeFetch, response] = await Promise.all([
63
+ fetch(`https://arweave.net${api}`),
64
+ wayfinder.request(`ar:///${api}`),
65
+ ]);
66
+ assert.strictEqual(response.status, 200);
67
+ assert.strictEqual(response.status, nativeFetch.status);
68
+ // TODO: ensure the headers are the same excluding unique headers
69
+ assert.deepStrictEqual(await response.text(), await nativeFetch.text());
70
+ });
71
+ }
72
+ for (const api of ['/ar-io/info', '/ar-io/__gateway_metrics']) {
73
+ it(`supports native ario node gateway apis ${api}`, async () => {
74
+ const [nativeFetch, response] = await Promise.all([
75
+ fetch(`https://arweave.net${api}`),
76
+ wayfinder.request(`ar:///${api}`),
77
+ ]);
78
+ assert.strictEqual(response.status, 200);
79
+ assert.strictEqual(response.status, nativeFetch.status);
80
+ // TODO: ensure the headers are the same excluding unique headers
81
+ assert.deepStrictEqual(await response.text(), await nativeFetch.text());
82
+ });
83
+ }
84
+ it('supports a post request to graphql', async () => {
85
+ const response = await wayfinder.request('ar:///graphql', {
86
+ method: 'POST',
87
+ headers: {
88
+ 'Content-Type': 'application/json',
89
+ },
90
+ body: JSON.stringify({
91
+ query: `
92
+ query {
93
+ transactions(
94
+ ids: ["xf958qhCNGfDme1FtoiD6DtMfDENDbtxZpjOM_1tsMM"]
95
+ ) {
96
+ edges {
97
+ cursor
98
+ node {
99
+ id
100
+ tags {
101
+ name
102
+ value
103
+ }
104
+ block {
105
+ height
106
+ timestamp
107
+ }
108
+ }
109
+ }
110
+ pageInfo {
111
+ hasNextPage
112
+ }
113
+ }
114
+ }
115
+ `,
116
+ }),
117
+ });
118
+ assert.strictEqual(response.status, 200);
119
+ });
120
+ it('returns the error from the target gateway if the route is not found', async () => {
121
+ const [nativeFetch, response] = await Promise.all([
122
+ fetch('https://arweave.net/not-found'),
123
+ wayfinder.request('https://arweave.net/not-found'),
124
+ ]);
125
+ assert.strictEqual(response.status, nativeFetch.status);
126
+ assert.strictEqual(response.statusText, nativeFetch.statusText);
127
+ assert.deepStrictEqual(await response.text(), await nativeFetch.text());
128
+ });
129
+ });
130
+ describe('axios', () => {
131
+ let wayfinder;
132
+ before(() => {
133
+ wayfinder = new Wayfinder({
134
+ httpClient: axios,
135
+ router: new RandomGatewayRouter({
136
+ gatewaysProvider: stubbedGatewaysProvider,
137
+ }),
138
+ });
139
+ });
140
+ it('should fetch the data using axios default function against the target gateway', async () => {
141
+ const [nativeAxios, response] = await Promise.all([
142
+ axios('https://ao.arweave.net'),
143
+ wayfinder.request('ar://ao'),
144
+ ]);
145
+ assert.strictEqual(response.status, 200);
146
+ assert.strictEqual(response.status, nativeAxios.status);
147
+ // assert the arns headers are the same
148
+ const arnsHeaders = Object.entries(response.headers)
149
+ .sort()
150
+ .filter(([key]) => key.startsWith('x-arns-'));
151
+ const nativeAxiosHeaders = Object.entries(nativeAxios.headers).filter(([key]) => key.startsWith('x-arns-'));
152
+ assert.deepStrictEqual(arnsHeaders.sort(), nativeAxiosHeaders.sort());
153
+ assert.deepStrictEqual(response.data, nativeAxios.data);
154
+ });
155
+ it('should fetch the data using the axios.get method against the target gateway', async () => {
156
+ const [nativeAxios, response] = await Promise.all([
157
+ axios.get('https://ao.arweave.net'),
158
+ wayfinder.request.get('ar://ao'),
159
+ ]);
160
+ assert.strictEqual(response.status, 200);
161
+ assert.strictEqual(response.status, nativeAxios.status);
162
+ // assert the arns headers are the same
163
+ const arnsHeaders = Object.entries(response.headers)
164
+ .sort()
165
+ .filter(([key]) => key.startsWith('x-arns-'));
166
+ const nativeAxiosHeaders = Object.entries(nativeAxios.headers).filter(([key]) => key.startsWith('x-arns-'));
167
+ assert.deepStrictEqual(arnsHeaders.sort(), nativeAxiosHeaders.sort());
168
+ assert.deepStrictEqual(response.data, nativeAxios.data);
169
+ });
170
+ it('should route a non-ar:// url as a normal axios request', async () => {
171
+ const [nativeAxios, response] = await Promise.all([
172
+ axios('https://arweave.net/'),
173
+ wayfinder.request('https://arweave.net/'),
174
+ ]);
175
+ assert.strictEqual(response.status, 200);
176
+ assert.strictEqual(response.status, nativeAxios.status);
177
+ assert.deepStrictEqual(response.data, nativeAxios.data);
178
+ // TODO: ensure the headers are the same excluding unique headers
179
+ });
180
+ for (const api of ['/info', '/metrics', '/block/current']) {
181
+ it(`supports native arweave node apis ${api}`, async () => {
182
+ const [nativeAxios, response] = await Promise.all([
183
+ axios(`https://arweave.net${api}`),
184
+ wayfinder.request(`ar:///${api}`),
185
+ ]);
186
+ assert.strictEqual(response.status, 200);
187
+ assert.strictEqual(response.status, nativeAxios.status);
188
+ // TODO: ensure the headers are the same excluding unique headers
189
+ assert.deepStrictEqual(response.data, nativeAxios.data);
190
+ });
191
+ }
192
+ for (const api of ['/ar-io/info', '/ar-io/__gateway_metrics']) {
193
+ it(`supports native ario node gateway apis ${api}`, async () => {
194
+ const [nativeAxios, response] = await Promise.all([
195
+ axios(`https://arweave.net${api}`),
196
+ wayfinder.request(`ar:///${api}`),
197
+ ]);
198
+ assert.strictEqual(response.status, 200);
199
+ assert.strictEqual(response.status, nativeAxios.status);
200
+ // TODO: ensure the headers are the same excluding unique headers
201
+ assert.deepStrictEqual(response.data, nativeAxios.data);
202
+ });
203
+ }
204
+ it('should return the error from the target gateway if the route is not found', async () => {
205
+ const axiosInstance = axios.create({
206
+ validateStatus: () => true, // don't throw so we can compare axios result with wrapped axios result
207
+ });
208
+ const wayfinder = new Wayfinder({
209
+ httpClient: axiosInstance,
210
+ router: new RandomGatewayRouter({
211
+ gatewaysProvider: stubbedGatewaysProvider,
212
+ }),
213
+ });
214
+ const [nativeAxios, response] = await Promise.all([
215
+ axiosInstance('https://arweave.net/not-found'),
216
+ wayfinder.request('https://arweave.net/not-found'),
217
+ ]);
218
+ assert.strictEqual(response.status, nativeAxios.status);
219
+ assert.strictEqual(response.data, nativeAxios.data);
220
+ });
221
+ });
222
+ });
223
+ describe('got', () => {
224
+ let wayfinder;
225
+ before(() => {
226
+ wayfinder = new Wayfinder({
227
+ httpClient: got,
228
+ router: new RandomGatewayRouter({
229
+ gatewaysProvider: stubbedGatewaysProvider,
230
+ }),
231
+ });
232
+ });
233
+ it('should fetch the data using the got default function against the target gateway', async () => {
234
+ const [nativeGot, response] = await Promise.all([
235
+ got('https://ao.arweave.net'),
236
+ wayfinder.request('ar://ao'),
237
+ ]);
238
+ assert.strictEqual(response.statusCode, 200);
239
+ assert.strictEqual(response.statusCode, nativeGot.statusCode);
240
+ assert.deepStrictEqual(response.body, nativeGot.body);
241
+ });
242
+ it('should stream the data using got.stream against the selected target gateway', async () => {
243
+ const nativeBuffer = await buffer(await got.stream('https://ao.arweave.net', { decompress: false }));
244
+ const wayfinderBuffer = await buffer(await wayfinder.request.stream('ar://ao', { decompress: false }));
245
+ assert.deepStrictEqual(wayfinderBuffer, nativeBuffer);
246
+ });
247
+ });
248
+ // TODO: streaming support using got.stream and got()
249
+ });
@@ -19,3 +19,4 @@ export * from './common.js';
19
19
  export * from './faucet.js';
20
20
  export * from './io.js';
21
21
  export * from './token.js';
22
+ export * from './wayfinder.js';
@@ -0,0 +1 @@
1
+ export {};
@@ -14,4 +14,4 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  // AUTOMATICALLY GENERATED FILE - DO NOT TOUCH
17
- export const version = '3.10.0-alpha.5';
17
+ export const version = '3.10.0-alpha.6';
@@ -21,3 +21,4 @@ export * from './ant-versions.js';
21
21
  export * from './faucet.js';
22
22
  export * from './io.js';
23
23
  export * from './contracts/ao-process.js';
24
+ export * from './wayfinder/index.js';
@@ -141,7 +141,6 @@ export declare class ARIOReadable implements AoARIORead {
141
141
  getAllGatewayVaults(params?: PaginationParams<AoAllGatewayVaults>): Promise<PaginationResult<AoAllGatewayVaults>>;
142
142
  }
143
143
  export declare class ARIOWriteable extends ARIOReadable implements AoARIOWrite {
144
- readonly process: AOProcess;
145
144
  private signer;
146
145
  protected paymentProvider: TurboArNSPaymentProviderAuthenticated | TurboArNSPaymentProviderUnauthenticated;
147
146
  constructor({ signer, paymentUrl, ...config }: ARIOConfigWithSigner);
@@ -0,0 +1,44 @@
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 { AoARIORead, AoGatewayWithAddress } from '../../types/io.js';
17
+ export interface GatewaysProvider {
18
+ getGateways(): Promise<AoGatewayWithAddress[]>;
19
+ }
20
+ export declare class ARIOGatewaysProvider implements GatewaysProvider {
21
+ private ario;
22
+ constructor({ ario }: {
23
+ ario: AoARIORead;
24
+ });
25
+ getGateways(): Promise<AoGatewayWithAddress[]>;
26
+ }
27
+ export declare class StaticGatewaysProvider implements GatewaysProvider {
28
+ private gateways;
29
+ constructor({ gateways }: {
30
+ gateways: AoGatewayWithAddress[];
31
+ });
32
+ getGateways(): Promise<AoGatewayWithAddress[]>;
33
+ }
34
+ export declare class SimpleCacheGatewaysProvider implements GatewaysProvider {
35
+ private gatewaysProvider;
36
+ private ttlSeconds;
37
+ private lastUpdated;
38
+ private gatewaysCache;
39
+ constructor({ gatewaysProvider, ttlSeconds, }: {
40
+ gatewaysProvider: GatewaysProvider;
41
+ ttlSeconds?: number;
42
+ });
43
+ getGateways(): Promise<AoGatewayWithAddress[]>;
44
+ }
@@ -0,0 +1,19 @@
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
+ export * from './wayfinder.js';
17
+ export * from './routers/random.js';
18
+ export * from './routers/priority.js';
19
+ export * from './routers/fixed.js';
@@ -0,0 +1,25 @@
1
+ /// <reference types="node" />
2
+ /**
3
+ * Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import { WayfinderRouter } from '../../../types/wayfinder.js';
18
+ export declare class FixedGatewayRouter implements WayfinderRouter {
19
+ readonly name = "fixed";
20
+ private gateway;
21
+ constructor({ gateway }: {
22
+ gateway: URL;
23
+ });
24
+ getTargetGateway(): Promise<URL>;
25
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,34 @@
1
+ /// <reference types="node" />
2
+ /**
3
+ * Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import { WayfinderRouter } from '../../../types/wayfinder.js';
18
+ import { GatewaysProvider } from '../gateways.js';
19
+ export declare class PriorityGatewayRouter implements WayfinderRouter {
20
+ readonly name = "priority";
21
+ private gatewaysProvider;
22
+ private limit;
23
+ private sortBy;
24
+ private sortOrder;
25
+ private blocklist;
26
+ constructor({ gatewaysProvider, limit, sortBy, sortOrder, blocklist, }: {
27
+ gatewaysProvider: GatewaysProvider;
28
+ limit?: number;
29
+ sortBy?: 'totalDelegatedStake' | 'operatorStake' | 'startTimestamp';
30
+ sortOrder?: 'asc' | 'desc';
31
+ blocklist?: string[];
32
+ });
33
+ getTargetGateway(): Promise<URL>;
34
+ }
@@ -0,0 +1,28 @@
1
+ /// <reference types="node" />
2
+ /**
3
+ * Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import { WayfinderRouter } from '../../../types/wayfinder.js';
18
+ import { GatewaysProvider } from '../gateways.js';
19
+ export declare class RandomGatewayRouter implements WayfinderRouter {
20
+ readonly name = "random";
21
+ private gatewaysProvider;
22
+ private blocklist;
23
+ constructor({ gatewaysProvider, blocklist, }: {
24
+ gatewaysProvider: GatewaysProvider;
25
+ blocklist?: string[];
26
+ });
27
+ getTargetGateway(): Promise<URL>;
28
+ }
@@ -0,0 +1,29 @@
1
+ /// <reference types="node" />
2
+ /**
3
+ * Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import { WayfinderRouter } from '../../../types/wayfinder.js';
18
+ export declare class SimpleCacheRouter implements WayfinderRouter {
19
+ readonly name: 'simple-cache';
20
+ private lastUpdatedTimestamp;
21
+ private ttlSeconds;
22
+ private targetGateway;
23
+ private router;
24
+ constructor({ router, ttlSeconds, }: {
25
+ router: WayfinderRouter;
26
+ ttlSeconds?: number;
27
+ });
28
+ getTargetGateway(): Promise<URL>;
29
+ }
@@ -0,0 +1,106 @@
1
+ /// <reference types="node" />
2
+ import { WayfinderRouter } from '../../types/wayfinder.js';
3
+ type AnyFunction = (...args: [string, ...unknown[]]) => unknown;
4
+ type WayfinderHttpClient<T extends AnyFunction> = T;
5
+ export declare const arnsRegex: RegExp;
6
+ export declare const txIdRegex: RegExp;
7
+ /**
8
+ * Cryptographically secure helper for randomness, does not support seeding
9
+ * @param min - the minimum value
10
+ * @param max - the maximum value
11
+ * @returns a random integer between min and max
12
+ */
13
+ export declare const randomInt: (min: number, max: number) => number;
14
+ /**
15
+ * Core function to resolve a wayfinder url against a target gateway
16
+ * @param originalUrl - the wayfinder url to resolve
17
+ * @param targetGateway - the target gateway to resolve the url against
18
+ * @returns the resolved url that can be used to make a request
19
+ */
20
+ export declare const resolveWayfinderUrl: ({ originalUrl, targetGateway, }: {
21
+ originalUrl: string | URL;
22
+ targetGateway: string | URL;
23
+ }) => URL;
24
+ /**
25
+ * Creates a wrapped http client that supports ar:// protocol
26
+ *
27
+ * This function leverages a Proxy to intercept calls to the http client
28
+ * and redirects them to the target gateway using the resolveUrl function url.
29
+ * It also supports the http client methods like get(), post(), put(), delete(), etc.
30
+ *
31
+ * Any URLs provided that are not wayfinder urls will be returned as is.
32
+ *
33
+ * @param httpClient - the http client to wrap (e.g. axios, fetch, got, etc.)
34
+ * @param resolveUrl - the function to construct the redirect url for ar:// requests
35
+ * @returns a wrapped http client that supports ar:// protocol
36
+ */
37
+ export declare const createWayfinderClient: <T extends AnyFunction>({ httpClient, resolveUrl, }: {
38
+ httpClient: T;
39
+ resolveUrl: (params: {
40
+ originalUrl: string | URL;
41
+ }) => Promise<URL>;
42
+ }) => WayfinderHttpClient<T>;
43
+ /**
44
+ * The main class for the wayfinder
45
+ * @param router - the router to use for requests
46
+ * @param httpClient - the http client to use for requests
47
+ * @param blocklist - the blocklist of gateways to avoid
48
+ */
49
+ export declare class Wayfinder<T extends AnyFunction> {
50
+ /**
51
+ * The router to use for requests
52
+ *
53
+ * @example
54
+ * const wayfinder = new Wayfinder({
55
+ * router: new RandomGatewayRouter({ ario: ARIO.mainnet() }),
56
+ * });
57
+ */
58
+ readonly router: WayfinderRouter;
59
+ /**
60
+ * The http client to use for requests
61
+ *
62
+ * @example
63
+ * const wayfinder = new Wayfinder({
64
+ * router: new RandomGatewayRouter({ ario: ARIO.mainnet() }),
65
+ * httpClient: axios,
66
+ * });
67
+ */
68
+ readonly httpClient: T;
69
+ /**
70
+ * The function that resolves the redirect url for ar:// requests to a target gateway
71
+ *
72
+ * @example
73
+ * const wayfinder = new Wayfinder({
74
+ * router: new RandomGatewayRouter({ ario: ARIO.mainnet() }),
75
+ * httpClient: axios,
76
+ * });
77
+ *
78
+ * const redirectUrl = await wayfinder.resolveUrl({ originalUrl: 'ar://example' });
79
+ */
80
+ readonly resolveUrl: (params: {
81
+ originalUrl: string;
82
+ }) => Promise<URL>;
83
+ /**
84
+ * A wrapped http client that supports ar:// protocol
85
+ *
86
+ * @example
87
+ * const { request: wayfind } = new Wayfinder({
88
+ * router: new RandomGatewayRouter({ ario: ARIO.mainnet() }),
89
+ * httpClient: axios,
90
+ * });;
91
+ *
92
+ * TODO: consider a top level function that supports wayfinder routing under the hood
93
+ * const response = await wayfind('ar://', {
94
+ * method: 'POST',
95
+ * data: {
96
+ * name: 'John Doe',
97
+ * },
98
+ * })
99
+ */
100
+ readonly request: WayfinderHttpClient<T>;
101
+ constructor({ router, httpClient, }: {
102
+ router: WayfinderRouter;
103
+ httpClient: T;
104
+ });
105
+ }
106
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -19,3 +19,4 @@ export * from './common.js';
19
19
  export * from './faucet.js';
20
20
  export * from './io.js';
21
21
  export * from './token.js';
22
+ export * from './wayfinder.js';
@@ -421,6 +421,7 @@ export type DemandFactorSettings = {
421
421
  criteria: string;
422
422
  };
423
423
  export interface AoARIORead {
424
+ process: AOProcess;
424
425
  getInfo(): Promise<{
425
426
  Ticker: string;
426
427
  Name: string;
@@ -1,4 +1,5 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="node" />
2
3
  interface Equatable<T> {
3
4
  equals(other: T): boolean;
4
5
  }
@@ -0,0 +1,20 @@
1
+ /// <reference types="node" />
2
+ /**
3
+ * Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ export interface WayfinderRouter {
18
+ readonly name: string;
19
+ getTargetGateway: () => Promise<URL>;
20
+ }
@@ -1,4 +1,5 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="node" />
2
3
  export declare function fromB64Url(str: string): Buffer;
3
4
  export declare function toB64Url(buffer: Buffer): string;
4
5
  export declare function sha256B64Url(input: Buffer): string;
@@ -13,4 +13,4 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- export declare const version = "3.10.0-alpha.4";
16
+ export declare const version = "3.10.0-alpha.5";