jso-protector 0.4.3 → 0.4.4

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 CHANGED
@@ -1,5 +1,23 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.4.4 - 2026-08-31
4
+
5
+ - **`javascriptobfuscator login` saves your credentials once, for every project
6
+ on the machine.** Getting a first protected build used to take about seven
7
+ steps: install, hit the error, find the site, register, verify email, locate
8
+ the dashboard, copy two values, work out two platform-specific environment
9
+ variable names, set them, and run again - then set them again in the next
10
+ shell. `login` opens the dashboard, takes the two values (the password is not
11
+ echoed), and stores them in `~/.jso-protector/credentials.json`.
12
+ - `javascriptobfuscator logout` removes them.
13
+ - Stored credentials are resolved **last**, after an explicit flag, a project
14
+ config and the environment variables, so no existing CI setup changes
15
+ behaviour.
16
+ - The missing-credential errors now name `login` as the fastest fix.
17
+ - The store is written 0600. That is real protection on POSIX; Windows does not
18
+ honour the mode, so there it is only as protected as your user profile - the
19
+ same position as `~/.npmrc`.
20
+
3
21
  ## 0.4.3 - 2026-08-30
4
22
 
5
23
  Error messages only. No behaviour changes.
package/README.md CHANGED
@@ -336,7 +336,25 @@ Keep billing, entitlement checks, plan limits, and API secrets on the server sid
336
336
 
337
337
  If the hosted API rejects a request, the CLI reports dashboard credential hints for authentication failures and account/plan/credit guidance for entitlement failures. API keys and passwords are redacted from error messages before they reach terminal logs.
338
338
 
339
- Set credentials from the dashboard:
339
+ ### Sign in once
340
+
341
+ ```bash
342
+ npx javascriptobfuscator login
343
+ ```
344
+
345
+ This opens the dashboard, takes the API Key and API Password (the password is
346
+ not echoed), and stores them in `~/.jso-protector/credentials.json` for every
347
+ project on the machine. `npx javascriptobfuscator logout` removes them.
348
+
349
+ The store is written `0600`. That is real protection on POSIX; Windows does not
350
+ honour the mode, so there the file is only as protected as your user profile
351
+ directory - the same position as `~/.npmrc`.
352
+
353
+ ### Or set them per shell
354
+
355
+ Stored credentials are read **last**, so an explicit flag, a project config, or
356
+ these environment variables always win - a CI setup is unaffected by whatever a
357
+ developer has logged in with locally.
340
358
 
