import {z} from 'zod' export type GetApiSuperuserUnexpectedDepositsArgs = {page?: number | undefined, pageSize?: number | undefined, taxId?: string | undefined, id?: string | undefined, referenceLabel?: string | undefined}; export type GetApiSuperuserUnexpectedDepositsOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const unexpectedDepositLog = z.object({id: z.string().optional(), workspaceId: z.string().optional(), depositId: z.string().optional(), name: z.string().optional(), taxId: z.string().optional(), bankCode: z.string().optional(), branchCode: z.string().optional(), accountNumber: z.string().optional(), accountType: z.string().optional(), amount: z.number().int().optional(), type: z.string().optional(), status: z.string().optional(), createdAt: z.string().optional(), reason: z.string().optional(), chargedBackAmount: z.number().int().optional()}); export const unexpectedDepositHistoryOutput = z.object({unexpectedDeposits: z.array(unexpectedDepositLog).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 }; /** * Retrieves history of unexpected deposits * * GET /superuser/unexpected-deposits * * Also accepts auth: apiKeyAuth + apiSignatureAuth + apiTimestampAuth */ export const getApiSuperuserUnexpectedDeposits = async (args: GetApiSuperuserUnexpectedDepositsArgs, options?: GetApiSuperuserUnexpectedDepositsOptions) => { const {baseUrl = "https://api.brla.digital:5567/v1", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.page != null) query.append("page", String(args.page)) if (args.pageSize != null) query.append("pageSize", String(args.pageSize)) if (args.taxId != null) query.append("taxId", String(args.taxId)) if (args.id != null) query.append("id", String(args.id)) if (args.referenceLabel != null) query.append("referenceLabel", String(args.referenceLabel)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/superuser/unexpected-deposits${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(unexpectedDepositHistoryOutput, await res.json()) };