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
@@ -0,0 +1,104 @@
1
+ import fetch from '@remix-run/web-fetch';
2
+ import { name, version } from '../../package.json.mjs';
3
+ import { TOO_MANY_REQUESTS, NOT_FOUND, FORBIDDEN, UNAUTHORIZED, BAD_REQUEST } from './responses.mjs';
4
+
5
+ /**
6
+ * Custom error thrown when the haveibeenpwned.com API responds with 429 Too
7
+ * Many Requests. See the `retryAfterSeconds` property for the number of seconds
8
+ * to wait before attempting the request again.
9
+ *
10
+ * @see https://haveibeenpwned.com/API/v3#RateLimiting
11
+ */
12
+ class RateLimitError extends Error {
13
+ /**
14
+ * The number of seconds to wait before attempting the request again. May be
15
+ * `undefined` if the API does not provide a `retry-after` header, but this
16
+ * should never happen.
17
+ */
18
+ retryAfterSeconds;
19
+ constructor(retryAfter, message, options) {
20
+ super(message, options);
21
+ this.name = this.constructor.name;
22
+ this.retryAfterSeconds = typeof retryAfter === 'string' ? Number.parseInt(retryAfter, 10) /* c8 ignore start */ : undefined;
23
+ }
24
+ }
25
+ /* c8 ignore stop */
26
+ function blockedWithRayId(rayId) {
27
+ return `Request blocked, contact haveibeenpwned.com if this continues (Ray ID: ${rayId})`;
28
+ }
29
+ /**
30
+ * Fetches data from the supplied API endpoint.
31
+ *
32
+ * HTTP status code 200 returns an Object (data found).
33
+ * HTTP status code 404 returns null (no data found).
34
+ * HTTP status code 400 throws an Error (bad request).
35
+ * HTTP status code 401 throws an Error (unauthorized).
36
+ * HTTP status code 403 throws an Error (forbidden).
37
+ * HTTP status code 429 throws an Error (too many requests).
38
+ *
39
+ * @internal
40
+ * @private
41
+ * @param {string} endpoint the API endpoint to query
42
+ * @param {object} [options] a configuration object
43
+ * @param {string} [options.apiKey] an API key from
44
+ * https://haveibeenpwned.com/API/Key
45
+ * @param {string} [options.baseUrl] a custom base URL for the
46
+ * haveibeenpwned.com API endpoints (default:
47
+ * `https://haveibeenpwned.com/api/v3`)
48
+ * @param {string} [options.userAgent] a custom string to send as the User-Agent
49
+ * field in the request headers (default: `hibp <version>`)
50
+ * @returns {Promise<ApiData>} a Promise which resolves to the data resulting
51
+ * from the query (or null for 404 Not Found responses), or rejects with an
52
+ * Error
53
+ */
54
+ function fetchFromApi(endpoint, {
55
+ apiKey,
56
+ baseUrl = 'https://haveibeenpwned.com/api/v3',
57
+ userAgent
58
+ } = {}) {
59
+ const headers = {};
60
+ if (apiKey) {
61
+ headers['HIBP-API-Key'] = apiKey;
62
+ }
63
+ if (userAgent) {
64
+ headers['User-Agent'] = userAgent;
65
+ }
66
+ // Provide a default User-Agent when running outside the browser
67
+ if (!userAgent && typeof navigator === 'undefined') {
68
+ headers['User-Agent'] = `${name} ${version}`;
69
+ }
70
+ const config = {
71
+ headers
72
+ };
73
+ const url = `${baseUrl.replace(/\/$/g, '')}${endpoint}`;
74
+ return fetch(url, config).then(res => {
75
+ if (res.ok) return res.json();
76
+ switch (res.status) {
77
+ case BAD_REQUEST.status:
78
+ throw new Error(BAD_REQUEST.statusText);
79
+ case UNAUTHORIZED.status:
80
+ return res.json().then(body => {
81
+ throw new Error(body.message);
82
+ });
83
+ case FORBIDDEN.status:
84
+ {
85
+ const rayId = res.headers.get('cf-ray');
86
+ if (rayId) {
87
+ throw new Error(blockedWithRayId(rayId));
88
+ }
89
+ throw new Error(FORBIDDEN.statusText);
90
+ }
91
+ case NOT_FOUND.status:
92
+ return null;
93
+ case TOO_MANY_REQUESTS.status:
94
+ return res.json().then(body => {
95
+ const retryAfter = res.headers.get('retry-after');
96
+ throw new RateLimitError(retryAfter, body.message);
97
+ });
98
+ default:
99
+ throw new Error(res.statusText);
100
+ }
101
+ });
102
+ }
103
+ export { RateLimitError, fetchFromApi };
104
+ //# sourceMappingURL=fetchFromApi.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetchFromApi.mjs","sources":["../../../../src/api/haveibeenpwned/fetchFromApi.ts"],"sourcesContent":["import fetch from '@remix-run/web-fetch';\nimport { name, version } from '../../../package.json';\nimport {\n BAD_REQUEST,\n UNAUTHORIZED,\n FORBIDDEN,\n NOT_FOUND,\n TOO_MANY_REQUESTS,\n} from './responses';\nimport type { ApiData, ErrorData } from './types';\n\n/**\n * Custom error thrown when the haveibeenpwned.com API responds with 429 Too\n * Many Requests. See the `retryAfterSeconds` property for the number of seconds\n * to wait before attempting the request again.\n *\n * @see https://haveibeenpwned.com/API/v3#RateLimiting\n */\nexport class RateLimitError extends Error {\n /**\n * The number of seconds to wait before attempting the request again. May be\n * `undefined` if the API does not provide a `retry-after` header, but this\n * should never happen.\n */\n public retryAfterSeconds: number | undefined;\n\n constructor(\n retryAfter: ReturnType<Headers['get']>,\n message: string | undefined,\n options?: ErrorOptions,\n ) {\n super(message, options);\n this.name = this.constructor.name;\n this.retryAfterSeconds =\n typeof retryAfter === 'string'\n ? Number.parseInt(retryAfter, 10) /* c8 ignore start */\n : undefined;\n }\n}\n/* c8 ignore stop */\n\nfunction blockedWithRayId(rayId: string) {\n return `Request blocked, contact haveibeenpwned.com if this continues (Ray ID: ${rayId})`;\n}\n\n/**\n * Fetches data from the supplied API endpoint.\n *\n * HTTP status code 200 returns an Object (data found).\n * HTTP status code 404 returns null (no data found).\n * HTTP status code 400 throws an Error (bad request).\n * HTTP status code 401 throws an Error (unauthorized).\n * HTTP status code 403 throws an Error (forbidden).\n * HTTP status code 429 throws an Error (too many requests).\n *\n * @internal\n * @private\n * @param {string} endpoint the API endpoint 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<ApiData>} a Promise which resolves to the data resulting\n * from the query (or null for 404 Not Found responses), or rejects with an\n * Error\n */\nexport function fetchFromApi(\n endpoint: string,\n {\n apiKey,\n baseUrl = 'https://haveibeenpwned.com/api/v3',\n userAgent,\n }: { apiKey?: string; baseUrl?: string; userAgent?: string } = {},\n): Promise<ApiData> {\n const headers: Record<string, string> = {};\n\n if (apiKey) {\n headers['HIBP-API-Key'] = apiKey;\n }\n\n if (userAgent) {\n headers['User-Agent'] = userAgent;\n }\n\n // Provide a default User-Agent when running outside the browser\n if (!userAgent && typeof navigator === 'undefined') {\n headers['User-Agent'] = `${name} ${version}`;\n }\n\n const config = { headers };\n const url = `${baseUrl.replace(/\\/$/g, '')}${endpoint}`;\n\n return fetch(url, config).then((res) => {\n if (res.ok) return res.json() as Promise<ApiData>;\n\n switch (res.status) {\n case BAD_REQUEST.status:\n throw new Error(BAD_REQUEST.statusText);\n case UNAUTHORIZED.status:\n return res.json().then((body: ErrorData) => {\n throw new Error(body.message);\n });\n case FORBIDDEN.status: {\n const rayId = res.headers.get('cf-ray');\n if (rayId) {\n throw new Error(blockedWithRayId(rayId));\n }\n throw new Error(FORBIDDEN.statusText);\n }\n case NOT_FOUND.status:\n return null;\n case TOO_MANY_REQUESTS.status:\n return res.json().then((body: ErrorData) => {\n const retryAfter = res.headers.get('retry-after');\n throw new RateLimitError(retryAfter, body.message);\n });\n default:\n throw new Error(res.statusText);\n }\n });\n}\n"],"names":["RateLimitError","Error","retryAfterSeconds","constructor","retryAfter","message","options","name","Number","parseInt","undefined","blockedWithRayId","rayId","fetchFromApi","endpoint","apiKey","baseUrl","userAgent","headers","navigator","version","config","url","replace","fetch","then","res","ok","json","status","BAD_REQUEST","statusText","UNAUTHORIZED","body","FORBIDDEN","get","NOT_FOUND","TOO_MANY_REQUESTS"],"mappings":";;;;AAWA;;;;;;AAMG;AACG,MAAOA,cAAe,SAAQC,KAAK,CAAA;EACvC;;;;AAIG;EACIC,iBAAiB;EAExBC,WAAA,CACEC,UAAsC,EACtCC,OAA2B,EAC3BC,OAAsB,EAAA;IAEtB,KAAK,CAACD,OAAO,EAAEC,OAAO,CAAC;IACvB,IAAI,CAACC,IAAI,GAAG,IAAI,CAACJ,WAAW,CAACI,IAAI;IACjC,IAAI,CAACL,iBAAiB,GACpB,OAAOE,UAAU,KAAK,QAAQ,GAC1BI,MAAM,CAACC,QAAQ,CAACL,UAAU,EAAE,EAAE,CAAC,CAAA,wBAC/BM,SAAS;EAChB;AACF;AACD;AAEA,SAASC,gBAAgB,CAACC,KAAa,EAAA;EACrC,OAAO,0EAA0EA,KAAK,GAAG;AAC3F;AAEA;;;;;;;;;;;;;;;;;;;;;;;;AAwBG;AACa,SAAAC,YAAY,CAC1BC,QAAgB,EAChB;EACEC,MAAM;EACNC,OAAO,GAAG,mCAAmC;EAC7CC;IAC6D,EAAE,EAAA;EAEjE,MAAMC,OAAO,GAA2B,CAAA,CAAE;EAE1C,IAAIH,MAAM,EAAE;IACVG,OAAO,CAAC,cAAc,CAAC,GAAGH,MAAM;EACjC;EAED,IAAIE,SAAS,EAAE;IACbC,OAAO,CAAC,YAAY,CAAC,GAAGD,SAAS;EAClC;;EAGD,IAAI,CAACA,SAAS,IAAI,OAAOE,SAAS,KAAK,WAAW,EAAE;IAClDD,OAAO,CAAC,YAAY,CAAC,MAAMX,IAAI,IAAIa,OAAO,EAAE;EAC7C;EAED,MAAMC,MAAM,GAAG;IAAEH;GAAS;EAC1B,MAAMI,GAAG,GAAM,GAAAN,OAAO,CAACO,OAAO,CAAC,MAAM,EAAE,EAAE,CAAI,GAAAT,UAAU;EAEvD,OAAOU,KAAK,CAACF,GAAG,EAAED,MAAM,CAAC,CAACI,IAAI,CAAEC,GAAG,IAAI;IACrC,IAAIA,GAAG,CAACC,EAAE,EAAE,OAAOD,GAAG,CAACE,IAAI,EAAsB;IAEjD,QAAQF,GAAG,CAACG,MAAM;MAChB,KAAKC,WAAW,CAACD,MAAM;QACrB,MAAM,IAAI5B,KAAK,CAAC6B,WAAW,CAACC,UAAU,CAAC;MACzC,KAAKC,YAAY,CAACH,MAAM;QACtB,OAAOH,GAAG,CAACE,IAAI,EAAE,CAACH,IAAI,CAAEQ,IAAe,IAAI;UACzC,MAAM,IAAIhC,KAAK,CAACgC,IAAI,CAAC5B,OAAO,CAAC;QAC/B,CAAC,CAAC;MACJ,KAAK6B,SAAS,CAACL,MAAM;QAAE;UACrB,MAAMjB,KAAK,GAAGc,GAAG,CAACR,OAAO,CAACiB,GAAG,CAAC,QAAQ,CAAC;UACvC,IAAIvB,KAAK,EAAE;YACT,MAAM,IAAIX,KAAK,CAACU,gBAAgB,CAACC,KAAK,CAAC,CAAC;UACzC;UACD,MAAM,IAAIX,KAAK,CAACiC,SAAS,CAACH,UAAU,CAAC;QACtC;MACD,KAAKK,SAAS,CAACP,MAAM;QACnB,OAAO,IAAI;MACb,KAAKQ,iBAAiB,CAACR,MAAM;QAC3B,OAAOH,GAAG,CAACE,IAAI,EAAE,CAACH,IAAI,CAAEQ,IAAe,IAAI;UACzC,MAAM7B,UAAU,GAAGsB,GAAG,CAACR,OAAO,CAACiB,GAAG,CAAC,aAAa,CAAC;UACjD,MAAM,IAAInC,cAAc,CAACI,UAAU,EAAE6B,IAAI,CAAC5B,OAAO,CAAC;QACpD,CAAC,CAAC;MACJ;QACE,MAAM,IAAIJ,KAAK,CAACyB,GAAG,CAACK,UAAU,CAAC;IAAC;EAEtC,CAAC,CAAC;AACJ;"}
@@ -0,0 +1,2 @@
1
+ export { RateLimitError, fetchFromApi } from './fetchFromApi.mjs';
2
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Known potential responses from the remote API.
3
+ *
4
+ * Unfortunately, the API does not send a decent human-readable message back
5
+ * with each response, but they are documented on the website:
6
+ * https://haveibeenpwned.com/api/v3#ResponseCodes
7
+ *
8
+ * These objects simply provide a mapping between the HTTP response status code
9
+ * and the corresponding human-readable message so we can throw a more
10
+ * descriptive error for the consumer. (They are also leveraged in our tests.)
11
+ */
12
+ const emptyHeaders = /*#__PURE__*/new Map();
13
+ /** @internal */
14
+ const OK = {
15
+ headers: emptyHeaders,
16
+ status: 200
17
+ };
18
+ /** @internal */
19
+ const BAD_REQUEST = {
20
+ headers: emptyHeaders,
21
+ status: 400,
22
+ statusText: 'Bad request — the account does not comply with an acceptable format.'
23
+ };
24
+ /**
25
+ * This response has unique behavior. For some reason, the API includes an
26
+ * object in the response body for this one, containing a human-readable
27
+ * message. Manually populating the message here purely for use in tests.
28
+ *
29
+ * @internal
30
+ */
31
+ const UNAUTHORIZED = {
32
+ headers: emptyHeaders,
33
+ status: 401,
34
+ body: {
35
+ statusCode: 401,
36
+ message: 'Access denied due to missing hibp-api-key.'
37
+ }
38
+ };
39
+ /** @internal */
40
+ const FORBIDDEN = {
41
+ headers: emptyHeaders,
42
+ status: 403,
43
+ statusText: 'Forbidden - access denied.'
44
+ };
45
+ /** @internal */
46
+ const BLOCKED = {
47
+ headers: /*#__PURE__*/new Map([['cf-ray', 'someRayId']]),
48
+ status: 403
49
+ };
50
+ /** @internal */
51
+ const NOT_FOUND = {
52
+ headers: emptyHeaders,
53
+ status: 404
54
+ };
55
+ /**
56
+ * This response has unique behavior. For some reason, the API includes an
57
+ * object in the response body for this one, containing a human-readable
58
+ * message. Manually populating the message here purely for use in tests.
59
+ *
60
+ * @internal
61
+ */
62
+ const TOO_MANY_REQUESTS = {
63
+ headers: /*#__PURE__*/new Map([['retry-after', '2']]),
64
+ status: 429,
65
+ body: {
66
+ statusCode: 429,
67
+ message: 'Rate limit is exceeded. Try again in 2 seconds.'
68
+ }
69
+ };
70
+ export { BAD_REQUEST, BLOCKED, FORBIDDEN, NOT_FOUND, OK, TOO_MANY_REQUESTS, UNAUTHORIZED };
71
+ //# sourceMappingURL=responses.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"responses.mjs","sources":["../../../../src/api/haveibeenpwned/responses.ts"],"sourcesContent":["/**\n * Known potential responses from the remote API.\n *\n * Unfortunately, the API does not send a decent human-readable message back\n * with each response, but they are documented on the website:\n * https://haveibeenpwned.com/api/v3#ResponseCodes\n *\n * These objects simply provide a mapping between the HTTP response status code\n * and the corresponding human-readable message so we can throw a more\n * descriptive error for the consumer. (They are also leveraged in our tests.)\n */\n\nimport type { ResponseBody } from './types';\n\n/** @internal */\nexport interface HaveIBeenPwnedApiResponse {\n headers: Map<string, string>;\n status: number;\n statusText?: string;\n body?: ResponseBody;\n}\n\nconst emptyHeaders = new Map<string, string>();\n\n/** @internal */\nexport const OK: HaveIBeenPwnedApiResponse = {\n headers: emptyHeaders,\n status: 200,\n};\n\n/** @internal */\nexport const BAD_REQUEST: HaveIBeenPwnedApiResponse = {\n headers: emptyHeaders,\n status: 400,\n statusText:\n 'Bad request — the account does not comply with an acceptable format.',\n};\n\n/**\n * This response has unique behavior. For some reason, the API includes an\n * object in the response body for this one, containing a human-readable\n * message. Manually populating the message here purely for use in tests.\n *\n * @internal\n */\nexport const UNAUTHORIZED: HaveIBeenPwnedApiResponse = {\n headers: emptyHeaders,\n status: 401,\n body: {\n statusCode: 401,\n message: 'Access denied due to missing hibp-api-key.',\n },\n};\n\n/** @internal */\nexport const FORBIDDEN: HaveIBeenPwnedApiResponse = {\n headers: emptyHeaders,\n status: 403,\n statusText: 'Forbidden - access denied.',\n};\n\n/** @internal */\nexport const BLOCKED: HaveIBeenPwnedApiResponse = {\n headers: new Map([['cf-ray', 'someRayId']]),\n status: 403,\n};\n\n/** @internal */\nexport const NOT_FOUND: HaveIBeenPwnedApiResponse = {\n headers: emptyHeaders,\n status: 404,\n};\n\n/**\n * This response has unique behavior. For some reason, the API includes an\n * object in the response body for this one, containing a human-readable\n * message. Manually populating the message here purely for use in tests.\n *\n * @internal\n */\nexport const TOO_MANY_REQUESTS: HaveIBeenPwnedApiResponse = {\n headers: new Map([['retry-after', '2']]),\n status: 429,\n body: {\n statusCode: 429,\n message: 'Rate limit is exceeded. Try again in 2 seconds.',\n },\n};\n"],"names":["emptyHeaders","Map","OK","headers","status","BAD_REQUEST","statusText","UNAUTHORIZED","body","statusCode","message","FORBIDDEN","BLOCKED","NOT_FOUND","TOO_MANY_REQUESTS"],"mappings":"AAAA;;;;;;;;;;AAUG;AAYH,MAAMA,YAAY,gBAAG,IAAIC,GAAG,EAAkB;AAE9C;AACa,MAAAC,EAAE,GAA8B;EAC3CC,OAAO,EAAEH,YAAY;EACrBI,MAAM,EAAE;CACR;AAEF;AACa,MAAAC,WAAW,GAA8B;EACpDF,OAAO,EAAEH,YAAY;EACrBI,MAAM,EAAE,GAAG;EACXE,UAAU,EACR;CACF;AAEF;;;;;;AAMG;AACU,MAAAC,YAAY,GAA8B;EACrDJ,OAAO,EAAEH,YAAY;EACrBI,MAAM,EAAE,GAAG;EACXI,IAAI,EAAE;IACJC,UAAU,EAAE,GAAG;IACfC,OAAO,EAAE;EACV;CACD;AAEF;AACa,MAAAC,SAAS,GAA8B;EAClDR,OAAO,EAAEH,YAAY;EACrBI,MAAM,EAAE,GAAG;EACXE,UAAU,EAAE;CACZ;AAEF;AACa,MAAAM,OAAO,GAA8B;EAChDT,OAAO,eAAE,IAAIF,GAAG,CAAC,CAAC,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC,CAAC;EAC3CG,MAAM,EAAE;CACR;AAEF;AACa,MAAAS,SAAS,GAA8B;EAClDV,OAAO,EAAEH,YAAY;EACrBI,MAAM,EAAE;CACR;AAEF;;;;;;AAMG;AACU,MAAAU,iBAAiB,GAA8B;EAC1DX,OAAO,eAAE,IAAIF,GAAG,CAAC,CAAC,CAAC,aAAa,EAAE,GAAG,CAAC,CAAC,CAAC;EACxCG,MAAM,EAAE,GAAG;EACXI,IAAI,EAAE;IACJC,UAAU,EAAE,GAAG;IACfC,OAAO,EAAE;EACV;;"}
@@ -0,0 +1,42 @@
1
+ import fetch from '@remix-run/web-fetch';
2
+ import { BAD_REQUEST } from './responses.mjs';
3
+
4
+ /**
5
+ * Fetches data from the supplied API endpoint.
6
+ *
7
+ * HTTP status code 200 returns plain text (data found).
8
+ * HTTP status code 400 throws an Error (bad request).
9
+ *
10
+ * @internal
11
+ * @private
12
+ * @param {string} endpoint the API endpoint to query
13
+ * @param {object} [options] a configuration object
14
+ * @param {string} [options.baseUrl] a custom base URL for the
15
+ * pwnedpasswords.com API endpoints (default: `https://api.pwnedpasswords.com`)
16
+ * @param {string} [options.userAgent] a custom string to send as the User-Agent
17
+ * field in the request headers (default: `hibp <version>`)
18
+ * @returns {Promise<string>} a Promise which resolves to the data resulting
19
+ * from the query, or rejects with an Error
20
+ */
21
+ function fetchFromApi(endpoint, {
22
+ baseUrl = 'https://api.pwnedpasswords.com',
23
+ userAgent
24
+ } = {}) {
25
+ const config = Object.assign({}, userAgent ? {
26
+ headers: {
27
+ 'User-Agent': userAgent
28
+ }
29
+ } : {});
30
+ const url = `${baseUrl.replace(/\/$/g, '')}${endpoint}`;
31
+ return fetch(url, config).then(res => {
32
+ if (res.ok) return res.text();
33
+ if (res.status === BAD_REQUEST.status) {
34
+ return res.text().then(text => {
35
+ throw new Error(text);
36
+ });
37
+ }
38
+ throw new Error(res.statusText);
39
+ });
40
+ }
41
+ export { fetchFromApi };
42
+ //# sourceMappingURL=fetchFromApi.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetchFromApi.mjs","sources":["../../../../src/api/pwnedpasswords/fetchFromApi.ts"],"sourcesContent":["import fetch from '@remix-run/web-fetch';\nimport { BAD_REQUEST } from './responses';\n\n/**\n * Fetches data from the supplied API endpoint.\n *\n * HTTP status code 200 returns plain text (data found).\n * HTTP status code 400 throws an Error (bad request).\n *\n * @internal\n * @private\n * @param {string} endpoint the API endpoint to query\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<string>} a Promise which resolves to the data resulting\n * from the query, or rejects with an Error\n */\nexport function fetchFromApi(\n endpoint: string,\n {\n baseUrl = 'https://api.pwnedpasswords.com',\n userAgent,\n }: { baseUrl?: string; userAgent?: string } = {},\n): Promise<string> {\n const config = Object.assign(\n {},\n userAgent\n ? {\n headers: {\n 'User-Agent': userAgent,\n },\n }\n : {},\n );\n\n const url = `${baseUrl.replace(/\\/$/g, '')}${endpoint}`;\n\n return fetch(url, config).then((res) => {\n if (res.ok) return res.text();\n\n if (res.status === BAD_REQUEST.status) {\n return res.text().then((text) => {\n throw new Error(text);\n });\n }\n\n throw new Error(res.statusText);\n });\n}\n"],"names":["fetchFromApi","endpoint","baseUrl","userAgent","config","Object","assign","headers","url","replace","fetch","then","res","ok","text","status","BAD_REQUEST","Error","statusText"],"mappings":";;;AAGA;;;;;;;;;;;;;;;;AAgBG;AACa,SAAAA,YAAY,CAC1BC,QAAgB,EAChB;EACEC,OAAO,GAAG,gCAAgC;EAC1CC;AAAS,CAAA,GACmC,EAAE,EAAA;EAEhD,MAAMC,MAAM,GAAGC,MAAM,CAACC,MAAM,CAC1B,CAAE,CAAA,EACFH,SAAS,GACL;IACEI,OAAO,EAAE;MACP,YAAY,EAAEJ;IACf;EACF,CAAA,GACD,CAAA,CAAE,CACP;EAED,MAAMK,GAAG,GAAM,GAAAN,OAAO,CAACO,OAAO,CAAC,MAAM,EAAE,EAAE,CAAI,GAAAR,UAAU;EAEvD,OAAOS,KAAK,CAACF,GAAG,EAAEJ,MAAM,CAAC,CAACO,IAAI,CAAEC,GAAG,IAAI;IACrC,IAAIA,GAAG,CAACC,EAAE,EAAE,OAAOD,GAAG,CAACE,IAAI,EAAE;IAE7B,IAAIF,GAAG,CAACG,MAAM,KAAKC,WAAW,CAACD,MAAM,EAAE;MACrC,OAAOH,GAAG,CAACE,IAAI,EAAE,CAACH,IAAI,CAAEG,IAAI,IAAI;QAC9B,MAAM,IAAIG,KAAK,CAACH,IAAI,CAAC;MACvB,CAAC,CAAC;IACH;IAED,MAAM,IAAIG,KAAK,CAACL,GAAG,CAACM,UAAU,CAAC;EACjC,CAAC,CAAC;AACJ;"}
@@ -0,0 +1,2 @@
1
+ export { fetchFromApi } from './fetchFromApi.mjs';
2
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Known potential responses from the remote API.
3
+ *
4
+ * https://haveibeenpwned.com/api/v3#PwnedPasswords
5
+ *
6
+ */
7
+ /** @internal */
8
+ const OK = {
9
+ status: 200
10
+ };
11
+ /** @internal */
12
+ const BAD_REQUEST = {
13
+ status: 400,
14
+ body: 'The hash prefix was not in a valid format'
15
+ };
16
+ export { BAD_REQUEST, OK };
17
+ //# sourceMappingURL=responses.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"responses.mjs","sources":["../../../../src/api/pwnedpasswords/responses.ts"],"sourcesContent":["/**\n * Known potential responses from the remote API.\n *\n * https://haveibeenpwned.com/api/v3#PwnedPasswords\n *\n */\n\n/** @internal */\nexport interface PwnedPasswordsApiResponse {\n status: number;\n body?: string;\n}\n\n/** @internal */\nexport const OK: PwnedPasswordsApiResponse = {\n status: 200,\n};\n\n/** @internal */\nexport const BAD_REQUEST: PwnedPasswordsApiResponse = {\n status: 400,\n body: 'The hash prefix was not in a valid format',\n};\n"],"names":["OK","status","BAD_REQUEST","body"],"mappings":"AAAA;;;;;AAKG;AAQH;AACa,MAAAA,EAAE,GAA8B;EAC3CC,MAAM,EAAE;CACR;AAEF;AACa,MAAAC,WAAW,GAA8B;EACpDD,MAAM,EAAE,GAAG;EACXE,IAAI,EAAE;;"}
@@ -0,0 +1,53 @@
1
+ import { fetchFromApi } from './api/haveibeenpwned/fetchFromApi.mjs';
2
+
3
+ /**
4
+ * An object representing a breach.
5
+ *
6
+ * @typedef {object} Breach
7
+ * @property {string} Name
8
+ * @property {string} Title
9
+ * @property {string} Domain
10
+ * @property {string} BreachDate
11
+ * @property {string} AddedDate
12
+ * @property {string} ModifiedDate
13
+ * @property {number} PwnCount
14
+ * @property {string} Description
15
+ * @property {string} LogoPath
16
+ * @property {string[]} DataClasses
17
+ * @property {boolean} IsVerified
18
+ * @property {boolean} IsFabricated
19
+ * @property {boolean} IsSensitive
20
+ * @property {boolean} IsRetired
21
+ * @property {boolean} IsSpamList
22
+ */
23
+ /**
24
+ * Fetches data for a specific breach event.
25
+ *
26
+ * @param {string} breachName the name of a breach in the system
27
+ * @param {object} [options] a configuration object
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<Breach>|Promise<null>)} a Promise which resolves to an
34
+ * object representing a breach (or null if no breach was found), or rejects
35
+ * with an Error
36
+ * @example
37
+ * breach('Adobe')
38
+ * .then(data => {
39
+ * if (data) {
40
+ * // ...
41
+ * } else {
42
+ * // ...
43
+ * }
44
+ * })
45
+ * .catch(err => {
46
+ * // ...
47
+ * });
48
+ */
49
+ function breach(breachName, options = {}) {
50
+ return fetchFromApi(`/breach/${encodeURIComponent(breachName)}`, options);
51
+ }
52
+ export { breach };
53
+ //# sourceMappingURL=breach.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"breach.mjs","sources":["../../src/breach.ts"],"sourcesContent":["import type { Breach } from './api/haveibeenpwned/types';\nimport { fetchFromApi } from './api/haveibeenpwned';\n\n/**\n * An object representing a breach.\n *\n * @typedef {object} Breach\n * @property {string} Name\n * @property {string} Title\n * @property {string} Domain\n * @property {string} BreachDate\n * @property {string} AddedDate\n * @property {string} ModifiedDate\n * @property {number} PwnCount\n * @property {string} Description\n * @property {string} LogoPath\n * @property {string[]} DataClasses\n * @property {boolean} IsVerified\n * @property {boolean} IsFabricated\n * @property {boolean} IsSensitive\n * @property {boolean} IsRetired\n * @property {boolean} IsSpamList\n */\n\n/**\n * Fetches data for a specific breach event.\n *\n * @param {string} breachName the name of a breach in the system\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<Breach>|Promise<null>)} a Promise which resolves to an\n * object representing a breach (or null if no breach was found), or rejects\n * with an Error\n * @example\n * breach('Adobe')\n * .then(data => {\n * if (data) {\n * // ...\n * } else {\n * // ...\n * }\n * })\n * .catch(err => {\n * // ...\n * });\n */\nexport function breach(\n breachName: string,\n options: { baseUrl?: string; userAgent?: string } = {},\n): Promise<Breach | null> {\n return fetchFromApi(\n `/breach/${encodeURIComponent(breachName)}`,\n options,\n ) as Promise<Breach | null>;\n}\n"],"names":["breach","breachName","options","fetchFromApi","encodeURIComponent"],"mappings":";;AAGA;;;;;;;;;;;;;;;;;;;AAmBG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;AAyBG;SACaA,MAAM,CACpBC,UAAkB,EAClBC,UAAoD,EAAE,EAAA;EAEtD,OAAOC,YAAY,CACjB,WAAWC,kBAAkB,CAACH,UAAU,CAAG,EAAA,EAC3CC,OAAO,CACkB;AAC7B;"}
@@ -0,0 +1,99 @@
1
+ import { fetchFromApi } from './api/haveibeenpwned/fetchFromApi.mjs';
2
+
3
+ /**
4
+ * Fetches breach data for a specific account.
5
+ *
6
+ * ***Warning (July 18, 2019):***
7
+ *
8
+ * `haveibeenpwned.com` now requires an API key from
9
+ * https://haveibeenpwned.com/API/Key for the `breachedaccount` endpoint. The
10
+ * `apiKey` option here is not explicitly required, but direct requests made
11
+ * without it (that is, without specifying a `baseUrl` to a proxy that inserts a
12
+ * valid API key on your behalf) will fail.
13
+ *
14
+ * @param {string} account a username or email address
15
+ * @param {object} [options] a configuration object
16
+ * @param {string} [options.apiKey] an API key from
17
+ * https://haveibeenpwned.com/API/Key (default: undefined)
18
+ * @param {string} [options.domain] a domain by which to filter the results
19
+ * (default: all domains)
20
+ * @param {boolean} [options.includeUnverified] include "unverified" breaches in
21
+ * the results (default: true)
22
+ * @param {boolean} [options.truncate] truncate the results to only include
23
+ * the name of each breach (default: true)
24
+ * @param {string} [options.baseUrl] a custom base URL for the
25
+ * haveibeenpwned.com API endpoints (default:
26
+ * `https://haveibeenpwned.com/api/v3`)
27
+ * @param {string} [options.userAgent] a custom string to send as the User-Agent
28
+ * field in the request headers (default: `hibp <version>`)
29
+ * @returns {(Promise<Breach[]> | Promise<null>)} a Promise which resolves to an
30
+ * array of breach objects (or null if no breaches were found), or rejects with
31
+ * an Error
32
+ * @example
33
+ * breachedAccount('foo', { apiKey: 'my-api-key' })
34
+ * .then(data => {
35
+ * if (data) {
36
+ * // ...
37
+ * } else {
38
+ * // ...
39
+ * }
40
+ * })
41
+ * .catch(err => {
42
+ * // ...
43
+ * });
44
+ * @example
45
+ * breachedAccount('bar', {
46
+ * includeUnverified: false,
47
+ * baseUrl: 'https://my-hibp-proxy:8080',
48
+ * })
49
+ * .then(data => {
50
+ * if (data) {
51
+ * // ...
52
+ * } else {
53
+ * // ...
54
+ * }
55
+ * })
56
+ * .catch(err => {
57
+ * // ...
58
+ * });
59
+ * @example
60
+ * breachedAccount('baz', {
61
+ * apiKey: 'my-api-key',
62
+ * domain: 'adobe.com',
63
+ * truncate: false,
64
+ * userAgent: 'my-app 1.0'
65
+ * })
66
+ * .then(data => {
67
+ * if (data) {
68
+ * // ...
69
+ * } else {
70
+ * // ...
71
+ * }
72
+ * })
73
+ * .catch(err => {
74
+ * // ...
75
+ * });
76
+ */
77
+ function breachedAccount(account, options = {
78
+ includeUnverified: true,
79
+ truncate: true
80
+ }) {
81
+ const endpoint = `/breachedaccount/${encodeURIComponent(account)}?`;
82
+ const params = [];
83
+ if (options.domain) {
84
+ params.push(`domain=${encodeURIComponent(options.domain)}`);
85
+ }
86
+ if (options.includeUnverified === false) {
87
+ params.push('includeUnverified=false');
88
+ }
89
+ if (options.truncate === false) {
90
+ params.push('truncateResponse=false');
91
+ }
92
+ return fetchFromApi(`${endpoint}${params.join('&')}`, {
93
+ apiKey: options.apiKey,
94
+ baseUrl: options.baseUrl,
95
+ userAgent: options.userAgent
96
+ });
97
+ }
98
+ export { breachedAccount };
99
+ //# sourceMappingURL=breachedAccount.mjs.map
@@ -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,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,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,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,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,WAAW,CACzBC,OAAA,GAAoD,EAAE,EAAA;EAEtD,OAAOC,YAAY,CAAC,cAAc,EAAED,OAAO,CAA6B;AAC1E;"}
@@ -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.9896b89a";
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