@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.
Files changed (153) hide show
  1. package/.github/workflows/npmpublish.yml +1 -1
  2. package/README.md +216 -5
  3. package/dist/index.d.ts +15 -0
  4. package/dist/index.js.map +1 -1
  5. package/dist/jest.config.js +1 -1
  6. package/dist/jest.config.js.map +1 -1
  7. package/dist/package.json +13 -2
  8. package/dist/src/API/Request.d.ts +45 -82
  9. package/dist/src/API/Request.js +49 -77
  10. package/dist/src/API/Request.js.map +1 -1
  11. package/dist/src/API/Response.d.ts +94 -163
  12. package/dist/src/API/Response.js +101 -161
  13. package/dist/src/API/Response.js.map +1 -1
  14. package/dist/src/API/Utils.d.ts +21 -42
  15. package/dist/src/API/Utils.js +22 -43
  16. package/dist/src/API/Utils.js.map +1 -1
  17. package/dist/src/BaseEvent/EventProcessor.d.ts +32 -55
  18. package/dist/src/BaseEvent/EventProcessor.js +30 -38
  19. package/dist/src/BaseEvent/EventProcessor.js.map +1 -1
  20. package/dist/src/BaseEvent/Process.d.ts +20 -43
  21. package/dist/src/BaseEvent/Process.js +16 -27
  22. package/dist/src/BaseEvent/Process.js.map +1 -1
  23. package/dist/src/BaseEvent/Transaction.d.ts +104 -2
  24. package/dist/src/BaseEvent/Transaction.js +196 -41
  25. package/dist/src/BaseEvent/Transaction.js.map +1 -1
  26. package/dist/src/Config/Configuration.d.ts +48 -66
  27. package/dist/src/Config/Configuration.js +25 -42
  28. package/dist/src/Config/Configuration.js.map +1 -1
  29. package/dist/src/Config/EnvironmentVar.d.ts +30 -57
  30. package/dist/src/Config/EnvironmentVar.js +28 -41
  31. package/dist/src/Config/EnvironmentVar.js.map +1 -1
  32. package/dist/src/Crypto/Crypto.d.ts +17 -35
  33. package/dist/src/Crypto/Crypto.js +12 -21
  34. package/dist/src/Crypto/Crypto.js.map +1 -1
  35. package/dist/src/Crypto/JWT.d.ts +21 -32
  36. package/dist/src/Crypto/JWT.js +14 -22
  37. package/dist/src/Crypto/JWT.js.map +1 -1
  38. package/dist/src/Database/Database.d.ts +18 -0
  39. package/dist/src/Database/Database.js +18 -0
  40. package/dist/src/Database/Database.js.map +1 -0
  41. package/dist/src/Database/DatabaseManager.d.ts +32 -0
  42. package/dist/src/Database/DatabaseManager.js +50 -0
  43. package/dist/src/Database/DatabaseManager.js.map +1 -0
  44. package/dist/src/Database/DatabaseTransaction.d.ts +65 -0
  45. package/dist/src/Database/DatabaseTransaction.js +183 -0
  46. package/dist/src/Database/DatabaseTransaction.js.map +1 -0
  47. package/dist/src/Database/integrations/knex/KnexDatabase.d.ts +22 -0
  48. package/dist/src/Database/integrations/knex/KnexDatabase.js +108 -0
  49. package/dist/src/Database/integrations/knex/KnexDatabase.js.map +1 -0
  50. package/dist/src/Database/integrations/knex/KnexTransaction.d.ts +37 -0
  51. package/dist/src/Database/integrations/knex/KnexTransaction.js +60 -0
  52. package/dist/src/Database/integrations/knex/KnexTransaction.js.map +1 -0
  53. package/dist/src/Database/integrations/pgsql/PostgresDatabase.d.ts +30 -0
  54. package/dist/src/Database/integrations/pgsql/PostgresDatabase.js +108 -0
  55. package/dist/src/Database/integrations/pgsql/PostgresDatabase.js.map +1 -0
  56. package/dist/src/Database/integrations/pgsql/PostgresTransaction.d.ts +37 -0
  57. package/dist/src/Database/integrations/pgsql/PostgresTransaction.js +60 -0
  58. package/dist/src/Database/integrations/pgsql/PostgresTransaction.js.map +1 -0
  59. package/dist/src/Globals.d.ts +26 -94
  60. package/dist/src/Globals.js +26 -95
  61. package/dist/src/Globals.js.map +1 -1
  62. package/dist/src/Logger/Logger.d.ts +82 -105
  63. package/dist/src/Logger/Logger.js +111 -136
  64. package/dist/src/Logger/Logger.js.map +1 -1
  65. package/dist/src/Mailer/Mailer.d.ts +39 -75
  66. package/dist/src/Mailer/Mailer.js +36 -65
  67. package/dist/src/Mailer/Mailer.js.map +1 -1
  68. package/dist/src/Publisher/Publisher.d.ts +17 -25
  69. package/dist/src/Publisher/Publisher.js +21 -32
  70. package/dist/src/Publisher/Publisher.js.map +1 -1
  71. package/dist/src/Server/RouteResolver.d.ts +14 -22
  72. package/dist/src/Server/RouteResolver.js +21 -34
  73. package/dist/src/Server/RouteResolver.js.map +1 -1
  74. package/dist/src/Server/Router.d.ts +72 -51
  75. package/dist/src/Server/Router.js +8 -17
  76. package/dist/src/Server/Router.js.map +1 -1
  77. package/dist/src/Server/lib/ContainerServer.d.ts +15 -31
  78. package/dist/src/Server/lib/ContainerServer.js +13 -28
  79. package/dist/src/Server/lib/ContainerServer.js.map +1 -1
  80. package/dist/src/Server/lib/Server.d.ts +17 -32
  81. package/dist/src/Server/lib/Server.js +18 -28
  82. package/dist/src/Server/lib/Server.js.map +1 -1
  83. package/dist/src/Server/lib/container/GenericHandler.d.ts +5 -0
  84. package/dist/src/Server/lib/container/GenericHandler.js +16 -3
  85. package/dist/src/Server/lib/container/GenericHandler.js.map +1 -1
  86. package/dist/src/Server/lib/container/GenericHandlerEvent.d.ts +22 -37
  87. package/dist/src/Server/lib/container/GenericHandlerEvent.js +29 -41
  88. package/dist/src/Server/lib/container/GenericHandlerEvent.js.map +1 -1
  89. package/dist/src/Server/lib/container/HealthHandler.d.ts +6 -0
  90. package/dist/src/Server/lib/container/HealthHandler.js +6 -0
  91. package/dist/src/Server/lib/container/HealthHandler.js.map +1 -1
  92. package/dist/src/Server/lib/container/Proxy.d.ts +24 -52
  93. package/dist/src/Server/lib/container/Proxy.js +52 -52
  94. package/dist/src/Server/lib/container/Proxy.js.map +1 -1
  95. package/dist/src/Server/lib/container/Utils.d.ts +6 -10
  96. package/dist/src/Server/lib/container/Utils.js +6 -10
  97. package/dist/src/Server/lib/container/Utils.js.map +1 -1
  98. package/dist/src/Validation/Validator.d.ts +9 -13
  99. package/dist/src/Validation/Validator.js +8 -12
  100. package/dist/src/Validation/Validator.js.map +1 -1
  101. package/index.ts +15 -0
  102. package/jest.config.ts +1 -1
  103. package/package.json +13 -2
  104. package/src/API/Request.ts +66 -84
  105. package/src/API/Response.ts +144 -203
  106. package/src/API/Utils.ts +28 -44
  107. package/src/BaseEvent/EventProcessor.ts +52 -77
  108. package/src/BaseEvent/Process.ts +27 -52
  109. package/src/BaseEvent/Transaction.ts +147 -27
  110. package/src/Config/Configuration.ts +59 -76
  111. package/src/Config/EnvironmentVar.ts +39 -62
  112. package/src/Crypto/Crypto.ts +20 -36
  113. package/src/Crypto/JWT.ts +31 -35
  114. package/src/Database/Database.ts +19 -0
  115. package/src/Database/DatabaseManager.ts +51 -0
  116. package/src/Database/DatabaseTransaction.ts +118 -0
  117. package/src/Database/integrations/knex/KnexDatabase.ts +47 -0
  118. package/src/Database/integrations/knex/KnexTransaction.ts +51 -0
  119. package/src/Database/integrations/pgsql/PostgresDatabase.ts +49 -0
  120. package/src/Database/integrations/pgsql/PostgresTransaction.ts +54 -0
  121. package/src/Database/types.d.ts +49 -0
  122. package/src/Globals.ts +28 -96
  123. package/src/Logger/Logger.ts +141 -160
  124. package/src/Mailer/Mailer.ts +43 -76
  125. package/src/Publisher/Publisher.ts +31 -40
  126. package/src/Server/RouteResolver.ts +31 -52
  127. package/src/Server/Router.ts +75 -54
  128. package/src/Server/lib/ContainerServer.ts +20 -32
  129. package/src/Server/lib/Server.ts +19 -34
  130. package/src/Server/lib/container/GenericHandler.ts +17 -3
  131. package/src/Server/lib/container/GenericHandlerEvent.ts +44 -54
  132. package/src/Server/lib/container/HealthHandler.ts +6 -0
  133. package/src/Server/lib/container/Proxy.ts +39 -58
  134. package/src/Server/lib/container/Utils.ts +7 -10
  135. package/src/Validation/Validator.ts +11 -13
  136. package/tests/API/Response.test.ts +55 -56
  137. package/tests/BaseEvent/EventProcessor.test.ts +49 -50
  138. package/tests/BaseEvent/Process.test.ts +2 -2
  139. package/tests/BaseEvent/Transaction.test.ts +102 -44
  140. package/tests/Config/Config.test.ts +27 -27
  141. package/tests/Config/EnvironmentVar.test.ts +54 -18
  142. package/tests/Database/DatabaseManager.test.ts +55 -0
  143. package/tests/Database/integrations/knex/KnexDatabase.test.ts +53 -0
  144. package/tests/Database/integrations/knex/KnexTransaction.test.ts +133 -0
  145. package/tests/Database/integrations/pg/PostgresDatabase.test.ts +50 -0
  146. package/tests/Database/integrations/pg/PostgresTransaction.test.ts +51 -0
  147. package/tests/Publisher/Publisher.test.ts +3 -3
  148. package/tests/Server/lib/ContainerServer.test.ts +21 -22
  149. package/tests/Server/lib/container/GenericHandler.test.ts +31 -32
  150. package/tests/Server/lib/container/GenericHandlerEvent.test.ts +2 -2
  151. package/tests/Server/lib/container/HealthHandler.test.ts +6 -7
  152. package/tests/Server/lib/container/Proxy.test.ts +37 -35
  153. package/tsconfig.json +6 -1
