@authhero/cloudflare-adapter 2.26.7 → 2.27.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 +34 -7
- package/dist/cloudflare-adapter.cjs +119 -19
- package/dist/cloudflare-adapter.d.ts +77 -8
- package/dist/cloudflare-adapter.mjs +1211 -1041
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -905,27 +905,54 @@ import type {
|
|
|
905
905
|
} from "@authhero/cloudflare-adapter";
|
|
906
906
|
```
|
|
907
907
|
|
|
908
|
-
## Code
|
|
908
|
+
## Code Executors
|
|
909
909
|
|
|
910
|
-
For user-authored code hooks (Actions),
|
|
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 {
|
|
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
|
|
924
|
+
const codeExecutor = new WorkerLoaderCodeExecutor({
|
|
920
925
|
loader: env.LOADER,
|
|
921
926
|
});
|
|
922
927
|
|
|
923
|
-
const { app } = init({
|
|
924
|
-
|
|
925
|
-
|
|
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
|