hibp 0.0.0-dev.9896b89a → 0.0.0-dev.debac06f

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 (119) hide show
  1. package/API.md +275 -198
  2. package/CHANGELOG.md +70 -0
  3. package/README.md +20 -22
  4. package/dist/browser/hibp.module.js +1 -1
  5. package/dist/browser/hibp.module.js.map +1 -1
  6. package/dist/browser/hibp.umd.js +1 -1
  7. package/dist/browser/hibp.umd.js.map +1 -1
  8. package/dist/cjs/api/fetch-polyfill.cjs +28 -0
  9. package/dist/cjs/api/fetch-polyfill.cjs.map +1 -0
  10. package/dist/cjs/api/haveibeenpwned/{fetchFromApi.js → fetch-from-api.cjs} +43 -38
  11. package/dist/cjs/api/haveibeenpwned/fetch-from-api.cjs.map +1 -0
  12. package/dist/cjs/api/haveibeenpwned/{responses.js → responses.cjs} +1 -7
  13. package/dist/cjs/api/haveibeenpwned/responses.cjs.map +1 -0
  14. package/dist/cjs/api/haveibeenpwned/types.cjs +2 -0
  15. package/dist/cjs/api/haveibeenpwned/types.cjs.map +1 -0
  16. package/dist/cjs/api/pwnedpasswords/fetch-from-api.cjs +53 -0
  17. package/dist/cjs/api/pwnedpasswords/fetch-from-api.cjs.map +1 -0
  18. package/dist/cjs/api/pwnedpasswords/{responses.js → responses.cjs} +1 -6
  19. package/dist/cjs/api/pwnedpasswords/responses.cjs.map +1 -0
  20. package/dist/cjs/{breach.js → breach.cjs} +14 -13
  21. package/dist/cjs/breach.cjs.map +1 -0
  22. package/dist/cjs/{breachedAccount.js → breached-account.cjs} +56 -56
  23. package/dist/cjs/breached-account.cjs.map +1 -0
  24. package/dist/cjs/{breaches.js → breaches.cjs} +29 -26
  25. package/dist/cjs/breaches.cjs.map +1 -0
  26. package/dist/cjs/{dataClasses.js → data-classes.cjs} +11 -12
  27. package/dist/cjs/data-classes.cjs.map +1 -0
  28. package/dist/cjs/hibp.cjs +23 -0
  29. package/dist/cjs/hibp.cjs.map +1 -0
  30. package/dist/cjs/hibp.d.cts +663 -0
  31. package/dist/cjs/{package.json.js → package.json.cjs} +2 -2
  32. package/dist/cjs/package.json.cjs.map +1 -0
  33. package/dist/cjs/{pasteAccount.js → paste-account.cjs} +28 -22
  34. package/dist/cjs/paste-account.cjs.map +1 -0
  35. package/dist/cjs/{pwnedPasswordRange.js → pwned-password-range.cjs} +44 -25
  36. package/dist/cjs/pwned-password-range.cjs.map +1 -0
  37. package/dist/cjs/{pwnedPassword.js → pwned-password.cjs} +20 -15
  38. package/dist/cjs/pwned-password.cjs.map +1 -0
  39. package/dist/cjs/{search.js → search.cjs} +51 -49
  40. package/dist/cjs/search.cjs.map +1 -0
  41. package/dist/cjs/subscription-status.cjs +56 -0
  42. package/dist/cjs/subscription-status.cjs.map +1 -0
  43. package/dist/esm/api/fetch-polyfill.js +26 -0
  44. package/dist/esm/api/fetch-polyfill.js.map +1 -0
  45. package/dist/esm/api/haveibeenpwned/{fetchFromApi.mjs → fetch-from-api.js} +43 -38
  46. package/dist/esm/api/haveibeenpwned/fetch-from-api.js.map +1 -0
  47. package/dist/esm/api/haveibeenpwned/{responses.mjs → responses.js} +2 -7
  48. package/dist/esm/api/haveibeenpwned/responses.js.map +1 -0
  49. package/dist/esm/api/haveibeenpwned/types.js +2 -0
  50. package/dist/esm/api/haveibeenpwned/types.js.map +1 -0
  51. package/dist/esm/api/pwnedpasswords/fetch-from-api.js +51 -0
  52. package/dist/esm/api/pwnedpasswords/fetch-from-api.js.map +1 -0
  53. package/dist/esm/api/pwnedpasswords/{responses.mjs → responses.js} +2 -6
  54. package/dist/esm/api/pwnedpasswords/responses.js.map +1 -0
  55. package/dist/esm/{breach.mjs → breach.js} +14 -13
  56. package/dist/esm/breach.js.map +1 -0
  57. package/dist/esm/{breachedAccount.mjs → breached-account.js} +56 -56
  58. package/dist/esm/breached-account.js.map +1 -0
  59. package/dist/esm/{breaches.mjs → breaches.js} +29 -26
  60. package/dist/esm/breaches.js.map +1 -0
  61. package/dist/esm/{dataClasses.mjs → data-classes.js} +11 -12
  62. package/dist/esm/data-classes.js.map +1 -0
  63. package/dist/esm/hibp.d.ts +663 -0
  64. package/dist/esm/hibp.js +11 -0
  65. package/dist/{cjs → esm}/hibp.js.map +1 -1
  66. package/dist/esm/package.json.js +4 -0
  67. package/dist/{cjs → esm}/package.json.js.map +1 -1
  68. package/dist/esm/{pasteAccount.mjs → paste-account.js} +28 -22
  69. package/dist/esm/paste-account.js.map +1 -0
  70. package/dist/esm/{pwnedPasswordRange.mjs → pwned-password-range.js} +44 -25
  71. package/dist/esm/pwned-password-range.js.map +1 -0
  72. package/dist/esm/{pwnedPassword.mjs → pwned-password.js} +20 -15
  73. package/dist/esm/pwned-password.js.map +1 -0
  74. package/dist/esm/{search.mjs → search.js} +51 -49
  75. package/dist/esm/search.js.map +1 -0
  76. package/dist/esm/subscription-status.js +54 -0
  77. package/dist/esm/subscription-status.js.map +1 -0
  78. package/example/runkit.js +13 -14
  79. package/package.json +57 -64
  80. package/dist/cjs/api/haveibeenpwned/fetchFromApi.js.map +0 -1
  81. package/dist/cjs/api/haveibeenpwned/index.js +0 -6
  82. package/dist/cjs/api/haveibeenpwned/index.js.map +0 -1
  83. package/dist/cjs/api/haveibeenpwned/responses.js.map +0 -1
  84. package/dist/cjs/api/pwnedpasswords/fetchFromApi.js +0 -44
  85. package/dist/cjs/api/pwnedpasswords/fetchFromApi.js.map +0 -1
  86. package/dist/cjs/api/pwnedpasswords/index.js +0 -5
  87. package/dist/cjs/api/pwnedpasswords/index.js.map +0 -1
  88. package/dist/cjs/api/pwnedpasswords/responses.js.map +0 -1
  89. package/dist/cjs/breach.js.map +0 -1
  90. package/dist/cjs/breachedAccount.js.map +0 -1
  91. package/dist/cjs/breaches.js.map +0 -1
  92. package/dist/cjs/dataClasses.js.map +0 -1
  93. package/dist/cjs/hibp.js +0 -21
  94. package/dist/cjs/pasteAccount.js.map +0 -1
  95. package/dist/cjs/pwnedPassword.js.map +0 -1
  96. package/dist/cjs/pwnedPasswordRange.js.map +0 -1
  97. package/dist/cjs/search.js.map +0 -1
  98. package/dist/esm/api/haveibeenpwned/fetchFromApi.mjs.map +0 -1
  99. package/dist/esm/api/haveibeenpwned/index.mjs +0 -2
  100. package/dist/esm/api/haveibeenpwned/index.mjs.map +0 -1
  101. package/dist/esm/api/haveibeenpwned/responses.mjs.map +0 -1
  102. package/dist/esm/api/pwnedpasswords/fetchFromApi.mjs +0 -42
  103. package/dist/esm/api/pwnedpasswords/fetchFromApi.mjs.map +0 -1
  104. package/dist/esm/api/pwnedpasswords/index.mjs +0 -2
  105. package/dist/esm/api/pwnedpasswords/index.mjs.map +0 -1
  106. package/dist/esm/api/pwnedpasswords/responses.mjs.map +0 -1
  107. package/dist/esm/breach.mjs.map +0 -1
  108. package/dist/esm/breachedAccount.mjs.map +0 -1
  109. package/dist/esm/breaches.mjs.map +0 -1
  110. package/dist/esm/dataClasses.mjs.map +0 -1
  111. package/dist/esm/hibp.mjs +0 -10
  112. package/dist/esm/hibp.mjs.map +0 -1
  113. package/dist/esm/package.json.mjs +0 -4
  114. package/dist/esm/package.json.mjs.map +0 -1
  115. package/dist/esm/pasteAccount.mjs.map +0 -1
  116. package/dist/esm/pwnedPassword.mjs.map +0 -1
  117. package/dist/esm/pwnedPasswordRange.mjs.map +0 -1
  118. package/dist/esm/search.mjs.map +0 -1
  119. package/dist/hibp.d.ts +0 -502
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetch-from-api.js","sources":["../../../../src/api/haveibeenpwned/fetch-from-api.ts"],"sourcesContent":["import { name, version } from '../../../package.json';\nimport { installUndiciOnNode18 } from '../fetch-polyfill.js';\nimport {\n BAD_REQUEST,\n UNAUTHORIZED,\n FORBIDDEN,\n NOT_FOUND,\n TOO_MANY_REQUESTS,\n} from './responses.js';\nimport type { ApiData, ErrorData } from './types.js';\n\ninstallUndiciOnNode18();\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; /* c8 ignore stop */\n }\n}\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 async function fetchFromApi(\n endpoint: string,\n options: {\n apiKey?: string;\n baseUrl?: string;\n userAgent?: string;\n } = {},\n): Promise<ApiData> {\n const {\n apiKey,\n baseUrl = 'https://haveibeenpwned.com/api/v3',\n userAgent,\n } = options;\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 const response = await fetch(url, config);\n\n if (response.ok) return response.json() as Promise<ApiData>;\n\n switch (response.status) {\n case BAD_REQUEST.status: {\n throw new Error(BAD_REQUEST.statusText);\n }\n case UNAUTHORIZED.status: {\n const body = (await response.json()) as unknown as ErrorData;\n throw new Error(body.message);\n }\n case FORBIDDEN.status: {\n const rayId = response.headers.get('cf-ray');\n if (rayId) throw new Error(blockedWithRayId(rayId));\n throw new Error(FORBIDDEN.statusText);\n }\n case NOT_FOUND.status: {\n return null;\n }\n case TOO_MANY_REQUESTS.status: {\n const body = (await response.json()) as unknown as ErrorData;\n const retryAfter = response.headers.get('retry-after');\n throw new RateLimitError(retryAfter, body.message);\n }\n default: {\n throw new Error(response.statusText);\n }\n }\n}\n"],"names":["installUndiciOnNode18","RateLimitError","Error","retryAfterSeconds","constructor","retryAfter","message","options","name","Number","parseInt","undefined","blockedWithRayId","rayId","fetchFromApi","endpoint","apiKey","baseUrl","userAgent","headers","navigator","version","config","url","replace","response","fetch","ok","json","status","BAD_REQUEST","statusText","UNAUTHORIZED","body","FORBIDDEN","get","NOT_FOUND","TOO_MANY_REQUESTS"],"mappings":";;;AAWAA,qBAAqB,EAAE;AAEvB;;;;;;AAMG;AACG,MAAOC,cAAe,SAAQC,KAAK,CAAA;EACvC;;;;AAIG;EACIC,iBAAiB;EAExBC,WAAAA,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,CAAC,CAAA;EACjB;AACF;AAED,SAASC,gBAAgBA,CAACC,KAAa,EAAA;EACrC,OAAO,0EAA0EA,KAAK,GAAG;AAC3F;AAEA;;;;;;;;;;;;;;;;;;;;;;;;AAwBG;AACI,eAAeC,YAAYA,CAChCC,QAAgB,EAChBR,UAII,EAAE,EAAA;EAEN,MAAM;IACJS,MAAM;IACNC,OAAO,GAAG,mCAAmC;IAC7CC;EAAS,CACV,GAAGX,OAAO;EACX,MAAMY,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;EACvD,MAAMU,QAAQ,GAAG,MAAMC,KAAK,CAACH,GAAG,EAAED,MAAM,CAAC;EAEzC,IAAIG,QAAQ,CAACE,EAAE,EAAE,OAAOF,QAAQ,CAACG,IAAI,EAAsB;EAE3D,QAAQH,QAAQ,CAACI,MAAM;IACrB,KAAKC,WAAW,CAACD,MAAM;MAAE;QACvB,MAAM,IAAI3B,KAAK,CAAC4B,WAAW,CAACC,UAAU,CAAC;MACxC;IACD,KAAKC,YAAY,CAACH,MAAM;MAAE;QACxB,MAAMI,IAAI,GAAI,MAAMR,QAAQ,CAACG,IAAI,CAAE,CAAyB;QAC5D,MAAM,IAAI1B,KAAK,CAAC+B,IAAI,CAAC3B,OAAO,CAAC;MAC9B;IACD,KAAK4B,SAAS,CAACL,MAAM;MAAE;QACrB,MAAMhB,KAAK,GAAGY,QAAQ,CAACN,OAAO,CAACgB,GAAG,CAAC,QAAQ,CAAC;QAC5C,IAAItB,KAAK,EAAE,MAAM,IAAIX,KAAK,CAACU,gBAAgB,CAACC,KAAK,CAAC,CAAC;QACnD,MAAM,IAAIX,KAAK,CAACgC,SAAS,CAACH,UAAU,CAAC;MACtC;IACD,KAAKK,SAAS,CAACP,MAAM;MAAE;QACrB,OAAO,IAAI;MACZ;IACD,KAAKQ,iBAAiB,CAACR,MAAM;MAAE;QAC7B,MAAMI,IAAI,GAAI,MAAMR,QAAQ,CAACG,IAAI,CAAE,CAAyB;QAC5D,MAAMvB,UAAU,GAAGoB,QAAQ,CAACN,OAAO,CAACgB,GAAG,CAAC,aAAa,CAAC;QACtD,MAAM,IAAIlC,cAAc,CAACI,UAAU,EAAE4B,IAAI,CAAC3B,OAAO,CAAC;MACnD;IACD;MAAS;QACP,MAAM,IAAIJ,KAAK,CAACuB,QAAQ,CAACM,UAAU,CAAC;MACrC;EACF;AACH;"}
@@ -11,11 +11,6 @@
11
11
  */
