lesgo 1.0.0 → 2.1.0

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 (315) hide show
  1. package/README.md +5 -4
  2. package/bin/lesgo-scripts.sh +4 -4
  3. package/dist/config/app.d.ts +7 -0
  4. package/dist/config/app.js +9 -0
  5. package/dist/config/aws.d.ts +5 -0
  6. package/dist/config/aws.js +4 -0
  7. package/dist/config/basicAuth.d.ts +7 -0
  8. package/dist/config/basicAuth.js +8 -0
  9. package/dist/config/crypto.d.ts +10 -0
  10. package/dist/config/crypto.js +9 -0
  11. package/dist/config/dynamodb.d.ts +8 -0
  12. package/dist/config/dynamodb.js +14 -0
  13. package/dist/config/elasticache.d.ts +7 -0
  14. package/dist/config/elasticache.js +6 -0
  15. package/dist/config/index.d.ts +11 -0
  16. package/dist/config/index.js +11 -0
  17. package/dist/config/jwt.d.ts +12 -0
  18. package/dist/config/jwt.js +16 -0
  19. package/dist/config/rds.d.ts +12 -0
  20. package/dist/config/rds.js +13 -0
  21. package/dist/config/s3.d.ts +5 -0
  22. package/dist/config/s3.js +5 -0
  23. package/dist/config/secretsManager.d.ts +4 -0
  24. package/dist/config/secretsManager.js +4 -0
  25. package/dist/config/sqs.d.ts +9 -0
  26. package/dist/config/sqs.js +18 -0
  27. package/dist/exceptions/LesgoException.d.ts +6 -0
  28. package/{src → dist}/exceptions/LesgoException.js +5 -4
  29. package/dist/exceptions/index.d.ts +1 -0
  30. package/dist/exceptions/index.js +1 -0
  31. package/dist/middlewares/disconnectMiddleware.d.ts +8 -0
  32. package/dist/middlewares/disconnectMiddleware.js +78 -0
  33. package/dist/middlewares/httpMiddleware.d.ts +12 -0
  34. package/dist/middlewares/httpMiddleware.js +74 -0
  35. package/dist/middlewares/httpResponseMiddleware.d.ts +7 -0
  36. package/dist/middlewares/httpResponseMiddleware.js +128 -0
  37. package/dist/middlewares/index.d.ts +7 -0
  38. package/dist/middlewares/index.js +7 -0
  39. package/dist/middlewares/invokeCommandMiddleware.d.ts +12 -0
  40. package/dist/middlewares/invokeCommandMiddleware.js +70 -0
  41. package/dist/middlewares/sqsMiddleware.d.ts +10 -0
  42. package/dist/middlewares/sqsMiddleware.js +70 -0
  43. package/dist/middlewares/verifyBasicAuthMiddleware.d.ts +8 -0
  44. package/dist/middlewares/verifyBasicAuthMiddleware.js +59 -0
  45. package/dist/middlewares/verifyJwtMiddleware.d.ts +6 -0
  46. package/dist/middlewares/verifyJwtMiddleware.js +37 -0
  47. package/dist/services/DynamoDbService/deleteRecord.d.ts +8 -0
  48. package/dist/services/DynamoDbService/deleteRecord.js +69 -0
  49. package/dist/services/DynamoDbService/getClient.d.ts +7 -0
  50. package/dist/services/DynamoDbService/getClient.js +30 -0
  51. package/dist/services/DynamoDbService/getTableName.d.ts +2 -0
  52. package/dist/services/DynamoDbService/getTableName.js +15 -0
  53. package/dist/services/DynamoDbService/index.d.ts +6 -0
  54. package/dist/services/DynamoDbService/index.js +6 -0
  55. package/dist/services/DynamoDbService/putRecord.d.ts +8 -0
  56. package/dist/services/DynamoDbService/putRecord.js +64 -0
  57. package/dist/services/DynamoDbService/query.d.ts +7 -0
  58. package/dist/services/DynamoDbService/query.js +78 -0
  59. package/dist/services/DynamoDbService/scan.d.ts +7 -0
  60. package/dist/services/DynamoDbService/scan.js +60 -0
  61. package/dist/services/DynamoDbService/updateRecord.d.ts +9 -0
  62. package/dist/services/DynamoDbService/updateRecord.js +89 -0
  63. package/dist/services/ElastiCacheRedisService/deleteRedisCache.d.ts +3 -0
  64. package/dist/services/ElastiCacheRedisService/deleteRedisCache.js +62 -0
  65. package/dist/services/ElastiCacheRedisService/disconnectElastiCacheRedisClient.d.ts +11 -0
  66. package/dist/services/ElastiCacheRedisService/disconnectElastiCacheRedisClient.js +69 -0
  67. package/dist/services/ElastiCacheRedisService/getElastiCacheRedisClient.d.ts +12 -0
  68. package/dist/services/ElastiCacheRedisService/getElastiCacheRedisClient.js +114 -0
  69. package/dist/services/ElastiCacheRedisService/getRedisCache.d.ts +3 -0
  70. package/dist/services/ElastiCacheRedisService/getRedisCache.js +70 -0
  71. package/dist/services/ElastiCacheRedisService/index.d.ts +5 -0
  72. package/dist/services/ElastiCacheRedisService/index.js +5 -0
  73. package/dist/services/ElastiCacheRedisService/setRedisCache.d.ts +6 -0
  74. package/dist/services/ElastiCacheRedisService/setRedisCache.js +77 -0
  75. package/dist/services/JWTService/decodeJwt.d.ts +7 -0
  76. package/dist/services/JWTService/decodeJwt.js +9 -0
  77. package/dist/services/JWTService/getJwtSecret.d.ts +13 -0
  78. package/dist/services/JWTService/getJwtSecret.js +54 -0
  79. package/dist/services/JWTService/index.d.ts +2 -0
  80. package/dist/services/JWTService/index.js +2 -0
  81. package/dist/services/JWTService/sign.d.ts +3 -0
  82. package/dist/services/JWTService/sign.js +31 -0
  83. package/dist/services/JWTService/verify.d.ts +7 -0
  84. package/dist/services/JWTService/verify.js +61 -0
  85. package/dist/services/LoggerService.d.ts +46 -0
  86. package/{src → dist}/services/LoggerService.js +29 -60
  87. package/dist/services/RDSAuroraMySQLProxyService/disconnectMySQLProxyClient.d.ts +2 -0
  88. package/dist/services/RDSAuroraMySQLProxyService/disconnectMySQLProxyClient.js +60 -0
  89. package/dist/services/RDSAuroraMySQLProxyService/getMySQLProxyClient.d.ts +8 -0
  90. package/dist/services/RDSAuroraMySQLProxyService/getMySQLProxyClient.js +87 -0
  91. package/dist/services/RDSAuroraMySQLProxyService/index.d.ts +3 -0
  92. package/dist/services/RDSAuroraMySQLProxyService/index.js +3 -0
  93. package/dist/services/RDSAuroraMySQLProxyService/query.d.ts +4 -0
  94. package/dist/services/RDSAuroraMySQLProxyService/query.js +63 -0
  95. package/dist/services/S3Service/getClient.d.ts +4 -0
  96. package/dist/services/S3Service/getClient.js +28 -0
  97. package/dist/services/S3Service/getDownloadSignedUrl.d.ts +7 -0
  98. package/dist/services/S3Service/getDownloadSignedUrl.js +58 -0
  99. package/dist/services/S3Service/getHeadObject.d.ts +13 -0
  100. package/dist/services/S3Service/getHeadObject.js +83 -0
  101. package/dist/services/S3Service/getObject.d.ts +10 -0
  102. package/dist/services/S3Service/getObject.js +89 -0
  103. package/dist/services/S3Service/getUploadSignedUrl.d.ts +7 -0
  104. package/dist/services/S3Service/getUploadSignedUrl.js +61 -0
  105. package/dist/services/S3Service/index.d.ts +6 -0
  106. package/dist/services/S3Service/index.js +6 -0
  107. package/dist/services/S3Service/putObject.d.ts +9 -0
  108. package/dist/services/S3Service/putObject.js +77 -0
  109. package/dist/services/SQSService/deleteMessage.d.ts +9 -0
  110. package/dist/services/SQSService/deleteMessage.js +69 -0
  111. package/dist/services/SQSService/dispatch.d.ts +9 -0
  112. package/dist/services/SQSService/dispatch.js +71 -0
  113. package/dist/services/SQSService/getClient.d.ts +4 -0
  114. package/dist/services/SQSService/getClient.js +28 -0
  115. package/dist/services/SQSService/getQueueUrl.d.ts +7 -0
  116. package/dist/services/SQSService/getQueueUrl.js +25 -0
  117. package/dist/services/SQSService/index.d.ts +4 -0
  118. package/dist/services/SQSService/index.js +4 -0
  119. package/dist/services/SQSService/receiveMessages.d.ts +8 -0
  120. package/dist/services/SQSService/receiveMessages.js +65 -0
  121. package/dist/services/SecretsManagerService/getClient.d.ts +7 -0
  122. package/dist/services/SecretsManagerService/getClient.js +28 -0
  123. package/dist/services/SecretsManagerService/getSecretValue.d.ts +7 -0
  124. package/dist/services/SecretsManagerService/getSecretValue.js +65 -0
  125. package/dist/services/SecretsManagerService/index.d.ts +2 -0
  126. package/dist/services/SecretsManagerService/index.js +2 -0
  127. package/dist/services/index.d.ts +1 -0
  128. package/dist/services/index.js +1 -0
  129. package/dist/types/aws.d.ts +8 -0
  130. package/dist/types/aws.js +1 -0
  131. package/dist/utils/cache/redis/deleteCache.d.ts +19 -0
  132. package/dist/utils/cache/redis/deleteCache.js +21 -0
  133. package/dist/utils/cache/redis/getCache.d.ts +22 -0
  134. package/dist/utils/cache/redis/getCache.js +24 -0
  135. package/dist/utils/cache/redis/getClient.d.ts +30 -0
  136. package/dist/utils/cache/redis/getClient.js +32 -0
  137. package/dist/utils/cache/redis/index.d.ts +4 -0
  138. package/dist/utils/cache/redis/index.js +4 -0
  139. package/dist/utils/cache/redis/setCache.d.ts +25 -0
  140. package/dist/utils/cache/redis/setCache.js +26 -0
  141. package/dist/utils/crypto/decrypt.d.ts +33 -0
  142. package/dist/utils/crypto/decrypt.js +59 -0
  143. package/dist/utils/crypto/encrypt.d.ts +31 -0
  144. package/dist/utils/crypto/encrypt.js +41 -0
  145. package/dist/utils/crypto/hash.d.ts +31 -0
  146. package/dist/utils/crypto/hash.js +56 -0
  147. package/dist/utils/crypto/index.d.ts +3 -0
  148. package/dist/utils/crypto/index.js +3 -0
  149. package/dist/utils/crypto/validateEncryptionFields.d.ts +19 -0
  150. package/dist/utils/crypto/validateEncryptionFields.js +71 -0
  151. package/dist/utils/db/mysql/proxy/disconnect.d.ts +2 -0
  152. package/dist/utils/db/mysql/proxy/disconnect.js +5 -0
  153. package/dist/utils/db/mysql/proxy/disconnectDb.d.ts +2 -0
  154. package/dist/utils/db/mysql/proxy/disconnectDb.js +5 -0
  155. package/dist/utils/db/mysql/proxy/getClient.d.ts +4 -0
  156. package/dist/utils/db/mysql/proxy/getClient.js +5 -0
  157. package/dist/utils/db/mysql/proxy/index.d.ts +3 -0
  158. package/dist/utils/db/mysql/proxy/index.js +3 -0
  159. package/dist/utils/db/mysql/proxy/query.d.ts +4 -0
  160. package/dist/utils/db/mysql/proxy/query.js +45 -0
  161. package/dist/utils/dynamodb/deleteRecord.d.ts +5 -0
  162. package/dist/utils/dynamodb/deleteRecord.js +39 -0
  163. package/dist/utils/dynamodb/getClient.d.ts +3 -0
  164. package/dist/utils/dynamodb/getClient.js +5 -0
  165. package/dist/utils/dynamodb/index.d.ts +6 -0
  166. package/dist/utils/dynamodb/index.js +6 -0
  167. package/dist/utils/dynamodb/putRecord.d.ts +4 -0
  168. package/dist/utils/dynamodb/putRecord.js +39 -0
  169. package/dist/utils/dynamodb/query.d.ts +5 -0
  170. package/dist/utils/dynamodb/query.js +52 -0
  171. package/dist/utils/dynamodb/scan.d.ts +4 -0
  172. package/dist/utils/dynamodb/scan.js +40 -0
  173. package/dist/utils/dynamodb/updateRecord.d.ts +5 -0
  174. package/dist/utils/dynamodb/updateRecord.js +53 -0
  175. package/dist/utils/formatUnixTimestamp.d.ts +8 -0
  176. package/dist/utils/formatUnixTimestamp.js +17 -0
  177. package/dist/utils/generateUid.d.ts +13 -0
  178. package/{src → dist}/utils/generateUid.js +9 -4
  179. package/dist/utils/getCurrentDatetime.d.ts +2 -0
  180. package/dist/utils/getCurrentDatetime.js +4 -0
  181. package/dist/utils/getCurrentTimestamp.d.ts +7 -0
  182. package/dist/utils/getCurrentTimestamp.js +9 -0
  183. package/dist/utils/getJwtSubFromAuthHeader.d.ts +9 -0
  184. package/dist/utils/getJwtSubFromAuthHeader.js +24 -0
  185. package/dist/utils/index.d.ts +9 -0
  186. package/dist/utils/index.js +9 -0
  187. package/dist/utils/isDecimal.d.ts +8 -0
  188. package/dist/utils/isDecimal.js +9 -0
  189. package/dist/utils/isEmail.d.ts +9 -0
  190. package/{src → dist}/utils/isEmail.js +9 -4
  191. package/dist/utils/isEmpty.d.ts +8 -0
  192. package/dist/utils/isEmpty.js +19 -0
  193. package/dist/utils/jwt/index.d.ts +2 -0
  194. package/dist/utils/jwt/index.js +2 -0
  195. package/dist/utils/jwt/sign.d.ts +3 -0
  196. package/dist/utils/jwt/sign.js +5 -0
  197. package/dist/utils/jwt/verify.d.ts +3 -0
  198. package/dist/utils/jwt/verify.js +12 -0
  199. package/dist/utils/logger.d.ts +20 -0
  200. package/dist/utils/logger.js +38 -0
  201. package/dist/utils/s3/getClient.d.ts +3 -0
  202. package/dist/utils/s3/getClient.js +5 -0
  203. package/dist/utils/s3/getDownloadSignedUrl.d.ts +5 -0
  204. package/dist/utils/s3/getDownloadSignedUrl.js +39 -0
  205. package/dist/utils/s3/getHeadObject.d.ts +10 -0
  206. package/dist/utils/s3/getHeadObject.js +39 -0
  207. package/dist/utils/s3/getObject.d.ts +13 -0
  208. package/dist/utils/s3/getObject.js +51 -0
  209. package/dist/utils/s3/getUploadSignedUrl.d.ts +5 -0
  210. package/dist/utils/s3/getUploadSignedUrl.js +39 -0
  211. package/dist/utils/s3/index.d.ts +6 -0
  212. package/dist/utils/s3/index.js +6 -0
  213. package/dist/utils/s3/putObject.d.ts +5 -0
  214. package/dist/utils/s3/putObject.js +39 -0
  215. package/dist/utils/secretsmanager/getClient.d.ts +3 -0
  216. package/dist/utils/secretsmanager/getClient.js +5 -0
  217. package/dist/utils/secretsmanager/getSecretValue.d.ts +4 -0
  218. package/dist/utils/secretsmanager/getSecretValue.js +68 -0
  219. package/dist/utils/secretsmanager/index.d.ts +2 -0
  220. package/dist/utils/secretsmanager/index.js +2 -0
  221. package/dist/utils/sqs/deleteMessage.d.ts +5 -0
  222. package/dist/utils/sqs/deleteMessage.js +39 -0
  223. package/dist/utils/sqs/dispatch.d.ts +5 -0
  224. package/dist/utils/sqs/dispatch.js +39 -0
  225. package/dist/utils/sqs/getClient.d.ts +3 -0
  226. package/dist/utils/sqs/getClient.js +5 -0
  227. package/dist/utils/sqs/index.d.ts +4 -0
  228. package/dist/utils/sqs/index.js +4 -0
  229. package/dist/utils/sqs/receiveMessages.d.ts +5 -0
  230. package/dist/utils/sqs/receiveMessages.js +39 -0
  231. package/dist/utils/validateFields.d.ts +22 -0
  232. package/{src → dist}/utils/validateFields.js +13 -19
  233. package/package.json +145 -34
  234. package/src/exceptions/__tests__/LesgoException.spec.js +0 -24
  235. package/src/exceptions/index.js +0 -4
  236. package/src/index.js +0 -4
  237. package/src/middlewares/__mocks__/ValidationErrorException.js +0 -18
  238. package/src/middlewares/__tests__/basicAuthMiddleware.spec.js +0 -264
  239. package/src/middlewares/__tests__/clientAuthMiddleware.spec.js +0 -235
  240. package/src/middlewares/__tests__/errorHttpResponseMiddleware.spec.js +0 -203
  241. package/src/middlewares/__tests__/gzipHttpResponse.spec.js +0 -185
  242. package/src/middlewares/__tests__/httpNoOutputMiddleware.spec.js +0 -201
  243. package/src/middlewares/__tests__/normalizeHttpRequestMiddleware.spec.js +0 -181
  244. package/src/middlewares/__tests__/normalizeSQSMessageMiddleware.spec.js +0 -120
  245. package/src/middlewares/__tests__/successHttpResponseMiddleware.spec.js +0 -172
  246. package/src/middlewares/__tests__/verifyJwtMiddleware.spec.js +0 -297
  247. package/src/middlewares/basicAuthMiddleware.js +0 -125
  248. package/src/middlewares/clientAuthMiddleware.js +0 -103
  249. package/src/middlewares/errorHttpResponseMiddleware.js +0 -101
  250. package/src/middlewares/gzipHttpResponse.js +0 -98
  251. package/src/middlewares/httpMiddleware.js +0 -19
  252. package/src/middlewares/httpNoOutputMiddleware.js +0 -91
  253. package/src/middlewares/index.js +0 -19
  254. package/src/middlewares/normalizeHttpRequestMiddleware.js +0 -101
  255. package/src/middlewares/normalizeSQSMessageMiddleware.js +0 -67
  256. package/src/middlewares/successHttpResponseMiddleware.js +0 -85
  257. package/src/middlewares/verifyJwtMiddleware.js +0 -73
  258. package/src/services/AuroraDbRDSProxyService.js +0 -182
  259. package/src/services/AuroraDbService.js +0 -111
  260. package/src/services/DynamoDbService.js +0 -177
  261. package/src/services/ElastiCacheService.js +0 -17
  262. package/src/services/ElasticsearchService.js +0 -181
  263. package/src/services/FirebaseAdminService.js +0 -108
  264. package/src/services/JwtService.js +0 -52
  265. package/src/services/S3Service.js +0 -59
  266. package/src/services/SQSService.js +0 -65
  267. package/src/services/__tests__/AuroraDbRDSProxyService.spec.js +0 -278
  268. package/src/services/__tests__/AuroraDbService.spec.js +0 -211
  269. package/src/services/__tests__/AwsElasticsearchConnection.spec.js +0 -89
  270. package/src/services/__tests__/DynamoDbService.spec.js +0 -314
  271. package/src/services/__tests__/ElasticsearchService.spec.js +0 -201
  272. package/src/services/__tests__/FirebaseAdminService.spec.js +0 -356
  273. package/src/services/__tests__/JwtService.spec.js +0 -35
  274. package/src/services/__tests__/LengthAwarePaginator.spec.js +0 -223
  275. package/src/services/__tests__/LoggerService.spec.js +0 -267
  276. package/src/services/__tests__/Paginator.spec.js +0 -383
  277. package/src/services/__tests__/S3Service.spec.js +0 -55
  278. package/src/services/__tests__/SQSService.spec.js +0 -47
  279. package/src/services/__tests__/SignedRequest.spec.js +0 -103
  280. package/src/services/aws/AwsElasticsearchConnection.js +0 -59
  281. package/src/services/aws/SignedRequest.js +0 -158
  282. package/src/services/index.js +0 -19
  283. package/src/services/pagination/LengthAwarePaginator.js +0 -49
  284. package/src/services/pagination/Paginator.js +0 -260
  285. package/src/utils/__mocks__/db.js +0 -109
  286. package/src/utils/__tests__/cache.spec.js +0 -131
  287. package/src/utils/__tests__/crypto.spec.js +0 -122
  288. package/src/utils/__tests__/db.spec.js +0 -70
  289. package/src/utils/__tests__/dynamodb.spec.js +0 -27
  290. package/src/utils/__tests__/elasticsearch.spec.js +0 -43
  291. package/src/utils/__tests__/generateUid.spec.js +0 -36
  292. package/src/utils/__tests__/getJwtSubFromAuthHeader.spec.js +0 -20
  293. package/src/utils/__tests__/isDecimal.spec.js +0 -12
  294. package/src/utils/__tests__/isEmail.spec.js +0 -28
  295. package/src/utils/__tests__/isEmpty.spec.js +0 -31
  296. package/src/utils/__tests__/logger.spec.js +0 -11
  297. package/src/utils/__tests__/objectStore.spec.js +0 -67
  298. package/src/utils/__tests__/prepSQLInsertParams.spec.js +0 -46
  299. package/src/utils/__tests__/prepSQLUpdateParams.spec.js +0 -36
  300. package/src/utils/__tests__/queue.spec.js +0 -54
  301. package/src/utils/__tests__/validateFields.spec.js +0 -374
  302. package/src/utils/cache.js +0 -215
  303. package/src/utils/crypto.js +0 -77
  304. package/src/utils/db.js +0 -17
  305. package/src/utils/dynamodb.js +0 -6
  306. package/src/utils/elasticsearch.js +0 -20
  307. package/src/utils/getJwtSubFromAuthHeader.js +0 -18
  308. package/src/utils/index.js +0 -26
  309. package/src/utils/isDecimal.js +0 -2
  310. package/src/utils/isEmpty.js +0 -6
  311. package/src/utils/logger.js +0 -25
  312. package/src/utils/objectStore.js +0 -11
  313. package/src/utils/prepSQLInsertParams.js +0 -21
  314. package/src/utils/prepSQLUpdateParams.js +0 -25
  315. package/src/utils/queue.js +0 -11
