@layr-labs/ecloud-cli 0.1.0-rc.1 → 0.1.0
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 +6 -4
- package/VERSION +2 -2
- package/dist/commands/auth/generate.js +184 -46
- package/dist/commands/auth/generate.js.map +1 -1
- package/dist/commands/auth/login.js +234 -93
- package/dist/commands/auth/login.js.map +1 -1
- package/dist/commands/auth/logout.js +170 -30
- package/dist/commands/auth/logout.js.map +1 -1
- package/dist/commands/auth/migrate.js +216 -76
- package/dist/commands/auth/migrate.js.map +1 -1
- package/dist/commands/auth/whoami.js +145 -17
- package/dist/commands/auth/whoami.js.map +1 -1
- package/dist/commands/billing/cancel.js +164 -30
- package/dist/commands/billing/cancel.js.map +1 -1
- package/dist/commands/billing/status.js +213 -80
- package/dist/commands/billing/status.js.map +1 -1
- package/dist/commands/billing/subscribe.js +179 -45
- package/dist/commands/billing/subscribe.js.map +1 -1
- package/dist/commands/compute/app/create.js +148 -20
- package/dist/commands/compute/app/create.js.map +1 -1
- package/dist/commands/compute/app/deploy.js +244 -146
- package/dist/commands/compute/app/deploy.js.map +1 -1
- package/dist/commands/compute/app/info.js +2 -1
- package/dist/commands/compute/app/info.js.map +1 -1
- package/dist/commands/compute/app/list.js +194 -111
- package/dist/commands/compute/app/list.js.map +1 -1
- package/dist/commands/compute/app/logs.js +105 -20
- package/dist/commands/compute/app/logs.js.map +1 -1
- package/dist/commands/compute/app/profile/set.js +153 -64
- package/dist/commands/compute/app/profile/set.js.map +1 -1
- package/dist/commands/compute/app/start.js +132 -43
- package/dist/commands/compute/app/start.js.map +1 -1
- package/dist/commands/compute/app/stop.js +132 -43
- package/dist/commands/compute/app/stop.js.map +1 -1
- package/dist/commands/compute/app/terminate.js +131 -44
- package/dist/commands/compute/app/terminate.js.map +1 -1
- package/dist/commands/compute/app/upgrade.js +210 -109
- package/dist/commands/compute/app/upgrade.js.map +1 -1
- package/dist/commands/compute/environment/list.js +104 -12
- package/dist/commands/compute/environment/list.js.map +1 -1
- package/dist/commands/compute/environment/set.js +103 -18
- package/dist/commands/compute/environment/set.js.map +1 -1
- package/dist/commands/compute/environment/show.js +122 -30
- package/dist/commands/compute/environment/show.js.map +1 -1
- package/dist/commands/compute/undelegate.js +113 -13
- package/dist/commands/compute/undelegate.js.map +1 -1
- package/dist/commands/telemetry.js +213 -0
- package/dist/commands/telemetry.js.map +1 -0
- package/dist/commands/upgrade.js +159 -19
- package/dist/commands/upgrade.js.map +1 -1
- package/dist/commands/version.js +163 -23
- package/dist/commands/version.js.map +1 -1
- package/package.json +2 -2
|
@@ -10,6 +10,7 @@ import * as path from "path";
|
|
|
10
10
|
import * as os from "os";
|
|
11
11
|
import { load as loadYaml, dump as dumpYaml } from "js-yaml";
|
|
12
12
|
import { getBuildType } from "@layr-labs/ecloud-sdk";
|
|
13
|
+
import * as crypto from "crypto";
|
|
13
14
|
var GLOBAL_CONFIG_FILE = "config.yaml";
|
|
14
15
|
var PROFILE_CACHE_TTL_MS = 24 * 60 * 60 * 1e3;
|
|
15
16
|
function getGlobalConfigDir() {
|
|
@@ -45,13 +46,102 @@ function loadGlobalConfig() {
|
|
|
45
46
|
};
|
|
46
47
|
}
|
|
47
48
|
}
|
|
49
|
+
function saveGlobalConfig(config) {
|
|
50
|
+
const configPath = getGlobalConfigPath();
|
|
51
|
+
const configDir = path.dirname(configPath);
|
|
52
|
+
fs.mkdirSync(configDir, { recursive: true, mode: 493 });
|
|
53
|
+
const content = dumpYaml(config, { lineWidth: -1 });
|
|
54
|
+
fs.writeFileSync(configPath, content, { mode: 420 });
|
|
55
|
+
}
|
|
48
56
|
function getDefaultEnvironment() {
|
|
49
57
|
const config = loadGlobalConfig();
|
|
50
58
|
return config.default_environment;
|
|
51
59
|
}
|
|
60
|
+
function getGlobalTelemetryPreference() {
|
|
61
|
+
const config = loadGlobalConfig();
|
|
62
|
+
return config.telemetry_enabled;
|
|
63
|
+
}
|
|
64
|
+
function getOrCreateUserUUID() {
|
|
65
|
+
const config = loadGlobalConfig();
|
|
66
|
+
if (config.user_uuid) {
|
|
67
|
+
return config.user_uuid;
|
|
68
|
+
}
|
|
69
|
+
const uuid = generateUUID();
|
|
70
|
+
config.user_uuid = uuid;
|
|
71
|
+
config.first_run = false;
|
|
72
|
+
saveGlobalConfig(config);
|
|
73
|
+
return uuid;
|
|
74
|
+
}
|
|
75
|
+
function generateUUID() {
|
|
76
|
+
const bytes = crypto.randomBytes(16);
|
|
77
|
+
bytes[6] = bytes[6] & 15 | 64;
|
|
78
|
+
bytes[8] = bytes[8] & 63 | 128;
|
|
79
|
+
const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, "0"));
|
|
80
|
+
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("");
|
|
81
|
+
}
|
|
52
82
|
|
|
53
83
|
// src/commands/compute/environment/list.ts
|
|
54
84
|
import chalk from "chalk";
|
|
85
|
+
|
|
86
|
+
// src/telemetry.ts
|
|
87
|
+
import {
|
|
88
|
+
createTelemetryClient,
|
|
89
|
+
createAppEnvironment,
|
|
90
|
+
createMetricsContext,
|
|
91
|
+
addMetric,
|
|
92
|
+
addMetricWithDimensions,
|
|
93
|
+
emitMetrics,
|
|
94
|
+
getBuildType as getBuildType2
|
|
95
|
+
} from "@layr-labs/ecloud-sdk";
|
|
96
|
+
function createCLITelemetryClient() {
|
|
97
|
+
const userUUID = getOrCreateUserUUID();
|
|
98
|
+
const environment = createAppEnvironment(userUUID);
|
|
99
|
+
const telemetryEnabled = getGlobalTelemetryPreference();
|
|
100
|
+
return createTelemetryClient(environment, "ecloud-cli", {
|
|
101
|
+
telemetryEnabled: telemetryEnabled === true
|
|
102
|
+
// Only enabled if explicitly set to true
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
async function withTelemetry(command, action) {
|
|
106
|
+
const client = createCLITelemetryClient();
|
|
107
|
+
const metrics = createMetricsContext();
|
|
108
|
+
metrics.properties["source"] = "ecloud-cli";
|
|
109
|
+
metrics.properties["command"] = command.id || command.constructor.name;
|
|
110
|
+
const environment = getDefaultEnvironment() || "sepolia";
|
|
111
|
+
metrics.properties["environment"] = environment;
|
|
112
|
+
const buildType = getBuildType2() || "prod";
|
|
113
|
+
metrics.properties["build_type"] = buildType;
|
|
114
|
+
const cliVersion = command.config.version;
|
|
115
|
+
if (cliVersion) {
|
|
116
|
+
metrics.properties["cli_version"] = cliVersion;
|
|
117
|
+
}
|
|
118
|
+
addMetric(metrics, "Count", 1);
|
|
119
|
+
let actionError;
|
|
120
|
+
let result;
|
|
121
|
+
try {
|
|
122
|
+
result = await action();
|
|
123
|
+
return result;
|
|
124
|
+
} catch (err) {
|
|
125
|
+
actionError = err instanceof Error ? err : new Error(String(err));
|
|
126
|
+
throw err;
|
|
127
|
+
} finally {
|
|
128
|
+
const resultValue = actionError ? "Failure" : "Success";
|
|
129
|
+
const dimensions = {};
|
|
130
|
+
if (actionError) {
|
|
131
|
+
dimensions["error"] = actionError.message;
|
|
132
|
+
}
|
|
133
|
+
addMetricWithDimensions(metrics, resultValue, 1, dimensions);
|
|
134
|
+
const duration = Date.now() - metrics.startTime.getTime();
|
|
135
|
+
addMetric(metrics, "DurationMilliseconds", duration);
|
|
136
|
+
try {
|
|
137
|
+
await emitMetrics(client, metrics);
|
|
138
|
+
await client.close();
|
|
139
|
+
} catch {
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// src/commands/compute/environment/list.ts
|
|
55
145
|
function getEnvironmentDescription(name) {
|
|
56
146
|
switch (name) {
|
|
57
147
|
case "sepolia":
|
|
@@ -68,19 +158,21 @@ var EnvironmentList = class extends Command {
|
|
|
68
158
|
static description = "List available deployment environments";
|
|
69
159
|
static aliases = ["compute:environment:list", "compute:env:list"];
|
|
70
160
|
async run() {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
161
|
+
return withTelemetry(this, async () => {
|
|
162
|
+
const availableEnvs = getAvailableEnvironments();
|
|
163
|
+
const currentEnv = getDefaultEnvironment();
|
|
164
|
+
console.log("Available deployment environments:");
|
|
165
|
+
for (const name of availableEnvs) {
|
|
166
|
+
try {
|
|
167
|
+
const config = getEnvironmentConfig(name);
|
|
168
|
+
const description = getEnvironmentDescription(name) || `- ${config.name}`;
|
|
169
|
+
const marker = currentEnv === name ? ` ${chalk.green("(active)")}` : "";
|
|
170
|
+
console.log(` \u2022 ${name} ${description}${marker}`);
|
|
171
|
+
} catch {
|
|
172
|
+
console.log(` \u2022 ${name} (unavailable)`);
|
|
173
|
+
}
|
|
82
174
|
}
|
|
83
|
-
}
|
|
175
|
+
});
|
|
84
176
|
}
|
|
85
177
|
};
|
|
86
178
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/commands/compute/environment/list.ts","../../../../src/utils/globalConfig.ts"],"sourcesContent":["import { Command } from \"@oclif/core\";\nimport { getAvailableEnvironments, getEnvironmentConfig } from \"@layr-labs/ecloud-sdk\";\nimport { getDefaultEnvironment } from \"../../../utils/globalConfig\";\nimport chalk from \"chalk\";\n\n/**\n * Get environment description\n */\nfunction getEnvironmentDescription(name: string): string {\n switch (name) {\n case \"sepolia\":\n return \"- Ethereum Sepolia testnet\";\n case \"sepolia-dev\":\n return \"- Ethereum Sepolia testnet (dev)\";\n case \"mainnet-alpha\":\n return \"- Ethereum mainnet (⚠️ uses real funds)\";\n default:\n return \"\";\n }\n}\n\nexport default class EnvironmentList extends Command {\n static description = \"List available deployment environments\";\n\n static aliases = [\"compute:environment:list\", \"compute:env:list\"];\n\n async run() {\n const availableEnvs = getAvailableEnvironments();\n const currentEnv = getDefaultEnvironment();\n\n console.log(\"Available deployment environments:\");\n\n for (const name of availableEnvs) {\n try {\n const config = getEnvironmentConfig(name);\n const description = getEnvironmentDescription(name) || `- ${config.name}`;\n const marker = currentEnv === name ? ` ${chalk.green(\"(active)\")}` : \"\";\n console.log(` • ${name} ${description}${marker}`);\n } catch {\n // Skip environments that can't be loaded\n console.log(` • ${name} (unavailable)`);\n }\n }\n }\n}\n","/**\n * Global configuration management\n *\n * Stores user-level configuration that persists across all CLI usage.\n * - $XDG_CONFIG_HOME/ecloud[BuildSuffix]/config.yaml (if XDG_CONFIG_HOME is set)\n * - Or ~/.config/ecloud[BuildSuffix]/config.yaml (fallback)\n *\n * Where BuildSuffix is:\n * - \"\" (empty) for production builds\n * - \"-dev\" for development builds\n */\n\nimport * as fs from \"fs\";\nimport * as path from \"path\";\nimport * as os from \"os\";\nimport { load as loadYaml, dump as dumpYaml } from \"js-yaml\";\nimport { getBuildType } from \"@layr-labs/ecloud-sdk\";\n\nconst GLOBAL_CONFIG_FILE = \"config.yaml\";\n\nexport interface ProfileCacheEntry {\n updated_at: number; // Unix timestamp in milliseconds\n profiles: { [appId: string]: string }; // appId -> profile name\n}\n\nexport interface GlobalConfig {\n first_run?: boolean;\n telemetry_enabled?: boolean;\n user_uuid?: string;\n default_environment?: string;\n last_version_check?: number;\n last_known_version?: string;\n profile_cache?: {\n [environment: string]: ProfileCacheEntry;\n };\n}\n\n// Profile cache TTL: 24 hours in milliseconds\nconst PROFILE_CACHE_TTL_MS = 24 * 60 * 60 * 1000;\n\n/**\n * Get the XDG-compliant directory where global ecloud config should be stored\n */\nfunction getGlobalConfigDir(): string {\n // First check XDG_CONFIG_HOME\n const configHome = process.env.XDG_CONFIG_HOME;\n\n let baseDir: string;\n if (configHome && path.isAbsolute(configHome)) {\n baseDir = configHome;\n } else {\n // Fall back to ~/.config\n baseDir = path.join(os.homedir(), \".config\");\n }\n\n // Use environment-specific config directory\n const buildType = getBuildType();\n const buildSuffix = buildType === \"dev\" ? \"-dev\" : \"\";\n const configDirName = `ecloud${buildSuffix}`;\n\n return path.join(baseDir, configDirName);\n}\n\n/**\n * Get the full path to the global config file\n */\nfunction getGlobalConfigPath(): string {\n return path.join(getGlobalConfigDir(), GLOBAL_CONFIG_FILE);\n}\n\n/**\n * Load global configuration, creating defaults if needed\n */\nexport function loadGlobalConfig(): GlobalConfig {\n const configPath = getGlobalConfigPath();\n\n // If file doesn't exist, return defaults for first run\n if (!fs.existsSync(configPath)) {\n return {\n first_run: true,\n };\n }\n\n try {\n const content = fs.readFileSync(configPath, \"utf-8\");\n const config = loadYaml(content) as GlobalConfig;\n return config || { first_run: true };\n } catch {\n // If parsing fails, return defaults\n return {\n first_run: true,\n };\n }\n}\n\n/**\n * Save global configuration to disk\n */\nexport function saveGlobalConfig(config: GlobalConfig): void {\n const configPath = getGlobalConfigPath();\n\n // Ensure directory exists\n const configDir = path.dirname(configPath);\n fs.mkdirSync(configDir, { recursive: true, mode: 0o755 });\n\n // Write config file\n const content = dumpYaml(config, { lineWidth: -1 });\n fs.writeFileSync(configPath, content, { mode: 0o644 });\n}\n\n/**\n * Get the user's preferred deployment environment\n */\nexport function getDefaultEnvironment(): string | undefined {\n const config = loadGlobalConfig();\n return config.default_environment;\n}\n\n/**\n * Set the user's preferred deployment environment\n */\nexport function setDefaultEnvironment(environment: string): void {\n const config = loadGlobalConfig();\n config.default_environment = environment;\n config.first_run = false; // No longer first run after setting environment\n saveGlobalConfig(config);\n}\n\n/**\n * Check if this is the user's first time running the CLI\n */\nexport function isFirstRun(): boolean {\n const config = loadGlobalConfig();\n return config.first_run === true;\n}\n\n/**\n * Mark that the first run has been completed\n */\nexport function markFirstRunComplete(): void {\n const config = loadGlobalConfig();\n config.first_run = false;\n saveGlobalConfig(config);\n}\n\n/**\n * Get the global telemetry preference\n */\nexport function getGlobalTelemetryPreference(): boolean | undefined {\n const config = loadGlobalConfig();\n return config.telemetry_enabled;\n}\n\n/**\n * Set the global telemetry preference\n */\nexport function setGlobalTelemetryPreference(enabled: boolean): void {\n const config = loadGlobalConfig();\n config.telemetry_enabled = enabled;\n config.first_run = false; // No longer first run after setting preference\n saveGlobalConfig(config);\n}\n\n// ==================== Profile Cache Functions ====================\n\n/**\n * Get cached profile names for an environment\n * Returns null if cache is missing or expired (older than 24 hours)\n */\nexport function getProfileCache(environment: string): Record<string, string> | null {\n const config = loadGlobalConfig();\n const cacheEntry = config.profile_cache?.[environment];\n\n if (!cacheEntry) {\n return null;\n }\n\n // Check if cache is expired\n const now = Date.now();\n if (now - cacheEntry.updated_at > PROFILE_CACHE_TTL_MS) {\n return null;\n }\n\n return cacheEntry.profiles;\n}\n\n/**\n * Set cached profile names for an environment\n */\nexport function setProfileCache(environment: string, profiles: Record<string, string>): void {\n const config = loadGlobalConfig();\n\n if (!config.profile_cache) {\n config.profile_cache = {};\n }\n\n config.profile_cache[environment] = {\n updated_at: Date.now(),\n profiles,\n };\n\n saveGlobalConfig(config);\n}\n\n/**\n * Invalidate profile cache for a specific environment or all environments\n */\nexport function invalidateProfileCache(environment?: string): void {\n const config = loadGlobalConfig();\n\n if (!config.profile_cache) {\n return;\n }\n\n if (environment) {\n // Invalidate specific environment\n delete config.profile_cache[environment];\n } else {\n // Invalidate all environments\n config.profile_cache = {};\n }\n\n saveGlobalConfig(config);\n}\n\n/**\n * Update a single profile name in the cache\n * This is useful after deploy or profile set to update just one entry\n */\nexport function updateProfileCacheEntry(\n environment: string,\n appId: string,\n profileName: string,\n): void {\n const config = loadGlobalConfig();\n\n if (!config.profile_cache) {\n config.profile_cache = {};\n }\n\n if (!config.profile_cache[environment]) {\n config.profile_cache[environment] = {\n updated_at: Date.now(),\n profiles: {},\n };\n }\n\n // Normalize appId to lowercase for consistent lookups\n const normalizedAppId = appId.toLowerCase();\n config.profile_cache[environment].profiles[normalizedAppId] = profileName;\n config.profile_cache[environment].updated_at = Date.now();\n\n saveGlobalConfig(config);\n}\n"],"mappings":";;;AAAA,SAAS,eAAe;AACxB,SAAS,0BAA0B,4BAA4B;;;ACW/D,YAA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AU,CAAC,4BAA4B,kBAAkB;AAAA,EAEhE,MAAM,MAAM;AACV,UAAM,gBAAgB,yBAAyB;AAC/C,UAAM,aAAa,sBAAsB;AAEzC,YAAQ,IAAI,oCAAoC;AAEhD,eAAW,QAAQ,eAAe;AAChC,UAAI;AACF,cAAM,SAAS,qBAAqB,IAAI;AACxC,cAAM,cAAc,0BAA0B,IAAI,KAAK,KAAK,OAAO,IAAI;AACvE,cAAM,SAAS,eAAe,OAAO,IAAI,MAAM,MAAM,UAAU,CAAC,KAAK;AACrE,gBAAQ,IAAI,YAAO,IAAI,IAAI,WAAW,GAAG,MAAM,EAAE;AAAA,MACnD,QAAQ;AAEN,gBAAQ,IAAI,YAAO,IAAI,gBAAgB;AAAA,MACzC;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../../src/commands/compute/environment/list.ts","../../../../src/utils/globalConfig.ts","../../../../src/telemetry.ts"],"sourcesContent":["import { Command } from \"@oclif/core\";\nimport { getAvailableEnvironments, getEnvironmentConfig } from \"@layr-labs/ecloud-sdk\";\nimport { getDefaultEnvironment } from \"../../../utils/globalConfig\";\nimport chalk from \"chalk\";\nimport { withTelemetry } from \"../../../telemetry\";\n\n/**\n * Get environment description\n */\nfunction getEnvironmentDescription(name: string): string {\n switch (name) {\n case \"sepolia\":\n return \"- Ethereum Sepolia testnet\";\n case \"sepolia-dev\":\n return \"- Ethereum Sepolia testnet (dev)\";\n case \"mainnet-alpha\":\n return \"- Ethereum mainnet (⚠️ uses real funds)\";\n default:\n return \"\";\n }\n}\n\nexport default class EnvironmentList extends Command {\n static description = \"List available deployment environments\";\n\n static aliases = [\"compute:environment:list\", \"compute:env:list\"];\n\n async run() {\n return withTelemetry(this, async () => {\n const availableEnvs = getAvailableEnvironments();\n const currentEnv = getDefaultEnvironment();\n\n console.log(\"Available deployment environments:\");\n\n for (const name of availableEnvs) {\n try {\n const config = getEnvironmentConfig(name);\n const description = getEnvironmentDescription(name) || `- ${config.name}`;\n const marker = currentEnv === name ? ` ${chalk.green(\"(active)\")}` : \"\";\n console.log(` • ${name} ${description}${marker}`);\n } catch {\n // Skip environments that can't be loaded\n console.log(` • ${name} (unavailable)`);\n }\n }\n });\n }\n}\n","/**\n * Global configuration management\n *\n * Stores user-level configuration that persists across all CLI usage.\n * - $XDG_CONFIG_HOME/ecloud[BuildSuffix]/config.yaml (if XDG_CONFIG_HOME is set)\n * - Or ~/.config/ecloud[BuildSuffix]/config.yaml (fallback)\n *\n * Where BuildSuffix is:\n * - \"\" (empty) for production builds\n * - \"-dev\" for development builds\n */\n\nimport * as fs from \"fs\";\nimport * as path from \"path\";\nimport * as os from \"os\";\nimport { load as loadYaml, dump as dumpYaml } from \"js-yaml\";\nimport { getBuildType } from \"@layr-labs/ecloud-sdk\";\nimport * as crypto from \"crypto\";\nconst GLOBAL_CONFIG_FILE = \"config.yaml\";\n\nexport interface ProfileCacheEntry {\n updated_at: number; // Unix timestamp in milliseconds\n profiles: { [appId: string]: string }; // appId -> profile name\n}\n\nexport interface GlobalConfig {\n first_run?: boolean;\n telemetry_enabled?: boolean;\n user_uuid?: string;\n default_environment?: string;\n last_version_check?: number;\n last_known_version?: string;\n profile_cache?: {\n [environment: string]: ProfileCacheEntry;\n };\n}\n\n// Profile cache TTL: 24 hours in milliseconds\nconst PROFILE_CACHE_TTL_MS = 24 * 60 * 60 * 1000;\n\n/**\n * Get the XDG-compliant directory where global ecloud config should be stored\n */\nfunction getGlobalConfigDir(): string {\n // First check XDG_CONFIG_HOME\n const configHome = process.env.XDG_CONFIG_HOME;\n\n let baseDir: string;\n if (configHome && path.isAbsolute(configHome)) {\n baseDir = configHome;\n } else {\n // Fall back to ~/.config\n baseDir = path.join(os.homedir(), \".config\");\n }\n\n // Use environment-specific config directory\n const buildType = getBuildType();\n const buildSuffix = buildType === \"dev\" ? \"-dev\" : \"\";\n const configDirName = `ecloud${buildSuffix}`;\n\n return path.join(baseDir, configDirName);\n}\n\n/**\n * Get the full path to the global config file\n */\nfunction getGlobalConfigPath(): string {\n return path.join(getGlobalConfigDir(), GLOBAL_CONFIG_FILE);\n}\n\n/**\n * Load global configuration, creating defaults if needed\n */\nexport function loadGlobalConfig(): GlobalConfig {\n const configPath = getGlobalConfigPath();\n\n // If file doesn't exist, return defaults for first run\n if (!fs.existsSync(configPath)) {\n return {\n first_run: true,\n };\n }\n\n try {\n const content = fs.readFileSync(configPath, \"utf-8\");\n const config = loadYaml(content) as GlobalConfig;\n return config || { first_run: true };\n } catch {\n // If parsing fails, return defaults\n return {\n first_run: true,\n };\n }\n}\n\n/**\n * Save global configuration to disk\n */\nexport function saveGlobalConfig(config: GlobalConfig): void {\n const configPath = getGlobalConfigPath();\n\n // Ensure directory exists\n const configDir = path.dirname(configPath);\n fs.mkdirSync(configDir, { recursive: true, mode: 0o755 });\n\n // Write config file\n const content = dumpYaml(config, { lineWidth: -1 });\n fs.writeFileSync(configPath, content, { mode: 0o644 });\n}\n\n/**\n * Get the user's preferred deployment environment\n */\nexport function getDefaultEnvironment(): string | undefined {\n const config = loadGlobalConfig();\n return config.default_environment;\n}\n\n/**\n * Set the user's preferred deployment environment\n */\nexport function setDefaultEnvironment(environment: string): void {\n const config = loadGlobalConfig();\n config.default_environment = environment;\n config.first_run = false; // No longer first run after setting environment\n saveGlobalConfig(config);\n}\n\n/**\n * Check if this is the user's first time running the CLI\n */\nexport function isFirstRun(): boolean {\n const config = loadGlobalConfig();\n return config.first_run === true;\n}\n\n/**\n * Mark that the first run has been completed\n */\nexport function markFirstRunComplete(): void {\n const config = loadGlobalConfig();\n config.first_run = false;\n saveGlobalConfig(config);\n}\n\n/**\n * Get the global telemetry preference\n */\nexport function getGlobalTelemetryPreference(): boolean | undefined {\n const config = loadGlobalConfig();\n return config.telemetry_enabled;\n}\n\n/**\n * Set the global telemetry preference\n */\nexport function setGlobalTelemetryPreference(enabled: boolean): void {\n const config = loadGlobalConfig();\n config.telemetry_enabled = enabled;\n config.first_run = false; // No longer first run after setting preference\n saveGlobalConfig(config);\n}\n\n// ==================== Profile Cache Functions ====================\n\n/**\n * Get cached profile names for an environment\n * Returns null if cache is missing or expired (older than 24 hours)\n */\nexport function getProfileCache(environment: string): Record<string, string> | null {\n const config = loadGlobalConfig();\n const cacheEntry = config.profile_cache?.[environment];\n\n if (!cacheEntry) {\n return null;\n }\n\n // Check if cache is expired\n const now = Date.now();\n if (now - cacheEntry.updated_at > PROFILE_CACHE_TTL_MS) {\n return null;\n }\n\n return cacheEntry.profiles;\n}\n\n/**\n * Set cached profile names for an environment\n */\nexport function setProfileCache(environment: string, profiles: Record<string, string>): void {\n const config = loadGlobalConfig();\n\n if (!config.profile_cache) {\n config.profile_cache = {};\n }\n\n config.profile_cache[environment] = {\n updated_at: Date.now(),\n profiles,\n };\n\n saveGlobalConfig(config);\n}\n\n/**\n * Invalidate profile cache for a specific environment or all environments\n */\nexport function invalidateProfileCache(environment?: string): void {\n const config = loadGlobalConfig();\n\n if (!config.profile_cache) {\n return;\n }\n\n if (environment) {\n // Invalidate specific environment\n delete config.profile_cache[environment];\n } else {\n // Invalidate all environments\n config.profile_cache = {};\n }\n\n saveGlobalConfig(config);\n}\n\n/**\n * Update a single profile name in the cache\n * This is useful after deploy or profile set to update just one entry\n */\nexport function updateProfileCacheEntry(\n environment: string,\n appId: string,\n profileName: string,\n): void {\n const config = loadGlobalConfig();\n\n if (!config.profile_cache) {\n config.profile_cache = {};\n }\n\n if (!config.profile_cache[environment]) {\n config.profile_cache[environment] = {\n updated_at: Date.now(),\n profiles: {},\n };\n }\n\n // Normalize appId to lowercase for consistent lookups\n const normalizedAppId = appId.toLowerCase();\n config.profile_cache[environment].profiles[normalizedAppId] = profileName;\n config.profile_cache[environment].updated_at = Date.now();\n\n saveGlobalConfig(config);\n}\n\n/**\n * Get the user UUID from global config, or generate a new one if it doesn't exist\n */\nexport function getOrCreateUserUUID(): string {\n const config = loadGlobalConfig();\n if (config.user_uuid) {\n return config.user_uuid;\n }\n\n // Generate a new UUID (v4)\n const uuid = generateUUID();\n\n // Save it to config\n config.user_uuid = uuid;\n config.first_run = false;\n saveGlobalConfig(config);\n\n return uuid;\n}\n\n/**\n * Generate a UUID v4\n */\nfunction generateUUID(): string {\n // UUID v4 format: xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx\n // Use cryptographically secure random values.\n const bytes = crypto.randomBytes(16);\n // Per RFC 4122 section 4.4, set bits for version and `clock_seq_hi_and_reserved`\n bytes[6] = (bytes[6] & 0x0f) | 0x40; // Version 4\n bytes[8] = (bytes[8] & 0x3f) | 0x80; // Variant 10\n const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, \"0\"));\n return (\n hex.slice(0, 4).join(\"\") +\n hex.slice(4, 6).join(\"\") +\n \"-\" +\n hex.slice(6, 8).join(\"\") +\n \"-\" +\n hex.slice(8, 10).join(\"\") +\n \"-\" +\n hex.slice(10, 12).join(\"\") +\n \"-\" +\n hex.slice(12, 16).join(\"\")\n );\n}\n\n/**\n * Save user UUID to global config (preserves existing UUID if present)\n */\nexport function saveUserUUID(userUUID: string): void {\n const config = loadGlobalConfig();\n // Only update if not already set\n if (!config.user_uuid) {\n config.user_uuid = userUUID;\n saveGlobalConfig(config);\n }\n}\n","/**\n * Telemetry utilities for CLI commands\n *\n * Provides helpers to wrap command execution with telemetry tracking\n */\n\nimport {\n createTelemetryClient,\n createAppEnvironment,\n createMetricsContext,\n addMetric,\n addMetricWithDimensions,\n emitMetrics,\n type TelemetryClient,\n getBuildType,\n} from \"@layr-labs/ecloud-sdk\";\nimport { Command } from \"@oclif/core\";\nimport {\n getDefaultEnvironment,\n getOrCreateUserUUID,\n getGlobalTelemetryPreference,\n} from \"./utils/globalConfig\";\n\n/**\n * Create a telemetry client for CLI usage\n */\nexport function createCLITelemetryClient(): TelemetryClient {\n // Get user UUID from CLI's globalConfig (handles I/O)\n const userUUID = getOrCreateUserUUID();\n const environment = createAppEnvironment(userUUID);\n\n // Get telemetry preference from CLI's globalConfig\n const telemetryEnabled = getGlobalTelemetryPreference();\n\n return createTelemetryClient(environment, \"ecloud-cli\", {\n telemetryEnabled: telemetryEnabled === true, // Only enabled if explicitly set to true\n });\n}\n\n/**\n * Wrap a command execution with telemetry\n *\n * @param command - The CLI command instance\n * @param action - The command action to execute\n * @returns The result of the action\n */\nexport async function withTelemetry<T>(command: Command, action: () => Promise<T>): Promise<T> {\n const client = createCLITelemetryClient();\n const metrics = createMetricsContext();\n\n // Set source to identify CLI usage\n metrics.properties[\"source\"] = \"ecloud-cli\";\n\n // Set command name in properties\n metrics.properties[\"command\"] = command.id || command.constructor.name;\n\n // Set environment in properties\n const environment = getDefaultEnvironment() || \"sepolia\";\n metrics.properties[\"environment\"] = environment;\n\n // Set buildType in properties\n const buildType = getBuildType() || \"prod\";\n metrics.properties[\"build_type\"] = buildType;\n\n // Set CLI version if available\n const cliVersion = command.config.version;\n if (cliVersion) {\n metrics.properties[\"cli_version\"] = cliVersion;\n }\n\n // Add initial count metric\n addMetric(metrics, \"Count\", 1);\n\n let actionError: Error | undefined;\n let result: T;\n\n try {\n result = await action();\n return result;\n } catch (err) {\n actionError = err instanceof Error ? err : new Error(String(err));\n throw err;\n } finally {\n // Add result metric\n const resultValue = actionError ? \"Failure\" : \"Success\";\n const dimensions: Record<string, string> = {};\n if (actionError) {\n dimensions[\"error\"] = actionError.message;\n }\n addMetricWithDimensions(metrics, resultValue, 1, dimensions);\n\n // Add duration metric\n const duration = Date.now() - metrics.startTime.getTime();\n addMetric(metrics, \"DurationMilliseconds\", duration);\n\n // Emit all metrics\n try {\n await emitMetrics(client, metrics);\n await client.close();\n } catch {\n // Silently ignore telemetry errors\n }\n }\n}\n"],"mappings":";;;AAAA,SAAS,eAAe;AACxB,SAAS,0BAA0B,4BAA4B;;;ACW/D,YAAY,QAAQ;AACpB,YAAY,UAAU;AACtB,YAAY,QAAQ;AACpB,SAAS,QAAQ,UAAU,QAAQ,gBAAgB;AACnD,SAAS,oBAAoB;AAC7B,YAAY,YAAY;AACxB,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AAW,QAAQ,eAAe;AAChC,YAAI;AACF,gBAAM,SAAS,qBAAqB,IAAI;AACxC,gBAAM,cAAc,0BAA0B,IAAI,KAAK,KAAK,OAAO,IAAI;AACvE,gBAAM,SAAS,eAAe,OAAO,IAAI,MAAM,MAAM,UAAU,CAAC,KAAK;AACrE,kBAAQ,IAAI,YAAO,IAAI,IAAI,WAAW,GAAG,MAAM,EAAE;AAAA,QACnD,QAAQ;AAEN,kBAAQ,IAAI,YAAO,IAAI,gBAAgB;AAAA,QACzC;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH;AACF;","names":["getBuildType","getBuildType"]}
|
|
@@ -14,6 +14,7 @@ import * as path from "path";
|
|
|
14
14
|
import * as os from "os";
|
|
15
15
|
import { load as loadYaml, dump as dumpYaml } from "js-yaml";
|
|
16
16
|
import { getBuildType } from "@layr-labs/ecloud-sdk";
|
|
17
|
+
import * as crypto from "crypto";
|
|
17
18
|
var GLOBAL_CONFIG_FILE = "config.yaml";
|
|
18
19
|
var PROFILE_CACHE_TTL_MS = 24 * 60 * 60 * 1e3;
|
|
19
20
|
function getGlobalConfigDir() {
|
|
@@ -66,6 +67,28 @@ function setDefaultEnvironment(environment) {
|
|
|
66
67
|
config.first_run = false;
|
|
67
68
|
saveGlobalConfig(config);
|
|
68
69
|
}
|
|
70
|
+
function getGlobalTelemetryPreference() {
|
|
71
|
+
const config = loadGlobalConfig();
|
|
72
|
+
return config.telemetry_enabled;
|
|
73
|
+
}
|
|
74
|
+
function getOrCreateUserUUID() {
|
|
75
|
+
const config = loadGlobalConfig();
|
|
76
|
+
if (config.user_uuid) {
|
|
77
|
+
return config.user_uuid;
|
|
78
|
+
}
|
|
79
|
+
const uuid = generateUUID();
|
|
80
|
+
config.user_uuid = uuid;
|
|
81
|
+
config.first_run = false;
|
|
82
|
+
saveGlobalConfig(config);
|
|
83
|
+
return uuid;
|
|
84
|
+
}
|
|
85
|
+
function generateUUID() {
|
|
86
|
+
const bytes = crypto.randomBytes(16);
|
|
87
|
+
bytes[6] = bytes[6] & 15 | 64;
|
|
88
|
+
bytes[8] = bytes[8] & 63 | 128;
|
|
89
|
+
const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, "0"));
|
|
90
|
+
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("");
|
|
91
|
+
}
|
|
69
92
|
|
|
70
93
|
// src/utils/prompts.ts
|
|
71
94
|
import { input, select, password, confirm as inquirerConfirm } from "@inquirer/prompts";
|
|
@@ -155,6 +178,66 @@ var MAX_IMAGE_SIZE = 4 * 1024 * 1024;
|
|
|
155
178
|
|
|
156
179
|
// src/commands/compute/environment/set.ts
|
|
157
180
|
import { confirm } from "@inquirer/prompts";
|
|
181
|
+
|
|
182
|
+
// src/telemetry.ts
|
|
183
|
+
import {
|
|
184
|
+
createTelemetryClient,
|
|
185
|
+
createAppEnvironment,
|
|
186
|
+
createMetricsContext,
|
|
187
|
+
addMetric,
|
|
188
|
+
addMetricWithDimensions,
|
|
189
|
+
emitMetrics,
|
|
190
|
+
getBuildType as getBuildType2
|
|
191
|
+
} from "@layr-labs/ecloud-sdk";
|
|
192
|
+
function createCLITelemetryClient() {
|
|
193
|
+
const userUUID = getOrCreateUserUUID();
|
|
194
|
+
const environment = createAppEnvironment(userUUID);
|
|
195
|
+
const telemetryEnabled = getGlobalTelemetryPreference();
|
|
196
|
+
return createTelemetryClient(environment, "ecloud-cli", {
|
|
197
|
+
telemetryEnabled: telemetryEnabled === true
|
|
198
|
+
// Only enabled if explicitly set to true
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
async function withTelemetry(command, action) {
|
|
202
|
+
const client = createCLITelemetryClient();
|
|
203
|
+
const metrics = createMetricsContext();
|
|
204
|
+
metrics.properties["source"] = "ecloud-cli";
|
|
205
|
+
metrics.properties["command"] = command.id || command.constructor.name;
|
|
206
|
+
const environment = getDefaultEnvironment() || "sepolia";
|
|
207
|
+
metrics.properties["environment"] = environment;
|
|
208
|
+
const buildType = getBuildType2() || "prod";
|
|
209
|
+
metrics.properties["build_type"] = buildType;
|
|
210
|
+
const cliVersion = command.config.version;
|
|
211
|
+
if (cliVersion) {
|
|
212
|
+
metrics.properties["cli_version"] = cliVersion;
|
|
213
|
+
}
|
|
214
|
+
addMetric(metrics, "Count", 1);
|
|
215
|
+
let actionError;
|
|
216
|
+
let result;
|
|
217
|
+
try {
|
|
218
|
+
result = await action();
|
|
219
|
+
return result;
|
|
220
|
+
} catch (err) {
|
|
221
|
+
actionError = err instanceof Error ? err : new Error(String(err));
|
|
222
|
+
throw err;
|
|
223
|
+
} finally {
|
|
224
|
+
const resultValue = actionError ? "Failure" : "Success";
|
|
225
|
+
const dimensions = {};
|
|
226
|
+
if (actionError) {
|
|
227
|
+
dimensions["error"] = actionError.message;
|
|
228
|
+
}
|
|
229
|
+
addMetricWithDimensions(metrics, resultValue, 1, dimensions);
|
|
230
|
+
const duration = Date.now() - metrics.startTime.getTime();
|
|
231
|
+
addMetric(metrics, "DurationMilliseconds", duration);
|
|
232
|
+
try {
|
|
233
|
+
await emitMetrics(client, metrics);
|
|
234
|
+
await client.close();
|
|
235
|
+
} catch {
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// src/commands/compute/environment/set.ts
|
|
158
241
|
function isMainnetEnvironment(env) {
|
|
159
242
|
return env.includes("mainnet");
|
|
160
243
|
}
|
|
@@ -187,26 +270,28 @@ var EnvironmentSet = class _EnvironmentSet extends Command {
|
|
|
187
270
|
})
|
|
188
271
|
};
|
|
189
272
|
async run() {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
273
|
+
return withTelemetry(this, async () => {
|
|
274
|
+
const { args, flags } = await this.parse(_EnvironmentSet);
|
|
275
|
+
const newEnv = args.environment || await getEnvironmentInteractive();
|
|
276
|
+
if (!isEnvironmentAvailable2(newEnv)) {
|
|
277
|
+
const available = getAvailableEnvironments2().join(", ");
|
|
278
|
+
throw new Error(
|
|
279
|
+
`Unknown environment: ${newEnv}
|
|
196
280
|
Run 'ecloud environment list' to see available environments (${available})`
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
281
|
+
);
|
|
282
|
+
}
|
|
283
|
+
try {
|
|
284
|
+
getEnvironmentConfig2(newEnv);
|
|
285
|
+
} catch (err) {
|
|
286
|
+
throw new Error(`Invalid environment: ${newEnv} - ${err.message}`);
|
|
287
|
+
}
|
|
288
|
+
if (isMainnetEnvironment(newEnv) && !flags.yes) {
|
|
289
|
+
await confirmMainnetEnvironment(newEnv);
|
|
290
|
+
}
|
|
291
|
+
setDefaultEnvironment(newEnv);
|
|
292
|
+
console.log(`
|
|
209
293
|
\u2705 Deployment environment set to ${newEnv}`);
|
|
294
|
+
});
|
|
210
295
|
}
|
|
211
296
|
};
|
|
212
297
|
export {
|