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.
Files changed (76) hide show
  1. package/API.md +508 -0
  2. package/CHANGELOG.md +7 -0
  3. package/LICENSE.txt +22 -0
  4. package/MIGRATION.md +227 -0
  5. package/README.md +255 -0
  6. package/dist/browser/hibp.module.js +2 -0
  7. package/dist/browser/hibp.module.js.map +1 -0
  8. package/dist/browser/hibp.umd.js +2 -0
  9. package/dist/browser/hibp.umd.js.map +1 -0
  10. package/dist/cjs/api/haveibeenpwned/fetchFromApi.js +107 -0
  11. package/dist/cjs/api/haveibeenpwned/fetchFromApi.js.map +1 -0
  12. package/dist/cjs/api/haveibeenpwned/index.js +6 -0
  13. package/dist/cjs/api/haveibeenpwned/index.js.map +1 -0
  14. package/dist/cjs/api/haveibeenpwned/responses.js +79 -0
  15. package/dist/cjs/api/haveibeenpwned/responses.js.map +1 -0
  16. package/dist/cjs/api/pwnedpasswords/fetchFromApi.js +44 -0
  17. package/dist/cjs/api/pwnedpasswords/fetchFromApi.js.map +1 -0
  18. package/dist/cjs/api/pwnedpasswords/index.js +5 -0
  19. package/dist/cjs/api/pwnedpasswords/index.js.map +1 -0
  20. package/dist/cjs/api/pwnedpasswords/responses.js +20 -0
  21. package/dist/cjs/api/pwnedpasswords/responses.js.map +1 -0
  22. package/dist/cjs/breach.js +55 -0
  23. package/dist/cjs/breach.js.map +1 -0
  24. package/dist/cjs/breachedAccount.js +101 -0
  25. package/dist/cjs/breachedAccount.js.map +1 -0
  26. package/dist/cjs/breaches.js +55 -0
  27. package/dist/cjs/breaches.js.map +1 -0
  28. package/dist/cjs/dataClasses.js +34 -0
  29. package/dist/cjs/dataClasses.js.map +1 -0
  30. package/dist/cjs/hibp.js +21 -0
  31. package/dist/cjs/hibp.js.map +1 -0
  32. package/dist/cjs/package.json.js +7 -0
  33. package/dist/cjs/package.json.js.map +1 -0
  34. package/dist/cjs/pasteAccount.js +59 -0
  35. package/dist/cjs/pasteAccount.js.map +1 -0
  36. package/dist/cjs/pwnedPassword.js +45 -0
  37. package/dist/cjs/pwnedPassword.js.map +1 -0
  38. package/dist/cjs/pwnedPasswordRange.js +63 -0
  39. package/dist/cjs/pwnedPasswordRange.js.map +1 -0
  40. package/dist/cjs/search.js +97 -0
  41. package/dist/cjs/search.js.map +1 -0
  42. package/dist/esm/api/haveibeenpwned/fetchFromApi.mjs +104 -0
  43. package/dist/esm/api/haveibeenpwned/fetchFromApi.mjs.map +1 -0
  44. package/dist/esm/api/haveibeenpwned/index.mjs +2 -0
  45. package/dist/esm/api/haveibeenpwned/index.mjs.map +1 -0
  46. package/dist/esm/api/haveibeenpwned/responses.mjs +71 -0
  47. package/dist/esm/api/haveibeenpwned/responses.mjs.map +1 -0
  48. package/dist/esm/api/pwnedpasswords/fetchFromApi.mjs +42 -0
  49. package/dist/esm/api/pwnedpasswords/fetchFromApi.mjs.map +1 -0
  50. package/dist/esm/api/pwnedpasswords/index.mjs +2 -0
  51. package/dist/esm/api/pwnedpasswords/index.mjs.map +1 -0
  52. package/dist/esm/api/pwnedpasswords/responses.mjs +17 -0
  53. package/dist/esm/api/pwnedpasswords/responses.mjs.map +1 -0
  54. package/dist/esm/breach.mjs +53 -0
  55. package/dist/esm/breach.mjs.map +1 -0
  56. package/dist/esm/breachedAccount.mjs +99 -0
  57. package/dist/esm/breachedAccount.mjs.map +1 -0
  58. package/dist/esm/breaches.mjs +53 -0
  59. package/dist/esm/breaches.mjs.map +1 -0
  60. package/dist/esm/dataClasses.mjs +32 -0
  61. package/dist/esm/dataClasses.mjs.map +1 -0
  62. package/dist/esm/hibp.mjs +10 -0
  63. package/dist/esm/hibp.mjs.map +1 -0
  64. package/dist/esm/package.json.mjs +4 -0
  65. package/dist/esm/package.json.mjs.map +1 -0
  66. package/dist/esm/pasteAccount.mjs +57 -0
  67. package/dist/esm/pasteAccount.mjs.map +1 -0
  68. package/dist/esm/pwnedPassword.mjs +43 -0
  69. package/dist/esm/pwnedPassword.mjs.map +1 -0
  70. package/dist/esm/pwnedPasswordRange.mjs +61 -0
  71. package/dist/esm/pwnedPasswordRange.mjs.map +1 -0
  72. package/dist/esm/search.mjs +95 -0
  73. package/dist/esm/search.mjs.map +1 -0
  74. package/dist/hibp.d.ts +502 -0
  75. package/example/runkit.js +16 -0
  76. package/package.json +139 -0
