jimpex 7.0.1 → 8.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +87 -0
- package/LICENSE +1 -1
- package/README.md +446 -434
- package/dist/app/index.d.ts +13 -0
- package/dist/app/index.js +19 -0
- package/dist/app/index.js.map +1 -0
- package/dist/app/jimpex.d.ts +13 -0
- package/dist/app/jimpex.js +440 -0
- package/dist/app/jimpex.js.map +1 -0
- package/dist/controllers/common/config.d.ts +78 -0
- package/dist/controllers/common/config.js +89 -0
- package/dist/controllers/common/config.js.map +1 -0
- package/dist/controllers/common/health.d.ts +82 -0
- package/dist/controllers/common/health.js +97 -0
- package/dist/controllers/common/health.js.map +1 -0
- package/dist/controllers/common/index.d.ts +21 -0
- package/dist/controllers/common/index.js +21 -0
- package/dist/controllers/common/index.js.map +1 -0
- package/dist/controllers/common/statics.d.ts +215 -0
- package/dist/controllers/common/statics.js +202 -0
- package/dist/controllers/common/statics.js.map +1 -0
- package/dist/controllers/index.d.ts +24 -0
- package/dist/controllers/index.js +20 -0
- package/dist/controllers/index.js.map +1 -0
- package/dist/controllers/utils/gateway.d.ts +724 -0
- package/dist/controllers/utils/gateway.js +425 -0
- package/dist/controllers/utils/gateway.js.map +1 -0
- package/dist/controllers/utils/index.d.ts +16 -0
- package/dist/controllers/utils/index.js +19 -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 +415 -0
- package/dist/esm/app/jimpex.js.map +1 -0
- package/dist/esm/chunk-T2T6Q22Z.js +11 -0
- package/dist/esm/chunk-T2T6Q22Z.js.map +1 -0
- package/dist/esm/controllers/common/config.js +62 -0
- package/dist/esm/controllers/common/config.js.map +1 -0
- package/dist/esm/controllers/common/health.js +70 -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 +173 -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 +404 -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 +92 -0
- package/dist/esm/middlewares/common/errorHandler.js.map +1 -0
- package/dist/esm/middlewares/common/forceHTTPS.js +41 -0
- package/dist/esm/middlewares/common/forceHTTPS.js.map +1 -0
- package/dist/esm/middlewares/common/hsts.js +53 -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 +104 -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 +68 -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 +101 -0
- package/dist/esm/middlewares/utils/versionValidator.js.map +1 -0
- package/dist/esm/services/common/appError.js +52 -0
- package/dist/esm/services/common/appError.js.map +1 -0
- package/dist/esm/services/common/httpError.js +19 -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 +38 -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 +144 -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 +71 -0
- package/dist/esm/services/http/apiClient.js.map +1 -0
- package/dist/esm/services/http/http.js +125 -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 +105 -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 +78 -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.d.ts +46 -0
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -0
- package/dist/jimpex-7eaee271.d.ts +1278 -0
- package/dist/middlewares/common/errorHandler.d.ts +131 -0
- package/dist/middlewares/common/errorHandler.js +119 -0
- package/dist/middlewares/common/errorHandler.js.map +1 -0
- package/dist/middlewares/common/forceHTTPS.d.ts +68 -0
- package/dist/middlewares/common/forceHTTPS.js +68 -0
- package/dist/middlewares/common/forceHTTPS.js.map +1 -0
- package/dist/middlewares/common/hsts.d.ts +109 -0
- package/dist/middlewares/common/hsts.js +80 -0
- package/dist/middlewares/common/hsts.js.map +1 -0
- package/dist/middlewares/common/index.d.ts +21 -0
- package/dist/middlewares/common/index.js +21 -0
- package/dist/middlewares/common/index.js.map +1 -0
- package/dist/middlewares/html/fastHTML.d.ts +180 -0
- package/dist/middlewares/html/fastHTML.js +131 -0
- package/dist/middlewares/html/fastHTML.js.map +1 -0
- package/dist/middlewares/html/index.d.ts +21 -0
- package/dist/middlewares/html/index.js +20 -0
- package/dist/middlewares/html/index.js.map +1 -0
- package/dist/middlewares/html/showHTML.d.ts +127 -0
- package/dist/middlewares/html/showHTML.js +95 -0
- package/dist/middlewares/html/showHTML.js.map +1 -0
- package/dist/middlewares/index.d.ts +30 -0
- package/dist/middlewares/index.js +21 -0
- package/dist/middlewares/index.js.map +1 -0
- package/dist/middlewares/utils/index.d.ts +19 -0
- package/dist/middlewares/utils/index.js +19 -0
- package/dist/middlewares/utils/index.js.map +1 -0
- package/dist/middlewares/utils/versionValidator.d.ts +214 -0
- package/dist/middlewares/utils/versionValidator.js +128 -0
- package/dist/middlewares/utils/versionValidator.js.map +1 -0
- package/dist/services/common/appError.d.ts +138 -0
- package/dist/services/common/appError.js +80 -0
- package/dist/services/common/appError.js.map +1 -0
- package/dist/services/common/httpError.d.ts +79 -0
- package/dist/services/common/httpError.js +44 -0
- package/dist/services/common/httpError.js.map +1 -0
- package/dist/services/common/index.d.ts +47 -0
- package/dist/services/common/index.js +41 -0
- package/dist/services/common/index.js.map +1 -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.ts +96 -0
- package/dist/services/frontend/frontendFs.js +71 -0
- package/dist/services/frontend/frontendFs.js.map +1 -0
- package/dist/services/frontend/index.d.ts +40 -0
- package/dist/services/frontend/index.js +35 -0
- package/dist/services/frontend/index.js.map +1 -0
- package/dist/services/html/htmlGenerator.d.ts +237 -0
- package/dist/services/html/htmlGenerator.js +171 -0
- package/dist/services/html/htmlGenerator.js.map +1 -0
- package/dist/services/html/index.d.ts +43 -0
- package/dist/services/html/index.js +35 -0
- package/dist/services/html/index.js.map +1 -0
- package/dist/services/http/apiClient.d.ts +169 -0
- package/dist/services/http/apiClient.js +96 -0
- package/dist/services/http/apiClient.js.map +1 -0
- package/dist/services/http/http.d.ts +175 -0
- package/dist/services/http/http.js +158 -0
- package/dist/services/http/http.js.map +1 -0
- package/dist/services/http/index.d.ts +50 -0
- package/dist/services/http/index.js +41 -0
- package/dist/services/http/index.js.map +1 -0
- package/dist/services/http/responsesBuilder.d.ts +178 -0
- package/dist/services/http/responsesBuilder.js +132 -0
- package/dist/services/http/responsesBuilder.js.map +1 -0
- package/dist/services/index.d.ts +33 -0
- package/dist/services/index.js +23 -0
- package/dist/services/index.js.map +1 -0
- package/dist/services/utils/ensureBearerToken.d.ts +157 -0
- package/dist/services/utils/ensureBearerToken.js +105 -0
- package/dist/services/utils/ensureBearerToken.js.map +1 -0
- package/dist/services/utils/index.d.ts +43 -0
- package/dist/services/utils/index.js +35 -0
- package/dist/services/utils/index.js.map +1 -0
- package/dist/types/events.d.ts +13 -0
- package/dist/types/events.js +17 -0
- package/dist/types/events.js.map +1 -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.ts +79 -0
- package/dist/types/http.js +17 -0
- package/dist/types/http.js.map +1 -0
- package/dist/types/index.d.ts +14 -0
- package/dist/types/index.js +24 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/options.d.ts +13 -0
- package/dist/types/options.js +17 -0
- package/dist/types/options.js.map +1 -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.ts +4 -0
- package/dist/types/wootils.js +17 -0
- package/dist/types/wootils.js.map +1 -0
- package/dist/utils/fns/index.d.ts +5 -0
- package/dist/utils/fns/index.js +22 -0
- package/dist/utils/fns/index.js.map +1 -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.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.ts +45 -0
- package/dist/utils/fns/statuses.js +35 -0
- package/dist/utils/fns/statuses.js.map +1 -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.ts +18 -0
- package/dist/utils/index.js +20 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/wrappers.d.ts +13 -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 +59 -38
- 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
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
export type ExpressMiddleware = import('../../types').ExpressMiddleware;
|
|
2
|
-
export type ExpressResponse = import('../../types').ExpressResponse;
|
|
3
|
-
export type ExpressNext = import('../../types').ExpressNext;
|
|
4
|
-
export type SendFile = import('../../services/common/sendFile').SendFile;
|
|
5
|
-
export type HTMLGenerator = import('../../services/html/htmlGenerator').HTMLGenerator;
|
|
6
|
-
/**
|
|
7
|
-
* <O>
|
|
8
|
-
*/
|
|
9
|
-
export type MiddlewareCreator<O> = import('../../types').MiddlewareCreator<O>;
|
|
10
|
-
/**
|
|
11
|
-
* A set options to customize the middleware behavior.
|
|
12
|
-
*/
|
|
13
|
-
export type ShowHTMLMiddlewareOptions = {
|
|
14
|
-
/**
|
|
15
|
-
* The name of the file the middleware will serve.
|
|
16
|
-
* Default `'index.html'`.
|
|
17
|
-
*/
|
|
18
|
-
file: string;
|
|
19
|
-
/**
|
|
20
|
-
* The name of a {@link HTMLGenerator } service for the
|
|
21
|
-
* middleware to use. If the service is available, the
|
|
22
|
-
* value of `file` will be overwritten for the file
|
|
23
|
-
* generated by the service. Default `'htmlGenerator'`.
|
|
24
|
-
*/
|
|
25
|
-
htmlGenerator: string;
|
|
26
|
-
};
|
|
27
|
-
/**
|
|
28
|
-
* @typedef {import('../../types').ExpressMiddleware} ExpressMiddleware
|
|
29
|
-
* @typedef {import('../../types').ExpressResponse} ExpressResponse
|
|
30
|
-
* @typedef {import('../../types').ExpressNext} ExpressNext
|
|
31
|
-
* @typedef {import('../../services/common/sendFile').SendFile} SendFile
|
|
32
|
-
* @typedef {import('../../services/html/htmlGenerator').HTMLGenerator} HTMLGenerator
|
|
33
|
-
*/
|
|
34
|
-
/**
|
|
35
|
-
* @typedef {import('../../types').MiddlewareCreator<O>} MiddlewareCreator<O>
|
|
36
|
-
* @template O
|
|
37
|
-
*/
|
|
38
|
-
/**
|
|
39
|
-
* A set options to customize the middleware behavior.
|
|
40
|
-
*
|
|
41
|
-
* @typedef {Object} ShowHTMLMiddlewareOptions
|
|
42
|
-
* @property {string} file The name of the file the middleware will serve.
|
|
43
|
-
* Default `'index.html'`.
|
|
44
|
-
* @property {string} htmlGenerator The name of a {@link HTMLGenerator} service for the
|
|
45
|
-
* middleware to use. If the service is available, the
|
|
46
|
-
* value of `file` will be overwritten for the file
|
|
47
|
-
* generated by the service. Default `'htmlGenerator'`.
|
|
48
|
-
* @parent module:middlewares
|
|
49
|
-
*/
|
|
50
|
-
/**
|
|
51
|
-
* A very simple middleware service to send an HTML on a server response. The special
|
|
52
|
-
* _'feature'_ of this service is that it can be hooked up to an `HTMLGenerator` service
|
|
53
|
-
* and it will automatically server the file generated by it.
|
|
54
|
-
*
|
|
55
|
-
* @parent module:middlewares
|
|
56
|
-
*/
|
|
57
|
-
export class ShowHTML {
|
|
58
|
-
/**
|
|
59
|
-
* @param {SendFile} sendFile Necessary to server the HTML file.
|
|
60
|
-
* @param {string} [file='index.html'] The name of the file it will serve. If
|
|
61
|
-
* `htmlGenerator` is specified, this will
|
|
62
|
-
* be overwritten with the name of the file
|
|
63
|
-
* generated by that service.
|
|
64
|
-
* @param {HTMLGenerator} [htmlGenerator=null] If used, the file to server will be the
|
|
65
|
-
* one generated by that service.
|
|
66
|
-
*/
|
|
67
|
-
constructor(sendFile: SendFile, file?: string, htmlGenerator?: HTMLGenerator);
|
|
68
|
-
/**
|
|
69
|
-
* A local reference for the `sendFile` service.
|
|
70
|
-
*
|
|
71
|
-
* @type {SendFile}
|
|
72
|
-
* @access protected
|
|
73
|
-
* @ignore
|
|
74
|
-
*/
|
|
75
|
-
_sendFile: SendFile;
|
|
76
|
-
/**
|
|
77
|
-
* The name of the file to serve.
|
|
78
|
-
*
|
|
79
|
-
* @type {string}
|
|
80
|
-
* @access protected
|
|
81
|
-
* @ignore
|
|
82
|
-
*/
|
|
83
|
-
_file: string;
|
|
84
|
-
/**
|
|
85
|
-
* If specified, a reference for a service that generates HTML files.
|
|
86
|
-
*
|
|
87
|
-
* @type {HTMLGenerator}
|
|
88
|
-
* @access protected
|
|
89
|
-
* @ignore
|
|
90
|
-
*/
|
|
91
|
-
_htmlGenerator: HTMLGenerator;
|
|
92
|
-
/**
|
|
93
|
-
* Whether or not the file is ready to be served.
|
|
94
|
-
*
|
|
95
|
-
* @type {boolean}
|
|
96
|
-
* @access protected
|
|
97
|
-
* @ignore
|
|
98
|
-
*/
|
|
99
|
-
_ready: boolean;
|
|
100
|
-
/**
|
|
101
|
-
* Returns the Express middleware that serves the HTML file.
|
|
102
|
-
*
|
|
103
|
-
* @returns {ExpressMiddleware}
|
|
104
|
-
*/
|
|
105
|
-
middleware(): ExpressMiddleware;
|
|
106
|
-
/**
|
|
107
|
-
* The name of the file to serve.
|
|
108
|
-
*
|
|
109
|
-
* @type {string}
|
|
110
|
-
*/
|
|
111
|
-
get file(): string;
|
|
112
|
-
/**
|
|
113
|
-
* Serves the file on the response.
|
|
114
|
-
*
|
|
115
|
-
* @param {ExpressResponse} res The server response.
|
|
116
|
-
* @param {ExpressNext} next The functino to call the next middleware.
|
|
117
|
-
* @access protected
|
|
118
|
-
* @ignore
|
|
119
|
-
*/
|
|
120
|
-
_sendHTML(res: ExpressResponse, next: ExpressNext): void;
|
|
121
|
-
}
|
|
122
|
-
/**
|
|
123
|
-
* A middleware for showing an `index.html` file.
|
|
124
|
-
*
|
|
125
|
-
* @type {MiddlewareCreator<ShowHTMLMiddlewareOptions>}
|
|
126
|
-
* @parent module:middlewares
|
|
127
|
-
*/
|
|
128
|
-
export const showHTML: MiddlewareCreator<ShowHTMLMiddlewareOptions>;
|
|
@@ -1,247 +0,0 @@
|
|
|
1
|
-
export type ExpressMiddleware = import('../../types').ExpressMiddleware;
|
|
2
|
-
export type ExpressRequest = import('../../types').ExpressRequest;
|
|
3
|
-
export type ResponsesBuilder = import('../../services/http/responsesBuilder').ResponsesBuilder;
|
|
4
|
-
/**
|
|
5
|
-
* <O>
|
|
6
|
-
*/
|
|
7
|
-
export type MiddlewareCreator<O> = import('../../types').MiddlewareCreator<O>;
|
|
8
|
-
/**
|
|
9
|
-
* The options for how the middleware should behave if the requested version is `latest`.
|
|
10
|
-
*/
|
|
11
|
-
export type VersionValidatorLatestOptions = {
|
|
12
|
-
/**
|
|
13
|
-
* Whether or not the middleware should validate the _"latest
|
|
14
|
-
* version"_.
|
|
15
|
-
* Default `true`.
|
|
16
|
-
*/
|
|
17
|
-
allow: boolean;
|
|
18
|
-
/**
|
|
19
|
-
* The name of the _"latest version"_. Basically,
|
|
20
|
-
* `req.params.version`
|
|
21
|
-
* must match with this property in order to be consider
|
|
22
|
-
* "latest".
|
|
23
|
-
* Default `'latest'`.
|
|
24
|
-
*/
|
|
25
|
-
name: string;
|
|
26
|
-
};
|
|
27
|
-
/**
|
|
28
|
-
* The options for how to detect if the request comes from a popup and how to compose the
|
|
29
|
-
* post message the middleware will use to respond.
|
|
30
|
-
*/
|
|
31
|
-
export type VersionValidatorPopupOptions = {
|
|
32
|
-
/**
|
|
33
|
-
* The name of the query string variable the middleware will
|
|
34
|
-
* check in order to indentify whether the request comes from
|
|
35
|
-
* a popup or not.
|
|
36
|
-
* The variable must have `'true'` as its value. Default
|
|
37
|
-
* `'popup'`.
|
|
38
|
-
*/
|
|
39
|
-
variable: string;
|
|
40
|
-
/**
|
|
41
|
-
* The title of the page that will be generated to respond in
|
|
42
|
-
* case the versions don't match. Default `'Conflict'`.
|
|
43
|
-
*/
|
|
44
|
-
title: string;
|
|
45
|
-
/**
|
|
46
|
-
* The contents of the post message the generated page will
|
|
47
|
-
* send if the versions don't match. Default
|
|
48
|
-
* `'vesion:conflict'`.
|
|
49
|
-
*/
|
|
50
|
-
message: string;
|
|
51
|
-
};
|
|
52
|
-
/**
|
|
53
|
-
* The options used to customize a {@link VersionValidator } instance.
|
|
54
|
-
*/
|
|
55
|
-
export type VersionValidatorOptions = {
|
|
56
|
-
/**
|
|
57
|
-
* The error message to show when the
|
|
58
|
-
* version is invalid.
|
|
59
|
-
*/
|
|
60
|
-
error: string;
|
|
61
|
-
/**
|
|
62
|
-
* The options for how the middleware
|
|
63
|
-
* should behave if the requested
|
|
64
|
-
* version is `latest`.
|
|
65
|
-
*/
|
|
66
|
-
latest: VersionValidatorLatestOptions;
|
|
67
|
-
/**
|
|
68
|
-
* The options for how to detect if the
|
|
69
|
-
* request comes from a popup and how
|
|
70
|
-
* to compose the post message the
|
|
71
|
-
* middleware will use to respond.
|
|
72
|
-
*/
|
|
73
|
-
popup: VersionValidatorPopupOptions;
|
|
74
|
-
/**
|
|
75
|
-
* The version used to validate the
|
|
76
|
-
* requests.
|
|
77
|
-
* On the {@link VersionValidator }constructor, if specified via
|
|
78
|
-
* parameter,
|
|
79
|
-
* the class will take care of
|
|
80
|
-
* automatically add it to the options.
|
|
81
|
-
*/
|
|
82
|
-
version: string | number;
|
|
83
|
-
};
|
|
84
|
-
/**
|
|
85
|
-
* @typedef {import('../../types').ExpressMiddleware} ExpressMiddleware
|
|
86
|
-
* @typedef {import('../../types').ExpressRequest} ExpressRequest
|
|
87
|
-
* @typedef {import('../../services/http/responsesBuilder').ResponsesBuilder} ResponsesBuilder
|
|
88
|
-
* @prettierignore
|
|
89
|
-
*/
|
|
90
|
-
/**
|
|
91
|
-
* @typedef {import('../../types').MiddlewareCreator<O>} MiddlewareCreator<O>
|
|
92
|
-
* @template O
|
|
93
|
-
*/
|
|
94
|
-
/**
|
|
95
|
-
* The options for how the middleware should behave if the requested version is `latest`.
|
|
96
|
-
*
|
|
97
|
-
* @typedef {Object} VersionValidatorLatestOptions
|
|
98
|
-
* @property {boolean} allow Whether or not the middleware should validate the _"latest
|
|
99
|
-
* version"_.
|
|
100
|
-
* Default `true`.
|
|
101
|
-
* @property {string} name The name of the _"latest version"_. Basically,
|
|
102
|
-
* `req.params.version`
|
|
103
|
-
* must match with this property in order to be consider
|
|
104
|
-
* "latest".
|
|
105
|
-
* Default `'latest'`.
|
|
106
|
-
* @parent module:middlewares
|
|
107
|
-
*/
|
|
108
|
-
/**
|
|
109
|
-
* The options for how to detect if the request comes from a popup and how to compose the
|
|
110
|
-
* post message the middleware will use to respond.
|
|
111
|
-
*
|
|
112
|
-
* @typedef {Object} VersionValidatorPopupOptions
|
|
113
|
-
* @property {string} variable The name of the query string variable the middleware will
|
|
114
|
-
* check in order to indentify whether the request comes from
|
|
115
|
-
* a popup or not.
|
|
116
|
-
* The variable must have `'true'` as its value. Default
|
|
117
|
-
* `'popup'`.
|
|
118
|
-
* @property {string} title The title of the page that will be generated to respond in
|
|
119
|
-
* case the versions don't match. Default `'Conflict'`.
|
|
120
|
-
* @property {string} message The contents of the post message the generated page will
|
|
121
|
-
* send if the versions don't match. Default
|
|
122
|
-
* `'vesion:conflict'`.
|
|
123
|
-
* @parent module:middlewares
|
|
124
|
-
*/
|
|
125
|
-
/**
|
|
126
|
-
* The options used to customize a {@link VersionValidator} instance.
|
|
127
|
-
*
|
|
128
|
-
* @typedef {Object} VersionValidatorOptions
|
|
129
|
-
* @property {string} error The error message to show when the
|
|
130
|
-
* version is invalid.
|
|
131
|
-
* @property {VersionValidatorLatestOptions} latest The options for how the middleware
|
|
132
|
-
* should behave if the requested
|
|
133
|
-
* version is `latest`.
|
|
134
|
-
* @property {VersionValidatorPopupOptions} popup The options for how to detect if the
|
|
135
|
-
* request comes from a popup and how
|
|
136
|
-
* to compose the post message the
|
|
137
|
-
* middleware will use to respond.
|
|
138
|
-
* @property {string | number} version The version used to validate the
|
|
139
|
-
* requests.
|
|
140
|
-
* On the {@link VersionValidator}
|
|
141
|
-
* constructor, if specified via
|
|
142
|
-
* parameter,
|
|
143
|
-
* the class will take care of
|
|
144
|
-
* automatically add it to the options.
|
|
145
|
-
* @parent module:middlewares
|
|
146
|
-
*/
|
|
147
|
-
/**
|
|
148
|
-
* This is the handler for the middleware/controller that validates the app version.
|
|
149
|
-
* This is useful in cases where you want to restrict the access to the app to specific
|
|
150
|
-
* versions,
|
|
151
|
-
* for example: you have a frontend app which needs to be aligned with the "current"
|
|
152
|
-
* version of the app, since the frontend won't realize a new version was released, the
|
|
153
|
-
* validator can be used to let the frontend know.
|
|
154
|
-
* Also, it can be configured to handle requests from popups, in which case, instead of
|
|
155
|
-
* generating an error message, it will send a post message.
|
|
156
|
-
*
|
|
157
|
-
* @parent module:middlewares
|
|
158
|
-
*/
|
|
159
|
-
export class VersionValidator {
|
|
160
|
-
/**
|
|
161
|
-
* @param {?(string | ?number)} version
|
|
162
|
-
* The current version of the app. The reason this is nullable is because this comes
|
|
163
|
-
* directly from the app configuration, but you may want to re use this to validate
|
|
164
|
-
* "another version", so you can use the custom shorthand and send the version using the
|
|
165
|
-
* `options` parameter.
|
|
166
|
-
* @param {ResponsesBuilder} responsesBuilder
|
|
167
|
-
* To generate post message responses for popups.
|
|
168
|
-
* @param {ClassAppError} AppError
|
|
169
|
-
* To generate the error in case the version is invalid.
|
|
170
|
-
* @param {Partial<VersionValidatorOptions>} [options={}]
|
|
171
|
-
* Custom options to modify the middleware behavior.
|
|
172
|
-
* @throws {Error}
|
|
173
|
-
* If the version is `null` and the `options` don't include one either.
|
|
174
|
-
*/
|
|
175
|
-
constructor(version: (string | (number | null)) | null, responsesBuilder: ResponsesBuilder, AppError: any, options?: Partial<VersionValidatorOptions>);
|
|
176
|
-
/**
|
|
177
|
-
* A local reference for the `responsesBuilder` service.
|
|
178
|
-
*
|
|
179
|
-
* @type {ResponsesBuilder}
|
|
180
|
-
* @access protected
|
|
181
|
-
* @ignore
|
|
182
|
-
*/
|
|
183
|
-
_responsesBuilder: ResponsesBuilder;
|
|
184
|
-
/**
|
|
185
|
-
* A local reference for the class the app uses to generate errors.
|
|
186
|
-
*
|
|
187
|
-
* @type {ClassAppError}
|
|
188
|
-
* @access protected
|
|
189
|
-
* @ignore
|
|
190
|
-
*/
|
|
191
|
-
_AppError: any;
|
|
192
|
-
/**
|
|
193
|
-
* These are the "settings" the middleware will use in order to validate the requests.
|
|
194
|
-
*
|
|
195
|
-
* @type {VersionValidatorOptions}
|
|
196
|
-
* @access protected
|
|
197
|
-
* @ignore
|
|
198
|
-
*/
|
|
199
|
-
_options: VersionValidatorOptions;
|
|
200
|
-
/**
|
|
201
|
-
* Returns the Express middleware that will validate the `version` parameter.
|
|
202
|
-
*
|
|
203
|
-
* @returns {ExpressMiddleware}
|
|
204
|
-
*/
|
|
205
|
-
middleware(): ExpressMiddleware;
|
|
206
|
-
/**
|
|
207
|
-
* The options used to customize the middleware behavior.
|
|
208
|
-
*
|
|
209
|
-
* @returns {VersionValidatorOptions}
|
|
210
|
-
*/
|
|
211
|
-
get options(): VersionValidatorOptions;
|
|
212
|
-
/**
|
|
213
|
-
* Helper method that checks if the incoming request is from a popup.
|
|
214
|
-
*
|
|
215
|
-
* @param {ExpressRequest} req The request information.
|
|
216
|
-
* @returns {boolean}
|
|
217
|
-
* @access protected
|
|
218
|
-
* @ignore
|
|
219
|
-
*/
|
|
220
|
-
_isPopup(req: ExpressRequest): boolean;
|
|
221
|
-
/**
|
|
222
|
-
* Helper method that checks if the "latest version" is enabled and if the given version
|
|
223
|
-
* is "the latest" (comparing it with the option name).
|
|
224
|
-
*
|
|
225
|
-
* @param {string | number} version The version to validate.
|
|
226
|
-
* @returns {boolean}
|
|
227
|
-
* @access protected
|
|
228
|
-
* @ignore
|
|
229
|
-
*/
|
|
230
|
-
_validateLatest(version: string | number): boolean;
|
|
231
|
-
}
|
|
232
|
-
/**
|
|
233
|
-
* A middleware that will validate a `version` request parameter against the app version
|
|
234
|
-
* and generate an error if they don't match.
|
|
235
|
-
* This is a "middleware/controller" is because the wrappers for both are the same, the
|
|
236
|
-
* difference is that, for controllers, Jimpex sends a second parameter with the route
|
|
237
|
-
* where they are mounted.
|
|
238
|
-
* By validating the route parameter, the function can know whether the implementation is
|
|
239
|
-
* going to use the middleware by itself or as a route middleware.
|
|
240
|
-
* If used as middleware, it will just return the result of
|
|
241
|
-
* {@link VersionValidator#middleware};
|
|
242
|
-
* but if used as controller, it will mount it on `[route]/:version/*`.
|
|
243
|
-
*
|
|
244
|
-
* @type {MiddlewareCreator<VersionValidatorOptions>}
|
|
245
|
-
* @parent module:middlewares
|
|
246
|
-
*/
|
|
247
|
-
export const versionValidator: MiddlewareCreator<VersionValidatorOptions>;
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
export type Provider = import('../../types').Provider;
|
|
2
|
-
/**
|
|
3
|
-
* @typedef {import('../../types').Provider} Provider
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* A simple subclass of `Error` but with support for context information.
|
|
7
|
-
*
|
|
8
|
-
* @augments Error
|
|
9
|
-
* @parent module:services
|
|
10
|
-
*/
|
|
11
|
-
export class AppError extends Error {
|
|
12
|
-
/**
|
|
13
|
-
* @param {string} message The error message.
|
|
14
|
-
* @param {Object} [context={}] Context information related to the error.
|
|
15
|
-
*/
|
|
16
|
-
constructor(message: string, context?: any);
|
|
17
|
-
/**
|
|
18
|
-
* Context information related to the error.
|
|
19
|
-
*
|
|
20
|
-
* @type {Object}
|
|
21
|
-
* @access protected
|
|
22
|
-
* @todo Remove Object.freeze.
|
|
23
|
-
*/
|
|
24
|
-
_context: any;
|
|
25
|
-
/**
|
|
26
|
-
* The date of when the error was generated.
|
|
27
|
-
*
|
|
28
|
-
* @type {Date}
|
|
29
|
-
* @access protected
|
|
30
|
-
*/
|
|
31
|
-
_date: Date;
|
|
32
|
-
/**
|
|
33
|
-
* Context information related to the error.
|
|
34
|
-
*
|
|
35
|
-
* @type {Object}
|
|
36
|
-
*/
|
|
37
|
-
get context(): any;
|
|
38
|
-
/**
|
|
39
|
-
* The date of when the error was generated.
|
|
40
|
-
*
|
|
41
|
-
* @type {Date}
|
|
42
|
-
*/
|
|
43
|
-
get date(): Date;
|
|
44
|
-
/**
|
|
45
|
-
* Information about the error that can be shown on an app response. This is set using
|
|
46
|
-
* the `response` key on the `context`. The idea is that the error handler will read it
|
|
47
|
-
* and use it on the response.
|
|
48
|
-
*
|
|
49
|
-
* @returns {Object}
|
|
50
|
-
*/
|
|
51
|
-
get response(): any;
|
|
52
|
-
/**
|
|
53
|
-
* An HTTP status code related to the error. This is set using the `status` key on the
|
|
54
|
-
* `context`. If the error handler finds it, it will use it as the response status,
|
|
55
|
-
* and use it if necessary.
|
|
56
|
-
*
|
|
57
|
-
* @type {?number}
|
|
58
|
-
*/
|
|
59
|
-
get status(): number;
|
|
60
|
-
/**
|
|
61
|
-
* Utility method that formats the context before saving it in the instance:
|
|
62
|
-
* - If the context includes a `status` as a `string`, it will try to replace it with
|
|
63
|
-
* its status code from the `statuses` package.
|
|
64
|
-
*
|
|
65
|
-
* @param {Object} original The original context to format.
|
|
66
|
-
* @returns {Object}
|
|
67
|
-
* @access protected
|
|
68
|
-
* @ignore
|
|
69
|
-
*/
|
|
70
|
-
_parseContext(original: any): any;
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* A service provider that will register both the {@link AppError} and a generator
|
|
74
|
-
* function on the container. `AppError` will be the key for class, and `appError` will be
|
|
75
|
-
* for the generator function.
|
|
76
|
-
*
|
|
77
|
-
* @type {Provider}
|
|
78
|
-
* @example
|
|
79
|
-
*
|
|
80
|
-
* // Register it on the container
|
|
81
|
-
* container.register(appError);
|
|
82
|
-
* // Getting access to the class.
|
|
83
|
-
* const AppError = container.get('AppError');
|
|
84
|
-
* // Getting access to the function.
|
|
85
|
-
* const appError = container.get('appError');
|
|
86
|
-
*
|
|
87
|
-
* @parent module:services
|
|
88
|
-
*/
|
|
89
|
-
export const appError: Provider;
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
export type Provider = import('../../types').Provider;
|
|
2
|
-
/**
|
|
3
|
-
* @typedef {import('../../types').Provider} Provider
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* A type of error to be used on HTTP requests.
|
|
7
|
-
*
|
|
8
|
-
* @augments AppError
|
|
9
|
-
* @parent module:services
|
|
10
|
-
*/
|
|
11
|
-
export class HTTPError extends AppError {
|
|
12
|
-
/**
|
|
13
|
-
* @param {string} message The error message.
|
|
14
|
-
* @param {number} [status=200] The HTTP status code of the request response.
|
|
15
|
-
* @param {Object} [context={}] Context information related to the error.
|
|
16
|
-
*/
|
|
17
|
-
constructor(message: string, status?: number, context?: any);
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* A service provider that will register both the {@link HTTPError} and a generator
|
|
21
|
-
* function on the container. `HTTPError` will be the key for class, and `httpError` will
|
|
22
|
-
* be for the generator function.
|
|
23
|
-
*
|
|
24
|
-
* @type {Provider}
|
|
25
|
-
* @example
|
|
26
|
-
*
|
|
27
|
-
* // Register it on the container
|
|
28
|
-
* container.register(httpError);
|
|
29
|
-
* // Getting access to the class.
|
|
30
|
-
* const HTTPError = container.get('HTTPError');
|
|
31
|
-
* // Getting access to the function.
|
|
32
|
-
* const httpError = container.get('httpError');
|
|
33
|
-
*
|
|
34
|
-
* @parent module:services
|
|
35
|
-
*/
|
|
36
|
-
export const httpError: Provider;
|
|
37
|
-
import { AppError } from "./appError";
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export = commonServices;
|
|
2
|
-
/**
|
|
3
|
-
* @typedef {import('../../types').Provider} Provider
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* The providers collection for the common services.
|
|
7
|
-
*
|
|
8
|
-
* @type {Provider}
|
|
9
|
-
* @property {Provider} appError The provider for {@link AppError}.
|
|
10
|
-
* @property {Provider} httpError The provider for {@link HTTPError}.
|
|
11
|
-
* @property {Provider} sendFile The provider for {@link SendFile}.
|
|
12
|
-
* @parent module:services
|
|
13
|
-
*/
|
|
14
|
-
declare const commonServices: Provider;
|
|
15
|
-
declare namespace commonServices {
|
|
16
|
-
export { Provider };
|
|
17
|
-
}
|
|
18
|
-
type Provider = import('../../types').Provider;
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
export type PathUtils = import('../../types').PathUtils;
|
|
2
|
-
export type Provider = import('../../types').Provider;
|
|
3
|
-
export type ExpressResponse = import('../../types').ExpressResponse;
|
|
4
|
-
export type ExpressNext = import('../../types').ExpressNext;
|
|
5
|
-
export type SendFile = (res: ExpressResponse, filepath: string, next: ExpressNext, from?: string) => any;
|
|
6
|
-
/**
|
|
7
|
-
* @typedef {import('../../types').PathUtils} PathUtils
|
|
8
|
-
* @typedef {import('../../types').Provider} Provider
|
|
9
|
-
* @typedef {import('../../types').ExpressResponse} ExpressResponse
|
|
10
|
-
* @typedef {import('../../types').ExpressNext} ExpressNext
|
|
11
|
-
*/
|
|
12
|
-
/**
|
|
13
|
-
* @callback SendFile
|
|
14
|
-
* @param {ExpressResponse} res Necessary to write the file.
|
|
15
|
-
* @param {string} filepath The path to the file relative to where the app
|
|
16
|
-
* executable is located.
|
|
17
|
-
* @param {ExpressNext} next To call the send out the error if anything
|
|
18
|
-
* happens.
|
|
19
|
-
* @param {string} [from='app'] The location it uses to build the relative path.
|
|
20
|
-
* It can be `app` for the directory where the app
|
|
21
|
-
* executable is located, or `home` for the project
|
|
22
|
-
* root directory.
|
|
23
|
-
* @parent module:services
|
|
24
|
-
*/
|
|
25
|
-
/**
|
|
26
|
-
* Generates a function to send files with path relatives to the app executable file is
|
|
27
|
-
* located.
|
|
28
|
-
*
|
|
29
|
-
* @example
|
|
30
|
-
*
|
|
31
|
-
* // Let's say this is inside an Express middleware.
|
|
32
|
-
* // Get the function
|
|
33
|
-
* const send = sendFile(pathUtils);
|
|
34
|
-
* send(res, 'some-file.html', next);
|
|
35
|
-
* // If your app is on `/app/index.js`, this will send `/app/some-file.html`.
|
|
36
|
-
*
|
|
37
|
-
* @param {PathUtils} pathUtils To generate the relative paths.
|
|
38
|
-
* @returns {SendFile}
|
|
39
|
-
* @parent module:services
|
|
40
|
-
*/
|
|
41
|
-
export function sendFile(pathUtils: PathUtils): SendFile;
|
|
42
|
-
/**
|
|
43
|
-
* The service provider that once registered on the app container will set the result of
|
|
44
|
-
* `sendFile(pathUtils)` as the `sendFile` service.
|
|
45
|
-
*
|
|
46
|
-
* @type {Provider}
|
|
47
|
-
* @example
|
|
48
|
-
*
|
|
49
|
-
* // Register it on the container
|
|
50
|
-
* container.register(sendFileProvider);
|
|
51
|
-
* // Getting access to the service instance
|
|
52
|
-
* const sendFile = container.get('sendFile');
|
|
53
|
-
*
|
|
54
|
-
* @parent module:services
|
|
55
|
-
*/
|
|
56
|
-
export const sendFileProvider: Provider;
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
export type PathUtils = import('../../types').PathUtils;
|
|
2
|
-
export type Provider = import('../../types').Provider;
|
|
3
|
-
/**
|
|
4
|
-
* @typedef {import('../../types').PathUtils} PathUtils
|
|
5
|
-
* @typedef {import('../../types').Provider} Provider
|
|
6
|
-
*/
|
|
7
|
-
/**
|
|
8
|
-
* This service allows the app to easily read static files. The idea behind centralizing
|
|
9
|
-
* this functionalities into a service is that is pretty common to have bundling tools to
|
|
10
|
-
* generate the frontend, and on that process files can have different paths or not even
|
|
11
|
-
* be generated all, that's why this service exists. The service can be
|
|
12
|
-
* extended/overwritten to accommodate any requirements and avoid having to update or add
|
|
13
|
-
* `if`s to every `fs` call the app does.
|
|
14
|
-
* Another _'feature'_ of this service is that all the paths are relative to the directory
|
|
15
|
-
* where the app executable is located, so you don't have to remember the relative path
|
|
16
|
-
* from the place you are accessing a file to the place where it's located.
|
|
17
|
-
*
|
|
18
|
-
* @parent module:services
|
|
19
|
-
*/
|
|
20
|
-
export class FrontendFs {
|
|
21
|
-
/**
|
|
22
|
-
* @param {PathUtils} pathUtils To generate the relative paths.
|
|
23
|
-
*/
|
|
24
|
-
constructor(pathUtils: PathUtils);
|
|
25
|
-
/**
|
|
26
|
-
* A local reference for the `pathUtils` service.
|
|
27
|
-
*
|
|
28
|
-
* @type {PathUtils}
|
|
29
|
-
* @access protected
|
|
30
|
-
* @ignore
|
|
31
|
-
*/
|
|
32
|
-
_pathUtils: PathUtils;
|
|
33
|
-
/**
|
|
34
|
-
* Delete a file from the file system.
|
|
35
|
-
*
|
|
36
|
-
* @param {string} filepath The path to the file.
|
|
37
|
-
* @returns {Promise}
|
|
38
|
-
*/
|
|
39
|
-
delete(filepath: string): Promise<any>;
|
|
40
|
-
/**
|
|
41
|
-
* Read a file from the file system.
|
|
42
|
-
*
|
|
43
|
-
* @param {string} filepath The path to the file.
|
|
44
|
-
* @param {string} [encoding='utf-8'] The text encoding in which the file should be
|
|
45
|
-
* read.
|
|
46
|
-
* @returns {Promise<string>}
|
|
47
|
-
*/
|
|
48
|
-
read(filepath: string, encoding?: string): Promise<string>;
|
|
49
|
-
/**
|
|
50
|
-
* Write a file on the file system.
|
|
51
|
-
*
|
|
52
|
-
* @param {string} filepath The path to the file.
|
|
53
|
-
* @param {string} data The contents of the file.
|
|
54
|
-
* @returns {Promise}
|
|
55
|
-
*/
|
|
56
|
-
write(filepath: string, data: string): Promise<any>;
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* The service provider that once registered on the app container will set an instance of
|
|
60
|
-
* `FrontendFs` as the `frontendFs` service.
|
|
61
|
-
*
|
|
62
|
-
* @type {Provider}
|
|
63
|
-
* @example
|
|
64
|
-
*
|
|
65
|
-
* // Register it on the container
|
|
66
|
-
* container.register(frontendFs);
|
|
67
|
-
* // Getting access to the service instance
|
|
68
|
-
* const frontendFs = container.get('frontendFs');
|
|
69
|
-
*
|
|
70
|
-
* @parent module:services
|
|
71
|
-
*/
|
|
72
|
-
export const frontendFs: Provider;
|