import {z} from 'zod' export type GetApiPayoutHoldsPayoutHoldIdArgs = {payout_hold_id: string, Authorization: string}; export type GetApiPayoutHoldsPayoutHoldIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiPayoutHoldsPayoutHoldIdResponse = z.object({id: z.string().optional(), type: z.string().optional(), data: z.object({id: z.string().optional(), account_id: z.string().optional(), hold_type: z.enum(["first_payment", "manual"]).optional(), issued_by: z.enum(["system", "platform"]).optional(), start_date: z.string().optional(), end_date: z.string().nullable().optional(), active: z.boolean().optional(), created_at: z.string().optional(), updated_at: z.string().optional()}).optional(), page_info: z.unknown()}); 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 a Payout Hold * * GET /payout_holds/{payout_hold_id} */ export const getApiPayoutHoldsPayoutHoldId = async (args: GetApiPayoutHoldsPayoutHoldIdArgs, options?: GetApiPayoutHoldsPayoutHoldIdOptions) => { const {baseUrl = "https://api.justifi.ai/v1", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.Authorization != null) headers.set("Authorization", String(args.Authorization)) const url = `${baseUrl.replace(/\/+$/, '')}/payout_holds/${encodeURIComponent(String(args.payout_hold_id))}${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(getApiPayoutHoldsPayoutHoldIdResponse, await res.json()) };