@caelo-cms/shared 0.11.18 → 0.11.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/change-journal.d.ts +1 -1
- package/dist/change-journal.d.ts.map +1 -1
- package/dist/change-journal.js +5 -0
- package/dist/change-journal.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/install-ai-mode.d.ts +25 -0
- package/dist/install-ai-mode.d.ts.map +1 -0
- package/dist/install-ai-mode.js +17 -0
- package/dist/install-ai-mode.js.map +1 -0
- package/dist/markup-structure.d.ts +7 -0
- package/dist/markup-structure.d.ts.map +1 -1
- package/dist/markup-structure.js +7 -3
- package/dist/markup-structure.js.map +1 -1
- package/dist/redirect-emit-caddy.d.ts +10 -0
- package/dist/redirect-emit-caddy.d.ts.map +1 -1
- package/dist/redirect-emit-caddy.js +13 -0
- package/dist/redirect-emit-caddy.js.map +1 -1
- package/dist/redirect-plan.d.ts +11 -0
- package/dist/redirect-plan.d.ts.map +1 -1
- package/dist/redirect-plan.js +14 -0
- package/dist/redirect-plan.js.map +1 -1
- package/dist/staged-site.d.ts.map +1 -1
- package/dist/staged-site.js +9 -0
- package/dist/staged-site.js.map +1 -1
- package/dist/static-files.d.ts +107 -0
- package/dist/static-files.d.ts.map +1 -0
- package/dist/static-files.js +274 -0
- package/dist/static-files.js.map +1 -0
- package/dist/version.d.ts +2 -2
- package/dist/version.js +1 -1
- package/package.json +1 -1
- package/src/change-journal.ts +6 -0
- package/src/index.ts +2 -0
- package/src/install-ai-mode.ts +35 -0
- package/src/markup-structure.test.ts +8 -0
- package/src/markup-structure.ts +14 -3
- package/src/redirect-emit-caddy.ts +18 -0
- package/src/redirect-plan.test.ts +12 -0
- package/src/redirect-plan.ts +15 -0
- package/src/staged-site.ts +13 -0
- package/src/static-files.test.ts +238 -0
- package/src/static-files.ts +311 -0
- package/src/version.ts +1 -1
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Issue #1461 — small static files on the site's domain: `/bot/ips.json`,
|
|
3
|
+
* `/.well-known/security.txt`, `/ads.txt`. The rules every surface shares
|
|
4
|
+
* (the ops, the generator and the publishers), so a file that passes here
|
|
5
|
+
* is one every provider serves the same way.
|
|
6
|
+
*
|
|
7
|
+
* Plain data only. HTML, JavaScript, CSS and SVG are refused for good: a
|
|
8
|
+
* file of those types would be the way around "no raw HTML on pages" and
|
|
9
|
+
* the module and plugin rules (CLAUDE.md §2). XML is data too, but a browser
|
|
10
|
+
* runs what an XML document carries in the XHTML or SVG namespace or through
|
|
11
|
+
* a stylesheet, so {@link staticFileBodyIssue} refuses those bodies. A header
|
|
12
|
+
* could not do that job on every provider: plain GCP serves object metadata,
|
|
13
|
+
* and a CSP there would be an infrastructure change per path.
|
|
14
|
+
*
|
|
15
|
+
* Docs: docs/dev/static-files.md.
|
|
16
|
+
*/
|
|
17
|
+
import { z } from "zod";
|
|
18
|
+
/** The Content-Types a static file may have (without charset). */
|
|
19
|
+
export declare const STATIC_FILE_CONTENT_TYPES: readonly ["application/json", "text/plain", "text/csv", "application/xml", "text/xml"];
|
|
20
|
+
/** One allowed Content-Type. */
|
|
21
|
+
export type StaticFileContentType = (typeof STATIC_FILE_CONTENT_TYPES)[number];
|
|
22
|
+
/** Largest body of one file, in UTF-8 bytes. Every byte lives in a snapshot row. */
|
|
23
|
+
export declare const STATIC_FILE_MAX_BYTES: number;
|
|
24
|
+
/** Most files one site may have. Every file is a header rule on Firebase and in Caddy. */
|
|
25
|
+
export declare const STATIC_FILE_MAX_COUNT = 50;
|
|
26
|
+
/** Most files one write may carry. */
|
|
27
|
+
export declare const STATIC_FILE_MAX_BATCH = 20;
|
|
28
|
+
/** Longest path, in characters. */
|
|
29
|
+
export declare const STATIC_FILE_MAX_PATH_LENGTH = 200;
|
|
30
|
+
/** Longest `purpose` text. */
|
|
31
|
+
export declare const STATIC_FILE_MAX_PURPOSE_LENGTH = 500;
|
|
32
|
+
/**
|
|
33
|
+
* The build's sidecar naming its static files and their Content-Types. The
|
|
34
|
+
* publishers that serve a file's type from a header rule (Firebase Hosting,
|
|
35
|
+
* Caddy) read it; the others take the type from the upload.
|
|
36
|
+
*/
|
|
37
|
+
export declare const STATIC_FILES_MANIFEST_FILE = "_static-files.json";
|
|
38
|
+
/** One file as {@link STATIC_FILES_MANIFEST_FILE} lists it. */
|
|
39
|
+
export interface StaticFileManifestEntry {
|
|
40
|
+
/** Build-relative path, no leading slash (`bot/ips.json`). */
|
|
41
|
+
readonly path: string;
|
|
42
|
+
/** The Content-Type header the file is served with. */
|
|
43
|
+
readonly contentType: string;
|
|
44
|
+
}
|
|
45
|
+
/** The sidecar's body for `files`. */
|
|
46
|
+
export declare function formatStaticFilesManifest(files: readonly StaticFileManifestEntry[]): string;
|
|
47
|
+
/**
|
|
48
|
+
* Parse the sidecar.
|
|
49
|
+
*
|
|
50
|
+
* @throws when the body is not one the generator wrote: a build whose files
|
|
51
|
+
* would lose their Content-Type must not be deployed.
|
|
52
|
+
*/
|
|
53
|
+
export declare function parseStaticFilesManifest(body: string): readonly StaticFileManifestEntry[];
|
|
54
|
+
/** The Content-Type header for a stored type. All bodies are UTF-8. */
|
|
55
|
+
export declare function staticFileContentTypeHeader(type: StaticFileContentType): string;
|
|
56
|
+
/**
|
|
57
|
+
* Why `path` cannot hold a static file, or null when it can. Pure: the
|
|
58
|
+
* collisions with pages, redirects and other files need data, see
|
|
59
|
+
* {@link staticFileCollisions}.
|
|
60
|
+
*/
|
|
61
|
+
export declare function staticFilePathIssue(path: string): string | null;
|
|
62
|
+
/**
|
|
63
|
+
* Why `contentType` does not fit `path`, or null. The two must agree: a
|
|
64
|
+
* host that goes by the extension then serves the declared type too. A path
|
|
65
|
+
* without an extension takes any allowed type.
|
|
66
|
+
*/
|
|
67
|
+
export declare function staticFileTypeIssue(path: string, contentType: string): string | null;
|
|
68
|
+
/** The body's size in UTF-8 bytes. */
|
|
69
|
+
export declare function staticFileByteLength(body: string): number;
|
|
70
|
+
/**
|
|
71
|
+
* Why `body` cannot be served as `contentType`, or null. Checks the size,
|
|
72
|
+
* that JSON parses, and that XML stays data (see the file header).
|
|
73
|
+
*/
|
|
74
|
+
export declare function staticFileBodyIssue(contentType: string, body: string): string | null;
|
|
75
|
+
/**
|
|
76
|
+
* What stands in the way of a file at `path`, one sentence per collision. A
|
|
77
|
+
* file cannot share a URL with a page or a redirect, and because it is a
|
|
78
|
+
* real file on disk and in a bucket it cannot sit where another path needs
|
|
79
|
+
* a folder, or below another file.
|
|
80
|
+
*
|
|
81
|
+
* @param args.pagePaths URL paths of the pages (`/about`, `/about/`).
|
|
82
|
+
* @param args.redirectFromPaths URL paths that redirect.
|
|
83
|
+
* @param args.filePaths URL paths of the other static files.
|
|
84
|
+
*/
|
|
85
|
+
export declare function staticFileCollisions(path: string, args: {
|
|
86
|
+
readonly pagePaths: Iterable<string>;
|
|
87
|
+
readonly redirectFromPaths: Iterable<string>;
|
|
88
|
+
readonly filePaths: Iterable<string>;
|
|
89
|
+
}): string[];
|
|
90
|
+
/** Zod shape of one file in a write. The rules with a message live in the functions above. */
|
|
91
|
+
export declare const staticFileInputSchema: z.ZodObject<{
|
|
92
|
+
path: z.ZodString;
|
|
93
|
+
contentType: z.ZodEnum<{
|
|
94
|
+
"application/json": "application/json";
|
|
95
|
+
"text/plain": "text/plain";
|
|
96
|
+
"text/csv": "text/csv";
|
|
97
|
+
"application/xml": "application/xml";
|
|
98
|
+
"text/xml": "text/xml";
|
|
99
|
+
}>;
|
|
100
|
+
body: z.ZodString;
|
|
101
|
+
purpose: z.ZodString;
|
|
102
|
+
}, z.core.$strict>;
|
|
103
|
+
/** One file in a write. */
|
|
104
|
+
export type StaticFileInput = z.infer<typeof staticFileInputSchema>;
|
|
105
|
+
/** Every problem of one file that needs no data, as sentences. */
|
|
106
|
+
export declare function staticFileIssues(file: StaticFileInput): string[];
|
|
107
|
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G;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CASpF;AAED,sCAAsC;AACtC,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEzD;AA2CD;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,WAAW,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAoBpF;AAKD;;;;;;;;;GASG;AACH,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE;IACJ,QAAQ,CAAC,SAAS,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;IACrC,QAAQ,CAAC,iBAAiB,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC7C,QAAQ,CAAC,SAAS,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;CACtC,GACA,MAAM,EAAE,CAkBV;AAED,8FAA8F;AAC9F,eAAO,MAAM,qBAAqB;;;;;;;;;;;kBAUvB,CAAC;AAEZ,2BAA2B;AAC3B,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAEpE,kEAAkE;AAClE,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,eAAe,GAAG,MAAM,EAAE,CAMhE"}
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
2
|
+
/**
|
|
3
|
+
* Issue #1461 — small static files on the site's domain: `/bot/ips.json`,
|
|
4
|
+
* `/.well-known/security.txt`, `/ads.txt`. The rules every surface shares
|
|
5
|
+
* (the ops, the generator and the publishers), so a file that passes here
|
|
6
|
+
* is one every provider serves the same way.
|
|
7
|
+
*
|
|
8
|
+
* Plain data only. HTML, JavaScript, CSS and SVG are refused for good: a
|
|
9
|
+
* file of those types would be the way around "no raw HTML on pages" and
|
|
10
|
+
* the module and plugin rules (CLAUDE.md §2). XML is data too, but a browser
|
|
11
|
+
* runs what an XML document carries in the XHTML or SVG namespace or through
|
|
12
|
+
* a stylesheet, so {@link staticFileBodyIssue} refuses those bodies. A header
|
|
13
|
+
* could not do that job on every provider: plain GCP serves object metadata,
|
|
14
|
+
* and a CSP there would be an infrastructure change per path.
|
|
15
|
+
*
|
|
16
|
+
* Docs: docs/dev/static-files.md.
|
|
17
|
+
*/
|
|
18
|
+
import { z } from "zod";
|
|
19
|
+
/** The Content-Types a static file may have (without charset). */
|
|
20
|
+
export const STATIC_FILE_CONTENT_TYPES = [
|
|
21
|
+
"application/json",
|
|
22
|
+
"text/plain",
|
|
23
|
+
"text/csv",
|
|
24
|
+
"application/xml",
|
|
25
|
+
"text/xml",
|
|
26
|
+
];
|
|
27
|
+
/** Largest body of one file, in UTF-8 bytes. Every byte lives in a snapshot row. */
|
|
28
|
+
export const STATIC_FILE_MAX_BYTES = 256 * 1024;
|
|
29
|
+
/** Most files one site may have. Every file is a header rule on Firebase and in Caddy. */
|
|
30
|
+
export const STATIC_FILE_MAX_COUNT = 50;
|
|
31
|
+
/** Most files one write may carry. */
|
|
32
|
+
export const STATIC_FILE_MAX_BATCH = 20;
|
|
33
|
+
/** Longest path, in characters. */
|
|
34
|
+
export const STATIC_FILE_MAX_PATH_LENGTH = 200;
|
|
35
|
+
/** Longest `purpose` text. */
|
|
36
|
+
export const STATIC_FILE_MAX_PURPOSE_LENGTH = 500;
|
|
37
|
+
/**
|
|
38
|
+
* The build's sidecar naming its static files and their Content-Types. The
|
|
39
|
+
* publishers that serve a file's type from a header rule (Firebase Hosting,
|
|
40
|
+
* Caddy) read it; the others take the type from the upload.
|
|
41
|
+
*/
|
|
42
|
+
export const STATIC_FILES_MANIFEST_FILE = "_static-files.json";
|
|
43
|
+
const manifestSchema = z.object({
|
|
44
|
+
version: z.literal(1),
|
|
45
|
+
files: z.array(z.object({ path: z.string().min(1), contentType: z.string().min(1) })),
|
|
46
|
+
});
|
|
47
|
+
/** The sidecar's body for `files`. */
|
|
48
|
+
export function formatStaticFilesManifest(files) {
|
|
49
|
+
return JSON.stringify({ version: 1, files }, null, 2);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Parse the sidecar.
|
|
53
|
+
*
|
|
54
|
+
* @throws when the body is not one the generator wrote: a build whose files
|
|
55
|
+
* would lose their Content-Type must not be deployed.
|
|
56
|
+
*/
|
|
57
|
+
export function parseStaticFilesManifest(body) {
|
|
58
|
+
return manifestSchema.parse(JSON.parse(body)).files;
|
|
59
|
+
}
|
|
60
|
+
/** The Content-Type header for a stored type. All bodies are UTF-8. */
|
|
61
|
+
export function staticFileContentTypeHeader(type) {
|
|
62
|
+
return `${type}; charset=utf-8`;
|
|
63
|
+
}
|
|
64
|
+
/** The extensions a path may carry, with the types each one may be served as. */
|
|
65
|
+
const TYPES_OF_EXTENSION = {
|
|
66
|
+
".json": ["application/json"],
|
|
67
|
+
".txt": ["text/plain"],
|
|
68
|
+
".csv": ["text/csv"],
|
|
69
|
+
".xml": ["application/xml", "text/xml"],
|
|
70
|
+
};
|
|
71
|
+
const SEGMENT = /^[A-Za-z0-9][A-Za-z0-9._~-]*$/;
|
|
72
|
+
/** Files the build writes at the site root. */
|
|
73
|
+
const RESERVED_ROOT_FILES = new Set([
|
|
74
|
+
"robots.txt",
|
|
75
|
+
"sitemap.xml",
|
|
76
|
+
"routing-manifest.json",
|
|
77
|
+
"cdn_manifest.json",
|
|
78
|
+
"render-deps.json",
|
|
79
|
+
]);
|
|
80
|
+
/**
|
|
81
|
+
* `/.well-known/` names the platform answers itself: remote MCP's OAuth
|
|
82
|
+
* metadata (the load balancer routes `oauth-*` to the MCP-Auth-Proxy on gcp,
|
|
83
|
+
* CLAUDE.md §11.B) and certificate issuance.
|
|
84
|
+
*/
|
|
85
|
+
const RESERVED_WELL_KNOWN = /^(?:oauth-|openid-configuration$|acme-challenge$)/;
|
|
86
|
+
/** The extension of the last path segment, lower-cased, or "" when it has none. */
|
|
87
|
+
function extensionOf(path) {
|
|
88
|
+
const name = path.slice(path.lastIndexOf("/") + 1);
|
|
89
|
+
const dot = name.lastIndexOf(".");
|
|
90
|
+
return dot <= 0 ? "" : name.slice(dot).toLowerCase();
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Why `path` cannot hold a static file, or null when it can. Pure: the
|
|
94
|
+
* collisions with pages, redirects and other files need data, see
|
|
95
|
+
* {@link staticFileCollisions}.
|
|
96
|
+
*/
|
|
97
|
+
export function staticFilePathIssue(path) {
|
|
98
|
+
if (path.length > STATIC_FILE_MAX_PATH_LENGTH) {
|
|
99
|
+
return `the path is longer than ${STATIC_FILE_MAX_PATH_LENGTH} characters`;
|
|
100
|
+
}
|
|
101
|
+
if (!path.startsWith("/") || path.endsWith("/")) {
|
|
102
|
+
return 'write it as a full file path, starting with "/" and not ending in "/", like /bot/ips.json';
|
|
103
|
+
}
|
|
104
|
+
const segments = path.slice(1).split("/");
|
|
105
|
+
const first = segments[0] ?? "";
|
|
106
|
+
if (first.toLowerCase() === "api" || first.startsWith("_")) {
|
|
107
|
+
return `"/${first}" is reserved for the site's own files and services; choose another folder`;
|
|
108
|
+
}
|
|
109
|
+
if (segments.length === 1 && RESERVED_ROOT_FILES.has(first.toLowerCase())) {
|
|
110
|
+
return `"${path}" is written by every build; a static file cannot replace it`;
|
|
111
|
+
}
|
|
112
|
+
const named = first === ".well-known" ? segments.slice(1) : segments;
|
|
113
|
+
if (named.length === 0) {
|
|
114
|
+
return "name a file inside /.well-known/, like /.well-known/security.txt";
|
|
115
|
+
}
|
|
116
|
+
if (first === ".well-known" && RESERVED_WELL_KNOWN.test(named[0] ?? "")) {
|
|
117
|
+
return `"${path}" is answered by the platform itself (sign-in and certificates)`;
|
|
118
|
+
}
|
|
119
|
+
const bad = named.find((s) => !SEGMENT.test(s));
|
|
120
|
+
if (bad !== undefined) {
|
|
121
|
+
return `"${bad}" cannot be part of a path: use letters, digits, "-", "_", "." and "~", and start each part with a letter or digit (only /.well-known/ starts with a dot)`;
|
|
122
|
+
}
|
|
123
|
+
const ext = extensionOf(path);
|
|
124
|
+
if (ext !== "" && TYPES_OF_EXTENSION[ext] === undefined) {
|
|
125
|
+
return `a file ending in "${ext}" cannot be served: use ${Object.keys(TYPES_OF_EXTENSION).join(", ")} or no extension. HTML, JavaScript, CSS and SVG belong in pages and modules`;
|
|
126
|
+
}
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Why `contentType` does not fit `path`, or null. The two must agree: a
|
|
131
|
+
* host that goes by the extension then serves the declared type too. A path
|
|
132
|
+
* without an extension takes any allowed type.
|
|
133
|
+
*/
|
|
134
|
+
export function staticFileTypeIssue(path, contentType) {
|
|
135
|
+
if (!STATIC_FILE_CONTENT_TYPES.includes(contentType)) {
|
|
136
|
+
return `"${contentType}" cannot be served: use one of ${STATIC_FILE_CONTENT_TYPES.join(", ")}`;
|
|
137
|
+
}
|
|
138
|
+
const ext = extensionOf(path);
|
|
139
|
+
if (ext === "")
|
|
140
|
+
return null;
|
|
141
|
+
const allowed = TYPES_OF_EXTENSION[ext];
|
|
142
|
+
if (allowed === undefined || allowed.includes(contentType))
|
|
143
|
+
return null;
|
|
144
|
+
return `a path ending in "${ext}" is served as ${allowed.join(" or ")}, not ${contentType}. Change the type or the path`;
|
|
145
|
+
}
|
|
146
|
+
/** The body's size in UTF-8 bytes. */
|
|
147
|
+
export function staticFileByteLength(body) {
|
|
148
|
+
return new TextEncoder().encode(body).byteLength;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Namespaces and constructs that make a browser treat an XML document as a
|
|
152
|
+
* page or run a stylesheet over it.
|
|
153
|
+
*/
|
|
154
|
+
const ACTIVE_XML = /www\.w3\.org\/1999\/xhtml|www\.w3\.org\/2000\/svg|www\.w3\.org\/1998\/Math\/MathML|<\?xml-stylesheet|<!DOCTYPE|<!ENTITY/i;
|
|
155
|
+
/**
|
|
156
|
+
* True when an `xmlns` value is spelled with character references, which
|
|
157
|
+
* would hide the namespace from {@link ACTIVE_XML}. A scan, not a regex: the
|
|
158
|
+
* body is up to the caller, and each step resumes where the last one stopped,
|
|
159
|
+
* so the cost stays linear in the body.
|
|
160
|
+
*/
|
|
161
|
+
function hasEscapedNamespace(body) {
|
|
162
|
+
const lower = body.toLowerCase();
|
|
163
|
+
const isSpace = (c) => c === " " || c === "\t" || c === "\n" || c === "\r";
|
|
164
|
+
let at = lower.indexOf("xmlns");
|
|
165
|
+
while (at !== -1) {
|
|
166
|
+
let i = at + "xmlns".length;
|
|
167
|
+
if (body[i] === ":") {
|
|
168
|
+
while (i < body.length && body[i] !== "=" && !isSpace(body[i]))
|
|
169
|
+
i += 1;
|
|
170
|
+
}
|
|
171
|
+
while (isSpace(body[i]))
|
|
172
|
+
i += 1;
|
|
173
|
+
if (body[i] === "=") {
|
|
174
|
+
i += 1;
|
|
175
|
+
while (isSpace(body[i]))
|
|
176
|
+
i += 1;
|
|
177
|
+
const quote = body[i];
|
|
178
|
+
if (quote === '"' || quote === "'") {
|
|
179
|
+
const end = body.indexOf(quote, i + 1);
|
|
180
|
+
const stop = end === -1 ? body.length : end;
|
|
181
|
+
const amp = body.indexOf("&", i + 1);
|
|
182
|
+
if (amp !== -1 && amp < stop)
|
|
183
|
+
return true;
|
|
184
|
+
i = stop;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
at = lower.indexOf("xmlns", i);
|
|
188
|
+
}
|
|
189
|
+
return false;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Why `body` cannot be served as `contentType`, or null. Checks the size,
|
|
193
|
+
* that JSON parses, and that XML stays data (see the file header).
|
|
194
|
+
*/
|
|
195
|
+
export function staticFileBodyIssue(contentType, body) {
|
|
196
|
+
if (body.length === 0)
|
|
197
|
+
return "the file is empty";
|
|
198
|
+
const bytes = staticFileByteLength(body);
|
|
199
|
+
if (bytes > STATIC_FILE_MAX_BYTES) {
|
|
200
|
+
return `the file has ${bytes} bytes; a static file may have at most ${STATIC_FILE_MAX_BYTES} (${STATIC_FILE_MAX_BYTES / 1024} KiB)`;
|
|
201
|
+
}
|
|
202
|
+
if (body.includes("\0"))
|
|
203
|
+
return "the file contains a NUL character, so it is not a text file";
|
|
204
|
+
if (contentType === "application/json") {
|
|
205
|
+
try {
|
|
206
|
+
JSON.parse(body);
|
|
207
|
+
}
|
|
208
|
+
catch (e) {
|
|
209
|
+
return `the file is not valid JSON: ${e instanceof Error ? e.message : String(e)}`;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
if (contentType === "application/xml" || contentType === "text/xml") {
|
|
213
|
+
if (ACTIVE_XML.test(body) || hasEscapedNamespace(body)) {
|
|
214
|
+
return "the XML carries a DOCTYPE, a stylesheet or an XHTML, SVG or MathML namespace, which a browser would run as a page. Send plain data XML, or build it as a page";
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return null;
|
|
218
|
+
}
|
|
219
|
+
const withoutTrailingSlash = (path) => path.length > 1 && path.endsWith("/") ? path.slice(0, -1) : path;
|
|
220
|
+
/**
|
|
221
|
+
* What stands in the way of a file at `path`, one sentence per collision. A
|
|
222
|
+
* file cannot share a URL with a page or a redirect, and because it is a
|
|
223
|
+
* real file on disk and in a bucket it cannot sit where another path needs
|
|
224
|
+
* a folder, or below another file.
|
|
225
|
+
*
|
|
226
|
+
* @param args.pagePaths URL paths of the pages (`/about`, `/about/`).
|
|
227
|
+
* @param args.redirectFromPaths URL paths that redirect.
|
|
228
|
+
* @param args.filePaths URL paths of the other static files.
|
|
229
|
+
*/
|
|
230
|
+
export function staticFileCollisions(path, args) {
|
|
231
|
+
const out = [];
|
|
232
|
+
for (const raw of args.pagePaths) {
|
|
233
|
+
const page = withoutTrailingSlash(raw);
|
|
234
|
+
if (page === path)
|
|
235
|
+
out.push(`a page already serves ${path}`);
|
|
236
|
+
else if (page.startsWith(`${path}/`))
|
|
237
|
+
out.push(`the page ${page} sits below ${path}`);
|
|
238
|
+
}
|
|
239
|
+
for (const raw of args.redirectFromPaths) {
|
|
240
|
+
if (withoutTrailingSlash(raw) === path)
|
|
241
|
+
out.push(`a redirect starts at ${path}`);
|
|
242
|
+
}
|
|
243
|
+
for (const other of args.filePaths) {
|
|
244
|
+
if (other === path)
|
|
245
|
+
continue;
|
|
246
|
+
if (other.startsWith(`${path}/`))
|
|
247
|
+
out.push(`the file ${other} sits below ${path}`);
|
|
248
|
+
else if (path.startsWith(`${other}/`)) {
|
|
249
|
+
out.push(`the file ${other} stands where ${path} needs a folder`);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
return out;
|
|
253
|
+
}
|
|
254
|
+
/** Zod shape of one file in a write. The rules with a message live in the functions above. */
|
|
255
|
+
export const staticFileInputSchema = z
|
|
256
|
+
.object({
|
|
257
|
+
/** Full path on the site, like `/bot/ips.json`. */
|
|
258
|
+
path: z.string().min(2).max(STATIC_FILE_MAX_PATH_LENGTH),
|
|
259
|
+
contentType: z.enum(STATIC_FILE_CONTENT_TYPES),
|
|
260
|
+
/** The file's text, UTF-8. */
|
|
261
|
+
body: z.string().min(1),
|
|
262
|
+
/** Why this file exists and who reads it (CLAUDE.md §1A). */
|
|
263
|
+
purpose: z.string().trim().min(1).max(STATIC_FILE_MAX_PURPOSE_LENGTH),
|
|
264
|
+
})
|
|
265
|
+
.strict();
|
|
266
|
+
/** Every problem of one file that needs no data, as sentences. */
|
|
267
|
+
export function staticFileIssues(file) {
|
|
268
|
+
const pathIssue = staticFilePathIssue(file.path);
|
|
269
|
+
return [
|
|
270
|
+
pathIssue ?? staticFileTypeIssue(file.path, file.contentType),
|
|
271
|
+
staticFileBodyIssue(file.contentType, file.body),
|
|
272
|
+
].filter((i) => i !== null);
|
|
273
|
+
}
|
|
274
|
+
//# sourceMappingURL=static-files.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"static-files.js","sourceRoot":"","sources":["../src/static-files.ts"],"names":[],"mappings":"AAAA,mCAAmC;AAE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8FAA8F;AAC9F,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC;KACnC,MAAM,CAAC;IACN,mDAAmD;IACnD,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,2BAA2B,CAAC;IACxD,WAAW,EAAE,CAAC,CAAC,IAAI,CAAC,yBAAyB,CAAC;IAC9C,8BAA8B;IAC9B,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACvB,6DAA6D;IAC7D,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,8BAA8B,CAAC;CACtE,CAAC;KACD,MAAM,EAAE,CAAC;AAKZ,kEAAkE;AAClE,MAAM,UAAU,gBAAgB,CAAC,IAAqB;IACpD,MAAM,SAAS,GAAG,mBAAmB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACjD,OAAO;QACL,SAAS,IAAI,mBAAmB,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC;QAC7D,mBAAmB,CAAC,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,IAAI,CAAC;KACjD,CAAC,MAAM,CAAC,CAAC,CAAC,EAAe,EAAE,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC;AAC3C,CAAC"}
|
package/dist/version.d.ts
CHANGED
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
* Format: SemVer 2.0.0. Pre-1.0 minor bumps are breaking; post-1.0
|
|
20
20
|
* follow standard SemVer.
|
|
21
21
|
*/
|
|
22
|
-
export declare const CAELO_VERSION = "0.11.
|
|
22
|
+
export declare const CAELO_VERSION = "0.11.20";
|
|
23
23
|
/**
|
|
24
24
|
* Deprecated alias for back-compat — early P17 work spelled this
|
|
25
25
|
* `CALEO_VERSION` (typo of "Caelo"). New code should import
|
|
@@ -31,7 +31,7 @@ export declare const CAELO_VERSION = "0.11.18";
|
|
|
31
31
|
*
|
|
32
32
|
* @deprecated use CAELO_VERSION
|
|
33
33
|
*/
|
|
34
|
-
export declare const CALEO_VERSION = "0.11.
|
|
34
|
+
export declare const CALEO_VERSION = "0.11.20";
|
|
35
35
|
/**
|
|
36
36
|
* Parsed shape — major/minor/patch + optional pre-release tag.
|
|
37
37
|
* Stable interface for callers that need to feature-gate (rare —
|
package/dist/version.js
CHANGED
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
* Format: SemVer 2.0.0. Pre-1.0 minor bumps are breaking; post-1.0
|
|
21
21
|
* follow standard SemVer.
|
|
22
22
|
*/
|
|
23
|
-
export const CAELO_VERSION = "0.11.
|
|
23
|
+
export const CAELO_VERSION = "0.11.20";
|
|
24
24
|
/**
|
|
25
25
|
* Deprecated alias for back-compat — early P17 work spelled this
|
|
26
26
|
* `CALEO_VERSION` (typo of "Caelo"). New code should import
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@caelo-cms/shared",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.20",
|
|
4
4
|
"private": false,
|
|
5
5
|
"license": "MPL-2.0",
|
|
6
6
|
"description": "Shared Zod schemas + types + the two-pass HTML composer used by every Caelo CMS workspace package. Stable enough for plugin authors and embedders to depend on directly.",
|
package/src/change-journal.ts
CHANGED
|
@@ -43,6 +43,7 @@ export const JOURNAL_KINDS = [
|
|
|
43
43
|
"media_crop",
|
|
44
44
|
"font",
|
|
45
45
|
"redirect",
|
|
46
|
+
"static_file",
|
|
46
47
|
"domain",
|
|
47
48
|
"site_defaults",
|
|
48
49
|
"site_settings",
|
|
@@ -142,6 +143,7 @@ export const JOURNALED_TABLES: Readonly<Record<string, JournaledTable>> = {
|
|
|
142
143
|
media_crops: row("media_crop", "id", ["id"], { parent: "asset_id" }),
|
|
143
144
|
font_assets: row("font", "id", ["id"]),
|
|
144
145
|
redirects: row("redirect", "id", ["id"]),
|
|
146
|
+
static_files: row("static_file", "id", ["id"]),
|
|
145
147
|
domains: row("domain", "id", ["id"]),
|
|
146
148
|
site_defaults: row("site_defaults", "id", ["id"]),
|
|
147
149
|
site_settings: row("site_settings", "id", ["id"]),
|
|
@@ -166,6 +168,7 @@ export const JOURNALED_TABLES: Readonly<Record<string, JournaledTable>> = {
|
|
|
166
168
|
list_type_snapshots: snapshot("list_type", "list_type_id"),
|
|
167
169
|
page_type_snapshots: snapshot("page_type", "page_type_id"),
|
|
168
170
|
theme_snapshots: snapshot("theme", "theme_id"),
|
|
171
|
+
static_file_snapshots: snapshot("static_file", "static_file_id"),
|
|
169
172
|
plugin_row_snapshots: snapshot("plugin_row", "row_id", {
|
|
170
173
|
parent: "table_name",
|
|
171
174
|
plugin: "plugin_id",
|
|
@@ -263,6 +266,8 @@ export const JOURNAL_EXEMPT_TABLES: Readonly<Record<string, string>> = {
|
|
|
263
266
|
plugin_rate_limit_proposals: QUEUE,
|
|
264
267
|
|
|
265
268
|
ai_providers: "Owner AI configuration; read per call, nothing is derived from it",
|
|
269
|
+
mcp_only_mode:
|
|
270
|
+
"#1460: the Owner's choice to run without an AI key; read per call, nothing is derived from it",
|
|
266
271
|
ai_budgets: "Owner AI budgets; read per call, nothing is derived from it",
|
|
267
272
|
ai_pricing: "Owner AI pricing; read per call, nothing is derived from it",
|
|
268
273
|
email_config: "Owner email configuration; read per send",
|
|
@@ -333,6 +338,7 @@ export const JOURNAL_EXEMPT_TABLES: Readonly<Record<string, string>> = {
|
|
|
333
338
|
ai_providers_pending_actions: QUEUE,
|
|
334
339
|
deploy_pending_actions: QUEUE,
|
|
335
340
|
domain_pending_actions: QUEUE,
|
|
341
|
+
static_file_pending_actions: QUEUE,
|
|
336
342
|
email_config_pending_actions: QUEUE,
|
|
337
343
|
layout_pending_actions: QUEUE,
|
|
338
344
|
mcp_token_pending_actions: QUEUE,
|
package/src/index.ts
CHANGED
|
@@ -35,6 +35,7 @@ export * from "./google-models.js";
|
|
|
35
35
|
export * from "./google-oauth.js";
|
|
36
36
|
export * from "./id-safe-truncate.js";
|
|
37
37
|
export * from "./image-capabilities.js";
|
|
38
|
+
export * from "./install-ai-mode.js";
|
|
38
39
|
export * from "./interactions.js";
|
|
39
40
|
export * from "./json-security-headers.js";
|
|
40
41
|
export * from "./link-canonicalise.js";
|
|
@@ -89,6 +90,7 @@ export * from "./staged-site.js";
|
|
|
89
90
|
export * from "./staging-gate.js";
|
|
90
91
|
export * from "./staging-plugin-stub.js";
|
|
91
92
|
export * from "./static-cache-policy.js";
|
|
93
|
+
export * from "./static-files.js";
|
|
92
94
|
export * from "./static-security-headers.js";
|
|
93
95
|
export * from "./strip-cdata.js";
|
|
94
96
|
export * from "./subagents.js";
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Issue #1460 — how an install runs AI, in the words every surface shares.
|
|
5
|
+
* Client-safe: the admin UI renders these, admin-core words its refusals
|
|
6
|
+
* with them. The concept is docs/dev/mcp-access.md.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* - `provider`: a usable AI key exists; the install's own AI runs.
|
|
11
|
+
* - `mcp_only`: the Owner chose to run without a key, through Power-MCP.
|
|
12
|
+
* - `unset`: neither yet; the first-run gate asks the Owner.
|
|
13
|
+
*/
|
|
14
|
+
export type InstallAiMode = "provider" | "mcp_only" | "unset";
|
|
15
|
+
|
|
16
|
+
/** Prefix of every refusal for work that would need the install's own AI. */
|
|
17
|
+
export const NO_INSTALL_AI_PREFIX = "NoInstallAi:";
|
|
18
|
+
|
|
19
|
+
/** What this mode leaves off, in the sentence the wizard and Settings → AI share. */
|
|
20
|
+
export const MCP_ONLY_LEAVES_OFF =
|
|
21
|
+
"The Live Edit chat and the AI work of the install itself stay off; your connected agent does that work.";
|
|
22
|
+
|
|
23
|
+
/** Why a chat token or the chat address is unavailable, and what works instead. */
|
|
24
|
+
export const CHAT_SURFACE_NEEDS_INSTALL_AI =
|
|
25
|
+
"Chat access runs this site's own AI, and this install has no AI key. Use admin access (Power-MCP) instead: your agent does the AI work. Storing a key under Settings → AI makes chat access available.";
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* The refusal for work that needs the install's own AI in this mode. Starts
|
|
29
|
+
* with {@link NO_INSTALL_AI_PREFIX} and names both ways forward.
|
|
30
|
+
*
|
|
31
|
+
* @param what what would have run, as a noun phrase ("The chat")
|
|
32
|
+
*/
|
|
33
|
+
export function noInstallAiRefusal(what: string): string {
|
|
34
|
+
return `${NO_INSTALL_AI_PREFIX} ${what} needs this install's own AI, and the Owner runs this install without an AI key (Power-MCP only). Do the work through an agent connected with an admin-scope MCP token (/settings/mcp), or store a key under Settings → AI (/settings/ai), which ends this mode at once.`;
|
|
35
|
+
}
|
|
@@ -113,6 +113,14 @@ describe("templates and free regions", () => {
|
|
|
113
113
|
expect(performance.now() - started).toBeLessThan(500);
|
|
114
114
|
});
|
|
115
115
|
|
|
116
|
+
it("stripMustache markTagPlaceholders marks values in a tag, keeps optional text (#1445)", () => {
|
|
117
|
+
const t = '<i class="s{{a}} {{#on}}x-{{{b}}}{{/on}}{{ ^off }}y{{ /off }}">{{c}}</i>';
|
|
118
|
+
expect(stripMustache(t, { keepOptionalAttributeText: true, markTagPlaceholders: true })).toBe(
|
|
119
|
+
'<i class="s\u001f x-\u001fy"></i>',
|
|
120
|
+
);
|
|
121
|
+
expect(stripMustache(t, { keepOptionalAttributeText: true })).toBe('<i class="s x-y"></i>');
|
|
122
|
+
});
|
|
123
|
+
|
|
116
124
|
it("stripMustache markSections keeps sections between elements as markers (#1256)", () => {
|
|
117
125
|
const t =
|
|
118
126
|
'<ul class="x {{#on}}on{{/on}}">{{#links}}<li><a href="{{link}}">{{label}}</a></li>{{/links}}{{^links}}<p>none</p>{{/links}}</ul>';
|
package/src/markup-structure.ts
CHANGED
|
@@ -137,6 +137,13 @@ export interface StripMustacheOptions {
|
|
|
137
137
|
* `keepOptionalAttributeText` (in-tag sections must be dropped first).
|
|
138
138
|
*/
|
|
139
139
|
readonly markSections?: boolean;
|
|
140
|
+
/**
|
|
141
|
+
* #1445 — with `keepOptionalAttributeText`: turn each value placeholder
|
|
142
|
+
* inside a tag into {@link PLACEHOLDER_MARK} instead of removing it, so
|
|
143
|
+
* `class="s{{group}}"` parses as the token `s\u001f` and a reader sees
|
|
144
|
+
* that the class is built from a field.
|
|
145
|
+
*/
|
|
146
|
+
readonly markTagPlaceholders?: boolean;
|
|
140
147
|
}
|
|
141
148
|
|
|
142
149
|
/** The marker element {@link stripMustache} `markSections` emits. */
|
|
@@ -177,14 +184,17 @@ export function stripMustache(template: string, opts: StripMustacheOptions = {})
|
|
|
177
184
|
const marked =
|
|
178
185
|
opts.markSections && !opts.keepOptionalAttributeText
|
|
179
186
|
? markSections(markTagPlaceholders(base))
|
|
180
|
-
:
|
|
187
|
+
: opts.markTagPlaceholders
|
|
188
|
+
? markTagPlaceholders(base)
|
|
189
|
+
: base;
|
|
181
190
|
return stripDelimited(stripDelimited(marked, 3), 2);
|
|
182
191
|
}
|
|
183
192
|
|
|
184
193
|
/**
|
|
185
194
|
* Replace every placeholder inside a tag (`{{x}}`, `{{{x}}}`) with
|
|
186
195
|
* {@link PLACEHOLDER_MARK}. One linear scan, tags tracked as in
|
|
187
|
-
* {@link dropInTagSections}; placeholders between elements
|
|
196
|
+
* {@link dropInTagSections}; placeholders between elements and section
|
|
197
|
+
* tags (`{{#s}}`, left in a tag only when its body is kept) are left for
|
|
188
198
|
* the strip.
|
|
189
199
|
*/
|
|
190
200
|
function markTagPlaceholders(text: string): string {
|
|
@@ -197,7 +207,8 @@ function markTagPlaceholders(text: string): string {
|
|
|
197
207
|
const end = text.indexOf("}}", i + 2);
|
|
198
208
|
if (end < 0) break;
|
|
199
209
|
const close = text.startsWith("}}}", end) ? end + 3 : end + 2;
|
|
200
|
-
|
|
210
|
+
const section = /^\{\{\s*[#^/]/.test(text.slice(i, end));
|
|
211
|
+
out += inTag && !section ? PLACEHOLDER_MARK : text.slice(i, close);
|
|
201
212
|
i = close;
|
|
202
213
|
continue;
|
|
203
214
|
}
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
22
|
import type { RedirectPlan } from "./redirect-plan.js";
|
|
23
|
+
import type { StaticFileManifestEntry } from "./static-files.js";
|
|
23
24
|
import { trimTrailingSlashes } from "./url.js";
|
|
24
25
|
|
|
25
26
|
/** The file name the generator writes the snippet to, at the build root. */
|
|
@@ -101,3 +102,20 @@ function assertCaddySafe(fromPath: string, location: string): void {
|
|
|
101
102
|
}
|
|
102
103
|
}
|
|
103
104
|
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* #1461 — the static files' Content-Types, appended to the redirects
|
|
108
|
+
* snippet: the one file a public site block imports from its build, reloaded
|
|
109
|
+
* by the Caddy container when it changes, so no Caddyfile changes. Caddy
|
|
110
|
+
* types a file by its name, which says nothing for an extension-less path
|
|
111
|
+
* and cannot tell `text/xml` from `application/xml`. The paths passed the
|
|
112
|
+
* path rules, so none holds a Caddyfile character.
|
|
113
|
+
*/
|
|
114
|
+
export function emitCaddyStaticFileHeaders(files: readonly StaticFileManifestEntry[]): string {
|
|
115
|
+
return files
|
|
116
|
+
.map(
|
|
117
|
+
(f, i) =>
|
|
118
|
+
`@caelo_static_${i} path /${f.path}\nheader @caelo_static_${i} Content-Type "${f.contentType}"\n`,
|
|
119
|
+
)
|
|
120
|
+
.join("");
|
|
121
|
+
}
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
formatRedirectsFile,
|
|
12
12
|
parseRedirectsFile,
|
|
13
13
|
type RedirectTableRow,
|
|
14
|
+
redirectFromPathSpellings,
|
|
14
15
|
redirectsToUnservedPaths,
|
|
15
16
|
} from "./redirect-plan.js";
|
|
16
17
|
|
|
@@ -166,3 +167,14 @@ describe("redirectsToUnservedPaths (#1157)", () => {
|
|
|
166
167
|
expect(redirectsToUnservedPaths(p, served)).toEqual([]);
|
|
167
168
|
});
|
|
168
169
|
});
|
|
170
|
+
|
|
171
|
+
describe("redirectFromPathSpellings", () => {
|
|
172
|
+
it("names both spellings of a path, from either one", () => {
|
|
173
|
+
expect(redirectFromPathSpellings("/old")).toEqual(["/old", "/old/"]);
|
|
174
|
+
expect(redirectFromPathSpellings("/old/")).toEqual(["/old", "/old/"]);
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
it("leaves the root alone", () => {
|
|
178
|
+
expect(redirectFromPathSpellings("/")).toEqual(["/"]);
|
|
179
|
+
});
|
|
180
|
+
});
|