@creator.co/wapi 1.2.2 → 1.2.4

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 (135) hide show
  1. package/.eslintrc.cjs +29 -22
  2. package/.github/workflows/npmpublish.yml +2 -5
  3. package/.github/workflows/prs.yml +1 -1
  4. package/README.md +1 -3
  5. package/dist/index.d.ts +11 -0
  6. package/dist/index.js +24 -0
  7. package/dist/index.js.map +1 -0
  8. package/dist/jest.config.d.ts +3 -0
  9. package/dist/jest.config.js +34 -0
  10. package/dist/jest.config.js.map +1 -0
  11. package/dist/package.json +64 -0
  12. package/dist/src/API/Request.d.ts +140 -0
  13. package/dist/src/API/Request.js +182 -0
  14. package/dist/src/API/Request.js.map +1 -0
  15. package/dist/src/API/Response.d.ts +256 -0
  16. package/dist/src/API/Response.js +398 -0
  17. package/dist/src/API/Response.js.map +1 -0
  18. package/dist/src/API/Utils.d.ts +63 -0
  19. package/dist/src/API/Utils.js +104 -0
  20. package/dist/src/API/Utils.js.map +1 -0
  21. package/dist/src/BaseEvent/EventProcessor.d.ts +81 -0
  22. package/dist/src/BaseEvent/EventProcessor.js +182 -0
  23. package/dist/src/BaseEvent/EventProcessor.js.map +1 -0
  24. package/dist/src/BaseEvent/Process.d.ts +74 -0
  25. package/dist/src/BaseEvent/Process.js +142 -0
  26. package/dist/src/BaseEvent/Process.js.map +1 -0
  27. package/dist/src/BaseEvent/Transaction.d.ts +29 -0
  28. package/dist/src/BaseEvent/Transaction.js +244 -0
  29. package/dist/src/BaseEvent/Transaction.js.map +1 -0
  30. package/dist/src/Config/Configuration.d.ts +131 -0
  31. package/dist/src/Config/Configuration.js +153 -0
  32. package/dist/src/Config/Configuration.js.map +1 -0
  33. package/dist/src/Config/EnvironmentVar.d.ts +101 -0
  34. package/dist/src/Config/EnvironmentVar.js +213 -0
  35. package/dist/src/Config/EnvironmentVar.js.map +1 -0
  36. package/dist/src/Crypto/Crypto.d.ts +57 -0
  37. package/dist/src/Crypto/Crypto.js +126 -0
  38. package/dist/src/Crypto/Crypto.js.map +1 -0
  39. package/dist/src/Crypto/JWT.d.ts +64 -0
  40. package/dist/src/Crypto/JWT.js +74 -0
  41. package/dist/src/Crypto/JWT.js.map +1 -0
  42. package/dist/src/Globals.d.ts +161 -0
  43. package/dist/src/Globals.js +173 -0
  44. package/dist/src/Globals.js.map +1 -0
  45. package/dist/src/Logger/Logger.d.ts +180 -0
  46. package/dist/src/Logger/Logger.js +412 -0
  47. package/dist/src/Logger/Logger.js.map +1 -0
  48. package/dist/src/Mailer/Mailer.d.ts +107 -0
  49. package/dist/src/Mailer/Mailer.js +313 -0
  50. package/dist/src/Mailer/Mailer.js.map +1 -0
  51. package/dist/src/Publisher/Publisher.d.ts +47 -0
  52. package/dist/src/Publisher/Publisher.js +141 -0
  53. package/dist/src/Publisher/Publisher.js.map +1 -0
  54. package/dist/src/Server/RouteResolver.d.ts +41 -0
  55. package/dist/src/Server/RouteResolver.js +135 -0
  56. package/dist/src/Server/RouteResolver.js.map +1 -0
  57. package/dist/src/Server/Router.d.ts +104 -0
  58. package/dist/src/Server/Router.js +45 -0
  59. package/dist/src/Server/Router.js.map +1 -0
  60. package/dist/src/Server/lib/ContainerServer.d.ts +58 -0
  61. package/dist/src/Server/lib/ContainerServer.js +143 -0
  62. package/dist/src/Server/lib/ContainerServer.js.map +1 -0
  63. package/dist/src/Server/lib/Server.d.ts +60 -0
  64. package/dist/src/Server/lib/Server.js +137 -0
  65. package/dist/src/Server/lib/Server.js.map +1 -0
  66. package/dist/src/Server/lib/container/GenericHandler.d.ts +4 -0
  67. package/dist/src/Server/lib/container/GenericHandler.js +138 -0
  68. package/dist/src/Server/lib/container/GenericHandler.js.map +1 -0
  69. package/dist/src/Server/lib/container/GenericHandlerEvent.d.ts +67 -0
  70. package/dist/src/Server/lib/container/GenericHandlerEvent.js +189 -0
  71. package/dist/src/Server/lib/container/GenericHandlerEvent.js.map +1 -0
  72. package/dist/src/Server/lib/container/HealthHandler.d.ts +3 -0
  73. package/dist/src/Server/lib/container/HealthHandler.js +45 -0
  74. package/dist/src/Server/lib/container/HealthHandler.js.map +1 -0
  75. package/dist/src/Server/lib/container/Proxy.d.ts +95 -0
  76. package/dist/src/Server/lib/container/Proxy.js +201 -0
  77. package/dist/src/Server/lib/container/Proxy.js.map +1 -0
  78. package/dist/src/Server/lib/container/Utils.d.ts +18 -0
  79. package/dist/src/Server/lib/container/Utils.js +84 -0
  80. package/dist/src/Server/lib/container/Utils.js.map +1 -0
  81. package/dist/src/Validation/Validator.d.ts +21 -0
  82. package/dist/src/Validation/Validator.js +48 -0
  83. package/dist/src/Validation/Validator.js.map +1 -0
  84. package/index.ts +12 -10
  85. package/jest.config.ts +14 -21
  86. package/package.json +3 -3
  87. package/src/API/Request.ts +17 -35
  88. package/src/API/Response.ts +24 -42
  89. package/src/API/Utils.ts +5 -7
  90. package/src/BaseEvent/EventProcessor.ts +16 -24
  91. package/src/BaseEvent/Process.ts +7 -12
  92. package/src/BaseEvent/Transaction.ts +25 -43
  93. package/src/Config/Configuration.ts +8 -14
  94. package/src/Config/EnvironmentVar.ts +10 -20
  95. package/src/Crypto/Crypto.ts +10 -10
  96. package/src/Crypto/JWT.ts +4 -10
  97. package/src/Globals.ts +19 -25
  98. package/src/Logger/Logger.ts +36 -51
  99. package/src/Mailer/Mailer.ts +19 -31
  100. package/src/Publisher/Publisher.ts +7 -12
  101. package/src/Server/RouteResolver.ts +5 -6
  102. package/src/Server/Router.ts +7 -12
  103. package/src/Server/lib/ContainerServer.ts +5 -5
  104. package/src/Server/lib/Server.ts +26 -38
  105. package/src/Server/lib/container/GenericHandler.ts +8 -13
  106. package/src/Server/lib/container/GenericHandlerEvent.ts +21 -35
  107. package/src/Server/lib/container/HealthHandler.ts +2 -2
  108. package/src/Server/lib/container/Proxy.ts +26 -38
  109. package/src/Server/lib/container/Utils.ts +2 -2
  110. package/src/Validation/Validator.ts +6 -6
  111. package/tests/API/Request.test.ts +107 -111
  112. package/tests/API/Response.test.ts +86 -91
  113. package/tests/API/Utils.test.ts +64 -64
  114. package/tests/BaseEvent/EventProcessor.test.ts +68 -84
  115. package/tests/BaseEvent/Process.test.ts +11 -11
  116. package/tests/BaseEvent/Transaction.test.ts +44 -53
  117. package/tests/Config/Config.test.ts +50 -50
  118. package/tests/Config/EnvironmentVar.test.ts +50 -59
  119. package/tests/Crypto/Crypto.test.ts +20 -22
  120. package/tests/Crypto/JWT.test.ts +40 -40
  121. package/tests/Logger/Logger.test.ts +24 -36
  122. package/tests/Mailer/Mailer.test.ts +21 -29
  123. package/tests/Publisher/Publisher.test.ts +18 -18
  124. package/tests/Server/RouteResolver.test.ts +56 -59
  125. package/tests/Server/Router.test.ts +16 -16
  126. package/tests/Server/lib/ContainerServer.test.ts +83 -85
  127. package/tests/Server/lib/Server.test.ts +4 -4
  128. package/tests/Server/lib/container/GenericHandler.test.ts +31 -41
  129. package/tests/Server/lib/container/GenericHandlerEvent.test.ts +35 -36
  130. package/tests/Server/lib/container/HealthHandler.test.ts +7 -7
  131. package/tests/Server/lib/container/Proxy.test.ts +66 -79
  132. package/tests/Server/lib/container/Utils.test.ts +16 -17
  133. package/tests/Test.utils.ts +9 -9
  134. package/tests/Validation/Validator.test.ts +28 -40
  135. package/tests/main.test.ts +2 -2
