prpm 0.1.16 → 0.1.17
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/dist/commands/login.js +17 -1
- package/dist/core/telemetry.js +46 -0
- package/dist/core/user-config.js +2 -0
- package/package.json +5 -3
package/dist/commands/login.js
CHANGED
|
@@ -40,6 +40,7 @@ exports.handleLogin = handleLogin;
|
|
|
40
40
|
exports.createLoginCommand = createLoginCommand;
|
|
41
41
|
const commander_1 = require("commander");
|
|
42
42
|
const http_1 = require("http");
|
|
43
|
+
const jwt = __importStar(require("jsonwebtoken"));
|
|
43
44
|
const telemetry_1 = require("../core/telemetry");
|
|
44
45
|
const user_config_1 = require("../core/user-config");
|
|
45
46
|
const errors_1 = require("../core/errors");
|
|
@@ -257,11 +258,26 @@ async function handleLogin(options) {
|
|
|
257
258
|
// OAuth login
|
|
258
259
|
result = await loginWithOAuth(registryUrl);
|
|
259
260
|
}
|
|
260
|
-
//
|
|
261
|
+
// Extract user_id and email from JWT token
|
|
262
|
+
const decoded = jwt.decode(result.token);
|
|
263
|
+
if (!decoded) {
|
|
264
|
+
throw new Error('Failed to decode authentication token');
|
|
265
|
+
}
|
|
266
|
+
// Save token and user info to config
|
|
261
267
|
await (0, user_config_1.saveConfig)({
|
|
262
268
|
...config,
|
|
263
269
|
token: result.token,
|
|
264
270
|
username: result.username,
|
|
271
|
+
userId: decoded.user_id,
|
|
272
|
+
email: decoded.email,
|
|
273
|
+
});
|
|
274
|
+
// Identify user in PostHog with user properties
|
|
275
|
+
await telemetry_1.telemetry.identifyUser(decoded.user_id, {
|
|
276
|
+
username: result.username,
|
|
277
|
+
email: decoded.email,
|
|
278
|
+
cli_version: process.env.npm_package_version,
|
|
279
|
+
platform: process.platform,
|
|
280
|
+
first_login: new Date().toISOString(),
|
|
265
281
|
});
|
|
266
282
|
console.log('✅ Successfully logged in!\n');
|
|
267
283
|
console.log(` Username: ${result.username}`);
|
package/dist/core/telemetry.js
CHANGED
|
@@ -67,6 +67,21 @@ class Telemetry {
|
|
|
67
67
|
};
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* Load userId from user config and update telemetry config
|
|
72
|
+
*/
|
|
73
|
+
async loadUserIdFromConfig() {
|
|
74
|
+
try {
|
|
75
|
+
const userConfig = await (0, user_config_1.getConfig)();
|
|
76
|
+
if (userConfig.userId && userConfig.userId !== this.config.userId) {
|
|
77
|
+
this.config.userId = userConfig.userId;
|
|
78
|
+
await this.saveConfig();
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
// Silently fail - telemetry shouldn't break the CLI
|
|
83
|
+
}
|
|
84
|
+
}
|
|
70
85
|
generateSessionId() {
|
|
71
86
|
return Math.random().toString(36).substring(2, 15) +
|
|
72
87
|
Math.random().toString(36).substring(2, 15);
|
|
@@ -88,6 +103,8 @@ class Telemetry {
|
|
|
88
103
|
return;
|
|
89
104
|
if (!this.config.enabled)
|
|
90
105
|
return;
|
|
106
|
+
// Load userId from user config before tracking
|
|
107
|
+
await this.loadUserIdFromConfig();
|
|
91
108
|
const fullEvent = {
|
|
92
109
|
...event,
|
|
93
110
|
timestamp: new Date().toISOString(),
|
|
@@ -170,6 +187,35 @@ class Telemetry {
|
|
|
170
187
|
}
|
|
171
188
|
}
|
|
172
189
|
}
|
|
190
|
+
/**
|
|
191
|
+
* Identify user in PostHog with user properties
|
|
192
|
+
* Called after successful login to set user attributes
|
|
193
|
+
*/
|
|
194
|
+
async identifyUser(userId, traits) {
|
|
195
|
+
if (!this.posthog || !this.config.enabled)
|
|
196
|
+
return;
|
|
197
|
+
try {
|
|
198
|
+
// Update local config with userId
|
|
199
|
+
this.config.userId = userId;
|
|
200
|
+
await this.saveConfig();
|
|
201
|
+
// Send $identify event to PostHog
|
|
202
|
+
this.posthog.identify({
|
|
203
|
+
distinctId: userId,
|
|
204
|
+
properties: traits,
|
|
205
|
+
});
|
|
206
|
+
// Also capture the $identify event explicitly
|
|
207
|
+
this.posthog.capture({
|
|
208
|
+
distinctId: userId,
|
|
209
|
+
event: '$identify',
|
|
210
|
+
properties: traits,
|
|
211
|
+
});
|
|
212
|
+
// Flush immediately to ensure identification happens
|
|
213
|
+
await this.posthog.flush();
|
|
214
|
+
}
|
|
215
|
+
catch (error) {
|
|
216
|
+
// Silently fail - telemetry shouldn't break the CLI
|
|
217
|
+
}
|
|
218
|
+
}
|
|
173
219
|
// Send to PostHog
|
|
174
220
|
async sendToPostHog(event) {
|
|
175
221
|
if (!this.posthog)
|
package/dist/core/user-config.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "prpm",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.17",
|
|
4
4
|
"description": "Prompt Package Manager CLI - Install and manage prompt-based files",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -45,16 +45,18 @@
|
|
|
45
45
|
"license": "MIT",
|
|
46
46
|
"dependencies": {
|
|
47
47
|
"@octokit/rest": "^22.0.0",
|
|
48
|
-
"@pr-pm/registry-client": "^1.3.
|
|
49
|
-
"@pr-pm/types": "^0.2.
|
|
48
|
+
"@pr-pm/registry-client": "^1.3.15",
|
|
49
|
+
"@pr-pm/types": "^0.2.16",
|
|
50
50
|
"ajv": "^8.17.1",
|
|
51
51
|
"ajv-formats": "^3.0.1",
|
|
52
52
|
"commander": "^11.1.0",
|
|
53
|
+
"jsonwebtoken": "^9.0.2",
|
|
53
54
|
"posthog-node": "^5.10.0",
|
|
54
55
|
"tar": "^6.2.1"
|
|
55
56
|
},
|
|
56
57
|
"devDependencies": {
|
|
57
58
|
"@types/jest": "^29.5.8",
|
|
59
|
+
"@types/jsonwebtoken": "^9.0.10",
|
|
58
60
|
"@types/node": "^20.10.0",
|
|
59
61
|
"@types/tar": "^6.1.13",
|
|
60
62
|
"jest": "^29.7.0",
|