@kardalum/plugin-sdk 0.16.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 (164) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/dist/admin-section-registry.d.ts +14 -5
  3. package/dist/admin-section-registry.js +14 -4
  4. package/dist/capabilities.js +0 -3
  5. package/dist/host-entry.d.ts +1 -1
  6. package/dist/host-entry.js +1 -1
  7. package/dist/index.d.ts +2 -2
  8. package/dist/index.js +8 -8
  9. package/dist/license-verdict-keys.d.ts +4 -3
  10. package/dist/license-verdict-keys.js +4 -7
  11. package/dist/manifest-entry.d.ts +2 -2
  12. package/dist/manifest-entry.js +1 -1
  13. package/dist/manifest-schema.d.ts +51 -62
  14. package/dist/manifest-schema.js +97 -249
  15. package/dist/manifest.d.ts +41 -73
  16. package/dist/manifest.js +13 -36
  17. package/dist/plugin-screen-context.d.ts +11 -1
  18. package/dist/richtext/block-panel.js +2 -2
  19. package/dist/richtext/insert-menu.js +1 -1
  20. package/dist/richtext/style-listbox.js +4 -4
  21. package/dist/tokens/tokens.css +1 -0
  22. package/dist/tokens/tokens.json +2 -1
  23. package/dist/type-equality.d.ts +2 -0
  24. package/dist/type-equality.js +1 -0
  25. package/dist/views/html-view.js +1 -1
  26. package/dist/views/rich-text-view.js +1 -1
  27. package/node_modules/@kardalum/api-schemas/dist/asset-api.schema.d.ts +90 -0
  28. package/node_modules/@kardalum/api-schemas/dist/asset-api.schema.js +32 -1
  29. package/node_modules/@kardalum/api-schemas/dist/asset.schema.d.ts +22 -1
  30. package/node_modules/@kardalum/api-schemas/dist/asset.schema.js +50 -15
  31. package/node_modules/@kardalum/api-schemas/dist/audit-api.schema.d.ts +204 -0
  32. package/node_modules/@kardalum/api-schemas/dist/audit-api.schema.js +134 -0
  33. package/node_modules/@kardalum/api-schemas/dist/content-api.schema.js +6 -5
  34. package/node_modules/@kardalum/api-schemas/dist/content-list.schema.d.ts +2 -2
  35. package/node_modules/@kardalum/api-schemas/dist/content-trash-api.schema.d.ts +4 -0
  36. package/node_modules/@kardalum/api-schemas/dist/content-trash-api.schema.js +3 -0
  37. package/node_modules/@kardalum/api-schemas/dist/content-trash.schema.js +2 -1
  38. package/node_modules/@kardalum/api-schemas/dist/core-actions.d.ts +41 -5
  39. package/node_modules/@kardalum/api-schemas/dist/core-actions.js +23 -9
  40. package/node_modules/@kardalum/api-schemas/dist/index.d.ts +36 -20
  41. package/node_modules/@kardalum/api-schemas/dist/index.js +21 -11
  42. package/node_modules/@kardalum/api-schemas/dist/install-warnings.schema.d.ts +4 -0
  43. package/node_modules/@kardalum/api-schemas/dist/install-warnings.schema.js +8 -0
  44. package/node_modules/@kardalum/api-schemas/dist/issue-list.d.ts +6 -0
  45. package/node_modules/@kardalum/api-schemas/dist/issue-list.js +6 -0
  46. package/node_modules/@kardalum/api-schemas/dist/marketplace-listing-api.schema.d.ts +101 -62
  47. package/node_modules/@kardalum/api-schemas/dist/marketplace-listing-api.schema.js +15 -4
  48. package/node_modules/@kardalum/api-schemas/dist/plugin-actions.schema.d.ts +6 -2
  49. package/node_modules/@kardalum/api-schemas/dist/plugin-actions.schema.js +8 -6
  50. package/node_modules/@kardalum/api-schemas/dist/plugin-docs-api.schema.d.ts +1 -16
  51. package/node_modules/@kardalum/api-schemas/dist/plugin-docs.d.ts +3 -19
  52. package/node_modules/@kardalum/api-schemas/dist/plugin-docs.js +13 -15
  53. package/node_modules/@kardalum/api-schemas/dist/plugin-id-rules.d.ts +17 -7
  54. package/node_modules/@kardalum/api-schemas/dist/plugin-id-rules.js +18 -8
  55. package/node_modules/@kardalum/api-schemas/dist/plugin-install-record.schema.d.ts +1 -1
  56. package/node_modules/@kardalum/api-schemas/dist/plugin-install.d.ts +97 -85
  57. package/node_modules/@kardalum/api-schemas/dist/plugin-install.js +35 -68
  58. package/node_modules/@kardalum/api-schemas/dist/plugin-labels.d.ts +60 -0
  59. package/node_modules/@kardalum/api-schemas/dist/plugin-labels.js +116 -0
  60. package/node_modules/@kardalum/api-schemas/dist/plugin-locales.d.ts +9 -2
  61. package/node_modules/@kardalum/api-schemas/dist/plugin-locales.js +22 -7
  62. package/node_modules/@kardalum/api-schemas/dist/plugin-management-api.schema.d.ts +13 -6
  63. package/node_modules/@kardalum/api-schemas/dist/plugin-management-api.schema.js +7 -1
  64. package/node_modules/@kardalum/api-schemas/dist/plugin-manifest-actions.d.ts +4 -3
  65. package/node_modules/@kardalum/api-schemas/dist/plugin-manifest-actions.js +1 -1
  66. package/node_modules/@kardalum/api-schemas/dist/plugin-manifest-api-routes.d.ts +14 -0
  67. package/node_modules/@kardalum/api-schemas/dist/plugin-manifest-api-routes.js +37 -1
  68. package/node_modules/@kardalum/api-schemas/dist/plugin-manifest-fields.d.ts +64 -0
  69. package/node_modules/@kardalum/api-schemas/dist/plugin-manifest-fields.js +134 -0
  70. package/node_modules/@kardalum/api-schemas/dist/plugin-registry-api.schema.d.ts +2 -0
  71. package/node_modules/@kardalum/api-schemas/dist/plugin-registry-api.schema.js +4 -0
  72. package/node_modules/@kardalum/api-schemas/dist/plugin-template-payload.d.ts +74 -0
  73. package/node_modules/@kardalum/api-schemas/dist/plugin-template-payload.js +132 -0
  74. package/node_modules/@kardalum/api-schemas/dist/plugin-vocabulary.d.ts +13 -0
  75. package/node_modules/@kardalum/api-schemas/dist/plugin-vocabulary.js +15 -0
  76. package/node_modules/@kardalum/api-schemas/dist/public-api.schema.js +12 -3
  77. package/node_modules/@kardalum/api-schemas/dist/role.schema.d.ts +11 -0
  78. package/node_modules/@kardalum/api-schemas/dist/role.schema.js +7 -0
  79. package/node_modules/@kardalum/api-schemas/dist/sample-content.schema.d.ts +11 -2
  80. package/node_modules/@kardalum/api-schemas/dist/sample-content.schema.js +21 -3
  81. package/node_modules/@kardalum/api-schemas/dist/sandbox-attach.schema.d.ts +126 -0
  82. package/node_modules/@kardalum/api-schemas/dist/sandbox-attach.schema.js +70 -0
  83. package/node_modules/@kardalum/api-schemas/dist/setup-api.schema.d.ts +6 -6
  84. package/node_modules/@kardalum/api-schemas/dist/sites.schema.d.ts +44 -25
  85. package/node_modules/@kardalum/api-schemas/dist/sites.schema.js +187 -48
  86. package/node_modules/@kardalum/api-schemas/dist/snapshot-api.schema.d.ts +15 -3
  87. package/node_modules/@kardalum/api-schemas/dist/snapshot-api.schema.js +14 -0
  88. package/node_modules/@kardalum/api-schemas/dist/snapshot.schema.d.ts +1 -1
  89. package/node_modules/@kardalum/api-schemas/dist/strict-url.d.ts +12 -0
  90. package/node_modules/@kardalum/api-schemas/dist/strict-url.js +31 -0
  91. package/node_modules/@kardalum/api-schemas/dist/template-api.schema.d.ts +105 -1
  92. package/node_modules/@kardalum/api-schemas/dist/template-api.schema.js +43 -3
  93. package/node_modules/@kardalum/api-schemas/dist/template.schema.d.ts +30 -2
  94. package/node_modules/@kardalum/api-schemas/dist/template.schema.js +19 -5
  95. package/node_modules/@kardalum/api-schemas/dist/trash-cursor.schema.d.ts +4 -0
  96. package/node_modules/@kardalum/api-schemas/dist/trash-cursor.schema.js +29 -0
  97. package/node_modules/@kardalum/api-schemas/dist/user-api.schema.d.ts +4 -0
  98. package/node_modules/@kardalum/api-schemas/dist/user-api.schema.js +3 -0
  99. package/node_modules/@kardalum/api-schemas/dist/whoami-api.schema.d.ts +19 -0
  100. package/node_modules/@kardalum/api-schemas/dist/whoami-api.schema.js +22 -0
  101. package/node_modules/@kardalum/api-schemas/package.json +2 -2
  102. package/node_modules/@kardalum/design-tokens/dist/tailwind-theme.d.ts +1 -0
  103. package/node_modules/@kardalum/design-tokens/dist/tailwind-theme.js +2 -0
  104. package/node_modules/@kardalum/design-tokens/dist/tokens.css +1 -0
  105. package/node_modules/@kardalum/design-tokens/dist/tokens.js +3 -0
  106. package/node_modules/@kardalum/design-tokens/dist/tokens.json +2 -1
  107. package/node_modules/@kardalum/design-tokens/dist/types.d.ts +1 -0
  108. package/node_modules/@kardalum/plugin-package/README.md +4 -1
  109. package/node_modules/@kardalum/plugin-package/dist/build-reference.d.ts +6 -21
  110. package/node_modules/@kardalum/plugin-package/dist/build-reference.js +13 -8
  111. package/node_modules/@kardalum/plugin-package/dist/capabilities.d.ts +4 -4
  112. package/node_modules/@kardalum/plugin-package/dist/capabilities.js +9 -14
  113. package/node_modules/@kardalum/plugin-package/dist/client-bundle.d.ts +4 -0
  114. package/node_modules/@kardalum/plugin-package/dist/client-bundle.js +25 -0
  115. package/node_modules/@kardalum/plugin-package/dist/delivery/archive-names.d.ts +25 -0
  116. package/node_modules/@kardalum/plugin-package/dist/delivery/archive-names.js +203 -0
  117. package/node_modules/@kardalum/plugin-package/dist/delivery/bundle.d.ts +3 -0
  118. package/node_modules/@kardalum/plugin-package/dist/delivery/bundle.js +73 -0
  119. package/node_modules/@kardalum/plugin-package/dist/delivery/contributions.d.ts +5 -0
  120. package/node_modules/@kardalum/plugin-package/dist/delivery/contributions.js +60 -0
  121. package/node_modules/@kardalum/plugin-package/dist/delivery/icon-names.generated.d.ts +1 -0
  122. package/node_modules/@kardalum/plugin-package/dist/delivery/icon-names.generated.js +2052 -0
  123. package/node_modules/@kardalum/plugin-package/dist/delivery/icons.d.ts +2 -0
  124. package/node_modules/@kardalum/plugin-package/dist/delivery/icons.js +51 -0
  125. package/node_modules/@kardalum/plugin-package/dist/delivery/index.d.ts +8 -0
  126. package/node_modules/@kardalum/plugin-package/dist/delivery/index.js +7 -0
  127. package/node_modules/@kardalum/plugin-package/dist/delivery/label-languages.d.ts +17 -0
  128. package/node_modules/@kardalum/plugin-package/dist/delivery/label-languages.js +119 -0
  129. package/node_modules/@kardalum/plugin-package/dist/delivery/limits.d.ts +14 -0
  130. package/node_modules/@kardalum/plugin-package/dist/delivery/limits.js +21 -0
  131. package/node_modules/@kardalum/plugin-package/dist/delivery/locales.d.ts +5 -0
  132. package/node_modules/@kardalum/plugin-package/dist/delivery/locales.js +148 -0
  133. package/node_modules/@kardalum/plugin-package/dist/delivery/package-files.d.ts +5 -0
  134. package/node_modules/@kardalum/plugin-package/dist/delivery/package-files.js +76 -0
  135. package/node_modules/@kardalum/plugin-package/dist/delivery/registry.d.ts +22 -0
  136. package/node_modules/@kardalum/plugin-package/dist/delivery/registry.js +133 -0
  137. package/node_modules/@kardalum/plugin-package/dist/delivery/sample-content.d.ts +3 -0
  138. package/node_modules/@kardalum/plugin-package/dist/delivery/sample-content.js +90 -0
  139. package/node_modules/@kardalum/plugin-package/dist/delivery/support.d.ts +24 -0
  140. package/node_modules/@kardalum/plugin-package/dist/delivery/support.js +55 -0
  141. package/node_modules/@kardalum/plugin-package/dist/delivery/templates.d.ts +6 -0
  142. package/node_modules/@kardalum/plugin-package/dist/delivery/templates.js +158 -0
  143. package/node_modules/@kardalum/plugin-package/dist/delivery/types.d.ts +53 -0
  144. package/node_modules/@kardalum/plugin-package/dist/delivery/types.js +1 -0
  145. package/node_modules/@kardalum/plugin-package/dist/docs-contract.d.ts +3 -2
  146. package/node_modules/@kardalum/plugin-package/dist/docs-contract.js +4 -2
  147. package/node_modules/@kardalum/plugin-package/dist/extract.d.ts +92 -3
  148. package/node_modules/@kardalum/plugin-package/dist/extract.js +251 -41
  149. package/node_modules/@kardalum/plugin-package/dist/index.d.ts +9 -2
  150. package/node_modules/@kardalum/plugin-package/dist/index.js +7 -2
  151. package/node_modules/@kardalum/plugin-package/dist/manifest-entry.d.ts +5 -0
  152. package/node_modules/@kardalum/plugin-package/dist/manifest-entry.js +20 -0
  153. package/node_modules/@kardalum/plugin-package/dist/reference-entry.d.ts +1 -0
  154. package/node_modules/@kardalum/plugin-package/dist/reference-entry.js +1 -0
  155. package/node_modules/@kardalum/plugin-package/dist/sample-content.d.ts +21 -3
  156. package/node_modules/@kardalum/plugin-package/dist/sample-content.js +37 -9
  157. package/node_modules/@kardalum/plugin-package/dist/shipped-files.d.ts +39 -0
  158. package/node_modules/@kardalum/plugin-package/dist/shipped-files.js +133 -0
  159. package/node_modules/@kardalum/plugin-package/dist/shipped-locales.d.ts +7 -0
  160. package/node_modules/@kardalum/plugin-package/dist/shipped-locales.js +27 -0
  161. package/node_modules/@kardalum/plugin-package/package.json +4 -2
  162. package/node_modules/@kardalum/ui/dist/components/dropdown-menu.js +2 -2
  163. package/node_modules/@kardalum/ui/package.json +1 -1
  164. package/package.json +6 -6
