@layr-labs/ecloud-cli 0.1.1 → 0.1.2-dev

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 (44) hide show
  1. package/VERSION +2 -2
  2. package/dist/commands/auth/generate.js +2 -2
  3. package/dist/commands/auth/generate.js.map +1 -1
  4. package/dist/commands/auth/login.js.map +1 -1
  5. package/dist/commands/auth/logout.js.map +1 -1
  6. package/dist/commands/auth/migrate.js.map +1 -1
  7. package/dist/commands/auth/whoami.js +5 -3
  8. package/dist/commands/auth/whoami.js.map +1 -1
  9. package/dist/commands/billing/cancel.js +5 -3
  10. package/dist/commands/billing/cancel.js.map +1 -1
  11. package/dist/commands/billing/status.js +5 -3
  12. package/dist/commands/billing/status.js.map +1 -1
  13. package/dist/commands/billing/subscribe.js +10 -6
  14. package/dist/commands/billing/subscribe.js.map +1 -1
  15. package/dist/commands/compute/app/create.js.map +1 -1
  16. package/dist/commands/compute/app/deploy.js +143 -76
  17. package/dist/commands/compute/app/deploy.js.map +1 -1
  18. package/dist/commands/compute/app/info.js +54 -8
  19. package/dist/commands/compute/app/info.js.map +1 -1
  20. package/dist/commands/compute/app/list.js +6 -7
  21. package/dist/commands/compute/app/list.js.map +1 -1
  22. package/dist/commands/compute/app/logs.js +55 -9
  23. package/dist/commands/compute/app/logs.js.map +1 -1
  24. package/dist/commands/compute/app/profile/set.js +141 -20
  25. package/dist/commands/compute/app/profile/set.js.map +1 -1
  26. package/dist/commands/compute/app/start.js +55 -9
  27. package/dist/commands/compute/app/start.js.map +1 -1
  28. package/dist/commands/compute/app/stop.js +55 -9
  29. package/dist/commands/compute/app/stop.js.map +1 -1
  30. package/dist/commands/compute/app/terminate.js +55 -9
  31. package/dist/commands/compute/app/terminate.js.map +1 -1
  32. package/dist/commands/compute/app/upgrade.js +172 -49
  33. package/dist/commands/compute/app/upgrade.js.map +1 -1
  34. package/dist/commands/compute/environment/list.js.map +1 -1
  35. package/dist/commands/compute/environment/set.js.map +1 -1
  36. package/dist/commands/compute/environment/show.js.map +1 -1
  37. package/dist/commands/compute/undelegate.js +6 -7
  38. package/dist/commands/compute/undelegate.js.map +1 -1
  39. package/dist/commands/telemetry/disable.js.map +1 -1
  40. package/dist/commands/telemetry/enable.js.map +1 -1
  41. package/dist/commands/telemetry/status.js.map +1 -1
  42. package/dist/commands/upgrade.js.map +1 -1
  43. package/dist/commands/version.js.map +1 -1
  44. package/package.json +3 -2
@@ -2,10 +2,11 @@
2
2
 
3
3
  // src/commands/compute/app/profile/set.ts
4
4
  import { Command, Args, Flags as Flags2 } from "@oclif/core";
5
- import { getEnvironmentConfig as getEnvironmentConfig2, UserApiClient as UserApiClient3 } from "@layr-labs/ecloud-sdk";
5
+ import { getEnvironmentConfig as getEnvironmentConfig3 } from "@layr-labs/ecloud-sdk";
6
6
 
7
7
  // src/flags.ts
8
8
  import { Flags } from "@oclif/core";
9
+ import { getBuildType as getBuildType2 } from "@layr-labs/ecloud-sdk";
9
10
 
10
11
  // src/utils/prompts.ts
11
12
  import { input, select, password, confirm as inquirerConfirm } from "@inquirer/prompts";
