@layr-labs/ecloud-cli 0.1.0-dev.3 → 0.1.0-rc.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 (53) hide show
  1. package/README.md +4 -4
  2. package/VERSION +2 -2
  3. package/dist/commands/auth/generate.js +46 -184
  4. package/dist/commands/auth/generate.js.map +1 -1
  5. package/dist/commands/auth/login.js +93 -234
  6. package/dist/commands/auth/login.js.map +1 -1
  7. package/dist/commands/auth/logout.js +30 -170
  8. package/dist/commands/auth/logout.js.map +1 -1
  9. package/dist/commands/auth/migrate.js +76 -216
  10. package/dist/commands/auth/migrate.js.map +1 -1
  11. package/dist/commands/auth/whoami.js +17 -145
  12. package/dist/commands/auth/whoami.js.map +1 -1
  13. package/dist/commands/billing/cancel.js +30 -164
  14. package/dist/commands/billing/cancel.js.map +1 -1
  15. package/dist/commands/billing/status.js +80 -213
  16. package/dist/commands/billing/status.js.map +1 -1
  17. package/dist/commands/billing/subscribe.js +45 -179
  18. package/dist/commands/billing/subscribe.js.map +1 -1
  19. package/dist/commands/compute/app/create.js +20 -148
  20. package/dist/commands/compute/app/create.js.map +1 -1
  21. package/dist/commands/compute/app/deploy.js +145 -243
  22. package/dist/commands/compute/app/deploy.js.map +1 -1
  23. package/dist/commands/compute/app/info.js +1 -2
  24. package/dist/commands/compute/app/info.js.map +1 -1
  25. package/dist/commands/compute/app/list.js +111 -194
  26. package/dist/commands/compute/app/list.js.map +1 -1
  27. package/dist/commands/compute/app/logs.js +20 -105
  28. package/dist/commands/compute/app/logs.js.map +1 -1
  29. package/dist/commands/compute/app/profile/set.js +64 -153
  30. package/dist/commands/compute/app/profile/set.js.map +1 -1
  31. package/dist/commands/compute/app/start.js +43 -132
  32. package/dist/commands/compute/app/start.js.map +1 -1
  33. package/dist/commands/compute/app/stop.js +43 -132
  34. package/dist/commands/compute/app/stop.js.map +1 -1
  35. package/dist/commands/compute/app/terminate.js +44 -131
  36. package/dist/commands/compute/app/terminate.js.map +1 -1
  37. package/dist/commands/compute/app/upgrade.js +108 -209
  38. package/dist/commands/compute/app/upgrade.js.map +1 -1
  39. package/dist/commands/compute/environment/list.js +12 -104
  40. package/dist/commands/compute/environment/list.js.map +1 -1
  41. package/dist/commands/compute/environment/set.js +18 -103
  42. package/dist/commands/compute/environment/set.js.map +1 -1
  43. package/dist/commands/compute/environment/show.js +30 -122
  44. package/dist/commands/compute/environment/show.js.map +1 -1
  45. package/dist/commands/compute/undelegate.js +18 -112
  46. package/dist/commands/compute/undelegate.js.map +1 -1
  47. package/dist/commands/upgrade.js +19 -159
  48. package/dist/commands/upgrade.js.map +1 -1
  49. package/dist/commands/version.js +23 -163
  50. package/dist/commands/version.js.map +1 -1
  51. package/package.json +2 -2
  52. package/dist/commands/telemetry.js +0 -213
  53. package/dist/commands/telemetry.js.map +0 -1
@@ -5,7 +5,7 @@ import { Command, Flags as Flags2 } from "@oclif/core";
5
5
 
6
6
  // src/client.ts