@@ -0,0 +1,64 @@
1
+ import { z } from "zod";
2
+ import { PLUGIN_ID_MAX } from "./plugin-id-rules.js";
3
+ import { type DeclarationIssue } from "./plugin-template-payload.js";
4
+ export { PLUGIN_ID_MAX };
5
+ /** The longest version a manifest may declare (S311 second code fix): short
6
+ * enough that every name a version becomes part of fits in FILE_NAME_MAX
7
+ * beside the longest id. The longest of them is the starter download's
8
+ * "<id>-<version>-starter.zip": 255 - 128 (PLUGIN_ID_MAX) - 1 ("-") - 12
9
+ * ("-starter.zip") = 114, room for ordinary build metadata such as
10
+ * "1.0.0+21AF26D3----117B344092BD". The others are shorter: "<id>-<version>.zip.sig" and
11
+ * "<id>-<version>.zip" (pack's archive and the downloads), and on disk the
12
+ * marketplace's "<version>-starter.zip", "<version>.tar.gz.sig" and
13
+ * "<version>.tar.gz" and the server's "<id>/<version>" folder. */
14
+ export declare const PLUGIN_VERSION_MAX: number;
15
+ /** The longest plugin name a listing shows. */
16
+ export declare const PLUGIN_NAME_MAX = 120;
17
+ /** The longest description a listing shows. */
18
+ export declare const PLUGIN_DESCRIPTION_MAX = 2000;
19
+ /** The longest author a listing shows. */
20
+ export declare const PLUGIN_AUTHOR_MAX = 200;
21
+ /** The longest licence text. */
22
+ export declare const PLUGIN_LICENSE_MAX = 100;
23
+ /** The longest CMS version range. */
24
+ export declare const PLUGIN_CMS_VERSION_MAX = 100;
25
+ export declare const PLUGIN_ID_MESSAGE = "must be a reverse-domain id like com.vendor.plugin: every segment is lowercase, starts with a letter, and uses only a-z, 0-9 and hyphens";
26
+ export declare const PLUGIN_ID_SEGMENTS_MESSAGE: string;
27
+ export declare const PLUGIN_VERSION_MESSAGE: string;
28
+ /** Whether `value` is a SemVer 2.0.0 version (MAJOR.MINOR.PATCH, an optional
29
+ * `-prerelease` and `+build`, no `v` prefix, no spaces) of at most
30
+ * PLUGIN_VERSION_MAX characters. The length is checked first, then the text
31
+ * is split at its first `+` and its first `-` and each part read on its own,
32
+ * so the work is linear in a length that is already bounded. */
33
+ export declare function isPluginVersion(value: string): boolean;
34
+ /** A manifest's own id: at most PLUGIN_ID_MAX characters, the reverse-domain
35
+ * rule, and at most MANIFEST_ID_SEGMENT_MAX segments. Also the rule for the
36
+ * ids of other plugins a manifest names (bundled plugins, dependencies),
37
+ * since each of those is some plugin's own id. */
38
+ export declare const PluginManifestIdSchema: z.ZodString;
39
+ export declare const PluginVersionSchema: z.ZodString;
40
+ export declare const PluginNameSchema: z.ZodString;
41
+ export declare const PluginDescriptionSchema: z.ZodString;
42
+ export declare const PluginAuthorSchema: z.ZodString;
43
+ export declare const PluginLicenseSchema: z.ZodString;
44
+ export declare const PluginCmsVersionSchema: z.ZodString;
45
+ /** The identity and listing fields of a manifest, as one shape: the SDK's
46
+ * manifest schema and the door's shape rule each spread it into theirs. */
47
+ export declare const pluginManifestFields: {
48
+ id: z.ZodString;
49
+ version: z.ZodString;
50
+ name: z.ZodString;
51
+ description: z.ZodString;
52
+ author: z.ZodString;
53
+ license: z.ZodString;
54
+ cmsVersion: z.ZodString;
55
+ };
56
+ /** The fields a listing row is written from, by the rules above, for the
57
+ * upload, which writes the row before validation reads the package: each
58
+ * field it refuses, with the rule's message. An absent author is left out
59
+ * (the listing names the publisher instead). */
60
+ export declare function checkPluginListingFields(fields: {
61
+ name: unknown;
62
+ description: unknown;
63
+ author?: unknown;
64
+ }): DeclarationIssue[];
@@ -0,0 +1,134 @@
1
+ import { z } from "zod";
2
+ import { ACTION_SEGMENT_MAX } from "./action.schema.js";
3
+ import { HOSTILE_CHARS_MESSAGE, hasHostileChars } from "./plugin-docs-text.js";
4
+ import { MANIFEST_ID_SEGMENT_MAX, PLUGIN_ID_MAX, PLUGIN_ID_REGEX } from "./plugin-id-rules.js";
5
+ import { FILE_NAME_MAX } from "./plugin-template-payload.js";
6
+ // S311 fix wave (I-A): the rules over a manifest's identity and listing fields,
7
+ // defined once. The SDK's manifest schema (`kardalum plugin validate` and every
8
+ // install) and the marketplace door's shape rule both build these fields from
9
+ // here, and the upload checks the listing fields by them before it writes a
10
+ // listing row, so a manifest `validate` accepts is never refused at the door
11
+ // for its id, version, name, description, author, licence or CMS range. Before
12
+ // this the caps and the semver rule lived in the door alone.
13
+ export { PLUGIN_ID_MAX };
14
+ /** The longest version a manifest may declare (S311 second code fix): short
15
+ * enough that every name a version becomes part of fits in FILE_NAME_MAX
16
+ * beside the longest id. The longest of them is the starter download's
17
+ * "<id>-<version>-starter.zip": 255 - 128 (PLUGIN_ID_MAX) - 1 ("-") - 12
18
+ * ("-starter.zip") = 114, room for ordinary build metadata such as
19
+ * "1.0.0+21AF26D3----117B344092BD". The others are shorter: "<id>-<version>.zip.sig" and
20
+ * "<id>-<version>.zip" (pack's archive and the downloads), and on disk the
21
+ * marketplace's "<version>-starter.zip", "<version>.tar.gz.sig" and
22
+ * "<version>.tar.gz" and the server's "<id>/<version>" folder. */
23
+ export const PLUGIN_VERSION_MAX = FILE_NAME_MAX - PLUGIN_ID_MAX - "-".length - "-starter.zip".length;
24
+ /** The longest plugin name a listing shows. */
25
+ export const PLUGIN_NAME_MAX = 120;
26
+ /** The longest description a listing shows. */
27
+ export const PLUGIN_DESCRIPTION_MAX = 2000;
28
+ /** The longest author a listing shows. */
29
+ export const PLUGIN_AUTHOR_MAX = 200;
30
+ /** The longest licence text. */
31
+ export const PLUGIN_LICENSE_MAX = 100;
32
+ /** The longest CMS version range. */
33
+ export const PLUGIN_CMS_VERSION_MAX = 100;
34
+ export const PLUGIN_ID_MESSAGE = "must be a reverse-domain id like com.vendor.plugin: every segment is lowercase, starts with a letter, and uses only a-z, 0-9 and hyphens";
35
+ export const PLUGIN_ID_SEGMENTS_MESSAGE = `a plugin id has at most ${MANIFEST_ID_SEGMENT_MAX} segments: every action is the plugin id plus an object ` +
36
+ `and a verb, and an action has at most ${ACTION_SEGMENT_MAX} segments, so a longer id could not declare any action`;
37
+ export const PLUGIN_VERSION_MESSAGE = `must be a semver version such as 1.0.0 or 1.0.0-beta.1, at most ${PLUGIN_VERSION_MAX} characters`;
38
+ const IDENTIFIER = /^[0-9A-Za-z-]+$/;
39
+ const NUMERIC = /^[0-9]+$/;
40
+ /** A core part: digits, no leading zero, within the largest safe integer, so
41
+ * every reader of the version (semver, the install's ordering) reads one number. */
42
+ function isCorePart(part) {
43
+ if (!NUMERIC.test(part) || (part.length > 1 && part.startsWith("0")))
44
+ return false;
45
+ return Number(part) <= Number.MAX_SAFE_INTEGER;
46
+ }
47
+ /** A prerelease identifier: letters, digits and hyphens, and a number with no leading zero. */
48
+ function isPrereleasePart(part) {
49
+ if (!IDENTIFIER.test(part))
50
+ return false;
51
+ return !(NUMERIC.test(part) && part.length > 1 && part.startsWith("0"));
52
+ }
53
+ /** A build identifier: letters, digits and hyphens (leading zeros allowed). */
54
+ function isBuildPart(part) {
55
+ return IDENTIFIER.test(part);
56
+ }
57
+ /** Whether `value` is a SemVer 2.0.0 version (MAJOR.MINOR.PATCH, an optional
58
+ * `-prerelease` and `+build`, no `v` prefix, no spaces) of at most
59
+ * PLUGIN_VERSION_MAX characters. The length is checked first, then the text
60
+ * is split at its first `+` and its first `-` and each part read on its own,
61
+ * so the work is linear in a length that is already bounded. */
62
+ export function isPluginVersion(value) {
63
+ if (value.length === 0 || value.length > PLUGIN_VERSION_MAX)
64
+ return false;
65
+ const plus = value.indexOf("+");
66
+ const main = plus === -1 ? value : value.slice(0, plus);
67
+ if (plus !== -1 && !value.slice(plus + 1).split(".").every(isBuildPart))
68
+ return false;
69
+ const dash = main.indexOf("-");
70
+ const core = dash === -1 ? main : main.slice(0, dash);
71
+ if (dash !== -1 && !main.slice(dash + 1).split(".").every(isPrereleasePart))
72
+ return false;
73
+ const parts = core.split(".");
74
+ return parts.length === 3 && parts.every(isCorePart);
75
+ }
76
+ /** A manifest's own id: at most PLUGIN_ID_MAX characters, the reverse-domain
77
+ * rule, and at most MANIFEST_ID_SEGMENT_MAX segments. Also the rule for the
78
+ * ids of other plugins a manifest names (bundled plugins, dependencies),
79
+ * since each of those is some plugin's own id. */
80
+ export const PluginManifestIdSchema = z
81
+ .string()
82
+ .max(PLUGIN_ID_MAX, { message: `is at most ${PLUGIN_ID_MAX} characters` })
83
+ .regex(PLUGIN_ID_REGEX, PLUGIN_ID_MESSAGE)
84
+ .refine((id) => id.split(".").length <= MANIFEST_ID_SEGMENT_MAX, { message: PLUGIN_ID_SEGMENTS_MESSAGE });
85
+ export const PluginVersionSchema = z.string().refine(isPluginVersion, { message: PLUGIN_VERSION_MESSAGE });
86
+ /** Text a listing shows as written: not empty, at most `max` characters, and
87
+ * no control, zero-width or direction-override character (Trojan Source). */
88
+ function listingText(max) {
89
+ return z
90
+ .string()
91
+ .min(1, { message: "must not be empty" })
92
+ .max(max, { message: `is at most ${max} characters` })
93
+ .refine((value) => !hasHostileChars(value), { message: HOSTILE_CHARS_MESSAGE });
94
+ }
95
+ function boundedText(max) {
96
+ return z.string().min(1, { message: "must not be empty" }).max(max, { message: `is at most ${max} characters` });
97
+ }
98
+ export const PluginNameSchema = listingText(PLUGIN_NAME_MAX);
99
+ export const PluginDescriptionSchema = listingText(PLUGIN_DESCRIPTION_MAX);
100
+ export const PluginAuthorSchema = listingText(PLUGIN_AUTHOR_MAX);
101
+ export const PluginLicenseSchema = boundedText(PLUGIN_LICENSE_MAX);
102
+ export const PluginCmsVersionSchema = boundedText(PLUGIN_CMS_VERSION_MAX);
103
+ /** The identity and listing fields of a manifest, as one shape: the SDK's
104
+ * manifest schema and the door's shape rule each spread it into theirs. */
105
+ export const pluginManifestFields = {
106
+ id: PluginManifestIdSchema,
107
+ version: PluginVersionSchema,
108
+ name: PluginNameSchema,
109
+ description: PluginDescriptionSchema,
110
+ author: PluginAuthorSchema,
111
+ license: PluginLicenseSchema,
112
+ cmsVersion: PluginCmsVersionSchema,
113
+ };
114
+ const LISTING_FIELDS = [
115
+ ["name", PluginNameSchema],
116
+ ["description", PluginDescriptionSchema],
117
+ ["author", PluginAuthorSchema],
118
+ ];
119
+ /** The fields a listing row is written from, by the rules above, for the
120
+ * upload, which writes the row before validation reads the package: each
121
+ * field it refuses, with the rule's message. An absent author is left out
122
+ * (the listing names the publisher instead). */
123
+ export function checkPluginListingFields(fields) {
124
+ const issues = [];
125
+ for (const [key, schema] of LISTING_FIELDS) {
126
+ const value = fields[key];
127
+ if (key === "author" && value === undefined)
128
+ continue;
129
+ const parsed = schema.safeParse(value);
130
+ if (!parsed.success)
131
+ issues.push({ path: [key], message: parsed.error.issues[0]?.message ?? "is invalid" });
132
+ }
133
+ return issues;
134
+ }
@@ -8,6 +8,7 @@ export declare const PluginSchema: z.ZodObject<{
8
8
  storageType: z.ZodString;
9
9
  enabled: z.ZodBoolean;
10
10
  remoteUrl: z.ZodNullable<z.ZodString>;
11
+ locales: z.ZodNullable<z.ZodArray<z.ZodString>>;
11
12
  }, z.core.$strip>;
