@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.
Files changed (204) hide show
  1. package/CHANGELOG.md +49 -1
  2. package/README.md +10 -0
  3. package/dist/admin-section-registry.d.ts +14 -5
  4. package/dist/admin-section-registry.js +14 -4
  5. package/dist/built-in-value-schemas.js +1 -1
  6. package/dist/built-ins.js +2 -2
  7. package/dist/capabilities.d.ts +8 -78
  8. package/dist/capabilities.js +23 -322
  9. package/dist/host-entry.d.ts +1 -1
  10. package/dist/host-entry.js +1 -1
  11. package/dist/index.d.ts +5 -5
  12. package/dist/index.js +13 -12
  13. package/dist/license-verdict-keys.d.ts +4 -3
  14. package/dist/license-verdict-keys.js +6 -5
  15. package/dist/manifest-entry.d.ts +3 -3
  16. package/dist/manifest-entry.js +2 -2
  17. package/dist/manifest-schema.d.ts +113 -56
  18. package/dist/manifest-schema.js +192 -295
  19. package/dist/manifest.d.ts +145 -112
  20. package/dist/manifest.js +13 -36
  21. package/dist/media/media-picker.js +21 -12
  22. package/dist/media/upload-error.d.ts +1 -1
  23. package/dist/media/upload-error.js +1 -1
  24. package/dist/plugin-context.d.ts +7 -0
  25. package/dist/plugin-context.js +7 -0
  26. package/dist/plugin-screen-context.d.ts +44 -3
  27. package/dist/plugin-screen-context.js +27 -2
  28. package/dist/read-all-pages.d.ts +23 -0
  29. package/dist/read-all-pages.js +30 -0
  30. package/dist/richtext/block-panel.js +6 -6
  31. package/dist/richtext/insert-menu.js +4 -4
  32. package/dist/richtext/style-listbox.js +4 -4
  33. package/dist/tokens/tokens.css +1 -0
  34. package/dist/tokens/tokens.json +2 -1
  35. package/dist/type-equality.d.ts +2 -0
  36. package/dist/type-equality.js +1 -0
  37. package/dist/views/content-list-view.js +2 -2
  38. package/dist/views/html-view.js +1 -1
  39. package/dist/views/image-view.js +24 -39
  40. package/dist/views/rich-text-view.js +3 -3
  41. package/node_modules/@kardalum/api-schemas/dist/api-error.schema.d.ts +12 -0
  42. package/node_modules/@kardalum/api-schemas/dist/api-error.schema.js +19 -0
  43. package/node_modules/@kardalum/api-schemas/dist/api-key-api.schema.d.ts +43 -25
  44. package/node_modules/@kardalum/api-schemas/dist/api-key-api.schema.js +60 -8
  45. package/node_modules/@kardalum/api-schemas/dist/asset-api.schema.d.ts +90 -0
  46. package/node_modules/@kardalum/api-schemas/dist/asset-api.schema.js +33 -2
  47. package/node_modules/@kardalum/api-schemas/dist/asset.schema.d.ts +22 -1
  48. package/node_modules/@kardalum/api-schemas/dist/asset.schema.js +50 -15
  49. package/node_modules/@kardalum/api-schemas/dist/audit-api.schema.d.ts +204 -0
  50. package/node_modules/@kardalum/api-schemas/dist/audit-api.schema.js +134 -0
  51. package/node_modules/@kardalum/api-schemas/dist/content-api.schema.d.ts +5 -0
  52. package/node_modules/@kardalum/api-schemas/dist/content-api.schema.js +18 -13
  53. package/node_modules/@kardalum/api-schemas/dist/content-list.schema.d.ts +2 -2
  54. package/node_modules/@kardalum/api-schemas/dist/content-list.schema.js +1 -1
  55. package/node_modules/@kardalum/api-schemas/dist/content-path.js +11 -7
  56. package/node_modules/@kardalum/api-schemas/dist/content-trash-api.schema.d.ts +4 -0
  57. package/node_modules/@kardalum/api-schemas/dist/content-trash-api.schema.js +3 -0
  58. package/node_modules/@kardalum/api-schemas/dist/content-trash.schema.d.ts +1 -0
  59. package/node_modules/@kardalum/api-schemas/dist/content-trash.schema.js +2 -1
  60. package/node_modules/@kardalum/api-schemas/dist/core-actions.d.ts +143 -57
  61. package/node_modules/@kardalum/api-schemas/dist/core-actions.js +110 -60
  62. package/node_modules/@kardalum/api-schemas/dist/data-type-api.schema.d.ts +1 -0
  63. package/node_modules/@kardalum/api-schemas/dist/document-type-api.schema.d.ts +2 -0
  64. package/node_modules/@kardalum/api-schemas/dist/document-type-api.schema.js +1 -1
  65. package/node_modules/@kardalum/api-schemas/dist/index.d.ts +67 -40
  66. package/node_modules/@kardalum/api-schemas/dist/index.js +35 -19
  67. package/node_modules/@kardalum/api-schemas/dist/install-warnings.schema.d.ts +4 -0
  68. package/node_modules/@kardalum/api-schemas/dist/install-warnings.schema.js +8 -0
  69. package/node_modules/@kardalum/api-schemas/dist/issue-list.d.ts +6 -0
  70. package/node_modules/@kardalum/api-schemas/dist/issue-list.js +6 -0
  71. package/node_modules/@kardalum/api-schemas/dist/management-multipart.schema.d.ts +73 -0
  72. package/node_modules/@kardalum/api-schemas/dist/management-multipart.schema.js +104 -0
  73. package/node_modules/@kardalum/api-schemas/dist/marketplace-listing-api.schema.d.ts +356 -16
  74. package/node_modules/@kardalum/api-schemas/dist/marketplace-listing-api.schema.js +93 -10
  75. package/node_modules/@kardalum/api-schemas/dist/media-api.schema.d.ts +10 -0
  76. package/node_modules/@kardalum/api-schemas/dist/media-api.schema.js +38 -30
  77. package/node_modules/@kardalum/api-schemas/dist/media-rendition.schema.js +2 -2
  78. package/node_modules/@kardalum/api-schemas/dist/media.schema.js +1 -1
  79. package/node_modules/@kardalum/api-schemas/dist/plugin-actions.schema.d.ts +6 -2
  80. package/node_modules/@kardalum/api-schemas/dist/plugin-actions.schema.js +8 -6
  81. package/node_modules/@kardalum/api-schemas/dist/plugin-docs-api.schema.d.ts +69 -4
  82. package/node_modules/@kardalum/api-schemas/dist/plugin-docs-api.schema.js +4 -0
  83. package/node_modules/@kardalum/api-schemas/dist/plugin-docs.d.ts +76 -9
  84. package/node_modules/@kardalum/api-schemas/dist/plugin-docs.js +84 -24
  85. package/node_modules/@kardalum/api-schemas/dist/plugin-id-rules.d.ts +17 -7
  86. package/node_modules/@kardalum/api-schemas/dist/plugin-id-rules.js +18 -8
  87. package/node_modules/@kardalum/api-schemas/dist/plugin-install-record.schema.d.ts +69 -0
  88. package/node_modules/@kardalum/api-schemas/dist/plugin-install-record.schema.js +59 -0
  89. package/node_modules/@kardalum/api-schemas/dist/plugin-install.d.ts +597 -0
  90. package/node_modules/@kardalum/api-schemas/dist/plugin-install.js +503 -0
  91. package/node_modules/@kardalum/api-schemas/dist/plugin-labels.d.ts +60 -0
  92. package/node_modules/@kardalum/api-schemas/dist/plugin-labels.js +116 -0
  93. package/node_modules/@kardalum/api-schemas/dist/plugin-locales.d.ts +82 -0
  94. package/node_modules/@kardalum/api-schemas/dist/plugin-locales.js +228 -0
  95. package/node_modules/@kardalum/api-schemas/dist/plugin-management-api.schema.d.ts +33 -4
  96. package/node_modules/@kardalum/api-schemas/dist/plugin-management-api.schema.js +28 -2
  97. package/node_modules/@kardalum/api-schemas/dist/plugin-manifest-actions.d.ts +11 -3
  98. package/node_modules/@kardalum/api-schemas/dist/plugin-manifest-actions.js +17 -4
  99. package/node_modules/@kardalum/api-schemas/dist/plugin-manifest-api-routes.d.ts +58 -0
  100. package/node_modules/@kardalum/api-schemas/dist/plugin-manifest-api-routes.js +198 -0
  101. package/node_modules/@kardalum/api-schemas/dist/plugin-manifest-fields.d.ts +64 -0
  102. package/node_modules/@kardalum/api-schemas/dist/plugin-manifest-fields.js +134 -0
  103. package/node_modules/@kardalum/api-schemas/dist/plugin-registry-api.schema.d.ts +2 -0
  104. package/node_modules/@kardalum/api-schemas/dist/plugin-registry-api.schema.js +4 -0
  105. package/node_modules/@kardalum/api-schemas/dist/plugin-template-payload.d.ts +74 -0
  106. package/node_modules/@kardalum/api-schemas/dist/plugin-template-payload.js +132 -0
  107. package/node_modules/@kardalum/api-schemas/dist/plugin-vocabulary.d.ts +13 -0
  108. package/node_modules/@kardalum/api-schemas/dist/plugin-vocabulary.js +15 -0
  109. package/node_modules/@kardalum/api-schemas/dist/public-api.schema.d.ts +8 -0
  110. package/node_modules/@kardalum/api-schemas/dist/public-api.schema.js +23 -4
  111. package/node_modules/@kardalum/api-schemas/dist/render-editing.d.ts +4 -4
  112. package/node_modules/@kardalum/api-schemas/dist/role.schema.d.ts +17 -0
  113. package/node_modules/@kardalum/api-schemas/dist/role.schema.js +13 -0
  114. package/node_modules/@kardalum/api-schemas/dist/sample-content.schema.d.ts +44 -0
  115. package/node_modules/@kardalum/api-schemas/dist/sample-content.schema.js +97 -0
  116. package/node_modules/@kardalum/api-schemas/dist/sandbox-attach.schema.d.ts +126 -0
  117. package/node_modules/@kardalum/api-schemas/dist/sandbox-attach.schema.js +70 -0
  118. package/node_modules/@kardalum/api-schemas/dist/setup-api.schema.d.ts +36 -6
  119. package/node_modules/@kardalum/api-schemas/dist/setup-api.schema.js +17 -5
  120. package/node_modules/@kardalum/api-schemas/dist/sites.schema.d.ts +52 -33
  121. package/node_modules/@kardalum/api-schemas/dist/sites.schema.js +195 -56
  122. package/node_modules/@kardalum/api-schemas/dist/snapshot-api.schema.d.ts +19 -3
  123. package/node_modules/@kardalum/api-schemas/dist/snapshot-api.schema.js +16 -0
  124. package/node_modules/@kardalum/api-schemas/dist/snapshot.schema.d.ts +1 -1
  125. package/node_modules/@kardalum/api-schemas/dist/strict-url.d.ts +12 -0
  126. package/node_modules/@kardalum/api-schemas/dist/strict-url.js +31 -0
  127. package/node_modules/@kardalum/api-schemas/dist/template-api.schema.d.ts +105 -1
  128. package/node_modules/@kardalum/api-schemas/dist/template-api.schema.js +47 -7
  129. package/node_modules/@kardalum/api-schemas/dist/template.schema.d.ts +30 -2
  130. package/node_modules/@kardalum/api-schemas/dist/template.schema.js +19 -5
  131. package/node_modules/@kardalum/api-schemas/dist/trash-cursor.schema.d.ts +4 -0
  132. package/node_modules/@kardalum/api-schemas/dist/trash-cursor.schema.js +29 -0
  133. package/node_modules/@kardalum/api-schemas/dist/user-api.schema.d.ts +15 -3
  134. package/node_modules/@kardalum/api-schemas/dist/user-api.schema.js +8 -0
  135. package/node_modules/@kardalum/api-schemas/dist/whoami-api.schema.d.ts +19 -0
  136. package/node_modules/@kardalum/api-schemas/dist/whoami-api.schema.js +22 -0
  137. package/node_modules/@kardalum/api-schemas/package.json +2 -2
  138. package/node_modules/@kardalum/design-tokens/dist/tailwind-theme.d.ts +1 -0
  139. package/node_modules/@kardalum/design-tokens/dist/tailwind-theme.js +2 -0
  140. package/node_modules/@kardalum/design-tokens/dist/tokens.css +1 -0
  141. package/node_modules/@kardalum/design-tokens/dist/tokens.js +3 -0
  142. package/node_modules/@kardalum/design-tokens/dist/tokens.json +2 -1
  143. package/node_modules/@kardalum/design-tokens/dist/types.d.ts +1 -0
  144. package/node_modules/@kardalum/plugin-package/README.md +4 -1
  145. package/node_modules/@kardalum/plugin-package/dist/build-reference.d.ts +96 -0
  146. package/node_modules/@kardalum/plugin-package/dist/build-reference.js +66 -0
  147. package/node_modules/@kardalum/plugin-package/dist/capabilities.d.ts +103 -0
  148. package/node_modules/@kardalum/plugin-package/dist/capabilities.js +346 -0
  149. package/node_modules/@kardalum/plugin-package/dist/client-bundle.d.ts +4 -0
  150. package/node_modules/@kardalum/plugin-package/dist/client-bundle.js +25 -0
  151. package/node_modules/@kardalum/plugin-package/dist/delivery/archive-names.d.ts +25 -0
  152. package/node_modules/@kardalum/plugin-package/dist/delivery/archive-names.js +203 -0
  153. package/node_modules/@kardalum/plugin-package/dist/delivery/bundle.d.ts +3 -0
  154. package/node_modules/@kardalum/plugin-package/dist/delivery/bundle.js +73 -0
  155. package/node_modules/@kardalum/plugin-package/dist/delivery/contributions.d.ts +5 -0
  156. package/node_modules/@kardalum/plugin-package/dist/delivery/contributions.js +60 -0
  157. package/node_modules/@kardalum/plugin-package/dist/delivery/icon-names.generated.d.ts +1 -0
  158. package/node_modules/@kardalum/plugin-package/dist/delivery/icon-names.generated.js +2052 -0
  159. package/node_modules/@kardalum/plugin-package/dist/delivery/icons.d.ts +2 -0
  160. package/node_modules/@kardalum/plugin-package/dist/delivery/icons.js +51 -0
  161. package/node_modules/@kardalum/plugin-package/dist/delivery/index.d.ts +8 -0
  162. package/node_modules/@kardalum/plugin-package/dist/delivery/index.js +7 -0
  163. package/node_modules/@kardalum/plugin-package/dist/delivery/label-languages.d.ts +17 -0
  164. package/node_modules/@kardalum/plugin-package/dist/delivery/label-languages.js +119 -0
  165. package/node_modules/@kardalum/plugin-package/dist/delivery/limits.d.ts +14 -0
  166. package/node_modules/@kardalum/plugin-package/dist/delivery/limits.js +21 -0
  167. package/node_modules/@kardalum/plugin-package/dist/delivery/locales.d.ts +5 -0
  168. package/node_modules/@kardalum/plugin-package/dist/delivery/locales.js +148 -0
  169. package/node_modules/@kardalum/plugin-package/dist/delivery/package-files.d.ts +5 -0
  170. package/node_modules/@kardalum/plugin-package/dist/delivery/package-files.js +76 -0
  171. package/node_modules/@kardalum/plugin-package/dist/delivery/registry.d.ts +22 -0
  172. package/node_modules/@kardalum/plugin-package/dist/delivery/registry.js +133 -0
  173. package/node_modules/@kardalum/plugin-package/dist/delivery/sample-content.d.ts +3 -0
  174. package/node_modules/@kardalum/plugin-package/dist/delivery/sample-content.js +90 -0
  175. package/node_modules/@kardalum/plugin-package/dist/delivery/support.d.ts +24 -0
  176. package/node_modules/@kardalum/plugin-package/dist/delivery/support.js +55 -0
  177. package/node_modules/@kardalum/plugin-package/dist/delivery/templates.d.ts +6 -0
  178. package/node_modules/@kardalum/plugin-package/dist/delivery/templates.js +158 -0
  179. package/node_modules/@kardalum/plugin-package/dist/delivery/types.d.ts +53 -0
  180. package/node_modules/@kardalum/plugin-package/dist/delivery/types.js +1 -0
  181. package/node_modules/@kardalum/plugin-package/dist/docs-contract.d.ts +3 -2
  182. package/node_modules/@kardalum/plugin-package/dist/docs-contract.js +4 -2
  183. package/node_modules/@kardalum/plugin-package/dist/extract.d.ts +92 -3
  184. package/node_modules/@kardalum/plugin-package/dist/extract.js +251 -41
  185. package/node_modules/@kardalum/plugin-package/dist/index.d.ts +11 -2
  186. package/node_modules/@kardalum/plugin-package/dist/index.js +8 -2
  187. package/node_modules/@kardalum/plugin-package/dist/manifest-entry.d.ts +5 -0
  188. package/node_modules/@kardalum/plugin-package/dist/manifest-entry.js +20 -0
  189. package/node_modules/@kardalum/plugin-package/dist/reference-entry.d.ts +3 -0
  190. package/node_modules/@kardalum/plugin-package/dist/reference-entry.js +7 -0
  191. package/node_modules/@kardalum/plugin-package/dist/sample-content.d.ts +38 -1
  192. package/node_modules/@kardalum/plugin-package/dist/sample-content.js +84 -16
  193. package/node_modules/@kardalum/plugin-package/dist/shipped-files.d.ts +39 -0
  194. package/node_modules/@kardalum/plugin-package/dist/shipped-files.js +133 -0
  195. package/node_modules/@kardalum/plugin-package/dist/shipped-locales.d.ts +7 -0
  196. package/node_modules/@kardalum/plugin-package/dist/shipped-locales.js +27 -0
  197. package/node_modules/@kardalum/plugin-package/dist/types.d.ts +4 -6
  198. package/node_modules/@kardalum/plugin-package/dist/types.js +15 -1
  199. package/node_modules/@kardalum/plugin-package/package.json +9 -2
  200. package/node_modules/@kardalum/ui/dist/components/checkbox.js +2 -2
  201. package/node_modules/@kardalum/ui/dist/components/dropdown-menu.js +2 -2
  202. package/node_modules/@kardalum/ui/dist/components/property-field.js +4 -1
  203. package/node_modules/@kardalum/ui/package.json +1 -1
  204. package/package.json +6 -6
