@arbidocs/cli 0.3.2 → 0.3.3

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/index.cjs CHANGED
@@ -3395,6 +3395,7 @@ async function promptConfirm(message, defaultValue = true) {
3395
3395
  }
3396
3396
  var CACHE_FILE = path__default.default.join(os__default.default.homedir(), ".arbi", "version-cache.json");
3397
3397
  var CACHE_TTL_MS = 24 * 60 * 60 * 1e3;
3398
+ var CHANGELOG_URL = "https://raw.githubusercontent.com/arbitrationcity/ARBI-frontend/refs/tags/{tag}/CHANGELOG.md";
3398
3399
  function readCache() {
3399
3400
  try {
3400
3401
  const data = JSON.parse(fs__default.default.readFileSync(CACHE_FILE, "utf8"));
@@ -3427,21 +3428,64 @@ function getLatestVersion() {
3427
3428
  return null;
3428
3429
  }
3429
3430
  }
3430
- function checkForUpdates(autoUpdate) {
3431
+ function getCurrentVersion() {
3432
+ return "0.3.3";
3433
+ }
3434
+ async function fetchChangelog(fromVersion, toVersion) {
3435
+ try {
3436
+ const url = CHANGELOG_URL.replace("{tag}", `v${toVersion}`);
3437
+ const res = await fetch(url, { signal: AbortSignal.timeout(5e3) });
3438
+ if (!res.ok) return null;
3439
+ const text = await res.text();
3440
+ return extractSections(text, fromVersion, toVersion);
3441
+ } catch {
3442
+ return null;
3443
+ }
3444
+ }
3445
+ function extractSections(changelog, fromVersion, toVersion) {
3446
+ const lines = changelog.split("\n");
3447
+ const sections = [];
3448
+ let capturing = false;
3449
+ for (const line of lines) {
3450
+ const match = line.match(/^## v(.+)/);
3451
+ if (match) {
3452
+ const version = match[1].trim();
3453
+ if (version === fromVersion) {
3454
+ break;
3455
+ }
3456
+ if (version === toVersion || capturing) {
3457
+ capturing = true;
3458
+ }
3459
+ }
3460
+ if (capturing) {
3461
+ sections.push(line);
3462
+ }
3463
+ }
3464
+ const result = sections.join("\n").trim();
3465
+ return result || null;
3466
+ }
3467
+ async function showChangelog(fromVersion, toVersion) {
3468
+ const changelog = await fetchChangelog(fromVersion, toVersion);
3469
+ if (changelog) {
3470
+ console.log("\n" + changelog);
3471
+ }
3472
+ }
3473
+ async function checkForUpdates(autoUpdate) {
3431
3474
  try {
3432
3475
  const latest = getLatestVersion();
3433
- if (!latest || latest === "0.3.2") return;
3476
+ if (!latest || latest === "0.3.3") return;
3434
3477
  if (autoUpdate) {
3435
3478
  console.log(
3436
3479
  `
3437
- Your arbi version is out of date (${"0.3.2"} \u2192 ${latest}). Updating...`
3480
+ Your arbi version is out of date (${"0.3.3"} \u2192 ${latest}). Updating...`
3438
3481
  );
3482
+ await showChangelog("0.3.3", latest);
3439
3483
  child_process.execSync("npm install -g @arbidocs/cli@latest", { stdio: "inherit" });
3440
3484
  console.log(`Updated to ${latest}.`);
3441
3485
  } else {
3442
3486
  console.error(
3443
3487
  `
3444
- Your arbi version is out of date (${"0.3.2"} \u2192 ${latest}).
3488
+ Your arbi version is out of date (${"0.3.3"} \u2192 ${latest}).
3445
3489
  Run "arbi update" to upgrade, or "arbi update auto" to always stay up to date.`
3446
3490
  );
3447
3491
  }
@@ -3451,9 +3495,9 @@ Run "arbi update" to upgrade, or "arbi update auto" to always stay up to date.`
3451
3495
  function hintUpdateOnError() {
3452
3496
  try {
3453
3497
  const cached = readCache();
3454
- if (cached && cached.latest !== "0.3.2") {
3498
+ if (cached && cached.latest !== "0.3.3") {
3455
3499
  console.error(
3456
- `Your arbi version is out of date (${"0.3.2"} \u2192 ${cached.latest}). Run "arbi update".`
3500
+ `Your arbi version is out of date (${"0.3.3"} \u2192 ${cached.latest}). Run "arbi update".`
3457
3501
  );
3458
3502
  }
3459
3503
  } catch {
@@ -3499,7 +3543,7 @@ function registerLoginCommand(program2) {
3499
3543
  console.error(`Login failed: ${core.getErrorMessage(err)}`);
3500
3544
  process.exit(1);
3501
3545
  } finally {
3502
- checkForUpdates(getConfig()?.autoUpdate);
3546
+ await checkForUpdates(getConfig()?.autoUpdate);
3503
3547
  }
3504
3548
  });
3505
3549
  }
@@ -3520,56 +3564,65 @@ async function getVerificationCode(email, apiKey) {
3520
3564
  return Array.isArray(words) ? words.join(" ") : String(words);
3521
3565
  }
3522
3566
  function registerRegisterCommand(program2) {
3523
- program2.command("register").description("Register a new ARBI account").option("--non-interactive", "CI/automation mode (requires SUPPORT_API_KEY env var)").option("-e, --email <email>", "Email address (or ARBI_EMAIL env var)").option("-p, --password <password>", "Password (or ARBI_PASSWORD env var)").option("--first-name <name>", "First name").option("--last-name <name>", "Last name").action(
3524
- async (opts) => {
3525
- const config = requireConfig();
3526
- if (opts.nonInteractive) {
3527
- await nonInteractiveRegister(config, opts);
3528
- } else {
3529
- await interactiveRegister(config, opts);
3530
- }
3567
+ program2.command("register").description("Register a new ARBI account").option("--non-interactive", "CI/automation mode (requires SUPPORT_API_KEY env var)").option("-e, --email <email>", "Email address (or ARBI_EMAIL env var)").option("-p, --password <password>", "Password (or ARBI_PASSWORD env var)").option("-c, --verification-code <code>", "Verification code (skip prompt)").option("--first-name <name>", "First name").option("--last-name <name>", "Last name").option("-w, --workspace <id>", "Workspace ID to select after login").action(async (opts) => {
3568
+ const config = requireConfig();
3569
+ if (opts.nonInteractive) {
3570
+ await nonInteractiveRegister(config, opts);
3571
+ } else {
3572
+ await smartRegister(config, opts);
3531
3573
  }
3532
- );
3574
+ });
3533
3575
  }
3534
- async function interactiveRegister(config, opts) {
3535
- const email = opts.email || await promptInput("Email");
3576
+ async function smartRegister(config, opts) {
3577
+ const email = opts.email || process.env.ARBI_EMAIL || await promptInput("Email");
3536
3578
  const arbi = sdk.createArbiClient({
3537
3579
  baseUrl: config.baseUrl,
3538
3580
  deploymentDomain: config.deploymentDomain,
3539
3581
  credentials: "omit"
3540
3582
  });
3541
3583
  await arbi.crypto.initSodium();
3542
- const codeMethod = await promptSelect("Verification method", [
3543
- { name: "I have an invitation code", value: "code" },
3544
- { name: "Send me a verification email", value: "email" }
3545
- ]);
3546
3584
  let verificationCode;
3547
- if (codeMethod === "code") {
3548
- verificationCode = await promptInput("Invitation code");
3585
+ if (opts.verificationCode) {
3586
+ verificationCode = opts.verificationCode;
3549
3587
  } else {
3550
- console.log("Sending verification email...");
3551
- const verifyResponse = await arbi.fetch.POST("/api/user/verify-email", {
3552
- body: { email }
3553
- });
3554
- if (verifyResponse.error) {
3555
- console.error(`Failed to send verification email: ${JSON.stringify(verifyResponse.error)}`);
3556
- process.exit(1);
3588
+ const codeMethod = await promptSelect("Verification method", [
3589
+ { name: "I have an invitation code", value: "code" },
3590
+ { name: "Send me a verification email", value: "email" }
3591
+ ]);
3592
+ if (codeMethod === "code") {
3593
+ verificationCode = await promptInput("Invitation code");
3594
+ } else {
3595
+ console.log("Sending verification email...");
3596
+ const verifyResponse = await arbi.fetch.POST("/api/user/verify-email", {
3597
+ body: { email }
3598
+ });
3599
+ if (verifyResponse.error) {
3600
+ console.error(`Failed to send verification email: ${JSON.stringify(verifyResponse.error)}`);
3601
+ process.exit(1);
3602
+ }
3603
+ console.log("Verification email sent. Check your inbox.");
3604
+ verificationCode = await promptInput("Verification code");
3557
3605
  }
3558
- console.log("Verification email sent. Check your inbox.");
3559
- verificationCode = await promptInput("Verification code");
3560
3606
  }
3561
- const password2 = opts.password || await promptPassword("Password");
3562
- const confirmPw = await promptPassword("Confirm password");
3563
- if (password2 !== confirmPw) {
3564
- console.error("Passwords do not match.");
3565
- process.exit(1);
3607
+ let pw;
3608
+ const flagOrEnvPassword = opts.password || process.env.ARBI_PASSWORD;
3609
+ if (flagOrEnvPassword) {
3610
+ pw = flagOrEnvPassword;
3611
+ } else {
3612
+ pw = await promptPassword("Password");
3613
+ const confirmPw = await promptPassword("Confirm password");
3614
+ if (pw !== confirmPw) {
3615
+ console.error("Passwords do not match.");
3616
+ process.exit(1);
3617
+ }
3566
3618
  }
3567
- const firstName = opts.firstName || await promptInput("First name", false) || "User";
3568
- const lastName = opts.lastName || await promptInput("Last name", false) || "";
3619
+ const hasAllCoreFlags = !!(opts.email || process.env.ARBI_EMAIL) && !!(opts.password || process.env.ARBI_PASSWORD) && !!opts.verificationCode;
3620
+ const firstName = opts.firstName || (hasAllCoreFlags ? "User" : await promptInput("First name", false) || "User");
3621
+ const lastName = opts.lastName || (hasAllCoreFlags ? "" : await promptInput("Last name", false) || "");
3569
3622
  try {
3570
3623
  await arbi.auth.register({
3571
3624
  email,
3572
- password: password2,
3625
+ password: pw,
3573
3626
  verificationCode,
3574
3627
  firstName,
3575
3628
  lastName
@@ -3580,27 +3633,10 @@ Registered successfully as ${email}`);
3580
3633
  console.error(`Registration failed: ${core.getErrorMessage(err)}`);
3581
3634
  process.exit(1);
3582
3635
  }
3583
- const doLogin = await promptConfirm("Log in now?");
3636
+ const allFlagsProvided = !!(opts.email || process.env.ARBI_EMAIL) && !!(opts.password || process.env.ARBI_PASSWORD) && !!opts.verificationCode;
3637
+ const doLogin = allFlagsProvided || await promptConfirm("Log in now?");
3584
3638
  if (doLogin) {
3585
- try {
3586
- const { arbi: loggedInArbi } = await core.performPasswordLogin(config, email, password2, store);
3587
- const { data: workspaces2 } = await loggedInArbi.fetch.GET("/api/user/workspaces");
3588
- const wsList = workspaces2 || [];
3589
- console.log(`Logged in as ${email}`);
3590
- if (wsList.length === 1) {
3591
- updateConfig({ selectedWorkspaceId: wsList[0].external_id });
3592
- console.log(`Workspace: ${wsList[0].name} (${wsList[0].external_id})`);
3593
- } else if (wsList.length > 1) {
3594
- const choices = core.formatWorkspaceChoices(wsList);
3595
- const selected = await promptSelect("Select workspace", choices);
3596
- updateConfig({ selectedWorkspaceId: selected });
3597
- const ws = wsList.find((w) => w.external_id === selected);
3598
- console.log(`Workspace: ${ws.name} (${selected})`);
3599
- }
3600
- } catch (err) {
3601
- console.error(`Login failed: ${core.getErrorMessage(err)}`);
3602
- console.error("You can log in later with: arbi login");
3603
- }
3639
+ await loginAfterRegister(config, email, pw, opts.workspace);
3604
3640
  }
3605
3641
  }
3606
3642
  async function nonInteractiveRegister(config, opts) {
@@ -3615,24 +3651,31 @@ async function nonInteractiveRegister(config, opts) {
3615
3651
  console.error("Password required. Use --password <password> or set ARBI_PASSWORD");
3616
3652
  process.exit(1);
3617
3653
  }
3618
- if (!supportApiKey) {
3619
- console.error("SUPPORT_API_KEY env var is required for --non-interactive registration");
3620
- process.exit(1);
3621
- }
3622
3654
  const arbi = sdk.createArbiClient({
3623
3655
  baseUrl: config.baseUrl,
3624
3656
  deploymentDomain: config.deploymentDomain,
3625
3657
  credentials: "omit"
3626
3658
  });
3627
3659
  await arbi.crypto.initSodium();
3628
- const verifyResponse = await arbi.fetch.POST("/api/user/verify-email", {
3629
- body: { email }
3630
- });
3631
- if (verifyResponse.error) {
3632
- console.error(`verify-email failed: ${JSON.stringify(verifyResponse.error)}`);
3633
- process.exit(1);
3660
+ let verificationCode;
3661
+ if (opts.verificationCode) {
3662
+ verificationCode = opts.verificationCode;
3663
+ } else {
3664
+ if (!supportApiKey) {
3665
+ console.error(
3666
+ "Verification code required. Use --verification-code <code> or set SUPPORT_API_KEY for CI mode"
3667
+ );
3668
+ process.exit(1);
3669
+ }
3670
+ const verifyResponse = await arbi.fetch.POST("/api/user/verify-email", {
3671
+ body: { email }
3672
+ });
3673
+ if (verifyResponse.error) {
3674
+ console.error(`verify-email failed: ${JSON.stringify(verifyResponse.error)}`);
3675
+ process.exit(1);
3676
+ }
3677
+ verificationCode = await getVerificationCode(email, supportApiKey);
3634
3678
  }
3635
- const verificationCode = await getVerificationCode(email, supportApiKey);
3636
3679
  try {
3637
3680
  await arbi.auth.register({
3638
3681
  email,
@@ -3647,6 +3690,38 @@ async function nonInteractiveRegister(config, opts) {
3647
3690
  process.exit(1);
3648
3691
  }
3649
3692
  }
3693
+ async function loginAfterRegister(config, email, password2, workspaceId) {
3694
+ try {
3695
+ const { arbi } = await core.performPasswordLogin(config, email, password2, store);
3696
+ const { data: workspaces2 } = await arbi.fetch.GET("/api/user/workspaces");
3697
+ const wsList = workspaces2 || [];
3698
+ console.log(`Logged in as ${email}`);
3699
+ if (wsList.length === 0) return;
3700
+ if (workspaceId) {
3701
+ const ws = wsList.find((w) => w.external_id === workspaceId);
3702
+ if (ws) {
3703
+ updateConfig({ selectedWorkspaceId: ws.external_id });
3704
+ console.log(`Workspace: ${ws.name} (${ws.external_id})`);
3705
+ } else {
3706
+ console.error(`Workspace ${workspaceId} not found.`);
3707
+ }
3708
+ return;
3709
+ }
3710
+ if (wsList.length === 1) {
3711
+ updateConfig({ selectedWorkspaceId: wsList[0].external_id });
3712
+ console.log(`Workspace: ${wsList[0].name} (${wsList[0].external_id})`);
3713
+ } else if (wsList.length > 1) {
3714
+ const choices = core.formatWorkspaceChoices(wsList);
3715
+ const selected = await promptSelect("Select workspace", choices);
3716
+ updateConfig({ selectedWorkspaceId: selected });
3717
+ const ws = wsList.find((w) => w.external_id === selected);
3718
+ console.log(`Workspace: ${ws.name} (${selected})`);
3719
+ }
3720
+ } catch (err) {
3721
+ console.error(`Login failed: ${core.getErrorMessage(err)}`);
3722
+ console.error("You can log in later with: arbi login");
3723
+ }
3724
+ }
3650
3725
 
3651
3726
  // src/commands/logout.ts
3652
3727
  function registerLogoutCommand(program2) {
@@ -5047,17 +5122,19 @@ function registerTuiCommand(program2) {
5047
5122
  });
5048
5123
  }
5049
5124
  function registerUpdateCommand(program2) {
5050
- const update = program2.command("update").description("Update ARBI CLI to the latest version").action(() => {
5051
- console.log(`Current version: ${"0.3.2"}`);
5125
+ const update = program2.command("update").description("Update ARBI CLI to the latest version").action(async () => {
5126
+ const current = getCurrentVersion();
5127
+ console.log(`Current version: ${current}`);
5052
5128
  console.log("Checking for updates...\n");
5053
5129
  try {
5054
- const latest = child_process.execSync("npm view @arbidocs/cli version", { encoding: "utf8" }).trim();
5055
- if (latest === "0.3.2") {
5130
+ const latest = getLatestVersion() || child_process.execSync("npm view @arbidocs/cli version", { encoding: "utf8" }).trim();
5131
+ if (latest === current) {
5056
5132
  console.log("Already up to date.");
5057
5133
  return;
5058
5134
  }
5059
5135
  console.log(`New version available: ${latest}`);
5060
- console.log("Updating...\n");
5136
+ await showChangelog(current, latest);
5137
+ console.log("\nUpdating...\n");
5061
5138
  child_process.execSync("npm install -g @arbidocs/cli@latest", { stdio: "inherit" });
5062
5139
  console.log(`
5063
5140
  Updated to ${latest}.`);
@@ -5084,7 +5161,7 @@ console.info = (...args) => {
5084
5161
  _origInfo(...args);
5085
5162
  };
5086
5163
  var program = new commander.Command();
5087
- program.name("arbi").description("ARBI CLI \u2014 interact with ARBI from the terminal").version("0.3.2");
5164
+ program.name("arbi").description("ARBI CLI \u2014 interact with ARBI from the terminal").version("0.3.3");
5088
5165
  registerConfigCommand(program);
5089
5166
  registerLoginCommand(program);
5090
5167
  registerRegisterCommand(program);