@helia/http 4.0.1 → 4.0.2-f4eb7d27

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.
@@ -12,10 +12,18 @@
12
12
  * ```typescript
13
13
  * import { withHTTP } from '@helia/http'
14
14
  * import { unixfs } from '@helia/unixfs'
15
- * import { createHelia } from 'helia'
15
+ * import { createHeliaLight } from 'helia'
16
16
  * import { CID } from 'multiformats/cid'
17
17
  *
18
- * const helia = await withHTTP(createHelia()).start()
18
+ * const helia = await withHTTP(createHeliaLight(), {
19
+ * delegatedRouters: [
20
+ * 'https://delegated-ipfs.dev'
21
+ * ],
22
+ * recursiveGateways: [
23
+ * 'https://trustless-gateway.link',
24
+ * 'https://4everland.io'
25
+ * ]
26
+ * }).start()
19
27
  *
20
28
  * const fs = unixfs(helia)
21
29
  * fs.cat(CID.parse('bafyFoo'))
@@ -25,14 +33,14 @@
25
33
  * It's possible to manually configure your node without using this module.
26
34
  *
27
35
  * ```typescript
28
- * import { createHelia } from 'helia'
36
+ * import { createHeliaLight } from 'helia'
29
37
  * import { trustlessGatewayBlockBroker } from '@helia/trustless-gateway-client'
30
38
  * import { fallbackRouter } from '@helia/fallback-router'
31
39
  * import { delegatedHTTPRouter } from '@helia/delegated-http-routing-client'
32
40
  * import { unixfs } from '@helia/unixfs'
33
41
  * import { CID } from 'multiformats/cid'
34
42
  *
35
- * const helia = await createHelia({
43
+ * const helia = await createHeliaLight({
36
44
  * blockBrokers: [
37
45
  * trustlessGatewayBlockBroker()
38
46
  * ],
@@ -41,7 +49,7 @@
41
49
  * url: 'https://delegated-ipfs.dev'
42
50
  * }),
43
51
  * fallbackRouter({
44
- * gateways: ['https://cloudflare-ipfs.com', 'https://ipfs.io']
52
+ * gateways: ['https://trustless-gateway.link', 'https://4everland.io']
45
53
  * })
46
54
  * ]
47
55
  * }).start()
@@ -50,10 +58,29 @@
50
58
  * fs.cat(CID.parse('bafyFoo'))
51
59
  * ```
52
60
  */
53
- import type { BlockBroker, Helia, Router } from '@helia/interface';
54
- export interface HTTPOptions {
55
- routers?: Router[];
56
- blockBrokers?: BlockBroker[];
61
+ import type { Helia } from '@helia/interface';
62
+ import type { TrustlessGatewayBlockBrokerInit } from '@helia/trustless-gateway-client';
63
+ export declare const DEFAULT_TRUSTLESS_GATEWAYS: string[];
64
+ export interface HTTPOptions extends TrustlessGatewayBlockBrokerInit {
65
+ /**
66
+ * Delegated routers are servers that make routing requests on behalf of peers
67
+ * with less capable network connectivity.
68
+ *
69
+ * @see https://specs.ipfs.tech/routing/http-routing-v1/
70
+ * @default ['https://delegated-ipfs.dev']
71
+ */
72
+ delegatedRouters?: string[];
73
+ /**
74
+ * A recursive gateway is one that will fetch content on behalf of peers with
75
+ * less capable network connectivity. For example it may fetch content from a
76
+ * node that supports transport(s) which the requesting peer does not.
77
+ *
78
+ * These are used as fallback routers which will always claim to be providers
79
+ * of a given block.
80
+ *
81
+ * @see https://docs.ipfs.tech/concepts/ipfs-gateway/#recursive-vs-non-recursive-gateways
82
+ */
83
+ recursiveGateways?: string[];
57
84
  }
58
85
  /**
59
86
  * Augment a Helia node with HTTP routers and block brokers
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;AAKH,OAAO,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AAElE,MAAM,WAAW,WAAW;IAC1B,OAAO,CAAC,EAAE,MAAM,EAAE,CAAA;IAClB,YAAY,CAAC,EAAE,WAAW,EAAE,CAAA;CAC7B;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAE,CAAC,SAAS,KAAK,EAAG,KAAK,EAAE,CAAC,EAAE,IAAI,CAAC,EAAE,WAAW,GAAG,CAAC,CAiB3E"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2DG;AAKH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,KAAK,EAAE,+BAA+B,EAAE,MAAM,iCAAiC,CAAA;AAEtF,eAAO,MAAM,0BAA0B,UAMtC,CAAA;AAED,MAAM,WAAW,WAAY,SAAQ,+BAA+B;IAClE;;;;;;OAMG;IACH,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAA;IAE3B;;;;;;;;;OASG;IACH,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAA;CAC7B;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAE,CAAC,SAAS,KAAK,EAAG,KAAK,EAAE,CAAC,EAAE,IAAI,CAAC,EAAE,WAAW,GAAG,CAAC,CAqB3E"}
package/dist/src/index.js CHANGED
@@ -12,10 +12,18 @@
12
12
  * ```typescript
