@cumulus/api-client
Version:
API client for working with the Cumulus archive API
187 lines • 7.3 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.rerunRule = exports.deleteRule = exports.getRule = exports.listRules = exports.updateRule = exports.replaceRule = exports.postRule = void 0;
const cumulusApiClient_1 = require("./cumulusApiClient");
/**
* Post a rule to the rules API
*
* @param {Object} params - params
* @param {string} params.prefix - the prefix configured for the stack
* @param {Object} params.rule - rule body to post
* @param {Function} params.callback - async function to invoke the api lambda
* that takes a prefix / user payload. Defaults
* to cumulusApiClient.invokeApi
* @returns {Promise<Object>} - promise that resolves to the output
* of the API lambda
*/
const postRule = async (params) => {
const { prefix, rule, callback = cumulusApiClient_1.invokeApi } = params;
return await callback({
prefix,
payload: {
httpMethod: 'POST',
resource: '/{proxy+}',
headers: {
'Content-Type': 'application/json',
},
path: '/rules',
body: JSON.stringify(rule),
},
});
};
exports.postRule = postRule;
/**
* Replace a rule via PUT request. Existing values will be removed if not specified
* or set to null.
* PUT /rules/${ruleName}
*
* @param {Object} params - params
* @param {string} params.prefix - the prefix configured for the stack
* @param {Object} params.ruleName - the rule to update
* @param {Object} params.replacementRule - complete replacement rule
* @param {Function} params.callback - async function to invoke the api lambda
* that takes a prefix / user payload. Defaults
* to cumulusApiClient.invokeApi
* @returns {Promise<Object>} - promise that resolves to the output of the API lambda
*/
const replaceRule = async (params) => {
const { prefix, ruleName, replacementRule, callback = cumulusApiClient_1.invokeApi, } = params;
return await callback({
prefix,
payload: {
httpMethod: 'PUT',
resource: '/{proxy+}',
headers: {
'Content-Type': 'application/json',
'Cumulus-API-Version': '2',
},
path: `/rules/${ruleName}`,
body: JSON.stringify(replacementRule),
},
});
};
exports.replaceRule = replaceRule;
/**
* Update a rule via PATCH request. Existing values will not be overwritten if not
* specified, null values will be removed.
*
* @param {Object} params - params
* @param {string} params.prefix - the prefix configured for the stack
* @param {Object} params.ruleName - the rule to update
* @param {Object} params.updateParams - key/value to update on the rule
* @param {Function} params.callback - async function to invoke the api lambda
* that takes a prefix / user payload. Defaults
* to cumulusApiClient.invokeApi
* @returns {Promise<Object>} - promise that resolves to the output of the API lambda
*/
const updateRule = async (params) => {
const { prefix, ruleName, updateParams, callback = cumulusApiClient_1.invokeApi, } = params;
return await callback({
prefix,
payload: {
httpMethod: 'PATCH',
resource: '/{proxy+}',
headers: {
'Content-Type': 'application/json',
'Cumulus-API-Version': '2',
},
path: `/rules/${ruleName}`,
body: JSON.stringify(updateParams),
},
});
};
exports.updateRule = updateRule;
/**
* Get a list of rules from the API
*
* @param {Object} params - params
* @param {string} params.prefix - the prefix configured for the stack
* @param {string} params.query - query params to use for listing rules
* @param {Object} params.callback - function to invoke the api lambda
* that takes a prefix / user payload
* @returns {Promise<Object>} - promise that resolves to the output of the API lambda
*/
const listRules = async (params) => {
const { prefix, query = {}, callback = cumulusApiClient_1.invokeApi } = params;
return await callback({
prefix,
payload: {
httpMethod: 'GET',
resource: '/{proxy+}',
path: '/rules',
queryStringParameters: query,
},
});
};
exports.listRules = listRules;
/**
* Get a rule definition from the API
*
* @param {Object} params - params
* @param {string} params.prefix - the prefix configured for the stack
* @param {string} params.ruleName - name of the rule
* @param {Object} params.callback - function to invoke the api lambda
* that takes a prefix / user payload
* @returns {Promise<Object>} - promise that resolves to the output of the
* API lambda
*/
const getRule = async (params) => {
const { prefix, ruleName, callback = cumulusApiClient_1.invokeApi, } = params;
return await callback({
prefix,
payload: {
httpMethod: 'GET',
resource: '/{proxy+}',
path: `/rules/${ruleName}`,
},
});
};
exports.getRule = getRule;
/**
* Delete a rule via the API
*
* @param {Object} params - params
* @param {string} params.prefix - the prefix configured for the stack
* @param {string} params.ruleName - name of the rule
* @param {Object} params.callback - function to invoke the api lambda
* that takes a prefix / user payload
* @returns {Promise<Object>} - promise that resolves to the output of the API lambda
*/
const deleteRule = async (params) => {
const { prefix, ruleName, callback = cumulusApiClient_1.invokeApi } = params;
return await callback({
prefix,
payload: {
httpMethod: 'DELETE',
resource: '/{proxy+}',
path: `/rules/${ruleName}`,
},
});
};
exports.deleteRule = deleteRule;
/**
* Rerun a rule via the API.
*
* @param {Object} params - params
* @param {string} params.prefix - the prefix configured for the stack
* @param {string} params.ruleName - the name of the rule to rerun
* @param {Object} params.updateParams - key/value to update on the rule
* @param {Object} params.callback - function to invoke the api lambda
* that takes a prefix / user payload
* @returns {Promise<Object>} - promise that resolves to the output of the API
* lambda
*/
async function rerunRule(params) {
const { prefix, ruleName, updateParams = {}, callback = cumulusApiClient_1.invokeApi, } = params;
return await (0, exports.updateRule)({
prefix,
ruleName,
updateParams: {
...updateParams,
action: 'rerun',
},
callback,
});
}
exports.rerunRule = rerunRule;
//# sourceMappingURL=rules.js.map
;