import {z} from 'zod' export type PatchApiV0PayeesPayeeIdArgs = {'payee-id': string, body: {'cop-request-url'?: (string | string) | undefined, 'payee-status'?: 'deactivated' | undefined}}; export type PatchApiV0PayeesPayeeIdOptions = {baseUrl?: string | undefined, apiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const patchApiV0PayeesPayeeIdResponse = z.object({"cop-request-url": z.union([z.string(), z.string()]).optional(), "payee-url": z.union([z.string(), z.string()]), "account-number": z.string().min(8).max(8), "account-holder": z.string().min(1), "legal-person-url": z.union([z.string(), z.string()]), "bank-id": z.string().min(6).max(6), "created-at": z.string(), "account-url": z.union([z.string(), z.string()]).optional(), "payee-status": z.enum(["deactivated", "active"]), "country-code": z.string().min(2).max(2)}); 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 }; /** * Update payee * * PATCH /v0/payees/{payee-id} */ export const patchApiV0PayeesPayeeId = async (args: PatchApiV0PayeesPayeeIdArgs, options?: PatchApiV0PayeesPayeeIdOptions) => { const {baseUrl = "https://api.griffin.com", 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 (apiKeyAuth !== undefined) headers.set("Authorization", apiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/v0/payees/${encodeURIComponent(String(args['payee-id']))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(patchApiV0PayeesPayeeIdResponse, await res.json()) };