import {z} from 'zod' export type BankDetailRequestData = {bankCode?: string | undefined, bankBranchCode?: string | undefined, countryCode?: string | undefined, countryName?: string | undefined, city?: string | undefined, bankName?: string | undefined, streetAddress?: string | undefined, zipCode?: string | undefined, state?: string | undefined, currencyCode?: string | undefined, pageSize?: number | undefined, pageNumber?: number | undefined}; export type CreateApiBanksSearchbydetailArgs = {body: BankDetailRequestData}; export type CreateApiBanksSearchbydetailOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const bankDirectory = z.object({recordKey: z.string().optional(), officeType: z.string().optional(), parentOfficeKey: z.string().optional(), headOfficeKey: z.string().optional(), legalType: z.string().optional(), legalParentKey: z.string().optional(), groupType: z.string().optional(), groupParentKey: z.string().optional(), institutionStatus: z.string().optional(), cooprativeGroupkey: z.string().optional(), isoleiCode: z.string().optional(), bic8Char: z.string().optional(), branchBic: z.string().optional(), bankCode: z.string().optional(), chipsUid: z.string().optional(), bankBranchCode: z.string().optional(), connectedBic: z.string().optional(), bankName: z.string().optional(), bankBranchName: z.string().optional(), pobNumber: z.string().optional(), streetAddress1: z.string().optional(), streetAddress2: z.string().optional(), streetAddress3: z.string().optional(), streetAddress4: z.string().optional(), city: z.string().optional(), countryProvinceState: z.string().optional(), zipCode: z.string().optional(), countryName: z.string().optional(), countryCode: z.string().optional(), timezone: z.string().optional(), subTypeIndicator: z.string().optional(), networkConnectivity: z.string().optional(), branchQualifiers: z.string().optional(), serviceCodes: z.string().optional(), ssiGroupKey: z.string().optional(), iBanKey: z.string().optional(), propertyChangeValidFromDate: z.string().optional(), nationalIdType: z.string().optional(), fedwireRoutingCode: z.string().optional(), fedachRoutingCode: z.string().optional(), parentFedwireRoutingCode: z.string().optional(), messageDetail: z.object({}).optional()}); export const officeType = z.object({officeTypeCode: z.string().optional(), officeTypeDescription: z.string().optional()}); export const legalType = z.object({legalTypeCode: z.string().optional(), legalTypeDescription: z.string().optional()}); export const institutionStatus = z.object({instStatusCode: z.string().optional(), instStatusDesc: z.string().optional(), instStatusParent: z.string().optional()}); export const fABBank = z.object({BankDirectory: bankDirectory.optional(), OfficeType: officeType.optional(), LegalType: legalType.optional(), InstitutionStatus: institutionStatus.optional()}); export const fABResultData = z.object({httpStatus: z.string().optional(), timestamp: z.string().optional(), responseStatus: z.string().optional(), totalRecordFound: z.string().optional(), totalRecordSent: z.string().optional(), nextPageNumber: z.string().optional(), previousPageNumber: z.string().optional(), banks: z.array(fABBank).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 }; /** * Search Bank by Detail * * POST /banks/searchbydetail */ export const createApiBanksSearchbydetail = async (args: CreateApiBanksSearchbydetailArgs, options?: CreateApiBanksSearchbydetailOptions) => { const {baseUrl = "https://masspaysandbox.api.convera.com/masspayments", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/banks/searchbydetail${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(fABResultData, await res.json()) };