@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
@@ -11,15 +11,38 @@ import {
11
11
  watchUpgrade
12
12
  } from "@layr-labs/ecloud-sdk";
13
13
 
14
- // src/telemetry.ts
14
+ // src/flags.ts
15
+ import { Flags } from "@oclif/core";
16
+
17
+ // src/utils/prompts.ts
18
+ import { input, select, password, confirm as inquirerConfirm } from "@inquirer/prompts";
19
+ import fs3 from "fs";
20
+ import path3 from "path";
21
+ import os3 from "os";
22
+ import { isAddress as isAddress2 } from "viem";
23
+ import { privateKeyToAccount as privateKeyToAccount2 } from "viem/accounts";
15
24
  import {
16
- createTelemetryClient,
17
- createAppEnvironment,
18
- createMetricsContext,
19
- addMetric,
20
- addMetricWithDimensions,
21
- emitMetrics,
22
- getBuildType as getBuildType2
25
+ getEnvironmentConfig,
26
+ getAvailableEnvironments,
27
+ isEnvironmentAvailable,
28
+ getAllAppsByDeveloper as getAllAppsByDeveloper2,
29
+ getCategoryDescriptions,
30
+ fetchTemplateCatalog,
31
+ PRIMARY_LANGUAGES,
32
+ validateAppName,
33
+ validateImageReference,
34
+ validateFilePath,
35
+ validatePrivateKeyFormat,
36
+ extractAppNameFromImage,
37
+ UserApiClient as UserApiClient2
38
+ } from "@layr-labs/ecloud-sdk";
39
+
40
+ // src/utils/appResolver.ts
41
+ import { isAddress } from "viem";
42
+ import { privateKeyToAccount } from "viem/accounts";
43
+ import {
44
+ UserApiClient,
45
+ getAllAppsByDeveloper
23
46
  } from "@layr-labs/ecloud-sdk";
24
47
 
25
48
  // src/utils/globalConfig.ts
@@ -28,7 +51,6 @@ import * as path from "path";
28
51
  import * as os from "os";
29
52
  import { load as loadYaml, dump as dumpYaml } from "js-yaml";
30
53
  import { getBuildType } from "@layr-labs/ecloud-sdk";
31
- import * as crypto from "crypto";
32
54
  var GLOBAL_CONFIG_FILE = "config.yaml";
33
55
  var PROFILE_CACHE_TTL_MS = 24 * 60 * 60 * 1e3;
