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