@velocity-astro/cms-astro 0.1.0-beta.1 → 0.1.0-beta.12

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 (137) hide show
  1. package/agents/cms.md +145 -0
  2. package/agents/skills/cms-add-content-type/SKILL.md +81 -0
  3. package/agents/skills/cms-add-form/SKILL.md +85 -0
  4. package/agents/skills/cms-add-section/SKILL.md +97 -0
  5. package/agents/skills/cms-add-to-site/SKILL.md +57 -0
  6. package/agents/skills/cms-connect-page/SKILL.md +64 -0
  7. package/agents/skills/cms-deploy/SKILL.md +64 -0
  8. package/agents/skills/cms-import-content/SKILL.md +63 -0
  9. package/agents/skills/cms-set-up-crm/SKILL.md +53 -0
  10. package/agents/skills/cms-write-plugin/SKILL.md +81 -0
  11. package/dist/admin-files.d.ts +2 -2
  12. package/dist/admin-files.d.ts.map +1 -1
  13. package/dist/admin-files.js +13 -7
  14. package/dist/admin-files.js.map +1 -1
  15. package/dist/agent-files.d.ts +23 -0
  16. package/dist/agent-files.d.ts.map +1 -0
  17. package/dist/agent-files.js +84 -0
  18. package/dist/agent-files.js.map +1 -0
  19. package/dist/challenge.d.ts +35 -0
  20. package/dist/challenge.d.ts.map +1 -0
  21. package/dist/challenge.js +84 -0
  22. package/dist/challenge.js.map +1 -0
  23. package/dist/check.d.ts +38 -0
  24. package/dist/check.d.ts.map +1 -0
  25. package/dist/check.js +194 -0
  26. package/dist/check.js.map +1 -0
  27. package/dist/cli-content.d.ts +22 -0
  28. package/dist/cli-content.d.ts.map +1 -0
  29. package/dist/cli-content.js +309 -0
  30. package/dist/cli-content.js.map +1 -0
  31. package/dist/cli.d.ts +3 -0
  32. package/dist/cli.d.ts.map +1 -1
  33. package/dist/cli.js +130 -6
  34. package/dist/cli.js.map +1 -1
  35. package/dist/connection.d.ts +1 -0
  36. package/dist/connection.d.ts.map +1 -1
  37. package/dist/connection.js +31 -6
  38. package/dist/connection.js.map +1 -1
  39. package/dist/editor.d.ts +2 -0
  40. package/dist/editor.d.ts.map +1 -1
  41. package/dist/editor.js +10 -1
  42. package/dist/editor.js.map +1 -1
  43. package/dist/form-post.d.ts +9 -1
  44. package/dist/form-post.d.ts.map +1 -1
  45. package/dist/form-post.js +10 -3
  46. package/dist/form-post.js.map +1 -1
  47. package/dist/hosted.d.ts +76 -0
  48. package/dist/hosted.d.ts.map +1 -0
  49. package/dist/hosted.js +104 -0
  50. package/dist/hosted.js.map +1 -0
  51. package/dist/image-optimizer.d.ts +35 -0
  52. package/dist/image-optimizer.d.ts.map +1 -0
  53. package/dist/image-optimizer.js +76 -0
  54. package/dist/image-optimizer.js.map +1 -0
  55. package/dist/import-files.d.ts +30 -0
  56. package/dist/import-files.d.ts.map +1 -0
  57. package/dist/import-files.js +100 -0
  58. package/dist/import-files.js.map +1 -0
  59. package/dist/index.d.ts +12 -3
  60. package/dist/index.d.ts.map +1 -1
  61. package/dist/index.js +12 -3
  62. package/dist/index.js.map +1 -1
  63. package/dist/init.d.ts +2 -0
  64. package/dist/init.d.ts.map +1 -1
  65. package/dist/init.js +16 -1
  66. package/dist/init.js.map +1 -1
  67. package/dist/integration.d.ts +9 -0
  68. package/dist/integration.d.ts.map +1 -1
  69. package/dist/integration.js +15 -1
  70. package/dist/integration.js.map +1 -1
  71. package/dist/link.d.ts.map +1 -1
  72. package/dist/link.js +6 -2
  73. package/dist/link.js.map +1 -1
  74. package/dist/live-loader.d.ts +7 -3
  75. package/dist/live-loader.d.ts.map +1 -1
  76. package/dist/live-loader.js +12 -6
  77. package/dist/live-loader.js.map +1 -1
  78. package/dist/media-store.d.ts +15 -0
  79. package/dist/media-store.d.ts.map +1 -1
  80. package/dist/media-store.js +26 -2
  81. package/dist/media-store.js.map +1 -1
  82. package/dist/page-marks.d.ts +50 -0
  83. package/dist/page-marks.d.ts.map +1 -0
  84. package/dist/page-marks.js +90 -0
  85. package/dist/page-marks.js.map +1 -0
  86. package/dist/preview.d.ts +34 -2
  87. package/dist/preview.d.ts.map +1 -1
  88. package/dist/preview.js +81 -15
  89. package/dist/preview.js.map +1 -1
  90. package/dist/resend-mailer.d.ts +18 -1
  91. package/dist/resend-mailer.d.ts.map +1 -1
  92. package/dist/resend-mailer.js +24 -3
  93. package/dist/resend-mailer.js.map +1 -1
  94. package/dist/secret.d.ts +1 -1
  95. package/dist/secret.d.ts.map +1 -1
  96. package/dist/secret.js +3 -2
  97. package/dist/secret.js.map +1 -1
  98. package/dist/single.d.ts +18 -0
  99. package/dist/single.d.ts.map +1 -0
  100. package/dist/single.js +37 -0
  101. package/dist/single.js.map +1 -0
  102. package/dist/site-client.d.ts +37 -0
  103. package/dist/site-client.d.ts.map +1 -0
  104. package/dist/site-client.js +73 -0
  105. package/dist/site-client.js.map +1 -0
  106. package/dist/site-editor.d.ts +1 -1
  107. package/dist/site-editor.d.ts.map +1 -1
  108. package/dist/site-editor.js +36 -6
  109. package/dist/site-editor.js.map +1 -1
  110. package/dist/site-forms.d.ts +11 -0
  111. package/dist/site-forms.d.ts.map +1 -1
  112. package/dist/site-forms.js +37 -19
  113. package/dist/site-forms.js.map +1 -1
  114. package/dist/site-mail.d.ts +45 -0
  115. package/dist/site-mail.d.ts.map +1 -0
  116. package/dist/site-mail.js +84 -0
  117. package/dist/site-mail.js.map +1 -0
  118. package/dist/site-media.d.ts +5 -1
  119. package/dist/site-media.d.ts.map +1 -1
  120. package/dist/site-media.js +14 -5
  121. package/dist/site-media.js.map +1 -1
  122. package/dist/site-name.d.ts +9 -0
  123. package/dist/site-name.d.ts.map +1 -0
  124. package/dist/site-name.js +21 -0
  125. package/dist/site-name.js.map +1 -0
  126. package/dist/site-storage.d.ts +34 -0
  127. package/dist/site-storage.d.ts.map +1 -0
  128. package/dist/site-storage.js +118 -0
  129. package/dist/site-storage.js.map +1 -0
  130. package/package.json +12 -8
  131. package/routes/editor.ts +7 -6
  132. package/routes/form-client.js.ts +68 -0
  133. package/routes/media.ts +2 -2
  134. package/routes/preview-client.js.ts +11 -56
  135. package/routes/published.ts +2 -2
  136. package/routes/sitemap-live.xml.ts +4 -1
  137. package/routes/sites.ts +11 -0
