import {z} from 'zod' export type BiorhythmBestDays = {birthDate: string, rangeStart?: string | undefined, rangeEnd?: string | undefined, count?: number | undefined, excludeCritical?: boolean | undefined}; export type CreateApiWellnessBiorhythmBestDaysArgs = {fields?: string | undefined, precision?: number | undefined, 'Idempotency-Key'?: string | undefined, body: BiorhythmBestDays}; export type CreateApiWellnessBiorhythmBestDaysOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiWellnessBiorhythmBestDaysResponse = z.object({ok: z.boolean().optional(), data: z.object({birthDate: z.string().nullable().optional(), range: z.object({start: z.string().nullable().optional(), end: z.string().nullable().optional(), days: z.number().nullable().optional()}).nullable().optional(), bestDays: z.array(z.object({date: z.string().nullable().optional(), dayOfLife: z.number().nullable().optional(), physical: z.number().nullable().optional(), emotional: z.number().nullable().optional(), intellectual: z.number().nullable().optional(), critical: z.array(z.unknown()).nullable().optional(), score: z.number().nullable().optional()}).nullable()).nullable().optional(), formula: z.string().nullable().optional(), disclaimer: z.string().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 }; /** * Biorhythm Best Days * * POST /wellness/biorhythm/best-days */ export const createApiWellnessBiorhythmBestDays = async (args: CreateApiWellnessBiorhythmBestDaysArgs, options?: CreateApiWellnessBiorhythmBestDaysOptions) => { 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(/\/+$/, '')}/wellness/biorhythm/best-days${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(createApiWellnessBiorhythmBestDaysResponse, await res.json()) };