Skip to content

Commit 4134aa3

Browse files
Allow setting min TLS Ver. Default: v1.2
This update allows setting the minimum TLS version when initializing the Phaxio object. Default is `TLSv1.2`, other options are those listed for `minVersion` at https://nodejs.org/api/tls.html#tls_tls_createsecurecontext_options Was updated to be backwards-compatible. Users of earlier versions should not have to modify code to get the benefit of TLSv1.2.
1 parent 0d3f103 commit 4134aa3

16 files changed

Lines changed: 88 additions & 30 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Change Log
2+
3+
## v1.2 (2019-03-21)
4+
Adds optional argument to set the minimum TLS version to be used. Defaults to `TLSv1.2`.

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,27 @@ phaxio.faxes.listFaxes({ direction: 'sent' })
7474
Phaxio methods are categorized according to the Phaxio API route that they target.
7575
See the [Phaxio Docs]('https://www.phaxio.com/docs/api/v2.1/') for more information about the raw API.
7676
77+
### Initialization
78+
Initializing the `Phaxio` class takes two required arguments, the Key and Secret you retreived from Phaxio, and
79+
allows for one optional argument, the minimum TLS version to use. By default, the minimum TLS version is set to
80+
`TLSv1.2`. See the [TLS documentation](https://nodejs.org/api/tls.html#tls_tls_createsecurecontext_options) for
81+
other possible options to `minVersion` if you require something other than `TLSv1.2`. **Modifying the minimum TLS
82+
version is not recommended.**
83+
84+
Arguments:
85+
86+
| Key | Value Type | Required? | Description |
87+
| --- | ---------- | --------- | ----------- |
88+
| `phaxio api key` | String | True | Your Phaxio API Key |
89+
| `phaxio api secret` | String | True | Your Phaxio API Secret |
90+
| `minimum TLS Version` | String | False | Default: `TLSv1.2`, other possible options are the same as `minVersion` in the [TLS documentation](https://nodejs.org/api/tls.html#tls_tls_createsecurecontext_options).
91+
92+
```javascript
93+
const Phaxio = require('phaxio-official');
94+
95+
const phaxio = new Phaxio(<phaxio api key>, <phaxio api secret>, [optional: <minimum TLS version>]);
96+
```
97+
7798
**All Phaxio methods take one argument:** either a single argument such as an ID, or an Object containing
7899
`key: value` parameters.
79100
See the documentation below for specifics.

index.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,17 @@ const PhaxCode = require('./src/phax-code');
55
const PhoneNumber = require('./src/phone-number');
66

77
module.exports = class {
8-
constructor(apiKey, apiSecret) {
8+
constructor(apiKey, apiSecret, minTLSVersion) {
99
this.apiKey = apiKey;
1010
this.apiSecret = apiSecret;
1111

1212
this.url = 'https://api.phaxio.com/v2.1';
13+
this.agentOptions = { minVersion: minTLSVersion || 'TLSv1.2' };
1314

14-
this.public = new Public(this.url);
15-
this.faxes = new Faxes(this.apiKey, this.apiSecret, this.url);
16-
this.account = new Account(this.apiKey, this.apiSecret, this.url);
17-
this.phaxCode = new PhaxCode(this.apiKey, this.apiSecret, this.url);
18-
this.phoneNumber = new PhoneNumber(this.apiKey, this.apiSecret, this.url);
15+
this.public = new Public(this.url, this.agentOptions);
16+
this.faxes = new Faxes(this.apiKey, this.apiSecret, this.url, this.agentOptions);
17+
this.account = new Account(this.apiKey, this.apiSecret, this.url, this.agentOptions);
18+
this.phaxCode = new PhaxCode(this.apiKey, this.apiSecret, this.url, this.agentOptions);
19+
this.phoneNumber = new PhoneNumber(this.apiKey, this.apiSecret, this.url, this.agentOptions);
1920
}
2021
};

src/account/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ const request = require('request-promise-native');
22
const errorHandler = require('../error-handler');
33

44
module.exports = class {
5-
constructor(apiKey, apiSecret, url) {
5+
constructor(apiKey, apiSecret, url, agentOptions) {
66
this.apiKey = apiKey;
77
this.apiSecret = apiSecret;
88
this.url = url;
9+
this.agentOptions = agentOptions;
910

1011
this.auth = { user: this.apiKey, pass: this.apiSecret };
1112
}
@@ -16,6 +17,7 @@ module.exports = class {
1617
method: 'GET',
1718
url: `${this.url}/account/status`,
1819
auth: this.auth,
20+
agentOptions: this.agentOptions,
1921
})
2022
.then((response) => {
2123
const res = JSON.parse(response);

src/faxes/fax.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,44 +8,47 @@ const {
88
} = require('./shared-methods');
99

1010
module.exports = class {
11-
constructor(apiKey, apiSecret, url, success, message, data) {
11+
constructor(apiKey, apiSecret, url, success, message, data, agentOptions) {
1212
this.apiKey = apiKey;
1313
this.apiSecret = apiSecret;
1414
this.url = url;
1515
this.success = success;
1616
this.message = message;
1717
this.id = data.id;
18+
this.agentOptions = agentOptions;
1819

1920
this.auth = { user: this.apiKey, pass: this.apiSecret };
2021
}
2122

2223
async cancel() {
23-
const canc = await cancel(this.url, this.id, this.auth);
24+
const canc = await cancel(this.url, this.id, this.auth, this.agentOptions);
2425
return canc;
2526
}
2627

2728
async resend(callback_url = null) {
28-
const res = await resend(this.url, this.id, this.auth, { id: this.id, callback_url });
29+
// eslint-disable-next-line max-len
30+
const res = await resend(this.url, this.id, this.auth, { id: this.id, callback_url }, this.agentOptions);
2931
return res;
3032
}
3133

3234
async getInfo() {
33-
const metadata = await getInfo(this.url, this.id, this.auth);
35+
const metadata = await getInfo(this.url, this.id, this.auth, this.agentOptions);
3436
return metadata;
3537
}
3638

3739
async getFile(thumbnail = null) {
38-
const gf = await getFile(this.url, this.id, this.auth, { id: this.id, thumbnail });
40+
// eslint-disable-next-line max-len
41+
const gf = await getFile(this.url, this.id, this.auth, { id: this.id, thumbnail }, this.agentOptions);
3942
return gf;
4043
}
4144

4245
async deleteFile() {
43-
const df = await deleteFile(this.url, this.id, this.auth);
46+
const df = await deleteFile(this.url, this.id, this.auth, this.agentOptions);
4447
return df;
4548
}
4649

4750
async testDelete() {
48-
const td = await testDelete(this.url, this.id, this.auth);
51+
const td = await testDelete(this.url, this.id, this.auth, this.agentOptions);
4952
return td;
5053
}
5154
};

src/faxes/index.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,41 +13,42 @@ const {
1313
} = require('./shared-methods');
1414

1515
module.exports = class {
16-
constructor(apiKey, apiSecret, url) {
16+
constructor(apiKey, apiSecret, url, agentOptions) {
1717
this.apiKey = apiKey;
1818
this.apiSecret = apiSecret;
1919
this.url = url;
20+
this.agentOptions = agentOptions;
2021

2122
this.auth = { user: this.apiKey, pass: this.apiSecret };
2223
}
2324

2425
async cancel(id) {
25-
const canc = await cancel(this.url, id, this.auth);
26+
const canc = await cancel(this.url, id, this.auth, this.agentOptions);
2627
return canc;
2728
}
2829

2930
async resend(options = { id: null, callback_url: null }) {
30-
const res = await resend(this.url, options.id, this.auth, options);
31+
const res = await resend(this.url, options.id, this.auth, options, this.agentOptions);
3132
return res;
3233
}
3334

3435
async testDelete(id) {
35-
const td = await testDelete(this.url, id, this.auth);
36+
const td = await testDelete(this.url, id, this.auth, this.agentOptions);
3637
return td;
3738
}
3839

3940
async getInfo(id) {
40-
const gi = await getInfo(this.url, id, this.auth);
41+
const gi = await getInfo(this.url, id, this.auth, this.agentOptions);
4142
return gi;
4243
}
4344

4445
async getFile(options = { id: null, thumbnail: null }) {
45-
const gf = await getFile(this.url, options.id, this.auth, options);
46+
const gf = await getFile(this.url, options.id, this.auth, options, this.agentOptions);
4647
return gf;
4748
}
4849

4950
async deleteFile(id) {
50-
const df = await deleteFile(this.url, id, this.auth);
51+
const df = await deleteFile(this.url, id, this.auth, this.agentOptions);
5152
return df;
5253
}
5354

@@ -77,6 +78,7 @@ module.exports = class {
7778
method: 'POST',
7879
url: `${this.url}/faxes`,
7980
auth: this.auth,
81+
agentOptions: this.agentOptions,
8082
};
8183

8284
const caller = request(req);
@@ -133,6 +135,7 @@ module.exports = class {
133135
url: `${this.url}/faxes`,
134136
auth: this.auth,
135137
formData,
138+
agentOptions: this.agentOptions,
136139
})
137140
.then((response) => {
138141
const res = JSON.parse(response);
@@ -171,6 +174,7 @@ module.exports = class {
171174
url: `${this.url}/faxes`,
172175
auth: this.auth,
173176
qs: query,
177+
agentOptions: this.agentOptions,
174178
})
175179
.then((response) => {
176180
const res = JSON.parse(response);

src/faxes/shared-methods.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
const request = require('request-promise-native');
22
const errorHandler = require('../error-handler');
33

4-
function cancel(url, id, auth) {
4+
function cancel(url, id, auth, agentOptions) {
55
return new Promise((resolve, reject) => {
66
request({
77
method: 'POST',
88
url: `${url}/faxes/${id}/cancel`,
99
auth,
10+
agentOptions,
1011
})
1112
.then((response) => {
1213
const res = JSON.parse(response);
@@ -17,7 +18,7 @@ function cancel(url, id, auth) {
1718
});
1819
}
1920

20-
function resend(url, id, auth, options = { id: null, callback_url: null }) {
21+
function resend(url, id, auth, options = { id: null, callback_url: null }, agentOptions) {
2122
return new Promise((resolve, reject) => {
2223
const { callback_url } = options; // eslint-disable-line camelcase
2324

@@ -26,6 +27,7 @@ function resend(url, id, auth, options = { id: null, callback_url: null }) {
2627
url: `${url}/faxes/${id}/resend`,
2728
auth,
2829
callback_url,
30+
agentOptions,
2931
};
3032

3133
if (req.callback_url === null || req.callback_url === undefined) delete req.callback_url;
@@ -40,12 +42,13 @@ function resend(url, id, auth, options = { id: null, callback_url: null }) {
4042
});
4143
}
4244

43-
function testDelete(url, id, auth) {
45+
function testDelete(url, id, auth, agentOptions) {
4446
return new Promise((resolve, reject) => {
4547
request({
4648
method: 'DELETE',
4749
url: `${url}/faxes/${id}`,
4850
auth,
51+
agentOptions,
4952
})
5053
.then((response) => {
5154
const res = JSON.parse(response);
@@ -56,12 +59,13 @@ function testDelete(url, id, auth) {
5659
});
5760
}
5861

59-
function getInfo(url, id, auth) {
62+
function getInfo(url, id, auth, agentOptions) {
6063
return new Promise((resolve, reject) => {
6164
request({
6265
method: 'GET',
6366
url: `${url}/faxes/${id}`,
6467
auth,
68+
agentOptions,
6569
})
6670
.then((response) => {
6771
const res = JSON.parse(response);
@@ -72,7 +76,7 @@ function getInfo(url, id, auth) {
7276
});
7377
}
7478

75-
function getFile(url, id, auth, options = { id: null, thumbnail: null }) {
79+
function getFile(url, id, auth, options = { id: null, thumbnail: null }, agentOptions) {
7680
return new Promise((resolve, reject) => { // eslint-disable-line consistent-return
7781
const thumbnail = options.thumbnail === undefined ? null : options.thumbnail;
7882

@@ -84,6 +88,7 @@ function getFile(url, id, auth, options = { id: null, thumbnail: null }) {
8488
method: 'GET',
8589
url: `${url}/faxes/${id}/file`,
8690
auth,
91+
agentOptions,
8792
};
8893

8994
if (thumbnail !== null) req.qs.thumbnail = thumbnail;
@@ -94,12 +99,13 @@ function getFile(url, id, auth, options = { id: null, thumbnail: null }) {
9499
});
95100
}
96101

97-
function deleteFile(url, id, auth) {
102+
function deleteFile(url, id, auth, agentOptions) {
98103
return new Promise((resolve, reject) => {
99104
request({
100105
method: 'DELETE',
101106
url: `${url}/faxes/${id}/file`,
102107
auth,
108+
agentOptions,
103109
})
104110
.then((response) => {
105111
const res = JSON.parse(response);

src/phax-code/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ const request = require('request-promise-native');
22
const errorHandler = require('../error-handler');
33

44
module.exports = class {
5-
constructor(apiKey, apiSecret, url) {
5+
constructor(apiKey, apiSecret, url, agentOptions) {
66
this.apiKey = apiKey;
77
this.apiSecret = apiSecret;
88
this.url = url;
9+
this.agentOptions = agentOptions;
910

1011
this.auth = { user: this.apiKey, pass: this.apiSecret };
1112
}
@@ -21,6 +22,7 @@ module.exports = class {
2122
method: 'POST',
2223
url: `${this.url}/phax_codes`,
2324
auth: this.auth,
25+
agentOptions: this.agentOptions,
2426
};
2527

2628
if (formData.length !== 0) req.formData = formData;

src/phone-number/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ const request = require('request-promise-native');
22
const errorHandler = require('../error-handler');
33

44
module.exports = class {
5-
constructor(apiKey, apiSecret, url) {
5+
constructor(apiKey, apiSecret, url, agentOptions) {
66
this.apiKey = apiKey;
77
this.apiSecret = apiSecret;
88
this.url = url;
9+
this.agentOptions = agentOptions;
910

1011
this.auth = { user: this.apiKey, pass: this.apiSecret };
1112
}
@@ -16,6 +17,7 @@ module.exports = class {
1617
method: 'DELETE',
1718
url: `${this.url}/phone_numbers/${number}`,
1819
auth: this.auth,
20+
agentOptions: this.agentOptions,
1921
})
2022
.then((response) => {
2123
const res = JSON.parse(response);
@@ -37,6 +39,7 @@ module.exports = class {
3739
method: 'GET',
3840
url: `${this.url}/phone_numbers`,
3941
auth: this.auth,
42+
agentOptions: this.agentOptions,
4043
};
4144

4245
if (query.length !== 0) req.qs = query;
@@ -57,6 +60,7 @@ module.exports = class {
5760
method: 'GET',
5861
url: `${this.url}/phone_numbers/${number}`,
5962
auth: this.auth,
63+
agentOptions: this.agentOptions,
6064
})
6165
.then((response) => {
6266
const res = JSON.parse(response);
@@ -78,6 +82,7 @@ module.exports = class {
7882
method: 'POST',
7983
url: `${this.url}/phone_numbers`,
8084
auth: this.auth,
85+
agentOptions: this.agentOptions,
8186
};
8287

8388
if (formData.length !== 0) req.formData = formData;

src/public/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ const request = require('request-promise-native');
22
const errorHandler = require('../error-handler');
33

44
module.exports = class {
5-
constructor(url) {
5+
constructor(url, agentOptions) {
66
this.url = url;
7+
this.agentOptions = agentOptions;
78
}
89

910

@@ -24,6 +25,7 @@ module.exports = class {
2425
const req = {
2526
method: 'GET',
2627
url: `${this.url}/public/area_codes`,
28+
agentOptions: this.agentOptions,
2729
};
2830

2931
if (qs.length !== 0) req.qs = qs;

0 commit comments

Comments
 (0)