bamboo-agents 0.1.2 → 0.1.4

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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.2
1
+ 0.1.4
package/dist/index.js CHANGED
@@ -3037,7 +3037,7 @@ var VERSION;
3037
3037
  var init_version = __esm({
3038
3038
  "src/version.ts"() {
3039
3039
  "use strict";
3040
- VERSION = "0.1.2";
3040
+ VERSION = "0.1.4";
3041
3041
  }
3042
3042
  });
3043
3043
 
@@ -11407,8 +11407,11 @@ var init_auth_status = __esm({
11407
11407
 
11408
11408
  // src/lib/api.ts
11409
11409
  import { platform as platform2 } from "node:os";
11410
+ function defaultApiBase(version) {
11411
+ return version.includes("-dev.") ? DEV_DEFAULT_BASE : PROD_DEFAULT_BASE;
11412
+ }
11410
11413
  function apiBase() {
11411
- return process.env.BAMBOO_API_BASE ?? DEFAULT_BASE;
11414
+ return process.env.BAMBOO_BASE_URL ?? defaultApiBase(VERSION);
11412
11415
  }
11413
11416
  async function parseError(res) {
11414
11417
  let body = {};
@@ -11450,14 +11453,28 @@ async function getCliAuthStatus(bambooSession) {
11450
11453
  const json = await res.json();
11451
11454
  return AuthStatusResponseSchema.parse(json);
11452
11455
  }
11453
- var DEFAULT_BASE, REQUEST_TIMEOUT_MS, ApiError;
11456
+ async function startGithubOAuthRelink(bambooSession) {
11457
+ const res = await cliApiFetch(
11458
+ `${apiBase()}/api/auth/github/oauth-relink/start`,
11459
+ {
11460
+ method: "POST",
11461
+ headers: { Authorization: `Bearer ${bambooSession}` }
11462
+ }
11463
+ );
11464
+ if (!res.ok) throw await parseError(res);
11465
+ const json = await res.json();
11466
+ return OAuthRelinkStartResponseSchema.parse(json);
11467
+ }
11468
+ var PROD_DEFAULT_BASE, DEV_DEFAULT_BASE, REQUEST_TIMEOUT_MS, ApiError, OAuthRelinkStartResponseSchema;
11454
11469
  var init_api = __esm({
11455
11470
  "src/lib/api.ts"() {
11456
11471
  "use strict";
11472
+ init_zod();
11457
11473
  init_auth_token();
11458
11474
  init_auth_status();
11459
11475
  init_version();
11460
- DEFAULT_BASE = "https://withbamboo.com";
11476
+ PROD_DEFAULT_BASE = "https://withbamboo.com";
11477
+ DEV_DEFAULT_BASE = "https://dev.withbamboo.com";
11461
11478
  REQUEST_TIMEOUT_MS = 3e4;
11462
11479
  ApiError = class extends Error {
11463
11480
  constructor(message, status, errorCode) {
@@ -11467,6 +11484,9 @@ var init_api = __esm({
11467
11484
  this.name = "ApiError";
11468
11485
  }
11469
11486
  };
11487
+ OAuthRelinkStartResponseSchema = external_exports.object({
11488
+ relink_url: external_exports.string().url()
11489
+ });
11470
11490
  }
11471
11491
  });
11472
11492
 
@@ -11530,6 +11550,7 @@ var init_credentials = __esm({
11530
11550
  // src/commands/login.ts
11531
11551
  var login_exports = {};
11532
11552
  __export(login_exports, {
11553
+ handleMissingGithubToken: () => handleMissingGithubToken,
11533
11554
  runLogin: () => runLogin,
11534
11555
  startCallbackServer: () => startCallbackServer,
11535
11556
  verificationCode: () => verificationCode
@@ -11542,6 +11563,26 @@ function verificationCode(state) {
11542
11563
  const head = state.slice(0, 8).toUpperCase();
11543
11564
  return `${head.slice(0, 4)}-${head.slice(4, 8)}`;
11544
11565
  }
11566
+ async function handleMissingGithubToken(bambooSession) {
11567
+ try {
11568
+ const { relink_url } = await startGithubOAuthRelink(bambooSession);
11569
+ await open_default(relink_url);
11570
+ console.log("");
11571
+ console.log(
11572
+ " After authorizing in your browser, re-run `bamboo-agents login`."
11573
+ );
11574
+ console.log("");
11575
+ return 0;
11576
+ } catch {
11577
+ console.log("");
11578
+ console.log(
11579
+ ` Couldn't start GitHub re-link automatically. Open this URL in your browser, then re-run \`bamboo-agents login\`:`
11580
+ );
11581
+ console.log(` ${FALLBACK_RELINK_URL}`);
11582
+ console.log("");
11583
+ return 1;
11584
+ }
11585
+ }
11545
11586
  async function startCallbackServer(expectedState) {
11546
11587
  let resolveSession;
11547
11588
  let rejectSession;
@@ -11649,10 +11690,11 @@ async function runLogin() {
11649
11690
  tokenResp = await getGithubToken(bambooSession);
11650
11691
  } catch (err) {
11651
11692
  if (err instanceof ApiError && err.status === 404) {
11652
- tokenSpinner.fail(
11653
- "No GitHub token linked yet. Sign in to Bamboo with GitHub once at https://withbamboo.com, then re-run."
11693
+ tokenSpinner.warn(
11694
+ "No GitHub token linked yet \u2014 opening browser to authorize Bamboo with GitHub\u2026"
11654
11695
  );
11655
- process.exit(1);
11696
+ const code2 = await handleMissingGithubToken(bambooSession);
11697
+ process.exit(code2);
11656
11698
  }
11657
11699
  if (err instanceof ApiError && err.status === 410) {
11658
11700
  tokenSpinner.fail("Your GitHub token expired. Sign in to Bamboo with GitHub again, then re-run.");
@@ -11676,7 +11718,7 @@ async function runLogin() {
11676
11718
  console.log(" Next: `bamboo-agents init` to clone your workspace.");
11677
11719
  console.log("");
11678
11720
  }
11679
- var LOGIN_TIMEOUT_MS;
11721
+ var FALLBACK_RELINK_URL, LOGIN_TIMEOUT_MS;
11680
11722
  var init_login = __esm({
11681
11723
  "src/commands/login.ts"() {
11682
11724
  "use strict";
@@ -11684,6 +11726,7 @@ var init_login = __esm({
11684
11726
  init_ora();
11685
11727
  init_api();
11686
11728
  init_credentials();
11729
+ FALLBACK_RELINK_URL = "https://withbamboo.com/connect-github";
11687
11730
  LOGIN_TIMEOUT_MS = 5 * 60 * 1e3;
11688
11731
  }
11689
11732
  });