@sisense/sdk-rest-client 1.3.0 → 1.4.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/bearer-authenticator.d.ts +8 -0
- package/dist/bearer-authenticator.js +10 -0
- package/dist/http-client.js +3 -16
- package/dist/index.d.ts +3 -3
- package/dist/index.js +3 -3
- package/dist/interceptors.d.ts +2 -17
- package/dist/interceptors.js +19 -4
- package/dist/interfaces.d.ts +1 -0
- package/dist/password-authenticator.d.ts +8 -0
- package/dist/password-authenticator.js +10 -0
- package/dist/sso-authenticator.d.ts +8 -0
- package/dist/sso-authenticator.js +10 -0
- package/dist/wat-authenticator.d.ts +8 -0
- package/dist/wat-authenticator.js +10 -0
- package/package.json +2 -2
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Authenticator } from './interfaces.js';
|
|
2
2
|
export declare class BearerAuthenticator implements Authenticator {
|
|
3
|
+
readonly type = "bearer";
|
|
3
4
|
readonly bearer: string;
|
|
4
5
|
readonly url: string;
|
|
5
6
|
private _valid;
|
|
@@ -10,3 +11,10 @@ export declare class BearerAuthenticator implements Authenticator {
|
|
|
10
11
|
applyHeader(headers: HeadersInit): void;
|
|
11
12
|
authenticate(): Promise<boolean>;
|
|
12
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* Checks if an authenticator is a BearerAuthenticator.
|
|
16
|
+
*
|
|
17
|
+
* @param authenticator - The authenticator to check.
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
export declare function isBearerAuthenticator(authenticator: Authenticator): authenticator is BearerAuthenticator;
|
|
@@ -12,6 +12,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
12
12
|
import { appendHeaders } from './helpers.js';
|
|
13
13
|
export class BearerAuthenticator {
|
|
14
14
|
constructor(url, bearer) {
|
|
15
|
+
this.type = 'bearer';
|
|
15
16
|
this._valid = true;
|
|
16
17
|
this.bearer = bearer;
|
|
17
18
|
this.url = url;
|
|
@@ -36,3 +37,12 @@ export class BearerAuthenticator {
|
|
|
36
37
|
});
|
|
37
38
|
}
|
|
38
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Checks if an authenticator is a BearerAuthenticator.
|
|
42
|
+
*
|
|
43
|
+
* @param authenticator - The authenticator to check.
|
|
44
|
+
* @internal
|
|
45
|
+
*/
|
|
46
|
+
export function isBearerAuthenticator(authenticator) {
|
|
47
|
+
return authenticator.type === 'bearer';
|
|
48
|
+
}
|
package/dist/http-client.js
CHANGED
|
@@ -8,7 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import fetchIntercept from 'fetch-intercept';
|
|
11
|
-
import {
|
|
11
|
+
import { getResponseInterceptor, errorInterceptor } from './interceptors.js';
|
|
12
12
|
import { SsoAuthenticator } from './sso-authenticator.js';
|
|
13
13
|
import { addQueryParamsToUrl } from './helpers.js';
|
|
14
14
|
export class HttpClient {
|
|
@@ -20,21 +20,8 @@ export class HttpClient {
|
|
|
20
20
|
this.auth = auth;
|
|
21
21
|
this.env = env;
|
|
22
22
|
fetchIntercept.register({
|
|
23
|
-
response: (
|
|
24
|
-
|
|
25
|
-
return handleUnauthorizedResponse(response, auth);
|
|
26
|
-
}
|
|
27
|
-
if (!response.ok) {
|
|
28
|
-
return handleErrorResponse(response);
|
|
29
|
-
}
|
|
30
|
-
return response;
|
|
31
|
-
},
|
|
32
|
-
responseError: (error) => {
|
|
33
|
-
if (isNetworkError(error)) {
|
|
34
|
-
return handleNetworkError();
|
|
35
|
-
}
|
|
36
|
-
return Promise.reject(error);
|
|
37
|
-
},
|
|
23
|
+
response: getResponseInterceptor(auth),
|
|
24
|
+
responseError: errorInterceptor,
|
|
38
25
|
});
|
|
39
26
|
}
|
|
40
27
|
login() {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import './translation/initialize-i18n.js';
|
|
2
2
|
export * from './interfaces.js';
|
|
3
3
|
export { PasswordAuthenticator } from './password-authenticator.js';
|
|
4
|
-
export { SsoAuthenticator } from './sso-authenticator.js';
|
|
5
|
-
export { BearerAuthenticator } from './bearer-authenticator.js';
|
|
6
|
-
export { WatAuthenticator } from './wat-authenticator.js';
|
|
4
|
+
export { SsoAuthenticator, isSsoAuthenticator } from './sso-authenticator.js';
|
|
5
|
+
export { BearerAuthenticator, isBearerAuthenticator } from './bearer-authenticator.js';
|
|
6
|
+
export { WatAuthenticator, isWatAuthenticator } from './wat-authenticator.js';
|
|
7
7
|
export { getAuthenticator } from './authenticator.js';
|
|
8
8
|
export { HttpClient } from './http-client.js';
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import './translation/initialize-i18n.js';
|
|
2
2
|
export * from './interfaces.js';
|
|
3
3
|
export { PasswordAuthenticator } from './password-authenticator.js';
|
|
4
|
-
export { SsoAuthenticator } from './sso-authenticator.js';
|
|
5
|
-
export { BearerAuthenticator } from './bearer-authenticator.js';
|
|
6
|
-
export { WatAuthenticator } from './wat-authenticator.js';
|
|
4
|
+
export { SsoAuthenticator, isSsoAuthenticator } from './sso-authenticator.js';
|
|
5
|
+
export { BearerAuthenticator, isBearerAuthenticator } from './bearer-authenticator.js';
|
|
6
|
+
export { WatAuthenticator, isWatAuthenticator } from './wat-authenticator.js';
|
|
7
7
|
export { getAuthenticator } from './authenticator.js';
|
|
8
8
|
export { HttpClient } from './http-client.js';
|
package/dist/interceptors.d.ts
CHANGED
|
@@ -1,19 +1,4 @@
|
|
|
1
1
|
import { FetchInterceptorResponse } from 'fetch-intercept';
|
|
2
2
|
import { Authenticator } from './interfaces.js';
|
|
3
|
-
export declare
|
|
4
|
-
export declare
|
|
5
|
-
/**
|
|
6
|
-
* Checks if the given response error indicates a Network error.
|
|
7
|
-
*
|
|
8
|
-
* It is impossible to distinguish between a CORS error and other network errors, such as
|
|
9
|
-
* 'net::ERR_SSL_PROTOCOL_ERROR' and 'net::ERR_EMPTY_RESPONSE'. This information is hidden by the browser.
|
|
10
|
-
*
|
|
11
|
-
* @param responseError - The error object received from the failed response.
|
|
12
|
-
*/
|
|
13
|
-
export declare function isNetworkError(responseError: Error): boolean;
|
|
14
|
-
/**
|
|
15
|
-
* Handles a Network error.
|
|
16
|
-
*
|
|
17
|
-
* @returns A promise that rejects with an error message.
|
|
18
|
-
*/
|
|
19
|
-
export declare function handleNetworkError(): Promise<never>;
|
|
3
|
+
export declare const getResponseInterceptor: (auth: Authenticator) => (response: FetchInterceptorResponse) => FetchInterceptorResponse;
|
|
4
|
+
export declare const errorInterceptor: (error: Error) => Promise<never>;
|
package/dist/interceptors.js
CHANGED
|
@@ -3,7 +3,7 @@ import { WatAuthenticator } from './wat-authenticator.js';
|
|
|
3
3
|
import { PasswordAuthenticator } from './password-authenticator.js';
|
|
4
4
|
import { SsoAuthenticator } from './sso-authenticator.js';
|
|
5
5
|
import { TranslatableError } from './translation/translatable-error.js';
|
|
6
|
-
|
|
6
|
+
function handleErrorResponse(response) {
|
|
7
7
|
if (!response.ok) {
|
|
8
8
|
throw new TranslatableError('errors.responseError', {
|
|
9
9
|
status: response.status.toString(),
|
|
@@ -13,7 +13,7 @@ export function handleErrorResponse(response) {
|
|
|
13
13
|
}
|
|
14
14
|
return response;
|
|
15
15
|
}
|
|
16
|
-
|
|
16
|
+
function handleUnauthorizedResponse(response, auth) {
|
|
17
17
|
auth.invalidate();
|
|
18
18
|
// skip login redirect for token auth
|
|
19
19
|
if (auth instanceof PasswordAuthenticator) {
|
|
@@ -36,7 +36,7 @@ export function handleUnauthorizedResponse(response, auth) {
|
|
|
36
36
|
*
|
|
37
37
|
* @param responseError - The error object received from the failed response.
|
|
38
38
|
*/
|
|
39
|
-
|
|
39
|
+
function isNetworkError(responseError) {
|
|
40
40
|
return !!(responseError.message === 'Failed to fetch' && responseError.name === 'TypeError');
|
|
41
41
|
}
|
|
42
42
|
/**
|
|
@@ -44,6 +44,21 @@ export function isNetworkError(responseError) {
|
|
|
44
44
|
*
|
|
45
45
|
* @returns A promise that rejects with an error message.
|
|
46
46
|
*/
|
|
47
|
-
|
|
47
|
+
function handleNetworkError() {
|
|
48
48
|
return Promise.reject(new TranslatableError('errors.networkError'));
|
|
49
49
|
}
|
|
50
|
+
export const getResponseInterceptor = (auth) => (response) => {
|
|
51
|
+
if (response.status === 401) {
|
|
52
|
+
return handleUnauthorizedResponse(response, auth);
|
|
53
|
+
}
|
|
54
|
+
if (!response.ok) {
|
|
55
|
+
return handleErrorResponse(response);
|
|
56
|
+
}
|
|
57
|
+
return response;
|
|
58
|
+
};
|
|
59
|
+
export const errorInterceptor = (error) => {
|
|
60
|
+
if (isNetworkError(error)) {
|
|
61
|
+
return handleNetworkError();
|
|
62
|
+
}
|
|
63
|
+
return Promise.reject(error);
|
|
64
|
+
};
|
package/dist/interfaces.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/// <reference lib="dom" />
|
|
2
2
|
import { Authenticator } from './interfaces.js';
|
|
3
3
|
export declare class PasswordAuthenticator implements Authenticator {
|
|
4
|
+
readonly type = "password";
|
|
4
5
|
private _authheader;
|
|
5
6
|
readonly user: string;
|
|
6
7
|
readonly pass: string;
|
|
@@ -14,3 +15,10 @@ export declare class PasswordAuthenticator implements Authenticator {
|
|
|
14
15
|
applyHeader(headers: HeadersInit): void;
|
|
15
16
|
authenticate(): Promise<boolean>;
|
|
16
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* Checks if an authenticator is a PasswordAuthenticator.
|
|
20
|
+
*
|
|
21
|
+
* @param authenticator - the authenticator to check
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
24
|
+
export declare function isPasswordAuthenticator(authenticator: Authenticator): authenticator is PasswordAuthenticator;
|
|
@@ -16,6 +16,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
16
16
|
import { appendHeaders } from './helpers.js';
|
|
17
17
|
export class PasswordAuthenticator {
|
|
18
18
|
constructor(url, user, pass) {
|
|
19
|
+
this.type = 'password';
|
|
19
20
|
this._authenticating = false;
|
|
20
21
|
this._valid = true;
|
|
21
22
|
this._authheader = undefined;
|
|
@@ -59,3 +60,12 @@ export class PasswordAuthenticator {
|
|
|
59
60
|
});
|
|
60
61
|
}
|
|
61
62
|
}
|
|
63
|
+
/**
|
|
64
|
+
* Checks if an authenticator is a PasswordAuthenticator.
|
|
65
|
+
*
|
|
66
|
+
* @param authenticator - the authenticator to check
|
|
67
|
+
* @internal
|
|
68
|
+
*/
|
|
69
|
+
export function isPasswordAuthenticator(authenticator) {
|
|
70
|
+
return authenticator.type === 'password';
|
|
71
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/// <reference lib="dom" />
|
|
2
2
|
import { Authenticator } from './interfaces.js';
|
|
3
3
|
export declare class SsoAuthenticator implements Authenticator {
|
|
4
|
+
readonly type = "sso";
|
|
4
5
|
readonly url: string;
|
|
5
6
|
private _enableSilentPreAuth;
|
|
6
7
|
private _valid;
|
|
@@ -14,3 +15,10 @@ export declare class SsoAuthenticator implements Authenticator {
|
|
|
14
15
|
private checkAuthentication;
|
|
15
16
|
authenticate(silent?: boolean): Promise<boolean>;
|
|
16
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* Checks if the authenticator is SSO authenticator
|
|
20
|
+
*
|
|
21
|
+
* @param authenticator - authenticator to check
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
24
|
+
export declare function isSsoAuthenticator(authenticator: Authenticator): authenticator is SsoAuthenticator;
|
|
@@ -11,6 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
import { TranslatableError } from './translation/translatable-error.js';
|
|
12
12
|
export class SsoAuthenticator {
|
|
13
13
|
constructor(url, enableSilentPreAuth = false) {
|
|
14
|
+
this.type = 'sso';
|
|
14
15
|
this._valid = true;
|
|
15
16
|
this._authenticating = false;
|
|
16
17
|
this.url = url;
|
|
@@ -85,3 +86,12 @@ export class SsoAuthenticator {
|
|
|
85
86
|
});
|
|
86
87
|
}
|
|
87
88
|
}
|
|
89
|
+
/**
|
|
90
|
+
* Checks if the authenticator is SSO authenticator
|
|
91
|
+
*
|
|
92
|
+
* @param authenticator - authenticator to check
|
|
93
|
+
* @internal
|
|
94
|
+
*/
|
|
95
|
+
export function isSsoAuthenticator(authenticator) {
|
|
96
|
+
return authenticator.type === 'sso';
|
|
97
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/// <reference lib="dom" />
|
|
2
2
|
import { Authenticator } from './interfaces.js';
|
|
3
3
|
export declare class WatAuthenticator implements Authenticator {
|
|
4
|
+
readonly type = "wat";
|
|
4
5
|
private _initialiser;
|
|
5
6
|
private _webSessionToken;
|
|
6
7
|
readonly wat: string;
|
|
@@ -14,3 +15,10 @@ export declare class WatAuthenticator implements Authenticator {
|
|
|
14
15
|
applyHeader(headers: HeadersInit): void;
|
|
15
16
|
authenticate(): Promise<boolean>;
|
|
16
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* Checks if an authenticator is a WatAuthenticator.
|
|
20
|
+
*
|
|
21
|
+
* @param authenticator - the authenticator to check
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
24
|
+
export declare function isWatAuthenticator(authenticator: Authenticator): authenticator is WatAuthenticator;
|
|
@@ -12,6 +12,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
12
12
|
import { appendHeaders } from './helpers.js';
|
|
13
13
|
export class WatAuthenticator {
|
|
14
14
|
constructor(url, wat) {
|
|
15
|
+
this.type = 'wat';
|
|
15
16
|
this._authenticating = false;
|
|
16
17
|
this._valid = true;
|
|
17
18
|
this._initialiser = undefined;
|
|
@@ -67,3 +68,12 @@ export class WatAuthenticator {
|
|
|
67
68
|
});
|
|
68
69
|
}
|
|
69
70
|
}
|
|
71
|
+
/**
|
|
72
|
+
* Checks if an authenticator is a WatAuthenticator.
|
|
73
|
+
*
|
|
74
|
+
* @param authenticator - the authenticator to check
|
|
75
|
+
* @internal
|
|
76
|
+
*/
|
|
77
|
+
export function isWatAuthenticator(authenticator) {
|
|
78
|
+
return authenticator.type === 'wat';
|
|
79
|
+
}
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"Sisense",
|
|
12
12
|
"Compose SDK"
|
|
13
13
|
],
|
|
14
|
-
"version": "1.
|
|
14
|
+
"version": "1.4.1",
|
|
15
15
|
"type": "module",
|
|
16
16
|
"exports": "./dist/index.js",
|
|
17
17
|
"main": "./dist/index.js",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"author": "Sisense",
|
|
21
21
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@sisense/sdk-common": "^1.
|
|
23
|
+
"@sisense/sdk-common": "^1.4.1",
|
|
24
24
|
"fetch-intercept": "^2.4.0"
|
|
25
25
|
},
|
|
26
26
|
"scripts": {
|