import {z} from 'zod' export type OPYAddressCategoryIndex = string; export type OPYAddressContactName = string; export type OPYAddressGroupSpecific = boolean; export type OPYAddressLine1 = string; export type OPYAddressLine2 = string; export type OPYAddressLine3 = string; export type OPYAddressLine4 = string; export type OPYAddressLine5 = string; export type OPYAddressPostCode = string; export type OPYAddressCity = string; export type OPYAddressState = string; export type OPYAddressCountryCode = string; export type OPYAddressTelephone = string; export type OPYAddressFax = string; export type OPYAddressEmail = string; export type OPYAddressDeliveryMethodIndex = string; export type OPYAddressEffectiveDate = string; export type MerchantAddressUpdate = {categoryIndex: OPYAddressCategoryIndex, contactName?: OPYAddressContactName | undefined, groupSpecific?: OPYAddressGroupSpecific | undefined, line1?: OPYAddressLine1 | undefined, line2?: OPYAddressLine2 | undefined, line3?: OPYAddressLine3 | undefined, line4?: OPYAddressLine4 | undefined, line5?: OPYAddressLine5 | undefined, postCode?: OPYAddressPostCode | undefined, city?: OPYAddressCity | undefined, state?: OPYAddressState | undefined, countryCode?: OPYAddressCountryCode | undefined, telephone?: OPYAddressTelephone | undefined, fax?: OPYAddressFax | undefined, email?: OPYAddressEmail | undefined, deliveryMethodIndex?: OPYAddressDeliveryMethodIndex | undefined, effectiveDate: OPYAddressEffectiveDate}; export type UpdateApiAddressesArgs = {'Content-Type': 'application/json' | 'application/json;charset=UTF-8', 'FSV-Interaction-Id': string, Environment: string, 'Institution-Number': string, 'Internal-Merchant-Id': string, body: Array}; export type UpdateApiAddressesOptions = {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 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 inlineResponse400 = z.object({meta: metaType.optional(), data: z.array(z.object({})).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 }; /** * Modify future effective addresses * * PUT /addresses */ export const updateApiAddresses = async (args: UpdateApiAddressesArgs, options?: UpdateApiAddressesOptions) => { 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('content-type', "application/json") 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 (AppKey !== undefined) headers.set("Api-Key", AppKey) if (JWSSignature !== undefined) headers.set("JWS-Signature", JWSSignature) const url = `${baseUrl.replace(/\/+$/, '')}/addresses${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(inlineResponse400, await res.json()) };