inlaycms 0.4.0 → 0.5.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 (131) hide show
  1. package/README.md +18 -709
  2. package/assets/admin/admin.css +1 -1
  3. package/assets/admin/editor.js +63 -46
  4. package/assets/site/consent.js +1 -0
  5. package/dist/adapters/admin/context.d.ts +1 -1
  6. package/dist/adapters/admin/context.js +1 -0
  7. package/dist/adapters/admin/routes.d.ts +2 -0
  8. package/dist/adapters/admin/routes.js +2 -0
  9. package/dist/adapters/admin/screens/backups.js +2 -2
  10. package/dist/adapters/admin/screens/editor.js +2 -1
  11. package/dist/adapters/admin/screens/integrations.d.ts +4 -0
  12. package/dist/adapters/admin/screens/integrations.js +140 -0
  13. package/dist/adapters/admin/screens/lists.js +2 -1
  14. package/dist/adapters/admin/screens/releases.js +1 -1
  15. package/dist/adapters/admin/views/layout.js +3 -0
  16. package/dist/adapters/cli/bin.js +8 -3
  17. package/dist/adapters/mcp/tools/read.js +17 -2
  18. package/dist/adapters/mcp/tools/write.js +4 -0
  19. package/dist/adapters/site/cache.d.ts +8 -2
  20. package/dist/adapters/site/cache.js +13 -4
  21. package/dist/adapters/site/code-files.d.ts +44 -0
  22. package/dist/adapters/site/code-files.js +212 -0
  23. package/dist/adapters/site/consent.d.ts +9 -0
  24. package/dist/adapters/site/consent.js +26 -0
  25. package/dist/adapters/site/context.d.ts +5 -0
  26. package/dist/adapters/site/context.js +97 -20
  27. package/dist/adapters/site/csp.d.ts +11 -0
  28. package/dist/adapters/site/csp.js +36 -0
  29. package/dist/adapters/site/head.js +1 -14
  30. package/dist/adapters/site/headers.d.ts +5 -2
  31. package/dist/adapters/site/headers.js +13 -6
  32. package/dist/adapters/site/integrations.d.ts +48 -0
  33. package/dist/adapters/site/integrations.js +118 -0
  34. package/dist/adapters/site/media-routes.d.ts +2 -0
  35. package/dist/adapters/site/media-routes.js +2 -1
  36. package/dist/adapters/site/plugin.d.ts +2 -0
  37. package/dist/adapters/site/plugin.js +64 -34
  38. package/dist/adapters/site/render.d.ts +31 -14
  39. package/dist/adapters/site/render.js +26 -5
  40. package/dist/adapters/site/routes.d.ts +3 -0
  41. package/dist/adapters/site/routes.js +7 -3
  42. package/dist/adapters/site/scripts.d.ts +6 -0
  43. package/dist/adapters/site/scripts.js +27 -0
  44. package/dist/core/auth/roles.d.ts +1 -1
  45. package/dist/core/auth/roles.js +1 -0
  46. package/dist/core/boot.d.ts +2 -0
  47. package/dist/core/boot.js +3 -0
  48. package/dist/core/content/shipped-input.js +1 -2
  49. package/dist/core/content/validate.d.ts +7 -0
  50. package/dist/core/content/validate.js +24 -1
  51. package/dist/core/core.d.ts +29 -0
  52. package/dist/core/core.js +10 -2
  53. package/dist/core/db/migrate.js +2 -0
  54. package/dist/core/db/migrations/0008_integrations.d.ts +3 -0
  55. package/dist/core/db/migrations/0008_integrations.js +11 -0
  56. package/dist/core/db/schema.d.ts +11 -0
  57. package/dist/core/export/export.js +4 -0
  58. package/dist/core/export/format.d.ts +11 -0
  59. package/dist/core/export/format.js +4 -0
  60. package/dist/core/export/import.js +2 -1
  61. package/dist/core/export/replace.d.ts +6 -1
  62. package/dist/core/export/replace.js +4 -1
  63. package/dist/core/export/report.d.ts +6 -0
  64. package/dist/core/export/report.js +7 -0
  65. package/dist/core/fields/builtins.d.ts +4 -0
  66. package/dist/core/fields/builtins.js +11 -1
  67. package/dist/core/fields/widgets.js +5 -1
  68. package/dist/core/integrations/integrations.d.ts +32 -0
  69. package/dist/core/integrations/integrations.js +80 -0
  70. package/dist/core/integrations/warnings.d.ts +4 -0
  71. package/dist/core/integrations/warnings.js +29 -0
  72. package/dist/core/media/store.d.ts +2 -0
  73. package/dist/core/media/store.js +17 -1
  74. package/dist/core/media/variants.d.ts +14 -0
  75. package/dist/core/media/variants.js +54 -0
  76. package/dist/core/messages/en.d.ts +73 -0
  77. package/dist/core/messages/en.js +73 -0
  78. package/dist/core/registry/code-image.d.ts +16 -0
  79. package/dist/core/registry/code-image.js +13 -0
  80. package/dist/core/registry/define.d.ts +7 -0
  81. package/dist/core/registry/define.js +2 -0
  82. package/dist/core/registry/designed.d.ts +6 -0
  83. package/dist/core/registry/designed.js +8 -0
  84. package/dist/core/registry/integration.d.ts +48 -0
  85. package/dist/core/registry/integration.js +29 -0
  86. package/dist/core/registry/js.d.ts +9 -0
  87. package/dist/core/registry/js.js +39 -0
  88. package/dist/core/registry/registry.js +46 -0
  89. package/dist/core/registry/render.d.ts +39 -4
  90. package/dist/core/release/bundle.d.ts +3 -1
  91. package/dist/core/release/bundle.js +169 -11
  92. package/dist/core/release/manifest.d.ts +29 -1
  93. package/dist/core/release/manifest.js +26 -1
  94. package/dist/core/release/pack.js +13 -2
  95. package/dist/core/release/pointer.js +14 -3
  96. package/dist/core/release/read.d.ts +2 -0
  97. package/dist/core/release/read.js +1 -0
  98. package/dist/core/report.d.ts +3 -0
  99. package/dist/core/richtext/headings.d.ts +10 -0
  100. package/dist/core/richtext/headings.js +37 -0
  101. package/dist/core/richtext/html.d.ts +10 -1
  102. package/dist/core/richtext/html.js +17 -6
  103. package/dist/core/richtext/markdown-text.d.ts +24 -0
  104. package/dist/core/richtext/markdown-text.js +38 -0
  105. package/dist/core/richtext/markdown.js +44 -3
  106. package/dist/core/richtext/schema.d.ts +12 -3
  107. package/dist/core/richtext/schema.js +34 -0
  108. package/dist/core/site/live.d.ts +6 -0
  109. package/dist/core/site/live.js +25 -0
  110. package/dist/host/app.d.ts +2 -0
  111. package/dist/host/app.js +1 -0
  112. package/dist/host/diff.d.ts +11 -0
  113. package/dist/host/diff.js +40 -0
  114. package/dist/host/drain.d.ts +12 -0
  115. package/dist/host/drain.js +34 -0
  116. package/dist/host/ipc.d.ts +2 -0
  117. package/dist/host/ipc.js +5 -1
  118. package/dist/host/preview-worker.js +2 -2
  119. package/dist/host/primary.js +15 -4
  120. package/dist/host/push.js +1 -1
  121. package/dist/host/serve.js +1 -1
  122. package/dist/host/store.d.ts +1 -2
  123. package/dist/host/store.js +32 -6
  124. package/dist/host/worker.js +6 -0
  125. package/dist/image-modules.d.ts +29 -0
  126. package/dist/image-modules.js +1 -0
  127. package/dist/index.d.ts +7 -1
  128. package/dist/index.js +4 -0
  129. package/dist/site.d.ts +8 -1
  130. package/dist/site.js +5 -0
  131. package/package.json +5 -1
