@dmptool/utils 1.0.29 → 1.0.30
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 +22 -15
- package/dist/maDMP.js +5 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -15,7 +15,7 @@ See below for usage examples of each utility.
|
|
|
15
15
|
- [AWS CloudFormation Stack Output Access](#cloudformation-support)
|
|
16
16
|
- [AWS DynamoDB Table Access](#dynamodb-support)
|
|
17
17
|
- [General Helper Functions](#general-helper-functions)
|
|
18
|
-
- [
|
|
18
|
+
- [SQS Message Publication](#sqs-support)
|
|
19
19
|
- [Logger Support (Pino with ECS formatting)](#logger-support-pino-with-ecs-formatting)
|
|
20
20
|
- [maDMP Support (serialization and deserialization)](#madmp-support-serialization-and-deserialization)
|
|
21
21
|
- [AWS RDS MySQL Database Access](#rds-mysql-support)
|
|
@@ -209,40 +209,40 @@ if (exists) {
|
|
|
209
209
|
}
|
|
210
210
|
}
|
|
211
211
|
```
|
|
212
|
-
##
|
|
212
|
+
## SQS Support
|
|
213
213
|
|
|
214
|
-
This code can be used to
|
|
214
|
+
This code can be used to send messages to an SQS Queue.
|
|
215
215
|
|
|
216
216
|
### Example usage
|
|
217
217
|
```typescript
|
|
218
|
-
import { initializeLogger,
|
|
218
|
+
import { initializeLogger, sendMessage, SendMessageResponse } from '@dmptool/utils';
|
|
219
219
|
|
|
220
220
|
const region = 'us-west-2';
|
|
221
221
|
|
|
222
222
|
// Initialize a logger
|
|
223
223
|
const logger: Logger = initializeLogger('exampleSSM', LogLevelEnum.DEBUG);
|
|
224
224
|
|
|
225
|
-
const
|
|
225
|
+
const queueURL = 'https://sqs.us-west-2.amazonaws.com/12345/my-example-function';
|
|
226
226
|
|
|
227
227
|
// See the documentation for the AWS Lambda you are trying to invoke to determine what the
|
|
228
228
|
// `detail-type` and `detail` payload should look like.
|
|
229
|
-
const source = 'my-application';
|
|
230
|
-
const detailType = 'my-
|
|
229
|
+
const source = 'my-application';
|
|
230
|
+
const detailType = 'my-message';
|
|
231
231
|
const detail = { property1: 'value1', property2: 'value2' }
|
|
232
232
|
|
|
233
|
-
const
|
|
233
|
+
const sent: SendMessageResponse = await sendMessage(
|
|
234
234
|
logger,
|
|
235
|
-
|
|
235
|
+
queueURL,
|
|
236
236
|
source,
|
|
237
237
|
detailType,
|
|
238
238
|
detail,
|
|
239
|
-
region
|
|
239
|
+
region,
|
|
240
240
|
);
|
|
241
241
|
|
|
242
|
-
if (
|
|
243
|
-
console.log('Message
|
|
242
|
+
if (sent && sent.status >= 200 && sent.status < 300) {
|
|
243
|
+
console.log('Message successfully sent', sent.status);
|
|
244
244
|
} else {
|
|
245
|
-
console.log('Error
|
|
245
|
+
console.log('Error sending message', sent.status, sent.messageId);
|
|
246
246
|
}
|
|
247
247
|
```
|
|
248
248
|
|
|
@@ -304,6 +304,7 @@ Environment variable requirements:
|
|
|
304
304
|
### Example usage
|
|
305
305
|
```typescript
|
|
306
306
|
import { Logger } from 'pino';
|
|
307
|
+
import { Context, SQSEvent, SQSHandler, SQSBatchResponse } from 'aws-lambda';
|
|
307
308
|
import { initializeLogger, LogLevel } from '@dmptool/utils';
|
|
308
309
|
|
|
309
310
|
process.env.AWS_REGION = 'us-west-2';
|
|
@@ -316,14 +317,20 @@ const logger: Logger = initializeLogger('GenerateMaDMPRecordLambda', LogLevel[LO
|
|
|
316
317
|
// Setup the LambdaRequestTracker for the logger
|
|
317
318
|
const withRequest = lambdaRequestTracker();
|
|
318
319
|
|
|
319
|
-
export const handler:
|
|
320
|
+
export const handler: SQSHandler = async (event: SQSEvent, context: Context): Promise<SQSBatchResponse> => {
|
|
320
321
|
// Log the incoming event and context
|
|
321
322
|
logger.debug({ event, context }, 'Received event');
|
|
322
323
|
|
|
323
324
|
// Initialize the logger by setting up automatic request tracing.
|
|
324
325
|
withRequest(event, context);
|
|
325
326
|
|
|
326
|
-
|
|
327
|
+
// Loop through the records in the event
|
|
328
|
+
for (const record of event.Records) {
|
|
329
|
+
logger.info({
|
|
330
|
+
log_level: LOG_LEVEL,
|
|
331
|
+
record_body: record.body
|
|
332
|
+
}, 'Processing record');
|
|
333
|
+
}
|
|
327
334
|
}
|
|
328
335
|
```
|
|
329
336
|
|
package/dist/maDMP.js
CHANGED
|
@@ -400,6 +400,11 @@ const loadNarrativeTemplateInfo = async (rdsConnectionParams, planId) => {
|
|
|
400
400
|
}
|
|
401
401
|
if (row.questionId !== null && row.questionId !== undefined) {
|
|
402
402
|
const hasAnswer = row.answerJSON !== undefined && row.answerJSON !== null;
|
|
403
|
+
if (hasAnswer) {
|
|
404
|
+
// parse the nested answer value which is stored as a JSON string
|
|
405
|
+
const answerVal = hasAnswer ? JSON.parse(row.answerJSON.answer) : undefined;
|
|
406
|
+
row.answerJSON.answer = answerVal;
|
|
407
|
+
}
|
|
403
408
|
// Every row in the results represents a single question/answer pair
|
|
404
409
|
curSection.question.push({
|
|
405
410
|
id: row.questionId,
|
package/package.json
CHANGED