import {z} from 'zod' export type GetApiMerchantsMerchantIdArgs = {with?: ('merchant_currencies' | 'merchant_payment_methods' | 'merchant_card_types' | 'primary_merchant_category' | 'secondary_merchant_category') | undefined}; export type GetApiMerchantsMerchantIdOptions = {baseUrl?: string | undefined, AccessTokenAuthorizer?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiMerchantsMerchantIdResponse = z.object({merchant_id: z.number().int().optional(), merchant_name: z.string().optional(), gateway_id: z.number().int().optional(), currency_id: z.number().int().optional(), merchant_mid_id: z.string().optional(), merchant_descriptor: z.string().optional(), merchant_phone: z.string().optional(), merchant_url: z.string().optional(), merchant_active: z.boolean().optional(), merchant_processor: z.string().nullable().optional(), merchant_mcc_code: z.string().nullable().optional(), merchant_processing_limit: z.string().optional(), merchant_processing_inforce: z.boolean().optional(), merchant_daily_rebills_limit: z.string().optional(), merchant_state: z.string().nullable().optional(), merchant_tax: z.string().optional(), merchant_mtd_revenue: z.string().optional(), merchant_mtd_transactions: z.number().int().optional(), merchant_mtd_initial: z.number().int().optional(), merchant_processing_perc: z.string().optional(), primary_merchant_category_id: z.number().int().optional(), secondary_merchant_category_id: z.number().int().optional(), merchant_notes: z.string().nullable().optional(), date_created: z.string().optional(), created_by: z.number().int().optional(), date_modified: z.string().optional(), modified_by: z.number().int().optional(), merchant_currencies: z.array(z.object({currency_id: z.number().int().optional(), currency_value: z.string().optional()})).optional(), merchant_payment_methods: z.array(z.object({payment_method_id: z.number().int().optional(), payment_method_name: z.string().optional()})).optional(), merchant_card_types: z.array(z.object({card_type_id: z.number().int().optional(), card_type_name: z.string().optional()})).optional(), primary_merchant_category: z.object({merchant_category_id: z.number().int().optional(), merchant_category_name: z.string().optional()}).nullable().optional(), secondary_merchant_category: z.object({merchant_category_id: z.number().int().optional(), merchant_category_name: z.string().optional()}).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 }; /** * Get a merchant * * GET /merchants/{merchant_id} */ export const getApiMerchantsMerchantId = async (args: GetApiMerchantsMerchantIdArgs, options?: GetApiMerchantsMerchantIdOptions) => { const {baseUrl = "https://api.vrio.app", fetch: fetchFn = fetch, AccessTokenAuthorizer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.with != null) query.append("with", String(args.with)) if (AccessTokenAuthorizer !== undefined) headers.set("X-Api-Key", AccessTokenAuthorizer) 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(getApiMerchantsMerchantIdResponse, await res.json()) };