@vercel/build-utils 14.17.0 → 14.19.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.
@@ -1,29 +1,20 @@
1
- import type { FlatBuildOutputSchedule, Schedule, ScheduleTarget } from './types';
1
+ import type { Schedule } from './types';
2
2
  /**
3
- * A `vercel.json` schedule in the nested shape. `entrypoint` targets are
4
- * resolved to `function` before the schedule reaches Build Output.
3
+ * A `vercel.json` schedule. `entrypoint` targets are resolved to `function`
4
+ * before the schedule reaches Build Output.
5
5
  */
6
- export type VercelJsonSchedule = Omit<Schedule, 'target'> & {
7
- target: ScheduleTarget | {
8
- entrypoint: string;
9
- };
10
- };
11
- declare const FLAT_TARGET_KEYS: readonly ["path", "function", "topic", "entrypoint"];
12
- type FlatTargetKey = (typeof FLAT_TARGET_KEYS)[number];
6
+ export type VercelJsonSchedule = Schedule | (Pick<Schedule, 'name' | 'schedule' | 'timezone' | 'jitter'> & {
7
+ entrypoint: string;
8
+ });
9
+ declare const SCHEDULE_TARGET_KEYS: readonly ["path", "function", "topic", "entrypoint"];
10
+ export type ScheduleTargetKey = (typeof SCHEDULE_TARGET_KEYS)[number];
13
11
  /**
14
- * Name for a flat schedule without one: a hex hash of `type|ref|expression`,
15
- * which always satisfies the schedule name pattern. Build Output omits these
16
- * names (except for entrypoint schedules) and the API derives its own; using
17
- * the same hash keeps `vercel dev` names the same as deployed ones.
12
+ * Name for a schedule without one: a hex hash of `type|ref|expression`, which
13
+ * always satisfies the schedule name pattern. Build Output omits these names
14
+ * (except for entrypoint schedules) and the API derives its own; using the
15
+ * same hash keeps `vercel dev` names the same as deployed ones.
18
16
  */
19
- export declare function defaultScheduleName(type: FlatTargetKey, ref: string, expression: string): string;
20
- export declare function parseScheduleDefinition(raw: unknown): VercelJsonSchedule;
21
- /**
22
- * Format a schedule for Build Output `config.json`. Pass `includeName: false`
23
- * for a name derived by `parseScheduleDefinition`; the API derives the same
24
- * name for a flat Build Output schedule without one.
25
- */
26
- export declare function formatBuildOutputSchedule(schedule: Schedule, { includeName }?: {
27
- includeName?: boolean;
28
- }): FlatBuildOutputSchedule;
17
+ export declare function defaultScheduleName(type: ScheduleTargetKey, ref: string, expression: string): string;
18
+ /** The schedule's `name`, or its default name when it has none. */
19
+ export declare function getScheduleName(schedule: VercelJsonSchedule): string;
29
20
  export {};
package/dist/schedules.js CHANGED
@@ -19,137 +19,34 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
19
19
  var schedules_exports = {};
20
20
  __export(schedules_exports, {
21
21
  defaultScheduleName: () => defaultScheduleName,
22
- formatBuildOutputSchedule: () => formatBuildOutputSchedule,
23
- parseScheduleDefinition: () => parseScheduleDefinition
22
+ getScheduleName: () => getScheduleName
24
23
  });
25
24
  module.exports = __toCommonJS(schedules_exports);
26
25
  var import_crypto = require("crypto");
27
- const FLAT_TARGET_KEYS = ["path", "function", "topic", "entrypoint"];
26
+ const SCHEDULE_TARGET_KEYS = [
27
+ "path",
28
+ "function",
29
+ "topic",
30
+ "entrypoint"
31
+ ];
28
32
  const DEFAULT_NAME_HASH_LENGTH = 12;
29
33
  function defaultScheduleName(type, ref, expression) {
30
34
  return (0, import_crypto.createHash)("sha1").update(`${type}|${ref}|${expression}`).digest("hex").slice(0, DEFAULT_NAME_HASH_LENGTH);
31
35
  }