@@ -1,6 +1,8 @@
1
1
  import type { ComponentType } from "react";
2
- import type { CreateDocumentTypeRequest, PluginDocsPage } from "@kardalum/api-schemas";
2
+ import type { CreateDocumentTypeRequest, PluginDocsPage, PluginInstallDeclaration, PluginLabel, ResolvedInstallAnswers } from "@kardalum/api-schemas";
3
+ export type { InstallChoice, InstallOption, InstallStep, PluginInstallDeclaration, ResolvedInstallAnswers } from "@kardalum/api-schemas";
3
4
  import type { ThemeTokenOverrides } from "@kardalum/design-tokens";
5
+ import { VIEW_BEARING_CONTRIBUTIONS, declaresClientBundle } from "@kardalum/plugin-package/reference";
4
6
  import type { ZodType } from "zod";
5
7
  import type { DataTypePlugin } from "./data-type-plugin.js";
6
8
  import type { BUILT_IN_RAIL_SECTIONS } from "./manifest-schema.js";
@@ -18,13 +20,13 @@ export type PluginType = "datatype" | "section" | "template" | "theme" | "integr
18
20
  /**
19
21
  * Databases a plugin can declare support for. Deliberately NOT
20
22
  * db-adapter's DatabaseDialect: that union includes 'mock' (the in-memory
21
- * test adapter), which no plugin may target — and the SDK is a published
23
+ * test adapter), which no plugin may target, and the SDK is a published
22
24
  * package that must not depend on the unpublished adapter internals.
23
25
  */
