@dmptool/utils 1.0.29 → 1.0.31

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
@@ -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
- - [EventBridge Event Publication](#eventbridge-support)
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
- ## EventBridge Support
212
+ ## SQS Support
213
213
 
214
- This code can be used to publish events to the EventBridge.
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, LogLevelEnum, publishMessage } from '@dmptool/utils';
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 busName = 'arn:aws:sns:us-east-1:123456789012:my-topic';
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-event';
229
+ const source = 'my-application';
230
+ const detailType = 'my-message';
231
231
  const detail = { property1: 'value1', property2: 'value2' }
232
232
 
233
- const response = await publishMessage(
233
+ const sent: SendMessageResponse = await sendMessage(
234
234
  logger,
235
- busName,
235
+ queueURL,
236
236
  source,
237
237
  detailType,
238
238
  detail,
239
- region
239
+ region,
240
240
  );
241
241
 
242
- if (response.statusCode === 200) {
243
- console.log('Message published successfully', response.body);
242
+ if (sent && sent.status >= 200 && sent.status < 300) {
243
+ console.log('Message successfully sent', sent.status);
244
244
  } else {
245
- console.log('Error publishing message', response.body);
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: Handler = async (event: EventBridgeEvent<string, EventBridgeDetails>, context: Context) => {
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
- logger.info({ log_level: LOG_LEVEL, foo: "bar" }, 'Hello World!');
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.d.ts CHANGED
@@ -45,6 +45,7 @@ export declare const validateDMPToolExtensions: (logger: Logger, dmpId: string,
45
45
  * @param domainName the domain name of the application/service website
46
46
  * @param planId the ID of the plan to generate the DMP for
47
47
  * @param env The environment from EnvironmentEnum (defaults to EnvironmentEnum.DEV)
48
+ * @param includeExtensions whether to include the DMP Tool extensions. Defaults to true.
48
49
  * @returns a JSON representation of the DMP
49
50
  */
50
- export declare function planToDMPCommonStandard(rdsConnectionParams: ConnectionParams, applicationName: string, domainName: string, env: EnvironmentEnum | undefined, planId: number): Promise<DMPToolDMPType | undefined>;
51
+ export declare function planToDMPCommonStandard(rdsConnectionParams: ConnectionParams, applicationName: string, domainName: string, env: EnvironmentEnum | undefined, planId: number, includeExtensions: true): Promise<DMPToolDMPType | undefined>;
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,
@@ -930,9 +935,10 @@ const cleanRDACommonStandard = (plan, dmp) => {
930
935
  * @param domainName the domain name of the application/service website
931
936
  * @param planId the ID of the plan to generate the DMP for
932
937
  * @param env The environment from EnvironmentEnum (defaults to EnvironmentEnum.DEV)
938
+ * @param includeExtensions whether to include the DMP Tool extensions. Defaults to true.
933
939
  * @returns a JSON representation of the DMP
934
940
  */
935
- async function planToDMPCommonStandard(rdsConnectionParams, applicationName, domainName, env = general_1.EnvironmentEnum.DEV, planId) {
941
+ async function planToDMPCommonStandard(rdsConnectionParams, applicationName, domainName, env = general_1.EnvironmentEnum.DEV, planId, includeExtensions) {
936
942
  if (!rdsConnectionParams || !applicationName || !domainName || !planId) {
937
943
  throw new Error('Invalid arguments provided to planToDMPCommonStandard');
938
944
  }
@@ -1025,10 +1031,14 @@ async function planToDMPCommonStandard(rdsConnectionParams, applicationName, dom
1025
1031
  }
1026
1032
  const cleaned = cleanRDACommonStandard(plan, dmp);
1027
1033
  // Generate the DMP Tool extensions to the RDA Common Standard
1028
- const extensions = await buildDMPToolExtensions(rdsConnectionParams, applicationName, domainName, plan, project, funding);
1034
+ const extensions = includeExtensions
1035
+ ? await buildDMPToolExtensions(rdsConnectionParams, applicationName, domainName, plan, project, funding)
1036
+ : undefined;
1029
1037
  rdsConnectionParams.logger.debug({ applicationName, domainName, planId, env, dmpId: plan.dmpId }, 'Generated maDMP metadata record');
1030
1038
  // Return the combined DMP metadata record
1031
- return {
1032
- dmp: Object.assign(Object.assign({}, (0, exports.validateRDACommonStandard)(rdsConnectionParams.logger, cleaned).dmp), (0, exports.validateDMPToolExtensions)(rdsConnectionParams.logger, plan.dmpId, extensions))
1033
- };
1039
+ return includeExtensions && extensions
1040
+ ? {
1041
+ dmp: Object.assign(Object.assign({}, (0, exports.validateRDACommonStandard)(rdsConnectionParams.logger, cleaned).dmp), (0, exports.validateDMPToolExtensions)(rdsConnectionParams.logger, plan.dmpId, extensions))
1042
+ }
1043
+ : (0, exports.validateRDACommonStandard)(rdsConnectionParams.logger, cleaned);
1034
1044
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dmptool/utils",
3
- "version": "1.0.29",
3
+ "version": "1.0.31",
4
4
  "description": "Helper/Utility functions for use in the DMP Tool services. Particularly AWS tooling and maDMP serialization",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",