genbox 1.0.42 → 1.0.43
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/commands/create.js +44 -0
- package/package.json +1 -1
package/dist/commands/create.js
CHANGED
|
@@ -51,6 +51,20 @@ const ssh_config_1 = require("../ssh-config");
|
|
|
51
51
|
const schema_v4_1 = require("../schema-v4");
|
|
52
52
|
const child_process_1 = require("child_process");
|
|
53
53
|
const random_name_1 = require("../random-name");
|
|
54
|
+
// Credits consumed per hour for each size (matches API billing.config.ts)
|
|
55
|
+
const CREDITS_PER_HOUR = {
|
|
56
|
+
cx22: 1,
|
|
57
|
+
cx32: 2,
|
|
58
|
+
cx42: 4,
|
|
59
|
+
cx52: 8,
|
|
60
|
+
small: 1,
|
|
61
|
+
medium: 2,
|
|
62
|
+
large: 4,
|
|
63
|
+
xl: 8,
|
|
64
|
+
};
|
|
65
|
+
function getCreditsPerHour(size) {
|
|
66
|
+
return CREDITS_PER_HOUR[size.toLowerCase()] || 2; // Default to medium
|
|
67
|
+
}
|
|
54
68
|
/**
|
|
55
69
|
* Spawn a background process to poll for IP and add SSH config
|
|
56
70
|
* This runs detached so the main process can exit immediately
|
|
@@ -296,11 +310,41 @@ exports.createCommand = new commander_1.Command('create')
|
|
|
296
310
|
if (!selectedProfile && !options.yes && !options.dryRun) {
|
|
297
311
|
await profileResolver.askSaveProfile(config, resolved);
|
|
298
312
|
}
|
|
313
|
+
// Calculate credits that will be consumed
|
|
314
|
+
const creditsPerHour = getCreditsPerHour(resolved.size);
|
|
315
|
+
// Fetch user's current credit balance
|
|
316
|
+
let userCredits = 0;
|
|
317
|
+
let addonCredits = 0;
|
|
318
|
+
try {
|
|
319
|
+
const user = await (0, api_1.fetchApi)('/users/me');
|
|
320
|
+
userCredits = user.credits || 0;
|
|
321
|
+
addonCredits = user.addonCredits || 0;
|
|
322
|
+
}
|
|
323
|
+
catch {
|
|
324
|
+
// Continue without balance info if fetch fails
|
|
325
|
+
}
|
|
326
|
+
const totalCredits = userCredits + addonCredits;
|
|
327
|
+
const estimatedHours = totalCredits > 0 ? Math.floor(totalCredits / creditsPerHour) : 0;
|
|
328
|
+
// Display billing info
|
|
329
|
+
console.log(chalk_1.default.blue('=== Billing ==='));
|
|
330
|
+
console.log(` Credits to start: ${chalk_1.default.yellow(creditsPerHour)} (${creditsPerHour} credit${creditsPerHour > 1 ? 's' : ''}/hr for ${resolved.size})`);
|
|
331
|
+
if (totalCredits > 0) {
|
|
332
|
+
console.log(` Your balance: ${chalk_1.default.green(totalCredits)} credits${addonCredits > 0 ? chalk_1.default.dim(` (${userCredits} regular + ${addonCredits} addon)`) : ''}`);
|
|
333
|
+
console.log(` After creation: ${chalk_1.default.cyan(totalCredits - creditsPerHour)} credits`);
|
|
334
|
+
console.log(` Estimated runtime: ${chalk_1.default.cyan('~' + estimatedHours + ' hours')}`);
|
|
335
|
+
}
|
|
336
|
+
console.log('');
|
|
299
337
|
// Dry run mode
|
|
300
338
|
if (options.dryRun) {
|
|
301
339
|
console.log(chalk_1.default.yellow('\nDry run mode - no genbox created'));
|
|
302
340
|
return;
|
|
303
341
|
}
|
|
342
|
+
// Check if user has enough credits
|
|
343
|
+
if (totalCredits < creditsPerHour) {
|
|
344
|
+
console.log(chalk_1.default.red(`Insufficient credits. Need ${creditsPerHour}, have ${totalCredits}.`));
|
|
345
|
+
console.log(chalk_1.default.dim('Run `genbox balance` to check your balance or purchase more credits.'));
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
304
348
|
// Confirm creation
|
|
305
349
|
if (!options.yes) {
|
|
306
350
|
const confirm = await prompts.confirm({
|