@helia/verified-fetch 3.1.0 → 3.2.0

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 (40) hide show
  1. package/README.md +27 -0
  2. package/dist/index.min.js +209 -71
  3. package/dist/index.min.js.map +4 -4
  4. package/dist/src/index.d.ts +27 -0
  5. package/dist/src/index.d.ts.map +1 -1
  6. package/dist/src/index.js +27 -0
  7. package/dist/src/index.js.map +1 -1
  8. package/dist/src/plugins/plugin-handle-car.d.ts.map +1 -1
  9. package/dist/src/plugins/plugin-handle-car.js +5 -2
  10. package/dist/src/plugins/plugin-handle-car.js.map +1 -1
  11. package/dist/src/plugins/plugin-handle-dag-cbor-html-preview.d.ts +27 -0
  12. package/dist/src/plugins/plugin-handle-dag-cbor-html-preview.d.ts.map +1 -0
  13. package/dist/src/plugins/plugin-handle-dag-cbor-html-preview.js +280 -0
  14. package/dist/src/plugins/plugin-handle-dag-cbor-html-preview.js.map +1 -0
  15. package/dist/src/plugins/plugin-handle-dag-cbor.d.ts +7 -2
  16. package/dist/src/plugins/plugin-handle-dag-cbor.d.ts.map +1 -1
  17. package/dist/src/plugins/plugin-handle-dag-cbor.js +6 -4
  18. package/dist/src/plugins/plugin-handle-dag-cbor.js.map +1 -1
  19. package/dist/src/plugins/plugins.d.ts +1 -0
  20. package/dist/src/plugins/plugins.d.ts.map +1 -1
  21. package/dist/src/plugins/plugins.js +1 -0
  22. package/dist/src/plugins/plugins.js.map +1 -1
  23. package/dist/src/plugins/types.d.ts +4 -0
  24. package/dist/src/plugins/types.d.ts.map +1 -1
  25. package/dist/src/utils/select-output-type.d.ts.map +1 -1
  26. package/dist/src/utils/select-output-type.js +2 -1
  27. package/dist/src/utils/select-output-type.js.map +1 -1
  28. package/dist/src/verified-fetch.d.ts.map +1 -1
  29. package/dist/src/verified-fetch.js +2 -1
  30. package/dist/src/verified-fetch.js.map +1 -1
  31. package/dist/typedoc-urls.json +2 -0
  32. package/package.json +1 -1
  33. package/src/index.ts +27 -0
  34. package/src/plugins/plugin-handle-car.ts +5 -2
  35. package/src/plugins/plugin-handle-dag-cbor-html-preview.ts +294 -0
  36. package/src/plugins/plugin-handle-dag-cbor.ts +8 -6
  37. package/src/plugins/plugins.ts +1 -0
  38. package/src/plugins/types.ts +5 -0
  39. package/src/utils/select-output-type.ts +2 -1
  40. 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: