@kardalum/plugin-sdk 0.17.0 → 0.19.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 (247) hide show
  1. package/CHANGELOG.md +109 -0
  2. package/README.md +4 -3
  3. package/dist/assets/asset-picker.d.ts +11 -0
  4. package/dist/assets/asset-picker.js +109 -0
  5. package/dist/assets/asset-tree.d.ts +30 -0
  6. package/dist/assets/asset-tree.js +150 -0
  7. package/dist/built-in-editor-ids.d.ts +1 -0
  8. package/dist/built-in-editor-ids.js +20 -0
  9. package/dist/built-in-serializers.js +1 -1
  10. package/dist/built-in-settings-schemas.d.ts +2 -0
  11. package/dist/built-in-settings-schemas.js +31 -4
  12. package/dist/built-in-value-schemas.js +3 -0
  13. package/dist/built-ins.js +20 -11
  14. package/dist/capabilities.js +5 -0
  15. package/dist/data-type-plugin.d.ts +2 -2
  16. package/dist/datatype-validation.d.ts +2 -2
  17. package/dist/datatype-validation.js +20 -6
  18. package/dist/datatypes-entry.d.ts +1 -0
  19. package/dist/datatypes-entry.js +1 -0
  20. package/dist/define-plugin.d.ts +4 -4
  21. package/dist/define-plugin.js +5 -5
  22. package/dist/entitlement-entry.d.ts +3 -2
  23. package/dist/entitlement-entry.js +13 -1
  24. package/dist/entitlement-gate.d.ts +18 -0
  25. package/dist/entitlement-gate.js +95 -21
  26. package/dist/entitlement-plan.d.ts +21 -0
  27. package/dist/entitlement-plan.js +26 -0
  28. package/dist/entitlement-types.d.ts +21 -4
  29. package/dist/entitlement.d.ts +29 -1
  30. package/dist/entitlement.js +39 -0
  31. package/dist/grid-arrow-step.d.ts +7 -0
  32. package/dist/grid-arrow-step.js +20 -0
  33. package/dist/index.d.ts +8 -1
  34. package/dist/index.js +11 -12
  35. package/dist/manifest-entry.d.ts +4 -0
  36. package/dist/manifest-entry.js +4 -0
  37. package/dist/manifest-schema.d.ts +5 -1
  38. package/dist/manifest-schema.js +14 -2
  39. package/dist/manifest.d.ts +21 -1
  40. package/dist/media/media-picker.js +34 -34
  41. package/dist/notify.d.ts +17 -0
  42. package/dist/notify.js +17 -0
  43. package/dist/plugin-context.js +3 -3
  44. package/dist/register-built-ins.js +6 -6
  45. package/dist/registry.js +1 -1
  46. package/dist/richtext/block-panel.js +19 -20
  47. package/dist/richtext/extensions.js +17 -8
  48. package/dist/richtext/insert-menu.js +4 -4
  49. package/dist/richtext/kardalum-block.js +17 -17
  50. package/dist/richtext/style-listbox.js +2 -2
  51. package/dist/richtext/text-style-class.js +1 -1
  52. package/dist/richtext-html-entry.d.ts +35 -0
  53. package/dist/richtext-html-entry.js +73 -0
  54. package/dist/simple-storage-value-provider.js +3 -3
  55. package/dist/structured-storage-types.d.ts +12 -1
  56. package/dist/structured-storage-types.js +2 -2
  57. package/dist/tailwind.js +10 -3
  58. package/dist/tokens/tailwind-theme.css +176 -0
  59. package/dist/tokens/tokens.css +1 -0
  60. package/dist/tokens/tokens.json +2 -1
  61. package/dist/ui-entry.js +3 -3
  62. package/dist/vendor-check.d.ts +39 -0
  63. package/dist/vendor-check.js +79 -0
  64. package/dist/vendor-entry.d.ts +3 -0
  65. package/dist/vendor-entry.js +9 -0
  66. package/dist/vendor-service.d.ts +20 -0
  67. package/dist/vendor-service.js +20 -0
  68. package/dist/views/asset-view.d.ts +6 -0
  69. package/dist/views/asset-view.js +55 -0
  70. package/dist/views/content-list-settings-view.js +1 -1
  71. package/dist/views/content-list-view.js +1 -1
  72. package/dist/views/date-range-view.js +5 -5
  73. package/dist/views/html-code-editor.js +2 -3
  74. package/dist/views/html-view.js +7 -7
  75. package/dist/views/image-view.js +5 -5
  76. package/dist/views/rich-text-view.js +33 -32
  77. package/node_modules/@kardalum/api-schemas/README.md +1 -1
  78. package/node_modules/@kardalum/api-schemas/dist/api-error.schema.js +1 -1
  79. package/node_modules/@kardalum/api-schemas/dist/asset-api.schema.js +17 -15
  80. package/node_modules/@kardalum/api-schemas/dist/asset-field.schema.d.ts +21 -0
  81. package/node_modules/@kardalum/api-schemas/dist/asset-field.schema.js +42 -0
  82. package/node_modules/@kardalum/api-schemas/dist/asset.schema.d.ts +1 -0
  83. package/node_modules/@kardalum/api-schemas/dist/asset.schema.js +10 -3
  84. package/node_modules/@kardalum/api-schemas/dist/auth.schema.js +1 -1
  85. package/node_modules/@kardalum/api-schemas/dist/checkout-shown.schema.d.ts +36 -0
  86. package/node_modules/@kardalum/api-schemas/dist/checkout-shown.schema.js +46 -0
  87. package/node_modules/@kardalum/api-schemas/dist/content-api.schema.d.ts +13 -0
  88. package/node_modules/@kardalum/api-schemas/dist/content-api.schema.js +30 -9
  89. package/node_modules/@kardalum/api-schemas/dist/content-trash-api.schema.js +3 -3
  90. package/node_modules/@kardalum/api-schemas/dist/content-trash.schema.js +1 -1
  91. package/node_modules/@kardalum/api-schemas/dist/core-actions.d.ts +12 -6
  92. package/node_modules/@kardalum/api-schemas/dist/core-actions.js +11 -6
  93. package/node_modules/@kardalum/api-schemas/dist/data-type-api.schema.d.ts +50 -0
  94. package/node_modules/@kardalum/api-schemas/dist/data-type-api.schema.js +26 -6
  95. package/node_modules/@kardalum/api-schemas/dist/data-type-config.schema.d.ts +1 -0
  96. package/node_modules/@kardalum/api-schemas/dist/data-type-config.schema.js +6 -3
  97. package/node_modules/@kardalum/api-schemas/dist/data-type-cursor.d.ts +11 -0
  98. package/node_modules/@kardalum/api-schemas/dist/data-type-cursor.js +28 -0
  99. package/node_modules/@kardalum/api-schemas/dist/document-type-api.schema.d.ts +90 -0
  100. package/node_modules/@kardalum/api-schemas/dist/document-type-api.schema.js +56 -6
  101. package/node_modules/@kardalum/api-schemas/dist/document-type.schema.js +8 -8
  102. package/node_modules/@kardalum/api-schemas/dist/home.schema.d.ts +130 -0
  103. package/node_modules/@kardalum/api-schemas/dist/home.schema.js +87 -0
  104. package/node_modules/@kardalum/api-schemas/dist/index.d.ts +48 -19
  105. package/node_modules/@kardalum/api-schemas/dist/index.js +34 -12
  106. package/node_modules/@kardalum/api-schemas/dist/kardalum-latest.schema.d.ts +7 -0
  107. package/node_modules/@kardalum/api-schemas/dist/kardalum-latest.schema.js +9 -0
  108. package/node_modules/@kardalum/api-schemas/dist/listing-categories.schema.d.ts +46 -0
  109. package/node_modules/@kardalum/api-schemas/dist/listing-categories.schema.js +52 -0
  110. package/node_modules/@kardalum/api-schemas/dist/marketplace-listing-api.schema.d.ts +162 -1
  111. package/node_modules/@kardalum/api-schemas/dist/marketplace-listing-api.schema.js +144 -9
  112. package/node_modules/@kardalum/api-schemas/dist/marketplace-package-api.schema.d.ts +17 -0
  113. package/node_modules/@kardalum/api-schemas/dist/marketplace-package-api.schema.js +16 -0
  114. package/node_modules/@kardalum/api-schemas/dist/media-api.schema.d.ts +26 -0
  115. package/node_modules/@kardalum/api-schemas/dist/media-api.schema.js +15 -9
  116. package/node_modules/@kardalum/api-schemas/dist/media-reference-use.d.ts +10 -0
  117. package/node_modules/@kardalum/api-schemas/dist/media-reference-use.js +4 -4
  118. package/node_modules/@kardalum/api-schemas/dist/media.schema.js +5 -5
  119. package/node_modules/@kardalum/api-schemas/dist/news.schema.d.ts +93 -0
  120. package/node_modules/@kardalum/api-schemas/dist/news.schema.js +86 -0
  121. package/node_modules/@kardalum/api-schemas/dist/node-access.schema.js +13 -0
  122. package/node_modules/@kardalum/api-schemas/dist/notification.schema.d.ts +410 -0
  123. package/node_modules/@kardalum/api-schemas/dist/notification.schema.js +193 -0
  124. package/node_modules/@kardalum/api-schemas/dist/plan-editor.schema.d.ts +86 -0
  125. package/node_modules/@kardalum/api-schemas/dist/plan-editor.schema.js +92 -0
  126. package/node_modules/@kardalum/api-schemas/dist/plugin-docs-api.schema.d.ts +7 -2
  127. package/node_modules/@kardalum/api-schemas/dist/plugin-docs-api.schema.js +7 -0
  128. package/node_modules/@kardalum/api-schemas/dist/plugin-docs-text.js +1 -0
  129. package/node_modules/@kardalum/api-schemas/dist/plugin-management-api.schema.d.ts +251 -0
  130. package/node_modules/@kardalum/api-schemas/dist/plugin-management-api.schema.js +196 -31
  131. package/node_modules/@kardalum/api-schemas/dist/plugin-read-only.schema.d.ts +19 -0
  132. package/node_modules/@kardalum/api-schemas/dist/plugin-read-only.schema.js +33 -0
  133. package/node_modules/@kardalum/api-schemas/dist/plugin-registry-api.schema.js +1 -1
  134. package/node_modules/@kardalum/api-schemas/dist/plugin-storage-api.schema.js +3 -3
  135. package/node_modules/@kardalum/api-schemas/dist/plugin-template-payload.d.ts +10 -1
  136. package/node_modules/@kardalum/api-schemas/dist/plugin-template-payload.js +24 -4
  137. package/node_modules/@kardalum/api-schemas/dist/public-api.schema.d.ts +5 -0
  138. package/node_modules/@kardalum/api-schemas/dist/public-api.schema.js +23 -20
  139. package/node_modules/@kardalum/api-schemas/dist/render-editing.js +4 -4
  140. package/node_modules/@kardalum/api-schemas/dist/render-settings-api.schema.js +1 -1
  141. package/node_modules/@kardalum/api-schemas/dist/revenue-view.schema.d.ts +83 -0
  142. package/node_modules/@kardalum/api-schemas/dist/revenue-view.schema.js +73 -0
  143. package/node_modules/@kardalum/api-schemas/dist/server-settings-api.schema.d.ts +207 -0
  144. package/node_modules/@kardalum/api-schemas/dist/server-settings-api.schema.js +147 -0
  145. package/node_modules/@kardalum/api-schemas/dist/setup-api.schema.d.ts +11 -0
  146. package/node_modules/@kardalum/api-schemas/dist/setup-api.schema.js +17 -8
  147. package/node_modules/@kardalum/api-schemas/dist/sites.schema.d.ts +14 -0
  148. package/node_modules/@kardalum/api-schemas/dist/sites.schema.js +7 -0
  149. package/node_modules/@kardalum/api-schemas/dist/snapshot-api.schema.d.ts +3 -3
  150. package/node_modules/@kardalum/api-schemas/dist/snapshot.schema.d.ts +1 -1
  151. package/node_modules/@kardalum/api-schemas/dist/snapshot.schema.js +1 -1
  152. package/node_modules/@kardalum/api-schemas/dist/template-api.schema.d.ts +10 -0
  153. package/node_modules/@kardalum/api-schemas/dist/template-api.schema.js +27 -12
  154. package/node_modules/@kardalum/api-schemas/dist/template.schema.d.ts +7 -0
  155. package/node_modules/@kardalum/api-schemas/dist/template.schema.js +22 -10
  156. package/node_modules/@kardalum/api-schemas/dist/theme-api.schema.d.ts +1 -1
  157. package/node_modules/@kardalum/api-schemas/dist/theme-api.schema.js +1 -1
  158. package/node_modules/@kardalum/api-schemas/dist/user-api.schema.d.ts +12 -0
  159. package/node_modules/@kardalum/api-schemas/dist/user-api.schema.js +6 -1
  160. package/node_modules/@kardalum/api-schemas/dist/uuid.schema.d.ts +2 -0
  161. package/node_modules/@kardalum/api-schemas/dist/uuid.schema.js +4 -0
  162. package/node_modules/@kardalum/api-schemas/dist/vendor-service.schema.d.ts +88 -0
  163. package/node_modules/@kardalum/api-schemas/dist/vendor-service.schema.js +100 -0
  164. package/node_modules/@kardalum/api-schemas/dist/whoami-api.schema.d.ts +13 -0
  165. package/node_modules/@kardalum/api-schemas/dist/whoami-api.schema.js +5 -0
  166. package/node_modules/@kardalum/design-tokens/README.md +1 -1
  167. package/node_modules/@kardalum/design-tokens/dist/build-css.d.ts +1 -1
  168. package/node_modules/@kardalum/design-tokens/dist/build-css.js +2 -2
  169. package/node_modules/@kardalum/design-tokens/dist/build-theme-css.d.ts +16 -0
  170. package/node_modules/@kardalum/design-tokens/dist/build-theme-css.js +76 -0
  171. package/node_modules/@kardalum/design-tokens/dist/generate.js +4 -1
  172. package/node_modules/@kardalum/design-tokens/dist/tailwind-theme.css +176 -0
  173. package/node_modules/@kardalum/design-tokens/dist/tailwind-theme.d.ts +1 -1
  174. package/node_modules/@kardalum/design-tokens/dist/tailwind-theme.js +3 -3
  175. package/node_modules/@kardalum/design-tokens/dist/theme-css.d.ts +2 -2
  176. package/node_modules/@kardalum/design-tokens/dist/theme-css.js +2 -2
  177. package/node_modules/@kardalum/design-tokens/dist/theme-types.d.ts +2 -2
  178. package/node_modules/@kardalum/design-tokens/dist/themes/dark.d.ts +3 -3
  179. package/node_modules/@kardalum/design-tokens/dist/themes/dark.js +3 -3
  180. package/node_modules/@kardalum/design-tokens/dist/themes/light.d.ts +1 -1
  181. package/node_modules/@kardalum/design-tokens/dist/themes/light.js +1 -1
  182. package/node_modules/@kardalum/design-tokens/dist/tokens.css +1 -0
  183. package/node_modules/@kardalum/design-tokens/dist/tokens.d.ts +3 -3
  184. package/node_modules/@kardalum/design-tokens/dist/tokens.js +6 -5
  185. package/node_modules/@kardalum/design-tokens/dist/tokens.json +2 -1
  186. package/node_modules/@kardalum/design-tokens/dist/types.d.ts +2 -1
  187. package/node_modules/@kardalum/design-tokens/dist/types.js +1 -1
  188. package/node_modules/@kardalum/design-tokens/package.json +6 -3
  189. package/node_modules/@kardalum/plugin-package/README.md +1 -1
  190. package/node_modules/@kardalum/plugin-package/dist/capabilities.d.ts +4 -4
  191. package/node_modules/@kardalum/plugin-package/dist/capabilities.js +54 -6
  192. package/node_modules/@kardalum/plugin-package/dist/delivery/bundle.js +1 -1
  193. package/node_modules/@kardalum/plugin-package/dist/delivery/contributions.d.ts +3 -0
  194. package/node_modules/@kardalum/plugin-package/dist/delivery/contributions.js +18 -1
  195. package/node_modules/@kardalum/plugin-package/dist/delivery/limits.d.ts +1 -1
  196. package/node_modules/@kardalum/plugin-package/dist/delivery/limits.js +1 -1
  197. package/node_modules/@kardalum/plugin-package/dist/delivery/registry.js +9 -4
  198. package/node_modules/@kardalum/plugin-package/dist/delivery/templates.d.ts +1 -0
  199. package/node_modules/@kardalum/plugin-package/dist/delivery/templates.js +58 -1
  200. package/node_modules/@kardalum/plugin-package/dist/envelope.d.ts +2 -2
  201. package/node_modules/@kardalum/plugin-package/dist/envelope.js +2 -2
  202. package/node_modules/@kardalum/plugin-package/dist/extract.d.ts +3 -3
  203. package/node_modules/@kardalum/plugin-package/dist/extract.js +10 -10
  204. package/node_modules/@kardalum/plugin-package/dist/hash.d.ts +1 -1
  205. package/node_modules/@kardalum/plugin-package/dist/hash.js +1 -1
  206. package/node_modules/@kardalum/plugin-package/dist/index.d.ts +4 -2
  207. package/node_modules/@kardalum/plugin-package/dist/index.js +3 -1
  208. package/node_modules/@kardalum/plugin-package/dist/license-verdict.d.ts +56 -19
  209. package/node_modules/@kardalum/plugin-package/dist/license-verdict.js +119 -25
  210. package/node_modules/@kardalum/plugin-package/dist/package-contract.d.ts +2 -2
  211. package/node_modules/@kardalum/plugin-package/dist/package-contract.js +5 -5
  212. package/node_modules/@kardalum/plugin-package/dist/types.d.ts +1 -1
  213. package/node_modules/@kardalum/plugin-package/dist/vendor-token.d.ts +24 -0
  214. package/node_modules/@kardalum/plugin-package/dist/vendor-token.js +118 -0
  215. package/node_modules/@kardalum/ui/README.md +1 -1
  216. package/node_modules/@kardalum/ui/dist/components/alert-dialog.d.ts +1 -1
  217. package/node_modules/@kardalum/ui/dist/components/alert-dialog.js +8 -3
  218. package/node_modules/@kardalum/ui/dist/components/badge.js +1 -1
  219. package/node_modules/@kardalum/ui/dist/components/button.js +2 -2
  220. package/node_modules/@kardalum/ui/dist/components/checkbox.js +1 -1
  221. package/node_modules/@kardalum/ui/dist/components/dialog.d.ts +1 -1
  222. package/node_modules/@kardalum/ui/dist/components/dialog.js +52 -4
  223. package/node_modules/@kardalum/ui/dist/components/dropdown-menu.d.ts +5 -1
  224. package/node_modules/@kardalum/ui/dist/components/dropdown-menu.js +20 -7
  225. package/node_modules/@kardalum/ui/dist/components/empty-state.d.ts +4 -4
  226. package/node_modules/@kardalum/ui/dist/components/input.js +6 -1
  227. package/node_modules/@kardalum/ui/dist/components/popover-panel.d.ts +4 -0
  228. package/node_modules/@kardalum/ui/dist/components/popover-panel.js +13 -0
  229. package/node_modules/@kardalum/ui/dist/components/property-field.js +3 -3
  230. package/node_modules/@kardalum/ui/dist/components/sheet.d.ts +1 -1
  231. package/node_modules/@kardalum/ui/dist/components/sheet.js +15 -9
  232. package/node_modules/@kardalum/ui/dist/components/skeleton.js +1 -1
  233. package/node_modules/@kardalum/ui/dist/components/switch.js +1 -1
  234. package/node_modules/@kardalum/ui/dist/components/tab-strip.d.ts +3 -3
  235. package/node_modules/@kardalum/ui/dist/components/tab-strip.js +1 -1
  236. package/node_modules/@kardalum/ui/dist/components/toast.js +4 -3
  237. package/node_modules/@kardalum/ui/dist/components/tooltip.d.ts +27 -0
  238. package/node_modules/@kardalum/ui/dist/components/tooltip.js +82 -0
  239. package/node_modules/@kardalum/ui/dist/components/truncated-text.d.ts +11 -0
  240. package/node_modules/@kardalum/ui/dist/components/truncated-text.js +94 -0
  241. package/node_modules/@kardalum/ui/dist/components/use-toast.js +2 -2
  242. package/node_modules/@kardalum/ui/dist/index.d.ts +4 -1
  243. package/node_modules/@kardalum/ui/dist/index.js +4 -1
  244. package/node_modules/@kardalum/ui/dist/lib/menu-host.d.ts +5 -0
  245. package/node_modules/@kardalum/ui/dist/lib/menu-host.js +17 -0
  246. package/node_modules/@kardalum/ui/package.json +8 -6
  247. package/package.json +21 -7
