diff --git a/CHANGELOG.md b/CHANGELOG.md index 808d75b..c27f76f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## 1.1.1 + +- Upgrade library to use HTTP/HTTPS or SOCKS proxies (JavaScript) +- Add instructions on how to set up a SOCKS proxy + ## 1.1.0 - Add client option to use a proxy diff --git a/README.md b/README.md index 79992c9..5c14de7 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ const api = new Client('https://dctrack.example.com/', { apiToken: 'token' }); ``` ## Advanced: Initialize a connection with a proxy -> Proxies can be used for either authentication method (username/password or API token.) For the Python library, specify an HTTP or HTTPS proxy, or both. For the JavaScript library, only 1 proxy is required and HTTPS will automatically upgraded to TLS. +> Proxies can be used for either authentication method (username/password or API token.) For the Python library, specify an HTTP or HTTPS proxy, or both. These can also be SOCKS proxies, however the `requests[socks]` module is required. For the JavaScript library, only 1 proxy is required and `https` proxies can begin with `http://` or `https://`. HTTPS will automatically upgraded to TLS. No additional modules are required. ### Python ```py @@ -45,7 +45,7 @@ api = Client('https://dctrack.example.com/', username='user', password='pass', h ### JavaScript ```js -const api = new Client('https://dctrack.example.com/', { username: 'user', password: 'pass' }, 'http://proxy:port'); +const api = new Client('https://dctrack.example.com/', { username: 'user', password: 'pass' }, { https: 'http://proxy:port', socks: 'socks://proxy:port' }); ``` ## Obtain an API Token diff --git a/js/package.json b/js/package.json index b4f516f..08e7595 100644 --- a/js/package.json +++ b/js/package.json @@ -25,7 +25,8 @@ }, "homepage": "https://github.com/nicfv/dcTrackClient#readme", "dependencies": { + "node-fetch": "^3.3.2", "https-proxy-agent": "^7.0.2", - "node-fetch": "^3.3.2" + "socks-proxy-agent": "^8.0.2" } -} +} \ No newline at end of file diff --git a/js/src/index.js b/js/src/index.js index 0a7f1fc..86e0060 100644 --- a/js/src/index.js +++ b/js/src/index.js @@ -1,5 +1,6 @@ import fetch from 'node-fetch'; import { HttpsProxyAgent } from 'https-proxy-agent'; +import { SocksProxyAgent } from 'socks-proxy-agent'; /** * Sunbird dcTrack API client version %VERSION% in JavaScript */ @@ -12,12 +13,16 @@ export class Client { /** * Provide either a username and password, or an API token to access the dcTrack database with JavaScript. */ - constructor(base_url = '', credentials = { username: '', password: '', apiToken: '' }, proxy = '') { + constructor(base_url = '', credentials = { username: '', password: '', apiToken: '' }, proxy = { https: '', socks: '' }) { this.#base_url = base_url; this.#username = credentials.username; this.#password = credentials.password; this.#apiToken = credentials.apiToken; - this.#proxyAgent = new HttpsProxyAgent(proxy); + if (proxy.https) { + this.#proxyAgent = new HttpsProxyAgent(proxy.https); + } else if (proxy.socks) { + this.#proxyAgent = new SocksProxyAgent(proxy.socks); + } } /**