@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,111 @@
1
+ import type { PluginInstallDeclaration, PluginReference } from "@kardalum/api-schemas";
2
+ type LabelMap = {
3
+ en: string;
4
+ [locale: string]: string;
5
+ };
6
+ /** What buildReference reads from a manifest, named structurally because this
7
+ * package cannot import the SDK (the SDK depends on it). The SDK asserts that
8
+ * its PluginManifest is assignable to this, so a field the builder cannot
9
+ * read is an SDK compile error (spec D3). */
10
+ export interface ReferenceManifestInput {
11
+ actions?: ReadonlyArray<{
12
+ id: string;
13
+ label: string;
14
+ }>;
15
+ roles?: ReadonlyArray<{
16
+ id: string;
17
+ label: string;
18
+ actions: readonly string[];
19
+ }>;
20
+ databaseCompatibility?: {
21
+ storageType?: string;
22
+ };
23
+ assertions?: {
24
+ externalNetwork?: {
25
+ reason: string;
26
+ };
27
+ filesystemAccess?: {
28
+ reason: string;
29
+ };
30
+ };
31
+ migrations?: ReadonlyArray<{
32
+ id: string;
33
+ name: string;
34
+ }>;
35
+ install?: PluginInstallDeclaration;
36
+ contributions: {
37
+ apiRoutes?: ReadonlyArray<{
38
+ method: string;
39
+ path: string;
40
+ access?: string;
41
+ action?: string;
42
+ }>;
43
+ documentTypes?: ReadonlyArray<{
44
+ name: string;
45
+ kind: string;
46
+ }>;
47
+ dataTypes?: ReadonlyArray<{
48
+ id: string;
49
+ name: string;
50
+ icon?: string;
51
+ version?: string;
52
+ schema?: unknown;
53
+ settingsSchema?: unknown;
54
+ defaultSettings?: unknown;
55
+ }>;
56
+ templates?: ReadonlyArray<{
57
+ name: string;
58
+ alias: string;
59
+ kind: string;
60
+ documentType?: string;
61
+ }>;
62
+ settingsPages?: ReadonlyArray<{
63
+ id: string;
64
+ name: string;
65
+ action: string;
66
+ }>;
67
+ adminSections?: ReadonlyArray<{
68
+ id: string;
69
+ label: LabelMap;
70
+ action: string;
71
+ rail?: ReadonlyArray<{
72
+ id: string;
73
+ label: LabelMap;
74
+ action: string;
75
+ }>;
76
+ }>;
77
+ railEntries?: ReadonlyArray<{
78
+ id: string;
79
+ label: LabelMap;
80
+ section: string;
81
+ action: string;
82
+ }>;
83
+ dashboardWidgets?: ReadonlyArray<{
84
+ id: string;
85
+ name: string;
86
+ action: string;
87
+ }>;
88
+ editorToolbar?: ReadonlyArray<{
89
+ id: string;
90
+ label: string;
91
+ action: string;
92
+ }>;
93
+ contentTreeActions?: ReadonlyArray<{
94
+ id: string;
95
+ label: string;
96
+ action: string;
97
+ }>;
98
+ hooks?: object;
99
+ scheduledTasks?: ReadonlyArray<{
100
+ id: string;
101
+ name: string;
102
+ cron: string;
103
+ }>;
104
+ };
105
+ }
106
+ /** The serialisable facts the seven generated Reference pages are rendered
107
+ * from (spec 3.2). Only plain data: never a view, a handler or a hook. The
108
+ * CLI writes it to reference.json; the server builds it live from the
109
+ * attached manifest. */
110
+ export declare function buildReference(manifest: ReferenceManifestInput): PluginReference;
111
+ export {};
@@ -0,0 +1,61 @@
1
+ import { ASSERTION_KEYS, deriveCapabilities } from "./capabilities.js";
2
+ /** Drops functions, components and undefined values by a JSON round trip. */
3
+ function plain(value) {
4
+ return JSON.parse(JSON.stringify(value));
5
+ }
6
+ /** A slot label's string entries only. */
7
+ function labelMap(label) {
8
+ return Object.fromEntries(Object.entries(label).filter(([, text]) => typeof text === "string"));
9
+ }
10
+ /** The serialisable facts the seven generated Reference pages are rendered
11
+ * from (spec 3.2). Only plain data: never a view, a handler or a hook. The
12
+ * CLI writes it to reference.json; the server builds it live from the
13
+ * attached manifest. */
14
+ export function buildReference(manifest) {
15
+ const c = manifest.contributions;
16
+ return {
17
+ actions: (manifest.actions ?? []).map(({ id, label }) => ({ id, label })),
18
+ roles: (manifest.roles ?? []).map(({ id, label, actions }) => ({ id, label, actions: [...actions] })),
19
+ apiRoutes: (c.apiRoutes ?? []).map((route) => ({
20
+ method: route.method,
21
+ path: route.path,
22
+ // Anything but the three named tiers falls back to "admin" at dispatch.
23
+ access: route.access ?? "admin",
24
+ ...(route.action ? { action: route.action } : {}),
25
+ })),
26
+ capabilities: deriveCapabilities(manifest).map(({ id, mediation, payload }) => ({ id, mediation, payload: { count: payload.count, details: [...payload.details] } })),
27
+ documentTypes: plain(c.documentTypes ?? []),
28
+ dataTypes: (c.dataTypes ?? []).map((type) => plain({ id: type.id, name: type.name, icon: type.icon, version: type.version, schema: type.schema, settingsSchema: type.settingsSchema, defaultSettings: type.defaultSettings })),
29
+ templates: (c.templates ?? []).map((t) => ({ name: t.name, alias: t.alias, kind: t.kind, ...(t.documentType ? { documentType: t.documentType } : {}) })),
30
+ settingsPages: (c.settingsPages ?? []).map(({ id, name, action }) => ({ id, name, action })),
31
+ adminSections: (c.adminSections ?? []).map((s) => ({
32
+ id: s.id,
33
+ label: labelMap(s.label),
34
+ action: s.action,
35
+ rail: (s.rail ?? []).map((e) => ({ id: e.id, label: labelMap(e.label), action: e.action })),
36
+ })),
37
+ railEntries: (c.railEntries ?? []).map((e) => ({ id: e.id, label: labelMap(e.label), section: e.section, action: e.action })),
38
+ dashboardWidgets: (c.dashboardWidgets ?? []).map(({ id, name, action }) => ({ id, name, action })),
39
+ editorToolbar: (c.editorToolbar ?? []).map(({ id, label, action }) => ({ id, label, action })),
40
+ contentTreeActions: (c.contentTreeActions ?? []).map(({ id, label, action }) => ({ id, label, action })),
41
+ hooks: Object.keys(c.hooks ?? {}),
42
+ scheduledTasks: (c.scheduledTasks ?? []).map(({ id, name, cron }) => ({ id, name, cron })),
43
+ migrations: (manifest.migrations ?? []).map(({ id, name }) => ({ id, name })),
44
+ assertions: ASSERTION_KEYS.flatMap((key) => {
45
+ const reason = manifest.assertions?.[key]?.reason;
46
+ return typeof reason === "string" && reason.trim() ? [{ key, reason }] : [];
47
+ }),
48
+ installOptions: (manifest.install?.steps ?? []).flatMap((step) => step.options.map((option) => ({
49
+ step: labelMap(step.label),
50
+ id: option.id,
51
+ label: labelMap(option.label),
52
+ kind: option.kind,
53
+ choices: option.kind === "boolean" ? [] : option.choices.map((choice) => ({ id: choice.id, label: labelMap(choice.label) })),
54
+ default: option.kind === "select" ? (option.default ?? null) : option.kind === "multiSelect" ? [...option.default] : option.default,
55
+ // installOptionNeedsAnswer in @kardalum/api-schemas, written inline
56
+ // because this module may take only types from there
57
+ // (reference-entry.test.ts); build-reference.test.ts pins the two.
58
+ required: option.kind === "select" && option.default === undefined && option.required !== false,
59
+ }))),
60
+ };
61
+ }
@@ -0,0 +1,103 @@
1
+ /**
2
+ * What a plugin can do, computed from what it declares (S267, section 3,
3
+ * implemented by S268 Task 5, moved here from the SDK by S289 so the one
4
+ * reference builder can call it; the SDK re-exports it and keeps the labels).
5
+ *
6
+ * **A capability is derived, not declared.** The author writes
7
+ * `contributions` (concrete, carrying payloads), `assertions` (the short
8
+ * list of claims nothing can check) and `databaseCompatibility`. This
9
+ * module reads those and produces the list. One source of truth, three
10
+ * renderings: the install screen shows it as consent items, the review
11
+ * queue highlights its promised entries for the reviewer, and the
12
+ * generated reference page prints it. An author cannot claim a capability
13
+ * they do not have, and cannot quietly have one they did not claim.
14
+ *
15
+ * **Disclosure, not enforcement** (S267 section 7). Plugin backend code
16
+ * runs unsandboxed and in-process, so this list is what the author says
17
+ * and what review checks, never what the runtime confines. The mediated
18
+ * entries are genuinely enforced, because the host owns the decision. The
19
+ * promised ones are promises.
20
+ */
21
+ /**
22
+ * `mediated`: the host bounds the outcome. It decides where the view
23
+ * renders, which gate the route sits behind, whether the action passes.
24
+ * The host enforces a mediated capability, so there is nothing in the
25
+ * plugin's code to read it against.
26
+ *
27
+ * `promised`: only the plugin's own code can honour it, so a reviewer reads
28
+ * it against that code.
29
+ */
30
+ export type CapabilityMediation = "mediated" | "promised";
31
+ /**
32
+ * The part of the declaration that produced a capability which is safe to
33
+ * store and to render: never a live function, never a Zod schema.
34
+ *
35
+ * `details` is a list of plain identifying strings, not sentences, so each
36
+ * of the three readers can put its own heading in front of them and none
37
+ * has to re-derive them from the manifest. For an assertion the detail IS
38
+ * the author's reason, because a reason is the whole content of an
39
+ * assertion.
40
+ */
41
+ export interface CapabilityPayload {
42
+ /** How many declarations produced this capability. 1 for a declaration
43
+ * that is not a list (themeTokens, an assertion, structured storage). */
44
+ count: number;
45
+ /** One line per declaration, in declaration order. Empty when the
46
+ * declaration carries no readable per-entry detail. */
47
+ details: string[];
48
+ }
49
+ export interface Capability {
50
+ /** Stable, dotted, and never reused for a different meaning. Persisted
51
+ * on a marketplace version row and rendered by three surfaces, so a
52
+ * renamed id is a data migration, not a cosmetic change. */
53
+ id: string;
54
+ payload: CapabilityPayload;
55
+ mediation: CapabilityMediation;
56
+ }
57
+ /**
58
+ * Every contribution key, in the order capabilities are emitted, fixed here
59
+ * rather than taken from the manifest's own key order. Two manifests
60
+ * declaring the same things in a different order must produce the same
61
+ * list, or the install screen, the review queue and the reference page
62
+ * would each print a different ordering of one fact.
63
+ *
64
+ * Storage leads because it is the heaviest thing an operator consents to.
65
+ * The assertions trail because they are the claims with nothing behind
66
+ * them, and they read as a closing caveat rather than as a feature.
67
+ *
68
+ * This package cannot name the SDK's `PluginContributions` (the SDK depends
69
+ * on it), so the SDK asserts at the type level that these 19 keys are
70
+ * exactly `keyof PluginContributions`: a twentieth contribution added to the
71
+ * contract and not classified here is a compile error in the SDK's build.
72
+ */
73
+ export declare const CONTRIBUTION_EMISSION_ORDER: readonly ["dataTypes", "documentTypes", "adminSections", "railEntries", "dashboardWidgets", "settingsPages", "contentTreeActions", "editorToolbar", "templates", "assets", "themeTokens", "hooks", "scheduledTasks", "mediaProcessors", "serializers", "apiRoutes", "exposedServices", "bundledPlugins", "bundledTemplate"];
74
+ export type ContributionKey = (typeof CONTRIBUTION_EMISSION_ORDER)[number];
75
+ /** The assertion kinds, in emission order. The SDK asserts these are
76
+ * exactly `keyof PluginAssertions`, for the reason above. */
77
+ export declare const ASSERTION_KEYS: readonly ["externalNetwork", "filesystemAccess"];
78
+ export type AssertionKey = (typeof ASSERTION_KEYS)[number];
79
+ /** Whether this contribution kind sits behind a named permission action.
80
+ * Lives on CONTRIBUTION_RULES rather than in a separate list, because that
81
+ * record is compiler-total over the 19 contribution keys: a twentieth key
82
+ * cannot be added without classifying it here. */
83
+ export declare function isActionGated(key: ContributionKey): boolean;
84
+ /** Every capability id this contract can produce, for the readers that
85
+ * need to be pinned against it (the marketplace's static mirror) and for
86
+ * the reference page S289 generates. */
87
+ export declare const CAPABILITY_IDS: readonly string[];
88
+ /**
89
+ * Compute a manifest's capability list.
90
+ *
91
+ * Accepts both a live `PluginManifest` and the redacted, JSON-safe summary
92
+ * kardalum plugin writes into a package's `manifest.json`, for the same
93
+ * reason `declaresClientBundle` does: the marketplace never executes
94
+ * plugin code, so the only manifest it can read is the redacted one, and
95
+ * the two sides of an install must not disagree about what a package
96
+ * declares.
97
+ *
98
+ * Defensive about its input rather than trusting it. It is handed parsed
99
+ * JSON from an artifact an author built, so a missing or wrongly-shaped
100
+ * field degrades to "declares nothing" for that field instead of throwing
101
+ * inside a review queue listing.
102
+ */
103
+ export declare function deriveCapabilities(manifest: unknown): Capability[];
@@ -0,0 +1,351 @@
1
+ /**
2
+ * What a plugin can do, computed from what it declares (S267, section 3,
3
+ * implemented by S268 Task 5, moved here from the SDK by S289 so the one
4
+ * reference builder can call it; the SDK re-exports it and keeps the labels).
5
+ *
6
+ * **A capability is derived, not declared.** The author writes
7
+ * `contributions` (concrete, carrying payloads), `assertions` (the short
8
+ * list of claims nothing can check) and `databaseCompatibility`. This
9
+ * module reads those and produces the list. One source of truth, three
10
+ * renderings: the install screen shows it as consent items, the review
11
+ * queue highlights its promised entries for the reviewer, and the
12
+ * generated reference page prints it. An author cannot claim a capability
13
+ * they do not have, and cannot quietly have one they did not claim.
14
+ *
15
+ * **Disclosure, not enforcement** (S267 section 7). Plugin backend code
16
+ * runs unsandboxed and in-process, so this list is what the author says
17
+ * and what review checks, never what the runtime confines. The mediated
18
+ * entries are genuinely enforced, because the host owns the decision. The
19
+ * promised ones are promises.
20
+ */
21
+ /**
22
+ * Every contribution key, in the order capabilities are emitted, fixed here
23
+ * rather than taken from the manifest's own key order. Two manifests
24
+ * declaring the same things in a different order must produce the same
25
+ * list, or the install screen, the review queue and the reference page
26
+ * would each print a different ordering of one fact.
27
+ *
28
+ * Storage leads because it is the heaviest thing an operator consents to.
29
+ * The assertions trail because they are the claims with nothing behind
30
+ * them, and they read as a closing caveat rather than as a feature.
31
+ *
32
+ * This package cannot name the SDK's `PluginContributions` (the SDK depends
33
+ * on it), so the SDK asserts at the type level that these 19 keys are
34
+ * exactly `keyof PluginContributions`: a twentieth contribution added to the
35
+ * contract and not classified here is a compile error in the SDK's build.
36
+ */
37
+ export const CONTRIBUTION_EMISSION_ORDER = [
38
+ "dataTypes",
39
+ "documentTypes",
40
+ "adminSections",
41
+ "railEntries",
42
+ "dashboardWidgets",
43
+ "settingsPages",
44
+ "contentTreeActions",
45
+ "editorToolbar",
46
+ "templates",
47
+ "assets",
48
+ "themeTokens",
49
+ "hooks",
50
+ "scheduledTasks",
51
+ "mediaProcessors",
52
+ "serializers",
53
+ "apiRoutes",
54
+ "exposedServices",
55
+ "bundledPlugins",
56
+ "bundledTemplate",
57
+ ];
58
+ /** The assertion kinds, in emission order. The SDK asserts these are
59
+ * exactly `keyof PluginAssertions`, for the reason above. */
60
+ export const ASSERTION_KEYS = ["externalNetwork", "filesystemAccess"];
61
+ /**
62
+ * Every contribution key, classified. Keyed by `ContributionKey` (which the
63
+ * SDK pins to `keyof PluginContributions`) rather than by a loose string, so
64
+ * a contribution added to the contract and not classified here is a compile
65
+ * error rather than a capability that silently never appears on an install
66
+ * screen.
67
+ *
68
+ * Classification follows S267 section 6 and its stated principle: a
69
+ * capability is mediated when the platform decides the outcome, and promised
70
+ * when the plugin does. Every contribution below is mediated,
71
+ * because every one of them is consumed by the host: it mounts the view,
72
+ * dispatches the hook, runs the task, registers the template. The only
73
+ * contribution that is not wholly mediated is `apiRoutes`, and only for
74
+ * the tiers that let traffic reach a handler without an admin session.
75
+ *
76
+ * `exposedServices`, `bundledPlugins` and `bundledTemplate` are not named
77
+ * in section 6's automatic list, which enumerates a policy rather than the
78
+ * contract's keys. They are classified mediated here rather than dropped:
79
+ * the marketplace resolves the two bundle keys, and the cross-plugin
80
+ * service registry (when it exists) is the host's own lookup.
81
+ * `exposedServices` reads promised until you remember that plugin backend
82
+ * code is unsandboxed and in-process already, so handing another plugin a
83
+ * service adds a lookup rather than a privilege it could not otherwise
84
+ * reach. Emitting them highlights nothing for the reviewer, since the host
85
+ * enforces a mediated capability, and not emitting them would be the exact
86
+ * failure this design exists to prevent, a declaration the install screen
87
+ * does not disclose.
88
+ */
89
+ const CONTRIBUTION_RULES = {
90
+ dataTypes: { derives: "one", id: "content.dataType", mediation: "mediated", actionGated: false },
91
+ documentTypes: { derives: "one", id: "content.documentType", mediation: "mediated", actionGated: false },
92
+ adminSections: { derives: "one", id: "admin.section", mediation: "mediated", actionGated: true },
93
+ // S280: a rail entry in a built-in section. Mediated like a section: the
94
+ // host decides where it renders and checks its action before it does. A
95
+ // section's own rail entries are part of the section's declaration, so
96
+ // they are disclosed under admin.section rather than counted here.
97
+ railEntries: { derives: "one", id: "admin.railEntry", mediation: "mediated", actionGated: true },
98
+ dashboardWidgets: { derives: "one", id: "admin.dashboardWidget", mediation: "mediated", actionGated: true },
99
+ settingsPages: { derives: "one", id: "admin.settingsPage", mediation: "mediated", actionGated: true },
100
+ contentTreeActions: { derives: "one", id: "admin.contentTreeAction", mediation: "mediated", actionGated: true },
101
+ editorToolbar: { derives: "one", id: "admin.editorToolbarItem", mediation: "mediated", actionGated: true },
102
+ templates: { derives: "one", id: "render.template", mediation: "mediated", actionGated: false },
103
+ assets: { derives: "one", id: "render.asset", mediation: "mediated", actionGated: false },
104
+ themeTokens: { derives: "one", id: "theme.tokens", mediation: "mediated", actionGated: false },
105
+ hooks: { derives: "one", id: "server.hook", mediation: "mediated", actionGated: false },
106
+ scheduledTasks: { derives: "one", id: "server.scheduledTask", mediation: "mediated", actionGated: false },
107
+ mediaProcessors: { derives: "one", id: "media.processor", mediation: "mediated", actionGated: false },
108
+ serializers: { derives: "one", id: "api.serializer", mediation: "mediated", actionGated: false },
109
+ exposedServices: { derives: "one", id: "service.exposed", mediation: "mediated", actionGated: false },
110
+ bundledPlugins: { derives: "one", id: "bundle.plugin", mediation: "mediated", actionGated: false },
111
+ bundledTemplate: { derives: "one", id: "bundle.template", mediation: "mediated", actionGated: false },
112
+ apiRoutes: { derives: "perApiRouteTier", actionGated: true },
113
+ };
114
+ /** Whether this contribution kind sits behind a named permission action.
115
+ * Lives on CONTRIBUTION_RULES rather than in a separate list, because that
116
+ * record is compiler-total over the 19 contribution keys: a twentieth key
117
+ * cannot be added without classifying it here. */
118
+ export function isActionGated(key) {
119
+ return CONTRIBUTION_RULES[key].actionGated;
120
+ }
121
+ /**
122
+ * The access tiers, in emission order, with the classification S267
123
+ * section 6 gives each.
124
+ *
125
+ * `admin` is mediated: the host checks the JWT admin session before the
126
+ * handler runs. `apiKey` and `public` are promised: the host enforces the
127
+ * tier, but a route reachable without an admin session is an abuse surface
128
+ * whose handling belongs to the author.
129
+ */
130
+ const API_ROUTE_TIERS = [
131
+ { tier: "admin", id: "api.route.admin", mediation: "mediated" },
132
+ { tier: "apiKey", id: "api.route.apiKey", mediation: "promised" },
133
+ { tier: "public", id: "api.route.public", mediation: "promised" },
134
+ ];
135
+ /**
136
+ * The tier a route actually runs at.
137
+ *
138
+ * This is a real coupling to `apps/server/src/routes/plugin-api-routes.ts`,
139
+ * which resolves `route.access ?? "admin"` and documents that anything
140
+ * unrecognised falls back to `admin`, secure by default. If the two
141
+ * disagreed, the install screen would promise a gate the runtime does not
142
+ * apply, or warn about one it does. The dispatcher is canonical; this
143
+ * follows it.
144
+ */
145
+ function routeTier(access) {
146
+ const match = API_ROUTE_TIERS.find((entry) => entry.tier === access);
147
+ return match ?? API_ROUTE_TIERS[0];
148
+ }
149
+ /**
150
+ * Capability id per assertion, in emission order. The reason the author
151
+ * gave is the capability's only detail, because the reason is the only
152
+ * checkable thing an assertion carries.
153
+ *
154
+ * Keyed by `AssertionKey` (pinned by the SDK to `keyof PluginAssertions`)
155
+ * for the same reason CONTRIBUTION_RULES is keyed by `ContributionKey`, and
156
+ * with more force: an unclassified contribution is at worst an undisclosed
157
+ * mediated addition, while an unclassified assertion is an undisclosed
158
+ * PROMISE, so it would never reach the consent list and never be
159
+ * highlighted for the reviewer. A third kind added to the type and not here
160
+ * is a compile error.
161
+ */
162
+ const ASSERTION_RULES = {
163
+ externalNetwork: "network.external",
164
+ filesystemAccess: "filesystem.access",
165
+ };
166
+ /** The rules as the derivation walks them, in ASSERTION_KEYS order. */
167
+ const ASSERTION_ENTRIES = ASSERTION_KEYS.map((key) => [key, ASSERTION_RULES[key]]);
168
+ /**
169
+ * Derived from `databaseCompatibility.storageType`, and NOT from a
170
+ * contribution: `PluginContributions` has no storage-shaped key and the
171
+ * contract cannot silently grow one. Declaring structured storage IS the
172
+ * declaration that the plugin owns real tables. The server agrees: it
173
+ * persists `storageType` on the installed-plugin row, because uninstall
174
+ * has to answer that question without the manifest.
175
+ */
176
+ const STRUCTURED_STORAGE_ID = "storage.structured";
177
+ /** Every capability id this contract can produce, for the readers that
178
+ * need to be pinned against it (the marketplace's static mirror) and for
179
+ * the reference page S289 generates. */
180
+ export const CAPABILITY_IDS = [
181
+ STRUCTURED_STORAGE_ID,
182
+ ...CONTRIBUTION_EMISSION_ORDER.flatMap((key) => {
183
+ const rule = CONTRIBUTION_RULES[key];
184
+ return rule.derives === "one" ? [rule.id] : API_ROUTE_TIERS.map((entry) => entry.id);
185
+ }),
186
+ ...ASSERTION_ENTRIES.map(([, id]) => id),
187
+ ];
188
+ // ---------------------------------------------------------------------------
189
+ // Reading a declaration's readable detail
190
+ // ---------------------------------------------------------------------------
191
+ /** The plain string fields a contribution entry can be named by, in the
192
+ * order they are preferred. Every one of them survives the redaction
193
+ * kardalum plugin applies when it writes a package's manifest.json, which
194
+ * is the only form the marketplace ever sees. */
195
+ const ENTRY_NAME_FIELDS = ["name", "label", "alias", "file", "id"];
196
+ /** A slot's label is a map of language to text (S280), and the detail is a
197
+ * plain identifying string, so a label map reads as its English text, the
198
+ * one language every label must carry. A map without readable English
199
+ * yields nothing, and the next name field is tried. */
200
+ function readableField(value) {
201
+ if (typeof value === "string")
202
+ return value.trim() ? value : null;
203
+ if (value !== null && typeof value === "object" && !Array.isArray(value)) {
204
+ const en = value.en;
205
+ if (typeof en === "string" && en.trim())
206
+ return en;
207
+ }
208
+ return null;
209
+ }
210
+ function describeEntry(entry) {
211
+ if (typeof entry === "string")
212
+ return entry.trim() || null;
213
+ if (entry === null || typeof entry !== "object")
214
+ return null;
215
+ const record = entry;
216
+ // An apiRoute is named by what it exposes, not by an id it has no field
217
+ // for: "GET /orders" is the thing a reviewer looks up in the code.
218
+ if (typeof record.method === "string" && typeof record.path === "string") {
219
+ return `${record.method} ${record.path}`;
220
+ }
221
+ for (const field of ENTRY_NAME_FIELDS) {
222
+ const value = readableField(record[field]);
223
+ if (value !== null)
224
+ return value;
225
+ }
226
+ return null;
227
+ }
228
+ /**
229
+ * Normalises one declared contribution value into the entries that
230
+ * produced it, handling the three shapes the contract uses: a list, the
231
+ * `hooks` map (whose keys are the events, and which arrives as a plain key
232
+ * array once redacted), and a single object like `themeTokens`.
233
+ *
234
+ * Returns an empty list for a declaration that declares nothing, which is
235
+ * the same rule `declaresClientBundle` applies: a present-but-empty array
236
+ * or object buys nothing. The one shape that is NOT nothing is the
237
+ * redactor's `true`, which is a declaration stripped of its detail rather
238
+ * than an absent one.
239
+ */
240
+ function declaredEntries(key, value) {
241
+ if (value === null || value === undefined)
242
+ return [];
243
+ if (Array.isArray(value))
244
+ return value;
245
+ // `true` is what kardalum plugin's redactor writes for a contribution it
246
+ // can keep no safe per-entry detail from (`serializers` is the only key
247
+ // that lands there today). It means "declared, nothing readable to
248
+ // show", which is exactly one entry with no detail, the same answer the
249
+ // live object form gives. Reading it as "declares nothing" is what made
250
+ // every marketplace surface omit a capability the SDK derived from the
251
+ // same plugin.
252
+ if (value === true)
253
+ return [true];
254
+ if (typeof value !== "object")
255
+ return [];
256
+ // `hooks` is Record<event, handler> live and string[] once redacted; the
257
+ // array branch above already covered the redacted form.
258
+ if (key === "hooks")
259
+ return Object.keys(value);
260
+ // A present-but-empty object buys nothing, which is the rule the array
261
+ // branch gets for free: `themeTokens: {}` declares no tokens, so it is
262
+ // not a theme capability.
263
+ return Object.keys(value).length === 0 ? [] : [value];
264
+ }
265
+ // ---------------------------------------------------------------------------
266
+ // The derivation
267
+ // ---------------------------------------------------------------------------
268
+ /**
269
+ * Compute a manifest's capability list.
270
+ *
271
+ * Accepts both a live `PluginManifest` and the redacted, JSON-safe summary
272
+ * kardalum plugin writes into a package's `manifest.json`, for the same
273
+ * reason `declaresClientBundle` does: the marketplace never executes
274
+ * plugin code, so the only manifest it can read is the redacted one, and
275
+ * the two sides of an install must not disagree about what a package
276
+ * declares.
277
+ *
278
+ * Defensive about its input rather than trusting it. It is handed parsed
279
+ * JSON from an artifact an author built, so a missing or wrongly-shaped
280
+ * field degrades to "declares nothing" for that field instead of throwing
281
+ * inside a review queue listing.
282
+ */
283
+ export function deriveCapabilities(manifest) {
284
+ if (manifest === null || typeof manifest !== "object")
285
+ return [];
286
+ const source = manifest;
287
+ const capabilities = [];
288
+ const databaseCompatibility = source.databaseCompatibility;
289
+ const storageType = databaseCompatibility !== null && typeof databaseCompatibility === "object"
290
+ ? databaseCompatibility.storageType
291
+ : undefined;
292
+ if (storageType === "structured") {
293
+ capabilities.push({
294
+ id: STRUCTURED_STORAGE_ID,
295
+ payload: { count: 1, details: [] },
296
+ mediation: "promised",
297
+ });
298
+ }
299
+ const contributions = source.contributions !== null && typeof source.contributions === "object"
300
+ ? source.contributions
301
+ : {};
302
+ for (const key of CONTRIBUTION_EMISSION_ORDER) {
303
+ const entries = declaredEntries(key, contributions[key]);
304
+ if (entries.length === 0)
305
+ continue;
306
+ const rule = CONTRIBUTION_RULES[key];
307
+ if (rule.derives === "one") {
308
+ capabilities.push({
309
+ id: rule.id,
310
+ payload: {
311
+ count: entries.length,
312
+ details: entries.map(describeEntry).filter((detail) => detail !== null),
313
+ },
314
+ mediation: rule.mediation,
315
+ });
316
+ continue;
317
+ }
318
+ // One contribution, up to three capabilities: the routes are grouped
319
+ // by the tier the dispatcher will actually run them at.
320
+ for (const tier of API_ROUTE_TIERS) {
321
+ const routes = entries.filter((entry) => routeTier(entry !== null && typeof entry === "object" ? entry.access : undefined)
322
+ .tier === tier.tier);
323
+ if (routes.length === 0)
324
+ continue;
325
+ capabilities.push({
326
+ id: tier.id,
327
+ payload: {
328
+ count: routes.length,
329
+ details: routes.map(describeEntry).filter((detail) => detail !== null),
330
+ },
331
+ mediation: tier.mediation,
332
+ });
333
+ }
334
+ }
335
+ const assertions = source.assertions !== null && typeof source.assertions === "object"
336
+ ? source.assertions
337
+ : {};
338
+ for (const [key, id] of ASSERTION_ENTRIES) {
339
+ const declared = assertions[key];
340
+ if (declared === null || typeof declared !== "object")
341
+ continue;
342
+ const reason = declared.reason;
343
+ // An assertion without a readable reason is not consentable and not
344
+ // checkable, so it is dropped rather than rendered as a blank line.
345
+ // The SDK schema refuses it upstream; this guards a parsed artifact.
346
+ if (typeof reason !== "string" || !reason.trim())
347
+ continue;
348
+ capabilities.push({ id, payload: { count: 1, details: [reason] }, mediation: "promised" });
349
+ }
350
+ return capabilities;
351
+ }
@@ -1,10 +1,12 @@
1
1
  export type { PackageSignatureSidecar, SignatureEnvelope, TrustedKey, VerifyFailureReason, VerifyResult, } from "./types.js";
