create-db 1.0.3-pr45-DC-4829-source-flag-17164819065.0 → 1.0.4-pr45-DC-4829-source-flag-17239115059.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 +8 -2
  2. package/index.js +9 -23
  3. package/package.json +1 -1
package/analytics.js CHANGED
@@ -10,7 +10,13 @@ class PosthogEventCapture {
10
10
  async capture(eventName, properties = {}) {
11
11
  const POSTHOG_API_HOST = process.env.POSTHOG_API_HOST;
12
12
  const POSTHOG_KEY = process.env.POSTHOG_API_KEY;
13
- if (!POSTHOG_API_HOST || !POSTHOG_KEY) {
13
+
14
+ if (
15
+ !POSTHOG_API_HOST ||
16
+ !POSTHOG_KEY ||
17
+ POSTHOG_API_HOST.trim() === "" ||
18
+ POSTHOG_KEY.trim() === ""
19
+ ) {
14
20
  if (process.env.NODE_ENV === "development") {
15
21
  console.warn(
16
22
  "Analytics disabled: missing POSTHOG_API_HOST or POSTHOG_API_KEY."
@@ -18,6 +24,7 @@ class PosthogEventCapture {
18
24
  }
19
25
  return;
20
26
  }
27
+
21
28
  const POSTHOG_CAPTURE_URL = `${POSTHOG_API_HOST.replace(/\/+$/, "")}/capture`;
22
29
 
23
30
  const payload = {
@@ -43,7 +50,6 @@ class PosthogEventCapture {
43
50
  throw new EventCaptureError(eventName, response.statusText);
44
51
  }
45
52
  } catch (error) {
46
- // Silently fail analytics to not disrupt user experience
47
53
  if (process.env.NODE_ENV === "development") {
48
54
  console.error("Analytics error:", error.message);
49
55
  }
package/index.js CHANGED
@@ -3,6 +3,7 @@
3
3
  import dotenv from "dotenv";
4
4
  import fs from "fs";
5
5
  import path from "path";
6
+
6
7
  dotenv.config();
7
8
 
8
9
  import { select, spinner, intro, outro, log, cancel } from "@clack/prompts";
@@ -295,12 +296,9 @@ async function promptForRegion(defaultRegion, userAgent) {
295
296
  command: CLI_NAME,
296
297
  region: region,
297
298
  "selection-method": "interactive",
299
+ "user-agent": userAgent,
298
300
  };
299
301
 
300
- if (userAgent) {
301
- analyticsProps["user-agent"] = userAgent;
302
- }
303
-
304
302
  await analytics.capture("create_db:region_selected", analyticsProps);
305
303
  } catch (error) {}
306
304
 
@@ -342,12 +340,9 @@ async function createDatabase(name, region, userAgent, returnJson = false) {
342
340
  region: region,
343
341
  "error-type": "rate_limit",
344
342
  "status-code": 429,
343
+ "user-agent": userAgent,
345
344
  };
346
345
 
347
- if (userAgent) {
348
- analyticsProps["user-agent"] = userAgent;
349
- }
350
-
351
346
  await analytics.capture(
352
347
  "create_db:database_creation_failed",
353
348
  analyticsProps
@@ -380,17 +375,14 @@ async function createDatabase(name, region, userAgent, returnJson = false) {
380
375
  region,
381
376
  "error-type": "invalid_json",
382
377
  "status-code": resp.status,
378
+ "user-agent": userAgent,
383
379
  };
384
380
 
385
- if (userAgent) {
386
- analyticsProps["user-agent"] = userAgent;
387
- }
388
-
389
381
  await analytics.capture(
390
382
  "create_db:database_creation_failed",
391
383
  analyticsProps
392
384
  );
393
- } catch {}
385
+ } catch (error) {}
394
386
  process.exit(1);
395
387
  }
396
388
 
@@ -432,7 +424,7 @@ async function createDatabase(name, region, userAgent, returnJson = false) {
432
424
  };
433
425
 
434
426
  if (userAgent) {
435
- jsonResponse.source = userAgent;
427
+ jsonResponse.userAgent = userAgent;
436
428
  }
437
429
 
438
430
  return jsonResponse;
@@ -459,12 +451,9 @@ async function createDatabase(name, region, userAgent, returnJson = false) {
459
451
  region: region,
460
452
  "error-type": "api_error",
461
453
  "error-message": result.error.message,
454
+ "user-agent": userAgent,
462
455
  };
463
456
 
464
- if (userAgent) {
465
- analyticsProps["user-agent"] = userAgent;
466
- }
467
-
468
457
  await analytics.capture(
469
458
  "create_db:database_creation_failed",
470
459
  analyticsProps
@@ -545,16 +534,13 @@ async function main() {
545
534
  "has-help-flag": rawArgs.includes("--help") || rawArgs.includes("-h"),
546
535
  "has-list-regions-flag": rawArgs.includes("--list-regions"),
547
536
  "has-json-flag": rawArgs.includes("--json") || rawArgs.includes("-j"),
548
- "has-source-from-env": !!userAgent,
537
+ "has-user-agent-from-env": !!userAgent,
549
538
  "node-version": process.version,
550
539
  platform: process.platform,
551
540
  arch: process.arch,
541
+ "user-agent": userAgent,
552
542
  };
553
543
 
554
- if (userAgent) {
555
- analyticsProps["user-agent"] = userAgent;
556
- }
557
-
558
544
  await analytics.capture("create_db:cli_command_ran", analyticsProps);
559
545
  } catch (error) {
560
546
  console.error("Error:", error.message);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-db",
3
- "version": "1.0.3-pr45-DC-4829-source-flag-17164819065.0",
3
+ "version": "1.0.4-pr45-DC-4829-source-flag-17239115059.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": "",