import {z} from 'zod' export type GetApiSubAccountsIdFeeConfigurationsArgs = {id: string, Authorization: string, limit?: number | undefined, after_cursor?: string | undefined, before_cursor?: string | undefined}; export type GetApiSubAccountsIdFeeConfigurationsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const standardFeeConfiguration = z.object({id: z.string().optional(), account_id: z.string().optional(), platform_account_id: z.string().nullable().optional(), fee_type: z.enum(["processing_ecomm", "processing_card_present", "processing_ach", "processing_ach_expedited", "visa_brand_ecomm", "visa_brand_card_present", "mastercard_brand_ecomm", "mastercard_brand_card_present", "amex_brand_ecomm", "amex_brand_card_present", "discover_brand_ecomm", "discover_brand_card_present", "platform"]).optional(), variable_rate: z.number().optional(), transaction_fee_cents: z.number().int().optional(), transaction_fee_currency: z.literal("usd").optional(), fee_cap_cents: z.number().int().nullable().optional(), effective_start: z.string().optional(), effective_end: z.string().nullable().optional()}); export const pageInfo = z.object({end_cursor: z.string().optional(), has_next: z.boolean().optional(), has_previous: z.boolean().optional(), start_cursor: z.string().optional()}); export const getApiSubAccountsIdFeeConfigurationsResponse = z.object({id: z.number().optional(), type: z.string().optional(), data: z.array(standardFeeConfiguration).optional(), page_info: pageInfo.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 }; /** * List Fee Configurations * * GET /sub_accounts/{id}/fee_configurations */ export const getApiSubAccountsIdFeeConfigurations = async (args: GetApiSubAccountsIdFeeConfigurationsArgs, options?: GetApiSubAccountsIdFeeConfigurationsOptions) => { 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)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.after_cursor != null) query.append("after_cursor", String(args.after_cursor)) if (args.before_cursor != null) query.append("before_cursor", String(args.before_cursor)) const url = `${baseUrl.replace(/\/+$/, '')}/sub_accounts/${encodeURIComponent(String(args.id))}/fee_configurations${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(getApiSubAccountsIdFeeConfigurationsResponse, await res.json()) };