@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.
Files changed (101) hide show
  1. package/CHANGELOG.md +11 -1
  2. package/README.md +10 -0
  3. package/dist/built-in-value-schemas.js +1 -1
  4. package/dist/built-ins.js +2 -2
  5. package/dist/capabilities.d.ts +8 -78
  6. package/dist/capabilities.js +23 -319
  7. package/dist/index.d.ts +4 -4
  8. package/dist/index.js +5 -4
  9. package/dist/license-verdict-keys.js +4 -0
  10. package/dist/manifest-entry.d.ts +2 -2
  11. package/dist/manifest-entry.js +1 -1
  12. package/dist/manifest-schema.d.ts +81 -13
  13. package/dist/manifest-schema.js +108 -59
  14. package/dist/manifest.d.ts +105 -40
  15. package/dist/media/media-picker.js +21 -12
  16. package/dist/media/upload-error.d.ts +1 -1
  17. package/dist/media/upload-error.js +1 -1
  18. package/dist/plugin-context.d.ts +7 -0
  19. package/dist/plugin-context.js +7 -0
  20. package/dist/plugin-screen-context.d.ts +33 -2
  21. package/dist/plugin-screen-context.js +27 -2
  22. package/dist/read-all-pages.d.ts +23 -0
  23. package/dist/read-all-pages.js +30 -0
  24. package/dist/richtext/block-panel.js +4 -4
  25. package/dist/richtext/insert-menu.js +3 -3
  26. package/dist/views/content-list-view.js +2 -2
  27. package/dist/views/image-view.js +24 -39
  28. package/dist/views/rich-text-view.js +2 -2
  29. package/node_modules/@kardalum/api-schemas/dist/api-error.schema.d.ts +12 -0
  30. package/node_modules/@kardalum/api-schemas/dist/api-error.schema.js +19 -0
  31. package/node_modules/@kardalum/api-schemas/dist/api-key-api.schema.d.ts +43 -25
  32. package/node_modules/@kardalum/api-schemas/dist/api-key-api.schema.js +60 -8
  33. package/node_modules/@kardalum/api-schemas/dist/asset-api.schema.js +1 -1
  34. package/node_modules/@kardalum/api-schemas/dist/content-api.schema.d.ts +5 -0
  35. package/node_modules/@kardalum/api-schemas/dist/content-api.schema.js +12 -8
  36. package/node_modules/@kardalum/api-schemas/dist/content-list.schema.js +1 -1
  37. package/node_modules/@kardalum/api-schemas/dist/content-path.js +11 -7
  38. package/node_modules/@kardalum/api-schemas/dist/content-trash.schema.d.ts +1 -0
  39. package/node_modules/@kardalum/api-schemas/dist/core-actions.d.ts +107 -57
  40. package/node_modules/@kardalum/api-schemas/dist/core-actions.js +96 -60
  41. package/node_modules/@kardalum/api-schemas/dist/data-type-api.schema.d.ts +1 -0
  42. package/node_modules/@kardalum/api-schemas/dist/document-type-api.schema.d.ts +2 -0
  43. package/node_modules/@kardalum/api-schemas/dist/document-type-api.schema.js +1 -1
  44. package/node_modules/@kardalum/api-schemas/dist/index.d.ts +39 -28
  45. package/node_modules/@kardalum/api-schemas/dist/index.js +19 -13
  46. package/node_modules/@kardalum/api-schemas/dist/management-multipart.schema.d.ts +73 -0
  47. package/node_modules/@kardalum/api-schemas/dist/management-multipart.schema.js +104 -0
  48. package/node_modules/@kardalum/api-schemas/dist/marketplace-listing-api.schema.d.ts +302 -1
  49. package/node_modules/@kardalum/api-schemas/dist/marketplace-listing-api.schema.js +78 -6
  50. package/node_modules/@kardalum/api-schemas/dist/media-api.schema.d.ts +10 -0
  51. package/node_modules/@kardalum/api-schemas/dist/media-api.schema.js +38 -30
  52. package/node_modules/@kardalum/api-schemas/dist/media-rendition.schema.js +2 -2
  53. package/node_modules/@kardalum/api-schemas/dist/media.schema.js +1 -1
  54. package/node_modules/@kardalum/api-schemas/dist/plugin-docs-api.schema.d.ts +82 -2
  55. package/node_modules/@kardalum/api-schemas/dist/plugin-docs-api.schema.js +4 -0
  56. package/node_modules/@kardalum/api-schemas/dist/plugin-docs.d.ts +88 -5
  57. package/node_modules/@kardalum/api-schemas/dist/plugin-docs.js +79 -17
  58. package/node_modules/@kardalum/api-schemas/dist/plugin-install-record.schema.d.ts +69 -0
  59. package/node_modules/@kardalum/api-schemas/dist/plugin-install-record.schema.js +59 -0
  60. package/node_modules/@kardalum/api-schemas/dist/plugin-install.d.ts +585 -0
  61. package/node_modules/@kardalum/api-schemas/dist/plugin-install.js +536 -0
  62. package/node_modules/@kardalum/api-schemas/dist/plugin-locales.d.ts +75 -0
  63. package/node_modules/@kardalum/api-schemas/dist/plugin-locales.js +213 -0
  64. package/node_modules/@kardalum/api-schemas/dist/plugin-management-api.schema.d.ts +25 -3
  65. package/node_modules/@kardalum/api-schemas/dist/plugin-management-api.schema.js +21 -1
  66. package/node_modules/@kardalum/api-schemas/dist/plugin-manifest-actions.d.ts +7 -0
  67. package/node_modules/@kardalum/api-schemas/dist/plugin-manifest-actions.js +16 -3
  68. package/node_modules/@kardalum/api-schemas/dist/plugin-manifest-api-routes.d.ts +44 -0
  69. package/node_modules/@kardalum/api-schemas/dist/plugin-manifest-api-routes.js +162 -0
  70. package/node_modules/@kardalum/api-schemas/dist/public-api.schema.d.ts +8 -0
  71. package/node_modules/@kardalum/api-schemas/dist/public-api.schema.js +11 -1
  72. package/node_modules/@kardalum/api-schemas/dist/render-editing.d.ts +4 -4
  73. package/node_modules/@kardalum/api-schemas/dist/role.schema.d.ts +6 -0
  74. package/node_modules/@kardalum/api-schemas/dist/role.schema.js +6 -0
  75. package/node_modules/@kardalum/api-schemas/dist/sample-content.schema.d.ts +35 -0
  76. package/node_modules/@kardalum/api-schemas/dist/sample-content.schema.js +79 -0
  77. package/node_modules/@kardalum/api-schemas/dist/setup-api.schema.d.ts +36 -6
  78. package/node_modules/@kardalum/api-schemas/dist/setup-api.schema.js +17 -5
  79. package/node_modules/@kardalum/api-schemas/dist/sites.schema.d.ts +8 -8
  80. package/node_modules/@kardalum/api-schemas/dist/sites.schema.js +8 -8
  81. package/node_modules/@kardalum/api-schemas/dist/snapshot-api.schema.d.ts +4 -0
  82. package/node_modules/@kardalum/api-schemas/dist/snapshot-api.schema.js +2 -0
  83. package/node_modules/@kardalum/api-schemas/dist/template-api.schema.js +4 -4
  84. package/node_modules/@kardalum/api-schemas/dist/user-api.schema.d.ts +11 -3
  85. package/node_modules/@kardalum/api-schemas/dist/user-api.schema.js +5 -0
  86. package/node_modules/@kardalum/plugin-package/dist/build-reference.d.ts +111 -0
  87. package/node_modules/@kardalum/plugin-package/dist/build-reference.js +61 -0
  88. package/node_modules/@kardalum/plugin-package/dist/capabilities.d.ts +103 -0
  89. package/node_modules/@kardalum/plugin-package/dist/capabilities.js +351 -0
  90. package/node_modules/@kardalum/plugin-package/dist/index.d.ts +3 -1
  91. package/node_modules/@kardalum/plugin-package/dist/index.js +2 -1
  92. package/node_modules/@kardalum/plugin-package/dist/reference-entry.d.ts +2 -0
  93. package/node_modules/@kardalum/plugin-package/dist/reference-entry.js +6 -0
  94. package/node_modules/@kardalum/plugin-package/dist/sample-content.d.ts +20 -1
  95. package/node_modules/@kardalum/plugin-package/dist/sample-content.js +56 -16
  96. package/node_modules/@kardalum/plugin-package/dist/types.d.ts +4 -6
  97. package/node_modules/@kardalum/plugin-package/dist/types.js +15 -1
  98. package/node_modules/@kardalum/plugin-package/package.json +5 -0
  99. package/node_modules/@kardalum/ui/dist/components/checkbox.js +2 -2
  100. package/node_modules/@kardalum/ui/dist/components/property-field.js +4 -1
  101. package/package.json +2 -2