12
13
  export type Plugin = z.infer<typeof PluginSchema>;
13
14
  export declare const PluginListQuerySchema: z.ZodObject<{
@@ -25,6 +26,7 @@ export declare const PluginListResponseSchema: z.ZodObject<{
25
26
  storageType: z.ZodString;
26
27
  enabled: z.ZodBoolean;
27
28
  remoteUrl: z.ZodNullable<z.ZodString>;
29
+ locales: z.ZodNullable<z.ZodArray<z.ZodString>>;
28
30
  }, z.core.$strip>>;
29
31
  nextCursor: z.ZodNullable<z.ZodString>;
30
32
  }, z.core.$strip>;
@@ -12,6 +12,10 @@ export const PluginSchema = z.object({
12
12
  storageType: z.string(),
13
13
  enabled: z.boolean(),
14
14
  remoteUrl: z.string().nullable(),
15
+ // S314c2 (D9): the language codes of the locale files (locales/<code>.json) the plugin's
16
+ // package ships, read at install, update and attach; null when the row records none. The
17
+ // admin asks only for these files.
18
+ locales: z.array(z.string()).max(100).nullable(),
15
19
  });
16
20
  // Cursor-paginated per the non-negotiable list-endpoint rule, mirroring
17
21
  // DataTypeListResponseSchema's exact shape (data-type-api.schema.ts).
