@allthings/cloud-toolkit 1.0.0 → 1.1.0-dev.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.
- package/README.md +12 -0
- package/dist/lib.cjs.js +71 -3
- package/dist/lib.esm.js +50 -3
- package/dist/lib.umd.min.js +1 -1
- package/dist/src/aws/index.d.ts +2 -0
- package/dist/src/aws/ses.d.ts +32 -0
- package/dist/src/aws/ses.test.d.ts +1 -0
- package/dist/src/index.d.ts +1 -1
- package/package.json +4 -1
- package/dist/test/setup.js +0 -0
package/README.md
CHANGED
|
@@ -1,2 +1,14 @@
|
|
|
1
1
|
# cloud-toolkit
|
|
2
2
|
Standardizes the setup of aws, datadog and other things
|
|
3
|
+
|
|
4
|
+
## Available functions
|
|
5
|
+
### parameter store
|
|
6
|
+
| function | description |
|
|
7
|
+
|------------|--------------------------------------------------------------------------------|
|
|
8
|
+
| getSecret | Retrieves a single secret from parameter store by providing the path |
|
|
9
|
+
| getSecrets | Retrieves multiple secrets from parameter store by providing an array of paths |
|
|
10
|
+
|
|
11
|
+
### ses
|
|
12
|
+
| function | description |
|
|
13
|
+
|----------|------------------------------------------------|
|
|
14
|
+
| sendMail | Sends an email via SES or provided SMTP config |
|
package/dist/lib.cjs.js
CHANGED
|
@@ -1,12 +1,33 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var clientSsm = require('@aws-sdk/client-ssm');
|
|
4
|
+
var aws = require('@aws-sdk/client-ses');
|
|
5
|
+
var nodemailer = require('nodemailer');
|
|
6
|
+
|
|
7
|
+
function _interopNamespaceDefault(e) {
|
|
8
|
+
var n = Object.create(null);
|
|
9
|
+
if (e) {
|
|
10
|
+
Object.keys(e).forEach(function (k) {
|
|
11
|
+
if (k !== 'default') {
|
|
12
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
13
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
get: function () { return e[k]; }
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
n.default = e;
|
|
21
|
+
return Object.freeze(n);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
var aws__namespace = /*#__PURE__*/_interopNamespaceDefault(aws);
|
|
4
25
|
|
|
5
26
|
const DEFAULT_AWS_CONFIGURATION = {
|
|
6
27
|
region: 'eu-central-2',
|
|
7
28
|
};
|
|
8
29
|
|
|
9
|
-
const DEFAULT_CLIENT_CONFIG = {
|
|
30
|
+
const DEFAULT_CLIENT_CONFIG$1 = {
|
|
10
31
|
clientConfig: DEFAULT_AWS_CONFIGURATION,
|
|
11
32
|
onlyDefault: false,
|
|
12
33
|
prefix: process.env.SSM_PARAM_PATH,
|
|
@@ -50,7 +71,7 @@ const getSecret = async (ssm, config, parameter_, defaultValue) => {
|
|
|
50
71
|
};
|
|
51
72
|
const parameterStore = (userConfig) => {
|
|
52
73
|
const { clientConfig, ...config } = {
|
|
53
|
-
...DEFAULT_CLIENT_CONFIG,
|
|
74
|
+
...DEFAULT_CLIENT_CONFIG$1,
|
|
54
75
|
...userConfig,
|
|
55
76
|
};
|
|
56
77
|
const ssm = new clientSsm.SSMClient(clientConfig);
|
|
@@ -60,5 +81,52 @@ const parameterStore = (userConfig) => {
|
|
|
60
81
|
};
|
|
61
82
|
};
|
|
62
83
|
|
|
63
|
-
|
|
84
|
+
const DEFAULT_CLIENT_CONFIG = {
|
|
85
|
+
clientConfig: { region: 'eu-west-1' },
|
|
86
|
+
};
|
|
87
|
+
const sendMail = async (config, transport, options, from) => {
|
|
88
|
+
if (!options.html && !options.text) {
|
|
89
|
+
if (config.logger) {
|
|
90
|
+
config.logger('The option text or html needs to be set.');
|
|
91
|
+
}
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
if (!options.to || !options.subject) {
|
|
95
|
+
if (config.logger) {
|
|
96
|
+
config.logger('The fields to and subject have to be set.');
|
|
97
|
+
}
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
const transportResponse = await transport.sendMail({
|
|
101
|
+
from,
|
|
102
|
+
...options,
|
|
103
|
+
});
|
|
104
|
+
if (config.logger) {
|
|
105
|
+
config.logger(`Transporter response: ${transportResponse}`);
|
|
106
|
+
}
|
|
107
|
+
if (!transportResponse) {
|
|
108
|
+
if (config.logger) {
|
|
109
|
+
config.logger('Sending email failed!');
|
|
110
|
+
}
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
return true;
|
|
114
|
+
};
|
|
115
|
+
const ses = (fromEmailAddress, userConfig) => {
|
|
116
|
+
const { clientConfig, ...config } = {
|
|
117
|
+
...DEFAULT_CLIENT_CONFIG,
|
|
118
|
+
...userConfig,
|
|
119
|
+
};
|
|
120
|
+
const sesClient = new aws__namespace.SESClient(clientConfig);
|
|
121
|
+
const transport = nodemailer.createTransport(userConfig.customSMTPConfig ?? {
|
|
122
|
+
SES: { aws: aws__namespace, ses: sesClient },
|
|
123
|
+
});
|
|
124
|
+
return {
|
|
125
|
+
sendMail: (options) => sendMail(config, transport, options, fromEmailAddress),
|
|
126
|
+
};
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
exports.DEFAULT_PARAMETER_STORE_CLIENT_CONFIG = DEFAULT_CLIENT_CONFIG$1;
|
|
130
|
+
exports.DEFAULT_SES_CLIENT_CONFIG = DEFAULT_CLIENT_CONFIG;
|
|
64
131
|
exports.parameterStore = parameterStore;
|
|
132
|
+
exports.ses = ses;
|
package/dist/lib.esm.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { SSMClient, GetParametersCommand, GetParameterCommand } from '@aws-sdk/client-ssm';
|
|
2
|
+
import * as aws from '@aws-sdk/client-ses';
|
|
3
|
+
import { createTransport } from 'nodemailer';
|
|
2
4
|
|
|
3
5
|
const DEFAULT_AWS_CONFIGURATION = {
|
|
4
6
|
region: 'eu-central-2',
|
|
5
7
|
};
|
|
6
8
|
|
|
7
|
-
const DEFAULT_CLIENT_CONFIG = {
|
|
9
|
+
const DEFAULT_CLIENT_CONFIG$1 = {
|
|
8
10
|
clientConfig: DEFAULT_AWS_CONFIGURATION,
|
|
9
11
|
onlyDefault: false,
|
|
10
12
|
prefix: process.env.SSM_PARAM_PATH,
|
|
@@ -48,7 +50,7 @@ const getSecret = async (ssm, config, parameter_, defaultValue) => {
|
|
|
48
50
|
};
|
|
49
51
|
const parameterStore = (userConfig) => {
|
|
50
52
|
const { clientConfig, ...config } = {
|
|
51
|
-
...DEFAULT_CLIENT_CONFIG,
|
|
53
|
+
...DEFAULT_CLIENT_CONFIG$1,
|
|
52
54
|
...userConfig,
|
|
53
55
|
};
|
|
54
56
|
const ssm = new SSMClient(clientConfig);
|
|
@@ -58,4 +60,49 @@ const parameterStore = (userConfig) => {
|
|
|
58
60
|
};
|
|
59
61
|
};
|
|
60
62
|
|
|
61
|
-
|
|
63
|
+
const DEFAULT_CLIENT_CONFIG = {
|
|
64
|
+
clientConfig: { region: 'eu-west-1' },
|
|
65
|
+
};
|
|
66
|
+
const sendMail = async (config, transport, options, from) => {
|
|
67
|
+
if (!options.html && !options.text) {
|
|
68
|
+
if (config.logger) {
|
|
69
|
+
config.logger('The option text or html needs to be set.');
|
|
70
|
+
}
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
if (!options.to || !options.subject) {
|
|
74
|
+
if (config.logger) {
|
|
75
|
+
config.logger('The fields to and subject have to be set.');
|
|
76
|
+
}
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
const transportResponse = await transport.sendMail({
|
|
80
|
+
from,
|
|
81
|
+
...options,
|
|
82
|
+
});
|
|
83
|
+
if (config.logger) {
|
|
84
|
+
config.logger(`Transporter response: ${transportResponse}`);
|
|
85
|
+
}
|
|
86
|
+
if (!transportResponse) {
|
|
87
|
+
if (config.logger) {
|
|
88
|
+
config.logger('Sending email failed!');
|
|
89
|
+
}
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
return true;
|
|
93
|
+
};
|
|
94
|
+
const ses = (fromEmailAddress, userConfig) => {
|
|
95
|
+
const { clientConfig, ...config } = {
|
|
96
|
+
...DEFAULT_CLIENT_CONFIG,
|
|
97
|
+
...userConfig,
|
|
98
|
+
};
|
|
99
|
+
const sesClient = new aws.SESClient(clientConfig);
|
|
100
|
+
const transport = createTransport(userConfig.customSMTPConfig ?? {
|
|
101
|
+
SES: { aws, ses: sesClient },
|
|
102
|
+
});
|
|
103
|
+
return {
|
|
104
|
+
sendMail: (options) => sendMail(config, transport, options, fromEmailAddress),
|
|
105
|
+
};
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
export { DEFAULT_CLIENT_CONFIG$1 as DEFAULT_PARAMETER_STORE_CLIENT_CONFIG, DEFAULT_CLIENT_CONFIG as DEFAULT_SES_CLIENT_CONFIG, parameterStore, ses };
|