rechrome 1.8.0 → 1.8.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rechrome",
3
- "version": "1.8.0",
3
+ "version": "1.8.2",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/snomiao/rechrome.git"
package/rech.js CHANGED
@@ -118,7 +118,8 @@ export function parseUrl(raw: string) {
118
118
  }
119
119
 
120
120
  export async function getOrCreateUrl(): Promise<string> {
121
- if (process.env[ENV_KEY]) return process.env[ENV_KEY];
121
+ // Treat a URL without a bearer key as missing — it cannot authenticate
122
+ try { if (process.env[ENV_KEY] && new URL(process.env[ENV_KEY]!).username) return process.env[ENV_KEY]!; } catch {}
122
123
  const key = randomBytes(9).toString("base64url"); // 12 chars
123
124
  const url = `http://${key}@127.0.0.1:${DEFAULT_PORT}`;
124
125
  const newLine = `${ENV_KEY}=${url}`;
@@ -534,15 +535,19 @@ async function setup(opts: { profile?: string } = {}): Promise<void> {
534
535
  const url = await getOrCreateUrl();
535
536
  const { host, port, protocol } = parseUrl(url);
536
537
 
537
- let ping = await fetch(`${protocol}://${host}:${port}/`, { signal: AbortSignal.timeout(2000) }).catch(() => null);
538
- if (ping) {
539
- console.log(` Already running at ${protocol}://${host}:${port}`);
540
- await daemonInstall(url);
541
- console.log(` Updated daemon: ${OXMGR_PROCESS_NAME}`);
538
+ const { key: serveKey } = parseUrl(url);
539
+ const authPing = await fetch(`${protocol}://${host}:${port}/ping`, {
540
+ headers: { Authorization: `Bearer ${serveKey}` },
541
+ signal: AbortSignal.timeout(2000),
542
+ }).catch(() => null);
543
+ if (authPing?.ok) {
544
+ console.log(` Already running at ${protocol}://${host}:${port} — skipping reinstall`);
545
+ await runOxmgr(["service", "install"]);
542
546
  } else {
543
547
  await daemonInstall(url);
544
548
  console.log(` Registered daemon: ${OXMGR_PROCESS_NAME}`);
545
549
  process.stdout.write(" Starting");
550
+ let ping = null;
546
551
  for (let i = 0; i < 15; i++) {
547
552
  await Bun.sleep(1000);
548
553
  ping = await fetch(`${protocol}://${host}:${port}/`, { signal: AbortSignal.timeout(2000) }).catch(() => null);
@@ -645,6 +650,7 @@ async function setup(opts: { profile?: string } = {}): Promise<void> {
645
650
  if (saveChoice === "2") mkdirSync(join(process.cwd(), ".rechrome"), { recursive: true });
646
651
  const existing = await file(globalEnvPath).text().catch(() => "");
647
652
  const rechUrl = new URL(url);
653
+ if (!rechUrl.username) rechUrl.username = randomBytes(9).toString("base64url");
648
654
  rechUrl.searchParams.set("extension_id", extId);
649
655
  rechUrl.searchParams.set("token", token);
650
656
  rechUrl.searchParams.set("profile", profileEmail);
package/rech.ts CHANGED
@@ -118,7 +118,8 @@ export function parseUrl(raw: string) {
118
118
  }
119
119
 
120
120
  export async function getOrCreateUrl(): Promise<string> {
121
- if (process.env[ENV_KEY]) return process.env[ENV_KEY];
121
+ // Treat a URL without a bearer key as missing — it cannot authenticate
122
+ try { if (process.env[ENV_KEY] && new URL(process.env[ENV_KEY]!).username) return process.env[ENV_KEY]!; } catch {}
122
123
  const key = randomBytes(9).toString("base64url"); // 12 chars
123
124
  const url = `http://${key}@127.0.0.1:${DEFAULT_PORT}`;
124
125
  const newLine = `${ENV_KEY}=${url}`;
@@ -534,15 +535,19 @@ async function setup(opts: { profile?: string } = {}): Promise<void> {
534
535
  const url = await getOrCreateUrl();
535
536
  const { host, port, protocol } = parseUrl(url);
536
537
 
537
- let ping = await fetch(`${protocol}://${host}:${port}/`, { signal: AbortSignal.timeout(2000) }).catch(() => null);
538
- if (ping) {
539
- console.log(` Already running at ${protocol}://${host}:${port}`);
540
- await daemonInstall(url);
541
- console.log(` Updated daemon: ${OXMGR_PROCESS_NAME}`);
538
+ const { key: serveKey } = parseUrl(url);
539
+ const authPing = await fetch(`${protocol}://${host}:${port}/ping`, {
540
+ headers: { Authorization: `Bearer ${serveKey}` },
541
+ signal: AbortSignal.timeout(2000),
542
+ }).catch(() => null);
543
+ if (authPing?.ok) {
544
+ console.log(` Already running at ${protocol}://${host}:${port} — skipping reinstall`);
545
+ await runOxmgr(["service", "install"]);
542
546
  } else {
543
547
  await daemonInstall(url);
544
548
  console.log(` Registered daemon: ${OXMGR_PROCESS_NAME}`);
545
549
  process.stdout.write(" Starting");
550
+ let ping = null;
546
551
  for (let i = 0; i < 15; i++) {
547
552
  await Bun.sleep(1000);
548
553
  ping = await fetch(`${protocol}://${host}:${port}/`, { signal: AbortSignal.timeout(2000) }).catch(() => null);
@@ -645,6 +650,7 @@ async function setup(opts: { profile?: string } = {}): Promise<void> {
645
650
  if (saveChoice === "2") mkdirSync(join(process.cwd(), ".rechrome"), { recursive: true });
646
651
  const existing = await file(globalEnvPath).text().catch(() => "");
647
652
  const rechUrl = new URL(url);
653
+ if (!rechUrl.username) rechUrl.username = randomBytes(9).toString("base64url");
648
654
  rechUrl.searchParams.set("extension_id", extId);
649
655
  rechUrl.searchParams.set("token", token);
650
656
  rechUrl.searchParams.set("profile", profileEmail);
package/serve.js CHANGED
@@ -107,6 +107,11 @@ export async function serve() {
107
107
  return new Response(f);
108
108
  }
109
109
 
110
+ if (reqUrl.pathname === "/ping") {
111
+ const denied = authCheck(req, key);
112
+ if (denied) return denied;
113
+ return new Response("ok");
114
+ }
110
115
  if (reqUrl.pathname !== "/run") return new Response("rech server\n");
111
116
  const denied = authCheck(req, key);
112
117
  if (denied) return denied;
package/serve.ts CHANGED
@@ -107,6 +107,11 @@ export async function serve() {
107
107
  return new Response(f);
108
108
  }
109
109
 
110
+ if (reqUrl.pathname === "/ping") {
111
+ const denied = authCheck(req, key);
112
+ if (denied) return denied;
113
+ return new Response("ok");
114
+ }
110
115
  if (reqUrl.pathname !== "/run") return new Response("rech server\n");
111
116
  const denied = authCheck(req, key);
112
117
  if (denied) return denied;