juggernaut-bedrock 4.1.0 → 4.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/index.js +86 -0
  2. package/package.json +14 -4
  3. package/install.js +0 -204
package/index.js ADDED
@@ -0,0 +1,86 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+
4
+ var path = require("path");
5
+ var child_process = require("child_process");
6
+ var fs = require("fs");
7
+
8
+ var PACKAGES_DIR = path.join(__dirname, "packages");
9
+
10
+ var PLATFORM_MAP = {
11
+ "linux-x64": "juggernaut-bedrock-linux-x64",
12
+ "linux-arm64": "juggernaut-bedrock-linux-arm64",
13
+ "darwin-x64": "juggernaut-bedrock-darwin-x64",
14
+ "darwin-arm64": "juggernaut-bedrock-darwin-arm64",
15
+ "win32-x64": "juggernaut-bedrock-win32-x64"
16
+ };
17
+
18
+ var VALID_PACKAGES = [
19
+ "juggernaut-bedrock-linux-x64",
20
+ "juggernaut-bedrock-linux-arm64",
21
+ "juggernaut-bedrock-darwin-x64",
22
+ "juggernaut-bedrock-darwin-arm64",
23
+ "juggernaut-bedrock-win32-x64"
24
+ ];
25
+
26
+ /**
27
+ * @param {string} platform
28
+ * @param {string} arch
29
+ * @returns {string|void}
30
+ */
31
+ function getPlatformPackage(platform, arch) {
32
+ return PLATFORM_MAP[platform + "-" + arch] || void 0;
33
+ }
34
+
35
+ function containsPackage(pkgName) {
36
+ for (var i = 0; i < VALID_PACKAGES.length; i++) {
37
+ if (VALID_PACKAGES[i] === pkgName) {
38
+ return true;
39
+ }
40
+ }
41
+ return false;
42
+ }
43
+
44
+ /**
45
+ * @param {string} pkgName
46
+ * @param {string} platform
47
+ * @returns {string}
48
+ */
49
+ function getBinaryPath(pkgName, platform) {
50
+ if (!containsPackage(pkgName)) {
51
+ throw new Error("unexpected package name: " + pkgName);
52
+ }
53
+ var binaryName = platform === "win32" ? "juggernaut.exe" : "juggernaut";
54
+ return path.join(PACKAGES_DIR, pkgName, "bin", binaryName); // nosemgrep: javascript.lang.security.audit.path-traversal.path-join-resolve-traversal.path-join-resolve-traversal
55
+ }
56
+
57
+ if (require.main === module) {
58
+ var pkg = getPlatformPackage(process.platform, process.arch);
59
+ if (!pkg) {
60
+ process.stderr.write(
61
+ "juggernaut-bedrock: unsupported platform " + process.platform + "/" + process.arch + "\n" +
62
+ "Please file an issue: https://github.com/jpvelasco/juggernaut/issues\n"
63
+ );
64
+ process.exit(1);
65
+ }
66
+
67
+ var bin = getBinaryPath(pkg, process.platform);
68
+ // nosemgrep: javascript_pathtraversal_rule-non-literal-fs-filename, javascript.lang.security.audit.detect-non-literal-fs-filename
69
+ if (!fs.existsSync(bin)) {
70
+ process.stderr.write(
71
+ "juggernaut-bedrock: binary not found at " + bin + "\n" +
72
+ "Try reinstalling: npm install -g juggernaut-bedrock\n" +
73
+ "If the problem persists, file an issue: https://github.com/jpvelasco/juggernaut/issues\n"
74
+ );
75
+ process.exit(1);
76
+ }
77
+
78
+ // nosemgrep: javascript.lang.security.detect-child-process, javascript_exec_rule-child-process
79
+ var result = child_process.spawnSync(bin, process.argv.slice(2), {
80
+ stdio: "inherit",
81
+ env: process.env
82
+ });
83
+ process.exit(result.status !== null ? result.status : 1);
84
+ }
85
+
86
+ module.exports = { getPlatformPackage: getPlatformPackage, getBinaryPath: getBinaryPath };
package/package.json CHANGED
@@ -1,12 +1,19 @@
1
1
  {
2
2
  "name": "juggernaut-bedrock",
3
- "version": "4.1.0",
3
+ "version": "4.2.2",
4
4
  "description": "Route Claude Code through Amazon Bedrock in one command — IAM, SSO, or API key. Cross-platform CLI for GenAI developers.",
5
5
  "bin": {
6
- "juggernaut": "./bin/juggernaut"
6
+ "juggernaut": "./index.js"
7
7
  },
8
8
  "scripts": {
9
- "postinstall": "node install.js"
9
+ "test": "node --test index.test.js"
10
+ },
11
+ "optionalDependencies": {
12
+ "juggernaut-bedrock-linux-x64": "4.2.2",
13
+ "juggernaut-bedrock-linux-arm64": "4.2.2",
14
+ "juggernaut-bedrock-darwin-x64": "4.2.2",
15
+ "juggernaut-bedrock-darwin-arm64": "4.2.2",
16
+ "juggernaut-bedrock-win32-x64": "4.2.2"
10
17
  },
11
18
  "os": [
12
19
  "darwin",
@@ -33,10 +40,13 @@
33
40
  "sso",
34
41
  "developer-tools"
35
42
  ],
43
+ "engines": {
44
+ "node": ">=20.0.0"
45
+ },
36
46
  "license": "MIT",
37
47
  "repository": {
38
48
  "type": "git",
39
- "url": "https://github.com/jpvelasco/juggernaut"
49
+ "url": "git+https://github.com/jpvelasco/juggernaut.git"
40
50
  },
41
51
  "bugs": {
42
52
  "url": "https://github.com/jpvelasco/juggernaut/issues"
package/install.js DELETED
@@ -1,204 +0,0 @@
1
- "use strict";
2
-
3
- const https = require("https");
4
- const fs = require("fs");
5
- const path = require("path");
6
- const os = require("os");
7
- const crypto = require("crypto");
8
- const { execFile, execFileSync } = require("child_process");
9
- const { promisify } = require("util");
10
-
11
- const execFileAsync = promisify(execFile);
12
-
13
- const REPO = "jpvelasco/juggernaut";
14
- const PACKAGE_DIR = __dirname;
15
- const BIN_DIR = path.join(PACKAGE_DIR, "bin");
16
- const TMP_PREFIX = path.join(os.tmpdir(), "juggernaut-install-");
17
- const ARCHIVE_TAR = "archive.tar.gz";
18
- const ARCHIVE_ZIP = "archive.zip";
19
- const BIN_NAME = "juggernaut";
20
- const ALLOWED_HOSTS = new Set([
21
- "github.com",
22
- "api.github.com",
23
- "release-assets.githubusercontent.com"
24
- ]);
25
-
26
- function joinUnder(base, ...segments) {
27
- if (base.indexOf("\0") !== -1) {
28
- throw new Error("Invalid base path");
29
- }
30
- for (const seg of segments) {
31
- if (seg.indexOf("..") !== -1 || seg.indexOf("/") !== -1 || seg.indexOf("\\") !== -1) {
32
- throw new Error(`Invalid path segment: ${seg}`);
33
- }
34
- }
35
- const joined = path.join(base, ...segments);
36
- const normalBase = path.normalize(base) + path.sep;
37
- const normalJoined = path.normalize(joined);
38
- const compare = process.platform === "win32"
39
- ? (a, b) => a.toLowerCase().startsWith(b.toLowerCase())
40
- : (a, b) => a.startsWith(b);
41
- if (!compare(normalJoined, normalBase)) {
42
- const exactBase = process.platform === "win32"
43
- ? path.normalize(base).toLowerCase()
44
- : path.normalize(base);
45
- const exactJoined = process.platform === "win32"
46
- ? normalJoined.toLowerCase()
47
- : normalJoined;
48
- if (exactJoined !== exactBase) {
49
- throw new Error(`Path traversal detected: ${joined} is outside ${base}`);
50
- }
51
- }
52
- return normalJoined;
53
- }
54
-
55
- function getPlatform() {
56
- const osMap = { darwin: "darwin", linux: "linux", win32: "windows" };
57
- const archMap = { x64: "amd64", arm64: "arm64" };
58
- const p = osMap[process.platform];
59
- const a = archMap[process.arch];
60
- if (!p || !a) {
61
- throw new Error(`Unsupported platform: ${process.platform}/${process.arch}`);
62
- }
63
- return { os: p, arch: a, platform: `${p}_${a}` };
64
- }
65
-
66
- function httpsGetBuffer(url) {
67
- const parsed = new URL(url);
68
- if (!ALLOWED_HOSTS.has(parsed.hostname)) {
69
- throw new Error(`URL host not allowed: ${parsed.hostname}`);
70
- }
71
- return new Promise((resolve, reject) => {
72
- https
73
- .get(url, { headers: { "User-Agent": "juggernaut-npm-installer/1.0" } }, (res) => {
74
- if (res.statusCode === 301 || res.statusCode === 302) {
75
- const location = res.headers.location;
76
- const redirectParsed = new URL(location);
77
- if (!ALLOWED_HOSTS.has(redirectParsed.hostname)) {
78
- reject(new Error(`Redirect host not allowed: ${redirectParsed.hostname}`));
79
- return;
80
- }
81
- httpsGetBuffer(location).then(resolve).catch(reject);
82
- return;
83
- }
84
- const chunks = [];
85
- res.on("data", (chunk) => chunks.push(chunk));
86
- res.on("end", () => resolve(Buffer.concat(chunks)));
87
- res.on("error", reject);
88
- })
89
- .on("error", reject);
90
- });
91
- }
92
-
93
- async function getLatestVersion() {
94
- const data = await httpsGetBuffer(`https://api.github.com/repos/${REPO}/releases/latest`);
95
- const release = JSON.parse(data.toString());
96
- return release.tag_name.replace(/^v/, "");
97
- }
98
-
99
- function pickArchive(platform, checksumsText) {
100
- const tarArchive = `juggernaut_${platform}.tar.gz`;
101
- if (checksumsText.includes(tarArchive)) return { name: tarArchive, kind: "tar.gz" };
102
- const zipArchive = `juggernaut_${platform}.zip`;
103
- if (process.platform === "win32" && checksumsText.includes(zipArchive)) {
104
- return { name: zipArchive, kind: "zip" };
105
- }
106
- throw new Error(`No supported archive found in release checksums for ${platform}`);
107
- }
108
-
109
- function extractTarGz(archiveBuf) {
110
- const tmpDir = fs.mkdtempSync(TMP_PREFIX);
111
- const archivePath = joinUnder(tmpDir, ARCHIVE_TAR);
112
- const prevCwd = process.cwd();
113
- try {
114
- process.chdir(tmpDir);
115
- fs.writeFileSync(ARCHIVE_TAR, archiveBuf);
116
- process.chdir(PACKAGE_DIR);
117
- fs.mkdirSync("bin", { recursive: true });
118
- try {
119
- execFileSync("tar", ["-xzf", archivePath, "-C", BIN_DIR], { stdio: "pipe" });
120
- } catch (err) {
121
- if (err.code === "ENOENT") {
122
- throw new Error(
123
- "tar not found on PATH. On Windows, use Windows 10 version 1803 or later (includes tar.exe)."
124
- );
125
- }
126
- const detail = err.stderr ? err.stderr.toString().trim() : err.message;
127
- throw new Error(`tar extraction failed: ${detail}`);
128
- }
129
- if (process.platform !== "win32") {
130
- process.chdir(BIN_DIR);
131
- if (fs.existsSync(BIN_NAME)) {
132
- fs.chmodSync(BIN_NAME, 0o700);
133
- }
134
- }
135
- } finally {
136
- process.chdir(prevCwd);
137
- fs.rmSync(tmpDir, { recursive: true, force: true });
138
- }
139
- }
140
-
141
- async function extractZip(archiveBuf) {
142
- const tmpDir = fs.mkdtempSync(TMP_PREFIX);
143
- const archivePath = joinUnder(tmpDir, ARCHIVE_ZIP);
144
- const prevCwd = process.cwd();
145
- try {
146
- process.chdir(tmpDir);
147
- fs.writeFileSync(ARCHIVE_ZIP, archiveBuf);
148
- process.chdir(PACKAGE_DIR);
149
- fs.mkdirSync("bin", { recursive: true });
150
- const script = [
151
- "$ErrorActionPreference = 'Stop'",
152
- `Expand-Archive -LiteralPath '${archivePath.replace(/'/g, "''")}' -DestinationPath '${BIN_DIR.replace(/'/g, "''")}' -Force`
153
- ].join("; ");
154
- try {
155
- await execFileAsync(
156
- "powershell",
157
- ["-NoProfile", "-NonInteractive", "-Command", script],
158
- { stdio: "pipe" }
159
- );
160
- } catch (err) {
161
- if (err.code === "ENOENT") {
162
- throw new Error(
163
- "PowerShell not found. PowerShell 5.0+ is required to extract archives on Windows."
164
- );
165
- }
166
- const detail = err.stderr ? err.stderr.toString().trim() : err.message;
167
- throw new Error(`ZIP extraction failed: ${detail}`);
168
- }
169
- } finally {
170
- process.chdir(prevCwd);
171
- fs.rmSync(tmpDir, { recursive: true, force: true });
172
- }
173
- }
174
-
175
- async function main() {
176
- const { platform } = getPlatform();
177
- const version = await getLatestVersion();
178
- const baseUrl = `https://github.com/${REPO}/releases/download/v${version}`;
179
- const checksumsBuf = await httpsGetBuffer(`${baseUrl}/checksums.txt`);
180
- const checksums = checksumsBuf.toString("utf8");
181
- const { name: archive, kind } = pickArchive(platform, checksums);
182
-
183
- console.log(`Downloading Juggernaut v${version} (${platform})...`);
184
- const archiveBuf = await httpsGetBuffer(`${baseUrl}/${archive}`);
185
-
186
- const line = checksums.split("\n").find((l) => l.includes(archive));
187
- if (!line) throw new Error(`Checksum not found for ${archive}`);
188
- const expected = line.trim().split(/\s+/)[0].toLowerCase();
189
- const actual = crypto.createHash("sha256").update(archiveBuf).digest("hex").toLowerCase();
190
- if (actual !== expected) {
191
- throw new Error(`Checksum mismatch for ${archive}\n expected: ${expected}\n got: ${actual}`);
192
- }
193
-
194
- if (kind === "zip") await extractZip(archiveBuf);
195
- else extractTarGz(archiveBuf);
196
-
197
- console.log(`Juggernaut v${version} installed successfully.`);
198
- console.log(`Run: juggernaut apply`);
199
- }
200
-
201
- main().catch((err) => {
202
- console.error("Installation failed:", err.message);
203
- process.exit(1);
204
- });