import {z} from 'zod' export type GetApiProfileActivitiesBalanceLogsArgs = {page?: number | undefined, page_size?: number | undefined, order_by?: string | undefined, order_dir?: string | undefined, q?: (string | null) | undefined, kind?: ('points' | 'gb' | null) | undefined, direction?: ('credit' | 'debit' | null) | undefined, date_from?: (string | null) | undefined, date_to?: (string | null) | undefined}; export type GetApiProfileActivitiesBalanceLogsOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const balanceLogItem = z.object({id: z.number().int(), user_id: z.number().int(), user_email: z.string().nullable().optional(), kind: z.string(), delta_total: z.number().int(), delta_subscription: z.number().int(), delta_extra: z.number().int(), reason: z.string().nullable().optional(), metadata: z.record(z.string(), z.unknown()).nullable().optional(), created_at: z.string()}); export const paginatedResponseBalanceLogItem = z.object({items: z.array(balanceLogItem), total: z.number().int(), page: z.number().int(), page_size: z.number().int(), blacklisted_value: z.string().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 }; /** * List balance history for the current account * * GET /profile/activities/balance-logs */ export const getApiProfileActivitiesBalanceLogs = async (args: GetApiProfileActivitiesBalanceLogsArgs, options?: GetApiProfileActivitiesBalanceLogsOptions) => { const {baseUrl = "https://api.leakradar.io", 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.page_size != null) query.append("page_size", String(args.page_size)) if (args.order_by != null) query.append("order_by", String(args.order_by)) if (args.order_dir != null) query.append("order_dir", String(args.order_dir)) if (args.q != null) query.append("q", String(args.q)) if (args.kind != null) query.append("kind", String(args.kind)) if (args.direction != null) query.append("direction", String(args.direction)) 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 (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/profile/activities/balance-logs${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(paginatedResponseBalanceLogItem, await res.json()) };