7
7
  import {
8
- createComputeModule,
8
+ createAppModule,
9
9
  createBillingModule,
10
10
  getEnvironmentConfig as getEnvironmentConfig2,
11
11
  requirePrivateKey,
@@ -52,75 +52,7 @@ import * as path from "path";
52
52
  import * as os from "os";
53
53
  import { load as loadYaml, dump as dumpYaml } from "js-yaml";
54
54
  import { getBuildType } from "@layr-labs/ecloud-sdk";
55
- import * as crypto from "crypto";
56
- var GLOBAL_CONFIG_FILE = "config.yaml";
57
55
  var PROFILE_CACHE_TTL_MS = 24 * 60 * 60 * 1e3;
58
- function getGlobalConfigDir() {
59
- const configHome = process.env.XDG_CONFIG_HOME;
60
- let baseDir;
61
- if (configHome && path.isAbsolute(configHome)) {
62
- baseDir = configHome;
63
- } else {
64
- baseDir = path.join(os.homedir(), ".config");
65
- }
66
- const buildType = getBuildType();
67
- const buildSuffix = buildType === "dev" ? "-dev" : "";
68
- const configDirName = `ecloud${buildSuffix}`;
69
- return path.join(baseDir, configDirName);
70
- }
71
- function getGlobalConfigPath() {
72
- return path.join(getGlobalConfigDir(), GLOBAL_CONFIG_FILE);
73
- }
74
- function loadGlobalConfig() {
75
- const configPath = getGlobalConfigPath();
76
- if (!fs.existsSync(configPath)) {
77
- return {
78
- first_run: true
79
- };
80
- }
81
- try {
82
- const content = fs.readFileSync(configPath, "utf-8");
83
- const config = loadYaml(content);
84
- return config || { first_run: true };
85
- } catch {
86
- return {
87
- first_run: true
88
- };
89
- }
90
- }
91
- function saveGlobalConfig(config) {
92
- const configPath = getGlobalConfigPath();
93
- const configDir = path.dirname(configPath);
94
- fs.mkdirSync(configDir, { recursive: true, mode: 493 });
95
- const content = dumpYaml(config, { lineWidth: -1 });
96
- fs.writeFileSync(configPath, content, { mode: 420 });
97
- }
98
- function getDefaultEnvironment() {
99
- const config = loadGlobalConfig();
100
- return config.default_environment;
101
- }
102
- function getGlobalTelemetryPreference() {
103
- const config = loadGlobalConfig();
104
- return config.telemetry_enabled;
105
- }
106
- function getOrCreateUserUUID() {
107
- const config = loadGlobalConfig();
108
- if (config.user_uuid) {
109
- return config.user_uuid;
110
- }
111
- const uuid = generateUUID();
112
- config.user_uuid = uuid;
113
- config.first_run = false;
114
- saveGlobalConfig(config);
115
- return uuid;
116
- }
117
- function generateUUID() {
118
- const bytes = crypto.randomBytes(16);
119
- bytes[6] = bytes[6] & 15 | 64;
120
- bytes[8] = bytes[8] & 63 | 128;
121
- const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, "0"));
122
- return hex.slice(0, 4).join("") + hex.slice(4, 6).join("") + "-" + hex.slice(6, 8).join("") + "-" + hex.slice(8, 10).join("") + "-" + hex.slice(10, 12).join("") + "-" + hex.slice(12, 16).join("");
123
- }
124
56
 
125
57
  // src/utils/appNames.ts
126
58
  import * as fs2 from "fs";
@@ -192,74 +124,12 @@ async function createBillingClient(flags) {
192
124
  const privateKey = await getPrivateKeyInteractive(result?.key);
193
125
  return createBillingModule({
194
126
  verbose: flags.verbose ?? false,
195
- privateKey,
196
- skipTelemetry: true
197
- // CLI already has telemetry, skip SDK telemetry
127
+ privateKey
198
128
  });
199
129
  }
200
130
 
201
131
  // src/commands/billing/status.ts
202
132
  import chalk from "chalk";
