create-db 1.0.3-pr47-DC-4759-set-region-to-be-near-user-17250359916.0 → 1.0.3-pr48-DC-4894-posthog-fix-17267174922.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 (3) hide show
  1. package/analytics.js +10 -8
  2. package/index.js +31 -76
  3. package/package.json +1 -1
package/analytics.js CHANGED
@@ -8,10 +8,8 @@ class EventCaptureError extends Error {
8
8
 
9
9
  class PosthogEventCapture {
10
10
  async capture(eventName, properties = {}) {
11
- const POSTHOG_CAPTURE_URL = process.env.POSTHOG_API_HOST
12
- ? process.env.POSTHOG_API_HOST + "/capture"
13
- : "https://proxyhog.prisma-data.net/capture";
14
- const POSTHOG_KEY = process.env.POSTHOG_API_KEY || "phc_cmc85avbWyuJ2JyKdGPdv7dxXli8xLdWDBPbvIXWJfs";
11
+ const POSTHOG_CAPTURE_URL = process.env.POSTHOG_API_HOST + "/capture";
12
+ const POSTHOG_KEY = process.env.POSTHOG_API_KEY;
15
13
 
16
14
  const payload = {
17
15
  api_key: POSTHOG_KEY,
@@ -35,11 +33,15 @@ class PosthogEventCapture {
35
33
  if (!response.ok) {
36
34
  throw new EventCaptureError(eventName, response.statusText);
37
35
  }
36
+
37
+ // Log success message
38
+ console.log(`${eventName}: Success`);
38
39
  } catch (error) {
39
- // Silently fail analytics to not disrupt user experience
40
- if (process.env.NODE_ENV === "development") {
41
- console.error("Analytics error:", error.message);
42
- }
40
+ // Log all analytics errors for debugging
41
+ console.error(`${eventName}: Failed - ${error.message}`);
42
+
43
+ // Re-throw the error so calling code can handle it if needed
44
+ throw error;
43
45
  }
44
46
  }
45
47
  }
package/index.js CHANGED
@@ -13,74 +13,6 @@ const CREATE_DB_WORKER_URL =
13
13
  const CLAIM_DB_WORKER_URL =
14
14
  process.env.CLAIM_DB_WORKER_URL || "https://create-db.prisma.io";
15
15
 
16
- async function detectUserLocation() {
17
- try {
18
- const response = await fetch("https://ipapi.co/json/", {
19
- method: "GET",
20
- headers: {
21
- "User-Agent": "create-db-cli/1.0",
22
- },
23
- });
24
-
25
- if (!response.ok) {
26
- throw new Error(`Failed to fetch location data: ${response.status}`);
27
- }
28
-
29
- const data = await response.json();
30
- return {
31
- country: data.country_code,
32
- continent: data.continent_code,
33
- city: data.city,
34
- region: data.region,
35
- latitude: data.latitude,
36
- longitude: data.longitude,
37
- };
38
- } catch (error) {
39
- return null;
40
- }
41
- }
42
-
43
- // Region coordinates (latitude, longitude)
44
- const REGION_COORDINATES = {
45
- "ap-southeast-1": { lat: 1.3521, lng: 103.8198 }, // Singapore
46
- "ap-northeast-1": { lat: 35.6762, lng: 139.6503 }, // Tokyo
47
- "eu-central-1": { lat: 50.1109, lng: 8.6821 }, // Frankfurt
48
- "eu-west-3": { lat: 48.8566, lng: 2.3522 }, // Paris
49
- "us-east-1": { lat: 38.9072, lng: -77.0369 }, // N. Virginia
50
- "us-west-1": { lat: 37.7749, lng: -122.4194 }, // N. California
51
- };
52
-
53
- function getRegionClosestToLocation(userLocation) {
54
- if (!userLocation) return null;
55
-
56
- const userLat = parseFloat(userLocation.latitude);
57
- const userLng = parseFloat(userLocation.longitude);
58
-
59
- let closestRegion = null;
60
- let minDistance = Infinity;
61
-
62
- for (const [region, coordinates] of Object.entries(REGION_COORDINATES)) {
63
- // Simple distance calculation using Haversine formula
64
- const latDiff = ((userLat - coordinates.lat) * Math.PI) / 180;
65
- const lngDiff = ((userLng - coordinates.lng) * Math.PI) / 180;
66
- const a =
67
- Math.sin(latDiff / 2) * Math.sin(latDiff / 2) +
68
- Math.cos((userLat * Math.PI) / 180) *
69
- Math.cos((coordinates.lat * Math.PI) / 180) *
70
- Math.sin(lngDiff / 2) *
71
- Math.sin(lngDiff / 2);
72
- const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
73
- const distance = 6371 * c; // Earth radius in km
74
-
75
- if (distance < minDistance) {
76
- minDistance = distance;
77
- closestRegion = region;
78
- }
79
- }
80
-
81
- return closestRegion;
82
- }
83
-
84
16
  async function listRegions() {
85
17
  try {
86
18
  const regions = await getRegions();
@@ -337,7 +269,9 @@ async function promptForRegion(defaultRegion) {
337
269
  region: region,
338
270
  "selection-method": "interactive",
339
271
  });
340
- } catch (error) {}
272
+ } catch (error) {
273
+ console.error("Failed to send region_selected analytics:", error.message);
274
+ }
341
275
 
342
276
  return region;
343
277
  }
