inlaycms 0.4.1 → 0.6.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/README.md +18 -709
- package/assets/admin/admin.css +1 -1
- package/assets/admin/admin.js +1 -1
- package/assets/admin/editor.js +63 -46
- package/assets/site/consent.js +1 -0
- package/dist/adapters/admin/context.d.ts +1 -1
- package/dist/adapters/admin/context.js +1 -0
- package/dist/adapters/admin/publish.js +2 -2
- package/dist/adapters/admin/routes.d.ts +2 -0
- package/dist/adapters/admin/routes.js +2 -0
- package/dist/adapters/admin/screens/backups.js +2 -2
- package/dist/adapters/admin/screens/editor.js +5 -2
- package/dist/adapters/admin/screens/integrations.d.ts +4 -0
- package/dist/adapters/admin/screens/integrations.js +140 -0
- package/dist/adapters/admin/screens/lists.js +2 -1
- package/dist/adapters/admin/screens/releases.js +9 -4
- package/dist/adapters/admin/views/data-table.js +1 -1
- package/dist/adapters/admin/views/layout.d.ts +1 -1
- package/dist/adapters/admin/views/layout.js +15 -2
- package/dist/adapters/cli/bin.js +8 -3
- package/dist/adapters/cli/main.js +12 -2
- package/dist/adapters/mcp/agent-refs.d.ts +2 -1
- package/dist/adapters/mcp/agent-refs.js +4 -4
- package/dist/adapters/mcp/tools/publish.js +1 -1
- package/dist/adapters/mcp/tools/read.js +19 -4
- package/dist/adapters/mcp/tools/write.js +5 -1
- package/dist/adapters/site/cache.d.ts +8 -2
- package/dist/adapters/site/cache.js +13 -4
- package/dist/adapters/site/code-files.d.ts +44 -0
- package/dist/adapters/site/code-files.js +212 -0
- package/dist/adapters/site/consent.d.ts +9 -0
- package/dist/adapters/site/consent.js +26 -0
- package/dist/adapters/site/context.d.ts +9 -1
- package/dist/adapters/site/context.js +106 -27
- package/dist/adapters/site/csp.d.ts +11 -0
- package/dist/adapters/site/csp.js +36 -0
- package/dist/adapters/site/head.d.ts +2 -0
- package/dist/adapters/site/head.js +7 -20
- package/dist/adapters/site/headers.d.ts +5 -2
- package/dist/adapters/site/headers.js +13 -6
- package/dist/adapters/site/integrations.d.ts +48 -0
- package/dist/adapters/site/integrations.js +118 -0
- package/dist/adapters/site/media-routes.d.ts +2 -0
- package/dist/adapters/site/media-routes.js +2 -1
- package/dist/adapters/site/plugin.d.ts +2 -0
- package/dist/adapters/site/plugin.js +78 -40
- package/dist/adapters/site/preview.d.ts +2 -0
- package/dist/adapters/site/preview.js +10 -5
- package/dist/adapters/site/render.d.ts +31 -14
- package/dist/adapters/site/render.js +33 -7
- package/dist/adapters/site/routes.d.ts +3 -0
- package/dist/adapters/site/routes.js +11 -6
- package/dist/adapters/site/scripts.d.ts +6 -0
- package/dist/adapters/site/scripts.js +27 -0
- package/dist/adapters/site/sitemap.d.ts +2 -1
- package/dist/adapters/site/sitemap.js +3 -3
- package/dist/core/auth/roles.d.ts +1 -1
- package/dist/core/auth/roles.js +1 -0
- package/dist/core/boot.d.ts +2 -0
- package/dist/core/boot.js +3 -0
- package/dist/core/content/shipped-input.js +1 -2
- package/dist/core/content/validate.d.ts +7 -0
- package/dist/core/content/validate.js +24 -1
- package/dist/core/core.d.ts +29 -0
- package/dist/core/core.js +10 -2
- package/dist/core/db/migrate.js +2 -0
- package/dist/core/db/migrations/0008_integrations.d.ts +3 -0
- package/dist/core/db/migrations/0008_integrations.js +11 -0
- package/dist/core/db/schema.d.ts +11 -0
- package/dist/core/export/export.js +4 -0
- package/dist/core/export/format.d.ts +11 -0
- package/dist/core/export/format.js +4 -0
- package/dist/core/export/import.js +2 -1
- package/dist/core/export/replace.d.ts +6 -1
- package/dist/core/export/replace.js +4 -1
- package/dist/core/export/report.d.ts +6 -0
- package/dist/core/export/report.js +7 -0
- package/dist/core/fields/builtins.d.ts +4 -0
- package/dist/core/fields/builtins.js +11 -1
- package/dist/core/fields/widgets.js +5 -1
- package/dist/core/integrations/integrations.d.ts +32 -0
- package/dist/core/integrations/integrations.js +80 -0
- package/dist/core/integrations/warnings.d.ts +4 -0
- package/dist/core/integrations/warnings.js +29 -0
- package/dist/core/media/store.d.ts +2 -0
- package/dist/core/media/store.js +17 -1
- package/dist/core/media/variants.d.ts +14 -0
- package/dist/core/media/variants.js +54 -0
- package/dist/core/messages/en.d.ts +83 -2
- package/dist/core/messages/en.js +83 -2
- package/dist/core/registry/code-image.d.ts +16 -0
- package/dist/core/registry/code-image.js +13 -0
- package/dist/core/registry/define.d.ts +12 -0
- package/dist/core/registry/define.js +3 -0
- package/dist/core/registry/designed.d.ts +6 -0
- package/dist/core/registry/designed.js +8 -0
- package/dist/core/registry/integration.d.ts +48 -0
- package/dist/core/registry/integration.js +29 -0
- package/dist/core/registry/js.d.ts +9 -0
- package/dist/core/registry/js.js +39 -0
- package/dist/core/registry/registry.js +46 -0
- package/dist/core/registry/render.d.ts +45 -5
- package/dist/core/release/bundle.d.ts +3 -1
- package/dist/core/release/bundle.js +169 -11
- package/dist/core/release/manifest.d.ts +29 -6
- package/dist/core/release/manifest.js +26 -25
- package/dist/core/release/pack.js +13 -2
- package/dist/core/release/pointer.js +14 -3
- package/dist/core/release/read.d.ts +4 -2
- package/dist/core/release/read.js +12 -12
- package/dist/core/release/window.d.ts +11 -0
- package/dist/core/release/window.js +34 -0
- package/dist/core/report.d.ts +3 -0
- package/dist/core/richtext/headings.d.ts +10 -0
- package/dist/core/richtext/headings.js +37 -0
- package/dist/core/richtext/html.d.ts +10 -1
- package/dist/core/richtext/html.js +17 -6
- package/dist/core/richtext/markdown-text.d.ts +24 -0
- package/dist/core/richtext/markdown-text.js +38 -0
- package/dist/core/richtext/markdown.js +44 -3
- package/dist/core/richtext/schema.d.ts +12 -3
- package/dist/core/richtext/schema.js +34 -0
- package/dist/core/site/live.d.ts +6 -0
- package/dist/core/site/live.js +25 -0
- package/dist/core/site/paths.d.ts +5 -0
- package/dist/core/site/paths.js +32 -0
- package/dist/core/site/resolve.js +17 -6
- package/dist/core/version.d.ts +4 -0
- package/dist/core/version.js +4 -0
- package/dist/host/activate.js +2 -1
- package/dist/host/app.d.ts +2 -0
- package/dist/host/app.js +1 -0
- package/dist/host/diff.d.ts +11 -0
- package/dist/host/diff.js +40 -0
- package/dist/host/ipc.d.ts +2 -0
- package/dist/host/ipc.js +5 -1
- package/dist/host/preview-worker.js +2 -2
- package/dist/host/primary.js +15 -4
- package/dist/host/push.d.ts +5 -1
- package/dist/host/push.js +18 -6
- package/dist/host/serve.js +1 -1
- package/dist/host/store.d.ts +1 -2
- package/dist/host/store.js +32 -6
- package/dist/host/worker.js +9 -3
- package/dist/image-modules.d.ts +29 -0
- package/dist/image-modules.js +1 -0
- package/dist/index.d.ts +7 -1
- package/dist/index.js +4 -0
- package/dist/site.d.ts +9 -2
- package/dist/site.js +5 -0
- package/package.json +5 -1
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import type { z } from 'zod';
|
|
2
2
|
import type { SafeHtml } from '../../jsx/html.js';
|
|
3
3
|
import type { VariantFormat } from '../media/variants.js';
|
|
4
|
+
import type { RichTextRenderOptions } from '../richtext/html.js';
|
|
4
5
|
import type { RichTextDoc } from '../richtext/schema.js';
|
|
5
6
|
import type { FileValue, ImageValue, LinkValue } from '../types.js';
|
|
7
|
+
import type { CodeImage } from './code-image.js';
|
|
8
|
+
import type { JsCode } from './js.js';
|
|
6
9
|
import type { CollectionDef, GlobalDef, TemplateDef } from './define.js';
|
|
7
10
|
export interface ResolvedImage {
|
|
8
11
|
id: string;
|
|
9
|
-
/** The original: `/media/<id
|
|
12
|
+
/** The original: `/media/<id>`, or `/media/files/<sha><ext>` for an imported image. */
|
|
10
13
|
url: string;
|
|
11
14
|
alt: string;
|
|
12
15
|
width: number | null;
|
|
@@ -37,7 +40,7 @@ export interface Entry<F = Record<string, unknown>> {
|
|
|
37
40
|
/** The locale whose content is shown. */
|
|
38
41
|
locale: string;
|
|
39
42
|
fallback: boolean;
|
|
40
|
-
/** The encoded site
|
|
43
|
+
/** The encoded page URL, with the trailing slash when the site asks for it, or `null` for data entries. */
|
|
41
44
|
url: string | null;
|
|
42
45
|
title: string;
|
|
43
46
|
slug: string | null;
|
|
@@ -72,6 +75,8 @@ export interface PageInfo {
|
|
|
72
75
|
fallback: boolean;
|
|
73
76
|
/** The decoded site path; `''` for a page without one. */
|
|
74
77
|
path: string;
|
|
78
|
+
/** The encoded page URL, with the trailing slash when the site asks for it; `''` for a page without one. */
|
|
79
|
+
url: string;
|
|
75
80
|
/** When Inlay first published the page's document; `null` for a route or a never-published draft. */
|
|
76
81
|
publishedAt: string | null;
|
|
77
82
|
page: number;
|
|
@@ -102,6 +107,15 @@ export interface HeadApi {
|
|
|
102
107
|
/** Replaces Inlay's link with the same `rel` and `hreflang`. Throws on an unsafe `href`. */
|
|
103
108
|
link(attrs: HeadLink): void;
|
|
104
109
|
}
|
|
110
|
+
/** What `ctx.script` takes: inline code, or an external script. */
|
|
111
|
+
export type ScriptInput = string | JsCode | {
|
|
112
|
+
src: string;
|
|
113
|
+
async?: boolean;
|
|
114
|
+
defer?: boolean;
|
|
115
|
+
type?: 'module';
|
|
116
|
+
};
|
|
117
|
+
/** Writes a `<script>` and records its hash for the page's Content-Security-Policy. Throws on unsafe code or `src`. */
|
|
118
|
+
export type ScriptApi = (input: ScriptInput) => SafeHtml;
|
|
105
119
|
export interface RenderContext {
|
|
106
120
|
locale: string;
|
|
107
121
|
defaultLocale: string;
|
|
@@ -113,17 +127,43 @@ export interface RenderContext {
|
|
|
113
127
|
asset(path: string): string;
|
|
114
128
|
/** Tags for the page's `<head>`, collected during this render. */
|
|
115
129
|
head: HeadApi;
|
|
130
|
+
/** A `<script>` for the page, to put in the template's output; inline code is allowed by the page's CSP by its hash. */
|
|
131
|
+
script: ScriptApi;
|
|
116
132
|
alternates: Array<{
|
|
117
133
|
locale: string;
|
|
134
|
+
/** The decoded site path. */
|
|
118
135
|
path: string;
|
|
136
|
+
/** The encoded page URL, with the trailing slash when the site asks for it. */
|
|
137
|
+
url: string;
|
|
119
138
|
fallback: boolean;
|
|
120
139
|
}>;
|
|
121
|
-
/**
|
|
122
|
-
|
|
140
|
+
/**
|
|
141
|
+
* An image the site imports (`import hero from './hero.jpg'`), served from the site with its variants. Alt is
|
|
142
|
+
* `opts.alt`, then `''`.
|
|
143
|
+
*/
|
|
144
|
+
image(v: CodeImage, opts?: {
|
|
145
|
+
alt?: string;
|
|
146
|
+
}): ResolvedImage;
|
|
147
|
+
/**
|
|
148
|
+
* A media library image. Alt is `opts.alt` when given (even `''`), then the value's, then the media's default, then
|
|
149
|
+
* `''`. `null` when the media is missing.
|
|
150
|
+
*/
|
|
151
|
+
image(v: ImageValue | null | undefined, opts?: {
|
|
152
|
+
alt?: string;
|
|
153
|
+
}): ResolvedImage | null;
|
|
154
|
+
/** Either kind of image, when the value may be one or the other or missing. */
|
|
155
|
+
image(v: CodeImage | ImageValue | null | undefined, opts?: {
|
|
156
|
+
alt?: string;
|
|
157
|
+
}): ResolvedImage | null;
|
|
123
158
|
file(v: FileValue | null | undefined): ResolvedFile | null;
|
|
124
159
|
/** `null` when the target document isn't live. Text is the value's, then the target's title, then the URL. */
|
|
125
160
|
link(v: LinkValue | null | undefined): ResolvedLink | null;
|
|
126
|
-
richText(doc: RichTextDoc | null | undefined): SafeHtml;
|
|
161
|
+
richText(doc: RichTextDoc | null | undefined, opts?: RichTextRenderOptions): SafeHtml;
|
|
162
|
+
/**
|
|
163
|
+
* Markdown text (an imported `.md` file) as HTML, with every rich text feature and headings 1 to 6. Images next to
|
|
164
|
+
* the file are served from the site (`/media/files/…`). Throws when the text can't be read as rich text.
|
|
165
|
+
*/
|
|
166
|
+
markdown(text: string, opts?: RichTextRenderOptions): Promise<SafeHtml>;
|
|
127
167
|
/** An inline-text value's first paragraph without its `<p>`, for a heading or a tagline. A string is escaped. */
|
|
128
168
|
inline(value: RichTextDoc | string | null | undefined): SafeHtml;
|
|
129
169
|
/** Live entries in the given order; ones that aren't live are skipped. */
|
|
@@ -14,8 +14,10 @@ export declare function bundleConfig(configFile: string, outFile: string): Promi
|
|
|
14
14
|
* any other import left outside the bundle (`inlaycms` itself included) with `error.packImport`, and site code
|
|
15
15
|
* (not installed packages) that reaches for the server with `error.packForbidden`; other build failures are
|
|
16
16
|
* `error.packBundle`. These checks catch mistakes: the release's signature is what makes it trusted. Returns the
|
|
17
|
-
* imports left in the bundle
|
|
17
|
+
* imports left in the bundle, and the `file:` URLs of the images site code names: those its `.md` files name, and
|
|
18
|
+
* those it imports.
|
|
18
19
|
*/
|
|
19
20
|
export declare function bundleSite(configFile: string, outFile: string): Promise<{
|
|
20
21
|
imports: string[];
|
|
22
|
+
codeImages: string[];
|
|
21
23
|
}>;
|
|
@@ -1,12 +1,17 @@
|
|
|
1
|
-
import { randomBytes } from 'node:crypto';
|
|
2
|
-
import { existsSync, realpathSync } from 'node:fs';
|
|
1
|
+
import { createHash, randomBytes } from 'node:crypto';
|
|
2
|
+
import { existsSync, readFileSync, realpathSync } from 'node:fs';
|
|
3
3
|
import { readFile } from 'node:fs/promises';
|
|
4
4
|
import { builtinModules } from 'node:module';
|
|
5
5
|
import { dirname, extname, isAbsolute, join, relative, resolve } from 'node:path';
|
|
6
6
|
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
7
|
-
import { build, transform } from 'esbuild';
|
|
7
|
+
import { build, transform, } from 'esbuild';
|
|
8
|
+
import sharp from 'sharp';
|
|
9
|
+
import { imageTarget, realInsideSync } from '../content/shipped-images.js';
|
|
8
10
|
import { InlayError } from '../errors.js';
|
|
11
|
+
import { detectType } from '../media/detect.js';
|
|
9
12
|
import { t } from '../messages/index.js';
|
|
13
|
+
import { markdownImages } from '../richtext/markdown.js';
|
|
14
|
+
import { isMediaTarget, MARKDOWN_IMAGE_TYPES, parseMarkdownText } from '../richtext/markdown-text.js';
|
|
10
15
|
import { rewriteImageTargets } from './markdown-file.js';
|
|
11
16
|
import { INLAY_ENTRIES } from './read.js';
|
|
12
17
|
import { SITE_DIR_EXPORT, siteDirUrl } from './site-dir.js';
|
|
@@ -119,12 +124,65 @@ function shownPath(base, file) {
|
|
|
119
124
|
const rel = relative(base, file);
|
|
120
125
|
return rel === '' || rel.startsWith('..') || isAbsolute(rel) ? file : rel;
|
|
121
126
|
}
|
|
127
|
+
/** The extensions a `.md` image's file may have, for messages: ".png, .jpg, …". */
|
|
128
|
+
const IMAGE_EXTENSIONS = Object.keys(MARKDOWN_IMAGE_TYPES).join(', ');
|
|
129
|
+
/**
|
|
130
|
+
* The first reason the image target `src` (on `line` of the `.md` file shown as `shown`, its relative targets already
|
|
131
|
+
* rewritten to `file:` URLs) can't be used, or null when it is a media library image or a picture file inside the
|
|
132
|
+
* site's folder (`siteDir`, a `file:` URL ending in `/`) whose extension is in `MARKDOWN_IMAGE_TYPES` and matches
|
|
133
|
+
* what it holds. An SVG file is refused.
|
|
134
|
+
*/
|
|
135
|
+
function markdownImageProblem(src, line, shown, siteDir) {
|
|
136
|
+
const refuse = (id, extra = {}) => t(id, { file: shown, line, src, ...extra });
|
|
137
|
+
const target = imageTarget(src, siteDir);
|
|
138
|
+
if (target.kind === 'library')
|
|
139
|
+
return isMediaTarget(src) ? null : refuse('error.markdownImageOther');
|
|
140
|
+
if (target.kind === 'remote')
|
|
141
|
+
return refuse('error.markdownImageRemote');
|
|
142
|
+
if (target.kind === 'rooted')
|
|
143
|
+
return refuse('error.markdownImageRooted');
|
|
144
|
+
if (!/^file:/i.test(src))
|
|
145
|
+
return refuse('error.markdownImageOther');
|
|
146
|
+
let path;
|
|
147
|
+
try {
|
|
148
|
+
path = fileURLToPath(src);
|
|
149
|
+
}
|
|
150
|
+
catch {
|
|
151
|
+
return refuse('error.markdownImageOutside');
|
|
152
|
+
}
|
|
153
|
+
if (!existsSync(path))
|
|
154
|
+
return refuse('error.markdownImageMissing');
|
|
155
|
+
const real = realInsideSync(path, siteDir);
|
|
156
|
+
if (real === null)
|
|
157
|
+
return refuse('error.markdownImageOutside');
|
|
158
|
+
let bytes;
|
|
159
|
+
try {
|
|
160
|
+
bytes = readFileSync(real);
|
|
161
|
+
}
|
|
162
|
+
catch {
|
|
163
|
+
return refuse('error.markdownImageMissing');
|
|
164
|
+
}
|
|
165
|
+
const ext = extname(path).toLowerCase();
|
|
166
|
+
const mime = detectType(bytes, path);
|
|
167
|
+
if (mime === 'image/svg+xml' || ext === '.svg')
|
|
168
|
+
return refuse('error.markdownImageSvg');
|
|
169
|
+
if (!mime.startsWith('image/'))
|
|
170
|
+
return refuse('error.markdownImageNotImage');
|
|
171
|
+
const expected = MARKDOWN_IMAGE_TYPES[ext];
|
|
172
|
+
if (expected === undefined)
|
|
173
|
+
return refuse('error.markdownImageExtension', { extensions: IMAGE_EXTENSIONS });
|
|
174
|
+
if (mime !== expected)
|
|
175
|
+
return refuse('error.markdownImageMismatch', { ext });
|
|
176
|
+
return null;
|
|
177
|
+
}
|
|
122
178
|
/**
|
|
123
179
|
* A `.md` file at `file` as a module whose default export is its text, with its images' targets rewritten from
|
|
124
180
|
* the file's own folder; a reference-style image is refused with `error.markdownImageReference`, and one whose
|
|
125
|
-
* place in the file can't be found with `error.markdownImageUnplaced`.
|
|
181
|
+
* place in the file can't be found with `error.markdownImageUnplaced`. Then the first thing `parseMarkdownText`
|
|
182
|
+
* refuses is, and then the first image `markdownImageProblem` refuses. `images` is given the `file:` targets of a
|
|
183
|
+
* file that passes.
|
|
126
184
|
*/
|
|
127
|
-
async function loadMarkdown(file, base) {
|
|
185
|
+
async function loadMarkdown(file, base, images) {
|
|
128
186
|
const result = rewriteImageTargets(await readFile(file, 'utf8'), file);
|
|
129
187
|
const line = result.references[0];
|
|
130
188
|
if (line !== undefined)
|
|
@@ -133,8 +191,103 @@ async function loadMarkdown(file, base) {
|
|
|
133
191
|
if (unplaced !== undefined) {
|
|
134
192
|
return { errors: [{ text: t('error.markdownImageUnplaced', { file: shownPath(base, file), line: unplaced }) }] };
|
|
135
193
|
}
|
|
194
|
+
const shown = shownPath(base, file);
|
|
195
|
+
const problem = parseMarkdownText(result.text);
|
|
196
|
+
if (!problem.ok) {
|
|
197
|
+
const first = problem.problems[0];
|
|
198
|
+
if (first)
|
|
199
|
+
return { errors: [{ text: t('error.markdownProblem', { file: shown, problem: first.message }) }] };
|
|
200
|
+
}
|
|
201
|
+
const siteDir = pathToFileURL(base).href + '/';
|
|
202
|
+
const targets = [];
|
|
203
|
+
for (const { src, line } of markdownImages(result.text)) {
|
|
204
|
+
const refused = markdownImageProblem(src, line, shown, siteDir);
|
|
205
|
+
if (refused !== null)
|
|
206
|
+
return { errors: [{ text: refused }] };
|
|
207
|
+
if (/^file:/i.test(src))
|
|
208
|
+
targets.push(src);
|
|
209
|
+
}
|
|
210
|
+
for (const target of targets)
|
|
211
|
+
images?.add(target);
|
|
136
212
|
return { contents: result.text, loader: 'text' };
|
|
137
213
|
}
|
|
214
|
+
/** The files an image import may name, and an SVG, which the loader refuses with a message of its own. */
|
|
215
|
+
const IMAGE_FILTER = new RegExp(`\\.(${[...Object.keys(MARKDOWN_IMAGE_TYPES), '.svg'].map((e) => e.slice(1)).join('|')})$`, 'i');
|
|
216
|
+
/** The `pluginData` of a plugin's own `b.resolve` call, so no plugin callback resolves its own lookup again. */
|
|
217
|
+
const RESOLVING = Symbol('resolving');
|
|
218
|
+
/**
|
|
219
|
+
* An `onResolve` callback for image imports that resolves them as esbuild would, and remembers the importing file
|
|
220
|
+
* so `loadImage` can name it. Anything it can't resolve is left to the other callbacks and esbuild's own error.
|
|
221
|
+
*/
|
|
222
|
+
function imageResolver(b) {
|
|
223
|
+
return async (args) => {
|
|
224
|
+
if (args.kind === 'entry-point' || args.pluginData === RESOLVING)
|
|
225
|
+
return undefined;
|
|
226
|
+
const found = await b.resolve(fileUrlPath(args.path)?.path ?? args.path, {
|
|
227
|
+
kind: args.kind,
|
|
228
|
+
importer: args.importer,
|
|
229
|
+
resolveDir: args.resolveDir,
|
|
230
|
+
pluginData: RESOLVING,
|
|
231
|
+
});
|
|
232
|
+
if (found.errors.length > 0 || found.external || found.namespace !== 'file')
|
|
233
|
+
return undefined;
|
|
234
|
+
const pluginData = { importer: args.importer };
|
|
235
|
+
return { path: found.path, pluginData };
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* An image file at `file`, imported by `importer`, as a JSON module whose default export is its `CodeImage`, measured
|
|
240
|
+
* here so render never reads it. Refuses an image whose real path isn't inside the site's folder `base` with
|
|
241
|
+
* `error.imageImportOutside`, an SVG (by its name or its bytes) with `error.imageImportSvg`, bytes that aren't
|
|
242
|
+
* the picture its extension names with `error.imageImportMismatch`, and a picture sharp can't measure with
|
|
243
|
+
* `error.imageImportUnreadable`. `images` is given the `source` of an image that passes.
|
|
244
|
+
*/
|
|
245
|
+
async function loadImage(file, base, importer, images) {
|
|
246
|
+
const params = { file: shownPath(base, importer ?? file), image: relative(realpathSync(base), file) };
|
|
247
|
+
const refuse = (id) => ({ errors: [{ text: t(id, params) }] });
|
|
248
|
+
const real = realInsideSync(file, pathToFileURL(base).href + '/');
|
|
249
|
+
if (real === null)
|
|
250
|
+
return refuse('error.imageImportOutside');
|
|
251
|
+
const ext = extname(file).toLowerCase();
|
|
252
|
+
if (ext === '.svg')
|
|
253
|
+
return refuse('error.imageImportSvg');
|
|
254
|
+
const bytes = await readFile(real);
|
|
255
|
+
const mime = detectType(bytes, file);
|
|
256
|
+
if (mime === 'image/svg+xml')
|
|
257
|
+
return refuse('error.imageImportSvg');
|
|
258
|
+
const expected = MARKDOWN_IMAGE_TYPES[ext];
|
|
259
|
+
if (expected === undefined || mime !== expected)
|
|
260
|
+
return refuse('error.imageImportMismatch');
|
|
261
|
+
let meta;
|
|
262
|
+
try {
|
|
263
|
+
meta = await sharp(bytes).metadata();
|
|
264
|
+
}
|
|
265
|
+
catch {
|
|
266
|
+
return refuse('error.imageImportUnreadable');
|
|
267
|
+
}
|
|
268
|
+
if (!meta.width || !meta.height)
|
|
269
|
+
return refuse('error.imageImportUnreadable');
|
|
270
|
+
const turned = meta.orientation !== undefined && meta.orientation >= 5 && meta.orientation <= 8;
|
|
271
|
+
const image = {
|
|
272
|
+
kind: 'codeImage',
|
|
273
|
+
source: pathToFileURL(file).href,
|
|
274
|
+
sha: createHash('sha256').update(bytes).digest('hex'),
|
|
275
|
+
ext,
|
|
276
|
+
mime,
|
|
277
|
+
width: turned ? meta.height : meta.width,
|
|
278
|
+
height: turned ? meta.width : meta.height,
|
|
279
|
+
};
|
|
280
|
+
images?.add(image.source);
|
|
281
|
+
return { contents: JSON.stringify(image), loader: 'json' };
|
|
282
|
+
}
|
|
283
|
+
/** The `onLoad` callback for image imports, for the site's folder `base`; `images` collects their sources. */
|
|
284
|
+
function imageLoader(base, images) {
|
|
285
|
+
return (args) => {
|
|
286
|
+
if (args.namespace !== 'file')
|
|
287
|
+
return undefined;
|
|
288
|
+
return loadImage(args.path, base, args.pluginData?.importer, images);
|
|
289
|
+
};
|
|
290
|
+
}
|
|
138
291
|
/** The esbuild options `bundleSite` and `bundleConfig` share. */
|
|
139
292
|
function buildOptions(configFile, outFile, plugin) {
|
|
140
293
|
return {
|
|
@@ -163,12 +316,12 @@ export async function bundleConfig(configFile, outFile) {
|
|
|
163
316
|
// The running copy's own folder (`src/` or `dist/`): a file in it is imported, never bundled as a second copy.
|
|
164
317
|
const inlayDir = dirname(INLAY_ENTRIES.inlaycms ?? '');
|
|
165
318
|
const base = dirname(resolve(configFile));
|
|
166
|
-
const resolving = Symbol('resolving');
|
|
167
319
|
const plugin = {
|
|
168
320
|
name: 'inlay-config',
|
|
169
321
|
setup(b) {
|
|
322
|
+
b.onResolve({ filter: IMAGE_FILTER }, imageResolver(b));
|
|
170
323
|
b.onResolve({ filter: /.*/ }, async (args) => {
|
|
171
|
-
if (args.kind === 'entry-point' || args.pluginData ===
|
|
324
|
+
if (args.kind === 'entry-point' || args.pluginData === RESOLVING)
|
|
172
325
|
return undefined;
|
|
173
326
|
const running = INLAY_ENTRIES[args.path];
|
|
174
327
|
if (running !== undefined)
|
|
@@ -178,7 +331,7 @@ export async function bundleConfig(configFile, outFile) {
|
|
|
178
331
|
kind: args.kind,
|
|
179
332
|
importer: args.importer,
|
|
180
333
|
resolveDir: args.resolveDir,
|
|
181
|
-
pluginData:
|
|
334
|
+
pluginData: RESOLVING,
|
|
182
335
|
});
|
|
183
336
|
if (found.errors.length > 0)
|
|
184
337
|
return url;
|
|
@@ -194,6 +347,7 @@ export async function bundleConfig(configFile, outFile) {
|
|
|
194
347
|
return withOwnUrl(await readFile(args.path, 'utf8'), args.path, loader, await tsconfigFor(dirname(args.path)));
|
|
195
348
|
});
|
|
196
349
|
b.onLoad({ filter: /\.md$/ }, (args) => (args.namespace === 'file' ? loadMarkdown(args.path, base) : undefined));
|
|
350
|
+
b.onLoad({ filter: IMAGE_FILTER }, imageLoader(base));
|
|
197
351
|
},
|
|
198
352
|
};
|
|
199
353
|
try {
|
|
@@ -211,9 +365,11 @@ export async function bundleConfig(configFile, outFile) {
|
|
|
211
365
|
* any other import left outside the bundle (`inlaycms` itself included) with `error.packImport`, and site code
|
|
212
366
|
* (not installed packages) that reaches for the server with `error.packForbidden`; other build failures are
|
|
213
367
|
* `error.packBundle`. These checks catch mistakes: the release's signature is what makes it trusted. Returns the
|
|
214
|
-
* imports left in the bundle
|
|
368
|
+
* imports left in the bundle, and the `file:` URLs of the images site code names: those its `.md` files name, and
|
|
369
|
+
* those it imports.
|
|
215
370
|
*/
|
|
216
371
|
export async function bundleSite(configFile, outFile) {
|
|
372
|
+
const images = new Set();
|
|
217
373
|
const base = dirname(resolve(configFile));
|
|
218
374
|
const shown = (file) => shownPath(base, file);
|
|
219
375
|
const refused = [];
|
|
@@ -222,6 +378,7 @@ export async function bundleSite(configFile, outFile) {
|
|
|
222
378
|
const guard = {
|
|
223
379
|
name: 'inlay-release',
|
|
224
380
|
setup(b) {
|
|
381
|
+
b.onResolve({ filter: IMAGE_FILTER }, imageResolver(b));
|
|
225
382
|
b.onResolve({ filter: /.*/ }, (args) => {
|
|
226
383
|
if (args.kind === 'entry-point')
|
|
227
384
|
return undefined;
|
|
@@ -245,7 +402,8 @@ export async function bundleSite(configFile, outFile) {
|
|
|
245
402
|
}
|
|
246
403
|
return withOwnUrl(text, args.path, loader, await tsconfigFor(dirname(args.path)));
|
|
247
404
|
});
|
|
248
|
-
b.onLoad({ filter: /\.md$/ }, (args) => (args.namespace === 'file' ? loadMarkdown(args.path, base) : undefined));
|
|
405
|
+
b.onLoad({ filter: /\.md$/ }, (args) => (args.namespace === 'file' ? loadMarkdown(args.path, base, images) : undefined));
|
|
406
|
+
b.onLoad({ filter: IMAGE_FILTER }, imageLoader(base, images));
|
|
249
407
|
},
|
|
250
408
|
};
|
|
251
409
|
let result;
|
|
@@ -273,5 +431,5 @@ export async function bundleSite(configFile, outFile) {
|
|
|
273
431
|
throw new InlayError('release', 'error.packImport', { file: shown(resolve(configFile)), specifier });
|
|
274
432
|
}
|
|
275
433
|
}
|
|
276
|
-
return { imports: [...imports] };
|
|
434
|
+
return { imports: [...imports], codeImages: [...images].sort() };
|
|
277
435
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
+
import { CONSENT_CATEGORIES } from '../registry/integration.js';
|
|
2
3
|
import type { Registry } from '../registry/registry.js';
|
|
3
4
|
export declare const MANIFEST_FORMAT = 1;
|
|
4
5
|
export type ManifestRedirect = {
|
|
@@ -6,6 +7,13 @@ export type ManifestRedirect = {
|
|
|
6
7
|
to: string;
|
|
7
8
|
status: 301 | 302;
|
|
8
9
|
};
|
|
10
|
+
export type ManifestCsp = Record<string, string[]>;
|
|
11
|
+
export type ManifestIntegration = {
|
|
12
|
+
name: string;
|
|
13
|
+
label: string;
|
|
14
|
+
consent?: (typeof CONSENT_CATEGORIES)[number];
|
|
15
|
+
csp?: ManifestCsp;
|
|
16
|
+
};
|
|
9
17
|
/** What `manifest.json` in a release says; `manifest.sig` signs its bytes. */
|
|
10
18
|
export interface ReleaseManifest {
|
|
11
19
|
format: 1;
|
|
@@ -19,10 +27,14 @@ export interface ReleaseManifest {
|
|
|
19
27
|
secrets: string[];
|
|
20
28
|
/** Every file in the release except the manifest and its signature, to its sha256 (hex). */
|
|
21
29
|
files: Record<string, string>;
|
|
22
|
-
/**
|
|
30
|
+
/**
|
|
31
|
+
* Each shipped image or file as the site names it, to where the release keeps it (`content/<sha256><ext>`).
|
|
32
|
+
* `code` marks an image site code names (a `.md` file it imports, or an image it imports): only those are served at `/media/files/`.
|
|
33
|
+
*/
|
|
23
34
|
content: Array<{
|
|
24
35
|
source: string;
|
|
25
36
|
path: string;
|
|
37
|
+
code?: true;
|
|
26
38
|
}>;
|
|
27
39
|
/** The JSON Schema of each type's stored data, by type name, as the export manifest has it. */
|
|
28
40
|
schema: Record<string, unknown>;
|
|
@@ -45,6 +57,10 @@ export interface ReleaseManifest {
|
|
|
45
57
|
}>;
|
|
46
58
|
/** The site's code redirects in stored form; absent in manifests made before 0.3, which means none. */
|
|
47
59
|
redirects?: ManifestRedirect[];
|
|
60
|
+
/** The site's integrations; absent when it has none, and in manifests made before integrations. */
|
|
61
|
+
integrations?: ManifestIntegration[];
|
|
62
|
+
/** The sources the site's own `csp` adds, by directive; absent when empty. */
|
|
63
|
+
csp?: ManifestCsp;
|
|
48
64
|
locales: string[];
|
|
49
65
|
/** Each type's kind and slot names, by type name. */
|
|
50
66
|
types: Record<string, {
|
|
@@ -65,6 +81,7 @@ export declare const manifestSchema: z.ZodObject<{
|
|
|
65
81
|
content: z.ZodArray<z.ZodObject<{
|
|
66
82
|
source: z.ZodString;
|
|
67
83
|
path: z.ZodString;
|
|
84
|
+
code: z.ZodOptional<z.ZodLiteral<true>>;
|
|
68
85
|
}, z.core.$strict>>;
|
|
69
86
|
schema: z.ZodRecord<z.ZodString, z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
70
87
|
shipped: z.ZodArray<z.ZodObject<{
|
|
@@ -84,6 +101,17 @@ export declare const manifestSchema: z.ZodObject<{
|
|
|
84
101
|
to: z.ZodString;
|
|
85
102
|
status: z.ZodUnion<readonly [z.ZodLiteral<301>, z.ZodLiteral<302>]>;
|
|
86
103
|
}, z.core.$strict>>>;
|
|
104
|
+
integrations: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
105
|
+
name: z.ZodString;
|
|
106
|
+
label: z.ZodString;
|
|
107
|
+
consent: z.ZodOptional<z.ZodEnum<{
|
|
108
|
+
analytics: "analytics";
|
|
109
|
+
functional: "functional";
|
|
110
|
+
marketing: "marketing";
|
|
111
|
+
}>>;
|
|
112
|
+
csp: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString>>>;
|
|
113
|
+
}, z.core.$strict>>>;
|
|
114
|
+
csp: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString>>>;
|
|
87
115
|
locales: z.ZodArray<z.ZodString>;
|
|
88
116
|
types: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
89
117
|
kind: z.ZodEnum<{
|
|
@@ -94,11 +122,6 @@ export declare const manifestSchema: z.ZodObject<{
|
|
|
94
122
|
slots: z.ZodArray<z.ZodString>;
|
|
95
123
|
}, z.core.$strict>>;
|
|
96
124
|
}, z.core.$strict>;
|
|
97
|
-
/**
|
|
98
|
-
* Whether `version` falls in `range`, which is `^MAJOR.MINOR.PATCH`: for major 0, the same minor and a patch at
|
|
99
|
-
* least as high; otherwise the same major and a minor and patch at least as high.
|
|
100
|
-
*/
|
|
101
|
-
export declare function satisfies(version: string, range: string): boolean;
|
|
102
125
|
export declare function sha256Hex(bytes: Uint8Array): string;
|
|
103
126
|
/** Where a release keeps a shipped file: named by its sha256, keeping its extension. */
|
|
104
127
|
export declare function contentPath(file: string, bytes: Uint8Array): string;
|
|
@@ -5,6 +5,7 @@ import { z } from 'zod';
|
|
|
5
5
|
import { imageTarget } from '../content/shipped-images.js';
|
|
6
6
|
import { mapRichText, shippedFiles } from '../content/shipped-input.js';
|
|
7
7
|
import { typeSchemas } from '../export/schema.js';
|
|
8
|
+
import { CONSENT_CATEGORIES } from '../registry/integration.js';
|
|
8
9
|
import { markdownImages } from '../richtext/markdown.js';
|
|
9
10
|
import { inlayVersion } from '../version.js';
|
|
10
11
|
import { replaceImageTargets } from './markdown-file.js';
|
|
@@ -17,7 +18,7 @@ export const manifestSchema = z.strictObject({
|
|
|
17
18
|
inlay: z.strictObject({ version: z.string(), range: z.string() }),
|
|
18
19
|
secrets: z.array(z.string()),
|
|
19
20
|
files: z.record(z.string(), z.string().regex(SHA256)),
|
|
20
|
-
content: z.array(z.strictObject({ source: z.string(), path: z.string() })),
|
|
21
|
+
content: z.array(z.strictObject({ source: z.string(), path: z.string(), code: z.literal(true).optional() })),
|
|
21
22
|
schema: z.record(z.string(), z.record(z.string(), z.unknown())),
|
|
22
23
|
shipped: z.array(z.strictObject({
|
|
23
24
|
type: z.string(),
|
|
@@ -30,33 +31,18 @@ export const manifestSchema = z.strictObject({
|
|
|
30
31
|
redirects: z
|
|
31
32
|
.array(z.strictObject({ from: z.string(), to: z.string(), status: z.union([z.literal(301), z.literal(302)]) }))
|
|
32
33
|
.optional(),
|
|
34
|
+
integrations: z
|
|
35
|
+
.array(z.strictObject({
|
|
36
|
+
name: z.string(),
|
|
37
|
+
label: z.string(),
|
|
38
|
+
consent: z.enum(CONSENT_CATEGORIES).optional(),
|
|
39
|
+
csp: z.record(z.string(), z.array(z.string())).optional(),
|
|
40
|
+
}))
|
|
41
|
+
.optional(),
|
|
42
|
+
csp: z.record(z.string(), z.array(z.string())).optional(),
|
|
33
43
|
locales: z.array(z.string()),
|
|
34
44
|
types: z.record(z.string(), z.strictObject({ kind: z.enum(['singleton', 'collection', 'global']), slots: z.array(z.string()) })),
|
|
35
45
|
});
|
|
36
|
-
const VERSION = /^(\d+)\.(\d+)\.(\d+)(?:[-+].*)?$/;
|
|
37
|
-
function parts(version) {
|
|
38
|
-
const m = VERSION.exec(version);
|
|
39
|
-
return m ? [Number(m[1]), Number(m[2]), Number(m[3])] : null;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Whether `version` falls in `range`, which is `^MAJOR.MINOR.PATCH`: for major 0, the same minor and a patch at
|
|
43
|
-
* least as high; otherwise the same major and a minor and patch at least as high.
|
|
44
|
-
*/
|
|
45
|
-
export function satisfies(version, range) {
|
|
46
|
-
if (!range.startsWith('^'))
|
|
47
|
-
return false;
|
|
48
|
-
const want = parts(range.slice(1));
|
|
49
|
-
const have = parts(version);
|
|
50
|
-
if (!want || !have)
|
|
51
|
-
return false;
|
|
52
|
-
const [major, minor, patch] = want;
|
|
53
|
-
const [hMajor, hMinor, hPatch] = have;
|
|
54
|
-
if (hMajor !== major)
|
|
55
|
-
return false;
|
|
56
|
-
if (major === 0)
|
|
57
|
-
return hMinor === minor && hPatch >= patch;
|
|
58
|
-
return hMinor > minor || (hMinor === minor && hPatch >= patch);
|
|
59
|
-
}
|
|
60
46
|
export function sha256Hex(bytes) {
|
|
61
47
|
return createHash('sha256').update(bytes).digest('hex');
|
|
62
48
|
}
|
|
@@ -113,6 +99,14 @@ function withReleaseImages(markdown, siteDir, paths) {
|
|
|
113
99
|
return text;
|
|
114
100
|
return { markdown: text, images: markdownImages(markdown).map(({ src }) => releaseCopy(src) ?? src) };
|
|
115
101
|
}
|
|
102
|
+
/** `csp` as a manifest keeps it, or `undefined` when it adds no source. */
|
|
103
|
+
function cspOf(csp) {
|
|
104
|
+
const out = {};
|
|
105
|
+
for (const [directive, sources] of Object.entries(csp))
|
|
106
|
+
if (sources && sources.length > 0)
|
|
107
|
+
out[directive] = [...sources];
|
|
108
|
+
return Object.keys(out).length > 0 ? out : undefined;
|
|
109
|
+
}
|
|
116
110
|
/**
|
|
117
111
|
* The manifest of the site `registry` describes, without its files: what `packRelease` writes, given the shipped
|
|
118
112
|
* files it packed as `content`. Without `content`, shipped files are read here to name them the way a release
|
|
@@ -157,6 +151,13 @@ export function manifestOfRegistry(registry, opts) {
|
|
|
157
151
|
migrations: site.migrations.map((m) => m.name),
|
|
158
152
|
routes: site.routes.map((r) => ({ method: r.method, path: r.path, ...(r.sitemap === true && { sitemap: true }) })),
|
|
159
153
|
redirects: registry.redirects.map(({ from, to, status }) => ({ from, to, status })),
|
|
154
|
+
...(site.integrations.length > 0 && {
|
|
155
|
+
integrations: site.integrations.map(({ name, label, consent, csp }) => {
|
|
156
|
+
const sources = cspOf(csp);
|
|
157
|
+
return { name, label, ...(consent !== undefined && { consent }), ...(sources && { csp: sources }) };
|
|
158
|
+
}),
|
|
159
|
+
}),
|
|
160
|
+
...(cspOf(site.csp) && { csp: cspOf(site.csp) }),
|
|
160
161
|
locales: [...registry.locales],
|
|
161
162
|
types: Object.fromEntries([...registry.types].map(([name, def]) => [name, { kind: def.kind, slots: Object.keys(def.template.slots) }])),
|
|
162
163
|
};
|
|
@@ -3,10 +3,12 @@ import { existsSync } from 'node:fs';
|
|
|
3
3
|
import { copyFile, mkdir, mkdtemp, readdir, readFile, rm, writeFile } from 'node:fs/promises';
|
|
4
4
|
import { tmpdir } from 'node:os';
|
|
5
5
|
import { dirname, join, posix, relative, sep } from 'node:path';
|
|
6
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
6
7
|
import { promisify } from 'node:util';
|
|
7
8
|
import * as tar from 'tar';
|
|
8
9
|
import { loadConfig } from '../../config.js';
|
|
9
10
|
import { shippedFiles } from '../content/shipped-input.js';
|
|
11
|
+
import { realInsideSync } from '../content/shipped-images.js';
|
|
10
12
|
import { InlayError } from '../errors.js';
|
|
11
13
|
import { buildRegistry } from '../registry/registry.js';
|
|
12
14
|
import { bundleSite } from './bundle.js';
|
|
@@ -52,9 +54,18 @@ export async function packRelease(opts) {
|
|
|
52
54
|
const registry = buildRegistry(config.site);
|
|
53
55
|
const tmp = await mkdtemp(join(tmpdir(), 'inlay-pack-'));
|
|
54
56
|
try {
|
|
55
|
-
await bundleSite(file, join(tmp, 'site.js'));
|
|
57
|
+
const bundled = await bundleSite(file, join(tmp, 'site.js'));
|
|
56
58
|
const content = [];
|
|
59
|
+
const codeImages = new Set(bundled.codeImages);
|
|
57
60
|
const sources = shippedFiles(registry);
|
|
61
|
+
const known = new Set(sources.map((s) => s.source));
|
|
62
|
+
const siteDir = pathToFileURL(dir).href + '/';
|
|
63
|
+
for (const source of bundled.codeImages) {
|
|
64
|
+
if (known.has(source))
|
|
65
|
+
continue;
|
|
66
|
+
const path = fileURLToPath(source);
|
|
67
|
+
sources.push({ source, path, read: realInsideSync(path, siteDir) ?? path });
|
|
68
|
+
}
|
|
58
69
|
if (sources.length > 0)
|
|
59
70
|
await mkdir(join(tmp, 'content'));
|
|
60
71
|
for (const { source, path, read } of sources) {
|
|
@@ -67,7 +78,7 @@ export async function packRelease(opts) {
|
|
|
67
78
|
}
|
|
68
79
|
const target = contentPath(path, bytes);
|
|
69
80
|
await writeFile(join(tmp, target), bytes);
|
|
70
|
-
content.push({ source, path: target });
|
|
81
|
+
content.push({ source, path: target, ...(codeImages.has(source) && { code: true }) });
|
|
71
82
|
}
|
|
72
83
|
const publicDir = join(dir, 'public');
|
|
73
84
|
if (existsSync(publicDir)) {
|
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
import { randomUUID } from 'node:crypto';
|
|
2
2
|
import { readFile, rename, rm, writeFile } from 'node:fs/promises';
|
|
3
3
|
import { dirname, join } from 'node:path';
|
|
4
|
-
import { z } from 'zod';
|
|
5
4
|
import { InlayError } from '../errors.js';
|
|
6
|
-
|
|
5
|
+
function isPointer(value) {
|
|
6
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value))
|
|
7
|
+
return false;
|
|
8
|
+
const keys = Object.keys(value).sort();
|
|
9
|
+
if (keys.length !== 3 || keys[0] !== 'activatedAt' || keys[1] !== 'id' || keys[2] !== 'name')
|
|
10
|
+
return false;
|
|
11
|
+
const { id, name, activatedAt } = value;
|
|
12
|
+
return typeof id === 'string' && id !== '' && typeof name === 'string' && typeof activatedAt === 'string';
|
|
13
|
+
}
|
|
7
14
|
const POINTER = 'current.json';
|
|
8
15
|
/** The `releases` folder beside the database file, as in the host's data folder. */
|
|
9
16
|
export function releasesDirOf(dbPath) {
|
|
@@ -26,7 +33,11 @@ export async function readCurrentPointer(releasesDir) {
|
|
|
26
33
|
throw e;
|
|
27
34
|
}
|
|
28
35
|
try {
|
|
29
|
-
|
|
36
|
+
const value = JSON.parse(text);
|
|
37
|
+
if (!isPointer(value))
|
|
38
|
+
throw new Error('not a pointer');
|
|
39
|
+
const { id, name, activatedAt } = value;
|
|
40
|
+
return { id, name, activatedAt };
|
|
30
41
|
}
|
|
31
42
|
catch {
|
|
32
43
|
throw new InlayError('release', 'error.releasePointerInvalid', { file });
|
|
@@ -6,6 +6,8 @@ export interface LoadedRelease {
|
|
|
6
6
|
dir: string;
|
|
7
7
|
/** Each shipped file's source as the site names it, to the release's copy. */
|
|
8
8
|
shippedFiles: Map<string, string>;
|
|
9
|
+
/** As `shippedFiles`, only the images `.md` files the site imports name: what `/media/files/` serves. */
|
|
10
|
+
codeFiles: Map<string, string>;
|
|
9
11
|
publicDir: string | null;
|
|
10
12
|
}
|
|
11
13
|
/**
|
|
@@ -13,8 +15,8 @@ export interface LoadedRelease {
|
|
|
13
15
|
* package (from `src/` the package's own `exports` name `dist/`): field definitions are checked by identity.
|
|
14
16
|
*/
|
|
15
17
|
export declare const INLAY_ENTRIES: Readonly<Record<string, string>>;
|
|
16
|
-
/** Throws `error.
|
|
17
|
-
export declare function checkInlayVersion(
|
|
18
|
+
/** Throws `error.releaseTooOld` or `error.releaseTooNew` when a release packed with Inlay `packed` doesn't run on Inlay `version` (default: the running one). */
|
|
19
|
+
export declare function checkInlayVersion(packed: string, version?: string): void;
|
|
18
20
|
/**
|
|
19
21
|
* Opens the release file at `file` into the empty folder `opts.dir` without running any of it. The signature is
|
|
20
22
|
* checked against `opts.trustedKeys` before anything but the manifest is read, the Inlay version range next, and
|