xtra-cli 1.0.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/LICENSE +21 -0
- package/README.md +87 -0
- package/dist/bin/xtra.js +138 -0
- package/dist/commands/access.js +184 -0
- package/dist/commands/admin.js +118 -0
- package/dist/commands/audit.js +67 -0
- package/dist/commands/branch.js +212 -0
- package/dist/commands/checkout.js +73 -0
- package/dist/commands/ci.js +341 -0
- package/dist/commands/completion.js +227 -0
- package/dist/commands/diff.js +162 -0
- package/dist/commands/doctor.js +164 -0
- package/dist/commands/env.js +70 -0
- package/dist/commands/export.js +83 -0
- package/dist/commands/generate.js +179 -0
- package/dist/commands/history.js +77 -0
- package/dist/commands/import.js +121 -0
- package/dist/commands/init.js +205 -0
- package/dist/commands/integration.js +188 -0
- package/dist/commands/local.js +198 -0
- package/dist/commands/login.js +198 -0
- package/dist/commands/login.test.js +51 -0
- package/dist/commands/logs.js +121 -0
- package/dist/commands/profile.js +184 -0
- package/dist/commands/project.js +165 -0
- package/dist/commands/rollback.js +95 -0
- package/dist/commands/rotate.js +93 -0
- package/dist/commands/run.js +215 -0
- package/dist/commands/scan.js +127 -0
- package/dist/commands/secrets.js +305 -0
- package/dist/commands/simulate.js +109 -0
- package/dist/commands/status.js +93 -0
- package/dist/commands/template.js +276 -0
- package/dist/commands/ui.js +289 -0
- package/dist/commands/watch.js +123 -0
- package/dist/lib/api.js +187 -0
- package/dist/lib/api.test.js +89 -0
- package/dist/lib/audit.js +136 -0
- package/dist/lib/config.js +70 -0
- package/dist/lib/config.test.js +47 -0
- package/dist/lib/crypto.js +50 -0
- package/dist/lib/manifest.js +52 -0
- package/dist/lib/profiles.js +103 -0
- package/package.json +67 -0
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.completionCommand = void 0;
|
|
40
|
+
const commander_1 = require("commander");
|
|
41
|
+
const fs = __importStar(require("fs"));
|
|
42
|
+
const path = __importStar(require("path"));
|
|
43
|
+
const os = __importStar(require("os"));
|
|
44
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
45
|
+
// ─── All CLI top-level commands ───────────────────────────────────────────────
|
|
46
|
+
const ALL_COMMANDS = [
|
|
47
|
+
"login", "run", "secrets", "generate", "status", "diff", "rollback",
|
|
48
|
+
"scan", "logs", "export", "import", "rotate", "audit", "access",
|
|
49
|
+
"branch", "checkout", "project", "admin", "integration", "kubernetes",
|
|
50
|
+
"history", "env", "ui", "completion"
|
|
51
|
+
];
|
|
52
|
+
const SUBCOMMANDS = {
|
|
53
|
+
secrets: ["list", "set", "link"],
|
|
54
|
+
branch: ["list", "create", "delete", "update"],
|
|
55
|
+
admin: ["users", "roles", "role", "set-role"],
|
|
56
|
+
access: ["request", "list", "approve"],
|
|
57
|
+
audit: ["verify", "export"],
|
|
58
|
+
integration: ["sync", "export", "apply"],
|
|
59
|
+
env: ["clone"],
|
|
60
|
+
project: ["set", "current"],
|
|
61
|
+
completion: ["bash", "zsh", "powershell", "install"],
|
|
62
|
+
};
|
|
63
|
+
// ─── Bash completion script ───────────────────────────────────────────────────
|
|
64
|
+
function bashScript() {
|
|
65
|
+
const subMap = Object.entries(SUBCOMMANDS)
|
|
66
|
+
.map(([cmd, subs]) => ` ${cmd}) echo "${subs.join(" ")}" ;;`)
|
|
67
|
+
.join("\n");
|
|
68
|
+
return `# xtra bash completion
|
|
69
|
+
# Add to ~/.bashrc: source <(xtra completion bash)
|
|
70
|
+
_xtra_completions() {
|
|
71
|
+
local cur prev words
|
|
72
|
+
cur="\${COMP_WORDS[COMP_CWORD]}"
|
|
73
|
+
prev="\${COMP_WORDS[COMP_CWORD-1]}"
|
|
74
|
+
|
|
75
|
+
if [ "\${COMP_CWORD}" -eq 1 ]; then
|
|
76
|
+
COMPREPLY=( $(compgen -W "${ALL_COMMANDS.join(" ")}" -- "$cur") )
|
|
77
|
+
return
|
|
78
|
+
fi
|
|
79
|
+
|
|
80
|
+
local subcommands=""
|
|
81
|
+
case "\${COMP_WORDS[1]}" in
|
|
82
|
+
${subMap}
|
|
83
|
+
*) ;;
|
|
84
|
+
esac
|
|
85
|
+
|
|
86
|
+
if [ -n "$subcommands" ]; then
|
|
87
|
+
COMPREPLY=( $(compgen -W "$subcommands" -- "$cur") )
|
|
88
|
+
fi
|
|
89
|
+
}
|
|
90
|
+
complete -F _xtra_completions xtra
|
|
91
|
+
`;
|
|
92
|
+
}
|
|
93
|
+
// ─── Zsh completion script ────────────────────────────────────────────────────
|
|
94
|
+
function zshScript() {
|
|
95
|
+
const subDefs = Object.entries(SUBCOMMANDS)
|
|
96
|
+
.map(([cmd, subs]) => ` (${cmd})\n local subcmds=(${subs.map(s => `'${s}'`).join(" ")})\n _describe 'subcommand' subcmds ;;`)
|
|
97
|
+
.join("\n");
|
|
98
|
+
return `#compdef xtra
|
|
99
|
+
# xtra zsh completion
|
|
100
|
+
# Add to ~/.zshrc: source <(xtra completion zsh)
|
|
101
|
+
_xtra() {
|
|
102
|
+
local state
|
|
103
|
+
_arguments \\
|
|
104
|
+
'1: :->command' \\
|
|
105
|
+
'*: :->args'
|
|
106
|
+
|
|
107
|
+
case $state in
|
|
108
|
+
command)
|
|
109
|
+
local commands=(${ALL_COMMANDS.map(c => `'${c}'`).join(" ")})
|
|
110
|
+
_describe 'command' commands ;;
|
|
111
|
+
args)
|
|
112
|
+
case $words[2] in
|
|
113
|
+
${subDefs}
|
|
114
|
+
esac ;;
|
|
115
|
+
esac
|
|
116
|
+
}
|
|
117
|
+
_xtra
|
|
118
|
+
`;
|
|
119
|
+
}
|
|
120
|
+
// ─── PowerShell completion script ────────────────────────────────────────────
|
|
121
|
+
function powershellScript() {
|
|
122
|
+
const subMap = Object.entries(SUBCOMMANDS)
|
|
123
|
+
.map(([cmd, subs]) => ` '${cmd}' { $subCommands = @(${subs.map(s => `'${s}'`).join(", ")}) }`)
|
|
124
|
+
.join("\n");
|
|
125
|
+
return `# xtra PowerShell completion
|
|
126
|
+
# Add to $PROFILE: xtra completion powershell | Invoke-Expression
|
|
127
|
+
Register-ArgumentCompleter -Native -CommandName xtra -ScriptBlock {
|
|
128
|
+
param($wordToComplete, $commandAst, $cursorPosition)
|
|
129
|
+
$tokens = $commandAst.CommandElements
|
|
130
|
+
$topCommands = @(${ALL_COMMANDS.map(c => `'${c}'`).join(", ")})
|
|
131
|
+
|
|
132
|
+
if ($tokens.Count -le 2) {
|
|
133
|
+
$topCommands | Where-Object { $_ -like "$wordToComplete*" } |
|
|
134
|
+
ForEach-Object { [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_) }
|
|
135
|
+
return
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
$subCommands = @()
|
|
139
|
+
switch ($tokens[1]) {
|
|
140
|
+
${subMap}
|
|
141
|
+
}
|
|
142
|
+
$subCommands | Where-Object { $_ -like "$wordToComplete*" } |
|
|
143
|
+
ForEach-Object { [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_) }
|
|
144
|
+
}
|
|
145
|
+
`;
|
|
146
|
+
}
|
|
147
|
+
// ─── Install helper ───────────────────────────────────────────────────────────
|
|
148
|
+
function installCompletion(shell) {
|
|
149
|
+
const home = os.homedir();
|
|
150
|
+
let rcFile;
|
|
151
|
+
let snippet;
|
|
152
|
+
let script;
|
|
153
|
+
switch (shell) {
|
|
154
|
+
case "bash":
|
|
155
|
+
rcFile = path.join(home, ".bashrc");
|
|
156
|
+
snippet = `\n# xtra CLI completion\nsource <(xtra completion bash)\n`;
|
|
157
|
+
script = bashScript();
|
|
158
|
+
break;
|
|
159
|
+
case "zsh":
|
|
160
|
+
rcFile = path.join(home, ".zshrc");
|
|
161
|
+
snippet = `\n# xtra CLI completion\nsource <(xtra completion zsh)\n`;
|
|
162
|
+
script = zshScript();
|
|
163
|
+
break;
|
|
164
|
+
case "powershell":
|
|
165
|
+
rcFile = path.join(home, "Documents", "WindowsPowerShell", "Microsoft.PowerShell_profile.ps1");
|
|
166
|
+
snippet = `\n# xtra CLI completion\nxtra completion powershell | Invoke-Expression\n`;
|
|
167
|
+
script = powershellScript();
|
|
168
|
+
break;
|
|
169
|
+
default:
|
|
170
|
+
console.error(chalk_1.default.red(`Unsupported shell: ${shell}. Use bash, zsh, or powershell.`));
|
|
171
|
+
process.exit(1);
|
|
172
|
+
}
|
|
173
|
+
// Write the completion script to a temp file path for reference
|
|
174
|
+
const scriptPath = path.join(home, `.xtra-completion.${shell}`);
|
|
175
|
+
fs.writeFileSync(scriptPath, script, "utf8");
|
|
176
|
+
// Append sourcing snippet to rc file if not already there
|
|
177
|
+
let rcContent = "";
|
|
178
|
+
try {
|
|
179
|
+
rcContent = fs.readFileSync(rcFile, "utf8");
|
|
180
|
+
}
|
|
181
|
+
catch (_) { }
|
|
182
|
+
if (rcContent.includes("xtra completion")) {
|
|
183
|
+
console.log(chalk_1.default.yellow(`Completion already installed in ${rcFile}. Skipping.`));
|
|
184
|
+
}
|
|
185
|
+
else {
|
|
186
|
+
fs.appendFileSync(rcFile, snippet, "utf8");
|
|
187
|
+
console.log(chalk_1.default.green(`✅ Completion installed!\n`));
|
|
188
|
+
console.log(` Script saved to: ${chalk_1.default.cyan(scriptPath)}`);
|
|
189
|
+
console.log(` Sourced in: ${chalk_1.default.cyan(rcFile)}`);
|
|
190
|
+
console.log(`\nRestart your shell or run: ${chalk_1.default.bold(`source ${rcFile}`)}`);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
// ─── Commander command ────────────────────────────────────────────────────────
|
|
194
|
+
exports.completionCommand = new commander_1.Command("completion")
|
|
195
|
+
.description("Generate shell completion scripts (bash, zsh, powershell)")
|
|
196
|
+
.argument("[shell]", "Target shell: bash | zsh | powershell", "bash")
|
|
197
|
+
.option("--install", "Automatically install completion into your shell profile")
|
|
198
|
+
.addHelpText("after", `
|
|
199
|
+
Examples:
|
|
200
|
+
$ xtra completion bash # Print bash completion script
|
|
201
|
+
$ xtra completion zsh # Print zsh completion script
|
|
202
|
+
$ xtra completion powershell # Print PowerShell completion script
|
|
203
|
+
$ source <(xtra completion bash) # Activate in current session
|
|
204
|
+
$ xtra completion bash --install # Auto-install to ~/.bashrc
|
|
205
|
+
$ xtra completion powershell --install # Auto-install to $PROFILE
|
|
206
|
+
`)
|
|
207
|
+
.action((shell, options) => {
|
|
208
|
+
const normalizedShell = shell.toLowerCase();
|
|
209
|
+
if (options.install) {
|
|
210
|
+
installCompletion(normalizedShell);
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
switch (normalizedShell) {
|
|
214
|
+
case "bash":
|
|
215
|
+
process.stdout.write(bashScript());
|
|
216
|
+
break;
|
|
217
|
+
case "zsh":
|
|
218
|
+
process.stdout.write(zshScript());
|
|
219
|
+
break;
|
|
220
|
+
case "powershell":
|
|
221
|
+
process.stdout.write(powershellScript());
|
|
222
|
+
break;
|
|
223
|
+
default:
|
|
224
|
+
console.error(chalk_1.default.red(`Unknown shell: '${shell}'. Use bash, zsh, or powershell.`));
|
|
225
|
+
process.exit(1);
|
|
226
|
+
}
|
|
227
|
+
});
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.diffCommand = void 0;
|
|
40
|
+
const commander_1 = require("commander");
|
|
41
|
+
const api_1 = require("../lib/api");
|
|
42
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
43
|
+
const ora_1 = __importDefault(require("ora"));
|
|
44
|
+
const config_1 = require("../lib/config");
|
|
45
|
+
const crypto_1 = require("../lib/crypto");
|
|
46
|
+
const diff = __importStar(require("diff"));
|
|
47
|
+
exports.diffCommand = new commander_1.Command("diff")
|
|
48
|
+
.description("Show differences between local cache and remote secrets")
|
|
49
|
+
.argument("[env1]", "Source Environment")
|
|
50
|
+
.argument("[env2]", "Target Environment")
|
|
51
|
+
.option("-p, --project <projectId>", "Project ID")
|
|
52
|
+
.option("-e, --env <environment>", "Environment (dev, stg, prod)", "dev")
|
|
53
|
+
.option("-b, --branch <branchName>", "Branch Name")
|
|
54
|
+
.option("--show", "Show actual value differences (sensitive)", false)
|
|
55
|
+
.action(async (env1, env2, options) => {
|
|
56
|
+
let { project, env, branch, show } = options;
|
|
57
|
+
// Use config fallback
|
|
58
|
+
if (!project)
|
|
59
|
+
project = (0, config_1.getRcConfig)().project;
|
|
60
|
+
if (!branch) {
|
|
61
|
+
branch = (0, config_1.getRcConfig)().branch || "main";
|
|
62
|
+
}
|
|
63
|
+
if (!project) {
|
|
64
|
+
console.error(chalk_1.default.red("Error: Project ID is required. Use -p <id> or run 'xtra project set' first."));
|
|
65
|
+
process.exit(1);
|
|
66
|
+
}
|
|
67
|
+
// Normalize Env Map
|
|
68
|
+
const envMap = { dev: "development", stg: "staging", prod: "production" };
|
|
69
|
+
if (env1 && env2) {
|
|
70
|
+
// COMPARE TWO REMOTE ENVIRONMENTS
|
|
71
|
+
const sourceEnv = envMap[env1] || env1;
|
|
72
|
+
const targetEnv = envMap[env2] || env2;
|
|
73
|
+
const spinner = (0, ora_1.default)(`Fetching secrets for ${sourceEnv} and ${targetEnv} (branch: ${branch})...`).start();
|
|
74
|
+
try {
|
|
75
|
+
const [sourceSecrets, targetSecrets] = await Promise.all([
|
|
76
|
+
api_1.api.getSecrets(project, sourceEnv, branch),
|
|
77
|
+
api_1.api.getSecrets(project, targetEnv, branch)
|
|
78
|
+
]);
|
|
79
|
+
spinner.stop();
|
|
80
|
+
console.log(chalk_1.default.bold(`\nDiff Report (${sourceEnv} <-> ${targetEnv} @ ${branch}):\n`));
|
|
81
|
+
compareSecrets(sourceSecrets, targetSecrets, show);
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
spinner.fail("Failed to fetch secrets");
|
|
85
|
+
console.error(chalk_1.default.red(error.message));
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
// DEFAULT: COMPARE REMOTE VS LOCAL CACHE
|
|
90
|
+
const targetEnv = envMap[env] || env;
|
|
91
|
+
const spinner = (0, ora_1.default)(`Fetching remote state for ${targetEnv} (branch: ${branch})...`).start();
|
|
92
|
+
try {
|
|
93
|
+
const remoteSecrets = await api_1.api.getSecrets(project, targetEnv, branch);
|
|
94
|
+
let localSecrets = {};
|
|
95
|
+
try {
|
|
96
|
+
const cacheKey = `cache.${project}.${targetEnv}.${branch}`;
|
|
97
|
+
const encrypted = (0, config_1.getConfigValue)(cacheKey);
|
|
98
|
+
if (encrypted) {
|
|
99
|
+
const decryptedStr = (0, crypto_1.decrypt)(encrypted);
|
|
100
|
+
localSecrets = JSON.parse(decryptedStr);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
catch (e) { }
|
|
104
|
+
spinner.stop();
|
|
105
|
+
console.log(chalk_1.default.bold(`\nDiff Report (Remote ${targetEnv} vs Local Cache):\n`));
|
|
106
|
+
compareSecrets(remoteSecrets, localSecrets, show); // Note: verify order or adjust message
|
|
107
|
+
// existing logic compared local (arg1) to remote (arg2)
|
|
108
|
+
// But usually diff is "What is in A that is not in B"
|
|
109
|
+
// Let's call a shared helper or inline it but consistent
|
|
110
|
+
// To match previous behavior: comparing LOCAL against REMOTE
|
|
111
|
+
// But wait, user wants to see what's different in Remote.
|
|
112
|
+
// Let's stick to the previous logic structure for consistency if I extract it.
|
|
113
|
+
// Actually, I'll just rewrite the comparison block to be generic.
|
|
114
|
+
}
|
|
115
|
+
catch (error) {
|
|
116
|
+
spinner.fail("Failed to run diff.");
|
|
117
|
+
console.error(chalk_1.default.red(error.message));
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
function compareSecrets(source, target, show) {
|
|
122
|
+
const allKeys = new Set([...Object.keys(source), ...Object.keys(target)]);
|
|
123
|
+
let hasDiff = false;
|
|
124
|
+
allKeys.forEach(key => {
|
|
125
|
+
const val1 = source[key];
|
|
126
|
+
const val2 = target[key];
|
|
127
|
+
if (val1 === val2)
|
|
128
|
+
return;
|
|
129
|
+
hasDiff = true;
|
|
130
|
+
if (val1 === undefined) {
|
|
131
|
+
// Present in Target, missing in Source
|
|
132
|
+
console.log(chalk_1.default.green(`+ ${key} (Only in Target)`));
|
|
133
|
+
if (show)
|
|
134
|
+
console.log(chalk_1.default.green(` + "${val2}"`));
|
|
135
|
+
}
|
|
136
|
+
else if (val2 === undefined) {
|
|
137
|
+
// Present in Source, missing in Target
|
|
138
|
+
console.log(chalk_1.default.red(`- ${key} (Only in Source)`));
|
|
139
|
+
if (show)
|
|
140
|
+
console.log(chalk_1.default.red(` - "${val1}"`));
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
console.log(chalk_1.default.yellow(`~ ${key} (Modified)`));
|
|
144
|
+
if (show) {
|
|
145
|
+
const changes = diff.diffChars(val1, val2);
|
|
146
|
+
let diffStr = " ";
|
|
147
|
+
changes.forEach(part => {
|
|
148
|
+
const color = part.added ? chalk_1.default.green :
|
|
149
|
+
part.removed ? chalk_1.default.red : chalk_1.default.gray;
|
|
150
|
+
diffStr += color(part.value);
|
|
151
|
+
});
|
|
152
|
+
console.log(diffStr);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
if (!hasDiff) {
|
|
157
|
+
console.log(chalk_1.default.green("✔ No differences found."));
|
|
158
|
+
}
|
|
159
|
+
else if (!show) {
|
|
160
|
+
console.log(chalk_1.default.gray("\n(Use --show to reveal secret values)"));
|
|
161
|
+
}
|
|
162
|
+
}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.doctorCommand = void 0;
|
|
40
|
+
/**
|
|
41
|
+
* doctor.ts — Diagnose common xtra-cli setup issues
|
|
42
|
+
*/
|
|
43
|
+
const commander_1 = require("commander");
|
|
44
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
45
|
+
const fs = __importStar(require("fs"));
|
|
46
|
+
const path = __importStar(require("path"));
|
|
47
|
+
const axios_1 = __importDefault(require("axios"));
|
|
48
|
+
const config_1 = require("../lib/config");
|
|
49
|
+
// ─── Box Drawing Helpers ─────────────────────────────────────────────────────
|
|
50
|
+
const W = 65;
|
|
51
|
+
const B = { tl: "╭", tr: "╮", bl: "╰", br: "╯", h: "─", v: "│" };
|
|
52
|
+
function hline(w) { return B.h.repeat(w); }
|
|
53
|
+
const PASS = chalk_1.default.green("✓ ");
|
|
54
|
+
const FAIL = chalk_1.default.red("✗ ");
|
|
55
|
+
const WARN = chalk_1.default.yellow("⚠ ");
|
|
56
|
+
async function runChecks() {
|
|
57
|
+
const checks = [];
|
|
58
|
+
const config = (0, config_1.getConfig)();
|
|
59
|
+
// 1. Node Version
|
|
60
|
+
const nodeMajor = parseInt(process.versions.node.split(".")[0]);
|
|
61
|
+
checks.push({
|
|
62
|
+
name: "Node.js Version",
|
|
63
|
+
status: nodeMajor >= 18 ? "pass" : "fail",
|
|
64
|
+
message: `v${process.versions.node} ${nodeMajor >= 18 ? "(OK)" : "(requires >=18)"}`,
|
|
65
|
+
});
|
|
66
|
+
// 2. Auth Token
|
|
67
|
+
const token = (0, config_1.getAuthToken)();
|
|
68
|
+
checks.push({
|
|
69
|
+
name: "Auth Token",
|
|
70
|
+
status: token ? "pass" : "fail",
|
|
71
|
+
message: token ? `Set (${token.substring(0, 8)}...)` : "Not set — run 'xtra login'",
|
|
72
|
+
});
|
|
73
|
+
// 3. API URL Configured
|
|
74
|
+
const apiUrl = config.apiUrl || process.env.XTRA_API_URL || "https://xtra-security.vercel.app/api";
|
|
75
|
+
checks.push({
|
|
76
|
+
name: "API URL",
|
|
77
|
+
status: config.apiUrl || process.env.XTRA_API_URL ? "pass" : "warn",
|
|
78
|
+
message: apiUrl,
|
|
79
|
+
});
|
|
80
|
+
// 4. API Reachability
|
|
81
|
+
try {
|
|
82
|
+
const res = await axios_1.default.get(`${apiUrl}/health`, { timeout: 4000 });
|
|
83
|
+
checks.push({
|
|
84
|
+
name: "API Connectivity",
|
|
85
|
+
status: res.status === 200 ? "pass" : "warn",
|
|
86
|
+
message: `${res.status} ${res.statusText}`,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
catch (e) {
|
|
90
|
+
const msg = e.code === "ECONNREFUSED" ? "Connection refused (offline?)"
|
|
91
|
+
: e.code === "ETIMEDOUT" ? "Timed out (unreachable)"
|
|
92
|
+
: e.response?.status === 404 ? "API reachable (health endpoint missing)"
|
|
93
|
+
: e.message;
|
|
94
|
+
// Special case: if it hits a 404 it means DNS and port work, but route is missing
|
|
95
|
+
const status = e.response?.status === 404 ? "pass" : "fail";
|
|
96
|
+
checks.push({ name: "API Connectivity", status, message: msg });
|
|
97
|
+
}
|
|
98
|
+
// 5. Active Project
|
|
99
|
+
const project = (0, config_1.getRcConfig)().project;
|
|
100
|
+
checks.push({
|
|
101
|
+
name: "Active Project",
|
|
102
|
+
status: project ? "pass" : "warn",
|
|
103
|
+
message: project ? project : "Not set — run 'xtra project set <id>'",
|
|
104
|
+
});
|
|
105
|
+
// 6. Active Branch
|
|
106
|
+
const branch = (0, config_1.getRcConfig)().branch || "main";
|
|
107
|
+
checks.push({
|
|
108
|
+
name: "Active Branch",
|
|
109
|
+
status: "pass",
|
|
110
|
+
message: branch,
|
|
111
|
+
});
|
|
112
|
+
// 7. Config files
|
|
113
|
+
const rcPath = path.join(process.cwd(), ".xtrarc");
|
|
114
|
+
const jsonPath = path.join(process.cwd(), "xtra.json");
|
|
115
|
+
const hasConfig = fs.existsSync(rcPath) || fs.existsSync(jsonPath);
|
|
116
|
+
checks.push({
|
|
117
|
+
name: "Project Config",
|
|
118
|
+
status: hasConfig ? "pass" : "warn",
|
|
119
|
+
message: hasConfig ? (fs.existsSync(rcPath) ? ".xtrarc found" : "xtra.json found") : "Not found (run 'xtra init')",
|
|
120
|
+
});
|
|
121
|
+
return checks;
|
|
122
|
+
}
|
|
123
|
+
exports.doctorCommand = new commander_1.Command("doctor")
|
|
124
|
+
.description("Diagnose CLI configuration and API connectivity")
|
|
125
|
+
.option("--json", "Output results as JSON", false)
|
|
126
|
+
.action(async (options) => {
|
|
127
|
+
if (!options.json) {
|
|
128
|
+
console.log();
|
|
129
|
+
console.log(chalk_1.default.bold.cyan(" ⚕ XtraSecurity Diagnostics"));
|
|
130
|
+
console.log(chalk_1.default.hex("#4a5568")(" " + B.tl + hline(W) + B.tr));
|
|
131
|
+
}
|
|
132
|
+
const checks = await runChecks();
|
|
133
|
+
if (options.json) {
|
|
134
|
+
process.stdout.write(JSON.stringify(checks, null, 2) + "\n");
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
let failures = 0, warnings = 0;
|
|
138
|
+
for (const c of checks) {
|
|
139
|
+
if (c.status === "fail")
|
|
140
|
+
failures++;
|
|
141
|
+
if (c.status === "warn")
|
|
142
|
+
warnings++;
|
|
143
|
+
const icon = c.status === "pass" ? PASS : c.status === "warn" ? WARN : FAIL;
|
|
144
|
+
const name = chalk_1.default.bold(chalk_1.default.white(c.name.padEnd(20)));
|
|
145
|
+
const msg = c.status === "pass" ? chalk_1.default.hex("#94a3b8")(c.message)
|
|
146
|
+
: c.status === "warn" ? chalk_1.default.yellow(c.message)
|
|
147
|
+
: chalk_1.default.red(c.message);
|
|
148
|
+
console.log(chalk_1.default.hex("#4a5568")(" " + B.v) + ` ${icon}${name} ${msg}`.padEnd(W) + chalk_1.default.hex("#4a5568")(B.v));
|
|
149
|
+
}
|
|
150
|
+
console.log(chalk_1.default.hex("#4a5568")(" " + B.bl + hline(W) + B.br));
|
|
151
|
+
console.log();
|
|
152
|
+
if (failures === 0 && warnings === 0) {
|
|
153
|
+
console.log(chalk_1.default.green(" ✓ All systems operational. The CLI is ready to use."));
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
const parts = [];
|
|
157
|
+
if (failures > 0)
|
|
158
|
+
parts.push(chalk_1.default.red(`${failures} error(s)`));
|
|
159
|
+
if (warnings > 0)
|
|
160
|
+
parts.push(chalk_1.default.yellow(`${warnings} warning(s)`));
|
|
161
|
+
console.log(` Found ${parts.join(" and ")}.`);
|
|
162
|
+
}
|
|
163
|
+
console.log();
|
|
164
|
+
});
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.envCommand = void 0;
|
|
7
|
+
const commander_1 = require("commander");
|
|
8
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
9
|
+
const api_1 = require("../lib/api");
|
|
10
|
+
const config_1 = require("../lib/config");
|
|
11
|
+
const inquirer_1 = __importDefault(require("inquirer"));
|
|
12
|
+
exports.envCommand = new commander_1.Command("env");
|
|
13
|
+
exports.envCommand
|
|
14
|
+
.command("clone")
|
|
15
|
+
.description("Clone secrets from one environment to another")
|
|
16
|
+
.requiredOption("--from <env>", "Source environment (e.g. production)")
|
|
17
|
+
.requiredOption("--to <env>", "Destination environment (e.g. staging)")
|
|
18
|
+
.option("-p, --project <id>", "Project ID")
|
|
19
|
+
.option("-b, --branch <name>", "Branch Name")
|
|
20
|
+
.option("--overwrite", "Overwrite existing secrets", false)
|
|
21
|
+
.action(async (options) => {
|
|
22
|
+
try {
|
|
23
|
+
let projectId = options.project;
|
|
24
|
+
const branch = options.branch || (0, config_1.getRcConfig)().branch || "main";
|
|
25
|
+
if (!projectId) {
|
|
26
|
+
projectId = (0, config_1.getRcConfig)().project;
|
|
27
|
+
if (!projectId) {
|
|
28
|
+
console.error(chalk_1.default.red("Error: Project ID is required. Use -p <id> or run 'xtra project set' first."));
|
|
29
|
+
process.exit(1);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
const fromEnv = options.from.toLowerCase();
|
|
33
|
+
const toEnv = options.to.toLowerCase();
|
|
34
|
+
if (fromEnv === toEnv) {
|
|
35
|
+
console.error(chalk_1.default.red("Source and destination must be different."));
|
|
36
|
+
process.exit(1);
|
|
37
|
+
}
|
|
38
|
+
console.log(chalk_1.default.blue(`Cloning secrets from ${fromEnv} to ${toEnv} (branch: ${branch})...`));
|
|
39
|
+
if (options.overwrite) {
|
|
40
|
+
console.log(chalk_1.default.yellow("Warning: Existing secrets in destination will be overwritten!"));
|
|
41
|
+
}
|
|
42
|
+
const confirm = await inquirer_1.default.prompt([
|
|
43
|
+
{
|
|
44
|
+
type: "confirm",
|
|
45
|
+
name: "proceed",
|
|
46
|
+
message: "Are you sure you want to proceed?",
|
|
47
|
+
default: false
|
|
48
|
+
}
|
|
49
|
+
]);
|
|
50
|
+
if (!confirm.proceed) {
|
|
51
|
+
console.log("Operation cancelled.");
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const result = await api_1.api.cloneEnvironment(projectId, fromEnv, toEnv, options.overwrite, branch);
|
|
55
|
+
if (result.success) {
|
|
56
|
+
console.log(chalk_1.default.green("\nClone successful!"));
|
|
57
|
+
console.log(`Copied: ${result.summary.copied}`);
|
|
58
|
+
console.log(`Updated: ${result.summary.updated} (overwrite: ${options.overwrite})`);
|
|
59
|
+
console.log(`Skipped: ${result.summary.skipped}`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
if (error.response && error.response.data && error.response.data.error) {
|
|
64
|
+
console.error(chalk_1.default.red("Error cloning environment:"), error.response.data.error);
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
console.error(chalk_1.default.red("Error cloning environment:"), error.message || error);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
});
|