package/API.md ADDED
@@ -0,0 +1,508 @@
1
+ ## Functions
2
+
3
+ <dl>
4
+ <dt><a href="#breach">breach(breachName, [options])</a> ⇒ <code><a href="#breach--object">Promise.&lt;Breach&gt;</a></code> | <code>Promise.&lt;null&gt;</code></dt>
5
+ <dd><p>Fetches data for a specific breach event.</p>
6
+ </dd>
7
+ <dt><a href="#breachedAccount">breachedAccount(account, [options])</a> ⇒ <code><a href="#breach--object">Promise.&lt;Array.&lt;Breach&gt;&gt;</a></code> | <code>Promise.&lt;null&gt;</code></dt>
8
+ <dd><p>Fetches breach data for a specific account.</p>
9
+ <p><em><strong>Warning (July 18, 2019):</strong></em></p>
10
+ <p><code>haveibeenpwned.com</code> now requires an API key from
11
+ <a href="https://haveibeenpwned.com/API/Key">https://haveibeenpwned.com/API/Key</a> for the <code>breachedaccount</code> endpoint. The
12
+ <code>apiKey</code> option here is not explicitly required, but direct requests made
13
+ without it (that is, without specifying a <code>baseUrl</code> to a proxy that inserts a
14
+ valid API key on your behalf) will fail.</p>
15
+ </dd>
16
+ <dt><a href="#breaches">breaches([options])</a> ⇒ <code><a href="#breach--object">Promise.&lt;Array.&lt;Breach&gt;&gt;</a></code></dt>
17
+ <dd><p>Fetches all breach events in the system.</p>
18
+ </dd>
19
+ <dt><a href="#dataClasses">dataClasses([options])</a> ⇒ <code>Promise.&lt;Array.&lt;string&gt;&gt;</code> | <code>Promise.&lt;null&gt;</code></dt>
20
+ <dd><p>Fetches all data classes in the system.</p>
21
+ </dd>
22
+ <dt><a href="#pasteAccount">pasteAccount(email, [options])</a> ⇒ <code><a href="#paste--object">Promise.&lt;Array.&lt;Paste&gt;&gt;</a></code> | <code>Promise.&lt;null&gt;</code></dt>
23
+ <dd><p>Fetches paste data for a specific account (email address).</p>
24
+ <p><em><strong>Warning (July 18, 2019):</strong></em></p>
25
+ <p><code>haveibeenpwned.com</code> now requires an API key from
26
+ <a href="https://haveibeenpwned.com/API/Key">https://haveibeenpwned.com/API/Key</a> for the <code>pasteaccount</code> endpoint. The
27
+ <code>apiKey</code> option here is not explicitly required, but direct requests made
28
+ without it (that is, without specifying a <code>baseUrl</code> to a proxy that inserts a
29
+ valid API key on your behalf) will fail.</p>
30
+ </dd>
31
+ <dt><a href="#pwnedPassword">pwnedPassword(password, [options])</a> ⇒ <code>Promise.&lt;number&gt;</code></dt>
32
+ <dd><p>Fetches the number of times the the given password has been exposed in a
33
+ breach (0 indicating no exposure). The password is given in plain text, but
34
+ only the first 5 characters of its SHA-1 hash will be submitted to the API.</p>
35
+ </dd>
36
+ <dt><a href="#pwnedPasswordRange">pwnedPasswordRange(prefix, [options])</a> ⇒ <code><a href="#PwnedPasswordSuffixes">Promise.&lt;PwnedPasswordSuffixes&gt;</a></code></dt>
37
+ <dd><p>Fetches the SHA-1 hash suffixes for the given 5-character SHA-1 hash prefix.</p>
38
+ <p>When a password hash with the same first 5 characters is found in the Pwned
39
+ Passwords repository, the API will respond with an HTTP 200 and include the
40
+ suffix of every hash beginning with the specified prefix, followed by a count
41
+ of how many times it appears in the data set. This function parses the
42
+ response and returns a more structured format.</p>
43
+ </dd>
44
+ <dt><a href="#search">search(account, [breachOptions])</a> ⇒ <code><a href="#SearchResults">Promise.&lt;SearchResults&gt;</a></code></dt>
45
+ <dd><p>Fetches all breaches and all pastes associated with the provided account
46
+ (email address or username). Note that the remote API does not support
47
+ querying pastes by username (only email addresses), so in the event the
48
+ provided account is not a valid email address, only breach data is queried
49
+ and the &quot;pastes&quot; field of the resulting object will always be null. This is
50
+ exactly how searching via the current web interface behaves, which this
51
+ convenience method is designed to mimic.</p>
52
+ <p><em><strong>Warning (July 18, 2019):</strong></em></p>
53
+ <p><code>haveibeenpwned.com</code> now requires an API key from
54
+ <a href="https://haveibeenpwned.com/API/Key">https://haveibeenpwned.com/API/Key</a> for the <code>breachedaccount</code> and
55
+ <code>pasteaccount</code> endpoints. The <code>apiKey</code> option here is not explicitly
56
+ required, but direct requests made without it (that is, without specifying a
57
+ <code>baseUrl</code> to a proxy that inserts a valid API key on your behalf) will fail.</p>
58
+ </dd>
59
+ </dl>
60
+
61
+ ## Typedefs
62
+
63
+ <dl>
64
+ <dt><a href="#breach--object">Breach</a> : <code>object</code></dt>
65
+ <dd><p>An object representing a breach.</p>
66
+ </dd>
67
+ <dt><a href="#Paste">Paste</a> : <code>object</code></dt>
68
+ <dd><p>An object representing a paste.</p>
69
+ </dd>
70
+ <dt><a href="#PwnedPasswordSuffixes">PwnedPasswordSuffixes</a> : <code>Object.&lt;string, number&gt;</code></dt>
71
+ <dd><p>An object mapping an exposed password hash suffix (corresponding to a given
72
+ hash prefix) to how many times it occurred in the Pwned Passwords repository.</p>
73
+ </dd>
74
+ <dt><a href="#SearchResults">SearchResults</a> : <code>object</code></dt>
75
+ <dd><p>An object representing search results.</p>
76
+ </dd>
77
+ </dl>
78
+
79
+ <a name="breach"></a>
80
+
81
+ ## breach(breachName, [options]) ⇒ [<code>Promise.&lt;Breach&gt;</code>](#breach--object) \| <code>Promise.&lt;null&gt;</code>
82
+ Fetches data for a specific breach event.
83
+
84
+ **Kind**: global function
85
+ **Returns**: [<code>Promise.&lt;Breach&gt;</code>](#breach--object) \| <code>Promise.&lt;null&gt;</code> - a Promise which resolves to an
86
+ object representing a breach (or null if no breach was found), or rejects
87
+ with an Error
88
+
89
+ | Param | Type | Description |
90
+ | --- | --- | --- |
91
+ | breachName | <code>string</code> | the name of a breach in the system |
92
+ | [options] | <code>object</code> | a configuration object |
93
+ | [options.baseUrl] | <code>string</code> | a custom base URL for the haveibeenpwned.com API endpoints (default: `https://haveibeenpwned.com/api/v3`) |
94
+ | [options.userAgent] | <code>string</code> | a custom string to send as the User-Agent field in the request headers (default: `hibp <version>`) |
95
+
96
+ **Example**
97
+ ```js
98
+ breach('Adobe')
99
+ .then(data => {
100
+ if (data) {
101
+ // ...
102
+ } else {
103
+ // ...
104
+ }
105
+ })
106
+ .catch(err => {
107
+ // ...
108
+ });
109
+ ```
110
+ <a name="breachedAccount"></a>
111
+
112
+ ## breachedAccount(account, [options]) ⇒ <code><a href="#breach--object">Promise.&lt;Array.&lt;Breach&gt;&gt;</a></code> \| <code>Promise.&lt;null&gt;</code>
113
+ Fetches breach data for a specific account.
114
+
115
+ ***Warning (July 18, 2019):***
116
+
117
+ `haveibeenpwned.com` now requires an API key from
118
+ https://haveibeenpwned.com/API/Key for the `breachedaccount` endpoint. The
119
+ `apiKey` option here is not explicitly required, but direct requests made
120
+ without it (that is, without specifying a `baseUrl` to a proxy that inserts a
121
+ valid API key on your behalf) will fail.
122
+
123
+ **Kind**: global function
124
+ **Returns**: <code><a href="#breach--object">Promise.&lt;Array.&lt;Breach&gt;&gt;</a></code> \| <code>Promise.&lt;null&gt;</code> - a Promise which resolves to an
125
+ array of breach objects (or null if no breaches were found), or rejects with
126
+ an Error
127
+
128
+ | Param | Type | Description |
129
+ | --- | --- | --- |
130
+ | account | <code>string</code> | a username or email address |
131
+ | [options] | <code>object</code> | a configuration object |
132
+ | [options.apiKey] | <code>string</code> | an API key from https://haveibeenpwned.com/API/Key (default: undefined) |
133
+ | [options.domain] | <code>string</code> | a domain by which to filter the results (default: all domains) |
134
+ | [options.includeUnverified] | <code>boolean</code> | include "unverified" breaches in the results (default: true) |
135
+ | [options.truncate] | <code>boolean</code> | truncate the results to only include the name of each breach (default: true) |
136
+ | [options.baseUrl] | <code>string</code> | a custom base URL for the haveibeenpwned.com API endpoints (default: `https://haveibeenpwned.com/api/v3`) |
137
+ | [options.userAgent] | <code>string</code> | a custom string to send as the User-Agent field in the request headers (default: `hibp <version>`) |
138
+
139
+ **Example**
140
+ ```js
141
+ breachedAccount('foo', { apiKey: 'my-api-key' })
142
+ .then(data => {
143
+ if (data) {
144
+ // ...
145
+ } else {
146
+ // ...
147
+ }
148
+ })
149
+ .catch(err => {
150
+ // ...
151
+ });
152
+ ```
153
+ **Example**
154
+ ```js
155
+ breachedAccount('bar', {
156
+ includeUnverified: false,
157
+ baseUrl: 'https://my-hibp-proxy:8080',
158
+ })
159
+ .then(data => {
160
+ if (data) {
161
+ // ...
162
+ } else {
163
+ // ...
164
+ }
165
+ })
166
+ .catch(err => {
167
+ // ...
168
+ });
169
+ ```
170
+ **Example**
171
+ ```js
172
+ breachedAccount('baz', {
173
+ apiKey: 'my-api-key',
174
+ domain: 'adobe.com',
175
+ truncate: false,
176
+ userAgent: 'my-app 1.0'
177
+ })
178
+ .then(data => {
179
+ if (data) {
180
+ // ...
181
+ } else {
182
+ // ...
183
+ }
184
+ })
185
+ .catch(err => {
186
+ // ...
187
+ });
188
+ ```
189
+ <a name="breaches"></a>
190
+
191
+ ## breaches([options]) ⇒ <code><a href="#breach--object">Promise.&lt;Array.&lt;Breach&gt;&gt;</a></code>
192
+ Fetches all breach events in the system.
193
+
194
+ **Kind**: global function
195
+ **Returns**: <code><a href="#breach--object">Promise.&lt;Array.&lt;Breach&gt;&gt;</a></code> - a Promise which resolves to an array of breach
196
+ objects (an empty array if no breaches were found), or rejects with an Error
197
+
198
+ | Param | Type | Description |
199
+ | --- | --- | --- |
200
+ | [options] | <code>object</code> | a configuration object |
201
+ | [options.domain] | <code>string</code> | a domain by which to filter the results (default: all domains) |
202
+ | [options.baseUrl] | <code>string</code> | a custom base URL for the haveibeenpwned.com API endpoints (default: `https://haveibeenpwned.com/api/v3`) |
203
+ | [options.userAgent] | <code>string</code> | a custom string to send as the User-Agent field in the request headers (default: `hibp <version>`) |
204
+
205
+ **Example**
206
+ ```js
207
+ breaches()
208
+ .then(data => {
209
+ if (data) {
210
+ // ...
211
+ } else {
212
+ // ...
213
+ }
214
+ })
215
+ .catch(err => {
216
+ // ...
217
+ });
218
+ ```
219
+ **Example**
220
+ ```js
221
+ breaches({ domain: 'adobe.com' })
222
+ .then(data => {
223
+ if (data) {
224
+ // ...
225
+ } else {
226
+ // ...
227
+ }
228
+ })
229
+ .catch(err => {
230
+ // ...
231
+ });
232
+ ```
233
+ <a name="dataClasses"></a>
234
+
235
+ ## dataClasses([options]) ⇒ <code>Promise.&lt;Array.&lt;string&gt;&gt;</code> \| <code>Promise.&lt;null&gt;</code>
236
+ Fetches all data classes in the system.
237
+
238
+ **Kind**: global function
239
+ **Returns**: <code>Promise.&lt;Array.&lt;string&gt;&gt;</code> \| <code>Promise.&lt;null&gt;</code> - a Promise which resolves to an
240
+ array of strings (or null if no data classes were found), or rejects with an
241
+ Error
242
+
243
+ | Param | Type | Description |
244
+ | --- | --- | --- |
245
+ | [options] | <code>object</code> | a configuration object |
246
+ | [options.baseUrl] | <code>string</code> | a custom base URL for the haveibeenpwned.com API endpoints (default: `https://haveibeenpwned.com/api/v3`) |
247
+ | [options.userAgent] | <code>string</code> | a custom string to send as the User-Agent field in the request headers (default: `hibp <version>`) |
248
+
249
+ **Example**
250
+ ```js
251
+ dataClasses()
252
+ .then(data => {
253
+ if (data) {
254
+ // ...
255
+ } else {
256
+ // ...
257
+ }
258
+ })
259
+ .catch(err => {
260
+ // ...
261
+ });
262
+ ```
263
+ <a name="pasteAccount"></a>
264
+
265
+ ## pasteAccount(email, [options]) ⇒ <code><a href="#paste--object">Promise.&lt;Array.&lt;Paste&gt;&gt;</a></code> \| <code>Promise.&lt;null&gt;</code>
266
+ Fetches paste data for a specific account (email address).
267
+
268
+ ***Warning (July 18, 2019):***
269
+
270
+ `haveibeenpwned.com` now requires an API key from
271
+ https://haveibeenpwned.com/API/Key for the `pasteaccount` endpoint. The
272
+ `apiKey` option here is not explicitly required, but direct requests made
273
+ without it (that is, without specifying a `baseUrl` to a proxy that inserts a
274
+ valid API key on your behalf) will fail.
275
+
276
+ **Kind**: global function
277
+ **Returns**: <code><a href="#paste--object">Promise.&lt;Array.&lt;Paste&gt;&gt;</a></code> \| <code>Promise.&lt;null&gt;</code> - a Promise which resolves to an
278
+ array of paste objects (or null if no pastes were found), or rejects with an
279
+ Error
280
+
281
+ | Param | Type | Description |
282
+ | --- | --- | --- |
283
+ | email | <code>string</code> | the email address to query |
284
+ | [options] | <code>object</code> | a configuration object |
285
+ | [options.apiKey] | <code>string</code> | an API key from https://haveibeenpwned.com/API/Key |
286
+ | [options.baseUrl] | <code>string</code> | a custom base URL for the haveibeenpwned.com API endpoints (default: `https://haveibeenpwned.com/api/v3`) |
287
+ | [options.userAgent] | <code>string</code> | a custom string to send as the User-Agent field in the request headers (default: `hibp <version>`) |
288
+
289
+ **Example**
290
+ ```js
291
+ pasteAccount('foo@bar.com', { apiKey: 'my-api-key' })
292
+ .then(data => {
293
+ if (data) {
294
+ // ...
295
+ } else {
296
+ // ...
297
+ }
298
+ })
299
+ .catch(err => {
300
+ // ...
301
+ });
302
+ ```
303
+ <a name="pwnedPassword"></a>
304
+
305
+ ## pwnedPassword(password, [options]) ⇒ <code>Promise.&lt;number&gt;</code>
306
+ Fetches the number of times the the given password has been exposed in a
307
+ breach (0 indicating no exposure). The password is given in plain text, but
308
+ only the first 5 characters of its SHA-1 hash will be submitted to the API.
309
+
310
+ **Kind**: global function
311
+ **Returns**: <code>Promise.&lt;number&gt;</code> - a Promise which resolves to the number of times
312
+ the password has been exposed in a breach, or rejects with an Error
313
+ **See**: https://haveibeenpwned.com/api/v3#PwnedPasswords
314
+
315
+ | Param | Type | Description |
316
+ | --- | --- | --- |
317
+ | password | <code>string</code> | a password in plain text |
318
+ | [options] | <code>object</code> | a configuration object |
319
+ | [options.baseUrl] | <code>string</code> | a custom base URL for the pwnedpasswords.com API endpoints (default: `https://api.pwnedpasswords.com`) |
320
+ | [options.userAgent] | <code>string</code> | a custom string to send as the User-Agent field in the request headers (default: `hibp <version>`) |
321
+
322
+ **Example**
323
+ ```js
324
+ pwnedPassword('f00b4r')
325
+ .then(numPwns => {
326
+ // truthy check or numeric condition
327
+ if (numPwns) {
328
+ // ...
329
+ } else {
330
+ // ...
331
+ }
332
+ })
333
+ .catch(err => {
334
+ // ...
335
+ });
336
+ ```
337
+ <a name="pwnedPasswordRange"></a>
338
+
339
+ ## pwnedPasswordRange(prefix, [options]) ⇒ [<code>Promise.&lt;PwnedPasswordSuffixes&gt;</code>](#PwnedPasswordSuffixes)
340
+ Fetches the SHA-1 hash suffixes for the given 5-character SHA-1 hash prefix.
341
+
342
+ When a password hash with the same first 5 characters is found in the Pwned
343
+ Passwords repository, the API will respond with an HTTP 200 and include the
344
+ suffix of every hash beginning with the specified prefix, followed by a count
345
+ of how many times it appears in the data set. This function parses the
346
+ response and returns a more structured format.
347
+
348
+ **Kind**: global function
349
+ **Returns**: [<code>Promise.&lt;PwnedPasswordSuffixes&gt;</code>](#PwnedPasswordSuffixes) - a Promise which resolves to an
350
+ object mapping the `suffix` that when matched with the prefix composes the
351
+ complete hash, to the `count` of how many times it appears in the breached
352
+ password data set, or rejects with an Error
353
+ **See**: https://haveibeenpwned.com/api/v3#SearchingPwnedPasswordsByRange
354
+
355
+ | Param | Type | Description |
356
+ | --- | --- | --- |
357
+ | prefix | <code>string</code> | the first 5 characters of a SHA-1 password hash (case insensitive) |
358
+ | [options] | <code>object</code> | a configuration object |
359
+ | [options.baseUrl] | <code>string</code> | a custom base URL for the pwnedpasswords.com API endpoints (default: `https://api.pwnedpasswords.com`) |
360
+ | [options.userAgent] | <code>string</code> | a custom string to send as the User-Agent field in the request headers (default: `hibp <version>`) |
361
+
362
+ **Example**
363
+ ```js
364
+ pwnedPasswordRange('5BAA6')
365
+ .then(results => {
366
+ // results will have the following shape:
367
+ // {
368
+ // "003D68EB55068C33ACE09247EE4C639306B": 3,
369
+ // "012C192B2F16F82EA0EB9EF18D9D539B0DD": 1,
370
+ // ...
371
+ // }
372
+ })
373
+ ```
374
+ **Example**
375
+ ```js
376
+ const suffix = '1E4C9B93F3F0682250B6CF8331B7EE68FD8';
377
+ pwnedPasswordRange('5BAA6')
378
+ .then(results => (results[suffix] || 0))
379
+ .catch(err => {
380
+ // ...
381
+ });
382
+ ```
383
+ <a name="search"></a>
384
+
385
+ ## search(account, [breachOptions]) ⇒ [<code>Promise.&lt;SearchResults&gt;</code>](#SearchResults)
386
+ Fetches all breaches and all pastes associated with the provided account
387
+ (email address or username). Note that the remote API does not support
388
+ querying pastes by username (only email addresses), so in the event the
389
+ provided account is not a valid email address, only breach data is queried
390
+ and the "pastes" field of the resulting object will always be null. This is
391
+ exactly how searching via the current web interface behaves, which this
392
+ convenience method is designed to mimic.
393
+
394
+ ***Warning (July 18, 2019):***
395
+
396
+ `haveibeenpwned.com` now requires an API key from
397
+ https://haveibeenpwned.com/API/Key for the `breachedaccount` and
398
+ `pasteaccount` endpoints. The `apiKey` option here is not explicitly
399
+ required, but direct requests made without it (that is, without specifying a
400
+ `baseUrl` to a proxy that inserts a valid API key on your behalf) will fail.
401
+
402
+ **Kind**: global function
403
+ **Returns**: [<code>Promise.&lt;SearchResults&gt;</code>](#SearchResults) - a Promise which resolves to an object
404
+ containing a "breaches" key (which can be null or an array of breach objects)
405
+ and a "pastes" key (which can be null or an array of paste objects), or
406
+ rejects with an Error
407
+ **See**: https://haveibeenpwned.com/
408
+
409
+ | Param | Type | Description |
410
+ | --- | --- | --- |
411
+ | account | <code>string</code> | an email address or username |
412
+ | [breachOptions] | <code>object</code> | a configuration object pertaining to breach queries |
413
+ | [breachOptions.apiKey] | <code>string</code> | an API key from https://haveibeenpwned.com/API/Key |
414
+ | [breachOptions.domain] | <code>string</code> | a domain by which to filter the results (default: all domains) |
415
+ | [breachOptions.truncate] | <code>boolean</code> | truncate the results to only include the name of each breach (default: true) |
416
+ | [breachOptions.baseUrl] | <code>string</code> | a custom base URL for the haveibeenpwned.com API endpoints (default: `https://haveibeenpwned.com/api/v3`) |
417
+ | [breachOptions.userAgent] | <code>string</code> | a custom string to send as the User-Agent field in the request headers (default: `hibp <version>`) |
418
+
419
+ **Example**
420
+ ```js
421
+ search('foo', { apiKey: 'my-api-key' })
422
+ .then(data => {
423
+ if (data.breaches || data.pastes) {
424
+ // ...
425
+ } else {
426
+ // ...
427
+ }
428
+ })
429
+ .catch(err => {
430
+ // ...
431
+ });
432
+ ```
433
+ **Example**
434
+ ```js
435
+ search('nobody@nowhere.com', { apiKey: 'my-api-key', truncate: false })
436
+ .then(data => {
437
+ if (data.breaches || data.pastes) {
438
+ // ...
439
+ } else {
440
+ // ...
441
+ }
442
+ })
443
+ .catch(err => {
444
+ // ...
445
+ });
446
+ ```
447
+ <a name="Breach"></a>
448
+
449
+ ## Breach : <code>object</code>
450
+ An object representing a breach.
451
+
452
+ **Kind**: global typedef
453
+ **Properties**
454
+
455
+ | Name | Type |
456
+ | --- | --- |
457
+ | Name | <code>string</code> |
458
+ | Title | <code>string</code> |
459
+ | Domain | <code>string</code> |
460
+ | BreachDate | <code>string</code> |
461
+ | AddedDate | <code>string</code> |
462
+ | ModifiedDate | <code>string</code> |
463
+ | PwnCount | <code>number</code> |
464
+ | Description | <code>string</code> |
465
+ | LogoPath | <code>string</code> |
466
+ | DataClasses | <code>Array.&lt;string&gt;</code> |
467
+ | IsVerified | <code>boolean</code> |
468
+ | IsFabricated | <code>boolean</code> |
469
+ | IsSensitive | <code>boolean</code> |
470
+ | IsRetired | <code>boolean</code> |
471
+ | IsSpamList | <code>boolean</code> |
472
+
473
+ <a name="Paste"></a>
474
+
475
+ ## Paste : <code>object</code>
476
+ An object representing a paste.
477
+
478
+ **Kind**: global typedef
479
+ **Properties**
480
+
481
+ | Name | Type |
482
+ | --- | --- |
483
+ | Id | <code>string</code> |
484
+ | Source | <code>string</code> |
485
+ | Title | <code>string</code> |
486
+ | Date | <code>string</code> |
487
+ | EmailCount | <code>number</code> |
488
+
489
+ <a name="PwnedPasswordSuffixes"></a>
490
+
491
+ ## PwnedPasswordSuffixes : <code>Object.&lt;string, number&gt;</code>
492
+ An object mapping an exposed password hash suffix (corresponding to a given
493
+ hash prefix) to how many times it occurred in the Pwned Passwords repository.
494
+
495
+ **Kind**: global typedef
496
+ <a name="SearchResults"></a>
497
+
498
+ ## SearchResults : <code>object</code>
499
+ An object representing search results.
500
+
501
+ **Kind**: global typedef
502
+ **Properties**
503
+
504
+ | Name | Type |
505
+ | --- | --- |
506
+ | breaches | [<code>Array.&lt;Breach&gt;</code>](#breach--object) \| <code>null</code> |
507
+ | pastes | [<code>Array.&lt;Paste&gt;</code>](#Paste) \| <code>null</code> |
508
+
package/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # Change Log
2
+
3
+ ## 11.1.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#365](https://github.com/wKovacs64/hibp/pull/365) [`ec26254`](https://github.com/wKovacs64/hibp/commit/ec2625486c8500484befa4d4d203bb820a338967) Thanks [@wKovacs64](https://github.com/wKovacs64)! - Add `types` to the `exports` map in `package.json` to fix ESM consumers.
package/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Justin R. Hall
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a
6
+ copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included
14
+ in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17
+ OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.