@sisense/sdk-rest-client 1.21.0 → 1.23.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.
Files changed (51) hide show
  1. package/dist/authenticator.d.ts +1 -1
  2. package/dist/authenticator.js +4 -1
  3. package/dist/cjs/authenticator.d.ts +13 -0
  4. package/dist/cjs/authenticator.js +32 -0
  5. package/dist/cjs/base-authenticator.d.ts +16 -0
  6. package/dist/cjs/base-authenticator.js +34 -0
  7. package/dist/cjs/bearer-authenticator.d.ts +16 -0
  8. package/dist/cjs/bearer-authenticator.js +34 -0
  9. package/dist/cjs/constants.d.ts +1 -0
  10. package/dist/cjs/constants.js +4 -0
  11. package/dist/cjs/fusion-authenticator.d.ts +23 -0
  12. package/dist/cjs/fusion-authenticator.js +38 -0
  13. package/dist/cjs/helpers.d.ts +14 -0
  14. package/dist/cjs/helpers.js +41 -0
  15. package/dist/cjs/http-client.d.ts +19 -0
  16. package/dist/cjs/http-client.js +85 -0
  17. package/dist/cjs/index.d.ts +11 -0
  18. package/dist/cjs/index.js +39 -0
  19. package/dist/cjs/interceptors.d.ts +3 -0
  20. package/dist/cjs/interceptors.js +69 -0
  21. package/dist/cjs/interfaces.d.ts +9 -0
  22. package/dist/cjs/interfaces.js +2 -0
  23. package/dist/cjs/package.json +12 -0
  24. package/dist/cjs/password-authenticator.d.ts +18 -0
  25. package/dist/cjs/password-authenticator.js +70 -0
  26. package/dist/cjs/sso-authenticator.d.ts +18 -0
  27. package/dist/cjs/sso-authenticator.js +100 -0
  28. package/dist/cjs/translation/initialize-i18n.d.ts +2 -0
  29. package/dist/cjs/translation/initialize-i18n.js +14 -0
  30. package/dist/cjs/translation/resources/en.d.ts +30 -0
  31. package/dist/cjs/translation/resources/en.js +18 -0
  32. package/dist/cjs/translation/resources/index.d.ts +35 -0
  33. package/dist/cjs/translation/resources/index.js +16 -0
  34. package/dist/cjs/translation/resources/uk.d.ts +5 -0
  35. package/dist/cjs/translation/resources/uk.js +18 -0
  36. package/dist/cjs/translation/translatable-error.d.ts +6 -0
  37. package/dist/cjs/translation/translatable-error.js +18 -0
  38. package/dist/cjs/wat-authenticator.d.ts +19 -0
  39. package/dist/cjs/wat-authenticator.js +78 -0
  40. package/dist/helpers.js +2 -0
  41. package/dist/http-client.d.ts +1 -0
  42. package/dist/http-client.js +10 -4
  43. package/dist/index.d.ts +1 -0
  44. package/dist/password-authenticator.js +3 -1
  45. package/dist/sso-authenticator.js +8 -5
  46. package/dist/translation/resources/en.d.ts +14 -0
  47. package/dist/translation/resources/index.d.ts +6 -0
  48. package/dist/translation/resources/index.js +6 -0
  49. package/dist/tsconfig.prod.cjs.tsbuildinfo +1 -0
  50. package/dist/wat-authenticator.js +2 -1
  51. package/package.json +3 -3
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.isPasswordAuthenticator = exports.PasswordAuthenticator = void 0;
13
+ /// <reference lib="dom" />
14
+ const sdk_common_1 = require("@sisense/sdk-common");
15
+ const base_authenticator_js_1 = require("./base-authenticator.js");
16
+ const helpers_js_1 = require("./helpers.js");
17
+ const interceptors_js_1 = require("./interceptors.js");
18
+ class PasswordAuthenticator extends base_authenticator_js_1.BaseAuthenticator {
19
+ constructor(url, user, pass) {
20
+ super('password');
21
+ this._authheader = '';
22
+ this.url = `${(0, sdk_common_1.normalizeUrl)(url)}api/v1/authentication/login`;
23
+ const username = encodeURIComponent(user);
24
+ const password = encodeURIComponent(pass);
25
+ this.body = `username=${username}&password=${password}`;
26
+ }
27
+ authenticate() {
28
+ return __awaiter(this, void 0, void 0, function* () {
29
+ if (this._tried) {
30
+ return this._result;
31
+ }
32
+ this._tried = true;
33
+ try {
34
+ this._authenticating = true;
35
+ const response = yield fetch(this.url, {
36
+ method: 'POST',
37
+ headers: {
38
+ accept: 'application/json',
39
+ 'Content-Type': 'application/x-www-form-urlencoded',
40
+ },
41
+ body: this.body,
42
+ }).catch(interceptors_js_1.errorInterceptor);
43
+ if (response.ok) {
44
+ const json = yield response.json();
45
+ this._authheader = json.access_token;
46
+ }
47
+ }
48
+ finally {
49
+ this._resolve(!!this._authheader);
50
+ this._authenticating = false;
51
+ }
52
+ return this._result;
53
+ });
54
+ }
55
+ applyHeader(headers) {
56
+ const authHeader = 'Bearer ' + this._authheader;
57
+ (0, helpers_js_1.appendHeaders)(headers, { Authorization: authHeader });
58
+ }
59
+ }
60
+ exports.PasswordAuthenticator = PasswordAuthenticator;
61
+ /**
62
+ * Checks if an authenticator is a PasswordAuthenticator.
63
+ *
64
+ * @param authenticator - the authenticator to check
65
+ * @internal
66
+ */
67
+ function isPasswordAuthenticator(authenticator) {
68
+ return authenticator.type === 'password';
69
+ }
70
+ exports.isPasswordAuthenticator = isPasswordAuthenticator;
@@ -0,0 +1,18 @@
1
+ /// <reference lib="dom" />
2
+ import { Authenticator } from './interfaces.js';
3
+ import { BaseAuthenticator } from './base-authenticator.js';
4
+ export declare class SsoAuthenticator extends BaseAuthenticator {
5
+ readonly url: string;
6
+ private _enableSilentPreAuth;
7
+ constructor(url: string, enableSilentPreAuth?: boolean);
8
+ authenticate(silent?: boolean): Promise<boolean>;
9
+ private authenticateSilent;
10
+ private checkAuthentication;
11
+ }
12
+ /**
13
+ * Checks if the authenticator is SSO authenticator
14
+ *
15
+ * @param authenticator - authenticator to check
16
+ * @internal
17
+ */
18
+ export declare function isSsoAuthenticator(authenticator: Authenticator): authenticator is SsoAuthenticator;
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+ /// <reference lib="dom" />
3
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
4
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
5
+ return new (P || (P = Promise))(function (resolve, reject) {
6
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
7
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
8
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
9
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
10
+ });
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.isSsoAuthenticator = exports.SsoAuthenticator = void 0;
14
+ const sdk_common_1 = require("@sisense/sdk-common");
15
+ const base_authenticator_js_1 = require("./base-authenticator.js");
16
+ const translatable_error_js_1 = require("./translation/translatable-error.js");
17
+ const interceptors_js_1 = require("./interceptors.js");
18
+ const helpers_js_1 = require("./helpers.js");
19
+ class SsoAuthenticator extends base_authenticator_js_1.BaseAuthenticator {
20
+ constructor(url, enableSilentPreAuth = false) {
21
+ super('sso');
22
+ this.url = (0, sdk_common_1.normalizeUrl)(url);
23
+ this._enableSilentPreAuth = enableSilentPreAuth;
24
+ }
25
+ authenticate(silent = true) {
26
+ var _a;
27
+ return __awaiter(this, void 0, void 0, function* () {
28
+ try {
29
+ this._authenticating = true;
30
+ const { isAuthenticated, loginUrl: url } = yield this.checkAuthentication();
31
+ if (isAuthenticated) {
32
+ this._resolve(true);
33
+ return yield this._result;
34
+ }
35
+ const loginUrl = (0, helpers_js_1.addQueryParamsToUrl)(url, { return_to: window.location.href });
36
+ if (this._enableSilentPreAuth && silent) {
37
+ yield this.authenticateSilent(loginUrl);
38
+ const { isAuthenticated } = yield this.checkAuthentication();
39
+ if (isAuthenticated) {
40
+ this._resolve(true);
41
+ return yield this._result;
42
+ }
43
+ }
44
+ (_a = window === null || window === void 0 ? void 0 : window.location) === null || _a === void 0 ? void 0 : _a.replace(loginUrl);
45
+ }
46
+ finally {
47
+ this._resolve(false);
48
+ this._authenticating = false;
49
+ }
50
+ return this._result;
51
+ });
52
+ }
53
+ authenticateSilent(loginUrl) {
54
+ return __awaiter(this, void 0, void 0, function* () {
55
+ const iframe = document.createElement('iframe');
56
+ iframe.style.display = 'none';
57
+ document.body.appendChild(iframe);
58
+ iframe.src = loginUrl;
59
+ yield new Promise((resolve) => {
60
+ iframe.onload = () => {
61
+ resolve(true);
62
+ };
63
+ });
64
+ document.body.removeChild(iframe);
65
+ });
66
+ }
67
+ checkAuthentication() {
68
+ return __awaiter(this, void 0, void 0, function* () {
69
+ const fetchUrl = `${this.url}api/auth/isauth`;
70
+ const response = yield fetch(fetchUrl, {
71
+ headers: { Internal: 'true' },
72
+ credentials: 'include',
73
+ }).catch(interceptors_js_1.errorInterceptor);
74
+ const result = yield response.json();
75
+ if (!result.isAuthenticated) {
76
+ if (!result.ssoEnabled) {
77
+ throw new translatable_error_js_1.TranslatableError('errors.ssoNotEnabled');
78
+ }
79
+ if (!result.loginUrl) {
80
+ throw new translatable_error_js_1.TranslatableError('errors.ssoNoLoginUrl');
81
+ }
82
+ }
83
+ return {
84
+ isAuthenticated: result.isAuthenticated,
85
+ loginUrl: result.loginUrl || '',
86
+ };
87
+ });
88
+ }
89
+ }
90
+ exports.SsoAuthenticator = SsoAuthenticator;
91
+ /**
92
+ * Checks if the authenticator is SSO authenticator
93
+ *
94
+ * @param authenticator - authenticator to check
95
+ * @internal
96
+ */
97
+ function isSsoAuthenticator(authenticator) {
98
+ return authenticator.type === 'sso';
99
+ }
100
+ exports.isSsoAuthenticator = isSsoAuthenticator;
@@ -0,0 +1,2 @@
1
+ export declare function initializeI18n(): import("@sisense/sdk-common").I18NextInitResult;
2
+ export declare const i18nextInstance: import("i18next").i18n;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.i18nextInstance = exports.initializeI18n = void 0;
4
+ const sdk_common_1 = require("@sisense/sdk-common");
5
+ const index_js_1 = require("./resources/index.js");
6
+ function initializeI18n() {
7
+ return (0, sdk_common_1.initI18next)({
8
+ resource: index_js_1.resources,
9
+ language: 'en',
10
+ namespace: index_js_1.PACKAGE_NAMESPACE,
11
+ });
12
+ }
13
+ exports.initializeI18n = initializeI18n;
14
+ exports.i18nextInstance = initializeI18n().i18nextInstance;
@@ -0,0 +1,30 @@
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
+ ssoNoLoginUrl: string;
10
+ passwordAuthFailed: string;
11
+ tokenAuthFailed: string;
12
+ responseError_onlyStatus: string;
13
+ responseError_withStatusText: string;
14
+ };
15
+ };
16
+ /**
17
+ * A reference type containing all currently used translation keys.
18
+ * This type serves as a complete resource for creating custom translations,
19
+ * ensuring that all required keys are present and included.
20
+ * It can also be used as Partial to make sure custom translation does not contain any typos.
21
+ *
22
+ * @example
23
+ * ```typescript
24
+ * import { TranslationDictionary } from '@sisense/sdk-rest-client';
25
+ *
26
+ * const customTranslationResources: Partial<TranslationDictionary> = {
27
+ * ```
28
+ * @internal
29
+ */
30
+ export declare type TranslationDictionary = typeof translation;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.translation = void 0;
4
+ /**
5
+ * Translation dictionary for English language.
6
+ */
7
+ exports.translation = {
8
+ errorPrefix: '[request-error]',
9
+ errors: {
10
+ networkError: "Network error. Probably you forgot to add your domain to 'CORS Allowed Origins' in Sisense Admin Panel -> Security Settings.",
11
+ ssoNotEnabled: 'SSO is not enabled on target instance, please choose another authentication method.',
12
+ ssoNoLoginUrl: 'Can not fetch login URL on target instance. Check SSO settings.',
13
+ passwordAuthFailed: '$t(errorPrefix) Username and password authentication was not successful. Check credentials.',
14
+ tokenAuthFailed: '$t(errorPrefix) Token authentication was not successful. Check credentials.',
15
+ responseError_onlyStatus: '$t(errorPrefix) Status: {{status}}',
16
+ responseError_withStatusText: '$t(errorPrefix) Status: {{status}} - {{statusText}}',
17
+ },
18
+ };
@@ -0,0 +1,35 @@
1
+ import { TranslationDictionary } from './en.js';
2
+ export type { TranslationDictionary };
3
+ /**
4
+ * A reference to the namespace of the translation resources.
5
+ * This namespace is used to access the translation resources in the i18next instance.
6
+ *
7
+ * @internal
8
+ */
9
+ export declare const PACKAGE_NAMESPACE: "sdkRestClient";
10
+ export declare const resources: {
11
+ en: {
12
+ errorPrefix: string;
13
+ errors: {
14
+ networkError: string;
15
+ ssoNotEnabled: string;
16
+ ssoNoLoginUrl: string;
17
+ passwordAuthFailed: string;
18
+ tokenAuthFailed: string;
19
+ responseError_onlyStatus: string;
20
+ responseError_withStatusText: string;
21
+ };
22
+ };
23
+ uk: {
24
+ errorPrefix: string;
25
+ errors: {
26
+ networkError: string;
27
+ ssoNotEnabled: string;
28
+ ssoNoLoginUrl: string;
29
+ passwordAuthFailed: string;
30
+ tokenAuthFailed: string;
31
+ responseError_onlyStatus: string;
32
+ responseError_withStatusText: string;
33
+ };
34
+ };
35
+ };
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resources = exports.PACKAGE_NAMESPACE = void 0;
4
+ const en_js_1 = require("./en.js");
5
+ const uk_js_1 = require("./uk.js");
6
+ /**
7
+ * A reference to the namespace of the translation resources.
8
+ * This namespace is used to access the translation resources in the i18next instance.
9
+ *
10
+ * @internal
11
+ */
12
+ exports.PACKAGE_NAMESPACE = 'sdkRestClient';
13
+ exports.resources = {
14
+ en: en_js_1.translation,
15
+ uk: uk_js_1.translation,
16
+ };
@@ -0,0 +1,5 @@
1
+ import { TranslationDictionary } from './index.js';
2
+ /**
3
+ * Translation dictionary for Ukrainian language.
4
+ */
5
+ export declare const translation: TranslationDictionary;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.translation = void 0;
4
+ /**
5
+ * Translation dictionary for Ukrainian language.
6
+ */
7
+ exports.translation = {
8
+ errorPrefix: '[request-error]',
9
+ errors: {
10
+ networkError: 'Помилка мережі. Можливо ви забули додати свій домен до «CORS Allowed Origins» в панелі адміністратора Sisense -> Security Settings.',
11
+ ssoNotEnabled: 'SSO не ввімкнено на цьому сервері, будь ласка, виберіть інший метод аутентифікації',
12
+ ssoNoLoginUrl: 'Неможливо отримати loginUrl з сервера. Перевірте налаштування SSO.',
13
+ passwordAuthFailed: '$t(errorPrefix) Помилка автентифікації за допомогою імені користувача та пароля. Перевірте дані для входу.',
14
+ tokenAuthFailed: '$t(errorPrefix) Помилка автентифікації за допомогою токена. Перевірте дані для входу.',
15
+ responseError_onlyStatus: '$t(errorPrefix) Статус: {{status}}',
16
+ responseError_withStatusText: '$t(errorPrefix) Статус: {{status}} - {{statusText}}',
17
+ },
18
+ };
@@ -0,0 +1,6 @@
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
+ get status(): string;
6
+ }
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TranslatableError = void 0;
4
+ const sdk_common_1 = require("@sisense/sdk-common");
5
+ const initialize_i18n_js_1 = require("./initialize-i18n.js");
6
+ const index_js_1 = require("./resources/index.js");
7
+ class TranslatableError extends sdk_common_1.AbstractTranslatableError {
8
+ constructor(translationKey, interpolationOptions) {
9
+ super(index_js_1.PACKAGE_NAMESPACE, {
10
+ key: translationKey,
11
+ interpolationOptions: interpolationOptions,
12
+ }, initialize_i18n_js_1.i18nextInstance.t);
13
+ }
14
+ get status() {
15
+ return this.interpolationOptions.status;
16
+ }
17
+ }
18
+ exports.TranslatableError = TranslatableError;
@@ -0,0 +1,19 @@
1
+ /// <reference lib="dom" />
2
+ import { Authenticator } from './interfaces.js';
3
+ import { BaseAuthenticator } from './base-authenticator.js';
4
+ export declare class WatAuthenticator extends BaseAuthenticator {
5
+ private _initialiser;
6
+ private _webSessionToken;
7
+ private readonly url;
8
+ private readonly body;
9
+ constructor(url: string, wat: string);
10
+ authenticate(): Promise<boolean>;
11
+ applyHeader(headers: HeadersInit): void;
12
+ }
13
+ /**
14
+ * Checks if an authenticator is a WatAuthenticator.
15
+ *
16
+ * @param authenticator - the authenticator to check
17
+ * @internal
18
+ */
19
+ export declare function isWatAuthenticator(authenticator: Authenticator): authenticator is WatAuthenticator;
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ /// <reference lib="dom" />
3
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
4
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
5
+ return new (P || (P = Promise))(function (resolve, reject) {
6
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
7
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
8
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
9
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
10
+ });
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.isWatAuthenticator = exports.WatAuthenticator = void 0;
14
+ const sdk_common_1 = require("@sisense/sdk-common");
15
+ const base_authenticator_js_1 = require("./base-authenticator.js");
16
+ const helpers_js_1 = require("./helpers.js");
17
+ const translatable_error_js_1 = require("./translation/translatable-error.js");
18
+ const interceptors_js_1 = require("./interceptors.js");
19
+ class WatAuthenticator extends base_authenticator_js_1.BaseAuthenticator {
20
+ constructor(url, wat) {
21
+ super('wat');
22
+ this.url = `${(0, sdk_common_1.normalizeUrl)(url)}api/v1/wat/sessionToken`;
23
+ this.body = `{"webAccessToken": "${wat}"}`;
24
+ }
25
+ authenticate() {
26
+ return __awaiter(this, void 0, void 0, function* () {
27
+ if (this._tried) {
28
+ return this._result;
29
+ }
30
+ this._tried = true;
31
+ try {
32
+ this._authenticating = true;
33
+ const response = yield fetch(this.url, {
34
+ method: 'POST',
35
+ headers: {
36
+ accept: 'application/json',
37
+ 'Content-Type': 'application/json',
38
+ },
39
+ body: this.body,
40
+ }).catch(interceptors_js_1.errorInterceptor);
41
+ if (response.ok) {
42
+ const responseJson = yield response.json();
43
+ this._initialiser = responseJson.initialiser;
44
+ this._webSessionToken = responseJson.webSessionToken;
45
+ this._resolve(true);
46
+ }
47
+ }
48
+ catch (e) {
49
+ // rather than returning empty catch block
50
+ // throw an error to be caught by Sisense context provider
51
+ throw new translatable_error_js_1.TranslatableError('errors.tokenAuthFailed');
52
+ }
53
+ finally {
54
+ this._resolve(false);
55
+ this._authenticating = false;
56
+ }
57
+ return this._result;
58
+ });
59
+ }
60
+ applyHeader(headers) {
61
+ if (!!this._webSessionToken && !!this._initialiser) {
62
+ const authHeader = this._webSessionToken;
63
+ const initialiserHeader = this._initialiser;
64
+ (0, helpers_js_1.appendHeaders)(headers, { Authorization: authHeader, Initialiser: initialiserHeader });
65
+ }
66
+ }
67
+ }
68
+ exports.WatAuthenticator = WatAuthenticator;
69
+ /**
70
+ * Checks if an authenticator is a WatAuthenticator.
71
+ *
72
+ * @param authenticator - the authenticator to check
73
+ * @internal
74
+ */
75
+ function isWatAuthenticator(authenticator) {
76
+ return authenticator.type === 'wat';
77
+ }
78
+ exports.isWatAuthenticator = isWatAuthenticator;
package/dist/helpers.js CHANGED
@@ -13,6 +13,8 @@ export const appendHeaders = (existingHeaders, additionalHeaders) => {
13
13
  }