12
12
  const emptyHeaders = /*#__PURE__*/new Map();
13
13
  /** @internal */
14
- const OK = {
15
- headers: emptyHeaders,
16
- status: 200
17
- };
18
- /** @internal */
19
14
  const BAD_REQUEST = {
20
15
  headers: emptyHeaders,
21
16
  status: 400,
@@ -67,5 +62,5 @@ const TOO_MANY_REQUESTS = {
67
62
  message: 'Rate limit is exceeded. Try again in 2 seconds.'
68
63
  }
69
64
  };
70
- export { BAD_REQUEST, BLOCKED, FORBIDDEN, NOT_FOUND, OK, TOO_MANY_REQUESTS, UNAUTHORIZED };
71
- //# sourceMappingURL=responses.mjs.map
65
+ export { BAD_REQUEST, BLOCKED, FORBIDDEN, NOT_FOUND, TOO_MANY_REQUESTS, UNAUTHORIZED };
66
+ //# sourceMappingURL=responses.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"responses.js","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.js';\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 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","BAD_REQUEST","headers","status","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,WAAW,GAA8B;EACpDC,OAAO,EAAEH,YAAY;EACrBI,MAAM,EAAE,GAAG;EACXC,UAAU,EACR;CACF;AAEF;;;;;;AAMG;AACU,MAAAC,YAAY,GAA8B;EACrDH,OAAO,EAAEH,YAAY;EACrBI,MAAM,EAAE,GAAG;EACXG,IAAI,EAAE;IACJC,UAAU,EAAE,GAAG;IACfC,OAAO,EAAE;EACV;CACD;AAEF;AACa,MAAAC,SAAS,GAA8B;EAClDP,OAAO,EAAEH,YAAY;EACrBI,MAAM,EAAE,GAAG;EACXC,UAAU,EAAE;CACZ;AAEF;AACa,MAAAM,OAAO,GAA8B;EAChDR,OAAO,eAAE,IAAIF,GAAG,CAAC,CAAC,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC,CAAC;EAC3CG,MAAM,EAAE;CACR;AAEF;AACa,MAAAQ,SAAS,GAA8B;EAClDT,OAAO,EAAEH,YAAY;EACrBI,MAAM,EAAE;CACR;AAEF;;;;;;AAMG;AACU,MAAAS,iBAAiB,GAA8B;EAC1DV,OAAO,eAAE,IAAIF,GAAG,CAAC,CAAC,CAAC,aAAa,EAAE,GAAG,CAAC,CAAC,CAAC;EACxCG,MAAM,EAAE,GAAG;EACXG,IAAI,EAAE;IACJC,UAAU,EAAE,GAAG;IACfC,OAAO,EAAE;EACV;;"}
@@ -0,0 +1,2 @@
1
+
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -0,0 +1,51 @@
1
+ import { installUndiciOnNode18 } from '../fetch-polyfill.js';
2
+ import { BAD_REQUEST } from './responses.js';
3
+ installUndiciOnNode18();
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
+ * @param {boolean} [options.addPadding] ask the remote API to add padding to
19
+ * the response to obscure the password prefix (default: `false`)
20
+ * @param {'sha1' | 'ntlm'} [options.mode] return SHA-1 or NTLM hashes
21
+ * (default: `sha1`)
22
+ * @returns {Promise<string>} a Promise which resolves to the data resulting
23
+ * from the query, or rejects with an Error
24
+ */
25
+ async function fetchFromApi(endpoint, options = {}) {
26
+ const {
27
+ baseUrl = 'https://api.pwnedpasswords.com',
28
+ userAgent,
29
+ addPadding = false,
30
+ mode = 'sha1'
31
+ } = options;
32
+ const config = Object.assign({}, userAgent ? {
33
+ headers: {
34
+ 'User-Agent': userAgent
35
+ }
36
+ } : {}, addPadding ? {
37
+ headers: {
38
+ 'Add-Padding': 'true'
39
+ }
40
+ } : {});
41
+ const url = `${baseUrl.replace(/\/$/g, '')}${endpoint}?mode=${mode}`;
42
+ const response = await fetch(url, config);
43
+ if (response.ok) return response.text();
44
+ if (response.status === BAD_REQUEST.status) {
45
+ const text = await response.text();
46
+ throw new Error(text);
47
+ }
48
+ throw new Error(response.statusText);
49
+ }
50
+ export { fetchFromApi };
51
+ //# sourceMappingURL=fetch-from-api.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetch-from-api.js","sources":["../../../../src/api/pwnedpasswords/fetch-from-api.ts"],"sourcesContent":["import { installUndiciOnNode18 } from '../fetch-polyfill.js';\nimport { BAD_REQUEST } from './responses.js';\n\ninstallUndiciOnNode18();\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 * @param {boolean} [options.addPadding] ask the remote API to add padding to\n * the response to obscure the password prefix (default: `false`)\n * @param {'sha1' | 'ntlm'} [options.mode] return SHA-1 or NTLM hashes\n * (default: `sha1`)\n * @returns {Promise<string>} a Promise which resolves to the data resulting\n * from the query, or rejects with an Error\n */\nexport async function fetchFromApi(\n endpoint: string,\n options: {\n baseUrl?: string;\n userAgent?: string;\n addPadding?: boolean;\n mode?: 'sha1' | 'ntlm';\n } = {},\n): Promise<string> {\n const {\n baseUrl = 'https://api.pwnedpasswords.com',\n userAgent,\n addPadding = false,\n mode = 'sha1',\n } = options;\n\n const config = Object.assign(\n {},\n userAgent ? { headers: { 'User-Agent': userAgent } } : {},\n addPadding ? { headers: { 'Add-Padding': 'true' } } : {},\n );\n const url = `${baseUrl.replace(/\\/$/g, '')}${endpoint}?mode=${mode}`;\n const response = await fetch(url, config);\n\n if (response.ok) return response.text();\n\n if (response.status === BAD_REQUEST.status) {\n const text = await response.text();\n throw new Error(text);\n }\n\n throw new Error(response.statusText);\n}\n"],"names":["installUndiciOnNode18","fetchFromApi","endpoint","options","baseUrl","userAgent","addPadding","mode","config","Object","assign","headers","url","replace","response","fetch","ok","text","status","BAD_REQUEST","Error","statusText"],"mappings":";;AAGAA,qBAAqB,EAAE;AAEvB;;;;;;;;;;;;;;;;;;;;AAoBG;AACI,eAAeC,YAAYA,CAChCC,QAAgB,EAChBC,UAKI,EAAE,EAAA;EAEN,MAAM;IACJC,OAAO,GAAG,gCAAgC;IAC1CC,SAAS;IACTC,UAAU,GAAG,KAAK;IAClBC,IAAI,GAAG;EACR,CAAA,GAAGJ,OAAO;EAEX,MAAMK,MAAM,GAAGC,MAAM,CAACC,MAAM,CAC1B,CAAA,CAAE,EACFL,SAAS,GAAG;IAAEM,OAAO,EAAE;MAAE,YAAY,EAAEN;IAAW;EAAA,CAAE,GAAG,CAAE,CAAA,EACzDC,UAAU,GAAG;IAAEK,OAAO,EAAE;MAAE,aAAa,EAAE;IAAM;GAAI,GAAG,CAAA,CAAE,CACzD;EACD,MAAMC,GAAG,GAAG,GAAGR,OAAO,CAACS,OAAO,CAAC,MAAM,EAAE,EAAE,CAAI,GAAAX,QAAiB,SAAAK,MAAM;EACpE,MAAMO,QAAQ,GAAG,MAAMC,KAAK,CAACH,GAAG,EAAEJ,MAAM,CAAC;EAEzC,IAAIM,QAAQ,CAACE,EAAE,EAAE,OAAOF,QAAQ,CAACG,IAAI,EAAE;EAEvC,IAAIH,QAAQ,CAACI,MAAM,KAAKC,WAAW,CAACD,MAAM,EAAE;IAC1C,MAAMD,IAAI,GAAG,MAAMH,QAAQ,CAACG,IAAI,EAAE;IAClC,MAAM,IAAIG,KAAK,CAACH,IAAI,CAAC;EACtB;EAED,MAAM,IAAIG,KAAK,CAACN,QAAQ,CAACO,UAAU,CAAC;AACtC;"}
@@ -5,13 +5,9 @@
5
5
  *
