@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,3 @@
1
+ import type { DeliveryCheck } from "./types.js";
2
+ export declare const sampleContentCheck: DeliveryCheck;
3
+ export declare const installOptionsCheck: DeliveryCheck;
@@ -0,0 +1,90 @@
1
+ import { installInterfaceFor, installOptionNeedsAnswer } from "@kardalum/api-schemas";
2
+ import { SAMPLE_CONTENT_MAX_BYTES, hasSampleContentConsumer, installFactsOf, readShippedSampleContent } from "../sample-content.js";
3
+ import { createShippedLookup } from "../shipped-files.js";
4
+ import { formatBinarySize } from "./limits.js";
5
+ import { contributionsOf, failed, list, listCapped, passed, plural, record } from "./support.js";
6
+ const declaredTypeNames = (manifest) => new Set(list(contributionsOf(manifest).documentTypes).map((entry) => record(entry)?.name).filter((name) => typeof name === "string"));
7
+ /** The run's one read of sample-content.json: the gate's, or this check's own
8
+ * when it runs outside a gate. */
9
+ function sampleOf({ dir, sampleContent }) {
10
+ return sampleContent ?? readShippedSampleContent(dir);
11
+ }
12
+ /** sample-content.json is optional: absent is a passing no-op. When present it
13
+ * must be a regular file within SAMPLE_CONTENT_MAX_BYTES (the limit the install
14
+ * reads by, checked before the file is read), parse under the one schema in
15
+ * @kardalum/api-schemas, which refuses a node or media count past its limits
16
+ * before reading an entry, name only document types this manifest declares
17
+ * (the seeder's cross-check, done here so an author catches it first), and
18
+ * every declared media file must be one the build carries into media/
19
+ * (whyNotShipped, S311 fix wave: not a left-out name, not behind a link). The
20
+ * read is readShippedSampleContent, the install's own; a schema refusal lists
21
+ * every issue in its details. */
22
+ function checkSampleContent(sample, dir, manifest) {
23
+ if (sample.status === "absent")
24
+ return passed("no sample-content.json: nothing to validate");
25
+ if (sample.status === "unreadable") {
26
+ return sample.details ? failed(`sample-content.json failed validation (${plural(sample.details.length, "issue")})`, sample.details) : failed(sample.reason);
27
+ }
28
+ const { nodes } = sample.file;
29
+ const media = sample.file.media ?? [];
30
+ const known = declaredTypeNames(manifest);
31
+ const unknown = [...new Set(nodes.map((node) => node.documentType))].filter((name) => !known.has(name));
32
+ if (unknown.length > 0) {
33
+ return failed(`sample-content.json references documentType(s) not in this manifest's documentTypes: ${listCapped(unknown, "names")}`);
34
+ }
35
+ const problems = [];
36
+ const whyNotShipped = createShippedLookup(dir);
37
+ for (const entry of media) {
38
+ const why = whyNotShipped(entry.file);
39
+ if (why !== null)
40
+ problems.push(why === "does not exist" ? `${entry.file}: does not exist at ${entry.file}` : `${entry.file}: ${why}`);
41
+ }
42
+ if (problems.length > 0) {
43
+ return failed(`sample-content.json declares ${plural(problems.length, "media file")} the package does not carry`, problems);
44
+ }
45
+ return passed(media.length > 0
46
+ ? `${plural(nodes.length, "sample content node")} valid, ${plural(media.length, "media file")} present`
47
+ : `${plural(nodes.length, "sample content node")} valid`);
48
+ }
49
+ export const sampleContentCheck = {
50
+ name: "sample content valid",
51
+ rule: `\`sample-content.json\` is a regular file within ${formatBinarySize(SAMPLE_CONTENT_MAX_BYTES)} that parses, names only document types the manifest declares, and whose media files are files under \`media/\` the build carries.`,
52
+ gates: ["cli", "door"],
53
+ needsManifest: true,
54
+ run: (context) => checkSampleContent(sampleOf(context), context.dir, context.manifest),
55
+ };
56
+ function count(n, one, many) {
57
+ return `${n} ${n === 1 ? one : many}`;
58
+ }
59
+ // S292: what an install of this plugin will ask, derived the way the install
60
+ // screen derives it (installInterfaceFor over the manifest and what the
61
+ // package ships). It fails one case only: a sample-content.json nothing
62
+ // consumes, which `build` refuses and an install could never add. A required
63
+ // option is a legitimate design, so it is counted, never warned about.
64
+ export const installOptionsCheck = {
65
+ name: "install options",
66
+ rule: "A `sample-content.json` ships only with a consumer: `documentTypes` or a `bundledTemplate`. The check also reports what the install will ask.",
67
+ gates: ["cli", "door"],
68
+ needsManifest: true,
69
+ run: (context) => {
70
+ const { manifest } = context;
71
+ const shipped = installFactsOf(sampleOf(context));
72
+ if (shipped.sampleContent && !hasSampleContentConsumer(manifest)) {
73
+ return failed("sample-content.json ships, but nothing in the manifest consumes it: declare documentTypes or a bundledTemplate, or remove the file");
74
+ }
75
+ const asks = installInterfaceFor(manifest, shipped);
76
+ const parts = [];
77
+ if (asks.sampleContent)
78
+ parts.push("add the sample content (yes by default)");
79
+ if (asks.roles.length > 0)
80
+ parts.push(`create ${count(asks.roles.length, "offered role", "offered roles")} (no by default)`);
81
+ if (asks.steps.length > 0) {
82
+ const options = asks.steps.flatMap((step) => step.options);
83
+ const needingAnswer = options.filter((option) => installOptionNeedsAnswer(option)).length;
84
+ parts.push(`${count(asks.steps.length, "step", "steps")} with ${count(options.length, "option", "options")}${needingAnswer > 0 ? `, ${needingAnswer} needing an answer` : ""}`);
85
+ }
86
+ if (parts.length === 0)
87
+ return passed("the install asks nothing: no steps declared, no sample content, no offered roles");
88
+ return passed(`the install asks: ${parts.join("; ")}`);
89
+ },
90
+ };
@@ -0,0 +1,24 @@
1
+ import type { DeliveryOutcome } from "./types.js";
2
+ export type Plain = Record<string, unknown>;
3
+ export declare function record(value: unknown): Plain | null;
4
+ export declare function list(value: unknown): unknown[];
5
+ export declare function contributionsOf(manifest: Plain): Plain;
6
+ export declare function plural(count: number, word: string): string;
7
+ /** "a, b or c": the items of a rule string that offers a choice. */
8
+ export declare function orList(items: readonly string[]): string;
9
+ export declare const passed: (message: string, details?: string[]) => DeliveryOutcome;
10
+ export declare const failed: (message: string, details?: string[]) => DeliveryOutcome;
11
+ export declare const warning: (message: string, details?: string[]) => DeliveryOutcome;
12
+ /** How many items a message lists before it says how many more there are. */
13
+ export declare const LISTED_MAX = 5;
14
+ /** The first LISTED_MAX items for a message, then how many more (S311): names
15
+ * run on with commas ("a, b and 3 more"), sentences with semicolons ("a; b;
16
+ * and 3 more"). A package can hold thousands of files, and a message that
17
+ * names each one is a message nobody reads and a door that stores megabytes. */
18
+ export declare function listCapped(items: readonly string[], kind?: "names" | "sentences"): string;
19
+ /** A thrown value as a developer-readable string, carrying the offending path
20
+ * when Node's error names one (EISDIR and EACCES do). Given the package
21
+ * directory, every path reads relative to it (S311): the server's extraction
22
+ * directory means nothing to an author and says where the server keeps its
23
+ * files. */
24
+ export declare function describeError(error: unknown, baseDir?: string): string;
@@ -0,0 +1,55 @@
1
+ import { relative, sep } from "node:path";
2
+ export function record(value) {
3
+ return value !== null && typeof value === "object" && !Array.isArray(value) ? value : null;
4
+ }
5
+ export function list(value) {
6
+ return Array.isArray(value) ? value : [];
7
+ }
8
+ export function contributionsOf(manifest) {
9
+ return record(manifest.contributions) ?? {};
10
+ }
11
+ export function plural(count, word) {
12
+ return `${count} ${word}${count === 1 ? "" : "s"}`;
13
+ }
14
+ /** "a, b or c": the items of a rule string that offers a choice. */
15
+ export function orList(items) {
16
+ if (items.length < 2)
17
+ return items.join("");
18
+ return `${items.slice(0, -1).join(", ")} or ${items[items.length - 1]}`;
19
+ }
20
+ export const passed = (message, details) => details && details.length > 0 ? { status: "passed", message, details } : { status: "passed", message };
21
+ export const failed = (message, details) => details && details.length > 0 ? { status: "failed", message, details } : { status: "failed", message };
22
+ export const warning = (message, details) => details && details.length > 0 ? { status: "warning", message, details } : { status: "warning", message };
23
+ /** How many items a message lists before it says how many more there are. */
24
+ export const LISTED_MAX = 5;
25
+ /** The first LISTED_MAX items for a message, then how many more (S311): names
26
+ * run on with commas ("a, b and 3 more"), sentences with semicolons ("a; b;
27
+ * and 3 more"). A package can hold thousands of files, and a message that
28
+ * names each one is a message nobody reads and a door that stores megabytes. */
29
+ export function listCapped(items, kind = "sentences") {
30
+ const shown = items.slice(0, LISTED_MAX);
31
+ const rest = items.length - shown.length;
32
+ if (kind === "names")
33
+ return rest > 0 ? `${shown.join(", ")} and ${rest} more` : shown.join(", ");
34
+ return rest > 0 ? `${shown.join("; ")}; and ${rest} more` : shown.join("; ");
35
+ }
36
+ /** A path as it reads inside the package: relative to `baseDir`, with "/". */
37
+ function insidePackage(baseDir, path) {
38
+ return relative(baseDir, path).split(sep).join("/") || ".";
39
+ }
40
+ /** A thrown value as a developer-readable string, carrying the offending path
41
+ * when Node's error names one (EISDIR and EACCES do). Given the package
42
+ * directory, every path reads relative to it (S311): the server's extraction
43
+ * directory means nothing to an author and says where the server keeps its
44
+ * files. */
45
+ export function describeError(error, baseDir) {
46
+ const path = error !== null && typeof error === "object" && "path" in error && typeof error.path === "string"
47
+ ? error.path
48
+ : null;
49
+ const message = error instanceof Error ? error.message : String(error);
50
+ if (path === null)
51
+ return baseDir ? message.split(baseDir + sep).join("") : message;
52
+ const shown = baseDir ? insidePackage(baseDir, path) : path;
53
+ const text = message.includes(path) ? message.split(path).join(shown) : `${message} (${shown})`;
54
+ return baseDir ? text.split(baseDir + sep).join("") : text;
55
+ }
@@ -0,0 +1,6 @@
1
+ import type { DeliveryCheck } from "./types.js";
2
+ export declare const templateDeclarationsCheck: DeliveryCheck;
3
+ export declare const templateFilesCheck: DeliveryCheck;
4
+ export declare const templateWiringCheck: DeliveryCheck;
5
+ export declare const assetsCheck: DeliveryCheck;
6
+ export declare const entryBudgetCheck: DeliveryCheck;
@@ -0,0 +1,158 @@
1
+ import { join } from "node:path";
2
+ import { MAX_TEMPLATE_PAYLOAD_ENTRIES, PluginAssetPathSchema, PluginTemplateFileSchema, PluginTemplatePayloadSchema, RESERVED_ASSET_ROOTS, TEMPLATE_KINDS, checkTemplateAndAssetDeclarations, effectiveDocsPages, listIssues, } from "@kardalum/api-schemas";
3
+ import { docsFilesToShip } from "../docs-contract.js";
4
+ import { createShippedLookup, walkShipped } from "../shipped-files.js";
5
+ import { contributionsOf, failed, list, orList, passed, plural, record } from "./support.js";
6
+ // S196 and S268: any plugin may declare templates and assets, whatever its
7
+ // listing label. Each check here asks its own question of the declaration and
8
+ // passes with "nothing declared" when there is none. The rules themselves are
9
+ // the shared schema in @kardalum/api-schemas (plugin-template-payload.ts),
10
+ // which the SDK and the server's install read too.
11
+ /** The cross-entry issues of a manifest's templates and assets, split by whether
12
+ * they are a page template's unresolved documentType (the wiring check reports
13
+ * those). A documentType on another kind is a declaration error, reported once,
14
+ * by the declarations check. */
15
+ function crossIssues(manifest) {
16
+ const c = contributionsOf(manifest);
17
+ // Entries too malformed to compare are left to the schema; the issue paths are
18
+ // mapped back to each entry's index in the manifest.
19
+ const templates = [];
20
+ list(c.templates).forEach((raw, index) => {
21
+ const e = record(raw);
22
+ if (!e || typeof e.file !== "string" || typeof e.alias !== "string" || typeof e.kind !== "string")
23
+ return;
24
+ templates.push({ index, file: e.file, alias: e.alias, kind: e.kind, ...(typeof e.documentType === "string" ? { documentType: e.documentType } : {}) });
25
+ });
26
+ const assets = [];
27
+ list(c.assets).forEach((raw, index) => {
28
+ if (typeof raw === "string")
29
+ assets.push({ index, path: raw });
30
+ });
31
+ const compared = { templates, assets };
32
+ const issues = checkTemplateAndAssetDeclarations({
33
+ templates,
34
+ assets: assets.map((asset) => asset.path),
35
+ documentTypes: list(c.documentTypes).flatMap((raw) => {
36
+ const name = record(raw)?.name;
37
+ return typeof name === "string" ? [{ name }] : [];
38
+ }),
39
+ }).map((issue) => {
40
+ const [field, position, ...rest] = issue.path;
41
+ const entry = typeof field === "string" && typeof position === "number" ? compared[field]?.[position] : undefined;
42
+ return entry ? { ...issue, path: [field, entry.index, ...rest] } : issue;
43
+ });
44
+ const pageIndexes = new Set(templates.filter((t) => t.kind === "page").map((t) => t.index));
45
+ const isWiring = (i) => i.path[0] === "templates" && i.path[2] === "documentType" && pageIndexes.has(i.path[1]);
46
+ return { wiring: issues.filter(isWiring), rest: issues.filter((i) => !isWiring(i)) };
47
+ }
48
+ /** The first folders an asset path may not start with, sorted as the schema's own message lists them. */
49
+ const RESERVED_FIRST_FOLDERS = [...RESERVED_ASSET_ROOTS].sort().map((root) => `\`${root}\``).join(", ");
50
+ export const templateDeclarationsCheck = {
51
+ name: "template declarations valid",
52
+ rule: "Template entries and asset paths obey the shared schema: kebab-case unique aliases, `.liquid` files, " +
53
+ `and a kind that is ${orList(TEMPLATE_KINDS)}; ` +
54
+ `asset paths that are relative, text, with no reserved first folder (${RESERVED_FIRST_FOLDERS}) and no \`public/\` prefix.`,
55
+ gates: ["cli", "door"],
56
+ needsManifest: true,
57
+ run: ({ manifest }) => {
58
+ const c = contributionsOf(manifest);
59
+ if (c.templates === undefined && c.assets === undefined)
60
+ return passed("no templates or assets declared");
61
+ const parsed = PluginTemplatePayloadSchema.safeParse({ templates: c.templates, assets: c.assets });
62
+ const issues = [...(parsed.success ? [] : parsed.error.issues), ...crossIssues(manifest).rest];
63
+ if (issues.length > 0)
64
+ return failed(listIssues(issues, 10));
65
+ return passed(`${plural(list(c.templates).length, "template")}, ${plural(list(c.assets).length, "asset")}: declarations valid`);
66
+ },
67
+ };
68
+ // S311 fix wave (W1): a declared file is there when the build carries it into
69
+ // the package (whyNotShipped, the rule the CLI's copy follows), not merely when
70
+ // it is on disk: a file under a left-out folder such as dist/, or behind a
71
+ // link, is on disk and never ships. Each detail says which it is.
72
+ export const templateFilesCheck = {
73
+ name: "template files exist",
74
+ rule: "Every declared template file is a file under `templates/` that the build carries: not behind a link, not inside a left-out folder such as `dist/` or `node_modules/`.",
75
+ gates: ["cli", "door"],
76
+ needsManifest: true,
77
+ run: ({ dir, manifest }) => {
78
+ const entries = list(contributionsOf(manifest).templates);
79
+ if (entries.length === 0)
80
+ return passed("no templates declared");
81
+ const problems = [];
82
+ const whyNotShipped = createShippedLookup(dir);
83
+ for (const raw of entries) {
84
+ const file = record(raw)?.file;
85
+ // An unusable path is reported by `template declarations valid`; never join it.
86
+ if (typeof file !== "string" || !PluginTemplateFileSchema.safeParse(file).success)
87
+ continue;
88
+ const why = whyNotShipped(`templates/${file}`);
89
+ if (why !== null)
90
+ problems.push(why === "does not exist" ? `${file}: does not exist under templates/` : `${file}: templates/${file} ${why}`);
91
+ }
92
+ if (problems.length > 0)
93
+ return failed(`${plural(problems.length, "declared template file")} not in the package`, problems);
94
+ return passed(`${plural(entries.length, "template file")} present`);
95
+ },
96
+ };
97
+ export const templateWiringCheck = {
98
+ name: "template document types wired",
99
+ rule: "A page template's `documentType`, when set, names a document type this manifest declares.",
100
+ gates: ["cli", "door"],
101
+ needsManifest: true,
102
+ run: ({ manifest }) => {
103
+ const { wiring } = crossIssues(manifest);
104
+ if (wiring.length > 0)
105
+ return failed(listIssues(wiring, 10));
106
+ return passed("every documentType a template names is declared");
107
+ },
108
+ };
109
+ export const assetsCheck = {
110
+ name: "assets declared exist",
111
+ rule: "Every declared asset is a file under `public/` that the build carries: not behind a link, not inside a left-out folder such as `dist/` or `node_modules/`.",
112
+ gates: ["cli", "door"],
113
+ needsManifest: true,
114
+ run: ({ dir, manifest }) => {
115
+ const declared = list(contributionsOf(manifest).assets).filter((a) => typeof a === "string");
116
+ if (declared.length === 0)
117
+ return passed("no assets declared");
118
+ const problems = [];
119
+ const whyNotShipped = createShippedLookup(dir);
120
+ for (const path of declared) {
121
+ // An unusable path is reported by `template declarations valid`; never join it.
122
+ if (!PluginAssetPathSchema.safeParse(path).success)
123
+ continue;
124
+ const why = whyNotShipped(`public/${path}`);
125
+ if (why !== null)
126
+ problems.push(why === "does not exist" ? `${path}: does not exist at public/${path}` : `${path}: public/${path} ${why}`);
127
+ }
128
+ if (problems.length > 0) {
129
+ return failed(`${plural(problems.length, "declared asset")} ${problems.length === 1 ? "is" : "are"} not in the package`, problems);
130
+ }
131
+ return passed(`${plural(declared.length, "asset")} present under public/`);
132
+ },
133
+ };
134
+ /** Past this many entries the check still passes, with a warning detail. */
135
+ const WARN_PAYLOAD_ENTRIES = 1000;
136
+ export const entryBudgetCheck = {
137
+ name: "artifact entry budget",
138
+ rule: `\`templates/\`, \`public/\` and the docs files hold at most ${MAX_TEMPLATE_PAYLOAD_ENTRIES} entries together.`,
139
+ gates: ["cli", "door"],
140
+ needsManifest: false,
141
+ run: ({ dir, manifest }) => {
142
+ // S311 second code fix: what the build carries, through the walker its
143
+ // copy uses: a left-out folder or a link never counts, and a linked top
144
+ // folder is not followed.
145
+ let total = 0;
146
+ for (const sub of ["templates", "public"])
147
+ total += walkShipped(join(dir, sub)).length;
148
+ // The docs pages and the images they show ship in the package too.
149
+ total += docsFilesToShip(dir, effectiveDocsPages(manifest.docs, String(manifest.name ?? ""))).length;
150
+ if (total > MAX_TEMPLATE_PAYLOAD_ENTRIES) {
151
+ return failed(`${total} payload entries exceeds the ${MAX_TEMPLATE_PAYLOAD_ENTRIES}-entry budget`);
152
+ }
153
+ const message = `${total} payload entries (budget ${MAX_TEMPLATE_PAYLOAD_ENTRIES})`;
154
+ if (total > WARN_PAYLOAD_ENTRIES)
155
+ return passed(message, [`warning: over ${WARN_PAYLOAD_ENTRIES} entries, approaching the artifact budget`]);
156
+ return passed(message);
157
+ },
158
+ };
@@ -0,0 +1,53 @@
1
+ import type { DocsContractInput } from "../docs-contract.js";
2
+ import type { ShippedSampleContent } from "../sample-content.js";
3
+ export type DeliveryGate = "cli" | "door";
4
+ export type DeliveryStatus = "passed" | "failed" | "warning" | "skipped";
5
+ export interface DeliveryOutcome {
6
+ status: DeliveryStatus;
7
+ message: string;
8
+ details?: string[];
9
+ }
10
+ export interface DeliveryResult extends DeliveryOutcome {
11
+ name: string;
12
+ }
13
+ export type DocsInputResult = {
14
+ ok: true;
15
+ input: DocsContractInput;
16
+ } | {
17
+ ok: false;
18
+ reasons: string[];
19
+ };
20
+ export interface DeliveryContext {
21
+ dir: string;
22
+ manifest: Record<string, unknown> | null;
23
+ docsInput?: DocsInputResult;
24
+ /** Where the client bundle (remoteEntry.js and assets/) is, when not in
25
+ * `dir`: the CLI hands over the federation build it packs, with the build's
26
+ * error when it failed. The door's package directory holds its bundle, so
27
+ * the door passes none. */
28
+ bundle?: {
29
+ dir: string;
30
+ buildError?: string;
31
+ };
32
+ /** The package's sample-content.json, read once for the run (S311): runChecks
33
+ * reads it when the caller has not, and both sample checks take it from
34
+ * here, so a gate parses the file once. The door hands its own read on to
35
+ * the stored install interface. */
36
+ sampleContent?: ShippedSampleContent;
37
+ }
38
+ export interface DeliveryRunContext extends Omit<DeliveryContext, "manifest"> {
39
+ manifest: Record<string, unknown>;
40
+ }
41
+ export interface DeliveryCheck {
42
+ name: string;
43
+ rule: string;
44
+ gates: readonly DeliveryGate[];
45
+ needsManifest: boolean;
46
+ run(context: DeliveryRunContext): DeliveryOutcome;
47
+ }
48
+ export interface GateOnlyCheck {
49
+ name: string;
50
+ gate: DeliveryGate;
51
+ rule: string;
52
+ skippedAtDoor: boolean;
53
+ }
@@ -6,8 +6,9 @@ export interface DocsContractInput {
6
6
  }
