@kardalum/plugin-sdk 0.15.0 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +49 -1
- package/README.md +10 -0
- package/dist/admin-section-registry.d.ts +14 -5
- package/dist/admin-section-registry.js +14 -4
- package/dist/built-in-value-schemas.js +1 -1
- package/dist/built-ins.js +2 -2
- package/dist/capabilities.d.ts +8 -78
- package/dist/capabilities.js +23 -322
- package/dist/host-entry.d.ts +1 -1
- package/dist/host-entry.js +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.js +13 -12
- package/dist/license-verdict-keys.d.ts +4 -3
- package/dist/license-verdict-keys.js +6 -5
- package/dist/manifest-entry.d.ts +3 -3
- package/dist/manifest-entry.js +2 -2
- package/dist/manifest-schema.d.ts +113 -56
- package/dist/manifest-schema.js +192 -295
- package/dist/manifest.d.ts +145 -112
- package/dist/manifest.js +13 -36
- package/dist/media/media-picker.js +21 -12
- package/dist/media/upload-error.d.ts +1 -1
- package/dist/media/upload-error.js +1 -1
- package/dist/plugin-context.d.ts +7 -0
- package/dist/plugin-context.js +7 -0
- package/dist/plugin-screen-context.d.ts +44 -3
- package/dist/plugin-screen-context.js +27 -2
- package/dist/read-all-pages.d.ts +23 -0
- package/dist/read-all-pages.js +30 -0
- package/dist/richtext/block-panel.js +6 -6
- package/dist/richtext/insert-menu.js +4 -4
- package/dist/richtext/style-listbox.js +4 -4
- package/dist/tokens/tokens.css +1 -0
- package/dist/tokens/tokens.json +2 -1
- package/dist/type-equality.d.ts +2 -0
- package/dist/type-equality.js +1 -0
- package/dist/views/content-list-view.js +2 -2
- package/dist/views/html-view.js +1 -1
- package/dist/views/image-view.js +24 -39
- package/dist/views/rich-text-view.js +3 -3
- package/node_modules/@kardalum/api-schemas/dist/api-error.schema.d.ts +12 -0
- package/node_modules/@kardalum/api-schemas/dist/api-error.schema.js +19 -0
- package/node_modules/@kardalum/api-schemas/dist/api-key-api.schema.d.ts +43 -25
- package/node_modules/@kardalum/api-schemas/dist/api-key-api.schema.js +60 -8
- package/node_modules/@kardalum/api-schemas/dist/asset-api.schema.d.ts +90 -0
- package/node_modules/@kardalum/api-schemas/dist/asset-api.schema.js +33 -2
- package/node_modules/@kardalum/api-schemas/dist/asset.schema.d.ts +22 -1
- package/node_modules/@kardalum/api-schemas/dist/asset.schema.js +50 -15
- package/node_modules/@kardalum/api-schemas/dist/audit-api.schema.d.ts +204 -0
- package/node_modules/@kardalum/api-schemas/dist/audit-api.schema.js +134 -0
- package/node_modules/@kardalum/api-schemas/dist/content-api.schema.d.ts +5 -0
- package/node_modules/@kardalum/api-schemas/dist/content-api.schema.js +18 -13
- package/node_modules/@kardalum/api-schemas/dist/content-list.schema.d.ts +2 -2
- package/node_modules/@kardalum/api-schemas/dist/content-list.schema.js +1 -1
- package/node_modules/@kardalum/api-schemas/dist/content-path.js +11 -7
- package/node_modules/@kardalum/api-schemas/dist/content-trash-api.schema.d.ts +4 -0
- package/node_modules/@kardalum/api-schemas/dist/content-trash-api.schema.js +3 -0
- package/node_modules/@kardalum/api-schemas/dist/content-trash.schema.d.ts +1 -0
- package/node_modules/@kardalum/api-schemas/dist/content-trash.schema.js +2 -1
- package/node_modules/@kardalum/api-schemas/dist/core-actions.d.ts +143 -57
- package/node_modules/@kardalum/api-schemas/dist/core-actions.js +110 -60
- package/node_modules/@kardalum/api-schemas/dist/data-type-api.schema.d.ts +1 -0
- package/node_modules/@kardalum/api-schemas/dist/document-type-api.schema.d.ts +2 -0
- package/node_modules/@kardalum/api-schemas/dist/document-type-api.schema.js +1 -1
- package/node_modules/@kardalum/api-schemas/dist/index.d.ts +67 -40
- package/node_modules/@kardalum/api-schemas/dist/index.js +35 -19
- package/node_modules/@kardalum/api-schemas/dist/install-warnings.schema.d.ts +4 -0
- package/node_modules/@kardalum/api-schemas/dist/install-warnings.schema.js +8 -0
- package/node_modules/@kardalum/api-schemas/dist/issue-list.d.ts +6 -0
- package/node_modules/@kardalum/api-schemas/dist/issue-list.js +6 -0
- package/node_modules/@kardalum/api-schemas/dist/management-multipart.schema.d.ts +73 -0
- package/node_modules/@kardalum/api-schemas/dist/management-multipart.schema.js +104 -0
- package/node_modules/@kardalum/api-schemas/dist/marketplace-listing-api.schema.d.ts +356 -16
- package/node_modules/@kardalum/api-schemas/dist/marketplace-listing-api.schema.js +93 -10
- package/node_modules/@kardalum/api-schemas/dist/media-api.schema.d.ts +10 -0
- package/node_modules/@kardalum/api-schemas/dist/media-api.schema.js +38 -30
- package/node_modules/@kardalum/api-schemas/dist/media-rendition.schema.js +2 -2
- package/node_modules/@kardalum/api-schemas/dist/media.schema.js +1 -1
- package/node_modules/@kardalum/api-schemas/dist/plugin-actions.schema.d.ts +6 -2
- package/node_modules/@kardalum/api-schemas/dist/plugin-actions.schema.js +8 -6
- package/node_modules/@kardalum/api-schemas/dist/plugin-docs-api.schema.d.ts +69 -4
- package/node_modules/@kardalum/api-schemas/dist/plugin-docs-api.schema.js +4 -0
- package/node_modules/@kardalum/api-schemas/dist/plugin-docs.d.ts +76 -9
- package/node_modules/@kardalum/api-schemas/dist/plugin-docs.js +84 -24
- package/node_modules/@kardalum/api-schemas/dist/plugin-id-rules.d.ts +17 -7
- package/node_modules/@kardalum/api-schemas/dist/plugin-id-rules.js +18 -8
- package/node_modules/@kardalum/api-schemas/dist/plugin-install-record.schema.d.ts +69 -0
- package/node_modules/@kardalum/api-schemas/dist/plugin-install-record.schema.js +59 -0
- package/node_modules/@kardalum/api-schemas/dist/plugin-install.d.ts +597 -0
- package/node_modules/@kardalum/api-schemas/dist/plugin-install.js +503 -0
- package/node_modules/@kardalum/api-schemas/dist/plugin-labels.d.ts +60 -0
- package/node_modules/@kardalum/api-schemas/dist/plugin-labels.js +116 -0
- package/node_modules/@kardalum/api-schemas/dist/plugin-locales.d.ts +82 -0
- package/node_modules/@kardalum/api-schemas/dist/plugin-locales.js +228 -0
- package/node_modules/@kardalum/api-schemas/dist/plugin-management-api.schema.d.ts +33 -4
- package/node_modules/@kardalum/api-schemas/dist/plugin-management-api.schema.js +28 -2
- package/node_modules/@kardalum/api-schemas/dist/plugin-manifest-actions.d.ts +11 -3
- package/node_modules/@kardalum/api-schemas/dist/plugin-manifest-actions.js +17 -4
- package/node_modules/@kardalum/api-schemas/dist/plugin-manifest-api-routes.d.ts +58 -0
- package/node_modules/@kardalum/api-schemas/dist/plugin-manifest-api-routes.js +198 -0
- package/node_modules/@kardalum/api-schemas/dist/plugin-manifest-fields.d.ts +64 -0
- package/node_modules/@kardalum/api-schemas/dist/plugin-manifest-fields.js +134 -0
- package/node_modules/@kardalum/api-schemas/dist/plugin-registry-api.schema.d.ts +2 -0
- package/node_modules/@kardalum/api-schemas/dist/plugin-registry-api.schema.js +4 -0
- package/node_modules/@kardalum/api-schemas/dist/plugin-template-payload.d.ts +74 -0
- package/node_modules/@kardalum/api-schemas/dist/plugin-template-payload.js +132 -0
- package/node_modules/@kardalum/api-schemas/dist/plugin-vocabulary.d.ts +13 -0
- package/node_modules/@kardalum/api-schemas/dist/plugin-vocabulary.js +15 -0
- package/node_modules/@kardalum/api-schemas/dist/public-api.schema.d.ts +8 -0
- package/node_modules/@kardalum/api-schemas/dist/public-api.schema.js +23 -4
- package/node_modules/@kardalum/api-schemas/dist/render-editing.d.ts +4 -4
- package/node_modules/@kardalum/api-schemas/dist/role.schema.d.ts +17 -0
- package/node_modules/@kardalum/api-schemas/dist/role.schema.js +13 -0
- package/node_modules/@kardalum/api-schemas/dist/sample-content.schema.d.ts +44 -0
- package/node_modules/@kardalum/api-schemas/dist/sample-content.schema.js +97 -0
- package/node_modules/@kardalum/api-schemas/dist/sandbox-attach.schema.d.ts +126 -0
- package/node_modules/@kardalum/api-schemas/dist/sandbox-attach.schema.js +70 -0
- package/node_modules/@kardalum/api-schemas/dist/setup-api.schema.d.ts +36 -6
- package/node_modules/@kardalum/api-schemas/dist/setup-api.schema.js +17 -5
- package/node_modules/@kardalum/api-schemas/dist/sites.schema.d.ts +52 -33
- package/node_modules/@kardalum/api-schemas/dist/sites.schema.js +195 -56
- package/node_modules/@kardalum/api-schemas/dist/snapshot-api.schema.d.ts +19 -3
- package/node_modules/@kardalum/api-schemas/dist/snapshot-api.schema.js +16 -0
- package/node_modules/@kardalum/api-schemas/dist/snapshot.schema.d.ts +1 -1
- package/node_modules/@kardalum/api-schemas/dist/strict-url.d.ts +12 -0
- package/node_modules/@kardalum/api-schemas/dist/strict-url.js +31 -0
- package/node_modules/@kardalum/api-schemas/dist/template-api.schema.d.ts +105 -1
- package/node_modules/@kardalum/api-schemas/dist/template-api.schema.js +47 -7
- package/node_modules/@kardalum/api-schemas/dist/template.schema.d.ts +30 -2
- package/node_modules/@kardalum/api-schemas/dist/template.schema.js +19 -5
- package/node_modules/@kardalum/api-schemas/dist/trash-cursor.schema.d.ts +4 -0
- package/node_modules/@kardalum/api-schemas/dist/trash-cursor.schema.js +29 -0
- package/node_modules/@kardalum/api-schemas/dist/user-api.schema.d.ts +15 -3
- package/node_modules/@kardalum/api-schemas/dist/user-api.schema.js +8 -0
- package/node_modules/@kardalum/api-schemas/dist/whoami-api.schema.d.ts +19 -0
- package/node_modules/@kardalum/api-schemas/dist/whoami-api.schema.js +22 -0
- package/node_modules/@kardalum/api-schemas/package.json +2 -2
- package/node_modules/@kardalum/design-tokens/dist/tailwind-theme.d.ts +1 -0
- package/node_modules/@kardalum/design-tokens/dist/tailwind-theme.js +2 -0
- package/node_modules/@kardalum/design-tokens/dist/tokens.css +1 -0
- package/node_modules/@kardalum/design-tokens/dist/tokens.js +3 -0
- package/node_modules/@kardalum/design-tokens/dist/tokens.json +2 -1
- package/node_modules/@kardalum/design-tokens/dist/types.d.ts +1 -0
- package/node_modules/@kardalum/plugin-package/README.md +4 -1
- package/node_modules/@kardalum/plugin-package/dist/build-reference.d.ts +96 -0
- package/node_modules/@kardalum/plugin-package/dist/build-reference.js +66 -0
- package/node_modules/@kardalum/plugin-package/dist/capabilities.d.ts +103 -0
- package/node_modules/@kardalum/plugin-package/dist/capabilities.js +346 -0
- package/node_modules/@kardalum/plugin-package/dist/client-bundle.d.ts +4 -0
- package/node_modules/@kardalum/plugin-package/dist/client-bundle.js +25 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/archive-names.d.ts +25 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/archive-names.js +203 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/bundle.d.ts +3 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/bundle.js +73 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/contributions.d.ts +5 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/contributions.js +60 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/icon-names.generated.d.ts +1 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/icon-names.generated.js +2052 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/icons.d.ts +2 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/icons.js +51 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/index.d.ts +8 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/index.js +7 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/label-languages.d.ts +17 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/label-languages.js +119 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/limits.d.ts +14 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/limits.js +21 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/locales.d.ts +5 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/locales.js +148 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/package-files.d.ts +5 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/package-files.js +76 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/registry.d.ts +22 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/registry.js +133 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/sample-content.d.ts +3 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/sample-content.js +90 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/support.d.ts +24 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/support.js +55 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/templates.d.ts +6 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/templates.js +158 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/types.d.ts +53 -0
- package/node_modules/@kardalum/plugin-package/dist/delivery/types.js +1 -0
- package/node_modules/@kardalum/plugin-package/dist/docs-contract.d.ts +3 -2
- package/node_modules/@kardalum/plugin-package/dist/docs-contract.js +4 -2
- package/node_modules/@kardalum/plugin-package/dist/extract.d.ts +92 -3
- package/node_modules/@kardalum/plugin-package/dist/extract.js +251 -41
- package/node_modules/@kardalum/plugin-package/dist/index.d.ts +11 -2
- package/node_modules/@kardalum/plugin-package/dist/index.js +8 -2
- package/node_modules/@kardalum/plugin-package/dist/manifest-entry.d.ts +5 -0
- package/node_modules/@kardalum/plugin-package/dist/manifest-entry.js +20 -0
- package/node_modules/@kardalum/plugin-package/dist/reference-entry.d.ts +3 -0
- package/node_modules/@kardalum/plugin-package/dist/reference-entry.js +7 -0
- package/node_modules/@kardalum/plugin-package/dist/sample-content.d.ts +38 -1
- package/node_modules/@kardalum/plugin-package/dist/sample-content.js +84 -16
- package/node_modules/@kardalum/plugin-package/dist/shipped-files.d.ts +39 -0
- package/node_modules/@kardalum/plugin-package/dist/shipped-files.js +133 -0
- package/node_modules/@kardalum/plugin-package/dist/shipped-locales.d.ts +7 -0
- package/node_modules/@kardalum/plugin-package/dist/shipped-locales.js +27 -0
- package/node_modules/@kardalum/plugin-package/dist/types.d.ts +4 -6
- package/node_modules/@kardalum/plugin-package/dist/types.js +15 -1
- package/node_modules/@kardalum/plugin-package/package.json +9 -2
- package/node_modules/@kardalum/ui/dist/components/checkbox.js +2 -2
- package/node_modules/@kardalum/ui/dist/components/dropdown-menu.js +2 -2
- package/node_modules/@kardalum/ui/dist/components/property-field.js +4 -1
- package/node_modules/@kardalum/ui/package.json +1 -1
- 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
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
|
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
|
|
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
|
|
38
|
-
* MAX_TOTAL_BYTES ceilings
|
|
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
|
|
77
|
-
// required
|
|
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
|
-
|
|
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
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
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
|
-
|
|
133
|
-
//
|
|
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
|
|
352
|
+
fail(`unsafe entry path ${quoteEntryName(fileName)}`);
|
|
143
353
|
return;
|
|
144
354
|
}
|
|
145
355
|
// The filesystem calls below can throw — most concretely EEXIST
|
|
@@ -1,11 +1,20 @@
|
|
|
1
1
|
export type { PackageSignatureSidecar, SignatureEnvelope, TrustedKey, VerifyFailureReason, VerifyResult, } from "./types.js";
|
|
2
|
+
export { VERIFY_FAILURE_REASONS } from "./types.js";
|
|
2
3
|
export { canonicalizeEnvelope, deriveKeyId, generateSigningKeyPair, signEnvelope, verifyEnvelope, } from "./envelope.js";
|
|
3
4
|
export type { LicenseChallenge, LicenseVerdictEnvelope, LicenseVerdictResult, LicenseVerdictSignatureResult, SignedLicenseVerdict, TamperKind, } from "./license-verdict.js";
|
|
4
5
|
export { canonicalizeLicenseVerdict, createLicenseChallenge, ENTITLEMENT_MAX_AGE_MS, hashLicenseKey, LICENSE_VERDICT_DETAIL_MAX, MAX_VERDICT_AGE_MS, signLicenseVerdict, verifyLicenseVerdict, verifyLicenseVerdictSignature, } from "./license-verdict.js";
|
|
5
6
|
export { hashBuffer, hashArchive, hashDirectories } from "./hash.js";
|
|
6
|
-
export {
|
|
7
|
-
export {
|
|
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";
|
|
12
|
+
export type { ShippedSampleContent } from "./sample-content.js";
|
|
13
|
+
export { MAX_SHIPPED_LOCALES, readShippedLocales } from "./shipped-locales.js";
|
|
8
14
|
export type { PackageContractCheck } from "./package-contract.js";
|
|
9
15
|
export { checkCoverContract, checkPackageContract, checkReadmeContract, COVER_HEIGHT, COVER_PATH, COVER_WIDTH, pngSize, } from "./package-contract.js";
|
|
10
16
|
export type { DocsContractInput } from "./docs-contract.js";
|
|
11
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";
|
|
@@ -1,7 +1,13 @@
|
|
|
1
|
+
export { VERIFY_FAILURE_REASONS } from "./types.js";
|
|
1
2
|
export { canonicalizeEnvelope, deriveKeyId, generateSigningKeyPair, signEnvelope, verifyEnvelope, } from "./envelope.js";
|
|
2
3
|
export { canonicalizeLicenseVerdict, createLicenseChallenge, ENTITLEMENT_MAX_AGE_MS, hashLicenseKey, LICENSE_VERDICT_DETAIL_MAX, MAX_VERDICT_AGE_MS, signLicenseVerdict, verifyLicenseVerdict, verifyLicenseVerdictSignature, } from "./license-verdict.js";
|
|
3
4
|
export { hashBuffer, hashArchive, hashDirectories } from "./hash.js";
|
|
4
|
-
export { entryViolation, extractArtifact, MAX_ENTRIES, MAX_ENTRY_BYTES, MAX_TOTAL_BYTES } from "./extract.js";
|
|
5
|
-
export {
|
|
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";
|
|
6
9
|
export { checkCoverContract, checkPackageContract, checkReadmeContract, COVER_HEIGHT, COVER_PATH, COVER_WIDTH, pngSize, } from "./package-contract.js";
|
|
7
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
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// @kardalum/plugin-package/reference: the capability derivation and the
|
|
2
|
+
// reference builder, with no node: import and no third-party import, so the
|
|
3
|
+
// SDK's browser entries can re-export them (S289, spec 3.1).
|
|
4
|
+
// reference-entry.test.ts holds that line.
|
|
5
|
+
export * from "./capabilities.js";
|
|
6
|
+
export * from "./build-reference.js";
|
|
7
|
+
export * from "./client-bundle.js";
|
|
@@ -1 +1,38 @@
|
|
|
1
|
-
|
|
1
|
+
import { type SampleContentFile, type ShippedInstallFacts } from "@kardalum/api-schemas";
|
|
2
|
+
/** The largest sample-content.json read to decide whether the sample ships,
|
|
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. */
|
|
6
|
+
export declare const SAMPLE_CONTENT_MAX_BYTES: number;
|
|
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. */
|
|
10
|
+
export type ShippedSampleContent = {
|
|
11
|
+
status: "absent";
|
|
12
|
+
} | {
|
|
13
|
+
status: "unreadable";
|
|
14
|
+
reason: string;
|
|
15
|
+
details?: string[];
|
|
16
|
+
} | {
|
|
17
|
+
status: "ships";
|
|
18
|
+
file: SampleContentFile;
|
|
19
|
+
};
|
|
20
|
+
/** Absent, unreadable (not a regular file, over SAMPLE_CONTENT_MAX_BYTES, not
|
|
21
|
+
* JSON, or refused by the schema) or the parsed file. Never throws. The
|
|
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. */
|
|
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;
|
|
29
|
+
/** Never throws: anything unreadable ships nothing. */
|
|
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,17 +1,85 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
// (
|
|
6
|
-
//
|
|
7
|
-
//
|
|
1
|
+
import { lstatSync, readFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { parseSampleContentFile } from "@kardalum/api-schemas";
|
|
4
|
+
import { listCapped } from "./delivery/support.js";
|
|
5
|
+
// S292 (2026-10-13-s292-what-the-wizard-may-ask-design.md, D8): what a
|
|
6
|
+
// package directory ships that its install's built-in questions are derived
|
|
7
|
+
// from. One definition for `kardalum plugin validate`'s `install options`
|
|
8
|
+
// check, the marketplace door's stored install interface, and (S293) the
|
|
9
|
+
// server's install doors: a sample-content.json at the package root that is
|
|
10
|
+
// a regular file within SAMPLE_CONTENT_MAX_BYTES and parses under
|
|
11
|
+
// SampleContentFileSchema (@kardalum/api-schemas, which also holds the
|
|
12
|
+
// media file pattern this module used to). A file the schema refuses does
|
|
13
|
+
// not ship: the CLI's `sample content valid` check reports it, and the
|
|
14
|
+
// seeder answers "invalid" at install.
|
|
8
15
|
//
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
//
|
|
12
|
-
//
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
export const
|
|
16
|
+
// S293 (2026-10-13-s293-the-wizard-installed-design.md 3.6, D11): the read
|
|
17
|
+
// itself is readShippedSampleContent, which the server's seeder goes through
|
|
18
|
+
// too, so the seeder parses only what the cap admits and a present but
|
|
19
|
+
// unreadable file is told apart from an absent one.
|
|
20
|
+
/** The largest sample-content.json read to decide whether the sample ships,
|
|
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;
|
|
25
|
+
/** Absent, unreadable (not a regular file, over SAMPLE_CONTENT_MAX_BYTES, not
|
|
26
|
+
* JSON, or refused by the schema) or the parsed file. Never throws. The
|
|
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. */
|
|
31
|
+
export function readShippedSampleContent(dir) {
|
|
32
|
+
const path = join(dir, "sample-content.json");
|
|
33
|
+
let size;
|
|
34
|
+
try {
|
|
35
|
+
const stats = lstatSync(path);
|
|
36
|
+
if (!stats.isFile())
|
|
37
|
+
return { status: "unreadable", reason: "sample-content.json is not a regular file" };
|
|
38
|
+
size = stats.size;
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
return error.code === "ENOENT"
|
|
42
|
+
? { status: "absent" }
|
|
43
|
+
: { status: "unreadable", reason: "sample-content.json cannot be read" };
|
|
44
|
+
}
|
|
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
|
+
}
|
|
51
|
+
let raw;
|
|
52
|
+
try {
|
|
53
|
+
raw = JSON.parse(readFileSync(path, "utf8"));
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
return { status: "unreadable", reason: "sample-content.json is not valid JSON" };
|
|
57
|
+
}
|
|
58
|
+
const parsed = parseSampleContentFile(raw);
|
|
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 };
|
|
62
|
+
}
|
|
63
|
+
/** What a read ships for the install interface: anything unreadable ships nothing. */
|
|
64
|
+
export function installFactsOf(sample) {
|
|
65
|
+
if (sample.status !== "ships")
|
|
66
|
+
return { sampleContent: false };
|
|
67
|
+
return sample.file.description ? { sampleContent: true, sampleContentDescription: sample.file.description } : { sampleContent: true };
|
|
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;
|