jimpex 8.0.0 → 10.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 +33 -0
- package/README.md +2 -2
- package/dist/app/index.d.mts +14 -0
- package/dist/app/index.d.ts +5 -4
- package/dist/app/index.js +4 -0
- package/dist/app/jimpex.d.mts +14 -0
- package/dist/app/jimpex.d.ts +3 -2
- package/dist/app/jimpex.js +238 -2
- package/dist/app/jimpex.js.map +1 -1
- package/dist/controllers/common/config.d.mts +79 -0
- package/dist/controllers/common/config.d.ts +4 -3
- package/dist/controllers/common/config.js +18 -0
- package/dist/controllers/common/config.js.map +1 -1
- package/dist/controllers/common/health.d.mts +83 -0
- package/dist/controllers/common/health.d.ts +5 -4
- package/dist/controllers/common/health.js +18 -0
- package/dist/controllers/common/health.js.map +1 -1
- package/dist/controllers/common/index.d.mts +22 -0
- package/dist/controllers/common/index.d.ts +5 -4
- package/dist/controllers/common/index.js +6 -0
- package/dist/controllers/common/statics.d.mts +223 -0
- package/dist/controllers/common/statics.d.ts +13 -5
- package/dist/controllers/common/statics.js +60 -3
- package/dist/controllers/common/statics.js.map +1 -1
- package/dist/controllers/index.d.mts +25 -0
- package/dist/controllers/index.d.ts +5 -4
- package/dist/controllers/index.js +5 -0
- package/dist/controllers/utils/gateway.d.mts +725 -0
- package/dist/controllers/utils/gateway.d.ts +5 -4
- package/dist/controllers/utils/gateway.js +155 -0
- package/dist/controllers/utils/gateway.js.map +1 -1
- package/dist/controllers/utils/index.d.mts +17 -0
- package/dist/controllers/utils/index.d.ts +4 -3
- package/dist/controllers/utils/index.js +4 -0
- package/dist/esm/app/jimpex.js +235 -3
- package/dist/esm/app/jimpex.js.map +1 -1
- package/dist/esm/{chunk-T2T6Q22Z.js → chunk-F3FYYIAV.js} +1 -1
- package/dist/esm/controllers/common/config.js +19 -1
- package/dist/esm/controllers/common/config.js.map +1 -1
- package/dist/esm/controllers/common/health.js +19 -1
- package/dist/esm/controllers/common/health.js.map +1 -1
- package/dist/esm/controllers/common/statics.js +57 -4
- package/dist/esm/controllers/common/statics.js.map +1 -1
- package/dist/esm/controllers/utils/gateway.js +156 -1
- package/dist/esm/controllers/utils/gateway.js.map +1 -1
- package/dist/esm/middlewares/common/errorHandler.js +25 -1
- package/dist/esm/middlewares/common/errorHandler.js.map +1 -1
- package/dist/esm/middlewares/common/forceHTTPS.js +13 -1
- package/dist/esm/middlewares/common/forceHTTPS.js.map +1 -1
- package/dist/esm/middlewares/common/hsts.js +22 -1
- package/dist/esm/middlewares/common/hsts.js.map +1 -1
- package/dist/esm/middlewares/html/fastHTML.js +55 -1
- package/dist/esm/middlewares/html/fastHTML.js.map +1 -1
- package/dist/esm/middlewares/html/showHTML.js +33 -1
- package/dist/esm/middlewares/html/showHTML.js.map +1 -1
- package/dist/esm/middlewares/utils/versionValidator.js +35 -1
- package/dist/esm/middlewares/utils/versionValidator.js.map +1 -1
- package/dist/esm/services/common/appError.js +48 -2
- package/dist/esm/services/common/appError.js.map +1 -1
- package/dist/esm/services/common/httpError.js +10 -1
- package/dist/esm/services/common/httpError.js.map +1 -1
- package/dist/esm/services/common/index.js +1 -1
- package/dist/esm/services/common/sendFile.js +1 -1
- package/dist/esm/services/frontend/frontendFs.js +29 -1
- package/dist/esm/services/frontend/frontendFs.js.map +1 -1
- package/dist/esm/services/frontend/index.js +1 -1
- package/dist/esm/services/html/htmlGenerator.js +51 -1
- package/dist/esm/services/html/htmlGenerator.js.map +1 -1
- package/dist/esm/services/html/index.js +1 -1
- package/dist/esm/services/http/apiClient.js +27 -1
- package/dist/esm/services/http/apiClient.js.map +1 -1
- package/dist/esm/services/http/http.js +60 -5
- package/dist/esm/services/http/http.js.map +1 -1
- package/dist/esm/services/http/index.js +1 -1
- package/dist/esm/services/http/responsesBuilder.js +49 -2
- package/dist/esm/services/http/responsesBuilder.js.map +1 -1
- package/dist/esm/services/utils/ensureBearerToken.js +17 -1
- package/dist/esm/services/utils/ensureBearerToken.js.map +1 -1
- package/dist/esm/services/utils/index.js +1 -1
- package/dist/esm/utils/fns/others.js +1 -1
- package/dist/esm/utils/fns/routes.js +1 -1
- package/dist/esm/utils/fns/routes.js.map +1 -1
- package/dist/esm/utils/fns/statuses.js +1 -1
- package/dist/esm/utils/fns/text.js +1 -1
- package/dist/esm/utils/wrappers.js +1 -1
- package/dist/index-Bwf7JHu9.d.mts +1287 -0
- package/dist/{jimpex-7eaee271.d.ts → index-C6I3NCC-.d.ts} +15 -6
- package/dist/index.d.mts +47 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.js +9 -0
- package/dist/middlewares/common/errorHandler.d.mts +132 -0
- package/dist/middlewares/common/errorHandler.d.ts +5 -4
- package/dist/middlewares/common/errorHandler.js +24 -0
- package/dist/middlewares/common/errorHandler.js.map +1 -1
- package/dist/middlewares/common/forceHTTPS.d.mts +69 -0
- package/dist/middlewares/common/forceHTTPS.d.ts +6 -5
- package/dist/middlewares/common/forceHTTPS.js +12 -0
- package/dist/middlewares/common/forceHTTPS.js.map +1 -1
- package/dist/middlewares/common/hsts.d.mts +110 -0
- package/dist/middlewares/common/hsts.d.ts +6 -5
- package/dist/middlewares/common/hsts.js +21 -0
- package/dist/middlewares/common/hsts.js.map +1 -1
- package/dist/middlewares/common/index.d.mts +22 -0
- package/dist/middlewares/common/index.d.ts +4 -3
- package/dist/middlewares/common/index.js +6 -0
- package/dist/middlewares/html/fastHTML.d.mts +180 -0
- package/dist/middlewares/html/fastHTML.d.ts +5 -5
- package/dist/middlewares/html/fastHTML.js +54 -0
- package/dist/middlewares/html/fastHTML.js.map +1 -1
- package/dist/middlewares/html/index.d.mts +21 -0
- package/dist/middlewares/html/index.d.ts +4 -4
- package/dist/middlewares/html/index.js +5 -0
- package/dist/middlewares/html/showHTML.d.mts +127 -0
- package/dist/middlewares/html/showHTML.d.ts +5 -5
- package/dist/middlewares/html/showHTML.js +32 -0
- package/dist/middlewares/html/showHTML.js.map +1 -1
- package/dist/middlewares/index.d.mts +30 -0
- package/dist/middlewares/index.d.ts +4 -4
- package/dist/middlewares/index.js +6 -0
- package/dist/middlewares/utils/index.d.mts +20 -0
- package/dist/middlewares/utils/index.d.ts +4 -3
- package/dist/middlewares/utils/index.js +4 -0
- package/dist/middlewares/utils/versionValidator.d.mts +215 -0
- package/dist/middlewares/utils/versionValidator.d.ts +5 -4
- package/dist/middlewares/utils/versionValidator.js +34 -0
- package/dist/middlewares/utils/versionValidator.js.map +1 -1
- package/dist/services/common/appError.d.mts +139 -0
- package/dist/services/common/appError.d.ts +5 -4
- package/dist/services/common/appError.js +47 -1
- package/dist/services/common/appError.js.map +1 -1
- package/dist/services/common/httpError.d.mts +80 -0
- package/dist/services/common/httpError.d.ts +5 -4
- package/dist/services/common/httpError.js +9 -0
- package/dist/services/common/httpError.js.map +1 -1
- package/dist/services/common/index.d.mts +47 -0
- package/dist/services/common/index.d.ts +4 -4
- package/dist/services/common/index.js +4 -1
- package/dist/services/common/sendFile.d.mts +102 -0
- package/dist/services/common/sendFile.d.ts +4 -4
- package/dist/services/frontend/frontendFs.d.mts +96 -0
- package/dist/services/frontend/frontendFs.d.ts +4 -4
- package/dist/services/frontend/frontendFs.js +32 -0
- package/dist/services/frontend/frontendFs.js.map +1 -1
- package/dist/services/frontend/index.d.mts +40 -0
- package/dist/services/frontend/index.d.ts +4 -4
- package/dist/services/frontend/index.js +2 -1
- package/dist/services/html/htmlGenerator.d.mts +237 -0
- package/dist/services/html/htmlGenerator.d.ts +3 -3
- package/dist/services/html/htmlGenerator.js +50 -0
- package/dist/services/html/htmlGenerator.js.map +1 -1
- package/dist/services/html/index.d.mts +43 -0
- package/dist/services/html/index.d.ts +4 -4
- package/dist/services/html/index.js +2 -1
- package/dist/services/http/apiClient.d.mts +170 -0
- package/dist/services/http/apiClient.d.ts +5 -4
- package/dist/services/http/apiClient.js +26 -0
- package/dist/services/http/apiClient.js.map +1 -1
- package/dist/services/http/http.d.mts +182 -0
- package/dist/services/http/http.d.ts +15 -8
- package/dist/services/http/http.js +63 -4
- package/dist/services/http/http.js.map +1 -1
- package/dist/services/http/index.d.mts +51 -0
- package/dist/services/http/index.d.ts +4 -3
- package/dist/services/http/index.js +4 -1
- package/dist/services/http/responsesBuilder.d.mts +179 -0
- package/dist/services/http/responsesBuilder.d.ts +4 -3
- package/dist/services/http/responsesBuilder.js +48 -1
- package/dist/services/http/responsesBuilder.js.map +1 -1
- package/dist/services/index.d.mts +33 -0
- package/dist/services/index.d.ts +4 -4
- package/dist/services/index.js +8 -0
- package/dist/services/utils/ensureBearerToken.d.mts +158 -0
- package/dist/services/utils/ensureBearerToken.d.ts +6 -5
- package/dist/services/utils/ensureBearerToken.js +16 -0
- package/dist/services/utils/ensureBearerToken.js.map +1 -1
- package/dist/services/utils/index.d.mts +44 -0
- package/dist/services/utils/index.d.ts +4 -3
- package/dist/services/utils/index.js +2 -1
- package/dist/types/events.d.mts +14 -0
- package/dist/types/events.d.ts +5 -4
- package/dist/types/express.d.mts +10 -0
- package/dist/types/express.d.ts +1 -1
- package/dist/types/http.d.mts +82 -0
- package/dist/types/http.d.ts +5 -2
- package/dist/types/http.js.map +1 -1
- package/dist/types/index.d.mts +14 -0
- package/dist/types/index.d.ts +2 -2
- package/dist/types/index.js +9 -0
- package/dist/types/options.d.mts +14 -0
- package/dist/types/options.d.ts +4 -3
- package/dist/types/utils.d.mts +48 -0
- package/dist/types/utils.d.ts +1 -1
- package/dist/types/wootils.d.mts +4 -0
- package/dist/utils/fns/index.d.mts +5 -0
- package/dist/utils/fns/index.js +7 -0
- package/dist/utils/fns/others.d.mts +17 -0
- package/dist/utils/fns/routes.d.mts +39 -0
- package/dist/utils/fns/routes.js.map +1 -1
- package/dist/utils/fns/statuses.d.mts +45 -0
- package/dist/utils/fns/statuses.d.ts +1 -1
- package/dist/utils/fns/statuses.js +4 -0
- package/dist/utils/fns/statuses.js.map +1 -1
- package/dist/utils/fns/text.d.mts +9 -0
- package/dist/utils/index.d.mts +19 -0
- package/dist/utils/index.d.ts +5 -4
- package/dist/utils/index.js +5 -0
- package/dist/utils/wrappers.d.mts +14 -0
- package/dist/utils/wrappers.d.ts +4 -3
- package/package.json +50 -49
- package/src/app/jimpex.ts +15 -2
- package/src/controllers/common/statics.ts +13 -2
- package/src/controllers/utils/gateway.ts +4 -0
- package/src/services/http/http.ts +13 -4
- package/src/types/http.ts +3 -0
- /package/dist/esm/{chunk-T2T6Q22Z.js.map → chunk-F3FYYIAV.js.map} +0 -0
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import * as _homer0_jimple from '@homer0/jimple';
|
|
2
|
+
import { J as Jimpex, R as MiddlewareConnectFn } from '../../index-Bwf7JHu9.mjs';
|
|
3
|
+
import { AsyncExpressMiddleware } from '../../types/express.mjs';
|
|
4
|
+
import { SendFile } from '../../services/common/sendFile.mjs';
|
|
5
|
+
import { HTMLGenerator } from '../../services/html/htmlGenerator.mjs';
|
|
6
|
+
import { Response, NextFunction } from 'express';
|
|
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/simple-config';
|
|
16
|
+
import '@homer0/events-hub';
|
|
17
|
+
import '../../services/frontend/frontendFs.mjs';
|
|
18
|
+
import 'fs/promises';
|
|
19
|
+
import '@homer0/deferred';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The options to customize the behavior of the middleware.
|
|
23
|
+
*
|
|
24
|
+
* @group Middlewares/ShowHTML
|
|
25
|
+
*/
|
|
26
|
+
type ShowHTMLOptions = {
|
|
27
|
+
/**
|
|
28
|
+
* The name of the file the middleware will serve. If the {@link HTMLGenerator} service
|
|
29
|
+
* is available, it will be overriden by the service.
|
|
30
|
+
*
|
|
31
|
+
* @default 'index.html'
|
|
32
|
+
*/
|
|
33
|
+
file: string;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* The options to construct a {@link ShowHTML}.
|
|
37
|
+
*
|
|
38
|
+
* @group Middlewares/ShowHTML
|
|
39
|
+
*/
|
|
40
|
+
type ShowHTMLConstructorOptions = Partial<ShowHTMLOptions> & {
|
|
41
|
+
/**
|
|
42
|
+
* A dictionary with the dependencies to inject.
|
|
43
|
+
*/
|
|
44
|
+
inject: {
|
|
45
|
+
sendFile: SendFile;
|
|
46
|
+
/**
|
|
47
|
+
* A function to get a possible {@link HTMLGenerator}. This is injected as a "getter"
|
|
48
|
+
* to not interrupt the DIC "lifecycle": middlewares are initialized right when the
|
|
49
|
+
* app starts, and injecting a reference would force the service to be initialized
|
|
50
|
+
* too, even if a request is not being made.
|
|
51
|
+
*/
|
|
52
|
+
getHTMLGenerator?: () => HTMLGenerator | undefined;
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* The options for the middleware creator that will mount an instance of {@link ShowHTML}.
|
|
57
|
+
*
|
|
58
|
+
* @group Middlewares/ShowHTML
|
|
59
|
+
*/
|
|
60
|
+
type ShowHTMLMiddlewareOptions = Partial<ShowHTMLOptions> & {
|
|
61
|
+
/**
|
|
62
|
+
* The name of an {@link HTMLGenerator} service already available in the application.
|
|
63
|
+
*
|
|
64
|
+
* @default 'htmlGenerator'
|
|
65
|
+
*/
|
|
66
|
+
htmlGeneratorServiceName?: string;
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* A very simple middleware service to send an HTML on a server response. The special
|
|
70
|
+
* _'feature'_ of this service is that it can be hooked up to an {@link HTMLGenerator}
|
|
71
|
+
* service and it will automatically server the file generated by it.
|
|
72
|
+
*
|
|
73
|
+
* @group Middleware Classes
|
|
74
|
+
* @group Middlewares/ShowHTML
|
|
75
|
+
* @prettierignore
|
|
76
|
+
*/
|
|
77
|
+
declare class ShowHTML {
|
|
78
|
+
/**
|
|
79
|
+
* The service that serves a file.
|
|
80
|
+
*/
|
|
81
|
+
protected readonly _sendFile: SendFile;
|
|
82
|
+
/**
|
|
83
|
+
* A function to get a possible {@link HTMLGenerator}. This is injected as a "getter"
|
|
84
|
+
* to not interrupt the DIC "lifecycle": middlewares are initialized right when the
|
|
85
|
+
* app starts, and injecting a reference would force the service to be initialized
|
|
86
|
+
* too, even if a request is not being made.
|
|
87
|
+
*/
|
|
88
|
+
protected readonly _getHTMLGenerator: () => HTMLGenerator | undefined;
|
|
89
|
+
/**
|
|
90
|
+
* The customization options for the middleware.
|
|
91
|
+
*/
|
|
92
|
+
protected _options: ShowHTMLOptions;
|
|
93
|
+
/**
|
|
94
|
+
* Whether or not the file is ready to be served. In case the middleware uses an
|
|
95
|
+
* {@link HTMLGenerator} service, the file needs to be generated before being available,
|
|
96
|
+
* and that's why this flag exists.
|
|
97
|
+
*/
|
|
98
|
+
protected _fileReady: boolean;
|
|
99
|
+
/**
|
|
100
|
+
* @param options The options to construct the class.
|
|
101
|
+
*/
|
|
102
|
+
constructor({ inject, ...options }: ShowHTMLConstructorOptions);
|
|
103
|
+
/**
|
|
104
|
+
* Generates the middleware that serves the HTML file.
|
|
105
|
+
*/
|
|
106
|
+
getMiddleware(): AsyncExpressMiddleware;
|
|
107
|
+
/**
|
|
108
|
+
* The customization options.
|
|
109
|
+
*/
|
|
110
|
+
get options(): Readonly<ShowHTMLOptions>;
|
|
111
|
+
/**
|
|
112
|
+
* Serves the HTML file to the response.
|
|
113
|
+
*
|
|
114
|
+
* @param res The response object generated by the application.
|
|
115
|
+
* @param next The function to call the next middleware.
|
|
116
|
+
*/
|
|
117
|
+
protected _sendResponse(res: Response, next: NextFunction): void;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Creates the middleware that serves an HTML file in the response.
|
|
121
|
+
*
|
|
122
|
+
* @group Middlewares
|
|
123
|
+
* @group Middlewares/ShowHTML
|
|
124
|
+
*/
|
|
125
|
+
declare const showHTMLMiddleware: _homer0_jimple.ResourceCreator<"middleware", "connect", (options?: ShowHTMLMiddlewareOptions) => <ContainerType extends Jimpex = Jimpex>(app: ContainerType) => AsyncExpressMiddleware, MiddlewareConnectFn>;
|
|
126
|
+
|
|
127
|
+
export { ShowHTML, type ShowHTMLConstructorOptions, type ShowHTMLMiddlewareOptions, type ShowHTMLOptions, showHTMLMiddleware };
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import * as _homer0_jimple from '@homer0/jimple';
|
|
2
|
-
import { J as Jimpex, R as MiddlewareConnectFn } from '../../
|
|
2
|
+
import { J as Jimpex, R as MiddlewareConnectFn } from '../../index-C6I3NCC-.js';
|
|
3
3
|
import { AsyncExpressMiddleware } from '../../types/express.js';
|
|
4
4
|
import { SendFile } from '../../services/common/sendFile.js';
|
|
5
5
|
import { HTMLGenerator } from '../../services/html/htmlGenerator.js';
|
|
6
6
|
import { Response, NextFunction } from 'express';
|
|
7
|
-
import '@homer0/events-hub';
|
|
8
7
|
import '../../types/http.js';
|
|
9
8
|
import 'https';
|
|
10
9
|
import 'http';
|
|
11
10
|
import 'spdy';
|
|
12
11
|
import 'node-fetch';
|
|
13
|
-
import '@homer0/simple-config';
|
|
14
12
|
import '../../types/utils.js';
|
|
15
|
-
import '@homer0/simple-logger';
|
|
16
13
|
import '@homer0/path-utils';
|
|
14
|
+
import '@homer0/simple-logger';
|
|
15
|
+
import '@homer0/simple-config';
|
|
16
|
+
import '@homer0/events-hub';
|
|
17
17
|
import '../../services/frontend/frontendFs.js';
|
|
18
18
|
import 'fs/promises';
|
|
19
19
|
import '@homer0/deferred';
|
|
@@ -124,4 +124,4 @@ declare class ShowHTML {
|
|
|
124
124
|
*/
|
|
125
125
|
declare const showHTMLMiddleware: _homer0_jimple.ResourceCreator<"middleware", "connect", (options?: ShowHTMLMiddlewareOptions) => <ContainerType extends Jimpex = Jimpex>(app: ContainerType) => AsyncExpressMiddleware, MiddlewareConnectFn>;
|
|
126
126
|
|
|
127
|
-
export { ShowHTML, ShowHTMLConstructorOptions, ShowHTMLMiddlewareOptions, ShowHTMLOptions, showHTMLMiddleware };
|
|
127
|
+
export { ShowHTML, type ShowHTMLConstructorOptions, type ShowHTMLMiddlewareOptions, type ShowHTMLOptions, showHTMLMiddleware };
|
|
@@ -29,10 +29,30 @@ __export(showHTML_exports, {
|
|
|
29
29
|
module.exports = __toCommonJS(showHTML_exports);
|
|
30
30
|
var import_utils = require("../../utils");
|
|
31
31
|
class ShowHTML {
|
|
32
|
+
/**
|
|
33
|
+
* @param options The options to construct the class.
|
|
34
|
+
*/
|
|
32
35
|
constructor({ inject, ...options }) {
|
|
36
|
+
/**
|
|
37
|
+
* The service that serves a file.
|
|
38
|
+
*/
|
|
33
39
|
__publicField(this, "_sendFile");
|
|
40
|
+
/**
|
|
41
|
+
* A function to get a possible {@link HTMLGenerator}. This is injected as a "getter"
|
|
42
|
+
* to not interrupt the DIC "lifecycle": middlewares are initialized right when the
|
|
43
|
+
* app starts, and injecting a reference would force the service to be initialized
|
|
44
|
+
* too, even if a request is not being made.
|
|
45
|
+
*/
|
|
34
46
|
__publicField(this, "_getHTMLGenerator");
|
|
47
|
+
/**
|
|
48
|
+
* The customization options for the middleware.
|
|
49
|
+
*/
|
|
35
50
|
__publicField(this, "_options");
|
|
51
|
+
/**
|
|
52
|
+
* Whether or not the file is ready to be served. In case the middleware uses an
|
|
53
|
+
* {@link HTMLGenerator} service, the file needs to be generated before being available,
|
|
54
|
+
* and that's why this flag exists.
|
|
55
|
+
*/
|
|
36
56
|
__publicField(this, "_fileReady", false);
|
|
37
57
|
this._sendFile = inject.sendFile;
|
|
38
58
|
this._getHTMLGenerator = inject.getHTMLGenerator || (() => void 0);
|
|
@@ -41,6 +61,9 @@ class ShowHTML {
|
|
|
41
61
|
...options
|
|
42
62
|
};
|
|
43
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* Generates the middleware that serves the HTML file.
|
|
66
|
+
*/
|
|
44
67
|
getMiddleware() {
|
|
45
68
|
return async (_, res, next) => {
|
|
46
69
|
if (this._fileReady) {
|
|
@@ -63,9 +86,18 @@ class ShowHTML {
|
|
|
63
86
|
}
|
|
64
87
|
};
|
|
65
88
|
}
|
|
89
|
+
/**
|
|
90
|
+
* The customization options.
|
|
91
|
+
*/
|
|
66
92
|
get options() {
|
|
67
93
|
return { ...this._options };
|
|
68
94
|
}
|
|
95
|
+
/**
|
|
96
|
+
* Serves the HTML file to the response.
|
|
97
|
+
*
|
|
98
|
+
* @param res The response object generated by the application.
|
|
99
|
+
* @param next The function to call the next middleware.
|
|
100
|
+
*/
|
|
69
101
|
_sendResponse(res, next) {
|
|
70
102
|
res.setHeader("Content-Type", "text/html");
|
|
71
103
|
this._sendFile({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/middlewares/html/showHTML.ts"],"sourcesContent":["import { middlewareCreator } from '../../utils';\nimport type { HTMLGenerator, SendFile } from '../../services';\nimport type { AsyncExpressMiddleware, Response, NextFunction } from '../../types';\n/**\n * The options to customize the behavior of the middleware.\n *\n * @group Middlewares/ShowHTML\n */\nexport type ShowHTMLOptions = {\n /**\n * The name of the file the middleware will serve. If the {@link HTMLGenerator} service\n * is available, it will be overriden by the service.\n *\n * @default 'index.html'\n */\n file: string;\n};\n/**\n * The options to construct a {@link ShowHTML}.\n *\n * @group Middlewares/ShowHTML\n */\nexport type ShowHTMLConstructorOptions = Partial<ShowHTMLOptions> & {\n /**\n * A dictionary with the dependencies to inject.\n */\n inject: {\n sendFile: SendFile;\n /**\n * A function to get a possible {@link HTMLGenerator}. This is injected as a \"getter\"\n * to not interrupt the DIC \"lifecycle\": middlewares are initialized right when the\n * app starts, and injecting a reference would force the service to be initialized\n * too, even if a request is not being made.\n */\n getHTMLGenerator?: () => HTMLGenerator | undefined;\n };\n};\n/**\n * The options for the middleware creator that will mount an instance of {@link ShowHTML}.\n *\n * @group Middlewares/ShowHTML\n */\nexport type ShowHTMLMiddlewareOptions = Partial<ShowHTMLOptions> & {\n /**\n * The name of an {@link HTMLGenerator} service already available in the application.\n *\n * @default 'htmlGenerator'\n */\n htmlGeneratorServiceName?: string;\n};\n\n/**\n * A very simple middleware service to send an HTML on a server response. The special\n * _'feature'_ of this service is that it can be hooked up to an {@link HTMLGenerator}\n * service and it will automatically server the file generated by it.\n *\n * @group Middleware Classes\n * @group Middlewares/ShowHTML\n * @prettierignore\n */\nexport class ShowHTML {\n /**\n * The service that serves a file.\n */\n protected readonly _sendFile: SendFile;\n /**\n * A function to get a possible {@link HTMLGenerator}. This is injected as a \"getter\"\n * to not interrupt the DIC \"lifecycle\": middlewares are initialized right when the\n * app starts, and injecting a reference would force the service to be initialized\n * too, even if a request is not being made.\n */\n protected readonly _getHTMLGenerator: () => HTMLGenerator | undefined;\n /**\n * The customization options for the middleware.\n */\n protected _options: ShowHTMLOptions;\n /**\n * Whether or not the file is ready to be served. In case the middleware uses an\n * {@link HTMLGenerator} service, the file needs to be generated before being available,\n * and that's why this flag exists.\n */\n protected _fileReady: boolean = false;\n /**\n * @param options The options to construct the class.\n */\n constructor({ inject, ...options }: ShowHTMLConstructorOptions) {\n this._sendFile = inject.sendFile;\n this._getHTMLGenerator = inject.getHTMLGenerator || (() => undefined);\n this._options = {\n file: 'index.html',\n ...options,\n };\n }\n /**\n * Generates the middleware that serves the HTML file.\n */\n getMiddleware(): AsyncExpressMiddleware {\n return async (_, res, next) => {\n // If the file is ready to be served, serve it.\n if (this._fileReady) {\n this._sendResponse(res, next);\n return;\n }\n\n const htmlGenerator = this._getHTMLGenerator();\n // If there's no generator, switch the flag and just serve the file.\n if (!htmlGenerator) {\n this._fileReady = true;\n this._sendResponse(res, next);\n return;\n }\n\n try {\n // Wait for the HTML to be generated.\n await htmlGenerator.whenReady();\n // Update the local option.\n this._options.file = htmlGenerator.options.file;\n // Switch the flag and serve the file.\n this._fileReady = true;\n this._sendResponse(res, next);\n } catch (error) {\n next(error);\n }\n };\n }\n /**\n * The customization options.\n */\n get options(): Readonly<ShowHTMLOptions> {\n return { ...this._options };\n }\n /**\n * Serves the HTML file to the response.\n *\n * @param res The response object generated by the application.\n * @param next The function to call the next middleware.\n */\n protected _sendResponse(res: Response, next: NextFunction): void {\n res.setHeader('Content-Type', 'text/html');\n this._sendFile({\n res,\n next,\n filepath: this._options.file,\n });\n }\n}\n/**\n * Creates the middleware that serves an HTML file in the response.\n *\n * @group Middlewares\n * @group Middlewares/ShowHTML\n */\nexport const showHTMLMiddleware = middlewareCreator(\n (options: ShowHTMLMiddlewareOptions = {}) =>\n (app) => {\n const { htmlGeneratorServiceName = 'htmlGenerator', ...rest } = options;\n return new ShowHTML({\n inject: {\n sendFile: app.get('sendFile'),\n getHTMLGenerator: () => app.try(htmlGeneratorServiceName),\n },\n ...rest,\n }).getMiddleware();\n },\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAkC;AA4D3B,MAAM,SAAS;AAAA,EAyBpB,YAAY,EAAE,
|
|
1
|
+
{"version":3,"sources":["../../../src/middlewares/html/showHTML.ts"],"sourcesContent":["import { middlewareCreator } from '../../utils';\nimport type { HTMLGenerator, SendFile } from '../../services';\nimport type { AsyncExpressMiddleware, Response, NextFunction } from '../../types';\n/**\n * The options to customize the behavior of the middleware.\n *\n * @group Middlewares/ShowHTML\n */\nexport type ShowHTMLOptions = {\n /**\n * The name of the file the middleware will serve. If the {@link HTMLGenerator} service\n * is available, it will be overriden by the service.\n *\n * @default 'index.html'\n */\n file: string;\n};\n/**\n * The options to construct a {@link ShowHTML}.\n *\n * @group Middlewares/ShowHTML\n */\nexport type ShowHTMLConstructorOptions = Partial<ShowHTMLOptions> & {\n /**\n * A dictionary with the dependencies to inject.\n */\n inject: {\n sendFile: SendFile;\n /**\n * A function to get a possible {@link HTMLGenerator}. This is injected as a \"getter\"\n * to not interrupt the DIC \"lifecycle\": middlewares are initialized right when the\n * app starts, and injecting a reference would force the service to be initialized\n * too, even if a request is not being made.\n */\n getHTMLGenerator?: () => HTMLGenerator | undefined;\n };\n};\n/**\n * The options for the middleware creator that will mount an instance of {@link ShowHTML}.\n *\n * @group Middlewares/ShowHTML\n */\nexport type ShowHTMLMiddlewareOptions = Partial<ShowHTMLOptions> & {\n /**\n * The name of an {@link HTMLGenerator} service already available in the application.\n *\n * @default 'htmlGenerator'\n */\n htmlGeneratorServiceName?: string;\n};\n\n/**\n * A very simple middleware service to send an HTML on a server response. The special\n * _'feature'_ of this service is that it can be hooked up to an {@link HTMLGenerator}\n * service and it will automatically server the file generated by it.\n *\n * @group Middleware Classes\n * @group Middlewares/ShowHTML\n * @prettierignore\n */\nexport class ShowHTML {\n /**\n * The service that serves a file.\n */\n protected readonly _sendFile: SendFile;\n /**\n * A function to get a possible {@link HTMLGenerator}. This is injected as a \"getter\"\n * to not interrupt the DIC \"lifecycle\": middlewares are initialized right when the\n * app starts, and injecting a reference would force the service to be initialized\n * too, even if a request is not being made.\n */\n protected readonly _getHTMLGenerator: () => HTMLGenerator | undefined;\n /**\n * The customization options for the middleware.\n */\n protected _options: ShowHTMLOptions;\n /**\n * Whether or not the file is ready to be served. In case the middleware uses an\n * {@link HTMLGenerator} service, the file needs to be generated before being available,\n * and that's why this flag exists.\n */\n protected _fileReady: boolean = false;\n /**\n * @param options The options to construct the class.\n */\n constructor({ inject, ...options }: ShowHTMLConstructorOptions) {\n this._sendFile = inject.sendFile;\n this._getHTMLGenerator = inject.getHTMLGenerator || (() => undefined);\n this._options = {\n file: 'index.html',\n ...options,\n };\n }\n /**\n * Generates the middleware that serves the HTML file.\n */\n getMiddleware(): AsyncExpressMiddleware {\n return async (_, res, next) => {\n // If the file is ready to be served, serve it.\n if (this._fileReady) {\n this._sendResponse(res, next);\n return;\n }\n\n const htmlGenerator = this._getHTMLGenerator();\n // If there's no generator, switch the flag and just serve the file.\n if (!htmlGenerator) {\n this._fileReady = true;\n this._sendResponse(res, next);\n return;\n }\n\n try {\n // Wait for the HTML to be generated.\n await htmlGenerator.whenReady();\n // Update the local option.\n this._options.file = htmlGenerator.options.file;\n // Switch the flag and serve the file.\n this._fileReady = true;\n this._sendResponse(res, next);\n } catch (error) {\n next(error);\n }\n };\n }\n /**\n * The customization options.\n */\n get options(): Readonly<ShowHTMLOptions> {\n return { ...this._options };\n }\n /**\n * Serves the HTML file to the response.\n *\n * @param res The response object generated by the application.\n * @param next The function to call the next middleware.\n */\n protected _sendResponse(res: Response, next: NextFunction): void {\n res.setHeader('Content-Type', 'text/html');\n this._sendFile({\n res,\n next,\n filepath: this._options.file,\n });\n }\n}\n/**\n * Creates the middleware that serves an HTML file in the response.\n *\n * @group Middlewares\n * @group Middlewares/ShowHTML\n */\nexport const showHTMLMiddleware = middlewareCreator(\n (options: ShowHTMLMiddlewareOptions = {}) =>\n (app) => {\n const { htmlGeneratorServiceName = 'htmlGenerator', ...rest } = options;\n return new ShowHTML({\n inject: {\n sendFile: app.get('sendFile'),\n getHTMLGenerator: () => app.try(htmlGeneratorServiceName),\n },\n ...rest,\n }).getMiddleware();\n },\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAkC;AA4D3B,MAAM,SAAS;AAAA;AAAA;AAAA;AAAA,EAyBpB,YAAY,EAAE,QAAQ,GAAG,QAAQ,GAA+B;AArBhE;AAAA;AAAA;AAAA,wBAAmB;AAOnB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAAmB;AAInB;AAAA;AAAA;AAAA,wBAAU;AAMV;AAAA;AAAA;AAAA;AAAA;AAAA,wBAAU,cAAsB;AAK9B,SAAK,YAAY,OAAO;AACxB,SAAK,oBAAoB,OAAO,qBAAqB,MAAM;AAC3D,SAAK,WAAW;AAAA,MACd,MAAM;AAAA,MACN,GAAG;AAAA,IACL;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAIA,gBAAwC;AACtC,WAAO,OAAO,GAAG,KAAK,SAAS;AAE7B,UAAI,KAAK,YAAY;AACnB,aAAK,cAAc,KAAK,IAAI;AAC5B;AAAA,MACF;AAEA,YAAM,gBAAgB,KAAK,kBAAkB;AAE7C,UAAI,CAAC,eAAe;AAClB,aAAK,aAAa;AAClB,aAAK,cAAc,KAAK,IAAI;AAC5B;AAAA,MACF;AAEA,UAAI;AAEF,cAAM,cAAc,UAAU;AAE9B,aAAK,SAAS,OAAO,cAAc,QAAQ;AAE3C,aAAK,aAAa;AAClB,aAAK,cAAc,KAAK,IAAI;AAAA,MAC9B,SAAS,OAAO;AACd,aAAK,KAAK;AAAA,MACZ;AAAA,IACF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAIA,IAAI,UAAqC;AACvC,WAAO,EAAE,GAAG,KAAK,SAAS;AAAA,EAC5B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOU,cAAc,KAAe,MAA0B;AAC/D,QAAI,UAAU,gBAAgB,WAAW;AACzC,SAAK,UAAU;AAAA,MACb;AAAA,MACA;AAAA,MACA,UAAU,KAAK,SAAS;AAAA,IAC1B,CAAC;AAAA,EACH;AACF;AAOO,MAAM,yBAAqB;AAAA,EAChC,CAAC,UAAqC,CAAC,MACrC,CAAC,QAAQ;AACP,UAAM,EAAE,2BAA2B,iBAAiB,GAAG,KAAK,IAAI;AAChE,WAAO,IAAI,SAAS;AAAA,MAClB,QAAQ;AAAA,QACN,UAAU,IAAI,IAAI,UAAU;AAAA,QAC5B,kBAAkB,MAAM,IAAI,IAAI,wBAAwB;AAAA,MAC1D;AAAA,MACA,GAAG;AAAA,IACL,CAAC,EAAE,cAAc;AAAA,EACnB;AACJ;","names":[]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export { ErrorHandler, ErrorHandlerConstructorOptions, ErrorHandlerOptions, ErrorHandlerPartialOptions, ErrorHandlerResponseOptions, errorHandlerMiddleware } from './common/errorHandler.mjs';
|
|
2
|
+
export { ForceHTTPS, ForceHTTPSOptions, ForceHTTPSPartialOptions, forceHTTPSMiddleware } from './common/forceHTTPS.mjs';
|
|
3
|
+
export { HSTS, HSTSMiddlewareOptions, HSTSMiddlewarePartialOptions, HSTSMiddlewareSettings, hstsMiddleware } from './common/hsts.mjs';
|
|
4
|
+
export { FastHTML, FastHTMLConstructorOptions, FastHTMLMiddlewareOptions, FastHTMLOptions, fastHTMLMiddleware } from './html/fastHTML.mjs';
|
|
5
|
+
export { ShowHTML, ShowHTMLConstructorOptions, ShowHTMLMiddlewareOptions, ShowHTMLOptions, showHTMLMiddleware } from './html/showHTML.mjs';
|
|
6
|
+
export { VersionValidator, VersionValidatorConstructorOptions, VersionValidatorLatestOptions, VersionValidatorMiddlewareOptions, VersionValidatorOptions, VersionValidatorPartialOptions, VersionValidatorPopupOptions, versionValidatorMiddleware } from './utils/versionValidator.mjs';
|
|
7
|
+
import '@homer0/jimple';
|
|
8
|
+
import '../utils/fns/statuses.mjs';
|
|
9
|
+
import 'statuses';
|
|
10
|
+
import '../index-Bwf7JHu9.mjs';
|
|
11
|
+
import '../types/express.mjs';
|
|
12
|
+
import 'express';
|
|
13
|
+
import '../types/http.mjs';
|
|
14
|
+
import 'https';
|
|
15
|
+
import 'http';
|
|
16
|
+
import 'spdy';
|
|
17
|
+
import 'node-fetch';
|
|
18
|
+
import '../types/utils.mjs';
|
|
19
|
+
import '@homer0/path-utils';
|
|
20
|
+
import '@homer0/simple-logger';
|
|
21
|
+
import '@homer0/simple-config';
|
|
22
|
+
import '@homer0/events-hub';
|
|
23
|
+
import '../services/common/httpError.mjs';
|
|
24
|
+
import '../services/common/appError.mjs';
|
|
25
|
+
import '../services/http/responsesBuilder.mjs';
|
|
26
|
+
import '../services/common/sendFile.mjs';
|
|
27
|
+
import '../services/html/htmlGenerator.mjs';
|
|
28
|
+
import '../services/frontend/frontendFs.mjs';
|
|
29
|
+
import 'fs/promises';
|
|
30
|
+
import '@homer0/deferred';
|
|
@@ -7,8 +7,7 @@ export { VersionValidator, VersionValidatorConstructorOptions, VersionValidatorL
|
|
|
7
7
|
import '@homer0/jimple';
|
|
8
8
|
import '../utils/fns/statuses.js';
|
|
9
9
|
import 'statuses';
|
|
10
|
-
import '../
|
|
11
|
-
import '@homer0/events-hub';
|
|
10
|
+
import '../index-C6I3NCC-.js';
|
|
12
11
|
import '../types/express.js';
|
|
13
12
|
import 'express';
|
|
14
13
|
import '../types/http.js';
|
|
@@ -16,14 +15,15 @@ import 'https';
|
|
|
16
15
|
import 'http';
|
|
17
16
|
import 'spdy';
|
|
18
17
|
import 'node-fetch';
|
|
19
|
-
import '@homer0/simple-config';
|
|
20
18
|
import '../types/utils.js';
|
|
19
|
+
import '@homer0/path-utils';
|
|
21
20
|
import '@homer0/simple-logger';
|
|
21
|
+
import '@homer0/simple-config';
|
|
22
|
+
import '@homer0/events-hub';
|
|
22
23
|
import '../services/common/httpError.js';
|
|
23
24
|
import '../services/common/appError.js';
|
|
24
25
|
import '../services/http/responsesBuilder.js';
|
|
25
26
|
import '../services/common/sendFile.js';
|
|
26
|
-
import '@homer0/path-utils';
|
|
27
27
|
import '../services/html/htmlGenerator.js';
|
|
28
28
|
import '../services/frontend/frontendFs.js';
|
|
29
29
|
import 'fs/promises';
|
|
@@ -18,4 +18,10 @@ module.exports = __toCommonJS(middlewares_exports);
|
|
|
18
18
|
__reExport(middlewares_exports, require("./common"), module.exports);
|
|
19
19
|
__reExport(middlewares_exports, require("./html"), module.exports);
|
|
20
20
|
__reExport(middlewares_exports, require("./utils"), module.exports);
|
|
21
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
22
|
+
0 && (module.exports = {
|
|
23
|
+
...require("./common"),
|
|
24
|
+
...require("./html"),
|
|
25
|
+
...require("./utils")
|
|
26
|
+
});
|
|
21
27
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export { VersionValidator, VersionValidatorConstructorOptions, VersionValidatorLatestOptions, VersionValidatorMiddlewareOptions, VersionValidatorOptions, VersionValidatorPartialOptions, VersionValidatorPopupOptions, versionValidatorMiddleware } from './versionValidator.mjs';
|
|
2
|
+
import '@homer0/jimple';
|
|
3
|
+
import '../../utils/fns/statuses.mjs';
|
|
4
|
+
import 'statuses';
|
|
5
|
+
import '../../index-Bwf7JHu9.mjs';
|
|
6
|
+
import '../../types/express.mjs';
|
|
7
|
+
import 'express';
|
|
8
|
+
import '../../types/http.mjs';
|
|
9
|
+
import 'https';
|
|
10
|
+
import 'http';
|
|
11
|
+
import 'spdy';
|
|
12
|
+
import 'node-fetch';
|
|
13
|
+
import '../../types/utils.mjs';
|
|
14
|
+
import '@homer0/path-utils';
|
|
15
|
+
import '@homer0/simple-logger';
|
|
16
|
+
import '@homer0/simple-config';
|
|
17
|
+
import '@homer0/events-hub';
|
|
18
|
+
import '../../services/common/httpError.mjs';
|
|
19
|
+
import '../../services/common/appError.mjs';
|
|
20
|
+
import '../../services/http/responsesBuilder.mjs';
|
|
@@ -2,8 +2,7 @@ export { VersionValidator, VersionValidatorConstructorOptions, VersionValidatorL
|
|
|
2
2
|
import '@homer0/jimple';
|
|
3
3
|
import '../../utils/fns/statuses.js';
|
|
4
4
|
import 'statuses';
|
|
5
|
-
import '../../
|
|
6
|
-
import '@homer0/events-hub';
|
|
5
|
+
import '../../index-C6I3NCC-.js';
|
|
7
6
|
import '../../types/express.js';
|
|
8
7
|
import 'express';
|
|
9
8
|
import '../../types/http.js';
|
|
@@ -11,9 +10,11 @@ import 'https';
|
|
|
11
10
|
import 'http';
|
|
12
11
|
import 'spdy';
|
|
13
12
|
import 'node-fetch';
|
|
14
|
-
import '@homer0/simple-config';
|
|
15
13
|
import '../../types/utils.js';
|
|
14
|
+
import '@homer0/path-utils';
|
|
16
15
|
import '@homer0/simple-logger';
|
|
16
|
+
import '@homer0/simple-config';
|
|
17
|
+
import '@homer0/events-hub';
|
|
17
18
|
import '../../services/common/httpError.js';
|
|
18
19
|
import '../../services/common/appError.js';
|
|
19
20
|
import '../../services/http/responsesBuilder.js';
|
|
@@ -16,4 +16,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
16
16
|
var utils_exports = {};
|
|
17
17
|
module.exports = __toCommonJS(utils_exports);
|
|
18
18
|
__reExport(utils_exports, require("./versionValidator"), module.exports);
|
|
19
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
20
|
+
0 && (module.exports = {
|
|
21
|
+
...require("./versionValidator")
|
|
22
|
+
});
|
|
19
23
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import * as _homer0_jimple from '@homer0/jimple';
|
|
2
|
+
import { Statuses } from '../../utils/fns/statuses.mjs';
|
|
3
|
+
import { J as Jimpex, R as MiddlewareConnectFn } from '../../index-Bwf7JHu9.mjs';
|
|
4
|
+
import { ExpressMiddleware } from '../../types/express.mjs';
|
|
5
|
+
import { DeepPartial } from '../../types/utils.mjs';
|
|
6
|
+
import { HTTPErrorClass } from '../../services/common/httpError.mjs';
|
|
7
|
+
import { ResponsesBuilder } from '../../services/http/responsesBuilder.mjs';
|
|
8
|
+
import { Request } from 'express';
|
|
9
|
+
import 'statuses';
|
|
10
|
+
import '../../types/http.mjs';
|
|
11
|
+
import 'https';
|
|
12
|
+
import 'http';
|
|
13
|
+
import 'spdy';
|
|
14
|
+
import 'node-fetch';
|
|
15
|
+
import '@homer0/path-utils';
|
|
16
|
+
import '@homer0/simple-logger';
|
|
17
|
+
import '@homer0/simple-config';
|
|
18
|
+
import '@homer0/events-hub';
|
|
19
|
+
import '../../services/common/appError.mjs';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The options for how the middleware should behave if the requested version is `latest`.
|
|
23
|
+
*
|
|
24
|
+
* @group Middlewares/VersionValidator
|
|
25
|
+
*/
|
|
26
|
+
type VersionValidatorLatestOptions = {
|
|
27
|
+
/**
|
|
28
|
+
* Whether or not the middleware should validate the _"latest version"_.
|
|
29
|
+
*
|
|
30
|
+
* @default true
|
|
31
|
+
*/
|
|
32
|
+
allow: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* The name of the _"latest version"_. Basically, `req.params.version` must match with
|
|
35
|
+
* this property in order to be consider "latest".
|
|
36
|
+
*
|
|
37
|
+
* @default 'latest'
|
|
38
|
+
*/
|
|
39
|
+
name: string;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* The options for how to detect if the request comes from a popup and how to compose the
|
|
43
|
+
* post message the middleware will use to respond.
|
|
44
|
+
*
|
|
45
|
+
* @group Middlewares/VersionValidator
|
|
46
|
+
*/
|
|
47
|
+
type VersionValidatorPopupOptions = {
|
|
48
|
+
/**
|
|
49
|
+
* The name of the query string variable the middleware will check in order to indentify
|
|
50
|
+
* whether the request comes from a popup or not. The variable must have `'true'` as its
|
|
51
|
+
* value.
|
|
52
|
+
*
|
|
53
|
+
* @default 'popup'
|
|
54
|
+
*/
|
|
55
|
+
variable: string;
|
|
56
|
+
/**
|
|
57
|
+
* The title of the page that will be generated to respond in case the versions don't
|
|
58
|
+
* match.
|
|
59
|
+
*
|
|
60
|
+
* @default 'Conflict'
|
|
61
|
+
*/
|
|
62
|
+
title: string;
|
|
63
|
+
/**
|
|
64
|
+
* The contents of the post message the generated page will send if the versions don't
|
|
65
|
+
* match.
|
|
66
|
+
*
|
|
67
|
+
* @default 'version:conflict'
|
|
68
|
+
*/
|
|
69
|
+
message: string;
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* The options used to customize a {@link VersionValidator} instance.
|
|
73
|
+
*
|
|
74
|
+
* @group Middlewares/VersionValidator
|
|
75
|
+
*/
|
|
76
|
+
type VersionValidatorOptions = {
|
|
77
|
+
/**
|
|
78
|
+
* The version used to validate the requests.
|
|
79
|
+
*/
|
|
80
|
+
version: string;
|
|
81
|
+
/**
|
|
82
|
+
* The options for how the middleware should behave if the requested version is
|
|
83
|
+
* `latest`.
|
|
84
|
+
*/
|
|
85
|
+
latest: VersionValidatorLatestOptions;
|
|
86
|
+
/**
|
|
87
|
+
* The options for how to detect if the request comes from a popup and how to compose
|
|
88
|
+
* the post message the middleware will use to respond.
|
|
89
|
+
*/
|
|
90
|
+
popup: VersionValidatorPopupOptions;
|
|
91
|
+
/**
|
|
92
|
+
* The error message to show when the version is invalid.
|
|
93
|
+
*
|
|
94
|
+
* @default "The application version doesn't match"
|
|
95
|
+
* @prettierignore
|
|
96
|
+
*/
|
|
97
|
+
error: string;
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* A partial version of the {@link VersionValidatorOptions}, to be used in the constructor
|
|
101
|
+
* and the middleware creator. The reason it omits `version` it's because for the
|
|
102
|
+
* constructor it's required, but for the middleware creator it's not.
|
|
103
|
+
*
|
|
104
|
+
* @group Middlewares/VersionValidator
|
|
105
|
+
*/
|
|
106
|
+
type VersionValidatorPartialOptions = DeepPartial<Omit<VersionValidatorOptions, 'version'>>;
|
|
107
|
+
/**
|
|
108
|
+
* The options to construct a {@link VersionValidator}.
|
|
109
|
+
*
|
|
110
|
+
* @group Middlewares/VersionValidator
|
|
111
|
+
*/
|
|
112
|
+
type VersionValidatorConstructorOptions = VersionValidatorPartialOptions & {
|
|
113
|
+
/**
|
|
114
|
+
* The version used to validate the requests.
|
|
115
|
+
*/
|
|
116
|
+
version: string;
|
|
117
|
+
/**
|
|
118
|
+
* A dictionary with the dependencies to inject.
|
|
119
|
+
*/
|
|
120
|
+
inject: {
|
|
121
|
+
HTTPError: HTTPErrorClass;
|
|
122
|
+
responsesBuilder: ResponsesBuilder;
|
|
123
|
+
statuses: Statuses;
|
|
124
|
+
};
|
|
125
|
+
};
|
|
126
|
+
/**
|
|
127
|
+
* The options for the middleware creator that will mount an instance of
|
|
128
|
+
* {@link VersionValidator}.
|
|
129
|
+
*
|
|
130
|
+
* @group Middlewares/VersionValidator
|
|
131
|
+
*/
|
|
132
|
+
type VersionValidatorMiddlewareOptions = VersionValidatorPartialOptions & {
|
|
133
|
+
/**
|
|
134
|
+
* The version used to validate the requests. This is optional in here because if it's
|
|
135
|
+
* not specified, it will be obtained from the configuration service.
|
|
136
|
+
*/
|
|
137
|
+
version?: string;
|
|
138
|
+
};
|
|
139
|
+
/**
|
|
140
|
+
* This is the handler for the middleware/controller that validates the application
|
|
141
|
+
* version.
|
|
142
|
+
* This is useful in cases where you want to restrict the access to specific versions; for
|
|
143
|
+
* example: you have a frontend which needs to be aligned with the "current" version of
|
|
144
|
+
* the application, since the frontend won't realize a new version was released, the
|
|
145
|
+
* validator can be used to let the frontend know.
|
|
146
|
+
* Also, it can be configured to handle requests from popups, in which case, instead of
|
|
147
|
+
* generating an error message, it will send a post message.
|
|
148
|
+
*
|
|
149
|
+
* @group Middleware Classes
|
|
150
|
+
* @group Middlewares/VersionValidator
|
|
151
|
+
* @prettierignore
|
|
152
|
+
*/
|
|
153
|
+
declare class VersionValidator {
|
|
154
|
+
/**
|
|
155
|
+
* To generate the errors in case the validation fails.
|
|
156
|
+
*/
|
|
157
|
+
protected readonly _HTTPError: HTTPErrorClass;
|
|
158
|
+
/**
|
|
159
|
+
* To generate responses for popups.
|
|
160
|
+
*/
|
|
161
|
+
protected readonly _responsesBuilder: ResponsesBuilder;
|
|
162
|
+
/**
|
|
163
|
+
* The uility service to get HTTP status codes.
|
|
164
|
+
*/
|
|
165
|
+
protected readonly _statuses: Statuses;
|
|
166
|
+
/**
|
|
167
|
+
* The customization options.
|
|
168
|
+
*/
|
|
169
|
+
protected readonly _options: VersionValidatorOptions;
|
|
170
|
+
/**
|
|
171
|
+
* @param options The options to construct the class.
|
|
172
|
+
* @throws If no `version` is specified in the options.
|
|
173
|
+
*/
|
|
174
|
+
constructor({ inject, version, ...options }: VersionValidatorConstructorOptions);
|
|
175
|
+
/**
|
|
176
|
+
* Generates the middleware that validates the version.
|
|
177
|
+
*/
|
|
178
|
+
getMiddleware(): ExpressMiddleware;
|
|
179
|
+
/**
|
|
180
|
+
* The customization options.
|
|
181
|
+
*/
|
|
182
|
+
get options(): Readonly<VersionValidatorOptions>;
|
|
183
|
+
/**
|
|
184
|
+
* Helper method that checks if the incoming request is from a popup. It will look for
|
|
185
|
+
* the query string variable defined in the constructor options.
|
|
186
|
+
*
|
|
187
|
+
* @param req The request object sent by the application.
|
|
188
|
+
*/
|
|
189
|
+
protected _isPopup(req: Request): boolean;
|
|
190
|
+
/**
|
|
191
|
+
* Helper method that checks if the "latest version" is enabled and if the given version
|
|
192
|
+
* is "the latest" (comparing it with the option name).
|
|
193
|
+
*
|
|
194
|
+
* @param version The version received in the request.
|
|
195
|
+
*/
|
|
196
|
+
protected _isTheAllowedLatest(version: string): boolean;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* A middleware that will validate a `version` request parameter against the application
|
|
200
|
+
* version, and generate an error if they don't match.
|
|
201
|
+
* This is a "middleware/controller" because the wrappers for both are the same, the
|
|
202
|
+
* difference is that, for controllers, Jimpex sends a second parameter with the route
|
|
203
|
+
* where they are mounted.
|
|
204
|
+
* By validating the route parameter, the function can know whether the implementation is
|
|
205
|
+
* going to use the middleware by itself or as a route middleware.
|
|
206
|
+
* If used as middleware, it will just return the result of
|
|
207
|
+
* {@link VersionValidator.getMiddleware}; but if used as controller, it will mount it on
|
|
208
|
+
* `[route]/:version/*`.
|
|
209
|
+
*
|
|
210
|
+
* @group Middlewares
|
|
211
|
+
* @group Middlewares/VersionValidator
|
|
212
|
+
*/
|
|
213
|
+
declare const versionValidatorMiddleware: _homer0_jimple.ResourceCreator<"middleware", "connect", (options?: VersionValidatorMiddlewareOptions) => <ContainerType extends Jimpex = Jimpex>(app: ContainerType, route: string | undefined) => ExpressMiddleware, MiddlewareConnectFn>;
|
|
214
|
+
|
|
215
|
+
export { VersionValidator, type VersionValidatorConstructorOptions, type VersionValidatorLatestOptions, type VersionValidatorMiddlewareOptions, type VersionValidatorOptions, type VersionValidatorPartialOptions, type VersionValidatorPopupOptions, versionValidatorMiddleware };
|
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
import * as _homer0_jimple from '@homer0/jimple';
|
|
2
2
|
import { Statuses } from '../../utils/fns/statuses.js';
|
|
3
|
-
import { J as Jimpex, R as MiddlewareConnectFn } from '../../
|
|
3
|
+
import { J as Jimpex, R as MiddlewareConnectFn } from '../../index-C6I3NCC-.js';
|
|
4
4
|
import { ExpressMiddleware } from '../../types/express.js';
|
|
5
5
|
import { DeepPartial } from '../../types/utils.js';
|
|
6
6
|
import { HTTPErrorClass } from '../../services/common/httpError.js';
|
|
7
7
|
import { ResponsesBuilder } from '../../services/http/responsesBuilder.js';
|
|
8
8
|
import { Request } from 'express';
|
|
9
9
|
import 'statuses';
|
|
10
|
-
import '@homer0/events-hub';
|
|
11
10
|
import '../../types/http.js';
|
|
12
11
|
import 'https';
|
|
13
12
|
import 'http';
|
|
14
13
|
import 'spdy';
|
|
15
14
|
import 'node-fetch';
|
|
16
|
-
import '@homer0/
|
|
15
|
+
import '@homer0/path-utils';
|
|
17
16
|
import '@homer0/simple-logger';
|
|
17
|
+
import '@homer0/simple-config';
|
|
18
|
+
import '@homer0/events-hub';
|
|
18
19
|
import '../../services/common/appError.js';
|
|
19
20
|
|
|
20
21
|
/**
|
|
@@ -211,4 +212,4 @@ declare class VersionValidator {
|
|
|
211
212
|
*/
|
|
212
213
|
declare const versionValidatorMiddleware: _homer0_jimple.ResourceCreator<"middleware", "connect", (options?: VersionValidatorMiddlewareOptions) => <ContainerType extends Jimpex = Jimpex>(app: ContainerType, route: string | undefined) => ExpressMiddleware, MiddlewareConnectFn>;
|
|
213
214
|
|
|
214
|
-
export { VersionValidator, VersionValidatorConstructorOptions, VersionValidatorLatestOptions, VersionValidatorMiddlewareOptions, VersionValidatorOptions, VersionValidatorPartialOptions, VersionValidatorPopupOptions, versionValidatorMiddleware };
|
|
215
|
+
export { VersionValidator, type VersionValidatorConstructorOptions, type VersionValidatorLatestOptions, type VersionValidatorMiddlewareOptions, type VersionValidatorOptions, type VersionValidatorPartialOptions, type VersionValidatorPopupOptions, versionValidatorMiddleware };
|