import {z} from 'zod' export type PhoneNumber = string; export type MobileNumber = string; export type CustomerNumber = string; export type RegNo = string; export type Locale = '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 type Screening = {status: boolean, statusLastUpdated?: string | undefined}; export type Country = string; export type UpdateAddress = {address1?: string | undefined, address2?: string | undefined, address3?: string | undefined, address4?: string | undefined, city?: string | undefined, country?: Country | undefined, region?: string | undefined, zipCode?: string | undefined}; export type KeyValuePair = {key: string, value: string}; export type AdditionalValues = Array; export type Name = string; export type CustomerRepresentative = string; export type Authority = string; export type RegistrationDate = string; export type Registration = {authority?: Authority | undefined, registrationDate?: RegistrationDate | undefined}; export type BankruptcyDate = string; export type RiskScore = 'High' | 'Med' | 'Low' | 'Pep' | 'Prohibited'; export type PatchCorporateResourceBody = {email?: string | undefined, phoneNumber?: PhoneNumber | undefined, mobileNumber?: MobileNumber | undefined, customerNumber?: CustomerNumber | undefined, regNo?: RegNo | undefined, locale?: Locale | undefined, screening?: Screening | undefined, address?: UpdateAddress | undefined, temporaryAddress?: UpdateAddress | undefined, additionalValues?: AdditionalValues | undefined, name?: Name | undefined, customerRepresentative?: CustomerRepresentative | undefined, registration?: Registration | undefined, bankruptcyDate?: BankruptcyDate | undefined, riskScore?: RiskScore | undefined}; export type PatchApiV3CORPORATEIdArgs = {auditUser: string, id: string, body: PatchCorporateResourceBody}; export type PatchApiV3CORPORATEIdOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const resourceResponse = z.object({description: z.string().optional(), id: z.string().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 }; /** * Update a corporate customer * * PATCH /v3/CORPORATE/{id} */ export const patchApiV3CORPORATEId = async (args: PatchApiV3CORPORATEIdArgs, options: PatchApiV3CORPORATEIdOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.auditUser != null) query.append("auditUser", String(args.auditUser)) const url = `${baseUrl.replace(/\/+$/, '')}/v3/CORPORATE/${encodeURIComponent(String(args.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(resourceResponse, await res.json()) };