import {z} from 'zod' export type AdvancedTextMatchType = 'contains' | 'starts_with' | 'ends_with'; export type PasswordStrengthCategoryInput = 'too_weak' | 'weak' | 'medium' | 'strong'; export type GetApiProfileUnlockedAdvancedArgs = {page?: number | undefined, page_size?: number | undefined, search?: (string | null) | undefined, list_id?: (number | null) | undefined, list_none?: (boolean | null) | undefined, status?: (string | null) | undefined, username?: (Array | null) | undefined, username_not?: (Array | null) | undefined, username_match_type?: (AdvancedTextMatchType | null) | undefined, username_not_match_type?: (AdvancedTextMatchType | null) | undefined, password?: (Array | null) | undefined, password_not?: (Array | null) | undefined, password_match_type?: (AdvancedTextMatchType | null) | undefined, password_not_match_type?: (AdvancedTextMatchType | null) | undefined, url?: (Array | null) | undefined, url_not?: (Array | null) | undefined, url_match_type?: (AdvancedTextMatchType | null) | undefined, url_not_match_type?: (AdvancedTextMatchType | null) | undefined, url_domain?: (Array | null) | undefined, url_domain_not?: (Array | null) | undefined, url_domain_match_type?: (AdvancedTextMatchType | null) | undefined, url_domain_not_match_type?: (AdvancedTextMatchType | null) | undefined, url_host?: (Array | null) | undefined, url_host_not?: (Array | null) | undefined, url_host_match_type?: (AdvancedTextMatchType | null) | undefined, url_host_not_match_type?: (AdvancedTextMatchType | null) | undefined, username_hash?: (Array | null) | undefined, password_hash?: (Array | null) | undefined, url_scheme?: (Array | null) | undefined, url_scheme_not?: (Array | null) | undefined, url_port?: (Array | null) | undefined, url_port_not?: (Array | null) | undefined, url_tld?: (Array | null) | undefined, url_tld_not?: (Array | null) | undefined, is_email?: (boolean | null) | undefined, email_domain?: (Array | null) | undefined, email_domain_not?: (Array | null) | undefined, email_domain_match_type?: (AdvancedTextMatchType | null) | undefined, email_domain_not_match_type?: (AdvancedTextMatchType | null) | undefined, email_host?: (Array | null) | undefined, email_host_not?: (Array | null) | undefined, email_host_match_type?: (AdvancedTextMatchType | null) | undefined, email_host_not_match_type?: (AdvancedTextMatchType | null) | undefined, email_tld?: (Array | null) | undefined, email_tld_not?: (Array | null) | undefined, password_strength?: (PasswordStrengthCategoryInput | null) | undefined, added_from?: (string | null) | undefined, added_to?: (string | null) | undefined, force_and?: (boolean | null) | undefined}; export type GetApiProfileUnlockedAdvancedOptions = {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 with advanced filters * * GET /profile/unlocked/advanced */ export const getApiProfileUnlockedAdvanced = async (args: GetApiProfileUnlockedAdvancedArgs, options?: GetApiProfileUnlockedAdvancedOptions) => { 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.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)) for (const item of args.username ?? []) query.append("username", String(item)) for (const item of args.username_not ?? []) query.append("username_not", String(item)) if (args.username_match_type != null) query.append("username_match_type", String(args.username_match_type)) if (args.username_not_match_type != null) query.append("username_not_match_type", String(args.username_not_match_type)) for (const item of args.password ?? []) query.append("password", String(item)) for (const item of args.password_not ?? []) query.append("password_not", String(item)) if (args.password_match_type != null) query.append("password_match_type", String(args.password_match_type)) if (args.password_not_match_type != null) query.append("password_not_match_type", String(args.password_not_match_type)) for (const item of args.url ?? []) query.append("url", String(item)) for (const item of args.url_not ?? []) query.append("url_not", String(item)) if (args.url_match_type != null) query.append("url_match_type", String(args.url_match_type)) if (args.url_not_match_type != null) query.append("url_not_match_type", String(args.url_not_match_type)) for (const item of args.url_domain ?? []) query.append("url_domain", String(item)) for (const item of args.url_domain_not ?? []) query.append("url_domain_not", String(item)) if (args.url_domain_match_type != null) query.append("url_domain_match_type", String(args.url_domain_match_type)) if (args.url_domain_not_match_type != null) query.append("url_domain_not_match_type", String(args.url_domain_not_match_type)) for (const item of args.url_host ?? []) query.append("url_host", String(item)) for (const item of args.url_host_not ?? []) query.append("url_host_not", String(item)) if (args.url_host_match_type != null) query.append("url_host_match_type", String(args.url_host_match_type)) if (args.url_host_not_match_type != null) query.append("url_host_not_match_type", String(args.url_host_not_match_type)) for (const item of args.username_hash ?? []) query.append("username_hash", String(item)) for (const item of args.password_hash ?? []) query.append("password_hash", String(item)) for (const item of args.url_scheme ?? []) query.append("url_scheme", String(item)) for (const item of args.url_scheme_not ?? []) query.append("url_scheme_not", String(item)) for (const item of args.url_port ?? []) query.append("url_port", String(item)) for (const item of args.url_port_not ?? []) query.append("url_port_not", String(item)) for (const item of args.url_tld ?? []) query.append("url_tld", String(item)) for (const item of args.url_tld_not ?? []) query.append("url_tld_not", String(item)) if (args.is_email != null) query.append("is_email", String(args.is_email)) for (const item of args.email_domain ?? []) query.append("email_domain", String(item)) for (const item of args.email_domain_not ?? []) query.append("email_domain_not", String(item)) if (args.email_domain_match_type != null) query.append("email_domain_match_type", String(args.email_domain_match_type)) if (args.email_domain_not_match_type != null) query.append("email_domain_not_match_type", String(args.email_domain_not_match_type)) for (const item of args.email_host ?? []) query.append("email_host", String(item)) for (const item of args.email_host_not ?? []) query.append("email_host_not", String(item)) if (args.email_host_match_type != null) query.append("email_host_match_type", String(args.email_host_match_type)) if (args.email_host_not_match_type != null) query.append("email_host_not_match_type", String(args.email_host_not_match_type)) for (const item of args.email_tld ?? []) query.append("email_tld", String(item)) for (const item of args.email_tld_not ?? []) query.append("email_tld_not", String(item)) if (args.password_strength != null) query.append("password_strength", String(args.password_strength)) if (args.added_from != null) query.append("added_from", String(args.added_from)) if (args.added_to != null) query.append("added_to", String(args.added_to)) if (args.force_and != null) query.append("force_and", String(args.force_and)) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/profile/unlocked/advanced${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()) };