@velocity-astro/cms-astro 0.0.0-stage → 0.1.0-beta.11

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 (154) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +12 -2
  3. package/bin/velocity-cms.mjs +6 -0
  4. package/dist/admin-files.d.ts +21 -0
  5. package/dist/admin-files.d.ts.map +1 -0
  6. package/dist/admin-files.js +83 -0
  7. package/dist/admin-files.js.map +1 -0
  8. package/dist/challenge.d.ts +35 -0
  9. package/dist/challenge.d.ts.map +1 -0
  10. package/dist/challenge.js +84 -0
  11. package/dist/challenge.js.map +1 -0
  12. package/dist/cli.d.ts +9 -0
  13. package/dist/cli.d.ts.map +1 -0
  14. package/dist/cli.js +76 -0
  15. package/dist/cli.js.map +1 -0
  16. package/dist/connection.d.ts +26 -0
  17. package/dist/connection.d.ts.map +1 -0
  18. package/dist/connection.js +87 -0
  19. package/dist/connection.js.map +1 -0
  20. package/dist/editor.d.ts +67 -0
  21. package/dist/editor.d.ts.map +1 -0
  22. package/dist/editor.js +194 -0
  23. package/dist/editor.js.map +1 -0
  24. package/dist/entry-page.d.ts +37 -0
  25. package/dist/entry-page.d.ts.map +1 -0
  26. package/dist/entry-page.js +56 -0
  27. package/dist/entry-page.js.map +1 -0
  28. package/dist/form-post.d.ts +114 -0
  29. package/dist/form-post.d.ts.map +1 -0
  30. package/dist/form-post.js +298 -0
  31. package/dist/form-post.js.map +1 -0
  32. package/dist/hosted.d.ts +76 -0
  33. package/dist/hosted.d.ts.map +1 -0
  34. package/dist/hosted.js +104 -0
  35. package/dist/hosted.js.map +1 -0
  36. package/dist/image-optimizer.d.ts +35 -0
  37. package/dist/image-optimizer.d.ts.map +1 -0
  38. package/dist/image-optimizer.js +76 -0
  39. package/dist/image-optimizer.js.map +1 -0
  40. package/dist/index.d.ts +34 -0
  41. package/dist/index.d.ts.map +1 -0
  42. package/dist/index.js +34 -0
  43. package/dist/index.js.map +1 -0
  44. package/dist/init.d.ts +35 -0
  45. package/dist/init.d.ts.map +1 -0
  46. package/dist/init.js +140 -0
  47. package/dist/init.js.map +1 -0
  48. package/dist/integration.d.ts +72 -0
  49. package/dist/integration.d.ts.map +1 -0
  50. package/dist/integration.js +143 -0
  51. package/dist/integration.js.map +1 -0
  52. package/dist/link.d.ts +32 -0
  53. package/dist/link.d.ts.map +1 -0
  54. package/dist/link.js +80 -0
  55. package/dist/link.js.map +1 -0
  56. package/dist/live-loader.d.ts +44 -0
  57. package/dist/live-loader.d.ts.map +1 -0
  58. package/dist/live-loader.js +98 -0
  59. package/dist/live-loader.js.map +1 -0
  60. package/dist/live-pages.d.ts +69 -0
  61. package/dist/live-pages.d.ts.map +1 -0
  62. package/dist/live-pages.js +94 -0
  63. package/dist/live-pages.js.map +1 -0
  64. package/dist/loader.d.ts +22 -0
  65. package/dist/loader.d.ts.map +1 -0
  66. package/dist/loader.js +62 -0
  67. package/dist/loader.js.map +1 -0
  68. package/dist/media-store.d.ts +61 -0
  69. package/dist/media-store.d.ts.map +1 -0
  70. package/dist/media-store.js +178 -0
  71. package/dist/media-store.js.map +1 -0
  72. package/dist/menu.d.ts +51 -0
  73. package/dist/menu.d.ts.map +1 -0
  74. package/dist/menu.js +81 -0
  75. package/dist/menu.js.map +1 -0
  76. package/dist/page-head.d.ts +23 -0
  77. package/dist/page-head.d.ts.map +1 -0
  78. package/dist/page-head.js +66 -0
  79. package/dist/page-head.js.map +1 -0
  80. package/dist/page-marks.d.ts +50 -0
  81. package/dist/page-marks.d.ts.map +1 -0
  82. package/dist/page-marks.js +90 -0
  83. package/dist/page-marks.js.map +1 -0
  84. package/dist/preview.d.ts +92 -0
  85. package/dist/preview.d.ts.map +1 -0
  86. package/dist/preview.js +192 -0
  87. package/dist/preview.js.map +1 -0
  88. package/dist/resend-mailer.d.ts +63 -0
  89. package/dist/resend-mailer.d.ts.map +1 -0
  90. package/dist/resend-mailer.js +116 -0
  91. package/dist/resend-mailer.js.map +1 -0
  92. package/dist/secret.d.ts +8 -0
  93. package/dist/secret.d.ts.map +1 -0
  94. package/dist/secret.js +17 -0
  95. package/dist/secret.js.map +1 -0
  96. package/dist/single.d.ts +18 -0
  97. package/dist/single.d.ts.map +1 -0
  98. package/dist/single.js +37 -0
  99. package/dist/single.js.map +1 -0
  100. package/dist/site-editor.d.ts +41 -0
  101. package/dist/site-editor.d.ts.map +1 -0
  102. package/dist/site-editor.js +140 -0
  103. package/dist/site-editor.js.map +1 -0
  104. package/dist/site-forms.d.ts +54 -0
  105. package/dist/site-forms.d.ts.map +1 -0
  106. package/dist/site-forms.js +100 -0
  107. package/dist/site-forms.js.map +1 -0
  108. package/dist/site-images.d.ts +17 -0
  109. package/dist/site-images.d.ts.map +1 -0
  110. package/dist/site-images.js +22 -0
  111. package/dist/site-images.js.map +1 -0
  112. package/dist/site-mail.d.ts +45 -0
  113. package/dist/site-mail.d.ts.map +1 -0
  114. package/dist/site-mail.js +84 -0
  115. package/dist/site-mail.js.map +1 -0
  116. package/dist/site-media.d.ts +22 -0
  117. package/dist/site-media.d.ts.map +1 -0
  118. package/dist/site-media.js +52 -0
  119. package/dist/site-media.js.map +1 -0
  120. package/dist/site-name.d.ts +9 -0
  121. package/dist/site-name.d.ts.map +1 -0
  122. package/dist/site-name.js +21 -0
  123. package/dist/site-name.js.map +1 -0
  124. package/dist/site-plugins.d.ts +10 -0
  125. package/dist/site-plugins.d.ts.map +1 -0
  126. package/dist/site-plugins.js +23 -0
  127. package/dist/site-plugins.js.map +1 -0
  128. package/dist/site-search.d.ts +12 -0
  129. package/dist/site-search.d.ts.map +1 -0
  130. package/dist/site-search.js +79 -0
  131. package/dist/site-search.js.map +1 -0
  132. package/dist/site-storage.d.ts +34 -0
  133. package/dist/site-storage.d.ts.map +1 -0
  134. package/dist/site-storage.js +118 -0
  135. package/dist/site-storage.js.map +1 -0
  136. package/package.json +56 -3
  137. package/routes/admin.ts +10 -0
  138. package/routes/api.ts +15 -0
  139. package/routes/auth.ts +10 -0
  140. package/routes/due.ts +12 -0
  141. package/routes/editor.ts +49 -0
  142. package/routes/form-client.js.ts +173 -0
  143. package/routes/media.ts +10 -0
  144. package/routes/pages.ts +13 -0
  145. package/routes/plugins.ts +10 -0
  146. package/routes/preview-client.js.ts +18 -0
  147. package/routes/published.ts +29 -0
  148. package/routes/schedule.ts +20 -0
  149. package/routes/search-client.js.ts +33 -0
  150. package/routes/search.json.ts +10 -0
  151. package/routes/share-image.png.ts +33 -0
  152. package/routes/sitemap-live.xml.ts +16 -0
  153. package/routes/sites.ts +11 -0
  154. package/routes/submit.ts +22 -0