7
7
  /** The most a manifest.json or reference.json may weigh. The door parses both
8
8
  * synchronously on the event loop, so a schema-valid file of tens of
9
- * megabytes would block it on every request that reads one. */
10
- export declare const MAX_PACKAGE_JSON_BYTES = 1048576;
9
+ * megabytes would block it on every request that reads one. The manifest's
10
+ * limit, defined once (S311). */
11
+ export declare const MAX_PACKAGE_JSON_BYTES: number;
11
12
  /** A posix package-relative path as a native filesystem path. This is the
12
13
  * one place such a path becomes a real one, so it is also where leaving the
13
14
  * package is made impossible: a path that would is a defect in the checks
@@ -1,10 +1,12 @@
1
1
  import { closeSync, existsSync, openSync, readFileSync, readSync, readdirSync, statSync } from "node:fs";
2
2
  import { join, resolve, sep } from "node:path";
3
3
  import { MAX_DOC_PAGE_BYTES, PluginDocsPageSchema, PluginReferenceSchema, checkDocsDeclaration, docsFactsFrom, effectiveDocsPages, extractDocHeadings, isRenderableExternalHref, MAX_DOCS_TARGET_LENGTH, referencePageSlugs, requiredDocRoles, resolveDocsLink, resolveDocsPath, } from "@kardalum/api-schemas";
4
+ import { MANIFEST_MAX_BYTES } from "./delivery/limits.js";
4
5
  /** The most a manifest.json or reference.json may weigh. The door parses both
5
6
  * synchronously on the event loop, so a schema-valid file of tens of
6
- * megabytes would block it on every request that reads one. */
7
- export const MAX_PACKAGE_JSON_BYTES = 1048576;
7
+ * megabytes would block it on every request that reads one. The manifest's
8
+ * limit, defined once (S311). */
9
+ export const MAX_PACKAGE_JSON_BYTES = MANIFEST_MAX_BYTES;
8
10
  const IMAGE_EXTENSION = /\.(png|jpe?g|gif|webp)$/i;
