jimpex 10.0.2 → 11.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (346) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/README.md +7 -9
  3. package/dist/app/index.d.ts +1 -1
  4. package/dist/app/index.js +1 -22
  5. package/dist/app/index.js.map +1 -1
  6. package/dist/app/jimpex.d.ts +1 -1
  7. package/dist/app/jimpex.js +100 -131
  8. package/dist/app/jimpex.js.map +1 -1
  9. package/dist/controllers/common/config.d.ts +2 -2
  10. package/dist/controllers/common/config.js +12 -39
  11. package/dist/controllers/common/config.js.map +1 -1
  12. package/dist/controllers/common/health.d.ts +4 -4
  13. package/dist/controllers/common/health.js +20 -47
  14. package/dist/controllers/common/health.js.map +1 -1
  15. package/dist/controllers/common/index.d.ts +1 -1
  16. package/dist/controllers/common/index.js +3 -26
  17. package/dist/controllers/common/index.js.map +1 -1
  18. package/dist/controllers/common/statics.d.ts +3 -3
  19. package/dist/controllers/common/statics.js +32 -65
  20. package/dist/controllers/common/statics.js.map +1 -1
  21. package/dist/controllers/index.d.ts +1 -1
  22. package/dist/controllers/index.js +2 -24
  23. package/dist/controllers/index.js.map +1 -1
  24. package/dist/controllers/utils/gateway.d.ts +5 -5
  25. package/dist/controllers/utils/gateway.js +70 -91
  26. package/dist/controllers/utils/gateway.js.map +1 -1
  27. package/dist/controllers/utils/index.d.ts +1 -1
  28. package/dist/controllers/utils/index.js +1 -22
  29. package/dist/controllers/utils/index.js.map +1 -1
  30. package/dist/{index-C6I3NCC-.d.ts → index-BlSpNHox.d.ts} +13 -13
  31. package/dist/index.d.ts +3 -3
  32. package/dist/index.js +6 -32
  33. package/dist/index.js.map +1 -1
  34. package/dist/middlewares/common/errorHandler.d.ts +5 -5
  35. package/dist/middlewares/common/errorHandler.js +31 -56
  36. package/dist/middlewares/common/errorHandler.js.map +1 -1
  37. package/dist/middlewares/common/forceHTTPS.d.ts +1 -1
  38. package/dist/middlewares/common/forceHTTPS.js +8 -35
  39. package/dist/middlewares/common/forceHTTPS.js.map +1 -1
  40. package/dist/middlewares/common/hsts.d.ts +1 -1
  41. package/dist/middlewares/common/hsts.js +12 -39
  42. package/dist/middlewares/common/hsts.js.map +1 -1
  43. package/dist/middlewares/common/index.d.ts +3 -3
  44. package/dist/middlewares/common/index.js +3 -26
  45. package/dist/middlewares/common/index.js.map +1 -1
  46. package/dist/middlewares/html/fastHTML.d.ts +4 -4
  47. package/dist/middlewares/html/fastHTML.js +43 -66
  48. package/dist/middlewares/html/fastHTML.js.map +1 -1
  49. package/dist/middlewares/html/index.d.ts +2 -2
  50. package/dist/middlewares/html/index.js +2 -24
  51. package/dist/middlewares/html/index.js.map +1 -1
  52. package/dist/middlewares/html/showHTML.d.ts +3 -3
  53. package/dist/middlewares/html/showHTML.js +25 -52
  54. package/dist/middlewares/html/showHTML.js.map +1 -1
  55. package/dist/middlewares/index.d.ts +4 -4
  56. package/dist/middlewares/index.js +3 -26
  57. package/dist/middlewares/index.js.map +1 -1
  58. package/dist/middlewares/utils/index.d.ts +3 -3
  59. package/dist/middlewares/utils/index.js +1 -22
  60. package/dist/middlewares/utils/index.js.map +1 -1
  61. package/dist/middlewares/utils/versionValidator.d.ts +5 -5
  62. package/dist/middlewares/utils/versionValidator.js +24 -51
  63. package/dist/middlewares/utils/versionValidator.js.map +1 -1
  64. package/dist/services/common/appError.d.ts +2 -2
  65. package/dist/services/common/appError.js +18 -46
  66. package/dist/services/common/appError.js.map +1 -1
  67. package/dist/services/common/httpError.d.ts +2 -2
  68. package/dist/services/common/httpError.js +7 -33
  69. package/dist/services/common/httpError.js.map +1 -1
  70. package/dist/services/common/index.d.ts +1 -1
  71. package/dist/services/common/index.js +14 -42
  72. package/dist/services/common/index.js.map +1 -1
  73. package/dist/services/common/sendFile.d.ts +1 -1
  74. package/dist/services/common/sendFile.js +4 -29
  75. package/dist/services/common/sendFile.js.map +1 -1
  76. package/dist/services/frontend/frontendFs.d.ts +2 -2
  77. package/dist/services/frontend/frontendFs.js +12 -49
  78. package/dist/services/frontend/frontendFs.js.map +1 -1
  79. package/dist/services/frontend/index.d.ts +2 -2
  80. package/dist/services/frontend/index.js +8 -34
  81. package/dist/services/frontend/index.js.map +1 -1
  82. package/dist/services/html/htmlGenerator.d.ts +5 -5
  83. package/dist/services/html/htmlGenerator.js +46 -75
  84. package/dist/services/html/htmlGenerator.js.map +1 -1
  85. package/dist/services/html/index.d.ts +2 -2
  86. package/dist/services/html/index.js +8 -34
  87. package/dist/services/html/index.js.map +1 -1
  88. package/dist/services/http/apiClient.d.ts +1 -1
  89. package/dist/services/http/apiClient.js +23 -48
  90. package/dist/services/http/apiClient.js.map +1 -1
  91. package/dist/services/http/http.d.ts +5 -5
  92. package/dist/services/http/http.js +23 -60
  93. package/dist/services/http/http.js.map +1 -1
  94. package/dist/services/http/index.d.ts +2 -2
  95. package/dist/services/http/index.js +14 -42
  96. package/dist/services/http/index.js.map +1 -1
  97. package/dist/services/http/responsesBuilder.d.ts +4 -4
  98. package/dist/services/http/responsesBuilder.js +13 -40
  99. package/dist/services/http/responsesBuilder.js.map +1 -1
  100. package/dist/services/index.d.ts +3 -3
  101. package/dist/services/index.js +5 -30
  102. package/dist/services/index.js.map +1 -1
  103. package/dist/services/utils/ensureBearerToken.d.ts +2 -2
  104. package/dist/services/utils/ensureBearerToken.js +15 -42
  105. package/dist/services/utils/ensureBearerToken.js.map +1 -1
  106. package/dist/services/utils/index.d.ts +1 -1
  107. package/dist/services/utils/index.js +8 -34
  108. package/dist/services/utils/index.js.map +1 -1
  109. package/dist/types/events.d.ts +1 -1
  110. package/dist/types/events.js +0 -16
  111. package/dist/types/events.js.map +1 -1
  112. package/dist/types/express.js +0 -16
  113. package/dist/types/express.js.map +1 -1
  114. package/dist/types/http.js +0 -16
  115. package/dist/types/http.js.map +1 -1
  116. package/dist/types/index.d.ts +1 -1
  117. package/dist/types/index.js +6 -32
  118. package/dist/types/index.js.map +1 -1
  119. package/dist/types/options.d.ts +1 -1
  120. package/dist/types/options.js +0 -16
  121. package/dist/types/options.js.map +1 -1
  122. package/dist/types/utils.js +0 -16
  123. package/dist/types/utils.js.map +1 -1
  124. package/dist/types/wootils.js +0 -16
  125. package/dist/types/wootils.js.map +1 -1
  126. package/dist/utils/fns/index.js +4 -28
  127. package/dist/utils/fns/index.js.map +1 -1
  128. package/dist/utils/fns/others.js +2 -26
  129. package/dist/utils/fns/others.js.map +1 -1
  130. package/dist/utils/fns/routes.js +4 -31
  131. package/dist/utils/fns/routes.js.map +1 -1
  132. package/dist/utils/fns/statuses.js +3 -37
  133. package/dist/utils/fns/statuses.js.map +1 -1
  134. package/dist/utils/fns/text.js +2 -26
  135. package/dist/utils/fns/text.js.map +1 -1
  136. package/dist/utils/index.d.ts +1 -1
  137. package/dist/utils/index.js +2 -24
  138. package/dist/utils/index.js.map +1 -1
  139. package/dist/utils/wrappers.d.ts +1 -1
  140. package/dist/utils/wrappers.js +20 -48
  141. package/dist/utils/wrappers.js.map +1 -1
  142. package/eslint.config.js +19 -0
  143. package/examples/basic/app.ts +4 -4
  144. package/examples/basic/controller.ts +2 -2
  145. package/examples/basic/index.ts +4 -4
  146. package/examples/basic/middleware.ts +2 -2
  147. package/examples/basic/service.ts +1 -1
  148. package/package.json +61 -49
  149. package/pnpm-workspace.yaml +4 -0
  150. package/src/app/index.ts +1 -1
  151. package/src/app/jimpex.ts +23 -20
  152. package/src/controllers/common/config.ts +4 -4
  153. package/src/controllers/common/health.ts +9 -5
  154. package/src/controllers/common/index.ts +3 -3
  155. package/src/controllers/common/statics.ts +12 -7
  156. package/src/controllers/index.ts +2 -2
  157. package/src/controllers/utils/gateway.ts +8 -8
  158. package/src/controllers/utils/index.ts +1 -1
  159. package/src/index.ts +6 -6
  160. package/src/middlewares/common/errorHandler.ts +9 -5
  161. package/src/middlewares/common/forceHTTPS.ts +2 -2
  162. package/src/middlewares/common/hsts.ts +2 -2
  163. package/src/middlewares/common/index.ts +3 -3
  164. package/src/middlewares/html/fastHTML.ts +14 -5
  165. package/src/middlewares/html/index.ts +2 -2
  166. package/src/middlewares/html/showHTML.ts +8 -4
  167. package/src/middlewares/index.ts +3 -3
  168. package/src/middlewares/utils/index.ts +1 -1
  169. package/src/middlewares/utils/versionValidator.ts +6 -6
  170. package/src/services/common/appError.ts +1 -1
  171. package/src/services/common/httpError.ts +2 -2
  172. package/src/services/common/index.ts +7 -7
  173. package/src/services/common/sendFile.ts +2 -2
  174. package/src/services/frontend/frontendFs.ts +3 -3
  175. package/src/services/frontend/index.ts +3 -3
  176. package/src/services/html/htmlGenerator.ts +11 -13
  177. package/src/services/html/index.ts +3 -3
  178. package/src/services/http/apiClient.ts +3 -3
  179. package/src/services/http/http.ts +5 -5
  180. package/src/services/http/index.ts +7 -7
  181. package/src/services/http/responsesBuilder.ts +5 -5
  182. package/src/services/index.ts +5 -5
  183. package/src/services/utils/ensureBearerToken.ts +4 -4
  184. package/src/services/utils/index.ts +3 -3
  185. package/src/types/events.ts +8 -8
  186. package/src/types/http.ts +1 -1
  187. package/src/types/index.ts +6 -6
  188. package/src/types/options.ts +2 -2
  189. package/src/types/utils.ts +4 -4
  190. package/src/utils/fns/index.ts +4 -4
  191. package/src/utils/fns/routes.ts +1 -1
  192. package/src/utils/index.ts +2 -2
  193. package/src/utils/wrappers.ts +6 -6
  194. package/tsconfig.json +9 -4
  195. package/tsup.config.ts +1 -2
  196. package/vitest.config.ts +24 -0
  197. package/dist/app/index.d.mts +0 -14
  198. package/dist/app/jimpex.d.mts +0 -14
  199. package/dist/controllers/common/config.d.mts +0 -79
  200. package/dist/controllers/common/health.d.mts +0 -83
  201. package/dist/controllers/common/index.d.mts +0 -22
  202. package/dist/controllers/common/statics.d.mts +0 -223
  203. package/dist/controllers/index.d.mts +0 -25
  204. package/dist/controllers/utils/gateway.d.mts +0 -725
  205. package/dist/controllers/utils/index.d.mts +0 -17
  206. package/dist/esm/app/index.js +0 -2
  207. package/dist/esm/app/index.js.map +0 -1
  208. package/dist/esm/app/jimpex.js +0 -640
  209. package/dist/esm/app/jimpex.js.map +0 -1
  210. package/dist/esm/chunk-V6TY7KAL.js +0 -8
  211. package/dist/esm/chunk-V6TY7KAL.js.map +0 -1
  212. package/dist/esm/controllers/common/config.js +0 -80
  213. package/dist/esm/controllers/common/config.js.map +0 -1
  214. package/dist/esm/controllers/common/health.js +0 -88
  215. package/dist/esm/controllers/common/health.js.map +0 -1
  216. package/dist/esm/controllers/common/index.js +0 -4
  217. package/dist/esm/controllers/common/index.js.map +0 -1
  218. package/dist/esm/controllers/common/statics.js +0 -226
  219. package/dist/esm/controllers/common/statics.js.map +0 -1
  220. package/dist/esm/controllers/index.js +0 -3
  221. package/dist/esm/controllers/index.js.map +0 -1
  222. package/dist/esm/controllers/utils/gateway.js +0 -559
  223. package/dist/esm/controllers/utils/gateway.js.map +0 -1
  224. package/dist/esm/controllers/utils/index.js +0 -2
  225. package/dist/esm/controllers/utils/index.js.map +0 -1
  226. package/dist/esm/index.js +0 -7
  227. package/dist/esm/index.js.map +0 -1
  228. package/dist/esm/middlewares/common/errorHandler.js +0 -116
  229. package/dist/esm/middlewares/common/errorHandler.js.map +0 -1
  230. package/dist/esm/middlewares/common/forceHTTPS.js +0 -52
  231. package/dist/esm/middlewares/common/forceHTTPS.js.map +0 -1
  232. package/dist/esm/middlewares/common/hsts.js +0 -74
  233. package/dist/esm/middlewares/common/hsts.js.map +0 -1
  234. package/dist/esm/middlewares/common/index.js +0 -4
  235. package/dist/esm/middlewares/common/index.js.map +0 -1
  236. package/dist/esm/middlewares/html/fastHTML.js +0 -157
  237. package/dist/esm/middlewares/html/fastHTML.js.map +0 -1
  238. package/dist/esm/middlewares/html/index.js +0 -3
  239. package/dist/esm/middlewares/html/index.js.map +0 -1
  240. package/dist/esm/middlewares/html/showHTML.js +0 -100
  241. package/dist/esm/middlewares/html/showHTML.js.map +0 -1
  242. package/dist/esm/middlewares/index.js +0 -4
  243. package/dist/esm/middlewares/index.js.map +0 -1
  244. package/dist/esm/middlewares/utils/index.js +0 -2
  245. package/dist/esm/middlewares/utils/index.js.map +0 -1
  246. package/dist/esm/middlewares/utils/versionValidator.js +0 -135
  247. package/dist/esm/middlewares/utils/versionValidator.js.map +0 -1
  248. package/dist/esm/services/common/appError.js +0 -98
  249. package/dist/esm/services/common/appError.js.map +0 -1
  250. package/dist/esm/services/common/httpError.js +0 -28
  251. package/dist/esm/services/common/httpError.js.map +0 -1
  252. package/dist/esm/services/common/index.js +0 -17
  253. package/dist/esm/services/common/index.js.map +0 -1
  254. package/dist/esm/services/common/sendFile.js +0 -27
  255. package/dist/esm/services/common/sendFile.js.map +0 -1
  256. package/dist/esm/services/frontend/frontendFs.js +0 -66
  257. package/dist/esm/services/frontend/frontendFs.js.map +0 -1
  258. package/dist/esm/services/frontend/index.js +0 -11
  259. package/dist/esm/services/frontend/index.js.map +0 -1
  260. package/dist/esm/services/html/htmlGenerator.js +0 -192
  261. package/dist/esm/services/html/htmlGenerator.js.map +0 -1
  262. package/dist/esm/services/html/index.js +0 -11
  263. package/dist/esm/services/html/index.js.map +0 -1
  264. package/dist/esm/services/http/apiClient.js +0 -94
  265. package/dist/esm/services/http/apiClient.js.map +0 -1
  266. package/dist/esm/services/http/http.js +0 -180
  267. package/dist/esm/services/http/http.js.map +0 -1
  268. package/dist/esm/services/http/index.js +0 -17
  269. package/dist/esm/services/http/index.js.map +0 -1
  270. package/dist/esm/services/http/responsesBuilder.js +0 -152
  271. package/dist/esm/services/http/responsesBuilder.js.map +0 -1
  272. package/dist/esm/services/index.js +0 -6
  273. package/dist/esm/services/index.js.map +0 -1
  274. package/dist/esm/services/utils/ensureBearerToken.js +0 -94
  275. package/dist/esm/services/utils/ensureBearerToken.js.map +0 -1
  276. package/dist/esm/services/utils/index.js +0 -11
  277. package/dist/esm/services/utils/index.js.map +0 -1
  278. package/dist/esm/types/events.js +0 -1
  279. package/dist/esm/types/events.js.map +0 -1
  280. package/dist/esm/types/express.js +0 -1
  281. package/dist/esm/types/express.js.map +0 -1
  282. package/dist/esm/types/http.js +0 -1
  283. package/dist/esm/types/http.js.map +0 -1
  284. package/dist/esm/types/index.js +0 -7
  285. package/dist/esm/types/index.js.map +0 -1
  286. package/dist/esm/types/options.js +0 -1
  287. package/dist/esm/types/options.js.map +0 -1
  288. package/dist/esm/types/utils.js +0 -1
  289. package/dist/esm/types/utils.js.map +0 -1
  290. package/dist/esm/types/wootils.js +0 -1
  291. package/dist/esm/types/wootils.js.map +0 -1
  292. package/dist/esm/utils/fns/index.js +0 -5
  293. package/dist/esm/utils/fns/index.js.map +0 -1
  294. package/dist/esm/utils/fns/others.js +0 -6
  295. package/dist/esm/utils/fns/others.js.map +0 -1
  296. package/dist/esm/utils/fns/routes.js +0 -25
  297. package/dist/esm/utils/fns/routes.js.map +0 -1
  298. package/dist/esm/utils/fns/statuses.js +0 -6
  299. package/dist/esm/utils/fns/statuses.js.map +0 -1
  300. package/dist/esm/utils/fns/text.js +0 -6
  301. package/dist/esm/utils/fns/text.js.map +0 -1
  302. package/dist/esm/utils/index.js +0 -3
  303. package/dist/esm/utils/index.js.map +0 -1
  304. package/dist/esm/utils/wrappers.js +0 -41
  305. package/dist/esm/utils/wrappers.js.map +0 -1
  306. package/dist/index-Bwf7JHu9.d.mts +0 -1287
  307. package/dist/index.d.mts +0 -47
  308. package/dist/middlewares/common/errorHandler.d.mts +0 -132
  309. package/dist/middlewares/common/forceHTTPS.d.mts +0 -69
  310. package/dist/middlewares/common/hsts.d.mts +0 -110
  311. package/dist/middlewares/common/index.d.mts +0 -22
  312. package/dist/middlewares/html/fastHTML.d.mts +0 -180
  313. package/dist/middlewares/html/index.d.mts +0 -21
  314. package/dist/middlewares/html/showHTML.d.mts +0 -127
  315. package/dist/middlewares/index.d.mts +0 -30
  316. package/dist/middlewares/utils/index.d.mts +0 -20
  317. package/dist/middlewares/utils/versionValidator.d.mts +0 -215
  318. package/dist/services/common/appError.d.mts +0 -139
  319. package/dist/services/common/httpError.d.mts +0 -80
  320. package/dist/services/common/index.d.mts +0 -47
  321. package/dist/services/common/sendFile.d.mts +0 -102
  322. package/dist/services/frontend/frontendFs.d.mts +0 -96
  323. package/dist/services/frontend/index.d.mts +0 -40
  324. package/dist/services/html/htmlGenerator.d.mts +0 -237
  325. package/dist/services/html/index.d.mts +0 -43
  326. package/dist/services/http/apiClient.d.mts +0 -170
  327. package/dist/services/http/http.d.mts +0 -182
  328. package/dist/services/http/index.d.mts +0 -51
  329. package/dist/services/http/responsesBuilder.d.mts +0 -179
  330. package/dist/services/index.d.mts +0 -33
  331. package/dist/services/utils/ensureBearerToken.d.mts +0 -158
  332. package/dist/services/utils/index.d.mts +0 -44
  333. package/dist/types/events.d.mts +0 -14
  334. package/dist/types/express.d.mts +0 -10
  335. package/dist/types/http.d.mts +0 -82
  336. package/dist/types/index.d.mts +0 -14
  337. package/dist/types/options.d.mts +0 -14
  338. package/dist/types/utils.d.mts +0 -48
  339. package/dist/types/wootils.d.mts +0 -4
  340. package/dist/utils/fns/index.d.mts +0 -5
  341. package/dist/utils/fns/others.d.mts +0 -17
  342. package/dist/utils/fns/routes.d.mts +0 -39
  343. package/dist/utils/fns/statuses.d.mts +0 -45
  344. package/dist/utils/fns/text.d.mts +0 -9
  345. package/dist/utils/index.d.mts +0 -19
  346. package/dist/utils/wrappers.d.mts +0 -14
