import {z} from 'zod' export type BiorhythmCompatibility = {birthDateA: string, birthDateB: string}; export type CreateApiWellnessBiorhythmCompatibilityArgs = {fields?: string | undefined, precision?: number | undefined, 'Idempotency-Key'?: string | undefined, body: BiorhythmCompatibility}; export type CreateApiWellnessBiorhythmCompatibilityOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiWellnessBiorhythmCompatibilityResponse = z.object({ok: z.boolean().optional(), data: z.object({birthDateA: z.string().nullable().optional(), birthDateB: z.string().nullable().optional(), daysApart: z.number().nullable().optional(), cycles: z.array(z.object({name: z.string().nullable().optional(), periodDays: z.number().nullable().optional(), phaseOffsetDays: z.number().nullable().optional(), syncPercent: z.number().nullable().optional()}).nullable()).nullable().optional(), overallPercent: z.number().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 Compatibility * * POST /wellness/biorhythm/compatibility */ export const createApiWellnessBiorhythmCompatibility = async (args: CreateApiWellnessBiorhythmCompatibilityArgs, options?: CreateApiWellnessBiorhythmCompatibilityOptions) => { 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/compatibility${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(createApiWellnessBiorhythmCompatibilityResponse, await res.json()) };