@secondlayer/cli 22.0.0 → 22.0.1

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/cli.js CHANGED
@@ -2567,12 +2567,27 @@ function nextStepHint(status) {
2567
2567
  return "Server error — retry shortly, or check `secondlayer status`.";
2568
2568
  return;
2569
2569
  }
2570
+ function authFailureMessage(code, status, ossMode) {
2571
+ if (code === "KEY_REVOKED") {
2572
+ return {
2573
+ message: "Your saved login was revoked.",
2574
+ hint: "Run `secondlayer login` to sign in again. If you set SECONDLAYER_API_KEY, replace it with a key from /account/keys."
2575
+ };
2576
+ }
2577
+ if (code === "SESSION_EXPIRED" || status === 401) {
2578
+ return {
2579
+ message: "Authentication required.",
2580
+ hint: ossMode ? "Set INSTANCE_TOKEN from `secondlayer init`." : "Run `secondlayer login` to re-authenticate."
2581
+ };
2582
+ }
2583
+ return null;
2584
+ }
2570
2585
  function handleApiError(err, action) {
2571
2586
  const status = err instanceof ApiError || err instanceof CliHttpError ? err.status : undefined;
2572
- if (err instanceof CliHttpError && err.code === "SESSION_EXPIRED" || status === 401) {
2573
- printError("Authentication required.", {
2574
- hint: isOssMode() ? "Set INSTANCE_TOKEN from `secondlayer init`." : "Run `secondlayer login` to re-authenticate."
2575
- });
2587
+ const code = err instanceof ApiError || err instanceof CliHttpError ? err.code : undefined;
2588
+ const auth = authFailureMessage(code, status, isOssMode());
2589
+ if (auth) {
2590
+ printError(auth.message, { hint: auth.hint });
2576
2591
  process.exit(1);
2577
2592
  }
2578
2593
  const detail = err instanceof Error ? err.message : String(err);
@@ -16181,7 +16196,11 @@ class StacksApiClient {
16181
16196
  return response.body;
16182
16197
  } catch (error) {
16183
16198
  const statusCode = typeof error === "object" && error !== null && "response" in error && typeof error.response === "object" && error.response !== null && "statusCode" in error.response ? error.response.statusCode : undefined;
16199
+ const responseBody = typeof error === "object" && error !== null && "response" in error && typeof error.response === "object" && error.response !== null && "body" in error.response ? error.response.body : undefined;
16184
16200
  const message = error instanceof Error ? error.message : String(error);
16201
+ if (statusCode === 401 && typeof responseBody === "object" && responseBody !== null && "code" in responseBody && responseBody.code === "KEY_REVOKED") {
16202
+ throw new Error("Your saved login was revoked. Run `secondlayer login` to sign in again.");
16203
+ }
16185
16204
  if (statusCode === 401) {
16186
16205
  throw new Error(isOssMode() ? "Authentication required. Set INSTANCE_TOKEN from `secondlayer init`." : "Authentication required. Run: secondlayer login");
16187
16206
  }
@@ -202692,7 +202711,7 @@ var {
202692
202711
  // package.json
202693
202712
  var package_default = {
202694
202713
  name: "@secondlayer/cli",
202695
- version: "22.0.0",
202714
+ version: "22.0.1",
202696
202715
  description: "Run a Stacks index on your own hardware — set it up, restore verified history, and keep it current.",
202697
202716
  repository: {
202698
202717
  type: "git",
@@ -207861,12 +207880,24 @@ async function runTokenLogin() {
207861
207880
  }, target);
207862
207881
  success(`Logged in as ${account.email} (${target})`);
207863
207882
  }
207864
- async function shouldContinueLogin(target, options) {
207883
+ var defaultLoginCheckDeps = {
207884
+ readSession,
207885
+ verify: (target, token) => httpAt(target, "/api/accounts/me", { bearer: token })
207886
+ };
207887
+ async function shouldContinueLogin(target, options, deps = defaultLoginCheckDeps) {
207865
207888
  if (options.force)
207866
207889
  return true;
207867
- const existing = await readSession(target);
207890
+ const existing = await deps.readSession(target);
207868
207891
  if (!existing)
207869
207892
  return true;
207893
+ try {
207894
+ await deps.verify(target, existing.token);
207895
+ } catch (err) {
207896
+ if (err instanceof CliHttpError && (err.status === 401 || err.status === 403)) {
207897
+ info(`Your saved login for ${existing.email} stopped working (revoked or expired). Signing in again.`);
207898
+ return true;
207899
+ }
207900
+ }
207870
207901
  info(`Already logged in as ${existing.email} (${target}).`);
207871
207902
  const hint = "Run 'secondlayer logout' first, or re-run with --force to switch accounts.";
207872
207903
  if (!process.stdin.isTTY) {
@@ -207936,10 +207967,10 @@ async function runDeviceLogin(options = {}) {
207936
207967
  error(err instanceof Error ? err.message : String(err));
207937
207968
  process.exit(1);
207938
207969
  }
207939
- info(`First copy your one-time code: ${start.userCode}`);
207970
+ info(`Your one-time code: ${start.userCode}`);
207940
207971
  const readline = process.stdin.isTTY ? createInterface({ input: process.stdin }) : null;
207941
207972
  if (readline) {
207942
- info("Press Enter to open secondlayer.tools in your browser...");
207973
+ info("Press Enter to open the sign-in page, then check the code matches.");
207943
207974
  readline.once("line", () => openBrowser(start.verificationUrl));
207944
207975
  }
207945
207976
  info(dim(`Or open ${start.verificationUrl}`));
@@ -208659,5 +208690,5 @@ registerCreditsCommand(program);
208659
208690
  registerArchiveCommand(program);
208660
208691
  program.parse();
208661
208692
 
208662
- //# debugId=32DC3B7BA2B6602D64756E2164756E21
208693
+ //# debugId=77FBD5CCBD0906B064756E2164756E21
208663
208694
  //# sourceMappingURL=cli.js.map