@@ -1,17 +0,0 @@
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.mjs';
2
- import '@homer0/jimple';
3
- import '../../index-Bwf7JHu9.mjs';
4
- import '../../types/express.mjs';
5
- import 'express';
6
- import '../../types/http.mjs';
7
- import 'https';
8
- import 'http';
9
- import 'spdy';
10
- import 'node-fetch';
11
- import '../../types/utils.mjs';
12
- import '@homer0/path-utils';
13
- import '@homer0/simple-logger';
14
- import '@homer0/simple-config';
15
- import '@homer0/events-hub';
16
- import '@homer0/api-utils';
17
- import '../../services/http/http.mjs';
@@ -1,2 +0,0 @@
1
- export * from "./jimpex";
2
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/app/index.ts"],"sourcesContent":["export * from './jimpex';\n"],"mappings":"AAAA,cAAc;","names":[]}
@@ -1,640 +0,0 @@
1
- import {
2
- __publicField
3
- } from "../chunk-V6TY7KAL.js";
4
- import * as path from "path";
5
- import fs from "fs/promises";
6
- import { createServer as createHTTPSServer } from "https";
7
- import { Jimple } from "@homer0/jimple";
8
- import { deepAssignWithOverwrite } from "@homer0/deep-assign";
9
- import { appLoggerProvider } from "@homer0/simple-logger";
10
- import { envUtilsProvider } from "@homer0/env-utils";
11
- import { packageInfoProvider } from "@homer0/package-info";
12
- import { pathUtilsProvider } from "@homer0/path-utils";
13
- import { rootFileProvider } from "@homer0/root-file";
14
- import { tsAsyncImport } from "@homer0/ts-async-import";
15
- import { EventsHub } from "@homer0/events-hub";
16
- import { simpleConfigProvider } from "@homer0/simple-config";
17
- import compression from "compression";
18
- import bodyParser from "body-parser";
19
- import multer from "multer";
20
- import {
21
- createServer as createSpdyServer
22
- } from "spdy";
23
- import express from "express";
24
- import {
25
- commonServicesProvider,
26
- httpServicesProvider,
27
- utilsServicesProvider
28
- } from "../services";
29
- import {
30
- statuses
31
- } from "../utils";
32
- class Jimpex extends Jimple {
33
- /**
34
- * @param options Preferences to customize the application.
35
- * @param config The default settings for the configuration service. It's a
36
- * shortcuit for `options.config.default`
37
- */
38
- constructor(options = {}, config = {}) {
39
- super();
40
- /**
41
- * The customization settings for the application.
42
- */
43
- __publicField(this, "_options");
44
- /**
45
- * The Express application Jimpex uses under the hood.
46
- */
47
- __publicField(this, "_express");
48
- /**
49
- * Since the configuration service has an async initialization, the class uses this flag
50
- * internally to validate if the configuration has been initialized or not.
51
- */
52
- __publicField(this, "_configReady", false);
53
- /**
54
- * A reference to the actuall HTTP the application will use. This can vary depending on
55
- * whether HTTPS, or HTTP2 are enabled. If HTTPS is not enabled, it will be the same as
56
- * the `express` property; if HTTPS is enabled, it will be an `https` server; and if
57
- * HTTP2 is enabled, it will be an `spdy` server.
58
- */
59
- __publicField(this, "_server");
60
- /**
61
- * The instance of the server that is listening for requests.
62
- */
63
- __publicField(this, "_instance");
64
- /**
65
- * A list of functions that implement controllers and middlewares. When the application
66
- * starts, the queue will be processed and those controllers and middlewares will be
67
- * added to the server instance. The reason they are not added directly like with a
68
- * regular Express implementation is that services on Jimple use lazy loading, and
69
- * adding middlewares and controllers as they come could cause errors if they depend on
70
- * services that are not yet registered.
71
- */
72
- __publicField(this, "_mountQueue", []);
73
- /**
74
- * A list with all the top routes controlled by the application. Every time a controller
75
- * is mounted, its route will be added here.
76
- */
77
- __publicField(this, "_controlledRoutes", []);
78
- this._options = deepAssignWithOverwrite(
79
- {
80
- filesizeLimit: "15MB",
81
- boot: true,
82
- path: {
83
- appPath: "",
84
- useParentPath: true
85
- },
86
- config: {
87
- default: options?.config?.default || config,
88
- name: "app",
89
- path: "config/",
90
- hasFolder: false,
91
- loadFromEnvironment: true,
92
- environmentVariable: "CONFIG",
93
- defaultConfigFilename: "[app-name].config.js",
94
- filenameFormat: "[app-name].[config-name].config.js"
95
- },
96
- statics: {
97
- enabled: true,
98
- onHome: false,
99
- route: "statics"
100
- },
101
- express: {
102
- trustProxy: true,
103
- disableXPoweredBy: true,
104
- compression: true,
105
- bodyParser: true,
106
- multer: true
107
- },
108
- services: {
109
- common: true,
110
- http: true,
111
- utils: true
112
- },
113
- healthCheck: () => Promise.resolve(true)
114
- },
115
- options,
116
- this._initOptions()
117
- );
118
- this._express = express();
119
- this._setupCoreServices();
120
- this._setupExpress();
121
- this._configurePath();
122
- this._init();
123
- if (this._options.boot) {
124
- this.boot();
125
- }
126
- }
127
- /**
128
- * This is where the app would register all its specific services, middlewares and controllers.
129
- */
130
- boot() {
131
- }
132
- /**
133
- * Disables the server TLS validation. Meant to be used for development purposes.
134
- */
135
- disableTLSValidation() {
136
- process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = "0";
137
- this.logger.warn("TLS validation has been disabled");
138
- }
139
- /**
140
- * Starts the app server.
141
- *
142
- * @param onStart A callback function to be called when the server actually starts.
143
- * @returns The server instance.
144
- */
145
- async start(onStart) {
146
- await Promise.all([this._setupConfig(), this._loadESMModules()]);
147
- const config = this.getConfig();
148
- const port = config.get("port");
149
- if (!port) {
150
- throw new Error("No port configured");
151
- }
152
- this._emitEvent("beforeStart", { app: this });
153
- this._server = await this._createServer();
154
- this._instance = this._server.listen(port, () => {
155
- this._emitEvent("start", { app: this });
156
- this._mountResources();
157
- this.logger.success(`Starting on port ${port}`);
158
- this._emitEvent("afterStart", { app: this });
159
- if (onStart) {
160
- onStart(config);
161
- }
162
- this._emitEvent("afterStartCallback", { app: this });
163
- });
164
- return this._instance;
165
- }
166
- /**
167
- * This is an alias of `start`. The idea is for it to be used on serverless platforms,
168
- * where you don't get to start your app, you just have export it.
169
- *
170
- * @param port In case the configuration doesn't already have it,
171
- * this is the port where the application will use to run. If this
172
- * parameter is used, the method will overwrite the `port`
173
- * setting on the configuration service.
174
- * @param onStart A callback function to be called when the server starts.
175
- * @returns The server instance.
176
- */
177
- async listen(port, onStart) {
178
- if (port) {
179
- await Promise.all([this._setupConfig(), this._loadESMModules()]);
180
- const config = this.getConfig();
181
- config.set("port", port);
182
- }
183
- return this.start(onStart);
184
- }
185
- /**
186
- * Stops the server instance.
187
- */
188
- stop() {
189
- if (!this._instance) return;
190
- this._emitEvent("beforeStop", { app: this });
191
- this._instance.close();
192
- this._instance = void 0;
193
- this._emitEvent("afterStop", { app: this });
194
- }
195
- /**
196
- * Mounts a route controller or a middleware into a server routes.
197
- *
198
- * @param route The route for the controller/middleware.
199
- * @param controller The controller/middleware resource to be mounted.
200
- */
201
- mount(route, controller) {
202
- let useController;
203
- if ("register" in controller && typeof controller.register === "function" && controller.provider === true) {
204
- useController = controller.register(this, route);
205
- } else if ("connect" in controller && typeof controller.connect === "function" && ("middleware" in controller && controller.middleware === true || "controller" in controller && controller.controller === true)) {
206
- useController = controller;
207
- } else {
208
- useController = {
209
- middleware: true,
210
- connect: () => controller
211
- };
212
- }
213
- this._mountQueue.push((server) => {
214
- const connected = useController.connect(this, route);
215
- if (!connected) return;
216
- const router = this._reduceWithEvent("controllerWillBeMounted", connected, {
217
- route,
218
- controller: useController,
219
- app: this
220
- });
221
- server.use(route, router);
222
- this._emitEvent("routeAdded", { route, app: this });
223
- this._controlledRoutes.push(route);
224
- });
225
- }
226
- /**
227
- * Adds a global middleware to the application.
228
- *
229
- * @param middleware The middleware resource to be added.
230
- */
231
- use(middleware) {
232
- const useMiddleware = "register" in middleware && typeof middleware.register === "function" ? middleware.register(this) : middleware;
233
- this._mountQueue.push((server) => {
234
- if ("connect" in useMiddleware && typeof useMiddleware.connect === "function") {
235
- const handler = useMiddleware.connect(this);
236
- if (handler) {
237
- server.use(
238
- this._reduceWithEvent("middlewareWillBeUsed", handler, { app: this })
239
- );
240
- }
241
- return;
242
- }
243
- server.use(
244
- this._reduceWithEvent(
245
- "middlewareWillBeUsed",
246
- useMiddleware,
247
- { app: this }
248
- )
249
- );
250
- });
251
- }
252
- /**
253
- * Gets a setting from the configuration, or the configuration itself.
254
- *
255
- * @param setting The setting or settings to be retrieved. If is not specified, it
256
- * will return the entire configuration.
257
- * @param asArray If `true` and `setting` is an array, it will return the values as
258
- * an array instead of an object.
259
- * @template T The type of the setting to be retrieved.
260
- */
261
- getConfig(setting, asArray = false) {
262
- const config = this.try("config");
263
- if (!config) {
264
- throw new Error("The config service is not available until the app starts");
265
- }
266
- if (typeof setting === "undefined") {
267
- return config;
268
- }
269
- return config.get(setting, asArray);
270
- }
271
- /**
272
- * Creates a new router instance.
273
- */
274
- getRouter() {
275
- return this.get("router");
276
- }
277
- /**
278
- * The logger service.
279
- */
280
- get logger() {
281
- return this.get("logger");
282
- }
283
- /**
284
- * The Express application Jimpex uses under the hood.
285
- */
286
- get express() {
287
- return this._express;
288
- }
289
- /**
290
- * The server instance that gets created when the app is started.
291
- */
292
- get instance() {
293
- return this._instance;
294
- }
295
- /**
296
- * The application customization options.
297
- */
298
- get options() {
299
- return deepAssignWithOverwrite({}, this._options);
300
- }
301
- /**
302
- * Gets the events service.
303
- */
304
- get eventsHub() {
305
- return this.get("events");
306
- }
307
- /**
308
- * A list of the routes that have controllers mounted on them.
309
- */
310
- get routes() {
311
- return this._controlledRoutes.slice();
312
- }
313
- /**
314
- * Adds a listener for an application event.
315
- *
316
- * @param eventName The name of the event to listen for.
317
- * @param listener The listener function.
318
- * @returns A function to unsubscribe the listener.
319
- * @template EventName The name of the event, to match the type of the listener
320
- * function.
321
- */
322
- on(eventName, listener) {
323
- return this.eventsHub.on(eventName, listener);
324
- }
325
- /**
326
- * Adds a listener for an application event that will only be execuded once: the first
327
- * time the event is triggered.
328
- *
329
- * @param eventName The name of the event to listen for.
330
- * @param listener The listener function.
331
- * @returns A function to unsubscribe the listener.
332
- * @template EventName The name of the event, to match the type of the listener
333
- * function.
334
- */
335
- once(eventName, listener) {
336
- return this.eventsHub.once(eventName, listener);
337
- }
338
- /**
339
- * Based on the application options, it returns wheter the application is healthy or
340
- * not.
341
- */
342
- isHealthy() {
343
- return this._options.healthCheck(this);
344
- }
345
- /**
346
- * This method is like a "lifecycle method", it gets executed on the constructor right
347
- * before the "boot step". The idea is for the method to be a helper when the
348
- * application is defined by subclassing {@link Jimpex}: the application could register
349
- * all important services here and the routes on boot, then, if the implementation needs
350
- * to access or overwrite a something, it can send `boot: false`, access/register what
351
- * it needs, and then call `boot()`. That would be impossible for an application without
352
- * overwriting the constructor and the boot functionality.
353
- */
354
- _init() {
355
- }
356
- /**
357
- * It generates overwrites for the application options when it gets created. This method
358
- * is a helper for when the application is defined by subclassing {@link Jimpex}: It's
359
- * highly probable that if the application needs to change the default options, it would
360
- * want to do it right from the class, instead of having to do it on every
361
- * implementation. A way to do it would be overwriting the constructor and calling
362
- * `super` with the custom overwrites, but this method exists so that won't be
363
- * necessary: when creating the `options`, the constructor will merge the result of this
364
- * method on top of the default ones.
365
- */
366
- _initOptions() {
367
- return {};
368
- }
369
- /**
370
- * Registers the "core services" on the container: logger, events, utils, etc.
371
- */
372
- _setupCoreServices() {
373
- this.register(
374
- appLoggerProvider({
375
- serviceName: "logger"
376
- })
377
- );
378
- this.register(envUtilsProvider);
379
- this.register(packageInfoProvider);
380
- this.register(pathUtilsProvider);
381
- this.register(rootFileProvider);
382
- const { services: enabledServices } = this._options;
383
- if (enabledServices.common) this.register(commonServicesProvider);
384
- if (enabledServices.http) this.register(httpServicesProvider);
385
- if (enabledServices.utils) this.register(utilsServicesProvider);
386
- this.set("events", () => new EventsHub());
387
- this.set("statuses", () => statuses);
388
- }
389
- /**
390
- * Configures the Express application based on the class options.
391
- */
392
- _setupExpress() {
393
- const { statics, filesizeLimit, express: expressOptions } = this._options;
394
- if (expressOptions.trustProxy) {
395
- this._express.enable("trust proxy");
396
- }
397
- if (expressOptions.disableXPoweredBy) {
398
- this._express.disable("x-powered-by");
399
- }
400
- if (expressOptions.compression) {
401
- this._express.use(compression());
402
- }
403
- if (statics.enabled) {
404
- this._addStaticsFolder(statics.route, statics.folder, statics.onHome);
405
- }
406
- if (expressOptions.bodyParser) {
407
- this._express.use(
408
- bodyParser.json({
409
- limit: filesizeLimit
410
- })
411
- );
412
- this._express.use(
413
- bodyParser.urlencoded({
414
- extended: true,
415
- limit: filesizeLimit
416
- })
417
- );
418
- }
419
- if (expressOptions.multer) {
420
- this._express.use(multer().any());
421
- }
422
- this.set(
423
- "router",
424
- this.factory(() => express.Router())
425
- );
426
- }
427
- /**
428
- * Adds a static folder to the application.
429
- *
430
- * @param route The route to add the folder to.
431
- * @param folder The path to the folder in the file system. If not defined, it will
432
- * be use the same value as `route`. The path could be relative to the
433
- * project root, or where the application executable is located,
434
- * depending on the value of the `onHome` parameter.
435
- * @param onHome If `true`, the path to the folder will be relative to the project
436
- * root. If `false`, it will be relative to where the application
437
- * executable is located.
438
- */
439
- _addStaticsFolder(route, folder = "", onHome = false) {
440
- const location = onHome ? "home" : "app";
441
- const staticRoute = route.replace(/^\/+/, "");
442
- const pathUtils = this.get("pathUtils");
443
- const staticFolder = pathUtils.joinFrom(location, folder || staticRoute);
444
- this.mount(`/${staticRoute}`, {
445
- connect: () => express.static(staticFolder),
446
- controller: true
447
- });
448
- }
449
- /**
450
- * This helper method validates the `path` options in order to register the `app`
451
- * location in the `pathUtils` service. The `app` location should be the path to where
452
- * the application executable is located, but due to how ESM works, we can't infer it
453
- * from the `module` object, so we need either recieved as the `appPath` setting, or try
454
- * to get it from the parent module.
455
- *
456
- * @throws If the method should use the path from the parent module, but can't find
457
- * it.
458
- */
459
- _configurePath() {
460
- const pathUtils = this.get("pathUtils");
461
- const {
462
- path: { appPath, useParentPath }
463
- } = this._options;
464
- if (appPath) {
465
- pathUtils.addLocation("app", appPath);
466
- return;
467
- }
468
- let foundPath = false;
469
- if (useParentPath) {
470
- const stack = new Error().stack;
471
- const stackList = stack.split("\n");
472
- stackList.shift();
473
- const parentFromStack = stackList.find((line) => !line.includes(__filename));
474
- if (parentFromStack) {
475
- const parentFile = parentFromStack.replace(/^.*?\s\(([^\s]+):\d+:\d+\)/, "$1");
476
- if (parentFile !== parentFromStack) {
477
- foundPath = true;
478
- pathUtils.addLocation("app", path.dirname(parentFile));
479
- }
480
- }
481
- }
482
- if (!foundPath) {
483
- throw new Error(
484
- "The app location cannot be determined. Please specify the appPath option."
485
- );
486
- }
487
- }
488
- /**
489
- * Setups the configuration service. The new configuration service requires async calls
490
- * in order to load the configuration files (as it uses `import` instead of `require`),
491
- * so it can't be instantiated as the other services.
492
- * This method is called just before starting the application.
493
- */
494
- async _setupConfig() {
495
- if (this._configReady) return;
496
- this._configReady = true;
497
- const { config: options } = this._options;
498
- let configsPath = options.path.replace(/\/$/, "");
499
- if (options.hasFolder) {
500
- configsPath = `${configsPath}${path.sep}${options.name}${path.sep}`;
501
- }
502
- const filenameFormat = options.filenameFormat.replace(/\[app-name\]/gi, options.name).replace(/\[config-name\]/gi, "[name]");
503
- const defaultConfigFilename = options.defaultConfigFilename.replace(
504
- /\[app-name\]/gi,
505
- options.name
506
- );
507
- this.register(
508
- simpleConfigProvider({
509
- name: options.name,
510
- defaultConfig: options.default,
511
- defaultConfigFilename,
512
- envVarName: options.environmentVariable,
513
- path: configsPath,
514
- filenameFormat
515
- })
516
- );
517
- const config = this.getConfig();
518
- await config.loadFromFile("", true, false);
519
- if (options.loadFromEnvironment) {
520
- await config.loadFromEnv();
521
- }
522
- }
523
- /**
524
- * Loads the ESM modules that are needed by Jimpex. This is called just before the starting
525
- * the application so they'll be available for all the services.
526
- */
527
- async _loadESMModules() {
528
- const { default: nodeFetch } = await tsAsyncImport("node-fetch");
529
- const { default: mime } = await tsAsyncImport("mime");
530
- this.set("node-fetch", () => nodeFetch);
531
- this.set("mime", () => mime);
532
- }
533
- /**
534
- * Processes the resources from the mount queue (added with {@link Jimpex.mount} and
535
- * {@link Jimpex.use}), and adds them to the Express application.
536
- */
537
- _mountResources() {
538
- this._mountQueue.forEach((mount) => mount(this._express));
539
- this._mountQueue.length = 0;
540
- }
541
- /**
542
- * Emits an event using the `events` service.
543
- *
544
- * @param name The name of the event to emit.
545
- * @param payload The event payload.
546
- * @template EventName The literal name of the event, to type the event payload.
547
- */
548
- _emitEvent(name, payload) {
549
- this.eventsHub.emit(name, payload);
550
- }
551
- /**
552
- * Sends a target object to a list of reducer events so they can modify or replace it.
553
- *
554
- * @param name The name of the event to use.
555
- * @param target The object to reduce with the event.
556
- * @param payload Extra context for the listeners.
557
- */
558
- _reduceWithEvent(name, target, payload) {
559
- return this.eventsHub.reduceSync(name, target, payload);
560
- }
561
- /**
562
- * Loads the contents of a dictionary of credentials files that need to be used to
563
- * configure HTTPS.
564
- *
565
- * @param credentialsInfo The dictionary where the keys are the type of credentials
566
- * (`ca`, `cert`, `key`) and the values are the paths to the
567
- * files.
568
- * @param onHome If this is `true`, the path of the files will be relative
569
- * to the project root. If it is `false`, it will be relative
570
- * to where the application executable is located.
571
- * @returns
572
- */
573
- async _loadCredentials(credentialsInfo, onHome = true) {
574
- const location = onHome ? "home" : "app";
575
- const pathUtils = this.get("pathUtils");
576
- const keys = ["ca", "cert", "key"];
577
- const info = await Promise.all(
578
- keys.map(async (key) => {
579
- const filepath = credentialsInfo[key];
580
- if (!filepath) return void 0;
581
- const file = await fs.readFile(pathUtils.joinFrom(location, filepath), "utf8");
582
- return {
583
- key,
584
- file
585
- };
586
- })
587
- );
588
- return info.reduce((acc, item) => {
589
- if (item) {
590
- acc[item.key] = item.file;
591
- }
592
- return acc;
593
- }, {});
594
- }
595
- /**
596
- * Validates the configuration and chooses the server the application needs to use: If
597
- * HTTP2 is enabled, it will use Spdy; if HTTPS is enabled but HTTP is not, it will use
598
- * the native HTTPS server; otherwise, it will be just the Express instance.
599
- *
600
- * @returns {Server}
601
- * @throws {Error} If HTTP2 is enabled but HTTPS is not.
602
- * @throws {Error} If HTTPS is enabled but there's no `https.credentials` object.
603
- * @throws {Error} If HTTPS is enabled and no creadentials are found.
604
- * @access protected
605
- * @ignore
606
- */
607
- async _createServer() {
608
- const [http2Config = {}, httpsConfig = {}] = this.getConfig(["http2", "https"], true);
609
- if (!http2Config.enabled && !httpsConfig.enabled) {
610
- return this._express;
611
- }
612
- if (http2Config.enabled && !httpsConfig.enabled) {
613
- throw new Error("HTTP2 requires for HTTPS to be enabled");
614
- }
615
- if (!httpsConfig.credentials) {
616
- throw new Error("The `credentials` object on the HTTPS settings is missing");
617
- }
618
- const credentials = await this._loadCredentials(
619
- httpsConfig.credentials,
620
- httpsConfig.credentials.onHome
621
- );
622
- if (!Object.keys(credentials).length) {
623
- throw new Error("No credentials were found for HTTPS");
624
- }
625
- if (http2Config.enabled) {
626
- const serverOptions = {
627
- ...credentials,
628
- spdy: http2Config.spdy
629
- };
630
- return createSpdyServer(serverOptions, this._express);
631
- }
632
- return createHTTPSServer(credentials, this._express);
633
- }
634
- }
635
- const jimpex = (...args) => new Jimpex(...args);
636
- export {
637
- Jimpex,
638
- jimpex
639
- };
640
- //# sourceMappingURL=jimpex.js.map