@helia/http 4.0.0-cee53d7d → 4.0.1-688bd9de

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,35 @@
50
58
  * fs.cat(CID.parse('bafyFoo'))
51
59
  * ```
52
60
  */
53
- import type { BlockBroker, Helia, Router } from '@helia/interface';
61
+ import type { Helia } from '@helia/interface';
62
+ import type { TrustlessGatewayBlockBrokerInit } from '@helia/trustless-gateway-client';
63
+ export declare const DEFAULT_TRUSTLESS_GATEWAYS: string[];
54
64
  export interface HTTPOptions {
55
- routers?: Router[];
56
- blockBrokers?: BlockBroker[];
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[];
84
+ /**
85
+ * Init arg passed to the trustless gateway block broker
86
+ *
87
+ * @see https://docs.ipfs.tech/reference/http/gateway/#trusted-vs-trustless
88
+ */
89
+ trustlessGatewayBlockBrokerInit?: TrustlessGatewayBlockBrokerInit;
57
90
  }
58
91
  /**
59
92
  * 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,WAAW;IAC1B;;;;;;OAMG;IACH,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAA;IAE3B;;;;;;;;;OASG;IACH,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAA;IAE5B;;;;OAIG;IACH,+BAA+B,CAAC,EAAE,+BAA+B,CAAA;CAClE;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAE,CAAC,SAAS,KAAK,EAAG,KAAK,EAAE,CAAC,EAAE,IAAI,CAAC,EAAE,WAAW,GAAG,CAAC,CAmB3E"}
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,30 @@
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
+ }));
72
80
  });
81
+ helia.addRouter(fallbackRouter({
82
+ gateways: init?.recursiveGateways ?? DEFAULT_TRUSTLESS_GATEWAYS
83
+ }));
84
+ // add trustless gateway block broker
85
+ if (!helia.hasBlockBroker('trustless-gateway')) {
86
+ helia.addBlockBroker(trustlessGatewayBlockBroker(init?.trustlessGatewayBlockBrokerInit));
87
+ }
73
88
  return helia;
74
89
  }
75
90
  //# 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;AAgCD;;GAEG;AACH,MAAM,UAAU,QAAQ,CAAoB,KAAQ,EAAE,IAAkB;IACtE,IAAI,EAAE,gBAAgB,IAAI;QACxB,4BAA4B;KAC7B,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;QACd,KAAK,CAAC,SAAS,CAAC,mBAAmB,CAAC;YAClC,GAAG;SACJ,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,EAAE,+BAA+B,CAAC,CAAC,CAAA;IAC1F,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.0-cee53d7d",
3
+ "version": "4.0.1-688bd9de",
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.0-cee53d7d",
52
- "@helia/fallback-router": "1.0.0-cee53d7d",
53
- "@helia/interface": "7.0.0-cee53d7d",
54
- "@helia/trustless-gateway-client": "1.0.0-cee53d7d"
51
+ "@helia/delegated-routing-client": "1.0.1-688bd9de",
52
+ "@helia/fallback-router": "1.0.1-688bd9de",
53
+ "@helia/interface": "7.0.1-688bd9de",
54
+ "@helia/trustless-gateway-client": "1.0.1-688bd9de"
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,67 @@
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',
71
+
72
+ // 2023-10-03: IPNS, Origin, and Block/CAR support from https://ipfs.github.io/public-gateway-checker/
73
+ 'https://4everland.io'
74
+ ]
58
75
 
59
76
  export interface HTTPOptions {
60
- routers?: Router[]
61
- blockBrokers?: BlockBroker[]
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[]
97
+
98
+ /**
99
+ * Init arg passed to the trustless gateway block broker
100
+ *
101
+ * @see https://docs.ipfs.tech/reference/http/gateway/#trusted-vs-trustless
102
+ */
103
+ trustlessGatewayBlockBrokerInit?: TrustlessGatewayBlockBrokerInit
62
104
  }
63
105
 
64
106
  /**
65
107
  * Augment a Helia node with HTTP routers and block brokers
66
108
  */
67
109
  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)
110
+ init?.delegatedRouters ?? [
111
+ 'https://delegated-ipfs.dev'
112
+ ].forEach(url => {
113
+ helia.addRouter(delegatedHTTPRouter({
114
+ url
115
+ }))
75
116
  })
76
117
 
77
- init?.blockBrokers ?? [
78
- trustlessGatewayBlockBroker()
79
- ].forEach(broker => {
80
- helia.addBlockBroker(broker)
81
- })
118
+ helia.addRouter(fallbackRouter({
119
+ gateways: init?.recursiveGateways ?? DEFAULT_TRUSTLESS_GATEWAYS
120
+ }))
121
+
122
+ // add trustless gateway block broker
123
+ if (!helia.hasBlockBroker('trustless-gateway')) {
124
+ helia.addBlockBroker(trustlessGatewayBlockBroker(init?.trustlessGatewayBlockBrokerInit))
125
+ }
82
126
 
83
127
  return helia
84
128
  }