@kardalum/plugin-sdk 0.15.0 → 0.16.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/CHANGELOG.md +11 -1
- package/README.md +10 -0
- package/dist/built-in-value-schemas.js +1 -1
- package/dist/built-ins.js +2 -2
- package/dist/capabilities.d.ts +8 -78
- package/dist/capabilities.js +23 -319
- package/dist/index.d.ts +4 -4
- package/dist/index.js +5 -4
- package/dist/license-verdict-keys.js +4 -0
- package/dist/manifest-entry.d.ts +2 -2
- package/dist/manifest-entry.js +1 -1
- package/dist/manifest-schema.d.ts +81 -13
- package/dist/manifest-schema.js +108 -59
- package/dist/manifest.d.ts +105 -40
- package/dist/media/media-picker.js +21 -12
- package/dist/media/upload-error.d.ts +1 -1
- package/dist/media/upload-error.js +1 -1
- package/dist/plugin-context.d.ts +7 -0
- package/dist/plugin-context.js +7 -0
- package/dist/plugin-screen-context.d.ts +33 -2
- package/dist/plugin-screen-context.js +27 -2
- package/dist/read-all-pages.d.ts +23 -0
- package/dist/read-all-pages.js +30 -0
- package/dist/richtext/block-panel.js +4 -4
- package/dist/richtext/insert-menu.js +3 -3
- package/dist/views/content-list-view.js +2 -2
- package/dist/views/image-view.js +24 -39
- package/dist/views/rich-text-view.js +2 -2
- package/node_modules/@kardalum/api-schemas/dist/api-error.schema.d.ts +12 -0
- package/node_modules/@kardalum/api-schemas/dist/api-error.schema.js +19 -0
- package/node_modules/@kardalum/api-schemas/dist/api-key-api.schema.d.ts +43 -25
- package/node_modules/@kardalum/api-schemas/dist/api-key-api.schema.js +60 -8
- package/node_modules/@kardalum/api-schemas/dist/asset-api.schema.js +1 -1
- package/node_modules/@kardalum/api-schemas/dist/content-api.schema.d.ts +5 -0
- package/node_modules/@kardalum/api-schemas/dist/content-api.schema.js +12 -8
- package/node_modules/@kardalum/api-schemas/dist/content-list.schema.js +1 -1
- package/node_modules/@kardalum/api-schemas/dist/content-path.js +11 -7
- package/node_modules/@kardalum/api-schemas/dist/content-trash.schema.d.ts +1 -0
- package/node_modules/@kardalum/api-schemas/dist/core-actions.d.ts +107 -57
- package/node_modules/@kardalum/api-schemas/dist/core-actions.js +96 -60
- package/node_modules/@kardalum/api-schemas/dist/data-type-api.schema.d.ts +1 -0
- package/node_modules/@kardalum/api-schemas/dist/document-type-api.schema.d.ts +2 -0
- package/node_modules/@kardalum/api-schemas/dist/document-type-api.schema.js +1 -1
- package/node_modules/@kardalum/api-schemas/dist/index.d.ts +39 -28
- package/node_modules/@kardalum/api-schemas/dist/index.js +19 -13
- package/node_modules/@kardalum/api-schemas/dist/management-multipart.schema.d.ts +73 -0
- package/node_modules/@kardalum/api-schemas/dist/management-multipart.schema.js +104 -0
- package/node_modules/@kardalum/api-schemas/dist/marketplace-listing-api.schema.d.ts +302 -1
- package/node_modules/@kardalum/api-schemas/dist/marketplace-listing-api.schema.js +78 -6
- package/node_modules/@kardalum/api-schemas/dist/media-api.schema.d.ts +10 -0
- package/node_modules/@kardalum/api-schemas/dist/media-api.schema.js +38 -30
- package/node_modules/@kardalum/api-schemas/dist/media-rendition.schema.js +2 -2
- package/node_modules/@kardalum/api-schemas/dist/media.schema.js +1 -1
- package/node_modules/@kardalum/api-schemas/dist/plugin-docs-api.schema.d.ts +82 -2
- package/node_modules/@kardalum/api-schemas/dist/plugin-docs-api.schema.js +4 -0
- package/node_modules/@kardalum/api-schemas/dist/plugin-docs.d.ts +88 -5
- package/node_modules/@kardalum/api-schemas/dist/plugin-docs.js +79 -17
- package/node_modules/@kardalum/api-schemas/dist/plugin-install-record.schema.d.ts +69 -0
- package/node_modules/@kardalum/api-schemas/dist/plugin-install-record.schema.js +59 -0
- package/node_modules/@kardalum/api-schemas/dist/plugin-install.d.ts +585 -0
- package/node_modules/@kardalum/api-schemas/dist/plugin-install.js +536 -0
- package/node_modules/@kardalum/api-schemas/dist/plugin-locales.d.ts +75 -0
- package/node_modules/@kardalum/api-schemas/dist/plugin-locales.js +213 -0
- package/node_modules/@kardalum/api-schemas/dist/plugin-management-api.schema.d.ts +25 -3
- package/node_modules/@kardalum/api-schemas/dist/plugin-management-api.schema.js +21 -1
- package/node_modules/@kardalum/api-schemas/dist/plugin-manifest-actions.d.ts +7 -0
- package/node_modules/@kardalum/api-schemas/dist/plugin-manifest-actions.js +16 -3
- package/node_modules/@kardalum/api-schemas/dist/plugin-manifest-api-routes.d.ts +44 -0
- package/node_modules/@kardalum/api-schemas/dist/plugin-manifest-api-routes.js +162 -0
- package/node_modules/@kardalum/api-schemas/dist/public-api.schema.d.ts +8 -0
- package/node_modules/@kardalum/api-schemas/dist/public-api.schema.js +11 -1
- package/node_modules/@kardalum/api-schemas/dist/render-editing.d.ts +4 -4
- package/node_modules/@kardalum/api-schemas/dist/role.schema.d.ts +6 -0
- package/node_modules/@kardalum/api-schemas/dist/role.schema.js +6 -0
- package/node_modules/@kardalum/api-schemas/dist/sample-content.schema.d.ts +35 -0
- package/node_modules/@kardalum/api-schemas/dist/sample-content.schema.js +79 -0
- package/node_modules/@kardalum/api-schemas/dist/setup-api.schema.d.ts +36 -6
- package/node_modules/@kardalum/api-schemas/dist/setup-api.schema.js +17 -5
- package/node_modules/@kardalum/api-schemas/dist/sites.schema.d.ts +8 -8
- package/node_modules/@kardalum/api-schemas/dist/sites.schema.js +8 -8
- package/node_modules/@kardalum/api-schemas/dist/snapshot-api.schema.d.ts +4 -0
- package/node_modules/@kardalum/api-schemas/dist/snapshot-api.schema.js +2 -0
- package/node_modules/@kardalum/api-schemas/dist/template-api.schema.js +4 -4
- package/node_modules/@kardalum/api-schemas/dist/user-api.schema.d.ts +11 -3
- package/node_modules/@kardalum/api-schemas/dist/user-api.schema.js +5 -0
- package/node_modules/@kardalum/plugin-package/dist/build-reference.d.ts +111 -0
- package/node_modules/@kardalum/plugin-package/dist/build-reference.js +61 -0
- package/node_modules/@kardalum/plugin-package/dist/capabilities.d.ts +103 -0
- package/node_modules/@kardalum/plugin-package/dist/capabilities.js +351 -0
- package/node_modules/@kardalum/plugin-package/dist/index.d.ts +3 -1
- package/node_modules/@kardalum/plugin-package/dist/index.js +2 -1
- package/node_modules/@kardalum/plugin-package/dist/reference-entry.d.ts +2 -0
- package/node_modules/@kardalum/plugin-package/dist/reference-entry.js +6 -0
- package/node_modules/@kardalum/plugin-package/dist/sample-content.d.ts +20 -1
- package/node_modules/@kardalum/plugin-package/dist/sample-content.js +56 -16
- package/node_modules/@kardalum/plugin-package/dist/types.d.ts +4 -6
- package/node_modules/@kardalum/plugin-package/dist/types.js +15 -1
- package/node_modules/@kardalum/plugin-package/package.json +5 -0
- package/node_modules/@kardalum/ui/dist/components/checkbox.js +2 -2
- package/node_modules/@kardalum/ui/dist/components/property-field.js +4 -1
- package/package.json +2 -2
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { CultureSchema } from "./content-api.schema.js";
|
|
3
|
+
// S290: a plugin's own strings, shipped as locales/<language>.json in its
|
|
4
|
+
// package and registered by the admin under the plugin's id. One file is a
|
|
5
|
+
// flat map from a key the plugin's code passes to t to the text. The rules
|
|
6
|
+
// live here once: the CLI's `locales` check applies them at the author's
|
|
7
|
+
// desk, and the admin's loader applies them again to every file it fetches,
|
|
8
|
+
// because on an installed site a package is untrusted input. Every value is
|
|
9
|
+
// shown as text, never as markup.
|
|
10
|
+
/** The largest locale file a plugin may ship, in UTF-8 bytes. */
|
|
11
|
+
export const PLUGIN_LOCALE_MAX_BYTES = 128 * 1024;
|
|
12
|
+
/** The most keys one locale file may hold. */
|
|
13
|
+
export const PLUGIN_LOCALE_MAX_KEYS = 2000;
|
|
14
|
+
export const PLUGIN_LOCALE_KEY_MAX_LENGTH = 128;
|
|
15
|
+
export const PLUGIN_LOCALE_VALUE_MAX_LENGTH = 4000;
|
|
16
|
+
/** How a refused key is explained, in the schema and in describeIssue. */
|
|
17
|
+
const KEY_RULE = "a key is 1 to 128 letters, digits, _ or -, in segments joined by dots";
|
|
18
|
+
const FORBIDDEN_KEY_SEGMENTS = new Set(["__proto__", "prototype", "constructor"]);
|
|
19
|
+
function isKeyCharacter(code) {
|
|
20
|
+
return (code >= 48 && code <= 57) || (code >= 65 && code <= 90) || (code >= 97 && code <= 122) || code === 95 || code === 45;
|
|
21
|
+
}
|
|
22
|
+
/** A key: 1 to 128 characters, dot-separated segments of ASCII letters,
|
|
23
|
+
* digits, "_" and "-", no empty segment, no segment named __proto__,
|
|
24
|
+
* prototype or constructor. One linear scan, never a regex: the key is
|
|
25
|
+
* untrusted, and the length cap is checked first. */
|
|
26
|
+
export function isPluginLocaleKey(key) {
|
|
27
|
+
if (key.length === 0 || key.length > PLUGIN_LOCALE_KEY_MAX_LENGTH)
|
|
28
|
+
return false;
|
|
29
|
+
let segmentStart = 0;
|
|
30
|
+
for (let index = 0; index <= key.length; index++) {
|
|
31
|
+
if (index === key.length || key.charCodeAt(index) === 46) {
|
|
32
|
+
if (index === segmentStart)
|
|
33
|
+
return false;
|
|
34
|
+
if (FORBIDDEN_KEY_SEGMENTS.has(key.slice(segmentStart, index)))
|
|
35
|
+
return false;
|
|
36
|
+
segmentStart = index + 1;
|
|
37
|
+
}
|
|
38
|
+
else if (!isKeyCharacter(key.charCodeAt(index))) {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
export const PluginLocaleFileSchema = z
|
|
45
|
+
.record(z.string().refine(isPluginLocaleKey, { message: KEY_RULE }), z.string().max(PLUGIN_LOCALE_VALUE_MAX_LENGTH, { message: `a value is at most ${PLUGIN_LOCALE_VALUE_MAX_LENGTH} characters` }))
|
|
46
|
+
.refine((bundle) => Object.keys(bundle).length <= PLUGIN_LOCALE_MAX_KEYS, {
|
|
47
|
+
message: `a locale file holds at most ${PLUGIN_LOCALE_MAX_KEYS} keys`,
|
|
48
|
+
});
|
|
49
|
+
/** The language a file name declares ("de.json" is "de"), or null for any
|
|
50
|
+
* name that is not <language>.json with a language CultureSchema accepts. */
|
|
51
|
+
export function pluginLocaleFileLanguage(fileName) {
|
|
52
|
+
if (fileName.length > 40 || !fileName.endsWith(".json"))
|
|
53
|
+
return null;
|
|
54
|
+
const language = fileName.slice(0, -".json".length);
|
|
55
|
+
return CultureSchema.safeParse(language).success ? language : null;
|
|
56
|
+
}
|
|
57
|
+
function utf8ByteLength(text) {
|
|
58
|
+
let bytes = 0;
|
|
59
|
+
for (let index = 0; index < text.length; index++) {
|
|
60
|
+
const code = text.charCodeAt(index);
|
|
61
|
+
if (code < 0x80)
|
|
62
|
+
bytes += 1;
|
|
63
|
+
else if (code < 0x800)
|
|
64
|
+
bytes += 2;
|
|
65
|
+
else if (code >= 0xd800 && code <= 0xdbff && index + 1 < text.length) {
|
|
66
|
+
bytes += 4;
|
|
67
|
+
index++;
|
|
68
|
+
}
|
|
69
|
+
else
|
|
70
|
+
bytes += 3;
|
|
71
|
+
}
|
|
72
|
+
return bytes;
|
|
73
|
+
}
|
|
74
|
+
// A key echoed back in an issue is cut short: the file is untrusted and a
|
|
75
|
+
// key can be as long as the file itself.
|
|
76
|
+
const ISSUE_KEY_MAX_LENGTH = 60;
|
|
77
|
+
function quoteKey(key) {
|
|
78
|
+
const text = String(key);
|
|
79
|
+
return text.length > ISSUE_KEY_MAX_LENGTH ? `"${text.slice(0, ISSUE_KEY_MAX_LENGTH)}..."` : `"${text}"`;
|
|
80
|
+
}
|
|
81
|
+
/** Zod 4 reports a record key that fails its schema as one issue with code
|
|
82
|
+
* "invalid_key" and a generic message, so that case is phrased here with
|
|
83
|
+
* the key rule; every other issue keeps its own message after the key it
|
|
84
|
+
* sits under. */
|
|
85
|
+
function describeIssue(issue) {
|
|
86
|
+
if (issue.code === "invalid_key") {
|
|
87
|
+
return issue.path.length > 0 ? `invalid key ${quoteKey(issue.path[0])}: ${KEY_RULE}` : `invalid key: ${KEY_RULE}`;
|
|
88
|
+
}
|
|
89
|
+
const where = issue.path.length > 0 ? `${quoteKey(issue.path[0])}: ` : "";
|
|
90
|
+
return `${where}${issue.message}`;
|
|
91
|
+
}
|
|
92
|
+
/** Size first, then JSON.parse, then the schema. Never throws; an issue is
|
|
93
|
+
* phrased to follow "locales/<file>: ". */
|
|
94
|
+
export function parsePluginLocaleFile(text) {
|
|
95
|
+
const bytes = text.length > PLUGIN_LOCALE_MAX_BYTES ? text.length : utf8ByteLength(text);
|
|
96
|
+
if (bytes > PLUGIN_LOCALE_MAX_BYTES)
|
|
97
|
+
return { ok: false, issue: `${bytes} bytes, over the ${PLUGIN_LOCALE_MAX_BYTES}-byte limit` };
|
|
98
|
+
let value;
|
|
99
|
+
try {
|
|
100
|
+
value = JSON.parse(text);
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
return { ok: false, issue: "not valid JSON" };
|
|
104
|
+
}
|
|
105
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
106
|
+
return { ok: false, issue: "not a JSON object of key to text" };
|
|
107
|
+
}
|
|
108
|
+
// The keys are scanned here, before the schema, because Zod's record
|
|
109
|
+
// skips a "__proto__" key rather than reporting it, and JSON.parse makes
|
|
110
|
+
// one an own property. The count comes first so an oversized file is not
|
|
111
|
+
// scanned key by key.
|
|
112
|
+
const keys = Object.keys(value);
|
|
113
|
+
if (keys.length > PLUGIN_LOCALE_MAX_KEYS)
|
|
114
|
+
return { ok: false, issue: `a locale file holds at most ${PLUGIN_LOCALE_MAX_KEYS} keys` };
|
|
115
|
+
for (const key of keys) {
|
|
116
|
+
if (!isPluginLocaleKey(key))
|
|
117
|
+
return { ok: false, issue: `invalid key ${quoteKey(key)}: ${KEY_RULE}` };
|
|
118
|
+
}
|
|
119
|
+
const parsed = PluginLocaleFileSchema.safeParse(value);
|
|
120
|
+
if (!parsed.success)
|
|
121
|
+
return { ok: false, issue: describeIssue(parsed.error.issues[0]) };
|
|
122
|
+
return { ok: true, bundle: parsed.data };
|
|
123
|
+
}
|
|
124
|
+
// S291: the comparison between a plugin's English and another language's
|
|
125
|
+
// file. One function for three readers: the CLI's `locale parity` check,
|
|
126
|
+
// the marketplace's language line, and the admin's own locale-parity test,
|
|
127
|
+
// so "complete" means one thing everywhere.
|
|
128
|
+
/** The {{placeholder}} names in a value, trimmed and sorted: the text
|
|
129
|
+
* between each "{{" and the next "}}", duplicates kept. One left-to-right
|
|
130
|
+
* scan with indexOf, never a regex: each search starts where the last one
|
|
131
|
+
* ended, so the work is linear in the value's length. A value from a
|
|
132
|
+
* plugin's file reaches this capped at PLUGIN_LOCALE_VALUE_MAX_LENGTH by
|
|
133
|
+
* parsePluginLocaleFile; the admin's own files are trusted. */
|
|
134
|
+
export function localePlaceholders(text) {
|
|
135
|
+
const names = [];
|
|
136
|
+
let from = 0;
|
|
137
|
+
for (;;) {
|
|
138
|
+
const open = text.indexOf("{{", from);
|
|
139
|
+
if (open === -1)
|
|
140
|
+
break;
|
|
141
|
+
const close = text.indexOf("}}", open + 2);
|
|
142
|
+
if (close === -1)
|
|
143
|
+
break;
|
|
144
|
+
names.push(text.slice(open + 2, close).trim());
|
|
145
|
+
from = close + 2;
|
|
146
|
+
}
|
|
147
|
+
return names.sort();
|
|
148
|
+
}
|
|
149
|
+
function samePlaceholders(a, b) {
|
|
150
|
+
const left = localePlaceholders(a);
|
|
151
|
+
const right = localePlaceholders(b);
|
|
152
|
+
return left.length === right.length && left.every((name, index) => name === right[index]);
|
|
153
|
+
}
|
|
154
|
+
/** Holds one language's flat key-to-text map to the English one. Keys are
|
|
155
|
+
* looked up as own properties only. Plural-suffixed keys (items_one,
|
|
156
|
+
* items_other) are ordinary keys: a plugin's t does no plural selection. */
|
|
157
|
+
export function compareLocaleFiles(en, other) {
|
|
158
|
+
const extra = [];
|
|
159
|
+
const mismatched = [];
|
|
160
|
+
for (const key of Object.keys(other)) {
|
|
161
|
+
if (!Object.hasOwn(en, key)) {
|
|
162
|
+
extra.push(key);
|
|
163
|
+
}
|
|
164
|
+
else if (!samePlaceholders(en[key], other[key])) {
|
|
165
|
+
mismatched.push(key);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
const missing = Object.keys(en).filter((key) => !Object.hasOwn(other, key));
|
|
169
|
+
return { extra, missing, mismatched };
|
|
170
|
+
}
|
|
171
|
+
/** The docs language of a plugin whose manifest names none. */
|
|
172
|
+
export const DEFAULT_DOCS_LANGUAGE = "en";
|
|
173
|
+
/** The longest docsLanguage a manifest may declare. */
|
|
174
|
+
export const DOCS_LANGUAGE_MAX_LENGTH = 35;
|
|
175
|
+
/** A manifest's docsLanguage: at most 35 characters, then a code under the
|
|
176
|
+
* site's culture rule (CultureSchema). One rule for `kardalum plugin
|
|
177
|
+
* validate`, the marketplace's manifest check and the stored languages, so
|
|
178
|
+
* a value one of them accepts is never stored as something else. The
|
|
179
|
+
* length is checked first, before the pattern sees the value. */
|
|
180
|
+
export const DocsLanguageSchema = z
|
|
181
|
+
.string()
|
|
182
|
+
.max(DOCS_LANGUAGE_MAX_LENGTH, { message: `a docs language is at most ${DOCS_LANGUAGE_MAX_LENGTH} characters` })
|
|
183
|
+
.pipe(CultureSchema);
|
|
184
|
+
/** What the marketplace stores on a version about its languages (S291):
|
|
185
|
+
* each UI language the package ships and whether it is complete, and the
|
|
186
|
+
* language its docs are written in. */
|
|
187
|
+
export const PluginLanguagesSchema = z
|
|
188
|
+
.object({
|
|
189
|
+
ui: z.array(z.object({ code: CultureSchema, complete: z.boolean() }).strict()).min(1),
|
|
190
|
+
docs: CultureSchema,
|
|
191
|
+
})
|
|
192
|
+
.strict();
|
|
193
|
+
/** English is always listed first and always complete: it is the fallback,
|
|
194
|
+
* and with no locales/ the plugin's words are in its code. Every other
|
|
195
|
+
* language follows by code, complete when it lacks none of en.json's keys
|
|
196
|
+
* (extra keys and placeholder drift are author errors `validate` fails,
|
|
197
|
+
* not missing words). With no readable en.json there is nothing to compare,
|
|
198
|
+
* so no other language is complete. `docs` is a language code the caller
|
|
199
|
+
* has already checked. */
|
|
200
|
+
export function summarizePluginLanguages(bundles, docs) {
|
|
201
|
+
const en = bundles.get("en");
|
|
202
|
+
const others = [...bundles.keys()].filter((code) => code !== "en").sort();
|
|
203
|
+
return {
|
|
204
|
+
ui: [
|
|
205
|
+
{ code: "en", complete: true },
|
|
206
|
+
...others.map((code) => ({
|
|
207
|
+
code,
|
|
208
|
+
complete: en !== undefined && compareLocaleFiles(en, bundles.get(code)).missing.length === 0,
|
|
209
|
+
})),
|
|
210
|
+
],
|
|
211
|
+
docs,
|
|
212
|
+
};
|
|
213
|
+
}
|
|
@@ -27,8 +27,8 @@ export declare const ManagedPluginSchema: z.ZodObject<{
|
|
|
27
27
|
unverified: "unverified";
|
|
28
28
|
}>;
|
|
29
29
|
storageType: z.ZodEnum<{
|
|
30
|
-
simple: "simple";
|
|
31
30
|
structured: "structured";
|
|
31
|
+
simple: "simple";
|
|
32
32
|
}>;
|
|
33
33
|
enabled: z.ZodBoolean;
|
|
34
34
|
licenseStatus: z.ZodNullable<z.ZodString>;
|
|
@@ -53,6 +53,9 @@ export declare const ManagedPluginSchema: z.ZodObject<{
|
|
|
53
53
|
created: z.ZodBoolean;
|
|
54
54
|
}, z.core.$strip>>;
|
|
55
55
|
grantedRoleCount: z.ZodNumber;
|
|
56
|
+
updateAvailable: z.ZodNullable<z.ZodObject<{
|
|
57
|
+
version: z.ZodString;
|
|
58
|
+
}, z.core.$strip>>;
|
|
56
59
|
}, z.core.$strip>;
|
|
57
60
|
export type ManagedPlugin = z.infer<typeof ManagedPluginSchema>;
|
|
58
61
|
export declare const ManagedPluginListQuerySchema: z.ZodObject<{
|
|
@@ -70,8 +73,8 @@ export declare const ManagedPluginListResponseSchema: z.ZodObject<{
|
|
|
70
73
|
unverified: "unverified";
|
|
71
74
|
}>;
|
|
72
75
|
storageType: z.ZodEnum<{
|
|
73
|
-
simple: "simple";
|
|
74
76
|
structured: "structured";
|
|
77
|
+
simple: "simple";
|
|
75
78
|
}>;
|
|
76
79
|
enabled: z.ZodBoolean;
|
|
77
80
|
licenseStatus: z.ZodNullable<z.ZodString>;
|
|
@@ -96,6 +99,9 @@ export declare const ManagedPluginListResponseSchema: z.ZodObject<{
|
|
|
96
99
|
created: z.ZodBoolean;
|
|
97
100
|
}, z.core.$strip>>;
|
|
98
101
|
grantedRoleCount: z.ZodNumber;
|
|
102
|
+
updateAvailable: z.ZodNullable<z.ZodObject<{
|
|
103
|
+
version: z.ZodString;
|
|
104
|
+
}, z.core.$strip>>;
|
|
99
105
|
}, z.core.$strip>>;
|
|
100
106
|
nextCursor: z.ZodNullable<z.ZodString>;
|
|
101
107
|
licenseGraceDays: z.ZodNumber;
|
|
@@ -106,7 +112,9 @@ export declare const PluginIdParamsSchema: z.ZodObject<{
|
|
|
106
112
|
}, z.core.$strip>;
|
|
107
113
|
export declare const UninstallPluginBodySchema: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
108
114
|
confirmStructuredDataCleanup: z.ZodOptional<z.ZodBoolean>;
|
|
109
|
-
|
|
115
|
+
removeSampleContent: z.ZodOptional<z.ZodBoolean>;
|
|
116
|
+
removeRoles: z.ZodOptional<z.ZodBoolean>;
|
|
117
|
+
}, z.core.$strict>>>;
|
|
110
118
|
export declare const UninstallConfirmationRequiredSchema: z.ZodObject<{
|
|
111
119
|
requiresConfirmation: z.ZodLiteral<true>;
|
|
112
120
|
snapshotGroupId: z.ZodString;
|
|
@@ -339,6 +347,14 @@ export declare const PluginUploadResponseSchema: z.ZodObject<{
|
|
|
339
347
|
status: z.ZodLiteral<"added">;
|
|
340
348
|
count: z.ZodNumber;
|
|
341
349
|
}, z.core.$strip>], "status">>;
|
|
350
|
+
roles: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
351
|
+
id: z.ZodString;
|
|
352
|
+
outcome: z.ZodEnum<{
|
|
353
|
+
created: "created";
|
|
354
|
+
"already-exists": "already-exists";
|
|
355
|
+
failed: "failed";
|
|
356
|
+
}>;
|
|
357
|
+
}, z.core.$strip>>>;
|
|
342
358
|
}, z.core.$strip>;
|
|
343
359
|
export type PluginUploadResponse = z.infer<typeof PluginUploadResponseSchema>;
|
|
344
360
|
/** S274c: the upload's confirmation travels as a query flag because the
|
|
@@ -367,3 +383,9 @@ export declare const TrustDowngradeConfirmationSchema: z.ZodObject<{
|
|
|
367
383
|
message: z.ZodString;
|
|
368
384
|
}, z.core.$strip>;
|
|
369
385
|
export type TrustDowngradeConfirmation = z.infer<typeof TrustDowngradeConfirmationSchema>;
|
|
386
|
+
export type ManagedPluginListQuery = z.infer<typeof ManagedPluginListQuerySchema>;
|
|
387
|
+
/** The uninstall body as a caller writes it: the object, without the null and undefined the route also accepts. */
|
|
388
|
+
export type UninstallPluginBody = NonNullable<z.infer<typeof UninstallPluginBodySchema>>;
|
|
389
|
+
export type SnapshotGroupListQuery = z.infer<typeof SnapshotGroupListQuerySchema>;
|
|
390
|
+
/** The restore body as a caller writes it: the object, without the null and undefined the route also accepts. */
|
|
391
|
+
export type RestoreBody = NonNullable<z.infer<typeof RestoreBodySchema>>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { PluginRoleOfferSchema } from "./plugin-actions.schema.js";
|
|
3
|
+
import { InstallRoleOutcomeSchema } from "./plugin-install-record.schema.js";
|
|
3
4
|
import { SampleContentOutcomeSchema } from "./sample-content-outcome.schema.js";
|
|
4
5
|
// The ADMIN management view of the registry (S135): unlike the public
|
|
5
6
|
// GET /api/plugins (enabled-only, boot-loader metadata), this surface
|
|
@@ -91,6 +92,15 @@ export const ManagedPluginSchema = z.object({
|
|
|
91
92
|
// S274c: distinct roles holding any of this plugin's actions, for the
|
|
92
93
|
// uninstall dialog.
|
|
93
94
|
grantedRoleCount: z.number().int().nonnegative(),
|
|
95
|
+
// S294 (2026-10-14-s294-update-available-design.md 3.6): the newer version
|
|
96
|
+
// the marketplace has for this plugin and this site can take
|
|
97
|
+
// (updateAvailableFor, the detail view's Update rule), or null: no such
|
|
98
|
+
// version, no listing, a bundle, no marketplace configured, or a
|
|
99
|
+
// marketplace that cannot be reached when nothing was learned from it
|
|
100
|
+
// before (a cold cache). The lookup fails open: a version learned earlier
|
|
101
|
+
// is served through a failure and its backoff, and while a lookup slower
|
|
102
|
+
// than the list's two-second wait runs.
|
|
103
|
+
updateAvailable: z.object({ version: z.string() }).nullable(),
|
|
94
104
|
});
|
|
95
105
|
export const ManagedPluginListQuerySchema = z.object({
|
|
96
106
|
cursor: z.string().uuid().optional(),
|
|
@@ -115,7 +125,14 @@ export const PluginIdParamsSchema = z.object({
|
|
|
115
125
|
export const UninstallPluginBodySchema = z
|
|
116
126
|
.object({
|
|
117
127
|
confirmStructuredDataCleanup: z.boolean().optional(),
|
|
128
|
+
// S293: the uninstall mirror; absent means true, and each only acts on
|
|
129
|
+
// what the install record holds.
|
|
130
|
+
removeSampleContent: z.boolean().optional(),
|
|
131
|
+
removeRoles: z.boolean().optional(),
|
|
118
132
|
})
|
|
133
|
+
// S293: strict, because an absent flag means true: a misspelt opt-out
|
|
134
|
+
// dropped as an unknown key would be read as consent to remove.
|
|
135
|
+
.strict()
|
|
119
136
|
.nullish();
|
|
120
137
|
// 409 payload when a structured plugin's uninstall needs confirmation —
|
|
121
138
|
// the snapshot has ALREADY been taken (S87's safe-to-retry design).
|
|
@@ -335,7 +352,7 @@ export const RestoreBodySchema = z
|
|
|
335
352
|
planHash: z.string().optional(),
|
|
336
353
|
})
|
|
337
354
|
.nullish();
|
|
338
|
-
// The second install door (Task 4): POST /api/plugins/upload lands an
|
|
355
|
+
// The second install door (Task 4): POST /api/manage/v1/plugins/upload lands an
|
|
339
356
|
// admin-uploaded .zip through the same installPackageArchive spine the
|
|
340
357
|
// marketplace uses, but with no marketplace signature to check — trust is
|
|
341
358
|
// always the literal "unregistered" here, never the registry's own
|
|
@@ -369,6 +386,9 @@ export const PluginUploadResponseSchema = z.object({
|
|
|
369
386
|
// S277e: what the install did with the package's sample content. Absent
|
|
370
387
|
// for an update and for a package that ships none.
|
|
371
388
|
sampleContent: SampleContentOutcomeSchema.optional(),
|
|
389
|
+
// S293: what the install did with each offered role its answers named;
|
|
390
|
+
// absent when they named none.
|
|
391
|
+
roles: z.array(InstallRoleOutcomeSchema).optional(),
|
|
372
392
|
});
|
|
373
393
|
/** S274c: the upload's confirmation travels as a query flag because the
|
|
374
394
|
* route reads only the multipart file part. */
|
|
@@ -2,6 +2,13 @@
|
|
|
2
2
|
* these on its CONTRIBUTION_RULES table; its test pins that table to this
|
|
3
3
|
* list, so the two cannot drift apart silently. */
|
|
4
4
|
export declare const ACTION_GATED_CONTRIBUTION_KEYS: readonly ["adminSections", "railEntries", "dashboardWidgets", "settingsPages", "contentTreeActions", "editorToolbar", "apiRoutes"];
|
|
5
|
+
/** S293 (S283's decision, 2026-10-13-s293-the-wizard-installed-design.md 3.9):
|
|
6
|
+
* the built-in rights an offered role may grant beside the plugin's own
|
|
7
|
+
* actions: the read right of each built-in section a rail entry may join
|
|
8
|
+
* (the SDK's BUILT_IN_RAIL_SECTIONS; its test pins the two together), so an
|
|
9
|
+
* accepted offer can open the section its plugin's screen sits in. A write
|
|
10
|
+
* right is never offerable. */
|
|
11
|
+
export declare const OFFERABLE_BUILT_IN_ACTIONS: readonly ["content.read", "media.read", "settings.read", "users.read"];
|
|
5
12
|
export interface ActionDeclarationIssue {
|
|
6
13
|
path: (string | number)[];
|
|
7
14
|
message: string;
|
|
@@ -5,11 +5,21 @@ import { isPluginActionFor } from "./action.schema.js";
|
|
|
5
5
|
// declared id in the plugin's namespace; the declared set equals the set the
|
|
6
6
|
// gated contributions reference (every gated kind, every entry, any route
|
|
7
7
|
// access); no two ids equal case-insensitively; each offer's actions a
|
|
8
|
-
// subset of the declared ids; no two offers
|
|
8
|
+
// subset of the declared ids and OFFERABLE_BUILT_IN_ACTIONS; no two offers
|
|
9
|
+
// sharing an id.
|
|
9
10
|
/** The contribution kinds that sit behind a named action. The SDK classifies
|
|
10
11
|
* these on its CONTRIBUTION_RULES table; its test pins that table to this
|
|
11
12
|
* list, so the two cannot drift apart silently. */
|
|
12
13
|
export const ACTION_GATED_CONTRIBUTION_KEYS = ["adminSections", "railEntries", "dashboardWidgets", "settingsPages", "contentTreeActions", "editorToolbar", "apiRoutes"];
|
|
14
|
+
/** S293 (S283's decision, 2026-10-13-s293-the-wizard-installed-design.md 3.9):
|
|
15
|
+
* the built-in rights an offered role may grant beside the plugin's own
|
|
16
|
+
* actions: the read right of each built-in section a rail entry may join
|
|
17
|
+
* (the SDK's BUILT_IN_RAIL_SECTIONS; its test pins the two together), so an
|
|
18
|
+
* accepted offer can open the section its plugin's screen sits in. A write
|
|
19
|
+
* right is never offerable. */
|
|
20
|
+
export const OFFERABLE_BUILT_IN_ACTIONS = ["content.read", "media.read", "settings.read", "users.read"];
|
|
21
|
+
const OFFERABLE = new Set(OFFERABLE_BUILT_IN_ACTIONS);
|
|
22
|
+
const OFFERABLE_LIST = `${OFFERABLE_BUILT_IN_ACTIONS.slice(0, -1).map((action) => `"${action}"`).join(", ")} or "${OFFERABLE_BUILT_IN_ACTIONS[OFFERABLE_BUILT_IN_ACTIONS.length - 1]}"`;
|
|
13
23
|
function referencedActions(contributions) {
|
|
14
24
|
const referenced = new Set();
|
|
15
25
|
if (!contributions || typeof contributions !== "object")
|
|
@@ -78,8 +88,11 @@ export function checkActionDeclarations(manifest) {
|
|
|
78
88
|
}
|
|
79
89
|
offerIds.add(offer.id);
|
|
80
90
|
offer.actions.forEach((action, actionIndex) => {
|
|
81
|
-
if (!declaredIds.has(action)) {
|
|
82
|
-
issues.push({
|
|
91
|
+
if (!declaredIds.has(action) && !OFFERABLE.has(action)) {
|
|
92
|
+
issues.push({
|
|
93
|
+
path: ["roles", index, "actions", actionIndex],
|
|
94
|
+
message: `role offer "${offer.id}" grants "${action}", which this plugin does not declare; beside its own actions an offer may grant only ${OFFERABLE_LIST}`,
|
|
95
|
+
});
|
|
83
96
|
}
|
|
84
97
|
});
|
|
85
98
|
});
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/** The methods an apiRoute may declare: the one list the SDK's manifest schema
|
|
2
|
+
* enforces (and the manual's enum test reads, through the SDK's re-export)
|
|
3
|
+
* and the only methods this rule compares. */
|
|
4
|
+
export declare const API_ROUTE_METHODS: readonly ["GET", "POST", "PUT", "PATCH", "DELETE"];
|
|
5
|
+
/** S297: a route's `schema.response` declares success statuses only, "200" to "299", at most this many. */
|
|
6
|
+
export declare const API_ROUTE_RESPONSE_STATUSES_MAX = 4;
|
|
7
|
+
/** True for a success status code written canonically as a string: "200" to "299". Linear, no pattern. */
|
|
8
|
+
export declare function isApiRouteResponseStatus(key: string): boolean;
|
|
9
|
+
/** The longest declared path, checked before the path is split. */
|
|
10
|
+
export declare const API_ROUTE_PATH_MAX = 200;
|
|
11
|
+
/** The most apiRoutes one manifest declares, which bounds the pairwise check. */
|
|
12
|
+
export declare const API_ROUTES_MAX = 200;
|
|
13
|
+
export interface ApiRouteDeclarationIssue {
|
|
14
|
+
path: (string | number)[];
|
|
15
|
+
message: string;
|
|
16
|
+
}
|
|
17
|
+
/** Why `path` cannot be a declared apiRoute path, or null when it can be. */
|
|
18
|
+
export declare function apiRoutePathProblem(path: string): string | null;
|
|
19
|
+
/** A manifest's apiRoutes, checked as the router will read them, with every
|
|
20
|
+
* issue rooted at the manifest: each path by apiRoutePathProblem; then, among
|
|
21
|
+
* the declarations whose path passed, a GET or PUT the host's storage route
|
|
22
|
+
* answers first, and the first earlier declaration of the same method that
|
|
23
|
+
* the router reads as the same route (a duplicate, reported in preference)
|
|
24
|
+
* or that one request can match too (ambiguous). An entry whose method is
|
|
25
|
+
* not one of API_ROUTE_METHODS, or whose path is not a string, is the
|
|
26
|
+
* schema's to report and is skipped here: the marketplace door runs this on
|
|
27
|
+
* a manifest.json its own schema leaves unvalidated, and a method that is
|
|
28
|
+
* any string must cost no comparison and appear in no message. */
|
|
29
|
+
export declare function checkApiRouteDeclarations(manifest: {
|
|
30
|
+
contributions?: unknown;
|
|
31
|
+
}): ApiRouteDeclarationIssue[];
|
|
32
|
+
/** S299 (2026-10-15-s299-tokens-that-carry-actions-design.md D15): every apiRoute
|
|
33
|
+
* that needs a credential names the action its caller must hold: a session's
|
|
34
|
+
* role on the admin tier (the default, and the tier of any value this code does
|
|
35
|
+
* not recognise, as effectiveAccess reads it) and an API key on the "apiKey"
|
|
36
|
+
* tier. Only a "public" route, which needs no credential, may omit it. One
|
|
37
|
+
* function, so the SDK's manifest schema (and through it install, upload, the
|
|
38
|
+
* boot loader and `kardalum plugin validate`) and the marketplace door cannot
|
|
39
|
+
* disagree. An entry that is not an object is the schema's to report and is
|
|
40
|
+
* skipped; the pairwise comparison checkApiRouteDeclarations runs is not
|
|
41
|
+
* needed, so a manifest past API_ROUTES_MAX is that function's to report. */
|
|
42
|
+
export declare function checkApiRouteActions(manifest: {
|
|
43
|
+
contributions?: unknown;
|
|
44
|
+
}): ApiRouteDeclarationIssue[];
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
// S295 (2026-10-14-s295-routes-fastify-knows-about-design.md 3.1): the rule for
|
|
2
|
+
// what a plugin may declare as an apiRoute's address, as plain data, so the
|
|
3
|
+
// SDK's manifest schema (and through it `kardalum plugin validate`), the
|
|
4
|
+
// marketplace's submission gate and the server's route table read one rule.
|
|
5
|
+
// The server routes plugin routes through find-my-way, Fastify's own router;
|
|
6
|
+
// this admits the part of its syntax a plugin needs (static segments and
|
|
7
|
+
// ":name" parameters) and refuses, within one manifest, what that router would
|
|
8
|
+
// read as one route or match by its own precedence.
|
|
9
|
+
/** The methods an apiRoute may declare: the one list the SDK's manifest schema
|
|
10
|
+
* enforces (and the manual's enum test reads, through the SDK's re-export)
|
|
11
|
+
* and the only methods this rule compares. */
|
|
12
|
+
export const API_ROUTE_METHODS = ["GET", "POST", "PUT", "PATCH", "DELETE"];
|
|
13
|
+
/** S297: a route's `schema.response` declares success statuses only, "200" to "299", at most this many. */
|
|
14
|
+
export const API_ROUTE_RESPONSE_STATUSES_MAX = 4;
|
|
15
|
+
/** True for a success status code written canonically as a string: "200" to "299". Linear, no pattern. */
|
|
16
|
+
export function isApiRouteResponseStatus(key) {
|
|
17
|
+
const status = Number(key);
|
|
18
|
+
return Number.isInteger(status) && status >= 200 && status <= 299 && String(status) === key;
|
|
19
|
+
}
|
|
20
|
+
/** The longest declared path, checked before the path is split. */
|
|
21
|
+
export const API_ROUTE_PATH_MAX = 200;
|
|
22
|
+
/** The most apiRoutes one manifest declares, which bounds the pairwise check. */
|
|
23
|
+
export const API_ROUTES_MAX = 200;
|
|
24
|
+
// A string of another length fails each of the five comparisons on its length
|
|
25
|
+
// alone, so a hostile method costs five length checks and nothing more.
|
|
26
|
+
const isApiRouteMethod = (value) => typeof value === "string" && API_ROUTE_METHODS.includes(value);
|
|
27
|
+
// Fixed, anchored, one character class each, so linear on any input. A
|
|
28
|
+
// parameter's name starts with a letter and holds no "-" or ".", which the
|
|
29
|
+
// router reads as the start of a static part inside a parameter segment.
|
|
30
|
+
const STATIC_SEGMENT = /^[A-Za-z0-9_-]+$/;
|
|
31
|
+
const PARAM_SEGMENT = /^:[A-Za-z][A-Za-z0-9_]*$/;
|
|
32
|
+
// The host's plugin storage route owns GET and PUT
|
|
33
|
+
// /api/plugins/:pluginId/storage/:contentId/:fieldId (the server's
|
|
34
|
+
// routes/plugin-storage.ts), and the router tries its static "storage" first.
|
|
35
|
+
const STORAGE_ROUTE_METHODS = new Set(["GET", "PUT"]);
|
|
36
|
+
/** Why `path` cannot be a declared apiRoute path, or null when it can be. */
|
|
37
|
+
export function apiRoutePathProblem(path) {
|
|
38
|
+
if (!path.startsWith("/"))
|
|
39
|
+
return 'path must start with "/"';
|
|
40
|
+
if (path.length > API_ROUTE_PATH_MAX)
|
|
41
|
+
return `path must be at most ${API_ROUTE_PATH_MAX} characters`;
|
|
42
|
+
if (path === "/")
|
|
43
|
+
return 'path must name at least one segment after "/"';
|
|
44
|
+
const names = new Set();
|
|
45
|
+
for (const segment of path.slice(1).split("/")) {
|
|
46
|
+
if (segment === "")
|
|
47
|
+
return `path "${path}" has an empty segment: one "/" between segments, and none at the end`;
|
|
48
|
+
if (PARAM_SEGMENT.test(segment)) {
|
|
49
|
+
const name = segment.slice(1);
|
|
50
|
+
if (names.has(name))
|
|
51
|
+
return `path "${path}" names the parameter ":${name}" twice`;
|
|
52
|
+
names.add(name);
|
|
53
|
+
}
|
|
54
|
+
else if (!STATIC_SEGMENT.test(segment)) {
|
|
55
|
+
return `path segment "${segment}" must be letters, digits, "-" and "_", or a parameter ":name" whose name is a letter followed by letters, digits or "_"`;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
const isParam = (segment) => segment.startsWith(":");
|
|
61
|
+
/** One request path reaches both: as many segments, and at every place the
|
|
62
|
+
* same static segment or a parameter on either side. A static segment over
|
|
63
|
+
* 100 characters beside a parameter counts too, although no request reaches
|
|
64
|
+
* both: the router matches a parameter of at most 100 characters (the limit
|
|
65
|
+
* the manual states), and this rule refuses the pair without modelling it. */
|
|
66
|
+
function overlaps(a, b) {
|
|
67
|
+
return a.length === b.length && a.every((x, at) => { const y = b[at]; return x === y || isParam(x) || isParam(y); });
|
|
68
|
+
}
|
|
69
|
+
/** The router reads the two as one route: the same, a parameter's name aside. */
|
|
70
|
+
function sameRoute(a, b) {
|
|
71
|
+
return a.length === b.length && a.every((x, at) => { const y = b[at]; return x === y || (isParam(x) && isParam(y)); });
|
|
72
|
+
}
|
|
73
|
+
/** A manifest's apiRoutes, checked as the router will read them, with every
|
|
74
|
+
* issue rooted at the manifest: each path by apiRoutePathProblem; then, among
|
|
75
|
+
* the declarations whose path passed, a GET or PUT the host's storage route
|
|
76
|
+
* answers first, and the first earlier declaration of the same method that
|
|
77
|
+
* the router reads as the same route (a duplicate, reported in preference)
|
|
78
|
+
* or that one request can match too (ambiguous). An entry whose method is
|
|
79
|
+
* not one of API_ROUTE_METHODS, or whose path is not a string, is the
|
|
80
|
+
* schema's to report and is skipped here: the marketplace door runs this on
|
|
81
|
+
* a manifest.json its own schema leaves unvalidated, and a method that is
|
|
82
|
+
* any string must cost no comparison and appear in no message. */
|
|
83
|
+
export function checkApiRouteDeclarations(manifest) {
|
|
84
|
+
const contributions = manifest.contributions;
|
|
85
|
+
if (!contributions || typeof contributions !== "object")
|
|
86
|
+
return [];
|
|
87
|
+
const routes = contributions.apiRoutes;
|
|
88
|
+
if (!Array.isArray(routes))
|
|
89
|
+
return [];
|
|
90
|
+
if (routes.length > API_ROUTES_MAX) {
|
|
91
|
+
return [{ path: ["contributions", "apiRoutes"], message: `a plugin declares at most ${API_ROUTES_MAX} apiRoutes` }];
|
|
92
|
+
}
|
|
93
|
+
const issues = [];
|
|
94
|
+
const declared = [];
|
|
95
|
+
routes.forEach((entry, index) => {
|
|
96
|
+
const { method, path } = (entry ?? {});
|
|
97
|
+
if (!isApiRouteMethod(method) || typeof path !== "string")
|
|
98
|
+
return;
|
|
99
|
+
const at = ["contributions", "apiRoutes", index, "path"];
|
|
100
|
+
const problem = apiRoutePathProblem(path);
|
|
101
|
+
if (problem !== null) {
|
|
102
|
+
issues.push({ path: at, message: problem });
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
const segments = path.slice(1).split("/");
|
|
106
|
+
if (STORAGE_ROUTE_METHODS.has(method) && segments.length === 3 && segments[0] === "storage") {
|
|
107
|
+
issues.push({
|
|
108
|
+
path: at,
|
|
109
|
+
message: `apiRoute "${method} ${path}" has the address of the host's plugin storage route (${method} /api/plugins/<plugin id>/storage/<contentId>/<fieldId>), which answers it before this plugin's handler could`,
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
const sameMethod = declared.filter((other) => other.method === method);
|
|
113
|
+
const duplicate = sameMethod.find((other) => sameRoute(other.segments, segments));
|
|
114
|
+
const earlier = duplicate ?? sameMethod.find((other) => overlaps(other.segments, segments));
|
|
115
|
+
if (earlier) {
|
|
116
|
+
const named = `"${method} ${earlier.path}" (apiRoutes.${earlier.index})`;
|
|
117
|
+
issues.push({
|
|
118
|
+
path: at,
|
|
119
|
+
message: duplicate === undefined
|
|
120
|
+
? `Ambiguous apiRoute "${method} ${path}": a request can match both it and ${named}, so the router would choose which one answers, not this manifest`
|
|
121
|
+
: duplicate.path === path
|
|
122
|
+
? `Duplicate apiRoute "${method} ${path}": method+path pairs must be unique within a manifest`
|
|
123
|
+
: `Duplicate apiRoute "${method} ${path}": the router reads it as ${named}, because a parameter's name does not make two paths different`,
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
declared.push({ index, method, path, segments });
|
|
127
|
+
});
|
|
128
|
+
return issues;
|
|
129
|
+
}
|
|
130
|
+
/** S299 (2026-10-15-s299-tokens-that-carry-actions-design.md D15): every apiRoute
|
|
131
|
+
* that needs a credential names the action its caller must hold: a session's
|
|
132
|
+
* role on the admin tier (the default, and the tier of any value this code does
|
|
133
|
+
* not recognise, as effectiveAccess reads it) and an API key on the "apiKey"
|
|
134
|
+
* tier. Only a "public" route, which needs no credential, may omit it. One
|
|
135
|
+
* function, so the SDK's manifest schema (and through it install, upload, the
|
|
136
|
+
* boot loader and `kardalum plugin validate`) and the marketplace door cannot
|
|
137
|
+
* disagree. An entry that is not an object is the schema's to report and is
|
|
138
|
+
* skipped; the pairwise comparison checkApiRouteDeclarations runs is not
|
|
139
|
+
* needed, so a manifest past API_ROUTES_MAX is that function's to report. */
|
|
140
|
+
export function checkApiRouteActions(manifest) {
|
|
141
|
+
const contributions = manifest.contributions;
|
|
142
|
+
if (!contributions || typeof contributions !== "object")
|
|
143
|
+
return [];
|
|
144
|
+
const routes = contributions.apiRoutes;
|
|
145
|
+
if (!Array.isArray(routes) || routes.length > API_ROUTES_MAX)
|
|
146
|
+
return [];
|
|
147
|
+
const issues = [];
|
|
148
|
+
routes.forEach((entry, index) => {
|
|
149
|
+
if (entry === null || typeof entry !== "object")
|
|
150
|
+
return;
|
|
151
|
+
const { access, action } = entry;
|
|
152
|
+
if (access === "public")
|
|
153
|
+
return;
|
|
154
|
+
if (typeof action === "string" && action !== "")
|
|
155
|
+
return;
|
|
156
|
+
issues.push({
|
|
157
|
+
path: ["contributions", "apiRoutes", index, "action"],
|
|
158
|
+
message: 'an admin-tier or apiKey-tier apiRoute must declare an "action" (only a "public" route may omit it)',
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
return issues;
|
|
162
|
+
}
|
|
@@ -280,6 +280,14 @@ export declare const PublicMediaUploadFieldsSchema: z.ZodObject<{
|
|
|
280
280
|
}>>;
|
|
281
281
|
}, z.core.$strict>;
|
|
282
282
|
export type PublicMediaUploadFields = z.infer<typeof PublicMediaUploadFieldsSchema>;
|
|
283
|
+
export declare const PublicMediaUploadBodySchema: z.ZodObject<{
|
|
284
|
+
visibility: z.ZodDefault<z.ZodEnum<{
|
|
285
|
+
public: "public";
|
|
286
|
+
private: "private";
|
|
287
|
+
}>>;
|
|
288
|
+
file: z.ZodFile;
|
|
289
|
+
}, z.core.$strict>;
|
|
290
|
+
export type PublicMediaUploadBody = z.infer<typeof PublicMediaUploadBodySchema>;
|
|
283
291
|
export declare const PublicMediaUpdateRequestSchema: z.ZodObject<{
|
|
284
292
|
visibility: z.ZodEnum<{
|
|
285
293
|
public: "public";
|
|
@@ -32,7 +32,7 @@ export const PublicContentItemSchema = z.object({
|
|
|
32
32
|
});
|
|
33
33
|
// `locale` mirrors the backoffice contract exactly (content-api.schema).
|
|
34
34
|
// `previewToken` (Session 116) is a stateless signed token minted by
|
|
35
|
-
// POST /api/content/:id/preview-token; verified once per request against
|
|
35
|
+
// POST /api/manage/v1/content/:id/preview-token; verified once per request against
|
|
36
36
|
// the FINAL resolved (post-locale) node id — see published-item.ts.
|
|
37
37
|
export const PublicContentItemQuerySchema = z.object({
|
|
38
38
|
// S230: validated as a language tag, identically to the backoffice
|
|
@@ -303,6 +303,16 @@ export const PublicMediaUploadFieldsSchema = z
|
|
|
303
303
|
visibility: MediaVisibilitySchema.default("private"),
|
|
304
304
|
})
|
|
305
305
|
.strict();
|
|
306
|
+
// S297: the whole multipart body of POST /api/v1/media for the OpenAPI document
|
|
307
|
+
// and the reference page: the fields above, then the file part. The route
|
|
308
|
+
// still streams the upload unvalidated and parses its fields with
|
|
309
|
+
// PublicMediaUploadFieldsSchema, so this schema is documentation only. The
|
|
310
|
+
// order is the route's rule: a field sent after the file may not be read.
|
|
311
|
+
export const PublicMediaUploadBodySchema = PublicMediaUploadFieldsSchema.extend({
|
|
312
|
+
file: z
|
|
313
|
+
.file()
|
|
314
|
+
.describe("The file to store. It must come after the visibility field in the multipart body: a field sent after the file may not be read."),
|
|
315
|
+
});
|
|
306
316
|
// PATCH /api/v1/media/:id body. v1 patches visibility only — metadata
|
|
307
317
|
// (filename, custom fields) is a later task, so visibility is required
|
|
308
318
|
// rather than optional: this is the only field there is, and an empty
|