@creator.co/wapi 1.2.4 → 1.2.6
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 +1 -1
- package/README.md +216 -5
- package/dist/index.d.ts +15 -0
- package/dist/index.js.map +1 -1
- package/dist/jest.config.js +1 -1
- package/dist/jest.config.js.map +1 -1
- package/dist/package.json +13 -2
- package/dist/src/API/Request.d.ts +45 -82
- package/dist/src/API/Request.js +49 -77
- package/dist/src/API/Request.js.map +1 -1
- package/dist/src/API/Response.d.ts +94 -163
- package/dist/src/API/Response.js +101 -161
- package/dist/src/API/Response.js.map +1 -1
- package/dist/src/API/Utils.d.ts +21 -42
- package/dist/src/API/Utils.js +22 -43
- package/dist/src/API/Utils.js.map +1 -1
- package/dist/src/BaseEvent/EventProcessor.d.ts +32 -55
- package/dist/src/BaseEvent/EventProcessor.js +30 -38
- package/dist/src/BaseEvent/EventProcessor.js.map +1 -1
- package/dist/src/BaseEvent/Process.d.ts +20 -43
- package/dist/src/BaseEvent/Process.js +16 -27
- package/dist/src/BaseEvent/Process.js.map +1 -1
- package/dist/src/BaseEvent/Transaction.d.ts +104 -2
- package/dist/src/BaseEvent/Transaction.js +196 -41
- package/dist/src/BaseEvent/Transaction.js.map +1 -1
- package/dist/src/Config/Configuration.d.ts +48 -66
- package/dist/src/Config/Configuration.js +25 -42
- package/dist/src/Config/Configuration.js.map +1 -1
- package/dist/src/Config/EnvironmentVar.d.ts +30 -57
- package/dist/src/Config/EnvironmentVar.js +28 -41
- package/dist/src/Config/EnvironmentVar.js.map +1 -1
- package/dist/src/Crypto/Crypto.d.ts +17 -35
- package/dist/src/Crypto/Crypto.js +12 -21
- package/dist/src/Crypto/Crypto.js.map +1 -1
- package/dist/src/Crypto/JWT.d.ts +21 -32
- package/dist/src/Crypto/JWT.js +14 -22
- package/dist/src/Crypto/JWT.js.map +1 -1
- package/dist/src/Database/Database.d.ts +18 -0
- package/dist/src/Database/Database.js +18 -0
- package/dist/src/Database/Database.js.map +1 -0
- package/dist/src/Database/DatabaseManager.d.ts +32 -0
- package/dist/src/Database/DatabaseManager.js +50 -0
- package/dist/src/Database/DatabaseManager.js.map +1 -0
- package/dist/src/Database/DatabaseTransaction.d.ts +65 -0
- package/dist/src/Database/DatabaseTransaction.js +183 -0
- package/dist/src/Database/DatabaseTransaction.js.map +1 -0
- package/dist/src/Database/integrations/knex/KnexDatabase.d.ts +22 -0
- package/dist/src/Database/integrations/knex/KnexDatabase.js +108 -0
- package/dist/src/Database/integrations/knex/KnexDatabase.js.map +1 -0
- package/dist/src/Database/integrations/knex/KnexTransaction.d.ts +37 -0
- package/dist/src/Database/integrations/knex/KnexTransaction.js +60 -0
- package/dist/src/Database/integrations/knex/KnexTransaction.js.map +1 -0
- package/dist/src/Database/integrations/pgsql/PostgresDatabase.d.ts +30 -0
- package/dist/src/Database/integrations/pgsql/PostgresDatabase.js +108 -0
- package/dist/src/Database/integrations/pgsql/PostgresDatabase.js.map +1 -0
- package/dist/src/Database/integrations/pgsql/PostgresTransaction.d.ts +37 -0
- package/dist/src/Database/integrations/pgsql/PostgresTransaction.js +60 -0
- package/dist/src/Database/integrations/pgsql/PostgresTransaction.js.map +1 -0
- package/dist/src/Globals.d.ts +26 -94
- package/dist/src/Globals.js +26 -95
- package/dist/src/Globals.js.map +1 -1
- package/dist/src/Logger/Logger.d.ts +82 -105
- package/dist/src/Logger/Logger.js +111 -136
- package/dist/src/Logger/Logger.js.map +1 -1
- package/dist/src/Mailer/Mailer.d.ts +39 -75
- package/dist/src/Mailer/Mailer.js +36 -65
- package/dist/src/Mailer/Mailer.js.map +1 -1
- package/dist/src/Publisher/Publisher.d.ts +17 -25
- package/dist/src/Publisher/Publisher.js +21 -32
- package/dist/src/Publisher/Publisher.js.map +1 -1
- package/dist/src/Server/RouteResolver.d.ts +14 -22
- package/dist/src/Server/RouteResolver.js +21 -34
- package/dist/src/Server/RouteResolver.js.map +1 -1
- package/dist/src/Server/Router.d.ts +72 -51
- package/dist/src/Server/Router.js +8 -17
- package/dist/src/Server/Router.js.map +1 -1
- package/dist/src/Server/lib/ContainerServer.d.ts +15 -31
- package/dist/src/Server/lib/ContainerServer.js +13 -28
- package/dist/src/Server/lib/ContainerServer.js.map +1 -1
- package/dist/src/Server/lib/Server.d.ts +17 -32
- package/dist/src/Server/lib/Server.js +18 -28
- package/dist/src/Server/lib/Server.js.map +1 -1
- package/dist/src/Server/lib/container/GenericHandler.d.ts +5 -0
- package/dist/src/Server/lib/container/GenericHandler.js +16 -3
- package/dist/src/Server/lib/container/GenericHandler.js.map +1 -1
- package/dist/src/Server/lib/container/GenericHandlerEvent.d.ts +22 -37
- package/dist/src/Server/lib/container/GenericHandlerEvent.js +29 -41
- package/dist/src/Server/lib/container/GenericHandlerEvent.js.map +1 -1
- package/dist/src/Server/lib/container/HealthHandler.d.ts +6 -0
- package/dist/src/Server/lib/container/HealthHandler.js +6 -0
- package/dist/src/Server/lib/container/HealthHandler.js.map +1 -1
- package/dist/src/Server/lib/container/Proxy.d.ts +24 -52
- package/dist/src/Server/lib/container/Proxy.js +52 -52
- package/dist/src/Server/lib/container/Proxy.js.map +1 -1
- package/dist/src/Server/lib/container/Utils.d.ts +6 -10
- package/dist/src/Server/lib/container/Utils.js +6 -10
- package/dist/src/Server/lib/container/Utils.js.map +1 -1
- package/dist/src/Validation/Validator.d.ts +9 -13
- package/dist/src/Validation/Validator.js +8 -12
- package/dist/src/Validation/Validator.js.map +1 -1
- package/index.ts +15 -0
- package/jest.config.ts +1 -1
- package/package.json +13 -2
- package/src/API/Request.ts +66 -84
- package/src/API/Response.ts +144 -203
- package/src/API/Utils.ts +28 -44
- package/src/BaseEvent/EventProcessor.ts +52 -77
- package/src/BaseEvent/Process.ts +27 -52
- package/src/BaseEvent/Transaction.ts +147 -27
- package/src/Config/Configuration.ts +59 -76
- package/src/Config/EnvironmentVar.ts +39 -62
- package/src/Crypto/Crypto.ts +20 -36
- package/src/Crypto/JWT.ts +31 -35
- package/src/Database/Database.ts +19 -0
- package/src/Database/DatabaseManager.ts +51 -0
- package/src/Database/DatabaseTransaction.ts +118 -0
- package/src/Database/integrations/knex/KnexDatabase.ts +47 -0
- package/src/Database/integrations/knex/KnexTransaction.ts +51 -0
- package/src/Database/integrations/pgsql/PostgresDatabase.ts +49 -0
- package/src/Database/integrations/pgsql/PostgresTransaction.ts +54 -0
- package/src/Database/types.d.ts +49 -0
- package/src/Globals.ts +28 -96
- package/src/Logger/Logger.ts +141 -160
- package/src/Mailer/Mailer.ts +43 -76
- package/src/Publisher/Publisher.ts +31 -40
- package/src/Server/RouteResolver.ts +31 -52
- package/src/Server/Router.ts +75 -54
- package/src/Server/lib/ContainerServer.ts +20 -32
- package/src/Server/lib/Server.ts +19 -34
- package/src/Server/lib/container/GenericHandler.ts +17 -3
- package/src/Server/lib/container/GenericHandlerEvent.ts +44 -54
- package/src/Server/lib/container/HealthHandler.ts +6 -0
- package/src/Server/lib/container/Proxy.ts +39 -58
- package/src/Server/lib/container/Utils.ts +7 -10
- package/src/Validation/Validator.ts +11 -13
- package/tests/API/Response.test.ts +55 -56
- package/tests/BaseEvent/EventProcessor.test.ts +49 -50
- package/tests/BaseEvent/Process.test.ts +2 -2
- package/tests/BaseEvent/Transaction.test.ts +102 -44
- package/tests/Config/Config.test.ts +27 -27
- package/tests/Config/EnvironmentVar.test.ts +54 -18
- package/tests/Database/DatabaseManager.test.ts +55 -0
- package/tests/Database/integrations/knex/KnexDatabase.test.ts +53 -0
- package/tests/Database/integrations/knex/KnexTransaction.test.ts +133 -0
- package/tests/Database/integrations/pg/PostgresDatabase.test.ts +50 -0
- package/tests/Database/integrations/pg/PostgresTransaction.test.ts +51 -0
- package/tests/Publisher/Publisher.test.ts +3 -3
- package/tests/Server/lib/ContainerServer.test.ts +21 -22
- package/tests/Server/lib/container/GenericHandler.test.ts +31 -32
- package/tests/Server/lib/container/GenericHandlerEvent.test.ts +2 -2
- package/tests/Server/lib/container/HealthHandler.test.ts +6 -7
- package/tests/Server/lib/container/Proxy.test.ts +37 -35
- package/tsconfig.json +6 -1
package/src/Logger/Logger.ts
CHANGED
|
@@ -2,14 +2,15 @@ import * as abind from 'abind'
|
|
|
2
2
|
import * as stringify from 'json-stringify-safe'
|
|
3
3
|
import * as stackTrace from 'stack-trace'
|
|
4
4
|
|
|
5
|
-
//
|
|
6
5
|
import Utils from '../API/Utils'
|
|
7
|
-
|
|
6
|
+
|
|
8
7
|
/**
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* @
|
|
12
|
-
* @
|
|
8
|
+
* Enumeration of log levels.
|
|
9
|
+
* @enum {string}
|
|
10
|
+
* @property {string} DEBUG - Debug log level.
|
|
11
|
+
* @property {string} INFO - Info log level.
|
|
12
|
+
* @property {string} WARN - Warning log level.
|
|
13
|
+
* @property {string} ERROR - Error log level.
|
|
13
14
|
*/
|
|
14
15
|
export enum LOG_LEVELS {
|
|
15
16
|
DEBUG = 'DEBUG',
|
|
@@ -18,22 +19,22 @@ export enum LOG_LEVELS {
|
|
|
18
19
|
ERROR = 'ERROR',
|
|
19
20
|
}
|
|
20
21
|
/**
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
22
|
+
* A constant that represents the console object to be used for logging.
|
|
23
|
+
* If the console object has a property named 'notGlobalLogger', it is assumed
|
|
24
|
+
* to be a custom logger and the 'origin' property is used as the console object.
|
|
25
|
+
* Otherwise, the global console object is used.
|
|
26
|
+
* @type {Console}
|
|
24
27
|
*/
|
|
25
28
|
const PURE_CONSOLE = console['notGlobalLogger'] ? console['origin'] : console
|
|
26
29
|
/**
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* @type {*}
|
|
30
|
+
* The default log function that is used for logging messages.
|
|
31
|
+
* @type {Function}
|
|
30
32
|
*/
|
|
31
33
|
const DEFAULT_LOG_FUNCTION = PURE_CONSOLE.log.bind(PURE_CONSOLE)
|
|
32
|
-
|
|
34
|
+
|
|
33
35
|
/**
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
* @type {{}\}
|
|
36
|
+
* An array of sensitive strings that should be blacklisted or excluded from certain operations.
|
|
37
|
+
* This array includes strings such as 'password', 'phonenumber', 'resetCode', etc.
|
|
37
38
|
*/
|
|
38
39
|
const blacklist = [
|
|
39
40
|
'password',
|
|
@@ -49,206 +50,191 @@ const blacklist = [
|
|
|
49
50
|
'UserCode',
|
|
50
51
|
'paymentMethodNonce',
|
|
51
52
|
]
|
|
52
|
-
|
|
53
|
+
|
|
53
54
|
/**
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
* @
|
|
57
|
-
* @
|
|
55
|
+
* Configuration options for the logger.
|
|
56
|
+
* @typedef {Object} LoggerConfig
|
|
57
|
+
* @property {boolean | Array<string>} [sensitiveFilteringKeywords] - Specifies whether to filter sensitive keywords in log messages. Can be a boolean value or an array of strings.
|
|
58
|
+
* @property {LOG_LEVELS | string} [logLevel] - The log level to use for logging. Can be one of the predefined log levels or a custom string value.
|
|
58
59
|
*/
|
|
59
60
|
export type LoggerConfig = {
|
|
60
61
|
sensitiveFilteringKeywords?: boolean | Array<string>
|
|
61
62
|
logLevel?: LOG_LEVELS | string
|
|
62
63
|
}
|
|
63
|
-
|
|
64
|
+
|
|
64
65
|
/**
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
* @export
|
|
68
|
-
* @class Logger
|
|
69
|
-
* @typedef {Logger}
|
|
66
|
+
* Logger class for logging messages with different log levels.
|
|
70
67
|
*/
|
|
71
68
|
export default class Logger {
|
|
72
69
|
/**
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
* @private
|
|
76
|
-
* @type {?LoggerConfig}
|
|
70
|
+
* The optional configuration object for the logger.
|
|
77
71
|
*/
|
|
78
|
-
private
|
|
72
|
+
private config?: LoggerConfig
|
|
79
73
|
/**
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
* @private
|
|
74
|
+
* Private property representing the transaction ID.
|
|
83
75
|
* @type {string}
|
|
76
|
+
* @private
|
|
84
77
|
*/
|
|
85
|
-
private
|
|
78
|
+
private transactionID: string
|
|
86
79
|
/**
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
* @private
|
|
90
|
-
* @type {(Array<string> | false)}
|
|
80
|
+
* An array of strings representing a blacklist of filters, or false if no blacklist is set.
|
|
91
81
|
*/
|
|
92
|
-
private
|
|
82
|
+
private filterBlacklist: Array<string> | false
|
|
93
83
|
/**
|
|
94
|
-
*
|
|
95
|
-
*
|
|
84
|
+
* The current log level for the application.
|
|
96
85
|
* @private
|
|
97
86
|
* @type {LOG_LEVELS}
|
|
98
87
|
*/
|
|
99
88
|
private _LOG_LEVEL: LOG_LEVELS
|
|
100
89
|
/**
|
|
101
|
-
*
|
|
102
|
-
*
|
|
90
|
+
* The origin of the object.
|
|
103
91
|
* @private
|
|
104
|
-
* @type {
|
|
92
|
+
* @type {any}
|
|
105
93
|
*/
|
|
106
94
|
private origin: any
|
|
107
95
|
|
|
108
96
|
/**
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
* @
|
|
112
|
-
* @
|
|
113
|
-
* @param {string} transactionID
|
|
97
|
+
* Constructs a Logger object with the given configuration and transaction ID.
|
|
98
|
+
* @param {config} config - The configuration object for the logger. Can be undefined.
|
|
99
|
+
* @param {string} transactionID - The ID of the transaction associated with the logger.
|
|
100
|
+
* @returns None
|
|
114
101
|
*/
|
|
115
|
-
constructor(
|
|
102
|
+
constructor(config: LoggerConfig | undefined, transactionID: string) {
|
|
116
103
|
abind(this)
|
|
117
104
|
//
|
|
118
105
|
this.origin = PURE_CONSOLE
|
|
119
|
-
this._LOG_LEVEL =
|
|
120
|
-
? LOG_LEVELS[
|
|
106
|
+
this._LOG_LEVEL = config?.logLevel
|
|
107
|
+
? LOG_LEVELS[config?.logLevel] || LOG_LEVELS.DEBUG
|
|
121
108
|
: LOG_LEVELS.DEBUG
|
|
122
|
-
this.
|
|
123
|
-
this.
|
|
124
|
-
this.
|
|
125
|
-
? Array.isArray(this.
|
|
126
|
-
? this.
|
|
109
|
+
this.config = config || {}
|
|
110
|
+
this.transactionID = transactionID
|
|
111
|
+
this.filterBlacklist = this.config.sensitiveFilteringKeywords
|
|
112
|
+
? Array.isArray(this.config.sensitiveFilteringKeywords)
|
|
113
|
+
? this.config.sensitiveFilteringKeywords
|
|
127
114
|
: blacklist
|
|
128
115
|
: false
|
|
129
116
|
//
|
|
130
|
-
this.
|
|
117
|
+
this.setupBindings()
|
|
131
118
|
//
|
|
132
119
|
this.log('Using logger with level: ' + this._LOG_LEVEL.toString())
|
|
133
|
-
this.debug('logger config: ', this.
|
|
120
|
+
this.debug('logger config: ', this.config)
|
|
134
121
|
}
|
|
122
|
+
|
|
135
123
|
/**
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
* @public
|
|
139
|
-
* @returns {boolean}
|
|
124
|
+
* Returns a boolean value indicating whether the notGlobalLogger function is executed successfully.
|
|
125
|
+
* @returns {boolean} - true if the function is executed successfully, false otherwise.
|
|
140
126
|
*/
|
|
141
127
|
public notGlobalLogger() {
|
|
142
128
|
return true
|
|
143
129
|
}
|
|
144
130
|
|
|
145
|
-
//Public
|
|
146
131
|
/**
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
* @
|
|
132
|
+
* Logs the given arguments with the debug log level.
|
|
133
|
+
* @param {...any} args - The arguments to be logged.
|
|
134
|
+
* @returns None
|
|
150
135
|
*/
|
|
151
136
|
debug(...args) {
|
|
152
|
-
this.
|
|
137
|
+
this.processLog(LOG_LEVELS.DEBUG, args)
|
|
153
138
|
}
|
|
139
|
+
|
|
154
140
|
/**
|
|
155
|
-
*
|
|
156
|
-
*
|
|
157
|
-
* @
|
|
141
|
+
* Logs the given arguments with the INFO log level.
|
|
142
|
+
* @param {...any} args - The arguments to be logged.
|
|
143
|
+
* @returns None
|
|
158
144
|
*/
|
|
159
145
|
log(...args) {
|
|
160
|
-
this.
|
|
146
|
+
this.processLog(LOG_LEVELS.INFO, args)
|
|
161
147
|
}
|
|
148
|
+
|
|
162
149
|
/**
|
|
163
|
-
*
|
|
164
|
-
*
|
|
165
|
-
* @
|
|
150
|
+
* Logs an informational message.
|
|
151
|
+
* @param {...any} args - The message(s) to log.
|
|
152
|
+
* @returns None
|
|
166
153
|
*/
|
|
167
154
|
info(...args) {
|
|
168
|
-
this.
|
|
155
|
+
this.processLog(LOG_LEVELS.INFO, args)
|
|
169
156
|
}
|
|
157
|
+
|
|
170
158
|
/**
|
|
171
|
-
*
|
|
172
|
-
*
|
|
173
|
-
* @
|
|
159
|
+
* Logs a warning message with the provided arguments.
|
|
160
|
+
* @param {...any} args - The arguments to be logged as a warning message.
|
|
161
|
+
* @returns None
|
|
174
162
|
*/
|
|
175
163
|
warning(...args) {
|
|
176
|
-
this.
|
|
164
|
+
this.processLog(LOG_LEVELS.WARN, args)
|
|
177
165
|
}
|
|
166
|
+
|
|
178
167
|
/**
|
|
179
|
-
*
|
|
180
|
-
*
|
|
181
|
-
* @
|
|
168
|
+
* Logs a warning message to the console.
|
|
169
|
+
* @param {...any} args - The arguments to be logged.
|
|
170
|
+
* @returns None
|
|
182
171
|
*/
|
|
183
172
|
warn(...args) {
|
|
184
|
-
this.
|
|
173
|
+
this.processLog(LOG_LEVELS.WARN, args)
|
|
185
174
|
}
|
|
175
|
+
|
|
186
176
|
/**
|
|
187
|
-
*
|
|
188
|
-
*
|
|
189
|
-
* @
|
|
177
|
+
* Logs an error message with the given arguments.
|
|
178
|
+
* @param {...any} args - The arguments to log as an error message.
|
|
179
|
+
* @returns None
|
|
190
180
|
*/
|
|
191
181
|
error(...args) {
|
|
192
|
-
this.
|
|
182
|
+
this.processLog(LOG_LEVELS.ERROR, args)
|
|
193
183
|
}
|
|
184
|
+
|
|
194
185
|
/**
|
|
195
|
-
*
|
|
196
|
-
*
|
|
197
|
-
* @param {
|
|
198
|
-
* @
|
|
186
|
+
* Logs an exception with optional additional arguments.
|
|
187
|
+
* @param {any} exception - The exception to log.
|
|
188
|
+
* @param {...any} args - Additional arguments to include in the log.
|
|
189
|
+
* @returns None
|
|
199
190
|
*/
|
|
200
191
|
exception(exception, ...args) {
|
|
201
|
-
this.
|
|
192
|
+
this.iexception(exception, args)
|
|
202
193
|
}
|
|
203
194
|
|
|
204
|
-
//initialization
|
|
205
195
|
/**
|
|
206
|
-
*
|
|
207
|
-
*
|
|
196
|
+
* Sets up the console bindings for logging purposes.
|
|
208
197
|
* @private
|
|
198
|
+
* @returns None
|
|
209
199
|
*/
|
|
210
|
-
private
|
|
200
|
+
private setupBindings(): void {
|
|
211
201
|
global.console = {
|
|
212
|
-
debug: (...args) => this.
|
|
213
|
-
log: (...args) => this.
|
|
214
|
-
info: (...args) => this.
|
|
215
|
-
warn: (...args) => this.
|
|
216
|
-
error: (...args) => this.
|
|
202
|
+
debug: (...args) => this.processLog(LOG_LEVELS.DEBUG, args),
|
|
203
|
+
log: (...args) => this.processLog(LOG_LEVELS.INFO, args),
|
|
204
|
+
info: (...args) => this.processLog(LOG_LEVELS.INFO, args),
|
|
205
|
+
warn: (...args) => this.processLog(LOG_LEVELS.WARN, args),
|
|
206
|
+
error: (...args) => this.processLog(LOG_LEVELS.ERROR, args),
|
|
217
207
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
218
208
|
// @ts-ignore
|
|
219
|
-
warning: (...args) => this.
|
|
220
|
-
exception: (exception, ...args) => this.
|
|
209
|
+
warning: (...args) => this.processLog(LOG_LEVELS.WARN, args),
|
|
210
|
+
exception: (exception, ...args) => this.iexception(exception, args),
|
|
221
211
|
}
|
|
222
212
|
}
|
|
223
213
|
|
|
224
|
-
/* Formatters */
|
|
225
214
|
/**
|
|
226
|
-
*
|
|
227
|
-
*
|
|
228
|
-
* @
|
|
229
|
-
* @param {
|
|
230
|
-
* @
|
|
231
|
-
* @param {string} caller
|
|
232
|
-
* @returns {string}
|
|
215
|
+
* Formats a log message with the specified log level, message, and caller.
|
|
216
|
+
* @param {LOG_LEVELS} level - The log level of the message.
|
|
217
|
+
* @param {Array<string>} msg - An array of strings representing the message.
|
|
218
|
+
* @param {string} caller - The name of the caller function.
|
|
219
|
+
* @returns {string} - The formatted log message.
|
|
233
220
|
*/
|
|
234
|
-
private
|
|
235
|
-
if (Utils.isHybridlessContainer() && this.
|
|
221
|
+
private formattedLog(level: LOG_LEVELS, msg: Array<string>, caller: string): string {
|
|
222
|
+
if (Utils.isHybridlessContainer() && this.transactionID) {
|
|
236
223
|
return (
|
|
237
|
-
`${this.
|
|
238
|
-
` [${level.toString()}] [${caller}] ${msg.map(this.
|
|
224
|
+
`${this.transactionID}` +
|
|
225
|
+
` [${level.toString()}] [${caller}] ${msg.map(this.suppressSensitiveInfo).join(' ')}`
|
|
239
226
|
)
|
|
240
227
|
} else {
|
|
241
|
-
return `[${level.toString()}] [${caller}] ${msg.map(this.
|
|
228
|
+
return `[${level.toString()}] [${caller}] ${msg.map(this.suppressSensitiveInfo).join(' ')}`
|
|
242
229
|
}
|
|
243
230
|
}
|
|
231
|
+
|
|
244
232
|
/**
|
|
245
|
-
*
|
|
246
|
-
*
|
|
247
|
-
* @
|
|
248
|
-
* @param {number} index
|
|
249
|
-
* @returns {string}
|
|
233
|
+
* Returns the name of the caller at the specified index in the call stack.
|
|
234
|
+
* @param {number} index - The index of the caller in the call stack.
|
|
235
|
+
* @returns {string} The name of the caller, including the file name and line number.
|
|
250
236
|
*/
|
|
251
|
-
private
|
|
237
|
+
private callerName(index: number): string {
|
|
252
238
|
const safeIndex = Math.min(index, stackTrace.get().length)
|
|
253
239
|
if (stackTrace.get()[safeIndex]) {
|
|
254
240
|
let callerName = stackTrace.get()[safeIndex]
|
|
@@ -262,15 +248,14 @@ export default class Logger {
|
|
|
262
248
|
}
|
|
263
249
|
return ''
|
|
264
250
|
}
|
|
265
|
-
|
|
251
|
+
|
|
266
252
|
/**
|
|
267
|
-
*
|
|
268
|
-
*
|
|
269
|
-
* @
|
|
270
|
-
* @
|
|
271
|
-
* @param {*} args
|
|
253
|
+
* Processes a log message based on the specified log level and arguments.
|
|
254
|
+
* @param {LOG_LEVELS} level - The log level of the message.
|
|
255
|
+
* @param {any[]} args - The arguments to be logged.
|
|
256
|
+
* @returns None
|
|
272
257
|
*/
|
|
273
|
-
private
|
|
258
|
+
private processLog(level: LOG_LEVELS, args: any): void {
|
|
274
259
|
if (level < this._LOG_LEVEL) return
|
|
275
260
|
//get args
|
|
276
261
|
const msg: Array<string> = []
|
|
@@ -281,16 +266,16 @@ export default class Logger {
|
|
|
281
266
|
}
|
|
282
267
|
//push into logs stack
|
|
283
268
|
// todo: improve error stack
|
|
284
|
-
this.
|
|
269
|
+
this.pushLog(level, this.formattedLog(level, msg, this.callerName(3)))
|
|
285
270
|
}
|
|
271
|
+
|
|
286
272
|
/**
|
|
287
|
-
*
|
|
288
|
-
*
|
|
289
|
-
* @
|
|
290
|
-
* @
|
|
291
|
-
* @param {...{}\} args
|
|
273
|
+
* Logs an exception along with additional arguments and the stack trace.
|
|
274
|
+
* @param {Error} exception - The exception object to log.
|
|
275
|
+
* @param {...any} args - Additional arguments to include in the log.
|
|
276
|
+
* @returns None
|
|
292
277
|
*/
|
|
293
|
-
private
|
|
278
|
+
private iexception(exception: Error, ...args): void {
|
|
294
279
|
//format message
|
|
295
280
|
const msg: Array<string> = []
|
|
296
281
|
//push exeception
|
|
@@ -299,37 +284,33 @@ export default class Logger {
|
|
|
299
284
|
for (const arg of args) if (arg != exception) msg.push(arg)
|
|
300
285
|
if (exception.stack) msg.push(exception.stack) //push Exeception stack at the end
|
|
301
286
|
//push into logs stack
|
|
302
|
-
this.
|
|
287
|
+
this.pushLog(LOG_LEVELS.ERROR, this.formattedLog(LOG_LEVELS.ERROR, msg, this.callerName(3)))
|
|
303
288
|
}
|
|
289
|
+
|
|
304
290
|
/**
|
|
305
|
-
*
|
|
306
|
-
*
|
|
307
|
-
* @
|
|
308
|
-
* @
|
|
309
|
-
* @param {string} fMsg
|
|
291
|
+
* Pushes a log message to the console with the specified log level.
|
|
292
|
+
* @param {LOG_LEVELS} level - The log level of the message.
|
|
293
|
+
* @param {string} fMsg - The formatted log message.
|
|
294
|
+
* @returns None
|
|
310
295
|
*/
|
|
311
|
-
private
|
|
312
|
-
// push into logs stack
|
|
313
|
-
// this._logs.push(fMsg);
|
|
296
|
+
private pushLog(level: LOG_LEVELS, fMsg: string): void {
|
|
314
297
|
DEFAULT_LOG_FUNCTION.apply(PURE_CONSOLE, [fMsg])
|
|
315
298
|
}
|
|
316
|
-
|
|
299
|
+
|
|
317
300
|
/**
|
|
318
|
-
*
|
|
319
|
-
*
|
|
320
|
-
* @
|
|
321
|
-
* @param {*} value
|
|
322
|
-
* @returns {string}
|
|
301
|
+
* Suppresses sensitive information in the given value based on the filter blacklist.
|
|
302
|
+
* @param {any} value - The value to suppress sensitive information from.
|
|
303
|
+
* @returns {string} - The value with sensitive information suppressed.
|
|
323
304
|
*/
|
|
324
|
-
private
|
|
305
|
+
private suppressSensitiveInfo(value: any): string {
|
|
325
306
|
//realy false
|
|
326
|
-
if (!this.
|
|
307
|
+
if (!this.filterBlacklist) return value
|
|
327
308
|
if (typeof value == 'string') {
|
|
328
309
|
//content based replacement
|
|
329
|
-
if (this.
|
|
330
|
-
this.
|
|
331
|
-
const match = this.
|
|
332
|
-
? this.
|
|
310
|
+
if (this.filterBlacklist) {
|
|
311
|
+
this.filterBlacklist.forEach(() => {
|
|
312
|
+
const match = this.filterBlacklist
|
|
313
|
+
? this.filterBlacklist.find(f => value.toLowerCase().includes(f.toLowerCase()))
|
|
333
314
|
: false
|
|
334
315
|
if (match) value = '**SUPPRESSED_SENSITIVE_DATA**'
|
|
335
316
|
})
|
package/src/Mailer/Mailer.ts
CHANGED
|
@@ -4,48 +4,30 @@ import * as Email from 'email-templates'
|
|
|
4
4
|
import * as nodemailer from 'nodemailer'
|
|
5
5
|
import type * as SESTransport from 'nodemailer/lib/ses-transport'
|
|
6
6
|
|
|
7
|
-
/**
|
|
8
|
-
* ${1:Description placeholder}
|
|
9
|
-
*
|
|
10
|
-
* @export
|
|
11
|
-
* @class Mailer
|
|
12
|
-
* @typedef {Mailer}
|
|
13
|
-
*/
|
|
14
7
|
export default class Mailer {
|
|
15
8
|
/**
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* @private
|
|
19
|
-
* @readonly
|
|
9
|
+
* The starting point of a range.
|
|
20
10
|
* @type {string}
|
|
21
11
|
*/
|
|
22
12
|
private readonly from: string
|
|
23
13
|
/**
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
* @private
|
|
27
|
-
* @readonly
|
|
14
|
+
* The default file template for the application.
|
|
28
15
|
* @type {string}
|
|
29
16
|
*/
|
|
30
17
|
private readonly templateDefaultFile: string = 'html'
|
|
31
18
|
/**
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
* @private
|
|
35
|
-
* @readonly
|
|
36
|
-
* @type {ReturnType<
|
|
37
|
-
* typeof nodemailer.createTransport<SESTransport.SentMessageInfo>
|
|
38
|
-
* >}
|
|
19
|
+
* The transporter object used for sending emails using the AWS SES service.
|
|
20
|
+
* @type {ReturnType<typeof nodemailer.createTransport<SESTransport.SentMessageInfo>>}
|
|
39
21
|
*/
|
|
40
22
|
private readonly transporter: ReturnType<
|
|
41
23
|
typeof nodemailer.createTransport<SESTransport.SentMessageInfo>
|
|
42
24
|
>
|
|
25
|
+
|
|
43
26
|
/**
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
* @
|
|
47
|
-
* @
|
|
48
|
-
* @param {string} region
|
|
27
|
+
* Constructs a new instance of the EmailSender class.
|
|
28
|
+
* @param {string} defaultFrom - The default "from" email address.
|
|
29
|
+
* @param {string} region - The AWS region to use for sending emails.
|
|
30
|
+
* @returns None
|
|
49
31
|
*/
|
|
50
32
|
constructor(defaultFrom: string, region: string) {
|
|
51
33
|
this.from = defaultFrom
|
|
@@ -62,19 +44,14 @@ export default class Mailer {
|
|
|
62
44
|
}
|
|
63
45
|
|
|
64
46
|
/**
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
* @
|
|
68
|
-
* @
|
|
69
|
-
* @param {
|
|
70
|
-
* @param {string}
|
|
71
|
-
* @param {string}
|
|
72
|
-
* @param {
|
|
73
|
-
* @param {?string} [optionalFrom]
|
|
74
|
-
* @param {?string} [optionalReplyTo]
|
|
75
|
-
* @param {?any[]} [optionalAttachments]
|
|
76
|
-
* @param {?Email.NodeMailerTransportOptions} [optionalTransport]
|
|
77
|
-
* @returns {unknown}
|
|
47
|
+
* Sends a raw email with the specified parameters.
|
|
48
|
+
* @param {string | Array<string>} to - The recipient(s) of the email.
|
|
49
|
+
* @param {string} htmlMessage - The HTML content of the email.
|
|
50
|
+
* @param {string} subject - The subject of the email.
|
|
51
|
+
* @param {string | Array<string>} [optionalCC] - The optional CC recipient(s) of the email.
|
|
52
|
+
* @param {string} [optionalFrom] - The optional sender of the email. If not provided, the default sender will be used.
|
|
53
|
+
* @param {string} [optionalReplyTo] - The optional reply-to address for the email.
|
|
54
|
+
* @param {any[]} [optionalAttachments] - The optional attachments to include
|
|
78
55
|
*/
|
|
79
56
|
public async sendRawEmail(
|
|
80
57
|
to: string | Array<string>,
|
|
@@ -112,20 +89,16 @@ export default class Mailer {
|
|
|
112
89
|
}
|
|
113
90
|
return resp
|
|
114
91
|
}
|
|
92
|
+
|
|
115
93
|
/**
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
* @
|
|
119
|
-
* @
|
|
120
|
-
* @param {
|
|
121
|
-
* @param {
|
|
122
|
-
* @param {
|
|
123
|
-
* @param {
|
|
124
|
-
* @param {?string} [optionalFrom]
|
|
125
|
-
* @param {?string} [optionalReplyTo]
|
|
126
|
-
* @param {?any[]} [optionalAttachments]
|
|
127
|
-
* @param {?Email.NodeMailerTransportOptions} [optionalTransport]
|
|
128
|
-
* @returns {unknown}
|
|
94
|
+
* Sends a templated email to the specified recipients.
|
|
95
|
+
* @param {string | Array<string>} to - The email address(es) of the recipient(s).
|
|
96
|
+
* @param {string | Array<string>} templates - The template(s) to use for the email.
|
|
97
|
+
* @param {object} data - The data to be used in the email template.
|
|
98
|
+
* @param {string | Array<string>} [optionalCC] - The email address(es) to CC.
|
|
99
|
+
* @param {string} [optionalFrom] - The email address to send the email from.
|
|
100
|
+
* @param {string} [optionalReplyTo] - The email address to set as the reply-to address.
|
|
101
|
+
* @param {any[]} [optionalAttachments] - An array
|
|
129
102
|
*/
|
|
130
103
|
public async sendTemplatedEmail(
|
|
131
104
|
to: string | Array<string>,
|
|
@@ -162,15 +135,14 @@ export default class Mailer {
|
|
|
162
135
|
}
|
|
163
136
|
return resp
|
|
164
137
|
}
|
|
138
|
+
|
|
165
139
|
/**
|
|
166
|
-
*
|
|
167
|
-
*
|
|
168
|
-
* @
|
|
169
|
-
* @param {string}
|
|
170
|
-
* @param {
|
|
171
|
-
* @
|
|
172
|
-
* @param {string} password
|
|
173
|
-
* @returns {Email.NodeMailerTransportOptions}
|
|
140
|
+
* Creates a new SMTP transporter for sending emails using NodeMailer.
|
|
141
|
+
* @param {string} host - The SMTP server host.
|
|
142
|
+
* @param {number} portNumber - The port number to connect to the SMTP server.
|
|
143
|
+
* @param {string} user - The username for authentication with the SMTP server.
|
|
144
|
+
* @param {string} password - The password for authentication with the SMTP server.
|
|
145
|
+
* @returns {Email.NodeMailerTransportOptions} - The SMTP transporter object.
|
|
174
146
|
*/
|
|
175
147
|
public newSMTPTransporter(
|
|
176
148
|
host: string,
|
|
@@ -190,15 +162,12 @@ export default class Mailer {
|
|
|
190
162
|
return smtpTransporter
|
|
191
163
|
}
|
|
192
164
|
|
|
193
|
-
/* private */
|
|
194
165
|
/**
|
|
195
|
-
*
|
|
196
|
-
*
|
|
197
|
-
* @
|
|
198
|
-
* @
|
|
199
|
-
* @
|
|
200
|
-
* @param {object} data
|
|
201
|
-
* @returns {Promise<string>}
|
|
166
|
+
* Chooses a template from the given array of templates or a single template string based on whether it can be rendered with the provided data.
|
|
167
|
+
* @param {string | Array<string>} templates - The template(s) to choose from.
|
|
168
|
+
* @param {object} data - The data to be used for rendering the template.
|
|
169
|
+
* @returns {Promise<string>} - The chosen template.
|
|
170
|
+
* @throws {Error} - If no template can be rendered with the provided data.
|
|
202
171
|
*/
|
|
203
172
|
private async chooseTemplate(templates: string | Array<string>, data: object): Promise<string> {
|
|
204
173
|
if (Array.isArray(templates)) {
|
|
@@ -214,14 +183,12 @@ export default class Mailer {
|
|
|
214
183
|
JSON.stringify(data, null, 2)
|
|
215
184
|
)
|
|
216
185
|
}
|
|
186
|
+
|
|
217
187
|
/**
|
|
218
|
-
*
|
|
219
|
-
*
|
|
220
|
-
* @
|
|
221
|
-
* @
|
|
222
|
-
* @param {string} template
|
|
223
|
-
* @param {object} data
|
|
224
|
-
* @returns {Promise<boolean>}
|
|
188
|
+
* Checks if a given email template can be rendered with the provided data.
|
|
189
|
+
* @param {string} template - The name of the email template.
|
|
190
|
+
* @param {object} data - The data to be used for rendering the template.
|
|
191
|
+
* @returns {Promise<boolean>} - A promise that resolves to true if the template can be rendered, false otherwise.
|
|
225
192
|
*/
|
|
226
193
|
private async canRenderTemplate(template: string, data: object): Promise<boolean> {
|
|
227
194
|
let validRenderResp = null
|