import {z} from 'zod' export type GetApiV1LeaksStatsDomainArgs = {domain?: string | undefined, unmask_email?: boolean | undefined}; export type GetApiV1LeaksStatsDomainOptions = {baseUrl?: string | undefined, XAPIKey?: string | undefined, fetch?: typeof fetch | undefined}; export const devicesCount = z.object({devices: z.number().optional()}); export const customersCount = z.object({customers: z.number().optional()}); export const usersCount = z.object({user: z.number().optional()}); export const employeesCount = z.object({employees: z.number().optional()}); export const combolistExposureCount = z.object({combolist_exposure: z.number().optional()}); export const leakCountryStats = z.object({Country: z.string().optional(), CredentialsCount: z.number().optional()}); export const usedUrlsCount = z.object({count: z.number().optional(), url: z.string().optional()}); export const leaksTimeline = z.object({CredentialsCount: z.number().optional(), Month: z.number().optional(), Year: z.number().optional()}); export const leaksUsersSampleData = z.object({password: z.string().optional(), username: z.string().optional(), url: z.string().optional(), country: z.string().optional(), log_date: z.string().optional()}); export const getApiV1LeaksStatsDomainResponse = z.object({leak_devices_count: z.array(devicesCount).optional(), leak_customers_count: z.array(customersCount).optional(), leak_user_count: z.array(usersCount).optional(), leak_employees_count: z.array(employeesCount).optional(), combolist_exposure: z.array(combolistExposureCount).optional(), leak_country_stats: z.array(leakCountryStats).optional(), top_used_urls_by_customers: z.array(usedUrlsCount).optional(), top_used_urls_by_employees: z.array(usedUrlsCount).optional(), top_used_urls_by_user: z.array(usedUrlsCount).optional(), leak_customers_timeline: z.array(leaksTimeline).optional(), leak_user_timeline: z.array(leaksTimeline).optional(), leak_employees_timeline: z.array(leaksTimeline).optional(), customers_sample_data: z.array(leaksUsersSampleData).optional(), employees_sample_data: z.array(leaksUsersSampleData).optional(), user_sample_data: z.array(leaksUsersSampleData).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 }; /** * Get leak statistics for a domain (Public) * * GET /v1/leaks/stats/domain */ export const getApiV1LeaksStatsDomain = async (args: GetApiV1LeaksStatsDomainArgs, options?: GetApiV1LeaksStatsDomainOptions) => { const {baseUrl = "https://api.projectdiscovery.io", fetch: fetchFn = fetch, XAPIKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.domain != null) query.append("domain", String(args.domain)) if (args.unmask_email != null) query.append("unmask_email", String(args.unmask_email)) if (XAPIKey !== undefined) headers.set("X-API-Key", XAPIKey) const url = `${baseUrl.replace(/\/+$/, '')}/v1/leaks/stats/domain${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(getApiV1LeaksStatsDomainResponse, await res.json()) };