Skip to content

Commit

Permalink
fix: add descriptions to each config option (#428)
Browse files Browse the repository at this point in the history
  • Loading branch information
wKovacs64 committed Nov 9, 2023
1 parent ecb0e98 commit 4a69884
Show file tree
Hide file tree
Showing 10 changed files with 129 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/fair-beds-sneeze.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'hibp': patch
---

Add descriptions to each config option for a better IDE experience.
8 changes: 8 additions & 0 deletions src/breach.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,15 @@ import { fetchFromApi } from './api/haveibeenpwned/fetch-from-api.js';
export function breach(
breachName: string,
options: {
/**
* 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> {
Expand Down
21 changes: 21 additions & 0 deletions src/breached-account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,32 @@ import { fetchFromApi } from './api/haveibeenpwned/fetch-from-api.js';
export 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;
/**
* 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> {
Expand Down
11 changes: 11 additions & 0 deletions src/breaches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,19 @@ import { fetchFromApi } from './api/haveibeenpwned/fetch-from-api.js';
*/
export function breaches(
options: {
/**
* a domain by which to filter the results (default: all domains)
*/
domain?: string;
/**
* 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[]> {
Expand Down
8 changes: 8 additions & 0 deletions src/data-classes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,15 @@ import { fetchFromApi } from './api/haveibeenpwned/fetch-from-api.js';
*/
export function dataClasses(
options: {
/**
* 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<string[] | null> {
Expand Down
11 changes: 11 additions & 0 deletions src/paste-account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,19 @@ import { fetchFromApi } from './api/haveibeenpwned/fetch-from-api.js';
export function pasteAccount(
email: string,
options: {
/**
* an API key from https://haveibeenpwned.com/API/Key (default: undefined)
*/
apiKey?: string;
/**
* 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<Paste[] | null> {
Expand Down
27 changes: 21 additions & 6 deletions src/pwned-password-range.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ export type PwnedPasswordSuffixes = Record<string, number>;
* @param {string} prefix the first 5 characters of a password hash (case
* insensitive)
* @param {object} [options] a configuration object
* @param {string} [options.baseUrl] a custom base URL for the
* pwnedpasswords.com API endpoints (default: `https://api.pwnedpasswords.com`)
* @param {string} [options.userAgent] a custom string to send as the User-Agent
* field in the request headers (default: `hibp <version>`)
* @param {boolean} [options.addPadding] ask the remote API to add padding to
* the response to obscure the password prefix (default: `false`)
* @param {'sha1' | 'ntlm'} [options.mode] return SHA-1 or NTLM hashes
* (default: `sha1`)
* @param {string} [options.baseUrl] a custom base URL for the
* pwnedpasswords.com API endpoints (default: `https://api.pwnedpasswords.com`)
* @param {string} [options.userAgent] a custom string to send as the User-Agent
* field in the request headers (default: `hibp <version>`)
* @returns {Promise<PwnedPasswordSuffixes>} a Promise which resolves to an
* object mapping the `suffix` that when matched with the prefix composes the
* complete hash, to the `count` of how many times it appears in the breached
Expand Down Expand Up @@ -60,10 +60,25 @@ export type PwnedPasswordSuffixes = Record<string, number>;
export async function pwnedPasswordRange(
prefix: string,
options: {
baseUrl?: string;
userAgent?: string;
/**
* ask the remote API to add padding to the response to obscure the password
* prefix (default: `false`)
*/
addPadding?: boolean;
/**
* return SHA-1 or NTLM hashes (default: `sha1`)
*/
mode?: 'sha1' | 'ntlm';
/**
* 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<PwnedPasswordSuffixes> {
const { baseUrl, userAgent, addPadding = false, mode = 'sha1' } = options;
Expand Down
18 changes: 15 additions & 3 deletions src/pwned-password.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import { pwnedPasswordRange } from './pwned-password-range.js';
*
* @param {string} password a password in plain text
* @param {object} [options] a configuration object
* @param {boolean} [options.addPadding] ask the remote API to add padding to
* the response to obscure the password prefix (default: `false`)
* @param {string} [options.baseUrl] a custom base URL for the
* pwnedpasswords.com API endpoints (default: `https://api.pwnedpasswords.com`)
* @param {string} [options.userAgent] a custom string to send as the User-Agent
* field in the request headers (default: `hibp <version>`)
* @param {boolean} [options.addPadding] ask the remote API to add padding to
* the response to obscure the password prefix (default: `false`)
* @returns {Promise<number>} a Promise which resolves to the number of times
* the password has been exposed in a breach, or rejects with an Error
* @example
Expand All @@ -33,9 +33,21 @@ import { pwnedPasswordRange } from './pwned-password-range.js';
export async function pwnedPassword(
password: string,
options: {
/**
* ask the remote API to add padding to the response to obscure the password
* prefix (default: `false`)
*/
addPadding?: 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;
addPadding?: boolean;
} = {},
): Promise<number> {
/* eslint-disable */
Expand Down
18 changes: 18 additions & 0 deletions src/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,28 @@ export interface SearchResults {
export async function search(
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;
/**
* 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<SearchResults> {
Expand Down
11 changes: 11 additions & 0 deletions src/subscription-status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,19 @@ import { fetchFromApi } from './api/haveibeenpwned/fetch-from-api.js';
*/
export async function subscriptionStatus(
options: {
/**
* an API key from https://haveibeenpwned.com/API/Key (default: undefined)
*/
apiKey?: string;
/**
* 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;
} = {},
) {
Expand Down

0 comments on commit 4a69884

Please sign in to comment.