6
6
  */
7
7
  /** @internal */
8
- const OK = {
9
- status: 200
10
- };
11
- /** @internal */
12
8
  const BAD_REQUEST = {
13
9
  status: 400,
14
10
  body: 'The hash prefix was not in a valid format'
15
11
  };
16
- export { BAD_REQUEST, OK };
17
- //# sourceMappingURL=responses.mjs.map
12
+ export { BAD_REQUEST };
13
+ //# sourceMappingURL=responses.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"responses.js","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 BAD_REQUEST: PwnedPasswordsApiResponse = {\n status: 400,\n body: 'The hash prefix was not in a valid format',\n};\n"],"names":["BAD_REQUEST","status","body"],"mappings":"AAAA;;;;;AAKG;AAQH;AACa,MAAAA,WAAW,GAA8B;EACpDC,MAAM,EAAE,GAAG;EACXC,IAAI,EAAE;;"}
@@ -1,4 +1,4 @@
1
- import { fetchFromApi } from './api/haveibeenpwned/fetchFromApi.mjs';
1
+ import { fetchFromApi } from './api/haveibeenpwned/fetch-from-api.js';
2
2
 
3
3
  /**
4
4
  * An object representing a breach.
@@ -12,13 +12,15 @@ import { fetchFromApi } from './api/haveibeenpwned/fetchFromApi.mjs';
12
12
  * @property {string} ModifiedDate
13
13
  * @property {number} PwnCount
14
14
  * @property {string} Description
15
- * @property {string} LogoPath
16
15
  * @property {string[]} DataClasses
17
16
  * @property {boolean} IsVerified
18
17
  * @property {boolean} IsFabricated
19
18
  * @property {boolean} IsSensitive
20
19
  * @property {boolean} IsRetired
21
20
  * @property {boolean} IsSpamList
21
+ * @property {boolean} IsMalware
22
+ * @property {boolean} IsSubscriptionFree
23
+ * @property {string} LogoPath
22
24
  */
