@thoughtspot/visual-embed-sdk 1.26.0-token-cache.2 → 1.26.1-alpha.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.
Files changed (66) hide show
  1. package/cjs/package.json +1 -1
  2. package/cjs/src/auth.d.ts.map +1 -1
  3. package/cjs/src/auth.js +6 -5
  4. package/cjs/src/auth.js.map +1 -1
  5. package/cjs/src/auth.spec.d.ts.map +1 -1
  6. package/cjs/src/auth.spec.js +27 -26
  7. package/cjs/src/auth.spec.js.map +1 -1
  8. package/cjs/src/authToken.d.ts.map +1 -1
  9. package/cjs/src/authToken.js +6 -5
  10. package/cjs/src/authToken.js.map +1 -1
  11. package/cjs/src/types.d.ts +2 -0
  12. package/cjs/src/types.d.ts.map +1 -1
  13. package/cjs/src/types.js.map +1 -1
  14. package/cjs/src/utils/authService/index.d.ts +1 -1
  15. package/cjs/src/utils/authService/index.d.ts.map +1 -1
  16. package/cjs/src/utils/authService/index.js +3 -3
  17. package/cjs/src/utils/authService/index.js.map +1 -1
  18. package/cjs/src/utils/authService/tokenizedAuthService.d.ts +11 -0
  19. package/cjs/src/utils/authService/tokenizedAuthService.d.ts.map +1 -0
  20. package/cjs/src/utils/authService/tokenizedAuthService.js +44 -0
  21. package/cjs/src/utils/authService/tokenizedAuthService.js.map +1 -0
  22. package/dist/src/auth.d.ts.map +1 -1
  23. package/dist/src/auth.spec.d.ts.map +1 -1
  24. package/dist/src/authToken.d.ts.map +1 -1
  25. package/dist/src/types.d.ts +2 -0
  26. package/dist/src/types.d.ts.map +1 -1
  27. package/dist/src/utils/authService/index.d.ts +1 -1
  28. package/dist/src/utils/authService/index.d.ts.map +1 -1
  29. package/dist/src/utils/authService/tokenizedAuthService.d.ts +11 -0
  30. package/dist/src/utils/authService/tokenizedAuthService.d.ts.map +1 -0
  31. package/dist/tsembed-react.es.js +59 -57
  32. package/dist/tsembed-react.js +59 -57
  33. package/dist/tsembed.es.js +82 -80
  34. package/dist/tsembed.js +82 -80
  35. package/dist/visual-embed-sdk-react-full.d.ts +2 -0
  36. package/dist/visual-embed-sdk-react.d.ts +2 -0
  37. package/dist/visual-embed-sdk.d.ts +2 -0
  38. package/lib/package.json +1 -1
  39. package/lib/src/auth.d.ts.map +1 -1
  40. package/lib/src/auth.js +6 -5
  41. package/lib/src/auth.js.map +1 -1
  42. package/lib/src/auth.spec.d.ts.map +1 -1
  43. package/lib/src/auth.spec.js +27 -26
  44. package/lib/src/auth.spec.js.map +1 -1
  45. package/lib/src/authToken.d.ts.map +1 -1
  46. package/lib/src/authToken.js +6 -5
  47. package/lib/src/authToken.js.map +1 -1
  48. package/lib/src/types.d.ts +2 -0
  49. package/lib/src/types.d.ts.map +1 -1
  50. package/lib/src/types.js.map +1 -1
  51. package/lib/src/utils/authService/index.d.ts +1 -1
  52. package/lib/src/utils/authService/index.d.ts.map +1 -1
  53. package/lib/src/utils/authService/index.js +1 -1
  54. package/lib/src/utils/authService/index.js.map +1 -1
  55. package/lib/src/utils/authService/tokenizedAuthService.d.ts +11 -0
  56. package/lib/src/utils/authService/tokenizedAuthService.d.ts.map +1 -0
  57. package/lib/src/utils/authService/tokenizedAuthService.js +39 -0
  58. package/lib/src/utils/authService/tokenizedAuthService.js.map +1 -0
  59. package/lib/src/visual-embed-sdk.d.ts +2 -0
  60. package/package.json +1 -1
  61. package/src/auth.spec.ts +37 -32
  62. package/src/auth.ts +6 -4
  63. package/src/authToken.ts +6 -8
  64. package/src/types.ts +29 -23
  65. package/src/utils/authService/index.ts +1 -1
  66. /package/src/utils/authService/{tokenisedAuthSerice.ts → tokenizedAuthService.ts} +0 -0