@@ -378,7 +312,12 @@ async function createDatabase(name, region, returnJson = false) {
378
312
  "error-type": "rate_limit",
379
313
  "status-code": 429,
380
314
  });
381
- } catch (error) {}
315
+ } catch (error) {
316
+ console.error(
317
+ "Failed to send database_creation_failed analytics:",
318
+ error.message
319
+ );
320
+ }
382
321
 
383
322
  process.exit(1);
384
323
  }
@@ -407,7 +346,12 @@ async function createDatabase(name, region, returnJson = false) {
407
346
  "error-type": "invalid_json",
408
347
  "status-code": resp.status,
409
348
  });
410
- } catch {}
349
+ } catch (error) {
350
+ console.error(
351
+ "Failed to send database_creation_failed analytics:",
352
+ error.message
353
+ );
354
+ }
411
355
  process.exit(1);
412
356
  }
413
357
 
@@ -471,7 +415,12 @@ async function createDatabase(name, region, returnJson = false) {
471
415
  "error-type": "api_error",
472
416
  "error-message": result.error.message,
473
417
  });
474
- } catch (error) {}
418
+ } catch (error) {
419
+ console.error(
420
+ "Failed to send database_creation_failed analytics:",
421
+ error.message
422
+ );
423
+ }
475
424
  process.exit(1);
476
425
  }
477
426
 
@@ -542,7 +491,9 @@ async function main() {
542
491
  platform: process.platform,
543
492
  arch: process.arch,
544
493
  });
545
- } catch (error) {}
494
+ } catch (error) {
495
+ console.error("Failed to send cli_command_ran analytics:", error.message);
496
+ }
546
497
 
547
498
  const { flags } = await parseArgs();
548
499
 
@@ -551,8 +502,7 @@ async function main() {
551
502
  }
552
503
 
553
504
  let name = new Date().toISOString();
554
- let userLocation = await detectUserLocation();
555
- let region = getRegionClosestToLocation(userLocation) || "us-east-1";
505
+ let region = "us-east-1";
556
506
  let chooseRegionPrompt = false;
557
507
 
558
508
  if (flags.help) {
@@ -573,7 +523,12 @@ async function main() {
573
523
  region: region,
574
524
  "selection-method": "flag",
575
525
  });
576
- } catch (error) {}
526
+ } catch (error) {
527
+ console.error(
528
+ "Failed to send region_selected analytics:",
529
+ error.message
530
+ );
531
+ }
577
532
  }
578
533
 
579
534
  if (flags.interactive) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-db",
3
- "version": "1.0.3-pr47-DC-4759-set-region-to-be-near-user-17250359916.0",
3
+ "version": "1.0.3-pr48-DC-4894-posthog-fix-17267174922.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": "",