23
25
  /**
24
26
  * Fetches data for a specific breach event.
@@ -34,20 +36,19 @@ import { fetchFromApi } from './api/haveibeenpwned/fetchFromApi.mjs';
34
36
  * object representing a breach (or null if no breach was found), or rejects
35
37
  * with an Error
36
38
  * @example
37
- * breach('Adobe')
38
- * .then(data => {
39
- * if (data) {
40
- * // ...
41
- * } else {
42
- * // ...
43
- * }
44
- * })
45
- * .catch(err => {
39
+ * try {
40
+ * const data = await breach("Adobe");
41
+ * if (data) {
42
+ * // ...
43
+ * } else {
46
44
  * // ...
47
- * });
45
+ * }
46
+ * } catch (err) {
47
+ * // ...
48
+ * }
48
49
  */
49
50
  function breach(breachName, options = {}) {
50
51
  return fetchFromApi(`/breach/${encodeURIComponent(breachName)}`, options);
51
52
  }
52
53
  export { breach };
53
- //# sourceMappingURL=breach.mjs.map
54
+ //# sourceMappingURL=breach.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"breach.js","sources":["../../src/breach.ts"],"sourcesContent":["import type { Breach } from './api/haveibeenpwned/types.js';\nimport { fetchFromApi } from './api/haveibeenpwned/fetch-from-api.js';\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[]} DataClasses\n * @property {boolean} IsVerified\n * @property {boolean} IsFabricated\n * @property {boolean} IsSensitive\n * @property {boolean} IsRetired\n * @property {boolean} IsSpamList\n * @property {boolean} IsMalware\n * @property {boolean} IsSubscriptionFree\n * @property {string} LogoPath\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 * try {\n * const data = await breach(\"Adobe\");\n * if (data) {\n * // ...\n * } else {\n * // ...\n * }\n * } catch (err) {\n * // ...\n * }\n */\nexport function breach(\n breachName: string,\n options: {\n /**\n * a custom base URL for the haveibeenpwned.com API endpoints (default:\n * `https://haveibeenpwned.com/api/v3`)\n */\n baseUrl?: string;\n /**\n * a custom string to send as the User-Agent field in the request headers\n * (default: `hibp <version>`)\n */\n userAgent?: string;\n } = {},\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;;;;;;;;;;;;;;;;;;;;;AAqBG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;AAwBG;SACaA,MAAMA,CACpBC,UAAkB,EAClBC,UAWI,EAAE,EAAA;EAEN,OAAOC,YAAY,CACjB,WAAWC,kBAAkB,CAACH,UAAU,CAAG,EAAA,EAC3CC,OAAO,CACkB;AAC7B;"}
@@ -1,15 +1,13 @@
1
- import { fetchFromApi } from './api/haveibeenpwned/fetchFromApi.mjs';
1
+ import { fetchFromApi } from './api/haveibeenpwned/fetch-from-api.js';
2
2
 
