@birdybeep/cli 0.0.3 → 0.1.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/dist/bin.cjs CHANGED
@@ -348,7 +348,7 @@ async function gatherIntegrations(adapters) {
348
348
  }))
349
349
  );
350
350
  }
351
- async function isLoggedIn(tokenOptions = {}) {
351
+ async function isPaired(tokenOptions = {}) {
352
352
  return await (0, import_agent_core3.getToken)(tokenOptions) !== null;
353
353
  }
354
354
  function localQueueDepth() {
@@ -385,13 +385,13 @@ function createDoctorCommand(deps = {}) {
385
385
  run: async (ctx) => {
386
386
  const checks = [];
387
387
  const apiUrl = resolveApiUrl();
388
- const loggedIn = await isLoggedIn(deps.tokenOptions ?? {});
388
+ const paired = await isPaired(deps.tokenOptions ?? {});
389
389
  checks.push(
390
- loggedIn ? { name: "Machine token", ok: true } : {
390
+ paired ? { name: "Machine token", ok: true } : {
391
391
  name: "Machine token",
392
392
  ok: false,
393
393
  detail: "No machine token found.",
394
- remedy: "Run `birdybeep login` to pair this machine."
394
+ remedy: "Run `birdybeep pair` to pair this machine."
395
395
  }
396
396
  );
397
397
  for (const adapter of adapters) {
@@ -519,12 +519,49 @@ function createHookCommand(deps = {}) {
519
519
  };
520
520
  }
521
521
 
522
- // src/commands/login.ts
523
- var import_agent_core7 = require("@birdybeep/agent-core");
522
+ // src/commands/logout.ts
523
+ var import_agent_core6 = require("@birdybeep/agent-core");
524
+ function createClearTokenCommand(spec, deps = {}) {
525
+ return {
526
+ name: spec.name,
527
+ summary: spec.summary,
528
+ usage: `birdybeep ${spec.name}`,
529
+ run: async (ctx) => {
530
+ await (0, import_agent_core6.clearToken)(deps.tokenOptions ?? {});
531
+ ctx.io.emit(spec.humanMessage, { [spec.jsonKey]: true });
532
+ return EXIT.OK;
533
+ }
534
+ };
535
+ }
536
+ function createLogoutCommand(deps = {}) {
537
+ return createClearTokenCommand(
538
+ {
539
+ name: "logout",
540
+ summary: "Remove the local machine token (same as `unpair`)",
541
+ humanMessage: "Logged out \u2014 the machine token was removed.",
542
+ jsonKey: "loggedOut"
543
+ },
544
+ deps
545
+ );
546
+ }
547
+ function createUnpairCommand(deps = {}) {
548
+ return createClearTokenCommand(
549
+ {
550
+ name: "unpair",
551
+ summary: "Unpair this machine \u2014 remove the local machine token (same as `logout`)",
552
+ humanMessage: "Unpaired \u2014 the machine token was removed.",
553
+ jsonKey: "unpaired"
554
+ },
555
+ deps
556
+ );
557
+ }
558
+
559
+ // src/commands/pair.ts
560
+ var import_agent_core8 = require("@birdybeep/agent-core");
524
561
  var import_uqr = require("uqr");
525
562
 
526
563
  // src/pairing.ts
527
- var import_agent_core6 = require("@birdybeep/agent-core");
564
+ var import_agent_core7 = require("@birdybeep/agent-core");
528
565
  function base(apiUrl) {
529
566
  return apiUrl.replace(/\/$/, "");
530
567
  }
@@ -540,7 +577,7 @@ async function pairStart(apiUrl, input, fetchImpl) {
540
577
  body: JSON.stringify(body)
541
578
  });
542
579
  if (!res.ok) throw new Error(`pairing could not be started (HTTP ${res.status})`);
543
- const parsed = import_agent_core6.pairStartResponseSchema.safeParse(await res.json());
580
+ const parsed = import_agent_core7.pairStartResponseSchema.safeParse(await res.json());
544
581
  if (!parsed.success) throw new Error("pairing start returned an unexpected response shape");
545
582
  return parsed.data;
546
583
  }
@@ -563,7 +600,7 @@ async function pairTokenPoll(apiUrl, deviceCode, fetchImpl, machineFingerprint)
563
600
  body: JSON.stringify(body)
564
601
  });
565
602
  if (res.ok) {
566
- const parsed = import_agent_core6.pairTokenResponseSchema.safeParse(await res.json());
603
+ const parsed = import_agent_core7.pairTokenResponseSchema.safeParse(await res.json());
567
604
  if (!parsed.success) return { status: "pending" };
568
605
  return {
569
606
  status: "paired",
@@ -576,7 +613,7 @@ async function pairTokenPoll(apiUrl, deviceCode, fetchImpl, machineFingerprint)
576
613
  errBody = await res.json();
577
614
  } catch {
578
615
  }
579
- const env = import_agent_core6.errorEnvelopeSchema.safeParse(errBody);
616
+ const env = import_agent_core7.errorEnvelopeSchema.safeParse(errBody);
580
617
  const code = env.success ? env.data.error.code : void 0;
581
618
  if (code === "validation_failed" || code === void 0 && res.status >= 400 && res.status < 500 && res.status !== 429) {
582
619
  return { status: "pending" };
@@ -589,27 +626,27 @@ async function pairTokenPoll(apiUrl, deviceCode, fetchImpl, machineFingerprint)
589
626
  }
590
627
 
591
628
  // src/version.ts
592
- var CLI_VERSION = "0.0.3".length > 0 ? "0.0.3" : "0.0.0";
629
+ var CLI_VERSION = "0.1.0".length > 0 ? "0.1.0" : "0.0.0";
593
630
 
594
- // src/commands/login.ts
631
+ // src/commands/pair.ts
595
632
  var DEFAULT_POLL_INTERVAL_MS = 2e3;
596
633
  var HEARTBEAT_MS = 15e3;
597
634
  function renderQrMatrix(qrPayload) {
598
635
  return (0, import_uqr.renderUnicodeCompact)(qrPayload, { border: 2 });
599
636
  }
600
- function createLoginCommand(deps = {}) {
637
+ function createPairCommand(deps = {}) {
601
638
  const fetchImpl = deps.fetchImpl ?? fetch;
602
639
  const sleep = deps.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
603
640
  const clock = deps.now ?? (() => Date.now());
604
641
  const renderQr = deps.renderQr ?? renderQrMatrix;
605
642
  const intervalMs = deps.pollIntervalMs ?? DEFAULT_POLL_INTERVAL_MS;
606
643
  return {
607
- name: "login",
644
+ name: "pair",
608
645
  summary: "Pair this machine with your BirdyBeep account (QR or manual)",
609
- usage: "birdybeep login [--json]",
646
+ usage: "birdybeep pair [--json]",
610
647
  run: async (ctx) => {
611
648
  const apiUrl = resolveApiUrl();
612
- const identity = (0, import_agent_core7.getMachineIdentity)();
649
+ const identity = (0, import_agent_core8.getMachineIdentity)();
613
650
  const start = await pairStart(
614
651
  apiUrl,
615
652
  { machineLabel: identity.label, os: identity.os, cliVersion: CLI_VERSION },
@@ -670,11 +707,11 @@ function createLoginCommand(deps = {}) {
670
707
  if (paired === void 0 || paired.status !== "paired") {
671
708
  ctx.io.result({ paired: false, reason: "timeout" });
672
709
  ctx.io.errline(
673
- "Pairing timed out before you approved it. In the BirdyBeep app, tap \u201Cpair a machine\u201D, scan the QR (or enter the code), then run `birdybeep login` again."
710
+ "Pairing timed out before you approved it. In the BirdyBeep app, tap \u201Cpair a machine\u201D, scan the QR (or enter the code), then run `birdybeep pair` again."
674
711
  );
675
712
  return EXIT.ERROR;
676
713
  }
677
- await (0, import_agent_core7.setToken)(paired.machineToken, deps.tokenOptions ?? {});
714
+ await (0, import_agent_core8.setToken)(paired.machineToken, deps.tokenOptions ?? {});
678
715
  writeCliConfig({ apiUrl });
679
716
  ctx.io.emit(`\u2713 Paired. Run \`birdybeep test\` to send a test Beep.`, {
680
717
  paired: true,
@@ -685,21 +722,6 @@ function createLoginCommand(deps = {}) {
685
722
  };
686
723
  }
687
724
 
688
- // src/commands/logout.ts
689
- var import_agent_core8 = require("@birdybeep/agent-core");
690
- function createLogoutCommand(deps = {}) {
691
- return {
692
- name: "logout",
693
- summary: "Remove the local machine token",
694
- usage: "birdybeep logout",
695
- run: async (ctx) => {
696
- await (0, import_agent_core8.clearToken)(deps.tokenOptions ?? {});
697
- ctx.io.emit("Logged out \u2014 the machine token was removed.", { loggedOut: true });
698
- return EXIT.OK;
699
- }
700
- };
701
- }
702
-
703
725
  // src/commands/queue.ts
704
726
  var import_agent_core9 = require("@birdybeep/agent-core");
705
727
  function createQueueCommand() {
@@ -756,7 +778,7 @@ function createReportStatusCommand(deps = {}) {
756
778
  run: async (ctx) => {
757
779
  const token = await (0, import_agent_core10.getToken)(deps.tokenOptions ?? {});
758
780
  if (token === null) {
759
- ctx.io.errline("Not logged in \u2014 run `birdybeep login` first.");
781
+ ctx.io.errline("No machine token \u2014 run `birdybeep pair` first.");
760
782
  return EXIT.ERROR;
761
783
  }
762
784
  const items = await gatherItems(adapters);
@@ -801,7 +823,7 @@ function createReportStatusCommand(deps = {}) {
801
823
  });
802
824
  } else if (outcome === "terminal") {
803
825
  ctx.io.errline(
804
- `Report rejected (${errorCode ?? "auth"}) \u2014 your token may be revoked. Re-run \`birdybeep login\`.`
826
+ `Report rejected (${errorCode ?? "auth"}) \u2014 your token may be revoked. Re-run \`birdybeep pair\`.`
805
827
  );
806
828
  } else {
807
829
  for (const e of effective) {
@@ -832,14 +854,14 @@ function createStatusCommand(deps = {}) {
832
854
  usage: "birdybeep status [--json]",
833
855
  run: async (ctx) => {
834
856
  const machine = machineIdentity();
835
- const loggedIn = await isLoggedIn(deps.tokenOptions ?? {});
857
+ const paired = await isPaired(deps.tokenOptions ?? {});
836
858
  const integrations = await gatherIntegrations(adapters);
837
859
  const depthBefore = localQueueDepth();
838
860
  const drain = await makeSender(resolveApiUrl()).drainNow();
839
861
  const depthAfter = localQueueDepth();
840
862
  const report = {
841
863
  machine,
842
- loggedIn,
864
+ paired,
843
865
  integrations,
844
866
  queue: { depthBefore, delivered: drain.delivered, depthAfter }
845
867
  };
@@ -847,16 +869,14 @@ function createStatusCommand(deps = {}) {
847
869
  ctx.io.result(report);
848
870
  } else {
849
871
  ctx.io.line(`Machine: ${machine.label} (${machine.os})`);
850
- ctx.io.line(
851
- loggedIn ? "Login: paired" : "Login: NOT logged in \u2014 run `birdybeep login`"
852
- );
872
+ ctx.io.line(paired ? "Paired: yes" : "Paired: no \u2014 run `birdybeep pair`");
853
873
  ctx.io.line("Integrations:");
854
874
  for (const i of integrations) ctx.io.line(` ${i.displayName}: ${i.status}`);
855
875
  ctx.io.line(
856
876
  `Queue: ${depthBefore} queued \u2192 ${drain.delivered} delivered, ${depthAfter} remaining`
857
877
  );
858
878
  }
859
- return loggedIn ? EXIT.OK : EXIT.ERROR;
879
+ return paired ? EXIT.OK : EXIT.ERROR;
860
880
  }
861
881
  };
862
882
  }
@@ -930,8 +950,9 @@ function createTestCommand(deps = {}) {
930
950
  // src/commands.ts
931
951
  function buildCommands() {
932
952
  return [
933
- createLoginCommand(),
953
+ createPairCommand(),
934
954
  createLogoutCommand(),
955
+ createUnpairCommand(),
935
956
  createStatusCommand(),
936
957
  createTestCommand(),
937
958
  createDoctorCommand(),