Skip to content

Commit f751ea0

Browse files
grezlegithub-advanced-security[bot]shrimalmadhur
authored
feat: add posthog telemetry to all CLI commands and top-level SDK methods (#37)
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> Co-authored-by: Madhur Shrimal <[email protected]>
1 parent ec45f63 commit f751ea0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+3037
-1954
lines changed

.github/workflows/release-dev.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ jobs:
6161
env:
6262
BUILD_TYPE: dev
6363
PACKAGE_VERSION: ${{ env.PACKAGE_VERSION }}
64+
POSTHOG_API_KEY_BUILD_TIME: ${{ secrets.POSTHOG_API_KEY }}
6465
run: |
6566
pnpm run build
6667
@@ -69,6 +70,7 @@ jobs:
6970
env:
7071
BUILD_TYPE: dev
7172
PACKAGE_VERSION: ${{ env.PACKAGE_VERSION }}
73+
POSTHOG_API_KEY_BUILD_TIME: ${{ secrets.POSTHOG_API_KEY }}
7274
run: |
7375
pnpm run build
7476

.github/workflows/release-prod.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ jobs:
101101
env:
102102
BUILD_TYPE: prod
103103
PACKAGE_VERSION: ${{ env.PACKAGE_VERSION }}
104+
POSTHOG_API_KEY_BUILD_TIME: ${{ secrets.POSTHOG_API_KEY }}
104105
run: |
105106
pnpm run build
106107
@@ -109,6 +110,7 @@ jobs:
109110
env:
110111
BUILD_TYPE: prod
111112
PACKAGE_VERSION: ${{ env.PACKAGE_VERSION }}
113+
POSTHOG_API_KEY_BUILD_TIME: ${{ secrets.POSTHOG_API_KEY }}
112114
run: |
113115
pnpm run build
114116

eslint.config.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,18 @@ import tseslint from "@typescript-eslint/eslint-plugin";
22
import tsparser from "@typescript-eslint/parser";
33

44
export default [
5+
{
6+
ignores: ["**/dist/**"],
7+
},
58
{
69
files: ["**/*.ts"],
710
languageOptions: { parser: tsparser },
811
plugins: { "@typescript-eslint": tseslint },
9-
rules: { "@typescript-eslint/no-unused-vars": ["error"] },
12+
rules: {
13+
"@typescript-eslint/no-unused-vars": [
14+
"error",
15+
{ argsIgnorePattern: "^_", varsIgnorePattern: "^_" },
16+
],
17+
},
1018
},
1119
];

packages/cli/src/client.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export async function createComputeClient(flags: CommonFlags) {
3030
rpcUrl,
3131
environment,
3232
clientId: getClientId(),
33+
skipTelemetry: true, // CLI already has telemetry, skip SDK telemetry
3334
});
3435
}
3536