@@ -0,0 +1,74 @@
1
+ import { z } from "zod";
2
+ /** The longest path an entry of a package archive may have: Windows' MAX_PATH.
3
+ * A longer path cannot be written on a Windows host, wherever the package
4
+ * installs, since the install's own folder only adds to it. The entry gate
5
+ * in @kardalum/plugin-package (ENTRY_NAME_MAX) reads it from here (S311). */
6
+ export declare const PACKAGE_PATH_MAX = 260;
7
+ /** The longest file or folder name, one segment of a path, that NTFS, APFS and
8
+ * ext4 take. */
9
+ export declare const FILE_NAME_MAX = 255;
10
+ export declare const TEMPLATE_ALIAS_MAX = 120;
11
+ /** A template file lands at templates/<file>, so it may take PACKAGE_PATH_MAX
12
+ * less that folder (S311 third code fix): a longer one is named here, by the
13
+ * declarations check, not later by the archive's name rule. */
14
+ export declare const TEMPLATE_FILE_MAX: number;
15
+ /** A registered asset lands at public/<path>: PACKAGE_PATH_MAX less that folder. */
16
+ export declare const ASSET_PATH_MAX: number;
17
+ /** Templates and public/ together: the budget the install pipeline copes with. */
18
+ export declare const MAX_TEMPLATE_PAYLOAD_ENTRIES = 1800;
19
+ /** First path segments the request pipeline owns (compared case-insensitively):
20
+ * the server's reserved root slugs, the one list (S311 fix wave), so a root
21
+ * the server adds, such as the edit-on-page route's, is refused here too. */
22
+ export declare const RESERVED_ASSET_ROOTS: readonly ["kardalum", "api", "docs", "plugin-assets", "media", "kardalum-edit"];
23
+ /** A registered asset is read as UTF-8 text and kept with version history; a
24
+ * binary would be mangled. Binaries ship as unregistered public/ files. */
25
+ export declare const REGISTERED_ASSET_TEXT_EXTENSIONS: readonly ["css", "js", "mjs", "json", "svg", "txt", "md"];
26
+ export declare function hasRegisteredAssetTextExtension(value: string): boolean;
27
+ export declare const PluginTemplateAliasSchema: z.ZodString;
28
+ export declare const PluginTemplateFileSchema: z.ZodString;
29
+ export declare const PluginAssetPathSchema: z.ZodString;
30
+ export declare const PluginTemplateEntrySchema: z.ZodObject<{
31
+ file: z.ZodString;
32
+ name: z.ZodString;
33
+ alias: z.ZodString;
34
+ kind: z.ZodEnum<{
35
+ page: "page";
36
+ layout: "layout";
37
+ partial: "partial";
38
+ }>;
39
+ documentType: z.ZodOptional<z.ZodString>;
40
+ }, z.core.$strict>;
41
+ export type PluginTemplateEntry = z.infer<typeof PluginTemplateEntrySchema>;
42
+ /** The two fields an install re-reads, whatever else the contributions hold. */
43
+ export declare const PluginTemplatePayloadSchema: z.ZodObject<{
44
+ templates: z.ZodOptional<z.ZodArray<z.ZodObject<{
45
+ file: z.ZodString;
46
+ name: z.ZodString;
47
+ alias: z.ZodString;
48
+ kind: z.ZodEnum<{
49
+ page: "page";
50
+ layout: "layout";
51
+ partial: "partial";
52
+ }>;
53
+ documentType: z.ZodOptional<z.ZodString>;
54
+ }, z.core.$strict>>>;
55
+ assets: z.ZodOptional<z.ZodArray<z.ZodString>>;
56
+ }, z.core.$loose>;
57
+ export interface DeclarationIssue {
58
+ path: (string | number)[];
59
+ message: string;
60
+ }
61
+ /** The cross-entry rules: unique aliases, files and asset paths, and a page
62
+ * template's documentType resolving against this manifest's own documentTypes. */
63
+ export declare function checkTemplateAndAssetDeclarations(value: {
64
+ templates?: ReadonlyArray<{
65
+ file: string;
66
+ alias: string;
67
+ kind: string;
68
+ documentType?: string;
69
+ }>;
70
+ assets?: ReadonlyArray<string>;
71
+ documentTypes?: ReadonlyArray<{
72
+ name: string;
73
+ }>;
74
+ }): DeclarationIssue[];
@@ -0,0 +1,132 @@
1
+ import { z } from "zod";
2
+ import { TEMPLATE_KINDS } from "./plugin-vocabulary.js";
3
+ import { RESERVED_ROOT_SLUGS, isReservedRootSlug } from "./reserved-slugs.js";
4
+ // S311 (S292): the rules for the two manifest fields an install lands as render
5
+ // templates and registered assets, defined once. The SDK's manifest schema
6
+ // (kardalum plugin validate), the delivery registry (validate and the
7
+ // marketplace door) and the server's install (install-template-payload.ts) all
8
+ // import from here; before S311 each held its own copy, three of them
9
+ // "byte-for-byte mirrors" kept in lockstep by a comment. Narrower than the
10
+ // server's general AssetPathSchema on purpose: a declared asset is a text file
11
+ // the admin edits, and may not repeat the public/ root.
12
+ /** The longest path an entry of a package archive may have: Windows' MAX_PATH.
13
+ * A longer path cannot be written on a Windows host, wherever the package
14
+ * installs, since the install's own folder only adds to it. The entry gate
15
+ * in @kardalum/plugin-package (ENTRY_NAME_MAX) reads it from here (S311). */
16
+ export const PACKAGE_PATH_MAX = 260;
17
+ /** The longest file or folder name, one segment of a path, that NTFS, APFS and
18
+ * ext4 take. */
19
+ export const FILE_NAME_MAX = 255;
20
+ export const TEMPLATE_ALIAS_MAX = 120;
21
+ /** A template file lands at templates/<file>, so it may take PACKAGE_PATH_MAX
22
+ * less that folder (S311 third code fix): a longer one is named here, by the
23
+ * declarations check, not later by the archive's name rule. */
24
+ export const TEMPLATE_FILE_MAX = PACKAGE_PATH_MAX - "templates/".length;
25
+ /** A registered asset lands at public/<path>: PACKAGE_PATH_MAX less that folder. */
26
+ export const ASSET_PATH_MAX = PACKAGE_PATH_MAX - "public/".length;
27
+ /** Templates and public/ together: the budget the install pipeline copes with. */
28
+ export const MAX_TEMPLATE_PAYLOAD_ENTRIES = 1800;
29
+ /** First path segments the request pipeline owns (compared case-insensitively):
30
+ * the server's reserved root slugs, the one list (S311 fix wave), so a root
31
+ * the server adds, such as the edit-on-page route's, is refused here too. */
32
+ export const RESERVED_ASSET_ROOTS = RESERVED_ROOT_SLUGS;
33
+ /** A registered asset is read as UTF-8 text and kept with version history; a
34
+ * binary would be mangled. Binaries ship as unregistered public/ files. */
35
+ export const REGISTERED_ASSET_TEXT_EXTENSIONS = ["css", "js", "mjs", "json", "svg", "txt", "md"];
36
+ const TEMPLATE_ALIAS_REGEX = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
37
+ // Starts alphanumeric, then alphanumeric, dot, dash, underscore: this alone
38
+ // rejects "." and ".." segments, so no separate traversal check is needed.
39
+ const PATH_SEGMENT_REGEX = /^[a-z0-9][a-z0-9._-]*$/i;
40
+ const isRelativeSlashPath = (value) => value.length > 0 && !value.startsWith("/") && !value.includes("\\");
41
+ const hasValidSegments = (value) => value.split("/").every((segment) => PATH_SEGMENT_REGEX.test(segment));
42
+ export function hasRegisteredAssetTextExtension(value) {
43
+ const base = value.split("/").pop() ?? value;
44
+ const dot = base.lastIndexOf(".");
45
+ if (dot <= 0)
46
+ return false;
47
+ const extension = base.slice(dot + 1).toLowerCase();
48
+ return REGISTERED_ASSET_TEXT_EXTENSIONS.includes(extension);
49
+ }
50
+ export const PluginTemplateAliasSchema = z
51
+ .string()
52
+ .min(1)
53
+ .max(TEMPLATE_ALIAS_MAX)
54
+ .regex(TEMPLATE_ALIAS_REGEX, "must be lowercase kebab-case, e.g. product-page");
55
+ export const PluginTemplateFileSchema = z
56
+ .string()
57
+ .min(1)
58
+ .max(TEMPLATE_FILE_MAX)
59
+ .refine(isRelativeSlashPath, { message: 'must be a relative path using forward slashes (no leading "/", no "\\\\")' })
60
+ .refine((value) => value.toLowerCase().endsWith(".liquid"), { message: "must end with .liquid" })
61
+ .refine(hasValidSegments, { message: 'path segments must match [a-z0-9][a-z0-9._-]*: no "." or ".." segments' });
62
+ export const PluginAssetPathSchema = z
63
+ .string()
64
+ .min(1)
65
+ .max(ASSET_PATH_MAX)
66
+ .refine(isRelativeSlashPath, { message: 'must be a relative path using forward slashes (no leading "/", no "\\\\")' })
67
+ .refine(hasValidSegments, { message: 'path segments must match [a-z0-9][a-z0-9._-]*: no "." or ".." segments' })
68
+ .refine((value) => !isReservedRootSlug(value.split("/")[0] ?? ""), {
69
+ message: `must not be rooted at a reserved path (${[...RESERVED_ASSET_ROOTS].sort().join(", ")})`,
70
+ })
71
+ .refine((value) => (value.split("/")[0]?.toLowerCase() ?? "") !== "public", {
72
+ message: 'declare asset paths relative to public/: drop the "public/" prefix',
73
+ })
74
+ .refine(hasRegisteredAssetTextExtension, {
75
+ message: "registered assets are text files editable in the admin: ship binary files as unregistered public/ files instead",
76
+ });
77
+ export const PluginTemplateEntrySchema = z
78
+ .object({
79
+ file: PluginTemplateFileSchema,
80
+ name: z.string().min(1),
81
+ alias: PluginTemplateAliasSchema,
82
+ kind: z.enum(TEMPLATE_KINDS),
83
+ documentType: z.string().min(1).optional(),
84
+ })
85
+ .strict();
86
+ /** The two fields an install re-reads, whatever else the contributions hold. */
87
+ export const PluginTemplatePayloadSchema = z
88
+ .object({
89
+ templates: z.array(PluginTemplateEntrySchema).optional(),
90
+ assets: z.array(PluginAssetPathSchema).optional(),
91
+ })
92
+ .passthrough();
93
+ /** The cross-entry rules: unique aliases, files and asset paths, and a page
94
+ * template's documentType resolving against this manifest's own documentTypes. */
95
+ export function checkTemplateAndAssetDeclarations(value) {
96
+ const issues = [];
97
+ const documentTypeNames = new Set((value.documentTypes ?? []).map((documentType) => documentType.name));
98
+ const seenAliases = new Set();
99
+ const seenFiles = new Set();
100
+ (value.templates ?? []).forEach((template, index) => {
101
+ if (seenAliases.has(template.alias)) {
102
+ issues.push({ path: ["templates", index, "alias"], message: `Duplicate template alias "${template.alias}": aliases must be unique within a manifest` });
103
+ }
104
+ seenAliases.add(template.alias);
105
+ if (seenFiles.has(template.file)) {
106
+ issues.push({ path: ["templates", index, "file"], message: `Duplicate template file "${template.file}": files must be unique within a manifest` });
107
+ }
108
+ seenFiles.add(template.file);
109
+ if (template.kind === "page") {
110
+ if (template.documentType !== undefined && !documentTypeNames.has(template.documentType)) {
111
+ issues.push({
112
+ path: ["templates", index, "documentType"],
113
+ message: `documentType "${template.documentType}" does not match any name in this manifest's documentTypes contribution`,
114
+ });
115
+ }
116
+ }
117
+ else if (template.documentType !== undefined) {
118
+ issues.push({
119
+ path: ["templates", index, "documentType"],
120
+ message: `documentType is only allowed on "page" kind templates, not "${template.kind}"`,
121
+ });
122
+ }
123
+ });
124
+ const seenAssets = new Set();
125
+ (value.assets ?? []).forEach((asset, index) => {
126
+ if (seenAssets.has(asset)) {
127
+ issues.push({ path: ["assets", index], message: `Duplicate asset path "${asset}": asset paths must be unique within a manifest` });
128
+ }
129
+ seenAssets.add(asset);
130
+ });
131
+ return issues;
132
+ }
@@ -0,0 +1,13 @@
1
+ /** The listing labels. A label files and filters a listing; it gates nothing. */
2
+ export declare const PLUGIN_TYPES: readonly ["datatype", "section", "template", "theme", "integration", "utility", "bundle"];
3
+ /** Every dialect the SDK's manifest schema accepts, for a plugin that runs on a developer's own machine. */
4
+ export declare const DATABASE_DIALECTS: readonly ["postgresql", "mysql", "sqlite", "mssql", "mongodb"];
5
+ /** The dialects a listed plugin may claim: Tier 1, the ones the conformance suite covers. */
6
+ export declare const TIER1_DIALECTS: readonly ["postgresql", "mysql", "sqlite"];
7
+ export declare const STORAGE_TYPES: readonly ["simple", "structured"];
8
+ /** Which credential reaches an apiRoute handler. */
9
+ export declare const API_ROUTE_ACCESS_TIERS: readonly ["admin", "apiKey", "public"];
10
+ export declare const TEMPLATE_KINDS: readonly ["page", "layout", "partial"];
11
+ export type PluginTypeValue = (typeof PLUGIN_TYPES)[number];
12
+ export type DatabaseDialectValue = (typeof DATABASE_DIALECTS)[number];
13
+ export type Tier1Dialect = (typeof TIER1_DIALECTS)[number];
@@ -0,0 +1,15 @@
1
+ // S311: the closed lists a plugin manifest is written in, defined once. The
2
+ // marketplace may import api-schemas and may not import the SDK's runtime (the
3
+ // deployed Next app must not pull TipTap or CodeMirror), so the lists live here
4
+ // and the SDK re-exports them. Each constant has a `Same<>` check against its
5
+ // contract type in packages/plugin-sdk/src/manifest-schema.ts.
6
+ /** The listing labels. A label files and filters a listing; it gates nothing. */
7
+ export const PLUGIN_TYPES = ["datatype", "section", "template", "theme", "integration", "utility", "bundle"];
8
+ /** Every dialect the SDK's manifest schema accepts, for a plugin that runs on a developer's own machine. */
9
+ export const DATABASE_DIALECTS = ["postgresql", "mysql", "sqlite", "mssql", "mongodb"];
10
+ /** The dialects a listed plugin may claim: Tier 1, the ones the conformance suite covers. */
11
+ export const TIER1_DIALECTS = ["postgresql", "mysql", "sqlite"];
12
+ export const STORAGE_TYPES = ["simple", "structured"];
13
+ /** Which credential reaches an apiRoute handler. */
14
+ export const API_ROUTE_ACCESS_TIERS = ["admin", "apiKey", "public"];
15
+ export const TEMPLATE_KINDS = ["page", "layout", "partial"];
@@ -56,11 +56,20 @@ export const PublicContentByPathQuerySchema = PublicContentItemQuerySchema.exten
56
56
  // types: a path, on a host. `path` is read as the renderer reads a
