@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 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
- if (!(route.methodName in readonly)) {
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
- if (route.methodName in authentication &&
143
- authentication[route.methodName] === false) {
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, readonly[route.methodName], false, log[route.methodName], logConfig[route.methodName]));
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, readonly[route.methodName], permission[route.methodName], log[route.methodName], logConfig[route.methodName]));
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
- const setProperty = (target, propertyKey) => (value, name) => {
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] = value;
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
- readOnly: true,
29
- dbSettings: 'Orm',
30
- authentication: true,
31
- }) => (target, propertyKey) => {
32
- const newProperty = setProperty(target, propertyKey);
33
- // ReadOnly
34
- newProperty(options.readOnly, 'readonly');
35
- // DbSettings
36
- newProperty(options.dbSettings, 'dbsettings');
37
- // Authentication
38
- newProperty(options.authentication, 'authentication');
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', [], target.constructor);
110
+ Reflect.defineMetadata('log', {}, target.constructor);
97
111
  }
98
112
  if (!Reflect.hasMetadata('logConfig', target.constructor)) {
99
- Reflect.defineMetadata('logConfig', [], target.constructor);
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.1.20",
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:publish": "yalc publish",
11
- "prod:publish": "npm publish",
12
- "start": "npm run build && node dist/index.js",
13
- "dev": "tsc-watch --target es2017 --outDir ./dist --onSuccess \"node .\"",
14
- "test": "echo \"Error: no test specified\" && exit 1"
15
- },
16
- "keywords": [
17
- "pxp-nd"
18
- ],
19
- "author": "Kplian",
20
- "license": "ISC",
21
- "devDependencies": {
22
- "@types/adm-zip": "^0.4.34",
23
- "@types/chalk": "^2.2.0",
24
- "@types/cors": "^2.8.10",
25
- "@types/crypto-js": "^4.0.1",
26
- "@types/express": "^4.17.11",
27
- "@types/express-fileupload": "^1.1.6",
28
- "@types/express-session": "^1.17.3",
29
- "@types/figlet": "^1.5.1",
30
- "@types/joi": "^17.2.3",
31
- "@types/lodash": "^4.14.170",
32
- "@types/node": "^15.3.1",
33
- "@types/passport": "^1.0.6",
34
- "@types/socket.io": "^3.0.2",
35
- "@types/swagger-jsdoc": "^6.0.1",
36
- "@types/swagger-ui-express": "^4.1.3",
37
- "rimraf": "^3.0.2",
38
- "tsc-watch": "^4.2.9",
39
- "typescript": "^4.2.4"
40
- },
41
- "dependencies": {
42
- "adm-zip": "^0.5.5",
43
- "chalk": "^1.1.3",
44
- "class-validator": "^0.13.1",
45
- "cors": "^2.8.5",
46
- "express": "^4.17.1",
47
- "express-fileupload": "^1.2.1",
48
- "express-session": "^1.17.2",
49
- "figlet": "^1.5.0",
50
- "joi": "^17.4.1",
51
- "jspdf": "^2.3.1",
52
- "jspdf-autotable": "^3.5.14",
53
- "lodash": "^4.17.21",
54
- "moment": "^2.29.1",
55
- "passport": "^0.4.1",
56
- "socket.io": "^4.2.0",
57
- "swagger-jsdoc": "^6.1.0",
58
- "swagger-ui-express": "^4.1.6",
59
- "typeorm": "^0.2.32",
60
- "typeorm-store": "^2.0.0",
61
- "xlsx": "^0.17.0"
62
- },
63
- "peerDependencies": {}
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
  }