@@ -87,6 +88,27 @@ function saveGlobalConfig(config) {
87
88
  const content = dumpYaml(config, { lineWidth: -1 });
88
89
  fs.writeFileSync(configPath, content, { mode: 420 });
89
90
  }
91
+ function normalizeDirectoryPath(directoryPath) {
92
+ const resolved = path.resolve(directoryPath);
93
+ try {
94
+ return fs.realpathSync(resolved);
95
+ } catch {
96
+ return resolved;
97
+ }
98
+ }
99
+ function getLinkedAppForDirectory(environment, directoryPath) {
100
+ if (!directoryPath) {
101
+ return null;
102
+ }
103
+ const config = loadGlobalConfig();
104
+ const links = config.directory_links?.[environment];
105
+ if (!links) {
106
+ return null;
107
+ }
108
+ const normalizedPath = normalizeDirectoryPath(directoryPath);
109
+ const appId = links[normalizedPath];
110
+ return appId || null;
111
+ }
90
112
  function getDefaultEnvironment() {
91
113
  const config = loadGlobalConfig();
92
114
  return config.default_environment;
@@ -232,7 +254,7 @@ function listApps(environment) {
232
254
 
233
255
  // src/utils/version.ts
234
256
  function getCliVersion() {
235
- return true ? "0.1.1" : "0.0.0";
257
+ return true ? "0.1.2-dev" : "0.0.0";
236
258
  }
237
259
  function getClientId() {
238
260
  return `ecloud-cli/v${getCliVersion()}`;
@@ -423,6 +445,9 @@ function addHexPrefix(value) {
423
445
  }
424
446
  return `0x${value}`;
425
447
  }
448
+ function getCurrentProjectPath() {
449
+ return process.env.INIT_CWD || process.cwd();
450
+ }
426
451
  var ContractAppStatusStarted = 1;
427
452
  var ContractAppStatusStopped = 2;
428
453
  var ContractAppStatusTerminated = 3;
@@ -589,7 +614,19 @@ Select an app to ${action}:
589
614
  index: i
590
615
  });
591
616
  }