57
57
  // request's path, so a language prefix in it selects the language unless
58
58
  // `locale` says otherwise. `host` selects the site and nothing else: it is
59
- // compared with the domains stored on sites and never written into an
60
- // answer. Without it the address is read on the default address.
59
+ // read through `parseSiteDomain` (S314i), so it is a host name or an IPv4
60
+ // address with an optional port, a port selects a site whose domain was
61
+ // stored with that port, and a scheme in front is ignored. It is compared
62
+ // with the domains stored on sites and never written into an answer.
63
+ // Without it the address is read on the default address. Its cap leaves
64
+ // room for a scheme and a port beside the longest host name, as the
65
+ // manage lookup's does.
61
66
  export const PublicContentByAddressQuerySchema = z.object({
62
67
  path: z.string().min(1).max(2048),
63
- host: z.string().max(253).optional(),
68
+ host: z
69
+ .string()
70
+ .max(300)
71
+ .optional()
72
+ .describe("The host the address is on: a host name or an IPv4 address with an optional port, as a browser sends it in its Host header. A port selects a site whose domain was stored with that port; a scheme in front is ignored. Without it the address is read on the default address."),
64
73
  locale: z.string().optional(),
65
74
  });
66
75
  // The page a visitor gets at that address. `redirected` is true when the