34
56
  function getGlobalConfigDir() {
@@ -71,14 +93,6 @@ function saveGlobalConfig(config) {
71
93
  const content = dumpYaml(config, { lineWidth: -1 });
72
94
  fs.writeFileSync(configPath, content, { mode: 420 });
73
95
  }
74
- function getDefaultEnvironment() {
75
- const config = loadGlobalConfig();
76
- return config.default_environment;
77
- }
78
- function getGlobalTelemetryPreference() {
79
- const config = loadGlobalConfig();
80
- return config.telemetry_enabled;
81
- }
82
96
  function getProfileCache(environment) {
83
97
  const config = loadGlobalConfig();
84
98
  const cacheEntry = config.profile_cache?.[environment];
@@ -102,107 +116,6 @@ function setProfileCache(environment, profiles) {
102
116
  };
103
117
  saveGlobalConfig(config);
104
118
  }
105
- function getOrCreateUserUUID() {
106
- const config = loadGlobalConfig();
107
- if (config.user_uuid) {
108
- return config.user_uuid;
109
- }
110
- const uuid = generateUUID();
111
- config.user_uuid = uuid;
112
- config.first_run = false;
113
- saveGlobalConfig(config);
114
- return uuid;
115
- }
116
- function generateUUID() {
117
- const bytes = crypto.randomBytes(16);
118
- bytes[6] = bytes[6] & 15 | 64;
119
- bytes[8] = bytes[8] & 63 | 128;
120
- const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, "0"));
121
- 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("");
122
- }
123
-
124
- // src/telemetry.ts
125
- function createCLITelemetryClient() {
126
- const userUUID = getOrCreateUserUUID();
127
- const environment = createAppEnvironment(userUUID);
128
- const telemetryEnabled = getGlobalTelemetryPreference();
129
- return createTelemetryClient(environment, "ecloud-cli", {
130
- telemetryEnabled: telemetryEnabled === true
131
- // Only enabled if explicitly set to true
132
- });
133
- }
134
- async function withTelemetry(command, action) {
135
- const client = createCLITelemetryClient();
136
- const metrics = createMetricsContext();
137
- metrics.properties["source"] = "ecloud-cli";
138
- metrics.properties["command"] = command.id || command.constructor.name;
139
- const environment = getDefaultEnvironment() || "sepolia";
140
- metrics.properties["environment"] = environment;
141
- const buildType = getBuildType2() || "prod";
142
- metrics.properties["build_type"] = buildType;
143
- const cliVersion = command.config.version;
144
- if (cliVersion) {
145
- metrics.properties["cli_version"] = cliVersion;
146
- }
147
- addMetric(metrics, "Count", 1);
148
- let actionError;
149
- let result;
150
- try {
151
- result = await action();
152
- return result;
153
- } catch (err) {
154
- actionError = err instanceof Error ? err : new Error(String(err));
155
- throw err;
156
- } finally {
157
- const resultValue = actionError ? "Failure" : "Success";
158
- const dimensions = {};
159
- if (actionError) {
160
- dimensions["error"] = actionError.message;
161
- }
162
- addMetricWithDimensions(metrics, resultValue, 1, dimensions);
163
- const duration = Date.now() - metrics.startTime.getTime();
164
- addMetric(metrics, "DurationMilliseconds", duration);
165
- try {
166
- await emitMetrics(client, metrics);
167
- await client.close();
168
- } catch {
169
- }
170
- }
171
- }
172
-
173
- // src/flags.ts
174
- import { Flags } from "@oclif/core";
175
-
176
- // src/utils/prompts.ts
177
- import { input, select, password, confirm as inquirerConfirm } from "@inquirer/prompts";
178
- import fs3 from "fs";
179
- import path3 from "path";
180
- import os3 from "os";
181
- import { isAddress as isAddress2 } from "viem";
182
- import { privateKeyToAccount as privateKeyToAccount2 } from "viem/accounts";
183
- import {
184
- getEnvironmentConfig,
185
- getAvailableEnvironments,
186
- isEnvironmentAvailable,
187
- getAllAppsByDeveloper as getAllAppsByDeveloper2,
188
- getCategoryDescriptions,
189
- fetchTemplateCatalog,
190
- PRIMARY_LANGUAGES,
191
- validateAppName,
192
- validateImageReference,
193
- validateFilePath,
194
- validatePrivateKeyFormat,
195
- extractAppNameFromImage,
196
- UserApiClient as UserApiClient2
197
- } from "@layr-labs/ecloud-sdk";
198
-
199
- // src/utils/appResolver.ts
200
- import { isAddress } from "viem";
201
- import { privateKeyToAccount } from "viem/accounts";
202
- import {
203
- UserApiClient,
204
- getAllAppsByDeveloper
205
- } from "@layr-labs/ecloud-sdk";
206
119
 
207
120
  // src/utils/appNames.ts
208
121
  import * as fs2 from "fs";
@@ -250,7 +163,7 @@ function listApps(environment) {
250
163
 
251
164
  // src/utils/version.ts
252
165
  function getCliVersion() {
253
- return true ? "0.1.0-dev.3" : "0.0.0";
166
+ return true ? "0.1.0-rc.2" : "0.0.0";
254
167
  }
255
168
  function getClientId() {
256
169
  return `ecloud-cli/v${getCliVersion()}`;
@@ -1056,102 +969,88 @@ var AppUpgrade = class _AppUpgrade extends Command {
1056
969
  })
1057
970
  };
