create-db 1.0.4-pr48-DC-4894-posthog-fix-17272603770.0 → 1.0.4-pr48-DC-4894-posthog-fix-17273527623.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 +66 -74
  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(/\/+$/, "") ||
@@ -21,10 +23,14 @@ async function sendAnalyticsToWorker(eventName, properties) {
21
23
  const controller = new AbortController();
22
24
  const timer = setTimeout(() => controller.abort(), 2000);
23
25
  try {
26
+ const payload = {
27
+ eventName,
28
+ properties: { distinct_id: CLI_RUN_ID, ...(properties || {}) },
29
+ };
24
30
  await fetch(`${CREATE_DB_WORKER_URL}/analytics`, {
25
31
  method: "POST",
26
32
  headers: { "Content-Type": "application/json" },
27
- body: JSON.stringify({ eventName, properties }),
33
+ body: JSON.stringify(payload),
28
34
  signal: controller.signal,
29
35
  });
30
36
  } catch (error) {
@@ -375,14 +381,12 @@ async function promptForRegion(defaultRegion, userAgent) {
375
381
  process.exit(0);
376
382
  }
377
383
 
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) {}
384
+ void sendAnalyticsToWorker("create_db:region_selected", {
385
+ command: CLI_NAME,
386
+ region: region,
387
+ "selection-method": "interactive",
388
+ "user-agent": userAgent,
389
+ });
386
390
 
387
391
  return region;
388
392
  }
@@ -420,15 +424,13 @@ async function createDatabase(name, region, userAgent, returnJson = false) {
420
424
  );
421
425
  }
422
426
 
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) {}
427
+ void sendAnalyticsToWorker("create_db:database_creation_failed", {
428
+ command: CLI_NAME,
429
+ region: region,
430
+ "error-type": "rate_limit",
431
+ "status-code": 429,
432
+ "user-agent": userAgent,
433
+ });
432
434
 
433
435
  process.exit(1);
434
436
  }
@@ -450,15 +452,15 @@ async function createDatabase(name, region, userAgent, returnJson = false) {
450
452
  if (s) {
451
453
  s.stop("Unexpected response from create service.");
452
454
  }
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) {}
455
+
456
+ void sendAnalyticsToWorker("create_db:database_creation_failed", {
457
+ command: CLI_NAME,
458
+ region,
459
+ "error-type": "invalid_json",
460
+ "status-code": resp.status,
461
+ "user-agent": userAgent,
462
+ });
463
+
462
464
  process.exit(1);
463
465
  }
464
466
 
@@ -521,15 +523,14 @@ async function createDatabase(name, region, userAgent, returnJson = false) {
521
523
  );
522
524
  }
523
525
 
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) {}
526
+ void sendAnalyticsToWorker("create_db:database_creation_failed", {
527
+ command: CLI_NAME,
528
+ region: region,
529
+ "error-type": "api_error",
530
+ "error-message": result.error.message,
531
+ "user-agent": userAgent,
532
+ });
533
+
533
534
  process.exit(1);
534
535
  }
535
536
 
@@ -581,13 +582,11 @@ async function createDatabase(name, region, userAgent, returnJson = false) {
581
582
  )
582
583
  );
583
584
 
584
- try {
585
- await sendAnalyticsToWorker("create_db:database_created", {
586
- command: CLI_NAME,
587
- region,
588
- utm_source: CLI_NAME,
589
- });
590
- } catch {}
585
+ void sendAnalyticsToWorker("create_db:database_created", {
586
+ command: CLI_NAME,
587
+ region,
588
+ utm_source: CLI_NAME,
589
+ });
591
590
  }
592
591
 
593
592
  async function main() {
@@ -602,26 +601,21 @@ async function main() {
602
601
  userAgent = `${userEnvVars.PRISMA_ACTOR_NAME}/${userEnvVars.PRISMA_ACTOR_PROJECT}`;
603
602
  }
604
603
 
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
- }
604
+ void sendAnalyticsToWorker("create_db:cli_command_ran", {
605
+ command: CLI_NAME,
606
+ "full-command": `${CLI_NAME} ${rawArgs.join(" ")}`.trim(),
607
+ "has-region-flag": rawArgs.includes("--region") || rawArgs.includes("-r"),
608
+ "has-interactive-flag":
609
+ rawArgs.includes("--interactive") || rawArgs.includes("-i"),
610
+ "has-help-flag": rawArgs.includes("--help") || rawArgs.includes("-h"),
611
+ "has-list-regions-flag": rawArgs.includes("--list-regions"),
612
+ "has-json-flag": rawArgs.includes("--json") || rawArgs.includes("-j"),
613
+ "has-user-agent-from-env": !!userAgent,
614
+ "node-version": process.version,
615
+ platform: process.platform,
616
+ arch: process.arch,
617
+ "user-agent": userAgent,
618
+ });
625
619
 
626
620
  if (!flags.help && !flags.json) {
627
621
  await isOffline();
@@ -644,14 +638,12 @@ async function main() {
644
638
  if (flags.region) {
645
639
  region = flags.region;
646
640
 
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) {}
641
+ void sendAnalyticsToWorker("create_db:region_selected", {
642
+ command: CLI_NAME,
643
+ region: region,
644
+ "selection-method": "flag",
645
+ "user-agent": userAgent,
646
+ });
655
647
  }
656
648
 
657
649
  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-17273527623.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": "",