package/dist/preview.d.ts CHANGED
@@ -10,6 +10,15 @@ export interface PreviewDraft {
10
10
  readonly id: string;
11
11
  /** The entry's values as the form holds them, by field id. */
12
12
  readonly data: EntryData;
13
+ /**
14
+ * Other entries tried along with it and not saved either: the site's settings, when their
15
+ * colours are being chosen beside the page. Each is shown in place of the saved entry, as the
16
+ * draft itself is.
17
+ */
18
+ readonly with?: readonly {
19
+ readonly id: string;
20
+ readonly data: EntryData;
21
+ }[];
13
22
  }
14
23
  /** True while the page being rendered is a preview: the loaders then read the versions being worked on. */
15
24
  export declare const isPreview: () => boolean;
@@ -24,6 +33,13 @@ export declare function withPreviewDraft<T extends {
24
33
  readonly id: string;
25
34
  readonly data: EntryData;
26
35
  }>(entry: T): T;
36
+ /**
37
+ * Notes where a link to an entry leads on the page beside the editor's form, so that page can
38
+ * find the button that goes there and offer to change it. Nothing is noted for a visitor's page.
39
+ */
40
+ export declare function noteLinkLeads(type: string, entry: string, href: string): void;
41
+ /** What `noteLinkLeads` was told for the page being drawn: the address by `<type>:<entry>`. */
42
+ export declare const linkLeads: () => Readonly<Record<string, string>>;
27
43
  /** Runs `work` as a preview, for tests and for anything that draws a page outside a request. */
28
44
  export declare const asPreview: <T>(work: () => T, draft?: PreviewDraft) => T;
29
45
  /** The form field the editor sends a draft in. */
@@ -36,8 +52,24 @@ export declare const DRAFT_FIELD = "draft";
36
52
  export declare function readPreviewDraft(request: Request, site: URL): Promise<PreviewDraft | null>;
37
53
  /** The address of the script the page beside the editor's form runs. */
38
54
  export declare const EDITOR_PREVIEW_SCRIPT = "/cms-preview.js";
39
- /** Adds the script that lets a click on the page find its section in the form. It comes from the site itself, so the page's own rules allow it. */
40
- export declare function addEditorScript(html: string): string;
55
+ /**
56
+ * Which script this version of the CMS sends, as a mark in its address. A page is drawn again
57
+ * with every change in the form, and a browser that kept the script runs it before the page is
58
+ * seen, so the page comes back where it was with no jump. The mark changes with the script, so
59
+ * a copy from before an upgrade is never run.
60
+ */
61
+ export declare const EDITOR_PREVIEW_VERSION: string;
62
+ /**
63
+ * Adds the script that lets a click on the page find its section in the form. It comes from the
64
+ * site itself, so the page's own rules allow it. Where the page's links to entries lead goes
65
+ * with it as data, which no browser runs.
66
+ *
67
+ * The page is drawn again with every change in the form, and must be seen only once it is back
68
+ * where it was. So the script is the last thing in the page and runs as soon as it is read, and
69
+ * the head asks the browser to show nothing before that (`rel="expect"`, which a browser that
70
+ * does not know it passes over).
71
+ */
72
+ export declare function addEditorScript(html: string, leads?: Readonly<Record<string, string>>): string;
41
73
  /**
42
74
  * Adds the token to every link that stays on the site, so the person can click around and stay
43
75
  * in the preview. A token is digits, a dot and hex, so it needs no escaping.
@@ -1 +1 @@
1
- {"version":3,"file":"preview.d.ts","sourceRoot":"","sources":["../src/preview.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAC/C,OAAO,EAAmC,KAAK,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAM3F;;;;GAIG;AACH,MAAM,WAAW,YAAY;IAC3B,2BAA2B;IAC3B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,8DAA8D;IAC9D,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;CAC1B;AAQD,2GAA2G;AAC3G,eAAO,MAAM,SAAS,QAAO,OAA8C,CAAC;AAE5E,iIAAiI;AACjI,eAAO,MAAM,eAAe,QAAO,OAAqD,CAAC;AAEzF;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,SAAS;IAAE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAA;CAAE,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,CAGzG;AAED,gGAAgG;AAChG,eAAO,MAAM,SAAS,GAAI,CAAC,EAAE,MAAM,MAAM,CAAC,EAA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jB,CAAC;AAE1E;;;;;;;;;;GAUG;AACH,eAAO,MAAM,SAAS,EAAE,iBAkCvB,CAAC"}
package/dist/preview.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { AsyncLocalStorage } from 'node:async_hooks';
2
+ import { PREVIEW_BRIDGE_SCRIPT } from '@velocity-astro/cms-admin/page-bridge';
2
3
  import { PREVIEW_PARAMETER, PreviewLinks } from '@velocity-astro/cms-core';
3
4
  import { siteSecret } from './secret.js';
4
5
  import { refreshUploadedImages } from './site-media.js';
@@ -15,12 +16,29 @@ export const isEditorPreview = () => previewing.getStore()?.draft !== undefined;
15
16
  */
