@coffer-org/plugin-documents 1.4.2 → 2.0.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.
- package/dist/personal_document/index.js +1 -1
- package/dist/schema.js +47 -15
- package/package.json +4 -4
|
@@ -6,7 +6,7 @@ export default defineShelf({
|
|
|
6
6
|
label: 'documents.personal_document.label',
|
|
7
7
|
icon: 'lucide:id-card',
|
|
8
8
|
views: {
|
|
9
|
-
|
|
9
|
+
list: { fields: ['owner', 'type', 'surname', 'expires'] },
|
|
10
10
|
},
|
|
11
11
|
fields: [
|
|
12
12
|
field.title({ key: 'name', label: 'core.fields.name' }),
|
package/dist/schema.js
CHANGED
|
@@ -6401,7 +6401,7 @@ function relation(raw) {
|
|
|
6401
6401
|
},
|
|
6402
6402
|
relation: {
|
|
6403
6403
|
library: raw.options.library,
|
|
6404
|
-
|
|
6404
|
+
shelf: raw.options.shelf
|
|
6405
6405
|
},
|
|
6406
6406
|
...multi && { json: true },
|
|
6407
6407
|
zod: optionalize(s, required)
|
|
@@ -6781,15 +6781,44 @@ function period(raw) {
|
|
|
6781
6781
|
zod: optionalize(s, required)
|
|
6782
6782
|
});
|
|
6783
6783
|
}
|
|
6784
|
+
/** Keys a file entry may carry. Everything else is rejected — see fileEntryIssue. */
|
|
6785
|
+
var FILE_KEYS = /* @__PURE__ */ new Set([
|
|
6786
|
+
"name",
|
|
6787
|
+
"mime",
|
|
6788
|
+
"size"
|
|
6789
|
+
]);
|
|
6790
|
+
/** Keys that mean "the author pasted a remote address" — the one mistake worth naming. */
|
|
6791
|
+
var FILE_URL_KEYS = [
|
|
6792
|
+
"url",
|
|
6793
|
+
"src",
|
|
6794
|
+
"href",
|
|
6795
|
+
"link"
|
|
6796
|
+
];
|
|
6797
|
+
/**
|
|
6798
|
+
* A file entry points at a file already uploaded to the server: `{ name }`, where
|
|
6799
|
+
* name is the bare filename returned by POST /api/upload. Anything else — a remote
|
|
6800
|
+
* URL, an extra key, a path — is refused here, so a record can never hold a
|
|
6801
|
+
* reference the server cannot serve. `mime`/`size` are accepted (legacy payloads
|
|
6802
|
+
* and the web uploader send them) but the server overwrites them from disk.
|
|
6803
|
+
* Returns a vmsg code, or null when the entry is well-formed.
|
|
6804
|
+
*/
|
|
6805
|
+
function fileEntryIssue(it) {
|
|
6806
|
+
if (typeof it !== "object" || it === null || Array.isArray(it)) return "file_structure";
|
|
6807
|
+
const rec = it;
|
|
6808
|
+
if (FILE_URL_KEYS.some((k) => k in rec)) return "file_remote_url";
|
|
6809
|
+
const name = rec["name"];
|
|
6810
|
+
if (typeof name !== "string" || name === "") return "file_structure";
|
|
6811
|
+
if (name.includes("://") || name.startsWith("//")) return "file_remote_url";
|
|
6812
|
+
if (/[\\/]/.test(name) || name.includes("..")) return "file_name";
|
|
6813
|
+
for (const k of Object.keys(rec)) if (!FILE_KEYS.has(k)) return "file_unknown_key";
|
|
6814
|
+
if (rec["mime"] !== void 0 && typeof rec["mime"] !== "string") return "file_structure";
|
|
6815
|
+
if (rec["size"] !== void 0 && typeof rec["size"] !== "number") return "file_structure";
|
|
6816
|
+
return null;
|
|
6817
|
+
}
|
|
6784
6818
|
function makeFile(kind, raw) {
|
|
6785
6819
|
const o = normalizeOpts(raw);
|
|
6786
6820
|
const required = o.required ?? false;
|
|
6787
6821
|
const multiple = o.multiple ?? false;
|
|
6788
|
-
const rowSchema = object({
|
|
6789
|
-
name: string$1().min(1),
|
|
6790
|
-
mime: string$1().optional(),
|
|
6791
|
-
size: number$1().optional()
|
|
6792
|
-
});
|
|
6793
6822
|
const s = unknown().superRefine((raw, ctx) => {
|
|
6794
6823
|
if (typeof raw === "string") try {
|
|
6795
6824
|
JSON.parse(raw);
|
|
@@ -6802,12 +6831,15 @@ function makeFile(kind, raw) {
|
|
|
6802
6831
|
}
|
|
6803
6832
|
const parsed = jsonValue(raw);
|
|
6804
6833
|
const items = Array.isArray(parsed) ? parsed : [parsed];
|
|
6805
|
-
for (const it of items)
|
|
6806
|
-
|
|
6807
|
-
|
|
6808
|
-
|
|
6809
|
-
|
|
6810
|
-
|
|
6834
|
+
for (const it of items) {
|
|
6835
|
+
const code = fileEntryIssue(it);
|
|
6836
|
+
if (code) {
|
|
6837
|
+
ctx.addIssue({
|
|
6838
|
+
code: ZodIssueCode.custom,
|
|
6839
|
+
message: vmsg(code)
|
|
6840
|
+
});
|
|
6841
|
+
return;
|
|
6842
|
+
}
|
|
6811
6843
|
}
|
|
6812
6844
|
});
|
|
6813
6845
|
return wrapKey(o, {
|
|
@@ -7738,7 +7770,7 @@ function defineShelf(m) {
|
|
|
7738
7770
|
const keys = fieldEntries(m.fields).map(([k]) => k);
|
|
7739
7771
|
const dup = keys.find((k, i) => keys.indexOf(k) !== i);
|
|
7740
7772
|
if (dup) throw new Error(`[shelf] ${m.library}/${m.shelf}: duplicate key '${dup}'`);
|
|
7741
|
-
if (m.standalone !== false && !m.views?.
|
|
7773
|
+
if (m.standalone !== false && !m.views?.list?.fields?.length) console.warn(`[shelf] ${m.library}/${m.shelf}: standalone shelf without an explicit views.list`);
|
|
7742
7774
|
return m;
|
|
7743
7775
|
}
|
|
7744
7776
|
//#endregion
|
|
@@ -7748,12 +7780,12 @@ var personal_document_default = defineShelf({
|
|
|
7748
7780
|
library: "documents",
|
|
7749
7781
|
label: "documents.personal_document.label",
|
|
7750
7782
|
icon: "lucide:id-card",
|
|
7751
|
-
views: {
|
|
7783
|
+
views: { list: { fields: [
|
|
7752
7784
|
"owner",
|
|
7753
7785
|
"type",
|
|
7754
7786
|
"surname",
|
|
7755
7787
|
"expires"
|
|
7756
|
-
] },
|
|
7788
|
+
] } },
|
|
7757
7789
|
fields: [
|
|
7758
7790
|
field.title({
|
|
7759
7791
|
key: "name",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coffer-org/plugin-documents",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=24"
|
|
@@ -25,9 +25,9 @@
|
|
|
25
25
|
"postpack": "node ../../scripts/swap-exports.mjs src"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@coffer-org/plugin-people": "^
|
|
29
|
-
"@coffer-org/sdk": "^
|
|
30
|
-
"@coffer-org/server": "^
|
|
28
|
+
"@coffer-org/plugin-people": "^2.0.0",
|
|
29
|
+
"@coffer-org/sdk": "^2.0.0",
|
|
30
|
+
"@coffer-org/server": "^2.0.1"
|
|
31
31
|
},
|
|
32
32
|
"coffer": {
|
|
33
33
|
"schema": "dist/schema.js"
|