hibp 0.0.0-dev.0e634825

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 (81) hide show
  1. package/API.md +508 -0
  2. package/CHANGELOG.md +17 -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/api/web-fetch.js +14 -0
  23. package/dist/cjs/api/web-fetch.js.map +1 -0
  24. package/dist/cjs/breach.js +55 -0
  25. package/dist/cjs/breach.js.map +1 -0
  26. package/dist/cjs/breachedAccount.js +101 -0
  27. package/dist/cjs/breachedAccount.js.map +1 -0
  28. package/dist/cjs/breaches.js +55 -0
  29. package/dist/cjs/breaches.js.map +1 -0
  30. package/dist/cjs/dataClasses.js +34 -0
  31. package/dist/cjs/dataClasses.js.map +1 -0
  32. package/dist/cjs/hibp.d.ts +480 -0
  33. package/dist/cjs/hibp.js +21 -0
  34. package/dist/cjs/hibp.js.map +1 -0
  35. package/dist/cjs/package.json.js +7 -0
  36. package/dist/cjs/package.json.js.map +1 -0
  37. package/dist/cjs/pasteAccount.js +59 -0
  38. package/dist/cjs/pasteAccount.js.map +1 -0
  39. package/dist/cjs/pwnedPassword.js +45 -0
  40. package/dist/cjs/pwnedPassword.js.map +1 -0
  41. package/dist/cjs/pwnedPasswordRange.js +63 -0
  42. package/dist/cjs/pwnedPasswordRange.js.map +1 -0
  43. package/dist/cjs/search.js +97 -0
  44. package/dist/cjs/search.js.map +1 -0
  45. package/dist/esm/api/haveibeenpwned/fetchFromApi.mjs +104 -0
  46. package/dist/esm/api/haveibeenpwned/fetchFromApi.mjs.map +1 -0
  47. package/dist/esm/api/haveibeenpwned/index.mjs +2 -0
  48. package/dist/esm/api/haveibeenpwned/index.mjs.map +1 -0
  49. package/dist/esm/api/haveibeenpwned/responses.mjs +71 -0
  50. package/dist/esm/api/haveibeenpwned/responses.mjs.map +1 -0
  51. package/dist/esm/api/pwnedpasswords/fetchFromApi.mjs +42 -0
  52. package/dist/esm/api/pwnedpasswords/fetchFromApi.mjs.map +1 -0
  53. package/dist/esm/api/pwnedpasswords/index.mjs +2 -0
  54. package/dist/esm/api/pwnedpasswords/index.mjs.map +1 -0
  55. package/dist/esm/api/pwnedpasswords/responses.mjs +17 -0
  56. package/dist/esm/api/pwnedpasswords/responses.mjs.map +1 -0
  57. package/dist/esm/api/web-fetch.mjs +10 -0
  58. package/dist/esm/api/web-fetch.mjs.map +1 -0
  59. package/dist/esm/breach.mjs +53 -0
  60. package/dist/esm/breach.mjs.map +1 -0
  61. package/dist/esm/breachedAccount.mjs +99 -0
  62. package/dist/esm/breachedAccount.mjs.map +1 -0
  63. package/dist/esm/breaches.mjs +53 -0
  64. package/dist/esm/breaches.mjs.map +1 -0
  65. package/dist/esm/dataClasses.mjs +32 -0
  66. package/dist/esm/dataClasses.mjs.map +1 -0
  67. package/dist/esm/hibp.d.mts +480 -0
  68. package/dist/esm/hibp.mjs +10 -0
  69. package/dist/esm/hibp.mjs.map +1 -0
  70. package/dist/esm/package.json.mjs +4 -0
  71. package/dist/esm/package.json.mjs.map +1 -0
  72. package/dist/esm/pasteAccount.mjs +57 -0
  73. package/dist/esm/pasteAccount.mjs.map +1 -0
  74. package/dist/esm/pwnedPassword.mjs +43 -0
  75. package/dist/esm/pwnedPassword.mjs.map +1 -0
  76. package/dist/esm/pwnedPasswordRange.mjs +61 -0
  77. package/dist/esm/pwnedPasswordRange.mjs.map +1 -0
  78. package/dist/esm/search.mjs +95 -0
  79. package/dist/esm/search.mjs.map +1 -0
  80. package/example/runkit.js +16 -0
  81. package/package.json +138 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"breachedAccount.mjs","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,eAAeA,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,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,53 @@
