@kardalum/plugin-sdk 0.15.0 → 0.17.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 +49 -1
- package/README.md +10 -0
- package/dist/admin-section-registry.d.ts +14 -5
- package/dist/admin-section-registry.js +14 -4
- 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 -322
- package/dist/host-entry.d.ts +1 -1
- package/dist/host-entry.js +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.js +13 -12
- package/dist/license-verdict-keys.d.ts +4 -3
- package/dist/license-verdict-keys.js +6 -5
- package/dist/manifest-entry.d.ts +3 -3
- package/dist/manifest-entry.js +2 -2
- package/dist/manifest-schema.d.ts +113 -56
- package/dist/manifest-schema.js +192 -295
- package/dist/manifest.d.ts +145 -112
- package/dist/manifest.js +13 -36
- 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 +44 -3
- 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 +6 -6
- package/dist/richtext/insert-menu.js +4 -4
- package/dist/richtext/style-listbox.js +4 -4
- package/dist/tokens/tokens.css +1 -0
- package/dist/tokens/tokens.json +2 -1
- package/dist/type-equality.d.ts +2 -0
- package/dist/type-equality.js +1 -0
- package/dist/views/content-list-view.js +2 -2
- package/dist/views/html-view.js +1 -1
- package/dist/views/image-view.js +24 -39
- package/dist/views/rich-text-view.js +3 -3
- 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.d.ts +90 -0
- package/node_modules/@kardalum/api-schemas/dist/asset-api.schema.js +33 -2
- package/node_modules/@kardalum/api-schemas/dist/asset.schema.d.ts +22 -1
- package/node_modules/@kardalum/api-schemas/dist/asset.schema.js +50 -15
- package/node_modules/@kardalum/api-schemas/dist/audit-api.schema.d.ts +204 -0
- package/node_modules/@kardalum/api-schemas/dist/audit-api.schema.js +134 -0
- 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 +18 -13
- package/node_modules/@kardalum/api-schemas/dist/content-list.schema.d.ts +2 -2
- 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-api.schema.d.ts +4 -0
- package/node_modules/@kardalum/api-schemas/dist/content-trash-api.schema.js +3 -0
- package/node_modules/@kardalum/api-schemas/dist/content-trash.schema.d.ts +1 -0
- package/node_modules/@kardalum/api-schemas/dist/content-trash.schema.js +2 -1
- package/node_modules/@kardalum/api-schemas/dist/core-actions.d.ts +143 -57
- package/node_modules/@kardalum/api-schemas/dist/core-actions.js +110 -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 +67 -40
- package/node_modules/@kardalum/api-schemas/dist/index.js +35 -19
- package/node_modules/@kardalum/api-schemas/dist/install-warnings.schema.d.ts +4 -0
- package/node_modules/@kardalum/api-schemas/dist/install-warnings.schema.js +8 -0
- package/node_modules/@kardalum/api-schemas/dist/issue-list.d.ts +6 -0
- package/node_modules/@kardalum/api-schemas/dist/issue-list.js +6 -0
- 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 +356 -16
- package/node_modules/@kardalum/api-schemas/dist/marketplace-listing-api.schema.js +93 -10
- 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-actions.schema.d.ts +6 -2
- package/node_modules/@kardalum/api-schemas/dist/plugin-actions.schema.js +8 -6
- package/node_modules/@kardalum/api-schemas/dist/plugin-docs-api.schema.d.ts +69 -4
- 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 +76 -9
- package/node_modules/@kardalum/api-schemas/dist/plugin-docs.js +84 -24
- package/node_modules/@kardalum/api-schemas/dist/plugin-id-rules.d.ts +17 -7
- package/node_modules/@kardalum/api-schemas/dist/plugin-id-rules.js +18 -8
- 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 +597 -0
- package/node_modules/@kardalum/api-schemas/dist/plugin-install.js +503 -0
- package/node_modules/@kardalum/api-schemas/dist/plugin-labels.d.ts +60 -0
- package/node_modules/@kardalum/api-schemas/dist/plugin-labels.js +116 -0
- package/node_modules/@kardalum/api-schemas/dist/plugin-locales.d.ts +82 -0
- package/node_modules/@kardalum/api-schemas/dist/plugin-locales.js +228 -0
- package/node_modules/@kardalum/api-schemas/dist/plugin-management-api.schema.d.ts +33 -4
- package/node_modules/@kardalum/api-schemas/dist/plugin-management-api.schema.js +28 -2
- package/node_modules/@kardalum/api-schemas/dist/plugin-manifest-actions.d.ts +11 -3
- package/node_modules/@kardalum/api-schemas/dist/plugin-manifest-actions.js +17 -4
- package/node_modules/@kardalum/api-schemas/dist/plugin-manifest-api-routes.d.ts +58 -0
- package/node_modules/@kardalum/api-schemas/dist/plugin-manifest-api-routes.js +198 -0
- package/node_modules/@kardalum/api-schemas/dist/plugin-manifest-fields.d.ts +64 -0
- package/node_modules/@kardalum/api-schemas/dist/plugin-manifest-fields.js +134 -0
- package/node_modules/@kardalum/api-schemas/dist/plugin-registry-api.schema.d.ts +2 -0
- package/node_modules/@kardalum/api-schemas/dist/plugin-registry-api.schema.js +4 -0
- package/node_modules/@kardalum/api-schemas/dist/plugin-template-payload.d.ts +74 -0
- package/node_modules/@kardalum/api-schemas/dist/plugin-template-payload.js +132 -0
- package/node_modules/@kardalum/api-schemas/dist/plugin-vocabulary.d.ts +13 -0
- package/node_modules/@kardalum/api-schemas/dist/plugin-vocabulary.js +15 -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 +23 -4
- package/node_modules/@kardalum/api-schemas/dist/render-editing.d.ts +4 -4
- package/node_modules/@kardalum/api-schemas/dist/role.schema.d.ts +17 -0
- package/node_modules/@kardalum/api-schemas/dist/role.schema.js +13 -0
- package/node_modules/@kardalum/api-schemas/dist/sample-content.schema.d.ts +44 -0
- package/node_modules/@kardalum/api-schemas/dist/sample-content.schema.js +97 -0
- package/node_modules/@kardalum/api-schemas/dist/sandbox-attach.schema.d.ts +126 -0
- package/node_modules/@kardalum/api-schemas/dist/sandbox-attach.schema.js +70 -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 +52 -33
- package/node_modules/@kardalum/api-schemas/dist/sites.schema.js +195 -56
- package/node_modules/@kardalum/api-schemas/dist/snapshot-api.schema.d.ts +19 -3
- package/node_modules/@kardalum/api-schemas/dist/snapshot-api.schema.js +16 -0
- package/node_modules/@kardalum/api-schemas/dist/snapshot.schema.d.ts +1 -1
- package/node_modules/@kardalum/api-schemas/dist/strict-url.d.ts +12 -0
- package/node_modules/@kardalum/api-schemas/dist/strict-url.js +31 -0
- package/node_modules/@kardalum/api-schemas/dist/template-api.schema.d.ts +105 -1
- package/node_modules/@kardalum/api-schemas/dist/template-api.schema.js +47 -7
- package/node_modules/@kardalum/api-schemas/dist/template.schema.d.ts +30 -2
- package/node_modules/@kardalum/api-schemas/dist/template.schema.js +19 -5
- package/node_modules/@kardalum/api-schemas/dist/trash-cursor.schema.d.ts +4 -0
- package/node_modules/@kardalum/api-schemas/dist/trash-cursor.schema.js +29 -0
- package/node_modules/@kardalum/api-schemas/dist/user-api.schema.d.ts +15 -3
- package/node_modules/@kardalum/api-schemas/dist/user-api.schema.js +8 -0
- package/node_modules/@kardalum/api-schemas/dist/whoami-api.schema.d.ts +19 -0
- package/node_modules/@kardalum/api-schemas/dist/whoami-api.schema.js +22 -0
- package/node_modules/@kardalum/api-schemas/package.json +2 -2
- package/node_modules/@kardalum/design-tokens/dist/tailwind-theme.d.ts +1 -0
- package/node_modules/@kardalum/design-tokens/dist/tailwind-theme.js +2 -0
- package/node_modules/@kardalum/design-tokens/dist/tokens.css +1 -0
- package/node_modules/@kardalum/design-tokens/dist/tokens.js +3 -0
- package/node_modules/@kardalum/design-tokens/dist/tokens.json +2 -1
- package/node_modules/@kardalum/design-tokens/dist/types.d.ts +1 -0
- package/node_modules/@kardalum/plugin-package/README.md +4 -1
- package/node_modules/@kardalum/plugin-package/dist/build-reference.d.ts +96 -0
- package/node_modules/@kardalum/plugin-package/dist/build-reference.js +66 -0
- package/node_modules/@kardalum/plugin-package/dist/capabilities.d.ts +103 -0
- package/node_modules/@kardalum/plugin-package/dist/capabilities.js +346 -0
- package/node_modules/@kardalum/plugin-package/dist/client-bundle.d.ts +4 -0
- package/node_modules/@kardalum/plugin-package/dist/client-bundle.js +25 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/archive-names.d.ts +25 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/archive-names.js +203 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/bundle.d.ts +3 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/bundle.js +73 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/contributions.d.ts +5 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/contributions.js +60 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/icon-names.generated.d.ts +1 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/icon-names.generated.js +2052 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/icons.d.ts +2 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/icons.js +51 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/index.d.ts +8 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/index.js +7 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/label-languages.d.ts +17 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/label-languages.js +119 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/limits.d.ts +14 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/limits.js +21 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/locales.d.ts +5 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/locales.js +148 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/package-files.d.ts +5 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/package-files.js +76 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/registry.d.ts +22 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/registry.js +133 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/sample-content.d.ts +3 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/sample-content.js +90 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/support.d.ts +24 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/support.js +55 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/templates.d.ts +6 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/templates.js +158 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/types.d.ts +53 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/types.js +1 -0
- package/node_modules/@kardalum/plugin-package/dist/docs-contract.d.ts +3 -2
- package/node_modules/@kardalum/plugin-package/dist/docs-contract.js +4 -2
- package/node_modules/@kardalum/plugin-package/dist/extract.d.ts +92 -3
- package/node_modules/@kardalum/plugin-package/dist/extract.js +251 -41
- package/node_modules/@kardalum/plugin-package/dist/index.d.ts +11 -2
- package/node_modules/@kardalum/plugin-package/dist/index.js +8 -2
- package/node_modules/@kardalum/plugin-package/dist/manifest-entry.d.ts +5 -0
- package/node_modules/@kardalum/plugin-package/dist/manifest-entry.js +20 -0
- package/node_modules/@kardalum/plugin-package/dist/reference-entry.d.ts +3 -0
- package/node_modules/@kardalum/plugin-package/dist/reference-entry.js +7 -0
- package/node_modules/@kardalum/plugin-package/dist/sample-content.d.ts +38 -1
- package/node_modules/@kardalum/plugin-package/dist/sample-content.js +84 -16
- package/node_modules/@kardalum/plugin-package/dist/shipped-files.d.ts +39 -0
- package/node_modules/@kardalum/plugin-package/dist/shipped-files.js +133 -0
- package/node_modules/@kardalum/plugin-package/dist/shipped-locales.d.ts +7 -0
- package/node_modules/@kardalum/plugin-package/dist/shipped-locales.js +27 -0
- 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 +9 -2
- package/node_modules/@kardalum/ui/dist/components/checkbox.js +2 -2
- package/node_modules/@kardalum/ui/dist/components/dropdown-menu.js +2 -2
- package/node_modules/@kardalum/ui/dist/components/property-field.js +4 -1
- package/node_modules/@kardalum/ui/package.json +1 -1
- package/package.json +6 -6
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { CultureSchema } from "./content-api.schema.js";
|
|
3
|
+
import { HOSTILE_CHARS_MESSAGE, hasHostileChars } from "./plugin-docs-text.js";
|
|
4
|
+
import { DOCS_LANGUAGE_MAX_LENGTH } from "./plugin-locales.js";
|
|
5
|
+
/** The most languages one label map may carry. */
|
|
6
|
+
export const LABEL_MAX_LANGUAGES = 32;
|
|
7
|
+
/** The longest language code a label map's key may be: the longest a locale
|
|
8
|
+
* file's name can carry (DocsLanguageSchema's bound), checked before the
|
|
9
|
+
* culture pattern ever sees the key. */
|
|
10
|
+
export const LABEL_KEY_MAX_LENGTH = DOCS_LANGUAGE_MAX_LENGTH;
|
|
11
|
+
/** A label map's keys, bounded before the map is read: at most
|
|
12
|
+
* LABEL_MAX_LANGUAGES of them, each at most LABEL_KEY_MAX_LENGTH characters.
|
|
13
|
+
* An issue raised here ends the preprocess's pipe, so the map is not read at
|
|
14
|
+
* all: a map of thousands of keys costs one count, and a key too long to be a
|
|
15
|
+
* language code is never echoed, neither in a message nor in a path (where
|
|
16
|
+
* reading the map would put it, under a text the map refuses). */
|
|
17
|
+
function boundLabelKeys(value, ctx) {
|
|
18
|
+
if (value === null || typeof value !== "object" || Array.isArray(value))
|
|
19
|
+
return value;
|
|
20
|
+
const keys = Object.keys(value);
|
|
21
|
+
if (keys.length > LABEL_MAX_LANGUAGES) {
|
|
22
|
+
ctx.addIssue({ code: "custom", message: `a label holds at most ${LABEL_MAX_LANGUAGES} languages` });
|
|
23
|
+
}
|
|
24
|
+
if (keys.some((key) => key.length > LABEL_KEY_MAX_LENGTH)) {
|
|
25
|
+
ctx.addIssue({ code: "custom", message: `label keys are language codes of at most ${LABEL_KEY_MAX_LENGTH} characters` });
|
|
26
|
+
}
|
|
27
|
+
return value;
|
|
28
|
+
}
|
|
29
|
+
/** One text of a label: never empty or only whitespace (a blank tab or
|
|
30
|
+
* question, and a blank English label is one the generated reference
|
|
31
|
+
* refuses), no control or direction-override character, and at most `max`
|
|
32
|
+
* characters when given. Shown as text, never as markup. */
|
|
33
|
+
export function labelTextSchema({ max, trim = false } = {}) {
|
|
34
|
+
let text = z.string({ error: "must be text" });
|
|
35
|
+
if (trim)
|
|
36
|
+
text = text.trim();
|
|
37
|
+
if (max !== undefined)
|
|
38
|
+
text = text.max(max, { message: `is at most ${max} characters` });
|
|
39
|
+
return text
|
|
40
|
+
.refine((value) => value.trim() !== "", { message: "must not be empty" })
|
|
41
|
+
.refine((value) => !hasHostileChars(value), { message: HOSTILE_CHARS_MESSAGE });
|
|
42
|
+
}
|
|
43
|
+
/** A label map: a language code to the text shown in that language, `en`
|
|
44
|
+
* required because every other language falls back to it. Its keys are
|
|
45
|
+
* bounded first (boundLabelKeys), then each is a language code under the
|
|
46
|
+
* same rule as the site's cultures setting (CultureSchema), so "" or
|
|
47
|
+
* "anything" is refused rather than carried as a language no locale can ever
|
|
48
|
+
* pick; every text follows labelTextSchema with `rule`. */
|
|
49
|
+
export function labelMapSchema(rule = {}) {
|
|
50
|
+
const text = labelTextSchema(rule);
|
|
51
|
+
return z.preprocess(boundLabelKeys, z
|
|
52
|
+
.object({ en: text })
|
|
53
|
+
.catchall(text)
|
|
54
|
+
.superRefine((label, ctx) => {
|
|
55
|
+
for (const key of Object.keys(label)) {
|
|
56
|
+
if (!CultureSchema.safeParse(key).success) {
|
|
57
|
+
ctx.addIssue({
|
|
58
|
+
code: "custom",
|
|
59
|
+
message: `label keys are language codes such as "en", "de" or "pt-BR", not ${JSON.stringify(key)}`,
|
|
60
|
+
path: [key],
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}));
|
|
65
|
+
}
|
|
66
|
+
/** A section's or a rail entry's label (S280): the map rule, at any length. */
|
|
67
|
+
export const SlotLabelSchema = labelMapSchema();
|
|
68
|
+
/** What the server stores for an action or an offered role is one string of at
|
|
69
|
+
* most 191 characters (MySQL's VARCHAR); 120 leaves room, and holds for every
|
|
70
|
+
* language of a map, since any of them may be the one stored. */
|
|
71
|
+
export const PLUGIN_LABEL_MAX = 120;
|
|
72
|
+
/** A label written as one string, trimmed, 1 to 120 characters. The generated
|
|
73
|
+
* reference carries this form, the English text of whatever was declared. */
|
|
74
|
+
export const PluginLabelStringSchema = labelTextSchema({ max: PLUGIN_LABEL_MAX, trim: true });
|
|
75
|
+
/** A label written as a map, its texts trimmed as a string is: a fresh
|
|
76
|
+
* instance of the rule each call. The install screen's consent list holds an
|
|
77
|
+
* action's label map to exactly this rule through its own instance, because
|
|
78
|
+
* the OpenAPI conversion drops a schema instance that a new union reuses. */
|
|
79
|
+
export function pluginLabelMapSchema() {
|
|
80
|
+
return labelMapSchema({ max: PLUGIN_LABEL_MAX, trim: true });
|
|
81
|
+
}
|
|
82
|
+
export const PluginLabelMapSchema = pluginLabelMapSchema();
|
|
83
|
+
const LABEL_HINT = "a string, or a map with en required";
|
|
84
|
+
/** A label neither branch accepts is explained once: a map that carries its
|
|
85
|
+
* English text by the map's own first problem (too many languages, a key that
|
|
86
|
+
* is not a language code, a text that is not one), anything else by what a
|
|
87
|
+
* label is. */
|
|
88
|
+
function labelUnionError(issue) {
|
|
89
|
+
if (issue.code !== "invalid_union")
|
|
90
|
+
return undefined;
|
|
91
|
+
const value = issue.input;
|
|
92
|
+
const first = issue.errors?.[1]?.[0];
|
|
93
|
+
if (value !== null && typeof value === "object" && !Array.isArray(value) && typeof value.en === "string" && first) {
|
|
94
|
+
return first.path.length > 0 ? `${first.path.map(String).join(".")}: ${first.message}` : first.message;
|
|
95
|
+
}
|
|
96
|
+
return LABEL_HINT;
|
|
97
|
+
}
|
|
98
|
+
export const PluginLabelSchema = z.union([PluginLabelStringSchema, PluginLabelMapSchema], { error: labelUnionError });
|
|
99
|
+
/** The text of a label for a language: the language as given, else its primary
|
|
100
|
+
* subtag (`de-AT` reads `de`), else `en`, which every map carries. Codes
|
|
101
|
+
* compare case-insensitively (BCP 47 tags do). A plain string is its own text. */
|
|
102
|
+
export function resolveLabel(label, language) {
|
|
103
|
+
if (typeof label === "string")
|
|
104
|
+
return label;
|
|
105
|
+
const wanted = language.toLowerCase();
|
|
106
|
+
const primary = wanted.split("-")[0] ?? "";
|
|
107
|
+
let primaryText;
|
|
108
|
+
for (const [code, text] of Object.entries(label)) {
|
|
109
|
+
const lower = code.toLowerCase();
|
|
110
|
+
if (lower === wanted)
|
|
111
|
+
return text;
|
|
112
|
+
if (primaryText === undefined && primary !== "" && lower === primary)
|
|
113
|
+
primaryText = text;
|
|
114
|
+
}
|
|
115
|
+
return primaryText ?? label.en;
|
|
116
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/** The largest locale file a plugin may ship, in UTF-8 bytes. */
|
|
3
|
+
export declare const PLUGIN_LOCALE_MAX_BYTES: number;
|
|
4
|
+
/** The most keys one locale file may hold. */
|
|
5
|
+
export declare const PLUGIN_LOCALE_MAX_KEYS = 2000;
|
|
6
|
+
export declare const PLUGIN_LOCALE_KEY_MAX_LENGTH = 128;
|
|
7
|
+
export declare const PLUGIN_LOCALE_VALUE_MAX_LENGTH = 4000;
|
|
8
|
+
/** A key: 1 to 128 characters, dot-separated segments of ASCII letters,
|
|
9
|
+
* digits, "_" and "-", no empty segment, no segment named __proto__,
|
|
10
|
+
* prototype or constructor. One linear scan, never a regex: the key is
|
|
11
|
+
* untrusted, and the length cap is checked first. */
|
|
12
|
+
export declare function isPluginLocaleKey(key: string): boolean;
|
|
13
|
+
export declare const PluginLocaleFileSchema: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
14
|
+
export type PluginLocaleFile = z.infer<typeof PluginLocaleFileSchema>;
|
|
15
|
+
export type ParsedPluginLocaleFile = {
|
|
16
|
+
ok: true;
|
|
17
|
+
bundle: PluginLocaleFile;
|
|
18
|
+
} | {
|
|
19
|
+
ok: false;
|
|
20
|
+
issue: string;
|
|
21
|
+
};
|
|
22
|
+
/** The language a file name declares ("de.json" is "de"), or null for any
|
|
23
|
+
* name that is not <language>.json with a language CultureSchema accepts. */
|
|
24
|
+
export declare function pluginLocaleFileLanguage(fileName: string): string | null;
|
|
25
|
+
/** Size first, then JSON.parse, then the schema. Never throws; an issue is
|
|
26
|
+
* phrased to follow "locales/<file>: ". */
|
|
27
|
+
export declare function parsePluginLocaleFile(text: string): ParsedPluginLocaleFile;
|
|
28
|
+
/** The {{placeholder}} names in a value, trimmed and sorted: the text
|
|
29
|
+
* between each "{{" and the next "}}", duplicates kept. One left-to-right
|
|
30
|
+
* scan with indexOf, never a regex: each search starts where the last one
|
|
31
|
+
* ended, so the work is linear in the value's length. A value from a
|
|
32
|
+
* plugin's file reaches this capped at PLUGIN_LOCALE_VALUE_MAX_LENGTH by
|
|
33
|
+
* parsePluginLocaleFile; the admin's own files are trusted. */
|
|
34
|
+
export declare function localePlaceholders(text: string): string[];
|
|
35
|
+
export interface LocaleFileComparison {
|
|
36
|
+
/** Keys the other file has and English lacks, in the other file's order. */
|
|
37
|
+
extra: string[];
|
|
38
|
+
/** Keys English has and the other file lacks, in English's order. */
|
|
39
|
+
missing: string[];
|
|
40
|
+
/** Keys both have whose placeholder lists differ, in the other file's order. */
|
|
41
|
+
mismatched: string[];
|
|
42
|
+
}
|
|
43
|
+
/** Holds one language's flat key-to-text map to the English one. Keys are
|
|
44
|
+
* looked up as own properties only. Plural-suffixed keys (items_one,
|
|
45
|
+
* items_other) are ordinary keys: a plugin's t does no plural selection. */
|
|
46
|
+
export declare function compareLocaleFiles(en: Readonly<Record<string, string>>, other: Readonly<Record<string, string>>): LocaleFileComparison;
|
|
47
|
+
/** The docs language of a plugin whose manifest names none. */
|
|
48
|
+
export declare const DEFAULT_DOCS_LANGUAGE = "en";
|
|
49
|
+
/** The longest docsLanguage a manifest may declare. */
|
|
50
|
+
export declare const DOCS_LANGUAGE_MAX_LENGTH = 35;
|
|
51
|
+
/** A manifest's docsLanguage: at most 35 characters, then a code under the
|
|
52
|
+
* site's culture rule (CultureSchema). One rule for `kardalum plugin
|
|
53
|
+
* validate`, the marketplace's manifest check and the stored languages, so
|
|
54
|
+
* a value one of them accepts is never stored as something else. The
|
|
55
|
+
* length is checked first, before the pattern sees the value. */
|
|
56
|
+
export declare const DocsLanguageSchema: z.ZodPipe<z.ZodString, z.ZodString>;
|
|
57
|
+
/** What the marketplace stores on a version about its languages (S291):
|
|
58
|
+
* each UI language the package ships and whether it is complete, and the
|
|
59
|
+
* language its docs are written in. */
|
|
60
|
+
export declare const PluginLanguagesSchema: z.ZodObject<{
|
|
61
|
+
ui: z.ZodArray<z.ZodObject<{
|
|
62
|
+
code: z.ZodString;
|
|
63
|
+
complete: z.ZodBoolean;
|
|
64
|
+
}, z.core.$strict>>;
|
|
65
|
+
docs: z.ZodString;
|
|
66
|
+
}, z.core.$strict>;
|
|
67
|
+
export type PluginLanguages = z.infer<typeof PluginLanguagesSchema>;
|
|
68
|
+
/** English is always listed first and always complete: it is the fallback,
|
|
69
|
+
* and with no locales/ the plugin's words are in its code. Every other
|
|
70
|
+
* language follows by code, complete when it lacks none of en.json's keys
|
|
71
|
+
* (extra keys and placeholder drift are author errors `validate` fails,
|
|
72
|
+
* not missing words). With no readable en.json there is nothing to compare,
|
|
73
|
+
* so no other language is complete. `docs` is a language code the caller
|
|
74
|
+
* has already checked.
|
|
75
|
+
*
|
|
76
|
+
* S311: `labelLanguages` are the language codes the manifest's label maps
|
|
77
|
+
* use. A language only labels use is listed too, and is never complete: its
|
|
78
|
+
* screens' words show English. A code is taken under DocsLanguageSchema's
|
|
79
|
+
* rule (a language code of at most 35 characters, the longest a locale
|
|
80
|
+
* file's name can carry), and one a file already lists, in any case, is not
|
|
81
|
+
* listed twice. */
|
|
82
|
+
export declare function summarizePluginLanguages(bundles: ReadonlyMap<string, PluginLocaleFile>, docs: string, labelLanguages?: ReadonlyArray<string>): PluginLanguages;
|
|
@@ -0,0 +1,228 @@
|
|
|
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
|
+
*
|
|
201
|
+
* S311: `labelLanguages` are the language codes the manifest's label maps
|
|
202
|
+
* use. A language only labels use is listed too, and is never complete: its
|
|
203
|
+
* screens' words show English. A code is taken under DocsLanguageSchema's
|
|
204
|
+
* rule (a language code of at most 35 characters, the longest a locale
|
|
205
|
+
* file's name can carry), and one a file already lists, in any case, is not
|
|
206
|
+
* listed twice. */
|
|
207
|
+
export function summarizePluginLanguages(bundles, docs, labelLanguages = []) {
|
|
208
|
+
const en = bundles.get("en");
|
|
209
|
+
const codes = new Set(bundles.keys());
|
|
210
|
+
const listed = new Set([...codes].map((code) => code.toLowerCase()));
|
|
211
|
+
for (const code of labelLanguages) {
|
|
212
|
+
if (listed.has(code.toLowerCase()) || !DocsLanguageSchema.safeParse(code).success)
|
|
213
|
+
continue;
|
|
214
|
+
codes.add(code);
|
|
215
|
+
listed.add(code.toLowerCase());
|
|
216
|
+
}
|
|
217
|
+
const others = [...codes].filter((code) => code !== "en").sort();
|
|
218
|
+
return {
|
|
219
|
+
ui: [
|
|
220
|
+
{ code: "en", complete: true },
|
|
221
|
+
...others.map((code) => {
|
|
222
|
+
const bundle = bundles.get(code);
|
|
223
|
+
return { code, complete: en !== undefined && bundle !== undefined && compareLocaleFiles(en, bundle).missing.length === 0 };
|
|
224
|
+
}),
|
|
225
|
+
],
|
|
226
|
+
docs,
|
|
227
|
+
};
|
|
228
|
+
}
|
|
@@ -4,7 +4,9 @@ import { z } from "zod";
|
|
|
4
4
|
* without reading the roles list (which needs roles.read). */
|
|
5
5
|
export declare const ManagedPluginRoleOfferSchema: z.ZodObject<{
|
|
6
6
|
id: z.ZodString;
|
|
7
|
-
label: z.ZodString
|
|
7
|
+
label: z.ZodUnion<readonly [z.ZodString, z.ZodPreprocess<z.ZodObject<{
|
|
8
|
+
en: z.ZodString;
|
|
9
|
+
}, z.core.$catchall<z.ZodString>>, unknown>]>;
|
|
8
10
|
actions: z.ZodArray<z.ZodString>;
|
|
9
11
|
created: z.ZodBoolean;
|
|
10
12
|
}, z.core.$strip>;
|
|
@@ -48,11 +50,16 @@ export declare const ManagedPluginSchema: z.ZodObject<{
|
|
|
48
50
|
buyHref: z.ZodNullable<z.ZodString>;
|
|
49
51
|
roleOffers: z.ZodArray<z.ZodObject<{
|
|
50
52
|
id: z.ZodString;
|
|
51
|
-
label: z.ZodString
|
|
53
|
+
label: z.ZodUnion<readonly [z.ZodString, z.ZodPreprocess<z.ZodObject<{
|
|
54
|
+
en: z.ZodString;
|
|
55
|
+
}, z.core.$catchall<z.ZodString>>, unknown>]>;
|
|
52
56
|
actions: z.ZodArray<z.ZodString>;
|
|
53
57
|
created: z.ZodBoolean;
|
|
54
58
|
}, z.core.$strip>>;
|
|
55
59
|
grantedRoleCount: z.ZodNumber;
|
|
60
|
+
updateAvailable: z.ZodNullable<z.ZodObject<{
|
|
61
|
+
version: z.ZodString;
|
|
62
|
+
}, z.core.$strip>>;
|
|
56
63
|
}, z.core.$strip>;
|
|
57
64
|
export type ManagedPlugin = z.infer<typeof ManagedPluginSchema>;
|
|
58
65
|
export declare const ManagedPluginListQuerySchema: z.ZodObject<{
|
|
@@ -91,11 +98,16 @@ export declare const ManagedPluginListResponseSchema: z.ZodObject<{
|
|
|
91
98
|
buyHref: z.ZodNullable<z.ZodString>;
|
|
92
99
|
roleOffers: z.ZodArray<z.ZodObject<{
|
|
93
100
|
id: z.ZodString;
|
|
94
|
-
label: z.ZodString
|
|
101
|
+
label: z.ZodUnion<readonly [z.ZodString, z.ZodPreprocess<z.ZodObject<{
|
|
102
|
+
en: z.ZodString;
|
|
103
|
+
}, z.core.$catchall<z.ZodString>>, unknown>]>;
|
|
95
104
|
actions: z.ZodArray<z.ZodString>;
|
|
96
105
|
created: z.ZodBoolean;
|
|
97
106
|
}, z.core.$strip>>;
|
|
98
107
|
grantedRoleCount: z.ZodNumber;
|
|
108
|
+
updateAvailable: z.ZodNullable<z.ZodObject<{
|
|
109
|
+
version: z.ZodString;
|
|
110
|
+
}, z.core.$strip>>;
|
|
99
111
|
}, z.core.$strip>>;
|
|
100
112
|
nextCursor: z.ZodNullable<z.ZodString>;
|
|
101
113
|
licenseGraceDays: z.ZodNumber;
|
|
@@ -106,7 +118,9 @@ export declare const PluginIdParamsSchema: z.ZodObject<{
|
|
|
106
118
|
}, z.core.$strip>;
|
|
107
119
|
export declare const UninstallPluginBodySchema: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
108
120
|
confirmStructuredDataCleanup: z.ZodOptional<z.ZodBoolean>;
|
|
109
|
-
|
|
121
|
+
removeSampleContent: z.ZodOptional<z.ZodBoolean>;
|
|
122
|
+
removeRoles: z.ZodOptional<z.ZodBoolean>;
|
|
123
|
+
}, z.core.$strict>>>;
|
|
110
124
|
export declare const UninstallConfirmationRequiredSchema: z.ZodObject<{
|
|
111
125
|
requiresConfirmation: z.ZodLiteral<true>;
|
|
112
126
|
snapshotGroupId: z.ZodString;
|
|
@@ -339,6 +353,15 @@ export declare const PluginUploadResponseSchema: z.ZodObject<{
|
|
|
339
353
|
status: z.ZodLiteral<"added">;
|
|
340
354
|
count: z.ZodNumber;
|
|
341
355
|
}, z.core.$strip>], "status">>;
|
|
356
|
+
roles: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
357
|
+
id: z.ZodString;
|
|
358
|
+
outcome: z.ZodEnum<{
|
|
359
|
+
failed: "failed";
|
|
360
|
+
created: "created";
|
|
361
|
+
"already-exists": "already-exists";
|
|
362
|
+
}>;
|
|
363
|
+
}, z.core.$strip>>>;
|
|
364
|
+
warnings: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
342
365
|
}, z.core.$strip>;
|
|
343
366
|
export type PluginUploadResponse = z.infer<typeof PluginUploadResponseSchema>;
|
|
344
367
|
/** S274c: the upload's confirmation travels as a query flag because the
|
|
@@ -367,3 +390,9 @@ export declare const TrustDowngradeConfirmationSchema: z.ZodObject<{
|
|
|
367
390
|
message: z.ZodString;
|
|
368
391
|
}, z.core.$strip>;
|
|
369
392
|
export type TrustDowngradeConfirmation = z.infer<typeof TrustDowngradeConfirmationSchema>;
|
|
393
|
+
export type ManagedPluginListQuery = z.infer<typeof ManagedPluginListQuerySchema>;
|
|
394
|
+
/** The uninstall body as a caller writes it: the object, without the null and undefined the route also accepts. */
|
|
395
|
+
export type UninstallPluginBody = NonNullable<z.infer<typeof UninstallPluginBodySchema>>;
|
|
396
|
+
export type SnapshotGroupListQuery = z.infer<typeof SnapshotGroupListQuerySchema>;
|
|
397
|
+
/** The restore body as a caller writes it: the object, without the null and undefined the route also accepts. */
|
|
398
|
+
export type RestoreBody = NonNullable<z.infer<typeof RestoreBodySchema>>;
|
|
@@ -1,6 +1,9 @@
|
|
|
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";
|
|
5
|
+
import { InstallWarningsSchema } from "./install-warnings.schema.js";
|
|
6
|
+
import { STORAGE_TYPES } from "./plugin-vocabulary.js";
|
|
4
7
|
// The ADMIN management view of the registry (S135): unlike the public
|
|
5
8
|
// GET /api/plugins (enabled-only, boot-loader metadata), this surface
|
|
6
9
|
// lists every installed plugin, disabled included. licenseStatus reflects
|
|
@@ -54,7 +57,7 @@ export const ManagedPluginSchema = z.object({
|
|
|
54
57
|
type: z.string(),
|
|
55
58
|
version: z.string(),
|
|
56
59
|
trustTier: z.enum(["verified", "unverified"]),
|
|
57
|
-
storageType: z.enum(
|
|
60
|
+
storageType: z.enum(STORAGE_TYPES),
|
|
58
61
|
enabled: z.boolean(),
|
|
59
62
|
licenseStatus: z
|
|
60
63
|
.string()
|
|
@@ -91,6 +94,15 @@ export const ManagedPluginSchema = z.object({
|
|
|
91
94
|
// S274c: distinct roles holding any of this plugin's actions, for the
|
|
92
95
|
// uninstall dialog.
|
|
93
96
|
grantedRoleCount: z.number().int().nonnegative(),
|
|
97
|
+
// S294 (2026-10-14-s294-update-available-design.md 3.6): the newer version
|
|
98
|
+
// the marketplace has for this plugin and this site can take
|
|
99
|
+
// (updateAvailableFor, the detail view's Update rule), or null: no such
|
|
100
|
+
// version, no listing, a bundle, no marketplace configured, or a
|
|
101
|
+
// marketplace that cannot be reached when nothing was learned from it
|
|
102
|
+
// before (a cold cache). The lookup fails open: a version learned earlier
|
|
103
|
+
// is served through a failure and its backoff, and while a lookup slower
|
|
104
|
+
// than the list's two-second wait runs.
|
|
105
|
+
updateAvailable: z.object({ version: z.string() }).nullable(),
|
|
94
106
|
});
|
|
95
107
|
export const ManagedPluginListQuerySchema = z.object({
|
|
96
108
|
cursor: z.string().uuid().optional(),
|
|
@@ -115,7 +127,14 @@ export const PluginIdParamsSchema = z.object({
|
|
|
115
127
|
export const UninstallPluginBodySchema = z
|
|
116
128
|
.object({
|
|
117
129
|
confirmStructuredDataCleanup: z.boolean().optional(),
|
|
130
|
+
// S293: the uninstall mirror; absent means true, and each only acts on
|
|
131
|
+
// what the install record holds.
|
|
132
|
+
removeSampleContent: z.boolean().optional(),
|
|
133
|
+
removeRoles: z.boolean().optional(),
|
|
118
134
|
})
|
|
135
|
+
// S293: strict, because an absent flag means true: a misspelt opt-out
|
|
136
|
+
// dropped as an unknown key would be read as consent to remove.
|
|
137
|
+
.strict()
|
|
119
138
|
.nullish();
|
|
120
139
|
// 409 payload when a structured plugin's uninstall needs confirmation —
|
|
121
140
|
// the snapshot has ALREADY been taken (S87's safe-to-retry design).
|
|
@@ -335,7 +354,7 @@ export const RestoreBodySchema = z
|
|
|
335
354
|
planHash: z.string().optional(),
|
|
336
355
|
})
|
|
337
356
|
.nullish();
|
|
338
|
-
// The second install door (Task 4): POST /api/plugins/upload lands an
|
|
357
|
+
// The second install door (Task 4): POST /api/manage/v1/plugins/upload lands an
|
|
339
358
|
// admin-uploaded .zip through the same installPackageArchive spine the
|
|
340
359
|
// marketplace uses, but with no marketplace signature to check — trust is
|
|
341
360
|
// always the literal "unregistered" here, never the registry's own
|
|
@@ -369,6 +388,13 @@ export const PluginUploadResponseSchema = z.object({
|
|
|
369
388
|
// S277e: what the install did with the package's sample content. Absent
|
|
370
389
|
// for an update and for a package that ships none.
|
|
371
390
|
sampleContent: SampleContentOutcomeSchema.optional(),
|
|
391
|
+
// S293: what the install did with each offered role its answers named;
|
|
392
|
+
// absent when they named none.
|
|
393
|
+
roles: z.array(InstallRoleOutcomeSchema).optional(),
|
|
394
|
+
// S314 (D4, W7): on an update, one sentence per template or asset the
|
|
395
|
+
// update did not apply as shipped, or removed. Absent on a fresh install
|
|
396
|
+
// and when there is nothing to say.
|
|
397
|
+
warnings: InstallWarningsSchema.optional(),
|
|
372
398
|
});
|
|
373
399
|
/** S274c: the upload's confirmation travels as a query flag because the
|
|
374
400
|
* route reads only the multipart file part. */
|
|
@@ -1,7 +1,15 @@
|
|
|
1
|
+
import type { PluginLabel } from "./plugin-labels.js";
|
|
1
2
|
/** The contribution kinds that sit behind a named action. The SDK classifies
|
|
2
3
|
* these on its CONTRIBUTION_RULES table; its test pins that table to this
|
|
3
4
|
* list, so the two cannot drift apart silently. */
|
|
4
|
-
export declare const ACTION_GATED_CONTRIBUTION_KEYS: readonly ["adminSections", "railEntries", "dashboardWidgets", "
|
|
5
|
+
export declare const ACTION_GATED_CONTRIBUTION_KEYS: readonly ["adminSections", "railEntries", "dashboardWidgets", "apiRoutes"];
|
|
6
|
+
/** S293 (S283's decision, 2026-10-13-s293-the-wizard-installed-design.md 3.9):
|
|
7
|
+
* the built-in rights an offered role may grant beside the plugin's own
|
|
8
|
+
* actions: the read right of each built-in section a rail entry may join
|
|
9
|
+
* (the SDK's BUILT_IN_RAIL_SECTIONS; its test pins the two together), so an
|
|
10
|
+
* accepted offer can open the section its plugin's screen sits in. A write
|
|
11
|
+
* right is never offerable. */
|
|
12
|
+
export declare const OFFERABLE_BUILT_IN_ACTIONS: readonly ["content.read", "media.read", "settings.read", "users.read"];
|
|
5
13
|
export interface ActionDeclarationIssue {
|
|
6
14
|
path: (string | number)[];
|
|
7
15
|
message: string;
|
|
@@ -10,11 +18,11 @@ export interface ActionDeclarationInput {
|
|
|
10
18
|
id: string;
|
|
11
19
|
actions?: ReadonlyArray<{
|
|
12
20
|
id: string;
|
|
13
|
-
label:
|
|
21
|
+
label: PluginLabel;
|
|
14
22
|
}>;
|
|
15
23
|
roles?: ReadonlyArray<{
|
|
16
24
|
id: string;
|
|
17
|
-
label:
|
|
25
|
+
label: PluginLabel;
|
|
18
26
|
actions: ReadonlyArray<string>;
|
|
19
27
|
}>;
|
|
20
28
|
contributions?: unknown;
|
|
@@ -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
|
-
export const ACTION_GATED_CONTRIBUTION_KEYS = ["adminSections", "railEntries", "dashboardWidgets", "
|
|
13
|
+
export const ACTION_GATED_CONTRIBUTION_KEYS = ["adminSections", "railEntries", "dashboardWidgets", "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
|
});
|