import {z} from 'zod' export type MerchantRegistration = {registration_type?: (string | null) | undefined, registration_id?: (string | null) | undefined, vat_id?: (string | null) | undefined}; export type MerchantContact = {name?: (string | null) | undefined, title?: (string | null) | undefined, phone_number?: (string | null) | undefined, email?: (string | null) | undefined}; export type MerchantAddress = {street_1?: (string | null) | undefined, street_2?: (string | null) | undefined, city?: (string | null) | undefined, state_province?: (string | null) | undefined, postal_code?: (string | null) | undefined, country?: (string | null) | undefined}; export type MerchantInfo = {full_legal_name?: (string | null) | undefined, doing_business_as?: (string | null) | undefined, parent_company_name?: (string | null) | undefined, website_url?: (string | null) | undefined, category_code_mcc?: (string | null) | undefined, descriptor?: (string | null) | undefined, business_description?: (string | null) | undefined, registration?: MerchantRegistration | undefined, contact?: MerchantContact | undefined, address?: MerchantAddress | undefined}; export type VisaConfig = {acquirer_bin?: (string | null) | undefined, card_acceptor_id_caid?: (string | null) | undefined}; export type MastercardConfig = {merchant_id_mid?: (string | null) | undefined}; export type AmexConfig = {se_number?: (string | null) | undefined}; export type DiscoverConfig = {merchant_id_mid?: (string | null) | undefined}; export type CardNetworkInfo = {visa?: VisaConfig | undefined, mastercard?: MastercardConfig | undefined, amex?: AmexConfig | undefined, discover?: DiscoverConfig | undefined}; export type MerchantDetails = {merchant?: MerchantInfo | undefined, card_network_info?: CardNetworkInfo | undefined}; export type TenantMerchantRequest = {name: string, details?: MerchantDetails | undefined}; export type PatchApiTenantsTenantIdMerchantsMerchantIdArgs = {tenantId: string, merchantId: string, body: TenantMerchantRequest}; export type PatchApiTenantsTenantIdMerchantsMerchantIdOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const merchantRegistration = z.object({registration_type: z.string().nullable().optional(), registration_id: z.string().nullable().optional(), vat_id: z.string().nullable().optional()}); export const merchantContact = z.object({name: z.string().nullable().optional(), title: z.string().nullable().optional(), phone_number: z.string().nullable().optional(), email: z.string().nullable().optional()}); export const merchantAddress = z.object({street_1: z.string().nullable().optional(), street_2: z.string().nullable().optional(), city: z.string().nullable().optional(), state_province: z.string().nullable().optional(), postal_code: z.string().nullable().optional(), country: z.string().nullable().optional()}); export const merchantInfo = z.object({full_legal_name: z.string().nullable().optional(), doing_business_as: z.string().nullable().optional(), parent_company_name: z.string().nullable().optional(), website_url: z.string().nullable().optional(), category_code_mcc: z.string().nullable().optional(), descriptor: z.string().nullable().optional(), business_description: z.string().nullable().optional(), registration: merchantRegistration.optional(), contact: merchantContact.optional(), address: merchantAddress.optional()}); export const visaConfig = z.object({acquirer_bin: z.string().nullable().optional(), card_acceptor_id_caid: z.string().nullable().optional()}); export const mastercardConfig = z.object({merchant_id_mid: z.string().nullable().optional()}); export const amexConfig = z.object({se_number: z.string().nullable().optional()}); export const discoverConfig = z.object({merchant_id_mid: z.string().nullable().optional()}); export const cardNetworkInfo = z.object({visa: visaConfig.optional(), mastercard: mastercardConfig.optional(), amex: amexConfig.optional(), discover: discoverConfig.optional()}); export const merchantDetails = z.object({merchant: merchantInfo.optional(), card_network_info: cardNetworkInfo.optional()}); export const networkStatusDetail = z.object({status: z.string().nullable().optional(), status_reason_code: z.string().nullable().optional(), status_reason: z.string().nullable().optional(), status_reason_label: z.string().nullable().optional()}); export const cardNetworkStatus = z.object({visa: networkStatusDetail.optional(), mastercard: networkStatusDetail.optional(), amex: networkStatusDetail.optional(), discover: networkStatusDetail.optional()}); export const serviceStatus = z.object({status: z.string().nullable().optional(), providers: z.array(z.string()).nullable().optional(), card_network_status: cardNetworkStatus.optional()}); export const merchantServices = z.object({account_updater: serviceStatus.optional(), network_token: serviceStatus.optional(), agentic_commerce: serviceStatus.optional()}); export const tenantMerchant = z.object({id: z.string().max(36).optional(), tenant_id: z.string().max(36).optional(), name: z.string().nullable().optional(), details: merchantDetails.optional(), services: merchantServices.optional(), created_by: z.string().max(36).nullable().optional(), created_at: z.string().max(40).nullable().optional(), modified_by: z.string().max(36).nullable().optional(), modified_at: z.string().max(40).nullable().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 }; /** * PATCH /tenants/{tenantId}/merchants/{merchantId} */ export const patchApiTenantsTenantIdMerchantsMerchantId = async (args: PatchApiTenantsTenantIdMerchantsMerchantIdArgs, options?: PatchApiTenantsTenantIdMerchantsMerchantIdOptions) => { const {baseUrl = "https://api.basistheory.com", fetch: fetchFn = fetch, ApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (ApiKey !== undefined) headers.set("BT-API-KEY", ApiKey) const url = `${baseUrl.replace(/\/+$/, '')}/tenants/${encodeURIComponent(String(args.tenantId))}/merchants/${encodeURIComponent(String(args.merchantId))}${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(tenantMerchant, await res.json()) };