@reckona/mreact-router 0.0.201 → 0.0.202
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 +1 -1
- package/dist/adapters/cloudflare.d.ts.map +1 -1
- package/dist/adapters/cloudflare.js +51 -4
- package/dist/adapters/cloudflare.js.map +1 -1
- package/dist/adapters/node.d.ts +7 -0
- package/dist/adapters/node.d.ts.map +1 -1
- package/dist/adapters/node.js +7 -1
- package/dist/adapters/node.js.map +1 -1
- package/dist/adapters/static.d.ts.map +1 -1
- package/dist/adapters/static.js +14 -3
- package/dist/adapters/static.js.map +1 -1
- package/dist/build.d.ts +3 -0
- package/dist/build.d.ts.map +1 -1
- package/dist/build.js +42 -5
- package/dist/build.js.map +1 -1
- package/dist/built-runtime.d.ts +4 -1
- package/dist/built-runtime.d.ts.map +1 -1
- package/dist/built-runtime.js.map +1 -1
- package/dist/cache.d.ts +26 -0
- package/dist/cache.d.ts.map +1 -1
- package/dist/cache.js +78 -12
- package/dist/cache.js.map +1 -1
- package/dist/cli-options.d.ts +4 -0
- package/dist/cli-options.d.ts.map +1 -1
- package/dist/cli-options.js +17 -0
- package/dist/cli-options.js.map +1 -1
- package/dist/cli.js +2 -1
- package/dist/cli.js.map +1 -1
- package/dist/node-server.d.ts +6 -0
- package/dist/node-server.d.ts.map +1 -1
- package/dist/node-server.js +19 -1
- package/dist/node-server.js.map +1 -1
- package/dist/prerender-entry.d.ts +5 -0
- package/dist/prerender-entry.d.ts.map +1 -0
- package/dist/prerender-entry.js +41 -0
- package/dist/prerender-entry.js.map +1 -0
- package/dist/render.d.ts +13 -0
- package/dist/render.d.ts.map +1 -1
- package/dist/render.js +139 -87
- package/dist/render.js.map +1 -1
- package/dist/request-header-tracking.d.ts +44 -0
- package/dist/request-header-tracking.d.ts.map +1 -0
- package/dist/request-header-tracking.js +116 -0
- package/dist/request-header-tracking.js.map +1 -0
- package/dist/route-source.d.ts +16 -0
- package/dist/route-source.d.ts.map +1 -1
- package/dist/route-source.js +55 -1
- package/dist/route-source.js.map +1 -1
- package/dist/security-headers.d.ts +16 -0
- package/dist/security-headers.d.ts.map +1 -1
- package/dist/security-headers.js +37 -0
- package/dist/security-headers.js.map +1 -1
- package/dist/serve.d.ts +7 -0
- package/dist/serve.d.ts.map +1 -1
- package/dist/serve.js +94 -28
- package/dist/serve.js.map +1 -1
- package/package.json +11 -11
- package/src/adapters/cloudflare.ts +81 -9
- package/src/adapters/node.ts +14 -1
- package/src/adapters/static.ts +18 -5
- package/src/build.ts +71 -4
- package/src/built-runtime.ts +2 -2
- package/src/cache.ts +117 -11
- package/src/cli-options.ts +24 -0
- package/src/cli.ts +5 -0
- package/src/node-server.ts +27 -1
- package/src/prerender-entry.ts +56 -0
- package/src/render.ts +188 -98
- package/src/request-header-tracking.ts +161 -0
- package/src/route-source.ts +71 -0
- package/src/security-headers.ts +41 -0
- package/src/serve.ts +133 -30
package/dist/built-runtime.d.ts
CHANGED
|
@@ -15,7 +15,10 @@ export interface BuiltRuntime extends BuiltServerModuleArtifactRuntime {
|
|
|
15
15
|
projectRoot: string;
|
|
16
16
|
publicAssetBaseUrl?: string | undefined;
|
|
17
17
|
prerenderableRoutes: ReadonlySet<string>;
|
|
18
|
-
prerenderLocks: Map<string, Promise<
|
|
18
|
+
prerenderLocks: Map<string, Promise<{
|
|
19
|
+
response: Response;
|
|
20
|
+
shareable: boolean;
|
|
21
|
+
}>>;
|
|
19
22
|
prerenderedRoutes: Map<string, BuiltPrerenderedRoute>;
|
|
20
23
|
routeMatcher: RouteMatcher;
|
|
21
24
|
routes: readonly AppRoute[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"built-runtime.d.ts","sourceRoot":"","sources":["../src/built-runtime.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,qBAAqB,EAGtB,MAAM,YAAY,CAAC;AAEpB,OAAO,KAAK,EAAE,gCAAgC,EAAE,MAAM,oCAAoC,CAAC;AAE3F,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oBAAoB,CAAC,QAAgB;IAC5C,MAAM,UAAU,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC;IAEvC,IAAI,UAAU,CAAC,UAAU,CAAC,IAAI,UAAU,KAAK,IAAI,IAAI,UAAU,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;QAClF,MAAM,IAAI,KAAK,CAAC,yCAAyC,QAAQ,EAAE,CAAC,CAAC;IACvE,CAAC;IAED,OAAO,UAAU,CAAC;AACpB,CAAC","sourcesContent":["import { createHash } from \"node:crypto\";\nimport { mkdir, readFile, rm, writeFile } from \"node:fs/promises\";\nimport { dirname, isAbsolute, join, normalize } from \"node:path\";\nimport type {\n BuiltPrerenderedRoute,\n BuiltServerManifest,\n BuiltServerModuleArtifact,\n} from \"./build.js\";\nimport { builtClientAssetPaths } from \"./built-assets.js\";\nimport type { BuiltServerModuleArtifactRuntime } from \"./built-server-module-artifacts.js\";\nimport type { ClientRouteManifestEntry } from \"./client-route-inference.js\";\nimport type { AppRouterImportPolicy } from \"./import-policy.js\";\nimport { createRouteMatcher, type AppRoute, type RouteMatcher } from \"./routes.js\";\n\nexport interface BuiltRuntime extends BuiltServerModuleArtifactRuntime {\n allowedSourceDirs: readonly string[];\n assetBaseUrl?: string | undefined;\n clientAssetPaths: ReadonlySet<string>;\n clientScripts: ReadonlyMap<string, string>;\n clientStylesByFile: ReadonlyMap<string, readonly string[]>;\n clientStyles: ReadonlyMap<string, readonly string[]>;\n generatedImportPolicy?: AppRouterImportPolicy | undefined;\n hasMiddleware: boolean;\n navigationScripts: ReadonlyMap<string, string>;\n projectRoot: string;\n publicAssetBaseUrl?: string | undefined;\n prerenderableRoutes: ReadonlySet<string>;\n prerenderLocks: Map<string, Promise<Response>>;\n prerenderedRoutes: Map<string, BuiltPrerenderedRoute>;\n routeMatcher: RouteMatcher;\n routes: readonly AppRoute[];\n serverActionReferencesByFile: ReadonlyMap<\n string,\n readonly {\n end: number;\n expression: string;\n expressionEnd: number;\n expressionStart: number;\n moduleId: string;\n exportName: string;\n inferred: boolean;\n sourceHash: string;\n start: number;\n }[]\n >;\n serverActionManifest?: readonly { moduleId: string; exportName: string; inferred?: boolean }[] | undefined;\n serverModuleCacheVersion: string;\n}\n\nexport async function materializeBuiltRuntime(options: {\n clientManifestText: string;\n clientManifestPath: string;\n importPolicyPath: string;\n importPolicyText: string | undefined;\n onMaterialize?: (() => void) | undefined;\n outDir: string;\n runtimeDir: string;\n serverManifestText: string;\n serverManifestPath: string;\n}): Promise<BuiltRuntime> {\n options.onMaterialize?.();\n const serverManifest = parseBuiltJsonArtifact<BuiltServerManifest>(\n options.serverManifestText,\n options.serverManifestPath,\n \"built app server manifest\",\n );\n const clientManifest = parseBuiltJsonArtifact<{\n assets?: readonly string[];\n routes: ClientRouteManifestEntry[];\n styles?: Array<{ css?: readonly string[]; file: string }>;\n }>(options.clientManifestText, options.clientManifestPath, \"built app client manifest\");\n const appDir = await materializeBuiltServerApp(options.runtimeDir, serverManifest);\n const projectRoot = appDir;\n const routesDir = join(projectRoot, serverManifest.routesDir ?? \"\");\n const routes = serverManifest.routes.map((route) => ({\n ...route,\n file: join(projectRoot, route.file),\n }));\n const prerenderedRoutes = new Map(Object.entries(serverManifest.prerenderedRoutes ?? {}));\n const prerenderableRoutes = new Set(prerenderedRoutes.keys());\n const prerenderLocks = new Map<string, Promise<Response>>();\n const serverModules = new Map<string, BuiltServerModuleArtifact>(\n Object.entries(serverManifest.serverModules ?? {}).map(([file, artifact]) => [\n join(appDir, file),\n artifact,\n ]),\n );\n const serverModuleClosureFiles = new Map<string, readonly string[]>(\n Object.entries(serverManifest.serverModuleClosureFiles ?? {}).map(([file, closure]) => [\n join(appDir, safeManifestFilePath(file)),\n closure.map((closureFile) => join(appDir, safeManifestFilePath(closureFile))),\n ]),\n );\n const serverModuleFiles = new Map(\n Object.entries(serverManifest.serverModuleFiles ?? {}).map(([file, artifactFile]) => [\n join(appDir, file),\n join(options.outDir, \"server\", safeManifestFilePath(artifactFile)),\n ]),\n );\n const serverModuleRequestFiles = new Map(\n Object.entries(serverManifest.serverModuleRequestFiles ?? {}).map(([file, artifactFile]) => [\n join(appDir, file),\n join(options.outDir, \"server\", safeManifestFilePath(artifactFile)),\n ]),\n );\n const serverModuleRenderFiles = new Map(\n Object.entries(serverManifest.serverModuleRenderFiles ?? {}).map(([file, artifactFile]) => [\n join(appDir, file),\n join(options.outDir, \"server\", safeManifestFilePath(artifactFile)),\n ]),\n );\n const serverSourceFiles = new Map(\n Object.entries(serverManifest.files).map(([file, source]) => [join(appDir, file), source]),\n );\n const serverActionReferencesByFile = new Map(\n Object.entries(serverManifest.routeServerActionReferences ?? {}).map(([file, references]) => [\n join(appDir, file),\n references,\n ]),\n );\n const routeMatcher = createRouteMatcher(routes, serverManifest.routeMatcher);\n const clientScripts = new Map(\n clientManifest.routes.flatMap((route) =>\n route.client && route.script !== undefined ? [[route.path, route.script]] : [],\n ),\n );\n const clientStyles = new Map(\n clientManifest.routes.flatMap((route) =>\n route.css !== undefined && route.css.length > 0 ? [[route.path, route.css]] : [],\n ),\n );\n const clientStylesByFile = new Map(\n (clientManifest.styles ?? []).flatMap((style) =>\n style.css !== undefined && style.css.length > 0\n ? [[join(routesDir, style.file), style.css] as const]\n : [],\n ),\n );\n const navigationScripts = new Map(\n clientManifest.routes.flatMap((route) =>\n route.navigation === true && route.navigationScript !== undefined\n ? [[route.path, route.navigationScript]]\n : [],\n ),\n );\n const hasMiddleware =\n serverSourceFiles.has(join(routesDir, \"middleware.ts\")) ||\n serverSourceFiles.has(join(routesDir, \"middleware.mreact.ts\"));\n const serverModuleCacheVersion = createHash(\"sha256\")\n .update(options.serverManifestText)\n .update(\"\\0\")\n .update(options.clientManifestText)\n .digest(\"hex\")\n .slice(0, 16);\n\n const allowedSourceDirs = (serverManifest.allowedSourceDirs ?? [\"\"]).map((directory) =>\n join(projectRoot, directory),\n );\n const generatedImportPolicy = builtGeneratedImportPolicy(\n options.importPolicyText,\n options.importPolicyPath,\n );\n\n return {\n appDir: routesDir,\n allowedSourceDirs,\n ...(serverManifest.assetBaseUrl === undefined\n ? {}\n : { assetBaseUrl: serverManifest.assetBaseUrl }),\n clientAssetPaths: builtClientAssetPaths(clientManifest),\n clientScripts,\n clientStylesByFile,\n clientStyles,\n ...(generatedImportPolicy === undefined ? {} : { generatedImportPolicy }),\n hasMiddleware,\n navigationScripts,\n projectRoot,\n ...(serverManifest.publicAssetBaseUrl === undefined\n ? {}\n : { publicAssetBaseUrl: serverManifest.publicAssetBaseUrl }),\n prerenderableRoutes,\n prerenderLocks,\n prerenderedRoutes,\n routeMatcher,\n routes,\n serverActionReferencesByFile,\n ...(serverManifest.serverActionManifest === undefined\n ? {}\n : { serverActionManifest: serverManifest.serverActionManifest }),\n serverModuleArtifactLoads: new Map(),\n serverModuleClosureFiles,\n serverModuleFiles,\n serverModuleRenderFiles,\n serverModuleRequestFiles,\n serverModules,\n serverModuleCacheVersion,\n serverSourceFiles,\n };\n}\n\nexport async function readBuiltImportPolicyText(outDir: string): Promise<string | undefined> {\n const policyPath = join(outDir, \"server\", \"import-policy.json\");\n\n try {\n return await readFile(policyPath, \"utf8\");\n } catch (error) {\n if (isMissingFileError(error)) {\n return undefined;\n }\n\n throw builtArtifactReadError(\"built app import policy\", policyPath, error);\n }\n}\n\nexport function mergeBuiltRuntimeImportPolicy(\n runtime: BuiltRuntime,\n importPolicy: AppRouterImportPolicy | undefined,\n): AppRouterImportPolicy | undefined {\n const generatedImportPolicy = runtime.generatedImportPolicy;\n\n if (generatedImportPolicy === undefined) {\n return importPolicy;\n }\n\n const allowedPackages = [\n ...new Set([\n ...(generatedImportPolicy.allowedPackages ?? []),\n ...(importPolicy?.allowedPackages ?? []),\n ]),\n ];\n\n return {\n ...(allowedPackages.length === 0 ? {} : { allowedPackages }),\n ...(importPolicy?.allowedSourceDirs === undefined\n ? {}\n : { allowedSourceDirs: importPolicy.allowedSourceDirs }),\n ...(importPolicy?.projectRoot === undefined ? {} : { projectRoot: importPolicy.projectRoot }),\n };\n}\n\nfunction builtGeneratedImportPolicy(\n importPolicyText: string | undefined,\n importPolicyPath: string,\n): AppRouterImportPolicy | undefined {\n if (importPolicyText === undefined) {\n return undefined;\n }\n\n const artifact = parseBuiltJsonArtifact<{\n runtimePackages?: unknown;\n }>(importPolicyText, importPolicyPath, \"built app import policy\");\n const runtimePackages = Array.isArray(artifact.runtimePackages)\n ? artifact.runtimePackages.filter((name): name is string => typeof name === \"string\")\n : [];\n\n return runtimePackages.length === 0 ? undefined : { allowedPackages: runtimePackages };\n}\n\nasync function materializeBuiltServerApp(\n runtimeDir: string,\n manifest: BuiltServerManifest,\n): Promise<string> {\n const appDir = join(runtimeDir, \"app\");\n\n await rm(appDir, { force: true, recursive: true });\n await Promise.all(\n Object.entries(manifest.files).map(async ([file, code]) => {\n const outputFile = join(appDir, safeManifestFilePath(file));\n\n await mkdir(dirname(outputFile), { recursive: true });\n await writeFile(outputFile, code);\n }),\n );\n\n return appDir;\n}\n\nfunction isMissingFileError(error: unknown): boolean {\n return (\n typeof error === \"object\" &&\n error !== null &&\n \"code\" in error &&\n (error as { code?: unknown }).code === \"ENOENT\"\n );\n}\n\nfunction builtArtifactReadError(label: string, artifactPath: string, error: unknown): Error {\n const prefix = isMissingFileError(error) ? \"Missing\" : \"Unable to read\";\n const detail = error instanceof Error && error.message !== \"\" ? `: ${error.message}` : \"\";\n\n return new Error(`${prefix} ${label}: ${artifactPath}${detail}`, { cause: error });\n}\n\nfunction parseBuiltJsonArtifact<T>(text: string, artifactPath: string, label: string): T {\n try {\n return JSON.parse(text) as T;\n } catch (error) {\n const detail = error instanceof Error && error.message !== \"\" ? `: ${error.message}` : \"\";\n\n throw new Error(`Invalid ${label}: ${artifactPath}${detail}`, { cause: error });\n }\n}\n\nfunction safeManifestFilePath(pathname: string): string {\n const normalized = normalize(pathname);\n\n if (isAbsolute(normalized) || normalized === \"..\" || normalized.startsWith(\"../\")) {\n throw new Error(`Invalid built app manifest file path: ${pathname}`);\n }\n\n return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AC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,MAAM,GAAG,KAAK,YAAY,KAAK,IAAI,KAAK,CAAC,OAAO,KAAK,EAAE,CAAC,CAAC,CAAC,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAE1F,MAAM,IAAI,KAAK,CAAC,WAAW,KAAK,KAAK,YAAY,GAAG,MAAM,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;IAClF,CAAC;AACH,CAAC;AAED,SAAS,oBAAoB,CAAC,QAAgB;IAC5C,MAAM,UAAU,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC;IAEvC,IAAI,UAAU,CAAC,UAAU,CAAC,IAAI,UAAU,KAAK,IAAI,IAAI,UAAU,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;QAClF,MAAM,IAAI,KAAK,CAAC,yCAAyC,QAAQ,EAAE,CAAC,CAAC;IACvE,CAAC;IAED,OAAO,UAAU,CAAC;AACpB,CAAC","sourcesContent":["import { createHash } from \"node:crypto\";\nimport { mkdir, readFile, rm, writeFile } from \"node:fs/promises\";\nimport { dirname, isAbsolute, join, normalize } from \"node:path\";\nimport type {\n BuiltPrerenderedRoute,\n BuiltServerManifest,\n BuiltServerModuleArtifact,\n} from \"./build.js\";\nimport { builtClientAssetPaths } from \"./built-assets.js\";\nimport type { BuiltServerModuleArtifactRuntime } from \"./built-server-module-artifacts.js\";\nimport type { ClientRouteManifestEntry } from \"./client-route-inference.js\";\nimport type { AppRouterImportPolicy } from \"./import-policy.js\";\nimport { createRouteMatcher, type AppRoute, type RouteMatcher } from \"./routes.js\";\n\nexport interface BuiltRuntime extends BuiltServerModuleArtifactRuntime {\n allowedSourceDirs: readonly string[];\n assetBaseUrl?: string | undefined;\n clientAssetPaths: ReadonlySet<string>;\n clientScripts: ReadonlyMap<string, string>;\n clientStylesByFile: ReadonlyMap<string, readonly string[]>;\n clientStyles: ReadonlyMap<string, readonly string[]>;\n generatedImportPolicy?: AppRouterImportPolicy | undefined;\n hasMiddleware: boolean;\n navigationScripts: ReadonlyMap<string, string>;\n projectRoot: string;\n publicAssetBaseUrl?: string | undefined;\n prerenderableRoutes: ReadonlySet<string>;\n prerenderLocks: Map<string, Promise<{ response: Response; shareable: boolean }>>;\n prerenderedRoutes: Map<string, BuiltPrerenderedRoute>;\n routeMatcher: RouteMatcher;\n routes: readonly AppRoute[];\n serverActionReferencesByFile: ReadonlyMap<\n string,\n readonly {\n end: number;\n expression: string;\n expressionEnd: number;\n expressionStart: number;\n moduleId: string;\n exportName: string;\n inferred: boolean;\n sourceHash: string;\n start: number;\n }[]\n >;\n serverActionManifest?: readonly { moduleId: string; exportName: string; inferred?: boolean }[] | undefined;\n serverModuleCacheVersion: string;\n}\n\nexport async function materializeBuiltRuntime(options: {\n clientManifestText: string;\n clientManifestPath: string;\n importPolicyPath: string;\n importPolicyText: string | undefined;\n onMaterialize?: (() => void) | undefined;\n outDir: string;\n runtimeDir: string;\n serverManifestText: string;\n serverManifestPath: string;\n}): Promise<BuiltRuntime> {\n options.onMaterialize?.();\n const serverManifest = parseBuiltJsonArtifact<BuiltServerManifest>(\n options.serverManifestText,\n options.serverManifestPath,\n \"built app server manifest\",\n );\n const clientManifest = parseBuiltJsonArtifact<{\n assets?: readonly string[];\n routes: ClientRouteManifestEntry[];\n styles?: Array<{ css?: readonly string[]; file: string }>;\n }>(options.clientManifestText, options.clientManifestPath, \"built app client manifest\");\n const appDir = await materializeBuiltServerApp(options.runtimeDir, serverManifest);\n const projectRoot = appDir;\n const routesDir = join(projectRoot, serverManifest.routesDir ?? \"\");\n const routes = serverManifest.routes.map((route) => ({\n ...route,\n file: join(projectRoot, route.file),\n }));\n const prerenderedRoutes = new Map(Object.entries(serverManifest.prerenderedRoutes ?? {}));\n const prerenderableRoutes = new Set(prerenderedRoutes.keys());\n const prerenderLocks = new Map<string, Promise<{ response: Response; shareable: boolean }>>();\n const serverModules = new Map<string, BuiltServerModuleArtifact>(\n Object.entries(serverManifest.serverModules ?? {}).map(([file, artifact]) => [\n join(appDir, file),\n artifact,\n ]),\n );\n const serverModuleClosureFiles = new Map<string, readonly string[]>(\n Object.entries(serverManifest.serverModuleClosureFiles ?? {}).map(([file, closure]) => [\n join(appDir, safeManifestFilePath(file)),\n closure.map((closureFile) => join(appDir, safeManifestFilePath(closureFile))),\n ]),\n );\n const serverModuleFiles = new Map(\n Object.entries(serverManifest.serverModuleFiles ?? {}).map(([file, artifactFile]) => [\n join(appDir, file),\n join(options.outDir, \"server\", safeManifestFilePath(artifactFile)),\n ]),\n );\n const serverModuleRequestFiles = new Map(\n Object.entries(serverManifest.serverModuleRequestFiles ?? {}).map(([file, artifactFile]) => [\n join(appDir, file),\n join(options.outDir, \"server\", safeManifestFilePath(artifactFile)),\n ]),\n );\n const serverModuleRenderFiles = new Map(\n Object.entries(serverManifest.serverModuleRenderFiles ?? {}).map(([file, artifactFile]) => [\n join(appDir, file),\n join(options.outDir, \"server\", safeManifestFilePath(artifactFile)),\n ]),\n );\n const serverSourceFiles = new Map(\n Object.entries(serverManifest.files).map(([file, source]) => [join(appDir, file), source]),\n );\n const serverActionReferencesByFile = new Map(\n Object.entries(serverManifest.routeServerActionReferences ?? {}).map(([file, references]) => [\n join(appDir, file),\n references,\n ]),\n );\n const routeMatcher = createRouteMatcher(routes, serverManifest.routeMatcher);\n const clientScripts = new Map(\n clientManifest.routes.flatMap((route) =>\n route.client && route.script !== undefined ? [[route.path, route.script]] : [],\n ),\n );\n const clientStyles = new Map(\n clientManifest.routes.flatMap((route) =>\n route.css !== undefined && route.css.length > 0 ? [[route.path, route.css]] : [],\n ),\n );\n const clientStylesByFile = new Map(\n (clientManifest.styles ?? []).flatMap((style) =>\n style.css !== undefined && style.css.length > 0\n ? [[join(routesDir, style.file), style.css] as const]\n : [],\n ),\n );\n const navigationScripts = new Map(\n clientManifest.routes.flatMap((route) =>\n route.navigation === true && route.navigationScript !== undefined\n ? [[route.path, route.navigationScript]]\n : [],\n ),\n );\n const hasMiddleware =\n serverSourceFiles.has(join(routesDir, \"middleware.ts\")) ||\n serverSourceFiles.has(join(routesDir, \"middleware.mreact.ts\"));\n const serverModuleCacheVersion = createHash(\"sha256\")\n .update(options.serverManifestText)\n .update(\"\\0\")\n .update(options.clientManifestText)\n .digest(\"hex\")\n .slice(0, 16);\n\n const allowedSourceDirs = (serverManifest.allowedSourceDirs ?? [\"\"]).map((directory) =>\n join(projectRoot, directory),\n );\n const generatedImportPolicy = builtGeneratedImportPolicy(\n options.importPolicyText,\n options.importPolicyPath,\n );\n\n return {\n appDir: routesDir,\n allowedSourceDirs,\n ...(serverManifest.assetBaseUrl === undefined\n ? {}\n : { assetBaseUrl: serverManifest.assetBaseUrl }),\n clientAssetPaths: builtClientAssetPaths(clientManifest),\n clientScripts,\n clientStylesByFile,\n clientStyles,\n ...(generatedImportPolicy === undefined ? {} : { generatedImportPolicy }),\n hasMiddleware,\n navigationScripts,\n projectRoot,\n ...(serverManifest.publicAssetBaseUrl === undefined\n ? {}\n : { publicAssetBaseUrl: serverManifest.publicAssetBaseUrl }),\n prerenderableRoutes,\n prerenderLocks,\n prerenderedRoutes,\n routeMatcher,\n routes,\n serverActionReferencesByFile,\n ...(serverManifest.serverActionManifest === undefined\n ? {}\n : { serverActionManifest: serverManifest.serverActionManifest }),\n serverModuleArtifactLoads: new Map(),\n serverModuleClosureFiles,\n serverModuleFiles,\n serverModuleRenderFiles,\n serverModuleRequestFiles,\n serverModules,\n serverModuleCacheVersion,\n serverSourceFiles,\n };\n}\n\nexport async function readBuiltImportPolicyText(outDir: string): Promise<string | undefined> {\n const policyPath = join(outDir, \"server\", \"import-policy.json\");\n\n try {\n return await readFile(policyPath, \"utf8\");\n } catch (error) {\n if (isMissingFileError(error)) {\n return undefined;\n }\n\n throw builtArtifactReadError(\"built app import policy\", policyPath, error);\n }\n}\n\nexport function mergeBuiltRuntimeImportPolicy(\n runtime: BuiltRuntime,\n importPolicy: AppRouterImportPolicy | undefined,\n): AppRouterImportPolicy | undefined {\n const generatedImportPolicy = runtime.generatedImportPolicy;\n\n if (generatedImportPolicy === undefined) {\n return importPolicy;\n }\n\n const allowedPackages = [\n ...new Set([\n ...(generatedImportPolicy.allowedPackages ?? []),\n ...(importPolicy?.allowedPackages ?? []),\n ]),\n ];\n\n return {\n ...(allowedPackages.length === 0 ? {} : { allowedPackages }),\n ...(importPolicy?.allowedSourceDirs === undefined\n ? {}\n : { allowedSourceDirs: importPolicy.allowedSourceDirs }),\n ...(importPolicy?.projectRoot === undefined ? {} : { projectRoot: importPolicy.projectRoot }),\n };\n}\n\nfunction builtGeneratedImportPolicy(\n importPolicyText: string | undefined,\n importPolicyPath: string,\n): AppRouterImportPolicy | undefined {\n if (importPolicyText === undefined) {\n return undefined;\n }\n\n const artifact = parseBuiltJsonArtifact<{\n runtimePackages?: unknown;\n }>(importPolicyText, importPolicyPath, \"built app import policy\");\n const runtimePackages = Array.isArray(artifact.runtimePackages)\n ? artifact.runtimePackages.filter((name): name is string => typeof name === \"string\")\n : [];\n\n return runtimePackages.length === 0 ? undefined : { allowedPackages: runtimePackages };\n}\n\nasync function materializeBuiltServerApp(\n runtimeDir: string,\n manifest: BuiltServerManifest,\n): Promise<string> {\n const appDir = join(runtimeDir, \"app\");\n\n await rm(appDir, { force: true, recursive: true });\n await Promise.all(\n Object.entries(manifest.files).map(async ([file, code]) => {\n const outputFile = join(appDir, safeManifestFilePath(file));\n\n await mkdir(dirname(outputFile), { recursive: true });\n await writeFile(outputFile, code);\n }),\n );\n\n return appDir;\n}\n\nfunction isMissingFileError(error: unknown): boolean {\n return (\n typeof error === \"object\" &&\n error !== null &&\n \"code\" in error &&\n (error as { code?: unknown }).code === \"ENOENT\"\n );\n}\n\nfunction builtArtifactReadError(label: string, artifactPath: string, error: unknown): Error {\n const prefix = isMissingFileError(error) ? \"Missing\" : \"Unable to read\";\n const detail = error instanceof Error && error.message !== \"\" ? `: ${error.message}` : \"\";\n\n return new Error(`${prefix} ${label}: ${artifactPath}${detail}`, { cause: error });\n}\n\nfunction parseBuiltJsonArtifact<T>(text: string, artifactPath: string, label: string): T {\n try {\n return JSON.parse(text) as T;\n } catch (error) {\n const detail = error instanceof Error && error.message !== \"\" ? `: ${error.message}` : \"\";\n\n throw new Error(`Invalid ${label}: ${artifactPath}${detail}`, { cause: error });\n }\n}\n\nfunction safeManifestFilePath(pathname: string): string {\n const normalized = normalize(pathname);\n\n if (isAbsolute(normalized) || normalized === \"..\" || normalized.startsWith(\"../\")) {\n throw new Error(`Invalid built app manifest file path: ${pathname}`);\n }\n\n return normalized;\n}\n"]}
|
package/dist/cache.d.ts
CHANGED
|
@@ -20,8 +20,31 @@ export interface AppRouterCacheEntry {
|
|
|
20
20
|
body: string;
|
|
21
21
|
cacheControl: string;
|
|
22
22
|
expiresAt: number;
|
|
23
|
+
/**
|
|
24
|
+
* Response headers to replay on a cache hit.
|
|
25
|
+
*
|
|
26
|
+
* Metadata-derived security headers such as `content-security-policy`,
|
|
27
|
+
* `x-frame-options` and `x-content-type-options` live here, so that turning a
|
|
28
|
+
* route into a cached one does not quietly drop them.
|
|
29
|
+
*/
|
|
30
|
+
headers?: Record<string, string> | undefined;
|
|
23
31
|
path: string;
|
|
32
|
+
/**
|
|
33
|
+
* Identifies entries that preserve the complete current cache contract.
|
|
34
|
+
*
|
|
35
|
+
* Missing markers are treated as cache misses so HTML written by older
|
|
36
|
+
* runtimes, or custom serializers that drop new security fields, is never
|
|
37
|
+
* replayed under the current security rules.
|
|
38
|
+
*/
|
|
39
|
+
schemaVersion?: 2 | undefined;
|
|
24
40
|
status: number;
|
|
41
|
+
/**
|
|
42
|
+
* Strict-Transport-Security value to replay to secure requests only.
|
|
43
|
+
*
|
|
44
|
+
* It is kept out of `headers` because it depends on the scheme of the
|
|
45
|
+
* request that produced the entry, which the cache key does not cover.
|
|
46
|
+
*/
|
|
47
|
+
strictTransportSecurity?: string | undefined;
|
|
25
48
|
}
|
|
26
49
|
/**
|
|
27
50
|
* Defines the storage interface used by app-router route response caching.
|
|
@@ -66,12 +89,15 @@ export declare function cachedRouteResponse(options: {
|
|
|
66
89
|
}): Promise<Response | undefined>;
|
|
67
90
|
export declare function cacheRouteResponse(options: {
|
|
68
91
|
cache?: AppRouterCache | undefined;
|
|
92
|
+
headerDependent?: boolean | undefined;
|
|
69
93
|
key: string;
|
|
70
94
|
now?: number;
|
|
71
95
|
path: string;
|
|
72
96
|
policy: RouteCachePolicy | undefined;
|
|
73
97
|
request?: Request | undefined;
|
|
74
98
|
response: Response;
|
|
99
|
+
/** Configured Strict-Transport-Security value, independent of this request's scheme. */
|
|
100
|
+
strictTransportSecurity?: string | undefined;
|
|
75
101
|
}): Promise<Response>;
|
|
76
102
|
/**
|
|
77
103
|
* Invalidates cached route responses for a normalized app-router path.
|
package/dist/cache.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,YAAY,EAAE,MAAM,CAAC;IACrB,iBAAiB,EAAE,MAAM,CAAC;CAC3B;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,oBAAoB,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAAC;CACrD;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,WAAW,gBAAg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ACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAUjD;AAED,wBAAsB,oBAAoB,CACxC,KAAK,GAAE,cAAuC,GAC7C,OAAO,CAAC,IAAI,CAAC,CAUf;AAED,wBAAsB,qBAAqB,CAAC,CAAC,EAC3C,KAAK,EAAE,cAAc,GAAG,SAAS,EACjC,EAAE,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,GACvB,OAAO,CAAC;IAAE,WAAW,EAAE,gBAAgB,GAAG,SAAS,CAAC;IAAC,gBAAgB,EAAE,MAAM,EAAE,CAAC;IAAC,KAAK,EAAE,CAAC,CAAA;CAAE,CAAC,CAsB9F;AAED,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,cAAc,GAAG,SAAS,GAAG;IACzE,QAAQ,CAAC,WAAW,EAAE,gBAAgB,GAAG,SAAS,CAAC;IACnD,OAAO,IAAI,OAAO,CAAC;QAAE,gBAAgB,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC,CAAC;CACpD,CA6BA;AAED,wBAAgB,uBAAuB,IAAI,iBAAiB,GAAG,SAAS,CAgBvE;AAMD,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,GAAG,MAAM,CAEjF;AAED,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE1D"}
|
package/dist/cache.js
CHANGED
|
@@ -163,15 +163,25 @@ export function cachedRouteResponse(options) {
|
|
|
163
163
|
await consumeInvalidations(cache);
|
|
164
164
|
const now = options.now ?? Date.now();
|
|
165
165
|
const cached = await cache.get(options.key, now);
|
|
166
|
-
if (cached === undefined ||
|
|
166
|
+
if (cached === undefined ||
|
|
167
|
+
cached.expiresAt <= now ||
|
|
168
|
+
cached.schemaVersion !== ROUTE_CACHE_ENTRY_SCHEMA_VERSION ||
|
|
169
|
+
!isStringRecord(cached.headers)) {
|
|
167
170
|
return undefined;
|
|
168
171
|
}
|
|
172
|
+
const headers = new Headers(cached.headers ?? {});
|
|
173
|
+
headers.set("cache-control", cached.cacheControl);
|
|
174
|
+
if (!headers.has("content-type")) {
|
|
175
|
+
headers.set("content-type", "text/html; charset=utf-8");
|
|
176
|
+
}
|
|
177
|
+
headers.set("x-mreact-cache", "HIT");
|
|
178
|
+
// Replayed against the scheme of the request being served, not the one
|
|
179
|
+
// that produced the entry.
|
|
180
|
+
if (cached.strictTransportSecurity !== undefined && isSecureRequest(options.request)) {
|
|
181
|
+
headers.set(HSTS_HEADER, cached.strictTransportSecurity);
|
|
182
|
+
}
|
|
169
183
|
return new Response(cached.body, {
|
|
170
|
-
headers
|
|
171
|
-
"cache-control": cached.cacheControl,
|
|
172
|
-
"content-type": "text/html; charset=utf-8",
|
|
173
|
-
"x-mreact-cache": "HIT",
|
|
174
|
-
},
|
|
184
|
+
headers,
|
|
175
185
|
status: cached.status,
|
|
176
186
|
});
|
|
177
187
|
});
|
|
@@ -181,6 +191,16 @@ export async function cacheRouteResponse(options) {
|
|
|
181
191
|
return options.response;
|
|
182
192
|
}
|
|
183
193
|
if (options.policy.revalidateSeconds === 0) {
|
|
194
|
+
// No entry is stored here, but cacheControl({ maxAge }) still emits a bare
|
|
195
|
+
// max-age that a shared cache may store, so a header dependent render has
|
|
196
|
+
// to opt out of that too. Directives that already keep the response out of
|
|
197
|
+
// shared caches are left exactly as the application asked for them.
|
|
198
|
+
const sharedCacheMayStore = !/(^|,)\s*(private|no-store)\s*(,|$)/.test(options.policy.cacheControl);
|
|
199
|
+
if (options.headerDependent === true && sharedCacheMayStore) {
|
|
200
|
+
options.response.headers.set("cache-control", "private, no-store");
|
|
201
|
+
options.response.headers.set("x-mreact-cache", "DYNAMIC");
|
|
202
|
+
return options.response;
|
|
203
|
+
}
|
|
184
204
|
options.response.headers.set("cache-control", options.policy.cacheControl);
|
|
185
205
|
return options.response;
|
|
186
206
|
}
|
|
@@ -188,34 +208,80 @@ export async function cacheRouteResponse(options) {
|
|
|
188
208
|
const cacheControl = options.policy.cacheControl;
|
|
189
209
|
const status = options.response.status;
|
|
190
210
|
const contentType = options.response.headers.get("content-type") ?? "text/html; charset=utf-8";
|
|
191
|
-
|
|
211
|
+
// A render that read a request header only produced HTML that is correct for
|
|
212
|
+
// that header value. The cache key covers the path and query alone, so the
|
|
213
|
+
// entry cannot be shared; the response is marked uncacheable for downstream
|
|
214
|
+
// shared caches too, which are keyed the same way.
|
|
215
|
+
if (options.headerDependent === true ||
|
|
216
|
+
requestCarriesCredentials(options.request) ||
|
|
192
217
|
options.response.headers.has("set-cookie")) {
|
|
193
218
|
const headers = new Headers(options.response.headers);
|
|
194
219
|
headers.set("cache-control", "private, no-store");
|
|
195
220
|
if (!headers.has("content-type")) {
|
|
196
221
|
headers.set("content-type", contentType);
|
|
197
222
|
}
|
|
223
|
+
if (options.headerDependent === true) {
|
|
224
|
+
headers.set("x-mreact-cache", "DYNAMIC");
|
|
225
|
+
}
|
|
198
226
|
return new Response(body, {
|
|
199
227
|
headers,
|
|
200
228
|
status,
|
|
201
229
|
});
|
|
202
230
|
}
|
|
231
|
+
// Metadata-derived security headers are part of the rendered response, so
|
|
232
|
+
// they are stored with it and replayed on a hit rather than dropped by the
|
|
233
|
+
// rebuilt cache response. Strict-Transport-Security is kept apart because it
|
|
234
|
+
// is derived from the scheme of whichever request missed and the key does not
|
|
235
|
+
// cover the scheme: it is replayed only to requests that are themselves
|
|
236
|
+
// secure, instead of pinning one visitor's scheme onto the entry.
|
|
237
|
+
const storedHeaders = {};
|
|
238
|
+
options.response.headers.forEach((value, key) => {
|
|
239
|
+
if (key !== "cache-control" && key !== "x-mreact-cache" && key !== HSTS_HEADER) {
|
|
240
|
+
storedHeaders[key] = value;
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
// Taken from the route's configuration rather than from this response, whose
|
|
244
|
+
// HSTS header is present only when this particular request was secure. Using
|
|
245
|
+
// the response would let one plain request pin an entry that withholds HSTS
|
|
246
|
+
// from every later secure visitor.
|
|
247
|
+
const hsts = options.strictTransportSecurity;
|
|
203
248
|
await (options.cache ?? cacheState.memoryCache).set(options.key, {
|
|
204
249
|
body,
|
|
205
250
|
cacheControl,
|
|
206
251
|
expiresAt: (options.now ?? Date.now()) + options.policy.revalidateSeconds * 1000,
|
|
252
|
+
headers: storedHeaders,
|
|
253
|
+
...(hsts === undefined ? {} : { strictTransportSecurity: hsts }),
|
|
207
254
|
path: normalizeRevalidationPath(options.path),
|
|
255
|
+
schemaVersion: ROUTE_CACHE_ENTRY_SCHEMA_VERSION,
|
|
208
256
|
status,
|
|
209
257
|
});
|
|
258
|
+
const headers = new Headers(storedHeaders);
|
|
259
|
+
headers.set("cache-control", cacheControl);
|
|
260
|
+
if (!headers.has("content-type")) {
|
|
261
|
+
headers.set("content-type", contentType);
|
|
262
|
+
}
|
|
263
|
+
headers.set("x-mreact-cache", "MISS");
|
|
264
|
+
if (hsts !== undefined && isSecureRequest(options.request)) {
|
|
265
|
+
headers.set(HSTS_HEADER, hsts);
|
|
266
|
+
}
|
|
210
267
|
return new Response(body, {
|
|
211
|
-
headers
|
|
212
|
-
"cache-control": cacheControl,
|
|
213
|
-
"content-type": contentType,
|
|
214
|
-
"x-mreact-cache": "MISS",
|
|
215
|
-
},
|
|
268
|
+
headers,
|
|
216
269
|
status,
|
|
217
270
|
});
|
|
218
271
|
}
|
|
272
|
+
const HSTS_HEADER = "strict-transport-security";
|
|
273
|
+
const ROUTE_CACHE_ENTRY_SCHEMA_VERSION = 2;
|
|
274
|
+
function isStringRecord(value) {
|
|
275
|
+
return (typeof value === "object" &&
|
|
276
|
+
value !== null &&
|
|
277
|
+
!Array.isArray(value) &&
|
|
278
|
+
Object.values(value).every((entry) => typeof entry === "string"));
|
|
279
|
+
}
|
|
280
|
+
function isSecureRequest(request) {
|
|
281
|
+
// `Request.url` is always absolute, so this avoids parsing a URL on the
|
|
282
|
+
// cache-hit hot path.
|
|
283
|
+
return request?.url.startsWith("https://") === true;
|
|
284
|
+
}
|
|
219
285
|
function requestCarriesCredentials(request) {
|
|
220
286
|
if (request === undefined) {
|
|
221
287
|
return false;
|
package/dist/cache.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cache.js","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAgErD,MAAM,UAAU,GAAG,CACjB,UACD,CAAC,sBAAsB,KAAK;IAC3B,cAAc,EAAE,EAAE;IAClB,gBAAgB,EAAE,IAAI,GAAG,EAAE;IAC3B,WAAW,EAAE,sBAAsB,EAAE;IACrC,OAAO,EAAE,IAAI,iBAAiB,EAAqB;CACpD,CAAC,CAAC;AACH,UAAU,CAAC,OAAO,KAAK,IAAI,iBAAiB,EAAqB,CAAC;AAElE;;;;GAIG;AACH,MAAM,UAAU,sBAAsB,CAAC,OAAO,GAA4B,EAAE;IAC1E,MAAM,UAAU,GAAG,wBAAwB,CAAC,OAAO,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;IACxE,MAAM,eAAe,GAAG,2BAA2B,CAAC,OAAO,CAAC,eAAe,EAAE,MAAM,CAAC,CAAC;IACrF,MAAM,YAAY,GAAG,IAAI,GAAG,EAA+B,CAAC;IAC5D,MAAM,UAAU,GAAG,IAAI,GAAG,EAAuB,CAAC;IAClD,IAAI,WAAW,GAAG,CAAC,CAAC;IAEpB,SAAS,UAAU,CAAC,GAAW,EAAE,IAAY;QAC3C,MAAM,IAAI,GAAG,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAClC,IAAI,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC;QAElB,IAAI,IAAI,EAAE,IAAI,KAAK,CAAC,EAAE,CAAC;YACrB,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC1B,CAAC;IACH,CAAC;IAED,SAAS,WAAW,CAAC,GAAW;QAC9B,MAAM,KAAK,GAAG,YAAY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C;QACpB,MAAM,IAAI,KAAK,CAAC,6EAA6E,CAAC,CAAC;IACjG,CAAC;IAED,MAAM,OAAO,GAAG,mBAAmB,CAAC,KAAK,EAAE,sBAAsB,CAAC,CAAC;IACnE,OAAO,0BAA0B,OAAO,EAAE,CAAC;AAC7C,CAAC","sourcesContent":["import { AsyncLocalStorage } from \"node:async_hooks\";\n\n/**\n * Describes the cache lifetime assigned to a rendered route response.\n */\nexport interface RouteCachePolicy {\n cacheControl: string;\n revalidateSeconds: number;\n}\n\n/**\n * Configures cache-control directives for route response caching.\n */\nexport interface CacheControlOptions {\n maxAge?: number | undefined;\n sMaxAge?: number | undefined;\n staleWhileRevalidate?: boolean | number | undefined;\n}\n\n/**\n * Stores a cached route response body and its expiration metadata.\n */\nexport interface AppRouterCacheEntry {\n body: string;\n cacheControl: string;\n expiresAt: number;\n path: string;\n status: number;\n}\n\n/**\n * Defines the storage interface used by app-router route response caching.\n */\nexport interface AppRouterCache {\n deleteByPath(path: string): void | Promise<void>;\n get(\n key: string,\n now?: number,\n ): AppRouterCacheEntry | undefined | Promise<AppRouterCacheEntry | undefined>;\n set(key: string, entry: AppRouterCacheEntry): void | Promise<void>;\n}\n\n/**\n * Configures the process-local in-memory route cache implementation.\n */\nexport interface MemoryRouteCacheOptions {\n maxEntries?: number;\n sweepIntervalMs?: number;\n}\n\ninterface AppRouterCacheState {\n activeContexts: RouteCacheContext[];\n invalidatedPaths: Set<string>;\n memoryCache: AppRouterCache;\n storage: AsyncLocalStorage<RouteCacheContext>;\n}\n\ninterface RouteCacheContext {\n cache: AppRouterCache;\n cachePolicy?: RouteCachePolicy | undefined;\n closed?: boolean | undefined;\n revalidatedPaths: Set<string>;\n}\n\nconst cacheState = ((\n globalThis as { __mreactAppRouterCache?: AppRouterCacheState }\n).__mreactAppRouterCache ??= {\n activeContexts: [],\n invalidatedPaths: new Set(),\n memoryCache: createMemoryRouteCache(),\n storage: new AsyncLocalStorage<RouteCacheContext>(),\n});\ncacheState.storage ??= new AsyncLocalStorage<RouteCacheContext>();\n\n/**\n * Creates an in-memory route response cache for app-router rendering.\n *\n * The cache is process-local, evicts expired entries during reads/writes, and is suitable for development, tests, or single-process deployments that do not need shared invalidation.\n */\nexport function createMemoryRouteCache(options: MemoryRouteCacheOptions = {}): AppRouterCache {\n const maxEntries = positiveIntegerOrDefault(options.maxEntries, 10_000);\n const sweepIntervalMs = nonNegativeIntegerOrDefault(options.sweepIntervalMs, 60_000);\n const cachedRoutes = new Map<string, AppRouterCacheEntry>();\n const keysByPath = new Map<string, Set<string>>();\n let nextSweepAt = 0;\n\n function unindexKey(key: string, path: string): void {\n const keys = keysByPath.get(path);\n keys?.delete(key);\n\n if (keys?.size === 0) {\n keysByPath.delete(path);\n }\n }\n\n function deleteEntry(key: string): void {\n const entry = cachedRoutes.get(key);\n cachedRoutes.delete(key);\n\n if (entry !== undefined) {\n unindexKey(key, entry.path);\n }\n }\n\n function indexKey(key: string, path: string): void {\n const keys = keysByPath.get(path);\n\n if (keys === undefined) {\n keysByPath.set(path, new Set([key]));\n return;\n }\n\n keys.add(key);\n }\n\n function sweepExpired(now: number): void {\n for (const [key, entry] of cachedRoutes) {\n if (entry.expiresAt <= now) {\n deleteEntry(key);\n }\n }\n\n nextSweepAt = now + sweepIntervalMs;\n }\n\n function maybeSweepExpired(now: number): void {\n if (sweepIntervalMs === 0 || now >= nextSweepAt) {\n sweepExpired(now);\n }\n }\n\n function evictOldestEntries(): void {\n while (cachedRoutes.size > maxEntries) {\n const oldestKey = cachedRoutes.keys().next().value;\n\n if (oldestKey === undefined) {\n return;\n }\n\n deleteEntry(oldestKey);\n }\n }\n\n return {\n deleteByPath(path) {\n const normalizedPath = normalizeRevalidationPath(path);\n const keys = keysByPath.get(normalizedPath);\n\n if (keys === undefined) {\n return;\n }\n\n for (const key of keys) {\n cachedRoutes.delete(key);\n }\n\n keysByPath.delete(normalizedPath);\n },\n get(key, now = Date.now()) {\n const entry = cachedRoutes.get(key);\n\n if (entry === undefined) {\n return undefined;\n }\n\n if (entry.expiresAt <= now) {\n deleteEntry(key);\n return undefined;\n }\n\n return entry;\n },\n set(key, entry) {\n const now = Date.now();\n maybeSweepExpired(now);\n const previous = cachedRoutes.get(key);\n\n if (previous !== undefined) {\n cachedRoutes.delete(key);\n unindexKey(key, previous.path);\n }\n\n cachedRoutes.set(key, entry);\n indexKey(key, entry.path);\n\n if (cachedRoutes.size > maxEntries) {\n sweepExpired(now);\n evictOldestEntries();\n }\n },\n };\n}\n\nfunction positiveIntegerOrDefault(value: number | undefined, fallback: number): number {\n return value === undefined || !Number.isInteger(value) || value < 1 ? fallback : value;\n}\n\nfunction nonNegativeIntegerOrDefault(value: number | undefined, fallback: number): number {\n return value === undefined || !Number.isInteger(value) || value < 0 ? fallback : value;\n}\n\nexport function routeCachePolicyFromSource(code: string): RouteCachePolicy | undefined {\n const match = /^\\s*export\\s+const\\s+revalidate\\s*=\\s*(?<seconds>\\d+)\\s*;?\\s*$/m.exec(code);\n const seconds = match?.groups?.seconds === undefined ? undefined : Number(match.groups.seconds);\n\n if (seconds === undefined || !Number.isFinite(seconds)) {\n if (/^\\s*export\\s+const\\s+revalidate\\s*=/m.test(code)) {\n console.warn(\n \"export const revalidate must be a plain integer literal, e.g. export const revalidate = 3600\",\n );\n }\n return undefined;\n }\n\n return {\n cacheControl: seconds === 0 ? \"no-store\" : `s-maxage=${seconds}, stale-while-revalidate`,\n revalidateSeconds: seconds,\n };\n}\n\n/**\n * Sets the cache policy for the current app-router render.\n *\n * Call this during a loader or route render to override the response `Cache-Control` policy; it throws outside an active app-router request.\n */\nexport function cacheControl(options: CacheControlOptions): void {\n const activeContext = activeRouteCacheContext();\n\n if (activeContext === undefined) {\n throw new Error(\"cacheControl() must be called during an app router request.\");\n }\n\n activeContext.cachePolicy = routeCachePolicyFromOptions(options);\n}\n\nexport function routeCachePolicyFromOptions(options: CacheControlOptions): RouteCachePolicy {\n const directives: string[] = [];\n const maxAge = cacheControlSeconds(options.maxAge, \"maxAge\");\n const sMaxAge = cacheControlSeconds(options.sMaxAge, \"sMaxAge\");\n\n if (maxAge !== undefined) {\n directives.push(`max-age=${maxAge}`);\n }\n\n if (sMaxAge !== undefined) {\n directives.push(`s-maxage=${sMaxAge}`);\n }\n\n if (options.staleWhileRevalidate !== undefined) {\n directives.push(staleWhileRevalidateDirective(options.staleWhileRevalidate));\n }\n\n if (directives.length === 0) {\n throw new Error(\"cacheControl() requires at least one cache directive.\");\n }\n\n return {\n cacheControl: directives.join(\", \"),\n revalidateSeconds: sMaxAge ?? 0,\n };\n}\n\nexport function cachedRouteResponse(options: {\n cache?: AppRouterCache | undefined;\n key: string;\n now?: number;\n request?: Request | undefined;\n}): Promise<Response | undefined> {\n return Promise.resolve().then(async () => {\n if (requestCarriesCredentials(options.request)) {\n return undefined;\n }\n\n const cache = options.cache ?? cacheState.memoryCache;\n\n await consumeInvalidations(cache);\n const now = options.now ?? Date.now();\n const cached = await cache.get(options.key, now);\n\n if (cached === undefined || cached.expiresAt <= now) {\n return undefined;\n }\n\n return new Response(cached.body, {\n headers: {\n \"cache-control\": cached.cacheControl,\n \"content-type\": \"text/html; charset=utf-8\",\n \"x-mreact-cache\": \"HIT\",\n },\n status: cached.status,\n });\n });\n}\n\nexport async function cacheRouteResponse(options: {\n cache?: AppRouterCache | undefined;\n key: string;\n now?: number;\n path: string;\n policy: RouteCachePolicy | undefined;\n request?: Request | undefined;\n response: Response;\n}): Promise<Response> {\n if (options.policy === undefined) {\n return options.response;\n }\n\n if (options.policy.revalidateSeconds === 0) {\n options.response.headers.set(\"cache-control\", options.policy.cacheControl);\n return options.response;\n }\n\n const body = await options.response.text();\n const cacheControl = options.policy.cacheControl;\n const status = options.response.status;\n const contentType = options.response.headers.get(\"content-type\") ?? \"text/html; charset=utf-8\";\n\n if (\n requestCarriesCredentials(options.request) ||\n options.response.headers.has(\"set-cookie\")\n ) {\n const headers = new Headers(options.response.headers);\n headers.set(\"cache-control\", \"private, no-store\");\n if (!headers.has(\"content-type\")) {\n headers.set(\"content-type\", contentType);\n }\n\n return new Response(body, {\n headers,\n status,\n });\n }\n\n await (options.cache ?? cacheState.memoryCache).set(options.key, {\n body,\n cacheControl,\n expiresAt: (options.now ?? Date.now()) + options.policy.revalidateSeconds * 1000,\n path: normalizeRevalidationPath(options.path),\n status,\n });\n\n return new Response(body, {\n headers: {\n \"cache-control\": cacheControl,\n \"content-type\": contentType,\n \"x-mreact-cache\": \"MISS\",\n },\n status,\n });\n}\n\nfunction requestCarriesCredentials(request: Request | undefined): boolean {\n if (request === undefined) {\n return false;\n }\n\n if (request.headers.has(\"authorization\") || request.headers.has(\"cookie\")) {\n return true;\n }\n\n for (const name of request.headers.keys()) {\n const lower = name.toLowerCase();\n if (PUBLIC_ROUTE_CACHE_REQUEST_HEADERS.has(lower)) {\n continue;\n }\n\n if (\n lower === \"x-api-key\" ||\n lower === \"cf-access-jwt-assertion\" ||\n lower === \"proxy-authorization\" ||\n lower === \"x-access-token\" ||\n lower === \"x-auth-token\" ||\n lower === \"x-authenticated-user\" ||\n lower === \"x-id-token\" ||\n lower === \"x-forwarded-user\" ||\n lower === \"x-session-id\" ||\n lower === \"x-user-email\" ||\n lower === \"x-user-id\" ||\n lower.endsWith(\"-api-key\") ||\n lower.endsWith(\"-auth-token\") ||\n lower.endsWith(\"-session-id\") ||\n lower.endsWith(\"-user\") ||\n lower.endsWith(\"-user-email\") ||\n lower.endsWith(\"-user-id\") ||\n lower.includes(\"-jwt-\") ||\n lower.endsWith(\"-jwt\")\n ) {\n return true;\n }\n\n continue;\n }\n\n return false;\n}\n\nconst PUBLIC_ROUTE_CACHE_REQUEST_HEADERS = new Set([\n \"accept\",\n \"accept-encoding\",\n \"accept-language\",\n \"cache-control\",\n \"cf-connecting-ip\",\n \"cf-ipcountry\",\n \"cf-ray\",\n \"connection\",\n \"dnt\",\n \"host\",\n \"if-none-match\",\n \"pragma\",\n \"priority\",\n \"purpose\",\n \"referer\",\n \"save-data\",\n \"sec-ch-prefers-color-scheme\",\n \"sec-ch-prefers-reduced-motion\",\n \"sec-ch-ua\",\n \"sec-ch-ua-mobile\",\n \"sec-ch-ua-platform\",\n \"sec-fetch-dest\",\n \"sec-fetch-mode\",\n \"sec-fetch-site\",\n \"sec-fetch-user\",\n \"upgrade-insecure-requests\",\n \"user-agent\",\n \"via\",\n \"x-mreact-navigation\",\n \"x-mreact-navigation-cache\",\n \"x-real-ip\",\n \"x-request-id\",\n \"x-forwarded-for\",\n \"x-forwarded-host\",\n \"x-forwarded-proto\",\n]);\n\n/**\n * Invalidates cached route responses for a normalized app-router path.\n *\n * During a request the invalidation is scoped to that route cache context; outside a request it is queued for the next cache access.\n */\nexport function revalidatePath(path: string): void {\n const normalizedPath = normalizeRevalidationPath(path);\n const activeContext = activeRouteCacheContext();\n\n if (activeContext !== undefined) {\n activeContext.revalidatedPaths.add(normalizedPath);\n return;\n }\n\n cacheState.invalidatedPaths.add(normalizedPath);\n}\n\nexport async function consumeInvalidations(\n cache: AppRouterCache = cacheState.memoryCache,\n): Promise<void> {\n if (cacheState.invalidatedPaths.size === 0) {\n return;\n }\n\n for (const path of cacheState.invalidatedPaths) {\n await cache.deleteByPath(path);\n }\n\n cacheState.invalidatedPaths.clear();\n}\n\nexport async function withRouteCacheContext<T>(\n cache: AppRouterCache | undefined,\n fn: () => T | Promise<T>,\n): Promise<{ cachePolicy: RouteCachePolicy | undefined; revalidatedPaths: string[]; value: T }> {\n const context: RouteCacheContext = {\n cache: cache ?? cacheState.memoryCache,\n revalidatedPaths: new Set(),\n };\n\n return cacheState.storage.run(context, async () => {\n try {\n const value = await fn();\n context.closed = true;\n const cachePolicy = context.cachePolicy;\n const revalidatedPaths = Array.from(context.revalidatedPaths);\n\n for (const path of revalidatedPaths) {\n await context.cache.deleteByPath(path);\n }\n\n return { cachePolicy, revalidatedPaths, value };\n } finally {\n context.closed = true;\n }\n });\n}\n\nexport function beginRouteCacheContext(cache: AppRouterCache | undefined): {\n readonly cachePolicy: RouteCachePolicy | undefined;\n dispose(): Promise<{ revalidatedPaths: string[] }>;\n} {\n const context: RouteCacheContext = {\n cache: cache ?? cacheState.memoryCache,\n revalidatedPaths: new Set(),\n };\n\n cacheState.activeContexts.push(context);\n\n return {\n get cachePolicy() {\n return context.cachePolicy;\n },\n async dispose() {\n context.closed = true;\n const revalidatedPaths = Array.from(context.revalidatedPaths);\n try {\n for (const path of revalidatedPaths) {\n await context.cache.deleteByPath(path);\n }\n } finally {\n const index = cacheState.activeContexts.lastIndexOf(context);\n if (index !== -1) {\n cacheState.activeContexts.splice(index, 1);\n }\n }\n\n return { revalidatedPaths };\n },\n };\n}\n\nexport function activeRouteCacheContext(): RouteCacheContext | undefined {\n const asyncContext = cacheState.storage.getStore();\n\n if (asyncContext !== undefined) {\n return asyncContext.closed === true ? undefined : asyncContext;\n }\n\n for (let index = cacheState.activeContexts.length - 1; index >= 0; index -= 1) {\n const context = cacheState.activeContexts[index];\n\n if (context?.closed !== true) {\n return context;\n }\n }\n\n return undefined;\n}\n\n// Host is excluded from the cache key to prevent attacker-supplied Host\n// headers from fragmenting / poisoning the cache (Issue 068). The Vary\n// dimension is the request path + query; same-origin reverse proxies are\n// expected to handle vhost separation at their layer.\nexport function routeCacheKey(appDir: string, routePath: string, url: URL): string {\n return `${appDir}\\0${normalizeRevalidationPath(routePath)}\\0${url.pathname}${url.search}`;\n}\n\nexport function stripRevalidateExport(code: string): string {\n return code.replace(/^\\s*export\\s+const\\s+revalidate\\s*=\\s*\\d+\\s*;?\\s*$/m, \"\");\n}\n\nfunction normalizeRevalidationPath(path: string): string {\n const pathname = path.startsWith(\"/\") ? path : `/${path}`;\n const withoutTrailing = pathname.length > 1 ? pathname.replace(/\\/+$/, \"\") : pathname;\n\n return withoutTrailing === \"\" ? \"/\" : withoutTrailing;\n}\n\nfunction cacheControlSeconds(value: number | undefined, name: string): number | undefined {\n if (value === undefined) {\n return undefined;\n }\n\n if (!Number.isSafeInteger(value) || value < 0) {\n throw new Error(`cacheControl() ${name} must be a non-negative integer.`);\n }\n\n return value;\n}\n\nfunction staleWhileRevalidateDirective(value: boolean | number): string {\n if (value === true) {\n return \"stale-while-revalidate\";\n }\n\n if (value === false) {\n throw new Error(\"cacheControl() staleWhileRevalidate must be true or a non-negative integer.\");\n }\n\n const seconds = cacheControlSeconds(value, \"staleWhileRevalidate\");\n return `stale-while-revalidate=${seconds}`;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"cache.js","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAuFrD,MAAM,UAAU,GAAG,CACjB,UACD,CAAC,sBAAsB,KAAK;IAC3B,cAAc,EAAE,EAAE;IAClB,gBAAgB,EAAE,IAAI,GAAG,EAAE;IAC3B,WAAW,EAAE,sBAAsB,EAAE;IACrC,OAAO,EAAE,IAAI,iBAAiB,EAAqB;CACpD,CAAC,CAAC;AACH,UAAU,CAAC,OAAO,KAAK,IAAI,iBAAiB,EAAqB,CAAC;AAElE;;;;GAIG;AACH,MAAM,UAAU,sBAAsB,CAAC,OAAO,GAA4B,EAAE;IAC1E,MAAM,UAAU,GAAG,wBAAwB,CAAC,OAAO,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;IACxE,MAAM,eAAe,GAAG,2BAA2B,CAAC,OAAO,CAAC,eAAe,EAAE,MAAM,CAAC,CAAC;IACrF,MAAM,YAAY,GAAG,IAAI,GAAG,EAA+B,CAAC;IAC5D,MAAM,UAAU,GAAG,IAAI,GAAG,EAAuB,CAAC;IAClD,IAAI,WAAW,GAAG,CAAC,CAAC;IAEpB,SAAS,UAAU,CAAC,GAAW,EAAE,IAAY;QAC3C,MAAM,IAAI,GAAG,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAClC,IAAI,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC;QAElB,IAAI,IAAI,EAAE,IAAI,KAAK,CAAC,EAAE,CAAC;YACrB,UAAU,CAAC,MAAM,C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AS,mBAAmB,CAAC,KAAyB,EAAE,IAAY;IAClE,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACxB,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;QAC9C,MAAM,IAAI,KAAK,CAAC,kBAAkB,IAAI,kCAAkC,CAAC,CAAC;IAC5E,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,6BAA6B,CAAC,KAAuB;IAC5D,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QACnB,OAAO,wBAAwB,CAAC;IAClC,CAAC;IAED,IAAI,KAAK,KAAK,KAAK,EAAE,CAAC;QACpB,MAAM,IAAI,KAAK,CAAC,6EAA6E,CAAC,CAAC;IACjG,CAAC;IAED,MAAM,OAAO,GAAG,mBAAmB,CAAC,KAAK,EAAE,sBAAsB,CAAC,CAAC;IACnE,OAAO,0BAA0B,OAAO,EAAE,CAAC;AAC7C,CAAC","sourcesContent":["import { AsyncLocalStorage } from \"node:async_hooks\";\n\n/**\n * Describes the cache lifetime assigned to a rendered route response.\n */\nexport interface RouteCachePolicy {\n cacheControl: string;\n revalidateSeconds: number;\n}\n\n/**\n * Configures cache-control directives for route response caching.\n */\nexport interface CacheControlOptions {\n maxAge?: number | undefined;\n sMaxAge?: number | undefined;\n staleWhileRevalidate?: boolean | number | undefined;\n}\n\n/**\n * Stores a cached route response body and its expiration metadata.\n */\nexport interface AppRouterCacheEntry {\n body: string;\n cacheControl: string;\n expiresAt: number;\n /**\n * Response headers to replay on a cache hit.\n *\n * Metadata-derived security headers such as `content-security-policy`,\n * `x-frame-options` and `x-content-type-options` live here, so that turning a\n * route into a cached one does not quietly drop them.\n */\n headers?: Record<string, string> | undefined;\n path: string;\n /**\n * Identifies entries that preserve the complete current cache contract.\n *\n * Missing markers are treated as cache misses so HTML written by older\n * runtimes, or custom serializers that drop new security fields, is never\n * replayed under the current security rules.\n */\n schemaVersion?: 2 | undefined;\n status: number;\n /**\n * Strict-Transport-Security value to replay to secure requests only.\n *\n * It is kept out of `headers` because it depends on the scheme of the\n * request that produced the entry, which the cache key does not cover.\n */\n strictTransportSecurity?: string | undefined;\n}\n\n/**\n * Defines the storage interface used by app-router route response caching.\n */\nexport interface AppRouterCache {\n deleteByPath(path: string): void | Promise<void>;\n get(\n key: string,\n now?: number,\n ): AppRouterCacheEntry | undefined | Promise<AppRouterCacheEntry | undefined>;\n set(key: string, entry: AppRouterCacheEntry): void | Promise<void>;\n}\n\n/**\n * Configures the process-local in-memory route cache implementation.\n */\nexport interface MemoryRouteCacheOptions {\n maxEntries?: number;\n sweepIntervalMs?: number;\n}\n\ninterface AppRouterCacheState {\n activeContexts: RouteCacheContext[];\n invalidatedPaths: Set<string>;\n memoryCache: AppRouterCache;\n storage: AsyncLocalStorage<RouteCacheContext>;\n}\n\ninterface RouteCacheContext {\n cache: AppRouterCache;\n cachePolicy?: RouteCachePolicy | undefined;\n closed?: boolean | undefined;\n revalidatedPaths: Set<string>;\n}\n\nconst cacheState = ((\n globalThis as { __mreactAppRouterCache?: AppRouterCacheState }\n).__mreactAppRouterCache ??= {\n activeContexts: [],\n invalidatedPaths: new Set(),\n memoryCache: createMemoryRouteCache(),\n storage: new AsyncLocalStorage<RouteCacheContext>(),\n});\ncacheState.storage ??= new AsyncLocalStorage<RouteCacheContext>();\n\n/**\n * Creates an in-memory route response cache for app-router rendering.\n *\n * The cache is process-local, evicts expired entries during reads/writes, and is suitable for development, tests, or single-process deployments that do not need shared invalidation.\n */\nexport function createMemoryRouteCache(options: MemoryRouteCacheOptions = {}): AppRouterCache {\n const maxEntries = positiveIntegerOrDefault(options.maxEntries, 10_000);\n const sweepIntervalMs = nonNegativeIntegerOrDefault(options.sweepIntervalMs, 60_000);\n const cachedRoutes = new Map<string, AppRouterCacheEntry>();\n const keysByPath = new Map<string, Set<string>>();\n let nextSweepAt = 0;\n\n function unindexKey(key: string, path: string): void {\n const keys = keysByPath.get(path);\n keys?.delete(key);\n\n if (keys?.size === 0) {\n keysByPath.delete(path);\n }\n }\n\n function deleteEntry(key: string): void {\n const entry = cachedRoutes.get(key);\n cachedRoutes.delete(key);\n\n if (entry !== undefined) {\n unindexKey(key, entry.path);\n }\n }\n\n function indexKey(key: string, path: string): void {\n const keys = keysByPath.get(path);\n\n if (keys === undefined) {\n keysByPath.set(path, new Set([key]));\n return;\n }\n\n keys.add(key);\n }\n\n function sweepExpired(now: number): void {\n for (const [key, entry] of cachedRoutes) {\n if (entry.expiresAt <= now) {\n deleteEntry(key);\n }\n }\n\n nextSweepAt = now + sweepIntervalMs;\n }\n\n function maybeSweepExpired(now: number): void {\n if (sweepIntervalMs === 0 || now >= nextSweepAt) {\n sweepExpired(now);\n }\n }\n\n function evictOldestEntries(): void {\n while (cachedRoutes.size > maxEntries) {\n const oldestKey = cachedRoutes.keys().next().value;\n\n if (oldestKey === undefined) {\n return;\n }\n\n deleteEntry(oldestKey);\n }\n }\n\n return {\n deleteByPath(path) {\n const normalizedPath = normalizeRevalidationPath(path);\n const keys = keysByPath.get(normalizedPath);\n\n if (keys === undefined) {\n return;\n }\n\n for (const key of keys) {\n cachedRoutes.delete(key);\n }\n\n keysByPath.delete(normalizedPath);\n },\n get(key, now = Date.now()) {\n const entry = cachedRoutes.get(key);\n\n if (entry === undefined) {\n return undefined;\n }\n\n if (entry.expiresAt <= now) {\n deleteEntry(key);\n return undefined;\n }\n\n return entry;\n },\n set(key, entry) {\n const now = Date.now();\n maybeSweepExpired(now);\n const previous = cachedRoutes.get(key);\n\n if (previous !== undefined) {\n cachedRoutes.delete(key);\n unindexKey(key, previous.path);\n }\n\n cachedRoutes.set(key, entry);\n indexKey(key, entry.path);\n\n if (cachedRoutes.size > maxEntries) {\n sweepExpired(now);\n evictOldestEntries();\n }\n },\n };\n}\n\nfunction positiveIntegerOrDefault(value: number | undefined, fallback: number): number {\n return value === undefined || !Number.isInteger(value) || value < 1 ? fallback : value;\n}\n\nfunction nonNegativeIntegerOrDefault(value: number | undefined, fallback: number): number {\n return value === undefined || !Number.isInteger(value) || value < 0 ? fallback : value;\n}\n\nexport function routeCachePolicyFromSource(code: string): RouteCachePolicy | undefined {\n const match = /^\\s*export\\s+const\\s+revalidate\\s*=\\s*(?<seconds>\\d+)\\s*;?\\s*$/m.exec(code);\n const seconds = match?.groups?.seconds === undefined ? undefined : Number(match.groups.seconds);\n\n if (seconds === undefined || !Number.isFinite(seconds)) {\n if (/^\\s*export\\s+const\\s+revalidate\\s*=/m.test(code)) {\n console.warn(\n \"export const revalidate must be a plain integer literal, e.g. export const revalidate = 3600\",\n );\n }\n return undefined;\n }\n\n return {\n cacheControl: seconds === 0 ? \"no-store\" : `s-maxage=${seconds}, stale-while-revalidate`,\n revalidateSeconds: seconds,\n };\n}\n\n/**\n * Sets the cache policy for the current app-router render.\n *\n * Call this during a loader or route render to override the response `Cache-Control` policy; it throws outside an active app-router request.\n */\nexport function cacheControl(options: CacheControlOptions): void {\n const activeContext = activeRouteCacheContext();\n\n if (activeContext === undefined) {\n throw new Error(\"cacheControl() must be called during an app router request.\");\n }\n\n activeContext.cachePolicy = routeCachePolicyFromOptions(options);\n}\n\nexport function routeCachePolicyFromOptions(options: CacheControlOptions): RouteCachePolicy {\n const directives: string[] = [];\n const maxAge = cacheControlSeconds(options.maxAge, \"maxAge\");\n const sMaxAge = cacheControlSeconds(options.sMaxAge, \"sMaxAge\");\n\n if (maxAge !== undefined) {\n directives.push(`max-age=${maxAge}`);\n }\n\n if (sMaxAge !== undefined) {\n directives.push(`s-maxage=${sMaxAge}`);\n }\n\n if (options.staleWhileRevalidate !== undefined) {\n directives.push(staleWhileRevalidateDirective(options.staleWhileRevalidate));\n }\n\n if (directives.length === 0) {\n throw new Error(\"cacheControl() requires at least one cache directive.\");\n }\n\n return {\n cacheControl: directives.join(\", \"),\n revalidateSeconds: sMaxAge ?? 0,\n };\n}\n\nexport function cachedRouteResponse(options: {\n cache?: AppRouterCache | undefined;\n key: string;\n now?: number;\n request?: Request | undefined;\n}): Promise<Response | undefined> {\n return Promise.resolve().then(async () => {\n if (requestCarriesCredentials(options.request)) {\n return undefined;\n }\n\n const cache = options.cache ?? cacheState.memoryCache;\n\n await consumeInvalidations(cache);\n const now = options.now ?? Date.now();\n const cached = await cache.get(options.key, now);\n\n if (\n cached === undefined ||\n cached.expiresAt <= now ||\n cached.schemaVersion !== ROUTE_CACHE_ENTRY_SCHEMA_VERSION ||\n !isStringRecord(cached.headers)\n ) {\n return undefined;\n }\n\n const headers = new Headers(cached.headers ?? {});\n headers.set(\"cache-control\", cached.cacheControl);\n if (!headers.has(\"content-type\")) {\n headers.set(\"content-type\", \"text/html; charset=utf-8\");\n }\n headers.set(\"x-mreact-cache\", \"HIT\");\n // Replayed against the scheme of the request being served, not the one\n // that produced the entry.\n if (cached.strictTransportSecurity !== undefined && isSecureRequest(options.request)) {\n headers.set(HSTS_HEADER, cached.strictTransportSecurity);\n }\n\n return new Response(cached.body, {\n headers,\n status: cached.status,\n });\n });\n}\n\nexport async function cacheRouteResponse(options: {\n cache?: AppRouterCache | undefined;\n headerDependent?: boolean | undefined;\n key: string;\n now?: number;\n path: string;\n policy: RouteCachePolicy | undefined;\n request?: Request | undefined;\n response: Response;\n /** Configured Strict-Transport-Security value, independent of this request's scheme. */\n strictTransportSecurity?: string | undefined;\n}): Promise<Response> {\n if (options.policy === undefined) {\n return options.response;\n }\n\n if (options.policy.revalidateSeconds === 0) {\n // No entry is stored here, but cacheControl({ maxAge }) still emits a bare\n // max-age that a shared cache may store, so a header dependent render has\n // to opt out of that too. Directives that already keep the response out of\n // shared caches are left exactly as the application asked for them.\n const sharedCacheMayStore = !/(^|,)\\s*(private|no-store)\\s*(,|$)/.test(\n options.policy.cacheControl,\n );\n\n if (options.headerDependent === true && sharedCacheMayStore) {\n options.response.headers.set(\"cache-control\", \"private, no-store\");\n options.response.headers.set(\"x-mreact-cache\", \"DYNAMIC\");\n return options.response;\n }\n\n options.response.headers.set(\"cache-control\", options.policy.cacheControl);\n return options.response;\n }\n\n const body = await options.response.text();\n const cacheControl = options.policy.cacheControl;\n const status = options.response.status;\n const contentType = options.response.headers.get(\"content-type\") ?? \"text/html; charset=utf-8\";\n\n // A render that read a request header only produced HTML that is correct for\n // that header value. The cache key covers the path and query alone, so the\n // entry cannot be shared; the response is marked uncacheable for downstream\n // shared caches too, which are keyed the same way.\n if (\n options.headerDependent === true ||\n requestCarriesCredentials(options.request) ||\n options.response.headers.has(\"set-cookie\")\n ) {\n const headers = new Headers(options.response.headers);\n headers.set(\"cache-control\", \"private, no-store\");\n if (!headers.has(\"content-type\")) {\n headers.set(\"content-type\", contentType);\n }\n if (options.headerDependent === true) {\n headers.set(\"x-mreact-cache\", \"DYNAMIC\");\n }\n\n return new Response(body, {\n headers,\n status,\n });\n }\n\n // Metadata-derived security headers are part of the rendered response, so\n // they are stored with it and replayed on a hit rather than dropped by the\n // rebuilt cache response. Strict-Transport-Security is kept apart because it\n // is derived from the scheme of whichever request missed and the key does not\n // cover the scheme: it is replayed only to requests that are themselves\n // secure, instead of pinning one visitor's scheme onto the entry.\n const storedHeaders: Record<string, string> = {};\n options.response.headers.forEach((value, key) => {\n if (key !== \"cache-control\" && key !== \"x-mreact-cache\" && key !== HSTS_HEADER) {\n storedHeaders[key] = value;\n }\n });\n // Taken from the route's configuration rather than from this response, whose\n // HSTS header is present only when this particular request was secure. Using\n // the response would let one plain request pin an entry that withholds HSTS\n // from every later secure visitor.\n const hsts = options.strictTransportSecurity;\n\n await (options.cache ?? cacheState.memoryCache).set(options.key, {\n body,\n cacheControl,\n expiresAt: (options.now ?? Date.now()) + options.policy.revalidateSeconds * 1000,\n headers: storedHeaders,\n ...(hsts === undefined ? {} : { strictTransportSecurity: hsts }),\n path: normalizeRevalidationPath(options.path),\n schemaVersion: ROUTE_CACHE_ENTRY_SCHEMA_VERSION,\n status,\n });\n\n const headers = new Headers(storedHeaders);\n headers.set(\"cache-control\", cacheControl);\n if (!headers.has(\"content-type\")) {\n headers.set(\"content-type\", contentType);\n }\n headers.set(\"x-mreact-cache\", \"MISS\");\n if (hsts !== undefined && isSecureRequest(options.request)) {\n headers.set(HSTS_HEADER, hsts);\n }\n\n return new Response(body, {\n headers,\n status,\n });\n}\n\nconst HSTS_HEADER = \"strict-transport-security\";\nconst ROUTE_CACHE_ENTRY_SCHEMA_VERSION = 2;\n\nfunction isStringRecord(value: unknown): value is Record<string, string> {\n return (\n typeof value === \"object\" &&\n value !== null &&\n !Array.isArray(value) &&\n Object.values(value).every((entry) => typeof entry === \"string\")\n );\n}\n\nfunction isSecureRequest(request: Request | undefined): boolean {\n // `Request.url` is always absolute, so this avoids parsing a URL on the\n // cache-hit hot path.\n return request?.url.startsWith(\"https://\") === true;\n}\n\nfunction requestCarriesCredentials(request: Request | undefined): boolean {\n if (request === undefined) {\n return false;\n }\n\n if (request.headers.has(\"authorization\") || request.headers.has(\"cookie\")) {\n return true;\n }\n\n for (const name of request.headers.keys()) {\n const lower = name.toLowerCase();\n if (PUBLIC_ROUTE_CACHE_REQUEST_HEADERS.has(lower)) {\n continue;\n }\n\n if (\n lower === \"x-api-key\" ||\n lower === \"cf-access-jwt-assertion\" ||\n lower === \"proxy-authorization\" ||\n lower === \"x-access-token\" ||\n lower === \"x-auth-token\" ||\n lower === \"x-authenticated-user\" ||\n lower === \"x-id-token\" ||\n lower === \"x-forwarded-user\" ||\n lower === \"x-session-id\" ||\n lower === \"x-user-email\" ||\n lower === \"x-user-id\" ||\n lower.endsWith(\"-api-key\") ||\n lower.endsWith(\"-auth-token\") ||\n lower.endsWith(\"-session-id\") ||\n lower.endsWith(\"-user\") ||\n lower.endsWith(\"-user-email\") ||\n lower.endsWith(\"-user-id\") ||\n lower.includes(\"-jwt-\") ||\n lower.endsWith(\"-jwt\")\n ) {\n return true;\n }\n\n continue;\n }\n\n return false;\n}\n\nconst PUBLIC_ROUTE_CACHE_REQUEST_HEADERS = new Set([\n \"accept\",\n \"accept-encoding\",\n \"accept-language\",\n \"cache-control\",\n \"cf-connecting-ip\",\n \"cf-ipcountry\",\n \"cf-ray\",\n \"connection\",\n \"dnt\",\n \"host\",\n \"if-none-match\",\n \"pragma\",\n \"priority\",\n \"purpose\",\n \"referer\",\n \"save-data\",\n \"sec-ch-prefers-color-scheme\",\n \"sec-ch-prefers-reduced-motion\",\n \"sec-ch-ua\",\n \"sec-ch-ua-mobile\",\n \"sec-ch-ua-platform\",\n \"sec-fetch-dest\",\n \"sec-fetch-mode\",\n \"sec-fetch-site\",\n \"sec-fetch-user\",\n \"upgrade-insecure-requests\",\n \"user-agent\",\n \"via\",\n \"x-mreact-navigation\",\n \"x-mreact-navigation-cache\",\n \"x-real-ip\",\n \"x-request-id\",\n \"x-forwarded-for\",\n \"x-forwarded-host\",\n \"x-forwarded-proto\",\n]);\n\n/**\n * Invalidates cached route responses for a normalized app-router path.\n *\n * During a request the invalidation is scoped to that route cache context; outside a request it is queued for the next cache access.\n */\nexport function revalidatePath(path: string): void {\n const normalizedPath = normalizeRevalidationPath(path);\n const activeContext = activeRouteCacheContext();\n\n if (activeContext !== undefined) {\n activeContext.revalidatedPaths.add(normalizedPath);\n return;\n }\n\n cacheState.invalidatedPaths.add(normalizedPath);\n}\n\nexport async function consumeInvalidations(\n cache: AppRouterCache = cacheState.memoryCache,\n): Promise<void> {\n if (cacheState.invalidatedPaths.size === 0) {\n return;\n }\n\n for (const path of cacheState.invalidatedPaths) {\n await cache.deleteByPath(path);\n }\n\n cacheState.invalidatedPaths.clear();\n}\n\nexport async function withRouteCacheContext<T>(\n cache: AppRouterCache | undefined,\n fn: () => T | Promise<T>,\n): Promise<{ cachePolicy: RouteCachePolicy | undefined; revalidatedPaths: string[]; value: T }> {\n const context: RouteCacheContext = {\n cache: cache ?? cacheState.memoryCache,\n revalidatedPaths: new Set(),\n };\n\n return cacheState.storage.run(context, async () => {\n try {\n const value = await fn();\n context.closed = true;\n const cachePolicy = context.cachePolicy;\n const revalidatedPaths = Array.from(context.revalidatedPaths);\n\n for (const path of revalidatedPaths) {\n await context.cache.deleteByPath(path);\n }\n\n return { cachePolicy, revalidatedPaths, value };\n } finally {\n context.closed = true;\n }\n });\n}\n\nexport function beginRouteCacheContext(cache: AppRouterCache | undefined): {\n readonly cachePolicy: RouteCachePolicy | undefined;\n dispose(): Promise<{ revalidatedPaths: string[] }>;\n} {\n const context: RouteCacheContext = {\n cache: cache ?? cacheState.memoryCache,\n revalidatedPaths: new Set(),\n };\n\n cacheState.activeContexts.push(context);\n\n return {\n get cachePolicy() {\n return context.cachePolicy;\n },\n async dispose() {\n context.closed = true;\n const revalidatedPaths = Array.from(context.revalidatedPaths);\n try {\n for (const path of revalidatedPaths) {\n await context.cache.deleteByPath(path);\n }\n } finally {\n const index = cacheState.activeContexts.lastIndexOf(context);\n if (index !== -1) {\n cacheState.activeContexts.splice(index, 1);\n }\n }\n\n return { revalidatedPaths };\n },\n };\n}\n\nexport function activeRouteCacheContext(): RouteCacheContext | undefined {\n const asyncContext = cacheState.storage.getStore();\n\n if (asyncContext !== undefined) {\n return asyncContext.closed === true ? undefined : asyncContext;\n }\n\n for (let index = cacheState.activeContexts.length - 1; index >= 0; index -= 1) {\n const context = cacheState.activeContexts[index];\n\n if (context?.closed !== true) {\n return context;\n }\n }\n\n return undefined;\n}\n\n// Host is excluded from the cache key to prevent attacker-supplied Host\n// headers from fragmenting / poisoning the cache (Issue 068). The Vary\n// dimension is the request path + query; same-origin reverse proxies are\n// expected to handle vhost separation at their layer.\nexport function routeCacheKey(appDir: string, routePath: string, url: URL): string {\n return `${appDir}\\0${normalizeRevalidationPath(routePath)}\\0${url.pathname}${url.search}`;\n}\n\nexport function stripRevalidateExport(code: string): string {\n return code.replace(/^\\s*export\\s+const\\s+revalidate\\s*=\\s*\\d+\\s*;?\\s*$/m, \"\");\n}\n\nfunction normalizeRevalidationPath(path: string): string {\n const pathname = path.startsWith(\"/\") ? path : `/${path}`;\n const withoutTrailing = pathname.length > 1 ? pathname.replace(/\\/+$/, \"\") : pathname;\n\n return withoutTrailing === \"\" ? \"/\" : withoutTrailing;\n}\n\nfunction cacheControlSeconds(value: number | undefined, name: string): number | undefined {\n if (value === undefined) {\n return undefined;\n }\n\n if (!Number.isSafeInteger(value) || value < 0) {\n throw new Error(`cacheControl() ${name} must be a non-negative integer.`);\n }\n\n return value;\n}\n\nfunction staleWhileRevalidateDirective(value: boolean | number): string {\n if (value === true) {\n return \"stale-while-revalidate\";\n }\n\n if (value === false) {\n throw new Error(\"cacheControl() staleWhileRevalidate must be true or a non-negative integer.\");\n }\n\n const seconds = cacheControlSeconds(value, \"staleWhileRevalidate\");\n return `stale-while-revalidate=${seconds}`;\n}\n"]}
|
package/dist/cli-options.d.ts
CHANGED
|
@@ -22,6 +22,7 @@ export interface ParsedCliArguments {
|
|
|
22
22
|
routeArg?: string | undefined;
|
|
23
23
|
skipRuntimeDependencyCheck?: boolean | undefined;
|
|
24
24
|
target?: CliBuildTarget | undefined;
|
|
25
|
+
trustForwardedProto?: boolean | undefined;
|
|
25
26
|
worker?: string | undefined;
|
|
26
27
|
}
|
|
27
28
|
export declare function parseCliArguments(argv: readonly string[]): ParsedCliArguments;
|
|
@@ -42,5 +43,8 @@ export declare function resolveCliHostPolicy(flagValue: RequestHostPolicy | unde
|
|
|
42
43
|
export declare function resolveCliAllowedHosts(flagValue: readonly string[] | undefined, env: {
|
|
43
44
|
MREACT_ROUTER_ALLOWED_HOSTS?: string | undefined;
|
|
44
45
|
}): readonly string[] | undefined;
|
|
46
|
+
export declare function resolveCliTrustForwardedProto(flagValue: boolean | undefined, env: {
|
|
47
|
+
MREACT_ROUTER_TRUST_FORWARDED_PROTO?: string | undefined;
|
|
48
|
+
}): boolean;
|
|
45
49
|
export declare function createCliRequestLogger(): AppRouterLogger;
|
|
46
50
|
//# sourceMappingURL=cli-options.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli-options.d.ts","sourceRoot":"","sources":["../src/cli-options.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GAAG,SAAS,CAAA;CAAE,GACtD,iBAAiB,GAAG,SAAS,CAO/B;AAED,wBAAgB,sBAAsB,CACpC,SAAS,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,EACxC,GAAG,EAAE;IAAE,2BAA2B,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,GACxD,SAAS,MAAM,EAAE,GAAG,SAAS,CAO/B;AAED,wBAAgB,6BAA6B,CAC3C,SAAS,EAAE,OAAO,GAAG,SAAS,EAC9B,GAAG,EAAE;IAAE,mCAAmC,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,GAChE,OAAO,CAMT;AAED,wBAAgB,sBAAsB,IAAI,eAAe,CAaxD"}
|
package/dist/cli-options.js
CHANGED
|
@@ -58,6 +58,13 @@ export function parseCliArguments(argv) {
|
|
|
58
58
|
index += 1;
|
|
59
59
|
continue;
|
|
60
60
|
}
|
|
61
|
+
if (value === "--trust-forwarded-proto") {
|
|
62
|
+
if (command !== "start") {
|
|
63
|
+
throw new Error("--trust-forwarded-proto is only supported by the start command");
|
|
64
|
+
}
|
|
65
|
+
parsed.trustForwardedProto = true;
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
61
68
|
if (value.startsWith("--allowed-hosts=")) {
|
|
62
69
|
parsed.allowedHosts = parseCliAllowedHosts(value.slice("--allowed-hosts=".length));
|
|
63
70
|
continue;
|
|
@@ -244,6 +251,8 @@ export function formatCliHelp(command) {
|
|
|
244
251
|
" Control Host header trust for request origin reconstruction.",
|
|
245
252
|
" --allowed-hosts <host[,host...]>",
|
|
246
253
|
" Exact Host header allow-list for public deployments.",
|
|
254
|
+
" --trust-forwarded-proto",
|
|
255
|
+
" Trust the first X-Forwarded-Proto value. Enable only when a trusted proxy overwrites the header and the Node port is not publicly reachable.",
|
|
247
256
|
" --log=requests Print request summaries.",
|
|
248
257
|
" -h, --help Show this help message.",
|
|
249
258
|
"",
|
|
@@ -253,6 +262,8 @@ export function formatCliHelp(command) {
|
|
|
253
262
|
" Host header trust policy when --host-policy is not set.",
|
|
254
263
|
" MREACT_ROUTER_ALLOWED_HOSTS",
|
|
255
264
|
" Comma-separated Host header allow-list when --allowed-hosts is not set.",
|
|
265
|
+
" MREACT_ROUTER_TRUST_FORWARDED_PROTO",
|
|
266
|
+
" Set to 1 to trust X-Forwarded-Proto when the flag is not set.",
|
|
256
267
|
" PORT TCP port. Default: 3001.",
|
|
257
268
|
].join("\n");
|
|
258
269
|
}
|
|
@@ -359,6 +370,12 @@ export function resolveCliAllowedHosts(flagValue, env) {
|
|
|
359
370
|
const envValue = env.MREACT_ROUTER_ALLOWED_HOSTS;
|
|
360
371
|
return envValue === undefined || envValue === "" ? undefined : parseCliAllowedHosts(envValue);
|
|
361
372
|
}
|
|
373
|
+
export function resolveCliTrustForwardedProto(flagValue, env) {
|
|
374
|
+
if (flagValue !== undefined) {
|
|
375
|
+
return flagValue;
|
|
376
|
+
}
|
|
377
|
+
return env.MREACT_ROUTER_TRUST_FORWARDED_PROTO === "1";
|
|
378
|
+
}
|
|
362
379
|
export function createCliRequestLogger() {
|
|
363
380
|
return {
|
|
364
381
|
error(event) {
|