Remove axios (#520)

This commit is contained in:
Franck R 2022-02-14 09:26:22 +11:00 committed by GitHub
parent 160fea0e7b
commit 2dc8764be2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 83 additions and 37 deletions

View File

@ -1,6 +1,6 @@
{ {
"extension": ["ts"], "extension": ["ts"],
"spec": "src/**/*.spec.ts", "spec": "src/**/*.spec.ts",
"require": "ts-node/register", "require": ["ts-node/register", "isomorphic-fetch"],
"exit": true "exit": true
} }

View File

@ -14,6 +14,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Ran `npm audit fix`. - Ran `npm audit fix`.
- `Waku.dial` accepts protocols expected from the peer. Defaults to Waku Relay only. - `Waku.dial` accepts protocols expected from the peer. Defaults to Waku Relay only.
### Removed
- axios dependency in favour of fetch.
## [0.16.0] - 2022-01-31 ## [0.16.0] - 2022-01-31
### Changed ### Changed

54
package-lock.json generated
View File

@ -10,7 +10,6 @@
"license": "MIT OR Apache-2.0", "license": "MIT OR Apache-2.0",
"dependencies": { "dependencies": {
"@chainsafe/libp2p-noise": "^5.0.0", "@chainsafe/libp2p-noise": "^5.0.0",
"axios": "^0.21.1",
"base64url": "^3.0.1", "base64url": "^3.0.1",
"bigint-buffer": "^1.1.5", "bigint-buffer": "^1.1.5",
"debug": "^4.3.1", "debug": "^4.3.1",
@ -58,6 +57,7 @@
"eslint-plugin-prettier": "^4.0.0", "eslint-plugin-prettier": "^4.0.0",
"fast-check": "^2.14.0", "fast-check": "^2.14.0",
"gh-pages": "^3.2.3", "gh-pages": "^3.2.3",
"isomorphic-fetch": "^3.0.0",
"karma": "^6.3.12", "karma": "^6.3.12",
"karma-chrome-launcher": "^3.1.0", "karma-chrome-launcher": "^3.1.0",
"karma-env-preprocessor": "^0.1.1", "karma-env-preprocessor": "^0.1.1",
@ -2202,14 +2202,6 @@
"resolved": "https://registry.npmjs.org/aws4/-/aws4-1.11.0.tgz", "resolved": "https://registry.npmjs.org/aws4/-/aws4-1.11.0.tgz",
"integrity": "sha512-xh1Rl34h6Fi1DC2WWKfxUTVqRsNnr6LsKz2+hfwDxQJWmrx8+c7ylaqBMcHfl1U1r2dsifOvKX3LQuLNZ+XSvA==" "integrity": "sha512-xh1Rl34h6Fi1DC2WWKfxUTVqRsNnr6LsKz2+hfwDxQJWmrx8+c7ylaqBMcHfl1U1r2dsifOvKX3LQuLNZ+XSvA=="
}, },
"node_modules/axios": {
"version": "0.21.2",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.21.2.tgz",
"integrity": "sha512-87otirqUw3e8CzHTMO+/9kh/FSgXt/eVDvipijwDtEuwbkySWZ9SBm6VEubmJ/kLKEoLQV/POhxXFb66bfekfg==",
"dependencies": {
"follow-redirects": "^1.14.0"
}
},
"node_modules/balanced-match": { "node_modules/balanced-match": {
"version": "1.0.2", "version": "1.0.2",
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz",
@ -4974,6 +4966,7 @@
"version": "1.14.8", "version": "1.14.8",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.8.tgz", "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.8.tgz",
"integrity": "sha512-1x0S9UVJHsQprFcEC/qnNzBLcIxsjAV905f/UkQxbclCsoTWlacCNOpQa/anodLl2uaEKFhfWOvM2Qg77+15zA==", "integrity": "sha512-1x0S9UVJHsQprFcEC/qnNzBLcIxsjAV905f/UkQxbclCsoTWlacCNOpQa/anodLl2uaEKFhfWOvM2Qg77+15zA==",
"dev": true,
"funding": [ "funding": [
{ {
"type": "individual", "type": "individual",
@ -6336,6 +6329,16 @@
"node": ">=0.10.0" "node": ">=0.10.0"
} }
}, },
"node_modules/isomorphic-fetch": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/isomorphic-fetch/-/isomorphic-fetch-3.0.0.tgz",
"integrity": "sha512-qvUtwJ3j6qwsF3jLxkZ72qCgjMysPzDfeV240JHiGZsANBYd+EEuu35v7dfrJ9Up0Ak07D7GGSkGhCHTqg/5wA==",
"dev": true,
"dependencies": {
"node-fetch": "^2.6.1",
"whatwg-fetch": "^3.4.1"
}
},
"node_modules/isstream": { "node_modules/isstream": {
"version": "0.1.2", "version": "0.1.2",
"resolved": "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz", "resolved": "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz",
@ -11218,6 +11221,12 @@
"acorn": "^8" "acorn": "^8"
} }
}, },
"node_modules/whatwg-fetch": {
"version": "3.6.2",
"resolved": "https://registry.npmjs.org/whatwg-fetch/-/whatwg-fetch-3.6.2.tgz",
"integrity": "sha512-bJlen0FcuU/0EMLrdbJ7zOnW6ITZLrZMIarMUVmdKtsGvZna8vxKYaexICWPfZ8qwf9fzNq+UEIZrnSaApt6RA==",
"dev": true
},
"node_modules/wherearewe": { "node_modules/wherearewe": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/wherearewe/-/wherearewe-1.0.0.tgz", "resolved": "https://registry.npmjs.org/wherearewe/-/wherearewe-1.0.0.tgz",
@ -13338,14 +13347,6 @@
"resolved": "https://registry.npmjs.org/aws4/-/aws4-1.11.0.tgz", "resolved": "https://registry.npmjs.org/aws4/-/aws4-1.11.0.tgz",
"integrity": "sha512-xh1Rl34h6Fi1DC2WWKfxUTVqRsNnr6LsKz2+hfwDxQJWmrx8+c7ylaqBMcHfl1U1r2dsifOvKX3LQuLNZ+XSvA==" "integrity": "sha512-xh1Rl34h6Fi1DC2WWKfxUTVqRsNnr6LsKz2+hfwDxQJWmrx8+c7ylaqBMcHfl1U1r2dsifOvKX3LQuLNZ+XSvA=="
}, },
"axios": {
"version": "0.21.2",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.21.2.tgz",
"integrity": "sha512-87otirqUw3e8CzHTMO+/9kh/FSgXt/eVDvipijwDtEuwbkySWZ9SBm6VEubmJ/kLKEoLQV/POhxXFb66bfekfg==",
"requires": {
"follow-redirects": "^1.14.0"
}
},
"balanced-match": { "balanced-match": {
"version": "1.0.2", "version": "1.0.2",
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz",
@ -15518,7 +15519,8 @@
"follow-redirects": { "follow-redirects": {
"version": "1.14.8", "version": "1.14.8",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.8.tgz", "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.8.tgz",
"integrity": "sha512-1x0S9UVJHsQprFcEC/qnNzBLcIxsjAV905f/UkQxbclCsoTWlacCNOpQa/anodLl2uaEKFhfWOvM2Qg77+15zA==" "integrity": "sha512-1x0S9UVJHsQprFcEC/qnNzBLcIxsjAV905f/UkQxbclCsoTWlacCNOpQa/anodLl2uaEKFhfWOvM2Qg77+15zA==",
"dev": true
}, },
"foreach": { "foreach": {
"version": "2.0.5", "version": "2.0.5",
@ -16481,6 +16483,16 @@
"integrity": "sha1-TkMekrEalzFjaqH5yNHMvP2reN8=", "integrity": "sha1-TkMekrEalzFjaqH5yNHMvP2reN8=",
"dev": true "dev": true
}, },
"isomorphic-fetch": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/isomorphic-fetch/-/isomorphic-fetch-3.0.0.tgz",
"integrity": "sha512-qvUtwJ3j6qwsF3jLxkZ72qCgjMysPzDfeV240JHiGZsANBYd+EEuu35v7dfrJ9Up0Ak07D7GGSkGhCHTqg/5wA==",
"dev": true,
"requires": {
"node-fetch": "^2.6.1",
"whatwg-fetch": "^3.4.1"
}
},
"isstream": { "isstream": {
"version": "0.1.2", "version": "0.1.2",
"resolved": "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz", "resolved": "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz",
@ -20292,6 +20304,12 @@
"integrity": "sha512-cp5qdmHnu5T8wRg2G3vZZHoJPN14aqQ89SyQ11NpGH5zEMDCclt49rzo+MaRazk7/UeILhAI+/sEtcM+7Fr0nw==", "integrity": "sha512-cp5qdmHnu5T8wRg2G3vZZHoJPN14aqQ89SyQ11NpGH5zEMDCclt49rzo+MaRazk7/UeILhAI+/sEtcM+7Fr0nw==",
"dev": true "dev": true
}, },
"whatwg-fetch": {
"version": "3.6.2",
"resolved": "https://registry.npmjs.org/whatwg-fetch/-/whatwg-fetch-3.6.2.tgz",
"integrity": "sha512-bJlen0FcuU/0EMLrdbJ7zOnW6ITZLrZMIarMUVmdKtsGvZna8vxKYaexICWPfZ8qwf9fzNq+UEIZrnSaApt6RA==",
"dev": true
},
"wherearewe": { "wherearewe": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/wherearewe/-/wherearewe-1.0.0.tgz", "resolved": "https://registry.npmjs.org/wherearewe/-/wherearewe-1.0.0.tgz",

View File

@ -57,7 +57,6 @@
}, },
"dependencies": { "dependencies": {
"@chainsafe/libp2p-noise": "^5.0.0", "@chainsafe/libp2p-noise": "^5.0.0",
"axios": "^0.21.1",
"base64url": "^3.0.1", "base64url": "^3.0.1",
"bigint-buffer": "^1.1.5", "bigint-buffer": "^1.1.5",
"debug": "^4.3.1", "debug": "^4.3.1",
@ -105,6 +104,7 @@
"eslint-plugin-prettier": "^4.0.0", "eslint-plugin-prettier": "^4.0.0",
"fast-check": "^2.14.0", "fast-check": "^2.14.0",
"gh-pages": "^3.2.3", "gh-pages": "^3.2.3",
"isomorphic-fetch": "^3.0.0",
"karma": "^6.3.12", "karma": "^6.3.12",
"karma-chrome-launcher": "^3.1.0", "karma-chrome-launcher": "^3.1.0",
"karma-env-preprocessor": "^0.1.1", "karma-env-preprocessor": "^0.1.1",

View File

@ -15,7 +15,6 @@
* @throws If the remote host is unreachable or the response cannot be parsed * @throws If the remote host is unreachable or the response cannot be parsed
* according to the passed _path_. * according to the passed _path_.
*/ */
import axios from "axios";
import debug from "debug"; import debug from "debug";
import { Multiaddr } from "multiaddr"; import { Multiaddr } from "multiaddr";
@ -33,11 +32,8 @@ export async function getNodesFromHostedJson(
return []; return [];
} }
const res = await axios.get(url, { const res = await fetch(url);
headers: { "Content-Type": "application/json" }, let nodes = await res.json();
});
let nodes = res.data;
for (const prop of path) { for (const prop of path) {
if (nodes[prop] === undefined) { if (nodes[prop] === undefined) {

View File

@ -1,6 +1,13 @@
import { expect } from "chai"; import { expect } from "chai";
import { getPseudoRandomSubset } from "./index"; import { getNodesFromHostedJson, getPseudoRandomSubset } from "./index";
declare global {
interface Window {
__env__?: any;
}
}
declare let window: Window | undefined;
describe("Discovery", () => { describe("Discovery", () => {
it("returns all values when wanted number matches available values", function () { it("returns all values when wanted number matches available values", function () {
@ -33,3 +40,25 @@ describe("Discovery", () => {
expect(res.length).to.eq(2); expect(res.length).to.eq(2);
}); });
}); });
describe("Discovery [live data]", function () {
before(function () {
if (
process.env.CI ||
(typeof window !== "undefined" && window?.__env__?.CI)
) {
this.skip();
}
});
it("Returns nodes from default hosted JSON [live data]", async function () {
const res = await getNodesFromHostedJson(
["fleets", "wakuv2.prod", "waku-websocket"],
"https://fleets.status.im/",
3
);
expect(res.length).to.eq(3);
expect(res[0].toString()).to.not.be.undefined;
});
});

View File

@ -6,7 +6,6 @@
import { ChildProcess, spawn } from "child_process"; import { ChildProcess, spawn } from "child_process";
import appRoot from "app-root-path"; import appRoot from "app-root-path";
import axios from "axios";
import debug from "debug"; import debug from "debug";
import { Multiaddr, multiaddr } from "multiaddr"; import { Multiaddr, multiaddr } from "multiaddr";
import PeerId from "peer-id"; import PeerId from "peer-id";
@ -333,6 +332,7 @@ export class NimWaku {
return { peerId: this.peerId, multiaddrWithId: this.multiaddrWithId }; return { peerId: this.peerId, multiaddrWithId: this.multiaddrWithId };
} }
const res = await this.info(); const res = await this.info();
console.log(res);
this.multiaddrWithId = res.listenAddresses this.multiaddrWithId = res.listenAddresses
.map((ma) => multiaddr(ma)) .map((ma) => multiaddr(ma))
.find((ma) => ma.protoNames().includes("ws")); .find((ma) => ma.protoNames().includes("ws"));
@ -351,20 +351,19 @@ export class NimWaku {
method: string, method: string,
params: Array<string | number | unknown> params: Array<string | number | unknown>
): Promise<T> { ): Promise<T> {
const res = await axios.post( const res = await fetch(this.rpcUrl, {
this.rpcUrl, method: "POST",
{ body: JSON.stringify({
jsonrpc: "2.0", jsonrpc: "2.0",
id: 1, id: 1,
method, method,
params, params,
}, }),
{ headers: new Headers({ "Content-Type": "application/json" }),
headers: { "Content-Type": "application/json" }, });
}
);
return res.data.result; const json = await res.json();
return json.result;
} }
private checkProcess(): void { private checkProcess(): void {