@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,373 @@
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/storage.ts
21
+ var storage_exports = {};
22
+ __export(storage_exports, {
23
+ ASSET_ID_RE: () => ASSET_ID_RE,
24
+ DEFAULT_ACCEPT: () => DEFAULT_ACCEPT,
25
+ DEFAULT_MAX_FILE_SIZE: () => DEFAULT_MAX_FILE_SIZE,
26
+ MIME_BY_EXT: () => MIME_BY_EXT,
27
+ MemoryStorage: () => MemoryStorage,
28
+ PART_SIZE: () => PART_SIZE,
29
+ RESERVED_FOLDER: () => RESERVED_FOLDER,
30
+ THUMB_PREFIX: () => THUMB_PREFIX,
31
+ acceptsFile: () => acceptsFile,
32
+ cleanFolder: () => cleanFolder,
33
+ cleanName: () => cleanName,
34
+ contentMatches: () => contentMatches,
35
+ declaredMatches: () => declaredMatches,
36
+ dispositionFor: () => dispositionFor,
37
+ extOf: () => extOf,
38
+ joinKey: () => joinKey,
39
+ kindOf: () => kindOf,
40
+ mimeOf: () => mimeOf,
41
+ newAssetId: () => newAssetId,
42
+ numberedName: () => numberedName,
43
+ servedInline: () => servedInline,
44
+ sniff: () => sniff
45
+ });
46
+ module.exports = __toCommonJS(storage_exports);
47
+ var MIME_BY_EXT = {
48
+ jpg: "image/jpeg",
49
+ jpeg: "image/jpeg",
50
+ png: "image/png",
51
+ webp: "image/webp",
52
+ gif: "image/gif",
53
+ avif: "image/avif",
54
+ heic: "image/heic",
55
+ svg: "image/svg+xml",
56
+ mp4: "video/mp4",
57
+ webm: "video/webm",
58
+ mov: "video/quicktime",
59
+ mkv: "video/x-matroska",
60
+ mp3: "audio/mpeg",
61
+ wav: "audio/wav",
62
+ m4a: "audio/mp4",
63
+ ogg: "audio/ogg",
64
+ pdf: "application/pdf",
65
+ docx: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
66
+ xlsx: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
67
+ pptx: "application/vnd.openxmlformats-officedocument.presentationml.presentation",
68
+ txt: "text/plain",
69
+ csv: "text/csv",
70
+ md: "text/markdown",
71
+ json: "application/json",
72
+ zip: "application/zip",
73
+ html: "text/html",
74
+ htm: "text/html",
75
+ js: "text/javascript",
76
+ exe: "application/vnd.microsoft.portable-executable"
77
+ };
78
+ var DEFAULT_ACCEPT = [
79
+ "image/jpeg",
80
+ "image/png",
81
+ "image/webp",
82
+ "image/gif",
83
+ "image/avif",
84
+ "image/svg+xml",
85
+ "video/mp4",
86
+ "video/webm",
87
+ "video/quicktime",
88
+ "audio/mpeg",
89
+ "audio/wav",
90
+ "audio/mp4",
91
+ "application/pdf",
92
+ MIME_BY_EXT.docx,
93
+ MIME_BY_EXT.xlsx,
94
+ MIME_BY_EXT.pptx,
95
+ "text/plain",
96
+ "text/csv",
97
+ "text/markdown",
98
+ "application/zip"
99
+ ];
100
+ var DEFAULT_MAX_FILE_SIZE = 5 * 1024 ** 3;
101
+ var PART_SIZE = 16 * 1024 * 1024;
102
+ var THUMB_PREFIX = "_cms/thumbs/";
103
+ var RESERVED_FOLDER = "_cms";
104
+ var extOf = (name) => {
105
+ const m = /\.([a-z0-9]{1,10})$/i.exec(name);
106
+ return m ? m[1].toLowerCase() : "";
107
+ };
108
+ function mimeOf(name, declared) {
109
+ const known = MIME_BY_EXT[extOf(name)];
110
+ if (known) return known;
111
+ const d = (declared ?? "").split(";")[0].trim().toLowerCase();
112
+ return /^[a-z0-9.+-]+\/[a-z0-9.+-]+$/.test(d) ? d : "application/octet-stream";
113
+ }
114
+ function declaredMatches(name, declared) {
115
+ const known = MIME_BY_EXT[extOf(name)];
116
+ const d = (declared ?? "").split(";")[0].trim().toLowerCase();
117
+ if (!known || !d || d === "application/octet-stream" || d === known) return true;
118
+ const top = (m) => m.split("/")[0];
119
+ if (top(d) === top(known) && top(known) !== "application") return true;
120
+ if (known === "application/zip" && /zip/.test(d)) return true;
121
+ if (top(known) === "text" && (d === "application/csv" || d === "application/vnd.ms-excel")) return true;
122
+ const office = /officedocument|msword|ms-excel|ms-powerpoint/;
123
+ if (office.test(known) && office.test(d)) return true;
124
+ return false;
125
+ }
126
+ function acceptsFile(rules, file) {
127
+ const ext = extOf(file.name);
128
+ const mime = file.mime.toLowerCase();
129
+ return rules.some((raw) => {
130
+ const r = raw.trim().toLowerCase();
131
+ if (r === "*/*" || r === "*") return true;
132
+ if (r.startsWith(".")) return r.slice(1) === ext;
133
+ if (r.endsWith("/*")) return mime.startsWith(r.slice(0, -1));
134
+ return r === mime;
135
+ });
136
+ }
137
+ function kindOf(mime) {
138
+ if (mime.startsWith("image/")) return "image";
139
+ if (mime.startsWith("video/")) return "video";
140
+ if (mime.startsWith("audio/")) return "audio";
141
+ if (mime === "application/pdf" || mime.startsWith("text/") || /officedocument|msword|ms-excel|ms-powerpoint|opendocument/.test(mime)) return "document";
142
+ return "other";
143
+ }
144
+ var servedInline = (mime) => mime.startsWith("image/") || mime.startsWith("video/") || mime.startsWith("audio/") || mime === "application/pdf";
145
+ function dispositionFor(name, mime, forceDownload = false) {
146
+ if (!forceDownload && servedInline(mime)) return null;
147
+ const ascii = name.replace(/[^\x20-\x7e]/g, "_").replace(/["\\]/g, "_");
148
+ return `attachment; filename="${ascii}"; filename*=UTF-8''${encodeURIComponent(name)}`;
149
+ }
150
+ var FAMILY_BY_MIME = {
151
+ "image/jpeg": "jpeg",
152
+ "image/png": "png",
153
+ "image/gif": "gif",
154
+ "image/webp": "webp",
155
+ "image/avif": "iso",
156
+ "image/heic": "iso",
157
+ "image/svg+xml": "svg",
158
+ "video/mp4": "iso",
159
+ "video/quicktime": "iso",
160
+ "audio/mp4": "iso",
161
+ "video/webm": "webm",
162
+ "video/x-matroska": "webm",
163
+ "audio/mpeg": "mp3",
164
+ "audio/wav": "wav",
165
+ "audio/ogg": "ogg",
166
+ "application/pdf": "pdf",
167
+ "application/zip": "zip",
168
+ [MIME_BY_EXT.docx]: "zip",
169
+ [MIME_BY_EXT.xlsx]: "zip",
170
+ [MIME_BY_EXT.pptx]: "zip",
171
+ "text/html": "html",
172
+ "text/plain": "text",
173
+ "text/csv": "text",
174
+ "text/markdown": "text",
175
+ "application/json": "text",
176
+ "text/javascript": "text",
177
+ [MIME_BY_EXT.exe]: "program"
178
+ };
179
+ function sniff(b) {
180
+ const at = (i, ...sig) => sig.every((v, k) => b[i + k] === v);
181
+ const ascii = (i, n) => String.fromCharCode(...b.subarray(i, i + n));
182
+ if (at(0, 255, 216, 255)) return "jpeg";
183
+ if (at(0, 137, 80, 78, 71)) return "png";
184
+ if (ascii(0, 4) === "GIF8") return "gif";
185
+ if (ascii(0, 4) === "RIFF" && ascii(8, 4) === "WEBP") return "webp";
186
+ if (ascii(0, 4) === "RIFF" && ascii(8, 4) === "WAVE") return "wav";
187
+ if (ascii(4, 4) === "ftyp") return "iso";
188
+ if (at(0, 26, 69, 223, 163)) return "webm";
189
+ if (ascii(0, 5) === "%PDF-") return "pdf";
190
+ if (at(0, 80, 75, 3, 4) || at(0, 80, 75, 5, 6)) return "zip";
191
+ if (ascii(0, 4) === "OggS") return "ogg";
192
+ if (ascii(0, 3) === "ID3" || b[0] === 255 && (b[1] & 224) === 224 && b.length > 2) return "mp3";
193
+ if (ascii(0, 2) === "MZ" || at(0, 127, 69, 76, 70) || at(0, 207, 250, 237, 254) || at(0, 202, 254, 186, 190) || ascii(0, 2) === "#!") return "program";
194
+ if (b.length && !b.includes(0)) {
195
+ const head = new TextDecoder("utf-8", { fatal: false }).decode(b).replace(/^\uFEFF/, "").trimStart().toLowerCase();
196
+ if (/^(<!doctype html|<html|<head|<body|<script|<iframe)/.test(head)) return "html";
197
+ if (/^(<\?xml[^>]*>\s*)?(<!--[\s\S]*?-->\s*)*(<!doctype svg[^>]*>\s*)?<svg[\s>]/.test(head)) return "svg";
198
+ return "text";
199
+ }
200
+ return null;
201
+ }
202
+ function contentMatches(mime, start) {
203
+ const want = FAMILY_BY_MIME[mime];
204
+ const got = sniff(start);
205
+ if ((got === "program" || got === "html") && want !== got) return false;
206
+ if (!want) return true;
207
+ if (want === "text") return got === "text" || got === "svg" || start.length === 0;
208
+ if (want === "svg") return got === "svg";
209
+ return got === want;
210
+ }
211
+ var clean = (s) => s.normalize("NFC").replace(/[\u0000-\u001f\u007f/\\]/g, "").replace(/^[.\s]+/, "").trim();
212
+ function cleanName(name) {
213
+ let n = clean(name);
214
+ if (!n) n = "file";
215
+ if (n.length > 200) {
216
+ const ext = extOf(n);
217
+ n = ext ? `${n.slice(0, 199 - ext.length)}.${ext}` : n.slice(0, 200);
218
+ }
219
+ return n;
220
+ }
221
+ function cleanFolder(folder) {
222
+ const parts = String(folder ?? "").split("/").map(clean).filter((p) => p && p !== "." && p !== "..");
223
+ if (parts[0] === RESERVED_FOLDER) return null;
224
+ const out = parts.join("/");
225
+ return out.length > 400 ? null : out;
226
+ }
227
+ var joinKey = (folder, name) => folder ? `${folder}/${name}` : name;
228
+ function numberedName(name, n) {
229
+ if (n <= 1) return name;
230
+ const ext = extOf(name);
231
+ return ext ? `${name.slice(0, -(ext.length + 1))}-${n}.${ext}` : `${name}-${n}`;
232
+ }
233
+ function newAssetId() {
234
+ const abc = "abcdefghijklmnopqrstuvwxyz0123456789";
235
+ const bytes = crypto.getRandomValues(new Uint8Array(12));
236
+ return [...bytes].map((x) => abc[x % abc.length]).join("");
237
+ }
238
+ var ASSET_ID_RE = /^[a-z0-9]{12}$/;
239
+ var MemoryStorage = class {
240
+ constructor(o = {}) {
241
+ this.o = o;
242
+ }
243
+ o;
244
+ objects = /* @__PURE__ */ new Map();
245
+ uploads = /* @__PURE__ */ new Map();
246
+ pending = /* @__PURE__ */ new Map();
247
+ n = 0;
248
+ base() {
249
+ return `memory://${this.o.name ?? "store"}/`;
250
+ }
251
+ store(key, body, o) {
252
+ this.objects.set(key, { body, mime: o.mime, disposition: o.disposition ?? null, at: (/* @__PURE__ */ new Date()).toISOString() });
253
+ }
254
+ meta(key, v) {
255
+ return { key, size: v.body.length, mime: v.mime, etag: `"m${v.body.length}"`, lastModified: v.at };
256
+ }
257
+ /** What a browser does with a signed PUT URL. Returns the HTTP status. */
258
+ async send(url, body) {
259
+ const u = new URL(url);
260
+ const key = decodeURIComponent(u.pathname.replace(/^\/+/, ""));
261
+ const uploadId = u.searchParams.get("uploadId");
262
+ if (uploadId) {
263
+ const up = this.uploads.get(uploadId);
264
+ if (!up || up.key !== key) return 404;
265
+ up.parts.set(Number(u.searchParams.get("partNumber")), body);
266
+ return 200;
267
+ }
268
+ const o = this.pending.get(key);
269
+ if (!o) return 403;
270
+ this.store(key, body, o);
271
+ return 200;
272
+ }
273
+ async presignPut(key, o) {
274
+ this.pending.set(key, o);
275
+ const headers = { "content-type": o.mime };
276
+ if (o.disposition) headers["content-disposition"] = o.disposition;
277
+ return { url: `${this.base()}${encodeURI(key)}?put=1`, headers };
278
+ }
279
+ async put(key, body, o) {
280
+ this.store(key, body, o);
281
+ }
282
+ async createMultipart(key, o) {
283
+ const id = `up${++this.n}`;
284
+ this.uploads.set(id, { key, o, parts: /* @__PURE__ */ new Map() });
285
+ return id;
286
+ }
287
+ async presignPart(key, uploadId, partNumber) {
288
+ return `${this.base()}${encodeURI(key)}?uploadId=${uploadId}&partNumber=${partNumber}`;
289
+ }
290
+ async listParts(_key, uploadId) {
291
+ const up = this.uploads.get(uploadId);
292
+ if (!up) return [];
293
+ return [...up.parts].sort((a, b) => a[0] - b[0]).map(([partNumber, body]) => ({ partNumber, etag: `"p${partNumber}"`, size: body.length }));
294
+ }
295
+ async completeMultipart(key, uploadId, parts) {
296
+ const up = this.uploads.get(uploadId);
297
+ if (!up) throw new Error("no such upload");
298
+ const bodies = parts.map((p) => up.parts.get(p.partNumber) ?? new Uint8Array());
299
+ const all = new Uint8Array(bodies.reduce((s, x) => s + x.length, 0));
300
+ let at = 0;
301
+ for (const x of bodies) {
302
+ all.set(x, at);
303
+ at += x.length;
304
+ }
305
+ this.store(key, all, up.o);
306
+ this.uploads.delete(uploadId);
307
+ }
308
+ async abortMultipart(_key, uploadId) {
309
+ this.uploads.delete(uploadId);
310
+ }
311
+ async head(key) {
312
+ const v = this.objects.get(key);
313
+ return v ? this.meta(key, v) : null;
314
+ }
315
+ async readStart(key, bytes) {
316
+ const v = this.objects.get(key);
317
+ return v ? v.body.slice(0, bytes) : null;
318
+ }
319
+ async presignGet(key, o) {
320
+ return `${this.base()}${encodeURI(key)}?expires=${o.expires}${o.download ? `&download=${encodeURIComponent(o.download)}` : ""}`;
321
+ }
322
+ publicUrl(key) {
323
+ return this.o.publicUrl ? `${this.o.publicUrl.replace(/\/+$/, "")}/${encodeURI(key)}` : null;
324
+ }
325
+ async copy(from, to) {
326
+ const v = this.objects.get(from);
327
+ if (!v) throw new Error("no such object");
328
+ this.objects.set(to, { ...v, at: (/* @__PURE__ */ new Date()).toISOString() });
329
+ }
330
+ async delete(key) {
331
+ this.objects.delete(key);
332
+ }
333
+ async list(o = {}) {
334
+ const prefix = o.prefix ?? "";
335
+ const keys = [...this.objects.keys()].filter((k) => k.startsWith(prefix)).sort();
336
+ const objects = [];
337
+ const prefixes = /* @__PURE__ */ new Set();
338
+ for (const k of keys) {
339
+ const rest = k.slice(prefix.length);
340
+ const cut = o.delimiter ? rest.indexOf(o.delimiter) : -1;
341
+ if (cut >= 0) prefixes.add(prefix + rest.slice(0, cut + 1));
342
+ else objects.push(this.meta(k, this.objects.get(k)));
343
+ }
344
+ const start = o.cursor ? Number(o.cursor) : 0;
345
+ const limit = o.limit ?? 1e3;
346
+ return { objects: objects.slice(start, start + limit), prefixes: [...prefixes], cursor: start + limit < objects.length ? String(start + limit) : null };
347
+ }
348
+ };
349
+ // Annotate the CommonJS export names for ESM import in node:
350
+ 0 && (module.exports = {
351
+ ASSET_ID_RE,
352
+ DEFAULT_ACCEPT,
353
+ DEFAULT_MAX_FILE_SIZE,
354
+ MIME_BY_EXT,
355
+ MemoryStorage,
356
+ PART_SIZE,
357
+ RESERVED_FOLDER,
358
+ THUMB_PREFIX,
359
+ acceptsFile,
360
+ cleanFolder,
361
+ cleanName,
362
+ contentMatches,
363
+ declaredMatches,
364
+ dispositionFor,
365
+ extOf,
366
+ joinKey,
367
+ kindOf,
368
+ mimeOf,
369
+ newAssetId,
370
+ numberedName,
371
+ servedInline,
372
+ sniff
373
+ });
@@ -0,0 +1,183 @@
1
+ import { AssetKind } from './types.cjs';
2
+ import 'zod';
3
+ import './errors.cjs';
4
+
5
+ /**
6
+ * Where files live. The CMS keeps a row per file (`cms_assets`) and talks to
7
+ * the bucket through a `StorageAdapter`; `./storage-s3` is the adapter for
8
+ * S3-compatible storage. Files go from the browser straight to the storage
9
+ * with signed URLs, so the app server never carries their bytes.
10
+ *
11
+ * This file also holds the rules about names and file types, which are the
12
+ * same for every adapter.
13
+ */
14
+
15
+ interface StoredObject {
16
+ key: string;
17
+ size: number;
18
+ mime: string | null;
19
+ etag: string | null;
20
+ lastModified: string | null;
21
+ }
22
+ interface PutOptions {
23
+ mime: string;
24
+ /** `Content-Disposition` to store with the object (e.g. `attachment; filename="a.zip"`). */
25
+ disposition?: string | null;
26
+ cacheControl?: string | null;
27
+ }
28
+ interface SignedRequest {
29
+ url: string;
30
+ /** Headers the uploader must send with the request, exactly. */
31
+ headers: Record<string, string>;
32
+ }
33
+ interface StoragePart {
34
+ partNumber: number;
35
+ etag: string;
36
+ size: number;
37
+ }
38
+ interface StorageList {
39
+ objects: StoredObject[];
40
+ /** Sub-folders (with a trailing slash) when a delimiter was given. */
41
+ prefixes: string[];
42
+ cursor: string | null;
43
+ }
44
+ interface StorageAdapter {
45
+ /** A URL the browser can PUT the whole file to. */
46
+ presignPut(key: string, o: PutOptions & {
47
+ expires: number;
48
+ }): Promise<SignedRequest>;
49
+ /** Server-side upload (small files: thumbnails, imports, folder markers). */
50
+ put(key: string, body: Uint8Array, o: PutOptions): Promise<void>;
51
+ createMultipart(key: string, o: PutOptions): Promise<string>;
52
+ presignPart(key: string, uploadId: string, partNumber: number, expires: number): Promise<string>;
53
+ listParts(key: string, uploadId: string): Promise<StoragePart[]>;
54
+ completeMultipart(key: string, uploadId: string, parts: readonly Pick<StoragePart, "partNumber" | "etag">[]): Promise<void>;
55
+ abortMultipart(key: string, uploadId: string): Promise<void>;
56
+ head(key: string): Promise<StoredObject | null>;
57
+ /** The first `bytes` bytes of the object (to check what it really is). */
58
+ readStart(key: string, bytes: number): Promise<Uint8Array | null>;
59
+ /** A short-lived URL to read the object. `download`: file name to save as. */
60
+ presignGet(key: string, o: {
61
+ expires: number;
62
+ download?: string | null;
63
+ }): Promise<string>;
64
+ /** The object's public address, when the bucket is public. */
65
+ publicUrl(key: string): string | null;
66
+ copy(from: string, to: string): Promise<void>;
67
+ delete(key: string): Promise<void>;
68
+ list(o: {
69
+ prefix?: string;
70
+ delimiter?: string;
71
+ cursor?: string | null;
72
+ limit?: number;
73
+ }): Promise<StorageList>;
74
+ }
75
+ /** Extension → MIME type for the types the CMS knows. */
76
+ declare const MIME_BY_EXT: Readonly<Record<string, string>>;
77
+ /**
78
+ * What a store takes when nothing is configured: images, video, sound, PDF,
79
+ * office documents, plain text and ZIP. HTML and programs are not in it; a
80
+ * developer who wants them lists them in `media.accept`.
81
+ */
82
+ declare const DEFAULT_ACCEPT: readonly string[];
83
+ declare const DEFAULT_MAX_FILE_SIZE: number;
84
+ /** Files up to this size go up in one request; larger ones in parts of this size. */
85
+ declare const PART_SIZE: number;
86
+ declare const THUMB_PREFIX = "_cms/thumbs/";
87
+ declare const RESERVED_FOLDER = "_cms";
88
+ declare const extOf: (name: string) => string;
89
+ /** The MIME type to store: the extension decides when it is a known one. */
90
+ declare function mimeOf(name: string, declared?: string | null): string;
91
+ /** False when the browser's declared type is a different kind of file than the extension says. */
92
+ declare function declaredMatches(name: string, declared?: string | null): boolean;
93
+ /** Does `rules` (MIME types, groups such as `image/*`, extensions such as `.pdf`, or the wildcard) take this file? */
94
+ declare function acceptsFile(rules: readonly string[], file: {
95
+ name: string;
96
+ mime: string;
97
+ }): boolean;
98
+ declare function kindOf(mime: string): Exclude<AssetKind, "folder">;
99
+ /** Shown in the page (image, video, sound, PDF) or saved as a download (everything else). */
100
+ declare const servedInline: (mime: string) => boolean;
101
+ declare function dispositionFor(name: string, mime: string, forceDownload?: boolean): string | null;
102
+ type Family = "jpeg" | "png" | "gif" | "webp" | "iso" | "webm" | "pdf" | "zip" | "mp3" | "wav" | "ogg" | "program" | "html" | "svg" | "text";
103
+ /** What the first bytes of a file say it is (`null`: an unknown binary format). */
104
+ declare function sniff(b: Uint8Array): Family | null;
105
+ /** True when the file's first bytes fit the type it was stored as. */
106
+ declare function contentMatches(mime: string, start: Uint8Array): boolean;
107
+ /** A safe file name: keeps Korean and spaces, drops control characters, slashes and leading dots; 200 characters at most. */
108
+ declare function cleanName(name: string): string;
109
+ /** A safe folder path ("" = top level): no empty, `.` or `..` parts, nothing under `_cms`. `null` when it is not allowed. */
110
+ declare function cleanFolder(folder: string | null | undefined): string | null;
111
+ declare const joinKey: (folder: string, name: string) => string;
112
+ /** `name`, `name-2`, `name-3`… before the extension. */
113
+ declare function numberedName(name: string, n: number): string;
114
+ /** 12 lowercase letters and digits. */
115
+ declare function newAssetId(): string;
116
+ declare const ASSET_ID_RE: RegExp;
117
+ interface MemObject {
118
+ body: Uint8Array;
119
+ mime: string;
120
+ disposition: string | null;
121
+ at: string;
122
+ }
123
+ /**
124
+ * A storage that lives in memory. Signed URLs look like
125
+ * `memory://<name>/<key>?…`; `send(url, body)` plays the browser's part.
126
+ */
127
+ declare class MemoryStorage implements StorageAdapter {
128
+ private o;
129
+ objects: Map<string, MemObject>;
130
+ uploads: Map<string, {
131
+ key: string;
132
+ o: PutOptions;
133
+ parts: Map<number, Uint8Array>;
134
+ }>;
135
+ private pending;
136
+ private n;
137
+ constructor(o?: {
138
+ name?: string;
139
+ publicUrl?: string | null;
140
+ });
141
+ private base;
142
+ private store;
143
+ private meta;
144
+ /** What a browser does with a signed PUT URL. Returns the HTTP status. */
145
+ send(url: string, body: Uint8Array): Promise<number>;
146
+ presignPut(key: string, o: PutOptions & {
147
+ expires: number;
148
+ }): Promise<{
149
+ url: string;
150
+ headers: Record<string, string>;
151
+ }>;
152
+ put(key: string, body: Uint8Array, o: PutOptions): Promise<void>;
153
+ createMultipart(key: string, o: PutOptions): Promise<string>;
154
+ presignPart(key: string, uploadId: string, partNumber: number): Promise<string>;
155
+ listParts(_key: string, uploadId: string): Promise<{
156
+ partNumber: number;
157
+ etag: string;
158
+ size: number;
159
+ }[]>;
160
+ completeMultipart(key: string, uploadId: string, parts: readonly Pick<StoragePart, "partNumber">[]): Promise<void>;
161
+ abortMultipart(_key: string, uploadId: string): Promise<void>;
162
+ head(key: string): Promise<StoredObject | null>;
163
+ readStart(key: string, bytes: number): Promise<Uint8Array<ArrayBuffer> | null>;
164
+ presignGet(key: string, o: {
165
+ expires: number;
166
+ download?: string | null;
167
+ }): Promise<string>;
168
+ publicUrl(key: string): string | null;
169
+ copy(from: string, to: string): Promise<void>;
170
+ delete(key: string): Promise<void>;
171
+ list(o?: {
172
+ prefix?: string;
173
+ delimiter?: string;
174
+ cursor?: string | null;
175
+ limit?: number;
176
+ }): Promise<{
177
+ objects: StoredObject[];
178
+ prefixes: string[];
179
+ cursor: string | null;
180
+ }>;
181
+ }
182
+
183
+ export { ASSET_ID_RE, DEFAULT_ACCEPT, DEFAULT_MAX_FILE_SIZE, MIME_BY_EXT, MemoryStorage, PART_SIZE, type PutOptions, RESERVED_FOLDER, type SignedRequest, type StorageAdapter, type StorageList, type StoragePart, type StoredObject, THUMB_PREFIX, acceptsFile, cleanFolder, cleanName, contentMatches, declaredMatches, dispositionFor, extOf, joinKey, kindOf, mimeOf, newAssetId, numberedName, servedInline, sniff };