@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 +63 -42
- package/dist/bin.cjs.map +1 -1
- package/dist/bin.js +1 -1
- package/dist/{chunk-6VRCYDN5.js → chunk-HGH5CDKD.js} +57 -36
- package/dist/chunk-HGH5CDKD.js.map +1 -0
- package/dist/index.cjs +63 -42
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1 -1
- package/package.json +5 -5
- package/dist/chunk-6VRCYDN5.js.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -384,7 +384,7 @@ async function gatherIntegrations(adapters) {
|
|
|
384
384
|
}))
|
|
385
385
|
);
|
|
386
386
|
}
|
|
387
|
-
async function
|
|
387
|
+
async function isPaired(tokenOptions = {}) {
|
|
388
388
|
return await (0, import_agent_core3.getToken)(tokenOptions) !== null;
|
|
389
389
|
}
|
|
390
390
|
function localQueueDepth() {
|
|
@@ -421,13 +421,13 @@ function createDoctorCommand(deps = {}) {
|
|
|
421
421
|
run: async (ctx) => {
|
|
422
422
|
const checks = [];
|
|
423
423
|
const apiUrl = resolveApiUrl();
|
|
424
|
-
const
|
|
424
|
+
const paired = await isPaired(deps.tokenOptions ?? {});
|
|
425
425
|
checks.push(
|
|
426
|
-
|
|
426
|
+
paired ? { name: "Machine token", ok: true } : {
|
|
427
427
|
name: "Machine token",
|
|
428
428
|
ok: false,
|
|
429
429
|
detail: "No machine token found.",
|
|
430
|
-
remedy: "Run `birdybeep
|
|
430
|
+
remedy: "Run `birdybeep pair` to pair this machine."
|
|
431
431
|
}
|
|
432
432
|
);
|
|
433
433
|
for (const adapter of adapters) {
|
|
@@ -555,12 +555,49 @@ function createHookCommand(deps = {}) {
|
|
|
555
555
|
};
|
|
556
556
|
}
|
|
557
557
|
|
|
558
|
-
// src/commands/
|
|
559
|
-
var
|
|
558
|
+
// src/commands/logout.ts
|
|
559
|
+
var import_agent_core6 = require("@birdybeep/agent-core");
|
|
560
|
+
function createClearTokenCommand(spec, deps = {}) {
|
|
561
|
+
return {
|
|
562
|
+
name: spec.name,
|
|
563
|
+
summary: spec.summary,
|
|
564
|
+
usage: `birdybeep ${spec.name}`,
|
|
565
|
+
run: async (ctx) => {
|
|
566
|
+
await (0, import_agent_core6.clearToken)(deps.tokenOptions ?? {});
|
|
567
|
+
ctx.io.emit(spec.humanMessage, { [spec.jsonKey]: true });
|
|
568
|
+
return EXIT.OK;
|
|
569
|
+
}
|
|
570
|
+
};
|
|
571
|
+
}
|
|
572
|
+
function createLogoutCommand(deps = {}) {
|
|
573
|
+
return createClearTokenCommand(
|
|
574
|
+
{
|
|
575
|
+
name: "logout",
|
|
576
|
+
summary: "Remove the local machine token (same as `unpair`)",
|
|
577
|
+
humanMessage: "Logged out \u2014 the machine token was removed.",
|
|
578
|
+
jsonKey: "loggedOut"
|
|
579
|
+
},
|
|
580
|
+
deps
|
|
581
|
+
);
|
|
582
|
+
}
|
|
583
|
+
function createUnpairCommand(deps = {}) {
|
|
584
|
+
return createClearTokenCommand(
|
|
585
|
+
{
|
|
586
|
+
name: "unpair",
|
|
587
|
+
summary: "Unpair this machine \u2014 remove the local machine token (same as `logout`)",
|
|
588
|
+
humanMessage: "Unpaired \u2014 the machine token was removed.",
|
|
589
|
+
jsonKey: "unpaired"
|
|
590
|
+
},
|
|
591
|
+
deps
|
|
592
|
+
);
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
// src/commands/pair.ts
|
|
596
|
+
var import_agent_core8 = require("@birdybeep/agent-core");
|
|
560
597
|
var import_uqr = require("uqr");
|
|
561
598
|
|
|
562
599
|
// src/pairing.ts
|
|
563
|
-
var
|
|
600
|
+
var import_agent_core7 = require("@birdybeep/agent-core");
|
|
564
601
|
function base(apiUrl) {
|
|
565
602
|
return apiUrl.replace(/\/$/, "");
|
|
566
603
|
}
|
|
@@ -576,7 +613,7 @@ async function pairStart(apiUrl, input, fetchImpl) {
|
|
|
576
613
|
body: JSON.stringify(body)
|
|
577
614
|
});
|
|
578
615
|
if (!res.ok) throw new Error(`pairing could not be started (HTTP ${res.status})`);
|
|
579
|
-
const parsed =
|
|
616
|
+
const parsed = import_agent_core7.pairStartResponseSchema.safeParse(await res.json());
|
|
580
617
|
if (!parsed.success) throw new Error("pairing start returned an unexpected response shape");
|
|
581
618
|
return parsed.data;
|
|
582
619
|
}
|
|
@@ -599,7 +636,7 @@ async function pairTokenPoll(apiUrl, deviceCode, fetchImpl, machineFingerprint)
|
|
|
599
636
|
body: JSON.stringify(body)
|
|
600
637
|
});
|
|
601
638
|
if (res.ok) {
|
|
602
|
-
const parsed =
|
|
639
|
+
const parsed = import_agent_core7.pairTokenResponseSchema.safeParse(await res.json());
|
|
603
640
|
if (!parsed.success) return { status: "pending" };
|
|
604
641
|
return {
|
|
605
642
|
status: "paired",
|
|
@@ -612,7 +649,7 @@ async function pairTokenPoll(apiUrl, deviceCode, fetchImpl, machineFingerprint)
|
|
|
612
649
|
errBody = await res.json();
|
|
613
650
|
} catch {
|
|
614
651
|
}
|
|
615
|
-
const env =
|
|
652
|
+
const env = import_agent_core7.errorEnvelopeSchema.safeParse(errBody);
|
|
616
653
|
const code = env.success ? env.data.error.code : void 0;
|
|
617
654
|
if (code === "validation_failed" || code === void 0 && res.status >= 400 && res.status < 500 && res.status !== 429) {
|
|
618
655
|
return { status: "pending" };
|
|
@@ -625,27 +662,27 @@ async function pairTokenPoll(apiUrl, deviceCode, fetchImpl, machineFingerprint)
|
|
|
625
662
|
}
|
|
626
663
|
|
|
627
664
|
// src/version.ts
|
|
628
|
-
var CLI_VERSION = "0.0
|
|
665
|
+
var CLI_VERSION = "0.1.0".length > 0 ? "0.1.0" : "0.0.0";
|
|
629
666
|
|
|
630
|
-
// src/commands/
|
|
667
|
+
// src/commands/pair.ts
|
|
631
668
|
var DEFAULT_POLL_INTERVAL_MS = 2e3;
|
|
632
669
|
var HEARTBEAT_MS = 15e3;
|
|
633
670
|
function renderQrMatrix(qrPayload) {
|
|
634
671
|
return (0, import_uqr.renderUnicodeCompact)(qrPayload, { border: 2 });
|
|
635
672
|
}
|
|
636
|
-
function
|
|
673
|
+
function createPairCommand(deps = {}) {
|
|
637
674
|
const fetchImpl = deps.fetchImpl ?? fetch;
|
|
638
675
|
const sleep = deps.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
|
|
639
676
|
const clock = deps.now ?? (() => Date.now());
|
|
640
677
|
const renderQr = deps.renderQr ?? renderQrMatrix;
|
|
641
678
|
const intervalMs = deps.pollIntervalMs ?? DEFAULT_POLL_INTERVAL_MS;
|
|
642
679
|
return {
|
|
643
|
-
name: "
|
|
680
|
+
name: "pair",
|
|
644
681
|
summary: "Pair this machine with your BirdyBeep account (QR or manual)",
|
|
645
|
-
usage: "birdybeep
|
|
682
|
+
usage: "birdybeep pair [--json]",
|
|
646
683
|
run: async (ctx) => {
|
|
647
684
|
const apiUrl = resolveApiUrl();
|
|
648
|
-
const identity = (0,
|
|
685
|
+
const identity = (0, import_agent_core8.getMachineIdentity)();
|
|
649
686
|
const start = await pairStart(
|
|
650
687
|
apiUrl,
|
|
651
688
|
{ machineLabel: identity.label, os: identity.os, cliVersion: CLI_VERSION },
|
|
@@ -706,11 +743,11 @@ function createLoginCommand(deps = {}) {
|
|
|
706
743
|
if (paired === void 0 || paired.status !== "paired") {
|
|
707
744
|
ctx.io.result({ paired: false, reason: "timeout" });
|
|
708
745
|
ctx.io.errline(
|
|
709
|
-
"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
|
|
746
|
+
"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."
|
|
710
747
|
);
|
|
711
748
|
return EXIT.ERROR;
|
|
712
749
|
}
|
|
713
|
-
await (0,
|
|
750
|
+
await (0, import_agent_core8.setToken)(paired.machineToken, deps.tokenOptions ?? {});
|
|
714
751
|
writeCliConfig({ apiUrl });
|
|
715
752
|
ctx.io.emit(`\u2713 Paired. Run \`birdybeep test\` to send a test Beep.`, {
|
|
716
753
|
paired: true,
|
|
@@ -721,21 +758,6 @@ function createLoginCommand(deps = {}) {
|
|
|
721
758
|
};
|
|
722
759
|
}
|
|
723
760
|
|
|
724
|
-
// src/commands/logout.ts
|
|
725
|
-
var import_agent_core8 = require("@birdybeep/agent-core");
|
|
726
|
-
function createLogoutCommand(deps = {}) {
|
|
727
|
-
return {
|
|
728
|
-
name: "logout",
|
|
729
|
-
summary: "Remove the local machine token",
|
|
730
|
-
usage: "birdybeep logout",
|
|
731
|
-
run: async (ctx) => {
|
|
732
|
-
await (0, import_agent_core8.clearToken)(deps.tokenOptions ?? {});
|
|
733
|
-
ctx.io.emit("Logged out \u2014 the machine token was removed.", { loggedOut: true });
|
|
734
|
-
return EXIT.OK;
|
|
735
|
-
}
|
|
736
|
-
};
|
|
737
|
-
}
|
|
738
|
-
|
|
739
761
|
// src/commands/queue.ts
|
|
740
762
|
var import_agent_core9 = require("@birdybeep/agent-core");
|
|
741
763
|
function createQueueCommand() {
|
|
@@ -792,7 +814,7 @@ function createReportStatusCommand(deps = {}) {
|
|
|
792
814
|
run: async (ctx) => {
|
|
793
815
|
const token = await (0, import_agent_core10.getToken)(deps.tokenOptions ?? {});
|
|
794
816
|
if (token === null) {
|
|
795
|
-
ctx.io.errline("
|
|
817
|
+
ctx.io.errline("No machine token \u2014 run `birdybeep pair` first.");
|
|
796
818
|
return EXIT.ERROR;
|
|
797
819
|
}
|
|
798
820
|
const items = await gatherItems(adapters);
|
|
@@ -837,7 +859,7 @@ function createReportStatusCommand(deps = {}) {
|
|
|
837
859
|
});
|
|
838
860
|
} else if (outcome === "terminal") {
|
|
839
861
|
ctx.io.errline(
|
|
840
|
-
`Report rejected (${errorCode ?? "auth"}) \u2014 your token may be revoked. Re-run \`birdybeep
|
|
862
|
+
`Report rejected (${errorCode ?? "auth"}) \u2014 your token may be revoked. Re-run \`birdybeep pair\`.`
|
|
841
863
|
);
|
|
842
864
|
} else {
|
|
843
865
|
for (const e of effective) {
|
|
@@ -868,14 +890,14 @@ function createStatusCommand(deps = {}) {
|
|
|
868
890
|
usage: "birdybeep status [--json]",
|
|
869
891
|
run: async (ctx) => {
|
|
870
892
|
const machine = machineIdentity();
|
|
871
|
-
const
|
|
893
|
+
const paired = await isPaired(deps.tokenOptions ?? {});
|
|
872
894
|
const integrations = await gatherIntegrations(adapters);
|
|
873
895
|
const depthBefore = localQueueDepth();
|
|
874
896
|
const drain = await makeSender(resolveApiUrl()).drainNow();
|
|
875
897
|
const depthAfter = localQueueDepth();
|
|
876
898
|
const report = {
|
|
877
899
|
machine,
|
|
878
|
-
|
|
900
|
+
paired,
|
|
879
901
|
integrations,
|
|
880
902
|
queue: { depthBefore, delivered: drain.delivered, depthAfter }
|
|
881
903
|
};
|
|
@@ -883,16 +905,14 @@ function createStatusCommand(deps = {}) {
|
|
|
883
905
|
ctx.io.result(report);
|
|
884
906
|
} else {
|
|
885
907
|
ctx.io.line(`Machine: ${machine.label} (${machine.os})`);
|
|
886
|
-
ctx.io.line(
|
|
887
|
-
loggedIn ? "Login: paired" : "Login: NOT logged in \u2014 run `birdybeep login`"
|
|
888
|
-
);
|
|
908
|
+
ctx.io.line(paired ? "Paired: yes" : "Paired: no \u2014 run `birdybeep pair`");
|
|
889
909
|
ctx.io.line("Integrations:");
|
|
890
910
|
for (const i of integrations) ctx.io.line(` ${i.displayName}: ${i.status}`);
|
|
891
911
|
ctx.io.line(
|
|
892
912
|
`Queue: ${depthBefore} queued \u2192 ${drain.delivered} delivered, ${depthAfter} remaining`
|
|
893
913
|
);
|
|
894
914
|
}
|
|
895
|
-
return
|
|
915
|
+
return paired ? EXIT.OK : EXIT.ERROR;
|
|
896
916
|
}
|
|
897
917
|
};
|
|
898
918
|
}
|
|
@@ -966,8 +986,9 @@ function createTestCommand(deps = {}) {
|
|
|
966
986
|
// src/commands.ts
|
|
967
987
|
function buildCommands() {
|
|
968
988
|
return [
|
|
969
|
-
|
|
989
|
+
createPairCommand(),
|
|
970
990
|
createLogoutCommand(),
|
|
991
|
+
createUnpairCommand(),
|
|
971
992
|
createStatusCommand(),
|
|
972
993
|
createTestCommand(),
|
|
973
994
|
createDoctorCommand(),
|