@velocitycareerlabs/aws-clients 1.25.0-dev-build.187d88673 → 1.25.0-dev-build.16cf6a024
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/package.json +4 -4
- package/src/client-config.js +23 -0
- package/src/document-storage.js +8 -11
- package/src/email-notifications.js +14 -13
- package/src/kms-client.js +7 -10
- package/src/s3-client.js +8 -7
- package/src/sms-notifications.js +8 -11
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@velocitycareerlabs/aws-clients",
|
3
|
-
"version": "1.25.0-dev-build.
|
3
|
+
"version": "1.25.0-dev-build.16cf6a024",
|
4
4
|
"description": "Set of aws functions and utils used by Velocity Foundation projects",
|
5
5
|
"repository": "https://github.com/velocitycareerlabs/packages",
|
6
6
|
"main": "index.js",
|
@@ -29,8 +29,8 @@
|
|
29
29
|
"twilio": "^5.0.0"
|
30
30
|
},
|
31
31
|
"devDependencies": {
|
32
|
-
"@velocitycareerlabs/crypto": "1.25.0-dev-build.
|
33
|
-
"@velocitycareerlabs/jwt": "1.25.0-dev-build.
|
32
|
+
"@velocitycareerlabs/crypto": "1.25.0-dev-build.16cf6a024",
|
33
|
+
"@velocitycareerlabs/jwt": "1.25.0-dev-build.16cf6a024",
|
34
34
|
"eslint": "8.57.1",
|
35
35
|
"eslint-config-airbnb-base": "14.2.1",
|
36
36
|
"eslint-config-prettier": "8.10.0",
|
@@ -43,5 +43,5 @@
|
|
43
43
|
"jest": "29.7.0",
|
44
44
|
"prettier": "2.8.8"
|
45
45
|
},
|
46
|
-
"gitHead": "
|
46
|
+
"gitHead": "83ab42d61fe23686696297589265e19fccbba500"
|
47
47
|
}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
const buildClientConfig = ({
|
2
|
+
apiVersion,
|
3
|
+
awsRegion,
|
4
|
+
awsEndpoint,
|
5
|
+
accessKeyId,
|
6
|
+
secretAccessKey,
|
7
|
+
}) => ({
|
8
|
+
apiVersion,
|
9
|
+
region: awsRegion,
|
10
|
+
...(awsEndpoint
|
11
|
+
? {
|
12
|
+
credentials: {
|
13
|
+
accessKeyId: accessKeyId ?? 'tests-key-id',
|
14
|
+
secretAccessKey: secretAccessKey ?? 'tests-key',
|
15
|
+
},
|
16
|
+
endpoint: awsEndpoint,
|
17
|
+
}
|
18
|
+
: {}),
|
19
|
+
});
|
20
|
+
|
21
|
+
module.exports = {
|
22
|
+
buildClientConfig,
|
23
|
+
};
|
package/src/document-storage.js
CHANGED
@@ -20,20 +20,17 @@ const {
|
|
20
20
|
GetCommand,
|
21
21
|
PutCommand,
|
22
22
|
} = require('@aws-sdk/lib-dynamodb');
|
23
|
+
const { buildClientConfig } = require('./client-config');
|
23
24
|
|
24
25
|
const createDynamoDbDocumentClient = ({ awsRegion, awsEndpoint }) =>
|
25
26
|
DynamoDBDocumentClient.from(
|
26
|
-
new DynamoDB(
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
}
|
34
|
-
: awsEndpoint,
|
35
|
-
endpoint: awsEndpoint,
|
36
|
-
})
|
27
|
+
new DynamoDB(
|
28
|
+
buildClientConfig({
|
29
|
+
apiVersion: '2012-08-10',
|
30
|
+
awsRegion,
|
31
|
+
awsEndpoint,
|
32
|
+
})
|
33
|
+
)
|
37
34
|
);
|
38
35
|
|
39
36
|
const initReadDocument =
|
@@ -23,26 +23,27 @@ const {
|
|
23
23
|
SESv2Client,
|
24
24
|
SendEmailCommand: SESv2SendEmailCommand,
|
25
25
|
} = require('@aws-sdk/client-sesv2');
|
26
|
+
const { buildClientConfig } = require('./client-config');
|
26
27
|
|
27
28
|
// 2020-10-20: At the moment free Localstack doesn't support SESv2,
|
28
29
|
// so SES is used for testing when a value is passed for endpoint (local address)
|
29
30
|
|
30
31
|
const createSesClient = ({ awsRegion, awsEndpoint }) =>
|
31
|
-
new SESClient(
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
endpoint: awsEndpoint,
|
39
|
-
});
|
32
|
+
new SESClient(
|
33
|
+
buildClientConfig({
|
34
|
+
apiVersion: '2010-12-01',
|
35
|
+
awsRegion,
|
36
|
+
awsEndpoint,
|
37
|
+
})
|
38
|
+
);
|
40
39
|
|
41
40
|
const createSesV2Client = ({ awsRegion }) =>
|
42
|
-
new SESv2Client(
|
43
|
-
|
44
|
-
|
45
|
-
|
41
|
+
new SESv2Client(
|
42
|
+
buildClientConfig({
|
43
|
+
apiVersion: '2019-09-27',
|
44
|
+
awsRegion,
|
45
|
+
})
|
46
|
+
);
|
46
47
|
|
47
48
|
const initSendEmailNotification =
|
48
49
|
({ awsRegion, awsEndpoint }) =>
|
package/src/kms-client.js
CHANGED
@@ -19,18 +19,15 @@ const {
|
|
19
19
|
EncryptCommand,
|
20
20
|
DecryptCommand,
|
21
21
|
} = require('@aws-sdk/client-kms');
|
22
|
+
const { buildClientConfig } = require('./client-config');
|
22
23
|
|
23
24
|
const initKmsClient = ({ awsRegion, awsEndpoint }) => {
|
24
|
-
const kmsClient = new KMSClient(
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
}
|
31
|
-
: awsEndpoint,
|
32
|
-
endpoint: awsEndpoint,
|
33
|
-
});
|
25
|
+
const kmsClient = new KMSClient(
|
26
|
+
buildClientConfig({
|
27
|
+
awsRegion,
|
28
|
+
awsEndpoint,
|
29
|
+
})
|
30
|
+
);
|
34
31
|
|
35
32
|
const encrypt = async (keyId, plaintext) => {
|
36
33
|
const command = new EncryptCommand({
|
package/src/s3-client.js
CHANGED
@@ -23,26 +23,27 @@ const {
|
|
23
23
|
const {
|
24
24
|
getSignedUrl: awsGetSignedUrl,
|
25
25
|
} = require('@aws-sdk/s3-request-presigner');
|
26
|
+
const { buildClientConfig } = require('./client-config');
|
26
27
|
|
27
28
|
const initS3Client = ({
|
28
29
|
awsRegion,
|
29
30
|
awsEndpoint,
|
30
31
|
s3Bucket,
|
31
|
-
s3PresignedUrlExpiration,
|
32
32
|
accessKeyId,
|
33
33
|
secretAccessKey,
|
34
|
+
s3PresignedUrlExpiration,
|
34
35
|
isTest,
|
35
36
|
}) => {
|
36
37
|
const s3Client = new S3Client({
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
38
|
+
...buildClientConfig({
|
39
|
+
apiVersion: '2006-03-01',
|
40
|
+
awsRegion,
|
41
|
+
awsEndpoint,
|
41
42
|
accessKeyId,
|
42
43
|
secretAccessKey,
|
43
|
-
},
|
44
|
+
}),
|
44
45
|
forcePathStyle: isTest,
|
45
|
-
|
46
|
+
signatureVersion: 'v4',
|
46
47
|
});
|
47
48
|
|
48
49
|
const getSignedUrl = async ({ key, contentType, metadata }) => {
|
package/src/sms-notifications.js
CHANGED
@@ -16,6 +16,7 @@
|
|
16
16
|
const { startsWith } = require('lodash/fp');
|
17
17
|
const { SNSClient, PublishCommand } = require('@aws-sdk/client-sns');
|
18
18
|
const { createTwilioClient } = require('./twilio-factory');
|
19
|
+
const { buildClientConfig } = require('./client-config');
|
19
20
|
|
20
21
|
const singaporePhoneCode = '+65';
|
21
22
|
|
@@ -39,17 +40,13 @@ const initSendSmsNotification =
|
|
39
40
|
onlyTwilioSms,
|
40
41
|
}) =>
|
41
42
|
async ({ message, phoneNumber, senderId }) => {
|
42
|
-
const awsSns = new SNSClient(
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
}
|
50
|
-
: awsEndpoint,
|
51
|
-
endpoint: awsEndpoint,
|
52
|
-
});
|
43
|
+
const awsSns = new SNSClient(
|
44
|
+
buildClientConfig({
|
45
|
+
apiVersion: '2010-03-31',
|
46
|
+
awsRegion,
|
47
|
+
awsEndpoint,
|
48
|
+
})
|
49
|
+
);
|
53
50
|
const { sendTwilioSms } = createTwilioClient({
|
54
51
|
twilioAccountSid,
|
55
52
|
twilioAuthToken,
|