@ar.io/wayfinder-core 0.0.4-alpha.0 → 0.0.4-alpha.1

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.
@@ -118,18 +118,12 @@ export declare function sandboxFromId(id: string): string;
118
118
  * @param resolveUrl - the function to construct the redirect url for ar:// requests
119
119
  * @returns a wrapped fetch function that supports ar:// protocol and always returns Response
120
120
  */
121
- export declare const wayfinderRequest: ({ getGateways, resolveUrl, verifyData, selectGateway, emitter, logger, strict, }: {
122
- getGateways: GatewaysProvider["getGateways"];
123
- selectGateway: RoutingStrategy["selectGateway"];
124
- resolveUrl: (params: {
125
- originalUrl: string;
126
- selectedGateway: URL;
127
- logger?: Logger;
128
- }) => URL;
129
- verifyData?: VerificationStrategy["verifyData"];
121
+ export declare const wayfinderFetch: ({ emitter, logger, gatewaysProvider, verificationSettings, routingSettings, }: {
130
122
  logger?: Logger;
131
123
  emitter?: WayfinderEmitter;
132
- strict?: boolean;
124
+ gatewaysProvider: GatewaysProvider;
125
+ verificationSettings: NonNullable<WayfinderOptions["verificationSettings"]>;
126
+ routingSettings: NonNullable<WayfinderOptions["routingSettings"]>;
133
127
  }) => (input: URL | RequestInfo, init?: RequestInit) => Promise<Response>;
134
128
  /**
135
129
  * Configuration options for the Wayfinder
@@ -149,10 +143,18 @@ export interface WayfinderOptions {
149
143
  */
150
144
  verificationSettings?: {
151
145
  /**
152
- * Whether verification is enabled. If false, verification will be skipped for all requests.
146
+ * Whether verification is enabled. If false, verification will be skipped for all requests. If true, strategy must be provided.
153
147
  * @default true
154
148
  */
155
149
  enabled?: boolean;
150
+ /**
151
+ * The events to use for verification
152
+ */
153
+ events?: WayfinderVerificationEventArgs | undefined;
154
+ /**
155
+ * The verification strategy to use for verifying data
156
+ */
157
+ strategy: VerificationStrategy;
156
158
  /**
157
159
  * Whether verification should be strict (blocking)
158
160
  * If true, verification failures will cause requests to fail
@@ -160,27 +162,19 @@ export interface WayfinderOptions {
160
162
  * @default false
161
163
  */
162
164
  strict?: boolean;
163
- /**
164
- * The events to use for verification
165
- */
166
- events?: WayfinderVerificationEventArgs;
167
- /**
168
- * The verification strategy to use for verifying data
169
- */
170
- strategy?: VerificationStrategy;
171
165
  };
172
166
  /**
173
167
  * The routing settings to use for routing requests
174
168
  */
175
169
  routingSettings?: {
176
- /**
177
- * The routing strategy to use for routing requests
178
- */
179
- strategy?: RoutingStrategy;
180
170
  /**
181
171
  * The events to use for routing requests
182
172
  */
183
173
  events?: WayfinderRoutingEventArgs;
174
+ /**
175
+ * The routing strategy to use for routing requests
176
+ */
177
+ strategy: RoutingStrategy;
184
178
  };
185
179
  }
186
180
  /**
@@ -200,13 +194,15 @@ export declare class Wayfinder {
200
194
  */
201
195
  readonly gatewaysProvider: GatewaysProvider;
202
196
  /**
203
- * The routing strategy to use when routing requests.
197
+ * The routing settings to use when routing requests.
198
+ * This includes the routing strategy and event handlers for routing events.
199
+ * If not provided, the default FastestPingRoutingStrategy will be used.
204
200
  */
205
- readonly routingStrategy: RoutingStrategy;
201
+ readonly routingSettings: NonNullable<WayfinderOptions['routingSettings']>;
206
202
  /**
207
- * The verification strategy to use when verifying data.
203
+ * The verification settings to use when verifying data.
208
204
  */
209
- readonly verificationStrategy: VerificationStrategy;
205
+ readonly verificationSettings: WayfinderOptions['verificationSettings'];
210
206
  /**
211
207
  * A helper function that resolves the redirect url for ar:// requests to a target gateway.
212
208
  *
@@ -255,23 +251,11 @@ export declare class Wayfinder {
255
251
  * console.error('Verification failed', error);
256
252
  * }
257
253
  */
258
- readonly request: WayfinderHttpClient;
259
- /**
260
- * The function that verifies the data hash for a given transaction id.
261
- *
262
- * @example
263
- * const wayfinder = new Wayfinder({
264
- * verifyData: (data, txId) => {
265
- * // some custom verification logic
266
- * return true;
267
- * },
268
- * });
269
- */
270
- readonly verifyData: VerificationStrategy['verifyData'];
254
+ request: WayfinderHttpClient;
271
255
  /**
272
256
  * The logger used by this Wayfinder instance
273
257
  */
274
- readonly logger: Logger;
258
+ protected logger: Logger;
275
259
  /**
276
260
  * The event emitter for wayfinder that emits routing and verification events.
277
261
  *
@@ -331,7 +315,8 @@ export declare class Wayfinder {
331
315
  * The constructor for the wayfinder
332
316
  * @param options - Wayfinder configuration options
333
317
  */
334
- constructor({ logger, gatewaysProvider, verificationSettings, routingSettings, }: WayfinderOptions);
318
+ constructor({ logger, gatewaysProvider, // forcing it to be required to avoid making ar-io-sdk a dependency
319
+ verificationSettings, routingSettings, }: WayfinderOptions);
335
320
  }
