@allthings/cloud-toolkit 1.3.0-dev.1 → 1.3.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 CHANGED
@@ -3,17 +3,20 @@ Standardizes the setup of aws, datadog and other things
3
3
 
4
4
  ## Available functions
5
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 |
6
+ | function | parameters | description |
7
+ |------------|-----------------------------------------|--------------------------------------------------------------------------------|
8
+ | getSecret | parameter<br/>defaultValue (optional) | Retrieves a single secret from parameter store by providing the path |
9
+ | getSecrets | parameters<br/>defaultValues (optional) | Retrieves multiple secrets from parameter store by providing an array of paths |
10
10
 
11
11
  ### ses
12
- | function | description |
13
- |----------|------------------------------------------------|
14
- | sendMail | Sends an email via SES or provided SMTP config |
12
+ | function | parameters | description |
13
+ |----------|------------|------------------------------------------------|
14
+ | sendMail | options | Sends an email via SES or provided SMTP config |
15
15
 
16
16
  ### lambda
17
- | function | description |
18
- |--------------|------------------------------------------------------|
19
- | invokeLambda | Invokes set lambda with invocations type and payload |
17
+ | function | parameters | description |
18
+ |--------------|----------------------------|------------------------------------------------------|
19
+ | invokeLambda | invocationType<br/>payload | Invokes set lambda with invocations type and payload |
20
+
21
+ ### logger
22
+ A winston instance will be created with default log levels https://github.com/winstonjs/winston?tab=readme-ov-file#logging
package/dist/lib.cjs.js CHANGED
@@ -65,9 +65,9 @@ const DEFAULT_CLIENT_CONFIG$1 = {
65
65
  onlyDefault: false,
66
66
  prefix: process.env.SSM_PARAM_PATH,
67
67
  };
68
- const getSecrets = async (ssm, config, parameters_, defaultValue) => {
68
+ const getSecrets = async (ssm, config, parameters_, defaultValues) => {
69
69
  if (config.onlyDefault) {
70
- return [defaultValue];
70
+ return defaultValues;
71
71
  }
72
72
  try {
73
73
  const command = new clientSsm.GetParametersCommand({
@@ -75,13 +75,21 @@ const getSecrets = async (ssm, config, parameters_, defaultValue) => {
75
75
  WithDecryption: true,
76
76
  });
77
77
  const parameters = await ssm.send(command);
78
- return (parameters?.Parameters?.map((parameter) => parameter.Value ?? defaultValue) ?? [defaultValue]);
78
+ return (parameters?.Parameters?.map((parameter) => {
79
+ const defaultIfNoParameter = !parameter.Value && parameter.Name
80
+ ? defaultValues.find((defaultValue) => defaultValue.name === parameter.Name)
81
+ : defaultValues[0];
82
+ return {
83
+ name: parameter.Name ?? defaultIfNoParameter?.name ?? '',
84
+ value: parameter.Value ?? defaultIfNoParameter?.value ?? '',
85
+ };
86
+ }) ?? defaultValues);
79
87
  }
80
88
  catch (error) {
81
89
  if (config.logger) {
82
90
  config.logger('error', error);
83
91
  }
84
- return [defaultValue];
92
+ return defaultValues;
85
93
  }
86
94
  };
87
95
  const getSecret = async (ssm, config, parameter_, defaultValue) => {
@@ -110,7 +118,7 @@ const parameterStore = (userConfig) => {
110
118
  const ssm = new clientSsm.SSMClient(clientConfig);
111
119
  return {
112
120
  getSecret: (parameter, defaultValue = '') => getSecret(ssm, config, parameter, defaultValue),
113
- getSecrets: (parameters, defaultValue = '') => getSecrets(ssm, config, parameters, defaultValue),
121
+ getSecrets: (parameters, defaultValues = []) => getSecrets(ssm, config, parameters, defaultValues),
114
122
  };
115
123
  };
116
124
 
@@ -170,10 +178,10 @@ const logger = (config) => {
170
178
  format: 'DD-MM-YYYY HH:mm:ss',
171
179
  }), winston.format.json()),
172
180
  };
