hibp 16.0.0 → 16.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/dist/browser/hibp.module.js +2 -2
- package/dist/esm/api/base-fetch.d.ts +8 -6
- package/dist/esm/api/base-fetch.js +5 -11
- package/dist/esm/api/base-fetch.js.map +1 -1
- package/dist/esm/api/haveibeenpwned/fetch-from-api.js +28 -57
- package/dist/esm/api/haveibeenpwned/fetch-from-api.js.map +1 -1
- package/dist/esm/api/haveibeenpwned/package-info.d.ts +1 -1
- package/dist/esm/api/haveibeenpwned/package-info.js +1 -1
- package/dist/esm/api/haveibeenpwned/post-to-api.js +1 -9
- package/dist/esm/api/haveibeenpwned/post-to-api.js.map +1 -1
- package/dist/esm/api/haveibeenpwned/responses.d.ts +0 -10
- package/dist/esm/api/haveibeenpwned/responses.js +3 -35
- package/dist/esm/api/haveibeenpwned/responses.js.map +1 -1
- package/dist/esm/api/haveibeenpwned/types.js +0 -3
- package/dist/esm/api/haveibeenpwned/types.js.map +1 -1
- package/dist/esm/api/pwnedpasswords/fetch-from-api.js +1 -24
- package/dist/esm/api/pwnedpasswords/fetch-from-api.js.map +1 -1
- package/dist/esm/api/pwnedpasswords/responses.d.ts +0 -6
- package/dist/esm/api/pwnedpasswords/responses.js +0 -6
- package/dist/esm/api/pwnedpasswords/responses.js.map +1 -1
- package/dist/esm/breach.d.ts +4 -4
- package/dist/esm/breach.js.map +1 -1
- package/dist/esm/breached-account-range.d.ts +5 -5
- package/dist/esm/breached-account-range.js.map +1 -1
- package/dist/esm/breached-account.d.ts +9 -9
- package/dist/esm/breached-account.js.map +1 -1
- package/dist/esm/breached-domain.d.ts +5 -5
- package/dist/esm/breached-domain.js.map +1 -1
- package/dist/esm/breaches.d.ts +6 -6
- package/dist/esm/breaches.js +2 -2
- package/dist/esm/breaches.js.map +1 -1
- package/dist/esm/data-class-descriptions.d.ts +4 -4
- package/dist/esm/data-class-descriptions.js.map +1 -1
- package/dist/esm/data-classes.d.ts +4 -4
- package/dist/esm/data-classes.js.map +1 -1
- package/dist/esm/generate-dns-token.d.ts +5 -5
- package/dist/esm/generate-dns-token.js +2 -1
- package/dist/esm/generate-dns-token.js.map +1 -1
- package/dist/esm/hibp.js +0 -11
- package/dist/esm/hibp.js.map +1 -1
- package/dist/esm/latest-breach.d.ts +4 -4
- package/dist/esm/latest-breach.js.map +1 -1
- package/dist/esm/paste-account.d.ts +5 -5
- package/dist/esm/paste-account.js.map +1 -1
- package/dist/esm/pwned-password-range.d.ts +6 -6
- package/dist/esm/pwned-password-range.js +0 -2
- package/dist/esm/pwned-password-range.js.map +1 -1
- package/dist/esm/pwned-password.d.ts +5 -5
- package/dist/esm/pwned-password.js +8 -3
- package/dist/esm/pwned-password.js.map +1 -1
- package/dist/esm/search.d.ts +8 -8
- package/dist/esm/search.js +2 -2
- package/dist/esm/search.js.map +1 -1
- package/dist/esm/send-email.d.ts +5 -5
- package/dist/esm/stealer-logs-by-email-domain.d.ts +5 -5
- package/dist/esm/stealer-logs-by-email-domain.js.map +1 -1
- package/dist/esm/stealer-logs-by-email.d.ts +5 -5
- package/dist/esm/stealer-logs-by-email.js.map +1 -1
- package/dist/esm/stealer-logs-by-website-domain.d.ts +5 -5
- package/dist/esm/stealer-logs-by-website-domain.js.map +1 -1
- package/dist/esm/subscribed-domains.d.ts +5 -5
- package/dist/esm/subscribed-domains.js +2 -2
- package/dist/esm/subscribed-domains.js.map +1 -1
- package/dist/esm/subscription-status.d.ts +5 -5
- package/dist/esm/subscription-status.js +2 -2
- package/dist/esm/subscription-status.js.map +1 -1
- package/dist/esm/verify-dns-token.d.ts +5 -5
- package/package.json +13 -13
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## 16.0.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#648](https://github.com/wKovacs64/hibp/pull/648) [`0deb503`](https://github.com/wKovacs64/hibp/commit/0deb503540d765e7a6368bd09b0739323fea25f0) Thanks [@wKovacs64](https://github.com/wKovacs64)! - Accept `undefined` for every optional option property, so consumers using `exactOptionalPropertyTypes` can pass possibly-unset values, such as `{ domain }` where `domain` is `string | undefined`, without conditional spreads. hibp treats `undefined` the same as an omitted option.
|
|
8
|
+
|
|
9
|
+
- [#645](https://github.com/wKovacs64/hibp/pull/645) [`7617801`](https://github.com/wKovacs64/hibp/commit/7617801e5391b5060e90fb1a28b2f85069f15048) Thanks [@wKovacs64](https://github.com/wKovacs64)! - `breaches()`, `subscribedDomains()`, and `subscriptionStatus()` reject on HTTP 404 instead of resolving `null`, which their return types exclude. haveibeenpwned.com does not send 404 for these endpoints, so this only affects responses from elsewhere, such as a proxy at a custom `baseUrl`.
|
|
10
|
+
|
|
3
11
|
## 16.0.0
|
|
4
12
|
|
|
5
13
|
### Major Changes
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
2
|
-
`).filter(Boolean).reduce((
|
|
1
|
+
var T="hibp",M="16.0.1";async function h({baseUrl:e,endpoint:t,headers:n,timeoutMs:r,signal:s,userAgent:i,queryParams:o,method:a,body:u}){let c={method:a??"GET",body:u??null,headers:K(i,n),signal:F(r,s)},p=k(e,t,o);return fetch(p,c)}function k(e,t,n){let r=e.replace(/\/$/g,""),s=t.startsWith("/")?t:`/${t}`,i=new URL(`${r}${s}`);if(n)for(let[o,a]of Object.entries(n))i.searchParams.set(o,a);return i.toString()}function K(e,t){let n={...t};return e?n["User-Agent"]=e:$()||(n["User-Agent"]=`${T} ${M}`),n}function F(e,t){let n=[];return e!==void 0&&e!==0&&!Number.isNaN(e)&&n.push(AbortSignal.timeout(e)),t&&n.push(t),n.length===0?null:n.length===1?n[0]:AbortSignal.any(n)}function $(){return typeof document<"u"||"importScripts"in globalThis}var P={status:400,statusText:"Bad request \u2014 the account does not comply with an acceptable format."},O={status:401},b={status:403,statusText:"Forbidden - access denied."},S={status:404,statusText:"Not found."},A={status:429};var f=class extends Error{retryAfterSeconds;constructor(t,n,r){super(n,r),this.name=this.constructor.name,this.retryAfterSeconds=t===null?void 0:Number.parseInt(t,10)}};async function x(e){return await e.json()}function D(e){return`Request blocked, contact haveibeenpwned.com if this continues (Ray ID: ${e})`}function y({status:e,statusText:t}){return`${e} ${t}`.trim()}function w(e){try{let t=JSON.parse(e);if(L(t)&&t.message.trim())return t.message}catch{return}}function L(e){return typeof e=="object"&&e!==null&&"message"in e&&typeof e.message=="string"}function R(e,t={},n){let{apiKey:r,baseUrl:s="https://haveibeenpwned.com/api/v3",timeoutMs:i,signal:o,userAgent:a}=t,u={};return r&&(u["HIBP-API-Key"]=r),n&&(u["Content-Type"]="application/json"),h({baseUrl:s,endpoint:e,headers:u,timeoutMs:i,signal:o,userAgent:a,method:n?"POST":void 0,body:n&&JSON.stringify(n)})}async function d(e,t={}){let n=await R(e,t);if(n.ok)return x(n);switch(n.status){case P.status:throw new Error(P.statusText);case O.status:{let r=await n.text();throw new Error(w(r)??(r.trim()?r:y(n)))}case b.status:{let r=n.headers.get("cf-ray");throw r?new Error(D(r)):new Error(b.statusText)}case S.status:return null;case A.status:{let r=w(await n.text())??y(n),s=n.headers.get("retry-after");throw new f(s,r)}default:throw new Error(n.statusText)}}async function g(e,t={}){let n=await d(e,t);if(n===null)throw new Error(S.statusText);return n}function j(e,t={}){return d(`/breach/${encodeURIComponent(e)}`,t)}function E(e,t={}){let{apiKey:n,domain:r,includeUnverified:s=!0,timeoutMs:i,signal:o,truncate:a=!0,baseUrl:u,userAgent:c}=t,p=`/breachedaccount/${encodeURIComponent(e)}?`,m=[];return r&&m.push(`domain=${encodeURIComponent(r)}`),s||m.push("includeUnverified=false"),a||m.push("truncateResponse=false"),d(`${p}${m.join("&")}`,{apiKey:n,baseUrl:u,timeoutMs:i,signal:o,userAgent:c})}function _(e,t={}){let{apiKey:n,baseUrl:r,timeoutMs:s,signal:i,userAgent:o}=t;return d(`/breachedaccount/range/${encodeURIComponent(e)}`,{apiKey:n,baseUrl:r,timeoutMs:s,signal:i,userAgent:o})}function q(e,t={}){let{apiKey:n,baseUrl:r,timeoutMs:s,signal:i,userAgent:o}=t,a=`/breacheddomain/${encodeURIComponent(e)}`;return d(a,{apiKey:n,baseUrl:r,timeoutMs:s,signal:i,userAgent:o})}function H(e={}){let{domain:t,isSpamList:n,baseUrl:r,timeoutMs:s,signal:i,userAgent:o}=e,a="/breaches?",u=[];return t&&u.push(`domain=${encodeURIComponent(t)}`),n!==void 0&&u.push(`isSpamList=${n}`),g(`${a}${u.join("&")}`,{baseUrl:r,timeoutMs:s,signal:i,userAgent:o})}function W(e={}){return d("/dataclasses",e)}function Q(e={}){return d("/dataclasses/descriptions",e)}async function l(e,t,n){let r=await R(e,n,t);if(r.ok)return r;let{headers:s,status:i}=r,o=await r.text(),a=s.get("cf-ray"),u=/^text\/plain\b/i.test(s.get("content-type")??""),c=w(o)??(i===b.status&&a?D(a):void 0)??(u&&o.trim()?o:void 0)??y(r);throw i===A.status?new f(s.get("retry-after"),c):new Error(c)}async function G(e,t={}){let n=await l("/domainVerification/generateDnsToken",{DomainName:e},t);return x(n)}function V(e={}){return d("/latestbreach",e)}function B(e,t={}){return d(`/pasteaccount/${encodeURIComponent(e)}`,t)}var N={status:400,body:"The hash prefix was not in a valid format"};async function I(e,t={}){let{baseUrl:n="https://api.pwnedpasswords.com",timeoutMs:r,signal:s,userAgent:i,addPadding:o=!1,mode:a="sha1"}=t,u={};o&&(u["Add-Padding"]="true");let c=await h({baseUrl:n,endpoint:e,headers:u,timeoutMs:r,signal:s,userAgent:i,queryParams:{mode:a}});if(c.ok)return c.text();if(c.status===N.status){let p=await c.text();throw new Error(p)}throw new Error(c.statusText)}async function U(e,t={}){let{baseUrl:n,timeoutMs:r,signal:s,userAgent:i,addPadding:o=!1,mode:a="sha1"}=t;return(await I(`/range/${encodeURIComponent(e)}`,{baseUrl:n,timeoutMs:r,signal:s,userAgent:i,addPadding:o,mode:a})).split(`
|
|
2
|
+
`).filter(Boolean).reduce((p,m)=>{let[v,C]=m.split(":");return p[v]=Number.parseInt(C,10),p},{})}async function J(e,t={}){let[n,r]=await Y(e),i=(await U(n,t))[r];return i===void 0||Number.isNaN(i)?0:i}async function Y(e){let t=Z()?.subtle;if(t){let n=new TextEncoder().encode(e),r=await t.digest("SHA-1",n),i=Array.from(new Uint8Array(r)).map(o=>o.toString(16).padStart(2,"0")).join("").toUpperCase();return[i.slice(0,5),i.slice(5)]}throw new Error("The Web Crypto API is not available in this environment.")}function Z(){return globalThis.crypto}var z=/^.+@.+$/;async function X(e,t={}){let{apiKey:n,domain:r,truncate:s=!0,baseUrl:i,timeoutMs:o,signal:a,userAgent:u}=t,[c,p]=await Promise.all([E(e,{apiKey:n,domain:r,truncate:s,baseUrl:i,timeoutMs:o,signal:a,userAgent:u}),z.test(e)?B(e,{apiKey:n,baseUrl:i,timeoutMs:o,signal:a,userAgent:u}):null]);return{breaches:c,pastes:p}}async function ee(e,t,n={}){await l("/domainVerification/sendEmail",{DomainName:e,EmailAlias:t},n)}function ne(e,t={}){let{apiKey:n,baseUrl:r,timeoutMs:s,signal:i,userAgent:o}=t,a=`/stealerlogsbyemail/${encodeURIComponent(e)}`;return d(a,{apiKey:n,baseUrl:r,timeoutMs:s,signal:i,userAgent:o})}function te(e,t={}){let{apiKey:n,baseUrl:r,timeoutMs:s,signal:i,userAgent:o}=t,a=`/stealerlogsbyemaildomain/${encodeURIComponent(e)}`;return d(a,{apiKey:n,baseUrl:r,timeoutMs:s,signal:i,userAgent:o})}function re(e,t={}){let{apiKey:n,baseUrl:r,timeoutMs:s,signal:i,userAgent:o}=t,a=`/stealerlogsbywebsitedomain/${encodeURIComponent(e)}`;return d(a,{apiKey:n,baseUrl:r,timeoutMs:s,signal:i,userAgent:o})}function ie(e={}){let{apiKey:t,baseUrl:n,timeoutMs:r,signal:s,userAgent:i}=e;return g("/subscribeddomains",{apiKey:t,baseUrl:n,timeoutMs:r,signal:s,userAgent:i})}async function se(e={}){return g("/subscription/status",e)}async function oe(e,t={}){await l("/domainVerification/verifyDnsToken",{DomainName:e},t)}export{f as RateLimitError,j as breach,E as breachedAccount,_ as breachedAccountRange,q as breachedDomain,H as breaches,Q as dataClassDescriptions,W as dataClasses,G as generateDnsToken,V as latestBreach,B as pasteAccount,J as pwnedPassword,U as pwnedPasswordRange,X as search,ee as sendEmail,ne as stealerLogsByEmail,te as stealerLogsByEmailDomain,re as stealerLogsByWebsiteDomain,ie as subscribedDomains,se as subscriptionStatus,oe as verifyDnsToken};
|
|
@@ -2,12 +2,14 @@ export declare function baseFetch({ baseUrl, endpoint, headers, timeoutMs, signa
|
|
|
2
2
|
baseUrl: string;
|
|
3
3
|
endpoint: string;
|
|
4
4
|
headers?: Record<string, string>;
|
|
5
|
-
timeoutMs?: number;
|
|
6
|
-
signal?: AbortSignal;
|
|
7
|
-
userAgent?: string;
|
|
5
|
+
timeoutMs?: number | undefined;
|
|
6
|
+
signal?: AbortSignal | undefined;
|
|
7
|
+
userAgent?: string | undefined;
|
|
8
8
|
queryParams?: Record<string, string>;
|
|
9
|
-
method?: "POST";
|
|
10
|
-
body?: string;
|
|
9
|
+
method?: "POST" | undefined;
|
|
10
|
+
body?: string | undefined;
|
|
11
11
|
}): Promise<Response>;
|
|
12
12
|
export declare function buildUrl(baseUrl: string, endpoint: string, queryParams?: Record<string, string>): string;
|
|
13
|
-
export declare function buildHeaders(userAgent?: string, extra?: Record<string, string>):
|
|
13
|
+
export declare function buildHeaders(userAgent?: string, extra?: Record<string, string>): {
|
|
14
|
+
[x: string]: string;
|
|
15
|
+
};
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
// @ts-ignore - package-info.js is generated
|
|
2
1
|
import { PACKAGE_NAME, PACKAGE_VERSION, } from "./haveibeenpwned/package-info.js";
|
|
3
2
|
export async function baseFetch({ baseUrl, endpoint, headers, timeoutMs, signal, userAgent, queryParams, method, body, }) {
|
|
4
3
|
const requestInit = {
|
|
5
|
-
method,
|
|
6
|
-
body,
|
|
4
|
+
method: method ?? "GET",
|
|
5
|
+
body: body ?? null,
|
|
7
6
|
headers: buildHeaders(userAgent, headers),
|
|
8
7
|
signal: buildSignal(timeoutMs, signal),
|
|
9
8
|
};
|
|
@@ -35,22 +34,17 @@ export function buildHeaders(userAgent, extra) {
|
|
|
35
34
|
}
|
|
36
35
|
function buildSignal(timeoutMs, signal) {
|
|
37
36
|
const signals = [];
|
|
38
|
-
if (timeoutMs)
|
|
37
|
+
if (timeoutMs !== undefined && timeoutMs !== 0 && !Number.isNaN(timeoutMs)) {
|
|
39
38
|
signals.push(AbortSignal.timeout(timeoutMs));
|
|
39
|
+
}
|
|
40
40
|
if (signal)
|
|
41
41
|
signals.push(signal);
|
|
42
42
|
if (signals.length === 0)
|
|
43
|
-
return
|
|
43
|
+
return null;
|
|
44
44
|
if (signals.length === 1)
|
|
45
45
|
return signals[0];
|
|
46
46
|
return AbortSignal.any(signals);
|
|
47
47
|
}
|
|
48
|
-
/**
|
|
49
|
-
* Browser pages have a `document` and browser workers have `importScripts`.
|
|
50
|
-
* Browsers send their own User-Agent, and setting one would force a CORS
|
|
51
|
-
* preflight, which haveibeenpwned.com rejects. Server runtimes have neither
|
|
52
|
-
* global, and some (e.g. Cloudflare Workers) send no User-Agent of their own.
|
|
53
|
-
*/
|
|
54
48
|
function isBrowser() {
|
|
55
49
|
return typeof document !== "undefined" || "importScripts" in globalThis;
|
|
56
50
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-fetch.js","sourceRoot":"","sources":["../../../src/api/base-fetch.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"base-fetch.js","sourceRoot":"","sources":["../../../src/api/base-fetch.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,eAAe,GAChB,MAAM,kCAAkC,CAAC;AAE1C,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,EAC9B,OA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AAE,CAAC;QACd,OAAO,CAAC,YAAY,CAAC,GAAG,SAAS,CAAC;IACpC,CAAC;SAAM,IAAI,CAAC,SAAS,EAAE,EAAE,CAAC;QACxB,OAAO,CAAC,YAAY,CAAC,GAAG,GAAG,YAAY,IAAI,eAAe,EAAE,CAAC;IAC/D,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,SAAS,WAAW,CAClB,SAAkB,EAClB,MAAoB;IAEpB,MAAM,OAAO,GAAkB,EAAE,CAAC;IAElC,IAAI,SAAS,KAAK,SAAS,IAAI,SAAS,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE,CAAC;QAC3E,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC;IAC/C,CAAC;IAED,IAAI,MAAM;QAAE,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAEjC,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IAEtC,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,OAAO,CAAC,CAAC,CAAC,CAAC;IAE5C,OAAO,WAAW,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;AAClC,CAAC;AAED,SAAS,SAAS;IAChB,OAAO,OAAO,QAAQ,KAAK,WAAW,IAAI,eAAe,IAAI,UAAU,CAAC;AAC1E,CAAC"}
|
|
@@ -18,50 +18,42 @@ export class RateLimitError extends Error {
|
|
|
18
18
|
super(message, options);
|
|
19
19
|
this.name = this.constructor.name;
|
|
20
20
|
this.retryAfterSeconds =
|
|
21
|
-
|
|
22
|
-
? Number.parseInt(retryAfter, 10)
|
|
23
|
-
: undefined;
|
|
21
|
+
retryAfter === null ? undefined : Number.parseInt(retryAfter, 10);
|
|
24
22
|
}
|
|
25
23
|
}
|
|
26
24
|
/** @internal */
|
|
25
|
+
export async function readJson(response) {
|
|
26
|
+
// SAFETY: haveibeenpwned.com documents each endpoint's response shape
|
|
27
|
+
return (await response.json());
|
|
28
|
+
}
|
|
29
|
+
/** @internal */
|
|
27
30
|
export function blockedWithRayId(rayId) {
|
|
28
31
|
return `Request blocked, contact haveibeenpwned.com if this continues (Ray ID: ${rayId})`;
|
|
29
32
|
}
|
|
30
|
-
/**
|
|
31
|
-
* Formats the HTTP status of a response, e.g. `429 Too Many Requests`.
|
|
32
|
-
*
|
|
33
|
-
* @internal
|
|
34
|
-
*/
|
|
33
|
+
/** @internal */
|
|
35
34
|
export function statusLine({ status, statusText }) {
|
|
36
35
|
return `${status} ${statusText}`.trim();
|
|
37
36
|
}
|
|
38
|
-
/**
|
|
39
|
-
* Reads the `message` of a JSON error body, or `undefined` if absent or blank.
|
|
40
|
-
*
|
|
41
|
-
* @internal
|
|
42
|
-
*/
|
|
37
|
+
/** @internal */
|
|
43
38
|
export function jsonMessage(text) {
|
|
44
39
|
try {
|
|
45
40
|
const error = JSON.parse(text);
|
|
46
|
-
if (
|
|
47
|
-
error !== null &&
|
|
48
|
-
"message" in error &&
|
|
49
|
-
typeof error.message === "string" &&
|
|
50
|
-
error.message.trim()) {
|
|
41
|
+
if (hasStringMessage(error) && error.message.trim()) {
|
|
51
42
|
return error.message;
|
|
52
43
|
}
|
|
53
44
|
}
|
|
54
45
|
catch {
|
|
55
|
-
|
|
46
|
+
return undefined;
|
|
56
47
|
}
|
|
57
48
|
return undefined;
|
|
58
49
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
50
|
+
function hasStringMessage(value) {
|
|
51
|
+
return (typeof value === "object" &&
|
|
52
|
+
value !== null &&
|
|
53
|
+
"message" in value &&
|
|
54
|
+
typeof value.message === "string");
|
|
55
|
+
}
|
|
56
|
+
/** @internal */
|
|
65
57
|
export function requestApi(endpoint, options = {}, body) {
|
|
66
58
|
const { apiKey, baseUrl = "https://haveibeenpwned.com/api/v3", timeoutMs, signal, userAgent, } = options;
|
|
67
59
|
const headers = {};
|
|
@@ -80,40 +72,12 @@ export function requestApi(endpoint, options = {}, body) {
|
|
|
80
72
|
body: body && JSON.stringify(body),
|
|
81
73
|
});
|
|
82
74
|
}
|
|
83
|
-
/**
|
|
84
|
-
* Fetches data from the supplied API endpoint.
|
|
85
|
-
*
|
|
86
|
-
* HTTP status code 200 returns an Object (data found).
|
|
87
|
-
* HTTP status code 404 returns null (no data found).
|
|
88
|
-
* HTTP status code 400 throws an Error (bad request).
|
|
89
|
-
* HTTP status code 401 throws an Error (unauthorized) with the body's JSON
|
|
90
|
-
* `message`, the body text, or the HTTP status.
|
|
91
|
-
* HTTP status code 403 throws an Error (forbidden).
|
|
92
|
-
* HTTP status code 429 throws a RateLimitError (too many requests) with the
|
|
93
|
-
* body's JSON `message`, or the HTTP status.
|
|
94
|
-
*
|
|
95
|
-
* @internal
|
|
96
|
-
* @private
|
|
97
|
-
* @param {string} endpoint the API endpoint to query
|
|
98
|
-
* @param {object} [options] a configuration object
|
|
99
|
-
* @param {string} [options.apiKey] an API key from
|
|
100
|
-
* https://haveibeenpwned.com/API/Key
|
|
101
|
-
* @param {string} [options.baseUrl] a custom base URL for the
|
|
102
|
-
* haveibeenpwned.com API endpoints (default:
|
|
103
|
-
* `https://haveibeenpwned.com/api/v3`)
|
|
104
|
-
* @param {number} [options.timeoutMs] timeout for the request in milliseconds
|
|
105
|
-
* (default: none)
|
|
106
|
-
* @param {AbortSignal} [options.signal] an AbortSignal to cancel the request (default: none)
|
|
107
|
-
* @param {string} [options.userAgent] a custom string to send as the User-Agent
|
|
108
|
-
* field in the request headers (default: `hibp <version>`)
|
|
109
|
-
* @returns {Promise<ApiData>} a Promise which resolves to the data resulting
|
|
110
|
-
* from the query (or null for 404 Not Found responses), or rejects with an
|
|
111
|
-
* Error
|
|
112
|
-
*/
|
|
75
|
+
/** @internal */
|
|
113
76
|
export async function fetchFromApi(endpoint, options = {}) {
|
|
114
77
|
const response = await requestApi(endpoint, options);
|
|
115
|
-
if (response.ok)
|
|
116
|
-
return response
|
|
78
|
+
if (response.ok) {
|
|
79
|
+
return readJson(response);
|
|
80
|
+
}
|
|
117
81
|
switch (response.status) {
|
|
118
82
|
case BAD_REQUEST.status: {
|
|
119
83
|
throw new Error(BAD_REQUEST.statusText);
|
|
@@ -141,4 +105,11 @@ export async function fetchFromApi(endpoint, options = {}) {
|
|
|
141
105
|
}
|
|
142
106
|
}
|
|
143
107
|
}
|
|
108
|
+
/** @internal */
|
|
109
|
+
export async function fetchRequiredFromApi(endpoint, options = {}) {
|
|
110
|
+
const data = await fetchFromApi(endpoint, options);
|
|
111
|
+
if (data === null)
|
|
112
|
+
throw new Error(NOT_FOUND.statusText);
|
|
113
|
+
return data;
|
|
114
|
+
}
|
|
144
115
|
//# sourceMappingURL=fetch-from-api.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch-from-api.js","sourceRoot":"","sources":["../../../../src/api/haveibeenpwned/fetch-from-api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EACL,WAAW,EACX,YAAY,EACZ,SAAS,EACT,SAAS,EACT,iBAAiB,GAClB,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"fetch-from-api.js","sourceRoot":"","sources":["../../../../src/api/haveibeenpwned/fetch-from-api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EACL,WAAW,EACX,YAAY,EACZ,SAAS,EACT,SAAS,EACT,iBAAiB,GAClB,MAAM,gBAAgB,CAAC;AAExB;;;;;;GAMG;AACH,MAAM,OAAO,cAAe,SAAQ,KAAK;IACvC;;;;OAIG;IACI,iBAAiB,CAAqB;IAE7C,YACE,UAAsC,EACtC,OAA2B,EAC3B,OAAsB;QAEtB,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACxB,IAA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0.
|
|
2
|
+
export declare const PACKAGE_VERSION = "16.0.1";
|
|
@@ -1,14 +1,6 @@
|
|
|
1
1
|
import { blockedWithRayId, jsonMessage, RateLimitError, requestApi, statusLine, } from "./fetch-from-api.js";
|
|
2
2
|
import { FORBIDDEN, TOO_MANY_REQUESTS } from "./responses.js";
|
|
3
|
-
/**
|
|
4
|
-
* Posts a JSON body to the supplied API endpoint.
|
|
5
|
-
*
|
|
6
|
-
* Failures reject with the first available reason: the JSON body's `message`,
|
|
7
|
-
* the Cloudflare Ray ID of a blocked (403) request, a plain-text body, or the
|
|
8
|
-
* HTTP status.
|
|
9
|
-
*
|
|
10
|
-
* @internal
|
|
11
|
-
*/
|
|
3
|
+
/** @internal */
|
|
12
4
|
export async function postToApi(endpoint, body, options) {
|
|
13
5
|
const response = await requestApi(endpoint, options, body);
|
|
14
6
|
if (response.ok)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"post-to-api.js","sourceRoot":"","sources":["../../../../src/api/haveibeenpwned/post-to-api.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,WAAW,EACX,cAAc,EACd,UAAU,EACV,UAAU,GAEX,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAE9D
|
|
1
|
+
{"version":3,"file":"post-to-api.js","sourceRoot":"","sources":["../../../../src/api/haveibeenpwned/post-to-api.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,WAAW,EACX,cAAc,EACd,UAAU,EACV,UAAU,GAEX,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAE9D,gBAAgB;AAChB,MAAM,CAAC,KAAK,UAAU,SAAS,CAC7B,QAAgB,EAChB,IAA4B,EAC5B,OAAoB;IAEpB,MAAM,QAAQ,GAAG,MAAM,UAAU,CAAC,QAAQ,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;IAE3D,IAAI,QAAQ,CAAC,EAAE;QAAE,OAAO,QAAQ,CAAC;IAEjC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,QAAQ,CAAC;IACrC,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;IACnC,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IACpC,MAAM,WAAW,GAAG,iBAAiB,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,IAAI,EAAE,CAAC,CAAC;IAE9E,MAAM,OAAO,GACX,WAAW,CAAC,IAAI,CAAC;QACjB,CAAC,MAAM,KAAK,SAAS,CAAC,MAAM,IAAI,KAAK;YACnC,CAAC,CAAC,gBAAgB,CAAC,KAAK,CAAC;YACzB,CAAC,CAAC,SAAS,CAAC;QACd,CAAC,WAAW,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;QAC/C,UAAU,CAAC,QAAQ,CAAC,CAAC;IAEvB,IAAI,MAAM,KAAK,iBAAiB,CAAC,MAAM,EAAE,CAAC;QACxC,MAAM,IAAI,cAAc,CAAC,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,EAAE,OAAO,CAAC,CAAC;IAChE,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;AAC3B,CAAC"}
|
|
@@ -1,11 +1 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Known potential responses from the remote API.
|
|
3
|
-
*
|
|
4
|
-
* Unfortunately, the API does not send a decent human-readable message back with each response, but
|
|
5
|
-
* they are documented on the website: https://haveibeenpwned.com/api/v3#ResponseCodes
|
|
6
|
-
*
|
|
7
|
-
* These objects simply provide a mapping between the HTTP response status code and the
|
|
8
|
-
* corresponding human-readable message so we can throw a more descriptive error for the consumer.
|
|
9
|
-
* (They are also leveraged in our tests.)
|
|
10
|
-
*/
|
|
11
1
|
export {};
|
|
@@ -1,28 +1,11 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Known potential responses from the remote API.
|
|
3
|
-
*
|
|
4
|
-
* Unfortunately, the API does not send a decent human-readable message back with each response, but
|
|
5
|
-
* they are documented on the website: https://haveibeenpwned.com/api/v3#ResponseCodes
|
|
6
|
-
*
|
|
7
|
-
* These objects simply provide a mapping between the HTTP response status code and the
|
|
8
|
-
* corresponding human-readable message so we can throw a more descriptive error for the consumer.
|
|
9
|
-
* (They are also leveraged in our tests.)
|
|
10
|
-
*/
|
|
11
1
|
/** @internal */
|
|
12
2
|
export const BAD_REQUEST = {
|
|
13
3
|
status: 400,
|
|
14
4
|
statusText: "Bad request — the account does not comply with an acceptable format.",
|
|
15
5
|
};
|
|
16
|
-
/**
|
|
17
|
-
* A plain-text body for this response type. The live API sends a JSON object
|
|
18
|
-
* containing a human-readable message instead. Manually populating the message
|
|
19
|
-
* here purely for use in tests.
|
|
20
|
-
*
|
|
21
|
-
* @internal
|
|
22
|
-
*/
|
|
6
|
+
/** @internal */
|
|
23
7
|
export const UNAUTHORIZED = {
|
|
24
8
|
status: 401,
|
|
25
|
-
body: `Your request to the API couldn't be authorised. Check you have the right value in the "hibp-api-key" header, refer to the documentation for more: https://haveibeenpwned.com/API/v3#Authorisation`,
|
|
26
9
|
};
|
|
27
10
|
/** @internal */
|
|
28
11
|
export const FORBIDDEN = {
|
|
@@ -30,27 +13,12 @@ export const FORBIDDEN = {
|
|
|
30
13
|
statusText: "Forbidden - access denied.",
|
|
31
14
|
};
|
|
32
15
|
/** @internal */
|
|
33
|
-
export const BLOCKED = {
|
|
34
|
-
headers: new Map([["cf-ray", "someRayId"]]),
|
|
35
|
-
status: 403,
|
|
36
|
-
};
|
|
37
|
-
/** @internal */
|
|
38
16
|
export const NOT_FOUND = {
|
|
39
17
|
status: 404,
|
|
18
|
+
statusText: "Not found.",
|
|
40
19
|
};
|
|
41
|
-
/**
|
|
42
|
-
* The API includes a JSON object containing a human-readable message in the
|
|
43
|
-
* body of this response type. Manually populating the message here purely for
|
|
44
|
-
* use in tests.
|
|
45
|
-
*
|
|
46
|
-
* @internal
|
|
47
|
-
*/
|
|
20
|
+
/** @internal */
|
|
48
21
|
export const TOO_MANY_REQUESTS = {
|
|
49
|
-
headers: new Map([["retry-after", "2"]]),
|
|
50
22
|
status: 429,
|
|
51
|
-
body: {
|
|
52
|
-
statusCode: 429,
|
|
53
|
-
message: "Rate limit is exceeded. Try again in 2 seconds.",
|
|
54
|
-
},
|
|
55
23
|
};
|
|
56
24
|
//# sourceMappingURL=responses.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"responses.js","sourceRoot":"","sources":["../../../../src/api/haveibeenpwned/responses.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"responses.js","sourceRoot":"","sources":["../../../../src/api/haveibeenpwned/responses.ts"],"names":[],"mappings":"AAAA,gBAAgB;AAChB,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,MAAM,EAAE,GAAY;IACpB,UAAU,EACR,sEAAsE;CACzE,CAAC;AAEF,gBAAgB;AAChB,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,MAAM,EAAE,GAAY;CACrB,CAAC;AAEF,gBAAgB;AAChB,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,MAAM,EAAE,GAAY;IACpB,UAAU,EAAE,4BAA4B;CACzC,CAAC;AAEF,gBAAgB;AAChB,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,MAAM,EAAE,GAAY;IACpB,UAAU,EAAE,YAAY;CACzB,CAAC;AAEF,gBAAgB;AAChB,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,MAAM,EAAE,GAAY;CACrB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/api/haveibeenpwned/types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/api/haveibeenpwned/types.ts"],"names":[],"mappings":""}
|
|
@@ -1,29 +1,6 @@
|
|
|
1
1
|
import { baseFetch } from "../base-fetch.js";
|
|
2
2
|
import { BAD_REQUEST } from "./responses.js";
|
|
3
|
-
/**
|
|
4
|
-
* Fetches data from the supplied API endpoint.
|
|
5
|
-
*
|
|
6
|
-
* HTTP status code 200 returns plain text (data found).
|
|
7
|
-
* HTTP status code 400 throws an Error (bad request).
|
|
8
|
-
*
|
|
9
|
-
* @internal
|
|
10
|
-
* @private
|
|
11
|
-
* @param {string} endpoint the API endpoint to query
|
|
12
|
-
* @param {object} [options] a configuration object
|
|
13
|
-
* @param {string} [options.baseUrl] a custom base URL for the
|
|
14
|
-
* pwnedpasswords.com API endpoints (default: `https://api.pwnedpasswords.com`)
|
|
15
|
-
* @param {number} [options.timeoutMs] timeout for the request in milliseconds
|
|
16
|
-
* (default: none)
|
|
17
|
-
* @param {AbortSignal} [options.signal] an AbortSignal to cancel the request (default: none)
|
|
18
|
-
* @param {string} [options.userAgent] a custom string to send as the User-Agent
|
|
19
|
-
* field in the request headers (default: `hibp <version>`)
|
|
20
|
-
* @param {boolean} [options.addPadding] ask the remote API to add padding to
|
|
21
|
-
* the response to obscure the password prefix (default: `false`)
|
|
22
|
-
* @param {'sha1' | 'ntlm'} [options.mode] return SHA-1 or NTLM hashes
|
|
23
|
-
* (default: `sha1`)
|
|
24
|
-
* @returns {Promise<string>} a Promise which resolves to the data resulting
|
|
25
|
-
* from the query, or rejects with an Error
|
|
26
|
-
*/
|
|
3
|
+
/** @internal */
|
|
27
4
|
export async function fetchFromApi(endpoint, options = {}) {
|
|
28
5
|
const { baseUrl = "https://api.pwnedpasswords.com", timeoutMs, signal, userAgent, addPadding = false, mode = "sha1", } = options;
|
|
29
6
|
const headers = {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch-from-api.js","sourceRoot":"","sources":["../../../../src/api/pwnedpasswords/fetch-from-api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C
|
|
1
|
+
{"version":3,"file":"fetch-from-api.js","sourceRoot":"","sources":["../../../../src/api/pwnedpasswords/fetch-from-api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,gBAAgB;AAChB,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,QAAgB,EAChB,OAAO,GAOH,EAAE;IAEN,MAAM,EACJ,OAAO,GAAG,gCAAgC,EAC1C,SAAS,EACT,MAAM,EACN,SAAS,EACT,UAAU,GAAG,KAAK,EAClB,IAAI,GAAG,MAAM,GACd,GAAG,OAAO,CAAC;IAEZ,MAAM,OAAO,GAA2B,EAAE,CAAC;IAE3C,IAAI,UAAU;QAAE,OAAO,CAAC,aAAa,CAAC,GAAG,MAAM,CAAC;IAEhD,MAAM,QAAQ,GAAG,MAAM,SAAS,CAAC;QAC/B,OAAO;QACP,QAAQ;QACR,OAAO;QACP,SAAS;QACT,MAAM;QACN,SAAS;QACT,WAAW,EAAE,EAAE,IAAI,EAAE;KACtB,CAAC,CAAC;IAEH,IAAI,QAAQ,CAAC,EAAE;QAAE,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAC;IAExC,IAAI,QAAQ,CAAC,MAAM,KAAK,WAAW,CAAC,MAAM,EAAE,CAAC;QAC3C,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;QACnC,MAAM,IAAI,KAAK,CAAC,IAAI,CAAC,CAAC;IACxB,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;AACvC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"responses.js","sourceRoot":"","sources":["../../../../src/api/pwnedpasswords/responses.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"responses.js","sourceRoot":"","sources":["../../../../src/api/pwnedpasswords/responses.ts"],"names":[],"mappings":"AAAA,gBAAgB;AAChB,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,MAAM,EAAE,GAAY;IACpB,IAAI,EAAE,2CAA2C;CAClD,CAAC"}
|
package/dist/esm/breach.d.ts
CHANGED
|
@@ -61,18 +61,18 @@ export declare function breach(breachName: string, options?: {
|
|
|
61
61
|
* a custom base URL for the haveibeenpwned.com API endpoints (default:
|
|
62
62
|
* `https://haveibeenpwned.com/api/v3`)
|
|
63
63
|
*/
|
|
64
|
-
baseUrl?: string;
|
|
64
|
+
baseUrl?: string | undefined;
|
|
65
65
|
/**
|
|
66
66
|
* timeout for the request in milliseconds (default: none)
|
|
67
67
|
*/
|
|
68
|
-
timeoutMs?: number;
|
|
68
|
+
timeoutMs?: number | undefined;
|
|
69
69
|
/**
|
|
70
70
|
* an AbortSignal to cancel the request (default: none)
|
|
71
71
|
*/
|
|
72
|
-
signal?: AbortSignal;
|
|
72
|
+
signal?: AbortSignal | undefined;
|
|
73
73
|
/**
|
|
74
74
|
* a custom string to send as the User-Agent field in the request headers
|
|
75
75
|
* (default: `hibp <version>`)
|
|
76
76
|
*/
|
|
77
|
-
userAgent?: string;
|
|
77
|
+
userAgent?: string | undefined;
|
|
78
78
|
}): Promise<Breach | null>;
|
package/dist/esm/breach.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"breach.js","sourceRoot":"","sources":["../../src/breach.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,wCAAwC,CAAC;AAEtE;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,UAAU,MAAM,CACpB,UAAkB,EAClB,OAAO,GAmBH,EAAE;IAEN,OAAO,YAAY,CACjB,WAAW,kBAAkB,CAAC,UAAU,CAAC,EAAE,EAC3C,OAAO,
|
|
1
|
+
{"version":3,"file":"breach.js","sourceRoot":"","sources":["../../src/breach.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,wCAAwC,CAAC;AAEtE;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,UAAU,MAAM,CACpB,UAAkB,EAClB,OAAO,GAmBH,EAAE;IAEN,OAAO,YAAY,CACjB,WAAW,kBAAkB,CAAC,UAAU,CAAC,EAAE,EAC3C,OAAO,CACR,CAAC;AACJ,CAAC"}
|
|
@@ -51,23 +51,23 @@ export declare function breachedAccountRange(prefix: string, options?: {
|
|
|
51
51
|
/**
|
|
52
52
|
* an API key from https://haveibeenpwned.com/API/Key (default: undefined)
|
|
53
53
|
*/
|
|
54
|
-
apiKey?: string;
|
|
54
|
+
apiKey?: string | undefined;
|
|
55
55
|
/**
|
|
56
56
|
* a custom base URL for the haveibeenpwned.com API endpoints (default:
|
|
57
57
|
* `https://haveibeenpwned.com/api/v3`)
|
|
58
58
|
*/
|
|
59
|
-
baseUrl?: string;
|
|
59
|
+
baseUrl?: string | undefined;
|
|
60
60
|
/**
|
|
61
61
|
* timeout for the request in milliseconds (default: none)
|
|
62
62
|
*/
|
|
63
|
-
timeoutMs?: number;
|
|
63
|
+
timeoutMs?: number | undefined;
|
|
64
64
|
/**
|
|
65
65
|
* an AbortSignal to cancel the request (default: none)
|
|
66
66
|
*/
|
|
67
|
-
signal?: AbortSignal;
|
|
67
|
+
signal?: AbortSignal | undefined;
|
|
68
68
|
/**
|
|
69
69
|
* a custom string to send as the User-Agent field in the request headers
|
|
70
70
|
* (default: `hibp <version>`)
|
|
71
71
|
*/
|
|
72
|
-
userAgent?: string;
|
|
72
|
+
userAgent?: string | undefined;
|
|
73
73
|
}): Promise<BreachedAccountRangeResult[] | null>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"breached-account-range.js","sourceRoot":"","sources":["../../src/breached-account-range.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,wCAAwC,CAAC;AAEtE;;;;;;GAMG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,MAAM,UAAU,oBAAoB,CAClC,MAAc,EACd,OAAO,GAuBH,EAAE;IAEN,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"breached-account-range.js","sourceRoot":"","sources":["../../src/breached-account-range.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,wCAAwC,CAAC;AAEtE;;;;;;GAMG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,MAAM,UAAU,oBAAoB,CAClC,MAAc,EACd,OAAO,GAuBH,EAAE;IAEN,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC;IAElE,OAAO,YAAY,CACjB,0BAA0B,kBAAkB,CAAC,MAAM,CAAC,EAAE,EACtD;QACE,MAAM;QACN,OAAO;QACP,SAAS;QACT,MAAM;QACN,SAAS;KACV,CACF,CAAC;AACJ,CAAC"}
|
|
@@ -3,38 +3,38 @@ interface BreachedAccountOptions {
|
|
|
3
3
|
/**
|
|
4
4
|
* an API key from https://haveibeenpwned.com/API/Key (default: undefined)
|
|
5
5
|
*/
|
|
6
|
-
apiKey?: string;
|
|
6
|
+
apiKey?: string | undefined;
|
|
7
7
|
/**
|
|
8
8
|
* a domain by which to filter the results (default: all domains)
|
|
9
9
|
*/
|
|
10
|
-
domain?: string;
|
|
10
|
+
domain?: string | undefined;
|
|
11
11
|
/**
|
|
12
12
|
* include "unverified" breaches in the results (default: true)
|
|
13
13
|
*/
|
|
14
|
-
includeUnverified?: boolean;
|
|
14
|
+
includeUnverified?: boolean | undefined;
|
|
15
15
|
/**
|
|
16
16
|
* timeout for the request in milliseconds (default: none)
|
|
17
17
|
*/
|
|
18
|
-
timeoutMs?: number;
|
|
18
|
+
timeoutMs?: number | undefined;
|
|
19
19
|
/**
|
|
20
20
|
* an AbortSignal to cancel the request (default: none)
|
|
21
21
|
*/
|
|
22
|
-
signal?: AbortSignal;
|
|
22
|
+
signal?: AbortSignal | undefined;
|
|
23
23
|
/**
|
|
24
24
|
* truncate the results to only include the name of each breach (default:
|
|
25
25
|
* true)
|
|
26
26
|
*/
|
|
27
|
-
truncate?: boolean;
|
|
27
|
+
truncate?: boolean | undefined;
|
|
28
28
|
/**
|
|
29
29
|
* a custom base URL for the haveibeenpwned.com API endpoints (default:
|
|
30
30
|
* `https://haveibeenpwned.com/api/v3`)
|
|
31
31
|
*/
|
|
32
|
-
baseUrl?: string;
|
|
32
|
+
baseUrl?: string | undefined;
|
|
33
33
|
/**
|
|
34
34
|
* a custom string to send as the User-Agent field in the request headers
|
|
35
35
|
* (default: `hibp <version>`)
|
|
36
36
|
*/
|
|
37
|
-
userAgent?: string;
|
|
37
|
+
userAgent?: string | undefined;
|
|
38
38
|
}
|
|
39
39
|
/**
|
|
40
40
|
* Fetches breach data for a specific account.
|
|
@@ -112,7 +112,7 @@ interface BreachedAccountOptions {
|
|
|
112
112
|
* }
|
|
113
113
|
*/
|
|
114
114
|
export declare function breachedAccount(account: string, options?: BreachedAccountOptions & {
|
|
115
|
-
truncate?: true;
|
|
115
|
+
truncate?: true | undefined;
|
|
116
116
|
}): Promise<Pick<Breach, "Name">[] | null>;
|
|
117
117
|
export declare function breachedAccount(account: string, options: BreachedAccountOptions & {
|
|
118
118
|
truncate: false;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"breached-account.js","sourceRoot":"","sources":["../../src/breached-account.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,wCAAwC,CAAC;AA+HtE,MAAM,UAAU,eAAe,CAC7B,OAAe,EACf,OAAO,GAA2B,EAAE;IAEpC,MAAM,EACJ,MAAM,EACN,MAAM,EACN,iBAAiB,GAAG,IAAI,EACxB,SAAS,EACT,MAAM,EACN,QAAQ,GAAG,IAAI,EACf,OAAO,EACP,SAAS,GACV,GAAG,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"breached-account.js","sourceRoot":"","sources":["../../src/breached-account.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,wCAAwC,CAAC;AA+HtE,MAAM,UAAU,eAAe,CAC7B,OAAe,EACf,OAAO,GAA2B,EAAE;IAEpC,MAAM,EACJ,MAAM,EACN,MAAM,EACN,iBAAiB,GAAG,IAAI,EACxB,SAAS,EACT,MAAM,EACN,QAAQ,GAAG,IAAI,EACf,OAAO,EACP,SAAS,GACV,GAAG,OAAO,CAAC;IAEZ,MAAM,QAAQ,GAAG,oBAAoB,kBAAkB,CAAC,OAAO,CAAC,GAAG,CAAC;IACpE,MAAM,MAAM,GAAa,EAAE,CAAC;IAE5B,IAAI,MAAM,EAAE,CAAC;QACX,MAAM,CAAC,IAAI,CAAC,UAAU,kBAAkB,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IACtD,CAAC;IAED,IAAI,CAAC,iBAAiB,EAAE,CAAC;QACvB,MAAM,CAAC,IAAI,CAAC,yBAAyB,CAAC,CAAC;IACzC,CAAC;IAED,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,MAAM,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAC;IACxC,CAAC;IAED,OAAO,YAAY,CACjB,GAAG,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,EAChC;QACE,MAAM;QACN,OAAO;QACP,SAAS;QACT,MAAM;QACN,SAAS;KACV,CACF,CAAC;AACJ,CAAC"}
|