@@ -0,0 +1 @@
1
+ (()=>{var C="inlay-consent";var A=["analytics","marketing","functional"],h=a=>A.includes(a);function v(a){let r=a.document,l=null;function S(){let t=l;try{let e=a.localStorage.getItem(C);if(e!==null){let n=JSON.parse(e);n&&typeof n.at=="number"&&(t={at:n.at,analytics:n.analytics===!0,marketing:n.marketing===!0,functional:n.functional===!0})}}catch{}return!t||Date.now()-t.at>31536e6||Date.now()<t.at-6e4?null:t}function c(){let t=S();return{decided:t!==null,analytics:t?.analytics??!1,marketing:t?.marketing??!1,functional:t?.functional??!1}}function s(t){let e=r.createElement("script");for(let n of Array.from(t.attributes))e.setAttribute(n.name,n.value);return e.text=t.text,e}let u=t=>t.nodeName==="SCRIPT",d=t=>{if(!u(t)||!t.hasAttribute("src")||t.hasAttribute("async")||t.hasAttribute("nomodule"))return!1;let e=(t.getAttribute("type")??"").trim().toLowerCase();return e===""||e==="module"||/^(text|application)\/(x-)?(javascript|ecmascript)$/.test(e)},T=t=>new Promise(e=>{t.addEventListener("load",()=>e(),{once:!0}),t.addEventListener("error",()=>e(),{once:!0})});async function L(t){let e=r.createComment("");t.replaceWith(e);let n=r.importNode(t.content,!0);for(let o of Array.from(n.childNodes)){if(o.nodeType===1)for(let E of Array.from(o.querySelectorAll("script")))E.replaceWith(s(E));let i=u(o)?s(o):o;d(i)&&(i.async=!1);let b=d(i)?T(i):null;e.before(i),b&&await b}e.remove()}function m(){let t=c();for(let e of Array.from(r.querySelectorAll("template[data-inlay-consent]"))){let n=e.getAttribute("data-inlay-consent")??"";!h(n)||!t[n]||!e.parentNode||L(e)}}function f(t,e){let n=t==="all"?[...A]:t.filter(h),o={at:Date.now(),...c()};delete o.decided;for(let i of n)o[i]=e;l=o;try{a.localStorage.setItem(C,JSON.stringify(o))}catch{}m(),y()}function y(){r.dispatchEvent(new a.CustomEvent("inlay:consent",{detail:c()}))}let p=a;p.inlay={...p.inlay,consent:{grant:t=>f(t,!0),revoke:t=>f(t,!1),get:c}};let g=()=>{m(),y()};r.readyState==="loading"?r.addEventListener("DOMContentLoaded",g,{once:!0}):g()}v(window);})();
@@ -8,7 +8,7 @@ export declare const SETUP_PATH = "/admin/setup";
8
8
  /** Everything admin screens receive. */
9
9
  export type AdminContext = AdminRouteOptions;
10
10
  /** The part of the admin a page belongs to, for the navigation. */
11
- export type Section = 'dashboard' | 'pages' | 'globals' | `collection:${string}` | 'media' | 'redirects' | 'users' | 'backups' | 'releases' | 'security' | 'account';
11
+ export type Section = 'dashboard' | 'pages' | 'globals' | `collection:${string}` | 'media' | 'redirects' | 'users' | 'backups' | 'releases' | 'integrations' | 'security' | 'account';
12
12
  export type { FormValues };
13
13
  /** The notices a redirect may ask for with `?notice=<key>`, and the counts each may carry in the query. */