1
+ import { fetchFromApi } from './api/haveibeenpwned/fetchFromApi.mjs';
2
+
3
+ /**
4
+ * Fetches all breach events in the system.
5
+ *
6
+ * @param {object} [options] a configuration object
7
+ * @param {string} [options.domain] a domain by which to filter the results
8
+ * (default: all domains)
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<Breach[]>} a Promise which resolves to an array of breach
15
+ * objects (an empty array if no breaches were found), or rejects with an Error
16
+ * @example
17
+ * breaches()
18
+ * .then(data => {
19
+ * if (data) {
20
+ * // ...
21
+ * } else {
22
+ * // ...
23
+ * }
24
+ * })
25
+ * .catch(err => {
26
+ * // ...
27
+ * });
28
+ * @example
29
+ * breaches({ domain: 'adobe.com' })
30
+ * .then(data => {
31
+ * if (data) {
32
+ * // ...
33
+ * } else {
34
+ * // ...
35
+ * }
36
+ * })
37
+ * .catch(err => {
38
+ * // ...
39
+ * });
40
+ */
41
+ function breaches(options = {}) {
42
+ const endpoint = '/breaches?';
43
+ const params = [];
44
+ if (options.domain) {
45
+ params.push(`domain=${encodeURIComponent(options.domain)}`);
46
+ }
47
+ return fetchFromApi(`${endpoint}${params.join('&')}`, {
48
+ baseUrl: options.baseUrl,
49
+ userAgent: options.userAgent
50
+ });
51
+ }
52
+ export { breaches };
53
+ //# sourceMappingURL=breaches.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"breaches.mjs","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,QAAQA,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,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,32 @@
1
+ import { fetchFromApi } from './api/haveibeenpwned/fetchFromApi.mjs';
2
+
3
+ /**
4
+ * Fetches all data classes in the system.
5
+ *
6
+ * @param {object} [options] a configuration object
7
+ * @param {string} [options.baseUrl] a custom base URL for the
8
+ * haveibeenpwned.com API endpoints (default:
9
+ * `https://haveibeenpwned.com/api/v3`)
10
+ * @param {string} [options.userAgent] a custom string to send as the User-Agent
11
+ * field in the request headers (default: `hibp <version>`)
12
+ * @returns {(Promise<string[]> | Promise<null>)} a Promise which resolves to an
13
+ * array of strings (or null if no data classes were found), or rejects with an
14
+ * Error
15
+ * @example
16
+ * dataClasses()
17
+ * .then(data => {
18
+ * if (data) {
19
+ * // ...
20
+ * } else {
21
+ * // ...
22
+ * }
23
+ * })
24
+ * .catch(err => {
25
+ * // ...
26
+ * });
27
+ */
28
+ function dataClasses(options = {}) {
29
+ return fetchFromApi('/dataclasses', options);
30
+ }
31
+ export { dataClasses };
32
+ //# sourceMappingURL=dataClasses.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dataClasses.mjs","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,WAAWA,CACzBC,OAAA,GAAoD,EAAE,EAAA;EAEtD,OAAOC,YAAY,CAAC,cAAc,EAAED,OAAO,CAA6B;AAC1E;"}
@@ -0,0 +1,480 @@
1
+ // Generated by dts-bundle-generator v7.2.0
2
+
3
+ //
4
+ // Data Models from the API
5
+ //
6
+ export interface Breach {
7
+ Name: string;
8
+ Title: string;
9
+ Domain: string;
10
+ BreachDate: string;
11
+ AddedDate: string;
12
+ ModifiedDate: string;
13
+ PwnCount: number;
14
+ Description: string;
15
+ LogoPath: string;
16
+ DataClasses: string[];
17
+ IsVerified: boolean;
18
+ IsFabricated: boolean;
19
+ IsSensitive: boolean;
20
+ IsRetired: boolean;
21
+ IsSpamList: boolean;
22
+ }
23
+ export interface Paste {
24
+ Id: string;
25
+ Source: string;
26
+ Title: string;
27
+ Date: string;
28
+ EmailCount: number;
29
+ }
30
+ /**
31
+ * An object representing a breach.
32
+ *
33
+ * @typedef {object} Breach
34
+ * @property {string} Name
35
+ * @property {string} Title
36
+ * @property {string} Domain
37
+ * @property {string} BreachDate
38
+ * @property {string} AddedDate
39
+ * @property {string} ModifiedDate
40
+ * @property {number} PwnCount
41
+ * @property {string} Description
42
+ * @property {string} LogoPath
43
+ * @property {string[]} DataClasses
44
+ * @property {boolean} IsVerified
45
+ * @property {boolean} IsFabricated
46
+ * @property {boolean} IsSensitive
47
+ * @property {boolean} IsRetired
48
+ * @property {boolean} IsSpamList
49
+ */
50
+ /**
51
+ * Fetches data for a specific breach event.
52
+ *
53
+ * @param {string} breachName the name of a breach in the system
54
+ * @param {object} [options] a configuration object
55
+ * @param {string} [options.baseUrl] a custom base URL for the
56
+ * haveibeenpwned.com API endpoints (default:
57
+ * `https://haveibeenpwned.com/api/v3`)
58
+ * @param {string} [options.userAgent] a custom string to send as the User-Agent
59
+ * field in the request headers (default: `hibp <version>`)
60
+ * @returns {(Promise<Breach>|Promise<null>)} a Promise which resolves to an
61
+ * object representing a breach (or null if no breach was found), or rejects
62
+ * with an Error
63
+ * @example
64
+ * breach('Adobe')
65
+ * .then(data => {
66
+ * if (data) {
67
+ * // ...
68
+ * } else {
69
+ * // ...
70
+ * }
71
+ * })
72
+ * .catch(err => {
73
+ * // ...
74
+ * });
75
+ */
76
+ export declare function breach(breachName: string, options?: {
77
+ baseUrl?: string;
78
+ userAgent?: string;
79
+ }): Promise<Breach | null>;
80
+ /**
81
+ * Fetches breach data for a specific account.
82
+ *
83
+ * ***Warning (July 18, 2019):***
84
+ *
85
+ * `haveibeenpwned.com` now requires an API key from
86
+ * https://haveibeenpwned.com/API/Key for the `breachedaccount` endpoint. The
87
+ * `apiKey` option here is not explicitly required, but direct requests made
88
+ * without it (that is, without specifying a `baseUrl` to a proxy that inserts a
89
+ * valid API key on your behalf) will fail.
90
+ *
91
+ * @param {string} account a username or email address
92
+ * @param {object} [options] a configuration object
93
+ * @param {string} [options.apiKey] an API key from
94
+ * https://haveibeenpwned.com/API/Key (default: undefined)
95
+ * @param {string} [options.domain] a domain by which to filter the results
96
+ * (default: all domains)
97
+ * @param {boolean} [options.includeUnverified] include "unverified" breaches in
98
+ * the results (default: true)
99
+ * @param {boolean} [options.truncate] truncate the results to only include
100
+ * the name of each breach (default: true)
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 {string} [options.userAgent] a custom string to send as the User-Agent
105
+ * field in the request headers (default: `hibp <version>`)
106
+ * @returns {(Promise<Breach[]> | Promise<null>)} a Promise which resolves to an
107
+ * array of breach objects (or null if no breaches were found), or rejects with
108
+ * an Error
109
+ * @example
110
+ * breachedAccount('foo', { apiKey: 'my-api-key' })
111
+ * .then(data => {
112
+ * if (data) {
113
+ * // ...
114
+ * } else {
115
+ * // ...
116
+ * }
117
+ * })
118
+ * .catch(err => {
119
+ * // ...
120
+ * });
121
+ * @example
122
+ * breachedAccount('bar', {
123
+ * includeUnverified: false,
124
+ * baseUrl: 'https://my-hibp-proxy:8080',
125
+ * })
126
+ * .then(data => {
127
+ * if (data) {
128
+ * // ...
129
+ * } else {
130
+ * // ...
131
+ * }
132
+ * })
133
+ * .catch(err => {
134
+ * // ...
135
+ * });
136
+ * @example
137
+ * breachedAccount('baz', {
138
+ * apiKey: 'my-api-key',
139
+ * domain: 'adobe.com',
140
+ * truncate: false,
141
+ * userAgent: 'my-app 1.0'
142
+ * })
143
+ * .then(data => {
144
+ * if (data) {
145
+ * // ...
146
+ * } else {
147
+ * // ...
148
+ * }
149
+ * })
150
+ * .catch(err => {
151
+ * // ...
152
+ * });
153
+ */
154
+ export declare function breachedAccount(account: string, options?: {
155
+ apiKey?: string;
156
+ domain?: string;
157
+ includeUnverified?: boolean;
158
+ truncate?: boolean;
159
+ baseUrl?: string;
160
+ userAgent?: string;
161
+ }): Promise<Breach[] | null>;
162
+ /**
163
+ * Fetches all breach events in the system.
164
+ *
165
+ * @param {object} [options] a configuration object
166
+ * @param {string} [options.domain] a domain by which to filter the results
167
+ * (default: all domains)
168
+ * @param {string} [options.baseUrl] a custom base URL for the
169
+ * haveibeenpwned.com API endpoints (default:
170
+ * `https://haveibeenpwned.com/api/v3`)
171
+ * @param {string} [options.userAgent] a custom string to send as the User-Agent
172
+ * field in the request headers (default: `hibp <version>`)
173
+ * @returns {Promise<Breach[]>} a Promise which resolves to an array of breach
174
+ * objects (an empty array if no breaches were found), or rejects with an Error
175
+ * @example
176
+ * breaches()
177
+ * .then(data => {
178
+ * if (data) {
179
+ * // ...
180
+ * } else {
181
+ * // ...
182
+ * }
183
+ * })
184
+ * .catch(err => {
185
+ * // ...
186
+ * });
187
+ * @example
188
+ * breaches({ domain: 'adobe.com' })
189
+ * .then(data => {
190
+ * if (data) {
191
+ * // ...
192
+ * } else {
193
+ * // ...
194
+ * }
195
+ * })
196
+ * .catch(err => {
197
+ * // ...
198
+ * });
199
+ */
200
+ export declare function breaches(options?: {
201
+ domain?: string;
202
+ baseUrl?: string;
203
+ userAgent?: string;
204
+ }): Promise<Breach[]>;
205
+ /**
206
+ * Fetches all data classes in the system.
207
+ *
208
+ * @param {object} [options] a configuration object
209
+ * @param {string} [options.baseUrl] a custom base URL for the
210
+ * haveibeenpwned.com API endpoints (default:
211
+ * `https://haveibeenpwned.com/api/v3`)
212
+ * @param {string} [options.userAgent] a custom string to send as the User-Agent
213
+ * field in the request headers (default: `hibp <version>`)
214
+ * @returns {(Promise<string[]> | Promise<null>)} a Promise which resolves to an
215
+ * array of strings (or null if no data classes were found), or rejects with an
216
+ * Error
217
+ * @example
218
+ * dataClasses()
219
+ * .then(data => {
220
+ * if (data) {
221
+ * // ...
222
+ * } else {
223
+ * // ...
224
+ * }
225
+ * })
226
+ * .catch(err => {
227
+ * // ...
228
+ * });
229
+ */
230
+ export declare function dataClasses(options?: {
231
+ baseUrl?: string;
232
+ userAgent?: string;
233
+ }): Promise<string[] | null>;
234
+ /**
235
+ * An object representing a paste.
236
+ *
237
+ * @typedef {object} Paste
238
+ * @property {string} Id
239
+ * @property {string} Source
240
+ * @property {string} Title
241
+ * @property {string} Date
242
+ * @property {number} EmailCount
243
+ */
244
+ /**
245
+ * Fetches paste data for a specific account (email address).
246
+ *
247
+ * ***Warning (July 18, 2019):***
248
+ *
249
+ * `haveibeenpwned.com` now requires an API key from
250
+ * https://haveibeenpwned.com/API/Key for the `pasteaccount` endpoint. The
251
+ * `apiKey` option here is not explicitly required, but direct requests made
252
+ * without it (that is, without specifying a `baseUrl` to a proxy that inserts a
253
+ * valid API key on your behalf) will fail.
254
+ *
255
+ * @param {string} email the email address to query
256
+ * @param {object} [options] a configuration object
257
+ * @param {string} [options.apiKey] an API key from
258
+ * https://haveibeenpwned.com/API/Key
259
+ * @param {string} [options.baseUrl] a custom base URL for the
260
+ * haveibeenpwned.com API endpoints (default:
261
+ * `https://haveibeenpwned.com/api/v3`)
262
+ * @param {string} [options.userAgent] a custom string to send as the User-Agent
263
+ * field in the request headers (default: `hibp <version>`)
264
+ * @returns {(Promise<Paste[]> | Promise<null>)} a Promise which resolves to an
265
+ * array of paste objects (or null if no pastes were found), or rejects with an
266
+ * Error
267
+ * @example
268
+ * pasteAccount('foo@bar.com', { apiKey: 'my-api-key' })
269
+ * .then(data => {
270
+ * if (data) {
271
+ * // ...
272
+ * } else {
273
+ * // ...
274
+ * }
275
+ * })
276
+ * .catch(err => {
277
+ * // ...
278
+ * });
279
+ */
280
+ export declare function pasteAccount(email: string, options?: {
281
+ apiKey?: string;
282
+ baseUrl?: string;
283
+ userAgent?: string;
284
+ }): Promise<Paste[] | null>;
285
+ /**
286
+ * Fetches the number of times the the given password has been exposed in a
287
+ * breach (0 indicating no exposure). The password is given in plain text, but
288
+ * only the first 5 characters of its SHA-1 hash will be submitted to the API.
289
+ *
290
+ * @param {string} password a password in plain text
291
+ * @param {object} [options] a configuration object
292
+ * @param {string} [options.baseUrl] a custom base URL for the
293
+ * pwnedpasswords.com API endpoints (default: `https://api.pwnedpasswords.com`)
294
+ * @param {string} [options.userAgent] a custom string to send as the User-Agent
295
+ * field in the request headers (default: `hibp <version>`)
296
+ * @returns {Promise<number>} a Promise which resolves to the number of times
297
+ * the password has been exposed in a breach, or rejects with an Error
298
+ * @example
299
+ * pwnedPassword('f00b4r')
300
+ * .then(numPwns => {
301
+ * // truthy check or numeric condition
302
+ * if (numPwns) {
303
+ * // ...
304
+ * } else {
305
+ * // ...
306
+ * }
307
+ * })
308
+ * .catch(err => {
309
+ * // ...
310
+ * });
311
+ * @see https://haveibeenpwned.com/api/v3#PwnedPasswords
312
+ */
313
+ export declare function pwnedPassword(password: string, options?: {
314
+ baseUrl?: string;
315
+ userAgent?: string;
316
+ }): Promise<number>;
317
+ export interface PwnedPasswordSuffixes {
318
+ [suffix: string]: number;
319
+ }
320
+ /**
321
+ * An object mapping an exposed password hash suffix (corresponding to a given
322
+ * hash prefix) to how many times it occurred in the Pwned Passwords repository.
323
+ *
324
+ * @typedef {Object.<string, number>} PwnedPasswordSuffixes
325
+ */
326
+ /**
327
+ * Fetches the SHA-1 hash suffixes for the given 5-character SHA-1 hash prefix.
328
+ *
329
+ * When a password hash with the same first 5 characters is found in the Pwned
330
+ * Passwords repository, the API will respond with an HTTP 200 and include the
331
+ * suffix of every hash beginning with the specified prefix, followed by a count
332
+ * of how many times it appears in the data set. This function parses the
333
+ * response and returns a more structured format.
334
+ *
335
+ * @param {string} prefix the first 5 characters of a SHA-1 password hash (case
336
+ * insensitive)
337
+ * @param {object} [options] a configuration object
338
+ * @param {string} [options.baseUrl] a custom base URL for the
339
+ * pwnedpasswords.com API endpoints (default: `https://api.pwnedpasswords.com`)
340
+ * @param {string} [options.userAgent] a custom string to send as the User-Agent
341
+ * field in the request headers (default: `hibp <version>`)
342
+ * @returns {Promise<PwnedPasswordSuffixes>} a Promise which resolves to an
343
+ * object mapping the `suffix` that when matched with the prefix composes the
344
+ * complete hash, to the `count` of how many times it appears in the breached
345
+ * password data set, or rejects with an Error
346
+ *
347
+ * @example
348
+ * pwnedPasswordRange('5BAA6')
349
+ * .then(results => {
350
+ * // results will have the following shape:
351
+ * // {
352
+ * // "003D68EB55068C33ACE09247EE4C639306B": 3,
353
+ * // "012C192B2F16F82EA0EB9EF18D9D539B0DD": 1,
354
+ * // ...
355
+ * // }
356
+ * })
357
+ * @example
358
+ * const suffix = '1E4C9B93F3F0682250B6CF8331B7EE68FD8';
359
+ * pwnedPasswordRange('5BAA6')
360
+ * .then(results => (results[suffix] || 0))
361
+ * .catch(err => {
362
+ * // ...
363
+ * });
364
+ * @see https://haveibeenpwned.com/api/v3#SearchingPwnedPasswordsByRange
365
+ */
366
+ export declare function pwnedPasswordRange(prefix: string, options?: {
367
+ baseUrl?: string;
368
+ userAgent?: string;
369
+ }): Promise<PwnedPasswordSuffixes>;
370
+ export interface SearchResults {
371
+ breaches: Breach[] | null;
372
+ pastes: Paste[] | null;
373
+ }
374
+ /**
375
+ * An object representing search results.
376
+ *
377
+ * @typedef {object} SearchResults
378
+ * @property {(Breach[] | null)} breaches
379
+ * @property {(Paste[] | null)} pastes
380
+ */
381
+ /**
382
+ * Fetches all breaches and all pastes associated with the provided account
383
+ * (email address or username). Note that the remote API does not support
384
+ * querying pastes by username (only email addresses), so in the event the
385
+ * provided account is not a valid email address, only breach data is queried
386
+ * and the "pastes" field of the resulting object will always be null. This is
387
+ * exactly how searching via the current web interface behaves, which this
388
+ * convenience method is designed to mimic.
389
+ *
390
+ * ***Warning (July 18, 2019):***
391
+ *
392
+ * `haveibeenpwned.com` now requires an API key from
393
+ * https://haveibeenpwned.com/API/Key for the `breachedaccount` and
394
+ * `pasteaccount` endpoints. The `apiKey` option here is not explicitly
395
+ * required, but direct requests made without it (that is, without specifying a
396
+ * `baseUrl` to a proxy that inserts a valid API key on your behalf) will fail.
397
+ *
398
+ * @param {string} account an email address or username
399
+ * @param {object} [breachOptions] a configuration object pertaining to breach
400
+ * queries
401
+ * @param {string} [breachOptions.apiKey] an API key from
402
+ * https://haveibeenpwned.com/API/Key
403
+ * @param {string} [breachOptions.domain] a domain by which to filter the
404
+ * results (default: all domains)
405
+ * @param {boolean} [breachOptions.truncate] truncate the results to only
406
+ * include the name of each breach (default: true)
407
+ * @param {string} [breachOptions.baseUrl] a custom base URL for the
408
+ * haveibeenpwned.com API endpoints (default:
409
+ * `https://haveibeenpwned.com/api/v3`)
410
+ * @param {string} [breachOptions.userAgent] a custom string to send as the
411
+ * User-Agent field in the request headers (default: `hibp <version>`)
412
+ * @returns {Promise<SearchResults>} a Promise which resolves to an object
413
+ * containing a "breaches" key (which can be null or an array of breach objects)
414
+ * and a "pastes" key (which can be null or an array of paste objects), or
415
+ * rejects with an Error
416
+ * @example
417
+ * search('foo', { apiKey: 'my-api-key' })
418
+ * .then(data => {
419
+ * if (data.breaches || data.pastes) {
420
+ * // ...
421
+ * } else {
422
+ * // ...
423
+ * }
424
+ * })
425
+ * .catch(err => {
426
+ * // ...
427
+ * });
428
+ * @example
429
+ * search('nobody@nowhere.com', { apiKey: 'my-api-key', truncate: false })
430
+ * .then(data => {
431
+ * if (data.breaches || data.pastes) {
432
+ * // ...
433
+ * } else {
434
+ * // ...
435
+ * }
436
+ * })
437
+ * .catch(err => {
438
+ * // ...
439
+ * });
440
+ *
441
+ * @see https://haveibeenpwned.com/
442
+ */
443
+ export declare function search(account: string, breachOptions?: {
444
+ apiKey?: string;
445
+ domain?: string;
446
+ truncate?: boolean;
447
+ baseUrl?: string;
448
+ userAgent?: string;
449
+ }): Promise<SearchResults>;
450
+ /**
451
+ * Custom error thrown when the haveibeenpwned.com API responds with 429 Too
452
+ * Many Requests. See the `retryAfterSeconds` property for the number of seconds
453
+ * to wait before attempting the request again.
454
+ *
455
+ * @see https://haveibeenpwned.com/API/v3#RateLimiting
456
+ */
457
+ export declare class RateLimitError extends Error {
458
+ /**
459
+ * The number of seconds to wait before attempting the request again. May be
460
+ * `undefined` if the API does not provide a `retry-after` header, but this
461
+ * should never happen.
462
+ */
463
+ retryAfterSeconds: number | undefined;
464
+ constructor(retryAfter: ReturnType<Headers["get"]>, message: string | undefined, options?: ErrorOptions);
465
+ }
466
+ export interface HIBP {
467
+ breach: typeof breach;
468
+ breachedAccount: typeof breachedAccount;
469
+ breaches: typeof breaches;
470
+ dataClasses: typeof dataClasses;
471
+ pasteAccount: typeof pasteAccount;
472
+ pwnedPassword: typeof pwnedPassword;
473
+ pwnedPasswordRange: typeof pwnedPasswordRange;
474
+ search: typeof search;
475
+ RateLimitError: typeof RateLimitError;
476
+ }
477
+
478
+ export as namespace hibp;
479
+
480
+ export {};
@@ -0,0 +1,10 @@
1
+ export { breach } from './breach.mjs';
2
+ export { breachedAccount } from './breachedAccount.mjs';
3
+ export { breaches } from './breaches.mjs';
4
+ export { dataClasses } from './dataClasses.mjs';
5
+ export { pasteAccount } from './pasteAccount.mjs';
6
+ export { pwnedPassword } from './pwnedPassword.mjs';
7
+ export { pwnedPasswordRange } from './pwnedPasswordRange.mjs';
8
+ export { search } from './search.mjs';
9
+ export { RateLimitError } from './api/haveibeenpwned/fetchFromApi.mjs';
10
+ //# sourceMappingURL=hibp.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hibp.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;"}
@@ -0,0 +1,4 @@
1
+ const name = "hibp";
2
+ const version = "0.0.0-dev.0e634825";
3
+ export { name, version };
4
+ //# sourceMappingURL=package.json.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"package.json.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
@@ -0,0 +1,57 @@
1
+ import { fetchFromApi } from './api/haveibeenpwned/fetchFromApi.mjs';
2
+
3
+ /**
4
+ * An object representing a paste.
5
+ *
6
+ * @typedef {object} Paste
7
+ * @property {string} Id
8
+ * @property {string} Source
9
+ * @property {string} Title
10
+ * @property {string} Date
11
+ * @property {number} EmailCount
12
+ */
13
+ /**
14
+ * Fetches paste data for a specific account (email address).
15
+ *
16
+ * ***Warning (July 18, 2019):***
17
+ *
18
+ * `haveibeenpwned.com` now requires an API key from
19
+ * https://haveibeenpwned.com/API/Key for the `pasteaccount` endpoint. The
20
+ * `apiKey` option here is not explicitly required, but direct requests made
21
+ * without it (that is, without specifying a `baseUrl` to a proxy that inserts a
22
+ * valid API key on your behalf) will fail.
23
+ *
24
+ * @param {string} email the email address to query
25
+ * @param {object} [options] a configuration object
26
+ * @param {string} [options.apiKey] an API key from
27
+ * https://haveibeenpwned.com/API/Key
28
+ * @param {string} [options.baseUrl] a custom base URL for the
29
+ * haveibeenpwned.com API endpoints (default:
30
+ * `https://haveibeenpwned.com/api/v3`)
31
+ * @param {string} [options.userAgent] a custom string to send as the User-Agent
32
+ * field in the request headers (default: `hibp <version>`)
33
+ * @returns {(Promise<Paste[]> | Promise<null>)} a Promise which resolves to an
34
+ * array of paste objects (or null if no pastes were found), or rejects with an
35
+ * Error
36
+ * @example
37
+ * pasteAccount('foo@bar.com', { apiKey: 'my-api-key' })
38
+ * .then(data => {
39
+ * if (data) {
40
+ * // ...
41
+ * } else {
42
+ * // ...
43
+ * }
44
+ * })
45
+ * .catch(err => {
46
+ * // ...
47
+ * });
48
+ */
49
+ function pasteAccount(email, options = {}) {
50
+ return fetchFromApi(`/pasteaccount/${encodeURIComponent(email)}`, {
51
+ apiKey: options.apiKey,
52
+ baseUrl: options.baseUrl,
53
+ userAgent: options.userAgent
54
+ });
55
+ }
56
+ export { pasteAccount };
57
+ //# sourceMappingURL=pasteAccount.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pasteAccount.mjs","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,YAAYA,CAC1BC,KAAa,EACbC,UAAqE,EAAE,EAAA;EAEvE,OAAOC,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;"}