create-db 0.0.13 → 0.0.15-pr27-feat-posthog-16473195330.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.
package/README.md CHANGED
@@ -2,8 +2,6 @@
2
2
 
3
3
  `create-db` is an open-source CLI tool that provisions [**temporary Prisma Postgres databases**](https://www.prisma.io/postgres?utm_source=create_db_npm_docs) with a single command.
4
4
 
5
- ![Demo Gif](demo.gif)
6
-
7
5
  Each database is available for **24 hours** by default. To keep the database permanently, you can **claim it for free** using the URL displayed in the CLI output.
8
6
 
9
7
  This tool is designed for developers who need a fast way to test, prototype, or integrate Prisma Postgres without manual setup or creating an account.
package/analytics.js ADDED
@@ -0,0 +1,50 @@
1
+ import { randomUUID } from "crypto";
2
+
3
+ class EventCaptureError extends Error {
4
+ constructor(event, status) {
5
+ super(`Failed to submit PostHog event '${event}': ${status}`);
6
+ }
7
+ }
8
+
9
+ class PosthogEventCapture {
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";
15
+
16
+ const payload = {
17
+ api_key: POSTHOG_KEY,
18
+ event: eventName,
19
+ distinct_id: randomUUID(),
20
+ properties: {
21
+ $process_person_profile: false,
22
+ ...properties,
23
+ },
24
+ };
25
+
26
+ try {
27
+ const response = await fetch(POSTHOG_CAPTURE_URL, {
28
+ method: "POST",
29
+ headers: {
30
+ "Content-Type": "application/json",
31
+ },
32
+ body: JSON.stringify(payload),
33
+ });
34
+
35
+ if (!response.ok) {
36
+ throw new EventCaptureError(eventName, response.statusText);
37
+ }
38
+ } 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
+ }
43
+ }
44
+ }
45
+ }
46
+
47
+ // Create a singleton instance
48
+ const analytics = new PosthogEventCapture();
49
+
50
+ export { analytics, EventCaptureError };
package/index.js CHANGED
@@ -1,5 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
 
3
+ import dotenv from "dotenv";
4
+ dotenv.config();
5
+
3
6
  import {
4
7
  select,
5
8
  spinner,
@@ -7,13 +10,10 @@ import {
7
10
  outro,
8
11
  log,
9
12
  cancel,
10
- confirm,
11
13
  } from "@clack/prompts";
12
14
  import chalk from "chalk";
13
- import dotenv from "dotenv";
14
15
  import terminalLink from "terminal-link";
15
-
16
- dotenv.config();
16
+ import { analytics } from "./analytics.js";
17
17
 
18
18
  const CREATE_DB_WORKER_URL =
19
19
  process.env.CREATE_DB_WORKER_URL || "https://create-db-temp.prisma.io";
@@ -265,6 +265,17 @@ async function promptForRegion(defaultRegion) {
265
265
  process.exit(0);
266
266
  }
267
267
 
268
+ // Track region selection event
269
+ try {
270
+ await analytics.capture("create_db:region_selected", {
271
+ command: CLI_NAME,
272
+ region: region,
273
+ "selection-method": "interactive"
274
+ });
275
+ } catch (error) {
276
+ // Silently fail analytics
277
+ }
278
+
268
279
  return region;
269
280
  }
270
281
 
@@ -284,6 +295,19 @@ async function createDatabase(name, region) {
284
295
  s.stop(
285
296
  "We're experiencing a high volume of requests. Please try again later."
286
297
  );
298
+
299
+ // Track database creation failure
300
+ try {
301
+ await analytics.capture("create_db:database_creation_failed", {
302
+ command: CLI_NAME,
303
+ region: region,
304
+ "error-type": "rate_limit",
305
+ "status-code": 429,
306
+ });
307
+ } catch (error) {
308
+ // Silently fail analytics
309
+ }
310
+
287
311
  process.exit(1);
288
312
  }
289
313
 
@@ -293,6 +317,18 @@ async function createDatabase(name, region) {
293
317
  s.stop(
294
318
  `Error creating database: ${result.error.message || "Unknown error"}`
295
319
  );
320
+
321
+ // Track database creation failure
322
+ try {
323
+ await analytics.capture("create_db:database_creation_failed", {
324
+ command: CLI_NAME,
325
+ region: region,
326
+ "error-type": "api_error",
327
+ "error-message": result.error.message,
328
+ });
329
+ } catch (error) {
330
+ // Silently fail analytics
331
+ }
296
332
  process.exit(1);
297
333
  }
298
334
 
@@ -362,6 +398,23 @@ async function createDatabase(name, region) {
362
398
 
363
399
  async function main() {
364
400
  try {
401
+ const rawArgs = process.argv.slice(2);
402
+ try {
403
+ await analytics.capture("create_db:cli_command_ran", {
404
+ command: CLI_NAME,
405
+ "full-command": `${CLI_NAME} ${rawArgs.join(' ')}`.trim(),
406
+ "has-region-flag": rawArgs.includes('--region') || rawArgs.includes('-r'),
407
+ "has-interactive-flag": rawArgs.includes('--interactive') || rawArgs.includes('-i'),
408
+ "has-help-flag": rawArgs.includes('--help') || rawArgs.includes('-h'),
409
+ "has-list-regions-flag": rawArgs.includes('--list-regions'),
410
+ "node-version": process.version,
411
+ platform: process.platform,
412
+ arch: process.arch
413
+ });
414
+ } catch (error) {
415
+ // Silently fail analytics
416
+ }
417
+
365
418
  // Parse command line arguments
366
419
  const { flags } = await parseArgs();
367
420
 
@@ -386,6 +439,17 @@ async function main() {
386
439
  // Apply command line flags
387
440
  if (flags.region) {
388
441
  region = flags.region;
442
+
443
+ // Track region selection via flag
444
+ try {
445
+ await analytics.capture("create_db:region_selected", {
446
+ command: CLI_NAME,
447
+ region: region,
448
+ "selection-method": "flag"
449
+ });
450
+ } catch (error) {
451
+ // Silently fail analytics
452
+ }
389
453
  }
390
454
  if (flags.interactive) {
391
455
  chooseRegionPrompt = true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-db",
3
- "version": "0.0.13",
3
+ "version": "0.0.15-pr27-feat-posthog-16473195330.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": "",
@@ -39,6 +39,6 @@
39
39
  "files": [
40
40
  "index.js",
41
41
  "README.md",
42
- "demo.gif"
42
+ "analytics.js"
43
43
  ]
44
44
  }
package/demo.gif DELETED
Binary file