@helia/verified-fetch 0.0.0-f243de2 → 0.0.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/dist/index.min.js +6 -6
- package/dist/src/index.d.ts +10 -6
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +24 -11
- package/dist/src/index.js.map +1 -1
- package/dist/src/utils/get-stream-and-content-type.d.ts +1 -2
- package/dist/src/utils/get-stream-and-content-type.d.ts.map +1 -1
- package/dist/src/utils/get-stream-and-content-type.js +4 -3
- package/dist/src/utils/get-stream-and-content-type.js.map +1 -1
- package/dist/src/utils/parse-resource.d.ts +1 -6
- package/dist/src/utils/parse-resource.d.ts.map +1 -1
- package/dist/src/utils/parse-resource.js +2 -2
- package/dist/src/utils/parse-resource.js.map +1 -1
- package/dist/src/utils/parse-url-string.d.ts +2 -3
- package/dist/src/utils/parse-url-string.d.ts.map +1 -1
- package/dist/src/utils/parse-url-string.js +4 -2
- package/dist/src/utils/parse-url-string.js.map +1 -1
- package/dist/src/utils/walk-path.d.ts +1 -2
- package/dist/src/utils/walk-path.d.ts.map +1 -1
- package/dist/src/utils/walk-path.js +3 -1
- package/dist/src/utils/walk-path.js.map +1 -1
- package/dist/src/verified-fetch.d.ts +0 -1
- package/dist/src/verified-fetch.d.ts.map +1 -1
- package/dist/src/verified-fetch.js +17 -17
- package/dist/src/verified-fetch.js.map +1 -1
- package/dist/typedoc-urls.json +20 -0
- package/package.json +12 -17
- package/src/index.ts +10 -3
- package/src/utils/get-stream-and-content-type.ts +1 -1
- package/src/utils/parse-url-string.ts +1 -0
- package/src/utils/walk-path.ts +5 -4
- package/src/verified-fetch.ts +3 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@helia/verified-fetch",
|
|
3
|
-
"version": "0.0.0
|
|
3
|
+
"version": "0.0.0",
|
|
4
4
|
"description": "A fetch-like API for obtaining verified & trustless IPFS content on the web.",
|
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
|
6
6
|
"homepage": "https://github.com/ipfs/helia/tree/main/packages/verified-fetch#readme",
|
|
@@ -11,10 +11,6 @@
|
|
|
11
11
|
"bugs": {
|
|
12
12
|
"url": "https://github.com/ipfs/helia/issues"
|
|
13
13
|
},
|
|
14
|
-
"publishConfig": {
|
|
15
|
-
"access": "public",
|
|
16
|
-
"provenance": true
|
|
17
|
-
},
|
|
18
14
|
"keywords": [
|
|
19
15
|
"IPFS",
|
|
20
16
|
"fetch",
|
|
@@ -141,15 +137,15 @@
|
|
|
141
137
|
"release": "aegir release"
|
|
142
138
|
},
|
|
143
139
|
"dependencies": {
|
|
144
|
-
"@helia/block-brokers": "2.0.1
|
|
145
|
-
"@helia/dag-cbor": "3.0.0
|
|
146
|
-
"@helia/dag-json": "3.0.0
|
|
147
|
-
"@helia/http": "1.0.1
|
|
148
|
-
"@helia/interface": "4.0.0
|
|
149
|
-
"@helia/ipns": "6.0.0
|
|
150
|
-
"@helia/json": "3.0.0
|
|
151
|
-
"@helia/routers": "1.0.0
|
|
152
|
-
"@helia/unixfs": "3.0.0
|
|
140
|
+
"@helia/block-brokers": "^2.0.1",
|
|
141
|
+
"@helia/dag-cbor": "^3.0.0",
|
|
142
|
+
"@helia/dag-json": "^3.0.0",
|
|
143
|
+
"@helia/http": "^1.0.1",
|
|
144
|
+
"@helia/interface": "^4.0.0",
|
|
145
|
+
"@helia/ipns": "^6.0.0",
|
|
146
|
+
"@helia/json": "^3.0.0",
|
|
147
|
+
"@helia/routers": "^1.0.0",
|
|
148
|
+
"@helia/unixfs": "^3.0.0",
|
|
153
149
|
"@ipld/dag-cbor": "^9.1.0",
|
|
154
150
|
"@ipld/dag-json": "^10.1.7",
|
|
155
151
|
"@ipld/dag-pb": "^4.0.8",
|
|
@@ -167,10 +163,9 @@
|
|
|
167
163
|
"@types/mime-types": "^2.1.4",
|
|
168
164
|
"@types/sinon": "^17.0.2",
|
|
169
165
|
"aegir": "^42.1.0",
|
|
170
|
-
"helia": "4.0.1
|
|
166
|
+
"helia": "^4.0.1",
|
|
171
167
|
"interface-blockstore": "^5.2.9",
|
|
172
168
|
"sinon": "^17.0.1",
|
|
173
169
|
"sinon-ts": "^2.0.0"
|
|
174
|
-
}
|
|
175
|
-
"sideEffects": false
|
|
170
|
+
}
|
|
176
171
|
}
|
package/src/index.ts
CHANGED
|
@@ -219,7 +219,7 @@ import { trustlessGateway } from '@helia/block-brokers'
|
|
|
219
219
|
import { createHeliaHTTP } from '@helia/http'
|
|
220
220
|
import { delegatedHTTPRouting } from '@helia/routers'
|
|
221
221
|
import { VerifiedFetch as VerifiedFetchClass } from './verified-fetch.js'
|
|
222
|
-
import type { Helia } from '@helia/interface'
|
|
222
|
+
import type { Helia, Routing } from '@helia/interface'
|
|
223
223
|
import type { IPNSRoutingEvents, ResolveDnsLinkProgressEvents, ResolveProgressEvents } from '@helia/ipns'
|
|
224
224
|
import type { GetEvents } from '@helia/unixfs'
|
|
225
225
|
import type { CID } from 'multiformats/cid'
|
|
@@ -280,13 +280,20 @@ export interface VerifiedFetchInit extends RequestInit, ProgressOptions<BubbledP
|
|
|
280
280
|
*/
|
|
281
281
|
export async function createVerifiedFetch (init: Helia | CreateVerifiedFetchWithOptions): Promise<VerifiedFetch> {
|
|
282
282
|
if (!isHelia(init)) {
|
|
283
|
+
const config = init
|
|
284
|
+
let routers: undefined | Array<Partial<Routing>>
|
|
285
|
+
|
|
286
|
+
if (config.routers != null) {
|
|
287
|
+
routers = config.routers.map((routerUrl) => delegatedHTTPRouting(routerUrl))
|
|
288
|
+
}
|
|
289
|
+
|
|
283
290
|
init = await createHeliaHTTP({
|
|
284
291
|
blockBrokers: [
|
|
285
292
|
trustlessGateway({
|
|
286
|
-
gateways:
|
|
293
|
+
gateways: config.gateways
|
|
287
294
|
})
|
|
288
295
|
],
|
|
289
|
-
routers
|
|
296
|
+
routers
|
|
290
297
|
})
|
|
291
298
|
}
|
|
292
299
|
|
|
@@ -10,6 +10,7 @@ export async function getStreamAndContentType (iterator: AsyncIterable<Uint8Arra
|
|
|
10
10
|
const log = logger.forComponent('helia:verified-fetch:get-stream-and-content-type')
|
|
11
11
|
const reader = iterator[Symbol.asyncIterator]()
|
|
12
12
|
const { value, done } = await reader.next()
|
|
13
|
+
options?.onProgress?.(new CustomProgressEvent<void>('verified-fetch:request:progress:chunk'))
|
|
13
14
|
|
|
14
15
|
if (done === true) {
|
|
15
16
|
log.error('No content found for path', path)
|
|
@@ -20,7 +21,6 @@ export async function getStreamAndContentType (iterator: AsyncIterable<Uint8Arra
|
|
|
20
21
|
const stream = new ReadableStream({
|
|
21
22
|
async start (controller) {
|
|
22
23
|
// the initial value is already available
|
|
23
|
-
options?.onProgress?.(new CustomProgressEvent<void>('verified-fetch:request:progress:chunk'))
|
|
24
24
|
controller.enqueue(value)
|
|
25
25
|
},
|
|
26
26
|
async pull (controller) {
|
|
@@ -31,6 +31,7 @@ const URL_REGEX = /^(?<protocol>ip[fn]s):\/\/(?<cidOrPeerIdOrDnsLink>[^/$?]+)\/?
|
|
|
31
31
|
* After determining the protocol successfully, we process the cidOrPeerIdOrDnsLink:
|
|
32
32
|
* * If it's ipfs, it parses the CID or throws an Aggregate error
|
|
33
33
|
* * If it's ipns, it attempts to resolve the PeerId and then the DNSLink. If both fail, an Aggregate error is thrown.
|
|
34
|
+
*
|
|
34
35
|
*/
|
|
35
36
|
export async function parseUrlString ({ urlString, ipns, logger }: ParseUrlStringInput, options?: ParseUrlStringOptions): Promise<ParsedUrlStringResults> {
|
|
36
37
|
const log = logger.forComponent('helia:verified-fetch:parse-url-string')
|
package/src/utils/walk-path.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { walkPath as exporterWalk, type ExporterOptions, type ReadableStorage, type UnixFSEntry } from 'ipfs-unixfs-exporter'
|
|
2
|
-
import type { CID } from 'multiformats/cid'
|
|
3
2
|
|
|
4
3
|
export interface PathWalkerOptions extends ExporterOptions {
|
|
5
4
|
|
|
6
5
|
}
|
|
7
6
|
export interface PathWalkerResponse {
|
|
8
|
-
ipfsRoots:
|
|
7
|
+
ipfsRoots: string[]
|
|
9
8
|
terminalElement: UnixFSEntry
|
|
10
9
|
|
|
11
10
|
}
|
|
@@ -15,11 +14,13 @@ export interface PathWalkerFn {
|
|
|
15
14
|
}
|
|
16
15
|
|
|
17
16
|
export async function walkPath (blockstore: ReadableStorage, path: string, options?: PathWalkerOptions): Promise<PathWalkerResponse> {
|
|
18
|
-
const
|
|
17
|
+
const entries: UnixFSEntry[] = []
|
|
18
|
+
const ipfsRoots: string[] = []
|
|
19
19
|
let terminalElement: UnixFSEntry | undefined
|
|
20
20
|
|
|
21
21
|
for await (const entry of exporterWalk(path, blockstore, options)) {
|
|
22
|
-
|
|
22
|
+
entries.push(entry)
|
|
23
|
+
ipfsRoots.push(entry.cid.toString())
|
|
23
24
|
terminalElement = entry
|
|
24
25
|
}
|
|
25
26
|
|
package/src/verified-fetch.ts
CHANGED
|
@@ -274,11 +274,11 @@ export class VerifiedFetch {
|
|
|
274
274
|
}
|
|
275
275
|
|
|
276
276
|
let terminalElement: UnixFSEntry | undefined
|
|
277
|
-
let ipfsRoots:
|
|
277
|
+
let ipfsRoots: string | undefined
|
|
278
278
|
|
|
279
279
|
try {
|
|
280
280
|
const pathDetails = await this.pathWalker(this.helia.blockstore, `${cid.toString()}/${path}`, options)
|
|
281
|
-
ipfsRoots = pathDetails.ipfsRoots
|
|
281
|
+
ipfsRoots = pathDetails.ipfsRoots.join(',')
|
|
282
282
|
terminalElement = pathDetails.terminalElement
|
|
283
283
|
} catch (err) {
|
|
284
284
|
this.log.error('Error walking path %s', path, err)
|
|
@@ -300,7 +300,7 @@ export class VerifiedFetch {
|
|
|
300
300
|
response.headers.set('X-Ipfs-Path', resource.toString()) // https://specs.ipfs.tech/http-gateways/path-gateway/#x-ipfs-path-response-header
|
|
301
301
|
|
|
302
302
|
if (ipfsRoots != null) {
|
|
303
|
-
response.headers.set('X-Ipfs-Roots', ipfsRoots
|
|
303
|
+
response.headers.set('X-Ipfs-Roots', ipfsRoots) // https://specs.ipfs.tech/http-gateways/path-gateway/#x-ipfs-roots-response-header
|
|
304
304
|
}
|
|
305
305
|
// response.headers.set('Content-Disposition', `TODO`) // https://specs.ipfs.tech/http-gateways/path-gateway/#content-disposition-response-header
|
|
306
306
|
|