@pxp-nd/core 1.2.74 → 1.2.75
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/README.md +1 -1
- package/dist/PxpApp.d.ts +54 -54
- package/dist/PxpApp.js +283 -284
- package/dist/ScriptManager.d.ts +1 -1
- package/dist/ScriptManager.js +130 -130
- package/dist/database/script.d.ts +16 -16
- package/dist/database/script.js +143 -143
- package/dist/db.datasource.d.ts +2 -2
- package/dist/db.datasource.js +86 -86
- package/dist/entities/Log.d.ts +32 -32
- package/dist/entities/Log.js +95 -95
- package/dist/entities/ScriptVersion.d.ts +19 -19
- package/dist/entities/ScriptVersion.js +43 -43
- package/dist/index.d.ts +11 -11
- package/dist/index.js +28 -28
- package/dist/interfaces.d.ts +49 -49
- package/dist/interfaces.js +3 -3
- package/dist/lib/pxp/Controller.d.ts +51 -51
- package/dist/lib/pxp/Controller.js +377 -377
- package/dist/lib/pxp/ControllerInterface.d.ts +18 -18
- package/dist/lib/pxp/ControllerInterface.js +2 -2
- package/dist/lib/pxp/Decorators.d.ts +23 -23
- package/dist/lib/pxp/Decorators.js +123 -123
- package/dist/lib/pxp/ListParamInterface.d.ts +23 -23
- package/dist/lib/pxp/ListParamInterface.js +2 -2
- package/dist/lib/pxp/PxpError.d.ts +24 -24
- package/dist/lib/pxp/PxpError.js +57 -57
- package/dist/lib/pxp/RouteDefinition.d.ts +26 -26
- package/dist/lib/pxp/RouteDefinition.js +26 -26
- package/dist/lib/pxp/index.d.ts +20 -20
- package/dist/lib/pxp/index.js +33 -33
- package/dist/lib/pxp/loadControllers.d.ts +4 -4
- package/dist/lib/pxp/loadControllers.js +89 -89
- package/dist/lib/pxp/middlewares/ParseParams.d.ts +4 -4
- package/dist/lib/pxp/middlewares/ParseParams.js +71 -71
- package/dist/lib/pxp/middlewares/isReportMiddleware.d.ts +2 -2
- package/dist/lib/pxp/middlewares/isReportMiddleware.js +13 -13
- package/dist/lib/pxp/utils/Security.d.ts +23 -23
- package/dist/lib/pxp/utils/Security.js +79 -77
- package/dist/lib/pxp/utils/crypto.d.ts +3 -3
- package/dist/lib/pxp/utils/crypto.js +15 -15
- package/dist/lib/reports/fonts/Roboto-Regular-normal.d.ts +2 -2
- package/dist/lib/reports/fonts/Roboto-Regular-normal.js +4 -4
- package/dist/lib/reports/generated.d.ts +4 -4
- package/dist/lib/reports/generated.js +200 -200
- package/dist/lib/reports/helper.d.ts +8 -8
- package/dist/lib/reports/helper.js +49 -49
- package/dist/lib/reports/pdf.d.ts +3 -3
- package/dist/lib/reports/pdf.js +119 -119
- package/dist/lib/reports/report-routes.d.ts +3 -3
- package/dist/lib/reports/report-routes.js +24 -24
- package/dist/lib/reports/xlsx.d.ts +1 -1
- package/dist/lib/reports/xlsx.js +65 -65
- package/dist/sockets/basic-sockets.d.ts +5 -5
- package/dist/sockets/basic-sockets.js +38 -38
- package/dist/sockets/entities/UserIo.d.ts +6 -6
- package/dist/sockets/entities/UserIo.js +30 -30
- package/dist/sockets/entities/index.d.ts +5 -5
- package/dist/sockets/entities/index.js +9 -9
- package/dist/sockets/index.d.ts +2 -2
- package/dist/sockets/index.js +19 -19
- package/dist/sockets/pxp-io-server.d.ts +6 -6
- package/dist/sockets/pxp-io-server.js +50 -50
- package/dist/swaggerOptions.d.ts +16 -16
- package/dist/swaggerOptions.js +20 -20
- package/package.json +65 -65
- package/yalc.lock +9 -9
package/dist/PxpApp.js
CHANGED
|
@@ -1,284 +1,283 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Kplian Ltda 2020
|
|
4
|
-
*
|
|
5
|
-
* MIT
|
|
6
|
-
*
|
|
7
|
-
* Main pxp-nd file.
|
|
8
|
-
*
|
|
9
|
-
* @summary Handles all requests for pxp-ui or pxp-nd.
|
|
10
|
-
* @author Jaime Rivera
|
|
11
|
-
*
|
|
12
|
-
* Created at : 2020-06-13 18:09:48
|
|
13
|
-
* Last modified : 2020-09-20 18:24:45
|
|
14
|
-
*/
|
|
15
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
16
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
17
|
-
};
|
|
18
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
-
exports.PxpApp = void 0;
|
|
20
|
-
require("reflect-metadata");
|
|
21
|
-
const typeorm_1 = require("typeorm");
|
|
22
|
-
const express_fileupload_1 = __importDefault(require("express-fileupload"));
|
|
23
|
-
const express_1 = __importDefault(require("express"));
|
|
24
|
-
const passport_1 = __importDefault(require("passport"));
|
|
25
|
-
const express_session_1 = __importDefault(require("express-session"));
|
|
26
|
-
const typeorm_2 = require("typeorm");
|
|
27
|
-
const cors_1 = __importDefault(require("cors"));
|
|
28
|
-
const fs_1 = __importDefault(require("fs"));
|
|
29
|
-
const path_1 = __importDefault(require("path"));
|
|
30
|
-
const http_1 = __importDefault(require("http"));
|
|
31
|
-
/** swagger options **/
|
|
32
|
-
const swagger_ui_express_1 = __importDefault(require("swagger-ui-express"));
|
|
33
|
-
const swagger_jsdoc_1 = __importDefault(require("swagger-jsdoc"));
|
|
34
|
-
const swaggerOptions_1 = __importDefault(require("./swaggerOptions"));
|
|
35
|
-
const loadControllers_1 = __importDefault(require("./lib/pxp/loadControllers"));
|
|
36
|
-
const pxp_1 = require("./lib/pxp");
|
|
37
|
-
// import { getAuthRoutes, customAuthRoutes } from '@pxp-nd/auth';
|
|
38
|
-
// import { configPassport } from '@pxp-nd/auth';
|
|
39
|
-
// import { Session } from '@pxp-nd/entities';
|
|
40
|
-
const typeorm_store_1 = require("typeorm-store");
|
|
41
|
-
const report_routes_1 = require("./lib/reports/report-routes");
|
|
42
|
-
const pxp_io_server_1 = __importDefault(require("./sockets/pxp-io-server"));
|
|
43
|
-
const modulesPxp = {
|
|
44
|
-
auth: '@pxp-nd/auth',
|
|
45
|
-
common: '@pxp-nd/common',
|
|
46
|
-
reports: '@pxp-nd/reports',
|
|
47
|
-
};
|
|
48
|
-
//auth configure
|
|
49
|
-
/**
|
|
50
|
-
*
|
|
51
|
-
* */
|
|
52
|
-
class PxpApp {
|
|
53
|
-
constructor(config) {
|
|
54
|
-
this.configAuth = null;
|
|
55
|
-
this.Report = null;
|
|
56
|
-
this.ReportGroup = null;
|
|
57
|
-
this.sockets = {};
|
|
58
|
-
this.config = {
|
|
59
|
-
defaultDbSettings: 'Orm',
|
|
60
|
-
apiPrefix: '/api',
|
|
61
|
-
logDuration: true,
|
|
62
|
-
middlewares: [],
|
|
63
|
-
};
|
|
64
|
-
this.getDurationInMilliseconds = (start) => {
|
|
65
|
-
const NS_PER_SEC = 1e9;
|
|
66
|
-
const NS_TO_MS = 1e6;
|
|
67
|
-
const diff = process.hrtime(start);
|
|
68
|
-
return (diff[0] * NS_PER_SEC + diff[1]) / NS_TO_MS;
|
|
69
|
-
};
|
|
70
|
-
this.folderModulesCreate();
|
|
71
|
-
this.config = Object.assign(Object.assign({}, this.config), config);
|
|
72
|
-
this.app = express_1.default();
|
|
73
|
-
this.controllers = [];
|
|
74
|
-
// this.initializeMiddlewares();
|
|
75
|
-
}
|
|
76
|
-
static get instance() {
|
|
77
|
-
return this._instance || (this._instance = new this(null));
|
|
78
|
-
}
|
|
79
|
-
set ConfigAuth(authOptions) {
|
|
80
|
-
this.configAuth = authOptions;
|
|
81
|
-
}
|
|
82
|
-
initializeSwagger() {
|
|
83
|
-
const options = {
|
|
84
|
-
customCss: '.swagger-ui .topbar { display: none }',
|
|
85
|
-
explorer: true,
|
|
86
|
-
};
|
|
87
|
-
const swaggerDocs = swagger_jsdoc_1.default(swaggerOptions_1.default);
|
|
88
|
-
this.app.use('/explorer', swagger_ui_express_1.default.serve, swagger_ui_express_1.default.setup(swaggerDocs, options));
|
|
89
|
-
}
|
|
90
|
-
async loadControllers() {
|
|
91
|
-
// await this.connectToTheDatabase();
|
|
92
|
-
// await this.initializeAuthentication();
|
|
93
|
-
this.controllers = await loadControllers_1.default(this.config, this.io);
|
|
94
|
-
this.initializeRoutes();
|
|
95
|
-
this.initializeErrorHandling();
|
|
96
|
-
}
|
|
97
|
-
loadIOserver() {
|
|
98
|
-
this._httpServer = new http_1.default.Server(this.app);
|
|
99
|
-
if (this.config.enableSocket) {
|
|
100
|
-
this.io = new pxp_io_server_1.default(this._httpServer, this.sockets).io;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
listen() {
|
|
104
|
-
this._httpServer.listen(process.env.PORT, () => {
|
|
105
|
-
console.log(`${'\x1b[36m'}App listening on the port ${process.env.PORT}${'\x1b[0m'}`);
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
getServer() {
|
|
109
|
-
return this.app;
|
|
110
|
-
}
|
|
111
|
-
initializeMiddlewares() {
|
|
112
|
-
this.app.use((req, res, next) => {
|
|
113
|
-
req.start = new Date();
|
|
114
|
-
if (this.config.logDuration) {
|
|
115
|
-
console.log(`${req.method} ${req.originalUrl} [STARTED]`);
|
|
116
|
-
const start = process.hrtime();
|
|
117
|
-
res.on('finish', () => {
|
|
118
|
-
const durationInMilliseconds = this.getDurationInMilliseconds(start);
|
|
119
|
-
console.log(`${req.method} ${req.originalUrl} [FINISHED] ${durationInMilliseconds.toLocaleString()} ms`);
|
|
120
|
-
});
|
|
121
|
-
res.on('close', () => {
|
|
122
|
-
const durationInMilliseconds = this.getDurationInMilliseconds(start);
|
|
123
|
-
console.log(`${req.method} ${req.originalUrl} [CLOSED] ${durationInMilliseconds.toLocaleString()} ms`);
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
next();
|
|
127
|
-
});
|
|
128
|
-
this.app.use(express_1.default.json(
|
|
129
|
-
this.app.use(express_1.default.urlencoded({
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
this.
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
\
|
|
145
|
-
\
|
|
146
|
-
\
|
|
147
|
-
\
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
this.app.use(
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
this.
|
|
183
|
-
this.
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
\
|
|
188
|
-
\
|
|
189
|
-
\
|
|
190
|
-
\tthis.
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
this.
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
const
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
this.app.
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
//
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
this.
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
this.
|
|
262
|
-
this.
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
const
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
exports.PxpApp = PxpApp;
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Kplian Ltda 2020
|
|
4
|
+
*
|
|
5
|
+
* MIT
|
|
6
|
+
*
|
|
7
|
+
* Main pxp-nd file.
|
|
8
|
+
*
|
|
9
|
+
* @summary Handles all requests for pxp-ui or pxp-nd.
|
|
10
|
+
* @author Jaime Rivera
|
|
11
|
+
*
|
|
12
|
+
* Created at : 2020-06-13 18:09:48
|
|
13
|
+
* Last modified : 2020-09-20 18:24:45
|
|
14
|
+
*/
|
|
15
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
16
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
17
|
+
};
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.PxpApp = void 0;
|
|
20
|
+
require("reflect-metadata");
|
|
21
|
+
const typeorm_1 = require("typeorm");
|
|
22
|
+
const express_fileupload_1 = __importDefault(require("express-fileupload"));
|
|
23
|
+
const express_1 = __importDefault(require("express"));
|
|
24
|
+
const passport_1 = __importDefault(require("passport"));
|
|
25
|
+
const express_session_1 = __importDefault(require("express-session"));
|
|
26
|
+
const typeorm_2 = require("typeorm");
|
|
27
|
+
const cors_1 = __importDefault(require("cors"));
|
|
28
|
+
const fs_1 = __importDefault(require("fs"));
|
|
29
|
+
const path_1 = __importDefault(require("path"));
|
|
30
|
+
const http_1 = __importDefault(require("http"));
|
|
31
|
+
/** swagger options **/
|
|
32
|
+
const swagger_ui_express_1 = __importDefault(require("swagger-ui-express"));
|
|
33
|
+
const swagger_jsdoc_1 = __importDefault(require("swagger-jsdoc"));
|
|
34
|
+
const swaggerOptions_1 = __importDefault(require("./swaggerOptions"));
|
|
35
|
+
const loadControllers_1 = __importDefault(require("./lib/pxp/loadControllers"));
|
|
36
|
+
const pxp_1 = require("./lib/pxp");
|
|
37
|
+
// import { getAuthRoutes, customAuthRoutes } from '@pxp-nd/auth';
|
|
38
|
+
// import { configPassport } from '@pxp-nd/auth';
|
|
39
|
+
// import { Session } from '@pxp-nd/entities';
|
|
40
|
+
const typeorm_store_1 = require("typeorm-store");
|
|
41
|
+
const report_routes_1 = require("./lib/reports/report-routes");
|
|
42
|
+
const pxp_io_server_1 = __importDefault(require("./sockets/pxp-io-server"));
|
|
43
|
+
const modulesPxp = {
|
|
44
|
+
auth: '@pxp-nd/auth',
|
|
45
|
+
common: '@pxp-nd/common',
|
|
46
|
+
reports: '@pxp-nd/reports',
|
|
47
|
+
};
|
|
48
|
+
//auth configure
|
|
49
|
+
/**
|
|
50
|
+
*
|
|
51
|
+
* */
|
|
52
|
+
class PxpApp {
|
|
53
|
+
constructor(config) {
|
|
54
|
+
this.configAuth = null;
|
|
55
|
+
this.Report = null;
|
|
56
|
+
this.ReportGroup = null;
|
|
57
|
+
this.sockets = {};
|
|
58
|
+
this.config = {
|
|
59
|
+
defaultDbSettings: 'Orm',
|
|
60
|
+
apiPrefix: '/api',
|
|
61
|
+
logDuration: true,
|
|
62
|
+
middlewares: [],
|
|
63
|
+
};
|
|
64
|
+
this.getDurationInMilliseconds = (start) => {
|
|
65
|
+
const NS_PER_SEC = 1e9;
|
|
66
|
+
const NS_TO_MS = 1e6;
|
|
67
|
+
const diff = process.hrtime(start);
|
|
68
|
+
return (diff[0] * NS_PER_SEC + diff[1]) / NS_TO_MS;
|
|
69
|
+
};
|
|
70
|
+
this.folderModulesCreate();
|
|
71
|
+
this.config = Object.assign(Object.assign({}, this.config), config);
|
|
72
|
+
this.app = express_1.default();
|
|
73
|
+
this.controllers = [];
|
|
74
|
+
// this.initializeMiddlewares();
|
|
75
|
+
}
|
|
76
|
+
static get instance() {
|
|
77
|
+
return this._instance || (this._instance = new this(null));
|
|
78
|
+
}
|
|
79
|
+
set ConfigAuth(authOptions) {
|
|
80
|
+
this.configAuth = authOptions;
|
|
81
|
+
}
|
|
82
|
+
initializeSwagger() {
|
|
83
|
+
const options = {
|
|
84
|
+
customCss: '.swagger-ui .topbar { display: none }',
|
|
85
|
+
explorer: true,
|
|
86
|
+
};
|
|
87
|
+
const swaggerDocs = swagger_jsdoc_1.default(swaggerOptions_1.default);
|
|
88
|
+
this.app.use('/explorer', swagger_ui_express_1.default.serve, swagger_ui_express_1.default.setup(swaggerDocs, options));
|
|
89
|
+
}
|
|
90
|
+
async loadControllers() {
|
|
91
|
+
// await this.connectToTheDatabase();
|
|
92
|
+
// await this.initializeAuthentication();
|
|
93
|
+
this.controllers = await loadControllers_1.default(this.config, this.io);
|
|
94
|
+
this.initializeRoutes();
|
|
95
|
+
this.initializeErrorHandling();
|
|
96
|
+
}
|
|
97
|
+
loadIOserver() {
|
|
98
|
+
this._httpServer = new http_1.default.Server(this.app);
|
|
99
|
+
if (this.config.enableSocket) {
|
|
100
|
+
this.io = new pxp_io_server_1.default(this._httpServer, this.sockets).io;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
listen() {
|
|
104
|
+
this._httpServer.listen(process.env.PORT, () => {
|
|
105
|
+
console.log(`${'\x1b[36m'}App listening on the port ${process.env.PORT}${'\x1b[0m'}`);
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
getServer() {
|
|
109
|
+
return this.app;
|
|
110
|
+
}
|
|
111
|
+
initializeMiddlewares() {
|
|
112
|
+
this.app.use((req, res, next) => {
|
|
113
|
+
req.start = new Date();
|
|
114
|
+
if (this.config.logDuration) {
|
|
115
|
+
console.log(`${req.method} ${req.originalUrl} [STARTED]`);
|
|
116
|
+
const start = process.hrtime();
|
|
117
|
+
res.on('finish', () => {
|
|
118
|
+
const durationInMilliseconds = this.getDurationInMilliseconds(start);
|
|
119
|
+
console.log(`${req.method} ${req.originalUrl} [FINISHED] ${durationInMilliseconds.toLocaleString()} ms`);
|
|
120
|
+
});
|
|
121
|
+
res.on('close', () => {
|
|
122
|
+
const durationInMilliseconds = this.getDurationInMilliseconds(start);
|
|
123
|
+
console.log(`${req.method} ${req.originalUrl} [CLOSED] ${durationInMilliseconds.toLocaleString()} ms`);
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
next();
|
|
127
|
+
});
|
|
128
|
+
this.app.use(express_1.default.json());
|
|
129
|
+
this.app.use(express_1.default.urlencoded({ extended: false }));
|
|
130
|
+
this.app.use(express_fileupload_1.default({
|
|
131
|
+
limits: { fileSize: 5 * 1024 * 1024 },
|
|
132
|
+
}));
|
|
133
|
+
this.configCors();
|
|
134
|
+
}
|
|
135
|
+
async initializeAuthentication(configAuth) {
|
|
136
|
+
if (configAuth) {
|
|
137
|
+
const { configPassport, getAuthRoutes, customAuthRoutes } = configAuth();
|
|
138
|
+
this.initializeSession();
|
|
139
|
+
await this.initializePassport(configPassport, getAuthRoutes, customAuthRoutes);
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
throw new Error(`Invalid config Auth, set ConfigAuth:\n
|
|
143
|
+
\t// App.ts file
|
|
144
|
+
\timport { configAuth } from '@pxp-nd/auth';
|
|
145
|
+
\t// In constructror set...
|
|
146
|
+
\tthis.ConfigAuth = configAuth;
|
|
147
|
+
\t//...`);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
initializeErrorHandling() {
|
|
151
|
+
this.app.use(pxp_1.errorMiddleware);
|
|
152
|
+
}
|
|
153
|
+
async initializePassport(configPassport, getAuthRoutes, customAuthRoutes) {
|
|
154
|
+
configPassport(this.config.auth);
|
|
155
|
+
this.app.use(passport_1.default.initialize());
|
|
156
|
+
// @todo only validate session if authorization is not set(10/03/2021)
|
|
157
|
+
this.app.use(passport_1.default.session());
|
|
158
|
+
this.app.use((req, res, next) => {
|
|
159
|
+
if (req.headers.authorization) {
|
|
160
|
+
passport_1.default.authenticate('jwt', { session: false }, function (err, user, info) {
|
|
161
|
+
if (user) {
|
|
162
|
+
req.logIn(user, function (err) {
|
|
163
|
+
next();
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
next();
|
|
168
|
+
}
|
|
169
|
+
})(req, res, next);
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
next();
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
this.app.use((req, res, next) => {
|
|
176
|
+
next();
|
|
177
|
+
});
|
|
178
|
+
const routes = await customAuthRoutes();
|
|
179
|
+
routes.forEach((route) => this.app.use(route.router));
|
|
180
|
+
const authRoutes = getAuthRoutes(this.config.apiPrefix);
|
|
181
|
+
this.showRoutes(authRoutes);
|
|
182
|
+
this.app.use(authRoutes);
|
|
183
|
+
if (this.config.reports) {
|
|
184
|
+
if (!this.Report && !this.ReportGroup) {
|
|
185
|
+
throw new Error(`Invalid Report configuration, set Report and ReportGroup entities:\n
|
|
186
|
+
\t// App.ts file
|
|
187
|
+
\timport { Report, ReportGroup } from '@pxp-nd/common';
|
|
188
|
+
\t//...
|
|
189
|
+
\tthis.Report = Report;
|
|
190
|
+
\tthis.ReportGroup = ReportGroup;
|
|
191
|
+
`);
|
|
192
|
+
}
|
|
193
|
+
const reportRouter = report_routes_1.getReportsRouter(this.config, this.Report, this.ReportGroup);
|
|
194
|
+
this.showRoutes(reportRouter);
|
|
195
|
+
this.app.use(reportRouter);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
configCors() {
|
|
199
|
+
const whitelist = process.env.WHITE_LIST ? String(process.env.WHITE_LIST).split(',') : [];
|
|
200
|
+
const corsOptions = {
|
|
201
|
+
credentials: true,
|
|
202
|
+
origin: function (origin, callback) {
|
|
203
|
+
if (whitelist.indexOf(origin) !== -1 || !origin) {
|
|
204
|
+
callback(null, true);
|
|
205
|
+
}
|
|
206
|
+
else {
|
|
207
|
+
callback(new Error('Not allowed by CORS'));
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
this.app.use(cors_1.default(corsOptions));
|
|
212
|
+
this.app.options('*', cors_1.default());
|
|
213
|
+
}
|
|
214
|
+
initializeSession() {
|
|
215
|
+
const repository = typeorm_2.getConnection().getRepository(this.config.session);
|
|
216
|
+
this.app.use(express_session_1.default({
|
|
217
|
+
secret: String(process.env.SECRET),
|
|
218
|
+
resave: false,
|
|
219
|
+
saveUninitialized: true,
|
|
220
|
+
store: new typeorm_store_1.TypeormStore({ repository }),
|
|
221
|
+
cookie: {
|
|
222
|
+
maxAge: 1000 * 60 * 60 * 168
|
|
223
|
+
// 24 = 1 day <=> 168 = 7 days
|
|
224
|
+
// Equals 1 day (1 day * 24 hr/1 day * 60 min/1 hr * 60 sec/1 min * 1000 ms / 1 sec)
|
|
225
|
+
}
|
|
226
|
+
}));
|
|
227
|
+
}
|
|
228
|
+
initializeRoutes() {
|
|
229
|
+
this.controllers.forEach((controller) => {
|
|
230
|
+
this.app.use(controller.router);
|
|
231
|
+
this.showRoutes(controller.router);
|
|
232
|
+
});
|
|
233
|
+
this.app.all('*', function (req, res) {
|
|
234
|
+
res.status(404).json({
|
|
235
|
+
error: {
|
|
236
|
+
code: 404,
|
|
237
|
+
message: 'Route not found'
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
// Show routes with config.showRoutes is true
|
|
243
|
+
showRoutes(router) {
|
|
244
|
+
const routes = router.stack.filter((r) => r.route)
|
|
245
|
+
.map((r) => {
|
|
246
|
+
return {
|
|
247
|
+
method: Object.keys(r.route.methods)[0].toUpperCase(),
|
|
248
|
+
path: r.route.path
|
|
249
|
+
};
|
|
250
|
+
});
|
|
251
|
+
if (this.config.showRoutes) {
|
|
252
|
+
routes.forEach((route) => console.log(`${'\x1b[31m'}${route.method.toUpperCase()}:\t${'\x1b[32m'}${route.path}${'\x1b[0m'}`));
|
|
253
|
+
console.log('');
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
async connectDatabase() {
|
|
257
|
+
await typeorm_1.createConnections();
|
|
258
|
+
}
|
|
259
|
+
async run() {
|
|
260
|
+
this.initializeSwagger();
|
|
261
|
+
this.initializeMiddlewares();
|
|
262
|
+
await this.connectDatabase();
|
|
263
|
+
// configure auth options
|
|
264
|
+
if (this.config.auth) {
|
|
265
|
+
await this.initializeAuthentication(this.configAuth);
|
|
266
|
+
}
|
|
267
|
+
// load ioServer
|
|
268
|
+
this.loadIOserver();
|
|
269
|
+
// load controllers and routes
|
|
270
|
+
await this.loadControllers();
|
|
271
|
+
}
|
|
272
|
+
folderModulesCreate() {
|
|
273
|
+
const dirModules = path_1.default.join(process.cwd(), 'dist/modules');
|
|
274
|
+
const dirModulesSrc = path_1.default.join(process.cwd(), 'src/modules');
|
|
275
|
+
if (!fs_1.default.existsSync(dirModules)) {
|
|
276
|
+
fs_1.default.mkdirSync(dirModules, '0744');
|
|
277
|
+
}
|
|
278
|
+
if (!fs_1.default.existsSync(dirModulesSrc)) {
|
|
279
|
+
fs_1.default.mkdirSync(dirModulesSrc, '0744');
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
exports.PxpApp = PxpApp;
|
package/dist/ScriptManager.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import 'reflect-metadata';
|
|
1
|
+
import 'reflect-metadata';
|