Skip to content

Commit 9a70e6c

Browse files
committed
2.0.0 implement keepAliveAgent
1 parent 3362afd commit 9a70e6c

File tree

4 files changed

+65
-5
lines changed

4 files changed

+65
-5
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,3 +456,4 @@ await fuusorApiClient.userGroups.removeUsers('3fa85f64-5717-4562-b3fc-2c963f66af
456456
- 1.1.2 Add support for user expiration date
457457
- 1.1.3 Better logging in case of invalid hierarchy items or dimension items
458458
- 1.2.0 pushDimensionFieldDimension option to allow empty dimensions
459+
- 2.0.0 Add internal httpsAgent (from agentkeepalive package) by default

package-lock.json

Lines changed: 37 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@rantalainen/fuusor-api-client",
3-
"version": "1.2.0",
3+
"version": "2.0.0",
44
"description": "Fuusor API client library",
55
"main": "dist/index.js",
66
"scripts": {
@@ -21,6 +21,7 @@
2121
"homepage": "https://github.com/rantalainen/fuusor-api-client#readme",
2222
"dependencies": {
2323
"@types/node": "^14.0.13",
24+
"agentkeepalive": "^4.2.1",
2425
"form-data": "^3.0.0",
2526
"got": "^11.3.0"
2627
},

src/index.ts

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import got, { Headers, Method, OptionsOfJSONResponseBody } from 'got';
22
import { FuusorDataSet, IFuusorDataSetOptions } from './data-set';
33
import { FuusorUser } from './user';
44
import { FuusorUserGroup } from './user-group';
5+
import { HttpsAgent } from 'agentkeepalive';
6+
7+
const httpsAgent = new HttpsAgent();
58

69
export interface IFuusorApiClientOptions {
710
clientId: string;
@@ -31,6 +34,9 @@ export class FuusorApiClient {
3134
/** @private */
3235
accessTokensTimeout: any;
3336

37+
/** @private */
38+
httpsAgent: HttpsAgent = httpsAgent;
39+
3440
constructor(options: IFuusorApiClientOptions) {
3541
// Set default connect URI
3642
options.uriConnect = options.uriConnect || 'https://api.fuusor.fi/connect/token';
@@ -106,14 +112,18 @@ export class FuusorApiClient {
106112

107113
headers: {
108114
Authorization: `Bearer ${accessToken}`
115+
},
116+
117+
agent: {
118+
https: this.httpsAgent
109119
}
110120
});
111121

112122
return;
113123
}
114124

115125
async fetchAccessTokenForDataSetUpload(): Promise<string> {
116-
const { access_token } = await got
126+
const { access_token } = (await got
117127
.post(this.options.uriConnect || '', {
118128
form: {
119129
scope: 'fileupload',
@@ -123,9 +133,13 @@ export class FuusorApiClient {
123133
username: this.options.username,
124134
password: this.options.password,
125135
filetype: 'JsonTransformer'
136+
},
137+
138+
agent: {
139+
https: this.httpsAgent
126140
}
127141
})
128-
.json();
142+
.json()) as any;
129143

130144
return access_token;
131145
}
@@ -149,6 +163,10 @@ export class FuusorApiClient {
149163
username: this.options.username,
150164
password: this.options.password,
151165
filetype: 'JsonTransformer'
166+
},
167+
168+
agent: {
169+
https: this.httpsAgent
152170
}
153171
})
154172
.json();
@@ -177,7 +195,11 @@ export class FuusorApiClient {
177195
timeout: this.options.timeout,
178196
headers: await this.getDefaultHttpHeaders(scope),
179197
responseType: 'json',
180-
throwHttpErrors: false
198+
throwHttpErrors: false,
199+
200+
agent: {
201+
https: this.httpsAgent
202+
}
181203
};
182204

183205
// If json body is defined

0 commit comments

Comments
 (0)