@venizia/ignis-helpers 0.4.6 → 0.4.7-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 (300) hide show
  1. package/LICENSE.md +1 -3
  2. package/README.md +4 -5
  3. package/dist/esm/common/redact.d.ts +25 -17
  4. package/dist/esm/common/redact.d.ts.map +1 -1
  5. package/dist/esm/common/redact.js +50 -46
  6. package/dist/esm/common/redact.js.map +1 -1
  7. package/dist/esm/common/resolvers.d.ts +7 -5
  8. package/dist/esm/common/resolvers.d.ts.map +1 -1
  9. package/dist/esm/common/resolvers.js +11 -9
  10. package/dist/esm/common/resolvers.js.map +1 -1
  11. package/dist/esm/core.d.ts +6 -3
  12. package/dist/esm/core.d.ts.map +1 -1
  13. package/dist/esm/core.js +6 -3
  14. package/dist/esm/core.js.map +1 -1
  15. package/dist/esm/modules/base.js +4 -4
  16. package/dist/esm/modules/base.js.map +1 -1
  17. package/dist/esm/modules/cron/helper.js +4 -4
  18. package/dist/esm/modules/cron/helper.js.map +1 -1
  19. package/dist/esm/modules/crypto/algorithms/aes-legacy.algorithm.js +3 -3
  20. package/dist/esm/modules/crypto/algorithms/aes-legacy.algorithm.js.map +1 -1
  21. package/dist/esm/modules/crypto/algorithms/aes.algorithm.js +5 -5
  22. package/dist/esm/modules/crypto/algorithms/aes.algorithm.js.map +1 -1
  23. package/dist/esm/modules/crypto/algorithms/base.algorithm.js +3 -3
  24. package/dist/esm/modules/crypto/algorithms/base.algorithm.js.map +1 -1
  25. package/dist/esm/modules/env/app-env.d.ts.map +1 -1
  26. package/dist/esm/modules/env/app-env.js +2 -2
  27. package/dist/esm/modules/env/app-env.js.map +1 -1
  28. package/dist/esm/modules/logger/common/constants.d.ts +23 -21
  29. package/dist/esm/modules/logger/common/constants.d.ts.map +1 -1
  30. package/dist/esm/modules/logger/common/constants.js +45 -42
  31. package/dist/esm/modules/logger/common/constants.js.map +1 -1
  32. package/dist/esm/modules/logger/factory.d.ts +5 -3
  33. package/dist/esm/modules/logger/factory.d.ts.map +1 -1
  34. package/dist/esm/modules/logger/factory.js +5 -3
  35. package/dist/esm/modules/logger/factory.js.map +1 -1
  36. package/dist/esm/modules/logger/formatting/deep-splat.d.ts +10 -6
  37. package/dist/esm/modules/logger/formatting/deep-splat.d.ts.map +1 -1
  38. package/dist/esm/modules/logger/formatting/deep-splat.js +73 -62
  39. package/dist/esm/modules/logger/formatting/deep-splat.js.map +1 -1
  40. package/dist/esm/modules/logger/formatting/error-prettier.d.ts.map +1 -1
  41. package/dist/esm/modules/logger/formatting/error-prettier.js +8 -6
  42. package/dist/esm/modules/logger/formatting/error-prettier.js.map +1 -1
  43. package/dist/esm/modules/logger/hf/logger.d.ts.map +1 -1
  44. package/dist/esm/modules/logger/hf/logger.js +2 -2
  45. package/dist/esm/modules/logger/hf/logger.js.map +1 -1
  46. package/dist/esm/modules/logger/pino/backing.d.ts +0 -9
  47. package/dist/esm/modules/logger/pino/backing.d.ts.map +1 -1
  48. package/dist/esm/modules/logger/pino/backing.js +3 -8
  49. package/dist/esm/modules/logger/pino/backing.js.map +1 -1
  50. package/dist/esm/modules/logger/pino/destination.d.ts +6 -9
  51. package/dist/esm/modules/logger/pino/destination.d.ts.map +1 -1
  52. package/dist/esm/modules/logger/pino/destination.js +12 -13
  53. package/dist/esm/modules/logger/pino/destination.js.map +1 -1
  54. package/dist/esm/modules/logger/pino/logger.js +2 -2
  55. package/dist/esm/modules/logger/pino/logger.js.map +1 -1
  56. package/dist/esm/modules/logger/resolver.js +2 -2
  57. package/dist/esm/modules/logger/resolver.js.map +1 -1
  58. package/dist/esm/modules/logger/slot.d.ts +39 -18
  59. package/dist/esm/modules/logger/slot.d.ts.map +1 -1
  60. package/dist/esm/modules/logger/slot.js +117 -110
  61. package/dist/esm/modules/logger/slot.js.map +1 -1
  62. package/dist/esm/modules/logger/winston/common/constants.d.ts.map +1 -1
  63. package/dist/esm/modules/logger/winston/common/constants.js +7 -6
  64. package/dist/esm/modules/logger/winston/common/constants.js.map +1 -1
  65. package/dist/esm/modules/logger/winston/define.d.ts +0 -7
  66. package/dist/esm/modules/logger/winston/define.d.ts.map +1 -1
  67. package/dist/esm/modules/logger/winston/define.js +0 -5
  68. package/dist/esm/modules/logger/winston/define.js.map +1 -1
  69. package/dist/esm/modules/logger/winston/formats.d.ts +2 -0
  70. package/dist/esm/modules/logger/winston/formats.d.ts.map +1 -1
  71. package/dist/esm/modules/logger/winston/formats.js +17 -4
  72. package/dist/esm/modules/logger/winston/formats.js.map +1 -1
  73. package/dist/esm/modules/logger/winston/index.d.ts +3 -2
  74. package/dist/esm/modules/logger/winston/index.d.ts.map +1 -1
  75. package/dist/esm/modules/logger/winston/index.js +3 -2
  76. package/dist/esm/modules/logger/winston/index.js.map +1 -1
  77. package/dist/esm/modules/logger/winston/logger-factory.js +4 -4
  78. package/dist/esm/modules/logger/winston/logger-factory.js.map +1 -1
  79. package/dist/esm/modules/network/http-request/base-network-request.helper.js +2 -2
  80. package/dist/esm/modules/network/http-request/base-network-request.helper.js.map +1 -1
  81. package/dist/esm/modules/network/http-request/common/index.d.ts +0 -1
  82. package/dist/esm/modules/network/http-request/common/index.d.ts.map +1 -1
  83. package/dist/esm/modules/network/http-request/common/index.js +0 -1
  84. package/dist/esm/modules/network/http-request/common/index.js.map +1 -1
  85. package/dist/esm/modules/network/http-request/fetcher/axios-fetcher.d.ts.map +1 -1
  86. package/dist/esm/modules/network/http-request/fetcher/axios-fetcher.js +4 -2
  87. package/dist/esm/modules/network/http-request/fetcher/axios-fetcher.js.map +1 -1
  88. package/dist/esm/modules/network/http-request/fetcher/node-fetcher.d.ts.map +1 -1
  89. package/dist/esm/modules/network/http-request/fetcher/node-fetcher.js +6 -4
  90. package/dist/esm/modules/network/http-request/fetcher/node-fetcher.js.map +1 -1
  91. package/dist/esm/modules/network/tcp-socket/base-tcp-client.helper.js +4 -4
  92. package/dist/esm/modules/network/tcp-socket/base-tcp-client.helper.js.map +1 -1
  93. package/dist/esm/modules/network/tcp-socket/base-tcp-server.helper.js +4 -4
  94. package/dist/esm/modules/network/tcp-socket/base-tcp-server.helper.js.map +1 -1
  95. package/dist/esm/modules/network/udp-socket/network-udp-client.helper.js +2 -2
  96. package/dist/esm/modules/network/udp-socket/network-udp-client.helper.js.map +1 -1
  97. package/dist/esm/modules/network/utilities/query-string.d.ts +22 -20
  98. package/dist/esm/modules/network/utilities/query-string.d.ts.map +1 -1
  99. package/dist/esm/modules/network/utilities/query-string.js +48 -46
  100. package/dist/esm/modules/network/utilities/query-string.js.map +1 -1
  101. package/dist/esm/modules/network/utilities/url-safety/common/errors.d.ts +0 -10
  102. package/dist/esm/modules/network/utilities/url-safety/common/errors.d.ts.map +1 -1
  103. package/dist/esm/modules/network/utilities/url-safety/common/errors.js +0 -11
  104. package/dist/esm/modules/network/utilities/url-safety/common/errors.js.map +1 -1
  105. package/dist/esm/modules/network/utilities/url-safety/ingest.d.ts.map +1 -1
  106. package/dist/esm/modules/network/utilities/url-safety/ingest.js +2 -1
  107. package/dist/esm/modules/network/utilities/url-safety/ingest.js.map +1 -1
  108. package/dist/esm/modules/network/utilities/url-safety/policy.d.ts +10 -0
  109. package/dist/esm/modules/network/utilities/url-safety/policy.d.ts.map +1 -1
  110. package/dist/esm/modules/network/utilities/url-safety/policy.js +11 -0
  111. package/dist/esm/modules/network/utilities/url-safety/policy.js.map +1 -1
  112. package/dist/esm/modules/pool/abstract.d.ts.map +1 -1
  113. package/dist/esm/modules/pool/abstract.js +4 -2
  114. package/dist/esm/modules/pool/abstract.js.map +1 -1
  115. package/dist/esm/modules/queue/bullmq/helper.d.ts.map +1 -1
  116. package/dist/esm/modules/queue/bullmq/helper.js +6 -6
  117. package/dist/esm/modules/queue/bullmq/helper.js.map +1 -1
  118. package/dist/esm/modules/queue/common/hook.d.ts +14 -12
  119. package/dist/esm/modules/queue/common/hook.d.ts.map +1 -1
  120. package/dist/esm/modules/queue/common/hook.js +21 -19
  121. package/dist/esm/modules/queue/common/hook.js.map +1 -1
  122. package/dist/esm/modules/queue/common/index.d.ts +0 -1
  123. package/dist/esm/modules/queue/common/index.d.ts.map +1 -1
  124. package/dist/esm/modules/queue/common/index.js +0 -1
  125. package/dist/esm/modules/queue/common/index.js.map +1 -1
  126. package/dist/esm/modules/queue/internal/sequential/helper.js +8 -8
  127. package/dist/esm/modules/queue/internal/sequential/helper.js.map +1 -1
  128. package/dist/esm/modules/queue/kafka/base.js +3 -3
  129. package/dist/esm/modules/queue/kafka/base.js.map +1 -1
  130. package/dist/esm/modules/queue/kafka/bundler/index.d.ts +0 -2
  131. package/dist/esm/modules/queue/kafka/bundler/index.d.ts.map +1 -1
  132. package/dist/esm/modules/queue/kafka/bundler/index.js +0 -2
  133. package/dist/esm/modules/queue/kafka/bundler/index.js.map +1 -1
  134. package/dist/esm/modules/queue/kafka/bundler/plugins.d.ts +8 -2
  135. package/dist/esm/modules/queue/kafka/bundler/plugins.d.ts.map +1 -1
  136. package/dist/esm/modules/queue/kafka/bundler/plugins.js +64 -7
  137. package/dist/esm/modules/queue/kafka/bundler/plugins.js.map +1 -1
  138. package/dist/esm/modules/queue/kafka/consumer.d.ts.map +1 -1
  139. package/dist/esm/modules/queue/kafka/consumer.js +26 -24
  140. package/dist/esm/modules/queue/kafka/consumer.js.map +1 -1
  141. package/dist/esm/modules/queue/mqtt/helper.js +10 -10
  142. package/dist/esm/modules/queue/mqtt/helper.js.map +1 -1
  143. package/dist/esm/modules/redis/base/abstract.helper.js +8 -8
  144. package/dist/esm/modules/redis/base/abstract.helper.js.map +1 -1
  145. package/dist/esm/modules/redis/cluster/cluster.helper.js +2 -2
  146. package/dist/esm/modules/redis/cluster/cluster.helper.js.map +1 -1
  147. package/dist/esm/modules/redis/factory.d.ts +13 -9
  148. package/dist/esm/modules/redis/factory.d.ts.map +1 -1
  149. package/dist/esm/modules/redis/factory.js +15 -13
  150. package/dist/esm/modules/redis/factory.js.map +1 -1
  151. package/dist/esm/modules/redis/sentinel/sentinel.helper.js +2 -2
  152. package/dist/esm/modules/redis/sentinel/sentinel.helper.js.map +1 -1
  153. package/dist/esm/modules/redis/single/single.helper.js +2 -2
  154. package/dist/esm/modules/redis/single/single.helper.js.map +1 -1
  155. package/dist/esm/modules/redis/utility.d.ts +13 -11
  156. package/dist/esm/modules/redis/utility.d.ts.map +1 -1
  157. package/dist/esm/modules/redis/utility.js +46 -44
  158. package/dist/esm/modules/redis/utility.js.map +1 -1
  159. package/dist/esm/modules/retry/helper.d.ts.map +1 -1
  160. package/dist/esm/modules/retry/helper.js +6 -4
  161. package/dist/esm/modules/retry/helper.js.map +1 -1
  162. package/dist/esm/modules/secrets/factory.d.ts +5 -3
  163. package/dist/esm/modules/secrets/factory.d.ts.map +1 -1
  164. package/dist/esm/modules/secrets/factory.js +36 -34
  165. package/dist/esm/modules/secrets/factory.js.map +1 -1
  166. package/dist/esm/modules/secrets/hashicorp/hashicorp.helper.d.ts.map +1 -1
  167. package/dist/esm/modules/secrets/hashicorp/hashicorp.helper.js +4 -2
  168. package/dist/esm/modules/secrets/hashicorp/hashicorp.helper.js.map +1 -1
  169. package/dist/esm/modules/socket/socket-io/server/helper.d.ts.map +1 -1
  170. package/dist/esm/modules/socket/socket-io/server/helper.js +11 -11
  171. package/dist/esm/modules/socket/socket-io/server/helper.js.map +1 -1
  172. package/dist/esm/modules/socket/websocket/emitter/helper.d.ts.map +1 -1
  173. package/dist/esm/modules/socket/websocket/emitter/helper.js +3 -3
  174. package/dist/esm/modules/socket/websocket/emitter/helper.js.map +1 -1
  175. package/dist/esm/modules/socket/websocket/server/delivery.d.ts.map +1 -1
  176. package/dist/esm/modules/socket/websocket/server/delivery.js +5 -6
  177. package/dist/esm/modules/socket/websocket/server/delivery.js.map +1 -1
  178. package/dist/esm/modules/socket/websocket/server/helper.d.ts.map +1 -1
  179. package/dist/esm/modules/socket/websocket/server/helper.js +7 -7
  180. package/dist/esm/modules/socket/websocket/server/helper.js.map +1 -1
  181. package/dist/esm/modules/storage/base.d.ts.map +1 -1
  182. package/dist/esm/modules/storage/base.js +9 -8
  183. package/dist/esm/modules/storage/base.js.map +1 -1
  184. package/dist/esm/modules/storage/bun-s3/helper.d.ts.map +1 -1
  185. package/dist/esm/modules/storage/bun-s3/helper.js +25 -18
  186. package/dist/esm/modules/storage/bun-s3/helper.js.map +1 -1
  187. package/dist/esm/modules/storage/bun-s3/utility.d.ts +95 -77
  188. package/dist/esm/modules/storage/bun-s3/utility.d.ts.map +1 -1
  189. package/dist/esm/modules/storage/bun-s3/utility.js +261 -244
  190. package/dist/esm/modules/storage/bun-s3/utility.js.map +1 -1
  191. package/dist/esm/modules/storage/common/errors.d.ts +0 -4
  192. package/dist/esm/modules/storage/common/errors.d.ts.map +1 -1
  193. package/dist/esm/modules/storage/common/errors.js +0 -10
  194. package/dist/esm/modules/storage/common/errors.js.map +1 -1
  195. package/dist/esm/modules/storage/common/utility.d.ts +11 -5
  196. package/dist/esm/modules/storage/common/utility.d.ts.map +1 -1
  197. package/dist/esm/modules/storage/common/utility.js +30 -17
  198. package/dist/esm/modules/storage/common/utility.js.map +1 -1
  199. package/dist/esm/modules/storage/disk/helper.d.ts.map +1 -1
  200. package/dist/esm/modules/storage/disk/helper.js +18 -9
  201. package/dist/esm/modules/storage/disk/helper.js.map +1 -1
  202. package/dist/esm/modules/tree/builder.d.ts.map +1 -1
  203. package/dist/esm/modules/tree/builder.js +2 -1
  204. package/dist/esm/modules/tree/builder.js.map +1 -1
  205. package/dist/esm/modules/uid/opaque.d.ts.map +1 -1
  206. package/dist/esm/modules/uid/opaque.js +4 -2
  207. package/dist/esm/modules/uid/opaque.js.map +1 -1
  208. package/dist/esm/modules/uid/uuid/helper.d.ts +1 -1
  209. package/dist/esm/modules/uid/uuid/helper.d.ts.map +1 -1
  210. package/dist/esm/modules/uid/uuid/helper.js +7 -7
  211. package/dist/esm/modules/uid/uuid/helper.js.map +1 -1
  212. package/dist/esm/modules/uid/uuid/v4.d.ts +11 -8
  213. package/dist/esm/modules/uid/uuid/v4.d.ts.map +1 -1
  214. package/dist/esm/modules/uid/uuid/v4.js +51 -46
  215. package/dist/esm/modules/uid/uuid/v4.js.map +1 -1
  216. package/dist/esm/modules/uid/uuid/v5.d.ts +17 -14
  217. package/dist/esm/modules/uid/uuid/v5.d.ts.map +1 -1
  218. package/dist/esm/modules/uid/uuid/v5.js +83 -78
  219. package/dist/esm/modules/uid/uuid/v5.js.map +1 -1
  220. package/dist/esm/modules/uid/uuid/v7.d.ts +15 -10
  221. package/dist/esm/modules/uid/uuid/v7.d.ts.map +1 -1
  222. package/dist/esm/modules/uid/uuid/v7.js +88 -79
  223. package/dist/esm/modules/uid/uuid/v7.js.map +1 -1
  224. package/dist/esm/modules/worker-thread/bus/base.js +2 -2
  225. package/dist/esm/modules/worker-thread/bus/base.js.map +1 -1
  226. package/dist/esm/modules/worker-thread/worker/base.d.ts.map +1 -1
  227. package/dist/esm/modules/worker-thread/worker/base.js +4 -3
  228. package/dist/esm/modules/worker-thread/worker/base.js.map +1 -1
  229. package/dist/esm/utilities/error.utility.d.ts +7 -0
  230. package/dist/esm/utilities/error.utility.d.ts.map +1 -0
  231. package/dist/esm/utilities/error.utility.js +9 -0
  232. package/dist/esm/utilities/error.utility.js.map +1 -0
  233. package/dist/esm/utilities/form-body.utility.d.ts +12 -10
  234. package/dist/esm/utilities/form-body.utility.d.ts.map +1 -1
  235. package/dist/esm/utilities/form-body.utility.js +19 -16
  236. package/dist/esm/utilities/form-body.utility.js.map +1 -1
  237. package/dist/esm/utilities/hr-time.utility.d.ts +7 -5
  238. package/dist/esm/utilities/hr-time.utility.d.ts.map +1 -1
  239. package/dist/esm/utilities/hr-time.utility.js +11 -9
  240. package/dist/esm/utilities/hr-time.utility.js.map +1 -1
  241. package/dist/esm/utilities/index.d.ts +2 -2
  242. package/dist/esm/utilities/index.d.ts.map +1 -1
  243. package/dist/esm/utilities/index.js +2 -2
  244. package/dist/esm/utilities/index.js.map +1 -1
  245. package/dist/esm/utilities/module.utility.d.ts.map +1 -1
  246. package/dist/esm/utilities/module.utility.js +4 -2
  247. package/dist/esm/utilities/module.utility.js.map +1 -1
  248. package/dist/esm/utilities/parse.utility.d.ts +89 -43
  249. package/dist/esm/utilities/parse.utility.d.ts.map +1 -1
  250. package/dist/esm/utilities/parse.utility.js +173 -141
  251. package/dist/esm/utilities/parse.utility.js.map +1 -1
  252. package/dist/esm/utilities/performance.utility.d.ts +15 -13
  253. package/dist/esm/utilities/performance.utility.d.ts.map +1 -1
  254. package/dist/esm/utilities/performance.utility.js +34 -29
  255. package/dist/esm/utilities/performance.utility.js.map +1 -1
  256. package/dist/esm/utilities/promise.utility.d.ts +20 -18
  257. package/dist/esm/utilities/promise.utility.d.ts.map +1 -1
  258. package/dist/esm/utilities/promise.utility.js +41 -51
  259. package/dist/esm/utilities/promise.utility.js.map +1 -1
  260. package/dist/esm/utilities/request.utility.d.ts +35 -29
  261. package/dist/esm/utilities/request.utility.d.ts.map +1 -1
  262. package/dist/esm/utilities/request.utility.js +117 -115
  263. package/dist/esm/utilities/request.utility.js.map +1 -1
  264. package/package.json +4 -15
  265. package/dist/esm/modules/logger/winston/formatters/deep-splat.d.ts +0 -4
  266. package/dist/esm/modules/logger/winston/formatters/deep-splat.d.ts.map +0 -1
  267. package/dist/esm/modules/logger/winston/formatters/deep-splat.js +0 -14
  268. package/dist/esm/modules/logger/winston/formatters/deep-splat.js.map +0 -1
  269. package/dist/esm/modules/logger/winston/formatters/index.d.ts +0 -2
  270. package/dist/esm/modules/logger/winston/formatters/index.d.ts.map +0 -1
  271. package/dist/esm/modules/logger/winston/formatters/index.js +0 -2
  272. package/dist/esm/modules/logger/winston/formatters/index.js.map +0 -1
  273. package/dist/esm/modules/network/http-request/common/types.d.ts +0 -2
  274. package/dist/esm/modules/network/http-request/common/types.d.ts.map +0 -1
  275. package/dist/esm/modules/network/http-request/common/types.js +0 -2
  276. package/dist/esm/modules/network/http-request/common/types.js.map +0 -1
  277. package/dist/esm/modules/queue/common/types.d.ts +0 -2
  278. package/dist/esm/modules/queue/common/types.d.ts.map +0 -1
  279. package/dist/esm/modules/queue/common/types.js +0 -2
  280. package/dist/esm/modules/queue/common/types.js.map +0 -1
  281. package/dist/esm/modules/queue/kafka/bundler/platformatic-require.plugin.d.ts +0 -4
  282. package/dist/esm/modules/queue/kafka/bundler/platformatic-require.plugin.d.ts.map +0 -1
  283. package/dist/esm/modules/queue/kafka/bundler/platformatic-require.plugin.js +0 -28
  284. package/dist/esm/modules/queue/kafka/bundler/platformatic-require.plugin.js.map +0 -1
  285. package/dist/esm/modules/queue/kafka/bundler/platformatic-wasm.plugin.d.ts +0 -4
  286. package/dist/esm/modules/queue/kafka/bundler/platformatic-wasm.plugin.d.ts.map +0 -1
  287. package/dist/esm/modules/queue/kafka/bundler/platformatic-wasm.plugin.js +0 -26
  288. package/dist/esm/modules/queue/kafka/bundler/platformatic-wasm.plugin.js.map +0 -1
  289. package/dist/esm/modules/storage/minio/helper.d.ts +0 -55
  290. package/dist/esm/modules/storage/minio/helper.d.ts.map +0 -1
  291. package/dist/esm/modules/storage/minio/helper.js +0 -176
  292. package/dist/esm/modules/storage/minio/helper.js.map +0 -1
  293. package/dist/esm/modules/storage/minio/index.d.ts +0 -2
  294. package/dist/esm/modules/storage/minio/index.d.ts.map +0 -1
  295. package/dist/esm/modules/storage/minio/index.js +0 -2
  296. package/dist/esm/modules/storage/minio/index.js.map +0 -1
  297. package/dist/esm/utilities/sleep.utility.d.ts +0 -2
  298. package/dist/esm/utilities/sleep.utility.d.ts.map +0 -1
  299. package/dist/esm/utilities/sleep.utility.js +0 -4
  300. package/dist/esm/utilities/sleep.utility.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"aes-legacy.algorithm.js","sourceRoot":"","sources":["../../../../../src/modules/crypto/algorithms/aes-legacy.algorithm.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AACnD,OAAO,CAAC,MAAM,aAAa,CAAC;AAC5B,OAAO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cAAc,CACf,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,OAAO,EAAE,CAAC;gBACZ,MAAM,KAAK,CAAC;YACd,CAAC;YAED,OAAO,OAAO,CAAC;QACjB,CAAC;IACH,CAAC;IAED,WAAW,CAAC,IAA8C;QACxD,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;QAEtC,IAAI,CAAC,YAAY,IAAI,OAAO,CAAC,EAAE,KAAK,EAAE,YAAY,EAAE,CAAC,EAAE,CAAC;YACtD,OAAO,EAAE,CAAC;QACZ,CAAC;QAED,MAAM,MAAM,GAAG,EAAE,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC;QAC7C,MAAM,WAAW,GAAG,MAAM,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC;QAC9C,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC,CAAC;QACjE,OAAO,SAAS,CAAC;IACnB,CAAC;IAEO,wBAAwB,CAAC,IAAyD;QACxF,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,eAAe,EAAE,GAAG,IAAI,CAAC;QAE1D,IAAI,MAAM,CAAC,MAAM,GAAG,MAAM,EAAE,CAAC;YAC3B,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;QACjC,CAAC;QAED,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACvC,CAAC;CACF","sourcesContent":["import { isEmpty } from '@venizia/ignis-inversion';\nimport C from 'node:crypto';\nimport fs from 'node:fs';\nimport { DEFAULT_PAD_END } from '../common';\nimport type { AESAlgorithmType } from './aes.algorithm';\nimport { BaseCryptoAlgorithm } from './base.algorithm';\n\nconst DEFAULT_LENGTH = 16;\n\ninterface IAESExtraOptions {\n iv?: Buffer;\n inputEncoding?: BufferEncoding;\n outputEncoding?: BufferEncoding;\n doThrow?: boolean;\n}\n\n/**\n * Frozen back-compat format - keys come from `normalizeSecretKeyLegacy` (padEnd/truncate), never\n * PBKDF2. `kdfSalt`/`kdfIterations` are deliberately absent from `IAESExtraOptions`: there is no\n * salt to override, so the option would type-check and silently do nothing.\n */\nexport class LegacyAES extends BaseCryptoAlgorithm<\n AESAlgorithmType,\n string,\n string,\n string,\n string,\n string,\n IAESExtraOptions\n> {\n constructor(opts: { algorithm: AESAlgorithmType }) {\n super({ scope: LegacyAES.name, ...opts });\n }\n\n static withAlgorithm(algorithm: AESAlgorithmType) {\n return new LegacyAES({ algorithm });\n }\n\n encrypt(opts: { message: string; secret: string; opts?: IAESExtraOptions }) {\n const { message, secret } = opts;\n const {\n iv = C.randomBytes(DEFAULT_LENGTH),\n inputEncoding = 'utf-8',\n outputEncoding = 'base64',\n doThrow = true,\n } = opts.opts ?? {};\n\n try {\n const secretKey = this.normalizeSecretKeyLegacy({\n secret,\n length: this.getAlgorithmKeySize(),\n });\n\n const cipher = C.createCipheriv(this.algorithm, Buffer.from(secretKey), iv);\n\n const parts = [iv];\n const cipherText = cipher.update(message, inputEncoding);\n const cipherFinal = cipher.final();\n\n switch (this.algorithm) {\n case 'aes-256-cbc': {\n break;\n }\n case 'aes-256-gcm': {\n parts.push((cipher as C.CipherGCM).getAuthTag());\n break;\n }\n }\n parts.push(cipherText);\n parts.push(cipherFinal);\n\n return Buffer.concat(parts).toString(outputEncoding);\n } catch (error) {\n if (doThrow) {\n throw error;\n }\n\n return message;\n }\n }\n\n encryptFile(opts: { absolutePath: string; secret: string }): string {\n const { absolutePath, secret } = opts;\n\n if (!absolutePath || isEmpty({ value: absolutePath })) {\n return '';\n }\n\n const buffer = fs.readFileSync(absolutePath);\n const fileContent = buffer?.toString('utf-8');\n const encrypted = this.encrypt({ message: fileContent, secret });\n return encrypted;\n }\n\n decrypt(opts: { message: string; secret: string; opts?: IAESExtraOptions }) {\n const { message, secret } = opts;\n const { inputEncoding = 'base64', outputEncoding = 'utf-8', doThrow = true } = opts.opts ?? {};\n\n try {\n const iv =\n opts.opts?.iv ??\n Buffer.from(message, inputEncoding).subarray(0, DEFAULT_LENGTH) ??\n Buffer.alloc(DEFAULT_LENGTH, 0);\n let messageIndex = iv.length;\n\n const secretKey = this.normalizeSecretKeyLegacy({\n secret,\n length: this.getAlgorithmKeySize(),\n });\n const decipher = C.createDecipheriv(this.algorithm, Buffer.from(secretKey), iv);\n\n switch (this.algorithm) {\n case 'aes-256-cbc': {\n break;\n }\n case 'aes-256-gcm': {\n const authTag = Buffer.from(message, inputEncoding).subarray(\n iv.length,\n iv.length + DEFAULT_LENGTH,\n );\n messageIndex += authTag.length;\n (decipher as C.DecipherGCM).setAuthTag(authTag);\n break;\n }\n }\n\n const cipherText = Buffer.from(message, inputEncoding).subarray(messageIndex);\n return Buffer.concat([decipher.update(cipherText), decipher.final()]).toString(\n outputEncoding,\n );\n } catch (error) {\n if (doThrow) {\n throw error;\n }\n\n return message;\n }\n }\n\n decryptFile(opts: { absolutePath: string; secret: string }) {\n const { absolutePath, secret } = opts;\n\n if (!absolutePath || isEmpty({ value: absolutePath })) {\n return '';\n }\n\n const buffer = fs.readFileSync(absolutePath);\n const fileContent = buffer?.toString('utf-8');\n const decrypted = this.decrypt({ message: fileContent, secret });\n return decrypted;\n }\n\n private normalizeSecretKeyLegacy(opts: { secret: string; length: number; padEnd?: string }) {\n const { secret, length, padEnd = DEFAULT_PAD_END } = opts;\n\n if (secret.length > length) {\n return secret.slice(0, length);\n }\n\n return secret.padEnd(length, padEnd);\n }\n}\n"]}
