jimpex 7.0.2 → 9.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 (438) hide show
  1. package/CHANGELOG.md +93 -0
  2. package/LICENSE +1 -1
  3. package/README.md +447 -435
  4. package/dist/app/index.d.mts +14 -0
  5. package/dist/app/index.d.ts +14 -0
  6. package/dist/app/index.js +23 -0
  7. package/dist/app/index.js.map +1 -0
  8. package/dist/app/jimpex.d.mts +14 -0
  9. package/dist/app/jimpex.d.ts +14 -0
  10. package/dist/app/jimpex.js +665 -0
  11. package/dist/app/jimpex.js.map +1 -0
  12. package/dist/controllers/common/config.d.mts +79 -0
  13. package/dist/controllers/common/config.d.ts +79 -0
  14. package/dist/controllers/common/config.js +107 -0
  15. package/dist/controllers/common/config.js.map +1 -0
  16. package/dist/controllers/common/health.d.mts +83 -0
  17. package/dist/controllers/common/health.d.ts +83 -0
  18. package/dist/controllers/common/health.js +115 -0
  19. package/dist/controllers/common/health.js.map +1 -0
  20. package/dist/controllers/common/index.d.mts +21 -0
  21. package/dist/controllers/common/index.d.ts +21 -0
  22. package/dist/controllers/common/index.js +27 -0
  23. package/dist/controllers/common/index.js.map +1 -0
  24. package/dist/controllers/common/statics.d.mts +215 -0
  25. package/dist/controllers/common/statics.d.ts +215 -0
  26. package/dist/controllers/common/statics.js +253 -0
  27. package/dist/controllers/common/statics.js.map +1 -0
  28. package/dist/controllers/index.d.mts +24 -0
  29. package/dist/controllers/index.d.ts +24 -0
  30. package/dist/controllers/index.js +25 -0
  31. package/dist/controllers/index.js.map +1 -0
  32. package/dist/controllers/utils/gateway.d.mts +725 -0
  33. package/dist/controllers/utils/gateway.d.ts +725 -0
  34. package/dist/controllers/utils/gateway.js +577 -0
  35. package/dist/controllers/utils/gateway.js.map +1 -0
  36. package/dist/controllers/utils/index.d.mts +17 -0
  37. package/dist/controllers/utils/index.d.ts +17 -0
  38. package/dist/controllers/utils/index.js +23 -0
  39. package/dist/controllers/utils/index.js.map +1 -0
  40. package/dist/esm/app/index.js +2 -0
  41. package/dist/esm/app/index.js.map +1 -0
  42. package/dist/esm/app/jimpex.js +636 -0
  43. package/dist/esm/app/jimpex.js.map +1 -0
  44. package/dist/esm/chunk-2B2CG5KL.js +11 -0
  45. package/dist/esm/chunk-2B2CG5KL.js.map +1 -0
  46. package/dist/esm/controllers/common/config.js +80 -0
  47. package/dist/esm/controllers/common/config.js.map +1 -0
  48. package/dist/esm/controllers/common/health.js +88 -0
  49. package/dist/esm/controllers/common/health.js.map +1 -0
  50. package/dist/esm/controllers/common/index.js +4 -0
  51. package/dist/esm/controllers/common/index.js.map +1 -0
  52. package/dist/esm/controllers/common/statics.js +220 -0
  53. package/dist/esm/controllers/common/statics.js.map +1 -0
  54. package/dist/esm/controllers/index.js +3 -0
  55. package/dist/esm/controllers/index.js.map +1 -0
  56. package/dist/esm/controllers/utils/gateway.js +556 -0
  57. package/dist/esm/controllers/utils/gateway.js.map +1 -0
  58. package/dist/esm/controllers/utils/index.js +2 -0
  59. package/dist/esm/controllers/utils/index.js.map +1 -0
  60. package/dist/esm/index.js +7 -0
  61. package/dist/esm/index.js.map +1 -0
  62. package/dist/esm/middlewares/common/errorHandler.js +116 -0
  63. package/dist/esm/middlewares/common/errorHandler.js.map +1 -0
  64. package/dist/esm/middlewares/common/forceHTTPS.js +53 -0
  65. package/dist/esm/middlewares/common/forceHTTPS.js.map +1 -0
  66. package/dist/esm/middlewares/common/hsts.js +74 -0
  67. package/dist/esm/middlewares/common/hsts.js.map +1 -0
  68. package/dist/esm/middlewares/common/index.js +4 -0
  69. package/dist/esm/middlewares/common/index.js.map +1 -0
  70. package/dist/esm/middlewares/html/fastHTML.js +158 -0
  71. package/dist/esm/middlewares/html/fastHTML.js.map +1 -0
  72. package/dist/esm/middlewares/html/index.js +3 -0
  73. package/dist/esm/middlewares/html/index.js.map +1 -0
  74. package/dist/esm/middlewares/html/showHTML.js +100 -0
  75. package/dist/esm/middlewares/html/showHTML.js.map +1 -0
  76. package/dist/esm/middlewares/index.js +4 -0
  77. package/dist/esm/middlewares/index.js.map +1 -0
  78. package/dist/esm/middlewares/utils/index.js +2 -0
  79. package/dist/esm/middlewares/utils/index.js.map +1 -0
  80. package/dist/esm/middlewares/utils/versionValidator.js +135 -0
  81. package/dist/esm/middlewares/utils/versionValidator.js.map +1 -0
  82. package/dist/esm/services/common/appError.js +98 -0
  83. package/dist/esm/services/common/appError.js.map +1 -0
  84. package/dist/esm/services/common/httpError.js +28 -0
  85. package/dist/esm/services/common/httpError.js.map +1 -0
  86. package/dist/esm/services/common/index.js +17 -0
  87. package/dist/esm/services/common/index.js.map +1 -0
  88. package/dist/esm/services/common/sendFile.js +27 -0
  89. package/dist/esm/services/common/sendFile.js.map +1 -0
  90. package/dist/esm/services/frontend/frontendFs.js +66 -0
  91. package/dist/esm/services/frontend/frontendFs.js.map +1 -0
  92. package/dist/esm/services/frontend/index.js +11 -0
  93. package/dist/esm/services/frontend/index.js.map +1 -0
  94. package/dist/esm/services/html/htmlGenerator.js +194 -0
  95. package/dist/esm/services/html/htmlGenerator.js.map +1 -0
  96. package/dist/esm/services/html/index.js +11 -0
  97. package/dist/esm/services/html/index.js.map +1 -0
  98. package/dist/esm/services/http/apiClient.js +97 -0
  99. package/dist/esm/services/http/apiClient.js.map +1 -0
  100. package/dist/esm/services/http/http.js +174 -0
  101. package/dist/esm/services/http/http.js.map +1 -0
  102. package/dist/esm/services/http/index.js +17 -0
  103. package/dist/esm/services/http/index.js.map +1 -0
  104. package/dist/esm/services/http/responsesBuilder.js +152 -0
  105. package/dist/esm/services/http/responsesBuilder.js.map +1 -0
  106. package/dist/esm/services/index.js +6 -0
  107. package/dist/esm/services/index.js.map +1 -0
  108. package/dist/esm/services/utils/ensureBearerToken.js +94 -0
  109. package/dist/esm/services/utils/ensureBearerToken.js.map +1 -0
  110. package/dist/esm/services/utils/index.js +11 -0
  111. package/dist/esm/services/utils/index.js.map +1 -0
  112. package/dist/esm/types/events.js +1 -0
  113. package/dist/esm/types/events.js.map +1 -0
  114. package/dist/esm/types/express.js +1 -0
  115. package/dist/esm/types/express.js.map +1 -0
  116. package/dist/esm/types/http.js +1 -0
  117. package/dist/esm/types/http.js.map +1 -0
  118. package/dist/esm/types/index.js +7 -0
  119. package/dist/esm/types/index.js.map +1 -0
  120. package/dist/esm/types/options.js +1 -0
  121. package/dist/esm/types/options.js.map +1 -0
  122. package/dist/esm/types/utils.js +1 -0
  123. package/dist/esm/types/utils.js.map +1 -0
  124. package/dist/esm/types/wootils.js +1 -0
  125. package/dist/esm/types/wootils.js.map +1 -0
  126. package/dist/esm/utils/fns/index.js +5 -0
  127. package/dist/esm/utils/fns/index.js.map +1 -0
  128. package/dist/esm/utils/fns/others.js +6 -0
  129. package/dist/esm/utils/fns/others.js.map +1 -0
  130. package/dist/esm/utils/fns/routes.js +25 -0
  131. package/dist/esm/utils/fns/routes.js.map +1 -0
  132. package/dist/esm/utils/fns/statuses.js +6 -0
  133. package/dist/esm/utils/fns/statuses.js.map +1 -0
  134. package/dist/esm/utils/fns/text.js +6 -0
  135. package/dist/esm/utils/fns/text.js.map +1 -0
  136. package/dist/esm/utils/index.js +3 -0
  137. package/dist/esm/utils/index.js.map +1 -0
  138. package/dist/esm/utils/wrappers.js +41 -0
  139. package/dist/esm/utils/wrappers.js.map +1 -0
  140. package/dist/index-b2a04c78.d.ts +1282 -0
  141. package/dist/index-efeb437e.d.ts +1282 -0
  142. package/dist/index.d.mts +46 -0
  143. package/dist/index.d.ts +46 -0
  144. package/dist/index.js +33 -0
  145. package/dist/index.js.map +1 -0
  146. package/dist/middlewares/common/errorHandler.d.mts +132 -0
  147. package/dist/middlewares/common/errorHandler.d.ts +132 -0
  148. package/dist/middlewares/common/errorHandler.js +143 -0
  149. package/dist/middlewares/common/errorHandler.js.map +1 -0
  150. package/dist/middlewares/common/forceHTTPS.d.mts +69 -0
  151. package/dist/middlewares/common/forceHTTPS.d.ts +69 -0
  152. package/dist/middlewares/common/forceHTTPS.js +80 -0
  153. package/dist/middlewares/common/forceHTTPS.js.map +1 -0
  154. package/dist/middlewares/common/hsts.d.mts +110 -0
  155. package/dist/middlewares/common/hsts.d.ts +110 -0
  156. package/dist/middlewares/common/hsts.js +101 -0
  157. package/dist/middlewares/common/hsts.js.map +1 -0
  158. package/dist/middlewares/common/index.d.mts +22 -0
  159. package/dist/middlewares/common/index.d.ts +22 -0
  160. package/dist/middlewares/common/index.js +27 -0
  161. package/dist/middlewares/common/index.js.map +1 -0
  162. package/dist/middlewares/html/fastHTML.d.mts +180 -0
  163. package/dist/middlewares/html/fastHTML.d.ts +180 -0
  164. package/dist/middlewares/html/fastHTML.js +185 -0
  165. package/dist/middlewares/html/fastHTML.js.map +1 -0
  166. package/dist/middlewares/html/index.d.mts +21 -0
  167. package/dist/middlewares/html/index.d.ts +21 -0
  168. package/dist/middlewares/html/index.js +25 -0
  169. package/dist/middlewares/html/index.js.map +1 -0
  170. package/dist/middlewares/html/showHTML.d.mts +127 -0
  171. package/dist/middlewares/html/showHTML.d.ts +127 -0
  172. package/dist/middlewares/html/showHTML.js +127 -0
  173. package/dist/middlewares/html/showHTML.js.map +1 -0
  174. package/dist/middlewares/index.d.mts +30 -0
  175. package/dist/middlewares/index.d.ts +30 -0
  176. package/dist/middlewares/index.js +27 -0
  177. package/dist/middlewares/index.js.map +1 -0
  178. package/dist/middlewares/utils/index.d.mts +20 -0
  179. package/dist/middlewares/utils/index.d.ts +20 -0
  180. package/dist/middlewares/utils/index.js +23 -0
  181. package/dist/middlewares/utils/index.js.map +1 -0
  182. package/dist/middlewares/utils/versionValidator.d.mts +215 -0
  183. package/dist/middlewares/utils/versionValidator.d.ts +215 -0
  184. package/dist/middlewares/utils/versionValidator.js +162 -0
  185. package/dist/middlewares/utils/versionValidator.js.map +1 -0
  186. package/dist/services/common/appError.d.mts +139 -0
  187. package/dist/services/common/appError.d.ts +139 -0
  188. package/dist/services/common/appError.js +126 -0
  189. package/dist/services/common/appError.js.map +1 -0
  190. package/dist/services/common/httpError.d.mts +80 -0
  191. package/dist/services/common/httpError.d.ts +80 -0
  192. package/dist/services/common/httpError.js +53 -0
  193. package/dist/services/common/httpError.js.map +1 -0
  194. package/dist/services/common/index.d.mts +47 -0
  195. package/dist/services/common/index.d.ts +47 -0
  196. package/dist/services/common/index.js +44 -0
  197. package/dist/services/common/index.js.map +1 -0
  198. package/dist/services/common/sendFile.d.mts +102 -0
  199. package/dist/services/common/sendFile.d.ts +102 -0
  200. package/dist/services/common/sendFile.js +51 -0
  201. package/dist/services/common/sendFile.js.map +1 -0
  202. package/dist/services/frontend/frontendFs.d.mts +96 -0
  203. package/dist/services/frontend/frontendFs.d.ts +96 -0
  204. package/dist/services/frontend/frontendFs.js +103 -0
  205. package/dist/services/frontend/frontendFs.js.map +1 -0
  206. package/dist/services/frontend/index.d.mts +40 -0
  207. package/dist/services/frontend/index.d.ts +40 -0
  208. package/dist/services/frontend/index.js +36 -0
  209. package/dist/services/frontend/index.js.map +1 -0
  210. package/dist/services/html/htmlGenerator.d.mts +237 -0
  211. package/dist/services/html/htmlGenerator.d.ts +237 -0
  212. package/dist/services/html/htmlGenerator.js +221 -0
  213. package/dist/services/html/htmlGenerator.js.map +1 -0
  214. package/dist/services/html/index.d.mts +43 -0
  215. package/dist/services/html/index.d.ts +43 -0
  216. package/dist/services/html/index.js +36 -0
  217. package/dist/services/html/index.js.map +1 -0
  218. package/dist/services/http/apiClient.d.mts +170 -0
  219. package/dist/services/http/apiClient.d.ts +170 -0
  220. package/dist/services/http/apiClient.js +122 -0
  221. package/dist/services/http/apiClient.js.map +1 -0
  222. package/dist/services/http/http.d.mts +176 -0
  223. package/dist/services/http/http.d.ts +176 -0
  224. package/dist/services/http/http.js +211 -0
  225. package/dist/services/http/http.js.map +1 -0
  226. package/dist/services/http/index.d.mts +51 -0
  227. package/dist/services/http/index.d.ts +51 -0
  228. package/dist/services/http/index.js +44 -0
  229. package/dist/services/http/index.js.map +1 -0
  230. package/dist/services/http/responsesBuilder.d.mts +179 -0
  231. package/dist/services/http/responsesBuilder.d.ts +179 -0
  232. package/dist/services/http/responsesBuilder.js +179 -0
  233. package/dist/services/http/responsesBuilder.js.map +1 -0
  234. package/dist/services/index.d.mts +33 -0
  235. package/dist/services/index.d.ts +33 -0
  236. package/dist/services/index.js +31 -0
  237. package/dist/services/index.js.map +1 -0
  238. package/dist/services/utils/ensureBearerToken.d.mts +158 -0
  239. package/dist/services/utils/ensureBearerToken.d.ts +158 -0
  240. package/dist/services/utils/ensureBearerToken.js +121 -0
  241. package/dist/services/utils/ensureBearerToken.js.map +1 -0
  242. package/dist/services/utils/index.d.mts +44 -0
  243. package/dist/services/utils/index.d.ts +44 -0
  244. package/dist/services/utils/index.js +36 -0
  245. package/dist/services/utils/index.js.map +1 -0
  246. package/dist/types/events.d.mts +14 -0
  247. package/dist/types/events.d.ts +14 -0
  248. package/dist/types/events.js +17 -0
  249. package/dist/types/events.js.map +1 -0
  250. package/dist/types/express.d.mts +10 -0
  251. package/dist/types/express.d.ts +10 -0
  252. package/dist/types/express.js +17 -0
  253. package/dist/types/express.js.map +1 -0
  254. package/dist/types/http.d.mts +79 -0
  255. package/dist/types/http.d.ts +79 -0
  256. package/dist/types/http.js +17 -0
  257. package/dist/types/http.js.map +1 -0
  258. package/dist/types/index.d.mts +14 -0
  259. package/dist/types/index.d.ts +14 -0
  260. package/dist/types/index.js +33 -0
  261. package/dist/types/index.js.map +1 -0
  262. package/dist/types/options.d.mts +14 -0
  263. package/dist/types/options.d.ts +14 -0
  264. package/dist/types/options.js +17 -0
  265. package/dist/types/options.js.map +1 -0
  266. package/dist/types/utils.d.mts +48 -0
  267. package/dist/types/utils.d.ts +48 -0
  268. package/dist/types/utils.js +17 -0
  269. package/dist/types/utils.js.map +1 -0
  270. package/dist/types/wootils.d.mts +4 -0
  271. package/dist/types/wootils.d.ts +4 -0
  272. package/dist/types/wootils.js +17 -0
  273. package/dist/types/wootils.js.map +1 -0
  274. package/dist/utils/fns/index.d.mts +5 -0
  275. package/dist/utils/fns/index.d.ts +5 -0
  276. package/dist/utils/fns/index.js +29 -0
  277. package/dist/utils/fns/index.js.map +1 -0
  278. package/dist/utils/fns/others.d.mts +17 -0
  279. package/dist/utils/fns/others.d.ts +17 -0
  280. package/dist/utils/fns/others.js +29 -0
  281. package/dist/utils/fns/others.js.map +1 -0
  282. package/dist/utils/fns/routes.d.mts +39 -0
  283. package/dist/utils/fns/routes.d.ts +39 -0
  284. package/dist/utils/fns/routes.js +51 -0
  285. package/dist/utils/fns/routes.js.map +1 -0
  286. package/dist/utils/fns/statuses.d.mts +45 -0
  287. package/dist/utils/fns/statuses.d.ts +45 -0
  288. package/dist/utils/fns/statuses.js +39 -0
  289. package/dist/utils/fns/statuses.js.map +1 -0
  290. package/dist/utils/fns/text.d.mts +9 -0
  291. package/dist/utils/fns/text.d.ts +9 -0
  292. package/dist/utils/fns/text.js +29 -0
  293. package/dist/utils/fns/text.js.map +1 -0
  294. package/dist/utils/index.d.mts +19 -0
  295. package/dist/utils/index.d.ts +19 -0
  296. package/dist/utils/index.js +25 -0
  297. package/dist/utils/index.js.map +1 -0
  298. package/dist/utils/wrappers.d.mts +14 -0
  299. package/dist/utils/wrappers.d.ts +14 -0
  300. package/dist/utils/wrappers.js +68 -0
  301. package/dist/utils/wrappers.js.map +1 -0
  302. package/examples/basic/404.html +12 -0
  303. package/examples/basic/README.md +30 -0
  304. package/examples/basic/app.ts +18 -0
  305. package/examples/basic/controller.ts +45 -0
  306. package/examples/basic/index.ts +19 -0
  307. package/examples/basic/middleware.ts +13 -0
  308. package/examples/basic/service.ts +11 -0
  309. package/package.json +60 -39
  310. package/src/app/index.ts +1 -0
  311. package/src/app/jimpex.ts +743 -0
  312. package/src/controllers/common/config.ts +115 -0
  313. package/src/controllers/common/health.ts +128 -0
  314. package/src/controllers/common/index.ts +3 -0
  315. package/src/controllers/common/statics.ts +380 -0
  316. package/src/controllers/index.ts +2 -0
  317. package/src/controllers/utils/gateway.ts +1186 -0
  318. package/src/controllers/utils/index.ts +1 -0
  319. package/src/index.ts +6 -0
  320. package/src/middlewares/common/errorHandler.ts +203 -0
  321. package/src/middlewares/common/forceHTTPS.ts +83 -0
  322. package/src/middlewares/common/hsts.ts +135 -0
  323. package/src/middlewares/common/index.ts +3 -0
  324. package/src/middlewares/html/fastHTML.ts +255 -0
  325. package/src/middlewares/html/index.ts +2 -0
  326. package/src/middlewares/html/showHTML.ts +165 -0
  327. package/src/middlewares/index.ts +3 -0
  328. package/src/middlewares/utils/index.ts +1 -0
  329. package/src/middlewares/utils/versionValidator.ts +289 -0
  330. package/src/services/common/appError.ts +158 -0
  331. package/src/services/common/httpError.ts +74 -0
  332. package/src/services/common/index.ts +29 -0
  333. package/src/services/common/sendFile.ts +106 -0
  334. package/src/services/frontend/frontendFs.ts +101 -0
  335. package/src/services/frontend/index.ts +21 -0
  336. package/src/services/html/htmlGenerator.ts +356 -0
  337. package/src/services/html/index.ts +21 -0
  338. package/src/services/http/apiClient.ts +221 -0
  339. package/src/services/http/http.ts +286 -0
  340. package/src/services/http/index.ts +29 -0
  341. package/src/services/http/responsesBuilder.ts +265 -0
  342. package/src/services/index.ts +5 -0
  343. package/src/services/utils/ensureBearerToken.ts +202 -0
  344. package/src/services/utils/index.ts +21 -0
  345. package/src/types/events.ts +303 -0
  346. package/src/types/express.ts +21 -0
  347. package/src/types/http.ts +77 -0
  348. package/src/types/index.ts +6 -0
  349. package/src/types/options.ts +248 -0
  350. package/src/types/utils.ts +52 -0
  351. package/src/types/wootils.ts +4 -0
  352. package/src/utils/fns/index.ts +4 -0
  353. package/src/utils/fns/others.ts +15 -0
  354. package/src/utils/fns/routes.ts +64 -0
  355. package/src/utils/fns/statuses.ts +44 -0
  356. package/src/utils/fns/text.ts +8 -0
  357. package/src/utils/index.ts +2 -0
  358. package/src/utils/wrappers.ts +537 -0
  359. package/tsconfig.json +5 -8
  360. package/tsup.config.ts +10 -0
  361. package/src/app/index.js +0 -692
  362. package/src/constants/eventNames.js +0 -48
  363. package/src/constants/index.js +0 -7
  364. package/src/controllers/common/configuration.js +0 -116
  365. package/src/controllers/common/health.js +0 -79
  366. package/src/controllers/common/index.js +0 -7
  367. package/src/controllers/common/statics.js +0 -336
  368. package/src/controllers/index.js +0 -9
  369. package/src/controllers/utils/gateway.js +0 -1039
  370. package/src/controllers/utils/index.js +0 -3
  371. package/src/index.js +0 -30
  372. package/src/middlewares/common/errorHandler.js +0 -185
  373. package/src/middlewares/common/forceHTTPS.js +0 -80
  374. package/src/middlewares/common/hsts.js +0 -122
  375. package/src/middlewares/common/index.js +0 -7
  376. package/src/middlewares/html/fastHTML.js +0 -298
  377. package/src/middlewares/html/index.js +0 -5
  378. package/src/middlewares/html/showHTML.js +0 -167
  379. package/src/middlewares/index.js +0 -11
  380. package/src/middlewares/utils/index.js +0 -3
  381. package/src/middlewares/utils/versionValidator.js +0 -261
  382. package/src/services/common/appError.js +0 -136
  383. package/src/services/common/httpError.js +0 -60
  384. package/src/services/common/index.js +0 -25
  385. package/src/services/common/sendFile.js +0 -68
  386. package/src/services/frontend/frontendFs.js +0 -85
  387. package/src/services/frontend/index.js +0 -17
  388. package/src/services/html/htmlGenerator.js +0 -391
  389. package/src/services/html/index.js +0 -17
  390. package/src/services/http/apiClient.js +0 -148
  391. package/src/services/http/http.js +0 -256
  392. package/src/services/http/index.js +0 -25
  393. package/src/services/http/responsesBuilder.js +0 -193
  394. package/src/services/index.js +0 -15
  395. package/src/services/utils/ensureBearerToken.js +0 -147
  396. package/src/services/utils/index.js +0 -19
  397. package/src/types.js +0 -377
  398. package/src/utils/functions.js +0 -78
  399. package/src/utils/wrappers.js +0 -131
  400. package/types/app/index.d.ts +0 -417
  401. package/types/constants/eventNames.d.ts +0 -93
  402. package/types/constants/index.d.ts +0 -2
  403. package/types/controllers/common/configuration.d.ts +0 -71
  404. package/types/controllers/common/health.d.ts +0 -55
  405. package/types/controllers/common/index.d.ts +0 -4
  406. package/types/controllers/common/statics.d.ts +0 -271
  407. package/types/controllers/index.d.ts +0 -3
  408. package/types/controllers/utils/gateway.d.ts +0 -947
  409. package/types/controllers/utils/index.d.ts +0 -2
  410. package/types/index.d.ts +0 -15
  411. package/types/middlewares/common/errorHandler.d.ts +0 -143
  412. package/types/middlewares/common/forceHTTPS.d.ts +0 -64
  413. package/types/middlewares/common/hsts.d.ts +0 -111
  414. package/types/middlewares/common/index.d.ts +0 -4
  415. package/types/middlewares/html/fastHTML.d.ts +0 -238
  416. package/types/middlewares/html/index.d.ts +0 -3
  417. package/types/middlewares/html/showHTML.d.ts +0 -128
  418. package/types/middlewares/index.d.ts +0 -4
  419. package/types/middlewares/utils/index.d.ts +0 -2
  420. package/types/middlewares/utils/versionValidator.d.ts +0 -247
  421. package/types/services/common/appError.d.ts +0 -89
  422. package/types/services/common/httpError.d.ts +0 -37
  423. package/types/services/common/index.d.ts +0 -18
  424. package/types/services/common/sendFile.d.ts +0 -56
  425. package/types/services/frontend/frontendFs.d.ts +0 -72
  426. package/types/services/frontend/index.d.ts +0 -3
  427. package/types/services/html/htmlGenerator.d.ts +0 -298
  428. package/types/services/html/index.d.ts +0 -3
  429. package/types/services/http/apiClient.d.ts +0 -141
  430. package/types/services/http/http.d.ts +0 -159
  431. package/types/services/http/index.d.ts +0 -18
  432. package/types/services/http/responsesBuilder.d.ts +0 -140
  433. package/types/services/index.d.ts +0 -6
  434. package/types/services/utils/ensureBearerToken.d.ts +0 -137
  435. package/types/services/utils/index.d.ts +0 -16
  436. package/types/types.d.ts +0 -280
  437. package/types/utils/functions.d.ts +0 -55
  438. package/types/utils/wrappers.d.ts +0 -127
