import {z} from 'zod' export type GetApiApiV1UserUserwhatsappIdUserWhatsAppArgs = {userwhatsapp_id: string}; export type GetApiApiV1UserUserwhatsappIdUserWhatsAppOptions = {baseUrl: string, YourAPIKey?: string | undefined, fetch?: typeof fetch | undefined}; export const iUserWhatsAppRead = z.object({phone_number_id: z.string().nullable(), phone_business_id: z.string().nullable(), facebook_app_secret: z.string().nullable(), whatsapp_access_token: z.string().nullable(), whatsapp_phone_number: z.string().nullable(), id: z.string(), updated_at: z.string()}); export const iGetResponseBaseIUserWhatsAppRead = z.object({message: z.string().nullable().optional(), meta: z.union([z.record(z.string(), z.unknown()), z.unknown()]).nullable().optional(), data: iUserWhatsAppRead.nullable().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 }; /** * Get Userwhatsapp By Id * * GET /api/v1/user/{userwhatsapp_id}/UserWhatsApp * * Also accepts auth: HTTPBearer */ export const getApiApiV1UserUserwhatsappIdUserWhatsApp = async (args: GetApiApiV1UserUserwhatsappIdUserWhatsAppArgs, options: GetApiApiV1UserUserwhatsappIdUserWhatsAppOptions) => { const {baseUrl, fetch: fetchFn = fetch, YourAPIKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (YourAPIKey !== undefined) query.set("api_key", YourAPIKey) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/user/${encodeURIComponent(String(args.userwhatsapp_id))}/UserWhatsApp${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(iGetResponseBaseIUserWhatsAppRead, await res.json()) };