import {z} from 'zod' export type GetApiProfileUnlockedArgs = {page?: number | undefined, page_size?: number | undefined, search?: (string | null) | undefined, is_email?: (boolean | null) | undefined, list_id?: (number | null) | undefined, list_none?: (boolean | null) | undefined, status?: (string | null) | undefined}; export type GetApiProfileUnlockedOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const unlockedLeakDetails = z.object({id: z.string(), url: z.string(), username: z.string(), password: z.string().nullable().optional(), password_strength: z.number().int(), unlocked: z.boolean().optional(), is_email: z.boolean(), added_at: z.string(), unlocked_at: z.string(), auto_unlocked: z.boolean().optional(), auto_unlocked_by: z.number().int().nullable().optional(), list_id: z.number().int().nullable().optional(), comment: z.string().nullable().optional(), status: z.string().optional()}); export const paginatedUnlockedLeaksResponse = z.object({items: z.array(unlockedLeakDetails), total: z.number().int(), total_unlocked: z.number().int(), page: z.number().int(), page_size: z.number().int()}); 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 your unlocked leaks * * GET /profile/unlocked */ export const getApiProfileUnlocked = async (args: GetApiProfileUnlockedArgs, options?: GetApiProfileUnlockedOptions) => { 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.search != null) query.append("search", String(args.search)) if (args.is_email != null) query.append("is_email", String(args.is_email)) if (args.list_id != null) query.append("list_id", String(args.list_id)) if (args.list_none != null) query.append("list_none", String(args.list_none)) if (args.status != null) query.append("status", String(args.status)) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/profile/unlocked${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(paginatedUnlockedLeaksResponse, await res.json()) };