@zudojs/errors 0.1.1 → 1.0.1

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 (506) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +29 -8
  3. package/dist/base/core/baseError.core.d.ts +25 -2
  4. package/dist/base/core/baseError.core.js +95 -23
  5. package/dist/base/core/errorMetadata.core.d.ts +62 -5
  6. package/dist/base/core/errorMetadata.core.js +292 -23
  7. package/dist/base/types/errorCategory.helpers.js +3 -2
  8. package/dist/base/types/errorCode.type.d.ts +70 -1
  9. package/dist/base/types/errorCode.type.js +78 -2
  10. package/dist/base/types/errorSeverity.type.js +3 -2
  11. package/dist/base/utils/baseError.utils.d.ts +18 -2
  12. package/dist/base/utils/baseError.utils.js +68 -17
  13. package/dist/domain/access/rateLimit.error.d.ts +6 -1
  14. package/dist/domain/access/rateLimit.error.js +7 -9
  15. package/dist/domain/api/apiError.base.js +2 -2
  16. package/dist/domain/api/apiError.lifecycle.d.ts +10 -1
  17. package/dist/domain/api/apiError.lifecycle.js +22 -7
  18. package/dist/domain/api/apiError.routing.js +4 -4
  19. package/dist/domain/app/domain.error.d.ts +2 -0
  20. package/dist/domain/app/domain.error.js +3 -1
  21. package/dist/domain/app/lifecycleError.types.js +2 -8
  22. package/dist/domain/app/moduleError.types.d.ts +3 -0
  23. package/dist/domain/app/moduleError.types.js +6 -2
  24. package/dist/domain/body/bodyParser.error.d.ts +9 -2
  25. package/dist/domain/body/bodyParser.error.js +20 -12
  26. package/dist/domain/body/httpBodyError.base.js +1 -2
  27. package/dist/domain/body/httpBodyError.types.js +1 -3
  28. package/dist/domain/body/httpFormData.error.js +2 -4
  29. package/dist/domain/body/multipart.error.js +2 -4
  30. package/dist/domain/documentation/documentationError.base.js +4 -2
  31. package/dist/domain/documentation/documentationError.types.js +1 -11
  32. package/dist/domain/documentation/index.d.ts +1 -1
  33. package/dist/domain/documentation/index.js +1 -1
  34. package/dist/domain/event/event.error.d.ts +1 -1
  35. package/dist/domain/event/event.error.js +1 -1
  36. package/dist/domain/event/eventError.base.d.ts +4 -1
  37. package/dist/domain/event/eventError.base.js +7 -9
  38. package/dist/domain/event/eventError.handler.d.ts +12 -3
  39. package/dist/domain/event/eventError.handler.js +21 -11
  40. package/dist/domain/event/eventError.lifecycle.d.ts +20 -3
  41. package/dist/domain/event/eventError.lifecycle.js +48 -18
  42. package/dist/domain/event/eventError.serialization.d.ts +10 -2
  43. package/dist/domain/event/eventError.serialization.js +16 -4
  44. package/dist/domain/message/message.error.d.ts +1 -0
  45. package/dist/domain/message/message.error.js +1 -0
  46. package/dist/domain/message/messageError.base.d.ts +4 -1
  47. package/dist/domain/message/messageError.base.js +7 -9
  48. package/dist/domain/message/messageError.handler.d.ts +12 -3
  49. package/dist/domain/message/messageError.handler.js +22 -12
  50. package/dist/domain/message/messageError.lifecycle.d.ts +5 -1
  51. package/dist/domain/message/messageError.lifecycle.js +15 -8
  52. package/dist/domain/message/messageError.serialization.d.ts +26 -0
  53. package/dist/domain/message/messageError.serialization.js +35 -0
  54. package/dist/domain/plugin/pluginError.lifecycle.js +23 -21
  55. package/dist/domain/plugin/pluginError.runtime.d.ts +5 -1
  56. package/dist/domain/plugin/pluginError.runtime.js +12 -7
  57. package/dist/domain/queue/queueError.base.d.ts +19 -0
  58. package/dist/domain/queue/queueError.base.js +24 -4
  59. package/dist/domain/queue/queueError.job.js +2 -0
  60. package/dist/domain/queue/queueError.worker.d.ts +9 -3
  61. package/dist/domain/queue/queueError.worker.js +14 -6
  62. package/dist/domain/rpc/rpcError.base.js +0 -2
  63. package/dist/domain/rpc/rpcError.protocol.js +0 -7
  64. package/dist/domain/rpc/rpcError.transport.d.ts +10 -1
  65. package/dist/domain/rpc/rpcError.transport.js +19 -9
  66. package/dist/domain/scheduler/schedulerError.base.d.ts +17 -3
  67. package/dist/domain/scheduler/schedulerError.base.js +26 -15
  68. package/dist/domain/scheduler/schedulerError.execution.d.ts +7 -6
  69. package/dist/domain/scheduler/schedulerError.execution.js +22 -18
  70. package/dist/domain/scheduler/schedulerError.schedule.d.ts +15 -5
  71. package/dist/domain/scheduler/schedulerError.schedule.js +32 -14
  72. package/dist/domain/schema/index.d.ts +2 -1
  73. package/dist/domain/schema/index.js +1 -1
  74. package/dist/domain/schema/schemaError.base.d.ts +31 -5
  75. package/dist/domain/schema/schemaError.base.js +34 -6
  76. package/dist/domain/schema/schemaError.types.js +12 -5
  77. package/dist/domain/serialization/serializationError.base.d.ts +8 -2
  78. package/dist/domain/serialization/serializationError.base.js +38 -8
  79. package/dist/domain/serialization/serializationError.types.d.ts +22 -3
  80. package/dist/domain/serialization/serializationError.types.js +30 -5
  81. package/dist/domain/shared/domainError.helpers.d.ts +60 -0
  82. package/dist/domain/shared/domainError.helpers.js +191 -0
  83. package/dist/domain/state/conflict.error.d.ts +1 -1
  84. package/dist/domain/state/conflict.error.js +2 -2
  85. package/dist/domain/state/validationError.base.d.ts +8 -1
  86. package/dist/domain/state/validationError.base.js +11 -2
  87. package/dist/infrastructure/adapter/adapterError.base.js +6 -6
  88. package/dist/infrastructure/adapter/adapterError.lifecycle.js +0 -3
  89. package/dist/infrastructure/adapter/adapterError.operation.js +0 -5
  90. package/dist/infrastructure/cache/cacheError.base.js +1 -1
  91. package/dist/infrastructure/container/containerError.registration.js +6 -4
  92. package/dist/infrastructure/network/httpAdapter.error.js +4 -2
  93. package/dist/infrastructure/network/httpClientError.advanced.js +10 -18
  94. package/dist/infrastructure/network/httpClientError.base.d.ts +11 -0
  95. package/dist/infrastructure/network/httpClientError.base.js +47 -7
  96. package/dist/infrastructure/network/httpClientError.common.d.ts +14 -0
  97. package/dist/infrastructure/network/httpClientError.common.js +21 -31
  98. package/dist/infrastructure/network/httpClientError.specialized.js +5 -8
  99. package/dist/infrastructure/network/httpClientError.types.d.ts +23 -2
  100. package/dist/infrastructure/network/httpClientError.types.js +55 -42
  101. package/dist/infrastructure/network/httpResponse.error.js +0 -3
  102. package/dist/infrastructure/network/httpRouterError.base.js +0 -1
  103. package/dist/infrastructure/network/httpRouterError.types.d.ts +5 -3
  104. package/dist/infrastructure/network/httpRouterError.types.js +6 -7
  105. package/dist/infrastructure/network/httpServerError.error.js +6 -10
  106. package/dist/infrastructure/network/httpServerLifecycleError.base.js +0 -1
  107. package/dist/infrastructure/network/httpServerLifecycleError.types.js +0 -3
  108. package/dist/infrastructure/network/httpStream.error.js +0 -1
  109. package/dist/infrastructure/network/network.error.d.ts +1 -1
  110. package/dist/infrastructure/network/network.error.js +1 -1
  111. package/dist/infrastructure/network/networkError.factory.d.ts +9 -2
  112. package/dist/infrastructure/network/networkError.factory.js +9 -2
  113. package/dist/infrastructure/network/routePattern.error.d.ts +7 -6
  114. package/dist/infrastructure/network/routePattern.error.js +16 -8
  115. package/dist/infrastructure/network/timeoutError.base.d.ts +7 -0
  116. package/dist/infrastructure/network/timeoutError.base.js +12 -1
  117. package/dist/infrastructure/network/timeoutError.factory.d.ts +14 -0
  118. package/dist/infrastructure/network/timeoutError.factory.js +25 -17
  119. package/dist/infrastructure/service/externalService.error.d.ts +1 -1
  120. package/dist/infrastructure/service/externalService.error.js +1 -1
  121. package/dist/infrastructure/service/externalServiceError.base.d.ts +8 -0
  122. package/dist/infrastructure/service/externalServiceError.base.js +8 -11
  123. package/dist/infrastructure/service/externalServiceError.factory.d.ts +3 -1
  124. package/dist/infrastructure/service/externalServiceError.factory.js +3 -1
  125. package/dist/infrastructure/storage/databaseError.factory.js +1 -1
  126. package/dist/infrastructure/storage/storageError.factory.js +2 -2
  127. package/dist/system/cryptoError.factory.js +5 -2
  128. package/dist/system/runtimeError.base.js +1 -1
  129. package/dist/utils/errorHandler.core.d.ts +42 -8
  130. package/dist/utils/errorHandler.core.js +116 -63
  131. package/dist/utils/errorHandler.factory.d.ts +1 -1
  132. package/dist/utils/errorHandler.factory.js +2 -2
  133. package/dist/utils/errorHandler.types.d.ts +37 -1
  134. package/dist/utils/errorMapper.core.d.ts +1 -1
  135. package/dist/utils/errorMapper.core.js +1 -1
  136. package/dist/utils/errorMapper.mappers.d.ts +27 -6
  137. package/dist/utils/errorMapper.mappers.js +57 -49
  138. package/dist/utils/errorSerializer.core.d.ts +22 -3
  139. package/dist/utils/errorSerializer.core.js +144 -39
  140. package/dist/utils/errorSerializer.factory.d.ts +1 -1
  141. package/dist/utils/errorSerializer.factory.js +2 -26
  142. package/dist/utils/errorSerializer.types.d.ts +14 -4
  143. package/dist/utils/errorUtils.extraction.js +3 -2
  144. package/dist/utils/errorUtils.transform.d.ts +1 -1
  145. package/dist/utils/errorUtils.transform.js +2 -26
  146. package/dist/utils/errorUtils.typeCheck.js +7 -7
  147. package/package.json +25 -10
  148. package/dist/.tsbuildinfo +0 -1
  149. package/dist/base/core/baseError.core.d.ts.map +0 -1
  150. package/dist/base/core/baseError.core.js.map +0 -1
  151. package/dist/base/core/errorMetadata.core.d.ts.map +0 -1
  152. package/dist/base/core/errorMetadata.core.js.map +0 -1
  153. package/dist/base/core/errorMetadata.type.d.ts.map +0 -1
  154. package/dist/base/core/errorMetadata.type.js.map +0 -1
  155. package/dist/base/core/index.d.ts.map +0 -1
  156. package/dist/base/core/index.js.map +0 -1
  157. package/dist/base/index.d.ts.map +0 -1
  158. package/dist/base/index.js.map +0 -1
  159. package/dist/base/types/baseError.type.d.ts.map +0 -1
  160. package/dist/base/types/baseError.type.js.map +0 -1
  161. package/dist/base/types/errorCategory.enum.d.ts.map +0 -1
  162. package/dist/base/types/errorCategory.enum.js.map +0 -1
  163. package/dist/base/types/errorCategory.helpers.d.ts.map +0 -1
  164. package/dist/base/types/errorCategory.helpers.js.map +0 -1
  165. package/dist/base/types/errorCategory.type.d.ts.map +0 -1
  166. package/dist/base/types/errorCategory.type.js.map +0 -1
  167. package/dist/base/types/errorCode.type.d.ts.map +0 -1
  168. package/dist/base/types/errorCode.type.js.map +0 -1
  169. package/dist/base/types/errorSeverity.type.d.ts.map +0 -1
  170. package/dist/base/types/errorSeverity.type.js.map +0 -1
  171. package/dist/base/types/index.d.ts.map +0 -1
  172. package/dist/base/types/index.js.map +0 -1
  173. package/dist/base/utils/baseError.utils.d.ts.map +0 -1
  174. package/dist/base/utils/baseError.utils.js.map +0 -1
  175. package/dist/base/utils/index.d.ts.map +0 -1
  176. package/dist/base/utils/index.js.map +0 -1
  177. package/dist/domain/access/authentication.error.d.ts.map +0 -1
  178. package/dist/domain/access/authentication.error.js.map +0 -1
  179. package/dist/domain/access/authorization.error.d.ts.map +0 -1
  180. package/dist/domain/access/authorization.error.js.map +0 -1
  181. package/dist/domain/access/index.d.ts.map +0 -1
  182. package/dist/domain/access/index.js.map +0 -1
  183. package/dist/domain/access/rateLimit.error.d.ts.map +0 -1
  184. package/dist/domain/access/rateLimit.error.js.map +0 -1
  185. package/dist/domain/api/api.error.d.ts.map +0 -1
  186. package/dist/domain/api/api.error.js.map +0 -1
  187. package/dist/domain/api/apiError.base.d.ts.map +0 -1
  188. package/dist/domain/api/apiError.base.js.map +0 -1
  189. package/dist/domain/api/apiError.lifecycle.d.ts.map +0 -1
  190. package/dist/domain/api/apiError.lifecycle.js.map +0 -1
  191. package/dist/domain/api/apiError.routing.d.ts.map +0 -1
  192. package/dist/domain/api/apiError.routing.js.map +0 -1
  193. package/dist/domain/api/index.d.ts.map +0 -1
  194. package/dist/domain/api/index.js.map +0 -1
  195. package/dist/domain/app/application.error.d.ts.map +0 -1
  196. package/dist/domain/app/application.error.js.map +0 -1
  197. package/dist/domain/app/configuration.error.d.ts.map +0 -1
  198. package/dist/domain/app/configuration.error.js.map +0 -1
  199. package/dist/domain/app/domain.error.d.ts.map +0 -1
  200. package/dist/domain/app/domain.error.js.map +0 -1
  201. package/dist/domain/app/index.d.ts.map +0 -1
  202. package/dist/domain/app/index.js.map +0 -1
  203. package/dist/domain/app/lifecycle.error.d.ts.map +0 -1
  204. package/dist/domain/app/lifecycle.error.js.map +0 -1
  205. package/dist/domain/app/lifecycleError.base.d.ts.map +0 -1
  206. package/dist/domain/app/lifecycleError.base.js.map +0 -1
  207. package/dist/domain/app/lifecycleError.types.d.ts.map +0 -1
  208. package/dist/domain/app/lifecycleError.types.js.map +0 -1
  209. package/dist/domain/app/module.error.d.ts.map +0 -1
  210. package/dist/domain/app/module.error.js.map +0 -1
  211. package/dist/domain/app/moduleError.base.d.ts.map +0 -1
  212. package/dist/domain/app/moduleError.base.js.map +0 -1
  213. package/dist/domain/app/moduleError.types.d.ts.map +0 -1
  214. package/dist/domain/app/moduleError.types.js.map +0 -1
  215. package/dist/domain/body/bodyParser.error.d.ts.map +0 -1
  216. package/dist/domain/body/bodyParser.error.js.map +0 -1
  217. package/dist/domain/body/httpBody.error.d.ts.map +0 -1
  218. package/dist/domain/body/httpBody.error.js.map +0 -1
  219. package/dist/domain/body/httpBodyError.base.d.ts.map +0 -1
  220. package/dist/domain/body/httpBodyError.base.js.map +0 -1
  221. package/dist/domain/body/httpBodyError.types.d.ts.map +0 -1
  222. package/dist/domain/body/httpBodyError.types.js.map +0 -1
  223. package/dist/domain/body/httpFormData.error.d.ts.map +0 -1
  224. package/dist/domain/body/httpFormData.error.js.map +0 -1
  225. package/dist/domain/body/index.d.ts.map +0 -1
  226. package/dist/domain/body/index.js.map +0 -1
  227. package/dist/domain/body/multipart.error.d.ts.map +0 -1
  228. package/dist/domain/body/multipart.error.js.map +0 -1
  229. package/dist/domain/documentation/documentation.error.d.ts.map +0 -1
  230. package/dist/domain/documentation/documentation.error.js.map +0 -1
  231. package/dist/domain/documentation/documentationError.base.d.ts.map +0 -1
  232. package/dist/domain/documentation/documentationError.base.js.map +0 -1
  233. package/dist/domain/documentation/documentationError.types.d.ts.map +0 -1
  234. package/dist/domain/documentation/documentationError.types.js.map +0 -1
  235. package/dist/domain/documentation/index.d.ts.map +0 -1
  236. package/dist/domain/documentation/index.js.map +0 -1
  237. package/dist/domain/event/event.error.d.ts.map +0 -1
  238. package/dist/domain/event/event.error.js.map +0 -1
  239. package/dist/domain/event/eventError.base.d.ts.map +0 -1
  240. package/dist/domain/event/eventError.base.js.map +0 -1
  241. package/dist/domain/event/eventError.handler.d.ts.map +0 -1
  242. package/dist/domain/event/eventError.handler.js.map +0 -1
  243. package/dist/domain/event/eventError.lifecycle.d.ts.map +0 -1
  244. package/dist/domain/event/eventError.lifecycle.js.map +0 -1
  245. package/dist/domain/event/eventError.serialization.d.ts.map +0 -1
  246. package/dist/domain/event/eventError.serialization.js.map +0 -1
  247. package/dist/domain/event/index.d.ts.map +0 -1
  248. package/dist/domain/event/index.js.map +0 -1
  249. package/dist/domain/index.d.ts.map +0 -1
  250. package/dist/domain/index.js.map +0 -1
  251. package/dist/domain/message/index.d.ts.map +0 -1
  252. package/dist/domain/message/index.js.map +0 -1
  253. package/dist/domain/message/message.error.d.ts.map +0 -1
  254. package/dist/domain/message/message.error.js.map +0 -1
  255. package/dist/domain/message/messageError.base.d.ts.map +0 -1
  256. package/dist/domain/message/messageError.base.js.map +0 -1
  257. package/dist/domain/message/messageError.handler.d.ts.map +0 -1
  258. package/dist/domain/message/messageError.handler.js.map +0 -1
  259. package/dist/domain/message/messageError.lifecycle.d.ts.map +0 -1
  260. package/dist/domain/message/messageError.lifecycle.js.map +0 -1
  261. package/dist/domain/message/messageError.validation.d.ts.map +0 -1
  262. package/dist/domain/message/messageError.validation.js.map +0 -1
  263. package/dist/domain/plugin/index.d.ts.map +0 -1
  264. package/dist/domain/plugin/index.js.map +0 -1
  265. package/dist/domain/plugin/plugin.error.d.ts.map +0 -1
  266. package/dist/domain/plugin/plugin.error.js.map +0 -1
  267. package/dist/domain/plugin/pluginError.base.d.ts.map +0 -1
  268. package/dist/domain/plugin/pluginError.base.js.map +0 -1
  269. package/dist/domain/plugin/pluginError.lifecycle.d.ts.map +0 -1
  270. package/dist/domain/plugin/pluginError.lifecycle.js.map +0 -1
  271. package/dist/domain/plugin/pluginError.runtime.d.ts.map +0 -1
  272. package/dist/domain/plugin/pluginError.runtime.js.map +0 -1
  273. package/dist/domain/queue/index.d.ts.map +0 -1
  274. package/dist/domain/queue/index.js.map +0 -1
  275. package/dist/domain/queue/queue.error.d.ts.map +0 -1
  276. package/dist/domain/queue/queue.error.js.map +0 -1
  277. package/dist/domain/queue/queueError.base.d.ts.map +0 -1
  278. package/dist/domain/queue/queueError.base.js.map +0 -1
  279. package/dist/domain/queue/queueError.job.d.ts.map +0 -1
  280. package/dist/domain/queue/queueError.job.js.map +0 -1
  281. package/dist/domain/queue/queueError.queue.d.ts.map +0 -1
  282. package/dist/domain/queue/queueError.queue.js.map +0 -1
  283. package/dist/domain/queue/queueError.worker.d.ts.map +0 -1
  284. package/dist/domain/queue/queueError.worker.js.map +0 -1
  285. package/dist/domain/rpc/index.d.ts.map +0 -1
  286. package/dist/domain/rpc/index.js.map +0 -1
  287. package/dist/domain/rpc/rpc.error.d.ts.map +0 -1
  288. package/dist/domain/rpc/rpc.error.js.map +0 -1
  289. package/dist/domain/rpc/rpcError.base.d.ts.map +0 -1
  290. package/dist/domain/rpc/rpcError.base.js.map +0 -1
  291. package/dist/domain/rpc/rpcError.protocol.d.ts.map +0 -1
  292. package/dist/domain/rpc/rpcError.protocol.js.map +0 -1
  293. package/dist/domain/rpc/rpcError.transport.d.ts.map +0 -1
  294. package/dist/domain/rpc/rpcError.transport.js.map +0 -1
  295. package/dist/domain/scheduler/index.d.ts.map +0 -1
  296. package/dist/domain/scheduler/index.js.map +0 -1
  297. package/dist/domain/scheduler/scheduler.error.d.ts.map +0 -1
  298. package/dist/domain/scheduler/scheduler.error.js.map +0 -1
  299. package/dist/domain/scheduler/schedulerError.base.d.ts.map +0 -1
  300. package/dist/domain/scheduler/schedulerError.base.js.map +0 -1
  301. package/dist/domain/scheduler/schedulerError.execution.d.ts.map +0 -1
  302. package/dist/domain/scheduler/schedulerError.execution.js.map +0 -1
  303. package/dist/domain/scheduler/schedulerError.schedule.d.ts.map +0 -1
  304. package/dist/domain/scheduler/schedulerError.schedule.js.map +0 -1
  305. package/dist/domain/schema/index.d.ts.map +0 -1
  306. package/dist/domain/schema/index.js.map +0 -1
  307. package/dist/domain/schema/schema.error.d.ts.map +0 -1
  308. package/dist/domain/schema/schema.error.js.map +0 -1
  309. package/dist/domain/schema/schemaError.base.d.ts.map +0 -1
  310. package/dist/domain/schema/schemaError.base.js.map +0 -1
  311. package/dist/domain/schema/schemaError.types.d.ts.map +0 -1
  312. package/dist/domain/schema/schemaError.types.js.map +0 -1
  313. package/dist/domain/serialization/index.d.ts.map +0 -1
  314. package/dist/domain/serialization/index.js.map +0 -1
  315. package/dist/domain/serialization/serialization.error.d.ts.map +0 -1
  316. package/dist/domain/serialization/serialization.error.js.map +0 -1
  317. package/dist/domain/serialization/serializationError.base.d.ts.map +0 -1
  318. package/dist/domain/serialization/serializationError.base.js.map +0 -1
  319. package/dist/domain/serialization/serializationError.types.d.ts.map +0 -1
  320. package/dist/domain/serialization/serializationError.types.js.map +0 -1
  321. package/dist/domain/state/conflict.error.d.ts.map +0 -1
  322. package/dist/domain/state/conflict.error.js.map +0 -1
  323. package/dist/domain/state/index.d.ts.map +0 -1
  324. package/dist/domain/state/index.js.map +0 -1
  325. package/dist/domain/state/notFound.error.d.ts.map +0 -1
  326. package/dist/domain/state/notFound.error.js.map +0 -1
  327. package/dist/domain/state/validation.error.d.ts.map +0 -1
  328. package/dist/domain/state/validation.error.js.map +0 -1
  329. package/dist/domain/state/validationError.base.d.ts.map +0 -1
  330. package/dist/domain/state/validationError.base.js.map +0 -1
  331. package/dist/domain/state/validationError.helpers.d.ts.map +0 -1
  332. package/dist/domain/state/validationError.helpers.js.map +0 -1
  333. package/dist/index.d.ts.map +0 -1
  334. package/dist/index.js.map +0 -1
  335. package/dist/infrastructure/adapter/adapter.error.d.ts.map +0 -1
  336. package/dist/infrastructure/adapter/adapter.error.js.map +0 -1
  337. package/dist/infrastructure/adapter/adapterError.base.d.ts.map +0 -1
  338. package/dist/infrastructure/adapter/adapterError.base.js.map +0 -1
  339. package/dist/infrastructure/adapter/adapterError.lifecycle.d.ts.map +0 -1
  340. package/dist/infrastructure/adapter/adapterError.lifecycle.js.map +0 -1
  341. package/dist/infrastructure/adapter/adapterError.operation.d.ts.map +0 -1
  342. package/dist/infrastructure/adapter/adapterError.operation.js.map +0 -1
  343. package/dist/infrastructure/adapter/index.d.ts.map +0 -1
  344. package/dist/infrastructure/adapter/index.js.map +0 -1
  345. package/dist/infrastructure/cache/cache.error.d.ts.map +0 -1
  346. package/dist/infrastructure/cache/cache.error.js.map +0 -1
  347. package/dist/infrastructure/cache/cacheError.base.d.ts.map +0 -1
  348. package/dist/infrastructure/cache/cacheError.base.js.map +0 -1
  349. package/dist/infrastructure/cache/cacheError.factory.d.ts.map +0 -1
  350. package/dist/infrastructure/cache/cacheError.factory.js.map +0 -1
  351. package/dist/infrastructure/cache/index.d.ts.map +0 -1
  352. package/dist/infrastructure/cache/index.js.map +0 -1
  353. package/dist/infrastructure/container/container.error.d.ts.map +0 -1
  354. package/dist/infrastructure/container/container.error.js.map +0 -1
  355. package/dist/infrastructure/container/containerError.base.d.ts.map +0 -1
  356. package/dist/infrastructure/container/containerError.base.js.map +0 -1
  357. package/dist/infrastructure/container/containerError.registration.d.ts.map +0 -1
  358. package/dist/infrastructure/container/containerError.registration.js.map +0 -1
  359. package/dist/infrastructure/container/index.d.ts.map +0 -1
  360. package/dist/infrastructure/container/index.js.map +0 -1
  361. package/dist/infrastructure/index.d.ts.map +0 -1
  362. package/dist/infrastructure/index.js.map +0 -1
  363. package/dist/infrastructure/middleware/index.d.ts.map +0 -1
  364. package/dist/infrastructure/middleware/index.js.map +0 -1
  365. package/dist/infrastructure/middleware/middleware.error.d.ts.map +0 -1
  366. package/dist/infrastructure/middleware/middleware.error.js.map +0 -1
  367. package/dist/infrastructure/network/http.error.d.ts.map +0 -1
  368. package/dist/infrastructure/network/http.error.js.map +0 -1
  369. package/dist/infrastructure/network/httpAdapter.error.d.ts.map +0 -1
  370. package/dist/infrastructure/network/httpAdapter.error.js.map +0 -1
  371. package/dist/infrastructure/network/httpClient.errors.d.ts.map +0 -1
  372. package/dist/infrastructure/network/httpClient.errors.js.map +0 -1
  373. package/dist/infrastructure/network/httpClientError.advanced.d.ts.map +0 -1
  374. package/dist/infrastructure/network/httpClientError.advanced.js.map +0 -1
  375. package/dist/infrastructure/network/httpClientError.base.d.ts.map +0 -1
  376. package/dist/infrastructure/network/httpClientError.base.js.map +0 -1
  377. package/dist/infrastructure/network/httpClientError.common.d.ts.map +0 -1
  378. package/dist/infrastructure/network/httpClientError.common.js.map +0 -1
  379. package/dist/infrastructure/network/httpClientError.error.d.ts.map +0 -1
  380. package/dist/infrastructure/network/httpClientError.error.js.map +0 -1
  381. package/dist/infrastructure/network/httpClientError.options.d.ts.map +0 -1
  382. package/dist/infrastructure/network/httpClientError.options.js.map +0 -1
  383. package/dist/infrastructure/network/httpClientError.specialized.d.ts.map +0 -1
  384. package/dist/infrastructure/network/httpClientError.specialized.js.map +0 -1
  385. package/dist/infrastructure/network/httpClientError.types.d.ts.map +0 -1
  386. package/dist/infrastructure/network/httpClientError.types.js.map +0 -1
  387. package/dist/infrastructure/network/httpError.base.d.ts.map +0 -1
  388. package/dist/infrastructure/network/httpError.base.js.map +0 -1
  389. package/dist/infrastructure/network/httpError.helpers.d.ts.map +0 -1
  390. package/dist/infrastructure/network/httpError.helpers.js.map +0 -1
  391. package/dist/infrastructure/network/httpResponse.error.d.ts.map +0 -1
  392. package/dist/infrastructure/network/httpResponse.error.js.map +0 -1
  393. package/dist/infrastructure/network/httpRouter.error.d.ts.map +0 -1
  394. package/dist/infrastructure/network/httpRouter.error.js.map +0 -1
  395. package/dist/infrastructure/network/httpRouterError.base.d.ts.map +0 -1
  396. package/dist/infrastructure/network/httpRouterError.base.js.map +0 -1
  397. package/dist/infrastructure/network/httpRouterError.types.d.ts.map +0 -1
  398. package/dist/infrastructure/network/httpRouterError.types.js.map +0 -1
  399. package/dist/infrastructure/network/httpServerError.error.d.ts.map +0 -1
  400. package/dist/infrastructure/network/httpServerError.error.js.map +0 -1
  401. package/dist/infrastructure/network/httpServerLifecycle.error.d.ts.map +0 -1
  402. package/dist/infrastructure/network/httpServerLifecycle.error.js.map +0 -1
  403. package/dist/infrastructure/network/httpServerLifecycleError.base.d.ts.map +0 -1
  404. package/dist/infrastructure/network/httpServerLifecycleError.base.js.map +0 -1
  405. package/dist/infrastructure/network/httpServerLifecycleError.types.d.ts.map +0 -1
  406. package/dist/infrastructure/network/httpServerLifecycleError.types.js.map +0 -1
  407. package/dist/infrastructure/network/httpStream.error.d.ts.map +0 -1
  408. package/dist/infrastructure/network/httpStream.error.js.map +0 -1
  409. package/dist/infrastructure/network/index.d.ts.map +0 -1
  410. package/dist/infrastructure/network/index.js.map +0 -1
  411. package/dist/infrastructure/network/network.error.d.ts.map +0 -1
  412. package/dist/infrastructure/network/network.error.js.map +0 -1
  413. package/dist/infrastructure/network/networkError.base.d.ts.map +0 -1
  414. package/dist/infrastructure/network/networkError.base.js.map +0 -1
  415. package/dist/infrastructure/network/networkError.factory.d.ts.map +0 -1
  416. package/dist/infrastructure/network/networkError.factory.js.map +0 -1
  417. package/dist/infrastructure/network/routePattern.error.d.ts.map +0 -1
  418. package/dist/infrastructure/network/routePattern.error.js.map +0 -1
  419. package/dist/infrastructure/network/timeout.error.d.ts.map +0 -1
  420. package/dist/infrastructure/network/timeout.error.js.map +0 -1
  421. package/dist/infrastructure/network/timeoutError.base.d.ts.map +0 -1
  422. package/dist/infrastructure/network/timeoutError.base.js.map +0 -1
  423. package/dist/infrastructure/network/timeoutError.factory.d.ts.map +0 -1
  424. package/dist/infrastructure/network/timeoutError.factory.js.map +0 -1
  425. package/dist/infrastructure/service/externalService.error.d.ts.map +0 -1
  426. package/dist/infrastructure/service/externalService.error.js.map +0 -1
  427. package/dist/infrastructure/service/externalServiceError.base.d.ts.map +0 -1
  428. package/dist/infrastructure/service/externalServiceError.base.js.map +0 -1
  429. package/dist/infrastructure/service/externalServiceError.factory.d.ts.map +0 -1
  430. package/dist/infrastructure/service/externalServiceError.factory.js.map +0 -1
  431. package/dist/infrastructure/service/index.d.ts.map +0 -1
  432. package/dist/infrastructure/service/index.js.map +0 -1
  433. package/dist/infrastructure/service/service.error.d.ts.map +0 -1
  434. package/dist/infrastructure/service/service.error.js.map +0 -1
  435. package/dist/infrastructure/service/serviceError.base.d.ts.map +0 -1
  436. package/dist/infrastructure/service/serviceError.base.js.map +0 -1
  437. package/dist/infrastructure/service/serviceError.factory.d.ts.map +0 -1
  438. package/dist/infrastructure/service/serviceError.factory.js.map +0 -1
  439. package/dist/infrastructure/storage/database.error.d.ts.map +0 -1
  440. package/dist/infrastructure/storage/database.error.js.map +0 -1
  441. package/dist/infrastructure/storage/databaseError.base.d.ts.map +0 -1
  442. package/dist/infrastructure/storage/databaseError.base.js.map +0 -1
  443. package/dist/infrastructure/storage/databaseError.factory.d.ts.map +0 -1
  444. package/dist/infrastructure/storage/databaseError.factory.js.map +0 -1
  445. package/dist/infrastructure/storage/index.d.ts.map +0 -1
  446. package/dist/infrastructure/storage/index.js.map +0 -1
  447. package/dist/infrastructure/storage/storage.error.d.ts.map +0 -1
  448. package/dist/infrastructure/storage/storage.error.js.map +0 -1
  449. package/dist/infrastructure/storage/storageError.base.d.ts.map +0 -1
  450. package/dist/infrastructure/storage/storageError.base.js.map +0 -1
  451. package/dist/infrastructure/storage/storageError.factory.d.ts.map +0 -1
  452. package/dist/infrastructure/storage/storageError.factory.js.map +0 -1
  453. package/dist/system/crypto.error.d.ts.map +0 -1
  454. package/dist/system/crypto.error.js.map +0 -1
  455. package/dist/system/cryptoError.base.d.ts.map +0 -1
  456. package/dist/system/cryptoError.base.js.map +0 -1
  457. package/dist/system/cryptoError.factory.d.ts.map +0 -1
  458. package/dist/system/cryptoError.factory.js.map +0 -1
  459. package/dist/system/index.d.ts.map +0 -1
  460. package/dist/system/index.js.map +0 -1
  461. package/dist/system/logging/index.d.ts.map +0 -1
  462. package/dist/system/logging/index.js.map +0 -1
  463. package/dist/system/logging/logging.error.d.ts.map +0 -1
  464. package/dist/system/logging/logging.error.js.map +0 -1
  465. package/dist/system/runtime.error.d.ts.map +0 -1
  466. package/dist/system/runtime.error.js.map +0 -1
  467. package/dist/system/runtimeError.base.d.ts.map +0 -1
  468. package/dist/system/runtimeError.base.js.map +0 -1
  469. package/dist/system/runtimeError.types.d.ts.map +0 -1
  470. package/dist/system/runtimeError.types.js.map +0 -1
  471. package/dist/system/system.error.d.ts.map +0 -1
  472. package/dist/system/system.error.js.map +0 -1
  473. package/dist/system/systemError.base.d.ts.map +0 -1
  474. package/dist/system/systemError.base.js.map +0 -1
  475. package/dist/system/systemError.factory.d.ts.map +0 -1
  476. package/dist/system/systemError.factory.js.map +0 -1
  477. package/dist/utils/errorHandler.core.d.ts.map +0 -1
  478. package/dist/utils/errorHandler.core.js.map +0 -1
  479. package/dist/utils/errorHandler.factory.d.ts.map +0 -1
  480. package/dist/utils/errorHandler.factory.js.map +0 -1
  481. package/dist/utils/errorHandler.types.d.ts.map +0 -1
  482. package/dist/utils/errorHandler.types.js.map +0 -1
  483. package/dist/utils/errorMapper.core.d.ts.map +0 -1
  484. package/dist/utils/errorMapper.core.js.map +0 -1
  485. package/dist/utils/errorMapper.mappers.d.ts.map +0 -1
  486. package/dist/utils/errorMapper.mappers.js.map +0 -1
  487. package/dist/utils/errorMapper.registry.d.ts.map +0 -1
  488. package/dist/utils/errorMapper.registry.js.map +0 -1
  489. package/dist/utils/errorMapper.types.d.ts.map +0 -1
  490. package/dist/utils/errorMapper.types.js.map +0 -1
  491. package/dist/utils/errorSerializer.core.d.ts.map +0 -1
  492. package/dist/utils/errorSerializer.core.js.map +0 -1
  493. package/dist/utils/errorSerializer.factory.d.ts.map +0 -1
  494. package/dist/utils/errorSerializer.factory.js.map +0 -1
  495. package/dist/utils/errorSerializer.types.d.ts.map +0 -1
  496. package/dist/utils/errorSerializer.types.js.map +0 -1
  497. package/dist/utils/errorUtils.extraction.d.ts.map +0 -1
  498. package/dist/utils/errorUtils.extraction.js.map +0 -1
  499. package/dist/utils/errorUtils.helper.d.ts.map +0 -1
  500. package/dist/utils/errorUtils.helper.js.map +0 -1
  501. package/dist/utils/errorUtils.transform.d.ts.map +0 -1
  502. package/dist/utils/errorUtils.transform.js.map +0 -1
  503. package/dist/utils/errorUtils.typeCheck.d.ts.map +0 -1
  504. package/dist/utils/errorUtils.typeCheck.js.map +0 -1
  505. package/dist/utils/index.d.ts.map +0 -1
  506. package/dist/utils/index.js.map +0 -1
