import {z} from 'zod' export type GetApiPayoutsIdArgs = {id: string}; export type GetApiPayoutsIdOptions = {baseUrl?: string | undefined, BasicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const payout = z.object({id: z.string().optional(), integration: z.string().optional(), srcId: z.string().optional(), amount: z.number().int().optional(), arrivalDate: z.string().nullable().optional(), automatic: z.string().nullable().optional(), balanceTransactionId: z.string().nullable().optional(), created: z.string().nullable().optional(), currency: z.string().nullable().optional(), payoutDescription: z.string().nullable().optional(), destinationId: z.string().nullable().optional(), failureBalanceTransactionId: z.string().nullable().optional(), failureCode: z.string().nullable().optional(), failureMessage: z.string().nullable().optional(), method: z.string().nullable().optional(), sourceType: z.string().nullable().optional(), status: z.string().nullable().optional(), payoutType: z.string().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 }; /** * Retrieves a Payout resource. * * GET /payouts/{id} */ export const getApiPayoutsId = async (args: GetApiPayoutsIdArgs, options?: GetApiPayoutsIdOptions) => { const {baseUrl = "https://example.myintranetapps.com/api", fetch: fetchFn = fetch, BasicAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (BasicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${BasicAuth.username}:${BasicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/payouts/${encodeURIComponent(String(args.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(payout, await res.json()) };