Add session request and lookup type definitions. Updated requestSessionId and getSessionIdForUser functions to include return type annotations for improved type safety and clarity in session management logic.

This commit is contained in:
이정수 2026-01-30 15:37:32 +09:00
parent 18dcf789c8
commit 09d800eee9
1 changed files with 10 additions and 2 deletions

View File

@ -79,6 +79,14 @@ type SessionRecord = {
updatedAt: number;
};
type SessionRequestResult =
| { ok: true; sessionId: string; url: string }
| { ok: false; error: string; url: string };
type SessionLookupResult =
| { ok: true; sessionId: string; url: string; source: "cache" | "login" }
| { ok: false; error: string; url: string };
type InstallStep = {
name: string;
result: CommandRunResult;
@ -936,7 +944,7 @@ const postText = async (path: string, body: unknown) => {
});
};
const requestSessionId = async (username: string) => {
const requestSessionId = async (username: string): Promise<SessionRequestResult> => {
const loginResult = await postText("/launcher/profile/login", { username });
if (!loginResult.ok) {
return { ok: false, error: loginResult.error ?? "login_failed", url: loginResult.url };
@ -952,7 +960,7 @@ const requestSessionId = async (username: string) => {
const isSessionInvalidStatus = (status?: number) => status === 401 || status === 403;
const getSessionIdForUser = async (username: string) => {
const getSessionIdForUser = async (username: string): Promise<SessionLookupResult> => {
const cached = await readSessionRecord();
if (cached && cached.username === username && !isSessionExpired(cached)) {
await refreshSessionRecord({ username: cached.username, sessionId: cached.sessionId });