@cumulus/cmr-client
Advanced tools
Comparing version 1.14.1 to 1.14.2
54
CMR.js
'use strict'; | ||
const got = require('got'); | ||
const get = require('lodash.get'); | ||
const publicIp = require('public-ip'); | ||
@@ -12,3 +11,3 @@ const Logger = require('@cumulus/logger'); | ||
const getUrl = require('./getUrl'); | ||
const ValidationError = require('./ValidationError'); | ||
const { ummVersion, validateUMMG } = require('./UmmUtils'); | ||
@@ -24,53 +23,2 @@ const log = new Logger({ sender: 'cmr-client' }); | ||
/** | ||
* Find the UMM version as a decimal string. | ||
* If a version cannot be found on the input object | ||
* version 1.4 is assumed and returned. | ||
* | ||
* @param {Object} umm - UMM metadata object | ||
* @returns {string} UMM version for the given object | ||
* | ||
* @private | ||
*/ | ||
function ummVersion(umm) { | ||
return get(umm, 'MetadataSpecification.Version', '1.4'); | ||
} | ||
/** | ||
* Posts a given xml string to the validate endpoint of CMR | ||
* and promises true if valid. | ||
* | ||
* @param {string} ummMetadata - the UMM object | ||
* @param {string} identifier - the document identifier | ||
* @param {string} provider - the CMR provider | ||
* @returns {Promise<boolean>} returns true if the document is valid | ||
* | ||
* @private | ||
*/ | ||
async function validateUMMG(ummMetadata, identifier, provider) { | ||
const version = ummVersion(ummMetadata); | ||
let result; | ||
try { | ||
result = await got.post(`${getUrl('validate', provider)}granule/${identifier}`, { | ||
json: true, | ||
body: ummMetadata, | ||
headers: { | ||
Accept: 'application/json', | ||
'Content-type': `application/vnd.nasa.cmr.umm+json;version=${version}` | ||
} | ||
}); | ||
if (result.statusCode === 200) { | ||
return true; | ||
} | ||
} catch (e) { | ||
result = e.response; | ||
} | ||
throw new ValidationError( | ||
`Validation was not successful. UMM metadata Object: ${JSON.stringify(ummMetadata)}` | ||
); | ||
} | ||
/** | ||
* Returns a valid a CMR token | ||
@@ -77,0 +25,0 @@ * |
{ | ||
"name": "@cumulus/cmr-client", | ||
"version": "1.14.1", | ||
"version": "1.14.2", | ||
"engines": { | ||
@@ -34,3 +34,3 @@ "node": ">=8.10.0" | ||
"dependencies": { | ||
"@cumulus/logger": "1.14.1", | ||
"@cumulus/logger": "1.14.2", | ||
"got": "^9.6.0", | ||
@@ -49,3 +49,3 @@ "lodash.get": "^4.4.2", | ||
}, | ||
"gitHead": "21573258d928168b03b04f4a8063236414506119" | ||
"gitHead": "e76da51e3915b49e68861996be542efe40dbe3d4" | ||
} |
41703
15
646
+ Added@cumulus/logger@1.14.2(transitive)
- Removed@cumulus/logger@1.14.1(transitive)
Updated@cumulus/logger@1.14.2