@udibo/oauth2 0.14.1 → 0.15.0

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 (411) hide show
  1. package/README.md +45 -24
  2. package/{esm → dist}/adapters/hono/_common.d.ts +5 -5
  3. package/{esm → dist}/adapters/hono/_common.js +1 -1
  4. package/{esm → dist}/adapters/hono/authorization-server.d.ts +6 -7
  5. package/{esm → dist}/adapters/hono/authorization-server.js +0 -1
  6. package/{esm → dist}/adapters/hono/bff/auth-request-store.d.ts +2 -2
  7. package/{esm → dist}/adapters/hono/bff/auth-request-store.js +2 -2
  8. package/{esm → dist}/adapters/hono/bff/bff.d.ts +8 -8
  9. package/{esm → dist}/adapters/hono/bff/bff.js +31 -26
  10. package/{esm → dist}/adapters/hono/bff/cookie-prefix.js +1 -2
  11. package/{esm → dist}/adapters/hono/bff/mod.d.ts +5 -6
  12. package/{esm → dist}/adapters/hono/bff/mod.js +1 -2
  13. package/{esm → dist}/adapters/hono/bff/proxy.js +2 -1
  14. package/{esm → dist}/adapters/hono/bff/session-store.d.ts +2 -2
  15. package/{esm → dist}/adapters/hono/bff/session-store.js +7 -6
  16. package/{esm → dist}/adapters/hono/bff/testing.d.ts +7 -8
  17. package/{esm → dist}/adapters/hono/bff/testing.js +19 -22
  18. package/{esm → dist}/adapters/hono/identity.d.ts +1 -2
  19. package/{esm → dist}/adapters/hono/identity.js +10 -10
  20. package/{esm → dist}/adapters/hono/log.d.ts +0 -1
  21. package/{esm → dist}/adapters/hono/log.js +0 -6
  22. package/{esm → dist}/adapters/hono/resource-server.d.ts +5 -6
  23. package/{esm → dist}/adapters/hono/resource-server.js +0 -1
  24. package/dist/cli/bin.d.ts +2 -0
  25. package/dist/cli/bin.js +3 -0
  26. package/dist/cli/idp/config.d.ts +110 -0
  27. package/dist/cli/idp/config.js +269 -0
  28. package/dist/cli/idp/mod.d.ts +20 -0
  29. package/dist/cli/idp/mod.js +175 -0
  30. package/dist/cli/idp/pages.d.ts +56 -0
  31. package/dist/cli/idp/pages.js +190 -0
  32. package/dist/cli/idp/server.d.ts +93 -0
  33. package/dist/cli/idp/server.js +559 -0
  34. package/dist/cli/keygen.d.ts +13 -0
  35. package/dist/cli/keygen.js +30 -0
  36. package/dist/cli/mod.d.ts +34 -0
  37. package/dist/cli/mod.js +94 -0
  38. package/{esm → dist}/client/_http.d.ts +1 -1
  39. package/{esm → dist}/client/base.d.ts +1 -1
  40. package/{esm → dist}/client/bff-client.d.ts +1 -1
  41. package/{esm → dist}/client/bff-client.js +7 -6
  42. package/{esm → dist}/client/browser-storage.d.ts +1 -1
  43. package/{esm → dist}/client/check.js +1 -1
  44. package/{esm → dist}/client/direct-client.d.ts +6 -6
  45. package/{esm → dist}/client/direct-client.js +11 -13
  46. package/{esm → dist}/client/discovery-cache.d.ts +1 -1
  47. package/{esm → dist}/client/discovery-cache.js +2 -2
  48. package/{esm → dist}/client/events.d.ts +1 -1
  49. package/{esm → dist}/client/mod.d.ts +11 -12
  50. package/{esm → dist}/client/mod.js +1 -1
  51. package/{esm → dist}/errors.d.ts +1 -1
  52. package/{esm → dist}/errors.js +1 -1
  53. package/{esm → dist}/identity/events.d.ts +1 -1
  54. package/{esm → dist}/identity/external/_shared.d.ts +1 -1
  55. package/{esm → dist}/identity/external/_shared.js +1 -2
  56. package/{esm → dist}/identity/external/apple-client-secret.d.ts +1 -1
  57. package/{esm → dist}/identity/external/apple-client-secret.js +6 -7
  58. package/{esm → dist}/identity/external/apple.d.ts +5 -5
  59. package/{esm → dist}/identity/external/apple.js +10 -11
  60. package/{esm → dist}/identity/external/discord.d.ts +3 -3
  61. package/{esm → dist}/identity/external/discord.js +2 -2
  62. package/{esm → dist}/identity/external/flow.d.ts +1 -1
  63. package/{esm → dist}/identity/external/flow.js +2 -2
  64. package/{esm → dist}/identity/external/github.d.ts +3 -3
  65. package/{esm → dist}/identity/external/github.js +12 -17
  66. package/{esm → dist}/identity/external/google.d.ts +5 -5
  67. package/{esm → dist}/identity/external/google.js +2 -2
  68. package/{esm → dist}/identity/external/mod.d.ts +12 -13
  69. package/{esm → dist}/identity/external/mod.js +0 -1
  70. package/{esm → dist}/identity/external/oauth2.d.ts +1 -1
  71. package/{esm → dist}/identity/external/oauth2.js +8 -8
  72. package/{esm → dist}/identity/external/oidc.d.ts +4 -4
  73. package/{esm → dist}/identity/external/oidc.js +9 -8
  74. package/{esm → dist}/identity/hibp.d.ts +1 -1
  75. package/{esm → dist}/identity/hibp.js +1 -1
  76. package/{esm → dist}/identity/lockout.js +1 -2
  77. package/{esm → dist}/identity/mfa/mod.d.ts +4 -5
  78. package/{esm → dist}/identity/mfa/mod.js +1 -2
  79. package/{esm → dist}/identity/mfa/service.d.ts +3 -3
  80. package/{esm → dist}/identity/mfa/service.js +4 -3
  81. package/{esm → dist}/identity/mfa/totp.d.ts +1 -1
  82. package/{esm → dist}/identity/mfa/totp.js +2 -2
  83. package/{esm → dist}/identity/migration.d.ts +2 -3
  84. package/{esm → dist}/identity/migration.js +3 -4
  85. package/{esm → dist}/identity/mod.d.ts +14 -15
  86. package/{esm → dist}/identity/mod.js +0 -1
  87. package/{esm → dist}/identity/otp.d.ts +1 -1
  88. package/{esm → dist}/identity/otp.js +4 -2
  89. package/{esm → dist}/identity/password.js +8 -5
  90. package/{esm → dist}/identity/rate-limit.d.ts +1 -1
  91. package/{esm → dist}/identity/service.d.ts +10 -10
  92. package/{esm → dist}/identity/service.js +17 -18
  93. package/{esm → dist}/identity/session.js +2 -2
  94. package/{esm → dist}/identity/token-flow.js +3 -2
  95. package/{esm → dist}/models/authorization-code.d.ts +3 -3
  96. package/{esm → dist}/models/authorization.d.ts +1 -1
  97. package/{esm → dist}/models/authorization.js +1 -2
  98. package/{esm → dist}/models/device-authorization.d.ts +2 -2
  99. package/{esm → dist}/models/token.d.ts +3 -3
  100. package/{esm → dist}/react/callback.d.ts +1 -1
  101. package/{esm → dist}/react/callback.js +0 -1
  102. package/{esm → dist}/react/components/class-names.d.ts +1 -1
  103. package/{esm → dist}/react/components/class-names.js +3 -2
  104. package/{esm → dist}/react/components/internal.d.ts +2 -2
  105. package/{esm → dist}/react/components/internal.js +5 -11
  106. package/{esm → dist}/react/components/mfa-challenge-form.d.ts +2 -2
  107. package/{esm → dist}/react/components/mfa-challenge-form.js +4 -6
  108. package/{esm → dist}/react/components/mfa-enrollment-form.d.ts +2 -2
  109. package/{esm → dist}/react/components/mfa-enrollment-form.js +2 -6
  110. package/{esm → dist}/react/components/mod.d.ts +20 -21
  111. package/{esm → dist}/react/components/mod.js +1 -2
  112. package/{esm → dist}/react/components/request-password-reset-form.d.ts +2 -2
  113. package/{esm → dist}/react/components/request-password-reset-form.js +1 -3
  114. package/{esm → dist}/react/components/reset-password-form.d.ts +2 -2
  115. package/{esm → dist}/react/components/reset-password-form.js +2 -2
  116. package/{esm → dist}/react/components/sign-in-form.d.ts +2 -2
  117. package/{esm → dist}/react/components/sign-in-form.js +1 -5
  118. package/{esm → dist}/react/components/sign-up-form.d.ts +2 -2
  119. package/{esm → dist}/react/components/sign-up-form.js +4 -10
  120. package/{esm → dist}/react/components/types.d.ts +2 -2
  121. package/{esm → dist}/react/components/use-auth-form.d.ts +3 -3
  122. package/{esm → dist}/react/components/use-auth-form.js +4 -7
  123. package/{esm → dist}/react/components/user-menu.d.ts +2 -2
  124. package/{esm → dist}/react/components/user-menu.js +9 -14
  125. package/{esm → dist}/react/context.d.ts +1 -1
  126. package/{esm → dist}/react/mod.d.ts +6 -7
  127. package/{esm → dist}/react/mod.js +0 -1
  128. package/{esm → dist}/react/provider.d.ts +2 -2
  129. package/{esm → dist}/react/require-auth.js +1 -3
  130. package/{esm → dist}/react/testing.d.ts +2 -3
  131. package/{esm → dist}/react/testing.js +1 -2
  132. package/{esm → dist}/react/use-authorization.d.ts +1 -1
  133. package/{esm → dist}/react/use-oauth2.d.ts +8 -1
  134. package/{esm → dist}/react/use-oauth2.js +0 -1
  135. package/{esm → dist}/server/_clock-skew.js +2 -1
  136. package/{esm → dist}/server/authorization-server.d.ts +40 -41
  137. package/{esm → dist}/server/authorization-server.js +32 -42
  138. package/{esm → dist}/server/client-authentication.d.ts +2 -2
  139. package/{esm → dist}/server/grants/authorization-code.d.ts +9 -9
  140. package/{esm → dist}/server/grants/authorization-code.js +5 -6
  141. package/{esm → dist}/server/grants/client-credentials.d.ts +4 -4
  142. package/{esm → dist}/server/grants/device-authorization.d.ts +6 -6
  143. package/{esm → dist}/server/grants/device-authorization.js +4 -4
  144. package/{esm → dist}/server/grants/grant.d.ts +7 -7
  145. package/{esm → dist}/server/grants/grant.js +7 -7
  146. package/{esm → dist}/server/grants/password.d.ts +5 -5
  147. package/{esm → dist}/server/grants/refresh-token.d.ts +4 -4
  148. package/{esm → dist}/server/grants/refresh-token.js +5 -6
  149. package/{esm → dist}/server/introspection-token-reader.d.ts +5 -5
  150. package/{esm → dist}/server/introspection-token-reader.js +4 -4
  151. package/{esm → dist}/server/jwks-token-reader.d.ts +5 -5
  152. package/{esm → dist}/server/jwks-token-reader.js +4 -4
  153. package/{esm → dist}/server/mod.d.ts +12 -13
  154. package/{esm → dist}/server/mod.js +0 -1
  155. package/{esm → dist}/server/public-suffix/mod.d.ts +2 -3
  156. package/{esm → dist}/server/public-suffix/mod.js +1 -2
  157. package/{esm → dist}/server/public-suffix/rules.d.ts +1 -1
  158. package/{esm → dist}/server/public-suffix/rules.js +1 -1
  159. package/{esm → dist}/server/redirect-uri.js +5 -4
  160. package/{esm → dist}/server/resource-server.d.ts +11 -12
  161. package/{esm → dist}/server/resource-server.js +12 -14
  162. package/{esm → dist}/server/services/authorization-code.d.ts +5 -5
  163. package/{esm → dist}/server/services/client.d.ts +1 -1
  164. package/{esm → dist}/server/services/device-authorization.d.ts +3 -3
  165. package/{esm → dist}/server/services/token.d.ts +6 -6
  166. package/{esm → dist}/server/services/token.js +3 -1
  167. package/{esm → dist}/server/services/user.d.ts +1 -1
  168. package/{esm → dist}/server/signing-keys.d.ts +1 -1
  169. package/{esm → dist}/server/signing-keys.js +8 -2
  170. package/{esm → dist}/server/utils/hash.js +1 -1
  171. package/{esm → dist}/testing/contract/auth-request-storage.d.ts +1 -1
  172. package/{esm → dist}/testing/contract/auth-request-storage.js +24 -29
  173. package/{esm → dist}/testing/contract/authorization-code.d.ts +6 -6
  174. package/{esm → dist}/testing/contract/authorization-code.js +16 -17
  175. package/{esm → dist}/testing/contract/client.d.ts +4 -4
  176. package/{esm → dist}/testing/contract/client.js +14 -15
  177. package/{esm → dist}/testing/contract/device-authorization.d.ts +6 -6
  178. package/{esm → dist}/testing/contract/device-authorization.js +37 -39
  179. package/{esm → dist}/testing/contract/identity-session.d.ts +6 -1
  180. package/{esm → dist}/testing/contract/identity-session.js +44 -36
  181. package/{esm → dist}/testing/contract/identity-user-store.d.ts +8 -2
  182. package/{esm → dist}/testing/contract/identity-user-store.js +48 -46
  183. package/{esm → dist}/testing/contract/lockout-store.d.ts +1 -1
  184. package/{esm → dist}/testing/contract/lockout-store.js +23 -24
  185. package/{esm → dist}/testing/contract/mfa-store.d.ts +1 -1
  186. package/{esm → dist}/testing/contract/mfa-store.js +53 -54
  187. package/{esm → dist}/testing/contract/mod.d.ts +15 -16
  188. package/{esm → dist}/testing/contract/mod.js +0 -1
  189. package/{esm → dist}/testing/contract/otp-store.d.ts +1 -1
  190. package/{esm → dist}/testing/contract/otp-store.js +33 -34
  191. package/{esm → dist}/testing/contract/rate-limit-store.d.ts +1 -1
  192. package/{esm → dist}/testing/contract/rate-limit-store.js +15 -16
  193. package/{esm → dist}/testing/contract/tenant.js +361 -330
  194. package/{esm → dist}/testing/contract/token-flow-store.d.ts +1 -1
  195. package/{esm → dist}/testing/contract/token-flow-store.js +27 -32
  196. package/{esm → dist}/testing/contract/token-reader.d.ts +3 -3
  197. package/{esm → dist}/testing/contract/token-reader.js +6 -7
  198. package/{esm → dist}/testing/contract/token.d.ts +7 -7
  199. package/{esm → dist}/testing/contract/token.js +48 -53
  200. package/{esm → dist}/testing/contract/user.d.ts +2 -2
  201. package/{esm → dist}/testing/contract/user.js +8 -9
  202. package/{esm → dist}/testing/mod.d.ts +5 -6
  203. package/{esm → dist}/testing/mod.js +2 -3
  204. package/{esm → dist}/testing/server.d.ts +7 -6
  205. package/{esm → dist}/testing/server.js +2 -1
  206. package/{esm → dist}/testing/services.d.ts +11 -11
  207. package/{esm → dist}/testing/services.js +8 -8
  208. package/{esm → dist}/testing/tenant.d.ts +11 -7
  209. package/{esm → dist}/testing/tenant.js +109 -94
  210. package/dist/utils/_constant-time.d.ts +12 -0
  211. package/dist/utils/_constant-time.js +19 -0
  212. package/{esm → dist}/utils/_default-fetch.js +4 -1
  213. package/dist/utils/_delay.d.ts +13 -0
  214. package/dist/utils/_delay.js +28 -0
  215. package/dist/utils/_encoding.d.ts +39 -0
  216. package/dist/utils/_encoding.js +126 -0
  217. package/{esm → dist}/utils/authentication-context.d.ts +1 -1
  218. package/{esm → dist}/utils/crypto.d.ts +2 -3
  219. package/{esm → dist}/utils/crypto.js +3 -4
  220. package/{esm → dist}/utils/pkce.js +1 -1
  221. package/{esm → dist}/utils/text.js +1 -1
  222. package/{esm → dist}/utils/url.d.ts +0 -1
  223. package/{esm → dist}/utils/url.js +0 -1
  224. package/package.json +156 -33
  225. package/esm/_dnt.polyfills.d.ts +0 -31
  226. package/esm/_dnt.polyfills.js +0 -26
  227. package/esm/deps/jsr.io/@std/assert/1.0.19/almost_equals.d.ts +0 -29
  228. package/esm/deps/jsr.io/@std/assert/1.0.19/almost_equals.js +0 -47
  229. package/esm/deps/jsr.io/@std/assert/1.0.19/array_includes.d.ts +0 -28
  230. package/esm/deps/jsr.io/@std/assert/1.0.19/array_includes.js +0 -65
  231. package/esm/deps/jsr.io/@std/assert/1.0.19/assert.d.ts +0 -16
  232. package/esm/deps/jsr.io/@std/assert/1.0.19/assert.js +0 -23
  233. package/esm/deps/jsr.io/@std/assert/1.0.19/assertion_error.d.ts +0 -25
  234. package/esm/deps/jsr.io/@std/assert/1.0.19/assertion_error.js +0 -30
  235. package/esm/deps/jsr.io/@std/assert/1.0.19/equal.d.ts +0 -24
  236. package/esm/deps/jsr.io/@std/assert/1.0.19/equal.js +0 -193
  237. package/esm/deps/jsr.io/@std/assert/1.0.19/equals.d.ts +0 -36
  238. package/esm/deps/jsr.io/@std/assert/1.0.19/equals.js +0 -61
  239. package/esm/deps/jsr.io/@std/assert/1.0.19/exists.d.ts +0 -17
  240. package/esm/deps/jsr.io/@std/assert/1.0.19/exists.js +0 -27
  241. package/esm/deps/jsr.io/@std/assert/1.0.19/fail.d.ts +0 -14
  242. package/esm/deps/jsr.io/@std/assert/1.0.19/fail.js +0 -20
  243. package/esm/deps/jsr.io/@std/assert/1.0.19/false.d.ts +0 -18
  244. package/esm/deps/jsr.io/@std/assert/1.0.19/false.js +0 -23
  245. package/esm/deps/jsr.io/@std/assert/1.0.19/greater.d.ts +0 -19
  246. package/esm/deps/jsr.io/@std/assert/1.0.19/greater.js +0 -29
  247. package/esm/deps/jsr.io/@std/assert/1.0.19/greater_or_equal.d.ts +0 -19
  248. package/esm/deps/jsr.io/@std/assert/1.0.19/greater_or_equal.js +0 -29
  249. package/esm/deps/jsr.io/@std/assert/1.0.19/instance_of.d.ts +0 -22
  250. package/esm/deps/jsr.io/@std/assert/1.0.19/instance_of.js +0 -52
  251. package/esm/deps/jsr.io/@std/assert/1.0.19/is_error.d.ts +0 -24
  252. package/esm/deps/jsr.io/@std/assert/1.0.19/is_error.js +0 -53
  253. package/esm/deps/jsr.io/@std/assert/1.0.19/less.d.ts +0 -18
  254. package/esm/deps/jsr.io/@std/assert/1.0.19/less.js +0 -28
  255. package/esm/deps/jsr.io/@std/assert/1.0.19/less_or_equal.d.ts +0 -19
  256. package/esm/deps/jsr.io/@std/assert/1.0.19/less_or_equal.js +0 -29
  257. package/esm/deps/jsr.io/@std/assert/1.0.19/match.d.ts +0 -17
  258. package/esm/deps/jsr.io/@std/assert/1.0.19/match.js +0 -26
  259. package/esm/deps/jsr.io/@std/assert/1.0.19/mod.d.ts +0 -43
  260. package/esm/deps/jsr.io/@std/assert/1.0.19/mod.js +0 -45
  261. package/esm/deps/jsr.io/@std/assert/1.0.19/not_equals.d.ts +0 -26
  262. package/esm/deps/jsr.io/@std/assert/1.0.19/not_equals.js +0 -39
  263. package/esm/deps/jsr.io/@std/assert/1.0.19/not_instance_of.d.ts +0 -19
  264. package/esm/deps/jsr.io/@std/assert/1.0.19/not_instance_of.js +0 -29
  265. package/esm/deps/jsr.io/@std/assert/1.0.19/not_match.d.ts +0 -17
  266. package/esm/deps/jsr.io/@std/assert/1.0.19/not_match.js +0 -26
  267. package/esm/deps/jsr.io/@std/assert/1.0.19/not_strict_equals.d.ts +0 -22
  268. package/esm/deps/jsr.io/@std/assert/1.0.19/not_strict_equals.js +0 -32
  269. package/esm/deps/jsr.io/@std/assert/1.0.19/object_match.d.ts +0 -28
  270. package/esm/deps/jsr.io/@std/assert/1.0.19/object_match.js +0 -177
  271. package/esm/deps/jsr.io/@std/assert/1.0.19/rejects.d.ts +0 -41
  272. package/esm/deps/jsr.io/@std/assert/1.0.19/rejects.js +0 -53
  273. package/esm/deps/jsr.io/@std/assert/1.0.19/strict_equals.d.ts +0 -23
  274. package/esm/deps/jsr.io/@std/assert/1.0.19/strict_equals.js +0 -58
  275. package/esm/deps/jsr.io/@std/assert/1.0.19/string_includes.d.ts +0 -17
  276. package/esm/deps/jsr.io/@std/assert/1.0.19/string_includes.js +0 -26
  277. package/esm/deps/jsr.io/@std/assert/1.0.19/throws.d.ts +0 -44
  278. package/esm/deps/jsr.io/@std/assert/1.0.19/throws.js +0 -44
  279. package/esm/deps/jsr.io/@std/assert/1.0.19/unimplemented.d.ts +0 -14
  280. package/esm/deps/jsr.io/@std/assert/1.0.19/unimplemented.js +0 -20
  281. package/esm/deps/jsr.io/@std/assert/1.0.19/unreachable.d.ts +0 -14
  282. package/esm/deps/jsr.io/@std/assert/1.0.19/unreachable.js +0 -20
  283. package/esm/deps/jsr.io/@std/async/1.5.0/delay.d.ts +0 -44
  284. package/esm/deps/jsr.io/@std/async/1.5.0/delay.js +0 -84
  285. package/esm/deps/jsr.io/@std/crypto/1.1.0/timing_safe_equal.d.ts +0 -39
  286. package/esm/deps/jsr.io/@std/crypto/1.1.0/timing_safe_equal.js +0 -61
  287. package/esm/deps/jsr.io/@std/encoding/1.0.11/_common16.d.ts +0 -22
  288. package/esm/deps/jsr.io/@std/encoding/1.0.11/_common16.js +0 -51
  289. package/esm/deps/jsr.io/@std/encoding/1.0.11/_common32.d.ts +0 -34
  290. package/esm/deps/jsr.io/@std/encoding/1.0.11/_common32.js +0 -192
  291. package/esm/deps/jsr.io/@std/encoding/1.0.11/_common64.d.ts +0 -34
  292. package/esm/deps/jsr.io/@std/encoding/1.0.11/_common64.js +0 -113
  293. package/esm/deps/jsr.io/@std/encoding/1.0.11/_common_detach.d.ts +0 -3
  294. package/esm/deps/jsr.io/@std/encoding/1.0.11/_common_detach.js +0 -13
  295. package/esm/deps/jsr.io/@std/encoding/1.0.11/_types.d.ts +0 -8
  296. package/esm/deps/jsr.io/@std/encoding/1.0.11/_types.js +0 -2
  297. package/esm/deps/jsr.io/@std/encoding/1.0.11/_validate_binary_like.d.ts +0 -1
  298. package/esm/deps/jsr.io/@std/encoding/1.0.11/_validate_binary_like.js +0 -26
  299. package/esm/deps/jsr.io/@std/encoding/1.0.11/ascii85.d.ts +0 -60
  300. package/esm/deps/jsr.io/@std/encoding/1.0.11/ascii85.js +0 -152
  301. package/esm/deps/jsr.io/@std/encoding/1.0.11/base32.d.ts +0 -39
  302. package/esm/deps/jsr.io/@std/encoding/1.0.11/base32.js +0 -87
  303. package/esm/deps/jsr.io/@std/encoding/1.0.11/base58.d.ts +0 -39
  304. package/esm/deps/jsr.io/@std/encoding/1.0.11/base58.js +0 -131
  305. package/esm/deps/jsr.io/@std/encoding/1.0.11/base64.d.ts +0 -39
  306. package/esm/deps/jsr.io/@std/encoding/1.0.11/base64.js +0 -82
  307. package/esm/deps/jsr.io/@std/encoding/1.0.11/base64url.d.ts +0 -39
  308. package/esm/deps/jsr.io/@std/encoding/1.0.11/base64url.js +0 -72
  309. package/esm/deps/jsr.io/@std/encoding/1.0.11/hex.d.ts +0 -38
  310. package/esm/deps/jsr.io/@std/encoding/1.0.11/hex.js +0 -87
  311. package/esm/deps/jsr.io/@std/encoding/1.0.11/mod.d.ts +0 -97
  312. package/esm/deps/jsr.io/@std/encoding/1.0.11/mod.js +0 -99
  313. package/esm/deps/jsr.io/@std/encoding/1.0.11/varint.d.ts +0 -119
  314. package/esm/deps/jsr.io/@std/encoding/1.0.11/varint.js +0 -209
  315. package/esm/deps/jsr.io/@std/http/1.1.3/status.d.ts +0 -343
  316. package/esm/deps/jsr.io/@std/http/1.1.3/status.js +0 -343
  317. package/esm/deps/jsr.io/@std/internal/1.0.14/assertion_state.d.ts +0 -159
  318. package/esm/deps/jsr.io/@std/internal/1.0.14/assertion_state.js +0 -223
  319. package/esm/deps/jsr.io/@std/internal/1.0.14/build_message.d.ts +0 -79
  320. package/esm/deps/jsr.io/@std/internal/1.0.14/build_message.js +0 -116
  321. package/esm/deps/jsr.io/@std/internal/1.0.14/diff.d.ts +0 -139
  322. package/esm/deps/jsr.io/@std/internal/1.0.14/diff.js +0 -277
  323. package/esm/deps/jsr.io/@std/internal/1.0.14/diff_str.d.ts +0 -98
  324. package/esm/deps/jsr.io/@std/internal/1.0.14/diff_str.js +0 -181
  325. package/esm/deps/jsr.io/@std/internal/1.0.14/format.d.ts +0 -29
  326. package/esm/deps/jsr.io/@std/internal/1.0.14/format.js +0 -68
  327. package/esm/deps/jsr.io/@std/internal/1.0.14/styles.d.ts +0 -158
  328. package/esm/deps/jsr.io/@std/internal/1.0.14/styles.js +0 -206
  329. package/esm/deps/jsr.io/@std/internal/1.0.14/types.d.ts +0 -24
  330. package/esm/deps/jsr.io/@std/internal/1.0.14/types.js +0 -3
  331. package/esm/deps/jsr.io/@std/testing/1.0.20/_test_suite.d.ts +0 -91
  332. package/esm/deps/jsr.io/@std/testing/1.0.20/_test_suite.js +0 -347
  333. package/esm/deps/jsr.io/@std/testing/1.0.20/bdd.d.ts +0 -382
  334. package/esm/deps/jsr.io/@std/testing/1.0.20/bdd.js +0 -1110
  335. package/esm/deps/jsr.io/@udibo/http-error/0.11.1/mod.d.ts +0 -363
  336. package/esm/deps/jsr.io/@udibo/http-error/0.11.1/mod.js +0 -616
  337. package/esm/package.json +0 -3
  338. /package/{esm → dist}/adapters/hono/bff/cookie-prefix.d.ts +0 -0
  339. /package/{esm → dist}/adapters/hono/bff/proxy.d.ts +0 -0
  340. /package/{esm → dist}/client/_http.js +0 -0
  341. /package/{esm → dist}/client/base.js +0 -0
  342. /package/{esm → dist}/client/browser-storage.js +0 -0
  343. /package/{esm → dist}/client/check.d.ts +0 -0
  344. /package/{esm → dist}/client/events.js +0 -0
  345. /package/{esm → dist}/client/storage.d.ts +0 -0
  346. /package/{esm → dist}/client/storage.js +0 -0
  347. /package/{esm → dist}/identity/captcha.d.ts +0 -0
  348. /package/{esm → dist}/identity/captcha.js +0 -0
  349. /package/{esm → dist}/identity/delivery.d.ts +0 -0
  350. /package/{esm → dist}/identity/delivery.js +0 -0
  351. /package/{esm → dist}/identity/errors.d.ts +0 -0
  352. /package/{esm → dist}/identity/errors.js +0 -0
  353. /package/{esm → dist}/identity/events.js +0 -0
  354. /package/{esm → dist}/identity/external/_token-exchange.d.ts +0 -0
  355. /package/{esm → dist}/identity/external/_token-exchange.js +0 -0
  356. /package/{esm → dist}/identity/external/errors.d.ts +0 -0
  357. /package/{esm → dist}/identity/external/errors.js +0 -0
  358. /package/{esm → dist}/identity/external/provider.d.ts +0 -0
  359. /package/{esm → dist}/identity/external/provider.js +0 -0
  360. /package/{esm → dist}/identity/identifier.d.ts +0 -0
  361. /package/{esm → dist}/identity/identifier.js +0 -0
  362. /package/{esm → dist}/identity/lockout.d.ts +0 -0
  363. /package/{esm → dist}/identity/mfa/recovery-codes.d.ts +0 -0
  364. /package/{esm → dist}/identity/mfa/recovery-codes.js +0 -0
  365. /package/{esm → dist}/identity/password-policy.d.ts +0 -0
  366. /package/{esm → dist}/identity/password-policy.js +0 -0
  367. /package/{esm → dist}/identity/password.d.ts +0 -0
  368. /package/{esm → dist}/identity/rate-limit.js +0 -0
  369. /package/{esm → dist}/identity/session.d.ts +0 -0
  370. /package/{esm → dist}/identity/token-flow.d.ts +0 -0
  371. /package/{esm → dist}/models/authentication.d.ts +0 -0
  372. /package/{esm → dist}/models/authentication.js +0 -0
  373. /package/{esm → dist}/models/authorization-code.js +0 -0
  374. /package/{esm → dist}/models/client.d.ts +0 -0
  375. /package/{esm → dist}/models/client.js +0 -0
  376. /package/{esm → dist}/models/device-authorization.js +0 -0
  377. /package/{esm → dist}/models/responses.d.ts +0 -0
  378. /package/{esm → dist}/models/responses.js +0 -0
  379. /package/{esm → dist}/models/scope.d.ts +0 -0
  380. /package/{esm → dist}/models/scope.js +0 -0
  381. /package/{esm → dist}/models/token.js +0 -0
  382. /package/{esm → dist}/react/components/types.js +0 -0
  383. /package/{esm → dist}/react/context.js +0 -0
  384. /package/{esm → dist}/react/provider.js +0 -0
  385. /package/{esm → dist}/react/require-auth.d.ts +0 -0
  386. /package/{esm → dist}/react/use-authorization.js +0 -0
  387. /package/{esm → dist}/server/_clock-skew.d.ts +0 -0
  388. /package/{esm → dist}/server/client-authentication.js +0 -0
  389. /package/{esm → dist}/server/grants/client-credentials.js +0 -0
  390. /package/{esm → dist}/server/grants/password.js +0 -0
  391. /package/{esm → dist}/server/redirect-uri.d.ts +0 -0
  392. /package/{esm → dist}/server/services/authorization-code.js +0 -0
  393. /package/{esm → dist}/server/services/client.js +0 -0
  394. /package/{esm → dist}/server/services/device-authorization.js +0 -0
  395. /package/{esm → dist}/server/services/user.js +0 -0
  396. /package/{esm → dist}/server/utils/hash.d.ts +0 -0
  397. /package/{esm → dist}/testing/contract/_race.d.ts +0 -0
  398. /package/{esm → dist}/testing/contract/_race.js +0 -0
  399. /package/{esm → dist}/testing/contract/tenant.d.ts +0 -0
  400. /package/{esm → dist}/utils/_body.d.ts +0 -0
  401. /package/{esm → dist}/utils/_body.js +0 -0
  402. /package/{esm → dist}/utils/_buffer.d.ts +0 -0
  403. /package/{esm → dist}/utils/_buffer.js +0 -0
  404. /package/{esm → dist}/utils/_default-fetch.d.ts +0 -0
  405. /package/{esm → dist}/utils/_timing-safe.d.ts +0 -0
  406. /package/{esm → dist}/utils/_timing-safe.js +0 -0
  407. /package/{esm → dist}/utils/authentication-context.js +0 -0
  408. /package/{esm → dist}/utils/basic-auth.d.ts +0 -0
  409. /package/{esm → dist}/utils/basic-auth.js +0 -0
  410. /package/{esm → dist}/utils/pkce.d.ts +0 -0
  411. /package/{esm → dist}/utils/text.d.ts +0 -0
