import {z} from 'zod' export type GetApiV3CustomerNumberCustomerNumberArgs = {auditUser: string, customerNumber: string}; export type GetApiV3CustomerNumberCustomerNumberOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const phoneNumber = z.string(); export const mobileNumber = z.string(); export const customerNumber = z.string(); export const locale = z.enum(["af_ZA", "ar_AE", "ar_BH", "ar_DZ", "ar_EG", "ar_IQ", "ar_JO", "ar_KW", "ar_LB", "ar_LY", "ar_MA", "ar_OM", "ar_QA", "ar_SA", "ar_SY", "ar_TN", "ar_YE", "az_AZ", "be_BY", "bg_BG", "bn_IN", "bs_BA", "ca_ES", "cs_CZ", "cy_GB", "da_DK", "de_AT", "de_CH", "de_DE", "de_LI", "de_LU", "de_NL", "el_GR", "en_AU", "en_BZ", "en_CA", "en_GB", "en_IE", "en_JM", "en_MT", "en_NZ", "en_PH", "en_TT", "en_US", "en_VI", "en_ZA", "en_ZW", "es_AR", "es_BO", "es_CL", "es_CO", "es_CR", "es_DO", "es_EC", "es_ES", "es_GT", "es_HN", "es_MX", "es_NI", "es_PA", "es_PE", "es_PR", "es_PY", "es_SV", "es_UY", "es_VE", "et_EE", "eu_ES", "fa_IR", "fi_FI", "fo_FO", "fr_BE", "fr_CA", "fr_CH", "fr_FR", "fr_LU", "fr_MC", "fr_NL", "ga_IE", "gl_ES", "gu_IN", "he_IL", "hi_IN", "hr_HR", "hu_HU", "hy_AM", "id_ID", "is_IS", "it_CH", "it_IT", "ja_JP", "ka_GE", "kk_KZ", "kl_GL", "kn_IN", "ko_KR", "kok_IN", "lb_LU", "lt_LT", "lv_LV", "mk_MK", "ml_IN", "mn_MN", "mr_IN", "ms_BN", "ms_MY", "mt_MT", "nb_NO", "nl_BE", "nl_NL", "nn_NO", "no_NO", "pa_IN", "pl_PL", "pt_BR", "pt_PT", "ro_RO", "ru_RU", "se_NO", "sk_SK", "sl_SI", "sq_AL", "sr_BA", "sr_CS", "sv_FI", "sv_SE", "sw_KE", "syr_SY", "ta_IN", "te_IN", "th_TH", "tn_ZA", "tr_TR", "uk_UA", "uz_UZ", "vi_VN", "xh_ZA", "zh_CN", "zh_HK", "zh_MO", "zh_SG", "zh_TW", "zu_ZA"]); export const regNo = z.string().max(64); export const screening = z.object({status: z.boolean(), statusLastUpdated: z.string().optional()}); export const country = z.string(); export const address = z.object({address1: z.string().min(1).max(255), address2: z.string().max(255).optional(), address3: z.string().max(255).optional(), address4: z.string().max(255).optional(), city: z.string().min(1).max(255), country: country, region: z.string().max(32).optional(), zipCode: z.string().min(1).max(32)}); export const keyValuePair = z.object({key: z.string().max(64), value: z.string().max(64)}); export const additionalValues = z.array(keyValuePair); export const riskScore = z.enum(["High", "Med", "Low", "Pep", "Prohibited"]); export const name = z.string().max(64); export const customerRepresentative = z.string().max(64); export const authority = z.string().max(70); export const registrationDate = z.string(); export const registration = z.object({authority: authority.optional(), registrationDate: registrationDate.optional()}); export const bankruptcyDate = z.string(); export const corporateCustomerResponse = z.object({email: z.string().max(255).optional(), phoneNumber: phoneNumber.optional(), mobileNumber: mobileNumber.optional(), customerNumber: customerNumber, locale: locale, regNo: regNo, screening: screening.optional(), address: address, temporaryAddress: address.optional(), additionalValues: additionalValues.optional(), id: z.string(), role: z.string(), riskScore: riskScore.optional(), name: name.optional(), customerRepresentative: customerRepresentative.optional(), registration: registration.optional(), bankruptcyDate: bankruptcyDate.optional()}); export const salutation = z.string().max(32); export const firstName = z.string().max(255); export const middleName = z.string().max(255); export const lastName = z.string().max(255); export const dateOfBirth = z.string(); export const birthCountry = z.string(); export const nationality = z.array(country); export const deceasedDate = z.string(); export const privateCustomerResponse = z.object({email: z.string().max(255).optional(), phoneNumber: phoneNumber.optional(), mobileNumber: mobileNumber.optional(), customerNumber: customerNumber, locale: locale, regNo: regNo, screening: screening.optional(), address: address, temporaryAddress: address.optional(), additionalValues: additionalValues.optional(), id: z.string(), role: z.string(), riskScore: riskScore.optional(), salutation: salutation.optional(), firstName: firstName.optional(), middleName: middleName.optional(), lastName: lastName.optional(), dateOfBirth: dateOfBirth.optional(), birthCountry: birthCountry.optional(), nationality: nationality.optional(), deceasedDate: deceasedDate.optional()}); export const getApiV3CustomerNumberCustomerNumberResponse = z.discriminatedUnion("role", [corporateCustomerResponse, privateCustomerResponse]); 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 customer by customer number * * GET /v3/customerNumber/{customerNumber} */ export const getApiV3CustomerNumberCustomerNumber = async (args: GetApiV3CustomerNumberCustomerNumberArgs, options: GetApiV3CustomerNumberCustomerNumberOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.auditUser != null) query.append("auditUser", String(args.auditUser)) const url = `${baseUrl.replace(/\/+$/, '')}/v3/customerNumber/${encodeURIComponent(String(args.customerNumber))}${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(getApiV3CustomerNumberCustomerNumberResponse, await res.json()) };