import {z} from 'zod' export type GetApiSuperuserKycHistoryArgs = {page?: number | undefined, pageSize?: number | undefined, id?: string | undefined, taxId?: string | undefined}; export type GetApiSuperuserKycHistoryOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const kycLimits = z.object({limitMint: z.number().int().optional(), limitBurn: z.number().int().optional(), limitSwapBuy: z.number().int().optional(), limitSwapSell: z.number().int().optional(), limitBRLAOutOwnAccount: z.number().int().optional(), limitBRLAOutThirdParty: z.number().int().optional()}); export const kycHistoryLog = z.object({id: z.string().optional(), userName: z.string().optional(), status: z.string().optional(), level: z.number().int().optional(), limits: kycLimits.optional(), birthDate: z.string().optional(), documentData: z.string().optional(), createdAt: z.string().optional(), updatedAt: z.string().optional(), failureReason: z.string().optional(), documentType: z.string().optional(), partnerTaxId: z.string().optional()}); export const kycHistoryOutput = z.object({history: z.array(kycHistoryLog).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 KYC operations * * GET /superuser/kyc/history * * Also accepts auth: apiKeyAuth + apiSignatureAuth + apiTimestampAuth */ export const getApiSuperuserKycHistory = async (args: GetApiSuperuserKycHistoryArgs, options?: GetApiSuperuserKycHistoryOptions) => { 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.id != null) query.append("id", String(args.id)) if (args.taxId != null) query.append("taxId", String(args.taxId)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/superuser/kyc/history${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(kycHistoryOutput, await res.json()) };