@@ -42,5 +43,6 @@ export async function createBillingClient(flags: { "private-key"?: string; verbo
4243
return createBillingModule({
4344
verbose: flags.verbose ?? false,
4445
privateKey: privateKey as Hex,
46+
skipTelemetry: true, // CLI already has telemetry, skip SDK telemetry
4547
});
4648
}

packages/cli/src/commands/auth/generate.ts

Lines changed: 60 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { Command, Flags } from "@oclif/core";
88
import { confirm } from "@inquirer/prompts";
99
import { generateNewPrivateKey, storePrivateKey, keyExists } from "@layr-labs/ecloud-sdk";
1010
import { showPrivateKey, displayWarning } from "../../utils/security";
11+
import { withTelemetry } from "../../telemetry";
1112

1213
export default class AuthGenerate extends Command {
1314
static description = "Generate a new private key";
@@ -27,14 +28,15 @@ export default class AuthGenerate extends Command {
2728
};
2829

2930
async run(): Promise<void> {
30-
const { flags } = await this.parse(AuthGenerate);
31+
return withTelemetry(this, async () => {
32+
const { flags } = await this.parse(AuthGenerate);
3133

32-
// Generate new key
33-
this.log("Generating new private key...\n");
34-
const { privateKey, address } = generateNewPrivateKey();
34+
// Generate new key
35+
this.log("Generating new private key...\n");
36+
const { privateKey, address } = generateNewPrivateKey();
3537

36-
// Display key securely
37-
const content = `
38+
// Display key securely
39+
const content = `
3840
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
3941
A new private key was generated for you.
4042
@@ -53,61 +55,62 @@ Private key: ${privateKey}
5355
Press 'q' to exit and continue...
5456
`;
5557

56-
const displayed = await showPrivateKey(content);
57-
58-
if (!displayed) {
59-
this.log("Key generation cancelled.");
60-
return;
61-
}
62-
63-
// Ask about storing
64-
let shouldStore = flags.store;
65-
66-
if (!shouldStore && displayed) {
67-
shouldStore = await confirm({
68-
message: "Store this key in your OS keyring?",
69-
default: true,
70-
});
71-
}
72-
73-
if (shouldStore) {
74-
// Check if key already exists
75-
const exists = await keyExists();
76-
77-
if (exists) {
78-
displayWarning([
79-
`WARNING: A private key for ecloud already exists!`,
80-
"If you continue, the existing key will be PERMANENTLY REPLACED.",
81-
"This cannot be undone!",
82-
"",
83-
"The previous key will be lost forever if you haven't backed it up.",
84-
]);
85-
86-
const confirmReplace = await confirm({
87-
message: `Replace existing key for ecloud?`,
88-
default: false,
58+
const displayed = await showPrivateKey(content);
59+
60+
if (!displayed) {
61+
this.log("Key generation cancelled.");
62+
return;
63+
}
64+
65+
// Ask about storing
66+
let shouldStore = flags.store;
67+
68+
if (!shouldStore && displayed) {
69+
shouldStore = await confirm({
70+
message: "Store this key in your OS keyring?",
71+
default: true,
8972
});
73+
}
9074

91-
if (!confirmReplace) {
92-
this.log(
93-
"\nKey not stored. If you did not save your new key when it was displayed, it is now lost and cannot be recovered.",
94-
);
95-
return;
75+
if (shouldStore) {
76+
// Check if key already exists
77+
const exists = await keyExists();
78+
79+
if (exists) {
80+
displayWarning([
81+
`WARNING: A private key for ecloud already exists!`,
82+
"If you continue, the existing key will be PERMANENTLY REPLACED.",
83+
"This cannot be undone!",
84+
"",
85+
"The previous key will be lost forever if you haven't backed it up.",
86+
]);
87+
88+
const confirmReplace = await confirm({
89+
message: `Replace existing key for ecloud?`,
90+
default: false,
91+
});
92+
93+
if (!confirmReplace) {
94+
this.log(
95+
"\nKey not stored. If you did not save your new key when it was displayed, it is now lost and cannot be recovered.",
96+
);
97+
return;
98+
}
9699
}
97-
}
98100

99-
// Store the key
100-
try {
101-
await storePrivateKey(privateKey);
102-
this.log(`\n✓ Private key stored in OS keyring`);
103-
this.log(`✓ Address: ${address}`);
104-
this.log("\nYou can now use ecloud commands without --private-key flag.");
105-
} catch (err: any) {
106-
this.error(`Failed to store key: ${err.message}`);
101+
// Store the key
102+
try {
103+
await storePrivateKey(privateKey);
104+
this.log(`\n✓ Private key stored in OS keyring`);
105+
this.log(`✓ Address: ${address}`);
106+
this.log("\nYou can now use ecloud commands without --private-key flag.");
107+
} catch (err: any) {
108+
this.error(`Failed to store key: ${err.message}`);
109+
}
110+
} else {
111+
this.log("\nKey not stored in keyring.");
112+
this.log("Remember to save the key shown above in a secure location.");
107113
}
108-
} else {
109-
this.log("\nKey not stored in keyring.");
110-
this.log("Remember to save the key shown above in a secure location.");
111-
}
114+
});
112115
}
113116
}

0 commit comments

Comments
 (0)