package/dist/built-ins.js CHANGED
@@ -1,13 +1,14 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { CONTENT_LIST_DEFAULT_SETTINGS } from "@kardalum/api-schemas";
3
3
  import { Checkbox, Input, PropertyField, usePropertyFieldControl } from "@kardalum/ui";
4
- import { CONTENT_LIST_SETTINGS_SCHEMA, CROP_DEFAULT_SETTINGS, CROP_SETTINGS_SCHEMA, FILE_UPLOAD_SETTINGS_SCHEMA, HTML_DEFAULT_SETTINGS, HTML_SETTINGS_SCHEMA, IMAGE_DEFAULT_SETTINGS, IMAGE_SETTINGS_SCHEMA, TEXT_DEFAULT_SETTINGS, TEXT_SETTINGS_SCHEMA, THUMBNAIL_DEFAULT_SETTINGS, THUMBNAIL_SETTINGS_SCHEMA, } from "./built-in-settings-schemas.js";
4
+ import { ASSET_DEFAULT_SETTINGS, ASSET_SETTINGS_SCHEMA, CONTENT_LIST_SETTINGS_SCHEMA, CROP_DEFAULT_SETTINGS, CROP_SETTINGS_SCHEMA, FILE_UPLOAD_SETTINGS_SCHEMA, HTML_DEFAULT_SETTINGS, HTML_SETTINGS_SCHEMA, IMAGE_DEFAULT_SETTINGS, IMAGE_SETTINGS_SCHEMA, TEXT_DEFAULT_SETTINGS, TEXT_SETTINGS_SCHEMA, THUMBNAIL_DEFAULT_SETTINGS, THUMBNAIL_SETTINGS_SCHEMA, } from "./built-in-settings-schemas.js";
5
5
  import { BUILT_IN_VALUE_SCHEMAS } from "./built-in-value-schemas.js";