3
3
  /**
4
4
  * Fetches breach data for a specific account.
5
5
  *
6
- * ***Warning (July 18, 2019):***
7
- *
8
- * `haveibeenpwned.com` now requires an API key from
6
+ * 🔑 `haveibeenpwned.com` requires an API key from
9
7
  * https://haveibeenpwned.com/API/Key for the `breachedaccount` endpoint. The
10
8
  * `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.
9
+ * without it will fail (unless you specify a `baseUrl` to a proxy that inserts
10
+ * a valid API key on your behalf).
13
11
  *
14
12
  * @param {string} account a username or email address
15
13
  * @param {object} [options] a configuration object
@@ -30,70 +28,72 @@ import { fetchFromApi } from './api/haveibeenpwned/fetchFromApi.mjs';
30
28
  * array of breach objects (or null if no breaches were found), or rejects with
31
29
  * an Error
32
30
  * @example
33
- * breachedAccount('foo', { apiKey: 'my-api-key' })
34
- * .then(data => {
35
- * if (data) {
36
- * // ...
37
- * } else {
38
- * // ...
39
- * }
40
- * })
41
- * .catch(err => {
31
+ * try {
32
+ * const data = await breachedAccount("foo", { apiKey: "my-api-key" });
33
+ * if (data) {
42
34
  * // ...
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 => {
35
+ * } else {
57
36
  * // ...
58
- * });
37
+ * }
38
+ * } catch (err) {
39
+ * // ...
40
+ * }
59
41
  * @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 => {
42
+ * try {
43
+ * const data = await breachedAccount("bar", {
44
+ * includeUnverified: false,
45
+ * baseUrl: "https://my-hibp-proxy:8080",
46
+ * });
47
+ * if (data) {
74
48
  * // ...
49
+ * } else {
50
+ * // ...
51
+ * }
52
+ * } catch (err) {
53
+ * // ...
54
+ * }
55
+ * @example
56
+ * try {
57
+ * const data = await breachedAccount("baz", {
58
+ * apiKey: "my-api-key",
59
+ * domain: "adobe.com",
60
+ * truncate: false,
61
+ * userAgent: "my-app 1.0",
75
62
  * });
63
+ * if (data) {
64
+ * // ...
65
+ * } else {
66
+ * // ...
67
+ * }
68
+ * } catch (err) {
69
+ * // ...
70
+ * }
76
71
  */
