@ar.io/wayfinder-core 1.6.1 → 1.7.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 +117 -61
- package/dist/client.d.ts +18 -4
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +83 -83
- package/dist/routing/ping.d.ts +5 -3
- package/dist/routing/ping.d.ts.map +1 -1
- package/dist/routing/ping.js +2 -0
- package/dist/telemetry.d.ts +2 -3
- package/dist/telemetry.d.ts.map +1 -1
- package/dist/telemetry.js +1 -2
- package/dist/types.d.ts +1 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/wayfinder.d.ts +8 -9
- package/dist/wayfinder.d.ts.map +1 -1
- package/dist/wayfinder.js +36 -16
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -29,51 +29,112 @@ const response = await wayfinder.request('ar://example-name');
|
|
|
29
29
|
### Using with AR.IO Network
|
|
30
30
|
|
|
31
31
|
```javascript
|
|
32
|
-
import {
|
|
32
|
+
import {
|
|
33
|
+
createWayfinderClient,
|
|
34
|
+
FastestPingRoutingStrategy,
|
|
35
|
+
NetworkGatewaysProvider,
|
|
36
|
+
} from '@ar.io/wayfinder-core';
|
|
33
37
|
import { ARIO } from '@ar.io/sdk';
|
|
34
38
|
|
|
35
|
-
|
|
36
|
-
const wayfinder = createWayfinderClient({
|
|
39
|
+
const gatewaysProvider = new NetworkGatewaysProvider({
|
|
37
40
|
ario: ARIO.mainnet(),
|
|
38
|
-
|
|
41
|
+
sortBy: 'operatorStake',
|
|
42
|
+
sortOrder: 'desc',
|
|
43
|
+
limit: 10,
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
const wayfinder = createWayfinderClient({
|
|
47
|
+
routingStrategy: new FastestPingRoutingStrategy({ gatewaysProvider }),
|
|
39
48
|
});
|
|
40
49
|
```
|
|
41
50
|
|
|
42
51
|
### Custom Trusted Gateway
|
|
43
52
|
|
|
44
53
|
```javascript
|
|
45
|
-
import {
|
|
54
|
+
import {
|
|
55
|
+
createWayfinderClient,
|
|
56
|
+
FastestPingRoutingStrategy,
|
|
57
|
+
HashVerificationStrategy,
|
|
58
|
+
} from '@ar.io/wayfinder-core';
|
|
59
|
+
|
|
60
|
+
const trustedGateways = [new URL('https://permagate.io')];
|
|
46
61
|
|
|
47
|
-
// Use a specific trusted gateway for fetching peers
|
|
48
62
|
const wayfinder = createWayfinderClient({
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
63
|
+
routingStrategy: new FastestPingRoutingStrategy(),
|
|
64
|
+
verificationStrategy: new HashVerificationStrategy({
|
|
65
|
+
trustedGateways,
|
|
66
|
+
}),
|
|
52
67
|
});
|
|
53
68
|
```
|
|
54
69
|
|
|
70
|
+
> [!NOTE]
|
|
71
|
+
> The legacy `trustedGateways` option on `createWayfinderClient` is deprecated.
|
|
72
|
+
> Configure trusted gateways on the verification strategy instead, as shown
|
|
73
|
+
> above.
|
|
74
|
+
|
|
55
75
|
### Configuration Options
|
|
56
76
|
|
|
57
|
-
|
|
77
|
+
> [!IMPORTANT]
|
|
78
|
+
> `createWayfinderClient` only honors the `cache`, `routingStrategy`,
|
|
79
|
+
> `verificationStrategy`, and `telemetry` options. All other legacy options are
|
|
80
|
+
> deprecated and ignored. Supply concrete strategy instances or instantiate
|
|
81
|
+
> `Wayfinder` directly for advanced customization.
|
|
82
|
+
|
|
83
|
+
By default the helper constructs a
|
|
84
|
+
`TrustedPeersGatewaysProvider('https://permagate.io')`, applies a
|
|
85
|
+
`RandomRoutingStrategy`, and disables verification.
|
|
58
86
|
|
|
59
87
|
```javascript
|
|
88
|
+
import {
|
|
89
|
+
createWayfinderClient,
|
|
90
|
+
FastestPingRoutingStrategy,
|
|
91
|
+
HashVerificationStrategy,
|
|
92
|
+
} from '@ar.io/wayfinder-core';
|
|
93
|
+
|
|
60
94
|
const wayfinder = createWayfinderClient({
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
95
|
+
cache: { ttlSeconds: 600 },
|
|
96
|
+
routingStrategy: new FastestPingRoutingStrategy(),
|
|
97
|
+
verificationStrategy: new HashVerificationStrategy({
|
|
98
|
+
trustedGateways: [new URL('https://permagate.io')],
|
|
99
|
+
}),
|
|
100
|
+
});
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
For custom gateway providers or bespoke routing logic, instantiate `Wayfinder`
|
|
104
|
+
directly:
|
|
105
|
+
|
|
106
|
+
```javascript
|
|
107
|
+
import {
|
|
108
|
+
FastestPingRoutingStrategy,
|
|
109
|
+
HashVerificationStrategy,
|
|
110
|
+
NetworkGatewaysProvider,
|
|
111
|
+
Wayfinder,
|
|
112
|
+
} from '@ar.io/wayfinder-core';
|
|
113
|
+
import { ARIO } from '@ar.io/sdk';
|
|
114
|
+
|
|
115
|
+
const gatewaysProvider = new NetworkGatewaysProvider({
|
|
116
|
+
ario: ARIO.mainnet(),
|
|
117
|
+
sortBy: 'operatorStake',
|
|
118
|
+
sortOrder: 'desc',
|
|
119
|
+
limit: 10,
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
const trustedGateways = [
|
|
123
|
+
new URL('https://arweave.net'),
|
|
124
|
+
new URL('https://permagate.io'),
|
|
125
|
+
];
|
|
126
|
+
|
|
127
|
+
const wayfinder = new Wayfinder({
|
|
128
|
+
gatewaysProvider,
|
|
129
|
+
routingSettings: {
|
|
130
|
+
strategy: new FastestPingRoutingStrategy({ gatewaysProvider }),
|
|
131
|
+
},
|
|
132
|
+
verificationSettings: {
|
|
133
|
+
strategy: new HashVerificationStrategy({
|
|
134
|
+
trustedGateways,
|
|
135
|
+
}),
|
|
136
|
+
},
|
|
137
|
+
telemetrySettings: { enabled: true },
|
|
77
138
|
});
|
|
78
139
|
```
|
|
79
140
|
|
|
@@ -82,23 +143,22 @@ const wayfinder = createWayfinderClient({
|
|
|
82
143
|
When using the AR.IO Network provider, you can specify how gateways are selected:
|
|
83
144
|
|
|
84
145
|
```javascript
|
|
85
|
-
import {
|
|
146
|
+
import {
|
|
147
|
+
createWayfinderClient,
|
|
148
|
+
NetworkGatewaysProvider,
|
|
149
|
+
RandomRoutingStrategy,
|
|
150
|
+
} from '@ar.io/wayfinder-core';
|
|
86
151
|
import { ARIO } from '@ar.io/sdk';
|
|
87
152
|
|
|
88
|
-
const
|
|
153
|
+
const gatewaysProvider = new NetworkGatewaysProvider({
|
|
89
154
|
ario: ARIO.mainnet(),
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
// 'best-performance' - Gateways with best performance metrics
|
|
98
|
-
// 'longest-streak' - Gateways with longest uptime streak
|
|
99
|
-
|
|
100
|
-
routing: 'random', // How to select from the filtered gateways
|
|
101
|
-
cache: { ttlSeconds: 600 }, // Cache for 10 minutes
|
|
155
|
+
sortBy: 'weights.normalizedCompositeWeight',
|
|
156
|
+
sortOrder: 'desc',
|
|
157
|
+
limit: 10,
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
const wayfinder = createWayfinderClient({
|
|
161
|
+
routingStrategy: new RandomRoutingStrategy({ gatewaysProvider }),
|
|
102
162
|
});
|
|
103
163
|
```
|
|
104
164
|
|
|
@@ -637,7 +697,7 @@ const wayfinder = new Wayfinder({
|
|
|
637
697
|
verificationSettings: {
|
|
638
698
|
enabled: true,
|
|
639
699
|
strategy: new HashVerificationStrategy({
|
|
640
|
-
trustedGateways: ['https://permagate.io'],
|
|
700
|
+
trustedGateways: [new URL('https://permagate.io')],
|
|
641
701
|
}),
|
|
642
702
|
},
|
|
643
703
|
});
|
|
@@ -654,7 +714,7 @@ const wayfinder = new Wayfinder({
|
|
|
654
714
|
verificationSettings: {
|
|
655
715
|
enabled: true,
|
|
656
716
|
strategy: new DataRootVerificationStrategy({
|
|
657
|
-
trustedGateways: ['https://permagate.io'],
|
|
717
|
+
trustedGateways: [new URL('https://permagate.io')],
|
|
658
718
|
}),
|
|
659
719
|
},
|
|
660
720
|
});
|
|
@@ -671,7 +731,7 @@ const wayfinder = new Wayfinder({
|
|
|
671
731
|
verificationSettings: {
|
|
672
732
|
enabled: true,
|
|
673
733
|
strategy: new SignatureVerificationStrategy({
|
|
674
|
-
trustedGateways: ['https://permagate.io'],
|
|
734
|
+
trustedGateways: [new URL('https://permagate.io')],
|
|
675
735
|
}),
|
|
676
736
|
},
|
|
677
737
|
});
|
|
@@ -787,7 +847,7 @@ const response = await wayfinder.request('ar://example-name', {
|
|
|
787
847
|
|
|
788
848
|
### Optional Dependencies
|
|
789
849
|
|
|
790
|
-
The `@ar.io/sdk` package is an optional peer dependency. To use AR.IO network gateways,
|
|
850
|
+
The `@ar.io/sdk` package is an optional peer dependency. To use AR.IO network gateways, instantiate a `NetworkGatewaysProvider` with an `ario` instance and supply it to `Wayfinder` directly:
|
|
791
851
|
|
|
792
852
|
**With AR.IO SDK (Recommended):**
|
|
793
853
|
```bash
|
|
@@ -795,7 +855,7 @@ npm install @ar.io/wayfinder-core @ar.io/sdk
|
|
|
795
855
|
# or
|
|
796
856
|
yarn add @ar.io/wayfinder-core @ar.io/sdk
|
|
797
857
|
```
|
|
798
|
-
- `
|
|
858
|
+
- `new NetworkGatewaysProvider({ ario: ARIO.mainnet() })` exposes AR.IO network gateways
|
|
799
859
|
- Supports intelligent gateway selection criteria
|
|
800
860
|
- Dynamic gateway discovery and updates
|
|
801
861
|
|
|
@@ -815,29 +875,27 @@ Wayfinder supports intelligent caching:
|
|
|
815
875
|
|
|
816
876
|
### Custom Providers and Strategies
|
|
817
877
|
|
|
818
|
-
For advanced use cases,
|
|
878
|
+
For advanced use cases, provide strategy instances explicitly:
|
|
819
879
|
|
|
820
880
|
```javascript
|
|
821
|
-
import {
|
|
822
|
-
|
|
881
|
+
import {
|
|
882
|
+
createWayfinderClient,
|
|
883
|
+
FastestPingRoutingStrategy,
|
|
884
|
+
HashVerificationStrategy,
|
|
885
|
+
} from '@ar.io/wayfinder-core';
|
|
823
886
|
|
|
824
887
|
const wayfinder = createWayfinderClient({
|
|
825
|
-
ario: ARIO.mainnet()
|
|
826
|
-
|
|
827
|
-
// Gateway selection
|
|
828
|
-
gatewaySelection: 'top-ranked',
|
|
829
|
-
|
|
830
888
|
// Enable caching with custom TTL
|
|
831
889
|
cache: { ttlSeconds: 3600 }, // 1 hour
|
|
832
890
|
|
|
833
|
-
//
|
|
891
|
+
// Supply a bespoke routing strategy
|
|
834
892
|
routingStrategy: new FastestPingRoutingStrategy({
|
|
835
893
|
timeoutMs: 1000,
|
|
836
894
|
}),
|
|
837
895
|
|
|
838
|
-
//
|
|
896
|
+
// Configure verification explicitly
|
|
839
897
|
verificationStrategy: new HashVerificationStrategy({
|
|
840
|
-
trustedGateways: ['https://permagate.io'],
|
|
898
|
+
trustedGateways: [new URL('https://permagate.io')],
|
|
841
899
|
}),
|
|
842
900
|
});
|
|
843
901
|
```
|
|
@@ -888,7 +946,7 @@ const wayfinder = new Wayfinder({
|
|
|
888
946
|
enabled: true,
|
|
889
947
|
// verify the data using the hash of the data against a list of trusted gateways
|
|
890
948
|
strategy: new HashVerificationStrategy({
|
|
891
|
-
trustedGateways: ['https://permagate.io'],
|
|
949
|
+
trustedGateways: [new URL('https://permagate.io')],
|
|
892
950
|
}),
|
|
893
951
|
// strict verification - if true, verification failures will cause requests to fail
|
|
894
952
|
strict: true,
|
|
@@ -910,17 +968,15 @@ const wayfinder = new Wayfinder({
|
|
|
910
968
|
|
|
911
969
|
## Telemetry
|
|
912
970
|
|
|
913
|
-
Wayfinder can optionally emit OpenTelemetry spans for every request. **By default, telemetry is disabled**. You can control this behavior with the `
|
|
971
|
+
Wayfinder can optionally emit OpenTelemetry spans for every request. **By default, telemetry is disabled**. You can control this behavior with the `telemetry` option.
|
|
914
972
|
|
|
915
973
|
```javascript
|
|
916
974
|
|
|
917
975
|
import { createWayfinderClient } from '@ar.io/wayfinder-core';
|
|
918
|
-
import { ARIO } from '@ar.io/sdk';
|
|
919
976
|
|
|
920
977
|
const wayfinder = createWayfinderClient({
|
|
921
|
-
ario: ARIO.mainnet(),
|
|
922
978
|
// other settings...
|
|
923
|
-
|
|
979
|
+
telemetry: {
|
|
924
980
|
enabled: true, // disabled by default (must be explicitly enabled)
|
|
925
981
|
sampleRate: 0.1, // 10% sample rate by default
|
|
926
982
|
exporterUrl: 'https://your-custom-otel-exporter', // optional, defaults to https://api.honeycomb.io/v1/traces
|
package/dist/client.d.ts
CHANGED
|
@@ -21,27 +21,32 @@ export interface CreateWayfinderClientOptions {
|
|
|
21
21
|
/**
|
|
22
22
|
* The ARIO instance to use for network gateways provider
|
|
23
23
|
* If not provided, will fall back to static gateways
|
|
24
|
+
* @deprecated Provide a custom `gatewaysProvider` instead.
|
|
24
25
|
*/
|
|
25
26
|
ario?: AoARIORead;
|
|
26
27
|
/**
|
|
27
28
|
* The routing strategy to use
|
|
28
29
|
* @default 'random'
|
|
30
|
+
* @deprecated Provide a `routingStrategy` instance instead.
|
|
29
31
|
*/
|
|
30
32
|
routing?: RoutingOption;
|
|
31
33
|
/**
|
|
32
34
|
* The verification strategy to use
|
|
33
35
|
* @default 'disabled'
|
|
36
|
+
* @deprecated Provide a `verificationStrategy` instance instead.
|
|
34
37
|
*/
|
|
35
38
|
verification?: VerificationOption;
|
|
36
39
|
/**
|
|
37
40
|
* The gateway selection when using NetworkGatewaysProvider (requires ario instance)
|
|
38
41
|
* Only applies when using AR.IO network - ignored for static gateways
|
|
39
42
|
* @default 'top-ranked'
|
|
43
|
+
* @deprecated Configure gateway selection via your custom `gatewaysProvider`.
|
|
40
44
|
*/
|
|
41
45
|
gatewaySelection?: GatewaySelection;
|
|
42
46
|
/**
|
|
43
47
|
* The trusted gateways to use
|
|
44
48
|
* @default ['https://permagate.io']
|
|
49
|
+
* @deprecated Configure trusted gateways via your `verificationStrategy`.
|
|
45
50
|
*/
|
|
46
51
|
trustedGateways?: string[];
|
|
47
52
|
/**
|
|
@@ -62,6 +67,7 @@ export interface CreateWayfinderClientOptions {
|
|
|
62
67
|
/**
|
|
63
68
|
* Custom gateways provider (overrides gatewaySelection)
|
|
64
69
|
* @default undefined
|
|
70
|
+
* @deprecated Instantiate `Wayfinder` directly when providing custom gateways providers.
|
|
65
71
|
*/
|
|
66
72
|
gatewaysProvider?: GatewaysProvider;
|
|
67
73
|
/**
|
|
@@ -83,8 +89,9 @@ export interface CreateWayfinderClientOptions {
|
|
|
83
89
|
/**
|
|
84
90
|
* The fallback routing strategy to use when routing is 'preferred'
|
|
85
91
|
* @default 'random'
|
|
92
|
+
* @deprecated Compose fallback behavior directly in your `routingStrategy`.
|
|
86
93
|
*/
|
|
87
|
-
fallbackStrategy?: RoutingOption;
|
|
94
|
+
fallbackStrategy?: RoutingOption | RoutingStrategy;
|
|
88
95
|
/**
|
|
89
96
|
* Telemetry configuration for OpenTelemetry tracing
|
|
90
97
|
* @default { enabled: false }
|
|
@@ -97,7 +104,13 @@ export interface CreateWayfinderClientOptions {
|
|
|
97
104
|
* @param config
|
|
98
105
|
* @returns
|
|
99
106
|
*/
|
|
100
|
-
|
|
107
|
+
type UseRoutingStrategyConfig = {
|
|
108
|
+
gatewaysProvider?: GatewaysProvider;
|
|
109
|
+
logger?: Logger;
|
|
110
|
+
preferredGateway?: string;
|
|
111
|
+
fallbackStrategy?: RoutingStrategy;
|
|
112
|
+
};
|
|
113
|
+
export declare const useRoutingStrategy: (strategy: RoutingOption, config?: UseRoutingStrategyConfig) => RoutingStrategy;
|
|
101
114
|
/**
|
|
102
115
|
* Helper function to construct a verification strategy
|
|
103
116
|
* @param strategy - The verification strategy to use
|
|
@@ -106,9 +119,10 @@ export declare const useRoutingStrategy: (strategy: RoutingOption, config?: any)
|
|
|
106
119
|
*/
|
|
107
120
|
export declare const useVerificationStrategy: (strategy: VerificationOption, config?: any) => VerificationStrategy;
|
|
108
121
|
/**
|
|
109
|
-
* Creates a Wayfinder client with the specified configuration
|
|
110
|
-
* Uses
|
|
122
|
+
* Creates a Wayfinder client with the specified configuration.
|
|
123
|
+
* Uses the trusted peers gateways provider and random routing by default.
|
|
111
124
|
*/
|
|
112
125
|
export declare function createWayfinderClient(options?: CreateWayfinderClientOptions): Wayfinder;
|
|
113
126
|
export declare const createWayfinder: typeof createWayfinderClient;
|
|
127
|
+
export {};
|
|
114
128
|
//# sourceMappingURL=client.d.ts.map
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAU7C,OAAO,KAAK,EACV,gBAAgB,EAChB,gBAAgB,EAChB,MAAM,EACN,aAAa,EACb,eAAe,
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAU7C,OAAO,KAAK,EACV,gBAAgB,EAChB,gBAAgB,EAChB,MAAM,EACN,aAAa,EACb,eAAe,EACf,iBAAiB,EACjB,kBAAkB,EAClB,oBAAoB,EAErB,MAAM,YAAY,CAAC;AAKpB,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAc3C,MAAM,WAAW,4BAA4B;IAC3C;;;;OAIG;IACH,IAAI,CAAC,EAAE,UAAU,CAAC;IAClB;;;;OAIG;IACH,OAAO,CAAC,EAAE,aAAa,CAAC;IAExB;;;;OAIG;IACH,YAAY,CAAC,EAAE,kBAAkB,CAAC;IAElC;;;;;OAKG;IACH,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;IAEpC;;;;OAIG;IACH,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAE3B;;;;;;OAMG;IACH,KAAK,CAAC,EAAE,OAAO,GAAG;QAAE,UAAU,EAAE,MAAM,CAAA;KAAE,CAAC;IAEzC;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;IAEpC;;;OAGG;IACH,eAAe,CAAC,EAAE,eAAe,CAAC;IAElC;;;OAGG;IACH,oBAAoB,CAAC,EAAE,oBAAoB,CAAC;IAE5C;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAE1B;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,aAAa,GAAG,eAAe,CAAC;IAEnD;;;OAGG;IACH,SAAS,CAAC,EAAE,iBAAiB,CAAC;CAC/B;AAED;;;;;GAKG;AACH,KAAK,wBAAwB,GAAG;IAC9B,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;IACpC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,gBAAgB,CAAC,EAAE,eAAe,CAAC;CACpC,CAAC;AAEF,eAAO,MAAM,kBAAkB,GAC7B,UAAU,aAAa,EACvB,SAAQ,wBAA6B,KACpC,eAkBF,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,GAClC,UAAU,kBAAkB,EAC5B,SAAS,GAAG,KACX,oBAQF,CAAC;AAEF;;;GAGG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,GAAE,4BAAiC,GACzC,SAAS,CA0HX;AAED,eAAO,MAAM,eAAe,8BAAwB,CAAC"}
|
package/dist/client.js
CHANGED
|
@@ -15,9 +15,9 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
import { LocalStorageGatewaysProvider } from './gateways/local-storage-cache.js';
|
|
18
|
-
import { NetworkGatewaysProvider } from './gateways/network.js';
|
|
19
18
|
import { SimpleCacheGatewaysProvider } from './gateways/simple-cache.js';
|
|
20
19
|
import { TrustedPeersGatewaysProvider } from './gateways/trusted-peers.js';
|
|
20
|
+
import { defaultLogger } from './logger.js';
|
|
21
21
|
import { FastestPingRoutingStrategy } from './routing/ping.js';
|
|
22
22
|
import { PreferredWithFallbackRoutingStrategy } from './routing/preferred-with-fallback.js';
|
|
23
23
|
import { RandomRoutingStrategy } from './routing/random.js';
|
|
@@ -28,34 +28,22 @@ import { DataRootVerificationStrategy } from './verification/data-root-verificat
|
|
|
28
28
|
import { HashVerificationStrategy } from './verification/hash-verification.js';
|
|
29
29
|
import { RemoteVerificationStrategy } from './verification/remote-verification.js';
|
|
30
30
|
import { Wayfinder } from './wayfinder.js';
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
sortOrder: 'desc',
|
|
35
|
-
},
|
|
36
|
-
'most-tenured': { sortBy: 'weights.tenureWeight', sortOrder: 'desc' },
|
|
37
|
-
'highest-staked': { sortBy: 'weights.stakeWeight', sortOrder: 'desc' },
|
|
38
|
-
'top-ranked': {
|
|
39
|
-
sortBy: 'weights.normalizedCompositeWeight',
|
|
40
|
-
sortOrder: 'desc',
|
|
41
|
-
},
|
|
42
|
-
'longest-streak': {
|
|
43
|
-
sortBy: 'stats.passedConsecutiveEpochs',
|
|
44
|
-
sortOrder: 'desc',
|
|
45
|
-
},
|
|
31
|
+
const DEFAULT_TRUSTED_GATEWAY = 'https://permagate.io';
|
|
32
|
+
const warnDeprecatedOption = (logger, option, guidance) => {
|
|
33
|
+
logger.warn(`[wayfinder] The \`${option}\` option for createWayfinderClient() is deprecated. ${guidance}`);
|
|
46
34
|
};
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
* @param config
|
|
51
|
-
* @returns
|
|
52
|
-
*/
|
|
53
|
-
export const useRoutingStrategy = (strategy, config) => {
|
|
35
|
+
export const useRoutingStrategy = (strategy, config = {}) => {
|
|
36
|
+
const { fallbackStrategy, preferredGateway, ...baseConfig } = config;
|
|
37
|
+
const resolvedFallbackStrategy = fallbackStrategy ?? new FastestPingRoutingStrategy(baseConfig);
|
|
54
38
|
const routingMap = {
|
|
55
|
-
random: new RandomRoutingStrategy(
|
|
56
|
-
fastest: new FastestPingRoutingStrategy(
|
|
57
|
-
preferred: new PreferredWithFallbackRoutingStrategy(
|
|
58
|
-
|
|
39
|
+
random: new RandomRoutingStrategy(baseConfig),
|
|
40
|
+
fastest: new FastestPingRoutingStrategy(baseConfig),
|
|
41
|
+
preferred: new PreferredWithFallbackRoutingStrategy({
|
|
42
|
+
preferredGateway: preferredGateway ?? 'https://arweave.net',
|
|
43
|
+
fallbackStrategy: resolvedFallbackStrategy,
|
|
44
|
+
logger: config.logger,
|
|
45
|
+
}),
|
|
46
|
+
'round-robin': new RoundRobinRoutingStrategy(baseConfig),
|
|
59
47
|
};
|
|
60
48
|
return routingMap[strategy];
|
|
61
49
|
};
|
|
@@ -75,91 +63,103 @@ export const useVerificationStrategy = (strategy, config) => {
|
|
|
75
63
|
return verificationMap[strategy];
|
|
76
64
|
};
|
|
77
65
|
/**
|
|
78
|
-
* Creates a Wayfinder client with the specified configuration
|
|
79
|
-
* Uses
|
|
66
|
+
* Creates a Wayfinder client with the specified configuration.
|
|
67
|
+
* Uses the trusted peers gateways provider and random routing by default.
|
|
80
68
|
*/
|
|
81
69
|
export function createWayfinderClient(options = {}) {
|
|
82
|
-
const {
|
|
70
|
+
const { cache = false, logger, routingStrategy: customRoutingStrategy, verificationStrategy: customVerificationStrategy, telemetry, } = options;
|
|
71
|
+
const resolvedLogger = logger ?? defaultLogger;
|
|
72
|
+
const deprecatedGuidance = [
|
|
73
|
+
['routing', 'Provide a `routingStrategy` instance instead.'],
|
|
74
|
+
['verification', 'Provide a `verificationStrategy` instance instead.'],
|
|
75
|
+
[
|
|
76
|
+
'gatewaySelection',
|
|
77
|
+
'Configure gateway selection via your custom `routingStrategy`.',
|
|
78
|
+
],
|
|
79
|
+
[
|
|
80
|
+
'gatewaysProvider',
|
|
81
|
+
'Instantiate `Wayfinder` directly when providing custom gateways providers.',
|
|
82
|
+
],
|
|
83
|
+
[
|
|
84
|
+
'fallbackStrategy',
|
|
85
|
+
'Compose fallback behavior directly in your `routingStrategy`.',
|
|
86
|
+
],
|
|
87
|
+
[
|
|
88
|
+
'preferredGateway',
|
|
89
|
+
'Configure preferred gateways within your `routingStrategy`.',
|
|
90
|
+
],
|
|
91
|
+
[
|
|
92
|
+
'ario',
|
|
93
|
+
'Instantiate `Wayfinder` directly and supply your own gateways provider.',
|
|
94
|
+
],
|
|
95
|
+
[
|
|
96
|
+
'trustedGateways',
|
|
97
|
+
'Configure trusted gateways via your `verificationStrategy`.',
|
|
98
|
+
],
|
|
99
|
+
];
|
|
100
|
+
for (const [option, guidance] of deprecatedGuidance) {
|
|
101
|
+
if (Object.prototype.hasOwnProperty.call(options, option)) {
|
|
102
|
+
warnDeprecatedOption(resolvedLogger, option, guidance);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
83
105
|
// Parse cache configuration
|
|
84
106
|
const cacheEnabled = !!cache;
|
|
85
107
|
const cacheTTLSeconds = typeof cache === 'object' ? cache.ttlSeconds : 300; // 5 minutes default
|
|
86
|
-
// Set up gateways provider
|
|
87
|
-
let gatewaysProvider;
|
|
88
|
-
if (customGatewaysProvider) {
|
|
89
|
-
gatewaysProvider = customGatewaysProvider;
|
|
90
|
-
}
|
|
91
|
-
else if (ario) {
|
|
92
|
-
const { sortBy, sortOrder } = selectionSortMap[gatewaySelection];
|
|
93
|
-
gatewaysProvider = new NetworkGatewaysProvider({
|
|
94
|
-
ario,
|
|
95
|
-
sortBy,
|
|
96
|
-
sortOrder,
|
|
97
|
-
limit: 10,
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
else {
|
|
101
|
-
// Fall back to trusted peers gateway provider when no ARIO instance is provided
|
|
102
|
-
gatewaysProvider = new TrustedPeersGatewaysProvider({
|
|
103
|
-
trustedGateway: trustedGateways[0] || 'https://arweave.net',
|
|
104
|
-
logger,
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
// Wrap with cache if enabled
|
|
108
|
-
if (cacheEnabled) {
|
|
109
|
-
if (isBrowser()) {
|
|
110
|
-
gatewaysProvider = new LocalStorageGatewaysProvider({
|
|
111
|
-
gatewaysProvider: gatewaysProvider,
|
|
112
|
-
ttlSeconds: cacheTTLSeconds,
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
else {
|
|
116
|
-
gatewaysProvider = new SimpleCacheGatewaysProvider({
|
|
117
|
-
gatewaysProvider: gatewaysProvider,
|
|
118
|
-
ttlSeconds: cacheTTLSeconds,
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
108
|
// Set up routing strategy
|
|
123
109
|
let routingStrategy;
|
|
124
110
|
if (customRoutingStrategy) {
|
|
125
111
|
routingStrategy = customRoutingStrategy;
|
|
126
112
|
}
|
|
127
113
|
else {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
114
|
+
// Create base gateways provider
|
|
115
|
+
let gatewaysProvider = new TrustedPeersGatewaysProvider({
|
|
116
|
+
trustedGateway: DEFAULT_TRUSTED_GATEWAY,
|
|
117
|
+
logger: resolvedLogger,
|
|
118
|
+
});
|
|
119
|
+
// Wrap gateways provider with cache if enabled
|
|
120
|
+
if (cacheEnabled) {
|
|
121
|
+
if (isBrowser()) {
|
|
122
|
+
gatewaysProvider = new LocalStorageGatewaysProvider({
|
|
123
|
+
gatewaysProvider: gatewaysProvider,
|
|
124
|
+
ttlSeconds: cacheTTLSeconds,
|
|
125
|
+
logger: resolvedLogger,
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
gatewaysProvider = new SimpleCacheGatewaysProvider({
|
|
130
|
+
gatewaysProvider: gatewaysProvider,
|
|
131
|
+
ttlSeconds: cacheTTLSeconds,
|
|
132
|
+
logger: resolvedLogger,
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
// Create routing strategy with the gateways provider
|
|
137
|
+
routingStrategy = useRoutingStrategy('random', {
|
|
138
|
+
gatewaysProvider,
|
|
139
|
+
logger: resolvedLogger,
|
|
131
140
|
});
|
|
132
|
-
// Wrap with cache if enabled
|
|
141
|
+
// Wrap routing strategy with cache if enabled
|
|
133
142
|
if (cacheEnabled) {
|
|
134
143
|
// TODO: add browser cache support for routing strategy
|
|
135
144
|
routingStrategy = new SimpleCacheRoutingStrategy({
|
|
136
145
|
routingStrategy,
|
|
137
146
|
ttlSeconds: cacheTTLSeconds,
|
|
147
|
+
logger: resolvedLogger,
|
|
138
148
|
});
|
|
139
149
|
}
|
|
140
150
|
}
|
|
141
151
|
// Set up verification strategy
|
|
142
|
-
|
|
143
|
-
const verificationEnabled = true;
|
|
144
|
-
if (customVerificationStrategy) {
|
|
145
|
-
verificationStrategy = customVerificationStrategy;
|
|
146
|
-
}
|
|
147
|
-
else {
|
|
148
|
-
verificationStrategy = useVerificationStrategy(verification, {
|
|
149
|
-
trustedGateways: trustedGateways.map((url) => new URL(url)),
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
+
const verificationStrategy = customVerificationStrategy;
|
|
152
153
|
// Create Wayfinder options
|
|
153
154
|
const wayfinderOptions = {
|
|
154
|
-
logger,
|
|
155
|
-
gatewaysProvider,
|
|
155
|
+
logger: resolvedLogger,
|
|
156
156
|
routingSettings: {
|
|
157
157
|
strategy: routingStrategy,
|
|
158
158
|
},
|
|
159
159
|
telemetrySettings: telemetry,
|
|
160
160
|
};
|
|
161
161
|
// Only add verification settings if not disabled
|
|
162
|
-
if (
|
|
162
|
+
if (verificationStrategy) {
|
|
163
163
|
wayfinderOptions.verificationSettings = {
|
|
164
164
|
enabled: true,
|
|
165
165
|
strategy: verificationStrategy,
|
package/dist/routing/ping.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { GatewaysProvider, Logger, RoutingStrategy } from '../types.js';
|
|
2
2
|
export declare class FastestPingRoutingStrategy implements RoutingStrategy {
|
|
3
|
+
readonly name = "fastest-ping";
|
|
3
4
|
private timeoutMs;
|
|
4
5
|
private logger;
|
|
5
6
|
private maxConcurrency;
|
|
@@ -23,10 +24,11 @@ export declare class FastestPingRoutingStrategy implements RoutingStrategy {
|
|
|
23
24
|
* If the HEAD check fails after all retries, it throws an error.
|
|
24
25
|
*/
|
|
25
26
|
export declare class PingRoutingStrategy implements RoutingStrategy {
|
|
26
|
-
|
|
27
|
+
readonly name = "ping";
|
|
28
|
+
readonly routingStrategy: RoutingStrategy;
|
|
27
29
|
private logger;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
+
readonly retries: number;
|
|
31
|
+
readonly timeoutMs: number;
|
|
30
32
|
private gatewaysProvider?;
|
|
31
33
|
constructor({ routingStrategy, logger, retries, timeoutMs, gatewaysProvider, }: {
|
|
32
34
|
routingStrategy: RoutingStrategy;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ping.d.ts","sourceRoot":"","sources":["../../src/routing/ping.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE7E,qBAAa,0BAA2B,YAAW,eAAe;IAChE,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,cAAc,CAAS;IAC/B,OAAO,CAAC,gBAAgB,CAAC,CAAmB;gBAEhC,EACV,SAAe,EACf,cAAmB,EACnB,MAAsB,EACtB,gBAAgB,GACjB,GAAE;QACD,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,cAAc,CAAC,EAAE,MAAM,CAAC;QACxB,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;KAChC;IAOA,aAAa,CAAC,EAClB,QAAQ,EACR,IAAS,E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S,EAAE,MAAM,CAAC;IAClC,OAAO,CAAC,gBAAgB,CAAC,CAAmB;gBAEhC,EACV,eAAe,EACf,MAAsB,EACtB,OAAW,EACX,SAAgB,EAChB,gBAAgB,GACjB,EAAE;QACD,eAAe,EAAE,eAAe,CAAC;QACjC,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;KACrC;IAQK,aAAa,CAAC,MAAM,EAAE;QAC1B,QAAQ,CAAC,EAAE,GAAG,EAAE,CAAC;QACjB,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,GAAG,OAAO,CAAC,GAAG,CAAC;CAkFjB"}
|
package/dist/routing/ping.js
CHANGED
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
import { pLimit } from 'plimit-lit';
|
|
18
18
|
import { defaultLogger } from '../logger.js';
|
|
19
19
|
export class FastestPingRoutingStrategy {
|
|
20
|
+
name = 'fastest-ping';
|
|
20
21
|
timeoutMs;
|
|
21
22
|
logger;
|
|
22
23
|
maxConcurrency;
|
|
@@ -102,6 +103,7 @@ export class FastestPingRoutingStrategy {
|
|
|
102
103
|
* If the HEAD check fails after all retries, it throws an error.
|
|
103
104
|
*/
|
|
104
105
|
export class PingRoutingStrategy {
|
|
106
|
+
name = 'ping';
|
|
105
107
|
routingStrategy;
|
|
106
108
|
logger;
|
|
107
109
|
retries;
|
package/dist/telemetry.d.ts
CHANGED
|
@@ -19,18 +19,17 @@ import { BasicTracerProvider } from '@opentelemetry/sdk-trace-base';
|
|
|
19
19
|
import { NodeTracerProvider } from '@opentelemetry/sdk-trace-node';
|
|
20
20
|
import { WebTracerProvider } from '@opentelemetry/sdk-trace-web';
|
|
21
21
|
import { WayfinderEmitter } from './emitter.js';
|
|
22
|
-
import type {
|
|
22
|
+
import type { TelemetrySettings, WayfinderOptions } from './types.js';
|
|
23
23
|
export declare const initTelemetry: ({ enabled, sampleRate, exporterUrl, apiKey, clientName, clientVersion, }: TelemetrySettings) => {
|
|
24
24
|
tracerProvider: WebTracerProvider | NodeTracerProvider | BasicTracerProvider;
|
|
25
25
|
tracer: Tracer;
|
|
26
26
|
} | undefined;
|
|
27
|
-
export declare const startRequestSpans: ({ originalUrl, emitter, tracer, verificationSettings, routingSettings,
|
|
27
|
+
export declare const startRequestSpans: ({ originalUrl, emitter, tracer, verificationSettings, routingSettings, }?: {
|
|
28
28
|
originalUrl?: string;
|
|
29
29
|
emitter?: WayfinderEmitter;
|
|
30
30
|
tracer?: Tracer;
|
|
31
31
|
verificationSettings?: WayfinderOptions["verificationSettings"];
|
|
32
32
|
routingSettings?: WayfinderOptions["routingSettings"];
|
|
33
|
-
gatewaysProvider?: GatewaysProvider;
|
|
34
33
|
}) => {
|
|
35
34
|
parentSpan: Span | undefined;
|
|
36
35
|
routingSpan: Span | undefined;
|
package/dist/telemetry.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"telemetry.d.ts","sourceRoot":"","sources":["../src/telemetry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAGL,IAAI,EACJ,KAAK,MAAM,EAIZ,MAAM,oBAAoB,CAAC;AAI5B,OAAO,EACL,mBAAmB,EAIpB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAKjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"telemetry.d.ts","sourceRoot":"","sources":["../src/telemetry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAGL,IAAI,EACJ,KAAK,MAAM,EAIZ,MAAM,oBAAoB,CAAC;AAI5B,OAAO,EACL,mBAAmB,EAIpB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAKjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,KAAK,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAkBtE,eAAO,MAAM,aAAa,GAAI,0EAO3B,iBAAiB,KAChB;IACE,cAAc,EACV,iBAAiB,GACjB,kBAAkB,GAClB,mBAAmB,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC;CAChB,GACD,SAuEH,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAAI,2EAM/B;IACD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,gBAAgB,CAAC;IAC3B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,oBAAoB,CAAC,EAAE,gBAAgB,CAAC,sBAAsB,CAAC,CAAC;IAChE,eAAe,CAAC,EAAE,gBAAgB,CAAC,iBAAiB,CAAC,CAAC;CAClD;;;;CA8EL,CAAC"}
|
package/dist/telemetry.js
CHANGED
|
@@ -98,7 +98,7 @@ clientName, clientVersion, }) => {
|
|
|
98
98
|
tracer,
|
|
99
99
|
};
|
|
100
100
|
};
|
|
101
|
-
export const startRequestSpans = ({ originalUrl, emitter, tracer, verificationSettings, routingSettings,
|
|
101
|
+
export const startRequestSpans = ({ originalUrl, emitter, tracer, verificationSettings, routingSettings, } = {}) => {
|
|
102
102
|
const parentSpan = tracer?.startSpan('wayfinder.request', {
|
|
103
103
|
attributes: {
|
|
104
104
|
originalUrl: originalUrl ?? 'undefined',
|
|
@@ -109,7 +109,6 @@ export const startRequestSpans = ({ originalUrl, emitter, tracer, verificationSe
|
|
|
109
109
|
?.map((gateway) => gateway.toString())
|
|
110
110
|
.join(','),
|
|
111
111
|
'routing.strategy': routingSettings?.strategy?.constructor.name ?? 'undefined',
|
|
112
|
-
gatewaysProvider: gatewaysProvider?.constructor.name,
|
|
113
112
|
},
|
|
114
113
|
}, context.active());
|
|
115
114
|
let routingSpan;
|
package/dist/types.d.ts
CHANGED
|
@@ -99,6 +99,7 @@ export interface WayfinderOptions {
|
|
|
99
99
|
logger?: Logger;
|
|
100
100
|
/**
|
|
101
101
|
* The gateways provider to use for routing requests.
|
|
102
|
+
* @deprecated Use routing strategies with their own gateways providers instead.
|
|
102
103
|
*/
|
|
103
104
|
gatewaysProvider?: GatewaysProvider;
|
|
104
105
|
/**
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAIrD;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,CAC3B,KAAK,EAAE,GAAG,GAAG,WAAW,EACxB,IAAI,CAAC,EAAE,WAAW,GAAG;IACnB,oBAAoB,CAAC,EAAE,gBAAgB,CAAC,sBAAsB,CAAC,CAAC;IAChE,eAAe,CAAC,EAAE,gBAAgB,CAAC,iBAAiB,CAAC,CAAC;CACvD,KACE,OAAO,CAAC,QAAQ,CAAC,CAAC;AAEvB,MAAM,MAAM,cAAc,GAAG;IAC3B,iBAAiB,EAAE;QAAE,WAAW,EAAE,MAAM,CAAA;KAAE,CAAC;IAC3C,iBAAiB,EAAE;QAAE,WAAW,EAAE,MAAM,CAAA;KAAE,CAAC;IAC3C,mBAAmB,EAAE;QACnB,WAAW,EAAE,MAAM,CAAC;QACpB,eAAe,EAAE,MAAM,CAAC;QACxB,WAAW,EAAE,MAAM,CAAC;KACrB,CAAC;IACF,gBAAgB,EAAE,KAAK,CAAC;IACxB,wBAAwB,EAAE;QAAE,IAAI,EAAE,MAA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MAAM,MAAM,UAAU,GAAG,cAAc,CAAC,UAAU,CAAC,GAAG,aAAa,CAAC,UAAU,CAAC,CAAC;AAEhF,MAAM,WAAW,gBAAgB;IAC/B,WAAW,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;CAC/B;AAED,MAAM,WAAW,eAAe;IAC9B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,aAAa,CAAC,MAAM,EAAE;QACpB,QAAQ,CAAC,EAAE,GAAG,EAAE,CAAC;QACjB,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;CAClB;AAED,MAAM,WAAW,oBAAoB;IACnC,eAAe,EAAE,GAAG,EAAE,CAAC;IACvB,UAAU,CAAC,MAAM,EAAE;QACjB,IAAI,EAAE,UAAU,CAAC;QACjB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAChC,IAAI,EAAE,MAAM,CAAC;KACd,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACnB;AAED,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,QAAQ,GAAG,aAAa,CAAC,CAAC;CACvE"}
|
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.
|
|
17
|
+
export declare const WAYFINDER_CORE_VERSION = "v1.7.0";
|
|
18
18
|
//# sourceMappingURL=version.d.ts.map
|
package/dist/version.js
CHANGED
package/dist/wayfinder.d.ts
CHANGED
|
@@ -75,9 +75,8 @@ export declare function tapAndVerifyReadableStream({ originalStream, contentLeng
|
|
|
75
75
|
* @param resolveUrl - the function to construct the redirect url for ar:// requests
|
|
76
76
|
* @returns a wrapped fetch function that supports ar:// protocol and always returns Response
|
|
77
77
|
*/
|
|
78
|
-
export declare const wayfinderFetch: ({ logger,
|
|
78
|
+
export declare const wayfinderFetch: ({ logger, verificationSettings, routingSettings, emitter, tracer, }: {
|
|
79
79
|
logger?: Logger;
|
|
80
|
-
gatewaysProvider: GatewaysProvider;
|
|
81
80
|
verificationSettings: NonNullable<WayfinderOptions["verificationSettings"]>;
|
|
82
81
|
routingSettings: NonNullable<WayfinderOptions["routingSettings"]>;
|
|
83
82
|
emitter?: WayfinderEmitter;
|
|
@@ -93,13 +92,7 @@ export declare class Wayfinder {
|
|
|
93
92
|
/**
|
|
94
93
|
* The gateways provider is responsible for providing the list of gateways to use for routing requests.
|
|
95
94
|
*
|
|
96
|
-
*
|
|
97
|
-
* const wayfinder = new Wayfinder({
|
|
98
|
-
* gatewaysProvider: new SimpleCacheGatewaysProvider({
|
|
99
|
-
* gatewaysProvider: new NetworkGatewaysProvider({ ario: ARIO.mainnet() }),
|
|
100
|
-
* ttlSeconds: 60 * 60 * 24, // 1 day
|
|
101
|
-
* }),
|
|
102
|
-
* });
|
|
95
|
+
* Useful if you want to get the list of gateways from a dynamic source.
|
|
103
96
|
*/
|
|
104
97
|
readonly gatewaysProvider: GatewaysProvider;
|
|
105
98
|
/**
|
|
@@ -194,6 +187,12 @@ export declare class Wayfinder {
|
|
|
194
187
|
* @param options - Wayfinder configuration options
|
|
195
188
|
*/
|
|
196
189
|
constructor({ logger, gatewaysProvider, verificationSettings, routingSettings, telemetrySettings, }?: WayfinderOptions);
|
|
190
|
+
/**
|
|
191
|
+
* Helper method to inject gatewaysProvider into routing strategies that support it
|
|
192
|
+
* @param strategy - The routing strategy to inject into
|
|
193
|
+
* @param gatewaysProvider - The gateways provider to inject
|
|
194
|
+
*/
|
|
195
|
+
private injectGatewaysProviderIntoStrategy;
|
|
197
196
|
/**
|
|
198
197
|
* Sets the routing strategy to use for routing requests.
|
|
199
198
|
*
|
package/dist/w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;;;;;;;;OA4BG;IACH,OAAO,CACL,KAAK,EAAE,GAAG,GAAG,WAAW,EACxB,IAAI,CAAC,EAAE,WAAW,GAAG;QACnB,oBAAoB,CAAC,EAAE,WAAW,CAChC,gBAAgB,CAAC,sBAAsB,CAAC,CACzC,CAAC;QACF,eAAe,CAAC,EAAE,WAAW,CAAC,gBAAgB,CAAC,iBAAiB,CAAC,CAAC,CAAC;KACpE,GACA,OAAO,CAAC,QAAQ,CAAC;IAUpB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAgCG;IACG,UAAU,CAAC,MAAM,EAAE,kBAAkB,GAAG,OAAO,CAAC,GAAG,CAAC;CAgD3D"}
|
package/dist/wayfinder.js
CHANGED
|
@@ -220,7 +220,7 @@ export function tapAndVerifyReadableStream({ originalStream, contentLength, veri
|
|
|
220
220
|
* @param resolveUrl - the function to construct the redirect url for ar:// requests
|
|
221
221
|
* @returns a wrapped fetch function that supports ar:// protocol and always returns Response
|
|
222
222
|
*/
|
|
223
|
-
export const wayfinderFetch = ({ logger = defaultLogger,
|
|
223
|
+
export const wayfinderFetch = ({ logger = defaultLogger, verificationSettings, routingSettings, emitter, tracer, }) => {
|
|
224
224
|
return async (input, init) => {
|
|
225
225
|
const {
|
|
226
226
|
// allows for overriding the verification and routing settings for a single request
|
|
@@ -235,7 +235,6 @@ export const wayfinderFetch = ({ logger = defaultLogger, gatewaysProvider, verif
|
|
|
235
235
|
originalUrl: url,
|
|
236
236
|
verificationSettings: requestVerificationSettings ?? verificationSettings,
|
|
237
237
|
routingSettings: requestRoutingSettings ?? routingSettings,
|
|
238
|
-
gatewaysProvider,
|
|
239
238
|
emitter: requestEmitter,
|
|
240
239
|
tracer,
|
|
241
240
|
});
|
|
@@ -260,7 +259,6 @@ export const wayfinderFetch = ({ logger = defaultLogger, gatewaysProvider, verif
|
|
|
260
259
|
const { subdomain, path } = extractRoutingInfo(url);
|
|
261
260
|
// select the target gateway
|
|
262
261
|
const selectedGateway = await routingSettings.strategy?.selectGateway({
|
|
263
|
-
gateways: await gatewaysProvider.getGateways(),
|
|
264
262
|
path,
|
|
265
263
|
subdomain,
|
|
266
264
|
});
|
|
@@ -420,13 +418,7 @@ export class Wayfinder {
|
|
|
420
418
|
/**
|
|
421
419
|
* The gateways provider is responsible for providing the list of gateways to use for routing requests.
|
|
422
420
|
*
|
|
423
|
-
*
|
|
424
|
-
* const wayfinder = new Wayfinder({
|
|
425
|
-
* gatewaysProvider: new SimpleCacheGatewaysProvider({
|
|
426
|
-
* gatewaysProvider: new NetworkGatewaysProvider({ ario: ARIO.mainnet() }),
|
|
427
|
-
* ttlSeconds: 60 * 60 * 24, // 1 day
|
|
428
|
-
* }),
|
|
429
|
-
* });
|
|
421
|
+
* Useful if you want to get the list of gateways from a dynamic source.
|
|
430
422
|
*/
|
|
431
423
|
gatewaysProvider;
|
|
432
424
|
/**
|
|
@@ -521,7 +513,7 @@ export class Wayfinder {
|
|
|
521
513
|
constructor({ logger, gatewaysProvider, verificationSettings, routingSettings, telemetrySettings, } = {}) {
|
|
522
514
|
// default logger to use if no logger is provided
|
|
523
515
|
this.logger = logger ?? defaultLogger;
|
|
524
|
-
//
|
|
516
|
+
// deprecated - kept for backwards compatibility
|
|
525
517
|
this.gatewaysProvider =
|
|
526
518
|
gatewaysProvider ??
|
|
527
519
|
new TrustedPeersGatewaysProvider({
|
|
@@ -543,16 +535,24 @@ export class Wayfinder {
|
|
|
543
535
|
// overwrite the default settings with the provided ones
|
|
544
536
|
...verificationSettings,
|
|
545
537
|
};
|
|
546
|
-
// default routing settings
|
|
538
|
+
// default routing settings with backwards compatibility for gatewaysProvider
|
|
547
539
|
this.routingSettings = {
|
|
548
540
|
events: {},
|
|
549
541
|
strategy: new PingRoutingStrategy({
|
|
550
542
|
logger,
|
|
551
|
-
routingStrategy: new RandomRoutingStrategy({
|
|
543
|
+
routingStrategy: new RandomRoutingStrategy({
|
|
544
|
+
logger,
|
|
545
|
+
// use the gateways provider given, or fallback to the default if non provided
|
|
546
|
+
gatewaysProvider: this.gatewaysProvider,
|
|
547
|
+
}),
|
|
552
548
|
}),
|
|
553
549
|
// overwrite the default settings with the provided ones
|
|
554
550
|
...routingSettings,
|
|
555
551
|
};
|
|
552
|
+
// If a custom routing strategy is provided, inject the gatewaysProvider into it
|
|
553
|
+
if (routingSettings?.strategy) {
|
|
554
|
+
this.injectGatewaysProviderIntoStrategy(routingSettings.strategy, this.gatewaysProvider);
|
|
555
|
+
}
|
|
556
556
|
this.emitter = new WayfinderEmitter({
|
|
557
557
|
verification: this.verificationSettings?.events,
|
|
558
558
|
routing: this.routingSettings?.events,
|
|
@@ -588,7 +588,25 @@ export class Wayfinder {
|
|
|
588
588
|
telemetrySettings: this.telemetrySettings,
|
|
589
589
|
});
|
|
590
590
|
}
|
|
591
|
-
|
|
591
|
+
/**
|
|
592
|
+
* Helper method to inject gatewaysProvider into routing strategies that support it
|
|
593
|
+
* @param strategy - The routing strategy to inject into
|
|
594
|
+
* @param gatewaysProvider - The gateways provider to inject
|
|
595
|
+
*/
|
|
596
|
+
injectGatewaysProviderIntoStrategy(strategy, gatewaysProvider) {
|
|
597
|
+
// Check if the strategy has a gatewaysProvider property that can be set
|
|
598
|
+
if ('gatewaysProvider' in strategy &&
|
|
599
|
+
strategy.gatewaysProvider === undefined) {
|
|
600
|
+
strategy.gatewaysProvider = gatewaysProvider;
|
|
601
|
+
}
|
|
602
|
+
// Handle composite strategies that might have nested strategies
|
|
603
|
+
if ('routingStrategy' in strategy && strategy.routingStrategy) {
|
|
604
|
+
this.injectGatewaysProviderIntoStrategy(strategy.routingStrategy, gatewaysProvider);
|
|
605
|
+
}
|
|
606
|
+
if ('fallbackStrategy' in strategy && strategy.fallbackStrategy) {
|
|
607
|
+
this.injectGatewaysProviderIntoStrategy(strategy.fallbackStrategy, gatewaysProvider);
|
|
608
|
+
}
|
|
609
|
+
}
|
|
592
610
|
/**
|
|
593
611
|
* Sets the routing strategy to use for routing requests.
|
|
594
612
|
*
|
|
@@ -600,6 +618,10 @@ export class Wayfinder {
|
|
|
600
618
|
*/
|
|
601
619
|
setRoutingStrategy(strategy) {
|
|
602
620
|
this.routingSettings.strategy = strategy;
|
|
621
|
+
// If a deprecated gatewaysProvider is set, inject it into the new strategy
|
|
622
|
+
if (this.gatewaysProvider) {
|
|
623
|
+
this.injectGatewaysProviderIntoStrategy(strategy, this.gatewaysProvider);
|
|
624
|
+
}
|
|
603
625
|
}
|
|
604
626
|
/**
|
|
605
627
|
* Sets the verification strategy to use for verifying requests.
|
|
@@ -694,7 +716,6 @@ export class Wayfinder {
|
|
|
694
716
|
request(input, init) {
|
|
695
717
|
return wayfinderFetch({
|
|
696
718
|
logger: this.logger,
|
|
697
|
-
gatewaysProvider: this.gatewaysProvider,
|
|
698
719
|
emitter: this.emitter,
|
|
699
720
|
routingSettings: this.routingSettings,
|
|
700
721
|
verificationSettings: this.verificationSettings,
|
|
@@ -753,7 +774,6 @@ export class Wayfinder {
|
|
|
753
774
|
resolveUrlSpan?.setAttribute('subdomain', subdomain);
|
|
754
775
|
resolveUrlSpan?.setAttribute('path', path);
|
|
755
776
|
const selectedGateway = await this.routingSettings.strategy.selectGateway({
|
|
756
|
-
gateways: await this.gatewaysProvider.getGateways(),
|
|
757
777
|
path,
|
|
758
778
|
subdomain,
|
|
759
779
|
});
|