6
6
  import { BUILT_IN_SERIALIZERS, identitySerializer } from "./built-in-serializers.js";
7
7
  import { BUILT_IN_DATATYPE_VALIDATORS } from "./datatype-validation.js";
8
8
  import { definePlugin } from "./define-plugin.js";
9
9
  import { usePluginSettings, usePluginSettingsValue, usePluginValue } from "./plugin-context.js";
10
10
  import { registerDataType } from "./registry.js";
11
+ import { AssetInputView, AssetReadOnlyView, AssetSettingsView } from "./views/asset-view.js";
11
12
  import { ContentListPreview } from "./views/content-list-preview.js";
12
13
  import { ContentListSettingsView } from "./views/content-list-settings-view.js";
13
14
  import { ContentListInputView, ContentListReadOnlyView } from "./views/content-list-view.js";
@@ -28,14 +29,14 @@ function NotImplementedView() {
28
29
  // Every built-in input view spreads usePropertyFieldControl(): the host
29
30
  // renders these inside a PropertyField whose <label> has no child element
30
31
  // to point at (the view is a component, not a DOM node), so without this
31
- // the control has no accessible name at all — WCAG 4.1.2, and exactly
32
+ // the control has no accessible name at all (WCAG 4.1.2), and exactly
32
33
  // what axe reports as `label` / `aria-input-field-name`.
33
34
  function TextInputView() {
34
35
  const { value, onChange } = usePluginValue();
35
36
  const settings = usePluginSettings();
36
37
  const field = usePropertyFieldControl();
37
38
  return (_jsx(Input, { ...field, value: value ?? "", placeholder: settings.placeholder,
38
- // Hard limit: the browser physically blocks keystrokes past this —
39
+ // Hard limit: the browser physically blocks keystrokes past this,
39
40
  // a different, config-level concept from FieldValidation.maxLength
40
41
  // (field-row.tsx), which is a soft, validated-on-blur field rule.
41
42
  maxLength: settings.maxLength, onChange: (e) => onChange(e.target.value) }));
@@ -44,7 +45,7 @@ function TextReadOnlyView() {
44
45
  const { value } = usePluginValue();
45
46
  return _jsx("p", { children: value ?? "" });
46
47
  }
47
- // Rendered by the Data Types editor only (data-type-editor.tsx) — a
48
+ // Rendered by the Data Types editor only (data-type-editor.tsx), a
48
49
  // settings-EDITING view, so it uses usePluginSettingsValue() (write path),
49
50
  // not usePluginSettings() (read-only, used by the input/readOnly views
50
51
  // above). Hardcoded English strings: this file has no access to
@@ -90,7 +91,7 @@ const NOT_IMPLEMENTED_VIEWS = {
90
91
  const NO_SETTINGS = { type: "object", properties: {} };
91
92
  function builtIn(id, name, icon, schema, views = NOT_IMPLEMENTED_VIEWS, options = {}) {
92
93
  // Through definePlugin (Session 61) so built-ins take the exact
93
- // validation path external plugins do — a regression in any built-in
94
+ // validation path external plugins do, so a regression in any built-in
94
95
  // definition fails loudly at module load, not silently at render.
95
96
  return definePlugin({
96
97
  id: `com.kardalum.${id}`,
@@ -110,12 +111,12 @@ function builtIn(id, name, icon, schema, views = NOT_IMPLEMENTED_VIEWS, options
110
111
  isEmpty: BUILT_IN_DATATYPE_VALIDATORS[`com.kardalum.${id}`]?.isEmpty,
111
112
  });
112
113
  }
113
- // Real views (Session 35) — settings stays NotImplementedView for four
114
+ // Real views (Session 35): settings stays NotImplementedView for four
114
115
  // of six (number/boolean/date/richtext) since they have no configurable
115
116
  // settings yet (empty settingsSchema). text and image gained real
116
117
  // settings + settingsSchema in Session 69, proving the settings pipeline
117
118
  // before Google Maps uses the exact same path.
118
- // `preview` is aliased to the same `readOnly` view (Session 41) — used by
119
+ // `preview` is aliased to the same `readOnly` view (Session 41), used by
119
120
  // the document type builder's per-field live preview while designing a
120
121
  // field, deliberately not a `disabled`-attribute wrapper around `input`:
121
122
  // the rich text view is TipTap/contenteditable, which a native `disabled`
@@ -145,7 +146,7 @@ registerDataType(builtIn("date", "Date", "calendar", BUILT_IN_VALUE_SCHEMAS["com
145
146
  settings: NotImplementedView,
146
147
  preview: DateReadOnlyView,
147
148
  }));
148
- // Stores a media reference id — the Media Library item itself is
149
+ // Stores a media reference id; the Media Library item itself is
149
150
  // fetched separately (GET /api/manage/v1/media/:id), not embedded in the field
150
151
  // value. S234d gave the view a second way to fill that id: Choose opens
151
152
  // the shared media picker over the library, beside the upload it has had
@@ -187,10 +188,10 @@ registerDataType(builtIn("richtext", "Rich Text", "file-text", BUILT_IN_VALUE_SC
187
188
  preview: RichTextReadOnlyView,
188
189
  }));
189
190
  // S197 Task 8 (spec §7, D7): developer-authored raw HTML, distinct from
190
- // the rich (TipTap) editor above — a plain string value edited in
191
+ // the rich (TipTap) editor above: a plain string value edited in
191
192
  // CodeMirror. `trusted` (default false) is the datatype's one setting;
192
193
  // the render pipeline (apps/server/src/render/render-context.ts) is what
193
- // actually enforces the posture this settings flag configures — this
194
+ // actually enforces the posture this settings flag configures; this
194
195
  // registration only carries the flag, it doesn't interpret it.
195
196
  registerDataType(builtIn("html", "HTML", "code", BUILT_IN_VALUE_SCHEMAS["com.kardalum.html"], {
196
197
  input: HtmlInputView,
@@ -198,7 +199,7 @@ registerDataType(builtIn("html", "HTML", "code", BUILT_IN_VALUE_SCHEMAS["com.kar
198
199
  settings: HtmlSettingsView,
199
200
  preview: HtmlReadOnlyView,
200
201
  }, { settingsSchema: HTML_SETTINGS_SCHEMA, defaultSettings: HTML_DEFAULT_SETTINGS }));
201
- // S198 Task 3: the first composite built-in datatype — its value has two
202
+ // S198 Task 3: the first composite built-in datatype: its value has two
202
203
  // interdependent members ({ start, end }), which is exactly what forces
203
204
  // the validate hook's shape to be honest: `path` names which sub-input is
204
205
  // at fault, and `isEmpty` lets `required` mean "a range must be provided"
@@ -255,3 +256,11 @@ registerDataType(builtIn("thumbnail", "Thumbnail", "image-down", BUILT_IN_VALUE_
255
256
  settings: ThumbnailSettingsView,
256
257
  preview: ThumbnailReadOnlyView,
257
258
  }, { settingsSchema: THUMBNAIL_SETTINGS_SCHEMA, defaultSettings: THUMBNAIL_DEFAULT_SETTINGS }));
259
+ // S314p (D3): the Asset editor, a file from Settings, Assets. Seeded as the "Asset" data type by
260
+ // migration 0033; its views read the asset tree through the host's fetch.
261
+ registerDataType(builtIn("asset", "Asset", "folder-open", BUILT_IN_VALUE_SCHEMAS["com.kardalum.asset"], {
262
+ input: AssetInputView,
263
+ readOnly: AssetReadOnlyView,
264
+ settings: AssetSettingsView,
265
+ preview: AssetReadOnlyView,
266
+ }, { settingsSchema: ASSET_SETTINGS_SCHEMA, defaultSettings: ASSET_DEFAULT_SETTINGS }));
@@ -35,6 +35,10 @@ export const CAPABILITY_LABELS = {
35
35
  "admin.section": { operator: "Admin sections", shopper: "Adds admin screens" },
36
36
  "admin.railEntry": { operator: "Admin rail entries", shopper: "Adds screens to built-in sections" },
37
37
  "admin.dashboardWidget": { operator: "Dashboard widgets", shopper: "Adds dashboard widgets" },
38
+ "admin.notifications": {
39
+ operator: "Notifications",
40
+ shopper: "Sends notifications to people in the admin, for example to everyone who may publish.",
41
+ },
38
42
  "render.template": { operator: "Render templates", shopper: "Ships render templates" },
39
43
  "render.asset": { operator: "Editable assets", shopper: "Ships editable assets" },
40
44
  "theme.tokens": { operator: "Theme tokens", shopper: "Restyles the admin" },
@@ -49,6 +53,7 @@ export const CAPABILITY_LABELS = {
49
53
  "bundle.plugin": { operator: "Bundled plugins", shopper: "Installs other plugins with it" },
50
54
  "bundle.template": { operator: "Bundled starter", shopper: "Comes with a frontend starter" },
51
55
  "network.external": { operator: "External network", shopper: "Reaches the network" },
56
+ "network.vendorService": { operator: "Vendor service", shopper: "Serves its paid features from the author's server" },
52
57
  "filesystem.access": { operator: "Filesystem access", shopper: "Reads or writes files" },
53
58
  };
54
59
  /**
@@ -19,8 +19,8 @@ export interface DataTypePlugin {
19
19
  views: DataTypePluginViews;
20
20
  serialize: (value: unknown, settings: Record<string, unknown>) => unknown;
21
21
  deserialize: (raw: unknown, settings: Record<string, unknown>) => unknown;
22
- /** Datatype-intrinsic validation (S198). Pure, synchronous, runtime-only
23
- * — never serialized into manifest.json (same as PluginHooks). */
22
+ /** Datatype-intrinsic validation (S198). Pure, synchronous, runtime-only,
23
+ * never serialized into manifest.json (same as PluginHooks). */
24
24
  validate?: DataTypeValidateHook;
25
25
  /** Optional emptiness predicate for composite values, consulted by the
26
26
  * `required` rule so a webmaster never needs to know the value shape. */
@@ -14,8 +14,8 @@ export interface DataTypeValidatorEntry {
14
14
  /**
15
15
  * The datatype's own `defaultSettings`. A DataTypeConfig stores `{}`
16
16
  * until a webmaster opens the settings view and changes something, and
17
- * the admin's resolver already substitutes these defaults in that case
18
- * — so the hook has to see them too, or it judges a value against
17
+ * the admin's resolver already substitutes these defaults in that case,
18
+ * so the hook has to see them too, or it judges a value against
19
19
  * different settings than the input view was configured with.
20
20
  */
21
21
  defaultSettings?: Record<string, unknown>;
@@ -1,7 +1,4 @@
1
- // The datatype validate hook (S198 spec §2). Deliberately React-free and
2
- // dependency-free: the SERVER imports this module to build its validator
3
- // lookup, and anything React-shaped here would drag the admin's UI graph
4
- // into plugin artifacts (the S197 F5 lesson).
1
+ import { AssetPathSchema, assetPathAccepted } from "@kardalum/api-schemas";
5
2
  const ISO_DATE = /^\d{4}-\d{2}-\d{2}$/;
6
3
  // A member reads as its string, as null (absent), or as MALFORMED when it
7
4
  // is present but not a string at all. Keeping the two failure modes apart
@@ -32,11 +29,11 @@ function isValidIsoDate(value) {
32
29
  // its lookup with a single object read.
33
30
  export const BUILT_IN_DATATYPE_VALIDATORS = {
34
31
  "com.kardalum.daterange": {
35
- // `required` asks this, not `validate` — Task 2 only calls `validate`
32
+ // `required` asks this, not `validate`. Task 2 only calls `validate`
36
33
  // once a value is present, so "empty" for a two-member composite has
37
34
  // to be answered here: both members null (or a value that is not an
38
35
  // object at all) is empty. A member that is present but malformed is
39
- // NOT empty — it is a value the editor supplied and got wrong, so it
36
+ // NOT empty: it is a value the editor supplied and got wrong, so it
40
37
  // must reach `validate` rather than be reported as a missing field.
41
38
  isEmpty(value) {
42
39
  const range = readDateRange(value);
@@ -107,4 +104,21 @@ export const BUILT_IN_DATATYPE_VALIDATORS = {
107
104
  "com.kardalum.thumbnail": {
108
105
  isEmpty: () => true,
109
106
  },
107
+ // S314p (D3). An Asset field holds a path under public/, the way Settings, Assets names a file.
108
+ // Its form is AssetPathSchema's (no "..", no hidden file, no reserved root); a type that takes
109
+ // images only also wants one of the image extensions. Whether the file exists is not asked
110
+ // (spec C6): a script may write the page before it uploads the kit's files, and the field shows a
111
+ // missing file instead.
112
+ "com.kardalum.asset": {
113
+ defaultSettings: { accepts: "images", startFolder: null },
114
+ isEmpty: (value) => value === null || value === undefined || value === "",
115
+ validate(value, { settings }) {
116
+ if (typeof value !== "string" || !AssetPathSchema.safeParse(value).success) {
117
+ return [{ key: "dataTypes.asset.errors.invalidPath" }];
118
+ }
119
+ if (!assetPathAccepted(value, settings.accepts))
120
+ return [{ key: "dataTypes.asset.errors.notAnImage" }];
121
+ return [];
122
+ },
123
+ },
110
124
  };
@@ -1,4 +1,5 @@
1
1
  export { BUILT_IN_SETTINGS_SCHEMAS } from "./built-in-settings-schemas.js";
2
2
  export { BUILT_IN_VALUE_SCHEMAS } from "./built-in-value-schemas.js";
3
+ export { BUILT_IN_EDITOR_IDS } from "./built-in-editor-ids.js";
3
4
  export { BUILT_IN_SERIALIZERS, identitySerializer, type DataTypeSerializer, } from "./built-in-serializers.js";
4
5
  export { RENDITION_INELIGIBLE_TYPES, isRenditionIneligible } from "./rendition-eligibility.js";
@@ -9,6 +9,7 @@
9
9
  // one.
10
10
  export { BUILT_IN_SETTINGS_SCHEMAS } from "./built-in-settings-schemas.js";
11
11
  export { BUILT_IN_VALUE_SCHEMAS } from "./built-in-value-schemas.js";
12
+ export { BUILT_IN_EDITOR_IDS } from "./built-in-editor-ids.js";
12
13
  export { BUILT_IN_SERIALIZERS, identitySerializer, } from "./built-in-serializers.js";
13
14
  // S234c fix wave: the "no GIF, no SVG" rule, read by the cut route so a
14
15
  // signed-in caller cannot post a "crop" of a format the browser refuses to
@@ -1,6 +1,6 @@
1
1
  import type { DataTypePlugin } from "./data-type-plugin.js";
2
2
  /**
3
- * Thrown when a plugin definition fails validation — catchable by the
3
+ * Thrown when a plugin definition fails validation, catchable by the
4
4
  * registry's install() (Session 62) and `kardalum plugin validate`
5
5
  * (Month 7), which want to report rather than crash.
6
6
  */
@@ -11,15 +11,15 @@ export declare class PluginDefinitionError extends Error {
11
11
  * Validate a datatype plugin definition and hand it back. This is the
12
12
  * one code path into the registry: built-ins construct their plugin
13
13
  * objects through it (see built-ins.tsx), and external plugins do the
14
- * same — so a missing required view fails LOUDLY at definition time,
14
+ * same, so a missing required view fails LOUDLY at definition time,
15
15
  * never silently at render time (plugin-sdk.md).
16
16
  *
17
17
  * Deliberately does NOT register: Module Federation remotes (Session 66)
18
18
  * export the defined plugin object, and the HOST decides when it enters
19
- * the registry (install/activate lifecycle) — a define-time side effect
19
+ * the registry (install/activate lifecycle), as a define-time side effect
20
20
  * would take that control away. Pass the result to registerDataType.
21
21
  *
22
- * Returns the ORIGINAL object (not a parsed clone) — a plugin carries
22
+ * Returns the ORIGINAL object (not a parsed clone): a plugin carries
23
23
  * React components and closures whose identity should survive.
24
24
  */
25
25
  export declare function definePlugin(plugin: DataTypePlugin): DataTypePlugin;
@@ -1,6 +1,6 @@
1
1
  import { DataTypePluginSchema, formatIssues } from "./manifest-schema.js";
2
2
  /**
3
- * Thrown when a plugin definition fails validation — catchable by the
3
+ * Thrown when a plugin definition fails validation, catchable by the
4
4
  * registry's install() (Session 62) and `kardalum plugin validate`
5
5
  * (Month 7), which want to report rather than crash.
6
6
  */
@@ -15,22 +15,22 @@ const REQUIRED_VIEWS = ["input", "readOnly", "settings"];
15
15
  * Validate a datatype plugin definition and hand it back. This is the
16
16
  * one code path into the registry: built-ins construct their plugin
17
17
  * objects through it (see built-ins.tsx), and external plugins do the
18
- * same — so a missing required view fails LOUDLY at definition time,
18
+ * same, so a missing required view fails LOUDLY at definition time,
19
19
  * never silently at render time (plugin-sdk.md).
20
20
  *
21
21
  * Deliberately does NOT register: Module Federation remotes (Session 66)
22
22
  * export the defined plugin object, and the HOST decides when it enters
23
- * the registry (install/activate lifecycle) — a define-time side effect
23
+ * the registry (install/activate lifecycle), as a define-time side effect
24
24
  * would take that control away. Pass the result to registerDataType.
25
25
  *
26
- * Returns the ORIGINAL object (not a parsed clone) — a plugin carries
26
+ * Returns the ORIGINAL object (not a parsed clone): a plugin carries
27
27
  * React components and closures whose identity should survive.
28
28
  */
29
29
  export function definePlugin(plugin) {
30
30
  const id = typeof plugin === "object" && plugin !== null && typeof plugin.id === "string"
31
31
  ? plugin.id
32
32
  : "(unknown id)";
33
- // Required views first, with purpose-built messages — Zod's generic
33
+ // Required views first, with purpose-built messages, since Zod's generic
34
34
  // "expected custom, received undefined" doesn't tell a plugin author
35
35
  // what to fix.
36
36
  const views = typeof plugin === "object" && plugin !== null ? plugin.views : undefined;
@@ -1,5 +1,6 @@
1
- export { EntitlementError, ENTITLEMENT_FLOOR_TABLE, isEntitlementError, requireEntitlement, structuredStorageFloor, type EntitlementFloor, type RequireEntitlementOptions, } from "./entitlement.js";
1
+ export { EntitlementError, ENTITLEMENT_FLOOR_TABLE, entitlementPlan, isEntitlementError, requireEntitlement, structuredStorageFloor, type EntitlementFloor, type EntitlementPlanOptions, type RequireEntitlementOptions, } from "./entitlement.js";
2
+ export { highestListingPlan, UNKNOWN_TERM, type EntitlementPlan } from "./entitlement-plan.js";
2
3
  export { LICENSE_VERDICT_PUBLIC_KEYS } from "./license-verdict-keys.js";
3
4
  export { isLocalHost } from "./local-host.js";
4
- export type { Entitlement, EntitlementErrorCode, EntitlementVerdict, LicenseVerdictEnvelope, PluginTaskContext, } from "./entitlement-types.js";
5
+ export type { Entitlement, EntitlementErrorCode, EntitlementVerdict, LicenseVerdictEnvelope, LicenseVerdictTerm, ListingPlanSummary, PluginTaskContext, } from "./entitlement-types.js";
5
6
  export type { TrustedKey } from "@kardalum/plugin-package";
@@ -19,6 +19,18 @@
19
19
  //
20
20
  // The host turns a thrown EntitlementError into a 403 for a route and skips
21
21
  // a hook that throws it.
22
- export { EntitlementError, ENTITLEMENT_FLOOR_TABLE, isEntitlementError, requireEntitlement, structuredStorageFloor, } from "./entitlement.js";
22
+ //
23
+ // S317: the plan and the term, after the check passed:
24
+ //
25
+ // const plan = entitlementPlan(context.entitlement, { pluginId: "com.acme.reports" });
26
+ // if (plan?.planId === "pro") { ... }
27
+ // if (plan?.term.state === "lapsed") { refuse writes, keep reads }
28
+ //
29
+ // S318: while the term is lapsed the host itself refuses the plugin's writes
30
+ // (403 plugin_read_only), and tells a route or hook so:
31
+ //
32
+ // if (context.readOnly) { skip writes }
33
+ export { EntitlementError, ENTITLEMENT_FLOOR_TABLE, entitlementPlan, isEntitlementError, requireEntitlement, structuredStorageFloor, } from "./entitlement.js";
34
+ export { highestListingPlan, UNKNOWN_TERM } from "./entitlement-plan.js";
23
35
  export { LICENSE_VERDICT_PUBLIC_KEYS } from "./license-verdict-keys.js";
24
36
  export { isLocalHost } from "./local-host.js";
@@ -1,5 +1,6 @@
1
1
  import { type JSX, type ReactNode } from "react";
2
2
  import type { TrustedKey } from "@kardalum/plugin-package";
3
+ import type { EntitlementPlan } from "./entitlement-plan.js";
3
4
  import type { EntitlementErrorCode, LicenseVerdictEnvelope } from "./entitlement-types.js";
4
5
  export declare const BROWSER_ENTITLEMENT_MAX_AGE_MS: number;
5
6
  export declare const BROWSER_MAX_VERDICT_AGE_MS: number;
@@ -7,6 +8,10 @@ export type EntitlementStatus = "loading" | "entitled" | "locked";
7
8
  export interface UseEntitlementResult {
8
9
  status: EntitlementStatus;
9
10
  reason?: EntitlementErrorCode;
11
+ /** S317: the plan and term, when entitled; plan unknown when this browser cannot verify the term (plan P9). */
12
+ plan?: EntitlementPlan;
13
+ /** S318: true when the verified term is lapsed: the host refuses writes, so disable Save actions. */
14
+ readOnly: boolean;
10
15
  }
11
16
  /** The exact bytes the marketplace signs, built the way
12
17
  * @kardalum/plugin-package's `canonicalizeLicenseVerdict` builds them
@@ -15,12 +20,25 @@ export interface UseEntitlementResult {
15
20
  * module that imports node:crypto; entitlement-gate.test.tsx pins this to
16
21
  * its output for the same envelopes, so the two cannot drift silently. */
17
22
  export declare function canonicalLicenseVerdictBytes(envelope: LicenseVerdictEnvelope): Uint8Array<ArrayBuffer>;
23
+ /** S317: the bytes `termSignature` covers, built the way
24
+ * @kardalum/plugin-package's `canonicalizeLicenseVerdictTerm` builds them
25
+ * (the version 1 fields, then `planId` and `term`, null when absent). A
26
+ * copy for the same reason as above; entitlement-gate.test.tsx pins it. */
27
+ export declare function canonicalLicenseVerdictTermBytes(envelope: LicenseVerdictEnvelope): Uint8Array<ArrayBuffer>;
18
28
  /** true or false when this browser could check the signature itself; null
19
29
  * when it cannot import an Ed25519 key, and the host's answer stands in. */
20
30
  export declare function verifyEntitlementInBrowser(entitlement: {
21
31
  envelope: LicenseVerdictEnvelope;
22
32
  signature: string;
23
33
  }, trustedKeys: TrustedKey[]): Promise<boolean | null>;
34
+ /** S317: true when the envelope carries a well-formed plan or term and its
35
+ * `termSignature` verifies; false when it carries none or the signature is
36
+ * wrong; null when this browser cannot check it (plan P9: the plan then
37
+ * reads as unknown). */
38
+ export declare function verifyTermInBrowser(entitlement: {
39
+ envelope: LicenseVerdictEnvelope;
40
+ termSignature?: string;
41
+ }, trustedKeys: TrustedKey[]): Promise<boolean | null>;
24
42
  /** `entitled` for `exempt` (a non-production install) on a page served from
25
43
  * a local host, and `locked` with `missing` for `exempt` anywhere else and
26
44
  * for `none` (no verdict held); a `verdict` is verified as above. A host answer the view cannot read at all (no session, an unknown
@@ -16,7 +16,12 @@ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-run
16
16
  // is absent. There is no floor in the browser: the view gate is the visible
17
17
  // half, the server route's `requireEntitlement` is the one that guards the
18
18
  // work.
19
+ //
20
+ // Since S317 the result carries `plan` beside the status: the signed plan
21
+ // and term when this browser verified their `termSignature`, otherwise plan
22
+ // unknown, term active.
19
23
  import { useEffect, useState } from "react";
24
+ import { highestListingPlan, planFromEnvelope, UNKNOWN_TERM } from "./entitlement-plan.js";
20
25
  import { LICENSE_VERDICT_PUBLIC_KEYS } from "./license-verdict-keys.js";
21
26
  import { isLocalHost } from "./local-host.js";
22
27
  import { usePluginApi } from "./plugin-context.js";
@@ -48,6 +53,32 @@ export function canonicalLicenseVerdictBytes(envelope) {
48
53
  ...(envelope.detail !== undefined ? { detail: envelope.detail } : {}),
49
54
  }));
50
55
  }
56
+ /** S317: the bytes `termSignature` covers, built the way
57
+ * @kardalum/plugin-package's `canonicalizeLicenseVerdictTerm` builds them
58
+ * (the version 1 fields, then `planId` and `term`, null when absent). A
59
+ * copy for the same reason as above; entitlement-gate.test.tsx pins it. */
60
+ export function canonicalLicenseVerdictTermBytes(envelope) {
61
+ const term = envelope.term;
62
+ return new TextEncoder().encode(JSON.stringify({
63
+ v: envelope.v,
64
+ alg: envelope.alg,
65
+ typ: envelope.typ,
66
+ keyId: envelope.keyId,
67
+ keyHash: envelope.keyHash,
68
+ pluginId: envelope.pluginId,
69
+ domain: envelope.domain,
70
+ nonce: envelope.nonce,
71
+ status: envelope.status,
72
+ reason: envelope.reason ?? null,
73
+ issuedAt: envelope.issuedAt,
74
+ ...(envelope.tamper !== undefined ? { tamper: envelope.tamper } : {}),
75
+ ...(envelope.detail !== undefined ? { detail: envelope.detail } : {}),
76
+ planId: envelope.planId ?? null,
77
+ term: term === undefined
78
+ ? null
79
+ : { state: term.state, endsAt: term.endsAt, renewalAmountCents: term.renewalAmountCents, cancelAtPeriodEnd: term.cancelAtPeriodEnd },
80
+ }));
81
+ }
51
82
  function base64ToBytes(value) {
52
83
  const binary = atob(value);
53
84
  const bytes = new Uint8Array(binary.length);
@@ -76,9 +107,9 @@ function looksLikeVerdict(value) {
76
107
  typeof e.issuedAt === "string");
77
108
  }
78
109
  const ED25519_SPKI_LENGTH = 44;
79
- /** true or false when this browser could check the signature itself; null
80
- * when it cannot import an Ed25519 key, and the host's answer stands in. */
81
- export async function verifyEntitlementInBrowser(entitlement, trustedKeys) {
110
+ /** true or false when this browser could check `signature` over `bytes`
111
+ * itself; null when it cannot import an Ed25519 key. */
112
+ async function verifyBytesInBrowser(keyId, signatureB64, bytes, trustedKeys) {
82
113
  const subtle = globalThis.crypto?.subtle;
83
114
  if (!subtle)
84
115
  return null;
@@ -96,7 +127,7 @@ export async function verifyEntitlementInBrowser(entitlement, trustedKeys) {
96
127
  // Re-derive the key id from the raw key, as the server does: the
97
128
  // listed keyId is a label, the key is the fact.
98
129
  const derivedId = toHex(await subtle.digest("SHA-256", der.slice(12))).slice(0, 16);
99
- if (derivedId !== entitlement.envelope.keyId)
130
+ if (derivedId !== keyId)
100
131
  continue;
101
132
  let key;
102
133
  try {
@@ -107,12 +138,12 @@ export async function verifyEntitlementInBrowser(entitlement, trustedKeys) {
107
138
  }
108
139
  let signature;
109
140
  try {
110
- signature = base64ToBytes(entitlement.signature);
141
+ signature = base64ToBytes(signatureB64);
111
142
  }
112
143
  catch {
113
144
  return false;
114
145
  }
115
- return await subtle.verify({ name: "Ed25519" }, key, signature, canonicalLicenseVerdictBytes(entitlement.envelope));
146
+ return await subtle.verify({ name: "Ed25519" }, key, signature, bytes);
116
147
  }
117
148
  return false;
118
149
  }
@@ -120,22 +151,56 @@ export async function verifyEntitlementInBrowser(entitlement, trustedKeys) {
120
151
  return null;
121
152
  }
122
153
  }
154
+ /** true or false when this browser could check the signature itself; null
155
+ * when it cannot import an Ed25519 key, and the host's answer stands in. */
156
+ export async function verifyEntitlementInBrowser(entitlement, trustedKeys) {
157
+ return verifyBytesInBrowser(entitlement.envelope.keyId, entitlement.signature, canonicalLicenseVerdictBytes(entitlement.envelope), trustedKeys);
158
+ }
159
+ const TERM_STATES = ["active", "renewing", "past_due", "lapsed"];
160
+ function termShapeOk(envelope) {
161
+ const planId = envelope.planId;
162
+ const term = envelope.term;
163
+ if (planId === undefined && term === undefined)
164
+ return false;
165
+ if (planId !== undefined && (typeof planId !== "string" || planId.length === 0 || planId.length > 64))
166
+ return false;
167
+ if (term === undefined)
168
+ return true;
169
+ if (typeof term !== "object" || term === null)
170
+ return false;
171
+ const t = term;
172
+ return (typeof t.state === "string" && TERM_STATES.includes(t.state) &&
173
+ (t.endsAt === null || (typeof t.endsAt === "string" && Number.isFinite(Date.parse(t.endsAt)))) &&
174
+ (t.renewalAmountCents === null || (typeof t.renewalAmountCents === "number" && Number.isInteger(t.renewalAmountCents) && t.renewalAmountCents >= 0)) &&
175
+ typeof t.cancelAtPeriodEnd === "boolean");
176
+ }
177
+ /** S317: true when the envelope carries a well-formed plan or term and its
178
+ * `termSignature` verifies; false when it carries none or the signature is
179
+ * wrong; null when this browser cannot check it (plan P9: the plan then
180
+ * reads as unknown). */
181
+ export async function verifyTermInBrowser(entitlement, trustedKeys) {
182
+ if (!termShapeOk(entitlement.envelope))
183
+ return false;
184
+ if (typeof entitlement.termSignature !== "string" || entitlement.termSignature.length === 0)
185
+ return false;
186
+ return verifyBytesInBrowser(entitlement.envelope.keyId, entitlement.termSignature, canonicalLicenseVerdictTermBytes(entitlement.envelope), trustedKeys);
187
+ }
123
188
  /** The checks after the signature, in the server's order. */
124
189
  function decide(entitlement, pluginId, now) {
125
190
  const { envelope } = entitlement;
126
191
  if (envelope.pluginId !== pluginId)
127
- return { status: "locked", reason: "wrong-plugin" };
192
+ return { status: "locked", reason: "wrong-plugin", readOnly: false };
128
193
  if (envelope.status !== "valid")
129
- return { status: "locked", reason: "not-valid" };
194
+ return { status: "locked", reason: "not-valid", readOnly: false };
130
195
  const issuedMs = Date.parse(envelope.issuedAt);
131
196
  const nowMs = now.getTime();
132
197
  if (!Number.isFinite(issuedMs))
133
- return { status: "locked", reason: "invalid-signature" };
198
+ return { status: "locked", reason: "invalid-signature", readOnly: false };
134
199
  if (nowMs - issuedMs > BROWSER_ENTITLEMENT_MAX_AGE_MS)
135
- return { status: "locked", reason: "expired" };
200
+ return { status: "locked", reason: "expired", readOnly: false };
136
201
  if (issuedMs > nowMs + BROWSER_MAX_VERDICT_AGE_MS)
137
- return { status: "locked", reason: "expired" };
138
- return { status: "entitled" };
202
+ return { status: "locked", reason: "expired", readOnly: false };
203
+ return { status: "entitled", readOnly: false };
139
204
  }
140
205
  /** S284b, C9: the host hands `exempt` whenever its site domain is unset or
141
206
  * local, which is one environment variable. The view takes it only when the
@@ -151,30 +216,39 @@ function pageIsLocal() {
151
216
  * that cannot tell does not open. A free plugin never uses the gate. */
152
217
  export function useEntitlement(pluginId) {
153
218
  const fetchApi = usePluginApi();
154
- const [result, setResult] = useState({ status: "loading" });
219
+ const [result, setResult] = useState({ status: "loading", readOnly: false });
155
220
  useEffect(() => {
156
221
  let cancelled = false;
157
- setResult({ status: "loading" });
222
+ setResult({ status: "loading", readOnly: false });
158
223
  (async () => {
159
224
  const response = await fetchApi(`/api/plugin-management/entitlement/${encodeURIComponent(pluginId)}`);
160
225
  if (!response.ok)
161
- return { status: "locked", reason: "missing" };
226
+ return { status: "locked", reason: "missing", readOnly: false };
162
227
  const body = (await response.json());
163
228
  const entitlement = body?.entitlement;
229
+ // S318: the host's answer counts even where this browser cannot verify the term.
230
+ const hostReadOnly = body?.readOnly !== undefined && body?.readOnly !== null;
164
231
  if (entitlement?.kind === "exempt") {
165
- return pageIsLocal() ? { status: "entitled" } : { status: "locked", reason: "missing" };
232
+ return pageIsLocal()
233
+ ? { status: "entitled", plan: { planId: highestListingPlan(entitlement.listingPlans), term: { ...UNKNOWN_TERM } }, readOnly: hostReadOnly }
234
+ : { status: "locked", reason: "missing", readOnly: hostReadOnly };
166
235
  }
167
236
  if (entitlement?.kind !== "verdict")
168
- return { status: "locked", reason: "missing" };
237
+ return { status: "locked", reason: "missing", readOnly: hostReadOnly };
169
238
  if (!looksLikeVerdict(entitlement))
170
- return { status: "locked", reason: "invalid-signature" };
239
+ return { status: "locked", reason: "invalid-signature", readOnly: hostReadOnly };
171
240
  const own = await verifyEntitlementInBrowser(entitlement, LICENSE_VERDICT_PUBLIC_KEYS);
172
241
  const authentic = own ?? body.valid === true;
173
242
  if (!authentic)
174
- return { status: "locked", reason: "invalid-signature" };
175
- return decide(entitlement, pluginId, new Date());
243
+ return { status: "locked", reason: "invalid-signature", readOnly: hostReadOnly };
244
+ const decided = decide(entitlement, pluginId, new Date());
245
+ if (decided.status !== "entitled")
246
+ return { ...decided, readOnly: hostReadOnly };
247
+ const termOk = await verifyTermInBrowser(entitlement, LICENSE_VERDICT_PUBLIC_KEYS);
248
+ const plan = planFromEnvelope(entitlement.envelope, termOk === true);
249
+ return { ...decided, plan, readOnly: hostReadOnly || plan.term.state === "lapsed" };
176
250
  })()
177
- .catch(() => ({ status: "locked", reason: "missing" }))
251
+ .catch(() => ({ status: "locked", reason: "missing", readOnly: false }))
178
252
  .then((next) => {
179
253
  if (!cancelled)
180
254
  setResult(next);
@@ -0,0 +1,21 @@
1
+ import type { LicenseVerdictEnvelope, LicenseVerdictTerm } from "@kardalum/plugin-package";
2
+ import type { ListingPlanSummary } from "./entitlement-types.js";
3
+ /** What a plugin knows about its licence's plan. `planId` is the plan's key
4
+ * on the listing, or null when unknown (a verdict from before S317, a host
5
+ * that could not verify the term, or a local install whose listing plans
6
+ * are not known). */
7
+ export interface EntitlementPlan {
8
+ planId: string | null;
9
+ term: LicenseVerdictTerm;
10
+ }
11
+ /** The term of a verdict that carries none: active, nothing known (S315
12
+ * section 9: an old verdict reads as plan unknown, term active). */
13
+ export declare const UNKNOWN_TERM: Readonly<LicenseVerdictTerm>;
14
+ /** S315 section 9: on a local install a plugin sees its listing's highest
15
+ * plan, the one with the highest yearly equivalent (the later position on
16
+ * a tie). Null with no plans. */
17
+ export declare function highestListingPlan(plans: readonly ListingPlanSummary[] | undefined): string | null;
18
+ /** The plan and term of an envelope whose base signature verified.
19
+ * `termVerified` says whether its `termSignature` did too; without it the
20
+ * fields are not trusted and the plan reads as unknown. */
21
+ export declare function planFromEnvelope(envelope: LicenseVerdictEnvelope, termVerified: boolean): EntitlementPlan;
@@ -0,0 +1,26 @@
1
+ /** The term of a verdict that carries none: active, nothing known (S315
2
+ * section 9: an old verdict reads as plan unknown, term active). */
3
+ export const UNKNOWN_TERM = Object.freeze({ state: "active", endsAt: null, renewalAmountCents: null, cancelAtPeriodEnd: false });
4
+ function yearlyEquivalentCents(plan) {
5
+ return plan.shape === "monthly" ? plan.priceCents * 12 : plan.priceCents;
6
+ }
7
+ /** S315 section 9: on a local install a plugin sees its listing's highest
8
+ * plan, the one with the highest yearly equivalent (the later position on
9
+ * a tie). Null with no plans. */
10
+ export function highestListingPlan(plans) {
11
+ let best = null;
12
+ for (const plan of plans ?? []) {
13
+ if (!best || yearlyEquivalentCents(plan) > yearlyEquivalentCents(best) || (yearlyEquivalentCents(plan) === yearlyEquivalentCents(best) && plan.position > best.position)) {
14
+ best = plan;
15
+ }
16
+ }
17
+ return best?.key ?? null;
18
+ }
19
+ /** The plan and term of an envelope whose base signature verified.
20
+ * `termVerified` says whether its `termSignature` did too; without it the
21
+ * fields are not trusted and the plan reads as unknown. */
22
+ export function planFromEnvelope(envelope, termVerified) {
23
+ if (!termVerified)
24
+ return { planId: null, term: { ...UNKNOWN_TERM } };
25
+ return { planId: envelope.planId ?? null, term: envelope.term ? { ...envelope.term } : { ...UNKNOWN_TERM } };
26
+ }