@helia/verified-fetch 2.4.0 → 2.5.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 +192 -0
- package/dist/index.min.js +357 -32
- package/dist/src/index.d.ts +198 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +192 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/plugins/errors.d.ts +25 -0
- package/dist/src/plugins/errors.d.ts.map +1 -0
- package/dist/src/plugins/errors.js +33 -0
- package/dist/src/plugins/errors.js.map +1 -0
- package/dist/src/plugins/index.d.ts +8 -0
- package/dist/src/plugins/index.d.ts.map +1 -0
- package/dist/src/plugins/index.js +7 -0
- package/dist/src/plugins/index.js.map +1 -0
- package/dist/src/plugins/plugin-base.d.ts +19 -0
- package/dist/src/plugins/plugin-base.d.ts.map +1 -0
- package/dist/src/plugins/plugin-base.js +26 -0
- package/dist/src/plugins/plugin-base.js.map +1 -0
- package/dist/src/plugins/plugin-handle-car.d.ts +11 -0
- package/dist/src/plugins/plugin-handle-car.d.ts.map +1 -0
- package/dist/src/plugins/plugin-handle-car.js +28 -0
- package/dist/src/plugins/plugin-handle-car.js.map +1 -0
- package/dist/src/plugins/plugin-handle-dag-cbor.d.ts +11 -0
- package/dist/src/plugins/plugin-handle-dag-cbor.d.ts.map +1 -0
- package/dist/src/plugins/plugin-handle-dag-cbor.js +73 -0
- package/dist/src/plugins/plugin-handle-dag-cbor.js.map +1 -0
- package/dist/src/plugins/plugin-handle-dag-pb.d.ts +15 -0
- package/dist/src/plugins/plugin-handle-dag-pb.d.ts.map +1 -0
- package/dist/src/plugins/plugin-handle-dag-pb.js +152 -0
- package/dist/src/plugins/plugin-handle-dag-pb.js.map +1 -0
- package/dist/src/plugins/plugin-handle-dag-walk.d.ts +16 -0
- package/dist/src/plugins/plugin-handle-dag-walk.d.ts.map +1 -0
- package/dist/src/plugins/plugin-handle-dag-walk.js +45 -0
- package/dist/src/plugins/plugin-handle-dag-walk.js.map +1 -0
- package/dist/src/plugins/plugin-handle-dir-index-html.d.ts +9 -0
- package/dist/src/plugins/plugin-handle-dir-index-html.d.ts.map +1 -0
- package/dist/src/plugins/plugin-handle-dir-index-html.js +37 -0
- package/dist/src/plugins/plugin-handle-dir-index-html.js.map +1 -0
- package/dist/src/plugins/plugin-handle-ipns-record.d.ts +12 -0
- package/dist/src/plugins/plugin-handle-ipns-record.d.ts.map +1 -0
- package/dist/src/plugins/plugin-handle-ipns-record.js +62 -0
- package/dist/src/plugins/plugin-handle-ipns-record.js.map +1 -0
- package/dist/src/plugins/plugin-handle-json.d.ts +11 -0
- package/dist/src/plugins/plugin-handle-json.d.ts.map +1 -0
- package/dist/src/plugins/plugin-handle-json.js +51 -0
- package/dist/src/plugins/plugin-handle-json.js.map +1 -0
- package/dist/src/plugins/plugin-handle-raw.d.ts +8 -0
- package/dist/src/plugins/plugin-handle-raw.d.ts.map +1 -0
- package/dist/src/plugins/plugin-handle-raw.js +80 -0
- package/dist/src/plugins/plugin-handle-raw.js.map +1 -0
- package/dist/src/plugins/plugin-handle-tar.d.ts +12 -0
- package/dist/src/plugins/plugin-handle-tar.d.ts.map +1 -0
- package/dist/src/plugins/plugin-handle-tar.js +36 -0
- package/dist/src/plugins/plugin-handle-tar.js.map +1 -0
- package/dist/src/plugins/plugins.d.ts +5 -0
- package/dist/src/plugins/plugins.d.ts.map +1 -0
- package/dist/src/plugins/plugins.js +5 -0
- package/dist/src/plugins/plugins.js.map +1 -0
- package/dist/src/plugins/types.d.ts +68 -0
- package/dist/src/plugins/types.d.ts.map +1 -0
- package/dist/src/plugins/types.js +2 -0
- package/dist/src/plugins/types.js.map +1 -0
- package/dist/src/types.d.ts +0 -27
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/types.js +1 -2
- package/dist/src/types.js.map +1 -1
- package/dist/src/utils/dir-index-html.d.ts +16 -0
- package/dist/src/utils/dir-index-html.d.ts.map +1 -0
- package/dist/src/utils/dir-index-html.js +387 -0
- package/dist/src/utils/dir-index-html.js.map +1 -0
- package/dist/src/utils/get-e-tag.d.ts +1 -1
- package/dist/src/utils/get-e-tag.d.ts.map +1 -1
- package/dist/src/utils/get-e-tag.js +18 -3
- package/dist/src/utils/get-e-tag.js.map +1 -1
- package/dist/src/utils/walk-path.d.ts +3 -2
- package/dist/src/utils/walk-path.d.ts.map +1 -1
- package/dist/src/utils/walk-path.js +1 -1
- package/dist/src/utils/walk-path.js.map +1 -1
- package/dist/src/verified-fetch.d.ts +6 -24
- package/dist/src/verified-fetch.d.ts.map +1 -1
- package/dist/src/verified-fetch.js +164 -387
- package/dist/src/verified-fetch.js.map +1 -1
- package/dist/typedoc-urls.json +32 -24
- package/package.json +6 -2
- package/src/index.ts +199 -0
- package/src/plugins/errors.ts +37 -0
- package/src/plugins/index.ts +8 -0
- package/src/plugins/plugin-base.ts +30 -0
- package/src/plugins/plugin-handle-car.ts +32 -0
- package/src/plugins/plugin-handle-dag-cbor.ts +84 -0
- package/src/plugins/plugin-handle-dag-pb.ts +168 -0
- package/src/plugins/plugin-handle-dag-walk.ts +53 -0
- package/src/plugins/plugin-handle-dir-index-html.ts +44 -0
- package/src/plugins/plugin-handle-ipns-record.ts +69 -0
- package/src/plugins/plugin-handle-json.ts +57 -0
- package/src/plugins/plugin-handle-raw.ts +92 -0
- package/src/plugins/plugin-handle-tar.ts +44 -0
- package/src/plugins/plugins.ts +4 -0
- package/src/plugins/types.ts +73 -0
- package/src/types.ts +0 -34
- package/src/utils/dir-index-html.ts +445 -0
- package/src/utils/get-e-tag.ts +20 -3
- package/src/utils/walk-path.ts +3 -3
- package/src/verified-fetch.ts +187 -430
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { code as rawCode } from 'multiformats/codecs/raw';
|
|
2
|
+
import { identity } from 'multiformats/hashes/identity';
|
|
3
|
+
import { ByteRangeContext } from '../utils/byte-range-context.js';
|
|
4
|
+
import { notFoundResponse, okRangeResponse } from '../utils/responses.js';
|
|
5
|
+
import { setContentType } from '../utils/set-content-type.js';
|
|
6
|
+
import { PluginFatalError } from './errors.js';
|
|
7
|
+
import { BasePlugin } from './plugin-base.js';
|
|
8
|
+
/**
|
|
9
|
+
* These are Accept header values that will cause content type sniffing to be
|
|
10
|
+
* skipped and set to these values.
|
|
11
|
+
*/
|
|
12
|
+
const RAW_HEADERS = [
|
|
13
|
+
'application/vnd.ipld.dag-json',
|
|
14
|
+
'application/vnd.ipld.raw',
|
|
15
|
+
'application/octet-stream'
|
|
16
|
+
];
|
|
17
|
+
/**
|
|
18
|
+
* if the user has specified an `Accept` header, and it's in our list of
|
|
19
|
+
* allowable "raw" format headers, use that instead of detecting the content
|
|
20
|
+
* type. This avoids the user from receiving something different when they
|
|
21
|
+
* signal that they want to `Accept` a specific mime type.
|
|
22
|
+
*/
|
|
23
|
+
function getOverridenRawContentType({ headers, accept }) {
|
|
24
|
+
// accept has already been resolved by getResolvedAcceptHeader, if we have it, use it.
|
|
25
|
+
const acceptHeader = accept ?? new Headers(headers).get('accept') ?? '';
|
|
26
|
+
// e.g. "Accept: text/html, application/xhtml+xml, application/xml;q=0.9, image/webp, */*;q=0.8"
|
|
27
|
+
const acceptHeaders = acceptHeader.split(',')
|
|
28
|
+
.map(s => s.split(';')[0])
|
|
29
|
+
.map(s => s.trim());
|
|
30
|
+
for (const mimeType of acceptHeaders) {
|
|
31
|
+
if (mimeType === '*/*') {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
if (RAW_HEADERS.includes(mimeType ?? '')) {
|
|
35
|
+
return mimeType;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
export class RawPlugin extends BasePlugin {
|
|
40
|
+
codes = [rawCode, identity.code];
|
|
41
|
+
canHandle({ cid, accept, query }) {
|
|
42
|
+
this.log('checking if we can handle %c with accept %s', cid, accept);
|
|
43
|
+
return accept === 'application/vnd.ipld.raw' || query.format === 'raw';
|
|
44
|
+
}
|
|
45
|
+
async handle(context) {
|
|
46
|
+
const { path, resource, cid, accept, query, options } = context;
|
|
47
|
+
const { getBlockstore, contentTypeParser } = this.pluginOptions;
|
|
48
|
+
const session = options?.session ?? true;
|
|
49
|
+
const log = this.log;
|
|
50
|
+
if (accept === 'application/vnd.ipld.raw' || query.format === 'raw') {
|
|
51
|
+
context.reqFormat = 'raw';
|
|
52
|
+
context.query.download = true;
|
|
53
|
+
context.query.filename = context.query.filename ?? `${cid.toString()}.bin`;
|
|
54
|
+
log.trace('Set content disposition...');
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
log.trace('Did NOT setting content disposition...');
|
|
58
|
+
}
|
|
59
|
+
if (path !== '' && cid.code === rawCode) {
|
|
60
|
+
log.trace('404-ing raw codec request for %c/%s', cid, path);
|
|
61
|
+
// throw new PluginError('ERR_RAW_PATHS_NOT_SUPPORTED', 'Raw codec does not support paths')
|
|
62
|
+
// return notFoundResponse(resource, 'Raw codec does not support paths')
|
|
63
|
+
throw new PluginFatalError('ERR_RAW_PATHS_NOT_SUPPORTED', 'Raw codec does not support paths', { response: notFoundResponse(resource, 'Raw codec does not support paths') });
|
|
64
|
+
}
|
|
65
|
+
const byteRangeContext = new ByteRangeContext(this.pluginOptions.logger, options?.headers);
|
|
66
|
+
const terminalCid = context.pathDetails?.terminalElement.cid ?? context.cid;
|
|
67
|
+
const blockstore = getBlockstore(terminalCid, resource, session, options);
|
|
68
|
+
const result = await blockstore.get(terminalCid, options);
|
|
69
|
+
byteRangeContext.setBody(result);
|
|
70
|
+
const response = okRangeResponse(resource, byteRangeContext.getBody(), { byteRangeContext, log }, {
|
|
71
|
+
redirected: false
|
|
72
|
+
});
|
|
73
|
+
// if the user has specified an `Accept` header that corresponds to a raw
|
|
74
|
+
// type, honour that header, so for example they don't request
|
|
75
|
+
// `application/vnd.ipld.raw` but get `application/octet-stream`
|
|
76
|
+
await setContentType({ bytes: result, path, response, defaultContentType: getOverridenRawContentType({ headers: options?.headers, accept }), contentTypeParser, log });
|
|
77
|
+
return response;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=plugin-handle-raw.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin-handle-raw.js","sourceRoot":"","sources":["../../../src/plugins/plugin-handle-raw.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,IAAI,OAAO,EAAE,MAAM,yBAAyB,CAAA;AACzD,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAA;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAA;AACjE,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AACzE,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAA;AAC7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAG7C;;;GAGG;AACH,MAAM,WAAW,GAAG;IAClB,+BAA+B;IAC/B,0BAA0B;IAC1B,0BAA0B;CAC3B,CAAA;AAED;;;;;GAKG;AACH,SAAS,0BAA0B,CAAE,EAAE,OAAO,EAAE,MAAM,EAA8C;IAClG,sFAAsF;IACtF,MAAM,YAAY,GAAG,MAAM,IAAI,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAA;IAEvE,gGAAgG;IAChG,MAAM,aAAa,GAAG,YAAY,CAAC,KAAK,CAAC,GAAG,CAAC;SAC1C,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;SACzB,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAA;IAErB,KAAK,MAAM,QAAQ,IAAI,aAAa,EAAE,CAAC;QACrC,IAAI,QAAQ,KAAK,KAAK,EAAE,CAAC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,QAAQ,CAAA;IACjB,CAAC;CACF"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { BasePlugin } from './plugin-base.js';
|
|
2
|
+
import type { PluginContext } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Accepts a UnixFS `CID` and returns a `.tar` file containing the file or
|
|
5
|
+
* directory structure referenced by the `CID`.
|
|
6
|
+
*/
|
|
7
|
+
export declare class TarPlugin extends BasePlugin {
|
|
8
|
+
readonly codes: never[];
|
|
9
|
+
canHandle({ cid, accept, query }: PluginContext): boolean;
|
|
10
|
+
handle(context: PluginContext): Promise<Response>;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=plugin-handle-tar.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin-handle-tar.d.ts","sourceRoot":"","sources":["../../../src/plugins/plugin-handle-tar.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAE/C;;;GAGG;AACH,qBAAa,SAAU,SAAQ,UAAU;IACvC,QAAQ,CAAC,KAAK,UAAK;IACnB,SAAS,CAAE,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,aAAa,GAAG,OAAO;IAKpD,MAAM,CAAE,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,QAAQ,CAAC;CAuBzD"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { code as dagPbCode } from '@ipld/dag-pb';
|
|
2
|
+
import toBrowserReadableStream from 'it-to-browser-readablestream';
|
|
3
|
+
import { code as rawCode } from 'multiformats/codecs/raw';
|
|
4
|
+
import { getETag } from '../utils/get-e-tag.js';
|
|
5
|
+
import { tarStream } from '../utils/get-tar-stream.js';
|
|
6
|
+
import { notAcceptableResponse, okResponse } from '../utils/responses.js';
|
|
7
|
+
import { BasePlugin } from './plugin-base.js';
|
|
8
|
+
/**
|
|
9
|
+
* Accepts a UnixFS `CID` and returns a `.tar` file containing the file or
|
|
10
|
+
* directory structure referenced by the `CID`.
|
|
11
|
+
*/
|
|
12
|
+
export class TarPlugin extends BasePlugin {
|
|
13
|
+
codes = [];
|
|
14
|
+
canHandle({ cid, accept, query }) {
|
|
15
|
+
this.log('checking if we can handle %c with accept %s', cid, accept);
|
|
16
|
+
return accept === 'application/x-tar' || query.format === 'tar';
|
|
17
|
+
}
|
|
18
|
+
async handle(context) {
|
|
19
|
+
const { cid, path, resource, options, pathDetails } = context;
|
|
20
|
+
const { getBlockstore } = this.pluginOptions;
|
|
21
|
+
const terminusElement = pathDetails?.terminalElement.cid ?? cid;
|
|
22
|
+
if (terminusElement.code !== dagPbCode && terminusElement.code !== rawCode) {
|
|
23
|
+
return notAcceptableResponse('only UnixFS data can be returned in a TAR file');
|
|
24
|
+
}
|
|
25
|
+
context.reqFormat = 'tar';
|
|
26
|
+
context.query.download = true;
|
|
27
|
+
context.query.filename = context.query.filename ?? `${terminusElement.toString()}.tar`;
|
|
28
|
+
const blockstore = getBlockstore(terminusElement, resource, options?.session, options);
|
|
29
|
+
const stream = toBrowserReadableStream(tarStream(`/ipfs/${cid}/${path}`, blockstore, options));
|
|
30
|
+
const response = okResponse(resource, stream);
|
|
31
|
+
response.headers.set('content-type', 'application/x-tar');
|
|
32
|
+
response.headers.set('etag', getETag({ cid: terminusElement, reqFormat: context.reqFormat, weak: true }));
|
|
33
|
+
return response;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=plugin-handle-tar.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin-handle-tar.js","sourceRoot":"","sources":["../../../src/plugins/plugin-handle-tar.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,IAAI,SAAS,EAAE,MAAM,cAAc,CAAA;AAChD,OAAO,uBAAuB,MAAM,8BAA8B,CAAA;AAClE,OAAO,EAAE,IAA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aAAa,CAAC,eAAe,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,CAAA;QACtF,MAAM,MAAM,GAAG,uBAAuB,CAAa,SAAS,CAAC,SAAS,GAAG,IAAI,IAAI,EAAE,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC,CAAA;QAE1G,MAAM,QAAQ,GAAG,UAAU,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAA;QAC7C,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,EAAE,mBAAmB,CAAC,CAAA;QAEzD,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,EAAE,eAAe,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAA;QAEzG,OAAO,QAAQ,CAAA;IACjB,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugins.d.ts","sourceRoot":"","sources":["../../../src/plugins/plugins.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,kBAAkB,EAAE,yBAAyB,EAAE,MAAM,mCAAmC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugins.js","sourceRoot":"","sources":["../../../src/plugins/plugins.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,kBAAkB,EAAE,yBAAyB,EAAE,MAAM,mCAAmC,CAAA"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { PluginError } from './errors.js';
|
|
2
|
+
import type { VerifiedFetchInit } from '../index.js';
|
|
3
|
+
import type { ContentTypeParser, RequestFormatShorthand } from '../types.js';
|
|
4
|
+
import type { ParsedUrlStringResults } from '../utils/parse-url-string.js';
|
|
5
|
+
import type { PathWalkerResponse } from '../utils/walk-path.js';
|
|
6
|
+
import type { AbortOptions, ComponentLogger, Logger } from '@libp2p/interface';
|
|
7
|
+
import type { Helia } from 'helia';
|
|
8
|
+
import type { Blockstore } from 'interface-blockstore';
|
|
9
|
+
import type { UnixFSEntry } from 'ipfs-unixfs-exporter';
|
|
10
|
+
import type { CID } from 'multiformats/cid';
|
|
11
|
+
import type { CustomProgressEvent } from 'progress-events';
|
|
12
|
+
/**
|
|
13
|
+
* Contains common components and functions required by plugins to handle a request.
|
|
14
|
+
* - Read-Only: Plugins can read but shouldn’t rewrite them.
|
|
15
|
+
* - Persistent: Relevant even after the request completes (e.g., logging or metrics).
|
|
16
|
+
*/
|
|
17
|
+
export interface PluginOptions {
|
|
18
|
+
logger: ComponentLogger;
|
|
19
|
+
getBlockstore(cid: CID, resource: string | CID, useSession?: boolean, options?: AbortOptions): Blockstore;
|
|
20
|
+
handleServerTiming<T>(name: string, description: string, fn: () => Promise<T>, withServerTiming: boolean): Promise<T>;
|
|
21
|
+
contentTypeParser?: ContentTypeParser;
|
|
22
|
+
helia: Helia;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Represents the ephemeral, modifiable state used by the pipeline.
|
|
26
|
+
* - Mutable: Evolves as you walk the plugin chain.
|
|
27
|
+
* - Shared Data: Allows plugins to communicate partial results, discovered data, or interim errors.
|
|
28
|
+
* - Ephemeral: Typically discarded once fetch(...) completes.
|
|
29
|
+
*/
|
|
30
|
+
export interface PluginContext {
|
|
31
|
+
readonly cid: CID;
|
|
32
|
+
readonly path: string;
|
|
33
|
+
readonly resource: string;
|
|
34
|
+
readonly accept?: string;
|
|
35
|
+
/**
|
|
36
|
+
* The last time the context is modified, so we know whether a plugin has modified it.
|
|
37
|
+
* A plugin should increment this value if it modifies the context.
|
|
38
|
+
*/
|
|
39
|
+
modified: number;
|
|
40
|
+
withServerTiming?: boolean;
|
|
41
|
+
onProgress?(evt: CustomProgressEvent<any>): void;
|
|
42
|
+
options?: Omit<VerifiedFetchInit, 'signal'> & AbortOptions;
|
|
43
|
+
isDirectory?: boolean;
|
|
44
|
+
directoryEntries?: UnixFSEntry[];
|
|
45
|
+
errors?: PluginError[];
|
|
46
|
+
reqFormat?: RequestFormatShorthand;
|
|
47
|
+
pathDetails?: PathWalkerResponse;
|
|
48
|
+
query: ParsedUrlStringResults['query'];
|
|
49
|
+
[key: string]: unknown;
|
|
50
|
+
}
|
|
51
|
+
export interface VerifiedFetchPlugin {
|
|
52
|
+
readonly codes: number[];
|
|
53
|
+
readonly log: Logger;
|
|
54
|
+
canHandle(context: PluginContext): boolean;
|
|
55
|
+
handle(context: PluginContext): Promise<Response | null>;
|
|
56
|
+
}
|
|
57
|
+
export interface VerifiedFetchPluginFactory {
|
|
58
|
+
(options: PluginOptions): VerifiedFetchPlugin;
|
|
59
|
+
}
|
|
60
|
+
export interface PluginErrorOptions {
|
|
61
|
+
fatal?: boolean;
|
|
62
|
+
details?: Record<string, any>;
|
|
63
|
+
response?: Response;
|
|
64
|
+
}
|
|
65
|
+
export interface FatalPluginErrorOptions extends PluginErrorOptions {
|
|
66
|
+
response: Response;
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/plugins/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAC9C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AACpD,OAAO,KAAK,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AAC5E,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAA;AAC1E,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AAC/D,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAC9E,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,OAAO,CAAA;AAClC,OA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AE,WAAW,EAAE,CAAA;IAChC,MAAM,CAAC,EAAE,WAAW,EAAE,CAAA;IACtB,SAAS,CAAC,EAAE,sBAAsB,CAAA;IAClC,WAAW,CAAC,EAAE,kBAAkB,CAAA;IAChC,KAAK,EAAE,sBAAsB,CAAC,OAAO,CAAC,CAAA;IACtC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CACvB;AAED,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,CAAA;IACxB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;IACpB,SAAS,CAAE,OAAO,EAAE,aAAa,GAAG,OAAO,CAAA;IAC3C,MAAM,CAAE,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,CAAA;CAC1D;AAED,MAAM,WAAW,0BAA0B;IACzC,CAAC,OAAO,EAAE,aAAa,GAAG,mBAAmB,CAAA;CAC9C;AAED,MAAM,WAAW,kBAAkB;IACjC,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC7B,QAAQ,CAAC,EAAE,QAAQ,CAAA;CACpB;AAED,MAAM,WAAW,uBAAwB,SAAQ,kBAAkB;IACjE,QAAQ,EAAE,QAAQ,CAAA;CACnB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/plugins/types.ts"],"names":[],"mappings":""}
|
package/dist/src/types.d.ts
CHANGED
|
@@ -1,32 +1,5 @@
|
|
|
1
|
-
import { type AbortOptions } from '@libp2p/interface';
|
|
2
|
-
import { type CID } from 'multiformats/cid';
|
|
3
|
-
import type { VerifiedFetchInit } from './index.js';
|
|
4
1
|
export type RequestFormatShorthand = 'raw' | 'car' | 'tar' | 'ipns-record' | 'dag-json' | 'dag-cbor' | 'json' | 'cbor';
|
|
5
2
|
export type SupportedBodyTypes = string | ArrayBuffer | Blob | ReadableStream<Uint8Array> | null;
|
|
6
|
-
export interface FetchHandlerFunctionArg {
|
|
7
|
-
cid: CID;
|
|
8
|
-
path: string;
|
|
9
|
-
/**
|
|
10
|
-
* Whether to use a session during fetch operations
|
|
11
|
-
*
|
|
12
|
-
* @default true
|
|
13
|
-
*/
|
|
14
|
-
session: boolean;
|
|
15
|
-
options?: Omit<VerifiedFetchInit, 'signal'> & AbortOptions;
|
|
16
|
-
/**
|
|
17
|
-
* If present, the user has sent an accept header with this value - if the
|
|
18
|
-
* content cannot be represented in this format a 406 should be returned
|
|
19
|
-
*/
|
|
20
|
-
accept?: string;
|
|
21
|
-
/**
|
|
22
|
-
* The originally requested resource
|
|
23
|
-
*/
|
|
24
|
-
resource: string;
|
|
25
|
-
/**
|
|
26
|
-
* Whether to include server-timing headers in the response.
|
|
27
|
-
*/
|
|
28
|
-
withServerTiming: boolean;
|
|
29
|
-
}
|
|
30
3
|
/**
|
|
31
4
|
* A ContentTypeParser attempts to return the mime type of a given file. It
|
|
32
5
|
* receives the first chunk of the file data and the file name, if it is
|
package/dist/src/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,sBAAsB,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,aAAa,GAAG,UAAU,GAAG,UAAU,GAAG,MAAM,GAAG,MAAM,CAAA;AAEtH,MAAM,MAAM,kBAAkB,GAAG,MAAM,GAAG,WAAW,GAAG,IAAI,GAAG,cAAc,CAAC,UAAU,CAAC,GAAG,IAAI,CAAA;AAEhG;;;;;GAKG;AACH,MAAM,WAAW,iBAAiB;IAChC;;;OAGG;IACH,CAAC,KAAK,EAAE,UAAU,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,GAAG,MAAM,GAAG,SAAS,CAAA;CACzF"}
|
package/dist/src/types.js
CHANGED
package/dist/src/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Logger } from '@libp2p/interface';
|
|
2
|
+
import type { UnixFSEntry } from 'ipfs-unixfs-exporter';
|
|
3
|
+
export interface DirIndexHtmlOptions {
|
|
4
|
+
gatewayURL: string;
|
|
5
|
+
dnsLink?: boolean;
|
|
6
|
+
log: Logger;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* todo: https://github.com/ipfs/boxo/blob/09b0013e1c3e09468009b02dfc9b2b9041199d5d/gateway/handler_unixfs_dir.go#L200-L208
|
|
10
|
+
*
|
|
11
|
+
* @see https://github.com/ipfs/boxo/blob/09b0013e1c3e09468009b02dfc9b2b9041199d5d/gateway/assets/directory.html
|
|
12
|
+
* @see https://github.com/ipfs/boxo/pull/298
|
|
13
|
+
* @see https://github.com/ipfs/kubo/pull/8555
|
|
14
|
+
*/
|
|
15
|
+
export declare const dirIndexHtml: (dir: UnixFSEntry, items: UnixFSEntry[], { gatewayURL, dnsLink, log }: DirIndexHtmlOptions) => string;
|
|
16
|
+
//# sourceMappingURL=dir-index-html.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dir-index-html.d.ts","sourceRoot":"","sources":["../../../src/utils/dir-index-html.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAwCvD,MAAM,WAAW,mBAAmB;IAClC,UAAU,EAAE,MAAM,CAAA;IAClB,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,GAAG,EAAE,MAAM,CAAA;CACZ;AA0CD;;;;;;GAMG;AACH,eAAO,MAAM,YAAY,QAAS,WAAW,SAAS,WAAW,EAAE,gCAAgC,mBAAmB,KAAG,MA2FxH,CAAA"}
|