@venizia/ignis-helpers 0.4.7-0 → 0.4.7-2

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 (311) hide show
  1. package/LICENSE.md +1 -3
  2. package/README.md +7 -8
  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 +5 -3
  12. package/dist/esm/core.d.ts.map +1 -1
  13. package/dist/esm/core.js +7 -3
  14. package/dist/esm/core.js.map +1 -1
  15. package/dist/esm/modules/base.d.ts +1 -1
  16. package/dist/esm/modules/base.d.ts.map +1 -1
  17. package/dist/esm/modules/base.js +14 -5
  18. package/dist/esm/modules/base.js.map +1 -1
  19. package/dist/esm/modules/cron/helper.js +4 -4
  20. package/dist/esm/modules/cron/helper.js.map +1 -1
  21. package/dist/esm/modules/crypto/algorithms/aes-legacy.algorithm.js +3 -3
  22. package/dist/esm/modules/crypto/algorithms/aes-legacy.algorithm.js.map +1 -1
  23. package/dist/esm/modules/crypto/algorithms/aes.algorithm.js +5 -5
  24. package/dist/esm/modules/crypto/algorithms/aes.algorithm.js.map +1 -1
  25. package/dist/esm/modules/crypto/algorithms/base.algorithm.js +3 -3
  26. package/dist/esm/modules/crypto/algorithms/base.algorithm.js.map +1 -1
  27. package/dist/esm/modules/crypto/algorithms/hash.algorithm.d.ts +15 -5
  28. package/dist/esm/modules/crypto/algorithms/hash.algorithm.d.ts.map +1 -1
  29. package/dist/esm/modules/crypto/algorithms/hash.algorithm.js +16 -4
  30. package/dist/esm/modules/crypto/algorithms/hash.algorithm.js.map +1 -1
  31. package/dist/esm/modules/env/app-env.d.ts.map +1 -1
  32. package/dist/esm/modules/env/app-env.js +2 -2
  33. package/dist/esm/modules/env/app-env.js.map +1 -1
  34. package/dist/esm/modules/logger/base/base.d.ts.map +1 -1
  35. package/dist/esm/modules/logger/base/base.js +3 -3
  36. package/dist/esm/modules/logger/base/base.js.map +1 -1
  37. package/dist/esm/modules/logger/base/console.d.ts +9 -4
  38. package/dist/esm/modules/logger/base/console.d.ts.map +1 -1
  39. package/dist/esm/modules/logger/base/console.js +15 -4
  40. package/dist/esm/modules/logger/base/console.js.map +1 -1
  41. package/dist/esm/modules/logger/common/constants.d.ts +23 -22
  42. package/dist/esm/modules/logger/common/constants.d.ts.map +1 -1
  43. package/dist/esm/modules/logger/common/constants.js +43 -46
  44. package/dist/esm/modules/logger/common/constants.js.map +1 -1
  45. package/dist/esm/modules/logger/common/debug-gate.d.ts +33 -0
  46. package/dist/esm/modules/logger/common/debug-gate.d.ts.map +1 -0
  47. package/dist/esm/modules/logger/common/debug-gate.js +51 -0
  48. package/dist/esm/modules/logger/common/debug-gate.js.map +1 -0
  49. package/dist/esm/modules/logger/common/index.d.ts +1 -0
  50. package/dist/esm/modules/logger/common/index.d.ts.map +1 -1
  51. package/dist/esm/modules/logger/common/index.js +1 -0
  52. package/dist/esm/modules/logger/common/index.js.map +1 -1
  53. package/dist/esm/modules/logger/common/types.d.ts +7 -0
  54. package/dist/esm/modules/logger/common/types.d.ts.map +1 -1
  55. package/dist/esm/modules/logger/common/types.js +16 -0
  56. package/dist/esm/modules/logger/common/types.js.map +1 -1
  57. package/dist/esm/modules/logger/factory.d.ts +29 -10
  58. package/dist/esm/modules/logger/factory.d.ts.map +1 -1
  59. package/dist/esm/modules/logger/factory.js +108 -48
  60. package/dist/esm/modules/logger/factory.js.map +1 -1
  61. package/dist/esm/modules/logger/formatting/deep-splat.d.ts +10 -6
  62. package/dist/esm/modules/logger/formatting/deep-splat.d.ts.map +1 -1
  63. package/dist/esm/modules/logger/formatting/deep-splat.js +73 -62
  64. package/dist/esm/modules/logger/formatting/deep-splat.js.map +1 -1
  65. package/dist/esm/modules/logger/formatting/error-prettier.d.ts.map +1 -1
  66. package/dist/esm/modules/logger/formatting/error-prettier.js +8 -6
  67. package/dist/esm/modules/logger/formatting/error-prettier.js.map +1 -1
  68. package/dist/esm/modules/logger/hf/logger.d.ts.map +1 -1
  69. package/dist/esm/modules/logger/hf/logger.js +5 -5
  70. package/dist/esm/modules/logger/hf/logger.js.map +1 -1
  71. package/dist/esm/modules/logger/index.d.ts +0 -1
  72. package/dist/esm/modules/logger/index.d.ts.map +1 -1
  73. package/dist/esm/modules/logger/index.js +0 -1
  74. package/dist/esm/modules/logger/index.js.map +1 -1
  75. package/dist/esm/modules/logger/pino/backing.d.ts +0 -9
  76. package/dist/esm/modules/logger/pino/backing.d.ts.map +1 -1
  77. package/dist/esm/modules/logger/pino/backing.js +3 -8
  78. package/dist/esm/modules/logger/pino/backing.js.map +1 -1
  79. package/dist/esm/modules/logger/pino/destination.d.ts +6 -9
  80. package/dist/esm/modules/logger/pino/destination.d.ts.map +1 -1
  81. package/dist/esm/modules/logger/pino/destination.js +12 -13
  82. package/dist/esm/modules/logger/pino/destination.js.map +1 -1
  83. package/dist/esm/modules/logger/pino/logger.js +2 -2
  84. package/dist/esm/modules/logger/pino/logger.js.map +1 -1
  85. package/dist/esm/modules/logger/winston/common/constants.d.ts.map +1 -1
  86. package/dist/esm/modules/logger/winston/common/constants.js +7 -6
  87. package/dist/esm/modules/logger/winston/common/constants.js.map +1 -1
  88. package/dist/esm/modules/logger/winston/define.d.ts +0 -7
  89. package/dist/esm/modules/logger/winston/define.d.ts.map +1 -1
  90. package/dist/esm/modules/logger/winston/define.js +0 -5
  91. package/dist/esm/modules/logger/winston/define.js.map +1 -1
  92. package/dist/esm/modules/logger/winston/formats.d.ts +2 -0
  93. package/dist/esm/modules/logger/winston/formats.d.ts.map +1 -1
  94. package/dist/esm/modules/logger/winston/formats.js +17 -4
  95. package/dist/esm/modules/logger/winston/formats.js.map +1 -1
  96. package/dist/esm/modules/logger/winston/index.d.ts +3 -2
  97. package/dist/esm/modules/logger/winston/index.d.ts.map +1 -1
  98. package/dist/esm/modules/logger/winston/index.js +3 -2
  99. package/dist/esm/modules/logger/winston/index.js.map +1 -1
  100. package/dist/esm/modules/logger/winston/logger-factory.js +4 -4
  101. package/dist/esm/modules/logger/winston/logger-factory.js.map +1 -1
  102. package/dist/esm/modules/network/http-request/base-network-request.helper.js +2 -2
  103. package/dist/esm/modules/network/http-request/base-network-request.helper.js.map +1 -1
  104. package/dist/esm/modules/network/http-request/common/index.d.ts +0 -1
  105. package/dist/esm/modules/network/http-request/common/index.d.ts.map +1 -1
  106. package/dist/esm/modules/network/http-request/common/index.js +0 -1
  107. package/dist/esm/modules/network/http-request/common/index.js.map +1 -1
  108. package/dist/esm/modules/network/http-request/fetcher/axios-fetcher.d.ts.map +1 -1
  109. package/dist/esm/modules/network/http-request/fetcher/axios-fetcher.js +4 -2
  110. package/dist/esm/modules/network/http-request/fetcher/axios-fetcher.js.map +1 -1
  111. package/dist/esm/modules/network/http-request/fetcher/node-fetcher.d.ts.map +1 -1
  112. package/dist/esm/modules/network/http-request/fetcher/node-fetcher.js +6 -4
  113. package/dist/esm/modules/network/http-request/fetcher/node-fetcher.js.map +1 -1
  114. package/dist/esm/modules/network/tcp-socket/base-tcp-client.helper.js +4 -4
  115. package/dist/esm/modules/network/tcp-socket/base-tcp-client.helper.js.map +1 -1
  116. package/dist/esm/modules/network/tcp-socket/base-tcp-server.helper.js +4 -4
  117. package/dist/esm/modules/network/tcp-socket/base-tcp-server.helper.js.map +1 -1
  118. package/dist/esm/modules/network/udp-socket/network-udp-client.helper.js +2 -2
  119. package/dist/esm/modules/network/udp-socket/network-udp-client.helper.js.map +1 -1
  120. package/dist/esm/modules/network/utilities/query-string.d.ts +22 -20
  121. package/dist/esm/modules/network/utilities/query-string.d.ts.map +1 -1
  122. package/dist/esm/modules/network/utilities/query-string.js +48 -46
  123. package/dist/esm/modules/network/utilities/query-string.js.map +1 -1
  124. package/dist/esm/modules/network/utilities/url-safety/common/errors.d.ts +0 -10
  125. package/dist/esm/modules/network/utilities/url-safety/common/errors.d.ts.map +1 -1
  126. package/dist/esm/modules/network/utilities/url-safety/common/errors.js +0 -11
  127. package/dist/esm/modules/network/utilities/url-safety/common/errors.js.map +1 -1
  128. package/dist/esm/modules/network/utilities/url-safety/policy.d.ts +10 -0
  129. package/dist/esm/modules/network/utilities/url-safety/policy.d.ts.map +1 -1
  130. package/dist/esm/modules/network/utilities/url-safety/policy.js +11 -0
  131. package/dist/esm/modules/network/utilities/url-safety/policy.js.map +1 -1
  132. package/dist/esm/modules/queue/bullmq/helper.d.ts.map +1 -1
  133. package/dist/esm/modules/queue/bullmq/helper.js +6 -6
  134. package/dist/esm/modules/queue/bullmq/helper.js.map +1 -1
  135. package/dist/esm/modules/queue/common/hook.d.ts +14 -12
  136. package/dist/esm/modules/queue/common/hook.d.ts.map +1 -1
  137. package/dist/esm/modules/queue/common/hook.js +21 -19
  138. package/dist/esm/modules/queue/common/hook.js.map +1 -1
  139. package/dist/esm/modules/queue/common/index.d.ts +0 -1
  140. package/dist/esm/modules/queue/common/index.d.ts.map +1 -1
  141. package/dist/esm/modules/queue/common/index.js +0 -1
  142. package/dist/esm/modules/queue/common/index.js.map +1 -1
  143. package/dist/esm/modules/queue/internal/sequential/helper.js +8 -8
  144. package/dist/esm/modules/queue/internal/sequential/helper.js.map +1 -1
  145. package/dist/esm/modules/queue/kafka/base.js +3 -3
  146. package/dist/esm/modules/queue/kafka/base.js.map +1 -1
  147. package/dist/esm/modules/queue/kafka/bundler/index.d.ts +0 -2
  148. package/dist/esm/modules/queue/kafka/bundler/index.d.ts.map +1 -1
  149. package/dist/esm/modules/queue/kafka/bundler/index.js +0 -2
  150. package/dist/esm/modules/queue/kafka/bundler/index.js.map +1 -1
  151. package/dist/esm/modules/queue/kafka/bundler/plugins.d.ts +8 -2
  152. package/dist/esm/modules/queue/kafka/bundler/plugins.d.ts.map +1 -1
  153. package/dist/esm/modules/queue/kafka/bundler/plugins.js +64 -7
  154. package/dist/esm/modules/queue/kafka/bundler/plugins.js.map +1 -1
  155. package/dist/esm/modules/queue/kafka/consumer.d.ts.map +1 -1
  156. package/dist/esm/modules/queue/kafka/consumer.js +22 -22
  157. package/dist/esm/modules/queue/kafka/consumer.js.map +1 -1
  158. package/dist/esm/modules/queue/mqtt/helper.js +10 -10
  159. package/dist/esm/modules/queue/mqtt/helper.js.map +1 -1
  160. package/dist/esm/modules/redis/base/abstract.helper.js +8 -8
  161. package/dist/esm/modules/redis/base/abstract.helper.js.map +1 -1
  162. package/dist/esm/modules/redis/cluster/cluster.helper.js +2 -2
  163. package/dist/esm/modules/redis/cluster/cluster.helper.js.map +1 -1
  164. package/dist/esm/modules/redis/factory.d.ts +13 -9
  165. package/dist/esm/modules/redis/factory.d.ts.map +1 -1
  166. package/dist/esm/modules/redis/factory.js +15 -13
  167. package/dist/esm/modules/redis/factory.js.map +1 -1
  168. package/dist/esm/modules/redis/sentinel/sentinel.helper.js +2 -2
  169. package/dist/esm/modules/redis/sentinel/sentinel.helper.js.map +1 -1
  170. package/dist/esm/modules/redis/single/single.helper.js +2 -2
  171. package/dist/esm/modules/redis/single/single.helper.js.map +1 -1
  172. package/dist/esm/modules/redis/utility.d.ts +13 -11
  173. package/dist/esm/modules/redis/utility.d.ts.map +1 -1
  174. package/dist/esm/modules/redis/utility.js +46 -44
  175. package/dist/esm/modules/redis/utility.js.map +1 -1
  176. package/dist/esm/modules/retry/helper.js +2 -2
  177. package/dist/esm/modules/retry/helper.js.map +1 -1
  178. package/dist/esm/modules/secrets/factory.d.ts +5 -3
  179. package/dist/esm/modules/secrets/factory.d.ts.map +1 -1
  180. package/dist/esm/modules/secrets/factory.js +36 -34
  181. package/dist/esm/modules/secrets/factory.js.map +1 -1
  182. package/dist/esm/modules/socket/socket-io/server/helper.d.ts.map +1 -1
  183. package/dist/esm/modules/socket/socket-io/server/helper.js +11 -11
  184. package/dist/esm/modules/socket/socket-io/server/helper.js.map +1 -1
  185. package/dist/esm/modules/socket/websocket/emitter/helper.d.ts.map +1 -1
  186. package/dist/esm/modules/socket/websocket/emitter/helper.js +3 -3
  187. package/dist/esm/modules/socket/websocket/emitter/helper.js.map +1 -1
  188. package/dist/esm/modules/socket/websocket/server/delivery.d.ts.map +1 -1
  189. package/dist/esm/modules/socket/websocket/server/delivery.js +5 -6
  190. package/dist/esm/modules/socket/websocket/server/delivery.js.map +1 -1
  191. package/dist/esm/modules/socket/websocket/server/helper.d.ts.map +1 -1
  192. package/dist/esm/modules/socket/websocket/server/helper.js +7 -7
  193. package/dist/esm/modules/socket/websocket/server/helper.js.map +1 -1
  194. package/dist/esm/modules/storage/base.js +7 -7
  195. package/dist/esm/modules/storage/base.js.map +1 -1
  196. package/dist/esm/modules/storage/bun-s3/helper.d.ts.map +1 -1
  197. package/dist/esm/modules/storage/bun-s3/helper.js +25 -18
  198. package/dist/esm/modules/storage/bun-s3/helper.js.map +1 -1
  199. package/dist/esm/modules/storage/bun-s3/utility.d.ts +95 -77
  200. package/dist/esm/modules/storage/bun-s3/utility.d.ts.map +1 -1
  201. package/dist/esm/modules/storage/bun-s3/utility.js +261 -239
  202. package/dist/esm/modules/storage/bun-s3/utility.js.map +1 -1
  203. package/dist/esm/modules/storage/common/errors.d.ts +0 -4
  204. package/dist/esm/modules/storage/common/errors.d.ts.map +1 -1
  205. package/dist/esm/modules/storage/common/errors.js +0 -10
  206. package/dist/esm/modules/storage/common/errors.js.map +1 -1
  207. package/dist/esm/modules/storage/common/utility.d.ts +11 -5
  208. package/dist/esm/modules/storage/common/utility.d.ts.map +1 -1
  209. package/dist/esm/modules/storage/common/utility.js +30 -17
  210. package/dist/esm/modules/storage/common/utility.js.map +1 -1
  211. package/dist/esm/modules/uid/uuid/helper.d.ts +1 -1
  212. package/dist/esm/modules/uid/uuid/helper.d.ts.map +1 -1
  213. package/dist/esm/modules/uid/uuid/helper.js +7 -7
  214. package/dist/esm/modules/uid/uuid/helper.js.map +1 -1
  215. package/dist/esm/modules/uid/uuid/v4.d.ts +11 -8
  216. package/dist/esm/modules/uid/uuid/v4.d.ts.map +1 -1
  217. package/dist/esm/modules/uid/uuid/v4.js +51 -46
  218. package/dist/esm/modules/uid/uuid/v4.js.map +1 -1
  219. package/dist/esm/modules/uid/uuid/v5.d.ts +17 -14
  220. package/dist/esm/modules/uid/uuid/v5.d.ts.map +1 -1
  221. package/dist/esm/modules/uid/uuid/v5.js +83 -78
  222. package/dist/esm/modules/uid/uuid/v5.js.map +1 -1
  223. package/dist/esm/modules/uid/uuid/v7.d.ts +15 -10
  224. package/dist/esm/modules/uid/uuid/v7.d.ts.map +1 -1
  225. package/dist/esm/modules/uid/uuid/v7.js +88 -79
  226. package/dist/esm/modules/uid/uuid/v7.js.map +1 -1
  227. package/dist/esm/modules/worker-thread/bus/base.js +2 -2
  228. package/dist/esm/modules/worker-thread/bus/base.js.map +1 -1
  229. package/dist/esm/modules/worker-thread/worker/base.d.ts.map +1 -1
  230. package/dist/esm/modules/worker-thread/worker/base.js +4 -3
  231. package/dist/esm/modules/worker-thread/worker/base.js.map +1 -1
  232. package/dist/esm/utilities/error.utility.d.ts +7 -0
  233. package/dist/esm/utilities/error.utility.d.ts.map +1 -0
  234. package/dist/esm/utilities/error.utility.js +9 -0
  235. package/dist/esm/utilities/error.utility.js.map +1 -0
  236. package/dist/esm/utilities/form-body.utility.d.ts +12 -10
  237. package/dist/esm/utilities/form-body.utility.d.ts.map +1 -1
  238. package/dist/esm/utilities/form-body.utility.js +19 -17
  239. package/dist/esm/utilities/form-body.utility.js.map +1 -1
  240. package/dist/esm/utilities/hr-time.utility.d.ts +7 -5
  241. package/dist/esm/utilities/hr-time.utility.d.ts.map +1 -1
  242. package/dist/esm/utilities/hr-time.utility.js +11 -9
  243. package/dist/esm/utilities/hr-time.utility.js.map +1 -1
  244. package/dist/esm/utilities/index.d.ts +2 -2
  245. package/dist/esm/utilities/index.d.ts.map +1 -1
  246. package/dist/esm/utilities/index.js +2 -2
  247. package/dist/esm/utilities/index.js.map +1 -1
  248. package/dist/esm/utilities/module.utility.d.ts.map +1 -1
  249. package/dist/esm/utilities/module.utility.js +1 -0
  250. package/dist/esm/utilities/module.utility.js.map +1 -1
  251. package/dist/esm/utilities/parse.utility.d.ts +89 -43
  252. package/dist/esm/utilities/parse.utility.d.ts.map +1 -1
  253. package/dist/esm/utilities/parse.utility.js +173 -141
  254. package/dist/esm/utilities/parse.utility.js.map +1 -1
  255. package/dist/esm/utilities/performance.utility.d.ts +15 -13
  256. package/dist/esm/utilities/performance.utility.d.ts.map +1 -1
  257. package/dist/esm/utilities/performance.utility.js +34 -29
  258. package/dist/esm/utilities/performance.utility.js.map +1 -1
  259. package/dist/esm/utilities/promise.utility.d.ts +20 -18
  260. package/dist/esm/utilities/promise.utility.d.ts.map +1 -1
  261. package/dist/esm/utilities/promise.utility.js +41 -51
  262. package/dist/esm/utilities/promise.utility.js.map +1 -1
  263. package/dist/esm/utilities/request.utility.d.ts +35 -29
  264. package/dist/esm/utilities/request.utility.d.ts.map +1 -1
  265. package/dist/esm/utilities/request.utility.js +118 -115
  266. package/dist/esm/utilities/request.utility.js.map +1 -1
  267. package/package.json +4 -15
  268. package/dist/esm/modules/logger/resolver.d.ts +0 -33
  269. package/dist/esm/modules/logger/resolver.d.ts.map +0 -1
  270. package/dist/esm/modules/logger/resolver.js +0 -95
  271. package/dist/esm/modules/logger/resolver.js.map +0 -1
  272. package/dist/esm/modules/logger/slot.d.ts +0 -23
  273. package/dist/esm/modules/logger/slot.d.ts.map +0 -1
  274. package/dist/esm/modules/logger/slot.js +0 -119
  275. package/dist/esm/modules/logger/slot.js.map +0 -1
  276. package/dist/esm/modules/logger/winston/formatters/deep-splat.d.ts +0 -4
  277. package/dist/esm/modules/logger/winston/formatters/deep-splat.d.ts.map +0 -1
  278. package/dist/esm/modules/logger/winston/formatters/deep-splat.js +0 -14
  279. package/dist/esm/modules/logger/winston/formatters/deep-splat.js.map +0 -1
  280. package/dist/esm/modules/logger/winston/formatters/index.d.ts +0 -2
  281. package/dist/esm/modules/logger/winston/formatters/index.d.ts.map +0 -1
  282. package/dist/esm/modules/logger/winston/formatters/index.js +0 -2
  283. package/dist/esm/modules/logger/winston/formatters/index.js.map +0 -1
  284. package/dist/esm/modules/network/http-request/common/types.d.ts +0 -2
  285. package/dist/esm/modules/network/http-request/common/types.d.ts.map +0 -1
  286. package/dist/esm/modules/network/http-request/common/types.js +0 -2
  287. package/dist/esm/modules/network/http-request/common/types.js.map +0 -1
  288. package/dist/esm/modules/queue/common/types.d.ts +0 -2
  289. package/dist/esm/modules/queue/common/types.d.ts.map +0 -1
  290. package/dist/esm/modules/queue/common/types.js +0 -2
  291. package/dist/esm/modules/queue/common/types.js.map +0 -1
  292. package/dist/esm/modules/queue/kafka/bundler/platformatic-require.plugin.d.ts +0 -4
  293. package/dist/esm/modules/queue/kafka/bundler/platformatic-require.plugin.d.ts.map +0 -1
  294. package/dist/esm/modules/queue/kafka/bundler/platformatic-require.plugin.js +0 -28
  295. package/dist/esm/modules/queue/kafka/bundler/platformatic-require.plugin.js.map +0 -1
  296. package/dist/esm/modules/queue/kafka/bundler/platformatic-wasm.plugin.d.ts +0 -4
  297. package/dist/esm/modules/queue/kafka/bundler/platformatic-wasm.plugin.d.ts.map +0 -1
  298. package/dist/esm/modules/queue/kafka/bundler/platformatic-wasm.plugin.js +0 -26
  299. package/dist/esm/modules/queue/kafka/bundler/platformatic-wasm.plugin.js.map +0 -1
  300. package/dist/esm/modules/storage/minio/helper.d.ts +0 -55
  301. package/dist/esm/modules/storage/minio/helper.d.ts.map +0 -1
  302. package/dist/esm/modules/storage/minio/helper.js +0 -177
  303. package/dist/esm/modules/storage/minio/helper.js.map +0 -1
  304. package/dist/esm/modules/storage/minio/index.d.ts +0 -2
  305. package/dist/esm/modules/storage/minio/index.d.ts.map +0 -1
  306. package/dist/esm/modules/storage/minio/index.js +0 -2
  307. package/dist/esm/modules/storage/minio/index.js.map +0 -1
  308. package/dist/esm/utilities/sleep.utility.d.ts +0 -2
  309. package/dist/esm/utilities/sleep.utility.d.ts.map +0 -1
  310. package/dist/esm/utilities/sleep.utility.js +0 -4
  311. package/dist/esm/utilities/sleep.utility.js.map +0 -1