16
17
  export function withPreviewDraft(entry) {
17
18
  const draft = previewing.getStore()?.draft;
18
- return draft && draft.id === entry.id ? { ...entry, data: draft.data } : entry;
19
+ if (!draft)
20
+ return entry;
21
+ if (draft.id === entry.id)
22
+ return { ...entry, data: draft.data };
23
+ const beside = draft.with?.find((other) => other.id === entry.id);
24
+ return beside ? { ...entry, data: beside.data } : entry;
19
25
  }
26
+ /**
27
+ * Notes where a link to an entry leads on the page beside the editor's form, so that page can
28
+ * find the button that goes there and offer to change it. Nothing is noted for a visitor's page.
29
+ */
30
+ export function noteLinkLeads(type, entry, href) {
31
+ previewing.getStore()?.leads?.set(`${type}:${entry}`, href);
32
+ }
33
+ /** What `noteLinkLeads` was told for the page being drawn: the address by `<type>:<entry>`. */
34
+ export const linkLeads = () => Object.fromEntries(previewing.getStore()?.leads ?? []);
35
+ const started = (draft) => (draft ? { draft, leads: new Map() } : {});
20
36
  /** Runs `work` as a preview, for tests and for anything that draws a page outside a request. */
21
- export const asPreview = (work, draft) => previewing.run(draft ? { draft } : {}, work);
37
+ export const asPreview = (work, draft) => previewing.run(started(draft), work);
22
38
  /** The most a draft sent with a preview may weigh. A page's sections are text; a megabyte is a very long page. */
23
39
  const DRAFT_LIMIT = 1_000_000;
40
+ /** The most other entries a draft may bring with it. */
41
+ const WITH_LIMIT = 4;
24
42
  /** The form field the editor sends a draft in. */
25
43
  export const DRAFT_FIELD = 'draft';
26
44
  const isRecord = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
@@ -47,7 +65,18 @@ export async function readPreviewDraft(request, site) {
47
65
  const sent = JSON.parse(new URLSearchParams(body).get(DRAFT_FIELD) ?? '');
48
66
  if (!isRecord(sent) || typeof sent['id'] !== 'string' || sent['id'] === '' || !isRecord(sent['data']))
49
67
  return null;
50
- return { id: sent['id'], data: sent['data'] };
68
+ const beside = sent['with'];
69
+ if (beside === undefined)
70
+ return { id: sent['id'], data: sent['data'] };
71
+ if (!Array.isArray(beside) || beside.length > WITH_LIMIT)
72
+ return null;
73
+ const others = [];
74
+ for (const other of beside) {
75
+ if (!isRecord(other) || typeof other['id'] !== 'string' || other['id'] === '' || !isRecord(other['data']))
76
+ return null;
77
+ others.push({ id: other['id'], data: other['data'] });
78
+ }
79
+ return { id: sent['id'], data: sent['data'], with: others };
51
80
  }
