@thoughtspot/visual-embed-sdk 1.35.14 → 1.36.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/cjs/package.json +2 -3
- package/cjs/src/auth.d.ts +5 -0
- package/cjs/src/auth.d.ts.map +1 -1
- package/cjs/src/auth.js +7 -0
- package/cjs/src/auth.js.map +1 -1
- package/cjs/src/css-variables.d.ts +8 -0
- package/cjs/src/css-variables.d.ts.map +1 -1
- package/cjs/src/embed/hostEventClient/host-event-client.d.ts.map +1 -1
- package/cjs/src/embed/hostEventClient/host-event-client.js +8 -3
- package/cjs/src/embed/hostEventClient/host-event-client.js.map +1 -1
- package/cjs/src/embed/hostEventClient/host-event-client.spec.js +54 -0
- package/cjs/src/embed/hostEventClient/host-event-client.spec.js.map +1 -1
- package/cjs/src/embed/ts-embed.d.ts +6 -0
- package/cjs/src/embed/ts-embed.d.ts.map +1 -1
- package/cjs/src/embed/ts-embed.js +27 -0
- package/cjs/src/embed/ts-embed.js.map +1 -1
- package/cjs/src/embed/ts-embed.spec.d.ts.map +1 -1
- package/cjs/src/embed/ts-embed.spec.js +73 -1
- package/cjs/src/embed/ts-embed.spec.js.map +1 -1
- package/cjs/src/react/index.spec.js +2 -2
- package/cjs/src/react/index.spec.js.map +1 -1
- package/cjs/src/types.d.ts +82 -7
- package/cjs/src/types.d.ts.map +1 -1
- package/cjs/src/types.js +81 -7
- package/cjs/src/types.js.map +1 -1
- package/cjs/src/utils/authService/authService.d.ts +1 -0
- package/cjs/src/utils/authService/authService.d.ts.map +1 -1
- package/cjs/src/utils/authService/authService.js +1 -0
- package/cjs/src/utils/authService/authService.js.map +1 -1
- package/cjs/src/utils/authService/index.d.ts +1 -1
- package/cjs/src/utils/authService/index.d.ts.map +1 -1
- package/cjs/src/utils/authService/index.js +2 -1
- package/cjs/src/utils/authService/index.js.map +1 -1
- package/cjs/src/utils/authService/tokenizedAuthService.d.ts +10 -0
- package/cjs/src/utils/authService/tokenizedAuthService.d.ts.map +1 -1
- package/cjs/src/utils/authService/tokenizedAuthService.js +27 -1
- package/cjs/src/utils/authService/tokenizedAuthService.js.map +1 -1
- package/cjs/src/utils/authService/tokenizedAuthService.spec.js +58 -1
- package/cjs/src/utils/authService/tokenizedAuthService.spec.js.map +1 -1
- package/cjs/src/utils/sessionInfoService.d.ts +30 -0
- package/cjs/src/utils/sessionInfoService.d.ts.map +1 -1
- package/cjs/src/utils/sessionInfoService.js +59 -1
- package/cjs/src/utils/sessionInfoService.js.map +1 -1
- package/dist/index-CR5u7BMC.js +7370 -0
- package/dist/src/auth.d.ts +5 -0
- package/dist/src/auth.d.ts.map +1 -1
- package/dist/src/css-variables.d.ts +8 -0
- package/dist/src/css-variables.d.ts.map +1 -1
- package/dist/src/embed/hostEventClient/host-event-client.d.ts.map +1 -1
- package/dist/src/embed/ts-embed.d.ts +6 -0
- package/dist/src/embed/ts-embed.d.ts.map +1 -1
- package/dist/src/embed/ts-embed.spec.d.ts.map +1 -1
- package/dist/src/types.d.ts +82 -7
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/utils/authService/authService.d.ts +1 -0
- package/dist/src/utils/authService/authService.d.ts.map +1 -1
- package/dist/src/utils/authService/index.d.ts +1 -1
- package/dist/src/utils/authService/index.d.ts.map +1 -1
- package/dist/src/utils/authService/tokenizedAuthService.d.ts +10 -0
- package/dist/src/utils/authService/tokenizedAuthService.d.ts.map +1 -1
- package/dist/src/utils/sessionInfoService.d.ts +30 -0
- package/dist/src/utils/sessionInfoService.d.ts.map +1 -1
- package/dist/tsembed-react.es.js +206 -13
- package/dist/tsembed-react.js +205 -12
- package/dist/tsembed.es.js +207 -13
- package/dist/tsembed.js +206 -12
- package/dist/visual-embed-sdk-react-full.d.ts +125 -7
- package/dist/visual-embed-sdk-react.d.ts +125 -7
- package/dist/visual-embed-sdk.d.ts +125 -7
- package/lib/package.json +2 -3
- package/lib/src/auth.d.ts +5 -0
- package/lib/src/auth.d.ts.map +1 -1
- package/lib/src/auth.js +8 -1
- package/lib/src/auth.js.map +1 -1
- package/lib/src/css-variables.d.ts +8 -0
- package/lib/src/css-variables.d.ts.map +1 -1
- package/lib/src/embed/hostEventClient/host-event-client.d.ts.map +1 -1
- package/lib/src/embed/hostEventClient/host-event-client.js +8 -3
- package/lib/src/embed/hostEventClient/host-event-client.js.map +1 -1
- package/lib/src/embed/hostEventClient/host-event-client.spec.js +54 -0
- package/lib/src/embed/hostEventClient/host-event-client.spec.js.map +1 -1
- package/lib/src/embed/ts-embed.d.ts +6 -0
- package/lib/src/embed/ts-embed.d.ts.map +1 -1
- package/lib/src/embed/ts-embed.js +27 -0
- package/lib/src/embed/ts-embed.js.map +1 -1
- package/lib/src/embed/ts-embed.spec.d.ts.map +1 -1
- package/lib/src/embed/ts-embed.spec.js +73 -1
- package/lib/src/embed/ts-embed.spec.js.map +1 -1
- package/lib/src/react/index.spec.js +2 -2
- package/lib/src/react/index.spec.js.map +1 -1
- package/lib/src/types.d.ts +82 -7
- package/lib/src/types.d.ts.map +1 -1
- package/lib/src/types.js +81 -7
- package/lib/src/types.js.map +1 -1
- package/lib/src/utils/authService/authService.d.ts +1 -0
- package/lib/src/utils/authService/authService.d.ts.map +1 -1
- package/lib/src/utils/authService/authService.js +1 -0
- package/lib/src/utils/authService/authService.js.map +1 -1
- package/lib/src/utils/authService/index.d.ts +1 -1
- package/lib/src/utils/authService/index.d.ts.map +1 -1
- package/lib/src/utils/authService/index.js +1 -1
- package/lib/src/utils/authService/index.js.map +1 -1
- package/lib/src/utils/authService/tokenizedAuthService.d.ts +10 -0
- package/lib/src/utils/authService/tokenizedAuthService.d.ts.map +1 -1
- package/lib/src/utils/authService/tokenizedAuthService.js +25 -0
- package/lib/src/utils/authService/tokenizedAuthService.js.map +1 -1
- package/lib/src/utils/authService/tokenizedAuthService.spec.js +59 -2
- package/lib/src/utils/authService/tokenizedAuthService.spec.js.map +1 -1
- package/lib/src/utils/sessionInfoService.d.ts +30 -0
- package/lib/src/utils/sessionInfoService.d.ts.map +1 -1
- package/lib/src/utils/sessionInfoService.js +57 -1
- package/lib/src/utils/sessionInfoService.js.map +1 -1
- package/lib/src/visual-embed-sdk.d.ts +125 -7
- package/package.json +2 -3
- package/src/auth.ts +8 -1
- package/src/css-variables.ts +10 -0
- package/src/embed/hostEventClient/host-event-client.spec.ts +61 -0
- package/src/embed/hostEventClient/host-event-client.ts +8 -3
- package/src/embed/ts-embed.spec.ts +95 -1
- package/src/embed/ts-embed.ts +31 -0
- package/src/react/index.spec.tsx +2 -2
- package/src/types.ts +83 -7
- package/src/utils/authService/authService.ts +1 -0
- package/src/utils/authService/index.ts +5 -1
- package/src/utils/authService/tokenizedAuthService.spec.ts +66 -2
- package/src/utils/authService/tokenizedAuthService.ts +26 -0
- package/src/utils/sessionInfoService.ts +64 -1
|
@@ -3,6 +3,7 @@ import { logger } from '../logger';
|
|
|
3
3
|
export const EndPoints = {
|
|
4
4
|
AUTH_VERIFICATION: '/callosum/v1/session/info',
|
|
5
5
|
SESSION_INFO: '/callosum/v1/session/info',
|
|
6
|
+
PREAUTH_INFO: '/prism/preauth/info',
|
|
6
7
|
SAML_LOGIN_TEMPLATE: (targetUrl: string) => `/callosum/v1/saml/login?targetURLPath=${targetUrl}`,
|
|
7
8
|
OIDC_LOGIN_TEMPLATE: (targetUrl: string) => `/callosum/v1/oidc/login?targetURLPath=${targetUrl}`,
|
|
8
9
|
TOKEN_LOGIN: '/callosum/v1/session/login/token',
|
|
@@ -6,4 +6,8 @@ export {
|
|
|
6
6
|
fetchBasicAuthService,
|
|
7
7
|
verifyTokenService,
|
|
8
8
|
} from './authService';
|
|
9
|
-
export {
|
|
9
|
+
export {
|
|
10
|
+
fetchLogoutService,
|
|
11
|
+
fetchSessionInfoService,
|
|
12
|
+
fetchPreauthInfoService,
|
|
13
|
+
} from './tokenizedAuthService';
|
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
import * as tokenizedFetchModule from '../../tokenizedFetch';
|
|
2
|
-
import { isActiveService } from './tokenizedAuthService';
|
|
2
|
+
import { isActiveService, fetchSessionInfoService, fetchPreauthInfoService } from './tokenizedAuthService';
|
|
3
3
|
import { logger } from '../logger';
|
|
4
|
+
import { EndPoints } from './authService';
|
|
5
|
+
|
|
6
|
+
const thoughtspotHost = 'http://thoughtspotHost';
|
|
4
7
|
|
|
5
8
|
describe('tokenizedAuthService', () => {
|
|
6
|
-
|
|
9
|
+
afterEach(() => {
|
|
10
|
+
jest.clearAllMocks();
|
|
11
|
+
jest.restoreAllMocks();
|
|
12
|
+
});
|
|
13
|
+
test('isActiveService if fetch returns ok', async () => {
|
|
7
14
|
jest.spyOn(tokenizedFetchModule, 'tokenizedFetch').mockResolvedValueOnce({
|
|
8
15
|
ok: true,
|
|
9
16
|
});
|
|
@@ -34,3 +41,60 @@ describe('tokenizedAuthService', () => {
|
|
|
34
41
|
expect(logger.warn).toHaveBeenCalled();
|
|
35
42
|
});
|
|
36
43
|
});
|
|
44
|
+
|
|
45
|
+
describe('fetchPreauthInfoService', () => {
|
|
46
|
+
afterEach(() => {
|
|
47
|
+
jest.clearAllMocks();
|
|
48
|
+
jest.restoreAllMocks();
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test('fetchPreauthInfoService if fetch returns ok', async () => {
|
|
52
|
+
const mockFetch = jest.spyOn(tokenizedFetchModule, 'tokenizedFetch');
|
|
53
|
+
|
|
54
|
+
// Mock for fetchPreauthInfoService
|
|
55
|
+
mockFetch
|
|
56
|
+
.mockResolvedValueOnce({
|
|
57
|
+
ok: true,
|
|
58
|
+
headers: new Headers({ 'content-type': 'application/json' }), // Mock headers correctly
|
|
59
|
+
status: 200,
|
|
60
|
+
statusText: 'Ok',
|
|
61
|
+
json: jest.fn().mockResolvedValue({
|
|
62
|
+
info: {
|
|
63
|
+
configInfo: {
|
|
64
|
+
mixpanelConfig: {
|
|
65
|
+
devSdkKey: 'devSdkKey',
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
userGUID: 'userGUID',
|
|
69
|
+
},
|
|
70
|
+
}),
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
const result = await fetchPreauthInfoService(thoughtspotHost);
|
|
74
|
+
const response = await result.json();
|
|
75
|
+
|
|
76
|
+
expect(mockFetch).toHaveBeenCalledTimes(1);
|
|
77
|
+
expect(mockFetch).toHaveBeenNthCalledWith(1, `${thoughtspotHost}${EndPoints.PREAUTH_INFO}`, {});
|
|
78
|
+
expect(response).toHaveProperty('info');
|
|
79
|
+
});
|
|
80
|
+
it('fetchPreauthInfoService if fetch fails', async () => {
|
|
81
|
+
const mockFetch = jest.spyOn(tokenizedFetchModule, 'tokenizedFetch');
|
|
82
|
+
|
|
83
|
+
// Mock for fetchPreauthInfoService
|
|
84
|
+
mockFetch.mockResolvedValueOnce({
|
|
85
|
+
ok: false,
|
|
86
|
+
status: 500,
|
|
87
|
+
statusText: 'Internal Server Error',
|
|
88
|
+
json: jest.fn().mockResolvedValue({}),
|
|
89
|
+
text: jest.fn().mockResolvedValue('Internal Server Error'),
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
try {
|
|
93
|
+
await fetchPreauthInfoService(thoughtspotHost);
|
|
94
|
+
} catch (e) {
|
|
95
|
+
expect(e.message).toContain(`Failed to fetch ${thoughtspotHost}${EndPoints.PREAUTH_INFO}`);
|
|
96
|
+
}
|
|
97
|
+
expect(mockFetch).toHaveBeenCalledTimes(1);
|
|
98
|
+
expect(mockFetch).toHaveBeenCalledWith(`${thoughtspotHost}${EndPoints.PREAUTH_INFO}`, {});
|
|
99
|
+
});
|
|
100
|
+
});
|
|
@@ -16,6 +16,32 @@ function tokenizedFailureLoggedFetch(url: string, options: RequestInit = {}): Pr
|
|
|
16
16
|
});
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
+
/**
|
|
20
|
+
* Fetches the session info from the ThoughtSpot server.
|
|
21
|
+
* @param thoughtspotHost
|
|
22
|
+
* @returns {Promise<any>}
|
|
23
|
+
* @example
|
|
24
|
+
* ```js
|
|
25
|
+
* const response = await sessionInfoService();
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export async function fetchPreauthInfoService(thoughtspotHost: string): Promise<any> {
|
|
29
|
+
const sessionInfoPath = `${thoughtspotHost}${EndPoints.PREAUTH_INFO}`;
|
|
30
|
+
const handleError = (e: any) => {
|
|
31
|
+
const error: any = new Error(`Failed to fetch auth info: ${e.message || e.statusText}`);
|
|
32
|
+
error.status = e.status; // Attach the status code to the error object
|
|
33
|
+
throw error;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
try {
|
|
37
|
+
const response = await tokenizedFailureLoggedFetch(sessionInfoPath);
|
|
38
|
+
return response;
|
|
39
|
+
} catch (e) {
|
|
40
|
+
handleError(e);
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
19
45
|
/**
|
|
20
46
|
* Fetches the session info from the ThoughtSpot server.
|
|
21
47
|
* @param thoughtspotHost
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getEmbedConfig } from '../embed/embedConfig';
|
|
2
|
-
import { fetchSessionInfoService } from './authService';
|
|
2
|
+
import { fetchSessionInfoService, fetchPreauthInfoService } from './authService';
|
|
3
3
|
|
|
4
4
|
export type SessionInfo = {
|
|
5
5
|
releaseVersion: string;
|
|
@@ -13,7 +13,70 @@ export type SessionInfo = {
|
|
|
13
13
|
[key: string]: any;
|
|
14
14
|
};
|
|
15
15
|
|
|
16
|
+
export type PreauthInfo = {
|
|
17
|
+
info?: SessionInfo;
|
|
18
|
+
headers: Record<string, string>;
|
|
19
|
+
status: number;
|
|
20
|
+
[key: string]: any;
|
|
21
|
+
};
|
|
22
|
+
|
|
16
23
|
let sessionInfo: null | SessionInfo = null;
|
|
24
|
+
let preauthInfo: null | PreauthInfo = null;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Processes the session info response and returns the session info object.
|
|
28
|
+
* @param preauthInfoResp {any} Response from the session info API.
|
|
29
|
+
* @returns {PreauthInfo} The session info object.
|
|
30
|
+
* @example ```js
|
|
31
|
+
* const preauthInfoResp = await fetch(sessionInfoPath);
|
|
32
|
+
* const sessionInfo = await formatPreauthInfo(preauthInfoResp);
|
|
33
|
+
* console.log(sessionInfo);
|
|
34
|
+
* ```
|
|
35
|
+
* @version SDK: 1.28.3 | ThoughtSpot: *
|
|
36
|
+
*/
|
|
37
|
+
export const formatPreauthInfo = async (preauthInfoResp: any): Promise<PreauthInfo> => {
|
|
38
|
+
try {
|
|
39
|
+
// Convert Headers to a plain object
|
|
40
|
+
const headers: Record<string, string> = {};
|
|
41
|
+
preauthInfoResp?.headers?.forEach((value: string, key: string) => {
|
|
42
|
+
headers[key] = value;
|
|
43
|
+
});
|
|
44
|
+
const data = await preauthInfoResp.json();
|
|
45
|
+
return {
|
|
46
|
+
...data,
|
|
47
|
+
status: 200,
|
|
48
|
+
headers,
|
|
49
|
+
};
|
|
50
|
+
} catch (error) {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Returns the session info object and caches it for future use.
|
|
57
|
+
* Once fetched the session info object is cached and returned from the cache on
|
|
58
|
+
* subsequent calls.
|
|
59
|
+
* @example ```js
|
|
60
|
+
* const preauthInfo = await getPreauthInfo();
|
|
61
|
+
* console.log(preauthInfo);
|
|
62
|
+
* ```
|
|
63
|
+
* @version SDK: 1.28.3 | ThoughtSpot: *
|
|
64
|
+
* @returns {Promise<SessionInfo>} The session info object.
|
|
65
|
+
*/
|
|
66
|
+
export async function getPreauthInfo(allowCache = true): Promise<PreauthInfo> {
|
|
67
|
+
if (!allowCache || !preauthInfo) {
|
|
68
|
+
try {
|
|
69
|
+
const host = getEmbedConfig().thoughtSpotHost;
|
|
70
|
+
const sessionResponse = await fetchPreauthInfoService(host);
|
|
71
|
+
const processedPreauthInfo = await formatPreauthInfo(sessionResponse);
|
|
72
|
+
preauthInfo = processedPreauthInfo;
|
|
73
|
+
} catch (error) {
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return preauthInfo;
|
|
79
|
+
}
|
|
17
80
|
|
|
18
81
|
/**
|
|
19
82
|
* Returns the session info object and caches it for future use.
|