24
26
  export type DatabaseDialect = "postgresql" | "mysql" | "sqlite" | "mssql" | "mongodb";
25
27
  /**
26
28
  * How the plugin stores data and where it can run. Required on every
27
- * manifest (plugin-sdk.md) — the marketplace pre-filters by the site's
29
+ * manifest (plugin-sdk.md): the marketplace pre-filters by the site's
28
30
  * active database and install is blocked with a clear reason, never a
29
31
  * silent failure.
30
32
  */
@@ -32,14 +34,15 @@ export interface DatabaseCompatibility {
32
34
  /** 'simple' = JSON key-value SimpleStorageAPI (default, ~80% of
33
35
  * plugins); 'structured' = relational StructuredStorageAPI. Declaring
34
36
  * 'structured' IS the declaration that this plugin owns real tables:
35
- * it derives the `storage.structured` capability, which triggers
36
- * manual marketplace review (S267 section 6). There is deliberately no
37
- * boolean beside it, because a second place to say the same thing is a
38
- * second place for the manifest to disagree with itself. */
37
+ * it derives the `storage.structured` capability, which is a promised
38
+ * capability, so a reviewer reads it against your code (S267 section 6).
39
+ * There is deliberately no boolean beside it, because a second place to
40
+ * say the same thing is a second place for the manifest to disagree with
41
+ * itself. */
39
42
  storageType: "simple" | "structured";
40
43
  supported: DatabaseDialect[];
41
44
  /** Optional human-readable reason per UNSUPPORTED dialect (shown on the
42
- * blocked-install screen) — hence Partial: supported dialects carry no
45
+ * blocked-install screen), hence Partial: supported dialects carry no
43
46
  * reason. */
44
47
  unsupportedReason?: Partial<Record<DatabaseDialect, string>>;
45
48
  }