2
+ export { VERIFY_FAILURE_REASONS } from "./types.js";
2
3
  export { canonicalizeEnvelope, deriveKeyId, generateSigningKeyPair, signEnvelope, verifyEnvelope, } from "./envelope.js";
3
4
  export type { LicenseChallenge, LicenseVerdictEnvelope, LicenseVerdictResult, LicenseVerdictSignatureResult, SignedLicenseVerdict, TamperKind, } from "./license-verdict.js";
4
5
  export { canonicalizeLicenseVerdict, createLicenseChallenge, ENTITLEMENT_MAX_AGE_MS, hashLicenseKey, LICENSE_VERDICT_DETAIL_MAX, MAX_VERDICT_AGE_MS, signLicenseVerdict, verifyLicenseVerdict, verifyLicenseVerdictSignature, } from "./license-verdict.js";
5
6
  export { hashBuffer, hashArchive, hashDirectories } from "./hash.js";
6
7
  export { entryViolation, extractArtifact, MAX_ENTRIES, MAX_ENTRY_BYTES, MAX_TOTAL_BYTES } from "./extract.js";
7
- export { SAMPLE_CONTENT_MEDIA_FILE_PATTERN } from "./sample-content.js";
8
+ export { SAMPLE_CONTENT_MAX_BYTES, readShippedInstallFacts, readShippedSampleContent } from "./sample-content.js";
9
+ export type { ShippedSampleContent } from "./sample-content.js";
8
10
  export type { PackageContractCheck } from "./package-contract.js";