13
13
  * import { withHTTP } from '@helia/http'
14
14
  * import { unixfs } from '@helia/unixfs'
15
- * import { createHelia } from 'helia'
15
+ * import { createHeliaLight } from 'helia'
16
16
  * import { CID } from 'multiformats/cid'
17
17
  *
18
- * const helia = await withHTTP(createHelia()).start()
18
+ * const helia = await withHTTP(createHeliaLight(), {
19
+ * delegatedRouters: [
20
+ * 'https://delegated-ipfs.dev'
21
+ * ],
22
+ * recursiveGateways: [
23
+ * 'https://trustless-gateway.link',
24
+ * 'https://4everland.io'
25
+ * ]
26
+ * }).start()
19
27
  *
20
28
  * const fs = unixfs(helia)
21
29
  * fs.cat(CID.parse('bafyFoo'))
@@ -25,14 +33,14 @@
25
33
  * It's possible to manually configure your node without using this module.
26
34
  *
27
35
  * ```typescript
28
- * import { createHelia } from 'helia'
36
+ * import { createHeliaLight } from 'helia'
29
37
  * import { trustlessGatewayBlockBroker } from '@helia/trustless-gateway-client'
30
38
  * import { fallbackRouter } from '@helia/fallback-router'
31
39
  * import { delegatedHTTPRouter } from '@helia/delegated-http-routing-client'
32
40
  * import { unixfs } from '@helia/unixfs'
33
41
  * import { CID } from 'multiformats/cid'
34
42
  *
35
- * const helia = await createHelia({
43
+ * const helia = await createHeliaLight({
36
44
  * blockBrokers: [
37
45
  * trustlessGatewayBlockBroker()
38
46
  * ],
@@ -41,7 +49,7 @@
41
49
  * url: 'https://delegated-ipfs.dev'
42
50
  * }),
43
51
  * fallbackRouter({
44
- * gateways: ['https://cloudflare-ipfs.com', 'https://ipfs.io']
52
+ * gateways: ['https://trustless-gateway.link', 'https://4everland.io']
45
53
  * })
46
54
  * ]
47
55
  * }).start()
@@ -53,23 +61,32 @@
53
61
  import { delegatedHTTPRouter } from '@helia/delegated-routing-client';
54
62
  import { fallbackRouter } from '@helia/fallback-router';
55
63
  import { trustlessGatewayBlockBroker } from '@helia/trustless-gateway-client';
64
+ export const DEFAULT_TRUSTLESS_GATEWAYS = [
65
+ // 2023-10-03: IPNS, Origin, and Block/CAR support from https://ipfs.github.io/public-gateway-checker/
66
+ 'https://trustless-gateway.link',
67
+ // 2023-10-03: IPNS, Origin, and Block/CAR support from https://ipfs.github.io/public-gateway-checker/
68
+ 'https://4everland.io'
69
+ ];
56
70
  /**
57
71
  * Augment a Helia node with HTTP routers and block brokers
58
72
  */
59
73
  export function withHTTP(helia, init) {
60
- init?.routers ?? [
61
- fallbackRouter(),
62
- delegatedHTTPRouter({
63
- url: 'https://delegated-ipfs.dev'
64
- })
65
- ].forEach(router => {
66
- helia.addRouter(router);
67
- });
68
- init?.blockBrokers ?? [
69
- trustlessGatewayBlockBroker()
70
- ].forEach(broker => {
71
- helia.addBlockBroker(broker);
74
+ (init?.delegatedRouters ?? [
75
+ 'https://delegated-ipfs.dev'
76
+ ]).forEach(url => {
77
+ helia.addRouter(delegatedHTTPRouter({
78
+ url,
79
+ filterProtocols: ['unknown', 'transport-ipfs-gateway-http'],
80
+ filterAddrs: ['https', ...(init?.allowInsecure === true ? ['http'] : [])]
81
+ }));
72
82
  });
83
+ helia.addRouter(fallbackRouter({
84
+ gateways: init?.recursiveGateways ?? DEFAULT_TRUSTLESS_GATEWAYS
85
+ }));
86
+ // add trustless gateway block broker
87
+ if (!helia.hasBlockBroker('trustless-gateway')) {
88
+ helia.addBlockBroker(trustlessGatewayBlockBroker(init));
89
+ }
73
90
  return helia;
74
91
  }
75
92
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAA;AACrE,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAA;AACvD,OAAO,EAAE,2BAA2B,EAAE,MAAM,iCAAiC,CAAA;AAQ7E;;GAEG;AACH,MAAM,UAAU,QAAQ,CAAoB,KAAQ,EAAE,IAAkB;IACtE,IAAI,EAAE,OAAO,IAAI;QACf,cAAc,EAAE;QAChB,mBAAmB,CAAC;YAClB,GAAG,EAAE,4BAA4B;SAClC,CAAC;KACH,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;QACjB,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,CAAA;IACzB,CAAC,CAAC,CAAA;IAEF,IAAI,EAAE,YAAY,IAAI;QACpB,2BAA2B,EAAE;KAC9B,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;QACjB,KAAK,CAAC,cAAc,CAAC,MAAM,CAAC,CAAA;IAC9B,CAAC,CAAC,CAAA;IAEF,OAAO,KAAK,CAAA;AACd,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2DG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAA;AACrE,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAA;AACvD,OAAO,EAAE,2BAA2B,EAAE,MAAM,iCAAiC,CAAA;AAI7E,MAAM,CAAC,MAAM,0BAA0B,GAAG;IACxC,sGAAsG;IACtG,gCAAgC;IAEhC,sGAAsG;IACtG,sBAAsB;CACvB,CAAA;AAyBD;;GAEG;AACH,MAAM,UAAU,QAAQ,CAAoB,KAAQ,EAAE,IAAkB;IACtE,CAAC,IAAI,EAAE,gBAAgB,IAAI;QACzB,4BAA4B;KAC7B,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;QACf,KAAK,CAAC,SAAS,CAAC,mBAAmB,CAAC;YAClC,GAAG;YACH,eAAe,EAAE,CAAC,SAAS,EAAE,6BAA6B,CAAC;YAC3D,WAAW,EAAE,CAAC,OAAO,EAAE,GAAG,CAAC,IAAI,EAAE,aAAa,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;SAC1E,CAAC,CAAC,CAAA;IACL,CAAC,CAAC,CAAA;IAEF,KAAK,CAAC,SAAS,CAAC,cAAc,CAAC;QAC7B,QAAQ,EAAE,IAAI,EAAE,iBAAiB,IAAI,0BAA0B;KAChE,CAAC,CAAC,CAAA;IAEH,qCAAqC;IACrC,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,mBAAmB,CAAC,EAAE,CAAC;QAC/C,KAAK,CAAC,cAAc,CAAC,2BAA2B,CAAC,IAAI,CAAC,CAAC,CAAA;IACzD,CAAC;IAED,OAAO,KAAK,CAAA;AACd,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@helia/http",
3
- "version": "4.0.1",
3
+ "version": "4.0.2-f4eb7d27",
4
4
  "description": "A lightweight implementation of IPFS over HTTP in JavaScript",
5
5
  "license": "Apache-2.0 OR MIT",
6
6
  "homepage": "https://github.com/ipfs/helia/tree/main/packages/http#readme",
@@ -48,10 +48,10 @@
48
48
  "test:electron-main": "aegir test -t electron-main"
49
49
  },
50
50
  "dependencies": {
51
- "@helia/delegated-routing-client": "^1.0.1",
52
- "@helia/fallback-router": "^1.0.1",
53
- "@helia/interface": "^7.0.1",
54
- "@helia/trustless-gateway-client": "^1.0.1"
51
+ "@helia/delegated-routing-client": "1.0.2-f4eb7d27",
52
+ "@helia/fallback-router": "1.0.2-f4eb7d27",
53
+ "@helia/interface": "7.0.2-f4eb7d27",
54
+ "@helia/trustless-gateway-client": "1.0.2-f4eb7d27"
55
55
  },
56
56
  "devDependencies": {
57
57
  "aegir": "^48.0.11",
package/src/index.ts CHANGED
@@ -12,10 +12,18 @@
12
12
  * ```typescript
