@ikonintegration/ikapi 3.0.2 → 3.0.5

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
@@ -42,6 +42,13 @@ export const handler = async (event, context) => {
42
42
  validation: {
43
43
  additionalTypes: { TYPE: (val) => { return validate(val); } }
44
44
  },
45
+ //Logger
46
+ logger: {
47
+ //takes precende over process.env.LOG_LEVEL
48
+ level: 'DEBUG' | 'INFO' | 'WARN' | 'ERROR',
49
+ enableSensitiveFiltering: false, //defaults to false
50
+ sensitiveFilteringKeywords: [], //replaced default blacklist set
51
+ },
45
52
  //Queue
46
53
  publisher: { region: 'SNS-REGION' }
47
54
  };)).handleEvent(event, context));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ikonintegration/ikapi",
3
- "version": "3.0.2",
3
+ "version": "3.0.5",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "module": "main.js",
@@ -15,7 +15,7 @@ export default class IKProcess {
15
15
  constructor(config, interval) {
16
16
  this._config = config;
17
17
  this.interval = interval;
18
- this.logger = new IKLogger({/*COFIG S3/SQS HERE*/}, Utils.logLevel());
18
+ this.logger = new IKLogger(config.logger, Utils.logLevel());
19
19
  this.publisher = new IKPublisher(config.publisher);
20
20
  this.validator = new IKValidation(config.validation);
21
21
  this.db = this._getDBDriver();
@@ -28,7 +28,7 @@ export default class IKTransaction {
28
28
  //When set, this will be called with the response context right before calling the context suceed/fail
29
29
  this.responseProxy = null;
30
30
  //
31
- this.logger = new IKLogger({/*COFIG S3/SQS HERE*/}, Utils.logLevel(), (context.awsRequestId ? context.awsRequestId : (event.requestContext ? event.requestContext.requestId : 'unknown')));
31
+ this.logger = new IKLogger(config.logger, Utils.logLevel(), (context.awsRequestId ? context.awsRequestId : (event.requestContext ? event.requestContext.requestId : 'unknown')));
32
32
  this.request = new IKRequest(this._event, this._context, this);
33
33
  this.publisher = new IKPublisher(config.publisher);
34
34
  this.validator = new IKValidation(config.validation);
@@ -9,21 +9,24 @@ const LOG_STRINGS = ['DEBUG', 'INFO', 'WARN', 'ERROR'];
9
9
  const PURE_CONSOLE = (console.flushLogs ? console.origin : console);
10
10
  const DEFAULT_LOG_FUNCTION = PURE_CONSOLE.log.bind(PURE_CONSOLE);
11
11
  //
12
+ const blacklist = ['password','phonenumber','code','resetCode','recaptchaToken','token','mfa','REFRESH_TOKEN','SECRET_HASH','SecretHash','AccessToken','UserCode','paymentMethodNonce'];
13
+ //
12
14
  export default class IKLogger {
13
15
  constructor(_config, _LOG_LEVEL, transactionID) {
14
16
  abind(this);
15
17
  //
16
- if (!_LOG_LEVEL) _LOG_LEVEL = LOG_LEVELS.DEBUG;
18
+ if (!_LOG_LEVEL && !(_config || {}).level) _LOG_LEVEL = LOG_LEVELS.DEBUG;
17
19
  else {
18
- _LOG_LEVEL = LOG_STRINGS.indexOf(_LOG_LEVEL);
20
+ _LOG_LEVEL = LOG_STRINGS.indexOf((_config || {}).level || _LOG_LEVEL);
19
21
  if (_LOG_LEVEL == -1) _LOG_LEVEL = LOG_LEVELS.DEBUG;
20
22
  }
21
23
  //
22
24
  this.origin = PURE_CONSOLE;
23
25
  this._LOG_LEVEL = _LOG_LEVEL;
24
- this._s3Config = _config;
26
+ this._config = _config || {};
25
27
  this._transactionID = transactionID;
26
- this._logs = [];
28
+ this._filterBlacklist = this._config.sensitiveFilteringKeywords || blacklist;
29
+ //
27
30
  this._setupBindings();
28
31
  //
29
32
  this.log("Using logger with level: " + LOG_STRINGS[this._LOG_LEVEL]);
@@ -49,7 +52,7 @@ export default class IKLogger {
49
52
  this._pushLog(LOG_LEVELS.ERROR, this._formattedLog(LOG_LEVELS.ERROR, msg, this._callerName(3), isRaw));
50
53
  }
51
54
  //
52
- cleanUp() { this._logs = []; }
55
+ cleanUp() { }
53
56
  async flushLogs() {}
54
57
 
55
58
 
@@ -67,7 +70,7 @@ export default class IKLogger {
67
70
  }
68
71
 
69
72
 
70
- //Helpers
73
+ /* Formatters */
71
74
  _timestamp() {
72
75
  let d = new Date();
73
76
  return [Utils.toDoubleDigit(d.getMonth()+1), Utils.toDoubleDigit(d.getDate()), d.getFullYear()].join('/') +' ' +
@@ -77,7 +80,7 @@ export default class IKLogger {
77
80
  if (Utils.isOffline()) {
78
81
  return ` [${this._timestamp()} - ${LOG_STRINGS[level]}] [${caller}] ${msg.join(" ")}`;
79
82
  } else if (Utils.isIKAPIGateway() && this._transactionID) {
80
- return (isRaw ? '' : ` ${this._transactionID}`) + ` [${LOG_STRINGS[level]}] [${caller}] ${msg.join(" ")}`;
83
+ return (isRaw ? '' : ` ${this._transactionID}`) + ` [${LOG_STRINGS[level]}] [${caller}] ${this._supressSensitiveInfo(msg.join(" "))}`;
81
84
  } else {
82
85
  return ` [${LOG_STRINGS[level]}] [${caller}] ${msg.join(" ")}`;
83
86
  }
@@ -92,6 +95,7 @@ export default class IKLogger {
92
95
  } return callerName + ":" + stackTrace.get()[safeIndex].getLineNumber();
93
96
  } return '';
94
97
  }
98
+ /* Helpers (core functionality) */
95
99
  _processLog(isRaw, level, args) {
96
100
  if (level < this._LOG_LEVEL) return;
97
101
  //get args
@@ -102,8 +106,30 @@ export default class IKLogger {
102
106
  this._pushLog(level, this._formattedLog(level, msg, this._callerName(3), isRaw));
103
107
  }
104
108
  _pushLog(level, fMsg) {
105
- //push into logs stack
106
- this._logs.push(fMsg);
109
+ // push into logs stack
110
+ // this._logs.push(fMsg);
107
111
  DEFAULT_LOG_FUNCTION.apply(PURE_CONSOLE, [fMsg]);
108
112
  }
113
+ /* Sensitive information handling */
114
+ _supressSensitiveInfo(value) {
115
+ //realy false
116
+ if (this._config.enableSensitiveFiltering !== undefined && !this._config.enableSensitiveFiltering) return value;
117
+ if (typeof value == "string") {
118
+ //content based replacement
119
+ blacklist.forEach((f) => {
120
+ const match = blacklist.find((f) => value.toLowerCase().includes(f.toLowerCase()));
121
+ if (match) value = '**SUPRESSED_SENSITIVE_DATA**';
122
+ });
123
+ return value;
124
+ } else if (typeof value == 'object') {
125
+ //key based replacement
126
+ Object.keys(value).forEach(function (elt, i, array) {
127
+ const match = blacklist.find((f) => elt.toLowerCase().includes(f.toLowerCase()));
128
+ if (match) value[elt] = '**SUPRESSED_SENSITIVE_DATA**';
129
+ else value[elt] = supress(value[elt]);
130
+ });
131
+ return value;
132
+ } else if (Array.isArray(value)) return value.map(v=>supress(v));
133
+ return value;
134
+ }
109
135
  }