@thoughtspot/visual-embed-sdk 1.20.0-alpha.2 → 1.20.0-prerender.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/src/auth.d.ts +75 -5
- package/dist/src/auth.d.ts.map +1 -1
- package/dist/src/config.d.ts +1 -0
- package/dist/src/config.d.ts.map +1 -1
- package/dist/src/embed/app.d.ts +19 -7
- package/dist/src/embed/app.d.ts.map +1 -1
- package/dist/src/embed/base.d.ts +39 -19
- package/dist/src/embed/base.d.ts.map +1 -1
- package/dist/src/embed/liveboard.d.ts +19 -7
- package/dist/src/embed/liveboard.d.ts.map +1 -1
- package/dist/src/embed/search-bar.d.ts +7 -1
- package/dist/src/embed/search-bar.d.ts.map +1 -1
- package/dist/src/embed/search.d.ts +11 -3
- package/dist/src/embed/search.d.ts.map +1 -1
- package/dist/src/embed/ts-embed.d.ts +76 -5
- package/dist/src/embed/ts-embed.d.ts.map +1 -1
- package/dist/src/errors.d.ts.map +1 -1
- package/dist/src/index.d.ts +3 -3
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/mixpanel-service.d.ts +8 -0
- package/dist/src/mixpanel-service.d.ts.map +1 -1
- package/dist/src/react/index.d.ts.map +1 -1
- package/dist/src/react/util.d.ts +4 -0
- package/dist/src/react/util.d.ts.map +1 -1
- package/dist/src/test/test-utils.d.ts +11 -2
- package/dist/src/test/test-utils.d.ts.map +1 -1
- package/dist/src/types.d.ts +429 -97
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/utils/answerService.d.ts +7 -0
- package/dist/src/utils/answerService.d.ts.map +1 -1
- package/dist/src/utils/authService.d.ts +30 -0
- package/dist/src/utils/authService.d.ts.map +1 -1
- package/dist/src/utils/processData.d.ts +12 -0
- package/dist/src/utils/processData.d.ts.map +1 -1
- package/dist/src/utils/processTrigger.d.ts +7 -0
- package/dist/src/utils/processTrigger.d.ts.map +1 -1
- package/dist/src/utils.d.ts +12 -0
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/tsembed.es.js +818 -285
- package/dist/tsembed.js +791 -284
- package/lib/package.json +4 -3
- package/lib/src/auth.d.ts +75 -5
- package/lib/src/auth.d.ts.map +1 -1
- package/lib/src/auth.js +86 -26
- package/lib/src/auth.js.map +1 -1
- package/lib/src/auth.spec.js +14 -5
- package/lib/src/auth.spec.js.map +1 -1
- package/lib/src/config.d.ts +1 -0
- package/lib/src/config.d.ts.map +1 -1
- package/lib/src/config.js +5 -3
- package/lib/src/config.js.map +1 -1
- package/lib/src/config.spec.js.map +1 -1
- package/lib/src/embed/app.d.ts +19 -7
- package/lib/src/embed/app.d.ts.map +1 -1
- package/lib/src/embed/app.js +26 -16
- package/lib/src/embed/app.js.map +1 -1
- package/lib/src/embed/app.spec.js +12 -12
- package/lib/src/embed/app.spec.js.map +1 -1
- package/lib/src/embed/base.d.ts +39 -19
- package/lib/src/embed/base.d.ts.map +1 -1
- package/lib/src/embed/base.js +49 -15
- package/lib/src/embed/base.js.map +1 -1
- package/lib/src/embed/base.spec.js +2 -2
- package/lib/src/embed/base.spec.js.map +1 -1
- package/lib/src/embed/embed.spec.js +1 -1
- package/lib/src/embed/embed.spec.js.map +1 -1
- package/lib/src/embed/liveboard.d.ts +19 -7
- package/lib/src/embed/liveboard.d.ts.map +1 -1
- package/lib/src/embed/liveboard.js +50 -38
- package/lib/src/embed/liveboard.js.map +1 -1
- package/lib/src/embed/liveboard.spec.js +37 -30
- package/lib/src/embed/liveboard.spec.js.map +1 -1
- package/lib/src/embed/pinboard.spec.js +14 -26
- package/lib/src/embed/pinboard.spec.js.map +1 -1
- package/lib/src/embed/search-bar.d.ts +7 -1
- package/lib/src/embed/search-bar.d.ts.map +1 -1
- package/lib/src/embed/search-bar.js +6 -7
- package/lib/src/embed/search-bar.js.map +1 -1
- package/lib/src/embed/search.d.ts +11 -3
- package/lib/src/embed/search.d.ts.map +1 -1
- package/lib/src/embed/search.js +19 -15
- package/lib/src/embed/search.js.map +1 -1
- package/lib/src/embed/search.spec.js +16 -19
- package/lib/src/embed/search.spec.js.map +1 -1
- package/lib/src/embed/searchEmbed-basic-auth.spec.js +4 -0
- package/lib/src/embed/searchEmbed-basic-auth.spec.js.map +1 -1
- package/lib/src/embed/ts-embed.d.ts +76 -5
- package/lib/src/embed/ts-embed.d.ts.map +1 -1
- package/lib/src/embed/ts-embed.js +150 -72
- package/lib/src/embed/ts-embed.js.map +1 -1
- package/lib/src/embed/ts-embed.spec.js +23 -24
- package/lib/src/embed/ts-embed.spec.js.map +1 -1
- package/lib/src/errors.d.ts.map +1 -1
- package/lib/src/errors.js.map +1 -1
- package/lib/src/index.d.ts +3 -3
- package/lib/src/index.d.ts.map +1 -1
- package/lib/src/index.js +3 -3
- package/lib/src/index.js.map +1 -1
- package/lib/src/mixpanel-service.d.ts +8 -0
- package/lib/src/mixpanel-service.d.ts.map +1 -1
- package/lib/src/mixpanel-service.js +13 -1
- package/lib/src/mixpanel-service.js.map +1 -1
- package/lib/src/mixpanel-service.spec.js.map +1 -1
- package/lib/src/react/index.d.ts.map +1 -1
- package/lib/src/react/index.js +4 -6
- package/lib/src/react/index.js.map +1 -1
- package/lib/src/react/index.spec.js +3 -6
- package/lib/src/react/index.spec.js.map +1 -1
- package/lib/src/react/util.d.ts +4 -0
- package/lib/src/react/util.d.ts.map +1 -1
- package/lib/src/react/util.js +4 -0
- package/lib/src/react/util.js.map +1 -1
- package/lib/src/test/test-utils.d.ts +11 -2
- package/lib/src/test/test-utils.d.ts.map +1 -1
- package/lib/src/test/test-utils.js +36 -25
- package/lib/src/test/test-utils.js.map +1 -1
- package/lib/src/types.d.ts +429 -97
- package/lib/src/types.d.ts.map +1 -1
- package/lib/src/types.js +310 -72
- package/lib/src/types.js.map +1 -1
- package/lib/src/utils/answerService.d.ts +7 -0
- package/lib/src/utils/answerService.d.ts.map +1 -1
- package/lib/src/utils/answerService.js +7 -0
- package/lib/src/utils/answerService.js.map +1 -1
- package/lib/src/utils/answerService.spec.js.map +1 -1
- package/lib/src/utils/authService.d.ts +30 -0
- package/lib/src/utils/authService.d.ts.map +1 -1
- package/lib/src/utils/authService.js +39 -2
- package/lib/src/utils/authService.js.map +1 -1
- package/lib/src/utils/authService.spec.js.map +1 -1
- package/lib/src/utils/processData.d.ts +12 -0
- package/lib/src/utils/processData.d.ts.map +1 -1
- package/lib/src/utils/processData.js +33 -5
- package/lib/src/utils/processData.js.map +1 -1
- package/lib/src/utils/processData.spec.js.map +1 -1
- package/lib/src/utils/processTrigger.d.ts +7 -0
- package/lib/src/utils/processTrigger.d.ts.map +1 -1
- package/lib/src/utils/processTrigger.js +17 -3
- package/lib/src/utils/processTrigger.js.map +1 -1
- package/lib/src/utils/processTrigger.spec.js.map +1 -1
- package/lib/src/utils.d.ts +12 -0
- package/lib/src/utils.d.ts.map +1 -1
- package/lib/src/utils.js +24 -19
- package/lib/src/utils.js.map +1 -1
- package/lib/src/utils.spec.js.map +1 -1
- package/lib/src/visual-embed-sdk.d.ts +664 -141
- package/package.json +4 -3
- package/src/auth.spec.ts +68 -150
- package/src/auth.ts +141 -101
- package/src/config.spec.ts +2 -4
- package/src/config.ts +5 -3
- package/src/embed/app.spec.ts +25 -14
- package/src/embed/app.ts +49 -37
- package/src/embed/base.spec.ts +6 -12
- package/src/embed/base.ts +74 -57
- package/src/embed/embed.spec.ts +5 -6
- package/src/embed/liveboard.spec.ts +56 -37
- package/src/embed/liveboard.ts +67 -65
- package/src/embed/pinboard.spec.ts +26 -29
- package/src/embed/search-bar.tsx +14 -9
- package/src/embed/search.spec.ts +31 -21
- package/src/embed/search.ts +28 -22
- package/src/embed/searchEmbed-basic-auth.spec.ts +22 -28
- package/src/embed/ts-embed.spec.ts +70 -148
- package/src/embed/ts-embed.ts +180 -157
- package/src/errors.ts +3 -6
- package/src/index.ts +23 -7
- package/src/mixpanel-service.spec.ts +1 -3
- package/src/mixpanel-service.ts +13 -1
- package/src/react/index.spec.tsx +11 -20
- package/src/react/index.tsx +40 -71
- package/src/react/util.ts +8 -4
- package/src/test/test-utils.ts +43 -39
- package/src/types.ts +427 -97
- package/src/utils/answerService.spec.ts +3 -5
- package/src/utils/answerService.ts +21 -17
- package/src/utils/authService.spec.ts +26 -41
- package/src/utils/authService.ts +47 -21
- package/src/utils/processData.spec.ts +26 -59
- package/src/utils/processData.ts +36 -14
- package/src/utils/processTrigger.spec.ts +1 -6
- package/src/utils/processTrigger.ts +18 -9
- package/src/utils.spec.ts +8 -12
- package/src/utils.ts +25 -26
|
@@ -11,11 +11,9 @@ describe('Unit test for getAnswerServiceInstance', () => {
|
|
|
11
11
|
|
|
12
12
|
test('fetchData, when api giving answer data', async () => {
|
|
13
13
|
const mockAnswerResponse = { data: {} };
|
|
14
|
-
global.fetch = jest.fn(() =>
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}),
|
|
18
|
-
);
|
|
14
|
+
global.fetch = jest.fn(() => Promise.resolve({
|
|
15
|
+
json: () => mockAnswerResponse,
|
|
16
|
+
}));
|
|
19
17
|
const answerService = getAnswerServiceInstance(
|
|
20
18
|
session,
|
|
21
19
|
query,
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import { SessionInterface, OperationType } from '../types';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* @param session
|
|
6
|
+
* @param query
|
|
7
|
+
* @param operation
|
|
8
|
+
* @param thoughtSpotHost
|
|
9
|
+
*/
|
|
3
10
|
export function getAnswerServiceInstance(
|
|
4
11
|
session: SessionInterface,
|
|
5
12
|
query: string,
|
|
@@ -10,24 +17,21 @@ export function getAnswerServiceInstance(
|
|
|
10
17
|
|
|
11
18
|
const fetchQuery = async (variables: any) => {
|
|
12
19
|
try {
|
|
13
|
-
const response = await fetch(
|
|
14
|
-
|
|
15
|
-
{
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
accept: '*/*',
|
|
21
|
-
'accept-language': 'en-us',
|
|
22
|
-
},
|
|
23
|
-
body: JSON.stringify({
|
|
24
|
-
operationName: operation,
|
|
25
|
-
query,
|
|
26
|
-
variables,
|
|
27
|
-
}),
|
|
28
|
-
credentials: 'include',
|
|
20
|
+
const response = await fetch(`${thoughtSpotHost}/prism/?op=${operation}`, {
|
|
21
|
+
method: 'POST',
|
|
22
|
+
headers: {
|
|
23
|
+
'content-type': 'application/json;charset=UTF-8',
|
|
24
|
+
'x-requested-by': 'ThoughtSpot',
|
|
25
|
+
accept: '*/*',
|
|
26
|
+
'accept-language': 'en-us',
|
|
29
27
|
},
|
|
30
|
-
|
|
28
|
+
body: JSON.stringify({
|
|
29
|
+
operationName: operation,
|
|
30
|
+
query,
|
|
31
|
+
variables,
|
|
32
|
+
}),
|
|
33
|
+
credentials: 'include',
|
|
34
|
+
});
|
|
31
35
|
const result = await response.json();
|
|
32
36
|
return result.data;
|
|
33
37
|
} catch (error) {
|
|
@@ -19,34 +19,28 @@ describe('Unit test for authService', () => {
|
|
|
19
19
|
global.fetch = window.fetch;
|
|
20
20
|
});
|
|
21
21
|
test('fetchSessionInfoService', async () => {
|
|
22
|
-
global.fetch = jest.fn(() =>
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}),
|
|
28
|
-
);
|
|
22
|
+
global.fetch = jest.fn(() => Promise.resolve({
|
|
23
|
+
json: () => ({ success: true }),
|
|
24
|
+
status: 200,
|
|
25
|
+
ok: true,
|
|
26
|
+
}));
|
|
29
27
|
const response = await fetchSessionInfoService(authVerificationUrl);
|
|
30
28
|
expect(response.status).toBe(200);
|
|
31
29
|
expect(fetch).toHaveBeenCalledTimes(1);
|
|
32
30
|
});
|
|
33
31
|
|
|
34
32
|
test('fetchAuthTokenService', async () => {
|
|
35
|
-
global.fetch = jest.fn(() =>
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}),
|
|
40
|
-
);
|
|
33
|
+
global.fetch = jest.fn(() => Promise.resolve({
|
|
34
|
+
text: () => ({ success: true }),
|
|
35
|
+
ok: true,
|
|
36
|
+
}));
|
|
41
37
|
const response = await fetchAuthTokenService(authEndpoint);
|
|
42
38
|
expect(response.text()).toStrictEqual({ success: true });
|
|
43
39
|
expect(fetch).toBeCalled();
|
|
44
40
|
});
|
|
45
41
|
|
|
46
42
|
test('fetchAuthService', async () => {
|
|
47
|
-
global.fetch = jest.fn(() =>
|
|
48
|
-
Promise.resolve({ success: true, ok: true }),
|
|
49
|
-
);
|
|
43
|
+
global.fetch = jest.fn(() => Promise.resolve({ success: true, ok: true }));
|
|
50
44
|
await fetchAuthService(thoughtSpotHost, username, authToken);
|
|
51
45
|
expect(fetch).toBeCalledWith(
|
|
52
46
|
`${thoughtSpotHost}${EndPoints.TOKEN_LOGIN}?username=${username}&auth_token=${authToken}`,
|
|
@@ -58,42 +52,33 @@ describe('Unit test for authService', () => {
|
|
|
58
52
|
});
|
|
59
53
|
|
|
60
54
|
test('fetchAuthPostService', async () => {
|
|
61
|
-
global.fetch = jest.fn(() =>
|
|
62
|
-
Promise.resolve({ success: true, ok: true }),
|
|
63
|
-
);
|
|
55
|
+
global.fetch = jest.fn(() => Promise.resolve({ success: true, ok: true }));
|
|
64
56
|
await fetchAuthPostService(thoughtSpotHost, username, authToken);
|
|
65
|
-
expect(fetch).toBeCalledWith(
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
'content-type': 'application/x-www-form-urlencoded',
|
|
74
|
-
'x-requested-by': 'ThoughtSpot',
|
|
75
|
-
},
|
|
57
|
+
expect(fetch).toBeCalledWith(`${thoughtSpotHost}${EndPoints.TOKEN_LOGIN}`, {
|
|
58
|
+
method: 'POST',
|
|
59
|
+
credentials: 'include',
|
|
60
|
+
redirect: 'manual',
|
|
61
|
+
body: 'username=tsuser&auth_token=token',
|
|
62
|
+
headers: {
|
|
63
|
+
'content-type': 'application/x-www-form-urlencoded',
|
|
64
|
+
'x-requested-by': 'ThoughtSpot',
|
|
76
65
|
},
|
|
77
|
-
);
|
|
66
|
+
});
|
|
78
67
|
});
|
|
79
68
|
|
|
80
69
|
test('fetchBasicAuthService called with manual redirect', async () => {
|
|
81
|
-
global.fetch = jest.fn(() =>
|
|
82
|
-
Promise.resolve({ success: true, ok: true }),
|
|
83
|
-
);
|
|
70
|
+
global.fetch = jest.fn(() => Promise.resolve({ success: true, ok: true }));
|
|
84
71
|
await fetchBasicAuthService(thoughtSpotHost, username, password);
|
|
85
72
|
expect(fetch).toBeCalled();
|
|
86
73
|
});
|
|
87
74
|
|
|
88
75
|
test('log error on API failures', async () => {
|
|
89
76
|
jest.spyOn(global.console, 'error').mockImplementation(() => undefined);
|
|
90
|
-
global.fetch = jest.fn(() =>
|
|
91
|
-
Promise.resolve(
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
}),
|
|
96
|
-
);
|
|
77
|
+
global.fetch = jest.fn(() => Promise.resolve({
|
|
78
|
+
text: () => Promise.resolve('error'),
|
|
79
|
+
status: 500,
|
|
80
|
+
ok: false,
|
|
81
|
+
}));
|
|
97
82
|
await fetchSessionInfoService(authVerificationUrl);
|
|
98
83
|
expect(global.console.error).toHaveBeenCalledWith('Failure', 'error');
|
|
99
84
|
});
|
package/src/utils/authService.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
// eslint-disable-next-line import/no-cycle
|
|
2
2
|
import { EndPoints } from '../auth';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
/**
|
|
5
|
+
*
|
|
6
|
+
* @param url
|
|
7
|
+
* @param options
|
|
8
|
+
*/
|
|
9
|
+
function failureLoggedFetch(url: string, options: RequestInit = {}): Promise<Response> {
|
|
8
10
|
return fetch(url, options).then(async (r) => {
|
|
9
11
|
if (!r.ok && r.type !== 'opaqueredirect' && r.type !== 'opaque') {
|
|
10
12
|
console.error('Failure', await r.text?.());
|
|
@@ -13,20 +15,30 @@ function failureLoggedFetch(
|
|
|
13
15
|
});
|
|
14
16
|
}
|
|
15
17
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
/**
|
|
19
|
+
*
|
|
20
|
+
* @param authVerificationUrl
|
|
21
|
+
*/
|
|
22
|
+
export function fetchSessionInfoService(authVerificationUrl: string): Promise<any> {
|
|
19
23
|
return failureLoggedFetch(authVerificationUrl, {
|
|
20
24
|
credentials: 'include',
|
|
21
25
|
});
|
|
22
26
|
}
|
|
23
27
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
28
|
+
/**
|
|
29
|
+
*
|
|
30
|
+
* @param authEndpoint
|
|
31
|
+
*/
|
|
32
|
+
export async function fetchAuthTokenService(authEndpoint: string): Promise<any> {
|
|
27
33
|
return fetch(authEndpoint);
|
|
28
34
|
}
|
|
29
35
|
|
|
36
|
+
/**
|
|
37
|
+
*
|
|
38
|
+
* @param thoughtSpotHost
|
|
39
|
+
* @param username
|
|
40
|
+
* @param authToken
|
|
41
|
+
*/
|
|
30
42
|
export async function fetchAuthService(
|
|
31
43
|
thoughtSpotHost: string,
|
|
32
44
|
username: string,
|
|
@@ -36,12 +48,19 @@ export async function fetchAuthService(
|
|
|
36
48
|
`${thoughtSpotHost}${EndPoints.TOKEN_LOGIN}?username=${username}&auth_token=${authToken}`,
|
|
37
49
|
{
|
|
38
50
|
credentials: 'include',
|
|
39
|
-
// We do not want to follow the redirect, as it starts giving a CORS
|
|
51
|
+
// We do not want to follow the redirect, as it starts giving a CORS
|
|
52
|
+
// error
|
|
40
53
|
redirect: 'manual',
|
|
41
54
|
},
|
|
42
55
|
);
|
|
43
56
|
}
|
|
44
57
|
|
|
58
|
+
/**
|
|
59
|
+
*
|
|
60
|
+
* @param thoughtSpotHost
|
|
61
|
+
* @param username
|
|
62
|
+
* @param authToken
|
|
63
|
+
*/
|
|
45
64
|
export async function fetchAuthPostService(
|
|
46
65
|
thoughtSpotHost: string,
|
|
47
66
|
username: string,
|
|
@@ -53,15 +72,22 @@ export async function fetchAuthPostService(
|
|
|
53
72
|
'content-type': 'application/x-www-form-urlencoded',
|
|
54
73
|
'x-requested-by': 'ThoughtSpot',
|
|
55
74
|
},
|
|
56
|
-
body: `username=${encodeURIComponent(
|
|
57
|
-
|
|
58
|
-
)}
|
|
75
|
+
body: `username=${encodeURIComponent(username)}&auth_token=${encodeURIComponent(
|
|
76
|
+
authToken,
|
|
77
|
+
)}`,
|
|
59
78
|
credentials: 'include',
|
|
60
|
-
// We do not want to follow the redirect, as it starts giving a CORS
|
|
79
|
+
// We do not want to follow the redirect, as it starts giving a CORS
|
|
80
|
+
// error
|
|
61
81
|
redirect: 'manual',
|
|
62
82
|
});
|
|
63
83
|
}
|
|
64
84
|
|
|
85
|
+
/**
|
|
86
|
+
*
|
|
87
|
+
* @param thoughtSpotHost
|
|
88
|
+
* @param username
|
|
89
|
+
* @param password
|
|
90
|
+
*/
|
|
65
91
|
export async function fetchBasicAuthService(
|
|
66
92
|
thoughtSpotHost: string,
|
|
67
93
|
username: string,
|
|
@@ -73,16 +99,16 @@ export async function fetchBasicAuthService(
|
|
|
73
99
|
'content-type': 'application/x-www-form-urlencoded',
|
|
74
100
|
'x-requested-by': 'ThoughtSpot',
|
|
75
101
|
},
|
|
76
|
-
body: `username=${encodeURIComponent(
|
|
77
|
-
username,
|
|
78
|
-
)}&password=${encodeURIComponent(password)}`,
|
|
102
|
+
body: `username=${encodeURIComponent(username)}&password=${encodeURIComponent(password)}`,
|
|
79
103
|
credentials: 'include',
|
|
80
104
|
});
|
|
81
105
|
}
|
|
82
106
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
107
|
+
/**
|
|
108
|
+
*
|
|
109
|
+
* @param thoughtSpotHost
|
|
110
|
+
*/
|
|
111
|
+
export async function fetchLogoutService(thoughtSpotHost: string): Promise<any> {
|
|
86
112
|
return failureLoggedFetch(`${thoughtSpotHost}${EndPoints.LOGOUT}`, {
|
|
87
113
|
credentials: 'include',
|
|
88
114
|
method: 'POST',
|
|
@@ -26,24 +26,17 @@ describe('Unit test for process data', () => {
|
|
|
26
26
|
operation: OperationType.GetChartWithData,
|
|
27
27
|
},
|
|
28
28
|
};
|
|
29
|
-
jest.spyOn(
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
).mockReturnValue(answerService);
|
|
29
|
+
jest.spyOn(answerServiceInstance, 'getAnswerServiceInstance').mockReturnValue(
|
|
30
|
+
answerService,
|
|
31
|
+
);
|
|
33
32
|
expect(
|
|
34
|
-
processDataInstance.processCustomAction(
|
|
35
|
-
processChartData,
|
|
36
|
-
thoughtSpotHost,
|
|
37
|
-
),
|
|
33
|
+
processDataInstance.processCustomAction(processChartData, thoughtSpotHost),
|
|
38
34
|
).toStrictEqual(processChartData);
|
|
39
35
|
});
|
|
40
36
|
|
|
41
37
|
test('ProcessData, when Action is CustomAction', async () => {
|
|
42
38
|
const processedData = { type: EmbedEvent.CustomAction };
|
|
43
|
-
jest.spyOn(
|
|
44
|
-
processDataInstance,
|
|
45
|
-
'processCustomAction',
|
|
46
|
-
).mockImplementation(async () => ({}));
|
|
39
|
+
jest.spyOn(processDataInstance, 'processCustomAction').mockImplementation(async () => ({}));
|
|
47
40
|
expect(
|
|
48
41
|
processDataInstance.processEventData(
|
|
49
42
|
EmbedEvent.CustomAction,
|
|
@@ -56,20 +49,12 @@ describe('Unit test for process data', () => {
|
|
|
56
49
|
|
|
57
50
|
test('ProcessData, when Action is non CustomAction', () => {
|
|
58
51
|
const processedData = { type: EmbedEvent.Data };
|
|
59
|
-
jest.spyOn(
|
|
60
|
-
processDataInstance,
|
|
61
|
-
'processCustomAction',
|
|
62
|
-
).mockImplementation(async () => ({}));
|
|
52
|
+
jest.spyOn(processDataInstance, 'processCustomAction').mockImplementation(async () => ({}));
|
|
63
53
|
jest.spyOn(
|
|
64
54
|
answerServiceInstance,
|
|
65
55
|
'getAnswerServiceInstance',
|
|
66
56
|
).mockImplementation(async () => ({}));
|
|
67
|
-
processDataInstance.processEventData(
|
|
68
|
-
EmbedEvent.Data,
|
|
69
|
-
processedData,
|
|
70
|
-
thoughtSpotHost,
|
|
71
|
-
null,
|
|
72
|
-
);
|
|
57
|
+
processDataInstance.processEventData(EmbedEvent.Data, processedData, thoughtSpotHost, null);
|
|
73
58
|
expect(processDataInstance.processCustomAction).not.toBeCalled();
|
|
74
59
|
});
|
|
75
60
|
|
|
@@ -82,9 +67,7 @@ describe('Unit test for process data', () => {
|
|
|
82
67
|
const e = { type: EmbedEvent.AuthInit, data: sessionInfo };
|
|
83
68
|
jest.spyOn(auth, 'initSession').mockReturnValue(null);
|
|
84
69
|
jest.spyOn(base, 'notifyAuthSuccess');
|
|
85
|
-
expect(
|
|
86
|
-
processDataInstance.processEventData(e.type, e, '', null),
|
|
87
|
-
).toEqual({
|
|
70
|
+
expect(processDataInstance.processEventData(e.type, e, '', null)).toEqual({
|
|
88
71
|
type: e.type,
|
|
89
72
|
data: {
|
|
90
73
|
userGUID: sessionInfo.userGUID,
|
|
@@ -103,14 +86,10 @@ describe('Unit test for process data', () => {
|
|
|
103
86
|
});
|
|
104
87
|
jest.spyOn(window, 'alert').mockImplementation(() => undefined);
|
|
105
88
|
const el: any = {};
|
|
106
|
-
expect(processDataInstance.processEventData(e.type, e, '', el)).toEqual(
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
);
|
|
111
|
-
expect(base.notifyAuthFailure).toBeCalledWith(
|
|
112
|
-
auth.AuthFailureType.NO_COOKIE_ACCESS,
|
|
113
|
-
);
|
|
89
|
+
expect(processDataInstance.processEventData(e.type, e, '', el)).toEqual({
|
|
90
|
+
type: e.type,
|
|
91
|
+
});
|
|
92
|
+
expect(base.notifyAuthFailure).toBeCalledWith(auth.AuthFailureType.NO_COOKIE_ACCESS);
|
|
114
93
|
expect(window.alert).toBeCalled();
|
|
115
94
|
expect(el.innerHTML).toBe('Hello');
|
|
116
95
|
});
|
|
@@ -125,14 +104,10 @@ describe('Unit test for process data', () => {
|
|
|
125
104
|
jest.spyOn(window, 'alert').mockReset();
|
|
126
105
|
jest.spyOn(window, 'alert').mockImplementation(() => undefined);
|
|
127
106
|
const el: any = {};
|
|
128
|
-
expect(processDataInstance.processEventData(e.type, e, '', el)).toEqual(
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
);
|
|
133
|
-
expect(base.notifyAuthFailure).toBeCalledWith(
|
|
134
|
-
auth.AuthFailureType.NO_COOKIE_ACCESS,
|
|
135
|
-
);
|
|
107
|
+
expect(processDataInstance.processEventData(e.type, e, '', el)).toEqual({
|
|
108
|
+
type: e.type,
|
|
109
|
+
});
|
|
110
|
+
expect(base.notifyAuthFailure).toBeCalledWith(auth.AuthFailureType.NO_COOKIE_ACCESS);
|
|
136
111
|
expect(window.alert).not.toBeCalled();
|
|
137
112
|
expect(el.innerHTML).toBe('Hello');
|
|
138
113
|
});
|
|
@@ -144,14 +119,10 @@ describe('Unit test for process data', () => {
|
|
|
144
119
|
loginFailedMessage: 'Hello',
|
|
145
120
|
});
|
|
146
121
|
const el: any = {};
|
|
147
|
-
expect(processDataInstance.processEventData(e.type, e, '', el)).toEqual(
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
);
|
|
152
|
-
expect(base.notifyAuthFailure).toBeCalledWith(
|
|
153
|
-
auth.AuthFailureType.OTHER,
|
|
154
|
-
);
|
|
122
|
+
expect(processDataInstance.processEventData(e.type, e, '', el)).toEqual({
|
|
123
|
+
type: e.type,
|
|
124
|
+
});
|
|
125
|
+
expect(base.notifyAuthFailure).toBeCalledWith(auth.AuthFailureType.OTHER);
|
|
155
126
|
expect(el.innerHTML).toBe('Hello');
|
|
156
127
|
});
|
|
157
128
|
|
|
@@ -163,11 +134,9 @@ describe('Unit test for process data', () => {
|
|
|
163
134
|
authType: AuthType.None,
|
|
164
135
|
});
|
|
165
136
|
const el: any = {};
|
|
166
|
-
expect(processDataInstance.processEventData(e.type, e, '', el)).toEqual(
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
},
|
|
170
|
-
);
|
|
137
|
+
expect(processDataInstance.processEventData(e.type, e, '', el)).toEqual({
|
|
138
|
+
type: e.type,
|
|
139
|
+
});
|
|
171
140
|
expect(base.notifyAuthFailure).not.toBeCalled();
|
|
172
141
|
expect(el.innerHTML).not.toBe('Hello');
|
|
173
142
|
});
|
|
@@ -183,11 +152,9 @@ describe('Unit test for process data', () => {
|
|
|
183
152
|
const e = { type: EmbedEvent.AuthLogout };
|
|
184
153
|
jest.spyOn(base, 'notifyLogout');
|
|
185
154
|
const el: any = {};
|
|
186
|
-
expect(processDataInstance.processEventData(e.type, e, '', el)).toEqual(
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
},
|
|
190
|
-
);
|
|
155
|
+
expect(processDataInstance.processEventData(e.type, e, '', el)).toEqual({
|
|
156
|
+
type: e.type,
|
|
157
|
+
});
|
|
191
158
|
expect(base.notifyLogout).toBeCalled();
|
|
192
159
|
expect(el.innerHTML).toBe('Hello');
|
|
193
160
|
expect(base.getEmbedConfig().autoLogin).toBe(false);
|
package/src/utils/processData.ts
CHANGED
|
@@ -9,20 +9,19 @@ import { AuthFailureType, initSession } from '../auth';
|
|
|
9
9
|
import { AuthType, EmbedEvent, OperationType } from '../types';
|
|
10
10
|
import { getAnswerServiceInstance } from './answerService';
|
|
11
11
|
|
|
12
|
+
/**
|
|
13
|
+
*
|
|
14
|
+
* @param e
|
|
15
|
+
* @param thoughtSpotHost
|
|
16
|
+
*/
|
|
12
17
|
export function processCustomAction(e: any, thoughtSpotHost: string) {
|
|
13
18
|
if (
|
|
14
|
-
[
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
].includes(e.data?.operation)
|
|
19
|
+
[OperationType.GetChartWithData, OperationType.GetTableWithHeadlineData].includes(
|
|
20
|
+
e.data?.operation,
|
|
21
|
+
)
|
|
18
22
|
) {
|
|
19
23
|
const { session, query, operation } = e.data;
|
|
20
|
-
const answerService = getAnswerServiceInstance(
|
|
21
|
-
session,
|
|
22
|
-
query,
|
|
23
|
-
operation,
|
|
24
|
-
thoughtSpotHost,
|
|
25
|
-
);
|
|
24
|
+
const answerService = getAnswerServiceInstance(session, query, operation, thoughtSpotHost);
|
|
26
25
|
return {
|
|
27
26
|
...e,
|
|
28
27
|
answerService,
|
|
@@ -31,6 +30,10 @@ export function processCustomAction(e: any, thoughtSpotHost: string) {
|
|
|
31
30
|
return e;
|
|
32
31
|
}
|
|
33
32
|
|
|
33
|
+
/**
|
|
34
|
+
*
|
|
35
|
+
* @param e
|
|
36
|
+
*/
|
|
34
37
|
function processAuthInit(e: any) {
|
|
35
38
|
// Store user session details sent by app.
|
|
36
39
|
initSession(e.data);
|
|
@@ -45,11 +48,13 @@ function processAuthInit(e: any) {
|
|
|
45
48
|
};
|
|
46
49
|
}
|
|
47
50
|
|
|
51
|
+
/**
|
|
52
|
+
*
|
|
53
|
+
* @param e
|
|
54
|
+
* @param containerEl
|
|
55
|
+
*/
|
|
48
56
|
function processNoCookieAccess(e: any, containerEl: Element) {
|
|
49
|
-
const {
|
|
50
|
-
loginFailedMessage,
|
|
51
|
-
suppressNoCookieAccessAlert,
|
|
52
|
-
} = getEmbedConfig();
|
|
57
|
+
const { loginFailedMessage, suppressNoCookieAccessAlert } = getEmbedConfig();
|
|
53
58
|
if (!suppressNoCookieAccessAlert) {
|
|
54
59
|
// eslint-disable-next-line no-alert
|
|
55
60
|
alert(
|
|
@@ -62,6 +67,11 @@ function processNoCookieAccess(e: any, containerEl: Element) {
|
|
|
62
67
|
return e;
|
|
63
68
|
}
|
|
64
69
|
|
|
70
|
+
/**
|
|
71
|
+
*
|
|
72
|
+
* @param e
|
|
73
|
+
* @param containerEl
|
|
74
|
+
*/
|
|
65
75
|
function processAuthFailure(e: any, containerEl: Element) {
|
|
66
76
|
const { loginFailedMessage, authType } = getEmbedConfig();
|
|
67
77
|
if (authType !== AuthType.None) {
|
|
@@ -72,6 +82,11 @@ function processAuthFailure(e: any, containerEl: Element) {
|
|
|
72
82
|
return e;
|
|
73
83
|
}
|
|
74
84
|
|
|
85
|
+
/**
|
|
86
|
+
*
|
|
87
|
+
* @param e
|
|
88
|
+
* @param containerEl
|
|
89
|
+
*/
|
|
75
90
|
function processAuthLogout(e: any, containerEl: Element) {
|
|
76
91
|
const { loginFailedMessage } = getEmbedConfig();
|
|
77
92
|
// eslint-disable-next-line no-param-reassign
|
|
@@ -81,6 +96,13 @@ function processAuthLogout(e: any, containerEl: Element) {
|
|
|
81
96
|
return e;
|
|
82
97
|
}
|
|
83
98
|
|
|
99
|
+
/**
|
|
100
|
+
*
|
|
101
|
+
* @param type
|
|
102
|
+
* @param e
|
|
103
|
+
* @param thoughtSpotHost
|
|
104
|
+
* @param containerEl
|
|
105
|
+
*/
|
|
84
106
|
export function processEventData(
|
|
85
107
|
type: EmbedEvent,
|
|
86
108
|
e: any,
|
|
@@ -17,12 +17,7 @@ describe('Unit test for processTrigger', () => {
|
|
|
17
17
|
const messageType = HostEvent.Reload;
|
|
18
18
|
const thoughtSpotHost = 'http://localhost:3000';
|
|
19
19
|
const data = {};
|
|
20
|
-
_processTriggerInstance.processTrigger(
|
|
21
|
-
iFrameElement,
|
|
22
|
-
messageType,
|
|
23
|
-
thoughtSpotHost,
|
|
24
|
-
data,
|
|
25
|
-
);
|
|
20
|
+
_processTriggerInstance.processTrigger(iFrameElement, messageType, thoughtSpotHost, data);
|
|
26
21
|
expect(divFrame.childNodes[0]).not.toBe(iFrameElement);
|
|
27
22
|
});
|
|
28
23
|
|
|
@@ -3,6 +3,8 @@ import { HostEvent } from '../types';
|
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Reloads the ThoughtSpot iframe.
|
|
6
|
+
*
|
|
7
|
+
* @param iFrame
|
|
6
8
|
*/
|
|
7
9
|
function reload(iFrame: HTMLIFrameElement) {
|
|
8
10
|
const oldFrame = iFrame.cloneNode();
|
|
@@ -13,6 +15,13 @@ function reload(iFrame: HTMLIFrameElement) {
|
|
|
13
15
|
|
|
14
16
|
/**
|
|
15
17
|
* Post Iframe message.
|
|
18
|
+
*
|
|
19
|
+
* @param iFrame
|
|
20
|
+
* @param message
|
|
21
|
+
* @param message.type
|
|
22
|
+
* @param message.data
|
|
23
|
+
* @param thoughtSpotHost
|
|
24
|
+
* @param channel
|
|
16
25
|
*/
|
|
17
26
|
function postIframeMessage(
|
|
18
27
|
iFrame: HTMLIFrameElement,
|
|
@@ -20,13 +29,18 @@ function postIframeMessage(
|
|
|
20
29
|
thoughtSpotHost: string,
|
|
21
30
|
channel?: MessageChannel,
|
|
22
31
|
) {
|
|
23
|
-
return iFrame.contentWindow.postMessage(message, thoughtSpotHost, [
|
|
24
|
-
channel?.port2,
|
|
25
|
-
]);
|
|
32
|
+
return iFrame.contentWindow.postMessage(message, thoughtSpotHost, [channel?.port2]);
|
|
26
33
|
}
|
|
27
34
|
|
|
28
35
|
const TRIGGER_TIMEOUT = 30000;
|
|
29
36
|
|
|
37
|
+
/**
|
|
38
|
+
*
|
|
39
|
+
* @param iFrame
|
|
40
|
+
* @param messageType
|
|
41
|
+
* @param thoughtSpotHost
|
|
42
|
+
* @param data
|
|
43
|
+
*/
|
|
30
44
|
export function processTrigger(
|
|
31
45
|
iFrame: HTMLIFrameElement,
|
|
32
46
|
messageType: HostEvent,
|
|
@@ -54,11 +68,6 @@ export function processTrigger(
|
|
|
54
68
|
res(new Error(ERROR_MESSAGE.TRIGGER_TIMED_OUT));
|
|
55
69
|
}, TRIGGER_TIMEOUT);
|
|
56
70
|
|
|
57
|
-
return postIframeMessage(
|
|
58
|
-
iFrame,
|
|
59
|
-
{ type: messageType, data },
|
|
60
|
-
thoughtSpotHost,
|
|
61
|
-
channel,
|
|
62
|
-
);
|
|
71
|
+
return postIframeMessage(iFrame, { type: messageType, data }, thoughtSpotHost, channel);
|
|
63
72
|
});
|
|
64
73
|
}
|
package/src/utils.spec.ts
CHANGED
|
@@ -77,9 +77,7 @@ describe('unit test for utils', () => {
|
|
|
77
77
|
expect(appendToUrlHash('http://myhost:3000', 'hashFrag')).toBe(
|
|
78
78
|
'http://myhost:3000#hashFrag',
|
|
79
79
|
);
|
|
80
|
-
expect(appendToUrlHash('http://xyz.com/#foo', 'bar')).toBe(
|
|
81
|
-
'http://xyz.com/#foobar',
|
|
82
|
-
);
|
|
80
|
+
expect(appendToUrlHash('http://xyz.com/#foo', 'bar')).toBe('http://xyz.com/#foobar');
|
|
83
81
|
});
|
|
84
82
|
|
|
85
83
|
describe('getRedirectURL', () => {
|
|
@@ -87,9 +85,7 @@ describe('unit test for utils', () => {
|
|
|
87
85
|
expect(getRedirectUrl('http://myhost:3000', 'hashFrag')).toBe(
|
|
88
86
|
'http://myhost:3000#hashFrag',
|
|
89
87
|
);
|
|
90
|
-
expect(getRedirectUrl('http://xyz.com/#foo', 'bar')).toBe(
|
|
91
|
-
'http://xyz.com/#foobar',
|
|
92
|
-
);
|
|
88
|
+
expect(getRedirectUrl('http://xyz.com/#foo', 'bar')).toBe('http://xyz.com/#foobar');
|
|
93
89
|
});
|
|
94
90
|
|
|
95
91
|
test('Should return correct value when path is set', () => {
|
|
@@ -97,13 +93,13 @@ describe('unit test for utils', () => {
|
|
|
97
93
|
get: () => 'http://myhost:3000',
|
|
98
94
|
});
|
|
99
95
|
|
|
100
|
-
expect(
|
|
101
|
-
|
|
102
|
-
)
|
|
96
|
+
expect(getRedirectUrl('http://myhost:3000/', 'hashFrag', '/bar')).toBe(
|
|
97
|
+
'http://myhost:3000/bar#hashFrag',
|
|
98
|
+
);
|
|
103
99
|
|
|
104
|
-
expect(
|
|
105
|
-
|
|
106
|
-
)
|
|
100
|
+
expect(getRedirectUrl('http://myhost:3000/#/foo', 'hashFrag', '#/bar')).toBe(
|
|
101
|
+
'http://myhost:3000/#/barhashFrag',
|
|
102
|
+
);
|
|
107
103
|
});
|
|
108
104
|
});
|
|
109
105
|
|