@helia/verified-fetch 4.0.0 → 4.0.2

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.
Files changed (126) hide show
  1. package/README.md +7 -49
  2. package/dist/index.min.js +56 -51
  3. package/dist/index.min.js.map +4 -4
  4. package/dist/src/index.d.ts +12 -52
  5. package/dist/src/index.d.ts.map +1 -1
  6. package/dist/src/index.js +8 -50
  7. package/dist/src/index.js.map +1 -1
  8. package/dist/src/plugins/index.d.ts +0 -1
  9. package/dist/src/plugins/index.d.ts.map +1 -1
  10. package/dist/src/plugins/index.js +0 -1
  11. package/dist/src/plugins/index.js.map +1 -1
  12. package/dist/src/plugins/plugin-base.d.ts.map +1 -1
  13. package/dist/src/plugins/plugin-base.js +3 -2
  14. package/dist/src/plugins/plugin-base.js.map +1 -1
  15. package/dist/src/plugins/plugin-handle-car.d.ts.map +1 -1
  16. package/dist/src/plugins/plugin-handle-car.js +0 -1
  17. package/dist/src/plugins/plugin-handle-car.js.map +1 -1
  18. package/dist/src/plugins/plugin-handle-dag-cbor-html-preview.d.ts +3 -3
  19. package/dist/src/plugins/plugin-handle-dag-cbor-html-preview.d.ts.map +1 -1
  20. package/dist/src/plugins/plugin-handle-dag-cbor-html-preview.js +5 -6
  21. package/dist/src/plugins/plugin-handle-dag-cbor-html-preview.js.map +1 -1
  22. package/dist/src/plugins/plugin-handle-dag-cbor.d.ts.map +1 -1
  23. package/dist/src/plugins/plugin-handle-dag-cbor.js +0 -1
  24. package/dist/src/plugins/plugin-handle-dag-cbor.js.map +1 -1
  25. package/dist/src/plugins/plugin-handle-dag-pb.d.ts.map +1 -1
  26. package/dist/src/plugins/plugin-handle-dag-pb.js +34 -39
  27. package/dist/src/plugins/plugin-handle-dag-pb.js.map +1 -1
  28. package/dist/src/plugins/plugin-handle-dag-walk.d.ts +8 -4
  29. package/dist/src/plugins/plugin-handle-dag-walk.d.ts.map +1 -1
  30. package/dist/src/plugins/plugin-handle-dag-walk.js +8 -5
  31. package/dist/src/plugins/plugin-handle-dag-walk.js.map +1 -1
  32. package/dist/src/plugins/plugin-handle-ipns-record.d.ts +1 -1
  33. package/dist/src/plugins/plugin-handle-ipns-record.d.ts.map +1 -1
  34. package/dist/src/plugins/plugin-handle-ipns-record.js +4 -6
  35. package/dist/src/plugins/plugin-handle-ipns-record.js.map +1 -1
  36. package/dist/src/plugins/plugin-handle-json.d.ts.map +1 -1
  37. package/dist/src/plugins/plugin-handle-json.js +0 -1
  38. package/dist/src/plugins/plugin-handle-json.js.map +1 -1
  39. package/dist/src/plugins/plugin-handle-raw.d.ts.map +1 -1
  40. package/dist/src/plugins/plugin-handle-raw.js +4 -8
  41. package/dist/src/plugins/plugin-handle-raw.js.map +1 -1
  42. package/dist/src/plugins/plugin-handle-tar.d.ts.map +1 -1
  43. package/dist/src/plugins/plugin-handle-tar.js +0 -1
  44. package/dist/src/plugins/plugin-handle-tar.js.map +1 -1
  45. package/dist/src/plugins/types.d.ts +6 -11
  46. package/dist/src/plugins/types.d.ts.map +1 -1
  47. package/dist/src/url-resolver.d.ts +4 -3
  48. package/dist/src/url-resolver.d.ts.map +1 -1
  49. package/dist/src/url-resolver.js +35 -47
  50. package/dist/src/url-resolver.js.map +1 -1
  51. package/dist/src/utils/byte-range-context.d.ts +2 -2
  52. package/dist/src/utils/byte-range-context.d.ts.map +1 -1
  53. package/dist/src/utils/byte-range-context.js +1 -1
  54. package/dist/src/utils/byte-range-context.js.map +1 -1
  55. package/dist/src/utils/content-type-parser.d.ts.map +1 -1
  56. package/dist/src/utils/content-type-parser.js +0 -10
  57. package/dist/src/utils/content-type-parser.js.map +1 -1
  58. package/dist/src/utils/dnslink-label.d.ts +26 -0
  59. package/dist/src/utils/dnslink-label.d.ts.map +1 -0
  60. package/dist/src/utils/dnslink-label.js +35 -0
  61. package/dist/src/utils/dnslink-label.js.map +1 -0
  62. package/dist/src/utils/error-to-object.d.ts +6 -0
  63. package/dist/src/utils/error-to-object.d.ts.map +1 -0
  64. package/dist/src/utils/error-to-object.js +20 -0
  65. package/dist/src/utils/error-to-object.js.map +1 -0
  66. package/dist/src/utils/get-content-type.d.ts +1 -1
  67. package/dist/src/utils/get-content-type.d.ts.map +1 -1
  68. package/dist/src/utils/get-content-type.js +1 -1
  69. package/dist/src/utils/get-content-type.js.map +1 -1
  70. package/dist/src/utils/get-stream-from-async-iterable.d.ts +1 -2
  71. package/dist/src/utils/get-stream-from-async-iterable.d.ts.map +1 -1
  72. package/dist/src/utils/get-stream-from-async-iterable.js +1 -3
  73. package/dist/src/utils/get-stream-from-async-iterable.js.map +1 -1
  74. package/dist/src/utils/handle-redirects.js +2 -2
  75. package/dist/src/utils/ipfs-path-to-url.d.ts +16 -0
  76. package/dist/src/utils/ipfs-path-to-url.d.ts.map +1 -0
  77. package/dist/src/utils/ipfs-path-to-url.js +45 -0
  78. package/dist/src/utils/ipfs-path-to-url.js.map +1 -0
  79. package/dist/src/utils/parse-url-string.d.ts +18 -5
  80. package/dist/src/utils/parse-url-string.d.ts.map +1 -1
  81. package/dist/src/utils/parse-url-string.js +126 -44
  82. package/dist/src/utils/parse-url-string.js.map +1 -1
  83. package/dist/src/utils/resource-to-cache-key.js +2 -2
  84. package/dist/src/utils/responses.d.ts +2 -1
  85. package/dist/src/utils/responses.d.ts.map +1 -1
  86. package/dist/src/utils/responses.js +16 -1
  87. package/dist/src/utils/responses.js.map +1 -1
  88. package/dist/src/utils/walk-path.js +1 -1
  89. package/dist/src/utils/walk-path.js.map +1 -1
  90. package/dist/src/verified-fetch.d.ts.map +1 -1
  91. package/dist/src/verified-fetch.js +36 -28
  92. package/dist/src/verified-fetch.js.map +1 -1
  93. package/dist/typedoc-urls.json +0 -2
  94. package/package.json +10 -10
  95. package/src/index.ts +12 -52
  96. package/src/plugins/index.ts +0 -1
  97. package/src/plugins/plugin-base.ts +3 -2
  98. package/src/plugins/plugin-handle-car.ts +0 -2
  99. package/src/plugins/plugin-handle-dag-cbor-html-preview.ts +10 -9
  100. package/src/plugins/plugin-handle-dag-cbor.ts +3 -1
  101. package/src/plugins/plugin-handle-dag-pb.ts +49 -37
  102. package/src/plugins/plugin-handle-dag-walk.ts +10 -5
  103. package/src/plugins/plugin-handle-ipns-record.ts +6 -6
  104. package/src/plugins/plugin-handle-json.ts +1 -1
  105. package/src/plugins/plugin-handle-raw.ts +7 -8
  106. package/src/plugins/plugin-handle-tar.ts +2 -1
  107. package/src/plugins/types.ts +7 -12
  108. package/src/url-resolver.ts +37 -56
  109. package/src/utils/byte-range-context.ts +3 -3
  110. package/src/utils/content-type-parser.ts +5 -11
  111. package/src/utils/dnslink-label.ts +38 -0
  112. package/src/utils/error-to-object.ts +22 -0
  113. package/src/utils/get-content-type.ts +2 -2
  114. package/src/utils/get-stream-from-async-iterable.ts +1 -4
  115. package/src/utils/handle-redirects.ts +2 -2
  116. package/src/utils/ipfs-path-to-url.ts +54 -0
  117. package/src/utils/parse-url-string.ts +166 -49
  118. package/src/utils/resource-to-cache-key.ts +2 -2
  119. package/src/utils/responses.ts +21 -1
  120. package/src/utils/walk-path.ts +1 -1
  121. package/src/verified-fetch.ts +46 -28
  122. package/dist/src/plugins/errors.d.ts +0 -25
  123. package/dist/src/plugins/errors.d.ts.map +0 -1
  124. package/dist/src/plugins/errors.js +0 -33
  125. package/dist/src/plugins/errors.js.map +0 -1
  126. package/src/plugins/errors.ts +0 -37
