create-db 1.0.4-pr48-DC-4894-posthog-fix-17271643844.0 → 1.0.4-pr48-DC-4894-posthog-fix-17272603770.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 +23 -8
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -10,21 +10,29 @@ import { select, spinner, intro, outro, log, cancel } from "@clack/prompts";
10
10
  import chalk from "chalk";
11
11
  import terminalLink from "terminal-link";
12
12
 
13
- async function sendAnalyticsToWorker(eventName, properties = {}) {
13
+ const CREATE_DB_WORKER_URL =
14
+ process.env.CREATE_DB_WORKER_URL.replace(/\/+$/, "") ||
15
+ "https://create-db-temp.prisma.io";
16
+ const CLAIM_DB_WORKER_URL =
17
+ process.env.CLAIM_DB_WORKER_URL.replace(/\/+$/, "") ||
18
+ "https://create-db.prisma.io";
19
+
20
+ async function sendAnalyticsToWorker(eventName, properties) {
21
+ const controller = new AbortController();
22
+ const timer = setTimeout(() => controller.abort(), 2000);
14
23
  try {
15
24
  await fetch(`${CREATE_DB_WORKER_URL}/analytics`, {
16
25
  method: "POST",
17
26
  headers: { "Content-Type": "application/json" },
18
27
  body: JSON.stringify({ eventName, properties }),
28
+ signal: controller.signal,
19
29
  });
20
- } catch (error) {}
30
+ } catch (error) {
31
+ } finally {
32
+ clearTimeout(timer);
33
+ }
21
34
  }
22
35
 
23
- const CREATE_DB_WORKER_URL =
24
- process.env.CREATE_DB_WORKER_URL || "https://create-db-temp.prisma.io";
25
- const CLAIM_DB_WORKER_URL =
26
- process.env.CLAIM_DB_WORKER_URL || "https://create-db.prisma.io";
27
-
28
36
  async function detectUserLocation() {
29
37
  try {
30
38
  const response = await fetch("https://ipapi.co/json/", {
@@ -52,7 +60,6 @@ async function detectUserLocation() {
52
60
  }
53
61
  }
54
62
 
55
- // Region coordinates (latitude, longitude)
56
63
  const REGION_COORDINATES = {
57
64
  "ap-southeast-1": { lat: 1.3521, lng: 103.8198 }, // Singapore
58
65
  "ap-northeast-1": { lat: 35.6762, lng: 139.6503 }, // Tokyo
@@ -573,6 +580,14 @@ async function createDatabase(name, region, userAgent, returnJson = false) {
573
580
  )
574
581
  )
575
582
  );
583
+
584
+ try {
585
+ await sendAnalyticsToWorker("create_db:database_created", {
586
+ command: CLI_NAME,
587
+ region,
588
+ utm_source: CLI_NAME,
589
+ });
590
+ } catch {}
576
591
  }
577
592
 
578
593
  async function main() {
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-17271643844.0",
3
+ "version": "1.0.4-pr48-DC-4894-posthog-fix-17272603770.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": "",