@@ -1,182 +0,0 @@
1
- import mysql from 'mysql2/promise';
2
- import logger from '../utils/logger';
3
- import isEmpty from '../utils/isEmpty';
4
- import LesgoException from '../exceptions/LesgoException';
5
- import LengthAwarePaginator from './pagination/LengthAwarePaginator';
6
- import Paginator from './pagination/Paginator';
7
-
8
- const FILE = 'Lesgo/services/AuroraDbRDSProxyService';
9
-
10
- /**
11
- * Service to connect to AWS Aurora Provisioned MySQL Database via RDS Proxy.
12
- * Use Services/AuroraDbServerlessService for the Serverless type via Data API.
13
- */
14
- export default class AuroraDbRDSProxyService {
15
- constructor(opts = {}) {
16
- const { host, user, password, database } = opts;
17
-
18
- this.clientOpts = {
19
- host,
20
- user,
21
- password,
22
- database,
23
- };
24
-
25
- this.conn = {};
26
- }
27
-
28
- /**
29
- * Persists the database connection for later use
30
- *
31
- * @param {*} connectionOpts
32
- * @returns
33
- */
34
- async pConnect(connectionOpts = {}) {
35
- await this.connect({ ...connectionOpts, persists: true });
36
- }
37
-
38
- async connect(connectionOpts = {}) {
39
- const clientOpts = {
40
- host: connectionOpts.host ? connectionOpts.host : this.clientOpts.host,
41
- user: connectionOpts.user ? connectionOpts.user : this.clientOpts.user,
42
- password: connectionOpts.password
43
- ? connectionOpts.password
44
- : this.clientOpts.password,
45
- database: connectionOpts.database
46
- ? connectionOpts.database
47
- : this.clientOpts.database,
48
- };
49
-
50
- const persistentConn = connectionOpts.persists;
51
-
52
- logger.debug(`${FILE}::PREPARING DB CONNECTION`, {
53
- clientOpts,
54
- persistentConn,
55
- });
56
-
57
- const conn = await mysql.createConnection(clientOpts);
58
- conn.config.namedPlaceholders = true;
59
- logger.debug(`${FILE}::DB CONNECTED`);
60
-
61
- if (persistentConn) {
62
- this.conn = conn;
63
- }
64
-
65
- return conn;
66
- }
67
-
68
- /* eslint-disable-next-line class-methods-use-this */
69
- async end(conn = {}) {
70
- logger.debug(`${FILE}::ENDING DB CONNECTION`);
71
- if (!isEmpty(conn)) {
72
- await conn.end();
73
- logger.debug(`${FILE}::DB DISCONNECTED`);
74
- } else {
75
- await this.conn.end();
76
- logger.debug(`${FILE}::PERSISTED DB DISCONNECTED`);
77
- }
78
- }
79
-
80
- async query(sql, sqlParams, connectionOpts = {}) {
81
- let conn = {};
82
- if (!isEmpty(connectionOpts)) {
83
- conn = await this.connect(connectionOpts);
84
- } else if (isEmpty(this.conn)) {
85
- conn = await this.connect();
86
- } else {
87
- conn = this.conn;
88
- }
89
-
90
- try {
91
- logger.debug(`${FILE}::QUERYING_DB`, { sql, sqlParams });
92
- const [results, fields] = await conn.execute(sql, sqlParams);
93
- logger.debug(`${FILE}::DB_RESPONSE`, { results, fields });
94
-
95
- return { results, fields };
96
- } catch (err) {
97
- throw new LesgoException(
98
- 'Exception caught executing SQL Statement',
99
- `${FILE}::QUERY_EXECUTION_EXCEPTION`,
100
- 500,
101
- { err }
102
- );
103
- } finally {
104
- if (isEmpty(this.conn) || !isEmpty(connectionOpts)) await this.end(conn);
105
- }
106
- }
107
-
108
- async select(sql, sqlParams, connectionOpts = {}) {
109
- const resp = await this.query(sql, sqlParams, connectionOpts);
110
- return resp.results;
111
- }
112
-
113
- async selectFirst(sql, sqlParams, connectionOpts = {}) {
114
- const resp = await this.query(sql, sqlParams, connectionOpts);
115
- return resp.results[0];
116
- }
117
-
118
- async selectPaginate(
119
- sql,
120
- sqlParams,
121
- perPage = 10,
122
- currentPage = 1,
123
- total = null,
124
- connectionOpts = {}
125
- ) {
126
- let paginator;
127
- if (typeof total === 'number') {
128
- paginator = new LengthAwarePaginator(
129
- this,
130
- sql,
131
- sqlParams,
132
- {
133
- perPage,
134
- currentPage,
135
- total,
136
- },
137
- connectionOpts
138
- );
139
- } else {
140
- paginator = new Paginator(
141
- this,
142
- sql,
143
- sqlParams,
144
- {
145
- perPage,
146
- currentPage,
147
- },
148
- connectionOpts
149
- );
150
- }
151
-
152
- return (await paginator).toObject();
153
- }
154
-
155
- async insert(sql, sqlParams, connectionOpts = {}) {
156
- const resp = await this.query(sql, sqlParams, connectionOpts);
157
-
158
- if (resp.results.affectedRows <= 0) {
159
- throw new LesgoException(
160
- 'No records inserted from INSERT query',
161
- `${FILE}::NO_RECORDS_INSERTED`,
162
- 400,
163
- { resp, sql, sqlParams }
164
- );
165
- }
166
-
167
- return resp.results.insertId;
168
- }
169
-
170
- async update(sql, sqlParams, connectionOpts = {}) {
171
- const resp = await this.query(sql, sqlParams, connectionOpts);
172
-
173
- if (resp.results.changedRows <= 0) {
174
- logger.warn(`${FILE}::No records updated from UPDATE query`, {
175
- sql,
176
- sqlParams,
177
- });
178
- }
179
-
180
- return Promise.resolve();
181
- }
182
- }
@@ -1,111 +0,0 @@
1
- import dataApiClient from 'data-api-client';
2
- import logger from '../utils/logger';
3
- import LesgoException from '../exceptions/LesgoException';
4
- import LengthAwarePaginator from './pagination/LengthAwarePaginator';
5
- import Paginator from './pagination/Paginator';
6
-
7
- const FILE = 'Lesgo/services/AuroraDbService';
8
-
9
- export default class AuroraDbService {
10
- constructor(opts = {}) {
11
- this.client = null;
12
- this.connect(opts);
13
- }
14
-
15
- connect(opts) {
16
- const { secretArn, resourceArn, database, region } = opts;
17
-
18
- const clientOpts = {
19
- secretArn,
20
- resourceArn,
21
- database,
22
- };
23
-
24
- if (region) {
25
- clientOpts.region = region;
26
- }
27
-
28
- this.client = dataApiClient(clientOpts);
29
- }
30
-
31
- async query(sql, sqlParams) {
32
- try {
33
- logger.debug(`${FILE}::QUERYING_DB`, { sql, sqlParams });
34
- const resp = await this.client.query(sql, sqlParams);
35
- logger.debug(`${FILE}::DB_RESPONSE`, { resp });
36
-
37
- return resp;
38
- } catch (err) {
39
- throw new LesgoException(
40
- 'Exception caught executing SQL Statement',
41
- 'AURORADBSERVICE_QUERY_EXCEPTION',
42
- 500,
43
- { err }
44
- );
45
- }
46
- }
47
-
48
- async select(sql, sqlParams) {
49
- const resp = await this.query(sql, sqlParams);
50
- return resp.records;
51
- }
52
-
53
- async selectFirst(sql, sqlParams) {
54
- const resp = await this.query(sql, sqlParams);
55
- return resp.records[0];
56
- }
57
-
58
- async selectPaginate(
59
- sql,
60
- sqlParams,
61
- perPage = 10,
62
- currentPage = 1,
63
- total = null
64
- ) {
65
- let paginator;
66
- if (typeof total === 'number') {
67
- paginator = new LengthAwarePaginator(this, sql, sqlParams, {
68
- perPage,
69
- currentPage,
70
- total,
71
- });
72
- } else {
73
- paginator = new Paginator(this, sql, sqlParams, {
74
- perPage,
75
- currentPage,
76
- });
77
- }
78
-
79
- return (await paginator).toObject();
80
- }
81
-
82
- async insert(sql, sqlParams) {
83
- const resp = await this.query(sql, sqlParams);
84
-
85
- if (resp.numberOfRecordsUpdated <= 0) {
86
- throw new LesgoException(
87
- 'No records inserted from INSERT query',
88
- 'AURORADBSERVICE_NO_RECORDS_INSERTED',
89
- 400,
90
- { resp, sql, sqlParams }
91
- );
92
- }
93
-
94
- return resp.insertId;
95
- }
96
-
97
- async update(sql, sqlParams) {
98
- const resp = await this.query(sql, sqlParams);
99
-
100
- if (resp.numberOfRecordsUpdated <= 0) {
101
- throw new LesgoException(
102
- 'No records updated from UPDATE query',
103
- 'AURORADBSERVICE_NO_RECORDS_UPDATED',
104
- 400,
105
- { resp, sql, sqlParams }
106
- );
107
- }
108
-
109
- return Promise.resolve();
110
- }
111
- }
@@ -1,177 +0,0 @@
1
- import { DocumentClient } from 'aws-sdk/clients/dynamodb'; // eslint-disable-line import/no-extraneous-dependencies
2
- import LesgoException from '../exceptions/LesgoException';
3
- import logger from '../utils/logger';
4
-
5
- const FILE = 'Lesgo/services/DynamoDbService';
6
-
7
- export default class DynamoDb {
8
- constructor(opts = {}) {
9
- this.client = null;
10
- this.connect(opts);
11
- }
12
-
13
- connect(opts) {
14
- const { region } = opts;
15
-
16
- if (!region)
17
- throw new LesgoException(
18
- 'Missing required parameter region',
19
- 'DYNAMODB_MISSING_PARAMETER',
20
- 500,
21
- { opts }
22
- );
23
-
24
- this.client = new DocumentClient({ region });
25
- }
26
-
27
- async query(
28
- tableName,
29
- keyConditionExpression,
30
- expressionAttributeValues,
31
- projectionExpression
32
- ) {
33
- const params = this.prepareQueryPayload(
34
- tableName,
35
- keyConditionExpression,
36
- expressionAttributeValues,
37
- projectionExpression
38
- );
39
-
40
- logger.debug(`${FILE}::PREPARING_QUERY`, { params });
41
-
42
- try {
43
- const data = await this.client.query(params).promise();
44
- logger.debug(`${FILE}::RECEIVED_QUERY_RESPONSE`, { data });
45
- return data.Items;
46
- } catch (err) {
47
- throw new LesgoException(
48
- 'EXCEPTION ENCOUNTERED FOR DYNAMODB QUERY OPERATION',
49
- 'DYNAMODB_QUERY_EXCEPTION',
50
- 500,
51
- { err, params }
52
- );
53
- }
54
- }
55
-
56
- async queryCount(
57
- tableName,
58
- keyConditionExpression,
59
- expressionAttributeValues
60
- ) {
61
- const params = this.prepareQueryCountPayload(
62
- tableName,
63
- keyConditionExpression,
64
- expressionAttributeValues
65
- );
66
-
67
- logger.debug(`${FILE}::PREPARING_QUERY_COUNT`, { params });
68
-
69
- try {
70
- const data = await this.client.query(params).promise();
71
- logger.debug(`${FILE}::RECEIVED_QUERY_COUNT_RESPONSE`, { data });
72
- return data.Count;
73
- } catch (err) {
74
- throw new LesgoException(
75
- 'EXCEPTION ENCOUNTERED FOR DYNAMODB QUERY COUNT OPERATION',
76
- 'DYNAMODB_QUERY_COUNT_EXCEPTION',
77
- 500,
78
- { err, params }
79
- );
80
- }
81
- }
82
-
83
- async put(tableName, item) {
84
- const params = this.preparePutPayload(tableName, item);
85
-
86
- logger.debug(`${FILE}::PREPARING_PUT`, { params });
87
-
88
- try {
89
- const data = await this.client.put(params).promise();
90
- logger.debug(`${FILE}::RECEIVED_PUT_RESPONSE`, { data });
91
- return data;
92
- } catch (err) {
93
- throw new LesgoException(
94
- 'EXCEPTION ENCOUNTERED FOR DYNAMODB PUT OPERATION',
95
- 'DYNAMODB_PUT_EXCEPTION',
96
- 500,
97
- { err, params }
98
- );
99
- }
100
- }
101
-
102
- async update(tableName, key, updateExpression, expressionAttributeValues) {
103
- const params = this.prepareUpdatePayload(
104
- tableName,
105
- key,
106
- updateExpression,
107
- expressionAttributeValues
108
- );
109
-
110
- logger.debug(`${FILE}::PREPARING_UPDATE`, { params });
111
-
112
- try {
113
- const data = await this.client.update(params).promise();
114
- logger.debug(`${FILE}::RECEIVED_UPDATE_RESPONSE`, { data });
115
- return data;
116
- } catch (err) {
117
- throw new LesgoException(
118
- 'EXCEPTION ENCOUNTERED FOR DYNAMODB UPDATE OPERATION',
119
- 'DYNAMODB_UPDATE_EXCEPTION',
120
- 500,
121
- { err, params }
122
- );
123
- }
124
- }
125
-
126
- // eslint-disable-next-line class-methods-use-this
127
- prepareQueryPayload(
128
- tableName,
129
- keyConditionExpression,
130
- expressionAttributeValues,
131
- projectionExpression
132
- ) {
133
- return {
134
- TableName: tableName,
135
- KeyConditionExpression: keyConditionExpression,
136
- ProjectionExpression: projectionExpression,
137
- ExpressionAttributeValues: expressionAttributeValues,
138
- };
139
- }
140
-
141
- // eslint-disable-next-line class-methods-use-this
142
- prepareQueryCountPayload(
143
- tableName,
144
- keyConditionExpression,
145
- expressionAttributeValues
146
- ) {
147
- return {
148
- TableName: tableName,
149
- KeyConditionExpression: keyConditionExpression,
150
- ExpressionAttributeValues: expressionAttributeValues,
151
- Select: 'COUNT',
152
- };
153
- }
154
-
155
- // eslint-disable-next-line class-methods-use-this
156
- preparePutPayload(tableName, item) {
157
- return {
158
- TableName: tableName,
159
- Item: item,
160
- };
161
- }
162
-
163
- // eslint-disable-next-line class-methods-use-this
164
- prepareUpdatePayload(
165
- tableName,
166
- key,
167
- updateExpression,
168
- expressionAttributeValues
169
- ) {
170
- return {
171
- TableName: tableName,
172
- Key: key,
173
- UpdateExpression: updateExpression,
174
- ExpressionAttributeValues: expressionAttributeValues,
175
- };
176
- }
177
- }
@@ -1,17 +0,0 @@
1
- import MemcachePlus from 'memcache-plus';
2
-
3
- export default class ElastiCacheService {
4
- constructor(options) {
5
- // @TODO:
6
- // - determine the driver used 'memcached' or 'redis'
7
- // - add switch-case that will set the driver
8
-
9
- this.setDriver(new MemcachePlus(options));
10
- }
11
-
12
- setDriver(driver) {
13
- this.driver = driver;
14
-
15
- return this;
16
- }
17
- }
@@ -1,181 +0,0 @@
1
- import {
2
- Client as ElasticsearchClient,
3
- Connection as DefaultConnection,
4
- } from '@elastic/elasticsearch';
5
- import AwsConnection from './aws/AwsElasticsearchConnection';
6
-
7
- class ElasticsearchService {
8
- constructor({ index, type, connection, options }) {
9
- this.index = index;
10
- this.type = type;
11
- this.options = options;
12
-
13
- this.setConnection(connection);
14
- }
15
-
16
- setConnection(conn) {
17
- let Connection = null;
18
-
19
- switch (conn) {
20
- case 'aws':
21
- Connection = AwsConnection;
22
- break;
23
-
24
- default:
25
- Connection = DefaultConnection;
26
- break;
27
- }
28
-
29
- this.client = new ElasticsearchClient({
30
- ...this.options,
31
- Connection,
32
- });
33
-
34
- return this;
35
- }
36
-
37
- getClient() {
38
- return this.client;
39
- }
40
-
41
- async search(body) {
42
- const param = {
43
- index: this.index,
44
- type: this.type,
45
- body,
46
- };
47
-
48
- const response = await this.client.search(param);
49
-
50
- this.result = response;
51
-
52
- return response;
53
- }
54
-
55
- /**
56
- * @param {*} settings
57
- * @param {*} index
58
- *
59
- * const settings = {
60
- * index: {
61
- * number_of_shards: 3,
62
- * number_of_replicas: 2,
63
- * },
64
- * };
65
- */
66
- createIndices(settings, index = null) {
67
- const params = {
68
- index: index || this.index,
69
- body: settings,
70
- };
71
-
72
- return this.client.indices.create(params);
73
- }
74
-
75
- deleteIndices(index, options = {}) {
76
- const params = {
77
- index,
78
- ...options,
79
- };
80
-
81
- return this.client.indices.delete(params);
82
- }
83
-
84
- async existIndices(index, options = {}) {
85
- const params = { index, ...options };
86
-
87
- const response = await this.client.indices.exists(params);
88
- return response.body;
89
- }
90
-
91
- putMapping(index, type, body) {
92
- const params = { index, type, body: { properties: body } };
93
-
94
- return this.client.indices.putMapping(params);
95
- }
96
-
97
- get(id) {
98
- const params = {
99
- index: this.index,
100
- type: this.type,
101
- id,
102
- };
103
-
104
- return this.client.get(params);
105
- }
106
-
107
- /**
108
- * Multi search API
109
- *
110
- * Executes several searches with a single API request.
111
- *
112
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/7.16/search-multi-search.html
113
- */
114
- msearch(body) {
115
- return this.client.msearch({ body });
116
- }
117
-
118
- indexOrCreateById(body, refresh = false) {
119
- const params = {
120
- index: this.index,
121
- type: this.type,
122
- id: body.id,
123
- body,
124
- refresh,
125
- };
126
-
127
- return this.client.index(params);
128
- }
129
-
130
- bulkIndex(bodies) {
131
- return this.client.bulk({ body: this.constructBulkIndex(bodies) });
132
- }
133
-
134
- create(id, body) {
135
- const params = {
136
- index: this.index,
137
- type: this.type,
138
- id,
139
- body,
140
- };
141
-
142
- return this.client.index(params);
143
- }
144
-
145
- updateById(id) {
146
- const params = {
147
- index: this.index,
148
- type: this.type,
149
- id,
150
- };
151
-
152
- return this.client.get(params);
153
- }
154
-
155
- /**
156
- * Bulk operation very confusing if read from documentation
157
- * use this example from blogs instead
158
- *
159
- * @ref https://taohiko.wordpress.com/2014/10/15/example-javascript-to-use-bulk-command-of-elasticsearch/
160
- */
161
- constructBulkIndex(bodies) {
162
- const bulk = [];
163
-
164
- bodies.forEach(body => {
165
- // array 0 - add index operation
166
- bulk.push({
167
- index: {
168
- _index: this.index,
169
- _type: this.type,
170
- _id: body.profile_id,
171
- },
172
- });
173
- // array 1 - profile attributes
174
- bulk.push(body);
175
- });
176
-
177
- return bulk;
178
- }
179
- }
180
-
181
- export default ElasticsearchService;