@cloudhal/cloudflare 0.6.4 → 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/dist/src/admin-worker.d.ts +10 -0
- package/dist/src/admin-worker.js +63 -15
- package/dist/src/scheduler.js +2 -1
- package/package.json +10 -10
|
@@ -76,6 +76,16 @@ export interface AdminEnv extends CommentsEnv, SchedulerEnv, MailEnv, BuildRooms
|
|
|
76
76
|
BROWSER?: BrowserBinding;
|
|
77
77
|
/** `off` keeps `render_page` unavailable even with a `BROWSER` binding. */
|
|
78
78
|
CLOUDHAL_RENDER?: string;
|
|
79
|
+
/** `off` turns the OAuth authorization server for remote MCP clients off (RFC-0044 §10). */
|
|
80
|
+
CLOUDHAL_MCP_OAUTH?: string;
|
|
81
|
+
/** `off`: no Client ID Metadata Documents (RFC-0044 §3). */
|
|
82
|
+
CLOUDHAL_MCP_CIMD?: string;
|
|
83
|
+
/** `off`: no dynamic client registration (RFC-0044 §3; Cursor needs it). */
|
|
84
|
+
CLOUDHAL_MCP_DCR?: string;
|
|
85
|
+
/** Comma-separated hosts OAuth clients may come from (`claude.ai,*.example.com`); unset: any. */
|
|
86
|
+
CLOUDHAL_MCP_CLIENT_HOSTS?: string;
|
|
87
|
+
/** Extra private-use redirect schemes of native clients (besides `cursor`, `vscode`). */
|
|
88
|
+
CLOUDHAL_MCP_REDIRECT_SCHEMES?: string;
|
|
79
89
|
}
|
|
80
90
|
/** Default daily budget of uncached live queries: 80 % of WAE Free's 10,000 (§7.7, A2). */
|
|
81
91
|
export declare const DEFAULT_ANALYTICS_BUDGET = 8000;
|
package/dist/src/admin-worker.js
CHANGED
|
@@ -47,11 +47,18 @@ import { AnalyticsService } from "@cloudhal/analytics/service";
|
|
|
47
47
|
import { SqlQueryBudget } from "@cloudhal/analytics/sql";
|
|
48
48
|
import { DATASET_RE, WaeReader } from "@cloudhal/analytics/wae";
|
|
49
49
|
import { AiStore, bindingTransport, createApi } from "@cloudhal/api";
|
|
50
|
-
import {
|
|
50
|
+
import {
|
|
51
|
+
|
|
52
|
+
cimdFetch,
|
|
53
|
+
createAuth,
|
|
54
|
+
mcpOauthFor,
|
|
55
|
+
oauthRegistrationFrom,
|
|
56
|
+
} from "@cloudhal/api/auth";
|
|
51
57
|
import { PURGE_LIMITS } from "@cloudhal/comments";
|
|
52
58
|
import { SqlCommentStore } from "@cloudhal/comments/sql";
|
|
53
59
|
import { SiteGraphStore, searchProviderFromEnv } from "@cloudhal/core-ts";
|
|
54
60
|
import { createBlockRegistry, } from "@cloudhal/core-ts/blocks";
|
|
61
|
+
import { workersTransport } from "@cloudhal/core-ts/media";
|
|
55
62
|
import { SqlScheduleStore } from "@cloudhal/schedules/sql";
|
|
56
63
|
import { migrate, migrations, } from "@cloudhal/storage";
|
|
57
64
|
import { D1Driver } from "@cloudhal/storage/d1";
|
|
@@ -104,8 +111,59 @@ import { routedSite } from "./site-routes.js";
|
|
|
104
111
|
|
|
105
112
|
|
|
106
113
|
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
|
|
107
124
|
|
|
108
125
|
|
|
126
|
+
/**
|
|
127
|
+
* Better Auth for one request: request-scoped state (background tasks, plugin promises) and no
|
|
128
|
+
* I/O at construction. RFC-0044 §10: the OAuth issuer is the origin the request came to
|
|
129
|
+
* (`CLOUDHAL_MCP_OAUTH=off` turns the authorization server off). §3: client metadata documents
|
|
130
|
+
* are fetched with the media import's Workers transport, never from this Worker's own host or a
|
|
131
|
+
* site's domain (read only when a document is fetched).
|
|
132
|
+
*/
|
|
133
|
+
function adminAuth(
|
|
134
|
+
env ,
|
|
135
|
+
sql ,
|
|
136
|
+
url ,
|
|
137
|
+
run
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
,
|
|
142
|
+
) {
|
|
143
|
+
const ownHosts = async () => [
|
|
144
|
+
url.hostname,
|
|
145
|
+
...(await run.store.listSites()).flatMap((site) => site.domains.map((d) => d.hostname)),
|
|
146
|
+
];
|
|
147
|
+
const cimd = cimdFetch({ transport: workersTransport(), blockedHosts: ownHosts });
|
|
148
|
+
const registration = oauthRegistrationFrom(env, cimd);
|
|
149
|
+
if (registration.problem) run.log(`OAuth client registration is off: ${registration.problem}`);
|
|
150
|
+
const oauth = mcpOauthFor(url.origin, env.CLOUDHAL_MCP_OAUTH, registration);
|
|
151
|
+
return createAuth({
|
|
152
|
+
database: env.DB,
|
|
153
|
+
sql,
|
|
154
|
+
baseURL: url.origin,
|
|
155
|
+
secret: required(env, "BETTER_AUTH_SECRET"),
|
|
156
|
+
signUp:
|
|
157
|
+
env.CLOUDHAL_SIGNUP === "open" || env.CLOUDHAL_SIGNUP === "closed"
|
|
158
|
+
? env.CLOUDHAL_SIGNUP
|
|
159
|
+
: "first-user",
|
|
160
|
+
setupToken: env.CLOUDHAL_SETUP_TOKEN,
|
|
161
|
+
workers: { waitUntil: run.waitUntil },
|
|
162
|
+
log: (level, message) => run.log(`auth ${level}: ${message}`),
|
|
163
|
+
...("mcpOauth" in oauth ? { mcpOauth: oauth.mcpOauth } : {}),
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
|
|
109
167
|
/** Default daily budget of uncached live queries: 80 % of WAE Free's 10,000 (§7.7, A2). */
|
|
110
168
|
export const DEFAULT_ANALYTICS_BUDGET = 8000;
|
|
111
169
|
|
|
@@ -426,20 +484,7 @@ export function createAdminWorker(options = {}) {
|
|
|
426
484
|
});
|
|
427
485
|
if (due) ctx.waitUntil(due);
|
|
428
486
|
|
|
429
|
-
|
|
430
|
-
// and its construction does no I/O.
|
|
431
|
-
const auth = createAuth({
|
|
432
|
-
database: env.DB,
|
|
433
|
-
sql,
|
|
434
|
-
baseURL: url.origin,
|
|
435
|
-
secret: required(env, "BETTER_AUTH_SECRET"),
|
|
436
|
-
signUp:
|
|
437
|
-
env.CLOUDHAL_SIGNUP === "open" || env.CLOUDHAL_SIGNUP === "closed"
|
|
438
|
-
? env.CLOUDHAL_SIGNUP
|
|
439
|
-
: "first-user",
|
|
440
|
-
setupToken: env.CLOUDHAL_SETUP_TOKEN,
|
|
441
|
-
workers: { waitUntil: (p) => ctx.waitUntil(p) },
|
|
442
|
-
});
|
|
487
|
+
const auth = adminAuth(env, sql, url, { waitUntil: (p) => ctx.waitUntil(p), log, store });
|
|
443
488
|
const audit = new AuditLog(sql);
|
|
444
489
|
const approvals = new ApprovalStore(sql);
|
|
445
490
|
const mail = adminMail(env);
|
|
@@ -452,6 +497,7 @@ export function createAdminWorker(options = {}) {
|
|
|
452
497
|
staff: auth.staff,
|
|
453
498
|
signUp: auth.signUp,
|
|
454
499
|
audit,
|
|
500
|
+
oauthServer: auth.oauth,
|
|
455
501
|
// RFC-0011: emailed invites and reset links when `cloudhal deploy` bound a sender.
|
|
456
502
|
...(mail ? { mail } : {}),
|
|
457
503
|
defer: (task) => ctx.waitUntil(task),
|
|
@@ -465,6 +511,8 @@ export function createAdminWorker(options = {}) {
|
|
|
465
511
|
approvals,
|
|
466
512
|
// Remote clients must speak the stateless 2026-07-28 protocol or be served statelessly.
|
|
467
513
|
legacy: "stateless",
|
|
514
|
+
// RFC-0044: discovery names this deployment's authorization server.
|
|
515
|
+
oauth: auth.oauth && { issuer: auth.oauth.issuer, resource: auth.oauth.resource },
|
|
468
516
|
// fetch_asset_url never reaches this Worker's own host (Studio, API, purge); each site's
|
|
469
517
|
// domains are refused too. Workers cannot pin DNS: see `workersTransport` (RFC-0004 §5.7).
|
|
470
518
|
media: { blockedHosts: [url.hostname] },
|
package/dist/src/scheduler.js
CHANGED
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
* `CLOUDHAL_ANALYTICS_CRON=off` / `CLOUDHAL_COMMENTS_CRON=off`; both read as `alarm` until the next
|
|
25
25
|
* `cloudhal deploy` removes them.
|
|
26
26
|
*/
|
|
27
|
-
import { releaseApprovalCheck } from "@cloudhal/api";
|
|
27
|
+
import { oauthClientsPruneJob, releaseApprovalCheck } from "@cloudhal/api";
|
|
28
28
|
import { PURGE_LIMITS } from "@cloudhal/comments";
|
|
29
29
|
import { SqlCommentStore } from "@cloudhal/comments/sql";
|
|
30
30
|
import {
|
|
@@ -272,6 +272,7 @@ export function adminSystemJobs(
|
|
|
272
272
|
},
|
|
273
273
|
},
|
|
274
274
|
listValuesJob(sql, { paid: env.CLOUDHAL_TICK_BUDGET === "paid", log }),
|
|
275
|
+
oauthClientsPruneJob(sql, log),
|
|
275
276
|
];
|
|
276
277
|
if (o.commentsOn)
|
|
277
278
|
jobs.push({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudhal/cloudflare",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Cloudhal on Cloudflare: the admin Worker (API, auth, MCP, Studio) over D1 + R2",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"homepage": "https://cloudhal.dev",
|
|
@@ -48,19 +48,19 @@
|
|
|
48
48
|
"README.md"
|
|
49
49
|
],
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@cloudhal/agent-runtime": "0.
|
|
52
|
-
"@cloudhal/analytics": "0.
|
|
53
|
-
"@cloudhal/api": "0.
|
|
54
|
-
"@cloudhal/comments": "0.
|
|
55
|
-
"@cloudhal/core-ts": "0.
|
|
56
|
-
"@cloudhal/mcp-server": "0.
|
|
57
|
-
"@cloudhal/schedules": "0.
|
|
58
|
-
"@cloudhal/storage": "0.
|
|
51
|
+
"@cloudhal/agent-runtime": "0.7.0",
|
|
52
|
+
"@cloudhal/analytics": "0.7.0",
|
|
53
|
+
"@cloudhal/api": "0.7.0",
|
|
54
|
+
"@cloudhal/comments": "0.7.0",
|
|
55
|
+
"@cloudhal/core-ts": "0.7.0",
|
|
56
|
+
"@cloudhal/mcp-server": "0.7.0",
|
|
57
|
+
"@cloudhal/schedules": "0.7.0",
|
|
58
|
+
"@cloudhal/storage": "0.7.0",
|
|
59
59
|
"zod": "^4.6.7"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
62
|
"@cloudflare/workers-types": "^5.20261007.1",
|
|
63
|
-
"@cloudhal/astro-renderer": "0.
|
|
63
|
+
"@cloudhal/astro-renderer": "0.7.0",
|
|
64
64
|
"@types/node": "^26.6.5",
|
|
65
65
|
"typescript": "7.0.2",
|
|
66
66
|
"vitest": "5.1.0",
|