hibp 0.0.0-dev.9896b89a
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/API.md +508 -0
- package/CHANGELOG.md +7 -0
- package/LICENSE.txt +22 -0
- package/MIGRATION.md +227 -0
- package/README.md +255 -0
- package/dist/browser/hibp.module.js +2 -0
- package/dist/browser/hibp.module.js.map +1 -0
- package/dist/browser/hibp.umd.js +2 -0
- package/dist/browser/hibp.umd.js.map +1 -0
- package/dist/cjs/api/haveibeenpwned/fetchFromApi.js +107 -0
- package/dist/cjs/api/haveibeenpwned/fetchFromApi.js.map +1 -0
- package/dist/cjs/api/haveibeenpwned/index.js +6 -0
- package/dist/cjs/api/haveibeenpwned/index.js.map +1 -0
- package/dist/cjs/api/haveibeenpwned/responses.js +79 -0
- package/dist/cjs/api/haveibeenpwned/responses.js.map +1 -0
- package/dist/cjs/api/pwnedpasswords/fetchFromApi.js +44 -0
- package/dist/cjs/api/pwnedpasswords/fetchFromApi.js.map +1 -0
- package/dist/cjs/api/pwnedpasswords/index.js +5 -0
- package/dist/cjs/api/pwnedpasswords/index.js.map +1 -0
- package/dist/cjs/api/pwnedpasswords/responses.js +20 -0
- package/dist/cjs/api/pwnedpasswords/responses.js.map +1 -0
- package/dist/cjs/breach.js +55 -0
- package/dist/cjs/breach.js.map +1 -0
- package/dist/cjs/breachedAccount.js +101 -0
- package/dist/cjs/breachedAccount.js.map +1 -0
- package/dist/cjs/breaches.js +55 -0
- package/dist/cjs/breaches.js.map +1 -0
- package/dist/cjs/dataClasses.js +34 -0
- package/dist/cjs/dataClasses.js.map +1 -0
- package/dist/cjs/hibp.js +21 -0
- package/dist/cjs/hibp.js.map +1 -0
- package/dist/cjs/package.json.js +7 -0
- package/dist/cjs/package.json.js.map +1 -0
- package/dist/cjs/pasteAccount.js +59 -0
- package/dist/cjs/pasteAccount.js.map +1 -0
- package/dist/cjs/pwnedPassword.js +45 -0
- package/dist/cjs/pwnedPassword.js.map +1 -0
- package/dist/cjs/pwnedPasswordRange.js +63 -0
- package/dist/cjs/pwnedPasswordRange.js.map +1 -0
- package/dist/cjs/search.js +97 -0
- package/dist/cjs/search.js.map +1 -0
- package/dist/esm/api/haveibeenpwned/fetchFromApi.mjs +104 -0
- package/dist/esm/api/haveibeenpwned/fetchFromApi.mjs.map +1 -0
- package/dist/esm/api/haveibeenpwned/index.mjs +2 -0
- package/dist/esm/api/haveibeenpwned/index.mjs.map +1 -0
- package/dist/esm/api/haveibeenpwned/responses.mjs +71 -0
- package/dist/esm/api/haveibeenpwned/responses.mjs.map +1 -0
- package/dist/esm/api/pwnedpasswords/fetchFromApi.mjs +42 -0
- package/dist/esm/api/pwnedpasswords/fetchFromApi.mjs.map +1 -0
- package/dist/esm/api/pwnedpasswords/index.mjs +2 -0
- package/dist/esm/api/pwnedpasswords/index.mjs.map +1 -0
- package/dist/esm/api/pwnedpasswords/responses.mjs +17 -0
- package/dist/esm/api/pwnedpasswords/responses.mjs.map +1 -0
- package/dist/esm/breach.mjs +53 -0
- package/dist/esm/breach.mjs.map +1 -0
- package/dist/esm/breachedAccount.mjs +99 -0
- package/dist/esm/breachedAccount.mjs.map +1 -0
- package/dist/esm/breaches.mjs +53 -0
- package/dist/esm/breaches.mjs.map +1 -0
- package/dist/esm/dataClasses.mjs +32 -0
- package/dist/esm/dataClasses.mjs.map +1 -0
- package/dist/esm/hibp.mjs +10 -0
- package/dist/esm/hibp.mjs.map +1 -0
- package/dist/esm/package.json.mjs +4 -0
- package/dist/esm/package.json.mjs.map +1 -0
- package/dist/esm/pasteAccount.mjs +57 -0
- package/dist/esm/pasteAccount.mjs.map +1 -0
- package/dist/esm/pwnedPassword.mjs +43 -0
- package/dist/esm/pwnedPassword.mjs.map +1 -0
- package/dist/esm/pwnedPasswordRange.mjs +61 -0
- package/dist/esm/pwnedPasswordRange.mjs.map +1 -0
- package/dist/esm/search.mjs +95 -0
- package/dist/esm/search.mjs.map +1 -0
- package/dist/hibp.d.ts +502 -0
- package/example/runkit.js +16 -0
- package/package.json +139 -0
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var fetchFromApi = /*#__PURE__*/require('./api/haveibeenpwned/fetchFromApi.js');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Fetches breach data for a specific account.
|
|
7
|
+
*
|
|
8
|
+
* ***Warning (July 18, 2019):***
|
|
9
|
+
*
|
|
10
|
+
* `haveibeenpwned.com` now requires an API key from
|
|
11
|
+
* https://haveibeenpwned.com/API/Key for the `breachedaccount` endpoint. The
|
|
12
|
+
* `apiKey` option here is not explicitly required, but direct requests made
|
|
13
|
+
* without it (that is, without specifying a `baseUrl` to a proxy that inserts a
|
|
14
|
+
* valid API key on your behalf) will fail.
|
|
15
|
+
*
|
|
16
|
+
* @param {string} account a username or email address
|
|
17
|
+
* @param {object} [options] a configuration object
|
|
18
|
+
* @param {string} [options.apiKey] an API key from
|
|
19
|
+
* https://haveibeenpwned.com/API/Key (default: undefined)
|
|
20
|
+
* @param {string} [options.domain] a domain by which to filter the results
|
|
21
|
+
* (default: all domains)
|
|
22
|
+
* @param {boolean} [options.includeUnverified] include "unverified" breaches in
|
|
23
|
+
* the results (default: true)
|
|
24
|
+
* @param {boolean} [options.truncate] truncate the results to only include
|
|
25
|
+
* the name of each breach (default: true)
|
|
26
|
+
* @param {string} [options.baseUrl] a custom base URL for the
|
|
27
|
+
* haveibeenpwned.com API endpoints (default:
|
|
28
|
+
* `https://haveibeenpwned.com/api/v3`)
|
|
29
|
+
* @param {string} [options.userAgent] a custom string to send as the User-Agent
|
|
30
|
+
* field in the request headers (default: `hibp <version>`)
|
|
31
|
+
* @returns {(Promise<Breach[]> | Promise<null>)} a Promise which resolves to an
|
|
32
|
+
* array of breach objects (or null if no breaches were found), or rejects with
|
|
33
|
+
* an Error
|
|
34
|
+
* @example
|
|
35
|
+
* breachedAccount('foo', { apiKey: 'my-api-key' })
|
|
36
|
+
* .then(data => {
|
|
37
|
+
* if (data) {
|
|
38
|
+
* // ...
|
|
39
|
+
* } else {
|
|
40
|
+
* // ...
|
|
41
|
+
* }
|
|
42
|
+
* })
|
|
43
|
+
* .catch(err => {
|
|
44
|
+
* // ...
|
|
45
|
+
* });
|
|
46
|
+
* @example
|
|
47
|
+
* breachedAccount('bar', {
|
|
48
|
+
* includeUnverified: false,
|
|
49
|
+
* baseUrl: 'https://my-hibp-proxy:8080',
|
|
50
|
+
* })
|
|
51
|
+
* .then(data => {
|
|
52
|
+
* if (data) {
|
|
53
|
+
* // ...
|
|
54
|
+
* } else {
|
|
55
|
+
* // ...
|
|
56
|
+
* }
|
|
57
|
+
* })
|
|
58
|
+
* .catch(err => {
|
|
59
|
+
* // ...
|
|
60
|
+
* });
|
|
61
|
+
* @example
|
|
62
|
+
* breachedAccount('baz', {
|
|
63
|
+
* apiKey: 'my-api-key',
|
|
64
|
+
* domain: 'adobe.com',
|
|
65
|
+
* truncate: false,
|
|
66
|
+
* userAgent: 'my-app 1.0'
|
|
67
|
+
* })
|
|
68
|
+
* .then(data => {
|
|
69
|
+
* if (data) {
|
|
70
|
+
* // ...
|
|
71
|
+
* } else {
|
|
72
|
+
* // ...
|
|
73
|
+
* }
|
|
74
|
+
* })
|
|
75
|
+
* .catch(err => {
|
|
76
|
+
* // ...
|
|
77
|
+
* });
|
|
78
|
+
*/
|
|
79
|
+
function breachedAccount(account, options = {
|
|
80
|
+
includeUnverified: true,
|
|
81
|
+
truncate: true
|
|
82
|
+
}) {
|
|
83
|
+
const endpoint = `/breachedaccount/${encodeURIComponent(account)}?`;
|
|
84
|
+
const params = [];
|
|
85
|
+
if (options.domain) {
|
|
86
|
+
params.push(`domain=${encodeURIComponent(options.domain)}`);
|
|
87
|
+
}
|
|
88
|
+
if (options.includeUnverified === false) {
|
|
89
|
+
params.push('includeUnverified=false');
|
|
90
|
+
}
|
|
91
|
+
if (options.truncate === false) {
|
|
92
|
+
params.push('truncateResponse=false');
|
|
93
|
+
}
|
|
94
|
+
return fetchFromApi.fetchFromApi(`${endpoint}${params.join('&')}`, {
|
|
95
|
+
apiKey: options.apiKey,
|
|
96
|
+
baseUrl: options.baseUrl,
|
|
97
|
+
userAgent: options.userAgent
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
exports.breachedAccount = breachedAccount;
|
|
101
|
+
//# sourceMappingURL=breachedAccount.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"breachedAccount.js","sources":["../../src/breachedAccount.ts"],"sourcesContent":["import type { Breach } from './api/haveibeenpwned/types';\nimport { fetchFromApi } from './api/haveibeenpwned';\n\n/**\n * Fetches breach data for a specific account.\n *\n * ***Warning (July 18, 2019):***\n *\n * `haveibeenpwned.com` now requires an API key from\n * https://haveibeenpwned.com/API/Key for the `breachedaccount` endpoint. The\n * `apiKey` option here is not explicitly required, but direct requests made\n * without it (that is, without specifying a `baseUrl` to a proxy that inserts a\n * valid API key on your behalf) will fail.\n *\n * @param {string} account a username or email address\n * @param {object} [options] a configuration object\n * @param {string} [options.apiKey] an API key from\n * https://haveibeenpwned.com/API/Key (default: undefined)\n * @param {string} [options.domain] a domain by which to filter the results\n * (default: all domains)\n * @param {boolean} [options.includeUnverified] include \"unverified\" breaches in\n * the results (default: true)\n * @param {boolean} [options.truncate] truncate the results to only include\n * the name of each breach (default: true)\n * @param {string} [options.baseUrl] a custom base URL for the\n * haveibeenpwned.com API endpoints (default:\n * `https://haveibeenpwned.com/api/v3`)\n * @param {string} [options.userAgent] a custom string to send as the User-Agent\n * field in the request headers (default: `hibp <version>`)\n * @returns {(Promise<Breach[]> | Promise<null>)} a Promise which resolves to an\n * array of breach objects (or null if no breaches were found), or rejects with\n * an Error\n * @example\n * breachedAccount('foo', { apiKey: 'my-api-key' })\n * .then(data => {\n * if (data) {\n * // ...\n * } else {\n * // ...\n * }\n * })\n * .catch(err => {\n * // ...\n * });\n * @example\n * breachedAccount('bar', {\n * includeUnverified: false,\n * baseUrl: 'https://my-hibp-proxy:8080',\n * })\n * .then(data => {\n * if (data) {\n * // ...\n * } else {\n * // ...\n * }\n * })\n * .catch(err => {\n * // ...\n * });\n * @example\n * breachedAccount('baz', {\n * apiKey: 'my-api-key',\n * domain: 'adobe.com',\n * truncate: false,\n * userAgent: 'my-app 1.0'\n * })\n * .then(data => {\n * if (data) {\n * // ...\n * } else {\n * // ...\n * }\n * })\n * .catch(err => {\n * // ...\n * });\n */\nexport function breachedAccount(\n account: string,\n options: {\n apiKey?: string;\n domain?: string;\n includeUnverified?: boolean;\n truncate?: boolean;\n baseUrl?: string;\n userAgent?: string;\n } = {\n includeUnverified: true,\n truncate: true,\n },\n): Promise<Breach[] | null> {\n const endpoint = `/breachedaccount/${encodeURIComponent(account)}?`;\n const params: Array<string> = [];\n if (options.domain) {\n params.push(`domain=${encodeURIComponent(options.domain)}`);\n }\n if (options.includeUnverified === false) {\n params.push('includeUnverified=false');\n }\n if (options.truncate === false) {\n params.push('truncateResponse=false');\n }\n return fetchFromApi(`${endpoint}${params.join('&')}`, {\n apiKey: options.apiKey,\n baseUrl: options.baseUrl,\n userAgent: options.userAgent,\n }) as Promise<Breach[] | null>;\n}\n"],"names":["breachedAccount","account","options","includeUnverified","truncate","endpoint","encodeURIComponent","params","domain","push","fetchFromApi","join","apiKey","baseUrl","userAgent"],"mappings":";;;;AAGA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyEG;AACa,SAAAA,eAAe,CAC7BC,OAAe,EACfC,OAOI,GAAA;EACFC,iBAAiB,EAAE,IAAI;EACvBC,QAAQ,EAAE;AACX,CAAA,EAAA;EAED,MAAMC,QAAQ,GAAuB,oBAAAC,kBAAkB,CAACL,OAAO,IAAI;EACnE,MAAMM,MAAM,GAAkB,EAAE;EAChC,IAAIL,OAAO,CAACM,MAAM,EAAE;IAClBD,MAAM,CAACE,IAAI,CAAC,UAAUH,kBAAkB,CAACJ,OAAO,CAACM,MAAM,CAAG,EAAA,CAAC;EAC5D;EACD,IAAIN,OAAO,CAACC,iBAAiB,KAAK,KAAK,EAAE;IACvCI,MAAM,CAACE,IAAI,CAAC,yBAAyB,CAAC;EACvC;EACD,IAAIP,OAAO,CAACE,QAAQ,KAAK,KAAK,EAAE;IAC9BG,MAAM,CAACE,IAAI,CAAC,wBAAwB,CAAC;EACtC;EACD,OAAOC,YAAY,CAAAA,YAAA,CAAI,GAAAL,QAAW,GAAAE,MAAM,CAACI,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE;IACpDC,MAAM,EAAEV,OAAO,CAACU,MAAM;IACtBC,OAAO,EAAEX,OAAO,CAACW,OAAO;IACxBC,SAAS,EAAEZ,OAAO,CAACY;EACpB,CAAA,CAA6B;AAChC;"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var fetchFromApi = /*#__PURE__*/require('./api/haveibeenpwned/fetchFromApi.js');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Fetches all breach events in the system.
|
|
7
|
+
*
|
|
8
|
+
* @param {object} [options] a configuration object
|
|
9
|
+
* @param {string} [options.domain] a domain by which to filter the results
|
|
10
|
+
* (default: all domains)
|
|
11
|
+
* @param {string} [options.baseUrl] a custom base URL for the
|
|
12
|
+
* haveibeenpwned.com API endpoints (default:
|
|
13
|
+
* `https://haveibeenpwned.com/api/v3`)
|
|
14
|
+
* @param {string} [options.userAgent] a custom string to send as the User-Agent
|
|
15
|
+
* field in the request headers (default: `hibp <version>`)
|
|
16
|
+
* @returns {Promise<Breach[]>} a Promise which resolves to an array of breach
|
|
17
|
+
* objects (an empty array if no breaches were found), or rejects with an Error
|
|
18
|
+
* @example
|
|
19
|
+
* breaches()
|
|
20
|
+
* .then(data => {
|
|
21
|
+
* if (data) {
|
|
22
|
+
* // ...
|
|
23
|
+
* } else {
|
|
24
|
+
* // ...
|
|
25
|
+
* }
|
|
26
|
+
* })
|
|
27
|
+
* .catch(err => {
|
|
28
|
+
* // ...
|
|
29
|
+
* });
|
|
30
|
+
* @example
|
|
31
|
+
* breaches({ domain: 'adobe.com' })
|
|
32
|
+
* .then(data => {
|
|
33
|
+
* if (data) {
|
|
34
|
+
* // ...
|
|
35
|
+
* } else {
|
|
36
|
+
* // ...
|
|
37
|
+
* }
|
|
38
|
+
* })
|
|
39
|
+
* .catch(err => {
|
|
40
|
+
* // ...
|
|
41
|
+
* });
|
|
42
|
+
*/
|
|
43
|
+
function breaches(options = {}) {
|
|
44
|
+
const endpoint = '/breaches?';
|
|
45
|
+
const params = [];
|
|
46
|
+
if (options.domain) {
|
|
47
|
+
params.push(`domain=${encodeURIComponent(options.domain)}`);
|
|
48
|
+
}
|
|
49
|
+
return fetchFromApi.fetchFromApi(`${endpoint}${params.join('&')}`, {
|
|
50
|
+
baseUrl: options.baseUrl,
|
|
51
|
+
userAgent: options.userAgent
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
exports.breaches = breaches;
|
|
55
|
+
//# sourceMappingURL=breaches.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"breaches.js","sources":["../../src/breaches.ts"],"sourcesContent":["import type { Breach } from './api/haveibeenpwned/types';\nimport { fetchFromApi } from './api/haveibeenpwned';\n\n/**\n * Fetches all breach events in the system.\n *\n * @param {object} [options] a configuration object\n * @param {string} [options.domain] a domain by which to filter the results\n * (default: all domains)\n * @param {string} [options.baseUrl] a custom base URL for the\n * haveibeenpwned.com API endpoints (default:\n * `https://haveibeenpwned.com/api/v3`)\n * @param {string} [options.userAgent] a custom string to send as the User-Agent\n * field in the request headers (default: `hibp <version>`)\n * @returns {Promise<Breach[]>} a Promise which resolves to an array of breach\n * objects (an empty array if no breaches were found), or rejects with an Error\n * @example\n * breaches()\n * .then(data => {\n * if (data) {\n * // ...\n * } else {\n * // ...\n * }\n * })\n * .catch(err => {\n * // ...\n * });\n * @example\n * breaches({ domain: 'adobe.com' })\n * .then(data => {\n * if (data) {\n * // ...\n * } else {\n * // ...\n * }\n * })\n * .catch(err => {\n * // ...\n * });\n */\nexport function breaches(\n options: {\n domain?: string;\n baseUrl?: string;\n userAgent?: string;\n } = {},\n): Promise<Breach[]> {\n const endpoint = '/breaches?';\n const params: Array<string> = [];\n if (options.domain) {\n params.push(`domain=${encodeURIComponent(options.domain)}`);\n }\n return fetchFromApi(`${endpoint}${params.join('&')}`, {\n baseUrl: options.baseUrl,\n userAgent: options.userAgent,\n }) as Promise<Breach[]>;\n}\n"],"names":["breaches","options","endpoint","params","domain","push","encodeURIComponent","fetchFromApi","join","baseUrl","userAgent"],"mappings":";;;;AAGA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCG;AACa,SAAAA,QAAQ,CACtBC,OAAA,GAII,EAAE,EAAA;EAEN,MAAMC,QAAQ,GAAG,YAAY;EAC7B,MAAMC,MAAM,GAAkB,EAAE;EAChC,IAAIF,OAAO,CAACG,MAAM,EAAE;IAClBD,MAAM,CAACE,IAAI,CAAC,UAAUC,kBAAkB,CAACL,OAAO,CAACG,MAAM,CAAG,EAAA,CAAC;EAC5D;EACD,OAAOG,YAAY,CAAAA,YAAA,CAAI,GAAAL,QAAW,GAAAC,MAAM,CAACK,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE;IACpDC,OAAO,EAAER,OAAO,CAACQ,OAAO;IACxBC,SAAS,EAAET,OAAO,CAACS;EACpB,CAAA,CAAsB;AACzB;"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var fetchFromApi = /*#__PURE__*/require('./api/haveibeenpwned/fetchFromApi.js');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Fetches all data classes in the system.
|
|
7
|
+
*
|
|
8
|
+
* @param {object} [options] a configuration object
|
|
9
|
+
* @param {string} [options.baseUrl] a custom base URL for the
|
|
10
|
+
* haveibeenpwned.com API endpoints (default:
|
|
11
|
+
* `https://haveibeenpwned.com/api/v3`)
|
|
12
|
+
* @param {string} [options.userAgent] a custom string to send as the User-Agent
|
|
13
|
+
* field in the request headers (default: `hibp <version>`)
|
|
14
|
+
* @returns {(Promise<string[]> | Promise<null>)} a Promise which resolves to an
|
|
15
|
+
* array of strings (or null if no data classes were found), or rejects with an
|
|
16
|
+
* Error
|
|
17
|
+
* @example
|
|
18
|
+
* dataClasses()
|
|
19
|
+
* .then(data => {
|
|
20
|
+
* if (data) {
|
|
21
|
+
* // ...
|
|
22
|
+
* } else {
|
|
23
|
+
* // ...
|
|
24
|
+
* }
|
|
25
|
+
* })
|
|
26
|
+
* .catch(err => {
|
|
27
|
+
* // ...
|
|
28
|
+
* });
|
|
29
|
+
*/
|
|
30
|
+
function dataClasses(options = {}) {
|
|
31
|
+
return fetchFromApi.fetchFromApi('/dataclasses', options);
|
|
32
|
+
}
|
|
33
|
+
exports.dataClasses = dataClasses;
|
|
34
|
+
//# sourceMappingURL=dataClasses.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dataClasses.js","sources":["../../src/dataClasses.ts"],"sourcesContent":["import { fetchFromApi } from './api/haveibeenpwned';\n\n/**\n * Fetches all data classes in the system.\n *\n * @param {object} [options] a configuration object\n * @param {string} [options.baseUrl] a custom base URL for the\n * haveibeenpwned.com API endpoints (default:\n * `https://haveibeenpwned.com/api/v3`)\n * @param {string} [options.userAgent] a custom string to send as the User-Agent\n * field in the request headers (default: `hibp <version>`)\n * @returns {(Promise<string[]> | Promise<null>)} a Promise which resolves to an\n * array of strings (or null if no data classes were found), or rejects with an\n * Error\n * @example\n * dataClasses()\n * .then(data => {\n * if (data) {\n * // ...\n * } else {\n * // ...\n * }\n * })\n * .catch(err => {\n * // ...\n * });\n */\nexport function dataClasses(\n options: { baseUrl?: string; userAgent?: string } = {},\n): Promise<string[] | null> {\n return fetchFromApi('/dataclasses', options) as Promise<string[] | null>;\n}\n"],"names":["dataClasses","options","fetchFromApi"],"mappings":";;;;AAEA;;;;;;;;;;;;;;;;;;;;;;;;AAwBG;AACa,SAAAA,WAAW,CACzBC,OAAA,GAAoD,EAAE,EAAA;EAEtD,OAAOC,YAAY,CAAAA,YAAA,CAAC,cAAc,EAAED,OAAO,CAA6B;AAC1E;"}
|
package/dist/cjs/hibp.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var breach = /*#__PURE__*/require('./breach.js');
|
|
4
|
+
var breachedAccount = /*#__PURE__*/require('./breachedAccount.js');
|
|
5
|
+
var breaches = /*#__PURE__*/require('./breaches.js');
|
|
6
|
+
var dataClasses = /*#__PURE__*/require('./dataClasses.js');
|
|
7
|
+
var pasteAccount = /*#__PURE__*/require('./pasteAccount.js');
|
|
8
|
+
var pwnedPassword = /*#__PURE__*/require('./pwnedPassword.js');
|
|
9
|
+
var pwnedPasswordRange = /*#__PURE__*/require('./pwnedPasswordRange.js');
|
|
10
|
+
var search = /*#__PURE__*/require('./search.js');
|
|
11
|
+
var fetchFromApi = /*#__PURE__*/require('./api/haveibeenpwned/fetchFromApi.js');
|
|
12
|
+
exports.breach = breach.breach;
|
|
13
|
+
exports.breachedAccount = breachedAccount.breachedAccount;
|
|
14
|
+
exports.breaches = breaches.breaches;
|
|
15
|
+
exports.dataClasses = dataClasses.dataClasses;
|
|
16
|
+
exports.pasteAccount = pasteAccount.pasteAccount;
|
|
17
|
+
exports.pwnedPassword = pwnedPassword.pwnedPassword;
|
|
18
|
+
exports.pwnedPasswordRange = pwnedPasswordRange.pwnedPasswordRange;
|
|
19
|
+
exports.search = search.search;
|
|
20
|
+
exports.RateLimitError = fetchFromApi.RateLimitError;
|
|
21
|
+
//# sourceMappingURL=hibp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hibp.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package.json.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var fetchFromApi = /*#__PURE__*/require('./api/haveibeenpwned/fetchFromApi.js');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* An object representing a paste.
|
|
7
|
+
*
|
|
8
|
+
* @typedef {object} Paste
|
|
9
|
+
* @property {string} Id
|
|
10
|
+
* @property {string} Source
|
|
11
|
+
* @property {string} Title
|
|
12
|
+
* @property {string} Date
|
|
13
|
+
* @property {number} EmailCount
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Fetches paste data for a specific account (email address).
|
|
17
|
+
*
|
|
18
|
+
* ***Warning (July 18, 2019):***
|
|
19
|
+
*
|
|
20
|
+
* `haveibeenpwned.com` now requires an API key from
|
|
21
|
+
* https://haveibeenpwned.com/API/Key for the `pasteaccount` endpoint. The
|
|
22
|
+
* `apiKey` option here is not explicitly required, but direct requests made
|
|
23
|
+
* without it (that is, without specifying a `baseUrl` to a proxy that inserts a
|
|
24
|
+
* valid API key on your behalf) will fail.
|
|
25
|
+
*
|
|
26
|
+
* @param {string} email the email address to query
|
|
27
|
+
* @param {object} [options] a configuration object
|
|
28
|
+
* @param {string} [options.apiKey] an API key from
|
|
29
|
+
* https://haveibeenpwned.com/API/Key
|
|
30
|
+
* @param {string} [options.baseUrl] a custom base URL for the
|
|
31
|
+
* haveibeenpwned.com API endpoints (default:
|
|
32
|
+
* `https://haveibeenpwned.com/api/v3`)
|
|
33
|
+
* @param {string} [options.userAgent] a custom string to send as the User-Agent
|
|
34
|
+
* field in the request headers (default: `hibp <version>`)
|
|
35
|
+
* @returns {(Promise<Paste[]> | Promise<null>)} a Promise which resolves to an
|
|
36
|
+
* array of paste objects (or null if no pastes were found), or rejects with an
|
|
37
|
+
* Error
|
|
38
|
+
* @example
|
|
39
|
+
* pasteAccount('foo@bar.com', { apiKey: 'my-api-key' })
|
|
40
|
+
* .then(data => {
|
|
41
|
+
* if (data) {
|
|
42
|
+
* // ...
|
|
43
|
+
* } else {
|
|
44
|
+
* // ...
|
|
45
|
+
* }
|
|
46
|
+
* })
|
|
47
|
+
* .catch(err => {
|
|
48
|
+
* // ...
|
|
49
|
+
* });
|
|
50
|
+
*/
|
|
51
|
+
function pasteAccount(email, options = {}) {
|
|
52
|
+
return fetchFromApi.fetchFromApi(`/pasteaccount/${encodeURIComponent(email)}`, {
|
|
53
|
+
apiKey: options.apiKey,
|
|
54
|
+
baseUrl: options.baseUrl,
|
|
55
|
+
userAgent: options.userAgent
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
exports.pasteAccount = pasteAccount;
|
|
59
|
+
//# sourceMappingURL=pasteAccount.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pasteAccount.js","sources":["../../src/pasteAccount.ts"],"sourcesContent":["import type { Paste } from './api/haveibeenpwned/types';\nimport { fetchFromApi } from './api/haveibeenpwned';\n\n/**\n * An object representing a paste.\n *\n * @typedef {object} Paste\n * @property {string} Id\n * @property {string} Source\n * @property {string} Title\n * @property {string} Date\n * @property {number} EmailCount\n */\n\n/**\n * Fetches paste data for a specific account (email address).\n *\n * ***Warning (July 18, 2019):***\n *\n * `haveibeenpwned.com` now requires an API key from\n * https://haveibeenpwned.com/API/Key for the `pasteaccount` endpoint. The\n * `apiKey` option here is not explicitly required, but direct requests made\n * without it (that is, without specifying a `baseUrl` to a proxy that inserts a\n * valid API key on your behalf) will fail.\n *\n * @param {string} email the email address to query\n * @param {object} [options] a configuration object\n * @param {string} [options.apiKey] an API key from\n * https://haveibeenpwned.com/API/Key\n * @param {string} [options.baseUrl] a custom base URL for the\n * haveibeenpwned.com API endpoints (default:\n * `https://haveibeenpwned.com/api/v3`)\n * @param {string} [options.userAgent] a custom string to send as the User-Agent\n * field in the request headers (default: `hibp <version>`)\n * @returns {(Promise<Paste[]> | Promise<null>)} a Promise which resolves to an\n * array of paste objects (or null if no pastes were found), or rejects with an\n * Error\n * @example\n * pasteAccount('foo@bar.com', { apiKey: 'my-api-key' })\n * .then(data => {\n * if (data) {\n * // ...\n * } else {\n * // ...\n * }\n * })\n * .catch(err => {\n * // ...\n * });\n */\nexport function pasteAccount(\n email: string,\n options: { apiKey?: string; baseUrl?: string; userAgent?: string } = {},\n): Promise<Paste[] | null> {\n return fetchFromApi(`/pasteaccount/${encodeURIComponent(email)}`, {\n apiKey: options.apiKey,\n baseUrl: options.baseUrl,\n userAgent: options.userAgent,\n }) as Promise<Paste[] | null>;\n}\n"],"names":["pasteAccount","email","options","fetchFromApi","encodeURIComponent","apiKey","baseUrl","userAgent"],"mappings":";;;;AAGA;;;;;;;;;AASG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmCG;SACaA,YAAY,CAC1BC,KAAa,EACbC,UAAqE,EAAE,EAAA;EAEvE,OAAOC,YAAAA,CAAAA,YAAY,CAAkB,iBAAAC,kBAAkB,CAACH,KAAK,GAAG,EAAE;IAChEI,MAAM,EAAEH,OAAO,CAACG,MAAM;IACtBC,OAAO,EAAEJ,OAAO,CAACI,OAAO;IACxBC,SAAS,EAAEL,OAAO,CAACK;EACpB,CAAA,CAA4B;AAC/B;"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var JSSHA = /*#__PURE__*/require('jssha/dist/sha1');
|
|
4
|
+
var pwnedPasswordRange = /*#__PURE__*/require('./pwnedPasswordRange.js');
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Fetches the number of times the the given password has been exposed in a
|
|
8
|
+
* breach (0 indicating no exposure). The password is given in plain text, but
|
|
9
|
+
* only the first 5 characters of its SHA-1 hash will be submitted to the API.
|
|
10
|
+
*
|
|
11
|
+
* @param {string} password a password in plain text
|
|
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 {string} [options.userAgent] a custom string to send as the User-Agent
|
|
16
|
+
* field in the request headers (default: `hibp <version>`)
|
|
17
|
+
* @returns {Promise<number>} a Promise which resolves to the number of times
|
|
18
|
+
* the password has been exposed in a breach, or rejects with an Error
|
|
19
|
+
* @example
|
|
20
|
+
* pwnedPassword('f00b4r')
|
|
21
|
+
* .then(numPwns => {
|
|
22
|
+
* // truthy check or numeric condition
|
|
23
|
+
* if (numPwns) {
|
|
24
|
+
* // ...
|
|
25
|
+
* } else {
|
|
26
|
+
* // ...
|
|
27
|
+
* }
|
|
28
|
+
* })
|
|
29
|
+
* .catch(err => {
|
|
30
|
+
* // ...
|
|
31
|
+
* });
|
|
32
|
+
* @see https://haveibeenpwned.com/api/v3#PwnedPasswords
|
|
33
|
+
*/
|
|
34
|
+
function pwnedPassword(password, options = {}) {
|
|
35
|
+
const sha1 = new JSSHA('SHA-1', 'TEXT');
|
|
36
|
+
sha1.update(password);
|
|
37
|
+
const hash = sha1.getHash('HEX', {
|
|
38
|
+
outputUpper: true
|
|
39
|
+
});
|
|
40
|
+
const prefix = hash.slice(0, 5);
|
|
41
|
+
const suffix = hash.slice(5);
|
|
42
|
+
return pwnedPasswordRange.pwnedPasswordRange(prefix, options).then(range => range[suffix] || 0);
|
|
43
|
+
}
|
|
44
|
+
exports.pwnedPassword = pwnedPassword;
|
|
45
|
+
//# sourceMappingURL=pwnedPassword.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pwnedPassword.js","sources":["../../src/pwnedPassword.ts"],"sourcesContent":["import JSSHA from 'jssha/dist/sha1';\nimport { pwnedPasswordRange } from './pwnedPasswordRange';\n\n/**\n * Fetches the number of times the the given password has been exposed in a\n * breach (0 indicating no exposure). The password is given in plain text, but\n * only the first 5 characters of its SHA-1 hash will be submitted to the API.\n *\n * @param {string} password a password in plain text\n * @param {object} [options] a configuration object\n * @param {string} [options.baseUrl] a custom base URL for the\n * pwnedpasswords.com API endpoints (default: `https://api.pwnedpasswords.com`)\n * @param {string} [options.userAgent] a custom string to send as the User-Agent\n * field in the request headers (default: `hibp <version>`)\n * @returns {Promise<number>} a Promise which resolves to the number of times\n * the password has been exposed in a breach, or rejects with an Error\n * @example\n * pwnedPassword('f00b4r')\n * .then(numPwns => {\n * // truthy check or numeric condition\n * if (numPwns) {\n * // ...\n * } else {\n * // ...\n * }\n * })\n * .catch(err => {\n * // ...\n * });\n * @see https://haveibeenpwned.com/api/v3#PwnedPasswords\n */\nexport function pwnedPassword(\n password: string,\n options: { baseUrl?: string; userAgent?: string } = {},\n): Promise<number> {\n const sha1 = new JSSHA('SHA-1', 'TEXT');\n sha1.update(password);\n const hash = sha1.getHash('HEX', { outputUpper: true });\n const prefix = hash.slice(0, 5);\n const suffix = hash.slice(5);\n\n return pwnedPasswordRange(prefix, options).then(\n (range) => range[suffix] || 0,\n );\n}\n"],"names":["pwnedPassword","password","options","sha1","JSSHA","update","hash","getHash","outputUpper","prefix","slice","suffix","pwnedPasswordRange","then","range"],"mappings":";;;;;AAGA;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BG;SACaA,aAAa,CAC3BC,QAAgB,EAChBC,UAAoD,EAAE,EAAA;EAEtD,MAAMC,IAAI,GAAG,IAAIC,KAAK,CAAC,OAAO,EAAE,MAAM,CAAC;EACvCD,IAAI,CAACE,MAAM,CAACJ,QAAQ,CAAC;EACrB,MAAMK,IAAI,GAAGH,IAAI,CAACI,OAAO,CAAC,KAAK,EAAE;IAAEC,WAAW,EAAE;EAAI,CAAE,CAAC;EACvD,MAAMC,MAAM,GAAGH,IAAI,CAACI,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC;EAC/B,MAAMC,MAAM,GAAGL,IAAI,CAACI,KAAK,CAAC,CAAC,CAAC;EAE5B,OAAOE,qCAAkB,CAACH,MAAM,EAAEP,OAAO,CAAC,CAACW,IAAI,CAC5CC,KAAK,IAAKA,KAAK,CAACH,MAAM,CAAC,IAAI,CAAC,CAC9B;AACH;"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var fetchFromApi = /*#__PURE__*/require('./api/pwnedpasswords/fetchFromApi.js');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* An object mapping an exposed password hash suffix (corresponding to a given
|
|
7
|
+
* hash prefix) to how many times it occurred in the Pwned Passwords repository.
|
|
8
|
+
*
|
|
9
|
+
* @typedef {Object.<string, number>} PwnedPasswordSuffixes
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Fetches the SHA-1 hash suffixes for the given 5-character SHA-1 hash prefix.
|
|
13
|
+
*
|
|
14
|
+
* When a password hash with the same first 5 characters is found in the Pwned
|
|
15
|
+
* Passwords repository, the API will respond with an HTTP 200 and include the
|
|
16
|
+
* suffix of every hash beginning with the specified prefix, followed by a count
|
|
17
|
+
* of how many times it appears in the data set. This function parses the
|
|
18
|
+
* response and returns a more structured format.
|
|
19
|
+
*
|
|
20
|
+
* @param {string} prefix the first 5 characters of a SHA-1 password hash (case
|
|
21
|
+
* insensitive)
|
|
22
|
+
* @param {object} [options] a configuration object
|
|
23
|
+
* @param {string} [options.baseUrl] a custom base URL for the
|
|
24
|
+
* pwnedpasswords.com API endpoints (default: `https://api.pwnedpasswords.com`)
|
|
25
|
+
* @param {string} [options.userAgent] a custom string to send as the User-Agent
|
|
26
|
+
* field in the request headers (default: `hibp <version>`)
|
|
27
|
+
* @returns {Promise<PwnedPasswordSuffixes>} a Promise which resolves to an
|
|
28
|
+
* object mapping the `suffix` that when matched with the prefix composes the
|
|
29
|
+
* complete hash, to the `count` of how many times it appears in the breached
|
|
30
|
+
* password data set, or rejects with an Error
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* pwnedPasswordRange('5BAA6')
|
|
34
|
+
* .then(results => {
|
|
35
|
+
* // results will have the following shape:
|
|
36
|
+
* // {
|
|
37
|
+
* // "003D68EB55068C33ACE09247EE4C639306B": 3,
|
|
38
|
+
* // "012C192B2F16F82EA0EB9EF18D9D539B0DD": 1,
|
|
39
|
+
* // ...
|
|
40
|
+
* // }
|
|
41
|
+
* })
|
|
42
|
+
* @example
|
|
43
|
+
* const suffix = '1E4C9B93F3F0682250B6CF8331B7EE68FD8';
|
|
44
|
+
* pwnedPasswordRange('5BAA6')
|
|
45
|
+
* .then(results => (results[suffix] || 0))
|
|
46
|
+
* .catch(err => {
|
|
47
|
+
* // ...
|
|
48
|
+
* });
|
|
49
|
+
* @see https://haveibeenpwned.com/api/v3#SearchingPwnedPasswordsByRange
|
|
50
|
+
*/
|
|
51
|
+
function pwnedPasswordRange(prefix, options = {}) {
|
|
52
|
+
return fetchFromApi.fetchFromApi(`/range/${encodeURIComponent(prefix)}`, options)
|
|
53
|
+
// create array from lines of text in response body
|
|
54
|
+
.then(data => data.split('\n').filter(Boolean))
|
|
55
|
+
// convert into an object mapping suffix to count for each line
|
|
56
|
+
.then(results => results.reduce((acc, row) => {
|
|
57
|
+
const [suffix, countString] = row.split(':');
|
|
58
|
+
acc[suffix] = parseInt(countString, 10);
|
|
59
|
+
return acc;
|
|
60
|
+
}, {}));
|
|
61
|
+
}
|
|
62
|
+
exports.pwnedPasswordRange = pwnedPasswordRange;
|
|
63
|
+
//# sourceMappingURL=pwnedPasswordRange.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pwnedPasswordRange.js","sources":["../../src/pwnedPasswordRange.ts"],"sourcesContent":["import { fetchFromApi } from './api/pwnedpasswords';\n\nexport interface PwnedPasswordSuffixes {\n [suffix: string]: number;\n}\n\n/**\n * An object mapping an exposed password hash suffix (corresponding to a given\n * hash prefix) to how many times it occurred in the Pwned Passwords repository.\n *\n * @typedef {Object.<string, number>} PwnedPasswordSuffixes\n */\n\n/**\n * Fetches the SHA-1 hash suffixes for the given 5-character SHA-1 hash prefix.\n *\n * When a password hash with the same first 5 characters is found in the Pwned\n * Passwords repository, the API will respond with an HTTP 200 and include the\n * suffix of every hash beginning with the specified prefix, followed by a count\n * of how many times it appears in the data set. This function parses the\n * response and returns a more structured format.\n *\n * @param {string} prefix the first 5 characters of a SHA-1 password hash (case\n * insensitive)\n * @param {object} [options] a configuration object\n * @param {string} [options.baseUrl] a custom base URL for the\n * pwnedpasswords.com API endpoints (default: `https://api.pwnedpasswords.com`)\n * @param {string} [options.userAgent] a custom string to send as the User-Agent\n * field in the request headers (default: `hibp <version>`)\n * @returns {Promise<PwnedPasswordSuffixes>} a Promise which resolves to an\n * object mapping the `suffix` that when matched with the prefix composes the\n * complete hash, to the `count` of how many times it appears in the breached\n * password data set, or rejects with an Error\n *\n * @example\n * pwnedPasswordRange('5BAA6')\n * .then(results => {\n * // results will have the following shape:\n * // {\n * // \"003D68EB55068C33ACE09247EE4C639306B\": 3,\n * // \"012C192B2F16F82EA0EB9EF18D9D539B0DD\": 1,\n * // ...\n * // }\n * })\n * @example\n * const suffix = '1E4C9B93F3F0682250B6CF8331B7EE68FD8';\n * pwnedPasswordRange('5BAA6')\n * .then(results => (results[suffix] || 0))\n * .catch(err => {\n * // ...\n * });\n * @see https://haveibeenpwned.com/api/v3#SearchingPwnedPasswordsByRange\n */\nexport function pwnedPasswordRange(\n prefix: string,\n options: { baseUrl?: string; userAgent?: string } = {},\n): Promise<PwnedPasswordSuffixes> {\n return (\n fetchFromApi(`/range/${encodeURIComponent(prefix)}`, options)\n // create array from lines of text in response body\n .then((data) => data.split('\\n').filter(Boolean))\n // convert into an object mapping suffix to count for each line\n .then((results) =>\n results.reduce<PwnedPasswordSuffixes>((acc, row) => {\n const [suffix, countString] = row.split(':');\n acc[suffix] = parseInt(countString, 10);\n return acc;\n }, {}),\n )\n );\n}\n"],"names":["pwnedPasswordRange","prefix","options","fetchFromApi","encodeURIComponent","then","data","split","filter","Boolean","results","reduce","acc","row","suffix","countString","parseInt"],"mappings":";;;;AAMA;;;;;AAKG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCG;SACaA,kBAAkB,CAChCC,MAAc,EACdC,UAAoD,EAAE,EAAA;EAEtD,OACEC,YAAAA,CAAAA,YAAY,CAAW,UAAAC,kBAAkB,CAACH,MAAM,CAAC,EAAE,EAAEC,OAAO;;GAEzDG,IAAI,CAAEC,IAAI,IAAKA,IAAI,CAACC,KAAK,CAAC,IAAI,CAAC,CAACC,MAAM,CAACC,OAAO,CAAC;;GAE/CJ,IAAI,CAAEK,OAAO,IACZA,OAAO,CAACC,MAAM,CAAwB,CAACC,GAAG,EAAEC,GAAG,KAAI;IACjD,MAAM,CAACC,MAAM,EAAEC,WAAW,CAAC,GAAGF,GAAG,CAACN,KAAK,CAAC,GAAG,CAAC;IAC5CK,GAAG,CAACE,MAAM,CAAC,GAAGE,QAAQ,CAACD,WAAW,EAAE,EAAE,CAAC;IACvC,OAAOH,GAAG;EACZ,CAAC,EAAE,CAAA,CAAE,CAAC,CACP;AAEP;"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var breachedAccount = /*#__PURE__*/require('./breachedAccount.js');
|
|
4
|
+
var pasteAccount = /*#__PURE__*/require('./pasteAccount.js');
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* An object representing search results.
|
|
8
|
+
*
|
|
9
|
+
* @typedef {object} SearchResults
|
|
10
|
+
* @property {(Breach[] | null)} breaches
|
|
11
|
+
* @property {(Paste[] | null)} pastes
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Fetches all breaches and all pastes associated with the provided account
|
|
15
|
+
* (email address or username). Note that the remote API does not support
|
|
16
|
+
* querying pastes by username (only email addresses), so in the event the
|
|
17
|
+
* provided account is not a valid email address, only breach data is queried
|
|
18
|
+
* and the "pastes" field of the resulting object will always be null. This is
|
|
19
|
+
* exactly how searching via the current web interface behaves, which this
|
|
20
|
+
* convenience method is designed to mimic.
|
|
21
|
+
*
|
|
22
|
+
* ***Warning (July 18, 2019):***
|
|
23
|
+
*
|
|
24
|
+
* `haveibeenpwned.com` now requires an API key from
|
|
25
|
+
* https://haveibeenpwned.com/API/Key for the `breachedaccount` and
|
|
26
|
+
* `pasteaccount` endpoints. The `apiKey` option here is not explicitly
|
|
27
|
+
* required, but direct requests made without it (that is, without specifying a
|
|
28
|
+
* `baseUrl` to a proxy that inserts a valid API key on your behalf) will fail.
|
|
29
|
+
*
|
|
30
|
+
* @param {string} account an email address or username
|
|
31
|
+
* @param {object} [breachOptions] a configuration object pertaining to breach
|
|
32
|
+
* queries
|
|
33
|
+
* @param {string} [breachOptions.apiKey] an API key from
|
|
34
|
+
* https://haveibeenpwned.com/API/Key
|
|
35
|
+
* @param {string} [breachOptions.domain] a domain by which to filter the
|
|
36
|
+
* results (default: all domains)
|
|
37
|
+
* @param {boolean} [breachOptions.truncate] truncate the results to only
|
|
38
|
+
* include the name of each breach (default: true)
|
|
39
|
+
* @param {string} [breachOptions.baseUrl] a custom base URL for the
|
|
40
|
+
* haveibeenpwned.com API endpoints (default:
|
|
41
|
+
* `https://haveibeenpwned.com/api/v3`)
|
|
42
|
+
* @param {string} [breachOptions.userAgent] a custom string to send as the
|
|
43
|
+
* User-Agent field in the request headers (default: `hibp <version>`)
|
|
44
|
+
* @returns {Promise<SearchResults>} a Promise which resolves to an object
|
|
45
|
+
* containing a "breaches" key (which can be null or an array of breach objects)
|
|
46
|
+
* and a "pastes" key (which can be null or an array of paste objects), or
|
|
47
|
+
* rejects with an Error
|
|
48
|
+
* @example
|
|
49
|
+
* search('foo', { apiKey: 'my-api-key' })
|
|
50
|
+
* .then(data => {
|
|
51
|
+
* if (data.breaches || data.pastes) {
|
|
52
|
+
* // ...
|
|
53
|
+
* } else {
|
|
54
|
+
* // ...
|
|
55
|
+
* }
|
|
56
|
+
* })
|
|
57
|
+
* .catch(err => {
|
|
58
|
+
* // ...
|
|
59
|
+
* });
|
|
60
|
+
* @example
|
|
61
|
+
* search('nobody@nowhere.com', { apiKey: 'my-api-key', truncate: false })
|
|
62
|
+
* .then(data => {
|
|
63
|
+
* if (data.breaches || data.pastes) {
|
|
64
|
+
* // ...
|
|
65
|
+
* } else {
|
|
66
|
+
* // ...
|
|
67
|
+
* }
|
|
68
|
+
* })
|
|
69
|
+
* .catch(err => {
|
|
70
|
+
* // ...
|
|
71
|
+
* });
|
|
72
|
+
*
|
|
73
|
+
* @see https://haveibeenpwned.com/
|
|
74
|
+
*/
|
|
75
|
+
function search(account, breachOptions = {
|
|
76
|
+
truncate: true
|
|
77
|
+
}) {
|
|
78
|
+
const {
|
|
79
|
+
apiKey,
|
|
80
|
+
baseUrl,
|
|
81
|
+
userAgent
|
|
82
|
+
} = breachOptions;
|
|
83
|
+
return Promise.all([breachedAccount.breachedAccount(account, breachOptions),
|
|
84
|
+
// This email regex is garbage but it seems to be what the API uses:
|
|
85
|
+
/^.+@.+$/.test(account) ? pasteAccount.pasteAccount(account, {
|
|
86
|
+
apiKey,
|
|
87
|
+
baseUrl,
|
|
88
|
+
userAgent
|
|
89
|
+
}) : null]).then(
|
|
90
|
+
// Avoid array destructuring here to prevent need for Babel helpers
|
|
91
|
+
promises => ({
|
|
92
|
+
breaches: promises[0],
|
|
93
|
+
pastes: promises[1]
|
|
94
|
+
}));
|
|
95
|
+
}
|
|
96
|
+
exports.search = search;
|
|
97
|
+
//# sourceMappingURL=search.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search.js","sources":["../../src/search.ts"],"sourcesContent":["import type { Breach, Paste } from './api/haveibeenpwned/types';\nimport { breachedAccount } from './breachedAccount';\nimport { pasteAccount } from './pasteAccount';\n\nexport interface SearchResults {\n breaches: Breach[] | null;\n pastes: Paste[] | null;\n}\n\n/**\n * An object representing search results.\n *\n * @typedef {object} SearchResults\n * @property {(Breach[] | null)} breaches\n * @property {(Paste[] | null)} pastes\n */\n\n/**\n * Fetches all breaches and all pastes associated with the provided account\n * (email address or username). Note that the remote API does not support\n * querying pastes by username (only email addresses), so in the event the\n * provided account is not a valid email address, only breach data is queried\n * and the \"pastes\" field of the resulting object will always be null. This is\n * exactly how searching via the current web interface behaves, which this\n * convenience method is designed to mimic.\n *\n * ***Warning (July 18, 2019):***\n *\n * `haveibeenpwned.com` now requires an API key from\n * https://haveibeenpwned.com/API/Key for the `breachedaccount` and\n * `pasteaccount` endpoints. The `apiKey` option here is not explicitly\n * required, but direct requests made without it (that is, without specifying a\n * `baseUrl` to a proxy that inserts a valid API key on your behalf) will fail.\n *\n * @param {string} account an email address or username\n * @param {object} [breachOptions] a configuration object pertaining to breach\n * queries\n * @param {string} [breachOptions.apiKey] an API key from\n * https://haveibeenpwned.com/API/Key\n * @param {string} [breachOptions.domain] a domain by which to filter the\n * results (default: all domains)\n * @param {boolean} [breachOptions.truncate] truncate the results to only\n * include the name of each breach (default: true)\n * @param {string} [breachOptions.baseUrl] a custom base URL for the\n * haveibeenpwned.com API endpoints (default:\n * `https://haveibeenpwned.com/api/v3`)\n * @param {string} [breachOptions.userAgent] a custom string to send as the\n * User-Agent field in the request headers (default: `hibp <version>`)\n * @returns {Promise<SearchResults>} a Promise which resolves to an object\n * containing a \"breaches\" key (which can be null or an array of breach objects)\n * and a \"pastes\" key (which can be null or an array of paste objects), or\n * rejects with an Error\n * @example\n * search('foo', { apiKey: 'my-api-key' })\n * .then(data => {\n * if (data.breaches || data.pastes) {\n * // ...\n * } else {\n * // ...\n * }\n * })\n * .catch(err => {\n * // ...\n * });\n * @example\n * search('nobody@nowhere.com', { apiKey: 'my-api-key', truncate: false })\n * .then(data => {\n * if (data.breaches || data.pastes) {\n * // ...\n * } else {\n * // ...\n * }\n * })\n * .catch(err => {\n * // ...\n * });\n *\n * @see https://haveibeenpwned.com/\n */\nexport function search(\n account: string,\n breachOptions: {\n apiKey?: string;\n domain?: string;\n truncate?: boolean;\n baseUrl?: string;\n userAgent?: string;\n } = {\n truncate: true,\n },\n): Promise<SearchResults> {\n const { apiKey, baseUrl, userAgent } = breachOptions;\n\n return Promise.all([\n breachedAccount(account, breachOptions),\n // This email regex is garbage but it seems to be what the API uses:\n /^.+@.+$/.test(account)\n ? pasteAccount(account, { apiKey, baseUrl, userAgent })\n : null,\n ]).then(\n // Avoid array destructuring here to prevent need for Babel helpers\n (promises) => ({\n breaches: promises[0],\n pastes: promises[1],\n }),\n );\n}\n"],"names":["search","account","breachOptions","truncate","apiKey","baseUrl","userAgent","Promise","all","breachedAccount","test","pasteAccount","then","promises","breaches","pastes"],"mappings":";;;;;AASA;;;;;;AAMG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6DG;AACa,SAAAA,MAAM,CACpBC,OAAe,EACfC,aAMI,GAAA;EACFC,QAAQ,EAAE;AACX,CAAA,EAAA;EAED,MAAM;IAAEC,MAAM;IAAEC,OAAO;IAAEC;EAAS,CAAE,GAAGJ,aAAa;EAEpD,OAAOK,OAAO,CAACC,GAAG,CAAC,CACjBC,eAAe,CAAAA,eAAA,CAACR,OAAO,EAAEC,aAAa,CAAC;;EAEvC,SAAS,CAACQ,IAAI,CAACT,OAAO,CAAC,GACnBU,YAAAA,CAAAA,YAAY,CAACV,OAAO,EAAE;IAAEG,MAAM;IAAEC,OAAO;IAAEC;EAAS,CAAE,CAAC,GACrD,IAAI,CACT,CAAC,CAACM,IAAI;;EAEJC,QAAQ,KAAM;IACbC,QAAQ,EAAED,QAAQ,CAAC,CAAC,CAAC;IACrBE,MAAM,EAAEF,QAAQ,CAAC,CAAC;EACnB,CAAA,CAAC,CACH;AACH;"}
|