@aotter/mantle-cloudflare 0.0.11-alpha.11
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/LICENSE +202 -0
- package/README.md +10 -0
- package/dist/assets/aotterFavicon.d.ts +2 -0
- package/dist/assets/aotterFavicon.d.ts.map +1 -0
- package/dist/assets/aotterFavicon.js +5 -0
- package/dist/assets/aotterFavicon.js.map +1 -0
- package/dist/auth/ConsoleEmailSender.d.ts +15 -0
- package/dist/auth/ConsoleEmailSender.d.ts.map +1 -0
- package/dist/auth/ConsoleEmailSender.js +19 -0
- package/dist/auth/ConsoleEmailSender.js.map +1 -0
- package/dist/auth/appleClientSecret.d.ts +70 -0
- package/dist/auth/appleClientSecret.d.ts.map +1 -0
- package/dist/auth/appleClientSecret.js +111 -0
- package/dist/auth/appleClientSecret.js.map +1 -0
- package/dist/auth/createAuth.d.ts +176 -0
- package/dist/auth/createAuth.d.ts.map +1 -0
- package/dist/auth/createAuth.js +360 -0
- package/dist/auth/createAuth.js.map +1 -0
- package/dist/bindings/AssetsAssetServer.d.ts +14 -0
- package/dist/bindings/AssetsAssetServer.d.ts.map +1 -0
- package/dist/bindings/AssetsAssetServer.js +20 -0
- package/dist/bindings/AssetsAssetServer.js.map +1 -0
- package/dist/bindings/D1DatabaseDriver.d.ts +21 -0
- package/dist/bindings/D1DatabaseDriver.d.ts.map +1 -0
- package/dist/bindings/D1DatabaseDriver.js +126 -0
- package/dist/bindings/D1DatabaseDriver.js.map +1 -0
- package/dist/bindings/KvCacheBinding.d.ts +14 -0
- package/dist/bindings/KvCacheBinding.d.ts.map +1 -0
- package/dist/bindings/KvCacheBinding.js +27 -0
- package/dist/bindings/KvCacheBinding.js.map +1 -0
- package/dist/bindings/R2MediaStorage.d.ts +80 -0
- package/dist/bindings/R2MediaStorage.d.ts.map +1 -0
- package/dist/bindings/R2MediaStorage.js +189 -0
- package/dist/bindings/R2MediaStorage.js.map +1 -0
- package/dist/bindings/WorkersQueueHookDispatcher.d.ts +38 -0
- package/dist/bindings/WorkersQueueHookDispatcher.d.ts.map +1 -0
- package/dist/bindings/WorkersQueueHookDispatcher.js +68 -0
- package/dist/bindings/WorkersQueueHookDispatcher.js.map +1 -0
- package/dist/bindings/index.d.ts +6 -0
- package/dist/bindings/index.d.ts.map +1 -0
- package/dist/bindings/index.js +6 -0
- package/dist/bindings/index.js.map +1 -0
- package/dist/handlers/index.d.ts +2 -0
- package/dist/handlers/index.d.ts.map +1 -0
- package/dist/handlers/index.js +2 -0
- package/dist/handlers/index.js.map +1 -0
- package/dist/handlers/turnstile.d.ts +43 -0
- package/dist/handlers/turnstile.d.ts.map +1 -0
- package/dist/handlers/turnstile.js +71 -0
- package/dist/handlers/turnstile.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/dist/mount/bootRuntimeOnce.d.ts +17 -0
- package/dist/mount/bootRuntimeOnce.d.ts.map +1 -0
- package/dist/mount/bootRuntimeOnce.js +35 -0
- package/dist/mount/bootRuntimeOnce.js.map +1 -0
- package/dist/mount/cmsConfig.d.ts +33 -0
- package/dist/mount/cmsConfig.d.ts.map +1 -0
- package/dist/mount/cmsConfig.js +2 -0
- package/dist/mount/cmsConfig.js.map +1 -0
- package/dist/mount/index.d.ts +6 -0
- package/dist/mount/index.d.ts.map +1 -0
- package/dist/mount/index.js +5 -0
- package/dist/mount/index.js.map +1 -0
- package/dist/mount/mountMcp.d.ts +32 -0
- package/dist/mount/mountMcp.d.ts.map +1 -0
- package/dist/mount/mountMcp.js +107 -0
- package/dist/mount/mountMcp.js.map +1 -0
- package/dist/mount/mountPublicRoutes.d.ts +82 -0
- package/dist/mount/mountPublicRoutes.d.ts.map +1 -0
- package/dist/mount/mountPublicRoutes.js +243 -0
- package/dist/mount/mountPublicRoutes.js.map +1 -0
- package/dist/mount/mountServerEndpoints.d.ts +10 -0
- package/dist/mount/mountServerEndpoints.d.ts.map +1 -0
- package/dist/mount/mountServerEndpoints.js +503 -0
- package/dist/mount/mountServerEndpoints.js.map +1 -0
- package/dist/oauth/consentHtml.d.ts +15 -0
- package/dist/oauth/consentHtml.d.ts.map +1 -0
- package/dist/oauth/consentHtml.js +89 -0
- package/dist/oauth/consentHtml.js.map +1 -0
- package/dist/oauth/index.d.ts +4 -0
- package/dist/oauth/index.d.ts.map +1 -0
- package/dist/oauth/index.js +4 -0
- package/dist/oauth/index.js.map +1 -0
- package/dist/oauth/mountOAuth.d.ts +29 -0
- package/dist/oauth/mountOAuth.d.ts.map +1 -0
- package/dist/oauth/mountOAuth.js +105 -0
- package/dist/oauth/mountOAuth.js.map +1 -0
- package/dist/oauth/oauthConstants.d.ts +15 -0
- package/dist/oauth/oauthConstants.d.ts.map +1 -0
- package/dist/oauth/oauthConstants.js +15 -0
- package/dist/oauth/oauthConstants.js.map +1 -0
- package/dist/oauth/oauthSingleton.d.ts +34 -0
- package/dist/oauth/oauthSingleton.d.ts.map +1 -0
- package/dist/oauth/oauthSingleton.js +22 -0
- package/dist/oauth/oauthSingleton.js.map +1 -0
- package/package.json +61 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { createCmsRuntime, } from "@aotter/mantle-runtime";
|
|
2
|
+
export function createCmsRef(config) {
|
|
3
|
+
const runtime = createCmsRuntime({
|
|
4
|
+
manifests: config.manifests,
|
|
5
|
+
handlers: config.handlers,
|
|
6
|
+
templates: config.templates,
|
|
7
|
+
siteDefaults: config.siteDefaults,
|
|
8
|
+
publicPathResolver: config.publicPathResolver,
|
|
9
|
+
mediaAllowSvg: config.mediaAllowSvg,
|
|
10
|
+
mediaMaxBytes: config.mediaMaxBytes,
|
|
11
|
+
db: config.bindings.db,
|
|
12
|
+
kv: config.bindings.kv,
|
|
13
|
+
assets: config.bindings.assets,
|
|
14
|
+
mediaStorage: config.bindings.mediaStorage,
|
|
15
|
+
deferredHookDispatcher: config.bindings.deferredHookDispatcher,
|
|
16
|
+
});
|
|
17
|
+
let booted = null;
|
|
18
|
+
return {
|
|
19
|
+
manifests: config.manifests,
|
|
20
|
+
auth: config.auth,
|
|
21
|
+
get() {
|
|
22
|
+
if (booted)
|
|
23
|
+
return booted;
|
|
24
|
+
booted = runtime
|
|
25
|
+
.bootInit()
|
|
26
|
+
.then(() => runtime)
|
|
27
|
+
.catch((err) => {
|
|
28
|
+
booted = null;
|
|
29
|
+
throw err;
|
|
30
|
+
});
|
|
31
|
+
return booted;
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=bootRuntimeOnce.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bootRuntimeOnce.js","sourceRoot":"","sources":["../../src/mount/bootRuntimeOnce.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,GAEjB,MAAM,wBAAwB,CAAC;AAiBhC,MAAM,UAAU,YAAY,CAAC,MAAiB;IAC5C,MAAM,OAAO,GAAG,gBAAgB,CAAC;QAC/B,SAAS,EAAE,MAAM,CAAC,SAAS;QAC3B,QAAQ,EAAE,MAAM,CAAC,QAAQ;QACzB,SAAS,EAAE,MAAM,CAAC,SAAS;QAC3B,YAAY,EAAE,MAAM,CAAC,YAAY;QACjC,kBAAkB,EAAE,MAAM,CAAC,kBAAkB;QAC7C,aAAa,EAAE,MAAM,CAAC,aAAa;QACnC,aAAa,EAAE,MAAM,CAAC,aAAa;QACnC,EAAE,EAAE,MAAM,CAAC,QAAQ,CAAC,EAAE;QACtB,EAAE,EAAE,MAAM,CAAC,QAAQ,CAAC,EAAE;QACtB,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM;QAC9B,YAAY,EAAE,MAAM,CAAC,QAAQ,CAAC,YAAY;QAC1C,sBAAsB,EAAE,MAAM,CAAC,QAAQ,CAAC,sBAAsB;KAC/D,CAAC,CAAC;IAEH,IAAI,MAAM,GAA+B,IAAI,CAAC;IAC9C,OAAO;QACL,SAAS,EAAE,MAAM,CAAC,SAAS;QAC3B,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,GAAG;YACD,IAAI,MAAM;gBAAE,OAAO,MAAM,CAAC;YAC1B,MAAM,GAAG,OAAO;iBACb,QAAQ,EAAE;iBACV,IAAI,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC;iBACnB,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;gBACb,MAAM,GAAG,IAAI,CAAC;gBACd,MAAM,GAAG,CAAC;YACZ,CAAC,CAAC,CAAC;YACL,OAAO,MAAM,CAAC;QAChB,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { AnyHandler, CreateCmsRuntimeArgs, PublicPathResolver, TemplateRegistry } from "@aotter/mantle-runtime";
|
|
2
|
+
import type { Manifest, SiteDefaults } from "@aotter/mantle-spec";
|
|
3
|
+
import type { Auth } from "../auth/createAuth.js";
|
|
4
|
+
/**
|
|
5
|
+
* Consumer-supplied config for the Cloudflare adapter mounts. `auth`
|
|
6
|
+
* (Better Auth) gates `/admin/api/*` + MCP bearers. `bindings` carries
|
|
7
|
+
* the three runtime-port adapters (db / kv / assets).
|
|
8
|
+
*/
|
|
9
|
+
export interface CmsConfig {
|
|
10
|
+
readonly manifests: readonly Manifest[];
|
|
11
|
+
readonly handlers?: Readonly<Record<string, AnyHandler>>;
|
|
12
|
+
readonly templates?: TemplateRegistry;
|
|
13
|
+
readonly siteDefaults?: SiteDefaults;
|
|
14
|
+
readonly publicPathResolver?: PublicPathResolver;
|
|
15
|
+
readonly bindings: Pick<CreateCmsRuntimeArgs, "db" | "kv" | "assets"> & {
|
|
16
|
+
/** Optional media storage adapter. When set, media MCP tools and
|
|
17
|
+
* `/admin/api/media/*` endpoints are registered. Forwarded to the
|
|
18
|
+
* runtime as `mediaStorage`. */
|
|
19
|
+
readonly mediaStorage?: CreateCmsRuntimeArgs["mediaStorage"];
|
|
20
|
+
/** Optional deferred-delivery dispatcher. When set, `after_*`
|
|
21
|
+
* lifecycle hooks fire through this instead of riding
|
|
22
|
+
* `ctx.waitUntil`. The Cloudflare adapter expects a
|
|
23
|
+
* `WorkersQueueHookDispatcher` bound to the `clam_internal` queue
|
|
24
|
+
* here. */
|
|
25
|
+
readonly deferredHookDispatcher?: CreateCmsRuntimeArgs["deferredHookDispatcher"];
|
|
26
|
+
};
|
|
27
|
+
/** Pass-through to runtime: SVG opt-in flag (default false). */
|
|
28
|
+
readonly mediaAllowSvg?: boolean;
|
|
29
|
+
/** Pass-through to runtime: byte ceiling for uploads (default 25MB). */
|
|
30
|
+
readonly mediaMaxBytes?: number;
|
|
31
|
+
readonly auth: Auth;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=cmsConfig.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cmsConfig.d.ts","sourceRoot":"","sources":["../../src/mount/cmsConfig.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EACV,oBAAoB,EACpB,kBAAkB,EAClB,gBAAgB,EACjB,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAClE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAElD;;;;GAIG;AACH,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,SAAS,EAAE,SAAS,QAAQ,EAAE,CAAC;IACxC,QAAQ,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC;IACzD,QAAQ,CAAC,SAAS,CAAC,EAAE,gBAAgB,CAAC;IACtC,QAAQ,CAAC,YAAY,CAAC,EAAE,YAAY,CAAC;IACrC,QAAQ,CAAC,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;IACjD,QAAQ,CAAC,QAAQ,EAAE,IAAI,CAAC,oBAAoB,EAAE,IAAI,GAAG,IAAI,GAAG,QAAQ,CAAC,GAAG;QACtE;;yCAEiC;QACjC,QAAQ,CAAC,YAAY,CAAC,EAAE,oBAAoB,CAAC,cAAc,CAAC,CAAC;QAC7D;;;;oBAIY;QACZ,QAAQ,CAAC,sBAAsB,CAAC,EAAE,oBAAoB,CAAC,wBAAwB,CAAC,CAAC;KAClF,CAAC;IACF,gEAAgE;IAChE,QAAQ,CAAC,aAAa,CAAC,EAAE,OAAO,CAAC;IACjC,wEAAwE;IACxE,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;CACrB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cmsConfig.js","sourceRoot":"","sources":["../../src/mount/cmsConfig.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { mountServerEndpoints } from "./mountServerEndpoints.js";
|
|
2
|
+
export { type CmsRuntimeRef, createCmsRef } from "./bootRuntimeOnce.js";
|
|
3
|
+
export { createMcpApiHandler, protectedResourceMetadataPath, type CreateMcpApiHandlerOptions, } from "./mountMcp.js";
|
|
4
|
+
export { mountPublicRoutes, type CollectionRouteConfig, type MountPublicRoutesOptions, type PublicRouteContext, type SlugOverride, } from "./mountPublicRoutes.js";
|
|
5
|
+
export type { CmsConfig } from "./cmsConfig.js";
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/mount/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,KAAK,aAAa,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACxE,OAAO,EACL,mBAAmB,EACnB,6BAA6B,EAC7B,KAAK,0BAA0B,GAChC,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,iBAAiB,EACjB,KAAK,qBAAqB,EAC1B,KAAK,wBAAwB,EAC7B,KAAK,kBAAkB,EACvB,KAAK,YAAY,GAClB,MAAM,wBAAwB,CAAC;AAChC,YAAY,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { mountServerEndpoints } from "./mountServerEndpoints.js";
|
|
2
|
+
export { createCmsRef } from "./bootRuntimeOnce.js";
|
|
3
|
+
export { createMcpApiHandler, protectedResourceMetadataPath, } from "./mountMcp.js";
|
|
4
|
+
export { mountPublicRoutes, } from "./mountPublicRoutes.js";
|
|
5
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/mount/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAsB,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACxE,OAAO,EACL,mBAAmB,EACnB,6BAA6B,GAE9B,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,iBAAiB,GAKlB,MAAM,wBAAwB,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { CmsRuntimeRef } from "./bootRuntimeOnce.js";
|
|
2
|
+
/**
|
|
3
|
+
* RFC 9728 §3.1: the OAuth Protected Resource Metadata document for a
|
|
4
|
+
* resource at `<origin><path>` is served at
|
|
5
|
+
* `<origin>/.well-known/oauth-protected-resource<path>`. The OAuth
|
|
6
|
+
* provider lib handles this automatically when it sits at top level
|
|
7
|
+
* (`export default new OAuthProvider(...)`); kept exported for
|
|
8
|
+
* consumers who want to inspect the path shape.
|
|
9
|
+
*/
|
|
10
|
+
export declare function protectedResourceMetadataPath(resourcePath: string): string;
|
|
11
|
+
export interface CreateMcpApiHandlerOptions {
|
|
12
|
+
readonly ref: CmsRuntimeRef;
|
|
13
|
+
readonly surface: "staff" | "public";
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Build a Cloudflare Worker `ExportedHandler` that serves one MCP
|
|
17
|
+
* resource path. Plug into `createOAuthProvider({ apiHandlers })`
|
|
18
|
+
* keyed by the resource path (e.g. `/mcp/staff` or `/mcp`).
|
|
19
|
+
*
|
|
20
|
+
* The OAuthProvider lib verifies the bearer token, decrypts grant
|
|
21
|
+
* props, and sets `ctx.props` BEFORE calling this handler. We read
|
|
22
|
+
* `ctx.props.{userId, role}` (stashed at consent time by
|
|
23
|
+
* `mountAuthorize`) and gate staff surfaces on the D1 admin role.
|
|
24
|
+
*
|
|
25
|
+
* Note: OAuth scope distinction (`mcp:read` vs `mcp:staff`) used to
|
|
26
|
+
* differentiate surfaces here. Removed because claude.ai's MCP client
|
|
27
|
+
* silently omits `scope=` from /authorize when scopes contain colons,
|
|
28
|
+
* which broke the consent flow. Staff vs public is now purely D1-role
|
|
29
|
+
* driven.
|
|
30
|
+
*/
|
|
31
|
+
export declare function createMcpApiHandler(options: CreateMcpApiHandlerOptions): ExportedHandler<Record<string, unknown>>;
|
|
32
|
+
//# sourceMappingURL=mountMcp.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mountMcp.d.ts","sourceRoot":"","sources":["../../src/mount/mountMcp.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAE1D;;;;;;;GAOG;AACH,wBAAgB,6BAA6B,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAK1E;AAED,MAAM,WAAW,0BAA0B;IACzC,QAAQ,CAAC,GAAG,EAAE,aAAa,CAAC;IAC5B,QAAQ,CAAC,OAAO,EAAE,OAAO,GAAG,QAAQ,CAAC;CACtC;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,0BAA0B,GAClC,eAAe,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAsE1C"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { McpJsonRpcDispatcher } from "@aotter/mantle-runtime";
|
|
2
|
+
import { ADMIN_ROLE_SET } from "../auth/createAuth.js";
|
|
3
|
+
/**
|
|
4
|
+
* RFC 9728 §3.1: the OAuth Protected Resource Metadata document for a
|
|
5
|
+
* resource at `<origin><path>` is served at
|
|
6
|
+
* `<origin>/.well-known/oauth-protected-resource<path>`. The OAuth
|
|
7
|
+
* provider lib handles this automatically when it sits at top level
|
|
8
|
+
* (`export default new OAuthProvider(...)`); kept exported for
|
|
9
|
+
* consumers who want to inspect the path shape.
|
|
10
|
+
*/
|
|
11
|
+
export function protectedResourceMetadataPath(resourcePath) {
|
|
12
|
+
const trimmed = resourcePath.replace(/\/+$/, "");
|
|
13
|
+
if (!trimmed || trimmed === "/")
|
|
14
|
+
return "/.well-known/oauth-protected-resource";
|
|
15
|
+
const normalized = trimmed.startsWith("/") ? trimmed : `/${trimmed}`;
|
|
16
|
+
return `/.well-known/oauth-protected-resource${normalized}`;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Build a Cloudflare Worker `ExportedHandler` that serves one MCP
|
|
20
|
+
* resource path. Plug into `createOAuthProvider({ apiHandlers })`
|
|
21
|
+
* keyed by the resource path (e.g. `/mcp/staff` or `/mcp`).
|
|
22
|
+
*
|
|
23
|
+
* The OAuthProvider lib verifies the bearer token, decrypts grant
|
|
24
|
+
* props, and sets `ctx.props` BEFORE calling this handler. We read
|
|
25
|
+
* `ctx.props.{userId, role}` (stashed at consent time by
|
|
26
|
+
* `mountAuthorize`) and gate staff surfaces on the D1 admin role.
|
|
27
|
+
*
|
|
28
|
+
* Note: OAuth scope distinction (`mcp:read` vs `mcp:staff`) used to
|
|
29
|
+
* differentiate surfaces here. Removed because claude.ai's MCP client
|
|
30
|
+
* silently omits `scope=` from /authorize when scopes contain colons,
|
|
31
|
+
* which broke the consent flow. Staff vs public is now purely D1-role
|
|
32
|
+
* driven.
|
|
33
|
+
*/
|
|
34
|
+
export function createMcpApiHandler(options) {
|
|
35
|
+
const { ref, surface } = options;
|
|
36
|
+
// Key the cached dispatcher to the runtime identity. Without this,
|
|
37
|
+
// if `ref.get()` rejects + resets and the next call returns a new
|
|
38
|
+
// runtime instance, the cached dispatcher would silently keep
|
|
39
|
+
// pointing at the pre-reset use-cases. A WeakMap also lets the GC
|
|
40
|
+
// reclaim the dispatcher if the runtime is replaced.
|
|
41
|
+
const dispatcherCache = new WeakMap();
|
|
42
|
+
return {
|
|
43
|
+
async fetch(request, _env, ctx) {
|
|
44
|
+
const props = ctx.props;
|
|
45
|
+
if (!props?.userId)
|
|
46
|
+
return forbidden();
|
|
47
|
+
const role = props.role;
|
|
48
|
+
if (surface === "staff" && (!role || !ADMIN_ROLE_SET.has(role))) {
|
|
49
|
+
return forbidden();
|
|
50
|
+
}
|
|
51
|
+
const runtime = await ref.get();
|
|
52
|
+
// Media tools require BOTH a storage adapter AND a declared
|
|
53
|
+
// `media.purposes` taxonomy (#262). Empty purposes →
|
|
54
|
+
// create_media_upload would always fail-closed, so don't surface
|
|
55
|
+
// the tools in tools/list at all. Read this before consulting the
|
|
56
|
+
// dispatcher cache so operator edits to site_config update the
|
|
57
|
+
// MCP catalog without a redeploy/runtime reset.
|
|
58
|
+
const mediaPurposes = runtime.media
|
|
59
|
+
? await runtime.siteConfig.readMediaPurposes()
|
|
60
|
+
: [];
|
|
61
|
+
const mediaPurposesKey = mediaPurposes.join("\u0000");
|
|
62
|
+
let cached = dispatcherCache.get(runtime);
|
|
63
|
+
if (!cached || cached.mediaPurposesKey !== mediaPurposesKey) {
|
|
64
|
+
const mediaEnabled = runtime.media !== null && mediaPurposes.length > 0;
|
|
65
|
+
const dispatcher = new McpJsonRpcDispatcher({
|
|
66
|
+
listEntries: runtime.listEntries,
|
|
67
|
+
getEntry: runtime.getEntry,
|
|
68
|
+
createDraft: runtime.createDraft,
|
|
69
|
+
updateDraft: runtime.updateDraft,
|
|
70
|
+
requestPublish: runtime.requestPublish,
|
|
71
|
+
unpublish: runtime.unpublish,
|
|
72
|
+
archive: runtime.archive,
|
|
73
|
+
deleteEntry: runtime.deleteEntry,
|
|
74
|
+
executeView: runtime.executeView,
|
|
75
|
+
media: mediaEnabled && runtime.media
|
|
76
|
+
? {
|
|
77
|
+
createUpload: runtime.media.createUpload,
|
|
78
|
+
commitUpload: runtime.media.commitUpload,
|
|
79
|
+
purposes: mediaPurposes,
|
|
80
|
+
}
|
|
81
|
+
: undefined,
|
|
82
|
+
}, [...runtime.schemasByName.values()], {
|
|
83
|
+
surface,
|
|
84
|
+
views: ref.manifests.filter((m) => m.kind === "View"),
|
|
85
|
+
});
|
|
86
|
+
cached = { mediaPurposesKey, dispatcher };
|
|
87
|
+
dispatcherCache.set(runtime, cached);
|
|
88
|
+
}
|
|
89
|
+
return cached.dispatcher.dispatch(request, {
|
|
90
|
+
userId: props.userId,
|
|
91
|
+
staff: role && ADMIN_ROLE_SET.has(role)
|
|
92
|
+
? { userId: props.userId, role: role }
|
|
93
|
+
: null,
|
|
94
|
+
});
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
function forbidden() {
|
|
99
|
+
return new Response("forbidden", {
|
|
100
|
+
status: 403,
|
|
101
|
+
headers: {
|
|
102
|
+
"www-authenticate": `Bearer realm="mcp", error="insufficient_scope"`,
|
|
103
|
+
"access-control-expose-headers": "WWW-Authenticate",
|
|
104
|
+
},
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
//# sourceMappingURL=mountMcp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mountMcp.js","sourceRoot":"","sources":["../../src/mount/mountMcp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAE9D,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAIvD;;;;;;;GAOG;AACH,MAAM,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gBAAgB,EAAE,UAAU,EAAE,CAAC;gBAC1C,eAAe,CAAC,GAAG,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;YACvC,CAAC;YACD,OAAO,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,OAAO,EAAE;gBACzC,MAAM,EAAE,KAAK,CAAC,MAAM;gBACpB,KAAK,EAAE,IAAI,IAAI,cAAc,CAAC,GAAG,CAAC,IAAI,CAAC;oBACrC,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,IAAI,EAAE,IAAiB,EAAE;oBACnD,CAAC,CAAC,IAAI;aACT,CAAC,CAAC;QACL,CAAC;KACF,CAAC;AACJ,CAAC;AAED,SAAS,SAAS;IAChB,OAAO,IAAI,QAAQ,CAAC,WAAW,EAAE;QAC/B,MAAM,EAAE,GAAG;QACX,OAAO,EAAE;YACP,kBAAkB,EAAE,gDAAgD;YACpE,+BAA+B,EAAE,kBAAkB;SACpD;KACF,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { Context, Hono } from "hono";
|
|
2
|
+
import type { ContentState, SiteConfig } from "@aotter/mantle-spec";
|
|
3
|
+
import { type CmsRuntime } from "@aotter/mantle-runtime";
|
|
4
|
+
import type { CmsRuntimeRef } from "./bootRuntimeOnce.js";
|
|
5
|
+
/**
|
|
6
|
+
* `mountPublicRoutes` — mounts the SDK-managed public surface on the
|
|
7
|
+
* consumer's Hono app. Replaces ~140 lines of route-stitching every
|
|
8
|
+
* starter would otherwise hand-roll.
|
|
9
|
+
*
|
|
10
|
+
* Routes (per `collectionRoutes` config):
|
|
11
|
+
*
|
|
12
|
+
* - `GET /` → 302 to `/{canonicalLocale}` (skipped if `homeRenderer` not set)
|
|
13
|
+
* - `GET /{locale}` → `homeRenderer` (composed; cross-collection)
|
|
14
|
+
* - `GET /{locale}/{segment}` → KV-cached collection list
|
|
15
|
+
* - `GET /{locale}/{segment}/{slug}` → KV-cached entry HTML
|
|
16
|
+
* - `GET /{locale}/{segment}/{slug}.md` → KV-cached entry markdown mirror (AEO)
|
|
17
|
+
* - `GET /{locale}/{segment}/{slug}?preview=1` → live render via `previewEntry` use case
|
|
18
|
+
* - `GET /{locale}/llms.txt` → KV-cached llms.txt
|
|
19
|
+
* - `GET /llms.txt` → KV-cached root llms.txt
|
|
20
|
+
* - `GET /sitemap.xml` → composed sitemap
|
|
21
|
+
*
|
|
22
|
+
* Slug overrides intercept `(collection, slug)` pairs the consumer
|
|
23
|
+
* wants to serve from a hand-rolled template (e.g. a contact form
|
|
24
|
+
* page that needs `<TURNSTILE_SITE_KEY>` injected) rather than a
|
|
25
|
+
* pre-rendered KV blob. Overrides take precedence over preview /
|
|
26
|
+
* live-dev / KV.
|
|
27
|
+
*
|
|
28
|
+
* `liveDev: true` (typically `env.CLAM_LOCAL_DEV === "1"`) bypasses
|
|
29
|
+
* KV for entry / list HTML — every request live-renders against
|
|
30
|
+
* current D1 state via the `RenderEntryLiveUseCase` /
|
|
31
|
+
* `RenderListLiveUseCase`. `.md` mirrors and `llms.txt` still come
|
|
32
|
+
* from KV (those are cheap to rebuild via `pnpm fixture`). Don't set
|
|
33
|
+
* in production — defeats the publish pipeline cache.
|
|
34
|
+
*/
|
|
35
|
+
export interface CollectionRouteConfig {
|
|
36
|
+
/** Schema name (e.g. `"post-translations"`). */
|
|
37
|
+
readonly collection: string;
|
|
38
|
+
/** URL segment beneath `/{locale}/`. Empty string puts entries
|
|
39
|
+
* directly under `/{locale}/{slug}` (rare; useful when a single
|
|
40
|
+
* collection owns the whole locale tree). */
|
|
41
|
+
readonly segment: string;
|
|
42
|
+
/** When true, expose `GET /{locale}/{segment}` for the collection
|
|
43
|
+
* list. Default false (most starters use a hand-rolled list page). */
|
|
44
|
+
readonly listRoute?: boolean;
|
|
45
|
+
/** When true, expose `GET /{locale}/{segment}/{slug}.md` for the
|
|
46
|
+
* AEO markdown mirror. Default true — the publish pipeline already
|
|
47
|
+
* writes the mirror to KV; not exposing it would be silent waste. */
|
|
48
|
+
readonly markdownMirror?: boolean;
|
|
49
|
+
/** Slug to collapse to `/{locale}` (no trailing segment + slug).
|
|
50
|
+
* Used for the home page when it lives in a translations
|
|
51
|
+
* collection. */
|
|
52
|
+
readonly homeSlug?: string;
|
|
53
|
+
}
|
|
54
|
+
export interface PublicRouteContext {
|
|
55
|
+
readonly c: Context;
|
|
56
|
+
readonly runtime: CmsRuntime;
|
|
57
|
+
readonly site: SiteConfig;
|
|
58
|
+
readonly locale: string;
|
|
59
|
+
}
|
|
60
|
+
export interface SlugOverride {
|
|
61
|
+
readonly collection: string;
|
|
62
|
+
readonly slug: string;
|
|
63
|
+
readonly render: (ctx: PublicRouteContext) => Promise<Response>;
|
|
64
|
+
}
|
|
65
|
+
export interface MountPublicRoutesOptions {
|
|
66
|
+
readonly collectionRoutes: ReadonlyArray<CollectionRouteConfig>;
|
|
67
|
+
/** Renderer for `/{locale}` — typically composes home page +
|
|
68
|
+
* recent posts across collections. Optional; without it `/` and
|
|
69
|
+
* `/{locale}` are not registered. */
|
|
70
|
+
readonly homeRenderer?: (ctx: PublicRouteContext) => Promise<Response>;
|
|
71
|
+
/** Renderer for the locale 404 fallback. Required — every miss
|
|
72
|
+
* falls through here. */
|
|
73
|
+
readonly notFoundRenderer: (ctx: PublicRouteContext) => Promise<Response>;
|
|
74
|
+
/** Per-(collection, slug) override taking precedence over KV. */
|
|
75
|
+
readonly slugOverrides?: ReadonlyArray<SlugOverride>;
|
|
76
|
+
/** Live-dev flag — bypasses KV for entry / list HTML. Default
|
|
77
|
+
* false. */
|
|
78
|
+
readonly liveDev?: boolean;
|
|
79
|
+
}
|
|
80
|
+
export declare function mountPublicRoutes(app: Hono, ref: CmsRuntimeRef, options: MountPublicRoutesOptions): void;
|
|
81
|
+
export type { ContentState };
|
|
82
|
+
//# sourceMappingURL=mountPublicRoutes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mountPublicRoutes.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IACtC,QAAQ,CAAC,YAAY,CAAC,EAAE,CAAC,GAAG,EAAE,kBAAkB,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;IACvE;8BAC0B;IAC1B,QAAQ,CAAC,gBAAgB,EAAE,CAAC,GAAG,EAAE,kBAAkB,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC1E,iEAAiE;IACjE,QAAQ,CAAC,aAAa,CAAC,EAAE,aAAa,CAAC,YAAY,CAAC,CAAC;IACrD;iBACa;IACb,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;CAC5B;AAwBD,wBAAgB,iBAAiB,CAC/B,GAAG,EAAE,IAAI,EACT,GAAG,EAAE,aAAa,EAClB,OAAO,EAAE,wBAAwB,GAChC,IAAI,CA8DN;AAwMD,YAAY,EAAE,YAAY,EAAE,CAAC"}
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import { entryHtmlKeyFromParts, entryMarkdownKeyFromParts, inferLocaleFromPath, isKnownLocale, listHtmlKey, llmsTxtKey, readEntryBySlug, serializeEntryAsMarkdown, toUrlLocale, } from "@aotter/mantle-runtime";
|
|
2
|
+
import { ADMIN_ROLE_SET } from "../auth/createAuth.js";
|
|
3
|
+
const HTML_NO_STORE = {
|
|
4
|
+
"content-type": "text/html; charset=utf-8",
|
|
5
|
+
"cache-control": "no-store",
|
|
6
|
+
};
|
|
7
|
+
const HTML_PUBLIC = {
|
|
8
|
+
"content-type": "text/html; charset=utf-8",
|
|
9
|
+
};
|
|
10
|
+
const MD_PUBLIC = {
|
|
11
|
+
"content-type": "text/markdown; charset=utf-8",
|
|
12
|
+
};
|
|
13
|
+
const TEXT_PUBLIC = {
|
|
14
|
+
"content-type": "text/plain; charset=utf-8",
|
|
15
|
+
};
|
|
16
|
+
const SITEMAP_HEADERS = {
|
|
17
|
+
"content-type": "application/xml; charset=utf-8",
|
|
18
|
+
"cache-control": "public, max-age=300, s-maxage=300",
|
|
19
|
+
};
|
|
20
|
+
export function mountPublicRoutes(app, ref, options) {
|
|
21
|
+
const liveDev = options.liveDev === true;
|
|
22
|
+
const overrideIndex = buildOverrideIndex(options.slugOverrides ?? []);
|
|
23
|
+
// Literal root paths register BEFORE any param-catch-all routes —
|
|
24
|
+
// Hono's trie matches `/llms.txt` against `/:locale` with
|
|
25
|
+
// `:locale = "llms.txt"` if the literal route registers later.
|
|
26
|
+
app.get("/llms.txt", async () => {
|
|
27
|
+
const runtime = await ref.get();
|
|
28
|
+
return readKvText(runtime.kv, llmsTxtKey(""), TEXT_PUBLIC);
|
|
29
|
+
});
|
|
30
|
+
app.get("/sitemap.xml", async (c) => {
|
|
31
|
+
const runtime = await ref.get();
|
|
32
|
+
const site = await runtime.siteConfig.load();
|
|
33
|
+
if (!runtime.publicPathResolver) {
|
|
34
|
+
return new Response("sitemap unavailable: no publicPathResolver configured", {
|
|
35
|
+
status: 500,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
const xml = await runtime.composeSitemap.execute({
|
|
39
|
+
site,
|
|
40
|
+
pathFor: (e) => runtime.publicPathResolver.forEntry(e),
|
|
41
|
+
});
|
|
42
|
+
return new Response(xml, { status: 200, headers: SITEMAP_HEADERS });
|
|
43
|
+
});
|
|
44
|
+
if (options.homeRenderer) {
|
|
45
|
+
app.get("/", async (c) => {
|
|
46
|
+
const runtime = await ref.get();
|
|
47
|
+
const site = await runtime.siteConfig.load();
|
|
48
|
+
const canonical = site.canonicalLocale ?? site.locales[0] ?? "en";
|
|
49
|
+
return c.redirect(`/${toUrlLocale(canonical)}`);
|
|
50
|
+
});
|
|
51
|
+
app.get("/:locale", async (c) => {
|
|
52
|
+
const runtime = await ref.get();
|
|
53
|
+
const site = await runtime.siteConfig.load();
|
|
54
|
+
const locale = canonicalLocaleParam(c.req.param("locale"), site);
|
|
55
|
+
const ctx = buildCtx(c, runtime, site, locale ?? inferLocaleFromPath(c.req.path, site));
|
|
56
|
+
if (locale === null)
|
|
57
|
+
return options.notFoundRenderer(ctx);
|
|
58
|
+
return options.homeRenderer(ctx);
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
app.get("/:locale/llms.txt", async (c) => {
|
|
62
|
+
const runtime = await ref.get();
|
|
63
|
+
const site = await runtime.siteConfig.load();
|
|
64
|
+
const locale = canonicalLocaleParam(c.req.param("locale"), site);
|
|
65
|
+
if (locale === null)
|
|
66
|
+
return new Response("not found", { status: 404, headers: TEXT_PUBLIC });
|
|
67
|
+
return readKvText(runtime.kv, llmsTxtKey(locale), TEXT_PUBLIC);
|
|
68
|
+
});
|
|
69
|
+
for (const route of options.collectionRoutes) {
|
|
70
|
+
mountCollection(app, ref, options, route, liveDev, overrideIndex);
|
|
71
|
+
}
|
|
72
|
+
app.notFound(async (c) => {
|
|
73
|
+
const runtime = await ref.get();
|
|
74
|
+
const site = await runtime.siteConfig.load();
|
|
75
|
+
const locale = inferLocaleFromPath(c.req.path, site);
|
|
76
|
+
return options.notFoundRenderer(buildCtx(c, runtime, site, locale));
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
function mountCollection(app, ref, options, route, liveDev, overrides) {
|
|
80
|
+
const segPath = route.segment ? `/${route.segment}` : "";
|
|
81
|
+
if (route.listRoute) {
|
|
82
|
+
app.get(`/:locale${segPath}`, async (c) => {
|
|
83
|
+
const runtime = await ref.get();
|
|
84
|
+
const site = await runtime.siteConfig.load();
|
|
85
|
+
const locale = canonicalLocaleParam(c.req.param("locale"), site);
|
|
86
|
+
const ctx = buildCtx(c, runtime, site, locale ?? inferLocaleFromPath(c.req.path, site));
|
|
87
|
+
const notFound = () => options.notFoundRenderer(ctx);
|
|
88
|
+
if (locale === null)
|
|
89
|
+
return notFound();
|
|
90
|
+
if (liveDev) {
|
|
91
|
+
const html = await runtime.renderListLive.execute({
|
|
92
|
+
collection: route.collection,
|
|
93
|
+
locale,
|
|
94
|
+
site,
|
|
95
|
+
});
|
|
96
|
+
if (html === null)
|
|
97
|
+
return notFound();
|
|
98
|
+
return new Response(html, { status: 200, headers: HTML_NO_STORE });
|
|
99
|
+
}
|
|
100
|
+
return readThroughCache(runtime.kv, listHtmlKey(route.collection, locale), HTML_PUBLIC, async () => runtime.renderListLive.execute({
|
|
101
|
+
collection: route.collection,
|
|
102
|
+
locale,
|
|
103
|
+
site,
|
|
104
|
+
}), notFound);
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
// Register the `.md` mirror BEFORE the bare `:slug` entry route —
|
|
108
|
+
// Hono matches in registration order, so without this the entry
|
|
109
|
+
// route swallows `slug = "foo.md"` and 404s on KV lookup.
|
|
110
|
+
if (route.markdownMirror !== false) {
|
|
111
|
+
// `[^/]+\\.md` (not `.+\\.md`) so a malicious crawler can't
|
|
112
|
+
// squat sub-paths like `/en/posts/long/random.md` and burn KV
|
|
113
|
+
// reads — the `:slug` group stays single-segment.
|
|
114
|
+
app.get(`/:locale${segPath}/:slug{[^/]+\\.md}`, async (c) => {
|
|
115
|
+
const runtime = await ref.get();
|
|
116
|
+
const site = await runtime.siteConfig.load();
|
|
117
|
+
const locale = canonicalLocaleParam(c.req.param("locale"), site);
|
|
118
|
+
const slugParam = c.req.param("slug") ?? "";
|
|
119
|
+
const slug = slugParam.endsWith(".md") ? slugParam.slice(0, -3) : slugParam;
|
|
120
|
+
const notFound = () => new Response("not found", { status: 404, headers: TEXT_PUBLIC });
|
|
121
|
+
if (locale === null)
|
|
122
|
+
return notFound();
|
|
123
|
+
const key = entryMarkdownKeyFromParts(route.collection, locale, slug);
|
|
124
|
+
return readThroughCache(runtime.kv, key, MD_PUBLIC, async () => {
|
|
125
|
+
const entry = await readEntryBySlug(runtime.db, {
|
|
126
|
+
collection: route.collection,
|
|
127
|
+
slug,
|
|
128
|
+
locale,
|
|
129
|
+
status: "published",
|
|
130
|
+
});
|
|
131
|
+
if (!entry)
|
|
132
|
+
return null;
|
|
133
|
+
return serializeEntryAsMarkdown(entry);
|
|
134
|
+
}, notFound);
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
app.get(`/:locale${segPath}/:slug`, async (c) => {
|
|
138
|
+
const runtime = await ref.get();
|
|
139
|
+
const site = await runtime.siteConfig.load();
|
|
140
|
+
const locale = canonicalLocaleParam(c.req.param("locale"), site);
|
|
141
|
+
const slug = c.req.param("slug");
|
|
142
|
+
const ctx = buildCtx(c, runtime, site, locale ?? inferLocaleFromPath(c.req.path, site));
|
|
143
|
+
const notFound = () => options.notFoundRenderer(ctx);
|
|
144
|
+
if (locale === null)
|
|
145
|
+
return notFound();
|
|
146
|
+
const override = overrides.get(overrideKey(route.collection, slug));
|
|
147
|
+
if (override)
|
|
148
|
+
return override.render(ctx);
|
|
149
|
+
if (c.req.query("preview") === "1") {
|
|
150
|
+
const denied = await assertStaffSession(ref, c.req.raw);
|
|
151
|
+
if (denied)
|
|
152
|
+
return denied;
|
|
153
|
+
const html = await runtime.previewEntry.execute({
|
|
154
|
+
collection: route.collection,
|
|
155
|
+
slug,
|
|
156
|
+
locale,
|
|
157
|
+
site,
|
|
158
|
+
});
|
|
159
|
+
if (html === null)
|
|
160
|
+
return notFound();
|
|
161
|
+
return new Response(html, { status: 200, headers: HTML_NO_STORE });
|
|
162
|
+
}
|
|
163
|
+
if (liveDev) {
|
|
164
|
+
const html = await runtime.renderEntryLive.execute({
|
|
165
|
+
collection: route.collection,
|
|
166
|
+
slug,
|
|
167
|
+
locale,
|
|
168
|
+
site,
|
|
169
|
+
});
|
|
170
|
+
if (html === null)
|
|
171
|
+
return notFound();
|
|
172
|
+
return new Response(html, { status: 200, headers: HTML_NO_STORE });
|
|
173
|
+
}
|
|
174
|
+
const key = entryHtmlKeyFromParts(route.collection, locale, slug);
|
|
175
|
+
return readThroughCache(runtime.kv, key, HTML_PUBLIC, async () => {
|
|
176
|
+
const html = await runtime.renderEntryLive.execute({
|
|
177
|
+
collection: route.collection,
|
|
178
|
+
slug,
|
|
179
|
+
locale,
|
|
180
|
+
site,
|
|
181
|
+
});
|
|
182
|
+
return html;
|
|
183
|
+
}, notFound);
|
|
184
|
+
});
|
|
185
|
+
if (route.homeSlug && options.homeRenderer == null) {
|
|
186
|
+
// Without a homeRenderer the `homeSlug` collapse is a noop —
|
|
187
|
+
// there's no `/{locale}` route to serve. Surface as a console
|
|
188
|
+
// warning at boot rather than silently misconfiguring.
|
|
189
|
+
console.warn(`[mantle] collectionRoute "${route.collection}" declares homeSlug="${route.homeSlug}" ` +
|
|
190
|
+
`but no homeRenderer was passed to mountPublicRoutes — /{locale} will 404.`);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Gate `?preview=1` behind a staff session so anonymous visitors can't
|
|
195
|
+
* enumerate draft slugs. Returns the denial `Response` on failure (401
|
|
196
|
+
* for no session, 403 for non-staff), or `null` when the caller may
|
|
197
|
+
* proceed.
|
|
198
|
+
*/
|
|
199
|
+
async function assertStaffSession(ref, req) {
|
|
200
|
+
const session = await ref.auth.getSession(req);
|
|
201
|
+
if (!session)
|
|
202
|
+
return new Response("unauthorized", { status: 401 });
|
|
203
|
+
const role = await ref.auth.getUserRole(session.user.id);
|
|
204
|
+
if (!role || !ADMIN_ROLE_SET.has(role)) {
|
|
205
|
+
return new Response("forbidden", { status: 403 });
|
|
206
|
+
}
|
|
207
|
+
return null;
|
|
208
|
+
}
|
|
209
|
+
async function readKvText(kv, key, headers) {
|
|
210
|
+
const body = await kv.get(key);
|
|
211
|
+
if (body === null) {
|
|
212
|
+
return new Response("not found", { status: 404, headers: TEXT_PUBLIC });
|
|
213
|
+
}
|
|
214
|
+
return new Response(body, { status: 200, headers });
|
|
215
|
+
}
|
|
216
|
+
async function readThroughCache(kv, key, headers, populate, fallback) {
|
|
217
|
+
const cached = await kv.get(key);
|
|
218
|
+
if (cached !== null)
|
|
219
|
+
return new Response(cached, { status: 200, headers });
|
|
220
|
+
const rendered = await populate();
|
|
221
|
+
if (rendered === null)
|
|
222
|
+
return fallback();
|
|
223
|
+
await kv.put(key, rendered);
|
|
224
|
+
return new Response(rendered, { status: 200, headers });
|
|
225
|
+
}
|
|
226
|
+
function buildCtx(c, runtime, site, locale) {
|
|
227
|
+
return { c, runtime, site, locale };
|
|
228
|
+
}
|
|
229
|
+
function canonicalLocaleParam(locale, site) {
|
|
230
|
+
if (!isKnownLocale(locale, site))
|
|
231
|
+
return null;
|
|
232
|
+
return inferLocaleFromPath(`/${locale}`, site);
|
|
233
|
+
}
|
|
234
|
+
function buildOverrideIndex(overrides) {
|
|
235
|
+
const map = new Map();
|
|
236
|
+
for (const o of overrides)
|
|
237
|
+
map.set(overrideKey(o.collection, o.slug), o);
|
|
238
|
+
return map;
|
|
239
|
+
}
|
|
240
|
+
function overrideKey(collection, slug) {
|
|
241
|
+
return `${collection}\u0000${slug}`;
|
|
242
|
+
}
|
|
243
|
+
//# sourceMappingURL=mountPublicRoutes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mountPublicRoutes.js","sourceRoot":"","sources":["../../src/mount/mountPublicRoutes.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,qBAAqB,EACrB,yBAAyB,EACzB,mBAAmB,EACnB,aAAa,EACb,WAAW,EACX,UAAU,EACV,eAAe,EACf,wBAAwB,EACxB,WAAW,GAGZ,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAiFvD,MAAM,aAAa,GAAG;IACpB,cAAc,EAAE,0BAA0B;IAC1C,eAAe,EAAE,UAAU;CACnB,CAAC;AAEX,MAAM,WAAW,GAAG;IAClB,cAAc,EAAE,0BAA0B;CAClC,CAAC;AAEX,MAAM,SAAS,GAAG;IAChB,cAAc,EAAE,8BAA8B;CACtC,CAAC;AAEX,MAAM,WAAW,GAAG;IAClB,cAAc,EAAE,2BAA2B;CACnC,CAAC;AAEX,MAAM,eAAe,GAAG;IACtB,cAAc,EAAE,gCAAgC;IAChD,eAAe,EAAE,mCAAmC;CAC5C,CAAC;AAEX,MAAM,UAAU,iBAAiB,CAC/B,GAAS,EACT,GAA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AC,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,UAAU,EAAE,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;IACzE,OAAO,GAAG,CAAC;AACb,CAAC;AAED,SAAS,WAAW,CAAC,UAAkB,EAAE,IAAY;IACnD,OAAO,GAAG,UAAU,SAAS,IAAI,EAAE,CAAC;AACtC,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Hono } from "hono";
|
|
2
|
+
import type { CmsRuntimeRef } from "./bootRuntimeOnce.js";
|
|
3
|
+
/** Mount HTTP Triggers + Views + the Better Auth admin surface.
|
|
4
|
+
* HTTP Trigger bearer-token authentication is delegated to the OAuth
|
|
5
|
+
* provider lib (via `createMcpApiHandler`) — if a Trigger needs
|
|
6
|
+
* identity, route it under an MCP `apiHandler` instead of a Hono
|
|
7
|
+
* catch-all. */
|
|
8
|
+
export declare function mountServerEndpoints(app: Hono, ref: CmsRuntimeRef): void;
|
|
9
|
+
export type { CmsRuntimeRef };
|
|
10
|
+
//# sourceMappingURL=mountServerEndpoints.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mountServerEndpoints.d.ts","sourceRoot":"","sources":["../../src/mount/mountServerEndpoints.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAW,IAAI,EAAE,MAAM,MAAM,CAAC;AAsB1C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAM1D;;;;iBAIiB;AACjB,wBAAgB,oBAAoB,CAClC,GAAG,EAAE,IAAI,EACT,GAAG,EAAE,aAAa,GACjB,IAAI,CAwBN;AAgjBD,YAAY,EAAE,aAAa,EAAE,CAAC"}
|