@cumulus/cmr-client
Advanced tools
Comparing version 1.11.2-alpha2 to 1.12.0
37
CMR.js
@@ -36,3 +36,3 @@ 'use strict'; | ||
* Posts a given xml string to the validate endpoint of CMR | ||
* and promises true of valid. | ||
* and promises true if valid. | ||
* | ||
@@ -126,3 +126,8 @@ * @param {string} ummMetadata - the UMM object | ||
* | ||
* const cmrClient = new CMR('my-provider', 'my-clientId', 'my-username', 'my-password'); | ||
* const cmrClient = new CMR({ | ||
* provider: 'my-provider', | ||
* clientId: 'my-clientId', | ||
* username: 'my-username', | ||
* password: 'my-password' | ||
* }); | ||
*/ | ||
@@ -265,9 +270,15 @@ class CMR { | ||
* | ||
* @param {string} searchParams - the search parameters | ||
* @param {string} searchParams.provider_short_name - provider shortname | ||
* @param {string} params - the search parameters | ||
* @param {string} [format=json] - format of the response | ||
* @returns {Promise.<Object>} the CMR response | ||
*/ | ||
async searchCollections(searchParams, format = 'json') { | ||
return searchConcept('collections', searchParams, [], { 'Client-Id': this.clientId }, format); | ||
async searchCollections(params, format = 'json') { | ||
const searchParams = Object.assign({}, { provider_short_name: this.provider }, params); | ||
return searchConcept({ | ||
type: 'collections', | ||
searchParams, | ||
previousResults: [], | ||
headers: { 'Client-Id': this.clientId }, | ||
format | ||
}); | ||
} | ||
@@ -278,11 +289,17 @@ | ||
* | ||
* @param {string} searchParams - the search parameters | ||
* @param {string} searchParams.provider_short_name - provider shortname | ||
* @param {string} params - the search parameters | ||
* @param {string} [format='json'] - format of the response | ||
* @returns {Promise.<Object>} the CMR response | ||
*/ | ||
async searchGranules(searchParams, format = 'json') { | ||
return searchConcept('granules', searchParams, [], { 'Client-Id': this.clientId }, format); | ||
async searchGranules(params, format = 'json') { | ||
const searchParams = Object.assign({}, { provider_short_name: this.provider }, params); | ||
return searchConcept({ | ||
type: 'granules', | ||
searchParams, | ||
previousResults: [], | ||
headers: { 'Client-Id': this.clientId }, | ||
format | ||
}); | ||
} | ||
} | ||
module.exports = CMR; |
@@ -14,9 +14,9 @@ 'use strict'; | ||
* | ||
* const cmrSearchConceptQueue = new CMRSearchConceptQueue( | ||
* 'my-provider', | ||
* 'my-clientId', | ||
* 'granule', | ||
* {}, | ||
* 'json' | ||
* ); | ||
* const cmrSearchConceptQueue = new CMRSearchConceptQueue({ | ||
* provider: 'my-provider', | ||
* clientId: 'my-clientId', | ||
* type: 'granule', | ||
* searchParams: {}, | ||
* format: 'json' | ||
* }); | ||
*/ | ||
@@ -75,3 +75,10 @@ class CMRSearchConceptQueue { | ||
async fetchItems() { | ||
const results = await searchConcept(this.type, this.params, [], { 'Client-Id': this.clientId }, this.format, false); | ||
const results = await searchConcept({ | ||
type: this.type, | ||
searchParams: this.params, | ||
previousResults: [], | ||
headers: { 'Client-Id': this.clientId }, | ||
format: this.format, | ||
recursive: false | ||
}); | ||
this.items = results; | ||
@@ -78,0 +85,0 @@ this.params.page_num = (this.params.page_num) ? this.params.page_num + 1 : 1; |
@@ -23,15 +23,13 @@ 'use strict'; | ||
* | ||
* @param {Object} environment - process env like object | ||
* @param {string} environment.CMR_ENVIRONMENT - [optional] CMR environment to | ||
* @param {string} cmrEnvironment - [optional] CMR environment to | ||
* use valid arguments are ['OPS', 'SIT', 'UAT'], anything that is | ||
* not 'OPS' or 'SIT' will be interpreted as 'UAT' | ||
* @param {string} environment.CMR_HOST [optional] explicit host to return, if | ||
* this has a value, it overrides any values for CMR_ENVIRONMENT | ||
* @param {string} cmrHost [optional] explicit host to return, if | ||
* this has a value, it overrides any values for cmrEnvironment | ||
* @returns {string} the cmr host address | ||
*/ | ||
function getHost(environment = process.env) { | ||
const env = environment.CMR_ENVIRONMENT; | ||
if (environment.CMR_HOST) return environment.CMR_HOST; | ||
function getHost(cmrEnvironment, cmrHost) { | ||
if (cmrHost) return cmrHost; | ||
const host = ['cmr', hostId(env), 'earthdata.nasa.gov'].filter((d) => d).join('.'); | ||
const host = ['cmr', hostId(cmrEnvironment), 'earthdata.nasa.gov'].filter((d) => d).join('.'); | ||
return host; | ||
@@ -46,8 +44,10 @@ } | ||
* @param {string} cmrProvider - the CMR provider id | ||
* @param {string} cmrEnvironment - CMR environment to | ||
* use valid arguments are ['OPS', 'SIT', 'UAT'] | ||
* @param {string} cmrHost - CMR host | ||
* @returns {string} the cmr url | ||
*/ | ||
function getUrl(type, cmrProvider) { | ||
function getUrl(type, cmrProvider, cmrEnvironment, cmrHost) { | ||
let url; | ||
const host = getHost(); | ||
const env = process.env.CMR_ENVIRONMENT; | ||
const host = getHost(cmrEnvironment, cmrHost); | ||
const provider = cmrProvider; | ||
@@ -57,6 +57,6 @@ | ||
case 'token': | ||
if (env === 'OPS') { | ||
if (cmrEnvironment === 'OPS') { | ||
url = 'https://api.echo.nasa.gov/echo-rest/tokens/'; | ||
} | ||
else if (env === 'SIT') { | ||
else if (cmrEnvironment === 'SIT') { | ||
url = 'https://testbed.echo.nasa.gov/echo-rest/tokens/'; | ||
@@ -63,0 +63,0 @@ } |
@@ -18,3 +18,3 @@ 'use strict'; | ||
/** | ||
* Posts a records of any kind (collection, granule, etc) to | ||
* Posts a record of any kind (collection, granule, etc) to | ||
* CMR | ||
@@ -21,0 +21,0 @@ * |
{ | ||
"name": "@cumulus/cmr-client", | ||
"version": "1.11.2-alpha2", | ||
"version": "1.12.0", | ||
"engines": { | ||
@@ -35,3 +35,3 @@ "node": ">=8.10.0" | ||
"dependencies": { | ||
"@cumulus/logger": "^1.11.2", | ||
"@cumulus/logger": "^1.12.0", | ||
"got": "^9.6.0", | ||
@@ -49,3 +49,4 @@ "lodash.get": "^4.4.2", | ||
"sinon": "^7.1.1" | ||
} | ||
}, | ||
"gitHead": "bffc25da88e2ec3639e1b265f660ec3633d75cea" | ||
} |
@@ -37,4 +37,4 @@ # @cumulus/cmr-client | ||
* [.deleteGranule(granuleUR)](#CMR+deleteGranule) ⇒ <code>Promise.<Object></code> | ||
* [.searchCollections(searchParams, [format])](#CMR+searchCollections) ⇒ <code>Promise.<Object></code> | ||
* [.searchGranules(searchParams, [format])](#CMR+searchGranules) ⇒ <code>Promise.<Object></code> | ||
* [.searchCollections(params, [format])](#CMR+searchCollections) ⇒ <code>Promise.<Object></code> | ||
* [.searchGranules(params, [format])](#CMR+searchGranules) ⇒ <code>Promise.<Object></code> | ||
@@ -59,3 +59,8 @@ <a name="new_CMR_new"></a> | ||
const cmrClient = new CMR('my-provider', 'my-clientId', 'my-username', 'my-password'); | ||
const cmrClient = new CMR({ | ||
provider: 'my-provider', | ||
clientId: 'my-clientId', | ||
username: 'my-username', | ||
password: 'my-password' | ||
}); | ||
``` | ||
@@ -145,3 +150,3 @@ <a name="CMR+getToken"></a> | ||
#### cmrClient.searchCollections(searchParams, [format]) ⇒ <code>Promise.<Object></code> | ||
#### cmrClient.searchCollections(params, [format]) ⇒ <code>Promise.<Object></code> | ||
Search in collections | ||
@@ -154,4 +159,3 @@ | ||
| --- | --- | --- | --- | | ||
| searchParams | <code>string</code> | | the search parameters | | ||
| searchParams.provider_short_name | <code>string</code> | | provider shortname | | ||
| params | <code>string</code> | | the search parameters | | ||
| [format] | <code>string</code> | <code>"json"</code> | format of the response | | ||
@@ -161,3 +165,3 @@ | ||
#### cmrClient.searchGranules(searchParams, [format]) ⇒ <code>Promise.<Object></code> | ||
#### cmrClient.searchGranules(params, [format]) ⇒ <code>Promise.<Object></code> | ||
Search in granules | ||
@@ -170,4 +174,3 @@ | ||
| --- | --- | --- | --- | | ||
| searchParams | <code>string</code> | | the search parameters | | ||
| searchParams.provider_short_name | <code>string</code> | | provider shortname | | ||
| params | <code>string</code> | | the search parameters | | ||
| [format] | <code>string</code> | <code>"'json'"</code> | format of the response | | ||
@@ -207,9 +210,9 @@ | ||
const cmrSearchConceptQueue = new CMRSearchConceptQueue( | ||
'my-provider', | ||
'my-clientId', | ||
'granule', | ||
{}, | ||
'json' | ||
); | ||
const cmrSearchConceptQueue = new CMRSearchConceptQueue({ | ||
provider: 'my-provider', | ||
clientId: 'my-clientId', | ||
type: 'granule', | ||
searchParams: {}, | ||
format: 'json' | ||
}); | ||
``` | ||
@@ -216,0 +219,0 @@ <a name="CMRSearchConceptQueue+peek"></a> |
@@ -8,15 +8,27 @@ 'use strict'; | ||
* | ||
* @param {string} type - Concept type to search, choices: ['collections', 'granules'] | ||
* @param {Object} searchParams - CMR search parameters | ||
* @param {Object} params | ||
* @param {string} params.type - Concept type to search, choices: ['collections', 'granules'] | ||
* @param {Object} params.searchParams - CMR search parameters | ||
* Note initial searchParams.page_num should only be set if recursive is false | ||
* @param {Array} previousResults - array of results returned in previous recursive calls | ||
* to be included in the results returned | ||
* @param {Object} headers - the CMR headers | ||
* @param {string} format - format of the response | ||
* @param {boolean} recursive - indicate whether search recursively to get all the result | ||
* @param {Array} [params.previousResults=[]] - array of results returned in previous recursive | ||
* calls to be included in the results returned | ||
* @param {Object} [params.headers={}] - the CMR headers | ||
* @param {string} [params.format] - format of the response | ||
* @param {boolean} [params.recursive] - indicate whether search recursively to get all the result | ||
* @param {number} params.cmrLimit - the CMR limit | ||
* @param {number} params.cmrPageSize - the CMR page size | ||
* @returns {Promise.<Array>} - array of search results. | ||
*/ | ||
async function searchConcept(type, searchParams, previousResults = [], headers = {}, format = 'json', recursive = true) { | ||
const recordsLimit = process.env.CMR_LIMIT || 100; | ||
const pageSize = searchParams.pageSize || process.env.CMR_PAGE_SIZE || 50; | ||
async function searchConcept({ | ||
type, | ||
searchParams, | ||
previousResults = [], | ||
headers = {}, | ||
format = 'json', | ||
recursive = true, | ||
cmrLimit, | ||
cmrPageSize | ||
}) { | ||
const recordsLimit = cmrLimit || 100; | ||
const pageSize = searchParams.pageSize || cmrPageSize || 50; | ||
@@ -39,3 +51,10 @@ const defaultParams = { page_size: pageSize }; | ||
if (recursive && CMRHasMoreResults && !recordsLimitReached) { | ||
return searchConcept(type, query, fetchedResults, headers, format, recursive); | ||
return searchConcept({ | ||
type, | ||
searchParams: query, | ||
previousResults: fetchedResults, | ||
headers, | ||
format, | ||
recursive | ||
}); | ||
} | ||
@@ -42,0 +61,0 @@ return fetchedResults.slice(0, recordsLimit); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 4 instances in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
642
1
257
0
41263
1
Updated@cumulus/logger@^1.12.0