jimpex 7.0.1 → 8.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (388) hide show
  1. package/CHANGELOG.md +87 -0
  2. package/LICENSE +1 -1
  3. package/README.md +446 -434
  4. package/dist/app/index.d.ts +13 -0
  5. package/dist/app/index.js +19 -0
  6. package/dist/app/index.js.map +1 -0
  7. package/dist/app/jimpex.d.ts +13 -0
  8. package/dist/app/jimpex.js +440 -0
  9. package/dist/app/jimpex.js.map +1 -0
  10. package/dist/controllers/common/config.d.ts +78 -0
  11. package/dist/controllers/common/config.js +89 -0
  12. package/dist/controllers/common/config.js.map +1 -0
  13. package/dist/controllers/common/health.d.ts +82 -0
  14. package/dist/controllers/common/health.js +97 -0
  15. package/dist/controllers/common/health.js.map +1 -0
  16. package/dist/controllers/common/index.d.ts +21 -0
  17. package/dist/controllers/common/index.js +21 -0
  18. package/dist/controllers/common/index.js.map +1 -0
  19. package/dist/controllers/common/statics.d.ts +215 -0
  20. package/dist/controllers/common/statics.js +202 -0
  21. package/dist/controllers/common/statics.js.map +1 -0
  22. package/dist/controllers/index.d.ts +24 -0
  23. package/dist/controllers/index.js +20 -0
  24. package/dist/controllers/index.js.map +1 -0
  25. package/dist/controllers/utils/gateway.d.ts +724 -0
  26. package/dist/controllers/utils/gateway.js +425 -0
  27. package/dist/controllers/utils/gateway.js.map +1 -0
  28. package/dist/controllers/utils/index.d.ts +16 -0
  29. package/dist/controllers/utils/index.js +19 -0
  30. package/dist/controllers/utils/index.js.map +1 -0
  31. package/dist/esm/app/index.js +2 -0
  32. package/dist/esm/app/index.js.map +1 -0
  33. package/dist/esm/app/jimpex.js +415 -0
  34. package/dist/esm/app/jimpex.js.map +1 -0
  35. package/dist/esm/chunk-T2T6Q22Z.js +11 -0
  36. package/dist/esm/chunk-T2T6Q22Z.js.map +1 -0
  37. package/dist/esm/controllers/common/config.js +62 -0
  38. package/dist/esm/controllers/common/config.js.map +1 -0
  39. package/dist/esm/controllers/common/health.js +70 -0
  40. package/dist/esm/controllers/common/health.js.map +1 -0
  41. package/dist/esm/controllers/common/index.js +4 -0
  42. package/dist/esm/controllers/common/index.js.map +1 -0
  43. package/dist/esm/controllers/common/statics.js +173 -0
  44. package/dist/esm/controllers/common/statics.js.map +1 -0
  45. package/dist/esm/controllers/index.js +3 -0
  46. package/dist/esm/controllers/index.js.map +1 -0
  47. package/dist/esm/controllers/utils/gateway.js +404 -0
  48. package/dist/esm/controllers/utils/gateway.js.map +1 -0
  49. package/dist/esm/controllers/utils/index.js +2 -0
  50. package/dist/esm/controllers/utils/index.js.map +1 -0
  51. package/dist/esm/index.js +7 -0
  52. package/dist/esm/index.js.map +1 -0
  53. package/dist/esm/middlewares/common/errorHandler.js +92 -0
  54. package/dist/esm/middlewares/common/errorHandler.js.map +1 -0
  55. package/dist/esm/middlewares/common/forceHTTPS.js +41 -0
  56. package/dist/esm/middlewares/common/forceHTTPS.js.map +1 -0
  57. package/dist/esm/middlewares/common/hsts.js +53 -0
  58. package/dist/esm/middlewares/common/hsts.js.map +1 -0
  59. package/dist/esm/middlewares/common/index.js +4 -0
  60. package/dist/esm/middlewares/common/index.js.map +1 -0
  61. package/dist/esm/middlewares/html/fastHTML.js +104 -0
  62. package/dist/esm/middlewares/html/fastHTML.js.map +1 -0
  63. package/dist/esm/middlewares/html/index.js +3 -0
  64. package/dist/esm/middlewares/html/index.js.map +1 -0
  65. package/dist/esm/middlewares/html/showHTML.js +68 -0
  66. package/dist/esm/middlewares/html/showHTML.js.map +1 -0
  67. package/dist/esm/middlewares/index.js +4 -0
  68. package/dist/esm/middlewares/index.js.map +1 -0
  69. package/dist/esm/middlewares/utils/index.js +2 -0
  70. package/dist/esm/middlewares/utils/index.js.map +1 -0
  71. package/dist/esm/middlewares/utils/versionValidator.js +101 -0
  72. package/dist/esm/middlewares/utils/versionValidator.js.map +1 -0
  73. package/dist/esm/services/common/appError.js +52 -0
  74. package/dist/esm/services/common/appError.js.map +1 -0
  75. package/dist/esm/services/common/httpError.js +19 -0
  76. package/dist/esm/services/common/httpError.js.map +1 -0
  77. package/dist/esm/services/common/index.js +17 -0
  78. package/dist/esm/services/common/index.js.map +1 -0
  79. package/dist/esm/services/common/sendFile.js +27 -0
  80. package/dist/esm/services/common/sendFile.js.map +1 -0
  81. package/dist/esm/services/frontend/frontendFs.js +38 -0
  82. package/dist/esm/services/frontend/frontendFs.js.map +1 -0
  83. package/dist/esm/services/frontend/index.js +11 -0
  84. package/dist/esm/services/frontend/index.js.map +1 -0
  85. package/dist/esm/services/html/htmlGenerator.js +144 -0
  86. package/dist/esm/services/html/htmlGenerator.js.map +1 -0
  87. package/dist/esm/services/html/index.js +11 -0
  88. package/dist/esm/services/html/index.js.map +1 -0
  89. package/dist/esm/services/http/apiClient.js +71 -0
  90. package/dist/esm/services/http/apiClient.js.map +1 -0
  91. package/dist/esm/services/http/http.js +125 -0
  92. package/dist/esm/services/http/http.js.map +1 -0
  93. package/dist/esm/services/http/index.js +17 -0
  94. package/dist/esm/services/http/index.js.map +1 -0
  95. package/dist/esm/services/http/responsesBuilder.js +105 -0
  96. package/dist/esm/services/http/responsesBuilder.js.map +1 -0
  97. package/dist/esm/services/index.js +6 -0
  98. package/dist/esm/services/index.js.map +1 -0
  99. package/dist/esm/services/utils/ensureBearerToken.js +78 -0
  100. package/dist/esm/services/utils/ensureBearerToken.js.map +1 -0
  101. package/dist/esm/services/utils/index.js +11 -0
  102. package/dist/esm/services/utils/index.js.map +1 -0
  103. package/dist/esm/types/events.js +1 -0
  104. package/dist/esm/types/events.js.map +1 -0
  105. package/dist/esm/types/express.js +1 -0
  106. package/dist/esm/types/express.js.map +1 -0
  107. package/dist/esm/types/http.js +1 -0
  108. package/dist/esm/types/http.js.map +1 -0
  109. package/dist/esm/types/index.js +7 -0
  110. package/dist/esm/types/index.js.map +1 -0
  111. package/dist/esm/types/options.js +1 -0
  112. package/dist/esm/types/options.js.map +1 -0
  113. package/dist/esm/types/utils.js +1 -0
  114. package/dist/esm/types/utils.js.map +1 -0
  115. package/dist/esm/types/wootils.js +1 -0
  116. package/dist/esm/types/wootils.js.map +1 -0
  117. package/dist/esm/utils/fns/index.js +5 -0
  118. package/dist/esm/utils/fns/index.js.map +1 -0
  119. package/dist/esm/utils/fns/others.js +6 -0
  120. package/dist/esm/utils/fns/others.js.map +1 -0
  121. package/dist/esm/utils/fns/routes.js +25 -0
  122. package/dist/esm/utils/fns/routes.js.map +1 -0
  123. package/dist/esm/utils/fns/statuses.js +6 -0
  124. package/dist/esm/utils/fns/statuses.js.map +1 -0
  125. package/dist/esm/utils/fns/text.js +6 -0
  126. package/dist/esm/utils/fns/text.js.map +1 -0
  127. package/dist/esm/utils/index.js +3 -0
  128. package/dist/esm/utils/index.js.map +1 -0
  129. package/dist/esm/utils/wrappers.js +41 -0
  130. package/dist/esm/utils/wrappers.js.map +1 -0
  131. package/dist/index.d.ts +46 -0
  132. package/dist/index.js +24 -0
  133. package/dist/index.js.map +1 -0
  134. package/dist/jimpex-7eaee271.d.ts +1278 -0
  135. package/dist/middlewares/common/errorHandler.d.ts +131 -0
  136. package/dist/middlewares/common/errorHandler.js +119 -0
  137. package/dist/middlewares/common/errorHandler.js.map +1 -0
  138. package/dist/middlewares/common/forceHTTPS.d.ts +68 -0
  139. package/dist/middlewares/common/forceHTTPS.js +68 -0
  140. package/dist/middlewares/common/forceHTTPS.js.map +1 -0
  141. package/dist/middlewares/common/hsts.d.ts +109 -0
  142. package/dist/middlewares/common/hsts.js +80 -0
  143. package/dist/middlewares/common/hsts.js.map +1 -0
  144. package/dist/middlewares/common/index.d.ts +21 -0
  145. package/dist/middlewares/common/index.js +21 -0
  146. package/dist/middlewares/common/index.js.map +1 -0
  147. package/dist/middlewares/html/fastHTML.d.ts +180 -0
  148. package/dist/middlewares/html/fastHTML.js +131 -0
  149. package/dist/middlewares/html/fastHTML.js.map +1 -0
  150. package/dist/middlewares/html/index.d.ts +21 -0
  151. package/dist/middlewares/html/index.js +20 -0
  152. package/dist/middlewares/html/index.js.map +1 -0
  153. package/dist/middlewares/html/showHTML.d.ts +127 -0
  154. package/dist/middlewares/html/showHTML.js +95 -0
  155. package/dist/middlewares/html/showHTML.js.map +1 -0
  156. package/dist/middlewares/index.d.ts +30 -0
  157. package/dist/middlewares/index.js +21 -0
  158. package/dist/middlewares/index.js.map +1 -0
  159. package/dist/middlewares/utils/index.d.ts +19 -0
  160. package/dist/middlewares/utils/index.js +19 -0
  161. package/dist/middlewares/utils/index.js.map +1 -0
  162. package/dist/middlewares/utils/versionValidator.d.ts +214 -0
  163. package/dist/middlewares/utils/versionValidator.js +128 -0
  164. package/dist/middlewares/utils/versionValidator.js.map +1 -0
  165. package/dist/services/common/appError.d.ts +138 -0
  166. package/dist/services/common/appError.js +80 -0
  167. package/dist/services/common/appError.js.map +1 -0
  168. package/dist/services/common/httpError.d.ts +79 -0
  169. package/dist/services/common/httpError.js +44 -0
  170. package/dist/services/common/httpError.js.map +1 -0
  171. package/dist/services/common/index.d.ts +47 -0
  172. package/dist/services/common/index.js +41 -0
  173. package/dist/services/common/index.js.map +1 -0
  174. package/dist/services/common/sendFile.d.ts +102 -0
  175. package/dist/services/common/sendFile.js +51 -0
  176. package/dist/services/common/sendFile.js.map +1 -0
  177. package/dist/services/frontend/frontendFs.d.ts +96 -0
  178. package/dist/services/frontend/frontendFs.js +71 -0
  179. package/dist/services/frontend/frontendFs.js.map +1 -0
  180. package/dist/services/frontend/index.d.ts +40 -0
  181. package/dist/services/frontend/index.js +35 -0
  182. package/dist/services/frontend/index.js.map +1 -0
  183. package/dist/services/html/htmlGenerator.d.ts +237 -0
  184. package/dist/services/html/htmlGenerator.js +171 -0
  185. package/dist/services/html/htmlGenerator.js.map +1 -0
  186. package/dist/services/html/index.d.ts +43 -0
  187. package/dist/services/html/index.js +35 -0
  188. package/dist/services/html/index.js.map +1 -0
  189. package/dist/services/http/apiClient.d.ts +169 -0
  190. package/dist/services/http/apiClient.js +96 -0
  191. package/dist/services/http/apiClient.js.map +1 -0
  192. package/dist/services/http/http.d.ts +175 -0
  193. package/dist/services/http/http.js +158 -0
  194. package/dist/services/http/http.js.map +1 -0
  195. package/dist/services/http/index.d.ts +50 -0
  196. package/dist/services/http/index.js +41 -0
  197. package/dist/services/http/index.js.map +1 -0
  198. package/dist/services/http/responsesBuilder.d.ts +178 -0
  199. package/dist/services/http/responsesBuilder.js +132 -0
  200. package/dist/services/http/responsesBuilder.js.map +1 -0
  201. package/dist/services/index.d.ts +33 -0
  202. package/dist/services/index.js +23 -0
  203. package/dist/services/index.js.map +1 -0
  204. package/dist/services/utils/ensureBearerToken.d.ts +157 -0
  205. package/dist/services/utils/ensureBearerToken.js +105 -0
  206. package/dist/services/utils/ensureBearerToken.js.map +1 -0
  207. package/dist/services/utils/index.d.ts +43 -0
  208. package/dist/services/utils/index.js +35 -0
  209. package/dist/services/utils/index.js.map +1 -0
  210. package/dist/types/events.d.ts +13 -0
  211. package/dist/types/events.js +17 -0
  212. package/dist/types/events.js.map +1 -0
  213. package/dist/types/express.d.ts +10 -0
  214. package/dist/types/express.js +17 -0
  215. package/dist/types/express.js.map +1 -0
  216. package/dist/types/http.d.ts +79 -0
  217. package/dist/types/http.js +17 -0
  218. package/dist/types/http.js.map +1 -0
  219. package/dist/types/index.d.ts +14 -0
  220. package/dist/types/index.js +24 -0
  221. package/dist/types/index.js.map +1 -0
  222. package/dist/types/options.d.ts +13 -0
  223. package/dist/types/options.js +17 -0
  224. package/dist/types/options.js.map +1 -0
  225. package/dist/types/utils.d.ts +48 -0
  226. package/dist/types/utils.js +17 -0
  227. package/dist/types/utils.js.map +1 -0
  228. package/dist/types/wootils.d.ts +4 -0
  229. package/dist/types/wootils.js +17 -0
  230. package/dist/types/wootils.js.map +1 -0
  231. package/dist/utils/fns/index.d.ts +5 -0
  232. package/dist/utils/fns/index.js +22 -0
  233. package/dist/utils/fns/index.js.map +1 -0
  234. package/dist/utils/fns/others.d.ts +17 -0
  235. package/dist/utils/fns/others.js +29 -0
  236. package/dist/utils/fns/others.js.map +1 -0
  237. package/dist/utils/fns/routes.d.ts +39 -0
  238. package/dist/utils/fns/routes.js +51 -0
  239. package/dist/utils/fns/routes.js.map +1 -0
  240. package/dist/utils/fns/statuses.d.ts +45 -0
  241. package/dist/utils/fns/statuses.js +35 -0
  242. package/dist/utils/fns/statuses.js.map +1 -0
  243. package/dist/utils/fns/text.d.ts +9 -0
  244. package/dist/utils/fns/text.js +29 -0
  245. package/dist/utils/fns/text.js.map +1 -0
  246. package/dist/utils/index.d.ts +18 -0
  247. package/dist/utils/index.js +20 -0
  248. package/dist/utils/index.js.map +1 -0
  249. package/dist/utils/wrappers.d.ts +13 -0
  250. package/dist/utils/wrappers.js +68 -0
  251. package/dist/utils/wrappers.js.map +1 -0
  252. package/examples/basic/404.html +12 -0
  253. package/examples/basic/README.md +30 -0
  254. package/examples/basic/app.ts +18 -0
  255. package/examples/basic/controller.ts +45 -0
  256. package/examples/basic/index.ts +19 -0
  257. package/examples/basic/middleware.ts +13 -0
  258. package/examples/basic/service.ts +11 -0
  259. package/package.json +59 -38
  260. package/src/app/index.ts +1 -0
  261. package/src/app/jimpex.ts +743 -0
  262. package/src/controllers/common/config.ts +115 -0
  263. package/src/controllers/common/health.ts +128 -0
  264. package/src/controllers/common/index.ts +3 -0
  265. package/src/controllers/common/statics.ts +380 -0
  266. package/src/controllers/index.ts +2 -0
  267. package/src/controllers/utils/gateway.ts +1186 -0
  268. package/src/controllers/utils/index.ts +1 -0
  269. package/src/index.ts +6 -0
  270. package/src/middlewares/common/errorHandler.ts +203 -0
  271. package/src/middlewares/common/forceHTTPS.ts +83 -0
  272. package/src/middlewares/common/hsts.ts +135 -0
  273. package/src/middlewares/common/index.ts +3 -0
  274. package/src/middlewares/html/fastHTML.ts +255 -0
  275. package/src/middlewares/html/index.ts +2 -0
  276. package/src/middlewares/html/showHTML.ts +165 -0
  277. package/src/middlewares/index.ts +3 -0
  278. package/src/middlewares/utils/index.ts +1 -0
  279. package/src/middlewares/utils/versionValidator.ts +289 -0
  280. package/src/services/common/appError.ts +158 -0
  281. package/src/services/common/httpError.ts +74 -0
  282. package/src/services/common/index.ts +29 -0
  283. package/src/services/common/sendFile.ts +106 -0
  284. package/src/services/frontend/frontendFs.ts +101 -0
  285. package/src/services/frontend/index.ts +21 -0
  286. package/src/services/html/htmlGenerator.ts +356 -0
  287. package/src/services/html/index.ts +21 -0
  288. package/src/services/http/apiClient.ts +221 -0
  289. package/src/services/http/http.ts +286 -0
  290. package/src/services/http/index.ts +29 -0
  291. package/src/services/http/responsesBuilder.ts +265 -0
  292. package/src/services/index.ts +5 -0
  293. package/src/services/utils/ensureBearerToken.ts +202 -0
  294. package/src/services/utils/index.ts +21 -0
  295. package/src/types/events.ts +303 -0
  296. package/src/types/express.ts +21 -0
  297. package/src/types/http.ts +77 -0
  298. package/src/types/index.ts +6 -0
  299. package/src/types/options.ts +248 -0
  300. package/src/types/utils.ts +52 -0
  301. package/src/types/wootils.ts +4 -0
  302. package/src/utils/fns/index.ts +4 -0
  303. package/src/utils/fns/others.ts +15 -0
  304. package/src/utils/fns/routes.ts +64 -0
  305. package/src/utils/fns/statuses.ts +44 -0
  306. package/src/utils/fns/text.ts +8 -0
  307. package/src/utils/index.ts +2 -0
  308. package/src/utils/wrappers.ts +537 -0
  309. package/tsconfig.json +5 -8
  310. package/tsup.config.ts +10 -0
  311. package/src/app/index.js +0 -692
  312. package/src/constants/eventNames.js +0 -48
  313. package/src/constants/index.js +0 -7
  314. package/src/controllers/common/configuration.js +0 -116
  315. package/src/controllers/common/health.js +0 -79
  316. package/src/controllers/common/index.js +0 -7
  317. package/src/controllers/common/statics.js +0 -336
  318. package/src/controllers/index.js +0 -9
  319. package/src/controllers/utils/gateway.js +0 -1039
  320. package/src/controllers/utils/index.js +0 -3
  321. package/src/index.js +0 -30
  322. package/src/middlewares/common/errorHandler.js +0 -185
  323. package/src/middlewares/common/forceHTTPS.js +0 -80
  324. package/src/middlewares/common/hsts.js +0 -122
  325. package/src/middlewares/common/index.js +0 -7
  326. package/src/middlewares/html/fastHTML.js +0 -298
  327. package/src/middlewares/html/index.js +0 -5
  328. package/src/middlewares/html/showHTML.js +0 -167
  329. package/src/middlewares/index.js +0 -11
  330. package/src/middlewares/utils/index.js +0 -3
  331. package/src/middlewares/utils/versionValidator.js +0 -261
  332. package/src/services/common/appError.js +0 -136
  333. package/src/services/common/httpError.js +0 -60
  334. package/src/services/common/index.js +0 -25
  335. package/src/services/common/sendFile.js +0 -68
  336. package/src/services/frontend/frontendFs.js +0 -85
  337. package/src/services/frontend/index.js +0 -17
  338. package/src/services/html/htmlGenerator.js +0 -391
  339. package/src/services/html/index.js +0 -17
  340. package/src/services/http/apiClient.js +0 -148
  341. package/src/services/http/http.js +0 -256
  342. package/src/services/http/index.js +0 -25
  343. package/src/services/http/responsesBuilder.js +0 -193
  344. package/src/services/index.js +0 -15
  345. package/src/services/utils/ensureBearerToken.js +0 -147
  346. package/src/services/utils/index.js +0 -19
  347. package/src/types.js +0 -377
  348. package/src/utils/functions.js +0 -78
  349. package/src/utils/wrappers.js +0 -131
  350. package/types/app/index.d.ts +0 -417
  351. package/types/constants/eventNames.d.ts +0 -93
  352. package/types/constants/index.d.ts +0 -2
  353. package/types/controllers/common/configuration.d.ts +0 -71
  354. package/types/controllers/common/health.d.ts +0 -55
  355. package/types/controllers/common/index.d.ts +0 -4
  356. package/types/controllers/common/statics.d.ts +0 -271
  357. package/types/controllers/index.d.ts +0 -3
  358. package/types/controllers/utils/gateway.d.ts +0 -947
  359. package/types/controllers/utils/index.d.ts +0 -2
  360. package/types/index.d.ts +0 -15
  361. package/types/middlewares/common/errorHandler.d.ts +0 -143
  362. package/types/middlewares/common/forceHTTPS.d.ts +0 -64
  363. package/types/middlewares/common/hsts.d.ts +0 -111
  364. package/types/middlewares/common/index.d.ts +0 -4
  365. package/types/middlewares/html/fastHTML.d.ts +0 -238
  366. package/types/middlewares/html/index.d.ts +0 -3
  367. package/types/middlewares/html/showHTML.d.ts +0 -128
  368. package/types/middlewares/index.d.ts +0 -4
  369. package/types/middlewares/utils/index.d.ts +0 -2
  370. package/types/middlewares/utils/versionValidator.d.ts +0 -247
  371. package/types/services/common/appError.d.ts +0 -89
  372. package/types/services/common/httpError.d.ts +0 -37
  373. package/types/services/common/index.d.ts +0 -18
  374. package/types/services/common/sendFile.d.ts +0 -56
  375. package/types/services/frontend/frontendFs.d.ts +0 -72
  376. package/types/services/frontend/index.d.ts +0 -3
  377. package/types/services/html/htmlGenerator.d.ts +0 -298
  378. package/types/services/html/index.d.ts +0 -3
  379. package/types/services/http/apiClient.d.ts +0 -141
  380. package/types/services/http/http.d.ts +0 -159
  381. package/types/services/http/index.d.ts +0 -18
  382. package/types/services/http/responsesBuilder.d.ts +0 -140
  383. package/types/services/index.d.ts +0 -6
  384. package/types/services/utils/ensureBearerToken.d.ts +0 -137
  385. package/types/services/utils/index.d.ts +0 -16
  386. package/types/types.d.ts +0 -280
  387. package/types/utils/functions.d.ts +0 -55
  388. package/types/utils/wrappers.d.ts +0 -127
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
15
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
+ var middlewares_exports = {};
17
+ module.exports = __toCommonJS(middlewares_exports);
18
+ __reExport(middlewares_exports, require("./common"), module.exports);
19
+ __reExport(middlewares_exports, require("./html"), module.exports);
20
+ __reExport(middlewares_exports, require("./utils"), module.exports);
21
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/middlewares/index.ts"],"sourcesContent":["export * from './common';\nexport * from './html';\nexport * from './utils';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,gCAAc,qBAAd;AACA,gCAAc,mBADd;AAEA,gCAAc,oBAFd;","names":[]}
@@ -0,0 +1,19 @@
1
+ export { VersionValidator, VersionValidatorConstructorOptions, VersionValidatorLatestOptions, VersionValidatorMiddlewareOptions, VersionValidatorOptions, VersionValidatorPartialOptions, VersionValidatorPopupOptions, versionValidatorMiddleware } from './versionValidator.js';
2
+ import '@homer0/jimple';
3
+ import '../../utils/fns/statuses.js';
4
+ import 'statuses';
5
+ import '../../jimpex-7eaee271.js';
6
+ import '@homer0/events-hub';
7
+ import '../../types/express.js';
8
+ import 'express';
9
+ import '../../types/http.js';
10
+ import 'https';
11
+ import 'http';
12
+ import 'spdy';
13
+ import 'node-fetch';
14
+ import '@homer0/simple-config';
15
+ import '../../types/utils.js';
16
+ import '@homer0/simple-logger';
17
+ import '../../services/common/httpError.js';
18
+ import '../../services/common/appError.js';
19
+ import '../../services/http/responsesBuilder.js';
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
15
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
+ var utils_exports = {};
17
+ module.exports = __toCommonJS(utils_exports);
18
+ __reExport(utils_exports, require("./versionValidator"), module.exports);
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/middlewares/utils/index.ts"],"sourcesContent":["export * from './versionValidator';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,0BAAc,+BAAd;","names":[]}
@@ -0,0 +1,214 @@
1
+ import * as _homer0_jimple from '@homer0/jimple';
2
+ import { Statuses } from '../../utils/fns/statuses.js';
3
+ import { J as Jimpex, R as MiddlewareConnectFn } from '../../jimpex-7eaee271.js';
4
+ import { ExpressMiddleware } from '../../types/express.js';
5
+ import { DeepPartial } from '../../types/utils.js';
6
+ import { HTTPErrorClass } from '../../services/common/httpError.js';
7
+ import { ResponsesBuilder } from '../../services/http/responsesBuilder.js';
8
+ import { Request } from 'express';
9
+ import 'statuses';
10
+ import '@homer0/events-hub';
11
+ import '../../types/http.js';
12
+ import 'https';
13
+ import 'http';
14
+ import 'spdy';
15
+ import 'node-fetch';
16
+ import '@homer0/simple-config';
17
+ import '@homer0/simple-logger';
18
+ import '../../services/common/appError.js';
19
+
20
+ /**
21
+ * The options for how the middleware should behave if the requested version is `latest`.
22
+ *
23
+ * @group Middlewares/VersionValidator
24
+ */
25
+ type VersionValidatorLatestOptions = {
26
+ /**
27
+ * Whether or not the middleware should validate the _"latest version"_.
28
+ *
29
+ * @default true
30
+ */
31
+ allow: boolean;
32
+ /**
33
+ * The name of the _"latest version"_. Basically, `req.params.version` must match with
34
+ * this property in order to be consider "latest".
35
+ *
36
+ * @default 'latest'
37
+ */
38
+ name: string;
39
+ };
40
+ /**
41
+ * The options for how to detect if the request comes from a popup and how to compose the
42
+ * post message the middleware will use to respond.
43
+ *
44
+ * @group Middlewares/VersionValidator
45
+ */
46
+ type VersionValidatorPopupOptions = {
47
+ /**
48
+ * The name of the query string variable the middleware will check in order to indentify
49
+ * whether the request comes from a popup or not. The variable must have `'true'` as its
50
+ * value.
51
+ *
52
+ * @default 'popup'
53
+ */
54
+ variable: string;
55
+ /**
56
+ * The title of the page that will be generated to respond in case the versions don't
57
+ * match.
58
+ *
59
+ * @default 'Conflict'
60
+ */
61
+ title: string;
62
+ /**
63
+ * The contents of the post message the generated page will send if the versions don't
64
+ * match.
65
+ *
66
+ * @default 'version:conflict'
67
+ */
68
+ message: string;
69
+ };
70
+ /**
71
+ * The options used to customize a {@link VersionValidator} instance.
72
+ *
73
+ * @group Middlewares/VersionValidator
74
+ */
75
+ type VersionValidatorOptions = {
76
+ /**
77
+ * The version used to validate the requests.
78
+ */
79
+ version: string;
80
+ /**
81
+ * The options for how the middleware should behave if the requested version is
82
+ * `latest`.
83
+ */
84
+ latest: VersionValidatorLatestOptions;
85
+ /**
86
+ * The options for how to detect if the request comes from a popup and how to compose
87
+ * the post message the middleware will use to respond.
88
+ */
89
+ popup: VersionValidatorPopupOptions;
90
+ /**
91
+ * The error message to show when the version is invalid.
92
+ *
93
+ * @default "The application version doesn't match"
94
+ * @prettierignore
95
+ */
96
+ error: string;
97
+ };
98
+ /**
99
+ * A partial version of the {@link VersionValidatorOptions}, to be used in the constructor
100
+ * and the middleware creator. The reason it omits `version` it's because for the
101
+ * constructor it's required, but for the middleware creator it's not.
102
+ *
103
+ * @group Middlewares/VersionValidator
104
+ */
105
+ type VersionValidatorPartialOptions = DeepPartial<Omit<VersionValidatorOptions, 'version'>>;
106
+ /**
107
+ * The options to construct a {@link VersionValidator}.
108
+ *
109
+ * @group Middlewares/VersionValidator
110
+ */
111
+ type VersionValidatorConstructorOptions = VersionValidatorPartialOptions & {
112
+ /**
113
+ * The version used to validate the requests.
114
+ */
115
+ version: string;
116
+ /**
117
+ * A dictionary with the dependencies to inject.
118
+ */
119
+ inject: {
120
+ HTTPError: HTTPErrorClass;
121
+ responsesBuilder: ResponsesBuilder;
122
+ statuses: Statuses;
123
+ };
124
+ };
125
+ /**
126
+ * The options for the middleware creator that will mount an instance of
127
+ * {@link VersionValidator}.
128
+ *
129
+ * @group Middlewares/VersionValidator
130
+ */
131
+ type VersionValidatorMiddlewareOptions = VersionValidatorPartialOptions & {
132
+ /**
133
+ * The version used to validate the requests. This is optional in here because if it's
134
+ * not specified, it will be obtained from the configuration service.
135
+ */
136
+ version?: string;
137
+ };
138
+ /**
139
+ * This is the handler for the middleware/controller that validates the application
140
+ * version.
141
+ * This is useful in cases where you want to restrict the access to specific versions; for
142
+ * example: you have a frontend which needs to be aligned with the "current" version of
143
+ * the application, since the frontend won't realize a new version was released, the
144
+ * validator can be used to let the frontend know.
145
+ * Also, it can be configured to handle requests from popups, in which case, instead of
146
+ * generating an error message, it will send a post message.
147
+ *
148
+ * @group Middleware Classes
149
+ * @group Middlewares/VersionValidator
150
+ * @prettierignore
151
+ */
152
+ declare class VersionValidator {
153
+ /**
154
+ * To generate the errors in case the validation fails.
155
+ */
156
+ protected readonly _HTTPError: HTTPErrorClass;
157
+ /**
158
+ * To generate responses for popups.
159
+ */
160
+ protected readonly _responsesBuilder: ResponsesBuilder;
161
+ /**
162
+ * The uility service to get HTTP status codes.
163
+ */
164
+ protected readonly _statuses: Statuses;
165
+ /**
166
+ * The customization options.
167
+ */
168
+ protected readonly _options: VersionValidatorOptions;
169
+ /**
170
+ * @param options The options to construct the class.
171
+ * @throws If no `version` is specified in the options.
172
+ */
173
+ constructor({ inject, version, ...options }: VersionValidatorConstructorOptions);
174
+ /**
175
+ * Generates the middleware that validates the version.
176
+ */
177
+ getMiddleware(): ExpressMiddleware;
178
+ /**
179
+ * The customization options.
180
+ */
181
+ get options(): Readonly<VersionValidatorOptions>;
182
+ /**
183
+ * Helper method that checks if the incoming request is from a popup. It will look for
184
+ * the query string variable defined in the constructor options.
185
+ *
186
+ * @param req The request object sent by the application.
187
+ */
188
+ protected _isPopup(req: Request): boolean;
189
+ /**
190
+ * Helper method that checks if the "latest version" is enabled and if the given version
191
+ * is "the latest" (comparing it with the option name).
192
+ *
193
+ * @param version The version received in the request.
194
+ */
195
+ protected _isTheAllowedLatest(version: string): boolean;
196
+ }
197
+ /**
198
+ * A middleware that will validate a `version` request parameter against the application
199
+ * version, and generate an error if they don't match.
200
+ * This is a "middleware/controller" because the wrappers for both are the same, the
201
+ * difference is that, for controllers, Jimpex sends a second parameter with the route
202
+ * where they are mounted.
203
+ * By validating the route parameter, the function can know whether the implementation is
204
+ * going to use the middleware by itself or as a route middleware.
205
+ * If used as middleware, it will just return the result of
206
+ * {@link VersionValidator.getMiddleware}; but if used as controller, it will mount it on
207
+ * `[route]/:version/*`.
208
+ *
209
+ * @group Middlewares
210
+ * @group Middlewares/VersionValidator
211
+ */
212
+ declare const versionValidatorMiddleware: _homer0_jimple.ResourceCreator<"middleware", "connect", (options?: VersionValidatorMiddlewareOptions) => <ContainerType extends Jimpex = Jimpex>(app: ContainerType, route: string | undefined) => ExpressMiddleware, MiddlewareConnectFn>;
213
+
214
+ export { VersionValidator, VersionValidatorConstructorOptions, VersionValidatorLatestOptions, VersionValidatorMiddlewareOptions, VersionValidatorOptions, VersionValidatorPartialOptions, VersionValidatorPopupOptions, versionValidatorMiddleware };
@@ -0,0 +1,128 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+ var __publicField = (obj, key, value) => {
21
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
22
+ return value;
23
+ };
24
+ var versionValidator_exports = {};
25
+ __export(versionValidator_exports, {
26
+ VersionValidator: () => VersionValidator,
27
+ versionValidatorMiddleware: () => versionValidatorMiddleware
28
+ });
29
+ module.exports = __toCommonJS(versionValidator_exports);
30
+ var import_deep_assign = require("@homer0/deep-assign");
31
+ var import_utils = require("../../utils");
32
+ class VersionValidator {
33
+ constructor({ inject, version, ...options }) {
34
+ __publicField(this, "_HTTPError");
35
+ __publicField(this, "_responsesBuilder");
36
+ __publicField(this, "_statuses");
37
+ __publicField(this, "_options");
38
+ this._HTTPError = inject.HTTPError;
39
+ this._responsesBuilder = inject.responsesBuilder;
40
+ this._statuses = inject.statuses;
41
+ this._options = (0, import_deep_assign.deepAssignWithOverwrite)(
42
+ {
43
+ error: "The application version doesn't match",
44
+ latest: {
45
+ allow: true,
46
+ name: "latest"
47
+ },
48
+ popup: {
49
+ variable: "popup",
50
+ title: "Conflict",
51
+ message: "vesion:conflict"
52
+ },
53
+ version
54
+ },
55
+ options
56
+ );
57
+ if (!this._options.version) {
58
+ throw new Error("You need to supply a version");
59
+ }
60
+ }
61
+ getMiddleware() {
62
+ return (req, res, next) => {
63
+ const { version } = req.params;
64
+ if (!version) {
65
+ next();
66
+ return;
67
+ }
68
+ if (version === this._options.version || this._isTheAllowedLatest(version)) {
69
+ next();
70
+ return;
71
+ }
72
+ const status = this._statuses("conflict");
73
+ if (this._isPopup(req)) {
74
+ const { title, message } = this._options.popup;
75
+ this._responsesBuilder.htmlPostMessage({
76
+ res,
77
+ title,
78
+ message,
79
+ status
80
+ });
81
+ return;
82
+ }
83
+ next(
84
+ new this._HTTPError(this._options.error, status, {
85
+ response: {
86
+ validation: true
87
+ }
88
+ })
89
+ );
90
+ };
91
+ }
92
+ get options() {
93
+ return (0, import_deep_assign.deepAssignWithOverwrite)({}, this._options);
94
+ }
95
+ _isPopup(req) {
96
+ const popup = req.query[this._options.popup.variable];
97
+ return !!(popup && String(popup).toLowerCase() === "true");
98
+ }
99
+ _isTheAllowedLatest(version) {
100
+ const { allow, name } = this._options.latest;
101
+ return allow && version === name;
102
+ }
103
+ }
104
+ const versionValidatorMiddleware = (0, import_utils.middlewareCreator)(
105
+ (options = {}) => (app, route) => {
106
+ const version = app.getConfig("version");
107
+ const middleware = new VersionValidator({
108
+ inject: {
109
+ HTTPError: app.get("HTTPError"),
110
+ responsesBuilder: app.get("responsesBuilder"),
111
+ statuses: app.get("statuses")
112
+ },
113
+ version,
114
+ ...options
115
+ }).getMiddleware();
116
+ if (route) {
117
+ const router = app.getRouter();
118
+ return router.all("/:version/*", middleware);
119
+ }
120
+ return middleware;
121
+ }
122
+ );
123
+ // Annotate the CommonJS export names for ESM import in node:
124
+ 0 && (module.exports = {
125
+ VersionValidator,
126
+ versionValidatorMiddleware
127
+ });
128
+ //# sourceMappingURL=versionValidator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/middlewares/utils/versionValidator.ts"],"sourcesContent":["import { deepAssignWithOverwrite } from '@homer0/deep-assign';\nimport { middlewareCreator, type Statuses } from '../../utils';\nimport { DeepPartial, Request, ExpressMiddleware } from '../../types';\nimport type { HTTPErrorClass, ResponsesBuilder } from '../../services';\n/**\n * The options for how the middleware should behave if the requested version is `latest`.\n *\n * @group Middlewares/VersionValidator\n */\nexport type VersionValidatorLatestOptions = {\n /**\n * Whether or not the middleware should validate the _\"latest version\"_.\n *\n * @default true\n */\n allow: boolean;\n /**\n * The name of the _\"latest version\"_. Basically, `req.params.version` must match with\n * this property in order to be consider \"latest\".\n *\n * @default 'latest'\n */\n name: string;\n};\n/**\n * The options for how to detect if the request comes from a popup and how to compose the\n * post message the middleware will use to respond.\n *\n * @group Middlewares/VersionValidator\n */\nexport type VersionValidatorPopupOptions = {\n /**\n * The name of the query string variable the middleware will check in order to indentify\n * whether the request comes from a popup or not. The variable must have `'true'` as its\n * value.\n *\n * @default 'popup'\n */\n variable: string;\n /**\n * The title of the page that will be generated to respond in case the versions don't\n * match.\n *\n * @default 'Conflict'\n */\n title: string;\n /**\n * The contents of the post message the generated page will send if the versions don't\n * match.\n *\n * @default 'version:conflict'\n */\n message: string;\n};\n/**\n * The options used to customize a {@link VersionValidator} instance.\n *\n * @group Middlewares/VersionValidator\n */\nexport type VersionValidatorOptions = {\n /**\n * The version used to validate the requests.\n */\n version: string;\n /**\n * The options for how the middleware should behave if the requested version is\n * `latest`.\n */\n latest: VersionValidatorLatestOptions;\n /**\n * The options for how to detect if the request comes from a popup and how to compose\n * the post message the middleware will use to respond.\n */\n popup: VersionValidatorPopupOptions;\n /**\n * The error message to show when the version is invalid.\n *\n * @default \"The application version doesn't match\"\n * @prettierignore\n */\n error: string;\n};\n/**\n * A partial version of the {@link VersionValidatorOptions}, to be used in the constructor\n * and the middleware creator. The reason it omits `version` it's because for the\n * constructor it's required, but for the middleware creator it's not.\n *\n * @group Middlewares/VersionValidator\n */\nexport type VersionValidatorPartialOptions = DeepPartial<\n Omit<VersionValidatorOptions, 'version'>\n>;\n/**\n * The options to construct a {@link VersionValidator}.\n *\n * @group Middlewares/VersionValidator\n */\nexport type VersionValidatorConstructorOptions = VersionValidatorPartialOptions & {\n /**\n * The version used to validate the requests.\n */\n version: string;\n /**\n * A dictionary with the dependencies to inject.\n */\n inject: {\n HTTPError: HTTPErrorClass;\n responsesBuilder: ResponsesBuilder;\n statuses: Statuses;\n };\n};\n/**\n * The options for the middleware creator that will mount an instance of\n * {@link VersionValidator}.\n *\n * @group Middlewares/VersionValidator\n */\nexport type VersionValidatorMiddlewareOptions = VersionValidatorPartialOptions & {\n /**\n * The version used to validate the requests. This is optional in here because if it's\n * not specified, it will be obtained from the configuration service.\n */\n version?: string;\n};\n/**\n * This is the handler for the middleware/controller that validates the application\n * version.\n * This is useful in cases where you want to restrict the access to specific versions; for\n * example: you have a frontend which needs to be aligned with the \"current\" version of\n * the application, since the frontend won't realize a new version was released, the\n * validator can be used to let the frontend know.\n * Also, it can be configured to handle requests from popups, in which case, instead of\n * generating an error message, it will send a post message.\n *\n * @group Middleware Classes\n * @group Middlewares/VersionValidator\n * @prettierignore\n */\nexport class VersionValidator {\n /**\n * To generate the errors in case the validation fails.\n */\n protected readonly _HTTPError: HTTPErrorClass;\n /**\n * To generate responses for popups.\n */\n protected readonly _responsesBuilder: ResponsesBuilder;\n /**\n * The uility service to get HTTP status codes.\n */\n protected readonly _statuses: Statuses;\n /**\n * The customization options.\n */\n protected readonly _options: VersionValidatorOptions;\n /**\n * @param options The options to construct the class.\n * @throws If no `version` is specified in the options.\n */\n constructor({ inject, version, ...options }: VersionValidatorConstructorOptions) {\n this._HTTPError = inject.HTTPError;\n this._responsesBuilder = inject.responsesBuilder;\n this._statuses = inject.statuses;\n this._options = deepAssignWithOverwrite(\n {\n error: \"The application version doesn't match\",\n latest: {\n allow: true,\n name: 'latest',\n },\n popup: {\n variable: 'popup',\n title: 'Conflict',\n message: 'vesion:conflict',\n },\n version,\n },\n options,\n );\n\n if (!this._options.version) {\n throw new Error('You need to supply a version');\n }\n }\n /**\n * Generates the middleware that validates the version.\n */\n getMiddleware(): ExpressMiddleware {\n return (req, res, next) => {\n // Get the `version` parameter from the request.\n const { version } = req.params;\n // If no version is present, move on to the next middleware.\n if (!version) {\n next();\n return;\n }\n // If the version matches, or it's a \"latest\" version, move on to the next middleware.\n if (version === this._options.version || this._isTheAllowedLatest(version)) {\n next();\n return;\n }\n\n const status = this._statuses('conflict');\n // If the request comes from a popup, send the post message.\n if (this._isPopup(req)) {\n const { title, message } = this._options.popup;\n this._responsesBuilder.htmlPostMessage({\n res,\n title,\n message,\n status,\n });\n return;\n }\n\n // Every other validation failed, and it's not a popup, so generate an error.\n next(\n new this._HTTPError(this._options.error, status, {\n response: {\n validation: true,\n },\n }),\n );\n };\n }\n /**\n * The customization options.\n */\n get options(): Readonly<VersionValidatorOptions> {\n return deepAssignWithOverwrite({}, this._options);\n }\n /**\n * Helper method that checks if the incoming request is from a popup. It will look for\n * the query string variable defined in the constructor options.\n *\n * @param req The request object sent by the application.\n */\n protected _isPopup(req: Request): boolean {\n const popup = req.query[this._options.popup.variable];\n return !!(popup && String(popup).toLowerCase() === 'true');\n }\n /**\n * Helper method that checks if the \"latest version\" is enabled and if the given version\n * is \"the latest\" (comparing it with the option name).\n *\n * @param version The version received in the request.\n */\n protected _isTheAllowedLatest(version: string): boolean {\n const { allow, name } = this._options.latest;\n return allow && version === name;\n }\n}\n/**\n * A middleware that will validate a `version` request parameter against the application\n * version, and generate an error if they don't match.\n * This is a \"middleware/controller\" because the wrappers for both are the same, the\n * difference is that, for controllers, Jimpex sends a second parameter with the route\n * where they are mounted.\n * By validating the route parameter, the function can know whether the implementation is\n * going to use the middleware by itself or as a route middleware.\n * If used as middleware, it will just return the result of\n * {@link VersionValidator.getMiddleware}; but if used as controller, it will mount it on\n * `[route]/:version/*`.\n *\n * @group Middlewares\n * @group Middlewares/VersionValidator\n */\nexport const versionValidatorMiddleware = middlewareCreator(\n (options: VersionValidatorMiddlewareOptions = {}) =>\n (app, route) => {\n const version = app.getConfig<string>('version');\n const middleware = new VersionValidator({\n inject: {\n HTTPError: app.get('HTTPError'),\n responsesBuilder: app.get('responsesBuilder'),\n statuses: app.get('statuses'),\n },\n version,\n ...options,\n }).getMiddleware();\n\n if (route) {\n const router = app.getRouter();\n return router.all('/:version/*', middleware);\n }\n\n return middleware;\n },\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAAwC;AACxC,mBAAiD;AAyI1C,MAAM,iBAAiB;AAAA,EAqB5B,YAAY,EAAE,QAAQ,YAAY,QAAQ,GAAuC;AAjBjF,wBAAmB;AAInB,wBAAmB;AAInB,wBAAmB;AAInB,wBAAmB;AAMjB,SAAK,aAAa,OAAO;AACzB,SAAK,oBAAoB,OAAO;AAChC,SAAK,YAAY,OAAO;AACxB,SAAK,eAAW;AAAA,MACd;AAAA,QACE,OAAO;AAAA,QACP,QAAQ;AAAA,UACN,OAAO;AAAA,UACP,MAAM;AAAA,QACR;AAAA,QACA,OAAO;AAAA,UACL,UAAU;AAAA,UACV,OAAO;AAAA,UACP,SAAS;AAAA,QACX;AAAA,QACA;AAAA,MACF;AAAA,MACA;AAAA,IACF;AAEA,QAAI,CAAC,KAAK,SAAS,SAAS;AAC1B,YAAM,IAAI,MAAM,8BAA8B;AAAA,IAChD;AAAA,EACF;AAAA,EAIA,gBAAmC;AACjC,WAAO,CAAC,KAAK,KAAK,SAAS;AAEzB,YAAM,EAAE,QAAQ,IAAI,IAAI;AAExB,UAAI,CAAC,SAAS;AACZ,aAAK;AACL;AAAA,MACF;AAEA,UAAI,YAAY,KAAK,SAAS,WAAW,KAAK,oBAAoB,OAAO,GAAG;AAC1E,aAAK;AACL;AAAA,MACF;AAEA,YAAM,SAAS,KAAK,UAAU,UAAU;AAExC,UAAI,KAAK,SAAS,GAAG,GAAG;AACtB,cAAM,EAAE,OAAO,QAAQ,IAAI,KAAK,SAAS;AACzC,aAAK,kBAAkB,gBAAgB;AAAA,UACrC;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,QACF,CAAC;AACD;AAAA,MACF;AAGA;AAAA,QACE,IAAI,KAAK,WAAW,KAAK,SAAS,OAAO,QAAQ;AAAA,UAC/C,UAAU;AAAA,YACR,YAAY;AAAA,UACd;AAAA,QACF,CAAC;AAAA,MACH;AAAA,IACF;AAAA,EACF;AAAA,EAIA,IAAI,UAA6C;AAC/C,eAAO,4CAAwB,CAAC,GAAG,KAAK,QAAQ;AAAA,EAClD;AAAA,EAOU,SAAS,KAAuB;AACxC,UAAM,QAAQ,IAAI,MAAM,KAAK,SAAS,MAAM;AAC5C,WAAO,CAAC,EAAE,SAAS,OAAO,KAAK,EAAE,YAAY,MAAM;AAAA,EACrD;AAAA,EAOU,oBAAoB,SAA0B;AACtD,UAAM,EAAE,OAAO,KAAK,IAAI,KAAK,SAAS;AACtC,WAAO,SAAS,YAAY;AAAA,EAC9B;AACF;AAgBO,MAAM,iCAA6B;AAAA,EACxC,CAAC,UAA6C,CAAC,MAC7C,CAAC,KAAK,UAAU;AACd,UAAM,UAAU,IAAI,UAAkB,SAAS;AAC/C,UAAM,aAAa,IAAI,iBAAiB;AAAA,MACtC,QAAQ;AAAA,QACN,WAAW,IAAI,IAAI,WAAW;AAAA,QAC9B,kBAAkB,IAAI,IAAI,kBAAkB;AAAA,QAC5C,UAAU,IAAI,IAAI,UAAU;AAAA,MAC9B;AAAA,MACA;AAAA,MACA,GAAG;AAAA,IACL,CAAC,EAAE,cAAc;AAEjB,QAAI,OAAO;AACT,YAAM,SAAS,IAAI,UAAU;AAC7B,aAAO,OAAO,IAAI,eAAe,UAAU;AAAA,IAC7C;AAEA,WAAO;AAAA,EACT;AACJ;","names":[]}
@@ -0,0 +1,138 @@
1
+ import * as _homer0_jimple from '@homer0/jimple';
2
+ import { J as Jimpex } from '../../jimpex-7eaee271.js';
3
+ import { Statuses } from '../../utils/fns/statuses.js';
4
+ import '@homer0/events-hub';
5
+ import '../../types/express.js';
6
+ import 'express';
7
+ import '../../types/http.js';
8
+ import 'https';
9
+ import 'http';
10
+ import 'spdy';
11
+ import 'node-fetch';
12
+ import '@homer0/simple-config';
13
+ import '../../types/utils.js';
14
+ import '@homer0/simple-logger';
15
+ import 'statuses';
16
+
17
+ /**
18
+ * A dictionary with some context information that can be provided to {@link AppError}.
19
+ *
20
+ * @group Services/AppError
21
+ */
22
+ type AppErrorContext = {
23
+ /**
24
+ * Extra information that the error handler can pick and include the response.
25
+ */
26
+ response?: unknown;
27
+ /**
28
+ * A status code or name for the error handler to set in the response.
29
+ */
30
+ status?: string | number;
31
+ } & Record<string, unknown>;
32
+ /**
33
+ * A simple subclass of `Error` but with support for context information.
34
+ *
35
+ * @group Services
36
+ * @group Services/AppError
37
+ */
38
+ declare class AppError extends Error {
39
+ /**
40
+ * The date of when the error was generated.
41
+ */
42
+ readonly _date: Date;
43
+ /**
44
+ * The context information that can be provided to the error, and picked by the error
45
+ * handler.
46
+ */
47
+ readonly _context: AppErrorContext;
48
+ /**
49
+ * The service that generates HTTP status codes.
50
+ */
51
+ protected _statuses: Statuses;
52
+ /**
53
+ * @param message The message of the error.
54
+ * @param context The context information, for the error handler.
55
+ * @param statuses A reference to the service that generates HTTP status codes. This
56
+ * is in case the implementation wants to use a special version from
57
+ * the container; otherwise, it will use the `statuses` library
58
+ * directly.
59
+ */
60
+ constructor(message: string, context?: AppErrorContext, statuses?: Statuses);
61
+ /**
62
+ * Gets an object that can be included in a response from the application. This method
63
+ * is a helper for the `response` getter, as it allows for the assertion of the response
64
+ * type.
65
+ *
66
+ * @template T The type of the response.
67
+ */
68
+ getResponse<T>(): T;
69
+ /**
70
+ * Information about the error that can be included in a response. This is set using the
71
+ * `response` key in the `context` option.
72
+ */
73
+ get response(): unknown;
74
+ /**
75
+ * An HTTP status code related to the error. This is set using the `status` key on the
76
+ * `context`.
77
+ */
78
+ get status(): number | undefined;
79
+ /**
80
+ * Context information related to the error.
81
+ */
82
+ get context(): unknown;
83
+ /**
84
+ * The date of when the error was generated.
85
+ */
86
+ get date(): Date;
87
+ /**
88
+ * Utility method that formats the context before saving it in the instance:
89
+ * - If the context includes a `status` as a `string`, it will try to replace it with
90
+ * its actual status code from the `statuses `service.
91
+ *
92
+ * @param context The original context sent to the constructor.
93
+ */
94
+ protected _parseContext(context: AppErrorContext): AppErrorContext;
95
+ }
96
+ /**
97
+ * Shorthand for `new AppError()`.
98
+ *
99
+ * @param args The same parameters as the {@link AppError} constructor.
100
+ * @returns A new instance of {@link AppError}.
101
+ * @group Services
102
+ * @group Services/AppError
103
+ */
104
+ declare const createAppError: (message: string, context?: AppErrorContext | undefined, statuses?: Statuses | undefined) => AppError;
105
+ /**
106
+ * The type of the function that generates a new instance of {@link AppError}.
107
+ * This is exported to make it easy to type the dependency injection.
108
+ *
109
+ * @group Services/AppError
110
+ */
111
+ type CreateAppErrorFn = typeof createAppError;
112
+ /**
113
+ * THe type of the {@link AppError} class.
114
+ * This is exported to make it easy to type the dependency injection.
115
+ *
116
+ * @group Services/AppError
117
+ */
118
+ type AppErrorClass = typeof AppError;
119
+ /**
120
+ * A service provider that will register both, {@link AppError} and
121
+ * {@link createAppError}, on the container. `AppError` will be the key for class, and
122
+ * `appError` will be for the generator function.
123
+ *
124
+ * @example
125
+ *
126
+ * // Register it on the container
127
+ * container.register(appErrorProvider);
128
+ * // Getting access to the class.
129
+ * const AppError = container.get<AppErrorClass>('AppError');
130
+ * // Getting access to the function.
131
+ * const appError = container.get<CreateAppErrorFn>('appError');
132
+ *
133
+ * @group Providers
134
+ * @group Services/AppError
135
+ */
136
+ declare const appErrorProvider: _homer0_jimple.Resource<"provider", "register", _homer0_jimple.ProviderRegisterFn<Jimpex>>;
137
+
138
+ export { AppError, AppErrorClass, AppErrorContext, CreateAppErrorFn, appErrorProvider, createAppError };
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+ var __publicField = (obj, key, value) => {
21
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
22
+ return value;
23
+ };
24
+ var appError_exports = {};
25
+ __export(appError_exports, {
26
+ AppError: () => AppError,
27
+ appErrorProvider: () => appErrorProvider,
28
+ createAppError: () => createAppError
29
+ });
30
+ module.exports = __toCommonJS(appError_exports);
31
+ var import_utils = require("../../utils");
32
+ class AppError extends Error {
33
+ constructor(message, context = {}, statuses = import_utils.statuses) {
34
+ super(message);
35
+ __publicField(this, "_date");
36
+ __publicField(this, "_context");
37
+ __publicField(this, "_statuses");
38
+ this.name = this.constructor.name;
39
+ this._date = new Date();
40
+ this._statuses = statuses;
41
+ this._context = this._parseContext(context);
42
+ if (Error.captureStackTrace) {
43
+ Error.captureStackTrace(this, this.constructor);
44
+ }
45
+ }
46
+ getResponse() {
47
+ return this.response;
48
+ }
49
+ get response() {
50
+ return this._context.response || {};
51
+ }
52
+ get status() {
53
+ return this._context.status;
54
+ }
55
+ get context() {
56
+ return this._context;
57
+ }
58
+ get date() {
59
+ return this._date;
60
+ }
61
+ _parseContext(context) {
62
+ const result = { ...context };
63
+ if (result.status && typeof result.status === "string") {
64
+ result.status = this._statuses.code[result.status.toLowerCase()] || result.status;
65
+ }
66
+ return result;
67
+ }
68
+ }
69
+ const createAppError = (...args) => new AppError(...args);
70
+ const appErrorProvider = (0, import_utils.provider)((app) => {
71
+ app.set("AppError", () => AppError);
72
+ app.set("appError", () => createAppError);
73
+ });
74
+ // Annotate the CommonJS export names for ESM import in node:
75
+ 0 && (module.exports = {
76
+ AppError,
77
+ appErrorProvider,
78
+ createAppError
79
+ });
80
+ //# sourceMappingURL=appError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/services/common/appError.ts"],"sourcesContent":["import { provider, statuses as statusesFn, type Statuses } from '../../utils';\n/**\n * A dictionary with some context information that can be provided to {@link AppError}.\n *\n * @group Services/AppError\n */\nexport type AppErrorContext = {\n /**\n * Extra information that the error handler can pick and include the response.\n */\n response?: unknown;\n /**\n * A status code or name for the error handler to set in the response.\n */\n status?: string | number;\n} & Record<string, unknown>;\n/**\n * A simple subclass of `Error` but with support for context information.\n *\n * @group Services\n * @group Services/AppError\n */\nexport class AppError extends Error {\n /**\n * The date of when the error was generated.\n */\n readonly _date: Date;\n /**\n * The context information that can be provided to the error, and picked by the error\n * handler.\n */\n readonly _context: AppErrorContext;\n /**\n * The service that generates HTTP status codes.\n */\n protected _statuses: Statuses;\n /**\n * @param message The message of the error.\n * @param context The context information, for the error handler.\n * @param statuses A reference to the service that generates HTTP status codes. This\n * is in case the implementation wants to use a special version from\n * the container; otherwise, it will use the `statuses` library\n * directly.\n */\n constructor(\n message: string,\n context: AppErrorContext = {},\n statuses: Statuses = statusesFn,\n ) {\n super(message);\n this.name = this.constructor.name;\n this._date = new Date();\n this._statuses = statuses;\n this._context = this._parseContext(context);\n\n // Limit the stack trace if possible.\n if (Error.captureStackTrace) {\n Error.captureStackTrace(this, this.constructor);\n }\n }\n /**\n * Gets an object that can be included in a response from the application. This method\n * is a helper for the `response` getter, as it allows for the assertion of the response\n * type.\n *\n * @template T The type of the response.\n */\n getResponse<T>(): T {\n return this.response as T;\n }\n /**\n * Information about the error that can be included in a response. This is set using the\n * `response` key in the `context` option.\n */\n get response(): unknown {\n return this._context.response || {};\n }\n /**\n * An HTTP status code related to the error. This is set using the `status` key on the\n * `context`.\n */\n get status(): number | undefined {\n return this._context.status as number | undefined;\n }\n /**\n * Context information related to the error.\n */\n get context(): unknown {\n return this._context;\n }\n /**\n * The date of when the error was generated.\n */\n get date(): Date {\n return this._date;\n }\n /**\n * Utility method that formats the context before saving it in the instance:\n * - If the context includes a `status` as a `string`, it will try to replace it with\n * its actual status code from the `statuses `service.\n *\n * @param context The original context sent to the constructor.\n */\n protected _parseContext(context: AppErrorContext): AppErrorContext {\n const result = { ...context };\n if (result.status && typeof result.status === 'string') {\n result.status = this._statuses.code[result.status.toLowerCase()] || result.status;\n }\n\n return result;\n }\n}\n/**\n * Shorthand for `new AppError()`.\n *\n * @param args The same parameters as the {@link AppError} constructor.\n * @returns A new instance of {@link AppError}.\n * @group Services\n * @group Services/AppError\n */\nexport const createAppError = (\n ...args: ConstructorParameters<typeof AppError>\n): AppError => new AppError(...args);\n/**\n * The type of the function that generates a new instance of {@link AppError}.\n * This is exported to make it easy to type the dependency injection.\n *\n * @group Services/AppError\n */\nexport type CreateAppErrorFn = typeof createAppError;\n/**\n * THe type of the {@link AppError} class.\n * This is exported to make it easy to type the dependency injection.\n *\n * @group Services/AppError\n */\nexport type AppErrorClass = typeof AppError;\n/**\n * A service provider that will register both, {@link AppError} and\n * {@link createAppError}, on the container. `AppError` will be the key for class, and\n * `appError` will be for the generator function.\n *\n * @example\n *\n * // Register it on the container\n * container.register(appErrorProvider);\n * // Getting access to the class.\n * const AppError = container.get<AppErrorClass>('AppError');\n * // Getting access to the function.\n * const appError = container.get<CreateAppErrorFn>('appError');\n *\n * @group Providers\n * @group Services/AppError\n */\nexport const appErrorProvider = provider((app) => {\n app.set('AppError', () => AppError);\n app.set('appError', () => createAppError);\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAgE;AAsBzD,MAAM,iBAAiB,MAAM;AAAA,EAsBlC,YACE,SACA,UAA2B,CAAC,GAC5B,WAAqB,aAAAA,UACrB;AACA,UAAM,OAAO;AAvBf,wBAAS;AAKT,wBAAS;AAIT,wBAAU;AAeR,SAAK,OAAO,KAAK,YAAY;AAC7B,SAAK,QAAQ,IAAI,KAAK;AACtB,SAAK,YAAY;AACjB,SAAK,WAAW,KAAK,cAAc,OAAO;AAG1C,QAAI,MAAM,mBAAmB;AAC3B,YAAM,kBAAkB,MAAM,KAAK,WAAW;AAAA,IAChD;AAAA,EACF;AAAA,EAQA,cAAoB;AAClB,WAAO,KAAK;AAAA,EACd;AAAA,EAKA,IAAI,WAAoB;AACtB,WAAO,KAAK,SAAS,YAAY,CAAC;AAAA,EACpC;AAAA,EAKA,IAAI,SAA6B;AAC/B,WAAO,KAAK,SAAS;AAAA,EACvB;AAAA,EAIA,IAAI,UAAmB;AACrB,WAAO,KAAK;AAAA,EACd;AAAA,EAIA,IAAI,OAAa;AACf,WAAO,KAAK;AAAA,EACd;AAAA,EAQU,cAAc,SAA2C;AACjE,UAAM,SAAS,EAAE,GAAG,QAAQ;AAC5B,QAAI,OAAO,UAAU,OAAO,OAAO,WAAW,UAAU;AACtD,aAAO,SAAS,KAAK,UAAU,KAAK,OAAO,OAAO,YAAY,MAAM,OAAO;AAAA,IAC7E;AAEA,WAAO;AAAA,EACT;AACF;AASO,MAAM,iBAAiB,IACzB,SACU,IAAI,SAAS,GAAG,IAAI;AAgC5B,MAAM,uBAAmB,uBAAS,CAAC,QAAQ;AAChD,MAAI,IAAI,YAAY,MAAM,QAAQ;AAClC,MAAI,IAAI,YAAY,MAAM,cAAc;AAC1C,CAAC;","names":["statusesFn"]}