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,108 +0,0 @@
1
- import * as firebaseAdmin from 'firebase-admin';
2
- import logger from '../utils/logger';
3
- import isEmpty from '../utils/isEmpty';
4
- import LesgoException from '../exceptions/LesgoException';
5
-
6
- const FILE = 'Lesgo/services/FirebaseAdminService';
7
-
8
- export default class FirebaseAdmin {
9
- constructor(opts = {}) {
10
- this.app = null;
11
- this.connect(opts);
12
- }
13
-
14
- connect(opts) {
15
- const { serviceAccount, projectName } = opts;
16
-
17
- if (!serviceAccount || !projectName)
18
- throw new LesgoException(
19
- 'Missing required parameters serviceAccount and or projectName',
20
- 'FIREBASEADMIN_MISSING_PARAMETERS',
21
- 500,
22
- { opts }
23
- );
24
-
25
- this.app = firebaseAdmin.initializeApp({
26
- credential: firebaseAdmin.credential.cert(serviceAccount),
27
- databaseURL: `https://${projectName}.firebaseio.com`,
28
- });
29
- }
30
-
31
- async getAllUsers(maxResults, nextPageToken) {
32
- const max = !isEmpty(maxResults) ? maxResults : 25;
33
-
34
- try {
35
- logger.debug(`${FILE}::FETCHING_USERS`, {
36
- max,
37
- maxResults,
38
- nextPageToken,
39
- });
40
- const users = await this.app.auth().listUsers(max, nextPageToken);
41
- logger.debug(`${FILE}::USERS_FETCHED`, { users });
42
- return users.users;
43
- } catch (err) {
44
- throw new LesgoException(
45
- 'Failed to fetch all users from firebase',
46
- 'FIREBASE_FETCH_USERS',
47
- 500,
48
- { err, max, maxResults, nextPageToken }
49
- );
50
- }
51
- }
52
-
53
- async createUser(data) {
54
- try {
55
- const { uid, email, password, username } = data;
56
- const userData = {
57
- uid,
58
- email,
59
- password,
60
- displayName: username,
61
- };
62
-
63
- logger.debug(`${FILE}::CREATING_USER`, { userData, data });
64
- const user = await this.app.auth().createUser(userData);
65
- logger.debug(`${FILE}::USER_CREATED`, { user });
66
- return user;
67
- } catch (err) {
68
- throw new LesgoException(
69
- 'Failed to create user on firebase',
70
- 'FIREBASE_CREATE_USER',
71
- 400,
72
- { err, data }
73
- );
74
- }
75
- }
76
-
77
- async deleteUser(uid) {
78
- try {
79
- logger.debug(`${FILE}::DELETING_USER`);
80
- const deleted = await this.app.auth().deleteUser(uid);
81
- logger.debug(`${FILE}::USER_DELETED`, { deleted, uid });
82
- return deleted;
83
- } catch (err) {
84
- throw new LesgoException(
85
- 'Failed to delete user from firebase',
86
- 'FIREBASE_DELETE_USER',
87
- 400,
88
- { err, uid }
89
- );
90
- }
91
- }
92
-
93
- async delete() {
94
- try {
95
- logger.debug(`${FILE}::DELETING_APP`);
96
- const resp = await this.app.delete();
97
- logger.debug(`${FILE}::APP_DELETED`, { resp });
98
- return resp;
99
- } catch (err) {
100
- throw new LesgoException(
101
- 'Failed to delete firebase app',
102
- 'FIREBASE_DELETE_APP',
103
- 500,
104
- { err }
105
- );
106
- }
107
- }
108
- }
@@ -1,52 +0,0 @@
1
- import jwtpkg from 'jsonwebtoken';
2
- import LesgoException from '../exceptions/LesgoException';
3
-
4
- export default class JwtService {
5
- constructor(token, config) {
6
- this.jwtpkg = jwtpkg;
7
- this.decoded = this.jwtpkg.verify(token, config.secret);
8
- this.settings = {
9
- validate: {
10
- iss: config.iss.validate,
11
- customClaims: config.customClaims.validate,
12
- },
13
- config: {
14
- iss: config.iss.data,
15
- customClaims: config.customClaims.data,
16
- },
17
- };
18
- }
19
-
20
- validate() {
21
- if (
22
- this.settings.validate.iss &&
23
- this.settings.config.iss.indexOf(this.decoded.iss) === -1
24
- ) {
25
- throw new LesgoException(
26
- `Token's [iss] is not valid!`,
27
- 'JWT_ISS_NOT_VALID',
28
- 403
29
- );
30
- }
31
-
32
- /**
33
- * Your conditions here, if you would like to validate
34
- * custom claims: https://auth0.com/docs/tokens/jwt-claims
35
- */
36
- this.settings.config.customClaims.forEach(customClaim => {
37
- if (this.settings.validate.customClaims && !this.decoded[customClaim]) {
38
- throw new LesgoException(
39
- `Token's custom claim [${customClaim}] not found!`,
40
- 'JWT_CUSTOM_CLAIM_NOT_FOUND',
41
- 403
42
- );
43
- }
44
- });
45
-
46
- return this;
47
- }
48
-
49
- jwt() {
50
- return this.jwtpkg;
51
- }
52
- }
@@ -1,59 +0,0 @@
1
- // eslint-disable-next-line import/no-extraneous-dependencies
2
- import { S3 } from 'aws-sdk';
3
-
4
- import LesgoException from '../exceptions/LesgoException';
5
-
6
- export default class S3Service {
7
- constructor(
8
- opts = {
9
- accessKeyId: null,
10
- secretAccessKey: null,
11
- region: null,
12
- }
13
- ) {
14
- let options = {};
15
-
16
- if (opts.accessKeyId !== null && opts.accessKeyId !== undefined) {
17
- options = { ...options, accessKeyId: opts.accessKeyId };
18
- }
19
- if (opts.secretAccessKey !== null && opts.secretAccessKey !== undefined) {
20
- options = { ...options, secretAccessKey: opts.secretAccessKey };
21
- }
22
- if (opts.region !== null && opts.region !== undefined) {
23
- options = { ...options, region: opts.region };
24
- }
25
-
26
- this.s3Instance = new S3({
27
- ...{ ...options },
28
- });
29
- }
30
-
31
- /**
32
- * Get S3 bucket object
33
- *
34
- * @param {object} payload
35
- * @param {string} queueName
36
- */
37
- getObject(key, bucket) {
38
- if (key === undefined || key === null) {
39
- throw new LesgoException(
40
- 'Key is undefined in S3Service.getObject()',
41
- 'S3SERVICE_GETOBJECT_KEY_UNDEFINED'
42
- );
43
- }
44
-
45
- if (bucket === undefined || bucket === null) {
46
- throw new LesgoException(
47
- 'Bucket is undefined in S3Service.getObject()',
48
- 'S3SERVICE_GETOBJECT_BUCKET_UNDEFINED'
49
- );
50
- }
51
-
52
- return this.s3Instance
53
- .getObject({
54
- Bucket: bucket,
55
- Key: key,
56
- })
57
- .promise();
58
- }
59
- }
@@ -1,65 +0,0 @@
1
- // eslint-disable-next-line import/no-extraneous-dependencies
2
- import { SQS } from 'aws-sdk';
3
- import LesgoException from '../exceptions/LesgoException';
4
-
5
- export default class SQSService {
6
- constructor(
7
- opts = {
8
- accessKeyId: null,
9
- secretAccessKey: null,
10
- region: null,
11
- },
12
- queues = {}
13
- ) {
14
- let options = {};
15
-
16
- if (opts.accessKeyId !== null && opts.accessKeyId !== undefined) {
17
- options = { ...options, accessKeyId: opts.accessKeyId };
18
- }
19
-
20
- if (opts.secretAccessKey !== null && opts.secretAccessKey !== undefined) {
21
- options = { ...options, secretAccessKey: opts.secretAccessKey };
22
- }
23
-
24
- if (opts.region !== null && opts.region !== undefined) {
25
- options = { ...options, region: opts.region };
26
- }
27
-
28
- this.sqsClient = new SQS({
29
- ...{ ...options },
30
- });
31
-
32
- this.queues = queues;
33
- }
34
-
35
- /**
36
- * Sends a payload to the queue
37
- *
38
- * @param {object} payload
39
- * @param {string} queueName
40
- */
41
- dispatch(payload, queueName) {
42
- if (payload === undefined) {
43
- throw new LesgoException(
44
- 'payload is undefined in dispatch()',
45
- 'SQSSERVICE_DISPATCH_PAYLOAD_UNDEFINED'
46
- );
47
- }
48
-
49
- if (queueName === undefined) {
50
- throw new LesgoException(
51
- 'queueName is undefined in dispatch()',
52
- 'SQSSERVICE_DISPATCH_QUEUENAME_UNDEFINED'
53
- );
54
- }
55
-
56
- const queue = this.queues[queueName];
57
-
58
- return this.sqsClient
59
- .sendMessage({
60
- MessageBody: JSON.stringify(payload),
61
- QueueUrl: `${queue.url}`,
62
- })
63
- .promise();
64
- }
65
- }
@@ -1,278 +0,0 @@
1
- import mysql from 'mysql2/promise';
2
- import AuroraDbRDSProxyService from '../AuroraDbRDSProxyService';
3
- import LesgoException from '../../exceptions/LesgoException';
4
-
5
- const auroraConfig = {
6
- host: 'some-fake-host',
7
- user: 'fakeUsername',
8
- password: 'fakePassword',
9
- database: 'fakeDbName',
10
- };
11
-
12
- const customConfig = {
13
- host: 'some-fake-host-2',
14
- user: 'fakeUsername2',
15
- password: 'fakePassword2',
16
- database: 'fakeDbName2',
17
- };
18
-
19
- describe('test AuroraDbRDSProxyService instantiate', () => {
20
- it('should not throw exception when instantiating', () => {
21
- const db = new AuroraDbRDSProxyService(auroraConfig);
22
- expect(db.clientOpts).toMatchObject(auroraConfig);
23
- });
24
-
25
- it('should allow for empty config', () => {
26
- const db = new AuroraDbRDSProxyService();
27
- expect(db.clientOpts).toMatchObject({});
28
- });
29
- });
30
-
31
- describe('test AuroraDbRDSProxyService connect', () => {
32
- it('should be able to connect without custom config', async () => {
33
- const db = new AuroraDbRDSProxyService(auroraConfig);
34
- const conn = await db.connect();
35
-
36
- expect(conn.mocked).toMatchObject(auroraConfig);
37
- });
38
-
39
- it('should be able to connect with custom config', async () => {
40
- const db = new AuroraDbRDSProxyService(auroraConfig);
41
- const conn = await db.connect(customConfig);
42
-
43
- expect(conn.mocked).toMatchObject(customConfig);
44
- });
45
- });
46
-
47
- describe('test AuroraDbRDSProxyService query', () => {
48
- it('should return results object when calling query function', async () => {
49
- const db = new AuroraDbRDSProxyService(auroraConfig);
50
- const resp = await db.query('SELECT_QUERY', {});
51
-
52
- expect(resp).toMatchObject({
53
- results: [
54
- {
55
- id: 1,
56
- uid: 'some-uid-1',
57
- },
58
- {
59
- id: 2,
60
- uid: 'some-uid-2',
61
- },
62
- ],
63
- });
64
-
65
- expect(mysql.createConnection).toHaveBeenCalled();
66
- });
67
-
68
- it('should return results object when calling querying with connection options passed', async () => {
69
- const db = new AuroraDbRDSProxyService(auroraConfig);
70
- const resp = await db.query('SELECT_QUERY', {}, auroraConfig);
71
-
72
- expect(resp).toMatchObject({
73
- results: [
74
- {
75
- id: 1,
76
- uid: 'some-uid-1',
77
- },
78
- {
79
- id: 2,
80
- uid: 'some-uid-2',
81
- },
82
- ],
83
- });
84
-
85
- expect(mysql.createConnection).toHaveBeenCalled();
86
- });
87
-
88
- it('should return results object when calling querying with no connection options passed and persistent conn', async () => {
89
- const db = new AuroraDbRDSProxyService(auroraConfig);
90
- await db.pConnect();
91
- const resp = await db.query('SELECT_QUERY', {});
92
-
93
- expect(resp).toMatchObject({
94
- results: [
95
- {
96
- id: 1,
97
- uid: 'some-uid-1',
98
- },
99
- {
100
- id: 2,
101
- uid: 'some-uid-2',
102
- },
103
- ],
104
- });
105
-
106
- expect(mysql.createConnection).toHaveBeenCalled();
107
- });
108
- });
109
-
110
- describe('test AuroraDbRDSProxyService select', () => {
111
- it('should return array results when calling select function', async () => {
112
- const db = new AuroraDbRDSProxyService(auroraConfig);
113
- return expect(db.select('SELECT_QUERY', {})).resolves.toMatchObject([
114
- {
115
- id: 1,
116
- uid: 'some-uid-1',
117
- },
118
- {
119
- id: 2,
120
- uid: 'some-uid-2',
121
- },
122
- ]);
123
- });
124
-
125
- it('should throw an exception when writing with invalid query', async () => {
126
- const error = new LesgoException(
127
- 'Exception caught executing SQL Statement',
128
- 'AURORADBSERVICE_QUERY_EXCEPTION',
129
- 500,
130
- {
131
- err: {
132
- code: 'BadRequestException',
133
- },
134
- }
135
- );
136
-
137
- const db = new AuroraDbRDSProxyService(auroraConfig);
138
- return expect(db.select('INVALID_QUERY', {})).rejects.toMatchObject(error);
139
- });
140
-
141
- it('should throw an exception when calling select with invalid query parameters', async () => {
142
- const error = new LesgoException(
143
- 'Exception caught executing SQL Statement',
144
- 'AURORADBSERVICE_QUERY_EXCEPTION',
145
- 500,
146
- {
147
- err: {
148
- code: 'BadRequestException',
149
- },
150
- }
151
- );
152
-
153
- const db = new AuroraDbRDSProxyService(auroraConfig);
154
- return expect(
155
- db.select('RANDOM_QUERY', 'INVALID_QUERY_PARAMETERS')
156
- ).rejects.toMatchObject(error);
157
- });
158
- });
159
-
160
- describe('test AuroraDbRDSProxyService selectPaginate', () => {
161
- it('should return paginated results when calling selectPaginate function', async () => {
162
- const db = new AuroraDbRDSProxyService(auroraConfig);
163
- return expect(db.selectPaginate('SELECT_QUERY', {})).resolves.toMatchObject(
164
- {
165
- count: 2,
166
- previous_page: false,
167
- current_page: 1,
168
- next_page: false,
169
- per_page: 10,
170
- items: [
171
- {
172
- id: 1,
173
- uid: 'some-uid-1',
174
- },
175
- {
176
- id: 2,
177
- uid: 'some-uid-2',
178
- },
179
- ],
180
- }
181
- );
182
- });
183
-
184
- it('should return paginated results when calling selectPaginate with defined total', async () => {
185
- const db = new AuroraDbRDSProxyService(auroraConfig);
186
- return expect(
187
- db.selectPaginate('SELECT_QUERY', {}, 1, 2, 1)
188
- ).resolves.toMatchObject({
189
- count: 1,
190
- previous_page: 1,
191
- current_page: 2,
192
- next_page: 3,
193
- per_page: 1,
194
- items: [
195
- {
196
- id: 1,
197
- uid: 'some-uid-1',
198
- },
199
- ],
200
- });
201
- });
202
- });
203
-
204
- describe('test AuroraDbRDSProxyService selectFirst', () => {
205
- it('should only return the first record when calling selectFirst', async () => {
206
- const db = new AuroraDbRDSProxyService(auroraConfig);
207
- return expect(db.selectFirst('SELECT_QUERY', {})).resolves.toMatchObject({
208
- id: 1,
209
- uid: 'some-uid-1',
210
- });
211
- });
212
- });
213
-
214
- describe('test AuroraDbRDSProxyService insert', () => {
215
- it('should return recordId when inserting record', async () => {
216
- const db = new AuroraDbRDSProxyService(auroraConfig);
217
- return expect(db.insert('INSERT_QUERY', {})).resolves.toEqual(20);
218
- });
219
-
220
- it('should throw exception when calling insert with invalid query', async () => {
221
- const error = new LesgoException(
222
- 'No records inserted from INSERT query',
223
- 'AURORADBSERVICE_NO_RECORDS_INSERTED',
224
- 400
225
- );
226
-
227
- const db = new AuroraDbRDSProxyService(auroraConfig);
228
- return expect(db.insert('INVALID_INSERT_QUERY', {})).rejects.toMatchObject(
229
- error
230
- );
231
- });
232
- });
233
-
234
- describe('test AuroraDbRDSProxyService update', () => {
235
- it('should return success when making update query', async () => {
236
- const db = new AuroraDbRDSProxyService(auroraConfig);
237
- return expect(db.update('UPDATE_QUERY', {})).resolves.not.toThrow();
238
- });
239
-
240
- it('should throw not exception when caliing update with invalid query', async () => {
241
- const db = new AuroraDbRDSProxyService(auroraConfig);
242
- return expect(db.update('INVALID_UPDATE_QUERY', {})).resolves.not.toThrow();
243
- });
244
- });
245
-
246
- describe('test AuroraDbRDSProxyService pConnect', () => {
247
- it('should be able to connect without custom config', async () => {
248
- const db = new AuroraDbRDSProxyService(auroraConfig);
249
- await db.pConnect();
250
-
251
- expect(db.conn.mocked).toMatchObject(auroraConfig);
252
- });
253
-
254
- it('should be able to connect with custom config', async () => {
255
- const db = new AuroraDbRDSProxyService(auroraConfig);
256
- await db.pConnect(customConfig);
257
-
258
- expect(db.conn.mocked).toMatchObject(customConfig);
259
- });
260
- });
261
-
262
- describe('test AuroraDbRDSProxyService end', () => {
263
- it('should end the connection when passed', async () => {
264
- const db = new AuroraDbRDSProxyService(auroraConfig);
265
- const conn = await db.connect();
266
- await db.end(conn);
267
-
268
- expect(conn.end).toHaveBeenCalledTimes(1);
269
- });
270
-
271
- it('should end the persisted connection when none is passed', async () => {
272
- const db = new AuroraDbRDSProxyService(auroraConfig);
273
- await db.pConnect();
274
- await db.end();
275
-
276
- expect(db.conn.end).toHaveBeenCalledTimes(1);
277
- });
278
- });