create-db 1.0.3-pr48-DC-4894-posthog-fix-17267509345.0 → 1.0.3-pr48-DC-4894-posthog-fix-17269175017.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/index.js +46 -38
- package/package.json +1 -1
- package/analytics.js +0 -53
package/index.js
CHANGED
|
@@ -6,7 +6,27 @@ dotenv.config();
|
|
|
6
6
|
import { select, spinner, intro, outro, log, cancel } from "@clack/prompts";
|
|
7
7
|
import chalk from "chalk";
|
|
8
8
|
import terminalLink from "terminal-link";
|
|
9
|
-
|
|
9
|
+
|
|
10
|
+
async function sendAnalyticsToWorker(eventName, properties = {}) {
|
|
11
|
+
try {
|
|
12
|
+
const response = await fetch(`${CREATE_DB_WORKER_URL}/analytics`, {
|
|
13
|
+
method: "POST",
|
|
14
|
+
headers: { "Content-Type": "application/json" },
|
|
15
|
+
body: JSON.stringify({ eventName, properties }),
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
if (!response.ok) {
|
|
19
|
+
throw new Error(
|
|
20
|
+
`Analytics request failed: ${response.status} ${response.statusText}`
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const result = await response.json();
|
|
25
|
+
if (result.status === "success") {
|
|
26
|
+
} else {
|
|
27
|
+
}
|
|
28
|
+
} catch (error) {}
|
|
29
|
+
}
|
|
10
30
|
|
|
11
31
|
const CREATE_DB_WORKER_URL =
|
|
12
32
|
process.env.CREATE_DB_WORKER_URL || "https://create-db-temp.prisma.io";
|
|
@@ -264,14 +284,12 @@ async function promptForRegion(defaultRegion) {
|
|
|
264
284
|
}
|
|
265
285
|
|
|
266
286
|
try {
|
|
267
|
-
await
|
|
287
|
+
await sendAnalyticsToWorker("create_db:region_selected", {
|
|
268
288
|
command: CLI_NAME,
|
|
269
289
|
region: region,
|
|
270
290
|
"selection-method": "interactive",
|
|
271
291
|
});
|
|
272
|
-
} catch (error) {
|
|
273
|
-
console.error("Failed to send region_selected analytics :", error.message);
|
|
274
|
-
}
|
|
292
|
+
} catch (error) {}
|
|
275
293
|
|
|
276
294
|
return region;
|
|
277
295
|
}
|
|
@@ -286,7 +304,19 @@ async function createDatabase(name, region, returnJson = false) {
|
|
|
286
304
|
const resp = await fetch(`${CREATE_DB_WORKER_URL}/create`, {
|
|
287
305
|
method: "POST",
|
|
288
306
|
headers: { "Content-Type": "application/json" },
|
|
289
|
-
body: JSON.stringify({
|
|
307
|
+
body: JSON.stringify({
|
|
308
|
+
region,
|
|
309
|
+
name,
|
|
310
|
+
utm_source: CLI_NAME,
|
|
311
|
+
analytics: {
|
|
312
|
+
eventName: "create_db:database_created",
|
|
313
|
+
properties: {
|
|
314
|
+
command: CLI_NAME,
|
|
315
|
+
region: region,
|
|
316
|
+
utm_source: CLI_NAME,
|
|
317
|
+
},
|
|
318
|
+
},
|
|
319
|
+
}),
|
|
290
320
|
});
|
|
291
321
|
|
|
292
322
|
if (resp.status === 429) {
|
|
@@ -306,18 +336,13 @@ async function createDatabase(name, region, returnJson = false) {
|
|
|
306
336
|
}
|
|
307
337
|
|
|
308
338
|
try {
|
|
309
|
-
await
|
|
339
|
+
await sendAnalyticsToWorker("create_db:database_creation_failed", {
|
|
310
340
|
command: CLI_NAME,
|
|
311
341
|
region: region,
|
|
312
342
|
"error-type": "rate_limit",
|
|
313
343
|
"status-code": 429,
|
|
314
344
|
});
|
|
315
|
-
} catch (error) {
|
|
316
|
-
console.error(
|
|
317
|
-
"Failed to send database_creation_failed analytics:",
|
|
318
|
-
error.message
|
|
319
|
-
);
|
|
320
|
-
}
|
|
345
|
+
} catch (error) {}
|
|
321
346
|
|
|
322
347
|
process.exit(1);
|
|
323
348
|
}
|
|
@@ -340,18 +365,13 @@ async function createDatabase(name, region, returnJson = false) {
|
|
|
340
365
|
s.stop("Unexpected response from create service.");
|
|
341
366
|
}
|
|
342
367
|
try {
|
|
343
|
-
await
|
|
368
|
+
await sendAnalyticsToWorker("create_db:database_creation_failed", {
|
|
344
369
|
command: CLI_NAME,
|
|
345
370
|
region,
|
|
346
371
|
"error-type": "invalid_json",
|
|
347
372
|
"status-code": resp.status,
|
|
348
373
|
});
|
|
349
|
-
} catch (error) {
|
|
350
|
-
console.error(
|
|
351
|
-
"Failed to send database_creation_failed analytics:",
|
|
352
|
-
error.message
|
|
353
|
-
);
|
|
354
|
-
}
|
|
374
|
+
} catch (error) {}
|
|
355
375
|
process.exit(1);
|
|
356
376
|
}
|
|
357
377
|
|
|
@@ -409,18 +429,13 @@ async function createDatabase(name, region, returnJson = false) {
|
|
|
409
429
|
}
|
|
410
430
|
|
|
411
431
|
try {
|
|
412
|
-
await
|
|
432
|
+
await sendAnalyticsToWorker("create_db:database_creation_failed", {
|
|
413
433
|
command: CLI_NAME,
|
|
414
434
|
region: region,
|
|
415
435
|
"error-type": "api_error",
|
|
416
436
|
"error-message": result.error.message,
|
|
417
437
|
});
|
|
418
|
-
} catch (error) {
|
|
419
|
-
console.error(
|
|
420
|
-
"Failed to send database_creation_failed analytics:",
|
|
421
|
-
error.message
|
|
422
|
-
);
|
|
423
|
-
}
|
|
438
|
+
} catch (error) {}
|
|
424
439
|
process.exit(1);
|
|
425
440
|
}
|
|
426
441
|
|
|
@@ -477,7 +492,7 @@ async function main() {
|
|
|
477
492
|
try {
|
|
478
493
|
const rawArgs = process.argv.slice(2);
|
|
479
494
|
try {
|
|
480
|
-
await
|
|
495
|
+
await sendAnalyticsToWorker("create_db:cli_command_ran", {
|
|
481
496
|
command: CLI_NAME,
|
|
482
497
|
"full-command": `${CLI_NAME} ${rawArgs.join(" ")}`.trim(),
|
|
483
498
|
"has-region-flag":
|
|
@@ -491,9 +506,7 @@ async function main() {
|
|
|
491
506
|
platform: process.platform,
|
|
492
507
|
arch: process.arch,
|
|
493
508
|
});
|
|
494
|
-
} catch (error) {
|
|
495
|
-
console.error("Failed to send cli_command_ran analytics:", error.message);
|
|
496
|
-
}
|
|
509
|
+
} catch (error) {}
|
|
497
510
|
|
|
498
511
|
const { flags } = await parseArgs();
|
|
499
512
|
|
|
@@ -518,17 +531,12 @@ async function main() {
|
|
|
518
531
|
region = flags.region;
|
|
519
532
|
|
|
520
533
|
try {
|
|
521
|
-
await
|
|
534
|
+
await sendAnalyticsToWorker("create_db:region_selected", {
|
|
522
535
|
command: CLI_NAME,
|
|
523
536
|
region: region,
|
|
524
537
|
"selection-method": "flag",
|
|
525
538
|
});
|
|
526
|
-
} catch (error) {
|
|
527
|
-
console.error(
|
|
528
|
-
"Failed to send region_selected analytics:",
|
|
529
|
-
error.message
|
|
530
|
-
);
|
|
531
|
-
}
|
|
539
|
+
} catch (error) {}
|
|
532
540
|
}
|
|
533
541
|
|
|
534
542
|
if (flags.interactive) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-db",
|
|
3
|
-
"version": "1.0.3-pr48-DC-4894-posthog-fix-
|
|
3
|
+
"version": "1.0.3-pr48-DC-4894-posthog-fix-17269175017.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": "",
|
package/analytics.js
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
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 + "/capture";
|
|
12
|
-
const POSTHOG_KEY = process.env.POSTHOG_API_KEY;
|
|
13
|
-
console.log("POSTHOG_KEY set?", !!POSTHOG_KEY);
|
|
14
|
-
console.log("POSTHOG_CAPTURE_URL:", POSTHOG_CAPTURE_URL);
|
|
15
|
-
const payload = {
|
|
16
|
-
api_key: POSTHOG_KEY,
|
|
17
|
-
event: eventName,
|
|
18
|
-
distinct_id: randomUUID(),
|
|
19
|
-
properties: {
|
|
20
|
-
$process_person_profile: false,
|
|
21
|
-
...properties,
|
|
22
|
-
},
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
try {
|
|
26
|
-
const response = await fetch(POSTHOG_CAPTURE_URL, {
|
|
27
|
-
method: "POST",
|
|
28
|
-
headers: {
|
|
29
|
-
"Content-Type": "application/json",
|
|
30
|
-
},
|
|
31
|
-
body: JSON.stringify(payload),
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
if (!response.ok) {
|
|
35
|
-
throw new EventCaptureError(eventName, response.statusText);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// Log success message
|
|
39
|
-
console.log(`${eventName}: Success`);
|
|
40
|
-
} catch (error) {
|
|
41
|
-
// Log all analytics errors for debugging
|
|
42
|
-
console.error(`${eventName}: Failed - ${error.message}`);
|
|
43
|
-
|
|
44
|
-
// Re-throw the error so calling code can handle it if needed
|
|
45
|
-
throw error;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// Create a singleton instance
|
|
51
|
-
const analytics = new PosthogEventCapture();
|
|
52
|
-
|
|
53
|
-
export { analytics, EventCaptureError };
|