import {z} from 'zod' export type GetApiV2AccountsAidPayoutPayoutDestinationsPayoutDestinationIdBalancesArgs = {aid: unknown, payout_destination_id: string}; export type GetApiV2AccountsAidPayoutPayoutDestinationsPayoutDestinationIdBalancesOptions = {baseUrl?: string | undefined, JWT?: string | undefined, fetch?: typeof fetch | undefined}; export const payoutDestinationBalanceV2 = z.object({account_id: z.string(), payout_destination_config_id: z.string(), payout_destination_id: z.string().max(40), currency: z.string().min(3).max(3), amount: z.number().int()}); export const payoutDestinationBalancesV2 = z.array(payoutDestinationBalanceV2); export const getApiV2AccountsAidPayoutPayoutDestinationsPayoutDestinationIdBalancesResponse = z.object({payout_destination_balances: payoutDestinationBalancesV2.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 }; /** * v2_aid_payout_destination_balance_get * * GET /v2/accounts/{aid}/payout/payout-destinations/{payout_destination_id}/balances */ export const getApiV2AccountsAidPayoutPayoutDestinationsPayoutDestinationIdBalances = async (args: GetApiV2AccountsAidPayoutPayoutDestinationsPayoutDestinationIdBalancesArgs, options?: GetApiV2AccountsAidPayoutPayoutDestinationsPayoutDestinationIdBalancesOptions) => { const {baseUrl = "https://api.dintero.com", fetch: fetchFn = fetch, JWT} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (JWT !== undefined) headers.set('authorization', `Bearer ${JWT}`) const url = `${baseUrl.replace(/\/+$/, '')}/v2/accounts/${encodeURIComponent(String(args.aid))}/payout/payout-destinations/${encodeURIComponent(String(args.payout_destination_id))}/balances${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(getApiV2AccountsAidPayoutPayoutDestinationsPayoutDestinationIdBalancesResponse, await res.json()) };