@mainsoft/agent-cms 0.7.0 → 0.10.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.
Files changed (111) hide show
  1. package/CHANGELOG.md +60 -0
  2. package/README.md +291 -32
  3. package/TODO.md +72 -26
  4. package/UPGRADE-0.10.md +36 -0
  5. package/UPGRADE-0.8.md +117 -0
  6. package/dist/agent.cjs +39 -17
  7. package/dist/agent.d.cts +2 -2
  8. package/dist/agent.d.ts +2 -2
  9. package/dist/agent.js +9 -7
  10. package/dist/bin.js +4528 -355
  11. package/dist/{chunk-OQ55GEF3.js → chunk-3OPKTBEI.js} +1 -1
  12. package/dist/chunk-6PB4ZCHH.js +328 -0
  13. package/dist/chunk-7SCYDG2G.js +2943 -0
  14. package/dist/chunk-7WJIIJCI.js +544 -0
  15. package/dist/chunk-7Y6TU2UA.js +150 -0
  16. package/dist/{chunk-EXV6JNLY.js → chunk-AKCXMT3X.js} +15 -22
  17. package/dist/{chunk-QC2M4NZY.js → chunk-BFVBHIHV.js} +72 -1
  18. package/dist/chunk-DSJETZT4.js +493 -0
  19. package/dist/{chunk-IW3D4I7Q.js → chunk-IU2SMWAM.js} +246 -4
  20. package/dist/{chunk-VICZ76TR.js → chunk-KAO3Z3CF.js} +43 -2
  21. package/dist/{chunk-CRDW6Q72.js → chunk-MA6VKJ3F.js} +87 -25
  22. package/dist/{chunk-6K5ZTGHQ.js → chunk-PEQY4N73.js} +16 -0
  23. package/dist/{chunk-DOADAH4L.js → chunk-PGV2QPIL.js} +40 -0
  24. package/dist/{chunk-Y63XQS2J.js → chunk-TOZQYJFG.js} +1 -1
  25. package/dist/cli.cjs +4528 -355
  26. package/dist/cli.d.cts +19 -3
  27. package/dist/cli.d.ts +19 -3
  28. package/dist/cli.js +206 -16
  29. package/dist/client.cjs +72 -1
  30. package/dist/client.d.cts +308 -6
  31. package/dist/client.d.ts +308 -6
  32. package/dist/client.js +1 -1
  33. package/dist/cms-C_vkAxYV.d.cts +1537 -0
  34. package/dist/cms-pqJyowu1.d.ts +1537 -0
  35. package/dist/config.d.cts +7 -1
  36. package/dist/config.d.ts +7 -1
  37. package/dist/drizzle-repo-CviH3EX7.d.cts +146 -0
  38. package/dist/drizzle-repo-DWLD0rWe.d.ts +146 -0
  39. package/dist/errors.cjs +82 -1
  40. package/dist/errors.d.cts +43 -3
  41. package/dist/errors.d.ts +43 -3
  42. package/dist/errors.js +2 -2
  43. package/dist/frontmatter.d.cts +5 -4
  44. package/dist/frontmatter.d.ts +5 -4
  45. package/dist/http.cjs +640 -94
  46. package/dist/http.d.cts +51 -2
  47. package/dist/http.d.ts +51 -2
  48. package/dist/http.js +203 -13
  49. package/dist/index.cjs +3759 -575
  50. package/dist/index.d.cts +8 -8
  51. package/dist/index.d.ts +8 -8
  52. package/dist/index.js +226 -30
  53. package/dist/markdown.cjs +89 -25
  54. package/dist/markdown.d.cts +57 -3
  55. package/dist/markdown.d.ts +57 -3
  56. package/dist/markdown.js +5 -1
  57. package/dist/mcp.cjs +314 -37
  58. package/dist/mcp.d.cts +3 -2
  59. package/dist/mcp.d.ts +3 -2
  60. package/dist/mcp.js +12 -9
  61. package/dist/messages/en.cjs +40 -0
  62. package/dist/messages/en.js +1 -1
  63. package/dist/messages/ko.cjs +40 -0
  64. package/dist/messages/ko.js +40 -0
  65. package/dist/registry/cms-audit.json +1 -1
  66. package/dist/registry/cms-doc-editor.json +15 -4
  67. package/dist/registry/cms-doc-list.json +2 -1
  68. package/dist/registry/cms-files.json +29 -0
  69. package/dist/registry/cms-lib.json +3 -3
  70. package/dist/registry/cms-media-picker.json +29 -0
  71. package/dist/registry/cms-media.json +28 -0
  72. package/dist/registry/cms-preview-comments.json +24 -0
  73. package/dist/registry/cms-releases.json +28 -0
  74. package/dist/registry/cms-shell.json +2 -2
  75. package/dist/registry/cms-trash.json +24 -0
  76. package/dist/registry/cms-versions.json +2 -1
  77. package/dist/registry/registry.json +163 -3
  78. package/dist/storage-s3.cjs +168 -0
  79. package/dist/storage-s3.d.cts +53 -0
  80. package/dist/storage-s3.d.ts +53 -0
  81. package/dist/storage-s3.js +143 -0
  82. package/dist/storage.cjs +373 -0
  83. package/dist/storage.d.cts +183 -0
  84. package/dist/storage.d.ts +183 -0
  85. package/dist/storage.js +49 -0
  86. package/dist/tables.cjs +251 -3
  87. package/dist/tables.d.cts +4965 -681
  88. package/dist/tables.d.ts +4965 -681
  89. package/dist/tables.js +14 -2
  90. package/dist/tools.cjs +331 -20
  91. package/dist/tools.d.cts +54 -7
  92. package/dist/tools.d.ts +54 -7
  93. package/dist/tools.js +16 -7
  94. package/dist/types.cjs +99 -1
  95. package/dist/types.d.cts +205 -5
  96. package/dist/types.d.ts +205 -5
  97. package/dist/types.js +5 -3
  98. package/package.json +32 -22
  99. package/dist/ai.cjs +0 -555
  100. package/dist/ai.d.cts +0 -48
  101. package/dist/ai.d.ts +0 -48
  102. package/dist/ai.js +0 -73
  103. package/dist/chunk-52NUUZC7.js +0 -1446
  104. package/dist/chunk-IGL2V6US.js +0 -324
  105. package/dist/chunk-QQV6VLYJ.js +0 -204
  106. package/dist/cms-BPp01z-8.d.ts +0 -411
  107. package/dist/cms-D6D89-qZ.d.cts +0 -411
  108. package/dist/drizzle-repo-B1rt7r4j.d.ts +0 -90
  109. package/dist/drizzle-repo-Cn-kL2FK.d.cts +0 -90
  110. package/dist/repo-BWI2Pkrv.d.ts +0 -162
  111. package/dist/repo-CeDxUxO6.d.cts +0 -162
