@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.
Files changed (41) hide show
  1. package/CHANGELOG.md +6 -2
  2. package/dist/src/auth.d.ts +5 -5
  3. package/dist/src/embed/base.d.ts +4 -4
  4. package/dist/src/embed/pinboard.d.ts +91 -0
  5. package/dist/src/embed/search.d.ts +0 -4
  6. package/dist/src/utils/plugin.d.ts +0 -0
  7. package/dist/src/v1/api.d.ts +19 -0
  8. package/dist/tsembed.es.js +31 -13
  9. package/dist/tsembed.js +31 -13
  10. package/lib/package.json +1 -1
  11. package/lib/src/auth.d.ts +5 -5
  12. package/lib/src/auth.js +13 -5
  13. package/lib/src/auth.js.map +1 -1
  14. package/lib/src/auth.spec.js +7 -3
  15. package/lib/src/auth.spec.js.map +1 -1
  16. package/lib/src/embed/base.d.ts +4 -4
  17. package/lib/src/embed/base.js.map +1 -1
  18. package/lib/src/embed/pinboard.d.ts +91 -0
  19. package/lib/src/embed/pinboard.js +110 -0
  20. package/lib/src/embed/pinboard.js.map +1 -0
  21. package/lib/src/embed/search.d.ts +0 -4
  22. package/lib/src/embed/search.js +1 -1
  23. package/lib/src/embed/search.js.map +1 -1
  24. package/lib/src/embed/ts-embed.js +5 -1
  25. package/lib/src/embed/ts-embed.js.map +1 -1
  26. package/lib/src/utils/authService.js +11 -5
  27. package/lib/src/utils/authService.js.map +1 -1
  28. package/lib/src/utils/authService.spec.js +4 -2
  29. package/lib/src/utils/authService.spec.js.map +1 -1
  30. package/lib/src/utils/plugin.d.ts +0 -0
  31. package/lib/src/utils/plugin.js +1 -0
  32. package/lib/src/utils/plugin.js.map +1 -0
  33. package/lib/src/visual-embed-sdk.d.ts +4 -8
  34. package/package.json +1 -1
  35. package/src/auth.spec.ts +11 -3
  36. package/src/auth.ts +24 -10
  37. package/src/embed/base.ts +4 -4
  38. package/src/embed/search.ts +0 -5
  39. package/src/embed/ts-embed.ts +6 -1
  40. package/src/utils/authService.spec.ts +8 -2
  41. 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 (embedConfig: EmbedConfig): Promise<void> => {
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(thoughtSpotHost, username, authToken);
108
- loggedInStatus = false;
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 (embedConfig: EmbedConfig): Promise<void> => {
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 (embedConfig: EmbedConfig): Promise<void> => {
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<void>;
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<void> => {
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<void> => authPromise;
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<void> => {
62
+ export const init = (embedConfig: EmbedConfig): Promise<boolean> => {
63
63
  config = embedConfig;
64
64
  handleAuth();
65
65
 
@@ -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,
@@ -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(() => Promise.resolve({ success: true }));
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(() => Promise.resolve({ success: true }));
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
  });
@@ -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 fetch(authVerificationUrl, {
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 fetch(
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 fetch(`${thoughtSpotHost}${EndPoints.BASIC_LOGIN}`, {
45
+ return errorLoggedFetch(`${thoughtSpotHost}${EndPoints.BASIC_LOGIN}`, {
37
46
  method: 'POST',
38
47
  headers: {
39
48
  'content-type': 'application/x-www-form-urlencoded',