@ikonintegration/ikapi 3.0.2 → 3.0.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 +7 -0
- package/package.json +1 -1
- package/src/BaseEvent/IKProcess.js +1 -1
- package/src/BaseEvent/IKTransaction.js +1 -1
- package/src/Logger/IKLogger.js +34 -8
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
|
@@ -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(
|
|
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(
|
|
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);
|
package/src/Logger/IKLogger.js
CHANGED
|
@@ -9,6 +9,8 @@ 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);
|
|
@@ -20,10 +22,11 @@ export default class IKLogger {
|
|
|
20
22
|
}
|
|
21
23
|
//
|
|
22
24
|
this.origin = PURE_CONSOLE;
|
|
23
|
-
this._LOG_LEVEL = _LOG_LEVEL;
|
|
24
|
-
this.
|
|
25
|
+
this._LOG_LEVEL = (_config || {}).level || _LOG_LEVEL;
|
|
26
|
+
this._config = _config || {};
|
|
25
27
|
this._transactionID = transactionID;
|
|
26
|
-
this.
|
|
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() {
|
|
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
|
-
|
|
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('/') +' ' +
|
|
@@ -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);
|
|
107
|
-
DEFAULT_LOG_FUNCTION.apply(PURE_CONSOLE, [fMsg]);
|
|
109
|
+
// push into logs stack
|
|
110
|
+
// this._logs.push(fMsg);
|
|
111
|
+
DEFAULT_LOG_FUNCTION.apply(PURE_CONSOLE, [this._supressSensitiveInfo(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
|
}
|