@@ -0,0 +1,536 @@
1
+ import { z } from "zod";
2
+ import { CultureSchema } from "./content-api.schema.js";
3
+ import { PluginRoleOfferSchema } from "./plugin-actions.schema.js";
4
+ import { HOSTILE_CHARS_MESSAGE, hasHostileChars } from "./plugin-docs-text.js";
5
+ import { SLOT_ID_MAX, SLOT_ID_REGEX } from "./plugin-id-rules.js";
6
+ import { DOCS_LANGUAGE_MAX_LENGTH } from "./plugin-locales.js";
7
+ import { RoleIdSchema } from "./role.schema.js";
8
+ // S292 (2026-10-13-s292-what-the-wizard-may-ask-design.md): what a plugin's
9
+ // install asks, declared as plain data in the manifest's `install`, so the
10
+ // install screen, a script and the CLI can all ask it and answer it before
11
+ // any of the plugin's code runs. The pure parts live here once: the
12
+ // declaration's shape and its rule (run by the SDK's manifest schema,
13
+ // `kardalum plugin validate` and the marketplace door), the answers object
14
+ // every install path takes, the resolver that fills its defaults, and the
15
+ // install interface derived from a package: what installing does whatever
16
+ // the answers, the built-in questions, and the plugin's own steps. Every
17
+ // label is shown as text, never as markup. S293
18
+ // (2026-10-13-s293-the-wizard-installed-design.md 3.1 and 3.5) adds an
19
+ // update's resolver, the steps an update still asks, and the parse a door
20
+ // runs on a manifest nothing has validated yet.
21
+ /** The most steps one declaration may have. */
22
+ export const INSTALL_MAX_STEPS = 16;
23
+ /** The most options one step may ask. */
24
+ export const INSTALL_MAX_OPTIONS_PER_STEP = 32;
25
+ /** The most choices one select or multi-select option may offer. */
26
+ export const INSTALL_MAX_CHOICES_PER_OPTION = 64;
27
+ /** The longest a label's text may be, per language. */
28
+ export const INSTALL_LABEL_MAX_LENGTH = 120;
29
+ /** The longest a description's text may be, per language. */
30
+ export const INSTALL_DESCRIPTION_MAX_LENGTH = 500;
31
+ /** The most languages one label or description may carry. */
32
+ export const INSTALL_LABEL_MAX_LANGUAGES = 32;
33
+ /** The longest language code a label's key may be: DocsLanguageSchema's
34
+ * bound, checked before the culture pattern ever sees the key. */
35
+ export const INSTALL_LABEL_KEY_MAX_LENGTH = DOCS_LANGUAGE_MAX_LENGTH;
36
+ /** The most option answers one answers object may carry: every option of a full declaration. */
37
+ export const INSTALL_MAX_OPTION_ANSWERS = INSTALL_MAX_STEPS * INSTALL_MAX_OPTIONS_PER_STEP;
38
+ /** The most offered roles one answers object may name. */
39
+ export const INSTALL_MAX_ROLE_ANSWERS = 64;
40
+ export const INSTALL_OPTION_KINDS = ["boolean", "select", "multiSelect"];
41
+ /** Keys an answers object can never use for an option. "__proto__" already
42
+ * fails the id rule as an option id, and InstallAnswersSchema refuses it as
43
+ * a key before its record reads the object; the other two are lowercase
44
+ * words the rule admits, so the declaration rule refuses them as option ids
45
+ * and the answers schema as keys, and no answers object can reach a
46
+ * prototype. */
47
+ const RESERVED_ANSWER_KEYS = new Set(["__proto__", "constructor", "prototype"]);
48
+ // One text of a label map: at most `max` characters, never empty or only
49
+ // whitespace (a blank question on a screen, and a blank English label is one
50
+ // the generated reference refuses), and no Trojan-Source character.
51
+ function installText(max) {
52
+ return z
53
+ .string({ error: "must be text" })
54
+ .max(max, { message: `is at most ${max} characters` })
55
+ .refine((text) => text.trim() !== "", { message: "must not be empty" })
56
+ .refine((text) => !hasHostileChars(text), { message: HOSTILE_CHARS_MESSAGE });
57
+ }
58
+ /** A label map's keys, bounded before the map is read: at most
59
+ * INSTALL_LABEL_MAX_LANGUAGES of them, each at most
60
+ * INSTALL_LABEL_KEY_MAX_LENGTH characters. An issue raised here ends the
61
+ * preprocess's pipe, so the map is not read at all: a map of thousands of
62
+ * keys costs one count, and a key too long to be a language code is never
63
+ * echoed, neither in a message nor in a path (where reading the map would
64
+ * put it, under a text the map refuses). */
65
+ function boundLabelKeys(value, ctx) {
66
+ if (value === null || typeof value !== "object" || Array.isArray(value))
67
+ return value;
68
+ const keys = Object.keys(value);
69
+ if (keys.length > INSTALL_LABEL_MAX_LANGUAGES) {
70
+ ctx.addIssue({ code: "custom", message: `a label holds at most ${INSTALL_LABEL_MAX_LANGUAGES} languages` });
71
+ }
72
+ if (keys.some((key) => key.length > INSTALL_LABEL_KEY_MAX_LENGTH)) {
73
+ ctx.addIssue({ code: "custom", message: `label keys are language codes of at most ${INSTALL_LABEL_KEY_MAX_LENGTH} characters` });
74
+ }
75
+ return value;
76
+ }
77
+ // A label map: a language code to the text shown in that language, `en`
78
+ // required because every other language falls back to it. Its keys are
79
+ // bounded first (boundLabelKeys), then follow a slot label's rule
80
+ // (CultureSchema), with the same message.
81
+ function installLabelMap(max) {
82
+ const text = installText(max);
83
+ return z.preprocess(boundLabelKeys, z
84
+ .object({ en: text })
85
+ .catchall(text)
86
+ .superRefine((label, ctx) => {
87
+ for (const key of Object.keys(label)) {
88
+ if (!CultureSchema.safeParse(key).success) {
89
+ ctx.addIssue({
90
+ code: "custom",
91
+ message: `label keys are language codes such as "en", "de" or "pt-BR", not ${JSON.stringify(key)}`,
92
+ path: [key],
93
+ });
94
+ }
95
+ }
96
+ }));
97
+ }
98
+ export const InstallLabelSchema = installLabelMap(INSTALL_LABEL_MAX_LENGTH);
99
+ export const InstallDescriptionSchema = installLabelMap(INSTALL_DESCRIPTION_MAX_LENGTH);
100
+ /** A step's, an option's or a choice's id: the slot id rule, so an id needs
101
+ * no encoding anywhere it travels and can never be "." or "..". */
102
+ export const InstallIdSchema = z
103
+ .string()
104
+ .max(SLOT_ID_MAX, { message: `an id is at most ${SLOT_ID_MAX} characters` })
105
+ .regex(SLOT_ID_REGEX, { message: 'an id is lowercase letters, digits and single hyphens, such as "payment-provider"' });
106
+ const InstallChoiceSchema = z
107
+ .object({ id: InstallIdSchema, label: InstallLabelSchema, description: InstallDescriptionSchema.optional() })
108
+ .strict();
109
+ const optionText = { id: InstallIdSchema, label: InstallLabelSchema, description: InstallDescriptionSchema.optional() };
110
+ /** One question. A select with no default must be answered unless it says
111
+ * `required: false`; a select with a default is never required. */
112
+ export const InstallOptionSchema = z.discriminatedUnion("kind", [
113
+ z.object({ ...optionText, kind: z.literal("boolean"), default: z.boolean() }).strict(),
114
+ z
115
+ .object({
116
+ ...optionText,
117
+ kind: z.literal("select"),
118
+ choices: z.array(InstallChoiceSchema),
119
+ default: InstallIdSchema.optional(),
120
+ required: z.boolean().optional(),
121
+ })
122
+ .strict(),
123
+ z.object({ ...optionText, kind: z.literal("multiSelect"), choices: z.array(InstallChoiceSchema), default: z.array(InstallIdSchema) }).strict(),
124
+ ]);
125
+ export const InstallStepSchema = z
126
+ .object({ id: InstallIdSchema, label: InstallLabelSchema, description: InstallDescriptionSchema.optional(), options: z.array(InstallOptionSchema) })
127
+ .strict();
128
+ /** The manifest's `install`: the steps the install asks, in order. */
129
+ export const PluginInstallDeclarationSchema = z.object({ steps: z.array(InstallStepSchema) }).strict();
130
+ /** Whether an option must be answered: a select with no default, unless it
131
+ * says `required: false`. buildReference (@kardalum/plugin-package) writes
132
+ * the same rule inline, and its test pins the two together. */
133
+ export function installOptionNeedsAnswer(option) {
134
+ return option.kind === "select" && option.default === undefined && option.required !== false;
135
+ }
136
+ /** The rules over a parsed declaration that its shape cannot express: the
137
+ * caps, distinct ids (option ids across every step, because each keys its
138
+ * answer), defaults among the choices. Paths are rooted at `install`. */
139
+ export function checkInstallDeclaration(install) {
140
+ const issues = [];
141
+ const steps = install.steps;
142
+ if (steps.length === 0)
143
+ issues.push({ path: ["install", "steps"], message: "declare at least one step, or leave install out" });
144
+ if (steps.length > INSTALL_MAX_STEPS)
145
+ issues.push({ path: ["install", "steps"], message: `an install declares at most ${INSTALL_MAX_STEPS} steps` });
146
+ const stepIds = new Set();
147
+ const optionIds = new Set();
148
+ steps.forEach((step, s) => {
149
+ const stepAt = ["install", "steps", s];
150
+ if (stepIds.has(step.id))
151
+ issues.push({ path: [...stepAt, "id"], message: `step id "${step.id}" is used more than once` });
152
+ stepIds.add(step.id);
153
+ if (step.options.length === 0)
154
+ issues.push({ path: [...stepAt, "options"], message: "a step asks at least one option" });
155
+ if (step.options.length > INSTALL_MAX_OPTIONS_PER_STEP) {
156
+ issues.push({ path: [...stepAt, "options"], message: `a step asks at most ${INSTALL_MAX_OPTIONS_PER_STEP} options` });
157
+ }
158
+ step.options.forEach((option, o) => {
159
+ const at = [...stepAt, "options", o];
160
+ if (RESERVED_ANSWER_KEYS.has(option.id)) {
161
+ issues.push({ path: [...at, "id"], message: `"${option.id}" cannot name an option: the answers object reserves it` });
162
+ }
163
+ else if (optionIds.has(option.id)) {
164
+ issues.push({ path: [...at, "id"], message: `option id "${option.id}" is used more than once in this declaration` });
165
+ }
166
+ optionIds.add(option.id);
167
+ if (option.kind === "boolean")
168
+ return;
169
+ if (option.choices.length === 0)
170
+ issues.push({ path: [...at, "choices"], message: `a ${option.kind} option offers at least one choice` });
171
+ if (option.choices.length > INSTALL_MAX_CHOICES_PER_OPTION) {
172
+ issues.push({ path: [...at, "choices"], message: `an option offers at most ${INSTALL_MAX_CHOICES_PER_OPTION} choices` });
173
+ }
174
+ const choiceIds = new Set();
175
+ option.choices.forEach((choice, c) => {
176
+ if (choiceIds.has(choice.id))
177
+ issues.push({ path: [...at, "choices", c, "id"], message: `choice id "${choice.id}" is used more than once in "${option.id}"` });
178
+ choiceIds.add(choice.id);
179
+ });
180
+ if (option.kind === "select") {
181
+ if (option.default !== undefined && !choiceIds.has(option.default)) {
182
+ issues.push({ path: [...at, "default"], message: `the default "${option.default}" is not one of the choices of "${option.id}"` });
183
+ }
184
+ if (option.default !== undefined && option.required === true) {
185
+ issues.push({ path: [...at, "required"], message: "a select with a default is never required: its default answers it" });
186
+ }
187
+ return;
188
+ }
189
+ const chosen = new Set();
190
+ option.default.forEach((id, d) => {
191
+ if (!choiceIds.has(id))
192
+ issues.push({ path: [...at, "default", d], message: `the default "${id}" is not one of the choices of "${option.id}"` });
193
+ else if (chosen.has(id))
194
+ issues.push({ path: [...at, "default", d], message: `the default names "${id}" more than once` });
195
+ chosen.add(id);
196
+ });
197
+ });
198
+ });
199
+ return issues;
200
+ }
201
+ const RESERVED_ANSWER_KEY_MESSAGE = "this key is reserved and can never name an option";
202
+ const InstallAnswerKeySchema = InstallIdSchema.refine((key) => !RESERVED_ANSWER_KEYS.has(key), {
203
+ message: RESERVED_ANSWER_KEY_MESSAGE,
204
+ });
205
+ /** Zod's record parser skips an own "__proto__" key without a word (so the
206
+ * key can never set the prototype of the object it builds), which means
207
+ * InstallAnswerKeySchema never sees one. A parsed JSON body can carry it,
208
+ * so the raw object is read first and the key refused, not dropped. */
209
+ function refuseOwnProtoKey(value, ctx) {
210
+ if (value !== null && typeof value === "object" && Object.hasOwn(value, "__proto__")) {
211
+ ctx.addIssue({ code: "custom", message: RESERVED_ANSWER_KEY_MESSAGE, path: ["__proto__"] });
212
+ }
213
+ return value;
214
+ }
215
+ /** One option's answer: true or false, a choice id, or a list of choice ids. */
216
+ export const InstallAnswerValueSchema = z.union([
217
+ z.boolean(),
218
+ InstallIdSchema,
219
+ z.array(InstallIdSchema).max(INSTALL_MAX_CHOICES_PER_OPTION, { message: `a list answer names at most ${INSTALL_MAX_CHOICES_PER_OPTION} choices` }),
220
+ ], { error: "an answer is true or false, a choice id, or a list of choice ids" });
221
+ /** The answers object every install path takes. Strict, so a misspelt key is
222
+ * refused rather than ignored; read by resolveInstallAnswers. */
223
+ export const InstallAnswersSchema = z
224
+ .object({
225
+ sampleContent: z.boolean().optional(),
226
+ roles: z.array(RoleIdSchema).max(INSTALL_MAX_ROLE_ANSWERS, { message: `an answers object names at most ${INSTALL_MAX_ROLE_ANSWERS} roles` }).optional(),
227
+ options: z
228
+ .preprocess(refuseOwnProtoKey, z
229
+ .record(InstallAnswerKeySchema, InstallAnswerValueSchema, {
230
+ // The record reports a refused key as "invalid_key", with the key
231
+ // rule's own words nested under it. They are lifted onto the issue,
232
+ // so a door prints the id rule or the reserved-key rule.
233
+ error: (issue) => (issue.code === "invalid_key" ? issue.issues.map((inner) => inner.message).join("; ") : undefined),
234
+ })
235
+ .refine((options) => Object.keys(options).length <= INSTALL_MAX_OPTION_ANSWERS, {
236
+ message: `an answers object answers at most ${INSTALL_MAX_OPTION_ANSWERS} options`,
237
+ }))
238
+ .optional(),
239
+ })
240
+ .strict();
241
+ /** The answers with every default filled: what onInstall and onUpdate are
242
+ * told, and what S293 records on the registry row. */
243
+ export const ResolvedInstallAnswersSchema = z
244
+ .object({
245
+ sampleContent: z.boolean(),
246
+ roles: z.array(RoleIdSchema),
247
+ options: z.record(InstallIdSchema, InstallAnswerValueSchema),
248
+ })
249
+ .strict();
250
+ /** One declared option's answer, or undefined with its issue pushed (or for an
251
+ * optional select left unanswered). `needsAnswer` words the refusal of an
252
+ * unanswered select that needs one, given the option's quoted id: an
253
+ * install's by default, an update's from resolveUpdateAnswers. */
254
+ function resolveOption(option, answer, issues, needsAnswer = (id) => `${id} has no default, so it needs an answer`) {
255
+ const path = ["options", option.id];
256
+ const id = JSON.stringify(option.id);
257
+ if (option.kind === "boolean") {
258
+ if (answer === null)
259
+ return option.default;
260
+ if (typeof answer.value === "boolean")
261
+ return answer.value;
262
+ issues.push({ path, message: `${id} is a yes-or-no option: answer true or false` });
263
+ return undefined;
264
+ }
265
+ const choices = new Set(option.choices.map((entry) => entry.id));
266
+ if (option.kind === "select") {
267
+ if (answer === null) {
268
+ if (option.default !== undefined)
269
+ return option.default;
270
+ if (option.required === false)
271
+ return undefined;
272
+ issues.push({ path, message: needsAnswer(id) });
273
+ return undefined;
274
+ }
275
+ if (typeof answer.value !== "string") {
276
+ issues.push({ path, message: `${id} takes one choice: answer a choice id` });
277
+ return undefined;
278
+ }
279
+ if (!choices.has(answer.value)) {
280
+ issues.push({ path, message: `${JSON.stringify(answer.value)} is not one of the choices of ${id}` });
281
+ return undefined;
282
+ }
283
+ return answer.value;
284
+ }
285
+ if (answer === null)
286
+ return [...option.default];
287
+ if (!Array.isArray(answer.value)) {
288
+ issues.push({ path, message: `${id} takes a list of choices: answer an array of choice ids` });
289
+ return undefined;
290
+ }
291
+ const picked = [];
292
+ let refused = false;
293
+ answer.value.forEach((value, index) => {
294
+ if (!choices.has(value)) {
295
+ issues.push({ path: [...path, index], message: `${JSON.stringify(value)} is not one of the choices of ${id}` });
296
+ refused = true;
297
+ }
298
+ else if (picked.includes(value)) {
299
+ issues.push({ path: [...path, index], message: `${JSON.stringify(value)} is chosen more than once for ${id}` });
300
+ refused = true;
301
+ }
302
+ else {
303
+ picked.push(value);
304
+ }
305
+ });
306
+ return refused ? undefined : picked;
307
+ }
308
+ /** The answers with every default filled, or every reason they cannot be:
309
+ * the sample content first, then the roles in answer order, then option
310
+ * keys the declaration lacks in answer order, then the declared options in
311
+ * declaration order. `answers` has passed InstallAnswersSchema (a door's
312
+ * body schema); its options are read as own properties only. The
313
+ * manifest's declaration has passed checkInstallDeclaration (the SDK's
314
+ * manifest schema runs it, and so does parseInstallAnswersManifest): an
315
+ * option id declared twice would otherwise resolve against its last
316
+ * declaration alone. */
317
+ export function resolveInstallAnswers(manifest, shipped, answers) {
318
+ const issues = [];
319
+ let sampleContent = shipped.sampleContent;
320
+ if (answers.sampleContent === true && !shipped.sampleContent) {
321
+ issues.push({ path: ["sampleContent"], message: "this plugin ships no sample content" });
322
+ }
323
+ else if (answers.sampleContent !== undefined) {
324
+ sampleContent = answers.sampleContent;
325
+ }
326
+ const offered = new Set((manifest.roles ?? []).map((role) => role.id));
327
+ const roles = [];
328
+ (answers.roles ?? []).forEach((role, index) => {
329
+ if (!offered.has(role))
330
+ issues.push({ path: ["roles", index], message: `this plugin offers no role ${JSON.stringify(role)}` });
331
+ else if (roles.includes(role))
332
+ issues.push({ path: ["roles", index], message: `role ${JSON.stringify(role)} is answered more than once` });
333
+ else
334
+ roles.push(role);
335
+ });
336
+ const declared = new Map();
337
+ for (const step of manifest.install?.steps ?? [])
338
+ for (const option of step.options)
339
+ declared.set(option.id, option);
340
+ const given = answers.options ?? {};
341
+ for (const key of Object.keys(given)) {
342
+ if (!declared.has(key))
343
+ issues.push({ path: ["options", key], message: `this plugin declares no install option ${JSON.stringify(key)}` });
344
+ }
345
+ const options = {};
346
+ for (const [id, option] of declared) {
347
+ const value = resolveOption(option, Object.hasOwn(given, id) ? { value: given[id] } : null, issues);
348
+ if (value !== undefined)
349
+ options[id] = value;
350
+ }
351
+ return issues.length > 0 ? { ok: false, issues } : { ok: true, answers: { sampleContent, roles, options } };
352
+ }
353
+ /** What a door reads from manifest.json (or the live manifest) to resolve
354
+ * answers. Not strict: a manifest's other keys are allowed and left out of
355
+ * the result. */
356
+ export const InstallAnswersManifestSchema = z.object({
357
+ install: PluginInstallDeclarationSchema.optional(),
358
+ roles: z.array(PluginRoleOfferSchema).optional(),
359
+ });
360
+ /** A manifest nothing has validated yet, read for its answers: the shape first,
361
+ * then checkInstallDeclaration on a declaration that parsed (S292 C7), because
362
+ * the resolvers trust the declaration they are given. */
363
+ export function parseInstallAnswersManifest(raw) {
364
+ const parsed = InstallAnswersManifestSchema.safeParse(raw);
365
+ if (!parsed.success) {
366
+ return {
367
+ ok: false,
368
+ issues: parsed.error.issues.map((issue) => ({
369
+ path: issue.path.filter((part) => typeof part !== "symbol"),
370
+ message: issue.message,
371
+ })),
372
+ };
373
+ }
374
+ const declarationIssues = parsed.data.install ? checkInstallDeclaration(parsed.data.install) : [];
375
+ return declarationIssues.length > 0 ? { ok: false, issues: declarationIssues } : { ok: true, manifest: parsed.data };
376
+ }
377
+ function recordedValue(recorded, id) {
378
+ return recorded && Object.hasOwn(recorded.options, id) ? recorded.options[id] : undefined;
379
+ }
380
+ /** Whether a recorded answer still answers this option: the option's kind
381
+ * takes it, every id it names is still one of the option's choices, and a
382
+ * list names each choice once (resolveOption refuses a repeated one, so an
383
+ * install never recorded it). */
384
+ function recordedAnswerFits(option, value) {
385
+ if (value === undefined)
386
+ return false;
387
+ if (option.kind === "boolean")
388
+ return typeof value === "boolean";
389
+ const choices = new Set(option.choices.map((choice) => choice.id));
390
+ if (option.kind === "select")
391
+ return typeof value === "string" && choices.has(value);
392
+ return Array.isArray(value) && value.every((id) => choices.has(id)) && new Set(value).size === value.length;
393
+ }
394
+ /** A declaration's steps, each keeping only the options the recorded answers
395
+ * do not cover (no recorded answer, or one the option no longer accepts); a
396
+ * step left with none is dropped. No record covers nothing. */
397
+ export function stepsNotCoveredBy(steps, recorded) {
398
+ return steps
399
+ .map((step) => ({ ...step, options: step.options.filter((option) => !recordedAnswerFits(option, recordedValue(recorded, option.id))) }))
400
+ .filter((step) => step.options.length > 0);
401
+ }
402
+ const updateNeedsAnswer = (id) => `${id} has no recorded answer and no default, so this update needs an answer for it`;
403
+ /** An update's answers (2026-10-13-s293-the-wizard-installed-design.md 3.5):
404
+ * the record's sample choice, the recorded roles the new version still
405
+ * offers, each covered option's recorded answer (a copy), and every other
406
+ * declared option resolved from the request's answer or its default. Every
407
+ * refusal at once: the sample content, the roles, the request's option keys
408
+ * in answer order, then the declared options in declaration order. `given`
409
+ * and the declaration are held to what resolveInstallAnswers assumes;
410
+ * `recorded` is the row's record read through readInstallRecord, or null
411
+ * for a plugin installed before S293. */
412
+ export function resolveUpdateAnswers(manifest, recorded, given) {
413
+ const issues = [];
414
+ if (given.sampleContent !== undefined)
415
+ issues.push({ path: ["sampleContent"], message: "an update never adds sample content" });
416
+ if (given.roles !== undefined && given.roles.length > 0) {
417
+ issues.push({ path: ["roles"], message: "an update creates no roles: accept an offered role from the installed plugins list" });
418
+ }
419
+ const offered = new Set((manifest.roles ?? []).map((role) => role.id));
420
+ const roles = (recorded?.roles ?? []).filter((role) => offered.has(role));
421
+ const declared = new Map();
422
+ for (const step of manifest.install?.steps ?? [])
423
+ for (const option of step.options)
424
+ declared.set(option.id, option);
425
+ const covered = (option) => recordedAnswerFits(option, recordedValue(recorded, option.id));
426
+ const givenOptions = given.options ?? {};
427
+ for (const key of Object.keys(givenOptions)) {
428
+ const option = declared.get(key);
429
+ if (!option)
430
+ issues.push({ path: ["options", key], message: `this plugin declares no install option ${JSON.stringify(key)}` });
431
+ else if (covered(option))
432
+ issues.push({ path: ["options", key], message: `${JSON.stringify(key)} was answered at install, and an update keeps that answer` });
433
+ }
434
+ const options = {};
435
+ for (const [id, option] of declared) {
436
+ if (covered(option)) {
437
+ const value = recordedValue(recorded, id);
438
+ options[id] = Array.isArray(value) ? [...value] : value;
439
+ continue;
440
+ }
441
+ const value = resolveOption(option, Object.hasOwn(givenOptions, id) ? { value: givenOptions[id] } : null, issues, updateNeedsAnswer);
442
+ if (value !== undefined)
443
+ options[id] = value;
444
+ }
445
+ return issues.length > 0 ? { ok: false, issues } : { ok: true, answers: { sampleContent: recorded?.sampleContent ?? false, roles, options } };
446
+ }
447
+ /** What installing does whatever the answers, in the order the install
448
+ * applies it, structured storage last (it is what an uninstall must
449
+ * snapshot). */
450
+ export const INSTALL_CONSENT_IDS = ["migrations", "documentTypes", "actions", "templates", "assets", "structuredStorage"];
451
+ /** A consent item's detail: a migration id, a document type's name, an
452
+ * action's label, a template's name or an asset's path. It is read from
453
+ * parts of a manifest no install schema bounds (the door's mirror leaves
454
+ * `contributions` unvalidated) and shown as text, so it is held to a
455
+ * label's text rule: at most 120 characters, never only whitespace, no
456
+ * control or direction-override character. */
457
+ const InstallConsentDetailSchema = installText(INSTALL_LABEL_MAX_LENGTH);
458
+ // The interface's parts, once: InstallInterfaceSchema holds them closed, and
459
+ // InstallInterfaceWireSchema below drops a key it does not know instead.
460
+ const consentItemShape = { id: z.string(), details: z.array(InstallConsentDetailSchema) };
461
+ const sampleContentShape = { default: z.literal(true), description: InstallDescriptionSchema.optional() };
462
+ const roleOfferShape = { id: z.string(), label: z.string(), actions: z.array(z.string()), default: z.literal(false) };
463
+ /** The install interface: what a screen shows and a script answers, before
464
+ * anything is installed. The marketplace stores it per version and its
465
+ * listing API carries it to the admin. A consent id is an open string on
466
+ * the wire, as a capability id is (MarketplaceCapabilitySchema): a newer
467
+ * marketplace's new item reaches an older admin as an id it has no words
468
+ * for, not as a listing that fails to parse. Option kinds stay closed: a CMS
469
+ * whose SDK does not know a kind refuses that plugin's manifest anyway. */
470
+ export const InstallInterfaceSchema = z
471
+ .object({
472
+ consent: z.array(z.object(consentItemShape).strict()),
473
+ sampleContent: z.object(sampleContentShape).strict().nullable(),
474
+ roles: z.array(z.object(roleOfferShape).strict()),
475
+ steps: z.array(InstallStepSchema),
476
+ })
477
+ .strict();
478
+ /** InstallInterfaceSchema as the listing wire carries it, from the
479
+ * marketplace's detail API through a CMS's proxy to its admin. The two are
480
+ * deployed and versioned apart, so a key a newer marketplace adds is
481
+ * dropped here rather than refused: refused, it would fail an older CMS's
482
+ * response validation and turn the whole listing into an error. Unknown
483
+ * keys are dropped on the interface, its consent items, its sample content
484
+ * and its roles; the steps stay on the closed InstallStepSchema (D15),
485
+ * because a step an older SDK cannot read belongs to a plugin that CMS
486
+ * refuses at install anyway. */
487
+ export const InstallInterfaceWireSchema = z.object({
488
+ consent: z.array(z.object(consentItemShape)),
489
+ sampleContent: z.object(sampleContentShape).nullable(),
490
+ roles: z.array(z.object(roleOfferShape)),
491
+ steps: z.array(InstallStepSchema),
492
+ });
493
+ function asRecord(value) {
494
+ return value !== null && typeof value === "object" && !Array.isArray(value) ? value : null;
495
+ }
496
+ /** A consent entry's readable name: the entry itself when it is a string
497
+ * (manifest.json's migration ids, an asset path), else its `field`, kept
498
+ * only when it passes InstallConsentDetailSchema. */
499
+ function readableName(entry, field) {
500
+ const value = typeof entry === "string" ? entry : asRecord(entry)?.[field];
501
+ return typeof value === "string" && InstallConsentDetailSchema.safeParse(value).success ? value : null;
502
+ }
503
+ /** One consent item when the manifest declares any of it. A detail the text
504
+ * rule refuses is left out of the list, and the item stays: what it names
505
+ * is installed whether or not its name can be shown. */
506
+ function consentItem(id, declared, field) {
507
+ if (!Array.isArray(declared) || declared.length === 0)
508
+ return null;
509
+ return { id, details: declared.map((entry) => readableName(entry, field)).filter((name) => name !== null) };
510
+ }
511
+ /** The interface a package's install asks, in the order a screen asks it:
512
+ * the consent list, the sample content when it ships, one unticked question
513
+ * per offered role, then the plugin's own steps (a copy). The built-ins are
514
+ * never declared; they follow from what ships. */
515
+ export function installInterfaceFor(manifest, shipped) {
516
+ const contributions = asRecord(manifest.contributions) ?? {};
517
+ const consent = [
518
+ consentItem("migrations", manifest.migrations, "id"),
519
+ consentItem("documentTypes", contributions.documentTypes, "name"),
520
+ consentItem("actions", manifest.actions, "label"),
521
+ consentItem("templates", contributions.templates, "name"),
522
+ consentItem("assets", contributions.assets, "path"),
523
+ ].filter((item) => item !== null);
524
+ if (asRecord(manifest.databaseCompatibility)?.storageType === "structured")
525
+ consent.push({ id: "structuredStorage", details: [] });
526
+ return {
527
+ consent,
528
+ sampleContent: shipped.sampleContent
529
+ ? { default: true, ...(shipped.sampleContentDescription ? { description: shipped.sampleContentDescription } : {}) }
530
+ : null,
531
+ roles: (manifest.roles ?? []).map(({ id, label, actions }) => ({ id, label, actions: [...actions], default: false })),
532
+ // A JSON round trip: the declaration is plain data, and the caller may
533
+ // change what it is handed without touching the manifest.
534
+ steps: manifest.install ? JSON.parse(JSON.stringify(manifest.install.steps)) : [],
535
+ };
536
+ }
@@ -0,0 +1,75 @@
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
+ export declare function summarizePluginLanguages(bundles: ReadonlyMap<string, PluginLocaleFile>, docs: string): PluginLanguages;