77
- function breachedAccount(account, options = {
78
- includeUnverified: true,
79
- truncate: true
80
- }) {
72
+ function breachedAccount(account, options = {}) {
73
+ const {
74
+ apiKey,
75
+ domain,
76
+ includeUnverified = true,
77
+ truncate = true,
78
+ baseUrl,
79
+ userAgent
80
+ } = options;
81
81
  const endpoint = `/breachedaccount/${encodeURIComponent(account)}?`;
82
82
  const params = [];
83
- if (options.domain) {
84
- params.push(`domain=${encodeURIComponent(options.domain)}`);
83
+ if (domain) {
84
+ params.push(`domain=${encodeURIComponent(domain)}`);
85
85
  }
86
- if (options.includeUnverified === false) {
86
+ if (!includeUnverified) {
87
87
  params.push('includeUnverified=false');
88
88
  }
89
- if (options.truncate === false) {
89
+ if (!truncate) {
90
90
  params.push('truncateResponse=false');
91
91
  }
92
92
  return fetchFromApi(`${endpoint}${params.join('&')}`, {
93
- apiKey: options.apiKey,
94
- baseUrl: options.baseUrl,
95
- userAgent: options.userAgent
93
+ apiKey,
94
+ baseUrl,
95
+ userAgent
96
96
  });
97
97
  }
98
98
  export { breachedAccount };
99
- //# sourceMappingURL=breachedAccount.mjs.map
99
+ //# sourceMappingURL=breached-account.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"breached-account.js","sources":["../../src/breached-account.ts"],"sourcesContent":["import type { Breach } from './api/haveibeenpwned/types.js';\nimport { fetchFromApi } from './api/haveibeenpwned/fetch-from-api.js';\n\n/**\n * Fetches breach data for a specific account.\n *\n * 🔑 `haveibeenpwned.com` 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 will fail (unless you specify a `baseUrl` to a proxy that inserts\n * a valid API key on your behalf).\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 * try {\n * const data = await breachedAccount(\"foo\", { apiKey: \"my-api-key\" });\n * if (data) {\n * // ...\n * } else {\n * // ...\n * }\n * } catch (err) {\n * // ...\n * }\n * @example\n * try {\n * const data = await breachedAccount(\"bar\", {\n * includeUnverified: false,\n * baseUrl: \"https://my-hibp-proxy:8080\",\n * });\n * if (data) {\n * // ...\n * } else {\n * // ...\n * }\n * } catch (err) {\n * // ...\n * }\n * @example\n * try {\n * const data = await breachedAccount(\"baz\", {\n * apiKey: \"my-api-key\",\n * domain: \"adobe.com\",\n * truncate: false,\n * userAgent: \"my-app 1.0\",\n * });\n * if (data) {\n * // ...\n * } else {\n * // ...\n * }\n * } catch (err) {\n * // ...\n * }\n */\nexport function breachedAccount(\n account: string,\n options: {\n /**\n * an API key from https://haveibeenpwned.com/API/Key (default: undefined)\n */\n apiKey?: string;\n /**\n * a domain by which to filter the results (default: all domains)\n */\n domain?: string;\n /**\n * include \"unverified\" breaches in the results (default: true)\n */\n includeUnverified?: boolean;\n /**\n * truncate the results to only include the name of each breach (default:\n * true)\n */\n truncate?: boolean;\n /**\n * a custom base URL for the haveibeenpwned.com API endpoints (default:\n * `https://haveibeenpwned.com/api/v3`)\n */\n baseUrl?: string;\n /**\n * a custom string to send as the User-Agent field in the request headers\n * (default: `hibp <version>`)\n */\n userAgent?: string;\n } = {},\n): Promise<Breach[] | null> {\n const {\n apiKey,\n domain,\n includeUnverified = true,\n truncate = true,\n baseUrl,\n userAgent,\n } = options;\n const endpoint = `/breachedaccount/${encodeURIComponent(account)}?`;\n const params: string[] = [];\n\n if (domain) {\n params.push(`domain=${encodeURIComponent(domain)}`);\n }\n\n if (!includeUnverified) {\n params.push('includeUnverified=false');\n }\n\n if (!truncate) {\n params.push('truncateResponse=false');\n }\n\n return fetchFromApi(`${endpoint}${params.join('&')}`, {\n apiKey,\n baseUrl,\n userAgent,\n }) as Promise<Breach[] | null>;\n}\n"],"names":["breachedAccount","account","options","apiKey","domain","includeUnverified","truncate","baseUrl","userAgent","endpoint","encodeURIComponent","params","push","fetchFromApi","join"],"mappings":";;AAGA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoEG;SACaA,eAAeA,CAC7BC,OAAe,EACfC,UA4BI,EAAE,EAAA;EAEN,MAAM;IACJC,MAAM;IACNC,MAAM;IACNC,iBAAiB,GAAG,IAAI;IACxBC,QAAQ,GAAG,IAAI;IACfC,OAAO;IACPC;EACD,CAAA,GAAGN,OAAO;EACX,MAAMO,QAAQ,GAAuB,oBAAAC,kBAAkB,CAACT,OAAO,IAAI;EACnE,MAAMU,MAAM,GAAa,EAAE;EAE3B,IAAIP,MAAM,EAAE;IACVO,MAAM,CAACC,IAAI,CAAW,UAAAF,kBAAkB,CAACN,MAAM,CAAG,EAAA,CAAC;EACpD;EAED,IAAI,CAACC,iBAAiB,EAAE;IACtBM,MAAM,CAACC,IAAI,CAAC,yBAAyB,CAAC;EACvC;EAED,IAAI,CAACN,QAAQ,EAAE;IACbK,MAAM,CAACC,IAAI,CAAC,wBAAwB,CAAC;EACtC;EAED,OAAOC,YAAY,CAAI,GAAAJ,QAAW,GAAAE,MAAM,CAACG,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE;IACpDX,MAAM;IACNI,OAAO;IACPC;EACD,CAAA,CAA6B;AAChC;"}
@@ -1,4 +1,4 @@
1
- import { fetchFromApi } from './api/haveibeenpwned/fetchFromApi.mjs';
1
+ import { fetchFromApi } from './api/haveibeenpwned/fetch-from-api.js';
2
2
 
3
3
  /**
4
4
  * Fetches all breach events in the system.
@@ -14,40 +14,43 @@ import { fetchFromApi } from './api/haveibeenpwned/fetchFromApi.mjs';
14
14
  * @returns {Promise<Breach[]>} a Promise which resolves to an array of breach
15
15
  * objects (an empty array if no breaches were found), or rejects with an Error
16
16
  * @example
17
- * breaches()
18
- * .then(data => {
19
- * if (data) {
20
- * // ...
21
- * } else {
22
- * // ...
23
- * }
24
- * })
25
- * .catch(err => {
17
+ * try {
18
+ * const data = await breaches();
19
+ * if (data) {
26
20
  * // ...
27
- * });
21
+ * } else {
22
+ * // ...
23
+ * }
24
+ * } catch (err) {
25
+ * // ...
26
+ * }
28
27
  * @example
29
- * breaches({ domain: 'adobe.com' })
30
- * .then(data => {
31
- * if (data) {
32
- * // ...
33
- * } else {
34
- * // ...
35
- * }
36
- * })
37
- * .catch(err => {
28
+ * try {
29
+ * const data = await breaches({ domain: "adobe.com" });
30
+ * if (data) {
31
+ * // ...
32
+ * } else {
38
33
  * // ...
39
- * });
34
+ * }
35
+ * } catch (err) {
36
+ * // ...
37
+ * }
40
38
  */
41
39
  function breaches(options = {}) {
40
+ const {
41
+ domain,
42
+ baseUrl,
43
+ userAgent
44
+ } = options;
42
45
  const endpoint = '/breaches?';
43
46
  const params = [];
44
- if (options.domain) {
45
- params.push(`domain=${encodeURIComponent(options.domain)}`);
47
+ if (domain) {
48
+ params.push(`domain=${encodeURIComponent(domain)}`);
46
49
  }
47
50
  return fetchFromApi(`${endpoint}${params.join('&')}`, {
48
- baseUrl: options.baseUrl,
49
- userAgent: options.userAgent
51
+ baseUrl,
52
+ userAgent
50
53
  });
51
54
  }
52
55
  export { breaches };
53
- //# sourceMappingURL=breaches.mjs.map
56
+ //# sourceMappingURL=breaches.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"breaches.js","sources":["../../src/breaches.ts"],"sourcesContent":["import type { Breach } from './api/haveibeenpwned/types.js';\nimport { fetchFromApi } from './api/haveibeenpwned/fetch-from-api.js';\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 * try {\n * const data = await breaches();\n * if (data) {\n * // ...\n * } else {\n * // ...\n * }\n * } catch (err) {\n * // ...\n * }\n * @example\n * try {\n * const data = await breaches({ domain: \"adobe.com\" });\n * if (data) {\n * // ...\n * } else {\n * // ...\n * }\n * } catch (err) {\n * // ...\n * }\n */\nexport function breaches(\n options: {\n /**\n * a domain by which to filter the results (default: all domains)\n */\n domain?: string;\n /**\n * a custom base URL for the haveibeenpwned.com API endpoints (default:\n * `https://haveibeenpwned.com/api/v3`)\n */\n baseUrl?: string;\n /**\n * a custom string to send as the User-Agent field in the request headers\n * (default: `hibp <version>`)\n */\n userAgent?: string;\n } = {},\n): Promise<Breach[]> {\n const { domain, baseUrl, userAgent } = options;\n const endpoint = '/breaches?';\n const params: string[] = [];\n\n if (domain) {\n params.push(`domain=${encodeURIComponent(domain)}`);\n }\n\n return fetchFromApi(`${endpoint}${params.join('&')}`, {\n baseUrl,\n userAgent,\n }) as Promise<Breach[]>;\n}\n"],"names":["breaches","options","domain","baseUrl","userAgent","endpoint","params","push","encodeURIComponent","fetchFromApi","join"],"mappings":";;AAGA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmCG;AACa,SAAAA,QAAQA,CACtBC,OAAA,GAeI,EAAE,EAAA;EAEN,MAAM;IAAEC,MAAM;IAAEC,OAAO;IAAEC;EAAS,CAAE,GAAGH,OAAO;EAC9C,MAAMI,QAAQ,GAAG,YAAY;EAC7B,MAAMC,MAAM,GAAa,EAAE;EAE3B,IAAIJ,MAAM,EAAE;IACVI,MAAM,CAACC,IAAI,CAAW,UAAAC,kBAAkB,CAACN,MAAM,CAAG,EAAA,CAAC;EACpD;EAED,OAAOO,YAAY,CAAI,GAAAJ,QAAW,GAAAC,MAAM,CAACI,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE;IACpDP,OAAO;IACPC;EACD,CAAA,CAAsB;AACzB;"}
@@ -1,4 +1,4 @@
1
- import { fetchFromApi } from './api/haveibeenpwned/fetchFromApi.mjs';
1
+ import { fetchFromApi } from './api/haveibeenpwned/fetch-from-api.js';
2
2
 
3
3
  /**
4
4
  * Fetches all data classes in the system.
@@ -13,20 +13,19 @@ import { fetchFromApi } from './api/haveibeenpwned/fetchFromApi.mjs';
13
13
  * array of strings (or null if no data classes were found), or rejects with an
14
14
  * Error
15
15
  * @example
16
- * dataClasses()
17
- * .then(data => {
18
- * if (data) {
19
- * // ...
20
- * } else {
21
- * // ...
22
- * }
23
- * })
24
- * .catch(err => {
16
+ * try {
17
+ * const data = await dataClasses();
18
+ * if (data) {
25
19
  * // ...
26
- * });
20
+ * } else {
21
+ * // ...
22
+ * }
23
+ * } catch (err) {
24
+ * // ...
25
+ * }
27
26
  */
28
27
  function dataClasses(options = {}) {
29
28
  return fetchFromApi('/dataclasses', options);
30
29
  }
31
30
  export { dataClasses };
32
- //# sourceMappingURL=dataClasses.mjs.map
31
+ //# sourceMappingURL=data-classes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"data-classes.js","sources":["../../src/data-classes.ts"],"sourcesContent":["import { fetchFromApi } from './api/haveibeenpwned/fetch-from-api.js';\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 * try {\n * const data = await dataClasses();\n * if (data) {\n * // ...\n * } else {\n * // ...\n * }\n * } catch (err) {\n * // ...\n * }\n */\nexport function dataClasses(\n options: {\n /**\n * a custom base URL for the haveibeenpwned.com API endpoints (default:\n * `https://haveibeenpwned.com/api/v3`)\n */\n baseUrl?: string;\n /**\n * a custom string to send as the User-Agent field in the request headers\n * (default: `hibp <version>`)\n */\n userAgent?: string;\n } = {},\n): Promise<string[] | null> {\n return fetchFromApi('/dataclasses', options) as Promise<string[] | null>;\n}\n"],"names":["dataClasses","options","fetchFromApi"],"mappings":";;AAEA;;;;;;;;;;;;;;;;;;;;;;;AAuBG;AACa,SAAAA,WAAWA,CACzBC,OAAA,GAWI,EAAE,EAAA;EAEN,OAAOC,YAAY,CAAC,cAAc,EAAED,OAAO,CAA6B;AAC1E;"}