@@ -0,0 +1,41 @@
1
+ import { type Mailer } from '@velocity-astro/cms-auth';
2
+ import { type ImageLibrary } from '@velocity-astro/cms-core';
3
+ import { EditorHost } from './editor.js';
4
+ /** What the integration tells the editor's routes about the site. */
5
+ export interface SiteEditorSettings {
6
+ /** `site` from the Astro config, if it is set. */
7
+ readonly site: string | undefined;
8
+ /** Whether this is `astro dev`. */
9
+ readonly dev: boolean;
10
+ readonly siteName: string;
11
+ readonly adminPath: string;
12
+ /** How sign-in links are delivered. Without one they are printed to the server's log. */
13
+ readonly mailer?: Mailer | undefined;
14
+ /** The site's images, for image fields. Without them there are none to choose from. */
15
+ readonly images?: ImageLibrary | undefined;
16
+ }
17
+ /** The editor cannot be served until the site's settings are completed. The message says how. */
18
+ export declare class EditorNotSetUpError extends Error {
19
+ }
20
+ /**
21
+ * The address sign-in links and passkeys are made for. It is never taken from a request on a
22
+ * deployed site: whoever sends a request chooses its `Host` header, and a link built from it
23
+ * would carry a real person's sign-in to an address of the sender's choosing.
24
+ */
25
+ export declare function editorOrigin(request: Request, settings: Pick<SiteEditorSettings, 'site' | 'dev'>): string;
26
+ /**
27
+ * The address the site reads its own pages from, for search and share images, or `null` when it
28
+ * cannot tell. The request's own address is used only when the site is known by it: whoever
29
+ * sends a request chooses its `Host` header, and a page read from an address of their choosing
30
+ * would be someone else's page, or a machine beside the site.
31
+ */
32
+ export declare function pagesOrigin(request: Request, settings: Pick<SiteEditorSettings, 'site' | 'dev'>): string | null;
33
+ /** The site's one editor host for the life of the server, made on first use. */
34
+ export declare function siteEditorHost(request: Request, settings: SiteEditorSettings): Promise<EditorHost>;
35
+ /**
36
+ * Hands a request to the site's editor host. When the editor is not set up yet, answers with
37
+ * what is missing instead, in the shape the API's errors have, so the person setting the site
38
+ * up reads it in the browser and in the log.
39
+ */
40
+ export declare function withEditor(request: Request, settings: SiteEditorSettings, answer: (host: EditorHost) => Response | Promise<Response>): Promise<Response>;
41
+ //# sourceMappingURL=site-editor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"site-editor.d.ts","sourceRoot":"","sources":["../src/site-editor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,KAAK,MAAM,EAAE,MAAM,0BAA0B,CAAC;AACvE,OAAO,EAAiB,KAAK,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAE5E,OAAO,EAAE,UAAU,EAAa,MAAM,aAAa,CAAC;AAMpD,qEAAqE;AACrE,MAAM,WAAW,kBAAkB;IACjC,kDAAkD;IAClD,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IAClC,mCAAmC;IACnC,QAAQ,CAAC,GAAG,EAAE,OAAO,CAAC;IACtB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,yFAAyF;IACzF,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACrC,uFAAuF;IACvF,QAAQ,CAAC,MAAM,CAAC,EAAE,YAAY,GAAG,SAAS,CAAC;CAC5C;AAED,iGAAiG;AACjG,qBAAa,mBAAoB,SAAQ,KAAK;CAAG;AAEjD;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,CAAC,kBAAkB,EAAE,MAAM,GAAG,KAAK,CAAC,GAAG,MAAM,CAezG;AAWD;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,CAAC,kBAAkB,EAAE,MAAM,GAAG,KAAK,CAAC,GAAG,MAAM,GAAG,IAAI,CAa/G;AAgDD,gFAAgF;AAChF,wBAAgB,cAAc,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,kBAAkB,GAAG,OAAO,CAAC,UAAU,CAAC,CAUlG;AAED;;;;GAIG;AACH,wBAAsB,UAAU,CAC9B,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,kBAAkB,EAC5B,MAAM,EAAE,CAAC,IAAI,EAAE,UAAU,KAAK,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,GACzD,OAAO,CAAC,QAAQ,CAAC,CAUnB"}
@@ -0,0 +1,140 @@
1
+ import { AuthSetupError } from '@velocity-astro/cms-auth';
2
+ import { ConflictError } from '@velocity-astro/cms-core';
3
+ import { sharedConnection } from './connection.js';
4
+ import { EditorHost, LogMailer } from './editor.js';
5
+ import { currentSite } from './hosted.js';
6
+ import { SiteMail } from './site-mail.js';
7
+ import { siteNameNow } from './site-name.js';
8
+ import { siteSecret } from './secret.js';
9
+ /** The editor cannot be served until the site's settings are completed. The message says how. */
10
+ export class EditorNotSetUpError extends Error {
11
+ }
12
+ /**
13
+ * The address sign-in links and passkeys are made for. It is never taken from a request on a
14
+ * deployed site: whoever sends a request chooses its `Host` header, and a link built from it
15
+ * would carry a real person's sign-in to an address of the sender's choosing.
16
+ */
17
+ export function editorOrigin(request, settings) {
18
+ // On a server that runs many sites, the address is the one its host keeps for the site.
19
+ const hosted = currentSite();
20
+ if (hosted)
21
+ return new URL(hosted.origin).origin;
22
+ const configured = process.env.VELOCITY_CMS_ORIGIN || (settings.dev ? new URL(request.url).origin : settings.site);
23
+ if (!configured) {
24
+ throw new EditorNotSetUpError('The editor needs to know the site\'s address. Set `site` in astro.config.mjs, or the VELOCITY_CMS_ORIGIN environment variable.');
25
+ }
26
+ try {
27
+ return new URL(configured).origin;
28
+ }
29
+ catch {
30
+ throw new EditorNotSetUpError(`"${configured}" is not an address. Give the site's own, such as https://example.com.`);
31
+ }
32
+ }
33
+ /** The names a host gives a deployment itself. A visitor cannot set them. */
34
+ const PLATFORM_HOSTS = ['VERCEL_URL', 'VERCEL_BRANCH_URL', 'VERCEL_PROJECT_PRODUCTION_URL', 'URL', 'DEPLOY_PRIME_URL', 'DEPLOY_URL'];
35
+ const hostOf = (address) => {
36
+ if (!address)
37
+ return null;
38
+ const full = address.includes('://') ? address : `https://${address}`;
39
+ return URL.canParse(full) ? new URL(full).host : null;
40
+ };
41
+ /**
42
+ * The address the site reads its own pages from, for search and share images, or `null` when it
43
+ * cannot tell. The request's own address is used only when the site is known by it: whoever
44
+ * sends a request chooses its `Host` header, and a page read from an address of their choosing
45
+ * would be someone else's page, or a machine beside the site.
46
+ */
47
+ export function pagesOrigin(request, settings) {
48
+ const asked = new URL(request.url);
49
+ const hosted = currentSite();
50
+ if (hosted)
51
+ return new URL(hosted.origin).origin;
52
+ if (settings.dev)
53
+ return asked.origin;
54
+ const configured = [process.env.VELOCITY_CMS_ORIGIN, settings.site].map(hostOf);
55
+ const known = [...configured, ...PLATFORM_HOSTS.map((name) => hostOf(process.env[name]))];
56
+ if (known.includes(asked.host))
57
+ return asked.origin;
58
+ try {
59
+ return editorOrigin(request, settings);
60
+ }
61
+ catch {
62
+ return null;
63
+ }
64
+ }
65
+ const hosts = new Map();
66
+ async function createHost(origin, settings) {
67
+ const secret = siteSecret();
68
+ if (!secret) {
69
+ throw new EditorNotSetUpError('The editor is off because VELOCITY_CMS_SECRET is not set. Set it to at least 32 random characters, for example from `openssl rand -base64 32`.');
70
+ }
71
+ try {
72
+ const connection = await sharedConnection({});
73
+ const hosted = currentSite();
74
+ // A host names its sites. Otherwise the name an owner saved, then the one the site's code gives.
75
+ const named = hosted ? undefined : () => siteNameNow(connection.cms);
76
+ const siteName = hosted?.name ?? (await named?.()) ?? settings.siteName;
77
+ // The site's own mailer first, then Resend from the server's settings, then what an owner set up in the editor, then the server's log.
78
+ const mail = new SiteMail({ settings: connection.cms.settings, own: settings.mailer, fallback: new LogMailer(), hosted: hosted !== undefined, ...(named && { siteName: named }) });
79
+ connection.cms.settings.useSite({ defaultName: hosted?.name ?? settings.siteName, fixedBy: hosted ? 'host' : null });
80
+ const host = new EditorHost({
81
+ connection,
82
+ secret,
83
+ origin,
84
+ siteName,
85
+ ...(named && { siteNameNow: named }),
86
+ adminPath: settings.adminPath,
87
+ mailer: mail,
88
+ ...(settings.images && { images: settings.images }),
89
+ onFault: (error) => console.error('[velocity-cms]', error),
90
+ });
91
+ connection.cms.settings.useMail({
92
+ fixedBy: () => mail.fixedBy(),
93
+ canTest: () => mail.canTest(),
94
+ // The test goes to the address the person signs in with, which only sign-in knows.
95
+ sendTest: async (actor) => {
96
+ const person = (await host.auth.listUsers(actor)).find((user) => user.id === actor.id);
97
+ if (!person)
98
+ throw new ConflictError('A test email goes to the person who asks for it, and only someone signed in has an address to send it to.');
99
+ await mail.sendTest({ email: person.email, name: person.name, siteName: hosted?.name ?? settings.siteName });
100
+ },
101
+ });
102
+ return host;
103
+ }
104
+ catch (error) {
105
+ if (error instanceof AuthSetupError)
106
+ throw new EditorNotSetUpError(error.message);
107
+ throw error;
108
+ }
109
+ }
110
+ /** The site's one editor host for the life of the server, made on first use. */
111
+ export function siteEditorHost(request, settings) {
112
+ const origin = editorOrigin(request, settings);
113
+ let host = hosts.get(origin);
114
+ if (!host) {
115
+ host = createHost(origin, settings);
116
+ hosts.set(origin, host);
117
+ // A failed start must not be remembered: the next request tries again with the settings fixed.
118
+ host.catch(() => hosts.delete(origin));
119
+ }
120
+ return host;
121
+ }
122
+ /**
123
+ * Hands a request to the site's editor host. When the editor is not set up yet, answers with
124
+ * what is missing instead, in the shape the API's errors have, so the person setting the site
125
+ * up reads it in the browser and in the log.
126
+ */
127
+ export async function withEditor(request, settings, answer) {
128
+ let host;
129
+ try {
130
+ host = await siteEditorHost(request, settings);
131
+ }
132
+ catch (error) {
133
+ if (!(error instanceof EditorNotSetUpError))
134
+ throw error;
135
+ console.warn(`[velocity-cms] ${error.message}`);
136
+ return Response.json({ error: { code: 'not_set_up', message: error.message } }, { status: 503, headers: { 'cache-control': 'no-store' } });
137
+ }
138
+ return answer(host);
139
+ }
140
+ //# sourceMappingURL=site-editor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"site-editor.js","sourceRoot":"","sources":["../src/site-editor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAe,MAAM,0BAA0B,CAAC;AACvE,OAAO,EAAE,aAAa,EAAqB,MAAM,0BAA0B,CAAC;AAC5E,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAgBzC,iGAAiG;AACjG,MAAM,OAAO,mBAAoB,SAAQ,KAAK;CAAG;AAEjD;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAC,OAAgB,EAAE,QAAkD;IAC/F,wFAAwF;IACxF,MAAM,MAAM,GAAG,WAAW,EAAE,CAAC;IAC7B,IAAI,MAAM;QAAE,OAAO,IAAI,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC;IACjD,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,mBAAmB,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,C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AAO,EAAE,QAAQ,CAAC,CAAC;IACjD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,CAAC,CAAC,KAAK,YAAY,mBAAmB,CAAC;YAAE,MAAM,KAAK,CAAC;QACzD,OAAO,CAAC,IAAI,CAAC,kBAAkB,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;QAChD,OAAO,QAAQ,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,eAAe,EAAE,UAAU,EAAE,EAAE,CAAC,CAAC;IAC7I,CAAC;IACD,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC;AACtB,CAAC"}
@@ -0,0 +1,54 @@
1
+ import type { PublicForm } from '@velocity-astro/cms-core';
2
+ import { FormPosts } from './form-post.js';
3
+ import { type DrawnPage } from './page-head.js';
4
+ import { type SiteEditorSettings } from './site-editor.js';
5
+ /** The site's one taker of form posts for the life of the server, made on first use. */
6
+ export declare function siteFormPosts(settings: SiteEditorSettings): Promise<FormPosts>;
7
+ /** A form as a page draws it, with where it posts and the hidden fields it sends along. */
8
+ export interface SiteForm extends PublicForm {
9
+ /** Where the form posts: the `action` of its `<form method="post">`. */
10
+ readonly action: string;
11
+ /** Hidden fields to write into the form as they are: name and value. */
12
+ readonly hidden: Readonly<Record<string, string>>;
13
+ /**
14
+ * The name of a field to draw empty and out of sight (and out of reach of the keyboard and of
15
+ * screen readers). A person leaves it alone; a script that fills in everything gives itself away.
16
+ */
17
+ readonly trap: string;
18
+ /**
19
+ * The challenge a sender must pass, when an owner set one up. The form's script (`FORM_SCRIPT`)
20
+ * draws it where the form has a `[data-cms-form-challenge]`, or above the submit button. A
21
+ * site with a content security policy allows `host` for scripts and frames.
22
+ */
23
+ readonly challenge?: {
24
+ readonly provider: 'turnstile';
25
+ readonly siteKey: string;
26
+ readonly script: string;
27
+ readonly host: string;
28
+ };
29
+ }
30
+ /** The address of the script that sends a form without leaving its page (`data-cms-form`). */
31
+ export declare const FORM_SCRIPT = "/cms-form.js";
32
+ /** Which form: its key, as a template names one, or its id, as a field of type `form` holds one. */
33
+ export type FormChoice = string | {
34
+ readonly id: string;
35
+ };
36
+ /** What a page may say about the form it draws. */
37
+ export interface SiteFormOptions {
38
+ /**
39
+ * The published entry the form is about, when the page knows better than its address does: a
40
+ * listing's page says the listing, so what is sent is kept as being about it, and starts a
41
+ * deal about it when the form asks for that. `type` is the content type's key.
42
+ */
43
+ readonly about?: {
44
+ readonly type: string;
45
+ readonly slug: string;
46
+ readonly locale?: string;
47
+ };
48
+ }
49
+ /**
50
+ * A form of the CMS for the page being drawn, or `null` when there is none open under that key
51
+ * or id, so the template leaves it out. It never throws: a page is not lost over its form.
52
+ */
53
+ export declare function siteForm(page: DrawnPage, choice: FormChoice, options?: SiteFormOptions): Promise<SiteForm | null>;
54
+ //# sourceMappingURL=site-forms.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"site-forms.d.ts","sourceRoot":"","sources":["../src/site-forms.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAG3D,OAAO,EAAqH,SAAS,EAA2C,MAAM,gBAAgB,CAAC;AACvM,OAAO,EAAU,KAAK,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAOxD,OAAO,EAAgB,KAAK,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAczE,wFAAwF;AACxF,wBAAgB,aAAa,CAAC,QAAQ,EAAE,kBAAkB,GAAG,OAAO,CAAC,SAAS,CAAC,CAgC9E;AAED,2FAA2F;AAC3F,MAAM,WAAW,QAAS,SAAQ,UAAU;IAC1C,wEAAwE;IACxE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,wEAAwE;IACxE,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAClD;;;OAGG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB;;;;OAIG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE;QAAE,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAC;QAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;CACnI;AAED,8FAA8F;AAC9F,eAAO,MAAM,WAAW,iBAAiB,CAAC;AAE1C,oGAAoG;AACpG,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG;IAAE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;CAAE,CAAC;AAE1D,mDAAmD;AACnD,MAAM,WAAW,eAAe;IAC9B;;;;OAIG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE;QAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CAC7F;AAED;;;GAGG;AACH,wBAAsB,QAAQ,CAAC,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,GAAE,eAAoB,GAAG,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,CAgC3H"}
@@ -0,0 +1,100 @@
1
+ import { isLiveType } from '@velocity-astro/cms-core';
2
+ import { sharedConnection, SITE } from './connection.js';
3
+ import { FORM_ABOUT_FIELD, FORM_CHALLENGE_KEY_FIELD, FORM_LOCALE_FIELD, FORM_PAGE_FIELD, FORM_TOKEN_FIELD, FORM_TRAP_FIELD, FormPosts, MemoryRateLimiter, aboutMark, formToken } from './form-post.js';
4
+ import { pageAt } from './page-head.js';
5
+ import { currentSite, siteKey } from './hosted.js';
6
+ import { LogMailer } from './editor.js';
7
+ import { SiteMail } from './site-mail.js';
8
+ import { siteNameNow } from './site-name.js';
9
+ import { SiteChallenge, TURNSTILE_HOST, TURNSTILE_SCRIPT } from './challenge.js';
10
+ import { siteSecret } from './secret.js';
11
+ import { editorOrigin } from './site-editor.js';
12
+ /** One taker of form posts for each site this server runs. */
13
+ const takers = new Map();
14
+ /** The site's address for forms. A site that has not said its address yet is taken at the request's word. */
15
+ function originOf(request, settings) {
16
+ try {
17
+ return editorOrigin(request, settings);
18
+ }
19
+ catch {
20
+ return new URL(request.url).origin;
21
+ }
22
+ }
23
+ /** The site's one taker of form posts for the life of the server, made on first use. */
24
+ export function siteFormPosts(settings) {
25
+ const key = siteKey();
26
+ let posts = takers.get(key);
27
+ if (!posts) {
28
+ const onFault = (error) => console.error('[velocity-cms]', error instanceof Error ? error.message : error);
29
+ const made = sharedConnection({}).then(({ cms }) => {
30
+ const challenge = new SiteChallenge({ account: () => cms.settings.challengeAccount(), onFault });
31
+ const counted = new MemoryRateLimiter();
32
+ return new FormPosts({
33
+ cms,
34
+ origin: (request) => originOf(request, settings),
35
+ siteName: currentSite()?.name ?? settings.siteName,
36
+ secret: siteSecret(),
37
+ entryAt: async (path) => {
38
+ const { type, entry } = await pageAt(cms, await cms.schema.list(), path);
39
+ return type && entry ? { typeId: type.id, entry: entry.translationGroup } : undefined;
40
+ },
41
+ // The site's own mailer when it sends notices, then Resend from the server's settings, then what an owner set up in the editor.
42
+ mailer: new SiteMail({ settings: cms.settings, own: settings.mailer, fallback: new LogMailer(), hosted: currentSite() !== undefined, ...(currentSite() === undefined && { siteName: () => siteNameNow(cms) }) }),
43
+ challenge,
44
+ // What an owner set under Settings, Forms and spam. Settings that cannot be read leave the limit the CMS comes with.
45
+ limiter: { take: async (address) => counted.take(address, await cms.settings.formPostsPerAddress().catch(() => undefined)) },
46
+ onFault,
47
+ });
48
+ });
49
+ posts = made;
50
+ takers.set(key, made);
51
+ made.catch(() => {
52
+ if (takers.get(key) === made)
53
+ takers.delete(key);
54
+ });
55
+ }
56
+ return posts;
57
+ }
58
+ /** The address of the script that sends a form without leaving its page (`data-cms-form`). */
59
+ export const FORM_SCRIPT = '/cms-form.js';
60
+ /**
61
+ * A form of the CMS for the page being drawn, or `null` when there is none open under that key
62
+ * or id, so the template leaves it out. It never throws: a page is not lost over its form.
63
+ */
64
+ export async function siteForm(page, choice, options = {}) {
65
+ try {
66
+ const { cms } = await sharedConnection({});
67
+ const form = typeof choice === 'string' ? await cms.forms.forSite(choice) : await cms.forms.forSiteById(choice.id);
68
+ if (!form)
69
+ return null;
70
+ const token = await formToken(siteSecret(), form.key);
71
+ const locale = page.currentLocale;
72
+ const siteKey = await cms.settings.challengeSiteKey();
73
+ let about;
74
+ if (options.about) {
75
+ // An entry that is not there, or not published, leaves the form as one about nothing.
76
+ const type = await cms.schema.getByKey(options.about.type).catch(() => undefined);
77
+ const entry = type && isLiveType(type) ? await cms.content.findBySlug(SITE, { typeId: type.id, locale: options.about.locale ?? locale ?? 'en', slug: options.about.slug, version: 'published' }) : null;
78
+ if (type && entry)
79
+ about = await aboutMark(siteSecret(), form.key, { typeId: type.id, entry: entry.translationGroup });
80
+ }
81
+ return {
82
+ ...form,
83
+ action: `/api/cms/submit/${encodeURIComponent(form.key)}`,
84
+ hidden: {
85
+ [FORM_PAGE_FIELD]: page.url.pathname,
86
+ ...(locale !== undefined && { [FORM_LOCALE_FIELD]: locale }),
87
+ ...(token !== undefined && { [FORM_TOKEN_FIELD]: token }),
88
+ ...(about !== undefined && { [FORM_ABOUT_FIELD]: about }),
89
+ ...(siteKey !== null && { [FORM_CHALLENGE_KEY_FIELD]: siteKey }),
90
+ },
91
+ trap: FORM_TRAP_FIELD,
92
+ ...(siteKey !== null && { challenge: { provider: 'turnstile', siteKey, script: TURNSTILE_SCRIPT, host: TURNSTILE_HOST } }),
93
+ };
94
+ }
95
+ catch (error) {
96
+ console.error('[velocity-cms] A form could not be read.', error instanceof Error ? error.message : error);
97
+ return null;
98
+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;QACzH,CAAC;QACD,OAAO;YACL,GAAG,IAAI;YACP,MAAM,EAAE,mBAAmB,kBAAkB,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE;YACzD,MAAM,EAAE;gBACN,CAAC,eAAe,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,QAAQ;gBACpC,GAAG,CAAC,MAAM,KAAK,SAAS,IAAI,EAAE,CAAC,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;gBAC5D,GAAG,CAAC,KAAK,KAAK,SAAS,IAAI,EAAE,CAAC,gBAAgB,CAAC,EAAE,KAAK,EAAE,CAAC;gBACzD,GAAG,CAAC,KAAK,KAAK,SAAS,IAAI,EAAE,CAAC,gBAAgB,CAAC,EAAE,KAAK,EAAE,CAAC;gBACzD,GAAG,CAAC,OAAO,KAAK,IAAI,IAAI,EAAE,CAAC,wBAAwB,CAAC,EAAE,OAAO,EAAE,CAAC;aACjE;YACD,IAAI,EAAE,eAAe;YACrB,GAAG,CAAC,OAAO,KAAK,IAAI,IAAI,EAAE,SAAS,EAAE,EAAE,QAAQ,EAAE,WAAoB,EAAE,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,IAAI,EAAE,cAAc,EAAE,EAAE,CAAC;SACpI,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,0CAA0C,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;QAC1G,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC"}
@@ -0,0 +1,17 @@
1
+ import type { ImageLibrary } from '@velocity-astro/cms-core';
2
+ /** An image file as the site's bundler describes it. */
3
+ export interface ImageFile {
4
+ readonly src: string;
5
+ readonly width: number;
6
+ readonly height: number;
7
+ }
8
+ /**
9
+ * The images in a folder of the project, for image fields to choose from. An image is called by
10
+ * its file name without the ending, which is how a template's pages look their images up.
11
+ *
12
+ * @param files The folder's images by path, as `import.meta.glob` gives them.
13
+ * @param small Makes the address of a small copy, for the editor to show. When it fails for an
14
+ * image, the editor loads the image itself.
15
+ */
16
+ export declare function folderImages(files: Readonly<Record<string, ImageFile>>, small?: (file: ImageFile) => Promise<string>): ImageLibrary;
17
+ //# sourceMappingURL=site-images.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"site-images.d.ts","sourceRoot":"","sources":["../src/site-images.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAa,MAAM,0BAA0B,CAAC;AAExE,wDAAwD;AACxD,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAKD;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,CAAC,IAAI,EAAE,SAAS,KAAK,OAAO,CAAC,MAAM,CAAC,GAAG,YAAY,CAanI"}
@@ -0,0 +1,22 @@
1
+ /** The file's name without its folder or its ending: `/src/assets/photos/porch.jpg` is `porch`. */
2
+ const nameOf = (file) => file.slice(file.lastIndexOf('/') + 1).replace(/\.[^.]+$/, '');
3
+ /**
4
+ * The images in a folder of the project, for image fields to choose from. An image is called by
5
+ * its file name without the ending, which is how a template's pages look their images up.
6
+ *
7
+ * @param files The folder's images by path, as `import.meta.glob` gives them.
8
+ * @param small Makes the address of a small copy, for the editor to show. When it fails for an
9
+ * image, the editor loads the image itself.
10
+ */
11
+ export function folderImages(files, small) {
12
+ let listed;
13
+ const list = () => Promise.all(Object.entries(files).map(async ([path, file]) => ({
14
+ name: nameOf(path),
15
+ url: small ? await small(file).catch(() => file.src) : file.src,
16
+ width: file.width,
17
+ height: file.height,
18
+ })));
19
+ // The folder changes only with a deploy, so it is read once.
20
+ return { list: () => (listed ??= list()) };
21
+ }
22
+ //# sourceMappingURL=site-images.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"site-images.js","sourceRoot":"","sources":["../src/site-images.ts"],"names":[],"mappings":"AASA,mGAAmG;AACnG,MAAM,MAAM,GAAG,CAAC,IAAY,EAAU,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;AAEvG;;;;;;;GAOG;AACH,MAAM,UAAU,YAAY,CAAC,KAA0C,EAAE,KAA4C;IACnH,IAAI,MAAiD,CAAC;IACtD,MAAM,IAAI,GAAG,GAAkC,EAAE,CAC/C,OAAO,CAAC,GAAG,CACT,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC;QACjD,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC;QAClB,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG;QAC/D,KAAK,EAAE,IAAI,CAAC,KAAK;QACjB,MAAM,EAAE,IAAI,CAAC,MAAM;KACpB,CAAC,CAAC,CACJ,CAAC;IACJ,6DAA6D;IAC7D,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC,MAAM,KAAK,IAAI,EAAE,CAAC,EAAE,CAAC;AAC7C,CAAC"}
@@ -0,0 +1,45 @@
1
+ import type { InvitationMail, Mailer, SignInMail } from '@velocity-astro/cms-auth';
2
+ import { type Cms, type MailFixedBy } from '@velocity-astro/cms-core';
3
+ import type { NoticeMailer, SubmissionNotice } from './form-post.js';
4
+ import { type TestMail } from './resend-mailer.js';
5
+ export interface SiteMailOptions {
6
+ /** The site's settings, where an owner may have said how email is sent. */
7
+ readonly settings: Cms['settings'];
8
+ /** The site's own mailer, from its code (`velocityCms({ mailer })`). It wins over everything. */
9
+ readonly own?: Mailer | undefined;
10
+ /** What sign-in links go to when nothing sends email: the server's log. */
11
+ readonly fallback: Mailer;
12
+ /** What an owner called the site in the editor, or `null`. It is what an email calls the site, when there is one. */
13
+ readonly siteName?: () => Promise<string | null>;
14
+ /** Whether a host runs this site among many, so what is fixed is fixed by the host. */
15
+ readonly hosted?: boolean;
16
+ /** Defaults to the server's own environment. */
17
+ readonly env?: Readonly<Record<string, string | undefined>>;
18
+ /** Defaults to the platform's own `fetch`. */
19
+ readonly fetch?: typeof globalThis.fetch;
20
+ }
21
+ /**
22
+ * How one site's email leaves, decided each time one is sent: the site's own mailer from its
23
+ * code, then Resend from the server's settings, then what an owner set up in the editor, and
24
+ * for sign-in links with none of the three, the server's log. The editor's settings are read
25
+ * from the database for every email, so every running copy follows a change at once, and the
26
+ * key is held only for as long as the email takes.
27
+ */
28
+ export declare class SiteMail implements Mailer, NoticeMailer {
29
+ #private;
30
+ constructor(options: SiteMailOptions);
31
+ /** Who decides how email is sent when the editor's settings do not. */
32
+ fixedBy(): MailFixedBy | null;
33
+ sendSignInLink(mail: SignInMail): Promise<void>;
34
+ sendInvitation(mail: InvitationMail): Promise<void>;
35
+ /** A notice goes through the site's own mailer when it sends notices, and otherwise as the settings say. */
36
+ sendSubmissionNotice(mail: SubmissionNotice): Promise<void>;
37
+ /** Whether email is sent in a way that can send a test. */
38
+ canTest(): Promise<boolean>;
39
+ /**
40
+ * Sends the test. What the provider said goes nowhere but into the words for the owner who
41
+ * asked: which of the two things they typed to look at again.
42
+ */
43
+ sendTest(mail: TestMail): Promise<void>;
44
+ }
45
+ //# sourceMappingURL=site-mail.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"site-mail.d.ts","sourceRo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A4G;IACtG,oBAAoB,CAAC,IAAI,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC;IAOjE,2DAA2D;IACrD,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC;IAIjC;;;OAGG;IACG,QAAQ,CAAC,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;CAyC9C"}
@@ -0,0 +1,84 @@
1
+ import { ConflictError } from '@velocity-astro/cms-core';
2
+ import { MailRefusedError, ResendMailer, mailerFromEnv } from './resend-mailer.js';
3
+ const takesNotices = (mailer) => typeof mailer === 'object' && mailer !== null && typeof mailer.sendSubmissionNotice === 'function';
4
+ const sendsTests = (mailer) => typeof mailer === 'object' && mailer !== null && typeof mailer.sendTest === 'function';
5
+ /**
6
+ * How one site's email leaves, decided each time one is sent: the site's own mailer from its
7
+ * code, then Resend from the server's settings, then what an owner set up in the editor, and
8
+ * for sign-in links with none of the three, the server's log. The editor's settings are read
9
+ * from the database for every email, so every running copy follows a change at once, and the
10
+ * key is held only for as long as the email takes.
11
+ */
12
+ export class SiteMail {
13
+ #options;
14
+ constructor(options) {
15
+ this.#options = options;
16
+ }
17
+ /** Who decides how email is sent when the editor's settings do not. */
18
+ fixedBy() {
19
+ const fixed = this.#options.own ? 'code' : this.#fromServer() ? 'server' : null;
20
+ return fixed !== null && this.#options.hosted === true ? 'host' : fixed;
21
+ }
22
+ async sendSignInLink(mail) {
23
+ await ((await this.#mailer()) ?? this.#options.fallback).sendSignInLink(await this.#named(mail));
24
+ }
25
+ async sendInvitation(mail) {
26
+ await ((await this.#mailer()) ?? this.#options.fallback).sendInvitation(await this.#named(mail));
27
+ }
28
+ /** A notice goes through the site's own mailer when it sends notices, and otherwise as the settings say. */
29
+ async sendSubmissionNotice(mail) {
30
+ const { own } = this.#options;
31
+ const mailer = takesNotices(own) ? own : (this.#fromServer() ?? (await this.#fromEditor()));
32
+ if (!mailer)
33
+ throw new Error('No email provider is set up. Set one up under Settings, Email in the editor.');
34
+ await mailer.sendSubmissionNotice(await this.#named(mail));
35
+ }
36
+ /** Whether email is sent in a way that can send a test. */
37
+ async canTest() {
38
+ return sendsTests(await this.#mailer());
39
+ }
40
+ /**
41
+ * Sends the test. What the provider said goes nowhere but into the words for the owner who
42
+ * asked: which of the two things they typed to look at again.
43
+ */
44
+ async sendTest(mail) {
45
+ const mailer = await this.#mailer();
46
+ if (!sendsTests(mailer))
47
+ throw new ConflictError('No test email can be sent yet. Save an API key and a sender first.');
48
+ try {
49
+ await mailer.sendTest(await this.#named(mail));
50
+ }
51
+ catch (error) {
52
+ if (!(error instanceof MailRefusedError))
53
+ throw new ConflictError('The email service could not be reached, so no test was sent. Try again in a moment.');
54
+ const { status } = error;
55
+ throw new ConflictError(status === 401
56
+ ? 'Resend did not accept the API key (401). Check that it was pasted whole, and that it has not been deleted in Resend.'
57
+ : status === 403
58
+ ? 'Resend refused to send from this sender (403). Verify the sender\'s domain in Resend, and check that the API key may send email.'
59
+ : status === 422
60
+ ? 'Resend did not accept the sender (422). Use an address on a domain you have verified in Resend.'
61
+ : status === 429
62
+ ? 'Resend is turning email away for now (429): too many were sent, or the plan\'s limit is reached. Try again later.'
63
+ : `Resend could not send the test (${status}). Try again in a moment.`);
64
+ }
65
+ }
66
+ /** The email with the site called what an owner called it. A name that cannot be read leaves the email as it was. */
67
+ async #named(mail) {
68
+ const siteName = await this.#options.siteName?.().catch(() => null);
69
+ return siteName ? { ...mail, siteName } : mail;
70
+ }
71
+ async #mailer() {
72
+ return this.#options.own ?? this.#fromServer() ?? (await this.#fromEditor());
73
+ }
74
+ #fromServer() {
75
+ return mailerFromEnv(this.#options.env, this.#options.fetch);
76
+ }
77
+ async #fromEditor() {
78
+ const account = await this.#options.settings.mailAccount();
79
+ if (account === null)
80
+ return undefined;
81
+ return new ResendMailer({ apiKey: account.apiKey, from: account.from, ...(this.#options.fetch && { fetch: this.#options.fetch }) });
82
+ }
83
+ }
84
+ //# sourceMappingURL=site-mail.js.map
@@ -0,0 +1 @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,EAAE,OAAO,CAAC,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC;IACtI,CAAC;CACF"}
@@ -0,0 +1,22 @@
1
+ import { type SiteImage } from '@velocity-astro/cms-core';
2
+ /**
3
+ * The answer to a request for an uploaded file. A file never changes once it is kept and its
4
+ * name is never given to another, so browsers and the CDN may keep it for good.
5
+ *
6
+ * With a width (`/media/kitchen.webp?w=640`, one of `IMAGE_WIDTHS`) the answer is a copy no
7
+ * wider than that. It is made when asked for and kept by the browser and the CDN like the
8
+ * image itself, so a width is made once.
9
+ */
10
+ export declare function uploadedFile(key: string, width?: string | null): Promise<Response>;
11
+ /**
12
+ * Reads the uploaded images again. The site's middleware does this before each page is
13
+ * rendered, so a page never misses an image that was uploaded a moment ago, whichever server
14
+ * renders it.
15
+ */
16
+ export declare function refreshUploadedImages(): Promise<void>;
17
+ /**
18
+ * The uploaded image with this name, as it was when the page began to render: its address on
19
+ * this site and its size. `undefined` when no upload has the name.
20
+ */
21
+ export declare const uploadedImage: (name: string) => SiteImage | undefined;
22
+ //# sourceMappingURL=site-media.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"site-media.d.ts","sourceRoot":"","sources":["../src/site-media.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAIzE;;;;;;;GAOG;AACH,wBAAsB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,QAAQ,CAAC,CAoBxF;AAKD;;;;GAIG;AACH,wBAAsB,qBAAqB,IAAI,OAAO,CAAC,IAAI,CAAC,CAG3D;AAED;;;GAGG;AACH,eAAO,MAAM,aAAa,GAAI,MAAM,MAAM,KAAG,SAAS,GAAG,SAA6C,CAAC"}