@rsc-kit/core 0.38.0 → 0.39.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/edgeShells.d.ts +2 -2
- package/dist/edgeShells.js +15 -2
- package/dist/edgeShells.js.map +1 -1
- package/dist/host.js +10 -3
- package/dist/host.js.map +1 -1
- package/dist/hostRouting.d.ts +4 -2
- package/dist/hostRouting.js +10 -7
- package/dist/hostRouting.js.map +1 -1
- package/dist/js/navigate.js +6 -1
- package/dist/js/navigate.js.map +1 -1
- package/dist/manifest.d.ts +6 -0
- package/dist/manifest.js.map +1 -1
- package/dist/pageCache.js +9 -1
- package/dist/pageCache.js.map +1 -1
- package/dist/purge.d.ts +9 -0
- package/dist/purge.js +24 -0
- package/dist/purge.js.map +1 -1
- package/dist/request.d.ts +9 -0
- package/dist/request.js +20 -0
- package/dist/request.js.map +1 -1
- package/dist/vite.d.ts +21 -0
- package/dist/vite.js +43 -7
- package/dist/vite.js.map +1 -1
- package/package.json +1 -1
package/dist/edgeShells.d.ts
CHANGED
|
@@ -52,7 +52,7 @@ export interface ShellRoute {
|
|
|
52
52
|
export declare function edgeShells(results: readonly {
|
|
53
53
|
type: string;
|
|
54
54
|
component: string;
|
|
55
|
-
}[], routes: readonly ShellRoute[]): {
|
|
55
|
+
}[], routes: readonly ShellRoute[], subdomains?: readonly string[]): {
|
|
56
56
|
shells: string[];
|
|
57
57
|
left: string[];
|
|
58
58
|
};
|
|
@@ -70,7 +70,7 @@ export declare function edgeStatic(results: readonly {
|
|
|
70
70
|
type: string;
|
|
71
71
|
component: string;
|
|
72
72
|
url: string;
|
|
73
|
-
}[], routes: readonly ShellRoute[], shells: readonly string[]): {
|
|
73
|
+
}[], routes: readonly ShellRoute[], shells: readonly string[], subdomains?: readonly string[]): {
|
|
74
74
|
static: string[];
|
|
75
75
|
left: string[];
|
|
76
76
|
};
|
package/dist/edgeShells.js
CHANGED
|
@@ -45,7 +45,7 @@ export function edgeMarker(build, shells, statics, nonceShells) {
|
|
|
45
45
|
* `[...name]` for one or more - and what was left out of the list, and why,
|
|
46
46
|
* for the build to say.
|
|
47
47
|
*/
|
|
48
|
-
export function edgeShells(results, routes) {
|
|
48
|
+
export function edgeShells(results, routes, subdomains = []) {
|
|
49
49
|
const byComponent = new Map(routes.map((route) => [route.component, route]));
|
|
50
50
|
const shells = [];
|
|
51
51
|
const left = [];
|
|
@@ -59,6 +59,8 @@ export function edgeShells(results, routes) {
|
|
|
59
59
|
// same pattern would match every tenant's page on every domain.
|
|
60
60
|
if (route.segments.some((segment) => segment.type === 'host'))
|
|
61
61
|
continue;
|
|
62
|
+
if (onSubdomain(route, subdomains))
|
|
63
|
+
continue;
|
|
62
64
|
const pattern = patternOf(route.segments);
|
|
63
65
|
if (pattern === null)
|
|
64
66
|
continue;
|
|
@@ -80,6 +82,15 @@ export function edgeShells(results, routes) {
|
|
|
80
82
|
shells.sort();
|
|
81
83
|
return { shells, left };
|
|
82
84
|
}
|
|
85
|
+
/**
|
|
86
|
+
* Under a folder rscKit({ subdomains }) serves on its own host. An edge
|
|
87
|
+
* answers by path, so it would answer example.com/merchant/orders itself and
|
|
88
|
+
* skip the 301 to merchant.example.com - and a pattern cannot say the host.
|
|
89
|
+
*/
|
|
90
|
+
function onSubdomain(route, subdomains) {
|
|
91
|
+
const first = route.segments.find((segment) => segment.type !== 'host');
|
|
92
|
+
return first?.type === 'static' && subdomains.includes(first.value);
|
|
93
|
+
}
|
|
83
94
|
/**
|
|
84
95
|
* A route's segments as the edge matches them, or null when it cannot: a
|
|
85
96
|
* catch-all anywhere but last, or a name that is itself bracketed - an
|
|
@@ -119,7 +130,7 @@ function depth(pattern) {
|
|
|
119
130
|
* A path a listed shell's pattern also matches is left out, so no path is
|
|
120
131
|
* two things to the edge.
|
|
121
132
|
*/
|
|
122
|
-
export function edgeStatic(results, routes, shells) {
|
|
133
|
+
export function edgeStatic(results, routes, shells, subdomains = []) {
|
|
123
134
|
const byComponent = new Map(routes.map((route) => [route.component, route]));
|
|
124
135
|
const statics = [];
|
|
125
136
|
const left = [];
|
|
@@ -133,6 +144,8 @@ export function edgeStatic(results, routes, shells) {
|
|
|
133
144
|
continue;
|
|
134
145
|
if (route.segments.some((segment) => segment.type === 'host'))
|
|
135
146
|
continue;
|
|
147
|
+
if (onSubdomain(route, subdomains))
|
|
148
|
+
continue;
|
|
136
149
|
const path = contractPath(result.url);
|
|
137
150
|
if (path === null)
|
|
138
151
|
continue;
|
package/dist/edgeShells.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"edgeShells.js","sourceRoot":"","sources":["../src/edgeShells.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAIH,sDAAsD;AACtD,MAAM,CAAC,MAAM,UAAU,GAAG,GAAG,CAAA;AAC7B,MAAM,CAAC,MAAM,eAAe,GAAG,GAAG,CAAA;AAClC,8DAA8D;AAC9D,MAAM,CAAC,MAAM,UAAU,GAAG,GAAG,CAAA;AAE7B;;;;;GAKG;AACH,MAAM,UAAU,UAAU,CAAC,KAAa,EAAE,MAAgB,EAAE,OAAiB,EAAE,WAAsB;IACnG,OAAO;QACL,CAAC,EAAE,CAAC;QACJ,KAAK;QACL,MAAM;QACN,MAAM,EAAE,OAAO;QACf,2EAA2E;QAC3E,wEAAwE;QACxE,2EAA2E;QAC3E,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACvC,MAAM,EAAE,EAAE,OAAO,EAAE,CAAC,OAAO,CAAC,EAAE;KAC/B,CAAA;AACH,CAAC;AASD;;;;GAIG;AACH,MAAM,UAAU,UAAU,CACxB,OAAuD,EACvD,MAA6B;IAE7B,MAAM,WAAW,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,SAAS,EAAE,KAAK,CAAC,CA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CAAC,MAAM,GAAG,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;QACxD,CAAC;QAED,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,SAAS;YAAE,OAAO,KAAK,CAAA;QACvC,IAAI,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC;YAAE,OAAO,KAAK,CAAA;IAC7E,CAAC;IAED,OAAO,IAAI,CAAC,MAAM,KAAK,IAAI,CAAC,MAAM,CAAA;AACpC,CAAC","sourcesContent":["/**\n * The pages an edge may serve without the app, for `.output/edge.json` - the\n * marker of the edge contract, which an edge reads the same way for every\n * framework that implements it: `shells`, the url patterns of the PPR pages\n * it may answer from a cached shell, and `static`, the paths of the pages it\n * may answer whole.\n *\n * An edge in front of the app asks one question of each request - may I\n * answer this? - and answers it from a list it was handed at deploy time. Reading\n * `rsc-static/` for it does not work: a guarded page has a shell on disk too,\n * served from a cache it skips its guard; `_team_` cannot say whether it was a\n * parameter or a folder of that name; and the layout is ours to change.\n *\n * So the list is the build's, by the same rule the page endpoint applies: a\n * page with a shell, on a route with no middleware - neither a `middleware.ts`\n * above it nor the host's `export const middleware`. The endpoint refuses\n * exactly those, so the list and the origin cannot disagree.\n */\n\nimport type { RouteSegment } from './manifest.js'\n\n/** What an edge is promised, and what it can hold. */\nexport const MAX_SHELLS = 200\nexport const MAX_SHELL_BYTES = 200\n/** The same again for `static`, on top of `shells`' count. */\nexport const MAX_STATIC = 200\n\n/**\n * The marker. `bypass` names this framework's own requests on a page's path\n * that are not a visitor's document: every payload fetch - a navigation, a\n * prefetch, a refresh - carries X-RSC, and an action is a POST, which an edge\n * never answers from a shell anyway.\n */\nexport function edgeMarker(build: string, shells: string[], statics: string[], nonceShells?: string[]) {\n return {\n v: 2,\n build,\n shells,\n static: statics,\n // Under a Content-Security-Policy: shells whose holes need a nonce, for an\n // edge that mints one (Edge-Accept: nonce). An edge that does not reads\n // only `shells`, which is then empty, and sends these pages to the origin.\n ...(nonceShells ? { nonceShells } : {}),\n bypass: { headers: ['X-RSC'] },\n }\n}\n\nexport interface ShellRoute {\n component: string\n segments: RouteSegment[]\n middleware?: readonly string[]\n hostMiddleware?: readonly string[]\n}\n\n/**\n * The patterns, `/` for the index, `[name]` for one segment and a final\n * `[...name]` for one or more - and what was left out of the list, and why,\n * for the build to say.\n */\nexport function edgeShells(\n results: readonly { type: string; component: string }[],\n routes: readonly ShellRoute[],\n): { shells: string[]; left: string[] } {\n const byComponent = new Map(routes.map((route) => [route.component, route]))\n const shells: string[] = []\n const left: string[] = []\n\n for (const component of new Set(results.filter((r) => r.type === 'shell').map((r) => r.component))) {\n const route = byComponent.get(component)\n\n if (!route) continue\n if (route.middleware?.length || route.hostMiddleware?.length) continue\n\n // Bound from the request's host, which a path pattern cannot say: the\n // same pattern would match every tenant's page on every domain.\n if (route.segments.some((segment) => segment.type === 'host')) continue\n\n const pattern = patternOf(route.segments)\n\n if (pattern === null) continue\n\n if (new TextEncoder().encode(pattern).length > MAX_SHELL_BYTES) {\n left.push(`${pattern.slice(0, 60)}… is over ${MAX_SHELL_BYTES} bytes`)\n continue\n }\n\n if (!shells.includes(pattern)) shells.push(pattern)\n }\n\n // Over the cap, the deepest are the ones not listed: an edge that does not\n // know a page is a PPR page sends it to the origin, which answers it\n // correctly, and the shallow pages are the ones most visited.\n if (shells.length > MAX_SHELLS) {\n shells.sort((a, b) => depth(a) - depth(b) || (a < b ? -1 : 1))\n left.push(`${shells.length - MAX_SHELLS} past the shallowest ${MAX_SHELLS}`)\n shells.length = MAX_SHELLS\n }\n\n shells.sort()\n\n return { shells, left }\n}\n\n/**\n * A route's segments as the edge matches them, or null when it cannot: a\n * catch-all anywhere but last, or a name that is itself bracketed - an\n * optional catch-all, `[[...name]]`, matches no url at all.\n */\nfunction patternOf(segments: readonly RouteSegment[]): string | null {\n const parts: string[] = []\n\n for (const [index, segment] of segments.entries()) {\n // Not a path an edge can match: the contract has no empty, `.` or `..`\n // segment, and a name with a slash would be two.\n if (['', '.', '..'].includes(segment.value) || segment.value.includes('/')) return null\n if (segment.type === 'static') parts.push(segment.value)\n else if (segment.value.includes('[') || segment.value.includes(']')) return null\n else if (segment.type === 'catchAll') {\n if (index !== segments.length - 1) return null\n parts.push(`[...${segment.value}]`)\n } else parts.push(`[${segment.value}]`)\n }\n\n return '/' + parts.join('/')\n}\n\nfunction depth(pattern: string): number {\n return pattern === '/' ? 0 : pattern.split('/').length - 1\n}\n\n/**\n * The pages an edge may answer whole: frozen, so the document is the same for\n * every visitor until the next build, with no guard of either kind and not\n * bound from the host - and listed as the paths the build rendered, since\n * `static` takes no patterns: a pattern would ask the edge for paths that\n * were never rendered. A frozen redirect is not here: it has no document.\n *\n * A path a listed shell's pattern also matches is left out, so no path is\n * two things to the edge.\n */\nexport function edgeStatic(\n results: readonly { type: string; component: string; url: string }[],\n routes: readonly ShellRoute[],\n shells: readonly string[],\n): { static: string[]; left: string[] } {\n const byComponent = new Map(routes.map((route) => [route.component, route]))\n const statics: string[] = []\n const left: string[] = []\n\n for (const result of results) {\n if (result.type !== 'frozen') continue\n\n const route = byComponent.get(result.component)\n\n if (!route) continue\n if (route.middleware?.length || route.hostMiddleware?.length) continue\n if (route.segments.some((segment) => segment.type === 'host')) continue\n\n const path = contractPath(result.url)\n\n if (path === null) continue\n\n if (new TextEncoder().encode(path).length > MAX_SHELL_BYTES) {\n left.push(`${path.slice(0, 60)}… is over ${MAX_SHELL_BYTES} bytes`)\n continue\n }\n\n if (shells.some((pattern) => matchesPattern(pattern, path))) continue\n if (!statics.includes(path)) statics.push(path)\n }\n\n if (statics.length > MAX_STATIC) {\n statics.sort((a, b) => depth(a) - depth(b) || (a < b ? -1 : 1))\n left.push(`${statics.length - MAX_STATIC} static past the shallowest ${MAX_STATIC}`)\n statics.length = MAX_STATIC\n }\n\n statics.sort()\n\n return { static: statics, left }\n}\n\n/**\n * Why pages an edge could otherwise have served were kept out: the outermost\n * middleware above each, with how many pages it guards. A root middleware -\n * the usual home of security headers - guards every page and empties both\n * lists, correctly, and an empty edge.json with no reason given reads as a\n * bug. So the build names the file.\n */\nexport function edgeGuarded(\n results: readonly { type: string; component: string }[],\n routes: readonly ShellRoute[],\n): string[] {\n const byComponent = new Map(routes.map((route) => [route.component, route]))\n const counts = new Map<string, number>()\n\n for (const result of results) {\n if (result.type !== 'frozen' && result.type !== 'shell') continue\n\n const route = byComponent.get(result.component)\n const guard = route?.middleware?.[0] ?? (route?.hostMiddleware?.length ? `the host's ${route.hostMiddleware[0]}` : null)\n\n if (guard) counts.set(guard, (counts.get(guard) ?? 0) + 1)\n }\n\n return [...counts].sort((a, b) => b[1] - a[1] || (a[0] < b[0] ? -1 : 1)).map(([guard, n]) => `${guard} (${n})`)\n}\n\n/**\n * A rendered url as the contract lists it - absolute, decoded once, no query\n * - or null when it has no such form: an empty, `.` or `..` segment, or one\n * holding a `/` once decoded.\n */\nexport function contractPath(url: string): string | null {\n const path = url.split(/[?#]/)[0]\n\n if (!path.startsWith('/')) return null\n if (path === '/') return path\n\n const parts: string[] = []\n\n for (const raw of path.slice(1).split('/')) {\n let part: string\n\n try {\n part = decodeURIComponent(raw)\n } catch {\n return null\n }\n\n if (['', '.', '..'].includes(part) || part.includes('/') || /[?#]/.test(part)) return null\n parts.push(part)\n }\n\n return '/' + parts.join('/')\n}\n\n/** A marker pattern against a path: `[name]` is one segment, a final `[...name]` one or more. */\nexport function matchesPattern(pattern: string, path: string): boolean {\n const want = pattern.split('/')\n const have = path.split('/')\n\n for (const [i, part] of want.entries()) {\n if (i === want.length - 1 && /^\\[\\.\\.\\..+\\]$/.test(part)) {\n return have.length > i && have.slice(i).every(Boolean)\n }\n\n if (have[i] === undefined) return false\n if (/^\\[.+\\]$/.test(part) ? have[i] === '' : part !== have[i]) return false\n }\n\n return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OAAO,EAAE,EAAE,CAAC;QACvC,IAAI,CAAC,KAAK,IAAI,CAAC,MAAM,GAAG,CAAC,IAAI,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;YACzD,OAAO,IAAI,CAAC,MAAM,GAAG,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;QACxD,CAAC;QAED,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,SAAS;YAAE,OAAO,KAAK,CAAA;QACvC,IAAI,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC;YAAE,OAAO,KAAK,CAAA;IAC7E,CAAC;IAED,OAAO,IAAI,CAAC,MAAM,KAAK,IAAI,CAAC,MAAM,CAAA;AACpC,CAAC","sourcesContent":["/**\n * The pages an edge may serve without the app, for `.output/edge.json` - the\n * marker of the edge contract, which an edge reads the same way for every\n * framework that implements it: `shells`, the url patterns of the PPR pages\n * it may answer from a cached shell, and `static`, the paths of the pages it\n * may answer whole.\n *\n * An edge in front of the app asks one question of each request - may I\n * answer this? - and answers it from a list it was handed at deploy time. Reading\n * `rsc-static/` for it does not work: a guarded page has a shell on disk too,\n * served from a cache it skips its guard; `_team_` cannot say whether it was a\n * parameter or a folder of that name; and the layout is ours to change.\n *\n * So the list is the build's, by the same rule the page endpoint applies: a\n * page with a shell, on a route with no middleware - neither a `middleware.ts`\n * above it nor the host's `export const middleware`. The endpoint refuses\n * exactly those, so the list and the origin cannot disagree.\n */\n\nimport type { RouteSegment } from './manifest.js'\n\n/** What an edge is promised, and what it can hold. */\nexport const MAX_SHELLS = 200\nexport const MAX_SHELL_BYTES = 200\n/** The same again for `static`, on top of `shells`' count. */\nexport const MAX_STATIC = 200\n\n/**\n * The marker. `bypass` names this framework's own requests on a page's path\n * that are not a visitor's document: every payload fetch - a navigation, a\n * prefetch, a refresh - carries X-RSC, and an action is a POST, which an edge\n * never answers from a shell anyway.\n */\nexport function edgeMarker(build: string, shells: string[], statics: string[], nonceShells?: string[]) {\n return {\n v: 2,\n build,\n shells,\n static: statics,\n // Under a Content-Security-Policy: shells whose holes need a nonce, for an\n // edge that mints one (Edge-Accept: nonce). An edge that does not reads\n // only `shells`, which is then empty, and sends these pages to the origin.\n ...(nonceShells ? { nonceShells } : {}),\n bypass: { headers: ['X-RSC'] },\n }\n}\n\nexport interface ShellRoute {\n component: string\n segments: RouteSegment[]\n middleware?: readonly string[]\n hostMiddleware?: readonly string[]\n}\n\n/**\n * The patterns, `/` for the index, `[name]` for one segment and a final\n * `[...name]` for one or more - and what was left out of the list, and why,\n * for the build to say.\n */\nexport function edgeShells(\n results: readonly { type: string; component: string }[],\n routes: readonly ShellRoute[],\n subdomains: readonly string[] = [],\n): { shells: string[]; left: string[] } {\n const byComponent = new Map(routes.map((route) => [route.component, route]))\n const shells: string[] = []\n const left: string[] = []\n\n for (const component of new Set(results.filter((r) => r.type === 'shell').map((r) => r.component))) {\n const route = byComponent.get(component)\n\n if (!route) continue\n if (route.middleware?.length || route.hostMiddleware?.length) continue\n\n // Bound from the request's host, which a path pattern cannot say: the\n // same pattern would match every tenant's page on every domain.\n if (route.segments.some((segment) => segment.type === 'host')) continue\n if (onSubdomain(route, subdomains)) continue\n\n const pattern = patternOf(route.segments)\n\n if (pattern === null) continue\n\n if (new TextEncoder().encode(pattern).length > MAX_SHELL_BYTES) {\n left.push(`${pattern.slice(0, 60)}… is over ${MAX_SHELL_BYTES} bytes`)\n continue\n }\n\n if (!shells.includes(pattern)) shells.push(pattern)\n }\n\n // Over the cap, the deepest are the ones not listed: an edge that does not\n // know a page is a PPR page sends it to the origin, which answers it\n // correctly, and the shallow pages are the ones most visited.\n if (shells.length > MAX_SHELLS) {\n shells.sort((a, b) => depth(a) - depth(b) || (a < b ? -1 : 1))\n left.push(`${shells.length - MAX_SHELLS} past the shallowest ${MAX_SHELLS}`)\n shells.length = MAX_SHELLS\n }\n\n shells.sort()\n\n return { shells, left }\n}\n\n/**\n * Under a folder rscKit({ subdomains }) serves on its own host. An edge\n * answers by path, so it would answer example.com/merchant/orders itself and\n * skip the 301 to merchant.example.com - and a pattern cannot say the host.\n */\nfunction onSubdomain(route: ShellRoute, subdomains: readonly string[]): boolean {\n const first = route.segments.find((segment) => segment.type !== 'host')\n\n return first?.type === 'static' && subdomains.includes(first.value)\n}\n\n/**\n * A route's segments as the edge matches them, or null when it cannot: a\n * catch-all anywhere but last, or a name that is itself bracketed - an\n * optional catch-all, `[[...name]]`, matches no url at all.\n */\nfunction patternOf(segments: readonly RouteSegment[]): string | null {\n const parts: string[] = []\n\n for (const [index, segment] of segments.entries()) {\n // Not a path an edge can match: the contract has no empty, `.` or `..`\n // segment, and a name with a slash would be two.\n if (['', '.', '..'].includes(segment.value) || segment.value.includes('/')) return null\n if (segment.type === 'static') parts.push(segment.value)\n else if (segment.value.includes('[') || segment.value.includes(']')) return null\n else if (segment.type === 'catchAll') {\n if (index !== segments.length - 1) return null\n parts.push(`[...${segment.value}]`)\n } else parts.push(`[${segment.value}]`)\n }\n\n return '/' + parts.join('/')\n}\n\nfunction depth(pattern: string): number {\n return pattern === '/' ? 0 : pattern.split('/').length - 1\n}\n\n/**\n * The pages an edge may answer whole: frozen, so the document is the same for\n * every visitor until the next build, with no guard of either kind and not\n * bound from the host - and listed as the paths the build rendered, since\n * `static` takes no patterns: a pattern would ask the edge for paths that\n * were never rendered. A frozen redirect is not here: it has no document.\n *\n * A path a listed shell's pattern also matches is left out, so no path is\n * two things to the edge.\n */\nexport function edgeStatic(\n results: readonly { type: string; component: string; url: string }[],\n routes: readonly ShellRoute[],\n shells: readonly string[],\n subdomains: readonly string[] = [],\n): { static: string[]; left: string[] } {\n const byComponent = new Map(routes.map((route) => [route.component, route]))\n const statics: string[] = []\n const left: string[] = []\n\n for (const result of results) {\n if (result.type !== 'frozen') continue\n\n const route = byComponent.get(result.component)\n\n if (!route) continue\n if (route.middleware?.length || route.hostMiddleware?.length) continue\n if (route.segments.some((segment) => segment.type === 'host')) continue\n if (onSubdomain(route, subdomains)) continue\n\n const path = contractPath(result.url)\n\n if (path === null) continue\n\n if (new TextEncoder().encode(path).length > MAX_SHELL_BYTES) {\n left.push(`${path.slice(0, 60)}… is over ${MAX_SHELL_BYTES} bytes`)\n continue\n }\n\n if (shells.some((pattern) => matchesPattern(pattern, path))) continue\n if (!statics.includes(path)) statics.push(path)\n }\n\n if (statics.length > MAX_STATIC) {\n statics.sort((a, b) => depth(a) - depth(b) || (a < b ? -1 : 1))\n left.push(`${statics.length - MAX_STATIC} static past the shallowest ${MAX_STATIC}`)\n statics.length = MAX_STATIC\n }\n\n statics.sort()\n\n return { static: statics, left }\n}\n\n/**\n * Why pages an edge could otherwise have served were kept out: the outermost\n * middleware above each, with how many pages it guards. A root middleware -\n * the usual home of security headers - guards every page and empties both\n * lists, correctly, and an empty edge.json with no reason given reads as a\n * bug. So the build names the file.\n */\nexport function edgeGuarded(\n results: readonly { type: string; component: string }[],\n routes: readonly ShellRoute[],\n): string[] {\n const byComponent = new Map(routes.map((route) => [route.component, route]))\n const counts = new Map<string, number>()\n\n for (const result of results) {\n if (result.type !== 'frozen' && result.type !== 'shell') continue\n\n const route = byComponent.get(result.component)\n const guard = route?.middleware?.[0] ?? (route?.hostMiddleware?.length ? `the host's ${route.hostMiddleware[0]}` : null)\n\n if (guard) counts.set(guard, (counts.get(guard) ?? 0) + 1)\n }\n\n return [...counts].sort((a, b) => b[1] - a[1] || (a[0] < b[0] ? -1 : 1)).map(([guard, n]) => `${guard} (${n})`)\n}\n\n/**\n * A rendered url as the contract lists it - absolute, decoded once, no query\n * - or null when it has no such form: an empty, `.` or `..` segment, or one\n * holding a `/` once decoded.\n */\nexport function contractPath(url: string): string | null {\n const path = url.split(/[?#]/)[0]\n\n if (!path.startsWith('/')) return null\n if (path === '/') return path\n\n const parts: string[] = []\n\n for (const raw of path.slice(1).split('/')) {\n let part: string\n\n try {\n part = decodeURIComponent(raw)\n } catch {\n return null\n }\n\n if (['', '.', '..'].includes(part) || part.includes('/') || /[?#]/.test(part)) return null\n parts.push(part)\n }\n\n return '/' + parts.join('/')\n}\n\n/** A marker pattern against a path: `[name]` is one segment, a final `[...name]` one or more. */\nexport function matchesPattern(pattern: string, path: string): boolean {\n const want = pattern.split('/')\n const have = path.split('/')\n\n for (const [i, part] of want.entries()) {\n if (i === want.length - 1 && /^\\[\\.\\.\\..+\\]$/.test(part)) {\n return have.length > i && have.slice(i).every(Boolean)\n }\n\n if (have[i] === undefined) return false\n if (/^\\[.+\\]$/.test(part) ? have[i] === '' : part !== have[i]) return false\n }\n\n return want.length === have.length\n}\n"]}
|
package/dist/host.js
CHANGED
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
import { allowFor, matchApiRoute, matchIntercept, layoutChain, matchRoute, retentionKey, sharedDepth, } from "./routing.js";
|
|
17
17
|
import { PARAM_PLACEHOLDER, pathKey, patternKey } from "./prerender.js";
|
|
18
18
|
import { apiKey } from "./apiPrerender.js";
|
|
19
|
+
import { setPurgeSubdomains } from "./purge.js";
|
|
19
20
|
import { bareHost, hostPath, hostSegment, routableHost, siteFromRequest, subdomainHref, subdomainRedirect } from "./hostRouting.js";
|
|
20
21
|
import { withRevalidation } from "./revalidate.js";
|
|
21
22
|
import { withoutPayloadKey } from "./js/payloadKey.js";
|
|
@@ -71,7 +72,7 @@ import { inlineFlight, inlineFlightStart } from "./inlineFlight.js";
|
|
|
71
72
|
import { currentNotFound, withRedirect } from "./redirect.js";
|
|
72
73
|
import { compressed } from "./compress.js";
|
|
73
74
|
import { installedCacheStore, setCacheBuild, withCache } from "./cache.js";
|
|
74
|
-
import { notFoundRowSent, renderAsNobody, takeAfterWork, withRequest, withResponseDraft, withUrl } from "./request.js";
|
|
75
|
+
import { notFoundRowSent, renderAsNobody, takeAfterWork, withoutVisitorCookies, withRequest, withResponseDraft, withUrl } from "./request.js";
|
|
75
76
|
import { criticalAssetsOf, linkHeader, mergeAssets } from "./earlyHints.js";
|
|
76
77
|
/**
|
|
77
78
|
* @internal For a host adapter that embeds the engine. An app imports this
|
|
@@ -597,6 +598,7 @@ export function createRscHandler(options) {
|
|
|
597
598
|
const siteHosts = manifest.build?.hosts ?? [];
|
|
598
599
|
/** rscKit({ subdomains }): the directories served on their own host, and only there. */
|
|
599
600
|
const subdomains = manifest.build?.subdomains ?? [];
|
|
601
|
+
setPurgeSubdomains(subdomains);
|
|
600
602
|
/** Whether responses say what built them. How they were served is always said. */
|
|
601
603
|
const identify = Boolean(manifest.build?.identify);
|
|
602
604
|
// rscKit({ headers }): every response, and every page an edge serves.
|
|
@@ -1037,9 +1039,14 @@ export function createRscHandler(options) {
|
|
|
1037
1039
|
if (api && engine.handleApiRoute) {
|
|
1038
1040
|
// A route.ts that changes something is a form any site could post to
|
|
1039
1041
|
// with the visitor's cookies, and nothing else here stands in the way:
|
|
1040
|
-
// no custom header, so no preflight. Refused before its guards run
|
|
1042
|
+
// no custom header, so no preflight. Refused before its guards run -
|
|
1043
|
+
// unless the route answers other sites (`export const crossOrigin =
|
|
1044
|
+
// true`, an embedded widget's api), where it runs without the cookies
|
|
1045
|
+
// instead: the forgery needs them, and a bearer key does not.
|
|
1041
1046
|
if (!SAFE_METHODS.has(request.method) && !originAllowed(request, url, trustedOrigins)) {
|
|
1042
|
-
|
|
1047
|
+
if (!api.route.crossOrigin)
|
|
1048
|
+
return new Response("Cross-origin request", { status: 403 });
|
|
1049
|
+
request = withoutVisitorCookies(request);
|
|
1043
1050
|
}
|
|
1044
1051
|
// The guards above it run first, exactly as they would for a page in the
|
|
1045
1052
|
// same directory. A route.ts is colocated with the pages it belongs
|