@thoughtspot/visual-embed-sdk 1.26.1 → 1.26.3

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 (243) hide show
  1. package/cjs/package.json +2 -2
  2. package/cjs/src/auth.d.ts +0 -12
  3. package/cjs/src/auth.d.ts.map +1 -1
  4. package/cjs/src/auth.js +16 -54
  5. package/cjs/src/auth.js.map +1 -1
  6. package/cjs/src/auth.spec.d.ts.map +1 -1
  7. package/cjs/src/auth.spec.js +42 -32
  8. package/cjs/src/auth.spec.js.map +1 -1
  9. package/cjs/src/authToken.d.ts +4 -0
  10. package/cjs/src/authToken.d.ts.map +1 -0
  11. package/cjs/src/authToken.js +61 -0
  12. package/cjs/src/authToken.js.map +1 -0
  13. package/cjs/src/embed/app.d.ts +0 -1
  14. package/cjs/src/embed/app.d.ts.map +1 -1
  15. package/cjs/src/embed/app.js +1 -1
  16. package/cjs/src/embed/app.js.map +1 -1
  17. package/cjs/src/embed/base.d.ts +0 -9
  18. package/cjs/src/embed/base.d.ts.map +1 -1
  19. package/cjs/src/embed/base.js +21 -44
  20. package/cjs/src/embed/base.js.map +1 -1
  21. package/cjs/src/embed/base.spec.js +15 -14
  22. package/cjs/src/embed/base.spec.js.map +1 -1
  23. package/cjs/src/embed/embedConfig.d.ts +18 -0
  24. package/cjs/src/embed/embedConfig.d.ts.map +1 -0
  25. package/cjs/src/embed/embedConfig.js +25 -0
  26. package/cjs/src/embed/embedConfig.js.map +1 -0
  27. package/cjs/src/embed/liveboard.d.ts +0 -1
  28. package/cjs/src/embed/liveboard.d.ts.map +1 -1
  29. package/cjs/src/embed/liveboard.js +1 -1
  30. package/cjs/src/embed/liveboard.js.map +1 -1
  31. package/cjs/src/embed/sage.d.ts +0 -1
  32. package/cjs/src/embed/sage.d.ts.map +1 -1
  33. package/cjs/src/embed/sage.js +1 -1
  34. package/cjs/src/embed/sage.js.map +1 -1
  35. package/cjs/src/embed/search.d.ts +0 -1
  36. package/cjs/src/embed/search.d.ts.map +1 -1
  37. package/cjs/src/embed/search.js +5 -4
  38. package/cjs/src/embed/search.js.map +1 -1
  39. package/cjs/src/embed/searchEmbed-basic-auth.spec.js +3 -2
  40. package/cjs/src/embed/searchEmbed-basic-auth.spec.js.map +1 -1
  41. package/cjs/src/embed/ts-embed.d.ts +0 -1
  42. package/cjs/src/embed/ts-embed.d.ts.map +1 -1
  43. package/cjs/src/embed/ts-embed.js +6 -6
  44. package/cjs/src/embed/ts-embed.js.map +1 -1
  45. package/cjs/src/embed/ts-embed.spec.js +58 -49
  46. package/cjs/src/embed/ts-embed.spec.js.map +1 -1
  47. package/cjs/src/index.d.ts +2 -1
  48. package/cjs/src/index.d.ts.map +1 -1
  49. package/cjs/src/index.js +2 -1
  50. package/cjs/src/index.js.map +1 -1
  51. package/cjs/src/tokenizedFetch.d.ts +2 -0
  52. package/cjs/src/tokenizedFetch.d.ts.map +1 -0
  53. package/cjs/src/tokenizedFetch.js +20 -0
  54. package/cjs/src/tokenizedFetch.js.map +1 -0
  55. package/cjs/src/types.d.ts +12 -0
  56. package/cjs/src/types.d.ts.map +1 -1
  57. package/cjs/src/types.js.map +1 -1
  58. package/cjs/src/utils/{authService.d.ts → authService/authService.d.ts} +12 -11
  59. package/cjs/src/utils/authService/authService.d.ts.map +1 -0
  60. package/cjs/src/utils/{authService.js → authService/authService.js} +31 -39
  61. package/cjs/src/utils/authService/authService.js.map +1 -0
  62. package/cjs/src/utils/authService/authService.spec.d.ts.map +1 -0
  63. package/cjs/src/utils/{authService.spec.js → authService/authService.spec.js} +11 -12
  64. package/cjs/src/utils/authService/authService.spec.js.map +1 -0
  65. package/cjs/src/utils/authService/index.d.ts +3 -0
  66. package/cjs/src/utils/authService/index.d.ts.map +1 -0
  67. package/cjs/src/utils/authService/index.js +14 -0
  68. package/cjs/src/utils/authService/index.js.map +1 -0
  69. package/cjs/src/utils/authService/tokenizedAuthService.d.ts +11 -0
  70. package/cjs/src/utils/authService/tokenizedAuthService.d.ts.map +1 -0
  71. package/cjs/src/utils/authService/tokenizedAuthService.js +44 -0
  72. package/cjs/src/utils/authService/tokenizedAuthService.js.map +1 -0
  73. package/cjs/src/utils/graphql/answerService/answerService.d.ts.map +1 -1
  74. package/cjs/src/utils/graphql/answerService/answerService.js +2 -1
  75. package/cjs/src/utils/graphql/answerService/answerService.js.map +1 -1
  76. package/cjs/src/utils/graphql/answerService/answerService.spec.js +15 -3
  77. package/cjs/src/utils/graphql/answerService/answerService.spec.js.map +1 -1
  78. package/cjs/src/utils/processData.d.ts.map +1 -1
  79. package/cjs/src/utils/processData.js +5 -4
  80. package/cjs/src/utils/processData.js.map +1 -1
  81. package/cjs/src/utils/processData.spec.js +8 -7
  82. package/cjs/src/utils/processData.spec.js.map +1 -1
  83. package/dist/src/auth.d.ts +0 -12
  84. package/dist/src/auth.d.ts.map +1 -1
  85. package/dist/src/auth.spec.d.ts.map +1 -1
  86. package/dist/src/authToken.d.ts +4 -0
  87. package/dist/src/authToken.d.ts.map +1 -0
  88. package/dist/src/embed/app.d.ts +0 -1
  89. package/dist/src/embed/app.d.ts.map +1 -1
  90. package/dist/src/embed/base.d.ts +0 -9
  91. package/dist/src/embed/base.d.ts.map +1 -1
  92. package/dist/src/embed/embedConfig.d.ts +18 -0
  93. package/dist/src/embed/embedConfig.d.ts.map +1 -0
  94. package/dist/src/embed/liveboard.d.ts +0 -1
  95. package/dist/src/embed/liveboard.d.ts.map +1 -1
  96. package/dist/src/embed/sage.d.ts +0 -1
  97. package/dist/src/embed/sage.d.ts.map +1 -1
  98. package/dist/src/embed/search.d.ts +0 -1
  99. package/dist/src/embed/search.d.ts.map +1 -1
  100. package/dist/src/embed/ts-embed.d.ts +0 -1
  101. package/dist/src/embed/ts-embed.d.ts.map +1 -1
  102. package/dist/src/index.d.ts +2 -1
  103. package/dist/src/index.d.ts.map +1 -1
  104. package/dist/src/tokenizedFetch.d.ts +2 -0
  105. package/dist/src/tokenizedFetch.d.ts.map +1 -0
  106. package/dist/src/types.d.ts +12 -0
  107. package/dist/src/types.d.ts.map +1 -1
  108. package/{lib/src/utils → dist/src/utils/authService}/authService.d.ts +44 -43
  109. package/dist/src/utils/authService/authService.d.ts.map +1 -0
  110. package/dist/src/utils/authService/index.d.ts +3 -0
  111. package/dist/src/utils/authService/index.d.ts.map +1 -0
  112. package/dist/src/utils/authService/tokenizedAuthService.d.ts +11 -0
  113. package/dist/src/utils/authService/tokenizedAuthService.d.ts.map +1 -0
  114. package/dist/src/utils/graphql/answerService/answerService.d.ts.map +1 -1
  115. package/dist/src/utils/processData.d.ts.map +1 -1
  116. package/dist/tsembed-react.es.js +207 -149
  117. package/dist/tsembed-react.js +207 -149
  118. package/dist/tsembed.es.js +236 -180
  119. package/dist/tsembed.js +236 -180
  120. package/dist/visual-embed-sdk-react-full.d.ts +29 -26
  121. package/dist/visual-embed-sdk-react.d.ts +29 -26
  122. package/dist/visual-embed-sdk.d.ts +29 -26
  123. package/lib/package.json +2 -2
  124. package/lib/src/auth.d.ts +0 -12
  125. package/lib/src/auth.d.ts.map +1 -1
  126. package/lib/src/auth.js +11 -48
  127. package/lib/src/auth.js.map +1 -1
  128. package/lib/src/auth.spec.d.ts.map +1 -1
  129. package/lib/src/auth.spec.js +42 -32
  130. package/lib/src/auth.spec.js.map +1 -1
  131. package/lib/src/authToken.d.ts +4 -0
  132. package/lib/src/authToken.d.ts.map +1 -0
  133. package/lib/src/authToken.js +56 -0
  134. package/lib/src/authToken.js.map +1 -0
  135. package/lib/src/embed/app.d.ts +0 -1
  136. package/lib/src/embed/app.d.ts.map +1 -1
  137. package/lib/src/embed/app.js +1 -1
  138. package/lib/src/embed/app.js.map +1 -1
  139. package/lib/src/embed/base.d.ts +0 -9
  140. package/lib/src/embed/base.d.ts.map +1 -1
  141. package/lib/src/embed/base.js +21 -43
  142. package/lib/src/embed/base.js.map +1 -1
  143. package/lib/src/embed/base.spec.js +15 -14
  144. package/lib/src/embed/base.spec.js.map +1 -1
  145. package/lib/src/embed/embedConfig.d.ts +18 -0
  146. package/lib/src/embed/embedConfig.d.ts.map +1 -0
  147. package/lib/src/embed/embedConfig.js +20 -0
  148. package/lib/src/embed/embedConfig.js.map +1 -0
  149. package/lib/src/embed/liveboard.d.ts +0 -1
  150. package/lib/src/embed/liveboard.d.ts.map +1 -1
  151. package/lib/src/embed/liveboard.js +1 -1
  152. package/lib/src/embed/liveboard.js.map +1 -1
  153. package/lib/src/embed/sage.d.ts +0 -1
  154. package/lib/src/embed/sage.d.ts.map +1 -1
  155. package/lib/src/embed/sage.js +1 -1
  156. package/lib/src/embed/sage.js.map +1 -1
  157. package/lib/src/embed/search.d.ts +0 -1
  158. package/lib/src/embed/search.d.ts.map +1 -1
  159. package/lib/src/embed/search.js +6 -5
  160. package/lib/src/embed/search.js.map +1 -1
  161. package/lib/src/embed/searchEmbed-basic-auth.spec.js +3 -2
  162. package/lib/src/embed/searchEmbed-basic-auth.spec.js.map +1 -1
  163. package/lib/src/embed/ts-embed.d.ts +0 -1
  164. package/lib/src/embed/ts-embed.d.ts.map +1 -1
  165. package/lib/src/embed/ts-embed.js +5 -5
  166. package/lib/src/embed/ts-embed.js.map +1 -1
  167. package/lib/src/embed/ts-embed.spec.js +58 -49
  168. package/lib/src/embed/ts-embed.spec.js.map +1 -1
  169. package/lib/src/index.d.ts +2 -1
  170. package/lib/src/index.d.ts.map +1 -1
  171. package/lib/src/index.js +2 -1
  172. package/lib/src/index.js.map +1 -1
  173. package/lib/src/tokenizedFetch.d.ts +2 -0
  174. package/lib/src/tokenizedFetch.d.ts.map +1 -0
  175. package/lib/src/tokenizedFetch.js +16 -0
  176. package/lib/src/tokenizedFetch.js.map +1 -0
  177. package/lib/src/types.d.ts +12 -0
  178. package/lib/src/types.d.ts.map +1 -1
  179. package/lib/src/types.js.map +1 -1
  180. package/{dist/src/utils → lib/src/utils/authService}/authService.d.ts +44 -43
  181. package/lib/src/utils/authService/authService.d.ts.map +1 -0
  182. package/lib/src/utils/{authService.js → authService/authService.js} +26 -32
  183. package/lib/src/utils/authService/authService.js.map +1 -0
  184. package/lib/src/utils/authService/authService.spec.d.ts.map +1 -0
  185. package/lib/src/utils/{authService.spec.js → authService/authService.spec.js} +1 -2
  186. package/lib/src/utils/authService/authService.spec.js.map +1 -0
  187. package/lib/src/utils/authService/index.d.ts +3 -0
  188. package/lib/src/utils/authService/index.d.ts.map +1 -0
  189. package/lib/src/utils/authService/index.js +3 -0
  190. package/lib/src/utils/authService/index.js.map +1 -0
  191. package/lib/src/utils/authService/tokenizedAuthService.d.ts +11 -0
  192. package/lib/src/utils/authService/tokenizedAuthService.d.ts.map +1 -0
  193. package/lib/src/utils/authService/tokenizedAuthService.js +39 -0
  194. package/lib/src/utils/authService/tokenizedAuthService.js.map +1 -0
  195. package/lib/src/utils/graphql/answerService/answerService.d.ts.map +1 -1
  196. package/lib/src/utils/graphql/answerService/answerService.js +2 -1
  197. package/lib/src/utils/graphql/answerService/answerService.js.map +1 -1
  198. package/lib/src/utils/graphql/answerService/answerService.spec.js +14 -3
  199. package/lib/src/utils/graphql/answerService/answerService.spec.js.map +1 -1
  200. package/lib/src/utils/processData.d.ts.map +1 -1
  201. package/lib/src/utils/processData.js +4 -3
  202. package/lib/src/utils/processData.js.map +1 -1
  203. package/lib/src/utils/processData.spec.js +8 -7
  204. package/lib/src/utils/processData.spec.js.map +1 -1
  205. package/lib/src/visual-embed-sdk.d.ts +34 -27
  206. package/package.json +2 -2
  207. package/src/auth.spec.ts +77 -63
  208. package/src/auth.ts +12 -55
  209. package/src/authToken.ts +66 -0
  210. package/src/embed/app.ts +1 -2
  211. package/src/embed/base.spec.ts +18 -17
  212. package/src/embed/base.ts +26 -51
  213. package/src/embed/embedConfig.ts +23 -0
  214. package/src/embed/liveboard.ts +1 -2
  215. package/src/embed/sage.ts +1 -2
  216. package/src/embed/search.ts +12 -14
  217. package/src/embed/searchEmbed-basic-auth.spec.ts +3 -2
  218. package/src/embed/ts-embed.spec.ts +87 -75
  219. package/src/embed/ts-embed.ts +7 -19
  220. package/src/index.ts +8 -2
  221. package/src/tokenizedFetch.ts +18 -0
  222. package/src/types.ts +36 -19
  223. package/src/utils/{authService.spec.ts → authService/authService.spec.ts} +2 -3
  224. package/src/utils/{authService.ts → authService/authService.ts} +29 -34
  225. package/src/utils/authService/index.ts +9 -0
  226. package/src/utils/authService/tokenizedAuthService.ts +40 -0
  227. package/src/utils/graphql/answerService/answerService.spec.ts +16 -4
  228. package/src/utils/graphql/answerService/answerService.ts +2 -1
  229. package/src/utils/processData.spec.ts +19 -16
  230. package/src/utils/processData.ts +3 -2
  231. package/cjs/src/utils/authService.d.ts.map +0 -1
  232. package/cjs/src/utils/authService.js.map +0 -1
  233. package/cjs/src/utils/authService.spec.d.ts.map +0 -1
  234. package/cjs/src/utils/authService.spec.js.map +0 -1
  235. package/dist/src/utils/authService.d.ts.map +0 -1
  236. package/lib/src/utils/authService.d.ts.map +0 -1
  237. package/lib/src/utils/authService.js.map +0 -1
  238. package/lib/src/utils/authService.spec.d.ts.map +0 -1
  239. package/lib/src/utils/authService.spec.js.map +0 -1
  240. /package/cjs/src/utils/{authService.spec.d.ts → authService/authService.spec.d.ts} +0 -0
  241. /package/dist/src/utils/{authService.spec.d.ts → authService/authService.spec.d.ts} +0 -0
  242. /package/dist/src/utils/{authService.spec.d.ts.map → authService/authService.spec.d.ts.map} +0 -0
  243. /package/lib/src/utils/{authService.spec.d.ts → authService/authService.spec.d.ts} +0 -0