9
11
  export { checkCoverContract, checkPackageContract, checkReadmeContract, COVER_HEIGHT, COVER_PATH, COVER_WIDTH, pngSize, } from "./package-contract.js";
10
12
  export type { DocsContractInput } from "./docs-contract.js";
@@ -1,7 +1,8 @@
1
+ export { VERIFY_FAILURE_REASONS } from "./types.js";
1
2
  export { canonicalizeEnvelope, deriveKeyId, generateSigningKeyPair, signEnvelope, verifyEnvelope, } from "./envelope.js";
2
3
  export { canonicalizeLicenseVerdict, createLicenseChallenge, ENTITLEMENT_MAX_AGE_MS, hashLicenseKey, LICENSE_VERDICT_DETAIL_MAX, MAX_VERDICT_AGE_MS, signLicenseVerdict, verifyLicenseVerdict, verifyLicenseVerdictSignature, } from "./license-verdict.js";
3
4
  export { hashBuffer, hashArchive, hashDirectories } from "./hash.js";
4
5
  export { entryViolation, extractArtifact, MAX_ENTRIES, MAX_ENTRY_BYTES, MAX_TOTAL_BYTES } from "./extract.js";
5
- export { SAMPLE_CONTENT_MEDIA_FILE_PATTERN } from "./sample-content.js";
6
+ export { SAMPLE_CONTENT_MAX_BYTES, readShippedInstallFacts, readShippedSampleContent } from "./sample-content.js";
6
7
  export { checkCoverContract, checkPackageContract, checkReadmeContract, COVER_HEIGHT, COVER_PATH, COVER_WIDTH, pngSize, } from "./package-contract.js";
7
8
  export { capViolations, checkDocsContract, countRemoteImages, docsFilesToShip, MAX_PACKAGE_JSON_BYTES, MAX_VIOLATIONS, packageFilePath, readDocsContractInput } from "./docs-contract.js";
@@ -0,0 +1,2 @@
1
+ export * from "./capabilities.js";
2
+ export * from "./build-reference.js";
@@ -0,0 +1,6 @@
1
+ // @kardalum/plugin-package/reference: the capability derivation and the
2
+ // reference builder, with no node: import and no third-party import, so the
3
+ // SDK's browser entries can re-export them (S289, spec 3.1).
4
+ // reference-entry.test.ts holds that line.
5
+ export * from "./capabilities.js";
6
+ export * from "./build-reference.js";