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,179 @@
|
|
|
1
|
+
import * as _homer0_jimple from '@homer0/jimple';
|
|
2
|
+
import { J as Jimpex } from '../../index-efeb437e.js';
|
|
3
|
+
import { Response } from 'express';
|
|
4
|
+
import { Statuses } from '../../utils/fns/statuses.mjs';
|
|
5
|
+
import { SimpleConfig } from '@homer0/simple-config';
|
|
6
|
+
import '../../types/express.mjs';
|
|
7
|
+
import '../../types/http.mjs';
|
|
8
|
+
import 'https';
|
|
9
|
+
import 'http';
|
|
10
|
+
import 'spdy';
|
|
11
|
+
import 'node-fetch';
|
|
12
|
+
import '../../types/utils.mjs';
|
|
13
|
+
import '@homer0/path-utils';
|
|
14
|
+
import '@homer0/simple-logger';
|
|
15
|
+
import '@homer0/events-hub';
|
|
16
|
+
import 'statuses';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The options to construct a {@link ResponsesBuilder}.
|
|
20
|
+
*
|
|
21
|
+
* @group Services/ResponsesBuilder
|
|
22
|
+
*/
|
|
23
|
+
type ResponsesBuilderConstructorOptions = {
|
|
24
|
+
/**
|
|
25
|
+
* A dictionary with the dependencies to inject.
|
|
26
|
+
*/
|
|
27
|
+
inject: {
|
|
28
|
+
config: SimpleConfig;
|
|
29
|
+
statuses: Statuses;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* The options to build a response for a post message.
|
|
34
|
+
*
|
|
35
|
+
* @group Services/ResponsesBuilder
|
|
36
|
+
*/
|
|
37
|
+
type HTMLPostMessageResponseOptions = {
|
|
38
|
+
/**
|
|
39
|
+
* The response object generated by the application.
|
|
40
|
+
*/
|
|
41
|
+
res: Response;
|
|
42
|
+
/**
|
|
43
|
+
* The title for the HTML.
|
|
44
|
+
*/
|
|
45
|
+
title: string;
|
|
46
|
+
/**
|
|
47
|
+
* The contents of the post message.
|
|
48
|
+
*/
|
|
49
|
+
message: string;
|
|
50
|
+
/**
|
|
51
|
+
* The status code for the response.
|
|
52
|
+
*
|
|
53
|
+
* @default 200
|
|
54
|
+
*/
|
|
55
|
+
status?: number | string;
|
|
56
|
+
/**
|
|
57
|
+
* From which object will the `postMessage` method called from.
|
|
58
|
+
*
|
|
59
|
+
* @default 'window.opener'
|
|
60
|
+
*/
|
|
61
|
+
target?: string;
|
|
62
|
+
/**
|
|
63
|
+
* Whether or not to call `window.close` after sending the message.
|
|
64
|
+
*
|
|
65
|
+
* @default true
|
|
66
|
+
*/
|
|
67
|
+
close?: boolean;
|
|
68
|
+
/**
|
|
69
|
+
* In case `close` is set to `true`, this option is to specify how many milliseconds
|
|
70
|
+
* should be waited before closing the window.
|
|
71
|
+
*
|
|
72
|
+
* @default 700
|
|
73
|
+
*/
|
|
74
|
+
closeDelay?: number;
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* The options to build a reponse for JSON.
|
|
78
|
+
*
|
|
79
|
+
* @group Services/ResponsesBuilder
|
|
80
|
+
*/
|
|
81
|
+
type JSONResponseOptions = {
|
|
82
|
+
/**
|
|
83
|
+
* The response object generated by the application.
|
|
84
|
+
*/
|
|
85
|
+
res: Response;
|
|
86
|
+
/**
|
|
87
|
+
* The actual data for the response. It will be added in a `data` property.
|
|
88
|
+
*/
|
|
89
|
+
data: unknown;
|
|
90
|
+
/**
|
|
91
|
+
* The status code for the response.
|
|
92
|
+
*
|
|
93
|
+
* @default 200
|
|
94
|
+
*/
|
|
95
|
+
status?: number | string;
|
|
96
|
+
/**
|
|
97
|
+
* Extra information to include inside the `metadata` object.
|
|
98
|
+
*/
|
|
99
|
+
metadata?: object;
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* A utility service to build responses.
|
|
103
|
+
*
|
|
104
|
+
* @group Services
|
|
105
|
+
* @group Services/ResponsesBuilder
|
|
106
|
+
*/
|
|
107
|
+
declare class ResponsesBuilder {
|
|
108
|
+
/**
|
|
109
|
+
* The application configuration, to get the `version` and the `postMessagesPrefix`.
|
|
110
|
+
*/
|
|
111
|
+
protected readonly _config: SimpleConfig;
|
|
112
|
+
/**
|
|
113
|
+
* The uility service to get HTTP status codes.
|
|
114
|
+
*/
|
|
115
|
+
protected readonly _statuses: Statuses;
|
|
116
|
+
/**
|
|
117
|
+
* @param options The options to construct the service.
|
|
118
|
+
*/
|
|
119
|
+
constructor({ inject: { config, statuses } }: ResponsesBuilderConstructorOptions);
|
|
120
|
+
/**
|
|
121
|
+
* Generates and send an HTML response that emits a post message.
|
|
122
|
+
* The post message will be prefixed with the value of the configuration setting
|
|
123
|
+
* `postMessagesPrefix`.
|
|
124
|
+
*
|
|
125
|
+
* @param options The options to customize how the HTML is generated.
|
|
126
|
+
*/
|
|
127
|
+
htmlPostMessage(options: HTMLPostMessageResponseOptions): void;
|
|
128
|
+
/**
|
|
129
|
+
* Generates and sends a JSON response.
|
|
130
|
+
*
|
|
131
|
+
* @param options The options to customize how the JSON is generated.
|
|
132
|
+
* @example
|
|
133
|
+
*
|
|
134
|
+
* <caption>The generated looks like this.</caption>
|
|
135
|
+
*
|
|
136
|
+
* {
|
|
137
|
+
* metadata: {
|
|
138
|
+
* version: 'dev',
|
|
139
|
+
* status: 200,
|
|
140
|
+
* },
|
|
141
|
+
* data: { foo: 'bar' },
|
|
142
|
+
* }
|
|
143
|
+
*
|
|
144
|
+
*/
|
|
145
|
+
json(options: JSONResponseOptions): void;
|
|
146
|
+
/**
|
|
147
|
+
* Generates a basic HTML template for the service to use when generating a post message
|
|
148
|
+
* response.
|
|
149
|
+
*
|
|
150
|
+
* @param title The HTML `<title />` attribute.
|
|
151
|
+
* @param code Javascript code to be wrapped on a `<script />` tag.
|
|
152
|
+
*/
|
|
153
|
+
protected _htmlTemplate(title: string, code: string): string;
|
|
154
|
+
/**
|
|
155
|
+
* Utility method used to make sure a recevied status is a valid status code. If the
|
|
156
|
+
* status is a string, the method will try to find the code from the `statuses` package.
|
|
157
|
+
*
|
|
158
|
+
* @param status The status to normalize.
|
|
159
|
+
* @returns If `status` is a string, but there's no valid code, it will return 200.
|
|
160
|
+
*/
|
|
161
|
+
protected _normalizeStatus(status: number | string): number;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* The service provider that once registered on the container will set an instance of
|
|
165
|
+
* {@link ResponsesBuilder} as the `responsesBuilder` service.
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
*
|
|
169
|
+
* // Register it on the container
|
|
170
|
+
* container.register(responsesBuilderProvider);
|
|
171
|
+
* // Getting access to the service instance
|
|
172
|
+
* const responsesBuilder = container.get<ResponsesBuilder>('responsesBuilder');
|
|
173
|
+
*
|
|
174
|
+
* @group Providers
|
|
175
|
+
* @group Services/ResponsesBuilder
|
|
176
|
+
*/
|
|
177
|
+
declare const responsesBuilderProvider: _homer0_jimple.Resource<"provider", "register", _homer0_jimple.ProviderRegisterFn<Jimpex>>;
|
|
178
|
+
|
|
179
|
+
export { HTMLPostMessageResponseOptions, JSONResponseOptions, ResponsesBuilder, ResponsesBuilderConstructorOptions, responsesBuilderProvider };
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import * as _homer0_jimple from '@homer0/jimple';
|
|
2
|
+
import { J as Jimpex } from '../../index-b2a04c78.js';
|
|
3
|
+
import { Response } from 'express';
|
|
4
|
+
import { Statuses } from '../../utils/fns/statuses.js';
|
|
5
|
+
import { SimpleConfig } from '@homer0/simple-config';
|
|
6
|
+
import '../../types/express.js';
|
|
7
|
+
import '../../types/http.js';
|
|
8
|
+
import 'https';
|
|
9
|
+
import 'http';
|
|
10
|
+
import 'spdy';
|
|
11
|
+
import 'node-fetch';
|
|
12
|
+
import '../../types/utils.js';
|
|
13
|
+
import '@homer0/path-utils';
|
|
14
|
+
import '@homer0/simple-logger';
|
|
15
|
+
import '@homer0/events-hub';
|
|
16
|
+
import 'statuses';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The options to construct a {@link ResponsesBuilder}.
|
|
20
|
+
*
|
|
21
|
+
* @group Services/ResponsesBuilder
|
|
22
|
+
*/
|
|
23
|
+
type ResponsesBuilderConstructorOptions = {
|
|
24
|
+
/**
|
|
25
|
+
* A dictionary with the dependencies to inject.
|
|
26
|
+
*/
|
|
27
|
+
inject: {
|
|
28
|
+
config: SimpleConfig;
|
|
29
|
+
statuses: Statuses;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* The options to build a response for a post message.
|
|
34
|
+
*
|
|
35
|
+
* @group Services/ResponsesBuilder
|
|
36
|
+
*/
|
|
37
|
+
type HTMLPostMessageResponseOptions = {
|
|
38
|
+
/**
|
|
39
|
+
* The response object generated by the application.
|
|
40
|
+
*/
|
|
41
|
+
res: Response;
|
|
42
|
+
/**
|
|
43
|
+
* The title for the HTML.
|
|
44
|
+
*/
|
|
45
|
+
title: string;
|
|
46
|
+
/**
|
|
47
|
+
* The contents of the post message.
|
|
48
|
+
*/
|
|
49
|
+
message: string;
|
|
50
|
+
/**
|
|
51
|
+
* The status code for the response.
|
|
52
|
+
*
|
|
53
|
+
* @default 200
|
|
54
|
+
*/
|
|
55
|
+
status?: number | string;
|
|
56
|
+
/**
|
|
57
|
+
* From which object will the `postMessage` method called from.
|
|
58
|
+
*
|
|
59
|
+
* @default 'window.opener'
|
|
60
|
+
*/
|
|
61
|
+
target?: string;
|
|
62
|
+
/**
|
|
63
|
+
* Whether or not to call `window.close` after sending the message.
|
|
64
|
+
*
|
|
65
|
+
* @default true
|
|
66
|
+
*/
|
|
67
|
+
close?: boolean;
|
|
68
|
+
/**
|
|
69
|
+
* In case `close` is set to `true`, this option is to specify how many milliseconds
|
|
70
|
+
* should be waited before closing the window.
|
|
71
|
+
*
|
|
72
|
+
* @default 700
|
|
73
|
+
*/
|
|
74
|
+
closeDelay?: number;
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* The options to build a reponse for JSON.
|
|
78
|
+
*
|
|
79
|
+
* @group Services/ResponsesBuilder
|
|
80
|
+
*/
|
|
81
|
+
type JSONResponseOptions = {
|
|
82
|
+
/**
|
|
83
|
+
* The response object generated by the application.
|
|
84
|
+
*/
|
|
85
|
+
res: Response;
|
|
86
|
+
/**
|
|
87
|
+
* The actual data for the response. It will be added in a `data` property.
|
|
88
|
+
*/
|
|
89
|
+
data: unknown;
|
|
90
|
+
/**
|
|
91
|
+
* The status code for the response.
|
|
92
|
+
*
|
|
93
|
+
* @default 200
|
|
94
|
+
*/
|
|
95
|
+
status?: number | string;
|
|
96
|
+
/**
|
|
97
|
+
* Extra information to include inside the `metadata` object.
|
|
98
|
+
*/
|
|
99
|
+
metadata?: object;
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* A utility service to build responses.
|
|
103
|
+
*
|
|
104
|
+
* @group Services
|
|
105
|
+
* @group Services/ResponsesBuilder
|
|
106
|
+
*/
|
|
107
|
+
declare class ResponsesBuilder {
|
|
108
|
+
/**
|
|
109
|
+
* The application configuration, to get the `version` and the `postMessagesPrefix`.
|
|
110
|
+
*/
|
|
111
|
+
protected readonly _config: SimpleConfig;
|
|
112
|
+
/**
|
|
113
|
+
* The uility service to get HTTP status codes.
|
|
114
|
+
*/
|
|
115
|
+
protected readonly _statuses: Statuses;
|
|
116
|
+
/**
|
|
117
|
+
* @param options The options to construct the service.
|
|
118
|
+
*/
|
|
119
|
+
constructor({ inject: { config, statuses } }: ResponsesBuilderConstructorOptions);
|
|
120
|
+
/**
|
|
121
|
+
* Generates and send an HTML response that emits a post message.
|
|
122
|
+
* The post message will be prefixed with the value of the configuration setting
|
|
123
|
+
* `postMessagesPrefix`.
|
|
124
|
+
*
|
|
125
|
+
* @param options The options to customize how the HTML is generated.
|
|
126
|
+
*/
|
|
127
|
+
htmlPostMessage(options: HTMLPostMessageResponseOptions): void;
|
|
128
|
+
/**
|
|
129
|
+
* Generates and sends a JSON response.
|
|
130
|
+
*
|
|
131
|
+
* @param options The options to customize how the JSON is generated.
|
|
132
|
+
* @example
|
|
133
|
+
*
|
|
134
|
+
* <caption>The generated looks like this.</caption>
|
|
135
|
+
*
|
|
136
|
+
* {
|
|
137
|
+
* metadata: {
|
|
138
|
+
* version: 'dev',
|
|
139
|
+
* status: 200,
|
|
140
|
+
* },
|
|
141
|
+
* data: { foo: 'bar' },
|
|
142
|
+
* }
|
|
143
|
+
*
|
|
144
|
+
*/
|
|
145
|
+
json(options: JSONResponseOptions): void;
|
|
146
|
+
/**
|
|
147
|
+
* Generates a basic HTML template for the service to use when generating a post message
|
|
148
|
+
* response.
|
|
149
|
+
*
|
|
150
|
+
* @param title The HTML `<title />` attribute.
|
|
151
|
+
* @param code Javascript code to be wrapped on a `<script />` tag.
|
|
152
|
+
*/
|
|
153
|
+
protected _htmlTemplate(title: string, code: string): string;
|
|
154
|
+
/**
|
|
155
|
+
* Utility method used to make sure a recevied status is a valid status code. If the
|
|
156
|
+
* status is a string, the method will try to find the code from the `statuses` package.
|
|
157
|
+
*
|
|
158
|
+
* @param status The status to normalize.
|
|
159
|
+
* @returns If `status` is a string, but there's no valid code, it will return 200.
|
|
160
|
+
*/
|
|
161
|
+
protected _normalizeStatus(status: number | string): number;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* The service provider that once registered on the container will set an instance of
|
|
165
|
+
* {@link ResponsesBuilder} as the `responsesBuilder` service.
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
*
|
|
169
|
+
* // Register it on the container
|
|
170
|
+
* container.register(responsesBuilderProvider);
|
|
171
|
+
* // Getting access to the service instance
|
|
172
|
+
* const responsesBuilder = container.get<ResponsesBuilder>('responsesBuilder');
|
|
173
|
+
*
|
|
174
|
+
* @group Providers
|
|
175
|
+
* @group Services/ResponsesBuilder
|
|
176
|
+
*/
|
|
177
|
+
declare const responsesBuilderProvider: _homer0_jimple.Resource<"provider", "register", _homer0_jimple.ProviderRegisterFn<Jimpex>>;
|
|
178
|
+
|
|
179
|
+
export { HTMLPostMessageResponseOptions, JSONResponseOptions, ResponsesBuilder, ResponsesBuilderConstructorOptions, responsesBuilderProvider };
|
|
@@ -0,0 +1,179 @@
|
|
|
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 responsesBuilder_exports = {};
|
|
25
|
+
__export(responsesBuilder_exports, {
|
|
26
|
+
ResponsesBuilder: () => ResponsesBuilder,
|
|
27
|
+
responsesBuilderProvider: () => responsesBuilderProvider
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(responsesBuilder_exports);
|
|
30
|
+
var import_utils = require("../../utils");
|
|
31
|
+
const DEFAULT_CLOSE_DELAY_FOR_POST_MESSAGE = 700;
|
|
32
|
+
class ResponsesBuilder {
|
|
33
|
+
/**
|
|
34
|
+
* @param options The options to construct the service.
|
|
35
|
+
*/
|
|
36
|
+
constructor({ inject: { config, statuses } }) {
|
|
37
|
+
/**
|
|
38
|
+
* The application configuration, to get the `version` and the `postMessagesPrefix`.
|
|
39
|
+
*/
|
|
40
|
+
__publicField(this, "_config");
|
|
41
|
+
/**
|
|
42
|
+
* The uility service to get HTTP status codes.
|
|
43
|
+
*/
|
|
44
|
+
__publicField(this, "_statuses");
|
|
45
|
+
this._config = config;
|
|
46
|
+
this._statuses = statuses;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Generates and send an HTML response that emits a post message.
|
|
50
|
+
* The post message will be prefixed with the value of the configuration setting
|
|
51
|
+
* `postMessagesPrefix`.
|
|
52
|
+
*
|
|
53
|
+
* @param options The options to customize how the HTML is generated.
|
|
54
|
+
*/
|
|
55
|
+
htmlPostMessage(options) {
|
|
56
|
+
const {
|
|
57
|
+
res,
|
|
58
|
+
title,
|
|
59
|
+
message,
|
|
60
|
+
status,
|
|
61
|
+
target = "window.opener",
|
|
62
|
+
close = true,
|
|
63
|
+
closeDelay = DEFAULT_CLOSE_DELAY_FOR_POST_MESSAGE
|
|
64
|
+
} = options;
|
|
65
|
+
const prefix = this._config.get("postMessagesPrefix") ?? "";
|
|
66
|
+
const closeCode = close ? `setTimeout(function() { window.close(); }, ${closeDelay});` : "";
|
|
67
|
+
const html = this._htmlTemplate(
|
|
68
|
+
title,
|
|
69
|
+
`
|
|
70
|
+
(function() {
|
|
71
|
+
if (${target}) {
|
|
72
|
+
${target}.postMessage('${prefix}${message}', '*');
|
|
73
|
+
${closeCode}
|
|
74
|
+
}
|
|
75
|
+
})();
|
|
76
|
+
`
|
|
77
|
+
);
|
|
78
|
+
const useStatus = typeof status === "undefined" ? this._statuses("ok") : this._normalizeStatus(status);
|
|
79
|
+
res.setHeader("Content-Type", "text/html");
|
|
80
|
+
res.setHeader("Cache-Control", "no-cache, max-age=0, must-revalidate, no-store");
|
|
81
|
+
res.status(useStatus);
|
|
82
|
+
res.write(html);
|
|
83
|
+
res.end();
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Generates and sends a JSON response.
|
|
87
|
+
*
|
|
88
|
+
* @param options The options to customize how the JSON is generated.
|
|
89
|
+
* @example
|
|
90
|
+
*
|
|
91
|
+
* <caption>The generated looks like this.</caption>
|
|
92
|
+
*
|
|
93
|
+
* {
|
|
94
|
+
* metadata: {
|
|
95
|
+
* version: 'dev',
|
|
96
|
+
* status: 200,
|
|
97
|
+
* },
|
|
98
|
+
* data: { foo: 'bar' },
|
|
99
|
+
* }
|
|
100
|
+
*
|
|
101
|
+
*/
|
|
102
|
+
json(options) {
|
|
103
|
+
const { res, data, status, metadata = {} } = options;
|
|
104
|
+
const useStatus = typeof status === "undefined" ? this._statuses("ok") : this._normalizeStatus(status);
|
|
105
|
+
res.status(useStatus);
|
|
106
|
+
res.json({
|
|
107
|
+
metadata: {
|
|
108
|
+
version: this._config.get("version"),
|
|
109
|
+
status: useStatus,
|
|
110
|
+
...metadata
|
|
111
|
+
},
|
|
112
|
+
data
|
|
113
|
+
});
|
|
114
|
+
res.end();
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Generates a basic HTML template for the service to use when generating a post message
|
|
118
|
+
* response.
|
|
119
|
+
*
|
|
120
|
+
* @param title The HTML `<title />` attribute.
|
|
121
|
+
* @param code Javascript code to be wrapped on a `<script />` tag.
|
|
122
|
+
*/
|
|
123
|
+
_htmlTemplate(title, code) {
|
|
124
|
+
return `
|
|
125
|
+
<!DOCTYPE html>
|
|
126
|
+
<html>
|
|
127
|
+
<head>
|
|
128
|
+
<meta charset="utf-8" />
|
|
129
|
+
<meta http-equiv="x-ua-compatible" content="ie=edge" />
|
|
130
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
131
|
+
<title>${title}</title>
|
|
132
|
+
</head>
|
|
133
|
+
<body>
|
|
134
|
+
<script type="text/javascript">
|
|
135
|
+
${code}
|
|
136
|
+
</script>
|
|
137
|
+
</body>
|
|
138
|
+
</html>
|
|
139
|
+
`;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Utility method used to make sure a recevied status is a valid status code. If the
|
|
143
|
+
* status is a string, the method will try to find the code from the `statuses` package.
|
|
144
|
+
*
|
|
145
|
+
* @param status The status to normalize.
|
|
146
|
+
* @returns If `status` is a string, but there's no valid code, it will return 200.
|
|
147
|
+
*/
|
|
148
|
+
_normalizeStatus(status) {
|
|
149
|
+
let useStatus;
|
|
150
|
+
try {
|
|
151
|
+
if (typeof status === "string") {
|
|
152
|
+
useStatus = this._statuses(status);
|
|
153
|
+
} else {
|
|
154
|
+
this._statuses(status);
|
|
155
|
+
useStatus = status;
|
|
156
|
+
}
|
|
157
|
+
} catch (_) {
|
|
158
|
+
useStatus = this._statuses("ok");
|
|
159
|
+
}
|
|
160
|
+
return useStatus;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
const responsesBuilderProvider = (0, import_utils.provider)((app) => {
|
|
164
|
+
app.set(
|
|
165
|
+
"responsesBuilder",
|
|
166
|
+
() => new ResponsesBuilder({
|
|
167
|
+
inject: {
|
|
168
|
+
config: app.getConfig(),
|
|
169
|
+
statuses: app.get("statuses")
|
|
170
|
+
}
|
|
171
|
+
})
|
|
172
|
+
);
|
|
173
|
+
});
|
|
174
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
175
|
+
0 && (module.exports = {
|
|
176
|
+
ResponsesBuilder,
|
|
177
|
+
responsesBuilderProvider
|
|
178
|
+
});
|
|
179
|
+
//# sourceMappingURL=responsesBuilder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/services/http/responsesBuilder.ts"],"sourcesContent":["import type { Config, Response } from '../../types';\nimport { provider, type Statuses } from '../../utils';\n/**\n * The options to construct a {@link ResponsesBuilder}.\n *\n * @group Services/ResponsesBuilder\n */\nexport type ResponsesBuilderConstructorOptions = {\n /**\n * A dictionary with the dependencies to inject.\n */\n inject: {\n config: Config;\n statuses: Statuses;\n };\n};\n/**\n * The options to build a response for a post message.\n *\n * @group Services/ResponsesBuilder\n */\nexport type HTMLPostMessageResponseOptions = {\n /**\n * The response object generated by the application.\n */\n res: Response;\n /**\n * The title for the HTML.\n */\n title: string;\n /**\n * The contents of the post message.\n */\n message: string;\n /**\n * The status code for the response.\n *\n * @default 200\n */\n status?: number | string;\n /**\n * From which object will the `postMessage` method called from.\n *\n * @default 'window.opener'\n */\n target?: string;\n /**\n * Whether or not to call `window.close` after sending the message.\n *\n * @default true\n */\n close?: boolean;\n /**\n * In case `close` is set to `true`, this option is to specify how many milliseconds\n * should be waited before closing the window.\n *\n * @default 700\n */\n closeDelay?: number;\n};\n/**\n * The options to build a reponse for JSON.\n *\n * @group Services/ResponsesBuilder\n */\nexport type JSONResponseOptions = {\n /**\n * The response object generated by the application.\n */\n res: Response;\n /**\n * The actual data for the response. It will be added in a `data` property.\n */\n data: unknown;\n /**\n * The status code for the response.\n *\n * @default 200\n */\n status?: number | string;\n /**\n * Extra information to include inside the `metadata` object.\n */\n metadata?: object;\n};\n/**\n * The default time to wait before closing a window, in case it's enabled.\n */\nconst DEFAULT_CLOSE_DELAY_FOR_POST_MESSAGE = 700;\n/**\n * A utility service to build responses.\n *\n * @group Services\n * @group Services/ResponsesBuilder\n */\nexport class ResponsesBuilder {\n /**\n * The application configuration, to get the `version` and the `postMessagesPrefix`.\n */\n protected readonly _config: Config;\n /**\n * The uility service to get HTTP status codes.\n */\n protected readonly _statuses: Statuses;\n /**\n * @param options The options to construct the service.\n */\n constructor({ inject: { config, statuses } }: ResponsesBuilderConstructorOptions) {\n this._config = config;\n this._statuses = statuses;\n }\n /**\n * Generates and send an HTML response that emits a post message.\n * The post message will be prefixed with the value of the configuration setting\n * `postMessagesPrefix`.\n *\n * @param options The options to customize how the HTML is generated.\n */\n htmlPostMessage(options: HTMLPostMessageResponseOptions): void {\n const {\n res,\n title,\n message,\n status,\n target = 'window.opener',\n close = true,\n closeDelay = DEFAULT_CLOSE_DELAY_FOR_POST_MESSAGE,\n } = options;\n const prefix = this._config.get<string | undefined>('postMessagesPrefix') ?? '';\n const closeCode = close\n ? `setTimeout(function() { window.close(); }, ${closeDelay});`\n : '';\n\n const html = this._htmlTemplate(\n title,\n `\n (function() {\n if (${target}) {\n ${target}.postMessage('${prefix}${message}', '*');\n ${closeCode}\n }\n })();\n `,\n );\n\n const useStatus =\n typeof status === 'undefined'\n ? (this._statuses('ok') as number)\n : this._normalizeStatus(status);\n\n res.setHeader('Content-Type', 'text/html');\n res.setHeader('Cache-Control', 'no-cache, max-age=0, must-revalidate, no-store');\n res.status(useStatus);\n res.write(html);\n res.end();\n }\n /**\n * Generates and sends a JSON response.\n *\n * @param options The options to customize how the JSON is generated.\n * @example\n *\n * <caption>The generated looks like this.</caption>\n *\n * {\n * metadata: {\n * version: 'dev',\n * status: 200,\n * },\n * data: { foo: 'bar' },\n * }\n *\n */\n json(options: JSONResponseOptions): void {\n const { res, data, status, metadata = {} } = options;\n const useStatus =\n typeof status === 'undefined'\n ? (this._statuses('ok') as number)\n : this._normalizeStatus(status);\n\n res.status(useStatus);\n res.json({\n metadata: {\n version: this._config.get<string>('version'),\n status: useStatus,\n ...metadata,\n },\n data,\n });\n res.end();\n }\n /**\n * Generates a basic HTML template for the service to use when generating a post message\n * response.\n *\n * @param title The HTML `<title />` attribute.\n * @param code Javascript code to be wrapped on a `<script />` tag.\n */\n protected _htmlTemplate(title: string, code: string): string {\n return `\n <!DOCTYPE html>\n <html>\n <head>\n <meta charset=\"utf-8\" />\n <meta http-equiv=\"x-ua-compatible\" content=\"ie=edge\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n <title>${title}</title>\n </head>\n <body>\n <script type=\"text/javascript\">\n ${code}\n </script>\n </body>\n </html>\n `;\n }\n /**\n * Utility method used to make sure a recevied status is a valid status code. If the\n * status is a string, the method will try to find the code from the `statuses` package.\n *\n * @param status The status to normalize.\n * @returns If `status` is a string, but there's no valid code, it will return 200.\n */\n protected _normalizeStatus(status: number | string): number {\n let useStatus: number;\n try {\n if (typeof status === 'string') {\n useStatus = this._statuses(status) as number;\n } else {\n this._statuses(status);\n useStatus = status;\n }\n } catch (_) {\n useStatus = this._statuses('ok') as number;\n }\n\n return useStatus;\n }\n}\n/**\n * The service provider that once registered on the container will set an instance of\n * {@link ResponsesBuilder} as the `responsesBuilder` service.\n *\n * @example\n *\n * // Register it on the container\n * container.register(responsesBuilderProvider);\n * // Getting access to the service instance\n * const responsesBuilder = container.get<ResponsesBuilder>('responsesBuilder');\n *\n * @group Providers\n * @group Services/ResponsesBuilder\n */\nexport const responsesBuilderProvider = provider((app) => {\n app.set(\n 'responsesBuilder',\n () =>\n new ResponsesBuilder({\n inject: {\n config: app.getConfig(),\n statuses: app.get('statuses'),\n },\n }),\n );\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAAwC;AAuFxC,MAAM,uCAAuC;AAOtC,MAAM,iBAAiB;AAAA;AAAA;AAAA;AAAA,EAY5B,YAAY,EAAE,QAAQ,EAAE,QAAQ,SAAS,EAAE,GAAuC;AARlF;AAAA;AAAA;AAAA,wBAAmB;AAInB;AAAA;AAAA;AAAA,wBAAmB;AAKjB,SAAK,UAAU;AACf,SAAK,YAAY;AAAA,EACnB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,gBAAgB,SAA+C;AAC7D,UAAM;AAAA,MACJ;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,SAAS;AAAA,MACT,QAAQ;AAAA,MACR,aAAa;AAAA,IACf,IAAI;AACJ,UAAM,SAAS,KAAK,QAAQ,IAAwB,oBAAoB,KAAK;AAC7E,UAAM,YAAY,QACd,8CAA8C,UAAU,OACxD;AAEJ,UAAM,OAAO,KAAK;AAAA,MAChB;AAAA,MACA;AAAA;AAAA,cAEQ,MAAM;AAAA,YACR,MAAM,iBAAiB,MAAM,GAAG,OAAO;AAAA,YACvC,SAAS;AAAA;AAAA;AAAA;AAAA,IAIjB;AAEA,UAAM,YACJ,OAAO,WAAW,cACb,KAAK,UAAU,IAAI,IACpB,KAAK,iBAAiB,MAAM;AAElC,QAAI,UAAU,gBAAgB,WAAW;AACzC,QAAI,UAAU,iBAAiB,gDAAgD;AAC/E,QAAI,OAAO,SAAS;AACpB,QAAI,MAAM,IAAI;AACd,QAAI,IAAI;AAAA,EACV;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAkBA,KAAK,SAAoC;AACvC,UAAM,EAAE,KAAK,MAAM,QAAQ,WAAW,CAAC,EAAE,IAAI;AAC7C,UAAM,YACJ,OAAO,WAAW,cACb,KAAK,UAAU,IAAI,IACpB,KAAK,iBAAiB,MAAM;AAElC,QAAI,OAAO,SAAS;AACpB,QAAI,KAAK;AAAA,MACP,UAAU;AAAA,QACR,SAAS,KAAK,QAAQ,IAAY,SAAS;AAAA,QAC3C,QAAQ;AAAA,QACR,GAAG;AAAA,MACL;AAAA,MACA;AAAA,IACF,CAAC;AACD,QAAI,IAAI;AAAA,EACV;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQU,cAAc,OAAe,MAAsB;AAC3D,WAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAOQ,KAAK;AAAA;AAAA;AAAA;AAAA,YAIZ,IAAI;AAAA;AAAA;AAAA;AAAA;AAAA,EAKd;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQU,iBAAiB,QAAiC;AAC1D,QAAI;AACJ,QAAI;AACF,UAAI,OAAO,WAAW,UAAU;AAC9B,oBAAY,KAAK,UAAU,MAAM;AAAA,MACnC,OAAO;AACL,aAAK,UAAU,MAAM;AACrB,oBAAY;AAAA,MACd;AAAA,IACF,SAAS,GAAG;AACV,kBAAY,KAAK,UAAU,IAAI;AAAA,IACjC;AAEA,WAAO;AAAA,EACT;AACF;AAeO,MAAM,+BAA2B,uBAAS,CAAC,QAAQ;AACxD,MAAI;AAAA,IACF;AAAA,IACA,MACE,IAAI,iBAAiB;AAAA,MACnB,QAAQ;AAAA,QACN,QAAQ,IAAI,UAAU;AAAA,QACtB,UAAU,IAAI,IAAI,UAAU;AAAA,MAC9B;AAAA,IACF,CAAC;AAAA,EACL;AACF,CAAC;","names":[]}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export { commonServicesProvider } from './common/index.mjs';
|
|
2
|
+
export { frontendServicesProvider } from './frontend/index.mjs';
|
|
3
|
+
export { htmlServicesProvider } from './html/index.mjs';
|
|
4
|
+
export { httpServicesProvider } from './http/index.mjs';
|
|
5
|
+
export { utilsServicesProvider } from './utils/index.mjs';
|
|
6
|
+
export { AppError, AppErrorClass, AppErrorContext, CreateAppErrorFn, appErrorProvider, createAppError } from './common/appError.mjs';
|
|
7
|
+
export { CreateHTTPErrorFn, HTTPError, HTTPErrorClass, createHTTPError, httpErrorProvider } from './common/httpError.mjs';
|
|
8
|
+
export { SendFile, SendFileGeneratorOptions, SendFileOptions, sendFile, sendFileProvider } from './common/sendFile.mjs';
|
|
9
|
+
export { FrontendFs, FrontendFsOptions, frontendFsProvider } from './frontend/frontendFs.mjs';
|
|
10
|
+
export { HTMLGenerator, HTMLGeneratorConstructorOptions, HTMLGeneratorOptions, HTMLGeneratorProviderOptions, HTMLGeneratorValuesService, htmlGeneratorProvider } from './html/htmlGenerator.mjs';
|
|
11
|
+
export { ErrorResponse } from '@homer0/api-utils';
|
|
12
|
+
export { APIClient, APIClientConfig, APIClientConstructorOptions, APIClientProviderOptions, APIClientSettings, EndpointsType, apiClientProvider } from './http/apiClient.mjs';
|
|
13
|
+
export { GetCustomHeadersFromRequestOptions, HTTP, HTTPContructorOptions, HTTPFetchBody, HTTPFetchOptions, HTTPOptions, httpProvider } from './http/http.mjs';
|
|
14
|
+
export { HTMLPostMessageResponseOptions, JSONResponseOptions, ResponsesBuilder, ResponsesBuilderConstructorOptions, responsesBuilderProvider } from './http/responsesBuilder.mjs';
|
|
15
|
+
export { EnsureBearerConstructorOptions, EnsureBearerToken, EnsureBearerTokenErrorOptions, EnsureBearerTokenOptions, EnsureBearerTokenProviderOptions, ensureBearerTokenProvider } from './utils/ensureBearerToken.mjs';
|
|
16
|
+
import '@homer0/jimple';
|
|
17
|
+
import '../index-efeb437e.js';
|
|
18
|
+
import '../types/express.mjs';
|
|
19
|
+
import 'express';
|
|
20
|
+
import '../types/http.mjs';
|
|
21
|
+
import 'https';
|
|
22
|
+
import 'http';
|
|
23
|
+
import 'spdy';
|
|
24
|
+
import 'node-fetch';
|
|
25
|
+
import '../types/utils.mjs';
|
|
26
|
+
import '@homer0/path-utils';
|
|
27
|
+
import '@homer0/simple-logger';
|
|
28
|
+
import '@homer0/simple-config';
|
|
29
|
+
import '@homer0/events-hub';
|
|
30
|
+
import '../utils/fns/statuses.mjs';
|
|
31
|
+
import 'statuses';
|
|
32
|
+
import 'fs/promises';
|
|
33
|
+
import '@homer0/deferred';
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export { commonServicesProvider } from './common/index.js';
|
|
2
|
+
export { frontendServicesProvider } from './frontend/index.js';
|
|
3
|
+
export { htmlServicesProvider } from './html/index.js';
|
|
4
|
+
export { httpServicesProvider } from './http/index.js';
|
|
5
|
+
export { utilsServicesProvider } from './utils/index.js';
|
|
6
|
+
export { AppError, AppErrorClass, AppErrorContext, CreateAppErrorFn, appErrorProvider, createAppError } from './common/appError.js';
|
|
7
|
+
export { CreateHTTPErrorFn, HTTPError, HTTPErrorClass, createHTTPError, httpErrorProvider } from './common/httpError.js';
|
|
8
|
+
export { SendFile, SendFileGeneratorOptions, SendFileOptions, sendFile, sendFileProvider } from './common/sendFile.js';
|
|
9
|
+
export { FrontendFs, FrontendFsOptions, frontendFsProvider } from './frontend/frontendFs.js';
|
|
10
|
+
export { HTMLGenerator, HTMLGeneratorConstructorOptions, HTMLGeneratorOptions, HTMLGeneratorProviderOptions, HTMLGeneratorValuesService, htmlGeneratorProvider } from './html/htmlGenerator.js';
|
|
11
|
+
export { ErrorResponse } from '@homer0/api-utils';
|
|
12
|
+
export { APIClient, APIClientConfig, APIClientConstructorOptions, APIClientProviderOptions, APIClientSettings, EndpointsType, apiClientProvider } from './http/apiClient.js';
|
|
13
|
+
export { GetCustomHeadersFromRequestOptions, HTTP, HTTPContructorOptions, HTTPFetchBody, HTTPFetchOptions, HTTPOptions, httpProvider } from './http/http.js';
|
|
14
|
+
export { HTMLPostMessageResponseOptions, JSONResponseOptions, ResponsesBuilder, ResponsesBuilderConstructorOptions, responsesBuilderProvider } from './http/responsesBuilder.js';
|
|
15
|
+
export { EnsureBearerConstructorOptions, EnsureBearerToken, EnsureBearerTokenErrorOptions, EnsureBearerTokenOptions, EnsureBearerTokenProviderOptions, ensureBearerTokenProvider } from './utils/ensureBearerToken.js';
|
|
16
|
+
import '@homer0/jimple';
|
|
17
|
+
import '../index-b2a04c78.js';
|
|
18
|
+
import '../types/express.js';
|
|
19
|
+
import 'express';
|
|
20
|
+
import '../types/http.js';
|
|
21
|
+
import 'https';
|
|
22
|
+
import 'http';
|
|
23
|
+
import 'spdy';
|
|
24
|
+
import 'node-fetch';
|
|
25
|
+
import '../types/utils.js';
|
|
26
|
+
import '@homer0/path-utils';
|
|
27
|
+
import '@homer0/simple-logger';
|
|
28
|
+
import '@homer0/simple-config';
|
|
29
|
+
import '@homer0/events-hub';
|
|
30
|
+
import '../utils/fns/statuses.js';
|
|
31
|
+
import 'statuses';
|
|
32
|
+
import 'fs/promises';
|
|
33
|
+
import '@homer0/deferred';
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
+
var services_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(services_exports);
|
|
18
|
+
__reExport(services_exports, require("./common"), module.exports);
|
|
19
|
+
__reExport(services_exports, require("./frontend"), module.exports);
|
|
20
|
+
__reExport(services_exports, require("./html"), module.exports);
|
|
21
|
+
__reExport(services_exports, require("./http"), module.exports);
|
|
22
|
+
__reExport(services_exports, require("./utils"), module.exports);
|
|
23
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
24
|
+
0 && (module.exports = {
|
|
25
|
+
...require("./common"),
|
|
26
|
+
...require("./frontend"),
|
|
27
|
+
...require("./html"),
|
|
28
|
+
...require("./http"),
|
|
29
|
+
...require("./utils")
|
|
30
|
+
});
|
|
31
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/services/index.ts"],"sourcesContent":["export * from './common';\nexport * from './frontend';\nexport * from './html';\nexport * from './http';\nexport * from './utils';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,6BAAc,qBAAd;AACA,6BAAc,uBADd;AAEA,6BAAc,mBAFd;AAGA,6BAAc,mBAHd;AAIA,6BAAc,oBAJd;","names":[]}
|