@creator.co/wapi 1.2.1-beta6 → 1.2.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/.github/workflows/npmpublish.yml +11 -19
- package/.github/workflows/prs.yml +13 -0
- package/jest.config.ts +39 -0
- package/package.json +15 -4
- package/src/API/Request.ts +120 -10
- package/src/API/Response.ts +236 -8
- package/src/API/Utils.ts +56 -1
- package/src/BaseEvent/EventProcessor.ts +84 -11
- package/src/BaseEvent/Process.ts +62 -1
- package/src/BaseEvent/Transaction.ts +5 -8
- package/src/Config/Configuration.ts +111 -5
- package/src/Config/EnvironmentVar.ts +90 -1
- package/src/Crypto/Crypto.ts +77 -18
- package/src/Crypto/JWT.ts +49 -3
- package/src/Globals.ts +141 -3
- package/src/Logger/Logger.ts +173 -19
- package/src/Mailer/Mailer.ts +95 -0
- package/src/Publisher/Publisher.ts +50 -4
- package/src/Server/RouteResolver.ts +142 -0
- package/src/Server/Router.ts +77 -0
- package/src/Server/lib/ContainerServer.ts +48 -1
- package/src/Server/lib/Server.ts +78 -38
- package/src/Server/lib/container/GenericHandler.ts +7 -5
- package/src/Server/lib/container/GenericHandlerEvent.ts +59 -17
- package/src/Server/lib/container/HealthHandler.ts +1 -1
- package/src/Server/lib/container/Proxy.ts +92 -11
- package/src/Server/lib/container/Utils.ts +16 -25
- package/src/Validation/Validator.ts +18 -2
- package/tests/API/Request.test.ts +263 -0
- package/tests/API/Response.test.ts +372 -0
- package/tests/API/Utils.test.ts +157 -0
- package/tests/BaseEvent/EventProcessor.test.ts +278 -0
- package/tests/BaseEvent/Process.test.ts +49 -0
- package/tests/BaseEvent/Transaction.test.ts +231 -0
- package/tests/Config/Config.test.ts +193 -0
- package/tests/Config/EnvironmentVar.test.ts +223 -0
- package/tests/Crypto/Crypto.test.ts +90 -0
- package/tests/Crypto/JWT.test.ts +92 -0
- package/tests/Logger/Logger.test.ts +108 -0
- package/tests/Mailer/Mailer.test.ts +67 -0
- package/tests/Publisher/Publisher.test.ts +60 -0
- package/tests/Server/RouteResolver.test.ts +106 -0
- package/tests/Server/Router.test.ts +38 -0
- package/tests/Server/lib/ContainerServer.test.ts +329 -0
- package/tests/Server/lib/Server.test.ts +12 -0
- package/tests/Server/lib/container/GenericHandler.test.ts +141 -0
- package/tests/Server/lib/container/GenericHandlerEvent.test.ts +103 -0
- package/tests/Server/lib/container/HealthHandler.test.ts +30 -0
- package/tests/Server/lib/container/Proxy.test.ts +278 -0
- package/tests/Server/lib/container/Utils.test.ts +48 -0
- package/tests/Test.utils.ts +95 -0
- package/tests/Validation/Validator.test.ts +88 -0
- package/tests/main.test.ts +15 -0
- package/tsconfig.json +1 -0
- package/dist/index.d.ts +0 -11
- package/dist/index.js +0 -24
- package/dist/index.js.map +0 -1
- package/dist/package.json +0 -53
- package/dist/src/API/Request.d.ts +0 -21
- package/dist/src/API/Request.js +0 -86
- package/dist/src/API/Request.js.map +0 -1
- package/dist/src/API/Response.d.ts +0 -39
- package/dist/src/API/Response.js +0 -232
- package/dist/src/API/Response.js.map +0 -1
- package/dist/src/API/Utils.d.ts +0 -8
- package/dist/src/API/Utils.js +0 -49
- package/dist/src/API/Utils.js.map +0 -1
- package/dist/src/BaseEvent/EventProcessor.d.ts +0 -13
- package/dist/src/BaseEvent/EventProcessor.js +0 -151
- package/dist/src/BaseEvent/EventProcessor.js.map +0 -1
- package/dist/src/BaseEvent/Process.d.ts +0 -12
- package/dist/src/BaseEvent/Process.js +0 -114
- package/dist/src/BaseEvent/Process.js.map +0 -1
- package/dist/src/BaseEvent/Transaction.d.ts +0 -29
- package/dist/src/BaseEvent/Transaction.js +0 -248
- package/dist/src/BaseEvent/Transaction.js.map +0 -1
- package/dist/src/Config/Configuration.d.ts +0 -34
- package/dist/src/Config/Configuration.js +0 -93
- package/dist/src/Config/Configuration.js.map +0 -1
- package/dist/src/Config/EnvironmentVar.d.ts +0 -17
- package/dist/src/Config/EnvironmentVar.js +0 -152
- package/dist/src/Config/EnvironmentVar.js.map +0 -1
- package/dist/src/Crypto/Crypto.d.ts +0 -8
- package/dist/src/Crypto/Crypto.js +0 -84
- package/dist/src/Crypto/Crypto.js.map +0 -1
- package/dist/src/Crypto/JWT.d.ts +0 -16
- package/dist/src/Crypto/JWT.js +0 -49
- package/dist/src/Crypto/JWT.js.map +0 -1
- package/dist/src/Globals.d.ts +0 -21
- package/dist/src/Globals.js +0 -35
- package/dist/src/Globals.js.map +0 -1
- package/dist/src/Logger/Logger.d.ts +0 -34
- package/dist/src/Logger/Logger.js +0 -345
- package/dist/src/Logger/Logger.js.map +0 -1
- package/dist/src/Mailer/Mailer.d.ts +0 -12
- package/dist/src/Mailer/Mailer.js +0 -234
- package/dist/src/Mailer/Mailer.js.map +0 -1
- package/dist/src/Publisher/Publisher.d.ts +0 -10
- package/dist/src/Publisher/Publisher.js +0 -109
- package/dist/src/Publisher/Publisher.js.map +0 -1
- package/dist/src/Server/Router.d.ts +0 -27
- package/dist/src/Server/Router.js +0 -22
- package/dist/src/Server/Router.js.map +0 -1
- package/dist/src/Server/lib/ContainerServer.d.ts +0 -11
- package/dist/src/Server/lib/ContainerServer.js +0 -103
- package/dist/src/Server/lib/ContainerServer.js.map +0 -1
- package/dist/src/Server/lib/Server.d.ts +0 -9
- package/dist/src/Server/lib/Server.js +0 -141
- package/dist/src/Server/lib/Server.js.map +0 -1
- package/dist/src/Server/lib/container/GenericHandler.d.ts +0 -4
- package/dist/src/Server/lib/container/GenericHandler.js +0 -136
- package/dist/src/Server/lib/container/GenericHandler.js.map +0 -1
- package/dist/src/Server/lib/container/GenericHandlerEvent.d.ts +0 -14
- package/dist/src/Server/lib/container/GenericHandlerEvent.js +0 -164
- package/dist/src/Server/lib/container/GenericHandlerEvent.js.map +0 -1
- package/dist/src/Server/lib/container/HealthHandler.d.ts +0 -3
- package/dist/src/Server/lib/container/HealthHandler.js +0 -44
- package/dist/src/Server/lib/container/HealthHandler.js.map +0 -1
- package/dist/src/Server/lib/container/Proxy.d.ts +0 -15
- package/dist/src/Server/lib/container/Proxy.js +0 -157
- package/dist/src/Server/lib/container/Proxy.js.map +0 -1
- package/dist/src/Server/lib/container/Utils.d.ts +0 -6
- package/dist/src/Server/lib/container/Utils.js +0 -109
- package/dist/src/Server/lib/container/Utils.js.map +0 -1
- package/dist/src/Validation/Validator.d.ts +0 -5
- package/dist/src/Validation/Validator.js +0 -31
- package/dist/src/Validation/Validator.js.map +0 -1
package/src/Crypto/Crypto.ts
CHANGED
|
@@ -1,35 +1,94 @@
|
|
|
1
1
|
import { KMSClient, EncryptCommand, DecryptCommand } from "@aws-sdk/client-kms"
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* ${1:Description placeholder}
|
|
5
|
+
*
|
|
6
|
+
* @export
|
|
7
|
+
* @class Crypto
|
|
8
|
+
* @typedef {Crypto}
|
|
9
|
+
*/
|
|
3
10
|
export default class Crypto {
|
|
11
|
+
/**
|
|
12
|
+
* ${1:Description placeholder}
|
|
13
|
+
*
|
|
14
|
+
* @private
|
|
15
|
+
* @readonly
|
|
16
|
+
* @type {KMSClient}
|
|
17
|
+
*/
|
|
4
18
|
private readonly client: KMSClient
|
|
19
|
+
/**
|
|
20
|
+
* ${1:Description placeholder}
|
|
21
|
+
*
|
|
22
|
+
* @private
|
|
23
|
+
* @readonly
|
|
24
|
+
* @type {string}
|
|
25
|
+
*/
|
|
5
26
|
private readonly region: string
|
|
27
|
+
/**
|
|
28
|
+
* ${1:Description placeholder}
|
|
29
|
+
*
|
|
30
|
+
* @private
|
|
31
|
+
* @readonly
|
|
32
|
+
* @type {string}
|
|
33
|
+
*/
|
|
6
34
|
private readonly keyId: string
|
|
35
|
+
/**
|
|
36
|
+
* Creates an instance of Crypto.
|
|
37
|
+
*
|
|
38
|
+
* @constructor
|
|
39
|
+
* @param {string} region
|
|
40
|
+
* @param {string} keyId
|
|
41
|
+
*/
|
|
7
42
|
constructor(region: string, keyId: string) {
|
|
8
43
|
this.region = region
|
|
9
44
|
this.keyId = keyId
|
|
10
45
|
this.client = new KMSClient({ region: this.region })
|
|
11
46
|
}
|
|
12
47
|
//
|
|
48
|
+
/**
|
|
49
|
+
* ${1:Description placeholder}
|
|
50
|
+
*
|
|
51
|
+
* @async
|
|
52
|
+
* @param {(string | any)} data
|
|
53
|
+
* @returns {Promise<string>}
|
|
54
|
+
*/
|
|
13
55
|
async encryptData(data: string | any): Promise<string> {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
56
|
+
try {
|
|
57
|
+
const resp = await this.client.send(
|
|
58
|
+
new EncryptCommand({
|
|
59
|
+
KeyId: this.keyId,
|
|
60
|
+
EncryptionAlgorithm: "RSAES_OAEP_SHA_256",
|
|
61
|
+
Plaintext: new TextEncoder().encode(
|
|
62
|
+
typeof data === "string" ? data : JSON.stringify(data),
|
|
63
|
+
),
|
|
64
|
+
}),
|
|
65
|
+
)
|
|
66
|
+
return Buffer.from(resp.CiphertextBlob as any, "utf8").toString("hex")
|
|
67
|
+
} catch (e) {
|
|
68
|
+
console.error("Encryption failure", e)
|
|
69
|
+
return null
|
|
70
|
+
}
|
|
24
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
* ${1:Description placeholder}
|
|
74
|
+
*
|
|
75
|
+
* @async
|
|
76
|
+
* @param {string} data
|
|
77
|
+
* @returns {Promise<string>}
|
|
78
|
+
*/
|
|
25
79
|
async decryptData(data: string): Promise<string> {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
80
|
+
try {
|
|
81
|
+
const resp = await this.client.send(
|
|
82
|
+
new DecryptCommand({
|
|
83
|
+
KeyId: this.keyId,
|
|
84
|
+
CiphertextBlob: Buffer.from(data, "hex"),
|
|
85
|
+
EncryptionAlgorithm: "RSAES_OAEP_SHA_256",
|
|
86
|
+
}),
|
|
87
|
+
)
|
|
88
|
+
return new TextDecoder().decode(resp.Plaintext)
|
|
89
|
+
} catch (e) {
|
|
90
|
+
console.error("Decryption failure", e)
|
|
91
|
+
return null
|
|
92
|
+
}
|
|
34
93
|
}
|
|
35
94
|
}
|
package/src/Crypto/JWT.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import * as jwt from "jsonwebtoken"
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* ${1:Description placeholder}
|
|
5
|
+
*
|
|
6
|
+
* @typedef {JWTValidationResponse}
|
|
7
|
+
*/
|
|
3
8
|
type JWTValidationResponse =
|
|
4
9
|
| { isValid: true; decodedToken: jwt.JwtPayload }
|
|
5
10
|
| {
|
|
@@ -7,14 +12,51 @@ type JWTValidationResponse =
|
|
|
7
12
|
isExpired?: boolean
|
|
8
13
|
}
|
|
9
14
|
|
|
15
|
+
/**
|
|
16
|
+
* ${1:Description placeholder}
|
|
17
|
+
*
|
|
18
|
+
* @export
|
|
19
|
+
* @class JWT
|
|
20
|
+
* @typedef {JWT}
|
|
21
|
+
*/
|
|
10
22
|
export default class JWT {
|
|
23
|
+
/**
|
|
24
|
+
* ${1:Description placeholder}
|
|
25
|
+
*
|
|
26
|
+
* @private
|
|
27
|
+
* @readonly
|
|
28
|
+
* @type {string}
|
|
29
|
+
*/
|
|
11
30
|
private readonly tokenSecret: string
|
|
31
|
+
/**
|
|
32
|
+
* ${1:Description placeholder}
|
|
33
|
+
*
|
|
34
|
+
* @private
|
|
35
|
+
* @readonly
|
|
36
|
+
* @type {string}
|
|
37
|
+
*/
|
|
12
38
|
private readonly defaultExpiration: string
|
|
39
|
+
/**
|
|
40
|
+
* Creates an instance of JWT.
|
|
41
|
+
*
|
|
42
|
+
* @constructor
|
|
43
|
+
* @param {string} tokenSecret
|
|
44
|
+
* @param {?string} [defaultExpiration]
|
|
45
|
+
*/
|
|
13
46
|
constructor(tokenSecret: string, defaultExpiration?: string) {
|
|
14
47
|
this.tokenSecret = tokenSecret
|
|
15
48
|
this.defaultExpiration = defaultExpiration
|
|
16
49
|
}
|
|
17
50
|
//
|
|
51
|
+
/**
|
|
52
|
+
* ${1:Description placeholder}
|
|
53
|
+
*
|
|
54
|
+
* @param {object} data
|
|
55
|
+
* @param {?string} [expiration]
|
|
56
|
+
* @param {?string} [overrideToken]
|
|
57
|
+
* @param {?*} [opts]
|
|
58
|
+
* @returns {string}
|
|
59
|
+
*/
|
|
18
60
|
createToken(
|
|
19
61
|
data: object,
|
|
20
62
|
expiration?: string,
|
|
@@ -28,15 +70,19 @@ export default class JWT {
|
|
|
28
70
|
exp ? { expiresIn: exp, ...(opts || {}) } : opts || {},
|
|
29
71
|
)
|
|
30
72
|
}
|
|
73
|
+
/**
|
|
74
|
+
* ${1:Description placeholder}
|
|
75
|
+
*
|
|
76
|
+
* @param {string} token
|
|
77
|
+
* @returns {JWTValidationResponse}
|
|
78
|
+
*/
|
|
31
79
|
validateToken(token: string): JWTValidationResponse {
|
|
32
80
|
try {
|
|
33
81
|
// Check if is valid
|
|
34
82
|
const isValid = jwt.verify(token, this.tokenSecret)
|
|
35
|
-
if (
|
|
36
|
-
else {
|
|
83
|
+
if (isValid) {
|
|
37
84
|
const payload = jwt.decode(token, { json: true })
|
|
38
85
|
if (payload) return { isValid: true, decodedToken: payload }
|
|
39
|
-
else throw new Error("Issue while decoding token!")
|
|
40
86
|
}
|
|
41
87
|
} catch (err) {
|
|
42
88
|
console.error(err)
|
package/src/Globals.ts
CHANGED
|
@@ -4,36 +4,174 @@ import Utils from "./API/Utils"
|
|
|
4
4
|
|
|
5
5
|
// important for dev env to load .env file
|
|
6
6
|
dotenv.config()
|
|
7
|
+
/**
|
|
8
|
+
* Description placeholder
|
|
9
|
+
*
|
|
10
|
+
* @export
|
|
11
|
+
* @class Globals
|
|
12
|
+
* @typedef {Globals}
|
|
13
|
+
*/
|
|
7
14
|
export default class Globals {
|
|
8
|
-
|
|
15
|
+
/**
|
|
16
|
+
* Description placeholder
|
|
17
|
+
*
|
|
18
|
+
* @public
|
|
19
|
+
* @static
|
|
20
|
+
* @type {string}
|
|
21
|
+
*/
|
|
9
22
|
public static ErrorResponseValidationFail = "Input validation failed: " //400
|
|
23
|
+
/**
|
|
24
|
+
* Description placeholder
|
|
25
|
+
*
|
|
26
|
+
* @public
|
|
27
|
+
* @static
|
|
28
|
+
* @type {string}
|
|
29
|
+
*/
|
|
10
30
|
public static ErrorResponseInvalidServerResponse =
|
|
11
31
|
"No valid response, this is a system error." //400
|
|
32
|
+
/**
|
|
33
|
+
* Description placeholder
|
|
34
|
+
*
|
|
35
|
+
* @public
|
|
36
|
+
* @static
|
|
37
|
+
* @type {string}
|
|
38
|
+
*/
|
|
12
39
|
public static ErrorResponseUnhandledError =
|
|
13
40
|
"Unhandled error when processing request." //400
|
|
41
|
+
/**
|
|
42
|
+
* Description placeholder
|
|
43
|
+
*
|
|
44
|
+
* @public
|
|
45
|
+
* @static
|
|
46
|
+
* @type {string}
|
|
47
|
+
*/
|
|
14
48
|
public static ErrorResponseNoRecords = "No events to be processed." //400
|
|
15
|
-
|
|
49
|
+
/**
|
|
50
|
+
* Description placeholder
|
|
51
|
+
*
|
|
52
|
+
* @public
|
|
53
|
+
* @static
|
|
54
|
+
* @type {string}
|
|
55
|
+
*/
|
|
16
56
|
public static ErrorCode_MissingParam = "MISSING_PARAM"
|
|
57
|
+
/**
|
|
58
|
+
* Description placeholder
|
|
59
|
+
*
|
|
60
|
+
* @public
|
|
61
|
+
* @static
|
|
62
|
+
* @type {string}
|
|
63
|
+
*/
|
|
17
64
|
public static ErrorCode_InvalidInput = "INVALID_INPUT"
|
|
65
|
+
/**
|
|
66
|
+
* Description placeholder
|
|
67
|
+
*
|
|
68
|
+
* @public
|
|
69
|
+
* @static
|
|
70
|
+
* @type {string}
|
|
71
|
+
*/
|
|
18
72
|
public static ErrorCode_APIError = "API_ERROR"
|
|
73
|
+
/**
|
|
74
|
+
* Description placeholder
|
|
75
|
+
*
|
|
76
|
+
* @public
|
|
77
|
+
* @static
|
|
78
|
+
* @type {string}
|
|
79
|
+
*/
|
|
19
80
|
public static ErrorCode_NoRecords = "EMPTY_EVENT"
|
|
20
81
|
|
|
82
|
+
/**
|
|
83
|
+
* Description placeholder
|
|
84
|
+
*
|
|
85
|
+
* @public
|
|
86
|
+
* @static
|
|
87
|
+
* @type {*}
|
|
88
|
+
*/
|
|
21
89
|
public static Listener_HTTP_DefaultPort =
|
|
22
|
-
Utils.parseIntNullIfNaN(process.env.PORT) ||
|
|
90
|
+
Utils.parseIntNullIfNaN(process.env.PORT) || 9000
|
|
23
91
|
|
|
92
|
+
/**
|
|
93
|
+
* Description placeholder
|
|
94
|
+
*
|
|
95
|
+
* @public
|
|
96
|
+
* @static
|
|
97
|
+
* @type {string}
|
|
98
|
+
*/
|
|
24
99
|
public static Listener_HTTP_DefaultHost = "localhost"
|
|
100
|
+
/**
|
|
101
|
+
* Description placeholder
|
|
102
|
+
*
|
|
103
|
+
* @public
|
|
104
|
+
* @static
|
|
105
|
+
* @type {string}
|
|
106
|
+
*/
|
|
25
107
|
public static Listener_HTTP_ProxyRoute = "*"
|
|
108
|
+
/**
|
|
109
|
+
* Description placeholder
|
|
110
|
+
*
|
|
111
|
+
* @public
|
|
112
|
+
* @static
|
|
113
|
+
* @type {*}
|
|
114
|
+
*/
|
|
26
115
|
public static Listener_HTTP_DefaultTimeout =
|
|
27
116
|
Utils.parseIntNullIfNaN(process.env.TIMEOUT) || 30000
|
|
117
|
+
/**
|
|
118
|
+
* Description placeholder
|
|
119
|
+
*
|
|
120
|
+
* @public
|
|
121
|
+
* @static
|
|
122
|
+
* @type {*}
|
|
123
|
+
*/
|
|
28
124
|
public static Listener_HTTP_DefaultHealthCheckRoute =
|
|
29
125
|
process.env.HEALTH_ROUTE || "/health"
|
|
30
126
|
//Resps
|
|
127
|
+
/**
|
|
128
|
+
* Description placeholder
|
|
129
|
+
*
|
|
130
|
+
* @public
|
|
131
|
+
* @static
|
|
132
|
+
* @type {string}
|
|
133
|
+
*/
|
|
31
134
|
public static Resp_MSG_EXCEPTION =
|
|
32
135
|
"[Proxy]: Exception during request execution!"
|
|
136
|
+
/**
|
|
137
|
+
* Description placeholder
|
|
138
|
+
*
|
|
139
|
+
* @public
|
|
140
|
+
* @static
|
|
141
|
+
* @type {string}
|
|
142
|
+
*/
|
|
33
143
|
public static Resp_CODE_EXCEPTION = "EXEC_EXCEPTION"
|
|
144
|
+
/**
|
|
145
|
+
* Description placeholder
|
|
146
|
+
*
|
|
147
|
+
* @public
|
|
148
|
+
* @static
|
|
149
|
+
* @type {number}
|
|
150
|
+
*/
|
|
34
151
|
public static Resp_STATUSCODE_EXCEPTION = 502
|
|
35
152
|
|
|
153
|
+
/**
|
|
154
|
+
* Description placeholder
|
|
155
|
+
*
|
|
156
|
+
* @public
|
|
157
|
+
* @static
|
|
158
|
+
* @type {string}
|
|
159
|
+
*/
|
|
36
160
|
public static Resp_MSG_INVALIDRESP = "[Proxy]: Invalid response from server!"
|
|
161
|
+
/**
|
|
162
|
+
* Description placeholder
|
|
163
|
+
*
|
|
164
|
+
* @public
|
|
165
|
+
* @static
|
|
166
|
+
* @type {string}
|
|
167
|
+
*/
|
|
37
168
|
public static Resp_CODE_INVALIDRESP = "EMPTY_RESPONSE"
|
|
169
|
+
/**
|
|
170
|
+
* Description placeholder
|
|
171
|
+
*
|
|
172
|
+
* @public
|
|
173
|
+
* @static
|
|
174
|
+
* @type {number}
|
|
175
|
+
*/
|
|
38
176
|
public static Resp_STATUSCODE_INVALIDRESP = 400
|
|
39
177
|
}
|
package/src/Logger/Logger.ts
CHANGED
|
@@ -5,15 +5,36 @@ import * as stackTrace from "stack-trace"
|
|
|
5
5
|
//
|
|
6
6
|
import Utils from "../API/Utils"
|
|
7
7
|
//
|
|
8
|
+
/**
|
|
9
|
+
* ${1:Description placeholder}
|
|
10
|
+
*
|
|
11
|
+
* @export
|
|
12
|
+
* @enum {number}
|
|
13
|
+
*/
|
|
8
14
|
export enum LOG_LEVELS {
|
|
9
15
|
DEBUG = "DEBUG",
|
|
10
16
|
INFO = "INFO",
|
|
11
17
|
WARN = "WARN",
|
|
12
18
|
ERROR = "ERROR",
|
|
13
19
|
}
|
|
14
|
-
|
|
20
|
+
/**
|
|
21
|
+
* ${1:Description placeholder}
|
|
22
|
+
*
|
|
23
|
+
* @type {*}
|
|
24
|
+
*/
|
|
25
|
+
const PURE_CONSOLE = console["notGlobalLogger"] ? console["origin"] : console
|
|
26
|
+
/**
|
|
27
|
+
* ${1:Description placeholder}
|
|
28
|
+
*
|
|
29
|
+
* @type {*}
|
|
30
|
+
*/
|
|
15
31
|
const DEFAULT_LOG_FUNCTION = PURE_CONSOLE.log.bind(PURE_CONSOLE)
|
|
16
32
|
//
|
|
33
|
+
/**
|
|
34
|
+
* ${1:Description placeholder}
|
|
35
|
+
*
|
|
36
|
+
* @type {{}\}
|
|
37
|
+
*/
|
|
17
38
|
const blacklist = [
|
|
18
39
|
"password",
|
|
19
40
|
"phonenumber" /*,'code'*/,
|
|
@@ -29,18 +50,68 @@ const blacklist = [
|
|
|
29
50
|
"paymentMethodNonce",
|
|
30
51
|
]
|
|
31
52
|
//
|
|
53
|
+
/**
|
|
54
|
+
* ${1:Description placeholder}
|
|
55
|
+
*
|
|
56
|
+
* @export
|
|
57
|
+
* @typedef {LoggerConfig}
|
|
58
|
+
*/
|
|
32
59
|
export type LoggerConfig = {
|
|
33
60
|
sensitiveFilteringKeywords?: boolean | Array<string>
|
|
34
61
|
logLevel?: LOG_LEVELS | string
|
|
35
62
|
}
|
|
36
63
|
//
|
|
64
|
+
/**
|
|
65
|
+
* ${1:Description placeholder}
|
|
66
|
+
*
|
|
67
|
+
* @export
|
|
68
|
+
* @class Logger
|
|
69
|
+
* @typedef {Logger}
|
|
70
|
+
*/
|
|
37
71
|
export default class Logger {
|
|
72
|
+
/**
|
|
73
|
+
* ${1:Description placeholder}
|
|
74
|
+
*
|
|
75
|
+
* @private
|
|
76
|
+
* @type {?LoggerConfig}
|
|
77
|
+
*/
|
|
38
78
|
private _config?: LoggerConfig
|
|
79
|
+
/**
|
|
80
|
+
* ${1:Description placeholder}
|
|
81
|
+
*
|
|
82
|
+
* @private
|
|
83
|
+
* @type {string}
|
|
84
|
+
*/
|
|
39
85
|
private _transactionID: string
|
|
86
|
+
/**
|
|
87
|
+
* ${1:Description placeholder}
|
|
88
|
+
*
|
|
89
|
+
* @private
|
|
90
|
+
* @type {(Array<string> | false)}
|
|
91
|
+
*/
|
|
40
92
|
private _filterBlacklist: Array<string> | false
|
|
93
|
+
/**
|
|
94
|
+
* ${1:Description placeholder}
|
|
95
|
+
*
|
|
96
|
+
* @private
|
|
97
|
+
* @type {LOG_LEVELS}
|
|
98
|
+
*/
|
|
41
99
|
private _LOG_LEVEL: LOG_LEVELS
|
|
100
|
+
/**
|
|
101
|
+
* ${1:Description placeholder}
|
|
102
|
+
*
|
|
103
|
+
* @private
|
|
104
|
+
* @type {*}
|
|
105
|
+
*/
|
|
42
106
|
private origin: any
|
|
43
107
|
|
|
108
|
+
/**
|
|
109
|
+
* Creates an instance of Logger.
|
|
110
|
+
*
|
|
111
|
+
* @constructor
|
|
112
|
+
* @param {(LoggerConfig | undefined)} _config
|
|
113
|
+
* @param {string} transactionID
|
|
114
|
+
*/
|
|
44
115
|
constructor(_config: LoggerConfig | undefined, transactionID: string) {
|
|
45
116
|
abind(this)
|
|
46
117
|
//
|
|
@@ -61,34 +132,81 @@ export default class Logger {
|
|
|
61
132
|
this.log("Using logger with level: " + this._LOG_LEVEL.toString())
|
|
62
133
|
this.debug("logger config: ", this._config)
|
|
63
134
|
}
|
|
135
|
+
/**
|
|
136
|
+
* ${1:Description placeholder}
|
|
137
|
+
*
|
|
138
|
+
* @public
|
|
139
|
+
* @returns {boolean}
|
|
140
|
+
*/
|
|
141
|
+
public notGlobalLogger() {
|
|
142
|
+
return true
|
|
143
|
+
}
|
|
64
144
|
|
|
65
145
|
//Public
|
|
146
|
+
/**
|
|
147
|
+
* ${1:Description placeholder}
|
|
148
|
+
*
|
|
149
|
+
* @param {...{}\} args
|
|
150
|
+
*/
|
|
66
151
|
debug(...args) {
|
|
67
152
|
this._processLog(LOG_LEVELS.DEBUG, args)
|
|
68
153
|
}
|
|
154
|
+
/**
|
|
155
|
+
* ${1:Description placeholder}
|
|
156
|
+
*
|
|
157
|
+
* @param {...{}\} args
|
|
158
|
+
*/
|
|
69
159
|
log(...args) {
|
|
70
160
|
this._processLog(LOG_LEVELS.INFO, args)
|
|
71
161
|
}
|
|
162
|
+
/**
|
|
163
|
+
* ${1:Description placeholder}
|
|
164
|
+
*
|
|
165
|
+
* @param {...{}\} args
|
|
166
|
+
*/
|
|
72
167
|
info(...args) {
|
|
73
168
|
this._processLog(LOG_LEVELS.INFO, args)
|
|
74
169
|
}
|
|
170
|
+
/**
|
|
171
|
+
* ${1:Description placeholder}
|
|
172
|
+
*
|
|
173
|
+
* @param {...{}\} args
|
|
174
|
+
*/
|
|
75
175
|
warning(...args) {
|
|
76
176
|
this._processLog(LOG_LEVELS.WARN, args)
|
|
77
177
|
}
|
|
178
|
+
/**
|
|
179
|
+
* ${1:Description placeholder}
|
|
180
|
+
*
|
|
181
|
+
* @param {...{}\} args
|
|
182
|
+
*/
|
|
78
183
|
warn(...args) {
|
|
79
184
|
this._processLog(LOG_LEVELS.WARN, args)
|
|
80
185
|
}
|
|
186
|
+
/**
|
|
187
|
+
* ${1:Description placeholder}
|
|
188
|
+
*
|
|
189
|
+
* @param {...{}\} args
|
|
190
|
+
*/
|
|
81
191
|
error(...args) {
|
|
82
192
|
this._processLog(LOG_LEVELS.ERROR, args)
|
|
83
193
|
}
|
|
194
|
+
/**
|
|
195
|
+
* ${1:Description placeholder}
|
|
196
|
+
*
|
|
197
|
+
* @param {*} exception
|
|
198
|
+
* @param {...{}\} args
|
|
199
|
+
*/
|
|
84
200
|
exception(exception, ...args) {
|
|
85
201
|
this._exception(exception, args)
|
|
86
202
|
}
|
|
87
|
-
//
|
|
88
|
-
cleanUp() {}
|
|
89
|
-
async flushLogs() {}
|
|
90
203
|
|
|
91
204
|
//initialization
|
|
205
|
+
/**
|
|
206
|
+
* ${1:Description placeholder}
|
|
207
|
+
*
|
|
208
|
+
* @private
|
|
209
|
+
*/
|
|
92
210
|
private _setupBindings(): void {
|
|
93
211
|
global.console = {
|
|
94
212
|
debug: (...args) => this._processLog(LOG_LEVELS.DEBUG, args),
|
|
@@ -98,12 +216,21 @@ export default class Logger {
|
|
|
98
216
|
error: (...args) => this._processLog(LOG_LEVELS.ERROR, args),
|
|
99
217
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
100
218
|
// @ts-ignore
|
|
101
|
-
warning: (...args) => this._processLog(
|
|
219
|
+
warning: (...args) => this._processLog(LOG_LEVELS.WARN, args),
|
|
102
220
|
exception: (exception, ...args) => this._exception(exception, args),
|
|
103
221
|
}
|
|
104
222
|
}
|
|
105
223
|
|
|
106
224
|
/* Formatters */
|
|
225
|
+
/**
|
|
226
|
+
* ${1:Description placeholder}
|
|
227
|
+
*
|
|
228
|
+
* @private
|
|
229
|
+
* @param {LOG_LEVELS} level
|
|
230
|
+
* @param {Array<string>} msg
|
|
231
|
+
* @param {string} caller
|
|
232
|
+
* @returns {string}
|
|
233
|
+
*/
|
|
107
234
|
private _formattedLog(
|
|
108
235
|
level: LOG_LEVELS,
|
|
109
236
|
msg: Array<string>,
|
|
@@ -111,15 +238,24 @@ export default class Logger {
|
|
|
111
238
|
): string {
|
|
112
239
|
if (Utils.isHybridlessContainer() && this._transactionID) {
|
|
113
240
|
return (
|
|
114
|
-
|
|
241
|
+
`${this._transactionID}` +
|
|
115
242
|
` [${level.toString()}] [${caller}] ${msg
|
|
116
243
|
.map(this._suppressSensitiveInfo)
|
|
117
244
|
.join(" ")}`
|
|
118
245
|
)
|
|
119
246
|
} else {
|
|
120
|
-
return `
|
|
247
|
+
return `[${level.toString()}] [${caller}] ${msg
|
|
248
|
+
.map(this._suppressSensitiveInfo)
|
|
249
|
+
.join(" ")}`
|
|
121
250
|
}
|
|
122
251
|
}
|
|
252
|
+
/**
|
|
253
|
+
* ${1:Description placeholder}
|
|
254
|
+
*
|
|
255
|
+
* @private
|
|
256
|
+
* @param {number} index
|
|
257
|
+
* @returns {string}
|
|
258
|
+
*/
|
|
123
259
|
private _callerName(index: number): string {
|
|
124
260
|
const safeIndex = Math.min(index, stackTrace.get().length)
|
|
125
261
|
if (stackTrace.get()[safeIndex]) {
|
|
@@ -135,6 +271,13 @@ export default class Logger {
|
|
|
135
271
|
return ""
|
|
136
272
|
}
|
|
137
273
|
/* Helpers (core functionality) */
|
|
274
|
+
/**
|
|
275
|
+
* ${1:Description placeholder}
|
|
276
|
+
*
|
|
277
|
+
* @private
|
|
278
|
+
* @param {LOG_LEVELS} level
|
|
279
|
+
* @param {*} args
|
|
280
|
+
*/
|
|
138
281
|
private _processLog(level: LOG_LEVELS, args: any): void {
|
|
139
282
|
if (level < this._LOG_LEVEL) return
|
|
140
283
|
//get args
|
|
@@ -150,6 +293,13 @@ export default class Logger {
|
|
|
150
293
|
// todo: improve error stack
|
|
151
294
|
this._pushLog(level, this._formattedLog(level, msg, this._callerName(3)))
|
|
152
295
|
}
|
|
296
|
+
/**
|
|
297
|
+
* ${1:Description placeholder}
|
|
298
|
+
*
|
|
299
|
+
* @private
|
|
300
|
+
* @param {Error} exception
|
|
301
|
+
* @param {...{}\} args
|
|
302
|
+
*/
|
|
153
303
|
private _exception(exception: Error, ...args): void {
|
|
154
304
|
//format message
|
|
155
305
|
const msg: Array<string> = []
|
|
@@ -164,12 +314,26 @@ export default class Logger {
|
|
|
164
314
|
this._formattedLog(LOG_LEVELS.ERROR, msg, this._callerName(3)),
|
|
165
315
|
)
|
|
166
316
|
}
|
|
317
|
+
/**
|
|
318
|
+
* ${1:Description placeholder}
|
|
319
|
+
*
|
|
320
|
+
* @private
|
|
321
|
+
* @param {LOG_LEVELS} level
|
|
322
|
+
* @param {string} fMsg
|
|
323
|
+
*/
|
|
167
324
|
private _pushLog(level: LOG_LEVELS, fMsg: string): void {
|
|
168
325
|
// push into logs stack
|
|
169
326
|
// this._logs.push(fMsg);
|
|
170
327
|
DEFAULT_LOG_FUNCTION.apply(PURE_CONSOLE, [fMsg])
|
|
171
328
|
}
|
|
172
329
|
/* Sensitive information handling */
|
|
330
|
+
/**
|
|
331
|
+
* ${1:Description placeholder}
|
|
332
|
+
*
|
|
333
|
+
* @private
|
|
334
|
+
* @param {*} value
|
|
335
|
+
* @returns {string}
|
|
336
|
+
*/
|
|
173
337
|
private _suppressSensitiveInfo(value: any): string {
|
|
174
338
|
//realy false
|
|
175
339
|
if (!this._filterBlacklist) return value
|
|
@@ -182,21 +346,11 @@ export default class Logger {
|
|
|
182
346
|
value.toLowerCase().includes(f.toLowerCase()),
|
|
183
347
|
)
|
|
184
348
|
: false
|
|
185
|
-
if (match) value = "**
|
|
349
|
+
if (match) value = "**SUPPRESSED_SENSITIVE_DATA**"
|
|
186
350
|
})
|
|
187
351
|
}
|
|
188
352
|
return value
|
|
189
|
-
}
|
|
190
|
-
//key based replacement
|
|
191
|
-
Object.keys(value).forEach(function (elt) {
|
|
192
|
-
const match = this._filterBlacklist.find((f) =>
|
|
193
|
-
elt.toLowerCase().includes(f.toLowerCase()),
|
|
194
|
-
)
|
|
195
|
-
if (match) value[elt] = "**SUPRESSED_SENSITIVE_DATA**"
|
|
196
|
-
})
|
|
197
|
-
return value
|
|
198
|
-
} else if (Array.isArray(value))
|
|
199
|
-
return value.map((v) => this._suppressSensitiveInfo(v)).join(" ")
|
|
353
|
+
}
|
|
200
354
|
return value
|
|
201
355
|
}
|
|
202
356
|
}
|