@ar.io/sdk 3.12.0-beta.3 → 3.12.0-beta.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bundles/web.bundle.min.js +125 -125
- package/lib/cjs/common/wayfinder/wayfinder.js +92 -233
- package/lib/cjs/version.js +1 -1
- package/lib/esm/common/wayfinder/wayfinder.js +92 -232
- package/lib/esm/version.js +1 -1
- package/lib/types/common/wayfinder/wayfinder.d.ts +13 -41
- package/lib/types/version.d.ts +1 -1
- package/package.json +1 -1
|
@@ -236,56 +236,44 @@ export function tapAndVerifyStream({ originalStream, contentLength, verifyData,
|
|
|
236
236
|
}
|
|
237
237
|
throw new Error('Unsupported body type for cloning');
|
|
238
238
|
}
|
|
239
|
-
export function wrapVerifiedResponse(original, newBody, txId) {
|
|
240
|
-
// Clone headers (Header objects aren't serializable)
|
|
241
|
-
const headers = new Headers();
|
|
242
|
-
original.headers.forEach((value, key) => headers.set(key, value));
|
|
243
|
-
// Create a new Response with the new body and cloned headers
|
|
244
|
-
const wrapped = new Response(newBody, {
|
|
245
|
-
status: original.status,
|
|
246
|
-
statusText: original.statusText,
|
|
247
|
-
headers,
|
|
248
|
-
});
|
|
249
|
-
// Attach txId for downstream tracking
|
|
250
|
-
wrapped.txId = txId;
|
|
251
|
-
wrapped.redirectedFrom = original.url;
|
|
252
|
-
return wrapped;
|
|
253
|
-
}
|
|
254
239
|
/**
|
|
255
|
-
* Creates a wrapped
|
|
240
|
+
* Creates a wrapped fetch function that supports ar:// protocol
|
|
256
241
|
*
|
|
257
|
-
* This function leverages a Proxy to intercept calls to
|
|
258
|
-
* and redirects them to the target gateway using the resolveUrl function
|
|
259
|
-
* It also supports the http client methods like get(), post(), put(), delete(), etc.
|
|
242
|
+
* This function leverages a Proxy to intercept calls to fetch
|
|
243
|
+
* and redirects them to the target gateway using the resolveUrl function.
|
|
260
244
|
*
|
|
261
|
-
* Any URLs provided that are not wayfinder urls will be
|
|
245
|
+
* Any URLs provided that are not wayfinder urls will be passed directly to fetch.
|
|
262
246
|
*
|
|
263
|
-
* @param httpClient - the http client to wrap (e.g. axios, fetch, got, etc.)
|
|
264
247
|
* @param resolveUrl - the function to construct the redirect url for ar:// requests
|
|
265
|
-
* @returns a wrapped
|
|
248
|
+
* @returns a wrapped fetch function that supports ar:// protocol and always returns Response
|
|
266
249
|
*/
|
|
267
|
-
export const createWayfinderClient = ({
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
250
|
+
export const createWayfinderClient = ({ resolveUrl, verifyData, selectGateway, emitter = new WayfinderEmitter(), logger, strict = false, }) => {
|
|
251
|
+
// Create a function that will handle the redirection logic for ar:// URLs
|
|
252
|
+
const wayfinderRedirect = async (url, init) => {
|
|
253
|
+
// If the url is not a string or URL (e.g., it's a Request object), extract the URL from it
|
|
254
|
+
const originalUrl = url instanceof Request ? url.url : url.toString();
|
|
255
|
+
// If it's not an ar:// URL, pass it directly to fetch
|
|
256
|
+
if (!originalUrl.startsWith('ar://')) {
|
|
257
|
+
logger?.debug('Not a wayfinder URL, passing to fetch directly', {
|
|
273
258
|
originalUrl,
|
|
274
259
|
});
|
|
275
260
|
emitter?.emit('routing-skipped', {
|
|
276
|
-
originalUrl
|
|
261
|
+
originalUrl,
|
|
277
262
|
});
|
|
278
|
-
|
|
263
|
+
// we don't do anything special with non-ar:// urls, just pass them through
|
|
264
|
+
return fetch(url, init);
|
|
279
265
|
}
|
|
266
|
+
// Start the routing process
|
|
280
267
|
emitter?.emit('routing-started', {
|
|
281
|
-
originalUrl
|
|
268
|
+
originalUrl,
|
|
282
269
|
});
|
|
283
|
-
//
|
|
270
|
+
// Retry logic for gateway selection
|
|
284
271
|
const maxRetries = 3;
|
|
285
272
|
const retryDelay = 1000;
|
|
286
273
|
for (let i = 0; i < maxRetries; i++) {
|
|
287
274
|
try {
|
|
288
275
|
// select the target gateway
|
|
276
|
+
// TODO: we may want to provide the `path` to select gateway so the HEAD checks in routers check the existence of the actual path/request
|
|
289
277
|
const selectedGateway = await selectGateway();
|
|
290
278
|
logger?.debug('Selected gateway', {
|
|
291
279
|
originalUrl,
|
|
@@ -306,172 +294,72 @@ export const createWayfinderClient = ({ httpClient, resolveUrl, verifyData, sele
|
|
|
306
294
|
originalUrl,
|
|
307
295
|
redirectUrl: redirectUrl.toString(),
|
|
308
296
|
});
|
|
309
|
-
//
|
|
310
|
-
const response = await
|
|
311
|
-
|
|
297
|
+
// Make the request to the target gateway
|
|
298
|
+
const response = await fetch(redirectUrl.toString(), {
|
|
299
|
+
// follow redirects as gateways use sandboxing on /txId requests
|
|
300
|
+
redirect: 'follow',
|
|
301
|
+
mode: 'cors',
|
|
302
|
+
// allow requestor to override and any additional request configuration
|
|
303
|
+
...init,
|
|
304
|
+
});
|
|
305
|
+
// TODO: update any caching we use for the request and gateway response
|
|
312
306
|
logger?.debug(`Successfully routed request to gateway`, {
|
|
313
307
|
redirectUrl: redirectUrl.toString(),
|
|
314
|
-
originalUrl
|
|
308
|
+
originalUrl,
|
|
315
309
|
});
|
|
316
|
-
//
|
|
317
|
-
if (
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
// no transaction id found, skip verification
|
|
354
|
-
logger?.debug('No transaction id found, skipping verification', {
|
|
355
|
-
redirectUrl: redirectUrl.toString(),
|
|
356
|
-
originalUrl,
|
|
357
|
-
});
|
|
358
|
-
emitter?.emit('verification-skipped', {
|
|
359
|
-
originalUrl,
|
|
360
|
-
});
|
|
361
|
-
return response;
|
|
362
|
-
}
|
|
363
|
-
emitter?.emit('identified-transaction-id', {
|
|
364
|
-
originalUrl,
|
|
365
|
-
selectedGateway: redirectUrl.toString(),
|
|
366
|
-
txId,
|
|
367
|
-
});
|
|
368
|
-
// parse out the key that contains the response body, we'll use it later when updating the response object
|
|
369
|
-
const responseDataKey = response.body
|
|
370
|
-
? 'body'
|
|
371
|
-
: response.data
|
|
372
|
-
? 'data'
|
|
373
|
-
: undefined;
|
|
374
|
-
if (responseDataKey === undefined) {
|
|
375
|
-
throw new Error('No data body or data provided, skipping verification', {
|
|
376
|
-
cause: {
|
|
377
|
-
redirectUrl: redirectUrl.toString(),
|
|
378
|
-
originalUrl: originalUrl.toString(),
|
|
379
|
-
},
|
|
380
|
-
});
|
|
381
|
-
}
|
|
382
|
-
const responseBody = response[responseDataKey];
|
|
383
|
-
// TODO: determine if it is data item or L1 transaction, and tell the verifier accordingly, just drop in hit to graphql now
|
|
384
|
-
if (txId === undefined) {
|
|
385
|
-
throw new Error('Failed to parse data hash from response headers', {
|
|
386
|
-
cause: {
|
|
387
|
-
redirectUrl: redirectUrl.toString(),
|
|
388
|
-
originalUrl: originalUrl.toString(),
|
|
389
|
-
txId,
|
|
390
|
-
},
|
|
391
|
-
});
|
|
392
|
-
}
|
|
393
|
-
else if (responseBody === undefined) {
|
|
394
|
-
throw new Error('No data body provided, skipping verification', {
|
|
395
|
-
cause: {
|
|
396
|
-
redirectUrl: redirectUrl.toString(),
|
|
397
|
-
originalUrl: originalUrl.toString(),
|
|
398
|
-
txId,
|
|
399
|
-
},
|
|
400
|
-
});
|
|
401
|
-
}
|
|
402
|
-
else {
|
|
403
|
-
logger?.debug('Verifying data hash for txId', {
|
|
404
|
-
redirectUrl: redirectUrl.toString(),
|
|
405
|
-
originalUrl: originalUrl.toString(),
|
|
406
|
-
txId,
|
|
407
|
-
});
|
|
408
|
-
if (responseBody instanceof ReadableStream ||
|
|
409
|
-
responseBody instanceof Readable) {
|
|
410
|
-
const newClientStream = tapAndVerifyStream({
|
|
411
|
-
originalStream: responseBody,
|
|
412
|
-
contentLength,
|
|
413
|
-
verifyData,
|
|
414
|
-
txId,
|
|
415
|
-
emitter,
|
|
416
|
-
strict,
|
|
417
|
-
});
|
|
418
|
-
if (response instanceof Response) {
|
|
419
|
-
// specific to fetch
|
|
420
|
-
return wrapVerifiedResponse(response, newClientStream, txId);
|
|
421
|
-
}
|
|
422
|
-
else {
|
|
423
|
-
// overwrite the response body with the new client stream
|
|
424
|
-
response.txId = txId;
|
|
425
|
-
response.body = newClientStream;
|
|
426
|
-
return response;
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
else {
|
|
430
|
-
// TODO: content-application/json and it's smaller than 10mb
|
|
431
|
-
// TODO: add tests and verify this works for all non-Readable/streamed responses
|
|
432
|
-
if (strict) {
|
|
433
|
-
// In strict mode, wait for verification before returning response
|
|
434
|
-
try {
|
|
435
|
-
await verifyData({
|
|
436
|
-
data: responseBody,
|
|
437
|
-
txId,
|
|
438
|
-
});
|
|
439
|
-
emitter?.emit('verification-succeeded', { txId });
|
|
440
|
-
return response;
|
|
441
|
-
}
|
|
442
|
-
catch (error) {
|
|
443
|
-
logger?.debug('Failed to verify data hash', {
|
|
444
|
-
error,
|
|
445
|
-
txId,
|
|
446
|
-
});
|
|
447
|
-
emitter?.emit('verification-failed', { txId, error });
|
|
448
|
-
throw new Error('Verification failed', { cause: error });
|
|
449
|
-
}
|
|
450
|
-
}
|
|
451
|
-
else {
|
|
452
|
-
// In non-strict mode, perform verification in the background
|
|
453
|
-
verifyData({
|
|
454
|
-
data: responseBody,
|
|
455
|
-
txId,
|
|
456
|
-
})
|
|
457
|
-
.then(() => {
|
|
458
|
-
emitter?.emit('verification-succeeded', { txId });
|
|
459
|
-
})
|
|
460
|
-
.catch((error) => {
|
|
461
|
-
logger?.debug('Failed to verify data hash', {
|
|
462
|
-
error,
|
|
463
|
-
txId,
|
|
464
|
-
});
|
|
465
|
-
emitter?.emit('verification-failed', { txId, error });
|
|
466
|
-
});
|
|
467
|
-
return response;
|
|
468
|
-
}
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
}
|
|
310
|
+
// return the response right away if no redirect was made
|
|
311
|
+
if (redirectUrl.toString() === originalUrl) {
|
|
312
|
+
return response;
|
|
313
|
+
}
|
|
314
|
+
// return the response right away if no verification is needed or if there is no body
|
|
315
|
+
if (!verifyData) {
|
|
316
|
+
return response;
|
|
317
|
+
}
|
|
318
|
+
// the txId is either in the response headers or the path of the request as the first parameter
|
|
319
|
+
const txId = response.headers.get('x-arns-resolved-id') ??
|
|
320
|
+
redirectUrl.pathname.split('/')[1];
|
|
321
|
+
const contentLength = +(response.headers.get('content-length') ?? 0);
|
|
322
|
+
if (!txIdRegex.test(txId)) {
|
|
323
|
+
// No transaction ID found, skip verification
|
|
324
|
+
logger?.debug('No transaction ID found, skipping verification', {
|
|
325
|
+
redirectUrl: redirectUrl.toString(),
|
|
326
|
+
originalUrl,
|
|
327
|
+
});
|
|
328
|
+
emitter?.emit('verification-skipped', {
|
|
329
|
+
originalUrl,
|
|
330
|
+
});
|
|
331
|
+
return response;
|
|
332
|
+
}
|
|
333
|
+
emitter?.emit('identified-transaction-id', {
|
|
334
|
+
originalUrl,
|
|
335
|
+
selectedGateway: redirectUrl.toString(),
|
|
336
|
+
txId,
|
|
337
|
+
});
|
|
338
|
+
if (!response.body) {
|
|
339
|
+
logger?.debug('No body, skipping verification', {
|
|
340
|
+
redirectUrl: redirectUrl.toString(),
|
|
341
|
+
originalUrl,
|
|
342
|
+
});
|
|
343
|
+
emitter?.emit('verification-skipped', {
|
|
344
|
+
originalUrl,
|
|
345
|
+
});
|
|
346
|
+
return response;
|
|
472
347
|
}
|
|
473
|
-
|
|
474
|
-
|
|
348
|
+
const verifiedStream = tapAndVerifyStream({
|
|
349
|
+
originalStream: response.body,
|
|
350
|
+
contentLength,
|
|
351
|
+
verifyData,
|
|
352
|
+
txId,
|
|
353
|
+
emitter,
|
|
354
|
+
strict,
|
|
355
|
+
});
|
|
356
|
+
// wrap the response with the verified stream
|
|
357
|
+
return new Response(verifiedStream, {
|
|
358
|
+
status: response.status,
|
|
359
|
+
statusText: response.statusText,
|
|
360
|
+
// TODO: we could add identified transaction id to the headers here, but it would be changing information from the original response
|
|
361
|
+
headers: response.headers,
|
|
362
|
+
});
|
|
475
363
|
}
|
|
476
364
|
catch (error) {
|
|
477
365
|
logger?.debug('Failed to route request', {
|
|
@@ -484,6 +372,12 @@ export const createWayfinderClient = ({ httpClient, resolveUrl, verifyData, sele
|
|
|
484
372
|
if (i < maxRetries - 1) {
|
|
485
373
|
await new Promise((resolve) => setTimeout(resolve, retryDelay));
|
|
486
374
|
}
|
|
375
|
+
else {
|
|
376
|
+
emitter?.emit('routing-failed', {
|
|
377
|
+
originalUrl,
|
|
378
|
+
error,
|
|
379
|
+
});
|
|
380
|
+
}
|
|
487
381
|
}
|
|
488
382
|
}
|
|
489
383
|
throw new Error('Failed to route request after max retries', {
|
|
@@ -493,37 +387,12 @@ export const createWayfinderClient = ({ httpClient, resolveUrl, verifyData, sele
|
|
|
493
387
|
},
|
|
494
388
|
});
|
|
495
389
|
};
|
|
496
|
-
return
|
|
497
|
-
// support direct calls: fetch('ar://…', options)
|
|
498
|
-
// axios() or got()
|
|
499
|
-
apply: (_target, _thisArg, argArray) => wayfinderRedirect(httpClient, argArray),
|
|
500
|
-
// support http clients that use functions like `got.get`, `got.post`, `axios.get`, etc. while still using the wayfinder redirect function
|
|
501
|
-
get: (target, prop, receiver) => {
|
|
502
|
-
const value = Reflect.get(target, prop, receiver);
|
|
503
|
-
if (typeof value === 'function') {
|
|
504
|
-
return (...inner) => wayfinderRedirect(value.bind(target), inner);
|
|
505
|
-
}
|
|
506
|
-
return value; // numbers, objects, symbols pass through untouched
|
|
507
|
-
},
|
|
508
|
-
});
|
|
390
|
+
return wayfinderRedirect;
|
|
509
391
|
};
|
|
510
392
|
/**
|
|
511
393
|
* The main class for the wayfinder
|
|
512
|
-
* @param router - the router to use for requests
|
|
513
|
-
* @param httpClient - the http client to use for requests
|
|
514
|
-
* @param blocklist - the blocklist of gateways to avoid
|
|
515
394
|
*/
|
|
516
395
|
export class Wayfinder {
|
|
517
|
-
/**
|
|
518
|
-
* The native http client used by wayfinder. By default, the native fetch api is used.
|
|
519
|
-
*
|
|
520
|
-
* @example
|
|
521
|
-
* const wayfinder = new Wayfinder({
|
|
522
|
-
* httpClient: axios,
|
|
523
|
-
* });
|
|
524
|
-
*
|
|
525
|
-
*/
|
|
526
|
-
httpClient;
|
|
527
396
|
/**
|
|
528
397
|
* The gateways provider is responsible for providing the list of gateways to use for routing requests.
|
|
529
398
|
*
|
|
@@ -564,8 +433,7 @@ export class Wayfinder {
|
|
|
564
433
|
*/
|
|
565
434
|
resolveUrl;
|
|
566
435
|
/**
|
|
567
|
-
*
|
|
568
|
-
* A wrapped http client that supports ar:// protocol. If a verification strategy is provided,
|
|
436
|
+
* A wrapped fetch function that supports ar:// protocol. If a verification strategy is provided,
|
|
569
437
|
* the request will be verified and events will be emitted as the request is processed.
|
|
570
438
|
*
|
|
571
439
|
* @example
|
|
@@ -585,9 +453,6 @@ export class Wayfinder {
|
|
|
585
453
|
* // request a transaction id
|
|
586
454
|
* const response = await wayfinder.request('ar://1234567890')
|
|
587
455
|
*
|
|
588
|
-
* // request a transaction id with a custom http client
|
|
589
|
-
* const response = await wayfinder.request('ar://1234567890')
|
|
590
|
-
*
|
|
591
456
|
* // Set strict mode to true to make verification blocking
|
|
592
457
|
* const wayfinder = new Wayfinder({
|
|
593
458
|
* strict: true,
|
|
@@ -653,14 +518,13 @@ export class Wayfinder {
|
|
|
653
518
|
emitter;
|
|
654
519
|
/**
|
|
655
520
|
* The constructor for the wayfinder
|
|
656
|
-
* @param httpClient - the http client to use for requests
|
|
657
521
|
* @param routingStrategy - the routing strategy to use for requests
|
|
658
522
|
* @param verificationStrategy - the verification strategy to use for requests
|
|
659
523
|
* @param gatewaysProvider - the gateways provider to use for routing requests
|
|
660
524
|
* @param logger - the logger to use for logging
|
|
661
525
|
* @param strict - if true, verification will be blocking and will fail requests if verification fails; if false, verification will be non-blocking
|
|
662
526
|
*/
|
|
663
|
-
constructor({
|
|
527
|
+
constructor({ logger = Logger.default, gatewaysProvider = new SimpleCacheGatewaysProvider({
|
|
664
528
|
gatewaysProvider: new NetworkGatewaysProvider({
|
|
665
529
|
ario: ARIO.mainnet(),
|
|
666
530
|
}),
|
|
@@ -683,12 +547,9 @@ export class Wayfinder {
|
|
|
683
547
|
onVerificationProgress: (event) => {
|
|
684
548
|
logger.debug('Verification progress!', event);
|
|
685
549
|
},
|
|
686
|
-
}, strict = false,
|
|
687
|
-
// TODO: stats provider
|
|
688
|
-
}) {
|
|
550
|
+
}, strict = false, }) {
|
|
689
551
|
this.routingStrategy = routingStrategy;
|
|
690
552
|
this.gatewaysProvider = gatewaysProvider;
|
|
691
|
-
this.httpClient = httpClient;
|
|
692
553
|
this.emitter = new WayfinderEmitter(events);
|
|
693
554
|
this.verifyData =
|
|
694
555
|
verificationStrategy.verifyData.bind(verificationStrategy);
|
|
@@ -706,7 +567,6 @@ export class Wayfinder {
|
|
|
706
567
|
};
|
|
707
568
|
// create a wayfinder client with the routing strategy and gateways provider
|
|
708
569
|
this.request = createWayfinderClient({
|
|
709
|
-
httpClient,
|
|
710
570
|
selectGateway: async () => {
|
|
711
571
|
return this.routingStrategy.selectGateway({
|
|
712
572
|
gateways: await this.gatewaysProvider.getGateways(),
|
package/lib/esm/version.js
CHANGED
|
@@ -17,9 +17,7 @@ import EventEmitter from 'node:events';
|
|
|
17
17
|
import { PassThrough, Readable } from 'node:stream';
|
|
18
18
|
import { DataVerificationStrategy, GatewaysProvider, RoutingStrategy } from '../../types/wayfinder.js';
|
|
19
19
|
import { Logger } from '../logger.js';
|
|
20
|
-
type
|
|
21
|
-
type HttpClientFunction = (...args: HttpClientArgs) => unknown;
|
|
22
|
-
type WayfinderHttpClient<T extends HttpClientFunction> = T;
|
|
20
|
+
type WayfinderHttpClient = typeof fetch;
|
|
23
21
|
export declare const arnsRegex: RegExp;
|
|
24
22
|
export declare const txIdRegex: RegExp;
|
|
25
23
|
/**
|
|
@@ -100,53 +98,33 @@ export declare function tapAndVerifyStream<T extends Readable | ReadableStream>(
|
|
|
100
98
|
emitter?: WayfinderEmitter;
|
|
101
99
|
strict?: boolean;
|
|
102
100
|
}): T extends Readable ? PassThrough : T;
|
|
103
|
-
export declare function wrapVerifiedResponse(original: Response, newBody: ReadableStream<Uint8Array>, txId: string): Response;
|
|
104
101
|
/**
|
|
105
|
-
* Creates a wrapped
|
|
102
|
+
* Creates a wrapped fetch function that supports ar:// protocol
|
|
106
103
|
*
|
|
107
|
-
* This function leverages a Proxy to intercept calls to
|
|
108
|
-
* and redirects them to the target gateway using the resolveUrl function
|
|
109
|
-
* It also supports the http client methods like get(), post(), put(), delete(), etc.
|
|
104
|
+
* This function leverages a Proxy to intercept calls to fetch
|
|
105
|
+
* and redirects them to the target gateway using the resolveUrl function.
|
|
110
106
|
*
|
|
111
|
-
* Any URLs provided that are not wayfinder urls will be
|
|
107
|
+
* Any URLs provided that are not wayfinder urls will be passed directly to fetch.
|
|
112
108
|
*
|
|
113
|
-
* @param httpClient - the http client to wrap (e.g. axios, fetch, got, etc.)
|
|
114
109
|
* @param resolveUrl - the function to construct the redirect url for ar:// requests
|
|
115
|
-
* @returns a wrapped
|
|
110
|
+
* @returns a wrapped fetch function that supports ar:// protocol and always returns Response
|
|
116
111
|
*/
|
|
117
|
-
export declare const createWayfinderClient:
|
|
118
|
-
httpClient: T;
|
|
112
|
+
export declare const createWayfinderClient: ({ resolveUrl, verifyData, selectGateway, emitter, logger, strict, }: {
|
|
119
113
|
selectGateway: () => Promise<URL>;
|
|
120
114
|
resolveUrl: (params: {
|
|
121
115
|
originalUrl: string | URL;
|
|
122
116
|
selectedGateway: URL;
|
|
123
117
|
logger?: Logger;
|
|
124
118
|
}) => URL;
|
|
125
|
-
verifyData?:
|
|
126
|
-
data: T_1;
|
|
127
|
-
txId: string;
|
|
128
|
-
}) => Promise<void>;
|
|
119
|
+
verifyData?: DataVerificationStrategy["verifyData"];
|
|
129
120
|
logger?: Logger;
|
|
130
121
|
emitter?: WayfinderEmitter;
|
|
131
122
|
strict?: boolean;
|
|
132
|
-
}) => WayfinderHttpClient
|
|
123
|
+
}) => WayfinderHttpClient;
|
|
133
124
|
/**
|
|
134
125
|
* The main class for the wayfinder
|
|
135
|
-
* @param router - the router to use for requests
|
|
136
|
-
* @param httpClient - the http client to use for requests
|
|
137
|
-
* @param blocklist - the blocklist of gateways to avoid
|
|
138
126
|
*/
|
|
139
|
-
export declare class Wayfinder
|
|
140
|
-
/**
|
|
141
|
-
* The native http client used by wayfinder. By default, the native fetch api is used.
|
|
142
|
-
*
|
|
143
|
-
* @example
|
|
144
|
-
* const wayfinder = new Wayfinder({
|
|
145
|
-
* httpClient: axios,
|
|
146
|
-
* });
|
|
147
|
-
*
|
|
148
|
-
*/
|
|
149
|
-
readonly httpClient: T;
|
|
127
|
+
export declare class Wayfinder {
|
|
150
128
|
/**
|
|
151
129
|
* The gateways provider is responsible for providing the list of gateways to use for routing requests.
|
|
152
130
|
*
|
|
@@ -190,8 +168,7 @@ export declare class Wayfinder<T extends HttpClientFunction> {
|
|
|
190
168
|
logger?: Logger;
|
|
191
169
|
}) => Promise<URL>;
|
|
192
170
|
/**
|
|
193
|
-
*
|
|
194
|
-
* A wrapped http client that supports ar:// protocol. If a verification strategy is provided,
|
|
171
|
+
* A wrapped fetch function that supports ar:// protocol. If a verification strategy is provided,
|
|
195
172
|
* the request will be verified and events will be emitted as the request is processed.
|
|
196
173
|
*
|
|
197
174
|
* @example
|
|
@@ -211,9 +188,6 @@ export declare class Wayfinder<T extends HttpClientFunction> {
|
|
|
211
188
|
* // request a transaction id
|
|
212
189
|
* const response = await wayfinder.request('ar://1234567890')
|
|
213
190
|
*
|
|
214
|
-
* // request a transaction id with a custom http client
|
|
215
|
-
* const response = await wayfinder.request('ar://1234567890')
|
|
216
|
-
*
|
|
217
191
|
* // Set strict mode to true to make verification blocking
|
|
218
192
|
* const wayfinder = new Wayfinder({
|
|
219
193
|
* strict: true,
|
|
@@ -226,7 +200,7 @@ export declare class Wayfinder<T extends HttpClientFunction> {
|
|
|
226
200
|
* console.error('Verification failed', error);
|
|
227
201
|
* }
|
|
228
202
|
*/
|
|
229
|
-
readonly request: WayfinderHttpClient
|
|
203
|
+
readonly request: WayfinderHttpClient;
|
|
230
204
|
/**
|
|
231
205
|
* The function that verifies the data hash for a given transaction id.
|
|
232
206
|
*
|
|
@@ -279,15 +253,13 @@ export declare class Wayfinder<T extends HttpClientFunction> {
|
|
|
279
253
|
readonly emitter: WayfinderEmitter;
|
|
280
254
|
/**
|
|
281
255
|
* The constructor for the wayfinder
|
|
282
|
-
* @param httpClient - the http client to use for requests
|
|
283
256
|
* @param routingStrategy - the routing strategy to use for requests
|
|
284
257
|
* @param verificationStrategy - the verification strategy to use for requests
|
|
285
258
|
* @param gatewaysProvider - the gateways provider to use for routing requests
|
|
286
259
|
* @param logger - the logger to use for logging
|
|
287
260
|
* @param strict - if true, verification will be blocking and will fail requests if verification fails; if false, verification will be non-blocking
|
|
288
261
|
*/
|
|
289
|
-
constructor({
|
|
290
|
-
httpClient?: T;
|
|
262
|
+
constructor({ logger, gatewaysProvider, routingStrategy, verificationStrategy, events, strict, }: {
|
|
291
263
|
routingStrategy?: RoutingStrategy;
|
|
292
264
|
gatewaysProvider?: GatewaysProvider;
|
|
293
265
|
verificationStrategy?: DataVerificationStrategy;
|
package/lib/types/version.d.ts
CHANGED