173
- if (config.datadogApiKey && config.host) {
181
+ if (config.datadogApiKey) {
174
182
  const httpOptions = {
175
- headers: { 'DD-API-KEY': config.datadogApiKey },
176
- host: config.host,
183
+ host: 'http-intake.logs.datadoghq.eu',
184
+ path: `/api/v2/logs?dd-api-key=${config.datadogApiKey}&ddsource=nodejs&service=${config.service}`,
177
185
  port: 443,
178
186
  ssl: true,
179
187
  };
@@ -184,7 +192,7 @@ const logger = (config) => {
184
192
  }
185
193
  return winston.createLogger({
186
194
  ...loggerConfig,
187
- transports: [new winston.transports.Console()],
195
+ transports: [new winston.transports.Console({ forceConsole: true })],
188
196
  });
189
197
  };
190
198
 
package/dist/lib.esm.js CHANGED
@@ -44,9 +44,9 @@ const DEFAULT_CLIENT_CONFIG$1 = {
44
44
  onlyDefault: false,
45
45
  prefix: process.env.SSM_PARAM_PATH,
46
46
  };
47
- const getSecrets = async (ssm, config, parameters_, defaultValue) => {
47
+ const getSecrets = async (ssm, config, parameters_, defaultValues) => {
48
48
  if (config.onlyDefault) {
49
- return [defaultValue];
49
+ return defaultValues;
50
50
  }
51
51
  try {
52
52
  const command = new GetParametersCommand({
@@ -54,13 +54,21 @@ const getSecrets = async (ssm, config, parameters_, defaultValue) => {
54
54
  WithDecryption: true,
55
55
  });
56
56
  const parameters = await ssm.send(command);
57
- return (parameters?.Parameters?.map((parameter) => parameter.Value ?? defaultValue) ?? [defaultValue]);
57
+ return (parameters?.Parameters?.map((parameter) => {
58
+ const defaultIfNoParameter = !parameter.Value && parameter.Name
59
+ ? defaultValues.find((defaultValue) => defaultValue.name === parameter.Name)
60
+ : defaultValues[0];
61
+ return {
62
+ name: parameter.Name ?? defaultIfNoParameter?.name ?? '',
63
+ value: parameter.Value ?? defaultIfNoParameter?.value ?? '',
64
+ };
65
+ }) ?? defaultValues);
58
66
  }
59
67
  catch (error) {
60
68
  if (config.logger) {
61
69
  config.logger('error', error);
62
70
  }
63
- return [defaultValue];
71
+ return defaultValues;
64
72
  }
65
73
  };
66
74
  const getSecret = async (ssm, config, parameter_, defaultValue) => {
@@ -89,7 +97,7 @@ const parameterStore = (userConfig) => {
89
97
  const ssm = new SSMClient(clientConfig);
90
98
  return {
91
99
  getSecret: (parameter, defaultValue = '') => getSecret(ssm, config, parameter, defaultValue),
92
- getSecrets: (parameters, defaultValue = '') => getSecrets(ssm, config, parameters, defaultValue),
100
+ getSecrets: (parameters, defaultValues = []) => getSecrets(ssm, config, parameters, defaultValues),
93
101
  };
94
102
  };
95
103
 
@@ -149,10 +157,10 @@ const logger = (config) => {
149
157
  format: 'DD-MM-YYYY HH:mm:ss',
150
158
  }), format.json()),
151
159
  };
152
- if (config.datadogApiKey && config.host) {
160
+ if (config.datadogApiKey) {
153
161
  const httpOptions = {
154
- headers: { 'DD-API-KEY': config.datadogApiKey },
155
- host: config.host,
162
+ host: 'http-intake.logs.datadoghq.eu',
163
+ path: `/api/v2/logs?dd-api-key=${config.datadogApiKey}&ddsource=nodejs&service=${config.service}`,
156
164
  port: 443,
157
165
  ssl: true,
158
166
  };
@@ -163,7 +171,7 @@ const logger = (config) => {
163
171
  }
164
172
  return createLogger({
165
173
  ...loggerConfig,
166
- transports: [new transports.Console()],
174
+ transports: [new transports.Console({ forceConsole: true })],
167
175
  });
168
176
  };
169
177