@helia/verified-fetch 3.1.1 → 3.2.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 +27 -0
- package/dist/index.min.js +196 -58
- package/dist/index.min.js.map +4 -4
- package/dist/src/index.d.ts +27 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +27 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/plugins/plugin-handle-dag-cbor-html-preview.d.ts +27 -0
- package/dist/src/plugins/plugin-handle-dag-cbor-html-preview.d.ts.map +1 -0
- package/dist/src/plugins/plugin-handle-dag-cbor-html-preview.js +280 -0
- package/dist/src/plugins/plugin-handle-dag-cbor-html-preview.js.map +1 -0
- package/dist/src/plugins/plugin-handle-dag-cbor.d.ts +7 -2
- package/dist/src/plugins/plugin-handle-dag-cbor.d.ts.map +1 -1
- package/dist/src/plugins/plugin-handle-dag-cbor.js +6 -4
- package/dist/src/plugins/plugin-handle-dag-cbor.js.map +1 -1
- package/dist/src/plugins/plugins.d.ts +1 -0
- package/dist/src/plugins/plugins.d.ts.map +1 -1
- package/dist/src/plugins/plugins.js +1 -0
- package/dist/src/plugins/plugins.js.map +1 -1
- package/dist/src/plugins/types.d.ts +4 -0
- package/dist/src/plugins/types.d.ts.map +1 -1
- package/dist/src/utils/select-output-type.d.ts.map +1 -1
- package/dist/src/utils/select-output-type.js +2 -1
- package/dist/src/utils/select-output-type.js.map +1 -1
- package/dist/src/verified-fetch.d.ts.map +1 -1
- package/dist/src/verified-fetch.js +2 -1
- package/dist/src/verified-fetch.js.map +1 -1
- package/dist/typedoc-urls.json +2 -0
- package/package.json +2 -2
- package/src/index.ts +27 -0
- package/src/plugins/plugin-handle-dag-cbor-html-preview.ts +294 -0
- package/src/plugins/plugin-handle-dag-cbor.ts +8 -6
- package/src/plugins/plugins.ts +1 -0
- package/src/plugins/types.ts +5 -0
- package/src/utils/select-output-type.ts +2 -1
- package/src/verified-fetch.ts +2 -1
package/README.md
CHANGED
|
@@ -664,6 +664,8 @@ Verified‑fetch can now be extended to alter how it handles requests by using p
|
|
|
664
664
|
Plugins are classes that extend the `BasePlugin` class and implement the `VerifiedFetchPlugin`
|
|
665
665
|
interface. They are instantiated with `PluginOptions` when the `VerifiedFetch` class is created.
|
|
666
666
|
|
|
667
|
+
### Plugin Interface
|
|
668
|
+
|
|
667
669
|
Each plugin must implement two methods:
|
|
668
670
|
|
|
669
671
|
- **`canHandle(context: PluginContext): boolean`**
|
|
@@ -678,6 +680,8 @@ Each plugin must implement two methods:
|
|
|
678
680
|
- **Throw a `PluginError`**: This logs a non-fatal error and continues the pipeline.
|
|
679
681
|
- **Throw a `PluginFatalError`**: This logs a fatal error and stops the pipeline immediately.
|
|
680
682
|
|
|
683
|
+
### Plugin Pipeline
|
|
684
|
+
|
|
681
685
|
Plugins are executed in a chain (a **plugin pipeline**):
|
|
682
686
|
|
|
683
687
|
1. **Initialization:**
|
|
@@ -724,6 +728,29 @@ Please see the original discussion on extensibility in [Issue #167](https://gith
|
|
|
724
728
|
|
|
725
729
|
***
|
|
726
730
|
|
|
731
|
+
### Non-default plugins provided by this library
|
|
732
|
+
|
|
733
|
+
#### `dir-index-html-plugin`
|
|
734
|
+
|
|
735
|
+
This plugin is used to serve dag-pb/unixfs without an `index.html` child as HTML directory listing of the content requested.
|
|
736
|
+
|
|
737
|
+
#### `dag-cbor-html-preview-plugin`
|
|
738
|
+
|
|
739
|
+
This plugin is used to serve the requested dag-cbor object as HTML when the Accept header includes `text/html`.
|
|
740
|
+
|
|
741
|
+
## Example - Using the plugins
|
|
742
|
+
|
|
743
|
+
```typescript
|
|
744
|
+
import { createVerifiedFetch } from '@helia/verified-fetch'
|
|
745
|
+
import { dagCborHtmlPreviewPluginFactory, dirIndexHtmlPluginFactory } from '@helia/verified-fetch/plugins'
|
|
746
|
+
import { createHelia } from 'helia'
|
|
747
|
+
|
|
748
|
+
const helia = await createHelia()
|
|
749
|
+
const fetch = await createVerifiedFetch(helia, {
|
|
750
|
+
plugins: [dagCborHtmlPreviewPluginFactory, dirIndexHtmlPluginFactory, ]
|
|
751
|
+
})
|
|
752
|
+
```
|
|
753
|
+
|
|
727
754
|
### Extending Verified‑Fetch with Custom Plugins
|
|
728
755
|
|
|
729
756
|
To add your own plugin:
|