@mainsoft/agent-cms 0.10.2 → 0.11.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 (87) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/README.md +91 -2
  3. package/TODO.md +6 -6
  4. package/UPGRADE-0.11.md +43 -0
  5. package/dist/agent.d.cts +1 -1
  6. package/dist/agent.d.ts +1 -1
  7. package/dist/agent.js +7 -7
  8. package/dist/bin.js +236 -23
  9. package/dist/{chunk-IU2SMWAM.js → chunk-42PW3HQ3.js} +15 -1
  10. package/dist/{chunk-6PB4ZCHH.js → chunk-CIMW73L3.js} +58 -1
  11. package/dist/{chunk-7Y6TU2UA.js → chunk-HY4ED7LT.js} +2 -2
  12. package/dist/{chunk-DSJETZT4.js → chunk-I3DF6DMI.js} +15 -10
  13. package/dist/{chunk-KAO3Z3CF.js → chunk-I5UHTAAW.js} +3 -1
  14. package/dist/{chunk-7SCYDG2G.js → chunk-J25IKU7C.js} +164 -28
  15. package/dist/{chunk-BFVBHIHV.js → chunk-J5DW3RFQ.js} +4 -1
  16. package/dist/{chunk-7WJIIJCI.js → chunk-LELPCGDX.js} +8 -5
  17. package/dist/{chunk-5ODZ2ZJF.js → chunk-NO6S7KOL.js} +1 -1
  18. package/dist/{chunk-5FMVVBDR.js → chunk-OLHLSSTD.js} +3 -3
  19. package/dist/{chunk-3OPKTBEI.js → chunk-SV3ZA6XP.js} +1 -1
  20. package/dist/{chunk-PEQY4N73.js → chunk-TKKTEGHL.js} +1 -0
  21. package/dist/{chunk-PGV2QPIL.js → chunk-WWG7XDIZ.js} +2 -0
  22. package/dist/cli.cjs +236 -23
  23. package/dist/cli.d.cts +2 -2
  24. package/dist/cli.d.ts +2 -2
  25. package/dist/cli.js +18 -16
  26. package/dist/client.cjs +4 -1
  27. package/dist/client.d.cts +14 -2
  28. package/dist/client.d.ts +14 -2
  29. package/dist/client.js +1 -1
  30. package/dist/{cms-pqJyowu1.d.ts → cms-A9tmLmTP.d.ts} +100 -5
  31. package/dist/{cms-C_vkAxYV.d.cts → cms-CaB81PPX.d.cts} +100 -5
  32. package/dist/config.d.cts +1 -1
  33. package/dist/config.d.ts +1 -1
  34. package/dist/{drizzle-repo-DWLD0rWe.d.ts → drizzle-repo-BXV-hFkE.d.ts} +1 -1
  35. package/dist/{drizzle-repo-CviH3EX7.d.cts → drizzle-repo-CblPVYnK.d.cts} +1 -1
  36. package/dist/errors.cjs +4 -0
  37. package/dist/errors.d.cts +3 -1
  38. package/dist/errors.d.ts +3 -1
  39. package/dist/errors.js +2 -2
  40. package/dist/frontmatter.d.cts +1 -1
  41. package/dist/frontmatter.d.ts +1 -1
  42. package/dist/http.cjs +17 -7
  43. package/dist/http.d.cts +2 -2
  44. package/dist/http.d.ts +2 -2
  45. package/dist/http.js +16 -15
  46. package/dist/image-sharp.cjs +104 -0
  47. package/dist/image-sharp.d.cts +47 -0
  48. package/dist/image-sharp.d.ts +47 -0
  49. package/dist/image-sharp.js +70 -0
  50. package/dist/index.cjs +244 -27
  51. package/dist/index.d.cts +3 -3
  52. package/dist/index.d.ts +3 -3
  53. package/dist/index.js +21 -21
  54. package/dist/mcp.cjs +9 -4
  55. package/dist/mcp.d.cts +1 -1
  56. package/dist/mcp.d.ts +1 -1
  57. package/dist/mcp.js +11 -11
  58. package/dist/messages/en.cjs +2 -0
  59. package/dist/messages/en.js +1 -1
  60. package/dist/messages/ko.cjs +2 -0
  61. package/dist/messages/ko.js +2 -0
  62. package/dist/registry/cms-doc-editor.json +6 -1
  63. package/dist/registry/cms-lib.json +2 -2
  64. package/dist/registry/cms-media-picker.json +2 -2
  65. package/dist/registry/cms-media.json +1 -1
  66. package/dist/registry/registry.json +4 -0
  67. package/dist/storage-vercel-blob.cjs +199 -0
  68. package/dist/storage-vercel-blob.d.cts +98 -0
  69. package/dist/storage-vercel-blob.d.ts +98 -0
  70. package/dist/storage-vercel-blob.js +165 -0
  71. package/dist/storage.cjs +63 -3
  72. package/dist/storage.d.cts +27 -2
  73. package/dist/storage.d.ts +27 -2
  74. package/dist/storage.js +9 -3
  75. package/dist/tables.cjs +15 -1
  76. package/dist/tables.d.cts +160 -7
  77. package/dist/tables.d.ts +160 -7
  78. package/dist/tables.js +2 -2
  79. package/dist/tools.cjs +8 -3
  80. package/dist/tools.d.cts +1 -1
  81. package/dist/tools.d.ts +1 -1
  82. package/dist/tools.js +9 -9
  83. package/dist/types.cjs +5 -0
  84. package/dist/types.d.cts +6 -1
  85. package/dist/types.d.ts +6 -1
  86. package/dist/types.js +3 -3
  87. package/package.json +36 -2