203
-
204
- // src/telemetry.ts
205
- import {
206
- createTelemetryClient,
207
- createAppEnvironment,
208
- createMetricsContext,
209
- addMetric,
210
- addMetricWithDimensions,
211
- emitMetrics,
212
- getBuildType as getBuildType2
213
- } from "@layr-labs/ecloud-sdk";
214
- function createCLITelemetryClient() {
215
- const userUUID = getOrCreateUserUUID();
216
- const environment = createAppEnvironment(userUUID);
217
- const telemetryEnabled = getGlobalTelemetryPreference();
218
- return createTelemetryClient(environment, "ecloud-cli", {
219
- telemetryEnabled: telemetryEnabled === true
220
- // Only enabled if explicitly set to true
221
- });
222
- }
223
- async function withTelemetry(command, action) {
224
- const client = createCLITelemetryClient();
225
- const metrics = createMetricsContext();
226
- metrics.properties["source"] = "ecloud-cli";
227
- metrics.properties["command"] = command.id || command.constructor.name;
228
- const environment = getDefaultEnvironment() || "sepolia";
229
- metrics.properties["environment"] = environment;
230
- const buildType = getBuildType2() || "prod";
231
- metrics.properties["build_type"] = buildType;
232
- const cliVersion = command.config.version;
233
- if (cliVersion) {
234
- metrics.properties["cli_version"] = cliVersion;
235
- }
236
- addMetric(metrics, "Count", 1);
237
- let actionError;
238
- let result;
239
- try {
240
- result = await action();
241
- return result;
242
- } catch (err) {
243
- actionError = err instanceof Error ? err : new Error(String(err));
244
- throw err;
245
- } finally {
246
- const resultValue = actionError ? "Failure" : "Success";
247
- const dimensions = {};
248
- if (actionError) {
249
- dimensions["error"] = actionError.message;
250
- }
251
- addMetricWithDimensions(metrics, resultValue, 1, dimensions);
252
- const duration = Date.now() - metrics.startTime.getTime();
253
- addMetric(metrics, "DurationMilliseconds", duration);
254
- try {
255
- await emitMetrics(client, metrics);
256
- await client.close();
257
- } catch {
258
- }
259
- }
260
- }
261
-
262
- // src/commands/billing/status.ts
263
133
  var BillingStatus = class _BillingStatus extends Command {
264
134
  static description = "Show subscription status";
265
135
  static flags = {
@@ -274,95 +144,92 @@ var BillingStatus = class _BillingStatus extends Command {
274
144
  })
275
145
  };
