@authhero/cloudflare-adapter 2.26.6 → 2.27.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.
package/README.md CHANGED
@@ -905,27 +905,54 @@ import type {
905
905
  } from "@authhero/cloudflare-adapter";
906
906
  ```
907
907
 
908
- ## Code Executor (Dynamic Workers)
908
+ ## Code Executors
909
909
 
910
- For user-authored code hooks (Actions), AuthHero provides a `CloudflareCodeExecutor` in the core `authhero` package that uses [Cloudflare Dynamic Workers](https://developers.cloudflare.com/dynamic-workers/) for isolated code execution. This is separate from the cloudflare-adapter but typically used alongside it.
910
+ For user-authored code hooks (Actions), `@authhero/cloudflare-adapter` ships two code executors. Pick one based on how you want user code deployed:
911
+
912
+ ### `WorkerLoaderCodeExecutor` — Dynamic Workers
913
+
914
+ Spins up isolated workers on demand from in-memory code via the [Worker Loader binding](https://developers.cloudflare.com/dynamic-workers/). No separate deploy step — the code stored in your `actions`/`hookCode` table is loaded into a fresh isolate per hook invocation (with a hash-based cache so the same code stays warm).
911
915
 
912
916
  ```typescript
913
- import { CloudflareCodeExecutor, init } from "authhero";
917
+ import { WorkerLoaderCodeExecutor } from "@authhero/cloudflare-adapter";
918
+ import { init } from "authhero";
914
919
 
915
920
  // Requires a worker_loaders binding in wrangler.toml:
916
921
  // [[worker_loaders]]
917
922
  // binding = "LOADER"
918
923
 
919
- const codeExecutor = new CloudflareCodeExecutor({
924
+ const codeExecutor = new WorkerLoaderCodeExecutor({
920
925
  loader: env.LOADER,
921
926
  });
922
927
 
923
- const { app } = init({
924
- dataAdapter,
925
- codeExecutor,
928
+ const { app } = init({ dataAdapter, codeExecutor });
929
+ ```
930
+
931
+ ### `DispatchNamespaceCodeExecutor` — Workers for Platforms
932
+
933
+ Invokes user workers that have been pre-deployed as separate scripts in a [dispatch namespace](https://developers.cloudflare.com/cloudflare-for-platforms/workers-for-platforms/). The executor's `deploy()` method uploads a script via the Cloudflare API; `execute()` invokes it via the namespace binding.
934
+
935
+ ```typescript
936
+ import { DispatchNamespaceCodeExecutor } from "@authhero/cloudflare-adapter";
937
+ import { init } from "authhero";
938
+
939
+ // Requires a dispatch_namespaces binding in wrangler.toml:
940
+ // [[dispatch_namespaces]]
941
+ // binding = "DISPATCHER"
942
+ // namespace = "authhero-hooks"
943
+
944
+ const codeExecutor = new DispatchNamespaceCodeExecutor({
945
+ accountId: env.CF_ACCOUNT_ID,
946
+ apiToken: env.CF_API_TOKEN,
947
+ dispatchNamespace: "authhero-hooks",
948
+ dispatcher: env.DISPATCHER,
926
949
  });
950
+
951
+ const { app } = init({ dataAdapter, codeExecutor });
927
952
  ```
928
953
 
954
+ > Previously exported as `CloudflareCodeExecutor` from the `authhero` and `@authhero/cloudflare-adapter` packages. That name is still re-exported as a deprecated alias of `DispatchNamespaceCodeExecutor` and will be removed in the next major.
955
+
929
956
  See the [Hooks Guide](https://www.authhero.net/features/hooks#code-executors) for details.
930
957
 
931
958
  ## Related Documentation