@@ -63,9 +66,10 @@ export interface PluginAssertion {
63
66
  * be claimed falsely or held quietly.
64
67
  *
65
68
  * These two survive as explicit assertions precisely because no
66
- * declaration can derive what a plugin's code does at runtime, and they
67
- * are review triggers for the same reason: they are the only claims in
68
- * the manifest with nothing behind them.
69
+ * declaration can derive what a plugin's code does at runtime, and each
70
+ * is a promised capability, so a reviewer reads it against your code, for
71
+ * the same reason: they are the only claims in the manifest with nothing
72
+ * behind them.
69
73
  *
70
74
  * Presence is the claim. There is no `false`: a key that is absent is an
71
75
  * assertion not made. The whole field is optional, so a plugin that
@@ -115,8 +119,8 @@ export interface PluginMigrationHooks {
115
119
  validateMigration?: (from: DatabaseDialect, to: DatabaseDialect) => PluginMigrationValidation | Promise<PluginMigrationValidation>;
116
120
  }
117
121
  /** The events a plugin can hook. The hook engine (S159) actually FIRES
118
- * only three of these — content:afterPublish (including rollbacks),
119
- * content:afterTrash, content:afterRestore — with the
122
+ * only three of these: content:afterPublish (including rollbacks),
123
+ * content:afterTrash, content:afterRestore, with the
120
124
  * ContentLifecycleHookPayload shape declared below; every other event in
121
125
  * this catalog is declared for forward compatibility and stays inert. */
122
126
  export type HookEvent = "content:beforeSave" | "content:afterSave" | "content:beforePublish" | "content:afterPublish" | "content:afterTrash" | "content:afterRestore" | "content:beforeDelete" | "media:afterUpload" | "user:afterLogin" | "api:beforeResponse";
@@ -141,8 +145,12 @@ export type HookHandler = (payload: unknown, context?: PluginHookContext) => voi
141
145
  export type PluginHooks = Partial<Record<HookEvent, HookHandler>>;
142
146
  /** A slot's label: a map of language code to text, `en` required (spec D5).
143
147
  * Each key is a language code such as `en`, `de` or `pt-BR`. The admin
144
- * shows the active language's text, else English; `slotLabel` is the one
145
- * place that choice is made. */
148
+ * shows the active language's text, else English; `resolveLabel` in
149
+ * @kardalum/api-schemas is the one place that choice is made (S311), and
150
+ * `slotLabel` is it for a map. Since S311 the display names of the other
151
+ * surfaces (an action's label, a role's, a widget's or a scheduled task's
152
+ * name, and the rest typed `PluginLabel` below) take the same map or a
153
+ * plain string. */
146
154
  export interface SlotLabel {
147
155
  en: string;
148
156
  [locale: string]: string;
@@ -200,7 +208,7 @@ export interface BuiltInRailEntryContribution extends RailEntryContribution {
200
208
  }
201
209
  export interface DashboardWidgetContribution {
202
210
  id: string;
203
- name: string;
211
+ name: PluginLabel;
204
212
  view: ComponentType;
205
213
  /** The named permission action a subject must hold to reach this
206
214
  * (S270, theme G1). Required: a contribution that declares no action
@@ -210,56 +218,78 @@ export interface DashboardWidgetContribution {
210
218
  action: string;
211
219
  }
212
220
  /** Mounted under /api/plugins/:pluginId/… so two plugins can never
213
- * collide on a path (api-design.md) — the host dispatches to this exact
214
- * (method, path) pair at request time (Month 8, Session 89: the first
215
- * real server-side consumer). `handler` stays untyped at the SDK
216
- * boundary (same cross-boundary erasure as view ComponentType fields)
217
- * — the host casts to real Fastify types internally, since it always
218
- * passes real FastifyRequest/FastifyReply instances. */
221
+ * collide on a path (api-design.md). The host routes every declaration
222
+ * through Fastify's own router, rebuilt whenever a plugin is attached or
223
+ * detached (S295, 2026-10-14-s295-routes-fastify-knows-about-design.md).
224
+ * `handler` stays untyped at the SDK boundary (the same cross-boundary
225
+ * erasure as view ComponentType fields): the host casts to real Fastify
226
+ * types internally, since it always passes real FastifyRequest and
227
+ * FastifyReply instances. */
219
228
  export interface ApiRouteContribution {
220
229
  method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
221
- /** Relative to /api/plugins/:pluginId/ — must start with "/". */
230
+ /** Relative to /api/plugins/:pluginId/: starting with "/" and holding one or
231
+ * more segments, each letters, digits, "-" and "_", or a parameter ":name"
232
+ * (a letter, then letters, digits or "_") matching one segment of the
233
+ * request; at most 200 characters. Two routes of one method that the
234
+ * router would read as one, or that one request could match both of, are
235
+ * refused (api-schemas' checkApiRouteDeclarations). */
222
236
  path: string;
223
237
  /** Who may call this route.
224
- * - "admin" (the default when omitted) requires a JWT admin session —
225
- * for admin-facing plugin UIs like Commerce Orders or the Forms
226
- * builder.
227
- * - "apiKey" requires a valid public API key — for credentialed
228
- * headless callers like a storefront checkout.
229
- * - "public" requires NO credentials — for genuinely anonymous
230
- * browser traffic such as a contact-form submission. Session 108
231
- * deliberately deferred this tier ("a webhook/public level can be
232
- * added when a real consumer needs it"); Session 160's Forms
233
- * plugin is that consumer. A public route owns its own abuse
234
- * controls (honeypot, per-IP bucket, body caps) and only reaches
235
- * browsers cross-origin when the operator allowlists their origin
236
- * in KARDALUM_CORS_ORIGINS.
237
- * Anything unrecognized falls back to "admin" — secure by default. */
238
+ * - "admin" (the default when omitted) requires a JWT session whose role
239
+ * holds `action`: for admin-facing plugin UIs like Commerce Orders or
240
+ * the Forms builder.
241
+ * - "apiKey" requires a live API key that holds `action`, for a read and a
242
+ * write alike (S299): for credentialed headless callers like a
243
+ * storefront checkout.
244
+ * - "public" requires NO credentials: for genuinely anonymous browser
245
+ * traffic such as a contact-form submission (Session 160's Forms plugin
246
+ * was the first consumer). A public route owns its own abuse controls
247
+ * (honeypot, per-IP bucket, body caps) and only reaches browsers
248
+ * cross-origin when the operator allowlists their origin in
249
+ * KARDALUM_CORS_ORIGINS.
250
+ * Anything unrecognized falls back to "admin": secure by default. */
238
251
  access?: "admin" | "apiKey" | "public";
239
- /** Optional request-side validation. The handler's response is NOT
240
- * schema-validated — trusted, same as SimpleStorageAPI's handlers
241
- * today. */
252
+ /** Optional validation, compiled with the host's validator compiler when the
253
+ * host routes the plugin (again on every attach or detach), never per
254
+ * request; the handler receives the parsed values. `response` is the other
255
+ * direction (S297): the success bodies the handler answers, which the host
256
+ * checks and documents. */
242
257
  schema?: {
243
258
  body?: ZodType;
244
259
  querystring?: ZodType;
260
+ /** The path's parameters: a Zod object keyed by the names the path
261
+ * declares. Without it each parameter reaches request.params as a
262
+ * string. */
245
263
  params?: ZodType;
264
+ /** The success responses, keyed by status code written as a string,
265
+ * "200" to "299", at most four. When the handler RETURNS a value (it does
266
+ * not send it with `reply.send`), the value is checked against the
267
+ * schema for the status the reply carries (200 unless the handler set
268
+ * another with `reply.code`), and the PARSED value is what is sent:
269
+ * unknown keys dropped, defaults and transforms applied. A value that
270
+ * does not match answers a 500 and is logged with the problems. A status
271
+ * with no entry is sent unchecked, and so is anything the handler sends
272
+ * through `reply.send`. The schemas also document the response in the
273
+ * server's OpenAPI documents. */
274
+ response?: Record<string, ZodType>;
246
275
  };
247
- /** Third argument added Month 8, Session 90 — the first server-side
276
+ /** Third argument added Month 8, Session 90, the first server-side
248
277
  * consumer needing privileged host access. Existing two-argument (or
249
278
  * fewer) handlers remain perfectly valid: TypeScript allows a function
250
279
  * with fewer declared parameters to satisfy a type expecting more. */
251
280
  handler: (request: unknown, reply: unknown, context: PluginApiRouteContext) => unknown;
252
281
  /** The named permission action a caller must hold (S270, theme G1).
253
- * Required when `access` is "admin" or omitted. A "public" route needs
254
- * no credential, so it needs no action either, and an "apiKey" route is
255
- * gated by its scope until month 26's S299 moves tokens onto actions.
282
+ * Required unless `access` is "public": on an "admin" route (or one that
283
+ * omits `access`) the session's role must hold it, and on an "apiKey"
284
+ * route the key must hold it, for a read and a write alike (S299). Only a
285
+ * "public" route, which needs no credential, may omit it.
256
286
  * `access` decides WHICH CREDENTIAL reaches the handler; this decides
257
287
  * WHAT THAT SUBJECT MAY DO. They are orthogonal. */
258
288
  action?: string;
259
289
  }
260
290
  export interface ScheduledTaskContribution {
261
291
  id: string;
262
- name: string;
292
+ name: PluginLabel;
263
293
  /** Standard 5-field cron expression. */
264
294
  cron: string;
265
295
  run: (context?: PluginTaskContext) => void | Promise<void>;
@@ -268,55 +298,19 @@ export interface ScheduledTaskContribution {
268
298
  * contract firms up when the BullMQ media pipeline lands. */
269
299
  export interface MediaProcessorContribution {
270
300
  id: string;
271
- name: string;
301
+ name: PluginLabel;
272
302
  process: (file: unknown) => unknown | Promise<unknown>;
273
303
  }
274
- export interface SettingsPageContribution {
275
- id: string;
276
- name: string;
277
- view: ComponentType;
278
- /** The named permission action a subject must hold to reach this
279
- * (S270, theme G1). Required: a contribution that declares no action
280
- * would be a gate nobody chose, and omission is how a permission
281
- * silently loosens. Must be prefixed with this plugin's own id, so one
282
- * plugin cannot declare an action in another's namespace or in core's. */
283
- action: string;
284
- }
285
- export interface ContentTreeActionContribution {
286
- id: string;
287
- label: string;
288
- onSelect: (nodeId: string) => void | Promise<void>;
289
- /** The named permission action a subject must hold to reach this
290
- * (S270, theme G1). Required: a contribution that declares no action
291
- * would be a gate nobody chose, and omission is how a permission
292
- * silently loosens. Must be prefixed with this plugin's own id, so one
293
- * plugin cannot declare an action in another's namespace or in core's. */
294
- action: string;
295
- }
296
- /** A button in the rich-text editor's toolbar. TipTap wiring comes with
297
- * the first consumer. */
298
- export interface EditorToolbarContribution {
299
- id: string;
300
- label: string;
301
- icon: string;
302
- onClick: () => void | Promise<void>;
303
- /** The named permission action a subject must hold to reach this
304
- * (S270, theme G1). Required: a contribution that declares no action
305
- * would be a gate nobody chose, and omission is how a permission
306
- * silently loosens. Must be prefixed with this plugin's own id, so one
307
- * plugin cannot declare an action in another's namespace or in core's. */
308
- action: string;
309
- }
310
304
  /** A service an integration plugin exposes for other plugins to consume
311
305
  * (e.g. a Stripe client). Shape intentionally opaque until the
312
306
  * cross-plugin service registry exists. */
313
307
  export interface ExposedServiceContribution {
314
308
  id: string;
315
- name: string;
309
+ name: PluginLabel;
316
310
  service: unknown;
317
311
  }
318
312
  /** A ready-made frontend starter shipped alongside a plugin (e.g. the
319
- * Commerce plugin's "Online Store" Next.js starter) — one marketplace
313
+ * Commerce plugin's "Online Store" Next.js starter), one marketplace
320
314
  * listing, working site immediately. Packaging lands Month 13. */
321
315
  export interface BundledTemplateContribution {
322
316
  name: string;
@@ -324,14 +318,14 @@ export interface BundledTemplateContribution {
324
318
  /** Where the starter's source lives until marketplace packaging exists. */
325
319
  repository?: string;
326
320
  }
327
- /** One render template a plugin ships under its own `templates/` dir —
328
- * per S192 §8 ("a new `templates` contribution — template files declared
321
+ /** One render template a plugin ships under its own `templates/` dir,
322
+ * per S192 §8 ("a new `templates` contribution: template files declared
329
323
  * with alias/kind and, for pages, which contributed document type they
330
324
  * render"). Any plugin may declare templates (S268): a `page` kind entry
331
325
  * may only name a document type this same manifest declares. */
332
326
  export interface TemplateContribution {
333
327
  /** Relative path under the plugin's `templates/` directory, forward
334
- * slashes, ending in `.liquid` — this is the file S192 §5 says the
328
+ * slashes, ending in `.liquid`: this is the file S192 §5 says the
335
329
  * developer edits and the mirror-on-edit versioning tracks. */
336
330
  file: string;
337
331
  name: string;
@@ -340,7 +334,7 @@ export interface TemplateContribution {
340
334
  alias: string;
341
335
  kind: "page" | "layout" | "partial";
342
336
  /** `page` kind only: a NAME from THIS manifest's own `documentTypes`
343
- * contribution — the document type this page template renders.
337
+ * contribution: the document type this page template renders.
344
338
  * Optional: a catch-all-ish page template with no specific type is
345
339
  * legal (S193 allows a null `documentTypeId`). Forbidden on
346
340
  * `layout`/`partial` entries, which never render a document type. */
@@ -355,7 +349,7 @@ export interface SerializerContext {
355
349
  publishedAt: string | null;
356
350
  version: number;
357
351
  };
358
- /** SERIALIZED field data — contributions run after core serialization. */
352
+ /** SERIALIZED field data: contributions run after core serialization. */
359
353
  data: Record<string, unknown>;
360
354
  documentType: {
361
355
  id: string;
@@ -363,7 +357,7 @@ export interface SerializerContext {
363
357
  };
364
358
  }
365
359
  export interface CustomFormatContribution {
366
- /** Plugin-scoped name, /^[a-z0-9-]+$/ — addressed as `<pluginId>:<name>`. */
360
+ /** Plugin-scoped name, /^[a-z0-9-]+$/, addressed as `<pluginId>:<name>`. */
367
361
  name: string;
368
362
  build: (context: SerializerContext) => unknown | Promise<unknown>;
369
363
  }
@@ -384,9 +378,6 @@ export interface PluginContributions {
384
378
  hooks?: PluginHooks;
385
379
  scheduledTasks?: ScheduledTaskContribution[];
386
380
  mediaProcessors?: MediaProcessorContribution[];
387
- settingsPages?: SettingsPageContribution[];
388
- contentTreeActions?: ContentTreeActionContribution[];
389
- editorToolbar?: EditorToolbarContribution[];
390
381
  exposedServices?: ExposedServiceContribution[];
391
382
  serializers?: SerializerContribution;
392
383
  /** Document types the plugin provisions at install: the creation shape
@@ -414,10 +405,10 @@ export interface PluginContributions {
414
405
  /**
415
406
  * The contributions that put code in the browser, and so the ones that
416
407
  * make a plugin ship a client bundle (S267 section 5, implemented by
417
- * S268 Task 3). `dataTypes`, `adminSections`, `railEntries` (S280),
418
- * `dashboardWidgets` and `settingsPages` carry React views; `contentTreeActions` and
419
- * `editorToolbar` carry client callbacks (`onSelect`, `onClick`), which
420
- * is just as much browser code even though neither has a `view` key.
408
+ * S268 Task 3). `dataTypes`, `adminSections`, `railEntries` (S280) and
409
+ * `dashboardWidgets` carry React views. S313b retired `settingsPages`,
410
+ * `contentTreeActions` and `editorToolbar`, which no admin screen hosted;
411
+ * the last two return when a host and an editor-handle API are designed.
421
412
  *
422
413
  * Everything else is absent on purpose: `apiRoutes`, `hooks`,
423
414
  * `scheduledTasks`, `mediaProcessors` and `serializers` run on the
@@ -429,7 +420,7 @@ export interface PluginContributions {
429
420
  * than that list was, not merely equivalent: a plugin listed as
430
421
  * `section` with no views had to ship a remoteEntry.js it did not have.
431
422
  */
432
- export declare const VIEW_BEARING_CONTRIBUTIONS: readonly ["dataTypes", "adminSections", "railEntries", "dashboardWidgets", "settingsPages", "contentTreeActions", "editorToolbar"];
423
+ export { VIEW_BEARING_CONTRIBUTIONS };
433
424
  export type ViewBearingContribution = (typeof VIEW_BEARING_CONTRIBUTIONS)[number];
434
425
  /**
435
426
  * Whether a manifest's declared contributions require a client bundle:
@@ -458,9 +449,39 @@ export type ViewBearingContribution = (typeof VIEW_BEARING_CONTRIBUTIONS)[number
458
449
  * 'hasClientBundle'", before it can decide anything. The old name is
459
450
  * gone rather than aliased: a name that outlives its meaning is how these
460
451
  * get recombined later. A caller passing a string to THIS name is a
461
- * compile error against the signature below.
452
+ * compile error against the signature in plugin-package.
462
453
  */
463
- export declare function declaresClientBundle(contributions: PluginContributions | Record<string, unknown> | null | undefined): boolean;
454
+ export { declaresClientBundle };
455
+ /** S292: what onInstall is told. */
456
+ export interface PluginInstallContext {
457
+ /** The install's answers with every default filled: what the operator
458
+ * chose for the sample content, the offered roles and the plugin's own
459
+ * `install` options (resolveInstallAnswers in @kardalum/api-schemas). */
460
+ answers: ResolvedInstallAnswers;
461
+ /** S293: the plugin's own structured storage, for a manifest declaring
462
+ * `storageType: 'structured'`, scoped to this plugin as a route's is and
463
+ * usable before it is active (onInstall runs before its row exists). A
464
+ * table onInstall defines is dropped again if the install fails. The handle
465
+ * is for the hook alone: once onInstall returns or throws it refuses while
466
+ * the plugin is not active, like any plugin storage, so keeping it for later
467
+ * gains nothing. Absent for a simple-storage plugin. */
468
+ structuredStorage?: ScopedStructuredStorage;
469
+ }
470
+ /** S292: what onUpdate is told. */
471
+ export interface PluginUpdateContext {
472
+ /** The version that was installed before. */
473
+ fromVersion: string;
474
+ answers: ResolvedInstallAnswers;
475
+ /** S293: the plugin's own structured storage, for a manifest declaring
476
+ * `storageType: 'structured'`, scoped to this plugin as a route's is and
477
+ * usable while it is not active (an update may run while the plugin is
478
+ * off). A table onUpdate defines is kept if the update fails: storage only
479
+ * grows, and an uninstall snapshots and drops it. The handle is for the
480
+ * hook alone: once onUpdate returns or throws it refuses while the plugin
481
+ * is not active, like any plugin storage, so keeping it for later gains
482
+ * nothing. Absent for a simple-storage plugin. */
483
+ structuredStorage?: ScopedStructuredStorage;
484
+ }
464
485
  /** Fields shared by every plugin type. */
465
486
  export interface PluginManifestBase {
466
487
  /** Reverse domain, e.g. 'com.yourname.googlemaps'. */
@@ -477,7 +498,7 @@ export interface PluginManifestBase {
477
498
  /**
478
499
  * Marketplace verification hash. Optional BY DESIGN, not oversight:
479
500
  * per the Trust model, sideloaded/local dev plugins are unsigned by
480
- * definition (Tier 2 'unverified') — only marketplace-signed plugins
501
+ * definition (Tier 2 'unverified'): only marketplace-signed plugins
481
502
  * carry one. Signing is authenticity, not a sandbox; the safety layer
482
503
  * is identical for both tiers.
483
504
  */
@@ -488,10 +509,10 @@ export interface PluginManifestBase {
488
509
  pluginDependencies?: string[];
489
510
  databaseCompatibility: DatabaseCompatibility;
490
511
  assertions?: PluginAssertions;
491
- /** DB changes applied on install (through plugin storage — never raw
512
+ /** DB changes applied on install (through plugin storage, never raw
492
513
  * SQL). */
493
514
  migrations?: PluginMigration[];
494
- onInstall?: () => void | Promise<void>;
515
+ onInstall?: (ctx: PluginInstallContext) => void | Promise<void>;
495
516
  onUninstall?: () => void | Promise<void>;
496
517
  onActivate?: () => void | Promise<void>;
497
518
  onDeactivate?: () => void | Promise<void>;
@@ -499,39 +520,51 @@ export interface PluginManifestBase {
499
520
  * the new migrations and document types and before the new actions sync.
500
521
  * A throw rolls the update back and the old version stays installed.
501
522
  * `onInstall` never runs on an update. */
502
- onUpdate?: (ctx: {
503
- fromVersion: string;
504
- }) => void | Promise<void>;
523
+ onUpdate?: (ctx: PluginUpdateContext) => void | Promise<void>;
505
524
  migrationHooks?: PluginMigrationHooks;
506
525
  /**
507
526
  * The actions this plugin brings (S273). Each gated contribution above
508
527
  * names one of these, and each of these is named by at least one, so the
509
528
  * install screen shows exactly what installing adds to the permission
510
529
  * surface. Ids carry this plugin's prefix and have a label, because
511
- * nothing ever shows an operator a raw action string.
530
+ * nothing ever shows an operator a raw action string. A label is a string
531
+ * or a map of language code to text with `en` required (S311); the install
532
+ * stores the text of the site's default language.
512
533
  */
513
534
  actions?: Array<{
514
535
  id: string;
515
- label: string;
536
+ label: PluginLabel;
516
537
  }>;
517
538
  /**
518
539
  * Roles this plugin offers (S273). An offer is never applied unasked: the
519
540
  * operator accepts it on the install screen or from the installed-plugins
520
541
  * view, and the result is an ordinary editable role holding exactly these
521
- * actions, each one of the plugin's own.
542
+ * actions: the plugin's own and, beside them, only the built-in read rights
543
+ * an offer may grant (S293, OFFERABLE_BUILT_IN_ACTIONS in
544
+ * @kardalum/api-schemas).
522
545
  */
523
546
  roles?: Array<{
524
547
  id: string;
525
- label: string;
548
+ label: PluginLabel;
526
549
  actions: string[];
527
550
  }>;
528
551
  /** S286: the plugin's docs pages, in reading order. Omit it and the
529
552
  * README is the one page (the overview). Which roles the marketplace
530
553
  * requires is derived from what the manifest declares, never listed
531
554
  * here: a "setup" page when the plugin has migrations, dependencies, a
532
- * price or document types; a "configuration" page when it has settings
533
- * pages. */
555
+ * price or document types. The "configuration" role stays declarable
556
+ * but is never required. */
534
557
  docs?: PluginDocsPage[];
558
+ /** S291: the language the docs pages are written in, as a language code
559
+ * such as "en", "de" or "pt-BR". Absent means English. The marketplace
560
+ * shows it on the listing and the docs index. One language per plugin
561
+ * before v1: translated docs pages are not supported yet. */
562
+ docsLanguage?: string;
563
+ /** S292: what the plugin's install asks, as plain data, so a person, a
564
+ * script and the CLI can answer it before any of the plugin's code runs.
565
+ * The built-in questions (the sample content, the offered roles) are never
566
+ * declared here: they follow from what the package ships. */
567
+ install?: PluginInstallDeclaration;
535
568
  }
536
569
  /**
537
570
  * The full plugin manifest. One shape for every plugin: `type` is a
package/dist/manifest.js CHANGED
@@ -1,3 +1,5 @@
1
+ import { resolveLabel } from "@kardalum/api-schemas";
2
+ import { VIEW_BEARING_CONTRIBUTIONS, declaresClientBundle } from "@kardalum/plugin-package/reference";
1
3
  /**
2
4
  * The text of a slot's label for a locale: the locale as given, else its
3
5
  * primary subtag (`de-AT` reads `de`), else `en`, which every label carries.
@@ -5,25 +7,15 @@
5
7
  * case-insensitive and a label written `pt-BR` must answer `pt-br`.
6
8
  */
7
9
  export function slotLabel(label, locale) {
8
- const wanted = locale.toLowerCase();
9
- const primary = wanted.split("-")[0] ?? "";
10
- let primaryText;
11
- for (const [code, text] of Object.entries(label)) {
12
- const lower = code.toLowerCase();
13
- if (lower === wanted)
14
- return text;
15
- if (primaryText === undefined && primary !== "" && lower === primary)
16
- primaryText = text;
17
- }
18
- return primaryText ?? label.en;
10
+ return resolveLabel(label, locale);
19
11
  }
20
12
  /**
21
13
  * The contributions that put code in the browser, and so the ones that
22
14
  * make a plugin ship a client bundle (S267 section 5, implemented by
23
- * S268 Task 3). `dataTypes`, `adminSections`, `railEntries` (S280),
24
- * `dashboardWidgets` and `settingsPages` carry React views; `contentTreeActions` and
25
- * `editorToolbar` carry client callbacks (`onSelect`, `onClick`), which
26
- * is just as much browser code even though neither has a `view` key.
15
+ * S268 Task 3). `dataTypes`, `adminSections`, `railEntries` (S280) and
16
+ * `dashboardWidgets` carry React views. S313b retired `settingsPages`,
17
+ * `contentTreeActions` and `editorToolbar`, which no admin screen hosted;
18
+ * the last two return when a host and an editor-handle API are designed.
27
19
  *
28
20
  * Everything else is absent on purpose: `apiRoutes`, `hooks`,
29
21
  * `scheduledTasks`, `mediaProcessors` and `serializers` run on the
@@ -35,15 +27,10 @@ export function slotLabel(label, locale) {
35
27
  * than that list was, not merely equivalent: a plugin listed as
36
28
  * `section` with no views had to ship a remoteEntry.js it did not have.
37
29
  */
38
- export const VIEW_BEARING_CONTRIBUTIONS = [
39
- "dataTypes",
40
- "adminSections",
41
- "railEntries",
42
- "dashboardWidgets",
43
- "settingsPages",
44
- "contentTreeActions",
45
- "editorToolbar",
46
- ];
30
+ // S311: the list and the rule live in @kardalum/plugin-package (browser-safe,
31
+ // shared with the marketplace door and the CLI, imported at the top of this
32
+ // file); the SDK re-exports them.
33
+ export { VIEW_BEARING_CONTRIBUTIONS };
47
34
  /**
48
35
  * Whether a manifest's declared contributions require a client bundle:
49
36
  * whether a built artifact must contain a `remoteEntry.js`, and whether
@@ -71,16 +58,6 @@ export const VIEW_BEARING_CONTRIBUTIONS = [
71
58
  * 'hasClientBundle'", before it can decide anything. The old name is
72
59
  * gone rather than aliased: a name that outlives its meaning is how these
73
60
  * get recombined later. A caller passing a string to THIS name is a
74
- * compile error against the signature below.
61
+ * compile error against the signature in plugin-package.
75
62
  */
76
- export function declaresClientBundle(contributions) {
77
- if (contributions === null || typeof contributions !== "object")
78
- return false;
79
- const declared = contributions;
80
- return VIEW_BEARING_CONTRIBUTIONS.some((key) => {
81
- const value = declared[key];
82
- if (value === null || value === undefined)
83
- return false;
84
- return Array.isArray(value) ? value.length > 0 : true;
85
- });
86
- }
63
+ export { declaresClientBundle };
@@ -3,14 +3,18 @@ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
3
3
  import { ChevronRight, Folder as FolderIcon } from "lucide-react";
4
4
  import { renditionShape, } from "@kardalum/api-schemas";
5
5
  import { Button, cn, Sheet, SheetContent, SheetDescription, SheetFooter, SheetHeader, SheetTitle, } from "@kardalum/ui";
6
- import { usePluginApi } from "../plugin-context.js";
6
+ import { MANAGE_API, usePluginApi } from "../plugin-context.js";
7
+ import { readAllPages } from "../read-all-pages.js";
7
8
  import { isRenditionIneligible } from "../rendition-eligibility.js";
8
9
  import { uploadFailureMessage } from "./upload-error.js";
9
- // GET /api/media page size for the picker's grid (S197 Task 2). Additional
10
+ // GET /api/manage/v1/media page size for the picker's grid (S197 Task 2). Additional
10
11
  // pages are fetched on demand via the "Load more" button below, following
11
12
  // MediaListQuerySchema's cursor contract (media-api.schema.ts) rather than
12
13
  // assuming a library's whole image set fits on one page.
13
14
  const PAGE_LIMIT = 50;
15
+ // The folder list is paged by the server (S300b): read it to its end, 200 folders a page, at most 50 pages.
16
+ const FOLDER_PAGE_LIMIT = 200;
17
+ const FOLDER_PAGE_CAP = 50;
14
18
  // What the picker offers when the caller names nothing. Rich text has no
15
19
  // accepted-types setting of its own and has always shown images only, so
16
20
  // this is that behaviour written down rather than a new default.
@@ -124,7 +128,7 @@ function folderPath(folderId, byId) {
124
128
  // controlled-open pattern as IconPickerDialog
125
129
  // (apps/admin-ui/src/icons/icon-picker-dialog.tsx).
126
130
  //
127
- // downloadUrl is resolved fresh from each GET /api/media response, never
131
+ // downloadUrl is resolved fresh from each GET /api/manage/v1/media response, never
128
132
  // cached across renders: a private item's URL carries a short-lived
129
133
  // token, so a stale one would go dead (image-view.tsx's useMediaPreview
130
134
  // :21-24 doctrine, mirrored here for the same reason).
@@ -199,13 +203,18 @@ export function MediaPicker({ onPick, onClose, collectAlt, acceptedTypes, rendit
199
203
  // banner, whichever fetch failed most recently.
200
204
  useEffect(() => {
201
205
  let cancelled = false;
202
- fetchApi("/api/media/folders")
203
- .then(async (response) => {
204
- if (!response.ok)
205
- throw new Error(`Failed to load media folders (${response.status})`);
206
- const body = (await response.json());
207
- if (!cancelled)
208
- setFolders(body.folders);
206
+ readAllPages(fetchApi, `${MANAGE_API}/media/folders`, "media folders", {
207
+ itemKey: "folders",
208
+ limit: FOLDER_PAGE_LIMIT,
209
+ cap: FOLDER_PAGE_CAP,
210
+ })
211
+ .then(({ items, complete }) => {
212
+ if (cancelled)
213
+ return;
214
+ setFolders(items);
215
+ // A tree that was not read to its end is a subset of the folders: say so through the banner the list uses.
216
+ if (!complete)
217
+ setError(`Only the first ${FOLDER_PAGE_CAP * FOLDER_PAGE_LIMIT} media folders could be read`);
209
218
  })
210
219
  .catch((err) => {
211
220
  if (!cancelled)
@@ -227,7 +236,7 @@ export function MediaPicker({ onPick, onClose, collectAlt, acceptedTypes, rendit
227
236
  params.set("cursor", cursor);
228
237
  if (rendition)
229
238
  params.set("rendition", rendition);
230
- return `/api/media?${params.toString()}`;
239
+ return `${MANAGE_API}/media?${params.toString()}`;
231
240
  }, [rendition]);
232
241
  // A generation counter, bumped on every call. It guards against a stale
233
242
  // response (e.g. two rapid folder switches) overwriting the newer one,
@@ -331,7 +340,7 @@ export function MediaPicker({ onPick, onClose, collectAlt, acceptedTypes, rendit
331
340
  if (currentFolderId)
332
341
  formData.append("folderId", currentFolderId);
333
342
  formData.append("file", file);
334
- const response = await fetchApi("/api/media", { method: "POST", body: formData });
343
+ const response = await fetchApi(`${MANAGE_API}/media`, { method: "POST", body: formData });
335
344
  // The server's own sentence, not a status code (S234d Task 8).
336
345
  // This drawer has no size check of its own and cannot usefully have
337
346
  // one: the ceiling belongs to the media document type the file will
@@ -1,5 +1,5 @@
1
1
  /**
2
- * The sentence a failed `POST /api/media` should show. The server's own
2
+ * The sentence a failed `POST /api/manage/v1/media` should show. The server's own
3
3
  * message when there is one (every refusal on that route answers with
4
4
  * `ApiErrorSchema`, which is `{ message }`), and the status otherwise:
5
5
  * a failure with nothing to say still has to say something, and the
@@ -12,7 +12,7 @@
12
12
  // a person meeting two different sentences for one refusal would have no
13
13
  // way to tell they are the same rule.
14
14
  /**
15
- * The sentence a failed `POST /api/media` should show. The server's own
15
+ * The sentence a failed `POST /api/manage/v1/media` should show. The server's own
16
16
  * message when there is one (every refusal on that route answers with
17
17
  * `ApiErrorSchema`, which is `{ message }`), and the status otherwise:
18
18
  * a failure with nothing to say still has to say something, and the