@ar.io/wayfinder-core 1.8.1 → 1.9.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 CHANGED
@@ -36,11 +36,10 @@ import {
36
36
  createWayfinderClient,
37
37
  FastestPingRoutingStrategy,
38
38
  NetworkGatewaysProvider,
39
- WayfinderFetchOptions,
40
39
  } from '@ar.io/wayfinder-core';
41
40
  import { ARIO } from '@ar.io/sdk';
42
41
 
43
- const options: WayfinderFetchOptions = {
42
+ const wayfinder = createWayfinderClient({
44
43
  routingStrategy: new FastestPingRoutingStrategy({
45
44
  gatewaysProvider: new NetworkGatewaysProvider({
46
45
  ario: ARIO.mainnet(),
@@ -49,9 +48,7 @@ const options: WayfinderFetchOptions = {
49
48
  limit: 10,
50
49
  }),
51
50
  }),
52
- };
53
-
54
- const wayfinder = createWayfinderClient(options);
51
+ });
55
52
  ```
56
53
 
57
54
  ### Enable Verification
@@ -60,17 +57,14 @@ const wayfinder = createWayfinderClient(options);
60
57
  import {
61
58
  createWayfinderClient,
62
59
  HashVerificationStrategy,
63
- WayfinderFetchOptions,
64
60
  } from '@ar.io/wayfinder-core';
65
61
 
66
- const options: WayfinderFetchOptions = {
62
+ const wayfinder = createWayfinderClient({
67
63
  verificationStrategy: new HashVerificationStrategy({
68
64
  trustedGateways: [new URL('https://permagate.io')],
69
65
  }),
70
66
  strict: true, // Fail requests on verification errors
71
- };
72
-
73
- const wayfinder = createWayfinderClient(options);
67
+ });
74
68
  ```
75
69
 
76
70
  Wayfinder Core provides helper functions to construct routing and verification strategies:
@@ -178,6 +172,7 @@ Gateway providers supply the list of gateways for routing. **By default, `create
178
172
  | `StaticGatewaysProvider` | Returns a static list of gateways | Testing or specific gateways |
179
173
  | `SimpleCacheGatewaysProvider` | In-memory caching wrapper | Reduce API calls (used by default) |
180
174
  | `LocalStorageGatewaysProvider` | Browser localStorage caching | Persistent caching (used by default in browsers) |
175
+ | `CompositeGatewaysProvider` | Chains multiple providers with fallback | Maximum resilience with multiple sources |
181
176
 
182
177
  #### NetworkGatewaysProvider
183
178
 
@@ -208,6 +203,47 @@ const gatewayProvider = new TrustedPeersGatewaysProvider({
208
203
  });
209
204
  ```
210
205
 
206
+ #### CompositeGatewaysProvider
207
+
208
+ Chains multiple gateway providers together, trying each in sequence until one succeeds. This is useful for building resilient gateway discovery with fallbacks.
209
+
210
+ **How it works:**
211
+
212
+ 1. Tries each provider in the order they're provided
213
+ 2. If a provider returns a non-empty list of gateways, those gateways are used
214
+ 3. If a provider throws an error or returns an empty list, moves to the next provider
215
+ 4. If all providers fail, throws an error
216
+
217
+ ```javascript
218
+ import {
219
+ CompositeGatewaysProvider,
220
+ NetworkGatewaysProvider,
221
+ StaticGatewaysProvider,
222
+ TrustedPeersGatewaysProvider,
223
+ } from '@ar.io/wayfinder-core';
224
+ import { ARIO } from '@ar.io/sdk';
225
+
226
+ // Example: Network-first with static fallback
227
+ const gatewayProvider = new CompositeGatewaysProvider({
228
+ providers: [
229
+ // Try fetching from AR.IO network first
230
+ new NetworkGatewaysProvider({
231
+ ario: ARIO.mainnet(),
232
+ sortBy: 'operatorStake',
233
+ limit: 10,
234
+ }),
235
+ // Fallback to trusted peers if network fetch fails
236
+ new TrustedPeersGatewaysProvider({
237
+ trustedGateway: 'https://arweave.net',
238
+ }),
239
+ // Final fallback to static list
240
+ new StaticGatewaysProvider({
241
+ gateways: ['https://arweave.net', 'https://permagate.io'],
242
+ }),
243
+ ],
244
+ });
245
+ ```
246
+
211
247
  ## Routing Strategies
212
248
 
213
249
  Wayfinder supports multiple routing strategies to select target gateways for your requests.
@@ -0,0 +1,13 @@
1
+ import type { GatewaysProvider, Logger } from '../types.js';
2
+ export declare class CompositeGatewaysProvider implements GatewaysProvider {
3
+ private providers;
4
+ private logger;
5
+ constructor({ providers, logger, }?: {
6
+ providers?: GatewaysProvider[];
7
+ logger?: Logger;
8
+ });
9
+ getGateways(): Promise<URL[]>;
10
+ addProvider(provider: GatewaysProvider): void;
11
+ getProviders(): GatewaysProvider[];
12
+ }
13
+ //# sourceMappingURL=composite.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"composite.d.ts","sourceRoot":"","sources":["../../src/gateways/composite.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE5D,qBAAa,yBAA0B,YAAW,gBAAgB;IAChE,OAAO,CAAC,SAAS,CAAqB;IACtC,OAAO,CAAC,MAAM,CAAS;gBAEX,EACV,SAAc,EACd,MAAsB,GACvB,GAAE;QACD,SAAS,CAAC,EAAE,gBAAgB,EAAE,CAAC;QAC/B,MAAM,CAAC,EAAE,MAAM,CAAC;KACZ;IAQA,WAAW,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;IA+BnC,WAAW,CAAC,QAAQ,EAAE,gBAAgB,GAAG,IAAI;IAI7C,YAAY,IAAI,gBAAgB,EAAE;CAGnC"}
@@ -0,0 +1,59 @@
1
+ /**
2
+ * WayFinder
3
+ * Copyright (C) 2022-2025 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 { defaultLogger } from '../logger.js';
18
+ export class CompositeGatewaysProvider {
19
+ providers;
20
+ logger;
21
+ constructor({ providers = [], logger = defaultLogger, } = {}) {
22
+ if (providers.length === 0) {
23
+ throw new Error('At least one gateways provider must be provided');
24
+ }
25
+ this.providers = providers;
26
+ this.logger = logger;
27
+ }
28
+ async getGateways() {
29
+ this.logger.debug('CompositeGatewaysProvider: starting gateway fetch', {
30
+ providersCount: this.providers.length,
31
+ });
32
+ for (const provider of this.providers) {
33
+ try {
34
+ this.logger.debug('CompositeGatewaysProvider: trying provider');
35
+ const gateways = await provider.getGateways();
36
+ if (gateways.length > 0) {
37
+ this.logger.debug('CompositeGatewaysProvider: provider succeeded', {
38
+ gatewaysCount: gateways.length,
39
+ });
40
+ return gateways;
41
+ }
42
+ this.logger.debug('CompositeGatewaysProvider: provider returned empty list');
43
+ }
44
+ catch (error) {
45
+ this.logger.debug('CompositeGatewaysProvider: provider failed', {
46
+ error: error instanceof Error ? error.message : String(error),
47
+ });
48
+ }
49
+ }
50
+ this.logger.error('CompositeGatewaysProvider: all providers failed to return gateways');
51
+ throw new Error('All gateways providers failed to return gateways');
52
+ }
53
+ addProvider(provider) {
54
+ this.providers.push(provider);
55
+ }
56
+ getProviders() {
57
+ return [...this.providers];
58
+ }
59
+ }
package/dist/index.d.ts CHANGED
@@ -22,6 +22,7 @@ export * from './routing/round-robin.js';
22
22
  export * from './routing/preferred-with-fallback.js';
23
23
  export * from './routing/simple-cache.js';
24
24
  export * from './routing/composite.js';
25
+ export * from './gateways/composite.js';
25
26
  export * from './gateways/network.js';
26
27
  export * from './gateways/simple-cache.js';
27
28
  export * from './gateways/static.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAGH,cAAc,YAAY,CAAC;AAG3B,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,0BAA0B,CAAC;AACzC,cAAc,sCAAsC,CAAC;AACrD,cAAc,2BAA2B,CAAC;AAC1C,cAAc,wBAAwB,CAAC;AAGvC,cAAc,uBAAuB,CAAC;AACtC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,sBAAsB,CAAC;AACrC,cAAc,mCAAmC,CAAC;AAClD,cAAc,6BAA6B,CAAC;AAG5C,cAAc,0CAA0C,CAAC;AACzD,cAAc,qCAAqC,CAAC;AACpD,cAAc,0CAA0C,CAAC;AACzD,cAAc,uCAAuC,CAAC;AAGtD,cAAc,2BAA2B,CAAC;AAC1C,cAAc,sBAAsB,CAAC;AAGrC,cAAc,cAAc,CAAC;AAG7B,cAAc,aAAa,CAAC;AAG5B,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAGH,cAAc,YAAY,CAAC;AAG3B,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,0BAA0B,CAAC;AACzC,cAAc,sCAAsC,CAAC;AACrD,cAAc,2BAA2B,CAAC;AAC1C,cAAc,wBAAwB,CAAC;AAGvC,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AACtC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,sBAAsB,CAAC;AACrC,cAAc,mCAAmC,CAAC;AAClD,cAAc,6BAA6B,CAAC;AAG5C,cAAc,0CAA0C,CAAC;AACzD,cAAc,qCAAqC,CAAC;AACpD,cAAc,0CAA0C,CAAC;AACzD,cAAc,uCAAuC,CAAC;AAGtD,cAAc,2BAA2B,CAAC;AAC1C,cAAc,sBAAsB,CAAC;AAGrC,cAAc,cAAc,CAAC;AAG7B,cAAc,aAAa,CAAC;AAG5B,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC"}
package/dist/index.js CHANGED
@@ -25,6 +25,7 @@ export * from './routing/preferred-with-fallback.js';
25
25
  export * from './routing/simple-cache.js';
26
26
  export * from './routing/composite.js';
27
27
  // gateways providers
28
+ export * from './gateways/composite.js';
28
29
  export * from './gateways/network.js';
29
30
  export * from './gateways/simple-cache.js';
30
31
  export * from './gateways/static.js';
package/dist/version.d.ts CHANGED
@@ -14,5 +14,5 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
- export declare const WAYFINDER_CORE_VERSION = "v1.8.1";
17
+ export declare const WAYFINDER_CORE_VERSION = "v1.9.0";
18
18
  //# sourceMappingURL=version.d.ts.map
package/dist/version.js CHANGED
@@ -14,4 +14,4 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
- export const WAYFINDER_CORE_VERSION = 'v1.8.1';
17
+ export const WAYFINDER_CORE_VERSION = 'v1.9.0';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ar.io/wayfinder-core",
3
- "version": "1.8.1",
3
+ "version": "1.9.0",
4
4
  "description": "WayFinder core library for intelligently routing to optimal AR.IO gateways",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",