@@ -0,0 +1,1537 @@
1
+ import { StorageAdapter } from './storage.js';
2
+ import { CmsDoc, DocStatus, CmsVersion, ReviewMark, KeyScope, CmsKey, AuditEntry, CmsAsset, AssetKind, AssetRef, CmsComment, CmsRelease, SavedFilter, Presence, Actor, AuditAction, DocContent, ReleaseItem, CollectionConfig, SearchMissEvent, DocSummary, DocCounts, VersionSummary, Via } from './types.js';
3
+ import { z, ZodTypeAny } from 'zod';
4
+ import { Block, TocItem } from './markdown.js';
5
+ import { FieldChange, Hunk } from './diff.js';
6
+ import { CmsErrorCode, ErrorParams, CmsErrorOptions, Diagnostic, Messages } from './errors.js';
7
+
8
+ type ResolveHost = (host: string) => Promise<string[]>;
9
+
10
+ /**
11
+ * Storage behind the CMS. `cms.ts` holds every rule (states, access, versions,
12
+ * validation) and talks only to this interface, so the rules are tested
13
+ * against `MemoryRepo` and run in production on `DrizzleRepo`.
14
+ */
15
+
16
+ type DocPatch = Partial<Omit<CmsDoc, "id" | "collection" | "createdAt">>;
17
+ type DocFlow = "deletedAt" | "deletedBy" | "schedule" | "dueAt" | "review";
18
+ type NewDoc = Omit<CmsDoc, "id" | "createdAt" | "updatedAt" | "republishedAt" | "autosave" | "updatedByAgent" | DocFlow> & Partial<Pick<CmsDoc, DocFlow>> & {
19
+ updatedByAgent?: string | null;
20
+ id?: string;
21
+ createdAt?: string;
22
+ updatedAt?: string;
23
+ republishedAt?: string | null;
24
+ autosave?: CmsDoc["autosave"];
25
+ };
26
+ type StoredVersion = Omit<CmsVersion, "published">;
27
+ type NewVersion = Omit<CmsVersion, "id" | "createdAt" | "published" | "reviewed" | "changed" | "authorAgent" | "label" | "pinned" | "approvedBy" | "approvedAt"> & {
28
+ label?: string | null;
29
+ authorAgent?: string | null;
30
+ createdAt?: string;
31
+ changed?: CmsVersion["changed"];
32
+ };
33
+ interface KeyRow extends CmsKey {
34
+ hash: string;
35
+ createdBy: string | null;
36
+ }
37
+ type NewAudit = Omit<AuditEntry, "id" | "actorAgent"> & {
38
+ actorAgent?: string | null;
39
+ };
40
+ interface AuditQuery {
41
+ /** Entries strictly older than this cursor (from the previous page). */
42
+ before?: string | null;
43
+ limit: number;
44
+ action?: string;
45
+ outcome?: AuditEntry["outcome"];
46
+ actorKind?: AuditEntry["actorKind"];
47
+ }
48
+ type NewAsset = Omit<CmsAsset, "createdAt" | "updatedAt" | "deletedAt" | "deletedBy"> & {
49
+ createdAt?: string;
50
+ updatedAt?: string;
51
+ };
52
+ type VersionPatch = Partial<Pick<CmsVersion, "label" | "pinned" | "approvedBy" | "approvedAt">>;
53
+ type NewComment = Omit<CmsComment, "id" | "resolvedAt" | "resolvedBy">;
54
+ type NewRelease = Pick<CmsRelease, "name" | "createdBy" | "createdById" | "createdAt">;
55
+ type ReleasePatch = Partial<Omit<CmsRelease, "id" | "createdAt" | "createdBy" | "createdById">>;
56
+ type NewFilter = Omit<SavedFilter, "id">;
57
+ /** `trashed`: also find rows that are in the trash. */
58
+ interface FindOptions {
59
+ trashed?: boolean;
60
+ }
61
+ interface DocFilter {
62
+ collection?: string;
63
+ statuses?: DocStatus[];
64
+ published?: boolean;
65
+ /** true: only what is in the trash. Default: only what is not. */
66
+ trashed?: boolean;
67
+ /** Only documents whose schedule is due at or before this time. */
68
+ dueBefore?: string;
69
+ }
70
+ type AssetPatch = Partial<Omit<CmsAsset, "id" | "store" | "createdAt">>;
71
+ interface AssetQuery {
72
+ store?: string;
73
+ /** Exactly this folder ("" = top level). */
74
+ folder?: string;
75
+ /** This folder and everything under it. */
76
+ under?: string;
77
+ kinds?: readonly AssetKind[];
78
+ notKinds?: readonly AssetKind[];
79
+ /** Part of the name, the alt text or a tag (case-insensitive). */
80
+ q?: string;
81
+ tag?: string;
82
+ status?: CmsAsset["status"];
83
+ /** Created strictly before this time. */
84
+ createdBefore?: string;
85
+ /** true: only what is in the trash. Default: only what is not. */
86
+ trashed?: boolean;
87
+ /** Entries strictly older than this cursor (`createdAt|id` of the last one). */
88
+ before?: string | null;
89
+ limit?: number;
90
+ }
91
+ interface CmsRepo {
92
+ /** Run `fn` atomically (one DB transaction). */
93
+ tx<T>(fn: (repo: CmsRepo) => Promise<T>): Promise<T>;
94
+ /** Documents in the trash are not found unless `trashed` is set. */
95
+ findDoc(collection: string, slug: string, o?: FindOptions): Promise<CmsDoc | null>;
96
+ findDocById(id: string, o?: FindOptions): Promise<CmsDoc | null>;
97
+ listDocs(filter: DocFilter): Promise<CmsDoc[]>;
98
+ insertDoc(doc: NewDoc): Promise<CmsDoc>;
99
+ /** Returns null when `expectedVersion` is given and the row moved on. */
100
+ updateDoc(id: string, patch: DocPatch, expectedVersion?: number): Promise<CmsDoc | null>;
101
+ deleteDoc(id: string): Promise<void>;
102
+ insertVersion(v: NewVersion): Promise<void>;
103
+ listVersions(documentId: string): Promise<StoredVersion[]>;
104
+ getVersion(documentId: string, version: number): Promise<StoredVersion | null>;
105
+ setVersionReviewed(documentId: string, version: number, reviewed: ReviewMark[]): Promise<void>;
106
+ updateVersion(documentId: string, version: number, patch: VersionPatch): Promise<void>;
107
+ /** Delete all but the newest `keep` versions, never one in `protect` and never a pinned one. */
108
+ pruneVersions(documentId: string, keep: number, protect: number[]): Promise<void>;
109
+ insertKey(k: {
110
+ name: string;
111
+ prefix: string;
112
+ hash: string;
113
+ scopes: KeyScope[];
114
+ collections: string[] | null;
115
+ createdBy: string | null;
116
+ expiresAt: string | null;
117
+ }): Promise<KeyRow>;
118
+ listKeys(): Promise<KeyRow[]>;
119
+ findKeyByHash(hash: string): Promise<KeyRow | null>;
120
+ touchKey(id: string, at: string): Promise<void>;
121
+ revokeKey(id: string, at: string): Promise<boolean>;
122
+ addHits(documentIds: string[], day: string, source: string): Promise<void>;
123
+ /** Hits per document since `sinceDay` (inclusive); only documents of `collection` when given. */
124
+ hitCounts(sinceDay: string, collection?: string): Promise<Map<string, number>>;
125
+ insertAudit(e: NewAudit): Promise<void>;
126
+ /** Newest first. */
127
+ listAudit(q: AuditQuery): Promise<AuditEntry[]>;
128
+ /** Throws when `(store, key)` is taken. */
129
+ insertAsset(a: NewAsset): Promise<CmsAsset>;
130
+ /** Files in the trash are not found unless `trashed` is set. */
131
+ findAsset(id: string, o?: FindOptions): Promise<CmsAsset | null>;
132
+ /** Never returns files in the trash. */
133
+ findAssets(ids: readonly string[]): Promise<CmsAsset[]>;
134
+ findAssetByKey(store: string, key: string): Promise<CmsAsset | null>;
135
+ findAssetsByKeys(store: string, keys: readonly string[]): Promise<CmsAsset[]>;
136
+ /** Newest first. */
137
+ listAssets(q: AssetQuery): Promise<CmsAsset[]>;
138
+ /** Ready files per folder and kind (folder rows included). */
139
+ countAssets(store?: string): Promise<{
140
+ store: string;
141
+ folder: string;
142
+ kind: AssetKind;
143
+ n: number;
144
+ }[]>;
145
+ updateAsset(id: string, patch: AssetPatch): Promise<CmsAsset | null>;
146
+ deleteAsset(id: string): Promise<void>;
147
+ /** Replace what `documentId` uses. Files that do not exist are skipped. */
148
+ setAssetRefs(documentId: string, refs: readonly Omit<AssetRef, "documentId">[]): Promise<void>;
149
+ listAssetRefs(assetId: string): Promise<AssetRef[]>;
150
+ insertComment(c: NewComment): Promise<CmsComment>;
151
+ findComment(id: string): Promise<CmsComment | null>;
152
+ /** Oldest first. */
153
+ listComments(documentId: string): Promise<CmsComment[]>;
154
+ updateComment(id: string, patch: Pick<CmsComment, "resolvedAt" | "resolvedBy">): Promise<CmsComment | null>;
155
+ /** Open (unresolved) top-level comments per document. */
156
+ countComments(documentIds: readonly string[]): Promise<Map<string, number>>;
157
+ insertRelease(r: NewRelease): Promise<CmsRelease>;
158
+ findRelease(id: string): Promise<CmsRelease | null>;
159
+ /** Newest first. */
160
+ listReleases(): Promise<CmsRelease[]>;
161
+ /** With `expectedState`, null when the release is no longer in that state (someone else ran it). */
162
+ updateRelease(id: string, patch: ReleasePatch, expectedState?: CmsRelease["state"]): Promise<CmsRelease | null>;
163
+ deleteRelease(id: string): Promise<void>;
164
+ insertFilter(f: NewFilter): Promise<SavedFilter>;
165
+ findFilter(id: string): Promise<SavedFilter | null>;
166
+ listFilters(collection: string): Promise<SavedFilter[]>;
167
+ deleteFilter(id: string): Promise<void>;
168
+ /** Insert or refresh one person's row for a document. */
169
+ touchPresence(p: Presence): Promise<void>;
170
+ /** Rows seen at or after `since`, for these documents (all when omitted). */
171
+ listPresence(since: string, documentIds?: readonly string[]): Promise<Presence[]>;
172
+ dropPresence(documentId: string, actorId: string): Promise<void>;
173
+ /** Remove rows last seen before `before`. */
174
+ prunePresence(before: string): Promise<void>;
175
+ /** Changes whenever any document changes (for cross-process index refresh). */
176
+ changeStamp(): Promise<string>;
177
+ getMeta(key: string): Promise<unknown>;
178
+ setMeta(key: string, value: unknown): Promise<void>;
179
+ }
180
+ /** In-memory repo for tests and examples. Starts at the current schema version. */
181
+ declare class MemoryRepo implements CmsRepo {
182
+ docs: Map<string, CmsDoc>;
183
+ versions: StoredVersion[];
184
+ keys: KeyRow[];
185
+ hits: Map<string, number>;
186
+ audit: AuditEntry[];
187
+ assets: Map<string, CmsAsset>;
188
+ assetRefs: AssetRef[];
189
+ comments: CmsComment[];
190
+ releases: CmsRelease[];
191
+ filters: SavedFilter[];
192
+ presence: Presence[];
193
+ meta: Map<string, unknown>;
194
+ private seq;
195
+ private id;
196
+ tx<T>(fn: (repo: CmsRepo) => Promise<T>): Promise<T>;
197
+ findDoc(collection: string, slug: string, o?: FindOptions): Promise<CmsDoc | null>;
198
+ findDocById(id: string, o?: FindOptions): Promise<CmsDoc | null>;
199
+ listDocs(f: DocFilter): Promise<CmsDoc[]>;
200
+ insertDoc(doc: NewDoc): Promise<CmsDoc>;
201
+ updateDoc(id: string, patch: DocPatch, expectedVersion?: number): Promise<CmsDoc | null>;
202
+ deleteDoc(id: string): Promise<void>;
203
+ insertVersion(v: NewVersion): Promise<void>;
204
+ listVersions(documentId: string): Promise<StoredVersion[]>;
205
+ getVersion(documentId: string, version: number): Promise<StoredVersion | null>;
206
+ setVersionReviewed(documentId: string, version: number, reviewed: ReviewMark[]): Promise<void>;
207
+ updateVersion(documentId: string, version: number, patch: VersionPatch): Promise<void>;
208
+ pruneVersions(documentId: string, keep: number, protect: number[]): Promise<void>;
209
+ insertKey(k: {
210
+ name: string;
211
+ prefix: string;
212
+ hash: string;
213
+ scopes: KeyScope[];
214
+ collections: string[] | null;
215
+ createdBy: string | null;
216
+ expiresAt: string | null;
217
+ }): Promise<{
218
+ hash: string;
219
+ createdBy: string | null;
220
+ id: string;
221
+ name: string;
222
+ prefix: string;
223
+ scopes: KeyScope[];
224
+ collections: string[] | null;
225
+ lastUsedAt: string | null;
226
+ revokedAt: string | null;
227
+ expiresAt: string | null;
228
+ createdAt: string;
229
+ }>;
230
+ listKeys(): Promise<{
231
+ hash: string;
232
+ createdBy: string | null;
233
+ id: string;
234
+ name: string;
235
+ prefix: string;
236
+ scopes: KeyScope[];
237
+ collections: string[] | null;
238
+ lastUsedAt: string | null;
239
+ revokedAt: string | null;
240
+ expiresAt: string | null;
241
+ createdAt: string;
242
+ }[]>;
243
+ findKeyByHash(hash: string): Promise<{
244
+ hash: string;
245
+ createdBy: string | null;
246
+ id: string;
247
+ name: string;
248
+ prefix: string;
249
+ scopes: KeyScope[];
250
+ collections: string[] | null;
251
+ lastUsedAt: string | null;
252
+ revokedAt: string | null;
253
+ expiresAt: string | null;
254
+ createdAt: string;
255
+ } | null>;
256
+ touchKey(id: string, at: string): Promise<void>;
257
+ revokeKey(id: string, at: string): Promise<boolean>;
258
+ addHits(ids: string[], day: string, source: string): Promise<void>;
259
+ hitCounts(sinceDay: string, collection?: string): Promise<Map<string, number>>;
260
+ insertAudit(e: NewAudit): Promise<void>;
261
+ listAudit(q: AuditQuery): Promise<AuditEntry[]>;
262
+ insertAsset(a: NewAsset): Promise<CmsAsset>;
263
+ findAsset(id: string, o?: FindOptions): Promise<CmsAsset | null>;
264
+ findAssets(ids: readonly string[]): Promise<CmsAsset[]>;
265
+ findAssetByKey(store: string, key: string): Promise<CmsAsset | null>;
266
+ findAssetsByKeys(store: string, keys: readonly string[]): Promise<CmsAsset[]>;
267
+ listAssets(q: AssetQuery): Promise<CmsAsset[]>;
268
+ countAssets(store?: string): Promise<{
269
+ store: string;
270
+ folder: string;
271
+ kind: AssetKind;
272
+ n: number;
273
+ }[]>;
274
+ updateAsset(id: string, patch: AssetPatch): Promise<CmsAsset | null>;
275
+ deleteAsset(id: string): Promise<void>;
276
+ setAssetRefs(documentId: string, refs: readonly Omit<AssetRef, "documentId">[]): Promise<void>;
277
+ listAssetRefs(assetId: string): Promise<{
278
+ assetId: string;
279
+ documentId: string;
280
+ inDraft: boolean;
281
+ inPublished: boolean;
282
+ }[]>;
283
+ insertComment(c: NewComment): Promise<CmsComment>;
284
+ findComment(id: string): Promise<CmsComment | null>;
285
+ listComments(documentId: string): Promise<CmsComment[]>;
286
+ updateComment(id: string, patch: Pick<CmsComment, "resolvedAt" | "resolvedBy">): Promise<CmsComment | null>;
287
+ countComments(documentIds: readonly string[]): Promise<Map<string, number>>;
288
+ insertRelease(r: NewRelease): Promise<CmsRelease>;
289
+ findRelease(id: string): Promise<CmsRelease | null>;
290
+ listReleases(): Promise<CmsRelease[]>;
291
+ updateRelease(id: string, patch: ReleasePatch, expectedState?: CmsRelease["state"]): Promise<CmsRelease | null>;
292
+ deleteRelease(id: string): Promise<void>;
293
+ insertFilter(f: NewFilter): Promise<SavedFilter>;
294
+ findFilter(id: string): Promise<SavedFilter | null>;
295
+ listFilters(collection: string): Promise<SavedFilter[]>;
296
+ deleteFilter(id: string): Promise<void>;
297
+ touchPresence(p: Presence): Promise<void>;
298
+ listPresence(since: string, documentIds?: readonly string[]): Promise<Presence[]>;
299
+ dropPresence(documentId: string, actorId: string): Promise<void>;
300
+ prunePresence(before: string): Promise<void>;
301
+ changeStamp(): Promise<string>;
302
+ getMeta(key: string): Promise<{} | null>;
303
+ setMeta(key: string, value: unknown): Promise<void>;
304
+ }
305
+
306
+ /**
307
+ * The media library: files in a storage, a row per file, and the rules about
308
+ * who may do what. `createCms({ media })` turns it on; `cms.assets` is this.
309
+ *
310
+ * Bytes never pass through here on the normal path: the browser asks for a
311
+ * signed address (`requestUpload`), sends the file to the storage itself, and
312
+ * says when it is done (`completeUpload`), at which point the server checks
313
+ * what actually arrived.
314
+ */
315
+
316
+ interface MediaStoreConfig {
317
+ /** Name shown in the admin. Default: the store's key. */
318
+ label?: string;
319
+ /** `public`: anyone with the address can read. `private`: opened through the CMS after a permission check. */
320
+ visibility: "public" | "private";
321
+ adapter: StorageAdapter;
322
+ /** Replace the default rule for one action. Default: see `canAsset`. */
323
+ access?: Partial<Record<"read" | "write" | "delete" | "browse", (a: {
324
+ actor: Actor;
325
+ store: string;
326
+ }) => boolean>>;
327
+ /** File types this store takes (replaces `media.accept` for this store). */
328
+ accept?: readonly string[];
329
+ /** Largest file in bytes (replaces `media.maxFileSize` for this store). */
330
+ maxFileSize?: number;
331
+ }
332
+ interface ScanFile {
333
+ store: string;
334
+ key: string;
335
+ name: string;
336
+ mime: string;
337
+ size: number;
338
+ url: string | null;
339
+ bytes?: Uint8Array;
340
+ }
341
+ interface MediaOptions {
342
+ /** The first one is the default store. */
343
+ stores: Record<string, MediaStoreConfig>;
344
+ /** File types every store takes unless it says otherwise. Default `DEFAULT_ACCEPT`. */
345
+ accept?: readonly string[];
346
+ /** Largest file in bytes. Default 5GB. */
347
+ maxFileSize?: number;
348
+ /** Turn an image address into a resized one (your CDN, an image proxy, `/_next/image`). */
349
+ imageUrl?: (o: {
350
+ url: string;
351
+ width: number;
352
+ asset: AssetInfo;
353
+ }) => string;
354
+ /** How long a link to a private file works, in seconds. Default 300. */
355
+ linkTtlSeconds?: number;
356
+ /** Largest file an agent may import by URL, in bytes. Default 50MB. */
357
+ importMaxBytes?: number;
358
+ /**
359
+ * Your own check of every file that arrives (a virus scanner, a content
360
+ * policy). Called once when an upload completes, a file is imported or
361
+ * stored by the server, or a file already in the bucket is registered.
362
+ * `url` is a signed address that works for 10 minutes (null when the file
363
+ * is not stored yet; then `bytes` is set). Return `false` or
364
+ * `{ ok: false, reason }` to refuse; throwing refuses too. A refused file
365
+ * is deleted (a registered one is left alone) and the caller gets
366
+ * `asset_rejected`.
367
+ */
368
+ scan?: (file: ScanFile) => boolean | void | {
369
+ ok: boolean;
370
+ reason?: string;
371
+ } | Promise<boolean | void | {
372
+ ok: boolean;
373
+ reason?: string;
374
+ }>;
375
+ /** Where the CMS route serves files. Default `/api/cms/files`. */
376
+ filesUrl?: string;
377
+ /** For tests and unusual networks: how `import` fetches and resolves host names. */
378
+ fetch?: typeof fetch;
379
+ resolveHost?: ResolveHost;
380
+ }
381
+ /** A file as callers see it: the row plus where to get it. */
382
+ interface AssetView extends CmsAsset {
383
+ visibility: "public" | "private";
384
+ /** Address through the CMS route (permission-checked, works for both kinds of store). */
385
+ href: string;
386
+ /** Direct address when the store is public and has one. */
387
+ publicUrl: string | null;
388
+ thumbHref: string | null;
389
+ }
390
+ /** What a page needs to show a file (`cms.assetsFor(doc)`). */
391
+ interface AssetInfo {
392
+ id: string;
393
+ name: string;
394
+ kind: AssetKind;
395
+ mime: string;
396
+ size: number;
397
+ width: number | null;
398
+ height: number | null;
399
+ duration: number | null;
400
+ alt: string;
401
+ url: string;
402
+ visibility: "public" | "private";
403
+ }
404
+ interface AssetUsage {
405
+ collection: string;
406
+ slug: string;
407
+ title: string;
408
+ status: CmsDoc["status"];
409
+ inDraft: boolean;
410
+ inPublished: boolean;
411
+ }
412
+ type UploadInstructions = {
413
+ kind: "single";
414
+ url: string;
415
+ headers: Record<string, string>;
416
+ } | {
417
+ kind: "multipart";
418
+ partSize: number;
419
+ partCount: number;
420
+ };
421
+ interface UploadRequest {
422
+ name: string;
423
+ /** What the browser says the file is. The extension decides when it is a known one. */
424
+ mime?: string | null;
425
+ size: number;
426
+ folder?: string | null;
427
+ store?: string | null;
428
+ alt?: string;
429
+ tags?: string[];
430
+ /** Uploading for one field: its `accept` and `maxFileSize` apply too. */
431
+ field?: {
432
+ collection: string;
433
+ path: string;
434
+ } | null;
435
+ }
436
+ interface AssetListOptions {
437
+ store?: string | null;
438
+ /** This folder and everything under it ("" or missing: the whole store). */
439
+ folder?: string | null;
440
+ kinds?: readonly AssetKind[];
441
+ q?: string;
442
+ tag?: string;
443
+ cursor?: string | null;
444
+ limit?: number;
445
+ }
446
+ interface AssetsContext {
447
+ repo: CmsRepo;
448
+ media: MediaOptions | undefined;
449
+ fail: (code: CmsErrorCode, params?: ErrorParams, o?: CmsErrorOptions) => Error;
450
+ diag: (path: string, code: CmsErrorCode, params: ErrorParams, severity: Diagnostic["severity"]) => Diagnostic;
451
+ audit: (actor: Actor, action: AuditAction, o?: {
452
+ outcome?: "ok" | "denied" | "failed";
453
+ detail?: Record<string, unknown>;
454
+ }) => void;
455
+ nowIso: () => string;
456
+ actorRef: (actor: Actor) => {
457
+ kind: "user" | "key" | "system";
458
+ id: string | null;
459
+ label: string;
460
+ agent: string | null;
461
+ };
462
+ collection: (slug: string) => AnyCollection;
463
+ canReadDoc: (actor: Actor, doc: CmsDoc) => boolean;
464
+ warn: (key: string, message: string) => void;
465
+ ready: () => Promise<void> | void;
466
+ /** Days a deleted file stays in the trash (0: deleted at once). */
467
+ trashDays?: number;
468
+ }
469
+ /** A field that holds a media library file: `fields: z.object({ cover: assetId().optional() })` with `admin.fields.cover.widget: "image"`. */
470
+ declare const assetId: () => z.ZodString;
471
+ declare function humanSize(bytes: number): string;
472
+ /** The asset fields of a collection: path, widget and rules (from `admin.fields`). */
473
+ declare function assetFields(cfg: AnyCollection): {
474
+ path: string;
475
+ widget: "image" | "file";
476
+ accept: readonly string[] | null;
477
+ maxFileSize: number | null;
478
+ store: string | null;
479
+ }[];
480
+ declare function createAssets(ctx: AssetsContext): {
481
+ enabled: boolean;
482
+ stores: () => {
483
+ accept: readonly string[];
484
+ maxFileSize: number;
485
+ /** Name shown in the admin. Default: the store's key. */
486
+ label?: string;
487
+ /** `public`: anyone with the address can read. `private`: opened through the CMS after a permission check. */
488
+ visibility: "public" | "private";
489
+ adapter: StorageAdapter;
490
+ /** Replace the default rule for one action. Default: see `canAsset`. */
491
+ access?: Partial<Record<"read" | "write" | "delete" | "browse", (a: {
492
+ actor: Actor;
493
+ store: string;
494
+ }) => boolean>>;
495
+ name: string;
496
+ }[];
497
+ describe: (actor: Actor) => {
498
+ stores: {
499
+ can: {
500
+ write: boolean;
501
+ delete: boolean;
502
+ browse: boolean;
503
+ };
504
+ accept: readonly string[];
505
+ maxFileSize: number;
506
+ name: string;
507
+ label: string;
508
+ visibility: "public" | "private";
509
+ }[];
510
+ partSize: number;
511
+ } | null;
512
+ can: (actor: Actor, store: string, what: "read" | "write" | "delete") => boolean;
513
+ requestUpload: (actor: Actor, input: UploadRequest) => Promise<{
514
+ asset: AssetView;
515
+ upload: UploadInstructions;
516
+ }>;
517
+ partUrls: (actor: Actor, id: string, parts: readonly number[]) => Promise<{
518
+ partNumber: number;
519
+ url: string;
520
+ }[]>;
521
+ uploadStatus: (actor: Actor, id: string) => Promise<{
522
+ asset: AssetView;
523
+ partSize: number;
524
+ partCount: number;
525
+ done: number[];
526
+ }>;
527
+ completeUpload: (actor: Actor, id: string, meta?: {
528
+ width?: number | null;
529
+ height?: number | null;
530
+ duration?: number | null;
531
+ }) => Promise<AssetView>;
532
+ abortUpload: (actor: Actor, id: string) => Promise<void>;
533
+ setThumb: (actor: Actor, id: string, bytes: Uint8Array) => Promise<AssetView>;
534
+ put: (actor: Actor, input: Omit<UploadRequest, "size"> & {
535
+ bytes: Uint8Array;
536
+ width?: number | null;
537
+ height?: number | null;
538
+ duration?: number | null;
539
+ }) => Promise<AssetView>;
540
+ import: (actor: Actor, input: {
541
+ url: string;
542
+ name?: string | null;
543
+ folder?: string | null;
544
+ store?: string | null;
545
+ alt?: string;
546
+ tags?: string[];
547
+ }) => Promise<AssetView>;
548
+ list: (actor: Actor, o?: AssetListOptions) => Promise<{
549
+ assets: AssetView[];
550
+ cursor: string | null;
551
+ counts: Record<"all" | "image" | "video" | "audio" | "document" | "other", number>;
552
+ }>;
553
+ folders: (actor: Actor) => Promise<{
554
+ store: string;
555
+ label: string;
556
+ visibility: "public" | "private";
557
+ total: number;
558
+ folders: {
559
+ path: string;
560
+ count: number;
561
+ }[];
562
+ }[]>;
563
+ createFolder: (actor: Actor, input: {
564
+ store?: string | null;
565
+ path: string;
566
+ }) => Promise<{
567
+ store: string;
568
+ path: string;
569
+ }>;
570
+ deleteFolder: (actor: Actor, input: {
571
+ store?: string | null;
572
+ path: string;
573
+ }) => Promise<void>;
574
+ get: (actor: Actor, id: string) => Promise<AssetView & {
575
+ usage: AssetUsage[];
576
+ usageHidden: number;
577
+ }>;
578
+ update: (actor: Actor, id: string, patch: {
579
+ alt?: string;
580
+ tags?: string[];
581
+ }) => Promise<AssetView>;
582
+ move: (actor: Actor, id: string, to: {
583
+ folder?: string | null;
584
+ name?: string | null;
585
+ }) => Promise<AssetView>;
586
+ remove: (actor: Actor, id: string, o?: {
587
+ confirm?: boolean;
588
+ }) => Promise<void>;
589
+ trashed: (actor: Actor) => Promise<CmsAsset[]>;
590
+ untrash: (actor: Actor, id: string) => Promise<AssetView>;
591
+ purge: (actor: Actor, id: string) => Promise<boolean>;
592
+ purgeOlder: (cutoff: string) => Promise<number>;
593
+ open: (actor: Actor, id: string, o?: {
594
+ thumb?: boolean;
595
+ download?: boolean;
596
+ }) => Promise<{
597
+ url: string;
598
+ visibility: "public" | "private";
599
+ ttl: number;
600
+ }>;
601
+ cleanup: (o?: {
602
+ olderThanMs?: number;
603
+ }) => Promise<{
604
+ removed: number;
605
+ }>;
606
+ browse: (actor: Actor, input?: {
607
+ store?: string | null;
608
+ prefix?: string | null;
609
+ q?: string | null;
610
+ cursor?: string | null;
611
+ limit?: number;
612
+ }) => Promise<{
613
+ store: string;
614
+ prefix: string;
615
+ folders: {
616
+ path: string;
617
+ name: string;
618
+ }[];
619
+ files: {
620
+ key: string;
621
+ name: string;
622
+ size: number;
623
+ mime: string;
624
+ kind: "image" | "video" | "audio" | "document" | "other" | "folder";
625
+ updatedAt: string | null;
626
+ asset: AssetView | null;
627
+ }[];
628
+ cursor: string | null;
629
+ }>;
630
+ register: (actor: Actor, input: {
631
+ store?: string | null;
632
+ key: string;
633
+ alt?: string;
634
+ tags?: string[];
635
+ }) => Promise<AssetView>;
636
+ moveMany: (actor: Actor, input: {
637
+ store?: string | null;
638
+ keys?: readonly string[];
639
+ folders?: readonly string[];
640
+ to: string | null;
641
+ }) => Promise<{
642
+ moved: number;
643
+ failed: {
644
+ key: string;
645
+ message: string;
646
+ }[];
647
+ }>;
648
+ removeMany: (actor: Actor, input: {
649
+ store?: string | null;
650
+ keys?: readonly string[];
651
+ folders?: readonly string[];
652
+ confirm?: boolean;
653
+ check?: boolean;
654
+ }) => Promise<{
655
+ deleted: number;
656
+ files: number;
657
+ used: number;
658
+ documents: AssetUsage[];
659
+ hidden: number;
660
+ }>;
661
+ share: (actor: Actor, id: string, o?: {
662
+ ttl?: "1h" | "24h" | "7d";
663
+ }) => Promise<{
664
+ url: string;
665
+ expiresAt: string | null;
666
+ }>;
667
+ openKey: (actor: Actor, input: {
668
+ store?: string | null;
669
+ key: string;
670
+ download?: boolean;
671
+ }) => Promise<{
672
+ url: string;
673
+ visibility: "public" | "private";
674
+ }>;
675
+ sync: (input?: {
676
+ store?: string | null;
677
+ prefix?: string | null;
678
+ }) => Promise<{
679
+ registered: number;
680
+ known: number;
681
+ missing: {
682
+ id: string;
683
+ key: string;
684
+ }[];
685
+ }>;
686
+ checkDoc: (cfg: AnyCollection, c: DocContent, known?: ReadonlySet<string>, r?: CmsRepo) => Promise<Diagnostic[]>;
687
+ assertDoc: (cfg: AnyCollection, next: DocContent, prev?: DocContent | null, r?: CmsRepo) => Promise<void>;
688
+ syncRefs: (r: CmsRepo, doc: CmsDoc) => Promise<void>;
689
+ idsIn: (cfg: AnyCollection, c: Pick<DocContent, "body" | "fields">) => Set<string>;
690
+ assetsFor: (doc: Pick<CmsDoc, "collection" | "body" | "fields">) => Promise<Record<string, AssetInfo>>;
691
+ imageUrl: (asset: AssetInfo, o: {
692
+ width: number;
693
+ }) => string;
694
+ };
695
+ type CmsAssets = ReturnType<typeof createAssets>;
696
+
697
+ /**
698
+ * The editing and publishing flow around a document (0.10.0): scheduled
699
+ * publishing, the trash, review requests, comments, releases, version labels,
700
+ * saved filters and who has a document open. `cms.ts` owns the rules of a
701
+ * single document; this file builds on them through `FlowContext`, so both
702
+ * stay readable.
703
+ */
704
+
705
+ interface TrashRef {
706
+ kind: "document" | "asset";
707
+ id: string;
708
+ }
709
+ interface TrashItem extends TrashRef {
710
+ title: string;
711
+ /** Collection label and slug, or store and path. */
712
+ where: string;
713
+ collection: string | null;
714
+ slug: string | null;
715
+ /** What it was before: draft, published, archived; a file's kind for files. */
716
+ state: string;
717
+ deletedAt: string;
718
+ deletedBy: string | null;
719
+ /** When it is deleted for good (null: never, `trash.days` is 0). */
720
+ purgeAt: string | null;
721
+ canRestore: boolean;
722
+ }
723
+ interface CommentThread extends CmsComment {
724
+ /** Where it sits now: on the quoted text, on its section only, or nowhere (both are gone). */
725
+ located: "quote" | "section" | "lost";
726
+ /** 1-based line in the body, null when lost. */
727
+ line: number | null;
728
+ replies: CmsComment[];
729
+ }
730
+ interface ReleaseView extends CmsRelease {
731
+ items: (ReleaseItem & {
732
+ /** The document's latest version, null when it is gone. */
733
+ currentVersion: number | null;
734
+ /** The document changed after it was added. */
735
+ stale: boolean;
736
+ state: string | null;
737
+ canPublish: boolean;
738
+ })[];
739
+ canPublish: boolean;
740
+ }
741
+ interface BlockedItem {
742
+ collection: string;
743
+ slug: string;
744
+ title: string;
745
+ code: string;
746
+ message: string;
747
+ }
748
+ interface ScheduledRun {
749
+ published: string[];
750
+ unpublished: string[];
751
+ failed: {
752
+ collection: string;
753
+ slug: string;
754
+ code: string;
755
+ message: string;
756
+ }[];
757
+ releases: {
758
+ id: string;
759
+ name: string;
760
+ ok: boolean;
761
+ message?: string;
762
+ }[];
763
+ purged: {
764
+ documents: number;
765
+ assets: number;
766
+ };
767
+ }
768
+
769
+ /**
770
+ * Section patches: change one `## ` section of a body without resending the
771
+ * whole document. Anchors are the ones `splitSections()` and the public page
772
+ * use, so an agent can patch the section a search result pointed at.
773
+ */
774
+ type PatchOp =
775
+ /** Replace the text under the section's heading (the heading stays unless `heading` is given). */
776
+ {
777
+ op: "replace";
778
+ anchor: string;
779
+ markdown: string;
780
+ heading?: string;
781
+ }
782
+ /** Insert markdown (usually a new `## ` section) right after / before the section. */
783
+ | {
784
+ op: "insert_after";
785
+ anchor: string;
786
+ markdown: string;
787
+ } | {
788
+ op: "insert_before";
789
+ anchor: string;
790
+ markdown: string;
791
+ }
792
+ /** Remove the section with its heading. */
793
+ | {
794
+ op: "delete";
795
+ anchor: string;
796
+ }
797
+ /** Add markdown at the end of the body. */
798
+ | {
799
+ op: "append";
800
+ markdown: string;
801
+ };
802
+ interface SectionRange {
803
+ /** "" = the text before the first heading. */
804
+ anchor: string;
805
+ heading: string;
806
+ /** Line index of the heading (or 0 for the intro). */
807
+ start: number;
808
+ /** First line after the section (exclusive). */
809
+ end: number;
810
+ /** True when the section has a heading line. */
811
+ hasHeading: boolean;
812
+ }
813
+ /** Where each section is, by line. Same anchors as `splitSections()`. */
814
+ declare function sectionRanges(body: string): SectionRange[];
815
+ /** Apply ops in order. Throws `invalid_anchor` (with the valid anchors) for an unknown section. */
816
+ declare function applyPatch(body: string, ops: PatchOp[]): string;
817
+
818
+ /**
819
+ * In-memory keyword search over published documents, split into sections.
820
+ *
821
+ * Why not Postgres full-text or embeddings: the corpus is small (hundreds of
822
+ * sections), the agent is waiting on it mid-answer, and Korean questions
823
+ * ("슬랙 어떻게 연결해?") rarely share exact words with a title ("Slack
824
+ * 연결하기"). Hangul words are indexed as whole words AND 2-grams, so
825
+ * "연결해" still meets "연결하기"; authors add aliases ("슬랙", "slack") as
826
+ * keywords, which weigh the most. Building the index is a few ms; a query is
827
+ * well under one.
828
+ */
829
+ interface SearchUnit {
830
+ docId: string;
831
+ collection: string;
832
+ slug: string;
833
+ title: string;
834
+ summary: string;
835
+ category: string | null;
836
+ keywords: string[];
837
+ /** Section anchor ("" = intro). */
838
+ anchor: string;
839
+ heading: string;
840
+ markdown: string;
841
+ publishedAt: string | null;
842
+ fields: Record<string, unknown>;
843
+ }
844
+ interface SearchHit {
845
+ unit: SearchUnit;
846
+ score: number;
847
+ /** Share of the query's meaningful words that matched (0–1). */
848
+ coverage: number;
849
+ }
850
+ declare function normalizeQuery(q: string): string;
851
+
852
+ /** Any collection (the default when nothing is known about the set). */
853
+ type AnyCollection = CollectionConfig<ZodTypeAny | undefined, string>;
854
+ declare function defineCollection<const S extends string, F extends ZodTypeAny | undefined = undefined>(c: CollectionConfig<F, S>): CollectionConfig<F, S>;
855
+ /** Collection slugs of a set (a union of literals when the set was declared with `defineCollection`). */
856
+ type CollectionName<C extends readonly AnyCollection[]> = C[number]["slug"];
857
+ /** The parsed `fields` type of collection `N` (zod output), or a plain record. */
858
+ type FieldsOf<C extends readonly AnyCollection[], N extends string> = Extract<C[number], {
859
+ slug: N;
860
+ }> extends CollectionConfig<infer F, string> ? [F] extends [undefined] ? Record<string, unknown> : [ZodTypeAny] extends [F] ? Record<string, unknown> : z.output<NonNullable<F>> : Record<string, unknown>;
861
+ type TypedDoc<F> = Omit<CmsDoc, "fields"> & {
862
+ fields: F;
863
+ };
864
+ declare const SLUG_RE: RegExp;
865
+ declare const LIMITS: {
866
+ readonly slug: 120;
867
+ readonly title: 200;
868
+ readonly summary: 300;
869
+ readonly body: 60000;
870
+ readonly keyword: 40;
871
+ readonly keywords: 30;
872
+ };
873
+ interface DocInput<F = Record<string, unknown>> {
874
+ slug?: string;
875
+ title?: string;
876
+ summary?: string;
877
+ body?: string;
878
+ category?: string | null;
879
+ keywords?: string[];
880
+ /** On update: a JSON Merge Patch (a key set to null is removed). */
881
+ fields?: FieldsPatch<F>;
882
+ }
883
+ /** A merge patch of `F`: every key optional, objects patched recursively, null removes. */
884
+ type FieldsPatch<F> = F extends readonly unknown[] ? F : F extends Record<string, unknown> ? {
885
+ [K in keyof F]?: FieldsPatch<F[K]> | null;
886
+ } : F;
887
+ interface WriteOptions {
888
+ /** Version the caller last read; a mismatch is a 409 (someone else saved). */
889
+ expectedVersion?: number;
890
+ /** Why it changed (shown in the version list). */
891
+ note?: string | null;
892
+ /** Publish right away (needs publish permission). */
893
+ publish?: boolean;
894
+ }
895
+ interface SearchResult {
896
+ hits: SearchHit[];
897
+ /** True when nothing relevant was found. */
898
+ empty: boolean;
899
+ }
900
+ interface SearchOptions {
901
+ limit?: number;
902
+ perDoc?: number;
903
+ /** When nothing is found, tell the app through `onSearchMiss`. */
904
+ reportMiss?: boolean;
905
+ /** @deprecated since 0.6.0: renamed to `reportMiss`. */
906
+ logGap?: boolean;
907
+ filter?: (u: SearchHit["unit"]) => boolean;
908
+ }
909
+ interface CreateCmsOptions<C extends readonly AnyCollection[] = readonly AnyCollection[]> {
910
+ repo: CmsRepo;
911
+ collections: C;
912
+ /** How often to check whether another process changed documents (ms). Default 60s. */
913
+ searchRefreshMs?: number;
914
+ /** Search results below this coverage count as "nothing found". Default 0.5. */
915
+ minCoverage?: number;
916
+ now?: () => Date;
917
+ /** IANA time zone that decides which calendar day a usage hit counts for. Default "UTC". */
918
+ timeZone?: string;
919
+ /** Error messages (default English). `import { ko } from "@mainsoft/agent-cms/messages/ko"`. */
920
+ messages?: Partial<Messages>;
921
+ /**
922
+ * Called (not awaited) when a search flagged with `reportMiss` found
923
+ * nothing. Store it in your own table if you want a "questions nobody
924
+ * answered" screen; the CMS keeps nothing. Errors go to `onError`.
925
+ */
926
+ onSearchMiss?: (e: SearchMissEvent) => void | Promise<void>;
927
+ /** Secret for signed draft preview links (32+ characters). Preview links are off without it. */
928
+ previewSecret?: string;
929
+ /** Check `cms_meta.schema_version` before the first call. Default true. */
930
+ schemaCheck?: boolean;
931
+ onError?: (err: unknown, where: string) => void;
932
+ /** Deprecation and setup warnings (default console.warn), each once. */
933
+ warn?: (message: string) => void;
934
+ /**
935
+ * The media library: where files are stored and what may be uploaded.
936
+ * Without it documents hold text only. See `./storage-s3` for S3-compatible
937
+ * storage.
938
+ */
939
+ media?: MediaOptions;
940
+ /**
941
+ * Days a deleted document or file stays in the trash before it is deleted
942
+ * for good. Default 30. `{ days: 0 }`: no trash, a delete is final.
943
+ */
944
+ trash?: {
945
+ days?: number;
946
+ };
947
+ /**
948
+ * Secret for the `/_cron` route (`Authorization: Bearer <secret>`), which
949
+ * runs scheduled publishes and empties the trash. The route is off without it.
950
+ */
951
+ cronSecret?: string;
952
+ }
953
+ /** Second argument of `afterChange` hooks and `onChange` listeners. */
954
+ interface ChangeInfo {
955
+ /**
956
+ * True when what the public sees changed (published content, publish,
957
+ * unpublish, archive, unarchive, delete). False for draft-only saves.
958
+ */
959
+ contentChanged: boolean;
960
+ }
961
+ /** `YYYY-MM-DD` of `d` in `timeZone`. */
962
+ declare function dayIn(timeZone: string, d: Date): string;
963
+ interface ListOptions {
964
+ drafts?: boolean;
965
+ status?: DocStatus;
966
+ /** Display state (editors): draft, published (incl. modified), modified, archived, scheduled, review (waiting for one). */
967
+ state?: "draft" | "published" | "modified" | "archived" | "scheduled" | "review";
968
+ category?: string;
969
+ /** Title, slug or summary contains (case-insensitive). */
970
+ q?: string;
971
+ /** Last writer kind (editors). */
972
+ by?: "user" | "key" | "system";
973
+ }
974
+ /** RFC 7396 JSON Merge Patch: objects merge, null removes a key, anything else replaces. */
975
+ declare function mergePatch(target: unknown, patch: unknown): unknown;
976
+ declare const PREVIEW_TTLS: {
977
+ readonly "1h": 3600000;
978
+ readonly "24h": 86400000;
979
+ readonly "7d": number;
980
+ };
981
+ type PreviewTtl = keyof typeof PREVIEW_TTLS;
982
+ declare const BULK_ACTIONS: readonly ["publish", "unpublish", "archive", "unarchive", "delete"];
983
+ type BulkAction = (typeof BULK_ACTIONS)[number];
984
+ interface BulkResult {
985
+ slug: string;
986
+ ok: boolean;
987
+ error?: {
988
+ code: CmsErrorCode;
989
+ message: string;
990
+ };
991
+ }
992
+ /** An agent's change still waiting for a person (`cms.agentChanges`). */
993
+ interface AgentChange {
994
+ /** Hunk id; pass it to `reviewChanges`. */
995
+ id: string;
996
+ version: number;
997
+ /** The agent's name (a key's name, the app's label, or the agent acting for a person). */
998
+ author: string;
999
+ /** `user` only when an agent acted for a person; `behalf` then names that person. */
1000
+ authorKind: "key" | "system" | "user";
1001
+ behalf: string | null;
1002
+ at: string;
1003
+ removed: string[];
1004
+ added: string[];
1005
+ /** Line just before the change in that version (to put removed lines back). */
1006
+ before: string | null;
1007
+ }
1008
+ interface PreviewLink {
1009
+ url: string;
1010
+ token: string;
1011
+ version: number;
1012
+ expiresAt: string;
1013
+ }
1014
+ interface PreviewRead {
1015
+ collection: string;
1016
+ slug: string;
1017
+ version: number;
1018
+ expiresAt: string;
1019
+ doc: DocContent;
1020
+ /** The link lets its holder read and write comments. */
1021
+ comments: boolean;
1022
+ }
1023
+ interface DocDiff {
1024
+ a: number;
1025
+ b: number;
1026
+ fields: FieldChange[];
1027
+ hunks: Hunk[];
1028
+ }
1029
+ /** The untyped CMS (what the transports use). `createCms` returns it with typed overloads on top. */
1030
+ declare function createCmsCore(opts: CreateCmsOptions): {
1031
+ collections: () => AnyCollection[];
1032
+ collection: (slug: string) => AnyCollection;
1033
+ can: (actor: Actor, col: string, what: "read" | "write" | "publish", doc?: CmsDoc | null) => boolean;
1034
+ isAdmin: (actor: Actor) => boolean;
1035
+ get: (actor: Actor, col: string, slug: string, o?: {
1036
+ draft?: boolean;
1037
+ }) => Promise<CmsDoc>;
1038
+ list: (actor: Actor, col: string, o?: ListOptions) => Promise<CmsDoc[]>;
1039
+ page: (actor: Actor, col: string, o?: ListOptions & {
1040
+ limit?: number;
1041
+ cursor?: string | null;
1042
+ hits?: boolean;
1043
+ }) => Promise<{
1044
+ docs: DocSummary[];
1045
+ total: number;
1046
+ nextCursor: string | null;
1047
+ }>;
1048
+ counts: (actor: Actor, col: string) => Promise<DocCounts>;
1049
+ versions: (actor: Actor, col: string, slug: string) => Promise<CmsVersion[]>;
1050
+ versionList: (actor: Actor, col: string, slug: string) => Promise<VersionSummary[]>;
1051
+ version: (actor: Actor, col: string, slug: string, n: number) => Promise<CmsVersion>;
1052
+ diff: (actor: Actor, col: string, slug: string, a: number, b: number, o?: {
1053
+ context?: number;
1054
+ }) => Promise<DocDiff>;
1055
+ diagnose: (actor: Actor, col: string, input: DocInput, o?: {
1056
+ slug?: string;
1057
+ }) => Promise<Diagnostic[]>;
1058
+ create: (actor: Actor, col: string, input: DocInput, o?: WriteOptions) => Promise<CmsDoc>;
1059
+ update: (actor: Actor, col: string, slug: string, input: DocInput, o?: WriteOptions) => Promise<CmsDoc>;
1060
+ patch: (actor: Actor, col: string, slug: string, ops: PatchOp[], o?: WriteOptions & {
1061
+ dryRun?: boolean;
1062
+ }) => Promise<{
1063
+ doc: CmsDoc | null;
1064
+ diff: string;
1065
+ diagnostics: Diagnostic[];
1066
+ saved: boolean;
1067
+ }>;
1068
+ sections: (actor: Actor, col: string, slug: string) => Promise<{
1069
+ anchor: string;
1070
+ heading: string;
1071
+ }[]>;
1072
+ autosave: (actor: Actor, col: string, slug: string, input: DocInput, baseVersion: number) => Promise<{
1073
+ content: DocContent;
1074
+ at: string;
1075
+ by: string;
1076
+ baseVersion: number;
1077
+ }>;
1078
+ discardAutosave: (actor: Actor, col: string, slug: string) => Promise<void>;
1079
+ publish: (actor: Actor, col: string, slug: string, o?: {
1080
+ version?: number;
1081
+ expectedVersion?: number;
1082
+ }) => Promise<CmsDoc>;
1083
+ archive: (actor: Actor, col: string, slug: string, o?: {
1084
+ expectedVersion?: number;
1085
+ }) => Promise<CmsDoc>;
1086
+ unarchive: (actor: Actor, col: string, slug: string, o?: {
1087
+ expectedVersion?: number;
1088
+ }) => Promise<CmsDoc>;
1089
+ unpublish: (actor: Actor, col: string, slug: string, o?: {
1090
+ expectedVersion?: number;
1091
+ }) => Promise<CmsDoc>;
1092
+ restore: (actor: Actor, col: string, slug: string, n: number, o?: WriteOptions) => Promise<CmsDoc>;
1093
+ remove: (actor: Actor, col: string, slug: string, o?: {
1094
+ expectedVersion?: number;
1095
+ }) => Promise<void>;
1096
+ bulk: (actor: Actor, col: string, action: BulkAction, items: {
1097
+ slug: string;
1098
+ expectedVersion?: number;
1099
+ }[]) => Promise<BulkResult[]>;
1100
+ agentChanges: (actor: Actor, col: string, slug: string) => Promise<AgentChange[]>;
1101
+ reviewChanges: (actor: Actor, col: string, slug: string, o: {
1102
+ hunks: string[] | "all";
1103
+ action?: ReviewMark["action"];
1104
+ }) => Promise<{
1105
+ reviewed: number;
1106
+ }>;
1107
+ createPreviewLink: (actor: Actor, col: string, slug: string, o?: {
1108
+ ttl?: PreviewTtl;
1109
+ comments?: boolean;
1110
+ }) => Promise<PreviewLink>;
1111
+ readPreview: (token: string) => Promise<PreviewRead>;
1112
+ previewEnabled: () => boolean;
1113
+ /** The zone days and schedules are shown in (`createCms({ timeZone })`, default UTC). */
1114
+ timeZone: string;
1115
+ search: (actor: Actor, cols: string[], query: string, o?: SearchOptions) => Promise<SearchResult>;
1116
+ recordHits: (docIds: string[], source?: Via) => Promise<void>;
1117
+ hitCounts: (actor: Actor, col: string, days?: number) => Promise<Map<string, number>>;
1118
+ createKey: (actor: Actor, input: {
1119
+ name: string;
1120
+ scopes: KeyScope[];
1121
+ collections?: string[] | null;
1122
+ expiresAt?: string | null;
1123
+ }) => Promise<{
1124
+ key: CmsKey;
1125
+ secret: string;
1126
+ }>;
1127
+ listKeys: (actor: Actor) => Promise<CmsKey[]>;
1128
+ revokeKey: (actor: Actor, id: string) => Promise<void>;
1129
+ authenticateKey: (raw: string) => Promise<Extract<Actor, {
1130
+ kind: "key";
1131
+ }> | null>;
1132
+ audit: (actor: Actor, o?: {
1133
+ cursor?: string | null;
1134
+ limit?: number;
1135
+ action?: string;
1136
+ outcome?: AuditEntry["outcome"];
1137
+ actorKind?: AuditEntry["actorKind"];
1138
+ }) => Promise<{
1139
+ entries: AuditEntry[];
1140
+ nextCursor: string | null;
1141
+ }>;
1142
+ preview: (actor: Actor, col: string, input: DocInput, o?: {
1143
+ slug?: string;
1144
+ }) => Promise<{
1145
+ blocks: Block[];
1146
+ toc: TocItem[];
1147
+ diagnostics: Diagnostic[];
1148
+ diff: string | null;
1149
+ publicUrl: string | null;
1150
+ assets: Record<string, AssetInfo>;
1151
+ }>;
1152
+ needsReview: (actor: Actor, col: string) => boolean;
1153
+ /** Publish (and/or unpublish) at a time; what goes out is the version that is current now. */
1154
+ schedule: (actor: Actor, col: string, slug: string, o: {
1155
+ publishAt?: string | null;
1156
+ unpublishAt?: string | null;
1157
+ expectedVersion?: number;
1158
+ }) => Promise<CmsDoc>;
1159
+ unschedule: (actor: Actor, col: string, slug: string) => Promise<CmsDoc>;
1160
+ /** Run everything whose time has come (the `/_cron` route calls this). */
1161
+ runScheduled: (o?: {
1162
+ now?: Date;
1163
+ }) => Promise<ScheduledRun>;
1164
+ cronSecret: string | null;
1165
+ /** Deleted documents and files: `list`, `restore`, `purge`. */
1166
+ trash: {
1167
+ days: number;
1168
+ list: (actor: Actor, o?: {
1169
+ kind?: TrashRef["kind"];
1170
+ }) => Promise<{
1171
+ items: TrashItem[];
1172
+ days: number;
1173
+ canPurge: boolean;
1174
+ }>;
1175
+ restore: (actor: Actor, items: readonly TrashRef[]) => Promise<{
1176
+ restored: number;
1177
+ }>;
1178
+ purge: (actor: Actor, items: readonly TrashRef[] | "all") => Promise<{
1179
+ purged: number;
1180
+ }>;
1181
+ };
1182
+ requestReview: (actor: Actor, col: string, slug: string, o?: {
1183
+ note?: string | null;
1184
+ }) => Promise<CmsDoc>;
1185
+ approveReview: (actor: Actor, col: string, slug: string, o?: {
1186
+ publish?: boolean;
1187
+ }) => Promise<CmsDoc>;
1188
+ rejectReview: (actor: Actor, col: string, slug: string, o?: {
1189
+ note?: string | null;
1190
+ }) => Promise<CmsDoc>;
1191
+ reviewRequests: (actor: Actor, o?: {
1192
+ collection?: string;
1193
+ }) => Promise<DocSummary[]>;
1194
+ comments: (actor: Actor, col: string, slug: string) => Promise<CommentThread[]>;
1195
+ addComment: (actor: Actor, col: string, slug: string, input: {
1196
+ body: string;
1197
+ anchor?: string | null;
1198
+ quote?: string | null;
1199
+ threadId?: string | null;
1200
+ }) => Promise<CmsComment>;
1201
+ resolveComment: (actor: Actor, col: string, slug: string, id: string, o?: {
1202
+ resolved?: boolean;
1203
+ }) => Promise<CmsComment>;
1204
+ previewComments: (token: string) => Promise<CommentThread[]>;
1205
+ addPreviewComment: (token: string, input: {
1206
+ name?: string | null;
1207
+ body: string;
1208
+ anchor?: string | null;
1209
+ quote?: string | null;
1210
+ threadId?: string | null;
1211
+ }) => Promise<CmsComment>;
1212
+ labelVersion: (actor: Actor, col: string, slug: string, n: number, o: {
1213
+ label?: string | null;
1214
+ pinned?: boolean;
1215
+ }) => Promise<CmsVersion>;
1216
+ /** Documents that go public together: `list`, `get`, `create`, `add`, `publish`, `schedule`… */
1217
+ releases: {
1218
+ list: (actor: Actor) => Promise<CmsRelease[]>;
1219
+ get: (actor: Actor, id: string) => Promise<ReleaseView>;
1220
+ create: (actor: Actor, input: {
1221
+ name: string;
1222
+ }) => Promise<ReleaseView>;
1223
+ rename: (actor: Actor, id: string, input: {
1224
+ name: string;
1225
+ }) => Promise<ReleaseView>;
1226
+ remove: (actor: Actor, id: string) => Promise<void>;
1227
+ add: (actor: Actor, id: string, input: readonly {
1228
+ collection: string;
1229
+ slug: string;
1230
+ action?: ReleaseItem["action"];
1231
+ }[]) => Promise<ReleaseView>;
1232
+ removeItem: (actor: Actor, id: string, documentId: string) => Promise<ReleaseView>;
1233
+ publish: (actor: Actor, id: string) => Promise<CmsRelease>;
1234
+ schedule: (actor: Actor, id: string, o: {
1235
+ publishAt: string | null;
1236
+ }) => Promise<ReleaseView>;
1237
+ of: (documentId: string) => Promise<{
1238
+ id: string;
1239
+ name: string;
1240
+ state: CmsRelease["state"];
1241
+ publishAt: string | null;
1242
+ } | null>;
1243
+ };
1244
+ /** Named list filters: `list`, `save`, `remove`. */
1245
+ filters: {
1246
+ list: (actor: Actor, col: string) => Promise<(SavedFilter & {
1247
+ mine: boolean;
1248
+ })[]>;
1249
+ save: (actor: Actor, col: string, input: {
1250
+ name: string;
1251
+ query: Record<string, unknown>;
1252
+ shared?: boolean;
1253
+ }) => Promise<SavedFilter>;
1254
+ remove: (actor: Actor, id: string) => Promise<void>;
1255
+ };
1256
+ /** Who has a document open: `touch`, `leave`, `in`. */
1257
+ presence: {
1258
+ touch: (actor: Actor, col: string, slug: string, o?: {
1259
+ cursor?: unknown;
1260
+ selection?: unknown;
1261
+ }) => Promise<{
1262
+ version: number;
1263
+ updatedBy: string | null;
1264
+ others: Presence[];
1265
+ }>;
1266
+ leave: (actor: Actor, col: string, slug: string) => Promise<void>;
1267
+ in: (actor: Actor, col: string) => Promise<{
1268
+ slug: string;
1269
+ people: Presence[];
1270
+ }[]>;
1271
+ };
1272
+ /** The media library (`createCms({ media })`). */
1273
+ assets: {
1274
+ enabled: boolean;
1275
+ stores: () => {
1276
+ accept: readonly string[];
1277
+ maxFileSize: number;
1278
+ label?: string;
1279
+ visibility: "public" | "private";
1280
+ adapter: StorageAdapter;
1281
+ access?: Partial<Record<"read" | "write" | "delete" | "browse", (a: {
1282
+ actor: Actor;
1283
+ store: string;
1284
+ }) => boolean>>;
1285
+ name: string;
1286
+ }[];
1287
+ describe: (actor: Actor) => {
1288
+ stores: {
1289
+ can: {
1290
+ write: boolean;
1291
+ delete: boolean;
1292
+ browse: boolean;
1293
+ };
1294
+ accept: readonly string[];
1295
+ maxFileSize: number;
1296
+ name: string;
1297
+ label: string;
1298
+ visibility: "public" | "private";
1299
+ }[];
1300
+ partSize: number;
1301
+ } | null;
1302
+ can: (actor: Actor, store: string, what: "read" | "write" | "delete") => boolean;
1303
+ requestUpload: (actor: Actor, input: UploadRequest) => Promise<{
1304
+ asset: AssetView;
1305
+ upload: UploadInstructions;
1306
+ }>;
1307
+ partUrls: (actor: Actor, id: string, parts: readonly number[]) => Promise<{
1308
+ partNumber: number;
1309
+ url: string;
1310
+ }[]>;
1311
+ uploadStatus: (actor: Actor, id: string) => Promise<{
1312
+ asset: AssetView;
1313
+ partSize: number;
1314
+ partCount: number;
1315
+ done: number[];
1316
+ }>;
1317
+ completeUpload: (actor: Actor, id: string, meta?: {
1318
+ width?: number | null;
1319
+ height?: number | null;
1320
+ duration?: number | null;
1321
+ }) => Promise<AssetView>;
1322
+ abortUpload: (actor: Actor, id: string) => Promise<void>;
1323
+ setThumb: (actor: Actor, id: string, bytes: Uint8Array) => Promise<AssetView>;
1324
+ put: (actor: Actor, input: Omit<UploadRequest, "size"> & {
1325
+ bytes: Uint8Array;
1326
+ width?: number | null;
1327
+ height?: number | null;
1328
+ duration?: number | null;
1329
+ }) => Promise<AssetView>;
1330
+ import: (actor: Actor, input: {
1331
+ url: string;
1332
+ name?: string | null;
1333
+ folder?: string | null;
1334
+ store?: string | null;
1335
+ alt?: string;
1336
+ tags?: string[];
1337
+ }) => Promise<AssetView>;
1338
+ list: (actor: Actor, o?: AssetListOptions) => Promise<{
1339
+ assets: AssetView[];
1340
+ cursor: string | null;
1341
+ counts: Record<"all" | "image" | "video" | "audio" | "document" | "other", number>;
1342
+ }>;
1343
+ folders: (actor: Actor) => Promise<{
1344
+ store: string;
1345
+ label: string;
1346
+ visibility: "public" | "private";
1347
+ total: number;
1348
+ folders: {
1349
+ path: string;
1350
+ count: number;
1351
+ }[];
1352
+ }[]>;
1353
+ createFolder: (actor: Actor, input: {
1354
+ store?: string | null;
1355
+ path: string;
1356
+ }) => Promise<{
1357
+ store: string;
1358
+ path: string;
1359
+ }>;
1360
+ deleteFolder: (actor: Actor, input: {
1361
+ store?: string | null;
1362
+ path: string;
1363
+ }) => Promise<void>;
1364
+ get: (actor: Actor, id: string) => Promise<AssetView & {
1365
+ usage: AssetUsage[];
1366
+ usageHidden: number;
1367
+ }>;
1368
+ update: (actor: Actor, id: string, patch: {
1369
+ alt?: string;
1370
+ tags?: string[];
1371
+ }) => Promise<AssetView>;
1372
+ move: (actor: Actor, id: string, to: {
1373
+ folder?: string | null;
1374
+ name?: string | null;
1375
+ }) => Promise<AssetView>;
1376
+ remove: (actor: Actor, id: string, o?: {
1377
+ confirm?: boolean;
1378
+ }) => Promise<void>;
1379
+ trashed: (actor: Actor) => Promise<CmsAsset[]>;
1380
+ untrash: (actor: Actor, id: string) => Promise<AssetView>;
1381
+ purge: (actor: Actor, id: string) => Promise<boolean>;
1382
+ purgeOlder: (cutoff: string) => Promise<number>;
1383
+ open: (actor: Actor, id: string, o?: {
1384
+ thumb?: boolean;
1385
+ download?: boolean;
1386
+ }) => Promise<{
1387
+ url: string;
1388
+ visibility: "public" | "private";
1389
+ ttl: number;
1390
+ }>;
1391
+ cleanup: (o?: {
1392
+ olderThanMs?: number;
1393
+ }) => Promise<{
1394
+ removed: number;
1395
+ }>;
1396
+ browse: (actor: Actor, input?: {
1397
+ store?: string | null;
1398
+ prefix?: string | null;
1399
+ q?: string | null;
1400
+ cursor?: string | null;
1401
+ limit?: number;
1402
+ }) => Promise<{
1403
+ store: string;
1404
+ prefix: string;
1405
+ folders: {
1406
+ path: string;
1407
+ name: string;
1408
+ }[];
1409
+ files: {
1410
+ key: string;
1411
+ name: string;
1412
+ size: number;
1413
+ mime: string;
1414
+ kind: "image" | "video" | "audio" | "document" | "other" | "folder";
1415
+ updatedAt: string | null;
1416
+ asset: AssetView | null;
1417
+ }[];
1418
+ cursor: string | null;
1419
+ }>;
1420
+ register: (actor: Actor, input: {
1421
+ store?: string | null;
1422
+ key: string;
1423
+ alt?: string;
1424
+ tags?: string[];
1425
+ }) => Promise<AssetView>;
1426
+ moveMany: (actor: Actor, input: {
1427
+ store?: string | null;
1428
+ keys?: readonly string[];
1429
+ folders?: readonly string[];
1430
+ to: string | null;
1431
+ }) => Promise<{
1432
+ moved: number;
1433
+ failed: {
1434
+ key: string;
1435
+ message: string;
1436
+ }[];
1437
+ }>;
1438
+ removeMany: (actor: Actor, input: {
1439
+ store?: string | null;
1440
+ keys?: readonly string[];
1441
+ folders?: readonly string[];
1442
+ confirm?: boolean;
1443
+ check?: boolean;
1444
+ }) => Promise<{
1445
+ deleted: number;
1446
+ files: number;
1447
+ used: number;
1448
+ documents: AssetUsage[];
1449
+ hidden: number;
1450
+ }>;
1451
+ share: (actor: Actor, id: string, o?: {
1452
+ ttl?: "1h" | "24h" | "7d";
1453
+ }) => Promise<{
1454
+ url: string;
1455
+ expiresAt: string | null;
1456
+ }>;
1457
+ openKey: (actor: Actor, input: {
1458
+ store?: string | null;
1459
+ key: string;
1460
+ download?: boolean;
1461
+ }) => Promise<{
1462
+ url: string;
1463
+ visibility: "public" | "private";
1464
+ }>;
1465
+ sync: (input?: {
1466
+ store?: string | null;
1467
+ prefix?: string | null;
1468
+ }) => Promise<{
1469
+ registered: number;
1470
+ known: number;
1471
+ missing: {
1472
+ id: string;
1473
+ key: string;
1474
+ }[];
1475
+ }>;
1476
+ checkDoc: (cfg: AnyCollection, c: DocContent, known?: ReadonlySet<string>, r?: CmsRepo) => Promise<Diagnostic[]>;
1477
+ assertDoc: (cfg: AnyCollection, next: DocContent, prev?: DocContent | null, r?: CmsRepo) => Promise<void>;
1478
+ syncRefs: (r: CmsRepo, doc: CmsDoc) => Promise<void>;
1479
+ idsIn: (cfg: AnyCollection, c: Pick<DocContent, "body" | "fields">) => Set<string>;
1480
+ assetsFor: (doc: Pick<CmsDoc, "collection" | "body" | "fields">) => Promise<Record<string, AssetInfo>>;
1481
+ imageUrl: (asset: AssetInfo, o: {
1482
+ width: number;
1483
+ }) => string;
1484
+ };
1485
+ /** The files a document uses, by id: address, size, alt text. For rendering. */
1486
+ assetsFor: (doc: Pick<CmsDoc, "collection" | "body" | "fields">) => Promise<Record<string, AssetInfo>>;
1487
+ /** An image's address at a width, through `media.imageUrl` when set. */
1488
+ imageUrl: (asset: AssetInfo, o: {
1489
+ width: number;
1490
+ }) => string;
1491
+ message: (e: unknown) => string;
1492
+ messages: Partial<Messages> | undefined;
1493
+ /** Fails with `schema_outdated` when the database needs a migration. */
1494
+ checkSchema: () => Promise<void>;
1495
+ /** Warm the search index (e.g. at boot) so the first agent call is fast. */
1496
+ warm: () => Promise<void>;
1497
+ onChange(fn: (doc: CmsDoc, info: ChangeInfo) => void): () => boolean;
1498
+ repo: CmsRepo;
1499
+ };
1500
+ type CmsCore = ReturnType<typeof createCmsCore>;
1501
+ type Typed = "get" | "list" | "create" | "update" | "publish" | "archive" | "unarchive" | "unpublish" | "restore";
1502
+ /**
1503
+ * The CMS with types from its collections: collection names are checked at
1504
+ * compile time and `fields` is the collection's zod output.
1505
+ */
1506
+ type Cms<C extends readonly AnyCollection[] = readonly AnyCollection[]> = Omit<CmsCore, Typed> & {
1507
+ /** The untyped CMS (what REST, MCP and the tools use). */
1508
+ readonly core: CmsCore;
1509
+ get<N extends CollectionName<C>>(actor: Actor, col: N, slug: string, o?: {
1510
+ draft?: boolean;
1511
+ }): Promise<TypedDoc<FieldsOf<C, N>>>;
1512
+ list<N extends CollectionName<C>>(actor: Actor, col: N, o?: Parameters<CmsCore["list"]>[2]): Promise<TypedDoc<FieldsOf<C, N>>[]>;
1513
+ create<N extends CollectionName<C>>(actor: Actor, col: N, input: DocInput<FieldsOf<C, N>>, o?: WriteOptions): Promise<TypedDoc<FieldsOf<C, N>>>;
1514
+ update<N extends CollectionName<C>>(actor: Actor, col: N, slug: string, input: DocInput<FieldsOf<C, N>>, o?: WriteOptions): Promise<TypedDoc<FieldsOf<C, N>>>;
1515
+ publish<N extends CollectionName<C>>(actor: Actor, col: N, slug: string, o?: {
1516
+ version?: number;
1517
+ expectedVersion?: number;
1518
+ }): Promise<TypedDoc<FieldsOf<C, N>>>;
1519
+ archive<N extends CollectionName<C>>(actor: Actor, col: N, slug: string, o?: {
1520
+ expectedVersion?: number;
1521
+ }): Promise<TypedDoc<FieldsOf<C, N>>>;
1522
+ unarchive<N extends CollectionName<C>>(actor: Actor, col: N, slug: string, o?: {
1523
+ expectedVersion?: number;
1524
+ }): Promise<TypedDoc<FieldsOf<C, N>>>;
1525
+ unpublish<N extends CollectionName<C>>(actor: Actor, col: N, slug: string, o?: {
1526
+ expectedVersion?: number;
1527
+ }): Promise<TypedDoc<FieldsOf<C, N>>>;
1528
+ restore<N extends CollectionName<C>>(actor: Actor, col: N, slug: string, n: number, o?: WriteOptions): Promise<TypedDoc<FieldsOf<C, N>>>;
1529
+ };
1530
+ /** Anything that carries a CMS (the typed `Cms` or the core itself). */
1531
+ type CmsLike = {
1532
+ readonly core: CmsCore;
1533
+ } | CmsCore;
1534
+ declare const coreOf: (c: CmsLike) => CmsCore;
1535
+ declare function createCms<const C extends readonly AnyCollection[]>(opts: CreateCmsOptions<C>): Cms<C>;
1536
+
1537
+ export { coreOf as $, type AgentChange as A, BULK_ACTIONS as B, type CmsLike as C, type DocDiff as D, type PatchOp as E, type FieldsOf as F, type PreviewLink as G, type PreviewRead as H, type PreviewTtl as I, type ScanFile as J, type KeyRow as K, LIMITS as L, type MediaOptions as M, type NewAsset as N, type SearchOptions as O, PREVIEW_TTLS as P, type SearchResult as Q, type SectionRange as R, SLUG_RE as S, type StoredVersion as T, type TypedDoc as U, type UploadInstructions as V, type UploadRequest as W, type WriteOptions as X, applyPatch as Y, assetFields as Z, assetId as _, type AnyCollection as a, createCms as a0, createCmsCore as a1, dayIn as a2, defineCollection as a3, humanSize as a4, mergePatch as a5, normalizeQuery as a6, sectionRanges as a7, type FindOptions as a8, type DocFilter as a9, type VersionPatch as aa, type NewComment as ab, type NewRelease as ac, type ReleasePatch as ad, type NewFilter as ae, type CommentThread as af, type TrashRef as ag, type TrashItem as ah, type ReleaseView as ai, type BlockedItem as aj, type ScheduledRun as ak, type AssetInfo as b, type AssetListOptions as c, type AssetPatch as d, type AssetQuery as e, type AssetUsage as f, type AssetView as g, type AuditQuery as h, type BulkAction as i, type BulkResult as j, type ChangeInfo as k, type Cms as l, type CmsAssets as m, type CmsCore as n, type CmsRepo as o, type CollectionName as p, type CreateCmsOptions as q, type DocInput as r, type DocPatch as s, type FieldsPatch as t, type ListOptions as u, type MediaStoreConfig as v, MemoryRepo as w, type NewAudit as x, type NewDoc as y, type NewVersion as z };