jimpex 7.0.2 → 9.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +93 -0
- package/LICENSE +1 -1
- package/README.md +447 -435
- package/dist/app/index.d.mts +14 -0
- package/dist/app/index.d.ts +14 -0
- package/dist/app/index.js +23 -0
- package/dist/app/index.js.map +1 -0
- package/dist/app/jimpex.d.mts +14 -0
- package/dist/app/jimpex.d.ts +14 -0
- package/dist/app/jimpex.js +665 -0
- package/dist/app/jimpex.js.map +1 -0
- package/dist/controllers/common/config.d.mts +79 -0
- package/dist/controllers/common/config.d.ts +79 -0
- package/dist/controllers/common/config.js +107 -0
- package/dist/controllers/common/config.js.map +1 -0
- package/dist/controllers/common/health.d.mts +83 -0
- package/dist/controllers/common/health.d.ts +83 -0
- package/dist/controllers/common/health.js +115 -0
- package/dist/controllers/common/health.js.map +1 -0
- package/dist/controllers/common/index.d.mts +21 -0
- package/dist/controllers/common/index.d.ts +21 -0
- package/dist/controllers/common/index.js +27 -0
- package/dist/controllers/common/index.js.map +1 -0
- package/dist/controllers/common/statics.d.mts +215 -0
- package/dist/controllers/common/statics.d.ts +215 -0
- package/dist/controllers/common/statics.js +253 -0
- package/dist/controllers/common/statics.js.map +1 -0
- package/dist/controllers/index.d.mts +24 -0
- package/dist/controllers/index.d.ts +24 -0
- package/dist/controllers/index.js +25 -0
- package/dist/controllers/index.js.map +1 -0
- package/dist/controllers/utils/gateway.d.mts +725 -0
- package/dist/controllers/utils/gateway.d.ts +725 -0
- package/dist/controllers/utils/gateway.js +577 -0
- package/dist/controllers/utils/gateway.js.map +1 -0
- package/dist/controllers/utils/index.d.mts +17 -0
- package/dist/controllers/utils/index.d.ts +17 -0
- package/dist/controllers/utils/index.js +23 -0
- package/dist/controllers/utils/index.js.map +1 -0
- package/dist/esm/app/index.js +2 -0
- package/dist/esm/app/index.js.map +1 -0
- package/dist/esm/app/jimpex.js +636 -0
- package/dist/esm/app/jimpex.js.map +1 -0
- package/dist/esm/chunk-2B2CG5KL.js +11 -0
- package/dist/esm/chunk-2B2CG5KL.js.map +1 -0
- package/dist/esm/controllers/common/config.js +80 -0
- package/dist/esm/controllers/common/config.js.map +1 -0
- package/dist/esm/controllers/common/health.js +88 -0
- package/dist/esm/controllers/common/health.js.map +1 -0
- package/dist/esm/controllers/common/index.js +4 -0
- package/dist/esm/controllers/common/index.js.map +1 -0
- package/dist/esm/controllers/common/statics.js +220 -0
- package/dist/esm/controllers/common/statics.js.map +1 -0
- package/dist/esm/controllers/index.js +3 -0
- package/dist/esm/controllers/index.js.map +1 -0
- package/dist/esm/controllers/utils/gateway.js +556 -0
- package/dist/esm/controllers/utils/gateway.js.map +1 -0
- package/dist/esm/controllers/utils/index.js +2 -0
- package/dist/esm/controllers/utils/index.js.map +1 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/middlewares/common/errorHandler.js +116 -0
- package/dist/esm/middlewares/common/errorHandler.js.map +1 -0
- package/dist/esm/middlewares/common/forceHTTPS.js +53 -0
- package/dist/esm/middlewares/common/forceHTTPS.js.map +1 -0
- package/dist/esm/middlewares/common/hsts.js +74 -0
- package/dist/esm/middlewares/common/hsts.js.map +1 -0
- package/dist/esm/middlewares/common/index.js +4 -0
- package/dist/esm/middlewares/common/index.js.map +1 -0
- package/dist/esm/middlewares/html/fastHTML.js +158 -0
- package/dist/esm/middlewares/html/fastHTML.js.map +1 -0
- package/dist/esm/middlewares/html/index.js +3 -0
- package/dist/esm/middlewares/html/index.js.map +1 -0
- package/dist/esm/middlewares/html/showHTML.js +100 -0
- package/dist/esm/middlewares/html/showHTML.js.map +1 -0
- package/dist/esm/middlewares/index.js +4 -0
- package/dist/esm/middlewares/index.js.map +1 -0
- package/dist/esm/middlewares/utils/index.js +2 -0
- package/dist/esm/middlewares/utils/index.js.map +1 -0
- package/dist/esm/middlewares/utils/versionValidator.js +135 -0
- package/dist/esm/middlewares/utils/versionValidator.js.map +1 -0
- package/dist/esm/services/common/appError.js +98 -0
- package/dist/esm/services/common/appError.js.map +1 -0
- package/dist/esm/services/common/httpError.js +28 -0
- package/dist/esm/services/common/httpError.js.map +1 -0
- package/dist/esm/services/common/index.js +17 -0
- package/dist/esm/services/common/index.js.map +1 -0
- package/dist/esm/services/common/sendFile.js +27 -0
- package/dist/esm/services/common/sendFile.js.map +1 -0
- package/dist/esm/services/frontend/frontendFs.js +66 -0
- package/dist/esm/services/frontend/frontendFs.js.map +1 -0
- package/dist/esm/services/frontend/index.js +11 -0
- package/dist/esm/services/frontend/index.js.map +1 -0
- package/dist/esm/services/html/htmlGenerator.js +194 -0
- package/dist/esm/services/html/htmlGenerator.js.map +1 -0
- package/dist/esm/services/html/index.js +11 -0
- package/dist/esm/services/html/index.js.map +1 -0
- package/dist/esm/services/http/apiClient.js +97 -0
- package/dist/esm/services/http/apiClient.js.map +1 -0
- package/dist/esm/services/http/http.js +174 -0
- package/dist/esm/services/http/http.js.map +1 -0
- package/dist/esm/services/http/index.js +17 -0
- package/dist/esm/services/http/index.js.map +1 -0
- package/dist/esm/services/http/responsesBuilder.js +152 -0
- package/dist/esm/services/http/responsesBuilder.js.map +1 -0
- package/dist/esm/services/index.js +6 -0
- package/dist/esm/services/index.js.map +1 -0
- package/dist/esm/services/utils/ensureBearerToken.js +94 -0
- package/dist/esm/services/utils/ensureBearerToken.js.map +1 -0
- package/dist/esm/services/utils/index.js +11 -0
- package/dist/esm/services/utils/index.js.map +1 -0
- package/dist/esm/types/events.js +1 -0
- package/dist/esm/types/events.js.map +1 -0
- package/dist/esm/types/express.js +1 -0
- package/dist/esm/types/express.js.map +1 -0
- package/dist/esm/types/http.js +1 -0
- package/dist/esm/types/http.js.map +1 -0
- package/dist/esm/types/index.js +7 -0
- package/dist/esm/types/index.js.map +1 -0
- package/dist/esm/types/options.js +1 -0
- package/dist/esm/types/options.js.map +1 -0
- package/dist/esm/types/utils.js +1 -0
- package/dist/esm/types/utils.js.map +1 -0
- package/dist/esm/types/wootils.js +1 -0
- package/dist/esm/types/wootils.js.map +1 -0
- package/dist/esm/utils/fns/index.js +5 -0
- package/dist/esm/utils/fns/index.js.map +1 -0
- package/dist/esm/utils/fns/others.js +6 -0
- package/dist/esm/utils/fns/others.js.map +1 -0
- package/dist/esm/utils/fns/routes.js +25 -0
- package/dist/esm/utils/fns/routes.js.map +1 -0
- package/dist/esm/utils/fns/statuses.js +6 -0
- package/dist/esm/utils/fns/statuses.js.map +1 -0
- package/dist/esm/utils/fns/text.js +6 -0
- package/dist/esm/utils/fns/text.js.map +1 -0
- package/dist/esm/utils/index.js +3 -0
- package/dist/esm/utils/index.js.map +1 -0
- package/dist/esm/utils/wrappers.js +41 -0
- package/dist/esm/utils/wrappers.js.map +1 -0
- package/dist/index-b2a04c78.d.ts +1282 -0
- package/dist/index-efeb437e.d.ts +1282 -0
- package/dist/index.d.mts +46 -0
- package/dist/index.d.ts +46 -0
- package/dist/index.js +33 -0
- package/dist/index.js.map +1 -0
- package/dist/middlewares/common/errorHandler.d.mts +132 -0
- package/dist/middlewares/common/errorHandler.d.ts +132 -0
- package/dist/middlewares/common/errorHandler.js +143 -0
- package/dist/middlewares/common/errorHandler.js.map +1 -0
- package/dist/middlewares/common/forceHTTPS.d.mts +69 -0
- package/dist/middlewares/common/forceHTTPS.d.ts +69 -0
- package/dist/middlewares/common/forceHTTPS.js +80 -0
- package/dist/middlewares/common/forceHTTPS.js.map +1 -0
- package/dist/middlewares/common/hsts.d.mts +110 -0
- package/dist/middlewares/common/hsts.d.ts +110 -0
- package/dist/middlewares/common/hsts.js +101 -0
- package/dist/middlewares/common/hsts.js.map +1 -0
- package/dist/middlewares/common/index.d.mts +22 -0
- package/dist/middlewares/common/index.d.ts +22 -0
- package/dist/middlewares/common/index.js +27 -0
- package/dist/middlewares/common/index.js.map +1 -0
- package/dist/middlewares/html/fastHTML.d.mts +180 -0
- package/dist/middlewares/html/fastHTML.d.ts +180 -0
- package/dist/middlewares/html/fastHTML.js +185 -0
- package/dist/middlewares/html/fastHTML.js.map +1 -0
- package/dist/middlewares/html/index.d.mts +21 -0
- package/dist/middlewares/html/index.d.ts +21 -0
- package/dist/middlewares/html/index.js +25 -0
- package/dist/middlewares/html/index.js.map +1 -0
- package/dist/middlewares/html/showHTML.d.mts +127 -0
- package/dist/middlewares/html/showHTML.d.ts +127 -0
- package/dist/middlewares/html/showHTML.js +127 -0
- package/dist/middlewares/html/showHTML.js.map +1 -0
- package/dist/middlewares/index.d.mts +30 -0
- package/dist/middlewares/index.d.ts +30 -0
- package/dist/middlewares/index.js +27 -0
- package/dist/middlewares/index.js.map +1 -0
- package/dist/middlewares/utils/index.d.mts +20 -0
- package/dist/middlewares/utils/index.d.ts +20 -0
- package/dist/middlewares/utils/index.js +23 -0
- package/dist/middlewares/utils/index.js.map +1 -0
- package/dist/middlewares/utils/versionValidator.d.mts +215 -0
- package/dist/middlewares/utils/versionValidator.d.ts +215 -0
- package/dist/middlewares/utils/versionValidator.js +162 -0
- package/dist/middlewares/utils/versionValidator.js.map +1 -0
- package/dist/services/common/appError.d.mts +139 -0
- package/dist/services/common/appError.d.ts +139 -0
- package/dist/services/common/appError.js +126 -0
- package/dist/services/common/appError.js.map +1 -0
- package/dist/services/common/httpError.d.mts +80 -0
- package/dist/services/common/httpError.d.ts +80 -0
- package/dist/services/common/httpError.js +53 -0
- package/dist/services/common/httpError.js.map +1 -0
- package/dist/services/common/index.d.mts +47 -0
- package/dist/services/common/index.d.ts +47 -0
- package/dist/services/common/index.js +44 -0
- package/dist/services/common/index.js.map +1 -0
- package/dist/services/common/sendFile.d.mts +102 -0
- package/dist/services/common/sendFile.d.ts +102 -0
- package/dist/services/common/sendFile.js +51 -0
- package/dist/services/common/sendFile.js.map +1 -0
- package/dist/services/frontend/frontendFs.d.mts +96 -0
- package/dist/services/frontend/frontendFs.d.ts +96 -0
- package/dist/services/frontend/frontendFs.js +103 -0
- package/dist/services/frontend/frontendFs.js.map +1 -0
- package/dist/services/frontend/index.d.mts +40 -0
- package/dist/services/frontend/index.d.ts +40 -0
- package/dist/services/frontend/index.js +36 -0
- package/dist/services/frontend/index.js.map +1 -0
- package/dist/services/html/htmlGenerator.d.mts +237 -0
- package/dist/services/html/htmlGenerator.d.ts +237 -0
- package/dist/services/html/htmlGenerator.js +221 -0
- package/dist/services/html/htmlGenerator.js.map +1 -0
- package/dist/services/html/index.d.mts +43 -0
- package/dist/services/html/index.d.ts +43 -0
- package/dist/services/html/index.js +36 -0
- package/dist/services/html/index.js.map +1 -0
- package/dist/services/http/apiClient.d.mts +170 -0
- package/dist/services/http/apiClient.d.ts +170 -0
- package/dist/services/http/apiClient.js +122 -0
- package/dist/services/http/apiClient.js.map +1 -0
- package/dist/services/http/http.d.mts +176 -0
- package/dist/services/http/http.d.ts +176 -0
- package/dist/services/http/http.js +211 -0
- package/dist/services/http/http.js.map +1 -0
- package/dist/services/http/index.d.mts +51 -0
- package/dist/services/http/index.d.ts +51 -0
- package/dist/services/http/index.js +44 -0
- package/dist/services/http/index.js.map +1 -0
- package/dist/services/http/responsesBuilder.d.mts +179 -0
- package/dist/services/http/responsesBuilder.d.ts +179 -0
- package/dist/services/http/responsesBuilder.js +179 -0
- package/dist/services/http/responsesBuilder.js.map +1 -0
- package/dist/services/index.d.mts +33 -0
- package/dist/services/index.d.ts +33 -0
- package/dist/services/index.js +31 -0
- package/dist/services/index.js.map +1 -0
- package/dist/services/utils/ensureBearerToken.d.mts +158 -0
- package/dist/services/utils/ensureBearerToken.d.ts +158 -0
- package/dist/services/utils/ensureBearerToken.js +121 -0
- package/dist/services/utils/ensureBearerToken.js.map +1 -0
- package/dist/services/utils/index.d.mts +44 -0
- package/dist/services/utils/index.d.ts +44 -0
- package/dist/services/utils/index.js +36 -0
- package/dist/services/utils/index.js.map +1 -0
- package/dist/types/events.d.mts +14 -0
- package/dist/types/events.d.ts +14 -0
- package/dist/types/events.js +17 -0
- package/dist/types/events.js.map +1 -0
- package/dist/types/express.d.mts +10 -0
- package/dist/types/express.d.ts +10 -0
- package/dist/types/express.js +17 -0
- package/dist/types/express.js.map +1 -0
- package/dist/types/http.d.mts +79 -0
- package/dist/types/http.d.ts +79 -0
- package/dist/types/http.js +17 -0
- package/dist/types/http.js.map +1 -0
- package/dist/types/index.d.mts +14 -0
- package/dist/types/index.d.ts +14 -0
- package/dist/types/index.js +33 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/options.d.mts +14 -0
- package/dist/types/options.d.ts +14 -0
- package/dist/types/options.js +17 -0
- package/dist/types/options.js.map +1 -0
- package/dist/types/utils.d.mts +48 -0
- package/dist/types/utils.d.ts +48 -0
- package/dist/types/utils.js +17 -0
- package/dist/types/utils.js.map +1 -0
- package/dist/types/wootils.d.mts +4 -0
- package/dist/types/wootils.d.ts +4 -0
- package/dist/types/wootils.js +17 -0
- package/dist/types/wootils.js.map +1 -0
- package/dist/utils/fns/index.d.mts +5 -0
- package/dist/utils/fns/index.d.ts +5 -0
- package/dist/utils/fns/index.js +29 -0
- package/dist/utils/fns/index.js.map +1 -0
- package/dist/utils/fns/others.d.mts +17 -0
- package/dist/utils/fns/others.d.ts +17 -0
- package/dist/utils/fns/others.js +29 -0
- package/dist/utils/fns/others.js.map +1 -0
- package/dist/utils/fns/routes.d.mts +39 -0
- package/dist/utils/fns/routes.d.ts +39 -0
- package/dist/utils/fns/routes.js +51 -0
- package/dist/utils/fns/routes.js.map +1 -0
- package/dist/utils/fns/statuses.d.mts +45 -0
- package/dist/utils/fns/statuses.d.ts +45 -0
- package/dist/utils/fns/statuses.js +39 -0
- package/dist/utils/fns/statuses.js.map +1 -0
- package/dist/utils/fns/text.d.mts +9 -0
- package/dist/utils/fns/text.d.ts +9 -0
- package/dist/utils/fns/text.js +29 -0
- package/dist/utils/fns/text.js.map +1 -0
- package/dist/utils/index.d.mts +19 -0
- package/dist/utils/index.d.ts +19 -0
- package/dist/utils/index.js +25 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/wrappers.d.mts +14 -0
- package/dist/utils/wrappers.d.ts +14 -0
- package/dist/utils/wrappers.js +68 -0
- package/dist/utils/wrappers.js.map +1 -0
- package/examples/basic/404.html +12 -0
- package/examples/basic/README.md +30 -0
- package/examples/basic/app.ts +18 -0
- package/examples/basic/controller.ts +45 -0
- package/examples/basic/index.ts +19 -0
- package/examples/basic/middleware.ts +13 -0
- package/examples/basic/service.ts +11 -0
- package/package.json +60 -39
- package/src/app/index.ts +1 -0
- package/src/app/jimpex.ts +743 -0
- package/src/controllers/common/config.ts +115 -0
- package/src/controllers/common/health.ts +128 -0
- package/src/controllers/common/index.ts +3 -0
- package/src/controllers/common/statics.ts +380 -0
- package/src/controllers/index.ts +2 -0
- package/src/controllers/utils/gateway.ts +1186 -0
- package/src/controllers/utils/index.ts +1 -0
- package/src/index.ts +6 -0
- package/src/middlewares/common/errorHandler.ts +203 -0
- package/src/middlewares/common/forceHTTPS.ts +83 -0
- package/src/middlewares/common/hsts.ts +135 -0
- package/src/middlewares/common/index.ts +3 -0
- package/src/middlewares/html/fastHTML.ts +255 -0
- package/src/middlewares/html/index.ts +2 -0
- package/src/middlewares/html/showHTML.ts +165 -0
- package/src/middlewares/index.ts +3 -0
- package/src/middlewares/utils/index.ts +1 -0
- package/src/middlewares/utils/versionValidator.ts +289 -0
- package/src/services/common/appError.ts +158 -0
- package/src/services/common/httpError.ts +74 -0
- package/src/services/common/index.ts +29 -0
- package/src/services/common/sendFile.ts +106 -0
- package/src/services/frontend/frontendFs.ts +101 -0
- package/src/services/frontend/index.ts +21 -0
- package/src/services/html/htmlGenerator.ts +356 -0
- package/src/services/html/index.ts +21 -0
- package/src/services/http/apiClient.ts +221 -0
- package/src/services/http/http.ts +286 -0
- package/src/services/http/index.ts +29 -0
- package/src/services/http/responsesBuilder.ts +265 -0
- package/src/services/index.ts +5 -0
- package/src/services/utils/ensureBearerToken.ts +202 -0
- package/src/services/utils/index.ts +21 -0
- package/src/types/events.ts +303 -0
- package/src/types/express.ts +21 -0
- package/src/types/http.ts +77 -0
- package/src/types/index.ts +6 -0
- package/src/types/options.ts +248 -0
- package/src/types/utils.ts +52 -0
- package/src/types/wootils.ts +4 -0
- package/src/utils/fns/index.ts +4 -0
- package/src/utils/fns/others.ts +15 -0
- package/src/utils/fns/routes.ts +64 -0
- package/src/utils/fns/statuses.ts +44 -0
- package/src/utils/fns/text.ts +8 -0
- package/src/utils/index.ts +2 -0
- package/src/utils/wrappers.ts +537 -0
- package/tsconfig.json +5 -8
- package/tsup.config.ts +10 -0
- package/src/app/index.js +0 -692
- package/src/constants/eventNames.js +0 -48
- package/src/constants/index.js +0 -7
- package/src/controllers/common/configuration.js +0 -116
- package/src/controllers/common/health.js +0 -79
- package/src/controllers/common/index.js +0 -7
- package/src/controllers/common/statics.js +0 -336
- package/src/controllers/index.js +0 -9
- package/src/controllers/utils/gateway.js +0 -1039
- package/src/controllers/utils/index.js +0 -3
- package/src/index.js +0 -30
- package/src/middlewares/common/errorHandler.js +0 -185
- package/src/middlewares/common/forceHTTPS.js +0 -80
- package/src/middlewares/common/hsts.js +0 -122
- package/src/middlewares/common/index.js +0 -7
- package/src/middlewares/html/fastHTML.js +0 -298
- package/src/middlewares/html/index.js +0 -5
- package/src/middlewares/html/showHTML.js +0 -167
- package/src/middlewares/index.js +0 -11
- package/src/middlewares/utils/index.js +0 -3
- package/src/middlewares/utils/versionValidator.js +0 -261
- package/src/services/common/appError.js +0 -136
- package/src/services/common/httpError.js +0 -60
- package/src/services/common/index.js +0 -25
- package/src/services/common/sendFile.js +0 -68
- package/src/services/frontend/frontendFs.js +0 -85
- package/src/services/frontend/index.js +0 -17
- package/src/services/html/htmlGenerator.js +0 -391
- package/src/services/html/index.js +0 -17
- package/src/services/http/apiClient.js +0 -148
- package/src/services/http/http.js +0 -256
- package/src/services/http/index.js +0 -25
- package/src/services/http/responsesBuilder.js +0 -193
- package/src/services/index.js +0 -15
- package/src/services/utils/ensureBearerToken.js +0 -147
- package/src/services/utils/index.js +0 -19
- package/src/types.js +0 -377
- package/src/utils/functions.js +0 -78
- package/src/utils/wrappers.js +0 -131
- package/types/app/index.d.ts +0 -417
- package/types/constants/eventNames.d.ts +0 -93
- package/types/constants/index.d.ts +0 -2
- package/types/controllers/common/configuration.d.ts +0 -71
- package/types/controllers/common/health.d.ts +0 -55
- package/types/controllers/common/index.d.ts +0 -4
- package/types/controllers/common/statics.d.ts +0 -271
- package/types/controllers/index.d.ts +0 -3
- package/types/controllers/utils/gateway.d.ts +0 -947
- package/types/controllers/utils/index.d.ts +0 -2
- package/types/index.d.ts +0 -15
- package/types/middlewares/common/errorHandler.d.ts +0 -143
- package/types/middlewares/common/forceHTTPS.d.ts +0 -64
- package/types/middlewares/common/hsts.d.ts +0 -111
- package/types/middlewares/common/index.d.ts +0 -4
- package/types/middlewares/html/fastHTML.d.ts +0 -238
- package/types/middlewares/html/index.d.ts +0 -3
- package/types/middlewares/html/showHTML.d.ts +0 -128
- package/types/middlewares/index.d.ts +0 -4
- package/types/middlewares/utils/index.d.ts +0 -2
- package/types/middlewares/utils/versionValidator.d.ts +0 -247
- package/types/services/common/appError.d.ts +0 -89
- package/types/services/common/httpError.d.ts +0 -37
- package/types/services/common/index.d.ts +0 -18
- package/types/services/common/sendFile.d.ts +0 -56
- package/types/services/frontend/frontendFs.d.ts +0 -72
- package/types/services/frontend/index.d.ts +0 -3
- package/types/services/html/htmlGenerator.d.ts +0 -298
- package/types/services/html/index.d.ts +0 -3
- package/types/services/http/apiClient.d.ts +0 -141
- package/types/services/http/http.d.ts +0 -159
- package/types/services/http/index.d.ts +0 -18
- package/types/services/http/responsesBuilder.d.ts +0 -140
- package/types/services/index.d.ts +0 -6
- package/types/services/utils/ensureBearerToken.d.ts +0 -137
- package/types/services/utils/index.d.ts +0 -16
- package/types/types.d.ts +0 -280
- package/types/utils/functions.d.ts +0 -55
- package/types/utils/wrappers.d.ts +0 -127
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import * as _homer0_jimple from '@homer0/jimple';
|
|
2
|
+
import { J as Jimpex } from '../../index-b2a04c78.js';
|
|
3
|
+
import { Request } from 'express';
|
|
4
|
+
import { BodyInit, Response, RequestInit } from 'node-fetch';
|
|
5
|
+
import { SimpleLogger } from '@homer0/simple-logger';
|
|
6
|
+
import '../../types/express.js';
|
|
7
|
+
import '../../types/http.js';
|
|
8
|
+
import 'https';
|
|
9
|
+
import 'http';
|
|
10
|
+
import 'spdy';
|
|
11
|
+
import '../../types/utils.js';
|
|
12
|
+
import '@homer0/path-utils';
|
|
13
|
+
import '@homer0/simple-config';
|
|
14
|
+
import '@homer0/events-hub';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The options to customize the service.
|
|
18
|
+
*
|
|
19
|
+
* @group Services/HTTP
|
|
20
|
+
*/
|
|
21
|
+
type HTTPOptions = {
|
|
22
|
+
/**
|
|
23
|
+
* Whether or not the service should log the requests and their responses.
|
|
24
|
+
*/
|
|
25
|
+
logRequests?: boolean;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* The options to construct a {@link HTTP}.
|
|
29
|
+
*
|
|
30
|
+
* @group Services/HTTP
|
|
31
|
+
*/
|
|
32
|
+
type HTTPContructorOptions = Partial<HTTPOptions> & {
|
|
33
|
+
/**
|
|
34
|
+
* A dictionary with the dependencies to inject.
|
|
35
|
+
*/
|
|
36
|
+
inject: {
|
|
37
|
+
logger: SimpleLogger;
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* The allowed formats for the body of a request.
|
|
42
|
+
*
|
|
43
|
+
* @group Services/HTTP
|
|
44
|
+
*/
|
|
45
|
+
type HTTPFetchBody = string | Record<string | number, unknown> | BodyInit;
|
|
46
|
+
/**
|
|
47
|
+
* The options for a request.
|
|
48
|
+
*
|
|
49
|
+
* @group Services/HTTP
|
|
50
|
+
*/
|
|
51
|
+
type HTTPFetchOptions = {
|
|
52
|
+
/**
|
|
53
|
+
* The HTTP method.
|
|
54
|
+
*
|
|
55
|
+
* @default 'GET'
|
|
56
|
+
*/
|
|
57
|
+
method?: string;
|
|
58
|
+
/**
|
|
59
|
+
* The headers dictionary.
|
|
60
|
+
*/
|
|
61
|
+
headers?: Record<string, string>;
|
|
62
|
+
/**
|
|
63
|
+
* The body of the request.
|
|
64
|
+
*/
|
|
65
|
+
body?: HTTPFetchBody;
|
|
66
|
+
/**
|
|
67
|
+
* A dictionary of query string parameters.
|
|
68
|
+
*/
|
|
69
|
+
qs?: Record<string, unknown>;
|
|
70
|
+
/**
|
|
71
|
+
* A request object generated by the application. This can be used to copy information
|
|
72
|
+
* like custom headers or the IP (for the X-Forwarded-For header).
|
|
73
|
+
*/
|
|
74
|
+
req?: Request;
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* The options for the method that extracts custom headers from a request.
|
|
78
|
+
*
|
|
79
|
+
* @group Services/HTTP
|
|
80
|
+
*/
|
|
81
|
+
type GetCustomHeadersFromRequestOptions = {
|
|
82
|
+
/**
|
|
83
|
+
* Since the method considers all headers that start with `x-` as custom headers,
|
|
84
|
+
* setting this to `false` is the only way to exclude `x-forwarded-` headers from the
|
|
85
|
+
* list.
|
|
86
|
+
*
|
|
87
|
+
* @default false
|
|
88
|
+
*/
|
|
89
|
+
includeXForwardedHeaders?: boolean;
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
* A set of utilities to work with HTTP requests and responses.
|
|
93
|
+
*
|
|
94
|
+
* @group Services
|
|
95
|
+
* @group Services/HTTP
|
|
96
|
+
*/
|
|
97
|
+
declare class HTTP {
|
|
98
|
+
/**
|
|
99
|
+
* The service used to log information in the terminal.
|
|
100
|
+
*/
|
|
101
|
+
protected readonly _logger: SimpleLogger;
|
|
102
|
+
/**
|
|
103
|
+
* The service customization options.
|
|
104
|
+
*/
|
|
105
|
+
protected readonly _options: HTTPOptions;
|
|
106
|
+
/**
|
|
107
|
+
* @param options The options to construct the class.
|
|
108
|
+
*/
|
|
109
|
+
constructor({ inject: { logger }, ...options }: HTTPContructorOptions);
|
|
110
|
+
/**
|
|
111
|
+
* Makes a fetch request.
|
|
112
|
+
*
|
|
113
|
+
* @param url The URL to fetch.
|
|
114
|
+
* @param options The custom options for the request.
|
|
115
|
+
*/
|
|
116
|
+
fetch(url: string, options?: HTTPFetchOptions): Promise<Response>;
|
|
117
|
+
/**
|
|
118
|
+
* Tries to get the IP address from a given request.
|
|
119
|
+
*
|
|
120
|
+
* @param req The request from which it will try to obtain the IP address.
|
|
121
|
+
*/
|
|
122
|
+
getIPFromRequest(req: Request): string | undefined;
|
|
123
|
+
/**
|
|
124
|
+
* Creates a dictionary with all the custom headers a request has. By custom header it
|
|
125
|
+
* means all the headers which name start with `x-`.
|
|
126
|
+
*
|
|
127
|
+
* @param req The request from which it will try to get the headers.
|
|
128
|
+
* @param options The options to customize the behavior with certain headers.
|
|
129
|
+
*/
|
|
130
|
+
getCustomHeadersFromRequest(req: Request, options?: GetCustomHeadersFromRequestOptions): Record<string, string>;
|
|
131
|
+
/**
|
|
132
|
+
* It takes a dictionary of headers and normalize the names so each word will start with
|
|
133
|
+
* an upper case character. This is helpful in case you added custom headers and didn't
|
|
134
|
+
* care about the casing, or when copying headers from a server request, as they all
|
|
135
|
+
* come tranformed into lower case.
|
|
136
|
+
*
|
|
137
|
+
* @param headers The dictionary of headers to normalize.
|
|
138
|
+
*/
|
|
139
|
+
normalizeHeaders(headers: Record<string, string>): Record<string, string>;
|
|
140
|
+
/**
|
|
141
|
+
* The customization options.
|
|
142
|
+
*/
|
|
143
|
+
get options(): Readonly<HTTPOptions>;
|
|
144
|
+
/**
|
|
145
|
+
* Logs a request information into the terminal.
|
|
146
|
+
*
|
|
147
|
+
* @param url The request URL.
|
|
148
|
+
* @param options The options for the request.
|
|
149
|
+
*/
|
|
150
|
+
protected _logRequest(url: string, options: RequestInit): void;
|
|
151
|
+
/**
|
|
152
|
+
* Logs a response information into the terminal.
|
|
153
|
+
*
|
|
154
|
+
* @param response The response to log.
|
|
155
|
+
*/
|
|
156
|
+
protected _logResponse(response: Response): void;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* The service provider that once registered on the container will set an instance of
|
|
160
|
+
* {@link HTTP} as the `http` service. The provider also checks the `debug.logRequests`
|
|
161
|
+
* setting on the application configuration in order to enable or not the logging of
|
|
162
|
+
* requests/responses.
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
*
|
|
166
|
+
* // Register it on the container
|
|
167
|
+
* container.register(httpProvider);
|
|
168
|
+
* // Getting access to the service instance
|
|
169
|
+
* const http = container.get<HTTP>('http');
|
|
170
|
+
*
|
|
171
|
+
* @group Providers
|
|
172
|
+
* @group Services/HTTP
|
|
173
|
+
*/
|
|
174
|
+
declare const httpProvider: _homer0_jimple.Resource<"provider", "register", _homer0_jimple.ProviderRegisterFn<Jimpex>>;
|
|
175
|
+
|
|
176
|
+
export { GetCustomHeadersFromRequestOptions, HTTP, HTTPContructorOptions, HTTPFetchBody, HTTPFetchOptions, HTTPOptions, httpProvider };
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
+
mod
|
|
28
|
+
));
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
+
var __publicField = (obj, key, value) => {
|
|
31
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
32
|
+
return value;
|
|
33
|
+
};
|
|
34
|
+
var http_exports = {};
|
|
35
|
+
__export(http_exports, {
|
|
36
|
+
HTTP: () => HTTP,
|
|
37
|
+
httpProvider: () => httpProvider
|
|
38
|
+
});
|
|
39
|
+
module.exports = __toCommonJS(http_exports);
|
|
40
|
+
var import_node_fetch = __toESM(require("node-fetch"));
|
|
41
|
+
var import_urijs = __toESM(require("urijs"));
|
|
42
|
+
var import_deep_assign = require("@homer0/deep-assign");
|
|
43
|
+
var import_utils = require("../../utils");
|
|
44
|
+
class HTTP {
|
|
45
|
+
/**
|
|
46
|
+
* @param options The options to construct the class.
|
|
47
|
+
*/
|
|
48
|
+
constructor({ inject: { logger }, ...options }) {
|
|
49
|
+
/**
|
|
50
|
+
* The service used to log information in the terminal.
|
|
51
|
+
*/
|
|
52
|
+
__publicField(this, "_logger");
|
|
53
|
+
/**
|
|
54
|
+
* The service customization options.
|
|
55
|
+
*/
|
|
56
|
+
__publicField(this, "_options");
|
|
57
|
+
this._logger = logger;
|
|
58
|
+
this._options = (0, import_deep_assign.deepAssignWithOverwrite)(
|
|
59
|
+
{
|
|
60
|
+
logRequests: false
|
|
61
|
+
},
|
|
62
|
+
options
|
|
63
|
+
);
|
|
64
|
+
this.fetch = this.fetch.bind(this);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Makes a fetch request.
|
|
68
|
+
*
|
|
69
|
+
* @param url The URL to fetch.
|
|
70
|
+
* @param options The custom options for the request.
|
|
71
|
+
*/
|
|
72
|
+
async fetch(url, options = {}) {
|
|
73
|
+
let useURL = url;
|
|
74
|
+
if (options.qs) {
|
|
75
|
+
useURL = (0, import_urijs.default)(url).query(options.qs).toString();
|
|
76
|
+
}
|
|
77
|
+
const fetchOptions = {
|
|
78
|
+
method: (options.method || "get").toUpperCase(),
|
|
79
|
+
body: options.body
|
|
80
|
+
};
|
|
81
|
+
let defaultHeaders;
|
|
82
|
+
if (options.req) {
|
|
83
|
+
defaultHeaders = this.getCustomHeadersFromRequest(options.req);
|
|
84
|
+
const ip = this.getIPFromRequest(options.req);
|
|
85
|
+
if (ip) {
|
|
86
|
+
defaultHeaders["x-forwarded-for"] = ip;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
const headers = {
|
|
90
|
+
...defaultHeaders,
|
|
91
|
+
...options.headers
|
|
92
|
+
};
|
|
93
|
+
if (Object.keys(headers).length) {
|
|
94
|
+
fetchOptions.headers = this.normalizeHeaders(headers);
|
|
95
|
+
}
|
|
96
|
+
const { logRequests } = this._options;
|
|
97
|
+
if (logRequests) {
|
|
98
|
+
this._logRequest(useURL, fetchOptions);
|
|
99
|
+
}
|
|
100
|
+
const response = await (0, import_node_fetch.default)(useURL, fetchOptions);
|
|
101
|
+
if (logRequests) {
|
|
102
|
+
this._logResponse(response);
|
|
103
|
+
}
|
|
104
|
+
return response;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Tries to get the IP address from a given request.
|
|
108
|
+
*
|
|
109
|
+
* @param req The request from which it will try to obtain the IP address.
|
|
110
|
+
*/
|
|
111
|
+
getIPFromRequest(req) {
|
|
112
|
+
const headerValue = req.headers["x-forwarded-for"];
|
|
113
|
+
if (headerValue) {
|
|
114
|
+
return String(headerValue);
|
|
115
|
+
}
|
|
116
|
+
return req?.connection?.remoteAddress || req?.socket?.remoteAddress;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Creates a dictionary with all the custom headers a request has. By custom header it
|
|
120
|
+
* means all the headers which name start with `x-`.
|
|
121
|
+
*
|
|
122
|
+
* @param req The request from which it will try to get the headers.
|
|
123
|
+
* @param options The options to customize the behavior with certain headers.
|
|
124
|
+
*/
|
|
125
|
+
getCustomHeadersFromRequest(req, options = {}) {
|
|
126
|
+
const { includeXForwardedHeaders = false } = options;
|
|
127
|
+
return Object.keys(req.headers).reduce((acc, headerName) => {
|
|
128
|
+
if (headerName.startsWith("x-") && (includeXForwardedHeaders || !headerName.startsWith("x-forwarded-"))) {
|
|
129
|
+
acc[headerName] = req.headers[headerName];
|
|
130
|
+
}
|
|
131
|
+
return acc;
|
|
132
|
+
}, {});
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* It takes a dictionary of headers and normalize the names so each word will start with
|
|
136
|
+
* an upper case character. This is helpful in case you added custom headers and didn't
|
|
137
|
+
* care about the casing, or when copying headers from a server request, as they all
|
|
138
|
+
* come tranformed into lower case.
|
|
139
|
+
*
|
|
140
|
+
* @param headers The dictionary of headers to normalize.
|
|
141
|
+
*/
|
|
142
|
+
normalizeHeaders(headers) {
|
|
143
|
+
return Object.keys(headers).reduce((acc, name) => {
|
|
144
|
+
const newName = name.split("-").map((part) => part.replace(/^(\w)/, (_, letter) => letter.toUpperCase())).join("-");
|
|
145
|
+
acc[newName] = headers[name];
|
|
146
|
+
return acc;
|
|
147
|
+
}, {});
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* The customization options.
|
|
151
|
+
*/
|
|
152
|
+
get options() {
|
|
153
|
+
return (0, import_deep_assign.deepAssignWithOverwrite)({}, this._options);
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Logs a request information into the terminal.
|
|
157
|
+
*
|
|
158
|
+
* @param url The request URL.
|
|
159
|
+
* @param options The options for the request.
|
|
160
|
+
*/
|
|
161
|
+
_logRequest(url, options) {
|
|
162
|
+
const { method, headers } = options;
|
|
163
|
+
const prefix = "REQUEST> ";
|
|
164
|
+
const lines = ["--->>", `${prefix}${method} ${url}`];
|
|
165
|
+
if (headers) {
|
|
166
|
+
Object.keys(headers).forEach((header) => {
|
|
167
|
+
const value = headers[header];
|
|
168
|
+
lines.push(`${prefix}${header}: ${value}`);
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
if (options.body) {
|
|
172
|
+
lines.push(`${prefix}body: "${options.body}"`);
|
|
173
|
+
}
|
|
174
|
+
this._logger.info(lines);
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Logs a response information into the terminal.
|
|
178
|
+
*
|
|
179
|
+
* @param response The response to log.
|
|
180
|
+
*/
|
|
181
|
+
_logResponse(response) {
|
|
182
|
+
const prefix = "RESPONSE> ";
|
|
183
|
+
const lines = [
|
|
184
|
+
"<<---",
|
|
185
|
+
`${prefix}${response.url}`,
|
|
186
|
+
`${prefix}status: ${response.status}`
|
|
187
|
+
];
|
|
188
|
+
response.headers.forEach((value, header) => {
|
|
189
|
+
lines.push(`${prefix}${header}: ${value}`);
|
|
190
|
+
});
|
|
191
|
+
this._logger.info(lines);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
const httpProvider = (0, import_utils.provider)((app) => {
|
|
195
|
+
app.set("http", () => {
|
|
196
|
+
const config = app.getConfig();
|
|
197
|
+
const logRequests = config.get("debug.logRequests") === true;
|
|
198
|
+
return new HTTP({
|
|
199
|
+
inject: {
|
|
200
|
+
logger: app.get("logger")
|
|
201
|
+
},
|
|
202
|
+
logRequests
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
});
|
|
206
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
207
|
+
0 && (module.exports = {
|
|
208
|
+
HTTP,
|
|
209
|
+
httpProvider
|
|
210
|
+
});
|
|
211
|
+
//# sourceMappingURL=http.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/services/http/http.ts"],"sourcesContent":["import fetch, { type RequestInit, type BodyInit } from 'node-fetch';\nimport urijs from 'urijs';\nimport { deepAssignWithOverwrite } from '@homer0/deep-assign';\nimport { provider } from '../../utils';\nimport { Logger, Request, HTTPResponse } from '../../types';\n/**\n * The options to customize the service.\n *\n * @group Services/HTTP\n */\nexport type HTTPOptions = {\n /**\n * Whether or not the service should log the requests and their responses.\n */\n logRequests?: boolean;\n};\n/**\n * The options to construct a {@link HTTP}.\n *\n * @group Services/HTTP\n */\nexport type HTTPContructorOptions = Partial<HTTPOptions> & {\n /**\n * A dictionary with the dependencies to inject.\n */\n inject: {\n logger: Logger;\n };\n};\n/**\n * The allowed formats for the body of a request.\n *\n * @group Services/HTTP\n */\nexport type HTTPFetchBody = string | Record<string | number, unknown> | BodyInit;\n/**\n * The options for a request.\n *\n * @group Services/HTTP\n */\nexport type HTTPFetchOptions = {\n /**\n * The HTTP method.\n *\n * @default 'GET'\n */\n method?: string;\n /**\n * The headers dictionary.\n */\n headers?: Record<string, string>;\n /**\n * The body of the request.\n */\n body?: HTTPFetchBody;\n /**\n * A dictionary of query string parameters.\n */\n qs?: Record<string, unknown>;\n /**\n * A request object generated by the application. This can be used to copy information\n * like custom headers or the IP (for the X-Forwarded-For header).\n */\n req?: Request;\n};\n/**\n * The options for the method that extracts custom headers from a request.\n *\n * @group Services/HTTP\n */\nexport type GetCustomHeadersFromRequestOptions = {\n /**\n * Since the method considers all headers that start with `x-` as custom headers,\n * setting this to `false` is the only way to exclude `x-forwarded-` headers from the\n * list.\n *\n * @default false\n */\n includeXForwardedHeaders?: boolean;\n};\n/**\n * A set of utilities to work with HTTP requests and responses.\n *\n * @group Services\n * @group Services/HTTP\n */\nexport class HTTP {\n /**\n * The service used to log information in the terminal.\n */\n protected readonly _logger: Logger;\n /**\n * The service customization options.\n */\n protected readonly _options: HTTPOptions;\n /**\n * @param options The options to construct the class.\n */\n constructor({ inject: { logger }, ...options }: HTTPContructorOptions) {\n this._logger = logger;\n this._options = deepAssignWithOverwrite(\n {\n logRequests: false,\n },\n options,\n );\n\n this.fetch = this.fetch.bind(this);\n }\n /**\n * Makes a fetch request.\n *\n * @param url The URL to fetch.\n * @param options The custom options for the request.\n */\n async fetch(url: string, options: HTTPFetchOptions = {}): Promise<HTTPResponse> {\n let useURL = url;\n if (options.qs) {\n useURL = urijs(url).query(options.qs).toString();\n }\n\n const fetchOptions: RequestInit = {\n method: (options.method || 'get').toUpperCase(),\n body: options.body as BodyInit,\n };\n\n let defaultHeaders: Record<string, string> | undefined;\n if (options.req) {\n defaultHeaders = this.getCustomHeadersFromRequest(options.req);\n const ip = this.getIPFromRequest(options.req);\n if (ip) {\n defaultHeaders['x-forwarded-for'] = ip;\n }\n }\n const headers = {\n ...defaultHeaders,\n ...options.headers,\n };\n\n if (Object.keys(headers).length) {\n fetchOptions.headers = this.normalizeHeaders(headers);\n }\n\n const { logRequests } = this._options;\n if (logRequests) {\n this._logRequest(useURL, fetchOptions);\n }\n\n const response = await fetch(useURL, fetchOptions);\n if (logRequests) {\n this._logResponse(response);\n }\n\n return response;\n }\n /**\n * Tries to get the IP address from a given request.\n *\n * @param req The request from which it will try to obtain the IP address.\n */\n getIPFromRequest(req: Request): string | undefined {\n const headerValue = req.headers['x-forwarded-for'];\n if (headerValue) {\n return String(headerValue);\n }\n\n return req?.connection?.remoteAddress || req?.socket?.remoteAddress;\n }\n /**\n * Creates a dictionary with all the custom headers a request has. By custom header it\n * means all the headers which name start with `x-`.\n *\n * @param req The request from which it will try to get the headers.\n * @param options The options to customize the behavior with certain headers.\n */\n getCustomHeadersFromRequest(\n req: Request,\n options: GetCustomHeadersFromRequestOptions = {},\n ): Record<string, string> {\n const { includeXForwardedHeaders = false } = options;\n return Object.keys(req.headers).reduce<Record<string, string>>((acc, headerName) => {\n if (\n headerName.startsWith('x-') &&\n (includeXForwardedHeaders || !headerName.startsWith('x-forwarded-'))\n ) {\n acc[headerName] = req.headers[headerName] as string;\n }\n return acc;\n }, {});\n }\n /**\n * It takes a dictionary of headers and normalize the names so each word will start with\n * an upper case character. This is helpful in case you added custom headers and didn't\n * care about the casing, or when copying headers from a server request, as they all\n * come tranformed into lower case.\n *\n * @param headers The dictionary of headers to normalize.\n */\n normalizeHeaders(headers: Record<string, string>): Record<string, string> {\n return Object.keys(headers).reduce<Record<string, string>>((acc, name) => {\n const newName = name\n .split('-')\n .map((part) => part.replace(/^(\\w)/, (_, letter) => letter.toUpperCase()))\n .join('-');\n\n acc[newName] = headers[name]!;\n return acc;\n }, {});\n }\n /**\n * The customization options.\n */\n get options(): Readonly<HTTPOptions> {\n return deepAssignWithOverwrite({}, this._options);\n }\n /**\n * Logs a request information into the terminal.\n *\n * @param url The request URL.\n * @param options The options for the request.\n */\n protected _logRequest(url: string, options: RequestInit): void {\n const { method, headers } = options;\n const prefix = 'REQUEST> ';\n const lines = ['--->>', `${prefix}${method} ${url}`];\n if (headers) {\n Object.keys(headers).forEach((header) => {\n const value = headers[header as keyof typeof headers];\n lines.push(`${prefix}${header}: ${value}`);\n });\n }\n\n if (options.body) {\n lines.push(`${prefix}body: \"${options.body}\"`);\n }\n\n this._logger.info(lines);\n }\n /**\n * Logs a response information into the terminal.\n *\n * @param response The response to log.\n */\n protected _logResponse(response: HTTPResponse) {\n const prefix = 'RESPONSE> ';\n const lines = [\n '<<---',\n `${prefix}${response.url}`,\n `${prefix}status: ${response.status}`,\n ];\n\n response.headers.forEach((value, header) => {\n lines.push(`${prefix}${header}: ${value}`);\n });\n\n this._logger.info(lines);\n }\n}\n/**\n * The service provider that once registered on the container will set an instance of\n * {@link HTTP} as the `http` service. The provider also checks the `debug.logRequests`\n * setting on the application configuration in order to enable or not the logging of\n * requests/responses.\n *\n * @example\n *\n * // Register it on the container\n * container.register(httpProvider);\n * // Getting access to the service instance\n * const http = container.get<HTTP>('http');\n *\n * @group Providers\n * @group Services/HTTP\n */\nexport const httpProvider = provider((app) => {\n app.set('http', () => {\n const config = app.getConfig();\n const logRequests = config.get<boolean | undefined>('debug.logRequests') === true;\n return new HTTP({\n inject: {\n logger: app.get('logger'),\n },\n logRequests,\n });\n });\n});\n"],"mappings":"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","names":["urijs","fetch"]}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import * as _homer0_jimple from '@homer0/jimple';
|
|
2
|
+
import { J as Jimpex } from '../../index-efeb437e.js';
|
|
3
|
+
export { ErrorResponse } from '@homer0/api-utils';
|
|
4
|
+
import { APIClientProviderOptions } from './apiClient.mjs';
|
|
5
|
+
export { APIClient, APIClientConfig, APIClientConstructorOptions, APIClientSettings, EndpointsType, apiClientProvider } from './apiClient.mjs';
|
|
6
|
+
export { GetCustomHeadersFromRequestOptions, HTTP, HTTPContructorOptions, HTTPFetchBody, HTTPFetchOptions, HTTPOptions, httpProvider } from './http.mjs';
|
|
7
|
+
export { HTMLPostMessageResponseOptions, JSONResponseOptions, ResponsesBuilder, ResponsesBuilderConstructorOptions, responsesBuilderProvider } from './responsesBuilder.mjs';
|
|
8
|
+
import '../../types/express.mjs';
|
|
9
|
+
import 'express';
|
|
10
|
+
import '../../types/http.mjs';
|
|
11
|
+
import 'https';
|
|
12
|
+
import 'http';
|
|
13
|
+
import 'spdy';
|
|
14
|
+
import 'node-fetch';
|
|
15
|
+
import '../../types/utils.mjs';
|
|
16
|
+
import '@homer0/path-utils';
|
|
17
|
+
import '@homer0/simple-logger';
|
|
18
|
+
import '@homer0/simple-config';
|
|
19
|
+
import '@homer0/events-hub';
|
|
20
|
+
import '../common/httpError.mjs';
|
|
21
|
+
import '../../utils/fns/statuses.mjs';
|
|
22
|
+
import 'statuses';
|
|
23
|
+
import '../common/appError.mjs';
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Registers all the HTTP services on the container.
|
|
27
|
+
*
|
|
28
|
+
* - {@link APIClient | apiClient}
|
|
29
|
+
* - {@link HTTP | http}
|
|
30
|
+
* - {@link ResponsesBuilder | responsesBuilder}
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
*
|
|
34
|
+
* // Register the collection on the container
|
|
35
|
+
* container.register(httpServicesProvider);
|
|
36
|
+
* // Getting access to one the services instance
|
|
37
|
+
* const apiClient = container.get<APIClient>('apiClient');
|
|
38
|
+
*
|
|
39
|
+
* @group Providers
|
|
40
|
+
*/
|
|
41
|
+
declare const httpServicesProvider: {
|
|
42
|
+
apiClientProvider: _homer0_jimple.ResourceCreator<"provider", "register", (options?: APIClientProviderOptions) => (app: Jimpex) => void, _homer0_jimple.ProviderRegisterFn<Jimpex>>;
|
|
43
|
+
httpProvider: _homer0_jimple.Resource<"provider", "register", _homer0_jimple.ProviderRegisterFn<Jimpex>>;
|
|
44
|
+
responsesBuilderProvider: _homer0_jimple.Resource<"provider", "register", _homer0_jimple.ProviderRegisterFn<Jimpex>>;
|
|
45
|
+
} & Record<string, _homer0_jimple.Resource<"provider", "register", _homer0_jimple.ProviderRegisterFn<Jimpex>>> & {
|
|
46
|
+
provider: true;
|
|
47
|
+
} & {
|
|
48
|
+
register: _homer0_jimple.ProviderRegisterFn<Jimpex>;
|
|
49
|
+
} & Record<string, unknown>;
|
|
50
|
+
|
|
51
|
+
export { APIClientProviderOptions, httpServicesProvider };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import * as _homer0_jimple from '@homer0/jimple';
|
|
2
|
+
import { J as Jimpex } from '../../index-b2a04c78.js';
|
|
3
|
+
export { ErrorResponse } from '@homer0/api-utils';
|
|
4
|
+
import { APIClientProviderOptions } from './apiClient.js';
|
|
5
|
+
export { APIClient, APIClientConfig, APIClientConstructorOptions, APIClientSettings, EndpointsType, apiClientProvider } from './apiClient.js';
|
|
6
|
+
export { GetCustomHeadersFromRequestOptions, HTTP, HTTPContructorOptions, HTTPFetchBody, HTTPFetchOptions, HTTPOptions, httpProvider } from './http.js';
|
|
7
|
+
export { HTMLPostMessageResponseOptions, JSONResponseOptions, ResponsesBuilder, ResponsesBuilderConstructorOptions, responsesBuilderProvider } from './responsesBuilder.js';
|
|
8
|
+
import '../../types/express.js';
|
|
9
|
+
import 'express';
|
|
10
|
+
import '../../types/http.js';
|
|
11
|
+
import 'https';
|
|
12
|
+
import 'http';
|
|
13
|
+
import 'spdy';
|
|
14
|
+
import 'node-fetch';
|
|
15
|
+
import '../../types/utils.js';
|
|
16
|
+
import '@homer0/path-utils';
|
|
17
|
+
import '@homer0/simple-logger';
|
|
18
|
+
import '@homer0/simple-config';
|
|
19
|
+
import '@homer0/events-hub';
|
|
20
|
+
import '../common/httpError.js';
|
|
21
|
+
import '../../utils/fns/statuses.js';
|
|
22
|
+
import 'statuses';
|
|
23
|
+
import '../common/appError.js';
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Registers all the HTTP services on the container.
|
|
27
|
+
*
|
|
28
|
+
* - {@link APIClient | apiClient}
|
|
29
|
+
* - {@link HTTP | http}
|
|
30
|
+
* - {@link ResponsesBuilder | responsesBuilder}
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
*
|
|
34
|
+
* // Register the collection on the container
|
|
35
|
+
* container.register(httpServicesProvider);
|
|
36
|
+
* // Getting access to one the services instance
|
|
37
|
+
* const apiClient = container.get<APIClient>('apiClient');
|
|
38
|
+
*
|
|
39
|
+
* @group Providers
|
|
40
|
+
*/
|
|
41
|
+
declare const httpServicesProvider: {
|
|
42
|
+
apiClientProvider: _homer0_jimple.ResourceCreator<"provider", "register", (options?: APIClientProviderOptions) => (app: Jimpex) => void, _homer0_jimple.ProviderRegisterFn<Jimpex>>;
|
|
43
|
+
httpProvider: _homer0_jimple.Resource<"provider", "register", _homer0_jimple.ProviderRegisterFn<Jimpex>>;
|
|
44
|
+
responsesBuilderProvider: _homer0_jimple.Resource<"provider", "register", _homer0_jimple.ProviderRegisterFn<Jimpex>>;
|
|
45
|
+
} & Record<string, _homer0_jimple.Resource<"provider", "register", _homer0_jimple.ProviderRegisterFn<Jimpex>>> & {
|
|
46
|
+
provider: true;
|
|
47
|
+
} & {
|
|
48
|
+
register: _homer0_jimple.ProviderRegisterFn<Jimpex>;
|
|
49
|
+
} & Record<string, unknown>;
|
|
50
|
+
|
|
51
|
+
export { APIClientProviderOptions, httpServicesProvider };
|
|
@@ -0,0 +1,44 @@
|
|
|
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 __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
var http_exports = {};
|
|
21
|
+
__export(http_exports, {
|
|
22
|
+
httpServicesProvider: () => httpServicesProvider
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(http_exports);
|
|
25
|
+
var import_utils = require("../../utils");
|
|
26
|
+
var import_apiClient = require("./apiClient");
|
|
27
|
+
var import_http = require("./http");
|
|
28
|
+
var import_responsesBuilder = require("./responsesBuilder");
|
|
29
|
+
__reExport(http_exports, require("./apiClient"), module.exports);
|
|
30
|
+
__reExport(http_exports, require("./http"), module.exports);
|
|
31
|
+
__reExport(http_exports, require("./responsesBuilder"), module.exports);
|
|
32
|
+
const httpServicesProvider = (0, import_utils.providers)({
|
|
33
|
+
apiClientProvider: import_apiClient.apiClientProvider,
|
|
34
|
+
httpProvider: import_http.httpProvider,
|
|
35
|
+
responsesBuilderProvider: import_responsesBuilder.responsesBuilderProvider
|
|
36
|
+
});
|
|
37
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
38
|
+
0 && (module.exports = {
|
|
39
|
+
httpServicesProvider,
|
|
40
|
+
...require("./apiClient"),
|
|
41
|
+
...require("./http"),
|
|
42
|
+
...require("./responsesBuilder")
|
|
43
|
+
});
|
|
44
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/services/http/index.ts"],"sourcesContent":["import { providers } from '../../utils';\nimport { apiClientProvider } from './apiClient';\nimport { httpProvider } from './http';\nimport { responsesBuilderProvider } from './responsesBuilder';\n/**\n * Registers all the HTTP services on the container.\n *\n * - {@link APIClient | apiClient}\n * - {@link HTTP | http}\n * - {@link ResponsesBuilder | responsesBuilder}\n *\n * @example\n *\n * // Register the collection on the container\n * container.register(httpServicesProvider);\n * // Getting access to one the services instance\n * const apiClient = container.get<APIClient>('apiClient');\n *\n * @group Providers\n */\nexport const httpServicesProvider = providers({\n apiClientProvider,\n httpProvider,\n responsesBuilderProvider,\n});\n\nexport * from './apiClient';\nexport * from './http';\nexport * from './responsesBuilder';\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA0B;AAC1B,uBAAkC;AAClC,kBAA6B;AAC7B,8BAAyC;AAuBzC,yBAAc,wBA1Bd;AA2BA,yBAAc,mBA3Bd;AA4BA,yBAAc,+BA5Bd;AAoBO,MAAM,2BAAuB,wBAAU;AAAA,EAC5C;AAAA,EACA;AAAA,EACA;AACF,CAAC;","names":[]}
|