@codebakers/cli 1.0.0 → 1.0.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.
- package/dist/index.js +34 -17
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -54,12 +54,25 @@ async function makeRequest(endpoint, options = {}) {
|
|
|
54
54
|
}
|
|
55
55
|
async function validateApiKey(apiKey) {
|
|
56
56
|
const baseUrl = getApiUrl();
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
57
|
+
try {
|
|
58
|
+
const response = await fetch(`${baseUrl}/api/patterns`, {
|
|
59
|
+
headers: {
|
|
60
|
+
Authorization: `Bearer ${apiKey}`
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
if (response.ok) {
|
|
64
|
+
return { valid: true };
|
|
60
65
|
}
|
|
61
|
-
|
|
62
|
-
|
|
66
|
+
try {
|
|
67
|
+
const data = await response.json();
|
|
68
|
+
return { valid: false, error: data.error || `HTTP ${response.status}` };
|
|
69
|
+
} catch {
|
|
70
|
+
return { valid: false, error: `HTTP ${response.status}` };
|
|
71
|
+
}
|
|
72
|
+
} catch (error) {
|
|
73
|
+
const message = error instanceof Error ? error.message : "Network error";
|
|
74
|
+
return { valid: false, error: message };
|
|
75
|
+
}
|
|
63
76
|
}
|
|
64
77
|
async function listPatterns() {
|
|
65
78
|
return makeRequest("/api/patterns");
|
|
@@ -139,21 +152,25 @@ function setupCommand(program2) {
|
|
|
139
152
|
apiKey = answers.apiKey;
|
|
140
153
|
}
|
|
141
154
|
const spinner = ora("Validating API key...").start();
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
console.log(chalk.
|
|
148
|
-
|
|
155
|
+
const validation = await validateApiKey(apiKey);
|
|
156
|
+
if (!validation.valid) {
|
|
157
|
+
spinner.fail("API key validation failed");
|
|
158
|
+
const errLower = validation.error?.toLowerCase() || "";
|
|
159
|
+
if (errLower.includes("invalid api key") || validation.error === "HTTP 401") {
|
|
160
|
+
console.log(chalk.red("\nInvalid API key."));
|
|
161
|
+
console.log(chalk.dim("Get your key at: https://codebakers.ai/dashboard"));
|
|
162
|
+
} else if (errLower.includes("enotfound") || errLower.includes("econnrefused") || errLower.includes("unable to connect")) {
|
|
163
|
+
console.log(chalk.red("\nCould not connect to CodeBakers API."));
|
|
164
|
+
console.log(chalk.dim("Check your internet connection and try again."));
|
|
165
|
+
console.log(chalk.dim(`Details: ${validation.error}`));
|
|
166
|
+
} else {
|
|
167
|
+
console.log(chalk.red(`
|
|
168
|
+
Validation failed: ${validation.error || "Unknown error"}`));
|
|
169
|
+
console.log(chalk.dim("Get your key at: https://codebakers.ai/dashboard"));
|
|
149
170
|
}
|
|
150
|
-
spinner.succeed("API key validated");
|
|
151
|
-
} catch (error) {
|
|
152
|
-
spinner.fail("Failed to validate API key");
|
|
153
|
-
console.log(chalk.red("\nCould not connect to CodeBakers API."));
|
|
154
|
-
console.log(chalk.dim("Check your internet connection and try again."));
|
|
155
171
|
process.exit(1);
|
|
156
172
|
}
|
|
173
|
+
spinner.succeed("API key validated");
|
|
157
174
|
setApiKey(apiKey);
|
|
158
175
|
console.log(chalk.green("\n\u2713 API key saved\n"));
|
|
159
176
|
let ide = options.ide;
|