@sisense/sdk-rest-client 0.15.0 → 0.16.0
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-client.d.ts +3 -1
- package/dist/http-client.js +2 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/interceptors.js +12 -12
- package/dist/sso-authenticator.js +2 -1
- package/dist/translation/initialize-i18n.d.ts +2 -0
- package/dist/translation/initialize-i18n.js +10 -0
- package/dist/translation/resources/en.d.ts +15 -0
- package/dist/translation/resources/en.js +14 -0
- package/dist/translation/resources/index.d.ts +27 -0
- package/dist/translation/resources/index.js +7 -0
- package/dist/translation/resources/uk.d.ts +5 -0
- package/dist/translation/resources/uk.js +14 -0
- package/dist/translation/translatable-error.d.ts +5 -0
- package/dist/translation/translatable-error.js +11 -0
- package/package.json +2 -1
package/dist/http-client.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
/// <reference lib="dom" />
|
|
2
2
|
import { Authenticator } from './interfaces.js';
|
|
3
3
|
export interface HttpClientRequestConfig {
|
|
4
|
-
skipTrackingParam
|
|
4
|
+
skipTrackingParam?: boolean;
|
|
5
|
+
nonJSONBody?: boolean;
|
|
6
|
+
returnBlob?: boolean;
|
|
5
7
|
}
|
|
6
8
|
export declare class HttpClient {
|
|
7
9
|
readonly auth: Authenticator;
|
package/dist/http-client.js
CHANGED
|
@@ -74,7 +74,7 @@ export class HttpClient {
|
|
|
74
74
|
return undefined;
|
|
75
75
|
}
|
|
76
76
|
try {
|
|
77
|
-
return (yield response.json());
|
|
77
|
+
return ((requestConfig === null || requestConfig === void 0 ? void 0 : requestConfig.returnBlob) ? yield response.blob() : yield response.json());
|
|
78
78
|
}
|
|
79
79
|
catch (e) {
|
|
80
80
|
// some of APIs in Sisense returns 200 with empty body - so it's not possible
|
|
@@ -91,7 +91,7 @@ export class HttpClient {
|
|
|
91
91
|
// eslint-disable-next-line max-params
|
|
92
92
|
post(endpoint, data, options = {}, abortSignal, config) {
|
|
93
93
|
return __awaiter(this, void 0, void 0, function* () {
|
|
94
|
-
const request = Object.assign({ method: 'POST', body: JSON.stringify(data), headers: {
|
|
94
|
+
const request = Object.assign({ method: 'POST', body: ((config === null || config === void 0 ? void 0 : config.nonJSONBody) ? data : JSON.stringify(data)), headers: {
|
|
95
95
|
Accept: 'application/json, text/plain, */*',
|
|
96
96
|
'Content-Type': 'application/json;charset=UTF-8',
|
|
97
97
|
}, signal: abortSignal }, options);
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/interceptors.js
CHANGED
|
@@ -2,10 +2,14 @@ import { BearerAuthenticator } from './bearer-authenticator.js';
|
|
|
2
2
|
import { WatAuthenticator } from './wat-authenticator.js';
|
|
3
3
|
import { PasswordAuthenticator } from './password-authenticator.js';
|
|
4
4
|
import { SsoAuthenticator } from './sso-authenticator.js';
|
|
5
|
-
import {
|
|
5
|
+
import { TranslatableError } from './translation/translatable-error.js';
|
|
6
6
|
export function handleErrorResponse(response) {
|
|
7
7
|
if (!response.ok) {
|
|
8
|
-
throw
|
|
8
|
+
throw new TranslatableError('errors.responseError', {
|
|
9
|
+
status: response.status.toString(),
|
|
10
|
+
statusText: response.statusText,
|
|
11
|
+
context: response.statusText ? 'withStatusText' : 'onlyStatus',
|
|
12
|
+
});
|
|
9
13
|
}
|
|
10
14
|
return response;
|
|
11
15
|
}
|
|
@@ -13,18 +17,14 @@ export function handleUnauthorizedResponse(response, auth) {
|
|
|
13
17
|
auth.invalidate();
|
|
14
18
|
// skip login redirect for token auth
|
|
15
19
|
if (auth instanceof PasswordAuthenticator) {
|
|
16
|
-
throw
|
|
20
|
+
throw new TranslatableError('errors.passwordAuthFailed');
|
|
17
21
|
}
|
|
18
22
|
if (auth instanceof BearerAuthenticator || auth instanceof WatAuthenticator) {
|
|
19
|
-
throw
|
|
23
|
+
throw new TranslatableError('errors.tokenAuthFailed');
|
|
20
24
|
}
|
|
21
|
-
if (auth instanceof SsoAuthenticator) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
void auth.authenticate();
|
|
25
|
-
}
|
|
26
|
-
// throw error to display while waiting for redirect
|
|
27
|
-
throw Error(`${ERROR_PREFIX} Not authenticated. Please wait for redirect or check SSO provider.`);
|
|
25
|
+
if (auth instanceof SsoAuthenticator && !auth.isAuthenticating()) {
|
|
26
|
+
// try to reauthenticate
|
|
27
|
+
void auth.authenticate();
|
|
28
28
|
}
|
|
29
29
|
return response;
|
|
30
30
|
}
|
|
@@ -45,5 +45,5 @@ export function isNetworkError(responseError) {
|
|
|
45
45
|
* @returns A promise that rejects with an error message.
|
|
46
46
|
*/
|
|
47
47
|
export function handleNetworkError() {
|
|
48
|
-
return Promise.reject(new
|
|
48
|
+
return Promise.reject(new TranslatableError('errors.networkError'));
|
|
49
49
|
}
|
|
@@ -8,6 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
+
import { TranslatableError } from './translation/translatable-error.js';
|
|
11
12
|
export class SsoAuthenticator {
|
|
12
13
|
constructor(url) {
|
|
13
14
|
this._valid = true;
|
|
@@ -40,7 +41,7 @@ export class SsoAuthenticator {
|
|
|
40
41
|
if (!res.isAuthenticated) {
|
|
41
42
|
// SSO is disabled on instance, do not proceed
|
|
42
43
|
if (!res.ssoEnabled)
|
|
43
|
-
throw new
|
|
44
|
+
throw new TranslatableError('errors.ssoNotEnabled');
|
|
44
45
|
// redirect to login page
|
|
45
46
|
window.location.href = `${res.loginUrl}?return_to=${window.location.href}`;
|
|
46
47
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { initI18next } from '@sisense/sdk-common';
|
|
2
|
+
import { resources, PACKAGE_NAMESPACE } from './resources/index.js';
|
|
3
|
+
export function initializeI18n() {
|
|
4
|
+
return initI18next({
|
|
5
|
+
resource: resources,
|
|
6
|
+
language: 'en',
|
|
7
|
+
namespace: PACKAGE_NAMESPACE,
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
export const { i18nextInstance } = initializeI18n();
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Translation dictionary for English language.
|
|
3
|
+
*/
|
|
4
|
+
export declare const translation: {
|
|
5
|
+
errorPrefix: string;
|
|
6
|
+
errors: {
|
|
7
|
+
networkError: string;
|
|
8
|
+
ssoNotEnabled: string;
|
|
9
|
+
passwordAuthFailed: string;
|
|
10
|
+
tokenAuthFailed: string;
|
|
11
|
+
responseError_onlyStatus: string;
|
|
12
|
+
responseError_withStatusText: string;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
export declare type TranslationDictionary = typeof translation;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Translation dictionary for English language.
|
|
3
|
+
*/
|
|
4
|
+
export const translation = {
|
|
5
|
+
errorPrefix: '[request-error]',
|
|
6
|
+
errors: {
|
|
7
|
+
networkError: "Network error. Probably you forgot to add your domain to 'CORS Allowed Origins' in Sisense Admin Panel -> Security Settings.",
|
|
8
|
+
ssoNotEnabled: 'SSO is not enabled on target instance, please choose another authentication method',
|
|
9
|
+
passwordAuthFailed: '$t(errorPrefix) Username and password authentication was not successful. Check credentials.',
|
|
10
|
+
tokenAuthFailed: '$t(errorPrefix) Token authentication was not successful. Check credentials.',
|
|
11
|
+
responseError_onlyStatus: '$t(errorPrefix) Status: {{status}}',
|
|
12
|
+
responseError_withStatusText: '$t(errorPrefix) Status: {{status}} - {{statusText}}',
|
|
13
|
+
},
|
|
14
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { TranslationDictionary } from './en.js';
|
|
2
|
+
export type { TranslationDictionary };
|
|
3
|
+
export declare const PACKAGE_NAMESPACE: "sdkRestClient";
|
|
4
|
+
export declare const resources: {
|
|
5
|
+
en: {
|
|
6
|
+
errorPrefix: string;
|
|
7
|
+
errors: {
|
|
8
|
+
networkError: string;
|
|
9
|
+
ssoNotEnabled: string;
|
|
10
|
+
passwordAuthFailed: string;
|
|
11
|
+
tokenAuthFailed: string;
|
|
12
|
+
responseError_onlyStatus: string;
|
|
13
|
+
responseError_withStatusText: string;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
uk: {
|
|
17
|
+
errorPrefix: string;
|
|
18
|
+
errors: {
|
|
19
|
+
networkError: string;
|
|
20
|
+
ssoNotEnabled: string;
|
|
21
|
+
passwordAuthFailed: string;
|
|
22
|
+
tokenAuthFailed: string;
|
|
23
|
+
responseError_onlyStatus: string;
|
|
24
|
+
responseError_withStatusText: string;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Translation dictionary for Ukrainian language.
|
|
3
|
+
*/
|
|
4
|
+
export const translation = {
|
|
5
|
+
errorPrefix: '[request-error]',
|
|
6
|
+
errors: {
|
|
7
|
+
networkError: 'Помилка мережі. Можливо ви забули додати свій домен до «CORS Allowed Origins» в панелі адміністратора Sisense -> Security Settings.',
|
|
8
|
+
ssoNotEnabled: 'SSO не ввімкнено на цьому сервері, будь ласка, виберіть інший метод аутентифікації',
|
|
9
|
+
passwordAuthFailed: '$t(errorPrefix) Помилка автентифікації за допомогою імені користувача та пароля. Перевірте дані для входу.',
|
|
10
|
+
tokenAuthFailed: '$t(errorPrefix) Помилка автентифікації за допомогою токена. Перевірте дані для входу.',
|
|
11
|
+
responseError_onlyStatus: '$t(errorPrefix) Статус: {{status}}',
|
|
12
|
+
responseError_withStatusText: '$t(errorPrefix) Статус: {{status}} - {{statusText}}',
|
|
13
|
+
},
|
|
14
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { AbstractTranslatableError } from '@sisense/sdk-common';
|
|
2
|
+
import { PACKAGE_NAMESPACE } from './resources/index.js';
|
|
3
|
+
export declare class TranslatableError extends AbstractTranslatableError<typeof PACKAGE_NAMESPACE> {
|
|
4
|
+
constructor(translationKey: string, interpolationOptions?: Record<string, string>);
|
|
5
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { AbstractTranslatableError } from '@sisense/sdk-common';
|
|
2
|
+
import { i18nextInstance } from './initialize-i18n.js';
|
|
3
|
+
import { PACKAGE_NAMESPACE } from './resources/index.js';
|
|
4
|
+
export class TranslatableError extends AbstractTranslatableError {
|
|
5
|
+
constructor(translationKey, interpolationOptions) {
|
|
6
|
+
super(PACKAGE_NAMESPACE, {
|
|
7
|
+
key: translationKey,
|
|
8
|
+
interpolationOptions: interpolationOptions,
|
|
9
|
+
}, i18nextInstance.t);
|
|
10
|
+
}
|
|
11
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sisense/sdk-rest-client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": "./dist/index.js",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
"author": "Sisense",
|
|
10
10
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
11
11
|
"dependencies": {
|
|
12
|
+
"@sisense/sdk-common": "^0.16.0",
|
|
12
13
|
"fetch-intercept": "^2.4.0"
|
|
13
14
|
},
|
|
14
15
|
"scripts": {
|