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
package/dist/core/boot.d.ts
CHANGED
|
@@ -26,6 +26,8 @@ export interface BootOptions {
|
|
|
26
26
|
content?: 'apply' | 'none';
|
|
27
27
|
/** A loaded release's shipped files, by source as written in the site. */
|
|
28
28
|
shippedFiles?: ReadonlyMap<string, string>;
|
|
29
|
+
/** As `shippedFiles`, only the images `.md` files the site imports name. */
|
|
30
|
+
codeFiles?: ReadonlyMap<string, string>;
|
|
29
31
|
}
|
|
30
32
|
export interface BootResult {
|
|
31
33
|
core: Core;
|
package/dist/core/boot.js
CHANGED
|
@@ -7,6 +7,7 @@ import { createCore } from './core.js';
|
|
|
7
7
|
import { openDatabase } from './db/connection.js';
|
|
8
8
|
import { migrateSystem, pendingSystemMigrations } from './db/migrate.js';
|
|
9
9
|
import { InlayError } from './errors.js';
|
|
10
|
+
import { policyWarnings } from './integrations/warnings.js';
|
|
10
11
|
import { t } from './messages/index.js';
|
|
11
12
|
import { formatReport } from './report.js';
|
|
12
13
|
/**
|
|
@@ -55,6 +56,7 @@ export async function upgradeDatabase(db, core, systemMigrations, auth, opts = {
|
|
|
55
56
|
for (const from of await core.codeRedirectLoops()) {
|
|
56
57
|
report.warnings.push({ code: 'redirect_loop', message: t('report.redirectLoop', { from }), redirect: { from } });
|
|
57
58
|
}
|
|
59
|
+
report.warnings.push(...policyWarnings(core.registry.site));
|
|
58
60
|
return report;
|
|
59
61
|
}
|
|
60
62
|
/** True for a database that has never been set up: no content tables yet. */
|
|
@@ -115,6 +117,7 @@ export async function bootInlay(opts) {
|
|
|
115
117
|
...(opts.uploads && { uploads: opts.uploads }),
|
|
116
118
|
...(opts.now && { now: opts.now }),
|
|
117
119
|
...(opts.shippedFiles && { shippedFiles: opts.shippedFiles }),
|
|
120
|
+
...(opts.codeFiles && { codeFiles: opts.codeFiles }),
|
|
118
121
|
});
|
|
119
122
|
const auth = opts.auth ? createAuthService({ db, ...opts.auth }) : null;
|
|
120
123
|
const systemMigrations = await pendingSystemMigrations(db);
|
|
@@ -7,13 +7,12 @@ import { isRecord } from '../fields/zod-internals.js';
|
|
|
7
7
|
import { inspectUpload } from '../media/library.js';
|
|
8
8
|
import { markdownToInlineText } from '../richtext/inline.js';
|
|
9
9
|
import { markdownImages, markdownToRichText } from '../richtext/markdown.js';
|
|
10
|
+
import { KEY_HREF } from '../richtext/markdown-text.js';
|
|
10
11
|
import { DEFAULT_RICH_TEXT } from '../richtext/schema.js';
|
|
11
12
|
import { docLabels } from './schema.js';
|
|
12
13
|
import { imageTarget, realInside, realInsideSync } from './shipped-images.js';
|
|
13
14
|
import { contentIssue } from './validate.js';
|
|
14
15
|
const KINDS = new Set(['image', 'file', 'richText', 'inlineText', 'ref', 'link']);
|
|
15
|
-
/** The start of a Markdown link target `](inlay:key/<type>` or `](inlay:key/<type>/<key>`; text elsewhere is left alone. */
|
|
16
|
-
const KEY_HREF = /\]\(inlay:key\/([\w-]+)(?:\/([\w-]+))?(?=[\s)])/g;
|
|
17
16
|
/** `root` with the value at `path` replaced, copying only the containers along the path. */
|
|
18
17
|
function setAt(root, path, value) {
|
|
19
18
|
const [head, ...rest] = path;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { z } from 'zod';
|
|
1
2
|
import { type MessageId } from '../messages/index.js';
|
|
2
3
|
import type { Registry } from '../registry/registry.js';
|
|
3
4
|
import type { ContentIssue, DocumentData, IssueCode, PathSegment } from '../types.js';
|
|
@@ -19,3 +20,9 @@ export declare function mergeIssues(first: ContentIssue[], more: ContentIssue[])
|
|
|
19
20
|
* the parsed data (defaults filled, unknown and blank keys stripped).
|
|
20
21
|
*/
|
|
21
22
|
export declare function validateContent(registry: Registry, type: string, data: unknown, level: Level): ValidationResult;
|
|
23
|
+
/**
|
|
24
|
+
* Validates a bare field object (`data` keyed by field) at `level`: `'draft'`
|
|
25
|
+
* is lenient, `'strict'` holds every field to its full rules. Blank values
|
|
26
|
+
* count as absent. Issue paths are the field keys.
|
|
27
|
+
*/
|
|
28
|
+
export declare function validateValues(schema: z.ZodObject, data: Record<string, unknown>, level: Level): ValidationResult;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { labelsAt, toDraftSchema } from '../fields/walk.js';
|
|
2
|
+
import { DATE_CHECK, DATETIME_CHECK, INLINE_TEXT_MAX, NON_BLANK, PATTERN_CHECK, TITLE_TEMPLATE_CHECK } from '../fields/builtins.js';
|
|
2
3
|
import { isRecord } from '../fields/zod-internals.js';
|
|
3
4
|
import { t } from '../messages/index.js';
|
|
4
5
|
import { docLabels, documentSchema } from './schema.js';
|
|
@@ -86,6 +87,10 @@ function mapIssue(issue, value) {
|
|
|
86
87
|
if (issue.code === 'custom' && issue.params?.check === TITLE_TEMPLATE_CHECK) {
|
|
87
88
|
return { code: 'invalid', messageId: 'issue.titleTemplate', params: {} };
|
|
88
89
|
}
|
|
90
|
+
if (issue.code === 'custom' && issue.params?.check === PATTERN_CHECK) {
|
|
91
|
+
const hint = typeof issue.params.hint === 'string' && issue.params.hint ? ` ${issue.params.hint}` : '';
|
|
92
|
+
return { code: 'invalid', messageId: 'issue.pattern', params: { hint } };
|
|
93
|
+
}
|
|
89
94
|
if (issue.code === 'invalid_type') {
|
|
90
95
|
const messageId = EXPECTED[issue.expected];
|
|
91
96
|
if (messageId)
|
|
@@ -128,3 +133,21 @@ export function validateContent(registry, type, data, level) {
|
|
|
128
133
|
});
|
|
129
134
|
return { ok: false, issues };
|
|
130
135
|
}
|
|
136
|
+
/**
|
|
137
|
+
* Validates a bare field object (`data` keyed by field) at `level`: `'draft'`
|
|
138
|
+
* is lenient, `'strict'` holds every field to its full rules. Blank values
|
|
139
|
+
* count as absent. Issue paths are the field keys.
|
|
140
|
+
*/
|
|
141
|
+
export function validateValues(schema, data, level) {
|
|
142
|
+
const input = withoutBlanks(data);
|
|
143
|
+
const result = (level === 'draft' ? toDraftSchema(schema) : schema).safeParse(input);
|
|
144
|
+
if (result.success)
|
|
145
|
+
return { ok: true, data: result.data };
|
|
146
|
+
const issues = result.error.issues.map((issue) => {
|
|
147
|
+
const path = issue.path.filter((s) => typeof s !== 'symbol');
|
|
148
|
+
const labels = labelsAt(schema, path) ?? path.map(String);
|
|
149
|
+
const { code, messageId, params } = mapIssue(issue, valueAt(input, path));
|
|
150
|
+
return contentIssue(path, labels, code, messageId, params);
|
|
151
|
+
});
|
|
152
|
+
return { ok: false, issues };
|
|
153
|
+
}
|
package/dist/core/core.d.ts
CHANGED
|
@@ -14,12 +14,15 @@ import { type VariantFormat } from './media/variants.js';
|
|
|
14
14
|
import type { SiteDefinition } from './registry/define.js';
|
|
15
15
|
import type { ReleaseMigration } from './registry/migration.js';
|
|
16
16
|
import { type Registry } from './registry/registry.js';
|
|
17
|
+
import { type ActiveIntegration, type IntegrationState } from './integrations/integrations.js';
|
|
17
18
|
import { type SiteLockStatus } from './site-lock/site-lock.js';
|
|
18
19
|
import { type SitemapEntry } from './site/sitemap.js';
|
|
19
20
|
import type { Activity, ContentInput, Ctx, DocumentData, DocumentSummary, DocumentView, ContentRef, Usage, DiffEntry, RevisionMeta, UploadLimits, MediaInfo, MediaStatus, LiveDocument, LiveState, RouteMatch, Redirect, RedirectInput, CodeRedirect } from './types.js';
|
|
20
21
|
export type { PatchOp, PublishResult, SaveResult, ShippedItem, ShippedReport };
|
|
21
22
|
export interface Core {
|
|
22
23
|
registry: Registry;
|
|
24
|
+
/** A loaded release's images that `.md` files the site imports name, by source: what `/media/files/` serves. */
|
|
25
|
+
readonly codeFiles?: ReadonlyMap<string, string>;
|
|
23
26
|
getDocument(id: string, opts?: {
|
|
24
27
|
state?: 'head' | 'published';
|
|
25
28
|
}): Promise<DocumentView | null>;
|
|
@@ -145,6 +148,17 @@ export interface Core {
|
|
|
145
148
|
path: string;
|
|
146
149
|
mime: string;
|
|
147
150
|
}>;
|
|
151
|
+
/** A resized variant of an image site code names, cached under `code-<sha>`. */
|
|
152
|
+
codeImageVariant(file: {
|
|
153
|
+
sha: string;
|
|
154
|
+
path: string;
|
|
155
|
+
}, opts: {
|
|
156
|
+
width: number;
|
|
157
|
+
format: VariantFormat;
|
|
158
|
+
}): Promise<{
|
|
159
|
+
path: string;
|
|
160
|
+
mime: string;
|
|
161
|
+
}>;
|
|
148
162
|
/** Re-creates missing refs of visible documents; returns how many documents it synced. */
|
|
149
163
|
repairRefs(): Promise<number>;
|
|
150
164
|
/** Entries whose slug gives them a page another path hides; editors can't save them until it changes. */
|
|
@@ -156,6 +170,11 @@ export interface Core {
|
|
|
156
170
|
liveDocuments(groupIds: string[], locale: string, opts?: {
|
|
157
171
|
state?: LiveState;
|
|
158
172
|
}): Promise<Map<string, LiveDocument>>;
|
|
173
|
+
/** The group id of each shipped-style document by `type/key` (a missing key means the type); deleted and unknown ones are left out. */
|
|
174
|
+
groupIdsByKey(refs: Array<{
|
|
175
|
+
type: string;
|
|
176
|
+
key: string | null;
|
|
177
|
+
}>): Promise<Map<string, string>>;
|
|
159
178
|
liveSingleton(type: string, locale: string, opts?: {
|
|
160
179
|
state?: LiveState;
|
|
161
180
|
}): Promise<LiveDocument | null>;
|
|
@@ -176,6 +195,14 @@ export interface Core {
|
|
|
176
195
|
siteLock(): Promise<SiteLockStatus>;
|
|
177
196
|
setSiteLock(enabled: boolean, ctx: Ctx): Promise<SiteLockStatus>;
|
|
178
197
|
setSitePassword(password: string, ctx: Ctx): Promise<SiteLockStatus>;
|
|
198
|
+
/** Every integration the site defines with its saved settings; owners only. */
|
|
199
|
+
integrations(ctx: Ctx): Promise<IntegrationState[]>;
|
|
200
|
+
saveIntegration(name: string, input: {
|
|
201
|
+
enabled: boolean;
|
|
202
|
+
values: Record<string, unknown>;
|
|
203
|
+
}, ctx: Ctx): Promise<void>;
|
|
204
|
+
/** The integrations that are on and whose saved values pass; for rendering, no actor. */
|
|
205
|
+
activeIntegrations(): Promise<ActiveIntegration[]>;
|
|
179
206
|
checkSitePassword(password: string): Promise<boolean>;
|
|
180
207
|
listRedirects(): Promise<Redirect[]>;
|
|
181
208
|
createRedirect(input: RedirectInput, ctx: Ctx): Promise<Redirect>;
|
|
@@ -220,6 +247,8 @@ export interface CreateCoreOptions {
|
|
|
220
247
|
uploads?: UploadLimits;
|
|
221
248
|
/** A loaded release's shipped files, by source as written in the site. */
|
|
222
249
|
shippedFiles?: ReadonlyMap<string, string>;
|
|
250
|
+
/** As `shippedFiles`, only the images `.md` files the site imports name. */
|
|
251
|
+
codeFiles?: ReadonlyMap<string, string>;
|
|
223
252
|
}
|
|
224
253
|
/** Builds the registry and binds the core functions. Does not migrate the database. */
|
|
225
254
|
export declare function createCore(opts: CreateCoreOptions): Core;
|
package/dist/core/core.js
CHANGED
|
@@ -26,12 +26,13 @@ import { InlayError } from './errors.js';
|
|
|
26
26
|
import { basename } from 'node:path';
|
|
27
27
|
import { DEFAULT_MAX_BYTES, DEFAULT_UPLOAD_TYPES } from './media/detect.js';
|
|
28
28
|
import { addMedia, deleteMedia, getMedia, listMedia, lookupMedia, mediaFile, mediaStats, setMediaAlt } from './media/library.js';
|
|
29
|
-
import { mediaVariant } from './media/variants.js';
|
|
29
|
+
import { codeImageVariant, mediaVariant } from './media/variants.js';
|
|
30
30
|
import { fileMediaStore } from './media/store.js';
|
|
31
31
|
import { buildRegistry } from './registry/registry.js';
|
|
32
|
+
import { activeIntegrations, listIntegrations, saveIntegration } from './integrations/integrations.js';
|
|
32
33
|
import { checkSitePassword, readSiteLock, setSiteLock, setSitePassword } from './site-lock/site-lock.js';
|
|
33
34
|
import { codeRedirectLoops, createRedirect, deleteRedirect, importRedirects, listCodeRedirects, listRedirects } from './redirects/redirects.js';
|
|
34
|
-
import { liveAlternates, liveDocuments, liveEntries, liveSingleton } from './site/live.js';
|
|
35
|
+
import { groupIdsByKey, liveAlternates, liveDocuments, liveEntries, liveSingleton } from './site/live.js';
|
|
35
36
|
import { resolvePath } from './site/resolve.js';
|
|
36
37
|
import { sitemapEntries } from './site/sitemap.js';
|
|
37
38
|
/** Builds the registry and binds the core functions. Does not migrate the database. */
|
|
@@ -74,6 +75,7 @@ export function createCore(opts) {
|
|
|
74
75
|
const published = (r) => r.items.length > 0;
|
|
75
76
|
return {
|
|
76
77
|
registry,
|
|
78
|
+
...(opts.codeFiles !== undefined && { codeFiles: opts.codeFiles }),
|
|
77
79
|
getDocument: (id, o) => getDocument(deps, id, o),
|
|
78
80
|
findSingleton: (type, locale) => findSingleton(deps, type, locale),
|
|
79
81
|
findTranslation: (groupId, locale) => findTranslation(deps, groupId, locale),
|
|
@@ -113,9 +115,11 @@ export function createCore(opts) {
|
|
|
113
115
|
deleteMedia: live((id, ctx) => deleteMedia(deps, id, ctx)),
|
|
114
116
|
mediaFile: (id) => mediaFile(deps, id),
|
|
115
117
|
mediaVariant: (id, o) => mediaVariant(deps, id, o),
|
|
118
|
+
codeImageVariant: (file, o) => codeImageVariant(deps, file, o),
|
|
116
119
|
repairRefs: () => repairRefs(deps),
|
|
117
120
|
shadowedEntries: () => shadowedEntries(deps),
|
|
118
121
|
liveDocuments: (groupIds, locale, o) => liveDocuments(deps, groupIds, locale, o),
|
|
122
|
+
groupIdsByKey: (refs) => groupIdsByKey(deps, refs),
|
|
119
123
|
liveSingleton: (type, locale, o) => liveSingleton(deps, type, locale, o),
|
|
120
124
|
liveEntries: (collection, locale, o) => liveEntries(deps, collection, locale, o),
|
|
121
125
|
liveAlternates: (groupId, o) => liveAlternates(deps, groupId, o),
|
|
@@ -190,6 +194,9 @@ export function createCore(opts) {
|
|
|
190
194
|
},
|
|
191
195
|
setSiteLock: live((enabled, ctx) => setSiteLock(deps, enabled, ctx)),
|
|
192
196
|
setSitePassword: live((password, ctx) => setSitePassword(deps, password, ctx)),
|
|
197
|
+
integrations: (ctx) => listIntegrations(deps, ctx),
|
|
198
|
+
saveIntegration: live((name, input, ctx) => saveIntegration(deps, name, input, ctx)),
|
|
199
|
+
activeIntegrations: () => activeIntegrations(deps),
|
|
193
200
|
checkSitePassword: (password) => checkSitePassword(deps, password),
|
|
194
201
|
listRedirects: () => listRedirects(deps),
|
|
195
202
|
createRedirect: live((input, ctx) => createRedirect(deps, input, ctx)),
|
|
@@ -242,6 +249,7 @@ export function readOnlyCore(core) {
|
|
|
242
249
|
repairRefs: refuse,
|
|
243
250
|
setSiteLock: refuse,
|
|
244
251
|
setSitePassword: refuse,
|
|
252
|
+
saveIntegration: refuse,
|
|
245
253
|
createRedirect: refuse,
|
|
246
254
|
deleteRedirect: refuse,
|
|
247
255
|
importRedirects: refuse,
|
package/dist/core/db/migrate.js
CHANGED
|
@@ -6,6 +6,7 @@ import * as m0004 from './migrations/0004_token_cutoffs.js';
|
|
|
6
6
|
import * as m0005 from './migrations/0005_site_lock.js';
|
|
7
7
|
import * as m0006 from './migrations/0006_releases.js';
|
|
8
8
|
import * as m0007 from './migrations/0007_published_at.js';
|
|
9
|
+
import * as m0008 from './migrations/0008_integrations.js';
|
|
9
10
|
const systemMigrations = {
|
|
10
11
|
'0001_content': m0001,
|
|
11
12
|
'0002_media': m0002,
|
|
@@ -14,6 +15,7 @@ const systemMigrations = {
|
|
|
14
15
|
'0005_site_lock': m0005,
|
|
15
16
|
'0006_releases': m0006,
|
|
16
17
|
'0007_published_at': m0007,
|
|
18
|
+
'0008_integrations': m0008,
|
|
17
19
|
};
|
|
18
20
|
function systemMigrator(db) {
|
|
19
21
|
return new Migrator({
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Integration settings: one row per integration the owner has saved, with its values as a JSON object. */
|
|
2
|
+
export async function up(db) {
|
|
3
|
+
await db.schema
|
|
4
|
+
.createTable('integrations')
|
|
5
|
+
.addColumn('name', 'text', (c) => c.primaryKey())
|
|
6
|
+
.addColumn('enabled', 'integer', (c) => c.notNull())
|
|
7
|
+
.addColumn('data', 'text', (c) => c.notNull())
|
|
8
|
+
.addColumn('updated_at', 'text', (c) => c.notNull())
|
|
9
|
+
.addColumn('updated_by', 'text')
|
|
10
|
+
.execute();
|
|
11
|
+
}
|
package/dist/core/db/schema.d.ts
CHANGED
|
@@ -106,6 +106,16 @@ export interface TokenCutoffsTable {
|
|
|
106
106
|
/** Seconds since the epoch: tokens whose `iat` is at or before this are refused. */
|
|
107
107
|
before: number;
|
|
108
108
|
}
|
|
109
|
+
/** Integration settings: one row per integration the owner has saved. */
|
|
110
|
+
export interface IntegrationsTable {
|
|
111
|
+
name: string;
|
|
112
|
+
/** 0 or 1. */
|
|
113
|
+
enabled: number;
|
|
114
|
+
/** JSON object of the saved field values. */
|
|
115
|
+
data: string;
|
|
116
|
+
updated_at: string;
|
|
117
|
+
updated_by: string | null;
|
|
118
|
+
}
|
|
109
119
|
/** The site password lock: at most one row (`id = 1`). */
|
|
110
120
|
export interface SiteLockTable {
|
|
111
121
|
id: number;
|
|
@@ -149,6 +159,7 @@ export interface Database {
|
|
|
149
159
|
redirects: RedirectsTable;
|
|
150
160
|
token_cutoffs: TokenCutoffsTable;
|
|
151
161
|
site_lock: SiteLockTable;
|
|
162
|
+
integrations: IntegrationsTable;
|
|
152
163
|
releases: ReleasesTable;
|
|
153
164
|
release_migrations: ReleaseMigrationsTable;
|
|
154
165
|
user: UserTable;
|
|
@@ -8,6 +8,7 @@ import { openDatabase } from '../db/connection.js';
|
|
|
8
8
|
import { InlayError } from '../errors.js';
|
|
9
9
|
import { fileMediaStore } from '../media/store.js';
|
|
10
10
|
import { t } from '../messages/index.js';
|
|
11
|
+
import { readIntegrationRows } from '../integrations/integrations.js';
|
|
11
12
|
import { readSiteLock } from '../site-lock/site-lock.js';
|
|
12
13
|
import { targetOf } from '../redirects/rule.js';
|
|
13
14
|
import { inlayVersion } from '../version.js';
|
|
@@ -27,12 +28,14 @@ export async function exportContent(opts) {
|
|
|
27
28
|
let mediaRows;
|
|
28
29
|
let deletions;
|
|
29
30
|
let siteLock;
|
|
31
|
+
let integrations;
|
|
30
32
|
try {
|
|
31
33
|
content = await readContent(snap);
|
|
32
34
|
redirects = await readRedirects(snap);
|
|
33
35
|
mediaRows = await readMedia(snap);
|
|
34
36
|
deletions = await readDeletions(snap);
|
|
35
37
|
siteLock = await readSiteLock(snap);
|
|
38
|
+
integrations = await readIntegrationRows(snap);
|
|
36
39
|
}
|
|
37
40
|
finally {
|
|
38
41
|
await snap.destroy();
|
|
@@ -82,6 +85,7 @@ export async function exportContent(opts) {
|
|
|
82
85
|
})),
|
|
83
86
|
counts,
|
|
84
87
|
siteLock,
|
|
88
|
+
integrations,
|
|
85
89
|
};
|
|
86
90
|
await writeFile(join(staging, 'manifest.json'), JSON.stringify(manifest, null, 2));
|
|
87
91
|
await writeFile(join(staging, 'content.ndjson'), lines(content));
|
|
@@ -28,6 +28,12 @@ export interface Manifest {
|
|
|
28
28
|
enabled: boolean;
|
|
29
29
|
passwordHash: string | null;
|
|
30
30
|
};
|
|
31
|
+
/** The integration settings; absent in exports made before they existed. */
|
|
32
|
+
integrations?: Array<{
|
|
33
|
+
name: string;
|
|
34
|
+
enabled: boolean;
|
|
35
|
+
values: Record<string, unknown>;
|
|
36
|
+
}>;
|
|
31
37
|
}
|
|
32
38
|
export interface DocumentRecord {
|
|
33
39
|
record: 'document';
|
|
@@ -141,6 +147,11 @@ export declare const manifestSchema: z.ZodObject<{
|
|
|
141
147
|
enabled: z.ZodBoolean;
|
|
142
148
|
passwordHash: z.ZodNullable<z.ZodString>;
|
|
143
149
|
}, z.core.$strip>>;
|
|
150
|
+
integrations: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
151
|
+
name: z.ZodString;
|
|
152
|
+
enabled: z.ZodBoolean;
|
|
153
|
+
values: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
154
|
+
}, z.core.$strip>>>;
|
|
144
155
|
}, z.core.$strip>;
|
|
145
156
|
export declare const contentRecordSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
146
157
|
record: z.ZodLiteral<"document">;
|
|
@@ -30,6 +30,10 @@ export const manifestSchema = z.object({
|
|
|
30
30
|
.object({ enabled: z.boolean(), passwordHash: z.string().regex(/^[^:\s]+:[^:\s]+$/).nullable() })
|
|
31
31
|
.refine((lock) => !lock.enabled || lock.passwordHash !== null)
|
|
32
32
|
.optional(),
|
|
33
|
+
integrations: z
|
|
34
|
+
.array(z.object({ name: z.string(), enabled: z.boolean(), values: z.record(z.string(), z.unknown()) }))
|
|
35
|
+
.refine((rows) => new Set(rows.map((r) => r.name)).size === rows.length)
|
|
36
|
+
.optional(),
|
|
33
37
|
});
|
|
34
38
|
const documentRecord = z.object({
|
|
35
39
|
record: z.literal('document'),
|
|
@@ -85,6 +85,7 @@ export async function planImport(site, bundle, now, current) {
|
|
|
85
85
|
media: { files: bundle.media.length, damaged: bundle.damaged.map((m) => m.filename) },
|
|
86
86
|
redirects: { count: bundle.redirects.length },
|
|
87
87
|
shipped: await shippedTitles(stage),
|
|
88
|
+
integrations: manifest.integrations ? manifest.integrations.map((r) => ({ name: r.name, enabled: r.enabled })) : null,
|
|
88
89
|
siteLock: manifest.siteLock
|
|
89
90
|
? {
|
|
90
91
|
enabled: manifest.siteLock.enabled,
|
|
@@ -155,7 +156,7 @@ export async function importContent(opts) {
|
|
|
155
156
|
});
|
|
156
157
|
}
|
|
157
158
|
}
|
|
158
|
-
replaced = await replaceContent(opts.db, stage.db, bundle.manifest.siteLock);
|
|
159
|
+
replaced = await replaceContent(opts.db, stage.db, bundle.manifest.siteLock, bundle.manifest.integrations && { rows: bundle.manifest.integrations, now: (opts.now?.() ?? new Date()).toISOString(), by: opts.ctx.actor.id });
|
|
159
160
|
}
|
|
160
161
|
catch (e) {
|
|
161
162
|
if (store)
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Kysely } from 'kysely';
|
|
2
2
|
import type { Database } from '../db/schema.js';
|
|
3
|
+
import { type IntegrationRow } from '../integrations/integrations.js';
|
|
3
4
|
import { type SiteLockRow } from '../site-lock/site-lock.js';
|
|
4
5
|
export interface ReplaceCounts {
|
|
5
6
|
documents: number;
|
|
@@ -12,6 +13,10 @@ export interface ReplaceCounts {
|
|
|
12
13
|
* in one transaction. `removedMedia` lists the media ids `live` had that
|
|
13
14
|
* `from` doesn't, so the caller can remove their files once this commits.
|
|
14
15
|
*/
|
|
15
|
-
export declare function replaceContent(live: Kysely<Database>, from: Kysely<Database>, siteLock?: SiteLockRow
|
|
16
|
+
export declare function replaceContent(live: Kysely<Database>, from: Kysely<Database>, siteLock?: SiteLockRow, integrations?: {
|
|
17
|
+
rows: IntegrationRow[];
|
|
18
|
+
now: string;
|
|
19
|
+
by: string | null;
|
|
20
|
+
}): Promise<ReplaceCounts & {
|
|
16
21
|
removedMedia: string[];
|
|
17
22
|
}>;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { replaceIntegrationRows } from '../integrations/integrations.js';
|
|
1
2
|
import { writeSiteLock } from '../site-lock/site-lock.js';
|
|
2
3
|
const CHUNK = 200;
|
|
3
4
|
/** Deleted children first, so no foreign key is left pointing at a removed row. */
|
|
@@ -9,7 +10,7 @@ const COPY_ORDER = ['documents', 'revisions', 'publish_events', 'refs', 'media',
|
|
|
9
10
|
* in one transaction. `removedMedia` lists the media ids `live` had that
|
|
10
11
|
* `from` doesn't, so the caller can remove their files once this commits.
|
|
11
12
|
*/
|
|
12
|
-
export async function replaceContent(live, from, siteLock) {
|
|
13
|
+
export async function replaceContent(live, from, siteLock, integrations) {
|
|
13
14
|
return live.transaction().execute(async (trx) => {
|
|
14
15
|
const oldMedia = (await trx.selectFrom('media').select('id').execute()).map((m) => m.id);
|
|
15
16
|
for (const table of DELETE_ORDER)
|
|
@@ -24,6 +25,8 @@ export async function replaceContent(live, from, siteLock) {
|
|
|
24
25
|
}
|
|
25
26
|
if (siteLock)
|
|
26
27
|
await writeSiteLock(trx, siteLock);
|
|
28
|
+
if (integrations)
|
|
29
|
+
await replaceIntegrationRows(trx, integrations.rows, integrations.now, integrations.by);
|
|
27
30
|
const newMedia = new Set((await trx.selectFrom('media').select('id').execute()).map((m) => m.id));
|
|
28
31
|
return {
|
|
29
32
|
documents: copied.get('documents') ?? 0,
|
|
@@ -47,9 +47,15 @@ export interface ImportReport {
|
|
|
47
47
|
shipped: string[];
|
|
48
48
|
/** The export's lock, or null for an export made before the lock existed (the import leaves the lock alone). */
|
|
49
49
|
siteLock: ImportSiteLock | null;
|
|
50
|
+
/** The integrations the export carries, or null for an export made before they existed (the import leaves them alone). */
|
|
51
|
+
integrations: Array<{
|
|
52
|
+
name: string;
|
|
53
|
+
enabled: boolean;
|
|
54
|
+
}> | null;
|
|
50
55
|
}
|
|
51
56
|
/** What replacing the lock `current` with `exported` changes. */
|
|
52
57
|
export declare function siteLockEffects(exported: SiteLockRow, current: SiteLockRow): SiteLockEffect[];
|
|
53
58
|
export declare function siteLockLines(lock: ImportSiteLock | null): string[];
|
|
59
|
+
export declare function integrationLines(report: ImportReport): string[];
|
|
54
60
|
/** The report as lines a person reads: one per type and locale, with the documents needing attention indented, then everything else. */
|
|
55
61
|
export declare function formatImportReport(report: ImportReport): string[];
|
|
@@ -24,6 +24,12 @@ export function siteLockLines(lock) {
|
|
|
24
24
|
lines.push(t('import.siteLock.exportNoPassword'));
|
|
25
25
|
return lines;
|
|
26
26
|
}
|
|
27
|
+
export function integrationLines(report) {
|
|
28
|
+
if (!report.integrations)
|
|
29
|
+
return [];
|
|
30
|
+
const list = report.integrations.map((i) => t(i.enabled ? 'import.integrations.on' : 'import.integrations.off', { name: i.name })).join(', ');
|
|
31
|
+
return [t('import.integrations.replace', { list })];
|
|
32
|
+
}
|
|
27
33
|
/** The report as lines a person reads: one per type and locale, with the documents needing attention indented, then everything else. */
|
|
28
34
|
export function formatImportReport(report) {
|
|
29
35
|
const lines = [];
|
|
@@ -46,5 +52,6 @@ export function formatImportReport(report) {
|
|
|
46
52
|
if (report.shipped.length > 0)
|
|
47
53
|
lines.push(t('import.shipped', { titles: report.shipped.join(', ') }));
|
|
48
54
|
lines.push(...siteLockLines(report.siteLock));
|
|
55
|
+
lines.push(...integrationLines(report));
|
|
49
56
|
return lines;
|
|
50
57
|
}
|
|
@@ -8,7 +8,11 @@ interface BaseOptions {
|
|
|
8
8
|
interface TextOptions extends BaseOptions {
|
|
9
9
|
maxLength?: number;
|
|
10
10
|
suggestedLength?: number;
|
|
11
|
+
pattern?: RegExp;
|
|
12
|
+
patternHint?: string;
|
|
11
13
|
}
|
|
14
|
+
/** The `check` param of the refinement that holds a text field to its `pattern` (the hint is in `params.hint`). */
|
|
15
|
+
export declare const PATTERN_CHECK = "pattern";
|
|
12
16
|
/** Marks the issue from text and textarea's non-blank check (in `params.check`). */
|
|
13
17
|
export declare const NON_BLANK = "nonBlank";
|
|
14
18
|
/** The `check` param of the refinements that make a date or datetime field reject a malformed value. */
|
|
@@ -25,6 +25,8 @@ function isRealDate(s) {
|
|
|
25
25
|
const dt = new Date(Date.UTC(y, m - 1, d));
|
|
26
26
|
return dt.getUTCFullYear() === y && dt.getUTCMonth() === m - 1 && dt.getUTCDate() === d;
|
|
27
27
|
}
|
|
28
|
+
/** The `check` param of the refinement that holds a text field to its `pattern` (the hint is in `params.hint`). */
|
|
29
|
+
export const PATTERN_CHECK = 'pattern';
|
|
28
30
|
/** Marks the issue from text and textarea's non-blank check (in `params.check`). */
|
|
29
31
|
export const NON_BLANK = 'nonBlank';
|
|
30
32
|
/** The `check` param of the refinements that make a date or datetime field reject a malformed value. */
|
|
@@ -44,7 +46,15 @@ function stringField(kind, o, also) {
|
|
|
44
46
|
draft = draft.max(o.maxLength);
|
|
45
47
|
if (also)
|
|
46
48
|
draft = draft.refine(also.test, { params: { check: also.check } });
|
|
47
|
-
|
|
49
|
+
let strict = draft;
|
|
50
|
+
const { pattern } = o;
|
|
51
|
+
if (pattern) {
|
|
52
|
+
const re = new RegExp(pattern.source, pattern.flags.replace(/[gy]/g, ''));
|
|
53
|
+
strict = draft.refine((s) => s.trim().length === 0 || re.test(s), {
|
|
54
|
+
params: { check: PATTERN_CHECK, hint: o.patternHint ?? '' },
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
strict = strict.refine((s) => s.trim().length > 0, { params: { check: NON_BLANK } });
|
|
48
58
|
return defineField(strict, {
|
|
49
59
|
kind,
|
|
50
60
|
...base(o),
|
|
@@ -325,6 +325,10 @@ function toolbarLabels(headings) {
|
|
|
325
325
|
bulletList: t('admin.richtext.bulletList'),
|
|
326
326
|
orderedList: t('admin.richtext.orderedList'),
|
|
327
327
|
blockquote: t('admin.richtext.blockquote'),
|
|
328
|
+
codeBlock: t('admin.richtext.codeBlock'),
|
|
329
|
+
codeLanguage: t('admin.richtext.codeLanguage'),
|
|
330
|
+
codeLanguageHint: t('admin.richtext.codeLanguageHint'),
|
|
331
|
+
codeLanguageInvalid: t('admin.richtext.codeLanguageInvalid'),
|
|
328
332
|
image: t('admin.richtext.image'),
|
|
329
333
|
hardBreak: t('admin.richtext.hardBreak'),
|
|
330
334
|
table: t('admin.richtext.table'),
|
|
@@ -342,7 +346,7 @@ function renderRichText(p, inline) {
|
|
|
342
346
|
const features = RICH_TEXT_FEATURES.filter((feature) => opts.features.includes(feature));
|
|
343
347
|
const value = p.value === undefined ? '' : typeof p.value === 'string' ? p.value : JSON.stringify(p.value);
|
|
344
348
|
const links = `/admin/pick/documents?${new URLSearchParams({ locale: p.locale, web: '1' }).toString()}`;
|
|
345
|
-
return (_jsxs(_Fragment, { children: [p.value !== undefined && _jsx("input", { type: "hidden", name: `${p.name}._present`, value: "", disabled: p.readOnly }), _jsxs("div", { "data-richtext": true, "data-inline": inline, "data-name": p.name, "data-features": features.join(' '), "data-headings": opts.headings.join(' '), "data-labels": JSON.stringify(toolbarLabels(opts.headings)), "data-readonly": p.readOnly, "data-pick-link": links, "data-pick-image": "/admin/pick/media?kind=image", class: "flex flex-col rounded-box border border-base-300 bg-base-100", children: [_jsx("div", { role: "toolbar", "aria-label": t('admin.richtext.toolbar', { field: p.meta.label }), "aria-controls": p.id, class: "flex flex-wrap gap-1 border-b border-base-300 p-1 empty:hidden" }), _jsx("div", { "data-richtext-mount": true, role: "group", id: p.id, "aria-label": p.meta.label, "aria-describedby": p.describedBy, "aria-invalid": p.invalid ? 'true' : undefined, class: `${inline ? INLINE_TEXT_MOUNT : RICH_TEXT_MOUNT} [&_.ProseMirror]:outline-none [&_.ProseMirror-focused]:ring-2 [&_.ProseMirror-focused]:ring-primary [&_p]:my-2 [&_h2]:my-3 [&_h2]:text-2xl [&_h2]:font-bold [&_h3]:my-3 [&_h3]:text-xl [&_h3]:font-bold [&_h4]:my-2 [&_h4]:text-lg [&_h4]:font-semibold [&_h5]:font-semibold [&_h6]:font-semibold [&_h1]:text-3xl [&_h1]:font-bold [&_ul]:list-disc [&_ul]:pl-6 [&_ol]:list-decimal [&_ol]:pl-6 [&_blockquote]:border-l-4 [&_blockquote]:border-base-300 [&_blockquote]:pl-4 [&_a]:text-primary [&_a]:underline [&_code]:rounded [&_code]:bg-base-200 [&_code]:px-1 [&_code]:font-mono [&_code]:text-[0.9em] [&_table]:my-2 [&_table]:border-collapse [&_th]:border [&_th]:border-base-300 [&_th]:px-2 [&_th]:text-left [&_th]:font-semibold [&_td]:border [&_td]:border-base-300 [&_td]:px-2 [&_img]:inline-block [&_img]:max-h-40 [&_img]:rounded [&_.ProseMirror-selectednode]:outline-2 [&_.ProseMirror-selectednode]:outline-primary` }), _jsx("p", { "data-richtext-error": true, hidden: true, class: "mx-3 mb-3 rounded-box bg-warning px-3 py-1 text-sm text-warning-content", children: t('admin.richtext.unreadable') }), _jsx("input", { type: "hidden", name: p.name, value: value, disabled: p.readOnly }), _jsx("noscript", { children: _jsx("p", { class: "mx-3 mb-3 rounded-box bg-warning px-3 py-1 text-sm text-warning-content", children: t('admin.form.needsJs') }) })] })] }));
|
|
349
|
+
return (_jsxs(_Fragment, { children: [p.value !== undefined && _jsx("input", { type: "hidden", name: `${p.name}._present`, value: "", disabled: p.readOnly }), _jsxs("div", { "data-richtext": true, "data-inline": inline, "data-name": p.name, "data-features": features.join(' '), "data-headings": opts.headings.join(' '), "data-labels": JSON.stringify(toolbarLabels(opts.headings)), "data-readonly": p.readOnly, "data-pick-link": links, "data-pick-image": "/admin/pick/media?kind=image", class: "flex flex-col rounded-box border border-base-300 bg-base-100", children: [_jsx("div", { role: "toolbar", "aria-label": t('admin.richtext.toolbar', { field: p.meta.label }), "aria-controls": p.id, class: "flex flex-wrap gap-1 border-b border-base-300 p-1 empty:hidden" }), _jsx("div", { "data-richtext-mount": true, role: "group", id: p.id, "aria-label": p.meta.label, "aria-describedby": p.describedBy, "aria-invalid": p.invalid ? 'true' : undefined, class: `${inline ? INLINE_TEXT_MOUNT : RICH_TEXT_MOUNT} [&_.ProseMirror]:outline-none [&_.ProseMirror-focused]:ring-2 [&_.ProseMirror-focused]:ring-primary [&_p]:my-2 [&_h2]:my-3 [&_h2]:text-2xl [&_h2]:font-bold [&_h3]:my-3 [&_h3]:text-xl [&_h3]:font-bold [&_h4]:my-2 [&_h4]:text-lg [&_h4]:font-semibold [&_h5]:font-semibold [&_h6]:font-semibold [&_h1]:text-3xl [&_h1]:font-bold [&_ul]:list-disc [&_ul]:pl-6 [&_ol]:list-decimal [&_ol]:pl-6 [&_blockquote]:border-l-4 [&_blockquote]:border-base-300 [&_blockquote]:pl-4 [&_a]:text-primary [&_a]:underline [&_code]:rounded [&_code]:bg-base-200 [&_code]:px-1 [&_code]:font-mono [&_code]:text-[0.9em] [&_pre]:my-2 [&_pre]:overflow-x-auto [&_pre]:whitespace-pre! [&_pre]:rounded [&_pre]:bg-base-200 [&_pre]:p-3 [&_pre]:font-mono [&_pre]:text-[0.9em] [&_pre_code]:rounded-none [&_pre_code]:bg-transparent [&_pre_code]:p-0 [&_pre_code]:text-[1em] [&_table]:my-2 [&_table]:border-collapse [&_th]:border [&_th]:border-base-300 [&_th]:px-2 [&_th]:text-left [&_th]:font-semibold [&_td]:border [&_td]:border-base-300 [&_td]:px-2 [&_img]:inline-block [&_img]:max-h-40 [&_img]:rounded [&_.ProseMirror-selectednode]:outline-2 [&_.ProseMirror-selectednode]:outline-primary` }), _jsx("p", { "data-richtext-error": true, hidden: true, class: "mx-3 mb-3 rounded-box bg-warning px-3 py-1 text-sm text-warning-content", children: t('admin.richtext.unreadable') }), _jsx("input", { type: "hidden", name: p.name, value: value, disabled: p.readOnly }), _jsx("noscript", { children: _jsx("p", { class: "mx-3 mb-3 rounded-box bg-warning px-3 py-1 text-sm text-warning-content", children: t('admin.form.needsJs') }) })] })] }));
|
|
346
350
|
}
|
|
347
351
|
function parseRichTextForm(form, name, optional, parse) {
|
|
348
352
|
const raw = form.get(name);
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { Kysely } from 'kysely';
|
|
2
|
+
import type { Database } from '../db/schema.js';
|
|
3
|
+
import type { IntegrationDef } from '../registry/integration.js';
|
|
4
|
+
import type { CoreDeps, Ctx } from '../types.js';
|
|
5
|
+
export interface IntegrationRow {
|
|
6
|
+
name: string;
|
|
7
|
+
enabled: boolean;
|
|
8
|
+
values: Record<string, unknown>;
|
|
9
|
+
}
|
|
10
|
+
export interface IntegrationState {
|
|
11
|
+
def: IntegrationDef;
|
|
12
|
+
enabled: boolean;
|
|
13
|
+
values: Record<string, unknown>;
|
|
14
|
+
/** Switched on and the saved values pass the integration's fields now. */
|
|
15
|
+
active: boolean;
|
|
16
|
+
updatedAt: string | null;
|
|
17
|
+
}
|
|
18
|
+
export interface ActiveIntegration {
|
|
19
|
+
def: IntegrationDef;
|
|
20
|
+
values: Record<string, unknown>;
|
|
21
|
+
}
|
|
22
|
+
/** Every stored row, defined by the site or not, by name. */
|
|
23
|
+
export declare function readIntegrationRows(db: Kysely<Database>): Promise<IntegrationRow[]>;
|
|
24
|
+
/** Replaces the whole table. Opens no transaction of its own, so call it inside the caller's. */
|
|
25
|
+
export declare function replaceIntegrationRows(db: Kysely<Database>, rows: IntegrationRow[], now: string, by: string | null): Promise<void>;
|
|
26
|
+
export declare function listIntegrations(deps: CoreDeps, ctx: Ctx): Promise<IntegrationState[]>;
|
|
27
|
+
export declare function saveIntegration(deps: CoreDeps, name: string, input: {
|
|
28
|
+
enabled: boolean;
|
|
29
|
+
values: Record<string, unknown>;
|
|
30
|
+
}, ctx: Ctx): Promise<void>;
|
|
31
|
+
/** What the site adapter renders: switched on, with saved values that pass the fields now. Needs no actor. */
|
|
32
|
+
export declare function activeIntegrations(deps: CoreDeps): Promise<ActiveIntegration[]>;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { assertCan } from '../auth/roles.js';
|
|
2
|
+
import { validateValues } from '../content/validate.js';
|
|
3
|
+
import { InlayError } from '../errors.js';
|
|
4
|
+
function parseData(data) {
|
|
5
|
+
try {
|
|
6
|
+
const parsed = JSON.parse(data);
|
|
7
|
+
return typeof parsed === 'object' && parsed !== null && !Array.isArray(parsed) ? parsed : {};
|
|
8
|
+
}
|
|
9
|
+
catch {
|
|
10
|
+
return {};
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
/** Every stored row, defined by the site or not, by name. */
|
|
14
|
+
export async function readIntegrationRows(db) {
|
|
15
|
+
const rows = await db.selectFrom('integrations').selectAll().orderBy('name').execute();
|
|
16
|
+
return rows.map((r) => ({ name: r.name, enabled: r.enabled === 1, values: parseData(r.data) }));
|
|
17
|
+
}
|
|
18
|
+
/** Replaces the whole table. Opens no transaction of its own, so call it inside the caller's. */
|
|
19
|
+
export async function replaceIntegrationRows(db, rows, now, by) {
|
|
20
|
+
await db.deleteFrom('integrations').execute();
|
|
21
|
+
if (rows.length === 0)
|
|
22
|
+
return;
|
|
23
|
+
await db
|
|
24
|
+
.insertInto('integrations')
|
|
25
|
+
.values(rows.map((r) => ({ name: r.name, enabled: r.enabled ? 1 : 0, data: JSON.stringify(r.values), updated_at: now, updated_by: by })))
|
|
26
|
+
.execute();
|
|
27
|
+
}
|
|
28
|
+
function definitions(deps) {
|
|
29
|
+
return deps.registry.site.integrations;
|
|
30
|
+
}
|
|
31
|
+
export async function listIntegrations(deps, ctx) {
|
|
32
|
+
assertCan(ctx, 'integrations.manage');
|
|
33
|
+
const stored = await deps.db.selectFrom('integrations').selectAll().execute();
|
|
34
|
+
const byName = new Map(stored.map((r) => [r.name, r]));
|
|
35
|
+
return definitions(deps).map((def) => {
|
|
36
|
+
const row = byName.get(def.name);
|
|
37
|
+
if (!row)
|
|
38
|
+
return { def, enabled: false, values: {}, active: false, updatedAt: null };
|
|
39
|
+
const values = parseData(row.data);
|
|
40
|
+
const enabled = row.enabled === 1;
|
|
41
|
+
return { def, enabled, values, active: enabled && validateValues(def.fields, values, 'strict').ok, updatedAt: row.updated_at };
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
export async function saveIntegration(deps, name, input, ctx) {
|
|
45
|
+
assertCan(ctx, 'integrations.manage');
|
|
46
|
+
const def = definitions(deps).find((d) => d.name === name);
|
|
47
|
+
if (!def)
|
|
48
|
+
throw new InlayError('not_found', 'integrations.unknown', { name });
|
|
49
|
+
const result = validateValues(def.fields, input.values, input.enabled ? 'strict' : 'draft');
|
|
50
|
+
if (!result.ok)
|
|
51
|
+
throw new InlayError('validation', 'error.validation', {}, { issues: result.issues });
|
|
52
|
+
const values = {
|
|
53
|
+
name,
|
|
54
|
+
enabled: input.enabled ? 1 : 0,
|
|
55
|
+
data: JSON.stringify(result.data),
|
|
56
|
+
updated_at: deps.now().toISOString(),
|
|
57
|
+
updated_by: ctx.actor.id,
|
|
58
|
+
};
|
|
59
|
+
const { name: _name, ...update } = values;
|
|
60
|
+
await deps.db
|
|
61
|
+
.insertInto('integrations')
|
|
62
|
+
.values(values)
|
|
63
|
+
.onConflict((oc) => oc.column('name').doUpdateSet(update))
|
|
64
|
+
.execute();
|
|
65
|
+
}
|
|
66
|
+
/** What the site adapter renders: switched on, with saved values that pass the fields now. Needs no actor. */
|
|
67
|
+
export async function activeIntegrations(deps) {
|
|
68
|
+
const stored = await deps.db.selectFrom('integrations').selectAll().where('enabled', '=', 1).execute();
|
|
69
|
+
const byName = new Map(stored.map((r) => [r.name, r]));
|
|
70
|
+
const active = [];
|
|
71
|
+
for (const def of definitions(deps)) {
|
|
72
|
+
const row = byName.get(def.name);
|
|
73
|
+
if (!row)
|
|
74
|
+
continue;
|
|
75
|
+
const result = validateValues(def.fields, parseData(row.data), 'strict');
|
|
76
|
+
if (result.ok)
|
|
77
|
+
active.push({ def, values: result.data });
|
|
78
|
+
}
|
|
79
|
+
return active;
|
|
80
|
+
}
|