@@ -94,3 +94,14 @@ export declare const RoleParamsSchema: z.ZodObject<{
94
94
  id: z.ZodString;
95
95
  }, z.core.$strip>;
96
96
  export type RoleParams = z.infer<typeof RoleParamsSchema>;
97
+ export declare const RoleEscalationRefusalSchema: z.ZodObject<{
98
+ message: z.ZodString;
99
+ action: z.ZodString;
100
+ }, z.core.$strip>;
101
+ export type RoleEscalationRefusal = z.infer<typeof RoleEscalationRefusalSchema>;
102
+ export declare const RoleForbiddenSchema: z.ZodUnion<readonly [z.ZodObject<{
103
+ message: z.ZodString;
104
+ action: z.ZodString;
105
+ }, z.core.$strip>, z.ZodObject<{
106
+ message: z.ZodString;
107
+ }, z.core.$strip>]>;
@@ -1,5 +1,6 @@
1
1
  import { z } from "zod";
2
2
  import { ActionStringSchema } from "./action.schema.js";
3
+ import { ApiErrorSchema } from "./api-error.schema.js";
3
4
  // S272, theme G2: roles are rows. This file is the one definition the
4
5
  // server, the admin UI and the setup wizard share for what a role id looks
5
6
  // like and which two roles are seeded, so none of them can drift.
