@sisense/sdk-rest-client 1.17.0 → 1.18.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.
@@ -7,6 +7,7 @@ declare type AuthenticatorConfig = {
7
7
  wat?: string | null;
8
8
  ssoEnabled?: boolean;
9
9
  enableSilentPreAuth?: boolean;
10
+ useFusionAuth?: boolean;
10
11
  };
11
- export declare function getAuthenticator({ url, username, password, token, wat, ssoEnabled, enableSilentPreAuth, }: AuthenticatorConfig): Authenticator | null;
12
+ export declare function getAuthenticator({ url, username, password, token, wat, ssoEnabled, enableSilentPreAuth, useFusionAuth, }: AuthenticatorConfig): Authenticator | null;
12
13
  export {};
@@ -2,7 +2,8 @@ import { PasswordAuthenticator } from './password-authenticator.js';
2
2
  import { BearerAuthenticator } from './bearer-authenticator.js';
3
3
  import { WatAuthenticator } from './wat-authenticator.js';
4
4
  import { SsoAuthenticator } from './sso-authenticator.js';
5
- export function getAuthenticator({ url, username, password, token, wat, ssoEnabled = false, enableSilentPreAuth = false, }) {
5
+ import { FusionAuthenticator } from './fusion-authenticator.js';
6
+ export function getAuthenticator({ url, username, password, token, wat, ssoEnabled = false, enableSilentPreAuth = false, useFusionAuth = false, }) {
6
7
  // sso overrides all other auth methods
7
8
  if (ssoEnabled) {
8
9
  return new SsoAuthenticator(url, enableSilentPreAuth);
@@ -17,5 +18,8 @@ export function getAuthenticator({ url, username, password, token, wat, ssoEnabl
17
18
  if (wat) {
18
19
  return new WatAuthenticator(url, wat);
19
20
  }
21
+ if (useFusionAuth) {
22
+ return new FusionAuthenticator();
23
+ }
20
24
  return null;
21
25
  }
@@ -0,0 +1,23 @@
1
+ /// <reference lib="dom" />
2
+ import { Authenticator } from './interfaces.js';
3
+ import { BaseAuthenticator } from './base-authenticator.js';
4
+ export declare type FusionWindow = Window & typeof globalThis & {
5
+ prism: {
6
+ user: {
7
+ _id: string | undefined;
8
+ };
9
+ } | undefined;
10
+ };
11
+ export declare class FusionAuthenticator extends BaseAuthenticator {
12
+ constructor();
13
+ private antiCsrfToken;
14
+ authenticate(): Promise<boolean>;
15
+ applyHeader(headers: HeadersInit): void;
16
+ }
17
+ /**
18
+ * Checks if the authenticator is SSO authenticator
19
+ *
20
+ * @param authenticator - authenticator to check
21
+ * @internal
22
+ */
23
+ export declare function isFusionAuthenticator(authenticator: Authenticator): authenticator is FusionAuthenticator;
@@ -0,0 +1,33 @@
1
+ /// <reference lib="dom" />
2
+ import { BaseAuthenticator } from './base-authenticator.js';
3
+ import { appendHeaders } from './helpers.js';
4
+ export class FusionAuthenticator extends BaseAuthenticator {
5
+ constructor() {
6
+ super('fusion');
7
+ }
8
+ authenticate() {
9
+ var _a, _b, _c, _d, _e;
10
+ const hasUser = !!((_b = (_a = window.prism) === null || _a === void 0 ? void 0 : _a.user) === null || _b === void 0 ? void 0 : _b._id);
11
+ this._resolve(hasUser);
12
+ const antiCsrfToken = (_e = (_d = (_c = window.document) === null || _c === void 0 ? void 0 : _c.cookie) === null || _d === void 0 ? void 0 : _d.match(/(?:^|;\s*)XSRF-TOKEN=([^;]+)/)) === null || _e === void 0 ? void 0 : _e[1];
13
+ if (antiCsrfToken)
14
+ this.antiCsrfToken = antiCsrfToken;
15
+ return this._result;
16
+ }
17
+ applyHeader(headers) {
18
+ if (this.antiCsrfToken) {
19
+ appendHeaders(headers, {
20
+ 'X-Xsrf-Token': this.antiCsrfToken,
21
+ });
22
+ }
23
+ }
24
+ }
25
+ /**
26
+ * Checks if the authenticator is SSO authenticator
27
+ *
28
+ * @param authenticator - authenticator to check
29
+ * @internal
30
+ */
31
+ export function isFusionAuthenticator(authenticator) {
32
+ return authenticator.type === 'fusion';
33
+ }
package/dist/index.d.ts CHANGED
@@ -2,6 +2,7 @@ import './translation/initialize-i18n.js';
2
2
  export * from './interfaces.js';
3
3
  export { PasswordAuthenticator } from './password-authenticator.js';
4
4
  export { SsoAuthenticator, isSsoAuthenticator } from './sso-authenticator.js';
5
+ export { FusionAuthenticator, isFusionAuthenticator } from './fusion-authenticator.js';
5
6
  export { BearerAuthenticator, isBearerAuthenticator } from './bearer-authenticator.js';
6
7
  export { WatAuthenticator, isWatAuthenticator } from './wat-authenticator.js';
7
8
  export { getAuthenticator } from './authenticator.js';
package/dist/index.js CHANGED
@@ -2,6 +2,7 @@ import './translation/initialize-i18n.js';
2
2
  export * from './interfaces.js';
3
3
  export { PasswordAuthenticator } from './password-authenticator.js';
4
4
  export { SsoAuthenticator, isSsoAuthenticator } from './sso-authenticator.js';
5
+ export { FusionAuthenticator, isFusionAuthenticator } from './fusion-authenticator.js';
5
6
  export { BearerAuthenticator, isBearerAuthenticator } from './bearer-authenticator.js';
6
7
  export { WatAuthenticator, isWatAuthenticator } from './wat-authenticator.js';
7
8
  export { getAuthenticator } from './authenticator.js';
@@ -1,5 +1,5 @@
1
1
  export interface Authenticator {
2
- readonly type: 'password' | 'bearer' | 'wat' | 'sso' | 'base';
2
+ readonly type: 'password' | 'bearer' | 'wat' | 'sso' | 'base' | 'fusion';
3
3
  isValid: () => boolean;
4
4
  invalidate: () => void;
5
5
  authenticate: () => Promise<boolean>;
@@ -10,6 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  import { BaseAuthenticator } from './base-authenticator.js';
12
12
  import { appendHeaders } from './helpers.js';
13
+ import { TranslatableError } from './translation/translatable-error.js';
13
14
  export class WatAuthenticator extends BaseAuthenticator {
14
15
  constructor(url, wat) {
15
16
  super('wat');
@@ -40,7 +41,9 @@ export class WatAuthenticator extends BaseAuthenticator {
40
41
  }
41
42
  }
42
43
  catch (e) {
43
- // empty catch block
44
+ // rather than returning empty catch block
45
+ // throw an error to be caught by Sisense context provider
46
+ throw new TranslatableError('errors.tokenAuthFailed');
44
47
  }
45
48
  finally {
46
49
  this._resolve(false);
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "Sisense",
12
12
  "Compose SDK"
13
13
  ],
14
- "version": "1.17.0",
14
+ "version": "1.18.0",
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.17.0",
23
+ "@sisense/sdk-common": "^1.18.0",
24
24
  "fetch-intercept": "^2.4.0"
25
25
  },
26
26
  "scripts": {