@@ -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
- * ${1:Description placeholder}
10
- *
11
- * @export
12
- * @enum {number}
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
- * ${1:Description placeholder}
22
- *
23
- * @type {*}
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
- * ${1:Description placeholder}
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
- * ${1:Description placeholder}
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
- * ${1:Description placeholder}
55
- *
56
- * @export
57
- * @typedef {LoggerConfig}
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
- * ${1:Description placeholder}
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
- * ${1:Description placeholder}
74
- *
75
- * @private
76
- * @type {?LoggerConfig}
70
+ * The optional configuration object for the logger.
77
71
  */
78
- private _config?: LoggerConfig
72
+ private config?: LoggerConfig
79
73
  /**
80
- * ${1:Description placeholder}
81
- *
82
- * @private
74
+ * Private property representing the transaction ID.
83
75
  * @type {string}
76
+ * @private
84
77
  */
85
- private _transactionID: string
78
+ private transactionID: string
86
79
  /**
87
- * ${1:Description placeholder}
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 _filterBlacklist: Array<string> | false
82
+ private filterBlacklist: Array<string> | false
93
83
  /**
94
- * ${1:Description placeholder}
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
- * ${1:Description placeholder}
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
- * Creates an instance of Logger.
110
- *
111
- * @constructor
112
- * @param {(LoggerConfig | undefined)} _config
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(_config: LoggerConfig | undefined, transactionID: string) {
102
+ constructor(config: LoggerConfig | undefined, transactionID: string) {
116
103
  abind(this)
117
104
  //
118
105
  this.origin = PURE_CONSOLE
119
- this._LOG_LEVEL = _config?.logLevel
120
- ? LOG_LEVELS[_config?.logLevel] || LOG_LEVELS.DEBUG
106
+ this._LOG_LEVEL = config?.logLevel
107
+ ? LOG_LEVELS[config?.logLevel] || LOG_LEVELS.DEBUG
121
108
  : LOG_LEVELS.DEBUG
122
- this._config = _config || {}
123
- this._transactionID = transactionID
124
- this._filterBlacklist = this._config.sensitiveFilteringKeywords
125
- ? Array.isArray(this._config.sensitiveFilteringKeywords)
126
- ? this._config.sensitiveFilteringKeywords
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._setupBindings()
117
+ this.setupBindings()
131
118
  //
132
119
  this.log('Using logger with level: ' + this._LOG_LEVEL.toString())
133
- this.debug('logger config: ', this._config)
120
+ this.debug('logger config: ', this.config)
134
121
  }
122
+
135
123
  /**
136
- * ${1:Description placeholder}
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
- * ${1:Description placeholder}
148
- *
149
- * @param {...{}\} args
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._processLog(LOG_LEVELS.DEBUG, args)
137
+ this.processLog(LOG_LEVELS.DEBUG, args)
153
138
  }
139
+
154
140
  /**
155
- * ${1:Description placeholder}
156
- *
157
- * @param {...{}\} args
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._processLog(LOG_LEVELS.INFO, args)
146
+ this.processLog(LOG_LEVELS.INFO, args)
161
147
  }
148
+
162
149
  /**
163
- * ${1:Description placeholder}
164
- *
165
- * @param {...{}\} args
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._processLog(LOG_LEVELS.INFO, args)
155
+ this.processLog(LOG_LEVELS.INFO, args)
169
156
  }
157
+
170
158
  /**
171
- * ${1:Description placeholder}
172
- *
173
- * @param {...{}\} args
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._processLog(LOG_LEVELS.WARN, args)
164
+ this.processLog(LOG_LEVELS.WARN, args)
177
165
  }
166
+
178
167
  /**
179
- * ${1:Description placeholder}
180
- *
181
- * @param {...{}\} args
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._processLog(LOG_LEVELS.WARN, args)
173
+ this.processLog(LOG_LEVELS.WARN, args)
185
174
  }
175
+
186
176
  /**
187
- * ${1:Description placeholder}
188
- *
189
- * @param {...{}\} args
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._processLog(LOG_LEVELS.ERROR, args)
182
+ this.processLog(LOG_LEVELS.ERROR, args)
193
183
  }
184
+
194
185
  /**
195
- * ${1:Description placeholder}
196
- *
197
- * @param {*} exception
198
- * @param {...{}\} args
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._exception(exception, args)
192
+ this.iexception(exception, args)
202
193
  }
203
194
 
204
- //initialization
205
195
  /**
206
- * ${1:Description placeholder}
207
- *
196
+ * Sets up the console bindings for logging purposes.
208
197
  * @private
198
+ * @returns None
209
199
  */
