lesgo 2.1.5 → 2.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,8 @@
1
- import { Connection, ConnectionOptions } from 'mysql2/promise';
1
+ import { Pool, ConnectionOptions } from 'mysql2/promise';
2
2
  import { RDSAuroraMySQLProxyClientOptions } from '../../types/aws';
3
3
  export interface Singleton {
4
- [key: string]: Connection;
4
+ [key: string]: Pool;
5
5
  }
6
6
  export declare const singleton: Singleton;
7
- declare const getMySQLProxyClient: (connOptions?: ConnectionOptions, clientOpts?: RDSAuroraMySQLProxyClientOptions) => Promise<Connection>;
7
+ declare const getMySQLProxyClient: (connOptions?: ConnectionOptions, clientOpts?: RDSAuroraMySQLProxyClientOptions) => Promise<Pool>;
8
8
  export default getMySQLProxyClient;
@@ -31,7 +31,7 @@ var __awaiter =
31
31
  step((generator = generator.apply(thisArg, _arguments || [])).next());
32
32
  });
33
33
  };
34
- import { createConnection } from 'mysql2/promise';
34
+ import { createPool } from 'mysql2/promise';
35
35
  import { logger, isEmpty, validateFields } from '../../utils';
36
36
  import { rds as rdsConfig } from '../../config';
37
37
  import { getSecretValue } from '../../utils/secretsmanager';
@@ -53,10 +53,7 @@ const getMySQLProxyClient = (connOptions, clientOpts) =>
53
53
  const databaseName =
54
54
  options.databaseName || rdsConfig.aurora.mysql.databaseName;
55
55
  if (!isEmpty(singleton[singletonConn])) {
56
- logger.debug(`${FILE}::REUSE_RDS_CONNECTION`, {
57
- client: singleton[singletonConn],
58
- region,
59
- });
56
+ logger.debug(`${FILE}::REUSE_RDS_CONNECTION`);
60
57
  return singleton[singletonConn];
61
58
  }
62
59
  const dbCredentials = yield getSecretValue(
@@ -80,17 +77,18 @@ const getMySQLProxyClient = (connOptions, clientOpts) =>
80
77
  connOptions
81
78
  );
82
79
  logger.debug(`${FILE}::CONN_OPTS`, { connOpts });
83
- const conn = yield createConnection(
80
+ const dbPool = createPool(
84
81
  Object.assign(
85
82
  {
86
83
  user: validatedDbCredentials.username,
87
84
  password: validatedDbCredentials.password,
85
+ connectionLimit: 20,
88
86
  },
89
87
  connOpts
90
88
  )
91
89
  );
92
- singleton[singletonConn] = conn;
90
+ singleton[singletonConn] = dbPool;
93
91
  logger.debug(`${FILE}::NEW_RDS_CONNECTION`);
94
- return conn;
92
+ return dbPool;
95
93
  });
96
94
  export default getMySQLProxyClient;
@@ -41,9 +41,9 @@ const query = (sql, preparedValues, connOptions, clientOpts) =>
41
41
  { key: 'sql', type: 'string', required: true },
42
42
  { key: 'preparedValues', type: 'array', required: false },
43
43
  ]);
44
- const connection = yield getClient(connOptions, clientOpts);
44
+ const pool = yield getClient(connOptions, clientOpts);
45
45
  try {
46
- const resp = yield connection.execute(input.sql, input.preparedValues);
46
+ const resp = yield pool.execute(input.sql, input.preparedValues);
47
47
  logger.debug(`${FILE}::RECEIVED_RESPONSE`, {
48
48
  result: resp[0],
49
49
  sql,
@@ -1,4 +1,4 @@
1
1
  import { ConnectionOptions } from 'mysql2/promise';
2
2
  import { RDSAuroraMySQLProxyClientOptions } from '../../../../types/aws';
3
- declare const getClient: (connOptions?: ConnectionOptions, clientOpts?: RDSAuroraMySQLProxyClientOptions) => Promise<import("mysql2/promise").Connection>;
3
+ declare const getClient: (connOptions?: ConnectionOptions, clientOpts?: RDSAuroraMySQLProxyClientOptions) => Promise<import("mysql2/promise").Pool>;
4
4
  export default getClient;
@@ -1,4 +1,7 @@
1
1
  import { GetSecretValueOptions } from '../../services/SecretsManagerService/getSecretValue';
2
2
  import { ClientOptions } from '../../types/aws';
3
+ export interface Secrets {
4
+ [key: string]: string | object;
5
+ }
3
6
  declare const getSecretValue: (secretId: string, opts?: GetSecretValueOptions, clientOpts?: ClientOptions) => Promise<any>;
4
7
  export default getSecretValue;
@@ -31,12 +31,18 @@ var __awaiter =
31
31
  step((generator = generator.apply(thisArg, _arguments || [])).next());
32
32
  });
33
33
  };
34
+ import { logger } from '../../utils';
34
35
  import { LesgoException } from '../../exceptions';
35
36
  import getSecretValueService from '../../services/SecretsManagerService/getSecretValue';
36
37
  import isEmpty from '../isEmpty';
38
+ const secret = {};
37
39
  const FILE = 'lesgo.utils.secretsmanager.getSecretValue';
38
40
  const getSecretValue = (secretId, opts, clientOpts) =>
39
41
  __awaiter(void 0, void 0, void 0, function* () {
42
+ if (secret[secretId]) {
43
+ logger.debug(`${FILE}::CACHED_SECRET_VALUE`, { secretId });
44
+ return secret[secretId];
45
+ }
40
46
  let secretString;
41
47
  try {
42
48
  const { SecretString } = yield getSecretValueService(
@@ -60,8 +66,13 @@ const getSecretValue = (secretId, opts, clientOpts) =>
60
66
  );
61
67
  }
62
68
  try {
63
- return JSON.parse(secretString);
69
+ const secretObj = JSON.parse(secretString);
70
+ secret[secretId] = secretObj;
71
+ logger.debug(`${FILE}::SECRET_VALUE`, { secretId });
72
+ return secretObj;
64
73
  } catch (error) {
74
+ secret[secretId] = secretString || '';
75
+ logger.debug(`${FILE}::SECRET_VALUE`, { secretId });
65
76
  return secretString;
66
77
  }
67
78
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lesgo",
3
- "version": "2.1.5",
3
+ "version": "2.1.6",
4
4
  "description": "Core framework for lesgo node.js serverless framework.",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",