import {z} from 'zod' export type GetApiApiV1AdminTransfermateGlobalAccountsUserBankIdDetailsArgs = {userBankId: string, provider?: string | undefined, date_from?: string | undefined, date_to?: string | undefined, items_per_page?: ('10' | '20' | '50' | '100') | undefined, p_number?: string | undefined, transaction_id?: string | undefined}; export type GetApiApiV1AdminTransfermateGlobalAccountsUserBankIdDetailsOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const adminTransfermateGlobalAccountByUserBankIdResponse = z.object({success: z.boolean(), data: z.object({resolved: z.object({merchantId: z.string(), bankAccountId: z.string(), provider: z.string(), userBankId: z.number()}), tm: z.object({is_successful: z.boolean(), messages: z.object({}), page: z.number().optional(), pages_count: z.number().optional(), records_per_page: z.number().optional(), total_records: z.number().optional(), data: z.array(z.object({}))})})}); 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 }; /** * Debug-only: fetch raw TransferMate global account details by raw user_bank_id (resolves the owning merchant via provider_metadata to authenticate). Use when you only have a user_bank_id from a webhook/TM dashboard and don't know the QK bank account ID. Returns 404 if no QK bank account owns that user_bank_id. * * GET /api/v1/admin/transfermate/global-accounts/{userBankId}/details */ export const getApiApiV1AdminTransfermateGlobalAccountsUserBankIdDetails = async (args: GetApiApiV1AdminTransfermateGlobalAccountsUserBankIdDetailsArgs, options?: GetApiApiV1AdminTransfermateGlobalAccountsUserBankIdDetailsOptions) => { const {baseUrl = "https://core.quidkey.com", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.provider != null) query.append("provider", String(args.provider)) if (args.date_from != null) query.append("date_from", String(args.date_from)) if (args.date_to != null) query.append("date_to", String(args.date_to)) if (args.items_per_page != null) query.append("items_per_page", String(args.items_per_page)) if (args.p_number != null) query.append("p_number", String(args.p_number)) if (args.transaction_id != null) query.append("transaction_id", String(args.transaction_id)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/admin/transfermate/global-accounts/${encodeURIComponent(String(args.userBankId))}/details${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(adminTransfermateGlobalAccountByUserBankIdResponse, await res.json()) };