common-rod 1.7.0 → 1.7.2

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/index.js CHANGED
@@ -129,12 +129,23 @@ function _init(callback, commonRodOpt={mongo_create_connect:true, detaillog_add_
129
129
 
130
130
  // Middleware parser
131
131
  let bodyParser = require('body-parser');
132
+ let collectRawData = function(req, res, buf, encoding) {
133
+ req.rodRawData = buf.toString(encoding);
134
+ };
135
+
132
136
  app.use(bodyParser.urlencoded({
137
+ verify: collectRawData,
133
138
  limit: envCommonRod.body_parser_limit,
134
139
  extended: true
135
140
  }));
136
- app.use(bodyParser.json({limit: envCommonRod.body_parser_limit}));
137
- app.use(bodyParser.text({type:"text/*", limit: envCommonRod.body_parser_limit}));
141
+ app.use(bodyParser.json({
142
+ verify: collectRawData,
143
+ limit: envCommonRod.body_parser_limit,
144
+ }));
145
+ app.use(bodyParser.text({
146
+ verify: collectRawData,
147
+ type:"text/*", limit: envCommonRod.body_parser_limit
148
+ }));
138
149
 
139
150
 
140
151
  //obtainSession + assign invoke
@@ -90,22 +90,22 @@ function genOptionAttribute(rodSession, optionAttribute) {
90
90
  }else{
91
91
  optionAttribute._invoke = optionAttribute.headers['X-Tid'];
92
92
  }
93
- optionAttribute._logHeaders = JSON.stringify(optionAttribute.headers); //to write log
93
+ // optionAttribute._logHeaders = JSON.stringify(optionAttribute.headers); //to write log //10/03/2022 stringify when use
94
94
 
95
95
  // optionAttribute.option = option;
96
96
  // optionAttribute.body = optionAttribute.body || optionAttribute.option.body //case method delete want to send body
97
97
 
98
98
  optionAttribute._reqTime = new Date();
99
99
  optionAttribute._maxRetry = conf.max_retry;
100
- if( rodSession.detail().isRawDataEnabled() ){
100
+ // if( rodSession.detail().isRawDataEnabled() ){
101
101
  optionAttribute._rawData = null;
102
102
  if( optionAttribute.data ){
103
103
  optionAttribute._rawData = typeof optionAttribute.data === 'string' ? optionAttribute.data : JSON.stringify(optionAttribute.data);
104
104
  }
105
105
 
106
- }else{
107
- optionAttribute._rawData = null;
108
- }
106
+ // }else{
107
+ // optionAttribute._rawData = null;
108
+ // }
109
109
  return optionAttribute;
110
110
  }
111
111
 
@@ -143,12 +143,12 @@ async function requestHttp(rodSession, optionAttributes, ins) {
143
143
 
144
144
 
145
145
  let processLog = maskCredential.outgoing_request_detail(optionAttribute._service+'.'+optionAttribute._command, {
146
- "Header" : optionAttribute.headers,
146
+ "Header" : {...optionAttribute.headers},
147
147
  "Url" : getURL(optionAttribute),
148
148
  "QueryString" : optionAttribute.params || null,
149
- "Body" : optionAttribute.data,
149
+ "Body" : optionAttribute.data, //NOT SHALLOW CLONE
150
150
  "_RawData": optionAttribute._rawData //REMOVE AFTER CALL outgoing_request_detail
151
- });
151
+ }, rodSession.detail().isRawDataEnabled());
152
152
  let rawData = processLog._RawData;
153
153
  delete processLog._RawData;
154
154
 
@@ -224,8 +224,8 @@ function printLog(rodSession, ins, optionAttribute, response, autoAddDetail=true
224
224
  }
225
225
 
226
226
  let processLog = maskCredential.incoming_response_detail(optionAttribute._service+'.'+optionAttribute._command, {
227
+ Header:{...headers},
227
228
  Body:data,
228
- Header:headers,
229
229
  _RawData: rawData
230
230
  });
231
231
  rawData = processLog._RawData;