336
321
  export {};
337
322
  //# sourceMappingURL=wayfinder.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"wayfinder.d.ts","sourceRoot":"","sources":["../src/wayfinder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAG7C,OAAO,EACL,gBAAgB,EAChB,eAAe,EACf,oBAAoB,EACrB,MAAM,uBAAuB,CAAC;AAK/B,KAAK,mBAAmB,GAAG,OAAO,KAAK,CAAC;AAExC;;;GAGG;AACH,MAAM,WAAW,MAAM;IACrB,KAAK,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;IACjD,IAAI,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;IAChD,IAAI,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;IAChD,KAAK,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;CAClD;AAED;;GAEG;AACH,eAAO,MAAM,aAAa,EAAE,MAK3B,CAAC;AAGF,eAAO,MAAM,SAAS,QAAuB,CAAC;AAC9C,eAAO,MAAM,SAAS,QAAwB,CAAC;AAE/C;;;;;GAKG;A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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAqDG;IACH,SAAgB,OAAO,EAAE,gBAAgB,CAAC;IAE1C;;;OAGG;gBACS,EACV,MAAsB,EACtB,gBAAgB,EAAE,mEAAmE;IACrF,oBAAoB,EACpB,eAAe,GAChB,EAAE,gBAAgB;CA8EpB"}