package/README.md CHANGED
@@ -672,13 +672,13 @@ Each plugin must implement two methods:
672
672
  Inspects the current `PluginContext` (which includes the CID, path, query, accept header, etc.)
673
673
  and returns `true` if the plugin can operate on the current state of the request.
674
674
 
675
- - **`handle(context: PluginContext): Promise<Response | null>`**
676
- Performs the plugin’s work. It may:
677
- - **Return a final `Response`**: This stops the pipeline immediately.
678
- - **Return `null`**: This indicates that the plugin has only partially processed the request
675
+ - **`handle(context: PluginContext): Promise<Response | undefined>`**
676
+ Performs the plugin’s work. It will only be executed if `canHandle` previously returned `true`.
677
+ It may:
678
+ - **Return a `Response`**: This stops the pipeline immediately and returns the response.
679
+ - **Return `undefined`**: This indicates that the plugin has only partially processed the request
679
680
  (for example, by performing path walking or decoding) and the pipeline should continue.
680
- - **Throw a `PluginError`**: This logs a non-fatal error and continues the pipeline.
681
- - **Throw a `PluginFatalError`**: This logs a fatal error and stops the pipeline immediately.
681
+ - **Throw an `Error`**: An Internal Server Error will be returned
682
682
 
683
683
  ### Plugin Pipeline