@@ -73,3 +74,9 @@ export const RoleResponseSchema = z.object({ role: RoleSchema });
73
74
  export const DeleteRoleResponseSchema = z.object({ deleted: z.literal(true) });
74
75
  // S301: the params of PATCH and DELETE /roles/:id, moved here from the route file.
75
76
  export const RoleParamsSchema = z.object({ id: RoleIdSchema });
77
+ // S309: a role never holds an action its maker does not hold. The 403 names the action twice, in the
78
+ // sentence and as a field the admin can mark a row by. The refusal is listed first so a body with
79
+ // `action` is the one serialised (a plain error object would strip it), the order ApiKeyCreateForbiddenSchema uses for
80
+ // the key subset rule this mirrors. POST /users and PATCH /users/:id/role answer it too, for a role holding an action the caller lacks.
81
+ export const RoleEscalationRefusalSchema = z.object({ message: z.string(), action: ActionStringSchema });
82
+ export const RoleForbiddenSchema = z.union([RoleEscalationRefusalSchema, ApiErrorSchema]);
@@ -1,12 +1,21 @@
1
1
  import { z } from "zod";
2
2
  /** media[].file: "media/" plus a flat, traversal-free file name. Without it,
3
3
  * a file of "../../.env" would resolve outside the package and be uploaded
4
- * as a public media record. One character class, no nesting. */
4
+ * as a public media record. One character class, no nesting, and a
5
+ * fixed-length lookahead that refuses the names "." and ".." (S311 fix wave),
6
+ * which the class admits and which name media/ itself and the package root. */
5
7
  export declare const SAMPLE_CONTENT_MEDIA_FILE_PATTERN: RegExp;
