Replace NodeJS dict aliases with maps and named field reads
Agents / agent (pull_request) Has been skipped
Check / check (pull_request) Successful in 49s

This commit is contained in:
Danny Kim
2026-10-19 02:30:54 +09:00
parent 32806120b3
commit c8ffb9cc6f
15 changed files with 275 additions and 196 deletions
+9 -8
View File
@@ -12,7 +12,7 @@ import {
} from "node:fs/promises";
import { dirname, join } from "node:path";
import { isNotFound, isObject } from "#common";
import { field, isNotFound, isObject } from "#common";
interface CodexApiKey {
kind: "api-key";
@@ -89,15 +89,16 @@ async function readCodexAuth(path: string): Promise<string> {
} catch {
throw new Error("invalid Codex login");
}
const tokens = isObject(value) ? value["tokens"] : undefined;
const authMode = field(value, "auth_mode");
const tokens = field(value, "tokens");
if (
!isObject(value) ||
typeof value["auth_mode"] !== "string" ||
value["auth_mode"] === "" ||
typeof authMode !== "string" ||
authMode === "" ||
!isObject(tokens) ||
!["access_token", "refresh_token", "id_token", "account_id"].every(
(name) => typeof tokens[name] === "string" && tokens[name] !== "",
)
!["access_token", "refresh_token", "id_token", "account_id"].every((name) => {
const token = field(tokens, name);
return typeof token === "string" && token !== "";
})
) {
throw new Error("invalid Codex login");
}