@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
|
@@ -50,7 +50,6 @@ import * as path from "path";
|
|
|
50
50
|
import * as os from "os";
|
|
51
51
|
import { load as loadYaml, dump as dumpYaml } from "js-yaml";
|
|
52
52
|
import { getBuildType } from "@layr-labs/ecloud-sdk";
|
|
53
|
-
import * as crypto from "crypto";
|
|
54
53
|
var GLOBAL_CONFIG_FILE = "config.yaml";
|
|
55
54
|
var PROFILE_CACHE_TTL_MS = 24 * 60 * 60 * 1e3;
|
|
56
55
|
function getGlobalConfigDir() {
|
|
@@ -86,39 +85,10 @@ function loadGlobalConfig() {
|
|
|
86
85
|
};
|
|
87
86
|
}
|
|
88
87
|
}
|
|
89
|
-
function saveGlobalConfig(config) {
|
|
90
|
-
const configPath = getGlobalConfigPath();
|
|
91
|
-
const configDir = path.dirname(configPath);
|
|
92
|
-
fs.mkdirSync(configDir, { recursive: true, mode: 493 });
|
|
93
|
-
const content = dumpYaml(config, { lineWidth: -1 });
|
|
94
|
-
fs.writeFileSync(configPath, content, { mode: 420 });
|
|
95
|
-
}
|
|
96
88
|
function getDefaultEnvironment() {
|
|
97
89
|
const config = loadGlobalConfig();
|
|
98
90
|
return config.default_environment;
|
|
99
91
|
}
|
|
100
|
-
function getGlobalTelemetryPreference() {
|
|
101
|
-
const config = loadGlobalConfig();
|
|
102
|
-
return config.telemetry_enabled;
|
|
103
|
-
}
|
|
104
|
-
function getOrCreateUserUUID() {
|
|
105
|
-
const config = loadGlobalConfig();
|
|
106
|
-
if (config.user_uuid) {
|
|
107
|
-
return config.user_uuid;
|
|
108
|
-
}
|
|
109
|
-
const uuid = generateUUID();
|
|
110
|
-
config.user_uuid = uuid;
|
|
111
|
-
config.first_run = false;
|
|
112
|
-
saveGlobalConfig(config);
|
|
113
|
-
return uuid;
|
|
114
|
-
}
|
|
115
|
-
function generateUUID() {
|
|
116
|
-
const bytes = crypto.randomBytes(16);
|
|
117
|
-
bytes[6] = bytes[6] & 15 | 64;
|
|
118
|
-
bytes[8] = bytes[8] & 63 | 128;
|
|
119
|
-
const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, "0"));
|
|
120
|
-
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("");
|
|
121
|
-
}
|
|
122
92
|
|
|
123
93
|
// src/utils/appNames.ts
|
|
124
94
|
import * as fs2 from "fs";
|
|
@@ -164,6 +134,14 @@ function getAppName(environment, appID) {
|
|
|
164
134
|
return "";
|
|
165
135
|
}
|
|
166
136
|
|
|
137
|
+
// src/utils/version.ts
|
|
138
|
+
function getCliVersion() {
|
|
139
|
+
return true ? "0.1.0-rc.2" : "0.0.0";
|
|
140
|
+
}
|
|
141
|
+
function getClientId() {
|
|
142
|
+
return `ecloud-cli/v${getCliVersion()}`;
|
|
143
|
+
}
|
|
144
|
+
|
|
167
145
|
// src/utils/appResolver.ts
|
|
168
146
|
var CHUNK_SIZE = 10;
|
|
169
147
|
async function getAppInfosChunked(userApiClient, appIds, addressCount) {
|
|
@@ -463,66 +441,6 @@ function printAppDisplay(display, log, indent = " ", options = {}) {
|
|
|
463
441
|
|
|
464
442
|
// src/commands/compute/app/list.ts
|
|
465
443
|
import chalk2 from "chalk";
|
|
466
|
-
|
|
467
|
-
// src/telemetry.ts
|
|
468
|
-
import {
|
|
469
|
-
createTelemetryClient,
|
|
470
|
-
createAppEnvironment,
|
|
471
|
-
createMetricsContext,
|
|
472
|
-
addMetric,
|
|
473
|
-
addMetricWithDimensions,
|
|
474
|
-
emitMetrics,
|
|
475
|
-
getBuildType as getBuildType2
|
|
476
|
-
} from "@layr-labs/ecloud-sdk";
|
|
477
|
-
function createCLITelemetryClient() {
|
|
478
|
-
const userUUID = getOrCreateUserUUID();
|
|
479
|
-
const environment = createAppEnvironment(userUUID);
|
|
480
|
-
const telemetryEnabled = getGlobalTelemetryPreference();
|
|
481
|
-
return createTelemetryClient(environment, "ecloud-cli", {
|
|
482
|
-
telemetryEnabled: telemetryEnabled === true
|
|
483
|
-
// Only enabled if explicitly set to true
|
|
484
|
-
});
|
|
485
|
-
}
|
|
486
|
-
async function withTelemetry(command, action) {
|
|
487
|
-
const client = createCLITelemetryClient();
|
|
488
|
-
const metrics = createMetricsContext();
|
|
489
|
-
metrics.properties["source"] = "ecloud-cli";
|
|
490
|
-
metrics.properties["command"] = command.id || command.constructor.name;
|
|
491
|
-
const environment = getDefaultEnvironment() || "sepolia";
|
|
492
|
-
metrics.properties["environment"] = environment;
|
|
493
|
-
const buildType = getBuildType2() || "prod";
|
|
494
|
-
metrics.properties["build_type"] = buildType;
|
|
495
|
-
const cliVersion = command.config.version;
|
|
496
|
-
if (cliVersion) {
|
|
497
|
-
metrics.properties["cli_version"] = cliVersion;
|
|
498
|
-
}
|
|
499
|
-
addMetric(metrics, "Count", 1);
|
|
500
|
-
let actionError;
|
|
501
|
-
let result;
|
|
502
|
-
try {
|
|
503
|
-
result = await action();
|
|
504
|
-
return result;
|
|
505
|
-
} catch (err) {
|
|
506
|
-
actionError = err instanceof Error ? err : new Error(String(err));
|
|
507
|
-
throw err;
|
|
508
|
-
} finally {
|
|
509
|
-
const resultValue = actionError ? "Failure" : "Success";
|
|
510
|
-
const dimensions = {};
|
|
511
|
-
if (actionError) {
|
|
512
|
-
dimensions["error"] = actionError.message;
|
|
513
|
-
}
|
|
514
|
-
addMetricWithDimensions(metrics, resultValue, 1, dimensions);
|
|
515
|
-
const duration = Date.now() - metrics.startTime.getTime();
|
|
516
|
-
addMetric(metrics, "DurationMilliseconds", duration);
|
|
517
|
-
try {
|
|
518
|
-
await emitMetrics(client, metrics);
|
|
519
|
-
await client.close();
|
|
520
|
-
} catch {
|
|
521
|
-
}
|
|
522
|
-
}
|
|
523
|
-
}
|
|
524
|
-
|
|
525
|
-
// src/commands/compute/app/list.ts
|
|
526
444
|
var AppList = class _AppList extends Command {
|
|
527
445
|
static description = "List all deployed apps";
|
|
528
446
|
static flags = {
|
|
@@ -538,121 +456,120 @@ var AppList = class _AppList extends Command {
|
|
|
538
456
|
})
|
|
539
457
|
};
|
|
540
458
|
async run() {
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
this.log(`
|
|
459
|
+
const { flags } = await this.parse(_AppList);
|
|
460
|
+
const validatedFlags = await validateCommonFlags(flags);
|
|
461
|
+
const environment = validatedFlags.environment || "sepolia";
|
|
462
|
+
const environmentConfig = getEnvironmentConfig2(environment);
|
|
463
|
+
const rpcUrl = validatedFlags["rpc-url"] || environmentConfig.defaultRPCURL;
|
|
464
|
+
const privateKey = validatedFlags["private-key"];
|
|
465
|
+
const account = privateKeyToAccount3(privateKey);
|
|
466
|
+
const developerAddr = account.address;
|
|
467
|
+
if (flags.verbose) {
|
|
468
|
+
this.log(`Fetching apps for developer: ${developerAddr}`);
|
|
469
|
+
}
|
|
470
|
+
const result = await getAllAppsByDeveloper3(rpcUrl, environmentConfig, developerAddr);
|
|
471
|
+
if (result.apps.length === 0) {
|
|
472
|
+
this.log(`
|
|
556
473
|
No apps found for developer ${developerAddr}`);
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
}
|
|
566
|
-
filteredApps.push(result.apps[i]);
|
|
567
|
-
filteredConfigs.push(config);
|
|
474
|
+
return;
|
|
475
|
+
}
|
|
476
|
+
const filteredApps = [];
|
|
477
|
+
const filteredConfigs = [];
|
|
478
|
+
for (let i = 0; i < result.apps.length; i++) {
|
|
479
|
+
const config = result.appConfigs[i];
|
|
480
|
+
if (!flags.all && config.status === ContractAppStatusTerminated) {
|
|
481
|
+
continue;
|
|
568
482
|
}
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
483
|
+
filteredApps.push(result.apps[i]);
|
|
484
|
+
filteredConfigs.push(config);
|
|
485
|
+
}
|
|
486
|
+
if (filteredApps.length === 0) {
|
|
487
|
+
if (flags.all) {
|
|
488
|
+
this.log(`
|
|
572
489
|
No apps found for developer ${developerAddr}`);
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
490
|
+
} else {
|
|
491
|
+
this.log(
|
|
492
|
+
`
|
|
576
493
|
No active apps found for developer ${developerAddr} (use --all to show terminated apps)`
|
|
577
|
-
|
|
578
|
-
}
|
|
579
|
-
return;
|
|
494
|
+
);
|
|
580
495
|
}
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
return /* @__PURE__ */ new Map();
|
|
594
|
-
})
|
|
595
|
-
]);
|
|
596
|
-
const blockNumbers = Array.from(releaseBlockNumbers.values()).filter((n) => n > 0);
|
|
597
|
-
const blockTimestamps = blockNumbers.length > 0 ? await getBlockTimestamps(rpcUrl, environmentConfig, blockNumbers).catch((err) => {
|
|
496
|
+
return;
|
|
497
|
+
}
|
|
498
|
+
const userApiClient = new UserApiClient3(environmentConfig, privateKey, rpcUrl, getClientId());
|
|
499
|
+
const addressCount = flags["address-count"];
|
|
500
|
+
const [appInfos, releaseBlockNumbers] = await Promise.all([
|
|
501
|
+
getAppInfosChunked(userApiClient, filteredApps, addressCount).catch((err) => {
|
|
502
|
+
if (flags.verbose) {
|
|
503
|
+
this.warn(`Could not fetch app info from UserAPI: ${err}`);
|
|
504
|
+
}
|
|
505
|
+
return [];
|
|
506
|
+
}),
|
|
507
|
+
getAppLatestReleaseBlockNumbers(rpcUrl, environmentConfig, filteredApps).catch((err) => {
|
|
598
508
|
if (flags.verbose) {
|
|
599
|
-
this.warn(`Could not fetch block
|
|
509
|
+
this.warn(`Could not fetch release block numbers: ${err}`);
|
|
600
510
|
}
|
|
601
511
|
return /* @__PURE__ */ new Map();
|
|
602
|
-
})
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
(info) => info.address && String(info.address).toLowerCase() === appAddr.toLowerCase()
|
|
609
|
-
);
|
|
610
|
-
const profileName = apiInfo?.profile?.name;
|
|
611
|
-
const localName = getAppName(environment, appAddr);
|
|
612
|
-
const appName = profileName || localName;
|
|
613
|
-
const status = apiInfo?.status || getContractStatusString(config.status);
|
|
614
|
-
const releaseBlockNumber = releaseBlockNumbers.get(appAddr);
|
|
615
|
-
const releaseTimestamp = releaseBlockNumber ? blockTimestamps.get(releaseBlockNumber) : void 0;
|
|
616
|
-
appItems.push({ appAddr, apiInfo, appName, status, releaseTimestamp });
|
|
512
|
+
})
|
|
513
|
+
]);
|
|
514
|
+
const blockNumbers = Array.from(releaseBlockNumbers.values()).filter((n) => n > 0);
|
|
515
|
+
const blockTimestamps = blockNumbers.length > 0 ? await getBlockTimestamps(rpcUrl, environmentConfig, blockNumbers).catch((err) => {
|
|
516
|
+
if (flags.verbose) {
|
|
517
|
+
this.warn(`Could not fetch block timestamps: ${err}`);
|
|
617
518
|
}
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
releaseTimestamp
|
|
641
|
-
});
|
|
642
|
-
this.log(` ${display.name}`);
|
|
643
|
-
printAppDisplay(display, this.log.bind(this), " ", {
|
|
644
|
-
singleAddress: true,
|
|
645
|
-
showProfile: false
|
|
646
|
-
});
|
|
647
|
-
if (i < appItems.length - 1) {
|
|
648
|
-
this.log(
|
|
649
|
-
chalk2.gray(" \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500")
|
|
650
|
-
);
|
|
651
|
-
}
|
|
519
|
+
return /* @__PURE__ */ new Map();
|
|
520
|
+
}) : /* @__PURE__ */ new Map();
|
|
521
|
+
const appItems = [];
|
|
522
|
+
for (let i = 0; i < filteredApps.length; i++) {
|
|
523
|
+
const appAddr = filteredApps[i];
|
|
524
|
+
const config = filteredConfigs[i];
|
|
525
|
+
const apiInfo = appInfos.find(
|
|
526
|
+
(info) => info.address && String(info.address).toLowerCase() === appAddr.toLowerCase()
|
|
527
|
+
);
|
|
528
|
+
const profileName = apiInfo?.profile?.name;
|
|
529
|
+
const localName = getAppName(environment, appAddr);
|
|
530
|
+
const appName = profileName || localName;
|
|
531
|
+
const status = apiInfo?.status || getContractStatusString(config.status);
|
|
532
|
+
const releaseBlockNumber = releaseBlockNumbers.get(appAddr);
|
|
533
|
+
const releaseTimestamp = releaseBlockNumber ? blockTimestamps.get(releaseBlockNumber) : void 0;
|
|
534
|
+
appItems.push({ appAddr, apiInfo, appName, status, releaseTimestamp });
|
|
535
|
+
}
|
|
536
|
+
appItems.sort((a, b) => {
|
|
537
|
+
const aPriority = getStatusSortPriority(a.status);
|
|
538
|
+
const bPriority = getStatusSortPriority(b.status);
|
|
539
|
+
if (aPriority !== bPriority) {
|
|
540
|
+
return aPriority - bPriority;
|
|
652
541
|
}
|
|
653
|
-
|
|
654
|
-
|
|
542
|
+
const aTime = a.releaseTimestamp || 0;
|
|
543
|
+
const bTime = b.releaseTimestamp || 0;
|
|
544
|
+
return bTime - aTime;
|
|
655
545
|
});
|
|
546
|
+
console.log();
|
|
547
|
+
this.log(chalk2.bold(`Apps for ${developerAddr} (${environment}):`));
|
|
548
|
+
console.log();
|
|
549
|
+
for (let i = 0; i < appItems.length; i++) {
|
|
550
|
+
const { apiInfo, appName, status, releaseTimestamp } = appItems[i];
|
|
551
|
+
if (!apiInfo) {
|
|
552
|
+
continue;
|
|
553
|
+
}
|
|
554
|
+
const display = formatAppDisplay({
|
|
555
|
+
appInfo: apiInfo,
|
|
556
|
+
appName,
|
|
557
|
+
status,
|
|
558
|
+
releaseTimestamp
|
|
559
|
+
});
|
|
560
|
+
this.log(` ${display.name}`);
|
|
561
|
+
printAppDisplay(display, this.log.bind(this), " ", {
|
|
562
|
+
singleAddress: addressCount === 1,
|
|
563
|
+
showProfile: false
|
|
564
|
+
});
|
|
565
|
+
if (i < appItems.length - 1) {
|
|
566
|
+
this.log(
|
|
567
|
+
chalk2.gray(" \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500")
|
|
568
|
+
);
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
console.log();
|
|
572
|
+
this.log(chalk2.gray(`Total: ${appItems.length} app(s)`));
|
|
656
573
|
}
|
|
657
574
|
};
|
|
658
575
|
export {
|