@@ -0,0 +1,215 @@
1
+ import * as _homer0_jimple from '@homer0/jimple';
2
+ import { Statuses } from '../../utils/fns/statuses.mjs';
3
+ import { J as Jimpex, R as MiddlewareConnectFn } from '../../index-efeb437e.js';
4
+ import { ExpressMiddleware } from '../../types/express.mjs';
5
+ import { DeepPartial } from '../../types/utils.mjs';
6
+ import { HTTPErrorClass } from '../../services/common/httpError.mjs';
7
+ import { ResponsesBuilder } from '../../services/http/responsesBuilder.mjs';
8
+ import { Request } from 'express';
9
+ import 'statuses';
10
+ import '../../types/http.mjs';
11
+ import 'https';
12
+ import 'http';
13
+ import 'spdy';
14
+ import 'node-fetch';
15
+ import '@homer0/path-utils';
16
+ import '@homer0/simple-logger';
17
+ import '@homer0/simple-config';
18
+ import '@homer0/events-hub';
19
+ import '../../services/common/appError.mjs';
20
+
21
+ /**
22
+ * The options for how the middleware should behave if the requested version is `latest`.
23
+ *
24
+ * @group Middlewares/VersionValidator
25
+ */
26
+ type VersionValidatorLatestOptions = {
27
+ /**
28
+ * Whether or not the middleware should validate the _"latest version"_.
29
+ *
30
+ * @default true
31
+ */
32
+ allow: boolean;
33
+ /**
34
+ * The name of the _"latest version"_. Basically, `req.params.version` must match with
35
+ * this property in order to be consider "latest".
36
+ *
37
+ * @default 'latest'
38
+ */
39
+ name: string;
40
+ };
41
+ /**
42
+ * The options for how to detect if the request comes from a popup and how to compose the
43
+ * post message the middleware will use to respond.
44
+ *
45
+ * @group Middlewares/VersionValidator
46
+ */
47
+ type VersionValidatorPopupOptions = {
48
+ /**
49
+ * The name of the query string variable the middleware will check in order to indentify
50
+ * whether the request comes from a popup or not. The variable must have `'true'` as its
51
+ * value.
52
+ *
53
+ * @default 'popup'
54
+ */
55
+ variable: string;
56
+ /**
57
+ * The title of the page that will be generated to respond in case the versions don't
58
+ * match.
59
+ *
60
+ * @default 'Conflict'
61
+ */
62
+ title: string;
63
+ /**
64
+ * The contents of the post message the generated page will send if the versions don't
65
+ * match.
66
+ *
67
+ * @default 'version:conflict'
68
+ */
69
+ message: string;
70
+ };
71
+ /**
72
+ * The options used to customize a {@link VersionValidator} instance.
73
+ *
74
+ * @group Middlewares/VersionValidator
75
+ */
76
+ type VersionValidatorOptions = {
77
+ /**
78
+ * The version used to validate the requests.
79
+ */
80
+ version: string;
81
+ /**
82
+ * The options for how the middleware should behave if the requested version is
83
+ * `latest`.
84
+ */
85
+ latest: VersionValidatorLatestOptions;
86
+ /**
87
+ * The options for how to detect if the request comes from a popup and how to compose
88
+ * the post message the middleware will use to respond.
89
+ */
90
+ popup: VersionValidatorPopupOptions;
91
+ /**
92
+ * The error message to show when the version is invalid.
93
+ *
94
+ * @default "The application version doesn't match"
95
+ * @prettierignore
96
+ */
97
+ error: string;
98
+ };
99
+ /**
100
+ * A partial version of the {@link VersionValidatorOptions}, to be used in the constructor
101
+ * and the middleware creator. The reason it omits `version` it's because for the
102
+ * constructor it's required, but for the middleware creator it's not.
103
+ *
104
+ * @group Middlewares/VersionValidator
105
+ */
106
+ type VersionValidatorPartialOptions = DeepPartial<Omit<VersionValidatorOptions, 'version'>>;
107
+ /**
108
+ * The options to construct a {@link VersionValidator}.
109
+ *
110
+ * @group Middlewares/VersionValidator
111
+ */
112
+ type VersionValidatorConstructorOptions = VersionValidatorPartialOptions & {
113
+ /**
114
+ * The version used to validate the requests.
115
+ */
116
+ version: string;
117
+ /**
118
+ * A dictionary with the dependencies to inject.
119
+ */
120
+ inject: {
121
+ HTTPError: HTTPErrorClass;
122
+ responsesBuilder: ResponsesBuilder;
123
+ statuses: Statuses;
124
+ };
125
+ };
126
+ /**
127
+ * The options for the middleware creator that will mount an instance of
128
+ * {@link VersionValidator}.
129
+ *
130
+ * @group Middlewares/VersionValidator
131
+ */
132
+ type VersionValidatorMiddlewareOptions = VersionValidatorPartialOptions & {
133
+ /**
134
+ * The version used to validate the requests. This is optional in here because if it's
135
+ * not specified, it will be obtained from the configuration service.
136
+ */
137
+ version?: string;
138
+ };
139
+ /**
140
+ * This is the handler for the middleware/controller that validates the application
141
+ * version.
142
+ * This is useful in cases where you want to restrict the access to specific versions; for
143
+ * example: you have a frontend which needs to be aligned with the "current" version of
144
+ * the application, since the frontend won't realize a new version was released, the
145
+ * validator can be used to let the frontend know.
146
+ * Also, it can be configured to handle requests from popups, in which case, instead of
147
+ * generating an error message, it will send a post message.
148
+ *
149
+ * @group Middleware Classes
150
+ * @group Middlewares/VersionValidator
151
+ * @prettierignore
152
+ */
153
+ declare class VersionValidator {
154
+ /**
155
+ * To generate the errors in case the validation fails.
156
+ */
157
+ protected readonly _HTTPError: HTTPErrorClass;
158
+ /**
159
+ * To generate responses for popups.
160
+ */
161
+ protected readonly _responsesBuilder: ResponsesBuilder;
162
+ /**
163
+ * The uility service to get HTTP status codes.
164
+ */
165
+ protected readonly _statuses: Statuses;
166
+ /**
167
+ * The customization options.
168
+ */
169
+ protected readonly _options: VersionValidatorOptions;
170
+ /**
171
+ * @param options The options to construct the class.
172
+ * @throws If no `version` is specified in the options.
173
+ */
174
+ constructor({ inject, version, ...options }: VersionValidatorConstructorOptions);
175
+ /**
176
+ * Generates the middleware that validates the version.
177
+ */
178
+ getMiddleware(): ExpressMiddleware;
179
+ /**
180
+ * The customization options.
181
+ */
182
+ get options(): Readonly<VersionValidatorOptions>;
183
+ /**
184
+ * Helper method that checks if the incoming request is from a popup. It will look for
185
+ * the query string variable defined in the constructor options.
186
+ *
187
+ * @param req The request object sent by the application.
188
+ */
189
+ protected _isPopup(req: Request): boolean;
190
+ /**
191
+ * Helper method that checks if the "latest version" is enabled and if the given version
192
+ * is "the latest" (comparing it with the option name).
193
+ *
194
+ * @param version The version received in the request.
195
+ */
196
+ protected _isTheAllowedLatest(version: string): boolean;
197
+ }
198
+ /**
199
+ * A middleware that will validate a `version` request parameter against the application
200
+ * version, and generate an error if they don't match.
201
+ * This is a "middleware/controller" because the wrappers for both are the same, the
202
+ * difference is that, for controllers, Jimpex sends a second parameter with the route
203
+ * where they are mounted.
204
+ * By validating the route parameter, the function can know whether the implementation is
205
+ * going to use the middleware by itself or as a route middleware.
206
+ * If used as middleware, it will just return the result of
207
+ * {@link VersionValidator.getMiddleware}; but if used as controller, it will mount it on
208
+ * `[route]/:version/*`.
209
+ *
210
+ * @group Middlewares
211
+ * @group Middlewares/VersionValidator
212
+ */
213
+ declare const versionValidatorMiddleware: _homer0_jimple.ResourceCreator<"middleware", "connect", (options?: VersionValidatorMiddlewareOptions) => <ContainerType extends Jimpex = Jimpex>(app: ContainerType, route: string | undefined) => ExpressMiddleware, MiddlewareConnectFn>;
214
+
215
+ export { VersionValidator, VersionValidatorConstructorOptions, VersionValidatorLatestOptions, VersionValidatorMiddlewareOptions, VersionValidatorOptions, VersionValidatorPartialOptions, VersionValidatorPopupOptions, versionValidatorMiddleware };
@@ -0,0 +1,215 @@
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 '../../index-b2a04c78.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 '../../types/http.js';
11
+ import 'https';
12
+ import 'http';
13
+ import 'spdy';
14
+ import 'node-fetch';
15
+ import '@homer0/path-utils';
16
+ import '@homer0/simple-logger';
17
+ import '@homer0/simple-config';
18
+ import '@homer0/events-hub';
19
+ import '../../services/common/appError.js';
20
+
21
+ /**
22
+ * The options for how the middleware should behave if the requested version is `latest`.
23
+ *
24
+ * @group Middlewares/VersionValidator
25
+ */
26
+ type VersionValidatorLatestOptions = {
27
+ /**
28
+ * Whether or not the middleware should validate the _"latest version"_.
29
+ *
30
+ * @default true
31
+ */
32
+ allow: boolean;
33
+ /**
34
+ * The name of the _"latest version"_. Basically, `req.params.version` must match with
35
+ * this property in order to be consider "latest".
36
+ *
37
+ * @default 'latest'
38
+ */
39
+ name: string;
40
+ };
41
+ /**
42
+ * The options for how to detect if the request comes from a popup and how to compose the
43
+ * post message the middleware will use to respond.
44
+ *
45
+ * @group Middlewares/VersionValidator
46
+ */
47
+ type VersionValidatorPopupOptions = {
48
+ /**
49
+ * The name of the query string variable the middleware will check in order to indentify
50
+ * whether the request comes from a popup or not. The variable must have `'true'` as its
51
+ * value.
52
+ *
53
+ * @default 'popup'
54
+ */
55
+ variable: string;
56
+ /**
57
+ * The title of the page that will be generated to respond in case the versions don't
58
+ * match.
59
+ *
60
+ * @default 'Conflict'
61
+ */
62
+ title: string;
63
+ /**
64
+ * The contents of the post message the generated page will send if the versions don't
65
+ * match.
66
+ *
67
+ * @default 'version:conflict'
68
+ */
69
+ message: string;
70
+ };
71
+ /**
72
+ * The options used to customize a {@link VersionValidator} instance.
73
+ *
74
+ * @group Middlewares/VersionValidator
75
+ */
76
+ type VersionValidatorOptions = {
77
+ /**
78
+ * The version used to validate the requests.
79
+ */
80
+ version: string;
81
+ /**
82
+ * The options for how the middleware should behave if the requested version is
83
+ * `latest`.
84
+ */
85
+ latest: VersionValidatorLatestOptions;
86
+ /**
87
+ * The options for how to detect if the request comes from a popup and how to compose
88
+ * the post message the middleware will use to respond.
89
+ */
90
+ popup: VersionValidatorPopupOptions;
91
+ /**
92
+ * The error message to show when the version is invalid.
93
+ *
94
+ * @default "The application version doesn't match"
95
+ * @prettierignore
96
+ */
97
+ error: string;
98
+ };
99
+ /**
100
+ * A partial version of the {@link VersionValidatorOptions}, to be used in the constructor
101
+ * and the middleware creator. The reason it omits `version` it's because for the
102
+ * constructor it's required, but for the middleware creator it's not.
103
+ *
104
+ * @group Middlewares/VersionValidator
105
+ */
106
+ type VersionValidatorPartialOptions = DeepPartial<Omit<VersionValidatorOptions, 'version'>>;
107
+ /**
108
+ * The options to construct a {@link VersionValidator}.
109
+ *
110
+ * @group Middlewares/VersionValidator
111
+ */
112
+ type VersionValidatorConstructorOptions = VersionValidatorPartialOptions & {
113
+ /**
114
+ * The version used to validate the requests.
115
+ */
116
+ version: string;
117
+ /**
118
+ * A dictionary with the dependencies to inject.
119
+ */
120
+ inject: {
121
+ HTTPError: HTTPErrorClass;
122
+ responsesBuilder: ResponsesBuilder;
123
+ statuses: Statuses;
124
+ };
125
+ };
126
+ /**
127
+ * The options for the middleware creator that will mount an instance of
128
+ * {@link VersionValidator}.
129
+ *
130
+ * @group Middlewares/VersionValidator
131
+ */
132
+ type VersionValidatorMiddlewareOptions = VersionValidatorPartialOptions & {
133
+ /**
134
+ * The version used to validate the requests. This is optional in here because if it's
135
+ * not specified, it will be obtained from the configuration service.
136
+ */
137
+ version?: string;
138
+ };
139
+ /**
140
+ * This is the handler for the middleware/controller that validates the application
141
+ * version.
142
+ * This is useful in cases where you want to restrict the access to specific versions; for
143
+ * example: you have a frontend which needs to be aligned with the "current" version of
144
+ * the application, since the frontend won't realize a new version was released, the
145
+ * validator can be used to let the frontend know.
146
+ * Also, it can be configured to handle requests from popups, in which case, instead of
147
+ * generating an error message, it will send a post message.
148
+ *
149
+ * @group Middleware Classes
150
+ * @group Middlewares/VersionValidator
151
+ * @prettierignore
152
+ */
153
+ declare class VersionValidator {
154
+ /**
155
+ * To generate the errors in case the validation fails.
156
+ */
157
+ protected readonly _HTTPError: HTTPErrorClass;
158
+ /**
159
+ * To generate responses for popups.
160
+ */
161
+ protected readonly _responsesBuilder: ResponsesBuilder;
162
+ /**
163
+ * The uility service to get HTTP status codes.
164
+ */
165
+ protected readonly _statuses: Statuses;
166
+ /**
167
+ * The customization options.
168
+ */
169
+ protected readonly _options: VersionValidatorOptions;
170
+ /**
171
+ * @param options The options to construct the class.
172
+ * @throws If no `version` is specified in the options.
173
+ */
174
+ constructor({ inject, version, ...options }: VersionValidatorConstructorOptions);
175
+ /**
176
+ * Generates the middleware that validates the version.
177
+ */
178
+ getMiddleware(): ExpressMiddleware;
179
+ /**
180
+ * The customization options.
181
+ */
182
+ get options(): Readonly<VersionValidatorOptions>;
183
+ /**
184
+ * Helper method that checks if the incoming request is from a popup. It will look for
185
+ * the query string variable defined in the constructor options.
186
+ *
187
+ * @param req The request object sent by the application.
188
+ */
189
+ protected _isPopup(req: Request): boolean;
190
+ /**
191
+ * Helper method that checks if the "latest version" is enabled and if the given version
192
+ * is "the latest" (comparing it with the option name).
193
+ *
194
+ * @param version The version received in the request.
195
+ */
196
+ protected _isTheAllowedLatest(version: string): boolean;
197
+ }
198
+ /**
199
+ * A middleware that will validate a `version` request parameter against the application
200
+ * version, and generate an error if they don't match.
201
+ * This is a "middleware/controller" because the wrappers for both are the same, the
202
+ * difference is that, for controllers, Jimpex sends a second parameter with the route
203
+ * where they are mounted.
204
+ * By validating the route parameter, the function can know whether the implementation is
205
+ * going to use the middleware by itself or as a route middleware.
206
+ * If used as middleware, it will just return the result of
207
+ * {@link VersionValidator.getMiddleware}; but if used as controller, it will mount it on
208
+ * `[route]/:version/*`.
209
+ *
210
+ * @group Middlewares
211
+ * @group Middlewares/VersionValidator
212
+ */
213
+ declare const versionValidatorMiddleware: _homer0_jimple.ResourceCreator<"middleware", "connect", (options?: VersionValidatorMiddlewareOptions) => <ContainerType extends Jimpex = Jimpex>(app: ContainerType, route: string | undefined) => ExpressMiddleware, MiddlewareConnectFn>;
214
+
215
+ export { VersionValidator, VersionValidatorConstructorOptions, VersionValidatorLatestOptions, VersionValidatorMiddlewareOptions, VersionValidatorOptions, VersionValidatorPartialOptions, VersionValidatorPopupOptions, versionValidatorMiddleware };
@@ -0,0 +1,162 @@
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
+ /**
34
+ * @param options The options to construct the class.
35
+ * @throws If no `version` is specified in the options.
36
+ */
37
+ constructor({ inject, version, ...options }) {
38
+ /**
39
+ * To generate the errors in case the validation fails.
40
+ */
41
+ __publicField(this, "_HTTPError");
42
+ /**
43
+ * To generate responses for popups.
44
+ */
45
+ __publicField(this, "_responsesBuilder");
46
+ /**
47
+ * The uility service to get HTTP status codes.
48
+ */
49
+ __publicField(this, "_statuses");
50
+ /**
51
+ * The customization options.
52
+ */
53
+ __publicField(this, "_options");
54
+ this._HTTPError = inject.HTTPError;
55
+ this._responsesBuilder = inject.responsesBuilder;
56
+ this._statuses = inject.statuses;
57
+ this._options = (0, import_deep_assign.deepAssignWithOverwrite)(
58
+ {
59
+ error: "The application version doesn't match",
60
+ latest: {
61
+ allow: true,
62
+ name: "latest"
63
+ },
64
+ popup: {
65
+ variable: "popup",
66
+ title: "Conflict",
67
+ message: "vesion:conflict"
68
+ },
69
+ version
70
+ },
71
+ options
72
+ );
73
+ if (!this._options.version) {
74
+ throw new Error("You need to supply a version");
75
+ }
76
+ }
77
+ /**
78
+ * Generates the middleware that validates the version.
79
+ */
80
+ getMiddleware() {
81
+ return (req, res, next) => {
82
+ const { version } = req.params;
83
+ if (!version) {
84
+ next();
85
+ return;
86
+ }
87
+ if (version === this._options.version || this._isTheAllowedLatest(version)) {
88
+ next();
89
+ return;
90
+ }
91
+ const status = this._statuses("conflict");
92
+ if (this._isPopup(req)) {
93
+ const { title, message } = this._options.popup;
94
+ this._responsesBuilder.htmlPostMessage({
95
+ res,
96
+ title,
97
+ message,
98
+ status
99
+ });
100
+ return;
101
+ }
102
+ next(
103
+ new this._HTTPError(this._options.error, status, {
104
+ response: {
105
+ validation: true
106
+ }
107
+ })
108
+ );
109
+ };
110
+ }
111
+ /**
112
+ * The customization options.
113
+ */
114
+ get options() {
115
+ return (0, import_deep_assign.deepAssignWithOverwrite)({}, this._options);
116
+ }
117
+ /**
118
+ * Helper method that checks if the incoming request is from a popup. It will look for
119
+ * the query string variable defined in the constructor options.
120
+ *
121
+ * @param req The request object sent by the application.
122
+ */
123
+ _isPopup(req) {
124
+ const popup = req.query[this._options.popup.variable];
125
+ return !!(popup && String(popup).toLowerCase() === "true");
126
+ }
127
+ /**
128
+ * Helper method that checks if the "latest version" is enabled and if the given version
129
+ * is "the latest" (comparing it with the option name).
130
+ *
131
+ * @param version The version received in the request.
132
+ */
133
+ _isTheAllowedLatest(version) {
134
+ const { allow, name } = this._options.latest;
135
+ return allow && version === name;
136
+ }
137
+ }
138
+ const versionValidatorMiddleware = (0, import_utils.middlewareCreator)(
139
+ (options = {}) => (app, route) => {
140
+ const version = app.getConfig("version");
141
+ const middleware = new VersionValidator({
142
+ inject: {
143
+ HTTPError: app.get("HTTPError"),
144
+ responsesBuilder: app.get("responsesBuilder"),
145
+ statuses: app.get("statuses")
146
+ },
147
+ version,
148
+ ...options
149
+ }).getMiddleware();
150
+ if (route) {
151
+ const router = app.getRouter();
152
+ return router.all("/:version/*", middleware);
153
+ }
154
+ return middleware;
155
+ }
156
+ );
157
+ // Annotate the CommonJS export names for ESM import in node:
158
+ 0 && (module.exports = {
159
+ VersionValidator,
160
+ versionValidatorMiddleware
161
+ });
162
+ //# 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;AAAA;AAAA;AAAA;AAAA,EAqB5B,YAAY,EAAE,QAAQ,SAAS,GAAG,QAAQ,GAAuC;AAjBjF;AAAA;AAAA;AAAA,wBAAmB;AAInB;AAAA;AAAA;AAAA,wBAAmB;AAInB;AAAA;AAAA;AAAA,wBAAmB;AAInB;AAAA;AAAA;AAAA,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;AAAA;AAAA;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;AAAA;AAAA;AAAA,EAIA,IAAI,UAA6C;AAC/C,eAAO,4CAAwB,CAAC,GAAG,KAAK,QAAQ;AAAA,EAClD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOU,SAAS,KAAuB;AACxC,UAAM,QAAQ,IAAI,MAAM,KAAK,SAAS,MAAM,QAAQ;AACpD,WAAO,CAAC,EAAE,SAAS,OAAO,KAAK,EAAE,YAAY,MAAM;AAAA,EACrD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;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":[]}