rshow 0.0.3 → 0.0.4

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.
Files changed (2) hide show
  1. package/dist/main.js +49 -11
  2. package/package.json +1 -1
package/dist/main.js CHANGED
@@ -13,7 +13,7 @@ import process from "node:process";
13
13
  // src/version.ts
14
14
  import { readFileSync } from "node:fs";
15
15
  import { fileURLToPath } from "node:url";
16
- var VERSION = true ? "0.0.3" : versionFromPackage();
16
+ var VERSION = true ? "0.0.4" : versionFromPackage();
17
17
 
18
18
  // src/binary.ts
19
19
  var ASSET_MANIFEST = "assets.json";
@@ -754,6 +754,9 @@ async function choose(env = process8.env, platform = process8.platform) {
754
754
  if (canUse(env, platform) && await usable(env)) return storeOf("keyring", env);
755
755
  return storeOf("file", env);
756
756
  }
757
+ function fileStore(env = process8.env) {
758
+ return storeOf("file", env);
759
+ }
757
760
  async function every(env = process8.env, platform = process8.platform) {
758
761
  const stores = [];
759
762
  if (canSave(platform, env.RSHOW_SECURITY_BIN)) stores.push(storeOf("keychain", env));
@@ -761,6 +764,23 @@ async function every(env = process8.env, platform = process8.platform) {
761
764
  stores.push(storeOf("file", env));
762
765
  return stores;
763
766
  }
767
+ async function find(env, url, platform = process8.platform) {
768
+ const forcedBackend = forced(env);
769
+ const stores = forcedBackend === void 0 ? await every(env, platform) : [storeOf(forcedBackend, env)];
770
+ let failed = false;
771
+ let firstError;
772
+ for (const store2 of stores) {
773
+ try {
774
+ const token = await store2.read(url);
775
+ if (token !== void 0) return { store: store2, token };
776
+ } catch (err) {
777
+ if (!failed) firstError = err;
778
+ failed = true;
779
+ }
780
+ }
781
+ if (failed) throw firstError;
782
+ return void 0;
783
+ }
764
784
 
765
785
  // src/config.ts
766
786
  var DEFAULT_OUT = "dist";
@@ -894,9 +914,8 @@ function requireArt(config) {
894
914
  async function readToken(env, url) {
895
915
  const token = (env.RSHOW_TOKEN ?? "").trim();
896
916
  if (token !== "") return token;
897
- const store2 = await choose(env);
898
- const saved = await store2.read(url);
899
- if (saved !== void 0) return saved;
917
+ const found = await find(env, url);
918
+ if (found !== void 0) return found.token;
900
919
  throw new UsageError("no token: run rshow login, or set RSHOW_TOKEN");
901
920
  }
902
921
 
@@ -4531,9 +4550,8 @@ async function tokenOf(url) {
4531
4550
  if (env !== "") return { token: env, source: "env" };
4532
4551
  if (url === void 0) return {};
4533
4552
  try {
4534
- const store2 = await choose(process13.env);
4535
- const saved = await store2.read(url);
4536
- if (saved !== void 0) return { token: saved, source: store2.detail };
4553
+ const found = await find(process13.env, url);
4554
+ if (found !== void 0) return { token: found.token, source: found.store.detail };
4537
4555
  return {};
4538
4556
  } catch (err) {
4539
4557
  return { error: messageOf10(err) };
@@ -8744,6 +8762,17 @@ async function tokenFromStdin() {
8744
8762
  if (!token.startsWith(TOKEN_PREFIX)) throw new UsageError(`that is not an rshow token: it must start with ${TOKEN_PREFIX}`);
8745
8763
  return token;
8746
8764
  }
8765
+ async function saveIn(store2, url, token) {
8766
+ await store2.save(url, token);
8767
+ if (await store2.read(url) !== token) {
8768
+ throw new ApiError(`cannot save the token in ${store2.description}`);
8769
+ }
8770
+ }
8771
+ function reasonOf(err) {
8772
+ const text = (err instanceof Error ? err.message : String(err)).replace(/^cannot save the token in the keyring: /, "");
8773
+ const lines = text.split("\n").map((part) => part.trim()).filter((part) => part !== "");
8774
+ return lines.at(-1) ?? "";
8775
+ }
8747
8776
  async function run19(argv, ctx, platform = process21.platform) {
8748
8777
  const args = parseCommandArgs(argv, { url: { type: "string" } }, 0, 0, LOGIN_USAGE);
8749
8778
  const settings = await ctx.config();
@@ -8753,10 +8782,19 @@ async function run19(argv, ctx, platform = process21.platform) {
8753
8782
  const me = (await new Client(url, token).send("GET", "/api/me")).body;
8754
8783
  const email = typeof me?.email === "string" ? me.email : "";
8755
8784
  const scope = typeof me?.scope === "string" ? me.scope : "";
8756
- const store2 = await choose(process21.env, platform);
8757
- await store2.save(url, token);
8758
- if (await store2.read(url) !== token) {
8759
- throw new ApiError(`cannot save the token in ${store2.description}`);
8785
+ let store2 = await choose(process21.env, platform);
8786
+ if (store2.backend === "keyring" && forced(process21.env) === void 0) {
8787
+ try {
8788
+ await saveIn(store2, url, token);
8789
+ } catch (err) {
8790
+ warn(`the Linux keyring cannot save the token (${reasonOf(err)}); saving it in a file`);
8791
+ await store2.remove(url).catch(() => {
8792
+ });
8793
+ store2 = fileStore(process21.env);
8794
+ await saveIn(store2, url, token);
8795
+ }
8796
+ } else {
8797
+ await saveIn(store2, url, token);
8760
8798
  }
8761
8799
  ctx.out.data({ email, scope, url });
8762
8800
  ctx.out.line(`logged in as ${email} (scope ${scope}) for ${url}, saved in ${store2.description}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rshow",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "description": "Publish static artifacts to rshow",
5
5
  "license": "MIT",
6
6
  "homepage": "https://rslib.github.io/rshow",