<repo_name>parz3val/connection_test_sdk<file_sep>/index.js
// Entrypoint in the package
const ipTest = require("./lib/network.js");
const speedTest = require("./lib/speedTest.js");

module.exports = {
  ipTest,
  speedTest,
};
<file_sep>/README.md
# Connection Test SDK

Package to monitor the call quality and network status for a specific browser/clients

Returns a hashmap`{}`after running a suite of tests

## Tests

1. IP test - returns IP and location
2. IP Fraud Score - returns details like VPN and proxies. Uses quality score api.
3. Speed test to the cloudflare cli 


<file_sep>/lib/network.js
//const fetch = require("node-fetch");
require("dotenv").config();
class ipTest {
  /**
   * Function to detect the IP
   *
   * @returns {Object}
   */
  async detectIP() {
    // may be we need to hit our own server which will hit multiple server if one is busy
    let resp = [];
    await fetch("https://extreme-ip-lookup.com/json/")
      .then((res) => res.json())
      .then((json) => {
        resp.push(json);
      })
      .catch((error) => {
        console.log("Request failed:", error);
      });
    return resp;
  }
  async detectVPN(ip, qualtyIpApiKey) {
    // may be we need to hit our own server which will hit multiple server if one is busy
    let resp = [];
    const qualityIPURL =
      "https://ipqualityscore.com/api/json/ip/" +
      qualtyIpApiKey +
      "/" +
      ip +
      "?strictness=1&user_agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36&user_language=en-US";
    await fetch(qualityIPURL, { method: "GET" })
      .then((res) => res.json())
      .then((json) => {
        resp.push(json);
      })
      .catch((error) => {
        console.log("Request failed:", error);
      });
    return resp;
  }
}

const iptest = new ipTest();
module.exports = iptest;
<file_sep>/tests/ip.test.js
const ipTest = require("../lib/network.js");
//
// Test the location and IP getting module
test("testIPLocation", async () => {
  resp = await ipTest.detectIP();
  json = resp[0];
  console.log(json);
  code = json.countryCode;
  expect(code).toBe("NP");
});
//
// Test the If user is on vpn
test("testIF on VPN", async () => {
  resp = await ipTest.detectVPN("172.16.31.10",process.env.QUALITY_IP_API_KEY);
  json = resp[0];
  code = json.vpn;
  console.log(json);
  expect(code).toBe(false);
});
