remove axios dependency from rollbar-backend
Signed-off-by: Colton Padden <colton.padden@fastmail.com>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-rollbar-backend': patch
|
||||
---
|
||||
|
||||
Replace the usage of `axios` with `node-fetch` in the Rollbar API
|
||||
@@ -33,8 +33,8 @@
|
||||
"dependencies": {
|
||||
"@backstage/backend-common": "^0.9.12",
|
||||
"@backstage/config": "^0.1.10",
|
||||
"@backstage/test-utils": "^0.1.24",
|
||||
"@types/express": "^4.17.6",
|
||||
"axios": "^0.24.0",
|
||||
"camelcase-keys": "^6.2.2",
|
||||
"compression": "^1.7.4",
|
||||
"cors": "^2.8.5",
|
||||
@@ -44,12 +44,14 @@
|
||||
"helmet": "^4.0.0",
|
||||
"lodash": "^4.17.21",
|
||||
"morgan": "^1.10.0",
|
||||
"node-fetch": "^2.6.1",
|
||||
"winston": "^3.2.1",
|
||||
"yn": "^4.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@backstage/cli": "^0.10.0",
|
||||
"@types/supertest": "^2.0.8",
|
||||
"msw": "^0.36.3",
|
||||
"supertest": "^6.1.3"
|
||||
},
|
||||
"files": [
|
||||
|
||||
@@ -14,7 +14,12 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { getRequestHeaders } from './RollbarApi';
|
||||
import { getRequestHeaders, RollbarApi } from './RollbarApi';
|
||||
import { setupRequestMockHandlers } from '@backstage/test-utils';
|
||||
import { rest } from 'msw';
|
||||
import { setupServer } from 'msw/node';
|
||||
import { getVoidLogger } from '@backstage/backend-common';
|
||||
import { RollbarProject } from './types';
|
||||
|
||||
describe('RollbarApi', () => {
|
||||
describe('getRequestHeaders', () => {
|
||||
@@ -26,4 +31,31 @@ describe('RollbarApi', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('getAllProjects', () => {
|
||||
const server = setupServer();
|
||||
setupRequestMockHandlers(server);
|
||||
|
||||
const mockBaseUrl = 'https://api.rollbar.com/api/1';
|
||||
|
||||
const mockProjects: RollbarProject[] = [
|
||||
{ id: 123, name: 'abc', accountId: 1, status: 'enabled' },
|
||||
{ id: 456, name: 'xyz', accountId: 1, status: 'enabled' },
|
||||
];
|
||||
|
||||
const setupHandlers = () => {
|
||||
server.use(
|
||||
rest.get(`${mockBaseUrl}/projects`, (_, res, ctx) => {
|
||||
return res(ctx.json({ result: mockProjects }));
|
||||
}),
|
||||
);
|
||||
};
|
||||
|
||||
it('should return all projects with a name attribute', async () => {
|
||||
setupHandlers();
|
||||
const api = new RollbarApi('my-access-token', getVoidLogger());
|
||||
const projects = await api.getAllProjects();
|
||||
expect(projects).toEqual(mockProjects);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import axios from 'axios';
|
||||
import { Logger } from 'winston';
|
||||
import camelcaseKeys from 'camelcase-keys';
|
||||
import { buildQuery } from '../util';
|
||||
@@ -25,6 +24,7 @@ import {
|
||||
RollbarProjectAccessToken,
|
||||
RollbarTopActiveItem,
|
||||
} from './types';
|
||||
import fetch from 'node-fetch';
|
||||
|
||||
const baseUrl = 'https://api.rollbar.com/api/1';
|
||||
|
||||
@@ -110,11 +110,12 @@ export class RollbarApi {
|
||||
this.logger.info(`Calling Rollbar REST API, ${fullUrl}`);
|
||||
}
|
||||
|
||||
return axios
|
||||
.get(fullUrl, getRequestHeaders(accessToken || this.accessToken || ''))
|
||||
.then(response =>
|
||||
camelcaseKeys<T>(response?.data?.result, { deep: true }),
|
||||
);
|
||||
return fetch(
|
||||
fullUrl,
|
||||
getRequestHeaders(accessToken || this.accessToken || ''),
|
||||
)
|
||||
.then(response => response.json())
|
||||
.then(json => camelcaseKeys<T>(json?.result, { deep: true }));
|
||||
}
|
||||
|
||||
private async getForProject<T>(
|
||||
|
||||
Reference in New Issue
Block a user