@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.
Files changed (2) hide show
  1. package/dist/index.js +34 -17
  2. 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
- const response = await fetch(`${baseUrl}/api/patterns`, {
58
- headers: {
59
- Authorization: `Bearer ${apiKey}`
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
- return response.ok;
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
- try {
143
- const isValid = await validateApiKey(apiKey);
144
- if (!isValid) {
145
- spinner.fail("Invalid API key");
146
- console.log(chalk.red("\nAPI key validation failed."));
147
- console.log(chalk.dim("Get your key at: https://codebakers.ai/settings"));
148
- process.exit(1);
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codebakers/cli",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "CodeBakers CLI - AI prompt patterns for production-ready code",
5
5
  "main": "dist/index.js",
6
6
  "bin": {