@hahnpro/hpc-api 3.7.0 → 3.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/http.service.d.ts +1 -1
- package/dist/http.service.js +3 -4
- package/dist/token-set.d.ts +6 -5
- package/dist/token-set.js +12 -8
- package/package.json +3 -3
package/dist/http.service.d.ts
CHANGED
|
@@ -30,7 +30,7 @@ export declare class HttpClient {
|
|
|
30
30
|
addEventSource(url: string, listener: (event: MessageEvent) => void, errorListener?: (event: MessageEvent) => void): Promise<any>;
|
|
31
31
|
destroyEventSource(id: string): void;
|
|
32
32
|
destroyAllEventSources(): void;
|
|
33
|
-
getAccessToken: () => Promise<string>;
|
|
33
|
+
getAccessToken: (forceRefresh?: boolean) => Promise<string>;
|
|
34
34
|
private validateIssuer;
|
|
35
35
|
private discoverIssuer;
|
|
36
36
|
private requestAccessToken;
|
package/dist/http.service.js
CHANGED
|
@@ -9,7 +9,6 @@ const jose_1 = require("jose");
|
|
|
9
9
|
const Queue_1 = require("./Queue");
|
|
10
10
|
const token_set_1 = require("./token-set");
|
|
11
11
|
const querystring_1 = require("querystring");
|
|
12
|
-
const TOKEN_EXPIRATION_BUFFER = 30;
|
|
13
12
|
class HttpClient {
|
|
14
13
|
constructor(baseURL, authBaseURL, realm, clientId, clientSecret) {
|
|
15
14
|
this.baseURL = baseURL;
|
|
@@ -34,11 +33,11 @@ class HttpClient {
|
|
|
34
33
|
.catch(reject);
|
|
35
34
|
}));
|
|
36
35
|
};
|
|
37
|
-
this.getAccessToken = async () => {
|
|
38
|
-
if (
|
|
36
|
+
this.getAccessToken = async (forceRefresh = false) => {
|
|
37
|
+
if (forceRefresh || !this.tokenSet || this.tokenSet.isExpired()) {
|
|
39
38
|
return this.requestAccessToken();
|
|
40
39
|
}
|
|
41
|
-
return this.tokenSet.
|
|
40
|
+
return this.tokenSet.accessToken;
|
|
42
41
|
};
|
|
43
42
|
this.axiosInstance = axios_1.default.create({ baseURL, timeout: 60000 });
|
|
44
43
|
this.authAxiosInstance = axios_1.default.create({ baseURL: authBaseURL || baseURL, timeout: 10000 });
|
package/dist/token-set.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
export declare class TokenSet {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
private readonly _accessToken;
|
|
3
|
+
private readonly _expiresAt;
|
|
4
4
|
constructor(access_token: string, expires_in: number);
|
|
5
|
-
|
|
6
|
-
get
|
|
7
|
-
|
|
5
|
+
get accessToken(): string;
|
|
6
|
+
get expiresAt(): number;
|
|
7
|
+
get expiresIn(): number;
|
|
8
|
+
isExpired(): boolean;
|
|
8
9
|
}
|
package/dist/token-set.js
CHANGED
|
@@ -1,19 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TokenSet = void 0;
|
|
4
|
+
const TOKEN_EXPIRATION_BUFFER = 20;
|
|
4
5
|
class TokenSet {
|
|
5
6
|
constructor(access_token, expires_in) {
|
|
6
|
-
this.
|
|
7
|
-
this.
|
|
7
|
+
this._accessToken = access_token;
|
|
8
|
+
this._expiresAt = Math.floor(Date.now() / 1000) + Number(expires_in);
|
|
8
9
|
}
|
|
9
|
-
|
|
10
|
-
this.
|
|
10
|
+
get accessToken() {
|
|
11
|
+
return this._accessToken;
|
|
11
12
|
}
|
|
12
|
-
get
|
|
13
|
-
return
|
|
13
|
+
get expiresAt() {
|
|
14
|
+
return this._expiresAt;
|
|
14
15
|
}
|
|
15
|
-
|
|
16
|
-
return this.
|
|
16
|
+
get expiresIn() {
|
|
17
|
+
return Math.max(this.expiresAt - Math.ceil(Date.now() / 1000), 0);
|
|
18
|
+
}
|
|
19
|
+
isExpired() {
|
|
20
|
+
return this.expiresIn <= TOKEN_EXPIRATION_BUFFER;
|
|
17
21
|
}
|
|
18
22
|
}
|
|
19
23
|
exports.TokenSet = TokenSet;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hahnpro/hpc-api",
|
|
3
|
-
"version": "3.7.
|
|
3
|
+
"version": "3.7.1",
|
|
4
4
|
"description": "Module for easy access to the HahnPRO API",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -24,10 +24,10 @@
|
|
|
24
24
|
"access": "public"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"axios": "~1.3.
|
|
27
|
+
"axios": "~1.3.4",
|
|
28
28
|
"eventsource": "^2.0.2",
|
|
29
29
|
"form-data": "^4.0.0",
|
|
30
|
-
"jose": "^4.
|
|
30
|
+
"jose": "^4.13.1",
|
|
31
31
|
"jwt-decode": "^3.1.2",
|
|
32
32
|
"p-queue": "^6.6.2",
|
|
33
33
|
"ts-mixer": "^6.0.3",
|