pleumrouter 0.5.17 → 0.5.18

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/package.json +1 -1
  2. package/src/login.mjs +25 -12
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pleumrouter",
3
- "version": "0.5.17",
3
+ "version": "0.5.18",
4
4
  "description": "Official PleumRouter terminal CLI — launch any coding agent against PleumRouter.",
5
5
  "type": "module",
6
6
  "bin": {
package/src/login.mjs CHANGED
@@ -17,11 +17,17 @@ export function browserCommand(url, platform = process.platform) {
17
17
 
18
18
  function openBrowser(url) {
19
19
  const { command, args } = browserCommand(url);
20
- spawn(command, args, {
21
- stdio: "ignore",
22
- detached: true,
23
- shell: false,
24
- }).unref();
20
+ try {
21
+ const child = spawn(command, args, {
22
+ stdio: "ignore",
23
+ detached: true,
24
+ shell: false,
25
+ });
26
+ child.on("error", () => {});
27
+ child.unref();
28
+ } catch {
29
+ // Ignore synchronous spawn failure on headless environments
30
+ }
25
31
  }
26
32
 
27
33
  function saveTokens({ access_token, refresh_token, expires_in }) {
@@ -123,14 +129,21 @@ export async function loginDevice() {
123
129
  ` ${t("Log in at the URL above, then enter the code (within {min} min).", { min: expires_in / 60 })}\n`
124
130
  );
125
131
 
126
- const deadline = Date.now() + expires_in * 1000;
132
+ const expiresIn = Number(expires_in) || 600;
133
+ const pollInterval = Math.max(1, Number(interval) || 5);
134
+ const deadline = Date.now() + expiresIn * 1000;
127
135
  while (Date.now() < deadline) {
128
- await new Promise((r) => setTimeout(r, interval * 1000));
129
- const poll = await fetch(`${V1}/auth/device/token`, {
130
- method: "POST",
131
- headers: { "Content-Type": "application/json" },
132
- body: JSON.stringify({ device_code }),
133
- });
136
+ await new Promise((r) => setTimeout(r, pollInterval * 1000));
137
+ let poll;
138
+ try {
139
+ poll = await fetch(`${V1}/auth/device/token`, {
140
+ method: "POST",
141
+ headers: { "Content-Type": "application/json" },
142
+ body: JSON.stringify({ device_code }),
143
+ });
144
+ } catch {
145
+ continue; // Transient network error; retry on next poll tick
146
+ }
134
147
  if (poll.status === 202) continue; // authorization_pending
135
148
  if (!poll.ok) {
136
149
  const e = await poll.json().catch(() => ({}));