52
81
  catch {
53
82
  return null;
@@ -55,19 +84,52 @@ export async function readPreviewDraft(request, site) {
55
84
  }
56
85
  /** The address of the script the page beside the editor's form runs. */
57
86
  export const EDITOR_PREVIEW_SCRIPT = '/cms-preview.js';
58
- /** Adds the script that lets a click on the page find its section in the form. It comes from the site itself, so the page's own rules allow it. */
59
- export function addEditorScript(html) {
60
- const tag = `<script type="module" src="${EDITOR_PREVIEW_SCRIPT}"></script>`;
87
+ /** A few letters that change whenever the script does. */
88
+ function mark(text) {
89
+ let sum = 5381;
90
+ for (let at = 0; at < text.length; at++)
91
+ sum = (Math.imul(sum, 33) ^ text.charCodeAt(at)) >>> 0;
92
+ return sum.toString(36);
93
+ }
94
+ /**
95
+ * Which script this version of the CMS sends, as a mark in its address. A page is drawn again
96
+ * with every change in the form, and a browser that kept the script runs it before the page is
97
+ * seen, so the page comes back where it was with no jump. The mark changes with the script, so
98
+ * a copy from before an upgrade is never run.
99
+ */
100
+ export const EDITOR_PREVIEW_VERSION = mark(PREVIEW_BRIDGE_SCRIPT);
101
+ /**
102
+ * Adds the script that lets a click on the page find its section in the form. It comes from the
103
+ * site itself, so the page's own rules allow it. Where the page's links to entries lead goes
104
+ * with it as data, which no browser runs.
105
+ *
106
+ * The page is drawn again with every change in the form, and must be seen only once it is back
107
+ * where it was. So the script is the last thing in the page and runs as soon as it is read, and
108
+ * the head asks the browser to show nothing before that (`rel="expect"`, which a browser that
109
+ * does not know it passes over).
110
+ */
111
+ export function addEditorScript(html, leads = {}) {
112
+ const said = Object.keys(leads).length > 0 ? `<script type="application/json" data-cms-links>${JSON.stringify(leads).replace(/</g, '\\u003c')}</script>` : '';
113
+ const tag = `${said}<script id="${EDITOR_SCRIPT_ID}" src="${EDITOR_PREVIEW_SCRIPT}?v=${EDITOR_PREVIEW_VERSION}"></script>`;
61
114
  const end = html.lastIndexOf('</body>');
62
- return end === -1 ? html + tag : html.slice(0, end) + tag + html.slice(end);
115
+ const whole = end === -1 ? html + tag : html.slice(0, end) + tag + html.slice(end);
116
+ const head = /<head(\s[^>]*)?>/i.exec(whole);
117
+ if (!head)
118
+ return whole;
119
+ const at = head.index + head[0].length;
120
+ return `${whole.slice(0, at)}<link rel="expect" href="#${EDITOR_SCRIPT_ID}" blocking="render">${whole.slice(at)}`;
63
121
  }
64
- let links;
122
+ const EDITOR_SCRIPT_ID = 'cms-preview-script';
123
+ /** A signer per secret, so a preview link made for one site is no link at all on another. */
124
+ const links = new Map();
65
125
  function previewLinks() {
66
- if (links === undefined) {
67
- const secret = siteSecret();
68
- links = secret ? new PreviewLinks(secret) : null;
69
- }
70
- return links;
126
+ const secret = siteSecret();
127
+ if (!secret)
128
+ return null;
129
+ let signer = links.get(secret);
130
+ if (!signer)
131
+ links.set(secret, (signer = new PreviewLinks(secret)));
132
+ return signer;
71
133
  }
72
134
  /**
73
135
  * Adds the token to every link that stays on the site, so the person can click around and stay
@@ -91,6 +153,10 @@ export const showsContent = (request, pathname, isPrerendered) => !isPrerendered
91
153
  * exactly as if this middleware were not there.
92
154
  */
93
155
  export const onRequest = async (context, next) => {
156
+ // A page built ahead of time is the same for everyone, so it is never a preview. On a server
157
+ // that runs many sites it is also built for no site, and has no secret to check a token with.
158
+ if (context.isPrerendered)
159
+ return next();
94
160
  if (showsContent(context.request, context.url.pathname, context.isPrerendered)) {
95
161
  // A page without its newest images is still a page, so a failure here is only logged.
96
162
  await refreshUploadedImages().catch((error) => console.error('[velocity-cms] Uploaded images were not read.', error));
@@ -110,7 +176,7 @@ export const onRequest = async (context, next) => {
110
176
  draft = sent;
111
177
  }
112
178
  // The page is read to the end inside the preview, because Astro renders as the response is read.
113
- return previewing.run(draft ? { draft } : {}, async () => {
179
+ return previewing.run(started(draft), async () => {
114
180
  const response = await next();
115
181
  const headers = new Headers(response.headers);
116
182
  headers.set('Cache-Control', 'private, no-store');
@@ -119,7 +185,7 @@ export const onRequest = async (context, next) => {
119
185
  headers.delete('Content-Length');
120
186
  const isHtml = headers.get('Content-Type')?.includes('text/html') === true;
121
187
  const page = isHtml ? keepPreviewInLinks(await response.text(), token) : null;
122
- const body = page === null ? await response.arrayBuffer() : draft ? addEditorScript(page) : page;
188
+ const body = page === null ? await response.arrayBuffer() : draft ? addEditorScript(page, linkLeads()) : page;
123
189
  return new Response(body, { status: response.status, statusText: response.statusText, headers });
124
190
  });
125
191
  };
@@ -1 +1 @@
1
- {"version":3,"file":"preview.js","sourceRoot":"","sources":["../src/preview.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAErD,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAkB,MAAM,0BAA0B,CAAC;AAC3F,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAExD,MAAM,SAAS,GAAG,iBAAiB,CAAC;AAkBpC,MAAM,UAAU,GAAG,IAAI,iBAAiB,EAAW,CAAC;AAEpD,2GAA2G;AAC3G,MAAM,CAAC,MAAM,SAAS,GAAG,GAA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AI,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QAC9C,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,mBAAmB,CAAC,CAAC;QAClD,OAAO,CAAC,GAAG,CAAC,cAAc,EAAE,SAAS,CAAC,CAAC;QACvC,OAAO,CAAC,GAAG,CAAC,iBAAiB,EAAE,aAAa,CAAC,CAAC;QAC9C,OAAO,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC;QACjC,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,EAAE,QAAQ,CAAC,WAAW,CAAC,KAAK,IAAI,CAAC;QAC3E,MAAM,IAAI,GAAG,MAAM,CAAC,CAAC,CAAC,kBAAkB,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QAC9E,MAAM,IAAI,GAAG,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,MAAM,QAAQ,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,eAAe,CAAC,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QAC9G,OAAO,IAAI,QAAQ,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,QAAQ,CAAC,MAAM,EAAE,UAAU,EAAE,QAAQ,CAAC,UAAU,EAAE,OAAO,EAAE,CAAC,CAAC;IACnG,CAAC,CAAC,CAAC;AACL,CAAC,CAAC"}
@@ -16,6 +16,10 @@ export interface MailWords {
16
16
  readonly noticeIntro?: (formName: string, siteName: string) => string;
17
17
  readonly noticeSentFrom?: string;
18
18
  readonly noticeReply?: string;
19
+ /** The email an owner asks for to see that the settings work. Left out, these are in English. */
20
+ readonly testSubject?: (siteName: string) => string;
21
+ readonly testGreeting?: (name: string) => string;
22
+ readonly testBody?: (siteName: string) => string;
19
23
  }
20
24
  export declare const englishMailWords: MailWords;
21
25
  export interface ResendMailerOptions {
@@ -27,6 +31,17 @@ export interface ResendMailerOptions {
27
31
  /** Defaults to the platform's own `fetch`. */
28
32
  readonly fetch?: typeof globalThis.fetch;
29
33
  }
34
+ /** A test email to send: to the person who asked for it. */
35
+ export interface TestMail {
36
+ readonly email: string;
37
+ readonly name: string;
38
+ readonly siteName: string;
39
+ }
40
+ /** The provider answered and refused. `status` is its answer; the message holds its own words, for the server's log. */
41
+ export declare class MailRefusedError extends Error {
42
+ readonly status: number;
43
+ constructor(status: number, detail: string);
44
+ }
30
45
  /**
31
46
  * Sends the CMS's emails through Resend, over plain HTTP: no SDK, so it runs wherever the site
32
47
  * does. A site that uses another provider writes its own `Mailer` the same way.
@@ -36,11 +51,13 @@ export declare class ResendMailer implements Mailer, NoticeMailer {
36
51
  constructor(options: ResendMailerOptions);
37
52
  sendSignInLink(mail: SignInMail): Promise<void>;
38
53
  sendInvitation(mail: InvitationMail): Promise<void>;
54
+ /** One email that says the settings work. It carries no link and no secret. */
55
+ sendTest(mail: TestMail): Promise<void>;
39
56
  sendSubmissionNotice(mail: SubmissionNotice): Promise<void>;
40
57
  }
41
58
  /**
42
59
  * The mailer a site gets from its settings alone: Resend when `VELOCITY_CMS_RESEND_API_KEY` and
43
60
  * `VELOCITY_CMS_EMAIL_FROM` are both set, otherwise none.
44
61
  */
45
- export declare function mailerFromEnv(env?: Readonly<Record<string, string | undefined>>): ResendMailer | undefined;
62
+ export declare function mailerFromEnv(env?: Readonly<Record<string, string | undefined>>, fetch?: typeof globalThis.fetch): ResendMailer | undefined;
46
63
  //# sourceMappingURL=resend-mailer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"resend-mailer.d.ts","sourceRoot":"","sources":["../src/resend-mailer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACnF,OAAO,KAAK,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAErE,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AQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC3B;AAED,wHAAwH;AACxH,qBAAa,gBAAiB,SAAQ,KAAK;IAEvC,QAAQ,CAAC,MAAM,EAAE,MAAM;gBAAd,MAAM,EAAE,MAAM,EACvB,MAAM,EAAE,MAAM;CAIjB;AA0BD;;;GAGG;AACH,qBAAa,YAAa,YAAW,MAAM,EAAE,YAAY;;gBAI3C,OAAO,EAAE,mBAAmB;IAKxC,cAAc,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAS/C,cAAc,CAAC,IAAI,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IASnD,+EAA+E;IAC/E,QAAQ,CAAC,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAKvC,oBAAoB,CAAC,IAAI,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC;CAmC5D;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,GAAG,GAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAe,EAAE,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,GAAG,YAAY,GAAG,SAAS,CAIxJ"}
@@ -12,8 +12,24 @@ export const englishMailWords = {
12
12
  noticeIntro: (formName, siteName) => `Someone filled in "${formName}" on ${siteName}.`,
13
13
  noticeSentFrom: 'Sent from',
14
14
  noticeReply: 'Reply to this email to answer them. The message is also kept in the CMS.',
15
+ testSubject: (siteName) => `Email works for ${siteName}`,
16
+ testGreeting: (name) => `Hi ${name},`,
17
+ testBody: (siteName) => `This is a test from ${siteName}. If you are reading it, sign-in links, invitations and notices from forms will arrive too.`,
15
18
  };
19
+ /** The provider answered and refused. `status` is its answer; the message holds its own words, for the server's log. */
20
+ export class MailRefusedError extends Error {
21
+ status;
22
+ constructor(status, detail) {
23
+ super(`Resend refused an email (${status}). ${detail}`);
24
+ this.status = status;
25
+ }
26
+ }
16
27
  const escaped = (text) => text.replace(/[&<>"']/g, (character) => `&#${character.charCodeAt(0)};`);
28
+ /** Paragraphs and nothing else. */
29
+ function plain(...paragraphs) {
30
+ const html = `<div style="max-width:480px;margin:0 auto;padding:32px 16px">${paragraphs.map((words) => `<p style="margin:0 0 16px;font:16px/1.5 system-ui,sans-serif;color:#1a1a1a">${escaped(words)}</p>`).join('')}</div>`;
31
+ return { html, text: paragraphs.join('\n\n') };
32
+ }
17
33
  /** One paragraph of greeting, one of explanation, one button, and the address in full under it. */
18
34
  function layout(greeting, body, button, url, note) {
19
35
  const paragraph = (words) => `<p style="margin:0 0 16px;font:16px/1.5 system-ui,sans-serif;color:#1a1a1a">${escaped(words)}</p>`;
@@ -48,6 +64,11 @@ export class ResendMailer {
48
64
  const words = this.#words;
49
65
  return this.#send(mail.email, words.invitationSubject(mail.siteName), layout(words.invitationGreeting(mail.name), words.invitationBody(mail.siteName, mail.email), words.invitationButton, mail.url));
50
66
  }
67
+ /** One email that says the settings work. It carries no link and no secret. */
68
+ sendTest(mail) {
69
+ const words = { ...englishMailWords, ...this.#words };
70
+ return this.#send(mail.email, words.testSubject?.(mail.siteName) ?? mail.siteName, plain(words.testGreeting?.(mail.name) ?? '', words.testBody?.(mail.siteName) ?? ''));
71
+ }
51
72
  sendSubmissionNotice(mail) {
52
73
  const words = { ...englishMailWords, ...this.#words };
53
74
  const intro = words.noticeIntro?.(mail.formName, mail.siteName) ?? '';
@@ -79,7 +100,7 @@ export class ResendMailer {
79
100
  // The provider's own words go to the server's log through whoever catches this. The address
80
101
  // is left out: a log is not the place for who works on a site.
81
102
  const detail = (await response.text().catch(() => '')).slice(0, 300);
82
- throw new Error(`Resend refused an email (${response.status}). ${detail}`);
103
+ throw new MailRefusedError(response.status, detail);
83
104
  }
84
105
  }
85
106
  }
@@ -87,9 +108,9 @@ export class ResendMailer {
87
108
  * The mailer a site gets from its settings alone: Resend when `VELOCITY_CMS_RESEND_API_KEY` and
88
109
  * `VELOCITY_CMS_EMAIL_FROM` are both set, otherwise none.
89
110
  */
90
- export function mailerFromEnv(env = process.env) {
111
+ export function mailerFromEnv(env = process.env, fetch) {
91
112
  const apiKey = env['VELOCITY_CMS_RESEND_API_KEY'];
92
113
  const from = env['VELOCITY_CMS_EMAIL_FROM'];
93
- return apiKey && from ? new ResendMailer({ apiKey, from }) : undefined;
114
+ return apiKey && from ? new ResendMailer({ apiKey, from, ...(fetch && { fetch }) }) : undefined;
94
115
  }
95
116
  //# sourceMappingURL=resend-mailer.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"resend-mailer.js","sourceRoot":"","sources":["../src/resend-mailer.ts"],"names":[],"mappings":"AAqBA,MAAM,CAAC,MAAM,gBAAgB,GAAc;IACzC,aAAa,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC,yBAAyB,QAAQ,EAAE;IAChE,cAAc,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,MAAM,IAAI,GAAG;IACvC,UAAU,EAAE,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,CAAC,sCAAsC,QAAQ,wCAAwC,OAAO,WAAW;IAC3I,YAAY,EAAE,SAAS;IACvB,YAAY,EAAE,8FAA8F;IAC5G,iBAAiB,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC,oBAAoB,QAAQ,EAAE;IAC/D,kBAAkB,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,MAAM,IAAI,GAAG;IAC3C,cAAc,EAAE,CAAC,QAAQ,EAAE,KAAK,EAAE,EAAE,CAClC,iCAAiC,QAAQ,+BAA+B,KAAK,uEAAuE;IACtJ,gBAAgB,EAAE,iBAAiB;IACnC,aAAa,EAAE,CAAC,QAAQ,EAAE,QAAQ,EAAE,EAAE,CAAC,gBAAgB,QAAQ,OAAO,QAAQ,EAAE;IAChF,WAAW,EAAE,CAAC,QAAQ,EAAE,QAAQ,EAAE,EAAE,CAAC,sBAAsB,QAAQ,QA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AO,EAAE,CAAC,EAAE,CAAC;SACpI,CAAC,CAAC;QACH,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACjB,4FAA4F;YAC5F,+DAA+D;YAC/D,MAAM,MAAM,GAAG,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;YACrE,MAAM,IAAI,gBAAgB,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACtD,CAAC;IACH,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,MAAoD,OAAO,CAAC,GAAG,EAAE,KAA+B;IAC5H,MAAM,MAAM,GAAG,GAAG,CAAC,6BAA6B,CAAC,CAAC;IAClD,MAAM,IAAI,GAAG,GAAG,CAAC,yBAAyB,CAAC,CAAC;IAC5C,OAAO,MAAM,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,YAAY,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,CAAC,KAAK,IAAI,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AAClG,CAAC"}
package/dist/secret.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * The site's one secret, from `VELOCITY_CMS_SECRET`. It signs preview links and, until the editor
2
+ * The site's one secret: from `VELOCITY_CMS_SECRET`, or the site's own on a server that runs many. It signs preview links and, until the editor
3
3
  * exists, proves that a publish notice comes from the site's owner. Without it both are off.
4
4
  */
5
5
  export declare const siteSecret: () => string | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"secret.d.ts","sourceRoot":"","sources":["../src/secret.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,eAAO,MAAM,UAAU,QAAO,MAAM,GAAG,SAAyD,CAAC;AAEjG,gEAAgE;AAChE,wBAAgB,aAAa,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAMvD"}
1
+ {"version":3,"file":"secret.d.ts","sourceRoot":"","sources":["../src/secret.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,eAAO,MAAM,UAAU,QAAO,MAAM,GAAG,SAAgG,CAAC;AAExI,gEAAgE;AAChE,wBAAgB,aAAa,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAMvD"}
package/dist/secret.js CHANGED
@@ -1,9 +1,10 @@
1
1
  import { timingSafeEqual } from 'node:crypto';
2
+ import { currentSite, isHosted } from './hosted.js';
2
3
  /**
3
- * The site's one secret, from `VELOCITY_CMS_SECRET`. It signs preview links and, until the editor
4
+ * The site's one secret: from `VELOCITY_CMS_SECRET`, or the site's own on a server that runs many. It signs preview links and, until the editor
4
5
  * exists, proves that a publish notice comes from the site's owner. Without it both are off.
5
6
  */
6
- export const siteSecret = () => process.env.VELOCITY_CMS_SECRET || undefined;
7
+ export const siteSecret = () => (isHosted() ? currentSite()?.secret : process.env.VELOCITY_CMS_SECRET || undefined);
7
8
  /** Whether the request carries the secret as a bearer token. */
8
9
  export function hasSiteSecret(request) {
9
10
  const secret = siteSecret();
@@ -1 +1 @@
1
- {"version":3,"file":"secret.js","sourceRoot":"","sources":["../src/secret.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C;;;GAGG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,GAAuB,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,mBAAmB,IAAI,SAAS,CAAC;AAEjG,gEAAgE;AAChE,MAAM,UAAU,aAAa,CAAC,OAAgB;IAC5C,MAAM,MAAM,GAAG,UAAU,EAAE,CAAC;IAC5B,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,EAAE,KAAK,CAAC,eAAe,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAChF,IAAI,CAAC,MAAM,IAAI,CAAC,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0,0 +1,18 @@
1
+ import type { Cms } from '@velocity-astro/cms-core';
2
+ import type { DrawnPage } from './page-head.js';
3
+ /** `single` for a CMS already at hand. `preview` reads the version being worked on. */
4
+ export declare function singleFrom(cms: Cms, locale: string, type: string, preview?: boolean): Promise<Readonly<Record<string, unknown>> | undefined>;
5
+ /**
6
+ * What a single page of the CMS holds, by field key, for the page being drawn: the site's
7
+ * settings, say, which every page reads.
8
+ *
9
+ * ```astro
10
+ * const settings = await single(Astro, 'settings');
11
+ * ```
12
+ *
13
+ * The entry in the page's language is read, and the first language's when that language has
14
+ * none. It answers with nothing when there is no such type, when nothing is published yet, and
15
+ * when anything goes wrong: a page is never lost over it, and the template uses its own values.
16
+ */
17
+ export declare function single(page: DrawnPage, type: string): Promise<Readonly<Record<string, unknown>> | undefined>;
18
+ //# sourceMappingURL=single.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"single.d.ts","sourceRoot":"","sources":["../src/single.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,0BAA0B,CAAC;AAGpD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAGhD,uFAAuF;AACvF,wBAAsB,UAAU,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,UAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,CAQhJ;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,MAAM,CAAC,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,CAQlH"}
package/dist/single.js ADDED
@@ -0,0 +1,37 @@
1
+ import { sharedConnection } from './connection.js';
2
+ import { DEFAULT_LOCALE, entriesOf } from './link.js';
3
+ import { isPreview, withPreviewDraft } from './preview.js';
4
+ /** `single` for a CMS already at hand. `preview` reads the version being worked on. */
5
+ export async function singleFrom(cms, locale, type, preview = false) {
6
+ const holder = (await cms.schema.list()).find((candidate) => candidate.key === type);
7
+ if (!holder || holder.kind !== 'single')
8
+ return undefined;
9
+ const shown = (await entriesOf(cms, holder)).filter((entry) => preview || entry.published !== undefined);
10
+ // What a site says about itself (its name, its phone number) holds in every language, so a
11
+ // language with no entry of its own reads the first language's instead of going without.
12
+ const entry = shown.find((candidate) => candidate.locale === locale) ?? shown.find((candidate) => candidate.locale === DEFAULT_LOCALE) ?? shown[0];
13
+ return entry && cms.content.toPublic(holder, withPreviewDraft(entry), preview ? 'working' : 'published').data;
14
+ }
15
+ /**
16
+ * What a single page of the CMS holds, by field key, for the page being drawn: the site's
17
+ * settings, say, which every page reads.
18
+ *
19
+ * ```astro
20
+ * const settings = await single(Astro, 'settings');
21
+ * ```
22
+ *
23
+ * The entry in the page's language is read, and the first language's when that language has
24
+ * none. It answers with nothing when there is no such type, when nothing is published yet, and
25
+ * when anything goes wrong: a page is never lost over it, and the template uses its own values.
26
+ */
27
+ export async function single(page, type) {
28
+ try {
29
+ const { cms } = await sharedConnection({});
30
+ return await singleFrom(cms, page.currentLocale ?? DEFAULT_LOCALE, type, isPreview());
31
+ }
32
+ catch (error) {
33
+ console.error(`[velocity-cms] "${type}" could not be read, so the template's own values are used.`, error instanceof Error ? error.message : error);
34
+ return undefined;
35
+ }
36
+ }
37
+ //# sourceMappingURL=single.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"single.js","sourceRoot":"","sources":["../src/single.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtD,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAE3D,uFAAuF;AAC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,aAAa,IAAI,cAAc,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC;IACxF,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,mBAAmB,IAAI,6DAA6D,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;QACpJ,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC"}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * How the `velocity-cms` command reaches a site's content: over the site's own API, with an
3
+ * access token, so it works the same on this computer and on the live site, and goes through
4
+ * every rule, plugin and cache the site has. Content commands call the same tools an AI agent
5
+ * calls over MCP (`/api/cms/mcp`), so the two can never disagree.
6
+ */
7
+ /** A refusal from the site, in its own words: what happened and what to do. */
8
+ export declare class SiteRefusal extends Error {
9
+ readonly name = "SiteRefusal";
10
+ }
11
+ export interface SiteClientOptions {
12
+ /** The site's address, such as `https://example.com` or `http://localhost:4321`. */
13
+ readonly origin: string;
14
+ /** An access token, `vcms_…`, made in the editor (Settings, Access tokens) or with `velocity-cms token`. */
15
+ readonly token: string;
16
+ /** Where the API is served. Defaults to `/api/cms`. */
17
+ readonly apiPath?: string;
18
+ readonly fetch?: typeof fetch;
19
+ }
20
+ /** The content type an image upload is sent as, from its file's name, or `null` for one the CMS does not take. */
21
+ export declare function imageTypeOf(fileName: string): string | null;
22
+ export declare class SiteClient {
23
+ #private;
24
+ constructor(options: SiteClientOptions);
25
+ /** Where the site's MCP server is. */
26
+ get mcpAddress(): string;
27
+ /** Hands one JSON-RPC message to the site's MCP server as it is, and its answer back (`null` for a notification). */
28
+ relay(message: string): Promise<string | null>;
29
+ /** Calls one of the site's MCP tools and returns what it answered, or throws its refusal. */
30
+ tool<T = unknown>(name: string, args?: Record<string, unknown>): Promise<T>;
31
+ /** Uploads one image. Answers with what an image field stores: its name. */
32
+ upload(fileName: string, bytes: Uint8Array): Promise<{
33
+ readonly name: string;
34
+ readonly url: string;
35
+ }>;
36
+ }
37
+ //# sourceMappingURL=site-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"site-client.d.ts","sourceRoot":"","sources":["../src/site-client.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,+EAA+E;AAC/E,qBAAa,WAAY,SAAQ,KAAK;IACpC,SAAkB,IAAI,iBAAiB;CACxC;AAED,MAAM,WAAW,iBAAiB;IAChC,oFAAoF;IACpF,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,4GAA4G;IAC5G,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,uDAAuD;IACvD,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;CAC/B;AAID,kHAAkH;AAClH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAE3D;AAED,qBAAa,UAAU;;gBAMT,OAAO,EAAE,iBAAiB;IAMtC,sCAAsC;IACtC,IAAI,UAAU,IAAI,MAAM,CAEvB;IAED,qHAAqH;IAC/G,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAKpD,6FAA6F;IACvF,IAAI,CAAC,CAAC,GAAG,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,GAAG,OAAO,CAAC,CAAC,CAAC;IASrF,4EAA4E;IACtE,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC;QAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC;CAsB5G"}
@@ -0,0 +1,73 @@
1
+ /**
2
+ * How the `velocity-cms` command reaches a site's content: over the site's own API, with an
3
+ * access token, so it works the same on this computer and on the live site, and goes through
4
+ * every rule, plugin and cache the site has. Content commands call the same tools an AI agent
5
+ * calls over MCP (`/api/cms/mcp`), so the two can never disagree.
6
+ */
7
+ /** A refusal from the site, in its own words: what happened and what to do. */
8
+ export class SiteRefusal extends Error {
9
+ name = 'SiteRefusal';
10
+ }
11
+ const IMAGE_TYPES = { jpg: 'image/jpeg', jpeg: 'image/jpeg', png: 'image/png', webp: 'image/webp' };
12
+ /** The content type an image upload is sent as, from its file's name, or `null` for one the CMS does not take. */
13
+ export function imageTypeOf(fileName) {
14
+ return IMAGE_TYPES[fileName.split('.').pop()?.toLowerCase() ?? ''] ?? null;
15
+ }
16
+ export class SiteClient {
17
+ #base;
18
+ #token;
19
+ #fetch;
20
+ #next = 1;
21
+ constructor(options) {
22
+ this.#base = `${options.origin.replace(/\/+$/, '')}/${(options.apiPath ?? '/api/cms').split('/').filter(Boolean).join('/')}`;
23
+ this.#token = options.token;
24
+ this.#fetch = options.fetch ?? fetch;
25
+ }
26
+ /** Where the site's MCP server is. */
27
+ get mcpAddress() {
28
+ return `${this.#base}/mcp`;
29
+ }
30
+ /** Hands one JSON-RPC message to the site's MCP server as it is, and its answer back (`null` for a notification). */
31
+ async relay(message) {
32
+ const response = await this.#post('/mcp', 'application/json', message);
33
+ return response.status === 202 ? null : response.text();
34
+ }
35
+ /** Calls one of the site's MCP tools and returns what it answered, or throws its refusal. */
36
+ async tool(name, args = {}) {
37
+ const response = await this.#post('/mcp', 'application/json', JSON.stringify({ jsonrpc: '2.0', id: this.#next++, method: 'tools/call', params: { name, arguments: args } }));
38
+ const answer = (await response.json());
39
+ if (answer.error)
40
+ throw new SiteRefusal(answer.error.message ?? 'The site refused the request.');
41
+ const text = answer.result?.content?.[0]?.text ?? '';
42
+ if (answer.result?.isError)
43
+ throw new SiteRefusal(text);
44
+ return JSON.parse(text === '' ? '{}' : text);
45
+ }
46
+ /** Uploads one image. Answers with what an image field stores: its name. */
47
+ async upload(fileName, bytes) {
48
+ const type = imageTypeOf(fileName);
49
+ if (type === null)
50
+ throw new SiteRefusal(`${fileName} is not an image the CMS takes. Use a JPEG, PNG or WebP file.`);
51
+ const response = await this.#post(`/images?name=${encodeURIComponent(fileName)}`, type, bytes);
52
+ return (await response.json());
53
+ }
54
+ async #post(path, contentType, body) {
55
+ let response;
56
+ try {
57
+ response = await this.#fetch(`${this.#base}${path}`, { method: 'POST', headers: { authorization: `Bearer ${this.#token}`, 'content-type': contentType, accept: 'application/json' }, body });
58
+ }
59
+ catch {
60
+ throw new SiteRefusal(`The site at ${new URL(this.#base).origin} did not answer. Is it running? Start it, or set VELOCITY_CMS_ORIGIN to its address.`);
61
+ }
62
+ if (response.status === 401)
63
+ throw new SiteRefusal('The site did not accept the token. Make a new one in the editor (Settings, Access tokens) or with `velocity-cms token`, and set VELOCITY_CMS_TOKEN.');
64
+ if (response.status === 404)
65
+ throw new SiteRefusal(`There is no Velocity CMS at ${new URL(this.#base).origin}, or it is older than this command. Check VELOCITY_CMS_ORIGIN, and update @velocity-astro/cms-astro.`);
66
+ if (!response.ok) {
67
+ const body = (await response.json().catch(() => null));
68
+ throw new SiteRefusal(body?.error?.message ?? `The site answered ${response.status}.`);
69
+ }
70
+ return response;
71
+ }
72
+ }
73
+ //# sourceMappingURL=site-client.js.map