// API source edit page renderer. const { renderView } = require('../../../view'); const { buildApiSourceFormViewModel } = require('./form-view-model'); module.exports = function renderApiSourceEditPage(apiSource, data, message, currentUser) { const viewData = Object.assign({ lastResponseJson: '', lastPullError: '' }, data || {}); return renderView('data-sources/api-sources/form', buildApiSourceFormViewModel(Object.assign({}, apiSource, { lastResponseJson: viewData.lastResponseJson, lastPullError: viewData.lastPullError, 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 || '', tokenUrl: apiSource.token_url || '', tokenRequestBodyJson: apiSource.token_request_body_json || '', tokenResponsePath: apiSource.token_response_path || 'access_token', tokenRefreshUrl: apiSource.token_refresh_url || '', tokenRefreshRequestBodyJson: apiSource.token_refresh_request_body_json || '', tokenRefreshResponsePath: apiSource.token_refresh_response_path || 'refresh_token', tokenHeaderName: apiSource.token_header_name || 'Authorization', tokenHeaderPrefix: apiSource.token_header_prefix || 'Bearer', itemsPath: apiSource.items_path || '', requestMethod: apiSource.request_method || 'GET', requestBodyJson: apiSource.request_body_json || '' }), message, currentUser, viewData, true)); };