create-db 1.0.4-pr48-DC-4894-posthog-fix-17272603770.0 → 1.0.4-pr48-DC-4894-posthog-fix-17272959571.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.
Files changed (2) hide show
  1. package/index.js +72 -76
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -1,14 +1,16 @@
1
1
  #!/usr/bin/env node
2
2
 
3
+ import { select, spinner, intro, outro, log, cancel } from "@clack/prompts";
4
+ import { randomUUID } from "crypto";
3
5
  import dotenv from "dotenv";
4
6
  import fs from "fs";
5
7
  import path from "path";
8
+ import terminalLink from "terminal-link";
9
+ import chalk from "chalk";
6
10
 
7
11
  dotenv.config();
8
12
 
9
- import { select, spinner, intro, outro, log, cancel } from "@clack/prompts";
10
- import chalk from "chalk";
11
- import terminalLink from "terminal-link";
13
+ const CLI_RUN_ID = randomUUID();
12
14
 
13
15
  const CREATE_DB_WORKER_URL =
14
16
  process.env.CREATE_DB_WORKER_URL.replace(/\/+$/, "") ||
@@ -17,14 +19,22 @@ const CLAIM_DB_WORKER_URL =
17
19
  process.env.CLAIM_DB_WORKER_URL.replace(/\/+$/, "") ||
18
20
  "https://create-db.prisma.io";
19
21
 
20
- async function sendAnalyticsToWorker(eventName, properties) {
22
+ async function sendAnalyticsToWorker(
23
+ eventName,
24
+ properties,
25
+ { timeoutMs = 2000 }
26
+ ) {
21
27
  const controller = new AbortController();
22
- const timer = setTimeout(() => controller.abort(), 2000);
28
+ const timer = setTimeout(() => controller.abort(), timeoutMs);
23
29
  try {
30
+ const payload = {
31
+ eventName,
32
+ properties: { distinct_id: CLI_RUN_ID, ...(properties || {}) },
33
+ };
24
34
  await fetch(`${CREATE_DB_WORKER_URL}/analytics`, {
25
35
  method: "POST",
26
36
  headers: { "Content-Type": "application/json" },
27
- body: JSON.stringify({ eventName, properties }),
37
+ body: JSON.stringify(payload),
28
38
  signal: controller.signal,
29
39
  });
30
40
  } catch (error) {
@@ -375,14 +385,12 @@ async function promptForRegion(defaultRegion, userAgent) {
375
385
  process.exit(0);
376
386
  }
377
387
 
378
- try {
379
- await sendAnalyticsToWorker("create_db:region_selected", {
380
- command: CLI_NAME,
381
- region: region,
382
- "selection-method": "interactive",
383
- "user-agent": userAgent,
384
- });
385
- } catch (error) {}
388
+ await sendAnalyticsToWorker("create_db:region_selected", {
389
+ command: CLI_NAME,
390
+ region: region,
391
+ "selection-method": "interactive",
392
+ "user-agent": userAgent,
393
+ });
386
394
 
387
395
  return region;
388
396
  }
@@ -420,15 +428,13 @@ async function createDatabase(name, region, userAgent, returnJson = false) {
420
428
  );
421
429
  }
422
430
 
423
- try {
424
- await sendAnalyticsToWorker("create_db:database_creation_failed", {
425
- command: CLI_NAME,
426
- region: region,
427
- "error-type": "rate_limit",
428
- "status-code": 429,
429
- "user-agent": userAgent,
430
- });
431
- } catch (error) {}
431
+ await sendAnalyticsToWorker("create_db:database_creation_failed", {
432
+ command: CLI_NAME,
433
+ region: region,
434
+ "error-type": "rate_limit",
435
+ "status-code": 429,
436
+ "user-agent": userAgent,
437
+ });
432
438
 
433
439
  process.exit(1);
434
440
  }
@@ -450,15 +456,15 @@ async function createDatabase(name, region, userAgent, returnJson = false) {
450
456
  if (s) {
451
457
  s.stop("Unexpected response from create service.");
452
458
  }
453
- try {
454
- await sendAnalyticsToWorker("create_db:database_creation_failed", {
455
- command: CLI_NAME,
456
- region,
457
- "error-type": "invalid_json",
458
- "status-code": resp.status,
459
- "user-agent": userAgent,
460
- });
461
- } catch (error) {}
459
+
460
+ await sendAnalyticsToWorker("create_db:database_creation_failed", {
461
+ command: CLI_NAME,
462
+ region,
463
+ "error-type": "invalid_json",
464
+ "status-code": resp.status,
465
+ "user-agent": userAgent,
466
+ });
467
+
462
468
  process.exit(1);
463
469
  }