32
- function isRecord(value) {
33
- return value != null && typeof value === "object" && !Array.isArray(value);
34
- }
35
- function isLegacyScheduleDefinition(obj) {
36
- return "expression" in obj && "target" in obj;
37
- }
38
- function isFlatScheduleDefinition(obj) {
39
- return "schedule" in obj;
40
- }
41
- function assertNotMixedFields(obj) {
42
- const hasLegacy = "expression" in obj || "target" in obj;
43
- const hasFlatSchedule = "schedule" in obj;
44
- const flatTargetCount = FLAT_TARGET_KEYS.filter((key) => key in obj).length;
45
- if (hasLegacy && (hasFlatSchedule || flatTargetCount > 0)) {
46
- throw new Error(
47
- "Schedule cannot mix legacy fields (`expression`, `target`) with flat fields (`schedule`, `path`, `function`, `topic`, `entrypoint`)."
48
- );
49
- }
50
- }
51
- function parseLegacySchedule(obj) {
52
- const { name, expression, target, timezone } = obj;
53
- if (typeof name !== "string") {
54
- throw new Error("Schedule `name` must be a string.");
55
- }
56
- if (!isRecord(expression) || typeof expression.cron !== "string") {
57
- throw new Error("Schedule `expression.cron` must be a string.");
58
- }
59
- for (const key of Object.keys(expression)) {
60
- if (key !== "cron" && key !== "jitter") {
61
- throw new Error(
62
- `Schedule \`expression\` cannot include \`${key}\`. Use top-level \`timezone\` for IANA timezones.`
63
- );
64
- }
65
- }
66
- if (!isRecord(target)) {
67
- throw new Error("Schedule `target` must be an object.");
68
- }
69
- const parsedExpression = {
70
- cron: expression.cron,
71
- ...expression.jitter !== void 0 ? { jitter: expression.jitter } : {}
72
- };
73
- let parsedTarget;
74
- if (typeof target.function === "string") {
75
- parsedTarget = { function: target.function };
76
- } else if (typeof target.path === "string") {
77
- parsedTarget = { path: target.path };
78
- } else if (typeof target.topic === "string") {
79
- parsedTarget = { topic: target.topic };
80
- } else if (typeof target.entrypoint === "string") {
81
- parsedTarget = { entrypoint: target.entrypoint };
82
- } else {
36
+ function getScheduleName(schedule) {
37
+ if (schedule.name !== void 0)
38
+ return schedule.name;
39
+ const type = SCHEDULE_TARGET_KEYS.find((key) => key in schedule);
40
+ if (type === void 0) {
83
41
  throw new Error(
84
- "Schedule `target` must include exactly one of `function`, `path`, `topic`, or `entrypoint`."
42
+ "Schedule must include one of `path`, `function`, `topic`, or `entrypoint`."
85
43
  );
86
44
  }
87
- return {
88
- name,
89
- expression: parsedExpression,
90
- target: parsedTarget,
91
- ...typeof timezone === "string" ? { timezone } : {}
92
- };
93
- }
94
- function parseFlatSchedule(obj) {
95
- const { name, schedule, timezone, jitter } = obj;
96
- if (name !== void 0 && typeof name !== "string") {
97
- throw new Error("Schedule `name` must be a string.");
98
- }
99
- if (typeof schedule !== "string") {
100
- throw new Error("Schedule `schedule` must be a string.");
101
- }
102
- const targetKeys = FLAT_TARGET_KEYS.filter((key) => key in obj);
103
- if (targetKeys.length !== 1) {
104
- throw new Error(
105
- "Flat schedule must include exactly one of `path`, `function`, `topic`, or `entrypoint`."
106
- );
107
- }
108
- const targetKey = targetKeys[0];
109
- const targetValue = obj[targetKey];
110
- if (typeof targetValue !== "string") {
111
- throw new Error(`Schedule \`${targetKey}\` must be a string.`);
112
- }
113
- const target = {
114
- [targetKey]: targetValue
115
- };
116
- return {
117
- name: name ?? defaultScheduleName(targetKey, targetValue, schedule),
118
- expression: {
119
- cron: schedule,
120
- ...jitter !== void 0 ? { jitter } : {}
121
- },
122
- target,
123
- ...typeof timezone === "string" ? { timezone } : {}
124
- };
125
- }
126
- function parseScheduleDefinition(raw) {
127
- if (!isRecord(raw)) {
128
- throw new Error("Schedule must be an object.");
129
- }
130
- assertNotMixedFields(raw);
131
- if (isLegacyScheduleDefinition(raw)) {
132
- return parseLegacySchedule(raw);
133
- }
134
- if (isFlatScheduleDefinition(raw)) {
135
- return parseFlatSchedule(raw);
136
- }
137
- throw new Error(
138
- "Schedule must use either the legacy shape (`expression`, `target`, `name`) or the flat shape (`schedule` and one target field)."
139
- );
140
- }
141
- function formatBuildOutputSchedule(schedule, { includeName = true } = {}) {
142
- return {
143
- ...includeName ? { name: schedule.name } : {},
144
- schedule: schedule.expression.cron,
145
- ...schedule.target,
146
- ...schedule.timezone !== void 0 ? { timezone: schedule.timezone } : {},
147
- ...schedule.expression.jitter !== void 0 ? { jitter: schedule.expression.jitter } : {}
148
- };
45
+ const ref = schedule[type];
46
+ return defaultScheduleName(type, ref ?? "", schedule.schedule);
149
47
  }
150
48
  // Annotate the CommonJS export names for ESM import in node:
151
49
  0 && (module.exports = {
152
50
  defaultScheduleName,
153
- formatBuildOutputSchedule,
154
- parseScheduleDefinition
51
+ getScheduleName
155
52
  });
@@ -0,0 +1,11 @@
1
+ import type { StaticBundleExclusions, StaticMount } from './types';
2
+ /** Stub file that keeps an excluded mount directory present in the Lambda. */
3
+ export declare const STATIC_PLACEHOLDER_FILE = ".static-placeholder";
4
+ /**
5
+ * Lambda bundle trimming for promoted mounts: exclude each mount directory
6
+ * (inside `workPath`) from the bundle, and add a placeholder stub plus any
7
+ * `keepFiles` present in the directory so framework startup checks (directory
8
+ * exists, fallback file exists) still pass. Mounts outside `workPath` are
9
+ * skipped.
10
+ */
11
+ export declare function staticBundleExclusions(mounts: StaticMount[], workPath: string, keepFiles: string[]): StaticBundleExclusions;
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var bundle_exports = {};
30
+ __export(bundle_exports, {
31
+ STATIC_PLACEHOLDER_FILE: () => STATIC_PLACEHOLDER_FILE,
32
+ staticBundleExclusions: () => staticBundleExclusions
33
+ });
34
+ module.exports = __toCommonJS(bundle_exports);
35
+ var import_fs = __toESM(require("fs"));
36
+ var import_path = require("path");
37
+ var import_file_blob = __toESM(require("../file-blob"));
38
+ var import_file_fs_ref = __toESM(require("../file-fs-ref"));
39
+ const STATIC_PLACEHOLDER_FILE = ".static-placeholder";
40
+ function staticBundleExclusions(mounts, workPath, keepFiles) {
41
+ const excludePatterns = [];
42
+ const directoryStubs = {};
43
+ for (const mount of mounts) {
44
+ const relDir = (0, import_path.relative)(workPath, mount.directory);
45
+ if (!relDir || relDir.startsWith("..") || (0, import_path.isAbsolute)(relDir))
46
+ continue;
47
+ const relDirUnix = relDir.split(import_path.sep).join("/");
48
+ excludePatterns.push(`${relDirUnix}/**`);
49
+ directoryStubs[`${relDirUnix}/${STATIC_PLACEHOLDER_FILE}`] = new import_file_blob.default({
50
+ data: ""
51
+ });
52
+ for (const keepFile of keepFiles) {
53
+ const fsPath = (0, import_path.join)(mount.directory, keepFile);
54
+ if (import_fs.default.existsSync(fsPath)) {
55
+ directoryStubs[`${relDirUnix}/${keepFile}`] = new import_file_fs_ref.default({
56
+ fsPath
57
+ });
58
+ }
59
+ }
60
+ }
61
+ return { excludePatterns, directoryStubs };
62
+ }
63
+ // Annotate the CommonJS export names for ESM import in node:
64
+ 0 && (module.exports = {
65
+ STATIC_PLACEHOLDER_FILE,
66
+ staticBundleExclusions
67
+ });
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Shared static-file CDN promotion for builders that deploy a web framework as
3
+ * one Lambda behind a catch-all route. Framework-specific discovery stays in
4
+ * each builder and emits a {@link StaticDiscovery}; this module copies the
5
+ * discovered directories into the build output's static dir and produces the
6
+ * routes that keep the framework's precedence.
7
+ */
8
+ export { EMPTY_DISCOVERY, type ShadowRoute, type StaticBundleExclusions, type StaticDiscovery, type StaticFallback, type StaticMount, type StaticPromotionResult, type StaticPromotionOptions, } from './types';
9
+ export { copyStaticMounts, promoteStaticFiles } from './promote';
10
+ export { MAX_ROUTE_SRC_LENGTH, NAVIGATION_ACCEPT_RE, staticDirectoryRedirects, staticFallbackRoutes, staticShadowRoutes, } from './routes';
11
+ export { STATIC_PLACEHOLDER_FILE, staticBundleExclusions } from './bundle';
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var static_files_exports = {};
20
+ __export(static_files_exports, {
21
+ EMPTY_DISCOVERY: () => import_types.EMPTY_DISCOVERY,
22
+ MAX_ROUTE_SRC_LENGTH: () => import_routes.MAX_ROUTE_SRC_LENGTH,
23
+ NAVIGATION_ACCEPT_RE: () => import_routes.NAVIGATION_ACCEPT_RE,
24
+ STATIC_PLACEHOLDER_FILE: () => import_bundle.STATIC_PLACEHOLDER_FILE,
25
+ copyStaticMounts: () => import_promote.copyStaticMounts,
26
+ promoteStaticFiles: () => import_promote.promoteStaticFiles,
27
+ staticBundleExclusions: () => import_bundle.staticBundleExclusions,
28
+ staticDirectoryRedirects: () => import_routes.staticDirectoryRedirects,
29
+ staticFallbackRoutes: () => import_routes.staticFallbackRoutes,
30
+ staticShadowRoutes: () => import_routes.staticShadowRoutes
31
+ });
32
+ module.exports = __toCommonJS(static_files_exports);
33
+ var import_types = require("./types");
34
+ var import_promote = require("./promote");
35
+ var import_routes = require("./routes");
36
+ var import_bundle = require("./bundle");
37
+ // Annotate the CommonJS export names for ESM import in node:
38
+ 0 && (module.exports = {
39
+ EMPTY_DISCOVERY,
40
+ MAX_ROUTE_SRC_LENGTH,
41
+ NAVIGATION_ACCEPT_RE,
42
+ STATIC_PLACEHOLDER_FILE,
43
+ copyStaticMounts,
44
+ promoteStaticFiles,
45
+ staticBundleExclusions,
46
+ staticDirectoryRedirects,
47
+ staticFallbackRoutes,
48
+ staticShadowRoutes
49
+ });
@@ -0,0 +1,19 @@
1
+ import type { StaticDiscovery, StaticMount, StaticPromotionOptions, StaticPromotionResult } from './types';
2
+ /**
3
+ * Copy each mount's directory into the CDN tree at its URL prefix.
4
+ *
5
+ * A path is filled only by the highest-priority source whose prefix covers it,
6
+ * so a lower-priority source never leaks a file that would 404 at runtime.
7
+ * Priority follows {@link byCopyPriority}; the per-file filter enforces it.
8
+ * Files listed in `excludedFiles` are skipped so the Lambda serves them.
9
+ *
10
+ * A failed mount is skipped (the Lambda still serves it), but it keeps its
11
+ * namespace so lower-priority sources cannot fill it. Returns the mounts that
12
+ * were copied, so a failed mount gets no fallback route (empty when all fail).
13
+ */
14
+ export declare function copyStaticMounts(discovery: Pick<StaticDiscovery, 'mounts' | 'excludedFiles'>, outputStaticDir: string, opts?: StaticPromotionOptions): Promise<StaticMount[]>;
15
+ /**
16
+ * Copy a discovery's mounts into `outputStaticDir`. Returns null when there
17
+ * is nothing to promote: no mounts discovered, or none could be copied.
18
+ */
19
+ export declare function promoteStaticFiles(discovery: StaticDiscovery, outputStaticDir: string, opts?: StaticPromotionOptions): Promise<StaticPromotionResult | null>;
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var promote_exports = {};
30
+ __export(promote_exports, {
31
+ copyStaticMounts: () => copyStaticMounts,
32
+ promoteStaticFiles: () => promoteStaticFiles
33
+ });
34
+ module.exports = __toCommonJS(promote_exports);
35
+ var import_fs = __toESM(require("fs"));
36
+ var import_path = require("path");
37
+ var import_debug = __toESM(require("../debug"));
38
+ var import_utils = require("./utils");
39
+ function cdnUrlPath(outputStaticDir, destPath) {
40
+ const rel = (0, import_path.relative)(outputStaticDir, destPath);
41
+ return rel === "" ? "/" : "/" + rel.split(import_path.sep).join("/");
42
+ }
43
+ async function copyStaticMounts(discovery, outputStaticDir, opts) {
44
+ const excluded = new Set(discovery.excludedFiles);
45
+ const higherPriority = [];
46
+ const copied = [];
47
+ for (const mount of (0, import_utils.byCopyPriority)(discovery.mounts)) {
48
+ const dest = (0, import_path.join)(outputStaticDir, (0, import_utils.trimSlashes)(mount.urlPath));
49
+ try {
50
+ await import_fs.default.promises.mkdir(dest, { recursive: true });
51
+ await import_fs.default.promises.cp(mount.directory, dest, {
52
+ recursive: true,
53
+ force: false,
54
+ filter: (_src, destPath) => {
55
+ const urlPath = cdnUrlPath(outputStaticDir, destPath);
56
+ return !higherPriority.some((base) => (0, import_utils.mountCovers)(base, urlPath)) && !excluded.has(urlPath);
57
+ }
58
+ });
59
+ copied.push(mount);
60
+ (0, import_debug.default)(`copied ${mount.directory} -> ${dest}`);
61
+ } catch (err) {
62
+ (0, import_debug.default)(
63
+ `${(0, import_utils.logLabel)(opts)}: skipping ${mount.urlPath}: copy failed (${err})`
64
+ );
65
+ }
66
+ higherPriority.push((0, import_utils.trimTrailingSlashes)(mount.urlPath));
67
+ }
68
+ return copied;
69
+ }
70
+ async function promoteStaticFiles(discovery, outputStaticDir, opts) {
71
+ const label = (0, import_utils.logLabel)(opts);
72
+ const { mounts } = discovery;
73
+ if (mounts.length === 0) {
74
+ (0, import_debug.default)(`${label}: no static mounts found, skipping`);
75
+ return null;
76
+ }
77
+ (0, import_debug.default)(
78
+ `${label}: found ${mounts.length} static mount(s): ${mounts.map((m) => m.urlPath).join(", ")}`
79
+ );
80
+ const copiedMounts = await copyStaticMounts(discovery, outputStaticDir, opts);
81
+ if (copiedMounts.length === 0) {
82
+ return null;
83
+ }
84
+ return { discovery, copiedMounts, outputStaticDir };
85
+ }
86
+ // Annotate the CommonJS export names for ESM import in node:
87
+ 0 && (module.exports = {
88
+ copyStaticMounts,
89
+ promoteStaticFiles
90
+ });
@@ -0,0 +1,60 @@
1
+ import type { RouteWithSrc } from '@vercel/routing-utils';
2
+ import type { ShadowRoute, StaticMount, StaticPromotionOptions } from './types';
3
+ export declare const MAX_ROUTE_SRC_LENGTH = 4096;
4
+ /**
5
+ * Routes that send paths the app owns to the Lambda, emitted before
6
+ * `handle: 'filesystem'` so the app wins over a colliding CDN file.
7
+ *
8
+ * Each shadow body is a ready-made pattern from discovery, minus its leading
9
+ * slash and with no capturing groups. The bodies are OR'd into one capturing
10
+ * group whose match is copied back into `request.path` via `$1`. The group
11
+ * allows an optional trailing slash so a framework's slash redirect still
12
+ * reaches the app.
13
+ *
14
+ * Bodies are grouped by method set so a shadow only intercepts the methods
15
+ * the app handles, then split across as many routes as fit the 4096-char
16
+ * `src` cap; all route to the Lambda, so the split is order-independent. A
17
+ * body too long for a `src` even alone is dropped (and logged): its path stays
18
+ * unshadowed. Returns an empty list when nothing is shadowed.
19
+ */
20
+ export declare function staticShadowRoutes(shadowRoutes: ShadowRoute[], lambdaPath: string, opts?: StaticPromotionOptions): RouteWithSrc[];
21
+ /**
22
+ * Bare-directory → slash redirects, emitted after shadow routes and before
23
+ * `handle: 'filesystem'`.
24
+ *
25
+ * The CDN serves index.html as an implicit directory index for bare directory
26
+ * paths. For `html`/`frontend` mounts, redirect the bare form to the slash
27
+ * form so the CDN serves the file at the correct URL base. Directories covered
28
+ * by a higher-priority mount get their CDN content from that mount, so they
29
+ * emit no redirect (mounts are walked in copy-priority order). Only
30
+ * directories that contain an index.html get a redirect.
31
+ */
32
+ export declare function staticDirectoryRedirects(mounts: StaticMount[], opts?: StaticPromotionOptions): RouteWithSrc[];
33
+ /**
34
+ * Accept-header gate for navigation requests: an explicit text/html or
35
+ * application/xhtml+xml media type not rejected with q=0. The type is
36
+ * boundary-guarded so a longer token like `text/htmlx` never matches, and a
37
+ * wildcard `Accept` does not count. The router anchors `has` values with
38
+ * `^…$`, hence the `.*` wrapping.
39
+ */
40
+ export declare const NAVIGATION_ACCEPT_RE = ".*(?:^|[,\\s])(?:text/html|application/xhtml\\+xml)(?=[,;\\s]|$)(?![^,]*;\\s*q=0(?:\\.0+)?(?:[,;\\s]|$)).*";
41
+ /**
42
+ * `handle: 'miss'` routes that serve each copied mount's fallback file for a
43
+ * miss under its mount. `check: true` re-resolves the rewrite to the copied
44
+ * file so it stays a CDN hit. Routes are GET/HEAD only.
45
+ *
46
+ * `copied` supplies the fallbacks: only copied mounts get one, since a
47
+ * `check: true` destination that doesn't exist ends the request instead of
48
+ * reaching the Lambda. `discovered` (every discovered mount) supplies the
49
+ * nested-mount exclusions, since nested mounts own their own subtrees whether
50
+ * or not they were copied.
51
+ *
52
+ * A non-200 fallback (e.g. 404.html) is served for every miss. A 200 fallback
53
+ * (e.g. index.html) is served only for navigation requests: an explicit html
54
+ * `Accept` ({@link NAVIGATION_ACCEPT_RE}) plus, unless
55
+ * `useFallbackForExtensionedPaths` is true, an extension-less final path
56
+ * segment (so `/app/main.js` falls through). Anything the gate rejects falls
57
+ * through to the Lambda. A fallback whose nested-mount guard pushes its `src`
58
+ * over the cap is skipped.
59
+ */
60
+ export declare function staticFallbackRoutes(copied: Pick<StaticMount, 'urlPath' | 'fallback'>[], discovered: Pick<StaticMount, 'urlPath'>[], opts?: StaticPromotionOptions): RouteWithSrc[];