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,425 @@
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 gateway_exports = {};
25
+ __export(gateway_exports, {
26
+ GatewayController: () => GatewayController,
27
+ gatewayController: () => gatewayController
28
+ });
29
+ module.exports = __toCommonJS(gateway_exports);
30
+ var import_deep_assign = require("@homer0/deep-assign");
31
+ var import_object_utils = require("@homer0/object-utils");
32
+ var import_utils = require("../../utils");
33
+ class GatewayController {
34
+ constructor({
35
+ inject,
36
+ route,
37
+ gatewayConfig,
38
+ ...options
39
+ }) {
40
+ __publicField(this, "http");
41
+ __publicField(this, "_getHelperService");
42
+ __publicField(this, "_gatewayConfig");
43
+ __publicField(this, "_route");
44
+ __publicField(this, "_routeExpression");
45
+ __publicField(this, "_options");
46
+ __publicField(this, "_endpoints");
47
+ __publicField(this, "_apiConfigUrl");
48
+ __publicField(this, "_apiConfigEndpoints");
49
+ __publicField(this, "_routes");
50
+ this.http = inject.http;
51
+ this._getHelperService = inject.getHelperService || (() => void 0);
52
+ this._route = (0, import_utils.removeSlashes)(route);
53
+ this._options = this._formatOptions(
54
+ (0, import_deep_assign.deepAssignWithOverwrite)(
55
+ {
56
+ root: "",
57
+ apiConfigSetting: "api",
58
+ headers: {
59
+ useXForwardedFor: true,
60
+ copyCustomHeaders: true,
61
+ copy: ["authorization", "content-type", "referer", "user-agent"],
62
+ remove: ["server", "x-powered-by", "content-encoding"]
63
+ }
64
+ },
65
+ options
66
+ )
67
+ );
68
+ this._gatewayConfig = {
69
+ ...gatewayConfig,
70
+ url: (0, import_utils.removeSlashes)(gatewayConfig.url, false, true)
71
+ };
72
+ this._routeExpression = (0, import_utils.createRouteExpression)(
73
+ this._options.root ? `${this._route}/${this._options.root}` : this._route,
74
+ true,
75
+ true
76
+ );
77
+ this._endpoints = this._formatEndpoints();
78
+ this._routes = this._createRoutes();
79
+ const { url, endpoints } = this._createAPIConfig();
80
+ this._apiConfigUrl = url;
81
+ this._apiConfigEndpoints = endpoints;
82
+ }
83
+ getAPIConfig({
84
+ setting,
85
+ placeholders = {}
86
+ } = {}) {
87
+ const useSetting = setting || this._options.apiConfigSetting;
88
+ let url;
89
+ const placeholdersEntries = Object.entries(placeholders);
90
+ if (placeholdersEntries.length) {
91
+ url = placeholdersEntries.reduce(
92
+ (acc, [key, value]) => acc.replace(`:${key}`, value),
93
+ this._apiConfigUrl
94
+ );
95
+ } else {
96
+ url = this._apiConfigUrl;
97
+ }
98
+ return {
99
+ url,
100
+ endpoints: {
101
+ [useSetting]: this._apiConfigEndpoints
102
+ }
103
+ };
104
+ }
105
+ addRoutes(router, middlewares = []) {
106
+ this._routes.forEach((route) => {
107
+ route.methods.forEach((info) => {
108
+ this._addRoute({
109
+ router,
110
+ method: info.method,
111
+ route: route.route,
112
+ gatewayMiddleware: this._createGatewayMiddleware(info.endpoint),
113
+ middlewares
114
+ });
115
+ });
116
+ });
117
+ return router;
118
+ }
119
+ get options() {
120
+ return { ...this._options };
121
+ }
122
+ get gatewayConfig() {
123
+ return { ...this._gatewayConfig };
124
+ }
125
+ _createGatewayMiddleware(endpoint) {
126
+ return async (req, res, next) => {
127
+ const {
128
+ _options: { headers: headersOptions },
129
+ _gatewayConfig: { url: gatewayUrl },
130
+ _routeExpression: routeExpression
131
+ } = this;
132
+ const reqPath = req.originalUrl.replace(routeExpression, "");
133
+ let headers = {};
134
+ headersOptions.copy.forEach((name) => {
135
+ if (req.headers[name]) {
136
+ headers[name] = req.headers[name];
137
+ }
138
+ });
139
+ if (headersOptions.copyCustomHeaders) {
140
+ headers = (0, import_deep_assign.deepAssignWithOverwrite)(
141
+ headers,
142
+ this.http.getCustomHeadersFromRequest(req)
143
+ );
144
+ }
145
+ if (headersOptions.useXForwardedFor) {
146
+ const ip = this.http.getIPFromRequest(req);
147
+ if (ip) {
148
+ headers["x-forwarded-for"] = ip;
149
+ }
150
+ }
151
+ const method = req.method.toUpperCase();
152
+ let body;
153
+ if (method !== "GET" && typeof req.body === "object") {
154
+ body = JSON.stringify(req.body);
155
+ if (!headers["content-type"]) {
156
+ headers["content-type"] = "application/json";
157
+ }
158
+ }
159
+ const helper = this._getHelperService() || {};
160
+ const helperBasePayload = {
161
+ endpoint,
162
+ req,
163
+ res,
164
+ next,
165
+ helper
166
+ };
167
+ try {
168
+ const request = await this._reduceEndpointRequest({
169
+ endpointReq: {
170
+ url: `${gatewayUrl}/${reqPath}`,
171
+ options: {
172
+ method,
173
+ headers,
174
+ body
175
+ }
176
+ },
177
+ ...helperBasePayload
178
+ });
179
+ const responseRaw = await this.http.fetch(request.url, request.options);
180
+ const response = await this._reduceEndpointResponse({
181
+ endpointRes: responseRaw,
182
+ ...helperBasePayload
183
+ });
184
+ const shouldStream = await this._shouldStreamEndpointResponse({
185
+ endpointRes: responseRaw,
186
+ ...helperBasePayload
187
+ });
188
+ if (shouldStream) {
189
+ res.status(response.status);
190
+ response.headers.forEach((value, name) => {
191
+ if (!headersOptions.remove.includes(name)) {
192
+ res.setHeader(name, value);
193
+ }
194
+ });
195
+ response.body.pipe(res).on("error", (error) => {
196
+ next(error);
197
+ });
198
+ } else {
199
+ await this._handleEndpointResponse({
200
+ endpointRes: response,
201
+ ...helperBasePayload
202
+ });
203
+ }
204
+ } catch (error) {
205
+ this._handleEndpointError({
206
+ error,
207
+ ...helperBasePayload
208
+ });
209
+ }
210
+ };
211
+ }
212
+ _addRoute({
213
+ router,
214
+ method,
215
+ route,
216
+ gatewayMiddleware,
217
+ middlewares
218
+ }) {
219
+ router[method](route, [...middlewares, gatewayMiddleware]);
220
+ }
221
+ _formatEndpoints() {
222
+ return (0, import_object_utils.flat)({
223
+ target: this._gatewayConfig.gateway,
224
+ shouldFlatten: (_, value) => {
225
+ const useValue = value;
226
+ return typeof useValue.path === "undefined";
227
+ }
228
+ });
229
+ }
230
+ _createRoutes() {
231
+ const routes = {};
232
+ Object.keys(this._endpoints).forEach((name) => {
233
+ const endpoint = this._endpoints[name];
234
+ let endpointPath;
235
+ let endpointMethod;
236
+ if (typeof endpoint === "string") {
237
+ endpointPath = endpoint;
238
+ endpointMethod = "all";
239
+ } else {
240
+ endpointPath = endpoint.path;
241
+ endpointMethod = endpoint.method ? this._validateHTTPMethod(endpoint.method) : "all";
242
+ }
243
+ endpointPath = (0, import_utils.removeSlashes)(endpointPath);
244
+ if (!routes[endpointPath]) {
245
+ routes[endpointPath] = {
246
+ path: endpointPath,
247
+ methods: {}
248
+ };
249
+ }
250
+ if (routes[endpointPath].methods[endpointMethod]) {
251
+ const repeatedEndpoint = routes[endpointPath].methods[endpointMethod];
252
+ throw new Error(
253
+ `You can't have two gateway endpoints to the same path and with the same HTTP method: '${repeatedEndpoint}' and '${name}'`
254
+ );
255
+ }
256
+ routes[endpointPath].methods[endpointMethod] = name;
257
+ });
258
+ const routePrefixes = this._options.root ? `/${this._options.root}/` : "/";
259
+ return Object.keys(routes).map((endpointPath) => {
260
+ const info = routes[endpointPath];
261
+ return {
262
+ path: info.path,
263
+ route: `${routePrefixes}${info.path}`,
264
+ methods: Object.keys(info.methods).map((methodNameRaw) => {
265
+ const methodName = methodNameRaw;
266
+ const endpointName = info.methods[methodName];
267
+ const endpointDefinition = this._endpoints[endpointName];
268
+ return {
269
+ method: methodName,
270
+ endpoint: {
271
+ name: endpointName,
272
+ definition: endpointDefinition
273
+ }
274
+ };
275
+ })
276
+ };
277
+ });
278
+ }
279
+ _reduceEndpointRequest({
280
+ helper,
281
+ ...options
282
+ }) {
283
+ if (helper.reduceEndpointRequest) {
284
+ return helper.reduceEndpointRequest(options);
285
+ }
286
+ return Promise.resolve(options.endpointReq);
287
+ }
288
+ _reduceEndpointResponse({
289
+ helper,
290
+ ...options
291
+ }) {
292
+ if (helper.reduceEndpointResponse) {
293
+ return helper.reduceEndpointResponse(options);
294
+ }
295
+ return Promise.resolve(options.endpointRes);
296
+ }
297
+ _shouldStreamEndpointResponse({
298
+ helper,
299
+ ...options
300
+ }) {
301
+ if (helper.shouldStreamEndpointResponse) {
302
+ return helper.shouldStreamEndpointResponse(options);
303
+ }
304
+ return Promise.resolve(true);
305
+ }
306
+ _handleEndpointResponse({
307
+ helper,
308
+ ...options
309
+ }) {
310
+ if (!helper.handleEndpointResponse) {
311
+ throw new Error("You must implement handleEndpointResponse");
312
+ }
313
+ return helper.handleEndpointResponse(options);
314
+ }
315
+ _handleEndpointError({
316
+ helper,
317
+ ...options
318
+ }) {
319
+ if (helper.handleEndpointError) {
320
+ return helper.handleEndpointError(options);
321
+ }
322
+ return options.next(options.error);
323
+ }
324
+ _formatOptions(options) {
325
+ if (options.root) {
326
+ const root = (0, import_utils.removeSlashes)(options.root).trim();
327
+ return { ...options, root };
328
+ }
329
+ return options;
330
+ }
331
+ _validateHTTPMethod(method) {
332
+ const newMethod = method.toLowerCase();
333
+ return [
334
+ "get",
335
+ "head",
336
+ "post",
337
+ "patch",
338
+ "put",
339
+ "delete",
340
+ "connect",
341
+ "options",
342
+ "trace"
343
+ ].includes(newMethod) ? newMethod : "all";
344
+ }
345
+ _createAPIConfig() {
346
+ let endpoints;
347
+ const { root } = this._options;
348
+ if (root) {
349
+ endpoints = Object.keys(this._endpoints).reduce((acc, name) => {
350
+ const endpoint = this._endpoints[name];
351
+ let newEndpoint;
352
+ if (typeof endpoint === "string") {
353
+ newEndpoint = (0, import_utils.removeSlashes)(endpoint);
354
+ newEndpoint = `${root}/${newEndpoint}`;
355
+ } else {
356
+ const endpointPath = (0, import_utils.removeSlashes)(endpoint.path);
357
+ newEndpoint = {
358
+ ...endpoint,
359
+ path: `${root}/${endpointPath}`
360
+ };
361
+ }
362
+ acc[name] = newEndpoint;
363
+ return acc;
364
+ }, {});
365
+ } else {
366
+ endpoints = this._endpoints;
367
+ }
368
+ return {
369
+ url: `/${this._route}`,
370
+ endpoints: (0, import_object_utils.unflat)({ target: endpoints })
371
+ };
372
+ }
373
+ }
374
+ const gatewayController = (0, import_utils.controllerProviderCreator)(
375
+ (options = {}) => (app, route) => {
376
+ const defaultServiceName = "apiGateway";
377
+ let defaultHelperServiceName = "apiGatewayHelper";
378
+ let defaultConfigSetting = "api";
379
+ let { serviceName = defaultServiceName } = options;
380
+ if (serviceName !== defaultServiceName) {
381
+ defaultConfigSetting = serviceName;
382
+ if (!serviceName.match(/gateway$/i)) {
383
+ serviceName = `${serviceName}Gateway`;
384
+ }
385
+ defaultHelperServiceName = `${serviceName}Helper`;
386
+ }
387
+ app.set(serviceName, () => {
388
+ const {
389
+ helperServiceName = defaultHelperServiceName,
390
+ gatewaySettingName = defaultConfigSetting,
391
+ gatewayClass: GatewayClass = GatewayController
392
+ } = options;
393
+ const gtConfig = app.getConfig(gatewaySettingName);
394
+ return new GatewayClass({
395
+ ...options,
396
+ apiConfigSetting: gatewaySettingName,
397
+ gatewayConfig: gtConfig,
398
+ route,
399
+ inject: {
400
+ http: app.get("http"),
401
+ getHelperService: () => app.try(helperServiceName)
402
+ }
403
+ });
404
+ });
405
+ return (0, import_utils.controller)(() => {
406
+ const ctrl = app.get(serviceName);
407
+ let useMiddlewares;
408
+ if (options.getMiddlewares) {
409
+ useMiddlewares = options.getMiddlewares(app).map((middleware) => {
410
+ if ("middleware" in middleware) {
411
+ return middleware.connect(app);
412
+ }
413
+ return middleware;
414
+ }).filter(import_utils.notUndefined);
415
+ }
416
+ return ctrl.addRoutes(app.get("router"), useMiddlewares);
417
+ });
418
+ }
419
+ );
420
+ // Annotate the CommonJS export names for ESM import in node:
421
+ 0 && (module.exports = {
422
+ GatewayController,
423
+ gatewayController
424
+ });
425
+ //# sourceMappingURL=gateway.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/controllers/utils/gateway.ts"],"sourcesContent":["import { deepAssignWithOverwrite } from '@homer0/deep-assign';\nimport { flat, unflat } from '@homer0/object-utils';\nimport type { APIClientOptions } from '@homer0/api-utils';\nimport {\n controllerProviderCreator,\n controller,\n createRouteExpression,\n removeSlashes,\n notUndefined,\n type MiddlewareLike,\n} from '../../utils';\nimport type { HTTP, HTTPFetchOptions } from '../../services';\nimport type { Jimpex } from '../../app';\nimport {\n RouterMethod,\n DeepPartial,\n Request,\n Response,\n NextFunction,\n HTTPResponse,\n Router,\n ExpressMiddleware,\n AsyncExpressMiddleware,\n} from '../../types';\n/**\n * The extended definition for endpoints.\n *\n * @group Controllers/Gateway\n */\nexport type GatewayConfigEndpointProps = {\n /**\n * The path to the endpoint relative to the entry point. It can include placeholders for\n * parameters like `/:parameter/`.\n */\n path: string;\n /**\n * The router (HTTP) method for the endpoint.\n *\n * @default 'all'\n */\n method?: RouterMethod;\n};\n/**\n * The definition of an endpoint: it can be just the path, relative to the entry point, or\n * an object in which you can also specify things like the method.\n *\n * @group Controllers/Gateway\n */\nexport type GatewayConfigEndpointDefinition = string | GatewayConfigEndpointProps;\n/**\n * The dictionary of endpoints the controller uses. The reason for this type is that this\n * could be a flat dictionary, or a nested one.\n *\n * @example\n *\n * <caption>A flat dictionary</caption>\n *\n * {\n * random: '/random',\n * users: '/users',\n * userById: {\n * path: '/users/:id',\n * method: 'get',\n * },\n * }\n *\n * @example\n *\n * <caption>A nested dictionary</caption>\n *\n * {\n * random: '/random',\n * users: {\n * list: '/users',\n * byId: {\n * path: '/users/:id',\n * method: 'get',\n * },\n * },\n * }\n *\n * @group Controllers/Gateway\n */\nexport type GatewayConfigEndpoints = {\n [key: string]: GatewayConfigEndpointDefinition | GatewayConfigEndpoints;\n};\n/**\n * The configuration for the gateway the controller uses.\n *\n * @group Controllers/Gateway\n */\nexport type GatewayConfig = {\n /**\n * The entry point to the API the controller will make the requests to.\n */\n url: string;\n /**\n * The dictionary of enpoints the gateway will make available.\n */\n gateway: GatewayConfigEndpoints;\n};\n/**\n * The options for how the gateway will handle the headers from the requests and the\n * responses.\n *\n * @group Controllers/Gateway\n */\nexport type GatewayControllerHeaderOptions = {\n /**\n * Whether or not to include the header with the request's IP address.\n *\n * @default true\n */\n useXForwardedFor: boolean;\n /**\n * Whether or not to copy all custom headers from the request. By custom header, it\n * means all the headers which names start with `x-`.\n *\n * @default true\n */\n copyCustomHeaders: boolean;\n /**\n * A list of \"known\" headers the gateway will try to copy from the incoming request.\n *\n * @default ['authorization','content-type', 'referer', 'user-agent']\n */\n copy: string[];\n /**\n * A list of \"known\" headers the gateway will try to remove the response.\n *\n * @default ['server', 'x-powered-by']\n */\n remove: string[];\n};\n/**\n * The extra options for the gateway controller. They are \"extra\" because they are mostly\n * helpers for when used with an API client, or for optional features.\n *\n * @group Controllers/Gateway\n */\nexport type GatewayControllerExtraOptions = {\n /**\n * This is really a helper for when the gateway is used with an API client. The idea is\n * that, by default, the routes are mounted on the controller route, but with this\n * option, you can specify another sub path. For example: The controller is mounted on\n * `/routes`, and if you set `root` to `gateway`, all the routes will be on\n * `/routes/gateway`.\n *\n * This become important (and useful) when you get the API client configuration (with\n * `getAPIConfig`): The `url` will be the controller route, but all the endpoints will\n * be modified and prefixed with the `root`, that way, you can have multiple gateways in\n * the same \"base route\".\n *\n * It can also includes placeholders for parameters like `/:parameter/`, that will be\n * replaced with the `placeholders` option when `getAPIConfig` gets called.\n *\n * @default ''\n */\n root: string;\n /**\n * This is another option for when the gateway is used with an API client. When calling\n * `getAPIConfig`, all the endpoints will be wrapped inside an object named after this\n * option. For example: `{ url: '...', endpoints: { api: { ... } } }`.\n *\n * @default 'api'\n */\n apiConfigSetting: string;\n /**\n * The options for how the gateway will handle the headers from the requests and the\n * responses.\n */\n headers: GatewayControllerHeaderOptions;\n};\n/**\n * The required options for the gateway controller.\n *\n * @group Controllers/Gateway\n */\nexport type GatewayControllerOptions = {\n /**\n * The configuration for the API the gateway will make the requests to.\n */\n gatewayConfig: GatewayConfig;\n /**\n * The route where the controller is mounted.\n */\n route: string;\n} & DeepPartial<GatewayControllerExtraOptions>;\n/**\n * The information for a request the controller will make.\n *\n * @group Controllers/Gateway\n */\nexport type GatewayControllerRequest = {\n /**\n * The URL for the request.\n */\n url: string;\n /**\n * The options for the fetch client that will make the requests.\n */\n options: HTTPFetchOptions;\n};\n/**\n * The information for an endpoint the gateway is calling.\n *\n * @group Controllers/Gateway\n */\nexport type GatewayControllerEndpointInfo = {\n /**\n * The name of the endpoint in the configuration.\n */\n name: string;\n /**\n * The properties (path and method) of the endpoint.\n */\n definition: GatewayConfigEndpointDefinition;\n};\n/**\n * These are the base options sent to all the helper service functions.\n *\n * @group Controllers/Gateway\n */\nexport type GatewayHelperServiceBaseFnOptions = {\n /**\n * The information of the endpoint the gateway is calling.\n */\n endpoint: GatewayControllerEndpointInfo;\n /**\n * The request recived by the application.\n */\n req: Request;\n /**\n * The response object created by the application.\n */\n res: Response;\n /**\n * The function to call the next middleware in the chain.\n */\n next: NextFunction;\n};\n/**\n * The information sent to the helper service in order to modify, or not, a request before\n * it is sent.\n *\n * @group Controllers/Gateway\n */\nexport type GatewayHelperServiceRequestReducerOptions =\n GatewayHelperServiceBaseFnOptions & {\n /**\n * The options the controller created for the fetch client.\n */\n endpointReq: GatewayControllerRequest;\n };\n/**\n * A function that can be used to modify the information of an endpoint before making a\n * request.\n *\n * @param options The information of the request.\n * @group Controllers/Gateway\n */\nexport type GatewayHelperServiceRequestReducer = (\n options: GatewayHelperServiceRequestReducerOptions,\n) => Promise<GatewayControllerRequest>;\n/**\n * The information sent to the helper service in order to modify a response before\n * processing it, decide if it should be streamed or not, and even handle it.\n *\n * @group Controllers/Gateway\n */\nexport type GatewayHelperServiceResponseReducerOptions =\n GatewayHelperServiceBaseFnOptions & {\n /**\n * The response from the endpoint request.\n */\n endpointRes: HTTPResponse;\n };\n/**\n * A function that can be used to modify the response of an endpoint before the controller\n * processes it.\n *\n * @param options The information of the response.\n * @group Controllers/Gateway\n */\nexport type GatewayHelperServiceResponseReducer = (\n options: GatewayHelperServiceResponseReducerOptions,\n) => Promise<HTTPResponse>;\n/**\n * A function that can be used to tell the controller to stream the response of an\n * endpoint or not.\n * If it returns `false`, the function to handle responses should be defined, otherwise,\n * an error will be generated.\n *\n * @param options The information of the response.\n * @group Controllers/Gateway\n */\nexport type GatewayHelperServiceStreamVerification = (\n options: GatewayHelperServiceResponseReducerOptions,\n) => Promise<boolean>;\n/**\n * A function to handle the response of an endpoint. This is called when the helper\n * service tells the controller that the endpoint shouldn't be streamed, so this method\n * should handle the response.\n *\n * @param options The information of the response.\n * @group Controllers/Gateway\n */\nexport type GatewayHelperServiceResponseHandler = (\n options: GatewayHelperServiceResponseReducerOptions,\n) => Promise<void>;\n/**\n * The information sent to the helper service in order to handle a failed request for an\n * endpoint.\n *\n * @group Controllers/Gateway\n */\nexport type GatewayHelperServiceErrorHandlerOptions =\n GatewayHelperServiceBaseFnOptions & {\n /**\n * The error generated during the request.\n */\n error: Error;\n };\n/**\n * A function to handle the error of an endpoint request.\n *\n * @param options The information of the error.\n * @group Controllers/Gateway\n */\nexport type GatewayHelperServiceErrorHandler = (\n options: GatewayHelperServiceErrorHandlerOptions,\n) => void;\n/**\n * The interface of a helper service that can intercept/modify the requests and responses\n * the gateway makes.\n *\n * @group Controllers/Gateway\n */\nexport type GatewayHelperService = Partial<{\n /**\n * A function that is called before an endpoint request is made.\n */\n reduceEndpointRequest: GatewayHelperServiceRequestReducer;\n /**\n * A function that is called with the response of an endpoint request.\n */\n reduceEndpointResponse: GatewayHelperServiceResponseReducer;\n /**\n * A function called in order to validate if an endpoint response should be streamed or\n * not. If the function returns `false`, `handleEndpointResponse` will be called.\n */\n shouldStreamEndpointResponse: GatewayHelperServiceStreamVerification;\n /**\n * A function called when `shouldStreamEndpointResponse` returns `false`. The function\n * should handle the response for the application.\n */\n handleEndpointResponse: GatewayHelperServiceResponseHandler;\n /**\n * A function called when an error is generated during an endpoint request/processing.\n */\n handleEndpointError: GatewayHelperServiceErrorHandler;\n}>;\n/**\n * Utility type for the options object sent to the \"proxy methods\" the controller has for\n * the helper service.\n *\n * @template T The type of the options for a specific helper service function.\n * @access protected\n * @group Controllers/Gateway\n */\nexport type GatewayControllerHelperOptions<T> = T & {\n /**\n * The reference for the helper service.\n */\n helper: GatewayHelperService;\n};\n/**\n * The information for a single HTTP method an endpoint can handle.\n *\n * @group Controllers/Gateway\n */\nexport type GatewayControllerRouteMethod = {\n /**\n * The method for the route.\n */\n method: RouterMethod;\n /**\n * The information of the endpoint.\n */\n endpoint: GatewayControllerEndpointInfo;\n};\n/**\n * The information for all the HTTP methods that can be handled for an endpoint.\n *\n * @group Controllers/Gateway\n */\nexport type GatewayControllerRoute = {\n /**\n * The path to the endpoint, relative to the entry point.\n */\n path: string;\n /**\n * The path for the route in the controller. This is different from `path` as it's possible for\n * the gateway to be implemented using the `root` option.\n */\n route: string;\n /**\n * A list with all the methods the controller uses on the route.\n */\n methods: GatewayControllerRouteMethod[];\n};\n/**\n * The API client configuration the gateway can generate for its endpoints.\n *\n * @group Controllers/Gateway\n */\nexport type GatewayControllerAPIConfig = {\n /**\n * The base URL for the API.\n */\n url: string;\n /**\n * The dictionary of endpoints the controller handles.\n */\n endpoints: APIClientOptions['endpoints'];\n};\n/**\n * The options sent to {@link GatewayController.getAPIConfig}.\n *\n * @group Controllers/Gateway\n */\nexport type GatewayControllerAPIConfigOptions = {\n /**\n * This can be used to overwrite the gateway's `apiConfigSetting` option, and set a new\n * setting as a wrapper for the endpoints.\n */\n setting?: string;\n /**\n * A dictionary of values for possible placeholders that were sent using the `root`\n * option.\n */\n placeholders?: Record<string, string>;\n};\n/**\n * The options to construct a {@link GatewayController}.\n *\n * @group Controllers/Gateway\n */\nexport type GatewayControllerConstructorOptions = GatewayControllerOptions & {\n /**\n * A dictionary with the dependencies to inject.\n */\n inject: {\n http: HTTP;\n /**\n * A function to get a possible helper service. This is injected as a \"getter\" to not\n * interrupt the DIC \"lifecycle\": controllers are initialized right when the app\n * starts, and injecting a reference would force the service to be initialized too,\n * even if a request is not being made.\n */\n getHelperService?: () => GatewayHelperService | undefined;\n };\n};\n/**\n * The options for {@link GatewayController._addRoute}.\n *\n * @access protected\n * @group Controllers/Gateway\n */\nexport type AddGatewayRouteOptions = {\n /**\n * The reference for the router in which the middlewares will be added.\n */\n router: Router;\n /**\n * The router method in which the middlewares will be added.\n */\n method: RouterMethod;\n /**\n * The route in which the middlewares will be added.\n */\n route: string;\n /**\n * The middleware created by {@link GatewayController}, that makes the request.\n */\n gatewayMiddleware: AsyncExpressMiddleware;\n /**\n * A list of extra middlewares to prepend to the gateway middleware.\n */\n middlewares: ExpressMiddleware[];\n};\n/**\n * A utility controller that generates routes that act as a gateway for a specific API.\n *\n * @group Controller Classes\n * @group Controllers/Gateway\n * @prettierignore\n */\nexport class GatewayController {\n /**\n * The service that makes HTTP requests.\n */\n protected readonly http: HTTP;\n /**\n * A function to get a possible helper service. This is injected as a \"getter\" to not\n * interrupt the DIC \"lifecycle\": controllers are initialized right when the app\n * starts, and injecting a reference would force the service to be initialized too,\n * even if a request is not being made.\n */\n protected readonly _getHelperService: () => GatewayHelperService | undefined;\n /**\n * The information, url and endpoints, for the gateway the controller will make requests to.\n */\n protected readonly _gatewayConfig: GatewayConfig;\n /**\n * The route in which the controller is mounted.\n */\n protected readonly _route: string;\n /**\n * A regular expression that will be used to remove the controller route from a\n * request path. This will allow the main middleware to extract the path to where the\n * request should be made.\n */\n protected readonly _routeExpression: RegExp;\n /**\n * The controller customization options.\n */\n protected readonly _options: GatewayControllerExtraOptions;\n /**\n * A flat dictionary with the endpoints information.\n */\n protected readonly _endpoints: Record<string, GatewayConfigEndpointDefinition>;\n /**\n * The entry URL for the API client configuration the controller can generate.\n */\n protected readonly _apiConfigUrl: string;\n /**\n * The generated endpoints for the API client configuration the controller can generate.\n */\n protected readonly _apiConfigEndpoints: APIClientOptions['endpoints'];\n /**\n * The list of routes the controller can handle.\n */\n protected readonly _routes: GatewayControllerRoute[];\n /**\n * @param options The options to construct the controller.\n */\n constructor({\n inject,\n route,\n gatewayConfig,\n ...options\n }: GatewayControllerConstructorOptions) {\n this.http = inject.http;\n this._getHelperService = inject.getHelperService || (() => undefined);\n this._route = removeSlashes(route);\n this._options = this._formatOptions(\n deepAssignWithOverwrite(\n {\n root: '',\n apiConfigSetting: 'api',\n headers: {\n useXForwardedFor: true,\n copyCustomHeaders: true,\n copy: ['authorization', 'content-type', 'referer', 'user-agent'],\n remove: ['server', 'x-powered-by', 'content-encoding'],\n },\n },\n options,\n ),\n );\n this._gatewayConfig = {\n ...gatewayConfig,\n url: removeSlashes(gatewayConfig.url, false, true),\n };\n this._routeExpression = createRouteExpression(\n this._options.root ? `${this._route}/${this._options.root}` : this._route,\n true,\n true,\n );\n this._endpoints = this._formatEndpoints();\n this._routes = this._createRoutes();\n const { url, endpoints } = this._createAPIConfig();\n this._apiConfigUrl = url;\n this._apiConfigEndpoints = endpoints;\n }\n /**\n * Generates an API client configuration based on the controller routes.\n *\n * @param options The options to customize the generated configuration.\n */\n getAPIConfig({\n setting,\n placeholders = {},\n }: GatewayControllerAPIConfigOptions = {}): Readonly<GatewayControllerAPIConfig> {\n const useSetting = setting || this._options.apiConfigSetting;\n let url: string;\n const placeholdersEntries = Object.entries(placeholders);\n if (placeholdersEntries.length) {\n url = placeholdersEntries.reduce<string>(\n (acc, [key, value]) => acc.replace(`:${key}`, value),\n this._apiConfigUrl,\n );\n } else {\n url = this._apiConfigUrl;\n }\n\n return {\n url,\n endpoints: {\n [useSetting]: this._apiConfigEndpoints,\n },\n };\n }\n /**\n * Mounts the middlewares in the router in order to make the requests.\n *\n * @param router A reference to the application router.\n * @param middlewares A list of extra middlewares to execute before the gateway\n * middleware.\n */\n addRoutes(router: Router, middlewares: ExpressMiddleware[] = []): Router {\n this._routes.forEach((route) => {\n route.methods.forEach((info) => {\n this._addRoute({\n router,\n method: info.method,\n route: route.route,\n gatewayMiddleware: this._createGatewayMiddleware(info.endpoint),\n middlewares,\n });\n });\n });\n\n return router;\n }\n /**\n * The customization options.\n */\n get options(): Readonly<GatewayControllerExtraOptions> {\n return { ...this._options };\n }\n /**\n * The configuration for the gateway the controller will make requests to.\n */\n get gatewayConfig(): Readonly<GatewayConfig> {\n return { ...this._gatewayConfig };\n }\n /**\n * Generates a middleware that will make the request to an endpoint and stream the\n * response.\n *\n * @param endpoint The information of the endpoint the middleware will handle.\n */\n protected _createGatewayMiddleware(\n endpoint: GatewayControllerEndpointInfo,\n ): AsyncExpressMiddleware {\n return async (req, res, next) => {\n const {\n _options: { headers: headersOptions },\n _gatewayConfig: { url: gatewayUrl },\n _routeExpression: routeExpression,\n } = this;\n // Remove the controller route from the requested URL.\n const reqPath = req.originalUrl.replace(routeExpression, '');\n // Process the headers for the request.\n let headers: Record<string, string> = {};\n // - Copy the headers from the incoming request.\n headersOptions.copy.forEach((name) => {\n if (req.headers[name]) {\n headers[name] = req.headers[name] as string;\n }\n });\n // - Copy the custom headers.\n if (headersOptions.copyCustomHeaders) {\n headers = deepAssignWithOverwrite<Record<string, string>>(\n headers,\n this.http.getCustomHeadersFromRequest(req),\n );\n }\n // - Include the IP on the X-Forwarded-For header, if enabled.\n if (headersOptions.useXForwardedFor) {\n const ip = this.http.getIPFromRequest(req);\n if (ip) {\n headers['x-forwarded-for'] = ip;\n }\n }\n\n const method = req.method.toUpperCase();\n // If the request has a body and the method is not `GET`, stringify it.\n let body: string | undefined;\n if (method !== 'GET' && typeof req.body === 'object') {\n body = JSON.stringify(req.body);\n // If there's no `content-type`, let's assume it's JSON.\n if (!headers['content-type']) {\n headers['content-type'] = 'application/json';\n }\n }\n\n /**\n * Get the helper service, if there's one, and define the base options for its\n * methods.\n */\n const helper = this._getHelperService() || {};\n const helperBasePayload = {\n endpoint,\n req,\n res,\n next,\n helper,\n };\n\n try {\n // Reduce the request information before using it.\n const request = await this._reduceEndpointRequest({\n endpointReq: {\n url: `${gatewayUrl}/${reqPath}`,\n options: {\n method,\n headers,\n body,\n },\n },\n ...helperBasePayload,\n });\n // Make the actual request.\n const responseRaw = await this.http.fetch(request.url, request.options);\n // Reduce the response information before using it.\n const response = await this._reduceEndpointResponse({\n endpointRes: responseRaw,\n ...helperBasePayload,\n });\n // Validate if the response should be streamed.\n const shouldStream = await this._shouldStreamEndpointResponse({\n endpointRes: responseRaw,\n ...helperBasePayload,\n });\n\n if (shouldStream) {\n /**\n * If the response should be streamed, set the status, remove unwanted headers,\n * and pipe it to the application response object.\n */\n res.status(response.status);\n response.headers.forEach((value, name) => {\n if (!headersOptions.remove.includes(name)) {\n res.setHeader(name, value);\n }\n });\n\n response.body.pipe(res).on('error', (error) => {\n next(error);\n });\n } else {\n /**\n * If the response should not be streamed, send it to the helper method to\n * handle it.\n */\n await this._handleEndpointResponse({\n endpointRes: response,\n ...helperBasePayload,\n });\n }\n } catch (error) {\n // Something failed, so let's pass the error to the helper service.\n this._handleEndpointError({\n error: error as Error,\n ...helperBasePayload,\n });\n }\n };\n }\n /**\n * Mounts the middleware(s) for an endpoint in the router.\n *\n * @param options The information of the endpoint and how it needs to be added.\n */\n protected _addRoute({\n router,\n method,\n route,\n gatewayMiddleware,\n middlewares,\n }: AddGatewayRouteOptions): void {\n router[method](route, [...middlewares, gatewayMiddleware]);\n }\n /**\n * Formats the endpoints for the gateway into a flat dictionary without nesting.\n */\n protected _formatEndpoints(): Record<string, GatewayConfigEndpointDefinition> {\n return flat({\n target: this._gatewayConfig.gateway,\n shouldFlatten: (_, value) => {\n const useValue = value as { path?: string };\n return typeof useValue.path === 'undefined';\n },\n });\n }\n /**\n * Based on the information from the endpoints, this method will create the routes the\n * controller will later add on a router.\n *\n * @throws If there's more than one endpoint using the same path with the same HTTP\n * method.\n */\n protected _createRoutes(): GatewayControllerRoute[] {\n const routes: Record<\n string,\n {\n path: string;\n methods: Partial<Record<RouterMethod, string>>;\n }\n > = {};\n Object.keys(this._endpoints).forEach((name) => {\n const endpoint = this._endpoints[name]!;\n let endpointPath: string;\n let endpointMethod: RouterMethod;\n if (typeof endpoint === 'string') {\n endpointPath = endpoint;\n endpointMethod = 'all';\n } else {\n endpointPath = endpoint.path;\n endpointMethod = endpoint.method\n ? this._validateHTTPMethod(endpoint.method)\n : 'all';\n }\n\n endpointPath = removeSlashes(endpointPath);\n if (!routes[endpointPath]) {\n routes[endpointPath] = {\n path: endpointPath,\n methods: {},\n };\n }\n\n if (routes[endpointPath]!.methods[endpointMethod]) {\n const repeatedEndpoint = routes[endpointPath]!.methods[endpointMethod];\n throw new Error(\n \"You can't have two gateway endpoints to the same path and with the same \" +\n `HTTP method: '${repeatedEndpoint}' and '${name}'`,\n );\n }\n\n routes[endpointPath]!.methods[endpointMethod] = name;\n });\n\n const routePrefixes = this._options.root ? `/${this._options.root}/` : '/';\n return Object.keys(routes).map((endpointPath) => {\n const info = routes[endpointPath]!;\n return {\n path: info.path,\n route: `${routePrefixes}${info.path}`,\n methods: Object.keys(info.methods).map((methodNameRaw) => {\n const methodName = methodNameRaw as RouterMethod;\n const endpointName = info.methods[methodName]!;\n const endpointDefinition = this._endpoints[endpointName]!;\n return {\n method: methodName,\n endpoint: {\n name: endpointName,\n definition: endpointDefinition,\n },\n };\n }),\n };\n });\n }\n /**\n * This is a \"proxy method\" to call the helper service's function that can modify an\n * endpoint request before it gets made.\n *\n * The reason this is a \"proxy method\" is in case the controller gets subclassed and\n * \"used itself as a helper\" instead of relying on a difference one.\n *\n * If the helper doesn't implement `reduceEndpointRequest`, it will just return\n * information for the request.\n *\n * @param options The information of the request and the reference to the helper.\n */\n protected _reduceEndpointRequest({\n helper,\n ...options\n }: GatewayControllerHelperOptions<GatewayHelperServiceRequestReducerOptions>): Promise<GatewayControllerRequest> {\n if (helper.reduceEndpointRequest) {\n return helper.reduceEndpointRequest(options);\n }\n\n return Promise.resolve(options.endpointReq);\n }\n /**\n * This is a \"proxy method\" to call the helper service's function that can modify an\n * endpoint response before it gets processed.\n *\n * The reason this is a \"proxy method\" is in case the controller gets subclassed and\n * \"used itself as a helper\" instead of relying on a difference one.\n *\n * If the helper doesn't implement `reduceEndpointResponse`, it will just return\n * information for the response.\n *\n * @param options The information of the response and the reference to the helper.\n */\n protected _reduceEndpointResponse({\n helper,\n ...options\n }: GatewayControllerHelperOptions<GatewayHelperServiceResponseReducerOptions>): Promise<HTTPResponse> {\n if (helper.reduceEndpointResponse) {\n return helper.reduceEndpointResponse(options);\n }\n\n return Promise.resolve(options.endpointRes);\n }\n /**\n * This is a \"proxy method\" to call the helper service's function that can decide if an\n * endpoint response should be streamed or not.\n *\n * The reason this is a \"proxy method\" is in case the controller gets subclassed and\n * \"used itself as a helper\" instead of relying on a difference one.\n *\n * If the helper doesn't implement `shouldStreamEndpointResponse`, it will just return\n * `true`.\n *\n * @param options The information of the response and the reference to the helper.\n */\n protected _shouldStreamEndpointResponse({\n helper,\n ...options\n }: GatewayControllerHelperOptions<GatewayHelperServiceResponseReducerOptions>): Promise<boolean> {\n if (helper.shouldStreamEndpointResponse) {\n return helper.shouldStreamEndpointResponse(options);\n }\n\n return Promise.resolve(true);\n }\n /**\n * This is a \"proxy method\" to call the helper service's function that handles a\n * response in case it already said that a response shouldn't be streamed.\n *\n * The reason this is a \"proxy method\" is in case the controller gets subclassed and\n * \"used itself as a helper\" instead of relying on a difference one.\n *\n * If the helper doesn't implement `shouldStreamEndpointResponse`, it will throw an\n * error.\n *\n * @param options The information of the response and the reference to the helper.\n * @throws If the helper doesn't implement `handleEndpointResponse`.\n */\n protected _handleEndpointResponse({\n helper,\n ...options\n }: GatewayControllerHelperOptions<GatewayHelperServiceResponseReducerOptions>): Promise<void> {\n if (!helper.handleEndpointResponse) {\n throw new Error('You must implement handleEndpointResponse');\n }\n\n return helper.handleEndpointResponse(options);\n }\n /**\n * This is a \"proxy method\" to call the helper service's function that handles an error\n * on an endpoint request.\n *\n * The reason this is a \"proxy method\" is in case the controller gets subclassed and\n * \"used itself as a helper\" instead of relying on a difference one.\n *\n * If the helper doesn't implement `handleEndpointError`, it will just send the error to\n * the next middleware/error handler.\n *\n * @param options The information of the response and the reference to the helper.\n */\n protected _handleEndpointError({\n helper,\n ...options\n }: GatewayControllerHelperOptions<GatewayHelperServiceErrorHandlerOptions>): void {\n if (helper.handleEndpointError) {\n return helper.handleEndpointError(options);\n }\n\n return options.next(options.error);\n }\n /**\n * Validates and formats the customization options sent to the controller.\n *\n * @param options The options sent to the constructor.\n */\n protected _formatOptions(\n options: GatewayControllerExtraOptions,\n ): GatewayControllerExtraOptions {\n if (options.root) {\n const root = removeSlashes(options.root).trim();\n return { ...options, root };\n }\n\n return options;\n }\n /**\n * Validates a router/HTTP method that the controller intends to use for an endpoint. If\n * it's not valid, it will return `all`.\n *\n * @param method The HTTP method for the endpoint.\n */\n protected _validateHTTPMethod(method: string): RouterMethod {\n const newMethod = method.toLowerCase();\n return [\n 'get',\n 'head',\n 'post',\n 'patch',\n 'put',\n 'delete',\n 'connect',\n 'options',\n 'trace',\n ].includes(newMethod)\n ? (newMethod as RouterMethod)\n : 'all';\n }\n /**\n * Creates the API client configuration based on the controller routes.\n */\n protected _createAPIConfig(): GatewayControllerAPIConfig {\n let endpoints: APIClientOptions['endpoints'];\n const { root } = this._options;\n if (root) {\n endpoints = Object.keys(this._endpoints).reduce<\n Record<string, GatewayConfigEndpointDefinition>\n >((acc, name) => {\n const endpoint = this._endpoints[name]!;\n let newEndpoint;\n if (typeof endpoint === 'string') {\n newEndpoint = removeSlashes(endpoint);\n newEndpoint = `${root}/${newEndpoint}`;\n } else {\n const endpointPath = removeSlashes(endpoint.path);\n newEndpoint = {\n ...endpoint,\n path: `${root}/${endpointPath}`,\n };\n }\n\n acc[name] = newEndpoint;\n return acc;\n }, {});\n } else {\n endpoints = this._endpoints;\n }\n\n return {\n url: `/${this._route}`,\n endpoints: unflat({ target: endpoints }),\n };\n }\n}\n/**\n * A function to generate a list of middlewares that can be executed before the tontroller\n * main middleware.\n *\n * @group Controllers/Gateway\n */\nexport type GatewayControllerGetMiddlewaresFn = (app: Jimpex) => MiddlewareLike[];\n/**\n * The options for the controller creator that mounts the {@link GatewayController}.\n *\n * @group Controllers/Gateway\n */\nexport type GatewayControllerCreatorOptions =\n DeepPartial<GatewayControllerExtraOptions> & {\n /**\n * The name the creator will use to register the controller in the container. No,\n * this is not a typo. The creator will register the controller so other services can\n * access the `getAPIConfig` method. The service will be available after the app\n * routes are mounted.\n * If this is overwritten, the creator will ensure that the name ends with `Gateway`;\n * and if overwritten, but it doesn't include `Gateway` at the end, and no\n * `gatewaySettingName` was defined, the creator will use the custom name (without\n * `Gatway`) for `gatewaySettingName`.\n *\n * @default 'apiGateway'\n */\n serviceName?: string;\n /**\n * The name of the helper service the creator will try to obtain from the container.\n * If `serviceName` is overwritten, the default for this will be\n * `${serviceName}Helper`.\n *\n * @default 'apiGatewayHelper'\n */\n helperServiceName?: string;\n /**\n * The name of the configuration setting where the gateway configuration is stored. If\n * not overwritten, check the description of `serviceName` to understand which will be\n * its default value.\n *\n * @default 'api'\n */\n gatewaySettingName?: string;\n /**\n * The class the creator will instantiate. Similar to the API Client, this allows for\n * extra customization as you can send a custom subclass of the\n * {@link GatewayController}.\n *\n * @default GatewayController\n */\n gatewayClass?: typeof GatewayController;\n /**\n * A function to generate a list of middlewares that can be executed before the\n * controller main middleware.\n */\n getMiddlewares?: GatewayControllerGetMiddlewaresFn;\n };\n/**\n * Creates a controller that allows the application to mount routes that will work like\n * gateway to a specific API.\n *\n * @group Controllers\n * @group Controllers/Gateway\n */\nexport const gatewayController = controllerProviderCreator(\n (options: GatewayControllerCreatorOptions = {}) =>\n (app, route) => {\n /**\n * Formats the name in order to keep consistency with the helper service and the\n * configuration setting: If the `serviceName` is different from the default, make\n * sure it ends with `Gateway`, set the default helper service name to\n * `${serviceName}Helper`, and the default configuration setting to the same as the\n * service name (without the `Gateway`).\n * This way, if you just use `myApi`, the service name will be `myApiGateway`, the\n * helper name will be `myApiGatewayHelper` and the configuration setting `myApi`.\n */\n const defaultServiceName = 'apiGateway';\n let defaultHelperServiceName = 'apiGatewayHelper';\n let defaultConfigSetting = 'api';\n let { serviceName = defaultServiceName } = options;\n if (serviceName !== defaultServiceName) {\n defaultConfigSetting = serviceName;\n if (!serviceName.match(/gateway$/i)) {\n serviceName = `${serviceName}Gateway`;\n }\n defaultHelperServiceName = `${serviceName}Helper`;\n }\n // Register the service.\n app.set(serviceName, () => {\n const {\n helperServiceName = defaultHelperServiceName,\n gatewaySettingName = defaultConfigSetting,\n gatewayClass: GatewayClass = GatewayController,\n } = options;\n\n const gtConfig = app.getConfig<GatewayConfig>(gatewaySettingName);\n\n return new GatewayClass({\n ...options,\n apiConfigSetting: gatewaySettingName,\n gatewayConfig: gtConfig,\n route,\n inject: {\n http: app.get('http'),\n getHelperService: () => app.try(helperServiceName),\n },\n });\n });\n\n return controller(() => {\n // Get the controller.\n const ctrl = app.get<GatewayController>(serviceName);\n /**\n * Check if there are actual middlewares to be included, and in case there are\n * Jimpex middlewares, connect them.\n */\n let useMiddlewares: ExpressMiddleware[] | undefined;\n if (options.getMiddlewares) {\n useMiddlewares = options\n .getMiddlewares(app)\n .map((middleware) => {\n if ('middleware' in middleware) {\n return middleware.connect(app) as ExpressMiddleware | undefined;\n }\n\n return middleware as ExpressMiddleware;\n })\n .filter(notUndefined);\n }\n\n // Add the routes to the router and return it.\n return ctrl.addRoutes(app.get('router'), useMiddlewares);\n });\n },\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAAwC;AACxC,0BAA6B;AAE7B,mBAOO;AAweA,MAAM,kBAAkB;AAAA,EAiD7B,YAAY;AAAA,IACV;AAAA,IACA;AAAA,IACA;AAAA,OACG;AAAA,EACL,GAAwC;AAlDxC,wBAAmB;AAOnB,wBAAmB;AAInB,wBAAmB;AAInB,wBAAmB;AAMnB,wBAAmB;AAInB,wBAAmB;AAInB,wBAAmB;AAInB,wBAAmB;AAInB,wBAAmB;AAInB,wBAAmB;AAUjB,SAAK,OAAO,OAAO;AACnB,SAAK,oBAAoB,OAAO,qBAAqB,MAAM;AAC3D,SAAK,aAAS,4BAAc,KAAK;AACjC,SAAK,WAAW,KAAK;AAAA,UACnB;AAAA,QACE;AAAA,UACE,MAAM;AAAA,UACN,kBAAkB;AAAA,UAClB,SAAS;AAAA,YACP,kBAAkB;AAAA,YAClB,mBAAmB;AA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oB;AAAA,QACpB,qBAAqB;AAAA,QACrB,cAAc,eAAe;AAAA,MAC/B,IAAI;AAEJ,YAAM,WAAW,IAAI,UAAyB,kBAAkB;AAEhE,aAAO,IAAI,aAAa;AAAA,QACtB,GAAG;AAAA,QACH,kBAAkB;AAAA,QAClB,eAAe;AAAA,QACf;AAAA,QACA,QAAQ;AAAA,UACN,MAAM,IAAI,IAAI,MAAM;AAAA,UACpB,kBAAkB,MAAM,IAAI,IAAI,iBAAiB;AAAA,QACnD;AAAA,MACF,CAAC;AAAA,IACH,CAAC;AAED,eAAO,yBAAW,MAAM;AAEtB,YAAM,OAAO,IAAI,IAAuB,WAAW;AAKnD,UAAI;AACJ,UAAI,QAAQ,gBAAgB;AAC1B,yBAAiB,QACd,eAAe,GAAG,EAClB,IAAI,CAAC,eAAe;AACnB,cAAI,gBAAgB,YAAY;AAC9B,mBAAO,WAAW,QAAQ,GAAG;AAAA,UAC/B;AAEA,iBAAO;AAAA,QACT,CAAC,EACA,OAAO,yBAAY;AAAA,MACxB;AAGA,aAAO,KAAK,UAAU,IAAI,IAAI,QAAQ,GAAG,cAAc;AAAA,IACzD,CAAC;AAAA,EACH;AACJ;","names":[]}
@@ -0,0 +1,16 @@
1
+ export { AddGatewayRouteOptions, GatewayConfig, GatewayConfigEndpointDefinition, GatewayConfigEndpointProps, GatewayConfigEndpoints, GatewayController, GatewayControllerAPIConfig, GatewayControllerAPIConfigOptions, GatewayControllerConstructorOptions, GatewayControllerCreatorOptions, GatewayControllerEndpointInfo, GatewayControllerExtraOptions, GatewayControllerGetMiddlewaresFn, GatewayControllerHeaderOptions, GatewayControllerHelperOptions, GatewayControllerOptions, GatewayControllerRequest, GatewayControllerRoute, GatewayControllerRouteMethod, GatewayHelperService, GatewayHelperServiceBaseFnOptions, GatewayHelperServiceErrorHandler, GatewayHelperServiceErrorHandlerOptions, GatewayHelperServiceRequestReducer, GatewayHelperServiceRequestReducerOptions, GatewayHelperServiceResponseHandler, GatewayHelperServiceResponseReducer, GatewayHelperServiceResponseReducerOptions, GatewayHelperServiceStreamVerification, gatewayController } from './gateway.js';
2
+ import '@homer0/jimple';
3
+ import '../../jimpex-7eaee271.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 '@homer0/api-utils';
16
+ import '../../services/http/http.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("./gateway"), module.exports);
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/controllers/utils/index.ts"],"sourcesContent":["export * from './gateway';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,0BAAc,sBAAd;","names":[]}
@@ -0,0 +1,2 @@
1
+ export * from "./jimpex";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/app/index.ts"],"sourcesContent":["export * from './jimpex';\n"],"mappings":"AAAA,cAAc;","names":[]}