(suffix = '', opts = {})
| 52 | * @returns {any} |
| 53 | */ |
| 54 | export async function performApiRequest(suffix = '', opts = {}) { |
| 55 | const {method = 'GET', payload, headers, params, isProjectSpecific = true} = opts; |
| 56 | const url = isProjectSpecific ? `${API_ROOT}/projects/${PROJECT_ID}${suffix}` : `${API_ROOT}${suffix}`; |
| 57 | log.debug(`Sending ${method} request to ${url}`); |
| 58 | if (util.isPlainObject(payload)) { |
| 59 | log.debug(`Request payload: ${JSON.stringify(payload)}`); |
| 60 | } |
| 61 | return ( |
| 62 | await axios({ |
| 63 | method, |
| 64 | headers: { |
| 65 | Authorization: `Bearer ${API_TOKEN}`, |
| 66 | 'Content-Type': 'application/json', |
| 67 | 'User-Agent': USER_AGENT, |
| 68 | ...headers, |
| 69 | }, |
| 70 | url, |
| 71 | params, |
| 72 | data: payload, |
| 73 | }) |
| 74 | ).data; |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * @typedef {Object} ApiRequestOptions |
no test coverage detected