@@ -243,7 +243,7 @@ function printLog(rodSession, ins, optionAttribute, response, autoAddDetail=true
243
243
 
244
244
  for (const input of rodSession.detail().Input) {
245
245
  let reqLog = maskCredential.outgoing_request(optionAttribute._service+'.'+optionAttribute._command, optionAttribute);
246
- let resLog = maskCredential.incoming_response(optionAttribute._service+'.'+optionAttribute._command, response, input, data);
246
+ let resLog = maskCredential.incoming_response(optionAttribute._service+'.'+optionAttribute._command, response, input, data, rawData);
247
247
  // let indexPrev = ins.prevOutput.findIndex(output => output.Invoke === input.Invoke);
248
248
  // if(indexPrev > -1 ){
249
249
  // let output = ins.prevOutput.splice(indexPrev,1)[0];
@@ -254,7 +254,7 @@ function printLog(rodSession, ins, optionAttribute, response, autoAddDetail=true
254
254
  trancLog += ' __METHOD='.concat(optionAttribute.method);
255
255
  trancLog += ' __COMMAND='.concat(optionAttribute._command);
256
256
  trancLog += ' __URL='.concat(optionAttribute.url);
257
- trancLog += ' __REQHEADERS='.concat(optionAttribute._logHeaders);
257
+ trancLog += ' __REQHEADERS='.concat(JSON.stringify(optionAttribute.headers));
258
258
  trancLog += ' __REQBODY='.concat(optionAttribute._rawData);
259
259
  }else{
260
260
  trancLog += reqLog;
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  *
3
- *
3
+ * data_path_body //true == body typeof string
4
4
  * {
5
5
  //mask pattern
6
6
  "mask_template":{
@@ -100,7 +100,7 @@
100
100
  }
101
101
  }
102
102
  */
103
- var _ = require('lodash');
103
+ var _ = require('lodash');
104
104
  const utils = require('./utils');
105
105
 
106
106
  function readWithPath(path, obj, cb, currentPath=0){
@@ -186,8 +186,15 @@ let maskCredential = function () {
186
186
 
187
187
  let body;
188
188
  if (typeof req.body === 'object') {
189
- body = {
190
- ...req.body
189
+ // body = {
190
+ // ...req.body
191
+ // }
192
+ //DEEP COPY
193
+ let ctype = utils.checkCType(req.get('Content-Type'));
194
+ if(ctype === 'json'){
195
+ body = JSON.parse(req.rodRawData);
196
+ }else{
197
+ body = JSON.parse(JSON.stringify(req.body));
191
198
  }
192
199
  } else if (typeof req.body === 'string') {
193
200
  body = req.body;
@@ -283,18 +290,26 @@ let maskCredential = function () {
283
290
  }
284
291
 
285
292
  let body;
286
- let rawData = null;
293
+ let rawData = req.rodRawData;
287
294
  if (typeof req.body === 'object') {
288
- rawData = Object.keys(req.body).length === 0 ? null : JSON.stringify(req.body);
289
- body = {
290
- ...req.body
295
+ // rawData = Object.keys(req.body).length === 0 ? null : JSON.stringify(req.body);
296
+ // body = {
297
+ // ...req.body
298
+ // }
299
+ //DEEP COPY
300
+ let ctype = utils.checkCType(req.get('Content-Type'));
301
+ if(ctype === 'json'){
302
+ body = JSON.parse(req.rodRawData);
303
+ }else{
304
+ body = JSON.parse(JSON.stringify(req.body));
291
305
  }
306
+
292
307
  } else if (typeof req.body === 'string') {
293
308
  body = req.body;
294
- rawData = req.body;
309
+ // rawData = req.body;
295
310
  } else {
296
311
  body = req.body;
297
- rawData = req.body;
312
+ // rawData = req.body;
298
313
  }
299
314
 
300
315
  for (let i = 0; i < mask_credentails.mask_data.incoming_request[cmd].mask.length; i++) {
@@ -389,7 +404,8 @@ let maskCredential = function () {
389
404
  } else {
390
405
  let rawData = null;
391
406
  if (detailLog.isRawDataEnabled()) {
392
- rawData = Object.keys(req.body).length === 0 ? null : JSON.stringify(req.body);
407
+ // rawData = Object.keys(req.body).length === 0 ? null : JSON.stringify(req.body);
408
+ rawData = req.rodRawData;
393
409
  }
394
410
  let inputCmd = detailLog.Scenario; //avoid case change cmd name
395
411
  detailLog.addInputRequest("client", inputCmd, req.invoke,
@@ -440,7 +456,7 @@ let maskCredential = function () {
440
456
  let copyHeaders = {
441
457
  ...res._headers
442
458
  }
443
- let body;
459
+ let body; //res.body is not effect with real resp
444
460
  if (typeof res.body === 'object') {
445
461
  body = {
446
462
  ...res.body
@@ -572,7 +588,7 @@ let maskCredential = function () {
572
588
  }
573
589
  }
574
590
  }
575
-
591
+ //header
576
592
  if (mask.detail_log.data_path_headers) {
577
593
  for (let j = 0; j < mask.detail_log.data_path_headers.length; j++) {
578
594
  let headerPath = mask.detail_log.data_path_headers[j];
@@ -591,9 +607,10 @@ let maskCredential = function () {
591
607
  }
592
608
  }
593
609
  }
594
- if (mask.app_log.body && body) {
595
- if (typeof mask.app_log.body === 'boolean' &&
596
- mask.app_log.body === true &&
610
+ //body
611
+ if (mask.detail_log.data_path_body && body) {
612
+ if (typeof mask.detail_log.data_path_body === 'boolean' &&
613
+ mask.detail_log.data_path_body === true &&
597
614
  typeof body === 'string' &&
598
615
  mask_credentails.mask_template[mask.type]) {
599
616
  let mt = mask_credentails.mask_template[mask.type];
@@ -607,11 +624,11 @@ let maskCredential = function () {
607
624
  }
608
625
  }
609
626
 
610
- } else if (Array.isArray(mask.app_log.body) &&
627
+ } else if (Array.isArray(mask.detail_log.data_path_body) &&
611
628
  typeof body === 'object' &&
612
629
  mask_credentails.mask_template[mask.type]) {
613
- for (let index = 0; index < mask.app_log.body.length; index++) {
614
- const bodyPath = mask.app_log.body[index];
630
+ for (let index = 0; index < mask.detail_log.data_path_body.length; index++) {
631
+ const bodyPath = mask.detail_log.data_path_body[index];
615
632
  readWithPath(bodyPath, body, (bdpValue)=>{
616
633
  if (bdpValue && typeof bdpValue === 'string') {
617
634
  let mt = mask_credentails.mask_template[mask.type];
@@ -692,11 +709,13 @@ let maskCredential = function () {
692
709
  }
693
710
 
694
711
 
695
- let body;
712
+ let body;
696
713
  if (typeof optionAttribute.data === 'object') {
697
- body = {
698
- ...optionAttribute.data
699
- }
714
+ // body = {
715
+ // ...optionAttribute.data
716
+ // }
717
+ body = JSON.parse(optionAttribute._rawData);//DEEP COPY
718
+
700
719
  } else if (typeof optionAttribute.data === 'string') {
701
720
  body = optionAttribute.data;
702
721
  } else {
@@ -779,7 +798,7 @@ let maskCredential = function () {
779
798
  }
780
799
  }
781
800
 
782
- let outgoing_request_detail = function (cmd, obj) {
801
+ let outgoing_request_detail = function (cmd, obj, enableRaw) {
783
802
  if (mask_credentails &&
784
803
  mask_credentails.mask_data &&
785
804
  mask_credentails.mask_data.outgoing_request &&
@@ -790,7 +809,7 @@ let maskCredential = function () {
790
809
  let mask = mask_credentails.mask_data.outgoing_request[cmd].mask[i];
791
810
  if (mask.detail_log) {
792
811
  //rawData
793
- if (mask.detail_log.raw_data && obj._RawData) {
812
+ if (mask.detail_log.raw_data && obj._RawData && enableRaw) {
794
813
  if (mask_credentails.mask_template[mask.type]) {
795
814
  let mt = mask_credentails.mask_template[mask.type];
796
815
  for (let k = 0; k < mt.length; k++) {
@@ -804,7 +823,7 @@ let maskCredential = function () {
804
823
  }
805
824
  }
806
825
  }
807
-
826
+ //header
808
827
  if (mask.detail_log.data_path_headers) {
809
828
  for (let j = 0; j < mask.detail_log.data_path_headers.length; j++) {
810
829
  let headerPath = mask.detail_log.data_path_headers[j];
@@ -823,8 +842,14 @@ let maskCredential = function () {
823
842
  }
824
843
  }
825
844
  }
826
-
845
+ //body
827
846
  if (mask.detail_log.data_path_body && obj.Body) {
847
+ if(obj._RawData){
848
+ obj.Body = JSON.parse(obj._RawData);//DEEP COPY
849
+ }else{
850
+ obj.Body = JSON.parse(JSON.stringify(obj.Body));
851
+ }
852
+
828
853
  if (typeof mask.detail_log.data_path_body === 'boolean' &&
829
854
  mask.detail_log.data_path_body === true &&
830
855
  typeof obj.Body === 'string' &&
@@ -845,7 +870,7 @@ let maskCredential = function () {
845
870
  mask_credentails.mask_template[mask.type]) {
846
871
  for (let index = 0; index < mask.detail_log.data_path_body.length; index++) {
847
872
  const bodyPath = mask.detail_log.data_path_body[index];
848
- readWithPath(bodyPath, body, (bdpValue)=>{
873
+ readWithPath(bodyPath, obj.Body, (bdpValue)=>{
849
874
  if (bdpValue && typeof bdpValue === 'string') {
850
875
  let mt = mask_credentails.mask_template[mask.type];
851
876
  for (let k = 0; k < mt.length; k++) {
@@ -873,19 +898,27 @@ let maskCredential = function () {
873
898
  }
874
899
 
875
900
 
876
- let incoming_response = function (cmd, response, input, data) {
901
+ let incoming_response = function (cmd, response, input, data, rawData) {
877
902
  if (mask_credentails &&
878
903
  mask_credentails.mask_data &&
879
904
  mask_credentails.mask_data.incoming_response &&
880
905
  mask_credentails.mask_data.incoming_response[cmd] &&
881
906
  mask_credentails.mask_data.incoming_response[cmd].mask) {
882
907
 
883
- let copyHeaders = response.headers;
884
- let body = data;
908
+ let copyHeaders = {...response.headers};
909
+ let body;
910
+ if (typeof data === 'object') {
911
+ body = JSON.parse(rawData);//DEEP COPY
912
+ } else if (typeof data === 'string') {
913
+ body = rawData;
914
+ } else {
915
+ body = rawData;
916
+ }
885
917
 
886
918
  for (let i = 0; i < mask_credentails.mask_data.incoming_response[cmd].mask.length; i++) {
887
919
  let mask = mask_credentails.mask_data.incoming_response[cmd].mask[i];
888
920
  if (mask.app_log) {
921
+ //header
889
922
  if (mask.app_log.headers) {
890
923
  for (let j = 0; j < mask.app_log.headers.length; j++) {
891
924
  let headerPath = mask.app_log.headers[j];
@@ -904,6 +937,7 @@ let maskCredential = function () {
904
937
  }
905
938
  }
906
939
  }
940
+ //body
907
941
  if (mask.app_log.body && body) {
908
942
  if (typeof mask.app_log.body === 'boolean' &&
909
943
  mask.app_log.body === true &&
@@ -960,12 +994,19 @@ let maskCredential = function () {
960
994
  }
961
995
 
962
996
  let incoming_response_detail = function (cmd, obj) {
963
-
997
+
964
998
  if (mask_credentails &&
965
999
  mask_credentails.mask_data &&
966
1000
  mask_credentails.mask_data.incoming_response &&
967
1001
  mask_credentails.mask_data.incoming_response[cmd] &&
968
1002
  mask_credentails.mask_data.incoming_response[cmd].mask) {
1003
+ if (typeof obj.Body === 'object') {
1004
+ obj.Body = JSON.parse(obj._RawData);//DEEP COPY
1005
+ } else if (typeof obj.Body === 'string') {
1006
+ obj.Body = obj._RawData;
1007
+ } else {
1008
+ obj.Body = obj._RawData;
1009
+ }
969
1010
 
970
1011
  for (let i = 0; i < mask_credentails.mask_data.incoming_response[cmd].mask.length; i++) {
971
1012
  let mask = mask_credentails.mask_data.incoming_response[cmd].mask[i];
@@ -985,7 +1026,7 @@ let maskCredential = function () {
985
1026
  }
986
1027
  }
987
1028
  }
988
-
1029
+ //header
989
1030
  if (mask.detail_log.data_path_headers) {
990
1031
  for (let j = 0; j < mask.detail_log.data_path_headers.length; j++) {
991
1032
  let headerPath = mask.detail_log.data_path_headers[j];
@@ -1004,6 +1045,7 @@ let maskCredential = function () {
1004
1045
  }
1005
1046
  }
1006
1047
  }
1048
+ //body
1007
1049
  if (mask.detail_log.data_path_body && obj.Body) {
1008
1050
  if (typeof mask.detail_log.data_path_body === 'boolean' &&
1009
1051
  mask.detail_log.data_path_body === true &&
@@ -1025,7 +1067,7 @@ let maskCredential = function () {
1025
1067
  mask_credentails.mask_template[mask.type]) {
1026
1068
  for (let index = 0; index < mask.detail_log.data_path_body.length; index++) {
1027
1069
  const bodyPath = mask.detail_log.data_path_body[index];
1028
- readWithPath(bodyPath, body, (bdpValue)=>{
1070
+ readWithPath(bodyPath, obj.Body, (bdpValue)=>{
1029
1071
  if (bdpValue && typeof bdpValue === 'string') {
1030
1072
  let mt = mask_credentails.mask_template[mask.type];
1031
1073
  for (let k = 0; k < mt.length; k++) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "common-rod",
3
- "version": "1.7.0",
3
+ "version": "1.7.2",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/readme.md CHANGED
@@ -321,3 +321,20 @@ foo[0].bar[0]
321
321
  ```
322
322
  ### Changed
323
323
  ### Fixed
324
+
325
+ # [1.7.1] - 2022-03-11
326
+ ### Added
327
+ ### Changed
328
+ ### Fixed
329
+ ```
330
+ Fix bug hideCredenmtial with nested object
331
+ ```
332
+
333
+ # [1.7.2] - 2022-10-03
334
+ ### Added
335
+ ### Changed
336
+ ### Fixed
337
+ ```
338
+ Fix bug hideCredenmtial with oher ctype
339
+ Fix DetailLog input response attribure Data
340
+ ```