@cumulus/api-client
Version:
API client for working with the Cumulus archive API
129 lines • 5.86 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.getCollections = exports.getCollection = exports.deleteCollection = exports.updateCollection = exports.createCollection = void 0;
const cumulusApiClient_1 = require("./cumulusApiClient");
/**
* POST /collections
*
* @param {Object} params - params
* @param {string} params.prefix - the prefix configured for the stack
* @param {Object} params.collection - collection object to add to the database
* @param {Function} params.callback - async function to invoke the api lambda
* that takes a prefix / user payload. Defaults
* to cumulusApiClient.invokeApi
* @returns {Promise<Object>} - the response from the callback
*/
const createCollection = async (params) => {
const { prefix, collection, callback = cumulusApiClient_1.invokeApi } = params;
return await callback({
prefix,
payload: {
httpMethod: 'POST',
resource: '/{proxy+}',
headers: { 'Content-Type': 'application/json' },
path: '/collections',
body: JSON.stringify(collection),
},
});
};
exports.createCollection = createCollection;
/**
* PUT /collections/{collectionName}/{collectionVersion}
*
* @param {Object} params - params
* @param {string} params.prefix - the prefix configured for the stack
* @param {Object} params.collection - collection object to update in the database
* @param {Function} params.callback - async function to invoke the api lambda
* that takes a prefix / user payload. Defaults
* to cumulusApiClient.invokeApi
* @returns {Promise<Object>} - the response from the callback
*/
const updateCollection = async (params) => {
const { prefix, collection, callback = cumulusApiClient_1.invokeApi, } = params;
return await callback({
prefix,
payload: {
httpMethod: 'PUT',
resource: '/{proxy+}',
headers: { 'Content-Type': 'application/json' },
path: `/collections/${encodeURIComponent(collection.name)}/${encodeURIComponent(collection.version)}`,
body: JSON.stringify(collection),
},
});
};
exports.updateCollection = updateCollection;
/**
* DELETE /collections/{collectionName}/{collectionVersion}
*
* @param {Object} params - params
* @param {string} params.prefix - the prefix configured for the stack
* @param {Object} params.collectionVersion - name of collection to delete
* @param {Object} params.collectionName - version of collection to delete
* @param {Function} params.callback - async function to invoke the api lambda
* that takes a prefix / user payload. Defaults
* to cumulusApiClient.invokeApi
* @returns {Promise<Object>} - the response from the callback
*/
const deleteCollection = async (params) => {
const { prefix, collectionName, collectionVersion, callback = cumulusApiClient_1.invokeApi, } = params;
return await callback({
prefix,
payload: {
httpMethod: 'DELETE',
resource: '/{proxy+}',
path: `/collections/${encodeURIComponent(collectionName)}/${encodeURIComponent(collectionVersion)}`,
},
});
};
exports.deleteCollection = deleteCollection;
/**
* Get a collection from Cumulus via the API lambda
* GET /collections/{vollectionName}/{collectionVersion}
*
* @param {Object} params - params
* @param {string} params.prefix - the prefix configured for the stack
* @param {Object} params.collectionVersion - name of collection to get
* @param {Object} params.collectionName - version of collection to get
* @param {Function} params.callback - async function to invoke the api lambda
* that takes a prefix / user payload. Defaults
* to cumulusApiClient.invokeApi
* @returns {Promise<Object>} - the response from the callback
*/
const getCollection = async (params) => {
const { prefix, collectionName, collectionVersion, callback = cumulusApiClient_1.invokeApi, } = params;
const returnedCollection = await callback({
prefix,
payload: {
httpMethod: 'GET',
resource: '/{proxy+}',
path: `/collections/${encodeURIComponent(collectionName)}/${encodeURIComponent(collectionVersion)}`,
},
});
return JSON.parse(returnedCollection.body);
};
exports.getCollection = getCollection;
/**
* Get a list of collections from Cumulus via the API lambda
* GET /collections
*
* @param {Object} params - params
* @param {string} params.prefix - the prefix configured for the stack
* @param {Function} params.callback - async function to invoke the api lambda
* that takes a prefix / user payload. Defaults
* to cumulusApiClient.invokeApi
* @returns {Promise<Object>} - the response from the callback
*/
const getCollections = async (params) => {
const { prefix, query, callback = cumulusApiClient_1.invokeApi } = params;
return await callback({
prefix,
payload: {
httpMethod: 'GET',
resource: '/{proxy+}',
path: '/collections/',
queryStringParameters: query,
},
});
};
exports.getCollections = getCollections;
//# sourceMappingURL=collections.js.map
;