import {z} from 'zod' export type GetApiDataApiV10StandardMerchantsArgs = {merchantBoardedDate?: string | undefined, merchantNumber?: string | undefined, sortBy?: string | undefined, pageNumber?: number | undefined, pageSize?: number | undefined}; export type GetApiDataApiV10StandardMerchantsOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const merchant = z.object({merchantNumber: z.string().optional(), merchantDBA: z.string().optional(), parentMerchantNumber: z.string().optional(), parentBusinessDBA: z.string().optional(), resellerMerchantNumber: z.string().optional(), resellerBusinessDBA: z.string().optional(), merchantBoardedDate: z.string().optional(), merchantBankIDNumber: z.string().optional(), merchantIncorporationTypeDescription: z.string().optional(), isMerchantNextDayFundingEnabled: z.string().optional(), merchantSettlementMethodName: z.string().optional(), merchantAmexSENumber: z.string().optional(), merchantAmexMID: z.string().optional(), merchantDiscoverMID: z.string().optional(), merchantStatusDescription: z.string().optional(), merchantComplianceStatusDescription: z.string().optional(), merchantSAQTypeCode: z.string().optional(), merchantLastSAQPassDate: z.string().optional(), merchantSAQExpirationDate: z.string().optional(), merchantEmailAddress: z.string().optional(), merchantBusinessPhoneNumberFull: z.string().optional(), merchantTaxpayerLegalName: z.string().optional(), merchantTINStatusDescription: z.string().optional(), merchantMailingAddressLine1: z.string().optional(), merchantMailingAddressLine2: z.string().optional(), merchantMailingCity: z.string().optional(), merchantMailingPostalCode: z.string().optional(), merchantMailingStateProvince: z.string().optional(), merchantMCCDescription: z.string().optional(), merchantPhysicalAddressLine1: z.string().optional(), merchantPhysicalAddressLine2: z.string().optional(), merchantPhysicalCity: z.string().optional(), merchantPhysicalPostalCode: z.string().optional(), merchantPhysicalStateOrProvince: z.string().optional(), merchantPrincipal1FirstName: z.string().optional(), merchantPrincipal1LastName: z.string().optional(), merchantPrincipal1Percentage: z.string().optional(), merchantPrincipal2FirstName: z.string().optional(), merchantPrincipal2LastName: z.string().optional(), merchantPrincipal2Percentage: z.string().optional()}); export const page = z.object({number: z.number().int().optional(), size: z.number().int().optional(), totalElements: z.number().int().optional(), last: z.boolean().optional()}); export const metadata = z.object({exchangeId: z.string().optional(), timestamp: z.string().optional(), maxId: z.number().int().optional()}); export const merchantProfileResponse = z.object({merchants: z.array(merchant).optional(), page: page.optional(), metadata: metadata.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 }; /** * Get merchant profile details * * GET /data/api/v1.0/standard/merchants */ export const getApiDataApiV10StandardMerchants = async (args: GetApiDataApiV10StandardMerchantsArgs, options: GetApiDataApiV10StandardMerchantsOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.merchantBoardedDate != null) query.append("merchantBoardedDate", String(args.merchantBoardedDate)) if (args.merchantNumber != null) query.append("merchantNumber", String(args.merchantNumber)) if (args.sortBy != null) query.append("sortBy", String(args.sortBy)) if (args.pageNumber != null) query.append("pageNumber", String(args.pageNumber)) if (args.pageSize != null) query.append("pageSize", String(args.pageSize)) const url = `${baseUrl.replace(/\/+$/, '')}/data/api/v1.0/standard/merchants${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(merchantProfileResponse, await res.json()) };