13
13
  * import { withHTTP } from '@helia/http'
14
14
  * import { unixfs } from '@helia/unixfs'
15
- * import { createHelia } from 'helia'
15
+ * import { createHeliaLight } from 'helia'
16
16
  * import { CID } from 'multiformats/cid'
17
17
  *
18
- * const helia = await withHTTP(createHelia()).start()
18
+ * const helia = await withHTTP(createHeliaLight(), {
19
+ * delegatedRouters: [
20
+ * 'https://delegated-ipfs.dev'
21
+ * ],
22
+ * recursiveGateways: [
23
+ * 'https://trustless-gateway.link',
24
+ * 'https://4everland.io'
25
+ * ]
26
+ * }).start()
19
27
  *
20
28
  * const fs = unixfs(helia)
21
29
  * fs.cat(CID.parse('bafyFoo'))
@@ -25,14 +33,14 @@
25
33
  * It's possible to manually configure your node without using this module.
26
34
  *
27
35
  * ```typescript
28
- * import { createHelia } from 'helia'
36
+ * import { createHeliaLight } from 'helia'
29
37
  * import { trustlessGatewayBlockBroker } from '@helia/trustless-gateway-client'
30
38
  * import { fallbackRouter } from '@helia/fallback-router'
31
39
  * import { delegatedHTTPRouter } from '@helia/delegated-http-routing-client'
32
40
  * import { unixfs } from '@helia/unixfs'
33
41
  * import { CID } from 'multiformats/cid'
34
42
  *
35
- * const helia = await createHelia({
43
+ * const helia = await createHeliaLight({
36
44
  * blockBrokers: [
37
45
  * trustlessGatewayBlockBroker()
38
46
  * ],
@@ -41,7 +49,7 @@
41
49
  * url: 'https://delegated-ipfs.dev'
42
50
  * }),
43
51
  * fallbackRouter({
44
- * gateways: ['https://cloudflare-ipfs.com', 'https://ipfs.io']
52
+ * gateways: ['https://trustless-gateway.link', 'https://4everland.io']
45
53
  * })
46
54
  * ]
47
55
  * }).start()
@@ -54,31 +62,62 @@
54
62
  import { delegatedHTTPRouter } from '@helia/delegated-routing-client'
55
63
  import { fallbackRouter } from '@helia/fallback-router'
56
64
  import { trustlessGatewayBlockBroker } from '@helia/trustless-gateway-client'
57
- import type { BlockBroker, Helia, Router } from '@helia/interface'
65
+ import type { Helia } from '@helia/interface'
66
+ import type { TrustlessGatewayBlockBrokerInit } from '@helia/trustless-gateway-client'
67
+
68
+ export const DEFAULT_TRUSTLESS_GATEWAYS = [
69
+ // 2023-10-03: IPNS, Origin, and Block/CAR support from https://ipfs.github.io/public-gateway-checker/
70
+ 'https://trustless-gateway.link',
58
71
 
59
- export interface HTTPOptions {
60
- routers?: Router[]
61
- blockBrokers?: BlockBroker[]
72
+ // 2023-10-03: IPNS, Origin, and Block/CAR support from https://ipfs.github.io/public-gateway-checker/
73
+ 'https://4everland.io'
74
+ ]
75
+
76
+ export interface HTTPOptions extends TrustlessGatewayBlockBrokerInit {
77
+ /**
78
+ * Delegated routers are servers that make routing requests on behalf of peers
79
+ * with less capable network connectivity.
80
+ *
81
+ * @see https://specs.ipfs.tech/routing/http-routing-v1/
82
+ * @default ['https://delegated-ipfs.dev']
83
+ */
84
+ delegatedRouters?: string[]
85
+
86
+ /**
87
+ * A recursive gateway is one that will fetch content on behalf of peers with
88
+ * less capable network connectivity. For example it may fetch content from a
89
+ * node that supports transport(s) which the requesting peer does not.
90
+ *
91
+ * These are used as fallback routers which will always claim to be providers
92
+ * of a given block.
93
+ *
94
+ * @see https://docs.ipfs.tech/concepts/ipfs-gateway/#recursive-vs-non-recursive-gateways
95
+ */
96
+ recursiveGateways?: string[]
62
97
  }
63
98
 
64
99
  /**
65
100
  * Augment a Helia node with HTTP routers and block brokers
66
101
  */
67
102
  export function withHTTP <H extends Helia> (helia: H, init?: HTTPOptions): H {
68
- init?.routers ?? [
69
- fallbackRouter(),
70
- delegatedHTTPRouter({
71
- url: 'https://delegated-ipfs.dev'
72
- })
73
- ].forEach(router => {
74
- helia.addRouter(router)
103
+ (init?.delegatedRouters ?? [
104
+ 'https://delegated-ipfs.dev'
105
+ ]).forEach(url => {
106
+ helia.addRouter(delegatedHTTPRouter({
107
+ url,
108
+ filterProtocols: ['unknown', 'transport-ipfs-gateway-http'],
109
+ filterAddrs: ['https', ...(init?.allowInsecure === true ? ['http'] : [])]
110
+ }))
75
111
  })
76
112
 
77
- init?.blockBrokers ?? [
78
- trustlessGatewayBlockBroker()
79
- ].forEach(broker => {
80
- helia.addBlockBroker(broker)
81
- })
113
+ helia.addRouter(fallbackRouter({
114
+ gateways: init?.recursiveGateways ?? DEFAULT_TRUSTLESS_GATEWAYS
115
+ }))
116
+
117
+ // add trustless gateway block broker
118
+ if (!helia.hasBlockBroker('trustless-gateway')) {
119
+ helia.addBlockBroker(trustlessGatewayBlockBroker(init))
120
+ }
82
121
 
83
122
  return helia
84
123
  }
@@ -1,6 +0,0 @@
1
- {
2
- "HTTPOptions": "https://ipfs.github.io/helia/interfaces/_helia_http.HTTPOptions.html",
3
- ".:HTTPOptions": "https://ipfs.github.io/helia/interfaces/_helia_http.HTTPOptions.html",
4
- "withHTTP": "https://ipfs.github.io/helia/functions/_helia_http.withHTTP.html",
5
- ".:withHTTP": "https://ipfs.github.io/helia/functions/_helia_http.withHTTP.html"
6
- }