@clavis.nexus/setup 1.0.1 → 1.0.2
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/README.md +6 -0
- package/dist/cli.js +228 -149
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +201 -142
- package/dist/index.js.map +1 -1
- package/dist/mcp.js +215 -145
- package/dist/mcp.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -70,8 +70,11 @@ type CreateSetupClientOptions = {
|
|
|
70
70
|
type SetupClient = {
|
|
71
71
|
origins: SetupOrigins;
|
|
72
72
|
getSession(): Promise<DevelopersSession | null>;
|
|
73
|
-
login(
|
|
73
|
+
login(opts?: {
|
|
74
|
+
bridgeJson?: string;
|
|
75
|
+
}): Promise<SetupResult<{
|
|
74
76
|
sub?: string;
|
|
77
|
+
pending?: true;
|
|
75
78
|
}>>;
|
|
76
79
|
logout(): Promise<SetupResult<{
|
|
77
80
|
cleared: true;
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { execFile } from 'child_process';
|
|
2
2
|
import { promisify } from 'util';
|
|
3
3
|
import { readFile, mkdir, writeFile, chmod, unlink } from 'fs/promises';
|
|
4
|
-
import { join, dirname } from 'path';
|
|
4
|
+
import path, { join, dirname } from 'path';
|
|
5
5
|
import { homedir } from 'os';
|
|
6
6
|
import { generateKeyPair, exportJWK, createRemoteJWKSet, jwtVerify } from 'jose';
|
|
7
|
-
import {
|
|
7
|
+
import { createInterface } from 'readline/promises';
|
|
8
|
+
import { stdin, stdout } from 'process';
|
|
8
9
|
import { randomBytes } from 'crypto';
|
|
9
10
|
|
|
10
11
|
// src/browser.ts
|
|
@@ -96,12 +97,12 @@ function stableStringify(v) {
|
|
|
96
97
|
}
|
|
97
98
|
|
|
98
99
|
// src/digests.ts
|
|
99
|
-
async function computeOrgPolicyBootstrapDigest(
|
|
100
|
+
async function computeOrgPolicyBootstrapDigest(input2) {
|
|
100
101
|
return sha256Base64Url(
|
|
101
102
|
canonicalStringify({
|
|
102
|
-
org_id:
|
|
103
|
-
primary_domain:
|
|
104
|
-
owner_sub:
|
|
103
|
+
org_id: input2.org_id.trim(),
|
|
104
|
+
primary_domain: input2.primary_domain.trim().toLowerCase(),
|
|
105
|
+
owner_sub: input2.owner_sub.trim()
|
|
105
106
|
})
|
|
106
107
|
);
|
|
107
108
|
}
|
|
@@ -112,21 +113,21 @@ async function computePayloadCommitmentHex(payload) {
|
|
|
112
113
|
}
|
|
113
114
|
return sha256HexUtf8(canonicalStringify(o));
|
|
114
115
|
}
|
|
115
|
-
async function computeOrgAppRegisterDigest(
|
|
116
|
+
async function computeOrgAppRegisterDigest(input2) {
|
|
116
117
|
return sha256Base64Url(
|
|
117
118
|
canonicalStringify({
|
|
118
|
-
payload_hash:
|
|
119
|
-
proposer_sub:
|
|
119
|
+
payload_hash: input2.payload_hash.trim().toLowerCase(),
|
|
120
|
+
proposer_sub: input2.proposer_sub.trim()
|
|
120
121
|
})
|
|
121
122
|
);
|
|
122
123
|
}
|
|
123
|
-
async function computeOrgAppVerifyHostDigest(
|
|
124
|
+
async function computeOrgAppVerifyHostDigest(input2) {
|
|
124
125
|
return sha256Base64Url(
|
|
125
126
|
canonicalStringify({
|
|
126
|
-
app_id:
|
|
127
|
-
host:
|
|
128
|
-
nonce:
|
|
129
|
-
org_id:
|
|
127
|
+
app_id: input2.app_id.trim(),
|
|
128
|
+
host: input2.host.trim().toLowerCase(),
|
|
129
|
+
nonce: input2.nonce.trim(),
|
|
130
|
+
org_id: input2.org_id.trim()
|
|
130
131
|
})
|
|
131
132
|
);
|
|
132
133
|
}
|
|
@@ -139,13 +140,13 @@ async function computeOrgAppDeclarationHash(declaration) {
|
|
|
139
140
|
})
|
|
140
141
|
);
|
|
141
142
|
}
|
|
142
|
-
async function computeOrgAppDeclarationDigest(
|
|
143
|
+
async function computeOrgAppDeclarationDigest(input2) {
|
|
143
144
|
return sha256Base64Url(
|
|
144
145
|
canonicalStringify({
|
|
145
|
-
org_id:
|
|
146
|
-
app_id:
|
|
147
|
-
declaration_hash:
|
|
148
|
-
actor_sub:
|
|
146
|
+
org_id: input2.org_id.trim(),
|
|
147
|
+
app_id: input2.app_id.trim(),
|
|
148
|
+
declaration_hash: input2.declaration_hash.trim(),
|
|
149
|
+
actor_sub: input2.actor_sub.trim()
|
|
149
150
|
})
|
|
150
151
|
);
|
|
151
152
|
}
|
|
@@ -242,8 +243,8 @@ var SetupApiError = class extends Error {
|
|
|
242
243
|
this.code = code;
|
|
243
244
|
}
|
|
244
245
|
};
|
|
245
|
-
async function apiJson(apiOrigin,
|
|
246
|
-
const res = await fetch(`${apiOrigin.replace(/\/+$/, "")}${
|
|
246
|
+
async function apiJson(apiOrigin, path2, opts) {
|
|
247
|
+
const res = await fetch(`${apiOrigin.replace(/\/+$/, "")}${path2}`, {
|
|
247
248
|
method: opts.method ?? "GET",
|
|
248
249
|
headers: {
|
|
249
250
|
Accept: "application/json",
|
|
@@ -382,25 +383,25 @@ function appEnvFilePath(appId) {
|
|
|
382
383
|
const base = process.env.CLAVIS_OPERATE_KEYS_DIR?.trim() || join(homedir(), ".config", "clavis", "apps");
|
|
383
384
|
return join(base, app, "app.env");
|
|
384
385
|
}
|
|
385
|
-
async function restrictFileMode(
|
|
386
|
+
async function restrictFileMode(path2) {
|
|
386
387
|
try {
|
|
387
|
-
await chmod(
|
|
388
|
+
await chmod(path2, 384);
|
|
388
389
|
} catch (e) {
|
|
389
390
|
console.warn(
|
|
390
|
-
`clavis: could not set mode 0600 on ${
|
|
391
|
+
`clavis: could not set mode 0600 on ${path2}: ${e instanceof Error ? e.message : e}`
|
|
391
392
|
);
|
|
392
393
|
}
|
|
393
394
|
}
|
|
394
395
|
async function saveOperatePrivateJwk(appId, jwkJson) {
|
|
395
|
-
const
|
|
396
|
-
await mkdir(dirname(
|
|
397
|
-
await writeFile(
|
|
398
|
-
await restrictFileMode(
|
|
396
|
+
const path2 = operatePrivateJwkPath(appId);
|
|
397
|
+
await mkdir(dirname(path2), { recursive: true });
|
|
398
|
+
await writeFile(path2, jwkJson.trim(), "utf8");
|
|
399
|
+
await restrictFileMode(path2);
|
|
399
400
|
try {
|
|
400
|
-
await chmod(dirname(
|
|
401
|
+
await chmod(dirname(path2), 448);
|
|
401
402
|
} catch {
|
|
402
403
|
}
|
|
403
|
-
return
|
|
404
|
+
return path2;
|
|
404
405
|
}
|
|
405
406
|
async function readOperatePrivateJwk(appId) {
|
|
406
407
|
try {
|
|
@@ -411,12 +412,12 @@ async function readOperatePrivateJwk(appId) {
|
|
|
411
412
|
}
|
|
412
413
|
}
|
|
413
414
|
async function writeAppEnvFile(appId, contents) {
|
|
414
|
-
const
|
|
415
|
-
await mkdir(dirname(
|
|
416
|
-
await writeFile(
|
|
415
|
+
const path2 = appEnvFilePath(appId);
|
|
416
|
+
await mkdir(dirname(path2), { recursive: true });
|
|
417
|
+
await writeFile(path2, contents.endsWith("\n") ? contents : `${contents}
|
|
417
418
|
`, "utf8");
|
|
418
|
-
await restrictFileMode(
|
|
419
|
-
return
|
|
419
|
+
await restrictFileMode(path2);
|
|
420
|
+
return path2;
|
|
420
421
|
}
|
|
421
422
|
|
|
422
423
|
// src/emit-env.ts
|
|
@@ -495,9 +496,9 @@ function originsFromEnv(overrides) {
|
|
|
495
496
|
developersOrigin: overrides?.developersOrigin ?? process.env.CLAVIS_DEVELOPERS_ORIGIN?.trim() ?? DEFAULT_ORIGINS.developersOrigin
|
|
496
497
|
};
|
|
497
498
|
}
|
|
498
|
-
async function loadSession(
|
|
499
|
+
async function loadSession(path2 = defaultSessionPath()) {
|
|
499
500
|
try {
|
|
500
|
-
const raw = await readFile(
|
|
501
|
+
const raw = await readFile(path2, "utf8");
|
|
501
502
|
const parsed = JSON.parse(raw);
|
|
502
503
|
if (parsed?.v !== 1 || typeof parsed.session?.accessToken !== "string") return null;
|
|
503
504
|
if (parsed.session.expiresAt && parsed.session.expiresAt * 1e3 < Date.now()) return null;
|
|
@@ -506,50 +507,30 @@ async function loadSession(path = defaultSessionPath()) {
|
|
|
506
507
|
return null;
|
|
507
508
|
}
|
|
508
509
|
}
|
|
509
|
-
async function saveSession(session, origins,
|
|
510
|
-
await mkdir(dirname(
|
|
510
|
+
async function saveSession(session, origins, path2 = defaultSessionPath()) {
|
|
511
|
+
await mkdir(dirname(path2), { recursive: true });
|
|
511
512
|
const body = { v: 1, origins, session, savedAt: Date.now() };
|
|
512
|
-
await writeFile(
|
|
513
|
+
await writeFile(path2, JSON.stringify(body, null, 2), "utf8");
|
|
513
514
|
try {
|
|
514
|
-
await chmod(
|
|
515
|
+
await chmod(path2, 384);
|
|
515
516
|
} catch (e) {
|
|
516
517
|
console.warn(
|
|
517
|
-
`clavis: could not set session file mode 0600 (${
|
|
518
|
+
`clavis: could not set session file mode 0600 (${path2}): ${e instanceof Error ? e.message : e}`
|
|
518
519
|
);
|
|
519
520
|
}
|
|
520
521
|
}
|
|
521
|
-
async function clearSession(
|
|
522
|
+
async function clearSession(path2 = defaultSessionPath()) {
|
|
522
523
|
try {
|
|
523
|
-
await unlink(
|
|
524
|
+
await unlink(path2);
|
|
524
525
|
} catch {
|
|
525
526
|
}
|
|
526
527
|
}
|
|
527
528
|
|
|
528
529
|
// src/login.ts
|
|
529
|
-
var
|
|
530
|
-
function
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
let total = 0;
|
|
534
|
-
req.on("data", (c) => {
|
|
535
|
-
const buf = Buffer.isBuffer(c) ? c : Buffer.from(c);
|
|
536
|
-
total += buf.length;
|
|
537
|
-
if (total > MAX_CALLBACK_BODY_BYTES) {
|
|
538
|
-
reject(new Error("callback body too large"));
|
|
539
|
-
req.destroy();
|
|
540
|
-
return;
|
|
541
|
-
}
|
|
542
|
-
chunks.push(buf);
|
|
543
|
-
});
|
|
544
|
-
req.on("end", () => resolve(Buffer.concat(chunks).toString("utf8")));
|
|
545
|
-
req.on("error", reject);
|
|
546
|
-
});
|
|
547
|
-
}
|
|
548
|
-
function cors(res, developersOrigin) {
|
|
549
|
-
res.setHeader("Access-Control-Allow-Origin", developersOrigin);
|
|
550
|
-
res.setHeader("Access-Control-Allow-Methods", "POST, OPTIONS");
|
|
551
|
-
res.setHeader("Access-Control-Allow-Headers", "Content-Type");
|
|
552
|
-
res.setHeader("Vary", "Origin");
|
|
530
|
+
var MAX_BRIDGE_JSON_CHARS = 16384;
|
|
531
|
+
function pendingLoginPath(sessionPath) {
|
|
532
|
+
const base = sessionPath ? path.dirname(sessionPath) : path.dirname(defaultSessionPath());
|
|
533
|
+
return path.join(base, "login-pending.json");
|
|
553
534
|
}
|
|
554
535
|
function subFromJwt(accessToken) {
|
|
555
536
|
try {
|
|
@@ -562,85 +543,148 @@ function subFromJwt(accessToken) {
|
|
|
562
543
|
return void 0;
|
|
563
544
|
}
|
|
564
545
|
}
|
|
546
|
+
function loginBridgeUrl(developersOrigin, state) {
|
|
547
|
+
const bridge = new URL("/developers/setup/login", developersOrigin);
|
|
548
|
+
bridge.searchParams.set("state", state);
|
|
549
|
+
return bridge.toString();
|
|
550
|
+
}
|
|
551
|
+
async function writePending(pendingPath, pending) {
|
|
552
|
+
await mkdir(path.dirname(pendingPath), { recursive: true, mode: 448 });
|
|
553
|
+
await writeFile(pendingPath, `${JSON.stringify(pending, null, 2)}
|
|
554
|
+
`, { mode: 384 });
|
|
555
|
+
}
|
|
556
|
+
async function readPending(pendingPath) {
|
|
557
|
+
try {
|
|
558
|
+
const raw = await readFile(pendingPath, "utf8");
|
|
559
|
+
const parsed = JSON.parse(raw);
|
|
560
|
+
if (parsed?.v !== 1 || typeof parsed.state !== "string" || !parsed.state) return null;
|
|
561
|
+
return parsed;
|
|
562
|
+
} catch {
|
|
563
|
+
return null;
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
async function clearPending(pendingPath) {
|
|
567
|
+
try {
|
|
568
|
+
await unlink(pendingPath);
|
|
569
|
+
} catch {
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
function parseBridgePayload(raw) {
|
|
573
|
+
const trimmed = raw.trim();
|
|
574
|
+
if (!trimmed) throw new Error("empty_bridge_json");
|
|
575
|
+
if (trimmed.length > MAX_BRIDGE_JSON_CHARS) throw new Error("bridge_json_too_large");
|
|
576
|
+
const body = JSON.parse(trimmed);
|
|
577
|
+
if (typeof body !== "object" || body === null || Array.isArray(body)) {
|
|
578
|
+
throw new Error("bridge_json_not_object");
|
|
579
|
+
}
|
|
580
|
+
return body;
|
|
581
|
+
}
|
|
582
|
+
async function sessionFromBridge(args) {
|
|
583
|
+
const body = parseBridgePayload(args.raw);
|
|
584
|
+
if (body.state !== args.expectedState || typeof body.accessToken !== "string" || !body.accessToken) {
|
|
585
|
+
throw new Error("invalid_bridge_json");
|
|
586
|
+
}
|
|
587
|
+
await verifyDevelopersAccessToken(body.accessToken, args.apiOrigin);
|
|
588
|
+
const sub = typeof body.sub === "string" ? body.sub : subFromJwt(body.accessToken);
|
|
589
|
+
return {
|
|
590
|
+
accessToken: body.accessToken,
|
|
591
|
+
...sub ? { sub } : {},
|
|
592
|
+
...typeof body.expiresAt === "number" ? { expiresAt: body.expiresAt } : {}
|
|
593
|
+
};
|
|
594
|
+
}
|
|
595
|
+
async function readBridgeJsonFromStdin() {
|
|
596
|
+
if (!stdin.isTTY) {
|
|
597
|
+
const chunks = [];
|
|
598
|
+
for await (const chunk of stdin) {
|
|
599
|
+
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
|
|
600
|
+
}
|
|
601
|
+
return Buffer.concat(chunks).toString("utf8");
|
|
602
|
+
}
|
|
603
|
+
const rl = createInterface({ input: stdin, output: stdout });
|
|
604
|
+
try {
|
|
605
|
+
stdout.write(
|
|
606
|
+
"Paste the JSON shown on developers /setup/login, then press Enter.\n(End with a blank line if the paste spans multiple lines.)\n"
|
|
607
|
+
);
|
|
608
|
+
const lines = [];
|
|
609
|
+
for (; ; ) {
|
|
610
|
+
const line = await rl.question("");
|
|
611
|
+
if (line.trim() === "" && lines.length > 0) break;
|
|
612
|
+
lines.push(line);
|
|
613
|
+
const joined = lines.join("\n").trim();
|
|
614
|
+
if (joined.startsWith("{") && joined.endsWith("}")) break;
|
|
615
|
+
}
|
|
616
|
+
return lines.join("\n");
|
|
617
|
+
} finally {
|
|
618
|
+
rl.close();
|
|
619
|
+
}
|
|
620
|
+
}
|
|
565
621
|
async function loginWithBrowser(args) {
|
|
566
|
-
const
|
|
567
|
-
const
|
|
568
|
-
|
|
569
|
-
const
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
try {
|
|
582
|
-
const raw = await readBody(req);
|
|
583
|
-
const body = JSON.parse(raw);
|
|
584
|
-
if (body.state !== state || typeof body.accessToken !== "string" || !body.accessToken) {
|
|
585
|
-
res.writeHead(400, { "Content-Type": "application/json" });
|
|
586
|
-
res.end(JSON.stringify({ ok: false, error: "invalid_callback" }));
|
|
587
|
-
return;
|
|
588
|
-
}
|
|
589
|
-
try {
|
|
590
|
-
await verifyDevelopersAccessToken(body.accessToken, args.origins.apiOrigin);
|
|
591
|
-
} catch {
|
|
592
|
-
res.writeHead(400, { "Content-Type": "application/json" });
|
|
593
|
-
res.end(JSON.stringify({ ok: false, error: "invalid_token" }));
|
|
594
|
-
return;
|
|
595
|
-
}
|
|
596
|
-
const sub = typeof body.sub === "string" ? body.sub : subFromJwt(body.accessToken);
|
|
597
|
-
const next = {
|
|
598
|
-
accessToken: body.accessToken,
|
|
599
|
-
...sub ? { sub } : {},
|
|
600
|
-
...typeof body.expiresAt === "number" ? { expiresAt: body.expiresAt } : {}
|
|
601
|
-
};
|
|
602
|
-
res.writeHead(200, { "Content-Type": "application/json" });
|
|
603
|
-
res.end(JSON.stringify({ ok: true }));
|
|
604
|
-
server.close();
|
|
605
|
-
resolve(next);
|
|
606
|
-
} catch (e) {
|
|
607
|
-
res.writeHead(500, { "Content-Type": "application/json" });
|
|
608
|
-
res.end(JSON.stringify({ ok: false }));
|
|
609
|
-
server.close();
|
|
610
|
-
reject(e);
|
|
611
|
-
}
|
|
622
|
+
const pendingPath = pendingLoginPath(args.sessionPath);
|
|
623
|
+
const openFlag = args.open !== false;
|
|
624
|
+
if (args.bridgeJson?.trim()) {
|
|
625
|
+
const pending = await readPending(pendingPath);
|
|
626
|
+
if (!pending) {
|
|
627
|
+
throw new Error("no_pending_login \u2014 run login again to open the browser first");
|
|
628
|
+
}
|
|
629
|
+
if (pending.apiOrigin !== args.origins.apiOrigin || pending.developersOrigin !== args.origins.developersOrigin) {
|
|
630
|
+
await clearPending(pendingPath);
|
|
631
|
+
throw new Error("pending_login_origin_mismatch \u2014 run login again");
|
|
632
|
+
}
|
|
633
|
+
const session2 = await sessionFromBridge({
|
|
634
|
+
raw: args.bridgeJson,
|
|
635
|
+
expectedState: pending.state,
|
|
636
|
+
apiOrigin: args.origins.apiOrigin
|
|
612
637
|
});
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
638
|
+
await saveSession(session2, args.origins, args.sessionPath);
|
|
639
|
+
await clearPending(pendingPath);
|
|
640
|
+
return {
|
|
641
|
+
session: session2,
|
|
642
|
+
human: {
|
|
643
|
+
needs_human: "login",
|
|
644
|
+
message: "Session stored.",
|
|
645
|
+
open_url: loginBridgeUrl(args.origins.developersOrigin, pending.state)
|
|
618
646
|
}
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
}
|
|
635
|
-
|
|
647
|
+
};
|
|
648
|
+
}
|
|
649
|
+
const state = randomBytes(16).toString("hex");
|
|
650
|
+
const openUrl = loginBridgeUrl(args.origins.developersOrigin, state);
|
|
651
|
+
await writePending(pendingPath, {
|
|
652
|
+
v: 1,
|
|
653
|
+
state,
|
|
654
|
+
createdAt: Date.now(),
|
|
655
|
+
developersOrigin: args.origins.developersOrigin,
|
|
656
|
+
apiOrigin: args.origins.apiOrigin
|
|
657
|
+
});
|
|
658
|
+
if (openFlag) {
|
|
659
|
+
try {
|
|
660
|
+
await openBrowser(assertOriginBrowserUrl(openUrl, args.origins.developersOrigin));
|
|
661
|
+
} catch {
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
if (args.deferPaste) {
|
|
665
|
+
return {
|
|
666
|
+
pending: true,
|
|
667
|
+
human: {
|
|
668
|
+
needs_human: "login",
|
|
669
|
+
message: "Complete Passkey in the browser, copy the JSON on the page, then call login again with bridge_json.",
|
|
670
|
+
open_url: openUrl
|
|
671
|
+
}
|
|
672
|
+
};
|
|
673
|
+
}
|
|
674
|
+
const raw = await readBridgeJsonFromStdin();
|
|
675
|
+
const session = await sessionFromBridge({
|
|
676
|
+
raw,
|
|
677
|
+
expectedState: state,
|
|
678
|
+
apiOrigin: args.origins.apiOrigin
|
|
636
679
|
});
|
|
637
|
-
await saveSession(session, args.origins);
|
|
680
|
+
await saveSession(session, args.origins, args.sessionPath);
|
|
681
|
+
await clearPending(pendingPath);
|
|
638
682
|
return {
|
|
639
683
|
session,
|
|
640
684
|
human: {
|
|
641
685
|
needs_human: "login",
|
|
642
|
-
message: "
|
|
643
|
-
open_url:
|
|
686
|
+
message: "Session stored. You can close the browser tab.",
|
|
687
|
+
open_url: openUrl
|
|
644
688
|
}
|
|
645
689
|
};
|
|
646
690
|
}
|
|
@@ -782,9 +826,24 @@ function createSetupClient(options = {}) {
|
|
|
782
826
|
const s = await loadSession(sessionPath);
|
|
783
827
|
return s?.session ?? null;
|
|
784
828
|
},
|
|
785
|
-
async login() {
|
|
786
|
-
const
|
|
787
|
-
|
|
829
|
+
async login(opts) {
|
|
830
|
+
const bridgeJson = opts?.bridgeJson?.trim();
|
|
831
|
+
const deferPaste = !bridgeJson && !process.stdin.isTTY;
|
|
832
|
+
const out = await loginWithBrowser({
|
|
833
|
+
origins,
|
|
834
|
+
open: openBrowserFlag,
|
|
835
|
+
...bridgeJson ? { bridgeJson } : {},
|
|
836
|
+
...deferPaste ? { deferPaste: true } : {},
|
|
837
|
+
sessionPath
|
|
838
|
+
});
|
|
839
|
+
if (out.pending || !out.session) {
|
|
840
|
+
return {
|
|
841
|
+
ok: false,
|
|
842
|
+
error: "login_pending_paste",
|
|
843
|
+
human: out.human
|
|
844
|
+
};
|
|
845
|
+
}
|
|
846
|
+
return { ok: true, data: { sub: out.session.sub } };
|
|
788
847
|
},
|
|
789
848
|
async logout() {
|
|
790
849
|
await clearSession(sessionPath);
|