connectbase-client 0.10.4 → 0.10.6

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