@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.
- 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 +83 -0
- package/dist/admin-files.js.map +1 -0
- package/dist/challenge.d.ts +35 -0
- package/dist/challenge.d.ts.map +1 -0
- package/dist/challenge.js +84 -0
- package/dist/challenge.js.map +1 -0
- package/dist/cli.d.ts +9 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +76 -0
- package/dist/cli.js.map +1 -0
- package/dist/connection.d.ts +26 -0
- package/dist/connection.d.ts.map +1 -0
- package/dist/connection.js +87 -0
- package/dist/connection.js.map +1 -0
- package/dist/editor.d.ts +67 -0
- package/dist/editor.d.ts.map +1 -0
- package/dist/editor.js +194 -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 +114 -0
- package/dist/form-post.d.ts.map +1 -0
- package/dist/form-post.js +298 -0
- package/dist/form-post.js.map +1 -0
- package/dist/hosted.d.ts +76 -0
- package/dist/hosted.d.ts.map +1 -0
- package/dist/hosted.js +104 -0
- package/dist/hosted.js.map +1 -0
- package/dist/image-optimizer.d.ts +35 -0
- package/dist/image-optimizer.d.ts.map +1 -0
- package/dist/image-optimizer.js +76 -0
- package/dist/image-optimizer.js.map +1 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +34 -0
- package/dist/index.js.map +1 -0
- package/dist/init.d.ts +35 -0
- package/dist/init.d.ts.map +1 -0
- package/dist/init.js +140 -0
- package/dist/init.js.map +1 -0
- package/dist/integration.d.ts +72 -0
- package/dist/integration.d.ts.map +1 -0
- package/dist/integration.js +143 -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 +80 -0
- package/dist/link.js.map +1 -0
- package/dist/live-loader.d.ts +44 -0
- package/dist/live-loader.d.ts.map +1 -0
- package/dist/live-loader.js +98 -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 +61 -0
- package/dist/media-store.d.ts.map +1 -0
- package/dist/media-store.js +178 -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/page-marks.d.ts +50 -0
- package/dist/page-marks.d.ts.map +1 -0
- package/dist/page-marks.js +90 -0
- package/dist/page-marks.js.map +1 -0
- package/dist/preview.d.ts +92 -0
- package/dist/preview.d.ts.map +1 -0
- package/dist/preview.js +192 -0
- package/dist/preview.js.map +1 -0
- package/dist/resend-mailer.d.ts +63 -0
- package/dist/resend-mailer.d.ts.map +1 -0
- package/dist/resend-mailer.js +116 -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 +17 -0
- package/dist/secret.js.map +1 -0
- package/dist/single.d.ts +18 -0
- package/dist/single.d.ts.map +1 -0
- package/dist/single.js +37 -0
- package/dist/single.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 +140 -0
- package/dist/site-editor.js.map +1 -0
- package/dist/site-forms.d.ts +54 -0
- package/dist/site-forms.d.ts.map +1 -0
- package/dist/site-forms.js +100 -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-mail.d.ts +45 -0
- package/dist/site-mail.d.ts.map +1 -0
- package/dist/site-mail.js +84 -0
- package/dist/site-mail.js.map +1 -0
- package/dist/site-media.d.ts +22 -0
- package/dist/site-media.d.ts.map +1 -0
- package/dist/site-media.js +52 -0
- package/dist/site-media.js.map +1 -0
- package/dist/site-name.d.ts +9 -0
- package/dist/site-name.d.ts.map +1 -0
- package/dist/site-name.js +21 -0
- package/dist/site-name.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/dist/site-storage.d.ts +34 -0
- package/dist/site-storage.d.ts.map +1 -0
- package/dist/site-storage.js +118 -0
- package/dist/site-storage.js.map +1 -0
- package/package.json +56 -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 +49 -0
- package/routes/form-client.js.ts +173 -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 +18 -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 +16 -0
- package/routes/sites.ts +11 -0
- package/routes/submit.ts +22 -0
package/dist/editor.js
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { CmsApi } from '@velocity-astro/cms-api';
|
|
2
|
+
import { CmsAuth } from '@velocity-astro/cms-auth';
|
|
3
|
+
import { pageAddress } from '@velocity-astro/cms-core';
|
|
4
|
+
import { AdminFiles, builtEditorDirectory } from './admin-files.js';
|
|
5
|
+
import { SITE } from './connection.js';
|
|
6
|
+
import { invalidateLiveContent } from './live-loader.js';
|
|
7
|
+
/** The language of the pages at a type's `urlPattern`, as the API and the previews take it. */
|
|
8
|
+
const DEFAULT_LOCALE = 'en';
|
|
9
|
+
const PAGE_SIZE = 500;
|
|
10
|
+
/**
|
|
11
|
+
* Prints sign-in links to the server's log instead of sending them. This is the mailer a site
|
|
12
|
+
* has until it sets up its own, and it is enough to work locally: copy the link from the log.
|
|
13
|
+
*/
|
|
14
|
+
export class LogMailer {
|
|
15
|
+
log;
|
|
16
|
+
constructor(log = (line) => console.info(line)) {
|
|
17
|
+
this.log = log;
|
|
18
|
+
}
|
|
19
|
+
async sendSignInLink(mail) {
|
|
20
|
+
this.log(`[velocity-cms] Sign-in link for ${mail.email} (works once, for ${mail.expiresInMinutes} minutes): ${mail.url}`);
|
|
21
|
+
}
|
|
22
|
+
async sendInvitation(mail) {
|
|
23
|
+
this.log(`[velocity-cms] ${mail.name} (${mail.email}) was invited. No email was sent: tell them to sign in at ${mail.url}`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Everything a site needs to host the editor, wired together: the editor's page, the API it
|
|
28
|
+
* calls and the sign-in behind both, over the site's one database connection. The integration's
|
|
29
|
+
* routes each hand their request to one of the three methods and do nothing else.
|
|
30
|
+
*/
|
|
31
|
+
/** How often entries due to be published are looked for. */
|
|
32
|
+
const DUE_EVERY_MS = 30_000;
|
|
33
|
+
export class EditorHost {
|
|
34
|
+
auth;
|
|
35
|
+
#api;
|
|
36
|
+
#files;
|
|
37
|
+
#pluginFile;
|
|
38
|
+
#plugins;
|
|
39
|
+
#content;
|
|
40
|
+
#onFault;
|
|
41
|
+
#siteNameNow;
|
|
42
|
+
/** When entries due to be published were last looked for. */
|
|
43
|
+
#lookedAt = 0;
|
|
44
|
+
/** Whether anything was published or taken down since `takePublished` was last called. */
|
|
45
|
+
#published = false;
|
|
46
|
+
/** The addresses of the pages that changed with it, where they are known. */
|
|
47
|
+
#changed = new Set();
|
|
48
|
+
constructor(options) {
|
|
49
|
+
const { cms } = options.connection;
|
|
50
|
+
const adminPath = options.adminPath ?? '/admin';
|
|
51
|
+
const apiPath = options.apiPath ?? '/api/cms';
|
|
52
|
+
const authPath = `${apiPath}/auth`;
|
|
53
|
+
this.auth = new CmsAuth({
|
|
54
|
+
db: options.connection.db,
|
|
55
|
+
secret: options.secret,
|
|
56
|
+
origin: options.origin,
|
|
57
|
+
siteName: options.siteName,
|
|
58
|
+
mailer: options.mailer,
|
|
59
|
+
basePath: authPath,
|
|
60
|
+
adminPath,
|
|
61
|
+
access: cms.access,
|
|
62
|
+
});
|
|
63
|
+
if (options.images)
|
|
64
|
+
cms.media.include(options.images);
|
|
65
|
+
this.#api = new CmsApi({
|
|
66
|
+
cms,
|
|
67
|
+
authenticator: this.auth,
|
|
68
|
+
people: this.auth,
|
|
69
|
+
basePath: apiPath,
|
|
70
|
+
...(options.onFault && { onFault: options.onFault }),
|
|
71
|
+
});
|
|
72
|
+
this.#plugins = cms.plugins;
|
|
73
|
+
this.#content = cms.content;
|
|
74
|
+
this.#onFault = options.onFault;
|
|
75
|
+
this.#siteNameNow = options.siteNameNow;
|
|
76
|
+
// `/admin/plugins/<name>.js`: what a running plugin adds to the editor.
|
|
77
|
+
this.#pluginFile = new RegExp(`^${adminPath.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}/plugins/([a-z][a-z0-9-]{0,39})\\.js$`);
|
|
78
|
+
this.#files = new AdminFiles(options.editorDirectory ?? builtEditorDirectory(), { siteName: options.siteName, adminPath, apiPath, authPath });
|
|
79
|
+
// The site keeps what it read from the CMS for a moment. A publish must be seen at once.
|
|
80
|
+
const published = async ({ entry, before }) => {
|
|
81
|
+
invalidateLiveContent();
|
|
82
|
+
this.#published = true;
|
|
83
|
+
const type = await cms.schema.get(entry.typeId).catch(() => null);
|
|
84
|
+
for (const address of addressesOf(type, [entry, before]))
|
|
85
|
+
this.#changed.add(address);
|
|
86
|
+
};
|
|
87
|
+
cms.events.on('entry.published', published);
|
|
88
|
+
cms.events.on('entry.unpublished', published);
|
|
89
|
+
// Archiving a type takes every page of it off the site, and restoring brings them back.
|
|
90
|
+
const shown = async ({ type }) => {
|
|
91
|
+
invalidateLiveContent();
|
|
92
|
+
this.#published = true;
|
|
93
|
+
for (let offset = 0;; offset += PAGE_SIZE) {
|
|
94
|
+
const page = await cms.content.find(SITE, { typeId: type.id, status: 'published', limit: PAGE_SIZE, offset });
|
|
95
|
+
for (const address of addressesOf(type, page.items))
|
|
96
|
+
this.#changed.add(address);
|
|
97
|
+
if (offset + page.items.length >= page.total || page.items.length === 0)
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
// A plugin changed what pages say about themselves: the copies the site kept are stale.
|
|
102
|
+
cms.events.on('pages.changed', () => {
|
|
103
|
+
invalidateLiveContent();
|
|
104
|
+
this.#published = true;
|
|
105
|
+
});
|
|
106
|
+
// A page that draws a form was kept with the form's fields as they were.
|
|
107
|
+
const formChanged = () => {
|
|
108
|
+
invalidateLiveContent();
|
|
109
|
+
this.#published = true;
|
|
110
|
+
};
|
|
111
|
+
cms.events.on('form.saved', formChanged);
|
|
112
|
+
cms.events.on('form.trashed', formChanged);
|
|
113
|
+
cms.events.on('form.restored', formChanged);
|
|
114
|
+
cms.events.on('form.deleted', formChanged);
|
|
115
|
+
// A page that draws a form was kept with or without the challenge an owner has now set up.
|
|
116
|
+
cms.events.on('settings.saved', ({ area }) => {
|
|
117
|
+
if (area === 'forms')
|
|
118
|
+
formChanged();
|
|
119
|
+
});
|
|
120
|
+
cms.events.on('type.archived', shown);
|
|
121
|
+
cms.events.on('type.restored', shown);
|
|
122
|
+
}
|
|
123
|
+
/** Answers a request to the API. */
|
|
124
|
+
api(request) {
|
|
125
|
+
return this.#api.handle(request);
|
|
126
|
+
}
|
|
127
|
+
/** Answers a request to one of the sign-in addresses. */
|
|
128
|
+
signIn(request) {
|
|
129
|
+
return this.auth.handle(request);
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Answers a request for the editor's page or one of its files, which include the file of each
|
|
133
|
+
* running plugin that adds to the editor. A plugin's file is code the site's owner installed,
|
|
134
|
+
* like the editor's own, and holds nothing private; it is never kept by a browser, so a plugin
|
|
135
|
+
* that is switched off or updated is gone or new on the next load.
|
|
136
|
+
*/
|
|
137
|
+
async admin(request) {
|
|
138
|
+
const name = this.#pluginFile.exec(new URL(request.url).pathname)?.[1];
|
|
139
|
+
// A name that cannot be read leaves the page with the one it started with: the editor still opens.
|
|
140
|
+
if (name === undefined)
|
|
141
|
+
return this.#files.respond(request, await this.#siteNameNow?.().catch(() => null));
|
|
142
|
+
if (request.method !== 'GET' && request.method !== 'HEAD')
|
|
143
|
+
return new Response(null, { status: 405, headers: { allow: 'GET, HEAD' } });
|
|
144
|
+
const file = await this.#plugins.editorFile(name);
|
|
145
|
+
// Not the editor's page: a browser asked for a script, and would try to run it.
|
|
146
|
+
if (file === null)
|
|
147
|
+
return new Response(null, { status: 404, headers: { 'cache-control': 'no-store' } });
|
|
148
|
+
return new Response(file, { headers: { 'content-type': 'text/javascript; charset=utf-8', 'cache-control': 'no-store', 'x-content-type-options': 'nosniff' } });
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Publishes the entries whose time has come. A site may have no clock of its own, so this is
|
|
152
|
+
* asked on every request and looks at most every half minute; a scheduled job that calls the
|
|
153
|
+
* site (`/api/cms/schedule`) passes `now` to look whenever it asks. It never throws: a page is
|
|
154
|
+
* not lost over a publish that could not be looked for. `takePublished` says what went out.
|
|
155
|
+
*/
|
|
156
|
+
async publishDue(options = {}) {
|
|
157
|
+
if (options.now !== true && Date.now() - this.#lookedAt < DUE_EVERY_MS)
|
|
158
|
+
return;
|
|
159
|
+
this.#lookedAt = Date.now();
|
|
160
|
+
try {
|
|
161
|
+
await this.#content.publishDue();
|
|
162
|
+
}
|
|
163
|
+
catch (error) {
|
|
164
|
+
this.#onFault?.(error);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* What was published or taken down since this was last asked, and forgets it: `null` when
|
|
169
|
+
* nothing was, otherwise the addresses of the entries' own pages. The caller clears its page
|
|
170
|
+
* cache, since any page may show the entry, and reads those pages again for search. The list
|
|
171
|
+
* is empty for a type that has no address pattern.
|
|
172
|
+
*/
|
|
173
|
+
takePublished() {
|
|
174
|
+
if (!this.#published)
|
|
175
|
+
return null;
|
|
176
|
+
const addresses = [...this.#changed];
|
|
177
|
+
this.#published = false;
|
|
178
|
+
this.#changed.clear();
|
|
179
|
+
return addresses;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Where an entry's own page is, from its type's address pattern: the address visitors find it
|
|
184
|
+
* at now and, if that changed or it was taken down, the one they found it at before. A page in
|
|
185
|
+
* a language the type gives no pattern for is not known here; it is fresh at once all the same,
|
|
186
|
+
* and searched after the next deploy.
|
|
187
|
+
*/
|
|
188
|
+
function addressesOf(type, versions) {
|
|
189
|
+
if (!type)
|
|
190
|
+
return [];
|
|
191
|
+
const at = (entry) => (entry.published ? pageAddress(type, { locale: entry.locale, ...entry.published }, DEFAULT_LOCALE) : null);
|
|
192
|
+
return [...new Set(versions.flatMap((entry) => at(entry) ?? []))];
|
|
193
|
+
}
|
|
194
|
+
//# sourceMappingURL=editor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"editor.js","sourceRoot":"","sources":["../src/editor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AACjD,OAAO,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EAAE,cAAc,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IACxI,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;AACpE,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type Cms, type PublicEntry } from '@velocity-astro/cms-core';
|
|
2
|
+
import { type DrawnPage } from './page-head.js';
|
|
3
|
+
/** An entry found by the address of its own page. */
|
|
4
|
+
export interface EntryPage {
|
|
5
|
+
/** The key of its content type, e.g. `pages`. */
|
|
6
|
+
readonly type: string;
|
|
7
|
+
readonly locale: string;
|
|
8
|
+
/** The entry as the site reads it: values by field key, and each section of a page with its block's key. */
|
|
9
|
+
readonly entry: PublicEntry;
|
|
10
|
+
}
|
|
11
|
+
export interface EntryPageOptions {
|
|
12
|
+
/** The content types to look in, by key. Left out, every type with a page of its own. */
|
|
13
|
+
readonly types?: readonly string[];
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* The entry whose own page is at the address being drawn, or nothing when there is none. It is
|
|
17
|
+
* how one route draws every page people make in the editor:
|
|
18
|
+
*
|
|
19
|
+
* ```astro
|
|
20
|
+
* const page = await entryPage(Astro, { types: ['pages'] });
|
|
21
|
+
* if (!page) return new Response(null, { status: 404 });
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* Visitors get the published version; a preview gets the one being worked on. A fault is thrown,
|
|
25
|
+
* not answered as "no page": a page that exists must never look like one that does not.
|
|
26
|
+
*/
|
|
27
|
+
export declare function entryPage(page: DrawnPage, options?: EntryPageOptions): Promise<EntryPage | undefined>;
|
|
28
|
+
/** `entryPage` for a CMS already at hand. */
|
|
29
|
+
export declare function entryPageAt(cms: Cms, path: string, types?: readonly string[]): Promise<EntryPage | undefined>;
|
|
30
|
+
/**
|
|
31
|
+
* The address of every published page of the content types named, for the sitemap, search and
|
|
32
|
+
* share images. Pages made in the editor have no file the site could have listed them from.
|
|
33
|
+
*/
|
|
34
|
+
export declare function entryPageAddresses(types: readonly string[]): Promise<string[]>;
|
|
35
|
+
/** `entryPageAddresses` for a CMS already at hand. */
|
|
36
|
+
export declare function publishedAddresses(cms: Cms, types: readonly string[]): Promise<string[]>;
|
|
37
|
+
//# sourceMappingURL=entry-page.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entry-page.d.ts","sourceRoot":"","sources":["../src/entry-page.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,KAAK,GAAG,EAAuB,KAAK,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAExG,OAAO,EAAU,KAAK,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAMxD,qDAAqD;AACrD,MAAM,WAAW,SAAS;IACxB,iDAAiD;IACjD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,4GAA4G;IAC5G,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC;CAC7B;AAED,MAAM,WAAW,gBAAgB;IAC/B,yFAAyF;IACzF,QAAQ,CAAC,KAAK,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CACpC;AAID;;;;;;;;;;;GAWG;AACH,wBAAsB,SAAS,CAAC,IAAI,EAAE,SAAS,EAAE,OAAO,GAAE,gBAAqB,GAAG,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC,CAG/G;AAED,6CAA6C;AAC7C,wBAAsB,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC,CAGnH;AAED;;;GAGG;AACH,wBAAsB,kBAAkB,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAIpF;AAED,sDAAsD;AACtD,wBAAsB,kBAAkB,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAa9F"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { pageAddress } from '@velocity-astro/cms-core';
|
|
2
|
+
import { sharedConnection, SITE } from './connection.js';
|
|
3
|
+
import { pageAt } from './page-head.js';
|
|
4
|
+
/** The language of the pages at a type's `urlPattern`. */
|
|
5
|
+
const DEFAULT_LOCALE = 'en';
|
|
6
|
+
const PAGE_SIZE = 500;
|
|
7
|
+
const among = (types, keys) => (keys ? types.filter((type) => keys.includes(type.key)) : types);
|
|
8
|
+
/**
|
|
9
|
+
* The entry whose own page is at the address being drawn, or nothing when there is none. It is
|
|
10
|
+
* how one route draws every page people make in the editor:
|
|
11
|
+
*
|
|
12
|
+
* ```astro
|
|
13
|
+
* const page = await entryPage(Astro, { types: ['pages'] });
|
|
14
|
+
* if (!page) return new Response(null, { status: 404 });
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* Visitors get the published version; a preview gets the one being worked on. A fault is thrown,
|
|
18
|
+
* not answered as "no page": a page that exists must never look like one that does not.
|
|
19
|
+
*/
|
|
20
|
+
export async function entryPage(page, options = {}) {
|
|
21
|
+
const { cms } = await sharedConnection({});
|
|
22
|
+
return entryPageAt(cms, page.url.pathname, options.types);
|
|
23
|
+
}
|
|
24
|
+
/** `entryPage` for a CMS already at hand. */
|
|
25
|
+
export async function entryPageAt(cms, path, types) {
|
|
26
|
+
const found = await pageAt(cms, among(await cms.schema.list(), types), path);
|
|
27
|
+
return found.entry && found.type && found.locale !== undefined ? { type: found.type.key, locale: found.locale, entry: found.entry } : undefined;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The address of every published page of the content types named, for the sitemap, search and
|
|
31
|
+
* share images. Pages made in the editor have no file the site could have listed them from.
|
|
32
|
+
*/
|
|
33
|
+
export async function entryPageAddresses(types) {
|
|
34
|
+
if (types.length === 0)
|
|
35
|
+
return [];
|
|
36
|
+
const { cms } = await sharedConnection({});
|
|
37
|
+
return publishedAddresses(cms, types);
|
|
38
|
+
}
|
|
39
|
+
/** `entryPageAddresses` for a CMS already at hand. */
|
|
40
|
+
export async function publishedAddresses(cms, types) {
|
|
41
|
+
const paths = [];
|
|
42
|
+
for (const type of among(await cms.schema.list(), types)) {
|
|
43
|
+
for (let offset = 0;; offset += PAGE_SIZE) {
|
|
44
|
+
const page = await cms.content.find(SITE, { typeId: type.id, status: 'published', limit: PAGE_SIZE, offset });
|
|
45
|
+
for (const entry of page.items) {
|
|
46
|
+
const address = entry.published && pageAddress(type, { locale: entry.locale, slug: entry.published.slug, data: entry.published.data }, DEFAULT_LOCALE);
|
|
47
|
+
if (address)
|
|
48
|
+
paths.push(address);
|
|
49
|
+
}
|
|
50
|
+
if (offset + page.items.length >= page.total || page.items.length === 0)
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return paths;
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=entry-page.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entry-page.js","sourceRoot":"","sources":["../src/entry-page.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAmD,MAAM,0BAA0B,CAAC;AACxG,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAAE,MAAM,EAAkB,MAAM,gBAAgB,CAAC;AAExD,0DAA0D;AAC1D,MAAM,cAAc,GAAG,IAAI,CAAC;AAC5B,MAAM,SAAS,GAAG,GAAG,CAAC;AAgBtB,MAAM,KAAK,GAAG,CAAC,KAAgC,EAAE,IAAmC,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAA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AAQ,EAAE,KAAwB;IACzE,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,KAAK,CAAC,EAAE,CAAC;QACzD,KAAK,IAAI,MAAM,GAAG,CAAC,GAAI,MAAM,IAAI,SAAS,EAAE,CAAC;YAC3C,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,EAAE,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC,CAAC;YAC9G,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;gBAC/B,MAAM,OAAO,GAAG,KAAK,CAAC,SAAS,IAAI,WAAW,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,IAAI,EAAE,KAAK,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,CAAC,SAAS,CAAC,IAAI,EAAE,EAAE,cAAc,CAAC,CAAC;gBACvJ,IAAI,OAAO;oBAAE,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YACnC,CAAC;YACD,IAAI,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,IAAI,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC;gBAAE,MAAM;QACjF,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { type ChallengeCheck } from './challenge.js';
|
|
2
|
+
import { type Cms, type DealSubject } from '@velocity-astro/cms-core';
|
|
3
|
+
/** The names a form's page sends beside its own fields. A field's key never starts with `_`. */
|
|
4
|
+
export declare const FORM_TRAP_FIELD = "_hp";
|
|
5
|
+
export declare const FORM_TOKEN_FIELD = "_t";
|
|
6
|
+
export declare const FORM_PAGE_FIELD = "_page";
|
|
7
|
+
export declare const FORM_LOCALE_FIELD = "_locale";
|
|
8
|
+
export declare const FORM_ABOUT_FIELD = "_about";
|
|
9
|
+
/** Holds the challenge's site key, so the form's script draws the challenge in a template that knows nothing of it. */
|
|
10
|
+
export declare const FORM_CHALLENGE_KEY_FIELD = "_challenge";
|
|
11
|
+
/** The largest post a form may send: plenty for words, far too little to fill a disk. */
|
|
12
|
+
export declare const MAX_FORM_POST_BYTES: number;
|
|
13
|
+
/** Says whether one more post may be taken from an address. A host with many servers supplies a shared one. */
|
|
14
|
+
export interface RateLimiter {
|
|
15
|
+
/** True when the post may go ahead, which counts it. */
|
|
16
|
+
take(address: string): boolean | Promise<boolean>;
|
|
17
|
+
}
|
|
18
|
+
/** How many posts one address may send in the limiter's stretch of time. */
|
|
19
|
+
export type PostLimit = number | (() => number | Promise<number>);
|
|
20
|
+
/** Counts posts per address in this server's memory: `limit` in any stretch of `windowMs`. */
|
|
21
|
+
export declare class MemoryRateLimiter implements RateLimiter {
|
|
22
|
+
#private;
|
|
23
|
+
private readonly limit;
|
|
24
|
+
private readonly windowMs;
|
|
25
|
+
private readonly now;
|
|
26
|
+
constructor(limit?: number, windowMs?: number, now?: () => number);
|
|
27
|
+
/** `limit` is the most to take from one address just now, when it is not the one this was made with. */
|
|
28
|
+
take(address: string, limit?: number): boolean;
|
|
29
|
+
}
|
|
30
|
+
/** Word to one of a form's people that it was filled in. */
|
|
31
|
+
export interface SubmissionNotice {
|
|
32
|
+
readonly to: string;
|
|
33
|
+
readonly siteName: string;
|
|
34
|
+
/** What the form is called. */
|
|
35
|
+
readonly formName: string;
|
|
36
|
+
/** Each answer, under its field's label, in the form's order. */
|
|
37
|
+
readonly answers: readonly {
|
|
38
|
+
readonly label: string;
|
|
39
|
+
readonly value: string;
|
|
40
|
+
}[];
|
|
41
|
+
/** The whole address of the page it was sent from. */
|
|
42
|
+
readonly page?: string;
|
|
43
|
+
/** The sender's email, so that a reply to the notice goes to them. */
|
|
44
|
+
readonly replyTo?: string;
|
|
45
|
+
}
|
|
46
|
+
/** Delivers notices of submissions. A site's mailer that has this method is used for them. */
|
|
47
|
+
export interface NoticeMailer {
|
|
48
|
+
sendSubmissionNotice(mail: SubmissionNotice): Promise<void>;
|
|
49
|
+
}
|
|
50
|
+
/** The words of the pages a visitor without scripts is shown. Give your own for another language. */
|
|
51
|
+
export interface FormPostWords {
|
|
52
|
+
readonly sentTitle: string;
|
|
53
|
+
readonly sentMessage: string;
|
|
54
|
+
readonly problemsTitle: string;
|
|
55
|
+
readonly problemsHelp: string;
|
|
56
|
+
readonly back: string;
|
|
57
|
+
readonly tooMany: string;
|
|
58
|
+
readonly tooLarge: string;
|
|
59
|
+
readonly notAForm: string;
|
|
60
|
+
readonly elsewhere: string;
|
|
61
|
+
}
|
|
62
|
+
export declare const englishFormPostWords: FormPostWords;
|
|
63
|
+
export interface FormPostsOptions {
|
|
64
|
+
readonly cms: Cms;
|
|
65
|
+
/**
|
|
66
|
+
* The site's own address, which a post must come from when it says where it comes from. A
|
|
67
|
+
* function is asked for each post, for a site in development that has no fixed address yet.
|
|
68
|
+
*/
|
|
69
|
+
readonly origin: string | ((request: Request) => string);
|
|
70
|
+
readonly siteName: string;
|
|
71
|
+
/** The site's secret. It signs the mark that says when a form was drawn. Without it that check is off. */
|
|
72
|
+
readonly secret?: string | undefined;
|
|
73
|
+
/** Who delivers notices. Without one nobody is emailed; submissions are kept all the same. */
|
|
74
|
+
readonly mailer?: NoticeMailer | undefined;
|
|
75
|
+
readonly limiter?: RateLimiter;
|
|
76
|
+
/** Checks that a post's sender passed the site's challenge. Without one no challenge is asked. */
|
|
77
|
+
readonly challenge?: ChallengeCheck;
|
|
78
|
+
/**
|
|
79
|
+
* The entry whose own page is at a path of the site, if any, so that what is sent from a
|
|
80
|
+
* listing's page is known to be about that listing. Asked only when the form's page did not
|
|
81
|
+
* say, with a signed mark, which entry it is about.
|
|
82
|
+
*/
|
|
83
|
+
readonly entryAt?: (path: string) => Promise<DealSubject | undefined>;
|
|
84
|
+
readonly words?: FormPostWords;
|
|
85
|
+
readonly now?: () => number;
|
|
86
|
+
/** Told what went wrong when a notice could not be sent. Never given what a visitor wrote. */
|
|
87
|
+
readonly onFault?: (error: unknown) => void;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Takes what visitors send through the site's forms. It is the one address of the CMS that
|
|
91
|
+
* anyone may post to, so it is narrow: a small body, only from the site's own pages, only so
|
|
92
|
+
* many from one address, and nothing that was sent is ever written back into a page.
|
|
93
|
+
*/
|
|
94
|
+
export declare class FormPosts {
|
|
95
|
+
#private;
|
|
96
|
+
constructor(options: FormPostsOptions);
|
|
97
|
+
/**
|
|
98
|
+
* The mark a form's page sends back with a post: when the form was drawn, signed. A post
|
|
99
|
+
* without a true one, or one that follows it too closely, did not come from a person filling
|
|
100
|
+
* in the page. `undefined` when the site has no secret to sign with.
|
|
101
|
+
*/
|
|
102
|
+
token(formKey: string): Promise<string | undefined>;
|
|
103
|
+
/** Answers a post to a form's address. `address` is where it came from, when the server knows. */
|
|
104
|
+
handle(request: Request, formKey: string, address?: string): Promise<Response>;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* The mark a form's page sends along to say which entry it is about, signed with the site's
|
|
108
|
+
* secret so that only the site's own pages can say it. `undefined` without a secret, or for ids
|
|
109
|
+
* a mark cannot carry.
|
|
110
|
+
*/
|
|
111
|
+
export declare function aboutMark(secret: string | undefined, formKey: string, about: DealSubject): Promise<string | undefined>;
|
|
112
|
+
/** The mark for a form drawn at `drawn`, signed with the site's secret. `undefined` without a secret. */
|
|
113
|
+
export declare function formToken(secret: string | undefined, formKey: string, drawn?: number): Promise<string | undefined>;
|
|
114
|
+
//# sourceMappingURL=form-post.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"form-post.d.ts","sourceRoot":"","sources":["../src/form-post.ts"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