import {z} from 'zod' export type GetApiApiStatusPageLztOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiStatusPageLztResponse = z.object({config: z.object({slug: z.string(), title: z.string(), description: z.string(), icon: z.string(), autoRefreshInterval: z.number().int(), theme: z.string(), published: z.boolean(), showTags: z.boolean(), customCSS: z.string(), footerText: z.string(), showPoweredBy: z.boolean(), analyticsId: z.number().int(), analyticsScriptUrl: z.string(), analyticsType: z.string(), showCertificateExpiry: z.boolean(), showOnlyLastHeartbeat: z.boolean(), rssTitle: z.string()}), incidents: z.array(z.object({id: z.number().int(), title: z.string(), content: z.string(), style: z.string(), createdDate: z.string(), lastUpdatedDate: z.string(), pin: z.boolean()})).nullable(), publicGroupList: z.array(z.object({id: z.number().int(), name: z.string(), weight: z.number().int(), monitorList: z.array(z.object({id: z.number().int(), name: z.string(), sendUrl: z.number().int(), type: z.string()}))})), maintenanceList: z.array(z.object({id: z.number().int(), title: z.string(), description: z.string(), strategy: z.string(), active: z.boolean(), status: z.string(), timeslotList: z.array(z.object({startDate: z.string(), endDate: z.string()}))})).nullable()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Get Status Page Info * * GET /api/status-page/lzt */ export const getApiApiStatusPageLzt = async (options?: GetApiApiStatusPageLztOptions) => { const {baseUrl = "https://status.lolz.live", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/api/status-page/lzt${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiApiStatusPageLztResponse, await res.json()) };