passcontrol 0.7.1 → 0.7.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/cli/login.mjs +58 -6
- package/package.json +1 -1
package/cli/login.mjs
CHANGED
|
@@ -39,6 +39,8 @@ import { ed25519 } from "@noble/curves/ed25519";
|
|
|
39
39
|
import fs from "node:fs";
|
|
40
40
|
import {
|
|
41
41
|
CLOUD_GATEWAY,
|
|
42
|
+
configInjectedKeys,
|
|
43
|
+
configSources,
|
|
42
44
|
fail,
|
|
43
45
|
findProjectConfig,
|
|
44
46
|
globalConfigPath,
|
|
@@ -334,6 +336,42 @@ export function resolveLoginGateway(opts = {}, env = process.env) {
|
|
|
334
336
|
return requireControlGateway({ gateway: fromFlag || fromConfig || CLOUD_GATEWAY });
|
|
335
337
|
}
|
|
336
338
|
|
|
339
|
+
/**
|
|
340
|
+
* WHERE the destination came from — so a failure can name something editable.
|
|
341
|
+
*
|
|
342
|
+
* This exists because the honest answer is not "the environment". cli/config.mjs
|
|
343
|
+
* injects config-file values into `process.env` at import, so by the time
|
|
344
|
+
* resolveLoginGateway reads PASSCONTROL_GATEWAY the shell and a file on disk are
|
|
345
|
+
* indistinguishable — and an error telling someone to "unset PASSCONTROL_GATEWAY"
|
|
346
|
+
* when their value lives in `~/.config/passcontrol/config` is instructing them to
|
|
347
|
+
* change something that is not set. They run it, nothing moves, and the CLI looks
|
|
348
|
+
* broken rather than merely configured. Reported from a real machine on 0.7.1.
|
|
349
|
+
*
|
|
350
|
+
* `configInjectedKeys` is the same set cli/config.mjs keeps so that "a file said
|
|
351
|
+
* so" and "the operator said so" stay separable for credentials. This is that
|
|
352
|
+
* distinction applied to advice.
|
|
353
|
+
*
|
|
354
|
+
* The file search takes the LAST match, not the first. applyConfigSourcesToEnv
|
|
355
|
+
* pushes global then project and Object.assign()es in order, so a project
|
|
356
|
+
* `.passcontrol` overwrites the global config — and `.find()` would confidently
|
|
357
|
+
* name a file whose value never reached the environment.
|
|
358
|
+
*/
|
|
359
|
+
export function gatewaySource(
|
|
360
|
+
opts = {},
|
|
361
|
+
env = process.env,
|
|
362
|
+
{ sources = configSources, injected = configInjectedKeys } = {}
|
|
363
|
+
) {
|
|
364
|
+
if (typeof opts.gateway === "string" && opts.gateway.trim()) return { from: "flag" };
|
|
365
|
+
if (typeof env.PASSCONTROL_GATEWAY === "string" && env.PASSCONTROL_GATEWAY.trim()) {
|
|
366
|
+
if (!injected.has("PASSCONTROL_GATEWAY")) return { from: "env" };
|
|
367
|
+
const file = [...sources]
|
|
368
|
+
.reverse()
|
|
369
|
+
.find((source) => "PASSCONTROL_GATEWAY" in (source?.values ?? {}));
|
|
370
|
+
return file ? { from: "file", path: file.path } : { from: "env" };
|
|
371
|
+
}
|
|
372
|
+
return { from: "default" };
|
|
373
|
+
}
|
|
374
|
+
|
|
337
375
|
export async function loginCommand(opts = {}, deps = {}) {
|
|
338
376
|
const fetchImpl = deps.fetch ?? fetch;
|
|
339
377
|
const openUrl = deps.openUrl ?? (() => {});
|
|
@@ -360,12 +398,26 @@ export async function loginCommand(opts = {}, deps = {}) {
|
|
|
360
398
|
// never be true and the timeout wording would be dead code.
|
|
361
399
|
const underlying = error?.cause ?? error;
|
|
362
400
|
const reason = underlying?.name === "AbortError" ? "timed out" : "could not be reached";
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
);
|
|
401
|
+
// Name the place BEFORE offering the remedy — that is the whole job of
|
|
402
|
+
// gatewaySource above. The default origin is nobody's mistake, and blaming a
|
|
403
|
+
// config file that never mentions a gateway sends the operator to edit a line
|
|
404
|
+
// that is not there.
|
|
405
|
+
const source = gatewaySource(opts);
|
|
406
|
+
const lines = [`${origin} ${reason} (${underlying?.message ?? "unknown"}).`];
|
|
407
|
+
if (source.from === "file") {
|
|
408
|
+
lines.push(` That origin comes from ${source.path}, not from your shell.`);
|
|
409
|
+
lines.push(` Edit or delete its PASSCONTROL_GATEWAY line to change it.`);
|
|
410
|
+
} else if (source.from === "env") {
|
|
411
|
+
lines.push(` That origin comes from PASSCONTROL_GATEWAY in your shell.`);
|
|
412
|
+
}
|
|
413
|
+
if (source.from === "default") {
|
|
414
|
+
lines.push(` • Self-hosting? Start your stack, then pass --gateway <origin>.`);
|
|
415
|
+
lines.push(` • Otherwise check your connection and run the command again.`);
|
|
416
|
+
} else {
|
|
417
|
+
lines.push(` • Self-hosting? Start your stack, or pass --gateway <origin>.`);
|
|
418
|
+
lines.push(` • Meant to use Cloud? passcontrol login --gateway ${CLOUD_GATEWAY}`);
|
|
419
|
+
}
|
|
420
|
+
throw new Error(lines.join("\n"), { cause: error });
|
|
369
421
|
}
|
|
370
422
|
if (started.status !== 200 || !started.body?.user_code) {
|
|
371
423
|
throw new Error(
|
package/package.json
CHANGED