210
- private _setupBindings(): void {
200
+ private setupBindings(): void {
211
201
  global.console = {
212
- debug: (...args) => this._processLog(LOG_LEVELS.DEBUG, args),
213
- log: (...args) => this._processLog(LOG_LEVELS.INFO, args),
214
- info: (...args) => this._processLog(LOG_LEVELS.INFO, args),
215
- warn: (...args) => this._processLog(LOG_LEVELS.WARN, args),
216
- error: (...args) => this._processLog(LOG_LEVELS.ERROR, args),
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._processLog(LOG_LEVELS.WARN, args),
220
- exception: (exception, ...args) => this._exception(exception, args),
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
- * ${1:Description placeholder}
227
- *
228
- * @private
229
- * @param {LOG_LEVELS} level
230
- * @param {Array<string>} msg
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 _formattedLog(level: LOG_LEVELS, msg: Array<string>, caller: string): string {
235
- if (Utils.isHybridlessContainer() && this._transactionID) {
221
+ private formattedLog(level: LOG_LEVELS, msg: Array<string>, caller: string): string {
222
+ if (Utils.isHybridlessContainer() && this.transactionID) {
236
223
  return (
237
- `${this._transactionID}` +
238
- ` [${level.toString()}] [${caller}] ${msg.map(this._suppressSensitiveInfo).join(' ')}`
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._suppressSensitiveInfo).join(' ')}`
228
+ return `[${level.toString()}] [${caller}] ${msg.map(this.suppressSensitiveInfo).join(' ')}`
242
229
  }
243
230
  }
231
+
244
232
  /**
245
- * ${1:Description placeholder}
246
- *
247
- * @private
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 _callerName(index: number): string {
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
- /* Helpers (core functionality) */
251
+
266
252
  /**
267
- * ${1:Description placeholder}
268
- *
269
- * @private
270
- * @param {LOG_LEVELS} level
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 _processLog(level: LOG_LEVELS, args: any): void {
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._pushLog(level, this._formattedLog(level, msg, this._callerName(3)))
269
+ this.pushLog(level, this.formattedLog(level, msg, this.callerName(3)))
285
270
  }
271
+
286
272
  /**
287
- * ${1:Description placeholder}
288
- *
289
- * @private
290
- * @param {Error} exception
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 _exception(exception: Error, ...args): void {
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._pushLog(LOG_LEVELS.ERROR, this._formattedLog(LOG_LEVELS.ERROR, msg, this._callerName(3)))
287
+ this.pushLog(LOG_LEVELS.ERROR, this.formattedLog(LOG_LEVELS.ERROR, msg, this.callerName(3)))
303
288
  }
289
+
304
290
  /**
305
- * ${1:Description placeholder}
306
- *
307
- * @private
308
- * @param {LOG_LEVELS} level
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 _pushLog(level: LOG_LEVELS, fMsg: string): void {
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
- /* Sensitive information handling */
299
+
317
300
  /**
318
- * ${1:Description placeholder}
319
- *
320
- * @private
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 _suppressSensitiveInfo(value: any): string {
305
+ private suppressSensitiveInfo(value: any): string {
325
306
  //realy false
326
- if (!this._filterBlacklist) return value
307
+ if (!this.filterBlacklist) return value
327
308
  if (typeof value == 'string') {
328
309
  //content based replacement
329
- if (this._filterBlacklist) {
330
- this._filterBlacklist.forEach(() => {
331
- const match = this._filterBlacklist
332
- ? this._filterBlacklist.find(f => value.toLowerCase().includes(f.toLowerCase()))
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
  })
@@ -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
- * ${1:Description placeholder}
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
- * ${1:Description placeholder}
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
- * ${1:Description placeholder}
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
- * Creates an instance of Mailer.
45
- *
46
- * @constructor
47
- * @param {string} defaultFrom
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
- * ${1:Description placeholder}
66
- *
67
- * @public
68
- * @async
69
- * @param {(string | Array<string>)} to
70
- * @param {string} htmlMessage
71
- * @param {string} subject
72
- * @param {?(string | Array<string>)} [optionalCC]
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
- * ${1:Description placeholder}
117
- *
118
- * @public
119
- * @async
120
- * @param {(string | Array<string>)} to
121
- * @param {(string | Array<string>)} templates
122
- * @param {object} data
123
- * @param {?(string | Array<string>)} [optionalCC]
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
- * ${1:Description placeholder}
167
- *
168
- * @public
169
- * @param {string} host
170
- * @param {number} portNumber
171
- * @param {string} user
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
- * ${1:Description placeholder}
196
- *
197
- * @private
198
- * @async
199
- * @param {(string | Array<string>)} templates
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
- * ${1:Description placeholder}
219
- *
220
- * @private
221
- * @async
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