create-db 1.0.4-pr48-DC-4894-posthog-fix-17272348089.0 → 1.0.4-pr48-DC-4894-posthog-fix-17272959571.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/index.js +70 -76
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1,19 +1,23 @@
|
|
|
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
|
-
|
|
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
|
-
process.env.CREATE_DB_WORKER_URL
|
|
16
|
+
process.env.CREATE_DB_WORKER_URL.replace(/\/+$/, "") ||
|
|
17
|
+
"https://create-db-temp.prisma.io";
|
|
15
18
|
const CLAIM_DB_WORKER_URL =
|
|
16
|
-
process.env.CLAIM_DB_WORKER_URL
|
|
19
|
+
process.env.CLAIM_DB_WORKER_URL.replace(/\/+$/, "") ||
|
|
20
|
+
"https://create-db.prisma.io";
|
|
17
21
|
|
|
18
22
|
async function sendAnalyticsToWorker(
|
|
19
23
|
eventName,
|
|
@@ -23,10 +27,14 @@ async function sendAnalyticsToWorker(
|
|
|
23
27
|
const controller = new AbortController();
|
|
24
28
|
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
25
29
|
try {
|
|
30
|
+
const payload = {
|
|
31
|
+
eventName,
|
|
32
|
+
properties: { distinct_id: CLI_RUN_ID, ...(properties || {}) },
|
|
33
|
+
};
|
|
26
34
|
await fetch(`${CREATE_DB_WORKER_URL}/analytics`, {
|
|
27
35
|
method: "POST",
|
|
28
36
|
headers: { "Content-Type": "application/json" },
|
|
29
|
-
body: JSON.stringify(
|
|
37
|
+
body: JSON.stringify(payload),
|
|
30
38
|
signal: controller.signal,
|
|
31
39
|
});
|
|
32
40
|
} catch (error) {
|
|
@@ -377,14 +385,12 @@ async function promptForRegion(defaultRegion, userAgent) {
|
|
|
377
385
|
process.exit(0);
|
|
378
386
|
}
|
|
379
387
|
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
});
|
|
387
|
-
} catch (error) {}
|
|
388
|
+
await sendAnalyticsToWorker("create_db:region_selected", {
|
|
389
|
+
command: CLI_NAME,
|
|
390
|
+
region: region,
|
|
391
|
+
"selection-method": "interactive",
|
|
392
|
+
"user-agent": userAgent,
|
|
393
|
+
});
|
|
388
394
|
|
|
389
395
|
return region;
|
|
390
396
|
}
|
|
@@ -422,15 +428,13 @@ async function createDatabase(name, region, userAgent, returnJson = false) {
|
|
|
422
428
|
);
|
|
423
429
|
}
|
|
424
430
|
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
});
|
|
433
|
-
} catch (error) {}
|
|
431
|
+
await sendAnalyticsToWorker("create_db:database_creation_failed", {
|
|
432
|
+
command: CLI_NAME,
|
|
433
|
+
region: region,
|
|
434
|
+
"error-type": "rate_limit",
|
|
435
|
+
"status-code": 429,
|
|
436
|
+
"user-agent": userAgent,
|
|
437
|
+
});
|
|
434
438
|
|
|
435
439
|
process.exit(1);
|
|
436
440
|
}
|
|
@@ -452,15 +456,15 @@ async function createDatabase(name, region, userAgent, returnJson = false) {
|
|
|
452
456
|
if (s) {
|
|
453
457
|
s.stop("Unexpected response from create service.");
|
|
454
458
|
}
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
459
|
+
|
|
460
|
+
await sendAnalyticsToWorker("create_db:database_creation_failed", {
|
|
461
|
+
command: CLI_NAME,
|
|
462
|
+
region,
|
|
463
|
+
"error-type": "invalid_json",
|
|
464
|
+
"status-code": resp.status,
|
|
465
|
+
"user-agent": userAgent,
|
|
466
|
+
});
|
|
467
|
+
|
|
464
468
|
process.exit(1);
|
|
465
469
|
}
|
|
466
470
|
|
|
@@ -523,15 +527,14 @@ async function createDatabase(name, region, userAgent, returnJson = false) {
|
|
|
523
527
|
);
|
|
524
528
|
}
|
|
525
529
|
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
} catch (error) {}
|
|
530
|
+
await sendAnalyticsToWorker("create_db:database_creation_failed", {
|
|
531
|
+
command: CLI_NAME,
|
|
532
|
+
region: region,
|
|
533
|
+
"error-type": "api_error",
|
|
534
|
+
"error-message": result.error.message,
|
|
535
|
+
"user-agent": userAgent,
|
|
536
|
+
});
|
|
537
|
+
|
|
535
538
|
process.exit(1);
|
|
536
539
|
}
|
|
537
540
|
|
|
@@ -583,13 +586,11 @@ async function createDatabase(name, region, userAgent, returnJson = false) {
|
|
|
583
586
|
)
|
|
584
587
|
);
|
|
585
588
|
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
});
|
|
592
|
-
} catch {}
|
|
589
|
+
await sendAnalyticsToWorker("create_db:database_created", {
|
|
590
|
+
command: CLI_NAME,
|
|
591
|
+
region,
|
|
592
|
+
utm_source: CLI_NAME,
|
|
593
|
+
});
|
|
593
594
|
}
|
|
594
595
|
|
|
595
596
|
async function main() {
|
|
@@ -604,26 +605,21 @@ async function main() {
|
|
|
604
605
|
userAgent = `${userEnvVars.PRISMA_ACTOR_NAME}/${userEnvVars.PRISMA_ACTOR_PROJECT}`;
|
|
605
606
|
}
|
|
606
607
|
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
"user-agent": userAgent,
|
|
623
|
-
});
|
|
624
|
-
} catch (error) {
|
|
625
|
-
console.error("Error:", error.message);
|
|
626
|
-
}
|
|
608
|
+
await sendAnalyticsToWorker("create_db:cli_command_ran", {
|
|
609
|
+
command: CLI_NAME,
|
|
610
|
+
"full-command": `${CLI_NAME} ${rawArgs.join(" ")}`.trim(),
|
|
611
|
+
"has-region-flag": rawArgs.includes("--region") || rawArgs.includes("-r"),
|
|
612
|
+
"has-interactive-flag":
|
|
613
|
+
rawArgs.includes("--interactive") || rawArgs.includes("-i"),
|
|
614
|
+
"has-help-flag": rawArgs.includes("--help") || rawArgs.includes("-h"),
|
|
615
|
+
"has-list-regions-flag": rawArgs.includes("--list-regions"),
|
|
616
|
+
"has-json-flag": rawArgs.includes("--json") || rawArgs.includes("-j"),
|
|
617
|
+
"has-user-agent-from-env": !!userAgent,
|
|
618
|
+
"node-version": process.version,
|
|
619
|
+
platform: process.platform,
|
|
620
|
+
arch: process.arch,
|
|
621
|
+
"user-agent": userAgent,
|
|
622
|
+
});
|
|
627
623
|
|
|
628
624
|
if (!flags.help && !flags.json) {
|
|
629
625
|
await isOffline();
|
|
@@ -646,14 +642,12 @@ async function main() {
|
|
|
646
642
|
if (flags.region) {
|
|
647
643
|
region = flags.region;
|
|
648
644
|
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
});
|
|
656
|
-
} catch (error) {}
|
|
645
|
+
await sendAnalyticsToWorker("create_db:region_selected", {
|
|
646
|
+
command: CLI_NAME,
|
|
647
|
+
region: region,
|
|
648
|
+
"selection-method": "flag",
|
|
649
|
+
"user-agent": userAgent,
|
|
650
|
+
});
|
|
657
651
|
}
|
|
658
652
|
|
|
659
653
|
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-
|
|
3
|
+
"version": "1.0.4-pr48-DC-4894-posthog-fix-17272959571.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": "",
|