@dmptool/utils 1.0.32 → 1.0.34
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/dist/dynamo.d.ts +2 -4
- package/dist/dynamo.js +6 -6
- package/dist/general.d.ts +7 -0
- package/dist/general.js +17 -1
- package/dist/maDMP.js +7 -8
- package/dist/sqs.d.ts +3 -1
- package/dist/sqs.js +10 -2
- package/package.json +1 -1
package/dist/dynamo.d.ts
CHANGED
|
@@ -8,9 +8,8 @@ export interface DynamoConnectionParams {
|
|
|
8
8
|
tableName: string;
|
|
9
9
|
maxAttempts: number;
|
|
10
10
|
}
|
|
11
|
-
interface DMPVersionType {
|
|
12
|
-
|
|
13
|
-
SK: string;
|
|
11
|
+
export interface DMPVersionType {
|
|
12
|
+
dmpId: string;
|
|
14
13
|
modified: string;
|
|
15
14
|
}
|
|
16
15
|
/**
|
|
@@ -133,4 +132,3 @@ export declare const tombstoneDMP: (dynamoConnectionParams: DynamoConnectionPara
|
|
|
133
132
|
* @throws DMPToolDynamoError if the record could not be deleted
|
|
134
133
|
*/
|
|
135
134
|
export declare const deleteDMP: (dynamoConnectionParams: DynamoConnectionParams, domainName: string, dmpId: string, includeExtensions?: boolean) => Promise<DMPToolDMPType>;
|
|
136
|
-
export {};
|
package/dist/dynamo.js
CHANGED
|
@@ -156,13 +156,14 @@ const getDMPVersions = async (dynamoConnectionParams, dmpId) => {
|
|
|
156
156
|
const unmarshalled = (0, util_dynamodb_1.unmarshall)(item);
|
|
157
157
|
if (unmarshalled.PK && unmarshalled.SK && unmarshalled.modified) {
|
|
158
158
|
versions.push({
|
|
159
|
-
|
|
160
|
-
SK: unmarshalled.SK,
|
|
159
|
+
dmpId: unmarshalled.PK.replace(`${DMP_PK_PREFIX}#`, 'https://'),
|
|
161
160
|
modified: unmarshalled.modified
|
|
162
161
|
});
|
|
163
162
|
}
|
|
164
163
|
}
|
|
165
|
-
return versions
|
|
164
|
+
return versions.sort((a, b) => {
|
|
165
|
+
return b.modified.localeCompare(a.modified);
|
|
166
|
+
});
|
|
166
167
|
}
|
|
167
168
|
return [];
|
|
168
169
|
}
|
|
@@ -310,10 +311,9 @@ const getDMPExtensions = async (dynamoConnectionParams, domainName, dmpId, versi
|
|
|
310
311
|
if (Array.isArray(versions) && versions.length > 0) {
|
|
311
312
|
// Return the versions sorted descending
|
|
312
313
|
extension.version = versions
|
|
313
|
-
.
|
|
314
|
-
.map((v) => {
|
|
314
|
+
.map((v, idx) => {
|
|
315
315
|
// The latest version doesn't have a query param appended to the URL
|
|
316
|
-
const queryParam =
|
|
316
|
+
const queryParam = idx === 0
|
|
317
317
|
? ''
|
|
318
318
|
: `?version=${v.modified}`;
|
|
319
319
|
const dmpIdWithoutProtocol = dmpId.replace(/^https?:\/\//, '');
|
package/dist/general.d.ts
CHANGED
|
@@ -61,6 +61,13 @@ export declare const isNullOrUndefined: (val: unknown) => boolean;
|
|
|
61
61
|
* @returns The object with null and undefined values removed.
|
|
62
62
|
*/
|
|
63
63
|
export declare const removeNullAndUndefinedFromObject: (obj: any) => any;
|
|
64
|
+
/**
|
|
65
|
+
* Function to check if a string is a valid JSON string.
|
|
66
|
+
*
|
|
67
|
+
* @param str The string to check.
|
|
68
|
+
* @returns True if the string is a valid JSON string, false otherwise.
|
|
69
|
+
*/
|
|
70
|
+
export declare const isJSON: (str: string) => boolean;
|
|
64
71
|
/**
|
|
65
72
|
* Function to test for equality between two objects, arrays or primitives
|
|
66
73
|
*
|
package/dist/general.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.areEqual = exports.removeNullAndUndefinedFromObject = exports.isNullOrUndefined = exports.randomHex = exports.convertMySQLDateTimeToRFC3339 = exports.currentDateAsString = exports.isValidDate = exports.normaliseHttpProtocol = exports.toErrorMessage = exports.EnvironmentEnum = void 0;
|
|
3
|
+
exports.areEqual = exports.isJSON = exports.removeNullAndUndefinedFromObject = exports.isNullOrUndefined = exports.randomHex = exports.convertMySQLDateTimeToRFC3339 = exports.currentDateAsString = exports.isValidDate = exports.normaliseHttpProtocol = exports.toErrorMessage = exports.EnvironmentEnum = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* Possible environments for the application.
|
|
6
6
|
*/
|
|
@@ -122,6 +122,22 @@ const removeNullAndUndefinedFromObject = (obj) => {
|
|
|
122
122
|
return obj;
|
|
123
123
|
};
|
|
124
124
|
exports.removeNullAndUndefinedFromObject = removeNullAndUndefinedFromObject;
|
|
125
|
+
/**
|
|
126
|
+
* Function to check if a string is a valid JSON string.
|
|
127
|
+
*
|
|
128
|
+
* @param str The string to check.
|
|
129
|
+
* @returns True if the string is a valid JSON string, false otherwise.
|
|
130
|
+
*/
|
|
131
|
+
const isJSON = (str) => {
|
|
132
|
+
try {
|
|
133
|
+
JSON.parse(str);
|
|
134
|
+
}
|
|
135
|
+
catch (e) {
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
138
|
+
return true;
|
|
139
|
+
};
|
|
140
|
+
exports.isJSON = isJSON;
|
|
125
141
|
/**
|
|
126
142
|
* Function to test for equality between two objects, arrays or primitives
|
|
127
143
|
*
|
package/dist/maDMP.js
CHANGED
|
@@ -355,7 +355,8 @@ const loadNarrativeTemplateInfo = async (rdsConnectionParams, planId) => {
|
|
|
355
355
|
t.version templateVersion,
|
|
356
356
|
s.id sectionId, s.name sectionTitle, s.introduction sectionDescription,
|
|
357
357
|
s.displayOrder sectionOrder, q.id questionId, q.questionText questionText,
|
|
358
|
-
q.
|
|
358
|
+
q.json questionJSON, q.displayOrder questionOrder,
|
|
359
|
+
a.id answerId, a.json answerJSON
|
|
359
360
|
FROM plans p
|
|
360
361
|
INNER JOIN versionedTemplates t ON p.versionedTemplateId = t.id
|
|
361
362
|
LEFT JOIN versionedSections s ON s.versionedTemplateId = t.id
|
|
@@ -382,6 +383,7 @@ const loadNarrativeTemplateInfo = async (rdsConnectionParams, planId) => {
|
|
|
382
383
|
section: [],
|
|
383
384
|
};
|
|
384
385
|
results.forEach((row) => {
|
|
386
|
+
var _a;
|
|
385
387
|
if (row.sectionId !== null && row.sectionId !== undefined) {
|
|
386
388
|
// Sections may have several rows in the results, so we need to check if we
|
|
387
389
|
// already have the section defined.
|
|
@@ -399,18 +401,14 @@ const loadNarrativeTemplateInfo = async (rdsConnectionParams, planId) => {
|
|
|
399
401
|
narrative.section.push(curSection);
|
|
400
402
|
}
|
|
401
403
|
if (row.questionId !== null && row.questionId !== undefined) {
|
|
402
|
-
const
|
|
403
|
-
|
|
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
|
-
}
|
|
404
|
+
const questionType = ((_a = row.questionJSON) === null || _a === void 0 ? void 0 : _a.type) || 'textArea';
|
|
405
|
+
const defaultAnswer = types_1.AnswerDefaultMap[questionType] || types_1.DefaultTextAreaAnswer;
|
|
408
406
|
// Every row in the results represents a single question/answer pair
|
|
409
407
|
curSection.question.push({
|
|
410
408
|
id: row.questionId,
|
|
411
409
|
text: row.questionText,
|
|
412
410
|
order: row.questionOrder !== null ? row.questionOrder : 0,
|
|
413
|
-
answer:
|
|
411
|
+
answer: row.answerJSON !== null && row.answerJSON !== undefined
|
|
414
412
|
? {
|
|
415
413
|
id: row.answerId,
|
|
416
414
|
json: row.answerJSON
|
|
@@ -888,6 +886,7 @@ const validateDMPToolExtensions = (logger, dmpId, dmp) => {
|
|
|
888
886
|
const msg = `Invalid DMP Tool extensions: ${validationErrors.join('; ')}`;
|
|
889
887
|
logger.warn({ dmpId }, msg);
|
|
890
888
|
logger.warn({ dmp }, 'Full DMP Tool extensions');
|
|
889
|
+
console.log(validationErrors);
|
|
891
890
|
throw new DMPValidationError(msg);
|
|
892
891
|
}
|
|
893
892
|
return dmp;
|
package/dist/sqs.d.ts
CHANGED
|
@@ -13,7 +13,9 @@ export interface SendMessageResponse {
|
|
|
13
13
|
* @param detailType The type of message
|
|
14
14
|
* @param detail The payload of the message (will be accessible to the invoked resource)
|
|
15
15
|
* @param region The region to publish the message in. Defaults to 'us-west-2'.
|
|
16
|
+
* @param useTLS Whether to use TLS when sending the message. Defaults to true.
|
|
17
|
+
* Should be false when running in a local development environment.
|
|
16
18
|
* @returns A SendMessageResponse object containing the status code and message info.
|
|
17
19
|
* @throws Error if there was an error sending the message
|
|
18
20
|
*/
|
|
19
|
-
export declare const sendMessage: (logger: Logger, queueURL: string, source: string, detailType: string, details: Record<string, unknown>, region?: string) => Promise<SendMessageResponse>;
|
|
21
|
+
export declare const sendMessage: (logger: Logger, queueURL: string, source: string, detailType: string, details: Record<string, unknown>, region?: string, useTLS?: boolean) => Promise<SendMessageResponse>;
|
package/dist/sqs.js
CHANGED
|
@@ -12,15 +12,23 @@ const general_1 = require("./general");
|
|
|
12
12
|
* @param detailType The type of message
|
|
13
13
|
* @param detail The payload of the message (will be accessible to the invoked resource)
|
|
14
14
|
* @param region The region to publish the message in. Defaults to 'us-west-2'.
|
|
15
|
+
* @param useTLS Whether to use TLS when sending the message. Defaults to true.
|
|
16
|
+
* Should be false when running in a local development environment.
|
|
15
17
|
* @returns A SendMessageResponse object containing the status code and message info.
|
|
16
18
|
* @throws Error if there was an error sending the message
|
|
17
19
|
*/
|
|
18
|
-
const sendMessage = async (logger, queueURL, source, detailType, details, region = 'us-west-2'
|
|
20
|
+
const sendMessage = async (logger, queueURL, source, detailType, details, region = 'us-west-2', useTLS = true // Should be false when running in a local dev environment
|
|
21
|
+
) => {
|
|
19
22
|
var _a, _b;
|
|
20
23
|
let errMsg = '';
|
|
21
24
|
if (logger && queueURL) {
|
|
22
25
|
// Create a new SQS client instance
|
|
23
|
-
const client = new client_sqs_1.SQSClient({
|
|
26
|
+
const client = new client_sqs_1.SQSClient({
|
|
27
|
+
region,
|
|
28
|
+
// These should be false when running in a local dev environment
|
|
29
|
+
useQueueUrlAsEndpoint: useTLS || true,
|
|
30
|
+
tls: useTLS || true,
|
|
31
|
+
});
|
|
24
32
|
logger.debug({ queueURL, source, detailType, details }, 'Sending message');
|
|
25
33
|
try {
|
|
26
34
|
// Send the message
|
package/package.json
CHANGED