@zalify/cli 0.2.0 → 0.2.1
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/cli.js +27 -16
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -11352,6 +11352,7 @@ async function login(options) {
|
|
|
11352
11352
|
const result = await new Promise((resolvePromise, reject) => {
|
|
11353
11353
|
const timer = setTimeout(() => {
|
|
11354
11354
|
server.close();
|
|
11355
|
+
server.closeAllConnections();
|
|
11355
11356
|
reject(new Error("Login timed out after 5 minutes."));
|
|
11356
11357
|
}, LOGIN_TIMEOUT_MS);
|
|
11357
11358
|
const server = createServer((req, res) => {
|
|
@@ -11360,11 +11361,18 @@ async function login(options) {
|
|
|
11360
11361
|
res.writeHead(404).end();
|
|
11361
11362
|
return;
|
|
11362
11363
|
}
|
|
11363
|
-
const done = (message) => {
|
|
11364
|
-
res.writeHead(200, {
|
|
11364
|
+
const done = (message, after) => {
|
|
11365
|
+
res.writeHead(200, {
|
|
11366
|
+
"Content-Type": "text/html",
|
|
11367
|
+
Connection: "close"
|
|
11368
|
+
});
|
|
11365
11369
|
res.end(`<!doctype html><meta charset="utf-8"><title>Zalify CLI</title>
|
|
11366
11370
|
<body style="font-family:system-ui;display:grid;place-items:center;height:100vh;margin:0">
|
|
11367
|
-
<p>${message} You can close this tab.</p></body
|
|
11371
|
+
<p>${message} You can close this tab.</p></body>`, after);
|
|
11372
|
+
};
|
|
11373
|
+
const teardown = () => {
|
|
11374
|
+
server.close();
|
|
11375
|
+
server.closeAllConnections();
|
|
11368
11376
|
};
|
|
11369
11377
|
if (url.searchParams.get("state") !== state) {
|
|
11370
11378
|
done("Login failed: state mismatch.");
|
|
@@ -11373,25 +11381,28 @@ async function login(options) {
|
|
|
11373
11381
|
clearTimeout(timer);
|
|
11374
11382
|
const error = url.searchParams.get("error");
|
|
11375
11383
|
if (error) {
|
|
11376
|
-
done("Authorization was denied.")
|
|
11377
|
-
|
|
11378
|
-
|
|
11384
|
+
done("Authorization was denied.", () => {
|
|
11385
|
+
teardown();
|
|
11386
|
+
reject(new Error(`Authorization denied (${error}).`));
|
|
11387
|
+
});
|
|
11379
11388
|
return;
|
|
11380
11389
|
}
|
|
11381
11390
|
const key = url.searchParams.get("key");
|
|
11382
11391
|
if (!key) {
|
|
11383
|
-
done("Login failed: no key in callback.")
|
|
11384
|
-
|
|
11385
|
-
|
|
11392
|
+
done("Login failed: no key in callback.", () => {
|
|
11393
|
+
teardown();
|
|
11394
|
+
reject(new Error("Callback did not include a key."));
|
|
11395
|
+
});
|
|
11386
11396
|
return;
|
|
11387
11397
|
}
|
|
11388
|
-
done("Logged in!")
|
|
11389
|
-
|
|
11390
|
-
|
|
11391
|
-
|
|
11392
|
-
|
|
11393
|
-
|
|
11394
|
-
|
|
11398
|
+
done("Logged in!", () => {
|
|
11399
|
+
teardown();
|
|
11400
|
+
resolvePromise({
|
|
11401
|
+
key,
|
|
11402
|
+
workspaceId: url.searchParams.get("workspace_id") ?? "",
|
|
11403
|
+
workspaceName: url.searchParams.get("workspace_name") ?? "",
|
|
11404
|
+
workspaceSlug: url.searchParams.get("workspace_slug") ?? ""
|
|
11405
|
+
});
|
|
11395
11406
|
});
|
|
11396
11407
|
});
|
|
11397
11408
|
server.listen(0, "127.0.0.1", () => {
|