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,170 @@
|
|
|
1
|
+
import * as _homer0_jimple from '@homer0/jimple';
|
|
2
|
+
import { J as Jimpex } from '../../index-efeb437e.js';
|
|
3
|
+
import { HTTPErrorClass } from '../common/httpError.mjs';
|
|
4
|
+
import { HTTP } from './http.mjs';
|
|
5
|
+
import { APIClientOptions, APIClient as APIClient$1, ErrorResponse } from '@homer0/api-utils';
|
|
6
|
+
export { ErrorResponse } from '@homer0/api-utils';
|
|
7
|
+
import '../../types/express.mjs';
|
|
8
|
+
import 'express';
|
|
9
|
+
import '../../types/http.mjs';
|
|
10
|
+
import 'https';
|
|
11
|
+
import 'http';
|
|
12
|
+
import 'spdy';
|
|
13
|
+
import 'node-fetch';
|
|
14
|
+
import '../../types/utils.mjs';
|
|
15
|
+
import '@homer0/path-utils';
|
|
16
|
+
import '@homer0/simple-logger';
|
|
17
|
+
import '@homer0/simple-config';
|
|
18
|
+
import '@homer0/events-hub';
|
|
19
|
+
import '../../utils/fns/statuses.mjs';
|
|
20
|
+
import 'statuses';
|
|
21
|
+
import '../common/appError.mjs';
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The required settings needed to create the an API client.
|
|
25
|
+
*
|
|
26
|
+
* @group Services/APIClient
|
|
27
|
+
*/
|
|
28
|
+
type APIClientConfig = Pick<APIClientOptions, 'url' | 'endpoints'>;
|
|
29
|
+
/**
|
|
30
|
+
* A dictionary of endpoints for the API client.
|
|
31
|
+
* This is declared as standalone because it needs to reference them multiple times.
|
|
32
|
+
*
|
|
33
|
+
* @group Services/APIClient
|
|
34
|
+
*/
|
|
35
|
+
type EndpointsType = APIClientOptions['endpoints'];
|
|
36
|
+
/**
|
|
37
|
+
* The format the settings needs to have in the application configuration in order to
|
|
38
|
+
* create a valid API client.
|
|
39
|
+
* The settings may include the endpoints dictionary in the `endpoints` property, or the
|
|
40
|
+
* gateway `property`, with `endpoints` always having priority if both exists.
|
|
41
|
+
* The reason for the `gateway` property to be valid, is in case the application also
|
|
42
|
+
* implements a {@link GatewayController}, using the same property for both things will
|
|
43
|
+
* help reduce the amount of duplicated definitions.
|
|
44
|
+
*
|
|
45
|
+
* @group Services/APIClient
|
|
46
|
+
*/
|
|
47
|
+
type APIClientSettings = Omit<APIClientConfig, 'endpoints'> & ({
|
|
48
|
+
endpoints: EndpointsType;
|
|
49
|
+
gateway?: EndpointsType;
|
|
50
|
+
} | {
|
|
51
|
+
endpoints?: EndpointsType;
|
|
52
|
+
gateway: EndpointsType;
|
|
53
|
+
});
|
|
54
|
+
/**
|
|
55
|
+
* The options to construct a {@link APIClient}.
|
|
56
|
+
*
|
|
57
|
+
* @group Services/APIClient
|
|
58
|
+
*/
|
|
59
|
+
type APIClientConstructorOptions = APIClientSettings & {
|
|
60
|
+
/**
|
|
61
|
+
* A dictionary with the dependencies to inject.
|
|
62
|
+
*/
|
|
63
|
+
inject: {
|
|
64
|
+
http: HTTP;
|
|
65
|
+
HTTPError: HTTPErrorClass;
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* An API client for the application to use. What makes this service special is that it
|
|
70
|
+
* formats received errors using the {@link _HTTPError} class, and as fetch client, it
|
|
71
|
+
* uses the {@link HTTP} service, allowing the application to to internally handle all the
|
|
72
|
+
* requests and responses.
|
|
73
|
+
*
|
|
74
|
+
* The only reason to use the class directly is if you want to subclass it, as you would
|
|
75
|
+
* normally just register the {@link apiClientProvider}.
|
|
76
|
+
*
|
|
77
|
+
* @group Services
|
|
78
|
+
* @group Services/APIClient
|
|
79
|
+
*/
|
|
80
|
+
declare class APIClient extends APIClient$1 {
|
|
81
|
+
/**
|
|
82
|
+
* The service that makes the requests to the API.
|
|
83
|
+
*/
|
|
84
|
+
protected readonly _http: HTTP;
|
|
85
|
+
/**
|
|
86
|
+
* The class to generate possible errors in the requests.
|
|
87
|
+
*/
|
|
88
|
+
protected readonly _HTTPError: HTTPErrorClass;
|
|
89
|
+
/**
|
|
90
|
+
* The configuration of the API it uses.
|
|
91
|
+
*/
|
|
92
|
+
protected readonly _apiConfig: APIClientConfig;
|
|
93
|
+
/**
|
|
94
|
+
* @param options The options to construct the class.
|
|
95
|
+
*/
|
|
96
|
+
constructor({ inject: { http, HTTPError }, ...rest }: APIClientConstructorOptions);
|
|
97
|
+
/**
|
|
98
|
+
* The configuration for the API.
|
|
99
|
+
*/
|
|
100
|
+
get apiConfig(): Readonly<APIClientConfig>;
|
|
101
|
+
/**
|
|
102
|
+
* Tries to obtain a message from an error caused on a failed request.
|
|
103
|
+
*
|
|
104
|
+
* @param response The response from the failed request.
|
|
105
|
+
*/
|
|
106
|
+
protected _getErrorMessageFromResponse(response: unknown): string;
|
|
107
|
+
/**
|
|
108
|
+
* Generates an {@link _HTTPError} from the response of a failed request.
|
|
109
|
+
*
|
|
110
|
+
* @param response The response from the failed request.
|
|
111
|
+
* @param status The status code of the response.
|
|
112
|
+
*/
|
|
113
|
+
protected formatError<ResponseType extends ErrorResponse>(response: ResponseType, status: number): Error;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* The options for the provider creator that registers an {@link APIClient} in the
|
|
117
|
+
* container.
|
|
118
|
+
* These options allow the application to register multiple instances for different APIs.
|
|
119
|
+
*
|
|
120
|
+
* @group Services/APIClient
|
|
121
|
+
*/
|
|
122
|
+
type APIClientProviderOptions = {
|
|
123
|
+
/**
|
|
124
|
+
* The name of the service that will be registered into the app.
|
|
125
|
+
*
|
|
126
|
+
* @default 'apiClient'
|
|
127
|
+
*/
|
|
128
|
+
serviceName?: string;
|
|
129
|
+
/**
|
|
130
|
+
* The name of the configuration setting that has the API information.
|
|
131
|
+
*
|
|
132
|
+
* @default 'api'
|
|
133
|
+
*/
|
|
134
|
+
configSetting?: string;
|
|
135
|
+
/**
|
|
136
|
+
* The class the service will instantiate. It has to extend {@link APIClient}.
|
|
137
|
+
*
|
|
138
|
+
* @default APIClient
|
|
139
|
+
*/
|
|
140
|
+
clientClass?: typeof APIClient;
|
|
141
|
+
};
|
|
142
|
+
/**
|
|
143
|
+
* The provider creator to register an instance of {@link APIClient} on the container.
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
*
|
|
147
|
+
* <caption>Basic usage</caption>
|
|
148
|
+
*
|
|
149
|
+
* // Register it on the container
|
|
150
|
+
* container.register(apiClientProvider);
|
|
151
|
+
* // Getting access to the service instance
|
|
152
|
+
* const apiClient = container.get<APIClient>('apiClient');
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
155
|
+
*
|
|
156
|
+
* <caption>With custom options</caption>
|
|
157
|
+
*
|
|
158
|
+
* container.register(
|
|
159
|
+
* apiClientProvider({
|
|
160
|
+
* serviceName: 'myApiClient',
|
|
161
|
+
* configSetting: 'myApi',
|
|
162
|
+
* }),
|
|
163
|
+
* );
|
|
164
|
+
*
|
|
165
|
+
* @group Providers
|
|
166
|
+
* @group Services/APIClient
|
|
167
|
+
*/
|
|
168
|
+
declare const apiClientProvider: _homer0_jimple.ResourceCreator<"provider", "register", (options?: APIClientProviderOptions) => (app: Jimpex) => void, _homer0_jimple.ProviderRegisterFn<Jimpex>>;
|
|
169
|
+
|
|
170
|
+
export { APIClient, APIClientConfig, APIClientConstructorOptions, APIClientProviderOptions, APIClientSettings, EndpointsType, apiClientProvider };
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import * as _homer0_jimple from '@homer0/jimple';
|
|
2
|
+
import { J as Jimpex } from '../../index-b2a04c78.js';
|
|
3
|
+
import { HTTPErrorClass } from '../common/httpError.js';
|
|
4
|
+
import { HTTP } from './http.js';
|
|
5
|
+
import { APIClientOptions, APIClient as APIClient$1, ErrorResponse } from '@homer0/api-utils';
|
|
6
|
+
export { ErrorResponse } from '@homer0/api-utils';
|
|
7
|
+
import '../../types/express.js';
|
|
8
|
+
import 'express';
|
|
9
|
+
import '../../types/http.js';
|
|
10
|
+
import 'https';
|
|
11
|
+
import 'http';
|
|
12
|
+
import 'spdy';
|
|
13
|
+
import 'node-fetch';
|
|
14
|
+
import '../../types/utils.js';
|
|
15
|
+
import '@homer0/path-utils';
|
|
16
|
+
import '@homer0/simple-logger';
|
|
17
|
+
import '@homer0/simple-config';
|
|
18
|
+
import '@homer0/events-hub';
|
|
19
|
+
import '../../utils/fns/statuses.js';
|
|
20
|
+
import 'statuses';
|
|
21
|
+
import '../common/appError.js';
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The required settings needed to create the an API client.
|
|
25
|
+
*
|
|
26
|
+
* @group Services/APIClient
|
|
27
|
+
*/
|
|
28
|
+
type APIClientConfig = Pick<APIClientOptions, 'url' | 'endpoints'>;
|
|
29
|
+
/**
|
|
30
|
+
* A dictionary of endpoints for the API client.
|
|
31
|
+
* This is declared as standalone because it needs to reference them multiple times.
|
|
32
|
+
*
|
|
33
|
+
* @group Services/APIClient
|
|
34
|
+
*/
|
|
35
|
+
type EndpointsType = APIClientOptions['endpoints'];
|
|
36
|
+
/**
|
|
37
|
+
* The format the settings needs to have in the application configuration in order to
|
|
38
|
+
* create a valid API client.
|
|
39
|
+
* The settings may include the endpoints dictionary in the `endpoints` property, or the
|
|
40
|
+
* gateway `property`, with `endpoints` always having priority if both exists.
|
|
41
|
+
* The reason for the `gateway` property to be valid, is in case the application also
|
|
42
|
+
* implements a {@link GatewayController}, using the same property for both things will
|
|
43
|
+
* help reduce the amount of duplicated definitions.
|
|
44
|
+
*
|
|
45
|
+
* @group Services/APIClient
|
|
46
|
+
*/
|
|
47
|
+
type APIClientSettings = Omit<APIClientConfig, 'endpoints'> & ({
|
|
48
|
+
endpoints: EndpointsType;
|
|
49
|
+
gateway?: EndpointsType;
|
|
50
|
+
} | {
|
|
51
|
+
endpoints?: EndpointsType;
|
|
52
|
+
gateway: EndpointsType;
|
|
53
|
+
});
|
|
54
|
+
/**
|
|
55
|
+
* The options to construct a {@link APIClient}.
|
|
56
|
+
*
|
|
57
|
+
* @group Services/APIClient
|
|
58
|
+
*/
|
|
59
|
+
type APIClientConstructorOptions = APIClientSettings & {
|
|
60
|
+
/**
|
|
61
|
+
* A dictionary with the dependencies to inject.
|
|
62
|
+
*/
|
|
63
|
+
inject: {
|
|
64
|
+
http: HTTP;
|
|
65
|
+
HTTPError: HTTPErrorClass;
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* An API client for the application to use. What makes this service special is that it
|
|
70
|
+
* formats received errors using the {@link _HTTPError} class, and as fetch client, it
|
|
71
|
+
* uses the {@link HTTP} service, allowing the application to to internally handle all the
|
|
72
|
+
* requests and responses.
|
|
73
|
+
*
|
|
74
|
+
* The only reason to use the class directly is if you want to subclass it, as you would
|
|
75
|
+
* normally just register the {@link apiClientProvider}.
|
|
76
|
+
*
|
|
77
|
+
* @group Services
|
|
78
|
+
* @group Services/APIClient
|
|
79
|
+
*/
|
|
80
|
+
declare class APIClient extends APIClient$1 {
|
|
81
|
+
/**
|
|
82
|
+
* The service that makes the requests to the API.
|
|
83
|
+
*/
|
|
84
|
+
protected readonly _http: HTTP;
|
|
85
|
+
/**
|
|
86
|
+
* The class to generate possible errors in the requests.
|
|
87
|
+
*/
|
|
88
|
+
protected readonly _HTTPError: HTTPErrorClass;
|
|
89
|
+
/**
|
|
90
|
+
* The configuration of the API it uses.
|
|
91
|
+
*/
|
|
92
|
+
protected readonly _apiConfig: APIClientConfig;
|
|
93
|
+
/**
|
|
94
|
+
* @param options The options to construct the class.
|
|
95
|
+
*/
|
|
96
|
+
constructor({ inject: { http, HTTPError }, ...rest }: APIClientConstructorOptions);
|
|
97
|
+
/**
|
|
98
|
+
* The configuration for the API.
|
|
99
|
+
*/
|
|
100
|
+
get apiConfig(): Readonly<APIClientConfig>;
|
|
101
|
+
/**
|
|
102
|
+
* Tries to obtain a message from an error caused on a failed request.
|
|
103
|
+
*
|
|
104
|
+
* @param response The response from the failed request.
|
|
105
|
+
*/
|
|
106
|
+
protected _getErrorMessageFromResponse(response: unknown): string;
|
|
107
|
+
/**
|
|
108
|
+
* Generates an {@link _HTTPError} from the response of a failed request.
|
|
109
|
+
*
|
|
110
|
+
* @param response The response from the failed request.
|
|
111
|
+
* @param status The status code of the response.
|
|
112
|
+
*/
|
|
113
|
+
protected formatError<ResponseType extends ErrorResponse>(response: ResponseType, status: number): Error;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* The options for the provider creator that registers an {@link APIClient} in the
|
|
117
|
+
* container.
|
|
118
|
+
* These options allow the application to register multiple instances for different APIs.
|
|
119
|
+
*
|
|
120
|
+
* @group Services/APIClient
|
|
121
|
+
*/
|
|
122
|
+
type APIClientProviderOptions = {
|
|
123
|
+
/**
|
|
124
|
+
* The name of the service that will be registered into the app.
|
|
125
|
+
*
|
|
126
|
+
* @default 'apiClient'
|
|
127
|
+
*/
|
|
128
|
+
serviceName?: string;
|
|
129
|
+
/**
|
|
130
|
+
* The name of the configuration setting that has the API information.
|
|
131
|
+
*
|
|
132
|
+
* @default 'api'
|
|
133
|
+
*/
|
|
134
|
+
configSetting?: string;
|
|
135
|
+
/**
|
|
136
|
+
* The class the service will instantiate. It has to extend {@link APIClient}.
|
|
137
|
+
*
|
|
138
|
+
* @default APIClient
|
|
139
|
+
*/
|
|
140
|
+
clientClass?: typeof APIClient;
|
|
141
|
+
};
|
|
142
|
+
/**
|
|
143
|
+
* The provider creator to register an instance of {@link APIClient} on the container.
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
*
|
|
147
|
+
* <caption>Basic usage</caption>
|
|
148
|
+
*
|
|
149
|
+
* // Register it on the container
|
|
150
|
+
* container.register(apiClientProvider);
|
|
151
|
+
* // Getting access to the service instance
|
|
152
|
+
* const apiClient = container.get<APIClient>('apiClient');
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
155
|
+
*
|
|
156
|
+
* <caption>With custom options</caption>
|
|
157
|
+
*
|
|
158
|
+
* container.register(
|
|
159
|
+
* apiClientProvider({
|
|
160
|
+
* serviceName: 'myApiClient',
|
|
161
|
+
* configSetting: 'myApi',
|
|
162
|
+
* }),
|
|
163
|
+
* );
|
|
164
|
+
*
|
|
165
|
+
* @group Providers
|
|
166
|
+
* @group Services/APIClient
|
|
167
|
+
*/
|
|
168
|
+
declare const apiClientProvider: _homer0_jimple.ResourceCreator<"provider", "register", (options?: APIClientProviderOptions) => (app: Jimpex) => void, _homer0_jimple.ProviderRegisterFn<Jimpex>>;
|
|
169
|
+
|
|
170
|
+
export { APIClient, APIClientConfig, APIClientConstructorOptions, APIClientProviderOptions, APIClientSettings, EndpointsType, apiClientProvider };
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
var __publicField = (obj, key, value) => {
|
|
21
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
22
|
+
return value;
|
|
23
|
+
};
|
|
24
|
+
var apiClient_exports = {};
|
|
25
|
+
__export(apiClient_exports, {
|
|
26
|
+
APIClient: () => APIClient,
|
|
27
|
+
apiClientProvider: () => apiClientProvider
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(apiClient_exports);
|
|
30
|
+
var import_api_utils = require("@homer0/api-utils");
|
|
31
|
+
var import_deep_assign = require("@homer0/deep-assign");
|
|
32
|
+
var import_utils = require("../../utils");
|
|
33
|
+
class APIClient extends import_api_utils.APIClient {
|
|
34
|
+
/**
|
|
35
|
+
* @param options The options to construct the class.
|
|
36
|
+
*/
|
|
37
|
+
constructor({ inject: { http, HTTPError }, ...rest }) {
|
|
38
|
+
const { endpoints, gateway, url } = rest;
|
|
39
|
+
const useEndpoints = endpoints || gateway;
|
|
40
|
+
const apiConfig = {
|
|
41
|
+
url,
|
|
42
|
+
endpoints: useEndpoints
|
|
43
|
+
};
|
|
44
|
+
super({
|
|
45
|
+
...apiConfig,
|
|
46
|
+
fetchClient: http.fetch
|
|
47
|
+
});
|
|
48
|
+
/**
|
|
49
|
+
* The service that makes the requests to the API.
|
|
50
|
+
*/
|
|
51
|
+
__publicField(this, "_http");
|
|
52
|
+
/**
|
|
53
|
+
* The class to generate possible errors in the requests.
|
|
54
|
+
*/
|
|
55
|
+
__publicField(this, "_HTTPError");
|
|
56
|
+
/**
|
|
57
|
+
* The configuration of the API it uses.
|
|
58
|
+
*/
|
|
59
|
+
__publicField(this, "_apiConfig");
|
|
60
|
+
this._http = http;
|
|
61
|
+
this._HTTPError = HTTPError;
|
|
62
|
+
this._apiConfig = (0, import_deep_assign.deepAssignWithOverwrite)({}, apiConfig);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* The configuration for the API.
|
|
66
|
+
*/
|
|
67
|
+
get apiConfig() {
|
|
68
|
+
return (0, import_deep_assign.deepAssignWithOverwrite)({}, this._apiConfig);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Tries to obtain a message from an error caused on a failed request.
|
|
72
|
+
*
|
|
73
|
+
* @param response The response from the failed request.
|
|
74
|
+
*/
|
|
75
|
+
_getErrorMessageFromResponse(response) {
|
|
76
|
+
const res = response;
|
|
77
|
+
if (res.error)
|
|
78
|
+
return res.error;
|
|
79
|
+
if (res.data) {
|
|
80
|
+
if (res.data.message)
|
|
81
|
+
return res.data.message;
|
|
82
|
+
if (res.data.error)
|
|
83
|
+
return res.data.error;
|
|
84
|
+
}
|
|
85
|
+
return "Unexpected error";
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Generates an {@link _HTTPError} from the response of a failed request.
|
|
89
|
+
*
|
|
90
|
+
* @param response The response from the failed request.
|
|
91
|
+
* @param status The status code of the response.
|
|
92
|
+
*/
|
|
93
|
+
formatError(response, status) {
|
|
94
|
+
return new this._HTTPError(this._getErrorMessageFromResponse(response), status);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
const apiClientProvider = (0, import_utils.providerCreator)(
|
|
98
|
+
(options = {}) => (app) => {
|
|
99
|
+
const defaultName = "apiClient";
|
|
100
|
+
const { serviceName = defaultName, clientClass: ClientClass = APIClient } = options;
|
|
101
|
+
let { configSetting } = options;
|
|
102
|
+
if (!configSetting) {
|
|
103
|
+
configSetting = serviceName === defaultName ? "api" : serviceName;
|
|
104
|
+
}
|
|
105
|
+
app.set(
|
|
106
|
+
serviceName,
|
|
107
|
+
() => new ClientClass({
|
|
108
|
+
inject: {
|
|
109
|
+
http: app.get("http"),
|
|
110
|
+
HTTPError: app.get("HTTPError")
|
|
111
|
+
},
|
|
112
|
+
...app.getConfig(configSetting)
|
|
113
|
+
})
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
);
|
|
117
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
118
|
+
0 && (module.exports = {
|
|
119
|
+
APIClient,
|
|
120
|
+
apiClientProvider
|
|
121
|
+
});
|
|
122
|
+
//# sourceMappingURL=apiClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/services/http/apiClient.ts"],"sourcesContent":["import {\n APIClient as APIClientBase,\n type ErrorResponse,\n type APIClientOptions,\n type FetchClient,\n} from '@homer0/api-utils';\nimport { deepAssignWithOverwrite } from '@homer0/deep-assign';\nimport { providerCreator } from '../../utils';\nimport type { HTTP } from './http';\nimport type { HTTPErrorClass } from '../common';\n\nexport type { ErrorResponse };\n/**\n * The required settings needed to create the an API client.\n *\n * @group Services/APIClient\n */\nexport type APIClientConfig = Pick<APIClientOptions, 'url' | 'endpoints'>;\n/**\n * A dictionary of endpoints for the API client.\n * This is declared as standalone because it needs to reference them multiple times.\n *\n * @group Services/APIClient\n */\nexport type EndpointsType = APIClientOptions['endpoints'];\n/**\n * The format the settings needs to have in the application configuration in order to\n * create a valid API client.\n * The settings may include the endpoints dictionary in the `endpoints` property, or the\n * gateway `property`, with `endpoints` always having priority if both exists.\n * The reason for the `gateway` property to be valid, is in case the application also\n * implements a {@link GatewayController}, using the same property for both things will\n * help reduce the amount of duplicated definitions.\n *\n * @group Services/APIClient\n */\nexport type APIClientSettings = Omit<APIClientConfig, 'endpoints'> &\n (\n | {\n endpoints: EndpointsType;\n gateway?: EndpointsType;\n }\n | {\n endpoints?: EndpointsType;\n gateway: EndpointsType;\n }\n );\n/**\n * The options to construct a {@link APIClient}.\n *\n * @group Services/APIClient\n */\nexport type APIClientConstructorOptions = APIClientSettings & {\n /**\n * A dictionary with the dependencies to inject.\n */\n inject: {\n http: HTTP;\n HTTPError: HTTPErrorClass;\n };\n};\n/**\n * An API client for the application to use. What makes this service special is that it\n * formats received errors using the {@link _HTTPError} class, and as fetch client, it\n * uses the {@link HTTP} service, allowing the application to to internally handle all the\n * requests and responses.\n *\n * The only reason to use the class directly is if you want to subclass it, as you would\n * normally just register the {@link apiClientProvider}.\n *\n * @group Services\n * @group Services/APIClient\n */\nexport class APIClient extends APIClientBase {\n /**\n * The service that makes the requests to the API.\n */\n protected readonly _http: HTTP;\n /**\n * The class to generate possible errors in the requests.\n */\n protected readonly _HTTPError: HTTPErrorClass;\n /**\n * The configuration of the API it uses.\n */\n protected readonly _apiConfig: APIClientConfig;\n /**\n * @param options The options to construct the class.\n */\n constructor({ inject: { http, HTTPError }, ...rest }: APIClientConstructorOptions) {\n const { endpoints, gateway, url } = rest;\n const useEndpoints = (endpoints || gateway)!;\n const apiConfig = {\n url,\n endpoints: useEndpoints,\n };\n super({\n ...apiConfig,\n fetchClient: http.fetch as unknown as FetchClient,\n });\n\n this._http = http;\n this._HTTPError = HTTPError;\n this._apiConfig = deepAssignWithOverwrite({}, apiConfig);\n }\n /**\n * The configuration for the API.\n */\n get apiConfig(): Readonly<APIClientConfig> {\n return deepAssignWithOverwrite({}, this._apiConfig);\n }\n /**\n * Tries to obtain a message from an error caused on a failed request.\n *\n * @param response The response from the failed request.\n */\n protected _getErrorMessageFromResponse(response: unknown) {\n const res = response as {\n error?: string;\n data?: {\n message?: string;\n error?: string;\n };\n };\n if (res.error) return res.error;\n if (res.data) {\n if (res.data.message) return res.data.message;\n if (res.data.error) return res.data.error;\n }\n\n return 'Unexpected error';\n }\n /**\n * Generates an {@link _HTTPError} from the response of a failed request.\n *\n * @param response The response from the failed request.\n * @param status The status code of the response.\n */\n protected override formatError<ResponseType extends ErrorResponse>(\n response: ResponseType,\n status: number,\n ): Error {\n return new this._HTTPError(this._getErrorMessageFromResponse(response), status);\n }\n}\n/**\n * The options for the provider creator that registers an {@link APIClient} in the\n * container.\n * These options allow the application to register multiple instances for different APIs.\n *\n * @group Services/APIClient\n */\nexport type APIClientProviderOptions = {\n /**\n * The name of the service that will be registered into the app.\n *\n * @default 'apiClient'\n */\n serviceName?: string;\n /**\n * The name of the configuration setting that has the API information.\n *\n * @default 'api'\n */\n configSetting?: string;\n /**\n * The class the service will instantiate. It has to extend {@link APIClient}.\n *\n * @default APIClient\n */\n clientClass?: typeof APIClient;\n};\n/**\n * The provider creator to register an instance of {@link APIClient} on the container.\n *\n * @example\n *\n * <caption>Basic usage</caption>\n *\n * // Register it on the container\n * container.register(apiClientProvider);\n * // Getting access to the service instance\n * const apiClient = container.get<APIClient>('apiClient');\n *\n * @example\n *\n * <caption>With custom options</caption>\n *\n * container.register(\n * apiClientProvider({\n * serviceName: 'myApiClient',\n * configSetting: 'myApi',\n * }),\n * );\n *\n * @group Providers\n * @group Services/APIClient\n */\nexport const apiClientProvider = providerCreator(\n (options: APIClientProviderOptions = {}) =>\n (app) => {\n const defaultName = 'apiClient';\n const { serviceName = defaultName, clientClass: ClientClass = APIClient } = options;\n let { configSetting } = options;\n if (!configSetting) {\n configSetting = serviceName === defaultName ? 'api' : serviceName;\n }\n\n app.set(\n serviceName,\n () =>\n new ClientClass({\n inject: {\n http: app.get('http'),\n HTTPError: app.get('HTTPError'),\n },\n ...app.getConfig<APIClientSettings>(configSetting!),\n }),\n );\n },\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAKO;AACP,yBAAwC;AACxC,mBAAgC;AAkEzB,MAAM,kBAAkB,iBAAAA,UAAc;AAAA;AAAA;AAAA;AAAA,EAgB3C,YAAY,EAAE,QAAQ,EAAE,MAAM,UAAU,GAAG,GAAG,KAAK,GAAgC;AACjF,UAAM,EAAE,WAAW,SAAS,IAAI,IAAI;AACpC,UAAM,eAAgB,aAAa;AACnC,UAAM,YAAY;AAAA,MAChB;AAAA,MACA,WAAW;AAAA,IACb;AACA,UAAM;AAAA,MACJ,GAAG;AAAA,MACH,aAAa,KAAK;AAAA,IACpB,CAAC;AAtBH;AAAA;AAAA;AAAA,wBAAmB;AAInB;AAAA;AAAA;AAAA,wBAAmB;AAInB;AAAA;AAAA;AAAA,wBAAmB;AAgBjB,SAAK,QAAQ;AACb,SAAK,aAAa;AAClB,SAAK,iBAAa,4CAAwB,CAAC,GAAG,SAAS;AAAA,EACzD;AAAA;AAAA;AAAA;AAAA,EAIA,IAAI,YAAuC;AACzC,eAAO,4CAAwB,CAAC,GAAG,KAAK,UAAU;AAAA,EACpD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMU,6BAA6B,UAAmB;AACxD,UAAM,MAAM;AAOZ,QAAI,IAAI;AAAO,aAAO,IAAI;AAC1B,QAAI,IAAI,MAAM;AACZ,UAAI,IAAI,KAAK;AAAS,eAAO,IAAI,KAAK;AACtC,UAAI,IAAI,KAAK;AAAO,eAAO,IAAI,KAAK;AAAA,IACtC;AAEA,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOmB,YACjB,UACA,QACO;AACP,WAAO,IAAI,KAAK,WAAW,KAAK,6BAA6B,QAAQ,GAAG,MAAM;AAAA,EAChF;AACF;AAsDO,MAAM,wBAAoB;AAAA,EAC/B,CAAC,UAAoC,CAAC,MACpC,CAAC,QAAQ;AACP,UAAM,cAAc;AACpB,UAAM,EAAE,cAAc,aAAa,aAAa,cAAc,UAAU,IAAI;AAC5E,QAAI,EAAE,cAAc,IAAI;AACxB,QAAI,CAAC,eAAe;AAClB,sBAAgB,gBAAgB,cAAc,QAAQ;AAAA,IACxD;AAEA,QAAI;AAAA,MACF;AAAA,MACA,MACE,IAAI,YAAY;AAAA,QACd,QAAQ;AAAA,UACN,MAAM,IAAI,IAAI,MAAM;AAAA,UACpB,WAAW,IAAI,IAAI,WAAW;AAAA,QAChC;AAAA,QACA,GAAG,IAAI,UAA6B,aAAc;AAAA,MACpD,CAAC;AAAA,IACL;AAAA,EACF;AACJ;","names":["APIClientBase"]}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import * as _homer0_jimple from '@homer0/jimple';
|
|
2
|
+
import { J as Jimpex } from '../../index-efeb437e.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.mjs';
|
|
7
|
+
import '../../types/http.mjs';
|
|
8
|
+
import 'https';
|
|
9
|
+
import 'http';
|
|
10
|
+
import 'spdy';
|
|
11
|
+
import '../../types/utils.mjs';
|
|
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 };
|