@@ -1,7 +1,7 @@
1
1
  import { BaseHelper } from '../../base.js';
2
2
  import { getError } from '../../error/index.js';
3
- import { getUID } from '../../../utilities/parse.utility.js';
4
- import { voidExecution } from '../../../utilities/promise.utility.js';
3
+ import { ParseUtility } from '../../../utilities/parse.utility.js';
4
+ import { PromiseUtility } from '../../../utilities/promise.utility.js';
5
5
  /** Where a TCP client is in the authentication handshake. */
6
6
  export class TcpClientStates {
7
7
  static { this.UNAUTHORIZED = 'unauthorized'; }
@@ -85,7 +85,7 @@ export class BaseNetworkTcpServer extends BaseHelper {
85
85
  }
86
86
  onNewConnection(opts) {
87
87
  const { socket } = opts;
88
- const id = getUID();
88
+ const id = ParseUtility.getUID();
89
89
  socket.on('data', (data) => {
90
90
  this.invokeHook({
91
91
  scope: 'onClientData',
@@ -124,7 +124,7 @@ export class BaseNetworkTcpServer extends BaseHelper {
124
124
  });
125
125
  for (const extraEvent in this.extraEvents) {
126
126
  socket.on(extraEvent, (args) => {
127
- voidExecution({
127
+ PromiseUtility.voidExecution({
128
128
  logger: this.logger,
129
129
  scope: 'onClientConnect',
130
130
  // The async wrapper turns a SYNCHRONOUS throw from the handler into a rejection; calling it bare would throw out of this listener as an uncaught exception.
@@ -1 +1 @@
1
- {"version":3,"file":"base-tcp-server.helper.js","sourceRoot":"","sources":["../../../../../src/modules/network/tcp-socket/base-tcp-server.helper.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,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M,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,8BAA8B,EAAE,QAAQ,CAAC,CAAC;YAChF,OAAO;QACT,CAAC;QAED,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,CAAC;YACrB,IAAI,CAAC,MAAM;iBACR,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;iBACnB,IAAI,CACH,0DAA0D,EAC1D,IAAI,CAAC,UAAU,EACf,QAAQ,CACT,CAAC;YACJ,OAAO;QACT,CAAC;QAED,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IACxB,CAAC;CACF","sourcesContent":["import type { TConstValue } from '@/common/types';\nimport { type ValueOrPromise } from '@/common/types';\nimport { BaseHelper } from '@/modules/base';\nimport { getError } from '@/modules/error';\nimport { getUID } from '@/utilities/parse.utility';\nimport { voidExecution } from '@/utilities/promise.utility';\nimport {\n type ListenOptions,\n type ServerOpts,\n type Socket as SocketClient,\n type Server as SocketServer,\n} from 'node:net';\n\n/** Where a TCP client is in the authentication handshake. */\nexport class TcpClientStates {\n static readonly UNAUTHORIZED = 'unauthorized';\n static readonly AUTHENTICATING = 'authenticating';\n static readonly AUTHENTICATED = 'authenticated';\n\n static readonly SCHEME_SET = new Set<string>([\n this.UNAUTHORIZED,\n this.AUTHENTICATING,\n this.AUTHENTICATED,\n ]);\n\n static isValid(value: string): boolean {\n return this.SCHEME_SET.has(value);\n }\n}\n\n/** Valid TCP client state values. */\nexport type TTcpClientState = TConstValue<typeof TcpClientStates>;\n\nexport interface ITcpSocketClient<SocketClientType> {\n id: string;\n socket: SocketClientType;\n state: TTcpClientState;\n subscriptions: Set<string>;\n storage: {\n connectedAt: Date;\n authenticatedAt: Date | null;\n authenticateTimeout?: ReturnType<typeof setTimeout> | null;\n [additionField: symbol | string]: any;\n };\n}\n\nexport interface ITcpSocketServerOptions<\n SocketServerOptions extends ServerOpts = ServerOpts,\n SocketServerType extends SocketServer = SocketServer,\n SocketClientType extends SocketClient = SocketClient,\n> {\n scope?: string;\n identifier: string;\n\n serverOptions: Partial<SocketServerOptions>;\n listenOptions: Partial<ListenOptions>;\n authenticateOptions: { required: boolean; duration?: number };\n\n extraEvents?: Record<\n string,\n (opts: { id: string; socket: SocketClientType; args: any }) => ValueOrPromise<void>\n >;\n\n createServerFn: (\n options: Partial<SocketServerOptions>,\n connectionListener: (socket: SocketClientType) => void,\n ) => SocketServerType;\n\n onServerReady?: (opts: { server: SocketServerType }) => void;\n onClientConnected?: (opts: { id: string; socket: SocketClientType }) => void;\n onClientData?: (opts: { id: string; socket: SocketClientType; data: Buffer | string }) => void;\n onClientClose?: (opts: { id: string; socket: SocketClientType }) => void;\n onClientError?: (opts: { id: string; socket: SocketClientType; error: Error }) => void;\n onServerError?: (opts: { server: SocketServerType; error: Error }) => void;\n}\n\nexport class BaseNetworkTcpServer<\n SocketServerOptions extends ServerOpts = ServerOpts,\n SocketServerType extends SocketServer = SocketServer,\n SocketClientType extends SocketClient = SocketClient,\n> extends BaseHelper {\n protected serverOptions: Partial<SocketServerOptions> = {};\n protected listenOptions: Partial<ListenOptions> = {};\n protected authenticateOptions: { required: boolean; duration?: number };\n\n protected clients: Record<string, ITcpSocketClient<SocketClientType>>;\n protected server: SocketServerType;\n\n protected extraEvents: Record<\n string,\n (opts: { id: string; socket: SocketClientType; args: any }) => ValueOrPromise<void>\n >;\n\n protected createServerFn: (\n options: Partial<SocketServerOptions>,\n connectionListener: (socket: SocketClientType) => void,\n ) => SocketServerType;\n\n protected onServerReady?: (opts: { server: SocketServerType }) => void;\n protected onClientConnected?: (opts: { id: string; socket: SocketClientType }) => void;\n protected onClientData?: (opts: {\n id: string;\n socket: SocketClientType;\n data: Buffer | string;\n }) => void;\n protected onClientClose?: (opts: { id: string; socket: SocketClientType }) => void;\n protected onClientError?: (opts: { id: string; socket: SocketClientType; error: Error }) => void;\n protected onServerError?: (opts: { server: SocketServerType; error: Error }) => void;\n\n constructor(\n opts: ITcpSocketServerOptions<SocketServerOptions, SocketServerType, SocketClientType>,\n ) {\n super({\n scope: opts.scope ?? opts.identifier ?? BaseNetworkTcpServer.name,\n identifier: opts.identifier,\n });\n\n // No prototype: `getClient({ id: 'constructor' })` must find nothing, not `Object`.\n this.clients = Object.create(null);\n\n this.serverOptions = opts.serverOptions;\n this.listenOptions = opts.listenOptions;\n this.authenticateOptions = opts.authenticateOptions;\n\n if (\n this.authenticateOptions.required &&\n (!this.authenticateOptions.duration || this.authenticateOptions.duration < 0)\n ) {\n throw getError({\n message:\n 'TCP Server | Invalid authenticate duration | Required duration for authenticateOptions',\n });\n }\n\n this.extraEvents = opts.extraEvents ?? {};\n\n this.createServerFn = opts.createServerFn;\n\n this.onServerReady = opts.onServerReady;\n this.onClientConnected = opts.onClientConnected;\n this.onClientData = opts.onClientData;\n this.onClientClose = opts.onClientClose;\n this.onClientError = opts.onClientError;\n this.onServerError = opts.onServerError;\n\n this.configure();\n }\n\n // Hooks run inside socket event listeners: a synchronous throw there is an uncaught exception that kills the process and skips the client-registry cleanup that follows it.\n protected invokeHook(opts: { scope: string; execution: () => void }) {\n const { scope, execution } = opts;\n\n try {\n execution();\n } catch (error) {\n this.logger.for(scope).error('Hook execution FAILED | Error: %s', error);\n }\n }\n\n configure() {\n this.server = this.createServerFn(this.serverOptions, (socket) => {\n this.onNewConnection({ socket });\n });\n\n // Without this listener a failed listen - a port already in use is the commonest boot failure there is - emits an unhandled 'error' event, which takes the whole process down with it.\n this.server.on('error', (error: Error) => {\n this.logger\n .for(this.configure.name)\n .error('TCP Socket Server error | Options: %j | Error: %s', this.listenOptions, error);\n\n this.invokeHook({\n scope: this.configure.name,\n execution: () => {\n this.onServerError?.({ server: this.server, error });\n },\n });\n });\n\n this.server.listen(this.listenOptions, () => {\n this.logger\n .for(this.configure.name)\n .info('TCP Socket Server is now listening | Options: %j', this.listenOptions);\n\n this.invokeHook({\n scope: this.configure.name,\n execution: () => {\n this.onServerReady?.({ server: this.server });\n },\n });\n });\n }\n\n onNewConnection(opts: { socket: SocketClientType }) {\n const { socket } = opts;\n\n const id = getUID();\n\n socket.on('data', (data: Buffer | string) => {\n this.invokeHook({\n scope: 'onClientData',\n execution: () => {\n this.onClientData?.({ id, socket, data });\n },\n });\n });\n\n socket.on('error', (error: Error) => {\n this.logger.for('onClientConnect').error('Socket Error | ID: %s | Error: %s', id, error);\n\n this.invokeHook({\n scope: 'onClientError',\n execution: () => {\n this.onClientError?.({ id, socket, error });\n },\n });\n\n socket.end();\n });\n\n socket.on('close', (hasError: boolean) => {\n this.logger\n .for('onClientConnect')\n .info('Socket Closed | ID: %s | hasError: %s', id, hasError);\n\n this.invokeHook({\n scope: 'onClientClose',\n execution: () => {\n this.onClientClose?.({ id, socket });\n },\n });\n\n const authenticateTimeout = this.getClient({ id })?.storage?.authenticateTimeout;\n if (authenticateTimeout) {\n clearTimeout(authenticateTimeout);\n }\n\n // `delete`, not `omit`: omit rebuilds the WHOLE registry per disconnect, so a disconnect\n // storm is O(n^2) - measured at 5000 clients, 2.3s of drain with a 2.2s worst-case stall.\n delete this.clients[id];\n });\n\n for (const extraEvent in this.extraEvents) {\n socket.on(extraEvent, (args) => {\n voidExecution({\n logger: this.logger,\n scope: 'onClientConnect',\n // The async wrapper turns a SYNCHRONOUS throw from the handler into a rejection; calling it bare would throw out of this listener as an uncaught exception.\n execution: (async () => this.extraEvents[extraEvent]({ id, socket, args }))(),\n });\n });\n }\n\n this.clients[id] = {\n id,\n socket,\n state: this.authenticateOptions.required\n ? TcpClientStates.UNAUTHORIZED\n : TcpClientStates.AUTHENTICATED,\n subscriptions: new Set([]),\n storage: {\n connectedAt: new Date(),\n authenticatedAt: this.authenticateOptions.required ? null : new Date(),\n },\n };\n\n this.logger\n .for('onClientConnect')\n .info(\n 'New TCP SocketClient | Client: %s | authenticateOptions: %s %s',\n `${id} - ${socket.remoteAddress} - ${socket.remotePort} - ${socket.remoteFamily}`,\n this.authenticateOptions.required,\n this.authenticateOptions.duration,\n );\n\n this.invokeHook({\n scope: 'onClientConnected',\n execution: () => {\n this.onClientConnected?.({ id, socket });\n },\n });\n\n if (\n this.authenticateOptions.required &&\n this.authenticateOptions.duration &&\n this.authenticateOptions.duration > 0\n ) {\n const authenticateTimeout = setTimeout(() => {\n const client = this.getClient({ id });\n if (!client) {\n return;\n }\n\n client.storage.authenticateTimeout = null;\n\n if (client.state === TcpClientStates.AUTHENTICATED) {\n return;\n }\n\n this.emit({ clientId: id, payload: 'Unauthorized Client' });\n client.socket.end();\n }, this.authenticateOptions.duration);\n\n const client = this.getClient({ id });\n if (!client) {\n clearTimeout(authenticateTimeout);\n return;\n }\n\n client.storage.authenticateTimeout = authenticateTimeout;\n }\n }\n\n getClients() {\n return this.clients;\n }\n\n getClient(opts: { id: string }) {\n return this.clients?.[opts.id];\n }\n\n getServer() {\n return this.server;\n }\n\n /** Clears timers and destroys all client sockets before closing the listener - `server.close()` alone never settles while a socket stays attached. Idempotent; safe if never listened. */\n async shutdown(): Promise<void> {\n const clientsValues = Object.values(this.clients);\n for (const client of clientsValues) {\n const { authenticateTimeout } = client.storage;\n if (authenticateTimeout) {\n clearTimeout(authenticateTimeout);\n client.storage.authenticateTimeout = null;\n }\n\n client.socket.destroy();\n }\n\n this.clients = Object.create(null);\n\n const server = this.server;\n if (!server) {\n return;\n }\n\n // Not guarded on `listening`: listen() is async (DNS lookup), so a shutdown() racing startup could skip close() and leave the server bound forever; close() on a never-listened server just logs ERR_SERVER_NOT_RUNNING below.\n\n await new Promise<void>((resolve) => {\n server.close((error) => {\n if (error) {\n this.logger.for(this.shutdown.name).error('Failed to close server | Error: %s', error);\n }\n\n resolve();\n });\n });\n\n this.logger.for(this.shutdown.name).info('Server closed | Identifier: %s', this.identifier);\n }\n\n doAuthenticate(opts: { id: string; state: TTcpClientState }) {\n const { id, state } = opts;\n\n const client = this.getClient({ id });\n if (!client) {\n this.logger.for('authenticateClient').error('Client NOT FOUND | ID: %s', id);\n return;\n }\n\n client.state = state;\n\n switch (state) {\n case TcpClientStates.UNAUTHORIZED:\n case TcpClientStates.AUTHENTICATING: {\n client.storage.authenticatedAt = null;\n break;\n }\n case TcpClientStates.AUTHENTICATED: {\n client.storage.authenticatedAt = new Date();\n\n if (client.storage.authenticateTimeout) {\n clearTimeout(client.storage.authenticateTimeout);\n client.storage.authenticateTimeout = null;\n }\n break;\n }\n default: {\n break;\n }\n }\n }\n\n emit(opts: { clientId: string; payload: Buffer | string }) {\n const { clientId, payload } = opts;\n const client = this.getClient({ id: clientId });\n\n if (!client) {\n this.logger.for(this.emit.name).error('Client NOT FOUND | ID: %s', clientId);\n return;\n }\n\n const { socket } = client;\n if (!socket.writable) {\n this.logger.for(this.emit.name).error('Client NOT WRITABLE | ID: %s', clientId);\n return;\n }\n\n if (!payload?.length) {\n this.logger\n .for(this.emit.name)\n .info(\n '[%s] Client %s | Invalid payload to write to TCP Socket!',\n this.identifier,\n clientId,\n );\n return;\n }\n\n socket.write(payload);\n }\n}\n"]}
1
+ {"version":3,"file":"base-tcp-server.helper.js","sourceRoot":"","sources":["../../../../../src/modules/network/tcp-socket/base-tcp-server.helper.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAQ7D,6DAA6D;AAC7D,MAAM,OAAO,eAAe;aACV,iBAAY,GAAG,cAAc,CAAC;aAC9B,mBAAc,GAAG,gBAAgB,CAAC;aAClC,kBAAa,GAAG,eAAe,CAAC;aAEhC,eAAU,GAAG,IAAI,GAAG,CAAS;QAC3C,IAAI,CAAC,YAAY;QACjB,IAAI,CAAC,cAAc;QACnB,IAAI,CAAC,aAAa;KACnB,CAAC,CAAC;IAEH,MAAM,CAAC,OAAO,CAAC,KAAa;QAC1B,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AAI,CAAC,UAAU,EACf,QAAQ,CACT,CAAC;YACJ,OAAO;QACT,CAAC;QAED,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IACxB,CAAC;CACF","sourcesContent":["import type { TConstValue } from '@/common/types';\nimport { type ValueOrPromise } from '@/common/types';\nimport { BaseHelper } from '@/modules/base';\nimport { getError } from '@/modules/error';\nimport { ParseUtility } from '@/utilities/parse.utility';\nimport { PromiseUtility } from '@/utilities/promise.utility';\nimport {\n type ListenOptions,\n type ServerOpts,\n type Socket as SocketClient,\n type Server as SocketServer,\n} from 'node:net';\n\n/** Where a TCP client is in the authentication handshake. */\nexport class TcpClientStates {\n static readonly UNAUTHORIZED = 'unauthorized';\n static readonly AUTHENTICATING = 'authenticating';\n static readonly AUTHENTICATED = 'authenticated';\n\n static readonly SCHEME_SET = new Set<string>([\n this.UNAUTHORIZED,\n this.AUTHENTICATING,\n this.AUTHENTICATED,\n ]);\n\n static isValid(value: string): boolean {\n return this.SCHEME_SET.has(value);\n }\n}\n\n/** Valid TCP client state values. */\nexport type TTcpClientState = TConstValue<typeof TcpClientStates>;\n\nexport interface ITcpSocketClient<SocketClientType> {\n id: string;\n socket: SocketClientType;\n state: TTcpClientState;\n subscriptions: Set<string>;\n storage: {\n connectedAt: Date;\n authenticatedAt: Date | null;\n authenticateTimeout?: ReturnType<typeof setTimeout> | null;\n [additionField: symbol | string]: any;\n };\n}\n\nexport interface ITcpSocketServerOptions<\n SocketServerOptions extends ServerOpts = ServerOpts,\n SocketServerType extends SocketServer = SocketServer,\n SocketClientType extends SocketClient = SocketClient,\n> {\n scope?: string;\n identifier: string;\n\n serverOptions: Partial<SocketServerOptions>;\n listenOptions: Partial<ListenOptions>;\n authenticateOptions: { required: boolean; duration?: number };\n\n extraEvents?: Record<\n string,\n (opts: { id: string; socket: SocketClientType; args: any }) => ValueOrPromise<void>\n >;\n\n createServerFn: (\n options: Partial<SocketServerOptions>,\n connectionListener: (socket: SocketClientType) => void,\n ) => SocketServerType;\n\n onServerReady?: (opts: { server: SocketServerType }) => void;\n onClientConnected?: (opts: { id: string; socket: SocketClientType }) => void;\n onClientData?: (opts: { id: string; socket: SocketClientType; data: Buffer | string }) => void;\n onClientClose?: (opts: { id: string; socket: SocketClientType }) => void;\n onClientError?: (opts: { id: string; socket: SocketClientType; error: Error }) => void;\n onServerError?: (opts: { server: SocketServerType; error: Error }) => void;\n}\n\nexport class BaseNetworkTcpServer<\n SocketServerOptions extends ServerOpts = ServerOpts,\n SocketServerType extends SocketServer = SocketServer,\n SocketClientType extends SocketClient = SocketClient,\n> extends BaseHelper {\n protected serverOptions: Partial<SocketServerOptions> = {};\n protected listenOptions: Partial<ListenOptions> = {};\n protected authenticateOptions: { required: boolean; duration?: number };\n\n protected clients: Record<string, ITcpSocketClient<SocketClientType>>;\n protected server: SocketServerType;\n\n protected extraEvents: Record<\n string,\n (opts: { id: string; socket: SocketClientType; args: any }) => ValueOrPromise<void>\n >;\n\n protected createServerFn: (\n options: Partial<SocketServerOptions>,\n connectionListener: (socket: SocketClientType) => void,\n ) => SocketServerType;\n\n protected onServerReady?: (opts: { server: SocketServerType }) => void;\n protected onClientConnected?: (opts: { id: string; socket: SocketClientType }) => void;\n protected onClientData?: (opts: {\n id: string;\n socket: SocketClientType;\n data: Buffer | string;\n }) => void;\n protected onClientClose?: (opts: { id: string; socket: SocketClientType }) => void;\n protected onClientError?: (opts: { id: string; socket: SocketClientType; error: Error }) => void;\n protected onServerError?: (opts: { server: SocketServerType; error: Error }) => void;\n\n constructor(\n opts: ITcpSocketServerOptions<SocketServerOptions, SocketServerType, SocketClientType>,\n ) {\n super({\n scope: opts.scope ?? opts.identifier ?? BaseNetworkTcpServer.name,\n identifier: opts.identifier,\n });\n\n // No prototype: `getClient({ id: 'constructor' })` must find nothing, not `Object`.\n this.clients = Object.create(null);\n\n this.serverOptions = opts.serverOptions;\n this.listenOptions = opts.listenOptions;\n this.authenticateOptions = opts.authenticateOptions;\n\n if (\n this.authenticateOptions.required &&\n (!this.authenticateOptions.duration || this.authenticateOptions.duration < 0)\n ) {\n throw getError({\n message:\n 'TCP Server | Invalid authenticate duration | Required duration for authenticateOptions',\n });\n }\n\n this.extraEvents = opts.extraEvents ?? {};\n\n this.createServerFn = opts.createServerFn;\n\n this.onServerReady = opts.onServerReady;\n this.onClientConnected = opts.onClientConnected;\n this.onClientData = opts.onClientData;\n this.onClientClose = opts.onClientClose;\n this.onClientError = opts.onClientError;\n this.onServerError = opts.onServerError;\n\n this.configure();\n }\n\n // Hooks run inside socket event listeners: a synchronous throw there is an uncaught exception that kills the process and skips the client-registry cleanup that follows it.\n protected invokeHook(opts: { scope: string; execution: () => void }) {\n const { scope, execution } = opts;\n\n try {\n execution();\n } catch (error) {\n this.logger.for(scope).error('Hook execution FAILED | Error: %s', error);\n }\n }\n\n configure() {\n this.server = this.createServerFn(this.serverOptions, (socket) => {\n this.onNewConnection({ socket });\n });\n\n // Without this listener a failed listen - a port already in use is the commonest boot failure there is - emits an unhandled 'error' event, which takes the whole process down with it.\n this.server.on('error', (error: Error) => {\n this.logger\n .for(this.configure.name)\n .error('TCP Socket Server error | Options: %j | Error: %s', this.listenOptions, error);\n\n this.invokeHook({\n scope: this.configure.name,\n execution: () => {\n this.onServerError?.({ server: this.server, error });\n },\n });\n });\n\n this.server.listen(this.listenOptions, () => {\n this.logger\n .for(this.configure.name)\n .info('TCP Socket Server is now listening | Options: %j', this.listenOptions);\n\n this.invokeHook({\n scope: this.configure.name,\n execution: () => {\n this.onServerReady?.({ server: this.server });\n },\n });\n });\n }\n\n onNewConnection(opts: { socket: SocketClientType }) {\n const { socket } = opts;\n\n const id = ParseUtility.getUID();\n\n socket.on('data', (data: Buffer | string) => {\n this.invokeHook({\n scope: 'onClientData',\n execution: () => {\n this.onClientData?.({ id, socket, data });\n },\n });\n });\n\n socket.on('error', (error: Error) => {\n this.logger.for('onClientConnect').error('Socket Error | ID: %s | Error: %s', id, error);\n\n this.invokeHook({\n scope: 'onClientError',\n execution: () => {\n this.onClientError?.({ id, socket, error });\n },\n });\n\n socket.end();\n });\n\n socket.on('close', (hasError: boolean) => {\n this.logger\n .for('onClientConnect')\n .info('Socket Closed | ID: %s | hasError: %s', id, hasError);\n\n this.invokeHook({\n scope: 'onClientClose',\n execution: () => {\n this.onClientClose?.({ id, socket });\n },\n });\n\n const authenticateTimeout = this.getClient({ id })?.storage?.authenticateTimeout;\n if (authenticateTimeout) {\n clearTimeout(authenticateTimeout);\n }\n\n // `delete`, not `omit`: omit rebuilds the WHOLE registry per disconnect, so a disconnect\n // storm is O(n^2) - measured at 5000 clients, 2.3s of drain with a 2.2s worst-case stall.\n delete this.clients[id];\n });\n\n for (const extraEvent in this.extraEvents) {\n socket.on(extraEvent, (args) => {\n PromiseUtility.voidExecution({\n logger: this.logger,\n scope: 'onClientConnect',\n // The async wrapper turns a SYNCHRONOUS throw from the handler into a rejection; calling it bare would throw out of this listener as an uncaught exception.\n execution: (async () => this.extraEvents[extraEvent]({ id, socket, args }))(),\n });\n });\n }\n\n this.clients[id] = {\n id,\n socket,\n state: this.authenticateOptions.required\n ? TcpClientStates.UNAUTHORIZED\n : TcpClientStates.AUTHENTICATED,\n subscriptions: new Set([]),\n storage: {\n connectedAt: new Date(),\n authenticatedAt: this.authenticateOptions.required ? null : new Date(),\n },\n };\n\n this.logger\n .for('onClientConnect')\n .info(\n 'New TCP SocketClient | Client: %s | authenticateOptions: %s %s',\n `${id} - ${socket.remoteAddress} - ${socket.remotePort} - ${socket.remoteFamily}`,\n this.authenticateOptions.required,\n this.authenticateOptions.duration,\n );\n\n this.invokeHook({\n scope: 'onClientConnected',\n execution: () => {\n this.onClientConnected?.({ id, socket });\n },\n });\n\n if (\n this.authenticateOptions.required &&\n this.authenticateOptions.duration &&\n this.authenticateOptions.duration > 0\n ) {\n const authenticateTimeout = setTimeout(() => {\n const client = this.getClient({ id });\n if (!client) {\n return;\n }\n\n client.storage.authenticateTimeout = null;\n\n if (client.state === TcpClientStates.AUTHENTICATED) {\n return;\n }\n\n this.emit({ clientId: id, payload: 'Unauthorized Client' });\n client.socket.end();\n }, this.authenticateOptions.duration);\n\n const client = this.getClient({ id });\n if (!client) {\n clearTimeout(authenticateTimeout);\n return;\n }\n\n client.storage.authenticateTimeout = authenticateTimeout;\n }\n }\n\n getClients() {\n return this.clients;\n }\n\n getClient(opts: { id: string }) {\n return this.clients?.[opts.id];\n }\n\n getServer() {\n return this.server;\n }\n\n /** Clears timers and destroys all client sockets before closing the listener - `server.close()` alone never settles while a socket stays attached. Idempotent; safe if never listened. */\n async shutdown(): Promise<void> {\n const clientsValues = Object.values(this.clients);\n for (const client of clientsValues) {\n const { authenticateTimeout } = client.storage;\n if (authenticateTimeout) {\n clearTimeout(authenticateTimeout);\n client.storage.authenticateTimeout = null;\n }\n\n client.socket.destroy();\n }\n\n this.clients = Object.create(null);\n\n const server = this.server;\n if (!server) {\n return;\n }\n\n // Not guarded on `listening`: listen() is async (DNS lookup), so a shutdown() racing startup could skip close() and leave the server bound forever; close() on a never-listened server just logs ERR_SERVER_NOT_RUNNING below.\n\n await new Promise<void>((resolve) => {\n server.close((error) => {\n if (error) {\n this.logger.for(this.shutdown.name).error('Failed to close server | Error: %s', error);\n }\n\n resolve();\n });\n });\n\n this.logger.for(this.shutdown.name).info('Server closed | Identifier: %s', this.identifier);\n }\n\n doAuthenticate(opts: { id: string; state: TTcpClientState }) {\n const { id, state } = opts;\n\n const client = this.getClient({ id });\n if (!client) {\n this.logger.for('authenticateClient').error('Client NOT FOUND | ID: %s', id);\n return;\n }\n\n client.state = state;\n\n switch (state) {\n case TcpClientStates.UNAUTHORIZED:\n case TcpClientStates.AUTHENTICATING: {\n client.storage.authenticatedAt = null;\n break;\n }\n case TcpClientStates.AUTHENTICATED: {\n client.storage.authenticatedAt = new Date();\n\n if (client.storage.authenticateTimeout) {\n clearTimeout(client.storage.authenticateTimeout);\n client.storage.authenticateTimeout = null;\n }\n break;\n }\n default: {\n break;\n }\n }\n }\n\n emit(opts: { clientId: string; payload: Buffer | string }) {\n const { clientId, payload } = opts;\n const client = this.getClient({ id: clientId });\n\n if (!client) {\n this.logger.for(this.emit.name).error('Client NOT FOUND | ID: %s', clientId);\n return;\n }\n\n const { socket } = client;\n if (!socket.writable) {\n this.logger.for(this.emit.name).error('Client NOT WRITABLE | ID: %s', clientId);\n return;\n }\n\n if (!payload?.length) {\n this.logger\n .for(this.emit.name)\n .info(\n '[%s] Client %s | Invalid payload to write to TCP Socket!',\n this.identifier,\n clientId,\n );\n return;\n }\n\n socket.write(payload);\n }\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  import { BaseHelper } from '../../base.js';
2
- import { voidExecution } from '../../../utilities/promise.utility.js';
2
+ import { PromiseUtility } from '../../../utilities/promise.utility.js';
3
3
  import dgram from 'node:dgram';
4
4
  export class NetworkUdpClient extends BaseHelper {
5
5
  constructor(opts) {
@@ -103,7 +103,7 @@ export class NetworkUdpClient extends BaseHelper {
103
103
  });
104
104
  });
105
105
  this.client.bind({ port: this.port, address: this.host }, () => {
106
- voidExecution({
106
+ PromiseUtility.voidExecution({
107
107
  logger: this.logger,
108
108
  scope: 'bind',
109
109
  // The async wrapper turns a SYNCHRONOUS throw from onBind into a rejection; calling it bare would throw out of the dgram listening listener as an uncaught exception.
@@ -1 +1 @@
1
- {"version":3,"file":"network-udp-client.helper.js","sourceRoot":"","sources":["../../../../../src/modules/network/udp-socket/network-udp-client.helper.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,KAAK,MAAM,YAAY,CAAC;AAgC/B,MAAM,OAAO,gBAAiB,SAAQ,UAAU;IAkC9C,YAAY,IAA4B;QACtC,KAAK,CAAC,EAAE,KAAK,EAAE,gBAAgB,CAAC,IAAI,EAAE,UAAU,EAAE,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC;QAErE,IAAI,CAAC,IAAI,G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C;QACL,CAAC,CAAC,CAAC;IACL,CAAC;IAED,8FAA8F;IACtF,UAAU,CAAC,IAA8C;QAC/D,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC;QAElC,IAAI,CAAC;YACH,SAAS,EAAE,CAAC;QACd,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,mCAAmC,EAAE,KAAK,CAAC,CAAC;QAC3E,CAAC;IACH,CAAC;IAED,UAAU;QACR,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;YACjB,IAAI,CAAC,MAAM;iBACR,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;iBACzB,IAAI,CAAC,wCAAwC,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;YACnE,OAAO;QACT,CAAC;QAED,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,CAAC;QAErB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;QACnB,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,kCAAkC,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;IAClG,CAAC;IAED,WAAW;QACT,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;CACF","sourcesContent":["import { type ValueOrPromise } from '@/common';\nimport { BaseHelper } from '@/modules/base';\nimport { voidExecution } from '@/utilities/promise.utility';\nimport dgram from 'node:dgram';\n\ninterface INetworkUdpClientProps {\n identifier: string;\n\n host?: string;\n port: number;\n reuseAddr?: boolean;\n\n multicastAddress?: {\n groups?: Array<string>;\n interface?: string;\n };\n\n onConnected?: (opts: { identifier: string; host?: string; port: number }) => void;\n onData?: (opts: {\n identifier: string;\n message: string | Buffer;\n remoteInfo: dgram.RemoteInfo;\n }) => void;\n onClosed?: (opts: { identifier: string; host?: string; port: number }) => void;\n onError?: (opts: { identifier: string; host?: string; port: number; error: Error }) => void;\n onBind?: (opts: {\n identifier: string;\n socket: dgram.Socket;\n host?: string;\n port: number;\n reuseAddr?: boolean;\n multicastAddress?: { groups?: Array<string>; interface?: string };\n }) => ValueOrPromise<void>;\n}\n\nexport class NetworkUdpClient extends BaseHelper {\n private host?: string;\n private port: number;\n private reuseAddr?: boolean;\n\n private multicastAddress?: {\n groups?: Array<string>;\n interface?: string;\n };\n\n private onConnected: (opts: { identifier: string; host?: string; port: number }) => void;\n private onData: (opts: {\n identifier: string;\n message: string | Buffer;\n remoteInfo: dgram.RemoteInfo;\n }) => void;\n private onClosed?: (opts: { identifier: string; host?: string; port: number }) => void;\n private onError?: (opts: {\n identifier: string;\n host?: string;\n port: number;\n error: Error;\n }) => void;\n private onBind?: (opts: {\n identifier: string;\n socket: dgram.Socket;\n host?: string;\n port: number;\n reuseAddr?: boolean;\n multicastAddress?: { groups?: Array<string>; interface?: string };\n }) => ValueOrPromise<void>;\n\n private client?: dgram.Socket | null;\n\n constructor(opts: INetworkUdpClientProps) {\n super({ scope: NetworkUdpClient.name, identifier: opts.identifier });\n\n this.host = opts.host;\n this.port = opts.port;\n this.reuseAddr = opts.reuseAddr;\n this.multicastAddress = opts.multicastAddress;\n\n this.onConnected = opts?.onConnected ?? this.handleConnected;\n this.onData = opts?.onData ?? this.handleData;\n this.onClosed = opts?.onClosed ?? this.handleClosed;\n this.onError = opts?.onError ?? this.handleError;\n this.onBind = opts?.onBind;\n }\n\n static newInstance(opts: INetworkUdpClientProps) {\n return new NetworkUdpClient(opts);\n }\n\n getClient() {\n return this.client;\n }\n\n handleConnected() {\n this.logger\n .for(this.handleConnected.name)\n .info('[%s] Successfully bind connection | Options: %j', this.identifier, {\n host: this.host,\n port: this.port,\n multicastAddress: this.multicastAddress,\n });\n }\n\n handleData(opts: { identifier: string; message: string | Buffer; remoteInfo: dgram.RemoteInfo }) {\n this.logger\n .for(this.handleData.name)\n .info('[%s][%s:%d][<==] Raw: %s', this.identifier, this.host, this.port, {\n message: opts.message,\n remoteInfo: opts.remoteInfo,\n });\n }\n\n handleClosed() {\n this.logger\n .for(this.handleClosed.name)\n .info('[%s] Closed connection UDP Server | Options: %j', this.identifier, {\n host: this.host,\n port: this.port,\n multicastAddress: this.multicastAddress,\n });\n }\n\n handleError(opts: { identifier: string; error: Error }) {\n this.logger.for(this.handleError.name).error(\n '[%s] Connection error | Options: %j | Error: %s',\n this.identifier,\n {\n host: this.host,\n port: this.port,\n },\n opts.error,\n );\n }\n\n connect() {\n if (this.client) {\n this.logger\n .for(this.connect.name)\n .info('[%s] UdpClient is already initialized!', this.identifier);\n return;\n }\n\n // Port 0 is a VALID request for an OS assigned port - only a missing / negative port is invalid.\n if (!Number.isInteger(this.port) || this.port < 0) {\n this.logger\n .for(this.connect.name)\n .info(\n '[%s] Cannot init UDP Client with invalid port | Port: %s',\n this.identifier,\n this.port,\n );\n return;\n }\n\n this.logger\n .for(this.connect.name)\n .info(\n '[%s] New network udp client | Host: %s | Port: %s | multicastAddress: %j',\n this.identifier,\n this.host,\n this.port,\n this.multicastAddress,\n );\n\n this.client = dgram.createSocket({ type: 'udp4', reuseAddr: this.reuseAddr });\n this.client.on('close', () => {\n this.invokeHook({\n scope: this.handleClosed.name,\n execution: () => {\n this.onClosed?.({ identifier: this.identifier, host: this.host, port: this.port });\n },\n });\n });\n\n this.client.on('error', (error) => {\n this.invokeHook({\n scope: this.handleError.name,\n execution: () => {\n this.onError?.({ identifier: this.identifier, host: this.host, port: this.port, error });\n },\n });\n });\n\n this.client.on('listening', () => {\n this.invokeHook({\n scope: this.handleConnected.name,\n execution: () => {\n this.onConnected?.({ identifier: this.identifier, host: this.host, port: this.port });\n },\n });\n });\n\n this.client.on('message', (message: string | Buffer, remoteInfo: dgram.RemoteInfo) => {\n this.invokeHook({\n scope: this.handleData.name,\n execution: () => {\n this.onData?.({ identifier: this.identifier, message, remoteInfo });\n },\n });\n });\n\n this.client.bind({ port: this.port, address: this.host }, () => {\n voidExecution({\n logger: this.logger,\n scope: 'bind',\n // The async wrapper turns a SYNCHRONOUS throw from onBind into a rejection; calling it bare would throw out of the dgram listening listener as an uncaught exception.\n execution: (async () =>\n this.onBind?.({\n identifier: this.identifier,\n socket: this.client!,\n host: this.host,\n port: this.port,\n reuseAddr: this.reuseAddr,\n multicastAddress: this.multicastAddress,\n }))(),\n });\n });\n }\n\n // Hooks run inside dgram event listeners: a synchronous throw there is an uncaught exception.\n private invokeHook(opts: { scope: string; execution: () => void }) {\n const { scope, execution } = opts;\n\n try {\n execution();\n } catch (error) {\n this.logger.for(scope).error('Hook execution FAILED | Error: %s', error);\n }\n }\n\n disconnect() {\n if (!this.client) {\n this.logger\n .for(this.disconnect.name)\n .info('[%s] UdpClient is not initialized yet!', this.identifier);\n return;\n }\n\n this.client?.close();\n\n this.client = null;\n this.logger.for(this.disconnect.name).info('UdpClient is destroyed! | ID: %s', this.identifier);\n }\n\n isConnected() {\n return this.client;\n }\n}\n"]}
1
+ {"version":3,"file":"network-udp-client.helper.js","sourceRoot":"","sources":["../../../../../src/modules/network/udp-socket/network-udp-client.helper.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,KAAK,MAAM,YAAY,CAAC;AAgC/B,MAAM,OAAO,gBAAiB,SAAQ,UAAU;IAkC9C,YAAY,IAA4B;QACtC,KAAK,CAAC,EAAE,KAAK,EAAE,gBAAgB,CAAC,IAAI,EAAE,UAAU,EAAE,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC;QAErE,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;QACtB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;QACtB,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC;QAChC,IAAI,CAAC,gBAAgB,GAAG,IAA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AAS,EAAE,CAAC;QACd,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,mCAAmC,EAAE,KAAK,CAAC,CAAC;QAC3E,CAAC;IACH,CAAC;IAED,UAAU;QACR,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;YACjB,IAAI,CAAC,MAAM;iBACR,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;iBACzB,IAAI,CAAC,wCAAwC,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;YACnE,OAAO;QACT,CAAC;QAED,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,CAAC;QAErB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;QACnB,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,kCAAkC,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;IAClG,CAAC;IAED,WAAW;QACT,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;CACF","sourcesContent":["import { type ValueOrPromise } from '@/common';\nimport { BaseHelper } from '@/modules/base';\nimport { PromiseUtility } from '@/utilities/promise.utility';\nimport dgram from 'node:dgram';\n\ninterface INetworkUdpClientProps {\n identifier: string;\n\n host?: string;\n port: number;\n reuseAddr?: boolean;\n\n multicastAddress?: {\n groups?: Array<string>;\n interface?: string;\n };\n\n onConnected?: (opts: { identifier: string; host?: string; port: number }) => void;\n onData?: (opts: {\n identifier: string;\n message: string | Buffer;\n remoteInfo: dgram.RemoteInfo;\n }) => void;\n onClosed?: (opts: { identifier: string; host?: string; port: number }) => void;\n onError?: (opts: { identifier: string; host?: string; port: number; error: Error }) => void;\n onBind?: (opts: {\n identifier: string;\n socket: dgram.Socket;\n host?: string;\n port: number;\n reuseAddr?: boolean;\n multicastAddress?: { groups?: Array<string>; interface?: string };\n }) => ValueOrPromise<void>;\n}\n\nexport class NetworkUdpClient extends BaseHelper {\n private host?: string;\n private port: number;\n private reuseAddr?: boolean;\n\n private multicastAddress?: {\n groups?: Array<string>;\n interface?: string;\n };\n\n private onConnected: (opts: { identifier: string; host?: string; port: number }) => void;\n private onData: (opts: {\n identifier: string;\n message: string | Buffer;\n remoteInfo: dgram.RemoteInfo;\n }) => void;\n private onClosed?: (opts: { identifier: string; host?: string; port: number }) => void;\n private onError?: (opts: {\n identifier: string;\n host?: string;\n port: number;\n error: Error;\n }) => void;\n private onBind?: (opts: {\n identifier: string;\n socket: dgram.Socket;\n host?: string;\n port: number;\n reuseAddr?: boolean;\n multicastAddress?: { groups?: Array<string>; interface?: string };\n }) => ValueOrPromise<void>;\n\n private client?: dgram.Socket | null;\n\n constructor(opts: INetworkUdpClientProps) {\n super({ scope: NetworkUdpClient.name, identifier: opts.identifier });\n\n this.host = opts.host;\n this.port = opts.port;\n this.reuseAddr = opts.reuseAddr;\n this.multicastAddress = opts.multicastAddress;\n\n this.onConnected = opts?.onConnected ?? this.handleConnected;\n this.onData = opts?.onData ?? this.handleData;\n this.onClosed = opts?.onClosed ?? this.handleClosed;\n this.onError = opts?.onError ?? this.handleError;\n this.onBind = opts?.onBind;\n }\n\n static newInstance(opts: INetworkUdpClientProps) {\n return new NetworkUdpClient(opts);\n }\n\n getClient() {\n return this.client;\n }\n\n handleConnected() {\n this.logger\n .for(this.handleConnected.name)\n .info('[%s] Successfully bind connection | Options: %j', this.identifier, {\n host: this.host,\n port: this.port,\n multicastAddress: this.multicastAddress,\n });\n }\n\n handleData(opts: { identifier: string; message: string | Buffer; remoteInfo: dgram.RemoteInfo }) {\n this.logger\n .for(this.handleData.name)\n .info('[%s][%s:%d][<==] Raw: %s', this.identifier, this.host, this.port, {\n message: opts.message,\n remoteInfo: opts.remoteInfo,\n });\n }\n\n handleClosed() {\n this.logger\n .for(this.handleClosed.name)\n .info('[%s] Closed connection UDP Server | Options: %j', this.identifier, {\n host: this.host,\n port: this.port,\n multicastAddress: this.multicastAddress,\n });\n }\n\n handleError(opts: { identifier: string; error: Error }) {\n this.logger.for(this.handleError.name).error(\n '[%s] Connection error | Options: %j | Error: %s',\n this.identifier,\n {\n host: this.host,\n port: this.port,\n },\n opts.error,\n );\n }\n\n connect() {\n if (this.client) {\n this.logger\n .for(this.connect.name)\n .info('[%s] UdpClient is already initialized!', this.identifier);\n return;\n }\n\n // Port 0 is a VALID request for an OS assigned port - only a missing / negative port is invalid.\n if (!Number.isInteger(this.port) || this.port < 0) {\n this.logger\n .for(this.connect.name)\n .info(\n '[%s] Cannot init UDP Client with invalid port | Port: %s',\n this.identifier,\n this.port,\n );\n return;\n }\n\n this.logger\n .for(this.connect.name)\n .info(\n '[%s] New network udp client | Host: %s | Port: %s | multicastAddress: %j',\n this.identifier,\n this.host,\n this.port,\n this.multicastAddress,\n );\n\n this.client = dgram.createSocket({ type: 'udp4', reuseAddr: this.reuseAddr });\n this.client.on('close', () => {\n this.invokeHook({\n scope: this.handleClosed.name,\n execution: () => {\n this.onClosed?.({ identifier: this.identifier, host: this.host, port: this.port });\n },\n });\n });\n\n this.client.on('error', (error) => {\n this.invokeHook({\n scope: this.handleError.name,\n execution: () => {\n this.onError?.({ identifier: this.identifier, host: this.host, port: this.port, error });\n },\n });\n });\n\n this.client.on('listening', () => {\n this.invokeHook({\n scope: this.handleConnected.name,\n execution: () => {\n this.onConnected?.({ identifier: this.identifier, host: this.host, port: this.port });\n },\n });\n });\n\n this.client.on('message', (message: string | Buffer, remoteInfo: dgram.RemoteInfo) => {\n this.invokeHook({\n scope: this.handleData.name,\n execution: () => {\n this.onData?.({ identifier: this.identifier, message, remoteInfo });\n },\n });\n });\n\n this.client.bind({ port: this.port, address: this.host }, () => {\n PromiseUtility.voidExecution({\n logger: this.logger,\n scope: 'bind',\n // The async wrapper turns a SYNCHRONOUS throw from onBind into a rejection; calling it bare would throw out of the dgram listening listener as an uncaught exception.\n execution: (async () =>\n this.onBind?.({\n identifier: this.identifier,\n socket: this.client!,\n host: this.host,\n port: this.port,\n reuseAddr: this.reuseAddr,\n multicastAddress: this.multicastAddress,\n }))(),\n });\n });\n }\n\n // Hooks run inside dgram event listeners: a synchronous throw there is an uncaught exception.\n private invokeHook(opts: { scope: string; execution: () => void }) {\n const { scope, execution } = opts;\n\n try {\n execution();\n } catch (error) {\n this.logger.for(scope).error('Hook execution FAILED | Error: %s', error);\n }\n }\n\n disconnect() {\n if (!this.client) {\n this.logger\n .for(this.disconnect.name)\n .info('[%s] UdpClient is not initialized yet!', this.identifier);\n return;\n }\n\n this.client?.close();\n\n this.client = null;\n this.logger.for(this.disconnect.name).info('UdpClient is destroyed! | ID: %s', this.identifier);\n }\n\n isConnected() {\n return this.client;\n }\n}\n"]}
@@ -24,28 +24,30 @@ export declare class QueryStringNestedModes {
24
24
  static readonly JSON = "json";
25
25
  }
26
26
  export type TQueryStringNestedMode = TConstValue<typeof QueryStringNestedModes>;
27
- /** How {@link toQueryString} treats the values `node:querystring` has no answer for. Both default to its behavior. */
27
+ /** How {@link QueryStringUtility.toQueryString} treats the values `node:querystring` has no answer for. Both default to its behavior. */
28
28
  export interface IQueryStringOptions {
29
29
  nullish?: TQueryStringNullishMode;
30
30
  nested?: TQueryStringNestedMode;
31
31
  }
32
- /**
33
- * `node:querystring`'s `stringify`, written out so nothing on the HTTP path carries a node builtin -
34
- * that one import is what kept the whole network layer out of a browser bundle.
35
- *
36
- * Not `new URLSearchParams(params).toString()`, which differs on four counts measured against the
37
- * original: an array becomes `a=1%2C2` instead of `a=1&a=2`, `undefined` and `null` become the
38
- * STRINGS "undefined" and "null" instead of an empty value, and a space encodes as `+` rather than
39
- * `%20`. The first changes what a server parses; the second is the same coercion that sends a header
40
- * reading "undefined".
41
- *
42
- * Diffed against `node:querystring` across 22 shapes with zero mismatches.
43
- *
44
- * `nullish: 'skip'` leaves a null or undefined pair out. `nested: 'json'` sends an object or an
45
- * array as ONE JSON parameter instead (an array does not repeat its key), so a filter object survives
46
- * the trip. The defaults keep the behavior above.
47
- */
48
- export declare const toQueryString: (opts: {
49
- params: AnyObject;
50
- } & IQueryStringOptions) => string;
32
+ export declare class QueryStringUtility {
33
+ /**
34
+ * `node:querystring`'s `stringify`, written out so nothing on the HTTP path carries a node builtin -
35
+ * that one import is what kept the whole network layer out of a browser bundle.
36
+ *
37
+ * Not `new URLSearchParams(params).toString()`, which differs on four counts measured against the
38
+ * original: an array becomes `a=1%2C2` instead of `a=1&a=2`, `undefined` and `null` become the
39
+ * STRINGS "undefined" and "null" instead of an empty value, and a space encodes as `+` rather than
40
+ * `%20`. The first changes what a server parses; the second is the same coercion that sends a header
41
+ * reading "undefined".
42
+ *
43
+ * Diffed against `node:querystring` across 22 shapes with zero mismatches.
44
+ *
45
+ * `nullish: 'skip'` leaves a null or undefined pair out. `nested: 'json'` sends an object or an
46
+ * array as ONE JSON parameter instead (an array does not repeat its key), so a filter object survives
47
+ * the trip. The defaults keep the behavior above.
48
+ */
49
+ static toQueryString(opts: {
50
+ params: AnyObject;
51
+ } & IQueryStringOptions): string;
52
+ }
51
53
  //# sourceMappingURL=query-string.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"query-string.d.ts","sourceRoot":"","sources":["../../../../../src/modules/network/utilities/query-string.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAElE,oGAAoG;AACpG,qBAAa,qBAAqB;IAChC,2CAA2C;IAC3C,MAAM,CAAC,QAAQ,CAAC,KAAK,OAAO;IAC5B,yBAAyB;IACzB,MAAM,CAAC,QAAQ,CAAC,IAAI,OAAO;IAC3B,oCAAoC;IACpC,MAAM,CAAC,QAAQ,CAAC,MAAM,OAAO;CAC9B;AAED,kDAAkD;AAClD,qBAAa,uBAAuB;IAClC,2DAA2D;IAC3D,MAAM,CAAC,QAAQ,CAAC,KAAK,WAAW;IAChC,4BAA4B;IAC5B,MAAM,CAAC,QAAQ,CAAC,IAAI,UAAU;CAC/B;AACD,MAAM,MAAM,uBAAuB,GAAG,WAAW,CAAC,OAAO,uBAAuB,CAAC,CAAC;AAElF,gDAAgD;AAChD,qBAAa,sBAAsB;IACjC,uFAAuF;IACvF,MAAM,CAAC,QAAQ,CAAC,IAAI,UAAU;IAC9B,2GAA2G;IAC3G,MAAM,CAAC,QAAQ,CAAC,IAAI,UAAU;CAC/B;AACD,MAAM,MAAM,sBAAsB,GAAG,WAAW,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAEhF,sHAAsH;AACtH,MAAM,WAAW,mBAAmB;IAClC,OAAO,CAAC,EAAE,uBAAuB,CAAC;IAClC,MAAM,CAAC,EAAE,sBAAsB,CAAC;CACjC;AAED;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,aAAa,GAAI,MAAM;IAAE,MAAM,EAAE,SAAS,CAAA;CAAE,GAAG,mBAAmB,KAAG,MAkDjF,CAAC"}
1
+ {"version":3,"file":"query-string.d.ts","sourceRoot":"","sources":["../../../../../src/modules/network/utilities/query-string.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAElE,oGAAoG;AACpG,qBAAa,qBAAqB;IAChC,2CAA2C;IAC3C,MAAM,CAAC,QAAQ,CAAC,KAAK,OAAO;IAC5B,yBAAyB;IACzB,MAAM,CAAC,QAAQ,CAAC,IAAI,OAAO;IAC3B,oCAAoC;IACpC,MAAM,CAAC,QAAQ,CAAC,MAAM,OAAO;CAC9B;AAED,kDAAkD;AAClD,qBAAa,uBAAuB;IAClC,2DAA2D;IAC3D,MAAM,CAAC,QAAQ,CAAC,KAAK,WAAW;IAChC,4BAA4B;IAC5B,MAAM,CAAC,QAAQ,CAAC,IAAI,UAAU;CAC/B;AACD,MAAM,MAAM,uBAAuB,GAAG,WAAW,CAAC,OAAO,uBAAuB,CAAC,CAAC;AAElF,gDAAgD;AAChD,qBAAa,sBAAsB;IACjC,uFAAuF;IACvF,MAAM,CAAC,QAAQ,CAAC,IAAI,UAAU;IAC9B,2GAA2G;IAC3G,MAAM,CAAC,QAAQ,CAAC,IAAI,UAAU;CAC/B;AACD,MAAM,MAAM,sBAAsB,GAAG,WAAW,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAEhF,yIAAyI;AACzI,MAAM,WAAW,mBAAmB;IAClC,OAAO,CAAC,EAAE,uBAAuB,CAAC;IAClC,MAAM,CAAC,EAAE,sBAAsB,CAAC;CACjC;AAED,qBAAa,kBAAkB;IAC7B;;;;;;;;;;;;;;;OAeG;IACH,MAAM,CAAC,aAAa,CAAC,IAAI,EAAE;QAAE,MAAM,EAAE,SAAS,CAAA;KAAE,GAAG,mBAAmB,GAAG,MAAM;CAmDhF"}
@@ -21,54 +21,56 @@ export class QueryStringNestedModes {
21
21
  /** One JSON-encoded parameter (`ids=[1,2]`, `filter={"where":{}}`), the shape a JSON filter travels in. */
22
22
  static { this.JSON = 'json'; }
23
23
  }
24
- /**
25
- * `node:querystring`'s `stringify`, written out so nothing on the HTTP path carries a node builtin -
26
- * that one import is what kept the whole network layer out of a browser bundle.
27
- *
28
- * Not `new URLSearchParams(params).toString()`, which differs on four counts measured against the
29
- * original: an array becomes `a=1%2C2` instead of `a=1&a=2`, `undefined` and `null` become the
30
- * STRINGS "undefined" and "null" instead of an empty value, and a space encodes as `+` rather than
31
- * `%20`. The first changes what a server parses; the second is the same coercion that sends a header
32
- * reading "undefined".
33
- *
34
- * Diffed against `node:querystring` across 22 shapes with zero mismatches.
35
- *
36
- * `nullish: 'skip'` leaves a null or undefined pair out. `nested: 'json'` sends an object or an
37
- * array as ONE JSON parameter instead (an array does not repeat its key), so a filter object survives
38
- * the trip. The defaults keep the behavior above.
39
- */
40
- export const toQueryString = (opts) => {
41
- const { params, nullish = QueryStringNullishModes.EMPTY, nested = QueryStringNestedModes.DROP, } = opts;
42
- const parts = [];
43
- const isSkipped = (value) => nullish === QueryStringNullishModes.SKIP && (value === null || value === undefined);
44
- const isJson = nested === QueryStringNestedModes.JSON;
45
- // A primitive only. `querystring` drops an object or a nested array to an empty value rather than
46
- // stringifying it, and a caller that passed one meant something this format cannot carry anyway.
47
- const encode = (value) => value === null || value === undefined || typeof value === 'object'
48
- ? ''
49
- : encodeURIComponent(String(value));
50
- const entries = Object.entries(params);
51
- for (const [key, value] of entries) {
52
- const name = encodeURIComponent(key);
53
- if (isSkipped(value)) {
54
- continue;
55
- }
56
- if (isJson && typeof value === 'object' && value !== null) {
57
- parts.push(`${name}${QueryStringSeparators.ASSIGN}${encodeURIComponent(JSON.stringify(value))}`);
58
- continue;
59
- }
60
- // An array repeats the key, which is what a server reading a list expects.
61
- if (Array.isArray(value)) {
62
- for (const entry of value) {
63
- if (isSkipped(entry)) {
64
- continue;
24
+ export class QueryStringUtility {
25
+ /**
26
+ * `node:querystring`'s `stringify`, written out so nothing on the HTTP path carries a node builtin -
27
+ * that one import is what kept the whole network layer out of a browser bundle.
28
+ *
29
+ * Not `new URLSearchParams(params).toString()`, which differs on four counts measured against the
30
+ * original: an array becomes `a=1%2C2` instead of `a=1&a=2`, `undefined` and `null` become the
31
+ * STRINGS "undefined" and "null" instead of an empty value, and a space encodes as `+` rather than
32
+ * `%20`. The first changes what a server parses; the second is the same coercion that sends a header
33
+ * reading "undefined".
34
+ *
35
+ * Diffed against `node:querystring` across 22 shapes with zero mismatches.
36
+ *
37
+ * `nullish: 'skip'` leaves a null or undefined pair out. `nested: 'json'` sends an object or an
38
+ * array as ONE JSON parameter instead (an array does not repeat its key), so a filter object survives
39
+ * the trip. The defaults keep the behavior above.
40
+ */
41
+ static toQueryString(opts) {
42
+ const { params, nullish = QueryStringNullishModes.EMPTY, nested = QueryStringNestedModes.DROP, } = opts;
43
+ const parts = [];
44
+ const isSkipped = (value) => nullish === QueryStringNullishModes.SKIP && (value === null || value === undefined);
45
+ const isJson = nested === QueryStringNestedModes.JSON;
46
+ // A primitive only. `querystring` drops an object or a nested array to an empty value rather than
47
+ // stringifying it, and a caller that passed one meant something this format cannot carry anyway.
48
+ const encode = (value) => value === null || value === undefined || typeof value === 'object'
49
+ ? ''
50
+ : encodeURIComponent(String(value));
51
+ const entries = Object.entries(params);
52
+ for (const [key, value] of entries) {
53
+ const name = encodeURIComponent(key);
54
+ if (isSkipped(value)) {
55
+ continue;
56
+ }
57
+ if (isJson && typeof value === 'object' && value !== null) {
58
+ parts.push(`${name}${QueryStringSeparators.ASSIGN}${encodeURIComponent(JSON.stringify(value))}`);
59
+ continue;
60
+ }
61
+ // An array repeats the key, which is what a server reading a list expects.
62
+ if (Array.isArray(value)) {
63
+ for (const entry of value) {
64
+ if (isSkipped(entry)) {
65
+ continue;
66
+ }
67
+ parts.push(`${name}${QueryStringSeparators.ASSIGN}${encode(entry)}`);
65
68
  }
66
- parts.push(`${name}${QueryStringSeparators.ASSIGN}${encode(entry)}`);
69
+ continue;
67
70
  }
68
- continue;
71
+ parts.push(`${name}${QueryStringSeparators.ASSIGN}${encode(value)}`);
69
72
  }
70
- parts.push(`${name}${QueryStringSeparators.ASSIGN}${encode(value)}`);
73
+ return parts.join(QueryStringSeparators.PAIR);
71
74
  }
72
- return parts.join(QueryStringSeparators.PAIR);
73
- };
75
+ }
74
76
  //# sourceMappingURL=query-string.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"query-string.js","sourceRoot":"","sources":["../../../../../src/modules/network/utilities/query-string.ts"],"names":[],"mappings":"AAEA,oGAAoG;AACpG,MAAM,OAAO,qBAAqB;IAChC,2CAA2C;aAC3B,UAAK,GAAG,GAAG,CAAC;IAC5B,yBAAyB;aACT,SAAI,GAAG,GAAG,CAAC;IAC3B,oCAAoC;aACpB,WAAM,GAAG,GAAG,CAAC;;AAG/B,kDAAkD;AAClD,MAAM,OAAO,uBAAuB;IAClC,2DAA2D;aAC3C,UAAK,GAAG,OAAO,CAAC;IAChC,4BAA4B;aACZ,SAAI,GAAG,MAAM,CAAC;;AAIhC,gDAAgD;AAChD,MAAM,OAAO,s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M,GAAG,kBAAkB,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,CACrF,CAAC;YACF,SAAS;QACX,CAAC;QAED,2EAA2E;QAC3E,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YACzB,KAAK,MAAM,KAAK,IAAI,KAAK,EAAE,CAAC;gBAC1B,IAAI,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC;oBACrB,SAAS;gBACX,CAAC;gBAED,KAAK,CAAC,IAAI,CAAC,GAAG,IAAI,GAAG,qBAAqB,CAAC,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;YACvE,CAAC;YAED,SAAS;QACX,CAAC;QAED,KAAK,CAAC,IAAI,CAAC,GAAG,IAAI,GAAG,qBAAqB,CAAC,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IACvE,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,CAAC;AAChD,CAAC,CAAC","sourcesContent":["import { type AnyObject, type TConstValue } from '@/common/types';\n\n/** The punctuation of a query string, named so a reader sees the role rather than the character. */\nexport class QueryStringSeparators {\n /** Between the path and the first pair. */\n static readonly START = '?';\n /** Between two pairs. */\n static readonly PAIR = '&';\n /** Between a name and its value. */\n static readonly ASSIGN = '=';\n}\n\n/** What a `null` or `undefined` value becomes. */\nexport class QueryStringNullishModes {\n /** An empty value (`a=`): what `node:querystring` does. */\n static readonly EMPTY = 'empty';\n /** The pair is left out. */\n static readonly SKIP = 'skip';\n}\nexport type TQueryStringNullishMode = TConstValue<typeof QueryStringNullishModes>;\n\n/** What an object or an array value becomes. */\nexport class QueryStringNestedModes {\n /** An empty value (an array repeats its key instead): what `node:querystring` does. */\n static readonly DROP = 'drop';\n /** One JSON-encoded parameter (`ids=[1,2]`, `filter={\"where\":{}}`), the shape a JSON filter travels in. */\n static readonly JSON = 'json';\n}\nexport type TQueryStringNestedMode = TConstValue<typeof QueryStringNestedModes>;\n\n/** How {@link toQueryString} treats the values `node:querystring` has no answer for. Both default to its behavior. */\nexport interface IQueryStringOptions {\n nullish?: TQueryStringNullishMode;\n nested?: TQueryStringNestedMode;\n}\n\n/**\n * `node:querystring`'s `stringify`, written out so nothing on the HTTP path carries a node builtin -\n * that one import is what kept the whole network layer out of a browser bundle.\n *\n * Not `new URLSearchParams(params).toString()`, which differs on four counts measured against the\n * original: an array becomes `a=1%2C2` instead of `a=1&a=2`, `undefined` and `null` become the\n * STRINGS \"undefined\" and \"null\" instead of an empty value, and a space encodes as `+` rather than\n * `%20`. The first changes what a server parses; the second is the same coercion that sends a header\n * reading \"undefined\".\n *\n * Diffed against `node:querystring` across 22 shapes with zero mismatches.\n *\n * `nullish: 'skip'` leaves a null or undefined pair out. `nested: 'json'` sends an object or an\n * array as ONE JSON parameter instead (an array does not repeat its key), so a filter object survives\n * the trip. The defaults keep the behavior above.\n */\nexport const toQueryString = (opts: { params: AnyObject } & IQueryStringOptions): string => {\n const {\n params,\n nullish = QueryStringNullishModes.EMPTY,\n nested = QueryStringNestedModes.DROP,\n } = opts;\n const parts: string[] = [];\n const isSkipped = (value: unknown) =>\n nullish === QueryStringNullishModes.SKIP && (value === null || value === undefined);\n const isJson = nested === QueryStringNestedModes.JSON;\n\n // A primitive only. `querystring` drops an object or a nested array to an empty value rather than\n // stringifying it, and a caller that passed one meant something this format cannot carry anyway.\n const encode = (value: unknown) =>\n value === null || value === undefined || typeof value === 'object'\n ? ''\n : encodeURIComponent(String(value));\n\n const entries = Object.entries(params);\n for (const [key, value] of entries) {\n const name = encodeURIComponent(key);\n\n if (isSkipped(value)) {\n continue;\n }\n\n if (isJson && typeof value === 'object' && value !== null) {\n parts.push(\n `${name}${QueryStringSeparators.ASSIGN}${encodeURIComponent(JSON.stringify(value))}`,\n );\n continue;\n }\n\n // An array repeats the key, which is what a server reading a list expects.\n if (Array.isArray(value)) {\n for (const entry of value) {\n if (isSkipped(entry)) {\n continue;\n }\n\n parts.push(`${name}${QueryStringSeparators.ASSIGN}${encode(entry)}`);\n }\n\n continue;\n }\n\n parts.push(`${name}${QueryStringSeparators.ASSIGN}${encode(value)}`);\n }\n\n return parts.join(QueryStringSeparators.PAIR);\n};\n"]}
1
+ {"version":3,"file":"query-string.js","sourceRoot":"","sources":["../../../../../src/modules/network/utilities/query-string.ts"],"names":[],"mappings":"AAEA,oGAAoG;AACpG,MAAM,OAAO,qBAAqB;IAChC,2CAA2C;aAC3B,UAAK,GAAG,GAAG,CAAC;IAC5B,yBAAyB;aACT,SAAI,GAAG,GAAG,CAAC;IAC3B,oCAAoC;aACpB,WAAM,GAAG,GAAG,CAAC;;AAG/B,kDAAkD;AAClD,MAAM,OAAO,uBAAuB;IAClC,2DAA2D;aAC3C,UAAK,GAAG,OAAO,CAAC;IAChC,4BAA4B;aACZ,SAAI,GAAG,MAAM,CAAC;;AAIhC,gDAAgD;AAChD,MAAM,OAAO,sBAAsB;IACjC,uFAAuF;aACvE,SAAI,GAAG,MAAM,CAAC;IAC9B,2GAA2G;aAC3F,SAAI,GAAG,MAAM,CAAC;;AAUhC,MAAM,OAAO,kBAAkB;IAC7B;;;;;;;;;;;;;;;OAeG;IACH,MAAM,CAAC,aAAa,CAAC,IAAiD;QACpE,MAAM,EACJ,MAAM,EACN,OAAO,GAAG,uBAAuB,CAAC,KAAK,EACvC,MAAM,GAAG,sBAAsB,CAAC,IAAI,GACrC,GAAG,IAAI,CAAC;QACT,MAAM,KAAK,GAAa,EAAE,CAAC;QAC3B,MAAM,SAAS,GAAG,CAAC,KAAc,EAAE,EAAE,CACnC,OAAO,KAAK,uBAAuB,CAAC,IAAI,IAAI,CAAC,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,CAAC,CAAC;QACtF,MAAM,MAAM,GAAG,MAAM,KAAK,sBAAsB,CAAC,IAAI,CAAC;QAEtD,kGAAkG;QAClG,iGAAiG;QACjG,MAAM,MAAM,GAAG,CA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,qBAAqB,CAAC,IAAI,CAAC,CAAC;IAChD,CAAC;CACF","sourcesContent":["import { type AnyObject, type TConstValue } from '@/common/types';\n\n/** The punctuation of a query string, named so a reader sees the role rather than the character. */\nexport class QueryStringSeparators {\n /** Between the path and the first pair. */\n static readonly START = '?';\n /** Between two pairs. */\n static readonly PAIR = '&';\n /** Between a name and its value. */\n static readonly ASSIGN = '=';\n}\n\n/** What a `null` or `undefined` value becomes. */\nexport class QueryStringNullishModes {\n /** An empty value (`a=`): what `node:querystring` does. */\n static readonly EMPTY = 'empty';\n /** The pair is left out. */\n static readonly SKIP = 'skip';\n}\nexport type TQueryStringNullishMode = TConstValue<typeof QueryStringNullishModes>;\n\n/** What an object or an array value becomes. */\nexport class QueryStringNestedModes {\n /** An empty value (an array repeats its key instead): what `node:querystring` does. */\n static readonly DROP = 'drop';\n /** One JSON-encoded parameter (`ids=[1,2]`, `filter={\"where\":{}}`), the shape a JSON filter travels in. */\n static readonly JSON = 'json';\n}\nexport type TQueryStringNestedMode = TConstValue<typeof QueryStringNestedModes>;\n\n/** How {@link QueryStringUtility.toQueryString} treats the values `node:querystring` has no answer for. Both default to its behavior. */\nexport interface IQueryStringOptions {\n nullish?: TQueryStringNullishMode;\n nested?: TQueryStringNestedMode;\n}\n\nexport class QueryStringUtility {\n /**\n * `node:querystring`'s `stringify`, written out so nothing on the HTTP path carries a node builtin -\n * that one import is what kept the whole network layer out of a browser bundle.\n *\n * Not `new URLSearchParams(params).toString()`, which differs on four counts measured against the\n * original: an array becomes `a=1%2C2` instead of `a=1&a=2`, `undefined` and `null` become the\n * STRINGS \"undefined\" and \"null\" instead of an empty value, and a space encodes as `+` rather than\n * `%20`. The first changes what a server parses; the second is the same coercion that sends a header\n * reading \"undefined\".\n *\n * Diffed against `node:querystring` across 22 shapes with zero mismatches.\n *\n * `nullish: 'skip'` leaves a null or undefined pair out. `nested: 'json'` sends an object or an\n * array as ONE JSON parameter instead (an array does not repeat its key), so a filter object survives\n * the trip. The defaults keep the behavior above.\n */\n static toQueryString(opts: { params: AnyObject } & IQueryStringOptions): string {\n const {\n params,\n nullish = QueryStringNullishModes.EMPTY,\n nested = QueryStringNestedModes.DROP,\n } = opts;\n const parts: string[] = [];\n const isSkipped = (value: unknown) =>\n nullish === QueryStringNullishModes.SKIP && (value === null || value === undefined);\n const isJson = nested === QueryStringNestedModes.JSON;\n\n // A primitive only. `querystring` drops an object or a nested array to an empty value rather than\n // stringifying it, and a caller that passed one meant something this format cannot carry anyway.\n const encode = (value: unknown) =>\n value === null || value === undefined || typeof value === 'object'\n ? ''\n : encodeURIComponent(String(value));\n\n const entries = Object.entries(params);\n for (const [key, value] of entries) {\n const name = encodeURIComponent(key);\n\n if (isSkipped(value)) {\n continue;\n }\n\n if (isJson && typeof value === 'object' && value !== null) {\n parts.push(\n `${name}${QueryStringSeparators.ASSIGN}${encodeURIComponent(JSON.stringify(value))}`,\n );\n continue;\n }\n\n // An array repeats the key, which is what a server reading a list expects.\n if (Array.isArray(value)) {\n for (const entry of value) {\n if (isSkipped(entry)) {\n continue;\n }\n\n parts.push(`${name}${QueryStringSeparators.ASSIGN}${encode(entry)}`);\n }\n\n continue;\n }\n\n parts.push(`${name}${QueryStringSeparators.ASSIGN}${encode(value)}`);\n }\n\n return parts.join(QueryStringSeparators.PAIR);\n }\n}\n"]}
@@ -18,14 +18,4 @@ declare module '@venizia/ignis-inversion' {
18
18
  interface IErrorKeyRegistry extends TRegisterErrors<typeof UrlSafetyErrors> {
19
19
  }
20
20
  }
21
- /**
22
- * True when the url will never be allowed, whatever happens next: a bad scheme, a non-public
23
- * address, a host outside the allow-list, a malformed url, or too many hops. Retrying any of those
24
- * repeats the same rejection - drop the work instead.
25
- *
26
- * A timeout, a DNS failure or a 5xx answers `false`: those are worth another attempt.
27
- */
28
- export declare const isUrlRefusedError: (opts: {
29
- error: unknown;
30
- }) => boolean;
31
21
  //# sourceMappingURL=errors.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../../../../../src/modules/network/utilities/url-safety/common/errors.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAoB,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAGlF;;;;GAIG;AACH,eAAO,MAAM,eAAe;;;;;;;;;CAMyB,CAAC;AAEtD,OAAO,QAAQ,0BAA0B,CAAC;IACxC,UAAU,iBAAkB,SAAQ,eAAe,CAAC,OAAO,eAAe,CAAC;KAAG;CAC/E;AAED;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB,GAAI,MAAM;IAAE,KAAK,EAAE,OAAO,CAAA;CAAE,KAAG,OAG5D,CAAC"}
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../../../../../src/modules/network/utilities/url-safety/common/errors.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAoB,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAGlF;;;;GAIG;AACH,eAAO,MAAM,eAAe;;;;;;;;;CAMyB,CAAC;AAEtD,OAAO,QAAQ,0BAA0B,CAAC;IACxC,UAAU,iBAAkB,SAAQ,eAAe,CAAC,OAAO,eAAe,CAAC;KAAG;CAC/E"}
@@ -12,15 +12,4 @@ export const UrlSafetyErrors = {
12
12
  category: ErrorScopes.BUSINESS,
13
13
  },
14
14
  };
15
- /**
16
- * True when the url will never be allowed, whatever happens next: a bad scheme, a non-public
17
- * address, a host outside the allow-list, a malformed url, or too many hops. Retrying any of those
18
- * repeats the same rejection - drop the work instead.
19
- *
20
- * A timeout, a DNS failure or a 5xx answers `false`: those are worth another attempt.
21
- */
22
- export const isUrlRefusedError = (opts) => {
23
- const source = opts.error;
24
- return source?.normalized?.code === UrlSafetyErrors.URL_REFUSED.message.code;
25
- };
26
15
  //# sourceMappingURL=errors.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../../../../../src/modules/network/utilities/url-safety/common/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAE1C,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEvD;;;;GAIG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,WAAW,EAAE;QACX,OAAO,EAAE,EAAE,IAAI,EAAE,kCAAkC,EAAE,IAAI,EAAE,6BAA6B,EAAE;QAC1F,UAAU,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU;QAC5C,QAAQ,EAAE,WAAW,CAAC,QAAQ;KAC/B;CACkD,CAAC;AAMtD;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,IAAwB,EAAW,EAAE;IACrE,MAAM,MAAM,GAAG,IAAI,CAAC,KAA2C,CAAC;IAChE,OAAO,MAAM,EAAE,UAAU,EAAE,IAAI,KAAK,eAAe,CAAC,WAAW,CAAC,OAAO,CAAC,IAAI,CAAC;AAC/E,CAAC,CAAC","sourcesContent":["import { HTTP } from '@/common/constants';\nimport type { TErrorDefinition, TRegisterErrors } from '@venizia/ignis-inversion';\nimport { ErrorScopes } from '@venizia/ignis-inversion';\n\n/**\n * A url the policy refuses is refused forever - the same url will never be allowed. A caller that\n * retries on failure has to tell that apart from a host that timed out, or it retries a rejection\n * and turns the guard into a repeat scanner.\n */\nexport const UrlSafetyErrors = {\n URL_REFUSED: {\n message: { text: 'Url refused by the safety policy', code: 'core.url_safety.url_refused' },\n statusCode: HTTP.ResultCodes.RS_4.BadRequest,\n category: ErrorScopes.BUSINESS,\n },\n} as const satisfies Record<string, TErrorDefinition>;\n\ndeclare module '@venizia/ignis-inversion' {\n interface IErrorKeyRegistry extends TRegisterErrors<typeof UrlSafetyErrors> {}\n}\n\n/**\n * True when the url will never be allowed, whatever happens next: a bad scheme, a non-public\n * address, a host outside the allow-list, a malformed url, or too many hops. Retrying any of those\n * repeats the same rejection - drop the work instead.\n *\n * A timeout, a DNS failure or a 5xx answers `false`: those are worth another attempt.\n */\nexport const isUrlRefusedError = (opts: { error: unknown }): boolean => {\n const source = opts.error as { normalized?: { code?: string } };\n return source?.normalized?.code === UrlSafetyErrors.URL_REFUSED.message.code;\n};\n"]}
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../../../../../src/modules/network/utilities/url-safety/common/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAE1C,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEvD;;;;GAIG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,WAAW,EAAE;QACX,OAAO,EAAE,EAAE,IAAI,EAAE,kCAAkC,EAAE,IAAI,EAAE,6BAA6B,EAAE;QAC1F,UAAU,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU;QAC5C,QAAQ,EAAE,WAAW,CAAC,QAAQ;KAC/B;CACkD,CAAC","sourcesContent":["import { HTTP } from '@/common/constants';\nimport type { TErrorDefinition, TRegisterErrors } from '@venizia/ignis-inversion';\nimport { ErrorScopes } from '@venizia/ignis-inversion';\n\n/**\n * A url the policy refuses is refused forever - the same url will never be allowed. A caller that\n * retries on failure has to tell that apart from a host that timed out, or it retries a rejection\n * and turns the guard into a repeat scanner.\n */\nexport const UrlSafetyErrors = {\n URL_REFUSED: {\n message: { text: 'Url refused by the safety policy', code: 'core.url_safety.url_refused' },\n statusCode: HTTP.ResultCodes.RS_4.BadRequest,\n category: ErrorScopes.BUSINESS,\n },\n} as const satisfies Record<string, TErrorDefinition>;\n\ndeclare module '@venizia/ignis-inversion' {\n interface IErrorKeyRegistry extends TRegisterErrors<typeof UrlSafetyErrors> {}\n}\n"]}
@@ -23,6 +23,16 @@ export declare class UrlPolicy {
23
23
  url: string;
24
24
  policy?: IUrlSafetyPolicy;
25
25
  }): URL;
26
+ /**
27
+ * True when the url will never be allowed, whatever happens next: a bad scheme, a non-public
28
+ * address, a host outside the allow-list, a malformed url, or too many hops. Retrying any of those
29
+ * repeats the same rejection - drop the work instead.
30
+ *
31
+ * A timeout, a DNS failure or a 5xx answers `false`: those are worth another attempt.
32
+ */
33
+ static isRefusedError(opts: {
34
+ error: unknown;
35
+ }): boolean;
26
36
  }
27
37
  export { UrlSafetyDefaults, UrlSchemes };
28
38
  export type { IUrlSafetyPolicy };
@@ -1 +1 @@
1
- {"version":3,"file":"policy.d.ts","sourceRoot":"","sources":["../../../../../../src/modules/network/utilities/url-safety/policy.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEnE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAEvD,+EAA+E;AAC/E,qBAAa,SAAS;IACpB,4GAA4G;IAC5G,OAAO,CAAC,MAAM,CAAC,eAAe;IA0B9B;;;OAGG;IACH,MAAM,CAAC,kBAAkB,CAAC,IAAI,EAAE;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO;IAoC7D,6FAA6F;IAC7F,MAAM,CAAC,eAAe,CAAC,IAAI,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAA;KAAE,GAAG,MAAM;IAK1D;;;OAGG;IACH,MAAM,CAAC,aAAa,CAAC,IAAI,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,gBAAgB,CAAA;KAAE,GAAG,GAAG;CA0C5E;AAED,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,CAAC;AACzC,YAAY,EAAE,gBAAgB,EAAE,CAAC"}
1
+ {"version":3,"file":"policy.d.ts","sourceRoot":"","sources":["../../../../../../src/modules/network/utilities/url-safety/policy.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEnE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAEvD,+EAA+E;AAC/E,qBAAa,SAAS;IACpB,4GAA4G;IAC5G,OAAO,CAAC,MAAM,CAAC,eAAe;IA0B9B;;;OAGG;IACH,MAAM,CAAC,kBAAkB,CAAC,IAAI,EAAE;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO;IAoC7D,6FAA6F;IAC7F,MAAM,CAAC,eAAe,CAAC,IAAI,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAA;KAAE,GAAG,MAAM;IAK1D;;;OAGG;IACH,MAAM,CAAC,aAAa,CAAC,IAAI,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,gBAAgB,CAAA;KAAE,GAAG,GAAG;IA2C3E;;;;;;OAMG;IACH,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE;QAAE,KAAK,EAAE,OAAO,CAAA;KAAE,GAAG,OAAO;CAIzD;AAED,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,CAAC;AACzC,YAAY,EAAE,gBAAgB,EAAE,CAAC"}
@@ -104,6 +104,17 @@ export class UrlPolicy {
104
104
  }
105
105
  return parsed;
106
106
  }
107
+ /**
108
+ * True when the url will never be allowed, whatever happens next: a bad scheme, a non-public
109
+ * address, a host outside the allow-list, a malformed url, or too many hops. Retrying any of those
110
+ * repeats the same rejection - drop the work instead.
111
+ *
112
+ * A timeout, a DNS failure or a 5xx answers `false`: those are worth another attempt.
113
+ */
114
+ static isRefusedError(opts) {
115
+ const source = opts.error;
116
+ return source?.normalized?.code === UrlSafetyErrors.URL_REFUSED.message.code;
117
+ }
107
118
  }
108
119
  export { UrlSafetyDefaults, UrlSchemes };
109
120
  //# sourceMappingURL=policy.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"policy.js","sourceRoot":"","sources":["../../../../../../src/modules/network/utilities/url-safety/policy.ts"],"names":[],"mappings":"AAAA,8FAA8F;AAC9F,gGAAgG;AAChG,gGAAgG;AAChG,iBAAiB;AAEjB,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AA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C,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC9C,MAAM,QAAQ,CAAC;gBACb,KAAK,EAAE,eAAe,CAAC,WAAW;gBAClC,OAAO,EAAE,+CAA+C,MAAM,CAAC,QAAQ,eAAe,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;aAClH,CAAC,CAAC;QACL,CAAC;QAED,IAAI,MAAM,EAAE,YAAY,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC3E,MAAM,QAAQ,CAAC;gBACb,KAAK,EAAE,eAAe,CAAC,WAAW;gBAClC,OAAO,EAAE,yDAAyD,MAAM,CAAC,QAAQ,EAAE;aACpF,CAAC,CAAC;QACL,CAAC;QAED,MAAM,OAAO,GAAG,SAAS,CAAC,eAAe,CAAC,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC;QACzE,MAAM,gBAAgB,GAAG,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;QAE3E,IAAI,CAAC,mBAAmB,IAAI,gBAAgB,IAAI,SAAS,CAAC,kBAAkB,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;YAC1F,MAAM,QAAQ,CAAC;gBACb,KAAK,EAAE,eAAe,CAAC,WAAW;gBAClC,OAAO,EAAE,iEAAiE,OAAO,EAAE;aACpF,CAAC,CAAC;QACL,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AAED,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,CAAC","sourcesContent":["// The browser-pure half of the guard: a url and a literal address are decided with string and\n// number work alone. Resolving a hostname needs `node:dns` and lives in `ingest.ts`, which this\n// file must never import - `policy.ts` is re-exported from the `./core` subpath and is gated by\n// `make purity`.\n\nimport { getError } from '@/modules/error';\nimport { UrlSafetyDefaults, UrlSchemes } from './common/constants';\nimport { UrlSafetyErrors } from './common/errors';\nimport type { IUrlSafetyPolicy } from './common/types';\n\n/** Everything about a url that can be decided without touching the network. */\nexport class UrlPolicy {\n /** A dotted-quad that is not routable on the public internet. An unparseable input counts as non-public. */\n private static isNonPublicIPv4(opts: { address: string }): boolean {\n const parts = opts.address.split('.').map(Number);\n\n if (\n parts.length !== 4 ||\n parts.some((part) => !Number.isInteger(part) || part < 0 || part > 255)\n ) {\n return true;\n }\n\n const [first, second] = parts;\n\n return (\n first === 0 || // this host\n first === 10 || // private\n first === 127 || // loopback\n (first === 100 && second >= 64 && second <= 127) || // carrier-grade NAT\n (first === 169 && second === 254) || // link-local, and the cloud metadata address\n (first === 172 && second >= 16 && second <= 31) || // private\n (first === 192 && second === 0) || // IETF protocol assignments\n (first === 192 && second === 168) || // private\n (first === 198 && (second === 18 || second === 19)) || // benchmarking\n first >= 224 // multicast and reserved\n );\n }\n\n /**\n * An address that must never be reached with an untrusted url. Anything unrecognised answers\n * `true`: a guard that fails open on a string it cannot parse is not a guard.\n */\n static isNonPublicAddress(opts: { address: string }): boolean {\n const normalized = opts.address.toLowerCase().split('%')[0];\n\n if (!normalized.includes(':')) {\n return UrlPolicy.isNonPublicIPv4({ address: normalized });\n }\n\n // An IPv4 address wearing an IPv6 coat walks past every naive v6 check. Both spellings must be\n // unwrapped: `new URL` rewrites `::ffff:169.254.169.254` into the hex form `::ffff:a9fe:a9fe`,\n // so a dotted-quad-only check is green on a value the parser never actually produces.\n const dottedMapped = /^::ffff:(\\d+\\.\\d+\\.\\d+\\.\\d+)$/.exec(normalized)?.[1];\n if (dottedMapped) {\n return UrlPolicy.isNonPublicIPv4({ address: dottedMapped });\n }\n\n const hexMapped = /^::ffff:([\\da-f]{1,4}):([\\da-f]{1,4})$/.exec(normalized);\n if (hexMapped) {\n const high = Number.parseInt(hexMapped[1], 16);\n const low = Number.parseInt(hexMapped[2], 16);\n const dotted = [high >> 8, high & 0xff, low >> 8, low & 0xff].join('.');\n\n return UrlPolicy.isNonPublicIPv4({ address: dotted });\n }\n\n return (\n normalized === '::' ||\n normalized === '::1' ||\n normalized.startsWith('fc') || // unique local\n normalized.startsWith('fd') ||\n normalized.startsWith('fe8') || // link-local\n normalized.startsWith('fe9') ||\n normalized.startsWith('fea') ||\n normalized.startsWith('feb')\n );\n }\n\n /** A bracketed IPv6 literal arrives as `[::1]`; the brackets are not part of the address. */\n static readHostAddress(opts: { hostname: string }): string {\n const { hostname } = opts;\n return hostname.startsWith('[') && hostname.endsWith(']') ? hostname.slice(1, -1) : hostname;\n }\n\n /**\n * A hostname that RESOLVES to a private address passes here on purpose - `UrlIngest` catches that,\n * and this half runs where `node:dns` does not exist.\n */\n static assertSafeUrl(opts: { url: string; policy?: IUrlSafetyPolicy }): URL {\n const { url, policy } = opts;\n const allowedSchemes = policy?.allowedSchemes ?? UrlSafetyDefaults.ALLOWED_SCHEMES;\n const allowPrivateAddress =\n policy?.allowPrivateAddress ?? UrlSafetyDefaults.ALLOW_PRIVATE_ADDRESS;\n\n let parsed: URL;\n try {\n parsed = new URL(url);\n } catch {\n throw getError({\n error: UrlSafetyErrors.URL_REFUSED,\n message: `[assertSafeUrl] Malformed url | url: ${url}`,\n });\n }\n\n if (!allowedSchemes.includes(parsed.protocol)) {\n throw getError({\n error: UrlSafetyErrors.URL_REFUSED,\n message: `[assertSafeUrl] Disallowed scheme | scheme: ${parsed.protocol} | allowed: ${allowedSchemes.join(', ')}`,\n });\n }\n\n if (policy?.allowedHosts && !policy.allowedHosts.includes(parsed.hostname)) {\n throw getError({\n error: UrlSafetyErrors.URL_REFUSED,\n message: `[assertSafeUrl] Host is not in the allow-list | host: ${parsed.hostname}`,\n });\n }\n\n const address = UrlPolicy.readHostAddress({ hostname: parsed.hostname });\n const isLiteralAddress = /^[\\d.]+$/.test(address) || address.includes(':');\n\n if (!allowPrivateAddress && isLiteralAddress && UrlPolicy.isNonPublicAddress({ address })) {\n throw getError({\n error: UrlSafetyErrors.URL_REFUSED,\n message: `[assertSafeUrl] Url points at a non-public address | address: ${address}`,\n });\n }\n\n return parsed;\n }\n}\n\nexport { UrlSafetyDefaults, UrlSchemes };\nexport type { IUrlSafetyPolicy };\n"]}
1
+ {"version":3,"file":"policy.js","sourceRoot":"","sources":["../../../../../../src/modules/network/utilities/url-safety/policy.ts"],"names":[],"mappings":"AAAA,8FAA8F;AAC9F,gGAAgG;AAChG,gGAAgG;AAChG,iBAAiB;AAEjB,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACnE,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAGlD,+EAA+E;AAC/E,MAAM,OAAO,SAAS;IACpB,4GAA4G;IACpG,MAAM,CAAC,eAAe,CAAC,IAAyB;QACtD,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QAElD,IACE,KAAK,CAAC,MAAM,KAAK,CAAC;YAClB,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,IAAI,GAAG,CAAC,IAAI,IAAI,GAAG,GAAG,CAAC,EACvE,CAAC;YACD,OAAO,IAAI,CAAC;QACd,CAAC;QAED,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,KAAK,CAAC;QAE9B,OAAO,CACL,KAAK,KAAK,CAAC,IAAI,YAAY;YAC3B,KAAK,KAAK,EAAE,IAAI,UAAU;YAC1B,KAAK,KAAK,GAAG,IAAI,WAAW;YAC5B,CAAC,KAAK,KAAK,GAAG,IAAI,MAAM,IAAI,EAAE,IAAI,MAAM,IAAI,GAAG,CAAC,IAAI,oBAAoB;YACxE,CAAC,KAAK,KAAK,GAAG,IAAI,MAAM,KAAK,GAAG,CAAC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O,EAAE,iEAAiE,OAAO,EAAE;aACpF,CAAC,CAAC;QACL,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;IAED;;;;;;OAMG;IACH,MAAM,CAAC,cAAc,CAAC,IAAwB;QAC5C,MAAM,MAAM,GAAG,IAAI,CAAC,KAA2C,CAAC;QAChE,OAAO,MAAM,EAAE,UAAU,EAAE,IAAI,KAAK,eAAe,CAAC,WAAW,CAAC,OAAO,CAAC,IAAI,CAAC;IAC/E,CAAC;CACF;AAED,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,CAAC","sourcesContent":["// The browser-pure half of the guard: a url and a literal address are decided with string and\n// number work alone. Resolving a hostname needs `node:dns` and lives in `ingest.ts`, which this\n// file must never import - `policy.ts` is re-exported from the `./core` subpath and is gated by\n// `make purity`.\n\nimport { getError } from '@/modules/error';\nimport { UrlSafetyDefaults, UrlSchemes } from './common/constants';\nimport { UrlSafetyErrors } from './common/errors';\nimport type { IUrlSafetyPolicy } from './common/types';\n\n/** Everything about a url that can be decided without touching the network. */\nexport class UrlPolicy {\n /** A dotted-quad that is not routable on the public internet. An unparseable input counts as non-public. */\n private static isNonPublicIPv4(opts: { address: string }): boolean {\n const parts = opts.address.split('.').map(Number);\n\n if (\n parts.length !== 4 ||\n parts.some((part) => !Number.isInteger(part) || part < 0 || part > 255)\n ) {\n return true;\n }\n\n const [first, second] = parts;\n\n return (\n first === 0 || // this host\n first === 10 || // private\n first === 127 || // loopback\n (first === 100 && second >= 64 && second <= 127) || // carrier-grade NAT\n (first === 169 && second === 254) || // link-local, and the cloud metadata address\n (first === 172 && second >= 16 && second <= 31) || // private\n (first === 192 && second === 0) || // IETF protocol assignments\n (first === 192 && second === 168) || // private\n (first === 198 && (second === 18 || second === 19)) || // benchmarking\n first >= 224 // multicast and reserved\n );\n }\n\n /**\n * An address that must never be reached with an untrusted url. Anything unrecognised answers\n * `true`: a guard that fails open on a string it cannot parse is not a guard.\n */\n static isNonPublicAddress(opts: { address: string }): boolean {\n const normalized = opts.address.toLowerCase().split('%')[0];\n\n if (!normalized.includes(':')) {\n return UrlPolicy.isNonPublicIPv4({ address: normalized });\n }\n\n // An IPv4 address wearing an IPv6 coat walks past every naive v6 check. Both spellings must be\n // unwrapped: `new URL` rewrites `::ffff:169.254.169.254` into the hex form `::ffff:a9fe:a9fe`,\n // so a dotted-quad-only check is green on a value the parser never actually produces.\n const dottedMapped = /^::ffff:(\\d+\\.\\d+\\.\\d+\\.\\d+)$/.exec(normalized)?.[1];\n if (dottedMapped) {\n return UrlPolicy.isNonPublicIPv4({ address: dottedMapped });\n }\n\n const hexMapped = /^::ffff:([\\da-f]{1,4}):([\\da-f]{1,4})$/.exec(normalized);\n if (hexMapped) {\n const high = Number.parseInt(hexMapped[1], 16);\n const low = Number.parseInt(hexMapped[2], 16);\n const dotted = [high >> 8, high & 0xff, low >> 8, low & 0xff].join('.');\n\n return UrlPolicy.isNonPublicIPv4({ address: dotted });\n }\n\n return (\n normalized === '::' ||\n normalized === '::1' ||\n normalized.startsWith('fc') || // unique local\n normalized.startsWith('fd') ||\n normalized.startsWith('fe8') || // link-local\n normalized.startsWith('fe9') ||\n normalized.startsWith('fea') ||\n normalized.startsWith('feb')\n );\n }\n\n /** A bracketed IPv6 literal arrives as `[::1]`; the brackets are not part of the address. */\n static readHostAddress(opts: { hostname: string }): string {\n const { hostname } = opts;\n return hostname.startsWith('[') && hostname.endsWith(']') ? hostname.slice(1, -1) : hostname;\n }\n\n /**\n * A hostname that RESOLVES to a private address passes here on purpose - `UrlIngest` catches that,\n * and this half runs where `node:dns` does not exist.\n */\n static assertSafeUrl(opts: { url: string; policy?: IUrlSafetyPolicy }): URL {\n const { url, policy } = opts;\n const allowedSchemes = policy?.allowedSchemes ?? UrlSafetyDefaults.ALLOWED_SCHEMES;\n const allowPrivateAddress =\n policy?.allowPrivateAddress ?? UrlSafetyDefaults.ALLOW_PRIVATE_ADDRESS;\n\n let parsed: URL;\n try {\n parsed = new URL(url);\n } catch {\n throw getError({\n error: UrlSafetyErrors.URL_REFUSED,\n message: `[assertSafeUrl] Malformed url | url: ${url}`,\n });\n }\n\n if (!allowedSchemes.includes(parsed.protocol)) {\n throw getError({\n error: UrlSafetyErrors.URL_REFUSED,\n message: `[assertSafeUrl] Disallowed scheme | scheme: ${parsed.protocol} | allowed: ${allowedSchemes.join(', ')}`,\n });\n }\n\n if (policy?.allowedHosts && !policy.allowedHosts.includes(parsed.hostname)) {\n throw getError({\n error: UrlSafetyErrors.URL_REFUSED,\n message: `[assertSafeUrl] Host is not in the allow-list | host: ${parsed.hostname}`,\n });\n }\n\n const address = UrlPolicy.readHostAddress({ hostname: parsed.hostname });\n const isLiteralAddress = /^[\\d.]+$/.test(address) || address.includes(':');\n\n if (!allowPrivateAddress && isLiteralAddress && UrlPolicy.isNonPublicAddress({ address })) {\n throw getError({\n error: UrlSafetyErrors.URL_REFUSED,\n message: `[assertSafeUrl] Url points at a non-public address | address: ${address}`,\n });\n }\n\n return parsed;\n }\n\n /**\n * True when the url will never be allowed, whatever happens next: a bad scheme, a non-public\n * address, a host outside the allow-list, a malformed url, or too many hops. Retrying any of those\n * repeats the same rejection - drop the work instead.\n *\n * A timeout, a DNS failure or a 5xx answers `false`: those are worth another attempt.\n */\n static isRefusedError(opts: { error: unknown }): boolean {\n const source = opts.error as { normalized?: { code?: string } };\n return source?.normalized?.code === UrlSafetyErrors.URL_REFUSED.message.code;\n }\n}\n\nexport { UrlSafetyDefaults, UrlSchemes };\nexport type { IUrlSafetyPolicy };\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"helper.d.ts","sourceRoot":"","sources":["../../../../../src/modules/queue/bullmq/helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAGpD,OAAO,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,EA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