1
+ {"version":3,"file":"aes-legacy.algorithm.js","sourceRoot":"","sources":["../../../../../src/modules/crypto/algorithms/aes-legacy.algorithm.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,CAAC,MAAM,aAAa,CAAC;AAC5B,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAA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QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,OAAO,EAAE,CAAC;gBACZ,MAAM,KAAK,CAAC;YACd,CAAC;YAED,OAAO,OAAO,CAAC;QACjB,CAAC;IACH,CAAC;IAED,WAAW,CAAC,IAA8C;QACxD,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;QAEtC,IAAI,CAAC,YAAY,IAAI,aAAa,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,YAAY,EAAE,CAAC,EAAE,CAAC;YACpE,OAAO,EAAE,CAAC;QACZ,CAAC;QAED,MAAM,MAAM,GAAG,EAAE,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC;QAC7C,MAAM,WAAW,GAAG,MAAM,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC;QAC9C,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC,CAAC;QACjE,OAAO,SAAS,CAAC;IACnB,CAAC;IAEO,wBAAwB,CAAC,IAAyD;QACxF,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,eAAe,EAAE,GAAG,IAAI,CAAC;QAE1D,IAAI,MAAM,CAAC,MAAM,GAAG,MAAM,EAAE,CAAC;YAC3B,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;QACjC,CAAC;QAED,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACvC,CAAC;CACF","sourcesContent":["import { ObjectUtility } from '@venizia/ignis-inversion';\nimport C from 'node:crypto';\nimport fs from 'node:fs';\nimport { DEFAULT_PAD_END } from '../common';\nimport type { AESAlgorithmType } from './aes.algorithm';\nimport { BaseCryptoAlgorithm } from './base.algorithm';\n\nconst DEFAULT_LENGTH = 16;\n\ninterface IAESExtraOptions {\n iv?: Buffer;\n inputEncoding?: BufferEncoding;\n outputEncoding?: BufferEncoding;\n doThrow?: boolean;\n}\n\n/**\n * Frozen back-compat format - keys come from `normalizeSecretKeyLegacy` (padEnd/truncate), never\n * PBKDF2. `kdfSalt`/`kdfIterations` are deliberately absent from `IAESExtraOptions`: there is no\n * salt to override, so the option would type-check and silently do nothing.\n */\nexport class LegacyAES extends BaseCryptoAlgorithm<\n AESAlgorithmType,\n string,\n string,\n string,\n string,\n string,\n IAESExtraOptions\n> {\n constructor(opts: { algorithm: AESAlgorithmType }) {\n super({ scope: LegacyAES.name, ...opts });\n }\n\n static withAlgorithm(algorithm: AESAlgorithmType) {\n return new LegacyAES({ algorithm });\n }\n\n encrypt(opts: { message: string; secret: string; opts?: IAESExtraOptions }) {\n const { message, secret } = opts;\n const {\n iv = C.randomBytes(DEFAULT_LENGTH),\n inputEncoding = 'utf-8',\n outputEncoding = 'base64',\n doThrow = true,\n } = opts.opts ?? {};\n\n try {\n const secretKey = this.normalizeSecretKeyLegacy({\n secret,\n length: this.getAlgorithmKeySize(),\n });\n\n const cipher = C.createCipheriv(this.algorithm, Buffer.from(secretKey), iv);\n\n const parts = [iv];\n const cipherText = cipher.update(message, inputEncoding);\n const cipherFinal = cipher.final();\n\n switch (this.algorithm) {\n case 'aes-256-cbc': {\n break;\n }\n case 'aes-256-gcm': {\n parts.push((cipher as C.CipherGCM).getAuthTag());\n break;\n }\n }\n parts.push(cipherText);\n parts.push(cipherFinal);\n\n return Buffer.concat(parts).toString(outputEncoding);\n } catch (error) {\n if (doThrow) {\n throw error;\n }\n\n return message;\n }\n }\n\n encryptFile(opts: { absolutePath: string; secret: string }): string {\n const { absolutePath, secret } = opts;\n\n if (!absolutePath || ObjectUtility.isEmpty({ value: absolutePath })) {\n return '';\n }\n\n const buffer = fs.readFileSync(absolutePath);\n const fileContent = buffer?.toString('utf-8');\n const encrypted = this.encrypt({ message: fileContent, secret });\n return encrypted;\n }\n\n decrypt(opts: { message: string; secret: string; opts?: IAESExtraOptions }) {\n const { message, secret } = opts;\n const { inputEncoding = 'base64', outputEncoding = 'utf-8', doThrow = true } = opts.opts ?? {};\n\n try {\n const iv =\n opts.opts?.iv ??\n Buffer.from(message, inputEncoding).subarray(0, DEFAULT_LENGTH) ??\n Buffer.alloc(DEFAULT_LENGTH, 0);\n let messageIndex = iv.length;\n\n const secretKey = this.normalizeSecretKeyLegacy({\n secret,\n length: this.getAlgorithmKeySize(),\n });\n const decipher = C.createDecipheriv(this.algorithm, Buffer.from(secretKey), iv);\n\n switch (this.algorithm) {\n case 'aes-256-cbc': {\n break;\n }\n case 'aes-256-gcm': {\n const authTag = Buffer.from(message, inputEncoding).subarray(\n iv.length,\n iv.length + DEFAULT_LENGTH,\n );\n messageIndex += authTag.length;\n (decipher as C.DecipherGCM).setAuthTag(authTag);\n break;\n }\n }\n\n const cipherText = Buffer.from(message, inputEncoding).subarray(messageIndex);\n return Buffer.concat([decipher.update(cipherText), decipher.final()]).toString(\n outputEncoding,\n );\n } catch (error) {\n if (doThrow) {\n throw error;\n }\n\n return message;\n }\n }\n\n decryptFile(opts: { absolutePath: string; secret: string }) {\n const { absolutePath, secret } = opts;\n\n if (!absolutePath || ObjectUtility.isEmpty({ value: absolutePath })) {\n return '';\n }\n\n const buffer = fs.readFileSync(absolutePath);\n const fileContent = buffer?.toString('utf-8');\n const decrypted = this.decrypt({ message: fileContent, secret });\n return decrypted;\n }\n\n private normalizeSecretKeyLegacy(opts: { secret: string; length: number; padEnd?: string }) {\n const { secret, length, padEnd = DEFAULT_PAD_END } = opts;\n\n if (secret.length > length) {\n return secret.slice(0, length);\n }\n\n return secret.padEnd(length, padEnd);\n }\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  import { AESAlgorithms } from './aes.constants.js';
2
- import { isEmpty } from '@venizia/ignis-inversion';
2
+ import { ObjectUtility } from '@venizia/ignis-inversion';
3
3
  import C from 'node:crypto';
4
4
  import fs from 'node:fs';
5
5
  import { getError } from '../../error/index.js';
@@ -18,7 +18,7 @@ export class AES extends BaseCryptoAlgorithm {
18
18
  resolveEncryptKey(opts) {
19
19
  const { secret, kdfSalt, kdfIterations } = opts;
20
20
  const entry = Array.isArray(secret) ? secret[0] : { id: DEFAULT_KEY_ID, secret };
21
- if (!entry || isEmpty({ value: entry.secret })) {
21
+ if (!entry || ObjectUtility.isEmpty({ value: entry.secret })) {
22
22
  throw getError({ message: '[AES][resolveEncryptKey] Missing secret or empty keyring' });
23
23
  }
24
24
  const key = this.normalizeSecretKey({
@@ -42,7 +42,7 @@ export class AES extends BaseCryptoAlgorithm {
42
42
  });
43
43
  }
44
44
  // Without this the empty secret derives a key from '' and fails as an opaque OpenSSL error, hiding a plain configuration mistake.
45
- if (isEmpty({ value: entry.secret })) {
45
+ if (ObjectUtility.isEmpty({ value: entry.secret })) {
46
46
  throw getError({
47
47
  message: `[AES][resolveDecryptKey] Keyring entry for key id "${id}" has an empty secret`,
48
48
  });
@@ -86,7 +86,7 @@ export class AES extends BaseCryptoAlgorithm {
86
86
  }
87
87
  encryptFile(opts) {
88
88
  const { absolutePath, secret } = opts;
89
- if (!absolutePath || isEmpty({ value: absolutePath })) {
89
+ if (!absolutePath || ObjectUtility.isEmpty({ value: absolutePath })) {
90
90
  return '';
91
91
  }
92
92
  const buffer = fs.readFileSync(absolutePath);
@@ -134,7 +134,7 @@ export class AES extends BaseCryptoAlgorithm {
134
134
  }
135
135
  decryptFile(opts) {
136
136
  const { absolutePath, secret } = opts;
137
- if (!absolutePath || isEmpty({ value: absolutePath })) {
137
+ if (!absolutePath || ObjectUtility.isEmpty({ value: absolutePath })) {
138
138
  return '';
139
139
  }
140
140
  const buffer = fs.readFileSync(absolutePath);
@@ -1 +1 @@
1
- {"version":3,"file":"aes.algorithm.js","sourceRoot":"","sources":["../../../../../src/modules/crypto/algorithms/aes.algorithm.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAyB,MAAM,iBAAiB,CAAC;AACvE,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AACnD,OAAO,CAAC,MAAM,aA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MAAM,KAAK,CAAC;YACd,CAAC;YAED,OAAO,OAAO,CAAC;QACjB,CAAC;IACH,CAAC;IAED,WAAW,CAAC,IAAkD;QAC5D,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;QAEtC,IAAI,CAAC,YAAY,IAAI,OAAO,CAAC,EAAE,KAAK,EAAE,YAAY,EAAE,CAAC,EAAE,CAAC;YACtD,OAAO,EAAE,CAAC;QACZ,CAAC;QAED,MAAM,MAAM,GAAG,EAAE,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC;QAC7C,MAAM,WAAW,GAAG,MAAM,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC;QAC9C,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC,CAAC;QACjE,OAAO,SAAS,CAAC;IACnB,CAAC;CACF","sourcesContent":["import { AESAlgorithms, type AESAlgorithmType } from './aes.constants';\nimport { isEmpty } from '@venizia/ignis-inversion';\nimport C from 'node:crypto';\nimport fs from 'node:fs';\nimport { getError } from '@/modules/error';\nimport { BaseCryptoAlgorithm } from './base.algorithm';\n\nconst DEFAULT_LENGTH = 16;\nconst CIPHERTEXT_VERSION = 0x01;\nconst DEFAULT_KEY_ID = '0';\n\ninterface IAESDecryptOptions {\n inputEncoding?: BufferEncoding;\n outputEncoding?: BufferEncoding;\n doThrow?: boolean;\n /** Per-deployment PBKDF2 salt override. Must be supplied identically on encrypt and decrypt; omit for the shipped default. */\n kdfSalt?: string;\n /** PBKDF2 iteration count override. Must be supplied identically on encrypt and decrypt; omit for the shipped default. */\n kdfIterations?: number;\n}\n\n/** `iv` is encrypt-only: the envelope carries the IV, so decrypt reads it from there and a supplied one would be silently ignored. */\ninterface IAESExtraOptions extends IAESDecryptOptions {\n iv?: Buffer;\n}\n\nexport interface IAESKeyringEntry {\n id: string;\n secret: string;\n}\n\nexport type TAESSecret = string | IAESKeyringEntry[];\n\nexport { AESAlgorithms, type AESAlgorithmType };\n\nexport class AES extends BaseCryptoAlgorithm<\n AESAlgorithmType,\n string,\n string,\n TAESSecret,\n string,\n string,\n IAESExtraOptions\n> {\n constructor(opts: { algorithm: AESAlgorithmType }) {\n super({ scope: AES.name, ...opts });\n }\n\n static withAlgorithm(algorithm: AESAlgorithmType) {\n return new AES({ algorithm });\n }\n\n protected resolveEncryptKey(opts: {\n secret: TAESSecret;\n kdfSalt?: string;\n kdfIterations?: number;\n }): { id: string; key: Buffer } {\n const { secret, kdfSalt, kdfIterations } = opts;\n const entry = Array.isArray(secret) ? secret[0] : { id: DEFAULT_KEY_ID, secret };\n\n if (!entry || isEmpty({ value: entry.secret })) {\n throw getError({ message: '[AES][resolveEncryptKey] Missing secret or empty keyring' });\n }\n\n const key = this.normalizeSecretKey({\n secret: entry.secret,\n length: this.getAlgorithmKeySize(),\n kdfSalt,\n kdfIterations,\n });\n return { id: entry.id, key };\n }\n\n protected resolveDecryptKey(opts: {\n secret: TAESSecret;\n id: string;\n kdfSalt?: string;\n kdfIterations?: number;\n }): Buffer {\n const { secret, id, kdfSalt, kdfIterations } = opts;\n const length = this.getAlgorithmKeySize();\n\n if (!Array.isArray(secret)) {\n return this.normalizeSecretKey({ secret, length, kdfSalt, kdfIterations });\n }\n\n const entry = secret.find((e) => e.id === id);\n if (!entry) {\n throw getError({\n message: `[AES][resolveDecryptKey] No key in keyring matches ciphertext key id \"${id}\"`,\n });\n }\n\n // Without this the empty secret derives a key from '' and fails as an opaque OpenSSL error, hiding a plain configuration mistake.\n if (isEmpty({ value: entry.secret })) {\n throw getError({\n message: `[AES][resolveDecryptKey] Keyring entry for key id \"${id}\" has an empty secret`,\n });\n }\n\n return this.normalizeSecretKey({ secret: entry.secret, length, kdfSalt, kdfIterations });\n }\n\n encrypt(opts: { message: string; secret: TAESSecret; opts?: IAESExtraOptions }) {\n const { message, secret } = opts;\n const {\n iv = C.randomBytes(DEFAULT_LENGTH),\n inputEncoding = 'utf-8',\n outputEncoding = 'base64',\n doThrow = true,\n kdfSalt,\n kdfIterations,\n } = opts.opts ?? {};\n\n try {\n const { id, key } = this.resolveEncryptKey({ secret, kdfSalt, kdfIterations });\n const idBuffer = Buffer.from(id, 'utf-8');\n if (idBuffer.length > 0xff) {\n throw getError({ message: '[AES][encrypt] Key id too long (max 255 bytes)' });\n }\n\n const cipher = C.createCipheriv(this.algorithm, key, iv);\n\n // Envelope: [version(1)][idLen(1)][id(idLen)][iv(16)][authTag(16, gcm only)][cipher]\n const header = Buffer.from([CIPHERTEXT_VERSION, idBuffer.length]);\n const parts = [header, idBuffer, iv];\n\n const cipherText = cipher.update(message, inputEncoding);\n const cipherFinal = cipher.final();\n\n switch (this.algorithm) {\n case 'aes-256-cbc': {\n break;\n }\n case 'aes-256-gcm': {\n parts.push((cipher as C.CipherGCM).getAuthTag());\n break;\n }\n }\n parts.push(cipherText);\n parts.push(cipherFinal);\n\n return Buffer.concat(parts).toString(outputEncoding);\n } catch (error) {\n if (doThrow) {\n throw error;\n }\n\n return message;\n }\n }\n\n encryptFile(opts: { absolutePath: string; secret: TAESSecret }): string {\n const { absolutePath, secret } = opts;\n\n if (!absolutePath || isEmpty({ value: absolutePath })) {\n return '';\n }\n\n const buffer = fs.readFileSync(absolutePath);\n const fileContent = buffer?.toString('utf-8');\n const encrypted = this.encrypt({ message: fileContent, secret });\n return encrypted;\n }\n\n decrypt(opts: { message: string; secret: TAESSecret; opts?: IAESDecryptOptions }) {\n const { message, secret } = opts;\n const {\n inputEncoding = 'base64',\n outputEncoding = 'utf-8',\n doThrow = true,\n kdfSalt,\n kdfIterations,\n } = opts.opts ?? {};\n\n try {\n const raw = Buffer.from(message, inputEncoding);\n\n const version = raw[0];\n if (version !== CIPHERTEXT_VERSION) {\n throw getError({ message: `[AES][decrypt] Unsupported ciphertext version: ${version}` });\n }\n\n const idLength = raw[1];\n let cursor = 2;\n\n const id = raw.subarray(cursor, cursor + idLength).toString('utf-8');\n cursor += idLength;\n\n const iv = raw.subarray(cursor, cursor + DEFAULT_LENGTH);\n cursor += DEFAULT_LENGTH;\n\n const key = this.resolveDecryptKey({ secret, id, kdfSalt, kdfIterations });\n const decipher = C.createDecipheriv(this.algorithm, key, iv);\n\n switch (this.algorithm) {\n case 'aes-256-cbc': {\n break;\n }\n case 'aes-256-gcm': {\n const authTag = raw.subarray(cursor, cursor + DEFAULT_LENGTH);\n cursor += DEFAULT_LENGTH;\n (decipher as C.DecipherGCM).setAuthTag(authTag);\n break;\n }\n }\n\n const cipherText = raw.subarray(cursor);\n return Buffer.concat([decipher.update(cipherText), decipher.final()]).toString(\n outputEncoding,\n );\n } catch (error) {\n if (doThrow) {\n throw error;\n }\n\n return message;\n }\n }\n\n decryptFile(opts: { absolutePath: string; secret: TAESSecret }) {\n const { absolutePath, secret } = opts;\n\n if (!absolutePath || isEmpty({ value: absolutePath })) {\n return '';\n }\n\n const buffer = fs.readFileSync(absolutePath);\n const fileContent = buffer?.toString('utf-8');\n const decrypted = this.decrypt({ message: fileContent, secret });\n return decrypted;\n }\n}\n"]}
1
+ {"version":3,"file":"aes.algorithm.js","sourceRoot":"","sources":["../../../../../src/modules/crypto/algorithms/aes.algorithm.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAyB,MAAM,iBAAiB,CAAC;AACvE,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,CAAC,MAAM,aAAa,CAAC;AAC5B,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAEvD,MAAM,cAAc,GAAG,EAAE,CAAC;AAC1B,MAAM,kBAAkB,GAAG,IAAI,CAAC;AAChC,MAAM,cAAc,GAAG,GAAG,CAAC;AAwB3B,OAAO,EAAE,aAAa,EAAyB,CAAC;AAEhD,MAAM,OAAO,GAAI,SAAQ,mBAQxB;IACC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M,GAAG,EAAE,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC;QAC7C,MAAM,WAAW,GAAG,MAAM,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC;QAC9C,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC,CAAC;QACjE,OAAO,SAAS,CAAC;IACnB,CAAC;CACF","sourcesContent":["import { AESAlgorithms, type AESAlgorithmType } from './aes.constants';\nimport { ObjectUtility } from '@venizia/ignis-inversion';\nimport C from 'node:crypto';\nimport fs from 'node:fs';\nimport { getError } from '@/modules/error';\nimport { BaseCryptoAlgorithm } from './base.algorithm';\n\nconst DEFAULT_LENGTH = 16;\nconst CIPHERTEXT_VERSION = 0x01;\nconst DEFAULT_KEY_ID = '0';\n\ninterface IAESDecryptOptions {\n inputEncoding?: BufferEncoding;\n outputEncoding?: BufferEncoding;\n doThrow?: boolean;\n /** Per-deployment PBKDF2 salt override. Must be supplied identically on encrypt and decrypt; omit for the shipped default. */\n kdfSalt?: string;\n /** PBKDF2 iteration count override. Must be supplied identically on encrypt and decrypt; omit for the shipped default. */\n kdfIterations?: number;\n}\n\n/** `iv` is encrypt-only: the envelope carries the IV, so decrypt reads it from there and a supplied one would be silently ignored. */\ninterface IAESExtraOptions extends IAESDecryptOptions {\n iv?: Buffer;\n}\n\nexport interface IAESKeyringEntry {\n id: string;\n secret: string;\n}\n\nexport type TAESSecret = string | IAESKeyringEntry[];\n\nexport { AESAlgorithms, type AESAlgorithmType };\n\nexport class AES extends BaseCryptoAlgorithm<\n AESAlgorithmType,\n string,\n string,\n TAESSecret,\n string,\n string,\n IAESExtraOptions\n> {\n constructor(opts: { algorithm: AESAlgorithmType }) {\n super({ scope: AES.name, ...opts });\n }\n\n static withAlgorithm(algorithm: AESAlgorithmType) {\n return new AES({ algorithm });\n }\n\n protected resolveEncryptKey(opts: {\n secret: TAESSecret;\n kdfSalt?: string;\n kdfIterations?: number;\n }): { id: string; key: Buffer } {\n const { secret, kdfSalt, kdfIterations } = opts;\n const entry = Array.isArray(secret) ? secret[0] : { id: DEFAULT_KEY_ID, secret };\n\n if (!entry || ObjectUtility.isEmpty({ value: entry.secret })) {\n throw getError({ message: '[AES][resolveEncryptKey] Missing secret or empty keyring' });\n }\n\n const key = this.normalizeSecretKey({\n secret: entry.secret,\n length: this.getAlgorithmKeySize(),\n kdfSalt,\n kdfIterations,\n });\n return { id: entry.id, key };\n }\n\n protected resolveDecryptKey(opts: {\n secret: TAESSecret;\n id: string;\n kdfSalt?: string;\n kdfIterations?: number;\n }): Buffer {\n const { secret, id, kdfSalt, kdfIterations } = opts;\n const length = this.getAlgorithmKeySize();\n\n if (!Array.isArray(secret)) {\n return this.normalizeSecretKey({ secret, length, kdfSalt, kdfIterations });\n }\n\n const entry = secret.find((e) => e.id === id);\n if (!entry) {\n throw getError({\n message: `[AES][resolveDecryptKey] No key in keyring matches ciphertext key id \"${id}\"`,\n });\n }\n\n // Without this the empty secret derives a key from '' and fails as an opaque OpenSSL error, hiding a plain configuration mistake.\n if (ObjectUtility.isEmpty({ value: entry.secret })) {\n throw getError({\n message: `[AES][resolveDecryptKey] Keyring entry for key id \"${id}\" has an empty secret`,\n });\n }\n\n return this.normalizeSecretKey({ secret: entry.secret, length, kdfSalt, kdfIterations });\n }\n\n encrypt(opts: { message: string; secret: TAESSecret; opts?: IAESExtraOptions }) {\n const { message, secret } = opts;\n const {\n iv = C.randomBytes(DEFAULT_LENGTH),\n inputEncoding = 'utf-8',\n outputEncoding = 'base64',\n doThrow = true,\n kdfSalt,\n kdfIterations,\n } = opts.opts ?? {};\n\n try {\n const { id, key } = this.resolveEncryptKey({ secret, kdfSalt, kdfIterations });\n const idBuffer = Buffer.from(id, 'utf-8');\n if (idBuffer.length > 0xff) {\n throw getError({ message: '[AES][encrypt] Key id too long (max 255 bytes)' });\n }\n\n const cipher = C.createCipheriv(this.algorithm, key, iv);\n\n // Envelope: [version(1)][idLen(1)][id(idLen)][iv(16)][authTag(16, gcm only)][cipher]\n const header = Buffer.from([CIPHERTEXT_VERSION, idBuffer.length]);\n const parts = [header, idBuffer, iv];\n\n const cipherText = cipher.update(message, inputEncoding);\n const cipherFinal = cipher.final();\n\n switch (this.algorithm) {\n case 'aes-256-cbc': {\n break;\n }\n case 'aes-256-gcm': {\n parts.push((cipher as C.CipherGCM).getAuthTag());\n break;\n }\n }\n parts.push(cipherText);\n parts.push(cipherFinal);\n\n return Buffer.concat(parts).toString(outputEncoding);\n } catch (error) {\n if (doThrow) {\n throw error;\n }\n\n return message;\n }\n }\n\n encryptFile(opts: { absolutePath: string; secret: TAESSecret }): string {\n const { absolutePath, secret } = opts;\n\n if (!absolutePath || ObjectUtility.isEmpty({ value: absolutePath })) {\n return '';\n }\n\n const buffer = fs.readFileSync(absolutePath);\n const fileContent = buffer?.toString('utf-8');\n const encrypted = this.encrypt({ message: fileContent, secret });\n return encrypted;\n }\n\n decrypt(opts: { message: string; secret: TAESSecret; opts?: IAESDecryptOptions }) {\n const { message, secret } = opts;\n const {\n inputEncoding = 'base64',\n outputEncoding = 'utf-8',\n doThrow = true,\n kdfSalt,\n kdfIterations,\n } = opts.opts ?? {};\n\n try {\n const raw = Buffer.from(message, inputEncoding);\n\n const version = raw[0];\n if (version !== CIPHERTEXT_VERSION) {\n throw getError({ message: `[AES][decrypt] Unsupported ciphertext version: ${version}` });\n }\n\n const idLength = raw[1];\n let cursor = 2;\n\n const id = raw.subarray(cursor, cursor + idLength).toString('utf-8');\n cursor += idLength;\n\n const iv = raw.subarray(cursor, cursor + DEFAULT_LENGTH);\n cursor += DEFAULT_LENGTH;\n\n const key = this.resolveDecryptKey({ secret, id, kdfSalt, kdfIterations });\n const decipher = C.createDecipheriv(this.algorithm, key, iv);\n\n switch (this.algorithm) {\n case 'aes-256-cbc': {\n break;\n }\n case 'aes-256-gcm': {\n const authTag = raw.subarray(cursor, cursor + DEFAULT_LENGTH);\n cursor += DEFAULT_LENGTH;\n (decipher as C.DecipherGCM).setAuthTag(authTag);\n break;\n }\n }\n\n const cipherText = raw.subarray(cursor);\n return Buffer.concat([decipher.update(cipherText), decipher.final()]).toString(\n outputEncoding,\n );\n } catch (error) {\n if (doThrow) {\n throw error;\n }\n\n return message;\n }\n }\n\n decryptFile(opts: { absolutePath: string; secret: TAESSecret }) {\n const { absolutePath, secret } = opts;\n\n if (!absolutePath || ObjectUtility.isEmpty({ value: absolutePath })) {\n return '';\n }\n\n const buffer = fs.readFileSync(absolutePath);\n const fileContent = buffer?.toString('utf-8');\n const decrypted = this.decrypt({ message: fileContent, secret });\n return decrypted;\n }\n}\n"]}
@@ -1,7 +1,7 @@
1
1
  import C from 'node:crypto';
2
2
  import { BaseHelper } from '../../base.js';
3
3
  import { getError } from '../../error/index.js';
4
- import { int } from '../../../utilities/index.js';
4
+ import { ParseUtility } from '../../../utilities/index.js';
5
5
  import { DEFAULT_CIPHER_BITS, DEFAULT_KDF_DIGEST, DEFAULT_KDF_ITERATIONS, DEFAULT_KDF_SALT, MINIMUM_KDF_SALT_BYTES, } from '../common/index.js';
6
6
  const DERIVED_KEY_CACHE = new Map();
7
7
  export class AbstractCryptoAlgorithm extends BaseHelper {
@@ -51,8 +51,8 @@ export class BaseCryptoAlgorithm extends AbstractCryptoAlgorithm {
51
51
  }
52
52
  }
53
53
  getAlgorithmKeySize() {
54
- const b = int(this.algorithm?.split('-')?.[1] ?? DEFAULT_CIPHER_BITS);
55
- return int(b / 8);
54
+ const b = ParseUtility.toInt({ input: this.algorithm?.split('-')?.[1] ?? DEFAULT_CIPHER_BITS });
55
+ return ParseUtility.toInt({ input: b / 8 });
56
56
  }
57
57
  }
58
58
  //# sourceMappingURL=base.algorithm.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"base.algorithm.js","sourceRoot":"","sources":["../../../../../src/modules/crypto/algorithms/base.algorithm.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,aAAa,CAAC;AAC5B,OAAO,EAAE,UAAU,E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U,GAAG,aAAa,IAAI,sBAAsB,CAAC;QAE3D,MAAM,QAAQ,GAAG,GAAG,kBAAkB,IAAI,UAAU,IAAI,MAAM,IAAI,IAAI,IAAI,MAAM,EAAE,CAAC;QACnF,MAAM,MAAM,GAAG,iBAAiB,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC/C,IAAI,MAAM,EAAE,CAAC;YACX,OAAO,MAAM,CAAC;QAChB,CAAC;QAED,MAAM,GAAG,GAAG,CAAC,CAAC,UAAU,CAAC,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,kBAAkB,CAAC,CAAC;QAC/E,iBAAiB,CAAC,GAAG,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;QACrC,OAAO,GAAG,CAAC;IACb,CAAC;IAED,uJAAuJ;IAC/I,eAAe,CAAC,IAAyB;QAC/C,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;QACzB,MAAM,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAEvD,IAAI,UAAU,GAAG,sBAAsB,EAAE,CAAC;YACxC,MAAM,QAAQ,CAAC;gBACb,OAAO,EAAE,mEAAmE,sBAAsB,eAAe,UAAU,EAAE;aAC9H,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED,mBAAmB;QACjB,MAAM,CAAC,GAAG,GAAG,CAAC,IAAI,CAAC,SAAS,EAAE,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,mBAAmB,CAAC,CAAC;QACtE,OAAO,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IACpB,CAAC;CACF","sourcesContent":["import C from 'node:crypto';\nimport { BaseHelper } from '@/modules/base';\nimport { getError } from '@/modules/error';\nimport { int } from '@/utilities';\nimport {\n DEFAULT_CIPHER_BITS,\n DEFAULT_KDF_DIGEST,\n DEFAULT_KDF_ITERATIONS,\n DEFAULT_KDF_SALT,\n type ICryptoAlgorithm,\n MINIMUM_KDF_SALT_BYTES,\n} from '../common';\n\nconst DERIVED_KEY_CACHE = new Map<string, Buffer>();\n\nexport abstract class AbstractCryptoAlgorithm<\n AlgorithmType extends string,\n EncryptInputType = unknown,\n DecryptInputType = unknown,\n SecretKeyType = unknown,\n EncryptReturnType = unknown,\n DecryptReturnType = unknown,\n ExtraOptions = unknown,\n>\n extends BaseHelper\n implements\n ICryptoAlgorithm<\n AlgorithmType,\n EncryptInputType,\n DecryptInputType,\n SecretKeyType,\n EncryptReturnType,\n DecryptReturnType,\n ExtraOptions\n >\n{\n algorithm: AlgorithmType;\n\n abstract encrypt(opts: {\n message: EncryptInputType;\n secret: SecretKeyType;\n opts?: ExtraOptions;\n }): EncryptReturnType;\n\n abstract decrypt(opts: {\n message: DecryptInputType;\n secret: SecretKeyType;\n opts?: ExtraOptions;\n }): DecryptReturnType;\n}\n\nexport abstract class BaseCryptoAlgorithm<\n AlgorithmType extends string,\n EncryptInputType = unknown,\n DecryptInputType = unknown,\n SecretKeyType = unknown,\n EncryptReturnType = unknown,\n DecryptReturnType = unknown,\n ExtraOptions = unknown,\n> extends AbstractCryptoAlgorithm<\n AlgorithmType,\n EncryptInputType,\n DecryptInputType,\n SecretKeyType,\n EncryptReturnType,\n DecryptReturnType,\n ExtraOptions\n> {\n constructor(opts: { scope: string; algorithm: AlgorithmType }) {\n super({\n scope: opts.scope ?? opts.algorithm ?? BaseCryptoAlgorithm.name,\n identifier: opts.algorithm,\n });\n this.validateAlgorithmName({ algorithm: opts.algorithm });\n\n this.algorithm = opts.algorithm;\n }\n\n validateAlgorithmName(opts: { algorithm: AlgorithmType }) {\n const { algorithm } = opts;\n\n if (!algorithm) {\n throw getError({\n message: `[validateAlgorithmName] Invalid algorithm name | algorithm: ${algorithm}`,\n });\n }\n }\n\n /** Omit `kdfSalt`/`kdfIterations` for the shipped default (byte-identical to every prior release). Supplying either requires supplying the same value again on decrypt. */\n normalizeSecretKey(opts: {\n secret: string;\n length: number;\n kdfSalt?: string;\n kdfIterations?: number;\n }): Buffer {\n const { secret, length, kdfSalt, kdfIterations } = opts;\n\n if (kdfSalt !== undefined) {\n this.validateKdfSalt({ kdfSalt });\n }\n\n const salt = kdfSalt ?? DEFAULT_KDF_SALT;\n const iterations = kdfIterations ?? DEFAULT_KDF_ITERATIONS;\n\n const cacheKey = `${DEFAULT_KDF_DIGEST}:${iterations}:${length}:${salt}:${secret}`;\n const cached = DERIVED_KEY_CACHE.get(cacheKey);\n if (cached) {\n return cached;\n }\n\n const key = C.pbkdf2Sync(secret, salt, iterations, length, DEFAULT_KDF_DIGEST);\n DERIVED_KEY_CACHE.set(cacheKey, key);\n return key;\n }\n\n /** Rejects a `kdfSalt` short enough to look configured while giving up most of the protection a salt exists for (NIST SP 800-132: 128-bit minimum). */\n private validateKdfSalt(opts: { kdfSalt: string }): void {\n const { kdfSalt } = opts;\n const byteLength = Buffer.byteLength(kdfSalt, 'utf-8');\n\n if (byteLength < MINIMUM_KDF_SALT_BYTES) {\n throw getError({\n message: `[BaseCryptoAlgorithm][validateKdfSalt] kdfSalt must be at least ${MINIMUM_KDF_SALT_BYTES} bytes, got ${byteLength}`,\n });\n }\n }\n\n getAlgorithmKeySize() {\n const b = int(this.algorithm?.split('-')?.[1] ?? DEFAULT_CIPHER_BITS);\n return int(b / 8);\n }\n}\n"]}
1
+ {"version":3,"file":"base.algorithm.js","sourceRoot":"","sources":["../../../../../src/modules/crypto/algorithms/base.algorithm.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,aAAa,CAAC;AAC5B,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EACL,mBAAmB,EACnB,kBAAkB,EAClB,sBAAsB,EACtB,gBAAgB,EAEhB,sBAAsB,GACvB,MAAM,WAAW,CAAC;AAEn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,OAAO,MAAM,CAAC;QAChB,CAAC;QAED,MAAM,GAAG,GAAG,CAAC,CAAC,UAAU,CAAC,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,kBAAkB,CAAC,CAAC;QAC/E,iBAAiB,CAAC,GAAG,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;QACrC,OAAO,GAAG,CAAC;IACb,CAAC;IAED,uJAAuJ;IAC/I,eAAe,CAAC,IAAyB;QAC/C,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;QACzB,MAAM,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAEvD,IAAI,UAAU,GAAG,sBAAsB,EAAE,CAAC;YACxC,MAAM,QAAQ,CAAC;gBACb,OAAO,EAAE,mEAAmE,sBAAsB,eAAe,UAAU,EAAE;aAC9H,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED,mBAAmB;QACjB,MAAM,CAAC,GAAG,YAAY,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,SAAS,EAAE,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,mBAAmB,EAAE,CAAC,CAAC;QAChG,OAAO,YAAY,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAC9C,CAAC;CACF","sourcesContent":["import C from 'node:crypto';\nimport { BaseHelper } from '@/modules/base';\nimport { getError } from '@/modules/error';\nimport { ParseUtility } from '@/utilities';\nimport {\n DEFAULT_CIPHER_BITS,\n DEFAULT_KDF_DIGEST,\n DEFAULT_KDF_ITERATIONS,\n DEFAULT_KDF_SALT,\n type ICryptoAlgorithm,\n MINIMUM_KDF_SALT_BYTES,\n} from '../common';\n\nconst DERIVED_KEY_CACHE = new Map<string, Buffer>();\n\nexport abstract class AbstractCryptoAlgorithm<\n AlgorithmType extends string,\n EncryptInputType = unknown,\n DecryptInputType = unknown,\n SecretKeyType = unknown,\n EncryptReturnType = unknown,\n DecryptReturnType = unknown,\n ExtraOptions = unknown,\n>\n extends BaseHelper\n implements\n ICryptoAlgorithm<\n AlgorithmType,\n EncryptInputType,\n DecryptInputType,\n SecretKeyType,\n EncryptReturnType,\n DecryptReturnType,\n ExtraOptions\n >\n{\n algorithm: AlgorithmType;\n\n abstract encrypt(opts: {\n message: EncryptInputType;\n secret: SecretKeyType;\n opts?: ExtraOptions;\n }): EncryptReturnType;\n\n abstract decrypt(opts: {\n message: DecryptInputType;\n secret: SecretKeyType;\n opts?: ExtraOptions;\n }): DecryptReturnType;\n}\n\nexport abstract class BaseCryptoAlgorithm<\n AlgorithmType extends string,\n EncryptInputType = unknown,\n DecryptInputType = unknown,\n SecretKeyType = unknown,\n EncryptReturnType = unknown,\n DecryptReturnType = unknown,\n ExtraOptions = unknown,\n> extends AbstractCryptoAlgorithm<\n AlgorithmType,\n EncryptInputType,\n DecryptInputType,\n SecretKeyType,\n EncryptReturnType,\n DecryptReturnType,\n ExtraOptions\n> {\n constructor(opts: { scope: string; algorithm: AlgorithmType }) {\n super({\n scope: opts.scope ?? opts.algorithm ?? BaseCryptoAlgorithm.name,\n identifier: opts.algorithm,\n });\n this.validateAlgorithmName({ algorithm: opts.algorithm });\n\n this.algorithm = opts.algorithm;\n }\n\n validateAlgorithmName(opts: { algorithm: AlgorithmType }) {\n const { algorithm } = opts;\n\n if (!algorithm) {\n throw getError({\n message: `[validateAlgorithmName] Invalid algorithm name | algorithm: ${algorithm}`,\n });\n }\n }\n\n /** Omit `kdfSalt`/`kdfIterations` for the shipped default (byte-identical to every prior release). Supplying either requires supplying the same value again on decrypt. */\n normalizeSecretKey(opts: {\n secret: string;\n length: number;\n kdfSalt?: string;\n kdfIterations?: number;\n }): Buffer {\n const { secret, length, kdfSalt, kdfIterations } = opts;\n\n if (kdfSalt !== undefined) {\n this.validateKdfSalt({ kdfSalt });\n }\n\n const salt = kdfSalt ?? DEFAULT_KDF_SALT;\n const iterations = kdfIterations ?? DEFAULT_KDF_ITERATIONS;\n\n const cacheKey = `${DEFAULT_KDF_DIGEST}:${iterations}:${length}:${salt}:${secret}`;\n const cached = DERIVED_KEY_CACHE.get(cacheKey);\n if (cached) {\n return cached;\n }\n\n const key = C.pbkdf2Sync(secret, salt, iterations, length, DEFAULT_KDF_DIGEST);\n DERIVED_KEY_CACHE.set(cacheKey, key);\n return key;\n }\n\n /** Rejects a `kdfSalt` short enough to look configured while giving up most of the protection a salt exists for (NIST SP 800-132: 128-bit minimum). */\n private validateKdfSalt(opts: { kdfSalt: string }): void {\n const { kdfSalt } = opts;\n const byteLength = Buffer.byteLength(kdfSalt, 'utf-8');\n\n if (byteLength < MINIMUM_KDF_SALT_BYTES) {\n throw getError({\n message: `[BaseCryptoAlgorithm][validateKdfSalt] kdfSalt must be at least ${MINIMUM_KDF_SALT_BYTES} bytes, got ${byteLength}`,\n });\n }\n }\n\n getAlgorithmKeySize() {\n const b = ParseUtility.toInt({ input: this.algorithm?.split('-')?.[1] ?? DEFAULT_CIPHER_BITS });\n return ParseUtility.toInt({ input: b / 8 });\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"app-env.d.ts","sourceRoot":"","sources":["../../../../src/modules/env/app-env.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,EAAE,KAAK,uBAAuB,EAAE,MAAM,UAAU,CAAC;AAExD,sPAAsP;AACtP,qBAAa,WAAY,SAAQ,gBAAgB;IAC/C,gNAAgN;IAChN,MAAM,KAAK,OAAO,IAAI,MAAM,GAAG,SAAS,CAGvC;IAED,MAAM,KAAK,OAAO,IAAI,MAAM,CAE3B;IAED,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE;CAGjC;AAED,qBAAa,sBAAuB,SAAQ,UA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AE,IAAI,EAAE,MAAM,CAAA;KAAE;CAGjC;AAED,qBAAa,sBAAuB,SAAQ,UAAW,YAAW,uBAAuB;IACvF,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,SAAS,CAA4C;gBAEjD,IAAI,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC,CAAA;KAAE;IAcvF;;;;;;;;;;OAUG;IACH,GAAG,CAAC,UAAU,EAAE,mBAAmB,GAAG,OAAO,EAC3C,GAAG,EAAE,MAAM,EACX,IAAI,CAAC,EAAE;QACL,YAAY,CAAC,EAAE,UAAU,CAAC;QAC1B,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,mBAAmB,KAAK,UAAU,CAAC;KACxD,GACA,UAAU;IAcb,GAAG,CAAC,SAAS,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS;IAI5C,KAAK,CAAC,IAAI,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;KAAE;IAO5C,aAAa;IAIb,IAAI;CAGL;AAqBD,eAAO,MAAM,sBAAsB,wBAAkC,CAAC;AAEtE,eAAO,MAAM,OAAO,wBAAyB,CAAC;AAC9C,eAAO,MAAM,IAAI,wBAAyB,CAAC"}
@@ -1,4 +1,4 @@
1
- import { blankToUndefined } from '../../utilities/parse.utility.js';
1
+ import { ParseUtility } from '../../utilities/parse.utility.js';
2
2
  import { BaseHelper } from '../base.js';
3
3
  import { EnvironmentNames } from './names.js';
4
4
  /** Adds the `NODE_ENV` reads to {@link EnvironmentNames}. Every name and set is inherited, so `Environment.PRODUCTION`, `Environment.COMMON_ENVS` and `Environment.DEVELOPMENT_ENVS` keep resolving here; only these two members need a `process`. */
@@ -72,7 +72,7 @@ const resolveApplicationEnvironment = () => {
72
72
  return shared;
73
73
  }
74
74
  const created = new ApplicationEnvironment({
75
- prefix: blankToUndefined(process.env.APPLICATION_ENV_PREFIX) ?? 'APP_ENV',
75
+ prefix: ParseUtility.blankToUndefined({ input: process.env.APPLICATION_ENV_PREFIX }) ?? 'APP_ENV',
76
76
  envs: process.env,
77
77
  });
78
78
  Reflect.set(globalThis, INSTANCE_SLOT, created);
@@ -1 +1 @@
1
- {"version":3,"file":"app-env.js","sourceRoot":"","sources":["../../../../src/modules/env/app-env.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAG3C,sPAAsP;AACtP,MAAM,OAAO,WAAY,SAAQ,gBAAgB;IAC/C,gNAAgN;IAChN,MAAM,KAAK,OAAO;QAChB,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC;QACjC,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,MAAM,KAAK,OAAO;QAChB,OAAO,WAAW,CAAC,OAAO,IAAI,WAAW,CAAC,WAAW,CAAC;IACxD,CAAC;IAED,MAAM,CAAC,EAAE,CAAC,IAAsB;QAC9B,OAAO,IAAI,CAAC,OAAO,KAAK,IAAI,CAAC,IAAI,CAAC;IACpC,CAAC;CACF;AAED,MAAM,OAAO,sBAAuB,SAAQ,UAAU;IAIpD,YAAY,IAA2E;QACrF,KAAK,CAAC,EAAE,KAAK,EAAE,sBAAsB,CAAC,IAAI,EAAE,CAAC,CAAC;QAHxC,cAAS,GAAwB,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAK3D,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QAE1B,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;YAC5B,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAA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C;IAED,IAAI;QACF,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACrC,CAAC;CACF;AAED,iNAAiN;AACjN,MAAM,aAAa,GAAG,MAAM,CAAC,GAAG,CAAC,+BAA+B,CAAC,CAAC;AAElE,MAAM,6BAA6B,GAAG,GAA2B,EAAE;IACjE,MAAM,MAAM,GAAuC,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,aAAa,CAAC,CAAC;IAC1F,IAAI,MAAM,EAAE,CAAC;QACX,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,MAAM,OAAO,GAAG,IAAI,sBAAsB,CAAC;QACzC,MAAM,EAAE,gBAAgB,CAAC,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC,IAAI,SAAS;QACzE,IAAI,EAAE,OAAO,CAAC,GAAG;KAClB,CAAC,CAAC;IACH,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,aAAa,EAAE,OAAO,CAAC,CAAC;IAEhD,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,sBAAsB,GAAG,6BAA6B,EAAE,CAAC;AAEtE,MAAM,CAAC,MAAM,OAAO,GAAG,sBAAsB,CAAC;AAC9C,MAAM,CAAC,MAAM,IAAI,GAAG,sBAAsB,CAAC","sourcesContent":["import { blankToUndefined } from '@/utilities/parse.utility';\nimport { BaseHelper } from '@/modules/base';\nimport { EnvironmentNames } from './names';\nimport { type IApplicationEnvironment } from './common';\n\n/** Adds the `NODE_ENV` reads to {@link EnvironmentNames}. Every name and set is inherited, so `Environment.PRODUCTION`, `Environment.COMMON_ENVS` and `Environment.DEVELOPMENT_ENVS` keep resolving here; only these two members need a `process`. */\nexport class Environment extends EnvironmentNames {\n /** `NODE_ENV` exactly as the host has it, `undefined` when unset. Destructured on purpose: `bun build` rewrites `process.env.NODE_ENV` to a literal at build time, a destructured read stays a runtime read. */\n static get ambient(): string | undefined {\n const { NODE_ENV } = process.env;\n return NODE_ENV;\n }\n\n static get current(): string {\n return Environment.ambient ?? Environment.DEVELOPMENT;\n }\n\n static is(opts: { name: string }) {\n return this.current === opts.name;\n }\n}\n\nexport class ApplicationEnvironment extends BaseHelper implements IApplicationEnvironment {\n private prefix: string;\n private arguments: Record<string, any> = Object.create(null);\n\n constructor(opts: { prefix: string; envs: Record<string, string | number | undefined> }) {\n super({ scope: ApplicationEnvironment.name });\n\n this.prefix = opts.prefix;\n\n for (const key in opts.envs) {\n if (!key.startsWith(this.prefix)) {\n continue;\n }\n\n this.arguments[key] = opts.envs[key];\n }\n }\n\n /**\n * Reads one name. A line that is present but empty - `KEY=`, or padded to `KEY= ` by a hand\n * edit - is a pipeline that forgot to export the value, not a value: it is normalised to\n * `undefined` so `defaultValue` applies, and `transform` is handed that `undefined` rather than\n * the empty string.\n *\n * The normalisation runs ONLY when the caller supplied a `defaultValue`, because that call site\n * has already declared what it wants when the name carries nothing. A caller without one still\n * receives `''` unchanged, so no existing read changes shape. `'0'` and `'false'` are values and\n * are never normalised.\n */\n get<ReturnType, BeforeTransformType = unknown>(\n key: string,\n opts?: {\n defaultValue?: ReturnType;\n transform?: (value: BeforeTransformType) => ReturnType;\n },\n ): ReturnType {\n const raw = this.arguments[key];\n\n const isBlank = raw === undefined || raw === null || (typeof raw === 'string' && !raw.trim());\n const rs = opts?.defaultValue !== undefined && isBlank ? undefined : raw;\n\n if (!opts?.transform) {\n return (rs ?? opts?.defaultValue) as ReturnType;\n }\n\n const transformed = opts.transform(rs);\n return (transformed ?? opts?.defaultValue) as ReturnType;\n }\n\n set<ValueType>(key: string, value: ValueType) {\n this.arguments[key] = value;\n }\n\n merge(opts: { envs: Record<string, string> }) {\n const envsEntries = Object.entries(opts.envs);\n for (const [key, value] of envsEntries) {\n this.arguments[key] = value;\n }\n }\n\n isDevelopment() {\n return Environment.ambient === 'development';\n }\n\n keys() {\n return Object.keys(this.arguments);\n }\n}\n\n/** A process can carry two copies of this module - an application's ESM import beside a CommonJS require. The instance lives in this globalThis slot so a `set()` through one copy is read through the other. */\nconst INSTANCE_SLOT = Symbol.for('ignis:application-environment');\n\nconst resolveApplicationEnvironment = (): ApplicationEnvironment => {\n const shared: ApplicationEnvironment | undefined = Reflect.get(globalThis, INSTANCE_SLOT);\n if (shared) {\n return shared;\n }\n\n const created = new ApplicationEnvironment({\n prefix: blankToUndefined(process.env.APPLICATION_ENV_PREFIX) ?? 'APP_ENV',\n envs: process.env,\n });\n Reflect.set(globalThis, INSTANCE_SLOT, created);\n\n return created;\n};\n\nexport const applicationEnvironment = resolveApplicationEnvironment();\n\nexport const AppEnvs = applicationEnvironment;\nexport const Envs = applicationEnvironment;\n"]}
1
+ {"version":3,"file":"app-env.js","sourceRoot":"","sources":["../../../../src/modules/env/app-env.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAG3C,sPAAsP;AACtP,MAAM,OAAO,WAAY,SAAQ,gBAAgB;IAC/C,gNAAgN;IAChN,MAAM,KAAK,OAAO;QAChB,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC;QACjC,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,MAAM,KAAK,OAAO;QAChB,OAAO,WAAW,CAAC,OAAO,IAAI,WAAW,CAAC,WAAW,CAAC;IACxD,CAAC;IAED,MAAM,CAAC,EAAE,CAAC,IAAsB;QAC9B,OAAO,IAAI,CAAC,OAAO,KAAK,IAAI,CAAC,IAAI,CAAC;IACpC,CAAC;CACF;AAED,MAAM,OAAO,sBAAuB,SAAQ,UAAU;IAIpD,YAAY,IAA2E;QACrF,KAAK,CAAC,EAAE,KAAK,EAAE,sBAAsB,CAAC,IAAI,EAAE,CAAC,CAAC;QAHxC,cAAS,GAAwB,MAAM,CAAC,MAAM,CAAC,IAA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,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,WAAW,EAAE,CAAC;YACvC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;QAC9B,CAAC;IACH,CAAC;IAED,aAAa;QACX,OAAO,WAAW,CAAC,OAAO,KAAK,aAAa,CAAC;IAC/C,CAAC;IAED,IAAI;QACF,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACrC,CAAC;CACF;AAED,iNAAiN;AACjN,MAAM,aAAa,GAAG,MAAM,CAAC,GAAG,CAAC,+BAA+B,CAAC,CAAC;AAElE,MAAM,6BAA6B,GAAG,GAA2B,EAAE;IACjE,MAAM,MAAM,GAAuC,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,aAAa,CAAC,CAAC;IAC1F,IAAI,MAAM,EAAE,CAAC;QACX,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,MAAM,OAAO,GAAG,IAAI,sBAAsB,CAAC;QACzC,MAAM,EACJ,YAAY,CAAC,gBAAgB,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,sBAAsB,EAAE,CAAC,IAAI,SAAS;QAC3F,IAAI,EAAE,OAAO,CAAC,GAAG;KAClB,CAAC,CAAC;IACH,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,aAAa,EAAE,OAAO,CAAC,CAAC;IAEhD,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,sBAAsB,GAAG,6BAA6B,EAAE,CAAC;AAEtE,MAAM,CAAC,MAAM,OAAO,GAAG,sBAAsB,CAAC;AAC9C,MAAM,CAAC,MAAM,IAAI,GAAG,sBAAsB,CAAC","sourcesContent":["import { ParseUtility } from '@/utilities/parse.utility';\nimport { BaseHelper } from '@/modules/base';\nimport { EnvironmentNames } from './names';\nimport { type IApplicationEnvironment } from './common';\n\n/** Adds the `NODE_ENV` reads to {@link EnvironmentNames}. Every name and set is inherited, so `Environment.PRODUCTION`, `Environment.COMMON_ENVS` and `Environment.DEVELOPMENT_ENVS` keep resolving here; only these two members need a `process`. */\nexport class Environment extends EnvironmentNames {\n /** `NODE_ENV` exactly as the host has it, `undefined` when unset. Destructured on purpose: `bun build` rewrites `process.env.NODE_ENV` to a literal at build time, a destructured read stays a runtime read. */\n static get ambient(): string | undefined {\n const { NODE_ENV } = process.env;\n return NODE_ENV;\n }\n\n static get current(): string {\n return Environment.ambient ?? Environment.DEVELOPMENT;\n }\n\n static is(opts: { name: string }) {\n return this.current === opts.name;\n }\n}\n\nexport class ApplicationEnvironment extends BaseHelper implements IApplicationEnvironment {\n private prefix: string;\n private arguments: Record<string, any> = Object.create(null);\n\n constructor(opts: { prefix: string; envs: Record<string, string | number | undefined> }) {\n super({ scope: ApplicationEnvironment.name });\n\n this.prefix = opts.prefix;\n\n for (const key in opts.envs) {\n if (!key.startsWith(this.prefix)) {\n continue;\n }\n\n this.arguments[key] = opts.envs[key];\n }\n }\n\n /**\n * Reads one name. A line that is present but empty - `KEY=`, or padded to `KEY= ` by a hand\n * edit - is a pipeline that forgot to export the value, not a value: it is normalised to\n * `undefined` so `defaultValue` applies, and `transform` is handed that `undefined` rather than\n * the empty string.\n *\n * The normalisation runs ONLY when the caller supplied a `defaultValue`, because that call site\n * has already declared what it wants when the name carries nothing. A caller without one still\n * receives `''` unchanged, so no existing read changes shape. `'0'` and `'false'` are values and\n * are never normalised.\n */\n get<ReturnType, BeforeTransformType = unknown>(\n key: string,\n opts?: {\n defaultValue?: ReturnType;\n transform?: (value: BeforeTransformType) => ReturnType;\n },\n ): ReturnType {\n const raw = this.arguments[key];\n\n const isBlank = raw === undefined || raw === null || (typeof raw === 'string' && !raw.trim());\n const rs = opts?.defaultValue !== undefined && isBlank ? undefined : raw;\n\n if (!opts?.transform) {\n return (rs ?? opts?.defaultValue) as ReturnType;\n }\n\n const transformed = opts.transform(rs);\n return (transformed ?? opts?.defaultValue) as ReturnType;\n }\n\n set<ValueType>(key: string, value: ValueType) {\n this.arguments[key] = value;\n }\n\n merge(opts: { envs: Record<string, string> }) {\n const envsEntries = Object.entries(opts.envs);\n for (const [key, value] of envsEntries) {\n this.arguments[key] = value;\n }\n }\n\n isDevelopment() {\n return Environment.ambient === 'development';\n }\n\n keys() {\n return Object.keys(this.arguments);\n }\n}\n\n/** A process can carry two copies of this module - an application's ESM import beside a CommonJS require. The instance lives in this globalThis slot so a `set()` through one copy is read through the other. */\nconst INSTANCE_SLOT = Symbol.for('ignis:application-environment');\n\nconst resolveApplicationEnvironment = (): ApplicationEnvironment => {\n const shared: ApplicationEnvironment | undefined = Reflect.get(globalThis, INSTANCE_SLOT);\n if (shared) {\n return shared;\n }\n\n const created = new ApplicationEnvironment({\n prefix:\n ParseUtility.blankToUndefined({ input: process.env.APPLICATION_ENV_PREFIX }) ?? 'APP_ENV',\n envs: process.env,\n });\n Reflect.set(globalThis, INSTANCE_SLOT, created);\n\n return created;\n};\n\nexport const applicationEnvironment = resolveApplicationEnvironment();\n\nexport const AppEnvs = applicationEnvironment;\nexport const Envs = applicationEnvironment;\n"]}
@@ -8,25 +8,27 @@ export declare class LoggerFormats {
8
8
  }
9
9
  export type TLoggerFormat = TConstValue<typeof LoggerFormats>;
10
10
  export declare const SHOULD_LOG_DEBUG: boolean;
11
- /** The logger's own level, below which a line never reaches ANY transport. Defaults to `debug` - level gating belongs to the wrapper and each transport, and a stricter default here would silently drop lines the wrapper already let through. */
12
- export declare const resolveLoggerLevel: (opts: {
13
- configured?: string;
14
- }) => TLogLevel;
15
- /**
16
- * Whether log lines may carry ANSI color, resolved at CALL time. First match wins:
17
- *
18
- * 1. `APP_ENV_LOGGER_COLOR` - an explicit yes or no from the operator.
19
- * 2. `NO_COLOR`, set to anything non-empty - the no-color.org convention.
20
- * 3. `NODE_ENV` outside {@link Environment.DEVELOPMENT_ENVS} - production, staging, uat and any
21
- * unrecognized name. Fail-closed, the same boundary the error sanitizer draws: colors are a
22
- * terminal affordance, and in a deployed environment the same bytes land in a file or an
23
- * aggregator as escape noise every grep then has to strip.
24
- *
25
- * `undefined` means the framework has no opinion, so a provider that detects a terminal itself
26
- * keeps deciding - which is why the pino path forwards nothing in that case.
27
- */
28
- export declare const resolveLoggerColorize: (opts?: {
29
- configured?: string;
30
- environment?: string;
31
- }) => boolean | undefined;
11
+ export declare class LoggerConfigUtility {
12
+ /** The logger's own level, below which a line never reaches ANY transport. Defaults to `debug` - level gating belongs to the wrapper and each transport, and a stricter default here would silently drop lines the wrapper already let through. */
13
+ static resolveLevel(opts: {
14
+ configured?: string;
15
+ }): TLogLevel;
16
+ /**
17
+ * Whether log lines may carry ANSI color, resolved at CALL time. First match wins:
18
+ *
19
+ * 1. `APP_ENV_LOGGER_COLOR` - an explicit yes or no from the operator.
20
+ * 2. `NO_COLOR`, set to anything non-empty - the no-color.org convention.
21
+ * 3. `NODE_ENV` outside {@link Environment.DEVELOPMENT_ENVS} - production, staging, uat and any
22
+ * unrecognized name. Fail-closed, the same boundary the error sanitizer draws: colors are a
23
+ * terminal affordance, and in a deployed environment the same bytes land in a file or an
24
+ * aggregator as escape noise every grep then has to strip.
25
+ *
26
+ * `undefined` means the framework has no opinion, so a provider that detects a terminal itself
27
+ * keeps deciding - which is why the pino path forwards nothing in that case.
28
+ */
29
+ static resolveColorize(opts?: {
30
+ configured?: string;
31
+ environment?: string;
32
+ }): boolean | undefined;
33
+ }
32
34
  //# sourceMappingURL=constants.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../../../src/modules/logger/common/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAGlD,OAAO,EAAa,KAAK,SAAS,EAAE,MAAM,SAAS,CAAC;AAGpD,qBAAa,aAAa;IACxB,MAAM,CAAC,QAAQ,CAAC,IAAI,UAAU;IAC9B,MAAM,CAAC,QAAQ,CAAC,IAAI,UAAU;IAE9B,MAAM,CAAC,QAAQ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I,CAAC,EAAE;QAC5B,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,WAAW,CAAC,EAAE,MAAM,CAAC;KACtB,GAAG,OAAO,GAAG,SAAS;CAkBxB"}
@@ -1,5 +1,5 @@
1
1
  import { Environment } from '../../env/index.js';
2
- import { toBoolean } from '../../../utilities/parse.utility.js';
2
+ import { ParseUtility } from '../../../utilities/parse.utility.js';
3
3
  import { LogLevels } from './types.js';
4
4
  // -------------------------------------------------------------
5
5
  export class LoggerFormats {
@@ -15,47 +15,50 @@ const extraLogEnvs = (process.env.APP_ENV_EXTRA_LOG_ENVS ?? '').split(',').map((
15
15
  const LOG_ENVIRONMENTS = new Set([...Array.from(Environment.COMMON_ENVS), ...extraLogEnvs]);
16
16
  /** debug() gate, computed ONCE at module load: DEBUG truthy and NODE_ENV unset or allowlisted. Shared across every logger implementation - runtime env changes need a restart. */
17
17
  const { DEBUG } = process.env;
18
- export const SHOULD_LOG_DEBUG = toBoolean(DEBUG) && (!Environment.ambient || LOG_ENVIRONMENTS.has(Environment.ambient));
19
- /** The logger's own level, below which a line never reaches ANY transport. Defaults to `debug` - level gating belongs to the wrapper and each transport, and a stricter default here would silently drop lines the wrapper already let through. */
20
- export const resolveLoggerLevel = (opts) => {
21
- const { configured } = opts;
22
- if (!configured || configured.trim() === '') {
23
- return LogLevels.DEBUG;
18
+ export const SHOULD_LOG_DEBUG = ParseUtility.toBoolean({ input: DEBUG }) &&
19
+ (!Environment.ambient || LOG_ENVIRONMENTS.has(Environment.ambient));
20
+ export class LoggerConfigUtility {
21
+ /** The logger's own level, below which a line never reaches ANY transport. Defaults to `debug` - level gating belongs to the wrapper and each transport, and a stricter default here would silently drop lines the wrapper already let through. */
22
+ static resolveLevel(opts) {
23
+ const { configured } = opts;
24
+ if (!configured || configured.trim() === '') {
25
+ return LogLevels.DEBUG;
26
+ }
27
+ const normalized = configured.trim().toLowerCase();
28
+ if (!LogLevels.isValid(normalized)) {
29
+ // console, not Logger: the logger is being built - routing this warning through it would re-enter the very pipeline that is not configured yet.
30
+ console.warn('[resolveLoggerLevel] Invalid logger level | value: %s | valids: %s | fallback: %s', configured, [...LogLevels.SCHEME_SET], LogLevels.DEBUG);
31
+ return LogLevels.DEBUG;
32
+ }
33
+ return normalized;
24
34
  }
25
- const normalized = configured.trim().toLowerCase();
26
- if (!LogLevels.isValid(normalized)) {
27
- // console, not Logger: the logger is being built - routing this warning through it would re-enter the very pipeline that is not configured yet.
28
- console.warn('[resolveLoggerLevel] Invalid logger level | value: %s | valids: %s | fallback: %s', configured, [...LogLevels.SCHEME_SET], LogLevels.DEBUG);
29
- return LogLevels.DEBUG;
35
+ /**
36
+ * Whether log lines may carry ANSI color, resolved at CALL time. First match wins:
37
+ *
38
+ * 1. `APP_ENV_LOGGER_COLOR` - an explicit yes or no from the operator.
39
+ * 2. `NO_COLOR`, set to anything non-empty - the no-color.org convention.
40
+ * 3. `NODE_ENV` outside {@link Environment.DEVELOPMENT_ENVS} - production, staging, uat and any
41
+ * unrecognized name. Fail-closed, the same boundary the error sanitizer draws: colors are a
42
+ * terminal affordance, and in a deployed environment the same bytes land in a file or an
43
+ * aggregator as escape noise every grep then has to strip.
44
+ *
45
+ * `undefined` means the framework has no opinion, so a provider that detects a terminal itself
46
+ * keeps deciding - which is why the pino path forwards nothing in that case.
47
+ */
48
+ static resolveColorize(opts) {
49
+ const configured = opts?.configured ?? process.env.APP_ENV_LOGGER_COLOR;
50
+ if (configured !== undefined && configured.trim() !== '') {
51
+ return ParseUtility.toBoolean({ input: configured.trim().toLowerCase() });
52
+ }
53
+ const noColor = process.env.NO_COLOR;
54
+ if (noColor !== undefined && noColor !== '') {
55
+ return false;
56
+ }
57
+ const environment = opts?.environment ?? Environment.current;
58
+ if (!Environment.DEVELOPMENT_ENVS.has(environment)) {
59
+ return false;
60
+ }
61
+ return undefined;
30
62
  }
31
- return normalized;
32
- };
33
- /**
34
- * Whether log lines may carry ANSI color, resolved at CALL time. First match wins:
35
- *
36
- * 1. `APP_ENV_LOGGER_COLOR` - an explicit yes or no from the operator.
37
- * 2. `NO_COLOR`, set to anything non-empty - the no-color.org convention.
38
- * 3. `NODE_ENV` outside {@link Environment.DEVELOPMENT_ENVS} - production, staging, uat and any
39
- * unrecognized name. Fail-closed, the same boundary the error sanitizer draws: colors are a
40
- * terminal affordance, and in a deployed environment the same bytes land in a file or an
41
- * aggregator as escape noise every grep then has to strip.
42
- *
43
- * `undefined` means the framework has no opinion, so a provider that detects a terminal itself
44
- * keeps deciding - which is why the pino path forwards nothing in that case.
45
- */
46
- export const resolveLoggerColorize = (opts) => {
47
- const configured = opts?.configured ?? process.env.APP_ENV_LOGGER_COLOR;
48
- if (configured !== undefined && configured.trim() !== '') {
49
- return toBoolean(configured.trim().toLowerCase());
50
- }
51
- const noColor = process.env.NO_COLOR;
52
- if (noColor !== undefined && noColor !== '') {
53
- return false;
54
- }
55
- const environment = opts?.environment ?? Environment.current;
56
- if (!Environment.DEVELOPMENT_ENVS.has(environment)) {
57
- return false;
58
- }
59
- return undefined;
60
- };
63
+ }
61
64
  //# sourceMappingURL=constants.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../../src/modules/logger/common/constants.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AACtD,OAAO,EAAE,SAAS,EAAkB,MAAM,SAAS,CAAC;AAEpD,gEAAgE;AAChE,MAAM,OAAO,aAAa;aACR,SAAI,GAAG,MAAM,CAAC;aACd,SAAI,GAAG,MAAM,CAAC;aAEd,eAAU,GAAG,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IAE7D,MAAM,CAAC,OAAO,CAAC,KAAa;QAC1B,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACpC,CAA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;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,IAGrC,EAAuB,EAAE;IACxB,MAAM,UAAU,GAAG,IAAI,EAAE,UAAU,IAAI,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC;IACxE,IAAI,UAAU,KAAK,SAAS,IAAI,UAAU,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;QACzD,OAAO,SAAS,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,CAAC;IACpD,CAAC;IAED,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC;IACrC,IAAI,OAAO,KAAK,SAAS,IAAI,OAAO,KAAK,EAAE,EAAE,CAAC;QAC5C,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,WAAW,GAAG,IAAI,EAAE,WAAW,IAAI,WAAW,CAAC,OAAO,CAAC;IAC7D,IAAI,CAAC,WAAW,CAAC,gBAAgB,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,CAAC;QACnD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC","sourcesContent":["import { type TConstValue } from '@/common/types';\nimport { Environment } from '@/modules/env';\nimport { toBoolean } from '@/utilities/parse.utility';\nimport { LogLevels, type TLogLevel } from './types';\n\n// -------------------------------------------------------------\nexport class LoggerFormats {\n static readonly JSON = 'json';\n static readonly TEXT = 'text';\n\n static readonly SCHEME_SET = new Set([this.JSON, this.TEXT]);\n\n static isValid(input: string): input is TLoggerFormat {\n return this.SCHEME_SET.has(input);\n }\n}\n\nexport type TLoggerFormat = TConstValue<typeof LoggerFormats>;\n\n// -------------------------------------------------------------\nconst extraLogEnvs = (process.env.APP_ENV_EXTRA_LOG_ENVS ?? '').split(',').map((el) => el.trim());\nconst LOG_ENVIRONMENTS = new Set([...Array.from(Environment.COMMON_ENVS), ...extraLogEnvs]);\n\n/** debug() gate, computed ONCE at module load: DEBUG truthy and NODE_ENV unset or allowlisted. Shared across every logger implementation - runtime env changes need a restart. */\nconst { DEBUG } = process.env;\nexport const SHOULD_LOG_DEBUG =\n toBoolean(DEBUG) && (!Environment.ambient || LOG_ENVIRONMENTS.has(Environment.ambient));\n\n/** The logger's own level, below which a line never reaches ANY transport. Defaults to `debug` - level gating belongs to the wrapper and each transport, and a stricter default here would silently drop lines the wrapper already let through. */\nexport const resolveLoggerLevel = (opts: { configured?: string }): TLogLevel => {\n const { configured } = opts;\n\n if (!configured || configured.trim() === '') {\n return LogLevels.DEBUG;\n }\n\n const normalized = configured.trim().toLowerCase();\n if (!LogLevels.isValid(normalized)) {\n // console, not Logger: the logger is being built - routing this warning through it would re-enter the very pipeline that is not configured yet.\n console.warn(\n '[resolveLoggerLevel] Invalid logger level | value: %s | valids: %s | fallback: %s',\n configured,\n [...LogLevels.SCHEME_SET],\n LogLevels.DEBUG,\n );\n return LogLevels.DEBUG;\n }\n\n return normalized as TLogLevel;\n};\n\n/**\n * Whether log lines may carry ANSI color, resolved at CALL time. First match wins:\n *\n * 1. `APP_ENV_LOGGER_COLOR` - an explicit yes or no from the operator.\n * 2. `NO_COLOR`, set to anything non-empty - the no-color.org convention.\n * 3. `NODE_ENV` outside {@link Environment.DEVELOPMENT_ENVS} - production, staging, uat and any\n * unrecognized name. Fail-closed, the same boundary the error sanitizer draws: colors are a\n * terminal affordance, and in a deployed environment the same bytes land in a file or an\n * aggregator as escape noise every grep then has to strip.\n *\n * `undefined` means the framework has no opinion, so a provider that detects a terminal itself\n * keeps deciding - which is why the pino path forwards nothing in that case.\n */\nexport const resolveLoggerColorize = (opts?: {\n configured?: string;\n environment?: string;\n}): boolean | undefined => {\n const configured = opts?.configured ?? process.env.APP_ENV_LOGGER_COLOR;\n if (configured !== undefined && configured.trim() !== '') {\n return toBoolean(configured.trim().toLowerCase());\n }\n\n const noColor = process.env.NO_COLOR;\n if (noColor !== undefined && noColor !== '') {\n return false;\n }\n\n const environment = opts?.environment ?? Environment.current;\n if (!Environment.DEVELOPMENT_ENVS.has(environment)) {\n return false;\n }\n\n return undefined;\n};\n"]}
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../../src/modules/logger/common/constants.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,SAAS,EAAkB,MAAM,SAAS,CAAC;AAEpD,gEAAgE;AAChE,MAAM,OAAO,aAAa;aACR,SAAI,GAAG,MAAM,CAAC;aACd,SAAI,GAAG,MAAM,CAAC;aAEd,eAAU,GAAG,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IAE7D,MAAM,CAAC,OAAO,CAAC,KAAa;QAC1B,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC;;AAKH,gEAAgE;AAChE,MAAM,YAAY,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,sBAAsB,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC;AAClG,MAAM,gBAAgB,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,WAAW,CAAC,EAAE,GAAG,YAAY,CAAC,CAAC,CAAC;AAE5F,kLAAkL;AAClL,MAAM,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC;AAC9B,MAAM,CAAC,MAAM,gBAAgB,GAC3B,YAAY,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;IACxC,CAAC,CAAC,WAAW,CAAC,OAAO,IAAI,gBAAgB,CAAC,GAAG,CAAC,WAAW,CAA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,CAAC;QAC7D,IAAI,CAAC,WAAW,CAAC,gBAAgB,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,CAAC;YACnD,OAAO,KAAK,CAAC;QACf,CAAC;QAED,OAAO,SAAS,CAAC;IACnB,CAAC;CACF","sourcesContent":["import { type TConstValue } from '@/common/types';\nimport { Environment } from '@/modules/env';\nimport { ParseUtility } from '@/utilities/parse.utility';\nimport { LogLevels, type TLogLevel } from './types';\n\n// -------------------------------------------------------------\nexport class LoggerFormats {\n static readonly JSON = 'json';\n static readonly TEXT = 'text';\n\n static readonly SCHEME_SET = new Set([this.JSON, this.TEXT]);\n\n static isValid(input: string): input is TLoggerFormat {\n return this.SCHEME_SET.has(input);\n }\n}\n\nexport type TLoggerFormat = TConstValue<typeof LoggerFormats>;\n\n// -------------------------------------------------------------\nconst extraLogEnvs = (process.env.APP_ENV_EXTRA_LOG_ENVS ?? '').split(',').map((el) => el.trim());\nconst LOG_ENVIRONMENTS = new Set([...Array.from(Environment.COMMON_ENVS), ...extraLogEnvs]);\n\n/** debug() gate, computed ONCE at module load: DEBUG truthy and NODE_ENV unset or allowlisted. Shared across every logger implementation - runtime env changes need a restart. */\nconst { DEBUG } = process.env;\nexport const SHOULD_LOG_DEBUG =\n ParseUtility.toBoolean({ input: DEBUG }) &&\n (!Environment.ambient || LOG_ENVIRONMENTS.has(Environment.ambient));\n\nexport class LoggerConfigUtility {\n /** The logger's own level, below which a line never reaches ANY transport. Defaults to `debug` - level gating belongs to the wrapper and each transport, and a stricter default here would silently drop lines the wrapper already let through. */\n static resolveLevel(opts: { configured?: string }): TLogLevel {\n const { configured } = opts;\n\n if (!configured || configured.trim() === '') {\n return LogLevels.DEBUG;\n }\n\n const normalized = configured.trim().toLowerCase();\n if (!LogLevels.isValid(normalized)) {\n // console, not Logger: the logger is being built - routing this warning through it would re-enter the very pipeline that is not configured yet.\n console.warn(\n '[resolveLoggerLevel] Invalid logger level | value: %s | valids: %s | fallback: %s',\n configured,\n [...LogLevels.SCHEME_SET],\n LogLevels.DEBUG,\n );\n return LogLevels.DEBUG;\n }\n\n return normalized as TLogLevel;\n }\n\n /**\n * Whether log lines may carry ANSI color, resolved at CALL time. First match wins:\n *\n * 1. `APP_ENV_LOGGER_COLOR` - an explicit yes or no from the operator.\n * 2. `NO_COLOR`, set to anything non-empty - the no-color.org convention.\n * 3. `NODE_ENV` outside {@link Environment.DEVELOPMENT_ENVS} - production, staging, uat and any\n * unrecognized name. Fail-closed, the same boundary the error sanitizer draws: colors are a\n * terminal affordance, and in a deployed environment the same bytes land in a file or an\n * aggregator as escape noise every grep then has to strip.\n *\n * `undefined` means the framework has no opinion, so a provider that detects a terminal itself\n * keeps deciding - which is why the pino path forwards nothing in that case.\n */\n static resolveColorize(opts?: {\n configured?: string;\n environment?: string;\n }): boolean | undefined {\n const configured = opts?.configured ?? process.env.APP_ENV_LOGGER_COLOR;\n if (configured !== undefined && configured.trim() !== '') {\n return ParseUtility.toBoolean({ input: configured.trim().toLowerCase() });\n }\n\n const noColor = process.env.NO_COLOR;\n if (noColor !== undefined && noColor !== '') {\n return false;\n }\n\n const environment = opts?.environment ?? Environment.current;\n if (!Environment.DEVELOPMENT_ENVS.has(environment)) {\n return false;\n }\n\n return undefined;\n }\n}\n"]}
@@ -14,7 +14,9 @@ export declare class LoggerFactory {
14
14
  static getLogger(scopes: string[]): ILogger;
15
15
  }
16
16
  /** Provider-following facade: always resolves through the registered provider. */
17
- export declare const ApplicationLogger: {
18
- get: (scope: string) => ILogger;
19
- };
17
+ export declare class ApplicationLogger {
18
+ static get(opts: {
19
+ scope: string;
20
+ }): ILogger;
21
+ }
20
22
  //# sourceMappingURL=factory.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../../../src/modules/logger/factory.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,OAAO,EAAE,KAAK,eAAe,EAAkB,MAAM,gBAAgB,CAAC;AAsDpF,uKAAuK;AACvK,qBAAa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94,11 @@ export class LoggerFactory {
94
94
  }
95
95
  }
96
96
  /** Provider-following facade: always resolves through the registered provider. */
97
- export const ApplicationLogger = {
98
- get: (scope) => LoggerFactory.getLogger([scope]),
99
- };
97
+ export class ApplicationLogger {
98
+ static get(opts) {
99
+ return LoggerFactory.getLogger([typeof opts === 'string' ? opts : opts.scope]);
100
+ }
101
+ }
100
102
  // Runs whenever LoggerFactory is imported as a value - which core's Container and every application entrypoint already do. This is what makes BaseHelper resolve real loggers on the server while its own import graph stays browser-pure.
101
103
  LoggerResolver.use({ resolver: (opts) => LoggerFactory.getLogger(opts.scopes) });
102
104
  //# sourceMappingURL=factory.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"factory.js","sourceRoot":"","sources":["../../../../src/modules/logger/factory.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEjD,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE5C,8PAA8P;AAC9P,MAAM,eAAgB,SAAQ,cAAc;IAG1C,YAA6B,KAAa;QACxC,KAAK,EAAE,CAAC;QADmB,UAAK,GAAL,KAAK,CAAQ;IAE1C,CAAC;IAED,OAAO,CAAC,QAAyB;QAC/B,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC5C,CAAC;IAEO,QAAQ;QACd,mEAAmE;QACnE,OAAO,CAAC,IAAI,CAAC,SAAS,KAAK,aAAa,CAAC,eAAe,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IAC9E,CAAC;IAED,KAAK,CAAC,OAAe,EAAE,GAAG,IAAe;QACvC,IAAI,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC,OAAO,EAAE,GAAG,IAAI,C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AI,CAAC,GAAG,CAAC;aACZ,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED,MAAM,CAAC,SAAS,CAAC,MAAgB;QAC/B,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC/B,IAAI,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QAEnC,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,GAAG,IAAI,eAAe,CAAC,KAAK,CAAC,CAAC;YACpC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QAChC,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;;AAGH,kFAAkF;AAClF,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,GAAG,EAAE,CAAC,KAAa,EAAW,EAAE,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,CAAC;CAClE,CAAC;AAEF,2OAA2O;AAC3O,cAAc,CAAC,GAAG,CAAC,EAAE,QAAQ,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,aAAa,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC","sourcesContent":["import { type AnyType } from '@/common/types';\nimport { getError } from '@venizia/ignis-inversion';\nimport { createRequire } from 'node:module';\nimport { AbstractLogger } from './base/abstract';\nimport { type ILogger, type ILoggerProvider, type TLogLevel } from './common/types';\nimport { LoggerResolver } from './resolver';\n\n/** Stable wrapper the factory hands out; the delegate resolves lazily (first log call or `use()`), never at construction, so no provider loads until needed. Mutual reference with LoggerFactory is by design - hence the `no-use-before-define` disables. */\nclass LoggerDelegator extends AbstractLogger {\n private _delegate?: ILogger;\n\n constructor(private readonly scope: string) {\n super();\n }\n\n repoint(provider: ILoggerProvider): void {\n this._delegate = provider.get(this.scope);\n }\n\n private delegate(): ILogger {\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n return (this._delegate ??= LoggerFactory.currentProvider().get(this.scope));\n }\n\n debug(message: string, ...args: AnyType[]) {\n this.delegate().debug(message, ...args);\n }\n\n info(message: string, ...args: AnyType[]) {\n this.delegate().info(message, ...args);\n }\n\n warn(message: string, ...args: AnyType[]) {\n this.delegate().warn(message, ...args);\n }\n\n error(message: string, ...args: AnyType[]) {\n this.delegate().error(message, ...args);\n }\n\n emerg(message: string, ...args: AnyType[]) {\n this.delegate().emerg(message, ...args);\n }\n\n log(level: TLogLevel, message: string, ...args: AnyType[]) {\n this.delegate().log(level, message, ...args);\n }\n\n for(methodName: string): ILogger {\n const childScope = this.scope !== '' ? `${this.scope}-${methodName}` : methodName;\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n return LoggerFactory.getLogger([childScope]);\n }\n}\n\n/** A bundle can carry two copies of this module - the application's ESM import and core's CJS require. The provider lives in this globalThis slot so `use()` in one copy is seen by the other. */\nconst PROVIDER_SLOT = Symbol.for('ignis:logger-provider');\n\n/** Provider-agnostic acquisition path. Exactly ONE provider is ever loaded - the one registered via `use()`, or the winston default at first unregistered log call. */\nexport class LoggerFactory {\n private static provider?: ILoggerProvider;\n private static cache = new Map<string, LoggerDelegator>();\n\n /** Register the application's provider. Re-points every wrapper issued so far. */\n static use(opts: { provider: ILoggerProvider }): void {\n this.provider = opts.provider;\n Reflect.set(globalThis, PROVIDER_SLOT, opts.provider);\n const cacheValues = this.cache.values();\n for (const wrapper of cacheValues) {\n wrapper.repoint(opts.provider);\n }\n }\n\n static currentProvider(): ILoggerProvider {\n if (!this.provider) {\n this.provider = this.sharedProvider() ?? this.loadDefaultProvider();\n Reflect.set(globalThis, PROVIDER_SLOT, this.provider);\n }\n\n return this.provider;\n }\n\n /** The provider another copy of this module registered, if any. */\n private static sharedProvider(): ILoggerProvider | undefined {\n const shared: ILoggerProvider | undefined = Reflect.get(globalThis, PROVIDER_SLOT);\n return shared;\n }\n\n // winston is an optional peer; compiled binaries must register a provider explicitly because only a class reference carries a provider into a bundle.\n private static loadDefaultProvider(): ILoggerProvider {\n try {\n return createRequire(__filename)('./winston').WinstonLogger;\n } catch (error) {\n throw getError({\n message: [\n '[LoggerFactory] No logger provider is registered and the default (winston) could not be loaded.',\n 'Either install it: `bun add winston winston-transport winston-daily-rotate-file`,',\n 'or register a provider at your entrypoint: `LoggerFactory.use({ provider })` with a class',\n \"from '@venizia/ignis-helpers/winston' or '@venizia/ignis-helpers/pino'.\",\n 'Compiled binaries (bun build --compile) MUST register explicitly.',\n `Cause: ${error instanceof Error ? error.message : String(error)}`,\n ].join(' '),\n });\n }\n }\n\n static getLogger(scopes: string[]): ILogger {\n const scope = scopes.join('-');\n let cached = this.cache.get(scope);\n\n if (!cached) {\n cached = new LoggerDelegator(scope);\n this.cache.set(scope, cached);\n }\n\n return cached;\n }\n}\n\n/** Provider-following facade: always resolves through the registered provider. */\nexport const ApplicationLogger = {\n get: (scope: string): ILogger => LoggerFactory.getLogger([scope]),\n};\n\n// Runs whenever LoggerFactory is imported as a value - which core's Container and every application entrypoint already do. This is what makes BaseHelper resolve real loggers on the server while its own import graph stays browser-pure.\nLoggerResolver.use({ resolver: (opts) => LoggerFactory.getLogger(opts.scopes) });\n"]}
1
+ {"version":3,"file":"factory.js","sourceRoot":"","sources":["../../../../src/modules/logger/factory.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEjD,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE5C,8PAA8P;AAC9P,MAAM,eAAgB,SAAQ,cAAc;IAG1C,YAA6B,KAAa;QACxC,KAAK,EAAE,CAAC;QADmB,UAAK,GAAL,KAAK,CAAQ;IAE1C,CAAC;IAED,OAAO,CAAC,QAAyB;QAC/B,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC,GAA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ignis-inversion';\nimport { createRequire } from 'node:module';\nimport { AbstractLogger } from './base/abstract';\nimport { type ILogger, type ILoggerProvider, type TLogLevel } from './common/types';\nimport { LoggerResolver } from './resolver';\n\n/** Stable wrapper the factory hands out; the delegate resolves lazily (first log call or `use()`), never at construction, so no provider loads until needed. Mutual reference with LoggerFactory is by design - hence the `no-use-before-define` disables. */\nclass LoggerDelegator extends AbstractLogger {\n private _delegate?: ILogger;\n\n constructor(private readonly scope: string) {\n super();\n }\n\n repoint(provider: ILoggerProvider): void {\n this._delegate = provider.get(this.scope);\n }\n\n private delegate(): ILogger {\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n return (this._delegate ??= LoggerFactory.currentProvider().get(this.scope));\n }\n\n debug(message: string, ...args: AnyType[]) {\n this.delegate().debug(message, ...args);\n }\n\n info(message: string, ...args: AnyType[]) {\n this.delegate().info(message, ...args);\n }\n\n warn(message: string, ...args: AnyType[]) {\n this.delegate().warn(message, ...args);\n }\n\n error(message: string, ...args: AnyType[]) {\n this.delegate().error(message, ...args);\n }\n\n emerg(message: string, ...args: AnyType[]) {\n this.delegate().emerg(message, ...args);\n }\n\n log(level: TLogLevel, message: string, ...args: AnyType[]) {\n this.delegate().log(level, message, ...args);\n }\n\n for(methodName: string): ILogger {\n const childScope = this.scope !== '' ? `${this.scope}-${methodName}` : methodName;\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n return LoggerFactory.getLogger([childScope]);\n }\n}\n\n/** A bundle can carry two copies of this module - the application's ESM import and core's CJS require. The provider lives in this globalThis slot so `use()` in one copy is seen by the other. */\nconst PROVIDER_SLOT = Symbol.for('ignis:logger-provider');\n\n/** Provider-agnostic acquisition path. Exactly ONE provider is ever loaded - the one registered via `use()`, or the winston default at first unregistered log call. */\nexport class LoggerFactory {\n private static provider?: ILoggerProvider;\n private static cache = new Map<string, LoggerDelegator>();\n\n /** Register the application's provider. Re-points every wrapper issued so far. */\n static use(opts: { provider: ILoggerProvider }): void {\n this.provider = opts.provider;\n Reflect.set(globalThis, PROVIDER_SLOT, opts.provider);\n const cacheValues = this.cache.values();\n for (const wrapper of cacheValues) {\n wrapper.repoint(opts.provider);\n }\n }\n\n static currentProvider(): ILoggerProvider {\n if (!this.provider) {\n this.provider = this.sharedProvider() ?? this.loadDefaultProvider();\n Reflect.set(globalThis, PROVIDER_SLOT, this.provider);\n }\n\n return this.provider;\n }\n\n /** The provider another copy of this module registered, if any. */\n private static sharedProvider(): ILoggerProvider | undefined {\n const shared: ILoggerProvider | undefined = Reflect.get(globalThis, PROVIDER_SLOT);\n return shared;\n }\n\n // winston is an optional peer; compiled binaries must register a provider explicitly because only a class reference carries a provider into a bundle.\n private static loadDefaultProvider(): ILoggerProvider {\n try {\n return createRequire(__filename)('./winston').WinstonLogger;\n } catch (error) {\n throw getError({\n message: [\n '[LoggerFactory] No logger provider is registered and the default (winston) could not be loaded.',\n 'Either install it: `bun add winston winston-transport winston-daily-rotate-file`,',\n 'or register a provider at your entrypoint: `LoggerFactory.use({ provider })` with a class',\n \"from '@venizia/ignis-helpers/winston' or '@venizia/ignis-helpers/pino'.\",\n 'Compiled binaries (bun build --compile) MUST register explicitly.',\n `Cause: ${error instanceof Error ? error.message : String(error)}`,\n ].join(' '),\n });\n }\n }\n\n static getLogger(scopes: string[]): ILogger {\n const scope = scopes.join('-');\n let cached = this.cache.get(scope);\n\n if (!cached) {\n cached = new LoggerDelegator(scope);\n this.cache.set(scope, cached);\n }\n\n return cached;\n }\n}\n\n/** Provider-following facade: always resolves through the registered provider. */\nexport class ApplicationLogger {\n static get(opts: { scope: string }): ILogger;\n\n static get(opts: { scope: string } | string): ILogger {\n return LoggerFactory.getLogger([typeof opts === 'string' ? opts : opts.scope]);\n }\n}\n\n// Runs whenever LoggerFactory is imported as a value - which core's Container and every application entrypoint already do. This is what makes BaseHelper resolve real loggers on the server while its own import graph stays browser-pure.\nLoggerResolver.use({ resolver: (opts) => LoggerFactory.getLogger(opts.scopes) });\n"]}
@@ -1,8 +1,12 @@
1
1
  import util from 'node:util';
2
- /** Formats like `util.format`, but `%s` inspects to configured depth instead of Node's hard-coded `depth: 0` (no inspect option overrides that), and `%j` is projected into a JSON-safe shape first. Per-placeholder only - handing `%j` the widened STRING would emit a JSON-quoted inspect dump instead of an object. */
3
- export declare const formatLogMessage: (opts: {
4
- message: string;
5
- args: Array<unknown>;
6
- inspectOptions?: util.InspectOptions;
7
- }) => string;
2
+ export declare class LogFormatUtility {
3
+ private static resolveDepth;
4
+ private static buildInspectOptions;
5
+ /** Formats like `util.format`, but `%s` inspects to configured depth instead of Node's hard-coded `depth: 0` (no inspect option overrides that), and `%j` is projected into a JSON-safe shape first. Per-placeholder only - handing `%j` the widened STRING would emit a JSON-quoted inspect dump instead of an object. */
6
+ static formatMessage(opts: {
7
+ message: string;
8
+ args: Array<unknown>;
9
+ inspectOptions?: util.InspectOptions;
10
+ }): string;
11
+ }
8
12
  //# sourceMappingURL=deep-splat.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"deep-splat.d.ts","sourceRoot":"","sources":["../../../../../src/modules/logger/formatting/deep-splat.ts"],"names":[],"mappings":"AACA,OAAO,IAAI,MAAM,WAAW,CAAC;AAoC7B,2TAA2T;AAC3T,eAAO,MAAM,gBAAgB,GAAI,MAAM;IACrC,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;IACrB,cAAc,CAAC,EAAE,IAAI,CAAC,cAAc,CAAC;CACtC,KAAG,MAoDH,CAAC"}
1
+ {"version":3,"file":"deep-splat.d.ts","sourceRoot":"","sources":["../../../../../src/modules/logger/formatting/deep-splat.ts"],"names":[],"mappings":"AACA,OAAO,IAAI,MAAM,WAAW,CAAC;AAS7B,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,MAAM,CAAC,YAAY;IAkB3B,OAAO,CAAC,MAAM,CAAC,mBAAmB;IASlC,2TAA2T;IAC3T,MAAM,CAAC,aAAa,CAAC,IAAI,EAAE;QACzB,OAAO,EAAE,MAAM,CAAC;QAChB,IAAI,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;QACrB,cAAc,CAAC,EAAE,IAAI,CAAC,cAAc,CAAC;KACtC,GAAG,MAAM;CAgEX"}