@codebakers/cli 1.0.1 → 1.0.3
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 +9 -5
- package/package.json +2 -1
package/dist/index.js
CHANGED
|
@@ -19,6 +19,8 @@ import { existsSync } from "fs";
|
|
|
19
19
|
import { join } from "path";
|
|
20
20
|
|
|
21
21
|
// src/utils/api.ts
|
|
22
|
+
import nodeFetch from "node-fetch";
|
|
23
|
+
var fetchFn = typeof fetch !== "undefined" ? fetch : nodeFetch;
|
|
22
24
|
var ApiError = class extends Error {
|
|
23
25
|
constructor(message, statusCode, code) {
|
|
24
26
|
super(message);
|
|
@@ -34,7 +36,7 @@ async function makeRequest(endpoint, options = {}) {
|
|
|
34
36
|
}
|
|
35
37
|
const baseUrl = getApiUrl();
|
|
36
38
|
const url = `${baseUrl}${endpoint}`;
|
|
37
|
-
const response = await
|
|
39
|
+
const response = await fetchFn(url, {
|
|
38
40
|
...options,
|
|
39
41
|
headers: {
|
|
40
42
|
"Content-Type": "application/json",
|
|
@@ -55,7 +57,7 @@ async function makeRequest(endpoint, options = {}) {
|
|
|
55
57
|
async function validateApiKey(apiKey) {
|
|
56
58
|
const baseUrl = getApiUrl();
|
|
57
59
|
try {
|
|
58
|
-
const response = await
|
|
60
|
+
const response = await fetchFn(`${baseUrl}/api/patterns`, {
|
|
59
61
|
headers: {
|
|
60
62
|
Authorization: `Bearer ${apiKey}`
|
|
61
63
|
}
|
|
@@ -155,15 +157,17 @@ function setupCommand(program2) {
|
|
|
155
157
|
const validation = await validateApiKey(apiKey);
|
|
156
158
|
if (!validation.valid) {
|
|
157
159
|
spinner.fail("API key validation failed");
|
|
158
|
-
|
|
160
|
+
const errLower = validation.error?.toLowerCase() || "";
|
|
161
|
+
if (errLower.includes("invalid api key") || validation.error === "HTTP 401") {
|
|
159
162
|
console.log(chalk.red("\nInvalid API key."));
|
|
160
163
|
console.log(chalk.dim("Get your key at: https://codebakers.ai/dashboard"));
|
|
161
|
-
} else if (
|
|
164
|
+
} else if (errLower.includes("enotfound") || errLower.includes("econnrefused") || errLower.includes("unable to connect")) {
|
|
162
165
|
console.log(chalk.red("\nCould not connect to CodeBakers API."));
|
|
163
166
|
console.log(chalk.dim("Check your internet connection and try again."));
|
|
167
|
+
console.log(chalk.dim(`Details: ${validation.error}`));
|
|
164
168
|
} else {
|
|
165
169
|
console.log(chalk.red(`
|
|
166
|
-
|
|
170
|
+
Validation failed: ${validation.error || "Unknown error"}`));
|
|
167
171
|
console.log(chalk.dim("Get your key at: https://codebakers.ai/dashboard"));
|
|
168
172
|
}
|
|
169
173
|
process.exit(1);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codebakers/cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "CodeBakers CLI - AI prompt patterns for production-ready code",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -40,6 +40,7 @@
|
|
|
40
40
|
"commander": "^12.1.0",
|
|
41
41
|
"conf": "^12.0.0",
|
|
42
42
|
"inquirer": "^9.2.23",
|
|
43
|
+
"node-fetch": "^3.3.2",
|
|
43
44
|
"ora": "^8.0.1"
|
|
44
45
|
},
|
|
45
46
|
"devDependencies": {
|