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:
parent
18dcf789c8
commit
09d800eee9
|
|
@ -79,6 +79,14 @@ type SessionRecord = {
|
||||||
updatedAt: number;
|
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 = {
|
type InstallStep = {
|
||||||
name: string;
|
name: string;
|
||||||
result: CommandRunResult;
|
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 });
|
const loginResult = await postText("/launcher/profile/login", { username });
|
||||||
if (!loginResult.ok) {
|
if (!loginResult.ok) {
|
||||||
return { ok: false, error: loginResult.error ?? "login_failed", url: loginResult.url };
|
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 isSessionInvalidStatus = (status?: number) => status === 401 || status === 403;
|
||||||
|
|
||||||
const getSessionIdForUser = async (username: string) => {
|
const getSessionIdForUser = async (username: string): Promise<SessionLookupResult> => {
|
||||||
const cached = await readSessionRecord();
|
const cached = await readSessionRecord();
|
||||||
if (cached && cached.username === username && !isSessionExpired(cached)) {
|
if (cached && cached.username === username && !isSessionExpired(cached)) {
|
||||||
await refreshSessionRecord({ username: cached.username, sessionId: cached.sessionId });
|
await refreshSessionRecord({ username: cached.username, sessionId: cached.sessionId });
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue