lesgo 2.1.4 → 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.
- package/dist/config/sqs.d.ts +1 -5
- package/dist/config/sqs.js +4 -13
- package/dist/services/RDSAuroraMySQLProxyService/getMySQLProxyClient.d.ts +3 -3
- package/dist/services/RDSAuroraMySQLProxyService/getMySQLProxyClient.js +6 -8
- package/dist/services/RDSAuroraMySQLProxyService/query.d.ts +3 -2
- package/dist/services/RDSAuroraMySQLProxyService/query.js +2 -2
- package/dist/services/SQSService/changeMessageVisibility.d.ts +10 -0
- package/dist/services/SQSService/changeMessageVisibility.js +80 -0
- package/dist/services/SQSService/getQueueCount.d.ts +8 -0
- package/dist/services/SQSService/getQueueCount.js +76 -0
- package/dist/services/SQSService/getQueueUrl.js +3 -1
- package/dist/services/SQSService/index.d.ts +1 -0
- package/dist/services/SQSService/index.js +1 -0
- package/dist/utils/crypto/validateEncryptionFields.d.ts +1 -1
- package/dist/utils/db/mysql/proxy/getClient.d.ts +1 -1
- package/dist/utils/db/mysql/proxy/query.d.ts +1 -1
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +1 -0
- package/dist/utils/safePromise.d.ts +20 -0
- package/dist/utils/safePromise.js +61 -0
- package/dist/utils/secretsmanager/getSecretValue.d.ts +3 -0
- package/dist/utils/secretsmanager/getSecretValue.js +12 -1
- package/dist/utils/sqs/changeMessageVisibility.d.ts +5 -0
- package/dist/utils/sqs/changeMessageVisibility.js +51 -0
- package/dist/utils/sqs/convertQueueAliasToObject.d.ts +3 -0
- package/dist/utils/sqs/convertQueueAliasToObject.js +16 -0
- package/dist/utils/sqs/getQueueCount.d.ts +5 -0
- package/dist/utils/sqs/getQueueCount.js +39 -0
- package/dist/utils/sqs/index.d.ts +3 -0
- package/dist/utils/sqs/index.js +3 -0
- package/dist/utils/validateFields.d.ts +2 -6
- package/dist/utils/validateFields.js +11 -11
- package/package.json +1 -1
package/dist/config/sqs.d.ts
CHANGED
package/dist/config/sqs.js
CHANGED
|
@@ -1,18 +1,9 @@
|
|
|
1
1
|
var _a;
|
|
2
2
|
import awsConfig from './aws';
|
|
3
|
-
import appConfig from './app';
|
|
4
|
-
const sqsQueueAliases =
|
|
5
|
-
((_a = process.env.LESGO_AWS_SQS_QUEUE_ALIASES) === null || _a === void 0
|
|
6
|
-
? void 0
|
|
7
|
-
: _a.split(',')) || [];
|
|
8
|
-
const region = process.env.LESGO_AWS_SQS_REGION || awsConfig.region;
|
|
9
3
|
export default {
|
|
10
4
|
region: process.env.LESGO_AWS_SQS_REGION || awsConfig.region,
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
awsConfig.accountId
|
|
16
|
-
}/${`${appConfig.stackName}-${q}`}`,
|
|
17
|
-
})),
|
|
5
|
+
queueAliases:
|
|
6
|
+
((_a = process.env.LESGO_AWS_SQS_QUEUE_ALIASES) === null || _a === void 0
|
|
7
|
+
? void 0
|
|
8
|
+
: _a.split(',')) || [],
|
|
18
9
|
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Pool, ConnectionOptions } from 'mysql2/promise';
|
|
2
2
|
import { RDSAuroraMySQLProxyClientOptions } from '../../types/aws';
|
|
3
3
|
export interface Singleton {
|
|
4
|
-
[key: string]:
|
|
4
|
+
[key: string]: Pool;
|
|
5
5
|
}
|
|
6
6
|
export declare const singleton: Singleton;
|
|
7
|
-
declare const getMySQLProxyClient: (connOptions?: ConnectionOptions, clientOpts?: RDSAuroraMySQLProxyClientOptions) => Promise<
|
|
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 {
|
|
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
|
|
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] =
|
|
90
|
+
singleton[singletonConn] = dbPool;
|
|
93
91
|
logger.debug(`${FILE}::NEW_RDS_CONNECTION`);
|
|
94
|
-
return
|
|
92
|
+
return dbPool;
|
|
95
93
|
});
|
|
96
94
|
export default getMySQLProxyClient;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { ConnectionOptions } from 'mysql2/promise';
|
|
1
|
+
import { ConnectionOptions, FieldPacket, QueryResult } from 'mysql2/promise';
|
|
2
2
|
import { RDSAuroraMySQLProxyClientOptions } from '../../types/aws';
|
|
3
|
-
|
|
3
|
+
type QueryReturn<T> = [T, FieldPacket[]];
|
|
4
|
+
declare const query: <T = QueryResult>(sql: string, preparedValues?: any[], connOptions?: ConnectionOptions, clientOpts?: RDSAuroraMySQLProxyClientOptions) => Promise<QueryReturn<T>>;
|
|
4
5
|
export default query;
|
|
@@ -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
|
|
44
|
+
const pool = yield getClient(connOptions, clientOpts);
|
|
45
45
|
try {
|
|
46
|
-
const resp = yield
|
|
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,
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ChangeMessageVisibilityCommandInput } from '@aws-sdk/client-sqs';
|
|
2
|
+
import { ClientOptions } from '../../types/aws';
|
|
3
|
+
import { Queue } from './getQueueUrl';
|
|
4
|
+
export interface changeMessageVisibilityOptions extends Partial<Omit<ChangeMessageVisibilityCommandInput, 'QueueUrl' | 'ReceiptHandle' | 'VisibilityTimeout'>> {
|
|
5
|
+
QueueUrl?: string;
|
|
6
|
+
ReceiptHandle?: string;
|
|
7
|
+
VisibilityTimeout?: number;
|
|
8
|
+
}
|
|
9
|
+
declare const changeMessageVisibility: (queue: string | Queue, receiptHandle: string, visibilityTimeout: number, opts?: changeMessageVisibilityOptions, clientOpts?: ClientOptions) => Promise<void>;
|
|
10
|
+
export default changeMessageVisibility;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
var __awaiter =
|
|
2
|
+
(this && this.__awaiter) ||
|
|
3
|
+
function (thisArg, _arguments, P, generator) {
|
|
4
|
+
function adopt(value) {
|
|
5
|
+
return value instanceof P
|
|
6
|
+
? value
|
|
7
|
+
: new P(function (resolve) {
|
|
8
|
+
resolve(value);
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
12
|
+
function fulfilled(value) {
|
|
13
|
+
try {
|
|
14
|
+
step(generator.next(value));
|
|
15
|
+
} catch (e) {
|
|
16
|
+
reject(e);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function rejected(value) {
|
|
20
|
+
try {
|
|
21
|
+
step(generator['throw'](value));
|
|
22
|
+
} catch (e) {
|
|
23
|
+
reject(e);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function step(result) {
|
|
27
|
+
result.done
|
|
28
|
+
? resolve(result.value)
|
|
29
|
+
: adopt(result.value).then(fulfilled, rejected);
|
|
30
|
+
}
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
import { ChangeMessageVisibilityCommand } from '@aws-sdk/client-sqs';
|
|
35
|
+
import LesgoException from '../../exceptions/LesgoException';
|
|
36
|
+
import { logger, validateFields } from '../../utils';
|
|
37
|
+
import getClient from './getClient';
|
|
38
|
+
import getQueueUrl from './getQueueUrl';
|
|
39
|
+
const FILE = 'lesgo.services.SQSService.changeMessageVisibility';
|
|
40
|
+
const changeMessageVisibility = (
|
|
41
|
+
queue,
|
|
42
|
+
receiptHandle,
|
|
43
|
+
visibilityTimeout,
|
|
44
|
+
opts,
|
|
45
|
+
clientOpts
|
|
46
|
+
) =>
|
|
47
|
+
__awaiter(void 0, void 0, void 0, function* () {
|
|
48
|
+
const queueUrl = getQueueUrl(queue);
|
|
49
|
+
const input = validateFields({ receiptHandle, visibilityTimeout }, [
|
|
50
|
+
{ key: 'receiptHandle', type: 'string', required: true },
|
|
51
|
+
{ key: 'visibilityTimeout', type: 'number', required: true },
|
|
52
|
+
]);
|
|
53
|
+
const client = getClient(clientOpts);
|
|
54
|
+
const commandInput = Object.assign(
|
|
55
|
+
{
|
|
56
|
+
QueueUrl: queueUrl,
|
|
57
|
+
ReceiptHandle: input.receiptHandle,
|
|
58
|
+
VisibilityTimeout: input.visibilityTimeout,
|
|
59
|
+
},
|
|
60
|
+
opts
|
|
61
|
+
);
|
|
62
|
+
try {
|
|
63
|
+
yield client.send(new ChangeMessageVisibilityCommand(commandInput));
|
|
64
|
+
logger.debug(`${FILE}::MESSAGE_VISIBILITY_UPDATED`, {
|
|
65
|
+
commandInput,
|
|
66
|
+
});
|
|
67
|
+
} catch (error) {
|
|
68
|
+
throw new LesgoException(
|
|
69
|
+
'Error occurred updating message visibility timeout',
|
|
70
|
+
`${FILE}::MESSAGE_VISIBILITY_TIMEOUT_UPDATED_ERROR`,
|
|
71
|
+
500,
|
|
72
|
+
{
|
|
73
|
+
error,
|
|
74
|
+
commandInput,
|
|
75
|
+
opts,
|
|
76
|
+
}
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
export default changeMessageVisibility;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { GetQueueAttributesCommandInput } from '@aws-sdk/client-sqs';
|
|
2
|
+
import { ClientOptions } from '../../types/aws';
|
|
3
|
+
import { Queue } from './getQueueUrl';
|
|
4
|
+
export interface GetQueueCountOptions extends Partial<Omit<GetQueueAttributesCommandInput, 'QueueUrl'>> {
|
|
5
|
+
QueueUrl?: string;
|
|
6
|
+
}
|
|
7
|
+
declare const getQueueCount: (queue: string | Queue, opts?: GetQueueCountOptions, clientOpts?: ClientOptions) => Promise<import("@aws-sdk/client-sqs").GetQueueAttributesCommandOutput>;
|
|
8
|
+
export default getQueueCount;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
var __awaiter =
|
|
2
|
+
(this && this.__awaiter) ||
|
|
3
|
+
function (thisArg, _arguments, P, generator) {
|
|
4
|
+
function adopt(value) {
|
|
5
|
+
return value instanceof P
|
|
6
|
+
? value
|
|
7
|
+
: new P(function (resolve) {
|
|
8
|
+
resolve(value);
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
12
|
+
function fulfilled(value) {
|
|
13
|
+
try {
|
|
14
|
+
step(generator.next(value));
|
|
15
|
+
} catch (e) {
|
|
16
|
+
reject(e);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function rejected(value) {
|
|
20
|
+
try {
|
|
21
|
+
step(generator['throw'](value));
|
|
22
|
+
} catch (e) {
|
|
23
|
+
reject(e);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function step(result) {
|
|
27
|
+
result.done
|
|
28
|
+
? resolve(result.value)
|
|
29
|
+
: adopt(result.value).then(fulfilled, rejected);
|
|
30
|
+
}
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
import { GetQueueAttributesCommand } from '@aws-sdk/client-sqs';
|
|
35
|
+
import LesgoException from '../../exceptions/LesgoException';
|
|
36
|
+
import { logger } from '../../utils';
|
|
37
|
+
import getClient from './getClient';
|
|
38
|
+
import getQueueUrl from './getQueueUrl';
|
|
39
|
+
const FILE = 'lesgo.services.SQSService.getQueueCount';
|
|
40
|
+
const getQueueCount = (queue, opts, clientOpts) =>
|
|
41
|
+
__awaiter(void 0, void 0, void 0, function* () {
|
|
42
|
+
const queueUrl = getQueueUrl(queue);
|
|
43
|
+
const client = getClient(clientOpts);
|
|
44
|
+
const commandInput = Object.assign(
|
|
45
|
+
{
|
|
46
|
+
QueueUrl: queueUrl,
|
|
47
|
+
AttributeNames: [
|
|
48
|
+
'ApproximateNumberOfMessages',
|
|
49
|
+
'ApproximateNumberOfMessagesNotVisible',
|
|
50
|
+
],
|
|
51
|
+
},
|
|
52
|
+
opts
|
|
53
|
+
);
|
|
54
|
+
try {
|
|
55
|
+
const data = yield client.send(
|
|
56
|
+
new GetQueueAttributesCommand(commandInput)
|
|
57
|
+
);
|
|
58
|
+
logger.debug(`${FILE}::QUEUE_COUNT`, {
|
|
59
|
+
data,
|
|
60
|
+
commandInput,
|
|
61
|
+
});
|
|
62
|
+
return data;
|
|
63
|
+
} catch (error) {
|
|
64
|
+
throw new LesgoException(
|
|
65
|
+
'Error occurred getting count from queue',
|
|
66
|
+
`${FILE}::QUEUE_COUNT_ERROR`,
|
|
67
|
+
500,
|
|
68
|
+
{
|
|
69
|
+
error,
|
|
70
|
+
commandInput,
|
|
71
|
+
opts,
|
|
72
|
+
}
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
export default getQueueCount;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { LesgoException } from '../../exceptions';
|
|
2
2
|
import sqsConfig from '../../config/sqs';
|
|
3
|
+
import { convertQueueAliasToObject } from '../../utils/sqs';
|
|
3
4
|
const FILE = 'lesgo.services.SQSService.getQueueUrl';
|
|
4
5
|
export default queue => {
|
|
5
6
|
if (
|
|
@@ -10,7 +11,8 @@ export default queue => {
|
|
|
10
11
|
) {
|
|
11
12
|
return queue.url;
|
|
12
13
|
}
|
|
13
|
-
const
|
|
14
|
+
const queues = convertQueueAliasToObject(sqsConfig.queueAliases);
|
|
15
|
+
const configQueue = queues.find(q => q.alias === queue);
|
|
14
16
|
if (!configQueue) {
|
|
15
17
|
throw new LesgoException(
|
|
16
18
|
`Queue with alias ${queue} not found in config`,
|
|
@@ -11,7 +11,7 @@ interface ValidateEncryptionFieldsOptions {
|
|
|
11
11
|
export declare const validateEncryptionAlgorithm: (algorithm: EncryptionAlgorithm) => void;
|
|
12
12
|
export declare const validateSecretKey: (secretKey?: string, algorithm?: EncryptionAlgorithm) => void;
|
|
13
13
|
declare const validateEncryptionFields: (text: string, opts?: ValidateEncryptionFieldsOptions) => {
|
|
14
|
-
validText:
|
|
14
|
+
validText: string;
|
|
15
15
|
validAlgorithm: EncryptionAlgorithm;
|
|
16
16
|
validSecretKey: string;
|
|
17
17
|
validIvLength: number;
|
|
@@ -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").
|
|
3
|
+
declare const getClient: (connOptions?: ConnectionOptions, clientOpts?: RDSAuroraMySQLProxyClientOptions) => Promise<import("mysql2/promise").Pool>;
|
|
4
4
|
export default getClient;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { ConnectionOptions } from 'mysql2/promise';
|
|
2
2
|
import { RDSAuroraMySQLProxyClientOptions } from '../../../../types/aws';
|
|
3
|
-
declare const query: (sql: string, preparedValues?: any[], connOptions?: ConnectionOptions, clientOpts?: RDSAuroraMySQLProxyClientOptions) => Promise<
|
|
3
|
+
declare const query: <T>(sql: string, preparedValues?: any[], connOptions?: ConnectionOptions, clientOpts?: RDSAuroraMySQLProxyClientOptions) => Promise<T>;
|
|
4
4
|
export default query;
|
package/dist/utils/index.d.ts
CHANGED
package/dist/utils/index.js
CHANGED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @param promise
|
|
4
|
+
* @returns [err, res]
|
|
5
|
+
* @reference https://github.com/arthurfiorette/proposal-safe-assignment-operator
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { safePromise } from 'lesgo/utils';
|
|
10
|
+
*
|
|
11
|
+
* const [err, res] = await safePromise(fetch('https://example.com/'));
|
|
12
|
+
* if (err) {
|
|
13
|
+
* console.error(err);
|
|
14
|
+
* } else {
|
|
15
|
+
* console.log(res);
|
|
16
|
+
* }
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
declare const safePromise: <T>(promise: Promise<T>) => Promise<[unknown, T | null]>;
|
|
20
|
+
export default safePromise;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
var __awaiter =
|
|
2
|
+
(this && this.__awaiter) ||
|
|
3
|
+
function (thisArg, _arguments, P, generator) {
|
|
4
|
+
function adopt(value) {
|
|
5
|
+
return value instanceof P
|
|
6
|
+
? value
|
|
7
|
+
: new P(function (resolve) {
|
|
8
|
+
resolve(value);
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
12
|
+
function fulfilled(value) {
|
|
13
|
+
try {
|
|
14
|
+
step(generator.next(value));
|
|
15
|
+
} catch (e) {
|
|
16
|
+
reject(e);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function rejected(value) {
|
|
20
|
+
try {
|
|
21
|
+
step(generator['throw'](value));
|
|
22
|
+
} catch (e) {
|
|
23
|
+
reject(e);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function step(result) {
|
|
27
|
+
result.done
|
|
28
|
+
? resolve(result.value)
|
|
29
|
+
: adopt(result.value).then(fulfilled, rejected);
|
|
30
|
+
}
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
*
|
|
36
|
+
* @param promise
|
|
37
|
+
* @returns [err, res]
|
|
38
|
+
* @reference https://github.com/arthurfiorette/proposal-safe-assignment-operator
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```typescript
|
|
42
|
+
* import { safePromise } from 'lesgo/utils';
|
|
43
|
+
*
|
|
44
|
+
* const [err, res] = await safePromise(fetch('https://example.com/'));
|
|
45
|
+
* if (err) {
|
|
46
|
+
* console.error(err);
|
|
47
|
+
* } else {
|
|
48
|
+
* console.log(res);
|
|
49
|
+
* }
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
const safePromise = promise =>
|
|
53
|
+
__awaiter(void 0, void 0, void 0, function* () {
|
|
54
|
+
try {
|
|
55
|
+
const res = yield promise;
|
|
56
|
+
return [null, res];
|
|
57
|
+
} catch (err) {
|
|
58
|
+
return [err, null];
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
export default safePromise;
|
|
@@ -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
|
-
|
|
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
|
});
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Queue } from '../../services/SQSService/getQueueUrl';
|
|
2
|
+
import { ClientOptions } from '../../types/aws';
|
|
3
|
+
import { changeMessageVisibilityOptions } from '../../services/SQSService/changeMessageVisibility';
|
|
4
|
+
export declare const changeMessageVisibility: (queue: string | Queue, receiptHandle: string, visibilityTimeout: number, opts?: changeMessageVisibilityOptions, clientOpts?: ClientOptions) => Promise<void>;
|
|
5
|
+
export default changeMessageVisibility;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
var __awaiter =
|
|
2
|
+
(this && this.__awaiter) ||
|
|
3
|
+
function (thisArg, _arguments, P, generator) {
|
|
4
|
+
function adopt(value) {
|
|
5
|
+
return value instanceof P
|
|
6
|
+
? value
|
|
7
|
+
: new P(function (resolve) {
|
|
8
|
+
resolve(value);
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
12
|
+
function fulfilled(value) {
|
|
13
|
+
try {
|
|
14
|
+
step(generator.next(value));
|
|
15
|
+
} catch (e) {
|
|
16
|
+
reject(e);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function rejected(value) {
|
|
20
|
+
try {
|
|
21
|
+
step(generator['throw'](value));
|
|
22
|
+
} catch (e) {
|
|
23
|
+
reject(e);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function step(result) {
|
|
27
|
+
result.done
|
|
28
|
+
? resolve(result.value)
|
|
29
|
+
: adopt(result.value).then(fulfilled, rejected);
|
|
30
|
+
}
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
import changeMessageVisibilityService from '../../services/SQSService/changeMessageVisibility';
|
|
35
|
+
export const changeMessageVisibility = (
|
|
36
|
+
queue,
|
|
37
|
+
receiptHandle,
|
|
38
|
+
visibilityTimeout,
|
|
39
|
+
opts,
|
|
40
|
+
clientOpts
|
|
41
|
+
) =>
|
|
42
|
+
__awaiter(void 0, void 0, void 0, function* () {
|
|
43
|
+
return changeMessageVisibilityService(
|
|
44
|
+
queue,
|
|
45
|
+
receiptHandle,
|
|
46
|
+
visibilityTimeout,
|
|
47
|
+
opts,
|
|
48
|
+
clientOpts
|
|
49
|
+
);
|
|
50
|
+
});
|
|
51
|
+
export default changeMessageVisibility;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import appConfig from '../../config/app';
|
|
2
|
+
import awsConfig from '../../config/aws';
|
|
3
|
+
const convert = queueAlias => ({
|
|
4
|
+
alias: queueAlias,
|
|
5
|
+
name: `${appConfig.stackName}-${queueAlias}`,
|
|
6
|
+
url: `https://sqs.${awsConfig.region}.amazonaws.com/${
|
|
7
|
+
awsConfig.accountId
|
|
8
|
+
}/${`${appConfig.stackName}-${queueAlias}`}`,
|
|
9
|
+
});
|
|
10
|
+
export const convertQueueAliasToObject = queueAlias => {
|
|
11
|
+
if (Array.isArray(queueAlias)) {
|
|
12
|
+
return queueAlias.map(q => convert(q));
|
|
13
|
+
}
|
|
14
|
+
return convert(queueAlias);
|
|
15
|
+
};
|
|
16
|
+
export default convertQueueAliasToObject;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { GetQueueCountOptions } from '../../services/SQSService/getQueueCount';
|
|
2
|
+
import { Queue } from '../../services/SQSService/getQueueUrl';
|
|
3
|
+
import { ClientOptions } from '../../types/aws';
|
|
4
|
+
export declare const getQueueCount: (queue: string | Queue, opts?: GetQueueCountOptions, clientOpts?: ClientOptions) => Promise<import("@aws-sdk/client-sqs").GetQueueAttributesCommandOutput>;
|
|
5
|
+
export default getQueueCount;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
var __awaiter =
|
|
2
|
+
(this && this.__awaiter) ||
|
|
3
|
+
function (thisArg, _arguments, P, generator) {
|
|
4
|
+
function adopt(value) {
|
|
5
|
+
return value instanceof P
|
|
6
|
+
? value
|
|
7
|
+
: new P(function (resolve) {
|
|
8
|
+
resolve(value);
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
12
|
+
function fulfilled(value) {
|
|
13
|
+
try {
|
|
14
|
+
step(generator.next(value));
|
|
15
|
+
} catch (e) {
|
|
16
|
+
reject(e);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function rejected(value) {
|
|
20
|
+
try {
|
|
21
|
+
step(generator['throw'](value));
|
|
22
|
+
} catch (e) {
|
|
23
|
+
reject(e);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function step(result) {
|
|
27
|
+
result.done
|
|
28
|
+
? resolve(result.value)
|
|
29
|
+
: adopt(result.value).then(fulfilled, rejected);
|
|
30
|
+
}
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
import getQueueCountService from '../../services/SQSService/getQueueCount';
|
|
35
|
+
export const getQueueCount = (queue, opts, clientOpts) =>
|
|
36
|
+
__awaiter(void 0, void 0, void 0, function* () {
|
|
37
|
+
return getQueueCountService(queue, opts, clientOpts);
|
|
38
|
+
});
|
|
39
|
+
export default getQueueCount;
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
export { default as changeMessageVisibility } from './changeMessageVisibility';
|
|
2
|
+
export { default as convertQueueAliasToObject } from './convertQueueAliasToObject';
|
|
1
3
|
export { default as deleteMessage } from './deleteMessage';
|
|
2
4
|
export { default as dispatch } from './dispatch';
|
|
3
5
|
export { default as getClient } from './getClient';
|
|
6
|
+
export { default as getQueueCount } from './getQueueCount';
|
|
4
7
|
export { default as receiveMessages } from './receiveMessages';
|
package/dist/utils/sqs/index.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
export { default as changeMessageVisibility } from './changeMessageVisibility';
|
|
2
|
+
export { default as convertQueueAliasToObject } from './convertQueueAliasToObject';
|
|
1
3
|
export { default as deleteMessage } from './deleteMessage';
|
|
2
4
|
export { default as dispatch } from './dispatch';
|
|
3
5
|
export { default as getClient } from './getClient';
|
|
6
|
+
export { default as getQueueCount } from './getQueueCount';
|
|
4
7
|
export { default as receiveMessages } from './receiveMessages';
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
export type Params =
|
|
2
|
-
[key: string]: any;
|
|
3
|
-
};
|
|
1
|
+
export type Params = Record<PropertyKey, any>;
|
|
4
2
|
export type Field = {
|
|
5
3
|
key: string;
|
|
6
4
|
type: string;
|
|
@@ -16,7 +14,5 @@ export type Field = {
|
|
|
16
14
|
* @returns An object containing the validated fields.
|
|
17
15
|
* @throws {LesgoException} If a required field is missing or if a field has an invalid type.
|
|
18
16
|
*/
|
|
19
|
-
declare const validateFields: (params:
|
|
20
|
-
[key: string]: any;
|
|
21
|
-
};
|
|
17
|
+
declare const validateFields: <T extends Params>(params: T, validFields: Field[]) => T;
|
|
22
18
|
export default validateFields;
|
|
@@ -25,9 +25,10 @@ const validateFields = (params, validFields) => {
|
|
|
25
25
|
const validated = {};
|
|
26
26
|
validFields.forEach(field => {
|
|
27
27
|
const { required, type, key, isCollection, enumValues = [] } = field;
|
|
28
|
+
const value = params[key];
|
|
28
29
|
if (required) {
|
|
29
|
-
if (typeof
|
|
30
|
-
if (Array.isArray(
|
|
30
|
+
if (typeof value === 'object') {
|
|
31
|
+
if (Array.isArray(value) && value.length === 0) {
|
|
31
32
|
throw new LesgoException(
|
|
32
33
|
`Missing required '${key}'`,
|
|
33
34
|
`${FILE}::MISSING_REQUIRED_${key.toUpperCase()}`,
|
|
@@ -36,8 +37,8 @@ const validateFields = (params, validFields) => {
|
|
|
36
37
|
);
|
|
37
38
|
}
|
|
38
39
|
}
|
|
39
|
-
if (!
|
|
40
|
-
if (typeof
|
|
40
|
+
if (!value) {
|
|
41
|
+
if (typeof value !== 'number') {
|
|
41
42
|
throw new LesgoException(
|
|
42
43
|
`Missing required '${key}'`,
|
|
43
44
|
`${FILE}::MISSING_REQUIRED_${key.toUpperCase()}`,
|
|
@@ -49,19 +50,18 @@ const validateFields = (params, validFields) => {
|
|
|
49
50
|
}
|
|
50
51
|
if (isCollection) {
|
|
51
52
|
try {
|
|
52
|
-
validateFields({ [key]:
|
|
53
|
-
{ key, required, type: 'array' },
|
|
54
|
-
]);
|
|
53
|
+
validateFields({ [key]: value }, [{ key, required, type: 'array' }]);
|
|
55
54
|
} catch (_) {
|
|
56
55
|
throw new LesgoException(
|
|
57
56
|
`Invalid type for '${key}', expecting collection of '${type}'`,
|
|
58
57
|
`${FILE}::INVALID_TYPE_${key.toUpperCase()}`,
|
|
59
58
|
500,
|
|
60
|
-
{ field, value
|
|
59
|
+
{ field, value }
|
|
61
60
|
);
|
|
62
61
|
}
|
|
63
62
|
}
|
|
64
|
-
|
|
63
|
+
const paramsItems = isCollection ? value || [] : [value];
|
|
64
|
+
paramsItems.forEach(paramsItem => {
|
|
65
65
|
if (
|
|
66
66
|
(type === 'string' &&
|
|
67
67
|
typeof paramsItem !== 'undefined' &&
|
|
@@ -101,8 +101,8 @@ const validateFields = (params, validFields) => {
|
|
|
101
101
|
);
|
|
102
102
|
}
|
|
103
103
|
});
|
|
104
|
-
if (typeof
|
|
105
|
-
validated[key] =
|
|
104
|
+
if (typeof value !== 'undefined') {
|
|
105
|
+
validated[key] = value;
|
|
106
106
|
}
|
|
107
107
|
});
|
|
108
108
|
return validated;
|