14
14
  };
15
15
  export const addQueryParamsToUrl = (url, params) => {
16
+ if (!url || typeof url !== 'string')
17
+ return url;
16
18
  // can't just append to the url because it might already have a query string
17
19
  const urlObject = new URL(url);
18
20
  for (const [paramName, paramValue] of Object.entries(params)) {
@@ -13,6 +13,7 @@ export declare class HttpClient {
13
13
  login(): Promise<boolean>;
14
14
  call<T>(url: string, config: RequestInit, requestConfig?: HttpClientRequestConfig): Promise<T | undefined>;
15
15
  post<T = unknown>(endpoint: string, data: unknown, options?: RequestInit, abortSignal?: AbortSignal, config?: HttpClientRequestConfig): Promise<T | undefined>;
16
+ patch<T = unknown>(endpoint: string, data: unknown, options?: RequestInit, abortSignal?: AbortSignal, config?: HttpClientRequestConfig): Promise<T | undefined>;
16
17
  get<T = unknown>(endpoint: string, request?: RequestInit, config?: HttpClientRequestConfig): Promise<T | undefined>;
17
18
  delete<T = void>(endpoint: string, request?: RequestInit, config?: HttpClientRequestConfig): Promise<T | undefined>;
18
19
  }
@@ -7,15 +7,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
+ /// <reference lib="dom" />
11
+ import { normalizeUrl } from '@sisense/sdk-common';
10
12
  import { getResponseInterceptor, errorInterceptor } from './interceptors.js';
11
13
  import { isSsoAuthenticator } from './sso-authenticator.js';
12
14
  import { addQueryParamsToUrl } from './helpers.js';
13
15
  export class HttpClient {
14
16
  constructor(url, auth, env) {
15
- if (!url.endsWith('/')) {
16
- url += '/';
17
- }
18
- this.url = url;
17
+ this.url = normalizeUrl(url);
19
18
  this.auth = auth;
20
19
  this.env = env;
21
20
  }
@@ -66,6 +65,13 @@ export class HttpClient {
66
65
  }, signal: abortSignal }, options);
67
66
  return this.call(this.url + endpoint, request, config);
68
67
  }