14
14
  export declare const NOTICES: Record<string, {
@@ -21,6 +21,7 @@ export const NOTICES = {
21
21
  siteLocked: { id: 'admin.notice.siteLocked' },
22
22
  siteUnlocked: { id: 'admin.notice.siteUnlocked' },
23
23
  sitePasswordSaved: { id: 'admin.notice.sitePasswordSaved' },
24
+ integrationSaved: { id: 'admin.notice.integrationSaved' },
24
25
  passwordChanged: { id: 'admin.notice.passwordChanged' },
25
26
  userAdded: { id: 'admin.notice.userAdded' },
26
27
  userUpdated: { id: 'admin.notice.userUpdated' },
@@ -36,6 +36,8 @@ export interface AdminRouteOptions {
36
36
  /** The site's database and the folder releases are kept in: with both, owners get the Releases screen. */
37
37
  db?: Kysely<Database>;
38
38
  releasesDir?: string;
39
+ /** The media folder, so deleting a release can sweep the variants of code images no release names any more. */
40
+ mediaDir?: string;
39
41
  /** The public keys an uploaded release must be signed with, when there is no `host` to check it. */
40
42
  trustedKeys?: readonly string[];
41
43
  }
@@ -8,6 +8,7 @@ import { adminActor, formOf, hostOf, HTML, notFound, registerScreens, SETUP_PATH
8
8
  import { badOriginPage, consentPage, loginPage, messagePage, setupPage } from './pages.js';
9
9
  import { registerPublishRoutes } from './publish.js';
10
10
  import { registerBackups } from './screens/backups.js';
11
+ import { registerIntegrations } from './screens/integrations.js';
11
12
  import { registerSecurity } from './screens/security.js';
12
13
  import { registerDashboard } from './screens/dashboard.js';
13
14
  import { registerEditor } from './screens/editor.js';
@@ -244,6 +245,7 @@ export function registerAdminRoutes(app, opts) {
244
245
  registerUsers(authed, opts);
245
246
  registerBackups(authed, opts);
246
247
  registerReleases(authed, opts);
248
+ registerIntegrations(authed, opts);
247
249
  registerSecurity(authed, opts);
248
250
  registerPublishRoutes(authed, opts);
249
251
  registerSearch(authed, opts);
@@ -7,7 +7,7 @@ import { basename, join } from 'node:path';
7
7
  import { pipeline } from 'node:stream/promises';
8
8
  import { InlayError } from '../../../core/errors.js';
9
9
  import { exportFileName } from '../../../core/export/format.js';
10
- import { siteLockLines } from '../../../core/export/report.js';
10
+ import { integrationLines, siteLockLines } from '../../../core/export/report.js';
11
11
  import { formatSize } from '../../../core/media/labels.js';
12
12
  import { t } from '../../../core/messages/index.js';
13
13
  import { adminActor, forbidden, HTML, noticeOf, notFound } from '../context.js';
@@ -98,7 +98,7 @@ export function registerBackups(scope, ctx) {
98
98
  },
99
99
  { key: 'documents', label: t('admin.import.documents'), cell: (row) => row.documents },
100
100
  { key: 'status', label: t('admin.import.status'), cell: (row) => t(`import.status.${row.status}`) },
101
- ] })] }), hiddenLocales.length > 0 && (_jsxs("section", { class: "flex flex-col gap-2", "aria-labelledby": "locales-heading", children: [_jsx("h2", { id: "locales-heading", class: "text-lg font-semibold", children: t('admin.import.locales') }), _jsx("ul", { class: "flex flex-col gap-2", children: hiddenLocales.map((row) => (_jsx("li", { children: t('import.localeLine', { locale: row.locale, status: t(`import.status.${row.status}`), documents: row.documents }) }))) })] })), report.general.length > 0 && (_jsxs("section", { class: "flex flex-col gap-2", "aria-labelledby": "general-heading", children: [_jsx("h2", { id: "general-heading", class: "text-lg font-semibold", children: t('admin.import.general') }), _jsx(Problems, { problems: report.general })] })), report.media.damaged.length > 0 && (_jsxs("section", { class: "flex flex-col gap-2", "aria-labelledby": "damaged-heading", children: [_jsx("h2", { id: "damaged-heading", class: "text-lg font-semibold", children: t('admin.import.damaged') }), _jsx("p", { children: t('import.damagedMedia', { count: report.media.damaged.length, names: report.media.damaged.join(', ') }) })] })), report.shipped.length > 0 && (_jsxs("section", { class: "flex flex-col gap-2", "aria-labelledby": "shipped-heading", children: [_jsx("h2", { id: "shipped-heading", class: "text-lg font-semibold", children: t('admin.import.shippedTitle') }), _jsx("ul", { class: "list-disc pl-6", children: report.shipped.map((title) => (_jsx("li", { children: title }))) })] })), siteLockLines(report.siteLock).length > 0 && (_jsxs("section", { class: "flex flex-col gap-2", "aria-labelledby": "site-lock-heading", children: [_jsx("h2", { id: "site-lock-heading", class: "text-lg font-semibold", children: t('admin.import.siteLockTitle') }), _jsx("ul", { class: "list-disc pl-6", children: siteLockLines(report.siteLock).map((line) => (_jsx("li", { children: line }))) })] })), report.ok ? (_jsxs("form", { method: "post", action: `/admin/backups/import/${token}`, class: "flex flex-col gap-4", children: [_jsx(Alert, { kind: "warning", id: "replace-warning", children: t('admin.import.replaceWarning') }), _jsxs("div", { class: "flex gap-4", children: [_jsx("button", { type: "submit", class: "btn btn-primary", children: t('admin.import.restore') }), _jsx("a", { href: "/admin/backups", class: "btn", children: t('admin.import.back') })] })] })) : (_jsxs("div", { class: "flex flex-col gap-4", children: [_jsx(Alert, { kind: "error", id: "cannot-restore", children: t('admin.import.cannotRestore') }), _jsx("div", { children: _jsx("a", { href: "/admin/backups", class: "btn", children: t('admin.import.back') }) })] }))] }));
101
+ ] })] }), hiddenLocales.length > 0 && (_jsxs("section", { class: "flex flex-col gap-2", "aria-labelledby": "locales-heading", children: [_jsx("h2", { id: "locales-heading", class: "text-lg font-semibold", children: t('admin.import.locales') }), _jsx("ul", { class: "flex flex-col gap-2", children: hiddenLocales.map((row) => (_jsx("li", { children: t('import.localeLine', { locale: row.locale, status: t(`import.status.${row.status}`), documents: row.documents }) }))) })] })), report.general.length > 0 && (_jsxs("section", { class: "flex flex-col gap-2", "aria-labelledby": "general-heading", children: [_jsx("h2", { id: "general-heading", class: "text-lg font-semibold", children: t('admin.import.general') }), _jsx(Problems, { problems: report.general })] })), report.media.damaged.length > 0 && (_jsxs("section", { class: "flex flex-col gap-2", "aria-labelledby": "damaged-heading", children: [_jsx("h2", { id: "damaged-heading", class: "text-lg font-semibold", children: t('admin.import.damaged') }), _jsx("p", { children: t('import.damagedMedia', { count: report.media.damaged.length, names: report.media.damaged.join(', ') }) })] })), report.shipped.length > 0 && (_jsxs("section", { class: "flex flex-col gap-2", "aria-labelledby": "shipped-heading", children: [_jsx("h2", { id: "shipped-heading", class: "text-lg font-semibold", children: t('admin.import.shippedTitle') }), _jsx("ul", { class: "list-disc pl-6", children: report.shipped.map((title) => (_jsx("li", { children: title }))) })] })), siteLockLines(report.siteLock).length > 0 && (_jsxs("section", { class: "flex flex-col gap-2", "aria-labelledby": "site-lock-heading", children: [_jsx("h2", { id: "site-lock-heading", class: "text-lg font-semibold", children: t('admin.import.siteLockTitle') }), _jsx("ul", { class: "list-disc pl-6", children: siteLockLines(report.siteLock).map((line) => (_jsx("li", { children: line }))) })] })), integrationLines(report).length > 0 && (_jsxs("section", { class: "flex flex-col gap-2", "aria-labelledby": "integrations-heading", children: [_jsx("h2", { id: "integrations-heading", class: "text-lg font-semibold", children: t('admin.import.integrationsTitle') }), _jsx("ul", { class: "list-disc pl-6", children: integrationLines(report).map((line) => (_jsx("li", { children: line }))) })] })), report.ok ? (_jsxs("form", { method: "post", action: `/admin/backups/import/${token}`, class: "flex flex-col gap-4", children: [_jsx(Alert, { kind: "warning", id: "replace-warning", children: t('admin.import.replaceWarning') }), _jsxs("div", { class: "flex gap-4", children: [_jsx("button", { type: "submit", class: "btn btn-primary", children: t('admin.import.restore') }), _jsx("a", { href: "/admin/backups", class: "btn", children: t('admin.import.back') })] })] })) : (_jsxs("div", { class: "flex flex-col gap-4", children: [_jsx(Alert, { kind: "error", id: "cannot-restore", children: t('admin.import.cannotRestore') }), _jsx("div", { children: _jsx("a", { href: "/admin/backups", class: "btn", children: t('admin.import.back') }) })] }))] }));
102
102
  const page = await adminPage(ctx, {
103
103
  title: t('admin.import.reportTitle'),
104
104
  actor,
@@ -3,6 +3,7 @@ import { normalizeContent } from '../../../core/content/schema.js';
3
3
  import { validateContent } from '../../../core/content/validate.js';
4
4
  import { InlayError } from '../../../core/errors.js';
5
5
  import { t } from '../../../core/messages/index.js';
6
+ import { designedInCode } from '../../../core/registry/designed.js';
6
7
  import { loadAgentRefs } from '../../mcp/agent-refs.js';
7
8
  import { previewLink } from '../../site/preview.js';
8
9
  import { adminActor, forbidden, formValues, HTML, noticeOf, notFound } from '../context.js';
@@ -112,7 +113,7 @@ export async function editorPage(ctx, actor, doc, state) {
112
113
  };
113
114
  const unplaced = state.unplaced ?? [];
114
115
  const actions = (_jsxs(_Fragment, { children: [_jsx("span", { id: "editor-status", "data-refresh": true, children: _jsx(StatusBadge, { doc: doc }) }), _jsx(LocaleSwitcher, { doc: doc, translations: translations, missing: (locale) => _jsx(TranslateButton, { id: doc.id, locale: locale }) }), _jsx(HeaderActions, { doc: doc, pane: pane !== null, ...(state.conflict && { conflictHead: state.conflict.head }) })] }));
115
- const body = (_jsxs(_Fragment, { children: [_jsxs("div", { id: "workspace", "data-view": "edit", class: pane ? 'grid min-h-0 flex-1 grid-cols-1 lg:grid-cols-[minmax(24rem,5fr)_7fr]' : 'grid min-h-0 flex-1 grid-cols-1', children: [_jsx("div", { id: "form-pane", class: "min-h-0 overflow-y-auto", children: _jsxs("form", { id: "editor-form", method: "post", action: action, "data-save-errors": (state.status ?? 200) >= 400, class: "mx-auto flex max-w-3xl flex-col gap-4 p-4 pb-24", children: [_jsx("button", { type: "submit", name: "_action", value: "save", class: "hidden", tabindex: "-1", "aria-hidden": "true" }), _jsx("input", { type: "hidden", name: "base", value: state.base }), state.review !== undefined && _jsx("div", { hidden: true, "data-publish-open": state.review }), state.unsaved === true && (_jsx("div", { role: "status", class: "alert alert-info", children: t('admin.editor.unsaved') })), state.conflict && (_jsx(Alert, { kind: "error", children: t('admin.editor.conflict', { name: state.conflict.name, source: sourceLabel(state.conflict.source) }) })), (state.error !== undefined || unplaced.length > 0) && (_jsx(Alert, { kind: "error", children: _jsxs("div", { children: [state.error !== undefined && _jsx("p", { children: state.error }), unplaced.length > 0 && (_jsx("ul", { class: "list-disc pl-6", children: unplaced.map((issue) => (_jsx("li", { children: issue.message }))) }))] }) })), gap && (_jsx(Alert, { kind: "warning", children: t('admin.gaps.editor', { count: gap.issues.length, labels: gap.issues.map((issue) => issue.labels.join(' → ')).join(', ') }) })), hints.unplaced.length > 0 && (_jsx(Alert, { kind: "warning", children: _jsxs("div", { children: [_jsx("p", { children: t('admin.editor.neededIntro') }), _jsx("ul", { class: "list-disc pl-6", children: hints.unplaced.map((issue) => (_jsx("li", { children: issue.message }))) })] }) })), _jsx(DocumentFields, { ctx: formCtx, data: state.data, ...(def.kind === 'collection' && { entry: { customPaths: def.customPaths } }) })] }) }), pane && _jsx(PreviewPane, { id: doc.id, live: pane })] }), pane && (_jsxs("button", { type: "button", id: "preview-show", hidden: true, class: "btn btn-sm fixed bottom-4 right-4 z-30 shadow-lg", children: [_jsx(Icon, { name: "eye" }), t('admin.preview.show')] }))] }));
116
+ const body = (_jsxs(_Fragment, { children: [_jsxs("div", { id: "workspace", "data-view": "edit", class: pane ? 'grid min-h-0 flex-1 grid-cols-1 lg:grid-cols-[minmax(24rem,5fr)_7fr]' : 'grid min-h-0 flex-1 grid-cols-1', children: [_jsx("div", { id: "form-pane", class: "min-h-0 overflow-y-auto", children: _jsxs("form", { id: "editor-form", method: "post", action: action, "data-save-errors": (state.status ?? 200) >= 400, class: "mx-auto flex max-w-3xl flex-col gap-4 p-4 pb-24", children: [_jsx("button", { type: "submit", name: "_action", value: "save", class: "hidden", tabindex: "-1", "aria-hidden": "true" }), _jsx("input", { type: "hidden", name: "base", value: state.base }), state.review !== undefined && _jsx("div", { hidden: true, "data-publish-open": state.review }), state.unsaved === true && (_jsx("div", { role: "status", class: "alert alert-info", children: t('admin.editor.unsaved') })), state.conflict && (_jsx(Alert, { kind: "error", children: t('admin.editor.conflict', { name: state.conflict.name, source: sourceLabel(state.conflict.source) }) })), (state.error !== undefined || unplaced.length > 0) && (_jsx(Alert, { kind: "error", children: _jsxs("div", { children: [state.error !== undefined && _jsx("p", { children: state.error }), unplaced.length > 0 && (_jsx("ul", { class: "list-disc pl-6", children: unplaced.map((issue) => (_jsx("li", { children: issue.message }))) }))] }) })), gap && (_jsx(Alert, { kind: "warning", children: t('admin.gaps.editor', { count: gap.issues.length, labels: gap.issues.map((issue) => issue.labels.join(' → ')).join(', ') }) })), hints.unplaced.length > 0 && (_jsx(Alert, { kind: "warning", children: _jsxs("div", { children: [_jsx("p", { children: t('admin.editor.neededIntro') }), _jsx("ul", { class: "list-disc pl-6", children: hints.unplaced.map((issue) => (_jsx("li", { children: issue.message }))) })] }) })), def.kind !== 'collection' && designedInCode(def.template) ? (_jsx("div", { role: "note", class: "alert alert-info", children: t('admin.editor.designedInCode') })) : (_jsx(DocumentFields, { ctx: formCtx, data: state.data, ...(def.kind === 'collection' && { entry: { customPaths: def.customPaths } }) }))] }) }), pane && _jsx(PreviewPane, { id: doc.id, live: pane })] }), pane && (_jsxs("button", { type: "button", id: "preview-show", hidden: true, class: "btn btn-sm fixed bottom-4 right-4 z-30 shadow-lg", children: [_jsx(Icon, { name: "eye" }), t('admin.preview.show')] }))] }));
116
117
  const { section, breadcrumbs } = placement(ctx, doc);
117
118
  return adminPage(ctx, {
118
119
  title: doc.title,
@@ -0,0 +1,4 @@
1
+ import type { FastifyInstance } from 'fastify';
2
+ import { type AdminContext } from '../context.js';
3
+ /** The owner's Integrations screen: switch on the scripts the site's code defines and fill in their details. */
4
+ export declare function registerIntegrations(scope: FastifyInstance, ctx: AdminContext): void;
@@ -0,0 +1,140 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "inlaycms/jsx-runtime";
2
+ import { InlayError } from '../../../core/errors.js';
3
+ import { fieldMeta } from '../../../core/fields/define.js';
4
+ import { t } from '../../../core/messages/index.js';
5
+ import { adminActor, forbidden, formValues, HTML, noticeOf, notFound } from '../context.js';
6
+ import { Alert, adminPage } from '../views/layout.js';
7
+ const NO_REFS = {
8
+ document: () => null,
9
+ media: () => ({ status: 'unknown' }),
10
+ mediaUrl: () => '',
11
+ };
12
+ const CATEGORY = {
13
+ analytics: 'admin.integrations.category.analytics',
14
+ marketing: 'admin.integrations.category.marketing',
15
+ functional: 'admin.integrations.category.functional',
16
+ };
17
+ const isOptional = (schema) => schema._zod.optin === 'optional';
18
+ const fieldsOf = (shape) => Object.entries(shape).flatMap(([key, schema]) => {
19
+ const meta = fieldMeta(schema);
20
+ return meta?.admin === undefined ? [] : [{ key, meta, widget: meta.admin, optional: isOptional(schema) }];
21
+ });
22
+ /** The validation issues of `e` by field key; anything else goes under `''`. */
23
+ function errorsOf(e, keys) {
24
+ const errors = {};
25
+ const issues = e.details.issues ?? [];
26
+ if (issues.length === 0)
27
+ (errors[''] ??= []).push(e.message);
28
+ for (const issue of issues) {
29
+ const at = issue.path[0];
30
+ const key = typeof at === 'string' && keys.includes(at) ? at : '';
31
+ (errors[key] ??= []).push(issue.message);
32
+ }
33
+ return errors;
34
+ }
35
+ function FieldRow(props) {
36
+ const { prefix, name, meta, widget, optional, value, errors } = props;
37
+ const id = `${prefix}-${name}`;
38
+ const ids = [];
39
+ if (meta.help !== undefined)
40
+ ids.push(`${id}-help`);
41
+ if (errors.length > 0)
42
+ ids.push(`${id}-problem`);
43
+ const control = widget.render({
44
+ name,
45
+ id,
46
+ value,
47
+ meta,
48
+ optional,
49
+ readOnly: false,
50
+ describedBy: ids.length > 0 ? ids.join(' ') : undefined,
51
+ invalid: errors.length > 0,
52
+ refs: NO_REFS,
53
+ locale: '',
54
+ });
55
+ const notes = (_jsxs(_Fragment, { children: [meta.help !== undefined && (_jsx("p", { id: `${id}-help`, class: "text-sm text-base-content/70", children: meta.help })), errors.length > 0 && (_jsx("ul", { id: `${id}-problem`, class: "text-sm text-error", children: errors.map((e) => (_jsx("li", { children: e }))) }))] }));
56
+ const mark = optional ? _jsx("span", { class: "ms-2 text-sm font-normal text-base-content/60", children: t('admin.form.optional') }) : null;
57
+ if (widget.fieldset === true) {
58
+ return (_jsxs("fieldset", { class: "fieldset", "aria-describedby": ids.length > 0 ? ids.join(' ') : undefined, children: [_jsxs("legend", { class: "fieldset-legend", children: [meta.label, mark] }), notes, control] }));
59
+ }
60
+ if (meta.kind === 'boolean') {
61
+ return (_jsxs("div", { class: "flex flex-col gap-1", children: [_jsxs("div", { class: "flex items-center gap-2", children: [control, _jsxs("label", { for: id, children: [meta.label, mark] })] }), notes] }));
62
+ }
63
+ return (_jsxs("div", { class: "flex flex-col gap-1", children: [_jsxs("label", { for: id, class: "text-sm font-medium", children: [meta.label, mark] }), control, notes] }));
64
+ }
65
+ function IntegrationForm({ state, posted }) {
66
+ const { def } = state;
67
+ const name = def.name;
68
+ const enabled = posted?.enabled ?? state.enabled;
69
+ const values = posted?.values ?? state.values;
70
+ const errors = posted?.errors ?? {};
71
+ const general = errors[''] ?? [];
72
+ const prefix = `integration-${name}`;
73
+ const unsafe = def.csp['script-src']?.includes("'unsafe-inline'") === true;
74
+ return (_jsx("form", { method: "post", action: `/admin/integrations/${name}`, class: "card bg-base-100 shadow-sm", "aria-labelledby": `${prefix}-title`, children: _jsxs("div", { class: "card-body flex flex-col gap-4", children: [_jsx("h2", { id: `${prefix}-title`, class: "card-title", children: def.label }), def.description !== undefined && _jsx("p", { children: def.description }), _jsxs("ul", { class: "list-none text-sm", children: [_jsx("li", { children: def.consent !== undefined ? t('admin.integrations.consent', { category: t(CATEGORY[def.consent]) }) : t('admin.integrations.always') }), def.preview && _jsx("li", { children: t('admin.integrations.preview') }), unsafe && _jsx("li", { children: t('admin.integrations.unsafeInline') })] }), posted === undefined && state.enabled && !state.active && (_jsx(Alert, { kind: "warning", id: `${prefix}-not-running`, children: t('admin.integrations.notRunning') })), general.length > 0 && (_jsx(Alert, { kind: "error", id: `${prefix}-error`, children: general.join(' ') })), _jsxs("div", { class: "flex items-center gap-3", children: [_jsx("input", { id: `${prefix}-enabled`, type: "checkbox", name: "enabled", value: "true", class: "toggle", checked: enabled }), _jsx("label", { for: `${prefix}-enabled`, children: t('admin.integrations.on') })] }), fieldsOf(def.fields.shape).map(({ key, meta, widget, optional }) => (_jsx(FieldRow, { prefix: prefix, name: key, meta: meta, widget: widget, optional: optional, value: values[key], errors: errors[key] ?? [] }))), _jsx("div", { class: "card-actions", children: _jsx("button", { type: "submit", class: "btn btn-primary", children: t('admin.integrations.save') }) })] }) }));
75
+ }
76
+ /** The owner's Integrations screen: switch on the scripts the site's code defines and fill in their details. */
77
+ export function registerIntegrations(scope, ctx) {
78
+ const { core } = ctx;
79
+ const asCtx = (request) => ({ actor: adminActor(request), source: 'admin' });
80
+ const defined = () => core.registry.site.integrations;
81
+ async function integrationsPage(request, reply, status = 200, posted) {
82
+ const actor = adminActor(request);
83
+ const states = await core.integrations(asCtx(request));
84
+ const notice = noticeOf(request.query);
85
+ const body = (_jsxs("div", { class: "flex flex-col gap-6", children: [_jsx(Alert, { kind: "info", children: t('admin.integrations.public') }), states.map((state) => (_jsx(IntegrationForm, { state: state, posted: posted?.name === state.def.name ? posted : undefined })))] }));
86
+ const page = await adminPage(ctx, {
87
+ title: t('admin.integrations.title'),
88
+ actor,
89
+ section: 'integrations',
90
+ status,
91
+ description: t('admin.integrations.description'),
92
+ ...(notice !== undefined && { notice }),
93
+ }, body);
94
+ return reply.code(status).type(HTML).send(page);
95
+ }
96
+ scope.get('/admin/integrations', async (request, reply) => {
97
+ const actor = adminActor(request);
98
+ if (actor.role !== 'owner')
99
+ return forbidden(reply, ctx, actor);
100
+ if (defined().length === 0)
101
+ return notFound(reply, ctx, actor);
102
+ return integrationsPage(request, reply);
103
+ });
104
+ scope.post('/admin/integrations/:name', async (request, reply) => {
105
+ const actor = adminActor(request);
106
+ if (actor.role !== 'owner')
107
+ return forbidden(reply, ctx, actor);
108
+ const { name } = request.params;
109
+ const def = defined().find((d) => d.name === name);
110
+ if (def === undefined)
111
+ return notFound(reply, ctx, actor);
112
+ const form = formValues(request);
113
+ const enabled = form.get('enabled') === 'true';
114
+ const fields = fieldsOf(def.fields.shape);
115
+ const values = {};
116
+ for (const { key, meta, widget, optional } of fields) {
117
+ const value = widget.parse(form, key, meta, optional);
118
+ if (value !== undefined)
119
+ values[key] = value;
120
+ }
121
+ try {
122
+ await core.saveIntegration(name, { enabled, values }, asCtx(request));
123
+ }
124
+ catch (e) {
125
+ if (!(e instanceof InlayError))
126
+ throw e;
127
+ if (e.code === 'not_found')
128
+ return notFound(reply, ctx, actor);
129
+ if (e.code !== 'validation')
130
+ throw e;
131
+ return integrationsPage(request, reply, 400, {
132
+ name,
133
+ enabled,
134
+ values,
135
+ errors: errorsOf(e, fields.map((x) => x.key)),
136
+ });
137
+ }
138
+ return reply.redirect('/admin/integrations?notice=integrationSaved', 303);
139
+ });
140
+ }
@@ -1,6 +1,7 @@
1
1
  import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "inlaycms/jsx-runtime";
2
2
  import { InlayError } from '../../../core/errors.js';
3
3
  import { t } from '../../../core/messages/index.js';
4
+ import { designedInCode } from '../../../core/registry/designed.js';
4
5
  import { singletonPath, withLocale } from '../../../core/site/paths.js';
5
6
  import { adminActor, forbidden, formValues, HTML, noticeOf, notFound } from '../context.js';
6
7
  import { backOf, idsOf } from '../publish.js';
@@ -82,7 +83,7 @@ export function registerLists(scope, ctx) {
82
83
  class: 'max-w-md',
83
84
  cell: (row) => {
84
85
  const doc = defaultDoc(row);
85
- return (_jsxs(_Fragment, { children: [doc ? (_jsx("a", { href: editorLink(doc), class: "link link-hover", children: row.def.label })) : (row.def.label), hasGap(row) && _jsx(GapBadge, {}), row.def.help !== undefined && (_jsx("div", { class: "truncate text-xs font-normal text-base-content/60", title: row.def.help, children: row.def.help }))] }));
86
+ return (_jsxs(_Fragment, { children: [doc ? (_jsx("a", { href: editorLink(doc), class: "link link-hover", children: row.def.label })) : (row.def.label), hasGap(row) && _jsx(GapBadge, {}), designedInCode(row.def.template) && (_jsx(Badge, { tone: "neutral", class: "ml-2", children: t('admin.list.designedInCode') })), row.def.help !== undefined && (_jsx("div", { class: "truncate text-xs font-normal text-base-content/60", title: row.def.help, children: row.def.help }))] }));
86
87
  },
87
88
  },
88
89
  ];
@@ -273,7 +273,7 @@ function releaseRoutes(scope, ctx, db, releasesDir) {
273
273
  if (row.state === 'deleted')
274
274
  return releasePage(request, reply, row, 409, t('admin.releases.alreadyDeleted', { name: row.name }));
275
275
  try {
276
- await deleteRelease({ db, releasesDir }, row.id);
276
+ await deleteRelease({ db, releasesDir, ...(ctx.mediaDir !== undefined && { mediaDir: ctx.mediaDir }) }, row.id);
277
277
  }
278
278
  catch (e) {
279
279
  if (e instanceof InlayError && e.messageId === 'error.releaseCurrent')
@@ -62,6 +62,9 @@ function navItems(ctx, actor, counts) {
62
62
  if (ctx.db !== undefined && ctx.releasesDir !== undefined) {
63
63
  siteItems.push({ section: 'releases', href: '/admin/releases', label: t('admin.nav.releases'), icon: 'rocket' });
64
64
  }
65
+ if (site.integrations.length > 0) {
66
+ siteItems.push({ section: 'integrations', href: '/admin/integrations', label: t('admin.nav.integrations'), icon: 'external' });
67
+ }
65
68
  siteItems.push({ section: 'security', href: '/admin/security', label: t('admin.nav.security'), icon: 'lock' });
66
69
  }
67
70
  const sections = [
@@ -1,7 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import { createInterface } from 'node:readline';
3
3
  import { Writable } from 'node:stream';
4
- import { runCli } from './main.js';
5
4
  async function readSecret(prompt) {
6
5
  if (process.stdin.isTTY) {
7
6
  let muted = false;
@@ -34,9 +33,15 @@ async function readSecret(prompt) {
34
33
  rl.close();
35
34
  }
36
35
  }
37
- process.exitCode = await runCli(process.argv.slice(2), {
36
+ const argv = process.argv.slice(2);
37
+ const io = {
38
38
  cwd: process.cwd(),
39
39
  out: console.log,
40
40
  err: console.error,
41
41
  readSecret,
42
- });
42
+ };
43
+ // `serve` skips main.js so the primary and every worker load only what serving needs, not the whole CLI.
44
+ process.exitCode =
45
+ argv.length === 1 && argv[0] === 'serve'
46
+ ? await (await import('../../host/serve.js')).serve([], io)
47
+ : await (await import('./main.js')).runCli(argv, io);
@@ -4,6 +4,7 @@ import { agentTypeSchema } from '../../../core/agent/schema.js';
4
4
  import { docLabels } from '../../../core/content/schema.js';
5
5
  import { InlayError } from '../../../core/errors.js';
6
6
  import { t } from '../../../core/messages/index.js';
7
+ import { designedInCode } from '../../../core/registry/designed.js';
7
8
  import { singletonPath, withLocale } from '../../../core/site/paths.js';
8
9
  import { previewLink } from '../../site/preview.js';
9
10
  import { loadAgentRefs, pageUrl } from '../agent-refs.js';
@@ -71,11 +72,24 @@ async function describeSite(deps) {
71
72
  if (path !== null)
72
73
  urls[locale] = pageUrl(baseUrl, withLocale(registry, locale, path));
73
74
  }
74
- singletons.push({ type: def.name, label: def.label, help: def.help ?? null, urls, documents: await documents(def.name) });
75
+ singletons.push({
76
+ type: def.name,
77
+ label: def.label,
78
+ help: def.help ?? null,
79
+ ...(designedInCode(def.template) && { designedInCode: true }),
80
+ urls,
81
+ documents: await documents(def.name),
82
+ });
75
83
  }
76
84
  const globals = [];
77
85
  for (const def of site.globals) {
78
- globals.push({ type: def.name, label: def.label, help: def.help ?? null, documents: await documents(def.name) });
86
+ globals.push({
87
+ type: def.name,
88
+ label: def.label,
89
+ help: def.help ?? null,
90
+ ...(designedInCode(def.template) && { designedInCode: true }),
91
+ documents: await documents(def.name),
92
+ });
79
93
  }
80
94
  const collections = [];
81
95
  for (const def of site.collections) {
@@ -113,6 +127,7 @@ async function describeType(deps, type) {
113
127
  label: def.label,
114
128
  help: def.help ?? null,
115
129
  ...(def.kind === 'collection' && { titleField: def.titleField }),
130
+ ...(def.kind !== 'collection' && designedInCode(def.template) && { designedInCode: true, note: t('mcp.designedInCode') }),
116
131
  slots: Object.entries(def.template.slots).map(([key, slot]) => ({
117
132
  key,
118
133
  label: slot.label ?? slot.block.label,
@@ -7,6 +7,7 @@ import { contentIssue, mergeIssues, validateContent } from '../../../core/conten
7
7
  import { InlayError } from '../../../core/errors.js';
8
8
  import { defOf, unwrap } from '../../../core/fields/zod-internals.js';
9
9
  import { t } from '../../../core/messages/index.js';
10
+ import { designedInCode } from '../../../core/registry/designed.js';
10
11
  import { previewLink } from '../../site/preview.js';
11
12
  import { pageUrl } from '../agent-refs.js';
12
13
  import { DESTRUCTIVE, documentOf, EDIT, livePath, READ_ONLY } from '../documents.js';
@@ -178,6 +179,9 @@ function toOps(deps, type, changes) {
178
179
  */
179
180
  async function updateDocument(deps, args, ctx) {
180
181
  const doc = await documentOf(deps, args.id);
182
+ const def = deps.core.registry.getType(doc.type);
183
+ if (def.kind !== 'collection' && designedInCode(def.template))
184
+ throw new InlayError('invalid_operation', 'mcp.designedInCode');
181
185
  const { ops, issues } = toOps(deps, doc.type, args.changes);
182
186
  issues.push(...(await groupIdIssues(deps, doc.type, opsAsData(ops))));
183
187
  if (issues.length > 0)
@@ -3,9 +3,14 @@ export type CachedResponse = {
3
3
  body: string;
4
4
  type: string;
5
5
  etag: string;
6
+ /** The page's own content-security-policy, with the hashes of its inline scripts. */
7
+ csp?: string;
6
8
  };
7
- /** A response with a strong ETag over its status and body, so unchanged pages revalidate with a 304. */
8
- export declare function response(status: number, body: string, type: string): CachedResponse;
9
+ /**
10
+ * A response with a strong ETag over its status, body and `csp`, so unchanged pages revalidate with a 304 and a page
11
+ * whose policy changed does not.
12
+ */
13
+ export declare function response(status: number, body: string, type: string, csp?: string): CachedResponse;
9
14
  /** True if `header` (an `If-None-Match` value) names `etag`, comparing weakly. */
10
15
  export declare function etagMatches(header: string | undefined, etag: string): boolean;
11
16
  export interface CdnOptions {
@@ -22,6 +27,7 @@ export declare class PageCache {
22
27
  readonly maxEntries: number;
23
28
  /** `changedElsewhere`: asked on every lookup; true empties the cache first (a write the site's own core didn't make). */
24
29
  constructor(maxEntries: number, changedElsewhere?: () => boolean);
30
+ /** Bumped by every `clear`, including the one a change made elsewhere causes, which reading it notices. */
25
31
  get generation(): number;
26
32
  get size(): number;
27
33
  get(key: string): CachedResponse | undefined;
@@ -1,8 +1,14 @@
1
1
  import { createHash } from 'node:crypto';
2
- /** A response with a strong ETag over its status and body, so unchanged pages revalidate with a 304. */
3
- export function response(status, body, type) {
4
- const hash = createHash('sha256').update(`${status}\n`).update(body).digest('hex').slice(0, 32);
5
- return { status, body, type, etag: `"${hash}"` };
2
+ /**
3
+ * A response with a strong ETag over its status, body and `csp`, so unchanged pages revalidate with a 304 and a page
4
+ * whose policy changed does not.
5
+ */
6
+ export function response(status, body, type, csp) {
7
+ const hash = createHash('sha256').update(`${status}\n`);
8
+ if (csp !== undefined)
9
+ hash.update(`${csp}\n`);
10
+ const etag = `"${hash.update(body).digest('hex').slice(0, 32)}"`;
11
+ return { status, body, type, etag, ...(csp !== undefined && { csp }) };
6
12
  }
7
13
  /** True if `header` (an `If-None-Match` value) names `etag`, comparing weakly. */
8
14
  export function etagMatches(header, etag) {
@@ -33,7 +39,10 @@ export class PageCache {
33
39
  this.maxEntries = maxEntries;
34
40
  this.#changedElsewhere = changedElsewhere;
35
41
  }
42
+ /** Bumped by every `clear`, including the one a change made elsewhere causes, which reading it notices. */
36
43
  get generation() {
44
+ if (this.#changedElsewhere())
45
+ this.clear();
37
46
  return this.#generation;
38
47
  }
39
48
  get size() {
@@ -0,0 +1,44 @@
1
+ import type { FastifyInstance } from 'fastify';
2
+ import type { Core } from '../../core/core.js';
3
+ import type { CodeImage } from '../../core/registry/code-image.js';
4
+ export interface CodeFile {
5
+ sha: string;
6
+ ext: string;
7
+ mime: string;
8
+ path: string;
9
+ url: string;
10
+ /** The displayed size (after EXIF rotation), known once the file has been read or registered from an import. */
11
+ width: number | null;
12
+ height: number | null;
13
+ }
14
+ export interface CodeFiles {
15
+ /**
16
+ * The file an image target in a site's code (a `file:` URL) names, or null when it isn't a usable image: one whose extension
17
+ * is in `MARKDOWN_IMAGE_TYPES` and whose bytes are of that type (so never SVG).
18
+ */
19
+ lookup(src: string): Promise<CodeFile | null>;
20
+ /** A known file by its `<sha><ext>` name. */
21
+ get(name: string): CodeFile | undefined;
22
+ /** A known file by its sha256. */
23
+ bySha(sha: string): CodeFile | undefined;
24
+ /**
25
+ * The file an imported image names. From source, one inside the site folder whose bytes match its sha and type,
26
+ * checked once per source and remembered; from a release, only one the release ships. Null otherwise.
27
+ */
28
+ register(image: CodeImage): CodeFile | null;
29
+ }
30
+ /**
31
+ * The image files site code names (Markdown in templates, or imports). A release lists them up front (`releaseFiles`, source URL to the file
32
+ * in the release); from source they are read from the site folder, hashed, and known from then on.
33
+ */
34
+ export declare function createCodeFiles(opts: {
35
+ siteDir: string | null;
36
+ releaseFiles?: ReadonlyMap<string, string>;
37
+ }): CodeFiles;
38
+ /** The one index of `core`'s images named by site code, so every render path and the image route share it. */
39
+ export declare function codeFilesFor(core: Core): CodeFiles;
40
+ /**
41
+ * Serves the known files at `/media/files/:name`, and their resized variants at `/media/files/:sha/:width.:format`,
42
+ * GET and HEAD, never anything but a file in the index.
43
+ */
44
+ export declare function registerCodeFileRoutes(app: FastifyInstance, files: CodeFiles, core: Core): void;