@@ -1,7 +1,7 @@
1
- import * as MemCache from "node-cache"
2
- import * as DurationParser from "parse-duration"
1
+ import * as MemCache from 'node-cache'
2
+ import * as DurationParser from 'parse-duration'
3
3
 
4
- import EnvironmentVar, { EnvironmentType } from "./EnvironmentVar"
4
+ import EnvironmentVar, { EnvironmentType } from './EnvironmentVar'
5
5
 
6
6
  // Hold cached values at nodeVM level
7
7
  // eslint-disable-next-line no-var
@@ -136,7 +136,7 @@ export default class Configuration<T extends ConfigurationSchema> {
136
136
  propString,
137
137
  EnvironmentType.Local,
138
138
  !propSchema.required,
139
- this.remotePrefix,
139
+ this.remotePrefix
140
140
  ).syncResolve()
141
141
  this.cacheValue(propString, v, propSchema.cachingPolicy)
142
142
  return v
@@ -149,9 +149,7 @@ export default class Configuration<T extends ConfigurationSchema> {
149
149
  * @param {keyof OmitByValueType<ExtractRemote<T>, null>} propName
150
150
  * @returns {Promise<any>}
151
151
  */
152
- public async asyncGet(
153
- propName: keyof OmitByValueType<ExtractRemote<T>, null>,
154
- ): Promise<any> {
152
+ public async asyncGet(propName: keyof OmitByValueType<ExtractRemote<T>, null>): Promise<any> {
155
153
  const propString = propName as string
156
154
  const propSchema = this.schema[propString]
157
155
  let v = this.getCachedValue(propString)
@@ -161,7 +159,7 @@ export default class Configuration<T extends ConfigurationSchema> {
161
159
  propString,
162
160
  EnvironmentType.PlainRemote,
163
161
  !propSchema.required,
164
- this.remotePrefix,
162
+ this.remotePrefix
165
163
  ).resolve())
166
164
  this.cacheValue(propString, v, propSchema.cachingPolicy)
167
165
  return v
@@ -185,12 +183,8 @@ export default class Configuration<T extends ConfigurationSchema> {
185
183
  * @param {*} value
186
184
  * @param {string} [policy="1d"]
187
185
  */
188
- private cacheValue(
189
- valueKey: string,
190
- value: any,
191
- policy: string = "1d",
192
- ): void {
193
- cacheStore.set(valueKey, value, DurationParser(policy, "s"))
186
+ private cacheValue(valueKey: string, value: any, policy: string = '1d'): void {
187
+ cacheStore.set(valueKey, value, DurationParser(policy, 's'))
194
188
  }
195
189
  // unit-test support
196
190
  /**
@@ -1,8 +1,5 @@
1
- import {
2
- SecretsManagerClient,
3
- GetSecretValueCommand,
4
- } from "@aws-sdk/client-secrets-manager"
5
- import { SSMClient, GetParameterCommand } from "@aws-sdk/client-ssm"
1
+ import { SecretsManagerClient, GetSecretValueCommand } from '@aws-sdk/client-secrets-manager'
2
+ import { SSMClient, GetParameterCommand } from '@aws-sdk/client-ssm'
6
3
 
7
4
  // Explicity setting VM level variables in order to persist
8
5
  // client across different important and instances.
@@ -80,7 +77,7 @@ export default class EnvironmentVar<T> {
80
77
  paramName: string,
81
78
  type: EnvironmentType,
82
79
  optional?: boolean,
83
- paramPrefix = `/creatorco-api-${process.env.STAGE}/env/` /* only allowed process.env */,
80
+ paramPrefix = `/creatorco-api-${process.env.STAGE}/env/` /* only allowed process.env */
84
81
  ) {
85
82
  this.paramName = paramName
86
83
  this.type = type
@@ -98,7 +95,7 @@ export default class EnvironmentVar<T> {
98
95
  if (this.type == EnvironmentType.Local) return this.getLocalValue()
99
96
  else {
100
97
  throw new Error(
101
- "EnvironmentVar syncResolve method can only be called for environments of type 'Local'",
98
+ "EnvironmentVar syncResolve method can only be called for environments of type 'Local'"
102
99
  )
103
100
  }
104
101
  }
@@ -111,8 +108,7 @@ export default class EnvironmentVar<T> {
111
108
  */
112
109
  public async resolve() {
113
110
  if (this.type == EnvironmentType.Local) return this.getLocalValue()
114
- else if (this.type == EnvironmentType.SecureRemote)
115
- return this.getSecureValue()
111
+ else if (this.type == EnvironmentType.SecureRemote) return this.getSecureValue()
116
112
  else return this.getPlainValue()
117
113
  }
118
114
 
@@ -126,7 +122,7 @@ export default class EnvironmentVar<T> {
126
122
  const value = process.env[this.paramName]
127
123
  if (!value && !this.optional) {
128
124
  throw new Error(
129
- `Local environment ${this.paramName} is not defined, please reconfigure the application and redeploy!`,
125
+ `Local environment ${this.paramName} is not defined, please reconfigure the application and redeploy!`
130
126
  )
131
127
  }
132
128
  return value as T
@@ -142,11 +138,8 @@ export default class EnvironmentVar<T> {
142
138
  if (!ssmClient) ssmClient = new SSMClient()
143
139
  const pName = `${this.paramPrefix}${this.paramName}`
144
140
  try {
145
- const data = await ssmClient.send(
146
- new GetParameterCommand({ Name: pName }),
147
- )
148
- if (data.Parameter && data.Parameter.Value)
149
- return data.Parameter.Value as T
141
+ const data = await ssmClient.send(new GetParameterCommand({ Name: pName }))
142
+ if (data.Parameter && data.Parameter.Value) return data.Parameter.Value as T
150
143
  } catch (error) {
151
144
  console.error(error)
152
145
  }
@@ -165,11 +158,8 @@ export default class EnvironmentVar<T> {
165
158
  if (!secretsClient) secretsClient = new SecretsManagerClient()
166
159
  const pName = `${this.paramPrefix}${this.paramName}`
167
160
  try {
168
- const data = await secretsClient.send(
169
- new GetSecretValueCommand({ SecretId: pName }),
170
- )
171
- if (data.Parameter && data.Parameter.Value)
172
- return data.Parameter.Value as T
161
+ const data = await secretsClient.send(new GetSecretValueCommand({ SecretId: pName }))
162
+ if (data.Parameter && data.Parameter.Value) return data.Parameter.Value as T
173
163
  } catch (error) {
174
164
  console.error(error)
175
165
  }
@@ -1,4 +1,4 @@
1
- import { KMSClient, EncryptCommand, DecryptCommand } from "@aws-sdk/client-kms"
1
+ import { KMSClient, EncryptCommand, DecryptCommand } from '@aws-sdk/client-kms'
2
2
 
3
3
  /**
4
4
  * ${1:Description placeholder}
@@ -57,15 +57,15 @@ export default class Crypto {
57
57
  const resp = await this.client.send(
58
58
  new EncryptCommand({
59
59
  KeyId: this.keyId,
60
- EncryptionAlgorithm: "RSAES_OAEP_SHA_256",
60
+ EncryptionAlgorithm: 'RSAES_OAEP_SHA_256',
61
61
  Plaintext: new TextEncoder().encode(
62
- typeof data === "string" ? data : JSON.stringify(data),
62
+ typeof data === 'string' ? data : JSON.stringify(data)
63
63
  ),
64
- }),
64
+ })
65
65
  )
66
- return Buffer.from(resp.CiphertextBlob as any, "utf8").toString("hex")
66
+ return Buffer.from(resp.CiphertextBlob as any, 'utf8').toString('hex')
67
67
  } catch (e) {
68
- console.error("Encryption failure", e)
68
+ console.error('Encryption failure', e)
69
69
  return null
70
70
  }
71
71
  }
@@ -81,13 +81,13 @@ export default class Crypto {
81
81
  const resp = await this.client.send(
82
82
  new DecryptCommand({
83
83
  KeyId: this.keyId,
84
- CiphertextBlob: Buffer.from(data, "hex"),
85
- EncryptionAlgorithm: "RSAES_OAEP_SHA_256",
86
- }),
84
+ CiphertextBlob: Buffer.from(data, 'hex'),
85
+ EncryptionAlgorithm: 'RSAES_OAEP_SHA_256',
86
+ })
87
87
  )
88
88
  return new TextDecoder().decode(resp.Plaintext)
89
89
  } catch (e) {
90
- console.error("Decryption failure", e)
90
+ console.error('Decryption failure', e)
91
91
  return null
92
92
  }
93
93
  }
package/src/Crypto/JWT.ts CHANGED
@@ -1,4 +1,4 @@
1
- import * as jwt from "jsonwebtoken"
1
+ import * as jwt from 'jsonwebtoken'
2
2
 
3
3
  /**
4
4
  * ${1:Description placeholder}
@@ -57,17 +57,12 @@ export default class JWT {
57
57
  * @param {?*} [opts]
58
58
  * @returns {string}
59
59
  */
60
- createToken(
61
- data: object,
62
- expiration?: string,
63
- overrideToken?: string,
64
- opts?: any,
65
- ): string {
60
+ createToken(data: object, expiration?: string, overrideToken?: string, opts?: any): string {
66
61
  const exp = expiration || this.defaultExpiration
67
62
  return jwt.sign(
68
63
  data,
69
64
  overrideToken || this.tokenSecret,
70
- exp ? { expiresIn: exp, ...(opts || {}) } : opts || {},
65
+ exp ? { expiresIn: exp, ...(opts || {}) } : opts || {}
71
66
  )
72
67
  }
73
68
  /**
@@ -86,8 +81,7 @@ export default class JWT {
86
81
  }
87
82
  } catch (err) {
88
83
  console.error(err)
89
- if (err instanceof jwt.TokenExpiredError)
90
- return { isValid: false, isExpired: true }
84
+ if (err instanceof jwt.TokenExpiredError) return { isValid: false, isExpired: true }
91
85
  }
92
86
  return { isValid: false }
93
87
  }
package/src/Globals.ts CHANGED
@@ -1,6 +1,6 @@
1
- import * as dotenv from "dotenv"
1
+ import * as dotenv from 'dotenv'
2
2
 
3
- import Utils from "./API/Utils"
3
+ import Utils from './API/Utils'
4
4
 
5
5
  // important for dev env to load .env file
6
6
  dotenv.config()
@@ -19,7 +19,7 @@ export default class Globals {
19
19
  * @static
20
20
  * @type {string}
21
21
  */
22
- public static ErrorResponseValidationFail = "Input validation failed: " //400
22
+ public static ErrorResponseValidationFail = 'Input validation failed: ' //400
23
23
  /**
24
24
  * Description placeholder
25
25
  *
@@ -27,8 +27,7 @@ export default class Globals {
27
27
  * @static
28
28
  * @type {string}
29
29
  */
30
- public static ErrorResponseInvalidServerResponse =
31
- "No valid response, this is a system error." //400
30
+ public static ErrorResponseInvalidServerResponse = 'No valid response, this is a system error.' //400
32
31
  /**
33
32
  * Description placeholder
34
33
  *
@@ -36,8 +35,7 @@ export default class Globals {
36
35
  * @static
37
36
  * @type {string}
38
37
  */
39
- public static ErrorResponseUnhandledError =
40
- "Unhandled error when processing request." //400
38
+ public static ErrorResponseUnhandledError = 'Unhandled error when processing request.' //400
41
39
  /**
42
40
  * Description placeholder
43
41
  *
@@ -45,7 +43,7 @@ export default class Globals {
45
43
  * @static
46
44
  * @type {string}
47
45
  */
48
- public static ErrorResponseNoRecords = "No events to be processed." //400
46
+ public static ErrorResponseNoRecords = 'No events to be processed.' //400
49
47
  /**
50
48
  * Description placeholder
51
49
  *
@@ -53,7 +51,7 @@ export default class Globals {
53
51
  * @static
54
52
  * @type {string}
55
53
  */
56
- public static ErrorCode_MissingParam = "MISSING_PARAM"
54
+ public static ErrorCode_MissingParam = 'MISSING_PARAM'
57
55
  /**
58
56
  * Description placeholder
59
57
  *
@@ -61,7 +59,7 @@ export default class Globals {
61
59
  * @static
62
60
  * @type {string}
63
61
  */
64
- public static ErrorCode_InvalidInput = "INVALID_INPUT"
62
+ public static ErrorCode_InvalidInput = 'INVALID_INPUT'
65
63
  /**
66
64
  * Description placeholder
67
65
  *
@@ -69,7 +67,7 @@ export default class Globals {
69
67
  * @static
70
68
  * @type {string}
71
69
  */
72
- public static ErrorCode_APIError = "API_ERROR"
70
+ public static ErrorCode_APIError = 'API_ERROR'
73
71
  /**
74
72
  * Description placeholder
75
73
  *
@@ -77,7 +75,7 @@ export default class Globals {
77
75
  * @static
78
76
  * @type {string}
79
77
  */
80
- public static ErrorCode_NoRecords = "EMPTY_EVENT"
78
+ public static ErrorCode_NoRecords = 'EMPTY_EVENT'
81
79
 
82
80
  /**
83
81
  * Description placeholder
@@ -86,8 +84,7 @@ export default class Globals {
86
84
  * @static
87
85
  * @type {*}
88
86
  */
89
- public static Listener_HTTP_DefaultPort =
90
- Utils.parseIntNullIfNaN(process.env.PORT) || 9000
87
+ public static Listener_HTTP_DefaultPort = Utils.parseIntNullIfNaN(process.env.PORT) || 9000
91
88
 
92
89
  /**
93
90
  * Description placeholder
@@ -96,7 +93,7 @@ export default class Globals {
96
93
  * @static
97
94
  * @type {string}
98
95
  */
99
- public static Listener_HTTP_DefaultHost = "localhost"
96
+ public static Listener_HTTP_DefaultHost = 'localhost'
100
97
  /**
101
98
  * Description placeholder
102
99
  *
@@ -104,7 +101,7 @@ export default class Globals {
104
101
  * @static
105
102
  * @type {string}
106
103
  */
107
- public static Listener_HTTP_ProxyRoute = "*"
104
+ public static Listener_HTTP_ProxyRoute = '*'
108
105
  /**
109
106
  * Description placeholder
110
107
  *
@@ -112,8 +109,7 @@ export default class Globals {
112
109
  * @static
113
110
  * @type {*}
114
111
  */
115
- public static Listener_HTTP_DefaultTimeout =
116
- Utils.parseIntNullIfNaN(process.env.TIMEOUT) || 30000
112
+ public static Listener_HTTP_DefaultTimeout = Utils.parseIntNullIfNaN(process.env.TIMEOUT) || 30000
117
113
  /**
118
114
  * Description placeholder
119
115
  *
@@ -121,8 +117,7 @@ export default class Globals {
121
117
  * @static
122
118
  * @type {*}
123
119
  */
124
- public static Listener_HTTP_DefaultHealthCheckRoute =
125
- process.env.HEALTH_ROUTE || "/health"
120
+ public static Listener_HTTP_DefaultHealthCheckRoute = process.env.HEALTH_ROUTE || '/health'
126
121
  //Resps
127
122
  /**
128
123
  * Description placeholder
@@ -131,8 +126,7 @@ export default class Globals {
131
126
  * @static
132
127
  * @type {string}
133
128
  */
134
- public static Resp_MSG_EXCEPTION =
135
- "[Proxy]: Exception during request execution!"
129
+ public static Resp_MSG_EXCEPTION = '[Proxy]: Exception during request execution!'
136
130
  /**
137
131
  * Description placeholder
138
132
  *
@@ -140,7 +134,7 @@ export default class Globals {
140
134
  * @static
141
135
  * @type {string}
142
136
  */
143
- public static Resp_CODE_EXCEPTION = "EXEC_EXCEPTION"
137
+ public static Resp_CODE_EXCEPTION = 'EXEC_EXCEPTION'
144
138
  /**
145
139
  * Description placeholder
146
140
  *
@@ -157,7 +151,7 @@ export default class Globals {
157
151
  * @static
158
152
  * @type {string}
159
153
  */
160
- public static Resp_MSG_INVALIDRESP = "[Proxy]: Invalid response from server!"
154
+ public static Resp_MSG_INVALIDRESP = '[Proxy]: Invalid response from server!'
161
155
  /**
162
156
  * Description placeholder
163
157
  *
@@ -165,7 +159,7 @@ export default class Globals {
165
159
  * @static
166
160
  * @type {string}
167
161
  */
168
- public static Resp_CODE_INVALIDRESP = "EMPTY_RESPONSE"
162
+ public static Resp_CODE_INVALIDRESP = 'EMPTY_RESPONSE'
169
163
  /**
170
164
  * Description placeholder
171
165
  *
@@ -1,9 +1,9 @@
1
- import * as abind from "abind"
2
- import * as stringify from "json-stringify-safe"
3
- import * as stackTrace from "stack-trace"
1
+ import * as abind from 'abind'
2
+ import * as stringify from 'json-stringify-safe'
3
+ import * as stackTrace from 'stack-trace'
4
4
 
5
5
  //
6
- import Utils from "../API/Utils"
6
+ import Utils from '../API/Utils'
7
7
  //
8
8
  /**
9
9
  * ${1:Description placeholder}
@@ -12,17 +12,17 @@ import Utils from "../API/Utils"
12
12
  * @enum {number}
13
13
  */
14
14
  export enum LOG_LEVELS {
15
- DEBUG = "DEBUG",
16
- INFO = "INFO",
17
- WARN = "WARN",
18
- ERROR = "ERROR",
15
+ DEBUG = 'DEBUG',
16
+ INFO = 'INFO',
17
+ WARN = 'WARN',
18
+ ERROR = 'ERROR',
19
19
  }
20
20
  /**
21
21
  * ${1:Description placeholder}
22
22
  *
23
23
  * @type {*}
24
24
  */
25
- const PURE_CONSOLE = console["notGlobalLogger"] ? console["origin"] : console
25
+ const PURE_CONSOLE = console['notGlobalLogger'] ? console['origin'] : console
26
26
  /**
27
27
  * ${1:Description placeholder}
28
28
  *
@@ -36,18 +36,18 @@ const DEFAULT_LOG_FUNCTION = PURE_CONSOLE.log.bind(PURE_CONSOLE)
36
36
  * @type {{}\}
37
37
  */
38
38
  const blacklist = [
39
- "password",
40
- "phonenumber" /*,'code'*/,
41
- "resetCode",
42
- "recaptchaToken",
43
- "token",
44
- "mfa",
45
- "REFRESH_TOKEN",
46
- "SECRET_HASH",
47
- "SecretHash",
48
- "AccessToken",
49
- "UserCode",
50
- "paymentMethodNonce",
39
+ 'password',
40
+ 'phonenumber' /*,'code'*/,
41
+ 'resetCode',
42
+ 'recaptchaToken',
43
+ 'token',
44
+ 'mfa',
45
+ 'REFRESH_TOKEN',
46
+ 'SECRET_HASH',
47
+ 'SecretHash',
48
+ 'AccessToken',
49
+ 'UserCode',
50
+ 'paymentMethodNonce',
51
51
  ]
52
52
  //
53
53
  /**
@@ -129,8 +129,8 @@ export default class Logger {
129
129
  //
130
130
  this._setupBindings()
131
131
  //
132
- this.log("Using logger with level: " + this._LOG_LEVEL.toString())
133
- this.debug("logger config: ", this._config)
132
+ this.log('Using logger with level: ' + this._LOG_LEVEL.toString())
133
+ this.debug('logger config: ', this._config)
134
134
  }
135
135
  /**
136
136
  * ${1:Description placeholder}
@@ -231,22 +231,14 @@ export default class Logger {
231
231
  * @param {string} caller
232
232
  * @returns {string}
233
233
  */
234
- private _formattedLog(
235
- level: LOG_LEVELS,
236
- msg: Array<string>,
237
- caller: string,
238
- ): string {
234
+ private _formattedLog(level: LOG_LEVELS, msg: Array<string>, caller: string): string {
239
235
  if (Utils.isHybridlessContainer() && this._transactionID) {
240
236
  return (
241
237
  `${this._transactionID}` +
242
- ` [${level.toString()}] [${caller}] ${msg
243
- .map(this._suppressSensitiveInfo)
244
- .join(" ")}`
238
+ ` [${level.toString()}] [${caller}] ${msg.map(this._suppressSensitiveInfo).join(' ')}`
245
239
  )
246
240
  } else {
247
- return `[${level.toString()}] [${caller}] ${msg
248
- .map(this._suppressSensitiveInfo)
249
- .join(" ")}`
241
+ return `[${level.toString()}] [${caller}] ${msg.map(this._suppressSensitiveInfo).join(' ')}`
250
242
  }
251
243
  }
252
244
  /**
@@ -263,12 +255,12 @@ export default class Logger {
263
255
  ? stackTrace.get()[safeIndex].getTypeName()
264
256
  : null
265
257
  if (!callerName) {
266
- callerName = stackTrace?.get()?.[safeIndex]?.getFileName()?.split("/")
267
- callerName = callerName?.slice(callerName?.indexOf("src"))?.join("/")
258
+ callerName = stackTrace?.get()?.[safeIndex]?.getFileName()?.split('/')
259
+ callerName = callerName?.slice(callerName?.indexOf('src'))?.join('/')
268
260
  }
269
- return callerName + ":" + stackTrace?.get()?.[safeIndex]?.getLineNumber()
261
+ return callerName + ':' + stackTrace?.get()?.[safeIndex]?.getLineNumber()
270
262
  }
271
- return ""
263
+ return ''
272
264
  }
273
265
  /* Helpers (core functionality) */
274
266
  /**
@@ -284,9 +276,7 @@ export default class Logger {
284
276
  const msg: Array<string> = []
285
277
  for (const arg of args) {
286
278
  const fMsg =
287
- typeof arg === "object" && !(arg instanceof Error)
288
- ? stringify(arg, null, 2)
289
- : arg
279
+ typeof arg === 'object' && !(arg instanceof Error) ? stringify(arg, null, 2) : arg
290
280
  msg.push(fMsg)
291
281
  }
292
282
  //push into logs stack
@@ -304,15 +294,12 @@ export default class Logger {
304
294
  //format message
305
295
  const msg: Array<string> = []
306
296
  //push exeception
307
- msg.push(exception.toString() + " -")
297
+ msg.push(exception.toString() + ' -')
308
298
  //get args
309
299
  for (const arg of args) if (arg != exception) msg.push(arg)
310
300
  if (exception.stack) msg.push(exception.stack) //push Exeception stack at the end
311
301
  //push into logs stack
312
- this._pushLog(
313
- LOG_LEVELS.ERROR,
314
- this._formattedLog(LOG_LEVELS.ERROR, msg, this._callerName(3)),
315
- )
302
+ this._pushLog(LOG_LEVELS.ERROR, this._formattedLog(LOG_LEVELS.ERROR, msg, this._callerName(3)))
316
303
  }
317
304
  /**
318
305
  * ${1:Description placeholder}
@@ -337,16 +324,14 @@ export default class Logger {
337
324
  private _suppressSensitiveInfo(value: any): string {
338
325
  //realy false
339
326
  if (!this._filterBlacklist) return value
340
- if (typeof value == "string") {
327
+ if (typeof value == 'string') {
341
328
  //content based replacement
342
329
  if (this._filterBlacklist) {
343
330
  this._filterBlacklist.forEach(() => {
344
331
  const match = this._filterBlacklist
345
- ? this._filterBlacklist.find((f) =>
346
- value.toLowerCase().includes(f.toLowerCase()),
347
- )
332
+ ? this._filterBlacklist.find(f => value.toLowerCase().includes(f.toLowerCase()))
348
333
  : false
349
- if (match) value = "**SUPPRESSED_SENSITIVE_DATA**"
334
+ if (match) value = '**SUPPRESSED_SENSITIVE_DATA**'
350
335
  })
351
336
  }
352
337
  return value
@@ -1,8 +1,8 @@
1
- import * as SES from "@aws-sdk/client-ses"
2
- import { defaultProvider } from "@aws-sdk/credential-provider-node"
3
- import * as Email from "email-templates"
4
- import * as nodemailer from "nodemailer"
5
- import type * as SESTransport from "nodemailer/lib/ses-transport"
1
+ import * as SES from '@aws-sdk/client-ses'
2
+ import { defaultProvider } from '@aws-sdk/credential-provider-node'
3
+ import * as Email from 'email-templates'
4
+ import * as nodemailer from 'nodemailer'
5
+ import type * as SESTransport from 'nodemailer/lib/ses-transport'
6
6
 
7
7
  /**
8
8
  * ${1:Description placeholder}
@@ -27,7 +27,7 @@ export default class Mailer {
27
27
  * @readonly
28
28
  * @type {string}
29
29
  */
30
- private readonly templateDefaultFile: string = "html"
30
+ private readonly templateDefaultFile: string = 'html'
31
31
  /**
32
32
  * ${1:Description placeholder}
33
33
  *
@@ -53,7 +53,7 @@ export default class Mailer {
53
53
  SES: {
54
54
  ses: new SES.SESClient({
55
55
  credentials: defaultProvider(),
56
- apiVersion: "2010-12-01",
56
+ apiVersion: '2010-12-01',
57
57
  region,
58
58
  }),
59
59
  aws: SES,
@@ -85,7 +85,7 @@ export default class Mailer {
85
85
  optionalReplyTo?: string,
86
86
  // TODO: improve attachment type -> Attachment
87
87
  optionalAttachments?: any[],
88
- optionalTransport?: Email.NodeMailerTransportOptions,
88
+ optionalTransport?: Email.NodeMailerTransportOptions
89
89
  ) {
90
90
  //Generate emails
91
91
  const email = new Email({
@@ -105,9 +105,9 @@ export default class Mailer {
105
105
  let resp = null
106
106
  try {
107
107
  resp = await email.send()
108
- console.debug("Mailer resp:", resp)
108
+ console.debug('Mailer resp:', resp)
109
109
  } catch (e) {
110
- console.error("Mailer error:", e)
110
+ console.error('Mailer error:', e)
111
111
  throw e
112
112
  }
113
113
  return resp
@@ -136,7 +136,7 @@ export default class Mailer {
136
136
  optionalReplyTo?: string,
137
137
  // TODO: improve attachment type -> Attachment
138
138
  optionalAttachments?: any[],
139
- optionalTransport?: Email.NodeMailerTransportOptions,
139
+ optionalTransport?: Email.NodeMailerTransportOptions
140
140
  ) {
141
141
  //Generate emails
142
142
  const email = new Email({
@@ -155,9 +155,9 @@ export default class Mailer {
155
155
  try {
156
156
  const chosenTemplate = await this.chooseTemplate(templates, data)
157
157
  resp = await email.send({ template: chosenTemplate, locals: data })
158
- console.debug("Mailer resp:", resp)
158
+ console.debug('Mailer resp:', resp)
159
159
  } catch (e) {
160
- console.error("Mailer error:", e)
160
+ console.error('Mailer error:', e)
161
161
  throw e
162
162
  }
163
163
  return resp
@@ -176,7 +176,7 @@ export default class Mailer {
176
176
  host: string,
177
177
  portNumber: number,
178
178
  user: string,
179
- password: string,
179
+ password: string
180
180
  ): Email.NodeMailerTransportOptions {
181
181
  const smtpTransporter = nodemailer.createTransport({
182
182
  host: host,
@@ -200,10 +200,7 @@ export default class Mailer {
200
200
  * @param {object} data
201
201
  * @returns {Promise<string>}
202
202
  */
203
- private async chooseTemplate(
204
- templates: string | Array<string>,
205
- data: object,
206
- ): Promise<string> {
203
+ private async chooseTemplate(templates: string | Array<string>, data: object): Promise<string> {
207
204
  if (Array.isArray(templates)) {
208
205
  //For each template check if can render it
209
206
  for (const template of templates) {
@@ -214,7 +211,7 @@ export default class Mailer {
214
211
  }
215
212
  throw new Error(
216
213
  `Could not render email with template ${templates} and following data. Please, check logs above! ` +
217
- JSON.stringify(data, null, 2),
214
+ JSON.stringify(data, null, 2)
218
215
  )
219
216
  }
220
217
  /**
@@ -226,22 +223,13 @@ export default class Mailer {
226
223
  * @param {object} data
227
224
  * @returns {Promise<boolean>}
228
225
  */
229
- private async canRenderTemplate(
230
- template: string,
231
- data: object,
232
- ): Promise<boolean> {
226
+ private async canRenderTemplate(template: string, data: object): Promise<boolean> {
233
227
  let validRenderResp = null
234
228
  try {
235
229
  const email = new Email()
236
- validRenderResp = await email.render(
237
- `${template}/${this.templateDefaultFile}`,
238
- data,
239
- )
230
+ validRenderResp = await email.render(`${template}/${this.templateDefaultFile}`, data)
240
231
  } catch (e) {
241
- console.log(
242
- `Error while checking renderability of email template ${template}`,
243
- e,
244
- )
232
+ console.log(`Error while checking renderability of email template ${template}`, e)
245
233
  }
246
234
  return validRenderResp != null
247
235
  }