1058
971
  async run() {
1059
- return withTelemetry(this, async () => {
1060
- const { args, flags } = await this.parse(_AppUpgrade);
1061
- const logger = {
1062
- info: (msg) => this.log(msg),
1063
- warn: (msg) => this.warn(msg),
1064
- error: (msg) => this.error(msg),
1065
- debug: (msg) => flags.verbose && this.log(msg)
1066
- };
1067
- const environment = flags.environment || "sepolia";
1068
- const environmentConfig = getEnvironmentConfig2(environment);
1069
- const rpcUrl = flags["rpc-url"] || environmentConfig.defaultRPCURL;
1070
- const privateKey = await getPrivateKeyInteractive(flags["private-key"]);
1071
- const appID = await getOrPromptAppID({
1072
- appID: args["app-id"],
1073
- environment,
1074
- privateKey,
1075
- rpcUrl,
1076
- action: "upgrade"
1077
- });
1078
- const dockerfilePath = await getDockerfileInteractive(flags.dockerfile);
1079
- const buildFromDockerfile = dockerfilePath !== "";
1080
- const imageRef = await getImageReferenceInteractive(flags["image-ref"], buildFromDockerfile);
1081
- const envFilePath = await getEnvFileInteractive(flags["env-file"]);
1082
- let currentInstanceType = "";
1083
- try {
1084
- const userApiClient = new UserApiClient3(
1085
- environmentConfig,
1086
- privateKey,
1087
- rpcUrl,
1088
- getClientId()
1089
- );
1090
- const infos = await userApiClient.getInfos([appID], 1);
1091
- if (infos.length > 0) {
1092
- currentInstanceType = infos[0].machineType || "";
1093
- }
1094
- } catch {
972
+ const { args, flags } = await this.parse(_AppUpgrade);
973
+ const logger = {
974
+ info: (msg) => this.log(msg),
975
+ warn: (msg) => this.warn(msg),
976
+ error: (msg) => this.error(msg),
977
+ debug: (msg) => flags.verbose && this.log(msg)
978
+ };
979
+ const environment = flags.environment || "sepolia";
980
+ const environmentConfig = getEnvironmentConfig2(environment);
981
+ const rpcUrl = flags["rpc-url"] || environmentConfig.defaultRPCURL;
982
+ const privateKey = await getPrivateKeyInteractive(flags["private-key"]);
983
+ const appID = await getOrPromptAppID({
984
+ appID: args["app-id"],
985
+ environment,
986
+ privateKey,
987
+ rpcUrl,
988
+ action: "upgrade"
989
+ });
990
+ const dockerfilePath = await getDockerfileInteractive(flags.dockerfile);
991
+ const buildFromDockerfile = dockerfilePath !== "";
992
+ const imageRef = await getImageReferenceInteractive(flags["image-ref"], buildFromDockerfile);
993
+ const envFilePath = await getEnvFileInteractive(flags["env-file"]);
994
+ let currentInstanceType = "";
995
+ try {
996
+ const userApiClient = new UserApiClient3(environmentConfig, privateKey, rpcUrl, getClientId());
997
+ const infos = await userApiClient.getInfos([appID], 1);
998
+ if (infos.length > 0) {
999
+ currentInstanceType = infos[0].machineType || "";
1095
1000
  }
1096
- const availableTypes = await fetchAvailableInstanceTypes(
1097
- environmentConfig,
1001
+ } catch {
1002
+ }
1003
+ const availableTypes = await fetchAvailableInstanceTypes(environmentConfig, privateKey, rpcUrl);
1004
+ const instanceType = await getInstanceTypeInteractive(
1005
+ flags["instance-type"],
1006
+ currentInstanceType,
1007
+ availableTypes
1008
+ );
1009
+ const logSettings = await getLogSettingsInteractive(
1010
+ flags["log-visibility"]
1011
+ );
1012
+ const resourceUsageMonitoring = await getResourceUsageMonitoringInteractive(
1013
+ flags["resource-usage-monitoring"]
1014
+ );
1015
+ const logVisibility = logSettings.publicLogs ? "public" : logSettings.logRedirect ? "private" : "off";
1016
+ const { prepared, gasEstimate } = await prepareUpgrade(
1017
+ {
1018
+ appId: appID,
1098
1019
  privateKey,
1099
- rpcUrl
1100
- );
1101
- const instanceType = await getInstanceTypeInteractive(
1102
- flags["instance-type"],
1103
- currentInstanceType,
1104
- availableTypes
1105
- );
1106
- const logSettings = await getLogSettingsInteractive(
1107
- flags["log-visibility"]
1108
- );
1109
- const resourceUsageMonitoring = await getResourceUsageMonitoringInteractive(
1110
- flags["resource-usage-monitoring"]
1111
- );
1112
- const logVisibility = logSettings.publicLogs ? "public" : logSettings.logRedirect ? "private" : "off";
1113
- const { prepared, gasEstimate } = await prepareUpgrade(
1114
- {
1115
- appId: appID,
1116
- privateKey,
1117
- rpcUrl,
1118
- environment,
1119
- dockerfilePath,
1120
- imageRef,
1121
- envFilePath,
1122
- instanceType,
1123
- logVisibility,
1124
- resourceUsageMonitoring,
1125
- skipTelemetry: true
1126
- },
1127
- logger
1128
- );
1129
- this.log(`
1020
+ rpcUrl,
1021
+ environment,
1022
+ dockerfilePath,
1023
+ imageRef,
1024
+ envFilePath,
1025
+ instanceType,
1026
+ logVisibility,
1027
+ resourceUsageMonitoring
1028
+ },
1029
+ logger
1030
+ );
1031
+ this.log(`
1130
1032
  Estimated transaction cost: ${chalk.cyan(gasEstimate.maxCostEth)} ETH`);
1131
- if (isMainnet(environmentConfig)) {
1132
- const confirmed = await confirm(`Continue with upgrade?`);
1133
- if (!confirmed) {
1134
- this.log(`
1033
+ if (isMainnet(environmentConfig)) {
1034
+ const confirmed = await confirm(`Continue with upgrade?`);
1035
+ if (!confirmed) {
1036
+ this.log(`
1135
1037
  ${chalk.gray(`Upgrade cancelled`)}`);
1136
- return;
1137
- }
1038
+ return;
1138
1039
  }
1139
- const res = await executeUpgrade(
1140
- prepared,
1141
- {
1142
- maxFeePerGas: gasEstimate.maxFeePerGas,
1143
- maxPriorityFeePerGas: gasEstimate.maxPriorityFeePerGas
1144
- },
1145
- logger,
1146
- true
1147
- // skipTelemetry
1148
- );
1149
- await watchUpgrade(res.appId, privateKey, rpcUrl, environment, logger, getClientId(), true);
1150
- this.log(
1151
- `
1040
+ }
1041
+ const res = await executeUpgrade(
1042
+ prepared,
1043
+ {
1044
+ maxFeePerGas: gasEstimate.maxFeePerGas,
1045
+ maxPriorityFeePerGas: gasEstimate.maxPriorityFeePerGas
1046
+ },
1047
+ logger
1048
+ );
1049
+ await watchUpgrade(res.appId, privateKey, rpcUrl, environment, logger, getClientId());
1050
+ this.log(
1051
+ `
1152
1052
  \u2705 ${chalk.green(`App upgraded successfully ${chalk.bold(`(id: ${res.appId}, image: ${res.imageRef})`)}`)}`
1153
- );
1154
- });
1053
+ );
1155
1054
  }
1156
1055
  };
1157
1056
  async function fetchAvailableInstanceTypes(environmentConfig, privateKey, rpcUrl) {