@guren/plugin-cloudflare 0.6.0 → 0.7.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 +6 -4
- package/dist/build-DLJgpyN5.js +950 -0
- package/dist/commands.js +1 -1
- package/dist/env.d.ts +25 -16
- package/dist/env.js +27 -16
- package/dist/index.d.ts +51 -56
- package/dist/index.js +63 -44
- package/package.json +2 -2
- package/templates/mcp-oauth/app/Http/Controllers/McpOAuthController.ts +37 -103
- package/templates/mcp-oauth/app/View/McpOAuthConsentPage.tsx +15 -40
- package/templates/mcp-oauth/app/View/McpOAuthErrorPage.tsx +7 -19
- package/templates/mcp-oauth/routes/mcp-oauth.ts +6 -21
- package/dist/build-B2fIb1lu.js +0 -867
package/dist/commands.js
CHANGED
package/dist/env.d.ts
CHANGED
|
@@ -2,25 +2,34 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* The Workers env holder, published as `@guren/plugin-cloudflare/env`.
|
|
4
4
|
*
|
|
5
|
-
* **This module must stay import-free.** It is
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* root
|
|
9
|
-
*
|
|
10
|
-
* `
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
5
|
+
* **This module must stay import-free.** It is what application code reaches for
|
|
6
|
+
* at runtime, while the package root also re-exports `buildCloudflareOutput` and
|
|
7
|
+
* pulls `node:fs`, `node:path` and the deploy generator behind it — importing
|
|
8
|
+
* these names from the root drags that into the route graph and the wrangler
|
|
9
|
+
* bundle. The root keeps re-exporting them for compatibility;
|
|
10
|
+
* `tests/lean-env-subpath.test.ts` holds the boundary.
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* First call wins; later calls are ignored (never overwrite a live env). Not the
|
|
14
|
+
* hard error RFC 0017 §6 asks for: under the Workers Vitest integration a Worker
|
|
15
|
+
* entrypoint and a Durable Object of one deployment receive *different* `env`
|
|
16
|
+
* objects, so identity cannot mean "another environment". The per-app boot
|
|
17
|
+
* latch in `boot.ts` is what keeps one isolate on one application.
|
|
18
18
|
*/
|
|
19
|
-
/** First call wins; later calls are ignored (never overwrite a live env). */
|
|
20
19
|
declare function captureWorkersEnv(env: unknown): void;
|
|
21
|
-
/**
|
|
20
|
+
/**
|
|
21
|
+
* Throws with a clear message if called before the first request captured env.
|
|
22
|
+
* Inside a Durable Object prefer `this.env`: the holder keeps whichever
|
|
23
|
+
* entrypoint booted first, which may be the Worker's rather than the object's.
|
|
24
|
+
*/
|
|
22
25
|
declare function getWorkersEnv<E = unknown>(): E;
|
|
23
26
|
/** Clears the holder. Used by createWorkersHandler on boot failure and by tests. */
|
|
24
27
|
declare function resetWorkersEnv(): void;
|
|
28
|
+
/**
|
|
29
|
+
* Whether this code is running on workerd, which identifies itself through the
|
|
30
|
+
* standard navigator user agent. The switch an app's `config/database.ts` needs
|
|
31
|
+
* to pick D1 over a local driver, and to keep filesystem work out of the Worker.
|
|
32
|
+
*/
|
|
33
|
+
declare function isWorkersRuntime(): boolean;
|
|
25
34
|
//#endregion
|
|
26
|
-
export { captureWorkersEnv, getWorkersEnv, resetWorkersEnv };
|
|
35
|
+
export { captureWorkersEnv, getWorkersEnv, isWorkersRuntime, resetWorkersEnv };
|
package/dist/env.js
CHANGED
|
@@ -2,26 +2,29 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* The Workers env holder, published as `@guren/plugin-cloudflare/env`.
|
|
4
4
|
*
|
|
5
|
-
* **This module must stay import-free.** It is
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* root
|
|
9
|
-
*
|
|
10
|
-
* `
|
|
11
|
-
* route graph on every `bun run dev` boot and into the wrangler bundle on
|
|
12
|
-
* every deploy, for three functions that need nothing at all.
|
|
13
|
-
*
|
|
14
|
-
* The root keeps re-exporting these names, so nothing that already imports
|
|
15
|
-
* them from there breaks. New application code should import from this
|
|
16
|
-
* subpath; `tests/lean-env-subpath.test.ts` holds that boundary, and the
|
|
17
|
-
* scaffolded consent controller is checked against it by name.
|
|
5
|
+
* **This module must stay import-free.** It is what application code reaches for
|
|
6
|
+
* at runtime, while the package root also re-exports `buildCloudflareOutput` and
|
|
7
|
+
* pulls `node:fs`, `node:path` and the deploy generator behind it — importing
|
|
8
|
+
* these names from the root drags that into the route graph and the wrangler
|
|
9
|
+
* bundle. The root keeps re-exporting them for compatibility;
|
|
10
|
+
* `tests/lean-env-subpath.test.ts` holds the boundary.
|
|
18
11
|
*/
|
|
19
12
|
let holder;
|
|
20
|
-
/**
|
|
13
|
+
/**
|
|
14
|
+
* First call wins; later calls are ignored (never overwrite a live env). Not the
|
|
15
|
+
* hard error RFC 0017 §6 asks for: under the Workers Vitest integration a Worker
|
|
16
|
+
* entrypoint and a Durable Object of one deployment receive *different* `env`
|
|
17
|
+
* objects, so identity cannot mean "another environment". The per-app boot
|
|
18
|
+
* latch in `boot.ts` is what keeps one isolate on one application.
|
|
19
|
+
*/
|
|
21
20
|
function captureWorkersEnv(env) {
|
|
22
21
|
holder ??= { env };
|
|
23
22
|
}
|
|
24
|
-
/**
|
|
23
|
+
/**
|
|
24
|
+
* Throws with a clear message if called before the first request captured env.
|
|
25
|
+
* Inside a Durable Object prefer `this.env`: the holder keeps whichever
|
|
26
|
+
* entrypoint booted first, which may be the Worker's rather than the object's.
|
|
27
|
+
*/
|
|
25
28
|
function getWorkersEnv() {
|
|
26
29
|
if (!holder) throw new Error("getWorkersEnv() was called before the first request captured the Workers env. Defer access behind a closure instead of reading it at module scope, e.g. binding: () => getWorkersEnv<Env>().DB");
|
|
27
30
|
return holder.env;
|
|
@@ -30,5 +33,13 @@ function getWorkersEnv() {
|
|
|
30
33
|
function resetWorkersEnv() {
|
|
31
34
|
holder = void 0;
|
|
32
35
|
}
|
|
36
|
+
/**
|
|
37
|
+
* Whether this code is running on workerd, which identifies itself through the
|
|
38
|
+
* standard navigator user agent. The switch an app's `config/database.ts` needs
|
|
39
|
+
* to pick D1 over a local driver, and to keep filesystem work out of the Worker.
|
|
40
|
+
*/
|
|
41
|
+
function isWorkersRuntime() {
|
|
42
|
+
return typeof navigator !== "undefined" && navigator.userAgent === "Cloudflare-Workers";
|
|
43
|
+
}
|
|
33
44
|
//#endregion
|
|
34
|
-
export { captureWorkersEnv, getWorkersEnv, resetWorkersEnv };
|
|
45
|
+
export { captureWorkersEnv, getWorkersEnv, isWorkersRuntime, resetWorkersEnv };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,23 +1,45 @@
|
|
|
1
|
-
import { captureWorkersEnv, getWorkersEnv, resetWorkersEnv } from "./env.js";
|
|
1
|
+
import { captureWorkersEnv, getWorkersEnv, isWorkersRuntime, resetWorkersEnv } from "./env.js";
|
|
2
2
|
import { FileMetadata, GetStreamOptions, PutOptions, ServiceProviderConstructor, StorageDriver, StorageDriverCapabilities, TemporaryUrlOptions } from "@guren/core";
|
|
3
3
|
import { PathLike } from "@guren/core/internal/deploy-build";
|
|
4
|
-
//#region src/
|
|
4
|
+
//#region src/boot.d.ts
|
|
5
5
|
interface WorkersExecutionContext {
|
|
6
6
|
waitUntil(promise: Promise<unknown>): void;
|
|
7
7
|
passThroughOnException?(): void;
|
|
8
8
|
}
|
|
9
9
|
/**
|
|
10
|
-
* The shape
|
|
11
|
-
* `Application` itself, so `boot()` is not assumed to be idempotent
|
|
12
|
-
* handler dedupes boot across its own requests for anything conforming here.
|
|
10
|
+
* The shape the Workers entrypoints need from an app. Structural rather than
|
|
11
|
+
* `Application` itself, so `boot()` is not assumed to be idempotent.
|
|
13
12
|
*/
|
|
14
13
|
interface WorkersAppLike {
|
|
15
14
|
boot(): Promise<void>;
|
|
16
15
|
fetch(request: Request, env?: unknown, executionCtx?: unknown): Response | Promise<Response>;
|
|
17
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* Boot `app` against `env`, once per isolate.
|
|
19
|
+
*
|
|
20
|
+
* Boot is deferred to the first request or wake because it performs I/O (ORM
|
|
21
|
+
* setup against D1), which workerd forbids in global scope (RFC 0003).
|
|
22
|
+
* @throws Whatever `boot()` threw, and `captureWorkersEnv`'s refusal of a second env.
|
|
23
|
+
*/
|
|
24
|
+
declare function bootWorkersApp(app: WorkersAppLike, env: unknown): Promise<void>;
|
|
25
|
+
/** Boot, then dispatch — the topology every Workers entrypoint shares. */
|
|
26
|
+
declare function bootAndFetch(app: WorkersAppLike, request: Request, env: unknown, ctx?: WorkersExecutionContext): Promise<Response>;
|
|
27
|
+
//#endregion
|
|
28
|
+
//#region src/handler.d.ts
|
|
18
29
|
interface WorkersHandler {
|
|
19
30
|
fetch(request: Request, env: unknown, ctx: WorkersExecutionContext): Promise<Response>;
|
|
31
|
+
/**
|
|
32
|
+
* Boot without dispatching, for an entrypoint that holds `env` but no request
|
|
33
|
+
* — an agent Durable Object woken by an alarm (RFC 0017 §6).
|
|
34
|
+
*/
|
|
35
|
+
boot(env: unknown): Promise<void>;
|
|
20
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* The worker entry `guren cloudflare:build` generates.
|
|
39
|
+
*
|
|
40
|
+
* One per module: it carries the isolate's boot slot, and `boot.ts` is where
|
|
41
|
+
* that invariant is specified.
|
|
42
|
+
*/
|
|
21
43
|
declare function createWorkersHandler(app: WorkersAppLike): WorkersHandler;
|
|
22
44
|
//#endregion
|
|
23
45
|
//#region src/build.d.ts
|
|
@@ -41,25 +63,17 @@ interface BuildCloudflareOutputOptions {
|
|
|
41
63
|
/**
|
|
42
64
|
* Front the worker with `@cloudflare/workers-oauth-provider`, so the App MCP
|
|
43
65
|
* endpoint is reached by OAuth-authorized clients instead of bearer tokens
|
|
44
|
-
* (RFC 0016 §7).
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
* runs in a separate process from the application and cannot read what
|
|
48
|
-
* `mcpPlugin()` was passed. Nothing records the choice: pass it on every
|
|
49
|
-
* build that wants it. A committed config carrying the OAuth binding while
|
|
50
|
-
* a build omits the flag is warned about, which is the drift this leaves
|
|
51
|
-
* detectable.
|
|
66
|
+
* (RFC 0016 §7). A **build** option, not plugin configuration: the generator
|
|
67
|
+
* runs in another process and cannot read what `mcpPlugin()` was passed, and
|
|
68
|
+
* nothing records the choice, so pass it on every build that wants it.
|
|
52
69
|
*/
|
|
53
70
|
mcpOAuth?: boolean;
|
|
54
71
|
/**
|
|
55
72
|
* Path the App MCP endpoint is mounted at, used as the OAuth provider's
|
|
56
|
-
* protected `apiRoute`. Only read when `mcpOAuth` is on.
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
* see runtime configuration, and a provider protecting a path the endpoint
|
|
61
|
-
* does not serve leaves the endpoint outside the OAuth boundary entirely —
|
|
62
|
-
* silently, because the request still reaches the app.
|
|
73
|
+
* protected `apiRoute`. Only read when `mcpOAuth` is on. Defaults to
|
|
74
|
+
* `mcpPlugin()`'s own default; an app that passed `mcpPlugin({ path })` must
|
|
75
|
+
* repeat it here — a provider protecting a path the endpoint does not serve
|
|
76
|
+
* leaves the endpoint outside the OAuth boundary silently.
|
|
63
77
|
*/
|
|
64
78
|
mcpPath?: string;
|
|
65
79
|
}
|
|
@@ -71,19 +85,17 @@ interface BuildCloudflareOutputOptions {
|
|
|
71
85
|
*/
|
|
72
86
|
declare function buildCloudflareOutput(options?: BuildCloudflareOutputOptions): Promise<void>;
|
|
73
87
|
/**
|
|
74
|
-
* Wrangler's `migrations_dir` only discovers flat `*.sql` files, but
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
* every build — run `cloudflare:build` after adding a migration.
|
|
88
|
+
* Wrangler's `migrations_dir` only discovers flat `*.sql` files, but drizzle-kit
|
|
89
|
+
* (1.x) emits one `<timestamp>_<name>/migration.sql` folder per migration.
|
|
90
|
+
* Flatten each folder into `<folder-name>.sql` (plain `*.sql` files pass
|
|
91
|
+
* through, `meta/` is skipped) so `wrangler d1 migrations apply` sees them in
|
|
92
|
+
* filename order. Regenerated on every build — run `cloudflare:build` after adding one.
|
|
80
93
|
*/
|
|
81
94
|
declare function flattenD1Migrations(migrationsDir: string, outDir: string): void;
|
|
82
95
|
//#endregion
|
|
83
96
|
//#region src/storage/R2Driver.d.ts
|
|
84
97
|
/**
|
|
85
|
-
* Structural view of the R2 binding
|
|
86
|
-
* local `S3Client { send() }`: only what this driver calls, so
|
|
98
|
+
* Structural view of the R2 binding: only what this driver calls, so
|
|
87
99
|
* `@cloudflare/workers-types` stays a devDependency. `R2Driver.types.test.ts`
|
|
88
100
|
* pins that the real `R2Bucket` satisfies it.
|
|
89
101
|
*/
|
|
@@ -103,11 +115,10 @@ interface R2ObjectLike {
|
|
|
103
115
|
customMetadata?: Record<string, string>;
|
|
104
116
|
}
|
|
105
117
|
/**
|
|
106
|
-
* Streams and blobs are typed structurally
|
|
107
|
-
* `ReadableStream`/`Blob
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
* the `R2BucketLike` check while being perfectly usable at runtime.
|
|
118
|
+
* Streams and blobs are typed structurally: `@cloudflare/workers-types` declares
|
|
119
|
+
* its own `ReadableStream`/`Blob`, assignable in neither direction to the runtime
|
|
120
|
+
* globals, so naming the globals would fail the `R2BucketLike` check on a real
|
|
121
|
+
* `R2Bucket` that works fine at runtime.
|
|
111
122
|
*/
|
|
112
123
|
interface R2StreamLike {
|
|
113
124
|
locked: boolean;
|
|
@@ -174,21 +185,17 @@ interface R2DriverOptions {
|
|
|
174
185
|
*/
|
|
175
186
|
binding: () => unknown;
|
|
176
187
|
/**
|
|
177
|
-
* Base URL for `url()`: the bucket's custom domain (recommended) or its
|
|
178
|
-
*
|
|
179
|
-
* `https://<bucket>.s3.<region>.amazonaws.com` — so `url()` throws with
|
|
180
|
-
* guidance when this is unset.
|
|
188
|
+
* Base URL for `url()`: the bucket's custom domain (recommended) or its r2.dev
|
|
189
|
+
* subdomain. R2 has no derivable default, so `url()` throws when this is unset.
|
|
181
190
|
*/
|
|
182
191
|
publicUrl?: string;
|
|
183
192
|
/** Key prefix, same semantics as `S3DriverOptions.prefix`. */
|
|
184
193
|
prefix?: string;
|
|
185
194
|
/**
|
|
186
195
|
* The visibility every object in this bucket effectively has. R2 has no
|
|
187
|
-
* per-object ACL
|
|
196
|
+
* per-object ACL, so `put({ visibility })` and `setVisibility()` throw when
|
|
197
|
+
* asked for the other value rather than pretend to enforce it.
|
|
188
198
|
* Defaults to `'public'` when `publicUrl` is set, `'private'` otherwise.
|
|
189
|
-
* `put({ visibility })` and `setVisibility()` throw when asked for the
|
|
190
|
-
* other value — the driver refuses to pretend it can enforce a per-object
|
|
191
|
-
* flag it cannot.
|
|
192
199
|
*/
|
|
193
200
|
visibility?: 'public' | 'private';
|
|
194
201
|
/**
|
|
@@ -199,14 +206,9 @@ interface R2DriverOptions {
|
|
|
199
206
|
}
|
|
200
207
|
/**
|
|
201
208
|
* Cloudflare R2 storage driver over the Workers binding.
|
|
202
|
-
*
|
|
203
209
|
* @example
|
|
204
210
|
* ```ts
|
|
205
|
-
*
|
|
206
|
-
* storage.registerDisk('media', () => new R2Driver({
|
|
207
|
-
* binding: () => getWorkersEnv<Env>().MEDIA,
|
|
208
|
-
* publicUrl: 'https://media.example.com',
|
|
209
|
-
* }))
|
|
211
|
+
* new R2Driver({ binding: () => getWorkersEnv<Env>().MEDIA, publicUrl: 'https://media.example.com' })
|
|
210
212
|
* ```
|
|
211
213
|
*/
|
|
212
214
|
declare class R2Driver implements StorageDriver {
|
|
@@ -271,14 +273,7 @@ declare class R2Driver implements StorageDriver {
|
|
|
271
273
|
* upcoming RFC 0003 parts (session/OAuth-state store wiring on Workers).
|
|
272
274
|
*/
|
|
273
275
|
interface CloudflarePluginConfig {}
|
|
274
|
-
/**
|
|
275
|
-
* Register the Cloudflare plugin.
|
|
276
|
-
*
|
|
277
|
-
* @example
|
|
278
|
-
* ```typescript
|
|
279
|
-
* createApp({ providers: [cloudflarePlugin()] })
|
|
280
|
-
* ```
|
|
281
|
-
*/
|
|
276
|
+
/** Register the Cloudflare plugin: `createApp({ providers: [cloudflarePlugin()] })`. */
|
|
282
277
|
declare function cloudflarePlugin(config?: CloudflarePluginConfig): ServiceProviderConstructor;
|
|
283
278
|
//#endregion
|
|
284
|
-
export { type BuildCloudflareOutputOptions, CloudflarePluginConfig, type R2BucketLike, R2Driver, type R2DriverOptions, type R2PresignOptions, type WorkersAppLike, type WorkersExecutionContext, type WorkersHandler, buildCloudflareOutput, captureWorkersEnv, cloudflarePlugin, createWorkersHandler, flattenD1Migrations, getWorkersEnv, resetWorkersEnv };
|
|
279
|
+
export { type BuildCloudflareOutputOptions, CloudflarePluginConfig, type R2BucketLike, R2Driver, type R2DriverOptions, type R2PresignOptions, type WorkersAppLike, type WorkersExecutionContext, type WorkersHandler, bootAndFetch, bootWorkersApp, buildCloudflareOutput, captureWorkersEnv, cloudflarePlugin, createWorkersHandler, flattenD1Migrations, getWorkersEnv, isWorkersRuntime, resetWorkersEnv };
|
package/dist/index.js
CHANGED
|
@@ -1,24 +1,61 @@
|
|
|
1
|
-
import { captureWorkersEnv, getWorkersEnv, resetWorkersEnv } from "./env.js";
|
|
2
|
-
import { n as flattenD1Migrations, t as buildCloudflareOutput } from "./build-
|
|
1
|
+
import { captureWorkersEnv, getWorkersEnv, isWorkersRuntime, resetWorkersEnv } from "./env.js";
|
|
2
|
+
import { n as flattenD1Migrations, t as buildCloudflareOutput } from "./build-DLJgpyN5.js";
|
|
3
3
|
import { definePlugin } from "@guren/core";
|
|
4
|
+
//#region src/boot.ts
|
|
5
|
+
/**
|
|
6
|
+
* The isolate's one boot slot (RFC 0017 §6).
|
|
7
|
+
*
|
|
8
|
+
* A worker's `fetch` export is not the only entrypoint: an alarm can wake an
|
|
9
|
+
* agent Durable Object before any request has arrived, and a second entrypoint
|
|
10
|
+
* with its own boot would race the module-global env holder. So boot is a
|
|
11
|
+
* shared primitive — promise-latched, first caller wins, everyone awaits the
|
|
12
|
+
* same latch. Keyed per app (a Bun test suite boots many); the env holder stays
|
|
13
|
+
* module-global, since `getWorkersEnv()` has no app to key on — one per isolate.
|
|
14
|
+
*/
|
|
15
|
+
const latches = /* @__PURE__ */ new WeakMap();
|
|
16
|
+
/**
|
|
17
|
+
* Boot `app` against `env`, once per isolate.
|
|
18
|
+
*
|
|
19
|
+
* Boot is deferred to the first request or wake because it performs I/O (ORM
|
|
20
|
+
* setup against D1), which workerd forbids in global scope (RFC 0003).
|
|
21
|
+
* @throws Whatever `boot()` threw, and `captureWorkersEnv`'s refusal of a second env.
|
|
22
|
+
*/
|
|
23
|
+
async function bootWorkersApp(app, env) {
|
|
24
|
+
captureWorkersEnv(env);
|
|
25
|
+
let attempt;
|
|
26
|
+
try {
|
|
27
|
+
attempt = latches.get(app);
|
|
28
|
+
if (!attempt) {
|
|
29
|
+
attempt = app.boot();
|
|
30
|
+
latches.set(app, attempt);
|
|
31
|
+
}
|
|
32
|
+
await attempt;
|
|
33
|
+
} catch (error) {
|
|
34
|
+
if (latches.get(app) === attempt) {
|
|
35
|
+
latches.delete(app);
|
|
36
|
+
resetWorkersEnv();
|
|
37
|
+
}
|
|
38
|
+
throw error;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/** Boot, then dispatch — the topology every Workers entrypoint shares. */
|
|
42
|
+
async function bootAndFetch(app, request, env, ctx) {
|
|
43
|
+
await bootWorkersApp(app, env);
|
|
44
|
+
return app.fetch(request, env, ctx);
|
|
45
|
+
}
|
|
46
|
+
//#endregion
|
|
4
47
|
//#region src/handler.ts
|
|
48
|
+
/**
|
|
49
|
+
* The worker entry `guren cloudflare:build` generates.
|
|
50
|
+
*
|
|
51
|
+
* One per module: it carries the isolate's boot slot, and `boot.ts` is where
|
|
52
|
+
* that invariant is specified.
|
|
53
|
+
*/
|
|
5
54
|
function createWorkersHandler(app) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
try {
|
|
11
|
-
attempt = bootPromise ??= app.boot();
|
|
12
|
-
await attempt;
|
|
13
|
-
} catch (error) {
|
|
14
|
-
if (bootPromise === attempt) {
|
|
15
|
-
bootPromise = void 0;
|
|
16
|
-
resetWorkersEnv();
|
|
17
|
-
}
|
|
18
|
-
throw error;
|
|
19
|
-
}
|
|
20
|
-
return app.fetch(request, env, ctx);
|
|
21
|
-
} };
|
|
55
|
+
return {
|
|
56
|
+
fetch: (request, env, ctx) => bootAndFetch(app, request, env, ctx),
|
|
57
|
+
boot: (env) => bootWorkersApp(app, env)
|
|
58
|
+
};
|
|
22
59
|
}
|
|
23
60
|
//#endregion
|
|
24
61
|
//#region src/storage/sigv4.ts
|
|
@@ -67,12 +104,10 @@ async function hmac(key, value) {
|
|
|
67
104
|
return crypto.subtle.sign("HMAC", cryptoKey, new TextEncoder().encode(value));
|
|
68
105
|
}
|
|
69
106
|
/**
|
|
70
|
-
* `AWS4<secret>` → date → region → service → terminator, cached per
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
* key id — never the secret — plus scope; self-bounding, but capped anyway
|
|
75
|
-
* so a pathological key rotation cannot grow it.
|
|
107
|
+
* `AWS4<secret>` → date → region → service → terminator, cached per credential
|
|
108
|
+
* and day: the four-step HMAC chain (eight `crypto.subtle` calls) only changes
|
|
109
|
+
* when the date stamp rolls over. Keyed by access key id — never the secret —
|
|
110
|
+
* plus scope, and capped so a pathological key rotation cannot grow it.
|
|
76
111
|
*/
|
|
77
112
|
const signingKeyCache = /* @__PURE__ */ new Map();
|
|
78
113
|
const SIGNING_KEY_CACHE_MAX = 8;
|
|
@@ -88,11 +123,7 @@ function signingKey(accessKeyId, secretAccessKey, dateStamp, region, service) {
|
|
|
88
123
|
derived.catch(() => signingKeyCache.delete(cacheKey));
|
|
89
124
|
return derived;
|
|
90
125
|
}
|
|
91
|
-
/**
|
|
92
|
-
* Presign a GET so the URL alone authorizes the read until it expires.
|
|
93
|
-
*
|
|
94
|
-
* @returns the signed absolute URL
|
|
95
|
-
*/
|
|
126
|
+
/** Presign a GET so the URL alone authorizes the read until it expires. */
|
|
96
127
|
async function presignGetUrl(options) {
|
|
97
128
|
const { accessKeyId, secretAccessKey, region, service, expiresIn } = options;
|
|
98
129
|
const amzDate = `${(options.date ?? /* @__PURE__ */ new Date()).toISOString().replace(/[-:]/g, "").slice(0, 15)}Z`;
|
|
@@ -132,14 +163,9 @@ const DELETE_BATCH_SIZE = 1e3;
|
|
|
132
163
|
const DELETE_CONCURRENCY = 6;
|
|
133
164
|
/**
|
|
134
165
|
* Cloudflare R2 storage driver over the Workers binding.
|
|
135
|
-
*
|
|
136
166
|
* @example
|
|
137
167
|
* ```ts
|
|
138
|
-
*
|
|
139
|
-
* storage.registerDisk('media', () => new R2Driver({
|
|
140
|
-
* binding: () => getWorkersEnv<Env>().MEDIA,
|
|
141
|
-
* publicUrl: 'https://media.example.com',
|
|
142
|
-
* }))
|
|
168
|
+
* new R2Driver({ binding: () => getWorkersEnv<Env>().MEDIA, publicUrl: 'https://media.example.com' })
|
|
143
169
|
* ```
|
|
144
170
|
*/
|
|
145
171
|
var R2Driver = class {
|
|
@@ -383,16 +409,9 @@ const factory = definePlugin({
|
|
|
383
409
|
name: "cloudflare",
|
|
384
410
|
register() {}
|
|
385
411
|
});
|
|
386
|
-
/**
|
|
387
|
-
* Register the Cloudflare plugin.
|
|
388
|
-
*
|
|
389
|
-
* @example
|
|
390
|
-
* ```typescript
|
|
391
|
-
* createApp({ providers: [cloudflarePlugin()] })
|
|
392
|
-
* ```
|
|
393
|
-
*/
|
|
412
|
+
/** Register the Cloudflare plugin: `createApp({ providers: [cloudflarePlugin()] })`. */
|
|
394
413
|
function cloudflarePlugin(config = {}) {
|
|
395
414
|
return factory(config);
|
|
396
415
|
}
|
|
397
416
|
//#endregion
|
|
398
|
-
export { R2Driver, buildCloudflareOutput, captureWorkersEnv, cloudflarePlugin, createWorkersHandler, flattenD1Migrations, getWorkersEnv, resetWorkersEnv };
|
|
417
|
+
export { R2Driver, bootAndFetch, bootWorkersApp, buildCloudflareOutput, captureWorkersEnv, cloudflarePlugin, createWorkersHandler, flattenD1Migrations, getWorkersEnv, isWorkersRuntime, resetWorkersEnv };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@guren/plugin-cloudflare",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"typecheck": "tsc --noEmit"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@guren/core": "^1.
|
|
49
|
+
"@guren/core": "^1.14.0",
|
|
50
50
|
"citty": "^0.1.6"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|