@tutti-os/app-release-tools 0.0.1

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/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,26 @@
1
+ # @tutti-os/app-release-tools
2
+
3
+ Command-line tools for publishing Nextop workspace apps into App Center release metadata.
4
+
5
+ ## Commands
6
+
7
+ ```sh
8
+ build-nextop-app-release --app-id vibe-design --package-dir dist/nextop-app/vibe-design --base-url https://cdn.example.test/nextop-app-releases
9
+ build-nextop-app-catalog --release-file ./apps/vibe-design/latest.json --output ./catalog.json
10
+ build-nextop-app-catalog --existing-catalog ./catalog.json --release-file ./apps/vibe-design/latest.json --output ./catalog.json
11
+ verify-nextop-app-release-artifacts --release-file ./apps/vibe-design/latest.json
12
+ verify-nextop-app-release-artifacts --catalog-file ./catalog.json --release-file ./apps/vibe-design/latest.json
13
+ ```
14
+
15
+ The release command validates a complete Nextop app package, creates a zip, writes immutable `release.json`, and writes mutable `latest.json`.
16
+
17
+ The catalog command merges one or more release files into `nextop.app.catalog.v1`.
18
+ Pass `--existing-catalog` to preserve existing catalog apps and update only the
19
+ apps represented by the release files. With `--existing-catalog`, release files
20
+ are optional, which allows rewriting an existing catalog without changing its app
21
+ set.
22
+
23
+ The verify command checks release and catalog metadata against the referenced
24
+ artifact downloads. When both `--catalog-file` and `--release-file` are passed,
25
+ catalog entries for those apps must exactly match the latest release metadata
26
+ before artifact SHA-256 and size checks run.
@@ -0,0 +1,163 @@
1
+ #!/usr/bin/env node
2
+ import { mkdir, readFile, writeFile } from "node:fs/promises";
3
+ import { pathToFileURL } from "node:url";
4
+ import path from "node:path";
5
+
6
+ import {
7
+ releaseToCatalogApp,
8
+ validateRelease
9
+ } from "./build-nextop-app-release.mjs";
10
+
11
+ const catalogSchemaVersion = "nextop.app.catalog.v1";
12
+
13
+ export async function buildNextopAppCatalog(options) {
14
+ const existingCatalogPath = options.existingCatalogPath
15
+ ? path.resolve(String(options.existingCatalogPath))
16
+ : null;
17
+ const releaseFiles = normalizeReleaseFiles(options.releaseFiles);
18
+ const outputPath = path.resolve(
19
+ options.outputPath
20
+ ? String(options.outputPath)
21
+ : "dist/nextop-app-catalog/catalog.json"
22
+ );
23
+
24
+ const seenAppIDs = new Set();
25
+ const seenReleaseAppIDs = new Set();
26
+ const appsByID = new Map();
27
+
28
+ if (existingCatalogPath) {
29
+ const existingCatalog = JSON.parse(
30
+ await readFile(existingCatalogPath, "utf8")
31
+ );
32
+ validateCatalog(existingCatalog);
33
+ for (const app of existingCatalog.apps) {
34
+ const appID = app.manifest.appId;
35
+ if (seenAppIDs.has(appID)) {
36
+ throw new Error(`duplicate catalog appId ${appID}`);
37
+ }
38
+ seenAppIDs.add(appID);
39
+ appsByID.set(appID, app);
40
+ }
41
+ }
42
+
43
+ for (const releaseFile of releaseFiles) {
44
+ const release = JSON.parse(await readFile(releaseFile, "utf8"));
45
+ validateRelease(release);
46
+ if (seenReleaseAppIDs.has(release.appId)) {
47
+ throw new Error(`duplicate release appId ${release.appId}`);
48
+ }
49
+ seenReleaseAppIDs.add(release.appId);
50
+ if (!seenAppIDs.has(release.appId)) {
51
+ seenAppIDs.add(release.appId);
52
+ }
53
+ appsByID.set(release.appId, releaseToCatalogApp(release));
54
+ }
55
+
56
+ if (appsByID.size === 0) {
57
+ throw new Error(
58
+ "at least one release file or existing catalog app is required"
59
+ );
60
+ }
61
+
62
+ const apps = [...appsByID.values()];
63
+ apps.sort((left, right) =>
64
+ left.manifest.appId.localeCompare(right.manifest.appId)
65
+ );
66
+
67
+ const catalog = {
68
+ schemaVersion: catalogSchemaVersion,
69
+ apps
70
+ };
71
+
72
+ await mkdir(path.dirname(outputPath), { recursive: true });
73
+ await writeFile(outputPath, `${JSON.stringify(catalog, null, 2)}\n`);
74
+ return { outputPath, catalog };
75
+ }
76
+
77
+ function normalizeReleaseFiles(value) {
78
+ const files = Array.isArray(value)
79
+ ? value
80
+ : String(value ?? "")
81
+ .split(/[\n,]/)
82
+ .map((file) => file.trim())
83
+ .filter(Boolean);
84
+ return files.map((file) => path.resolve(file));
85
+ }
86
+
87
+ function validateCatalog(catalog) {
88
+ if (!catalog || typeof catalog !== "object") {
89
+ throw new Error("catalog must be an object");
90
+ }
91
+ if (catalog.schemaVersion !== catalogSchemaVersion) {
92
+ throw new Error(`catalog schemaVersion must be ${catalogSchemaVersion}`);
93
+ }
94
+ if (!Array.isArray(catalog.apps)) {
95
+ throw new Error("catalog apps must be an array");
96
+ }
97
+ for (const [index, app] of catalog.apps.entries()) {
98
+ if (!app || typeof app !== "object") {
99
+ throw new Error(`catalog apps[${index}] must be an object`);
100
+ }
101
+ if (
102
+ !app.manifest ||
103
+ typeof app.manifest !== "object" ||
104
+ typeof app.manifest.appId !== "string" ||
105
+ app.manifest.appId.trim() === ""
106
+ ) {
107
+ throw new Error(`catalog apps[${index}].manifest.appId is required`);
108
+ }
109
+ }
110
+ }
111
+
112
+ function parseArgs(argv) {
113
+ const result = {
114
+ releaseFiles: []
115
+ };
116
+ for (let index = 0; index < argv.length; index += 1) {
117
+ const arg = argv[index];
118
+ if (arg === "--release-file") {
119
+ const value = argv[index + 1];
120
+ if (!value || value.startsWith("--")) {
121
+ throw new Error("missing value for --release-file");
122
+ }
123
+ result.releaseFiles.push(value);
124
+ index += 1;
125
+ continue;
126
+ }
127
+ if (arg === "--existing-catalog") {
128
+ const value = argv[index + 1];
129
+ if (!value || value.startsWith("--")) {
130
+ throw new Error("missing value for --existing-catalog");
131
+ }
132
+ result.existingCatalogPath = value;
133
+ index += 1;
134
+ continue;
135
+ }
136
+ if (arg === "--output") {
137
+ const value = argv[index + 1];
138
+ if (!value || value.startsWith("--")) {
139
+ throw new Error("missing value for --output");
140
+ }
141
+ result.outputPath = value;
142
+ index += 1;
143
+ continue;
144
+ }
145
+ throw new Error(`unexpected argument: ${arg}`);
146
+ }
147
+ return result;
148
+ }
149
+
150
+ export async function main() {
151
+ const result = await buildNextopAppCatalog(parseArgs(process.argv.slice(2)));
152
+ process.stdout.write(`${JSON.stringify(result.catalog, null, 2)}\n`);
153
+ }
154
+
155
+ if (
156
+ process.argv[1] &&
157
+ import.meta.url === pathToFileURL(process.argv[1]).href
158
+ ) {
159
+ main().catch((error) => {
160
+ console.error(error.message);
161
+ process.exitCode = 1;
162
+ });
163
+ }
@@ -0,0 +1,557 @@
1
+ #!/usr/bin/env node
2
+ import { spawnSync } from "node:child_process";
3
+ import { createHash } from "node:crypto";
4
+ import { pathToFileURL } from "node:url";
5
+ import { cp, mkdir, readFile, stat, writeFile } from "node:fs/promises";
6
+ import path from "node:path";
7
+
8
+ const manifestSchemaVersion = "nextop.app.manifest.v1";
9
+ const cliManifestSchemaVersion = "nextop.app.cli.v1";
10
+ const releaseSchemaVersion = "nextop.app.release.v1";
11
+
12
+ export async function buildNextopAppRelease(options) {
13
+ const appId = requireNonEmpty(options.appId, "appId");
14
+ requireSafePathSegment(appId, "appId");
15
+ const packageDir = path.resolve(
16
+ requireNonEmpty(options.packageDir, "packageDir")
17
+ );
18
+ const outputDir = path.resolve(
19
+ options.outputDir ? String(options.outputDir) : "dist/nextop-app-release"
20
+ );
21
+ const baseUrl = normalizeBaseUrl(requireNonEmpty(options.baseUrl, "baseUrl"));
22
+ const publishedAt =
23
+ options.publishedAt || new Date().toISOString().replace(/\.\d{3}Z$/, "Z");
24
+ const gitSha = options.gitSha || resolveGitSha();
25
+
26
+ const manifestPath = path.join(packageDir, "nextop.app.json");
27
+ const manifest = JSON.parse(await readFile(manifestPath, "utf8"));
28
+ validateManifest(manifest, manifestPath);
29
+ if (manifest.appId !== appId) {
30
+ throw new Error(
31
+ `appId mismatch: input ${appId} does not match manifest ${manifest.appId}`
32
+ );
33
+ }
34
+
35
+ const version = requireNonEmpty(
36
+ options.version || manifest.version,
37
+ "version"
38
+ );
39
+ requireSafePathSegment(version, "version");
40
+ manifest.version = version;
41
+ validateManifest(manifest, manifestPath);
42
+ await writeFile(manifestPath, `${JSON.stringify(manifest, null, 2)}\n`);
43
+
44
+ await requireExecutableFile(
45
+ path.join(packageDir, manifest.runtime.bootstrap)
46
+ );
47
+ await requireNonEmptyTextFile(path.join(packageDir, "AGENTS.md"));
48
+
49
+ const manifestIconPath = path.join(packageDir, manifest.icon.src);
50
+ await requireFile(manifestIconPath);
51
+ for (const locale of manifest.localizationInfo?.additionalLocales ?? []) {
52
+ await requireNonEmptyTextFile(path.join(packageDir, locale.file));
53
+ }
54
+ if (manifest.cli?.manifest) {
55
+ const cliManifestPath = path.join(packageDir, manifest.cli.manifest);
56
+ await requireFile(cliManifestPath);
57
+ validateCLIManifest(
58
+ JSON.parse(await readFile(cliManifestPath, "utf8")),
59
+ `${manifestPath}.cli.manifest`
60
+ );
61
+ }
62
+ const sourceIconPath = options.iconPath
63
+ ? path.resolve(String(options.iconPath))
64
+ : manifestIconPath;
65
+ await requireFile(sourceIconPath);
66
+
67
+ const releasePrefix = `apps/${appId}/${version}`;
68
+ const releaseURLPrefix = joinURLPathSegments("apps", appId, version);
69
+ const releaseDir = path.join(outputDir, releasePrefix);
70
+ await mkdir(releaseDir, { recursive: true });
71
+
72
+ const artifactName = `${appId}-${version}.zip`;
73
+ const artifactPath = path.join(releaseDir, artifactName);
74
+ createZip(packageDir, artifactPath);
75
+ const artifact = await fileDigestAndSize(artifactPath);
76
+
77
+ const iconName = path.basename(sourceIconPath);
78
+ const iconOutputPath = path.join(releaseDir, iconName);
79
+ await cp(sourceIconPath, iconOutputPath);
80
+
81
+ const releaseJson = {
82
+ schemaVersion: releaseSchemaVersion,
83
+ appId,
84
+ version,
85
+ name: manifest.name,
86
+ description: manifest.description,
87
+ manifest,
88
+ artifactUrl: `${baseUrl}/${releaseURLPrefix}/${encodeURLPathSegment(artifactName)}`,
89
+ artifactSha256: artifact.sha256,
90
+ artifactSizeBytes: artifact.size,
91
+ iconUrl: `${baseUrl}/${releaseURLPrefix}/${encodeURLPathSegment(iconName)}`,
92
+ publishedAt,
93
+ gitSha
94
+ };
95
+
96
+ await writeJson(path.join(releaseDir, "release.json"), releaseJson);
97
+ await mkdir(path.join(outputDir, "apps", appId), { recursive: true });
98
+ await writeJson(
99
+ path.join(outputDir, "apps", appId, "latest.json"),
100
+ releaseJson
101
+ );
102
+
103
+ return {
104
+ artifactPath,
105
+ latestJsonPath: path.join(outputDir, "apps", appId, "latest.json"),
106
+ releaseJsonPath: path.join(releaseDir, "release.json"),
107
+ release: releaseJson
108
+ };
109
+ }
110
+
111
+ export function validateManifest(manifest, sourceLabel = "manifest") {
112
+ if (!manifest || typeof manifest !== "object") {
113
+ throw new Error(`${sourceLabel} must be an object`);
114
+ }
115
+ for (const key of ["schemaVersion", "appId", "version", "name"]) {
116
+ requireManifestString(manifest, key, sourceLabel);
117
+ }
118
+ if (manifest.schemaVersion !== manifestSchemaVersion) {
119
+ throw new Error(
120
+ `${sourceLabel} schemaVersion must be ${manifestSchemaVersion}`
121
+ );
122
+ }
123
+ if (!manifest.icon || typeof manifest.icon !== "object") {
124
+ throw new Error(`${sourceLabel} icon is required`);
125
+ }
126
+ requireManifestString(manifest.icon, "type", `${sourceLabel}.icon`);
127
+ requireManifestString(manifest.icon, "src", `${sourceLabel}.icon`);
128
+ if (!isRelativePackagePath(manifest.icon.src)) {
129
+ throw new Error(`${sourceLabel} icon.src must be a relative package path`);
130
+ }
131
+ if (!manifest.runtime || typeof manifest.runtime !== "object") {
132
+ throw new Error(`${sourceLabel} runtime is required`);
133
+ }
134
+ requireManifestString(
135
+ manifest.runtime,
136
+ "bootstrap",
137
+ `${sourceLabel}.runtime`
138
+ );
139
+ requireManifestString(
140
+ manifest.runtime,
141
+ "healthcheckPath",
142
+ `${sourceLabel}.runtime`
143
+ );
144
+ if (!isRelativePackagePath(manifest.runtime.bootstrap)) {
145
+ throw new Error(
146
+ `${sourceLabel} runtime.bootstrap must be a relative package path`
147
+ );
148
+ }
149
+ if (!manifest.runtime.healthcheckPath.startsWith("/")) {
150
+ throw new Error(`${sourceLabel} runtime.healthcheckPath must start with /`);
151
+ }
152
+ validateManifestCLI(manifest.cli, sourceLabel);
153
+ validateLocalizationInfo(manifest.localizationInfo, sourceLabel);
154
+ }
155
+
156
+ function validateManifestCLI(cli, sourceLabel) {
157
+ if (cli === undefined) {
158
+ return;
159
+ }
160
+ if (!cli || typeof cli !== "object") {
161
+ throw new Error(`${sourceLabel} cli must be an object`);
162
+ }
163
+ const cliManifest = requireNonEmpty(
164
+ cli.manifest,
165
+ `${sourceLabel}.cli.manifest`
166
+ );
167
+ if (!isRelativePackagePath(cliManifest)) {
168
+ throw new Error(
169
+ `${sourceLabel}.cli.manifest must be a relative package path`
170
+ );
171
+ }
172
+ }
173
+
174
+ export function validateCLIManifest(manifest, sourceLabel = "cli manifest") {
175
+ if (!manifest || typeof manifest !== "object") {
176
+ throw new Error(`${sourceLabel} must be an object`);
177
+ }
178
+ if (manifest.schemaVersion !== cliManifestSchemaVersion) {
179
+ throw new Error(
180
+ `${sourceLabel} schemaVersion must be ${cliManifestSchemaVersion}`
181
+ );
182
+ }
183
+ requireCLISegment(manifest.scope, `${sourceLabel}.scope`);
184
+ if (!Array.isArray(manifest.commands) || manifest.commands.length === 0) {
185
+ throw new Error(`${sourceLabel}.commands must be a non-empty array`);
186
+ }
187
+ const seenPaths = new Set();
188
+ for (const [index, command] of manifest.commands.entries()) {
189
+ const label = `${sourceLabel}.commands[${index}]`;
190
+ validateCLICommand(command, label, manifest.scope, seenPaths);
191
+ }
192
+ }
193
+
194
+ function validateCLICommand(command, label, scope, seenPaths) {
195
+ if (!command || typeof command !== "object") {
196
+ throw new Error(`${label} must be an object`);
197
+ }
198
+ if (!Array.isArray(command.path) || command.path.length === 0) {
199
+ throw new Error(`${label}.path must be a non-empty array`);
200
+ }
201
+ if (command.path[0] === scope) {
202
+ throw new Error(`${label}.path must not repeat scope`);
203
+ }
204
+ for (const [index, segment] of command.path.entries()) {
205
+ requireCLISegment(segment, `${label}.path[${index}]`);
206
+ }
207
+ const pathKey = command.path.join(".");
208
+ if (seenPaths.has(pathKey)) {
209
+ throw new Error(`${label}.path must be unique`);
210
+ }
211
+ seenPaths.add(pathKey);
212
+ requireNonEmpty(command.summary, `${label}.summary`);
213
+ validateCLIInputSchema(command.inputSchema, `${label}.inputSchema`);
214
+ validateCLIOutput(command.output, `${label}.output`);
215
+ validateCLIHandler(command.handler, `${label}.handler`);
216
+ }
217
+
218
+ function validateCLIInputSchema(schema, label) {
219
+ if (schema === undefined) {
220
+ return;
221
+ }
222
+ if (!schema || typeof schema !== "object" || Array.isArray(schema)) {
223
+ throw new Error(`${label} must be an object`);
224
+ }
225
+ if (schema.type !== "object") {
226
+ throw new Error(`${label}.type must be object`);
227
+ }
228
+ if (
229
+ !schema.properties ||
230
+ typeof schema.properties !== "object" ||
231
+ Array.isArray(schema.properties)
232
+ ) {
233
+ throw new Error(`${label}.properties must be an object`);
234
+ }
235
+ for (const [name, property] of Object.entries(schema.properties)) {
236
+ requireCLISegment(name, `${label}.properties key`);
237
+ if (!property || typeof property !== "object" || Array.isArray(property)) {
238
+ throw new Error(`${label}.properties.${name} must be an object`);
239
+ }
240
+ if (!["string", "boolean", "integer"].includes(property.type)) {
241
+ throw new Error(
242
+ `${label}.properties.${name}.type must be string, boolean, or integer`
243
+ );
244
+ }
245
+ for (const key of Object.keys(property)) {
246
+ if (!["type", "description"].includes(key)) {
247
+ throw new Error(`${label}.properties.${name}.${key} is not supported`);
248
+ }
249
+ }
250
+ }
251
+ const required = schema.required ?? [];
252
+ if (!Array.isArray(required)) {
253
+ throw new Error(`${label}.required must be an array`);
254
+ }
255
+ for (const name of required) {
256
+ if (typeof name !== "string" || !Object.hasOwn(schema.properties, name)) {
257
+ throw new Error(
258
+ `${label}.required contains unknown property ${String(name)}`
259
+ );
260
+ }
261
+ }
262
+ for (const key of Object.keys(schema)) {
263
+ if (!["type", "properties", "required"].includes(key)) {
264
+ throw new Error(`${label}.${key} is not supported`);
265
+ }
266
+ }
267
+ }
268
+
269
+ function validateCLIOutput(output, label) {
270
+ if (!output || typeof output !== "object" || Array.isArray(output)) {
271
+ throw new Error(`${label} must be an object`);
272
+ }
273
+ if (!["json", "table"].includes(output.defaultMode)) {
274
+ throw new Error(`${label}.defaultMode must be json or table`);
275
+ }
276
+ if (output.defaultMode === "json" && output.json !== true) {
277
+ throw new Error(`${label}.json must be true when defaultMode is json`);
278
+ }
279
+ if (output.defaultMode === "table") {
280
+ if (
281
+ !output.table ||
282
+ !Array.isArray(output.table.columns) ||
283
+ output.table.columns.length === 0
284
+ ) {
285
+ throw new Error(
286
+ `${label}.table.columns must be a non-empty array when defaultMode is table`
287
+ );
288
+ }
289
+ for (const [index, column] of output.table.columns.entries()) {
290
+ requireCLISegment(column?.key, `${label}.table.columns[${index}].key`);
291
+ requireNonEmpty(column?.label, `${label}.table.columns[${index}].label`);
292
+ }
293
+ }
294
+ }
295
+
296
+ function validateCLIHandler(handler, label) {
297
+ if (!handler || typeof handler !== "object" || Array.isArray(handler)) {
298
+ throw new Error(`${label} must be an object`);
299
+ }
300
+ if (handler.kind !== "http") {
301
+ throw new Error(`${label}.kind must be http`);
302
+ }
303
+ if (handler.method !== "POST") {
304
+ throw new Error(`${label}.method must be POST`);
305
+ }
306
+ if (
307
+ typeof handler.path !== "string" ||
308
+ !handler.path.startsWith("/nextop/cli/")
309
+ ) {
310
+ throw new Error(`${label}.path must start with /nextop/cli/`);
311
+ }
312
+ const timeoutMs = handler.timeoutMs ?? 30000;
313
+ if (!Number.isInteger(timeoutMs) || timeoutMs < 1000 || timeoutMs > 300000) {
314
+ throw new Error(`${label}.timeoutMs must be between 1000 and 300000`);
315
+ }
316
+ }
317
+
318
+ function requireCLISegment(value, label) {
319
+ const text = requireNonEmpty(value, label);
320
+ if (
321
+ !/^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/.test(text) ||
322
+ text.startsWith("--")
323
+ ) {
324
+ throw new Error(
325
+ `${label} must contain lowercase letters, numbers, and hyphen only`
326
+ );
327
+ }
328
+ return text;
329
+ }
330
+
331
+ function validateLocalizationInfo(localizationInfo, sourceLabel) {
332
+ if (localizationInfo === undefined) {
333
+ return;
334
+ }
335
+ if (!localizationInfo || typeof localizationInfo !== "object") {
336
+ throw new Error(`${sourceLabel} localizationInfo must be an object`);
337
+ }
338
+
339
+ const defaultLocale = requireNonEmpty(
340
+ localizationInfo.defaultLocale,
341
+ `${sourceLabel}.localizationInfo.defaultLocale`
342
+ );
343
+ const seenLocales = new Set([defaultLocale.toLowerCase()]);
344
+ const additionalLocales = localizationInfo.additionalLocales ?? [];
345
+ if (!Array.isArray(additionalLocales)) {
346
+ throw new Error(
347
+ `${sourceLabel}.localizationInfo.additionalLocales must be an array`
348
+ );
349
+ }
350
+ for (const [index, entry] of additionalLocales.entries()) {
351
+ const label = `${sourceLabel}.localizationInfo.additionalLocales[${index}]`;
352
+ if (!entry || typeof entry !== "object") {
353
+ throw new Error(`${label} must be an object`);
354
+ }
355
+ const locale = requireNonEmpty(entry.locale, `${label}.locale`);
356
+ const localeKey = locale.toLowerCase();
357
+ if (seenLocales.has(localeKey)) {
358
+ throw new Error(`${label}.locale must be unique`);
359
+ }
360
+ seenLocales.add(localeKey);
361
+ const file = requireNonEmpty(entry.file, `${label}.file`);
362
+ if (!isRelativePackagePath(file)) {
363
+ throw new Error(`${label}.file must be a relative package path`);
364
+ }
365
+ }
366
+ }
367
+
368
+ export function releaseToCatalogApp(release) {
369
+ validateRelease(release);
370
+ return {
371
+ manifest: release.manifest,
372
+ distribution: {
373
+ kind: "remote",
374
+ artifactUrl: release.artifactUrl,
375
+ artifactSha256: release.artifactSha256,
376
+ iconUrl: release.iconUrl
377
+ }
378
+ };
379
+ }
380
+
381
+ export function validateRelease(release) {
382
+ if (!release || typeof release !== "object") {
383
+ throw new Error("release must be an object");
384
+ }
385
+ if (release.schemaVersion !== releaseSchemaVersion) {
386
+ throw new Error(`release schemaVersion must be ${releaseSchemaVersion}`);
387
+ }
388
+ for (const key of [
389
+ "appId",
390
+ "version",
391
+ "artifactUrl",
392
+ "artifactSha256",
393
+ "iconUrl"
394
+ ]) {
395
+ requireManifestString(release, key, "release");
396
+ }
397
+ validateManifest(release.manifest, "release.manifest");
398
+ if (release.manifest.appId !== release.appId) {
399
+ throw new Error("release manifest.appId must match release appId");
400
+ }
401
+ if (release.manifest.version !== release.version) {
402
+ throw new Error("release manifest.version must match release version");
403
+ }
404
+ if (!/^[a-f0-9]{64}$/i.test(release.artifactSha256)) {
405
+ throw new Error("release artifactSha256 must be a sha256 hex digest");
406
+ }
407
+ if (
408
+ !Number.isSafeInteger(release.artifactSizeBytes) ||
409
+ release.artifactSizeBytes <= 0
410
+ ) {
411
+ throw new Error("release artifactSizeBytes must be a positive integer");
412
+ }
413
+ }
414
+
415
+ function createZip(packageDir, artifactPath) {
416
+ const result = spawnSync("zip", ["-qr", artifactPath, "."], {
417
+ cwd: packageDir,
418
+ encoding: "utf8"
419
+ });
420
+ if (result.error) {
421
+ throw result.error;
422
+ }
423
+ if (result.status !== 0) {
424
+ throw new Error(result.stderr || `zip exited with status ${result.status}`);
425
+ }
426
+ }
427
+
428
+ async function fileDigestAndSize(filePath) {
429
+ const data = await readFile(filePath);
430
+ return {
431
+ sha256: createHash("sha256").update(data).digest("hex"),
432
+ size: data.length
433
+ };
434
+ }
435
+
436
+ async function requireFile(filePath) {
437
+ const fileStat = await stat(filePath).catch((error) => {
438
+ throw new Error(`required file missing: ${filePath}: ${error.message}`);
439
+ });
440
+ if (!fileStat.isFile()) {
441
+ throw new Error(`required path is not a file: ${filePath}`);
442
+ }
443
+ if (fileStat.size === 0) {
444
+ throw new Error(`required file is empty: ${filePath}`);
445
+ }
446
+ }
447
+
448
+ async function requireNonEmptyTextFile(filePath) {
449
+ const data = await readFile(filePath, "utf8").catch((error) => {
450
+ throw new Error(`required file missing: ${filePath}: ${error.message}`);
451
+ });
452
+ if (data.trim() === "") {
453
+ throw new Error(`required file is empty: ${filePath}`);
454
+ }
455
+ }
456
+
457
+ async function requireExecutableFile(filePath) {
458
+ const fileStat = await stat(filePath).catch((error) => {
459
+ throw new Error(`required file missing: ${filePath}: ${error.message}`);
460
+ });
461
+ if (!fileStat.isFile()) {
462
+ throw new Error(`required path is not a file: ${filePath}`);
463
+ }
464
+ if (fileStat.mode & 0o111) {
465
+ return;
466
+ }
467
+ throw new Error(`required file is not executable: ${filePath}`);
468
+ }
469
+
470
+ function requireManifestString(target, key, label) {
471
+ requireNonEmpty(target[key], `${label}.${key}`);
472
+ }
473
+
474
+ function requireNonEmpty(value, label) {
475
+ const text = String(value ?? "").trim();
476
+ if (text === "") {
477
+ throw new Error(`${label} is required`);
478
+ }
479
+ return text;
480
+ }
481
+
482
+ function requireSafePathSegment(value, label) {
483
+ if (!/^[A-Za-z0-9._+-]+$/.test(value)) {
484
+ throw new Error(
485
+ `${label} must use only letters, digits, dot, underscore, plus, or dash`
486
+ );
487
+ }
488
+ }
489
+
490
+ function isRelativePackagePath(value) {
491
+ const text = String(value ?? "").trim();
492
+ if (text === "" || path.isAbsolute(text) || text.startsWith("\\")) {
493
+ return false;
494
+ }
495
+ return !text.split(/[\\/]+/).includes("..");
496
+ }
497
+
498
+ function normalizeBaseUrl(value) {
499
+ return String(value).trim().replace(/\/+$/, "");
500
+ }
501
+
502
+ function joinURLPathSegments(...segments) {
503
+ return segments.map((segment) => encodeURLPathSegment(segment)).join("/");
504
+ }
505
+
506
+ function encodeURLPathSegment(value) {
507
+ return encodeURIComponent(String(value));
508
+ }
509
+
510
+ function resolveGitSha() {
511
+ const result = spawnSync("git", ["rev-parse", "HEAD"], {
512
+ encoding: "utf8"
513
+ });
514
+ if (result.status !== 0) {
515
+ return "";
516
+ }
517
+ return result.stdout.trim();
518
+ }
519
+
520
+ async function writeJson(filePath, value) {
521
+ await writeFile(filePath, `${JSON.stringify(value, null, 2)}\n`);
522
+ }
523
+
524
+ function parseArgs(argv) {
525
+ const result = {};
526
+ for (let index = 0; index < argv.length; index += 1) {
527
+ const arg = argv[index];
528
+ if (!arg.startsWith("--")) {
529
+ throw new Error(`unexpected argument: ${arg}`);
530
+ }
531
+ const key = arg
532
+ .slice(2)
533
+ .replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
534
+ const value = argv[index + 1];
535
+ if (!value || value.startsWith("--")) {
536
+ throw new Error(`missing value for ${arg}`);
537
+ }
538
+ result[key] = value;
539
+ index += 1;
540
+ }
541
+ return result;
542
+ }
543
+
544
+ export async function main() {
545
+ const result = await buildNextopAppRelease(parseArgs(process.argv.slice(2)));
546
+ process.stdout.write(`${JSON.stringify(result.release, null, 2)}\n`);
547
+ }
548
+
549
+ if (
550
+ process.argv[1] &&
551
+ import.meta.url === pathToFileURL(process.argv[1]).href
552
+ ) {
553
+ main().catch((error) => {
554
+ console.error(error.message);
555
+ process.exitCode = 1;
556
+ });
557
+ }
@@ -0,0 +1,310 @@
1
+ #!/usr/bin/env node
2
+ import { createHash } from "node:crypto";
3
+ import { createReadStream } from "node:fs";
4
+ import { readFile } from "node:fs/promises";
5
+ import path from "node:path";
6
+ import { fileURLToPath, pathToFileURL } from "node:url";
7
+
8
+ import { validateRelease } from "./build-nextop-app-release.mjs";
9
+
10
+ const catalogSchemaVersion = "nextop.app.catalog.v1";
11
+
12
+ export async function verifyNextopAppReleaseArtifacts(options) {
13
+ const releaseFiles = normalizeFiles(options.releaseFiles);
14
+ const catalogFile = options.catalogFile
15
+ ? path.resolve(String(options.catalogFile))
16
+ : null;
17
+ const verifyArtifacts = options.verifyArtifacts !== false;
18
+
19
+ if (releaseFiles.length === 0 && !catalogFile) {
20
+ throw new Error(
21
+ "at least one --release-file or --catalog-file is required"
22
+ );
23
+ }
24
+
25
+ const releases = [];
26
+ const releasesByAppID = new Map();
27
+ for (const releaseFile of releaseFiles) {
28
+ const release = JSON.parse(await readFile(releaseFile, "utf8"));
29
+ validateRelease(release);
30
+ if (releasesByAppID.has(release.appId)) {
31
+ throw new Error(`duplicate release appId ${release.appId}`);
32
+ }
33
+ releases.push(release);
34
+ releasesByAppID.set(release.appId, release);
35
+ }
36
+
37
+ const checks = [];
38
+ for (const release of releases) {
39
+ checks.push({
40
+ appId: release.appId,
41
+ artifactUrl: release.artifactUrl,
42
+ artifactSha256: release.artifactSha256,
43
+ artifactSizeBytes: release.artifactSizeBytes,
44
+ source: `release ${release.appId}`
45
+ });
46
+ }
47
+
48
+ if (catalogFile) {
49
+ const catalog = JSON.parse(await readFile(catalogFile, "utf8"));
50
+ validateCatalog(catalog);
51
+ const seenCatalogAppIDs = new Set();
52
+ for (const app of catalog.apps) {
53
+ const appId = app.manifest.appId;
54
+ if (seenCatalogAppIDs.has(appId)) {
55
+ throw new Error(`duplicate catalog appId ${appId}`);
56
+ }
57
+ seenCatalogAppIDs.add(appId);
58
+ const distribution = app.distribution;
59
+ if (!distribution || distribution.kind !== "remote") {
60
+ throw new Error(
61
+ `catalog app ${appId} distribution.kind must be remote`
62
+ );
63
+ }
64
+ for (const key of ["artifactUrl", "artifactSha256", "iconUrl"]) {
65
+ if (
66
+ typeof distribution[key] !== "string" ||
67
+ distribution[key].trim() === ""
68
+ ) {
69
+ throw new Error(
70
+ `catalog app ${appId} distribution.${key} is required`
71
+ );
72
+ }
73
+ }
74
+ requireSHA256Hex(
75
+ distribution.artifactSha256,
76
+ `catalog app ${appId} distribution.artifactSha256`
77
+ );
78
+
79
+ const release = releasesByAppID.get(appId);
80
+ if (release) {
81
+ assertCatalogMatchesRelease(app, release);
82
+ }
83
+
84
+ checks.push({
85
+ appId,
86
+ artifactUrl: distribution.artifactUrl,
87
+ artifactSha256: distribution.artifactSha256,
88
+ artifactSizeBytes: release?.artifactSizeBytes,
89
+ source: `catalog ${appId}`
90
+ });
91
+ }
92
+ }
93
+
94
+ if (verifyArtifacts) {
95
+ const artifactDigests = new Map();
96
+ for (const check of checks) {
97
+ let digest = artifactDigests.get(check.artifactUrl);
98
+ if (!digest) {
99
+ digest = await digestArtifact(check.artifactUrl);
100
+ artifactDigests.set(check.artifactUrl, digest);
101
+ }
102
+ if (digest.sha256 !== check.artifactSha256.toLowerCase()) {
103
+ throw new Error(
104
+ `${check.source} artifact sha256 mismatch: want ${check.artifactSha256} got ${digest.sha256}`
105
+ );
106
+ }
107
+ if (
108
+ Number.isSafeInteger(check.artifactSizeBytes) &&
109
+ digest.size !== check.artifactSizeBytes
110
+ ) {
111
+ throw new Error(
112
+ `${check.source} artifact size mismatch: want ${check.artifactSizeBytes} got ${digest.size}`
113
+ );
114
+ }
115
+ }
116
+ }
117
+
118
+ return {
119
+ catalogFile,
120
+ releaseFiles,
121
+ checkedArtifactCount: verifyArtifacts
122
+ ? new Set(checks.map((check) => check.artifactUrl)).size
123
+ : 0
124
+ };
125
+ }
126
+
127
+ function assertCatalogMatchesRelease(app, release) {
128
+ const appId = release.appId;
129
+ const distribution = app.distribution;
130
+ if (app.manifest.version !== release.version) {
131
+ throw new Error(
132
+ `catalog app ${appId} manifest.version must match release version`
133
+ );
134
+ }
135
+ if (distribution.artifactUrl !== release.artifactUrl) {
136
+ throw new Error(
137
+ `catalog app ${appId} artifactUrl must match latest release metadata`
138
+ );
139
+ }
140
+ if (distribution.artifactSha256 !== release.artifactSha256) {
141
+ throw new Error(
142
+ `catalog app ${appId} artifactSha256 must match latest release metadata`
143
+ );
144
+ }
145
+ if (distribution.iconUrl !== release.iconUrl) {
146
+ throw new Error(
147
+ `catalog app ${appId} iconUrl must match latest release metadata`
148
+ );
149
+ }
150
+ }
151
+
152
+ function validateCatalog(catalog) {
153
+ if (!catalog || typeof catalog !== "object") {
154
+ throw new Error("catalog must be an object");
155
+ }
156
+ if (catalog.schemaVersion !== catalogSchemaVersion) {
157
+ throw new Error(`catalog schemaVersion must be ${catalogSchemaVersion}`);
158
+ }
159
+ if (!Array.isArray(catalog.apps)) {
160
+ throw new Error("catalog apps must be an array");
161
+ }
162
+ for (const [index, app] of catalog.apps.entries()) {
163
+ if (!app || typeof app !== "object") {
164
+ throw new Error(`catalog apps[${index}] must be an object`);
165
+ }
166
+ if (
167
+ !app.manifest ||
168
+ typeof app.manifest !== "object" ||
169
+ typeof app.manifest.appId !== "string" ||
170
+ app.manifest.appId.trim() === ""
171
+ ) {
172
+ throw new Error(`catalog apps[${index}].manifest.appId is required`);
173
+ }
174
+ }
175
+ }
176
+
177
+ async function digestArtifact(artifactUrl) {
178
+ const url = String(artifactUrl).trim();
179
+ if (url.startsWith("http://") || url.startsWith("https://")) {
180
+ return digestHTTPArtifact(url);
181
+ }
182
+ if (url.startsWith("file://")) {
183
+ return digestFileArtifact(fileURLToPath(url));
184
+ }
185
+ return digestFileArtifact(path.resolve(url));
186
+ }
187
+
188
+ async function digestHTTPArtifact(url) {
189
+ let lastError;
190
+ for (let attempt = 1; attempt <= 3; attempt += 1) {
191
+ try {
192
+ return await digestHTTPArtifactOnce(url);
193
+ } catch (error) {
194
+ lastError = error;
195
+ if (attempt < 3) {
196
+ await delay(1000 * attempt);
197
+ }
198
+ }
199
+ }
200
+ throw lastError;
201
+ }
202
+
203
+ async function digestHTTPArtifactOnce(url) {
204
+ const response = await fetch(url);
205
+ if (!response.ok || !response.body) {
206
+ throw new Error(
207
+ `download artifact failed: ${url}: HTTP ${response.status}`
208
+ );
209
+ }
210
+ const hash = createHash("sha256");
211
+ let size = 0;
212
+ for await (const chunk of response.body) {
213
+ const buffer = Buffer.from(chunk);
214
+ hash.update(buffer);
215
+ size += buffer.length;
216
+ }
217
+ return {
218
+ sha256: hash.digest("hex"),
219
+ size
220
+ };
221
+ }
222
+
223
+ function delay(ms) {
224
+ return new Promise((resolve) => setTimeout(resolve, ms));
225
+ }
226
+
227
+ async function digestFileArtifact(filePath) {
228
+ const hash = createHash("sha256");
229
+ let size = 0;
230
+ await new Promise((resolve, reject) => {
231
+ const stream = createReadStream(filePath);
232
+ stream.on("data", (chunk) => {
233
+ hash.update(chunk);
234
+ size += chunk.length;
235
+ });
236
+ stream.on("error", reject);
237
+ stream.on("end", resolve);
238
+ });
239
+ return {
240
+ sha256: hash.digest("hex"),
241
+ size
242
+ };
243
+ }
244
+
245
+ function normalizeFiles(value) {
246
+ const files = Array.isArray(value)
247
+ ? value
248
+ : String(value ?? "")
249
+ .split(/[\n,]/)
250
+ .map((file) => file.trim())
251
+ .filter(Boolean);
252
+ return files.map((file) => path.resolve(file));
253
+ }
254
+
255
+ function requireSHA256Hex(value, label) {
256
+ if (!/^[a-f0-9]{64}$/i.test(String(value ?? ""))) {
257
+ throw new Error(`${label} must be a sha256 hex digest`);
258
+ }
259
+ }
260
+
261
+ function parseArgs(argv) {
262
+ const result = {
263
+ releaseFiles: [],
264
+ verifyArtifacts: true
265
+ };
266
+ for (let index = 0; index < argv.length; index += 1) {
267
+ const arg = argv[index];
268
+ if (arg === "--release-file") {
269
+ const value = argv[index + 1];
270
+ if (!value || value.startsWith("--")) {
271
+ throw new Error("missing value for --release-file");
272
+ }
273
+ result.releaseFiles.push(value);
274
+ index += 1;
275
+ continue;
276
+ }
277
+ if (arg === "--catalog-file") {
278
+ const value = argv[index + 1];
279
+ if (!value || value.startsWith("--")) {
280
+ throw new Error("missing value for --catalog-file");
281
+ }
282
+ result.catalogFile = value;
283
+ index += 1;
284
+ continue;
285
+ }
286
+ if (arg === "--skip-artifact-download") {
287
+ result.verifyArtifacts = false;
288
+ continue;
289
+ }
290
+ throw new Error(`unexpected argument: ${arg}`);
291
+ }
292
+ return result;
293
+ }
294
+
295
+ export async function main() {
296
+ const result = await verifyNextopAppReleaseArtifacts(
297
+ parseArgs(process.argv.slice(2))
298
+ );
299
+ process.stdout.write(`${JSON.stringify(result, null, 2)}\n`);
300
+ }
301
+
302
+ if (
303
+ process.argv[1] &&
304
+ import.meta.url === pathToFileURL(process.argv[1]).href
305
+ ) {
306
+ main().catch((error) => {
307
+ console.error(error.message);
308
+ process.exitCode = 1;
309
+ });
310
+ }
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "@tutti-os/app-release-tools",
3
+ "version": "0.0.1",
4
+ "private": false,
5
+ "type": "module",
6
+ "bin": {
7
+ "build-nextop-app-release": "./bin/build-nextop-app-release.mjs",
8
+ "build-nextop-app-catalog": "./bin/build-nextop-app-catalog.mjs",
9
+ "verify-nextop-app-release-artifacts": "./bin/verify-nextop-app-release-artifacts.mjs"
10
+ },
11
+ "exports": {
12
+ "./build-nextop-app-release": "./bin/build-nextop-app-release.mjs",
13
+ "./build-nextop-app-catalog": "./bin/build-nextop-app-catalog.mjs",
14
+ "./verify-nextop-app-release-artifacts": "./bin/verify-nextop-app-release-artifacts.mjs"
15
+ },
16
+ "files": [
17
+ "bin",
18
+ "README.md"
19
+ ],
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "git+https://github.com/tutti-os/tutti.git",
23
+ "directory": "packages/workspace/app-release-tools"
24
+ },
25
+ "publishConfig": {
26
+ "access": "public"
27
+ },
28
+ "scripts": {
29
+ "build": "node -e \"\"",
30
+ "test": "node --test ../../../tools/scripts/build-nextop-app-release.test.mjs"
31
+ }
32
+ }