rechrome 1.9.2 → 1.10.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/package.json +1 -1
- package/rech.js +20 -7
- package/rech.ts +20 -7
package/package.json
CHANGED
package/rech.js
CHANGED
|
@@ -11,8 +11,8 @@ export const DEFAULT_PORT = 13775;
|
|
|
11
11
|
export const RECH_DIR = join(import.meta.dir, ".rech");
|
|
12
12
|
export const LOG_DIR = join(RECH_DIR, "logs");
|
|
13
13
|
|
|
14
|
-
const RECH_HOME_DIR = join(process.env.HOME!, ".
|
|
15
|
-
const TOKENS_FILE = join(RECH_HOME_DIR, "
|
|
14
|
+
const RECH_HOME_DIR = join(process.env.HOME!, ".rechrome");
|
|
15
|
+
const TOKENS_FILE = join(RECH_HOME_DIR, "profiles.json");
|
|
16
16
|
|
|
17
17
|
type TokenEntry = { extensionId: string; token: string; profileDir: string; userDataDir?: string };
|
|
18
18
|
|
|
@@ -608,7 +608,7 @@ async function setup(opts: { profile?: string } = {}): Promise<void> {
|
|
|
608
608
|
return available[idx];
|
|
609
609
|
}
|
|
610
610
|
|
|
611
|
-
async function getExtAndToken(profileDir: string, profileDisplay: string): Promise<{ extId: string; token: string } | null> {
|
|
611
|
+
async function getExtAndToken(profileDir: string, profileDisplay: string, profileKey: string): Promise<{ extId: string; token: string } | null> {
|
|
612
612
|
// Extension check
|
|
613
613
|
let extId: string | undefined;
|
|
614
614
|
while (true) {
|
|
@@ -625,6 +625,19 @@ async function setup(opts: { profile?: string } = {}): Promise<void> {
|
|
|
625
625
|
}
|
|
626
626
|
console.log(` Extension found: ${extId}`);
|
|
627
627
|
|
|
628
|
+
// Check for existing token in registry
|
|
629
|
+
const registry = await readTokenRegistry();
|
|
630
|
+
const existing = registry[profileKey];
|
|
631
|
+
if (existing && existing.extensionId === extId && existing.token) {
|
|
632
|
+
console.log(` Existing token found: ${existing.token.slice(0, 6)}…`);
|
|
633
|
+
if (!isTTY) console.log(` [agent] Provide y to keep existing token, n to refresh on next stdin line`);
|
|
634
|
+
const keep = (await ask(" Keep existing token? [Y/n]: ")).trim().toLowerCase();
|
|
635
|
+
if (keep !== "n") {
|
|
636
|
+
console.log(" Keeping existing token");
|
|
637
|
+
return { extId, token: existing.token };
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
|
|
628
641
|
// Token
|
|
629
642
|
const statusUrl = `chrome-extension://${extId}/status.html`;
|
|
630
643
|
console.log(`\n Get auth token from the extension:`);
|
|
@@ -658,10 +671,10 @@ async function setup(opts: { profile?: string } = {}): Promise<void> {
|
|
|
658
671
|
|
|
659
672
|
// [3+4/4] Extension + token for primary profile
|
|
660
673
|
console.log("\n[3/4] Checking extension...");
|
|
661
|
-
const
|
|
674
|
+
const profileEmail = profileInfoSel.user_name || profileDir;
|
|
675
|
+
const primary = await getExtAndToken(profileDir, profileDisplay, profileEmail);
|
|
662
676
|
if (!primary) { rl?.close(); process.exit(1); }
|
|
663
677
|
const { extId, token } = primary;
|
|
664
|
-
const profileEmail = profileInfoSel.user_name || profileDir;
|
|
665
678
|
|
|
666
679
|
// Build RECHROME_URL and show it before asking where to save
|
|
667
680
|
const rechUrl = new URL(url);
|
|
@@ -708,10 +721,10 @@ async function setup(opts: { profile?: string } = {}): Promise<void> {
|
|
|
708
721
|
if (!extra) { console.log(" Skipped."); continue; }
|
|
709
722
|
const [extraDir, extraInfo] = extra;
|
|
710
723
|
const extraDisplay = extraInfo.user_name || extraInfo.name || extraDir;
|
|
724
|
+
const extraEmail = extraInfo.user_name || extraDir;
|
|
711
725
|
console.log(`\n Setting up: ${extraDisplay}`);
|
|
712
|
-
const result = await getExtAndToken(extraDir, extraDisplay);
|
|
726
|
+
const result = await getExtAndToken(extraDir, extraDisplay, extraEmail);
|
|
713
727
|
if (!result) { console.log(" Skipped."); continue; }
|
|
714
|
-
const extraEmail = extraInfo.user_name || extraDir;
|
|
715
728
|
await saveTokenEntry(extraEmail, { extensionId: result.extId, token: result.token, profileDir: extraDir, userDataDir: userDataDir ?? undefined });
|
|
716
729
|
configured.add(extraDir);
|
|
717
730
|
console.log(` Saved token for ${extraDisplay}`);
|
package/rech.ts
CHANGED
|
@@ -11,8 +11,8 @@ export const DEFAULT_PORT = 13775;
|
|
|
11
11
|
export const RECH_DIR = join(import.meta.dir, ".rech");
|
|
12
12
|
export const LOG_DIR = join(RECH_DIR, "logs");
|
|
13
13
|
|
|
14
|
-
const RECH_HOME_DIR = join(process.env.HOME!, ".
|
|
15
|
-
const TOKENS_FILE = join(RECH_HOME_DIR, "
|
|
14
|
+
const RECH_HOME_DIR = join(process.env.HOME!, ".rechrome");
|
|
15
|
+
const TOKENS_FILE = join(RECH_HOME_DIR, "profiles.json");
|
|
16
16
|
|
|
17
17
|
type TokenEntry = { extensionId: string; token: string; profileDir: string; userDataDir?: string };
|
|
18
18
|
|
|
@@ -608,7 +608,7 @@ async function setup(opts: { profile?: string } = {}): Promise<void> {
|
|
|
608
608
|
return available[idx];
|
|
609
609
|
}
|
|
610
610
|
|
|
611
|
-
async function getExtAndToken(profileDir: string, profileDisplay: string): Promise<{ extId: string; token: string } | null> {
|
|
611
|
+
async function getExtAndToken(profileDir: string, profileDisplay: string, profileKey: string): Promise<{ extId: string; token: string } | null> {
|
|
612
612
|
// Extension check
|
|
613
613
|
let extId: string | undefined;
|
|
614
614
|
while (true) {
|
|
@@ -625,6 +625,19 @@ async function setup(opts: { profile?: string } = {}): Promise<void> {
|
|
|
625
625
|
}
|
|
626
626
|
console.log(` Extension found: ${extId}`);
|
|
627
627
|
|
|
628
|
+
// Check for existing token in registry
|
|
629
|
+
const registry = await readTokenRegistry();
|
|
630
|
+
const existing = registry[profileKey];
|
|
631
|
+
if (existing && existing.extensionId === extId && existing.token) {
|
|
632
|
+
console.log(` Existing token found: ${existing.token.slice(0, 6)}…`);
|
|
633
|
+
if (!isTTY) console.log(` [agent] Provide y to keep existing token, n to refresh on next stdin line`);
|
|
634
|
+
const keep = (await ask(" Keep existing token? [Y/n]: ")).trim().toLowerCase();
|
|
635
|
+
if (keep !== "n") {
|
|
636
|
+
console.log(" Keeping existing token");
|
|
637
|
+
return { extId, token: existing.token };
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
|
|
628
641
|
// Token
|
|
629
642
|
const statusUrl = `chrome-extension://${extId}/status.html`;
|
|
630
643
|
console.log(`\n Get auth token from the extension:`);
|
|
@@ -658,10 +671,10 @@ async function setup(opts: { profile?: string } = {}): Promise<void> {
|
|
|
658
671
|
|
|
659
672
|
// [3+4/4] Extension + token for primary profile
|
|
660
673
|
console.log("\n[3/4] Checking extension...");
|
|
661
|
-
const
|
|
674
|
+
const profileEmail = profileInfoSel.user_name || profileDir;
|
|
675
|
+
const primary = await getExtAndToken(profileDir, profileDisplay, profileEmail);
|
|
662
676
|
if (!primary) { rl?.close(); process.exit(1); }
|
|
663
677
|
const { extId, token } = primary;
|
|
664
|
-
const profileEmail = profileInfoSel.user_name || profileDir;
|
|
665
678
|
|
|
666
679
|
// Build RECHROME_URL and show it before asking where to save
|
|
667
680
|
const rechUrl = new URL(url);
|
|
@@ -708,10 +721,10 @@ async function setup(opts: { profile?: string } = {}): Promise<void> {
|
|
|
708
721
|
if (!extra) { console.log(" Skipped."); continue; }
|
|
709
722
|
const [extraDir, extraInfo] = extra;
|
|
710
723
|
const extraDisplay = extraInfo.user_name || extraInfo.name || extraDir;
|
|
724
|
+
const extraEmail = extraInfo.user_name || extraDir;
|
|
711
725
|
console.log(`\n Setting up: ${extraDisplay}`);
|
|
712
|
-
const result = await getExtAndToken(extraDir, extraDisplay);
|
|
726
|
+
const result = await getExtAndToken(extraDir, extraDisplay, extraEmail);
|
|
713
727
|
if (!result) { console.log(" Skipped."); continue; }
|
|
714
|
-
const extraEmail = extraInfo.user_name || extraDir;
|
|
715
728
|
await saveTokenEntry(extraEmail, { extensionId: result.extId, token: result.token, profileDir: extraDir, userDataDir: userDataDir ?? undefined });
|
|
716
729
|
configured.add(extraDir);
|
|
717
730
|
console.log(` Saved token for ${extraDisplay}`);
|