mirror of https://github.com/waku-org/js-waku.git
Remove axios (#520)
This commit is contained in:
parent
160fea0e7b
commit
2dc8764be2
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"extension": ["ts"],
|
||||
"spec": "src/**/*.spec.ts",
|
||||
"require": "ts-node/register",
|
||||
"require": ["ts-node/register", "isomorphic-fetch"],
|
||||
"exit": true
|
||||
}
|
||||
|
|
|
@ -14,6 +14,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
- Ran `npm audit fix`.
|
||||
- `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
|
||||
|
||||
### Changed
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
"license": "MIT OR Apache-2.0",
|
||||
"dependencies": {
|
||||
"@chainsafe/libp2p-noise": "^5.0.0",
|
||||
"axios": "^0.21.1",
|
||||
"base64url": "^3.0.1",
|
||||
"bigint-buffer": "^1.1.5",
|
||||
"debug": "^4.3.1",
|
||||
|
@ -58,6 +57,7 @@
|
|||
"eslint-plugin-prettier": "^4.0.0",
|
||||
"fast-check": "^2.14.0",
|
||||
"gh-pages": "^3.2.3",
|
||||
"isomorphic-fetch": "^3.0.0",
|
||||
"karma": "^6.3.12",
|
||||
"karma-chrome-launcher": "^3.1.0",
|
||||
"karma-env-preprocessor": "^0.1.1",
|
||||
|
@ -2202,14 +2202,6 @@
|
|||
"resolved": "https://registry.npmjs.org/aws4/-/aws4-1.11.0.tgz",
|
||||
"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": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz",
|
||||
|
@ -4974,6 +4966,7 @@
|
|||
"version": "1.14.8",
|
||||
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.8.tgz",
|
||||
"integrity": "sha512-1x0S9UVJHsQprFcEC/qnNzBLcIxsjAV905f/UkQxbclCsoTWlacCNOpQa/anodLl2uaEKFhfWOvM2Qg77+15zA==",
|
||||
"dev": true,
|
||||
"funding": [
|
||||
{
|
||||
"type": "individual",
|
||||
|
@ -6336,6 +6329,16 @@
|
|||
"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": {
|
||||
"version": "0.1.2",
|
||||
"resolved": "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz",
|
||||
|
@ -11218,6 +11221,12 @@
|
|||
"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": {
|
||||
"version": "1.0.0",
|
||||
"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",
|
||||
"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": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz",
|
||||
|
@ -15518,7 +15519,8 @@
|
|||
"follow-redirects": {
|
||||
"version": "1.14.8",
|
||||
"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": {
|
||||
"version": "2.0.5",
|
||||
|
@ -16481,6 +16483,16 @@
|
|||
"integrity": "sha1-TkMekrEalzFjaqH5yNHMvP2reN8=",
|
||||
"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": {
|
||||
"version": "0.1.2",
|
||||
"resolved": "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz",
|
||||
|
@ -20292,6 +20304,12 @@
|
|||
"integrity": "sha512-cp5qdmHnu5T8wRg2G3vZZHoJPN14aqQ89SyQ11NpGH5zEMDCclt49rzo+MaRazk7/UeILhAI+/sEtcM+7Fr0nw==",
|
||||
"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": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/wherearewe/-/wherearewe-1.0.0.tgz",
|
||||
|
|
|
@ -57,7 +57,6 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"@chainsafe/libp2p-noise": "^5.0.0",
|
||||
"axios": "^0.21.1",
|
||||
"base64url": "^3.0.1",
|
||||
"bigint-buffer": "^1.1.5",
|
||||
"debug": "^4.3.1",
|
||||
|
@ -105,6 +104,7 @@
|
|||
"eslint-plugin-prettier": "^4.0.0",
|
||||
"fast-check": "^2.14.0",
|
||||
"gh-pages": "^3.2.3",
|
||||
"isomorphic-fetch": "^3.0.0",
|
||||
"karma": "^6.3.12",
|
||||
"karma-chrome-launcher": "^3.1.0",
|
||||
"karma-env-preprocessor": "^0.1.1",
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
* @throws If the remote host is unreachable or the response cannot be parsed
|
||||
* according to the passed _path_.
|
||||
*/
|
||||
import axios from "axios";
|
||||
import debug from "debug";
|
||||
import { Multiaddr } from "multiaddr";
|
||||
|
||||
|
@ -33,11 +32,8 @@ export async function getNodesFromHostedJson(
|
|||
return [];
|
||||
}
|
||||
|
||||
const res = await axios.get(url, {
|
||||
headers: { "Content-Type": "application/json" },
|
||||
});
|
||||
|
||||
let nodes = res.data;
|
||||
const res = await fetch(url);
|
||||
let nodes = await res.json();
|
||||
|
||||
for (const prop of path) {
|
||||
if (nodes[prop] === undefined) {
|
||||
|
|
|
@ -1,6 +1,13 @@
|
|||
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", () => {
|
||||
it("returns all values when wanted number matches available values", function () {
|
||||
|
@ -33,3 +40,25 @@ describe("Discovery", () => {
|
|||
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;
|
||||
});
|
||||
});
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
import { ChildProcess, spawn } from "child_process";
|
||||
|
||||
import appRoot from "app-root-path";
|
||||
import axios from "axios";
|
||||
import debug from "debug";
|
||||
import { Multiaddr, multiaddr } from "multiaddr";
|
||||
import PeerId from "peer-id";
|
||||
|
@ -333,6 +332,7 @@ export class NimWaku {
|
|||
return { peerId: this.peerId, multiaddrWithId: this.multiaddrWithId };
|
||||
}
|
||||
const res = await this.info();
|
||||
console.log(res);
|
||||
this.multiaddrWithId = res.listenAddresses
|
||||
.map((ma) => multiaddr(ma))
|
||||
.find((ma) => ma.protoNames().includes("ws"));
|
||||
|
@ -351,20 +351,19 @@ export class NimWaku {
|
|||
method: string,
|
||||
params: Array<string | number | unknown>
|
||||
): Promise<T> {
|
||||
const res = await axios.post(
|
||||
this.rpcUrl,
|
||||
{
|
||||
const res = await fetch(this.rpcUrl, {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
jsonrpc: "2.0",
|
||||
id: 1,
|
||||
method,
|
||||
params,
|
||||
},
|
||||
{
|
||||
headers: { "Content-Type": "application/json" },
|
||||
}
|
||||
);
|
||||
}),
|
||||
headers: new Headers({ "Content-Type": "application/json" }),
|
||||
});
|
||||
|
||||
return res.data.result;
|
||||
const json = await res.json();
|
||||
return json.result;
|
||||
}
|
||||
|
||||
private checkProcess(): void {
|
||||
|
|
Loading…
Reference in New Issue