import {z} from 'zod' export type GetApiGlobalFeesArgs = {'Content-Type': 'application/json' | 'application/json;charset=UTF-8', 'FSV-Interaction-Id': string, 'Institution-Number': string, Environment: string, limit?: number | undefined, offset?: number | undefined}; export type GetApiGlobalFeesOptions = {baseUrl?: string | undefined, AppKey?: string | undefined, JWSSignature?: string | undefined, fetch?: typeof fetch | undefined}; export const pagingMetaType = z.object({count: z.number().int().optional(), totalPages: z.number().int().optional(), currentOffset: z.number().int().optional(), currentNumberOfRetrievedRecords: z.number().int().optional(), maxLimit: z.number().int().optional(), hasMoreRecords: z.boolean().optional(), pageNumber: z.number().int().optional()}); export const sortingMetaType = z.object({sort: z.string().optional()}); export const sourceType = z.object({pointer: z.string().optional(), parameter: z.string().optional(), header: z.string().optional()}); export const errorType = z.object({id: z.string().optional(), code: z.string(), title: z.string(), detail: z.string().optional(), source: sourceType.optional()}); export const metaType = z.object({paging: pagingMetaType.optional(), sorting: sortingMetaType.optional(), messages: z.array(errorType).optional()}); export const oPYGenericDescription = z.string().max(100); export const oPYSplitPaymentInstructionSourceAccountObj = z.object({accountTypeIndex: z.string().min(3).max(3).optional(), accountTypeDescription: oPYGenericDescription.optional(), accountCurrencyCode: z.string().min(3).max(3).optional()}); export const oPYSplitPaymentInstructionDestinationAccountObj = z.object({accountTypeIndex: z.string().min(3).max(3).optional(), accountTypeDescription: oPYGenericDescription.optional(), accountCurrencyCode: z.string().min(3).max(3).optional()}); export const oPYSplitPaymentInstructionInstructionTypeObj = z.object({instructionTypeIndex: z.string().min(3).max(3).optional(), instructionTypeDescription: oPYGenericDescription.optional()}); export const oPYSplitPaymentInstructionStatus = z.enum(["ACTIVE", "FUTURE", "EXPIRED", "ALL"]); export const oPYSplitPaymentInstructionInstructionIdNumber = z.string().min(1).max(10); export const oPYSplitPaymentInstructionStartDate = z.string().min(8).max(8); export const oPYSplitPaymentInstructionEndDate = z.string().min(8).max(8); export const oPYSplitPaymentInstructionSplitPercentage = z.string().max(11); export const oPYPaymentInstructionLastExecutionDate = z.string().min(8).max(8); export const oPYPaymentInstructionExecutionCount = z.string().max(11); export const oPYPaymentInstructionAmountPaid = z.string().max(18); export const oPYPaymentInstructionLastUpdatedBy = z.string().max(60); export const oPYPaymentInstructionLastUpdatedDate = z.string().min(8).max(8); export const linksType = z.object({self: z.string().optional(), first: z.string().optional(), last: z.string().optional(), prev: z.string().optional(), next: z.string().optional()}); export const inlineResponse20013 = z.object({meta: metaType.optional(), data: z.array(z.object({sourceAccount: oPYSplitPaymentInstructionSourceAccountObj.optional(), destinationAccount: oPYSplitPaymentInstructionDestinationAccountObj.optional(), instructionType: oPYSplitPaymentInstructionInstructionTypeObj.optional(), status: oPYSplitPaymentInstructionStatus.optional(), instructionIdNumber: oPYSplitPaymentInstructionInstructionIdNumber.optional(), startDate: oPYSplitPaymentInstructionStartDate.optional(), endDate: oPYSplitPaymentInstructionEndDate.optional(), deductionPercentage: oPYSplitPaymentInstructionSplitPercentage.optional(), lastExecutionDate: oPYPaymentInstructionLastExecutionDate.optional(), totalExecutionCount: oPYPaymentInstructionExecutionCount.optional(), totalAmountPaid: oPYPaymentInstructionAmountPaid.optional(), lastUpdatedBy: oPYPaymentInstructionLastUpdatedBy.optional(), lastUpdatedDate: oPYPaymentInstructionLastUpdatedDate.optional()})).optional(), errors: z.array(errorType).optional(), links: linksType.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 }; /** * Retrieve Global Scheme Fees * * GET /global-fees */ export const getApiGlobalFees = async (args: GetApiGlobalFeesArgs, options?: GetApiGlobalFeesOptions) => { const {baseUrl = "https://prod.emea.api.fiservapps.com/ipp/omnipay/acquirerprofile/v1.0", fetch: fetchFn = fetch, AppKey, JWSSignature} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['Content-Type'] != null) headers.set("Content-Type", String(args['Content-Type'])) if (args['FSV-Interaction-Id'] != null) headers.set("FSV-Interaction-Id", String(args['FSV-Interaction-Id'])) if (args['Institution-Number'] != null) headers.set("Institution-Number", String(args['Institution-Number'])) if (args.Environment != null) headers.set("Environment", String(args.Environment)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.offset != null) query.append("offset", String(args.offset)) if (AppKey !== undefined) headers.set("Api-Key", AppKey) if (JWSSignature !== undefined) headers.set("JWS-Signature", JWSSignature) const url = `${baseUrl.replace(/\/+$/, '')}/global-fees${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(inlineResponse20013, await res.json()) };