import {z} from 'zod' export type CalendarVratsInput = {year: number, latitude: number | null, longitude: number | null, timezone?: string | undefined, timezoneOffset?: (number | null) | undefined, ayanamsaId?: (number | null) | undefined, ayanamsa?: ('fagan-bradley' | 'lahiri' | 'de-luce' | 'raman' | 'krishnamurti' | 'kp' | 'yukteshwar' | 'jn-bhasin' | 'true-citra' | 'djwhal-khul') | undefined, types?: (Array<'ekadashi' | 'pradosh' | 'sankashti' | 'purnima' | 'amavasya' | 'masik-shivaratri'>) | undefined}; export type CreateApiVedicCalendarVratsArgs = {fields?: string | undefined, precision?: number | undefined, 'Idempotency-Key'?: string | undefined, body: CalendarVratsInput}; export type CreateApiVedicCalendarVratsOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiVedicCalendarVratsResponse = z.object({ok: z.boolean().optional(), data: z.object({year: z.number().nullable().optional(), place: z.object({latitude: z.number().nullable().optional(), longitude: z.number().nullable().optional(), timezone: z.string().nullable().optional(), timezoneOffset: z.unknown(), ayanamsaId: z.number().nullable().optional()}).nullable().optional(), types: z.array(z.string().nullable()).nullable().optional(), count: z.number().nullable().optional(), vrats: z.array(z.object({type: z.string().nullable().optional(), name: z.string().nullable().optional(), date: z.string().nullable().optional(), observance: z.unknown(), rule: z.string().nullable().optional(), source: z.string().nullable().optional(), kala: z.string().nullable().optional(), observedWindow: z.unknown(), tithi: z.object({number: z.number().nullable().optional(), name: z.string().nullable().optional(), paksha: z.string().nullable().optional(), start: z.string().nullable().optional(), end: z.string().nullable().optional()}).nullable().optional(), month: z.object({amanta: z.string().nullable().optional(), purnimanta: z.string().nullable().optional()}).nullable().optional(), moonrise: z.string().nullable().optional()}).nullable()).nullable().optional()}).optional()}); 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 }; /** * Hindu calendar: vrats (Ekadashi with parana, Pradosh, Sankashti, Purnima, Amavasya, Masik Shivaratri) * * POST /vedic/calendar/vrats */ export const createApiVedicCalendarVrats = async (args: CreateApiVedicCalendarVratsArgs, options?: CreateApiVedicCalendarVratsOptions) => { const {baseUrl = "https://api.astroway.info/v1", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.fields != null) query.append("fields", String(args.fields)) if (args.precision != null) query.append("precision", String(args.precision)) if (args['Idempotency-Key'] != null) headers.set("Idempotency-Key", String(args['Idempotency-Key'])) if (ApiKeyAuth !== undefined) headers.set("X-Api-Key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/vedic/calendar/vrats${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(createApiVedicCalendarVratsResponse, await res.json()) };