package/src/auth.spec.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import * as authInstance from './auth';
2
- import * as authService from './utils/authService';
2
+ import * as authService from './utils/authService/authService';
3
+ import * as tokenAuthService from './utils/authService/tokenizedAuthService';
3
4
  import * as checkReleaseVersionInBetaInstance from './utils';
4
5
  import * as mixPanelService from './mixpanel-service';
5
6
  import { AuthType, EmbedEvent } from './types';
@@ -152,19 +153,19 @@ describe('Unit test for auth', () => {
152
153
  });
153
154
 
154
155
  test('doTokenAuth: when user is loggedIn', async () => {
155
- jest.spyOn(authService, 'fetchSessionInfoService').mockImplementation(async () => ({
156
+ jest.spyOn(tokenAuthService, 'fetchSessionInfoService').mockImplementation(async () => ({
156
157
  json: () => mockSessionInfo,
157
158
  status: 200,
158
159
  }));
159
160
  jest.spyOn(authInstance, 'getSessionDetails').mockReturnValue(mockSessionInfo);
160
161
  jest.spyOn(authInstance, 'initSession').mockReturnValue(null);
161
162
  await authInstance.doTokenAuth(embedConfig.doTokenAuthSuccess('authToken'));
162
- expect(authService.fetchSessionInfoService).toBeCalled();
163
+ expect(tokenAuthService.fetchSessionInfoService).toBeCalled();
163
164
  expect(authInstance.loggedInStatus).toBe(true);
164
165
  });
165
166
 
166
167
  test('doTokenAuth: when user is not loggedIn & getAuthToken have response', async () => {
167
- jest.spyOn(authService, 'fetchSessionInfoService').mockImplementation(() => false);
168
+ jest.spyOn(tokenAuthService, 'fetchSessionInfoService').mockImplementation(() => false);
168
169
  jest.spyOn(authService, 'fetchAuthTokenService').mockImplementation(() => ({
169
170
  text: () => Promise.resolve('abc'),
170
171
  }));
@@ -173,7 +174,7 @@ describe('Unit test for auth', () => {
173
174
  }));
174
175
  jest.spyOn(authService, 'verifyTokenService').mockResolvedValueOnce(true);
175
176
  await authInstance.doTokenAuth(embedConfig.doTokenAuthSuccess('authToken2'));
176
- expect(authService.fetchSessionInfoService).toBeCalled();
177
+ expect(tokenAuthService.fetchSessionInfoService).toBeCalled();
177
178
  expect(authService.fetchAuthService).toBeCalledWith(
178
179
  thoughtSpotHost,
179
180
  username,
@@ -182,7 +183,7 @@ describe('Unit test for auth', () => {
182
183
  });
183
184
 
184
185
  test('doTokenAuth: when user is not loggedIn & getAuthToken not present, isLoggedIn should called', async () => {
185
- jest.spyOn(authService, 'fetchSessionInfoService').mockImplementation(() => false);
186
+ jest.spyOn(tokenAuthService, 'fetchSessionInfoService').mockImplementation(() => false);
186
187
  jest.spyOn(authService, 'fetchAuthTokenService').mockImplementation(() => Promise.resolve({ text: () => Promise.resolve('abc') }));
187
188
  jest.spyOn(authService, 'fetchAuthService').mockImplementation(() => Promise.resolve({
188
189
  status: 200,
@@ -192,7 +193,7 @@ describe('Unit test for auth', () => {
192
193
  await authInstance.doTokenAuth(embedConfig.doTokenAuthFailureWithoutGetAuthToken);
193
194
  await executeAfterWait(() => {
194
195
  expect(authInstance.loggedInStatus).toBe(true);
195
- expect(authService.fetchSessionInfoService).toBeCalled();
196
+ expect(tokenAuthService.fetchSessionInfoService).toBeCalled();
196
197
  expect(authService.fetchAuthService).toBeCalledWith(
197
198
  thoughtSpotHost,
198
199
  username,
@@ -202,7 +203,7 @@ describe('Unit test for auth', () => {
202
203
  });
203
204
 
204
205
  test('doTokenAuth: Should raise error when duplicate token is used', async () => {
205
- jest.spyOn(authService, 'fetchSessionInfoService').mockResolvedValue({
206
+ jest.spyOn(tokenAuthService, 'fetchSessionInfoService').mockResolvedValue({
206
207
  status: 401,
207
208
  });
208
209
  jest.spyOn(window, 'alert').mockClear();
@@ -230,7 +231,7 @@ describe('Unit test for auth', () => {
230
231
  });
231
232
 
232
233
  test('doTokenAuth: Should set loggedInStatus if detectThirdPartyCookieAccess is true and the second info call fails', async () => {
233
- jest.spyOn(authService, 'fetchSessionInfoService')
234
+ jest.spyOn(tokenAuthService, 'fetchSessionInfoService')
234
235
  .mockResolvedValue({
235
236
  status: 401,
236
237
  })
@@ -244,13 +245,13 @@ describe('Unit test for auth', () => {
244
245
  }));
245
246
  jest.spyOn(authService, 'verifyTokenService').mockResolvedValueOnce(true);
246
247
  const isLoggedIn = await authInstance.doTokenAuth(embedConfig.doTokenAuthWithCookieDetect);
247
- expect(authService.fetchSessionInfoService).toHaveBeenCalledTimes(2);
248
+ expect(tokenAuthService.fetchSessionInfoService).toHaveBeenCalledTimes(2);
248
249
  expect(isLoggedIn).toBe(false);
249
250
  });
250
251
 
251
252
  test('doTokenAuth: when user is not loggedIn & fetchAuthPostService failed than fetchAuthService should call', async () => {
252
253
  jest.spyOn(window, 'alert').mockImplementation(() => undefined);
253
- jest.spyOn(authService, 'fetchSessionInfoService').mockImplementation(() => false);
254
+ jest.spyOn(tokenAuthService, 'fetchSessionInfoService').mockImplementation(() => false);
254
255
  jest.spyOn(authService, 'fetchAuthTokenService').mockImplementation(() => ({
255
256
  text: () => Promise.resolve('abc'),
256
257
  }));
@@ -267,7 +268,7 @@ describe('Unit test for auth', () => {
267
268
  expect(await authInstance.doTokenAuth(embedConfig.doTokenAuthSuccess('authToken2'))).toBe(
268
269
  true,
269
270
  );
270
- expect(authService.fetchSessionInfoService).toBeCalled();
271
+ expect(tokenAuthService.fetchSessionInfoService).toBeCalled();
271
272
  expect(authService.fetchAuthPostService).toBeCalledWith(
272
273
  thoughtSpotHost,
273
274
  username,
@@ -289,26 +290,28 @@ describe('Unit test for auth', () => {
289
290
  spyOn(checkReleaseVersionInBetaInstance, 'checkReleaseVersionInBeta');
290
291
  jest.spyOn(authInstance, 'getSessionDetails').mockReturnValue(mockSessionInfo);
291
292
  jest.spyOn(authInstance, 'initSession').mockReturnValue(null);
292
- jest.spyOn(authService, 'fetchSessionInfoService').mockImplementation(async () => ({
293
- json: () => mockSessionInfo,
294
- status: 200,
295
- }));
293
+ jest.spyOn(tokenAuthService, 'fetchSessionInfoService').mockImplementation(
294
+ async () => ({
295
+ json: () => mockSessionInfo,
296
+ status: 200,
297
+ }),
298
+ );
296
299
  await authInstance.doBasicAuth(embedConfig.doBasicAuth);
297
- expect(authService.fetchSessionInfoService).toBeCalled();
300
+ expect(tokenAuthService.fetchSessionInfoService).toBeCalled();
298
301
  expect(authInstance.loggedInStatus).toBe(true);
299
302
  expect(authInstance.getSessionDetails).toBeCalled();
300
303
  expect(authInstance.initSession).toBeCalled();
301
304
  });
302
305
 
303
306
  it('when user is not loggedIn', async () => {
304
- jest.spyOn(authService, 'fetchSessionInfoService').mockImplementation(() => Promise.reject());
307
+ jest.spyOn(tokenAuthService, 'fetchSessionInfoService').mockImplementation(() => Promise.reject());
305
308
  jest.spyOn(authService, 'fetchBasicAuthService').mockImplementation(() => ({
306
309
  status: 200,
307
310
  ok: true,
308
311
  }));
309
312
 
310
313
  await authInstance.doBasicAuth(embedConfig.doBasicAuth);
311
- expect(authService.fetchSessionInfoService).toBeCalled();
314
+ expect(tokenAuthService.fetchSessionInfoService).toBeCalled();
312
315
  expect(authService.fetchBasicAuthService).toBeCalled();
313
316
  expect(authInstance.loggedInStatus).toBe(true);
314
317
  });
@@ -330,22 +333,24 @@ describe('Unit test for auth', () => {
330
333
  hash: '',
331
334
  },
332
335
  });
333
- jest.spyOn(authService, 'fetchSessionInfoService').mockImplementation(async () => ({
334
- json: () => mockSessionInfo,
335
- status: 200,
336
- }));
336
+ jest.spyOn(tokenAuthService, 'fetchSessionInfoService').mockImplementation(
337
+ async () => ({
338
+ json: () => mockSessionInfo,
339
+ status: 200,
340
+ }),
341
+ );
337
342
  jest.spyOn(authInstance, 'getSessionDetails').mockReturnValue(mockSessionInfo);
338
343
  jest.spyOn(authInstance, 'initSession').mockReturnValue(null);
339
344
  await authInstance.doSamlAuth(embedConfig.doSamlAuth);
340
- expect(authService.fetchSessionInfoService).toBeCalled();
345
+ expect(tokenAuthService.fetchSessionInfoService).toBeCalled();
341
346
  expect(window.location.hash).toBe('');
342
347
  expect(authInstance.loggedInStatus).toBe(true);
343
348
  });
344
349
 
345
350
  it('when user is not loggedIn & isAtSSORedirectUrl is true', async () => {
346
- jest.spyOn(authService, 'fetchSessionInfoService').mockImplementation(() => Promise.reject());
351
+ jest.spyOn(tokenAuthService, 'fetchSessionInfoService').mockImplementation(() => Promise.reject());
347
352
  await authInstance.doSamlAuth(embedConfig.doSamlAuth);
348
- expect(authService.fetchSessionInfoService).toBeCalled();
353
+ expect(tokenAuthService.fetchSessionInfoService).toBeCalled();
349
354
  expect(window.location.hash).toBe('');
350
355
  expect(authInstance.loggedInStatus).toBe(false);
351
356
  });
@@ -357,9 +362,9 @@ describe('Unit test for auth', () => {
357
362
  hash: '',
358
363
  },
359
364
  });
360
- jest.spyOn(authService, 'fetchSessionInfoService').mockImplementation(() => Promise.reject());
365
+ jest.spyOn(tokenAuthService, 'fetchSessionInfoService').mockImplementation(() => Promise.reject());
361
366
  await authInstance.doSamlAuth(embedConfig.doSamlAuth);
362
- expect(authService.fetchSessionInfoService).toBeCalled();
367
+ expect(tokenAuthService.fetchSessionInfoService).toBeCalled();
363
368
  expect(global.window.location.href).toBe(samalLoginUrl);
364
369
  });
365
370
 
@@ -372,7 +377,7 @@ describe('Unit test for auth', () => {
372
377
  });
373
378
  spyOn(authInstance, 'samlCompletionPromise');
374
379
  global.window.open = jest.fn();
375
- jest.spyOn(authService, 'fetchSessionInfoService')
380
+ jest.spyOn(tokenAuthService, 'fetchSessionInfoService')
376
381
  .mockImplementationOnce(() => Promise.reject())
377
382
  .mockImplementationOnce(async () => ({
378
383
  json: () => mockSessionInfo,
@@ -389,7 +394,7 @@ describe('Unit test for auth', () => {
389
394
  document.getElementById('ts-auth-btn').click();
390
395
  window.postMessage({ type: EmbedEvent.SAMLComplete }, '*');
391
396
  await authInstance.samlCompletionPromise;
392
- expect(authService.fetchSessionInfoService).toBeCalled();
397
+ expect(tokenAuthService.fetchSessionInfoService).toBeCalled();
393
398
  expect(authInstance.getSessionDetails).toBeCalled();
394
399
  expect(authInstance.initSession).toBeCalled();
395
400
  });
@@ -405,9 +410,9 @@ describe('Unit test for auth', () => {
405
410
  });
406
411
 
407
412
  it('when user is not loggedIn & isAtSSORedirectUrl is true', async () => {
408
- jest.spyOn(authService, 'fetchSessionInfoService').mockImplementation(() => Promise.reject());
413
+ jest.spyOn(tokenAuthService, 'fetchSessionInfoService').mockImplementation(() => Promise.reject());
409
414
  await authInstance.doOIDCAuth(embedConfig.doOidcAuth);
410
- expect(authService.fetchSessionInfoService).toBeCalled();
415
+ expect(tokenAuthService.fetchSessionInfoService).toBeCalled();
411
416
  expect(window.location.hash).toBe('');
412
417
  expect(authInstance.loggedInStatus).toBe(false);
413
418
  });
package/src/auth.ts CHANGED
@@ -203,7 +203,6 @@ export const initSession = (sessionDetails: sessionInfoInterface) => {
203
203
  };
204
204
 
205
205
  export const getSessionDetails = (sessionInfoResp: any): sessionInfoInterface => {
206
- console.log('helloooo');
207
206
  const devMixpanelToken = sessionInfoResp.configInfo.mixpanelConfig.devSdkKey;
208
207
  const prodMixpanelToken = sessionInfoResp.configInfo.mixpanelConfig.prodSdkKey;
209
208
  const mixpanelToken = sessionInfoResp.configInfo.mixpanelConfig.production
@@ -319,14 +318,17 @@ export const doCookielessTokenAuth = async (embedConfig: EmbedConfig): Promise<b
319
318
  if (!authEndpoint && !getAuthToken) {
320
319
  throw new Error('Either auth endpoint or getAuthToken function must be provided');
321
320
  }
321
+ let authSuccess = false;
322
322
  try {
323
323
  const authToken = await getAuthenticationToken(embedConfig);
324
- if (authToken) return true;
324
+ if (authToken) {
325
+ authSuccess = true;
326
+ }
325
327
  } catch {
326
- // return false if getAuthenticationToken fails
328
+ authSuccess = false;
327
329
  }
328
330
 
329
- return false;
331
+ return authSuccess;
330
332
  };
331
333
 
332
334
  /**
package/src/authToken.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { EmbedConfig } from './types';
2
- import { fetchAuthTokenService, verifyTokenService } from './utils/authService';
2
+ import { fetchAuthTokenService, verifyTokenService } from './utils/authService/authService';
3
3
 
4
4
  const DUPLICATE_TOKEN_ERR = 'Duplicate token, please issue a new token every time getAuthToken callback is called.'
5
5
  + 'See https://developers.thoughtspot.com/docs/?pageid=embed-auth#trusted-auth-embed for more details.';
@@ -11,16 +11,14 @@ let cachedAuthToken: string | null = null;
11
11
  // This method can be used to get the authToken using the embedConfig
12
12
  export const getAuthenticationToken = async (embedConfig: EmbedConfig): Promise<string> => {
13
13
  if (cachedAuthToken) {
14
+ let isCachedTokenStillValid;
14
15
  try {
15
- const isCachedTokenStillValid = await validateAuthToken(
16
- embedConfig,
17
- cachedAuthToken,
18
- true,
19
- );
20
- if (isCachedTokenStillValid) return cachedAuthToken;
16
+ isCachedTokenStillValid = await validateAuthToken(embedConfig, cachedAuthToken, true);
21
17
  } catch {
22
- // Continue to get a new token if validation fails
18
+ isCachedTokenStillValid = false;
23
19
  }
20
+
21
+ if (isCachedTokenStillValid) return cachedAuthToken;
24
22
  }
25
23
 
26
24
  const { authEndpoint, getAuthToken } = embedConfig;
package/src/types.ts CHANGED
@@ -533,12 +533,14 @@ export interface EmbedConfig {
533
533
 
534
534
  /**
535
535
  * If passed as true all alerts will be suppressed in the embedded app.
536
+ *
537
+ * @version SDK: 1.26.1 | ThoughtSpot: *
536
538
  */
537
539
  suppressErrorAlerts?: boolean;
538
540
  }
539
541
 
540
542
  // eslint-disable-next-line @typescript-eslint/no-empty-interface
541
- export interface LayoutConfig { }
543
+ export interface LayoutConfig {}
542
544
 
543
545
  /**
544
546
  * Embedded iFrame configuration
@@ -3216,40 +3218,44 @@ export enum ContextMenuTriggerOptions {
3216
3218
 
3217
3219
  export interface ColumnValue {
3218
3220
  column: {
3219
- id: string,
3220
- name: string,
3221
- dataType: string,
3222
- [key: string]: any
3223
- },
3224
- value: string | number | boolean | {
3225
- v: {
3226
- s: number;
3227
- e: number;
3228
- }
3221
+ id: string;
3222
+ name: string;
3223
+ dataType: string;
3224
+ [key: string]: any;
3229
3225
  };
3226
+ value:
3227
+ | string
3228
+ | number
3229
+ | boolean
3230
+ | {
3231
+ v: {
3232
+ s: number;
3233
+ e: number;
3234
+ };
3235
+ };
3230
3236
  }
3231
3237
 
3232
3238
  export interface VizPoint {
3233
- selectedAttributes: ColumnValue[],
3234
- selectedMeasures: ColumnValue[]
3239
+ selectedAttributes: ColumnValue[];
3240
+ selectedMeasures: ColumnValue[];
3235
3241
  }
3236
3242
 
3237
3243
  export interface CustomActionPayload {
3238
3244
  contextMenuPoints?: {
3239
- clickedPoint: VizPoint
3240
- selectedPoints: VizPoint[]
3245
+ clickedPoint: VizPoint;
3246
+ selectedPoints: VizPoint[];
3241
3247
  };
3242
3248
  embedAnswerData: {
3243
- name: string,
3244
- id: string,
3249
+ name: string;
3250
+ id: string;
3245
3251
  sources: {
3246
3252
  header: {
3247
- guid: string
3248
- }
3249
- },
3250
- columns: any[],
3251
- data: any[],
3252
- [key: string]: any
3253
+ guid: string;
3254
+ };
3255
+ };
3256
+ columns: any[];
3257
+ data: any[];
3258
+ [key: string]: any;
3253
3259
  };
3254
3260
  session: SessionInterface;
3255
3261
  vizId?: string;
@@ -6,4 +6,4 @@ export {
6
6
  fetchBasicAuthService,
7
7
  verifyTokenService,
8
8
  } from './authService';
9
- export { fetchLogoutService, fetchSessionInfoService } from './tokenisedAuthSerice';
9
+ export { fetchLogoutService, fetchSessionInfoService } from './tokenizedAuthService';