astronaut-cms 0.0.1 → 1.1.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.
Files changed (120) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +84 -3
  3. package/dist/admin/THIRD_PARTY_LICENSES.md +7646 -0
  4. package/dist/admin/assets/assistant-DTlSNidc.js +235 -0
  5. package/dist/admin/assets/badge-BfN73-be.js +1 -0
  6. package/dist/admin/assets/changes-h1lmD7AA.js +1 -0
  7. package/dist/admin/assets/client-B4PWCmC4.js +5 -0
  8. package/dist/admin/assets/clsx-DB0hHKMi.js +1 -0
  9. package/dist/admin/assets/collapsible-item-zlnNAUdM.js +1 -0
  10. package/dist/admin/assets/collapsible-mcJ6G3X4.js +1 -0
  11. package/dist/admin/assets/collections._collection-D-rC9E9v.js +1 -0
  12. package/dist/admin/assets/collections._collection._entry-UD8hLmC1.js +52 -0
  13. package/dist/admin/assets/collections._collection.index-Cgc93hCD.js +1 -0
  14. package/dist/admin/assets/component-lookup-8lVQh8pl.js +4 -0
  15. package/dist/admin/assets/config-Pm_BHLNT.js +1 -0
  16. package/dist/admin/assets/copy-DxuErr3x.js +1 -0
  17. package/dist/admin/assets/css-BGIxQoYs.js +1 -0
  18. package/dist/admin/assets/css-DgaLhXQH.js +1 -0
  19. package/dist/admin/assets/diff-woXpYk--.js +1 -0
  20. package/dist/admin/assets/dist-DVv3ALC7.js +1 -0
  21. package/dist/admin/assets/dist-Dpyc1riS.js +1 -0
  22. package/dist/admin/assets/docx-BctAmX91.js +56 -0
  23. package/dist/admin/assets/editor-BauN0yXd.js +2 -0
  24. package/dist/admin/assets/empty-DAOUBpWb.js +1 -0
  25. package/dist/admin/assets/entry-link-DhcL6M5c.js +158 -0
  26. package/dist/admin/assets/error-banner-CNWZU5u_.js +161 -0
  27. package/dist/admin/assets/errors-DkJ5E_ak.js +1 -0
  28. package/dist/admin/assets/field-CbbZZGxO.js +41 -0
  29. package/dist/admin/assets/field-schema-CacrjSYw.js +1 -0
  30. package/dist/admin/assets/file-text-Ciz5Mr4S.js +1 -0
  31. package/dist/admin/assets/github-dark-C-LZuMrd.js +1 -0
  32. package/dist/admin/assets/github-light-EUqPIrTm.js +1 -0
  33. package/dist/admin/assets/highlighted-body-JLMTFACH-D1bycIV3.js +1 -0
  34. package/dist/admin/assets/html-CvFb5cGI.js +1 -0
  35. package/dist/admin/assets/javascript-BzbQS41l.js +1 -0
  36. package/dist/admin/assets/javascript-CpIGwZ_Y.js +1 -0
  37. package/dist/admin/assets/json-qhed-kSA.js +1 -0
  38. package/dist/admin/assets/jsx-Bz0zcwM4.js +1 -0
  39. package/dist/admin/assets/lib-CC_S4yjQ.js +21 -0
  40. package/dist/admin/assets/library-Da82FNwp.js +1 -0
  41. package/dist/admin/assets/list-skeleton-BXLP4Fak.js +1 -0
  42. package/dist/admin/assets/markdown-BYOwaDjH.js +1 -0
  43. package/dist/admin/assets/matchContext-BjW1F-Cq.js +2 -0
  44. package/dist/admin/assets/media-browser-DeKpWCUD.js +1 -0
  45. package/dist/admin/assets/media._library-DGnXJc0I.js +1 -0
  46. package/dist/admin/assets/mermaid-WFAXDIZX-CqFnahFh.js +1 -0
  47. package/dist/admin/assets/page-header-C2Uwa_yv.js +1 -0
  48. package/dist/admin/assets/pdf-BSEX-sd8.js +106 -0
  49. package/dist/admin/assets/python-gzcpVVnB.js +1 -0
  50. package/dist/admin/assets/react-CXnqG51l.js +1 -0
  51. package/dist/admin/assets/rolldown-runtime-BWaJ3C7D.js +1 -0
  52. package/dist/admin/assets/routes-Bx9rPcHA.js +1 -0
  53. package/dist/admin/assets/routes-D7tEdYGV.js +1 -0
  54. package/dist/admin/assets/save-actions-DrVgh3KH.js +32 -0
  55. package/dist/admin/assets/select-CMV39q80.js +1 -0
  56. package/dist/admin/assets/separator-C9bNKNSU.js +3 -0
  57. package/dist/admin/assets/shell-DBEiq06l.js +1 -0
  58. package/dist/admin/assets/shellscript-CLZ0U2zV.js +1 -0
  59. package/dist/admin/assets/skeleton-DTwTUSqm.js +1 -0
  60. package/dist/admin/assets/sql-CEbI0hMM.js +1 -0
  61. package/dist/admin/assets/syntax-DDPd1mQn.js +8 -0
  62. package/dist/admin/assets/toggle-B6ASf-kL.js +1 -0
  63. package/dist/admin/assets/toml-BPTmHmyx.js +1 -0
  64. package/dist/admin/assets/tsx-udAQXfEw.js +1 -0
  65. package/dist/admin/assets/typescript-bsJCZSQ-.js +1 -0
  66. package/dist/admin/assets/ui.module.css-BdAmwQeM.js +56 -0
  67. package/dist/admin/assets/use-entries-CrNqaMfa.js +1 -0
  68. package/dist/admin/assets/useSelector-Cs39W18m.js +1 -0
  69. package/dist/admin/assets/yaml-rwi0_p6S.js +1 -0
  70. package/dist/admin/assets/zwitch-Wwuax-dJ.js +1 -0
  71. package/dist/admin/bootstrap.d.ts +1 -0
  72. package/dist/admin/bootstrap.js +1 -0
  73. package/dist/admin/editor.d.ts +1065 -0
  74. package/dist/admin/editor.js +1 -0
  75. package/dist/server/THIRD_PARTY_LICENSES.md +49 -0
  76. package/dist/server/assets.d.ts +30 -0
  77. package/dist/server/assets.js +30 -0
  78. package/dist/server/chunks/anchors-DuZ1fokt.js +86 -0
  79. package/dist/server/chunks/auth-DJP9ryVd.js +44 -0
  80. package/dist/server/chunks/cms-markers-CUqrOnfA.js +78 -0
  81. package/dist/server/chunks/component-lookup-DAFg_Qg8.js +128 -0
  82. package/dist/server/chunks/config-BsOYly9a.d.ts +1210 -0
  83. package/dist/server/chunks/digest-tkKu_Wj5.js +753 -0
  84. package/dist/server/chunks/entry-checks-3SxhoHwH.js +608 -0
  85. package/dist/server/chunks/field-schema-CfdN75jT.js +48 -0
  86. package/dist/server/chunks/http-BnsNh57m.d.ts +35 -0
  87. package/dist/server/chunks/i18n-BPmx7ESy.d.ts +15 -0
  88. package/dist/server/chunks/index-CYbkNvu5.d.ts +22 -0
  89. package/dist/server/chunks/media-BhqUVVYY.js +223 -0
  90. package/dist/server/chunks/paths-CEW9fvg8.js +17 -0
  91. package/dist/server/chunks/paths-Dztx2eUw.js +13 -0
  92. package/dist/server/chunks/types-DkkewFTT.js +418 -0
  93. package/dist/server/chunks/types-Dkx4Xovf.d.ts +359 -0
  94. package/dist/server/chunks/types-Jew_-Qpp.d.ts +273 -0
  95. package/dist/server/chunks/user-config-CqNK-Ebs.js +292 -0
  96. package/dist/server/chunks/xml-D8qPILJU.js +81 -0
  97. package/dist/server/config.d.ts +3 -0
  98. package/dist/server/config.js +22 -0
  99. package/dist/server/content.d.ts +58 -0
  100. package/dist/server/content.js +83 -0
  101. package/dist/server/endpoint.d.ts +16 -0
  102. package/dist/server/endpoint.js +2726 -0
  103. package/dist/server/integration.d.ts +7 -0
  104. package/dist/server/integration.js +1187 -0
  105. package/dist/server/internal.d.ts +100 -0
  106. package/dist/server/internal.js +30 -0
  107. package/dist/server/server-local.d.ts +453 -0
  108. package/dist/server/server-local.js +336 -0
  109. package/dist/styles/THIRD_PARTY_LICENSES.md +193 -0
  110. package/dist/styles/assets/geist-cyrillic-ext-wght-normal-DjL33-gN.woff2 +0 -0
  111. package/dist/styles/assets/geist-cyrillic-wght-normal-BEAKL7Jp.woff2 +0 -0
  112. package/dist/styles/assets/geist-latin-ext-wght-normal-DC-KSUi6.woff2 +0 -0
  113. package/dist/styles/assets/geist-latin-wght-normal-BgDaEnEv.woff2 +0 -0
  114. package/dist/styles/assets/geist-vietnamese-wght-normal-6IgcOCM7.woff2 +0 -0
  115. package/dist/styles/styles.css +3 -0
  116. package/package.json +151 -5
  117. package/src/astro/Image.astro +28 -0
  118. package/src/astro/Video.astro +44 -0
  119. package/src/astro/admin.astro +137 -0
  120. package/src/astro/licenses.ts +5 -0
