@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
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { PgDatabase } from 'drizzle-orm/pg-core';
|
|
2
|
+
import { C as CmsRepo, N as NewDoc, D as DocPatch, a as NewVersion, S as StoredVersion, K as KeyRow, A as AuditQuery } from './repo-CeDxUxO6.cjs';
|
|
3
|
+
import { CmsTables } from './tables.cjs';
|
|
4
|
+
import { CmsDoc, DocStatus, ReviewMark, KeyScope, AuditEntry } from './types.cjs';
|
|
5
|
+
|
|
6
|
+
/** `CmsRepo` on Postgres via Drizzle (node-postgres, pglite and other `PgDatabase` drivers with transactions). */
|
|
7
|
+
|
|
8
|
+
type Db = PgDatabase<any, any, any>;
|
|
9
|
+
interface DrizzleRepoOptions {
|
|
10
|
+
/** A table set from `cmsTables({ prefix, schema })`. Default: the `cms_*` tables. */
|
|
11
|
+
tables?: CmsTables;
|
|
12
|
+
}
|
|
13
|
+
declare class DrizzleRepo implements CmsRepo {
|
|
14
|
+
readonly db: Db;
|
|
15
|
+
readonly t: CmsTables;
|
|
16
|
+
constructor(db: Db, o?: DrizzleRepoOptions);
|
|
17
|
+
private toDoc;
|
|
18
|
+
private patchRow;
|
|
19
|
+
private toVersion;
|
|
20
|
+
private toKey;
|
|
21
|
+
tx<T>(fn: (repo: CmsRepo) => Promise<T>): Promise<T>;
|
|
22
|
+
findDoc(collection: string, slug: string): Promise<CmsDoc | null>;
|
|
23
|
+
findDocById(id: string): Promise<CmsDoc | null>;
|
|
24
|
+
listDocs(f: {
|
|
25
|
+
collection?: string;
|
|
26
|
+
statuses?: DocStatus[];
|
|
27
|
+
published?: boolean;
|
|
28
|
+
}): Promise<CmsDoc[]>;
|
|
29
|
+
insertDoc(doc: NewDoc): Promise<CmsDoc>;
|
|
30
|
+
updateDoc(id: string, p: DocPatch, expectedVersion?: number): Promise<CmsDoc | null>;
|
|
31
|
+
deleteDoc(id: string): Promise<void>;
|
|
32
|
+
insertVersion(v: NewVersion): Promise<void>;
|
|
33
|
+
listVersions(documentId: string): Promise<StoredVersion[]>;
|
|
34
|
+
getVersion(documentId: string, version: number): Promise<StoredVersion | null>;
|
|
35
|
+
setVersionReviewed(documentId: string, version: number, reviewed: ReviewMark[]): Promise<void>;
|
|
36
|
+
pruneVersions(documentId: string, keep: number, protect: number[]): Promise<void>;
|
|
37
|
+
insertKey(k: {
|
|
38
|
+
name: string;
|
|
39
|
+
prefix: string;
|
|
40
|
+
hash: string;
|
|
41
|
+
scopes: KeyScope[];
|
|
42
|
+
collections: string[] | null;
|
|
43
|
+
createdBy: string | null;
|
|
44
|
+
expiresAt: string | null;
|
|
45
|
+
}): Promise<KeyRow>;
|
|
46
|
+
listKeys(): Promise<KeyRow[]>;
|
|
47
|
+
findKeyByHash(hash: string): Promise<KeyRow | null>;
|
|
48
|
+
touchKey(id: string, at: string): Promise<void>;
|
|
49
|
+
revokeKey(id: string, at: string): Promise<boolean>;
|
|
50
|
+
addHits(ids: string[], day: string, source: string): Promise<void>;
|
|
51
|
+
hitCounts(sinceDay: string, collection?: string): Promise<Map<string, number>>;
|
|
52
|
+
insertAudit(e: Omit<AuditEntry, "id">): Promise<void>;
|
|
53
|
+
listAudit(q: AuditQuery): Promise<{
|
|
54
|
+
id: string;
|
|
55
|
+
at: string;
|
|
56
|
+
actorKind: AuditEntry["actorKind"];
|
|
57
|
+
actorId: string | null;
|
|
58
|
+
actorLabel: string;
|
|
59
|
+
action: AuditEntry["action"];
|
|
60
|
+
collection: string | null;
|
|
61
|
+
slug: string | null;
|
|
62
|
+
version: number | null;
|
|
63
|
+
outcome: AuditEntry["outcome"];
|
|
64
|
+
via: "rest" | "mcp" | "ai" | "cli" | "app" | null;
|
|
65
|
+
detail: Record<string, unknown>;
|
|
66
|
+
}[]>;
|
|
67
|
+
changeStamp(): Promise<string>;
|
|
68
|
+
getMeta(key: string): Promise<{} | null>;
|
|
69
|
+
setMeta(key: string, value: unknown): Promise<void>;
|
|
70
|
+
/** Raw rows of a SQL query, across drivers (node-postgres returns `{ rows }`, pglite too, postgres.js an array). */
|
|
71
|
+
private rows;
|
|
72
|
+
/** What `agent-cms doctor` checks. Read-only. */
|
|
73
|
+
inspect(): Promise<DoctorReport>;
|
|
74
|
+
}
|
|
75
|
+
interface DoctorReport {
|
|
76
|
+
schemaVersion: number | null;
|
|
77
|
+
expectedSchemaVersion: number;
|
|
78
|
+
missingTables: string[];
|
|
79
|
+
missingColumns: string[];
|
|
80
|
+
/** 0.4.0 columns nothing reads any more. */
|
|
81
|
+
legacyColumns: string[];
|
|
82
|
+
/** A `cms_gaps` table from 0.5.x is still there (move it to the app, then drop it yourself). */
|
|
83
|
+
gapsTable: boolean;
|
|
84
|
+
gapsRows: number | null;
|
|
85
|
+
/** Documents whose published pointer is broken. */
|
|
86
|
+
badPublished: number;
|
|
87
|
+
orphanVersions: number;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export { type DoctorReport as D, DrizzleRepo as a, type DrizzleRepoOptions as b };
|
package/dist/errors.cjs
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
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/errors.ts
|
|
21
|
+
var errors_exports = {};
|
|
22
|
+
__export(errors_exports, {
|
|
23
|
+
CmsError: () => CmsError,
|
|
24
|
+
ERROR_CODES: () => ERROR_CODES,
|
|
25
|
+
ERROR_KINDS: () => ERROR_KINDS,
|
|
26
|
+
formatMessage: () => formatMessage,
|
|
27
|
+
isCmsError: () => isCmsError
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(errors_exports);
|
|
30
|
+
|
|
31
|
+
// src/messages/en.ts
|
|
32
|
+
var en = {
|
|
33
|
+
not_found: "Document not found",
|
|
34
|
+
version_not_found: "Version v{version} not found",
|
|
35
|
+
key_not_found: "API key not found",
|
|
36
|
+
route_not_found: "No such route",
|
|
37
|
+
unknown_collection: "Unknown collection: {collection}",
|
|
38
|
+
unauthorized: "Sign in or use an API key",
|
|
39
|
+
invalid_key: "The API key is wrong or revoked",
|
|
40
|
+
key_expired: "The API key expired on {expiresAt}",
|
|
41
|
+
preview_invalid: "This preview link is not valid",
|
|
42
|
+
preview_expired: "This preview link expired",
|
|
43
|
+
forbidden: "Not allowed",
|
|
44
|
+
forbidden_read: "No read access to {collection}",
|
|
45
|
+
forbidden_write: "No edit access to {collection}",
|
|
46
|
+
forbidden_publish: "No publish access to {collection}",
|
|
47
|
+
forbidden_keys: "No access to API keys",
|
|
48
|
+
forbidden_audit: "No access to the audit log",
|
|
49
|
+
key_too_wide: "A key can only create keys narrower than itself",
|
|
50
|
+
cross_site: "Cross-site request refused",
|
|
51
|
+
invalid: "Invalid input",
|
|
52
|
+
invalid_slug: "The slug may use lowercase letters, digits and hyphens (max {max})",
|
|
53
|
+
invalid_title: "The title must be 1 to {max} characters",
|
|
54
|
+
summary_too_long: "The summary must be at most {max} characters",
|
|
55
|
+
body_too_long: "The body is too long (max {max} characters)",
|
|
56
|
+
invalid_keywords: "At most {max} keywords of {maxLength} characters each",
|
|
57
|
+
forbidden_char: "The character \u201C{char}\u201D is not allowed",
|
|
58
|
+
invalid_category: "The category must be one of: {allowed}",
|
|
59
|
+
invalid_field: "{path}: {issue}",
|
|
60
|
+
unknown_link: "Unknown screen link: {keys}",
|
|
61
|
+
slug_locked: "A published document's slug cannot change",
|
|
62
|
+
not_published: "Only a published document can be hidden",
|
|
63
|
+
invalid_key_name: "The key name must be 1 to 60 characters",
|
|
64
|
+
scopes_required: "Choose at least one scope",
|
|
65
|
+
invalid_expiry: "The expiry date must be in the future",
|
|
66
|
+
invalid_anchor: "No section \u201C{anchor}\u201D. Sections: {valid}",
|
|
67
|
+
invalid_version: "Invalid version number",
|
|
68
|
+
invalid_request: "Invalid request: {issues}",
|
|
69
|
+
invalid_json: "The request body is not valid JSON",
|
|
70
|
+
body_too_large: "The request is too large",
|
|
71
|
+
preview_disabled: "Preview links are off (set previewSecret)",
|
|
72
|
+
no_public_url: "This collection has no public URL (set url)",
|
|
73
|
+
schema_outdated: "The database schema is v{found}, this version needs v{expected}. Run: {command}",
|
|
74
|
+
conflict_version: "Someone else saved v{current} since you read v{expected}. Reload or merge, then save",
|
|
75
|
+
slug_taken: "The slug {slug} is already used",
|
|
76
|
+
precondition_required: "Send If-Match (or expectedVersion) to change this document",
|
|
77
|
+
internal: "Something went wrong"
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
// src/errors.ts
|
|
81
|
+
var ERROR_KINDS = ["not_found", "unknown_collection", "forbidden", "unauthorized", "invalid", "conflict", "precondition", "internal"];
|
|
82
|
+
var ERROR_CODES = {
|
|
83
|
+
// not found
|
|
84
|
+
not_found: "not_found",
|
|
85
|
+
version_not_found: "not_found",
|
|
86
|
+
key_not_found: "not_found",
|
|
87
|
+
route_not_found: "not_found",
|
|
88
|
+
unknown_collection: "unknown_collection",
|
|
89
|
+
// access
|
|
90
|
+
unauthorized: "unauthorized",
|
|
91
|
+
invalid_key: "unauthorized",
|
|
92
|
+
key_expired: "unauthorized",
|
|
93
|
+
preview_invalid: "unauthorized",
|
|
94
|
+
preview_expired: "unauthorized",
|
|
95
|
+
forbidden: "forbidden",
|
|
96
|
+
forbidden_read: "forbidden",
|
|
97
|
+
forbidden_write: "forbidden",
|
|
98
|
+
forbidden_publish: "forbidden",
|
|
99
|
+
forbidden_keys: "forbidden",
|
|
100
|
+
forbidden_audit: "forbidden",
|
|
101
|
+
key_too_wide: "forbidden",
|
|
102
|
+
cross_site: "forbidden",
|
|
103
|
+
// validation
|
|
104
|
+
invalid: "invalid",
|
|
105
|
+
invalid_slug: "invalid",
|
|
106
|
+
invalid_title: "invalid",
|
|
107
|
+
summary_too_long: "invalid",
|
|
108
|
+
body_too_long: "invalid",
|
|
109
|
+
invalid_keywords: "invalid",
|
|
110
|
+
forbidden_char: "invalid",
|
|
111
|
+
invalid_category: "invalid",
|
|
112
|
+
invalid_field: "invalid",
|
|
113
|
+
unknown_link: "invalid",
|
|
114
|
+
slug_locked: "invalid",
|
|
115
|
+
not_published: "invalid",
|
|
116
|
+
invalid_key_name: "invalid",
|
|
117
|
+
scopes_required: "invalid",
|
|
118
|
+
invalid_expiry: "invalid",
|
|
119
|
+
invalid_anchor: "invalid",
|
|
120
|
+
invalid_version: "invalid",
|
|
121
|
+
invalid_request: "invalid",
|
|
122
|
+
invalid_json: "invalid",
|
|
123
|
+
body_too_large: "invalid",
|
|
124
|
+
preview_disabled: "invalid",
|
|
125
|
+
no_public_url: "invalid",
|
|
126
|
+
schema_outdated: "invalid",
|
|
127
|
+
// concurrency
|
|
128
|
+
conflict_version: "conflict",
|
|
129
|
+
slug_taken: "conflict",
|
|
130
|
+
precondition_required: "precondition",
|
|
131
|
+
// anything else
|
|
132
|
+
internal: "internal"
|
|
133
|
+
};
|
|
134
|
+
var STATUS = {
|
|
135
|
+
not_found: 404,
|
|
136
|
+
unknown_collection: 404,
|
|
137
|
+
unauthorized: 401,
|
|
138
|
+
forbidden: 403,
|
|
139
|
+
invalid: 422,
|
|
140
|
+
conflict: 409,
|
|
141
|
+
precondition: 428,
|
|
142
|
+
internal: 500
|
|
143
|
+
};
|
|
144
|
+
function formatMessage(messages, code, params = {}) {
|
|
145
|
+
const t = messages?.[code] ?? en[code] ?? code;
|
|
146
|
+
if (typeof t === "function") return t(params);
|
|
147
|
+
return t.replace(/\{(\w+)\}/g, (_, k) => {
|
|
148
|
+
const v = params[k];
|
|
149
|
+
return v == null ? "" : Array.isArray(v) ? v.join(", ") : String(v);
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
var CmsError = class extends Error {
|
|
153
|
+
constructor(code, params = {}, o = {}) {
|
|
154
|
+
super(o.message ?? formatMessage(o.messages, code, params));
|
|
155
|
+
this.code = code;
|
|
156
|
+
this.name = "CmsError";
|
|
157
|
+
this.kind = ERROR_CODES[code] ?? "internal";
|
|
158
|
+
this.status = o.status ?? STATUS[this.kind];
|
|
159
|
+
this.params = params;
|
|
160
|
+
this.diagnostics = o.diagnostics;
|
|
161
|
+
this.current = o.current;
|
|
162
|
+
}
|
|
163
|
+
code;
|
|
164
|
+
kind;
|
|
165
|
+
status;
|
|
166
|
+
params;
|
|
167
|
+
diagnostics;
|
|
168
|
+
current;
|
|
169
|
+
/** Marks CmsErrors so `isCmsError` works across bundle copies of this class. */
|
|
170
|
+
isCmsError = true;
|
|
171
|
+
/** The wire shape (REST body, MCP error text, AI tool result). */
|
|
172
|
+
toJSON() {
|
|
173
|
+
return {
|
|
174
|
+
error: this.code,
|
|
175
|
+
kind: this.kind,
|
|
176
|
+
message: this.message,
|
|
177
|
+
params: this.params,
|
|
178
|
+
...this.diagnostics ? { diagnostics: this.diagnostics } : {},
|
|
179
|
+
...this.current !== void 0 ? { current: this.current } : {}
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
function isCmsError(e) {
|
|
184
|
+
return !!e && typeof e === "object" && e.isCmsError === true;
|
|
185
|
+
}
|
|
186
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
187
|
+
0 && (module.exports = {
|
|
188
|
+
CmsError,
|
|
189
|
+
ERROR_CODES,
|
|
190
|
+
ERROR_KINDS,
|
|
191
|
+
formatMessage,
|
|
192
|
+
isCmsError
|
|
193
|
+
});
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The error contract. Every failure has a fine `code` (stable, for programs
|
|
3
|
+
* and agents), a coarse `kind` (what kind of failure, decides the HTTP
|
|
4
|
+
* status) and `params` (the values a message is built from). The message is
|
|
5
|
+
* only for people and comes from a catalog (`messages/en.ts` by default,
|
|
6
|
+
* `messages/ko.ts` or your own via `createCms({ messages })`).
|
|
7
|
+
*/
|
|
8
|
+
declare const ERROR_KINDS: readonly ["not_found", "unknown_collection", "forbidden", "unauthorized", "invalid", "conflict", "precondition", "internal"];
|
|
9
|
+
type CmsErrorKind = (typeof ERROR_KINDS)[number];
|
|
10
|
+
/** Every code with its kind. Add new codes here and in both catalogs. */
|
|
11
|
+
declare const ERROR_CODES: {
|
|
12
|
+
readonly not_found: "not_found";
|
|
13
|
+
readonly version_not_found: "not_found";
|
|
14
|
+
readonly key_not_found: "not_found";
|
|
15
|
+
readonly route_not_found: "not_found";
|
|
16
|
+
readonly unknown_collection: "unknown_collection";
|
|
17
|
+
readonly unauthorized: "unauthorized";
|
|
18
|
+
readonly invalid_key: "unauthorized";
|
|
19
|
+
readonly key_expired: "unauthorized";
|
|
20
|
+
readonly preview_invalid: "unauthorized";
|
|
21
|
+
readonly preview_expired: "unauthorized";
|
|
22
|
+
readonly forbidden: "forbidden";
|
|
23
|
+
readonly forbidden_read: "forbidden";
|
|
24
|
+
readonly forbidden_write: "forbidden";
|
|
25
|
+
readonly forbidden_publish: "forbidden";
|
|
26
|
+
readonly forbidden_keys: "forbidden";
|
|
27
|
+
readonly forbidden_audit: "forbidden";
|
|
28
|
+
readonly key_too_wide: "forbidden";
|
|
29
|
+
readonly cross_site: "forbidden";
|
|
30
|
+
readonly invalid: "invalid";
|
|
31
|
+
readonly invalid_slug: "invalid";
|
|
32
|
+
readonly invalid_title: "invalid";
|
|
33
|
+
readonly summary_too_long: "invalid";
|
|
34
|
+
readonly body_too_long: "invalid";
|
|
35
|
+
readonly invalid_keywords: "invalid";
|
|
36
|
+
readonly forbidden_char: "invalid";
|
|
37
|
+
readonly invalid_category: "invalid";
|
|
38
|
+
readonly invalid_field: "invalid";
|
|
39
|
+
readonly unknown_link: "invalid";
|
|
40
|
+
readonly slug_locked: "invalid";
|
|
41
|
+
readonly not_published: "invalid";
|
|
42
|
+
readonly invalid_key_name: "invalid";
|
|
43
|
+
readonly scopes_required: "invalid";
|
|
44
|
+
readonly invalid_expiry: "invalid";
|
|
45
|
+
readonly invalid_anchor: "invalid";
|
|
46
|
+
readonly invalid_version: "invalid";
|
|
47
|
+
readonly invalid_request: "invalid";
|
|
48
|
+
readonly invalid_json: "invalid";
|
|
49
|
+
readonly body_too_large: "invalid";
|
|
50
|
+
readonly preview_disabled: "invalid";
|
|
51
|
+
readonly no_public_url: "invalid";
|
|
52
|
+
readonly schema_outdated: "invalid";
|
|
53
|
+
readonly conflict_version: "conflict";
|
|
54
|
+
readonly slug_taken: "conflict";
|
|
55
|
+
readonly precondition_required: "precondition";
|
|
56
|
+
readonly internal: "internal";
|
|
57
|
+
};
|
|
58
|
+
type CmsErrorCode = keyof typeof ERROR_CODES;
|
|
59
|
+
type ErrorParams = Record<string, string | number | boolean | null | string[] | undefined>;
|
|
60
|
+
/** A message is a template (`{name}` placeholders) or a function of the params. */
|
|
61
|
+
type MessageTemplate = string | ((p: ErrorParams) => string);
|
|
62
|
+
type Messages = Record<CmsErrorCode, MessageTemplate>;
|
|
63
|
+
declare function formatMessage(messages: Partial<Messages> | undefined, code: CmsErrorCode, params?: ErrorParams): string;
|
|
64
|
+
/** One problem with a document, from `diagnose()`. */
|
|
65
|
+
interface Diagnostic {
|
|
66
|
+
/** Where: `slug`, `title`, `body`, `fields.tags.0`, … */
|
|
67
|
+
path: string;
|
|
68
|
+
code: CmsErrorCode;
|
|
69
|
+
message: string;
|
|
70
|
+
params: ErrorParams;
|
|
71
|
+
severity: "error" | "warning";
|
|
72
|
+
}
|
|
73
|
+
interface CmsErrorOptions {
|
|
74
|
+
message?: string;
|
|
75
|
+
messages?: Partial<Messages>;
|
|
76
|
+
/** Override the HTTP status the kind implies (e.g. 413, 400). */
|
|
77
|
+
status?: number;
|
|
78
|
+
/** Every problem when the error came from validation. */
|
|
79
|
+
diagnostics?: Diagnostic[];
|
|
80
|
+
/** On `conflict_version`: the current working copy, for a 3-way merge. */
|
|
81
|
+
current?: unknown;
|
|
82
|
+
}
|
|
83
|
+
declare class CmsError extends Error {
|
|
84
|
+
readonly code: CmsErrorCode;
|
|
85
|
+
readonly kind: CmsErrorKind;
|
|
86
|
+
readonly status: number;
|
|
87
|
+
readonly params: ErrorParams;
|
|
88
|
+
readonly diagnostics?: Diagnostic[];
|
|
89
|
+
current?: unknown;
|
|
90
|
+
/** Marks CmsErrors so `isCmsError` works across bundle copies of this class. */
|
|
91
|
+
readonly isCmsError = true;
|
|
92
|
+
constructor(code: CmsErrorCode, params?: ErrorParams, o?: CmsErrorOptions);
|
|
93
|
+
/** The wire shape (REST body, MCP error text, AI tool result). */
|
|
94
|
+
toJSON(): {
|
|
95
|
+
current?: {} | null | undefined;
|
|
96
|
+
diagnostics?: Diagnostic[] | undefined;
|
|
97
|
+
error: "not_found" | "unknown_collection" | "forbidden" | "unauthorized" | "invalid" | "internal" | "version_not_found" | "key_not_found" | "route_not_found" | "invalid_key" | "key_expired" | "preview_invalid" | "preview_expired" | "forbidden_read" | "forbidden_write" | "forbidden_publish" | "forbidden_keys" | "forbidden_audit" | "key_too_wide" | "cross_site" | "invalid_slug" | "invalid_title" | "summary_too_long" | "body_too_long" | "invalid_keywords" | "forbidden_char" | "invalid_category" | "invalid_field" | "unknown_link" | "slug_locked" | "not_published" | "invalid_key_name" | "scopes_required" | "invalid_expiry" | "invalid_anchor" | "invalid_version" | "invalid_request" | "invalid_json" | "body_too_large" | "preview_disabled" | "no_public_url" | "schema_outdated" | "conflict_version" | "slug_taken" | "precondition_required";
|
|
98
|
+
kind: "conflict" | "not_found" | "unknown_collection" | "forbidden" | "unauthorized" | "invalid" | "precondition" | "internal";
|
|
99
|
+
message: string;
|
|
100
|
+
params: ErrorParams;
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* True for any CmsError, even one from another copy of this package (bundlers
|
|
105
|
+
* can duplicate the class, which breaks `instanceof`). Use this, not instanceof.
|
|
106
|
+
*/
|
|
107
|
+
declare function isCmsError(e: unknown): e is CmsError;
|
|
108
|
+
|
|
109
|
+
export { CmsError, type CmsErrorCode, type CmsErrorKind, type CmsErrorOptions, type Diagnostic, ERROR_CODES, ERROR_KINDS, type ErrorParams, type MessageTemplate, type Messages, formatMessage, isCmsError };
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The error contract. Every failure has a fine `code` (stable, for programs
|
|
3
|
+
* and agents), a coarse `kind` (what kind of failure, decides the HTTP
|
|
4
|
+
* status) and `params` (the values a message is built from). The message is
|
|
5
|
+
* only for people and comes from a catalog (`messages/en.ts` by default,
|
|
6
|
+
* `messages/ko.ts` or your own via `createCms({ messages })`).
|
|
7
|
+
*/
|
|
8
|
+
declare const ERROR_KINDS: readonly ["not_found", "unknown_collection", "forbidden", "unauthorized", "invalid", "conflict", "precondition", "internal"];
|
|
9
|
+
type CmsErrorKind = (typeof ERROR_KINDS)[number];
|
|
10
|
+
/** Every code with its kind. Add new codes here and in both catalogs. */
|
|
11
|
+
declare const ERROR_CODES: {
|
|
12
|
+
readonly not_found: "not_found";
|
|
13
|
+
readonly version_not_found: "not_found";
|
|
14
|
+
readonly key_not_found: "not_found";
|
|
15
|
+
readonly route_not_found: "not_found";
|
|
16
|
+
readonly unknown_collection: "unknown_collection";
|
|
17
|
+
readonly unauthorized: "unauthorized";
|
|
18
|
+
readonly invalid_key: "unauthorized";
|
|
19
|
+
readonly key_expired: "unauthorized";
|
|
20
|
+
readonly preview_invalid: "unauthorized";
|
|
21
|
+
readonly preview_expired: "unauthorized";
|
|
22
|
+
readonly forbidden: "forbidden";
|
|
23
|
+
readonly forbidden_read: "forbidden";
|
|
24
|
+
readonly forbidden_write: "forbidden";
|
|
25
|
+
readonly forbidden_publish: "forbidden";
|
|
26
|
+
readonly forbidden_keys: "forbidden";
|
|
27
|
+
readonly forbidden_audit: "forbidden";
|
|
28
|
+
readonly key_too_wide: "forbidden";
|
|
29
|
+
readonly cross_site: "forbidden";
|
|
30
|
+
readonly invalid: "invalid";
|
|
31
|
+
readonly invalid_slug: "invalid";
|
|
32
|
+
readonly invalid_title: "invalid";
|
|
33
|
+
readonly summary_too_long: "invalid";
|
|
34
|
+
readonly body_too_long: "invalid";
|
|
35
|
+
readonly invalid_keywords: "invalid";
|
|
36
|
+
readonly forbidden_char: "invalid";
|
|
37
|
+
readonly invalid_category: "invalid";
|
|
38
|
+
readonly invalid_field: "invalid";
|
|
39
|
+
readonly unknown_link: "invalid";
|
|
40
|
+
readonly slug_locked: "invalid";
|
|
41
|
+
readonly not_published: "invalid";
|
|
42
|
+
readonly invalid_key_name: "invalid";
|
|
43
|
+
readonly scopes_required: "invalid";
|
|
44
|
+
readonly invalid_expiry: "invalid";
|
|
45
|
+
readonly invalid_anchor: "invalid";
|
|
46
|
+
readonly invalid_version: "invalid";
|
|
47
|
+
readonly invalid_request: "invalid";
|
|
48
|
+
readonly invalid_json: "invalid";
|
|
49
|
+
readonly body_too_large: "invalid";
|
|
50
|
+
readonly preview_disabled: "invalid";
|
|
51
|
+
readonly no_public_url: "invalid";
|
|
52
|
+
readonly schema_outdated: "invalid";
|
|
53
|
+
readonly conflict_version: "conflict";
|
|
54
|
+
readonly slug_taken: "conflict";
|
|
55
|
+
readonly precondition_required: "precondition";
|
|
56
|
+
readonly internal: "internal";
|
|
57
|
+
};
|
|
58
|
+
type CmsErrorCode = keyof typeof ERROR_CODES;
|
|
59
|
+
type ErrorParams = Record<string, string | number | boolean | null | string[] | undefined>;
|
|
60
|
+
/** A message is a template (`{name}` placeholders) or a function of the params. */
|
|
61
|
+
type MessageTemplate = string | ((p: ErrorParams) => string);
|
|
62
|
+
type Messages = Record<CmsErrorCode, MessageTemplate>;
|
|
63
|
+
declare function formatMessage(messages: Partial<Messages> | undefined, code: CmsErrorCode, params?: ErrorParams): string;
|
|
64
|
+
/** One problem with a document, from `diagnose()`. */
|
|
65
|
+
interface Diagnostic {
|
|
66
|
+
/** Where: `slug`, `title`, `body`, `fields.tags.0`, … */
|
|
67
|
+
path: string;
|
|
68
|
+
code: CmsErrorCode;
|
|
69
|
+
message: string;
|
|
70
|
+
params: ErrorParams;
|
|
71
|
+
severity: "error" | "warning";
|
|
72
|
+
}
|
|
73
|
+
interface CmsErrorOptions {
|
|
74
|
+
message?: string;
|
|
75
|
+
messages?: Partial<Messages>;
|
|
76
|
+
/** Override the HTTP status the kind implies (e.g. 413, 400). */
|
|
77
|
+
status?: number;
|
|
78
|
+
/** Every problem when the error came from validation. */
|
|
79
|
+
diagnostics?: Diagnostic[];
|
|
80
|
+
/** On `conflict_version`: the current working copy, for a 3-way merge. */
|
|
81
|
+
current?: unknown;
|
|
82
|
+
}
|
|
83
|
+
declare class CmsError extends Error {
|
|
84
|
+
readonly code: CmsErrorCode;
|
|
85
|
+
readonly kind: CmsErrorKind;
|
|
86
|
+
readonly status: number;
|
|
87
|
+
readonly params: ErrorParams;
|
|
88
|
+
readonly diagnostics?: Diagnostic[];
|
|
89
|
+
current?: unknown;
|
|
90
|
+
/** Marks CmsErrors so `isCmsError` works across bundle copies of this class. */
|
|
91
|
+
readonly isCmsError = true;
|
|
92
|
+
constructor(code: CmsErrorCode, params?: ErrorParams, o?: CmsErrorOptions);
|
|
93
|
+
/** The wire shape (REST body, MCP error text, AI tool result). */
|
|
94
|
+
toJSON(): {
|
|
95
|
+
current?: {} | null | undefined;
|
|
96
|
+
diagnostics?: Diagnostic[] | undefined;
|
|
97
|
+
error: "not_found" | "unknown_collection" | "forbidden" | "unauthorized" | "invalid" | "internal" | "version_not_found" | "key_not_found" | "route_not_found" | "invalid_key" | "key_expired" | "preview_invalid" | "preview_expired" | "forbidden_read" | "forbidden_write" | "forbidden_publish" | "forbidden_keys" | "forbidden_audit" | "key_too_wide" | "cross_site" | "invalid_slug" | "invalid_title" | "summary_too_long" | "body_too_long" | "invalid_keywords" | "forbidden_char" | "invalid_category" | "invalid_field" | "unknown_link" | "slug_locked" | "not_published" | "invalid_key_name" | "scopes_required" | "invalid_expiry" | "invalid_anchor" | "invalid_version" | "invalid_request" | "invalid_json" | "body_too_large" | "preview_disabled" | "no_public_url" | "schema_outdated" | "conflict_version" | "slug_taken" | "precondition_required";
|
|
98
|
+
kind: "conflict" | "not_found" | "unknown_collection" | "forbidden" | "unauthorized" | "invalid" | "precondition" | "internal";
|
|
99
|
+
message: string;
|
|
100
|
+
params: ErrorParams;
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* True for any CmsError, even one from another copy of this package (bundlers
|
|
105
|
+
* can duplicate the class, which breaks `instanceof`). Use this, not instanceof.
|
|
106
|
+
*/
|
|
107
|
+
declare function isCmsError(e: unknown): e is CmsError;
|
|
108
|
+
|
|
109
|
+
export { CmsError, type CmsErrorCode, type CmsErrorKind, type CmsErrorOptions, type Diagnostic, ERROR_CODES, ERROR_KINDS, type ErrorParams, type MessageTemplate, type Messages, formatMessage, isCmsError };
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CmsError,
|
|
3
|
+
ERROR_CODES,
|
|
4
|
+
ERROR_KINDS,
|
|
5
|
+
formatMessage,
|
|
6
|
+
isCmsError
|
|
7
|
+
} from "./chunk-VICZ76TR.js";
|
|
8
|
+
import "./chunk-DOADAH4L.js";
|
|
9
|
+
import "./chunk-2NTK7H4W.js";
|
|
10
|
+
export {
|
|
11
|
+
CmsError,
|
|
12
|
+
ERROR_CODES,
|
|
13
|
+
ERROR_KINDS,
|
|
14
|
+
formatMessage,
|
|
15
|
+
isCmsError
|
|
16
|
+
};
|
|
@@ -0,0 +1,103 @@
|
|
|
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/frontmatter.ts
|
|
21
|
+
var frontmatter_exports = {};
|
|
22
|
+
__export(frontmatter_exports, {
|
|
23
|
+
docFromMarkdown: () => docFromMarkdown,
|
|
24
|
+
parseFrontmatter: () => parseFrontmatter
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(frontmatter_exports);
|
|
27
|
+
var DOC_KEYS = /* @__PURE__ */ new Set(["slug", "title", "summary", "category", "keywords"]);
|
|
28
|
+
function scalar(raw) {
|
|
29
|
+
const v = raw.trim();
|
|
30
|
+
if (v === "") return "";
|
|
31
|
+
if (v === "true") return true;
|
|
32
|
+
if (v === "false") return false;
|
|
33
|
+
if (v === "null" || v === "~") return null;
|
|
34
|
+
if (/^-?\d+(\.\d+)?$/.test(v)) return Number(v);
|
|
35
|
+
if (v.startsWith('"') && v.endsWith('"') || v.startsWith("'") && v.endsWith("'")) return v.slice(1, -1);
|
|
36
|
+
if (v.startsWith("[") && v.endsWith("]")) {
|
|
37
|
+
const inner = v.slice(1, -1).trim();
|
|
38
|
+
return inner ? splitOutsideQuotes(inner, ",").map((x) => scalar(x)) : [];
|
|
39
|
+
}
|
|
40
|
+
return v;
|
|
41
|
+
}
|
|
42
|
+
function splitOutsideQuotes(s, sep) {
|
|
43
|
+
const out = [];
|
|
44
|
+
let cur = "";
|
|
45
|
+
let q = null;
|
|
46
|
+
for (const ch of s) {
|
|
47
|
+
if (q) {
|
|
48
|
+
if (ch === q) q = null;
|
|
49
|
+
} else if (ch === '"' || ch === "'") q = ch;
|
|
50
|
+
else if (ch === sep) {
|
|
51
|
+
out.push(cur);
|
|
52
|
+
cur = "";
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
cur += ch;
|
|
56
|
+
}
|
|
57
|
+
out.push(cur);
|
|
58
|
+
return out;
|
|
59
|
+
}
|
|
60
|
+
function stripComment(line) {
|
|
61
|
+
let q = null;
|
|
62
|
+
for (let i = 0; i < line.length; i++) {
|
|
63
|
+
const ch = line[i];
|
|
64
|
+
if (q) {
|
|
65
|
+
if (ch === q) q = null;
|
|
66
|
+
} else if (ch === '"' || ch === "'") q = ch;
|
|
67
|
+
else if (ch === "#" && (i === 0 || /\s/.test(line[i - 1]))) return line.slice(0, i).trimEnd();
|
|
68
|
+
}
|
|
69
|
+
return line;
|
|
70
|
+
}
|
|
71
|
+
function parseFrontmatter(text) {
|
|
72
|
+
const src = text.replace(/^\uFEFF/, "").replace(/\r\n/g, "\n");
|
|
73
|
+
const m = /^---\n([\s\S]*?)\n---\n?/.exec(src);
|
|
74
|
+
if (!m) return { data: {}, body: src.trim() };
|
|
75
|
+
const data = {};
|
|
76
|
+
for (const line of m[1].split("\n")) {
|
|
77
|
+
const t = stripComment(line);
|
|
78
|
+
if (!t.trim()) continue;
|
|
79
|
+
const i = t.indexOf(":");
|
|
80
|
+
if (i < 1) throw new Error(`frontmatter: cannot read line "${line}"`);
|
|
81
|
+
data[t.slice(0, i).trim()] = scalar(t.slice(i + 1));
|
|
82
|
+
}
|
|
83
|
+
return { data, body: src.slice(m[0].length).trim() };
|
|
84
|
+
}
|
|
85
|
+
function docFromMarkdown(text, fallbackSlug) {
|
|
86
|
+
const { data, body } = parseFrontmatter(text);
|
|
87
|
+
const fields = {};
|
|
88
|
+
for (const [k, v] of Object.entries(data)) if (!DOC_KEYS.has(k)) fields[k] = v;
|
|
89
|
+
const doc = { body };
|
|
90
|
+
const slug = data.slug ?? fallbackSlug;
|
|
91
|
+
if (slug) doc.slug = String(slug);
|
|
92
|
+
if (data.title !== void 0) doc.title = String(data.title);
|
|
93
|
+
if (data.summary !== void 0) doc.summary = String(data.summary);
|
|
94
|
+
if (data.category !== void 0) doc.category = data.category === null ? null : String(data.category);
|
|
95
|
+
if (Array.isArray(data.keywords)) doc.keywords = data.keywords.map(String);
|
|
96
|
+
if (Object.keys(fields).length) doc.fields = fields;
|
|
97
|
+
return doc;
|
|
98
|
+
}
|
|
99
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
100
|
+
0 && (module.exports = {
|
|
101
|
+
docFromMarkdown,
|
|
102
|
+
parseFrontmatter
|
|
103
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { i as DocInput } from './cms-D6D89-qZ.cjs';
|
|
2
|
+
import 'zod';
|
|
3
|
+
import './diff.cjs';
|
|
4
|
+
import './errors.cjs';
|
|
5
|
+
import './repo-CeDxUxO6.cjs';
|
|
6
|
+
import './types.cjs';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Markdown file to document. The CLI's `put` reads a file like:
|
|
10
|
+
*
|
|
11
|
+
* ---
|
|
12
|
+
* title: 새 기능이 나왔어요
|
|
13
|
+
* summary: 한 줄 요약
|
|
14
|
+
* category: 기능
|
|
15
|
+
* keywords: [release, 출시]
|
|
16
|
+
* tags: [가이드, 도움말] # anything else goes into `fields`
|
|
17
|
+
* pinned: false
|
|
18
|
+
* ---
|
|
19
|
+
* 본문 (markdown)
|
|
20
|
+
*
|
|
21
|
+
* Values: strings (quotes optional), numbers, true/false/null, and one-line
|
|
22
|
+
* arrays `[a, b]`. No nesting: that is all a document's top level needs.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
declare function parseFrontmatter(text: string): {
|
|
26
|
+
data: Record<string, unknown>;
|
|
27
|
+
body: string;
|
|
28
|
+
};
|
|
29
|
+
/** A markdown file as document input. `slug` defaults to `fallbackSlug` (the file name). */
|
|
30
|
+
declare function docFromMarkdown(text: string, fallbackSlug?: string): DocInput;
|
|
31
|
+
|
|
32
|
+
export { docFromMarkdown, parseFrontmatter };
|