genbox 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.
- package/dist/api.js +42 -4
- package/dist/commands/create.js +20 -1
- package/dist/commands/destroy.js +9 -0
- package/dist/commands/list.js +9 -0
- package/package.json +1 -1
package/dist/api.js
CHANGED
|
@@ -1,8 +1,43 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.AuthenticationError = void 0;
|
|
7
|
+
exports.handleApiError = handleApiError;
|
|
8
|
+
exports.isAuthError = isAuthError;
|
|
3
9
|
exports.fetchApi = fetchApi;
|
|
10
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
4
11
|
const config_store_1 = require("./config-store");
|
|
5
12
|
const API_URL = process.env.GENBOX_API_URL || 'https://api.genbox.dev';
|
|
13
|
+
class AuthenticationError extends Error {
|
|
14
|
+
constructor(message) {
|
|
15
|
+
super(message);
|
|
16
|
+
this.name = 'AuthenticationError';
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.AuthenticationError = AuthenticationError;
|
|
20
|
+
/**
|
|
21
|
+
* Handle errors with proper messages for auth errors
|
|
22
|
+
*/
|
|
23
|
+
function handleApiError(error) {
|
|
24
|
+
if (error instanceof AuthenticationError) {
|
|
25
|
+
console.error('');
|
|
26
|
+
console.error(chalk_1.default.red('✖ Not logged in'));
|
|
27
|
+
console.error('');
|
|
28
|
+
console.error(chalk_1.default.yellow(' Please authenticate first:'));
|
|
29
|
+
console.error(chalk_1.default.cyan(' $ genbox login'));
|
|
30
|
+
console.error('');
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
console.error(chalk_1.default.red(`Error: ${error.message}`));
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Check if error is an authentication error
|
|
37
|
+
*/
|
|
38
|
+
function isAuthError(error) {
|
|
39
|
+
return error instanceof AuthenticationError;
|
|
40
|
+
}
|
|
6
41
|
async function fetchApi(endpoint, options = {}) {
|
|
7
42
|
const url = `${API_URL}${endpoint}`;
|
|
8
43
|
const token = config_store_1.ConfigStore.getToken();
|
|
@@ -13,15 +48,18 @@ async function fetchApi(endpoint, options = {}) {
|
|
|
13
48
|
if (token) {
|
|
14
49
|
headers['Authorization'] = `Bearer ${token}`;
|
|
15
50
|
}
|
|
16
|
-
else {
|
|
17
|
-
// Fallback for prototype (optional, or remove if we want forced auth)
|
|
18
|
-
headers['X-User-ID'] = 'user-1 (prototype)';
|
|
19
|
-
}
|
|
20
51
|
const response = await fetch(url, {
|
|
21
52
|
...options,
|
|
22
53
|
headers,
|
|
23
54
|
});
|
|
24
55
|
if (!response.ok) {
|
|
56
|
+
// Handle authentication errors with a friendly message
|
|
57
|
+
if (response.status === 401) {
|
|
58
|
+
throw new AuthenticationError('You are not logged in. Please run `genbox login` first.');
|
|
59
|
+
}
|
|
60
|
+
if (response.status === 403) {
|
|
61
|
+
throw new AuthenticationError('Access denied. Your session may have expired. Please run `genbox login` again.');
|
|
62
|
+
}
|
|
25
63
|
const text = await response.text();
|
|
26
64
|
throw new Error(`API Error (${response.status}): ${text}`);
|
|
27
65
|
}
|
package/dist/commands/create.js
CHANGED
|
@@ -204,7 +204,16 @@ exports.createCommand = new commander_1.Command('create')
|
|
|
204
204
|
console.log(` Destroy: ${chalk_1.default.cyan(`genbox destroy ${name}`)}`);
|
|
205
205
|
}
|
|
206
206
|
catch (innerError) {
|
|
207
|
-
|
|
207
|
+
if (innerError instanceof api_1.AuthenticationError) {
|
|
208
|
+
spinner.fail(chalk_1.default.red('Not logged in'));
|
|
209
|
+
console.error('');
|
|
210
|
+
console.error(chalk_1.default.yellow(' Please authenticate first:'));
|
|
211
|
+
console.error(chalk_1.default.cyan(' $ genbox login'));
|
|
212
|
+
console.error('');
|
|
213
|
+
}
|
|
214
|
+
else {
|
|
215
|
+
spinner.fail(chalk_1.default.red(`Failed to create Genbox '${name}': ${innerError.message}`));
|
|
216
|
+
}
|
|
208
217
|
}
|
|
209
218
|
}
|
|
210
219
|
catch (error) {
|
|
@@ -214,6 +223,16 @@ exports.createCommand = new commander_1.Command('create')
|
|
|
214
223
|
console.log(chalk_1.default.dim('Cancelled.'));
|
|
215
224
|
return;
|
|
216
225
|
}
|
|
226
|
+
// Handle authentication errors with a helpful message
|
|
227
|
+
if (error instanceof api_1.AuthenticationError) {
|
|
228
|
+
console.error('');
|
|
229
|
+
console.error(chalk_1.default.red('✖ Not logged in'));
|
|
230
|
+
console.error('');
|
|
231
|
+
console.error(chalk_1.default.yellow(' Please authenticate first:'));
|
|
232
|
+
console.error(chalk_1.default.cyan(' $ genbox login'));
|
|
233
|
+
console.error('');
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
217
236
|
console.error(chalk_1.default.red(`Error: ${error.message}`));
|
|
218
237
|
}
|
|
219
238
|
});
|
package/dist/commands/destroy.js
CHANGED
|
@@ -57,6 +57,15 @@ exports.destroyCommand = new commander_1.Command('destroy')
|
|
|
57
57
|
console.log(chalk_1.default.dim('Cancelled.'));
|
|
58
58
|
return;
|
|
59
59
|
}
|
|
60
|
+
if (error instanceof api_1.AuthenticationError) {
|
|
61
|
+
console.error('');
|
|
62
|
+
console.error(chalk_1.default.red('✖ Not logged in'));
|
|
63
|
+
console.error('');
|
|
64
|
+
console.error(chalk_1.default.yellow(' Please authenticate first:'));
|
|
65
|
+
console.error(chalk_1.default.cyan(' $ genbox login'));
|
|
66
|
+
console.error('');
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
60
69
|
console.error(chalk_1.default.red(`Error: ${error.message}`));
|
|
61
70
|
}
|
|
62
71
|
});
|
package/dist/commands/list.js
CHANGED
|
@@ -31,6 +31,15 @@ exports.listCommand = new commander_1.Command('list')
|
|
|
31
31
|
console.log(chalk_1.default.dim('----------------------------------------------------'));
|
|
32
32
|
}
|
|
33
33
|
catch (error) {
|
|
34
|
+
if (error instanceof api_1.AuthenticationError) {
|
|
35
|
+
console.error('');
|
|
36
|
+
console.error(chalk_1.default.red('✖ Not logged in'));
|
|
37
|
+
console.error('');
|
|
38
|
+
console.error(chalk_1.default.yellow(' Please authenticate first:'));
|
|
39
|
+
console.error(chalk_1.default.cyan(' $ genbox login'));
|
|
40
|
+
console.error('');
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
34
43
|
console.error(chalk_1.default.red(`Error: ${error.message}`));
|
|
35
44
|
}
|
|
36
45
|
});
|