@@ -0,0 +1 @@
1
+ export{t as NestedLexicalEditor,n as useLexicalNodeRemove,r as useMdastNodeUpdater}from"./assets/editor-BauN0yXd.js";
@@ -0,0 +1,49 @@
1
+ # Licenses
2
+
3
+ ## @types/mdast - 4.0.4 (MIT)
4
+
5
+ MIT License
6
+
7
+ Copyright (c) Microsoft Corporation.
8
+
9
+ Permission is hereby granted, free of charge, to any person obtaining a copy
10
+ of this software and associated documentation files (the "Software"), to deal
11
+ in the Software without restriction, including without limitation the rights
12
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
+ copies of the Software, and to permit persons to whom the Software is
14
+ furnished to do so, subject to the following conditions:
15
+
16
+ The above copyright notice and this permission notice shall be included in all
17
+ copies or substantial portions of the Software.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25
+ SOFTWARE
26
+
27
+ ## @types/unist - 3.0.3 (MIT)
28
+
29
+ MIT License
30
+
31
+ Copyright (c) Microsoft Corporation.
32
+
33
+ Permission is hereby granted, free of charge, to any person obtaining a copy
34
+ of this software and associated documentation files (the "Software"), to deal
35
+ in the Software without restriction, including without limitation the rights
36
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
37
+ copies of the Software, and to permit persons to whom the Software is
38
+ furnished to do so, subject to the following conditions:
39
+
40
+ The above copyright notice and this permission notice shall be included in all
41
+ copies or substantial portions of the Software.
42
+
43
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
44
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
45
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
46
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
47
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
48
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
49
+ SOFTWARE
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Host-facing asset resolver.
3
+ *
4
+ * Resolves CMS asset path strings to optimized assets via lazy loader maps the CMS
5
+ * Vite plugin generates per project, a glob over each library directory, so any
6
+ * file resolves, in dev a freshly uploaded one without a restart. Paths are
7
+ * root-absolute (e.g. "/src/assets/hero.png"), relative paths (e.g. "./hero.png")
8
+ * resolve against a `base` argument (the referencing content file, such as `entry.filePath`).
9
+ *
10
+ * An object-store reference is its public URL already, so there is no map and
11
+ * nothing to bundle: `resolveImage` hands the URL back rather than
12
+ * `ImageMetadata`, which is exactly what `astro:assets` `<Image>` takes for a
13
+ * remote image (`astronaut-cms/Image.astro` passes it on with `inferSize`).
14
+ *
15
+ * What needs resolving here is what astro cannot resolve for you: the `image()`
16
+ * and `file()` props of MDX components, and `file()` collection fields. A
17
+ * collection's `image()` fields are not among them. Astro imports a repository
18
+ * one into `entry.data` itself, and leaves an object-store URL as it is, so
19
+ * `entry.data.cover` is either `ImageMetadata` or a URL that `Image.astro` takes.
20
+ *
21
+ * Resolution happens at render time and never touches the markdown processor, so
22
+ * it works under both the default `satteri()` pipeline and `unified()`.
23
+ *
24
+ * Use {@link resolveImage} in `.astro` files (or the ready-made
25
+ * `astronaut-cms/Image.astro` wrapper), and pass the resolved value to
26
+ * `astro:assets` `<Image>`. React islands should receive an already-resolved
27
+ * `src` from an `.astro` wrapper rather than calling these directly.
28
+ */
29
+ import { i as resolveImage, n as ResolvedImage, r as resolveFile, t as MediaRegistry } from "./chunks/index-CYbkNvu5.js";
30
+ export { MediaRegistry, ResolvedImage, resolveFile, resolveImage };
@@ -0,0 +1,30 @@
1
+ import { m as mediaPath, x as assetKey } from "./chunks/media-BhqUVVYY.js";
2
+ import { join } from "pathe";
3
+ import { files, images, media } from "virtual:astronaut-cms/assets";
4
+ // src/assets/index.ts
5
+ /**
6
+ * The one place the libraries are told apart, so a new one is added here rather
7
+ * than in every exported resolver. A repository asset is loaded through the map,
8
+ * and an object-store URL passes through, or, for a dev run whose store is the
9
+ * working tree, becomes the file there, loaded through the map like any other.
10
+ */
11
+ async function resolve$1(map, kind, ref, base) {
12
+ const location = mediaPath(ref, media, base);
13
+ if (location?.library !== "s3") return load(map, kind, assetKey(ref, base));
14
+ const directory = media.s3?.directory;
15
+ return directory == null ? ref : load(map, kind, join("/", directory, location.path));
16
+ }
17
+ function load(map, kind, key) {
18
+ const loader = map[key];
19
+ if (!loader) throw new Error(`CMS ${kind} not found: ${key}`);
20
+ return loader();
21
+ }
22
+ /**
23
+ * Resolve an asset reference to optimized image metadata, or, for an
24
+ * object-store file, to the URL the image is served under. Absolute paths need
25
+ * no `base`, relative paths resolve against `base` (e.g. `entry.filePath`).
26
+ */
27
+ var resolveImage = async (path, base) => await resolve$1(images, "image", path, base);
28
+ /** Resolve an asset path to a file URL. See {@link resolveImage} for base semantics. */
29
+ var resolveFile = async (path, base) => resolve$1(files, "file", path, base);
30
+ export { resolveFile, resolveImage };
@@ -0,0 +1,86 @@
1
+ import { d as diagnostic } from "./field-schema-CfdN75jT.js";
2
+ // src/shared/links.ts
3
+ var LINK_PROTOCOLS = [
4
+ "http:",
5
+ "https:",
6
+ "mailto:",
7
+ "tel:"
8
+ ];
9
+ var NAVIGABLE_PROTOCOLS = /* @__PURE__ */ new Set([
10
+ ...LINK_PROTOCOLS,
11
+ "javascript:",
12
+ "vbscript:",
13
+ "data:",
14
+ "blob:",
15
+ "file:",
16
+ "ftp:",
17
+ "ws:",
18
+ "wss:"
19
+ ]);
20
+ var BASE = new URL("https://relative.invalid/");
21
+ var LINK_KINDS = "relative, http, https, mailto or tel URL";
22
+ var LINK_MESSAGE = `Expected a ${LINK_KINDS}.`;
23
+ var LINK_DESCRIPTION = `A ${LINK_KINDS}.`;
24
+ var PLAIN_TEXT_MESSAGE = "Plain text may not be a link. Declare the field with link() to hold a URL.";
25
+ var resolve = (value) => URL.parse(value, BASE);
26
+ /** Whether a value declared as a link points somewhere a visitor may follow. */
27
+ function isAllowedLink(value) {
28
+ const url = resolve(value);
29
+ return url !== null && LINK_PROTOCOLS.includes(url.protocol);
30
+ }
31
+ /** Limits a string schema to the links a visitor may follow. */
32
+ function allowedLinks(schema) {
33
+ return schema.refine(isAllowedLink, LINK_MESSAGE);
34
+ }
35
+ /**
36
+ * Whether plain text would act as a link if rendered as an `href`: it resolves
37
+ * off the page, to a scheme a browser acts on or to another host. Prose that
38
+ * merely contains a colon ("ISBN:978", "Update: new pricing") does not.
39
+ */
40
+ function isLinkLike(value) {
41
+ if (!/:|[\\/]{2}/.test(value.replace(/[\t\n\r]/g, ""))) return false;
42
+ const url = resolve(value);
43
+ return url !== null && !url.href.startsWith(BASE.href) && NAVIGABLE_PROTOCOLS.has(url.protocol);
44
+ }
45
+ /** Whether any string inside a value of unknown shape acts as a link. */
46
+ function containsLink(value) {
47
+ if (typeof value === "string") return isLinkLike(value);
48
+ if (Array.isArray(value)) return value.some(containsLink);
49
+ if (value && typeof value === "object") return Object.values(value).some(containsLink);
50
+ return false;
51
+ }
52
+ // src/shared/anchors.ts
53
+ var ANCHOR_MESSAGE = "Expected an anchor id without # or spaces, such as contact.";
54
+ var ANCHOR_DESCRIPTION = "An element id, which a link in the same entry targets as #id.";
55
+ /** Whether a value can be an element id that a link reaches as `#value`. */
56
+ var isAnchor = (value) => /^[^\s#]+$/.test(value);
57
+ /** Limits a string schema to anchor ids. */
58
+ function anchorIds(schema) {
59
+ return schema.refine(isAnchor, ANCHOR_MESSAGE);
60
+ }
61
+ var IMPLICIT_FRAGMENTS = /* @__PURE__ */ new Set(["", "top"]);
62
+ function fragment(link) {
63
+ if (!link.startsWith("#")) return null;
64
+ try {
65
+ return decodeURIComponent(link.slice(1));
66
+ } catch {
67
+ return link.slice(1);
68
+ }
69
+ }
70
+ /**
71
+ * Every link to `#id` among an entry's leaves that names none of its anchors,
72
+ * and every anchor defined twice, which leaves a link to it ambiguous.
73
+ */
74
+ function checkAnchors(leaves) {
75
+ const anchors = leaves.filter((leaf) => leaf.kind === "anchor");
76
+ const ids = new Set(anchors.map((anchor) => anchor.value));
77
+ const known = ids.size ? `The anchors of this entry are ${[...ids].map((id) => `#${id}`).join(", ")}.` : "This entry defines no anchors. A prop that renders an id has to be declared with anchor().";
78
+ const duplicates = anchors.filter((anchor, index) => anchors.findIndex((other) => other.value === anchor.value) !== index).map((anchor) => diagnostic(`defines the anchor "${anchor.value}" again, which has to be unique on the page.`, anchor.path));
79
+ const dead = leaves.flatMap((leaf) => {
80
+ const id = leaf.kind === "link" ? fragment(leaf.value) : null;
81
+ if (id === null || IMPLICIT_FRAGMENTS.has(id.toLowerCase()) || ids.has(id)) return [];
82
+ return diagnostic(`links to "#${id}", which no anchor of this entry defines. ${known}`, leaf.path);
83
+ });
84
+ return [...duplicates, ...dead];
85
+ }
86
+ export { LINK_MESSAGE as a, containsLink as c, LINK_DESCRIPTION as i, isAllowedLink as l, anchorIds as n, PLAIN_TEXT_MESSAGE as o, checkAnchors as r, allowedLinks as s, ANCHOR_DESCRIPTION as t, isLinkLike as u };
@@ -0,0 +1,44 @@
1
+ // src/shared/auth.ts
2
+ /**
3
+ * Who issued the session. `local` is `astro dev` against the working tree, which
4
+ * has no provider and therefore no sign-in at all.
5
+ */
6
+ var PROVIDERS = [
7
+ "github",
8
+ "gitlab",
9
+ "local"
10
+ ];
11
+ /** The element the shell renders and the admin mounts into, carrying the site's routing. */
12
+ var ADMIN_ROOT_ID = "astronaut-cms-root";
13
+ /** Root-relative prefix of everything the CMS serves. Astro prepends the site `base`. */
14
+ var CMS_BASE = "/_astronaut-cms";
15
+ /** Root-relative base of the CMS API. */
16
+ var API_BASE = `${CMS_BASE}/api`;
17
+ /** Injected-route pattern covering every CMS API path (see `server/endpoint.ts`). */
18
+ var API_PATTERN = `${API_BASE}/[...path]`;
19
+ var API_LOGIN = `${API_BASE}/login`;
20
+ var API_CALLBACK = `${API_BASE}/callback`;
21
+ /** Root-relative path of the notices of the packages the admin bundles. */
22
+ var LICENSES_PATH = `${CMS_BASE}/THIRD_PARTY_LICENSES.txt`;
23
+ /**
24
+ * Optional. The session cookie's key is derived from the OAuth client secret by
25
+ * default, which every deployment already holds, so nothing has to be generated
26
+ * or seeded. Set this to key sessions off something else instead, to expire
27
+ * them without touching the OAuth app, or to share one session across services.
28
+ */
29
+ var SESSION_SECRET_ENV = "ASTRONAUT_CMS_SESSION_SECRET";
30
+ /** The OAuth client secret of the configured GitHub App or GitLab application. */
31
+ var GITHUB_CLIENT_SECRET_ENV = "ASTRONAUT_CMS_GITHUB_CLIENT_SECRET";
32
+ var GITLAB_CLIENT_SECRET_ENV = "ASTRONAUT_CMS_GITLAB_CLIENT_SECRET";
33
+ /**
34
+ * Set by Cloudflare Access on every request it lets through. Its presence means
35
+ * the editor has already signed in to the identity provider in front of this
36
+ * site, which is why the admin starts the provider redirect itself instead of
37
+ * showing a sign-in button.
38
+ *
39
+ * Deliberately not verified: it is read as a hint about what to render, never as
40
+ * a permission. Forging it buys nothing, because the redirect it triggers still
41
+ * has to complete a real OAuth exchange.
42
+ */
43
+ var CF_ACCESS_HEADER = "cf-access-jwt-assertion";
44
+ export { API_PATTERN as a, GITLAB_CLIENT_SECRET_ENV as c, SESSION_SECRET_ENV as d, API_LOGIN as i, LICENSES_PATH as l, API_BASE as n, CF_ACCESS_HEADER as o, API_CALLBACK as r, GITHUB_CLIENT_SECRET_ENV as s, ADMIN_ROOT_ID as t, PROVIDERS as u };
@@ -0,0 +1,78 @@
1
+ import { a as CMS_LOCALIZED, i as CMS_LINK, n as CMS_FILE, o as CMS_REFERENCE, r as CMS_IMAGE, t as CMS_ANCHOR } from "./field-schema-CfdN75jT.js";
2
+ import { n as anchorIds, s as allowedLinks } from "./anchors-DuZ1fokt.js";
3
+ import { z } from "zod";
4
+ // src/shared/cms-markers.ts
5
+ /**
6
+ * The single source of the CMS asset/reference marker factories. A marker is a
7
+ * Zod string tagged with one of the `CMS_*` meta keys from `field-schema.ts`,
8
+ * which `zodToFieldSchema` reads back to produce an image/file/reference field.
9
+ *
10
+ * Used by the public `astronaut-cms/config` helpers (`file`/`link`/`anchor`), the
11
+ * `astro:content` stub (`reference`), and the content-config schema helper bag.
12
+ *
13
+ * In a `content.config.ts` `repoImageMarker` stands in for astro's own schema
14
+ * helper while the integration reads the config in Node: astro's `image()` is
15
+ * what the real build runs, and the marker is only how the admin learns the field
16
+ * takes a repository image. In a `cms.config.ts` the markers are the real thing,
17
+ * since astro has no say over an MDX component's props.
18
+ */
19
+ /** Astro's collection `image()` as the admin reads it: an image in the repository library alone. */
20
+ var repoImageMarker = () => z.string().meta({ [CMS_IMAGE]: "repo" });
21
+ /**
22
+ * A collection image field that takes a file from either media library: an
23
+ * object-store URL as it is, or anything else through astro's own `image()`,
24
+ * which imports a repository file as ever. Typed as what arrives, so rendering a
25
+ * URL where only `ImageMetadata` is handled is a compile error rather than a
26
+ * failed build. The URL is left to astro, which optimizes it as a remote image,
27
+ * and whether it names a library file is checked when content is written.
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * schema: ({ image }) => z.object({ cover: libraryImage(image) })
32
+ * ```
33
+ */
34
+ function libraryImage(image) {
35
+ return z.union([z.url(), image()]).meta({ [CMS_IMAGE]: true });
36
+ }
37
+ /** A Zod string naming a file in the media library, resolved to a bundled URL. */
38
+ var fileMarker = () => z.string().meta({ [CMS_FILE]: true });
39
+ /**
40
+ * A Zod string holding a URL: relative, http, https, mailto or tel. The only
41
+ * field a URL may be written into, since plain text is refused as one. The check
42
+ * is part of the schema itself, so the site's own content validation enforces it
43
+ * too, not only the CMS.
44
+ */
45
+ var linkMarker = () => allowedLinks(z.string()).meta({ [CMS_LINK]: true });
46
+ /**
47
+ * A Zod string holding an element id that the component or layout renders, such
48
+ * as a section's `id`. Declaring it is what lets a `#id` link in the same entry
49
+ * be checked, since the CMS cannot tell which prop ends up as an id otherwise.
50
+ */
51
+ var anchorMarker = () => anchorIds(z.string()).meta({ [CMS_ANCHOR]: true });
52
+ /**
53
+ * One value per content language, such as a translated title in an otherwise
54
+ * language-neutral entry. Stored as `{ de: "…", en: "…" }` and read with
55
+ * `pickLocale` from `astronaut-cms/content`. The admin edits it in a tab per
56
+ * language, and the default language is required, which the build and every
57
+ * save check, since only the CMS knows the site's languages.
58
+ */
59
+ var localizedMarker = (schema) => z.record(z.string(), schema).meta({ [CMS_LOCALIZED]: true });
60
+ /** A Zod string that references an entry id in another collection. */
61
+ var referenceMarker = (collection) => z.string().meta({ [CMS_REFERENCE]: collection });
62
+ /**
63
+ * What a component's props function is handed, mirroring the `({ image })` bag
64
+ * astro gives a collection schema. Handing them in rather than exporting them is
65
+ * what keeps an `image()` meant for a component prop out of a `content.config.ts`,
66
+ * where astro's own helper is the only one that resolves.
67
+ */
68
+ function schemaHelpers(resolveImage) {
69
+ return {
70
+ image: () => z.string().pipe(z.transform((path) => resolveImage(path)).meta({ [CMS_IMAGE]: true })),
71
+ file: fileMarker,
72
+ link: linkMarker,
73
+ anchor: anchorMarker,
74
+ localized: localizedMarker,
75
+ reference: referenceMarker
76
+ };
77
+ }
78
+ export { localizedMarker as a, schemaHelpers as c, linkMarker as i, fileMarker as n, referenceMarker as o, libraryImage as r, repoImageMarker as s, anchorMarker as t };
@@ -0,0 +1,128 @@
1
+ // src/shared/http.ts
2
+ /**
3
+ * What every CMS-owned response and every CMS-owned request body has in common,
4
+ * so no injected route has to restate it.
5
+ */
6
+ /**
7
+ * Hardening headers carried by every response the CMS serves. `nosniff` keeps a
8
+ * body from being interpreted as something other than the type it declares, and
9
+ * `no-referrer` keeps repository, entry and media paths out of the `Referer` of
10
+ * everything the admin reaches. The cross-origin policies keep other sites from
11
+ * embedding what the CMS serves or holding a handle on the admin's window, which
12
+ * the admin needs neither of, since it opens nothing it talks back to.
13
+ *
14
+ * Deliberately no `Permissions-Policy`: WebMCP is gated by the `tools` feature,
15
+ * which is allowed for a document's own origin only while nothing says
16
+ * otherwise. Adding a policy here has to name `tools=(self)`, or the admin's
17
+ * tool registration starts failing with `NotAllowedError`.
18
+ */
19
+ var HARDENING_HEADERS = {
20
+ "x-content-type-options": "nosniff",
21
+ "referrer-policy": "no-referrer",
22
+ "cross-origin-resource-policy": "same-origin",
23
+ "cross-origin-opener-policy": "same-origin"
24
+ };
25
+ /**
26
+ * Marks a request that is about to change content, for the dev server's reload
27
+ * suppression. Set by the admin rather than inferred from the method, because
28
+ * every operation is a POST and only the caller knows which one it is sending.
29
+ */
30
+ var WRITE_HEADER = "x-astronaut-cms-write";
31
+ /** Thrown by {@link readBody} when a request body exceeds a route's limit. */
32
+ var BodyTooLargeError = class extends Error {
33
+ constructor(maxBytes) {
34
+ super(`Request body is larger than the ${maxBytes} byte limit for this endpoint.`);
35
+ this.name = "BodyTooLargeError";
36
+ }
37
+ };
38
+ /**
39
+ * The body as it arrives, refusing anything over `maxBytes`. A route that
40
+ * forwards a body to a paid upstream, spends a secret on it, or holds it in a
41
+ * serverless instance's memory cannot let the caller choose its size, and
42
+ * `content-length` is only a claim, so the stream is measured as it is read and
43
+ * abandoned the moment it goes over.
44
+ *
45
+ * Yields the chunks rather than a body, so the two readers below each build the
46
+ * shape they want without either paying for the other's.
47
+ */
48
+ async function* chunks(request, maxBytes) {
49
+ const declared = Number(request.headers.get("content-length"));
50
+ if (Number.isFinite(declared) && declared > maxBytes) throw new BodyTooLargeError(maxBytes);
51
+ let size = 0;
52
+ for await (const value of request.body ?? []) {
53
+ size += value.length;
54
+ if (size > maxBytes) throw new BodyTooLargeError(maxBytes);
55
+ yield value;
56
+ }
57
+ }
58
+ /** The body as bytes, for an upload. */
59
+ async function readBytes(request, maxBytes) {
60
+ return new Blob(await Array.fromAsync(chunks(request, maxBytes))).bytes();
61
+ }
62
+ /**
63
+ * The body as text, for the routes whose bodies are JSON. Decoded as it arrives,
64
+ * so a multi-byte character split across two chunks survives and the bytes are
65
+ * never held twice.
66
+ */
67
+ async function readBody(request, maxBytes) {
68
+ const decoder = new TextDecoder();
69
+ let text = "";
70
+ for await (const chunk of chunks(request, maxBytes)) text += decoder.decode(chunk, { stream: true });
71
+ return text + decoder.decode();
72
+ }
73
+ /**
74
+ * A single `bytes=` range, which is all a media element asks for. Anything else
75
+ * reads as no range at all, and is answered with the whole file, exactly as a
76
+ * server that ignores the header would.
77
+ */
78
+ function parseByteRange(header) {
79
+ const { start, end } = header?.match(/^bytes=(?<start>\d*)-(?<end>\d*)$/)?.groups ?? {};
80
+ if (!start && !end) return null;
81
+ return {
82
+ start: start ? Number(start) : void 0,
83
+ end: end ? Number(end) : void 0
84
+ };
85
+ }
86
+ /** The header a range is forwarded upstream with. Inverse of {@link parseByteRange}. */
87
+ var rangeHeader = ({ start, end }) => `bytes=${start ?? ""}-${end ?? ""}`;
88
+ /** Settles a range against the size of the file it addresses. */
89
+ function partialContent({ start, end }, size) {
90
+ const [first, last] = start === void 0 ? [Math.max(size - (end ?? 0), 0), size - 1] : [start, Math.min(end ?? size - 1, size - 1)];
91
+ if (first > last || first >= size) return {
92
+ status: 416,
93
+ contentRange: `bytes */${size}`
94
+ };
95
+ return {
96
+ status: 206,
97
+ contentRange: `bytes ${first}-${last}/${size}`,
98
+ span: {
99
+ start: first,
100
+ end: last
101
+ }
102
+ };
103
+ }
104
+ // src/shared/component-lookup.ts
105
+ /**
106
+ * Every component in the tree with its name, nested child sets included. Generic
107
+ * over the definition so the admin gets its full `ClientComponentDef` back, the
108
+ * build the structural shape it walks with, and the site its live definitions.
109
+ */
110
+ function* componentEntries(tree) {
111
+ for (const [name, def] of Object.entries(tree)) {
112
+ yield [name, def];
113
+ if (typeof def.children === "object") yield* componentEntries(def.children);
114
+ }
115
+ }
116
+ /** Finds a component by name anywhere in the tree, including nested child sets. */
117
+ function findComponent(name, tree) {
118
+ return componentEntries(tree).find(([key]) => key === name)?.[1];
119
+ }
120
+ /**
121
+ * The components written directly inside one: its declared children, the
122
+ * top-level ones inside markdown children, and none inside a leaf.
123
+ */
124
+ function childComponents(def, topLevel) {
125
+ if (def.children === void 0) return {};
126
+ return def.children === "markdown" ? topLevel : def.children;
127
+ }
128
+ export { HARDENING_HEADERS as a, partialContent as c, readBytes as d, BodyTooLargeError as i, rangeHeader as l, componentEntries as n, WRITE_HEADER as o, findComponent as r, parseByteRange as s, childComponents as t, readBody as u };