import {z} from 'zod' export type CustomerPutRequest = {external_id?: (string | null) | undefined, business_address?: string | undefined, business_city?: string | undefined, business_state?: string | undefined, business_zip?: string | undefined, business_country?: string | undefined, business_ap_email?: string | undefined, business_ap_phone?: string | undefined, business_ap_phone_extension?: string | undefined, business_name?: string | undefined, email?: string | undefined, default_terms?: ('net7' | 'net10' | 'net10th' | 'net15' | 'net20' | 'net30' | 'net45' | 'net60' | 'net75' | 'net90' | 'net120' | 'net180' | 'null' | null) | undefined}; export type UpdateApiCustomersCustomerIdArgs = {customer_id: string, body: CustomerPutRequest}; export type UpdateApiCustomersCustomerIdOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const customer = z.object({id: z.string().optional(), merchant_id: z.string().optional(), external_id: z.string().nullable().optional(), created_at: z.string().optional(), updated_at: z.string().optional(), source: z.enum(["QUICKBOOKS", "MERCHANT_USER", "ADMIN_USER", "APPLICATION", "CUSTOMER_USER", "API"]).optional(), business_address: z.string().optional(), business_city: z.string().optional(), business_state: z.string().optional(), business_zip: z.string().optional(), business_country: z.string().optional(), business_age_range: z.enum(["0-2", "2-5", "5-10", "10+"]).optional(), business_ap_email: z.string().optional(), business_ap_phone: z.string().optional(), business_ap_phone_extension: z.string().optional(), business_name: z.string().optional(), business_trade_name: z.string().optional(), business_phone: z.string().optional(), business_type: z.enum(["sole_prop_or_partnership", "llc", "corporation", "nonprofit", "government"]).optional(), email: z.string().optional(), personal_name_first: z.string().optional(), personal_name_last: z.string().optional(), personal_phone: z.string().optional(), amount_approved: z.number().int().optional(), amount_authorized: z.number().int().optional(), amount_available: z.number().int().optional(), amount_balance: z.number().int().optional(), amount_unapplied_payments: z.number().int().optional(), default_terms: z.enum(["net7", "net10", "net10th", "net15", "net20", "net30", "net45", "net60", "net75", "net90", "net120", "net180", "null"]).nullable().optional(), advance_rate: z.number().gte(0).lte(1).nullable().optional(), credit_status: z.enum(["approved", "hold", "declined", "pending", "deactivated", "null"]).nullable().optional(), net_terms_status: z.enum(["enrolled", "pending_enrollment", "enrollment_expired", "null"]).nullable().optional(), net_terms_enrollment_url: z.string().nullable().optional(), net_terms_enrollment_expires_at: z.string().nullable().optional(), credit_check_requested_at: z.string().nullable().optional(), archived: z.boolean().optional(), duns_number: z.string().nullable().optional(), credit_decisions: z.array(z.object({id: z.string().optional(), created_at: z.string().optional(), decision: z.enum(["approved", "declined", "hold", "line_adjustment", "deactivate"]).optional(), amount: z.number().int().optional(), advance_rate: z.number().gte(0).lte(1).optional(), decline_code: z.enum(["no_business_found", "thin_file", "failing_credit", "not_approved_need_more_info", "sole_prop", "applicant_business_association", "merchant_risk", "fraud", "no_us_address", "duplicate", "test_account", "email_verification_freemail", "email_verification_domain", "address_verification", "poor_cash_flow", "additional_info_not_provided", "other"]).nullable().optional(), hold_code: z.enum(["past_due", "failed_payment", "requested_by_customer", "requested_by_merchant", "dispute", "fraud", "churned", "payment_plan", "inactive", "other"]).nullable().optional()})).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 customer * * PUT /customers/{customer_id} * * Also accepts auth: basicAuth */ export const updateApiCustomersCustomerId = async (args: UpdateApiCustomersCustomerIdArgs, options?: UpdateApiCustomersCustomerIdOptions) => { const {baseUrl = "https://app-sandbox.resolvepay.com/api", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/customers/${encodeURIComponent(String(args.customer_id))}${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(customer, await res.json()) };