@vocoder/cli 0.13.4 → 0.14.0
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/bin.mjs
CHANGED
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
readAuthData,
|
|
14
14
|
verifyStoredAuth,
|
|
15
15
|
writeAuthData
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-T4BLNDJ3.mjs";
|
|
17
17
|
|
|
18
18
|
// src/bin.ts
|
|
19
19
|
import { Command } from "commander";
|
|
@@ -1494,46 +1494,71 @@ async function runAuthFlow(api, options, reauth = false, repoCanonical) {
|
|
|
1494
1494
|
let rawToken = null;
|
|
1495
1495
|
let callbackOrganizationId;
|
|
1496
1496
|
let callbackDiscoveryReady = false;
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
]);
|
|
1507
|
-
if (params && typeof params.token === "string") {
|
|
1508
|
-
rawToken = params.token;
|
|
1509
|
-
if (typeof params.organizationId === "string" && params.organizationId) {
|
|
1510
|
-
callbackOrganizationId = params.organizationId;
|
|
1511
|
-
}
|
|
1512
|
-
if (params.discovery_ready === "1") {
|
|
1513
|
-
callbackDiscoveryReady = true;
|
|
1497
|
+
const deadline = Math.min(expiresAt, Date.now() + 10 * 60 * 1e3);
|
|
1498
|
+
let stopPolling = false;
|
|
1499
|
+
const serverCallback = server ? server.waitForCallback().catch(() => null) : Promise.resolve(null);
|
|
1500
|
+
const sessionPoll = (async () => {
|
|
1501
|
+
while (!stopPolling && Date.now() < expiresAt) {
|
|
1502
|
+
try {
|
|
1503
|
+
const result = await api.pollCliAuthSession(session.sessionId);
|
|
1504
|
+
if (result.status === "complete" || result.status === "failed") {
|
|
1505
|
+
return result;
|
|
1514
1506
|
}
|
|
1507
|
+
} catch {
|
|
1515
1508
|
}
|
|
1516
|
-
|
|
1517
|
-
} finally {
|
|
1518
|
-
server.close();
|
|
1509
|
+
if (!stopPolling) await sleep(2e3);
|
|
1519
1510
|
}
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1511
|
+
return null;
|
|
1512
|
+
})();
|
|
1513
|
+
const winner = await new Promise((resolve2) => {
|
|
1514
|
+
let done = false;
|
|
1515
|
+
serverCallback.then((params) => {
|
|
1516
|
+
if (done || params === null || typeof params.token !== "string") return;
|
|
1517
|
+
done = true;
|
|
1518
|
+
resolve2({ kind: "server", params });
|
|
1519
|
+
}).catch(() => {
|
|
1520
|
+
});
|
|
1521
|
+
sessionPoll.then((result) => {
|
|
1522
|
+
if (done || result === null) return;
|
|
1523
|
+
if (result.status === "complete" || result.status === "failed") {
|
|
1524
|
+
done = true;
|
|
1525
|
+
resolve2({
|
|
1526
|
+
kind: "poll",
|
|
1527
|
+
result
|
|
1528
|
+
});
|
|
1529
|
+
}
|
|
1530
|
+
}).catch(() => {
|
|
1531
|
+
});
|
|
1532
|
+
setTimeout(
|
|
1533
|
+
() => {
|
|
1534
|
+
if (!done) {
|
|
1535
|
+
done = true;
|
|
1536
|
+
resolve2(null);
|
|
1528
1537
|
}
|
|
1529
|
-
|
|
1538
|
+
},
|
|
1539
|
+
Math.max(0, deadline - Date.now())
|
|
1540
|
+
);
|
|
1541
|
+
});
|
|
1542
|
+
stopPolling = true;
|
|
1543
|
+
server?.close();
|
|
1544
|
+
if (winner !== null) {
|
|
1545
|
+
if (winner.kind === "server") {
|
|
1546
|
+
rawToken = winner.params.token;
|
|
1547
|
+
if (typeof winner.params.organizationId === "string" && winner.params.organizationId) {
|
|
1548
|
+
callbackOrganizationId = winner.params.organizationId;
|
|
1530
1549
|
}
|
|
1531
|
-
if (
|
|
1532
|
-
|
|
1533
|
-
p5.log.error(result.reason);
|
|
1534
|
-
return null;
|
|
1550
|
+
if (winner.params.discovery_ready === "1") {
|
|
1551
|
+
callbackDiscoveryReady = true;
|
|
1535
1552
|
}
|
|
1536
|
-
|
|
1553
|
+
} else if (winner.result.status === "complete") {
|
|
1554
|
+
rawToken = winner.result.token;
|
|
1555
|
+
if (winner.result.organizationId) {
|
|
1556
|
+
callbackOrganizationId = winner.result.organizationId;
|
|
1557
|
+
}
|
|
1558
|
+
} else {
|
|
1559
|
+
authSpinner.stop();
|
|
1560
|
+
p5.log.error(winner.result.reason);
|
|
1561
|
+
return null;
|
|
1537
1562
|
}
|
|
1538
1563
|
}
|
|
1539
1564
|
if (!rawToken) {
|