@@ -0,0 +1,165 @@
1
+ import "./chunk-2NTK7H4W.js";
2
+
3
+ // src/storage-vercel-blob.ts
4
+ var VercelBlobError = class extends Error {
5
+ constructor(op, message, options) {
6
+ super(`Vercel Blob ${op} failed: ${message}`, options);
7
+ this.op = op;
8
+ this.name = "VercelBlobError";
9
+ }
10
+ op;
11
+ };
12
+ var MAX_LINK_MS = 7 * 24 * 3600 * 1e3 - 6e4;
13
+ var TOKEN_LIFE_MS = 2 * 3600 * 1e3;
14
+ var NO_PARTS = "Vercel Blob takes a file in one request; uploads in parts are not supported on this store";
15
+ var notFound = (e, b) => !!e && typeof e === "object" && (!!b?.BlobNotFoundError && e instanceof b.BlobNotFoundError || e.name === "BlobNotFoundError" || e.constructor?.name === "BlobNotFoundError");
16
+ var Missing = class extends Error {
17
+ };
18
+ var text = (e) => e instanceof Error ? e.message : String(e);
19
+ var iso = (d) => d ? new Date(d).toISOString() : null;
20
+ var hasExt = (key) => /\.[A-Za-z0-9]{1,10}$/.test(key.split("/").pop() ?? "");
21
+ var maxAge = (cacheControl) => {
22
+ const m = /max-age=(\d+)/.exec(cacheControl ?? "");
23
+ return m ? { cacheControlMaxAge: Number(m[1]) } : {};
24
+ };
25
+ function vercelBlobStorage(o) {
26
+ if (o.access !== "public" && o.access !== "private") throw new Error('agent-cms: vercelBlobStorage({ access }) must be "public" or "private", the way the Blob store was created');
27
+ const storeId = /^vercel_blob_rw_([A-Za-z0-9]+)_/.exec(o.token ?? "")?.[1];
28
+ if (!storeId) throw new Error("agent-cms: vercelBlobStorage({ token }) needs the store's read-write token (BLOB_READ_WRITE_TOKEN, it starts with vercel_blob_rw_)");
29
+ const { token, access } = o;
30
+ const prefix = o.prefix ? `${o.prefix.replace(/^\/+|\/+$/g, "")}/` : "";
31
+ const doFetch = o.fetch ?? fetch;
32
+ const full = (key) => prefix + key;
33
+ const strip = (k) => k.startsWith(prefix) ? k.slice(prefix.length) : k;
34
+ const fixed = { access, token, addRandomSuffix: false, allowOverwrite: true };
35
+ let lib = o.blob ? Promise.resolve(o.blob) : null;
36
+ const load = () => lib ??= import("@vercel/blob").then(
37
+ (m) => m,
38
+ (e) => {
39
+ lib = null;
40
+ throw new Error(`agent-cms: vercelBlobStorage() could not load "@vercel/blob" (npm install @vercel/blob): ${text(e)}`);
41
+ }
42
+ );
43
+ async function call(op, fn) {
44
+ const b = await load();
45
+ try {
46
+ return await fn(b);
47
+ } catch (e) {
48
+ if (notFound(e, b)) throw new Missing(text(e));
49
+ throw new VercelBlobError(op, text(e), { cause: e });
50
+ }
51
+ }
52
+ const signers = /* @__PURE__ */ new Map();
53
+ async function signer(operation, needMs) {
54
+ const cached = await signers.get(operation)?.catch(() => null);
55
+ if (cached && cached.validUntil - Date.now() >= needMs + 3e4) return cached;
56
+ const made = call("sign", (b) => b.issueSignedToken({ token, operations: [operation], validUntil: Date.now() + Math.min(MAX_LINK_MS + 3e4, Math.max(needMs + 6e5, TOKEN_LIFE_MS)) }));
57
+ signers.set(operation, made);
58
+ return made;
59
+ }
60
+ async function presign(operation, key, expires, more = {}) {
61
+ const ms = Math.min(Math.max(1, expires) * 1e3, MAX_LINK_MS);
62
+ const t = await signer(operation, ms);
63
+ return (await call("sign", (b) => b.presignUrl(t, { operation, pathname: full(key), access, validUntil: Date.now() + ms, ...more }))).presignedUrl;
64
+ }
65
+ async function head(key) {
66
+ try {
67
+ const h = await call("head", (b) => b.head(full(key), { token }));
68
+ return { key, size: h.size, mime: h.contentType ?? null, etag: h.etag ?? null, lastModified: iso(h.uploadedAt) };
69
+ } catch (e) {
70
+ if (e instanceof Missing) return null;
71
+ throw e;
72
+ }
73
+ }
74
+ async function copy(from, to, mime) {
75
+ const contentType = mime ?? (hasExt(to) ? void 0 : (await head(from))?.mime ?? void 0);
76
+ await call("copy", (b) => b.copy(full(from), full(to), { ...fixed, ...contentType ? { contentType } : {} }));
77
+ }
78
+ return {
79
+ options: o,
80
+ multipart: false,
81
+ async presignPut(key, p) {
82
+ const url = await presign("put", key, p.expires, { addRandomSuffix: false, allowOverwrite: true, ...p.size ? { maximumSizeInBytes: p.size } : {}, ...maxAge(p.cacheControl) });
83
+ return { url, headers: { "content-type": p.mime } };
84
+ },
85
+ async put(key, body, p) {
86
+ if (key.endsWith("/")) {
87
+ await call("createFolder", (b) => b.createFolder(full(key).replace(/\/+$/, ""), { token, access })).catch(async (e) => {
88
+ if (!await head(key)) throw e;
89
+ });
90
+ return;
91
+ }
92
+ if (!body.length) {
93
+ const signed = await this.presignPut(key, { ...p, expires: 300 });
94
+ const res = await doFetch(signed.url, { method: "PUT", headers: signed.headers, body });
95
+ if (!res.ok) throw new VercelBlobError("put", `${res.status} ${(await res.text().catch(() => "")).slice(0, 200)}`);
96
+ await res.arrayBuffer().catch(() => {
97
+ });
98
+ return;
99
+ }
100
+ await call("put", (b) => b.put(full(key), new Blob([body]), { ...fixed, contentType: p.mime, ...maxAge(p.cacheControl) }));
101
+ },
102
+ async createMultipart() {
103
+ throw new VercelBlobError("createMultipart", NO_PARTS);
104
+ },
105
+ async presignPart() {
106
+ throw new VercelBlobError("presignPart", NO_PARTS);
107
+ },
108
+ async listParts() {
109
+ return [];
110
+ },
111
+ async completeMultipart() {
112
+ throw new VercelBlobError("completeMultipart", NO_PARTS);
113
+ },
114
+ async abortMultipart() {
115
+ },
116
+ head,
117
+ async readStart(key, bytes) {
118
+ if (bytes <= 0) return new Uint8Array();
119
+ try {
120
+ const got = await call("read", (b) => b.get(full(key), { access, token, headers: { range: `bytes=0-${bytes - 1}` } }));
121
+ if (!got) return null;
122
+ if (!got.stream) return new Uint8Array();
123
+ return new Uint8Array(await new Response(got.stream).arrayBuffer()).slice(0, bytes);
124
+ } catch (e) {
125
+ if (e instanceof Missing) return null;
126
+ const h = await head(key);
127
+ if (!h) return null;
128
+ if (h.size === 0) return new Uint8Array();
129
+ throw e;
130
+ }
131
+ },
132
+ async presignGet(key, g) {
133
+ const url = await presign("get", key, g.expires);
134
+ return g.download ? `${url}&download=1` : url;
135
+ },
136
+ publicUrl(key) {
137
+ return access === "public" ? `https://${storeId.toLowerCase()}.public.blob.vercel-storage.com/${full(key).split("/").map(encodeURIComponent).join("/")}` : null;
138
+ },
139
+ copy: (from, to) => copy(from, to),
140
+ /**
141
+ * A file a browser sent is stored as a download. Copying it onto itself
142
+ * from the server makes Blob apply its usual rule (pictures, PDF, video
143
+ * and sound open in the browser), in about a second even for large files.
144
+ */
145
+ async settle(key, p) {
146
+ if (p.disposition?.startsWith("attachment")) return;
147
+ await copy(key, key, p.mime);
148
+ },
149
+ async delete(key) {
150
+ await call("delete", (b) => b.del(full(key), { token }));
151
+ },
152
+ async list(l = {}) {
153
+ const r = await call("list", (b) => b.list({ token, prefix: prefix + (l.prefix ?? ""), mode: l.delimiter ? "folded" : "expanded", limit: l.limit ?? 1e3, ...l.cursor ? { cursor: l.cursor } : {} }));
154
+ return {
155
+ objects: r.blobs.map((x) => ({ key: strip(x.pathname), size: x.size, mime: null, etag: x.etag ?? null, lastModified: iso(x.uploadedAt) })),
156
+ prefixes: (r.folders ?? []).map(strip),
157
+ cursor: r.hasMore && r.cursor ? r.cursor : null
158
+ };
159
+ }
160
+ };
161
+ }
162
+ export {
163
+ VercelBlobError,
164
+ vercelBlobStorage
165
+ };
package/dist/storage.cjs CHANGED
@@ -23,9 +23,11 @@ __export(storage_exports, {
23
23
  ASSET_ID_RE: () => ASSET_ID_RE,
24
24
  DEFAULT_ACCEPT: () => DEFAULT_ACCEPT,
25
25
  DEFAULT_MAX_FILE_SIZE: () => DEFAULT_MAX_FILE_SIZE,
26
+ DERIVED_PREFIX: () => DERIVED_PREFIX,
26
27
  MIME_BY_EXT: () => MIME_BY_EXT,
27
28
  MemoryStorage: () => MemoryStorage,
28
29
  PART_SIZE: () => PART_SIZE,
30
+ REPLACE_PREFIX: () => REPLACE_PREFIX,
29
31
  RESERVED_FOLDER: () => RESERVED_FOLDER,
30
32
  THUMB_PREFIX: () => THUMB_PREFIX,
31
33
  acceptsFile: () => acceptsFile,
@@ -41,7 +43,8 @@ __export(storage_exports, {
41
43
  newAssetId: () => newAssetId,
42
44
  numberedName: () => numberedName,
43
45
  servedInline: () => servedInline,
44
- sniff: () => sniff
46
+ sniff: () => sniff,
47
+ stripJpegMetadata: () => stripJpegMetadata
45
48
  });
46
49
  module.exports = __toCommonJS(storage_exports);
47
50
  var MIME_BY_EXT = {
@@ -101,6 +104,60 @@ var DEFAULT_MAX_FILE_SIZE = 5 * 1024 ** 3;
101
104
  var PART_SIZE = 16 * 1024 * 1024;
102
105
  var THUMB_PREFIX = "_cms/thumbs/";
103
106
  var RESERVED_FOLDER = "_cms";
107
+ var DERIVED_PREFIX = "_cms/derived/";
108
+ var REPLACE_PREFIX = "_cms/replace/";
109
+ function stripJpegMetadata(b) {
110
+ if (b.length < 4 || b[0] !== 255 || b[1] !== 216) return b;
111
+ const keep = [];
112
+ let orientation = 1;
113
+ let dropped = false;
114
+ let i = 2;
115
+ while (i + 4 <= b.length && b[i] === 255) {
116
+ const m = b[i + 1];
117
+ if (m === 218 || m === 217) break;
118
+ if (m === 255) {
119
+ i++;
120
+ continue;
121
+ }
122
+ if (m >= 208 && m <= 215 || m === 1) {
123
+ keep.push([i, i + 2]);
124
+ i += 2;
125
+ continue;
126
+ }
127
+ const end = i + 2 + (b[i + 2] << 8 | b[i + 3]);
128
+ if (end < i + 4 || end > b.length) return b;
129
+ if (m === 225 || m === 237 || m === 254) {
130
+ dropped = true;
131
+ if (m === 225 && end - i >= 18 && b[i + 4] === 69 && b[i + 5] === 120 && b[i + 6] === 105 && b[i + 7] === 102) orientation = exifOrientation(b.subarray(i + 10, end)) ?? orientation;
132
+ } else keep.push([i, end]);
133
+ i = end;
134
+ }
135
+ if (!dropped) return b;
136
+ const turn = orientation >= 2 && orientation <= 8 ? Uint8Array.of(255, 225, 0, 34, 69, 120, 105, 102, 0, 0, 77, 77, 0, 42, 0, 0, 0, 8, 0, 1, 1, 18, 0, 3, 0, 0, 0, 1, 0, orientation, 0, 0, 0, 0, 0, 0) : new Uint8Array();
137
+ const out = new Uint8Array(2 + turn.length + keep.reduce((n, [a, z]) => n + z - a, 0) + b.length - i);
138
+ out.set(b.subarray(0, 2));
139
+ out.set(turn, 2);
140
+ let at = 2 + turn.length;
141
+ for (const [a, z] of keep) {
142
+ out.set(b.subarray(a, z), at);
143
+ at += z - a;
144
+ }
145
+ out.set(b.subarray(i), at);
146
+ return out;
147
+ }
148
+ function exifOrientation(t) {
149
+ if (t.length < 14) return null;
150
+ const le = t[0] === 73;
151
+ const u16 = (o) => le ? t[o] | t[o + 1] << 8 : t[o] << 8 | t[o + 1];
152
+ const ifd = le ? t[4] | t[5] << 8 | t[6] << 16 | t[7] << 24 : (t[4] << 24 | t[5] << 16 | t[6] << 8 | t[7]) >>> 0;
153
+ if (ifd < 8 || ifd + 2 > t.length) return null;
154
+ const n = u16(ifd);
155
+ for (let k = 0; k < n && ifd + 2 + (k + 1) * 12 <= t.length; k++) {
156
+ const e = ifd + 2 + k * 12;
157
+ if (u16(e) === 274) return u16(e + 8);
158
+ }
159
+ return null;
160
+ }
104
161
  var extOf = (name) => {
105
162
  const m = /\.([a-z0-9]{1,10})$/i.exec(name);
106
163
  return m ? m[1].toLowerCase() : "";
@@ -249,7 +306,7 @@ var MemoryStorage = class {
249
306
  return `memory://${this.o.name ?? "store"}/`;
250
307
  }
251
308
  store(key, body, o) {
252
- this.objects.set(key, { body, mime: o.mime, disposition: o.disposition ?? null, at: (/* @__PURE__ */ new Date()).toISOString() });
309
+ this.objects.set(key, { body, mime: o.mime, disposition: o.disposition ?? null, cacheControl: o.cacheControl ?? null, at: (/* @__PURE__ */ new Date()).toISOString() });
253
310
  }
254
311
  meta(key, v) {
255
312
  return { key, size: v.body.length, mime: v.mime, etag: `"m${v.body.length}"`, lastModified: v.at };
@@ -351,9 +408,11 @@ var MemoryStorage = class {
351
408
  ASSET_ID_RE,
352
409
  DEFAULT_ACCEPT,
353
410
  DEFAULT_MAX_FILE_SIZE,
411
+ DERIVED_PREFIX,
354
412
  MIME_BY_EXT,
355
413
  MemoryStorage,
356
414
  PART_SIZE,
415
+ REPLACE_PREFIX,
357
416
  RESERVED_FOLDER,
358
417
  THUMB_PREFIX,
359
418
  acceptsFile,
@@ -369,5 +428,6 @@ var MemoryStorage = class {
369
428
  newAssetId,
370
429
  numberedName,
371
430
  servedInline,
372
- sniff
431
+ sniff,
432
+ stripJpegMetadata
373
433
  });
@@ -42,9 +42,16 @@ interface StorageList {
42
42
  cursor: string | null;
43
43
  }
44
44
  interface StorageAdapter {
45
- /** A URL the browser can PUT the whole file to. */
45
+ /**
46
+ * `false`: this storage takes a file in one request only, whatever its
47
+ * size. The CMS then never asks for parts, and a failed upload starts again
48
+ * instead of carrying on. Leave out when parts work (S3-compatible storage).
49
+ */
50
+ readonly multipart?: boolean;
51
+ /** A URL the browser can PUT the whole file to. `size`: the size the uploader declared, for storage that can hold it to that. */
46
52
  presignPut(key: string, o: PutOptions & {
47
53
  expires: number;
54
+ size?: number;
48
55
  }): Promise<SignedRequest>;
49
56
  /** Server-side upload (small files: thumbnails, imports, folder markers). */
50
57
  put(key: string, body: Uint8Array, o: PutOptions): Promise<void>;
@@ -64,6 +71,12 @@ interface StorageAdapter {
64
71
  /** The object's public address, when the bucket is public. */
65
72
  publicUrl(key: string): string | null;
66
73
  copy(from: string, to: string): Promise<void>;
74
+ /**
75
+ * Called once for a file a browser uploaded, after it passed the checks and
76
+ * before it joins the library. For storage that has to finish something
77
+ * from the server (leave out otherwise).
78
+ */
79
+ settle?(key: string, o: PutOptions): Promise<void>;
67
80
  delete(key: string): Promise<void>;
68
81
  list(o: {
69
82
  prefix?: string;
@@ -85,6 +98,17 @@ declare const DEFAULT_MAX_FILE_SIZE: number;
85
98
  declare const PART_SIZE: number;
86
99
  declare const THUMB_PREFIX = "_cms/thumbs/";
87
100
  declare const RESERVED_FOLDER = "_cms";
101
+ /** Resized copies of images (`media.transforms`): `_cms/derived/<id>/<size>-<stamp>.<ext>`. */
102
+ declare const DERIVED_PREFIX = "_cms/derived/";
103
+ /** New content on its way to replace a file: `_cms/replace/<id>/<upload id>.<ext>`. */
104
+ declare const REPLACE_PREFIX = "_cms/replace/";
105
+ /**
106
+ * A JPEG without what cameras and phones write into it: where and when it
107
+ * was taken, the device, comments, editing history (Exif, XMP, IPTC). The
108
+ * picture itself, its colour profile and its orientation stay. Returns the
109
+ * same array when there is nothing to remove or the bytes are not a JPEG.
110
+ */
111
+ declare function stripJpegMetadata(b: Uint8Array): Uint8Array;
88
112
  declare const extOf: (name: string) => string;
89
113
  /** The MIME type to store: the extension decides when it is a known one. */
90
114
  declare function mimeOf(name: string, declared?: string | null): string;
@@ -118,6 +142,7 @@ interface MemObject {
118
142
  body: Uint8Array;
119
143
  mime: string;
120
144
  disposition: string | null;
145
+ cacheControl?: string | null;
121
146
  at: string;
122
147
  }
123
148
  /**
@@ -180,4 +205,4 @@ declare class MemoryStorage implements StorageAdapter {
180
205
  }>;
181
206
  }
182
207
 
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 };
208
+ export { ASSET_ID_RE, DEFAULT_ACCEPT, DEFAULT_MAX_FILE_SIZE, DERIVED_PREFIX, MIME_BY_EXT, MemoryStorage, PART_SIZE, type PutOptions, REPLACE_PREFIX, 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, stripJpegMetadata };
package/dist/storage.d.ts CHANGED
@@ -42,9 +42,16 @@ interface StorageList {
42
42
  cursor: string | null;
43
43
  }
44
44
  interface StorageAdapter {
45
- /** A URL the browser can PUT the whole file to. */
45
+ /**
46
+ * `false`: this storage takes a file in one request only, whatever its
47
+ * size. The CMS then never asks for parts, and a failed upload starts again
48
+ * instead of carrying on. Leave out when parts work (S3-compatible storage).
49
+ */
50
+ readonly multipart?: boolean;
51
+ /** A URL the browser can PUT the whole file to. `size`: the size the uploader declared, for storage that can hold it to that. */
46
52
  presignPut(key: string, o: PutOptions & {
47
53
  expires: number;
54
+ size?: number;
48
55
  }): Promise<SignedRequest>;
49
56
  /** Server-side upload (small files: thumbnails, imports, folder markers). */
50
57
  put(key: string, body: Uint8Array, o: PutOptions): Promise<void>;
@@ -64,6 +71,12 @@ interface StorageAdapter {
64
71
  /** The object's public address, when the bucket is public. */
65
72
  publicUrl(key: string): string | null;
66
73
  copy(from: string, to: string): Promise<void>;
74
+ /**
75
+ * Called once for a file a browser uploaded, after it passed the checks and
76
+ * before it joins the library. For storage that has to finish something
77
+ * from the server (leave out otherwise).
78
+ */
79
+ settle?(key: string, o: PutOptions): Promise<void>;
67
80
  delete(key: string): Promise<void>;
68
81
  list(o: {
69
82
  prefix?: string;
@@ -85,6 +98,17 @@ declare const DEFAULT_MAX_FILE_SIZE: number;
85
98
  declare const PART_SIZE: number;
86
99
  declare const THUMB_PREFIX = "_cms/thumbs/";
87
100
  declare const RESERVED_FOLDER = "_cms";
101
+ /** Resized copies of images (`media.transforms`): `_cms/derived/<id>/<size>-<stamp>.<ext>`. */
102
+ declare const DERIVED_PREFIX = "_cms/derived/";
103
+ /** New content on its way to replace a file: `_cms/replace/<id>/<upload id>.<ext>`. */
104
+ declare const REPLACE_PREFIX = "_cms/replace/";
105
+ /**
106
+ * A JPEG without what cameras and phones write into it: where and when it
107
+ * was taken, the device, comments, editing history (Exif, XMP, IPTC). The
108
+ * picture itself, its colour profile and its orientation stay. Returns the
109
+ * same array when there is nothing to remove or the bytes are not a JPEG.
110
+ */
111
+ declare function stripJpegMetadata(b: Uint8Array): Uint8Array;
88
112
  declare const extOf: (name: string) => string;
89
113
  /** The MIME type to store: the extension decides when it is a known one. */
90
114
  declare function mimeOf(name: string, declared?: string | null): string;
@@ -118,6 +142,7 @@ interface MemObject {
118
142
  body: Uint8Array;
119
143
  mime: string;
120
144
  disposition: string | null;
145
+ cacheControl?: string | null;
121
146
  at: string;
122
147
  }
123
148
  /**
@@ -180,4 +205,4 @@ declare class MemoryStorage implements StorageAdapter {
180
205
  }>;
181
206
  }
182
207
 
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 };
208
+ export { ASSET_ID_RE, DEFAULT_ACCEPT, DEFAULT_MAX_FILE_SIZE, DERIVED_PREFIX, MIME_BY_EXT, MemoryStorage, PART_SIZE, type PutOptions, REPLACE_PREFIX, 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, stripJpegMetadata };
package/dist/storage.js CHANGED
@@ -2,9 +2,11 @@ import {
2
2
  ASSET_ID_RE,
3
3
  DEFAULT_ACCEPT,
4
4
  DEFAULT_MAX_FILE_SIZE,
5
+ DERIVED_PREFIX,
5
6
  MIME_BY_EXT,
6
7
  MemoryStorage,
7
8
  PART_SIZE,
9
+ REPLACE_PREFIX,
8
10
  RESERVED_FOLDER,
9
11
  THUMB_PREFIX,
10
12
  acceptsFile,
@@ -20,16 +22,19 @@ import {
20
22
  newAssetId,
21
23
  numberedName,
22
24
  servedInline,
23
- sniff
24
- } from "./chunk-6PB4ZCHH.js";
25
+ sniff,
26
+ stripJpegMetadata
27
+ } from "./chunk-CIMW73L3.js";
25
28
  import "./chunk-2NTK7H4W.js";
26
29
  export {
27
30
  ASSET_ID_RE,
28
31
  DEFAULT_ACCEPT,
29
32
  DEFAULT_MAX_FILE_SIZE,
33
+ DERIVED_PREFIX,
30
34
  MIME_BY_EXT,
31
35
  MemoryStorage,
32
36
  PART_SIZE,
37
+ REPLACE_PREFIX,
33
38
  RESERVED_FOLDER,
34
39
  THUMB_PREFIX,
35
40
  acceptsFile,
@@ -45,5 +50,6 @@ export {
45
50
  newAssetId,
46
51
  numberedName,
47
52
  servedInline,
48
- sniff
53
+ sniff,
54
+ stripJpegMetadata
49
55
  };
package/dist/tables.cjs CHANGED
@@ -45,7 +45,7 @@ module.exports = __toCommonJS(tables_exports);
45
45
  var import_pg_core = require("drizzle-orm/pg-core");
46
46
 
47
47
  // src/schema-version.ts
48
- var SCHEMA_VERSION = 4;
48
+ var SCHEMA_VERSION = 5;
49
49
 
50
50
  // src/tables.ts
51
51
  var NAME_RE = /^[a-z_][a-z0-9_]*$/;
@@ -183,6 +183,9 @@ function cmsTables(o = {}) {
183
183
  alt: (0, import_pg_core.text)("alt").notNull().default(""),
184
184
  tags: (0, import_pg_core.jsonb)("tags").$type().notNull().default([]),
185
185
  thumbKey: (0, import_pg_core.text)("thumb_key"),
186
+ focalX: (0, import_pg_core.real)("focal_x"),
187
+ focalY: (0, import_pg_core.real)("focal_y"),
188
+ rev: (0, import_pg_core.integer)("rev").notNull().default(0),
186
189
  status: (0, import_pg_core.text)("status").notNull().default("pending"),
187
190
  uploadId: (0, import_pg_core.text)("upload_id"),
188
191
  createdBy: (0, import_pg_core.text)("created_by"),
@@ -359,6 +362,9 @@ CREATE TABLE IF NOT EXISTS ${tbl("assets")} (
359
362
  "alt" text NOT NULL DEFAULT '',
360
363
  "tags" jsonb NOT NULL DEFAULT '[]'::jsonb,
361
364
  "thumb_key" text,
365
+ "focal_x" real,
366
+ "focal_y" real,
367
+ "rev" integer NOT NULL DEFAULT 0,
362
368
  "status" text NOT NULL DEFAULT 'pending',
363
369
  "upload_id" text,
364
370
  "created_by" text,
@@ -448,6 +454,14 @@ CREATE TABLE IF NOT EXISTS ${tbl("presence")} (
448
454
  PRIMARY KEY ("document_id", "actor_id")
449
455
  );
450
456
  CREATE INDEX IF NOT EXISTS ${idx("presence_seen_idx")} ON ${tbl("presence")} ("seen_at");`.trim()
457
+ },
458
+ {
459
+ version: 5,
460
+ name: "agent-cms 0.11.0: an image's focal point, replacing a file at the same address",
461
+ sql: `
462
+ ALTER TABLE ${tbl("assets")} ADD COLUMN IF NOT EXISTS "focal_x" real;
463
+ ALTER TABLE ${tbl("assets")} ADD COLUMN IF NOT EXISTS "focal_y" real;
464
+ ALTER TABLE ${tbl("assets")} ADD COLUMN IF NOT EXISTS "rev" integer NOT NULL DEFAULT 0;`.trim()
451
465
  }
452
466
  ];
453
467
  }