68
+ patch(endpoint, data, options = {}, abortSignal, config) {
69
+ const request = Object.assign({ method: 'PATCH', body: ((config === null || config === void 0 ? void 0 : config.nonJSONBody) ? data : JSON.stringify(data)), headers: {
70
+ Accept: 'application/json, text/plain, */*',
71
+ 'Content-Type': 'application/json;charset=UTF-8',
72
+ }, signal: abortSignal }, options);
73
+ return this.call(this.url + endpoint, request, config);
74
+ }
69
75
  get(endpoint, request = {}, config) {
70
76
  return this.call(this.url + endpoint, Object.assign(Object.assign({}, request), { method: 'GET' }), config);
71
77
  }
package/dist/index.d.ts CHANGED
@@ -8,3 +8,4 @@ export { WatAuthenticator, isWatAuthenticator } from './wat-authenticator.js';
8
8
  export { getAuthenticator } from './authenticator.js';
9
9
  export { isAuthTokenPending } from './helpers.js';
10
10
  export { HttpClient } from './http-client.js';
11
+ export type { TranslationDictionary, PACKAGE_NAMESPACE as translationNamespace, } from './translation/resources/index.js';
@@ -7,6 +7,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
+ /// <reference lib="dom" />
11
+ import { normalizeUrl } from '@sisense/sdk-common';
10
12
  import { BaseAuthenticator } from './base-authenticator.js';
