38 lines
1.3 KiB
JavaScript
38 lines
1.3 KiB
JavaScript
// API source duplication helpers.
|
|
|
|
function buildDuplicateApiSourceName(sourceName) {
|
|
const baseName = 'Copy of ' + String(sourceName || '').trim();
|
|
return baseName;
|
|
}
|
|
|
|
function buildDuplicateApiSource(apiSource, duplicateName) {
|
|
return Object.assign({}, apiSource, {
|
|
id: null,
|
|
name: duplicateName,
|
|
apiUrl: apiSource.api_url || '',
|
|
lastPulledAt: null,
|
|
lastPullError: '',
|
|
lastResponseStatus: null,
|
|
lastResponseContentType: '',
|
|
lastResponseJson: '',
|
|
authMethod: apiSource.auth_method || 'none',
|
|
authUsername: apiSource.auth_username || '',
|
|
authPassword: apiSource.auth_password || '',
|
|
authBearerToken: apiSource.auth_bearer_token || '',
|
|
authHeaderName: apiSource.auth_header_name || 'X-API-Key',
|
|
authHeaderValue: apiSource.auth_header_value || '',
|
|
requestMethod: apiSource.request_method || 'GET',
|
|
requestBodyJson: apiSource.request_body_json || '',
|
|
tokenUrl: apiSource.token_url || '',
|
|
tokenRequestBodyJson: apiSource.token_request_body_json || '',
|
|
tokenResponsePath: apiSource.token_response_path || 'access_token',
|
|
tokenHeaderName: apiSource.token_header_name || 'Authorization',
|
|
tokenHeaderPrefix: apiSource.token_header_prefix || 'Bearer',
|
|
itemsPath: apiSource.items_path || ''
|
|
});
|
|
}
|
|
|
|
module.exports = {
|
|
buildDuplicateApiSourceName,
|
|
buildDuplicateApiSource
|
|
}; |