package/dist/wayfinder.js CHANGED
@@ -198,12 +198,9 @@ export function sandboxFromId(id) {
198
198
  * @param resolveUrl - the function to construct the redirect url for ar:// requests
199
199
  * @returns a wrapped fetch function that supports ar:// protocol and always returns Response
200
200
  */
201
- export const wayfinderRequest = ({ getGateways, resolveUrl, verifyData, selectGateway, emitter = new WayfinderEmitter(), logger = defaultLogger, strict = false, }) => {
201
+ export const wayfinderFetch = ({ emitter = new WayfinderEmitter(), logger = defaultLogger, gatewaysProvider, verificationSettings, routingSettings, }) => {
202
202
  return async (input, init) => {
203
203
  const url = input instanceof URL ? input.toString() : input.toString();
204
- console.log('URL', {
205
- url,
206
- });
207
204
  if (!url.toString().startsWith('ar://')) {
208
205
  logger?.debug('URL is not a wayfinder url, skipping routing', {
209
206
  input,
@@ -221,17 +218,20 @@ export const wayfinderRequest = ({ getGateways, resolveUrl, verifyData, selectGa
221
218
  for (let i = 0; i < maxRetries; i++) {
222
219
  try {
223
220
  // select the target gateway
224
- const selectedGateway = await selectGateway({
225
- gateways: await getGateways(),
221
+ const selectedGateway = await routingSettings.strategy?.selectGateway({
222
+ gateways: await gatewaysProvider.getGateways(),
226
223
  path: url.split('/').slice(1).join('/'), // everything after the first /
227
224
  subdomain: '',
228
225
  });
226
+ if (!selectedGateway) {
227
+ throw new Error('Failed to select a gateway');
228
+ }
229
229
  logger?.debug('Selected gateway', {
230
230
  originalUrl: url,
231
- selectedGateway: selectedGateway.toString(),
231
+ selectedGateway: selectedGateway?.toString(),
232
232
  });
233
233
  // route the request to the target gateway
234
- const redirectUrl = resolveUrl({
234
+ const redirectUrl = await resolveWayfinderUrl({
235
235
  originalUrl: url.toString(),
236
236
  selectedGateway,
237
237
  logger,
@@ -258,7 +258,8 @@ export const wayfinderRequest = ({ getGateways, resolveUrl, verifyData, selectGa
258
258
  });
259
259
  // only verify data if the redirect url is different from the original url
260
260
  if (redirectUrl.toString() !== url) {
261
- if (verifyData) {
261
+ if (verificationSettings.enabled &&
262
+ verificationSettings.strategy?.verifyData) {
262
263
  const headers = response.headers;
263
264
  // transaction id is either in the response headers or the path of the request as the first parameter
264
265
  const txId = headers.get('x-arns-resolved-id') ??
@@ -285,10 +286,10 @@ export const wayfinderRequest = ({ getGateways, resolveUrl, verifyData, selectGa
285
286
  const newClientStream = tapAndVerifyReadableStream({
286
287
  originalStream: response.body,
287
288
  contentLength,
288
- verifyData,
289
+ verifyData: verificationSettings.strategy?.verifyData.bind(verificationSettings.strategy),
289
290
  txId,
290
291
  emitter,
291
- strict,
292
+ strict: verificationSettings.strict,
292
293
  });
293
294
  return new Response(newClientStream, {
294
295
  status: response.status,
@@ -347,13 +348,15 @@ export class Wayfinder {
347
348
  */
348
349
  gatewaysProvider;
349
350
  /**
350
- * The routing strategy to use when routing requests.
351
+ * The routing settings to use when routing requests.
352
+ * This includes the routing strategy and event handlers for routing events.
353
+ * If not provided, the default FastestPingRoutingStrategy will be used.
351
354
  */
352
- routingStrategy;
355
+ routingSettings;
353
356
  /**
354
- * The verification strategy to use when verifying data.
357
+ * The verification settings to use when verifying data.
355
358
  */
356
- verificationStrategy;
359
+ verificationSettings;
357
360
  /**
358
361
  * A helper function that resolves the redirect url for ar:// requests to a target gateway.
359
362
  *
@@ -400,18 +403,6 @@ export class Wayfinder {
400
403
  * }
401
404
  */
402
405
  request;
403
- /**
404
- * The function that verifies the data hash for a given transaction id.
405
- *
406
- * @example
407
- * const wayfinder = new Wayfinder({
408
- * verifyData: (data, txId) => {
409
- * // some custom verification logic
410
- * return true;
411
- * },
412
- * });
413
- */
414
- verifyData;
415
406
  /**
416
407
  * The logger used by this Wayfinder instance
417
408
  */
@@ -475,61 +466,64 @@ export class Wayfinder {
475
466
  * The constructor for the wayfinder
476
467
  * @param options - Wayfinder configuration options
477
468
  */
478
- constructor({ logger = defaultLogger, gatewaysProvider, verificationSettings = {
479
- enabled: true,
480
- strict: false,
481
- strategy: new HashVerificationStrategy({
482
- trustedGateways: [new URL('https://permagate.io')],
483
- }),
484
- events: {
485
- onVerificationProgress: (event) => {
486
- logger.debug('Verification progress!', event);
487
- },
488
- onVerificationSucceeded: (event) => {
489
- logger.debug('Verification succeeded!', event);
490
- },
491
- onVerificationFailed: (event) => {
492
- logger.error('Verification failed!', event);
493
- },
494
- },
495
- }, routingSettings = {
496
- strategy: new FastestPingRoutingStrategy({
497
- timeoutMs: 1000,
498
- logger,
499
- }),
500
- events: {
501
- onRoutingStarted: (event) => {
502
- logger.debug('Routing started!', event);
503
- },
504
- onRoutingSkipped: (event) => {
505
- logger.debug('Routing skipped!', event);
506
- },
507
- onRoutingSucceeded: (event) => {
508
- logger.debug('Routing succeeded!', event);
509
- },
510
- },
511
- }, }) {
469
+ constructor({ logger = defaultLogger, gatewaysProvider, // forcing it to be required to avoid making ar-io-sdk a dependency
470
+ verificationSettings, routingSettings, }) {
512
471
  this.logger = logger;
513
- this.routingStrategy =
514
- routingSettings.strategy ??
515
- new FastestPingRoutingStrategy({
516
- timeoutMs: 1000,
517
- logger,
518
- });
519
- this.verificationStrategy =
520
- verificationSettings.strategy ??
521
- new HashVerificationStrategy({
522
- trustedGateways: [new URL('https://permagate.io')],
523
- });
524
472
  this.gatewaysProvider = gatewaysProvider;
525
473
  this.emitter = new WayfinderEmitter({
526
- verification: verificationSettings.events,
527
- routing: routingSettings.events,
474
+ verification: verificationSettings?.events,
475
+ routing: routingSettings?.events,
476
+ });
477
+ // default verification settings
478
+ this.verificationSettings = {
479
+ enabled: verificationSettings?.enabled ??
480
+ verificationSettings?.strategy !== undefined,
481
+ strategy: new HashVerificationStrategy({
482
+ trustedGateways: [new URL('https://permagate.io')],
483
+ }),
484
+ events: {
485
+ onVerificationFailed: (event) => {
486
+ this.logger.error('Verification failed', event);
487
+ },
488
+ onVerificationSucceeded: (event) => {
489
+ this.logger.info('Verification succeeded', event);
490
+ },
491
+ onVerificationProgress: (event) => {
492
+ this.logger.info('Verification progress', event);
493
+ },
494
+ },
495
+ // overwrite the default settings with the provided ones
496
+ ...verificationSettings,
497
+ };
498
+ // default routing settings
499
+ this.routingSettings = {
500
+ strategy: new FastestPingRoutingStrategy({
501
+ timeoutMs: 1000,
502
+ logger: defaultLogger,
503
+ }),
504
+ events: {
505
+ onRoutingStarted: (event) => {
506
+ this.logger.debug('Routing started', event);
507
+ },
508
+ onRoutingSkipped: (event) => {
509
+ this.logger.debug('Routing skipped', event);
510
+ },
511
+ onRoutingSucceeded: (event) => {
512
+ this.logger.debug('Routing succeeded', event);
513
+ },
514
+ },
515
+ // overwrite the default settings with the provided ones
516
+ ...routingSettings,
517
+ };
518
+ this.request = wayfinderFetch({
519
+ logger: this.logger,
520
+ emitter: this.emitter,
521
+ gatewaysProvider: this.gatewaysProvider,
522
+ routingSettings: this.routingSettings,
523
+ verificationSettings: this.verificationSettings,
528
524
  });
529
- this.verifyData = this.verificationStrategy.verifyData.bind(this.verificationStrategy);
530
- // top level function to easily resolve wayfinder urls using the routing strategy and gateways provider
531
525
  this.resolveUrl = async ({ originalUrl, logger = this.logger }) => {
532
- const selectedGateway = await this.routingStrategy.selectGateway({
526
+ const selectedGateway = await this.routingSettings.strategy.selectGateway({
533
527
  gateways: await this.gatewaysProvider.getGateways(),
534
528
  });
535
529
  return resolveWayfinderUrl({
@@ -538,16 +532,6 @@ export class Wayfinder {
538
532
  logger,
539
533
  });
540
534
  };
541
- // create a wayfinder request function with the routing strategy and gateways provider
542
- this.request = wayfinderRequest({
543
- getGateways: this.gatewaysProvider.getGateways.bind(this.gatewaysProvider),
544
- verifyData: this.verifyData,
545
- selectGateway: this.routingStrategy.selectGateway.bind(this.routingStrategy),
546
- resolveUrl: resolveWayfinderUrl,
547
- emitter: this.emitter,
548
- logger: this.logger,
549
- strict: verificationSettings.strict,
550
- });
551
- logger.debug(`Wayfinder initialized with ${this.routingStrategy.constructor.name} routing strategy`);
535
+ logger.debug(`Wayfinder initialized with ${this.routingSettings.strategy?.constructor.name} routing strategy`);
552
536
  }
553
537
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ar.io/wayfinder-core",
3
- "version": "0.0.4-alpha.0",
3
+ "version": "0.0.4-alpha.1",
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",
@@ -41,11 +41,11 @@
41
41
  "build": "npm run clean && tsc",
42
42
  "clean": "rimraf dist",
43
43
  "test": "npm run test:unit",
44
- "test:unit": "c8 tsx --enable-source-maps --trace-uncaught --trace-warnings --trace-deprecation src/**/*.test.ts",
45
- "lint:fix": "biome check --write --unsafe",
46
- "lint:check": "biome check --unsafe",
47
- "format:fix": "biome format --write",
48
- "format:check": "biome format"
44
+ "test:unit": "c8 tsx --test 'src/**/*.test.ts'",
45
+ "lint:fix": "biome check --write --unsafe --config-path=../../biome.json",
46
+ "lint:check": "biome check --unsafe --config-path=../../biome.json",
47
+ "format:fix": "biome format --write --config-path=../../biome.json",
48
+ "format:check": "biome format --config-path=../../biome.json"
49
49
  },
50
50
  "dependencies": {
51
51
  "@dha-team/arbundles": "^1.0.3",