import {z} from 'zod' export type EntityUid = string; export type MerchantCompanyEntityUid = string; export type MerchantName = string; export type AddressLine = string; export type PostCode = string; export type ActiveBank = string; export type CustomerId = string; export type SiteId = string; export type GetApiAccountsSitesArgs = {customerEntityUid: EntityUid, merchantCompanyEntityUid?: MerchantCompanyEntityUid | undefined, billingSitesOnly?: boolean | undefined, billingSiteId?: string | undefined, locateCustomer?: boolean | undefined, merchantCompany?: MerchantName | undefined, addressLine?: AddressLine | undefined, postCode?: PostCode | undefined, activeBank?: ActiveBank | undefined, customerId?: CustomerId | undefined, siteId?: SiteId | undefined}; export type GetApiAccountsSitesOptions = {baseUrl?: string | undefined, BasicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const postCode = z.string().min(1).max(16); export const countryCode3Enum = z.enum(["ZZZ", "ABW", "AFG", "AGO", "AIA", "ALA", "ALB", "AND", "ARE", "ARG", "ARM", "ASM", "ATA", "ATF", "ATG", "AUS", "AUT", "AZE", "BDI", "BEL", "BEN", "BES", "BFA", "BGD", "BGR", "BHR", "BHS", "BIH", "BLM", "BLR", "BLZ", "BMU", "BOL", "BRA", "BRB", "BSB", "BRN", "BTN", "BVT", "BWA", "CAF", "CAN", "CCK", "CHE", "CHL", "CHN", "CIV", "CMR", "COD", "COG", "COK", "COL", "COM", "CPV", "CRI", "CUB", "CUW", "CXR", "CYM", "CYP", "CZE", "DEU", "DJI", "DMA", "DNK", "DOM", "DZA", "ECU", "EGY", "ERI", "ESH", "ESP", "EST", "ETH", "FIN", "FJI", "FLK", "FRA", "FRO", "FSM", "GAB", "GBR", "GEO", "GGY", "GHA", "GIB", "GIN", "GLP", "GMB", "GNB", "GNQ", "GRC", "GRD", "GRL", "GTM", "GUF", "GUM", "GUY", "HKG", "HMD", "HND", "HRV", "HTI", "HUN", "IDN", "IMN", "IND", "IOT", "IRL", "IRN", "IRQ", "ISL", "ISR", "ITA", "JAM", "JEY", "JOR", "JPN", "KAZ", "KEN", "KGZ", "KHM", "KIR", "KNA", "KOR", "KWT", "LAO", "LBN", "LBR", "LBY", "LCA", "LIE", "LKA", "LSO", "LTU", "LUX", "LVA", "MAC", "MAF", "MAR", "MCO", "MDA", "MDG", "MDV", "MEX", "MHL", "MKD", "MLI", "MLT", "MMR", "MNE", "MNG", "MNP", "MOZ", "MRT", "MSR", "MTQ", "MUS", "MWI", "MYS", "MYT", "NAM", "NCL", "NER", "NFK", "NGA", "NIC", "NIU", "NLD", "NOR", "NPL", "NRU", "NZL", "OMN", "PAK", "PAN", "PCN", "PER", "PHL", "PLW", "PNG", "POL", "PRI", "PRK", "PRT", "PRY", "PSE", "PYF", "QAT", "REU", "ROU", "RUS", "RWA", "SAU", "SDN", "SEN", "SGC", "SGP", "SHN", "SJM", "SLB", "SLE", "SLV", "SMR", "SOM", "SPM", "SRB", "SSD", "STP", "SUR", "SVK", "SVN", "SWE", "SWZ", "SXM", "SYC", "SYR", "TCA", "TCD", "TGO", "THA", "TJK", "TKL", "TKM", "TLS", "TON", "TTO", "TUN", "TUR", "TUV", "TWN", "TZA", "UGA", "UKR", "UMI", "URY", "USA", "UZB", "VAT", "VCT", "VEN", "VGB", "VIR", "VNM", "VUT", "WLF", "WSM", "YEM", "ZAF", "ZMB", "ZWE"]); export const timeZone = z.string().min(1).max(127); export const contactTypeEnum = z.enum(["BUSINESS", "DISPUTE_HANDLING", "OWNER", "PERSONAL"]); export const contactName = z.object({firstName: z.string().min(1).max(120), lastName: z.string().min(1).max(120), prefix: z.string().max(120).optional(), alternateFullName: z.string().max(200).optional(), middleName: z.string().max(120).optional(), suffix: z.string().max(120).optional()}); export const phoneTypeEnum = z.enum(["HOME", "MOBILE", "WORK", "FAX", "OTHER"]); export const phone = z.object({callingCode: z.string().optional(), value: z.string().min(5), extension: z.string().optional(), isPrimary: z.boolean().optional(), phoneType: phoneTypeEnum}); export const emailAddress = z.string().min(3).max(254); export const businessTitle = z.string().max(100); export const contactType = z.object({contactType: contactTypeEnum, name: contactName, phoneNumbers: z.array(phone).optional(), email: emailAddress.optional(), businessTitle: businessTitle.optional()}); export const activeBank = z.string().min(1).max(4); export const customerId = z.string(); export const baseAccountSite = z.object({receiverName: z.string().min(1).optional(), addressLine1: z.string().min(1).max(40).optional(), addressLine2: z.string().max(40).optional(), addressLine3: z.string().max(40).optional(), poBox: z.string().optional(), city: z.string().min(1).max(28).optional(), countrySubdivision: z.string().min(1).max(35).optional(), postCode: postCode.optional(), country: countryCode3Enum.optional(), timeZone: timeZone.optional(), contact: contactType.optional(), vfiSiteId: z.string().min(1).max(50).optional(), storeNumber: z.string().optional(), governmentOwned: z.boolean().optional(), governmentCountry: countryCode3Enum.optional(), sitePurpose: z.enum(["BILL", "SHIP"]).optional(), groupNumber: z.string().optional(), activeBank: activeBank.optional(), customerId: customerId.optional()}); export const accountSite = z.object({receiverName: z.string().min(1).optional(), addressLine1: z.string().min(1).max(40).optional(), addressLine2: z.string().max(40).optional(), addressLine3: z.string().max(40).optional(), poBox: z.string().optional(), city: z.string().min(1).max(28).optional(), countrySubdivision: z.string().min(1).max(35).optional(), postCode: postCode.optional(), country: countryCode3Enum.optional(), timeZone: timeZone.optional(), contact: contactType.optional(), vfiSiteId: z.string().min(1).max(50).optional(), storeNumber: z.string().optional(), governmentOwned: z.boolean().optional(), governmentCountry: countryCode3Enum.optional(), sitePurpose: z.enum(["BILL", "SHIP"]).optional(), groupNumber: z.string().optional(), activeBank: activeBank.optional(), customerId: customerId.optional(), linkedSites: z.array(baseAccountSite).optional()}); export const accountSitesResponse = z.object({sites: z.array(accountSite).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 the list of all Verifone Sites in Billing Engine * * GET /accounts/sites * * Also accepts auth: BearerAuth */ export const getApiAccountsSites = async (args: GetApiAccountsSitesArgs, options?: GetApiAccountsSitesOptions) => { const {baseUrl = "https://emea.gsc.verifone.cloud/oidc/checkout-service", fetch: fetchFn = fetch, BasicAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.customerEntityUid != null) query.append("customerEntityUid", String(args.customerEntityUid)) if (args.merchantCompanyEntityUid != null) query.append("merchantCompanyEntityUid", String(args.merchantCompanyEntityUid)) if (args.billingSitesOnly != null) query.append("billingSitesOnly", String(args.billingSitesOnly)) if (args.billingSiteId != null) query.append("billingSiteId", String(args.billingSiteId)) if (args.locateCustomer != null) query.append("locateCustomer", String(args.locateCustomer)) if (args.merchantCompany != null) query.append("merchantCompany", String(args.merchantCompany)) if (args.addressLine != null) query.append("addressLine", String(args.addressLine)) if (args.postCode != null) query.append("postCode", String(args.postCode)) if (args.activeBank != null) query.append("activeBank", String(args.activeBank)) if (args.customerId != null) query.append("customerId", String(args.customerId)) if (args.siteId != null) query.append("siteId", String(args.siteId)) if (BasicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${BasicAuth.username}:${BasicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/accounts/sites${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(accountSitesResponse, await res.json()) };