@thoughtspot/visual-embed-sdk 1.10.0 → 1.11.0-auth.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/CHANGELOG.md +6 -2
- package/dist/src/auth.d.ts +5 -5
- package/dist/src/embed/base.d.ts +4 -4
- package/dist/src/embed/pinboard.d.ts +91 -0
- package/dist/src/embed/search.d.ts +0 -4
- package/dist/src/utils/plugin.d.ts +0 -0
- package/dist/src/v1/api.d.ts +19 -0
- package/dist/tsembed.es.js +31 -13
- package/dist/tsembed.js +31 -13
- package/lib/package.json +1 -1
- package/lib/src/auth.d.ts +5 -5
- package/lib/src/auth.js +13 -5
- package/lib/src/auth.js.map +1 -1
- package/lib/src/auth.spec.js +7 -3
- package/lib/src/auth.spec.js.map +1 -1
- package/lib/src/embed/base.d.ts +4 -4
- package/lib/src/embed/base.js.map +1 -1
- package/lib/src/embed/pinboard.d.ts +91 -0
- package/lib/src/embed/pinboard.js +110 -0
- package/lib/src/embed/pinboard.js.map +1 -0
- package/lib/src/embed/search.d.ts +0 -4
- package/lib/src/embed/search.js +1 -1
- package/lib/src/embed/search.js.map +1 -1
- package/lib/src/embed/ts-embed.js +5 -1
- package/lib/src/embed/ts-embed.js.map +1 -1
- package/lib/src/utils/authService.js +11 -5
- package/lib/src/utils/authService.js.map +1 -1
- package/lib/src/utils/authService.spec.js +4 -2
- package/lib/src/utils/authService.spec.js.map +1 -1
- package/lib/src/utils/plugin.d.ts +0 -0
- package/lib/src/utils/plugin.js +1 -0
- package/lib/src/utils/plugin.js.map +1 -0
- package/lib/src/visual-embed-sdk.d.ts +4 -8
- package/package.json +1 -1
- package/src/auth.spec.ts +11 -3
- package/src/auth.ts +24 -10
- package/src/embed/base.ts +4 -4
- package/src/embed/search.ts +0 -5
- package/src/embed/ts-embed.ts +6 -1
- package/src/utils/authService.spec.ts +8 -2
- package/src/utils/authService.ts +15 -6
package/src/auth.ts
CHANGED
|
@@ -83,7 +83,9 @@ function removeSSORedirectUrlMarker(): void {
|
|
|
83
83
|
* Perform token based authentication
|
|
84
84
|
* @param embedConfig The embed configuration
|
|
85
85
|
*/
|
|
86
|
-
export const doTokenAuth = async (
|
|
86
|
+
export const doTokenAuth = async (
|
|
87
|
+
embedConfig: EmbedConfig,
|
|
88
|
+
): Promise<boolean> => {
|
|
87
89
|
const {
|
|
88
90
|
thoughtSpotHost,
|
|
89
91
|
username,
|
|
@@ -104,11 +106,16 @@ export const doTokenAuth = async (embedConfig: EmbedConfig): Promise<void> => {
|
|
|
104
106
|
const response = await fetchAuthTokenService(authEndpoint);
|
|
105
107
|
authToken = await response.text();
|
|
106
108
|
}
|
|
107
|
-
await fetchAuthService(
|
|
108
|
-
|
|
109
|
+
const resp = await fetchAuthService(
|
|
110
|
+
thoughtSpotHost,
|
|
111
|
+
username,
|
|
112
|
+
authToken,
|
|
113
|
+
);
|
|
114
|
+
loggedInStatus = resp.status === 200;
|
|
115
|
+
} else {
|
|
116
|
+
loggedInStatus = true;
|
|
109
117
|
}
|
|
110
|
-
|
|
111
|
-
loggedInStatus = true;
|
|
118
|
+
return loggedInStatus;
|
|
112
119
|
};
|
|
113
120
|
|
|
114
121
|
/**
|
|
@@ -119,7 +126,9 @@ export const doTokenAuth = async (embedConfig: EmbedConfig): Promise<void> => {
|
|
|
119
126
|
* strongly advised not to use this authentication method in production.
|
|
120
127
|
* @param embedConfig The embed configuration
|
|
121
128
|
*/
|
|
122
|
-
export const doBasicAuth = async (
|
|
129
|
+
export const doBasicAuth = async (
|
|
130
|
+
embedConfig: EmbedConfig,
|
|
131
|
+
): Promise<boolean> => {
|
|
123
132
|
const { thoughtSpotHost, username, password } = embedConfig;
|
|
124
133
|
const loggedIn = await isLoggedIn(thoughtSpotHost);
|
|
125
134
|
if (!loggedIn) {
|
|
@@ -129,9 +138,10 @@ export const doBasicAuth = async (embedConfig: EmbedConfig): Promise<void> => {
|
|
|
129
138
|
password,
|
|
130
139
|
);
|
|
131
140
|
loggedInStatus = response.status === 200;
|
|
141
|
+
} else {
|
|
142
|
+
loggedInStatus = true;
|
|
132
143
|
}
|
|
133
|
-
|
|
134
|
-
loggedInStatus = true;
|
|
144
|
+
return loggedInStatus;
|
|
135
145
|
};
|
|
136
146
|
|
|
137
147
|
async function samlPopupFlow(ssoURL: string) {
|
|
@@ -218,6 +228,7 @@ export const doSamlAuth = async (embedConfig: EmbedConfig) => {
|
|
|
218
228
|
)}`;
|
|
219
229
|
|
|
220
230
|
await doSSOAuth(embedConfig, ssoEndPoint);
|
|
231
|
+
return loggedInStatus;
|
|
221
232
|
};
|
|
222
233
|
|
|
223
234
|
export const doOIDCAuth = async (embedConfig: EmbedConfig) => {
|
|
@@ -234,13 +245,16 @@ export const doOIDCAuth = async (embedConfig: EmbedConfig) => {
|
|
|
234
245
|
)}`;
|
|
235
246
|
|
|
236
247
|
await doSSOAuth(embedConfig, ssoEndPoint);
|
|
248
|
+
return loggedInStatus;
|
|
237
249
|
};
|
|
238
250
|
|
|
239
251
|
/**
|
|
240
252
|
* Perform authentication on the ThoughtSpot cluster
|
|
241
253
|
* @param embedConfig The embed configuration
|
|
242
254
|
*/
|
|
243
|
-
export const authenticate = async (
|
|
255
|
+
export const authenticate = async (
|
|
256
|
+
embedConfig: EmbedConfig,
|
|
257
|
+
): Promise<boolean> => {
|
|
244
258
|
const { authType } = embedConfig;
|
|
245
259
|
switch (authType) {
|
|
246
260
|
case AuthType.SSO:
|
|
@@ -252,7 +266,7 @@ export const authenticate = async (embedConfig: EmbedConfig): Promise<void> => {
|
|
|
252
266
|
case AuthType.Basic:
|
|
253
267
|
return doBasicAuth(embedConfig);
|
|
254
268
|
default:
|
|
255
|
-
return Promise.resolve();
|
|
269
|
+
return Promise.resolve(true);
|
|
256
270
|
}
|
|
257
271
|
};
|
|
258
272
|
|
package/src/embed/base.ts
CHANGED
|
@@ -14,12 +14,12 @@ import { uploadMixpanelEvent, MIXPANEL_EVENT } from '../mixpanel-service';
|
|
|
14
14
|
|
|
15
15
|
let config = {} as EmbedConfig;
|
|
16
16
|
|
|
17
|
-
export let authPromise: Promise<
|
|
17
|
+
export let authPromise: Promise<boolean>;
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
20
|
* Perform authentication on the ThoughtSpot app as applicable.
|
|
21
21
|
*/
|
|
22
|
-
export const handleAuth = (): Promise<
|
|
22
|
+
export const handleAuth = (): Promise<boolean> => {
|
|
23
23
|
const authConfig = {
|
|
24
24
|
...config,
|
|
25
25
|
thoughtSpotHost: getThoughtSpotHost(config),
|
|
@@ -30,7 +30,7 @@ export const handleAuth = (): Promise<void> => {
|
|
|
30
30
|
|
|
31
31
|
export const getEmbedConfig = (): EmbedConfig => config;
|
|
32
32
|
|
|
33
|
-
export const getAuthPromise = (): Promise<
|
|
33
|
+
export const getAuthPromise = (): Promise<boolean> => authPromise;
|
|
34
34
|
|
|
35
35
|
/**
|
|
36
36
|
* Prefetches static resources from the specified URL. Web browsers can then cache the prefetched resources and serve them from the user's local disk to provide faster access to your app.
|
|
@@ -59,7 +59,7 @@ export const prefetch = (url?: string): void => {
|
|
|
59
59
|
*
|
|
60
60
|
* @returns authPromise Promise which resolves when authentication is complete.
|
|
61
61
|
*/
|
|
62
|
-
export const init = (embedConfig: EmbedConfig): Promise<
|
|
62
|
+
export const init = (embedConfig: EmbedConfig): Promise<boolean> => {
|
|
63
63
|
config = embedConfig;
|
|
64
64
|
handleAuth();
|
|
65
65
|
|
package/src/embed/search.ts
CHANGED
|
@@ -49,10 +49,6 @@ export interface SearchViewConfig extends ViewConfig {
|
|
|
49
49
|
* using raw answer data.
|
|
50
50
|
*/
|
|
51
51
|
hideResults?: boolean;
|
|
52
|
-
/**
|
|
53
|
-
* If set to true, expands all the data sources panel.
|
|
54
|
-
*/
|
|
55
|
-
expandAllDataSource?: boolean;
|
|
56
52
|
/**
|
|
57
53
|
* If set to true, the Search Assist feature is enabled.
|
|
58
54
|
*/
|
|
@@ -130,7 +126,6 @@ export class SearchEmbed extends TsEmbed {
|
|
|
130
126
|
private getIFrameSrc(answerId: string, dataSources?: string[]) {
|
|
131
127
|
const {
|
|
132
128
|
hideResults,
|
|
133
|
-
expandAllDataSource,
|
|
134
129
|
enableSearchAssist,
|
|
135
130
|
forceTable,
|
|
136
131
|
searchOptions,
|
package/src/embed/ts-embed.ts
CHANGED
|
@@ -464,7 +464,12 @@ export class TsEmbed {
|
|
|
464
464
|
uploadMixpanelEvent(MIXPANEL_EVENT.VISUAL_SDK_RENDER_START);
|
|
465
465
|
|
|
466
466
|
getAuthPromise()
|
|
467
|
-
?.then(() => {
|
|
467
|
+
?.then((isLoggedIn: boolean) => {
|
|
468
|
+
if (!isLoggedIn) {
|
|
469
|
+
this.el.innerHTML = 'Login failed';
|
|
470
|
+
return;
|
|
471
|
+
}
|
|
472
|
+
|
|
468
473
|
uploadMixpanelEvent(
|
|
469
474
|
MIXPANEL_EVENT.VISUAL_SDK_RENDER_COMPLETE,
|
|
470
475
|
);
|
|
@@ -21,6 +21,7 @@ describe('Unit test for authService', () => {
|
|
|
21
21
|
Promise.resolve({
|
|
22
22
|
json: () => ({ success: true }),
|
|
23
23
|
status: 200,
|
|
24
|
+
ok: true,
|
|
24
25
|
}),
|
|
25
26
|
);
|
|
26
27
|
const response = await fetchSessionInfoService(authVerificationUrl);
|
|
@@ -32,6 +33,7 @@ describe('Unit test for authService', () => {
|
|
|
32
33
|
global.fetch = jest.fn(() =>
|
|
33
34
|
Promise.resolve({
|
|
34
35
|
text: () => ({ success: true }),
|
|
36
|
+
ok: true,
|
|
35
37
|
}),
|
|
36
38
|
);
|
|
37
39
|
const response = await fetchAuthTokenService(authEndpoint);
|
|
@@ -40,13 +42,17 @@ describe('Unit test for authService', () => {
|
|
|
40
42
|
});
|
|
41
43
|
|
|
42
44
|
test('fetchAuthService', async () => {
|
|
43
|
-
global.fetch = jest.fn(() =>
|
|
45
|
+
global.fetch = jest.fn(() =>
|
|
46
|
+
Promise.resolve({ success: true, ok: true }),
|
|
47
|
+
);
|
|
44
48
|
await fetchAuthService(authVerificationUrl, username, authToken);
|
|
45
49
|
expect(fetch).toBeCalled();
|
|
46
50
|
});
|
|
47
51
|
|
|
48
52
|
test('fetchBasicAuthService', async () => {
|
|
49
|
-
global.fetch = jest.fn(() =>
|
|
53
|
+
global.fetch = jest.fn(() =>
|
|
54
|
+
Promise.resolve({ success: true, ok: true }),
|
|
55
|
+
);
|
|
50
56
|
await fetchBasicAuthService(thoughtSpotHost, username, password);
|
|
51
57
|
expect(fetch).toBeCalled();
|
|
52
58
|
});
|
package/src/utils/authService.ts
CHANGED
|
@@ -1,10 +1,22 @@
|
|
|
1
1
|
// eslint-disable-next-line import/no-cycle
|
|
2
2
|
import { EndPoints } from '../auth';
|
|
3
3
|
|
|
4
|
+
function errorLoggedFetch(
|
|
5
|
+
url: string,
|
|
6
|
+
options: RequestInit = {},
|
|
7
|
+
): Promise<Response> {
|
|
8
|
+
return fetch(url, options).then(async (r) => {
|
|
9
|
+
if (!r.ok) {
|
|
10
|
+
console.error('Failure', await r.json());
|
|
11
|
+
}
|
|
12
|
+
return r;
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
|
|
4
16
|
export function fetchSessionInfoService(
|
|
5
17
|
authVerificationUrl: string,
|
|
6
18
|
): Promise<any> {
|
|
7
|
-
return
|
|
19
|
+
return errorLoggedFetch(authVerificationUrl, {
|
|
8
20
|
credentials: 'include',
|
|
9
21
|
});
|
|
10
22
|
}
|
|
@@ -20,11 +32,8 @@ export async function fetchAuthService(
|
|
|
20
32
|
username: string,
|
|
21
33
|
authToken: string,
|
|
22
34
|
): Promise<any> {
|
|
23
|
-
return
|
|
35
|
+
return errorLoggedFetch(
|
|
24
36
|
`${thoughtSpotHost}${EndPoints.TOKEN_LOGIN}?username=${username}&auth_token=${authToken}`,
|
|
25
|
-
{
|
|
26
|
-
credentials: 'include',
|
|
27
|
-
},
|
|
28
37
|
);
|
|
29
38
|
}
|
|
30
39
|
|
|
@@ -33,7 +42,7 @@ export async function fetchBasicAuthService(
|
|
|
33
42
|
username: string,
|
|
34
43
|
password: string,
|
|
35
44
|
): Promise<any> {
|
|
36
|
-
return
|
|
45
|
+
return errorLoggedFetch(`${thoughtSpotHost}${EndPoints.BASIC_LOGIN}`, {
|
|
37
46
|
method: 'POST',
|
|
38
47
|
headers: {
|
|
39
48
|
'content-type': 'application/x-www-form-urlencoded',
|