@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/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Southwell Media
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @velocity-astro/cms-astro
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The Astro side of Velocity CMS: a live loader for pages rendered on demand, a Content Layer loader for static builds, and the integration.
|
|
4
|
+
|
|
5
|
+
Part of [Velocity CMS](https://github.com/Velocity-Astro/velocity-cms), a content management system for Astro sites. A site installs `@velocity-astro/cms-astro`, which brings the rest:
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npx velocity-cms init
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Docs: https://docs.deployvelocity.com/cms/
|
|
12
|
+
|
|
13
|
+
MIT
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** What the editor needs to know about the site, written into its page. */
|
|
2
|
+
export interface EditorPageConfig {
|
|
3
|
+
readonly siteName: string;
|
|
4
|
+
readonly adminPath: string;
|
|
5
|
+
readonly apiPath: string;
|
|
6
|
+
readonly authPath: string;
|
|
7
|
+
}
|
|
8
|
+
/** Where `@velocity-astro/cms-admin` keeps the editor it built. */
|
|
9
|
+
export declare const builtEditorDirectory: () => string;
|
|
10
|
+
/**
|
|
11
|
+
* Serves the editor: a page and the files it loads, built ahead of time by `cms-admin`. The
|
|
12
|
+
* files are read once. Only a file that was there at the start can ever be sent, whatever
|
|
13
|
+
* address is asked for.
|
|
14
|
+
*/
|
|
15
|
+
export declare class AdminFiles {
|
|
16
|
+
#private;
|
|
17
|
+
constructor(directory: string, config: EditorPageConfig);
|
|
18
|
+
/** Answers a request for anything under the editor's address. `siteName` is what an owner called the site, when they did. */
|
|
19
|
+
respond(request: Request, siteName?: string | null): Response;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=admin-files.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"admin-files.d.ts","sourceRoot":"","sources":["../src/admin-files.ts"],"names":[],"mappings":"AAIA,2EAA2E;AAC3E,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC3B;AAkCD,mEAAmE;AACnE,eAAO,MAAM,oBAAoB,QAAO,MAAsB,CAAC;AAE/D;;;;GAIG;AACH,qBAAa,UAAU;;gBAMT,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,gBAAgB;IAwBvD,6HAA6H;IAC7H,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,QAAQ;CAkB9D"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { appDirectory } from '@velocity-astro/cms-admin/app-directory';
|
|
4
|
+
const TYPES = {
|
|
5
|
+
'.js': 'text/javascript; charset=utf-8',
|
|
6
|
+
'.css': 'text/css; charset=utf-8',
|
|
7
|
+
'.svg': 'image/svg+xml',
|
|
8
|
+
'.png': 'image/png',
|
|
9
|
+
'.woff2': 'font/woff2',
|
|
10
|
+
'.json': 'application/json; charset=utf-8',
|
|
11
|
+
};
|
|
12
|
+
/** Where the editor's page marks the place for its settings. */
|
|
13
|
+
const MARKER = '<!--velocity-cms-->';
|
|
14
|
+
/**
|
|
15
|
+
* The page may load scripts and styles only from the site itself, and may not be put in a frame.
|
|
16
|
+
* Styles written on elements are allowed because the editor's floating panels place themselves
|
|
17
|
+
* that way; nothing here can run a script.
|
|
18
|
+
*/
|
|
19
|
+
const PAGE_HEADERS = {
|
|
20
|
+
'content-type': 'text/html; charset=utf-8',
|
|
21
|
+
'cache-control': 'no-store',
|
|
22
|
+
'content-security-policy': "default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data: blob:; font-src 'self' data:; frame-ancestors 'none'; base-uri 'self'; form-action 'self'",
|
|
23
|
+
'x-frame-options': 'DENY',
|
|
24
|
+
'x-content-type-options': 'nosniff',
|
|
25
|
+
'referrer-policy': 'same-origin',
|
|
26
|
+
};
|
|
27
|
+
/** Where `@velocity-astro/cms-admin` keeps the editor it built. */
|
|
28
|
+
export const builtEditorDirectory = () => appDirectory;
|
|
29
|
+
/**
|
|
30
|
+
* Serves the editor: a page and the files it loads, built ahead of time by `cms-admin`. The
|
|
31
|
+
* files are read once. Only a file that was there at the start can ever be sent, whatever
|
|
32
|
+
* address is asked for.
|
|
33
|
+
*/
|
|
34
|
+
export class AdminFiles {
|
|
35
|
+
#files = new Map();
|
|
36
|
+
#template;
|
|
37
|
+
#config;
|
|
38
|
+
#adminPath;
|
|
39
|
+
constructor(directory, config) {
|
|
40
|
+
const index = path.join(directory, 'index.html');
|
|
41
|
+
if (!fs.existsSync(index)) {
|
|
42
|
+
throw new Error(`The editor has not been built: ${index} is missing. Run \`pnpm --filter @velocity-astro/cms-admin build:app\`.`);
|
|
43
|
+
}
|
|
44
|
+
for (const name of fs.readdirSync(directory, { recursive: true }).map(String)) {
|
|
45
|
+
const file = path.join(directory, name);
|
|
46
|
+
const type = TYPES[path.extname(name)];
|
|
47
|
+
if (type && fs.statSync(file).isFile())
|
|
48
|
+
this.#files.set(name.replaceAll('\\', '/'), { body: fs.readFileSync(file), type });
|
|
49
|
+
}
|
|
50
|
+
this.#adminPath = config.adminPath;
|
|
51
|
+
this.#config = config;
|
|
52
|
+
this.#template = fs.readFileSync(index, 'utf8');
|
|
53
|
+
}
|
|
54
|
+
/** The editor's page with its settings written in, the site called `siteName` when one is given. */
|
|
55
|
+
#pageFor(siteName) {
|
|
56
|
+
const config = siteName ? { ...this.#config, siteName } : this.#config;
|
|
57
|
+
// `<` is escaped so nothing in a site's name can end the block and start a script.
|
|
58
|
+
const settings = JSON.stringify(config).replaceAll('<', '\\u003c');
|
|
59
|
+
// A function, so nothing in the name is read as a pattern of the replacement.
|
|
60
|
+
return this.#template.replace(MARKER, () => `<base href="${config.adminPath}/" />\n <script type="application/json" id="velocity-cms-config">${settings}</script>`);
|
|
61
|
+
}
|
|
62
|
+
/** Answers a request for anything under the editor's address. `siteName` is what an owner called the site, when they did. */
|
|
63
|
+
respond(request, siteName) {
|
|
64
|
+
if (request.method !== 'GET' && request.method !== 'HEAD') {
|
|
65
|
+
return new Response(null, { status: 405, headers: { allow: 'GET, HEAD' } });
|
|
66
|
+
}
|
|
67
|
+
const { pathname } = new URL(request.url);
|
|
68
|
+
const inside = pathname === this.#adminPath ? '' : pathname.slice(this.#adminPath.length + 1);
|
|
69
|
+
const file = this.#files.get(inside);
|
|
70
|
+
if (file) {
|
|
71
|
+
// File names carry a hash of their content, so a browser may keep them for good.
|
|
72
|
+
return new Response(new Uint8Array(file.body), {
|
|
73
|
+
headers: { 'content-type': file.type, 'cache-control': 'public, max-age=31536000, immutable', 'x-content-type-options': 'nosniff' },
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
// A missing file must not be answered with the page: a browser would try to run it.
|
|
77
|
+
if (inside.startsWith('assets/'))
|
|
78
|
+
return new Response(null, { status: 404 });
|
|
79
|
+
// Every other address is a screen of the editor, which works out which one in the browser.
|
|
80
|
+
return new Response(this.#pageFor(siteName), { headers: PAGE_HEADERS });
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=admin-files.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"admin-files.js","sourceRoot":"","sources":["../src/admin-files.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,YAAY,EAAE,MAAM,yCAAyC,CAAC;AAevE,MAAM,KAAK,GAAqC;IAC9C,KAAK,EAAE,gCAAgC;IACvC,MAAM,EAAE,yBAAyB;IACjC,MAAM,EAAE,eAAe;IACvB,MAAM,EAAE,WAAW;IACnB,QAAQ,EAAE,YAAY;IACtB,OAAO,EAAE,iCAAiC;CAC3C,CAAC;AAEF,gEAAgE;AAChE,MAAM,MAAM,GAAG,qBAAqB,CAAC;AAErC;;;;GAIG;AACH,MAAM,YAAY,GAAG;IACnB,cAAc,EAAE,0BAA0B;IAC1C,eAAe,EAAE,UAAU;IAC3B,yBAAyB,EACvB,yLAAyL;IAC3L,iBAAiB,EAAE,MAAM;IACzB,wBAAwB,EAAE,SAAS;IACnC,iBAAiB,EAAE,aAAa;CACjC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,IAAI,CAAC,EAAE;gBAC7C,OAAO,EAAE,EAAE,cAAc,EAAE,IAAI,CAAC,IAAI,EAAE,eAAe,EAAE,qCAAqC,EAAE,wBAAwB,EAAE,SAAS,EAAE;aACpI,CAAC,CAAC;QACL,CAAC;QACD,oFAAoF;QACpF,IAAI,MAAM,CAAC,UAAU,CAAC,SAAS,CAAC;YAAE,OAAO,IAAI,QAAQ,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC;QAC7E,2FAA2F;QAC3F,OAAO,IAAI,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,EAAE,OAAO,EAAE,YAAY,EAAE,CAAC,CAAC;IAC1E,CAAC;CACF"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { type ChallengeAccount, type ChallengeRoom } from '@velocity-astro/cms-core';
|
|
2
|
+
/** Where Cloudflare Turnstile is asked whether an answer is a person's. The only address a check goes to. */
|
|
3
|
+
export declare const TURNSTILE_VERIFY = "https://challenges.cloudflare.com/turnstile/v0/siteverify";
|
|
4
|
+
/** The host a page with a form loads the challenge from, for a site's content security policy (scripts and frames). */
|
|
5
|
+
export declare const TURNSTILE_HOST = "https://challenges.cloudflare.com";
|
|
6
|
+
/** The script that draws the challenge. `render=explicit`: the form's own script says where. */
|
|
7
|
+
export declare const TURNSTILE_SCRIPT = "https://challenges.cloudflare.com/turnstile/v0/api.js?render=explicit";
|
|
8
|
+
/** The name the challenge's answer is posted under. */
|
|
9
|
+
export declare const FORM_CHALLENGE_FIELD = "cf-turnstile-response";
|
|
10
|
+
/** Says whether what a post carries shows its sender passed the challenge. */
|
|
11
|
+
export interface ChallengeCheck {
|
|
12
|
+
/** True when the sender passed, and when the site asks for no challenge. */
|
|
13
|
+
passed(answer: unknown): Promise<boolean>;
|
|
14
|
+
}
|
|
15
|
+
export interface SiteChallengeOptions {
|
|
16
|
+
/** The challenge an owner set up in the editor's settings, read for each post. */
|
|
17
|
+
readonly account: () => Promise<ChallengeAccount | null>;
|
|
18
|
+
/** Defaults to the platform's own `fetch`. */
|
|
19
|
+
readonly fetch?: typeof globalThis.fetch;
|
|
20
|
+
/** Told when the challenge service could not be asked. Never given what a visitor sent. */
|
|
21
|
+
readonly onFault?: (error: unknown) => void;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Checks a form's sender with the challenge an owner set up (Cloudflare Turnstile). A sender who
|
|
25
|
+
* did not pass is suspected, and what they sent is kept as spam like any other suspected post.
|
|
26
|
+
* A service that cannot be asked, or that does not know the site's key, is never held against a
|
|
27
|
+
* visitor: the other checks still stand, and the fault is told to the log.
|
|
28
|
+
*/
|
|
29
|
+
export declare class SiteChallenge implements ChallengeCheck, ChallengeRoom {
|
|
30
|
+
#private;
|
|
31
|
+
constructor(options: SiteChallengeOptions);
|
|
32
|
+
passed(answer: unknown): Promise<boolean>;
|
|
33
|
+
test(): Promise<void>;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=challenge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"challenge.d.ts","sourceRoot":"","sources":["../src/challenge.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,gBAAgB,EAAE,KAAK,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAEpG,6GAA6G;AAC7G,eAAO,MAAM,gBAAgB,8DAA8D,CAAC;AAC5F,uHAAuH;AACvH,eAAO,MAAM,cAAc,sCAAsC,CAAC;AAClE,gGAAgG;AAChG,eAAO,MAAM,gBAAgB,0EAA0D,CAAC;AACxF,uDAAuD;AACvD,eAAO,MAAM,oBAAoB,0BAA0B,CAAC;AAM5D,8EAA8E;AAC9E,MAAM,WAAW,cAAc;IAC7B,4EAA4E;IAC5E,MAAM,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CAC3C;AAED,MAAM,WAAW,oBAAoB;IACnC,kFAAkF;IAClF,QAAQ,CAAC,OAAO,EAAE,MAAM,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC,CAAC;IACzD,8CAA8C;IAC9C,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;IACzC,2FAA2F;IAC3F,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;CAC7C;AAID;;;;;GAKG;AACH,qBAAa,aAAc,YAAW,cAAc,EAAE,aAAa;;gBAGrD,OAAO,EAAE,oBAAoB;IAInC,MAAM,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IAgBzC,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CA+B5B"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { ConflictError } from '@velocity-astro/cms-core';
|
|
2
|
+
/** Where Cloudflare Turnstile is asked whether an answer is a person's. The only address a check goes to. */
|
|
3
|
+
export const TURNSTILE_VERIFY = 'https://challenges.cloudflare.com/turnstile/v0/siteverify';
|
|
4
|
+
/** The host a page with a form loads the challenge from, for a site's content security policy (scripts and frames). */
|
|
5
|
+
export const TURNSTILE_HOST = 'https://challenges.cloudflare.com';
|
|
6
|
+
/** The script that draws the challenge. `render=explicit`: the form's own script says where. */
|
|
7
|
+
export const TURNSTILE_SCRIPT = `${TURNSTILE_HOST}/turnstile/v0/api.js?render=explicit`;
|
|
8
|
+
/** The name the challenge's answer is posted under. */
|
|
9
|
+
export const FORM_CHALLENGE_FIELD = 'cf-turnstile-response';
|
|
10
|
+
/** The longest answer Turnstile gives. */
|
|
11
|
+
const MAX_ANSWER_LENGTH = 2048;
|
|
12
|
+
/** What a test sends in place of a person's answer. Cloudflare refuses it, and says first whether it knows the key. */
|
|
13
|
+
const TEST_ANSWER = 'velocity-cms-key-check';
|
|
14
|
+
/**
|
|
15
|
+
* Checks a form's sender with the challenge an owner set up (Cloudflare Turnstile). A sender who
|
|
16
|
+
* did not pass is suspected, and what they sent is kept as spam like any other suspected post.
|
|
17
|
+
* A service that cannot be asked, or that does not know the site's key, is never held against a
|
|
18
|
+
* visitor: the other checks still stand, and the fault is told to the log.
|
|
19
|
+
*/
|
|
20
|
+
export class SiteChallenge {
|
|
21
|
+
#options;
|
|
22
|
+
constructor(options) {
|
|
23
|
+
this.#options = options;
|
|
24
|
+
}
|
|
25
|
+
async passed(answer) {
|
|
26
|
+
let account;
|
|
27
|
+
try {
|
|
28
|
+
account = await this.#options.account();
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
this.#options.onFault?.(error);
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
if (account === null)
|
|
35
|
+
return true;
|
|
36
|
+
if (typeof answer !== 'string' || answer === '' || answer.length > MAX_ANSWER_LENGTH)
|
|
37
|
+
return false;
|
|
38
|
+
const verdict = await this.#ask(account.secretKey, answer);
|
|
39
|
+
if (verdict === 'wrong-secret')
|
|
40
|
+
this.#options.onFault?.(new Error('Cloudflare Turnstile does not know the secret key saved under Settings, Forms and spam, so forms are not being checked with it.'));
|
|
41
|
+
if (verdict === 'unreachable')
|
|
42
|
+
this.#options.onFault?.(new Error('Cloudflare Turnstile could not be asked about a form\'s sender, so that post was not checked with it.'));
|
|
43
|
+
return verdict !== 'not-a-person';
|
|
44
|
+
}
|
|
45
|
+
async test() {
|
|
46
|
+
const account = await this.#options.account();
|
|
47
|
+
if (account === null)
|
|
48
|
+
throw new ConflictError('There are no keys to check yet. Save the site key and the secret key first.');
|
|
49
|
+
const verdict = await this.#ask(account.secretKey, TEST_ANSWER);
|
|
50
|
+
if (verdict === 'wrong-secret')
|
|
51
|
+
throw new ConflictError('Cloudflare does not know this secret key. Copy it again from the widget\'s settings in Cloudflare, under Turnstile.');
|
|
52
|
+
if (verdict === 'unreachable')
|
|
53
|
+
throw new ConflictError('Cloudflare could not be reached to check the key. Try again in a moment.');
|
|
54
|
+
}
|
|
55
|
+
/** Asks the one address checks go to. The visitor's own address is not sent along. */
|
|
56
|
+
async #ask(secret, answer) {
|
|
57
|
+
const send = this.#options.fetch ?? ((input, init) => globalThis.fetch(input, init));
|
|
58
|
+
try {
|
|
59
|
+
const response = await send(TURNSTILE_VERIFY, {
|
|
60
|
+
method: 'POST',
|
|
61
|
+
headers: { 'content-type': 'application/x-www-form-urlencoded' },
|
|
62
|
+
body: new URLSearchParams({ secret, response: answer }).toString(),
|
|
63
|
+
redirect: 'error',
|
|
64
|
+
signal: AbortSignal.timeout(5000),
|
|
65
|
+
});
|
|
66
|
+
const body = await response.json();
|
|
67
|
+
if (typeof body !== 'object' || body === null)
|
|
68
|
+
return 'unreachable';
|
|
69
|
+
const { success, 'error-codes': codes } = body;
|
|
70
|
+
if (success === true)
|
|
71
|
+
return 'person';
|
|
72
|
+
const said = Array.isArray(codes) ? codes.filter((code) => typeof code === 'string') : [];
|
|
73
|
+
if (said.includes('invalid-input-secret') || said.includes('missing-input-secret'))
|
|
74
|
+
return 'wrong-secret';
|
|
75
|
+
if (said.includes('internal-error') || success !== false)
|
|
76
|
+
return 'unreachable';
|
|
77
|
+
return 'not-a-person';
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
return 'unreachable';
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=challenge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"challenge.js","sourceRoot":"","sources":["../src/challenge.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAA6C,MAAM,0BAA0B,CAAC;AAEpG,6GAA6G;AAC7G,MAAM,CAAC,MAAM,gBAAgB,GAAG,2DAA2D,CAAC;AAC5F,uHAAuH;AACvH,MAAM,CAAC,MAAM,cAAc,GAAG,mCAAmC,CAAC;AAClE,gGAAgG;AAChG,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAG,cAAc,sCAAsC,CAAC;AACxF,uDAAuD;AACvD,MAAM,CAAC,MAAM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M,IAAI,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAkB,EAAE,CAAC,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;YAC1G,IAAI,IAAI,CAAC,QAAQ,CAAC,sBAAsB,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,sBAAsB,CAAC;gBAAE,OAAO,cAAc,CAAC;YAC1G,IAAI,IAAI,CAAC,QAAQ,CAAC,gBAAgB,CAAC,IAAI,OAAO,KAAK,KAAK;gBAAE,OAAO,aAAa,CAAC;YAC/E,OAAO,cAAc,CAAC;QACxB,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,aAAa,CAAC;QACvB,CAAC;IACH,CAAC;CACF"}
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface CliEnvironment {
|
|
2
|
+
readonly env: Readonly<Record<string, string | undefined>>;
|
|
3
|
+
readonly print: (line: string) => void;
|
|
4
|
+
/** The folder the command is run in. Defaults to the process's own. */
|
|
5
|
+
readonly dir?: string;
|
|
6
|
+
}
|
|
7
|
+
/** The `velocity-cms` command. Returns the exit code. */
|
|
8
|
+
export declare function runCli(args: readonly string[], environment: CliEnvironment): Promise<number>;
|
|
9
|
+
//# sourceMappingURL=cli.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,GAAG,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC;IAC3D,QAAQ,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACvC,uEAAuE;IACvE,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;CACvB;AAWD,yDAAyD;AACzD,wBAAsB,MAAM,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,EAAE,WAAW,EAAE,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC,CAwDlG"}
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { CmsAuth } from '@velocity-astro/cms-auth';
|
|
2
|
+
import { CmsError } from '@velocity-astro/cms-core';
|
|
3
|
+
import { connect } from './connection.js';
|
|
4
|
+
import { LogMailer } from './editor.js';
|
|
5
|
+
import { initSite, runScript } from './init.js';
|
|
6
|
+
const USAGE = `Usage:
|
|
7
|
+
velocity-cms init [<email> <name>] Set this site up for the CMS: a secret in .env, the integration in the
|
|
8
|
+
Astro config. With an email and a name, also create the first owner.
|
|
9
|
+
velocity-cms owner <email> <name> Create the site's first owner and print a link that signs them in.
|
|
10
|
+
velocity-cms link <email> Print a new sign-in link for someone who already has access.
|
|
11
|
+
|
|
12
|
+
Reads VELOCITY_CMS_SECRET, VELOCITY_CMS_ORIGIN (the site's address, such as https://example.com)
|
|
13
|
+
and VELOCITY_CMS_DATABASE_URL from the environment or from a .env file in this folder.`;
|
|
14
|
+
/** The `velocity-cms` command. Returns the exit code. */
|
|
15
|
+
export async function runCli(args, environment) {
|
|
16
|
+
const { print } = environment;
|
|
17
|
+
let { env } = environment;
|
|
18
|
+
const [asked, email, ...nameParts] = args;
|
|
19
|
+
const name = nameParts.join(' ');
|
|
20
|
+
let command = asked;
|
|
21
|
+
const dev = runScript(environment.dir ?? process.cwd(), 'dev');
|
|
22
|
+
if (command === 'init') {
|
|
23
|
+
if (email && !name) {
|
|
24
|
+
print(`Give the owner's name after the address, or leave both out.\n\n${USAGE}`);
|
|
25
|
+
return 1;
|
|
26
|
+
}
|
|
27
|
+
const done = initSite({ dir: environment.dir ?? process.cwd(), print });
|
|
28
|
+
if (done.code !== 0)
|
|
29
|
+
return done.code;
|
|
30
|
+
if (!email) {
|
|
31
|
+
print(`\nNext, make the first owner:\n\n npx velocity-cms owner <email> <name>\n\nThen start the site (\`${dev}\`) and open /admin.`);
|
|
32
|
+
return 0;
|
|
33
|
+
}
|
|
34
|
+
// What init wrote is used at once; what the environment already said still wins.
|
|
35
|
+
env = { ...done.env, ...Object.fromEntries(Object.entries(env).filter(([, value]) => value)) };
|
|
36
|
+
command = 'owner';
|
|
37
|
+
print('');
|
|
38
|
+
}
|
|
39
|
+
const understood = (command === 'owner' && email && name) || (command === 'link' && email && !name);
|
|
40
|
+
if (!understood || !email) {
|
|
41
|
+
print(USAGE);
|
|
42
|
+
return command === undefined || command === 'help' ? 0 : 1;
|
|
43
|
+
}
|
|
44
|
+
const secret = env.VELOCITY_CMS_SECRET;
|
|
45
|
+
const origin = env.VELOCITY_CMS_ORIGIN;
|
|
46
|
+
if (!secret || !origin) {
|
|
47
|
+
print(`${secret ? 'VELOCITY_CMS_ORIGIN' : 'VELOCITY_CMS_SECRET'} is not set.\n\n${USAGE}`);
|
|
48
|
+
return 1;
|
|
49
|
+
}
|
|
50
|
+
const connection = await connect({
|
|
51
|
+
...(env.VELOCITY_CMS_DATABASE_URL && { url: env.VELOCITY_CMS_DATABASE_URL }),
|
|
52
|
+
...(env.VELOCITY_CMS_DATABASE_TOKEN && { authToken: env.VELOCITY_CMS_DATABASE_TOKEN }),
|
|
53
|
+
});
|
|
54
|
+
try {
|
|
55
|
+
const auth = new CmsAuth({ db: connection.db, secret, origin, siteName: 'Velocity CMS', mailer: new LogMailer(print), access: connection.cms.access });
|
|
56
|
+
if (command === 'owner') {
|
|
57
|
+
const { user, link } = await auth.createFirstOwner({ email, name });
|
|
58
|
+
print(`${user.name} <${user.email}> is the site's owner.\n\nOpen this link to sign in. It works once, for 10 minutes:\n\n${link}\n${origin.includes('localhost') ? `\nStart the site first (\`${dev}\`), so the link has somewhere to land.\n` : ''}`);
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
// Whoever holds the link is that person, so it is only ever printed here, for whoever runs the site.
|
|
62
|
+
print(`Open this link to sign in as ${email}. It works once, for 10 minutes:\n\n${await auth.createSignInLink(email)}\n`);
|
|
63
|
+
}
|
|
64
|
+
return 0;
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
if (!(error instanceof CmsError))
|
|
68
|
+
throw error;
|
|
69
|
+
print(error.message);
|
|
70
|
+
return 1;
|
|
71
|
+
}
|
|
72
|
+
finally {
|
|
73
|
+
connection.close();
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAShD,MAAM,KAAK,GAAG;;;;;;;uFAOyE,CAAC;AAExF,yDAAyD;AACzD,MAAM,CAAC,KAAK,UAAU,MAAM,CAAC,IAAuB,EAAE,WAA2B;IAC/E,MAAM,EAAE,KAAK,EAAE,GAAG,WAAW,CAAC;IAC9B,IAAI,EAAE,GAAG,EAAE,GAAG,WAAW,CAAC;IAC1B,MAAM,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,SAAS,CAAC,GAAG,IAAI,CAAC;IAC1C,MAAM,IAAI,GAAG,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACjC,IAAI,OAAO,GAAG,KAAK,CAAC;IACpB,MAAM,GAAG,GAAG,SAAS,CAAC,WAAW,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,EAAE,EAAE,KAAK,CAAC,CA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AC,gBAAgB,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC5H,CAAC;QACD,OAAO,CAAC,CAAC;IACX,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,CAAC,CAAC,KAAK,YAAY,QAAQ,CAAC;YAAE,MAAM,KAAK,CAAC;QAC9C,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACrB,OAAO,CAAC,CAAC;IACX,CAAC;YAAS,CAAC;QACT,UAAU,CAAC,KAAK,EAAE,CAAC;IACrB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type Actor, type Cms, type SearchIndex } from '@velocity-astro/cms-core';
|
|
2
|
+
import { type Db } from '@velocity-astro/cms-db';
|
|
3
|
+
export interface ConnectionOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Where the CMS database is. Defaults to the `VELOCITY_CMS_DATABASE_URL` environment variable,
|
|
6
|
+
* then to `file:./cms/data.db`.
|
|
7
|
+
*/
|
|
8
|
+
readonly url?: string;
|
|
9
|
+
/** The access token of a hosted database. Defaults to `VELOCITY_CMS_DATABASE_TOKEN`. */
|
|
10
|
+
readonly authToken?: string;
|
|
11
|
+
}
|
|
12
|
+
/** The site reads content as itself, with read access only. */
|
|
13
|
+
export declare const SITE: Actor;
|
|
14
|
+
/** Where the database is. On a server that runs many sites it is the site's own, whatever was asked for. */
|
|
15
|
+
export declare const resolveUrl: (options: ConnectionOptions) => string;
|
|
16
|
+
export interface Connection {
|
|
17
|
+
readonly cms: Cms;
|
|
18
|
+
readonly search: SearchIndex;
|
|
19
|
+
/** The database itself, for the packages that keep their own tables in it, such as sign-in. */
|
|
20
|
+
readonly db: Db;
|
|
21
|
+
close(): void;
|
|
22
|
+
}
|
|
23
|
+
export declare function connect(options: ConnectionOptions): Promise<Connection>;
|
|
24
|
+
/** One connection per database for the life of the server, opened on first use. */
|
|
25
|
+
export declare function sharedConnection(options: ConnectionOptions): Promise<Connection>;
|
|
26
|
+
//# sourceMappingURL=connection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../src/connection.ts"],"names":[],"mappings":"AAGA,OAAO,EAAa,KAAK,KAAK,EAAE,KAAK,GAAG,EAAmB,KAAK,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAE9G,OAAO,EAAgS,KAAK,EAAE,EAAE,MAAM,wBAAwB,CAAC;AAS/U,MAAM,WAAW,iBAAiB;IAChC;;;OAGG;IACH,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IACtB,wFAAwF;IACxF,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED,+DAA+D;AAC/D,eAAO,MAAM,IAAI,EAAE,KAAyD,CAAC;AAE7E,4GAA4G;AAC5G,eAAO,MAAM,UAAU,GAAI,SAAS,iBAAiB,KAAG,MACqD,CAAC;AAE9G,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC;IAClB,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;IAC7B,+FAA+F;IAC/F,QAAQ,CAAC,EAAE,EAAE,EAAE,CAAC;IAChB,KAAK,IAAI,IAAI,CAAC;CACf;AAQD,wBAAsB,OAAO,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,UAAU,CAAC,CA6C7E;AAID,mFAAmF;AACnF,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,UAAU,CAAC,CAehF"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { lookup } from 'node:dns/promises';
|
|
2
|
+
import { mkdirSync } from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { createCms } from '@velocity-astro/cms-core';
|
|
5
|
+
import { AuthTeam } from '@velocity-astro/cms-auth/team';
|
|
6
|
+
import { openDatabase, SqliteEntryRepository, SqliteFormRepository, SqliteSubmissionRepository, SqliteContactRepository, SqliteDealRepository, SqlitePipelineStore, SqliteSettingsStore, SqliteCustomFieldsStore, SqliteMediaRepository, SqlitePluginStore, SqliteSchemaRepository, SqliteSearchIndex } from '@velocity-astro/cms-db';
|
|
7
|
+
import { currentSite } from './hosted.js';
|
|
8
|
+
import { SharpImageOptimizer } from './image-optimizer.js';
|
|
9
|
+
import { bucketFromEnv, folderFromEnv } from './media-store.js';
|
|
10
|
+
import { SiteMediaStore } from './site-storage.js';
|
|
11
|
+
import { SiteChallenge } from './challenge.js';
|
|
12
|
+
import { siteSecret } from './secret.js';
|
|
13
|
+
import { allPlugins } from './site-plugins.js';
|
|
14
|
+
/** The site reads content as itself, with read access only. */
|
|
15
|
+
export const SITE = { kind: 'cli', id: 'astro-site', role: 'author' };
|
|
16
|
+
/** Where the database is. On a server that runs many sites it is the site's own, whatever was asked for. */
|
|
17
|
+
export const resolveUrl = (options) => currentSite()?.database.url ?? options.url ?? process.env.VELOCITY_CMS_DATABASE_URL ?? 'file:./cms/data.db';
|
|
18
|
+
/** Every address a host's name leads to, so a plugin can refuse a name that leads to a private machine. */
|
|
19
|
+
const lookUp = async (host) => (await lookup(host, { all: true })).map((found) => found.address);
|
|
20
|
+
/** One for the whole server: it holds a library and nothing of any site. */
|
|
21
|
+
const optimizer = new SharpImageOptimizer();
|
|
22
|
+
export async function connect(options) {
|
|
23
|
+
const site = currentSite();
|
|
24
|
+
const authToken = site ? site.database.authToken : (options.authToken ?? (process.env.VELOCITY_CMS_DATABASE_TOKEN || undefined));
|
|
25
|
+
const url = resolveUrl(options);
|
|
26
|
+
// A database that is a file is made on first use, and so is the folder it sits in.
|
|
27
|
+
const file = /^file:(?!:memory:)([^?]+)/.exec(url)?.[1];
|
|
28
|
+
if (file !== undefined)
|
|
29
|
+
mkdirSync(path.dirname(path.resolve(file.replace(/^\/\/(?=\/)/, ''))), { recursive: true });
|
|
30
|
+
const database = await openDatabase({ url, ...(authToken !== undefined && { authToken }) });
|
|
31
|
+
// A hosted site keeps uploads where its host says, and nowhere a setting of the server names.
|
|
32
|
+
// A site of its own keeps them where the server's settings say, then in the bucket an owner
|
|
33
|
+
// named in the editor, then in a folder beside a database that is a file.
|
|
34
|
+
const store = new SiteMediaStore({
|
|
35
|
+
account: () => cms.settings.bucketAccount(),
|
|
36
|
+
fixed: site ? site.media : bucketFromEnv(),
|
|
37
|
+
hosted: site !== undefined,
|
|
38
|
+
folder: site ? undefined : folderFromEnv(url),
|
|
39
|
+
lookup: lookUp,
|
|
40
|
+
});
|
|
41
|
+
const secret = siteSecret();
|
|
42
|
+
const cms = createCms({
|
|
43
|
+
entries: new SqliteEntryRepository(database.db),
|
|
44
|
+
types: new SqliteSchemaRepository(database.db),
|
|
45
|
+
forms: new SqliteFormRepository(database.db),
|
|
46
|
+
submissions: new SqliteSubmissionRepository(database.db),
|
|
47
|
+
contacts: new SqliteContactRepository(database.db),
|
|
48
|
+
pipeline: new SqlitePipelineStore(database.db),
|
|
49
|
+
settings: new SqliteSettingsStore(database.db),
|
|
50
|
+
customFields: new SqliteCustomFieldsStore(database.db),
|
|
51
|
+
deals: new SqliteDealRepository(database.db),
|
|
52
|
+
team: new AuthTeam(database.db),
|
|
53
|
+
// A secret too short to sign with is the editor's to report, not a reason to read no content.
|
|
54
|
+
...(secret !== undefined && secret.length >= 32 && { previews: { secret } }),
|
|
55
|
+
media: {
|
|
56
|
+
storage: { files: new SqliteMediaRepository(database.db), store },
|
|
57
|
+
optimizer,
|
|
58
|
+
// The image is never logged, only that one could not be handled: the upload is kept as it arrived.
|
|
59
|
+
onOptimizerFault: (error) => console.warn('[velocity-cms] An image could not be made lighter, so it is kept as it is.', error),
|
|
60
|
+
},
|
|
61
|
+
pluginStore: new SqlitePluginStore(database.db),
|
|
62
|
+
lookup: lookUp,
|
|
63
|
+
onPluginFault: (plugin, error) => console.error(`[velocity-cms] The plugin "${plugin}" failed.`, error),
|
|
64
|
+
});
|
|
65
|
+
cms.settings.useStorage(store.room());
|
|
66
|
+
cms.settings.useChallenge(new SiteChallenge({ account: () => cms.settings.challengeAccount() }));
|
|
67
|
+
return { cms, search: new SqliteSearchIndex(database.db), db: database.db, close: () => database.close() };
|
|
68
|
+
}
|
|
69
|
+
const shared = new Map();
|
|
70
|
+
/** One connection per database for the life of the server, opened on first use. */
|
|
71
|
+
export function sharedConnection(options) {
|
|
72
|
+
const url = resolveUrl(options);
|
|
73
|
+
let connection = shared.get(url);
|
|
74
|
+
if (!connection) {
|
|
75
|
+
// The site's plugins, and the ones that come with the CMS, start with its one connection, so a field type they add is known
|
|
76
|
+
// before the first page or the editor reads content.
|
|
77
|
+
connection = connect(options).then(async (opened) => {
|
|
78
|
+
await opened.cms.plugins.load(allPlugins());
|
|
79
|
+
return opened;
|
|
80
|
+
});
|
|
81
|
+
shared.set(url, connection);
|
|
82
|
+
// A failed connection must not be remembered, or every later request would fail too.
|
|
83
|
+
connection.catch(() => shared.delete(url));
|
|
84
|
+
}
|
|
85
|
+
return connection;
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=connection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connection.js","sourceRoot":"","sources":["../src/connection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,SAAS,EAA2D,MAAM,0BAA0B,CAAC;AAC9G,OAAO,EAAE,QAAQ,EAAE,MAAM,+BAA+B,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,0BAA0B,EAAE,uBAAuB,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,uBAAuB,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,iBAAiB,EAAW,MAAM,wBAAwB,CAAC;AAC/U,OAAO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IAAI,aAAa,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,gBAAgB,EAAE,EAAE,CAAC,CAAC,CAAC;IACjG,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,iBAAiB,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,QAAQ,CAAC,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,KAAK,EAAE,EAAE,CAAC;AAC7G,CAAC;AAED,MAAM,MAAM,GAAG,IAAI,GAAG,EAA+B,CAAC;AAEtD,mFAAmF;AACnF,MAAM,UAAU,gBAAgB,CAAC,OAA0B;IACzD,MAAM,GAAG,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC;IAChC,IAAI,UAAU,GAAG,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACjC,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,4HAA4H;QAC5H,qDAAqD;QACrD,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE;YAClD,MAAM,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC;YAC5C,OAAO,MAAM,CAAC;QAChB,CAAC,CAAC,CAAC;QACH,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC;QAC5B,qFAAqF;QACrF,UAAU,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;IAC7C,CAAC;IACD,OAAO,UAAU,CAAC;AACpB,CAAC"}
|
package/dist/editor.d.ts
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { CmsAuth, type InvitationMail, type Mailer, type SignInMail } from '@velocity-astro/cms-auth';
|
|
2
|
+
import { type ImageLibrary } from '@velocity-astro/cms-core';
|
|
3
|
+
import { type Connection } from './connection.js';
|
|
4
|
+
export interface EditorHostOptions {
|
|
5
|
+
readonly connection: Connection;
|
|
6
|
+
/** The site's secret, `VELOCITY_CMS_SECRET`. It signs sessions and sign-in links. */
|
|
7
|
+
readonly secret: string;
|
|
8
|
+
/** The site's own address, such as `https://example.com`. */
|
|
9
|
+
readonly origin: string;
|
|
10
|
+
readonly siteName: string;
|
|
11
|
+
/** What an owner called the site in the editor's settings, or `null`. Asked each time the editor's page is served. */
|
|
12
|
+
readonly siteNameNow?: () => Promise<string | null>;
|
|
13
|
+
readonly mailer: Mailer;
|
|
14
|
+
/** The site's images, for image fields to choose from. */
|
|
15
|
+
readonly images?: ImageLibrary;
|
|
16
|
+
/** Where the editor is served. Defaults to `/admin`. */
|
|
17
|
+
readonly adminPath?: string;
|
|
18
|
+
/** Where the API is served. Defaults to `/api/cms`; sign-in sits under it at `/auth`. */
|
|
19
|
+
readonly apiPath?: string;
|
|
20
|
+
/** Where the built editor is. Defaults to the one `@velocity-astro/cms-admin` ships. */
|
|
21
|
+
readonly editorDirectory?: string;
|
|
22
|
+
/** Told about every fault in the API, which its responses say nothing about. */
|
|
23
|
+
readonly onFault?: (error: unknown) => void;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Prints sign-in links to the server's log instead of sending them. This is the mailer a site
|
|
27
|
+
* has until it sets up its own, and it is enough to work locally: copy the link from the log.
|
|
28
|
+
*/
|
|
29
|
+
export declare class LogMailer implements Mailer {
|
|
30
|
+
private readonly log;
|
|
31
|
+
constructor(log?: (line: string) => void);
|
|
32
|
+
sendSignInLink(mail: SignInMail): Promise<void>;
|
|
33
|
+
sendInvitation(mail: InvitationMail): Promise<void>;
|
|
34
|
+
}
|
|
35
|
+
export declare class EditorHost {
|
|
36
|
+
#private;
|
|
37
|
+
readonly auth: CmsAuth;
|
|
38
|
+
constructor(options: EditorHostOptions);
|
|
39
|
+
/** Answers a request to the API. */
|
|
40
|
+
api(request: Request): Promise<Response>;
|
|
41
|
+
/** Answers a request to one of the sign-in addresses. */
|
|
42
|
+
signIn(request: Request): Promise<Response>;
|
|
43
|
+
/**
|
|
44
|
+
* Answers a request for the editor's page or one of its files, which include the file of each
|
|
45
|
+
* running plugin that adds to the editor. A plugin's file is code the site's owner installed,
|
|
46
|
+
* like the editor's own, and holds nothing private; it is never kept by a browser, so a plugin
|
|
47
|
+
* that is switched off or updated is gone or new on the next load.
|
|
48
|
+
*/
|
|
49
|
+
admin(request: Request): Promise<Response>;
|
|
50
|
+
/**
|
|
51
|
+
* Publishes the entries whose time has come. A site may have no clock of its own, so this is
|
|
52
|
+
* asked on every request and looks at most every half minute; a scheduled job that calls the
|
|
53
|
+
* site (`/api/cms/schedule`) passes `now` to look whenever it asks. It never throws: a page is
|
|
54
|
+
* not lost over a publish that could not be looked for. `takePublished` says what went out.
|
|
55
|
+
*/
|
|
56
|
+
publishDue(options?: {
|
|
57
|
+
readonly now?: boolean;
|
|
58
|
+
}): Promise<void>;
|
|
59
|
+
/**
|
|
60
|
+
* What was published or taken down since this was last asked, and forgets it: `null` when
|
|
61
|
+
* nothing was, otherwise the addresses of the entries' own pages. The caller clears its page
|
|
62
|
+
* cache, since any page may show the entry, and reads those pages again for search. The list
|
|
63
|
+
* is empty for a type that has no address pattern.
|
|
64
|
+
*/
|
|
65
|
+
takePublished(): string[] | null;
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=editor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"editor.d.ts","sourceRoot":"","sources":["../src/editor.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,MAAM,EAAE,KAAK,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtG,OAAO,EAAgD,KAAK,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAE3G,OAAO,EAAQ,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAOxD,MAAM,WAAW,iBAAiB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