@rayul/kordis 0.6.5 → 0.6.6
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 +44 -19
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1204,6 +1204,7 @@ import { join as join2 } from "path";
|
|
|
1204
1204
|
var SERVICE = "kordis";
|
|
1205
1205
|
var plaintextWarningEmitted = false;
|
|
1206
1206
|
async function loadKeytar() {
|
|
1207
|
+
if (process.env["KORDIS_NO_KEYCHAIN"] === "1") return null;
|
|
1207
1208
|
try {
|
|
1208
1209
|
const mod = await import("keytar");
|
|
1209
1210
|
return mod.default ?? mod;
|
|
@@ -1583,29 +1584,53 @@ async function useClient() {
|
|
|
1583
1584
|
baseUrl: cfg.apiUrl,
|
|
1584
1585
|
userAgent: `kordis-cli/${VERSION} node/${process.version}`
|
|
1585
1586
|
});
|
|
1587
|
+
const debug = process.env["KORDIS_DEBUG"] === "1";
|
|
1588
|
+
let pollResult = null;
|
|
1586
1589
|
try {
|
|
1587
|
-
|
|
1588
|
-
const meClient = new KordisClient({
|
|
1589
|
-
baseUrl: cfg.apiUrl,
|
|
1590
|
-
userAgent: `kordis-cli/${VERSION} node/${process.version}`,
|
|
1591
|
-
getAccessToken: () => tokens.access_token
|
|
1592
|
-
});
|
|
1593
|
-
const me = await meClient.me();
|
|
1594
|
-
username = me.username;
|
|
1595
|
-
currentTokens = {
|
|
1596
|
-
access_token: tokens.access_token,
|
|
1597
|
-
refresh_token: tokens.refresh_token,
|
|
1598
|
-
session_id: tokens.session_id,
|
|
1599
|
-
expires_at_epoch: Math.floor(Date.now() / 1e3) + tokens.expires_in
|
|
1600
|
-
};
|
|
1601
|
-
await keychain.save(username, currentTokens);
|
|
1602
|
-
cfg = { ...cfg, username, sessionId: tokens.session_id };
|
|
1603
|
-
await saveCliConfig(cfg);
|
|
1604
|
-
await clearPending();
|
|
1590
|
+
pollResult = await bootstrapApi.pollDeviceFlow(pending.device_code);
|
|
1605
1591
|
} catch (err) {
|
|
1606
1592
|
const code = err.code;
|
|
1607
|
-
if (code
|
|
1593
|
+
if (code === "authorization_pending") {
|
|
1594
|
+
if (debug) process.stderr.write("[kordis] auto-finalize: authorization_pending (keeping pending)\n");
|
|
1595
|
+
} else {
|
|
1608
1596
|
await clearPending();
|
|
1597
|
+
if (debug) {
|
|
1598
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
1599
|
+
process.stderr.write(`[kordis] auto-finalize: poll failed (code=${code ?? "none"}): ${msg}
|
|
1600
|
+
`);
|
|
1601
|
+
}
|
|
1602
|
+
}
|
|
1603
|
+
}
|
|
1604
|
+
if (pollResult) {
|
|
1605
|
+
try {
|
|
1606
|
+
const meClient = new KordisClient({
|
|
1607
|
+
baseUrl: cfg.apiUrl,
|
|
1608
|
+
userAgent: `kordis-cli/${VERSION} node/${process.version}`,
|
|
1609
|
+
getAccessToken: () => pollResult.access_token
|
|
1610
|
+
});
|
|
1611
|
+
const me = await meClient.me();
|
|
1612
|
+
username = me.username;
|
|
1613
|
+
currentTokens = {
|
|
1614
|
+
access_token: pollResult.access_token,
|
|
1615
|
+
refresh_token: pollResult.refresh_token,
|
|
1616
|
+
session_id: pollResult.session_id,
|
|
1617
|
+
expires_at_epoch: Math.floor(Date.now() / 1e3) + pollResult.expires_in
|
|
1618
|
+
};
|
|
1619
|
+
await keychain.save(username, currentTokens);
|
|
1620
|
+
cfg = { ...cfg, username, sessionId: pollResult.session_id };
|
|
1621
|
+
await saveCliConfig(cfg);
|
|
1622
|
+
await clearPending();
|
|
1623
|
+
if (debug) process.stderr.write(`[kordis] auto-finalize: persisted tokens for ${username}
|
|
1624
|
+
`);
|
|
1625
|
+
} catch (err) {
|
|
1626
|
+
await clearPending();
|
|
1627
|
+
currentTokens = null;
|
|
1628
|
+
username = null;
|
|
1629
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
1630
|
+
process.stderr.write(
|
|
1631
|
+
`[kordis] auto-finalize: server issued tokens but local persistence failed (${msg}). Run \`kordis login --emit-only\` again to retry.
|
|
1632
|
+
`
|
|
1633
|
+
);
|
|
1609
1634
|
}
|
|
1610
1635
|
}
|
|
1611
1636
|
}
|