276
146
  async run() {
277
- return withTelemetry(this, async () => {
278
- const { flags } = await this.parse(_BillingStatus);
279
- const billing = await createBillingClient(flags);
280
- const result = await billing.getStatus({
281
- productId: flags.product
282
- });
283
- const formatExpiry = (timestamp) => timestamp ? ` (expires ${new Date(timestamp * 1e3).toLocaleDateString()})` : "";
284
- const formatStatus = (status) => {
285
- switch (status) {
286
- case "active":
287
- return `${chalk.green("\u2713 Active")}`;
288
- case "trialing":
289
- return `${chalk.green("\u2713 Trial")}`;
290
- case "past_due":
291
- return `${chalk.yellow("\u26A0 Past Due")}`;
292
- case "canceled":
293
- return `${chalk.red("\u2717 Canceled")}`;
294
- case "inactive":
295
- return `${chalk.gray("\u2717 Inactive")}`;
296
- case "incomplete":
297
- return `${chalk.yellow("\u26A0 Incomplete")}`;
298
- case "incomplete_expired":
299
- return `${chalk.red("\u2717 Expired")}`;
300
- case "unpaid":
301
- return `${chalk.yellow("\u26A0 Unpaid")}`;
302
- case "paused":
303
- return `${chalk.yellow("\u26A0 Paused")}`;
304
- default:
305
- return status;
306
- }
307
- };
308
- this.log(`
309
- ${chalk.bold("Subscription Status:")}`);
310
- this.log(` Status: ${formatStatus(result.subscriptionStatus)}`);
311
- this.log(` Product: ${result.productId}`);
312
- if (result.currentPeriodStart && result.currentPeriodEnd) {
313
- const startDate = new Date(result.currentPeriodStart).toLocaleDateString();
314
- const endDate = new Date(result.currentPeriodEnd).toLocaleDateString();
315
- this.log(` Current Period: ${startDate} - ${endDate}`);
147
+ const { flags } = await this.parse(_BillingStatus);
148
+ const billing = await createBillingClient(flags);
149
+ const result = await billing.getStatus({
150
+ productId: flags.product
151
+ });
152
+ const formatExpiry = (timestamp) => timestamp ? ` (expires ${new Date(timestamp * 1e3).toLocaleDateString()})` : "";
153
+ const formatStatus = (status) => {
154
+ switch (status) {
155
+ case "active":
156
+ return `${chalk.green("\u2713 Active")}`;
157
+ case "trialing":
158
+ return `${chalk.green("\u2713 Trial")}`;
159
+ case "past_due":
160
+ return `${chalk.yellow("\u26A0 Past Due")}`;
161
+ case "canceled":
162
+ return `${chalk.red("\u2717 Canceled")}`;
163
+ case "inactive":
164
+ return `${chalk.gray("\u2717 Inactive")}`;
165
+ case "incomplete":
166
+ return `${chalk.yellow("\u26A0 Incomplete")}`;
167
+ case "incomplete_expired":
168
+ return `${chalk.red("\u2717 Expired")}`;
169
+ case "unpaid":
170
+ return `${chalk.yellow("\u26A0 Unpaid")}`;
171
+ case "paused":
172
+ return `${chalk.yellow("\u26A0 Paused")}`;
173
+ default:
174
+ return status;
316
175
  }
317
- if (result.lineItems && result.lineItems.length > 0) {
318
- this.log(`
176
+ };
177
+ this.log(`
178
+ ${chalk.bold("Subscription Status:")}`);
179
+ this.log(` Status: ${formatStatus(result.subscriptionStatus)}`);
180
+ this.log(` Product: ${result.productId}`);
181
+ if (result.currentPeriodStart && result.currentPeriodEnd) {
182
+ const startDate = new Date(result.currentPeriodStart).toLocaleDateString();
183
+ const endDate = new Date(result.currentPeriodEnd).toLocaleDateString();
184
+ this.log(` Current Period: ${startDate} - ${endDate}`);
185
+ }
186
+ if (result.lineItems && result.lineItems.length > 0) {
187
+ this.log(`
319
188
  ${chalk.bold(" Line Items:")}`);
320
- for (const item of result.lineItems) {
321
- const product = `${flags.product.charAt(0).toUpperCase()}${flags.product.slice(1)}`;
322
- const chain = item.description.toLowerCase().includes("sepolia") ? "Sepolia" : "Mainnet";
323
- this.log(
324
- ` \u2022 ${product} (${chain}): $${item.subtotal.toFixed(2)} (${item.quantity} vCPU hours \xD7 $${item.price.toFixed(3)}/vCPU hour)`
325
- );
326
- }
189
+ for (const item of result.lineItems) {
190
+ const product = `${flags.product.charAt(0).toUpperCase()}${flags.product.slice(1)}`;
191
+ const chain = item.description.toLowerCase().includes("sepolia") ? "Sepolia" : "Mainnet";
192
+ this.log(
193
+ ` \u2022 ${product} (${chain}): $${item.subtotal.toFixed(2)} (${item.quantity} vCPU hours \xD7 $${item.price.toFixed(3)}/vCPU hour)`
194
+ );
327
195
  }
328
- if (result.creditsApplied !== void 0 && result.creditsApplied > 0) {
329
- this.log(`
196
+ }
197
+ if (result.creditsApplied !== void 0 && result.creditsApplied > 0) {
198
+ this.log(`
330
199
  ${chalk.bold(" Invoice Summary:")}`);
331
- const subtotal = result.upcomingInvoiceSubtotal ?? result.upcomingInvoiceTotal ?? 0;
332
- this.log(` Subtotal: $${subtotal.toFixed(2)}`);
333
- this.log(` Credits Applied: ${chalk.green(`-$${result.creditsApplied.toFixed(2)}`)}`);
334
- this.log(` ${"\u2500".repeat(21)}`);
335
- this.log(` Total Due: $${(result.upcomingInvoiceTotal ?? 0).toFixed(2)}`);
336
- if (result.remainingCredits !== void 0) {
337
- this.log(
338
- `
200
+ const subtotal = result.upcomingInvoiceSubtotal ?? result.upcomingInvoiceTotal ?? 0;
201
+ this.log(` Subtotal: $${subtotal.toFixed(2)}`);
202
+ this.log(` Credits Applied: ${chalk.green(`-$${result.creditsApplied.toFixed(2)}`)}`);
203
+ this.log(` ${"\u2500".repeat(21)}`);
204
+ this.log(` Total Due: $${(result.upcomingInvoiceTotal ?? 0).toFixed(2)}`);
205
+ if (result.remainingCredits !== void 0) {
206
+ this.log(
207
+ `
339
208
  ${chalk.bold("Remaining Credits:")} ${chalk.cyan(`$${result.remainingCredits.toFixed(2)}`)}${formatExpiry(result.nextCreditExpiry)}`
340
- );
341
- }
342
- } else if (result.upcomingInvoiceTotal !== void 0) {
343
- this.log(`
209
+ );
210
+ }
211
+ } else if (result.upcomingInvoiceTotal !== void 0) {
212
+ this.log(`
344
213
  Upcoming Invoice: $${result.upcomingInvoiceTotal.toFixed(2)}`);
345
- if (result.remainingCredits !== void 0 && result.remainingCredits > 0) {
346
- this.log(
347
- ` ${chalk.bold("Available Credits:")} ${chalk.cyan(`$${result.remainingCredits.toFixed(2)}`)}${formatExpiry(result.nextCreditExpiry)}`
348
- );
349
- }
214
+ if (result.remainingCredits !== void 0 && result.remainingCredits > 0) {
215
+ this.log(
216
+ ` ${chalk.bold("Available Credits:")} ${chalk.cyan(`$${result.remainingCredits.toFixed(2)}`)}${formatExpiry(result.nextCreditExpiry)}`
217
+ );
350
218
  }
351
- if (result.cancelAtPeriodEnd) {
352
- this.log(`
219
+ }
220
+ if (result.cancelAtPeriodEnd) {
221
+ this.log(`
353
222
  ${chalk.yellow("\u26A0 Subscription will cancel at period end")}`);
354
- }
355
- if (result.canceledAt) {
356
- const cancelDate = new Date(result.canceledAt).toLocaleDateString();
357
- this.log(` Canceled On: ${cancelDate}`);
358
- }
359
- if (result.portalUrl) {
360
- this.log(`
361
- ${chalk.bold("Payment & Invoices:")}`);
362
- this.log(` ${chalk.cyan(result.portalUrl)}`);
363
- }
364
- this.log();
365
- });
223
+ }
224
+ if (result.canceledAt) {
225
+ const cancelDate = new Date(result.canceledAt).toLocaleDateString();
226
+ this.log(` Canceled On: ${cancelDate}`);
227
+ }
228
+ if (result.portalUrl) {
229
+ this.log(`
230
+ ${chalk.dim("Manage subscription:")} ${chalk.cyan(result.portalUrl)}`);
231
+ }
232
+ this.log();
366
233
  }
367
234
  };
368
235
  export {