@dmptool/utils 1.0.28 → 1.0.29

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/general.d.ts CHANGED
@@ -20,6 +20,13 @@ export declare const toErrorMessage: (error: unknown) => string;
20
20
  * @returns a URL with the protocol converted to https
21
21
  */
22
22
  export declare const normaliseHttpProtocol: (input: string | null) => string | null;
23
+ /**
24
+ * Function to determine if the string is a valid date / time
25
+ *
26
+ * @param dateString the date string to validate
27
+ * @returns true if the date string is valid, false otherwise
28
+ */
29
+ export declare const isValidDate: (dateString: string) => boolean;
23
30
  /**
24
31
  *Function to return the current date.
25
32
  *
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.normaliseHttpProtocol = exports.toErrorMessage = exports.EnvironmentEnum = void 0;
3
+ exports.areEqual = 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
  */
@@ -35,6 +35,18 @@ const normaliseHttpProtocol = (input) => {
35
35
  return input.trim().replace(/^http:\/\//, 'https://');
36
36
  };
37
37
  exports.normaliseHttpProtocol = normaliseHttpProtocol;
38
+ /**
39
+ * Function to determine if the string is a valid date / time
40
+ *
41
+ * @param dateString the date string to validate
42
+ * @returns true if the date string is valid, false otherwise
43
+ */
44
+ const isValidDate = (dateString) => {
45
+ const date = Date.parse(dateString);
46
+ // A valid date will return a number, an invalid one will return NaN
47
+ return !Number.isNaN(date);
48
+ };
49
+ exports.isValidDate = isValidDate;
38
50
  /**
39
51
  *Function to return the current date.
40
52
  *
package/dist/maDMP.js CHANGED
@@ -382,34 +382,38 @@ const loadNarrativeTemplateInfo = async (rdsConnectionParams, planId) => {
382
382
  section: [],
383
383
  };
384
384
  results.forEach((row) => {
385
- // Sections may have several rows in the results, so we need to check if we
386
- // already have the section defined.
387
- let curSection = narrative.section.find((s) => {
388
- return s.id === row.sectionId;
389
- });
390
- if (curSection === undefined || curSection === null) {
391
- curSection = {
392
- id: row.sectionId,
393
- title: row.sectionTitle,
394
- description: row.sectionDescription !== null ? row.sectionDescription : undefined,
395
- order: row.sectionOrder !== null ? row.sectionOrder : 0,
396
- question: [],
397
- };
398
- narrative.section.push(curSection);
385
+ if (row.sectionId !== null && row.sectionId !== undefined) {
386
+ // Sections may have several rows in the results, so we need to check if we
387
+ // already have the section defined.
388
+ let curSection = narrative.section.find((s) => {
389
+ return s.id === row.sectionId;
390
+ });
391
+ if (curSection === undefined || curSection === null) {
392
+ curSection = {
393
+ id: row.sectionId,
394
+ title: row.sectionTitle,
395
+ description: row.sectionDescription !== null ? row.sectionDescription : undefined,
396
+ order: row.sectionOrder !== null ? row.sectionOrder : 0,
397
+ question: [],
398
+ };
399
+ narrative.section.push(curSection);
400
+ }
401
+ if (row.questionId !== null && row.questionId !== undefined) {
402
+ const hasAnswer = row.answerJSON !== undefined && row.answerJSON !== null;
403
+ // Every row in the results represents a single question/answer pair
404
+ curSection.question.push({
405
+ id: row.questionId,
406
+ text: row.questionText,
407
+ order: row.questionOrder !== null ? row.questionOrder : 0,
408
+ answer: hasAnswer
409
+ ? {
410
+ id: row.answerId,
411
+ json: row.answerJSON
412
+ }
413
+ : undefined
414
+ });
415
+ }
399
416
  }
400
- const hasAnswer = row.answerJSON !== undefined && row.answerJSON !== null;
401
- // Every row in the results represents a single question/answer pair
402
- curSection.question.push({
403
- id: row.questionId,
404
- text: row.questionText,
405
- order: row.questionOrder !== null ? row.questionOrder : 0,
406
- answer: hasAnswer
407
- ? {
408
- id: row.answerId,
409
- json: row.answerJSON
410
- }
411
- : undefined
412
- });
413
417
  });
414
418
  return narrative;
415
419
  };
@@ -525,7 +529,7 @@ const buildContributors = (applicationName, env, planId, projectId, members, def
525
529
  * @returns the DMP metadata with extensions from the DMP Tool
526
530
  */
527
531
  const buildDMPToolExtensions = async (rdsConnectionParams, applicationName, domainName, plan, project, funding) => {
528
- var _a, _b, _c, _d, _e, _f;
532
+ var _a, _b, _c, _d;
529
533
  const extensions = {
530
534
  rda_schema_version: types_1.RDA_COMMON_STANDARD_VERSION,
531
535
  // Ignoring the `!` assertion here because we know we check the env variable
@@ -533,8 +537,8 @@ const buildDMPToolExtensions = async (rdsConnectionParams, applicationName, doma
533
537
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
534
538
  provenance: applicationName,
535
539
  featured: plan.featured ? 'yes' : 'no',
536
- privacy: (_b = (_a = plan.visibility) === null || _a === void 0 ? void 0 : _a.toLowerCase()) !== null && _b !== void 0 ? _b : 'private',
537
- status: (_d = (_c = plan.status) === null || _c === void 0 ? void 0 : _c.toLowerCase()) !== null && _d !== void 0 ? _d : 'draft',
540
+ privacy: plan.visibility === 'PUBLIC' ? 'public' : 'private',
541
+ status: (_b = (_a = plan.status) === null || _a === void 0 ? void 0 : _a.toLowerCase()) !== null && _b !== void 0 ? _b : 'draft',
538
542
  };
539
543
  // Generate the DMP Narrative
540
544
  const narrative = await loadNarrativeTemplateInfo(rdsConnectionParams, plan.id);
@@ -570,7 +574,7 @@ const buildDMPToolExtensions = async (rdsConnectionParams, applicationName, doma
570
574
  funder_id: funderId,
571
575
  project_identifier: {
572
576
  identifier: funding.funderProjectNumber,
573
- type: ((_e = funding.funderProjectNumber) === null || _e === void 0 ? void 0 : _e.startsWith('http'))
577
+ type: ((_c = funding.funderProjectNumber) === null || _c === void 0 ? void 0 : _c.startsWith('http'))
574
578
  ? maDMPTypes_1.StandardIdentifierType.URL
575
579
  : maDMPTypes_1.StandardIdentifierType.OTHER
576
580
  }
@@ -585,7 +589,7 @@ const buildDMPToolExtensions = async (rdsConnectionParams, applicationName, doma
585
589
  funder_id: funderId,
586
590
  opportunity_identifier: {
587
591
  identifier: funding.funderOpportunityNumber,
588
- type: ((_f = funding.funderOpportunityNumber) === null || _f === void 0 ? void 0 : _f.startsWith('http'))
592
+ type: ((_d = funding.funderOpportunityNumber) === null || _d === void 0 ? void 0 : _d.startsWith('http'))
589
593
  ? maDMPTypes_1.StandardIdentifierType.URL
590
594
  : maDMPTypes_1.StandardIdentifierType.OTHER
591
595
  }
@@ -608,8 +612,9 @@ const buildDMPToolExtensions = async (rdsConnectionParams, applicationName, doma
608
612
  extensions.funding_opportunity = [funderOpportunity];
609
613
  }
610
614
  if (!(0, general_1.isNullOrUndefined)(narrative)) {
615
+ const id = plan.dmpId.replace('https://doi.org/', '');
611
616
  extensions.narrative = {
612
- download_url: `https://${domainName}/dmps/${plan.dmpId}/narrative`,
617
+ download_url: `https://${domainName}/dmps/${id}/narrative`,
613
618
  template: narrative
614
619
  };
615
620
  }
@@ -663,8 +668,8 @@ const buildProject = (applicationName, planId, project, funding) => {
663
668
  return {
664
669
  title: project.title,
665
670
  description: (_c = project.abstractText) !== null && _c !== void 0 ? _c : undefined,
666
- start: (_d = project.startDate) !== null && _d !== void 0 ? _d : undefined,
667
- end: (_e = project.endDate) !== null && _e !== void 0 ? _e : undefined,
671
+ start: (0, general_1.isValidDate)((_d = project.startDate) !== null && _d !== void 0 ? _d : '') ? project.startDate : undefined,
672
+ end: (0, general_1.isValidDate)((_e = project.endDate) !== null && _e !== void 0 ? _e : '') ? project.endDate : undefined,
668
673
  project_id: [{
669
674
  identifier: internalIdBase(applicationName, project.id, planId),
670
675
  type: 'other'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dmptool/utils",
3
- "version": "1.0.28",
3
+ "version": "1.0.29",
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",