@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.
- package/README.md +4 -4
- package/VERSION +2 -2
- package/dist/commands/auth/generate.js +46 -184
- package/dist/commands/auth/generate.js.map +1 -1
- package/dist/commands/auth/login.js +93 -234
- package/dist/commands/auth/login.js.map +1 -1
- package/dist/commands/auth/logout.js +30 -170
- package/dist/commands/auth/logout.js.map +1 -1
- package/dist/commands/auth/migrate.js +76 -216
- package/dist/commands/auth/migrate.js.map +1 -1
- package/dist/commands/auth/whoami.js +17 -145
- package/dist/commands/auth/whoami.js.map +1 -1
- package/dist/commands/billing/cancel.js +30 -164
- package/dist/commands/billing/cancel.js.map +1 -1
- package/dist/commands/billing/status.js +80 -213
- package/dist/commands/billing/status.js.map +1 -1
- package/dist/commands/billing/subscribe.js +45 -179
- package/dist/commands/billing/subscribe.js.map +1 -1
- package/dist/commands/compute/app/create.js +20 -148
- package/dist/commands/compute/app/create.js.map +1 -1
- package/dist/commands/compute/app/deploy.js +145 -243
- package/dist/commands/compute/app/deploy.js.map +1 -1
- package/dist/commands/compute/app/info.js +1 -2
- package/dist/commands/compute/app/info.js.map +1 -1
- package/dist/commands/compute/app/list.js +111 -194
- package/dist/commands/compute/app/list.js.map +1 -1
- package/dist/commands/compute/app/logs.js +20 -105
- package/dist/commands/compute/app/logs.js.map +1 -1
- package/dist/commands/compute/app/profile/set.js +64 -153
- package/dist/commands/compute/app/profile/set.js.map +1 -1
- package/dist/commands/compute/app/start.js +43 -132
- package/dist/commands/compute/app/start.js.map +1 -1
- package/dist/commands/compute/app/stop.js +43 -132
- package/dist/commands/compute/app/stop.js.map +1 -1
- package/dist/commands/compute/app/terminate.js +44 -131
- package/dist/commands/compute/app/terminate.js.map +1 -1
- package/dist/commands/compute/app/upgrade.js +108 -209
- package/dist/commands/compute/app/upgrade.js.map +1 -1
- package/dist/commands/compute/environment/list.js +12 -104
- package/dist/commands/compute/environment/list.js.map +1 -1
- package/dist/commands/compute/environment/set.js +18 -103
- package/dist/commands/compute/environment/set.js.map +1 -1
- package/dist/commands/compute/environment/show.js +30 -122
- package/dist/commands/compute/environment/show.js.map +1 -1
- package/dist/commands/compute/undelegate.js +18 -112
- package/dist/commands/compute/undelegate.js.map +1 -1
- package/dist/commands/upgrade.js +19 -159
- package/dist/commands/upgrade.js.map +1 -1
- package/dist/commands/version.js +23 -163
- package/dist/commands/version.js.map +1 -1
- package/package.json +2 -2
- package/dist/commands/telemetry.js +0 -213
- package/dist/commands/telemetry.js.map +0 -1
|
@@ -6,7 +6,7 @@ import { isSubscriptionActive } from "@layr-labs/ecloud-sdk";
|
|
|
6
6
|
|
|
7
7
|
// src/client.ts
|
|
8
8
|
import {
|
|
9
|
-
|
|
9
|
+
createAppModule,
|
|
10
10
|
createBillingModule,
|
|
11
11
|
getEnvironmentConfig as getEnvironmentConfig2,
|
|
12
12
|
requirePrivateKey,
|
|
@@ -53,75 +53,7 @@ import * as path from "path";
|
|
|
53
53
|
import * as os from "os";
|
|
54
54
|
import { load as loadYaml, dump as dumpYaml } from "js-yaml";
|
|
55
55
|
import { getBuildType } from "@layr-labs/ecloud-sdk";
|
|
56
|
-
import * as crypto from "crypto";
|
|
57
|
-
var GLOBAL_CONFIG_FILE = "config.yaml";
|
|
58
56
|
var PROFILE_CACHE_TTL_MS = 24 * 60 * 60 * 1e3;
|
|
59
|
-
function getGlobalConfigDir() {
|
|
60
|
-
const configHome = process.env.XDG_CONFIG_HOME;
|
|
61
|
-
let baseDir;
|
|
62
|
-
if (configHome && path.isAbsolute(configHome)) {
|
|
63
|
-
baseDir = configHome;
|
|
64
|
-
} else {
|
|
65
|
-
baseDir = path.join(os.homedir(), ".config");
|
|
66
|
-
}
|
|
67
|
-
const buildType = getBuildType();
|
|
68
|
-
const buildSuffix = buildType === "dev" ? "-dev" : "";
|
|
69
|
-
const configDirName = `ecloud${buildSuffix}`;
|
|
70
|
-
return path.join(baseDir, configDirName);
|
|
71
|
-
}
|
|
72
|
-
function getGlobalConfigPath() {
|
|
73
|
-
return path.join(getGlobalConfigDir(), GLOBAL_CONFIG_FILE);
|
|
74
|
-
}
|
|
75
|
-
function loadGlobalConfig() {
|
|
76
|
-
const configPath = getGlobalConfigPath();
|
|
77
|
-
if (!fs.existsSync(configPath)) {
|
|
78
|
-
return {
|
|
79
|
-
first_run: true
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
try {
|
|
83
|
-
const content = fs.readFileSync(configPath, "utf-8");
|
|
84
|
-
const config = loadYaml(content);
|
|
85
|
-
return config || { first_run: true };
|
|
86
|
-
} catch {
|
|
87
|
-
return {
|
|
88
|
-
first_run: true
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
function saveGlobalConfig(config) {
|
|
93
|
-
const configPath = getGlobalConfigPath();
|
|
94
|
-
const configDir = path.dirname(configPath);
|
|
95
|
-
fs.mkdirSync(configDir, { recursive: true, mode: 493 });
|
|
96
|
-
const content = dumpYaml(config, { lineWidth: -1 });
|
|
97
|
-
fs.writeFileSync(configPath, content, { mode: 420 });
|
|
98
|
-
}
|
|
99
|
-
function getDefaultEnvironment() {
|
|
100
|
-
const config = loadGlobalConfig();
|
|
101
|
-
return config.default_environment;
|
|
102
|
-
}
|
|
103
|
-
function getGlobalTelemetryPreference() {
|
|
104
|
-
const config = loadGlobalConfig();
|
|
105
|
-
return config.telemetry_enabled;
|
|
106
|
-
}
|
|
107
|
-
function getOrCreateUserUUID() {
|
|
108
|
-
const config = loadGlobalConfig();
|
|
109
|
-
if (config.user_uuid) {
|
|
110
|
-
return config.user_uuid;
|
|
111
|
-
}
|
|
112
|
-
const uuid = generateUUID();
|
|
113
|
-
config.user_uuid = uuid;
|
|
114
|
-
config.first_run = false;
|
|
115
|
-
saveGlobalConfig(config);
|
|
116
|
-
return uuid;
|
|
117
|
-
}
|
|
118
|
-
function generateUUID() {
|
|
119
|
-
const bytes = crypto.randomBytes(16);
|
|
120
|
-
bytes[6] = bytes[6] & 15 | 64;
|
|
121
|
-
bytes[8] = bytes[8] & 63 | 128;
|
|
122
|
-
const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, "0"));
|
|
123
|
-
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("");
|
|
124
|
-
}
|
|
125
57
|
|
|
126
58
|
// src/utils/appNames.ts
|
|
127
59
|
import * as fs2 from "fs";
|
|
@@ -193,75 +125,13 @@ async function createBillingClient(flags) {
|
|
|
193
125
|
const privateKey = await getPrivateKeyInteractive(result?.key);
|
|
194
126
|
return createBillingModule({
|
|
195
127
|
verbose: flags.verbose ?? false,
|
|
196
|
-
privateKey
|
|
197
|
-
skipTelemetry: true
|
|
198
|
-
// CLI already has telemetry, skip SDK telemetry
|
|
128
|
+
privateKey
|
|
199
129
|
});
|
|
200
130
|
}
|
|
201
131
|
|
|
202
132
|
// src/commands/billing/subscribe.ts
|
|
203
133
|
import chalk from "chalk";
|
|
204
134
|
import open from "open";
|
|
205
|
-
|
|
206
|
-
// src/telemetry.ts
|
|
207
|
-
import {
|
|
208
|
-
createTelemetryClient,
|
|
209
|
-
createAppEnvironment,
|
|
210
|
-
createMetricsContext,
|
|
211
|
-
addMetric,
|
|
212
|
-
addMetricWithDimensions,
|
|
213
|
-
emitMetrics,
|
|
214
|
-
getBuildType as getBuildType2
|
|
215
|
-
} from "@layr-labs/ecloud-sdk";
|
|
216
|
-
function createCLITelemetryClient() {
|
|
217
|
-
const userUUID = getOrCreateUserUUID();
|
|
218
|
-
const environment = createAppEnvironment(userUUID);
|
|
219
|
-
const telemetryEnabled = getGlobalTelemetryPreference();
|
|
220
|
-
return createTelemetryClient(environment, "ecloud-cli", {
|
|
221
|
-
telemetryEnabled: telemetryEnabled === true
|
|
222
|
-
// Only enabled if explicitly set to true
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
async function withTelemetry(command, action) {
|
|
226
|
-
const client = createCLITelemetryClient();
|
|
227
|
-
const metrics = createMetricsContext();
|
|
228
|
-
metrics.properties["source"] = "ecloud-cli";
|
|
229
|
-
metrics.properties["command"] = command.id || command.constructor.name;
|
|
230
|
-
const environment = getDefaultEnvironment() || "sepolia";
|
|
231
|
-
metrics.properties["environment"] = environment;
|
|
232
|
-
const buildType = getBuildType2() || "prod";
|
|
233
|
-
metrics.properties["build_type"] = buildType;
|
|
234
|
-
const cliVersion = command.config.version;
|
|
235
|
-
if (cliVersion) {
|
|
236
|
-
metrics.properties["cli_version"] = cliVersion;
|
|
237
|
-
}
|
|
238
|
-
addMetric(metrics, "Count", 1);
|
|
239
|
-
let actionError;
|
|
240
|
-
let result;
|
|
241
|
-
try {
|
|
242
|
-
result = await action();
|
|
243
|
-
return result;
|
|
244
|
-
} catch (err) {
|
|
245
|
-
actionError = err instanceof Error ? err : new Error(String(err));
|
|
246
|
-
throw err;
|
|
247
|
-
} finally {
|
|
248
|
-
const resultValue = actionError ? "Failure" : "Success";
|
|
249
|
-
const dimensions = {};
|
|
250
|
-
if (actionError) {
|
|
251
|
-
dimensions["error"] = actionError.message;
|
|
252
|
-
}
|
|
253
|
-
addMetricWithDimensions(metrics, resultValue, 1, dimensions);
|
|
254
|
-
const duration = Date.now() - metrics.startTime.getTime();
|
|
255
|
-
addMetric(metrics, "DurationMilliseconds", duration);
|
|
256
|
-
try {
|
|
257
|
-
await emitMetrics(client, metrics);
|
|
258
|
-
await client.close();
|
|
259
|
-
} catch {
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
// src/commands/billing/subscribe.ts
|
|
265
135
|
var PAYMENT_TIMEOUT_MS = 5 * 60 * 1e3;
|
|
266
136
|
var POLL_INTERVAL_MS = 3e3;
|
|
267
137
|
var BillingSubscribe = class _BillingSubscribe extends Command {
|
|
@@ -278,66 +148,62 @@ var BillingSubscribe = class _BillingSubscribe extends Command {
|
|
|
278
148
|
})
|
|
279
149
|
};
|
|
280
150
|
async run() {
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
this.debug(`
|
|
151
|
+
const { flags } = await this.parse(_BillingSubscribe);
|
|
152
|
+
const billing = await createBillingClient(flags);
|
|
153
|
+
this.debug(`
|
|
285
154
|
Checking subscription status for ${flags.product}...`);
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
155
|
+
const result = await billing.subscribe({
|
|
156
|
+
productId: flags.product
|
|
157
|
+
});
|
|
158
|
+
if (result.type === "already_active") {
|
|
159
|
+
this.log(`
|
|
291
160
|
${chalk.green("\u2713")} You're already subscribed to ${flags.product}.`);
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
161
|
+
this.log(chalk.gray("Run 'ecloud billing status' for details."));
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
if (result.type === "payment_issue") {
|
|
165
|
+
this.log(
|
|
166
|
+
`
|
|
298
167
|
${chalk.yellow("\u26A0")} You already have a subscription on ${flags.product}, but it has a payment issue.`
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
168
|
+
);
|
|
169
|
+
this.log("Please update your payment method to restore access.");
|
|
170
|
+
if (result.portalUrl) {
|
|
171
|
+
this.log(`
|
|
303
172
|
${chalk.bold("Update payment method:")}`);
|
|
304
|
-
|
|
305
|
-
}
|
|
306
|
-
return;
|
|
173
|
+
this.log(` ${result.portalUrl}`);
|
|
307
174
|
}
|
|
308
|
-
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
this.log(`
|
|
309
178
|
${chalk.gray("Opening checkout in your browser...")}`);
|
|
310
|
-
|
|
179
|
+
this.log(chalk.gray(`
|
|
311
180
|
URL: ${result.checkoutUrl}`));
|
|
312
|
-
|
|
313
|
-
|
|
181
|
+
await open(result.checkoutUrl);
|
|
182
|
+
this.log(`
|
|
314
183
|
${chalk.gray("Waiting for payment confirmation...")}`);
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
184
|
+
const startTime = Date.now();
|
|
185
|
+
while (Date.now() - startTime < PAYMENT_TIMEOUT_MS) {
|
|
186
|
+
await new Promise((resolve) => setTimeout(resolve, POLL_INTERVAL_MS));
|
|
187
|
+
try {
|
|
188
|
+
const status = await billing.getStatus({
|
|
189
|
+
productId: flags.product
|
|
190
|
+
});
|
|
191
|
+
if (isSubscriptionActive(status.subscriptionStatus)) {
|
|
192
|
+
this.log(
|
|
193
|
+
`
|
|
325
194
|
${chalk.green("\u2713")} Subscription activated successfully for ${flags.product}!`
|
|
326
|
-
|
|
327
|
-
|
|
195
|
+
);
|
|
196
|
+
this.log(`
|
|
328
197
|
${chalk.gray("Start deploying with:")} ecloud app deploy`);
|
|
329
|
-
|
|
330
|
-
}
|
|
331
|
-
} catch (error) {
|
|
332
|
-
this.debug(`Error polling for subscription status: ${error}`);
|
|
198
|
+
return;
|
|
333
199
|
}
|
|
200
|
+
} catch (error) {
|
|
201
|
+
this.debug(`Error polling for subscription status: ${error}`);
|
|
334
202
|
}
|
|
335
|
-
|
|
203
|
+
}
|
|
204
|
+
this.log(`
|
|
336
205
|
${chalk.yellow("\u26A0")} Payment confirmation timed out after 5 minutes.`);
|
|
337
|
-
|
|
338
|
-
chalk.gray(`If you completed payment, run 'ecloud billing status' to check status.`)
|
|
339
|
-
);
|
|
340
|
-
});
|
|
206
|
+
this.log(chalk.gray(`If you completed payment, run 'ecloud billing status' to check status.`));
|
|
341
207
|
}
|
|
342
208
|
};
|
|
343
209
|
export {
|