@@ -2,52 +2,29 @@
2
2
  * Error mapping functions — native error mapping, registry-based mapping, rule creation.
3
3
  */
4
4
  import { BaseError } from "../base/core/baseError.core.js";
5
- import { ErrorCategory } from "../base/types/errorCategory.type.js";
6
- import { ErrorCode } from "../base/types/errorCode.type.js";
7
- import { ErrorSeverity } from "../base/types/errorSeverity.type.js";
8
- /** Maps common native JavaScript errors. */
5
+ import { isBaseError, normalizeUnknownToBaseError, } from "../base/utils/baseError.utils.js";
6
+ /**
7
+ * Maps common native JavaScript errors.
8
+ *
9
+ * Native `TypeError`/`RangeError`/`SyntaxError` are overwhelmingly programmer
10
+ * bugs rather than client input problems, so they are classified as
11
+ * non-operational internal errors (500, not exposed). Register an explicit
12
+ * mapping rule to treat a specific error type as client input.
13
+ */
9
14
  export function mapNativeError(error) {
10
- if (error instanceof BaseError) {
15
+ if (isBaseError(error)) {
11
16
  return error;
12
17
  }
13
- if (error instanceof TypeError) {
14
- return new BaseError(error.message, {
15
- code: ErrorCode.INVALID_INPUT,
16
- category: ErrorCategory.VALIDATION,
17
- severity: ErrorSeverity.WARNING,
18
- statusCode: 400,
19
- expose: true,
20
- isOperational: true,
21
- cause: error,
22
- });
23
- }
24
- if (error instanceof RangeError) {
25
- return new BaseError(error.message, {
26
- code: ErrorCode.INVALID_INPUT,
27
- category: ErrorCategory.VALIDATION,
28
- severity: ErrorSeverity.WARNING,
29
- statusCode: 400,
30
- expose: true,
31
- isOperational: true,
32
- cause: error,
33
- });
34
- }
35
18
  if (error instanceof Error) {
36
- return new BaseError(error.message || "An unexpected error occurred.", {
37
- code: ErrorCode.INTERNAL_ERROR,
38
- category: ErrorCategory.SYSTEM,
39
- severity: ErrorSeverity.ERROR,
40
- statusCode: 500,
41
- expose: false,
42
- isOperational: false,
43
- cause: error,
19
+ return normalizeUnknownToBaseError(error, {
20
+ metadata: { nativeErrorName: error.name },
44
21
  });
45
22
  }
46
23
  return undefined;
47
24
  }
48
25
  /** Maps an error using a registry and falls back to native error mapping. */
49
26
  export function mapError(error, registry, context) {
50
- if (error instanceof BaseError) {
27
+ if (isBaseError(error)) {
51
28
  return error;
52
29
  }
53
30
  const mapped = registry?.map(error, context);
@@ -58,27 +35,58 @@ export function mapError(error, registry, context) {
58
35
  if (native) {
59
36
  return native;
60
37
  }
61
- return new BaseError("An unexpected error occurred.", {
62
- code: ErrorCode.INTERNAL_ERROR,
63
- category: ErrorCategory.SYSTEM,
64
- severity: ErrorSeverity.ERROR,
65
- statusCode: 500,
66
- expose: false,
67
- isOperational: false,
68
- metadata: { originalType: typeof error },
69
- });
38
+ return normalizeUnknownToBaseError(error);
70
39
  }
71
- /** Creates a mapping rule for a specific error constructor. */
40
+ /**
41
+ * Creates a mapping rule for a specific error constructor.
42
+ *
43
+ * `mapper` may be a function producing a `BaseError`, or a declarative
44
+ * `ErrorMapping` describing the resulting error.
45
+ */
72
46
  export function mapErrorType(name, errorType, mapper, priority = 0) {
47
+ const mapFn = typeof mapper === "function"
48
+ ? (error, context) => mapper(error, context)
49
+ : (error, context) => applyErrorMapping(error, mapper, context);
73
50
  return {
74
51
  name,
75
52
  priority,
76
53
  predicate: (error) => error instanceof errorType,
77
- mapper: (error, context) => mapper(error, context),
54
+ mapper: mapFn,
78
55
  };
79
56
  }
80
- /** Creates a mapping rule based on a predicate. */
57
+ /**
58
+ * Creates a mapping rule based on a predicate.
59
+ *
60
+ * `mapper` may be a function producing a `BaseError`, or a declarative
61
+ * `ErrorMapping` describing the resulting error.
62
+ */
81
63
  export function createErrorMappingRule(name, predicate, mapper, priority = 0) {
82
- return { name, predicate, mapper, priority };
64
+ const mapFn = typeof mapper === "function"
65
+ ? mapper
66
+ : (error, context) => applyErrorMapping(error, mapper, context);
67
+ return { name, predicate, mapper: mapFn, priority };
68
+ }
69
+ /** Builds a BaseError from a declarative `ErrorMapping`. */
70
+ export function applyErrorMapping(error, mapping, context) {
71
+ const message = mapping.message ??
72
+ (error instanceof Error && error.message
73
+ ? error.message
74
+ : "An unexpected error occurred.");
75
+ return new BaseError(message, {
76
+ code: mapping.code,
77
+ category: mapping.category,
78
+ severity: mapping.severity,
79
+ statusCode: mapping.statusCode,
80
+ expose: mapping.expose,
81
+ isOperational: mapping.isOperational,
82
+ cause: error,
83
+ metadata: {
84
+ ...context?.metadata,
85
+ ...mapping.metadata,
86
+ ...(context?.requestId !== undefined
87
+ ? { requestId: context.requestId }
88
+ : {}),
89
+ },
90
+ });
83
91
  }
84
92
  //# sourceMappingURL=errorMapper.mappers.js.map
@@ -12,16 +12,35 @@ export declare class ErrorSerializer {
12
12
  private readonly includeMetadata;
13
13
  private readonly safeMessage;
14
14
  private readonly redactSensitiveData;
15
+ private readonly sensitiveKeyPattern;
16
+ private readonly publicMetadataKeys;
15
17
  constructor(options?: ErrorSerializerOptions);
16
- /** Serializes an error for internal logging or monitoring. */
18
+ /**
19
+ * Serializes an error for internal logging or monitoring.
20
+ *
21
+ * `includeStack`, `includeCause` and `redactSensitiveData` are applied at
22
+ * every level of the cause chain.
23
+ */
17
24
  serialize(error: BaseError): InternalErrorResponse;
18
- /** Serializes an error for an untrusted API client. */
25
+ /**
26
+ * Serializes an error for an untrusted API client.
27
+ *
28
+ * Never includes a stack or cause. Metadata is only included when the error
29
+ * is exposable (or when `publicMetadataKeys` allow-lists specific keys) and
30
+ * is always redacted.
31
+ */
19
32
  serializePublic(error: BaseError): PublicErrorResponse;
20
33
  /** Serializes an unknown thrown value. */
21
34
  serializeUnknown(value: unknown): InternalErrorResponse;
22
35
  /** Creates a public response from an unknown thrown value. */
23
36
  serializeUnknownPublic(value: unknown): PublicErrorResponse;
24
- /** Removes commonly sensitive metadata fields. */
37
+ /** Applies the serializer options to one level of a serialized error. */
38
+ private serializeLevel;
39
+ /** Applies the serializer options recursively to a serialized cause. */
40
+ private serializeCause;
41
+ /** Computes the metadata allowed in a public response. */
42
+ private publicMetadata;
43
+ /** Removes commonly sensitive metadata fields (recursively). */
25
44
  private redactMetadata;
26
45
  }
27
46
  //# sourceMappingURL=errorSerializer.core.d.ts.map
@@ -2,6 +2,7 @@
2
2
  * Converts errors into safe, predictable serialized structures.
3
3
  */
4
4
  import { BaseError } from "../base/core/baseError.core.js";
5
+ import { isSensitiveMetadataKey, pickErrorMetadata, redactErrorMetadata, REDACTED_METADATA_VALUE, } from "../base/core/errorMetadata.core.js";
5
6
  import { normalizeUnknownError } from "./errorSerializer.factory.js";
6
7
  export { createErrorSerializer, serializeError, serializePublicError, normalizeUnknownError, } from "./errorSerializer.factory.js";
7
8
  /** Converts errors into safe, predictable serialized structures. */
@@ -11,41 +12,41 @@ export class ErrorSerializer {
11
12
  includeMetadata;
12
13
  safeMessage;
13
14
  redactSensitiveData;
15
+ sensitiveKeyPattern;
16
+ publicMetadataKeys;
14
17
  constructor(options = {}) {
15
18
  this.includeStack = options.includeStack ?? false;
16
19
  this.includeCause = options.includeCause ?? false;
17
20
  this.includeMetadata = options.includeMetadata ?? true;
18
21
  this.safeMessage = options.safeMessage ?? "An unexpected error occurred.";
19
22
  this.redactSensitiveData = options.redactSensitiveData ?? true;
23
+ this.sensitiveKeyPattern = options.sensitiveKeyPattern;
24
+ this.publicMetadataKeys = options.publicMetadataKeys;
20
25
  }
21
- /** Serializes an error for internal logging or monitoring. */
26
+ /**
27
+ * Serializes an error for internal logging or monitoring.
28
+ *
29
+ * `includeStack`, `includeCause` and `redactSensitiveData` are applied at
30
+ * every level of the cause chain.
31
+ */
22
32
  serialize(error) {
23
- const serialized = error.toJSON();
24
- const result = {
25
- ...serialized,
26
- ...(this.includeStack ? {} : { stack: undefined }),
27
- ...(this.includeCause ? {} : { cause: undefined }),
28
- ...(this.includeMetadata ? {} : { metadata: {} }),
29
- };
30
- if (this.redactSensitiveData && result.metadata) {
31
- return {
32
- ...result,
33
- metadata: this.redactMetadata(result.metadata),
34
- };
35
- }
36
- return result;
33
+ return this.serializeLevel(error.toJSON());
37
34
  }
38
- /** Serializes an error for an untrusted API client. */
35
+ /**
36
+ * Serializes an error for an untrusted API client.
37
+ *
38
+ * Never includes a stack or cause. Metadata is only included when the error
39
+ * is exposable (or when `publicMetadataKeys` allow-lists specific keys) and
40
+ * is always redacted.
41
+ */
39
42
  serializePublic(error) {
40
- const metadata = this.includeMetadata
41
- ? this.redactMetadata(error.metadata)
42
- : undefined;
43
+ const metadata = this.publicMetadata(error);
43
44
  return {
44
45
  code: error.code,
45
46
  message: error.expose ? error.message : this.safeMessage,
46
47
  category: error.category,
47
48
  statusCode: error.statusCode,
48
- ...(metadata && Object.keys(metadata).length > 0 ? { metadata } : {}),
49
+ ...(metadata !== undefined ? { metadata } : {}),
49
50
  };
50
51
  }
51
52
  /** Serializes an unknown thrown value. */
@@ -56,27 +57,131 @@ export class ErrorSerializer {
56
57
  serializeUnknownPublic(value) {
57
58
  return this.serializePublic(normalizeUnknownError(value));
58
59
  }
59
- /** Removes commonly sensitive metadata fields. */
60
+ /** Applies the serializer options to one level of a serialized error. */
61
+ serializeLevel(serialized) {
62
+ const { stack, cause, metadata, ...rest } = serialized;
63
+ const result = {
64
+ ...rest,
65
+ metadata: this.includeMetadata
66
+ ? this.redactSensitiveData
67
+ ? this.redactMetadata(metadata)
68
+ : metadata
69
+ : {},
70
+ ...(this.includeStack && stack !== undefined ? { stack } : {}),
71
+ ...(this.includeCause && cause !== undefined
72
+ ? { cause: this.serializeCause(cause) }
73
+ : {}),
74
+ };
75
+ return result;
76
+ }
77
+ /** Applies the serializer options recursively to a serialized cause. */
78
+ serializeCause(cause) {
79
+ if (cause === null || typeof cause !== "object")
80
+ return cause;
81
+ if (Array.isArray(cause))
82
+ return cause;
83
+ const record = cause;
84
+ if (isSerializedBaseError(record)) {
85
+ return this.serializeLevel(record);
86
+ }
87
+ // Native error shape: { name, message, stack?, cause? } — or an
88
+ // arbitrary plain object that was thrown/attached as a cause. The
89
+ // latter reaches here by reference and used to be copied verbatim, so
90
+ // `redactSensitiveData` did not apply to it.
91
+ const { stack, cause: nested, ...rest } = record;
92
+ const fields = this.redactSensitiveData
93
+ ? redactCauseFields(rest, this.sensitiveKeyPattern, new WeakSet([record]))
94
+ : rest;
95
+ return {
96
+ ...fields,
97
+ ...(this.includeStack && stack !== undefined ? { stack } : {}),
98
+ ...(nested !== undefined ? { cause: this.serializeCause(nested) } : {}),
99
+ };
100
+ }
101
+ /** Computes the metadata allowed in a public response. */
102
+ publicMetadata(error) {
103
+ if (!this.includeMetadata)
104
+ return undefined;
105
+ let metadata;
106
+ if (this.publicMetadataKeys !== undefined) {
107
+ metadata = pickErrorMetadata(error.metadata, this.publicMetadataKeys);
108
+ }
109
+ else if (error.expose) {
110
+ metadata = error.metadata;
111
+ }
112
+ else {
113
+ return undefined;
114
+ }
115
+ const redacted = this.redactSensitiveData
116
+ ? this.redactMetadata(metadata)
117
+ : metadata;
118
+ return Object.keys(redacted).length > 0 ? redacted : undefined;
119
+ }
120
+ /** Removes commonly sensitive metadata fields (recursively). */
60
121
  redactMetadata(metadata) {
61
- const sensitiveKeys = new Set([
62
- "password",
63
- "passcode",
64
- "token",
65
- "accessToken",
66
- "refreshToken",
67
- "authorization",
68
- "cookie",
69
- "secret",
70
- "privateKey",
71
- "apiKey",
72
- "credential",
73
- "clientSecret",
74
- ]);
75
- const result = {};
76
- for (const [key, value] of Object.entries(metadata)) {
77
- result[key] = sensitiveKeys.has(key) ? "[REDACTED]" : value;
122
+ return redactErrorMetadata(metadata, {
123
+ sensitiveKeyPattern: this.sensitiveKeyPattern,
124
+ });
125
+ }
126
+ }
127
+ /** Plain objects (Object.prototype or null prototype) are walked; anything else is kept as-is. */
128
+ function isPlainRecord(value) {
129
+ if (value === null || typeof value !== "object")
130
+ return false;
131
+ const proto = Object.getPrototypeOf(value);
132
+ return proto === Object.prototype || proto === null;
133
+ }
134
+ /**
135
+ * Redacts sensitive keys inside a non-BaseError cause without changing its
136
+ * shape: primitives, dates and class instances are kept, plain objects and
137
+ * arrays are walked, cycles stop at "[Circular]".
138
+ */
139
+ function redactCauseFields(fields, pattern, seen = new WeakSet()) {
140
+ const result = {};
141
+ for (const key of Object.keys(fields)) {
142
+ if (key === "__proto__" || key === "constructor" || key === "prototype")
143
+ continue;
144
+ const value = fields[key];
145
+ const sensitive = pattern === undefined
146
+ ? isSensitiveMetadataKey(key)
147
+ : isSensitiveMetadataKey(key, pattern);
148
+ result[key] = sensitive
149
+ ? REDACTED_METADATA_VALUE
150
+ : redactCauseValue(value, pattern, seen);
151
+ }
152
+ return result;
153
+ }
154
+ function redactCauseValue(value, pattern, seen) {
155
+ if (Array.isArray(value)) {
156
+ if (seen.has(value))
157
+ return "[Circular]";
158
+ seen.add(value);
159
+ try {
160
+ return value.map((entry) => redactCauseValue(entry, pattern, seen));
161
+ }
162
+ finally {
163
+ seen.delete(value);
78
164
  }
79
- return result;
80
165
  }
166
+ if (!isPlainRecord(value))
167
+ return value;
168
+ if (seen.has(value))
169
+ return "[Circular]";
170
+ seen.add(value);
171
+ try {
172
+ return redactCauseFields(value, pattern, seen);
173
+ }
174
+ finally {
175
+ seen.delete(value);
176
+ }
177
+ }
178
+ /** Structural check for a serialized BaseError (used on nested causes). */
179
+ function isSerializedBaseError(value) {
180
+ return (typeof value.code === "string" &&
181
+ typeof value.category === "string" &&
182
+ typeof value.severity === "string" &&
183
+ typeof value.statusCode === "number" &&
184
+ typeof value.metadata === "object" &&
185
+ value.metadata !== null);
81
186
  }
82
187
  //# sourceMappingURL=errorSerializer.core.js.map
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Error serializer factory and utility functions.
3
3
  */
4
- import { BaseError } from "../base/core/baseError.core.js";
4
+ import type { BaseError } from "../base/core/baseError.core.js";
5
5
  import { ErrorSerializer } from "./errorSerializer.core.js";
6
6
  import type { ErrorSerializerOptions, PublicErrorResponse, InternalErrorResponse } from "./errorSerializer.types.js";
7
7
  export type { ErrorSerializerOptions, PublicErrorResponse, InternalErrorResponse, } from "./errorSerializer.types.js";
@@ -1,9 +1,7 @@
1
1
  /**
2
2
  * Error serializer factory and utility functions.
3
3
  */
4
- import { BaseError } from "../base/core/baseError.core.js";
5
- import { ErrorCategory } from "../base/types/errorCategory.type.js";
6
- import { ErrorSeverity } from "../base/types/errorSeverity.type.js";
4
+ import { normalizeUnknownToBaseError } from "../base/utils/baseError.utils.js";
7
5
  import { ErrorSerializer } from "./errorSerializer.core.js";
8
6
  /** Creates an ErrorSerializer instance. */
9
7
  export function createErrorSerializer(options = {}) {
@@ -19,28 +17,6 @@ export function serializePublicError(error, options = {}) {
19
17
  }
20
18
  /** Converts an unknown thrown value into a BaseError. */
21
19
  export function normalizeUnknownError(value) {
22
- if (value instanceof BaseError) {
23
- return value;
24
- }
25
- if (value instanceof Error) {
26
- return new BaseError(value.message || "An unexpected error occurred.", {
27
- code: "INTERNAL_ERROR",
28
- category: ErrorCategory.SYSTEM,
29
- severity: ErrorSeverity.ERROR,
30
- statusCode: 500,
31
- expose: false,
32
- isOperational: false,
33
- cause: value,
34
- });
35
- }
36
- return new BaseError("An unexpected error occurred.", {
37
- code: "INTERNAL_ERROR",
38
- category: ErrorCategory.SYSTEM,
39
- severity: ErrorSeverity.ERROR,
40
- statusCode: 500,
41
- expose: false,
42
- isOperational: false,
43
- metadata: { originalType: typeof value },
44
- });
20
+ return normalizeUnknownToBaseError(value);
45
21
  }
46
22
  //# sourceMappingURL=errorSerializer.factory.js.map
@@ -5,16 +5,26 @@ import type { SerializedBaseError } from "../base/types/baseError.type.js";
5
5
  import { ErrorCategory } from "../base/types/errorCategory.type.js";
6
6
  /** Options controlling error serialization. */
7
7
  export interface ErrorSerializerOptions {
8
- /** Include the stack trace in the serialized result. Defaults to false. */
8
+ /** Include the stack trace (at every level of the cause chain). Defaults to false. */
9
9
  readonly includeStack?: boolean;
10
- /** Include the error cause. Defaults to false. */
10
+ /** Include the error cause chain. Defaults to false. */
11
11
  readonly includeCause?: boolean;
12
- /** Include internal metadata. Defaults to true for internal serialization. */
12
+ /** Include metadata in internal serialization. Defaults to true. */
13
13
  readonly includeMetadata?: boolean;
14
14
  /** Replace non-exposable error messages with a safe message. */
15
15
  readonly safeMessage?: string;
16
- /** Remove sensitive metadata values. */
16
+ /** Redact sensitive metadata values (recursively, at every level). Defaults to true. */
17
17
  readonly redactSensitiveData?: boolean;
18
+ /** Pattern used to detect sensitive metadata keys. Defaults to the package pattern. */
19
+ readonly sensitiveKeyPattern?: RegExp;
20
+ /**
21
+ * Metadata keys allowed in public output.
22
+ *
23
+ * When provided, only these keys are copied into `PublicErrorResponse.metadata`
24
+ * (for exposed and non-exposed errors alike). When omitted, metadata is only
25
+ * included for errors with `expose: true`, and never for non-exposed errors.
26
+ */
27
+ readonly publicMetadataKeys?: readonly string[];
18
28
  }
19
29
  /** Public error representation suitable for an API response. */
20
30
  export interface PublicErrorResponse {
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * Error extraction utilities — message, name, stack, root cause.
3
3
  */
4
+ import { isBaseError } from "../base/utils/baseError.utils.js";
4
5
  import { BaseError } from "../base/core/baseError.core.js";
5
6
  import { isErrorLike } from "./errorUtils.typeCheck.js";
6
7
  /** Returns the message from an unknown thrown value. */
@@ -56,7 +57,7 @@ export function getRootBaseError(value) {
56
57
  const visited = new Set();
57
58
  while (current !== undefined && current !== null && !visited.has(current)) {
58
59
  visited.add(current);
59
- if (current instanceof BaseError) {
60
+ if (isBaseError(current)) {
60
61
  result = current;
61
62
  }
62
63
  if (current instanceof Error && "cause" in current) {
@@ -77,7 +78,7 @@ export function getErrorDiagnostics(value) {
77
78
  if (stack !== undefined) {
78
79
  diagnostics.stack = stack;
79
80
  }
80
- if (value instanceof BaseError) {
81
+ if (isBaseError(value)) {
81
82
  diagnostics.code = value.code;
82
83
  diagnostics.category = value.category;
83
84
  diagnostics.severity = value.severity;
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Error transformation utilities — toError, withErrorContext, tryCatch, normalize.
3
3
  */
4
- import { BaseError } from "../base/core/baseError.core.js";
4
+ import type { BaseError } from "../base/core/baseError.core.js";
5
5
  /** Safely converts an unknown thrown value into an Error instance. */
6
6
  export declare function toError(value: unknown, fallback?: string): Error;
7
7
  /** Adds context to an Error while preserving the original error as its cause. */
@@ -1,9 +1,7 @@
1
1
  /**
2
2
  * Error transformation utilities — toError, withErrorContext, tryCatch, normalize.
3
3
  */
4
- import { BaseError } from "../base/core/baseError.core.js";
5
- import { ErrorCategory } from "../base/types/errorCategory.type.js";
6
- import { ErrorSeverity } from "../base/types/errorSeverity.type.js";
4
+ import { normalizeUnknownToBaseError } from "../base/utils/baseError.utils.js";
7
5
  import { getErrorMessage } from "./errorUtils.extraction.js";
8
6
  /** Safely converts an unknown thrown value into an Error instance. */
9
7
  export function toError(value, fallback = "An unexpected error occurred.") {
@@ -37,28 +35,6 @@ export async function tryCatchAsync(operation) {
37
35
  }
38
36
  /** Converts an unknown thrown value into a BaseError. */
39
37
  export function normalizeToBaseError(value) {
40
- if (value instanceof BaseError) {
41
- return value;
42
- }
43
- if (value instanceof Error) {
44
- return new BaseError(value.message || "An unexpected error occurred.", {
45
- code: "INTERNAL_ERROR",
46
- category: ErrorCategory.SYSTEM,
47
- severity: ErrorSeverity.ERROR,
48
- statusCode: 500,
49
- expose: false,
50
- isOperational: false,
51
- cause: value,
52
- });
53
- }
54
- return new BaseError(getErrorMessage(value), {
55
- code: "INTERNAL_ERROR",
56
- category: ErrorCategory.SYSTEM,
57
- severity: ErrorSeverity.ERROR,
58
- statusCode: 500,
59
- expose: false,
60
- isOperational: false,
61
- metadata: { originalType: typeof value },
62
- });
38
+ return normalizeUnknownToBaseError(value);
63
39
  }
64
40
  //# sourceMappingURL=errorUtils.transform.js.map
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Error type-checking utilities.
3
3
  */
4
- import { BaseError } from "../base/core/baseError.core.js";
4
+ import { isBaseError } from "../base/utils/baseError.utils.js";
5
5
  import { ErrorCategory } from "../base/types/errorCategory.type.js";
6
6
  import { ErrorSeverity } from "../base/types/errorSeverity.type.js";
7
7
  /** Type guard for unknown error-like values. */
@@ -13,31 +13,31 @@ export function isErrorLike(value) {
13
13
  }
14
14
  /** Returns whether an error is operational. */
15
15
  export function isOperationalError(value) {
16
- return value instanceof BaseError && value.isOperational;
16
+ return isBaseError(value) && value.isOperational;
17
17
  }
18
18
  /** Returns whether an error is safe to expose to clients. */
19
19
  export function isExposableError(value) {
20
- return value instanceof BaseError && value.expose;
20
+ return isBaseError(value) && value.expose;
21
21
  }
22
22
  /** Returns whether an error represents a server-side failure. */
23
23
  export function isServerError(value) {
24
- if (value instanceof BaseError) {
24
+ if (isBaseError(value)) {
25
25
  return value.statusCode >= 500;
26
26
  }
27
27
  return true;
28
28
  }
29
29
  /** Returns whether an error represents a client-side failure. */
30
30
  export function isClientError(value) {
31
- return (value instanceof BaseError &&
31
+ return (isBaseError(value) &&
32
32
  value.statusCode >= 400 &&
33
33
  value.statusCode < 500);
34
34
  }
35
35
  /** Returns whether an error belongs to a category. */
36
36
  export function hasErrorCategory(value, category) {
37
- return value instanceof BaseError && value.category === category;
37
+ return isBaseError(value) && value.category === category;
38
38
  }
39
39
  /** Returns whether an error has a specific severity. */
40
40
  export function hasErrorSeverity(value, severity) {
41
- return value instanceof BaseError && value.severity === severity;
41
+ return isBaseError(value) && value.severity === severity;
42
42
  }
43
43
  //# sourceMappingURL=errorUtils.typeCheck.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zudojs/errors",
3
- "version": "0.1.1",
3
+ "version": "1.0.1",
4
4
  "description": "Shared error base class, error codes, and error handling utilities for the Zudojs framework.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -13,21 +13,25 @@
13
13
  }
14
14
  },
15
15
  "files": [
16
- "dist"
16
+ "dist",
17
+ "!dist/**/*.map",
18
+ "!dist/**/*.tsbuildinfo",
19
+ "!dist/.tsbuildinfo"
17
20
  ],
18
- "scripts": {
19
- "build": "tsc -p tsconfig.json",
20
- "clean": "rm -rf dist",
21
- "typecheck": "tsc -p tsconfig.json --noEmit"
22
- },
21
+ "sideEffects": false,
23
22
  "dependencies": {},
24
23
  "devDependencies": {
25
- "typescript": "^7.0.2"
24
+ "typescript": "7.0.2",
25
+ "vitest": "^4.1.11"
26
26
  },
27
27
  "engines": {
28
28
  "node": ">=24.0.0"
29
29
  },
30
30
  "license": "MIT",
31
+ "author": {
32
+ "name": "Oluwayemi Oyinlola",
33
+ "url": "https://github.com/oyinlola-tech"
34
+ },
31
35
  "publishConfig": {
32
36
  "access": "public"
33
37
  },
@@ -37,8 +41,19 @@
37
41
  "error-handling"
38
42
  ],
39
43
  "homepage": "https://github.com/oyinlola-tech/zudo#readme",
44
+ "bugs": {
45
+ "url": "https://github.com/oyinlola-tech/zudo/issues"
46
+ },
40
47
  "repository": {
41
48
  "type": "git",
42
- "url": "https://github.com/oyinlola-tech/zudo"
49
+ "url": "https://github.com/oyinlola-tech/zudo",
50
+ "directory": "packages/errors"
51
+ },
52
+ "scripts": {
53
+ "build": "tsc -p tsconfig.json",
54
+ "clean": "rm -rf dist",
55
+ "typecheck": "tsc -p tsconfig.json --noEmit && tsc -p tsconfig.test.json --noEmit",
56
+ "test": "vitest run",
57
+ "test:watch": "vitest"
43
58
  }
44
- }
59
+ }