@universalcms/connect 0.0.0-stage → 0.13.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 (132) hide show
  1. package/README.md +779 -2
  2. package/dist/angular-runtime.d.mts +4 -0
  3. package/dist/angular-runtime.mjs +7 -0
  4. package/dist/angular-setup.mjs +124 -0
  5. package/dist/astro-runtime.d.mts +6 -0
  6. package/dist/astro-runtime.mjs +255 -0
  7. package/dist/astro-setup.mjs +215 -0
  8. package/dist/astro-source.mjs +451 -0
  9. package/dist/astro-website.d.mts +5 -0
  10. package/dist/astro-website.mjs +42 -0
  11. package/dist/cli.mjs +552 -0
  12. package/dist/connector-runtime.mjs +130 -0
  13. package/dist/content-next-setup.mjs +200 -0
  14. package/dist/content-registry-validation.mjs +40 -0
  15. package/dist/content-registry.mjs +44 -0
  16. package/dist/content-setup.mjs +13 -0
  17. package/dist/content-storefront-setup.mjs +155 -0
  18. package/dist/content-vite-setup.mjs +107 -0
  19. package/dist/core.mjs +205 -0
  20. package/dist/framework-ownership.mjs +68 -0
  21. package/dist/framework.mjs +54 -0
  22. package/dist/guided.mjs +335 -0
  23. package/dist/native-adapters.mjs +31 -0
  24. package/dist/native-chrome-model.d.mts +3 -0
  25. package/dist/native-chrome-model.mjs +14 -0
  26. package/dist/native-chrome-review.mjs +49 -0
  27. package/dist/native-chrome-source.mjs +69 -0
  28. package/dist/native-route-review.mjs +152 -0
  29. package/dist/native-routes.mjs +27 -0
  30. package/dist/native-website-model.d.mts +18 -0
  31. package/dist/native-website-model.mjs +67 -0
  32. package/dist/native-website-server.d.mts +1 -0
  33. package/dist/native-website-server.mjs +35222 -0
  34. package/dist/native-website-server.mjs.LEGAL.txt +56 -0
  35. package/dist/native-website.d.mts +3 -0
  36. package/dist/native-website.mjs +120 -0
  37. package/dist/native-website.mjs.LEGAL.txt +56 -0
  38. package/dist/next-publication.d.mts +12 -0
  39. package/dist/next-publication.mjs +107 -0
  40. package/dist/next-settings-layout.mjs +233 -0
  41. package/dist/next-source.d.mts +8 -0
  42. package/dist/next-source.mjs +93 -0
  43. package/dist/page-discovery.mjs +236 -0
  44. package/dist/page-mapping-review.mjs +160 -0
  45. package/dist/preflight-recovery.mjs +122 -0
  46. package/dist/preflight.mjs +138 -0
  47. package/dist/project-files.mjs +56 -0
  48. package/dist/public-bindings.d.mts +3 -0
  49. package/dist/public-bindings.mjs +28 -0
  50. package/dist/publication-browser.d.mts +5 -0
  51. package/dist/publication-browser.mjs +258 -0
  52. package/dist/publication-check.mjs +141 -0
  53. package/dist/publication-document.d.mts +2 -0
  54. package/dist/publication-document.mjs +59 -0
  55. package/dist/publication-next-setup.mjs +134 -0
  56. package/dist/publication-setup.mjs +138 -0
  57. package/dist/publication-verification.mjs +85 -0
  58. package/dist/publication.css +6 -0
  59. package/dist/publication.d.mts +31 -0
  60. package/dist/publication.mjs +320 -0
  61. package/dist/react-publication.d.mts +22 -0
  62. package/dist/react-publication.mjs +301 -0
  63. package/dist/react-website.d.mts +15 -0
  64. package/dist/react-website.mjs +735 -0
  65. package/dist/reviewed-commerce-ownership.mjs +26 -0
  66. package/dist/reviewed-commerce-settings-setup.mjs +243 -0
  67. package/dist/reviewed-native-ownership.mjs +118 -0
  68. package/dist/reviewed-storefront-source.mjs +227 -0
  69. package/dist/runtime-dependencies.mjs +59 -0
  70. package/dist/setup-environment.mjs +307 -0
  71. package/dist/source-bindings.mjs +77 -0
  72. package/dist/source-check.mjs +149 -0
  73. package/dist/source-collect.mjs +80 -0
  74. package/dist/source-config.mjs +20 -0
  75. package/dist/source-extract.mjs +514 -0
  76. package/dist/source-finalize.mjs +52 -0
  77. package/dist/source-routes.mjs +65 -0
  78. package/dist/source-setup.mjs +490 -0
  79. package/dist/staged-setup.mjs +287 -0
  80. package/dist/static-runtime.mjs +67 -0
  81. package/dist/static-setup.mjs +136 -0
  82. package/dist/svelte-runtime.d.mts +27 -0
  83. package/dist/svelte-runtime.mjs +40 -0
  84. package/dist/svelte-setup.mjs +135 -0
  85. package/dist/svelte-template.mjs +48 -0
  86. package/dist/templates.mjs +248 -0
  87. package/dist/vendor/analyze-project.mjs +82 -0
  88. package/dist/vendor/astro-compiler/LICENSE +53 -0
  89. package/dist/vendor/astro-compiler/astro.wasm +0 -0
  90. package/dist/vendor/astro-compiler/chunk-W5DTLHV4.js +1 -0
  91. package/dist/vendor/astro-compiler/node/index.js +1 -0
  92. package/dist/vendor/check-delivery.mjs +158 -0
  93. package/dist/vendor/dependency-diagnostics.mjs +72 -0
  94. package/dist/vendor/inspect-installed-dependencies.mjs +125 -0
  95. package/dist/vendor/project-analysis.mjs +498 -0
  96. package/dist/vendor/react-LICENSE.txt +21 -0
  97. package/dist/vendor/react-document.mjs +124 -0
  98. package/dist/vendor/react-dom-LICENSE.txt +21 -0
  99. package/dist/vendor/react-form.mjs +63 -0
  100. package/dist/vendor/react-safety.mjs +47 -0
  101. package/dist/vendor/source-manifest-provider.mjs +104 -0
  102. package/dist/vendor/typescript-LICENSE.txt +55 -0
  103. package/dist/vendor/typescript.cjs +200276 -0
  104. package/dist/vite-handler.mjs +54 -0
  105. package/dist/vite-publication-server.d.mts +3 -0
  106. package/dist/vite-publication-server.mjs +82 -0
  107. package/dist/vite-publication.d.mts +15 -0
  108. package/dist/vite-publication.mjs +241 -0
  109. package/dist/vite-source-discovery.mjs +315 -0
  110. package/dist/vite-source.d.mts +30 -0
  111. package/dist/vite-source.mjs +141 -0
  112. package/dist/vue-runtime.d.mts +10 -0
  113. package/dist/vue-runtime.mjs +50 -0
  114. package/dist/vue-server.d.mts +2 -0
  115. package/dist/vue-server.mjs +58 -0
  116. package/dist/vue-setup.mjs +127 -0
  117. package/dist/vue-source.mjs +168 -0
  118. package/dist/website-check.mjs +41 -0
  119. package/dist/website-http.mjs +149 -0
  120. package/dist/website-model.d.mts +20 -0
  121. package/dist/website-model.mjs +155 -0
  122. package/dist/website-next.d.mts +2 -0
  123. package/dist/website-next.mjs +29 -0
  124. package/dist/website-node.d.mts +3 -0
  125. package/dist/website-node.mjs +50 -0
  126. package/dist/website-runtime.d.mts +13 -0
  127. package/dist/website-runtime.mjs +396 -0
  128. package/dist/website-schema.mjs +22175 -0
  129. package/dist/website-setup.mjs +256 -0
  130. package/dist/website.css +49 -0
  131. package/dist/wizard.mjs +298 -0
  132. package/package.json +60 -4
