import {z} from 'zod' export type GetApiMerchantsMerchantIdArgs = {merchant_id: string}; export type GetApiMerchantsMerchantIdOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const address = z.object({line1: z.string(), line2: z.string().nullable().optional(), city: z.string(), state: z.string(), postal_code: z.string(), country: z.string()}); export const documentIngestionResult = z.object({document_id: z.string().nullable().optional(), document_type: z.enum(["bank_statements", "financial_statements", "credit_references", "personal_guarantee", "other"]).optional(), filename: z.string().optional(), download_url: z.string().optional(), status: z.enum(["queued", "failed"]).optional(), error_code: z.string().nullable().optional(), error_message: z.string().nullable().optional()}); export const documentIngestionSummary = z.object({requested_count: z.number().int().optional(), queued_count: z.number().int().optional(), failed_count: z.number().int().optional(), results: z.array(documentIngestionResult).optional()}); export const merchant = z.object({id: z.string().optional(), reference_id: z.string().nullable().optional(), legal_business_name: z.string().optional(), dba_name: z.string().nullable().optional(), business_address: address.optional(), business_email: z.string().optional(), business_phone: z.string().optional(), entity_type: z.enum(["corporation", "llc", "sole_proprietorship", "partnership", "non_profit"]).optional(), formation_state: z.string().optional(), industry: z.string().nullable().optional(), website: z.string().nullable().optional(), underwriting_status: z.string().optional(), seller_amount_approved: z.number().int().nullable().optional(), active_subscription: z.object({id: z.string().optional(), tier: z.string().optional()}).nullable().optional(), metadata: z.record(z.string(), z.unknown()).optional(), document_ingestion: documentIngestionSummary.optional(), created_at: z.string().optional(), updated_at: 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 }; /** * Get Merchant * * GET /merchants/{merchant_id} * * Also accepts auth: basicAuth */ export const getApiMerchantsMerchantId = async (args: GetApiMerchantsMerchantIdArgs, options?: GetApiMerchantsMerchantIdOptions) => { const {baseUrl = "https://app-sandbox.resolvepay.com/api", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/merchants/${encodeURIComponent(String(args.merchant_id))}${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(merchant, await res.json()) };