Files
spsays-training/lib/vani.ts
T
2026-07-11 00:57:35 +05:30

35 lines
1.0 KiB
TypeScript

/**
* Client for "Vāṇī of the Day" — the home page's daily content pick.
*
* Public endpoint (no auth): the BFF returns the same pick to everyone for the
* current day, chosen from a prose chapter, verse, or transcript and not
* repeated within 90 days.
*/
const BFF_BASE = process.env.NEXT_PUBLIC_BFF_URL || "http://localhost:8080";
export type Vani = {
kind: "verse" | "prose" | "transcript";
label: string; // "Verse" | "Chapter" | "Lecture" | "Conversation"
title: string;
subtitle: string;
href: string;
book_title?: string;
date?: string; // transcript date, for the "Lecture • DATE" line
};
type Envelope<T> = { success?: boolean; data?: T };
export async function getVaniOfTheDay(): Promise<Vani | null> {
try {
const res = await fetch(`${BFF_BASE}/api/v1/vani/today`, {
headers: { Accept: "application/json" },
});
if (!res.ok) return null;
const body = (await res.json().catch(() => ({}))) as Envelope<Vani | null>;
return body.data ?? null;
} catch {
return null;
}
}