@conloca/content-api 0.2.2 → 0.2.4
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/.build-inputs.json +82 -0
- package/dist/address-site.d.ts +6 -0
- package/dist/address-site.d.ts.map +1 -0
- package/dist/address-site.js +15 -0
- package/dist/address-site.js.map +1 -0
- package/dist/asset-constraints.d.ts +9 -1
- package/dist/asset-constraints.d.ts.map +1 -1
- package/dist/asset-constraints.js +10 -2
- package/dist/asset-constraints.js.map +1 -1
- package/dist/asset-metadata-record.d.ts +18 -0
- package/dist/asset-metadata-record.d.ts.map +1 -0
- package/dist/asset-metadata-record.js +59 -0
- package/dist/asset-metadata-record.js.map +1 -0
- package/dist/asset-metadata-store.d.ts.map +1 -1
- package/dist/asset-metadata-store.js +7 -26
- package/dist/asset-metadata-store.js.map +1 -1
- package/dist/asset-naming.d.ts +39 -0
- package/dist/asset-naming.d.ts.map +1 -0
- package/dist/asset-naming.js +123 -0
- package/dist/asset-naming.js.map +1 -0
- package/dist/asset-operations.d.ts +15 -2
- package/dist/asset-operations.d.ts.map +1 -1
- package/dist/asset-operations.js +99 -90
- package/dist/asset-operations.js.map +1 -1
- package/dist/asset-types.d.ts +2 -0
- package/dist/asset-types.d.ts.map +1 -1
- package/dist/asset-usage.d.ts +8 -1
- package/dist/asset-usage.d.ts.map +1 -1
- package/dist/asset-usage.js +4 -1
- package/dist/asset-usage.js.map +1 -1
- package/dist/component-registry.d.ts +3 -0
- package/dist/component-registry.d.ts.map +1 -1
- package/dist/content-utils.d.ts +4 -1
- package/dist/content-utils.d.ts.map +1 -1
- package/dist/content-utils.js +14 -1
- package/dist/content-utils.js.map +1 -1
- package/dist/draft-media-ref.d.ts +9 -0
- package/dist/draft-media-ref.d.ts.map +1 -0
- package/dist/draft-media-ref.js +47 -0
- package/dist/draft-media-ref.js.map +1 -0
- package/dist/editor-host.d.ts +174 -0
- package/dist/editor-host.d.ts.map +1 -0
- package/dist/editor-host.js +304 -0
- package/dist/editor-host.js.map +1 -0
- package/dist/filesystem-content-api.d.ts +15 -0
- package/dist/filesystem-content-api.d.ts.map +1 -1
- package/dist/filesystem-content-api.js +3 -2
- package/dist/filesystem-content-api.js.map +1 -1
- package/dist/git-operations.d.ts +0 -5
- package/dist/git-operations.d.ts.map +1 -1
- package/dist/git-operations.js +1 -33
- package/dist/git-operations.js.map +1 -1
- package/dist/image-format.d.ts +9 -0
- package/dist/image-format.d.ts.map +1 -0
- package/dist/image-format.js +100 -0
- package/dist/image-format.js.map +1 -0
- package/dist/image-metadata.d.ts +11 -0
- package/dist/image-metadata.d.ts.map +1 -0
- package/dist/image-metadata.js +283 -0
- package/dist/image-metadata.js.map +1 -0
- package/dist/image-shrink.d.ts +15 -0
- package/dist/image-shrink.d.ts.map +1 -0
- package/dist/image-shrink.js +52 -0
- package/dist/image-shrink.js.map +1 -0
- package/dist/index.d.ts +8 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +16 -3
- package/dist/index.js.map +1 -1
- package/dist/lfs-attributes.d.ts +26 -0
- package/dist/lfs-attributes.d.ts.map +1 -0
- package/dist/lfs-attributes.js +285 -0
- package/dist/lfs-attributes.js.map +1 -0
- package/dist/site.d.ts.map +1 -1
- package/dist/site.js +3 -1
- package/dist/site.js.map +1 -1
- package/dist/skill-stamp.d.ts +10 -0
- package/dist/skill-stamp.d.ts.map +1 -0
- package/dist/skill-stamp.js +42 -0
- package/dist/skill-stamp.js.map +1 -0
- package/dist/svg-sanitize.d.ts +8 -0
- package/dist/svg-sanitize.d.ts.map +1 -0
- package/dist/svg-sanitize.js +260 -0
- package/dist/svg-sanitize.js.map +1 -0
- package/dist/types.d.ts +9 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/upload-bytes.d.ts +17 -0
- package/dist/upload-bytes.d.ts.map +1 -0
- package/dist/upload-bytes.js +43 -0
- package/dist/upload-bytes.js.map +1 -0
- package/dist/upload-refusals.d.ts +24 -0
- package/dist/upload-refusals.d.ts.map +1 -0
- package/dist/upload-refusals.js +49 -0
- package/dist/upload-refusals.js.map +1 -0
- package/package.json +49 -6
- package/src/address-site.ts +19 -0
- package/src/asset-constraints.ts +14 -2
- package/src/asset-metadata-record.ts +57 -0
- package/src/asset-metadata-store.ts +12 -21
- package/src/asset-naming.ts +120 -0
- package/src/asset-operations.ts +108 -91
- package/src/asset-types.ts +2 -0
- package/src/asset-usage.ts +16 -2
- package/src/content-utils.ts +18 -2
- package/src/draft-media-ref.ts +46 -0
- package/src/editor-host.ts +384 -0
- package/src/filesystem-content-api.ts +3 -2
- package/src/git-operations.ts +1 -38
- package/src/image-format.ts +87 -0
- package/src/image-metadata.ts +266 -0
- package/src/image-shrink.ts +57 -0
- package/src/index.ts +47 -3
- package/src/lfs-attributes.ts +291 -0
- package/src/site.ts +3 -1
- package/src/skill-stamp.ts +45 -0
- package/src/svg-sanitize.ts +260 -0
- package/src/types.ts +9 -0
- package/src/upload-bytes.ts +46 -0
- package/src/upload-refusals.ts +59 -0
package/dist/content-utils.js
CHANGED
|
@@ -181,6 +181,7 @@ export function getMetadataSize(meta) {
|
|
|
181
181
|
* - Must start with /
|
|
182
182
|
* - Cannot contain spaces (should be URL-encoded)
|
|
183
183
|
* - Cannot contain special characters that would break URLs
|
|
184
|
+
* - Cannot be under the reserved `/_conloca/` prefix
|
|
184
185
|
*/
|
|
185
186
|
export function isValidPathname(pathname) {
|
|
186
187
|
if (!pathname?.startsWith('/'))
|
|
@@ -189,7 +190,11 @@ export function isValidPathname(pathname) {
|
|
|
189
190
|
return false;
|
|
190
191
|
if (pathname.includes('?') || pathname.includes('#'))
|
|
191
192
|
return false;
|
|
192
|
-
return
|
|
193
|
+
return !isReservedPathname(pathname);
|
|
194
|
+
}
|
|
195
|
+
/** True for `/_conloca` and everything under it: the editor page a site build writes there owns those paths. */
|
|
196
|
+
export function isReservedPathname(pathname) {
|
|
197
|
+
return pathname === '/_conloca' || pathname.startsWith('/_conloca/');
|
|
193
198
|
}
|
|
194
199
|
/**
|
|
195
200
|
* Normalize a pathname to ensure consistency
|
|
@@ -262,6 +267,14 @@ export function normalizeAndValidatePathname(input) {
|
|
|
262
267
|
value = value.replace(/\/+/g, '/');
|
|
263
268
|
if (value !== '/' && value.endsWith('/'))
|
|
264
269
|
value = value.slice(0, -1);
|
|
270
|
+
if (isReservedPathname(value)) {
|
|
271
|
+
return {
|
|
272
|
+
value,
|
|
273
|
+
valid: false,
|
|
274
|
+
reason: 'reserved_prefix',
|
|
275
|
+
message: 'Paths under `/_conloca/` are reserved for the editor page',
|
|
276
|
+
};
|
|
277
|
+
}
|
|
265
278
|
// Segment-level check: `.` and `..` are never valid path segments.
|
|
266
279
|
// Run before the generic disallowed-char check so the user gets the
|
|
267
280
|
// more specific "traversal" message.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"content-utils.js","sourceRoot":"","sources":["../src/content-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,IAAI,EAAE,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AAChD,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAG1C,4EAA4E;AAC5E,gFAAgF;AAChF,6EAA6E;AAC7E,6EAA6E;AAC7E,qBAAqB;AACrB,MAAM,qBAAqB,GAAG;IAC5B,OAAO;IACP,UAAU;IACV,aAAa;IACb,IAAI;IACJ,SAAS;IACT,UAAU;IACV,WAAW;IACX,aAAa;CACL,CAAC;AAEX,wEAAwE;AACxE,iFAAiF;AACjF,+EAA+E;AAC/E,6EAA6E;AAC7E,sDAAsD;AACtD,MAAM,gBAAgB,GAAG,sEAAsE,CAAC;AAEhG,MAAM,SAAS,CAAC,CAAC,SAAS,CAAI,QAAoD;IAChF,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,MAAM,CAAC,Q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*/
|
|
2
|
+
export declare const DRAFT_MEDIA_REF_BASE = "/api/v1/assets/serve";
|
|
3
|
+
/** The draft address of a path inside the media library, written raw, never URL-encoded. */
|
|
4
|
+
export declare function draftMediaRef(path: string): string;
|
|
5
|
+
/** The raw media path of a link that is exactly `${base}/<path>`, or `undefined` when it is not a safe image path. */
|
|
6
|
+
export declare function mediaRefPath(value: string, base: string): string | undefined;
|
|
7
|
+
/** The raw media path of a draft address, or `undefined` when the value is not one. */
|
|
8
|
+
export declare function draftMediaRefPath(value: string): string | undefined;
|
|
9
|
+
//# sourceMappingURL=draft-media-ref.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"draft-media-ref.d.ts","sourceRoot":"","sources":["../src/draft-media-ref.ts"],"names":[],"mappings":"AAMA,gDAAgD;AAChD,eAAO,MAAM,oBAAoB,yBAAyB,CAAC;AAE3D,4FAA4F;AAC5F,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAElD;AAED,sHAAsH;AACtH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAgB5E;AAWD,uFAAuF;AACvF,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAEnE"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where the editor links an image uploaded on a branch but not yet published: a path no site serves, so it is never
|
|
3
|
+
* mistaken for one of the site's own images.
|
|
4
|
+
*/
|
|
5
|
+
import { IMAGE_EXTENSION_MIME } from './asset-constraints.js';
|
|
6
|
+
/** The path every draft address starts with. */
|
|
7
|
+
export const DRAFT_MEDIA_REF_BASE = '/api/v1/assets/serve';
|
|
8
|
+
/** The draft address of a path inside the media library, written raw, never URL-encoded. */
|
|
9
|
+
export function draftMediaRef(path) {
|
|
10
|
+
return `${DRAFT_MEDIA_REF_BASE}/${path}`;
|
|
11
|
+
}
|
|
12
|
+
/** The raw media path of a link that is exactly `${base}/<path>`, or `undefined` when it is not a safe image path. */
|
|
13
|
+
export function mediaRefPath(value, base) {
|
|
14
|
+
if (!value.startsWith(`${base}/`))
|
|
15
|
+
return undefined;
|
|
16
|
+
const path = value.slice(base.length + 1);
|
|
17
|
+
if (/[\\?#]/.test(path))
|
|
18
|
+
return undefined;
|
|
19
|
+
const segments = path.split('/');
|
|
20
|
+
for (const part of segments) {
|
|
21
|
+
if (part === '' || part === '.' || part === '..' || hasControlChar(part)) {
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
const filename = segments[segments.length - 1] ?? '';
|
|
26
|
+
const dot = filename.lastIndexOf('.');
|
|
27
|
+
if (dot <= 0)
|
|
28
|
+
return undefined;
|
|
29
|
+
const extension = filename.slice(dot + 1).toLowerCase();
|
|
30
|
+
if (!Object.prototype.hasOwnProperty.call(IMAGE_EXTENSION_MIME, extension))
|
|
31
|
+
return undefined;
|
|
32
|
+
return path;
|
|
33
|
+
}
|
|
34
|
+
/** Whether `text` holds an ASCII control character (U+0000–U+001F or U+007F). */
|
|
35
|
+
function hasControlChar(text) {
|
|
36
|
+
for (let index = 0; index < text.length; index += 1) {
|
|
37
|
+
const code = text.charCodeAt(index);
|
|
38
|
+
if (code < 32 || code === 127)
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
/** The raw media path of a draft address, or `undefined` when the value is not one. */
|
|
44
|
+
export function draftMediaRefPath(value) {
|
|
45
|
+
return mediaRefPath(value, DRAFT_MEDIA_REF_BASE);
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=draft-media-ref.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"draft-media-ref.js","sourceRoot":"","sources":["../src/draft-media-ref.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,oBAAoB,EAAE,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CAAC;IAC7F,OAAO,IAAI,CAAC;AACd,CAAC;AAED,iFAAiF;AACjF,SAAS,cAAc,CAAC,IAAY;IAClC,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,IAAI,CAAC,MAAM,EAAE,KAAK,IAAI,CAAC,EAAE,CAAC;QACpD,MAAM,IAAI,GAAG,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;QACpC,IAAI,IAAI,GAAG,EAAE,IAAI,IAAI,KAAK,GAAG;YAAE,OAAO,IAAI,CAAC;IAC7C,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,uFAAuF;AACvF,MAAM,UAAU,iBAAiB,CAAC,KAAa;IAC7C,OAAO,YAAY,CAAC,KAAK,EAAE,oBAAoB,CAAC,CAAC;AACnD,CAAC"}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
/** The wire protocol an editor page built by this release speaks; the editor UI path is /host/v<this>/. */
|
|
2
|
+
export declare const EDITOR_HOST_PROTOCOL = 1;
|
|
3
|
+
/** Protocols the current editor UI accepts. */
|
|
4
|
+
export declare const EDITOR_HOST_PROTOCOLS: {
|
|
5
|
+
readonly min: 1;
|
|
6
|
+
readonly max: 1;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* The draft-preview protocol a preview server built by this release speaks. Protocol 1 keeps the pass out of the
|
|
10
|
+
* page; protocol 2 opens a preview with a single-use code the server trades for the pass, so no pass travels in a
|
|
11
|
+
* link. conloca.json `preview.protocol` and the exit route's `conloca-preview-protocol` header carry it.
|
|
12
|
+
*/
|
|
13
|
+
export declare const PREVIEW_PROTOCOL = 2;
|
|
14
|
+
/**
|
|
15
|
+
* How a build serves draft previews: `d2` from the site's own server deploy, `d3` from a dispatcher in front of a
|
|
16
|
+
* static site under `<base>_conloca/preview/<branch slug>/`, `d4` from a separate preview deploy, `off` not at all.
|
|
17
|
+
*/
|
|
18
|
+
export type PreviewMode = 'd2' | 'd3' | 'd4' | 'off';
|
|
19
|
+
/** conloca.json `preview`: the build's preview mode and the preview protocol it speaks. */
|
|
20
|
+
export interface PreviewSignal {
|
|
21
|
+
mode: PreviewMode;
|
|
22
|
+
protocol: number;
|
|
23
|
+
}
|
|
24
|
+
/** A branch name as one path segment and cookie-name suffix: its UTF-8 bytes as unpadded base64url, one slug per name. */
|
|
25
|
+
export declare function previewBranchSlug(branch: string): string;
|
|
26
|
+
/** The branch a slug names, or null unless it is the slug of a valid branch name (at most 765 UTF-8 bytes, 1020 characters; 1360 bounds it with room). */
|
|
27
|
+
export declare function branchOfPreviewSlug(slug: string): string | null;
|
|
28
|
+
/** Whether a branch's slug leaves room in a 1024-byte cookie `Path` (`<base>_conloca/preview/<slug>`). */
|
|
29
|
+
export declare function previewSlugFits(branch: string): boolean;
|
|
30
|
+
/** conloca.json `preview`; `undefined` when absent or malformed, so a bad optional field never makes the page invalid. */
|
|
31
|
+
export declare function previewSignalOf(info: ConlocaJson): PreviewSignal | undefined;
|
|
32
|
+
export declare const DEFAULT_EDITOR_ENDPOINT = "https://app.conloca.com";
|
|
33
|
+
/** Where the editor page is served, below the site's base. */
|
|
34
|
+
export declare const EDITOR_PAGE_PATH = "/_conloca/editor/";
|
|
35
|
+
/** The deployable-site id grammar (moved here from cloud-astro's site-id.ts; the census imports it too). */
|
|
36
|
+
export declare const SITE_ID_RE: RegExp;
|
|
37
|
+
/** The editor UI origin for an endpoint, or null unless its host is `app.` plus at least two labels. */
|
|
38
|
+
export declare function editorUiOrigin(endpoint: string | undefined): string | null;
|
|
39
|
+
/** The parent root for a URL on the editor UI origin (`app.conloca.com` → `conloca.com`), or null under the same rule. */
|
|
40
|
+
export declare function parentRoot(url: string): string | null;
|
|
41
|
+
/** Editor UI file per bare specifier the page's bundle keeps external, under `<origin>/host/v<protocol>/`. */
|
|
42
|
+
export declare const EDITOR_UI_MODULE_FILES: {
|
|
43
|
+
readonly react: 'react.js';
|
|
44
|
+
readonly 'react-dom': 'react-dom.js';
|
|
45
|
+
readonly 'react-dom/client': 'react-dom-client.js';
|
|
46
|
+
readonly 'react/jsx-runtime': 'jsx-runtime.js';
|
|
47
|
+
readonly 'react/jsx-dev-runtime': 'jsx-dev-runtime.js';
|
|
48
|
+
readonly '@puckeditor/core': 'puck.js';
|
|
49
|
+
};
|
|
50
|
+
export type EditorHostStatus = 'ready' | 'no-address' | 'blocked-address' | 'unreachable' | 'protected' | 'not-found' | 'invalid' | 'wrong-repo' | 'wrong-site' | 'unsupported-protocol' | 'frame-blocked';
|
|
51
|
+
export type EditorFrameFailure = 'handshake-timeout' | 'origin-rejected' | 'unsupported-protocol' | 'site-load-failed';
|
|
52
|
+
/** The page's inline JSON block, `<script type="application/json" id="conloca-editor-host">`. URLs are base-absolute. */
|
|
53
|
+
export interface EditorHostPageData {
|
|
54
|
+
protocol: number;
|
|
55
|
+
repo: string | null;
|
|
56
|
+
siteId: string;
|
|
57
|
+
site: string;
|
|
58
|
+
css: string[];
|
|
59
|
+
editorCss: string | null;
|
|
60
|
+
sandboxFrame: string;
|
|
61
|
+
info: string;
|
|
62
|
+
}
|
|
63
|
+
/** conloca.json: public facts about one deploy of the editor page. Grants nothing. */
|
|
64
|
+
export interface EditorPageInfo {
|
|
65
|
+
protocol: number;
|
|
66
|
+
repo: string | null;
|
|
67
|
+
siteId: string;
|
|
68
|
+
commit: string | null;
|
|
69
|
+
branch: string | null;
|
|
70
|
+
builtWith: string;
|
|
71
|
+
/** `path` is relative to the editor folder. */
|
|
72
|
+
componentManifest: {
|
|
73
|
+
path: string;
|
|
74
|
+
sha256: string;
|
|
75
|
+
} | null;
|
|
76
|
+
}
|
|
77
|
+
/** The file beside conloca.json holding each `dataSchemas` collection's JSON schema, as `{ collections }`. */
|
|
78
|
+
export declare const DATA_SCHEMAS_FILE = "data-schemas.json";
|
|
79
|
+
export declare const EDITOR_PAGE_INFO_FORMATS: {
|
|
80
|
+
readonly commit: RegExp;
|
|
81
|
+
readonly builtWith: RegExp;
|
|
82
|
+
readonly repo: RegExp;
|
|
83
|
+
readonly siteId: RegExp;
|
|
84
|
+
readonly sha256: RegExp;
|
|
85
|
+
readonly manifestPath: RegExp;
|
|
86
|
+
};
|
|
87
|
+
/** Where the host serves a build of every other branch, recorded by the production build. */
|
|
88
|
+
export type BranchDeploys = {
|
|
89
|
+
host: 'cloudflare-pages';
|
|
90
|
+
project: string;
|
|
91
|
+
};
|
|
92
|
+
/** A parsed conloca.json object, whether or not it passed `isEditorPageInfo`, as the optional-field readers take it. */
|
|
93
|
+
export type ConlocaJson = EditorPageInfo | {
|
|
94
|
+
branchDeploys?: unknown;
|
|
95
|
+
contentPaths?: unknown;
|
|
96
|
+
preview?: unknown;
|
|
97
|
+
routes?: unknown;
|
|
98
|
+
media?: unknown;
|
|
99
|
+
};
|
|
100
|
+
/** conloca.json `branchDeploys`; `undefined` when absent or malformed, so a bad optional field never makes the page invalid. */
|
|
101
|
+
export declare function branchDeploysOf(info: ConlocaJson): BranchDeploys | undefined;
|
|
102
|
+
export declare const CONTENT_PATHS_MAX = 16;
|
|
103
|
+
/**
|
|
104
|
+
* conloca.json `contentPaths`: repository paths the site's content lives under, duplicates removed;
|
|
105
|
+
* `undefined` when absent or malformed, so a bad optional field never makes the page invalid.
|
|
106
|
+
*/
|
|
107
|
+
export declare function contentPathsOf(info: ConlocaJson): string[] | undefined;
|
|
108
|
+
/** The most bytes of conloca.json the workspace editor reads; a build never writes more. */
|
|
109
|
+
export declare const CONLOCA_JSON_MAX_BYTES: number;
|
|
110
|
+
/** A page route: `/` then at most 200 unreserved URL characters or `/`, so no route carries prompt or shell syntax. */
|
|
111
|
+
export declare const EDITOR_ROUTE_RE: RegExp;
|
|
112
|
+
/** The most routes a conloca.json lists. */
|
|
113
|
+
export declare const ROUTES_MAX = 500;
|
|
114
|
+
/** Whether `route` is a string matching `EDITOR_ROUTE_RE`. */
|
|
115
|
+
export declare function isEditorRoute(route: unknown): route is string;
|
|
116
|
+
/**
|
|
117
|
+
* conloca.json `routes`: the page routes a build lists, those outside `EDITOR_ROUTE_RE` and duplicates dropped,
|
|
118
|
+
* at most `ROUTES_MAX`; `undefined` when absent or not a list, so a bad optional field never makes the page invalid.
|
|
119
|
+
*/
|
|
120
|
+
export declare function routesOf(info: ConlocaJson): string[] | undefined;
|
|
121
|
+
/** conloca.json `media`: the repository folder uploaded images go to and the URL the site serves it at. */
|
|
122
|
+
export interface EditorMedia {
|
|
123
|
+
path: string;
|
|
124
|
+
refBase: string;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* conloca.json `media`; `undefined` when absent or malformed (the repository root, a folder `folderPathError`
|
|
128
|
+
* refuses, or a link base {@link REF_BASE_RE} refuses), so a bad optional field never makes the page invalid. The
|
|
129
|
+
* link base is written into saved pages, so it may hold nothing a page's JSON, front matter or MDX would read.
|
|
130
|
+
*/
|
|
131
|
+
export declare function mediaOf(info: ConlocaJson): EditorMedia | undefined;
|
|
132
|
+
/** Git's ref-name rules for one branch name, at most 255 characters. */
|
|
133
|
+
export declare function isValidBranchName(name: string): boolean;
|
|
134
|
+
/** Shape and field formats of a parsed conloca.json; null allowed where the type allows it. */
|
|
135
|
+
export declare function isEditorPageInfo(value: unknown): value is EditorPageInfo;
|
|
136
|
+
/** True when `location` is an absolute URL on vercel.com or a subdomain (Vercel's sign-in redirect). */
|
|
137
|
+
export declare function isVercelSignIn(location: string | null): boolean;
|
|
138
|
+
/** Any Vercel signal on an answer: an `x-vercel-*` header or a sign-in redirect. Feeds the classifier's `vercel`. */
|
|
139
|
+
export declare function isFromVercel(headers: Headers): boolean;
|
|
140
|
+
/** What one conloca.json answer means; `info` is the parsed file once it passed the format checks. */
|
|
141
|
+
export interface EditorHostVerdict {
|
|
142
|
+
status: EditorHostStatus;
|
|
143
|
+
reason?: 'repo-missing';
|
|
144
|
+
info?: EditorPageInfo;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* One conloca.json answer → status; body is null when not read (non-200 or over the cap).
|
|
148
|
+
* `vercel` (any Vercel signal) only picks the caller's message: an ordinary redirect on Vercel stays `invalid`.
|
|
149
|
+
*/
|
|
150
|
+
export declare function classifyEditorHostResponse(response: {
|
|
151
|
+
status: number;
|
|
152
|
+
contentType: string | null;
|
|
153
|
+
location: string | null;
|
|
154
|
+
vercel: boolean;
|
|
155
|
+
body: string | null;
|
|
156
|
+
}, expected: {
|
|
157
|
+
repoUri: string;
|
|
158
|
+
siteId: string;
|
|
159
|
+
protocols: {
|
|
160
|
+
min: number;
|
|
161
|
+
max: number;
|
|
162
|
+
};
|
|
163
|
+
}): EditorHostVerdict;
|
|
164
|
+
/**
|
|
165
|
+
* Frame headers of the page → whether a workspace parent may frame it. `allowedAncestors` are the source expressions
|
|
166
|
+
* that admit the workspace; `*` and `https:` always do. A `frame-ancestors` directive overrides X-Frame-Options.
|
|
167
|
+
* shortcut: sources match as exact tokens, so a broader host wildcard (`https://*.com`) reads as blocked; parse
|
|
168
|
+
* host patterns if a real site needs one.
|
|
169
|
+
*/
|
|
170
|
+
export declare function classifyFrameHeaders(headers: {
|
|
171
|
+
xFrameOptions: string | null;
|
|
172
|
+
csp: string | null;
|
|
173
|
+
}, allowedAncestors: readonly string[]): 'ok' | 'frame-blocked';
|
|
174
|
+
//# sourceMappingURL=editor-host.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"editor-host.d.ts","sourceRoot":"","sources":["../src/editor-host.ts"],"names":[],"mappings":"AAGA,2GAA2G;AAC3G,eAAO,MAAM,oBAAoB,IAAI,CAAC;AACtC,+CAA+C;AAC/C,eAAO,MAAM,qBAAqB;aAAK,GAAG,EAAE,CAAC;aAAE,GAAG,EAAE,CAAC;CAAW,CAAC;AACjE;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,IAAI,CAAC;AAElC;;;GAGG;AACH,MAAM,MAAM,WAAW,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,KAAK,CAAC;AAQrD,2FAA2F;AAC3F,MAAM,WAAW,aAAa;IAC5B,I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ACvB;AAED;;;GAGG;AACH,wBAAgB,0BAA0B,CACxC,QAAQ,EAAE;IACR,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,MAAM,EAAE,OAAO,CAAC;IAChB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CACrB,EACD,QAAQ,EAAE;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE,GACrF,iBAAiB,CA0BnB;AAOD;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE;IAAE,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,EAC7D,gBAAgB,EAAE,SAAS,MAAM,EAAE,GAClC,IAAI,GAAG,eAAe,CAiBxB"}
|
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
import { folderPathError } from './asset-naming.js';
|
|
2
|
+
import { isRecord } from './component-vocabulary.js';
|
|
3
|
+
/** The wire protocol an editor page built by this release speaks; the editor UI path is /host/v<this>/. */
|
|
4
|
+
export const EDITOR_HOST_PROTOCOL = 1;
|
|
5
|
+
/** Protocols the current editor UI accepts. */
|
|
6
|
+
export const EDITOR_HOST_PROTOCOLS = { min: 1, max: 1 };
|
|
7
|
+
/**
|
|
8
|
+
* The draft-preview protocol a preview server built by this release speaks. Protocol 1 keeps the pass out of the
|
|
9
|
+
* page; protocol 2 opens a preview with a single-use code the server trades for the pass, so no pass travels in a
|
|
10
|
+
* link. conloca.json `preview.protocol` and the exit route's `conloca-preview-protocol` header carry it.
|
|
11
|
+
*/
|
|
12
|
+
export const PREVIEW_PROTOCOL = 2;
|
|
13
|
+
const PREVIEW_MODES = ['d2', 'd3', 'd4', 'off'];
|
|
14
|
+
function isPreviewMode(value) {
|
|
15
|
+
return PREVIEW_MODES.some((mode) => mode === value);
|
|
16
|
+
}
|
|
17
|
+
/** A branch name as one path segment and cookie-name suffix: its UTF-8 bytes as unpadded base64url, one slug per name. */
|
|
18
|
+
export function previewBranchSlug(branch) {
|
|
19
|
+
let binary = '';
|
|
20
|
+
for (const byte of new TextEncoder().encode(branch))
|
|
21
|
+
binary += String.fromCharCode(byte);
|
|
22
|
+
return btoa(binary).replaceAll('+', '-').replaceAll('/', '_').replace(/=+$/u, '');
|
|
23
|
+
}
|
|
24
|
+
/** The branch a slug names, or null unless it is the slug of a valid branch name (at most 765 UTF-8 bytes, 1020 characters; 1360 bounds it with room). */
|
|
25
|
+
export function branchOfPreviewSlug(slug) {
|
|
26
|
+
if (!/^[A-Za-z0-9_-]{1,1360}$/u.test(slug))
|
|
27
|
+
return null;
|
|
28
|
+
let bytes;
|
|
29
|
+
try {
|
|
30
|
+
bytes = Uint8Array.from(atob(slug.replaceAll('-', '+').replaceAll('_', '/')), (char) => char.charCodeAt(0));
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
let branch;
|
|
36
|
+
try {
|
|
37
|
+
branch = new TextDecoder('utf-8', { fatal: true }).decode(bytes);
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
return isValidBranchName(branch) && previewBranchSlug(branch) === slug ? branch : null;
|
|
43
|
+
}
|
|
44
|
+
/** Whether a branch's slug leaves room in a 1024-byte cookie `Path` (`<base>_conloca/preview/<slug>`). */
|
|
45
|
+
export function previewSlugFits(branch) {
|
|
46
|
+
return previewBranchSlug(branch).length <= 900;
|
|
47
|
+
}
|
|
48
|
+
/** conloca.json `preview`; `undefined` when absent or malformed, so a bad optional field never makes the page invalid. */
|
|
49
|
+
export function previewSignalOf(info) {
|
|
50
|
+
const value = Reflect.get(info, 'preview');
|
|
51
|
+
if (!isRecord(value))
|
|
52
|
+
return undefined;
|
|
53
|
+
const { mode, protocol } = value;
|
|
54
|
+
return isPreviewMode(mode) && typeof protocol === 'number' && Number.isSafeInteger(protocol)
|
|
55
|
+
? { mode, protocol }
|
|
56
|
+
: undefined;
|
|
57
|
+
}
|
|
58
|
+
export const DEFAULT_EDITOR_ENDPOINT = 'https://app.conloca.com';
|
|
59
|
+
/** Where the editor page is served, below the site's base. */
|
|
60
|
+
export const EDITOR_PAGE_PATH = '/_conloca/editor/';
|
|
61
|
+
/** The deployable-site id grammar (moved here from cloud-astro's site-id.ts; the census imports it too). */
|
|
62
|
+
export const SITE_ID_RE = /^[a-z0-9][a-z0-9-]{0,63}$/;
|
|
63
|
+
/** The parsed http(s) URL when its host is `app.` plus at least two non-empty labels, else null. */
|
|
64
|
+
function appUrl(url) {
|
|
65
|
+
let parsed;
|
|
66
|
+
try {
|
|
67
|
+
parsed = new URL(url);
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:')
|
|
73
|
+
return null;
|
|
74
|
+
const labels = parsed.hostname.split('.');
|
|
75
|
+
return labels.length >= 3 && labels[0] === 'app' && labels.every((label) => label !== '') ? parsed : null;
|
|
76
|
+
}
|
|
77
|
+
/** The editor UI origin for an endpoint, or null unless its host is `app.` plus at least two labels. */
|
|
78
|
+
export function editorUiOrigin(endpoint) {
|
|
79
|
+
return appUrl(endpoint ?? DEFAULT_EDITOR_ENDPOINT)?.origin ?? null;
|
|
80
|
+
}
|
|
81
|
+
/** The parent root for a URL on the editor UI origin (`app.conloca.com` → `conloca.com`), or null under the same rule. */
|
|
82
|
+
export function parentRoot(url) {
|
|
83
|
+
return appUrl(url)?.hostname.slice('app.'.length) ?? null;
|
|
84
|
+
}
|
|
85
|
+
/** Editor UI file per bare specifier the page's bundle keeps external, under `<origin>/host/v<protocol>/`. */
|
|
86
|
+
export const EDITOR_UI_MODULE_FILES = {
|
|
87
|
+
react: 'react.js',
|
|
88
|
+
'react-dom': 'react-dom.js',
|
|
89
|
+
'react-dom/client': 'react-dom-client.js',
|
|
90
|
+
'react/jsx-runtime': 'jsx-runtime.js',
|
|
91
|
+
'react/jsx-dev-runtime': 'jsx-dev-runtime.js',
|
|
92
|
+
'@puckeditor/core': 'puck.js',
|
|
93
|
+
};
|
|
94
|
+
/** The file beside conloca.json holding each `dataSchemas` collection's JSON schema, as `{ collections }`. */
|
|
95
|
+
export const DATA_SCHEMAS_FILE = 'data-schemas.json';
|
|
96
|
+
export const EDITOR_PAGE_INFO_FORMATS = {
|
|
97
|
+
commit: /^[0-9a-f]{40}$/,
|
|
98
|
+
builtWith: /^@conloca\/cloud-astro@\d+\.\d+\.\d+(-[0-9A-Za-z.-]+)?$/,
|
|
99
|
+
repo: /^[A-Za-z0-9-]{1,39}\/[A-Za-z0-9._-]{1,100}$/,
|
|
100
|
+
siteId: SITE_ID_RE,
|
|
101
|
+
sha256: /^[0-9a-f]{64}$/,
|
|
102
|
+
manifestPath: /^component-manifest\.[0-9a-f]{16}\.json$/,
|
|
103
|
+
};
|
|
104
|
+
// One DNS label: the Pages project names the first label of its `pages.dev` address.
|
|
105
|
+
const PAGES_PROJECT_RE = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/;
|
|
106
|
+
/** conloca.json `branchDeploys`; `undefined` when absent or malformed, so a bad optional field never makes the page invalid. */
|
|
107
|
+
export function branchDeploysOf(info) {
|
|
108
|
+
const value = Reflect.get(info, 'branchDeploys');
|
|
109
|
+
if (!isRecord(value) || value.host !== 'cloudflare-pages')
|
|
110
|
+
return undefined;
|
|
111
|
+
const { project } = value;
|
|
112
|
+
return typeof project === 'string' && PAGES_PROJECT_RE.test(project)
|
|
113
|
+
? { host: 'cloudflare-pages', project }
|
|
114
|
+
: undefined;
|
|
115
|
+
}
|
|
116
|
+
export const CONTENT_PATHS_MAX = 16;
|
|
117
|
+
/** '' (the repository root) or a relative path of plain segments, at most 255 characters. */
|
|
118
|
+
function isContentPath(path) {
|
|
119
|
+
if (path === '')
|
|
120
|
+
return true;
|
|
121
|
+
if (typeof path !== 'string' || path.length > 255 || path.includes('\\'))
|
|
122
|
+
return false;
|
|
123
|
+
return path.split('/').every((segment) => segment !== '' && segment !== '.' && segment !== '..');
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* conloca.json `contentPaths`: repository paths the site's content lives under, duplicates removed;
|
|
127
|
+
* `undefined` when absent or malformed, so a bad optional field never makes the page invalid.
|
|
128
|
+
*/
|
|
129
|
+
export function contentPathsOf(info) {
|
|
130
|
+
const value = Reflect.get(info, 'contentPaths');
|
|
131
|
+
if (!Array.isArray(value) || value.length === 0 || value.length > CONTENT_PATHS_MAX)
|
|
132
|
+
return undefined;
|
|
133
|
+
if (!value.every(isContentPath))
|
|
134
|
+
return undefined;
|
|
135
|
+
return [...new Set(value)];
|
|
136
|
+
}
|
|
137
|
+
/** The most bytes of conloca.json the workspace editor reads; a build never writes more. */
|
|
138
|
+
export const CONLOCA_JSON_MAX_BYTES = 16 * 1024;
|
|
139
|
+
/** A page route: `/` then at most 200 unreserved URL characters or `/`, so no route carries prompt or shell syntax. */
|
|
140
|
+
export const EDITOR_ROUTE_RE = /^\/[A-Za-z0-9._~\-/]{0,200}$/;
|
|
141
|
+
/** The most routes a conloca.json lists. */
|
|
142
|
+
export const ROUTES_MAX = 500;
|
|
143
|
+
/** Whether `route` is a string matching `EDITOR_ROUTE_RE`. */
|
|
144
|
+
export function isEditorRoute(route) {
|
|
145
|
+
return typeof route === 'string' && EDITOR_ROUTE_RE.test(route);
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* conloca.json `routes`: the page routes a build lists, those outside `EDITOR_ROUTE_RE` and duplicates dropped,
|
|
149
|
+
* at most `ROUTES_MAX`; `undefined` when absent or not a list, so a bad optional field never makes the page invalid.
|
|
150
|
+
*/
|
|
151
|
+
export function routesOf(info) {
|
|
152
|
+
const value = Reflect.get(info, 'routes');
|
|
153
|
+
if (!Array.isArray(value))
|
|
154
|
+
return undefined;
|
|
155
|
+
return [...new Set(value.filter(isEditorRoute))].slice(0, ROUTES_MAX);
|
|
156
|
+
}
|
|
157
|
+
/** A link base: `''`, or `/`-led segments of URL-safe characters with no `.` or `..` segment and no trailing `/`. */
|
|
158
|
+
const REF_BASE_RE = /^(\/(?!\.\.?(?:\/|$))[A-Za-z0-9._~-]+)*$/;
|
|
159
|
+
/**
|
|
160
|
+
* conloca.json `media`; `undefined` when absent or malformed (the repository root, a folder `folderPathError`
|
|
161
|
+
* refuses, or a link base {@link REF_BASE_RE} refuses), so a bad optional field never makes the page invalid. The
|
|
162
|
+
* link base is written into saved pages, so it may hold nothing a page's JSON, front matter or MDX would read.
|
|
163
|
+
*/
|
|
164
|
+
export function mediaOf(info) {
|
|
165
|
+
const value = Reflect.get(info, 'media');
|
|
166
|
+
if (!isRecord(value))
|
|
167
|
+
return undefined;
|
|
168
|
+
const { path, refBase } = value;
|
|
169
|
+
if (typeof path !== 'string' || path === '' || path.length > 255 || folderPathError(path) !== null)
|
|
170
|
+
return undefined;
|
|
171
|
+
if (typeof refBase !== 'string' || refBase.length > 255 || !REF_BASE_RE.test(refBase))
|
|
172
|
+
return undefined;
|
|
173
|
+
return { path, refBase };
|
|
174
|
+
}
|
|
175
|
+
// `~^:?*[\`, `..`, `@{` and `//` anywhere (`git check-ref-format`); space and control characters are checked apart.
|
|
176
|
+
const BRANCH_FORBIDDEN_RE = /[~^:?*[\\]|\.\.|@\{|\/\//;
|
|
177
|
+
/** Git's ref-name rules for one branch name, at most 255 characters. */
|
|
178
|
+
export function isValidBranchName(name) {
|
|
179
|
+
if (name === '' || name.length > 255 || name === '@' || BRANCH_FORBIDDEN_RE.test(name))
|
|
180
|
+
return false;
|
|
181
|
+
for (let index = 0; index < name.length; index++) {
|
|
182
|
+
const code = name.charCodeAt(index);
|
|
183
|
+
if (code <= 0x20 || code === 0x7f)
|
|
184
|
+
return false;
|
|
185
|
+
}
|
|
186
|
+
if (name.startsWith('-') || name.startsWith('/') || name.endsWith('/') || name.endsWith('.'))
|
|
187
|
+
return false;
|
|
188
|
+
return name.split('/').every((segment) => !segment.startsWith('.') && !segment.endsWith('.lock'));
|
|
189
|
+
}
|
|
190
|
+
/** Shape and field formats of a parsed conloca.json; null allowed where the type allows it. */
|
|
191
|
+
export function isEditorPageInfo(value) {
|
|
192
|
+
if (!isRecord(value))
|
|
193
|
+
return false;
|
|
194
|
+
const { protocol, repo, siteId, commit, branch, builtWith, componentManifest } = value;
|
|
195
|
+
const formats = EDITOR_PAGE_INFO_FORMATS;
|
|
196
|
+
return (typeof protocol === 'number' &&
|
|
197
|
+
Number.isSafeInteger(protocol) &&
|
|
198
|
+
(repo === null || (typeof repo === 'string' && formats.repo.test(repo))) &&
|
|
199
|
+
typeof siteId === 'string' &&
|
|
200
|
+
formats.siteId.test(siteId) &&
|
|
201
|
+
(commit === null || (typeof commit === 'string' && formats.commit.test(commit))) &&
|
|
202
|
+
(branch === null || (typeof branch === 'string' && isValidBranchName(branch))) &&
|
|
203
|
+
typeof builtWith === 'string' &&
|
|
204
|
+
formats.builtWith.test(builtWith) &&
|
|
205
|
+
(componentManifest === null ||
|
|
206
|
+
(isRecord(componentManifest) &&
|
|
207
|
+
typeof componentManifest.path === 'string' &&
|
|
208
|
+
formats.manifestPath.test(componentManifest.path) &&
|
|
209
|
+
typeof componentManifest.sha256 === 'string' &&
|
|
210
|
+
formats.sha256.test(componentManifest.sha256))));
|
|
211
|
+
}
|
|
212
|
+
/** True when `location` is an absolute URL on vercel.com or a subdomain (Vercel's sign-in redirect). */
|
|
213
|
+
export function isVercelSignIn(location) {
|
|
214
|
+
if (location === null)
|
|
215
|
+
return false;
|
|
216
|
+
let host;
|
|
217
|
+
try {
|
|
218
|
+
host = new URL(location).hostname;
|
|
219
|
+
}
|
|
220
|
+
catch {
|
|
221
|
+
return false;
|
|
222
|
+
}
|
|
223
|
+
return host === 'vercel.com' || host.endsWith('.vercel.com');
|
|
224
|
+
}
|
|
225
|
+
/** Any Vercel signal on an answer: an `x-vercel-*` header or a sign-in redirect. Feeds the classifier's `vercel`. */
|
|
226
|
+
export function isFromVercel(headers) {
|
|
227
|
+
for (const [name] of headers)
|
|
228
|
+
if (name.startsWith('x-vercel-'))
|
|
229
|
+
return true;
|
|
230
|
+
return isVercelSignIn(headers.get('location'));
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* One conloca.json answer → status; body is null when not read (non-200 or over the cap).
|
|
234
|
+
* `vercel` (any Vercel signal) only picks the caller's message: an ordinary redirect on Vercel stays `invalid`.
|
|
235
|
+
*/
|
|
236
|
+
export function classifyEditorHostResponse(response, expected) {
|
|
237
|
+
const { status, contentType, body } = response;
|
|
238
|
+
if (status >= 500 || status === 429)
|
|
239
|
+
return { status: 'unreachable' };
|
|
240
|
+
if (status === 401 || status === 403)
|
|
241
|
+
return { status: 'protected' };
|
|
242
|
+
if (status === 404)
|
|
243
|
+
return { status: 'not-found' };
|
|
244
|
+
if (status >= 300 && status < 400)
|
|
245
|
+
return { status: isVercelSignIn(response.location) ? 'protected' : 'invalid' };
|
|
246
|
+
if (status !== 200)
|
|
247
|
+
return { status: 'invalid' };
|
|
248
|
+
// A host serving its HTML fallback for unknown paths.
|
|
249
|
+
if (contentType?.split(';')[0]?.trim().toLowerCase() === 'text/html')
|
|
250
|
+
return { status: 'not-found' };
|
|
251
|
+
if (body === null)
|
|
252
|
+
return { status: 'invalid' };
|
|
253
|
+
if (body.trimStart().startsWith('<'))
|
|
254
|
+
return { status: 'not-found' };
|
|
255
|
+
let parsed;
|
|
256
|
+
try {
|
|
257
|
+
parsed = JSON.parse(body);
|
|
258
|
+
}
|
|
259
|
+
catch {
|
|
260
|
+
return { status: 'invalid' };
|
|
261
|
+
}
|
|
262
|
+
if (!isEditorPageInfo(parsed))
|
|
263
|
+
return { status: 'invalid' };
|
|
264
|
+
const info = parsed;
|
|
265
|
+
if (info.protocol < expected.protocols.min || info.protocol > expected.protocols.max) {
|
|
266
|
+
return { status: 'unsupported-protocol', info };
|
|
267
|
+
}
|
|
268
|
+
if (info.repo === null)
|
|
269
|
+
return { status: 'wrong-repo', reason: 'repo-missing', info };
|
|
270
|
+
if (info.repo.toLowerCase() !== expected.repoUri.toLowerCase())
|
|
271
|
+
return { status: 'wrong-repo', info };
|
|
272
|
+
if (info.siteId !== expected.siteId)
|
|
273
|
+
return { status: 'wrong-site', info };
|
|
274
|
+
return { status: 'ready', info };
|
|
275
|
+
}
|
|
276
|
+
/** A CSP source expression compared as a token: case-insensitive, without a trailing `/`. */
|
|
277
|
+
function sourceToken(source) {
|
|
278
|
+
return source.toLowerCase().replace(/\/$/, '');
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Frame headers of the page → whether a workspace parent may frame it. `allowedAncestors` are the source expressions
|
|
282
|
+
* that admit the workspace; `*` and `https:` always do. A `frame-ancestors` directive overrides X-Frame-Options.
|
|
283
|
+
* shortcut: sources match as exact tokens, so a broader host wildcard (`https://*.com`) reads as blocked; parse
|
|
284
|
+
* host patterns if a real site needs one.
|
|
285
|
+
*/
|
|
286
|
+
export function classifyFrameHeaders(headers, allowedAncestors) {
|
|
287
|
+
const admitting = new Set(['*', 'https:', ...allowedAncestors.map(sourceToken)]);
|
|
288
|
+
// A combined header joins policies with commas; every policy is enforced on its own, by its first frame-ancestors.
|
|
289
|
+
const ancestorLists = (headers.csp ?? '').split(',').flatMap((policy) => {
|
|
290
|
+
const directive = policy
|
|
291
|
+
.split(';')
|
|
292
|
+
.map((part) => part.trim().split(/\s+/))
|
|
293
|
+
.find(([name]) => name?.toLowerCase() === 'frame-ancestors');
|
|
294
|
+
return directive ? [directive.slice(1)] : [];
|
|
295
|
+
});
|
|
296
|
+
if (ancestorLists.length > 0) {
|
|
297
|
+
return ancestorLists.every((sources) => sources.some((source) => admitting.has(sourceToken(source))))
|
|
298
|
+
? 'ok'
|
|
299
|
+
: 'frame-blocked';
|
|
300
|
+
}
|
|
301
|
+
const xfo = new Set((headers.xFrameOptions ?? '').split(',').map((value) => value.trim().toLowerCase()));
|
|
302
|
+
return xfo.has('deny') || xfo.has('sameorigin') ? 'frame-blocked' : 'ok';
|
|
303
|
+
}
|
|
304
|
+
//# sourceMappingURL=editor-host.js.map
|