inlaycms 0.0.0-stage → 0.2.0
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 +469 -2
- package/assets/admin/admin.css +2 -0
- package/assets/admin/admin.js +1 -0
- package/assets/admin/editor.js +125 -0
- package/dist/adapters/admin/activity.d.ts +17 -0
- package/dist/adapters/admin/activity.js +59 -0
- package/dist/adapters/admin/assets.d.ts +14 -0
- package/dist/adapters/admin/assets.js +64 -0
- package/dist/adapters/admin/attention.d.ts +15 -0
- package/dist/adapters/admin/attention.js +34 -0
- package/dist/adapters/admin/context.d.ts +40 -0
- package/dist/adapters/admin/context.js +142 -0
- package/dist/adapters/admin/form/walk.d.ts +61 -0
- package/dist/adapters/admin/form/walk.js +565 -0
- package/dist/adapters/admin/pages.d.ts +38 -0
- package/dist/adapters/admin/pages.js +66 -0
- package/dist/adapters/admin/publish.d.ts +12 -0
- package/dist/adapters/admin/publish.js +195 -0
- package/dist/adapters/admin/routes.d.ts +47 -0
- package/dist/adapters/admin/routes.js +255 -0
- package/dist/adapters/admin/screens/backups.d.ts +11 -0
- package/dist/adapters/admin/screens/backups.js +223 -0
- package/dist/adapters/admin/screens/dashboard.d.ts +4 -0
- package/dist/adapters/admin/screens/dashboard.js +160 -0
- package/dist/adapters/admin/screens/editor.d.ts +67 -0
- package/dist/adapters/admin/screens/editor.js +416 -0
- package/dist/adapters/admin/screens/history.d.ts +4 -0
- package/dist/adapters/admin/screens/history.js +105 -0
- package/dist/adapters/admin/screens/lists.d.ts +4 -0
- package/dist/adapters/admin/screens/lists.js +297 -0
- package/dist/adapters/admin/screens/media.d.ts +20 -0
- package/dist/adapters/admin/screens/media.js +186 -0
- package/dist/adapters/admin/screens/pickers.d.ts +29 -0
- package/dist/adapters/admin/screens/pickers.js +134 -0
- package/dist/adapters/admin/screens/preview-pane.d.ts +10 -0
- package/dist/adapters/admin/screens/preview-pane.js +74 -0
- package/dist/adapters/admin/screens/redirects.d.ts +4 -0
- package/dist/adapters/admin/screens/redirects.js +137 -0
- package/dist/adapters/admin/screens/releases.d.ts +7 -0
- package/dist/adapters/admin/screens/releases.js +287 -0
- package/dist/adapters/admin/screens/search.d.ts +22 -0
- package/dist/adapters/admin/screens/search.js +113 -0
- package/dist/adapters/admin/screens/security.d.ts +4 -0
- package/dist/adapters/admin/screens/security.js +85 -0
- package/dist/adapters/admin/screens/users.d.ts +4 -0
- package/dist/adapters/admin/screens/users.js +330 -0
- package/dist/adapters/admin/theme.d.ts +1 -0
- package/dist/adapters/admin/theme.js +1 -0
- package/dist/adapters/admin/translations.d.ts +16 -0
- package/dist/adapters/admin/translations.js +23 -0
- package/dist/adapters/admin/upload.d.ts +8 -0
- package/dist/adapters/admin/upload.js +116 -0
- package/dist/adapters/admin/views/data-table.d.ts +82 -0
- package/dist/adapters/admin/views/data-table.js +117 -0
- package/dist/adapters/admin/views/icons.d.ts +48 -0
- package/dist/adapters/admin/views/icons.js +47 -0
- package/dist/adapters/admin/views/layout.d.ts +51 -0
- package/dist/adapters/admin/views/layout.js +145 -0
- package/dist/adapters/admin/views/sheet.d.ts +15 -0
- package/dist/adapters/admin/views/sheet.js +6 -0
- package/dist/adapters/admin/views/status.d.ts +32 -0
- package/dist/adapters/admin/views/status.js +74 -0
- package/dist/adapters/auth/handler.d.ts +10 -0
- package/dist/adapters/auth/handler.js +63 -0
- package/dist/adapters/auth/request.d.ts +8 -0
- package/dist/adapters/auth/request.js +14 -0
- package/dist/adapters/cli/bin.d.ts +2 -0
- package/dist/adapters/cli/bin.js +42 -0
- package/dist/adapters/cli/main.d.ts +7 -0
- package/dist/adapters/cli/main.js +982 -0
- package/dist/adapters/cli/remote.d.ts +52 -0
- package/dist/adapters/cli/remote.js +161 -0
- package/dist/adapters/mcp/agent-refs.d.ts +9 -0
- package/dist/adapters/mcp/agent-refs.js +25 -0
- package/dist/adapters/mcp/documents.d.ts +15 -0
- package/dist/adapters/mcp/documents.js +26 -0
- package/dist/adapters/mcp/fetch-url.d.ts +19 -0
- package/dist/adapters/mcp/fetch-url.js +244 -0
- package/dist/adapters/mcp/request-state.d.ts +15 -0
- package/dist/adapters/mcp/request-state.js +38 -0
- package/dist/adapters/mcp/results.d.ts +20 -0
- package/dist/adapters/mcp/results.js +61 -0
- package/dist/adapters/mcp/route.d.ts +34 -0
- package/dist/adapters/mcp/route.js +52 -0
- package/dist/adapters/mcp/server.d.ts +44 -0
- package/dist/adapters/mcp/server.js +49 -0
- package/dist/adapters/mcp/tools/history.d.ts +5 -0
- package/dist/adapters/mcp/tools/history.js +84 -0
- package/dist/adapters/mcp/tools/media.d.ts +5 -0
- package/dist/adapters/mcp/tools/media.js +102 -0
- package/dist/adapters/mcp/tools/publish.d.ts +5 -0
- package/dist/adapters/mcp/tools/publish.js +157 -0
- package/dist/adapters/mcp/tools/read.d.ts +5 -0
- package/dist/adapters/mcp/tools/read.js +279 -0
- package/dist/adapters/mcp/tools/redirects.d.ts +5 -0
- package/dist/adapters/mcp/tools/redirects.js +74 -0
- package/dist/adapters/mcp/tools/write.d.ts +5 -0
- package/dist/adapters/mcp/tools/write.js +304 -0
- package/dist/adapters/site/backup-schedule.d.ts +8 -0
- package/dist/adapters/site/backup-schedule.js +31 -0
- package/dist/adapters/site/cache.d.ts +29 -0
- package/dist/adapters/site/cache.js +63 -0
- package/dist/adapters/site/context.d.ts +29 -0
- package/dist/adapters/site/context.js +278 -0
- package/dist/adapters/site/head.d.ts +23 -0
- package/dist/adapters/site/head.js +44 -0
- package/dist/adapters/site/limiter.d.ts +17 -0
- package/dist/adapters/site/limiter.js +39 -0
- package/dist/adapters/site/lock.d.ts +30 -0
- package/dist/adapters/site/lock.js +143 -0
- package/dist/adapters/site/media-routes.d.ts +4 -0
- package/dist/adapters/site/media-routes.js +55 -0
- package/dist/adapters/site/plugin.d.ts +122 -0
- package/dist/adapters/site/plugin.js +436 -0
- package/dist/adapters/site/preview.d.ts +36 -0
- package/dist/adapters/site/preview.js +82 -0
- package/dist/adapters/site/public.d.ts +6 -0
- package/dist/adapters/site/public.js +87 -0
- package/dist/adapters/site/render.d.ts +45 -0
- package/dist/adapters/site/render.js +191 -0
- package/dist/adapters/site/routes.d.ts +17 -0
- package/dist/adapters/site/routes.js +125 -0
- package/dist/adapters/site/sitemap.d.ts +10 -0
- package/dist/adapters/site/sitemap.js +10 -0
- package/dist/adapters/web.d.ts +22 -0
- package/dist/adapters/web.js +75 -0
- package/dist/config.d.ts +21 -0
- package/dist/config.js +58 -0
- package/dist/core/agent/format.d.ts +62 -0
- package/dist/core/agent/format.js +211 -0
- package/dist/core/agent/schema.d.ts +6 -0
- package/dist/core/agent/schema.js +86 -0
- package/dist/core/archive.d.ts +12 -0
- package/dist/core/archive.js +72 -0
- package/dist/core/auth/auth.d.ts +4911 -0
- package/dist/core/auth/auth.js +61 -0
- package/dist/core/auth/roles.d.ts +10 -0
- package/dist/core/auth/roles.js +38 -0
- package/dist/core/auth/service.d.ts +118 -0
- package/dist/core/auth/service.js +424 -0
- package/dist/core/auth/upload-token.d.ts +8 -0
- package/dist/core/auth/upload-token.js +27 -0
- package/dist/core/backup/backup.d.ts +28 -0
- package/dist/core/backup/backup.js +126 -0
- package/dist/core/backup/restore.d.ts +41 -0
- package/dist/core/backup/restore.js +264 -0
- package/dist/core/backup/schedule.d.ts +12 -0
- package/dist/core/backup/schedule.js +29 -0
- package/dist/core/boot.d.ts +63 -0
- package/dist/core/boot.js +141 -0
- package/dist/core/check.d.ts +32 -0
- package/dist/core/check.js +111 -0
- package/dist/core/content/activity.d.ts +8 -0
- package/dist/core/content/activity.js +101 -0
- package/dist/core/content/delete.d.ts +5 -0
- package/dist/core/content/delete.js +100 -0
- package/dist/core/content/diff.d.ts +6 -0
- package/dist/core/content/diff.js +129 -0
- package/dist/core/content/dry-run.d.ts +24 -0
- package/dist/core/content/dry-run.js +69 -0
- package/dist/core/content/gaps.d.ts +25 -0
- package/dist/core/content/gaps.js +50 -0
- package/dist/core/content/hidden.d.ts +33 -0
- package/dist/core/content/hidden.js +103 -0
- package/dist/core/content/history.d.ts +15 -0
- package/dist/core/content/history.js +62 -0
- package/dist/core/content/patch.d.ts +40 -0
- package/dist/core/content/patch.js +287 -0
- package/dist/core/content/path.d.ts +6 -0
- package/dist/core/content/path.js +38 -0
- package/dist/core/content/publish.d.ts +26 -0
- package/dist/core/content/publish.js +211 -0
- package/dist/core/content/read.d.ts +99 -0
- package/dist/core/content/read.js +141 -0
- package/dist/core/content/reader.d.ts +37 -0
- package/dist/core/content/reader.js +195 -0
- package/dist/core/content/refs.d.ts +44 -0
- package/dist/core/content/refs.js +161 -0
- package/dist/core/content/release-migrations.d.ts +12 -0
- package/dist/core/content/release-migrations.js +154 -0
- package/dist/core/content/save.d.ts +25 -0
- package/dist/core/content/save.js +87 -0
- package/dist/core/content/schema.d.ts +22 -0
- package/dist/core/content/schema.js +127 -0
- package/dist/core/content/search.d.ts +8 -0
- package/dist/core/content/search.js +89 -0
- package/dist/core/content/shipped-input.d.ts +39 -0
- package/dist/core/content/shipped-input.js +221 -0
- package/dist/core/content/shipped.d.ts +112 -0
- package/dist/core/content/shipped.js +437 -0
- package/dist/core/content/slug.d.ts +23 -0
- package/dist/core/content/slug.js +182 -0
- package/dist/core/content/stats.d.ts +11 -0
- package/dist/core/content/stats.js +30 -0
- package/dist/core/content/translate.d.ts +3 -0
- package/dist/core/content/translate.js +68 -0
- package/dist/core/content/usages.d.ts +13 -0
- package/dist/core/content/usages.js +70 -0
- package/dist/core/content/validate.d.ts +21 -0
- package/dist/core/content/validate.js +124 -0
- package/dist/core/content/write.d.ts +10 -0
- package/dist/core/content/write.js +93 -0
- package/dist/core/core.d.ts +227 -0
- package/dist/core/core.js +251 -0
- package/dist/core/db/connection.d.ts +6 -0
- package/dist/core/db/connection.js +12 -0
- package/dist/core/db/migrate.d.ts +9 -0
- package/dist/core/db/migrate.js +42 -0
- package/dist/core/db/migrations/0001_content.d.ts +2 -0
- package/dist/core/db/migrations/0001_content.js +69 -0
- package/dist/core/db/migrations/0002_media.d.ts +2 -0
- package/dist/core/db/migrations/0002_media.js +26 -0
- package/dist/core/db/migrations/0003_redirects.d.ts +2 -0
- package/dist/core/db/migrations/0003_redirects.js +19 -0
- package/dist/core/db/migrations/0004_token_cutoffs.d.ts +3 -0
- package/dist/core/db/migrations/0004_token_cutoffs.js +8 -0
- package/dist/core/db/migrations/0005_site_lock.d.ts +3 -0
- package/dist/core/db/migrations/0005_site_lock.js +10 -0
- package/dist/core/db/migrations/0006_releases.d.ts +3 -0
- package/dist/core/db/migrations/0006_releases.js +34 -0
- package/dist/core/db/schema.d.ts +155 -0
- package/dist/core/db/schema.js +1 -0
- package/dist/core/errors.d.ts +27 -0
- package/dist/core/errors.js +15 -0
- package/dist/core/export/export.d.ts +17 -0
- package/dist/core/export/export.js +185 -0
- package/dist/core/export/format.d.ts +241 -0
- package/dist/core/export/format.js +106 -0
- package/dist/core/export/import.d.ts +54 -0
- package/dist/core/export/import.js +180 -0
- package/dist/core/export/read.d.ts +16 -0
- package/dist/core/export/read.js +234 -0
- package/dist/core/export/replace.d.ts +17 -0
- package/dist/core/export/replace.js +36 -0
- package/dist/core/export/report.d.ts +55 -0
- package/dist/core/export/report.js +50 -0
- package/dist/core/export/schema.d.ts +8 -0
- package/dist/core/export/schema.js +47 -0
- package/dist/core/export/stage.d.ts +25 -0
- package/dist/core/export/stage.js +192 -0
- package/dist/core/fields/builtins.d.ts +70 -0
- package/dist/core/fields/builtins.js +335 -0
- package/dist/core/fields/define.d.ts +86 -0
- package/dist/core/fields/define.js +34 -0
- package/dist/core/fields/walk.d.ts +49 -0
- package/dist/core/fields/walk.js +270 -0
- package/dist/core/fields/widgets.d.ts +27 -0
- package/dist/core/fields/widgets.js +330 -0
- package/dist/core/fields/zod-internals.d.ts +29 -0
- package/dist/core/fields/zod-internals.js +28 -0
- package/dist/core/media/detect.d.ts +5 -0
- package/dist/core/media/detect.js +66 -0
- package/dist/core/media/labels.d.ts +6 -0
- package/dist/core/media/labels.js +17 -0
- package/dist/core/media/library.d.ts +45 -0
- package/dist/core/media/library.js +239 -0
- package/dist/core/media/store.d.ts +11 -0
- package/dist/core/media/store.js +49 -0
- package/dist/core/media/variants.d.ts +10 -0
- package/dist/core/media/variants.js +59 -0
- package/dist/core/messages/en.d.ts +1278 -0
- package/dist/core/messages/en.js +1287 -0
- package/dist/core/messages/index.d.ts +7 -0
- package/dist/core/messages/index.js +14 -0
- package/dist/core/preview.d.ts +16 -0
- package/dist/core/preview.js +42 -0
- package/dist/core/redirects/collapse.d.ts +68 -0
- package/dist/core/redirects/collapse.js +153 -0
- package/dist/core/redirects/csv.d.ts +15 -0
- package/dist/core/redirects/csv.js +68 -0
- package/dist/core/redirects/redirects.d.ts +58 -0
- package/dist/core/redirects/redirects.js +545 -0
- package/dist/core/registry/content.d.ts +26 -0
- package/dist/core/registry/content.js +9 -0
- package/dist/core/registry/define.d.ts +145 -0
- package/dist/core/registry/define.js +41 -0
- package/dist/core/registry/migration.d.ts +44 -0
- package/dist/core/registry/migration.js +4 -0
- package/dist/core/registry/registry.d.ts +18 -0
- package/dist/core/registry/registry.js +255 -0
- package/dist/core/registry/render.d.ts +98 -0
- package/dist/core/registry/render.js +1 -0
- package/dist/core/registry/route.d.ts +42 -0
- package/dist/core/registry/route.js +3 -0
- package/dist/core/release/bundle.d.ts +21 -0
- package/dist/core/release/bundle.js +252 -0
- package/dist/core/release/keys.d.ts +11 -0
- package/dist/core/release/keys.js +60 -0
- package/dist/core/release/manifest.d.ts +103 -0
- package/dist/core/release/manifest.js +138 -0
- package/dist/core/release/pack.d.ts +20 -0
- package/dist/core/release/pack.js +97 -0
- package/dist/core/release/pointer.d.ts +19 -0
- package/dist/core/release/pointer.js +53 -0
- package/dist/core/release/read.d.ts +59 -0
- package/dist/core/release/read.js +256 -0
- package/dist/core/report.d.ts +31 -0
- package/dist/core/report.js +37 -0
- package/dist/core/richtext/html.d.ts +15 -0
- package/dist/core/richtext/html.js +81 -0
- package/dist/core/richtext/markdown.d.ts +19 -0
- package/dist/core/richtext/markdown.js +951 -0
- package/dist/core/richtext/schema.d.ts +98 -0
- package/dist/core/richtext/schema.js +275 -0
- package/dist/core/site/live.d.ts +56 -0
- package/dist/core/site/live.js +145 -0
- package/dist/core/site/paths.d.ts +15 -0
- package/dist/core/site/paths.js +64 -0
- package/dist/core/site/resolve.d.ts +9 -0
- package/dist/core/site/resolve.js +202 -0
- package/dist/core/site/sitemap.d.ts +11 -0
- package/dist/core/site/sitemap.js +24 -0
- package/dist/core/site-lock/site-lock.d.ts +21 -0
- package/dist/core/site-lock/site-lock.js +65 -0
- package/dist/core/site-lock/token.d.ts +7 -0
- package/dist/core/site-lock/token.js +24 -0
- package/dist/core/theme.d.ts +22 -0
- package/dist/core/theme.js +133 -0
- package/dist/core/types.d.ts +253 -0
- package/dist/core/types.js +1 -0
- package/dist/core/version.d.ts +1 -0
- package/dist/core/version.js +5 -0
- package/dist/host/activate.d.ts +53 -0
- package/dist/host/activate.js +162 -0
- package/dist/host/app.d.ts +46 -0
- package/dist/host/app.js +129 -0
- package/dist/host/bin.d.ts +5 -0
- package/dist/host/bin.js +8 -0
- package/dist/host/config.d.ts +36 -0
- package/dist/host/config.js +152 -0
- package/dist/host/dev.d.ts +10 -0
- package/dist/host/dev.js +293 -0
- package/dist/host/diff.d.ts +78 -0
- package/dist/host/diff.js +346 -0
- package/dist/host/hooks.d.ts +41 -0
- package/dist/host/hooks.js +49 -0
- package/dist/host/ipc.d.ts +123 -0
- package/dist/host/ipc.js +61 -0
- package/dist/host/preview-proxy.d.ts +24 -0
- package/dist/host/preview-proxy.js +154 -0
- package/dist/host/preview-worker.d.ts +42 -0
- package/dist/host/preview-worker.js +242 -0
- package/dist/host/primary.d.ts +38 -0
- package/dist/host/primary.js +357 -0
- package/dist/host/push.d.ts +125 -0
- package/dist/host/push.js +420 -0
- package/dist/host/serve.d.ts +16 -0
- package/dist/host/serve.js +150 -0
- package/dist/host/store.d.ts +48 -0
- package/dist/host/store.js +109 -0
- package/dist/host/worker.d.ts +67 -0
- package/dist/host/worker.js +310 -0
- package/dist/index.d.ts +47 -0
- package/dist/index.js +32 -0
- package/dist/jsx/html.d.ts +16 -0
- package/dist/jsx/html.js +65 -0
- package/dist/jsx/jsx-dev-runtime.d.ts +4 -0
- package/dist/jsx/jsx-dev-runtime.js +5 -0
- package/dist/jsx/jsx-runtime.d.ts +17 -0
- package/dist/jsx/jsx-runtime.js +41 -0
- package/dist/site.d.ts +17 -0
- package/dist/site.js +14 -0
- package/package.json +111 -3
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { t } from '../../core/messages/index.js';
|
|
2
|
+
import { matchSitePassword, readSiteLock } from '../../core/site-lock/site-lock.js';
|
|
3
|
+
import { createUnlockToken, UNLOCK_TTL_MS, verifyUnlockToken } from '../../core/site-lock/token.js';
|
|
4
|
+
import { escapeHtml, raw } from '../../jsx/html.js';
|
|
5
|
+
import { requestActor } from '../auth/request.js';
|
|
6
|
+
import { safeNext } from '../web.js';
|
|
7
|
+
import { FailureLimiter } from './limiter.js';
|
|
8
|
+
import { readPreview } from './preview.js';
|
|
9
|
+
import { inlayPage } from './render.js';
|
|
10
|
+
export const UNLOCK_COOKIE = 'inlay_unlock';
|
|
11
|
+
export const UNLOCK_PATH = '/_inlay/unlock';
|
|
12
|
+
/** Paths that are never locked, with everything under them. */
|
|
13
|
+
const EXEMPT_PREFIXES = ['/admin', '/api/auth', '/mcp', '/.well-known', '/_inlay', '/public'];
|
|
14
|
+
/** Dot segments, encoded slashes, dots or backslashes, and empty segments: none may borrow an exemption. */
|
|
15
|
+
const TRICKY = /(^|\/)\.\.?(\/|$)|%2e|%2f|%5c|\\|\/\//i;
|
|
16
|
+
const locked = new WeakSet();
|
|
17
|
+
/** True when the gate saw the lock on for this request. */
|
|
18
|
+
export function isLockedRequest(request) {
|
|
19
|
+
return locked.has(request);
|
|
20
|
+
}
|
|
21
|
+
/** The site's own catch-all routes, which would answer any unknown path under an exemption with the site's 404. */
|
|
22
|
+
const SITE_ROUTES = new Set(['/', '/*']);
|
|
23
|
+
function exempt(request, path, publicPaths) {
|
|
24
|
+
const route = request.routeOptions.url;
|
|
25
|
+
if (route === undefined || SITE_ROUTES.has(route))
|
|
26
|
+
return false;
|
|
27
|
+
if (publicPaths.includes(path))
|
|
28
|
+
return true;
|
|
29
|
+
if (TRICKY.test(path))
|
|
30
|
+
return false;
|
|
31
|
+
return EXEMPT_PREFIXES.some((prefix) => path === prefix || path.startsWith(`${prefix}/`));
|
|
32
|
+
}
|
|
33
|
+
function readCookie(header, name) {
|
|
34
|
+
for (const part of header.split(';')) {
|
|
35
|
+
const eq = part.indexOf('=');
|
|
36
|
+
if (eq !== -1 && part.slice(0, eq).trim() === name)
|
|
37
|
+
return part.slice(eq + 1).trim();
|
|
38
|
+
}
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
/** The neutral screen asking for the site password, which sends it to `UNLOCK_PATH` and comes back to `next`. */
|
|
42
|
+
export function passwordScreen(baseUrl, next, error) {
|
|
43
|
+
const alert = error === undefined ? '' : `<p role="alert" class="inlay-error">${escapeHtml(t(error))}</p>`;
|
|
44
|
+
const body = `<p>${escapeHtml(t('site.lock.intro'))}</p>${alert}` +
|
|
45
|
+
`<form method="post" action="${UNLOCK_PATH}">` +
|
|
46
|
+
`<input type="hidden" name="next" value="${escapeHtml(next)}">` +
|
|
47
|
+
`<label for="inlay-password">${escapeHtml(t('site.lock.password'))}</label>` +
|
|
48
|
+
'<input type="password" id="inlay-password" name="password" autocomplete="current-password" required autofocus>' +
|
|
49
|
+
`<button type="submit">${escapeHtml(t('site.lock.submit'))}</button></form>`;
|
|
50
|
+
return inlayPage(new URL(baseUrl).host, raw(body));
|
|
51
|
+
}
|
|
52
|
+
/** Locks every request but the exempt ones while the site lock is on, and keeps let-through responses out of shared caches. */
|
|
53
|
+
export function registerSiteLockGate(app, opts) {
|
|
54
|
+
async function unlocked(request, passwordHash) {
|
|
55
|
+
const cookie = request.headers.cookie;
|
|
56
|
+
if (typeof cookie !== 'string')
|
|
57
|
+
return false;
|
|
58
|
+
const now = opts.now();
|
|
59
|
+
const token = readCookie(cookie, UNLOCK_COOKIE);
|
|
60
|
+
if (token !== undefined && passwordHash !== null && verifyUnlockToken(opts.secret, passwordHash, token, now))
|
|
61
|
+
return true;
|
|
62
|
+
// A preview of the live site's drafts; a release's preview is answered by its own worker, through the proxy.
|
|
63
|
+
const preview = readPreview(request, opts.secret, now);
|
|
64
|
+
if (preview.state === 'preview' && (preview.release === null || preview.release === opts.release))
|
|
65
|
+
return true;
|
|
66
|
+
return (await requestActor(request, opts.service)) !== null;
|
|
67
|
+
}
|
|
68
|
+
app.addHook('onRequest', async (request, reply) => {
|
|
69
|
+
const q = request.url.indexOf('?');
|
|
70
|
+
const path = q === -1 ? request.url : request.url.slice(0, q);
|
|
71
|
+
if (exempt(request, path, opts.publicPaths))
|
|
72
|
+
return;
|
|
73
|
+
const lock = await readSiteLock(opts.db);
|
|
74
|
+
if (!lock.enabled)
|
|
75
|
+
return;
|
|
76
|
+
locked.add(request);
|
|
77
|
+
if (path === '/robots.txt')
|
|
78
|
+
return;
|
|
79
|
+
if (await unlocked(request, lock.passwordHash))
|
|
80
|
+
return;
|
|
81
|
+
return reply
|
|
82
|
+
.code(401)
|
|
83
|
+
.type('text/html; charset=utf-8')
|
|
84
|
+
.header('cache-control', 'no-store')
|
|
85
|
+
.header('x-robots-tag', 'noindex')
|
|
86
|
+
.send(passwordScreen(opts.baseUrl, safeNext(request.url, '/')));
|
|
87
|
+
});
|
|
88
|
+
app.addHook('onSend', async (request, reply, payload) => {
|
|
89
|
+
if (!locked.has(request))
|
|
90
|
+
return payload;
|
|
91
|
+
reply.header('x-robots-tag', 'noindex');
|
|
92
|
+
reply.header('cache-control', privateControl(reply.getHeader('cache-control')));
|
|
93
|
+
return payload;
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
/** `control` made private: kept when already `private` or `no-store`, else `public` swapped for `private`. */
|
|
97
|
+
function privateControl(control) {
|
|
98
|
+
const directives = (Array.isArray(control) ? control.join(',') : String(control ?? ''))
|
|
99
|
+
.split(',')
|
|
100
|
+
.map((d) => d.trim())
|
|
101
|
+
.filter((d) => d !== '');
|
|
102
|
+
if (directives.length === 0)
|
|
103
|
+
return 'private, no-cache';
|
|
104
|
+
const lower = directives.map((d) => d.toLowerCase());
|
|
105
|
+
if (lower.includes('private') || lower.includes('no-store'))
|
|
106
|
+
return directives.join(', ');
|
|
107
|
+
return ['private', ...directives.filter((_, i) => lower[i] !== 'public')].join(', ');
|
|
108
|
+
}
|
|
109
|
+
const FORM_LIMIT = 4 * 1024;
|
|
110
|
+
/** `POST /_inlay/unlock`: checks the site password, sets the unlock cookie and returns to `next`; wrong guesses are rate limited per client IP. */
|
|
111
|
+
export function registerUnlockRoute(app, opts) {
|
|
112
|
+
const limiter = new FailureLimiter({ max: 5, windowMs: 60_000 });
|
|
113
|
+
const secure = opts.baseUrl.startsWith('https:');
|
|
114
|
+
app.register(async (child) => {
|
|
115
|
+
child.addContentTypeParser('application/x-www-form-urlencoded', { parseAs: 'string', bodyLimit: FORM_LIMIT }, (_request, body, done) => done(null, new URLSearchParams(body)));
|
|
116
|
+
child.post(UNLOCK_PATH, async (request, reply) => {
|
|
117
|
+
const form = request.body instanceof URLSearchParams ? request.body : new URLSearchParams();
|
|
118
|
+
const next = safeNext(form.get('next'), '/');
|
|
119
|
+
reply.header('cache-control', 'no-store').header('x-robots-tag', 'noindex');
|
|
120
|
+
const screen = (status, error) => reply.code(status).type('text/html; charset=utf-8').send(passwordScreen(opts.baseUrl, next, error));
|
|
121
|
+
if (!(await readSiteLock(opts.db)).enabled)
|
|
122
|
+
return reply.redirect(next, 303);
|
|
123
|
+
if (opts.rateLimit) {
|
|
124
|
+
const now = opts.now().getTime();
|
|
125
|
+
if (limiter.blocked(request.ip, now))
|
|
126
|
+
return screen(429, 'site.lock.tooMany');
|
|
127
|
+
// Counted before the slow check, so concurrent guesses can't all slip past `blocked`
|
|
128
|
+
limiter.fail(request.ip, now);
|
|
129
|
+
}
|
|
130
|
+
const passwordHash = await matchSitePassword(opts.db, form.get('password') ?? '');
|
|
131
|
+
if (passwordHash === null)
|
|
132
|
+
return screen(401, 'site.lock.wrong');
|
|
133
|
+
if (opts.rateLimit)
|
|
134
|
+
limiter.refund(request.ip);
|
|
135
|
+
const token = createUnlockToken(opts.secret, passwordHash, opts.now());
|
|
136
|
+
const parts = [`${UNLOCK_COOKIE}=${token}`, 'Path=/', 'HttpOnly', 'SameSite=Lax', `Max-Age=${UNLOCK_TTL_MS / 1000}`];
|
|
137
|
+
if (secure)
|
|
138
|
+
parts.push('Secure');
|
|
139
|
+
reply.header('set-cookie', parts.join('; '));
|
|
140
|
+
return reply.redirect(next, 303);
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { FastifyInstance } from 'fastify';
|
|
2
|
+
import type { Core } from '../../core/core.js';
|
|
3
|
+
/** `GET /media/:id` (the original) and `GET /media/:id/:width.:format` (a resized variant). */
|
|
4
|
+
export declare function registerMediaRoutes(app: FastifyInstance, core: Core): void;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { createReadStream } from 'node:fs';
|
|
2
|
+
import { InlayError } from '../../core/errors.js';
|
|
3
|
+
import { isRasterImage } from '../../core/media/detect.js';
|
|
4
|
+
import { t } from '../../core/messages/index.js';
|
|
5
|
+
const VARIANT = /^([1-9][0-9]{0,4})\.(webp|avif|jpeg|png)$/;
|
|
6
|
+
/** RFC 5987 `ext-value` encoding for `filename*`. */
|
|
7
|
+
function encodeFilename(name) {
|
|
8
|
+
return encodeURIComponent(name).replace(/['()*]/g, (c) => `%${c.charCodeAt(0).toString(16).toUpperCase()}`);
|
|
9
|
+
}
|
|
10
|
+
function disposition(mime, filename) {
|
|
11
|
+
const type = isRasterImage(mime) || mime === 'application/pdf' ? 'inline' : 'attachment';
|
|
12
|
+
return `${type}; filename*=UTF-8''${encodeFilename(filename)}`;
|
|
13
|
+
}
|
|
14
|
+
function notFound(reply) {
|
|
15
|
+
return reply.code(404).type('text/plain; charset=utf-8').send(t('error.mediaNotFound'));
|
|
16
|
+
}
|
|
17
|
+
/** Sends the file at `path` with headers for a content-addressed, never-changing resource. */
|
|
18
|
+
function sendFile(request, reply, id, file) {
|
|
19
|
+
const etag = `"${id}"`;
|
|
20
|
+
reply
|
|
21
|
+
.header('cache-control', 'public, max-age=31536000, immutable')
|
|
22
|
+
.header('etag', etag)
|
|
23
|
+
.header('x-content-type-options', 'nosniff');
|
|
24
|
+
if (request.headers['if-none-match'] === etag)
|
|
25
|
+
return reply.code(304).send();
|
|
26
|
+
if (file.disposition)
|
|
27
|
+
reply.header('content-disposition', file.disposition);
|
|
28
|
+
return reply.type(file.mime).send(createReadStream(file.path));
|
|
29
|
+
}
|
|
30
|
+
async function guard(reply, send) {
|
|
31
|
+
try {
|
|
32
|
+
return await send();
|
|
33
|
+
}
|
|
34
|
+
catch (e) {
|
|
35
|
+
if (e instanceof InlayError && e.code === 'not_found')
|
|
36
|
+
return notFound(reply);
|
|
37
|
+
throw e;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/** `GET /media/:id` (the original) and `GET /media/:id/:width.:format` (a resized variant). */
|
|
41
|
+
export function registerMediaRoutes(app, core) {
|
|
42
|
+
app.get('/media/:id', (request, reply) => guard(reply, async () => {
|
|
43
|
+
const { id } = request.params;
|
|
44
|
+
const file = await core.mediaFile(id);
|
|
45
|
+
return sendFile(request, reply, id, { ...file, disposition: disposition(file.mime, file.filename) });
|
|
46
|
+
}));
|
|
47
|
+
app.get('/media/:id/:variant', (request, reply) => guard(reply, async () => {
|
|
48
|
+
const { id, variant } = request.params;
|
|
49
|
+
const m = VARIANT.exec(variant);
|
|
50
|
+
if (!m)
|
|
51
|
+
return notFound(reply);
|
|
52
|
+
const file = await core.mediaVariant(id, { width: Number(m[1]), format: m[2] });
|
|
53
|
+
return sendFile(request, reply, id, file);
|
|
54
|
+
}));
|
|
55
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import type { FastifyPluginAsync } from 'fastify';
|
|
2
|
+
import type { AuthService } from '../../core/auth/service.js';
|
|
3
|
+
import { type Core } from '../../core/core.js';
|
|
4
|
+
import type { SiteDefinition } from '../../core/registry/define.js';
|
|
5
|
+
import type { Entry, QueryOptions, QueryResult } from '../../core/registry/render.js';
|
|
6
|
+
import type { UploadLimits } from '../../core/types.js';
|
|
7
|
+
import type { AdminHostHooks } from '../../host/hooks.js';
|
|
8
|
+
import type { ActivationSummary } from '../../host/ipc.js';
|
|
9
|
+
import { type CdnOptions } from './cache.js';
|
|
10
|
+
export interface InlayOptions {
|
|
11
|
+
site: SiteDefinition;
|
|
12
|
+
db: string;
|
|
13
|
+
/** The site's absolute http(s) origin, such as `https://example.com`. */
|
|
14
|
+
baseUrl: string;
|
|
15
|
+
/** Signs preview links; at least 32 characters. */
|
|
16
|
+
secret: string;
|
|
17
|
+
/** Defaults to `media` next to `db`. */
|
|
18
|
+
media?: string;
|
|
19
|
+
/** Defaults to `backups` next to `db`. */
|
|
20
|
+
backups?: string;
|
|
21
|
+
uploads?: UploadLimits;
|
|
22
|
+
cache?: {
|
|
23
|
+
maxEntries?: number;
|
|
24
|
+
} | false;
|
|
25
|
+
/** How long CDNs and proxies may hold published pages. ETags are always sent. */
|
|
26
|
+
cdn?: CdnOptions;
|
|
27
|
+
now?: () => Date;
|
|
28
|
+
/** Limits login attempts per client. Defaults to `true`; turn it off only in tests. */
|
|
29
|
+
rateLimit?: boolean;
|
|
30
|
+
/** A daily backup, keeping the newest `keep` (default 14). Defaults to on; `false` turns it off. */
|
|
31
|
+
backupSchedule?: {
|
|
32
|
+
keep?: number;
|
|
33
|
+
} | false;
|
|
34
|
+
/** Absolute path of the folder served at `/public/*`. Without it that path is not served. */
|
|
35
|
+
publicDir?: string;
|
|
36
|
+
/** Seconds browsers and CDNs may keep `/public/*` files (default 3600). */
|
|
37
|
+
publicMaxAge?: number;
|
|
38
|
+
/** Secret values by name, such as API tokens. Routes see only the ones their site declares in `secrets`. */
|
|
39
|
+
secrets?: Record<string, string>;
|
|
40
|
+
/** `'apply'` (the default) applies the site's shipped content at boot; `'none'` leaves content to release activation. */
|
|
41
|
+
content?: 'apply' | 'none';
|
|
42
|
+
/**
|
|
43
|
+
* Every content page answers a plain page instead of the site; the admin works as usual. `'empty'`: "no site yet"
|
|
44
|
+
* (status 200, not indexed), for a host with no release. `'unavailable'`: "temporarily unavailable" (status 503
|
|
45
|
+
* with Retry-After), for a site that is down, so search engines keep it.
|
|
46
|
+
*/
|
|
47
|
+
noSite?: 'empty' | 'unavailable';
|
|
48
|
+
/** Set by `inlaycms serve`: what the site can ask of the server it runs under. */
|
|
49
|
+
host?: HostApi;
|
|
50
|
+
/** A loaded release's shipped files, by source as written in the site. */
|
|
51
|
+
shippedFiles?: ReadonlyMap<string, string>;
|
|
52
|
+
/**
|
|
53
|
+
* Nothing can be changed: every write through the core is refused with `error.previewReadOnly`, and the admin and
|
|
54
|
+
* `/api/auth` answer their write requests (other than logging in and out) with 403. Boot still applies shipped
|
|
55
|
+
* content and, with `release`, then runs the site's migration functions. Set for a staged release's preview, which
|
|
56
|
+
* runs on a copy of the database.
|
|
57
|
+
*/
|
|
58
|
+
readOnly?: boolean;
|
|
59
|
+
/**
|
|
60
|
+
* `'forced'`: every content request renders in preview state (drafts as published, not cached, not indexed, with the
|
|
61
|
+
* banner), cookie or not, and no answer may be stored by a browser or a shared cache.
|
|
62
|
+
*/
|
|
63
|
+
preview?: 'forced';
|
|
64
|
+
/** The release this site runs, when it is a stored release; a forced preview's banner names it. */
|
|
65
|
+
release?: {
|
|
66
|
+
id: string;
|
|
67
|
+
name: string;
|
|
68
|
+
};
|
|
69
|
+
/** The folder releases are kept in. With it, owners get the admin's Releases screen. */
|
|
70
|
+
releasesDir?: string;
|
|
71
|
+
/** The public keys a release uploaded in the admin must be signed with, when there is no `adminHost`. */
|
|
72
|
+
trustedKeys?: readonly string[];
|
|
73
|
+
/** What the admin's Releases screen can ask of `inlaycms serve` (preview, activate, push checks). */
|
|
74
|
+
adminHost?: AdminHostHooks;
|
|
75
|
+
}
|
|
76
|
+
/** What a site running under `inlaycms serve` can ask of the server. */
|
|
77
|
+
export interface HostApi {
|
|
78
|
+
/**
|
|
79
|
+
* Makes a stored release live: resolves with what the activation did once the new release is serving; rejects
|
|
80
|
+
* with the activation's error, the previous release still live.
|
|
81
|
+
*/
|
|
82
|
+
requestActivation(releaseId: string): Promise<ActivationSummary>;
|
|
83
|
+
/**
|
|
84
|
+
* Starts (or finds) the preview worker of a staged release and resolves with the Unix socket it listens on. `dir`:
|
|
85
|
+
* the push's scratch folder the release is in, for a dry run (recorded as staged only in the preview's copy).
|
|
86
|
+
*/
|
|
87
|
+
startPreview?(releaseId: string, opts?: {
|
|
88
|
+
dir?: string;
|
|
89
|
+
}): Promise<string>;
|
|
90
|
+
/** The staged release's preview worker is no longer needed. */
|
|
91
|
+
stopPreview?(releaseId: string): Promise<void>;
|
|
92
|
+
/** The staged release's preview is still in use, so its worker isn't stopped as idle. */
|
|
93
|
+
touchPreview?(releaseId: string): void;
|
|
94
|
+
}
|
|
95
|
+
/** Where tests find the plugin's `AuthService` on `app.inlay`; not part of the public API. */
|
|
96
|
+
export declare const AUTH: unique symbol;
|
|
97
|
+
export interface InlayApi {
|
|
98
|
+
core: Core;
|
|
99
|
+
/** Published content: singletons and globals by type, entries by slug. */
|
|
100
|
+
getDocument<F = Record<string, unknown>>(type: string, opts?: {
|
|
101
|
+
locale?: string;
|
|
102
|
+
slug?: string;
|
|
103
|
+
}): Promise<Entry<F> | null>;
|
|
104
|
+
/** Published entries of `collection`, filtered, sorted and paginated as in a template's `ctx.query`. */
|
|
105
|
+
query<F = Record<string, unknown>>(collection: string, opts?: QueryOptions<F> & {
|
|
106
|
+
locale?: string;
|
|
107
|
+
}): Promise<QueryResult<F>>;
|
|
108
|
+
previewUrl(path?: string): string;
|
|
109
|
+
/** Clears the page cache. */
|
|
110
|
+
clearCache(): void;
|
|
111
|
+
/** The server the site runs under, with `inlaycms serve`; null otherwise. */
|
|
112
|
+
host: HostApi | null;
|
|
113
|
+
/** @internal The plugin's auth service (non-enumerable). */
|
|
114
|
+
readonly [AUTH]: AuthService;
|
|
115
|
+
}
|
|
116
|
+
declare module 'fastify' {
|
|
117
|
+
interface FastifyInstance {
|
|
118
|
+
inlay: InlayApi;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/** The Fastify plugin: boots the content core and serves the public site. */
|
|
122
|
+
export declare const inlay: FastifyPluginAsync<InlayOptions>;
|