684
684
 
@@ -816,47 +816,6 @@ To add your own plugin:
816
816
  const fetch = await createVerifiedFetch(helia, { plugins })
817
817
  ```
818
818
 
819
- ***
820
-
821
- ### Error Handling in the Plugin Pipeline
822
-
823
- Verified‑Fetch distinguishes between two types of errors thrown by plugins:
824
-
825
- - **PluginError (Non‑Fatal):**
826
- - Use this when your plugin encounters an issue that should be logged but does not prevent the pipeline
827
- from continuing.
828
- - When a plugin throws a `PluginError`, the error is logged and the pipeline continues with the next plugin.
829
-
830
- - **PluginFatalError (Fatal):**
831
- - Use this when a critical error occurs that should immediately abort the request.
832
- - When a plugin throws a `PluginFatalError`, the pipeline immediately terminates and the provided error
833
- response is returned.
834
-
835
- ## Example - Plugin error Handling
836
-
837
- ```typescript
838
- import { PluginError, PluginFatalError } from '@helia/verified-fetch'
839
-
840
- // async handle(context: PluginContext): Promise<Response | null> {
841
- const recoverable = Math.random() > 0.5 // Use more sophisticated logic here ;)
842
- if (recoverable === true) {
843
- throw new PluginError('MY_CUSTOM_WARNING', 'A non‑fatal issue occurred', {
844
- details: {
845
- someKey: 'Additional details here'
846
- }
847
- })
848
- }
849
-
850
- if (recoverable === false) {
851
- throw new PluginFatalError('MY_CUSTOM_FATAL', 'A critical error occurred', {
852
- response: new Response('Something happened', { status: 500 }) // Required: supply your own error response
853
- })
854
- }
855
-
856
- // Otherwise, continue processing...
857
- // }
858
- ```
859
-
860
819
  ### How the Plugin Pipeline Works
861
820
 
862
821
  - **Shared Context:**
@@ -874,8 +833,7 @@ if (recoverable === false) {
874
833
  This means you do not have to specify a rigid order, each plugin simply checks the context and acts if appropriate.
875
834
 
876
835
  - **Error Handling:**
877
- - A thrown `PluginError` is considered non‑fatal and is logged, allowing the pipeline to continue.
878
- - A thrown `PluginFatalError` immediately stops the pipeline and returns the error response.
836
+ - Any thrown error immediately stops the pipeline and returns the error response.
879
837
 
880
838
  For a detailed explanation of the pipeline, please refer to the discussion in [Issue #167](https://github.com/ipfs/helia-verified-fetch/issues/167).
881
839