@pxp-nd/core 1.1.20 → 1.2.3
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.js +11 -11
- package/dist/lib/pxp/Controller.js +17 -6
- package/dist/lib/pxp/Decorators.d.ts +4 -0
- package/dist/lib/pxp/Decorators.js +30 -16
- package/dist/lib/pxp/middlewares/isReportMiddleware.js +1 -1
- package/dist/sockets/pxp-io-server.js +3 -1
- package/package.json +65 -64
- package/yalc.lock +9 -9
package/README.md
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
# PXP-ND core
|
|
1
|
+
# PXP-ND core
|
|
2
2
|
- Core module for pxp-nd
|
package/dist/PxpApp.js
CHANGED
|
@@ -139,11 +139,11 @@ class PxpApp {
|
|
|
139
139
|
await this.initializePassport(configPassport, getAuthRoutes, customAuthRoutes);
|
|
140
140
|
}
|
|
141
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;
|
|
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
147
|
\t//...`);
|
|
148
148
|
}
|
|
149
149
|
}
|
|
@@ -182,12 +182,12 @@ class PxpApp {
|
|
|
182
182
|
this.app.use(authRoutes);
|
|
183
183
|
if (this.config.reports) {
|
|
184
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;
|
|
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
191
|
`);
|
|
192
192
|
}
|
|
193
193
|
const reportRouter = report_routes_1.getReportsRouter(this.config, this.Report, this.ReportGroup);
|
|
@@ -121,10 +121,12 @@ class Controller {
|
|
|
121
121
|
const permission = Reflect.getMetadata('permission', this.constructor) || {};
|
|
122
122
|
// get log
|
|
123
123
|
const log = Reflect.getMetadata('log', this.constructor) || {};
|
|
124
|
+
console.log('qqqqqqw', log);
|
|
124
125
|
// get dbsettings
|
|
125
126
|
const dbsettings = Reflect.getMetadata('dbsettings', this.constructor) || {};
|
|
126
127
|
// get logConfig
|
|
127
128
|
const logConfig = Reflect.getMetadata('logConfig', this.constructor) || {};
|
|
129
|
+
const defaultConfig = Reflect.getMetadata('optionsRoute', this.constructor) || {};
|
|
128
130
|
// define basic routes
|
|
129
131
|
if (this.modelString !== '') {
|
|
130
132
|
routes = lodash_1.default.union(this.basicRoutes, routes);
|
|
@@ -132,15 +134,22 @@ class Controller {
|
|
|
132
134
|
}
|
|
133
135
|
routes.forEach((route) => {
|
|
134
136
|
const methodDbSettings = dbsettings[route.methodName] || this.config.defaultDbSettings;
|
|
135
|
-
|
|
137
|
+
// readOnly
|
|
138
|
+
const readOnlyMethod = readonly[route.methodName] !== undefined ? readonly[route.methodName] : defaultConfig[route.methodName].readOnly;
|
|
139
|
+
// log
|
|
140
|
+
const logMethod = log[route.methodName] !== undefined ? log[route.methodName] : (defaultConfig[route.methodName] ? defaultConfig[route.methodName].log : true);
|
|
141
|
+
const logValue = typeof logMethod == 'object' ? logMethod : logConfig[route.methodName];
|
|
142
|
+
const logKey = typeof logMethod == 'object' ? true : logMethod;
|
|
143
|
+
if (readOnlyMethod === null || readOnlyMethod === undefined) {
|
|
136
144
|
throw new index_1.PxpError(500, 'ReadOnly decorator was not defined for ' +
|
|
137
145
|
route.methodName +
|
|
138
146
|
' in ' +
|
|
139
147
|
this.constructor.name +
|
|
140
148
|
' controller.');
|
|
141
149
|
}
|
|
142
|
-
|
|
143
|
-
|
|
150
|
+
// auth
|
|
151
|
+
const auth = authentication[route.methodName] !== undefined ? authentication[route.methodName] : (defaultConfig[route.methodName] ? defaultConfig[route.methodName].authentication : true);
|
|
152
|
+
if (!auth) {
|
|
144
153
|
this.router[route.requestMethod](this.config.apiPrefix + '/' + this.module + this.path + route.path,
|
|
145
154
|
// MIDDLEWARES AREA
|
|
146
155
|
[
|
|
@@ -156,7 +165,7 @@ class Controller {
|
|
|
156
165
|
.toLowerCase();
|
|
157
166
|
this.validated = false;
|
|
158
167
|
try {
|
|
159
|
-
await index_1.__(this.genericMethodWrapper(params, req, next, res, route.methodName, methodDbSettings,
|
|
168
|
+
await index_1.__(this.genericMethodWrapper(params, req, next, res, route.methodName, methodDbSettings, readOnlyMethod, false, logKey, logValue));
|
|
160
169
|
}
|
|
161
170
|
catch (ex) {
|
|
162
171
|
const now = new Date();
|
|
@@ -169,6 +178,7 @@ class Controller {
|
|
|
169
178
|
});
|
|
170
179
|
}
|
|
171
180
|
else {
|
|
181
|
+
//NORMALMENTE VIENE POR AQUI RCM-20211011 *****
|
|
172
182
|
this.router[route.requestMethod](this.config.apiPrefix + '/' + this.module + this.path + route.path,
|
|
173
183
|
// MIDDLEWARES AREA
|
|
174
184
|
[
|
|
@@ -189,14 +199,14 @@ class Controller {
|
|
|
189
199
|
.toLowerCase();
|
|
190
200
|
this.validated = false;
|
|
191
201
|
try {
|
|
192
|
-
await index_1.__(this.genericMethodWrapper(params, req, next, res, route.methodName, methodDbSettings,
|
|
202
|
+
await index_1.__(this.genericMethodWrapper(params, req, next, res, route.methodName, methodDbSettings, readOnlyMethod, permission[route.methodName], logKey, logValue));
|
|
193
203
|
}
|
|
194
204
|
catch (ex) {
|
|
195
205
|
const now = new Date();
|
|
196
206
|
const iniAt = req.start;
|
|
197
207
|
const endsAt = now.valueOf() - iniAt.valueOf();
|
|
198
208
|
res.logId = (await index_1.__(index_1.insertLog(this.user && this.user.username ? this.user.username : 'nouser', 'mac', req.ip, 'error', ex.tecMessage, this.module, this.transactionCode, '', // query
|
|
199
|
-
params, ex.stack, ex.statusCode, endsAt, logConfig)));
|
|
209
|
+
params, ex.stack, ex.statusCode, endsAt, Object.assign(Object.assign({}, logConfig), { logValue }))));
|
|
200
210
|
index_1.errorMiddleware(ex, req, res);
|
|
201
211
|
}
|
|
202
212
|
});
|
|
@@ -251,6 +261,7 @@ class Controller {
|
|
|
251
261
|
const endsAt = now.valueOf() - iniAt.valueOf();
|
|
252
262
|
index_1.__(index_1.insertLog(this.user && this.user.username ? this.user.username : 'nouser', 'mac', req.ip, 'success', 'successful transaction', this.module, this.transactionCode, '', params, JSON.stringify(metResponse), '200', endsAt, logConfig));
|
|
253
263
|
}
|
|
264
|
+
//PARA REPORTES
|
|
254
265
|
if (req.report && req.report.type === 'pdf') {
|
|
255
266
|
req.reportData = metResponse;
|
|
256
267
|
pdf_1.makePdf(req, res);
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
+
export declare interface ILog {
|
|
2
|
+
[field: string]: 'cc_mask' | 'complete_mask';
|
|
3
|
+
}
|
|
1
4
|
export declare interface IOptionsRoute {
|
|
2
5
|
readOnly?: boolean;
|
|
3
6
|
dbSettings?: 'Procedure' | 'Orm' | 'Query';
|
|
4
7
|
authentication?: boolean;
|
|
8
|
+
log?: boolean | ILog;
|
|
5
9
|
}
|
|
6
10
|
declare const Get: (path?: string, options?: IOptionsRoute) => (target: any, propertyKey: string) => void;
|
|
7
11
|
declare const Post: (path?: string, options?: IOptionsRoute) => (target: any, propertyKey: string) => void;
|
|
@@ -16,26 +16,40 @@ exports.StoredProcedure = exports.Model = exports.ReadOnly = exports.DbSettings
|
|
|
16
16
|
*/
|
|
17
17
|
const RouteDefinition_1 = require("./RouteDefinition");
|
|
18
18
|
;
|
|
19
|
-
|
|
19
|
+
;
|
|
20
|
+
const setProperty = (target, propertyKey) => (value, name, overwrite = true) => {
|
|
20
21
|
if (!Reflect.hasMetadata(name, target.constructor)) {
|
|
21
22
|
Reflect.defineMetadata(name, {}, target.constructor);
|
|
22
23
|
}
|
|
23
24
|
const valueName = Reflect.getMetadata(name, target.constructor);
|
|
24
|
-
valueName[propertyKey]
|
|
25
|
+
if (!overwrite && !valueName[propertyKey]) {
|
|
26
|
+
valueName[propertyKey] = value;
|
|
27
|
+
}
|
|
28
|
+
else if (overwrite) {
|
|
29
|
+
valueName[propertyKey] = value;
|
|
30
|
+
}
|
|
25
31
|
Reflect.defineMetadata(name, valueName, target.constructor);
|
|
26
32
|
};
|
|
27
|
-
const createOptions = (options
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
newProperty(
|
|
35
|
-
//
|
|
36
|
-
newProperty(options.
|
|
37
|
-
//
|
|
38
|
-
newProperty(options.
|
|
33
|
+
const createOptions = (options) => (target, propertyKey) => {
|
|
34
|
+
options = Object.assign({
|
|
35
|
+
readOnly: true,
|
|
36
|
+
dbSettings: 'Orm',
|
|
37
|
+
authentication: true,
|
|
38
|
+
log: true
|
|
39
|
+
}, options);
|
|
40
|
+
// const newProperty = setProperty(target, propertyKey);
|
|
41
|
+
// // ReadOnly
|
|
42
|
+
// newProperty(options.readOnly, 'readonly', false);
|
|
43
|
+
// // DbSettings
|
|
44
|
+
// newProperty(options.dbSettings, 'dbsettings', false);
|
|
45
|
+
// // Authentication
|
|
46
|
+
// newProperty(options.authentication, 'authentication', false);
|
|
47
|
+
if (!Reflect.hasMetadata('optionsRoute', target.constructor)) {
|
|
48
|
+
Reflect.defineMetadata('optionsRoute', {}, target.constructor);
|
|
49
|
+
}
|
|
50
|
+
const optionsRoute = Reflect.getMetadata('optionsRoute', target.constructor);
|
|
51
|
+
optionsRoute[propertyKey] = options;
|
|
52
|
+
Reflect.defineMetadata('optionsRoute', optionsRoute, target.constructor);
|
|
39
53
|
};
|
|
40
54
|
const setRoute = (path = '', method, options) => (target, propertyKey) => {
|
|
41
55
|
if (!Reflect.hasMetadata('routes', target.constructor)) {
|
|
@@ -93,10 +107,10 @@ exports.Permission = Permission;
|
|
|
93
107
|
const Log = (log = true, config = {}) => {
|
|
94
108
|
return (target, propertyKey) => {
|
|
95
109
|
if (!Reflect.hasMetadata('log', target.constructor)) {
|
|
96
|
-
Reflect.defineMetadata('log',
|
|
110
|
+
Reflect.defineMetadata('log', {}, target.constructor);
|
|
97
111
|
}
|
|
98
112
|
if (!Reflect.hasMetadata('logConfig', target.constructor)) {
|
|
99
|
-
Reflect.defineMetadata('logConfig',
|
|
113
|
+
Reflect.defineMetadata('logConfig', {}, target.constructor);
|
|
100
114
|
}
|
|
101
115
|
const logVar = Reflect.getMetadata('log', target.constructor);
|
|
102
116
|
logVar[propertyKey] = log;
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.isReportMiddleware = void 0;
|
|
4
4
|
const isReportMiddleware = (req, res, next) => {
|
|
5
5
|
if (req.query.report) {
|
|
6
|
-
delete req.query.start;
|
|
6
|
+
delete req.query.start; //TODO 20211011: change for spread operator instead of delete
|
|
7
7
|
delete req.query.limit;
|
|
8
8
|
req.report = JSON.parse(req.query.report);
|
|
9
9
|
delete req.query.report;
|
|
@@ -23,7 +23,9 @@ const socket_io_1 = require("socket.io");
|
|
|
23
23
|
const mainSockets = __importStar(require("./basic-sockets"));
|
|
24
24
|
class PxpIOServer {
|
|
25
25
|
constructor(server, sockets) {
|
|
26
|
-
this.io = new socket_io_1.Server(server
|
|
26
|
+
this.io = new socket_io_1.Server(server, { cors: {
|
|
27
|
+
origin: '*',
|
|
28
|
+
} });
|
|
27
29
|
this.listenSockets(sockets);
|
|
28
30
|
}
|
|
29
31
|
listenSockets(sockets = {}) {
|
package/package.json
CHANGED
|
@@ -1,64 +1,65 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@pxp-nd/core",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "Contains main files for pxp-nd",
|
|
5
|
-
"main": "dist/index.js",
|
|
6
|
-
"types": "dist/index.d.ts",
|
|
7
|
-
"prepublish": "tsc",
|
|
8
|
-
"scripts": {
|
|
9
|
-
"build": "rimraf ./dist && tsc",
|
|
10
|
-
"dev
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
|
|
23
|
-
"@types/
|
|
24
|
-
"@types/
|
|
25
|
-
"@types/
|
|
26
|
-
"@types/
|
|
27
|
-
"@types/express
|
|
28
|
-
"@types/express-
|
|
29
|
-
"@types/
|
|
30
|
-
"@types/
|
|
31
|
-
"@types/
|
|
32
|
-
"@types/
|
|
33
|
-
"@types/
|
|
34
|
-
"@types/
|
|
35
|
-
"@types/
|
|
36
|
-
"@types/swagger-
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"express
|
|
48
|
-
"express-
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"jspdf
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"swagger-
|
|
59
|
-
"
|
|
60
|
-
"typeorm
|
|
61
|
-
"
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@pxp-nd/core",
|
|
3
|
+
"version": "1.2.3",
|
|
4
|
+
"description": "Contains main files for pxp-nd",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"prepublish": "tsc",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "rimraf ./dist && tsc",
|
|
10
|
+
"build-dev": "npm run build && npm run dev:publish",
|
|
11
|
+
"dev:publish": "yalc publish",
|
|
12
|
+
"prod:publish": "npm publish",
|
|
13
|
+
"start": "npm run build && node dist/index.js",
|
|
14
|
+
"dev": "tsc-watch --target es2017 --outDir ./dist --onSuccess \"node .\"",
|
|
15
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"pxp-nd"
|
|
19
|
+
],
|
|
20
|
+
"author": "Kplian",
|
|
21
|
+
"license": "ISC",
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@types/adm-zip": "^0.4.34",
|
|
24
|
+
"@types/chalk": "^2.2.0",
|
|
25
|
+
"@types/cors": "^2.8.10",
|
|
26
|
+
"@types/crypto-js": "^4.0.1",
|
|
27
|
+
"@types/express": "^4.17.11",
|
|
28
|
+
"@types/express-fileupload": "^1.1.6",
|
|
29
|
+
"@types/express-session": "^1.17.3",
|
|
30
|
+
"@types/figlet": "^1.5.1",
|
|
31
|
+
"@types/joi": "^17.2.3",
|
|
32
|
+
"@types/lodash": "^4.14.170",
|
|
33
|
+
"@types/node": "^15.3.1",
|
|
34
|
+
"@types/passport": "^1.0.6",
|
|
35
|
+
"@types/socket.io": "^3.0.2",
|
|
36
|
+
"@types/swagger-jsdoc": "^6.0.1",
|
|
37
|
+
"@types/swagger-ui-express": "^4.1.3",
|
|
38
|
+
"rimraf": "^3.0.2",
|
|
39
|
+
"tsc-watch": "^4.2.9",
|
|
40
|
+
"typescript": "^4.2.4"
|
|
41
|
+
},
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"adm-zip": "^0.5.5",
|
|
44
|
+
"chalk": "^1.1.3",
|
|
45
|
+
"class-validator": "^0.13.1",
|
|
46
|
+
"cors": "^2.8.5",
|
|
47
|
+
"express": "^4.17.1",
|
|
48
|
+
"express-fileupload": "^1.2.1",
|
|
49
|
+
"express-session": "^1.17.2",
|
|
50
|
+
"figlet": "^1.5.0",
|
|
51
|
+
"joi": "^17.4.1",
|
|
52
|
+
"jspdf": "^2.3.1",
|
|
53
|
+
"jspdf-autotable": "^3.5.14",
|
|
54
|
+
"lodash": "^4.17.21",
|
|
55
|
+
"moment": "^2.29.1",
|
|
56
|
+
"passport": "^0.4.1",
|
|
57
|
+
"socket.io": "^4.2.0",
|
|
58
|
+
"swagger-jsdoc": "^6.1.0",
|
|
59
|
+
"swagger-ui-express": "^4.1.6",
|
|
60
|
+
"typeorm": "^0.2.32",
|
|
61
|
+
"typeorm-store": "^2.0.0",
|
|
62
|
+
"xlsx": "^0.17.0"
|
|
63
|
+
},
|
|
64
|
+
"peerDependencies": {}
|
|
65
|
+
}
|
package/yalc.lock
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": "v1",
|
|
3
|
-
"packages": {
|
|
4
|
-
"@pxp-nd/auth": {
|
|
5
|
-
"signature": "c8114cdb0b6ff484731ec780c5ae951e",
|
|
6
|
-
"file": true,
|
|
7
|
-
"replaced": "^1.0.0"
|
|
8
|
-
}
|
|
9
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"version": "v1",
|
|
3
|
+
"packages": {
|
|
4
|
+
"@pxp-nd/auth": {
|
|
5
|
+
"signature": "c8114cdb0b6ff484731ec780c5ae951e",
|
|
6
|
+
"file": true,
|
|
7
|
+
"replaced": "^1.0.0"
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
10
|
}
|