464
470
 
@@ -521,15 +527,14 @@ async function createDatabase(name, region, userAgent, returnJson = false) {
521
527
  );
522
528
  }
523
529
 
524
- try {
525
- await sendAnalyticsToWorker("create_db:database_creation_failed", {
526
- command: CLI_NAME,
527
- region: region,
528
- "error-type": "api_error",
529
- "error-message": result.error.message,
530
- "user-agent": userAgent,
531
- });
532
- } catch (error) {}
530
+ await sendAnalyticsToWorker("create_db:database_creation_failed", {
531
+ command: CLI_NAME,
532
+ region: region,
533
+ "error-type": "api_error",
534
+ "error-message": result.error.message,
535
+ "user-agent": userAgent,
536
+ });
537
+
533
538
  process.exit(1);
534
539
  }
535
540
 
@@ -581,13 +586,11 @@ async function createDatabase(name, region, userAgent, returnJson = false) {
581
586
  )
582
587
  );
583
588
 
584
- try {
585
- await sendAnalyticsToWorker("create_db:database_created", {
586
- command: CLI_NAME,
587
- region,
588
- utm_source: CLI_NAME,
589
- });
590
- } catch {}
589
+ await sendAnalyticsToWorker("create_db:database_created", {
590
+ command: CLI_NAME,
591
+ region,
592
+ utm_source: CLI_NAME,
593
+ });
591
594
  }
592
595
 
593
596
  async function main() {
@@ -602,26 +605,21 @@ async function main() {
602
605
  userAgent = `${userEnvVars.PRISMA_ACTOR_NAME}/${userEnvVars.PRISMA_ACTOR_PROJECT}`;
603
606
  }
604
607
 
605
- try {
606
- await sendAnalyticsToWorker("create_db:cli_command_ran", {
607
- command: CLI_NAME,
608
- "full-command": `${CLI_NAME} ${rawArgs.join(" ")}`.trim(),
609
- "has-region-flag":
610
- rawArgs.includes("--region") || rawArgs.includes("-r"),
611
- "has-interactive-flag":
612
- rawArgs.includes("--interactive") || rawArgs.includes("-i"),
613
- "has-help-flag": rawArgs.includes("--help") || rawArgs.includes("-h"),
614
- "has-list-regions-flag": rawArgs.includes("--list-regions"),
615
- "has-json-flag": rawArgs.includes("--json") || rawArgs.includes("-j"),
616
- "has-user-agent-from-env": !!userAgent,
617
- "node-version": process.version,
618
- platform: process.platform,
619
- arch: process.arch,
620
- "user-agent": userAgent,
621
- });
622
- } catch (error) {
623
- console.error("Error:", error.message);
624
- }
608
+ await sendAnalyticsToWorker("create_db:cli_command_ran", {
609
+ command: CLI_NAME,
610
+ "full-command": `${CLI_NAME} ${rawArgs.join(" ")}`.trim(),
611
+ "has-region-flag": rawArgs.includes("--region") || rawArgs.includes("-r"),
612
+ "has-interactive-flag":
613
+ rawArgs.includes("--interactive") || rawArgs.includes("-i"),
614
+ "has-help-flag": rawArgs.includes("--help") || rawArgs.includes("-h"),
615
+ "has-list-regions-flag": rawArgs.includes("--list-regions"),
616
+ "has-json-flag": rawArgs.includes("--json") || rawArgs.includes("-j"),
617
+ "has-user-agent-from-env": !!userAgent,
618
+ "node-version": process.version,
619
+ platform: process.platform,
620
+ arch: process.arch,
621
+ "user-agent": userAgent,
622
+ });
625
623
 
626
624
  if (!flags.help && !flags.json) {
627
625
  await isOffline();
@@ -644,14 +642,12 @@ async function main() {
644
642
  if (flags.region) {
645
643
  region = flags.region;
646
644
 
647
- try {
648
- await sendAnalyticsToWorker("create_db:region_selected", {
649
- command: CLI_NAME,
650
- region: region,
651
- "selection-method": "flag",
652
- "user-agent": userAgent,
653
- });
654
- } catch (error) {}
645
+ await sendAnalyticsToWorker("create_db:region_selected", {
646
+ command: CLI_NAME,
647
+ region: region,
648
+ "selection-method": "flag",
649
+ "user-agent": userAgent,
650
+ });
655
651
  }
656
652
 
657
653
  if (flags.interactive) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-db",
3
- "version": "1.0.4-pr48-DC-4894-posthog-fix-17272603770.0",
3
+ "version": "1.0.4-pr48-DC-4894-posthog-fix-17272959571.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": "",