617
+ const linkedAppId = getLinkedAppForDirectory(environment, getCurrentProjectPath());
618
+ const normalizedLinkedAppId = linkedAppId ? linkedAppId.toLowerCase() : "";
592
619
  appItems.sort((a, b) => {
620
+ if (normalizedLinkedAppId) {
621
+ const aLinked = String(a.addr).toLowerCase() === normalizedLinkedAppId;
622
+ const bLinked = String(b.addr).toLowerCase() === normalizedLinkedAppId;
623
+ if (aLinked && !bLinked) {
624
+ return -1;
625
+ }
626
+ if (bLinked && !aLinked) {
627
+ return 1;
628
+ }
629
+ }
593
630
  const aPriority = getStatusPriority(a.status, false);
594
631
  const bPriority = getStatusPriority(b.status, false);
595
632
  if (aPriority !== bPriority) {
@@ -655,7 +692,18 @@ async function getAppIDInteractiveFromRegistry(environment, action) {
655
692
  }
656
693
  throw new Error(`Invalid app ID address: ${appIDInput}`);
657
694
  }
658
- const choices = Object.entries(allApps).map(([name, appID]) => {
695
+ const entries = Object.entries(allApps);
696
+ const linkedAppId = getLinkedAppForDirectory(environment, getCurrentProjectPath());
697
+ if (linkedAppId) {
698
+ const linkedIndex = entries.findIndex(
699
+ ([, appId]) => String(appId).toLowerCase() === linkedAppId.toLowerCase()
700
+ );
701
+ if (linkedIndex > 0) {
702
+ const [linkedEntry] = entries.splice(linkedIndex, 1);
703
+ entries.unshift(linkedEntry);
704
+ }
705
+ }
706
+ const choices = entries.map(([name, appID]) => {
659
707
  const displayName = `${name} (${appID})`;
660
708
  return { name: displayName, value: appID };
661
709
  });
@@ -703,8 +751,8 @@ async function getPrivateKeyInteractive(privateKey) {
703
751
  }
704
752
  return privateKey;
705
753
  }
706
- const { getPrivateKeyWithSource } = await import("@layr-labs/ecloud-sdk");
707
- const result = await getPrivateKeyWithSource({ privateKey: void 0 });
754
+ const { getPrivateKeyWithSource: getPrivateKeyWithSource2 } = await import("@layr-labs/ecloud-sdk");
755
+ const result = await getPrivateKeyWithSource2({ privateKey: void 0 });
708
756
  if (result) {
709
757
  return result.key;
710
758
  }
@@ -723,6 +771,50 @@ async function getPrivateKeyInteractive(privateKey) {
723
771
  });
724
772
  return key.trim();
725
773
  }
774
+ async function getEnvironmentInteractive(environment) {
775
+ if (environment) {
776
+ try {
777
+ getEnvironmentConfig(environment);
778
+ if (!isEnvironmentAvailable(environment)) {
779
+ throw new Error(`Environment ${environment} is not available in this build`);
780
+ }
781
+ return environment;
782
+ } catch {
783
+ }
784
+ }
785
+ const availableEnvs = getAvailableEnvironments();
786
+ let defaultEnv;
787
+ const configDefaultEnv = getDefaultEnvironment();
788
+ if (configDefaultEnv && availableEnvs.includes(configDefaultEnv)) {
789
+ try {
790
+ getEnvironmentConfig(configDefaultEnv);
791
+ defaultEnv = configDefaultEnv;
792
+ } catch {
793
+ }
794
+ }
795
+ const choices = [];
796
+ if (availableEnvs.includes("sepolia")) {
797
+ choices.push({ name: "sepolia - Ethereum Sepolia testnet", value: "sepolia" });
798
+ }
799
+ if (availableEnvs.includes("sepolia-dev")) {
800
+ choices.push({ name: "sepolia-dev - Ethereum Sepolia testnet (dev)", value: "sepolia-dev" });
801
+ }
802
+ if (availableEnvs.includes("mainnet-alpha")) {
803
+ choices.push({
804
+ name: "mainnet-alpha - Ethereum mainnet (\u26A0\uFE0F uses real funds)",
805
+ value: "mainnet-alpha"
806
+ });
807
+ }
808
+ if (choices.length === 0) {
809
+ throw new Error("No environments available in this build");
810
+ }
811
+ const env = await select({
812
+ message: "Select environment:",
813
+ choices,
814
+ default: defaultEnv
815
+ });
816
+ return env;
817
+ }
726
818
  var MAX_DESCRIPTION_LENGTH = 1e3;
727
819
  var MAX_IMAGE_SIZE = 4 * 1024 * 1024;
728
820
  var VALID_IMAGE_EXTENSIONS = [".jpg", ".jpeg", ".png"];
@@ -985,7 +1077,8 @@ var commonFlags = {
985
1077
  environment: Flags.string({
986
1078
  required: false,
987
1079
  description: "Deployment environment to use",
988
- env: "ECLOUD_ENV"
1080
+ env: "ECLOUD_ENV",
1081
+ default: async () => getDefaultEnvironment() || (getBuildType2() === "dev" ? "sepolia-dev" : "sepolia")
989
1082
  }),
990
1083
  "private-key": Flags.string({
991
1084
  required: false,
@@ -1003,6 +1096,41 @@ var commonFlags = {
1003
1096
  default: false
1004
1097
  })
1005
1098
  };
1099
+ async function validateCommonFlags(flags) {
1100
+ flags["environment"] = await getEnvironmentInteractive(flags["environment"]);
1101
+ flags["private-key"] = await getPrivateKeyInteractive(flags["private-key"]);
1102
+ return flags;
1103
+ }
1104
+
1105
+ // src/client.ts
1106
+ import {
1107
+ createComputeModule,
1108
+ createBillingModule,
1109
+ getEnvironmentConfig as getEnvironmentConfig2,
1110
+ requirePrivateKey,
1111
+ getPrivateKeyWithSource
1112
+ } from "@layr-labs/ecloud-sdk";
1113
+ async function createComputeClient(flags) {
1114
+ flags = await validateCommonFlags(flags);
1115
+ const environment = flags.environment;
1116
+ const environmentConfig = getEnvironmentConfig2(environment);
1117
+ const rpcUrl = flags["rpc-url"] || environmentConfig.defaultRPCURL;
1118
+ const { key: privateKey, source } = await requirePrivateKey({
1119
+ privateKey: flags["private-key"]
1120
+ });
1121
+ if (flags.verbose) {
1122
+ console.log(`Using private key from: ${source}`);
1123
+ }
1124
+ return createComputeModule({
1125
+ verbose: flags.verbose,
1126
+ privateKey,
1127
+ rpcUrl,
1128
+ environment,
1129
+ clientId: getClientId(),
1130
+ skipTelemetry: true
1131
+ // CLI already has telemetry, skip SDK telemetry
1132
+ });
1133
+ }
1006
1134
 
1007
1135
  // src/commands/compute/app/profile/set.ts
1008
1136
  import chalk from "chalk";
@@ -1015,7 +1143,7 @@ import {
1015
1143
  addMetric,
1016
1144
  addMetricWithDimensions,
1017
1145
  emitMetrics,
1018
- getBuildType as getBuildType2
1146
+ getBuildType as getBuildType3
1019
1147
  } from "@layr-labs/ecloud-sdk";
1020
1148
  function createCLITelemetryClient() {
1021
1149
  const userUUID = getOrCreateUserUUID();
@@ -1033,7 +1161,7 @@ async function withTelemetry(command, action) {
1033
1161
  metrics.properties["command"] = command.id || command.constructor.name;
1034
1162
  const environment = getDefaultEnvironment() || "sepolia";
1035
1163
  metrics.properties["environment"] = environment;
1036
- const buildType = getBuildType2() || "prod";
1164
+ const buildType = getBuildType3() || "prod";
1037
1165
  metrics.properties["build_type"] = buildType;
1038
1166
  const cliVersion = command.config.version;
1039
1167
  if (cliVersion) {
@@ -1100,10 +1228,11 @@ var ProfileSet = class _ProfileSet extends Command {
1100
1228
  async run() {
1101
1229
  return withTelemetry(this, async () => {
1102
1230
  const { args, flags } = await this.parse(_ProfileSet);
1103
- const environment = flags.environment || "sepolia";
1104
- const environmentConfig = getEnvironmentConfig2(environment);
1231
+ const compute = await createComputeClient(flags);
1232
+ const environment = flags.environment;
1233
+ const environmentConfig = getEnvironmentConfig3(environment);
1105
1234
  const rpcUrl = flags["rpc-url"] || environmentConfig.defaultRPCURL;
1106
- const privateKey = await getPrivateKeyInteractive(flags["private-key"]);
1235
+ const privateKey = flags["private-key"];
1107
1236
  const resolver = createAppResolver(environment, environmentConfig, privateKey, rpcUrl);
1108
1237
  const appId = await getOrPromptAppID({
1109
1238
  appID: args["app-id"],
@@ -1143,16 +1272,8 @@ ${chalk.gray("Profile setup cancelled")}`);
1143
1272
  }
1144
1273
  }
1145
1274
  this.log("\nUploading app profile...");
1146
- const userApiClient = new UserApiClient3(environmentConfig, privateKey, rpcUrl);
1147
1275
  try {
1148
- const response = await userApiClient.uploadAppProfile(
1149
- appId,
1150
- profile.name,
1151
- profile.website,
1152
- profile.description,
1153
- profile.xURL,
1154
- profile.imagePath
1155
- );
1276
+ const response = await compute.app.setProfile(appId, profile);
1156
1277
  resolver.updateCacheEntry(appId, response.name);
1157
1278
  invalidateProfileCache(environment);
1158
1279
  this.log(`