bpmax-cli 0.1.41 → 0.1.42
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.js +57 -6
- package/dist/bin.js.map +1 -1
- package/package.json +1 -1
package/dist/bin.js
CHANGED
|
@@ -515,9 +515,53 @@ function buildBridgeUrl(origin, workspace, params) {
|
|
|
515
515
|
const query = new URLSearchParams(params);
|
|
516
516
|
return `${origin}/${encodeURIComponent(workspace)}/cli-login?${query.toString()}`;
|
|
517
517
|
}
|
|
518
|
+
function normalizeDeviceWorkspace(workspace) {
|
|
519
|
+
const nextWorkspace = workspace.trim().replace(/^\/+|\/+$/g, "");
|
|
520
|
+
if (!nextWorkspace) {
|
|
521
|
+
throw new Error("Workspace is required before starting device authorization.");
|
|
522
|
+
}
|
|
523
|
+
if (nextWorkspace === "default") {
|
|
524
|
+
return nextWorkspace;
|
|
525
|
+
}
|
|
526
|
+
if (nextWorkspace === "w" || nextWorkspace === "w:") {
|
|
527
|
+
throw new Error(`Invalid BPMAX workspace "${workspace}". Expected a concrete workspace like "w:ybs".`);
|
|
528
|
+
}
|
|
529
|
+
return nextWorkspace.startsWith("w:") ? nextWorkspace : `w:${nextWorkspace}`;
|
|
530
|
+
}
|
|
531
|
+
function normalizeOriginForLint(origin) {
|
|
532
|
+
const nextOrigin = origin.trim().replace(/\/+$/g, "");
|
|
533
|
+
if (!nextOrigin) {
|
|
534
|
+
throw new Error("Origin is required before starting device authorization.");
|
|
535
|
+
}
|
|
536
|
+
return nextOrigin;
|
|
537
|
+
}
|
|
538
|
+
function firstPathSegment(url) {
|
|
539
|
+
return url.pathname.split("/").filter(Boolean).map((segment) => decodeURIComponent(segment))[0];
|
|
540
|
+
}
|
|
541
|
+
function lintDeviceAuthorizationUrl(urlValue, expectedOrigin, expectedWorkspace, fieldName) {
|
|
542
|
+
let url;
|
|
543
|
+
try {
|
|
544
|
+
url = new URL(urlValue);
|
|
545
|
+
} catch {
|
|
546
|
+
throw new Error(`Device authorization ${fieldName} is not a valid URL: ${urlValue}`);
|
|
547
|
+
}
|
|
548
|
+
if (url.origin !== expectedOrigin) {
|
|
549
|
+
throw new Error(
|
|
550
|
+
`Device authorization URL origin mismatch for ${fieldName}: expected ${expectedOrigin}, got ${url.origin}.`
|
|
551
|
+
);
|
|
552
|
+
}
|
|
553
|
+
const actualWorkspace = firstPathSegment(url);
|
|
554
|
+
if (actualWorkspace !== expectedWorkspace) {
|
|
555
|
+
throw new Error(
|
|
556
|
+
`Device authorization URL workspace mismatch for ${fieldName}: expected ${expectedWorkspace}, got ${actualWorkspace || "(missing)"}. Refusing to print a potentially wrong authorization link.`
|
|
557
|
+
);
|
|
558
|
+
}
|
|
559
|
+
}
|
|
518
560
|
async function runBrowserLogin(options) {
|
|
519
561
|
const state = randomBytes(16).toString("hex");
|
|
520
562
|
const timeoutMs = options.timeoutMs ?? 5 * 60 * 1e3;
|
|
563
|
+
const origin = normalizeOriginForLint(options.origin);
|
|
564
|
+
const workspace = normalizeDeviceWorkspace(options.workspace);
|
|
521
565
|
return await new Promise((resolve, reject) => {
|
|
522
566
|
const server = createServer(async (req, res) => {
|
|
523
567
|
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
@@ -574,7 +618,7 @@ async function runBrowserLogin(options) {
|
|
|
574
618
|
return;
|
|
575
619
|
}
|
|
576
620
|
const callbackUrl = `http://127.0.0.1:${address.port}/callback`;
|
|
577
|
-
const bridgeUrl = buildBridgeUrl(
|
|
621
|
+
const bridgeUrl = buildBridgeUrl(origin, workspace, {
|
|
578
622
|
callback: callbackUrl,
|
|
579
623
|
state,
|
|
580
624
|
profile: options.profileName,
|
|
@@ -628,21 +672,28 @@ function numberField(value, name, fallback) {
|
|
|
628
672
|
async function startDeviceLogin(options) {
|
|
629
673
|
const agent = options.agent || "generic";
|
|
630
674
|
const channel = options.channel || "json";
|
|
631
|
-
const
|
|
675
|
+
const origin = normalizeOriginForLint(options.origin);
|
|
676
|
+
const workspace = normalizeDeviceWorkspace(options.workspace);
|
|
677
|
+
const request = options.request || createDeviceRequest(origin);
|
|
632
678
|
const response = await request("POST", "/cli/device_authorizations", {
|
|
633
679
|
data: {
|
|
634
|
-
workspace
|
|
680
|
+
workspace,
|
|
635
681
|
profile: options.profileName,
|
|
636
682
|
key_name: options.apiKeyName,
|
|
637
683
|
agent,
|
|
638
684
|
channel,
|
|
639
|
-
origin
|
|
685
|
+
origin
|
|
640
686
|
}
|
|
641
687
|
});
|
|
642
688
|
const expiresIn = numberField(response.expires_in, "expires_in");
|
|
643
689
|
const now = options.now?.() || /* @__PURE__ */ new Date();
|
|
644
690
|
const verificationUri = stringField(response.verification_uri, "verification_uri");
|
|
691
|
+
lintDeviceAuthorizationUrl(verificationUri, origin, workspace, "verification_uri");
|
|
645
692
|
const verificationUriComplete = typeof response.verification_uri_complete === "string" && response.verification_uri_complete.trim() ? response.verification_uri_complete : void 0;
|
|
693
|
+
if (verificationUriComplete) {
|
|
694
|
+
lintDeviceAuthorizationUrl(verificationUriComplete, origin, workspace, "verification_uri_complete");
|
|
695
|
+
}
|
|
696
|
+
const authorizationUrl = verificationUriComplete || verificationUri;
|
|
646
697
|
return {
|
|
647
698
|
profile: options.profileName,
|
|
648
699
|
agent,
|
|
@@ -651,7 +702,7 @@ async function startDeviceLogin(options) {
|
|
|
651
702
|
user_code: stringField(response.user_code, "user_code"),
|
|
652
703
|
verification_uri: verificationUri,
|
|
653
704
|
verification_uri_complete: verificationUriComplete,
|
|
654
|
-
authorization_url:
|
|
705
|
+
authorization_url: authorizationUrl,
|
|
655
706
|
expires_in: expiresIn,
|
|
656
707
|
interval: numberField(response.interval, "interval", 5),
|
|
657
708
|
expires_at: new Date(now.getTime() + expiresIn * 1e3).toISOString()
|
|
@@ -905,7 +956,7 @@ import { readFile as readFile5 } from "fs/promises";
|
|
|
905
956
|
// package.json
|
|
906
957
|
var package_default = {
|
|
907
958
|
name: "bpmax-cli",
|
|
908
|
-
version: "0.1.
|
|
959
|
+
version: "0.1.42",
|
|
909
960
|
description: "CLI for BPMAX environments with multi-profile config and local login callback flow",
|
|
910
961
|
type: "module",
|
|
911
962
|
bin: {
|