create-ailk 0.40.0 → 0.40.2
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 +26 -4
- package/component-catalog.json +1 -1
- package/component-catalog.md +1 -1
- package/dist/add-module.d.ts +2 -1
- package/dist/add-module.js +17 -1
- package/dist/cutover.d.ts +7 -3
- package/dist/cutover.js +8 -3
- package/dist/lib/declared-env.d.ts +5 -1
- package/dist/lib/declared-env.js +6 -1
- package/dist/lib/env-catalog.d.ts +3 -2
- package/dist/lib/env-catalog.js +4 -8
- package/dist/module-architecture.js +0 -1
- package/dist/programmatic.js +18 -9
- package/dist/remove-module.js +1 -1
- package/dist/seam-refresh.d.ts +60 -0
- package/dist/seam-refresh.js +214 -0
- package/dist/spoke-checkout.d.ts +12 -3
- package/dist/spoke-checkout.js +14 -5
- package/dist/sync-routes.d.ts +10 -1
- package/dist/sync-routes.js +61 -6
- package/dist/template-record.d.ts +14 -2
- package/dist/template-record.js +60 -22
- package/dist/topology.js +3 -4
- package/dist/update.d.ts +13 -1
- package/dist/update.js +100 -8
- package/package.json +3 -3
- package/templates/.env.example +6 -0
- package/templates/.github/workflows/ci.yml +3 -0
- package/templates/apps/api/.env.example +12 -0
- package/templates/apps/api/CLAUDE.md +10 -7
- package/templates/apps/mcp/CLAUDE.md +25 -5
- package/templates/apps/web/.env.example +7 -1
- package/templates/apps/web/CLAUDE.md +40 -13
- package/templates/apps/web/app/[locale]/(authed)/account/connect/__tests__/page.test.tsx +1 -1
- package/templates/apps/web/app/[locale]/layout.tsx +41 -24
- package/templates/apps/web/app/api/revalidate/__tests__/route.test.ts +56 -1
- package/templates/apps/web/app/api/revalidate/route.ts +45 -4
- package/templates/apps/web/app/llms.txt/__tests__/site-listing.test.ts +60 -0
- package/templates/apps/web/app/llms.txt/route.ts +17 -4
- package/templates/apps/web/app/openapi.json/__tests__/route.test.ts +15 -7
- package/templates/apps/web/auth.config.tsx +2 -0
- package/templates/apps/web/auth.ts +28 -4
- package/templates/apps/web/jest.config.cjs +1 -1
- package/templates/apps/web/lib/__tests__/auth-email.test.ts +21 -0
- package/templates/apps/web/lib/__tests__/docs-path.test.ts +20 -2
- package/templates/apps/web/lib/__tests__/hub-site-config.test.ts +246 -0
- package/templates/apps/web/lib/__tests__/profile-back-link.test.ts +58 -0
- package/templates/apps/web/lib/__tests__/relay.test.ts +127 -12
- package/templates/apps/web/lib/__tests__/served-pages.test.ts +163 -20
- package/templates/apps/web/lib/__tests__/server-api.test.ts +72 -7
- package/templates/apps/web/lib/__tests__/services-path.test.ts +22 -1
- package/templates/apps/web/lib/__tests__/site-brand.test.ts +77 -0
- package/templates/apps/web/lib/__tests__/site-contact-lines.test.ts +64 -0
- package/templates/apps/web/lib/__tests__/site-identity-feature-list.test.ts +144 -4
- package/templates/apps/web/lib/auth-email.ts +19 -0
- package/templates/apps/web/lib/docs-path.ts +1 -1
- package/templates/apps/web/lib/hub-site-config.ts +154 -0
- package/templates/apps/web/lib/mcp-oauth.ts +123 -17
- package/templates/apps/web/lib/profile-back-link.ts +49 -12
- package/templates/apps/web/lib/relay.ts +48 -9
- package/templates/apps/web/lib/served-pages.ts +144 -39
- package/templates/apps/web/lib/server-api.ts +37 -4
- package/templates/apps/web/lib/services-path.ts +1 -1
- package/templates/apps/web/lib/site-brand.tsx +66 -0
- package/templates/apps/web/lib/site-contact-email.ts +24 -4
- package/templates/apps/web/lib/site-contact-lines.ts +20 -4
- package/templates/apps/web/lib/site-identity.ts +38 -2
- package/templates/apps/web/messages/en.json +13 -8
- package/templates/apps/web/middleware.ts +4 -2
- package/templates/apps/web/src/lib/routes.ts +13 -0
- package/templates/tools/declared-env.ts +6 -1
- package/versions.json +51 -51
|
@@ -36,6 +36,25 @@ function escapeRegExp(segment: string): string {
|
|
|
36
36
|
return segment.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
+
/**
|
|
40
|
+
* The page's ancestors below the home as bare (locale-less) paths, nearest
|
|
41
|
+
* first — every parent the walk may ask about (`lib/served-pages.ts` matches
|
|
42
|
+
* them against the app's dynamic page routes, #11438). None for an absent or
|
|
43
|
+
* empty pathname.
|
|
44
|
+
*/
|
|
45
|
+
export function ancestorPaths(
|
|
46
|
+
pathname: string | null | undefined,
|
|
47
|
+
locales: readonly string[],
|
|
48
|
+
): string[] {
|
|
49
|
+
if (!pathname) return [];
|
|
50
|
+
const segments = barePath(pathname, locales).split("/").filter(Boolean);
|
|
51
|
+
const ancestors: string[] = [];
|
|
52
|
+
for (let depth = segments.length - 1; depth >= 1; depth--) {
|
|
53
|
+
ancestors.push(`/${segments.slice(0, depth).join("/")}`);
|
|
54
|
+
}
|
|
55
|
+
return ancestors;
|
|
56
|
+
}
|
|
57
|
+
|
|
39
58
|
/**
|
|
40
59
|
* The page's served parent as a bare (locale-less) path, nearest first, or
|
|
41
60
|
* `null` when no ancestor below the home is served.
|
|
@@ -48,14 +67,7 @@ export function servedParent(input: {
|
|
|
48
67
|
locales: readonly string[];
|
|
49
68
|
served: (barePath: string) => boolean;
|
|
50
69
|
}): string | null {
|
|
51
|
-
|
|
52
|
-
if (!pathname) return null;
|
|
53
|
-
const segments = barePath(pathname, locales).split("/").filter(Boolean);
|
|
54
|
-
for (let depth = segments.length - 1; depth >= 1; depth--) {
|
|
55
|
-
const parent = `/${segments.slice(0, depth).join("/")}`;
|
|
56
|
-
if (served(parent)) return parent;
|
|
57
|
-
}
|
|
58
|
-
return null;
|
|
70
|
+
return ancestorPaths(input.pathname, input.locales).find((path) => input.served(path)) ?? null;
|
|
59
71
|
}
|
|
60
72
|
|
|
61
73
|
/** The arrow's server href: the served parent under the home's locale prefix, else `homePath`. */
|
|
@@ -104,20 +116,45 @@ export function navLabelsByPath(
|
|
|
104
116
|
return labels;
|
|
105
117
|
}
|
|
106
118
|
|
|
119
|
+
/** The separators a page title may join a trailing site name with. */
|
|
120
|
+
const SITE_NAME_SEPARATORS = [" — ", " | ", " - "] as const;
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* `title` without a trailing ` — <siteName>` / ` | <siteName>` /
|
|
124
|
+
* ` - <siteName>` (hub-built pages title themselves "About — Sam Henry").
|
|
125
|
+
* Only that exact trailing form is removed: the site name anywhere else, or
|
|
126
|
+
* a suffix that would leave nothing, is left alone.
|
|
127
|
+
*/
|
|
128
|
+
function stripSiteNameSuffix(title: string, siteName: string | undefined): string {
|
|
129
|
+
const name = siteName?.trim();
|
|
130
|
+
if (!name) return title;
|
|
131
|
+
for (const separator of SITE_NAME_SEPARATORS) {
|
|
132
|
+
const suffix = `${separator}${name}`;
|
|
133
|
+
if (title.endsWith(suffix) && title.length > suffix.length) {
|
|
134
|
+
return title.slice(0, -suffix.length).trim() || title;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return title;
|
|
138
|
+
}
|
|
139
|
+
|
|
107
140
|
/**
|
|
108
141
|
* The name the arrow's label gives its destination ("Back to <name>"): the
|
|
109
|
-
* parent's nav label, else its page title
|
|
110
|
-
* (`/meet` → "Meet",
|
|
111
|
-
* names where the
|
|
142
|
+
* parent's nav label, else its page title with a trailing site-name suffix
|
|
143
|
+
* removed, else its last segment in words (`/meet` → "Meet",
|
|
144
|
+
* `/case-studies` → "Case studies"), so the label always names where the
|
|
145
|
+
* link goes.
|
|
112
146
|
*/
|
|
113
147
|
export function backLinkName(
|
|
114
148
|
parent: string,
|
|
115
149
|
sources: {
|
|
116
150
|
navLabels: ReadonlyMap<string, string>;
|
|
117
151
|
titles: ReadonlyMap<string, string>;
|
|
152
|
+
siteName?: string;
|
|
118
153
|
},
|
|
119
154
|
): string {
|
|
120
|
-
const
|
|
155
|
+
const title = sources.titles.get(parent);
|
|
156
|
+
const named =
|
|
157
|
+
sources.navLabels.get(parent) || (title ? stripSiteNameSuffix(title, sources.siteName) : "");
|
|
121
158
|
if (named) return named;
|
|
122
159
|
const words = (parent.split("/").pop() ?? "").replace(/-/g, " ");
|
|
123
160
|
return words.charAt(0).toUpperCase() + words.slice(1);
|
|
@@ -16,8 +16,10 @@
|
|
|
16
16
|
*
|
|
17
17
|
* - ONLY THE LIST (D2). `RELAY_ROUTES` is the fixed set of (method, path)
|
|
18
18
|
* pairs a browser form calls; an exact, case-sensitive match on the
|
|
19
|
-
* pathname or a 404 with no hub call.
|
|
20
|
-
*
|
|
19
|
+
* pathname or a 404 with no hub call. The session route is on the list on
|
|
20
|
+
* a hub only (#8066 D2): a spoke answers it 404 with no hub call. Adding a
|
|
21
|
+
* route is a reviewed change to this list, its test and
|
|
22
|
+
* apps/web/.env.example.
|
|
21
23
|
* - NO CROSS-SITE POST (D4). `Sec-Fetch-Site` other than `same-origin`, or
|
|
22
24
|
* an `Origin` whose host is not this site's own, is refused with 403
|
|
23
25
|
* before the hub is called. A POST must be JSON, which no cross-origin
|
|
@@ -27,7 +29,9 @@
|
|
|
27
29
|
* still count each visitor (#7615's rule; `flow.actions.ts`).
|
|
28
30
|
* - AN ALLOW-LIST OF HEADERS (D3). Nothing else from the incoming request is
|
|
29
31
|
* forwarded: no `authorization`, no client-sent `x-ailk-*`, no `host`, and
|
|
30
|
-
* a `cookie` only on the one session route
|
|
32
|
+
* a `cookie` only on the one session route — and there only the hub's own
|
|
33
|
+
* Better Auth session cookie (#8066 D1), never a spoke's sealed
|
|
34
|
+
* `__Host-ailk-hub-session` or any other cookie.
|
|
31
35
|
* - A PER-VISITOR BUDGET (#7707, D1-D7). Each visitor gets 8 calls per 10
|
|
32
36
|
* minutes across the five visitor routes, and 30 per 10 minutes on the
|
|
33
37
|
* session route, counted in this instance's own in-memory store; the
|
|
@@ -58,6 +62,7 @@ import {
|
|
|
58
62
|
import { browserApiOrigin } from "./api-origin.generated";
|
|
59
63
|
import { runBotCheck } from "./bot-check";
|
|
60
64
|
import { readConsentVisitorFromCookieHeader } from "./consent-visitor";
|
|
65
|
+
import { TOPOLOGY } from "./topology.generated";
|
|
61
66
|
|
|
62
67
|
type RelayMethod = "GET" | "POST";
|
|
63
68
|
|
|
@@ -77,9 +82,10 @@ function route(method: RelayMethod, path: string): RelayRoute {
|
|
|
77
82
|
*/
|
|
78
83
|
/**
|
|
79
84
|
* The one session route: a site-admin, cookie-authenticated write. It is
|
|
80
|
-
* forwarded with the visitor's
|
|
81
|
-
* that `Origin` against its trusted list)
|
|
82
|
-
*
|
|
85
|
+
* forwarded with the visitor's Better Auth session cookie and `Origin` (the
|
|
86
|
+
* hub still checks that `Origin` against its trusted list). Every other entry
|
|
87
|
+
* is a visitor route. A hub only (#8066 D2): from a spoke the hub has no
|
|
88
|
+
* cookie session to read, and nothing a spoke renders calls it.
|
|
83
89
|
*/
|
|
84
90
|
const SESSION_ROUTE = route("POST", "/v1/commerce/invoices");
|
|
85
91
|
|
|
@@ -95,7 +101,7 @@ export const RELAY_ROUTES: readonly RelayRoute[] = Object.freeze([
|
|
|
95
101
|
CALLBACK_ROUTE,
|
|
96
102
|
route("GET", "/v1/schedule/availability"),
|
|
97
103
|
BOOK_ROUTE,
|
|
98
|
-
SESSION_ROUTE,
|
|
104
|
+
...(TOPOLOGY === "hub" ? [SESSION_ROUTE] : []),
|
|
99
105
|
]);
|
|
100
106
|
|
|
101
107
|
/**
|
|
@@ -425,6 +431,39 @@ async function readCapped(
|
|
|
425
431
|
return new TextDecoder().decode(bytes);
|
|
426
432
|
}
|
|
427
433
|
|
|
434
|
+
/**
|
|
435
|
+
* The two Better Auth session-token cookies the hub reads (#8066 D1): a copy
|
|
436
|
+
* of `COOKIE_NAMES` in packages/api/src/middleware/auth.ts, which apps/web
|
|
437
|
+
* cannot import. If that list changes, this one changes in the same PR.
|
|
438
|
+
*/
|
|
439
|
+
const BETTER_AUTH_SESSION_COOKIES: readonly string[] = [
|
|
440
|
+
"better-auth.session_token",
|
|
441
|
+
"__Secure-better-auth.session_token",
|
|
442
|
+
];
|
|
443
|
+
|
|
444
|
+
/**
|
|
445
|
+
* The one session cookie pair the session route forwards (#8066 D1), parsed
|
|
446
|
+
* by the hub's own `readSessionCookie` rules: split on `;`, the trimmed name
|
|
447
|
+
* before the first `=` matched exactly, a pair with no `=` or an empty value
|
|
448
|
+
* dropped. The first `__Secure-` pair wins over the first plain one, so a
|
|
449
|
+
* plain-named cookie, which any host can set, cannot shadow the visitor's
|
|
450
|
+
* secure one (SEC-8066-1). `__Secure-` requires only the Secure flag, not a
|
|
451
|
+
* host-only cookie, so a sibling https host can still set one.
|
|
452
|
+
* `undefined` when there is none.
|
|
453
|
+
*/
|
|
454
|
+
function sessionCookieHeader(raw: string | null): string | undefined {
|
|
455
|
+
const pairs = (raw ?? "").split(";").flatMap((part) => {
|
|
456
|
+
const eq = part.indexOf("=");
|
|
457
|
+
if (eq < 0) return [];
|
|
458
|
+
const name = part.slice(0, eq).trim();
|
|
459
|
+
const value = part.slice(eq + 1).trim();
|
|
460
|
+
return value && BETTER_AUTH_SESSION_COOKIES.includes(name)
|
|
461
|
+
? [`${name}=${value}`]
|
|
462
|
+
: [];
|
|
463
|
+
});
|
|
464
|
+
return pairs.find((pair) => pair.startsWith("__Secure-")) ?? pairs[0];
|
|
465
|
+
}
|
|
466
|
+
|
|
428
467
|
/** The outbound headers, built from an allow-list (D3). Never a spread of the incoming set. */
|
|
429
468
|
function relayHeaders(
|
|
430
469
|
request: Request,
|
|
@@ -444,8 +483,8 @@ function relayHeaders(
|
|
|
444
483
|
if (visitorIp) out["x-forwarded-for"] = visitorIp;
|
|
445
484
|
|
|
446
485
|
if (entry === SESSION_ROUTE) {
|
|
447
|
-
const
|
|
448
|
-
if (
|
|
486
|
+
const sessionCookie = sessionCookieHeader(incoming.get("cookie"));
|
|
487
|
+
if (sessionCookie) out.cookie = sessionCookie;
|
|
449
488
|
const origin = incoming.get("origin");
|
|
450
489
|
if (origin) out.origin = origin;
|
|
451
490
|
} else {
|
|
@@ -8,20 +8,28 @@
|
|
|
8
8
|
* (`app/sitemap.xml/route.ts`: `listPages` per type, `listedPath` over
|
|
9
9
|
* the site's listing, docs rows and `ThankYouPage` left out). Title =
|
|
10
10
|
* the page's frontmatter `title`.
|
|
11
|
-
* 2. Every
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* route
|
|
11
|
+
* 2. Every page route the app builds (#11438) — its page files under
|
|
12
|
+
* `app/`, and Next's app-path routes manifest where those files are not
|
|
13
|
+
* deployed — whatever module or site file put it there. No title. A
|
|
14
|
+
* route with no dynamic segment is a served path in itself; one with a
|
|
15
|
+
* dynamic segment (`[slug]`) serves the candidates the caller asks about
|
|
16
|
+
* that it matches, so `/flows/<slug>` counts under its start page. An
|
|
17
|
+
* optional catch-all serves its own index only; a required catch-all,
|
|
18
|
+
* and a route of dynamic segments alone (the content catch-all), serve
|
|
19
|
+
* nothing.
|
|
20
|
+
* A route with seed content (a `ROUTES` row with a `contentPath`) counts only
|
|
21
|
+
* through source 1, so a scaffold that dropped that surface's content never
|
|
22
|
+
* gets a link to a missing page. The layout adds the nav and footer paths
|
|
23
|
+
* itself (every nav entry is a route the site carries — `lib/nav-config.ts`).
|
|
19
24
|
*
|
|
20
25
|
* Shared per server instance for 60 seconds per locale, and fail-safe: any
|
|
21
26
|
* read that throws leaves that source out, so the arrow degrades toward the
|
|
22
27
|
* home, never to an error.
|
|
23
28
|
*/
|
|
24
29
|
|
|
30
|
+
import { readdirSync, readFileSync } from "node:fs";
|
|
31
|
+
import { join } from "node:path";
|
|
32
|
+
|
|
25
33
|
import { SCHEMA_ORG_TYPES } from "@working-theory/content-adapters";
|
|
26
34
|
import type { SchemaOrgType } from "@working-theory/content-adapters";
|
|
27
35
|
import { getContentAdapter, listedPath } from "@working-theory/page-renderer";
|
|
@@ -30,36 +38,120 @@ import { ROUTES } from "@working-theory/templates/routes";
|
|
|
30
38
|
import { pagePathFor } from "../src/lib/routes";
|
|
31
39
|
|
|
32
40
|
import { isDocsType } from "./docs-index";
|
|
33
|
-
import {
|
|
34
|
-
DOCS_BLOG_PAGES,
|
|
35
|
-
MARKETING_PAGES,
|
|
36
|
-
SCHEDULING_PAGES,
|
|
37
|
-
} from "./modules.generated";
|
|
38
41
|
import { SITE_LISTING } from "./site-listing";
|
|
39
42
|
|
|
40
43
|
const TTL_MS = 60_000;
|
|
41
44
|
|
|
42
|
-
/** The
|
|
43
|
-
const
|
|
44
|
-
marketing: MARKETING_PAGES,
|
|
45
|
-
scheduling: SCHEDULING_PAGES,
|
|
46
|
-
"docs-blog": DOCS_BLOG_PAGES,
|
|
47
|
-
};
|
|
45
|
+
/** The app's locale segment, under which every site page route sits. */
|
|
46
|
+
const LOCALE_SEGMENT = "[locale]";
|
|
48
47
|
|
|
49
|
-
const
|
|
50
|
-
string,
|
|
51
|
-
{ at: number; pages: Promise<ReadonlyMap<string, string>> }
|
|
52
|
-
>();
|
|
48
|
+
const PAGE_FILE = /^page\.(?:tsx|ts|jsx|js|mdx)$/;
|
|
53
49
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
50
|
+
interface ServedSet {
|
|
51
|
+
/** Bare path → title for every served path. */
|
|
52
|
+
pages: ReadonlyMap<string, string>;
|
|
53
|
+
/** The built routes with a dynamic segment, as segments. */
|
|
54
|
+
dynamic: readonly (readonly string[])[];
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const cache = new Map<string, { at: number; served: Promise<ServedSet> }>();
|
|
58
|
+
|
|
59
|
+
function isDynamic(segment: string): boolean {
|
|
60
|
+
return segment.startsWith("[") || segment.startsWith(":");
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** A route's shape: its segments, every dynamic one as `*`, whatever its name. */
|
|
64
|
+
function shape(segments: readonly string[]): string {
|
|
65
|
+
return segments.map((segment) => (isDynamic(segment) ? "*" : segment)).join("/");
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** The shapes of the routes whose pages render seed content. */
|
|
69
|
+
const CONTENT_SHAPES = new Set(
|
|
70
|
+
ROUTES.filter((row) => row.contentPath !== undefined).map((row) =>
|
|
71
|
+
shape(row.route.split("/").filter(Boolean)),
|
|
72
|
+
),
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
/** Every page route under `dir`, from its page files, route groups dropped. */
|
|
76
|
+
function pageFileRoutes(dir: string, route = ""): string[] {
|
|
77
|
+
const routes: string[] = [];
|
|
78
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
79
|
+
if (entry.isFile() && PAGE_FILE.test(entry.name)) routes.push(route);
|
|
80
|
+
// `_private` folders and `@slot`s are not URL segments; a `(group)` adds none.
|
|
81
|
+
if (!entry.isDirectory() || /^[_@]/.test(entry.name)) continue;
|
|
82
|
+
const segment = /^\(.*\)$/.test(entry.name) ? "" : `/${entry.name}`;
|
|
83
|
+
routes.push(...pageFileRoutes(join(dir, entry.name), route + segment));
|
|
84
|
+
}
|
|
85
|
+
return routes;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** Every page route in Next's app-path routes manifest (route handlers left out). */
|
|
89
|
+
function manifestRoutes(root: string): string[] {
|
|
90
|
+
const distDir = process.env.__NEXT_RELATIVE_DIST_DIR || ".next";
|
|
91
|
+
const manifest: unknown = JSON.parse(
|
|
92
|
+
readFileSync(join(root, distDir, "app-path-routes-manifest.json"), "utf8"),
|
|
93
|
+
);
|
|
94
|
+
if (typeof manifest !== "object" || manifest === null) return [];
|
|
95
|
+
return Object.entries(manifest)
|
|
96
|
+
.filter(([entry, route]) => entry.endsWith("/page") && typeof route === "string")
|
|
97
|
+
.map(([, route]) => route as string);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function readSafely(read: () => string[]): string[] {
|
|
101
|
+
try {
|
|
102
|
+
return read();
|
|
103
|
+
} catch {
|
|
104
|
+
return [];
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* The page routes the app builds, as locale-less segments: an optional
|
|
110
|
+
* catch-all's index kept, a required catch-all, a route of dynamic segments
|
|
111
|
+
* alone, the home and every seed-content route left out.
|
|
112
|
+
*/
|
|
113
|
+
function builtRoutes(): string[][] {
|
|
114
|
+
const root = process.cwd();
|
|
115
|
+
const routes = new Set([
|
|
116
|
+
...readSafely(() => pageFileRoutes(join(root, "app"))),
|
|
117
|
+
...readSafely(() => manifestRoutes(root)),
|
|
118
|
+
]);
|
|
119
|
+
if (routes.size === 0) {
|
|
120
|
+
// Neither the page files nor the manifest could be read: every code
|
|
121
|
+
// route's arrow falls through to home, so say so once per read.
|
|
122
|
+
console.warn("[served-pages] no page route of the app could be read; the back arrow sees content pages only");
|
|
123
|
+
}
|
|
124
|
+
const built: string[][] = [];
|
|
125
|
+
for (const route of routes) {
|
|
126
|
+
const segments = route.split("/").filter(Boolean);
|
|
127
|
+
// A `_private` segment is never a URL; the walk skips such folders, and
|
|
128
|
+
// the manifest's own entries (`/_not-found`) start with one too.
|
|
129
|
+
if (segments.some((segment) => segment.startsWith("_"))) continue;
|
|
130
|
+
if (segments[0] === LOCALE_SEGMENT) segments.shift();
|
|
131
|
+
if (segments[segments.length - 1]?.startsWith("[[...")) segments.pop();
|
|
132
|
+
if (segments.some((segment) => segment.startsWith("[..."))) continue;
|
|
133
|
+
if (segments.every(isDynamic)) continue;
|
|
134
|
+
if (CONTENT_SHAPES.has(shape(segments))) continue;
|
|
135
|
+
built.push(segments);
|
|
136
|
+
}
|
|
137
|
+
return built;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function matches(route: readonly string[], path: string): boolean {
|
|
141
|
+
const segments = path.split("/").filter(Boolean);
|
|
142
|
+
return (
|
|
143
|
+
segments.length === route.length &&
|
|
144
|
+
route.every((segment, i) => isDynamic(segment) || segment === segments[i])
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
async function readServedSet(locale: string): Promise<ServedSet> {
|
|
57
149
|
const pages = new Map<string, string>();
|
|
150
|
+
const dynamic: string[][] = [];
|
|
58
151
|
|
|
59
|
-
for (const
|
|
60
|
-
if (
|
|
61
|
-
|
|
62
|
-
pages.set(row.route, "");
|
|
152
|
+
for (const route of builtRoutes()) {
|
|
153
|
+
if (route.some(isDynamic)) dynamic.push(route);
|
|
154
|
+
else pages.set(`/${route.join("/")}`, "");
|
|
63
155
|
}
|
|
64
156
|
|
|
65
157
|
try {
|
|
@@ -76,20 +168,33 @@ async function readServedPages(
|
|
|
76
168
|
}
|
|
77
169
|
}
|
|
78
170
|
} catch {
|
|
79
|
-
// No adapter: the
|
|
171
|
+
// No adapter: the built page routes alone.
|
|
80
172
|
}
|
|
81
173
|
|
|
82
|
-
return pages;
|
|
174
|
+
return { pages, dynamic };
|
|
83
175
|
}
|
|
84
176
|
|
|
85
|
-
/**
|
|
86
|
-
|
|
177
|
+
/**
|
|
178
|
+
* Bare path → title ("" when the page has none) for every page served in
|
|
179
|
+
* `locale`, plus each of `candidates` (bare paths — the page's ancestors,
|
|
180
|
+
* `ancestorPaths`) that a built dynamic route serves.
|
|
181
|
+
*/
|
|
182
|
+
export async function servedPages(
|
|
87
183
|
locale: string,
|
|
184
|
+
candidates: readonly string[] = [],
|
|
88
185
|
): Promise<ReadonlyMap<string, string>> {
|
|
89
186
|
const now = Date.now();
|
|
90
|
-
|
|
91
|
-
if (hit
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
187
|
+
let hit = cache.get(locale);
|
|
188
|
+
if (!hit || now - hit.at >= TTL_MS) {
|
|
189
|
+
hit = { at: now, served: readServedSet(locale) };
|
|
190
|
+
cache.set(locale, hit);
|
|
191
|
+
}
|
|
192
|
+
const { pages, dynamic } = await hit.served;
|
|
193
|
+
const matched = candidates.filter(
|
|
194
|
+
(path) => !pages.has(path) && dynamic.some((route) => matches(route, path)),
|
|
195
|
+
);
|
|
196
|
+
if (matched.length === 0) return pages;
|
|
197
|
+
const withMatched = new Map(pages);
|
|
198
|
+
for (const path of matched) withMatched.set(path, "");
|
|
199
|
+
return withMatched;
|
|
95
200
|
}
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
* Server-side (RSC) helper for reading the operator-dashboard read API
|
|
3
3
|
* (#4665 D9).
|
|
4
4
|
*
|
|
5
|
-
* Forwards the incoming request's
|
|
5
|
+
* Forwards the incoming request's Better Auth session cookie — only that one
|
|
6
|
+
* cookie, the `__Secure-` name first (#8089) — to `@working-theory/api-client`'s
|
|
6
7
|
* `waitlistExperiments` / `workspace` namespaces (B0, #4671; #5371) so
|
|
7
8
|
* `apps/api`'s cookie-session auth preHandler resolves the SAME Better Auth
|
|
8
9
|
* session the browser holds — both apps share the session store. Every page
|
|
@@ -64,8 +65,40 @@ interface ErrorBody {
|
|
|
64
65
|
}
|
|
65
66
|
|
|
66
67
|
/**
|
|
67
|
-
*
|
|
68
|
-
*
|
|
68
|
+
* The two Better Auth session-token cookies the API reads, secure name first
|
|
69
|
+
* (#8089 D1): a copy of `COOKIE_NAMES` in packages/api/src/middleware/auth.ts,
|
|
70
|
+
* which apps/web cannot import. If that list changes, this one changes in the
|
|
71
|
+
* same PR.
|
|
72
|
+
*/
|
|
73
|
+
const BETTER_AUTH_SESSION_COOKIES = [
|
|
74
|
+
"__Secure-better-auth.session_token",
|
|
75
|
+
"better-auth.session_token",
|
|
76
|
+
] as const;
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* The one session cookie pair to forward. It parses by the API's own
|
|
80
|
+
* `readSessionCookie` rules — split on `;`, the trimmed name before the first
|
|
81
|
+
* `=` matched exactly, a pair with no `=` or an empty value skipped — but,
|
|
82
|
+
* unlike that reader, picks by allow-list order rather than header order: a
|
|
83
|
+
* `__Secure-` cookie needs a secure origin to be set, so an http origin
|
|
84
|
+
* cannot plant one to stand in for the visitor's. `""` when there is none.
|
|
85
|
+
*/
|
|
86
|
+
function sessionCookiePair(jar: string): string {
|
|
87
|
+
const values = new Map<string, string>();
|
|
88
|
+
for (const part of jar.split(";")) {
|
|
89
|
+
const eq = part.indexOf("=");
|
|
90
|
+
if (eq < 0) continue;
|
|
91
|
+
const value = part.slice(eq + 1).trim();
|
|
92
|
+
if (value) values.set(part.slice(0, eq).trim(), value);
|
|
93
|
+
}
|
|
94
|
+
const name = BETTER_AUTH_SESSION_COOKIES.find((n) => values.has(n));
|
|
95
|
+
return name ? `${name}=${values.get(name)}` : "";
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Forward the incoming request's Better Auth session cookie (only it, #8089)
|
|
100
|
+
* — and, when present, its `Origin` — as the `init` every
|
|
101
|
+
* `waitlistExperiments.*` / `workspace.*` call accepts.
|
|
69
102
|
* Call once per request — `cookies()` / `headers()` read the current RSC
|
|
70
103
|
* request context.
|
|
71
104
|
*
|
|
@@ -89,7 +122,7 @@ export async function forwardedCookieInit(): Promise<{
|
|
|
89
122
|
headers: Record<string, string>;
|
|
90
123
|
}> {
|
|
91
124
|
if (SIGN_IN_PROVIDER === "hub") return hubSessionInit();
|
|
92
|
-
const cookieHeader = (await cookies()).toString();
|
|
125
|
+
const cookieHeader = sessionCookiePair((await cookies()).toString());
|
|
93
126
|
const origin = (await headers()).get("origin");
|
|
94
127
|
return { headers: { cookie: cookieHeader, ...(origin ? { origin } : {}) } };
|
|
95
128
|
}
|
|
@@ -25,6 +25,13 @@
|
|
|
25
25
|
* the agent-operator editing workflow — disproportionate for reading two
|
|
26
26
|
* fields. See docs/specs/4157-scaffold-brand-defaults-spec.md § Design
|
|
27
27
|
* Decisions (D1) for the full reasoning.
|
|
28
|
+
*
|
|
29
|
+
* #11456 D4 — on a hub-connected site the hub holds the brand: the async
|
|
30
|
+
* `resolveSiteBrand()` answers the hub identity's name, description and legal
|
|
31
|
+
* name, and the seo row's indexing switch, read per request through
|
|
32
|
+
* `lib/hub-site-config.ts`. The constants below are unchanged and are what it
|
|
33
|
+
* answers when there is no hub identity row, a failed read, or no hub
|
|
34
|
+
* connection.
|
|
28
35
|
*/
|
|
29
36
|
|
|
30
37
|
import { existsSync, readFileSync } from "node:fs";
|
|
@@ -32,6 +39,8 @@ import { join } from "node:path";
|
|
|
32
39
|
|
|
33
40
|
import { parse as parseYaml } from "yaml";
|
|
34
41
|
|
|
42
|
+
import { readHubSite, type HubSite } from "./hub-site-config";
|
|
43
|
+
|
|
35
44
|
/** Neutral, non-vendor fallback — see module doc comment point 3. */
|
|
36
45
|
export const FALLBACK_SITE_NAME = "My Site";
|
|
37
46
|
/** Neutral, non-vendor fallback — see module doc comment point 3. */
|
|
@@ -154,3 +163,60 @@ export const COPYRIGHT_HOLDER = siteFrontmatter?.legalName ?? SITE_NAME;
|
|
|
154
163
|
* `SITE_BASE_URL` for the routes that read only those.
|
|
155
164
|
*/
|
|
156
165
|
export const SITE_LOGOMARK: unknown = siteFrontmatter?.logomark;
|
|
166
|
+
|
|
167
|
+
/** The brand the locale layout and both llms.txt routes render (#11456 D4). */
|
|
168
|
+
export interface SiteBrand {
|
|
169
|
+
siteName: string;
|
|
170
|
+
description: string;
|
|
171
|
+
copyrightHolder: string;
|
|
172
|
+
/** False when the hub's seo row turns search indexing off (`robots.index: false`). */
|
|
173
|
+
indexable: boolean;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* A hub value as one line: every run of control, format (bidi overrides,
|
|
178
|
+
* zero-width characters), line-separator and paragraph-separator characters
|
|
179
|
+
* becomes one space (SEC-11456-5). A hub value is written by any member
|
|
180
|
+
* holding `workspace-settings`, and lands in the plain-text llms.txt heading,
|
|
181
|
+
* where a newline would add lines.
|
|
182
|
+
*/
|
|
183
|
+
function oneLine(value: string): string {
|
|
184
|
+
return value.replace(/[\p{Cc}\p{Cf}\p{Zl}\p{Zp}]+/gu, " ").trim();
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* The site's brand for this request (#11456 D4). With a hub identity row, that
|
|
189
|
+
* row is the whole identity: a field the operator cleared is absent, never
|
|
190
|
+
* refilled from `_site.mdx` — `siteName` is `NEXT_PUBLIC_SITE_NAME`, else the
|
|
191
|
+
* hub `name`; `description` the hub's, else the seo row's, else the neutral
|
|
192
|
+
* fallback; `copyrightHolder` the hub `legalName`, else the hub `siteName`.
|
|
193
|
+
* Otherwise the module's constants, exactly. `indexable` reads the seo row
|
|
194
|
+
* whether or not an identity row exists, and fails open. Never rejects.
|
|
195
|
+
*/
|
|
196
|
+
export async function resolveSiteBrand(): Promise<SiteBrand> {
|
|
197
|
+
return brandFrom(await readHubSite());
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/** `resolveSiteBrand`'s rule over one hub read, so a caller holding the read derives the same brand. */
|
|
201
|
+
export function brandFrom(hub: HubSite | undefined): SiteBrand {
|
|
202
|
+
const indexable = hub?.seo?.robots?.index !== false;
|
|
203
|
+
const identity = hub?.identity;
|
|
204
|
+
if (!identity) {
|
|
205
|
+
return {
|
|
206
|
+
siteName: SITE_NAME,
|
|
207
|
+
description: SITE_DESCRIPTION,
|
|
208
|
+
copyrightHolder: COPYRIGHT_HOLDER,
|
|
209
|
+
indexable,
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
const siteName =
|
|
213
|
+
oneLine(process.env.NEXT_PUBLIC_SITE_NAME ?? identity.name) || FALLBACK_SITE_NAME;
|
|
214
|
+
return {
|
|
215
|
+
siteName,
|
|
216
|
+
description:
|
|
217
|
+
oneLine(identity.description ?? hub.seo?.description ?? "") ||
|
|
218
|
+
FALLBACK_SITE_DESCRIPTION,
|
|
219
|
+
copyrightHolder: oneLine(identity.legalName ?? "") || siteName,
|
|
220
|
+
indexable,
|
|
221
|
+
};
|
|
222
|
+
}
|
|
@@ -13,14 +13,25 @@
|
|
|
13
13
|
* the client-safe `/schema` entry. Any failure (no file, no frontmatter, an
|
|
14
14
|
* invalid address) is `undefined`: the fallback then says the site has
|
|
15
15
|
* published no contact details, which is true.
|
|
16
|
+
*
|
|
17
|
+
* #11456 D4 — on a hub-connected site that holds a hub identity row, the
|
|
18
|
+
* row's `email` (when valid) comes first, else the file's top-level
|
|
19
|
+
* `contactEmail` (not an identity field, so it stays the fallback). It reads
|
|
20
|
+
* the value `readHubSite` last resolved on this instance (`heldHubSite()`),
|
|
21
|
+
* because the seam is synchronous: the file value on a cold instance's first
|
|
22
|
+
* render.
|
|
16
23
|
*/
|
|
17
24
|
|
|
18
25
|
import { readFileSync } from "node:fs";
|
|
19
26
|
import { join } from "node:path";
|
|
20
27
|
|
|
21
|
-
import {
|
|
28
|
+
import {
|
|
29
|
+
SiteConfigSchema,
|
|
30
|
+
type SiteIdentity,
|
|
31
|
+
} from "@working-theory/site-config/schema";
|
|
22
32
|
import { parse as parseYaml } from "yaml";
|
|
23
33
|
|
|
34
|
+
import { heldHubSite } from "./hub-site-config";
|
|
24
35
|
import { resolveContentRoot } from "./site-brand";
|
|
25
36
|
|
|
26
37
|
const FRONTMATTER_RE = /^---\r?\n([\s\S]*?)\r?\n---/;
|
|
@@ -32,23 +43,32 @@ function validEmail(value: unknown): string | undefined {
|
|
|
32
43
|
return parsed.success ? parsed.data : undefined;
|
|
33
44
|
}
|
|
34
45
|
|
|
46
|
+
/** The hub identity's `email`, when the identity kind carries one. */
|
|
47
|
+
function hubIdentityEmail(identity: SiteIdentity): string | undefined {
|
|
48
|
+
return "email" in identity ? validEmail(identity.email) : undefined;
|
|
49
|
+
}
|
|
50
|
+
|
|
35
51
|
export function readSiteContactEmail(): string | undefined {
|
|
52
|
+
const hubIdentity = heldHubSite()?.identity;
|
|
53
|
+
// With a hub identity row, every file failure still answers its email.
|
|
54
|
+
const hubEmail = hubIdentity ? hubIdentityEmail(hubIdentity) : undefined;
|
|
36
55
|
try {
|
|
37
56
|
const raw = readFileSync(join(resolveContentRoot(), "_site.mdx"), "utf8");
|
|
38
57
|
const match = FRONTMATTER_RE.exec(raw);
|
|
39
|
-
if (!match) return
|
|
58
|
+
if (!match) return hubEmail;
|
|
40
59
|
const fm: unknown = parseYaml(match[1] ?? "");
|
|
41
|
-
if (!fm || typeof fm !== "object") return
|
|
60
|
+
if (!fm || typeof fm !== "object") return hubEmail;
|
|
42
61
|
|
|
43
62
|
const { contactEmail, siteIdentity } = fm as {
|
|
44
63
|
contactEmail?: unknown;
|
|
45
64
|
siteIdentity?: { kind?: unknown; email?: unknown };
|
|
46
65
|
};
|
|
66
|
+
if (hubIdentity) return hubEmail ?? validEmail(contactEmail);
|
|
47
67
|
return (
|
|
48
68
|
validEmail(contactEmail) ??
|
|
49
69
|
(siteIdentity?.kind === "LocalBusiness" ? validEmail(siteIdentity.email) : undefined)
|
|
50
70
|
);
|
|
51
71
|
} catch {
|
|
52
|
-
return
|
|
72
|
+
return hubEmail;
|
|
53
73
|
}
|
|
54
74
|
}
|