import {z} from 'zod' export type GetApiProfileActivitiesTasksArgs = {page?: number | undefined, page_size?: number | undefined, order_by?: string | undefined, order_dir?: string | undefined, q?: (string | null) | undefined, status?: ('QUEUED' | 'RUNNING' | 'COMPLETED' | 'FAILED' | 'CANCELED' | null) | undefined, kind?: (string | null) | undefined, scope?: (string | null) | undefined, date_from?: (string | null) | undefined, date_to?: (string | null) | undefined}; export type GetApiProfileActivitiesTasksOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const userTaskItem = z.object({id: z.number().int(), kind: z.string(), scope: z.string().nullable().optional(), status: z.string(), total: z.number().int().nullable().optional(), updated: z.number().int(), points_charged: z.number().int(), error_message: z.string().nullable().optional(), created_at: z.string(), started_at: z.string().nullable().optional(), finished_at: z.string().nullable().optional()}); export const paginatedResponseUserTaskItem = z.object({items: z.array(userTaskItem), 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 task history for the current account * * GET /profile/activities/tasks */ export const getApiProfileActivitiesTasks = async (args: GetApiProfileActivitiesTasksArgs, options?: GetApiProfileActivitiesTasksOptions) => { 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.status != null) query.append("status", String(args.status)) if (args.kind != null) query.append("kind", String(args.kind)) if (args.scope != null) query.append("scope", String(args.scope)) 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/tasks${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(paginatedResponseUserTaskItem, await res.json()) };