@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
@@ -1,14 +1,92 @@
1
1
  import { createWriteStream, mkdirSync } from "node:fs";
2
2
  import { dirname, resolve as resolvePath, sep } from "node:path";
3
3
  import * as yauzl from "yauzl";
4
+ import { FILE_NAME_MAX, PACKAGE_PATH_MAX } from "@kardalum/api-schemas";
4
5
  export const MAX_TOTAL_BYTES = 100 * 1024 * 1024;
5
6
  export const MAX_ENTRY_BYTES = 50 * 1024 * 1024;
6
7
  export const MAX_ENTRIES = 2000;
7
8
  const ALLOWED_ENTRY_TYPES = new Set(["File", "OldFile", "ContiguousFile", "Directory"]);
9
+ /** How much of a name a message quotes: an entry name may be 64 KiB, and a
10
+ * refusal reaches an upload's response and a stored report. */
11
+ const NAME_SHOWN = 120;
12
+ /** An entry name as a message quotes it: JSON-escaped, so a control character
13
+ * or a quote cannot break the line, and cut after NAME_SHOWN characters. */
14
+ export function quoteEntryName(name) {
15
+ return JSON.stringify(name.length > NAME_SHOWN ? `${name.slice(0, NAME_SHOWN)}...` : name);
16
+ }
17
+ /** The longest name a package may hold: Windows' MAX_PATH, api-schemas'
18
+ * PACKAGE_PATH_MAX, which the template file and asset path caps are drawn
19
+ * from. A path longer than that cannot be written on a Windows host, wherever
20
+ * the package installs, since the install's own folder only adds to it (S311
21
+ * second code fix). */
22
+ export const ENTRY_NAME_MAX = PACKAGE_PATH_MAX;
23
+ /** The most segments, folders and a file, one name may have. */
24
+ export const ENTRY_SEGMENTS_MAX = 32;
25
+ /** The names Windows keeps for devices, which no Windows folder can hold as a
26
+ * file or a folder, in any case and with any extension ("nul.txt" and
27
+ * "NUL.tar.gz" are the device too). */
28
+ const WINDOWS_DEVICE_NAME = /^(?:con|prn|aux|nul|com[1-9]|lpt[1-9])(?:\.|$)/i;
29
+ /** Why a name cannot be extracted the same way on every host, or null.
30
+ * The door extracts on Linux, a site may install on Windows or macOS, and a
31
+ * name that is one file on the first can be another file, or the same file
32
+ * as its neighbour, on the second (S311 second fix wave): an NTFS stream
33
+ * ("plugin.js::$DATA" writes plugin.js), an 8.3 short name ("PLUGIN~1.JS"),
34
+ * a trailing dot or space Windows drops, a backslash Windows reads as a
35
+ * separator, and any non-ASCII character a filesystem folds or normalizes
36
+ * ("\u0131", "\u017F", NFD on APFS). Every package path rule (manifest
37
+ * ids, docs, locales, media, templates, assets) is ASCII already, so a
38
+ * package holds only names that read one way everywhere. Since the S311
39
+ * second code fix it also refuses what a Windows host cannot write at all: a
40
+ * name longer than ENTRY_NAME_MAX or deeper than ENTRY_SEGMENTS_MAX, a
41
+ * segment longer than FILE_NAME_MAX (the third code fix), the characters
42
+ * < > " | ? * and the device names. The length and the depth come
43
+ * first, before any pattern reads the name, and they bound every reader that
44
+ * admits it: createPathKeyGate's tree, the folders extraction implies and the
45
+ * marketplace's walks of what it extracted. */
46
+ function nameViolation(path) {
47
+ if (path.length > ENTRY_NAME_MAX)
48
+ return `a name longer than ${ENTRY_NAME_MAX} characters, which Windows cannot write (MAX_PATH)`;
49
+ // A directory entry ends in "/", so its last segment is empty and is not counted.
50
+ let segments = path.endsWith("/") ? 0 : 1;
51
+ for (let i = 0; i < path.length; i++)
52
+ if (path[i] === "/")
53
+ segments++;
54
+ if (segments > ENTRY_SEGMENTS_MAX)
55
+ return `more than ${ENTRY_SEGMENTS_MAX} segments, folders and a file, in one path`;
56
+ if (/[\u0000-\u001f\u007f]/.test(path))
57
+ return "a control character in a name";
58
+ if (/[^\u0020-\u007e]/.test(path))
59
+ return "a character that is not ASCII: every package path is ASCII";
60
+ if (path.startsWith("/"))
61
+ return "an absolute path";
62
+ if (path.includes("\\"))
63
+ return "a backslash, which Windows reads as a separator";
64
+ if (path.includes(":"))
65
+ return "a colon, which names a drive or a stream on Windows";
66
+ if (/[<>"|?*]/.test(path))
67
+ return 'a character Windows refuses in a name: <, >, ", |, ? or *';
68
+ for (const segment of path.split("/")) {
69
+ if (segment.length > FILE_NAME_MAX)
70
+ return `a segment longer than ${FILE_NAME_MAX} characters, longer than a file or folder name may be`;
71
+ if (segment === "..")
72
+ return 'a ".." segment';
73
+ if (segment.endsWith(".") || segment.endsWith(" "))
74
+ return 'a segment that ends in "." or a space, which Windows drops';
75
+ if (/~[0-9]/.test(segment))
76
+ return '"~" and a digit, the shape of a Windows short name';
77
+ if (WINDOWS_DEVICE_NAME.test(segment)) {
78
+ return "a Windows device name (CON, PRN, AUX, NUL, COM1 to COM9 or LPT1 to LPT9, with or without an extension), which no Windows folder can hold";
79
+ }
80
+ }
81
+ return null;
82
+ }
8
83
  /** Pure gate over one entry's (path, type, declaredSize). Returns the
9
84
  * violation message or null. Exported for direct unit testing — a
10
85
  * well-formed writer can't produce hostile names, but attackers hand-craft
11
- * archives directly.
86
+ * archives directly. The path rules are nameViolation's: what a Linux
87
+ * extraction and a Windows or macOS one would read as different files is
88
+ * refused, so every reader of a package (both of the marketplace's, the
89
+ * install's, the watermark's re-pack) admits the same names.
12
90
  *
13
91
  * "OldFile" and "ContiguousFile" are accepted alongside "File" for
14
92
  * historical (tar-era) compatibility with entries this gate has always
@@ -18,24 +96,170 @@ const ALLOWED_ENTRY_TYPES = new Set(["File", "OldFile", "ContiguousFile", "Direc
18
96
  * behavior and would only risk breaking direct callers of this exported
19
97
  * function. */
20
98
  export function entryViolation(path, type, size) {
21
- if (path.startsWith("/") ||
22
- path.startsWith("\\") ||
23
- /^[a-zA-Z]:/.test(path) ||
24
- path.split(/[\\/]/).includes("..")) {
25
- return `unsafe entry path "${path}"`;
26
- }
99
+ const unsafe = nameViolation(path);
100
+ if (unsafe)
101
+ return `unsafe entry path ${quoteEntryName(path)}: ${unsafe}`;
27
102
  if (!ALLOWED_ENTRY_TYPES.has(type)) {
28
- return `unsafe entry type "${type}" for "${path}": only files and directories are allowed`;
103
+ return `unsafe entry type ${JSON.stringify(type)} for ${quoteEntryName(path)}: only files and directories are allowed`;
29
104
  }
30
105
  if (size > MAX_ENTRY_BYTES) {
31
- return `entry "${path}" exceeds the per-file size limit`;
106
+ return `entry ${quoteEntryName(path)} exceeds the per-file size limit`;
107
+ }
108
+ return null;
109
+ }
110
+ /** The key two entry names are compared by: the path's segments, split on "/"
111
+ * and backslash (a Windows extraction reads both as a separator), with empty
112
+ * and "." segments dropped and case folded (a case-insensitive filesystem
113
+ * writes "A.txt" and "a.txt" to one file). Two names with one key land on one
114
+ * path, so "manifest.json", "./manifest.json", ".//manifest.json" and the same
115
+ * name behind a backslash are one name. entryViolation refuses the "." and
116
+ * backslash spellings on their own now; the key still folds case and empty
117
+ * segments. Linear in the name's length. */
118
+ export function normalizeEntryName(name) {
119
+ return name
120
+ .split(/[\\/]/)
121
+ .filter((segment) => segment !== "" && segment !== ".")
122
+ .join("/")
123
+ .toLowerCase();
124
+ }
125
+ /** The Info-ZIP Unicode Path extra field: a second name for an entry, in UTF-8,
126
+ * which yauzl's own decoding prefers to the header's name when its CRC matches. */
127
+ const UNICODE_PATH_FIELD = 0x7075;
128
+ /** The one name every reader of a package gives an entry (S311): the header's
129
+ * raw bytes, decoded as UTF-8 when the entry's flag (0x800) says so and as
130
+ * latin1 otherwise. ASCII, the only bytes entryViolation's checks look at,
131
+ * decodes the same either way. An entry that names itself a second time, in an
132
+ * Info-ZIP Unicode Path field, is refused: a reader that honours the field (yauzl
133
+ * with decodeStrings) and one that does not would read different files. Open the
134
+ * archive with `decodeStrings: false`, so yauzl neither prefers the field nor
135
+ * turns a backslash into a slash. */
136
+ export function decodeEntryName(entry) {
137
+ const isUtf8 = (entry.generalPurposeBitFlag & 0x800) !== 0;
138
+ const name = entry.fileNameRaw.toString(isUtf8 ? "utf8" : "latin1");
139
+ if (entry.extraFields.some((field) => field.id === UNICODE_PATH_FIELD)) {
140
+ return { ok: false, reason: `entry ${quoteEntryName(name)} carries a second name (an Info-ZIP Unicode Path field): an archive names each entry once` };
141
+ }
142
+ return { ok: true, name };
143
+ }
144
+ const newPathNode = () => ({ children: null, file: null, folder: null, folderEntry: false });
145
+ const ONE_KIND = "a path is a file or a folder, not both (paths compare without case)";
146
+ /** The rule for the paths of one archive (S311 fix wave): each path once, by
147
+ * normalizeEntryName's key, and each path one kind, never a file where another
148
+ * entry needs a folder ("a" beside "a/b", or "public/Logo" beside
149
+ * "public/logo/x.png", which a case-insensitive host cannot write). Returns
150
+ * the reason a name is refused, or null once it is admitted. A folder entry
151
+ * for a folder the files under it already imply is admitted, in either order.
152
+ * The paths are held as a tree of segments, so a name costs time linear in its
153
+ * length. Every caller hands it a name entryViolation admitted, at most
154
+ * ENTRY_NAME_MAX characters in at most ENTRY_SEGMENTS_MAX segments, so an
155
+ * archive of MAX_ENTRIES entries holds at most that many nodes per entry
156
+ * (the S311 second code fix: an uncapped name could make one archive hold
157
+ * gigabytes). createEntryGate applies it to every reader of a package, and the
158
+ * `archive names` check and `kardalum plugin pack` apply it before an archive
159
+ * exists. */
160
+ export function createPathKeyGate() {
161
+ const root = newPathNode();
162
+ return (name, isDirectory) => {
163
+ const key = normalizeEntryName(name);
164
+ if (key === "")
165
+ return `entry ${quoteEntryName(name)} names no path`;
166
+ const segments = key.split("/");
167
+ let node = root;
168
+ for (let i = 0; i < segments.length - 1; i++) {
169
+ const segment = segments[i];
170
+ node.children ??= new Map();
171
+ let child = node.children.get(segment);
172
+ if (child === undefined) {
173
+ child = newPathNode();
174
+ child.folder = name;
175
+ node.children.set(segment, child);
176
+ }
177
+ else if (child.file !== null) {
178
+ return `entry ${quoteEntryName(name)} sits under ${quoteEntryName(child.file)}, which the archive holds as a file: ${ONE_KIND}`;
179
+ }
180
+ node = child;
181
+ }
182
+ const last = segments[segments.length - 1];
183
+ node.children ??= new Map();
184
+ const existing = node.children.get(last);
185
+ if (existing === undefined) {
186
+ const created = newPathNode();
187
+ if (isDirectory) {
188
+ created.folder = name;
189
+ created.folderEntry = true;
190
+ }
191
+ else {
192
+ created.file = name;
193
+ }
194
+ node.children.set(last, created);
195
+ return null;
196
+ }
197
+ // S311 (S292): a second entry under a name already admitted would overwrite
198
+ // the first on disk, so the file a reader of the archive's first copy checked
199
+ // (the door's manifest read) is not the one that lands.
200
+ if (existing.file !== null || existing.folderEntry)
201
+ return `repeated entry name ${quoteEntryName(name)}: an archive holds each path once`;
202
+ if (!isDirectory)
203
+ return `entry ${quoteEntryName(name)} is a file where ${quoteEntryName(existing.folder ?? name)} needs a folder: ${ONE_KIND}`;
204
+ existing.folderEntry = true;
205
+ return null;
206
+ };
207
+ }
208
+ /** The rules every reader of a package applies to its entries, in central
209
+ * directory order (S311): at most MAX_ENTRIES entries, each name decoded by
210
+ * decodeEntryName and passing entryViolation (which holds MAX_ENTRY_BYTES), each
211
+ * path once and of one kind by createPathKeyGate, and MAX_TOTAL_BYTES declared
212
+ * in all. One gate per archive: it counts what it has admitted. extractArtifact
213
+ * and the marketplace's manifest reader both read through it, so the door's
214
+ * reader refuses exactly what extraction refuses, before a listing exists. */
215
+ export function createEntryGate() {
216
+ let entries = 0;
217
+ let totalBytes = 0;
218
+ const admitPath = createPathKeyGate();
219
+ return (entry) => {
220
+ entries += 1;
221
+ if (entries > MAX_ENTRIES)
222
+ return { ok: false, reason: `archive has more than ${MAX_ENTRIES} entries` };
223
+ const decoded = decodeEntryName(entry);
224
+ if (!decoded.ok)
225
+ return decoded;
226
+ const name = decoded.name;
227
+ const isDirectory = name.endsWith("/");
228
+ const violation = entryViolation(name, isDirectory ? "Directory" : "File", entry.uncompressedSize);
229
+ if (violation)
230
+ return { ok: false, reason: violation };
231
+ const pathRefusal = admitPath(name, isDirectory);
232
+ if (pathRefusal)
233
+ return { ok: false, reason: pathRefusal };
234
+ totalBytes += entry.uncompressedSize;
235
+ if (totalBytes > MAX_TOTAL_BYTES)
236
+ return { ok: false, reason: `archive expands beyond the ${MAX_TOTAL_BYTES / 1024 / 1024} MB limit` };
237
+ return { ok: true, name, isDirectory };
238
+ };
239
+ }
240
+ /** What createEntryGate would refuse first in `entries`, in order, or null:
241
+ * the rule extraction and the marketplace read an archive by, applied by a
242
+ * packer before it writes one (S311 fix wave), so `kardalum plugin pack` never
243
+ * writes an archive the marketplace or an install would refuse for a name,
244
+ * the entry count or a size. */
245
+ export function plannedEntryRefusal(entries) {
246
+ const admit = createEntryGate();
247
+ for (const entry of entries) {
248
+ const name = entry.isDirectory ? `${entry.name}/` : entry.name;
249
+ const admitted = admit({ fileNameRaw: Buffer.from(name, "utf8"), generalPurposeBitFlag: 0x800, extraFields: [], uncompressedSize: entry.size });
250
+ if (!admitted.ok)
251
+ return admitted.reason;
32
252
  }
33
253
  return null;
34
254
  }
35
255
  /**
36
256
  * Extracts a single ZIP archive into `targetDir`, admitting only entries
37
- * that pass `entryViolation`'s allow-list and the MAX_ENTRIES/
38
- * MAX_TOTAL_BYTES ceilings below. Never throws — every failure mode
257
+ * that pass createEntryGate: `entryViolation`'s allow-list, the MAX_ENTRIES
258
+ * and MAX_TOTAL_BYTES ceilings, one name per entry (no Info-ZIP Unicode Path
259
+ * field) and each path once by `normalizeEntryName`'s segment key (S311). The
260
+ * marketplace's manifest reader reads through the same gate and the same
261
+ * decoder, so the manifest.json it parsed is the one file that lands at
262
+ * manifest.json; the door also compares the two by hash. Never throws: every failure mode
39
263
  * resolves `{ ok: false, reason }`, so a hostile or broken package
40
264
  * degrades with a clear reason at install time instead of an uncaught
41
265
  * rejection bricking (or 500-ing) the host.
@@ -73,8 +297,10 @@ export function extractArtifact(archivePath, targetDir) {
73
297
  // an 'entry' event, and rejects by emitting 'error' on the whole
74
298
  // zipfile with its own message text. That would make yauzl's built-in
75
299
  // check the real gate for hostile names, not entryViolation. Decoding
76
- // fileNameRaw ourselves below keeps entryViolation authoritative, as
77
- // required — one gate, not two.
300
+ // fileNameRaw ourselves (createEntryGate, through decodeEntryName) keeps
301
+ // entryViolation authoritative, as required: one gate, not two. It also
302
+ // keeps yauzl from preferring an Info-ZIP Unicode Path field to the
303
+ // header's name, which the gate refuses instead.
78
304
  yauzl.open(archivePath, { lazyEntries: true, decodeStrings: false }, (openErr, zipfile) => {
79
305
  if (openErr || !zipfile) {
80
306
  settle({ ok: false, reason: "not a valid .zip archive" });
@@ -94,8 +320,7 @@ export function extractArtifact(archivePath, targetDir) {
94
320
  settle({ ok: false, reason: `archive has more than ${MAX_ENTRIES} entries` });
95
321
  return;
96
322
  }
97
- let entryCount = 0;
98
- let totalBytes = 0;
323
+ const admit = createEntryGate();
99
324
  const fail = (reason) => {
100
325
  zipfile.close();
101
326
  settle({ ok: false, reason });
@@ -104,33 +329,18 @@ export function extractArtifact(archivePath, targetDir) {
104
329
  zipfile.on("entry", (entry) => {
105
330
  if (settled)
106
331
  return;
107
- entryCount += 1;
108
- if (entryCount > MAX_ENTRIES) {
109
- fail(`archive has more than ${MAX_ENTRIES} entries`);
110
- return;
111
- }
112
- // fileNameRaw is always populated regardless of decodeStrings; the
113
- // UTF-8 general-purpose bit (0x800) tells us how to interpret it.
114
- // ASCII bytes (the only ones that matter to entryViolation's own
115
- // checks) decode identically under utf8 or latin1, so a plain
116
- // fallback for non-UTF-8 archives is fine here — full CP437
117
- // fidelity only affects display of non-ASCII names, never safety.
118
- const isUtf8 = (entry.generalPurposeBitFlag & 0x800) !== 0;
119
- const fileName = entry.fileNameRaw.toString(isUtf8 ? "utf8" : "latin1");
120
- const isDirectory = fileName.endsWith("/");
121
- const type = isDirectory ? "Directory" : "File";
122
- const violation = entryViolation(fileName, type, entry.uncompressedSize);
123
- if (violation) {
124
- fail(violation);
125
- return;
126
- }
127
- totalBytes += entry.uncompressedSize;
128
- if (totalBytes > MAX_TOTAL_BYTES) {
129
- fail(`archive expands beyond the ${MAX_TOTAL_BYTES / 1024 / 1024} MB limit`);
332
+ // The gate decodes fileNameRaw itself (the archive is opened with
333
+ // decodeStrings: false), so entryViolation stays the one judge of a
334
+ // hostile name and yauzl never swaps in an Info-ZIP Unicode Path field
335
+ // or turns a backslash into a slash behind it.
336
+ const admitted = admit(entry);
337
+ if (!admitted.ok) {
338
+ fail(admitted.reason);
130
339
  return;
131
340
  }
132
- // This is an assertion, not a second gate: entryViolation above
133
- // already rejects a leading "/" or "\\", a drive letter, and any
341
+ const { name: fileName, isDirectory } = admitted;
342
+ // This is an assertion, not a second gate: entryViolation (inside the
343
+ // gate) already rejects a leading "/" or "\\", a drive letter, and any
134
344
  // ".." segment, so resolving fileName against targetDir can never
135
345
  // land outside it — this branch must be unreachable. It stays
136
346
  // because it is a two-line check against the one failure mode
@@ -139,7 +349,7 @@ export function extractArtifact(archivePath, targetDir) {
139
349
  // regression in entryViolation would cost.
140
350
  const destPath = resolvePath(targetDir, fileName);
141
351
  if (destPath !== resolvedTargetDir && !destPath.startsWith(resolvedTargetDir + sep)) {
142
- fail(`unsafe entry path "${fileName}"`);
352
+ fail(`unsafe entry path ${quoteEntryName(fileName)}`);
143
353
  return;
144
354
  }
145
355
  // The filesystem calls below can throw — most concretely EEXIST
@@ -4,10 +4,17 @@ export { canonicalizeEnvelope, deriveKeyId, generateSigningKeyPair, signEnvelope
4
4
  export type { LicenseChallenge, LicenseVerdictEnvelope, LicenseVerdictResult, LicenseVerdictSignatureResult, SignedLicenseVerdict, TamperKind, } from "./license-verdict.js";
5
5
  export { canonicalizeLicenseVerdict, createLicenseChallenge, ENTITLEMENT_MAX_AGE_MS, hashLicenseKey, LICENSE_VERDICT_DETAIL_MAX, MAX_VERDICT_AGE_MS, signLicenseVerdict, verifyLicenseVerdict, verifyLicenseVerdictSignature, } from "./license-verdict.js";
6
6
  export { hashBuffer, hashArchive, hashDirectories } from "./hash.js";
7
- export { entryViolation, extractArtifact, MAX_ENTRIES, MAX_ENTRY_BYTES, MAX_TOTAL_BYTES } from "./extract.js";
8
- export { SAMPLE_CONTENT_MAX_BYTES, readShippedInstallFacts, readShippedSampleContent } from "./sample-content.js";
7
+ export type { AdmittedEntry, PlannedEntry } from "./extract.js";
8
+ export { createEntryGate, createPathKeyGate, decodeEntryName, ENTRY_NAME_MAX, ENTRY_SEGMENTS_MAX, entryViolation, extractArtifact, MAX_ENTRIES, MAX_ENTRY_BYTES, MAX_TOTAL_BYTES, normalizeEntryName, plannedEntryRefusal, } from "./extract.js";
9
+ export type { ShippedEntry } from "./shipped-files.js";
10
+ export { EXCLUDED_NAMES, createShippedLookup, isExcludedSegment, walkShipped, whyNotShipped } from "./shipped-files.js";
11
+ export { SAMPLE_CONTENT_MAX_BYTES, hasSampleContentConsumer, installFactsOf, readShippedInstallFacts, readShippedSampleContent } from "./sample-content.js";
9
12
  export type { ShippedSampleContent } from "./sample-content.js";
13
+ export { MAX_SHIPPED_LOCALES, readShippedLocales } from "./shipped-locales.js";
10
14
  export type { PackageContractCheck } from "./package-contract.js";
11
15
  export { checkCoverContract, checkPackageContract, checkReadmeContract, COVER_HEIGHT, COVER_PATH, COVER_WIDTH, pngSize, } from "./package-contract.js";
12
16
  export type { DocsContractInput } from "./docs-contract.js";
13
17
  export { capViolations, checkDocsContract, countRemoteImages, docsFilesToShip, MAX_PACKAGE_JSON_BYTES, MAX_VIOLATIONS, packageFilePath, readDocsContractInput } from "./docs-contract.js";
18
+ export { VIEW_BEARING_CONTRIBUTIONS, declaresClientBundle } from "./client-bundle.js";
19
+ export { resolvePluginManifestEntry } from "./manifest-entry.js";
20
+ export * from "./delivery/index.js";
@@ -2,7 +2,12 @@ export { VERIFY_FAILURE_REASONS } from "./types.js";
2
2
  export { canonicalizeEnvelope, deriveKeyId, generateSigningKeyPair, signEnvelope, verifyEnvelope, } from "./envelope.js";
3
3
  export { canonicalizeLicenseVerdict, createLicenseChallenge, ENTITLEMENT_MAX_AGE_MS, hashLicenseKey, LICENSE_VERDICT_DETAIL_MAX, MAX_VERDICT_AGE_MS, signLicenseVerdict, verifyLicenseVerdict, verifyLicenseVerdictSignature, } from "./license-verdict.js";
4
4
  export { hashBuffer, hashArchive, hashDirectories } from "./hash.js";
5
- export { entryViolation, extractArtifact, MAX_ENTRIES, MAX_ENTRY_BYTES, MAX_TOTAL_BYTES } from "./extract.js";
6
- export { SAMPLE_CONTENT_MAX_BYTES, readShippedInstallFacts, readShippedSampleContent } from "./sample-content.js";
5
+ export { createEntryGate, createPathKeyGate, decodeEntryName, ENTRY_NAME_MAX, ENTRY_SEGMENTS_MAX, entryViolation, extractArtifact, MAX_ENTRIES, MAX_ENTRY_BYTES, MAX_TOTAL_BYTES, normalizeEntryName, plannedEntryRefusal, } from "./extract.js";
6
+ export { EXCLUDED_NAMES, createShippedLookup, isExcludedSegment, walkShipped, whyNotShipped } from "./shipped-files.js";
7
+ export { SAMPLE_CONTENT_MAX_BYTES, hasSampleContentConsumer, installFactsOf, readShippedInstallFacts, readShippedSampleContent } from "./sample-content.js";
8
+ export { MAX_SHIPPED_LOCALES, readShippedLocales } from "./shipped-locales.js";
7
9
  export { checkCoverContract, checkPackageContract, checkReadmeContract, COVER_HEIGHT, COVER_PATH, COVER_WIDTH, pngSize, } from "./package-contract.js";
8
10
  export { capViolations, checkDocsContract, countRemoteImages, docsFilesToShip, MAX_PACKAGE_JSON_BYTES, MAX_VIOLATIONS, packageFilePath, readDocsContractInput } from "./docs-contract.js";
11
+ export { VIEW_BEARING_CONTRIBUTIONS, declaresClientBundle } from "./client-bundle.js";
12
+ export { resolvePluginManifestEntry } from "./manifest-entry.js";
13
+ export * from "./delivery/index.js";
@@ -0,0 +1,5 @@
1
+ /** S314c2 (D11): the one rule for a plugin project's manifest entry, shared by the server's
2
+ * sandbox (resolveManifestPath) and the CLI (resolveManifestEntry): src/plugin.tsx, else
3
+ * src/plugin.ts. The scaffolds write src/plugin.tsx and name it in their vite.config.ts, so
4
+ * .tsx wins when both exist, and `warn` is told that the other file is not read. */
5
+ export declare function resolvePluginManifestEntry(pluginDir: string, warn?: (message: string) => void): string;
@@ -0,0 +1,20 @@
1
+ import { existsSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ /** S314c2 (D11): the one rule for a plugin project's manifest entry, shared by the server's
4
+ * sandbox (resolveManifestPath) and the CLI (resolveManifestEntry): src/plugin.tsx, else
5
+ * src/plugin.ts. The scaffolds write src/plugin.tsx and name it in their vite.config.ts, so
6
+ * .tsx wins when both exist, and `warn` is told that the other file is not read. */
7
+ export function resolvePluginManifestEntry(pluginDir, warn = (message) => console.warn(message)) {
8
+ const tsx = join(pluginDir, "src", "plugin.tsx");
9
+ const ts = join(pluginDir, "src", "plugin.ts");
10
+ const hasTsx = existsSync(tsx);
11
+ const hasTs = existsSync(ts);
12
+ if (hasTsx && hasTs) {
13
+ warn(`Both src/plugin.tsx and src/plugin.ts exist in ${pluginDir}: src/plugin.tsx is the plugin's entry and src/plugin.ts is not read. Remove one of them.`);
14
+ }
15
+ if (hasTsx)
16
+ return tsx;
17
+ if (hasTs)
18
+ return ts;
19
+ throw new Error(`No plugin entry found in ${pluginDir}: expected src/plugin.tsx or src/plugin.ts`);
20
+ }
@@ -1,2 +1,3 @@
1
1
  export * from "./capabilities.js";
2
2
  export * from "./build-reference.js";
3
+ export * from "./client-bundle.js";
@@ -4,3 +4,4 @@
4
4
  // reference-entry.test.ts holds that line.
5
5
  export * from "./capabilities.js";
6
6
  export * from "./build-reference.js";
7
+ export * from "./client-bundle.js";
@@ -1,20 +1,38 @@
1
1
  import { type SampleContentFile, type ShippedInstallFacts } from "@kardalum/api-schemas";
2
2
  /** The largest sample-content.json read to decide whether the sample ships,
3
- * so the door's parse stays inside its validation budget. */
3
+ * so the door's parse stays inside its validation budget. 2 MiB since the S311
4
+ * fix wave (it was 8): the largest first-party sample is about 5 KB, and at 8
5
+ * MiB a file the node count then refused still cost a door seconds of parsing. */
4
6
  export declare const SAMPLE_CONTENT_MAX_BYTES: number;
5
- /** S293: the package's sample-content.json as an install reads it. */
7
+ /** S293: the package's sample-content.json as an install reads it. A file the
8
+ * schema refuses carries every issue in `details` (S311); its `reason` names
9
+ * the first few, since it is logged at install and shown at the door. */
6
10
  export type ShippedSampleContent = {
7
11
  status: "absent";
8
12
  } | {
9
13
  status: "unreadable";
10
14
  reason: string;
15
+ details?: string[];
11
16
  } | {
12
17
  status: "ships";
13
18
  file: SampleContentFile;
14
19
  };
15
20
  /** Absent, unreadable (not a regular file, over SAMPLE_CONTENT_MAX_BYTES, not
16
21
  * JSON, or refused by the schema) or the parsed file. Never throws. The
17
- * server's seeder reads through it, so the cap applies at install too. */
22
+ * server's seeder reads through it, so the cap applies at install too, and
23
+ * both gates' sample checks read the file through it once per run (S311). No
24
+ * word of the file itself reaches a reason: "not valid JSON" says enough, and
25
+ * the parser's own message quotes the text. */
18
26
  export declare function readShippedSampleContent(dir: string): ShippedSampleContent;
27
+ /** What a read ships for the install interface: anything unreadable ships nothing. */
28
+ export declare function installFactsOf(sample: ShippedSampleContent): ShippedInstallFacts;
19
29
  /** Never throws: anything unreadable ships nothing. */
20
30
  export declare function readShippedInstallFacts(dir: string): ShippedInstallFacts;
31
+ /** S311 (D5): whether a sample-content.json can be consumed at all: it is the
32
+ * seed tree keyed to the plugin's own documentTypes, and it also ships with a
33
+ * starter a plugin bundles. Reads plain data, so it answers the same for a live
34
+ * manifest and the manifest.json the door parses. The CLI's build and pack
35
+ * steps and both gates call this one function. */
36
+ export declare function hasSampleContentConsumer(manifest: {
37
+ contributions?: unknown;
38
+ }): boolean;
@@ -1,6 +1,7 @@
1
1
  import { lstatSync, readFileSync } from "node:fs";
2
2
  import { join } from "node:path";
3
3
  import { parseSampleContentFile } from "@kardalum/api-schemas";
4
+ import { listCapped } from "./delivery/support.js";
4
5
  // S292 (2026-10-13-s292-what-the-wizard-may-ask-design.md, D8): what a
5
6
  // package directory ships that its install's built-in questions are derived
6
7
  // from. One definition for `kardalum plugin validate`'s `install options`
@@ -17,11 +18,16 @@ import { parseSampleContentFile } from "@kardalum/api-schemas";
17
18
  // too, so the seeder parses only what the cap admits and a present but
18
19
  // unreadable file is told apart from an absent one.
19
20
  /** The largest sample-content.json read to decide whether the sample ships,
20
- * so the door's parse stays inside its validation budget. */
21
- export const SAMPLE_CONTENT_MAX_BYTES = 8 * 1024 * 1024;
21
+ * so the door's parse stays inside its validation budget. 2 MiB since the S311
22
+ * fix wave (it was 8): the largest first-party sample is about 5 KB, and at 8
23
+ * MiB a file the node count then refused still cost a door seconds of parsing. */
24
+ export const SAMPLE_CONTENT_MAX_BYTES = 2 * 1024 * 1024;
22
25
  /** Absent, unreadable (not a regular file, over SAMPLE_CONTENT_MAX_BYTES, not
23
26
  * JSON, or refused by the schema) or the parsed file. Never throws. The
24
- * server's seeder reads through it, so the cap applies at install too. */
27
+ * server's seeder reads through it, so the cap applies at install too, and
28
+ * both gates' sample checks read the file through it once per run (S311). No
29
+ * word of the file itself reaches a reason: "not valid JSON" says enough, and
30
+ * the parser's own message quotes the text. */
25
31
  export function readShippedSampleContent(dir) {
26
32
  const path = join(dir, "sample-content.json");
27
33
  let size;
@@ -36,8 +42,12 @@ export function readShippedSampleContent(dir) {
36
42
  ? { status: "absent" }
37
43
  : { status: "unreadable", reason: "sample-content.json cannot be read" };
38
44
  }
39
- if (size > SAMPLE_CONTENT_MAX_BYTES)
40
- return { status: "unreadable", reason: `sample-content.json is larger than ${SAMPLE_CONTENT_MAX_BYTES} bytes` };
45
+ if (size > SAMPLE_CONTENT_MAX_BYTES) {
46
+ return {
47
+ status: "unreadable",
48
+ reason: `sample-content.json is ${size} bytes, over the limit of ${SAMPLE_CONTENT_MAX_BYTES} bytes (${SAMPLE_CONTENT_MAX_BYTES / 1024 / 1024} MiB)`,
49
+ };
50
+ }
41
51
  let raw;
42
52
  try {
43
53
  raw = JSON.parse(readFileSync(path, "utf8"));
@@ -46,12 +56,30 @@ export function readShippedSampleContent(dir) {
46
56
  return { status: "unreadable", reason: "sample-content.json is not valid JSON" };
47
57
  }
48
58
  const parsed = parseSampleContentFile(raw);
49
- return parsed.ok ? { status: "ships", file: parsed.file } : { status: "unreadable", reason: `sample-content.json: ${parsed.errors.join("; ")}` };
59
+ if (parsed.ok)
60
+ return { status: "ships", file: parsed.file };
61
+ return { status: "unreadable", reason: `sample-content.json: ${listCapped(parsed.errors)}`, details: parsed.errors };
50
62
  }
51
- /** Never throws: anything unreadable ships nothing. */
52
- export function readShippedInstallFacts(dir) {
53
- const sample = readShippedSampleContent(dir);
63
+ /** What a read ships for the install interface: anything unreadable ships nothing. */
64
+ export function installFactsOf(sample) {
54
65
  if (sample.status !== "ships")
55
66
  return { sampleContent: false };
56
67
  return sample.file.description ? { sampleContent: true, sampleContentDescription: sample.file.description } : { sampleContent: true };
57
68
  }
69
+ /** Never throws: anything unreadable ships nothing. */
70
+ export function readShippedInstallFacts(dir) {
71
+ return installFactsOf(readShippedSampleContent(dir));
72
+ }
73
+ /** S311 (D5): whether a sample-content.json can be consumed at all: it is the
74
+ * seed tree keyed to the plugin's own documentTypes, and it also ships with a
75
+ * starter a plugin bundles. Reads plain data, so it answers the same for a live
76
+ * manifest and the manifest.json the door parses. The CLI's build and pack
77
+ * steps and both gates call this one function. */
78
+ export function hasSampleContentConsumer(manifest) {
79
+ const contributions = manifest.contributions;
80
+ if (contributions === null || typeof contributions !== "object")
81
+ return false;
82
+ const declared = contributions;
83
+ const hasTypes = Array.isArray(declared.documentTypes) && declared.documentTypes.length > 0;
84
+ return hasTypes || (declared.bundledTemplate !== undefined && declared.bundledTemplate !== null);
85
+ }
@@ -0,0 +1,39 @@
1
+ /** Names a package never carries, at any depth, a folder with everything under
2
+ * it: vendored and build folders, and env files (they can hold live secrets),
3
+ * `.env.example` excepted (placeholder values a reader copies). A bare file
4
+ * of one of these names is left out too. */
5
+ export declare const EXCLUDED_NAMES: readonly string[];
6
+ export declare function isExcludedSegment(segment: string): boolean;
7
+ export interface ShippedEntry {
8
+ /** Relative to the walked folder, with "/". */
9
+ path: string;
10
+ isDirectory: boolean;
11
+ /** A folder with nothing that ships inside it, which the build still
12
+ * creates; always false for a file. */
13
+ empty: boolean;
14
+ }
15
+ /** Every file and folder under `folder` that ships, parents before children,
16
+ * each folder's entries in name order. A link is never followed and never
17
+ * listed, a left-out name is skipped with everything under it, and a folder
18
+ * that is absent, a file or a link ships nothing. Iterative, so a deep tree
19
+ * costs no stack. */
20
+ export declare function walkShipped(folder: string): ShippedEntry[];
21
+ /** Why a file is not one the build carries into the package, for any number
22
+ * of paths under one package root, each folder read once (S311 second code
23
+ * fix). A path is relative to `root`, with "/"; the answer is null for a
24
+ * regular file reached through real folders only, none of them a left-out
25
+ * name, or the reason, which reads after the path: "public/dist/theme.css is
26
+ * inside public/dist/, which ...".
27
+ *
28
+ * The first segment is the folder the build opens by its own name
29
+ * (templates, public or media), which a case-insensitive host resolves in any
30
+ * case, as the build's copy does, and writes into the package under that
31
+ * name. Every segment below it must be spelled as its folder lists it: the
32
+ * build copies the names it reads, so on Windows or macOS a declared
33
+ * `Styles/Site.css` the file system would find as `styles/site.css` is not in
34
+ * the package under the declared name, and the marketplace (and any Linux
35
+ * install) reads names exactly. */
36
+ export declare function createShippedLookup(root: string): (path: string) => string | null;
37
+ /** createShippedLookup's answer for one path. A caller with many paths under
38
+ * one root makes one lookup and asks it each. */
39
+ export declare function whyNotShipped(root: string, path: string): string | null;