@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
package/README.md
CHANGED
|
@@ -314,7 +314,7 @@ const client = createECloudClient({
|
|
|
314
314
|
});
|
|
315
315
|
|
|
316
316
|
// Deploy an application
|
|
317
|
-
const result = await client.
|
|
317
|
+
const result = await client.app.deploy({
|
|
318
318
|
image: "myapp:latest",
|
|
319
319
|
});
|
|
320
320
|
|
|
@@ -322,13 +322,13 @@ console.log(`Deployed app ID: ${result.appId}`);
|
|
|
322
322
|
console.log(`Transaction hash: ${result.tx}`);
|
|
323
323
|
|
|
324
324
|
// Start an application
|
|
325
|
-
await client.
|
|
325
|
+
await client.app.start(result.appId);
|
|
326
326
|
|
|
327
327
|
// Stop an application
|
|
328
|
-
await client.
|
|
328
|
+
await client.app.stop(result.appId);
|
|
329
329
|
|
|
330
330
|
// Terminate an application
|
|
331
|
-
await client.
|
|
331
|
+
await client.app.terminate(result.appId);
|
|
332
332
|
```
|
|
333
333
|
|
|
334
334
|
## Environments
|
package/VERSION
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
version=0.1.0-
|
|
2
|
-
commit=
|
|
1
|
+
version=0.1.0-rc.2
|
|
2
|
+
commit=59c794bb1aebad8f343114aa1f279b7e2136b2e2
|
|
@@ -117,142 +117,6 @@ function displayWarning(lines) {
|
|
|
117
117
|
console.log("");
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
-
// src/telemetry.ts
|
|
121
|
-
import {
|
|
122
|
-
createTelemetryClient,
|
|
123
|
-
createAppEnvironment,
|
|
124
|
-
createMetricsContext,
|
|
125
|
-
addMetric,
|
|
126
|
-
addMetricWithDimensions,
|
|
127
|
-
emitMetrics,
|
|
128
|
-
getBuildType as getBuildType2
|
|
129
|
-
} from "@layr-labs/ecloud-sdk";
|
|
130
|
-
|
|
131
|
-
// src/utils/globalConfig.ts
|
|
132
|
-
import * as fs from "fs";
|
|
133
|
-
import * as path from "path";
|
|
134
|
-
import * as os from "os";
|
|
135
|
-
import { load as loadYaml, dump as dumpYaml } from "js-yaml";
|
|
136
|
-
import { getBuildType } from "@layr-labs/ecloud-sdk";
|
|
137
|
-
import * as crypto from "crypto";
|
|
138
|
-
var GLOBAL_CONFIG_FILE = "config.yaml";
|
|
139
|
-
var PROFILE_CACHE_TTL_MS = 24 * 60 * 60 * 1e3;
|
|
140
|
-
function getGlobalConfigDir() {
|
|
141
|
-
const configHome = process.env.XDG_CONFIG_HOME;
|
|
142
|
-
let baseDir;
|
|
143
|
-
if (configHome && path.isAbsolute(configHome)) {
|
|
144
|
-
baseDir = configHome;
|
|
145
|
-
} else {
|
|
146
|
-
baseDir = path.join(os.homedir(), ".config");
|
|
147
|
-
}
|
|
148
|
-
const buildType = getBuildType();
|
|
149
|
-
const buildSuffix = buildType === "dev" ? "-dev" : "";
|
|
150
|
-
const configDirName = `ecloud${buildSuffix}`;
|
|
151
|
-
return path.join(baseDir, configDirName);
|
|
152
|
-
}
|
|
153
|
-
function getGlobalConfigPath() {
|
|
154
|
-
return path.join(getGlobalConfigDir(), GLOBAL_CONFIG_FILE);
|
|
155
|
-
}
|
|
156
|
-
function loadGlobalConfig() {
|
|
157
|
-
const configPath = getGlobalConfigPath();
|
|
158
|
-
if (!fs.existsSync(configPath)) {
|
|
159
|
-
return {
|
|
160
|
-
first_run: true
|
|
161
|
-
};
|
|
162
|
-
}
|
|
163
|
-
try {
|
|
164
|
-
const content = fs.readFileSync(configPath, "utf-8");
|
|
165
|
-
const config = loadYaml(content);
|
|
166
|
-
return config || { first_run: true };
|
|
167
|
-
} catch {
|
|
168
|
-
return {
|
|
169
|
-
first_run: true
|
|
170
|
-
};
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
function saveGlobalConfig(config) {
|
|
174
|
-
const configPath = getGlobalConfigPath();
|
|
175
|
-
const configDir = path.dirname(configPath);
|
|
176
|
-
fs.mkdirSync(configDir, { recursive: true, mode: 493 });
|
|
177
|
-
const content = dumpYaml(config, { lineWidth: -1 });
|
|
178
|
-
fs.writeFileSync(configPath, content, { mode: 420 });
|
|
179
|
-
}
|
|
180
|
-
function getDefaultEnvironment() {
|
|
181
|
-
const config = loadGlobalConfig();
|
|
182
|
-
return config.default_environment;
|
|
183
|
-
}
|
|
184
|
-
function getGlobalTelemetryPreference() {
|
|
185
|
-
const config = loadGlobalConfig();
|
|
186
|
-
return config.telemetry_enabled;
|
|
187
|
-
}
|
|
188
|
-
function getOrCreateUserUUID() {
|
|
189
|
-
const config = loadGlobalConfig();
|
|
190
|
-
if (config.user_uuid) {
|
|
191
|
-
return config.user_uuid;
|
|
192
|
-
}
|
|
193
|
-
const uuid = generateUUID();
|
|
194
|
-
config.user_uuid = uuid;
|
|
195
|
-
config.first_run = false;
|
|
196
|
-
saveGlobalConfig(config);
|
|
197
|
-
return uuid;
|
|
198
|
-
}
|
|
199
|
-
function generateUUID() {
|
|
200
|
-
const bytes = crypto.randomBytes(16);
|
|
201
|
-
bytes[6] = bytes[6] & 15 | 64;
|
|
202
|
-
bytes[8] = bytes[8] & 63 | 128;
|
|
203
|
-
const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, "0"));
|
|
204
|
-
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("");
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
// src/telemetry.ts
|
|
208
|
-
function createCLITelemetryClient() {
|
|
209
|
-
const userUUID = getOrCreateUserUUID();
|
|
210
|
-
const environment = createAppEnvironment(userUUID);
|
|
211
|
-
const telemetryEnabled = getGlobalTelemetryPreference();
|
|
212
|
-
return createTelemetryClient(environment, "ecloud-cli", {
|
|
213
|
-
telemetryEnabled: telemetryEnabled === true
|
|
214
|
-
// Only enabled if explicitly set to true
|
|
215
|
-
});
|
|
216
|
-
}
|
|
217
|
-
async function withTelemetry(command, action) {
|
|
218
|
-
const client = createCLITelemetryClient();
|
|
219
|
-
const metrics = createMetricsContext();
|
|
220
|
-
metrics.properties["source"] = "ecloud-cli";
|
|
221
|
-
metrics.properties["command"] = command.id || command.constructor.name;
|
|
222
|
-
const environment = getDefaultEnvironment() || "sepolia";
|
|
223
|
-
metrics.properties["environment"] = environment;
|
|
224
|
-
const buildType = getBuildType2() || "prod";
|
|
225
|
-
metrics.properties["build_type"] = buildType;
|
|
226
|
-
const cliVersion = command.config.version;
|
|
227
|
-
if (cliVersion) {
|
|
228
|
-
metrics.properties["cli_version"] = cliVersion;
|
|
229
|
-
}
|
|
230
|
-
addMetric(metrics, "Count", 1);
|
|
231
|
-
let actionError;
|
|
232
|
-
let result;
|
|
233
|
-
try {
|
|
234
|
-
result = await action();
|
|
235
|
-
return result;
|
|
236
|
-
} catch (err) {
|
|
237
|
-
actionError = err instanceof Error ? err : new Error(String(err));
|
|
238
|
-
throw err;
|
|
239
|
-
} finally {
|
|
240
|
-
const resultValue = actionError ? "Failure" : "Success";
|
|
241
|
-
const dimensions = {};
|
|
242
|
-
if (actionError) {
|
|
243
|
-
dimensions["error"] = actionError.message;
|
|
244
|
-
}
|
|
245
|
-
addMetricWithDimensions(metrics, resultValue, 1, dimensions);
|
|
246
|
-
const duration = Date.now() - metrics.startTime.getTime();
|
|
247
|
-
addMetric(metrics, "DurationMilliseconds", duration);
|
|
248
|
-
try {
|
|
249
|
-
await emitMetrics(client, metrics);
|
|
250
|
-
await client.close();
|
|
251
|
-
} catch {
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
|
|
256
120
|
// src/commands/auth/generate.ts
|
|
257
121
|
var AuthGenerate = class _AuthGenerate extends Command {
|
|
258
122
|
static description = "Generate a new private key";
|
|
@@ -268,11 +132,10 @@ var AuthGenerate = class _AuthGenerate extends Command {
|
|
|
268
132
|
})
|
|
269
133
|
};
|
|
270
134
|
async run() {
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
const content = `
|
|
135
|
+
const { flags } = await this.parse(_AuthGenerate);
|
|
136
|
+
this.log("Generating new private key...\n");
|
|
137
|
+
const { privateKey, address } = generateNewPrivateKey();
|
|
138
|
+
const content = `
|
|
276
139
|
\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501
|
|
277
140
|
A new private key was generated for you.
|
|
278
141
|
|
|
@@ -290,53 +153,52 @@ Private key: ${privateKey}
|
|
|
290
153
|
|
|
291
154
|
Press 'q' to exit and continue...
|
|
292
155
|
`;
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
156
|
+
const displayed = await showPrivateKey(content);
|
|
157
|
+
if (!displayed) {
|
|
158
|
+
this.log("Key generation cancelled.");
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
let shouldStore = flags.store;
|
|
162
|
+
if (!shouldStore && displayed) {
|
|
163
|
+
shouldStore = await confirm({
|
|
164
|
+
message: "Store this key in your OS keyring?",
|
|
165
|
+
default: true
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
if (shouldStore) {
|
|
169
|
+
const exists = await keyExists();
|
|
170
|
+
if (exists) {
|
|
171
|
+
displayWarning([
|
|
172
|
+
`WARNING: A private key for ecloud already exists!`,
|
|
173
|
+
"If you continue, the existing key will be PERMANENTLY REPLACED.",
|
|
174
|
+
"This cannot be undone!",
|
|
175
|
+
"",
|
|
176
|
+
"The previous key will be lost forever if you haven't backed it up."
|
|
177
|
+
]);
|
|
178
|
+
const confirmReplace = await confirm({
|
|
179
|
+
message: `Replace existing key for ecloud?`,
|
|
180
|
+
default: false
|
|
303
181
|
});
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
`WARNING: A private key for ecloud already exists!`,
|
|
310
|
-
"If you continue, the existing key will be PERMANENTLY REPLACED.",
|
|
311
|
-
"This cannot be undone!",
|
|
312
|
-
"",
|
|
313
|
-
"The previous key will be lost forever if you haven't backed it up."
|
|
314
|
-
]);
|
|
315
|
-
const confirmReplace = await confirm({
|
|
316
|
-
message: `Replace existing key for ecloud?`,
|
|
317
|
-
default: false
|
|
318
|
-
});
|
|
319
|
-
if (!confirmReplace) {
|
|
320
|
-
this.log(
|
|
321
|
-
"\nKey not stored. If you did not save your new key when it was displayed, it is now lost and cannot be recovered."
|
|
322
|
-
);
|
|
323
|
-
return;
|
|
324
|
-
}
|
|
182
|
+
if (!confirmReplace) {
|
|
183
|
+
this.log(
|
|
184
|
+
"\nKey not stored. If you did not save your new key when it was displayed, it is now lost and cannot be recovered."
|
|
185
|
+
);
|
|
186
|
+
return;
|
|
325
187
|
}
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
188
|
+
}
|
|
189
|
+
try {
|
|
190
|
+
await storePrivateKey(privateKey);
|
|
191
|
+
this.log(`
|
|
329
192
|
\u2713 Private key stored in OS keyring`);
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
}
|
|
335
|
-
} else {
|
|
336
|
-
this.log("\nKey not stored in keyring.");
|
|
337
|
-
this.log("Remember to save the key shown above in a secure location.");
|
|
193
|
+
this.log(`\u2713 Address: ${address}`);
|
|
194
|
+
this.log("\nYou can now use ecloud commands without --private-key flag.");
|
|
195
|
+
} catch (err) {
|
|
196
|
+
this.error(`Failed to store key: ${err.message}`);
|
|
338
197
|
}
|
|
339
|
-
}
|
|
198
|
+
} else {
|
|
199
|
+
this.log("\nKey not stored in keyring.");
|
|
200
|
+
this.log("Remember to save the key shown above in a secure location.");
|
|
201
|
+
}
|
|
340
202
|
}
|
|
341
203
|
};
|
|
342
204
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/commands/auth/generate.ts","../../../src/utils/security.ts","../../../src/telemetry.ts","../../../src/utils/globalConfig.ts"],"sourcesContent":["/**\n * Auth Generate Command\n *\n * Generate a new private key and optionally store it in OS keyring\n */\n\nimport { Command, Flags } from \"@oclif/core\";\nimport { confirm } from \"@inquirer/prompts\";\nimport { generateNewPrivateKey, storePrivateKey, keyExists } from \"@layr-labs/ecloud-sdk\";\nimport { showPrivateKey, displayWarning } from \"../../utils/security\";\nimport { withTelemetry } from \"../../telemetry\";\n\nexport default class AuthGenerate extends Command {\n static description = \"Generate a new private key\";\n\n static aliases = [\"auth:gen\", \"auth:new\"];\n\n static examples = [\n \"<%= config.bin %> <%= command.id %>\",\n \"<%= config.bin %> <%= command.id %> --store\",\n ];\n\n static flags = {\n store: Flags.boolean({\n description: \"Automatically store in OS keyring\",\n default: false,\n }),\n };\n\n async run(): Promise<void> {\n return withTelemetry(this, async () => {\n const { flags } = await this.parse(AuthGenerate);\n\n // Generate new key\n this.log(\"Generating new private key...\\n\");\n const { privateKey, address } = generateNewPrivateKey();\n\n // Display key securely\n const content = `\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\nA new private key was generated for you.\n\nIMPORTANT: You MUST backup this key now.\n It will never be shown again.\n\nAddress: ${address}\nPrivate key: ${privateKey}\n\n⚠️ SECURITY WARNING:\n • Anyone with this key can control your account\n • Never share it or commit it to version control\n • Store it in a secure password manager\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n\nPress 'q' to exit and continue...\n`;\n\n const displayed = await showPrivateKey(content);\n\n if (!displayed) {\n this.log(\"Key generation cancelled.\");\n return;\n }\n\n // Ask about storing\n let shouldStore = flags.store;\n\n if (!shouldStore && displayed) {\n shouldStore = await confirm({\n message: \"Store this key in your OS keyring?\",\n default: true,\n });\n }\n\n if (shouldStore) {\n // Check if key already exists\n const exists = await keyExists();\n\n if (exists) {\n displayWarning([\n `WARNING: A private key for ecloud already exists!`,\n \"If you continue, the existing key will be PERMANENTLY REPLACED.\",\n \"This cannot be undone!\",\n \"\",\n \"The previous key will be lost forever if you haven't backed it up.\",\n ]);\n\n const confirmReplace = await confirm({\n message: `Replace existing key for ecloud?`,\n default: false,\n });\n\n if (!confirmReplace) {\n this.log(\n \"\\nKey not stored. If you did not save your new key when it was displayed, it is now lost and cannot be recovered.\",\n );\n return;\n }\n }\n\n // Store the key\n try {\n await storePrivateKey(privateKey);\n this.log(`\\n✓ Private key stored in OS keyring`);\n this.log(`✓ Address: ${address}`);\n this.log(\"\\nYou can now use ecloud commands without --private-key flag.\");\n } catch (err: any) {\n this.error(`Failed to store key: ${err.message}`);\n }\n } else {\n this.log(\"\\nKey not stored in keyring.\");\n this.log(\"Remember to save the key shown above in a secure location.\");\n }\n });\n }\n}\n","/**\n * Security utilities for CLI\n *\n * Functions for securely displaying and handling sensitive content\n * like private keys.\n */\n\nimport { spawn, execSync } from \"child_process\";\nimport { platform } from \"os\";\nimport { select, password } from \"@inquirer/prompts\";\n\n/**\n * Display sensitive content using system pager (less/more)\n * Returns true if content was displayed, false if user aborted\n */\nexport async function showPrivateKey(content: string): Promise<boolean> {\n // Try to use system pager\n const pager = detectPager();\n\n if (pager) {\n try {\n await runPager(pager, content);\n return true;\n } catch (err) {\n console.error(`Failed to run pager: ${err}`);\n // Fall through to fallback\n }\n }\n\n // No pager available - give user a choice\n console.log(\"\\nNo pager (less/more) found on PATH.\");\n console.log(\"For security, avoid printing private keys to the terminal.\");\n console.log(\"\");\n\n const choice = await select({\n message: \"Choose an option:\",\n choices: [\n { name: \"Abort (recommended)\", value: \"abort\" },\n { name: \"Print and clear screen\", value: \"print\" },\n ],\n });\n\n if (choice === \"print\") {\n console.log(content);\n console.log(\"\");\n console.log(\"Press Enter after you have securely saved the key.\");\n console.log(\"The screen will be cleared...\");\n\n // Wait for Enter\n await password({\n message: \"\",\n mask: \"\",\n });\n\n clearTerminal();\n return true;\n }\n\n return false; // User aborted\n}\n\n/**\n * Detect system pager (less or more)\n */\nfunction detectPager(): string | null {\n // Check PAGER env var first\n if (process.env.PAGER) {\n const pagerEnv = process.env.PAGER.trim();\n // Only allow simple command names without arguments or special characters\n if (/^[a-zA-Z0-9_-]+$/.test(pagerEnv)) {\n return pagerEnv;\n }\n }\n\n // Try common pagers\n const pagers = [\"less\", \"more\"];\n\n for (const pagerCmd of pagers) {\n if (commandExists(pagerCmd)) {\n return pagerCmd;\n }\n }\n\n return null;\n}\n\n/**\n * Run pager with content\n */\nfunction runPager(pager: string, content: string): Promise<void> {\n return new Promise((resolve, reject) => {\n const child = spawn(pager, [], {\n stdio: [\"pipe\", \"inherit\", \"inherit\"],\n });\n\n child.on(\"error\", reject);\n child.on(\"exit\", (code) => {\n if (code === 0) {\n resolve();\n } else {\n reject(new Error(`Pager exited with code ${code}`));\n }\n });\n\n try {\n const written = child.stdin!.write(content);\n if (!written) {\n child.stdin!.once(\"drain\", () => {\n try {\n child.stdin!.end();\n } catch (err) {\n reject(err);\n }\n });\n } else {\n child.stdin!.end();\n }\n } catch (err) {\n reject(err);\n }\n });\n}\n\n/**\n * Check if command exists\n */\nfunction commandExists(command: string): boolean {\n try {\n const cmd = platform() === \"win32\" ? `where ${command}` : `which ${command}`;\n execSync(cmd, { stdio: \"ignore\" });\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Clear terminal screen\n */\nexport function clearTerminal(): void {\n if (platform() === \"win32\") {\n process.stdout.write(\"\\x1Bc\");\n } else {\n process.stdout.write(\"\\x1B[2J\\x1B[3J\\x1B[H\");\n }\n}\n\n/**\n * Get hidden input (password-style)\n */\nexport async function getHiddenInput(message: string): Promise<string> {\n return await password({\n message,\n mask: \"*\",\n });\n}\n\n/**\n * Display multi-line warning for destructive operations\n */\nexport function displayWarning(lines: string[]): void {\n const width = lines.length > 0 ? Math.max(...lines.map((l) => l.length)) + 4 : 4;\n const border = \"⚠\".repeat(width);\n\n console.log(\"\");\n console.log(border);\n for (const line of lines) {\n console.log(`⚠ ${line}`);\n }\n console.log(border);\n console.log(\"\");\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","/**\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"],"mappings":";;;AAMA,SAAS,SAAS,aAAa;AAC/B,SAAS,eAAe;AACxB,SAAS,uBAAuB,iBAAiB,iBAAiB;;;ACDlE,SAAS,OAAO,gBAAgB;AAChC,SAAS,gBAAgB;AACzB,SAAS,QAAQ,gBAAgB;AAMjC,eAAsB,eAAe,SAAmC;AAEtE,QAAM,QAAQ,YAAY;AAE1B,MAAI,OAAO;AACT,QAAI;AACF,YAAM,SAAS,OAAO,OAAO;AAC7B,aAAO;AAAA,IACT,SAAS,KAAK;AACZ,cAAQ,MAAM,wBAAwB,GAAG,EAAE;AAAA,IAE7C;AAAA,EACF;AAGA,UAAQ,IAAI,uCAAuC;AACnD,UAAQ,IAAI,4DAA4D;AACxE,UAAQ,IAAI,EAAE;AAEd,QAAM,SAAS,MAAM,OAAO;AAAA,IAC1B,SAAS;AAAA,IACT,SAAS;AAAA,MACP,EAAE,MAAM,uBAAuB,OAAO,QAAQ;AAAA,MAC9C,EAAE,MAAM,0BAA0B,OAAO,QAAQ;AAAA,IACnD;AAAA,EACF,CAAC;AAED,MAAI,WAAW,SAAS;AACtB,YAAQ,IAAI,OAAO;AACnB,YAAQ,IAAI,EAAE;AACd,YAAQ,IAAI,oDAAoD;AAChE,YAAQ,IAAI,+BAA+B;AAG3C,UAAM,SAAS;AAAA,MACb,SAAS;AAAA,MACT,MAAM;AAAA,IACR,CAAC;AAED,kBAAc;AACd,WAAO;AAAA,EACT;AAEA,SAAO;AACT;AAKA,SAAS,cAA6B;AAEpC,MAAI,QAAQ,IAAI,OAAO;AACrB,UAAM,WAAW,QAAQ,IAAI,MAAM,KAAK;AAExC,QAAI,mBAAmB,KAAK,QAAQ,GAAG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AAAA,cACH;AAAA,YACF;AACA;AAAA,UACF;AAAA,QACF;AAGA,YAAI;AACF,gBAAM,gBAAgB,UAAU;AAChC,eAAK,IAAI;AAAA,wCAAsC;AAC/C,eAAK,IAAI,mBAAc,OAAO,EAAE;AAChC,eAAK,IAAI,+DAA+D;AAAA,QAC1E,SAAS,KAAU;AACjB,eAAK,MAAM,wBAAwB,IAAI,OAAO,EAAE;AAAA,QAClD;AAAA,MACF,OAAO;AACL,aAAK,IAAI,8BAA8B;AACvC,aAAK,IAAI,4DAA4D;AAAA,MACvE;AAAA,IACF,CAAC;AAAA,EACH;AACF;","names":["getBuildType","getBuildType"]}
|
|
1
|
+
{"version":3,"sources":["../../../src/commands/auth/generate.ts","../../../src/utils/security.ts"],"sourcesContent":["/**\n * Auth Generate Command\n *\n * Generate a new private key and optionally store it in OS keyring\n */\n\nimport { Command, Flags } from \"@oclif/core\";\nimport { confirm } from \"@inquirer/prompts\";\nimport { generateNewPrivateKey, storePrivateKey, keyExists } from \"@layr-labs/ecloud-sdk\";\nimport { showPrivateKey, displayWarning } from \"../../utils/security\";\n\nexport default class AuthGenerate extends Command {\n static description = \"Generate a new private key\";\n\n static aliases = [\"auth:gen\", \"auth:new\"];\n\n static examples = [\n \"<%= config.bin %> <%= command.id %>\",\n \"<%= config.bin %> <%= command.id %> --store\",\n ];\n\n static flags = {\n store: Flags.boolean({\n description: \"Automatically store in OS keyring\",\n default: false,\n }),\n };\n\n async run(): Promise<void> {\n const { flags } = await this.parse(AuthGenerate);\n\n // Generate new key\n this.log(\"Generating new private key...\\n\");\n const { privateKey, address } = generateNewPrivateKey();\n\n // Display key securely\n const content = `\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\nA new private key was generated for you.\n\nIMPORTANT: You MUST backup this key now.\n It will never be shown again.\n\nAddress: ${address}\nPrivate key: ${privateKey}\n\n⚠️ SECURITY WARNING:\n • Anyone with this key can control your account\n • Never share it or commit it to version control\n • Store it in a secure password manager\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n\nPress 'q' to exit and continue...\n`;\n\n const displayed = await showPrivateKey(content);\n\n if (!displayed) {\n this.log(\"Key generation cancelled.\");\n return;\n }\n\n // Ask about storing\n let shouldStore = flags.store;\n\n if (!shouldStore && displayed) {\n shouldStore = await confirm({\n message: \"Store this key in your OS keyring?\",\n default: true,\n });\n }\n\n if (shouldStore) {\n // Check if key already exists\n const exists = await keyExists();\n\n if (exists) {\n displayWarning([\n `WARNING: A private key for ecloud already exists!`,\n \"If you continue, the existing key will be PERMANENTLY REPLACED.\",\n \"This cannot be undone!\",\n \"\",\n \"The previous key will be lost forever if you haven't backed it up.\",\n ]);\n\n const confirmReplace = await confirm({\n message: `Replace existing key for ecloud?`,\n default: false,\n });\n\n if (!confirmReplace) {\n this.log(\n \"\\nKey not stored. If you did not save your new key when it was displayed, it is now lost and cannot be recovered.\",\n );\n return;\n }\n }\n\n // Store the key\n try {\n await storePrivateKey(privateKey);\n this.log(`\\n✓ Private key stored in OS keyring`);\n this.log(`✓ Address: ${address}`);\n this.log(\"\\nYou can now use ecloud commands without --private-key flag.\");\n } catch (err: any) {\n this.error(`Failed to store key: ${err.message}`);\n }\n } else {\n this.log(\"\\nKey not stored in keyring.\");\n this.log(\"Remember to save the key shown above in a secure location.\");\n }\n }\n}\n","/**\n * Security utilities for CLI\n *\n * Functions for securely displaying and handling sensitive content\n * like private keys.\n */\n\nimport { spawn, execSync } from \"child_process\";\nimport { platform } from \"os\";\nimport { select, password } from \"@inquirer/prompts\";\n\n/**\n * Display sensitive content using system pager (less/more)\n * Returns true if content was displayed, false if user aborted\n */\nexport async function showPrivateKey(content: string): Promise<boolean> {\n // Try to use system pager\n const pager = detectPager();\n\n if (pager) {\n try {\n await runPager(pager, content);\n return true;\n } catch (err) {\n console.error(`Failed to run pager: ${err}`);\n // Fall through to fallback\n }\n }\n\n // No pager available - give user a choice\n console.log(\"\\nNo pager (less/more) found on PATH.\");\n console.log(\"For security, avoid printing private keys to the terminal.\");\n console.log(\"\");\n\n const choice = await select({\n message: \"Choose an option:\",\n choices: [\n { name: \"Abort (recommended)\", value: \"abort\" },\n { name: \"Print and clear screen\", value: \"print\" },\n ],\n });\n\n if (choice === \"print\") {\n console.log(content);\n console.log(\"\");\n console.log(\"Press Enter after you have securely saved the key.\");\n console.log(\"The screen will be cleared...\");\n\n // Wait for Enter\n await password({\n message: \"\",\n mask: \"\",\n });\n\n clearTerminal();\n return true;\n }\n\n return false; // User aborted\n}\n\n/**\n * Detect system pager (less or more)\n */\nfunction detectPager(): string | null {\n // Check PAGER env var first\n if (process.env.PAGER) {\n const pagerEnv = process.env.PAGER.trim();\n // Only allow simple command names without arguments or special characters\n if (/^[a-zA-Z0-9_-]+$/.test(pagerEnv)) {\n return pagerEnv;\n }\n }\n\n // Try common pagers\n const pagers = [\"less\", \"more\"];\n\n for (const pagerCmd of pagers) {\n if (commandExists(pagerCmd)) {\n return pagerCmd;\n }\n }\n\n return null;\n}\n\n/**\n * Run pager with content\n */\nfunction runPager(pager: string, content: string): Promise<void> {\n return new Promise((resolve, reject) => {\n const child = spawn(pager, [], {\n stdio: [\"pipe\", \"inherit\", \"inherit\"],\n });\n\n child.on(\"error\", reject);\n child.on(\"exit\", (code) => {\n if (code === 0) {\n resolve();\n } else {\n reject(new Error(`Pager exited with code ${code}`));\n }\n });\n\n try {\n const written = child.stdin!.write(content);\n if (!written) {\n child.stdin!.once(\"drain\", () => {\n try {\n child.stdin!.end();\n } catch (err) {\n reject(err);\n }\n });\n } else {\n child.stdin!.end();\n }\n } catch (err) {\n reject(err);\n }\n });\n}\n\n/**\n * Check if command exists\n */\nfunction commandExists(command: string): boolean {\n try {\n const cmd = platform() === \"win32\" ? `where ${command}` : `which ${command}`;\n execSync(cmd, { stdio: \"ignore\" });\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Clear terminal screen\n */\nexport function clearTerminal(): void {\n if (platform() === \"win32\") {\n process.stdout.write(\"\\x1Bc\");\n } else {\n process.stdout.write(\"\\x1B[2J\\x1B[3J\\x1B[H\");\n }\n}\n\n/**\n * Get hidden input (password-style)\n */\nexport async function getHiddenInput(message: string): Promise<string> {\n return await password({\n message,\n mask: \"*\",\n });\n}\n\n/**\n * Display multi-line warning for destructive operations\n */\nexport function displayWarning(lines: string[]): void {\n const width = lines.length > 0 ? Math.max(...lines.map((l) => l.length)) + 4 : 4;\n const border = \"⚠\".repeat(width);\n\n console.log(\"\");\n console.log(border);\n for (const line of lines) {\n console.log(`⚠ ${line}`);\n }\n console.log(border);\n console.log(\"\");\n}\n"],"mappings":";;;AAMA,SAAS,SAAS,aAAa;AAC/B,SAAS,eAAe;AACxB,SAAS,uBAAuB,iBAAiB,iBAAiB;;;ACDlE,SAAS,OAAO,gBAAgB;AAChC,SAAS,gBAAgB;AACzB,SAAS,QAAQ,gBAAgB;AAMjC,eAAsB,eAAe,SAAmC;AAEtE,QAAM,QAAQ,YAAY;AAE1B,MAAI,OAAO;AACT,QAAI;AACF,YAAM,SAAS,OAAO,OAAO;AAC7B,aAAO;AAAA,IACT,SAAS,KAAK;AACZ,cAAQ,MAAM,wBAAwB,GAAG,EAAE;AAAA,IAE7C;AAAA,EACF;AAGA,UAAQ,IAAI,uCAAuC;AACnD,UAAQ,IAAI,4DAA4D;AACxE,UAAQ,IAAI,EAAE;AAEd,QAAM,SAAS,MAAM,OAAO;AAAA,IAC1B,SAAS;AAAA,IACT,SAAS;AAAA,MACP,EAAE,MAAM,uBAAuB,OAAO,QAAQ;AAAA,MAC9C,EAAE,MAAM,0BAA0B,OAAO,QAAQ;AAAA,IACnD;AAAA,EACF,CAAC;AAED,MAAI,WAAW,SAAS;AACtB,YAAQ,IAAI,OAAO;AACnB,YAAQ,IAAI,EAAE;AACd,YAAQ,IAAI,oDAAoD;AAChE,YAAQ,IAAI,+BAA+B;AAG3C,UAAM,SAAS;AAAA,MACb,SAAS;AAA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