@velocity-astro/cms-astro 0.0.0-stage → 0.1.0-beta.2
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.
- package/LICENSE +21 -0
- package/README.md +12 -2
- package/bin/velocity-cms.mjs +6 -0
- package/dist/admin-files.d.ts +21 -0
- package/dist/admin-files.d.ts.map +1 -0
- package/dist/admin-files.js +77 -0
- package/dist/admin-files.js.map +1 -0
- package/dist/cli.d.ts +9 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +75 -0
- package/dist/cli.js.map +1 -0
- package/dist/connection.d.ts +25 -0
- package/dist/connection.d.ts.map +1 -0
- package/dist/connection.js +62 -0
- package/dist/connection.js.map +1 -0
- package/dist/editor.d.ts +65 -0
- package/dist/editor.d.ts.map +1 -0
- package/dist/editor.js +186 -0
- package/dist/editor.js.map +1 -0
- package/dist/entry-page.d.ts +37 -0
- package/dist/entry-page.d.ts.map +1 -0
- package/dist/entry-page.js +56 -0
- package/dist/entry-page.js.map +1 -0
- package/dist/form-post.d.ts +106 -0
- package/dist/form-post.d.ts.map +1 -0
- package/dist/form-post.js +291 -0
- package/dist/form-post.js.map +1 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -0
- package/dist/init.d.ts +33 -0
- package/dist/init.d.ts.map +1 -0
- package/dist/init.js +125 -0
- package/dist/init.js.map +1 -0
- package/dist/integration.d.ts +63 -0
- package/dist/integration.d.ts.map +1 -0
- package/dist/integration.js +129 -0
- package/dist/integration.js.map +1 -0
- package/dist/link.d.ts +32 -0
- package/dist/link.d.ts.map +1 -0
- package/dist/link.js +76 -0
- package/dist/link.js.map +1 -0
- package/dist/live-loader.d.ts +40 -0
- package/dist/live-loader.d.ts.map +1 -0
- package/dist/live-loader.js +92 -0
- package/dist/live-loader.js.map +1 -0
- package/dist/live-pages.d.ts +69 -0
- package/dist/live-pages.d.ts.map +1 -0
- package/dist/live-pages.js +94 -0
- package/dist/live-pages.js.map +1 -0
- package/dist/loader.d.ts +22 -0
- package/dist/loader.d.ts.map +1 -0
- package/dist/loader.js +62 -0
- package/dist/loader.js.map +1 -0
- package/dist/media-store.d.ts +46 -0
- package/dist/media-store.d.ts.map +1 -0
- package/dist/media-store.js +154 -0
- package/dist/media-store.js.map +1 -0
- package/dist/menu.d.ts +51 -0
- package/dist/menu.d.ts.map +1 -0
- package/dist/menu.js +81 -0
- package/dist/menu.js.map +1 -0
- package/dist/page-head.d.ts +23 -0
- package/dist/page-head.d.ts.map +1 -0
- package/dist/page-head.js +66 -0
- package/dist/page-head.js.map +1 -0
- package/dist/preview.d.ts +60 -0
- package/dist/preview.d.ts.map +1 -0
- package/dist/preview.js +126 -0
- package/dist/preview.js.map +1 -0
- package/dist/resend-mailer.d.ts +46 -0
- package/dist/resend-mailer.d.ts.map +1 -0
- package/dist/resend-mailer.js +95 -0
- package/dist/resend-mailer.js.map +1 -0
- package/dist/secret.d.ts +8 -0
- package/dist/secret.d.ts.map +1 -0
- package/dist/secret.js +16 -0
- package/dist/secret.js.map +1 -0
- package/dist/site-editor.d.ts +41 -0
- package/dist/site-editor.d.ts.map +1 -0
- package/dist/site-editor.js +110 -0
- package/dist/site-editor.js.map +1 -0
- package/dist/site-forms.d.ts +43 -0
- package/dist/site-forms.d.ts.map +1 -0
- package/dist/site-forms.js +82 -0
- package/dist/site-forms.js.map +1 -0
- package/dist/site-images.d.ts +17 -0
- package/dist/site-images.d.ts.map +1 -0
- package/dist/site-images.js +22 -0
- package/dist/site-images.js.map +1 -0
- package/dist/site-media.d.ts +18 -0
- package/dist/site-media.d.ts.map +1 -0
- package/dist/site-media.js +43 -0
- package/dist/site-media.js.map +1 -0
- package/dist/site-plugins.d.ts +10 -0
- package/dist/site-plugins.d.ts.map +1 -0
- package/dist/site-plugins.js +23 -0
- package/dist/site-plugins.js.map +1 -0
- package/dist/site-search.d.ts +12 -0
- package/dist/site-search.d.ts.map +1 -0
- package/dist/site-search.js +79 -0
- package/dist/site-search.js.map +1 -0
- package/package.json +53 -3
- package/routes/admin.ts +10 -0
- package/routes/api.ts +15 -0
- package/routes/auth.ts +10 -0
- package/routes/due.ts +12 -0
- package/routes/editor.ts +48 -0
- package/routes/form-client.js.ts +105 -0
- package/routes/media.ts +10 -0
- package/routes/pages.ts +13 -0
- package/routes/plugins.ts +10 -0
- package/routes/preview-client.js.ts +63 -0
- package/routes/published.ts +29 -0
- package/routes/schedule.ts +20 -0
- package/routes/search-client.js.ts +33 -0
- package/routes/search.json.ts +10 -0
- package/routes/share-image.png.ts +33 -0
- package/routes/sitemap-live.xml.ts +13 -0
- package/routes/submit.ts +22 -0
package/dist/menu.d.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { Cms } from '@velocity-astro/cms-core';
|
|
2
|
+
import type { DrawnPage } from './page-head.js';
|
|
3
|
+
/** One link of a menu, ready to be written into a page. */
|
|
4
|
+
export interface MenuLink {
|
|
5
|
+
readonly label: string;
|
|
6
|
+
/** A path on this site, or a whole address when the link leaves it. */
|
|
7
|
+
readonly href: string;
|
|
8
|
+
/** True when the link leaves the site. */
|
|
9
|
+
readonly external: boolean;
|
|
10
|
+
/** What opens under the link, when it has anything: a large menu's columns. Left out otherwise. */
|
|
11
|
+
readonly columns?: readonly MenuColumn[];
|
|
12
|
+
}
|
|
13
|
+
/** One column of the menu that opens under a link: a heading and its own links. */
|
|
14
|
+
export interface MenuColumn {
|
|
15
|
+
readonly title: string;
|
|
16
|
+
readonly links: readonly MenuLink[];
|
|
17
|
+
/**
|
|
18
|
+
* What the template is asked to fill the column with, when the item has a `show` choice: the
|
|
19
|
+
* template's own word for it, such as `neighborhoods`. Left out, the column shows its links.
|
|
20
|
+
*/
|
|
21
|
+
readonly show?: string;
|
|
22
|
+
}
|
|
23
|
+
export interface MenuOptions {
|
|
24
|
+
/** The key of the content type that holds the site's menus, e.g. `navigation`. Its entry in the page's language is read. */
|
|
25
|
+
readonly type: string;
|
|
26
|
+
/** The key of the list field that is the menu, e.g. `header`. Each item is a group with a label and a link. */
|
|
27
|
+
readonly field: string;
|
|
28
|
+
/** The keys of an item's label and link fields. `label` and `link` unless told otherwise. */
|
|
29
|
+
readonly labelKey?: string;
|
|
30
|
+
readonly linkKey?: string;
|
|
31
|
+
/**
|
|
32
|
+
* The key of an item's list of columns: `columns` unless told otherwise. Each column is a group
|
|
33
|
+
* with a `title`, a list of `links` (label and link, as above) and, if the template has columns
|
|
34
|
+
* it fills itself, a `show` choice.
|
|
35
|
+
*/
|
|
36
|
+
readonly columnsKey?: string;
|
|
37
|
+
}
|
|
38
|
+
/** `menuLinks` for a CMS already at hand. `preview` reads the versions being worked on. */
|
|
39
|
+
export declare function menuLinksFrom(cms: Cms, locale: string, options: MenuOptions, preview?: boolean): Promise<MenuLink[]>;
|
|
40
|
+
/**
|
|
41
|
+
* A menu people edit in the CMS, as links ready for the page being drawn:
|
|
42
|
+
*
|
|
43
|
+
* ```astro
|
|
44
|
+
* const links = await menuLinks(Astro, { type: 'navigation', field: 'header' });
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
* It answers with no links when there is no menu in the page's language yet, and also when anything goes wrong: a page
|
|
48
|
+
* is never lost over its menu, and the template shows its own links instead.
|
|
49
|
+
*/
|
|
50
|
+
export declare function menuLinks(page: DrawnPage, options: MenuOptions): Promise<MenuLink[]>;
|
|
51
|
+
//# sourceMappingURL=menu.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"menu.d.ts","sourceRoot":"","sources":["../src/menu.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,0BAA0B,CAAC;AAGpD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAGhD,2DAA2D;AAC3D,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,uEAAuE;IACvE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,0CAA0C;IAC1C,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B,mGAAmG;IACnG,QAAQ,CAAC,OAAO,CAAC,EAAE,SAAS,UAAU,EAAE,CAAC;CAC1C;AAED,mFAAmF;AACnF,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,KAAK,EAAE,SAAS,QAAQ,EAAE,CAAC;IACpC;;;OAGG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,WAAW;IAC1B,4HAA4H;IAC5H,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,+GAA+G;IAC/G,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,6FAA6F;IAC7F,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B;;;;OAIG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;CAC9B;AAID,2FAA2F;AAC3F,wBAAsB,aAAa,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,OAAO,UAAQ,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC,CA+CxH;AAED;;;;;;;;;GASG;AACH,wBAAsB,SAAS,CAAC,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC,CAQ1F"}
|
package/dist/menu.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { sharedConnection } from './connection.js';
|
|
2
|
+
import { DEFAULT_LOCALE, entriesOf, linkResolver } from './link.js';
|
|
3
|
+
import { isPreview, withPreviewDraft } from './preview.js';
|
|
4
|
+
const isRecord = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
5
|
+
/** `menuLinks` for a CMS already at hand. `preview` reads the versions being worked on. */
|
|
6
|
+
export async function menuLinksFrom(cms, locale, options, preview = false) {
|
|
7
|
+
const types = await cms.schema.list();
|
|
8
|
+
const holder = types.find((type) => type.key === options.type);
|
|
9
|
+
if (!holder)
|
|
10
|
+
return [];
|
|
11
|
+
// A language with no menu of its own has no links here, so the template shows its own, in that
|
|
12
|
+
// language. Another language's menu would put the wrong words on every page.
|
|
13
|
+
const menu = (await entriesOf(cms, holder)).find((entry) => entry.locale === locale && (preview || entry.published !== undefined));
|
|
14
|
+
if (!menu)
|
|
15
|
+
return [];
|
|
16
|
+
const items = cms.content.toPublic(holder, withPreviewDraft(menu), preview ? 'working' : 'published').data[options.field];
|
|
17
|
+
if (!Array.isArray(items))
|
|
18
|
+
return [];
|
|
19
|
+
const resolve = linkResolver(cms, locale, preview);
|
|
20
|
+
/** One item as a link, or nothing when it has no label or leads nowhere a visitor can go. */
|
|
21
|
+
const linkOf = async (item) => {
|
|
22
|
+
if (!isRecord(item))
|
|
23
|
+
return undefined;
|
|
24
|
+
const label = item[options.labelKey ?? 'label'];
|
|
25
|
+
const link = item[options.linkKey ?? 'link'];
|
|
26
|
+
if (typeof label !== 'string' || label.trim() === '' || !isRecord(link))
|
|
27
|
+
return undefined;
|
|
28
|
+
const target = await resolve(link);
|
|
29
|
+
return target && { label, ...target };
|
|
30
|
+
};
|
|
31
|
+
const linksOf = async (list) => {
|
|
32
|
+
const found = [];
|
|
33
|
+
for (const item of Array.isArray(list) ? list : []) {
|
|
34
|
+
const link = await linkOf(item);
|
|
35
|
+
if (link)
|
|
36
|
+
found.push(link);
|
|
37
|
+
}
|
|
38
|
+
return found;
|
|
39
|
+
};
|
|
40
|
+
const links = [];
|
|
41
|
+
for (const item of items) {
|
|
42
|
+
const link = await linkOf(item);
|
|
43
|
+
if (!link || !isRecord(item))
|
|
44
|
+
continue;
|
|
45
|
+
const columns = [];
|
|
46
|
+
const described = item[options.columnsKey ?? 'columns'];
|
|
47
|
+
for (const column of Array.isArray(described) ? described : []) {
|
|
48
|
+
if (!isRecord(column))
|
|
49
|
+
continue;
|
|
50
|
+
const title = typeof column['title'] === 'string' ? column['title'] : '';
|
|
51
|
+
const show = typeof column['show'] === 'string' && column['show'] !== 'links' ? column['show'] : undefined;
|
|
52
|
+
const inside = await linksOf(column['links']);
|
|
53
|
+
// A column with nothing in it, and nothing the template fills it with, is left out.
|
|
54
|
+
if (inside.length > 0 || show !== undefined)
|
|
55
|
+
columns.push({ title, links: inside, ...(show !== undefined && { show }) });
|
|
56
|
+
}
|
|
57
|
+
links.push(columns.length > 0 ? { ...link, columns } : link);
|
|
58
|
+
}
|
|
59
|
+
return links;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* A menu people edit in the CMS, as links ready for the page being drawn:
|
|
63
|
+
*
|
|
64
|
+
* ```astro
|
|
65
|
+
* const links = await menuLinks(Astro, { type: 'navigation', field: 'header' });
|
|
66
|
+
* ```
|
|
67
|
+
*
|
|
68
|
+
* It answers with no links when there is no menu in the page's language yet, and also when anything goes wrong: a page
|
|
69
|
+
* is never lost over its menu, and the template shows its own links instead.
|
|
70
|
+
*/
|
|
71
|
+
export async function menuLinks(page, options) {
|
|
72
|
+
try {
|
|
73
|
+
const { cms } = await sharedConnection({});
|
|
74
|
+
return await menuLinksFrom(cms, page.currentLocale ?? DEFAULT_LOCALE, options, isPreview());
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
console.error('[velocity-cms] The menu could not be read, so the template\'s own links are used.', error);
|
|
78
|
+
return [];
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=menu.js.map
|
package/dist/menu.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"menu.js","sourceRoot":"","sources":["../src/menu.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;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;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,IAAe,EAAE,OAAoB;IACnE,IAAI,CAAC;QACH,MAAM,EAAE,GAAG,EAAE,GAAG,MAAM,gBAAgB,CAAC,EAAE,CAAC,CAAC;QAC3C,OAAO,MAAM,aAAa,CAAC,GAAG,EAAE,IAAI,CAAC,aAAa,IAAI,cAAc,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC,CAAC;IAC9F,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,mFAAmF,EAAE,KAAK,CAAC,CAAC;QAC1G,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type Cms, type ContentTypeDef, type PageHead, type PageInfo } from '@velocity-astro/cms-core';
|
|
2
|
+
/** What `pageHead` needs of the page being drawn: `Astro` has both. */
|
|
3
|
+
export interface DrawnPage {
|
|
4
|
+
readonly url: URL;
|
|
5
|
+
readonly currentLocale?: string | undefined;
|
|
6
|
+
}
|
|
7
|
+
/** The entry whose own page is at `path`, if any: the published one, or in a preview the one being worked on. */
|
|
8
|
+
export declare function pageAt(cms: Cms, types: readonly ContentTypeDef[], path: string): Promise<Pick<PageInfo, 'entry' | 'type'> & {
|
|
9
|
+
locale?: string;
|
|
10
|
+
}>;
|
|
11
|
+
/**
|
|
12
|
+
* What the page being drawn should say about itself to search engines, after the site's plugins
|
|
13
|
+
* have had their say. A template calls it where it writes its `<title>` and description:
|
|
14
|
+
*
|
|
15
|
+
* ```astro
|
|
16
|
+
* const head = await pageHead(Astro, { title, description, noindex });
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* It gives back what it was given when no plugin changes anything, and also when anything goes
|
|
20
|
+
* wrong: a page is never lost over its description.
|
|
21
|
+
*/
|
|
22
|
+
export declare function pageHead(page: DrawnPage, head: PageHead): Promise<PageHead>;
|
|
23
|
+
//# sourceMappingURL=page-head.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"page-head.d.ts","sourceRoot":"","sources":["../src/page-head.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiC,KAAK,GAAG,EAAE,KAAK,cAAc,EAAE,KAAK,QAAQ,EAAE,KAAK,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAOtI,uEAAuE;AACvE,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC;IAClB,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC7C;AAmBD,iHAAiH;AACjH,wBAAsB,MAAM,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,SAAS,cAAc,EAAE,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,QAAQ,EAAE,OAAO,GAAG,MAAM,CAAC,GAAG;IAAE,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAYtJ;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,QAAQ,CAAC,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,CAWjF"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { HOME_SLUG, isSlug, isSlugPath } from '@velocity-astro/cms-core';
|
|
2
|
+
import { sharedConnection, SITE } from './connection.js';
|
|
3
|
+
import { isPreview, withPreviewDraft } from './preview.js';
|
|
4
|
+
/** The language of the pages at a type's `urlPattern`. */
|
|
5
|
+
const DEFAULT_LOCALE = 'en';
|
|
6
|
+
/** A type's address pattern as something an address can be tried against: the slug, when it fits. */
|
|
7
|
+
function slugIn(pattern, path) {
|
|
8
|
+
// Only a pattern whose one name is the slug says which entry a page is for. `[...slug]` is a
|
|
9
|
+
// slug that may have several parts, so pages can sit under other pages.
|
|
10
|
+
const name = pattern.includes('[...slug]') ? '[...slug]' : '[slug]';
|
|
11
|
+
if (pattern.replace(name, '').includes('[') || !pattern.includes(name))
|
|
12
|
+
return null;
|
|
13
|
+
const trim = (text) => text.replace(/\/+$/, '');
|
|
14
|
+
const [before = '', after = ''] = trim(pattern).split(name);
|
|
15
|
+
const address = trim(path);
|
|
16
|
+
// The top of a [...slug] pattern is the page called index, and that page has no other address.
|
|
17
|
+
if (name === '[...slug]' && address === trim(trim(before) + after))
|
|
18
|
+
return HOME_SLUG;
|
|
19
|
+
if (!address.startsWith(before) || !address.endsWith(after) || address.length <= before.length + after.length)
|
|
20
|
+
return null;
|
|
21
|
+
const slug = address.slice(before.length, address.length - after.length);
|
|
22
|
+
if (name === '[slug]')
|
|
23
|
+
return isSlug(slug) ? slug : null;
|
|
24
|
+
return isSlugPath(slug) && slug !== HOME_SLUG ? slug : null;
|
|
25
|
+
}
|
|
26
|
+
/** The entry whose own page is at `path`, if any: the published one, or in a preview the one being worked on. */
|
|
27
|
+
export async function pageAt(cms, types, path) {
|
|
28
|
+
for (const type of types) {
|
|
29
|
+
const patterns = [[DEFAULT_LOCALE, type.urlPattern], ...Object.entries(type.localizedUrlPatterns ?? {})];
|
|
30
|
+
for (const [locale, pattern] of patterns) {
|
|
31
|
+
const slug = pattern === undefined ? null : slugIn(pattern, path);
|
|
32
|
+
if (slug === null)
|
|
33
|
+
continue;
|
|
34
|
+
const version = isPreview() ? 'working' : 'published';
|
|
35
|
+
const entry = await cms.content.findBySlug(SITE, { typeId: type.id, locale, slug, version });
|
|
36
|
+
if (entry)
|
|
37
|
+
return { type, locale, entry: cms.content.toPublic(type, withPreviewDraft(entry), version) };
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return {};
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* What the page being drawn should say about itself to search engines, after the site's plugins
|
|
44
|
+
* have had their say. A template calls it where it writes its `<title>` and description:
|
|
45
|
+
*
|
|
46
|
+
* ```astro
|
|
47
|
+
* const head = await pageHead(Astro, { title, description, noindex });
|
|
48
|
+
* ```
|
|
49
|
+
*
|
|
50
|
+
* It gives back what it was given when no plugin changes anything, and also when anything goes
|
|
51
|
+
* wrong: a page is never lost over its description.
|
|
52
|
+
*/
|
|
53
|
+
export async function pageHead(page, head) {
|
|
54
|
+
try {
|
|
55
|
+
const { cms } = await sharedConnection({});
|
|
56
|
+
const path = page.url.pathname;
|
|
57
|
+
const found = await pageAt(cms, await cms.schema.list(), path);
|
|
58
|
+
const { locale = page.currentLocale ?? DEFAULT_LOCALE, ...entry } = found;
|
|
59
|
+
return await cms.pages.run({ path, locale, ...entry }, head);
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
console.error('[velocity-cms] The page head could not be worked out, so the template\'s own is used.', error);
|
|
63
|
+
return head;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=page-head.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"page-head.js","sourceRoot":"","sources":["../src/page-head.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,EAA+D,MAAM,0BAA0B,CAAC;AACtI,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAE3D,0DAA0D;AAC1D,MAAM,cAAc,GAAG,IAAI,CAAC;AAQ5B,qGAAqG;AACrG,SAAS,MAAM,CAAC,OAAe,EAAE,IAAY;IAC3C,6FAA6F;IAC7F,wEAAwE;IACxE,MAAM,IAAI,GAAG,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,QAAQ,CAAC;IACpE,IAAI,OAAO,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC;QAAE,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AAI,CAAC,aAAa,IAAI,cAAc,EAAE,GAAG,KAAK,EAAE,GAAG,KAAK,CAAC;QAC1E,OAAO,MAAM,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,KAAK,EAAE,EAAE,IAAI,CAAC,CAAC;IAC/D,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,uFAAuF,EAAE,KAAK,CAAC,CAAC;QAC9G,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { MiddlewareHandler } from 'astro';
|
|
2
|
+
import { type EntryData } from '@velocity-astro/cms-core';
|
|
3
|
+
/**
|
|
4
|
+
* What someone has typed into one entry and not saved yet. The editor sends it with a preview,
|
|
5
|
+
* so the page beside the form shows the form as it is now. It is drawn once, for the person who
|
|
6
|
+
* sent it, and kept nowhere.
|
|
7
|
+
*/
|
|
8
|
+
export interface PreviewDraft {
|
|
9
|
+
/** The entry it is for. */
|
|
10
|
+
readonly id: string;
|
|
11
|
+
/** The entry's values as the form holds them, by field id. */
|
|
12
|
+
readonly data: EntryData;
|
|
13
|
+
}
|
|
14
|
+
/** True while the page being rendered is a preview: the loaders then read the versions being worked on. */
|
|
15
|
+
export declare const isPreview: () => boolean;
|
|
16
|
+
/** True while the page being rendered is the one beside the editor's form, which marks its sections so a click can find them. */
|
|
17
|
+
export declare const isEditorPreview: () => boolean;
|
|
18
|
+
/**
|
|
19
|
+
* The entry as the preview should show it: with what was typed and not saved, when the preview
|
|
20
|
+
* came with that for this entry. Any other entry, and any entry outside a preview, is given back
|
|
21
|
+
* as it is.
|
|
22
|
+
*/
|
|
23
|
+
export declare function withPreviewDraft<T extends {
|
|
24
|
+
readonly id: string;
|
|
25
|
+
readonly data: EntryData;
|
|
26
|
+
}>(entry: T): T;
|
|
27
|
+
/** Runs `work` as a preview, for tests and for anything that draws a page outside a request. */
|
|
28
|
+
export declare const asPreview: <T>(work: () => T, draft?: PreviewDraft) => T;
|
|
29
|
+
/** The form field the editor sends a draft in. */
|
|
30
|
+
export declare const DRAFT_FIELD = "draft";
|
|
31
|
+
/**
|
|
32
|
+
* Reads the draft the editor posted with a preview. Nothing is read from a request that did not
|
|
33
|
+
* come from the site's own pages, is too large, or is not shaped like a draft: the page is then
|
|
34
|
+
* refused, never drawn from something half understood.
|
|
35
|
+
*/
|
|
36
|
+
export declare function readPreviewDraft(request: Request, site: URL): Promise<PreviewDraft | null>;
|
|
37
|
+
/** The address of the script the page beside the editor's form runs. */
|
|
38
|
+
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;
|
|
41
|
+
/**
|
|
42
|
+
* Adds the token to every link that stays on the site, so the person can click around and stay
|
|
43
|
+
* in the preview. A token is digits, a dot and hex, so it needs no escaping.
|
|
44
|
+
*/
|
|
45
|
+
export declare function keepPreviewInLinks(html: string, token: string): string;
|
|
46
|
+
/** Whether a request is for a page rendered now, which may show uploaded images. */
|
|
47
|
+
export declare const showsContent: (request: Request, pathname: string, isPrerendered: boolean) => boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Turns a request with a valid preview token (`?preview=<token>`) into a preview. Without
|
|
50
|
+
* `VELOCITY_CMS_SECRET` there are no previews at all.
|
|
51
|
+
*
|
|
52
|
+
* The token stays in the address rather than in a cookie, on purpose. A cache, in this server or
|
|
53
|
+
* at a CDN, answers by address before any code runs: with a cookie it would hand the person the
|
|
54
|
+
* public page. An address with a token is one no cache has seen, and it is never stored.
|
|
55
|
+
*
|
|
56
|
+
* A preview is never cached and never indexed, and a request without a valid token is handled
|
|
57
|
+
* exactly as if this middleware were not there.
|
|
58
|
+
*/
|
|
59
|
+
export declare const onRequest: MiddlewareHandler;
|
|
60
|
+
//# sourceMappingURL=preview.d.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;AAID,oFAAoF;AACpF,eAAO,MAAM,YAAY,GAAI,SAAS,OAAO,EAAE,UAAU,MAAM,EAAE,eAAe,OAAO,KAAG,OACjB,CAAC;AAE1E;;;;;;;;;;GAUG;AACH,eAAO,MAAM,SAAS,EAAE,iBA+BvB,CAAC"}
|
package/dist/preview.js
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
|
+
import { PREVIEW_PARAMETER, PreviewLinks } from '@velocity-astro/cms-core';
|
|
3
|
+
import { siteSecret } from './secret.js';
|
|
4
|
+
import { refreshUploadedImages } from './site-media.js';
|
|
5
|
+
const PARAMETER = PREVIEW_PARAMETER;
|
|
6
|
+
const previewing = new AsyncLocalStorage();
|
|
7
|
+
/** True while the page being rendered is a preview: the loaders then read the versions being worked on. */
|
|
8
|
+
export const isPreview = () => previewing.getStore() !== undefined;
|
|
9
|
+
/** True while the page being rendered is the one beside the editor's form, which marks its sections so a click can find them. */
|
|
10
|
+
export const isEditorPreview = () => previewing.getStore()?.draft !== undefined;
|
|
11
|
+
/**
|
|
12
|
+
* The entry as the preview should show it: with what was typed and not saved, when the preview
|
|
13
|
+
* came with that for this entry. Any other entry, and any entry outside a preview, is given back
|
|
14
|
+
* as it is.
|
|
15
|
+
*/
|
|
16
|
+
export function withPreviewDraft(entry) {
|
|
17
|
+
const draft = previewing.getStore()?.draft;
|
|
18
|
+
return draft && draft.id === entry.id ? { ...entry, data: draft.data } : entry;
|
|
19
|
+
}
|
|
20
|
+
/** 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);
|
|
22
|
+
/** The most a draft sent with a preview may weigh. A page's sections are text; a megabyte is a very long page. */
|
|
23
|
+
const DRAFT_LIMIT = 1_000_000;
|
|
24
|
+
/** The form field the editor sends a draft in. */
|
|
25
|
+
export const DRAFT_FIELD = 'draft';
|
|
26
|
+
const isRecord = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
27
|
+
/**
|
|
28
|
+
* Reads the draft the editor posted with a preview. Nothing is read from a request that did not
|
|
29
|
+
* come from the site's own pages, is too large, or is not shaped like a draft: the page is then
|
|
30
|
+
* refused, never drawn from something half understood.
|
|
31
|
+
*/
|
|
32
|
+
export async function readPreviewDraft(request, site) {
|
|
33
|
+
// The browser says where a request came from, and a page cannot change what it says. A proxy
|
|
34
|
+
// in front of the site may change the scheme the site sees, so the host is what is compared.
|
|
35
|
+
const origin = request.headers.get('Origin');
|
|
36
|
+
const isOwn = request.headers.get('Sec-Fetch-Site') === 'same-origin' || (origin !== null && URL.canParse(origin) && new URL(origin).host === site.host);
|
|
37
|
+
if (!isOwn)
|
|
38
|
+
return null;
|
|
39
|
+
if (!(request.headers.get('Content-Type') ?? '').startsWith('application/x-www-form-urlencoded'))
|
|
40
|
+
return null;
|
|
41
|
+
if (Number(request.headers.get('Content-Length') ?? 0) > DRAFT_LIMIT)
|
|
42
|
+
return null;
|
|
43
|
+
const body = await request.text();
|
|
44
|
+
if (body.length > DRAFT_LIMIT)
|
|
45
|
+
return null;
|
|
46
|
+
try {
|
|
47
|
+
const sent = JSON.parse(new URLSearchParams(body).get(DRAFT_FIELD) ?? '');
|
|
48
|
+
if (!isRecord(sent) || typeof sent['id'] !== 'string' || sent['id'] === '' || !isRecord(sent['data']))
|
|
49
|
+
return null;
|
|
50
|
+
return { id: sent['id'], data: sent['data'] };
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/** The address of the script the page beside the editor's form runs. */
|
|
57
|
+
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>`;
|
|
61
|
+
const end = html.lastIndexOf('</body>');
|
|
62
|
+
return end === -1 ? html + tag : html.slice(0, end) + tag + html.slice(end);
|
|
63
|
+
}
|
|
64
|
+
let links;
|
|
65
|
+
function previewLinks() {
|
|
66
|
+
if (links === undefined) {
|
|
67
|
+
const secret = siteSecret();
|
|
68
|
+
links = secret ? new PreviewLinks(secret) : null;
|
|
69
|
+
}
|
|
70
|
+
return links;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Adds the token to every link that stays on the site, so the person can click around and stay
|
|
74
|
+
* in the preview. A token is digits, a dot and hex, so it needs no escaping.
|
|
75
|
+
*/
|
|
76
|
+
export function keepPreviewInLinks(html, token) {
|
|
77
|
+
return html.replace(/(<a\b[^>]*?\shref=")(\/(?!\/)[^"#?]*)(\?[^"#]*)?(#[^"]*)?"/g, (_, start, path, query, hash) => `${start}${path}${query ? `${query}&` : '?'}${PARAMETER}=${token}${hash ?? ''}"`);
|
|
78
|
+
}
|
|
79
|
+
const NOT_PAGES = /^\/(?:api|media|admin|og|_image|_astro|_server-islands|_actions)(?:\/|$)|\.[a-z0-9]+$/;
|
|
80
|
+
/** Whether a request is for a page rendered now, which may show uploaded images. */
|
|
81
|
+
export const showsContent = (request, pathname, isPrerendered) => !isPrerendered && request.method === 'GET' && !NOT_PAGES.test(pathname);
|
|
82
|
+
/**
|
|
83
|
+
* Turns a request with a valid preview token (`?preview=<token>`) into a preview. Without
|
|
84
|
+
* `VELOCITY_CMS_SECRET` there are no previews at all.
|
|
85
|
+
*
|
|
86
|
+
* The token stays in the address rather than in a cookie, on purpose. A cache, in this server or
|
|
87
|
+
* at a CDN, answers by address before any code runs: with a cookie it would hand the person the
|
|
88
|
+
* public page. An address with a token is one no cache has seen, and it is never stored.
|
|
89
|
+
*
|
|
90
|
+
* A preview is never cached and never indexed, and a request without a valid token is handled
|
|
91
|
+
* exactly as if this middleware were not there.
|
|
92
|
+
*/
|
|
93
|
+
export const onRequest = async (context, next) => {
|
|
94
|
+
if (showsContent(context.request, context.url.pathname, context.isPrerendered)) {
|
|
95
|
+
// A page without its newest images is still a page, so a failure here is only logged.
|
|
96
|
+
await refreshUploadedImages().catch((error) => console.error('[velocity-cms] Uploaded images were not read.', error));
|
|
97
|
+
}
|
|
98
|
+
const signer = previewLinks();
|
|
99
|
+
const token = context.url.searchParams.get(PARAMETER);
|
|
100
|
+
if (!signer || token === null || !(await signer.verify(token)))
|
|
101
|
+
return next();
|
|
102
|
+
context.cache.set(false);
|
|
103
|
+
// The editor posts what is in its form, to see the page before saving. Only a preview takes a
|
|
104
|
+
// post, and only one it can read.
|
|
105
|
+
let draft;
|
|
106
|
+
if (context.request.method === 'POST' && !NOT_PAGES.test(context.url.pathname)) {
|
|
107
|
+
const sent = await readPreviewDraft(context.request.clone(), context.url);
|
|
108
|
+
if (!sent)
|
|
109
|
+
return new Response('This preview could not be read. Open it again from the editor.', { status: 400, headers: { 'Cache-Control': 'no-store' } });
|
|
110
|
+
draft = sent;
|
|
111
|
+
}
|
|
112
|
+
// 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 () => {
|
|
114
|
+
const response = await next();
|
|
115
|
+
const headers = new Headers(response.headers);
|
|
116
|
+
headers.set('Cache-Control', 'private, no-store');
|
|
117
|
+
headers.set('X-Robots-Tag', 'noindex');
|
|
118
|
+
headers.set('Referrer-Policy', 'same-origin');
|
|
119
|
+
headers.delete('Content-Length');
|
|
120
|
+
const isHtml = headers.get('Content-Type')?.includes('text/html') === true;
|
|
121
|
+
const page = isHtml ? keepPreviewInLinks(await response.text(), token) : null;
|
|
122
|
+
const body = page === null ? await response.arrayBuffer() : draft ? addEditorScript(page) : page;
|
|
123
|
+
return new Response(body, { status: response.status, statusText: response.statusText, headers });
|
|
124
|
+
});
|
|
125
|
+
};
|
|
126
|
+
//# sourceMappingURL=preview.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"preview.js","sourceRoot":"","sources":["../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,MAAM,IAAI,GAAG,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,MAAM,QAAQ,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QACjG,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"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { InvitationMail, Mailer, SignInMail } from '@velocity-astro/cms-auth';
|
|
2
|
+
import type { NoticeMailer, SubmissionNotice } from './form-post.js';
|
|
3
|
+
/** The words of the emails. Give your own to send them in another language. */
|
|
4
|
+
export interface MailWords {
|
|
5
|
+
readonly signInSubject: (siteName: string) => string;
|
|
6
|
+
readonly signInGreeting: (name: string) => string;
|
|
7
|
+
readonly signInBody: (siteName: string, minutes: number) => string;
|
|
8
|
+
readonly signInButton: string;
|
|
9
|
+
readonly signInIgnore: string;
|
|
10
|
+
readonly invitationSubject: (siteName: string) => string;
|
|
11
|
+
readonly invitationGreeting: (name: string) => string;
|
|
12
|
+
readonly invitationBody: (siteName: string, email: string) => string;
|
|
13
|
+
readonly invitationButton: string;
|
|
14
|
+
/** The notice that a form was filled in. Left out, these are in English. */
|
|
15
|
+
readonly noticeSubject?: (formName: string, siteName: string) => string;
|
|
16
|
+
readonly noticeIntro?: (formName: string, siteName: string) => string;
|
|
17
|
+
readonly noticeSentFrom?: string;
|
|
18
|
+
readonly noticeReply?: string;
|
|
19
|
+
}
|
|
20
|
+
export declare const englishMailWords: MailWords;
|
|
21
|
+
export interface ResendMailerOptions {
|
|
22
|
+
/** A Resend API key that may send email. */
|
|
23
|
+
readonly apiKey: string;
|
|
24
|
+
/** Who the emails come from, on a domain verified with Resend: `Lakeshore Realty <cms@lakeshore.example>`. */
|
|
25
|
+
readonly from: string;
|
|
26
|
+
readonly words?: MailWords;
|
|
27
|
+
/** Defaults to the platform's own `fetch`. */
|
|
28
|
+
readonly fetch?: typeof globalThis.fetch;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Sends the CMS's emails through Resend, over plain HTTP: no SDK, so it runs wherever the site
|
|
32
|
+
* does. A site that uses another provider writes its own `Mailer` the same way.
|
|
33
|
+
*/
|
|
34
|
+
export declare class ResendMailer implements Mailer, NoticeMailer {
|
|
35
|
+
#private;
|
|
36
|
+
constructor(options: ResendMailerOptions);
|
|
37
|
+
sendSignInLink(mail: SignInMail): Promise<void>;
|
|
38
|
+
sendInvitation(mail: InvitationMail): Promise<void>;
|
|
39
|
+
sendSubmissionNotice(mail: SubmissionNotice): Promise<void>;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* The mailer a site gets from its settings alone: Resend when `VELOCITY_CMS_RESEND_API_KEY` and
|
|
43
|
+
* `VELOCITY_CMS_EMAIL_FROM` are both set, otherwise none.
|
|
44
|
+
*/
|
|
45
|
+
export declare function mailerFromEnv(env?: Readonly<Record<string, string | undefined>>): ResendMailer | undefined;
|
|
46
|
+
//# sourceMappingURL=resend-mailer.d.ts.map
|
|
@@ -0,0 +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,+EAA+E;AAC/E,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,aAAa,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,MAAM,CAAC;IACrD,QAAQ,CAAC,cAAc,EAAE,CAAC,IAAI,EAAE,MAAM,KA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AAO,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,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,GAAG,YAAY,GAAG,SAAS,CAIvH"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
export const englishMailWords = {
|
|
2
|
+
signInSubject: (siteName) => `Your sign-in link for ${siteName}`,
|
|
3
|
+
signInGreeting: (name) => `Hi ${name},`,
|
|
4
|
+
signInBody: (siteName, minutes) => `Use the button below to sign in to ${siteName}. The link works once and expires in ${minutes} minutes.`,
|
|
5
|
+
signInButton: 'Sign in',
|
|
6
|
+
signInIgnore: 'If you did not ask for this, you can ignore this email. Nobody can sign in without the link.',
|
|
7
|
+
invitationSubject: (siteName) => `You can now edit ${siteName}`,
|
|
8
|
+
invitationGreeting: (name) => `Hi ${name},`,
|
|
9
|
+
invitationBody: (siteName, email) => `You have been invited to edit ${siteName}. Open the editor and enter ${email}: a sign-in link will be emailed to you. There is no password to set.`,
|
|
10
|
+
invitationButton: 'Open the editor',
|
|
11
|
+
noticeSubject: (formName, siteName) => `New message: ${formName} on ${siteName}`,
|
|
12
|
+
noticeIntro: (formName, siteName) => `Someone filled in "${formName}" on ${siteName}.`,
|
|
13
|
+
noticeSentFrom: 'Sent from',
|
|
14
|
+
noticeReply: 'Reply to this email to answer them. The message is also kept in the CMS.',
|
|
15
|
+
};
|
|
16
|
+
const escaped = (text) => text.replace(/[&<>"']/g, (character) => `&#${character.charCodeAt(0)};`);
|
|
17
|
+
/** One paragraph of greeting, one of explanation, one button, and the address in full under it. */
|
|
18
|
+
function layout(greeting, body, button, url, note) {
|
|
19
|
+
const paragraph = (words) => `<p style="margin:0 0 16px;font:16px/1.5 system-ui,sans-serif;color:#1a1a1a">${escaped(words)}</p>`;
|
|
20
|
+
const html = [
|
|
21
|
+
'<div style="max-width:480px;margin:0 auto;padding:32px 16px">',
|
|
22
|
+
paragraph(greeting),
|
|
23
|
+
paragraph(body),
|
|
24
|
+
`<p style="margin:0 0 24px"><a href="${escaped(url)}" style="display:inline-block;padding:10px 18px;border-radius:8px;background:#111;color:#fff;font:600 16px system-ui,sans-serif;text-decoration:none">${escaped(button)}</a></p>`,
|
|
25
|
+
`<p style="margin:0 0 16px;font:13px/1.5 system-ui,sans-serif;color:#666;word-break:break-all">${escaped(url)}</p>`,
|
|
26
|
+
note === undefined ? '' : `<p style="margin:0;font:13px/1.5 system-ui,sans-serif;color:#666">${escaped(note)}</p>`,
|
|
27
|
+
'</div>',
|
|
28
|
+
].join('');
|
|
29
|
+
const text = [greeting, body, url, ...(note === undefined ? [] : [note])].join('\n\n');
|
|
30
|
+
return { html, text };
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Sends the CMS's emails through Resend, over plain HTTP: no SDK, so it runs wherever the site
|
|
34
|
+
* does. A site that uses another provider writes its own `Mailer` the same way.
|
|
35
|
+
*/
|
|
36
|
+
export class ResendMailer {
|
|
37
|
+
#options;
|
|
38
|
+
#words;
|
|
39
|
+
constructor(options) {
|
|
40
|
+
this.#options = options;
|
|
41
|
+
this.#words = options.words ?? englishMailWords;
|
|
42
|
+
}
|
|
43
|
+
sendSignInLink(mail) {
|
|
44
|
+
const words = this.#words;
|
|
45
|
+
return this.#send(mail.email, words.signInSubject(mail.siteName), layout(words.signInGreeting(mail.name), words.signInBody(mail.siteName, mail.expiresInMinutes), words.signInButton, mail.url, words.signInIgnore));
|
|
46
|
+
}
|
|
47
|
+
sendInvitation(mail) {
|
|
48
|
+
const words = this.#words;
|
|
49
|
+
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
|
+
}
|
|
51
|
+
sendSubmissionNotice(mail) {
|
|
52
|
+
const words = { ...englishMailWords, ...this.#words };
|
|
53
|
+
const intro = words.noticeIntro?.(mail.formName, mail.siteName) ?? '';
|
|
54
|
+
const from = mail.page === undefined ? undefined : `${words.noticeSentFrom ?? ''} ${mail.page}`;
|
|
55
|
+
const note = mail.replyTo === undefined ? undefined : words.noticeReply;
|
|
56
|
+
const line = (style, text) => `<p style="margin:0 0 ${style}">${escaped(text).replace(/\n/g, '<br>')}</p>`;
|
|
57
|
+
// Everything a visitor wrote is escaped, and shown as text: a notice never carries their markup or links.
|
|
58
|
+
const html = [
|
|
59
|
+
'<div style="max-width:480px;margin:0 auto;padding:32px 16px">',
|
|
60
|
+
line('24px;font:16px/1.5 system-ui,sans-serif;color:#1a1a1a', intro),
|
|
61
|
+
...mail.answers.flatMap((answer) => [
|
|
62
|
+
line('2px;font:600 13px/1.5 system-ui,sans-serif;color:#666', answer.label),
|
|
63
|
+
line('16px;font:16px/1.5 system-ui,sans-serif;color:#1a1a1a', answer.value),
|
|
64
|
+
]),
|
|
65
|
+
...[from, note].flatMap((text) => (text === undefined ? [] : [line('8px;font:13px/1.5 system-ui,sans-serif;color:#666;word-break:break-all', text)])),
|
|
66
|
+
'</div>',
|
|
67
|
+
].join('');
|
|
68
|
+
const text = [intro, ...mail.answers.map((answer) => `${answer.label}:\n${answer.value}`), ...(from === undefined ? [] : [from]), ...(note === undefined ? [] : [note])].join('\n\n');
|
|
69
|
+
return this.#send(mail.to, words.noticeSubject?.(mail.formName, mail.siteName) ?? mail.formName, { html, text }, mail.replyTo);
|
|
70
|
+
}
|
|
71
|
+
async #send(to, subject, body, replyTo) {
|
|
72
|
+
const send = this.#options.fetch ?? ((input, init) => globalThis.fetch(input, init));
|
|
73
|
+
const response = await send('https://api.resend.com/emails', {
|
|
74
|
+
method: 'POST',
|
|
75
|
+
headers: { authorization: `Bearer ${this.#options.apiKey}`, 'content-type': 'application/json' },
|
|
76
|
+
body: JSON.stringify({ from: this.#options.from, to: [to], subject, ...body, ...(replyTo !== undefined && { reply_to: replyTo }) }),
|
|
77
|
+
});
|
|
78
|
+
if (!response.ok) {
|
|
79
|
+
// The provider's own words go to the server's log through whoever catches this. The address
|
|
80
|
+
// is left out: a log is not the place for who works on a site.
|
|
81
|
+
const detail = (await response.text().catch(() => '')).slice(0, 300);
|
|
82
|
+
throw new Error(`Resend refused an email (${response.status}). ${detail}`);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* The mailer a site gets from its settings alone: Resend when `VELOCITY_CMS_RESEND_API_KEY` and
|
|
88
|
+
* `VELOCITY_CMS_EMAIL_FROM` are both set, otherwise none.
|
|
89
|
+
*/
|
|
90
|
+
export function mailerFromEnv(env = process.env) {
|
|
91
|
+
const apiKey = env['VELOCITY_CMS_RESEND_API_KEY'];
|
|
92
|
+
const from = env['VELOCITY_CMS_EMAIL_FROM'];
|
|
93
|
+
return apiKey && from ? new ResendMailer({ apiKey, from }) : undefined;
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=resend-mailer.js.map
|
|
@@ -0,0 +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,CA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,MAAM,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;YAChG,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,OAAO,EAAE,GAAG,IAAI,EAAE,GAAG,CAAC,OAAO,KAAK,SAAS,IAAI,EAAE,QAAQ,EAAE,OAAO,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,KAAK,CAAC,4BAA4B,QAAQ,CAAC,MAAM,MAAM,MAAM,EAAE,CAAC,CAAC;QAC7E,CAAC;IACH,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,MAAoD,OAAO,CAAC,GAAG;IAC3F,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,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AACzE,CAAC"}
|
package/dist/secret.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The site's one secret, from `VELOCITY_CMS_SECRET`. It signs preview links and, until the editor
|
|
3
|
+
* exists, proves that a publish notice comes from the site's owner. Without it both are off.
|
|
4
|
+
*/
|
|
5
|
+
export declare const siteSecret: () => string | undefined;
|
|
6
|
+
/** Whether the request carries the secret as a bearer token. */
|
|
7
|
+
export declare function hasSiteSecret(request: Request): boolean;
|
|
8
|
+
//# sourceMappingURL=secret.d.ts.map
|
|
@@ -0,0 +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"}
|