import {z} from 'zod' export type GetApiApiV2RiskintelligenceLeaksLeakIdArgs = {leakId: string}; export type GetApiApiV2RiskintelligenceLeaksLeakIdOptions = {baseUrl?: string | undefined, OAuthv2?: string | undefined, fetch?: typeof fetch | undefined}; export const riskIntelligenceLeak = z.object({LeakId: z.number().optional(), Name: z.string().optional(), SourceDomain: z.string().optional(), Type: z.enum(["combolist", "breach"]).optional(), CurrentExposure: z.number().optional(), PublishDate: z.string().optional(), RecordType: z.string().optional(), UniqueEmailAccountCount: z.number().optional(), FreshnessRate: z.number().int().optional(), TotalCount: z.number().int().optional(), ThreatActor: z.string().optional(), SourceType: z.string().optional(), PasswordType: z.string().optional(), Notes: 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 }; /** * Get details of a leak. * * GET /api/v2/riskintelligence/leaks/{leakId} */ export const getApiApiV2RiskintelligenceLeaksLeakId = async (args: GetApiApiV2RiskintelligenceLeaksLeakIdArgs, options?: GetApiApiV2RiskintelligenceLeaksLeakIdOptions) => { const {baseUrl = "https://app.blackkitetech.com", fetch: fetchFn = fetch, OAuthv2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (OAuthv2 !== undefined) headers.set('authorization', `Bearer ${OAuthv2}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v2/riskintelligence/leaks/${encodeURIComponent(String(args.leakId))}${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(riskIntelligenceLeak, await res.json()) };