@gheima/cli 0.9.1 → 0.9.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/CHANGELOG.md +6 -0
- package/dist/cli.js +3 -1
- package/dist/device-login.js +15 -3
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @gheima/cli
|
|
2
2
|
|
|
3
|
+
## 0.9.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- ff3385e: A sign-in that can no longer succeed now reports a stable error code under `--json`: `login_expired` (expired or already used) or `login_denied`, instead of the generic `error`, so a script or an agent knows to start a new one with `gheima login --no-wait`.
|
|
8
|
+
|
|
3
9
|
## 0.9.1
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
package/dist/cli.js
CHANGED
|
@@ -19,7 +19,7 @@ import { findLink, toDotenv, writeLink } from './link.js';
|
|
|
19
19
|
import { listSourceFiles, packSource } from './pack.js';
|
|
20
20
|
import { defaultServiceName, gitRemote, gitSubdir } from './git-remote.js';
|
|
21
21
|
import { AGENTS_FILE, agentsSection, upsertAgentsMd } from './agents-md.js';
|
|
22
|
-
import { clearPendingLogin, defaultClientName, loadPendingLogin, LoginStillPending, openBrowser, pollForApproval, savePendingLogin, startDeviceLogin, } from './device-login.js';
|
|
22
|
+
import { clearPendingLogin, defaultClientName, loadPendingLogin, LoginEnded, LoginStillPending, openBrowser, pollForApproval, savePendingLogin, startDeviceLogin, } from './device-login.js';
|
|
23
23
|
const program = new Command();
|
|
24
24
|
program
|
|
25
25
|
.name('gheima')
|
|
@@ -85,6 +85,8 @@ function localErrorCode(err) {
|
|
|
85
85
|
return 'unauthenticated';
|
|
86
86
|
if (err instanceof LoginStillPending)
|
|
87
87
|
return 'login_pending';
|
|
88
|
+
if (err instanceof LoginEnded)
|
|
89
|
+
return err.code;
|
|
88
90
|
return 'error';
|
|
89
91
|
}
|
|
90
92
|
/**
|
package/dist/device-login.js
CHANGED
|
@@ -90,6 +90,18 @@ export class LoginStillPending extends Error {
|
|
|
90
90
|
'`gheima login --resume` once they say they have approved.');
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
|
+
/**
|
|
94
|
+
* A sign-in that can no longer succeed: it expired, was already used, or was denied. Carries a
|
|
95
|
+
* stable `code` so a script or an agent knows to start a new one with `login --no-wait`.
|
|
96
|
+
*/
|
|
97
|
+
export class LoginEnded extends Error {
|
|
98
|
+
code;
|
|
99
|
+
name = 'LoginEnded';
|
|
100
|
+
constructor(message, code) {
|
|
101
|
+
super(message);
|
|
102
|
+
this.code = code;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
93
105
|
const defaultSleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
94
106
|
/**
|
|
95
107
|
* Poll until the login is approved, denied or expires.
|
|
@@ -106,7 +118,7 @@ export async function pollForApproval(baseUrl, start, opts = {}) {
|
|
|
106
118
|
let intervalMs = Math.max(1, start.interval) * 1000;
|
|
107
119
|
for (;;) {
|
|
108
120
|
if (now() >= deadline) {
|
|
109
|
-
throw new
|
|
121
|
+
throw new LoginEnded(`This sign-in expired before it was approved. ${restart}`, 'login_expired');
|
|
110
122
|
}
|
|
111
123
|
if (opts.giveUpAt !== undefined && now() >= opts.giveUpAt)
|
|
112
124
|
throw new LoginStillPending();
|
|
@@ -127,9 +139,9 @@ export async function pollForApproval(baseUrl, start, opts = {}) {
|
|
|
127
139
|
opts.onSlowDown?.(Math.round(intervalMs / 1000));
|
|
128
140
|
break;
|
|
129
141
|
case 'access_denied':
|
|
130
|
-
throw new
|
|
142
|
+
throw new LoginEnded(`The sign-in was denied in the dashboard. ${restart}`, 'login_denied');
|
|
131
143
|
case 'expired_token':
|
|
132
|
-
throw new
|
|
144
|
+
throw new LoginEnded(`This sign-in expired or was already used. ${restart}`, 'login_expired');
|
|
133
145
|
default:
|
|
134
146
|
throw new Error(body.error?.message ?? `Sign-in failed (HTTP ${res.status}). ${restart}`);
|
|
135
147
|
}
|
package/dist/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// GENERATED by scripts/write-version.mjs from package.json. Do not edit.
|
|
2
|
-
export const VERSION = '0.9.
|
|
2
|
+
export const VERSION = '0.9.2';
|