Menu
Public repository / 0216cf0f6008aae88a648a82e9b3a462a6688302
AkurAI-Mail / src/lib/webmail/session.ts
Latest change 0d7f5f902b20084326479f36d4ccf2b55ee890c0 - OLI-317: scheduled sends read the API's payload field (legacy message kept) by Ólafur Búi Ólafsson
/** Normalizes /api/auth/check into the signed-in webmail session. */
export interface AuthCheck {
authenticated?: boolean;
admin?: boolean;
email?: string;
user?: string;
mailbox?: string;
method?: string;
}
export function webmailSession(check: AuthCheck) {
return {
signedIn: !!check.authenticated,
email: check.email || check.user || check.mailbox || "",
admin: check.admin ?? check.method === "password",
};
}
/** A scheduled send as the API lists it: the body is `payload`, older records say `message`. */
export interface ScheduledSendView {
id: string;
status: string;
sendAt: number;
subject: string;
to: string;
}
function recipients(value: unknown): string {
if (Array.isArray(value)) return value.filter((v) => typeof v === "string").join(", ");
return typeof value === "string" ? value : "";
}
export function scheduledSendView(item: Record<string, any>): ScheduledSendView {
const body = item.payload ?? item.message;
const message = body && typeof body === "object" ? body : {};
return {
id: String(item.id ?? ""),
status: String(item.status ?? ""),
sendAt: Number(item.send_at) || 0,
subject: typeof message.subject === "string" ? message.subject : "",
to: recipients(message.to),
};
}