hibp
Version:
An unofficial TypeScript SDK for the 'Have I been pwned?' service.
106 lines (105 loc) • 3.29 kB
TypeScript
import type { Breach } from './api/haveibeenpwned/types.js';
/**
* Fetches breach data for a specific account.
*
* 🔑 `haveibeenpwned.com` requires an API key from
* https://haveibeenpwned.com/API/Key for the `breachedaccount` endpoint. The
* `apiKey` option here is not explicitly required, but direct requests made
* without it will fail (unless you specify a `baseUrl` to a proxy that inserts
* a valid API key on your behalf).
*
* @param {string} account a username or email address
* @param {object} [options] a configuration object
* @param {string} [options.apiKey] an API key from
* https://haveibeenpwned.com/API/Key (default: undefined)
* @param {string} [options.domain] a domain by which to filter the results
* (default: all domains)
* @param {boolean} [options.includeUnverified] include "unverified" breaches in
* the results (default: true)
* @param {number} [options.timeoutMs] timeout for the request in milliseconds
* (default: none)
* @param {boolean} [options.truncate] truncate the results to only include
* the name of each breach (default: true)
* @param {string} [options.baseUrl] a custom base URL for the
* haveibeenpwned.com API endpoints (default:
* `https://haveibeenpwned.com/api/v3`)
* @param {string} [options.userAgent] a custom string to send as the User-Agent
* field in the request headers (default: `hibp <version>`)
* @returns {(Promise<Breach[]> | Promise<null>)} a Promise which resolves to an
* array of breach objects (or null if no breaches were found), or rejects with
* an Error
* @example
* try {
* const data = await breachedAccount("foo", { apiKey: "my-api-key" });
* if (data) {
* // ...
* } else {
* // ...
* }
* } catch (err) {
* // ...
* }
* @example
* try {
* const data = await breachedAccount("bar", {
* includeUnverified: false,
* baseUrl: "https://my-hibp-proxy:8080",
* });
* if (data) {
* // ...
* } else {
* // ...
* }
* } catch (err) {
* // ...
* }
* @example
* try {
* const data = await breachedAccount("baz", {
* apiKey: "my-api-key",
* domain: "adobe.com",
* truncate: false,
* userAgent: "my-app 1.0",
* });
* if (data) {
* // ...
* } else {
* // ...
* }
* } catch (err) {
* // ...
* }
*/
export declare function breachedAccount(account: string, options?: {
/**
* an API key from https://haveibeenpwned.com/API/Key (default: undefined)
*/
apiKey?: string;
/**
* a domain by which to filter the results (default: all domains)
*/
domain?: string;
/**
* include "unverified" breaches in the results (default: true)
*/
includeUnverified?: boolean;
/**
* timeout for the request in milliseconds (default: none)
*/
timeoutMs?: number;
/**
* truncate the results to only include the name of each breach (default:
* true)
*/
truncate?: boolean;
/**
* a custom base URL for the haveibeenpwned.com API endpoints (default:
* `https://haveibeenpwned.com/api/v3`)
*/
baseUrl?: string;
/**
* a custom string to send as the User-Agent field in the request headers
* (default: `hibp <version>`)
*/
userAgent?: string;
}): Promise<Breach[] | null>;