9
11
  /** Past this many links and images a page is refused rather than checked. */
10
12
  const MAX_TARGETS_PER_PAGE = 2000;
@@ -1,10 +1,25 @@
1
+ import type { Entry } from "yauzl";
1
2
  export declare const MAX_TOTAL_BYTES: number;
2
3
  export declare const MAX_ENTRY_BYTES: number;
3
4
  export declare const MAX_ENTRIES = 2000;
5
+ /** An entry name as a message quotes it: JSON-escaped, so a control character
6
+ * or a quote cannot break the line, and cut after NAME_SHOWN characters. */
7
+ export declare function quoteEntryName(name: string): string;
8
+ /** The longest name a package may hold: Windows' MAX_PATH, api-schemas'
9
+ * PACKAGE_PATH_MAX, which the template file and asset path caps are drawn
10
+ * from. A path longer than that cannot be written on a Windows host, wherever
11
+ * the package installs, since the install's own folder only adds to it (S311
12
+ * second code fix). */
13
+ export declare const ENTRY_NAME_MAX = 260;
14
+ /** The most segments, folders and a file, one name may have. */
15
+ export declare const ENTRY_SEGMENTS_MAX = 32;
4
16
  /** Pure gate over one entry's (path, type, declaredSize). Returns the
5
17
  * violation message or null. Exported for direct unit testing — a
6
18
  * well-formed writer can't produce hostile names, but attackers hand-craft
7
- * archives directly.
19
+ * archives directly. The path rules are nameViolation's: what a Linux
20
+ * extraction and a Windows or macOS one would read as different files is
21
+ * refused, so every reader of a package (both of the marketplace's, the
22
+ * install's, the watermark's re-pack) admits the same names.
8
23
  *
9
24
  * "OldFile" and "ContiguousFile" are accepted alongside "File" for
10
25
  * historical (tar-era) compatibility with entries this gate has always
@@ -14,10 +29,83 @@ export declare const MAX_ENTRIES = 2000;
14
29
  * behavior and would only risk breaking direct callers of this exported
15
30
  * function. */
