create-db 1.0.3-pr45-DC-4829-source-flag-17164722487.0 → 1.0.3-pr46-feat-add-sslmode-17243005030.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/analytics.js +4 -2
- package/index.js +24 -112
- package/package.json +1 -1
package/analytics.js
CHANGED
|
@@ -8,8 +8,10 @@ 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
|
-
|
|
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";
|
|
13
15
|
|
|
14
16
|
const payload = {
|
|
15
17
|
api_key: POSTHOG_KEY,
|
package/index.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
import dotenv from "dotenv";
|
|
4
|
-
import fs from "fs";
|
|
5
|
-
import path from "path";
|
|
6
4
|
dotenv.config();
|
|
7
5
|
|
|
8
6
|
import { select, spinner, intro, outro, log, cancel } from "@clack/prompts";
|
|
@@ -59,31 +57,6 @@ function getCommandName() {
|
|
|
59
57
|
|
|
60
58
|
const CLI_NAME = getCommandName();
|
|
61
59
|
|
|
62
|
-
function readUserEnvFile() {
|
|
63
|
-
const userCwd = process.cwd();
|
|
64
|
-
const envPath = path.join(userCwd, ".env");
|
|
65
|
-
|
|
66
|
-
if (!fs.existsSync(envPath)) {
|
|
67
|
-
return {};
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const envContent = fs.readFileSync(envPath, "utf8");
|
|
71
|
-
const envVars = {};
|
|
72
|
-
|
|
73
|
-
envContent.split("\n").forEach((line) => {
|
|
74
|
-
const trimmed = line.trim();
|
|
75
|
-
if (trimmed && !trimmed.startsWith("#")) {
|
|
76
|
-
const [key, ...valueParts] = trimmed.split("=");
|
|
77
|
-
if (key && valueParts.length > 0) {
|
|
78
|
-
const value = valueParts.join("=").replace(/^["']|["']$/g, "");
|
|
79
|
-
envVars[key.trim()] = value.trim();
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
return envVars;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
60
|
async function showHelp() {
|
|
88
61
|
let regionExamples = "us-east-1, eu-west-1";
|
|
89
62
|
try {
|
|
@@ -266,7 +239,7 @@ function handleError(message, extra = "") {
|
|
|
266
239
|
process.exit(1);
|
|
267
240
|
}
|
|
268
241
|
|
|
269
|
-
async function promptForRegion(defaultRegion
|
|
242
|
+
async function promptForRegion(defaultRegion) {
|
|
270
243
|
let regions;
|
|
271
244
|
try {
|
|
272
245
|
regions = await getRegions();
|
|
@@ -291,23 +264,17 @@ async function promptForRegion(defaultRegion, userAgent) {
|
|
|
291
264
|
}
|
|
292
265
|
|
|
293
266
|
try {
|
|
294
|
-
|
|
267
|
+
await analytics.capture("create_db:region_selected", {
|
|
295
268
|
command: CLI_NAME,
|
|
296
269
|
region: region,
|
|
297
270
|
"selection-method": "interactive",
|
|
298
|
-
};
|
|
299
|
-
|
|
300
|
-
if (userAgent) {
|
|
301
|
-
analyticsProps["user-agent"] = userAgent;
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
await analytics.capture("create_db:region_selected", analyticsProps);
|
|
271
|
+
});
|
|
305
272
|
} catch (error) {}
|
|
306
273
|
|
|
307
274
|
return region;
|
|
308
275
|
}
|
|
309
276
|
|
|
310
|
-
async function createDatabase(name, region,
|
|
277
|
+
async function createDatabase(name, region, returnJson = false) {
|
|
311
278
|
let s;
|
|
312
279
|
if (!returnJson) {
|
|
313
280
|
s = spinner();
|
|
@@ -317,7 +284,7 @@ async function createDatabase(name, region, userAgent, returnJson = false) {
|
|
|
317
284
|
const resp = await fetch(`${CREATE_DB_WORKER_URL}/create`, {
|
|
318
285
|
method: "POST",
|
|
319
286
|
headers: { "Content-Type": "application/json" },
|
|
320
|
-
body: JSON.stringify({ region, name, utm_source:
|
|
287
|
+
body: JSON.stringify({ region, name, utm_source: CLI_NAME }),
|
|
321
288
|
});
|
|
322
289
|
|
|
323
290
|
if (resp.status === 429) {
|
|
@@ -337,21 +304,12 @@ async function createDatabase(name, region, userAgent, returnJson = false) {
|
|
|
337
304
|
}
|
|
338
305
|
|
|
339
306
|
try {
|
|
340
|
-
|
|
307
|
+
await analytics.capture("create_db:database_creation_failed", {
|
|
341
308
|
command: CLI_NAME,
|
|
342
309
|
region: region,
|
|
343
310
|
"error-type": "rate_limit",
|
|
344
311
|
"status-code": 429,
|
|
345
|
-
};
|
|
346
|
-
|
|
347
|
-
if (userAgent) {
|
|
348
|
-
analyticsProps["user-agent"] = userAgent;
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
await analytics.capture(
|
|
352
|
-
"create_db:database_creation_failed",
|
|
353
|
-
analyticsProps
|
|
354
|
-
);
|
|
312
|
+
});
|
|
355
313
|
} catch (error) {}
|
|
356
314
|
|
|
357
315
|
process.exit(1);
|
|
@@ -375,21 +333,12 @@ async function createDatabase(name, region, userAgent, returnJson = false) {
|
|
|
375
333
|
s.stop("Unexpected response from create service.");
|
|
376
334
|
}
|
|
377
335
|
try {
|
|
378
|
-
|
|
336
|
+
await analytics.capture("create_db:database_creation_failed", {
|
|
379
337
|
command: CLI_NAME,
|
|
380
338
|
region,
|
|
381
339
|
"error-type": "invalid_json",
|
|
382
340
|
"status-code": resp.status,
|
|
383
|
-
};
|
|
384
|
-
|
|
385
|
-
if (userAgent) {
|
|
386
|
-
analyticsProps["user-agent"] = userAgent;
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
await analytics.capture(
|
|
390
|
-
"create_db:database_creation_failed",
|
|
391
|
-
analyticsProps
|
|
392
|
-
);
|
|
341
|
+
});
|
|
393
342
|
} catch {}
|
|
394
343
|
process.exit(1);
|
|
395
344
|
}
|
|
@@ -414,14 +363,14 @@ async function createDatabase(name, region, userAgent, returnJson = false) {
|
|
|
414
363
|
const directDbName = directConnDetails?.database || "postgres";
|
|
415
364
|
const directConn =
|
|
416
365
|
directConnDetails && directHost
|
|
417
|
-
? `postgresql://${directUser}:${directPass}@${directHost}${directPort}/${directDbName}`
|
|
366
|
+
? `postgresql://${directUser}:${directPass}@${directHost}${directPort}/${directDbName}?sslmode=require`
|
|
418
367
|
: null;
|
|
419
368
|
|
|
420
|
-
const claimUrl = `${CLAIM_DB_WORKER_URL}?projectID=${projectId}&utm_source=${
|
|
369
|
+
const claimUrl = `${CLAIM_DB_WORKER_URL}?projectID=${projectId}&utm_source=${CLI_NAME}&utm_medium=cli`;
|
|
421
370
|
const expiryDate = new Date(Date.now() + 24 * 60 * 60 * 1000);
|
|
422
371
|
|
|
423
372
|
if (returnJson && !result.error) {
|
|
424
|
-
|
|
373
|
+
return {
|
|
425
374
|
connectionString: prismaConn,
|
|
426
375
|
directConnectionString: directConn,
|
|
427
376
|
claimUrl: claimUrl,
|
|
@@ -430,12 +379,6 @@ async function createDatabase(name, region, userAgent, returnJson = false) {
|
|
|
430
379
|
name: database?.name,
|
|
431
380
|
projectId: projectId,
|
|
432
381
|
};
|
|
433
|
-
|
|
434
|
-
if (userAgent) {
|
|
435
|
-
jsonResponse.source = userAgent;
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
return jsonResponse;
|
|
439
382
|
}
|
|
440
383
|
|
|
441
384
|
if (result.error) {
|
|
@@ -454,21 +397,12 @@ async function createDatabase(name, region, userAgent, returnJson = false) {
|
|
|
454
397
|
}
|
|
455
398
|
|
|
456
399
|
try {
|
|
457
|
-
|
|
400
|
+
await analytics.capture("create_db:database_creation_failed", {
|
|
458
401
|
command: CLI_NAME,
|
|
459
402
|
region: region,
|
|
460
403
|
"error-type": "api_error",
|
|
461
404
|
"error-message": result.error.message,
|
|
462
|
-
};
|
|
463
|
-
|
|
464
|
-
if (userAgent) {
|
|
465
|
-
analyticsProps["user-agent"] = userAgent;
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
await analytics.capture(
|
|
469
|
-
"create_db:database_creation_failed",
|
|
470
|
-
analyticsProps
|
|
471
|
-
);
|
|
405
|
+
});
|
|
472
406
|
} catch (error) {}
|
|
473
407
|
process.exit(1);
|
|
474
408
|
}
|
|
@@ -525,17 +459,8 @@ async function createDatabase(name, region, userAgent, returnJson = false) {
|
|
|
525
459
|
async function main() {
|
|
526
460
|
try {
|
|
527
461
|
const rawArgs = process.argv.slice(2);
|
|
528
|
-
|
|
529
|
-
const { flags } = await parseArgs();
|
|
530
|
-
|
|
531
|
-
let userAgent;
|
|
532
|
-
const userEnvVars = readUserEnvFile();
|
|
533
|
-
if (userEnvVars.PRISMA_ACTOR_NAME && userEnvVars.PRISMA_ACTOR_PROJECT) {
|
|
534
|
-
userAgent = `${userEnvVars.PRISMA_ACTOR_NAME}/${userEnvVars.PRISMA_ACTOR_PROJECT}`;
|
|
535
|
-
}
|
|
536
|
-
|
|
537
462
|
try {
|
|
538
|
-
|
|
463
|
+
await analytics.capture("create_db:cli_command_ran", {
|
|
539
464
|
command: CLI_NAME,
|
|
540
465
|
"full-command": `${CLI_NAME} ${rawArgs.join(" ")}`.trim(),
|
|
541
466
|
"has-region-flag":
|
|
@@ -545,20 +470,13 @@ async function main() {
|
|
|
545
470
|
"has-help-flag": rawArgs.includes("--help") || rawArgs.includes("-h"),
|
|
546
471
|
"has-list-regions-flag": rawArgs.includes("--list-regions"),
|
|
547
472
|
"has-json-flag": rawArgs.includes("--json") || rawArgs.includes("-j"),
|
|
548
|
-
"has-source-from-env": !!userAgent,
|
|
549
473
|
"node-version": process.version,
|
|
550
474
|
platform: process.platform,
|
|
551
475
|
arch: process.arch,
|
|
552
|
-
};
|
|
553
|
-
|
|
554
|
-
if (userAgent) {
|
|
555
|
-
analyticsProps["user-agent"] = userAgent;
|
|
556
|
-
}
|
|
476
|
+
});
|
|
477
|
+
} catch (error) {}
|
|
557
478
|
|
|
558
|
-
|
|
559
|
-
} catch (error) {
|
|
560
|
-
console.error("Error:", error.message);
|
|
561
|
-
}
|
|
479
|
+
const { flags } = await parseArgs();
|
|
562
480
|
|
|
563
481
|
if (!flags.help && !flags.json) {
|
|
564
482
|
await isOffline();
|
|
@@ -581,17 +499,11 @@ async function main() {
|
|
|
581
499
|
region = flags.region;
|
|
582
500
|
|
|
583
501
|
try {
|
|
584
|
-
|
|
502
|
+
await analytics.capture("create_db:region_selected", {
|
|
585
503
|
command: CLI_NAME,
|
|
586
504
|
region: region,
|
|
587
505
|
"selection-method": "flag",
|
|
588
|
-
};
|
|
589
|
-
|
|
590
|
-
if (userAgent) {
|
|
591
|
-
analyticsProps["user-agent"] = userAgent;
|
|
592
|
-
}
|
|
593
|
-
|
|
594
|
-
await analytics.capture("create_db:region_selected", analyticsProps);
|
|
506
|
+
});
|
|
595
507
|
} catch (error) {}
|
|
596
508
|
}
|
|
597
509
|
|
|
@@ -602,11 +514,11 @@ async function main() {
|
|
|
602
514
|
if (flags.json) {
|
|
603
515
|
try {
|
|
604
516
|
if (chooseRegionPrompt) {
|
|
605
|
-
region = await promptForRegion(region
|
|
517
|
+
region = await promptForRegion(region);
|
|
606
518
|
} else {
|
|
607
519
|
await validateRegion(region, true);
|
|
608
520
|
}
|
|
609
|
-
const result = await createDatabase(name, region,
|
|
521
|
+
const result = await createDatabase(name, region, true);
|
|
610
522
|
console.log(JSON.stringify(result, null, 2));
|
|
611
523
|
process.exit(0);
|
|
612
524
|
} catch (e) {
|
|
@@ -631,12 +543,12 @@ async function main() {
|
|
|
631
543
|
)
|
|
632
544
|
);
|
|
633
545
|
if (chooseRegionPrompt) {
|
|
634
|
-
region = await promptForRegion(region
|
|
546
|
+
region = await promptForRegion(region);
|
|
635
547
|
}
|
|
636
548
|
|
|
637
549
|
region = await validateRegion(region);
|
|
638
550
|
|
|
639
|
-
await createDatabase(name, region
|
|
551
|
+
await createDatabase(name, region);
|
|
640
552
|
|
|
641
553
|
outro("");
|
|
642
554
|
} catch (error) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-db",
|
|
3
|
-
"version": "1.0.3-
|
|
3
|
+
"version": "1.0.3-pr46-feat-add-sslmode-17243005030.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": "",
|