@keynv/cli 0.1.0-rc.17 → 0.1.0-rc.18
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/dist/index.js +69 -27
- package/dist/index.js.map +1 -1
- package/package.json +3 -15
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { createRequire } from 'module';
|
|
3
3
|
import { createHash, randomBytes } from 'crypto';
|
|
4
|
-
import { readFileSync,
|
|
4
|
+
import { readFileSync, unlinkSync, existsSync, statSync, writeFileSync, readdirSync, mkdirSync, rmSync, lstatSync } from 'fs';
|
|
5
5
|
import { hostname, platform, homedir } from 'os';
|
|
6
6
|
import * as nodePath from 'path';
|
|
7
7
|
import { relative, join, isAbsolute, resolve, dirname, basename } from 'path';
|
|
@@ -1057,7 +1057,7 @@ var require_lib = __commonJS({
|
|
|
1057
1057
|
var VERSION, AGENT;
|
|
1058
1058
|
var init_version = __esm({
|
|
1059
1059
|
"src/version.ts"() {
|
|
1060
|
-
VERSION = "0.1.0-rc.
|
|
1060
|
+
VERSION = "0.1.0-rc.18" ;
|
|
1061
1061
|
AGENT = `keynv-cli/${VERSION}`;
|
|
1062
1062
|
}
|
|
1063
1063
|
});
|
|
@@ -5778,6 +5778,13 @@ var init_http = __esm({
|
|
|
5778
5778
|
Check the server is running: curl ${serverUrl}/v1/health`
|
|
5779
5779
|
);
|
|
5780
5780
|
}
|
|
5781
|
+
} else {
|
|
5782
|
+
this.creds = null;
|
|
5783
|
+
throw clientError(
|
|
5784
|
+
401,
|
|
5785
|
+
"auth.session_expired",
|
|
5786
|
+
"Session expired. Run `keynv` to reconnect."
|
|
5787
|
+
);
|
|
5781
5788
|
}
|
|
5782
5789
|
}
|
|
5783
5790
|
if (res.status === 204) return void 0;
|
|
@@ -46718,6 +46725,28 @@ function toAliasKey2(name) {
|
|
|
46718
46725
|
if (KEY_RE3.test(normalised)) return normalised;
|
|
46719
46726
|
return normalised.replace(/[^a-zA-Z0-9_-]/g, "").slice(0, 64) || "key";
|
|
46720
46727
|
}
|
|
46728
|
+
function escapeRegExp2(value) {
|
|
46729
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
46730
|
+
}
|
|
46731
|
+
function writeKeynvEnvMappings(path, projectName, envName, secrets) {
|
|
46732
|
+
const existing = existsSync(path) ? readFileSync(path, "utf8") : "";
|
|
46733
|
+
const lines = [];
|
|
46734
|
+
for (const s of secrets) {
|
|
46735
|
+
const hasEntry = new RegExp(`^${escapeRegExp2(s.name)}=`, "m").test(existing);
|
|
46736
|
+
if (!hasEntry) {
|
|
46737
|
+
lines.push(`# ${s.name}`, `${s.name}=@${projectName}.${envName}.${s.aliasKey}`);
|
|
46738
|
+
}
|
|
46739
|
+
}
|
|
46740
|
+
if (lines.length === 0) return 0;
|
|
46741
|
+
const prefix = existing.trimEnd();
|
|
46742
|
+
const block = `# Generated by keynv setup
|
|
46743
|
+
${lines.join("\n")}
|
|
46744
|
+
`;
|
|
46745
|
+
writeFileSync(path, prefix ? `${prefix}
|
|
46746
|
+
|
|
46747
|
+
${block}` : block);
|
|
46748
|
+
return lines.length / 2;
|
|
46749
|
+
}
|
|
46721
46750
|
var InitCommand = class extends Command {
|
|
46722
46751
|
static paths = [["init"]];
|
|
46723
46752
|
static usage = Command.Usage({
|
|
@@ -46874,7 +46903,22 @@ any prompts.
|
|
|
46874
46903
|
return 0;
|
|
46875
46904
|
}
|
|
46876
46905
|
const secretsWithKeys = secrets.map((s) => ({ ...s, aliasKey: toAliasKey2(s.name) }));
|
|
46877
|
-
|
|
46906
|
+
const result = await this.uploadSecrets(
|
|
46907
|
+
client,
|
|
46908
|
+
projectId2,
|
|
46909
|
+
projectName,
|
|
46910
|
+
envName,
|
|
46911
|
+
secretsWithKeys
|
|
46912
|
+
);
|
|
46913
|
+
if (result !== 0) return result;
|
|
46914
|
+
const keynvEnvPath = join(process.cwd(), ".keynv.env");
|
|
46915
|
+
const written = writeKeynvEnvMappings(keynvEnvPath, projectName, envName, secretsWithKeys);
|
|
46916
|
+
this.context.stdout.write(
|
|
46917
|
+
written > 0 ? `keynv: wrote ${keynvEnvPath}
|
|
46918
|
+
` : `keynv: ${keynvEnvPath} already up to date
|
|
46919
|
+
`
|
|
46920
|
+
);
|
|
46921
|
+
return 0;
|
|
46878
46922
|
}
|
|
46879
46923
|
/**
|
|
46880
46924
|
* Auto-scan mode (--yes without explicit --env-file). Finds .env files
|
|
@@ -46948,14 +46992,13 @@ any prompts.
|
|
|
46948
46992
|
secretsWithKeys
|
|
46949
46993
|
);
|
|
46950
46994
|
if (result !== 0) return result;
|
|
46951
|
-
const aliasLines = secretsWithKeys.map((s) => `# ${s.name}
|
|
46952
|
-
${s.name}=@${projectName}.${envName}.${s.aliasKey}`).join("\n");
|
|
46953
46995
|
const keynvEnvPath = join(root.path, ".keynv.env");
|
|
46954
|
-
|
|
46955
|
-
|
|
46956
|
-
`
|
|
46957
|
-
|
|
46958
|
-
`
|
|
46996
|
+
const written = writeKeynvEnvMappings(keynvEnvPath, projectName, envName, secretsWithKeys);
|
|
46997
|
+
this.context.stdout.write(
|
|
46998
|
+
written > 0 ? `keynv: wrote ${keynvEnvPath}
|
|
46999
|
+
` : `keynv: ${keynvEnvPath} already up to date
|
|
47000
|
+
`
|
|
47001
|
+
);
|
|
46959
47002
|
try {
|
|
46960
47003
|
const outcome = writeAiContext(root.path);
|
|
46961
47004
|
if (outcome === "created") this.context.stdout.write("keynv: wrote AGENTS.md\n");
|
|
@@ -48537,28 +48580,27 @@ cli.register(RedactStreamCommand);
|
|
|
48537
48580
|
cli.register(TestCommand);
|
|
48538
48581
|
cli.register(ServerInitCommand);
|
|
48539
48582
|
var argv = process.argv.slice(2);
|
|
48540
|
-
|
|
48541
|
-
|
|
48542
|
-
|
|
48543
|
-
|
|
48544
|
-
|
|
48545
|
-
|
|
48546
|
-
|
|
48547
|
-
process.exit(1);
|
|
48548
|
-
});
|
|
48549
|
-
} else {
|
|
48583
|
+
async function main() {
|
|
48584
|
+
if (argv.length === 0) {
|
|
48585
|
+
const { runMenu: runMenu2 } = await Promise.resolve().then(() => (init_menu(), menu_exports));
|
|
48586
|
+
const { isInteractive: isInteractive2 } = await Promise.resolve().then(() => (init_tty(), tty_exports));
|
|
48587
|
+
if (isInteractive2()) {
|
|
48588
|
+
return runMenu2();
|
|
48589
|
+
}
|
|
48550
48590
|
process.stdout.write(
|
|
48551
48591
|
"keynv \u2014 AI-safe secrets management.\nRun `keynv --help` for the full command list, or run `keynv` in an interactive\nterminal to open the menu.\n"
|
|
48552
48592
|
);
|
|
48553
|
-
|
|
48593
|
+
return 0;
|
|
48554
48594
|
}
|
|
48555
|
-
|
|
48556
|
-
cli.run(argv).then((code) => process.exit(code ?? 0)).catch((err) => {
|
|
48557
|
-
process.stderr.write(`${fmtError(err)}
|
|
48558
|
-
`);
|
|
48559
|
-
process.exit(1);
|
|
48560
|
-
});
|
|
48595
|
+
return cli.run(argv);
|
|
48561
48596
|
}
|
|
48597
|
+
main().then((code) => {
|
|
48598
|
+
process.exitCode = code ?? 0;
|
|
48599
|
+
}).catch((err) => {
|
|
48600
|
+
process.stderr.write(`${fmtError(err)}
|
|
48601
|
+
`);
|
|
48602
|
+
process.exitCode = 1;
|
|
48603
|
+
});
|
|
48562
48604
|
/*! Bundled license information:
|
|
48563
48605
|
|
|
48564
48606
|
long/umd/index.js:
|