import {z} from 'zod' export type GetApiAccountFeesArgs = {'Content-Type': 'application/json' | 'application/json;charset=UTF-8', 'FSV-Interaction-Id': string, Environment: string, 'Institution-Number': string, 'Internal-Merchant-Id': string, feeStatus?: ('ACTIVE' | 'FUTURE' | 'ALL' | 'INACTIVE') | undefined, feeModel?: ('DEFAULT' | 'INDIVIDUAL' | 'ALL') | undefined, limit?: number | undefined, offset?: number | undefined}; export type GetApiAccountFeesOptions = {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 oPYAccountFeesRecordIdNumber = z.string().min(10).max(10); export const oPYGenericCode3 = z.string().min(1).max(3); export const oPYGenericDescription = z.string().max(100); export const oPYAccountAccountTypeObj = z.object({accountTypeIndex: oPYGenericCode3.optional(), accountTypeDescription: oPYGenericDescription.optional()}); export const oPYAccountAccountCurrencyCode = z.string().min(3).max(3); export const oPYFxRateMarginsEffectiveDate = z.string().min(8).max(8); export const oPYAccountFeesExpiryDate = z.string().min(8).max(8); export const oPYAccountFeesTriggerSourceObj = z.object({triggerSourceIndex: oPYGenericCode3.optional(), triggerSourceDescription: oPYGenericDescription.optional()}); export const oPYAccountFeesRuleIDObj = z.object({ruleIDIndex: oPYGenericCode3.optional(), ruleIDDescription: oPYGenericDescription.optional()}); export const oPYAccountFeesCurrencyCode = z.string().min(3).max(3); export const oPYAccountFeesFeePercentage = z.string().max(11); export const oPYAccountFeesFeeBase = z.string().max(11); export const oPYAccountFeesFeeMinimum = z.string().max(11); export const oPYAccountFeesFeeMaximum = z.string().max(11); export const oPYAccountFeesFeeMode = z.boolean(); export const oPYAccountFeesTriggerHighValue = z.string().max(18); export const oPYAccountFeesTriggerLowValue = z.string().max(18); export const oPYAccountFeesTriggerVolumeHigh = z.string().max(18); export const oPYAccountFeesTriggerVolumeLow = z.string().max(18); export const oPYAccountFeesFeeTypeObj = z.object({feeTypeIndex: oPYGenericCode3.optional(), feeTypeDescription: oPYGenericDescription.optional()}); export const oPYAccountFeesRateCategoryObj = z.object({rateCategoryIndex: oPYGenericCode3.optional(), rateCategoryDescription: oPYGenericDescription.optional()}); export const oPYAccountFeesFeeIdObj = z.object({feeIdIndex: oPYGenericCode3.optional(), feeIdDescription: oPYGenericDescription.optional()}); export const oPYAccountFeesFeeLevelObj = z.object({feeLevelIndex: oPYGenericCode3.optional(), feeLevelDescription: oPYGenericDescription.optional()}); export const oPYAccountFeesTriggerFrequencyObj = z.object({triggerFrequencyIndex: oPYGenericCode3.optional(), triggerFrequencyDescription: oPYGenericDescription.optional()}); export const oPYAccountFeesTriggerCurrencyObj = z.object({triggerCurrencyIndex: oPYGenericCode3.optional(), triggerCurrencyDescription: oPYGenericDescription.optional()}); export const oPYAccountFeesPostToAccountObj = z.object({postToAccountIndex: oPYGenericCode3.optional(), postToAccountDescription: oPYGenericDescription.optional()}); export const oPYAccountFeesLastUpdated = z.string().min(8).max(8); export const oPYAccountFeesLastUpdatedBy = z.string().max(60); 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 inlineResponse2001 = z.object({meta: metaType.optional(), data: z.array(z.object({feeModel: z.enum(["INDIVIDUAL", "DEFAULT"]).optional(), recordIdNumber: oPYAccountFeesRecordIdNumber, status: z.enum(["ACTIVE", "FUTURE", "INACTIVE"]).optional(), accountType: oPYAccountAccountTypeObj.optional(), accountCurrencyCode: oPYAccountAccountCurrencyCode.optional(), effectiveDate: oPYFxRateMarginsEffectiveDate.optional(), expiryDate: oPYAccountFeesExpiryDate.optional(), triggerSource: oPYAccountFeesTriggerSourceObj.optional(), rule: oPYAccountFeesRuleIDObj.optional(), feeBaseCurrencyCode: oPYAccountFeesCurrencyCode.optional(), feePercentage: oPYAccountFeesFeePercentage.optional(), feeBase: oPYAccountFeesFeeBase.optional(), feeMinimum: oPYAccountFeesFeeMinimum.optional(), feeMaximum: oPYAccountFeesFeeMaximum.optional(), feeMode: oPYAccountFeesFeeMode.optional(), triggerHighValue: oPYAccountFeesTriggerHighValue.optional(), triggerLowValue: oPYAccountFeesTriggerLowValue.optional(), triggerVolumeHigh: oPYAccountFeesTriggerVolumeHigh.optional(), triggerVolumeLow: oPYAccountFeesTriggerVolumeLow.optional(), feeType: oPYAccountFeesFeeTypeObj.optional(), rateCategory: oPYAccountFeesRateCategoryObj.optional(), feeId: oPYAccountFeesFeeIdObj.optional(), feeLevel: oPYAccountFeesFeeLevelObj.optional(), triggerFrequency: oPYAccountFeesTriggerFrequencyObj.optional(), triggerCurrency: oPYAccountFeesTriggerCurrencyObj.optional(), postToAccount: oPYAccountFeesPostToAccountObj.optional(), lastUpdated: oPYAccountFeesLastUpdated.optional(), lastUpdatedBy: oPYAccountFeesLastUpdatedBy.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 account fees * * GET /account-fees */ export const getApiAccountFees = async (args: GetApiAccountFeesArgs, options?: GetApiAccountFeesOptions) => { 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.Environment != null) headers.set("Environment", String(args.Environment)) if (args['Institution-Number'] != null) headers.set("Institution-Number", String(args['Institution-Number'])) if (args['Internal-Merchant-Id'] != null) headers.set("Internal-Merchant-Id", String(args['Internal-Merchant-Id'])) if (args.feeStatus != null) query.append("feeStatus", String(args.feeStatus)) if (args.feeModel != null) query.append("feeModel", String(args.feeModel)) 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(/\/+$/, '')}/account-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(inlineResponse2001, await res.json()) };