8
+ /** The most nodes, and media entries, a sample-content.json may declare (S311).
9
+ * parseSampleContentFile refuses a count past either before the schema reads a
10
+ * single entry, so a small file of empty nodes cannot cost one issue per field
11
+ * per node; the schema holds the same limits for any other caller. Generous for
12
+ * a sample: the first-party samples hold a handful of each. */
13
+ export declare const SAMPLE_CONTENT_MAX_NODES = 1000;
14
+ export declare const SAMPLE_CONTENT_MAX_MEDIA = 200;
6
15
  export declare const SampleContentFileSchema: z.ZodObject<{
7
16
  description: z.ZodOptional<z.ZodPreprocess<z.ZodObject<{
8
17
  en: z.ZodString;
9
- }, z.core.$catchall<z.ZodString>>>>;
18
+ }, z.core.$catchall<z.ZodString>>, unknown>>;
10
19
  nodes: z.ZodArray<z.ZodObject<{
11
20
  documentType: z.ZodString;
12
21
  slug: z.ZodString;
@@ -10,11 +10,22 @@ import { InstallDescriptionSchema } from "./plugin-install.js";
10
10
  // interface shows with the "add the sample content" question.
11
11
  /** media[].file: "media/" plus a flat, traversal-free file name. Without it,
12
12
  * a file of "../../.env" would resolve outside the package and be uploaded
13
- * as a public media record. One character class, no nesting. */
14
- export const SAMPLE_CONTENT_MEDIA_FILE_PATTERN = /^media\/[A-Za-z0-9._-]+$/;
13
+ * as a public media record. One character class, no nesting, and a
14
+ * fixed-length lookahead that refuses the names "." and ".." (S311 fix wave),
15
+ * which the class admits and which name media/ itself and the package root. */
16
+ export const SAMPLE_CONTENT_MEDIA_FILE_PATTERN = /^media\/(?!\.\.?$)[A-Za-z0-9._-]+$/;
15
17
  /** media[].key: exactly what the seeder's {{media:key}} tokens can match. */
16
18
  const SAMPLE_CONTENT_MEDIA_KEY_PATTERN = /^[A-Za-z0-9_-]+$/;
19
+ /** The most nodes, and media entries, a sample-content.json may declare (S311).
20
+ * parseSampleContentFile refuses a count past either before the schema reads a
21
+ * single entry, so a small file of empty nodes cannot cost one issue per field
22
+ * per node; the schema holds the same limits for any other caller. Generous for
23
+ * a sample: the first-party samples hold a handful of each. */
24
+ export const SAMPLE_CONTENT_MAX_NODES = 1000;
25
+ export const SAMPLE_CONTENT_MAX_MEDIA = 200;
17
26
  const NON_EMPTY = "must be a non-empty string";
27
+ const NODES_RULE = `must hold at most ${SAMPLE_CONTENT_MAX_NODES} nodes`;
28
+ const MEDIA_RULE = `must hold at most ${SAMPLE_CONTENT_MAX_MEDIA} entries`;
18
29
  const ROOT_RULE = "sample-content.json must be a JSON object";
19
30
  const MEDIA_KEY_RULE = 'must be letters, digits, "_" or "-"';
20
31
  const MEDIA_FILE_RULE = 'must be "media/" followed by a file name of letters, digits, ".", "_" or "-"';
@@ -39,7 +50,7 @@ const SampleContentNodeSchema = z
39
50
  export const SampleContentFileSchema = z
40
51
  .object({
41
52
  description: InstallDescriptionSchema.optional(),
42
- nodes: z.array(SampleContentNodeSchema, { error: "must be an array" }),
53
+ nodes: z.array(SampleContentNodeSchema, { error: "must be an array" }).max(SAMPLE_CONTENT_MAX_NODES, { message: NODES_RULE }),
43
54
  // S199: files inside the package that the install uploads into the
44
55
  // media library, referenced from node data as {{media:key}} (the id)
45
56
  // or {{media:key:url}} (the url). Not strict, as the seeder's never
@@ -50,6 +61,7 @@ export const SampleContentFileSchema = z
50
61
  file: z.string({ error: MEDIA_FILE_RULE }).regex(SAMPLE_CONTENT_MEDIA_FILE_PATTERN, { message: MEDIA_FILE_RULE }),
51
62
  mimeType: z.string({ error: NON_EMPTY }).min(1, { message: NON_EMPTY }),
52
63
  }, { error: mustBeAnObject }), { error: "must be an array" })
64
+ .max(SAMPLE_CONTENT_MAX_MEDIA, { message: MEDIA_RULE })
53
65
  .optional(),
54
66
  })
55
67
  .strict();
@@ -72,6 +84,12 @@ function pathText(path) {
72
84
  export function parseSampleContentFile(raw) {
73
85
  if (typeof raw !== "object" || raw === null || Array.isArray(raw))
74
86
  return { ok: false, errors: [ROOT_RULE] };
87
+ // The counts first, in the schema's own words: past a limit, nothing else is read.
88
+ const { nodes, media } = raw;
89
+ if (Array.isArray(nodes) && nodes.length > SAMPLE_CONTENT_MAX_NODES)
90
+ return { ok: false, errors: [`nodes: ${NODES_RULE}`] };
91
+ if (Array.isArray(media) && media.length > SAMPLE_CONTENT_MAX_MEDIA)
92
+ return { ok: false, errors: [`media: ${MEDIA_RULE}`] };
75
93
  const result = SampleContentFileSchema.safeParse(raw);
76
94
  if (result.success)
77
95
  return { ok: true, file: result.data };