passport-bridge 0.16.13 → 0.17.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/README.md +20 -20
- package/dist/bridgeExchange.d.ts +7 -1
- package/dist/bridgeExchange.js +11 -2
- package/dist/cli.js +3 -1
- package/dist/cliActions.js +38 -18
- package/dist/cliArgs.js +14 -9
- package/dist/cliAutopilot.js +36 -21
- package/dist/cliAutopilotPolicy.d.ts +22 -0
- package/dist/cliAutopilotPolicy.js +61 -0
- package/dist/cliConnect.js +8 -7
- package/dist/cliDeadline.js +2 -1
- package/dist/cliDescribe.d.ts +4 -0
- package/dist/cliDescribe.js +11 -0
- package/dist/cliEnv.js +5 -4
- package/dist/cliExec.js +13 -5
- package/dist/cliGuardState.d.ts +2 -0
- package/dist/cliGuardState.js +5 -1
- package/dist/cliHelp.d.ts +5 -4
- package/dist/cliHelp.js +2 -27
- package/dist/cliHook.js +6 -2
- package/dist/cliHookGuard.js +5 -11
- package/dist/cliHookInstall.d.ts +3 -0
- package/dist/cliHookInstall.js +17 -7
- package/dist/cliHookStatus.d.ts +2 -1
- package/dist/cliHookStatus.js +26 -17
- package/dist/cliInit.js +5 -3
- package/dist/cliKeys.d.ts +3 -0
- package/dist/cliKeys.js +59 -77
- package/dist/cliKeysShim.js +7 -5
- package/dist/cliLogin.js +44 -24
- package/dist/cliLogout.js +24 -8
- package/dist/cliMain.js +50 -22
- package/dist/cliMemberCall.js +1 -1
- package/dist/cliOffline.d.ts +2 -2
- package/dist/cliOffline.js +32 -9
- package/dist/cliOutput.js +73 -43
- package/dist/cliReady.d.ts +2 -1
- package/dist/cliReady.js +9 -6
- package/dist/cliResult.js +1 -1
- package/dist/cliScan.js +10 -28
- package/dist/cliScriptRead.d.ts +1 -1
- package/dist/cliScriptRead.js +2 -2
- package/dist/cliSessions.d.ts +3 -2
- package/dist/cliSessions.js +19 -17
- package/dist/cliSetup.js +6 -4
- package/dist/cliSetupLock.js +2 -1
- package/dist/cliSetupOrg.js +7 -5
- package/dist/cliStatus.d.ts +2 -4
- package/dist/cliStatus.js +56 -61
- package/dist/cliSuggest.d.ts +3 -2
- package/dist/cliSuggest.js +19 -6
- package/dist/cliSupport.d.ts +1 -1
- package/dist/cliSupport.js +3 -7
- package/dist/cliSync.js +2 -0
- package/dist/cliUndo.d.ts +3 -1
- package/dist/cliUndo.js +14 -11
- package/dist/cliWait.d.ts +3 -2
- package/dist/cliWait.js +10 -18
- package/dist/doctor.d.ts +4 -1
- package/dist/doctor.js +48 -29
- package/dist/execNoKey.d.ts +1 -1
- package/dist/execNoKey.js +3 -2
- package/dist/execShims.js +2 -2
- package/dist/hookFastPath.js +1 -0
- package/dist/initAutopilotStep.js +5 -4
- package/dist/initInstall.js +4 -3
- package/dist/initKeysStep.js +1 -1
- package/dist/initLocalSteps.d.ts +2 -1
- package/dist/initLocalSteps.js +10 -7
- package/dist/initOutro.d.ts +1 -3
- package/dist/initOutro.js +8 -16
- package/dist/initPlan.js +7 -7
- package/dist/initUi.d.ts +2 -4
- package/dist/initUi.js +8 -17
- package/dist/keysLocal.js +3 -3
- package/dist/keysSecret.d.ts +6 -0
- package/dist/keysSecret.js +43 -0
- package/dist/launcherFastPath.js +1 -0
- package/dist/lockedHooks.d.ts +1 -1
- package/dist/lockedHooks.js +1 -1
- package/dist/loginFlow.d.ts +1 -1
- package/dist/loginFlow.js +4 -4
- package/dist/pathLines.d.ts +1 -0
- package/dist/pathLines.js +23 -0
- package/dist/pluginPin.d.ts +1 -1
- package/dist/pluginPin.js +1 -1
- package/dist/plural.d.ts +10 -0
- package/dist/plural.js +14 -0
- package/dist/term.d.ts +49 -5
- package/dist/term.js +200 -26
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/waitingLine.js +2 -1
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
package/dist/cliKeys.d.ts
CHANGED
|
@@ -65,6 +65,9 @@ export type MoveSummary = {
|
|
|
65
65
|
};
|
|
66
66
|
/** The computer's name people recognize: "Ramish's MacBook Pro", else its host. */
|
|
67
67
|
export declare function computerName(platform?: NodeJS.Platform): string;
|
|
68
|
+
/** When a key was last used: "used 3 min ago", "not used yet". `passport
|
|
69
|
+
* status` and `passport keys` say it the same way. */
|
|
70
|
+
export declare function keyUse(lastUsedAt: number | null | undefined, now: number): string;
|
|
68
71
|
/** Keys still here, by provider, and the .env files Passport leaves alone. */
|
|
69
72
|
export declare function scanCounts(scan: ScanResult): {
|
|
70
73
|
remaining: Record<string, number>;
|
package/dist/cliKeys.js
CHANGED
|
@@ -23,11 +23,15 @@ import { offerShims, shim, shimJson } from "./cliKeysShim.js";
|
|
|
23
23
|
import { findLocalKeys, removeLocalCopy } from "./keysLocal.js";
|
|
24
24
|
import { runScan } from "./scan.js";
|
|
25
25
|
import { RELEASE_KEY_QUESTION, deploysPassportWithRailway } from "./releaseTooling.js";
|
|
26
|
-
import {
|
|
26
|
+
import { listOf, processTerminal } from "./initUi.js";
|
|
27
|
+
import { readSecret } from "./keysSecret.js";
|
|
27
28
|
import { unknownSubcommand } from "./cliSuggest.js";
|
|
28
|
-
import { table, termOf } from "./term.js";
|
|
29
|
+
import { ago, layout, mark, promptRows, table, termOf } from "./term.js";
|
|
30
|
+
import { pathLines } from "./pathLines.js";
|
|
31
|
+
import { countOf } from "./plural.js";
|
|
29
32
|
export const KEYS_PATH = "/api/my/keys";
|
|
30
33
|
const KEY_CLIS = "railway|gh|vercel|wrangler|supabase|stripe|aws|neonctl|flyctl";
|
|
34
|
+
const HELD_CLIS = "railway, gh, vercel, wrangler, supabase, stripe, aws, neonctl, and flyctl";
|
|
31
35
|
const MOVABLE_PROVIDERS = new Set(["Railway", "GitHub", "Vercel", "Cloudflare", "Supabase", "Stripe", "AWS"]);
|
|
32
36
|
const ENV_FILE_LOCATION = /(?:^|\/)\.env[^/ ]*(?: \(|$)/;
|
|
33
37
|
/** The computer's name people recognize: "Ramish's MacBook Pro", else its host. */
|
|
@@ -46,6 +50,11 @@ export function computerName(platform = process.platform) {
|
|
|
46
50
|
.replace(/\.local$/, "")
|
|
47
51
|
.slice(0, 60) || "This computer");
|
|
48
52
|
}
|
|
53
|
+
/** When a key was last used: "used 3 min ago", "not used yet". `passport
|
|
54
|
+
* status` and `passport keys` say it the same way. */
|
|
55
|
+
export function keyUse(lastUsedAt, now) {
|
|
56
|
+
return lastUsedAt ? `used ${ago(now - lastUsedAt)}` : "not used yet";
|
|
57
|
+
}
|
|
49
58
|
/** Keys still here, by provider, and the .env files Passport leaves alone. */
|
|
50
59
|
export function scanCounts(scan) {
|
|
51
60
|
const remaining = {};
|
|
@@ -127,7 +136,7 @@ async function mayReplace(io, vendor) {
|
|
|
127
136
|
}
|
|
128
137
|
/** Without a person at a terminal, a key Passport holds is never replaced. */
|
|
129
138
|
export function replaceNeedsTerminal(vendor) {
|
|
130
|
-
return `Replacing a key in Passport needs you at a terminal
|
|
139
|
+
return `Replacing a key in Passport needs you at a terminal.\nRun: passport keys move ${vendor}`;
|
|
131
140
|
}
|
|
132
141
|
export async function moveKeys(io) {
|
|
133
142
|
const summary = {
|
|
@@ -163,7 +172,7 @@ export async function moveKeys(io) {
|
|
|
163
172
|
}
|
|
164
173
|
releaseAnswered = true;
|
|
165
174
|
}
|
|
166
|
-
const question = `
|
|
175
|
+
const question = `Move your ${key.label} into Passport and ${key.removalWords}?`;
|
|
167
176
|
if (!releaseAnswered && !io.yes && !(await io.confirm(question))) {
|
|
168
177
|
summary.kept.push({ vendor: key.vendor, label: key.label });
|
|
169
178
|
io.result("skip", `${name}: left on this computer`);
|
|
@@ -248,7 +257,7 @@ export function summaryLines(summary) {
|
|
|
248
257
|
const lines = [];
|
|
249
258
|
const names = [...new Set(summary.moved.map((entry) => EXEC_VENDOR_NAMES[entry.vendor]))];
|
|
250
259
|
if (names.length) {
|
|
251
|
-
lines.push(`Moved ${summary.moved.length
|
|
260
|
+
lines.push(`Moved ${countOf(summary.moved.length, "key")} to Passport: ${listOf(names)}. Agents use ${summary.moved.length === 1 ? "it" : "them"} through passport exec.`);
|
|
252
261
|
}
|
|
253
262
|
else if (!summary.failed.length) {
|
|
254
263
|
lines.push(summary.kept.length || summary.unholdable.length
|
|
@@ -318,7 +327,7 @@ function apiFor(args, runtime, deps) {
|
|
|
318
327
|
return deps.api;
|
|
319
328
|
const auth = resolveCliAuth(args, runtime.env);
|
|
320
329
|
if (auth.kind !== "profile") {
|
|
321
|
-
return failure("Keys belong to a person.
|
|
330
|
+
return failure("Keys belong to a person. Sign in, then move them.", 6, "member_profile_required", {
|
|
322
331
|
hint: "Run: passport login"
|
|
323
332
|
});
|
|
324
333
|
}
|
|
@@ -347,30 +356,32 @@ async function list(args, runtime, deps) {
|
|
|
347
356
|
const keys = Array.isArray(view.keys) ? view.keys : [];
|
|
348
357
|
const pruned = applyKeyList(profileOf(args, runtime), keys);
|
|
349
358
|
const local = findLocalKeys({ env: runtime.env, ...(deps.home ? { home: deps.home } : {}) }).filter((key) => key.secret);
|
|
350
|
-
|
|
351
|
-
|
|
359
|
+
const term = termOf((runtime.stdout ?? {}), runtime.env);
|
|
360
|
+
const now = Date.now();
|
|
361
|
+
// One aligned row per key: when agents last used it (said as `passport
|
|
362
|
+
// status` says it), how often this week, and how Passport hands it out when
|
|
363
|
+
// that isn't the stored key itself.
|
|
352
364
|
const rows = keys.map((key) => {
|
|
353
365
|
const label = ` ${String(key.label ?? "Key")}`;
|
|
354
|
-
if (key.status === "broken")
|
|
355
|
-
return [label, "
|
|
366
|
+
if (key.status === "broken") {
|
|
367
|
+
return [label, `${mark(term, "warn")} not working · ${key.statusMessage ?? "Update it in Apps."}`];
|
|
368
|
+
}
|
|
356
369
|
const uses = Number(key.usesThisWeek ?? 0);
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
key.issuance && key.issuance !== "stored" ? (key.issuanceLabel ?? "") : ""
|
|
361
|
-
];
|
|
370
|
+
const last = typeof key.lastUsedAt === "number" ? keyUse(key.lastUsedAt, now) : uses ? "used" : keyUse(null, now);
|
|
371
|
+
const issued = key.issuance && key.issuance !== "stored" ? (key.issuanceLabel ?? "") : "";
|
|
372
|
+
return [label, [last, uses ? `${countOf(uses, "time")} this week` : "", issued].filter(Boolean).join(" · ")];
|
|
362
373
|
});
|
|
363
|
-
const width = termOf((runtime.stdout ?? {}), runtime.env).width;
|
|
364
374
|
const lines = keys.length
|
|
365
|
-
? ["In Passport:", ...table(rows, width, { indent: "
|
|
375
|
+
? ["In Passport:", ...table(rows, term.width, { indent: " " })]
|
|
366
376
|
: ["No keys in Passport yet."];
|
|
367
377
|
if (local.length) {
|
|
368
378
|
const names = listOf([...new Set(local.map((key) => EXEC_VENDOR_NAMES[key.vendor]))]);
|
|
369
|
-
lines.push(`Still on this computer: ${names}
|
|
379
|
+
lines.push(`Still on this computer: ${names}.`, "Run: passport keys move");
|
|
370
380
|
}
|
|
371
381
|
const shims = listShims(runtime.env);
|
|
372
382
|
if (shims.length) {
|
|
373
|
-
|
|
383
|
+
const typed = listOf(shims.map((shim) => shim.binary));
|
|
384
|
+
lines.push(`Typing ${typed} ${shims.length === 1 ? "runs" : "run"} ${shims.length === 1 ? "it" : "them"} through Passport.`);
|
|
374
385
|
}
|
|
375
386
|
const removedLine = prunedLine(pruned);
|
|
376
387
|
if (removedLine)
|
|
@@ -390,27 +401,36 @@ async function move(args, runtime, deps) {
|
|
|
390
401
|
const json = bool(args, "json");
|
|
391
402
|
const named = args.positionals[1];
|
|
392
403
|
const only = named === undefined ? undefined : execVendorOf(named);
|
|
393
|
-
if (named !== undefined && !only)
|
|
394
|
-
return failure(`Use: passport keys move [${KEY_CLIS}]
|
|
404
|
+
if (named !== undefined && !only) {
|
|
405
|
+
return failure(`Passport can't hold a ${named.replace(/[^\w.-]/g, "").slice(0, 40)} key. It holds keys for ${HELD_CLIS}.`, 6, "usage", { hint: `Use: passport keys move [${KEY_CLIS}]` });
|
|
406
|
+
}
|
|
395
407
|
const terminal = deps.terminal ?? processTerminal(runtime, process.platform, json);
|
|
396
408
|
if (!yes && !terminal.interactive) {
|
|
397
409
|
return failure("passport keys move asks before each key. Run it in a terminal, or add --yes to move them all.", 6, "usage");
|
|
398
410
|
}
|
|
399
411
|
const api = apiFor(args, runtime, deps);
|
|
400
412
|
const cwd = deps.cwd ?? process.cwd();
|
|
401
|
-
|
|
413
|
+
// Every line fits the terminal (term.ts `layout`): a marked line hangs
|
|
414
|
+
// under its text, and a command or URL is never broken.
|
|
402
415
|
const write = (text) => {
|
|
403
416
|
if (!json)
|
|
404
|
-
terminal.write(`${text}\n`);
|
|
417
|
+
terminal.write(`${layout(text, terminal.width)}\n`);
|
|
405
418
|
};
|
|
419
|
+
const done = mark(terminal, "done");
|
|
406
420
|
const local = findLocalKeys({ env: runtime.env, ...(deps.home ? { home: deps.home } : {}) }).filter((key) => !only || key.vendor === only);
|
|
407
421
|
if (local.length) {
|
|
408
422
|
write("Keys on this computer that Passport can hold:");
|
|
409
|
-
for (const
|
|
410
|
-
write(` ${
|
|
423
|
+
for (const line of table(local.map((key) => [key.label, key.location]), terminal.width, { indent: " " }))
|
|
424
|
+
write(` ${line}`);
|
|
411
425
|
write("");
|
|
412
426
|
}
|
|
413
|
-
|
|
427
|
+
// A long question wraps; its last row, with [y/N], is the prompt.
|
|
428
|
+
const prompt = (text) => {
|
|
429
|
+
const rows = promptRows(text, terminal.width);
|
|
430
|
+
for (const row of rows.rows)
|
|
431
|
+
write(row);
|
|
432
|
+
return terminal.question(rows.prompt, runtime.signal);
|
|
433
|
+
};
|
|
414
434
|
// Signing a CLI out can't be taken back from here: [y/N], Enter keeps it.
|
|
415
435
|
const ask = (question) => askYesNo(prompt, write, question, "destructive");
|
|
416
436
|
// The safe answer is the default: Enter keeps things working.
|
|
@@ -427,7 +447,7 @@ async function move(args, runtime, deps) {
|
|
|
427
447
|
// at a terminal: with --yes, or without a terminal, both keys stay.
|
|
428
448
|
...(terminal.interactive && !yes ? { replace: askName, keepHere: askYes } : {}),
|
|
429
449
|
...(only ? { only } : {}),
|
|
430
|
-
result: (kind, text) => write(` ${mark
|
|
450
|
+
result: (kind, text) => text.split("\n").forEach((line, index) => write(index ? ` ${line}` : ` ${mark(terminal, kind)} ${line}`)),
|
|
431
451
|
line: write,
|
|
432
452
|
env: runtime.env,
|
|
433
453
|
...(deps.home ? { home: deps.home } : {}),
|
|
@@ -439,12 +459,13 @@ async function move(args, runtime, deps) {
|
|
|
439
459
|
...(deps.scan ? { scan: deps.scan } : {})
|
|
440
460
|
});
|
|
441
461
|
await syncMarker(api, profileOf(args, runtime), runtime.signal);
|
|
442
|
-
const shims = await offerShims(summary.moved.map((entry) => entry.vendor), { args, runtime, deps, yes, interactive: terminal.interactive, ask: askYes, write, done
|
|
462
|
+
const shims = await offerShims(summary.moved.map((entry) => entry.vendor), { args, runtime, deps, yes, interactive: terminal.interactive, ask: askYes, write, done });
|
|
443
463
|
write("");
|
|
444
464
|
for (const line of summaryLines(summary))
|
|
445
465
|
write(line);
|
|
446
466
|
if (shims.pathLine)
|
|
447
|
-
|
|
467
|
+
for (const line of pathLines(shims.pathLine, terminal.width))
|
|
468
|
+
write(line);
|
|
448
469
|
return {
|
|
449
470
|
json: {
|
|
450
471
|
...summary,
|
|
@@ -455,53 +476,14 @@ async function move(args, runtime, deps) {
|
|
|
455
476
|
...(json ? {} : { silent: true })
|
|
456
477
|
};
|
|
457
478
|
}
|
|
458
|
-
/** Hidden input on a terminal; the whole of stdin otherwise. */
|
|
459
|
-
async function readSecret(runtime, prompt) {
|
|
460
|
-
const stdin = runtime.stdin;
|
|
461
|
-
if (!stdin)
|
|
462
|
-
return "";
|
|
463
|
-
if (!stdin.isTTY || !stdin.setRawMode) {
|
|
464
|
-
const chunks = [];
|
|
465
|
-
let bytes = 0;
|
|
466
|
-
for await (const chunk of stdin) {
|
|
467
|
-
const buffer = Buffer.from(chunk);
|
|
468
|
-
bytes += buffer.byteLength;
|
|
469
|
-
if (bytes > 16 * 1024)
|
|
470
|
-
break;
|
|
471
|
-
chunks.push(buffer);
|
|
472
|
-
}
|
|
473
|
-
return Buffer.concat(chunks).toString("utf8").trim();
|
|
474
|
-
}
|
|
475
|
-
// Keys typed before the prompt aren't part of the key.
|
|
476
|
-
if (await discardTypeAhead(stdin))
|
|
477
|
-
throw new Error("Cancelled.");
|
|
478
|
-
runtime.stderr.write(prompt);
|
|
479
|
-
stdin.setRawMode(true);
|
|
480
|
-
let value = "";
|
|
481
|
-
try {
|
|
482
|
-
for await (const chunk of stdin) {
|
|
483
|
-
for (const char of String(chunk)) {
|
|
484
|
-
if (char === "\u0003")
|
|
485
|
-
throw new Error("Cancelled.");
|
|
486
|
-
if (char === "\r" || char === "\n")
|
|
487
|
-
return value.trim();
|
|
488
|
-
if (char === "\u007f")
|
|
489
|
-
value = value.slice(0, -1);
|
|
490
|
-
else
|
|
491
|
-
value += char;
|
|
492
|
-
}
|
|
493
|
-
}
|
|
494
|
-
}
|
|
495
|
-
finally {
|
|
496
|
-
stdin.setRawMode(false);
|
|
497
|
-
runtime.stderr.write("\n");
|
|
498
|
-
}
|
|
499
|
-
return value.trim();
|
|
500
|
-
}
|
|
501
479
|
async function add(args, runtime, deps) {
|
|
502
|
-
const
|
|
503
|
-
|
|
504
|
-
|
|
480
|
+
const typed = args.positionals[1];
|
|
481
|
+
const vendor = execVendorOf(typed ?? "");
|
|
482
|
+
if (!vendor) {
|
|
483
|
+
return failure(typed
|
|
484
|
+
? `Passport can't hold a ${typed.replace(/[^\w.-]/g, "").slice(0, 40)} key. It holds keys for ${HELD_CLIS}.`
|
|
485
|
+
: `Name the CLI whose key to store. Passport holds keys for ${HELD_CLIS}.`, 6, "usage", { hint: "Run: passport keys add <cli>" });
|
|
486
|
+
}
|
|
505
487
|
const api = apiFor(args, runtime, deps);
|
|
506
488
|
const name = EXEC_VENDOR_NAMES[vendor];
|
|
507
489
|
const prompt = vendor === "aws"
|
|
@@ -540,7 +522,7 @@ async function add(args, runtime, deps) {
|
|
|
540
522
|
const binary = vendor === "flyctl" ? "fly" : vendor;
|
|
541
523
|
return {
|
|
542
524
|
json: { stored: true, vendor },
|
|
543
|
-
human: `Stored your ${name} key in Passport. Agents use it through passport exec -- ${binary}
|
|
525
|
+
human: `Stored your ${name} key in Passport. Agents use it through passport exec -- ${binary} <args>.\nTo keep typing ${binary} yourself, add a shim.\nRun: passport keys shim ${binary}`
|
|
544
526
|
};
|
|
545
527
|
}
|
|
546
528
|
export async function keys(args, runtime, deps = {}) {
|
|
@@ -553,6 +535,6 @@ export async function keys(args, runtime, deps = {}) {
|
|
|
553
535
|
return add(args, runtime, deps);
|
|
554
536
|
if (action === "shim")
|
|
555
537
|
return shim(args, runtime, deps, profileOf(args, runtime));
|
|
556
|
-
const unknown = unknownSubcommand("keys", action, ["list", "move", "add", "shim"]);
|
|
538
|
+
const unknown = unknownSubcommand("keys", action, ["list", "move", "add", "shim"], "Remove a key Passport holds in Passport › Apps › Keys.");
|
|
557
539
|
return failure(unknown.message, 6, "usage", unknown.next ? { next: unknown.next } : {});
|
|
558
540
|
}
|
package/dist/cliKeysShim.js
CHANGED
|
@@ -8,6 +8,8 @@ import { readExecVendors } from "./execMarker.js";
|
|
|
8
8
|
import { findVendorBinary, installShims, listShims, removeShims, shimBinaries, shimPathAdvice } from "./execShims.js";
|
|
9
9
|
import { EXEC_VENDOR_NAMES, execVendorOf } from "./execVendors.js";
|
|
10
10
|
import { listOf } from "./initUi.js";
|
|
11
|
+
import { pathLines } from "./pathLines.js";
|
|
12
|
+
import { table } from "./term.js";
|
|
11
13
|
/** A shim as JSON: no home-folder paths beyond Passport's own. */
|
|
12
14
|
export function shimJson(shim) {
|
|
13
15
|
return { vendor: shim.vendor, command: shim.binary, state: shim.state, path: shim.path };
|
|
@@ -28,10 +30,10 @@ export async function shim(args, runtime, deps, profile) {
|
|
|
28
30
|
const shims = listShims(runtime.env, platform);
|
|
29
31
|
const advice = shimPathAdvice(shims, runtime.env, platform);
|
|
30
32
|
const lines = shims.length
|
|
31
|
-
? shims.map((entry) =>
|
|
32
|
-
: ["No shims.
|
|
33
|
+
? table(shims.map((entry) => [entry.binary, SHIM_STATE_WORDS[entry.state]]), Number.POSITIVE_INFINITY)
|
|
34
|
+
: ["No shims yet. To keep typing a CLI whose key Passport holds, add one.", "Run: passport keys shim <cli>"];
|
|
33
35
|
if (advice)
|
|
34
|
-
lines.push(advice);
|
|
36
|
+
lines.push(...pathLines(advice));
|
|
35
37
|
return { json: { shims: shims.map(shimJson), ...(advice ? { pathLine: advice } : {}) }, human: lines.join("\n") };
|
|
36
38
|
}
|
|
37
39
|
if (remove) {
|
|
@@ -62,9 +64,9 @@ export async function shim(args, runtime, deps, profile) {
|
|
|
62
64
|
const commands = outcome.installed.map((entry) => entry.binary);
|
|
63
65
|
const lines = [`${listOf(commands)} now ${commands.length === 1 ? "runs" : "run"} through passport exec.`];
|
|
64
66
|
if (!held) {
|
|
65
|
-
lines.push(`Passport doesn't hold a ${EXEC_VENDOR_NAMES[vendor]} key yet
|
|
67
|
+
lines.push(`Passport doesn't hold a ${EXEC_VENDOR_NAMES[vendor]} key yet.`, `Run: passport keys move ${vendor}`);
|
|
66
68
|
}
|
|
67
|
-
lines.push(advice
|
|
69
|
+
lines.push(...(advice ? pathLines(advice) : ["Open a new terminal (or run hash -r) so your shell finds it."]));
|
|
68
70
|
return {
|
|
69
71
|
json: { installed: outcome.installed.map(shimJson), ...(advice ? { pathLine: advice } : {}) },
|
|
70
72
|
human: lines.join("\n")
|
package/dist/cliLogin.js
CHANGED
|
@@ -5,7 +5,7 @@ import { bool, value } from "./cliArgs.js";
|
|
|
5
5
|
import { answerOf, choices } from "./cliAsk.js";
|
|
6
6
|
import { assertCredentialStoreMutationReady, credsPath, getProfile, getProfileStrict, readCreds, setActiveProfile, withProfileLock, writeProfile } from "./credentials.js";
|
|
7
7
|
import { CliFailure, cloudOrigin, endpoint, failure, profileName, readBoundedJson, safeApiError, sameOriginWebUrl, selectStoredProfile, selfCommand, timedFetch, timeoutMs } from "./cliSupport.js";
|
|
8
|
-
import { fetchLoginIdentity, identityPhrase, rememberLoginIdentity } from "./loginIdentity.js";
|
|
8
|
+
import { fetchLoginIdentity, identityPhrase, loginIdentity, rememberLoginIdentity } from "./loginIdentity.js";
|
|
9
9
|
import { isPendingLoginId, newPendingLoginId, prunePendingLogins, readPendingLogin, removePendingLogin, savePendingLogin } from "./loginPending.js";
|
|
10
10
|
import { EXPIRED, IDENTITY_TIMEOUT_MS, PASSPORT_CLOUD, POLL_SLACK_MS, isTty, loginArgv, missingWorkspace, printPrompt, startSignIn, waitForApproval } from "./loginFlow.js";
|
|
11
11
|
export { signInLines } from "./loginFlow.js";
|
|
@@ -130,14 +130,21 @@ function loginOptions(args, runtime, hooks = {}) {
|
|
|
130
130
|
}
|
|
131
131
|
/** Ask one question on the terminal; the answer, trimmed. */
|
|
132
132
|
async function askOnTerminal(runtime, question) {
|
|
133
|
-
const { createInterface } = await
|
|
133
|
+
const [{ createInterface }, { promptRows, termOf }] = await Promise.all([
|
|
134
|
+
import("node:readline"),
|
|
135
|
+
import("./term.js")
|
|
136
|
+
]);
|
|
137
|
+
// A long question wraps; its last row, with [y/N], is the prompt.
|
|
138
|
+
const rows = promptRows(question, termOf(runtime.stderr, runtime.env).width);
|
|
139
|
+
for (const row of rows.rows)
|
|
140
|
+
runtime.stderr.write(`${row}\n`);
|
|
134
141
|
const input = (runtime.stdin ?? process.stdin);
|
|
135
142
|
const prompt = createInterface({ input, output: runtime.stderr, terminal: true });
|
|
136
143
|
try {
|
|
137
144
|
return await new Promise((resolveAnswer, reject) => {
|
|
138
145
|
const onAbort = () => reject(new Error("Cancelled."));
|
|
139
146
|
runtime.signal.addEventListener("abort", onAbort, { once: true });
|
|
140
|
-
prompt.question(
|
|
147
|
+
prompt.question(rows.prompt, (answer) => {
|
|
141
148
|
runtime.signal.removeEventListener("abort", onAbort);
|
|
142
149
|
resolveAnswer(answer.trim());
|
|
143
150
|
});
|
|
@@ -147,14 +154,18 @@ async function askOnTerminal(runtime, question) {
|
|
|
147
154
|
prompt.close();
|
|
148
155
|
}
|
|
149
156
|
}
|
|
157
|
+
/** A route the CLI's own sign-in may read: answering it proves the sign-in works. */
|
|
158
|
+
const SIGN_IN_PROBE = "/api/my/cli-policy";
|
|
150
159
|
/**
|
|
151
160
|
* Who the saved profile this login would refresh signs in as, when its
|
|
152
|
-
* credential still works
|
|
153
|
-
*
|
|
161
|
+
* credential still works: the name cached at login, confirmed by one call
|
|
162
|
+
* the CLI's sign-in can make. `none` when there is no saved sign-in or it was
|
|
163
|
+
* refused (login goes ahead), `unknown` when Passport couldn't confirm it.
|
|
154
164
|
*/
|
|
155
165
|
async function currentSignIn(profile, args, runtime) {
|
|
156
|
-
|
|
157
|
-
|
|
166
|
+
const saved = profile ? getProfile(profile) : undefined;
|
|
167
|
+
if (!saved)
|
|
168
|
+
return "none";
|
|
158
169
|
try {
|
|
159
170
|
const [{ memberApi }, { resolveCliAuth }] = await Promise.all([
|
|
160
171
|
import("./cliClient.js"),
|
|
@@ -162,17 +173,23 @@ async function currentSignIn(profile, args, runtime) {
|
|
|
162
173
|
]);
|
|
163
174
|
const auth = resolveCliAuth({ ...args, values: { ...args.values, profile } }, runtime.env);
|
|
164
175
|
if (auth.kind !== "profile")
|
|
165
|
-
return
|
|
176
|
+
return "none";
|
|
166
177
|
const signal = AbortSignal.any([runtime.signal, AbortSignal.timeout(IDENTITY_TIMEOUT_MS)]);
|
|
167
178
|
const api = memberApi({ auth, timeoutMs: IDENTITY_TIMEOUT_MS, signal });
|
|
168
|
-
const
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
179
|
+
const response = await api.fetchApi(SIGN_IN_PROBE, {
|
|
180
|
+
method: "GET",
|
|
181
|
+
headers: { accept: "application/json" },
|
|
182
|
+
signal
|
|
183
|
+
});
|
|
184
|
+
await response.body?.cancel().catch(() => undefined);
|
|
185
|
+
if (!response.ok)
|
|
186
|
+
return "unknown";
|
|
187
|
+
return { identity: loginIdentity(profile) ?? { workspaceId: workspaceOfProfile(saved) } };
|
|
173
188
|
}
|
|
174
|
-
catch {
|
|
175
|
-
|
|
189
|
+
catch (error) {
|
|
190
|
+
// The sign-in itself was refused: it expired, so signing in is the fix.
|
|
191
|
+
const refused = error ?? {};
|
|
192
|
+
return refused.status === 401 && refused.phase === "exchange" ? "none" : "unknown";
|
|
176
193
|
}
|
|
177
194
|
}
|
|
178
195
|
/** Step two, in the same output mode as step one. */
|
|
@@ -216,8 +233,8 @@ function firstStep(started, options, args, runtime) {
|
|
|
216
233
|
},
|
|
217
234
|
human: [
|
|
218
235
|
`Open ${started.verifyUrl}`,
|
|
219
|
-
`Check the code matches the one in your browser: ${started.userCode}
|
|
220
|
-
`
|
|
236
|
+
`Check the code matches the one in your browser: ${started.userCode}. Approve it, then finish here.`,
|
|
237
|
+
`Run: ${nextStep}`
|
|
221
238
|
].join("\n")
|
|
222
239
|
};
|
|
223
240
|
}
|
|
@@ -229,11 +246,11 @@ async function completeLogin(id, args, runtime) {
|
|
|
229
246
|
}
|
|
230
247
|
}
|
|
231
248
|
if (!isPendingLoginId(id)) {
|
|
232
|
-
return failure("That isn't a sign-in id from passport login.
|
|
249
|
+
return failure("That isn't a sign-in id from passport login. Sign in again.\nRun: passport login", 6, "usage");
|
|
233
250
|
}
|
|
234
251
|
const pending = readPendingLogin(id);
|
|
235
252
|
if (!pending) {
|
|
236
|
-
return failure("No sign-in with that id is waiting on this computer.
|
|
253
|
+
return failure("No sign-in with that id is waiting on this computer. Sign in again.\nRun: passport login", 2, "auth");
|
|
237
254
|
}
|
|
238
255
|
if (pending.expiresAt + POLL_SLACK_MS <= Date.now()) {
|
|
239
256
|
removePendingLogin(id);
|
|
@@ -246,11 +263,11 @@ async function completeLogin(id, args, runtime) {
|
|
|
246
263
|
client: pending.client
|
|
247
264
|
};
|
|
248
265
|
if (!bool(args, "json") && !bool(args, "quiet")) {
|
|
249
|
-
runtime.stderr.write(`Waiting for the browser to approve code ${pending.userCode}
|
|
266
|
+
runtime.stderr.write(`Waiting for the browser to approve code ${pending.userCode}… (Ctrl-C to stop)\n`);
|
|
250
267
|
}
|
|
251
268
|
let approval;
|
|
252
269
|
try {
|
|
253
|
-
approval = await waitForApproval({ ...pending }, options, args, runtime, `Stopped waiting. The sign-in is still open:
|
|
270
|
+
approval = await waitForApproval({ ...pending }, options, args, runtime, `Stopped waiting. The sign-in is still open.\nRun: passport login --complete ${id}`);
|
|
254
271
|
}
|
|
255
272
|
catch (error) {
|
|
256
273
|
// Denied, expired, or the wrong workspace: this id is done.
|
|
@@ -352,7 +369,7 @@ async function finishSignIn(options, approval, args, runtime) {
|
|
|
352
369
|
// Profile names and file paths are for when something needs looking into.
|
|
353
370
|
if (bool(args, "verbose"))
|
|
354
371
|
lines.push(`Profile "${profile}" is active. Saved in ${credsPath()}.`);
|
|
355
|
-
lines.push("
|
|
372
|
+
lines.push("Run: passport status");
|
|
356
373
|
return { json, human: lines.join("\n") };
|
|
357
374
|
}
|
|
358
375
|
export async function login(args, runtime, hooks = {}) {
|
|
@@ -373,9 +390,12 @@ export async function login(args, runtime, hooks = {}) {
|
|
|
373
390
|
const canAsk = Boolean(hooks.ask) || (watching && isTty(runtime.stdin));
|
|
374
391
|
const named = value(args, "workspace") !== undefined || value(args, "profile") !== undefined;
|
|
375
392
|
if (watching && canAsk && !hooks.onPrompt && !named && !bool(args, "switch")) {
|
|
376
|
-
const
|
|
393
|
+
const checked = await currentSignIn(options.requestedProfile, args, runtime);
|
|
394
|
+
if (checked === "unknown")
|
|
395
|
+
runtime.stderr.write("Couldn't confirm your current sign-in, so signing in again.\n");
|
|
396
|
+
const current = typeof checked === "object" ? checked.identity : undefined;
|
|
377
397
|
if (current) {
|
|
378
|
-
const who = identityPhrase(current);
|
|
398
|
+
const who = identityPhrase(current, current.workspaceId);
|
|
379
399
|
// Switching replaces the sign-in this computer uses: [y/N], and any
|
|
380
400
|
// answer but yes keeps it (cliAsk.ts).
|
|
381
401
|
const answer = await (hooks.ask ?? ((question) => askOnTerminal(runtime, question)))(`Already signed in as ${who}. Switch? ${choices("destructive")} `);
|
package/dist/cliLogout.js
CHANGED
|
@@ -3,19 +3,27 @@
|
|
|
3
3
|
* profile. Signing out of the last profile also stops the agents' allowlist
|
|
4
4
|
* sync and removes the vendor shims, which could only fail now.
|
|
5
5
|
*/
|
|
6
|
-
import { bool } from "./cliArgs.js";
|
|
6
|
+
import { bool, value } from "./cliArgs.js";
|
|
7
7
|
import { readCreds, removeProfile, withProfileLock } from "./credentials.js";
|
|
8
8
|
import { failure, resolveCliAuth, timedFetch, timeoutMs } from "./cliSupport.js";
|
|
9
|
+
import { listOf } from "./initUi.js";
|
|
10
|
+
import { paint, say, termOf } from "./term.js";
|
|
9
11
|
export async function logout(args, runtime) {
|
|
10
12
|
if (runtime.env.PASSPORT_AGENT_KEY || runtime.env.PASSPORT_ENDPOINT) {
|
|
11
|
-
return failure("Agent-
|
|
13
|
+
return failure("Agent-token authentication is not stored locally and cannot be logged out. Unset the environment variables instead.", 6, "usage");
|
|
14
|
+
}
|
|
15
|
+
// Nothing saved here: signing out is already done.
|
|
16
|
+
if (!Object.keys(readCreds()).length && value(args, "profile") === undefined) {
|
|
17
|
+
return { json: { removed: false, signedOut: true }, human: "Already signed out." };
|
|
12
18
|
}
|
|
13
19
|
const auth = resolveCliAuth(args, runtime.env);
|
|
14
20
|
if (auth.kind !== "profile")
|
|
15
21
|
return failure("No local profile is active.", 2, "auth");
|
|
22
|
+
const { forgetLoginIdentity, loginIdentity } = await import("./loginIdentity.js");
|
|
23
|
+
const identity = loginIdentity(auth.profile);
|
|
16
24
|
const existing = await withProfileLock(auth.profile, async () => removeProfile(auth.profile));
|
|
17
25
|
(await import("./cliPolicy.js")).removeCliPolicy(auth.profile);
|
|
18
|
-
|
|
26
|
+
forgetLoginIdentity(auth.profile);
|
|
19
27
|
let shimsRemoved = [];
|
|
20
28
|
// Signed out everywhere: the agents' allowlists no longer follow any rules,
|
|
21
29
|
// and a vendor shim could only fail, so the CLIs run on their own again.
|
|
@@ -39,19 +47,27 @@ export async function logout(args, runtime) {
|
|
|
39
47
|
}, timeoutMs(args), runtime.signal);
|
|
40
48
|
revoked = response.ok;
|
|
41
49
|
if (!response.ok)
|
|
42
|
-
warning =
|
|
50
|
+
warning = `! Passport couldn't revoke the sign-in (${response.status}), but it's removed from this computer.`;
|
|
43
51
|
}
|
|
44
52
|
catch {
|
|
45
|
-
warning = "
|
|
53
|
+
warning = "! Passport couldn't be reached to revoke the sign-in, but it's removed from this computer.";
|
|
46
54
|
}
|
|
47
55
|
}
|
|
48
56
|
if (warning && !bool(args, "quiet"))
|
|
49
|
-
runtime.stderr.
|
|
57
|
+
say(runtime.stderr, runtime.env, warning);
|
|
50
58
|
const shimLine = shimsRemoved.length
|
|
51
|
-
? `\nRemoved Passport's ${shimsRemoved
|
|
59
|
+
? `\nRemoved Passport's ${listOf(shimsRemoved)} ${shimsRemoved.length === 1 ? "shim" : "shims"}.`
|
|
52
60
|
: "";
|
|
61
|
+
// The person and workspace, with the profile id dimmed beside them.
|
|
62
|
+
const who = identity?.name && identity.workspaceName
|
|
63
|
+
? `${identity.name} from ${identity.workspaceName}`
|
|
64
|
+
: identity?.name || identity?.workspaceName;
|
|
65
|
+
const term = termOf(runtime.stdout, runtime.env);
|
|
66
|
+
const signedOut = who
|
|
67
|
+
? `Signed out ${who} ${paint(term, "dim", `(${auth.profile})`)}.`
|
|
68
|
+
: `Signed out ${auth.profile}.`;
|
|
53
69
|
return {
|
|
54
70
|
json: { profile: auth.profile, removed: true, revoked, ...(shimsRemoved.length ? { shimsRemoved } : {}) },
|
|
55
|
-
human:
|
|
71
|
+
human: `${signedOut}${shimLine}`
|
|
56
72
|
};
|
|
57
73
|
}
|