connectbase-client 0.10.4 → 0.10.5
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/dist/cli.js +103 -14
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -350,6 +350,84 @@ function getProjectRoot() {
|
|
|
350
350
|
const gitRoot = getGitRoot();
|
|
351
351
|
return gitRoot || process.cwd();
|
|
352
352
|
}
|
|
353
|
+
var CONSOLE_URL = DEFAULT_BASE_URL.replace("api.", "");
|
|
354
|
+
function openBrowser(url) {
|
|
355
|
+
const { exec } = require("child_process");
|
|
356
|
+
const platform = process.platform;
|
|
357
|
+
let command;
|
|
358
|
+
if (platform === "darwin") {
|
|
359
|
+
command = `open "${url}"`;
|
|
360
|
+
} else if (platform === "win32") {
|
|
361
|
+
command = `start "" "${url}"`;
|
|
362
|
+
} else {
|
|
363
|
+
command = `xdg-open "${url}"`;
|
|
364
|
+
}
|
|
365
|
+
exec(command, () => {
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
async function browserAuthFlow() {
|
|
369
|
+
info("\uBE0C\uB77C\uC6B0\uC800 \uC778\uC99D \uC138\uC158\uC744 \uC2DC\uC791\uD569\uB2C8\uB2E4...");
|
|
370
|
+
const startRes = await makeRequest(
|
|
371
|
+
`${DEFAULT_BASE_URL}/v1/public/cli-auth/start`,
|
|
372
|
+
"POST",
|
|
373
|
+
{}
|
|
374
|
+
);
|
|
375
|
+
if (startRes.status !== 200) {
|
|
376
|
+
error("\uC778\uC99D \uC138\uC158 \uC2DC\uC791\uC5D0 \uC2E4\uD328\uD588\uC2B5\uB2C8\uB2E4");
|
|
377
|
+
process.exit(1);
|
|
378
|
+
}
|
|
379
|
+
const { session_id } = startRes.data;
|
|
380
|
+
const authUrl = `${CONSOLE_URL}/auth/cli-auth?session=${session_id}`;
|
|
381
|
+
log(`
|
|
382
|
+
${colors.cyan}\uBE0C\uB77C\uC6B0\uC800\uC5D0\uC11C \uB85C\uADF8\uC778\uD558\uC138\uC694:${colors.reset}`);
|
|
383
|
+
log(`${colors.dim}${authUrl}${colors.reset}
|
|
384
|
+
`);
|
|
385
|
+
openBrowser(authUrl);
|
|
386
|
+
const pollInterval = 2e3;
|
|
387
|
+
const maxAttempts = 150;
|
|
388
|
+
let attempts = 0;
|
|
389
|
+
const spinnerFrames = ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
|
|
390
|
+
while (attempts < maxAttempts) {
|
|
391
|
+
const frame = spinnerFrames[attempts % spinnerFrames.length];
|
|
392
|
+
process.stdout.write(`\r${colors.blue}${frame}${colors.reset} \uBE0C\uB77C\uC6B0\uC800\uC5D0\uC11C \uC2B9\uC778 \uB300\uAE30 \uC911...`);
|
|
393
|
+
await new Promise((resolve2) => setTimeout(resolve2, pollInterval));
|
|
394
|
+
try {
|
|
395
|
+
const pollRes = await makeRequest(
|
|
396
|
+
`${DEFAULT_BASE_URL}/v1/public/cli-auth/poll/${session_id}`,
|
|
397
|
+
"GET",
|
|
398
|
+
{}
|
|
399
|
+
);
|
|
400
|
+
if (pollRes.status === 200) {
|
|
401
|
+
const data = pollRes.data;
|
|
402
|
+
if (data.status === "approved" && data.secret_key) {
|
|
403
|
+
process.stdout.write("\r \r");
|
|
404
|
+
success("\uBE0C\uB77C\uC6B0\uC800 \uC778\uC99D\uC774 \uC644\uB8CC\uB418\uC5C8\uC2B5\uB2C8\uB2E4!");
|
|
405
|
+
return data.secret_key;
|
|
406
|
+
}
|
|
407
|
+
if (data.status === "expired") {
|
|
408
|
+
process.stdout.write("\r \r");
|
|
409
|
+
error("\uC778\uC99D \uC138\uC158\uC774 \uB9CC\uB8CC\uB418\uC5C8\uC2B5\uB2C8\uB2E4. \uB2E4\uC2DC \uC2DC\uB3C4\uD574\uC8FC\uC138\uC694.");
|
|
410
|
+
process.exit(1);
|
|
411
|
+
}
|
|
412
|
+
if (data.status === "denied") {
|
|
413
|
+
process.stdout.write("\r \r");
|
|
414
|
+
error("\uC778\uC99D\uC774 \uAC70\uBD80\uB418\uC5C8\uC2B5\uB2C8\uB2E4.");
|
|
415
|
+
process.exit(1);
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
if (pollRes.status === 404) {
|
|
419
|
+
process.stdout.write("\r \r");
|
|
420
|
+
error("\uC778\uC99D \uC138\uC158\uC744 \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4. \uB2E4\uC2DC \uC2DC\uB3C4\uD574\uC8FC\uC138\uC694.");
|
|
421
|
+
process.exit(1);
|
|
422
|
+
}
|
|
423
|
+
} catch {
|
|
424
|
+
}
|
|
425
|
+
attempts++;
|
|
426
|
+
}
|
|
427
|
+
process.stdout.write("\r \r");
|
|
428
|
+
error("\uC778\uC99D \uC2DC\uAC04\uC774 \uCD08\uACFC\uB418\uC5C8\uC2B5\uB2C8\uB2E4. \uB2E4\uC2DC \uC2DC\uB3C4\uD574\uC8FC\uC138\uC694.");
|
|
429
|
+
process.exit(1);
|
|
430
|
+
}
|
|
353
431
|
async function init() {
|
|
354
432
|
log(`
|
|
355
433
|
${colors.cyan}Connect Base \uD504\uB85C\uC81D\uD2B8 \uCD08\uAE30\uD654${colors.reset}
|
|
@@ -369,21 +447,32 @@ ${colors.cyan}Connect Base \uD504\uB85C\uC81D\uD2B8 \uCD08\uAE30\uD654${colors.r
|
|
|
369
447
|
return;
|
|
370
448
|
}
|
|
371
449
|
}
|
|
372
|
-
log(
|
|
450
|
+
log(`
|
|
451
|
+
${colors.dim}\uC778\uC99D \uBC29\uC2DD\uC744 \uC120\uD0DD\uD558\uC138\uC694:${colors.reset}`);
|
|
452
|
+
log(` ${colors.cyan}1${colors.reset}) Secret Key \uC9C1\uC811 \uC785\uB825 (cb_sk_...)`);
|
|
453
|
+
log(` ${colors.cyan}2${colors.reset}) \uBE0C\uB77C\uC6B0\uC800 \uB85C\uADF8\uC778\uC73C\uB85C \uC790\uB3D9 \uBC1C\uAE09
|
|
373
454
|
`);
|
|
374
|
-
const
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
455
|
+
const authChoice = await prompt(`${colors.blue}?${colors.reset} \uC120\uD0DD (1/2): `);
|
|
456
|
+
let secretKey = "";
|
|
457
|
+
if (authChoice === "2") {
|
|
458
|
+
secretKey = await browserAuthFlow();
|
|
459
|
+
} else {
|
|
460
|
+
log(`${colors.dim}Secret Key (cb_sk_): \uCF58\uC194 > \uD504\uB85C\uD544 > \uC2DC\uD06C\uB9BF \uD0A4 \uD0ED\uC5D0\uC11C \uBC1C\uAE09${colors.reset}
|
|
461
|
+
`);
|
|
462
|
+
secretKey = await promptSecret(`${colors.blue}?${colors.reset} Secret Key: `);
|
|
463
|
+
if (!secretKey) {
|
|
464
|
+
error("Secret Key\uB294 \uD544\uC218\uC785\uB2C8\uB2E4");
|
|
465
|
+
process.exit(1);
|
|
466
|
+
}
|
|
467
|
+
if (secretKey.startsWith("cb_pk_")) {
|
|
468
|
+
error("Public Key\uAC00 \uC544\uB2CC Secret Key(cb_sk_)\uB97C \uC785\uB825\uD558\uC138\uC694");
|
|
469
|
+
info("Secret Key\uB294 \uCF58\uC194 > \uD504\uB85C\uD544 > \uC2DC\uD06C\uB9BF \uD0A4 \uD0ED\uC5D0\uC11C \uC0DD\uC131\uD560 \uC218 \uC788\uC2B5\uB2C8\uB2E4");
|
|
470
|
+
process.exit(1);
|
|
471
|
+
}
|
|
472
|
+
if (!secretKey.startsWith("cb_sk_")) {
|
|
473
|
+
error("\uC720\uD6A8\uD558\uC9C0 \uC54A\uC740 \uD0A4 \uD615\uC2DD\uC785\uB2C8\uB2E4. cb_sk_\uB85C \uC2DC\uC791\uD558\uB294 Secret Key\uB97C \uC785\uB825\uD558\uC138\uC694");
|
|
474
|
+
process.exit(1);
|
|
475
|
+
}
|
|
387
476
|
}
|
|
388
477
|
let appId = "";
|
|
389
478
|
let publicKey = "";
|