@@ -0,0 +1,124 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { createElement } from 'react';
3
+ import { CmsForm } from './react-form.mjs';
4
+ import { embedUrl, integer, record, safeSrcSet, safeUrl, text } from './react-safety.mjs';
5
+ export { CmsForm } from './react-form.mjs';
6
+ const supported = new Set(['paragraph', 'heading', 'quote', 'list', 'code', 'image', 'gallery', 'button', 'divider', 'spacer', 'faq', 'table', 'embed', 'form', 'section', 'columns']);
7
+ const styles = { align: ['left', 'center', 'right'], size: ['small', 'normal', 'large'], tone: ['default', 'muted', 'accent', 'inverse'], spaceAbove: ['none', 'small', 'medium', 'large'], spaceBelow: ['none', 'small', 'medium', 'large'], hideOnMobile: [true], hideOnDesktop: [true] };
8
+ function blockClasses(block) {
9
+ const style = record(block.style);
10
+ return ['cms-block', `cms-block-${text(block.type)}`, ...Object.entries(styles).flatMap(([key, allowed]) => allowed.includes(style[key]) ? [`cms-${key}-${String(style[key])}`] : [])].join(' ');
11
+ }
12
+ function image(data, key) {
13
+ const src = safeUrl(data.url, false);
14
+ return src ? _jsx("img", { src: src, alt: text(data.alt), srcSet: safeSrcSet(data.srcset), width: integer(data.width, 1, 20000), height: integer(data.height, 1, 20000), loading: "lazy", decoding: "async" }, key) : null;
15
+ }
16
+ function formDefinition(data) {
17
+ if (!Array.isArray(data.fields) || data.fields.length > 20 || !data.fields.length)
18
+ return null;
19
+ const fields = [], names = new Set();
20
+ for (const value of data.fields) {
21
+ const field = record(value), name = text(field.name), type = text(field.type);
22
+ if (!/^[a-z][a-z0-9_]{0,39}$/.test(name) || names.has(name) || !['text', 'email', 'phone', 'textarea', 'select', 'checkbox'].includes(type))
23
+ return null;
24
+ names.add(name);
25
+ fields.push({ id: text(field.id) || name, name, label: text(field.label), type: type, required: field.required === true, placeholder: text(field.placeholder), options: Array.isArray(field.options) ? field.options.filter((item) => typeof item === 'string').slice(0, 30) : [] });
26
+ }
27
+ return { fields, submitLabel: text(data.submitLabel), successMessage: text(data.successMessage), consentText: text(data.consentText) };
28
+ }
29
+ /** Default semantic HTML. Replace any block renderer with the website's own component. */
30
+ export function CmsDocument({ document, components = {}, entryId, revisionId, variant, formEndpoint, className, preview = false, selectedId, unknownBlock }) {
31
+ let count = 0;
32
+ function renderMany(values, parent) {
33
+ return Array.isArray(values) ? values.slice(0, 400).map((value, index) => render(value, parent, index)) : null;
34
+ }
35
+ function render(value, parent, index) {
36
+ if (++count > 400)
37
+ return null;
38
+ const block = record(value), type = text(block.type), id = text(block.id), body = text(block.text), data = record(block.data);
39
+ if (block.version !== 1 || !supported.has(type))
40
+ return unknownBlock ? unknownBlock(value) : preview ? _jsxs("p", { role: "status", children: ["Unsupported content block: ", type || 'unknown', " (version ", String(block.version), ")."] }, id || index) : null;
41
+ if ((type === 'section' && parent !== 'root') || (type === 'columns' && parent === 'columns'))
42
+ return null;
43
+ const children = type === 'section' ? renderMany(data.blocks, 'section') : type === 'columns' && Array.isArray(data.columns) ? data.columns.slice(0, 4).map((column, columnIndex) => _jsx("div", { className: "cms-column", children: renderMany(column, 'columns') }, columnIndex)) : undefined;
44
+ const Custom = components[type];
45
+ let node;
46
+ if (Custom)
47
+ node = _jsx(Custom, { block: value, entryId: entryId, revisionId: revisionId, variant: variant, children: children });
48
+ else
49
+ switch (type) {
50
+ case 'paragraph':
51
+ node = _jsx("p", { children: body });
52
+ break;
53
+ case 'heading':
54
+ node = createElement(`h${integer(data.level, 2, 4) ?? 2}`, null, body);
55
+ break;
56
+ case 'quote':
57
+ node = _jsx("blockquote", { children: body });
58
+ break;
59
+ case 'list':
60
+ node = _jsx("ul", { children: body.split('\n').map((line, lineIndex) => _jsx("li", { children: line }, lineIndex)) });
61
+ break;
62
+ case 'code':
63
+ node = _jsx("pre", { children: _jsx("code", { children: body }) });
64
+ break;
65
+ case 'image': {
66
+ const href = safeUrl(data.link);
67
+ const align = ['left', 'center', 'right', 'full'].includes(text(data.align)) ? text(data.align) : 'full';
68
+ node = _jsxs("figure", { className: `cms-image-align-${align}`, children: [href ? _jsx("a", { href: href, children: image(data) }) : image(data), body && _jsx("figcaption", { children: body })] });
69
+ break;
70
+ }
71
+ case 'gallery':
72
+ node = _jsxs("figure", { children: [_jsx("div", { className: `cms-gallery cms-grid-${integer(data.columns, 2, 4) ?? 2}`, children: Array.isArray(data.images) && data.images.slice(0, 30).map((item, i) => image(record(item), text(record(item).id) || String(i))) }), body && _jsx("figcaption", { children: body })] });
73
+ break;
74
+ case 'button': {
75
+ const href = safeUrl(data.url);
76
+ const tone = ['primary', 'secondary', 'link'].includes(text(data.style)) ? text(data.style) : 'primary';
77
+ const align = ['left', 'center', 'right'].includes(text(data.align)) ? text(data.align) : 'left';
78
+ node = _jsx("div", { className: `cms-align-${align}`, children: href ? _jsx("a", { className: `cms-button cms-button-${tone}`, href: href, target: data.newTab === true ? '_blank' : undefined, rel: data.newTab === true ? 'noopener noreferrer' : undefined, children: body }) : _jsx("span", { "aria-disabled": "true", children: body }) });
79
+ break;
80
+ }
81
+ case 'divider':
82
+ node = _jsx("hr", {});
83
+ break;
84
+ case 'spacer':
85
+ node = _jsx("div", { "aria-hidden": "true", style: { height: integer(data.height, 8, 400) ?? 48 } });
86
+ break;
87
+ case 'faq':
88
+ node = _jsx("div", { children: Array.isArray(data.items) && data.items.slice(0, 50).map((value, i) => { const item = record(value); return _jsxs("details", { children: [_jsx("summary", { children: text(item.question) }), _jsx("p", { children: text(item.answer) })] }, text(item.id) || i); }) });
89
+ break;
90
+ case 'table': {
91
+ const rows = Array.isArray(data.rows) ? data.rows.slice(0, 100).filter(Array.isArray) : [];
92
+ node = _jsx("div", { className: "cms-table-scroll", role: "region", "aria-label": body || 'Content table', tabIndex: 0, children: _jsxs("table", { children: [body && _jsx("caption", { children: body }), data.header === true && rows[0] && _jsx("thead", { children: _jsx("tr", { children: rows[0].slice(0, 12).map((cell, i) => _jsx("th", { scope: "col", children: text(cell) }, i)) }) }), _jsx("tbody", { children: rows.slice(data.header === true ? 1 : 0).map((row, i) => _jsx("tr", { children: row.slice(0, 12).map((cell, j) => _jsx("td", { children: text(cell) }, j)) }, i)) })] }) });
93
+ break;
94
+ }
95
+ case 'embed': {
96
+ const src = embedUrl(data.url, data.provider);
97
+ const aspect = ['16:9', '4:3', '1:1'].includes(text(data.aspect)) ? text(data.aspect).replace(':', '/') : '16/9';
98
+ node = src ? _jsx("iframe", { className: "cms-embed", src: src, title: body || 'Embedded content', style: { aspectRatio: aspect }, loading: "lazy", sandbox: data.provider === 'iframe' ? 'allow-scripts allow-presentation' : 'allow-scripts allow-same-origin allow-presentation', allow: "fullscreen; picture-in-picture", allowFullScreen: true, referrerPolicy: "no-referrer" }) : null;
99
+ break;
100
+ }
101
+ case 'form': {
102
+ const definition = formDefinition(data);
103
+ node = definition && entryId ? _jsx(CmsForm, { definition: definition, entryId: entryId, blockId: id, revisionId: revisionId, variant: variant, endpoint: formEndpoint, disabled: preview }) : _jsx("p", { children: "Submissions are currently unavailable." });
104
+ break;
105
+ }
106
+ case 'section': {
107
+ const background = ['none', 'muted', 'accent', 'dark'].includes(text(data.background)) ? text(data.background) : 'none';
108
+ const padding = ['none', 'small', 'medium', 'large'].includes(text(data.padding)) ? text(data.padding) : 'medium';
109
+ const width = ['normal', 'wide', 'full'].includes(text(data.width)) ? text(data.width) : 'normal';
110
+ node = _jsx("section", { className: `cms-section-${background} cms-padding-${padding} cms-width-${width}`, children: children });
111
+ break;
112
+ }
113
+ case 'columns': {
114
+ const layout = ['1-1', '1-2', '2-1', '1-1-1', '1-1-1-1'].includes(text(data.layout)) ? text(data.layout) : '1-1';
115
+ const gap = ['small', 'medium', 'large'].includes(text(data.gap)) ? text(data.gap) : 'medium';
116
+ node = _jsx("div", { className: `cms-columns cms-layout-${layout} cms-gap-${gap}${data.stackOnMobile === false ? '' : ' cms-stack'}`, children: children });
117
+ break;
118
+ }
119
+ }
120
+ const anchor = text(record(block.style).anchor);
121
+ return _jsx("div", { id: /^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(anchor) ? anchor : undefined, className: `${blockClasses(block)}${preview && id === selectedId ? ' cms-selected' : ''}`, ...(preview ? { 'data-cms-block': id, 'data-cms-type': type } : {}), children: node }, id || index);
122
+ }
123
+ return _jsx("div", { className: ['cms-document', className].filter(Boolean).join(' '), children: renderMany(document.blocks, 'root') });
124
+ }
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) Meta Platforms, Inc. and affiliates.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,63 @@
1
+ 'use client';
2
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
+ import { useEffect, useId, useState } from 'react';
4
+ import { record, sameOriginPath, text } from './react-safety.mjs';
5
+ /** Submissions go only to a same-origin website route; credentials never enter this component. */
6
+ export function CmsForm({ definition, entryId, blockId, revisionId, variant, endpoint, disabled = false }) {
7
+ const prefix = useId();
8
+ const [ready, setReady] = useState(false);
9
+ useEffect(() => setReady(true), []);
10
+ const [busy, setBusy] = useState(false), [message, setMessage] = useState(''), [errors, setErrors] = useState([]);
11
+ const action = sameOriginPath(endpoint);
12
+ async function submit(event) {
13
+ event.preventDefault();
14
+ if (!ready || !action || disabled || busy || (variant === 'b' && !revisionId))
15
+ return;
16
+ const form = event.currentTarget;
17
+ const values = new FormData(form);
18
+ const input = Object.fromEntries(definition.fields.map(field => [field.name, field.type === 'checkbox' ? values.get(field.name) === 'on' : String(values.get(field.name) ?? '')]));
19
+ setBusy(true);
20
+ setErrors([]);
21
+ setMessage('');
22
+ try {
23
+ const response = await fetch(action, { method: 'POST', credentials: 'same-origin', redirect: 'error', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ entryId, blockId, ...(revisionId ? { revisionId } : {}), ...(variant ? { variant } : {}), values: input, website: String(values.get('_cms_website') ?? ''), path: window.location.pathname }), signal: AbortSignal.timeout(15000) });
24
+ if (response.status === 429) {
25
+ setMessage('Too many submissions. Please wait a few minutes and try again.');
26
+ return;
27
+ }
28
+ if (response.status === 409) {
29
+ setMessage('This form has changed. Refresh the page before submitting again.');
30
+ return;
31
+ }
32
+ if (response.status === 404) {
33
+ setMessage('This form is no longer available. Refresh the page and try again.');
34
+ return;
35
+ }
36
+ if (!response.ok)
37
+ throw new Error('The form could not be submitted. Please try again.');
38
+ const envelope = record(await response.json());
39
+ const result = record(envelope.data ?? envelope);
40
+ if (Array.isArray(result.errors) && result.errors.length) {
41
+ setErrors(result.errors.filter((value) => typeof value === 'string'));
42
+ setMessage('Please check the highlighted fields.');
43
+ }
44
+ else if (typeof result.message === 'string' && ('id' in result)) {
45
+ setMessage(result.message || definition.successMessage || 'Thank you.');
46
+ form.reset();
47
+ }
48
+ else
49
+ throw new Error('The form could not be submitted. Please try again.');
50
+ }
51
+ catch {
52
+ setMessage('The form could not be submitted. Please try again.');
53
+ }
54
+ finally {
55
+ setBusy(false);
56
+ }
57
+ }
58
+ return _jsxs("form", { className: "cms-form", method: "post", action: action || undefined, onSubmit: submit, "aria-busy": busy, children: [_jsxs("fieldset", { disabled: !ready || disabled || !action || busy || (variant === 'b' && !revisionId), children: [definition.fields.map(field => {
59
+ const id = `${prefix}-${field.id}`, invalid = errors.includes(field.name);
60
+ const props = { id, name: field.name, required: field.required, 'aria-invalid': invalid || undefined, 'aria-describedby': invalid ? `${id}-error` : undefined };
61
+ return _jsxs("div", { className: "cms-form-field", children: [field.type === 'checkbox' ? _jsxs("label", { children: [_jsx("input", { ...props, type: "checkbox" }), field.label] }) : _jsxs(_Fragment, { children: [_jsx("label", { htmlFor: id, children: field.label }), field.type === 'textarea' ? _jsx("textarea", { ...props, placeholder: field.placeholder, maxLength: 5000 }) : field.type === 'select' ? _jsxs("select", { ...props, defaultValue: "", children: [_jsx("option", { value: "", children: "Choose an option" }), field.options?.map(option => _jsx("option", { value: option, children: option }, option))] }) : _jsx("input", { ...props, type: field.type === 'phone' ? 'tel' : field.type, placeholder: field.placeholder, maxLength: 500 })] }), invalid && _jsx("span", { id: `${id}-error`, children: "Please check this field." })] }, field.id);
62
+ }), _jsxs("div", { hidden: true, "aria-hidden": "true", children: [_jsx("label", { htmlFor: `${prefix}-website`, children: "Leave this empty" }), _jsx("input", { id: `${prefix}-website`, name: "_cms_website", tabIndex: -1, autoComplete: "off" })] }), definition.consentText && _jsx("p", { children: definition.consentText }), _jsx("button", { type: "submit", children: busy ? 'Sending…' : definition.submitLabel || 'Send' })] }), (!action || (variant === 'b' && !revisionId)) && !disabled && _jsx("p", { children: "Submissions are currently unavailable." }), _jsx("noscript", { children: _jsx("p", { children: "Enable JavaScript to submit this form." }) }), _jsx("p", { role: "status", children: text(message) })] });
63
+ }
@@ -0,0 +1,47 @@
1
+ /** CMS values are data: never treat a string as HTML, CSS or an executable URL. */
2
+ export function safeUrl(value, internal = true) {
3
+ if (typeof value !== 'string' || !value || value.length > 2048 || /[\u0000-\u0020\u007f\\]/.test(value))
4
+ return undefined;
5
+ if (internal && value.startsWith('/') && !value.startsWith('//'))
6
+ return value;
7
+ try {
8
+ const url = new URL(value);
9
+ return ['https:', 'http:'].includes(url.protocol) && !url.username && !url.password ? url.href : undefined;
10
+ }
11
+ catch {
12
+ return undefined;
13
+ }
14
+ }
15
+ export function sameOriginPath(value) {
16
+ return typeof value === 'string' && value.startsWith('/') && !value.startsWith('//') ? safeUrl(value) : undefined;
17
+ }
18
+ export function safeSrcSet(value) {
19
+ if (typeof value !== 'string' || value.length > 4000 || !value)
20
+ return undefined;
21
+ const candidates = value.split(',').map(part => part.trim().split(/\s+/));
22
+ return candidates.every(([url, width, ...rest]) => rest.length === 0 && safeUrl(url, false) && /^[1-9]\d{0,4}w$/.test(width ?? '')) ? value : undefined;
23
+ }
24
+ export function embedUrl(value, provider) {
25
+ const safe = safeUrl(value, false);
26
+ if (!safe || !safe.startsWith('https:'))
27
+ return undefined;
28
+ const url = new URL(safe);
29
+ if (provider === 'iframe')
30
+ return safe;
31
+ if (provider === 'youtube') {
32
+ const id = url.hostname === 'youtu.be' ? /^\/([^/]+)\/?$/.exec(url.pathname)?.[1] : ['youtube.com', 'www.youtube.com', 'm.youtube.com', 'youtube-nocookie.com', 'www.youtube-nocookie.com'].includes(url.hostname) ? (/^\/watch\/?$/.test(url.pathname) ? url.searchParams.get('v') : /^\/(?:embed|shorts|live)\/([^/]+)\/?$/.exec(url.pathname)?.[1]) : null;
33
+ return id && /^[A-Za-z0-9_-]{11}$/.test(id) ? `https://www.youtube-nocookie.com/embed/${id}` : undefined;
34
+ }
35
+ if (provider === 'vimeo' && ['vimeo.com', 'www.vimeo.com', 'player.vimeo.com'].includes(url.hostname)) {
36
+ const id = /^\/(?:video\/)?(\d{1,20})\/?$/.exec(url.pathname)?.[1];
37
+ return id ? `https://player.vimeo.com/video/${id}` : undefined;
38
+ }
39
+ return undefined;
40
+ }
41
+ export function record(value) {
42
+ return value && typeof value === 'object' && !Array.isArray(value) ? value : {};
43
+ }
44
+ export function text(value) { return typeof value === 'string' ? value : ''; }
45
+ export function integer(value, minimum, maximum) {
46
+ return typeof value === 'number' && Number.isSafeInteger(value) && value >= minimum && value <= maximum ? value : undefined;
47
+ }
@@ -0,0 +1,104 @@
1
+ /** Copyable Node-only source bridge. Serves public source content; never contacts or writes to the CMS. */
2
+ import { createHash } from 'node:crypto';
3
+
4
+ export const sourceManifestPath = '/api/cms-source';
5
+ const MAX_BYTES = 20 * 1024 * 1024;
6
+ const MAX_ENTRIES = 1000;
7
+ const object = value => value !== null && typeof value === 'object' && !Array.isArray(value);
8
+ const only = (value, keys) => Object.keys(value).every(key => keys.includes(key));
9
+ const fail = () => { throw Error('Invalid public source manifest'); };
10
+
11
+ // Match the authoring taxonomy contract before exposing a source snapshot. IDs
12
+ // are stable references: do not silently rename labels or merge collisions here.
13
+ function validateTaxonomy(taxonomy, entryIndex) {
14
+ if (taxonomy === undefined) return;
15
+ const at = `entries[${entryIndex}].document.taxonomy`;
16
+ const invalid = (path, rule) => { throw Error(`Invalid public source manifest: ${path} ${rule}`); };
17
+ if (!object(taxonomy) || !only(taxonomy, ['categories', 'tags'])) invalid(at, 'must contain only categories and tags');
18
+ for (const [field, limit] of [['categories', 20], ['tags', 50]]) {
19
+ const items = taxonomy[field];
20
+ if (items === undefined) continue;
21
+ if (!Array.isArray(items) || items.length > limit) invalid(`${at}.${field}`, `must be an array of at most ${limit} IDs`);
22
+ const seen = new Set();
23
+ items.forEach((value, index) => {
24
+ if (typeof value !== 'string' || value.length > 80 || !/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(value)) invalid(`${at}.${field}[${index}]`, 'must use a lowercase letter/digit ID with single hyphens, at most 80 characters');
25
+ if (seen.has(value)) invalid(`${at}.${field}[${index}]`, 'must not repeat another ID in this list');
26
+ seen.add(value);
27
+ });
28
+ }
29
+ }
30
+
31
+ function configuredOrigin(value) {
32
+ try {
33
+ const url = new URL(value);
34
+ const loopback = ['localhost', '127.0.0.1', '[::1]'].includes(url.hostname);
35
+ if ((url.protocol === 'https:' || (url.protocol === 'http:' && loopback)) && !url.username && !url.password && url.pathname === '/' && !url.search && !url.hash) return url.origin;
36
+ } catch { /* Never echo configuration or credentials. */ }
37
+ throw Error('Configure an exact HTTPS or loopback origin');
38
+ }
39
+
40
+ /** The source adapter must already validate complete documents and select only intentionally public source content. */
41
+ function readManifest(json) {
42
+ if (typeof json !== 'string' || Buffer.byteLength(json) > MAX_BYTES) throw Error('Source manifest exceeds the 20 MiB budget');
43
+ let manifest;
44
+ try { manifest = JSON.parse(json); } catch { fail(); }
45
+ if (!object(manifest) || !only(manifest, ['version', 'entries']) || manifest.version !== 1 || !Array.isArray(manifest.entries)) fail();
46
+ if (manifest.entries.length > MAX_ENTRIES) throw Error('Source connection exceeds 1,000 entries; use separately reviewed file batches');
47
+ const identities = new Set();
48
+ for (const [entryIndex, entry] of manifest.entries.entries()) {
49
+ if (!object(entry) || !only(entry, ['kind', 'slug', 'locale', 'document']) || !['page', 'post'].includes(entry.kind) || typeof entry.slug !== 'string' || entry.slug.length > 160 || !/^[a-z0-9]+(?:[-/][a-z0-9]+)*$/.test(entry.slug) || typeof entry.locale !== 'string' || entry.locale.length < 2 || entry.locale.length > 35) fail();
50
+ try { if (Intl.getCanonicalLocales(entry.locale).length !== 1) fail(); } catch { fail(); }
51
+ const key = `${entry.kind}:${Intl.getCanonicalLocales(entry.locale)[0]}:${entry.slug}`;
52
+ if (identities.has(key)) throw Error('Duplicate public source identity');
53
+ identities.add(key);
54
+ const doc = entry.document;
55
+ if (!object(doc) || !only(doc, ['schemaVersion', 'title', 'excerpt', 'blocks', 'taxonomy', 'fields']) || doc.schemaVersion !== 1 || typeof doc.title !== 'string' || !doc.title.trim() || doc.title.length > 200 || typeof doc.excerpt !== 'string' || doc.excerpt.length > 1000 || !Array.isArray(doc.blocks) || doc.blocks.length > 200 || (doc.fields !== undefined && (!object(doc.fields) || Object.keys(doc.fields).length))) fail();
56
+ validateTaxonomy(doc.taxonomy, entryIndex);
57
+ }
58
+ return JSON.stringify(manifest);
59
+ }
60
+
61
+ /**
62
+ * Call before a source server's normal method/API routing. Returns false for other paths.
63
+ * publicContent: true is an explicit assertion by the source adapter, not an authorization mechanism.
64
+ * CORS restricts browser reads; the content is intentionally public and Origin can be forged by non-browsers.
65
+ */
66
+ export function createSourceManifestProvider({ manifestJson, sourceOrigin, adminOrigin, siteId, environmentId, publicContent }) {
67
+ if (publicContent !== true) throw Error('Explicitly select public source content before enabling the provider');
68
+ const source = configuredOrigin(sourceOrigin), admin = configuredOrigin(adminOrigin);
69
+ const uuid = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
70
+ if (typeof siteId !== 'string' || typeof environmentId !== 'string' || !uuid.test(siteId) || !uuid.test(environmentId)) throw Error('Configure the source website and environment IDs');
71
+ const manifest = JSON.parse(readManifest(manifestJson));
72
+ const body = JSON.stringify({ version: 1, siteId, environmentId, entries: manifest.entries });
73
+ if (Buffer.byteLength(body) > MAX_BYTES) throw Error('Bound source manifest exceeds the 20 MiB budget');
74
+ const etag = `"${createHash('sha256').update(body).digest('hex')}"`;
75
+ return function sourceManifestProvider(request, response) {
76
+ let url;
77
+ try { url = new URL(request.url, source); } catch { return false; }
78
+ if (url.pathname !== sourceManifestPath) return false;
79
+ const common = {
80
+ 'Cache-Control': 'no-store', 'Content-Type': 'application/json; charset=utf-8',
81
+ 'X-Content-Type-Options': 'nosniff', 'Referrer-Policy': 'no-referrer', Vary: 'Origin',
82
+ };
83
+ const send = (status, payload, headers = {}) => {
84
+ const text = payload === undefined ? '' : JSON.stringify({ error: payload });
85
+ response.writeHead(status, { ...common, ...headers, 'Content-Length': Buffer.byteLength(text) });
86
+ response.end(request.method === 'HEAD' ? undefined : text);
87
+ return true;
88
+ };
89
+ // IDs bind this public snapshot to server configuration; they never grant authoring access.
90
+ const query = [...url.searchParams.entries()];
91
+ const matchesBinding = query.length === 2 && query.every(([key]) => ['siteId', 'environmentId'].includes(key)) && url.searchParams.get('siteId') === siteId && url.searchParams.get('environmentId') === environmentId;
92
+ // No API key, cookies or session proof belongs on this source read.
93
+ if (url.origin !== source || !matchesBinding || url.hash || request.headers?.host !== new URL(source).host || request.headers?.origin !== admin || request.headers?.authorization || request.headers?.cookie || request.headers?.['x-csrf-token']) return send(403, 'Source export is not available for this request');
94
+ const cors = { 'Access-Control-Allow-Origin': admin, 'Access-Control-Expose-Headers': 'ETag' };
95
+ if (request.method === 'OPTIONS') {
96
+ if (!['GET', 'HEAD'].includes(request.headers?.['access-control-request-method']) || request.headers?.['access-control-request-headers']) return send(403, 'Source export does not accept credential headers');
97
+ return send(204, undefined, { ...cors, 'Access-Control-Allow-Methods': 'GET, HEAD, OPTIONS' });
98
+ }
99
+ if (!['GET', 'HEAD'].includes(request.method)) return send(405, 'Use GET or HEAD', { ...cors, Allow: 'GET, HEAD, OPTIONS' });
100
+ response.writeHead(200, { ...common, ...cors, ETag: etag, 'Content-Length': Buffer.byteLength(body) });
101
+ response.end(request.method === 'HEAD' ? undefined : body);
102
+ return true;
103
+ };
104
+ }
@@ -0,0 +1,55 @@
1
+ Apache License
2
+
3
+ Version 2.0, January 2004
4
+
5
+ http://www.apache.org/licenses/
6
+
7
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
8
+
9
+ 1. Definitions.
10
+
11
+ "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
16
+
17
+ "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
18
+
19
+ "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
20
+
21
+ "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
22
+
23
+ "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
24
+
25
+ "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
26
+
27
+ "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
28
+
29
+ "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
30
+
31
+ 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
32
+
33
+ 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
34
+
35
+ 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
36
+
37
+ You must give any other recipients of the Work or Derivative Works a copy of this License; and
38
+
39
+ You must cause any modified files to carry prominent notices stating that You changed the files; and
40
+
41
+ You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
42
+
43
+ If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
44
+
45
+ 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
46
+
47
+ 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
48
+
49
+ 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
50
+
51
+ 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
52
+
53
+ 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
54
+
55
+ END OF TERMS AND CONDITIONS