@mainsoft/agent-cms 0.0.0-stage → 0.6.1
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/CHANGELOG.md +49 -0
- package/LICENSE +21 -0
- package/README.md +347 -2
- package/TODO.md +178 -0
- package/UPGRADE-0.6.md +236 -0
- package/dist/agent.cjs +250 -0
- package/dist/agent.d.cts +88 -0
- package/dist/agent.d.ts +88 -0
- package/dist/agent.js +24 -0
- package/dist/ai.cjs +555 -0
- package/dist/ai.d.cts +48 -0
- package/dist/ai.d.ts +48 -0
- package/dist/ai.js +73 -0
- package/dist/bin.js +1556 -0
- package/dist/chunk-2NTK7H4W.js +10 -0
- package/dist/chunk-52NUUZC7.js +1446 -0
- package/dist/chunk-6K5ZTGHQ.js +30 -0
- package/dist/chunk-AKN7SUXU.js +281 -0
- package/dist/chunk-BTO42652.js +249 -0
- package/dist/chunk-CRDW6Q72.js +188 -0
- package/dist/chunk-DD56PTZ4.js +78 -0
- package/dist/chunk-DOADAH4L.js +52 -0
- package/dist/chunk-IGL2V6US.js +324 -0
- package/dist/chunk-IW3D4I7Q.js +317 -0
- package/dist/chunk-OQ55GEF3.js +6 -0
- package/dist/chunk-QC2M4NZY.js +158 -0
- package/dist/chunk-QIUXAUQ6.js +6 -0
- package/dist/chunk-QQV6VLYJ.js +204 -0
- package/dist/chunk-T66ZKBHF.js +25 -0
- package/dist/chunk-VICZ76TR.js +118 -0
- package/dist/cli.cjs +1596 -0
- package/dist/cli.d.cts +89 -0
- package/dist/cli.d.ts +89 -0
- package/dist/cli.js +534 -0
- package/dist/client.cjs +185 -0
- package/dist/client.d.cts +228 -0
- package/dist/client.d.ts +228 -0
- package/dist/client.js +13 -0
- package/dist/cms-BPp01z-8.d.ts +411 -0
- package/dist/cms-D6D89-qZ.d.cts +411 -0
- package/dist/config.cjs +61 -0
- package/dist/config.d.cts +36 -0
- package/dist/config.d.ts +36 -0
- package/dist/config.js +11 -0
- package/dist/diff.cjs +316 -0
- package/dist/diff.d.cts +122 -0
- package/dist/diff.d.ts +122 -0
- package/dist/diff.js +29 -0
- package/dist/drizzle-repo-B1rt7r4j.d.ts +90 -0
- package/dist/drizzle-repo-Cn-kL2FK.d.cts +90 -0
- package/dist/errors.cjs +193 -0
- package/dist/errors.d.cts +109 -0
- package/dist/errors.d.ts +109 -0
- package/dist/errors.js +16 -0
- package/dist/frontmatter.cjs +103 -0
- package/dist/frontmatter.d.cts +32 -0
- package/dist/frontmatter.d.ts +32 -0
- package/dist/frontmatter.js +9 -0
- package/dist/http.cjs +1104 -0
- package/dist/http.d.cts +67 -0
- package/dist/http.d.ts +67 -0
- package/dist/http.js +321 -0
- package/dist/index.cjs +3066 -0
- package/dist/index.d.cts +19 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +263 -0
- package/dist/markdown.cjs +220 -0
- package/dist/markdown.d.cts +88 -0
- package/dist/markdown.d.ts +88 -0
- package/dist/markdown.js +23 -0
- package/dist/mcp.cjs +649 -0
- package/dist/mcp.d.cts +33 -0
- package/dist/mcp.d.ts +33 -0
- package/dist/mcp.js +24 -0
- package/dist/messages/en.cjs +76 -0
- package/dist/messages/en.d.cts +7 -0
- package/dist/messages/en.d.ts +7 -0
- package/dist/messages/en.js +7 -0
- package/dist/messages/ko.cjs +76 -0
- package/dist/messages/ko.d.cts +7 -0
- package/dist/messages/ko.d.ts +7 -0
- package/dist/messages/ko.js +53 -0
- package/dist/registry/cms-audit.json +25 -0
- package/dist/registry/cms-command.json +23 -0
- package/dist/registry/cms-doc-editor.json +36 -0
- package/dist/registry/cms-doc-list.json +29 -0
- package/dist/registry/cms-empty.json +22 -0
- package/dist/registry/cms-keys.json +29 -0
- package/dist/registry/cms-lib.json +33 -0
- package/dist/registry/cms-merge.json +26 -0
- package/dist/registry/cms-shell.json +22 -0
- package/dist/registry/cms-versions.json +26 -0
- package/dist/registry/registry.json +255 -0
- package/dist/repo-BWI2Pkrv.d.ts +162 -0
- package/dist/repo-CeDxUxO6.d.cts +162 -0
- package/dist/tables.cjs +356 -0
- package/dist/tables.d.cts +3515 -0
- package/dist/tables.d.ts +3515 -0
- package/dist/tables.js +35 -0
- package/dist/tools.cjs +420 -0
- package/dist/tools.d.cts +27 -0
- package/dist/tools.d.ts +27 -0
- package/dist/tools.js +18 -0
- package/dist/types.cjs +226 -0
- package/dist/types.d.cts +286 -0
- package/dist/types.d.ts +286 -0
- package/dist/types.js +28 -0
- package/package.json +277 -4
package/dist/types.cjs
ADDED
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/types.ts
|
|
21
|
+
var types_exports = {};
|
|
22
|
+
__export(types_exports, {
|
|
23
|
+
AUDIT_ACTIONS: () => AUDIT_ACTIONS,
|
|
24
|
+
CmsError: () => CmsError,
|
|
25
|
+
DOC_STATUSES: () => DOC_STATUSES,
|
|
26
|
+
ERROR_CODES: () => ERROR_CODES,
|
|
27
|
+
ERROR_KINDS: () => ERROR_KINDS,
|
|
28
|
+
KEY_SCOPES: () => KEY_SCOPES,
|
|
29
|
+
VIAS: () => VIAS,
|
|
30
|
+
docState: () => docState,
|
|
31
|
+
formatMessage: () => formatMessage,
|
|
32
|
+
isCmsError: () => isCmsError
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(types_exports);
|
|
35
|
+
|
|
36
|
+
// src/messages/en.ts
|
|
37
|
+
var en = {
|
|
38
|
+
not_found: "Document not found",
|
|
39
|
+
version_not_found: "Version v{version} not found",
|
|
40
|
+
key_not_found: "API key not found",
|
|
41
|
+
route_not_found: "No such route",
|
|
42
|
+
unknown_collection: "Unknown collection: {collection}",
|
|
43
|
+
unauthorized: "Sign in or use an API key",
|
|
44
|
+
invalid_key: "The API key is wrong or revoked",
|
|
45
|
+
key_expired: "The API key expired on {expiresAt}",
|
|
46
|
+
preview_invalid: "This preview link is not valid",
|
|
47
|
+
preview_expired: "This preview link expired",
|
|
48
|
+
forbidden: "Not allowed",
|
|
49
|
+
forbidden_read: "No read access to {collection}",
|
|
50
|
+
forbidden_write: "No edit access to {collection}",
|
|
51
|
+
forbidden_publish: "No publish access to {collection}",
|
|
52
|
+
forbidden_keys: "No access to API keys",
|
|
53
|
+
forbidden_audit: "No access to the audit log",
|
|
54
|
+
key_too_wide: "A key can only create keys narrower than itself",
|
|
55
|
+
cross_site: "Cross-site request refused",
|
|
56
|
+
invalid: "Invalid input",
|
|
57
|
+
invalid_slug: "The slug may use lowercase letters, digits and hyphens (max {max})",
|
|
58
|
+
invalid_title: "The title must be 1 to {max} characters",
|
|
59
|
+
summary_too_long: "The summary must be at most {max} characters",
|
|
60
|
+
body_too_long: "The body is too long (max {max} characters)",
|
|
61
|
+
invalid_keywords: "At most {max} keywords of {maxLength} characters each",
|
|
62
|
+
forbidden_char: "The character \u201C{char}\u201D is not allowed",
|
|
63
|
+
invalid_category: "The category must be one of: {allowed}",
|
|
64
|
+
invalid_field: "{path}: {issue}",
|
|
65
|
+
unknown_link: "Unknown screen link: {keys}",
|
|
66
|
+
slug_locked: "A published document's slug cannot change",
|
|
67
|
+
not_published: "Only a published document can be hidden",
|
|
68
|
+
invalid_key_name: "The key name must be 1 to 60 characters",
|
|
69
|
+
scopes_required: "Choose at least one scope",
|
|
70
|
+
invalid_expiry: "The expiry date must be in the future",
|
|
71
|
+
invalid_anchor: "No section \u201C{anchor}\u201D. Sections: {valid}",
|
|
72
|
+
invalid_version: "Invalid version number",
|
|
73
|
+
invalid_request: "Invalid request: {issues}",
|
|
74
|
+
invalid_json: "The request body is not valid JSON",
|
|
75
|
+
body_too_large: "The request is too large",
|
|
76
|
+
preview_disabled: "Preview links are off (set previewSecret)",
|
|
77
|
+
no_public_url: "This collection has no public URL (set url)",
|
|
78
|
+
schema_outdated: "The database schema is v{found}, this version needs v{expected}. Run: {command}",
|
|
79
|
+
conflict_version: "Someone else saved v{current} since you read v{expected}. Reload or merge, then save",
|
|
80
|
+
slug_taken: "The slug {slug} is already used",
|
|
81
|
+
precondition_required: "Send If-Match (or expectedVersion) to change this document",
|
|
82
|
+
internal: "Something went wrong"
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
// src/errors.ts
|
|
86
|
+
var ERROR_KINDS = ["not_found", "unknown_collection", "forbidden", "unauthorized", "invalid", "conflict", "precondition", "internal"];
|
|
87
|
+
var ERROR_CODES = {
|
|
88
|
+
// not found
|
|
89
|
+
not_found: "not_found",
|
|
90
|
+
version_not_found: "not_found",
|
|
91
|
+
key_not_found: "not_found",
|
|
92
|
+
route_not_found: "not_found",
|
|
93
|
+
unknown_collection: "unknown_collection",
|
|
94
|
+
// access
|
|
95
|
+
unauthorized: "unauthorized",
|
|
96
|
+
invalid_key: "unauthorized",
|
|
97
|
+
key_expired: "unauthorized",
|
|
98
|
+
preview_invalid: "unauthorized",
|
|
99
|
+
preview_expired: "unauthorized",
|
|
100
|
+
forbidden: "forbidden",
|
|
101
|
+
forbidden_read: "forbidden",
|
|
102
|
+
forbidden_write: "forbidden",
|
|
103
|
+
forbidden_publish: "forbidden",
|
|
104
|
+
forbidden_keys: "forbidden",
|
|
105
|
+
forbidden_audit: "forbidden",
|
|
106
|
+
key_too_wide: "forbidden",
|
|
107
|
+
cross_site: "forbidden",
|
|
108
|
+
// validation
|
|
109
|
+
invalid: "invalid",
|
|
110
|
+
invalid_slug: "invalid",
|
|
111
|
+
invalid_title: "invalid",
|
|
112
|
+
summary_too_long: "invalid",
|
|
113
|
+
body_too_long: "invalid",
|
|
114
|
+
invalid_keywords: "invalid",
|
|
115
|
+
forbidden_char: "invalid",
|
|
116
|
+
invalid_category: "invalid",
|
|
117
|
+
invalid_field: "invalid",
|
|
118
|
+
unknown_link: "invalid",
|
|
119
|
+
slug_locked: "invalid",
|
|
120
|
+
not_published: "invalid",
|
|
121
|
+
invalid_key_name: "invalid",
|
|
122
|
+
scopes_required: "invalid",
|
|
123
|
+
invalid_expiry: "invalid",
|
|
124
|
+
invalid_anchor: "invalid",
|
|
125
|
+
invalid_version: "invalid",
|
|
126
|
+
invalid_request: "invalid",
|
|
127
|
+
invalid_json: "invalid",
|
|
128
|
+
body_too_large: "invalid",
|
|
129
|
+
preview_disabled: "invalid",
|
|
130
|
+
no_public_url: "invalid",
|
|
131
|
+
schema_outdated: "invalid",
|
|
132
|
+
// concurrency
|
|
133
|
+
conflict_version: "conflict",
|
|
134
|
+
slug_taken: "conflict",
|
|
135
|
+
precondition_required: "precondition",
|
|
136
|
+
// anything else
|
|
137
|
+
internal: "internal"
|
|
138
|
+
};
|
|
139
|
+
var STATUS = {
|
|
140
|
+
not_found: 404,
|
|
141
|
+
unknown_collection: 404,
|
|
142
|
+
unauthorized: 401,
|
|
143
|
+
forbidden: 403,
|
|
144
|
+
invalid: 422,
|
|
145
|
+
conflict: 409,
|
|
146
|
+
precondition: 428,
|
|
147
|
+
internal: 500
|
|
148
|
+
};
|
|
149
|
+
function formatMessage(messages, code, params = {}) {
|
|
150
|
+
const t = messages?.[code] ?? en[code] ?? code;
|
|
151
|
+
if (typeof t === "function") return t(params);
|
|
152
|
+
return t.replace(/\{(\w+)\}/g, (_, k) => {
|
|
153
|
+
const v = params[k];
|
|
154
|
+
return v == null ? "" : Array.isArray(v) ? v.join(", ") : String(v);
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
var CmsError = class extends Error {
|
|
158
|
+
constructor(code, params = {}, o = {}) {
|
|
159
|
+
super(o.message ?? formatMessage(o.messages, code, params));
|
|
160
|
+
this.code = code;
|
|
161
|
+
this.name = "CmsError";
|
|
162
|
+
this.kind = ERROR_CODES[code] ?? "internal";
|
|
163
|
+
this.status = o.status ?? STATUS[this.kind];
|
|
164
|
+
this.params = params;
|
|
165
|
+
this.diagnostics = o.diagnostics;
|
|
166
|
+
this.current = o.current;
|
|
167
|
+
}
|
|
168
|
+
code;
|
|
169
|
+
kind;
|
|
170
|
+
status;
|
|
171
|
+
params;
|
|
172
|
+
diagnostics;
|
|
173
|
+
current;
|
|
174
|
+
/** Marks CmsErrors so `isCmsError` works across bundle copies of this class. */
|
|
175
|
+
isCmsError = true;
|
|
176
|
+
/** The wire shape (REST body, MCP error text, AI tool result). */
|
|
177
|
+
toJSON() {
|
|
178
|
+
return {
|
|
179
|
+
error: this.code,
|
|
180
|
+
kind: this.kind,
|
|
181
|
+
message: this.message,
|
|
182
|
+
params: this.params,
|
|
183
|
+
...this.diagnostics ? { diagnostics: this.diagnostics } : {},
|
|
184
|
+
...this.current !== void 0 ? { current: this.current } : {}
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
function isCmsError(e) {
|
|
189
|
+
return !!e && typeof e === "object" && e.isCmsError === true;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// src/types.ts
|
|
193
|
+
var DOC_STATUSES = ["draft", "published", "archived"];
|
|
194
|
+
var KEY_SCOPES = ["read", "write", "publish", "admin"];
|
|
195
|
+
var VIAS = ["rest", "mcp", "ai", "cli", "app"];
|
|
196
|
+
var AUDIT_ACTIONS = [
|
|
197
|
+
"key.create",
|
|
198
|
+
"key.revoke",
|
|
199
|
+
"doc.publish",
|
|
200
|
+
"doc.unpublish",
|
|
201
|
+
"doc.archive",
|
|
202
|
+
"doc.unarchive",
|
|
203
|
+
"doc.delete",
|
|
204
|
+
"doc.restore",
|
|
205
|
+
"preview.create",
|
|
206
|
+
"access.denied",
|
|
207
|
+
"auth.failed"
|
|
208
|
+
];
|
|
209
|
+
function docState(doc) {
|
|
210
|
+
if (doc.status === "archived") return { state: "archived", modifiedSincePublish: false };
|
|
211
|
+
if (doc.publishedVersion === null) return { state: "draft", modifiedSincePublish: false };
|
|
212
|
+
return { state: "published", modifiedSincePublish: doc.version !== doc.publishedVersion };
|
|
213
|
+
}
|
|
214
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
215
|
+
0 && (module.exports = {
|
|
216
|
+
AUDIT_ACTIONS,
|
|
217
|
+
CmsError,
|
|
218
|
+
DOC_STATUSES,
|
|
219
|
+
ERROR_CODES,
|
|
220
|
+
ERROR_KINDS,
|
|
221
|
+
KEY_SCOPES,
|
|
222
|
+
VIAS,
|
|
223
|
+
docState,
|
|
224
|
+
formatMessage,
|
|
225
|
+
isCmsError
|
|
226
|
+
});
|
package/dist/types.d.cts
ADDED
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
import { ZodTypeAny } from 'zod';
|
|
2
|
+
export { CmsError, CmsErrorCode, CmsErrorKind, CmsErrorOptions, Diagnostic, ERROR_CODES, ERROR_KINDS, ErrorParams, MessageTemplate, Messages, formatMessage, isCmsError } from './errors.cjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* agent-cms — an add-on CMS that people (an admin screen) and agents (REST,
|
|
6
|
+
* MCP, AI SDK tools) edit together. Lives inside the app: no separate server.
|
|
7
|
+
*
|
|
8
|
+
* EXTRACTION RULE: nothing under `src/` may import from a host app (`@/`) or
|
|
9
|
+
* any app module (`src/parts.test.ts` enforces it).
|
|
10
|
+
*
|
|
11
|
+
* Browser-safe: no Node APIs here (the admin UI imports these types).
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* draft — the latest version is not public (an older one may be).
|
|
16
|
+
* published — the latest version is the public one.
|
|
17
|
+
* archived — hidden from the public; history kept.
|
|
18
|
+
*/
|
|
19
|
+
declare const DOC_STATUSES: readonly ["draft", "published", "archived"];
|
|
20
|
+
type DocStatus = (typeof DOC_STATUSES)[number];
|
|
21
|
+
declare const KEY_SCOPES: readonly ["read", "write", "publish", "admin"];
|
|
22
|
+
type KeyScope = (typeof KEY_SCOPES)[number];
|
|
23
|
+
/** How a request came in. Used for usage counts (`cms_hits.source`) and the audit log. */
|
|
24
|
+
declare const VIAS: readonly ["rest", "mcp", "ai", "cli", "app"];
|
|
25
|
+
type Via = (typeof VIAS)[number];
|
|
26
|
+
/** Who is acting. Either an app session (user), an API key, the app itself or nobody. */
|
|
27
|
+
type Actor = ({
|
|
28
|
+
kind: "anonymous";
|
|
29
|
+
} | {
|
|
30
|
+
kind: "user";
|
|
31
|
+
id: string;
|
|
32
|
+
label: string;
|
|
33
|
+
email?: string | null;
|
|
34
|
+
isAdmin: boolean;
|
|
35
|
+
} | {
|
|
36
|
+
kind: "key";
|
|
37
|
+
id: string;
|
|
38
|
+
label: string;
|
|
39
|
+
scopes: KeyScope[];
|
|
40
|
+
collections: string[] | null;
|
|
41
|
+
} | {
|
|
42
|
+
kind: "system";
|
|
43
|
+
label: string;
|
|
44
|
+
}) & {
|
|
45
|
+
/** Set by the transports (REST, MCP, AI tools); app code may leave it out. */
|
|
46
|
+
via?: Via;
|
|
47
|
+
};
|
|
48
|
+
/** The editable content of a document; one version = one snapshot of this. */
|
|
49
|
+
interface DocContent {
|
|
50
|
+
slug: string;
|
|
51
|
+
title: string;
|
|
52
|
+
summary: string;
|
|
53
|
+
body: string;
|
|
54
|
+
category: string | null;
|
|
55
|
+
keywords: string[];
|
|
56
|
+
fields: Record<string, unknown>;
|
|
57
|
+
}
|
|
58
|
+
/** Unsaved editor state kept by `cms.autosave()`. Never a version. */
|
|
59
|
+
interface AutosaveState {
|
|
60
|
+
content: DocContent;
|
|
61
|
+
at: string;
|
|
62
|
+
by: string | null;
|
|
63
|
+
/** The version the editor started from (the base of a 3-way merge). */
|
|
64
|
+
baseVersion: number;
|
|
65
|
+
}
|
|
66
|
+
interface CmsDoc extends DocContent {
|
|
67
|
+
id: string;
|
|
68
|
+
collection: string;
|
|
69
|
+
status: DocStatus;
|
|
70
|
+
/** Latest version number (the working copy). */
|
|
71
|
+
version: number;
|
|
72
|
+
/** Version that is public, or null when never published. */
|
|
73
|
+
publishedVersion: number | null;
|
|
74
|
+
/** The public snapshot (null when never published). */
|
|
75
|
+
published: DocContent | null;
|
|
76
|
+
/** First publish time; kept across unpublish and republish. */
|
|
77
|
+
publishedAt: string | null;
|
|
78
|
+
/** Last time it went public again after being hidden or unpublished. */
|
|
79
|
+
republishedAt: string | null;
|
|
80
|
+
createdAt: string;
|
|
81
|
+
updatedAt: string;
|
|
82
|
+
/** Label of whoever wrote the latest version. */
|
|
83
|
+
updatedBy: string | null;
|
|
84
|
+
updatedByKind: "user" | "key" | "system" | null;
|
|
85
|
+
/** Unsaved editor content (only for editors; never on a public read). */
|
|
86
|
+
autosave: AutosaveState | null;
|
|
87
|
+
}
|
|
88
|
+
/** What `commit()` records about a version: changed fields and body hunks. */
|
|
89
|
+
interface VersionChange {
|
|
90
|
+
fields: string[];
|
|
91
|
+
/** Body hunks (added and removed lines) against the previous version. */
|
|
92
|
+
hunks: {
|
|
93
|
+
id: string;
|
|
94
|
+
removed: string[];
|
|
95
|
+
added: string[];
|
|
96
|
+
before?: string | null;
|
|
97
|
+
}[];
|
|
98
|
+
}
|
|
99
|
+
/** A reviewed agent change (`cms.reviewChanges`). */
|
|
100
|
+
interface ReviewMark {
|
|
101
|
+
hunk: string;
|
|
102
|
+
by: string;
|
|
103
|
+
at: string;
|
|
104
|
+
action: "accepted" | "reverted";
|
|
105
|
+
}
|
|
106
|
+
interface CmsVersion {
|
|
107
|
+
id: string;
|
|
108
|
+
documentId: string;
|
|
109
|
+
version: number;
|
|
110
|
+
snapshot: DocContent;
|
|
111
|
+
authorKind: "user" | "key" | "system";
|
|
112
|
+
authorId: string | null;
|
|
113
|
+
authorLabel: string;
|
|
114
|
+
note: string | null;
|
|
115
|
+
published: boolean;
|
|
116
|
+
createdAt: string;
|
|
117
|
+
changed: VersionChange | null;
|
|
118
|
+
reviewed: ReviewMark[];
|
|
119
|
+
}
|
|
120
|
+
/** A version without its snapshot (version lists). */
|
|
121
|
+
type VersionSummary = Omit<CmsVersion, "snapshot"> & {
|
|
122
|
+
title: string;
|
|
123
|
+
};
|
|
124
|
+
interface CmsKey {
|
|
125
|
+
id: string;
|
|
126
|
+
name: string;
|
|
127
|
+
prefix: string;
|
|
128
|
+
scopes: KeyScope[];
|
|
129
|
+
collections: string[] | null;
|
|
130
|
+
lastUsedAt: string | null;
|
|
131
|
+
revokedAt: string | null;
|
|
132
|
+
/** null = never expires. */
|
|
133
|
+
expiresAt: string | null;
|
|
134
|
+
createdAt: string;
|
|
135
|
+
}
|
|
136
|
+
declare const AUDIT_ACTIONS: readonly ["key.create", "key.revoke", "doc.publish", "doc.unpublish", "doc.archive", "doc.unarchive", "doc.delete", "doc.restore", "preview.create", "access.denied", "auth.failed"];
|
|
137
|
+
type AuditAction = (typeof AUDIT_ACTIONS)[number];
|
|
138
|
+
interface AuditEntry {
|
|
139
|
+
id: string;
|
|
140
|
+
at: string;
|
|
141
|
+
actorKind: Actor["kind"];
|
|
142
|
+
actorId: string | null;
|
|
143
|
+
actorLabel: string;
|
|
144
|
+
action: AuditAction;
|
|
145
|
+
collection: string | null;
|
|
146
|
+
slug: string | null;
|
|
147
|
+
version: number | null;
|
|
148
|
+
outcome: "ok" | "denied" | "failed";
|
|
149
|
+
via: Via | null;
|
|
150
|
+
detail: Record<string, unknown>;
|
|
151
|
+
}
|
|
152
|
+
/** Passed to `createCms({ onSearchMiss })` when a search the caller flagged found nothing. */
|
|
153
|
+
interface SearchMissEvent {
|
|
154
|
+
query: string;
|
|
155
|
+
/** `normalizeQuery(query)`: particles dropped, words sorted — group by this. */
|
|
156
|
+
normalized: string;
|
|
157
|
+
collections: string[];
|
|
158
|
+
/** Anyone, anonymous included. Whether to keep it is the app's call. */
|
|
159
|
+
actor: Actor;
|
|
160
|
+
source: Via;
|
|
161
|
+
at: string;
|
|
162
|
+
/** Best results that scored below the threshold (max 3). */
|
|
163
|
+
nearest: {
|
|
164
|
+
collection: string;
|
|
165
|
+
slug: string;
|
|
166
|
+
anchor: string | null;
|
|
167
|
+
score: number;
|
|
168
|
+
coverage: number;
|
|
169
|
+
}[];
|
|
170
|
+
}
|
|
171
|
+
interface AccessArgs {
|
|
172
|
+
actor: Actor;
|
|
173
|
+
collection: string;
|
|
174
|
+
doc?: CmsDoc | null;
|
|
175
|
+
}
|
|
176
|
+
/** How the admin form shows one field (`admin.fields` in the collection). */
|
|
177
|
+
interface FieldAdmin {
|
|
178
|
+
label?: string;
|
|
179
|
+
help?: string;
|
|
180
|
+
widget?: "text" | "textarea" | "number" | "switch" | "select" | "multiselect" | "date" | "tags" | "json";
|
|
181
|
+
}
|
|
182
|
+
interface CollectionConfig<F extends ZodTypeAny | undefined = ZodTypeAny | undefined, S extends string = string> {
|
|
183
|
+
slug: S;
|
|
184
|
+
label: string;
|
|
185
|
+
/**
|
|
186
|
+
* Required. "public": anyone may read published documents unless
|
|
187
|
+
* `access.read` says otherwise. "internal": `access.read` is required (the
|
|
188
|
+
* CMS refuses to start without it), so nothing is public by accident.
|
|
189
|
+
*/
|
|
190
|
+
visibility: "public" | "internal";
|
|
191
|
+
/**
|
|
192
|
+
* Writes only through the host app (the `system` actor). Users and API keys
|
|
193
|
+
* can read it over REST and MCP but never create, edit, publish or delete.
|
|
194
|
+
*/
|
|
195
|
+
managed?: boolean;
|
|
196
|
+
/** Allowed category values (null = free text / none). */
|
|
197
|
+
categories?: readonly string[];
|
|
198
|
+
/** zod object for `fields`; parsed (with defaults) on every save. */
|
|
199
|
+
fields?: F;
|
|
200
|
+
versions?: {
|
|
201
|
+
/** Versions kept per document (0 = all). Default 100. */
|
|
202
|
+
max?: number;
|
|
203
|
+
/**
|
|
204
|
+
* true (default): saving a published document makes a draft; the public
|
|
205
|
+
* copy stays until it is published. false: a save to a published
|
|
206
|
+
* document republishes it (a changelog post edited in place).
|
|
207
|
+
*/
|
|
208
|
+
drafts?: boolean;
|
|
209
|
+
};
|
|
210
|
+
/** Slug rule override (default: lowercase ascii words joined by hyphens). */
|
|
211
|
+
slugPattern?: RegExp;
|
|
212
|
+
/** Characters the house style bans from title, summary and body. */
|
|
213
|
+
forbiddenChars?: readonly string[];
|
|
214
|
+
search?: {
|
|
215
|
+
/** Index published docs of this collection. Default true. */
|
|
216
|
+
enabled?: boolean;
|
|
217
|
+
};
|
|
218
|
+
/** `[[link:key|label]]` keys: return the URL, or null when the key is unknown. */
|
|
219
|
+
links?: {
|
|
220
|
+
resolve: (key: string) => string | null;
|
|
221
|
+
};
|
|
222
|
+
/** Public URL of a document (agent results, the editor's public link, preview links). */
|
|
223
|
+
url?: (doc: {
|
|
224
|
+
slug: string;
|
|
225
|
+
}) => string;
|
|
226
|
+
access?: {
|
|
227
|
+
/** Read published documents. Default for "public": everyone. Required for "internal". */
|
|
228
|
+
read?: (a: AccessArgs) => boolean;
|
|
229
|
+
/** Read drafts and versions; create and edit. */
|
|
230
|
+
write?: (a: AccessArgs) => boolean;
|
|
231
|
+
/** Publish, archive, restore-and-publish, delete. */
|
|
232
|
+
publish?: (a: AccessArgs) => boolean;
|
|
233
|
+
};
|
|
234
|
+
admin?: {
|
|
235
|
+
/** Per field path (`tags`, `seo.title`): label, help text, widget. */
|
|
236
|
+
fields?: Record<string, FieldAdmin>;
|
|
237
|
+
};
|
|
238
|
+
hooks?: {
|
|
239
|
+
/**
|
|
240
|
+
* After every write. `info.contentChanged` is false when only the draft
|
|
241
|
+
* changed (the public copy is the same), e.g. to skip ISR revalidation.
|
|
242
|
+
*/
|
|
243
|
+
afterChange?: Array<(doc: CmsDoc, info: {
|
|
244
|
+
contentChanged: boolean;
|
|
245
|
+
}) => void | Promise<void>>;
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
/** What the admin list shows for a document. */
|
|
249
|
+
interface DocState {
|
|
250
|
+
state: "draft" | "published" | "archived";
|
|
251
|
+
/** Published, and the working copy has changes the public does not see yet. */
|
|
252
|
+
modifiedSincePublish: boolean;
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Display state. The stored status is "draft" when a published document has
|
|
256
|
+
* a newer working copy; the admin shows that as "published, modified".
|
|
257
|
+
*/
|
|
258
|
+
declare function docState(doc: Pick<CmsDoc, "status" | "version" | "publishedVersion">): DocState;
|
|
259
|
+
/** List item without the body (`fields: "summary"` lists). */
|
|
260
|
+
interface DocSummary {
|
|
261
|
+
id: string;
|
|
262
|
+
collection: string;
|
|
263
|
+
slug: string;
|
|
264
|
+
title: string;
|
|
265
|
+
summary: string;
|
|
266
|
+
category: string | null;
|
|
267
|
+
status: DocStatus;
|
|
268
|
+
state: DocState["state"];
|
|
269
|
+
modifiedSincePublish: boolean;
|
|
270
|
+
version: number;
|
|
271
|
+
publishedVersion: number | null;
|
|
272
|
+
publishedAt: string | null;
|
|
273
|
+
updatedAt: string;
|
|
274
|
+
updatedBy: string | null;
|
|
275
|
+
updatedByKind: CmsDoc["updatedByKind"];
|
|
276
|
+
hits7d?: number;
|
|
277
|
+
}
|
|
278
|
+
interface DocCounts {
|
|
279
|
+
all: number;
|
|
280
|
+
draft: number;
|
|
281
|
+
published: number;
|
|
282
|
+
modified: number;
|
|
283
|
+
archived: number;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
export { AUDIT_ACTIONS, type AccessArgs, type Actor, type AuditAction, type AuditEntry, type AutosaveState, type CmsDoc, type CmsKey, type CmsVersion, type CollectionConfig, DOC_STATUSES, type DocContent, type DocCounts, type DocState, type DocStatus, type DocSummary, type FieldAdmin, KEY_SCOPES, type KeyScope, type ReviewMark, type SearchMissEvent, VIAS, type VersionChange, type VersionSummary, type Via, docState };
|