Skip to content

Commit

Permalink
Remove axios 0.23.0
Browse files Browse the repository at this point in the history
Axios is a library used for convenience. The native fetch browser API is
sufficient for the limited use case this library has.
  • Loading branch information
thibmeu authored and armfazh committed Dec 4, 2023
1 parent dd0ff5d commit ed2df5d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 54 deletions.
41 changes: 0 additions & 41 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
},
"dependencies": {
"asn1-parser": "1.1.8",
"axios": "0.23.0",
"buffer": "6.0.3",
"keccak": "3.0.2",
"qs": "6.10.3",
Expand Down
12 changes: 6 additions & 6 deletions src/background/providers/cloudflare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { Callbacks, Provider } from '.';

import { Storage } from '../storage';
import Token from '../token';
import axios from 'axios';
import qs from 'qs';

const ISSUE_HEADER_NAME = 'cf-chl-bypass';
Expand Down Expand Up @@ -91,7 +90,7 @@ export class CloudflareProvider implements Provider {
}

// Download the commitment
const { data } = await axios.get<Response>(COMMITMENT_URL);
const data: Response = await fetch(COMMITMENT_URL).then((r) => r.json());
const commitment = data.CF[version as string];
if (commitment === undefined) {
throw new Error(`No commitment for the version ${version} is found`);
Expand Down Expand Up @@ -143,12 +142,13 @@ export class CloudflareProvider implements Provider {
[ISSUE_HEADER_NAME]: CloudflareProvider.ID.toString(),
};

const response = await axios.post<string, { data: string }>(url, body, {
const response = await fetch(url, {
method: 'POST',
body,
headers,
responseType: 'text',
});
}).then((r) => r.text());

const { signatures } = qs.parse(response.data);
const { signatures } = qs.parse(response);
if (signatures === undefined) {
throw new Error('There is no signatures parameter in the issuance response.');
}
Expand Down
12 changes: 6 additions & 6 deletions src/background/providers/hcaptcha.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import * as voprf from '../voprf';
import { Callbacks, Provider } from '.';
import Token from '../token';
import { Storage } from '../storage';
import axios from 'axios';
import qs from 'qs';

const COMMITMENT_URL =
Expand Down Expand Up @@ -107,7 +106,7 @@ export class HcaptchaProvider implements Provider {
}

// Download the commitment
const { data } = await axios.get<Response>(COMMITMENT_URL);
const data: Response = await fetch(COMMITMENT_URL).then((r) => r.json());
const commitment = data.HC[version as string];
if (commitment === undefined) {
throw new Error(`No commitment for the version ${version} is found`);
Expand Down Expand Up @@ -135,12 +134,13 @@ export class HcaptchaProvider implements Provider {
'cf-chl-bypass': this.getID().toString(),
};

const response = await axios.post<string, { data: string }>(url, requestBody, {
const response = await fetch(url, {
method: 'POST',
body: requestBody,
headers,
responseType: 'text',
});
}).then((r) => r.text());

const { signatures } = qs.parse(response.data);
const { signatures } = qs.parse(response);
if (signatures === undefined) {
throw new Error('There is no signatures parameter in the issuance response.');
}
Expand Down

0 comments on commit ed2df5d

Please sign in to comment.