@authhero/cloudflare-adapter 2.26.7 → 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 +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 +1 -1
|
@@ -1040,7 +1040,7 @@ export interface DispatchNamespace {
|
|
|
1040
1040
|
fetch(request: Request | string, init?: RequestInit): Promise<Response>;
|
|
1041
1041
|
};
|
|
1042
1042
|
}
|
|
1043
|
-
export interface
|
|
1043
|
+
export interface DispatchNamespaceCodeExecutorConfig {
|
|
1044
1044
|
/** Cloudflare account ID */
|
|
1045
1045
|
accountId: string;
|
|
1046
1046
|
/** API token with Workers Scripts write permission */
|
|
@@ -1066,15 +1066,20 @@ export interface CloudflareCodeExecutorConfig {
|
|
|
1066
1066
|
compatibilityDate?: string;
|
|
1067
1067
|
}
|
|
1068
1068
|
/**
|
|
1069
|
-
* Code executor that uses Cloudflare Workers for Platforms.
|
|
1069
|
+
* Code executor that uses Cloudflare Workers for Platforms dispatch namespaces.
|
|
1070
1070
|
*
|
|
1071
|
-
* User code is deployed as individual worker scripts in a dispatch namespace
|
|
1072
|
-
*
|
|
1073
|
-
*
|
|
1071
|
+
* User code is deployed as individual worker scripts in a dispatch namespace
|
|
1072
|
+
* (via the `deploy()` method, which calls the Cloudflare API). At execution
|
|
1073
|
+
* time, the pre-deployed worker is invoked via the dispatch namespace binding
|
|
1074
|
+
* (in-worker) or via HTTP (external fallback).
|
|
1075
|
+
*
|
|
1076
|
+
* Contrast with `WorkerLoaderCodeExecutor`, which creates isolates on the fly
|
|
1077
|
+
* from in-memory code via the Worker Loader binding and does not require
|
|
1078
|
+
* pre-deployment.
|
|
1074
1079
|
*
|
|
1075
1080
|
* Usage:
|
|
1076
1081
|
* ```typescript
|
|
1077
|
-
* const codeExecutor = new
|
|
1082
|
+
* const codeExecutor = new DispatchNamespaceCodeExecutor({
|
|
1078
1083
|
* accountId: env.CF_ACCOUNT_ID,
|
|
1079
1084
|
* apiToken: env.CF_API_TOKEN,
|
|
1080
1085
|
* dispatchNamespace: "authhero-hooks",
|
|
@@ -1084,9 +1089,9 @@ export interface CloudflareCodeExecutorConfig {
|
|
|
1084
1089
|
* const { app } = init({ dataAdapter, codeExecutor });
|
|
1085
1090
|
* ```
|
|
1086
1091
|
*/
|
|
1087
|
-
export declare class
|
|
1092
|
+
export declare class DispatchNamespaceCodeExecutor implements CodeExecutor {
|
|
1088
1093
|
private config;
|
|
1089
|
-
constructor(config:
|
|
1094
|
+
constructor(config: DispatchNamespaceCodeExecutorConfig);
|
|
1090
1095
|
execute(params: {
|
|
1091
1096
|
code: string;
|
|
1092
1097
|
hookCodeId?: string;
|
|
@@ -1111,6 +1116,15 @@ export declare class CloudflareCodeExecutor implements CodeExecutor {
|
|
|
1111
1116
|
*/
|
|
1112
1117
|
remove(hookCodeId: string): Promise<void>;
|
|
1113
1118
|
}
|
|
1119
|
+
/**
|
|
1120
|
+
* @deprecated Renamed to `DispatchNamespaceCodeExecutor` to disambiguate from
|
|
1121
|
+
* `WorkerLoaderCodeExecutor` (also Cloudflare-based, but using the Worker
|
|
1122
|
+
* Loader binding instead of Workers for Platforms). This alias will be removed
|
|
1123
|
+
* in the next major.
|
|
1124
|
+
*/
|
|
1125
|
+
export declare const CloudflareCodeExecutor: typeof DispatchNamespaceCodeExecutor;
|
|
1126
|
+
/** @deprecated Use `DispatchNamespaceCodeExecutorConfig`. */
|
|
1127
|
+
export type CloudflareCodeExecutorConfig = DispatchNamespaceCodeExecutorConfig;
|
|
1114
1128
|
/**
|
|
1115
1129
|
* Generates a Cloudflare Worker script that wraps user-authored code.
|
|
1116
1130
|
*
|
|
@@ -1121,6 +1135,61 @@ export declare class CloudflareCodeExecutor implements CodeExecutor {
|
|
|
1121
1135
|
* 4. Returns { success, apiCalls, error, durationMs } as JSON
|
|
1122
1136
|
*/
|
|
1123
1137
|
export declare function generateWorkerScript(userCode: string): string;
|
|
1138
|
+
/**
|
|
1139
|
+
* Worker Loader binding type (Cloudflare Dynamic Workers).
|
|
1140
|
+
* Configure in wrangler.toml:
|
|
1141
|
+
* [[worker_loaders]]
|
|
1142
|
+
* binding = "LOADER"
|
|
1143
|
+
*/
|
|
1144
|
+
export interface WorkerLoader {
|
|
1145
|
+
load(code: WorkerCode): WorkerStub;
|
|
1146
|
+
get(id: string, callback: () => Promise<WorkerCode>): WorkerStub;
|
|
1147
|
+
}
|
|
1148
|
+
export interface WorkerCode {
|
|
1149
|
+
compatibilityDate: string;
|
|
1150
|
+
mainModule: string;
|
|
1151
|
+
modules: Record<string, string>;
|
|
1152
|
+
}
|
|
1153
|
+
export interface WorkerStub {
|
|
1154
|
+
getEntrypoint(): {
|
|
1155
|
+
fetch(request: Request): Promise<Response>;
|
|
1156
|
+
};
|
|
1157
|
+
}
|
|
1158
|
+
export interface WorkerLoaderCodeExecutorOptions {
|
|
1159
|
+
loader: WorkerLoader;
|
|
1160
|
+
compatibilityDate?: string;
|
|
1161
|
+
}
|
|
1162
|
+
/**
|
|
1163
|
+
* Cloudflare Dynamic Workers code executor (Worker Loader binding).
|
|
1164
|
+
* Spins up isolated Workers on demand from in-memory code to execute
|
|
1165
|
+
* user-authored hook code in a sandboxed v8 isolate.
|
|
1166
|
+
*
|
|
1167
|
+
* Uses `env.LOADER.get(id, callback)` to cache workers by hookCodeId + code hash,
|
|
1168
|
+
* so the same code stays warm across requests while code updates get a fresh worker.
|
|
1169
|
+
*
|
|
1170
|
+
* User code can make outbound `fetch()` calls. The Worker Loader still provides
|
|
1171
|
+
* process isolation (separate v8 isolate, no access to the parent worker's
|
|
1172
|
+
* bindings or env), so this only widens the network boundary, not the host
|
|
1173
|
+
* boundary. Plan: a future AI/static-analysis layer inspects action code on
|
|
1174
|
+
* upload to flag exfiltration patterns before they reach the executor.
|
|
1175
|
+
*
|
|
1176
|
+
* Contrast with `DispatchNamespaceCodeExecutor`, which uses Workers for
|
|
1177
|
+
* Platforms dispatch namespaces and requires user code to be pre-deployed
|
|
1178
|
+
* as individual worker scripts via the Cloudflare API.
|
|
1179
|
+
*/
|
|
1180
|
+
export declare class WorkerLoaderCodeExecutor implements CodeExecutor {
|
|
1181
|
+
private loader;
|
|
1182
|
+
private compatibilityDate;
|
|
1183
|
+
constructor(options: WorkerLoaderCodeExecutorOptions);
|
|
1184
|
+
execute(params: {
|
|
1185
|
+
code: string;
|
|
1186
|
+
hookCodeId?: string;
|
|
1187
|
+
triggerId: string;
|
|
1188
|
+
event: Record<string, unknown>;
|
|
1189
|
+
timeoutMs?: number;
|
|
1190
|
+
cpuLimitMs?: number;
|
|
1191
|
+
}): Promise<CodeExecutionResult>;
|
|
1192
|
+
}
|
|
1124
1193
|
export interface CloudflareAdapters {
|
|
1125
1194
|
customDomains: CustomDomainsAdapter;
|
|
1126
1195
|
cache: CacheAdapter;
|