@codebakers/cli 1.0.0 → 1.0.1

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 +32 -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,23 @@ 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
+ if (validation.error?.includes("Invalid API key")) {
159
+ console.log(chalk.red("\nInvalid API key."));
160
+ console.log(chalk.dim("Get your key at: https://codebakers.ai/dashboard"));
161
+ } else if (validation.error?.includes("fetch") || validation.error?.includes("ENOTFOUND")) {
162
+ console.log(chalk.red("\nCould not connect to CodeBakers API."));
163
+ console.log(chalk.dim("Check your internet connection and try again."));
164
+ } else {
165
+ console.log(chalk.red(`
166
+ Error: ${validation.error || "Unknown error"}`));
167
+ console.log(chalk.dim("Get your key at: https://codebakers.ai/dashboard"));
149
168
  }
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
169
  process.exit(1);
156
170
  }
171
+ spinner.succeed("API key validated");
157
172
  setApiKey(apiKey);
158
173
  console.log(chalk.green("\n\u2713 API key saved\n"));
159
174
  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.1",
4
4
  "description": "CodeBakers CLI - AI prompt patterns for production-ready code",
5
5
  "main": "dist/index.js",
6
6
  "bin": {