11
13
  import { appendHeaders } from './helpers.js';
12
14
  import { errorInterceptor } from './interceptors.js';
@@ -14,7 +16,7 @@ export class PasswordAuthenticator extends BaseAuthenticator {
14
16
  constructor(url, user, pass) {
15
17
  super('password');
16
18
  this._authheader = '';
17
- this.url = `${url}${!url.endsWith('/') ? '/' : ''}api/v1/authentication/login`;
19
+ this.url = `${normalizeUrl(url)}api/v1/authentication/login`;
18
20
  const username = encodeURIComponent(user);
19
21
  const password = encodeURIComponent(pass);
20
22
  this.body = `username=${username}&password=${password}`;
@@ -8,13 +8,15 @@ 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 { normalizeUrl } from '@sisense/sdk-common';
11
12
  import { BaseAuthenticator } from './base-authenticator.js';
12
13
  import { TranslatableError } from './translation/translatable-error.js';
13
14
  import { errorInterceptor } from './interceptors.js';
15
+ import { addQueryParamsToUrl } from './helpers.js';
14
16
  export class SsoAuthenticator extends BaseAuthenticator {
15
17
  constructor(url, enableSilentPreAuth = false) {
16
18
  super('sso');
17
- this.url = url;
19
+ this.url = normalizeUrl(url);
18
20
  this._enableSilentPreAuth = enableSilentPreAuth;
19
21
  }
20
22
  authenticate(silent = true) {
@@ -22,11 +24,12 @@ export class SsoAuthenticator extends BaseAuthenticator {
22
24
  return __awaiter(this, void 0, void 0, function* () {
23
25
  try {
24
26
  this._authenticating = true;
25
- const { isAuthenticated, loginUrl } = yield this.checkAuthentication();
27
+ const { isAuthenticated, loginUrl: url } = yield this.checkAuthentication();
26
28
  if (isAuthenticated) {
27
29
  this._resolve(true);
28
30
  return yield this._result;
29
31
  }
32
+ const loginUrl = addQueryParamsToUrl(url, { return_to: window.location.href });
30
33
  if (this._enableSilentPreAuth && silent) {
31
34
  yield this.authenticateSilent(loginUrl);
32
35
  const { isAuthenticated } = yield this.checkAuthentication();
@@ -49,7 +52,7 @@ export class SsoAuthenticator extends BaseAuthenticator {
49
52
  const iframe = document.createElement('iframe');
50
53
  iframe.style.display = 'none';
51
54
  document.body.appendChild(iframe);
52
- iframe.src = `${loginUrl}?return_to=${window.location.href}`;
55
+ iframe.src = loginUrl;
53
56
  yield new Promise((resolve) => {
54
57
  iframe.onload = () => {
55
58
  resolve(true);
@@ -60,7 +63,7 @@ export class SsoAuthenticator extends BaseAuthenticator {
60
63
  }
61
64
  checkAuthentication() {
62
65
  return __awaiter(this, void 0, void 0, function* () {
63
- const fetchUrl = `${this.url}${!this.url.endsWith('/') ? '/' : ''}api/auth/isauth`;
66
+ const fetchUrl = `${this.url}api/auth/isauth`;
64
67
  const response = yield fetch(fetchUrl, {
65
68
  headers: { Internal: 'true' },
66
69
  credentials: 'include',
@@ -76,7 +79,7 @@ export class SsoAuthenticator extends BaseAuthenticator {
76
79
  }
77
80
  return {
78
81
  isAuthenticated: result.isAuthenticated,
79
- loginUrl: `${result.loginUrl}?return_to=${window.location.href}`,
82
+ loginUrl: result.loginUrl || '',
80
83
  };
81
84
  });
82
85
  }
@@ -13,4 +13,18 @@ export declare const translation: {
13
13
  responseError_withStatusText: string;
14
14
  };
15
15
  };
16
+ /**
17
+ * A reference type containing all currently used translation keys.
18
+ * This type serves as a complete resource for creating custom translations,
19
+ * ensuring that all required keys are present and included.
20
+ * It can also be used as Partial to make sure custom translation does not contain any typos.
21
+ *
22
+ * @example
23
+ * ```typescript
24
+ * import { TranslationDictionary } from '@sisense/sdk-rest-client';
25
+ *
26
+ * const customTranslationResources: Partial<TranslationDictionary> = {
27
+ * ```
28
+ * @internal
29
+ */
16
30
  export declare type TranslationDictionary = typeof translation;
@@ -1,5 +1,11 @@
1
1
  import { TranslationDictionary } from './en.js';
2
2
  export type { TranslationDictionary };
3
+ /**
4
+ * A reference to the namespace of the translation resources.
5
+ * This namespace is used to access the translation resources in the i18next instance.
6
+ *
7
+ * @internal
8
+ */
3
9
  export declare const PACKAGE_NAMESPACE: "sdkRestClient";
4
10
  export declare const resources: {
5
11
  en: {
@@ -1,5 +1,11 @@
1
1
  import { translation as enDictionary } from './en.js';
2
2
  import { translation as ukDictionary } from './uk.js';
3
+ /**
4
+ * A reference to the namespace of the translation resources.
5
+ * This namespace is used to access the translation resources in the i18next instance.
6
+ *
7
+ * @internal
8
+ */
3
9
  export const PACKAGE_NAMESPACE = 'sdkRestClient';
4
10
  export const resources = {
5
11
  en: enDictionary,