@helia/verified-fetch 4.0.0 → 4.0.1
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 +7 -49
- package/dist/index.min.js +52 -47
- package/dist/index.min.js.map +4 -4
- package/dist/src/index.d.ts +8 -50
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +8 -50
- package/dist/src/index.js.map +1 -1
- package/dist/src/plugins/index.d.ts +0 -1
- package/dist/src/plugins/index.d.ts.map +1 -1
- package/dist/src/plugins/index.js +0 -1
- package/dist/src/plugins/index.js.map +1 -1
- package/dist/src/plugins/plugin-base.d.ts.map +1 -1
- package/dist/src/plugins/plugin-base.js +3 -2
- package/dist/src/plugins/plugin-base.js.map +1 -1
- package/dist/src/plugins/plugin-handle-car.d.ts.map +1 -1
- package/dist/src/plugins/plugin-handle-car.js +0 -1
- package/dist/src/plugins/plugin-handle-car.js.map +1 -1
- package/dist/src/plugins/plugin-handle-dag-cbor-html-preview.d.ts.map +1 -1
- package/dist/src/plugins/plugin-handle-dag-cbor-html-preview.js +0 -1
- package/dist/src/plugins/plugin-handle-dag-cbor-html-preview.js.map +1 -1
- package/dist/src/plugins/plugin-handle-dag-cbor.d.ts.map +1 -1
- package/dist/src/plugins/plugin-handle-dag-cbor.js +0 -1
- package/dist/src/plugins/plugin-handle-dag-cbor.js.map +1 -1
- package/dist/src/plugins/plugin-handle-dag-pb.d.ts.map +1 -1
- package/dist/src/plugins/plugin-handle-dag-pb.js +13 -16
- package/dist/src/plugins/plugin-handle-dag-pb.js.map +1 -1
- package/dist/src/plugins/plugin-handle-dag-walk.d.ts +8 -4
- package/dist/src/plugins/plugin-handle-dag-walk.d.ts.map +1 -1
- package/dist/src/plugins/plugin-handle-dag-walk.js +8 -5
- package/dist/src/plugins/plugin-handle-dag-walk.js.map +1 -1
- package/dist/src/plugins/plugin-handle-ipns-record.d.ts +1 -1
- package/dist/src/plugins/plugin-handle-ipns-record.d.ts.map +1 -1
- package/dist/src/plugins/plugin-handle-ipns-record.js +3 -5
- package/dist/src/plugins/plugin-handle-ipns-record.js.map +1 -1
- package/dist/src/plugins/plugin-handle-json.d.ts.map +1 -1
- package/dist/src/plugins/plugin-handle-json.js +0 -1
- package/dist/src/plugins/plugin-handle-json.js.map +1 -1
- package/dist/src/plugins/plugin-handle-raw.d.ts.map +1 -1
- package/dist/src/plugins/plugin-handle-raw.js +3 -7
- package/dist/src/plugins/plugin-handle-raw.js.map +1 -1
- package/dist/src/plugins/plugin-handle-tar.d.ts.map +1 -1
- package/dist/src/plugins/plugin-handle-tar.js +0 -1
- package/dist/src/plugins/plugin-handle-tar.js.map +1 -1
- package/dist/src/plugins/types.d.ts +5 -7
- package/dist/src/plugins/types.d.ts.map +1 -1
- package/dist/src/utils/byte-range-context.d.ts +2 -2
- package/dist/src/utils/byte-range-context.d.ts.map +1 -1
- package/dist/src/utils/byte-range-context.js +1 -1
- package/dist/src/utils/byte-range-context.js.map +1 -1
- package/dist/src/utils/content-type-parser.d.ts.map +1 -1
- package/dist/src/utils/content-type-parser.js +0 -10
- package/dist/src/utils/content-type-parser.js.map +1 -1
- package/dist/src/utils/error-to-object.d.ts +6 -0
- package/dist/src/utils/error-to-object.d.ts.map +1 -0
- package/dist/src/utils/error-to-object.js +20 -0
- package/dist/src/utils/error-to-object.js.map +1 -0
- package/dist/src/utils/get-stream-from-async-iterable.d.ts +2 -2
- package/dist/src/utils/get-stream-from-async-iterable.d.ts.map +1 -1
- package/dist/src/utils/get-stream-from-async-iterable.js +2 -2
- package/dist/src/utils/get-stream-from-async-iterable.js.map +1 -1
- package/dist/src/utils/responses.d.ts +2 -1
- package/dist/src/utils/responses.d.ts.map +1 -1
- package/dist/src/utils/responses.js +12 -1
- package/dist/src/utils/responses.js.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.map +1 -1
- package/dist/src/verified-fetch.js +36 -28
- package/dist/src/verified-fetch.js.map +1 -1
- package/dist/typedoc-urls.json +0 -2
- package/package.json +2 -2
- package/src/index.ts +8 -50
- package/src/plugins/index.ts +0 -1
- package/src/plugins/plugin-base.ts +3 -2
- package/src/plugins/plugin-handle-car.ts +0 -2
- package/src/plugins/plugin-handle-dag-cbor-html-preview.ts +2 -1
- package/src/plugins/plugin-handle-dag-cbor.ts +3 -1
- package/src/plugins/plugin-handle-dag-pb.ts +23 -15
- package/src/plugins/plugin-handle-dag-walk.ts +10 -5
- package/src/plugins/plugin-handle-ipns-record.ts +5 -5
- package/src/plugins/plugin-handle-json.ts +1 -1
- package/src/plugins/plugin-handle-raw.ts +6 -7
- package/src/plugins/plugin-handle-tar.ts +2 -1
- package/src/plugins/types.ts +6 -8
- package/src/utils/byte-range-context.ts +3 -3
- package/src/utils/content-type-parser.ts +5 -11
- package/src/utils/error-to-object.ts +22 -0
- package/src/utils/get-stream-from-async-iterable.ts +4 -4
- package/src/utils/responses.ts +15 -1
- package/src/utils/walk-path.ts +1 -1
- package/src/verified-fetch.ts +46 -28
- package/dist/src/plugins/errors.d.ts +0 -25
- package/dist/src/plugins/errors.d.ts.map +0 -1
- package/dist/src/plugins/errors.js +0 -33
- package/dist/src/plugins/errors.js.map +0 -1
- 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 |
|
|
676
|
-
Performs the plugin’s work. It
|
|
677
|
-
|
|
678
|
-
- **Return `
|
|
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
|
|
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
|
-
-
|
|
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
|
|