341
359
  ```bash
342
360
  set JSO_API_KEY=base64-api-key-from-dashboard
@@ -898,6 +898,8 @@ Usage:
898
898
  jso-protector --payment-page-headers-from-har reports/checkout.har --payment-page-headers-baseline reports/payment-page-headers.baseline.json --payment-page-headers-output reports/payment-page-headers.json
899
899
  jso-protector --script-inventory-audit reports/payment-script-inventory.json --runtime-inventory-snapshot reports/runtime-inventory.json
900
900
  jso-protector --init
901
+ javascriptobfuscator login Sign in once and save credentials for this machine
902
+ javascriptobfuscator logout Remove the saved credentials
901
903
 
902
904
  Options:
903
905
  --config <file> Config file path. Supports JSON, CommonJS .cjs/.js, and ESM .mjs/.js files.
@@ -2340,11 +2342,23 @@ function mergeConfig(config, args = {}) {
2340
2342
  reservedNames: (args.reservedNames && args.reservedNames.length) ? args.reservedNames : config.reservedNames
2341
2343
  });
2342
2344
 
2345
+ // Credentials saved by `javascriptobfuscator login`. Deliberately LAST in the
2346
+ // chain: an explicit flag, a project config, or a CI environment variable must
2347
+ // always win over a developer's machine-wide login.
2348
+ let _stored;
2349
+ const storedCredentials = () => {
2350
+ if (_stored === undefined) {
2351
+ try { _stored = require("../credentials.js").readStored() || {}; }
2352
+ catch (err) { _stored = {}; }
2353
+ }
2354
+ return _stored;
2355
+ };
2356
+
2343
2357
  const merged = {
2344
2358
  mode: args.mode || config.mode || readEnv(["NODE_ENV"]) || null,
2345
2359
  endpoint: args.endpoint || config.endpoint || readEnv(["JSO_ENDPOINT", "JAVASCRIPT_OBFUSCATOR_ENDPOINT"]) || DEFAULT_ENDPOINT,
2346
- apiKey: resolveEnv(args.apiKey || config.apiKey || readEnv(["JSO_API_KEY", "JAVASCRIPT_OBFUSCATOR_API_KEY"]) || ""),
2347
- apiPassword: resolveEnv(args.apiPassword || config.apiPassword || readEnv(["JSO_API_PASSWORD", "JAVASCRIPT_OBFUSCATOR_API_PASSWORD"]) || ""),
2360
+ apiKey: resolveEnv(args.apiKey || config.apiKey || readEnv(["JSO_API_KEY", "JAVASCRIPT_OBFUSCATOR_API_KEY"]) || storedCredentials().apiKey || ""),
2361
+ apiPassword: resolveEnv(args.apiPassword || config.apiPassword || readEnv(["JSO_API_PASSWORD", "JAVASCRIPT_OBFUSCATOR_API_PASSWORD"]) || storedCredentials().apiPassword || ""),
2348
2362
  projectName: config.projectName || "jso-protector",
2349
2363
  preset,
2350
2364
  input: args.input || config.input || "dist",
@@ -4667,8 +4681,8 @@ function normalizeName(name) {
4667
4681
  }
4668
4682
 
4669
4683
  function assertReady(config) {
4670
- if (!config.apiKey) throw new Error("Missing API key. Create one free at https://javascriptobfuscator.com/dashboard/APIKeys.aspx, then set JSO_API_KEY (or apiKey in config). Setup guide: https://javascriptobfuscator.com/docs/npmcli.aspx");
4671
- if (!config.apiPassword) throw new Error("Missing API password. It is shown next to the key at https://javascriptobfuscator.com/dashboard/APIKeys.aspx, then set JSO_API_PASSWORD (or apiPassword in config).");
4684
+ if (!config.apiKey) throw new Error("Missing API key. Run `javascriptobfuscator login` to sign in and save credentials, or create a key at https://javascriptobfuscator.com/dashboard/APIKeys.aspx and set JSO_API_KEY.");
4685
+ if (!config.apiPassword) throw new Error("Missing API password. Run `javascriptobfuscator login` to sign in and save credentials, or copy it from https://javascriptobfuscator.com/dashboard/APIKeys.aspx and set JSO_API_PASSWORD.");
4672
4686
  }
4673
4687
 
4674
4688
  function sha256(value) {
@@ -4849,8 +4863,8 @@ async function runDoctor(config, args = {}) {
4849
4863
  const checks = [];
4850
4864
  const limitations = collectCompetitorLimitations(args.rawConfig && typeof args.rawConfig === "object" ? args.rawConfig : config, args);
4851
4865
  addDoctorCheck(checks, "endpoint", isValidUrl(config.endpoint), `Endpoint: ${config.endpoint}`, "Endpoint must be a valid URL.");
4852
- addDoctorCheck(checks, "apiKey", !!config.apiKey, "API key is present.", "Missing API key. Create one free at https://javascriptobfuscator.com/dashboard/APIKeys.aspx, then set JSO_API_KEY (or apiKey in config). Setup guide: https://javascriptobfuscator.com/docs/npmcli.aspx");
4853
- addDoctorCheck(checks, "apiPassword", !!config.apiPassword, "API password is present.", "Missing API password. It is shown next to the key at https://javascriptobfuscator.com/dashboard/APIKeys.aspx, then set JSO_API_PASSWORD (or apiPassword in config).");
4866
+ addDoctorCheck(checks, "apiKey", !!config.apiKey, "API key is present.", "Missing API key. Run `javascriptobfuscator login` to sign in and save credentials, or create a key at https://javascriptobfuscator.com/dashboard/APIKeys.aspx and set JSO_API_KEY.");
4867
+ addDoctorCheck(checks, "apiPassword", !!config.apiPassword, "API password is present.", "Missing API password. Run `javascriptobfuscator login` to sign in and save credentials, or copy it from https://javascriptobfuscator.com/dashboard/APIKeys.aspx and set JSO_API_PASSWORD.");
4854
4868
  addDoctorCheck(checks, "preset", true, `Preset: ${config.preset}`);
4855
4869
  addDoctorCheck(checks, "options", Object.keys(config.options || {}).length > 0, `${Object.keys(config.options || {}).length} option(s) enabled.`, "No protection options are enabled.");
4856
4870
 
@@ -7119,8 +7133,8 @@ function validateProtectionConfig(config, args = {}) {
7119
7133
  }
7120
7134
 
7121
7135
  addValidationCheck(checks, "endpoint", isValidUrl(resolved.endpoint) ? "ok" : "error", isValidUrl(resolved.endpoint) ? `Endpoint: ${resolved.endpoint}` : "Endpoint must be a valid HTTP or HTTPS URL.");
7122
- addValidationCheck(checks, "apiKey", resolved.apiKey ? "ok" : "error", resolved.apiKey ? "API key is present." : "Missing API key. Create one free at https://javascriptobfuscator.com/dashboard/APIKeys.aspx, then set JSO_API_KEY (or apiKey in config). Setup guide: https://javascriptobfuscator.com/docs/npmcli.aspx");
7123
- addValidationCheck(checks, "apiPassword", resolved.apiPassword ? "ok" : "error", resolved.apiPassword ? "API password is present." : "Missing API password. It is shown next to the key at https://javascriptobfuscator.com/dashboard/APIKeys.aspx, then set JSO_API_PASSWORD (or apiPassword in config).");
7136
+ addValidationCheck(checks, "apiKey", resolved.apiKey ? "ok" : "error", resolved.apiKey ? "API key is present." : "Missing API key. Run `javascriptobfuscator login` to sign in and save credentials, or create a key at https://javascriptobfuscator.com/dashboard/APIKeys.aspx and set JSO_API_KEY.");
7137
+ addValidationCheck(checks, "apiPassword", resolved.apiPassword ? "ok" : "error", resolved.apiPassword ? "API password is present." : "Missing API password. Run `javascriptobfuscator login` to sign in and save credentials, or copy it from https://javascriptobfuscator.com/dashboard/APIKeys.aspx and set JSO_API_PASSWORD.");
7124
7138
  addCredentialStorageValidation(checks, config, args);
7125
7139
  addValidationCheck(checks, "preset", "ok", `Preset: ${resolved.preset}`);
7126
7140
  addValidationCheck(checks, "paths", resolved.input && resolved.output ? "ok" : "error", resolved.input && resolved.output ? "Input and output paths are configured." : "Input and output paths must be configured.");
@@ -11814,6 +11828,19 @@ async function main(argv = process.argv.slice(2)) {
11814
11828
  // `jso ai <subcommand>` -- intercept before parseArgs so the AI
11815
11829
  // surface gets its own flag set without bloating the protect-side
11816
11830
  // parser. See ai-cli.js for the subcommand definitions.
11831
+ // `login` / `logout` -- a user-level credential store. Intercepted here for
11832
+ // the same reason as `ai`: it needs no protect-side flags. See credentials.js.
11833
+ if (argv.length > 0 && (argv[0] === "login" || argv[0] === "logout")) {
11834
+ const creds = require("../credentials.js");
11835
+ const code = argv[0] === "login" ? await creds.login(argv.slice(1)) : creds.logout();
11836
+ if (code !== 0) {
11837
+ const err = new Error("jso " + argv[0] + " exited with code " + code);
11838
+ err.exitCode = code;
11839
+ throw err;
11840
+ }
11841
+ return;
11842
+ }
11843
+
11817
11844
  if (argv.length > 0 && argv[0] === "ai") {
11818
11845
  const aiCli = require("../ai-cli.js");
11819
11846
  const code = await aiCli.main(argv.slice(1));
@@ -24,6 +24,7 @@ const REQUIRED_PACKED_FILES = [
24
24
  "bun.js",
25
25
  "browserify.d.ts",
26
26
  "browserify.js",
27
+ "credentials.js",
27
28
  "ci/azure-pipelines.yml",
28
29
  "ci/github-actions.yml",
29
30
  "ci/gitlab-ci.yml",
package/credentials.js ADDED
@@ -0,0 +1,158 @@
1
+ "use strict";
2
+
3
+ // User-level credential store for the CLI.
4
+ //
5
+ // Before this existed, credentials could only come from environment variables
6
+ // or a project-local jso.config.json. That meant a first-time user had to find
7
+ // the dashboard, copy two values, work out two platform-specific env var names,
8
+ // and set them again in every new shell. Measured against the competitor, whose
9
+ // package needs no account at all, that was the widest part of the gap we can
10
+ // actually close without changing the API's paid-only contract.
11
+ //
12
+ // The file is per-user and outside any project directory, so it is never
13
+ // committed by accident. It is written 0600, which is real protection on POSIX.
14
+ // On Windows the mode bits are not honoured - MEASURED, the file reports 666 -
15
+ // so there the secret is only as protected as the user profile directory's ACL.
16
+ // That is the same protection npm gives ~/.npmrc, and it is worth knowing rather
17
+ // than assuming the chmod did something.
18
+
19
+ const fs = require("fs");
20
+ const os = require("os");
21
+ const path = require("path");
22
+ const readline = require("readline");
23
+ const { spawn } = require("child_process");
24
+
25
+ const DASHBOARD_URL = "https://javascriptobfuscator.com/dashboard/APIKeys.aspx";
26
+ const STORE_DIR = path.join(os.homedir() || ".", ".jso-protector");
27
+ const STORE_FILE = path.join(STORE_DIR, "credentials.json");
28
+
29
+ function storePath() { return STORE_FILE; }
30
+
31
+ function readStored() {
32
+ try {
33
+ const raw = fs.readFileSync(STORE_FILE, "utf8");
34
+ const parsed = JSON.parse(raw);
35
+ if (!parsed || typeof parsed !== "object") return null;
36
+ const apiKey = typeof parsed.apiKey === "string" ? parsed.apiKey : "";
37
+ const apiPassword = typeof parsed.apiPassword === "string" ? parsed.apiPassword : "";
38
+ if (!apiKey || !apiPassword) return null;
39
+ return { apiKey, apiPassword, endpoint: typeof parsed.endpoint === "string" ? parsed.endpoint : "" };
40
+ } catch (err) {
41
+ // A missing store is the normal case, not an error. A corrupt one must not
42
+ // take down a build that has working credentials in the environment.
43
+ return null;
44
+ }
45
+ }
46
+
47
+ function writeStored(apiKey, apiPassword, endpoint) {
48
+ fs.mkdirSync(STORE_DIR, { recursive: true, mode: 0o700 });
49
+ const body = { apiKey, apiPassword };
50
+ if (endpoint) body.endpoint = endpoint;
51
+ // Write with the restrictive mode from the start rather than chmod-ing after,
52
+ // so the secret is never briefly world-readable.
53
+ fs.writeFileSync(STORE_FILE, JSON.stringify(body, null, 2) + "\n", { encoding: "utf8", mode: 0o600 });
54
+ // No-op on Windows, which does not honour POSIX modes; see the header note.
55
+ try { fs.chmodSync(STORE_FILE, 0o600); } catch (err) { /* best effort */ }
56
+ return STORE_FILE;
57
+ }
58
+
59
+ function clearStored() {
60
+ try { fs.unlinkSync(STORE_FILE); return true; }
61
+ catch (err) { return false; }
62
+ }
63
+
64
+ // A dashboard value is base64. Catching an obviously wrong paste here turns a
65
+ // confusing failure at protect time into an immediate, specific message.
66
+ function looksLikeDashboardValue(value) {
67
+ return typeof value === "string" && value.length >= 8 && /^[A-Za-z0-9+/=_-]+$/.test(value.trim());
68
+ }
69
+
70
+ function openBrowser(url) {
71
+ const cmd = process.platform === "win32" ? "cmd" : (process.platform === "darwin" ? "open" : "xdg-open");
72
+ const args = process.platform === "win32" ? ["/c", "start", "", url] : [url];
73
+ try {
74
+ const child = spawn(cmd, args, { stdio: "ignore", detached: true });
75
+ child.on("error", () => {});
76
+ child.unref();
77
+ return true;
78
+ } catch (err) {
79
+ return false;
80
+ }
81
+ }
82
+
83
+ function ask(rl, question, { hidden = false } = {}) {
84
+ return new Promise((resolve) => {
85
+ if (!hidden) { rl.question(question, (answer) => resolve(answer.trim())); return; }
86
+ // Mute the echo so a pasted secret does not stay on screen or in a shared
87
+ // terminal recording.
88
+ const output = rl.output;
89
+ let muted = false;
90
+ const onData = (chunk) => { if (muted) return; };
91
+ output.write(question);
92
+ muted = true;
93
+ const origWrite = output.write.bind(output);
94
+ output.write = (chunk, ...rest) => { if (muted && typeof chunk === "string" && chunk !== "\n" && chunk !== "\r\n") return true; return origWrite(chunk, ...rest); };
95
+ rl.question("", (answer) => {
96
+ muted = false;
97
+ output.write = origWrite;
98
+ output.write("\n");
99
+ resolve(answer.trim());
100
+ });
101
+ void onData;
102
+ });
103
+ }
104
+
105
+ async function login(argv = []) {
106
+ const noBrowser = argv.includes("--no-browser");
107
+ const out = process.stdout;
108
+
109
+ out.write("Sign in to javascriptobfuscator.com and copy your API credentials.\n\n");
110
+ out.write(" " + DASHBOARD_URL + "\n\n");
111
+ if (!noBrowser) {
112
+ if (openBrowser(DASHBOARD_URL)) out.write("Opened that page in your browser.\n");
113
+ else out.write("Could not open a browser automatically - use the link above.\n");
114
+ }
115
+ out.write("The dashboard shows an API Key and an API Password. Both are already\n");
116
+ out.write("base64 encoded; paste them exactly as shown.\n\n");
117
+
118
+ if (!process.stdin.isTTY) {
119
+ out.write("No interactive terminal. Set JSO_API_KEY and JSO_API_PASSWORD instead,\n");
120
+ out.write("or run this command in a terminal.\n");
121
+ return 1;
122
+ }
123
+
124
+ const rl = readline.createInterface({ input: process.stdin, output: process.stdout, terminal: true });
125
+ try {
126
+ const apiKey = await ask(rl, "API Key: ");
127
+ const apiPassword = await ask(rl, "API Password: ", { hidden: true });
128
+
129
+ if (!apiKey || !apiPassword) {
130
+ out.write("\nBoth values are required. Nothing was saved.\n");
131
+ return 1;
132
+ }
133
+ if (!looksLikeDashboardValue(apiKey) || !looksLikeDashboardValue(apiPassword)) {
134
+ out.write("\nThat does not look like a dashboard value. They are base64 strings -\n");
135
+ out.write("check you copied the value and not the label. Nothing was saved.\n");
136
+ return 1;
137
+ }
138
+
139
+ const file = writeStored(apiKey, apiPassword, "");
140
+ out.write("\nSaved to " + file + "\n");
141
+ out.write("Every project on this machine now uses these credentials.\n");
142
+ out.write("Run `javascriptobfuscator --input dist --output dist-protected` to protect a build.\n");
143
+ out.write("Run `javascriptobfuscator logout` to remove them.\n");
144
+ return 0;
145
+ } finally {
146
+ rl.close();
147
+ }
148
+ }
149
+
150
+ function logout() {
151
+ const removed = clearStored();
152
+ process.stdout.write(removed
153
+ ? "Removed " + STORE_FILE + "\n"
154
+ : "No stored credentials at " + STORE_FILE + "\n");
155
+ return 0;
156
+ }
157
+
158
+ module.exports = { login, logout, readStored, writeStored, clearStored, storePath, looksLikeDashboardValue, DASHBOARD_URL };
@@ -39,7 +39,7 @@ published as `javascriptobfuscator-com`; `jso-protector` is the former name and
39
39
  is deprecated but still updated:
40
40
 
41
41
  ```bash
42
- npm install --save-dev javascriptobfuscator-com@0.4.3
42
+ npm install --save-dev javascriptobfuscator-com@0.4.4
43
43
  ```
44
44
 
45
45
  Repository contributors can instead use the existing `file:../..` development
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jso-protector",
3
- "version": "0.4.3",
3
+ "version": "0.4.4",
4
4
  "description": "Obfuscate and protect JavaScript in your build or CI: dependency-free CLI, Node API, and webpack/Vite/Rollup/esbuild/Next.js/Metro plugins, with one-command migration from javascript-obfuscator and JS-Confuser configs.",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "author": "JavaScript Obfuscator",
@@ -62,6 +62,7 @@
62
62
  "ai.js",
63
63
  "browserify.d.ts",
64
64
  "browserify.js",
65
+ "credentials.js",
65
66
  "esbuild.d.ts",
66
67
  "esbuild.js",
67
68
  "gulp.d.ts",