@@ -1,4 +1,5 @@
1
1
  /* eslint-disable dot-notation */
2
+ import { resetCachedAuthToken } from '../authToken';
2
3
  import {
3
4
  AuthType,
4
5
  init,
@@ -10,11 +11,7 @@ import {
10
11
  LiveboardEmbed,
11
12
  } from '../index';
12
13
  import {
13
- Action,
14
- HomeLeftNavItem,
15
- RuntimeFilter,
16
- RuntimeFilterOp,
17
- HomepageModule,
14
+ Action, HomeLeftNavItem, RuntimeFilter, RuntimeFilterOp, HomepageModule,
18
15
  } from '../types';
19
16
  import {
20
17
  executeAfterWait,
@@ -34,6 +31,7 @@ import * as mixpanelInstance from '../mixpanel-service';
34
31
  import * as authInstance from '../auth';
35
32
  import * as baseInstance from './base';
36
33
  import { MIXPANEL_EVENT } from '../mixpanel-service';
34
+ import * as authService from '../utils/authService/authService';
37
35
 
38
36
  const defaultViewConfig = {
39
37
  frameParams: {
@@ -89,8 +87,51 @@ describe('Unit test case for ts embed', () => {
89
87
 
90
88
  afterEach(() => {
91
89
  jest.clearAllMocks();
90
+ resetCachedAuthToken();
92
91
  });
93
92
 
93
+ describe('AuthExpire embedEvent in cookieless authentication authType', () => {
94
+ beforeAll(() => {
95
+ jest.spyOn(authInstance, 'doCookielessTokenAuth').mockResolvedValueOnce(true);
96
+ jest.spyOn(authService, 'verifyTokenService').mockResolvedValueOnce(true);
97
+ init({
98
+ thoughtSpotHost: 'tshost',
99
+ customizations: customisations,
100
+ customCssUrl: 'http://localhost:5000',
101
+ authType: AuthType.TrustedAuthTokenCookieless,
102
+ getAuthToken: () => Promise.resolve('test_auth_token2'),
103
+ });
104
+ });
105
+
106
+ test('check for new authToken based on getAuthToken function', async () => {
107
+ const mockEmbedEventPayload = {
108
+ type: EmbedEvent.AuthExpire,
109
+ data: {},
110
+ };
111
+ const searchEmbed = new SearchEmbed(getRootEl(), defaultViewConfig);
112
+ jest.spyOn(baseInstance, 'notifyAuthFailure');
113
+ jest.spyOn(baseInstance, 'handleAuth');
114
+
115
+ searchEmbed.render();
116
+ const mockPort: any = {
117
+ postMessage: jest.fn(),
118
+ };
119
+ await executeAfterWait(() => {
120
+ const iframe = getIFrameEl();
121
+ postMessageToParent(iframe.contentWindow, mockEmbedEventPayload, mockPort);
122
+ });
123
+ await executeAfterWait(() => {
124
+ expect(baseInstance.notifyAuthFailure).toBeCalledWith(
125
+ authInstance.AuthFailureType.EXPIRY,
126
+ );
127
+ expect(baseInstance.handleAuth).not.toHaveBeenCalled();
128
+ expect(mockPort.postMessage).toHaveBeenCalledWith({
129
+ type: EmbedEvent.AuthExpire,
130
+ data: { authToken: 'test_auth_token2' },
131
+ });
132
+ });
133
+ });
134
+ });
94
135
  describe('Called Embed event status for start and end', () => {
95
136
  beforeAll(() => {
96
137
  init({
@@ -193,8 +234,7 @@ describe('Unit test case for ts embed', () => {
193
234
  hostConfig: undefined,
194
235
  runtimeFilterParams: null,
195
236
  hiddenHomeLeftNavItems: [],
196
- hiddenHomepageModules: [HomepageModule.MyLibrary,
197
- HomepageModule.Learning],
237
+ hiddenHomepageModules: [HomepageModule.MyLibrary, HomepageModule.Learning],
198
238
  reorderedHomepageModules: [],
199
239
  },
200
240
  });
@@ -231,8 +271,7 @@ describe('Unit test case for ts embed', () => {
231
271
  runtimeFilterParams: null,
232
272
  hiddenHomeLeftNavItems: [],
233
273
  hiddenHomepageModules: [],
234
- reorderedHomepageModules: [HomepageModule.MyLibrary,
235
- HomepageModule.Watchlist],
274
+ reorderedHomepageModules: [HomepageModule.MyLibrary, HomepageModule.Watchlist],
236
275
  },
237
276
  });
238
277
  });
@@ -346,8 +385,7 @@ describe('Unit test case for ts embed', () => {
346
385
  authToken: '',
347
386
  hostConfig: undefined,
348
387
  runtimeFilterParams: null,
349
- hiddenHomeLeftNavItems: [HomeLeftNavItem.Home,
350
- HomeLeftNavItem.Documentation],
388
+ hiddenHomeLeftNavItems: [HomeLeftNavItem.Home, HomeLeftNavItem.Documentation],
351
389
  hiddenHomepageModules: [],
352
390
  reorderedHomepageModules: [],
353
391
  },
@@ -483,7 +521,15 @@ describe('Unit test case for ts embed', () => {
483
521
  });
484
522
  });
485
523
 
524
+ afterEach(() => {
525
+ baseInstance.reset();
526
+ });
527
+
486
528
  test('check for authToken based on getAuthToken function', async () => {
529
+ const a = jest.spyOn(authService, 'verifyTokenService');
530
+ a.mockResolvedValue(true);
531
+
532
+ // authVerifyMock.mockResolvedValue(true);
487
533
  const mockEmbedEventPayload = {
488
534
  type: EmbedEvent.APP_INIT,
489
535
  data: {},
@@ -511,47 +557,8 @@ describe('Unit test case for ts embed', () => {
511
557
  },
512
558
  });
513
559
  });
514
- });
515
- });
516
560
 
517
- describe('AuthExpire embedEvent in cookieless authentication authType', () => {
518
- beforeAll(() => {
519
- jest.spyOn(authInstance, 'doCookielessTokenAuth').mockResolvedValueOnce(true);
520
- init({
521
- thoughtSpotHost: 'tshost',
522
- customizations: customisations,
523
- customCssUrl: 'http://localhost:5000',
524
- authType: AuthType.TrustedAuthTokenCookieless,
525
- getAuthToken: () => Promise.resolve('test_auth_token2'),
526
- });
527
- });
528
-
529
- test('check for new authToken based on getAuthToken function', async () => {
530
- const mockEmbedEventPayload = {
531
- type: EmbedEvent.AuthExpire,
532
- data: {},
533
- };
534
- const searchEmbed = new SearchEmbed(getRootEl(), defaultViewConfig);
535
- jest.spyOn(baseInstance, 'notifyAuthFailure');
536
- jest.spyOn(baseInstance, 'handleAuth');
537
- searchEmbed.render();
538
- const mockPort: any = {
539
- postMessage: jest.fn(),
540
- };
541
- await executeAfterWait(() => {
542
- const iframe = getIFrameEl();
543
- postMessageToParent(iframe.contentWindow, mockEmbedEventPayload, mockPort);
544
- });
545
- await executeAfterWait(() => {
546
- expect(baseInstance.notifyAuthFailure).toBeCalledWith(
547
- authInstance.AuthFailureType.EXPIRY,
548
- );
549
- expect(baseInstance.handleAuth).not.toHaveBeenCalled();
550
- expect(mockPort.postMessage).toHaveBeenCalledWith({
551
- type: EmbedEvent.AuthExpire,
552
- data: { authToken: 'test_auth_token2' },
553
- });
554
- });
561
+ jest.spyOn(authService, 'verifyTokenService').mockClear();
555
562
  });
556
563
  });
557
564
 
@@ -1036,7 +1043,7 @@ describe('Unit test case for ts embed', () => {
1036
1043
  expectUrlMatchesWithParams(
1037
1044
  getIFrameSrc(),
1038
1045
  `http://${thoughtSpotHost}/?embedApp=true&primaryNavHidden=true&profileAndHelpInNavBarHidden=false&${defaultParamsForPinboardEmbed}`
1039
- + `&foo=bar&baz=1&bool=true${defaultParamsPost}#/home`,
1046
+ + `&foo=bar&baz=1&bool=true${defaultParamsPost}#/home`,
1040
1047
  );
1041
1048
  });
1042
1049
 
@@ -1052,7 +1059,7 @@ describe('Unit test case for ts embed', () => {
1052
1059
  expectUrlMatchesWithParams(
1053
1060
  getIFrameSrc(),
1054
1061
  `http://${thoughtSpotHost}/?embedApp=true&primaryNavHidden=true&profileAndHelpInNavBarHidden=false&${defaultParamsForPinboardEmbed}`
1055
- + `&showAlerts=true${defaultParamsPost}#/home`,
1062
+ + `&showAlerts=true${defaultParamsPost}#/home`,
1056
1063
  );
1057
1064
  });
1058
1065
  it('Sets the locale param', async () => {
@@ -1067,7 +1074,7 @@ describe('Unit test case for ts embed', () => {
1067
1074
  expectUrlMatchesWithParams(
1068
1075
  getIFrameSrc(),
1069
1076
  `http://${thoughtSpotHost}/?embedApp=true&primaryNavHidden=true&profileAndHelpInNavBarHidden=false&${defaultParamsForPinboardEmbed}`
1070
- + `&locale=ja-JP${defaultParamsPost}#/home`,
1077
+ + `&locale=ja-JP${defaultParamsPost}#/home`,
1071
1078
  );
1072
1079
  });
1073
1080
  it('Sets the iconSprite url', async () => {
@@ -1084,7 +1091,7 @@ describe('Unit test case for ts embed', () => {
1084
1091
  expectUrlMatchesWithParams(
1085
1092
  getIFrameSrc(),
1086
1093
  `http://${thoughtSpotHost}/?embedApp=true&primaryNavHidden=true&profileAndHelpInNavBarHidden=false&${defaultParamsForPinboardEmbed}`
1087
- + `&iconSprite=iconSprite.com${defaultParamsPost}#/home`,
1094
+ + `&iconSprite=iconSprite.com${defaultParamsPost}#/home`,
1088
1095
  );
1089
1096
  });
1090
1097
 
@@ -1302,8 +1309,7 @@ describe('Unit test case for ts embed', () => {
1302
1309
  expect(preRenderWrapper.style.pointerEvents).toBe('none');
1303
1310
  expect(preRenderWrapper.style.zIndex).toBe('-1000');
1304
1311
 
1305
- const preRenderChild = (document
1306
- .getElementById(preRenderIds.child) as HTMLIFrameElement);
1312
+ const preRenderChild = document.getElementById(preRenderIds.child) as HTMLIFrameElement;
1307
1313
  expect(preRenderWrapper.children[0]).toEqual(preRenderChild);
1308
1314
  expect(preRenderChild).toBeInstanceOf(HTMLIFrameElement);
1309
1315
  expect(preRenderChild.src).toMatch(/^http:\/\/tshost.*\/myLiveboardId/);
@@ -1314,24 +1320,26 @@ describe('Unit test case for ts embed', () => {
1314
1320
 
1315
1321
  let resizeObserverCb: any;
1316
1322
  (window as any).ResizeObserver = window.ResizeObserver
1317
- || jest.fn().mockImplementation((resizeObserverCbParam) => {
1318
- resizeObserverCb = resizeObserverCbParam;
1319
- return ({
1320
- disconnect: jest.fn(),
1321
- observe: jest.fn(),
1322
- unobserve: jest.fn(),
1323
+ || jest.fn().mockImplementation((resizeObserverCbParam) => {
1324
+ resizeObserverCb = resizeObserverCbParam;
1325
+ return {
1326
+ disconnect: jest.fn(),
1327
+ observe: jest.fn(),
1328
+ unobserve: jest.fn(),
1329
+ };
1323
1330
  });
1324
- });
1325
1331
 
1326
1332
  // show preRender
1327
1333
  const warnSpy = spyOn(console, 'warn');
1328
1334
  libEmbed.showPreRender();
1329
1335
  expect(warnSpy).toHaveBeenCalledTimes(0);
1330
1336
 
1331
- resizeObserverCb([{
1332
- target: tsEmbedDiv,
1333
- contentRect: { height: 297, width: 987 },
1334
- }]);
1337
+ resizeObserverCb([
1338
+ {
1339
+ target: tsEmbedDiv,
1340
+ contentRect: { height: 297, width: 987 },
1341
+ },
1342
+ ]);
1335
1343
 
1336
1344
  expect(preRenderWrapper.style.height).toEqual(`${297}px`);
1337
1345
  expect(preRenderWrapper.style.width).toEqual(`${987}px`);
@@ -1394,11 +1402,11 @@ describe('Unit test case for ts embed', () => {
1394
1402
  createRootEleForEmbed();
1395
1403
  mockMessageChannel();
1396
1404
  (window as any).ResizeObserver = window.ResizeObserver
1397
- || jest.fn().mockImplementation(() => ({
1398
- disconnect: jest.fn(),
1399
- observe: jest.fn(),
1400
- unobserve: jest.fn(),
1401
- }));
1405
+ || jest.fn().mockImplementation(() => ({
1406
+ disconnect: jest.fn(),
1407
+ observe: jest.fn(),
1408
+ unobserve: jest.fn(),
1409
+ }));
1402
1410
  const libEmbed = new LiveboardEmbed('#tsEmbedDiv', {
1403
1411
  preRenderId: 'i-am-preRendered',
1404
1412
  liveboardId: 'myLiveboardId',
@@ -1451,7 +1459,9 @@ describe('Unit test case for ts embed', () => {
1451
1459
  });
1452
1460
  await libEmbed.preRender();
1453
1461
 
1454
- expect(document.getElementById('tsEmbed-pre-render-child-test').innerHTML).toBe('Not logged in');
1462
+ expect(document.getElementById('tsEmbed-pre-render-child-test').innerHTML).toBe(
1463
+ 'Not logged in',
1464
+ );
1455
1465
  });
1456
1466
  it('should log error if sync is called before preRender', async () => {
1457
1467
  jest.spyOn(console, 'error').mockImplementation(jest.fn());
@@ -1460,7 +1470,9 @@ describe('Unit test case for ts embed', () => {
1460
1470
  preRenderId: 'test',
1461
1471
  });
1462
1472
  await libEmbed.syncPreRenderStyle();
1463
- expect(console.error).toBeCalledWith('PreRender should be called before using syncPreRenderStyle');
1473
+ expect(console.error).toBeCalledWith(
1474
+ 'PreRender should be called before using syncPreRenderStyle',
1475
+ );
1464
1476
  (console.error as any).mockClear();
1465
1477
  });
1466
1478
  });
@@ -9,6 +9,7 @@
9
9
 
10
10
  import isEqual from 'lodash/isEqual';
11
11
 
12
+ import { getAuthenticationToken } from '../authToken';
12
13
  import { AnswerService } from '../utils/graphql/answerService/answerService';
13
14
  import {
14
15
  getEncodedQueryParamsString,
@@ -55,13 +56,10 @@ import { processEventData } from '../utils/processData';
55
56
  import { processTrigger } from '../utils/processTrigger';
56
57
  import pkgInfo from '../../package.json';
57
58
  import {
58
- getAuthPromise,
59
- getEmbedConfig,
60
- renderInQueue,
61
- handleAuth,
62
- notifyAuthFailure,
59
+ getAuthPromise, renderInQueue, handleAuth, notifyAuthFailure,
63
60
  } from './base';
64
- import { AuthFailureType, getAuthenticationToken } from '../auth';
61
+ import { AuthFailureType } from '../auth';
62
+ import { getEmbedConfig } from './embedConfig';
65
63
 
66
64
  const { version } = pkgInfo;
67
65
 
@@ -126,8 +124,6 @@ export class TsEmbed {
126
124
  */
127
125
  protected thoughtSpotV2Base: string;
128
126
 
129
- protected embedComponentType = 'TsEmbed';
130
-
131
127
  /**
132
128
  * A map of event handlers for particular message types triggered
133
129
  * by the embedded app; multiple event handlers can be registered
@@ -179,7 +175,6 @@ export class TsEmbed {
179
175
  this.registerAppInit();
180
176
  uploadMixpanelEvent(MIXPANEL_EVENT.VISUAL_SDK_EMBED_CREATE, {
181
177
  ...viewConfig,
182
- embedComponentType: this.embedComponentType,
183
178
  });
184
179
  }
185
180
 
@@ -1072,7 +1067,7 @@ export class TsEmbed {
1072
1067
  && !isEqual(viewConfig[key], preRenderedObject.viewConfig[key])
1073
1068
  ) {
1074
1069
  console.warn(
1075
- `${this.embedComponentType} was pre-rendered with `
1070
+ 'TS Embed component was pre-rendered with '
1076
1071
  + `"${key}" as "${JSON.stringify(preRenderedObject.viewConfig[key])}" `
1077
1072
  + `but a different value "${JSON.stringify(viewConfig[key])}" `
1078
1073
  + 'was passed to the Embed component. '
@@ -1204,15 +1199,8 @@ export class TsEmbed {
1204
1199
  * @version SDK: 1.25.0 / ThoughtSpot 9.10.0
1205
1200
  */
1206
1201
  public async getAnswerService(vizId?: string): Promise<AnswerService> {
1207
- const { session, embedAnswerData } = await this.trigger(
1208
- HostEvent.GetAnswerSession,
1209
- vizId,
1210
- );
1211
- return new AnswerService(
1212
- session,
1213
- embedAnswerData,
1214
- this.embedConfig.thoughtSpotHost,
1215
- );
1202
+ const { session, embedAnswerData } = await this.trigger(HostEvent.GetAnswerSession, vizId);
1203
+ return new AnswerService(session, embedAnswerData, this.embedConfig.thoughtSpotHost);
1216
1204
  }
1217
1205
  }
1218
1206
 
package/src/index.ts CHANGED
@@ -9,8 +9,13 @@
9
9
  */
10
10
  import { AppEmbed, Page, AppViewConfig } from './embed/app';
11
11
  import {
12
- init, prefetch, logout, getEmbedConfig, executeTML, exportTML,
13
- executeTMLInput, exportTMLInput,
12
+ init,
13
+ prefetch,
14
+ logout,
15
+ executeTML,
16
+ exportTML,
17
+ executeTMLInput,
18
+ exportTMLInput,
14
19
  } from './embed/base';
15
20
  import { PinboardEmbed, LiveboardViewConfig, LiveboardEmbed } from './embed/liveboard';
16
21
  import { SearchEmbed, SearchViewConfig } from './embed/search';
@@ -44,6 +49,7 @@ import {
44
49
  import { CustomCssVariables } from './css-variables';
45
50
  import { SageEmbed, SageViewConfig } from './embed/sage';
46
51
  import { AnswerService } from './utils/graphql/answerService/answerService';
52
+ import { getEmbedConfig } from './embed/embedConfig';
47
53
 
48
54
  export {
49
55
  init,
@@ -0,0 +1,18 @@
1
+ import { getAuthenticationToken } from './authToken';
2
+ import { getEmbedConfig } from './embed/embedConfig';
3
+
4
+ import { AuthType } from './types';
5
+
6
+ export const tokenizedFetch: typeof fetch = async (input, init): Promise<Response> => {
7
+ const embedConfig = getEmbedConfig();
8
+ if (embedConfig.authType !== AuthType.TrustedAuthTokenCookieless) {
9
+ return fetch(input, init);
10
+ }
11
+
12
+ const req = new Request(input, init);
13
+ const authToken = await getAuthenticationToken(embedConfig);
14
+ if (authToken) {
15
+ req.headers.append('Authorization', `Bearer ${authToken}`);
16
+ }
17
+ return fetch(req);
18
+ };
package/src/types.ts CHANGED
@@ -531,6 +531,13 @@ export interface EmbedConfig {
531
531
  * @version SDK: 1.27.0 | ThoughtSpot: 9.8.0.cl
532
532
  */
533
533
  pendoTrackingKey?: string;
534
+
535
+ /**
536
+ * If passed as true all alerts will be suppressed in the embedded app.
537
+ *
538
+ * @version SDK: 1.26.2 | ThoughtSpot: *
539
+ */
540
+ suppressErrorAlerts?: boolean;
534
541
  }
535
542
 
536
543
  // eslint-disable-next-line @typescript-eslint/no-empty-interface
@@ -810,6 +817,12 @@ export interface ViewConfig {
810
817
  * const myComponent = new MyComponent(config);
811
818
  */
812
819
  doNotTrackPreRenderSize?: boolean;
820
+ /**
821
+ * For internal tracking of the embed component type.
822
+ *
823
+ * @hidden
824
+ */
825
+ embedComponentType?: string;
813
826
  }
814
827
 
815
828
  /**
@@ -3212,40 +3225,44 @@ export enum ContextMenuTriggerOptions {
3212
3225
 
3213
3226
  export interface ColumnValue {
3214
3227
  column: {
3215
- id: string,
3216
- name: string,
3217
- dataType: string,
3218
- [key: string]: any
3219
- },
3220
- value: string | number | boolean | {
3228
+ id: string;
3229
+ name: string;
3230
+ dataType: string;
3231
+ [key: string]: any;
3232
+ };
3233
+ value:
3234
+ | string
3235
+ | number
3236
+ | boolean
3237
+ | {
3221
3238
  v: {
3222
3239
  s: number;
3223
3240
  e: number;
3224
- }
3241
+ };
3225
3242
  };
3226
3243
  }
3227
3244
 
3228
3245
  export interface VizPoint {
3229
- selectedAttributes: ColumnValue[],
3230
- selectedMeasures: ColumnValue[]
3246
+ selectedAttributes: ColumnValue[];
3247
+ selectedMeasures: ColumnValue[];
3231
3248
  }
3232
3249
 
3233
3250
  export interface CustomActionPayload {
3234
3251
  contextMenuPoints?: {
3235
- clickedPoint: VizPoint
3236
- selectedPoints: VizPoint[]
3252
+ clickedPoint: VizPoint;
3253
+ selectedPoints: VizPoint[];
3237
3254
  };
3238
3255
  embedAnswerData: {
3239
- name: string,
3240
- id: string,
3256
+ name: string;
3257
+ id: string;
3241
3258
  sources: {
3242
3259
  header: {
3243
- guid: string
3244
- }
3245
- },
3246
- columns: any[],
3247
- data: any[],
3248
- [key: string]: any
3260
+ guid: string;
3261
+ };
3262
+ };
3263
+ columns: any[];
3264
+ data: any[];
3265
+ [key: string]: any;
3249
3266
  };
3250
3267
  session: SessionInterface;
3251
3268
  vizId?: string;
@@ -1,4 +1,3 @@
1
- import { embedConfig } from 'src/auth.spec';
2
1
  import {
3
2
  fetchSessionInfoService,
4
3
  fetchAuthTokenService,
@@ -6,8 +5,8 @@ import {
6
5
  fetchBasicAuthService,
7
6
  fetchAuthPostService,
8
7
  verifyTokenService,
9
- } from './authService';
10
- import { EndPoints } from '../auth';
8
+ EndPoints,
9
+ } from '.';
11
10
 
12
11
  const thoughtSpotHost = 'http://10.79.135.124:3000';
13
12
 
@@ -1,5 +1,14 @@
1
- // eslint-disable-next-line import/no-cycle
2
- import { EndPoints } from '../auth';
1
+ export const EndPoints = {
2
+ AUTH_VERIFICATION: '/callosum/v1/session/info',
3
+ SAML_LOGIN_TEMPLATE: (targetUrl: string) => `/callosum/v1/saml/login?targetURLPath=${targetUrl}`,
4
+ OIDC_LOGIN_TEMPLATE: (targetUrl: string) => `/callosum/v1/oidc/login?targetURLPath=${targetUrl}`,
5
+ TOKEN_LOGIN: '/callosum/v1/session/login/token',
6
+ BASIC_LOGIN: '/callosum/v1/session/login',
7
+ LOGOUT: '/callosum/v1/session/logout',
8
+ EXECUTE_TML: '/api/rest/2.0/metadata/tml/import',
9
+ EXPORT_TML: '/api/rest/2.0/metadata/tml/export',
10
+ IS_ACTIVE: '/callosum/v1/session/isactive',
11
+ };
3
12
 
4
13
  /**
5
14
  *
@@ -15,31 +24,31 @@ function failureLoggedFetch(url: string, options: RequestInit = {}): Promise<Res
15
24
  });
16
25
  }
17
26
 
18
- /**
19
- *
20
- * @param authVerificationUrl
21
- */
22
- export function fetchSessionInfoService(authVerificationUrl: string): Promise<any> {
23
- return failureLoggedFetch(authVerificationUrl, {
24
- credentials: 'include',
25
- });
26
- }
27
-
28
27
  /**
29
28
  * Service to validate a auth token against a ThoughtSpot host.
30
29
  *
31
30
  * @param thoughtSpotHost : ThoughtSpot host to verify the token against.
32
31
  * @param authToken : Auth token to verify.
33
32
  */
34
- export function verifyTokenService(thoughtSpotHost: string, authToken: string): Promise<Response> {
33
+ export async function verifyTokenService(
34
+ thoughtSpotHost: string,
35
+ authToken: string,
36
+ ): Promise<boolean> {
35
37
  const authVerificationUrl = `${thoughtSpotHost}${EndPoints.IS_ACTIVE}`;
36
- return fetch(authVerificationUrl, {
37
- headers: {
38
- Authorization: `Bearer ${authToken}`,
39
- 'x-requested-by': 'ThoughtSpot',
40
- },
41
- credentials: 'omit',
42
- });
38
+ try {
39
+ const res = await fetch(authVerificationUrl, {
40
+ headers: {
41
+ Authorization: `Bearer ${authToken}`,
42
+ 'x-requested-by': 'ThoughtSpot',
43
+ },
44
+ credentials: 'omit',
45
+ });
46
+ return res.ok;
47
+ } catch (e) {
48
+ console.error(`Token Verification Service failed : ${e.message}`);
49
+ }
50
+
51
+ return false;
43
52
  }
44
53
 
45
54
  /**
@@ -120,17 +129,3 @@ export async function fetchBasicAuthService(
120
129
  credentials: 'include',
121
130
  });
122
131
  }
123
-
124
- /**
125
- *
126
- * @param thoughtSpotHost
127
- */
128
- export async function fetchLogoutService(thoughtSpotHost: string): Promise<any> {
129
- return failureLoggedFetch(`${thoughtSpotHost}${EndPoints.LOGOUT}`, {
130
- credentials: 'include',
131
- method: 'POST',
132
- headers: {
133
- 'x-requested-by': 'ThoughtSpot',
134
- },
135
- });
136
- }
@@ -0,0 +1,9 @@
1
+ export {
2
+ EndPoints,
3
+ fetchAuthPostService,
4
+ fetchAuthService,
5
+ fetchAuthTokenService,
6
+ fetchBasicAuthService,
7
+ verifyTokenService,
8
+ } from './authService';
9
+ export { fetchLogoutService, fetchSessionInfoService } from './tokenizedAuthService';
@@ -0,0 +1,40 @@
1
+ import { tokenizedFetch } from '../../tokenizedFetch';
2
+ import { EndPoints } from './authService';
3
+
4
+ /**
5
+ *
6
+ * @param url
7
+ * @param options
8
+ */
9
+ function tokenisedFailureLoggedFetch(url: string, options: RequestInit = {}): Promise<Response> {
10
+ return tokenizedFetch(url, options).then(async (r) => {
11
+ if (!r.ok && r.type !== 'opaqueredirect' && r.type !== 'opaque') {
12
+ console.error('Failure', await r.text?.());
13
+ }
14
+ return r;
15
+ });
16
+ }
17
+
18
+ /**
19
+ *
20
+ * @param authVerificationUrl
21
+ */
22
+ export function fetchSessionInfoService(authVerificationUrl: string): Promise<any> {
23
+ return tokenisedFailureLoggedFetch(authVerificationUrl, {
24
+ credentials: 'include',
25
+ });
26
+ }
27
+
28
+ /**
29
+ *
30
+ * @param thoughtSpotHost
31
+ */
32
+ export async function fetchLogoutService(thoughtSpotHost: string): Promise<any> {
33
+ return tokenisedFailureLoggedFetch(`${thoughtSpotHost}${EndPoints.LOGOUT}`, {
34
+ credentials: 'include',
35
+ method: 'POST',
36
+ headers: {
37
+ 'x-requested-by': 'ThoughtSpot',
38
+ },
39
+ });
40
+ }