@sentio/cli 4.4.0-rc.1 → 4.4.0-rc.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/dist/index.js +14 -9
- package/package.json +1 -1
- package/src/commands/login-server.ts +17 -12
package/dist/index.js
CHANGED
|
@@ -46186,7 +46186,8 @@ function isAccessTokenExpired(expiresAt) {
|
|
|
46186
46186
|
function startServer(params) {
|
|
46187
46187
|
return new Promise((resolve, reject) => {
|
|
46188
46188
|
const app = (0, import_express.default)();
|
|
46189
|
-
let
|
|
46189
|
+
let redemption;
|
|
46190
|
+
let responses = 0;
|
|
46190
46191
|
let settled = false;
|
|
46191
46192
|
const controller = new AbortController();
|
|
46192
46193
|
const finish = (error) => {
|
|
@@ -46209,13 +46210,14 @@ function startServer(params) {
|
|
|
46209
46210
|
res.status(400).end("Invalid authorization state");
|
|
46210
46211
|
return;
|
|
46211
46212
|
}
|
|
46212
|
-
|
|
46213
|
-
res.status(409).end("Authorization already in progress");
|
|
46214
|
-
return;
|
|
46215
|
-
}
|
|
46216
|
-
redeeming = true;
|
|
46213
|
+
responses++;
|
|
46217
46214
|
const respond = (message, error) => {
|
|
46218
|
-
|
|
46215
|
+
let completed = false;
|
|
46216
|
+
const complete = () => {
|
|
46217
|
+
if (completed) return;
|
|
46218
|
+
completed = true;
|
|
46219
|
+
if (--responses === 0) finish(error);
|
|
46220
|
+
};
|
|
46219
46221
|
if (res.destroyed) return complete();
|
|
46220
46222
|
res.once("close", complete);
|
|
46221
46223
|
res.status(error ? 400 : 200).end(message, complete);
|
|
@@ -46223,8 +46225,11 @@ function startServer(params) {
|
|
|
46223
46225
|
try {
|
|
46224
46226
|
if (req.query.error) throw new Error("Authorization was not completed");
|
|
46225
46227
|
if (typeof req.query.code !== "string" || !req.query.code) throw new Error("Missing authorization code");
|
|
46226
|
-
|
|
46227
|
-
|
|
46228
|
+
redemption ??= exchangeCodeAndSave(getFinalizedHost(params.sentioHost), req.query.code, params.codeVerifier, params.authConfig, controller.signal).then((username) => {
|
|
46229
|
+
console.log(chalk.green(`Login success with ${username}`));
|
|
46230
|
+
return username;
|
|
46231
|
+
});
|
|
46232
|
+
await redemption;
|
|
46228
46233
|
respond("Login success, please go back to CLI to continue");
|
|
46229
46234
|
} catch (error) {
|
|
46230
46235
|
respond("Login failed. Check the terminal and try again.", error);
|
package/package.json
CHANGED
|
@@ -20,7 +20,8 @@ interface AuthParams {
|
|
|
20
20
|
export function startServer(params: AuthParams): Promise<void> {
|
|
21
21
|
return new Promise((resolve, reject) => {
|
|
22
22
|
const app = express()
|
|
23
|
-
let
|
|
23
|
+
let redemption: Promise<string> | undefined
|
|
24
|
+
let responses = 0
|
|
24
25
|
let settled = false
|
|
25
26
|
const controller = new AbortController()
|
|
26
27
|
const finish = (error?: Error) => {
|
|
@@ -46,15 +47,16 @@ export function startServer(params: AuthParams): Promise<void> {
|
|
|
46
47
|
res.status(400).end('Invalid authorization state')
|
|
47
48
|
return
|
|
48
49
|
}
|
|
49
|
-
|
|
50
|
-
res.status(409).end('Authorization already in progress')
|
|
51
|
-
return
|
|
52
|
-
}
|
|
53
|
-
redeeming = true
|
|
50
|
+
responses++
|
|
54
51
|
const respond = (message: string, error?: Error) => {
|
|
55
|
-
//
|
|
56
|
-
//
|
|
57
|
-
|
|
52
|
+
// Browsers may interrupt and retry the navigation during redemption.
|
|
53
|
+
// Flush every waiting response before closing the shared listener.
|
|
54
|
+
let completed = false
|
|
55
|
+
const complete = () => {
|
|
56
|
+
if (completed) return
|
|
57
|
+
completed = true
|
|
58
|
+
if (--responses === 0) finish(error)
|
|
59
|
+
}
|
|
58
60
|
if (res.destroyed) return complete()
|
|
59
61
|
res.once('close', complete)
|
|
60
62
|
res.status(error ? 400 : 200).end(message, complete)
|
|
@@ -62,14 +64,17 @@ export function startServer(params: AuthParams): Promise<void> {
|
|
|
62
64
|
try {
|
|
63
65
|
if (req.query.error) throw new Error('Authorization was not completed')
|
|
64
66
|
if (typeof req.query.code !== 'string' || !req.query.code) throw new Error('Missing authorization code')
|
|
65
|
-
|
|
67
|
+
redemption ??= exchangeCodeAndSave(
|
|
66
68
|
getFinalizedHost(params.sentioHost),
|
|
67
69
|
req.query.code,
|
|
68
70
|
params.codeVerifier,
|
|
69
71
|
params.authConfig,
|
|
70
72
|
controller.signal
|
|
71
|
-
)
|
|
72
|
-
|
|
73
|
+
).then((username) => {
|
|
74
|
+
console.log(chalk.green(`Login success with ${username}`))
|
|
75
|
+
return username
|
|
76
|
+
})
|
|
77
|
+
await redemption
|
|
73
78
|
respond('Login success, please go back to CLI to continue')
|
|
74
79
|
} catch (error) {
|
|
75
80
|
respond('Login failed. Check the terminal and try again.', error as Error)
|