@@ -1,616 +0,0 @@
1
- import { STATUS_CODE, STATUS_TEXT } from "../../../@std/http/1.1.3/status.js";
2
- /**
3
- * Default user-friendly messages for HTTP error status codes.
4
- * These are only used when expose is false and no exposedMessage was explicitly set.
5
- */
6
- const DEFAULT_EXPOSED_MESSAGES = {
7
- // 4xx Client Errors
8
- 400: "The server cannot process the request due to a client error.",
9
- 401: "Authentication is required to access this resource.",
10
- 402: "Payment is required to access this resource.",
11
- 403: "You do not have permission to access this resource.",
12
- 404: "The requested resource could not be found.",
13
- 405: "The request method is not supported for this resource.",
14
- 406: "The server cannot produce a response matching the acceptable values.",
15
- 407: "Proxy authentication is required.",
16
- 408: "The server timed out waiting for the request.",
17
- 409: "The request conflicts with the current state of the resource.",
18
- 410: "The requested resource is no longer available.",
19
- 411: "The request requires a Content-Length header.",
20
- 412: "A precondition in the request headers was not met.",
21
- 413: "The request body is larger than the server is willing to process.",
22
- 414: "The request URI is longer than the server is willing to process.",
23
- 415: "The request uses a media type that is not supported.",
24
- 416: "The requested range cannot be satisfied.",
25
- 417: "The expectation in the Expect header cannot be met.",
26
- 418: "The server refuses to brew coffee because it is a teapot.",
27
- 421: "The request was directed at a server unable to produce a response.",
28
- 422: "The request was well-formed but contained semantic errors.",
29
- 423: "The requested resource is locked.",
30
- 424: "The request failed due to a previous request failure.",
31
- 425: "The server is unwilling to process a request that might be replayed.",
32
- 426: "The client must upgrade to a different protocol.",
33
- 428: "The request must be conditional.",
34
- 429: "Too many requests have been sent in a given amount of time.",
35
- 431: "The request headers are too large.",
36
- 451: "The resource is unavailable for legal reasons.",
37
- // 5xx Server Errors
38
- 500: "The server encountered an unexpected condition.",
39
- 501: "The server does not support the functionality required.",
40
- 502: "The server received an invalid response from an upstream server.",
41
- 503: "The server is currently unavailable.",
42
- 504: "The server did not receive a timely response from an upstream server.",
43
- 505: "The HTTP version used in the request is not supported.",
44
- 506: "The server has an internal configuration error.",
45
- 507: "The server has insufficient storage to complete the request.",
46
- 508: "The server detected an infinite loop while processing the request.",
47
- 510: "Further extensions to the request are required.",
48
- 511: "Network authentication is required to access this resource.",
49
- };
50
- /**
51
- * Gets the default exposed message for a given HTTP error status code.
52
- * Falls back to generic client/server error messages for unknown status codes.
53
- */
54
- function defaultExposedMessageForStatus(status) {
55
- return DEFAULT_EXPOSED_MESSAGES[status] ??
56
- (status < 500 ? "A client error occurred." : "A server error occurred.");
57
- }
58
- function isProblemDetails(value) {
59
- return typeof value === "object" && value !== null && ("status" in value ||
60
- "title" in value ||
61
- "type" in value);
62
- }
63
- /**
64
- * Converts HttpError arguments to an options object.
65
- * Prioritizing status and message arguments over status and message options.
66
- *
67
- * This function is useful for creating custom error classes that extend HttpError.
68
- *
69
- * ```ts
70
- * import {
71
- * HttpError,
72
- * type HttpErrorOptions,
73
- * optionsFromArgs,
74
- * } from "@udibo/http-error";
75
- *
76
- * class CustomError extends HttpError {
77
- * constructor(
78
- * status?: number,
79
- * message?: string,
80
- * options?: HttpErrorOptions,
81
- * );
82
- * constructor(status?: number, options?: HttpErrorOptions);
83
- * constructor(message?: string, options?: HttpErrorOptions);
84
- * constructor(options?: HttpErrorOptions);
85
- * constructor(
86
- * statusOrMessageOrOptions?: number | string | HttpErrorOptions,
87
- * messageOrOptions?: string | HttpErrorOptions,
88
- * options?: HttpErrorOptions,
89
- * ) {
90
- * const init = optionsFromArgs(
91
- * statusOrMessageOrOptions,
92
- * messageOrOptions,
93
- * options,
94
- * );
95
- * super({ name: "CustomError", status: 420, ...init });
96
- * }
97
- * }
98
- * ```
99
- *
100
- * @param statusOrMessageOrOptions - The status, message, or options.
101
- * @param messageOrOptions - The message or options.
102
- * @param options - The options.
103
- * @returns The options object.
104
- */
105
- function optionsFromArgs(statusOrMessageOrOptions, messageOrOptions, options) {
106
- let status = undefined;
107
- let message = undefined;
108
- let init = options;
109
- if (typeof statusOrMessageOrOptions === "number") {
110
- status = statusOrMessageOrOptions;
111
- if (typeof messageOrOptions === "string") {
112
- message = messageOrOptions;
113
- }
114
- else if (messageOrOptions) {
115
- init = messageOrOptions;
116
- message = init?.message;
117
- }
118
- }
119
- else if (typeof statusOrMessageOrOptions === "string") {
120
- message = statusOrMessageOrOptions;
121
- init = messageOrOptions;
122
- status = init?.status ?? status;
123
- }
124
- else if (typeof messageOrOptions === "string") {
125
- message = messageOrOptions;
126
- }
127
- else if (!init) {
128
- init = messageOrOptions ? messageOrOptions : statusOrMessageOrOptions;
129
- status = init?.status ?? status;
130
- message = init?.message;
131
- }
132
- return { ...init, status, message };
133
- }
134
- /**
135
- * Gets the human-readable name for a given HTTP error status code.
136
- * Returns names with spaces (e.g., "Bad Request", "Not Found").
137
- */
138
- function errorNameForStatus(status) {
139
- if (STATUS_TEXT[status]) {
140
- return STATUS_TEXT[status];
141
- }
142
- return status < 500 ? "Unknown Client Error" : "Unknown Server Error";
143
- }
144
- /**
145
- * Checks if a name matches the old error name format for a given status.
146
- * The old format was "{StatusText}Error" (e.g., "BadRequestError" for 400).
147
- * This is used to convert old-format names to the new human-readable format
148
- * when processing errors from other frameworks.
149
- */
150
- function matchesOldNameFormat(name, status) {
151
- if (!name)
152
- return false;
153
- const statusText = STATUS_TEXT[status];
154
- if (!statusText)
155
- return false;
156
- const oldFormat = statusText.replace(/\W/g, "") + "Error";
157
- return name === oldFormat;
158
- }
159
- /**
160
- * An error for an HTTP request.
161
- *
162
- * This class can be used on its own to create any HttpError. It has a few
163
- * different call signatures you can use. The 4 examples below would throw the same
164
- * error.
165
- *
166
- * ```ts
167
- * import { HttpError } from "@udibo/http-error";
168
- *
169
- * throw new HttpError(404, "file not found");
170
- * throw new HttpError(404, { message: "file not found" });
171
- * throw new HttpError("file not found", { status: 404 });
172
- * throw new HttpError({ status: 404, message: "file not found" });
173
- * ```
174
- *
175
- * You can also include a cause in the optional options argument for it like you
176
- * can with regular errors.
177
- *
178
- * ```ts
179
- * import { HttpError } from "@udibo/http-error";
180
- *
181
- * throw new HttpError(404, "file not found", { cause: error });
182
- * ```
183
- *
184
- * All HttpError objects have a status associated with them. If a status is not
185
- * provided it will default to 500. The expose property will default to true for
186
- * client error status and false for server error status. You can override the
187
- * default behavior by setting the expose property on the options argument.
188
- *
189
- * For all known HTTP error status codes, a name will be generated for them. For
190
- * example, the name of an HttpError with the 404 status would be NotFoundError. If
191
- * the name is not known for an HTTP error status code, it will default to
192
- * UnknownClientError or UnknownServerError.
193
- *
194
- * ```ts
195
- * import { HttpError } from "@udibo/http-error";
196
- *
197
- * const error = new HttpError(404, "file not found");
198
- * console.log(error.toString()); // NotFoundError: file not found
199
- * ```
200
- *
201
- * If you would like to extend the HttpError class, you can pass your own error
202
- * name in the options.
203
- *
204
- * ```ts
205
- * import { HttpError, type HttpErrorOptions } from "@udibo/http-error";
206
- *
207
- * class CustomError extends HttpError {
208
- * constructor(
209
- * message?: string,
210
- * options?: HttpErrorOptions,
211
- * ) {
212
- * super(message, { name: "CustomError", status: 420, ...options });
213
- * }
214
- * }
215
- * ```
216
- *
217
- * If you'd like the arguments to match the parent HttpError classes call
218
- * signature, you can make use of the optionsFromArgs function. It will prioritize
219
- * the status / message arguments over status / message options.
220
- *
221
- * ```ts
222
- * import {
223
- * HttpError,
224
- * type HttpErrorOptions,
225
- * optionsFromArgs,
226
- * } from "@udibo/http-error";
227
- *
228
- * class CustomError extends HttpError {
229
- * constructor(
230
- * status?: number,
231
- * message?: string,
232
- * options?: HttpErrorOptions,
233
- * );
234
- * constructor(status?: number, options?: HttpErrorOptions);
235
- * constructor(message?: string, options?: HttpErrorOptions);
236
- * constructor(options?: HttpErrorOptions);
237
- * constructor(
238
- * statusOrMessageOrOptions?: number | string | HttpErrorOptions,
239
- * messageOrOptions?: string | HttpErrorOptions,
240
- * options?: HttpErrorOptions,
241
- * ) {
242
- * const init = optionsFromArgs(
243
- * statusOrMessageOrOptions,
244
- * messageOrOptions,
245
- * options,
246
- * );
247
- * super({ name: "CustomError", status: 420, ...init });
248
- * }
249
- * }
250
- * ```
251
- *
252
- * The HttpError class also provides `toJSON()` and `getResponse()` methods to
253
- * convert errors into RFC 9457 Problem Details objects or Response objects,
254
- * respectively. This makes it easy to return standardized error responses from
255
- * your HTTP APIs.
256
- *
257
- * ```ts
258
- * import { HttpError } from "@udibo/http-error";
259
- *
260
- * const error = new HttpError(403, "Access denied", {
261
- * type: "/errors/forbidden",
262
- * instance: "/docs/123/edit",
263
- * extensions: { accountId: "user-abc" },
264
- * });
265
- *
266
- * // Get Problem Details object
267
- * const problemDetails = error.toJSON();
268
- * console.log(problemDetails);
269
- * // Output:
270
- * // {
271
- * // accountId: "user-abc",
272
- * // status: 403,
273
- * // title: "ForbiddenError",
274
- * // detail: "Access denied",
275
- * // type: "/errors/forbidden",
276
- * // instance: "/docs/123/edit"
277
- * // }
278
- *
279
- * // Get a Response object
280
- * const response = error.getResponse();
281
- * console.log(response.status); // 403
282
- * response.json().then(body => console.log(body)); // Same as problemDetails
283
- * ```
284
- *
285
- * @typeparam Extensions - Other data associated with the error that will be included in the error response.
286
- * @param status - The HTTP status associated with the error.
287
- * @param message - The message associated with the error.
288
- * @param options - Other data associated with the error.
289
- * @returns An HttpError object.
290
- */
291
- export class HttpError extends Error {
292
- /**
293
- * The HTTP status associated with the error.
294
- * Must be a client or server error status. Defaults to 500.
295
- */
296
- status;
297
- /** The HTTP status text associated with the error. */
298
- statusText;
299
- /**
300
- * Determines if the error detail should be exposed in the response.
301
- * Defaults to true for client error statuses and false for server error statuses.
302
- */
303
- expose;
304
- /**
305
- * The type of the error is a URI reference that identifies the problem type.
306
- */
307
- type;
308
- /**
309
- * The instance of the error is a URI reference that identifies the specific occurrence of the problem.
310
- */
311
- instance;
312
- /**
313
- * Other data associated with the error that will be included in the error response.
314
- */
315
- extensions;
316
- /**
317
- * The headers to send in the response. The content-type will default to application/problem+json unless otherwise specified in the headers.
318
- */
319
- headers;
320
- /**
321
- * The message to expose in the response. Used as the `detail` field in toJSON().
322
- * - If explicitly set in options, that value is used
323
- * - If expose is true and message exists, defaults to message
324
- * - Otherwise, defaults to a generic message for the status code
325
- *
326
- * Use this instead of `message` when rendering errors to prevent leaking internal details.
327
- */
328
- exposedMessage;
329
- constructor(statusOrMessageOrOptions, messageOrOptions, options) {
330
- const init = optionsFromArgs(statusOrMessageOrOptions, messageOrOptions, options);
331
- const { message, name, expose, status: _status, statusText, cause, type, instance, extensions, headers, exposedMessage, } = init;
332
- const status = init.status ?? STATUS_CODE.InternalServerError;
333
- if (status < 400 || status >= 600) {
334
- throw new RangeError("invalid error status");
335
- }
336
- const errorOptions = {};
337
- if (typeof cause !== "undefined")
338
- errorOptions.cause = cause;
339
- super(message, errorOptions);
340
- Object.defineProperty(this, "name", {
341
- configurable: true,
342
- enumerable: false,
343
- value: name ?? errorNameForStatus(status),
344
- writable: true,
345
- });
346
- this.status = status;
347
- if (statusText)
348
- this.statusText = statusText;
349
- if (type)
350
- this.type = type;
351
- if (instance)
352
- this.instance = instance;
353
- this.expose = expose ?? (status < 500);
354
- this.extensions = extensions ?? {};
355
- this.headers = headers instanceof Headers
356
- ? headers
357
- : new Headers(headers ?? {});
358
- if (!this.headers.has("content-type")) {
359
- this.headers.set("content-type", "application/problem+json");
360
- }
361
- // Compute exposedMessage with precedence:
362
- // 1. Explicitly provided exposedMessage option
363
- // 2. If expose=true and message exists, use message
364
- // 3. Default message for status code
365
- this.exposedMessage = exposedMessage ??
366
- (this.expose && this.message
367
- ? this.message
368
- : defaultExposedMessageForStatus(status));
369
- }
370
- static from(error) {
371
- if (error instanceof HttpError) {
372
- return error;
373
- }
374
- else if (isHttpErrorLike(error)) {
375
- const { name: originalName, message, status, expose, cause, type, instance, extensions, headers, exposedMessage, } = error;
376
- // Use new format if name matches old format, otherwise preserve custom name
377
- const name = matchesOldNameFormat(originalName, status)
378
- ? undefined
379
- : originalName;
380
- const options = {
381
- name,
382
- message,
383
- status,
384
- expose,
385
- cause,
386
- type,
387
- instance,
388
- extensions,
389
- exposedMessage,
390
- headers,
391
- };
392
- return new HttpError(options);
393
- }
394
- else if (error instanceof Error) {
395
- return new HttpError(500, error.message, {
396
- cause: error,
397
- });
398
- }
399
- else if (error instanceof Response) {
400
- return error.json()
401
- .then((json) => {
402
- if (!isProblemDetails(json)) {
403
- return new HttpError(500, "invalid problem details response", {
404
- cause: json,
405
- });
406
- }
407
- const { status, title, detail, type, instance, ...extensions } = json;
408
- const options = {
409
- status: status || error.status,
410
- name: title,
411
- message: detail,
412
- type,
413
- instance,
414
- extensions: extensions,
415
- };
416
- return new HttpError(options);
417
- })
418
- .catch((parseError) => {
419
- return new HttpError(500, "could not parse problem details response", { cause: parseError });
420
- });
421
- }
422
- else if (isProblemDetails(error)) {
423
- const { status, title, detail, type, instance, ...extensions } = error;
424
- const options = {
425
- status,
426
- name: title,
427
- message: detail,
428
- type,
429
- instance,
430
- extensions: extensions,
431
- };
432
- return new HttpError(options);
433
- }
434
- else {
435
- return new HttpError(500, "unexpected error type", {
436
- cause: error,
437
- });
438
- }
439
- }
440
- /**
441
- * Converts the HttpError to a ProblemDetails object that matches the RFC 9457
442
- * Problem Details for HTTP APIs specification. This object is suitable for
443
- * direct serialization into a JSON response body.
444
- *
445
- * @returns A ProblemDetails object representing the error, compliant with RFC 9457.
446
- */
447
- toJSON() {
448
- const json = {
449
- ...this.extensions,
450
- status: this.status,
451
- title: this.name,
452
- detail: this.exposedMessage,
453
- };
454
- if (this.type) {
455
- json.type = this.type;
456
- }
457
- if (this.instance) {
458
- json.instance = this.instance;
459
- }
460
- return json;
461
- }
462
- /**
463
- * Converts the HttpError to a Response object that matches the RFC 9457
464
- * Problem Details for HTTP APIs specification. The body of the response will
465
- * be a JSON string representing the ProblemDetails object.
466
- *
467
- * @returns A Response object suitable for returning from an HTTP handler, compliant with RFC 9457.
468
- */
469
- getResponse() {
470
- const options = {
471
- status: this.status,
472
- headers: this.headers,
473
- };
474
- if (this.statusText)
475
- options.statusText = this.statusText;
476
- return new Response(JSON.stringify(this.toJSON()), options);
477
- }
478
- }
479
- /**
480
- * Checks if a value is HttpError-like (an Error with a numeric status property).
481
- *
482
- * This function returns true for any Error object that has a numeric `status` property,
483
- * not just HttpError instances. This allows it to recognize HTTP errors from other
484
- * libraries or custom error classes that follow the same pattern.
485
- *
486
- * If you need to verify that an error is specifically an HttpError instance
487
- * (not just similar to one), use `error instanceof HttpError` instead.
488
- *
489
- * ```ts
490
- * import { HttpError, isHttpErrorLike } from "@udibo/http-error";
491
- *
492
- * let error = new Error("file not found");
493
- * console.log(isHttpErrorLike(error)); // false
494
- *
495
- * error = new HttpError(404, "file not found");
496
- * console.log(isHttpErrorLike(error)); // true
497
- * console.log(error instanceof HttpError); // true
498
- *
499
- * // Custom error class with status property
500
- * class CustomHttpError extends Error {
501
- * status = 400;
502
- * }
503
- * const customError = new CustomHttpError("bad request");
504
- * console.log(isHttpErrorLike(customError)); // true
505
- * console.log(customError instanceof HttpError); // false
506
- * ```
507
- *
508
- * @param value - The value to check.
509
- * @returns True if the value is an HttpError or an Error with a numeric status property.
510
- */
511
- export function isHttpErrorLike(value) {
512
- return typeof value === "object" && value !== null &&
513
- (value instanceof HttpError ||
514
- (value instanceof Error &&
515
- typeof value.status === "number"));
516
- }
517
- /**
518
- * Creates a new class that extends HttpError, allowing for predefined default
519
- * options and a specific default type for extensions.
520
- *
521
- * This factory is useful for creating custom HttpError types tailored to specific
522
- * kinds of errors in an application, each with its own default status, name,
523
- * or custom extension fields.
524
- *
525
- * @example
526
- * ```ts
527
- * // Define a type for default extensions
528
- * interface MyApiErrorExtensions {
529
- * errorCode: string;
530
- * requestId?: string;
531
- * }
532
- *
533
- * // Create a custom error class with defaults
534
- * const MyApiError = createHttpErrorClass<MyApiErrorExtensions>({
535
- * name: "MyApiError",
536
- * status: 452, // Custom default status
537
- * extensions: {
538
- * errorCode: "API_GENERAL_FAILURE", // Default extension value
539
- * },
540
- * });
541
- *
542
- * // Usage of the custom error class
543
- * try {
544
- * // Simulate an error condition
545
- * throw new MyApiError("A specific API operation failed.", {
546
- * extensions: {
547
- * errorCode: "API_OPERATION_X_FAILED", // Override default extension
548
- * requestId: "req-12345", // Add instance-specific extension
549
- * },
550
- * });
551
- * } catch (e) {
552
- * if (e instanceof MyApiError) {
553
- * console.log(e.name); // "MyApiError"
554
- * console.log(e.status); // 452
555
- * console.log(e.message); // "A specific API operation failed."
556
- * console.log(e.extensions.errorCode); // "API_OPERATION_X_FAILED"
557
- * console.log(e.extensions.requestId); // "req-12345"
558
- * // console.log(e.toJSON());
559
- * }
560
- * }
561
- *
562
- * // Example with a different status code at instantiation
563
- * const anotherError = new MyApiError(453, "Another failure");
564
- * console.log(anotherError.status) // 453
565
- * console.log(anotherError.extensions.errorCode) // "API_GENERAL_FAILURE"
566
- * ```
567
- *
568
- * @typeparam DefaultExtensions The type for the default `extensions` object. Defaults to `Record<string, unknown>`.
569
- * @param defaultOptionsForClass Optional default HttpErrorOptions to apply to the new error class.
570
- * @returns A new class that extends `HttpError`.
571
- */
572
- export function createHttpErrorClass(defaultOptionsForClass) {
573
- return class CustomHttpError extends HttpError {
574
- constructor(statusOrMessageOrOptions, messageOrOptions, optionsArgument) {
575
- const constructorTimeOptions = optionsFromArgs(statusOrMessageOrOptions, messageOrOptions, optionsArgument);
576
- const dfo = defaultOptionsForClass;
577
- const finalOptions = {};
578
- finalOptions.status = constructorTimeOptions.status !== undefined
579
- ? constructorTimeOptions.status
580
- : dfo?.status;
581
- finalOptions.message = constructorTimeOptions.message !== undefined
582
- ? constructorTimeOptions.message
583
- : dfo?.message;
584
- finalOptions.name = constructorTimeOptions.name !== undefined
585
- ? constructorTimeOptions.name
586
- : dfo?.name;
587
- finalOptions.expose = constructorTimeOptions.expose !== undefined
588
- ? constructorTimeOptions.expose
589
- : dfo?.expose;
590
- finalOptions.cause = constructorTimeOptions.cause !== undefined
591
- ? constructorTimeOptions.cause
592
- : dfo?.cause;
593
- finalOptions.type = constructorTimeOptions.type !== undefined
594
- ? constructorTimeOptions.type
595
- : dfo?.type;
596
- finalOptions.instance = constructorTimeOptions.instance !== undefined
597
- ? constructorTimeOptions.instance
598
- : dfo?.instance;
599
- finalOptions.headers = constructorTimeOptions.headers !== undefined
600
- ? constructorTimeOptions.headers
601
- : dfo?.headers;
602
- finalOptions.statusText = constructorTimeOptions.statusText !== undefined
603
- ? constructorTimeOptions.statusText
604
- : dfo?.statusText;
605
- finalOptions.exposedMessage =
606
- constructorTimeOptions.exposedMessage !== undefined
607
- ? constructorTimeOptions.exposedMessage
608
- : dfo?.exposedMessage;
609
- finalOptions.extensions = {
610
- ...(dfo?.extensions),
611
- ...(constructorTimeOptions.extensions),
612
- };
613
- super(finalOptions);
614
- }
615
- };
616
- }
package/esm/package.json DELETED
@@ -1,3 +0,0 @@
1
- {
2
- "type": "module"
3
- }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes