Skip to content

Commit

Permalink
Release v1.1.1 (socks proxy)
Browse files Browse the repository at this point in the history
  • Loading branch information
6nv committed Nov 3, 2023
1 parent fb47261 commit 33d8f44
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
5 changes: 3 additions & 2 deletions js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
9 changes: 7 additions & 2 deletions js/src/index.js
Original file line number Diff line number Diff line change
@@ -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
*/
Expand All @@ -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);
}
}

/**
Expand Down

0 comments on commit 33d8f44

Please sign in to comment.