import {z} from 'zod' export type GetApiMerchantDevicesArgs = {'Content-Type': 'application/json' | 'application/json;charset=UTF-8', 'FSV-Interaction-Id': string, Environment: string, 'Institution-Number': string, 'Internal-Merchant-Id': string, externalTerminalID?: string | undefined, limit?: number | undefined, offset?: number | undefined}; export type GetApiMerchantDevicesOptions = {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 oPYDevicesExternalTerminalId = z.string().min(1).max(20); export const oPYDevicesSerialNumber = z.string().max(9); export const oPYDevicesContactName = z.string().max(35); export const oPYDevicesTerminalLocation = z.string().max(25); export const oPYDevicesTerminalCountryCode = z.string().min(3).max(3); export const oPYGenericDescription = z.string().max(100); export const oPYDevicesTerminalCountryObj = z.object({countryCode: oPYDevicesTerminalCountryCode.optional(), countryName: oPYGenericDescription.optional()}); export const oPYDevicesCity = z.string().max(13); export const oPYDevicesTelephone = z.string().max(15); export const oPYDevicesSchemeId = z.string().max(6); export const oPYDevicesAccountCurrencyCode = z.string().min(3).max(3); export const oPYDevicesSystemBatchId = z.string().max(6); export const oPYDevicesServiceProviderObj = z.object({serviceProviderIndex: z.string().min(3).max(3).optional(), serviceProviderDescription: oPYGenericDescription.optional()}); export const oPYDevicesAcquiringProfileObj = z.object({acquiringProfileIndex: z.string().min(3).max(3).optional(), acquiringProfileDescription: oPYGenericDescription.optional()}); export const oPYDevicesTemplateId = z.string().max(4); export const oPYDevicesAmex = z.boolean(); export const oPYDevicesClientFeeObj = z.object({clientFeeIndex: z.string().min(3).max(3).optional(), clientFeeDescription: oPYGenericDescription.optional()}); export const oPYDevicesFeeEffeciveDate = z.string().min(8).max(8); export const oPYDevicesFeeExpiryDate = z.string().min(8).max(8); export const oPYDevicesLastFeeDate = z.string().min(8).max(8); export const oPYDevicesConfigOfTerminalObj = z.object({configOfTerminalIndex: z.string().min(3).max(3).optional(), configOfTerminalDescription: oPYGenericDescription.optional()}); export const oPYDevicesTerminalTypeObj = z.object({terminalTypeIndex: z.string().min(3).max(3).optional(), terminalTypeDescription: oPYGenericDescription.optional()}); export const oPYDevicesEmv = z.boolean(); export const oPYDevicesInstallDate = z.string().min(8).max(8); export const oPYDevicesActiveDate = z.string().min(8).max(8); export const oPYDevicesTerminationDate = z.string().min(8).max(8); export const oPYDevicesTerminalPassword = z.string().max(8); export const oPYDevicesWorkStation = z.string().max(50); export const oPYDevicesAmexPhoneNo1 = z.string().max(24); export const oPYDevicesAmexPhoneNo2 = z.string().max(24); export const oPYDevicesRelatedTId = z.string().max(20); export const viewMerchantDevicesAmexDetails = z.object({amexPhoneNo1: oPYDevicesAmexPhoneNo1.optional(), amexPhoneNo2: oPYDevicesAmexPhoneNo2.optional(), relatedTId: oPYDevicesRelatedTId.optional()}); export const oPYDevicesSocCode = z.string().max(15); export const oPYDevicesWaiver = z.string().max(30); export const oPYDevicesSetupFee = z.string().max(7); export const oPYDevicesGprsRental = z.string().max(8); export const oPYDevicesGprsRentalAmount = z.string().max(7); export const oPYDevicesInstalled = z.string().max(12); export const viewMerchantDevicesScheduleOfChargeDetails = z.object({socCode: oPYDevicesSocCode.optional(), waiver: oPYDevicesWaiver.optional(), setupFee: oPYDevicesSetupFee.optional(), gprsRental: oPYDevicesGprsRental.optional(), gprsRentalAmount: oPYDevicesGprsRentalAmount.optional(), installed: oPYDevicesInstalled.optional()}); export const oPYLastUpdatedBy = z.string().max(60); export const oPYLastUpdated = 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 inlineResponse20012 = z.object({meta: metaType.optional(), data: z.array(z.object({externalTerminalId: oPYDevicesExternalTerminalId.optional(), serialNumber: oPYDevicesSerialNumber.optional(), contactName: oPYDevicesContactName.optional(), terminalLocation: oPYDevicesTerminalLocation.optional(), terminalCountry: oPYDevicesTerminalCountryObj.optional(), city: oPYDevicesCity.optional(), telephone: oPYDevicesTelephone.optional(), schemaId: oPYDevicesSchemeId.optional(), accountCurrencyCode: oPYDevicesAccountCurrencyCode.optional(), systemBatchId: oPYDevicesSystemBatchId.optional(), serviceProvider: oPYDevicesServiceProviderObj.optional(), acquiringProfile: oPYDevicesAcquiringProfileObj.optional(), templateId: oPYDevicesTemplateId.optional(), amex: oPYDevicesAmex.optional(), clientFee: oPYDevicesClientFeeObj.optional(), feeEffectiveDate: oPYDevicesFeeEffeciveDate.optional(), feeExpiryDate: oPYDevicesFeeExpiryDate.optional(), lastFeeDate: oPYDevicesLastFeeDate.optional(), configOfTerminal: oPYDevicesConfigOfTerminalObj.optional(), terminalType: oPYDevicesTerminalTypeObj.optional(), emv: oPYDevicesEmv.optional(), installDate: oPYDevicesInstallDate.optional(), activeDate: oPYDevicesActiveDate.optional(), terminationDate: oPYDevicesTerminationDate.optional(), terminalPassword: oPYDevicesTerminalPassword.optional(), workStation: oPYDevicesWorkStation.optional(), amexDetails: viewMerchantDevicesAmexDetails.optional(), scheduleOfChargeDetails: viewMerchantDevicesScheduleOfChargeDetails.optional(), lastUpdatedBy: oPYLastUpdatedBy.optional(), lastUpdatedDate: oPYLastUpdated.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 Merchant Devices * * GET /merchant-devices */ export const getApiMerchantDevices = async (args: GetApiMerchantDevicesArgs, options?: GetApiMerchantDevicesOptions) => { 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.externalTerminalID != null) query.append("externalTerminalID", String(args.externalTerminalID)) 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(/\/+$/, '')}/merchant-devices${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(inlineResponse20012, await res.json()) };