@ar.io/sdk 3.12.0-beta.3 → 3.12.0-beta.4
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 +90 -233
- package/lib/cjs/version.js +1 -1
- package/lib/esm/common/wayfinder/wayfinder.js +90 -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,70 @@ 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
|
+
...init,
|
|
300
|
+
// follow redirects as gateways use sandboxing on /txId requests
|
|
301
|
+
redirect: 'follow',
|
|
302
|
+
});
|
|
303
|
+
// TODO: update any caching we use for the request and gateway response
|
|
312
304
|
logger?.debug(`Successfully routed request to gateway`, {
|
|
313
305
|
redirectUrl: redirectUrl.toString(),
|
|
314
|
-
originalUrl
|
|
306
|
+
originalUrl,
|
|
315
307
|
});
|
|
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
|
-
}
|
|
308
|
+
// return the response right away if no redirect was made
|
|
309
|
+
if (redirectUrl.toString() === originalUrl) {
|
|
310
|
+
return response;
|
|
311
|
+
}
|
|
312
|
+
// return the response right away if no verification is needed or if there is no body
|
|
313
|
+
if (!verifyData) {
|
|
314
|
+
return response;
|
|
315
|
+
}
|
|
316
|
+
// the txId is either in the response headers or the path of the request as the first parameter
|
|
317
|
+
const txId = response.headers.get('x-arns-resolved-id') ??
|
|
318
|
+
redirectUrl.pathname.split('/')[1];
|
|
319
|
+
const contentLength = +(response.headers.get('content-length') ?? 0);
|
|
320
|
+
if (!txIdRegex.test(txId)) {
|
|
321
|
+
// No transaction ID found, skip verification
|
|
322
|
+
logger?.debug('No transaction ID found, skipping verification', {
|
|
323
|
+
redirectUrl: redirectUrl.toString(),
|
|
324
|
+
originalUrl,
|
|
325
|
+
});
|
|
326
|
+
emitter?.emit('verification-skipped', {
|
|
327
|
+
originalUrl,
|
|
328
|
+
});
|
|
329
|
+
return response;
|
|
330
|
+
}
|
|
331
|
+
emitter?.emit('identified-transaction-id', {
|
|
332
|
+
originalUrl,
|
|
333
|
+
selectedGateway: redirectUrl.toString(),
|
|
334
|
+
txId,
|
|
335
|
+
});
|
|
336
|
+
if (!response.body) {
|
|
337
|
+
logger?.debug('No body, skipping verification', {
|
|
338
|
+
redirectUrl: redirectUrl.toString(),
|
|
339
|
+
originalUrl,
|
|
340
|
+
});
|
|
341
|
+
emitter?.emit('verification-skipped', {
|
|
342
|
+
originalUrl,
|
|
343
|
+
});
|
|
344
|
+
return response;
|
|
472
345
|
}
|
|
473
|
-
|
|
474
|
-
|
|
346
|
+
const verifiedStream = tapAndVerifyStream({
|
|
347
|
+
originalStream: response.body,
|
|
348
|
+
contentLength,
|
|
349
|
+
verifyData,
|
|
350
|
+
txId,
|
|
351
|
+
emitter,
|
|
352
|
+
strict,
|
|
353
|
+
});
|
|
354
|
+
// wrap the response with the verified stream
|
|
355
|
+
return new Response(verifiedStream, {
|
|
356
|
+
status: response.status,
|
|
357
|
+
statusText: response.statusText,
|
|
358
|
+
// TODO: we could add identified transaction id to the headers here, but it would be changing information from the original response
|
|
359
|
+
headers: response.headers,
|
|
360
|
+
});
|
|
475
361
|
}
|
|
476
362
|
catch (error) {
|
|
477
363
|
logger?.debug('Failed to route request', {
|
|
@@ -484,6 +370,12 @@ export const createWayfinderClient = ({ httpClient, resolveUrl, verifyData, sele
|
|
|
484
370
|
if (i < maxRetries - 1) {
|
|
485
371
|
await new Promise((resolve) => setTimeout(resolve, retryDelay));
|
|
486
372
|
}
|
|
373
|
+
else {
|
|
374
|
+
emitter?.emit('routing-failed', {
|
|
375
|
+
originalUrl,
|
|
376
|
+
error,
|
|
377
|
+
});
|
|
378
|
+
}
|
|
487
379
|
}
|
|
488
380
|
}
|
|
489
381
|
throw new Error('Failed to route request after max retries', {
|
|
@@ -493,37 +385,12 @@ export const createWayfinderClient = ({ httpClient, resolveUrl, verifyData, sele
|
|
|
493
385
|
},
|
|
494
386
|
});
|
|
495
387
|
};
|
|
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
|
-
});
|
|
388
|
+
return wayfinderRedirect;
|
|
509
389
|
};
|
|
510
390
|
/**
|
|
511
391
|
* 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
392
|
*/
|
|
516
393
|
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
394
|
/**
|
|
528
395
|
* The gateways provider is responsible for providing the list of gateways to use for routing requests.
|
|
529
396
|
*
|
|
@@ -564,8 +431,7 @@ export class Wayfinder {
|
|
|
564
431
|
*/
|
|
565
432
|
resolveUrl;
|
|
566
433
|
/**
|
|
567
|
-
*
|
|
568
|
-
* A wrapped http client that supports ar:// protocol. If a verification strategy is provided,
|
|
434
|
+
* A wrapped fetch function that supports ar:// protocol. If a verification strategy is provided,
|
|
569
435
|
* the request will be verified and events will be emitted as the request is processed.
|
|
570
436
|
*
|
|
571
437
|
* @example
|
|
@@ -585,9 +451,6 @@ export class Wayfinder {
|
|
|
585
451
|
* // request a transaction id
|
|
586
452
|
* const response = await wayfinder.request('ar://1234567890')
|
|
587
453
|
*
|
|
588
|
-
* // request a transaction id with a custom http client
|
|
589
|
-
* const response = await wayfinder.request('ar://1234567890')
|
|
590
|
-
*
|
|
591
454
|
* // Set strict mode to true to make verification blocking
|
|
592
455
|
* const wayfinder = new Wayfinder({
|
|
593
456
|
* strict: true,
|
|
@@ -653,14 +516,13 @@ export class Wayfinder {
|
|
|
653
516
|
emitter;
|
|
654
517
|
/**
|
|
655
518
|
* The constructor for the wayfinder
|
|
656
|
-
* @param httpClient - the http client to use for requests
|
|
657
519
|
* @param routingStrategy - the routing strategy to use for requests
|
|
658
520
|
* @param verificationStrategy - the verification strategy to use for requests
|
|
659
521
|
* @param gatewaysProvider - the gateways provider to use for routing requests
|
|
660
522
|
* @param logger - the logger to use for logging
|
|
661
523
|
* @param strict - if true, verification will be blocking and will fail requests if verification fails; if false, verification will be non-blocking
|
|
662
524
|
*/
|
|
663
|
-
constructor({
|
|
525
|
+
constructor({ logger = Logger.default, gatewaysProvider = new SimpleCacheGatewaysProvider({
|
|
664
526
|
gatewaysProvider: new NetworkGatewaysProvider({
|
|
665
527
|
ario: ARIO.mainnet(),
|
|
666
528
|
}),
|
|
@@ -683,12 +545,9 @@ export class Wayfinder {
|
|
|
683
545
|
onVerificationProgress: (event) => {
|
|
684
546
|
logger.debug('Verification progress!', event);
|
|
685
547
|
},
|
|
686
|
-
}, strict = false,
|
|
687
|
-
// TODO: stats provider
|
|
688
|
-
}) {
|
|
548
|
+
}, strict = false, }) {
|
|
689
549
|
this.routingStrategy = routingStrategy;
|
|
690
550
|
this.gatewaysProvider = gatewaysProvider;
|
|
691
|
-
this.httpClient = httpClient;
|
|
692
551
|
this.emitter = new WayfinderEmitter(events);
|
|
693
552
|
this.verifyData =
|
|
694
553
|
verificationStrategy.verifyData.bind(verificationStrategy);
|
|
@@ -706,7 +565,6 @@ export class Wayfinder {
|
|
|
706
565
|
};
|
|
707
566
|
// create a wayfinder client with the routing strategy and gateways provider
|
|
708
567
|
this.request = createWayfinderClient({
|
|
709
|
-
httpClient,
|
|
710
568
|
selectGateway: async () => {
|
|
711
569
|
return this.routingStrategy.selectGateway({
|
|
712
570
|
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