16
31
  export declare function entryViolation(path: string, type: string, size: number): string | null;
32
+ /** The key two entry names are compared by: the path's segments, split on "/"
33
+ * and backslash (a Windows extraction reads both as a separator), with empty
34
+ * and "." segments dropped and case folded (a case-insensitive filesystem
35
+ * writes "A.txt" and "a.txt" to one file). Two names with one key land on one
36
+ * path, so "manifest.json", "./manifest.json", ".//manifest.json" and the same
37
+ * name behind a backslash are one name. entryViolation refuses the "." and
38
+ * backslash spellings on their own now; the key still folds case and empty
39
+ * segments. Linear in the name's length. */
40
+ export declare function normalizeEntryName(name: string): string;
41
+ type EntryNameSource = Pick<Entry, "fileNameRaw" | "generalPurposeBitFlag" | "extraFields">;
42
+ /** The one name every reader of a package gives an entry (S311): the header's
43
+ * raw bytes, decoded as UTF-8 when the entry's flag (0x800) says so and as
44
+ * latin1 otherwise. ASCII, the only bytes entryViolation's checks look at,
45
+ * decodes the same either way. An entry that names itself a second time, in an
46
+ * Info-ZIP Unicode Path field, is refused: a reader that honours the field (yauzl
47
+ * with decodeStrings) and one that does not would read different files. Open the
48
+ * archive with `decodeStrings: false`, so yauzl neither prefers the field nor
49
+ * turns a backslash into a slash. */
50
+ export declare function decodeEntryName(entry: EntryNameSource): {
51
+ ok: true;
52
+ name: string;
53
+ } | {
54
+ ok: false;
55
+ reason: string;
56
+ };
57
+ export type AdmittedEntry = {
58
+ ok: true;
59
+ name: string;
60
+ isDirectory: boolean;
61
+ } | {
62
+ ok: false;
63
+ reason: string;
64
+ };
65
+ /** The rule for the paths of one archive (S311 fix wave): each path once, by
66
+ * normalizeEntryName's key, and each path one kind, never a file where another
67
+ * entry needs a folder ("a" beside "a/b", or "public/Logo" beside
68
+ * "public/logo/x.png", which a case-insensitive host cannot write). Returns
69
+ * the reason a name is refused, or null once it is admitted. A folder entry
70
+ * for a folder the files under it already imply is admitted, in either order.
71
+ * The paths are held as a tree of segments, so a name costs time linear in its
72
+ * length. Every caller hands it a name entryViolation admitted, at most
73
+ * ENTRY_NAME_MAX characters in at most ENTRY_SEGMENTS_MAX segments, so an
74
+ * archive of MAX_ENTRIES entries holds at most that many nodes per entry
75
+ * (the S311 second code fix: an uncapped name could make one archive hold
76
+ * gigabytes). createEntryGate applies it to every reader of a package, and the
77
+ * `archive names` check and `kardalum plugin pack` apply it before an archive
78
+ * exists. */
79
+ export declare function createPathKeyGate(): (name: string, isDirectory: boolean) => string | null;
80
+ /** The rules every reader of a package applies to its entries, in central
81
+ * directory order (S311): at most MAX_ENTRIES entries, each name decoded by
82
+ * decodeEntryName and passing entryViolation (which holds MAX_ENTRY_BYTES), each
83
+ * path once and of one kind by createPathKeyGate, and MAX_TOTAL_BYTES declared
84
+ * in all. One gate per archive: it counts what it has admitted. extractArtifact
85
+ * and the marketplace's manifest reader both read through it, so the door's
86
+ * reader refuses exactly what extraction refuses, before a listing exists. */
87
+ export declare function createEntryGate(): (entry: EntryNameSource & Pick<Entry, "uncompressedSize">) => AdmittedEntry;
88
+ /** An entry a packer is about to write: its path with "/" (a folder without
89
+ * the trailing slash the archive gives it) and its size. */
90
+ export interface PlannedEntry {
91
+ name: string;
92
+ isDirectory: boolean;
93
+ size: number;
94
+ }
95
+ /** What createEntryGate would refuse first in `entries`, in order, or null:
96
+ * the rule extraction and the marketplace read an archive by, applied by a
97
+ * packer before it writes one (S311 fix wave), so `kardalum plugin pack` never
98
+ * writes an archive the marketplace or an install would refuse for a name,
99
+ * the entry count or a size. */
100
+ export declare function plannedEntryRefusal(entries: readonly PlannedEntry[]): string | null;
17
101
  /**
18
102
  * Extracts a single ZIP archive into `targetDir`, admitting only entries
19
- * that pass `entryViolation`'s allow-list and the MAX_ENTRIES/
20
- * MAX_TOTAL_BYTES ceilings below. Never throws — every failure mode
103
+ * that pass createEntryGate: `entryViolation`'s allow-list, the MAX_ENTRIES
104
+ * and MAX_TOTAL_BYTES ceilings, one name per entry (no Info-ZIP Unicode Path
105
+ * field) and each path once by `normalizeEntryName`'s segment key (S311). The
106
+ * marketplace's manifest reader reads through the same gate and the same
107
+ * decoder, so the manifest.json it parsed is the one file that lands at
108
+ * manifest.json; the door also compares the two by hash. Never throws: every failure mode
21
109
  * resolves `{ ok: false, reason }`, so a hostile or broken package
22
110
  * degrades with a clear reason at install time instead of an uncaught
23
111
  * rejection bricking (or 500-ing) the host.
@@ -35,3 +123,4 @@ export declare function extractArtifact(archivePath: string, targetDir: string):
35
123
  ok: false;
36
124
  reason: string;
37
125
  }>;
126
+ export {};