create-db 0.0.11 → 0.0.13-pr27-feat-posthog-16472784776.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/analytics.js +60 -0
- package/index.js +71 -4
- package/package.json +3 -2
package/analytics.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { randomUUID } from "crypto";
|
|
2
|
+
|
|
3
|
+
class EventCaptureError extends Error {
|
|
4
|
+
constructor(event, status) {
|
|
5
|
+
super(`Failed to submit PostHog event '${event}': ${status}`);
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
class PosthogEventCapture {
|
|
10
|
+
async capture(eventName, properties = {}) {
|
|
11
|
+
const POSTHOG_CAPTURE_URL = process.env.POSTHOG_API_HOST
|
|
12
|
+
? process.env.POSTHOG_API_HOST + "/capture"
|
|
13
|
+
: null;
|
|
14
|
+
const POSTHOG_KEY = process.env.POSTHOG_API_KEY;
|
|
15
|
+
|
|
16
|
+
// Skip if environment variables are not set
|
|
17
|
+
if (!POSTHOG_CAPTURE_URL || !POSTHOG_KEY) {
|
|
18
|
+
if (process.env.NODE_ENV === "development") {
|
|
19
|
+
console.warn(
|
|
20
|
+
"Analytics skipped: POSTHOG_API_HOST or POSTHOG_API_KEY not set"
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const payload = {
|
|
27
|
+
api_key: POSTHOG_KEY,
|
|
28
|
+
event: eventName,
|
|
29
|
+
distinct_id: randomUUID(),
|
|
30
|
+
properties: {
|
|
31
|
+
$process_person_profile: false,
|
|
32
|
+
...properties,
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
try {
|
|
37
|
+
const response = await fetch(POSTHOG_CAPTURE_URL, {
|
|
38
|
+
method: "POST",
|
|
39
|
+
headers: {
|
|
40
|
+
"Content-Type": "application/json",
|
|
41
|
+
},
|
|
42
|
+
body: JSON.stringify(payload),
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
if (!response.ok) {
|
|
46
|
+
throw new EventCaptureError(eventName, response.statusText);
|
|
47
|
+
}
|
|
48
|
+
} catch (error) {
|
|
49
|
+
// Silently fail analytics to not disrupt user experience
|
|
50
|
+
if (process.env.NODE_ENV === "development") {
|
|
51
|
+
console.error("Analytics error:", error.message);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Create a singleton instance
|
|
58
|
+
const analytics = new PosthogEventCapture();
|
|
59
|
+
|
|
60
|
+
export { analytics, EventCaptureError };
|
package/index.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
+
import dotenv from "dotenv";
|
|
4
|
+
dotenv.config();
|
|
5
|
+
|
|
3
6
|
import {
|
|
4
7
|
select,
|
|
5
8
|
spinner,
|
|
@@ -7,13 +10,10 @@ import {
|
|
|
7
10
|
outro,
|
|
8
11
|
log,
|
|
9
12
|
cancel,
|
|
10
|
-
confirm,
|
|
11
13
|
} from "@clack/prompts";
|
|
12
14
|
import chalk from "chalk";
|
|
13
|
-
import dotenv from "dotenv";
|
|
14
15
|
import terminalLink from "terminal-link";
|
|
15
|
-
|
|
16
|
-
dotenv.config();
|
|
16
|
+
import { analytics } from "./analytics.js";
|
|
17
17
|
|
|
18
18
|
const CREATE_DB_WORKER_URL =
|
|
19
19
|
process.env.CREATE_DB_WORKER_URL || "https://create-db-temp.prisma.io";
|
|
@@ -265,6 +265,17 @@ async function promptForRegion(defaultRegion) {
|
|
|
265
265
|
process.exit(0);
|
|
266
266
|
}
|
|
267
267
|
|
|
268
|
+
// Track region selection event
|
|
269
|
+
try {
|
|
270
|
+
await analytics.capture("create_db:region_selected", {
|
|
271
|
+
command: CLI_NAME,
|
|
272
|
+
region: region,
|
|
273
|
+
"selection-method": "interactive"
|
|
274
|
+
});
|
|
275
|
+
} catch (error) {
|
|
276
|
+
// Silently fail analytics
|
|
277
|
+
}
|
|
278
|
+
|
|
268
279
|
return region;
|
|
269
280
|
}
|
|
270
281
|
|
|
@@ -284,6 +295,19 @@ async function createDatabase(name, region) {
|
|
|
284
295
|
s.stop(
|
|
285
296
|
"We're experiencing a high volume of requests. Please try again later."
|
|
286
297
|
);
|
|
298
|
+
|
|
299
|
+
// Track database creation failure
|
|
300
|
+
try {
|
|
301
|
+
await analytics.capture("create_db:database_creation_failed", {
|
|
302
|
+
command: CLI_NAME,
|
|
303
|
+
region: region,
|
|
304
|
+
"error-type": "rate_limit",
|
|
305
|
+
"status-code": 429,
|
|
306
|
+
});
|
|
307
|
+
} catch (error) {
|
|
308
|
+
// Silently fail analytics
|
|
309
|
+
}
|
|
310
|
+
|
|
287
311
|
process.exit(1);
|
|
288
312
|
}
|
|
289
313
|
|
|
@@ -293,6 +317,18 @@ async function createDatabase(name, region) {
|
|
|
293
317
|
s.stop(
|
|
294
318
|
`Error creating database: ${result.error.message || "Unknown error"}`
|
|
295
319
|
);
|
|
320
|
+
|
|
321
|
+
// Track database creation failure
|
|
322
|
+
try {
|
|
323
|
+
await analytics.capture("create_db:database_creation_failed", {
|
|
324
|
+
command: CLI_NAME,
|
|
325
|
+
region: region,
|
|
326
|
+
"error-type": "api_error",
|
|
327
|
+
"error-message": result.error.message,
|
|
328
|
+
});
|
|
329
|
+
} catch (error) {
|
|
330
|
+
// Silently fail analytics
|
|
331
|
+
}
|
|
296
332
|
process.exit(1);
|
|
297
333
|
}
|
|
298
334
|
|
|
@@ -362,6 +398,26 @@ async function createDatabase(name, region) {
|
|
|
362
398
|
|
|
363
399
|
async function main() {
|
|
364
400
|
try {
|
|
401
|
+
const rawArgs = process.argv.slice(2);
|
|
402
|
+
log.message(
|
|
403
|
+
chalk.white(`POSTHOG: ${process.env.POSTHOG_API_KEY} ${process.env.POSTHOG_API_HOST}`)
|
|
404
|
+
);
|
|
405
|
+
try {
|
|
406
|
+
await analytics.capture("create_db:cli_command_ran", {
|
|
407
|
+
command: CLI_NAME,
|
|
408
|
+
"full-command": `${CLI_NAME} ${rawArgs.join(' ')}`.trim(),
|
|
409
|
+
"has-region-flag": rawArgs.includes('--region') || rawArgs.includes('-r'),
|
|
410
|
+
"has-interactive-flag": rawArgs.includes('--interactive') || rawArgs.includes('-i'),
|
|
411
|
+
"has-help-flag": rawArgs.includes('--help') || rawArgs.includes('-h'),
|
|
412
|
+
"has-list-regions-flag": rawArgs.includes('--list-regions'),
|
|
413
|
+
"node-version": process.version,
|
|
414
|
+
platform: process.platform,
|
|
415
|
+
arch: process.arch
|
|
416
|
+
});
|
|
417
|
+
} catch (error) {
|
|
418
|
+
// Silently fail analytics
|
|
419
|
+
}
|
|
420
|
+
|
|
365
421
|
// Parse command line arguments
|
|
366
422
|
const { flags } = await parseArgs();
|
|
367
423
|
|
|
@@ -386,6 +442,17 @@ async function main() {
|
|
|
386
442
|
// Apply command line flags
|
|
387
443
|
if (flags.region) {
|
|
388
444
|
region = flags.region;
|
|
445
|
+
|
|
446
|
+
// Track region selection via flag
|
|
447
|
+
try {
|
|
448
|
+
await analytics.capture("create_db:region_selected", {
|
|
449
|
+
command: CLI_NAME,
|
|
450
|
+
region: region,
|
|
451
|
+
"selection-method": "flag"
|
|
452
|
+
});
|
|
453
|
+
} catch (error) {
|
|
454
|
+
// Silently fail analytics
|
|
455
|
+
}
|
|
389
456
|
}
|
|
390
457
|
if (flags.interactive) {
|
|
391
458
|
chooseRegionPrompt = true;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-db",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.13-pr27-feat-posthog-16472784776.0",
|
|
4
4
|
"description": "Instantly create a temporary Prisma Postgres database with one command, then claim and persist it in your Prisma Data Platform project when ready.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"author": "",
|
|
@@ -39,6 +39,7 @@
|
|
|
39
39
|
"files": [
|
|
40
40
|
"index.js",
|
|
41
41
|
"README.md",
|
|
42
|
-
"demo.gif"
|
|
42
|
+
"demo.gif",
|
|
43
|
+
"analytics.js"
|
|
43
44
|
]
|
|
44
45
|
}
|