@thoughtspot/visual-embed-sdk 1.26.1 → 1.26.2

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 (267) 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/TsEmbed.d.ts +302 -0
  14. package/cjs/src/embed/TsEmbed.d.ts.map +1 -0
  15. package/cjs/src/embed/TsEmbed.js +851 -0
  16. package/cjs/src/embed/TsEmbed.js.map +1 -0
  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/search.d.ts.map +1 -1
  28. package/cjs/src/embed/search.js +3 -1
  29. package/cjs/src/embed/search.js.map +1 -1
  30. package/cjs/src/embed/searchEmbed-basic-auth.spec.js +3 -2
  31. package/cjs/src/embed/searchEmbed-basic-auth.spec.js.map +1 -1
  32. package/cjs/src/embed/ts-embed.d.ts.map +1 -1
  33. package/cjs/src/embed/ts-embed.js +5 -3
  34. package/cjs/src/embed/ts-embed.js.map +1 -1
  35. package/cjs/src/embed/ts-embed.spec.js +58 -49
  36. package/cjs/src/embed/ts-embed.spec.js.map +1 -1
  37. package/cjs/src/index.d.ts +2 -1
  38. package/cjs/src/index.d.ts.map +1 -1
  39. package/cjs/src/index.js +2 -1
  40. package/cjs/src/index.js.map +1 -1
  41. package/cjs/src/tokenizedFetch.d.ts +2 -0
  42. package/cjs/src/tokenizedFetch.d.ts.map +1 -0
  43. package/cjs/src/tokenizedFetch.js +20 -0
  44. package/cjs/src/tokenizedFetch.js.map +1 -0
  45. package/cjs/src/types.d.ts +6 -0
  46. package/cjs/src/types.d.ts.map +1 -1
  47. package/cjs/src/types.js.map +1 -1
  48. package/cjs/src/utils/answerService.d.ts +10 -0
  49. package/cjs/src/utils/answerService.d.ts.map +1 -0
  50. package/cjs/src/utils/answerService.js +61 -0
  51. package/cjs/src/utils/answerService.js.map +1 -0
  52. package/cjs/src/utils/answerService.spec.d.ts +2 -0
  53. package/cjs/src/utils/answerService.spec.d.ts.map +1 -0
  54. package/cjs/src/utils/answerService.spec.js +31 -0
  55. package/cjs/src/utils/answerService.spec.js.map +1 -0
  56. package/cjs/src/utils/authService/authService.d.ts +45 -0
  57. package/cjs/src/utils/authService/authService.d.ts.map +1 -0
  58. package/cjs/src/utils/authService/authService.js +115 -0
  59. package/cjs/src/utils/authService/authService.js.map +1 -0
  60. package/cjs/src/utils/authService/authService.spec.d.ts +2 -0
  61. package/cjs/src/utils/authService/authService.spec.d.ts.map +1 -0
  62. package/cjs/src/utils/authService/authService.spec.js +82 -0
  63. package/cjs/src/utils/authService/authService.spec.js.map +1 -0
  64. package/cjs/src/utils/authService/index.d.ts +3 -0
  65. package/cjs/src/utils/authService/index.d.ts.map +1 -0
  66. package/cjs/src/utils/authService/index.js +14 -0
  67. package/cjs/src/utils/authService/index.js.map +1 -0
  68. package/cjs/src/utils/authService/tokenisedAuthSerice.d.ts +11 -0
  69. package/cjs/src/utils/authService/tokenisedAuthSerice.d.ts.map +1 -0
  70. package/cjs/src/utils/authService/tokenisedAuthSerice.js +44 -0
  71. package/cjs/src/utils/authService/tokenisedAuthSerice.js.map +1 -0
  72. package/cjs/src/utils/authService/tokenizedAuthService.d.ts +11 -0
  73. package/cjs/src/utils/authService/tokenizedAuthService.d.ts.map +1 -0
  74. package/cjs/src/utils/authService/tokenizedAuthService.js +44 -0
  75. package/cjs/src/utils/authService/tokenizedAuthService.js.map +1 -0
  76. package/cjs/src/utils/authService.d.ts +12 -1
  77. package/cjs/src/utils/authService.d.ts.map +1 -1
  78. package/cjs/src/utils/authService.js +32 -16
  79. package/cjs/src/utils/authService.js.map +1 -1
  80. package/cjs/src/utils/authService.spec.js +3 -4
  81. package/cjs/src/utils/authService.spec.js.map +1 -1
  82. package/cjs/src/utils/graphql/answerService/answerService.d.ts.map +1 -1
  83. package/cjs/src/utils/graphql/answerService/answerService.js +2 -1
  84. package/cjs/src/utils/graphql/answerService/answerService.js.map +1 -1
  85. package/cjs/src/utils/graphql/answerService/answerService.spec.js +15 -3
  86. package/cjs/src/utils/graphql/answerService/answerService.spec.js.map +1 -1
  87. package/cjs/src/utils/graphql/graphql-request.spec.d.ts +2 -0
  88. package/cjs/src/utils/graphql/graphql-request.spec.d.ts.map +1 -0
  89. package/cjs/src/utils/graphql/graphql-request.spec.js +39 -0
  90. package/cjs/src/utils/graphql/graphql-request.spec.js.map +1 -0
  91. package/cjs/src/utils/logger.d.ts +28 -0
  92. package/cjs/src/utils/logger.d.ts.map +1 -0
  93. package/cjs/src/utils/logger.js +82 -0
  94. package/cjs/src/utils/logger.js.map +1 -0
  95. package/cjs/src/utils/processData.d.ts.map +1 -1
  96. package/cjs/src/utils/processData.js +5 -4
  97. package/cjs/src/utils/processData.js.map +1 -1
  98. package/cjs/src/utils/processData.spec.js +8 -7
  99. package/cjs/src/utils/processData.spec.js.map +1 -1
  100. package/dist/src/auth.d.ts +0 -12
  101. package/dist/src/auth.d.ts.map +1 -1
  102. package/dist/src/auth.spec.d.ts.map +1 -1
  103. package/dist/src/authToken.d.ts +4 -0
  104. package/dist/src/authToken.d.ts.map +1 -0
  105. package/dist/src/embed/base.d.ts +0 -9
  106. package/dist/src/embed/base.d.ts.map +1 -1
  107. package/dist/src/embed/embedConfig.d.ts +18 -0
  108. package/dist/src/embed/embedConfig.d.ts.map +1 -0
  109. package/dist/src/embed/search.d.ts.map +1 -1
  110. package/dist/src/embed/ts-embed.d.ts.map +1 -1
  111. package/dist/src/index.d.ts +2 -1
  112. package/dist/src/index.d.ts.map +1 -1
  113. package/dist/src/tokenizedFetch.d.ts +2 -0
  114. package/dist/src/tokenizedFetch.d.ts.map +1 -0
  115. package/dist/src/types.d.ts +6 -0
  116. package/dist/src/types.d.ts.map +1 -1
  117. package/dist/src/utils/answerService.d.ts +10 -0
  118. package/dist/src/utils/answerService.d.ts.map +1 -0
  119. package/dist/src/utils/answerService.spec.d.ts +2 -0
  120. package/dist/src/utils/answerService.spec.d.ts.map +1 -0
  121. package/dist/src/utils/authService/authService.d.ts +45 -0
  122. package/dist/src/utils/authService/authService.d.ts.map +1 -0
  123. package/dist/src/utils/authService/authService.spec.d.ts +2 -0
  124. package/dist/src/utils/authService/authService.spec.d.ts.map +1 -0
  125. package/dist/src/utils/authService/index.d.ts +3 -0
  126. package/dist/src/utils/authService/index.d.ts.map +1 -0
  127. package/dist/src/utils/authService/tokenisedAuthSerice.d.ts +11 -0
  128. package/dist/src/utils/authService/tokenisedAuthSerice.d.ts.map +1 -0
  129. package/dist/src/utils/authService/tokenizedAuthService.d.ts +11 -0
  130. package/dist/src/utils/authService/tokenizedAuthService.d.ts.map +1 -0
  131. package/dist/src/utils/authService.d.ts +12 -1
  132. package/dist/src/utils/authService.d.ts.map +1 -1
  133. package/dist/src/utils/graphql/answerService/answerService.d.ts.map +1 -1
  134. package/dist/src/utils/graphql/graphql-request.spec.d.ts +2 -0
  135. package/dist/src/utils/graphql/graphql-request.spec.d.ts.map +1 -0
  136. package/dist/src/utils/logger.d.ts +28 -0
  137. package/dist/src/utils/logger.d.ts.map +1 -0
  138. package/dist/src/utils/processData.d.ts.map +1 -1
  139. package/dist/tsembed-react.es.js +201 -140
  140. package/dist/tsembed-react.js +201 -140
  141. package/dist/tsembed.es.js +230 -171
  142. package/dist/tsembed.js +230 -171
  143. package/dist/visual-embed-sdk-react-full.d.ts +23 -21
  144. package/dist/visual-embed-sdk-react.d.ts +23 -21
  145. package/dist/visual-embed-sdk.d.ts +23 -21
  146. package/lib/package.json +2 -2
  147. package/lib/src/auth.d.ts +0 -12
  148. package/lib/src/auth.d.ts.map +1 -1
  149. package/lib/src/auth.js +11 -48
  150. package/lib/src/auth.js.map +1 -1
  151. package/lib/src/auth.spec.d.ts.map +1 -1
  152. package/lib/src/auth.spec.js +42 -32
  153. package/lib/src/auth.spec.js.map +1 -1
  154. package/lib/src/authToken.d.ts +4 -0
  155. package/lib/src/authToken.d.ts.map +1 -0
  156. package/lib/src/authToken.js +56 -0
  157. package/lib/src/authToken.js.map +1 -0
  158. package/lib/src/embed/TsEmbed.d.ts +302 -0
  159. package/lib/src/embed/TsEmbed.d.ts.map +1 -0
  160. package/lib/src/embed/TsEmbed.js +847 -0
  161. package/lib/src/embed/TsEmbed.js.map +1 -0
  162. package/lib/src/embed/base.d.ts +0 -9
  163. package/lib/src/embed/base.d.ts.map +1 -1
  164. package/lib/src/embed/base.js +21 -43
  165. package/lib/src/embed/base.js.map +1 -1
  166. package/lib/src/embed/base.spec.js +15 -14
  167. package/lib/src/embed/base.spec.js.map +1 -1
  168. package/lib/src/embed/embedConfig.d.ts +18 -0
  169. package/lib/src/embed/embedConfig.d.ts.map +1 -0
  170. package/lib/src/embed/embedConfig.js +20 -0
  171. package/lib/src/embed/embedConfig.js.map +1 -0
  172. package/lib/src/embed/search.d.ts.map +1 -1
  173. package/lib/src/embed/search.js +4 -2
  174. package/lib/src/embed/search.js.map +1 -1
  175. package/lib/src/embed/searchEmbed-basic-auth.spec.js +3 -2
  176. package/lib/src/embed/searchEmbed-basic-auth.spec.js.map +1 -1
  177. package/lib/src/embed/ts-embed.d.ts.map +1 -1
  178. package/lib/src/embed/ts-embed.js +4 -2
  179. package/lib/src/embed/ts-embed.js.map +1 -1
  180. package/lib/src/embed/ts-embed.spec.js +58 -49
  181. package/lib/src/embed/ts-embed.spec.js.map +1 -1
  182. package/lib/src/index.d.ts +2 -1
  183. package/lib/src/index.d.ts.map +1 -1
  184. package/lib/src/index.js +2 -1
  185. package/lib/src/index.js.map +1 -1
  186. package/lib/src/tokenizedFetch.d.ts +2 -0
  187. package/lib/src/tokenizedFetch.d.ts.map +1 -0
  188. package/lib/src/tokenizedFetch.js +16 -0
  189. package/lib/src/tokenizedFetch.js.map +1 -0
  190. package/lib/src/types.d.ts +6 -0
  191. package/lib/src/types.d.ts.map +1 -1
  192. package/lib/src/types.js.map +1 -1
  193. package/lib/src/utils/answerService.d.ts +10 -0
  194. package/lib/src/utils/answerService.d.ts.map +1 -0
  195. package/lib/src/utils/answerService.js +57 -0
  196. package/lib/src/utils/answerService.js.map +1 -0
  197. package/lib/src/utils/answerService.spec.d.ts +2 -0
  198. package/lib/src/utils/answerService.spec.d.ts.map +1 -0
  199. package/lib/src/utils/answerService.spec.js +29 -0
  200. package/lib/src/utils/answerService.spec.js.map +1 -0
  201. package/lib/src/utils/authService/authService.d.ts +45 -0
  202. package/lib/src/utils/authService/authService.d.ts.map +1 -0
  203. package/lib/src/utils/authService/authService.js +107 -0
  204. package/lib/src/utils/authService/authService.js.map +1 -0
  205. package/lib/src/utils/authService/authService.spec.d.ts +2 -0
  206. package/lib/src/utils/authService/authService.spec.d.ts.map +1 -0
  207. package/lib/src/utils/authService/authService.spec.js +80 -0
  208. package/lib/src/utils/authService/authService.spec.js.map +1 -0
  209. package/lib/src/utils/authService/index.d.ts +3 -0
  210. package/lib/src/utils/authService/index.d.ts.map +1 -0
  211. package/lib/src/utils/authService/index.js +3 -0
  212. package/lib/src/utils/authService/index.js.map +1 -0
  213. package/lib/src/utils/authService/tokenisedAuthSerice.d.ts +11 -0
  214. package/lib/src/utils/authService/tokenisedAuthSerice.d.ts.map +1 -0
  215. package/lib/src/utils/authService/tokenisedAuthSerice.js +39 -0
  216. package/lib/src/utils/authService/tokenisedAuthSerice.js.map +1 -0
  217. package/lib/src/utils/authService/tokenizedAuthService.d.ts +11 -0
  218. package/lib/src/utils/authService/tokenizedAuthService.d.ts.map +1 -0
  219. package/lib/src/utils/authService/tokenizedAuthService.js +39 -0
  220. package/lib/src/utils/authService/tokenizedAuthService.js.map +1 -0
  221. package/lib/src/utils/authService.d.ts +12 -1
  222. package/lib/src/utils/authService.d.ts.map +1 -1
  223. package/lib/src/utils/authService.js +26 -10
  224. package/lib/src/utils/authService.js.map +1 -1
  225. package/lib/src/utils/authService.spec.js +1 -2
  226. package/lib/src/utils/authService.spec.js.map +1 -1
  227. package/lib/src/utils/graphql/answerService/answerService.d.ts.map +1 -1
  228. package/lib/src/utils/graphql/answerService/answerService.js +2 -1
  229. package/lib/src/utils/graphql/answerService/answerService.js.map +1 -1
  230. package/lib/src/utils/graphql/answerService/answerService.spec.js +14 -3
  231. package/lib/src/utils/graphql/answerService/answerService.spec.js.map +1 -1
  232. package/lib/src/utils/graphql/graphql-request.spec.d.ts +2 -0
  233. package/lib/src/utils/graphql/graphql-request.spec.d.ts.map +1 -0
  234. package/lib/src/utils/graphql/graphql-request.spec.js +36 -0
  235. package/lib/src/utils/graphql/graphql-request.spec.js.map +1 -0
  236. package/lib/src/utils/logger.d.ts +28 -0
  237. package/lib/src/utils/logger.d.ts.map +1 -0
  238. package/lib/src/utils/logger.js +75 -0
  239. package/lib/src/utils/logger.js.map +1 -0
  240. package/lib/src/utils/processData.d.ts.map +1 -1
  241. package/lib/src/utils/processData.js +4 -3
  242. package/lib/src/utils/processData.js.map +1 -1
  243. package/lib/src/utils/processData.spec.js +8 -7
  244. package/lib/src/utils/processData.spec.js.map +1 -1
  245. package/lib/src/visual-embed-sdk.d.ts +28 -22
  246. package/package.json +2 -2
  247. package/src/auth.spec.ts +77 -63
  248. package/src/auth.ts +12 -55
  249. package/src/authToken.ts +66 -0
  250. package/src/embed/base.spec.ts +18 -17
  251. package/src/embed/base.ts +26 -51
  252. package/src/embed/embedConfig.ts +23 -0
  253. package/src/embed/search.ts +10 -10
  254. package/src/embed/searchEmbed-basic-auth.spec.ts +3 -2
  255. package/src/embed/ts-embed.spec.ts +87 -75
  256. package/src/embed/ts-embed.ts +11 -20
  257. package/src/index.ts +8 -2
  258. package/src/tokenizedFetch.ts +18 -0
  259. package/src/types.ts +34 -23
  260. package/src/utils/{authService.spec.ts → authService/authService.spec.ts} +2 -3
  261. package/src/utils/{authService.ts → authService/authService.ts} +29 -34
  262. package/src/utils/authService/index.ts +9 -0
  263. package/src/utils/authService/tokenizedAuthService.ts +40 -0
  264. package/src/utils/graphql/answerService/answerService.spec.ts +16 -4
  265. package/src/utils/graphql/answerService/answerService.ts +2 -1
  266. package/src/utils/processData.spec.ts +19 -16
  267. package/src/utils/processData.ts +3 -2
@@ -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
 
@@ -1073,11 +1071,11 @@ export class TsEmbed {
1073
1071
  ) {
1074
1072
  console.warn(
1075
1073
  `${this.embedComponentType} was pre-rendered with `
1076
- + `"${key}" as "${JSON.stringify(preRenderedObject.viewConfig[key])}" `
1077
- + `but a different value "${JSON.stringify(viewConfig[key])}" `
1078
- + 'was passed to the Embed component. '
1079
- + 'The new value provided is ignored, the value provided during '
1080
- + 'preRender is used.',
1074
+ + `"${key}" as "${JSON.stringify(preRenderedObject.viewConfig[key])}" `
1075
+ + `but a different value "${JSON.stringify(viewConfig[key])}" `
1076
+ + 'was passed to the Embed component. '
1077
+ + 'The new value provided is ignored, the value provided during '
1078
+ + 'preRender is used.',
1081
1079
  );
1082
1080
  }
1083
1081
  });
@@ -1204,15 +1202,8 @@ export class TsEmbed {
1204
1202
  * @version SDK: 1.25.0 / ThoughtSpot 9.10.0
1205
1203
  */
1206
1204
  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
- );
1205
+ const { session, embedAnswerData } = await this.trigger(HostEvent.GetAnswerSession, vizId);
1206
+ return new AnswerService(session, embedAnswerData, this.embedConfig.thoughtSpotHost);
1216
1207
  }
1217
1208
  }
1218
1209
 
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,10 +531,17 @@ 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
537
- export interface LayoutConfig { }
544
+ export interface LayoutConfig {}
538
545
 
539
546
  /**
540
547
  * Embedded iFrame configuration
@@ -3212,40 +3219,44 @@ export enum ContextMenuTriggerOptions {
3212
3219
 
3213
3220
  export interface ColumnValue {
3214
3221
  column: {
3215
- id: string,
3216
- name: string,
3217
- dataType: string,
3218
- [key: string]: any
3219
- },
3220
- value: string | number | boolean | {
3221
- v: {
3222
- s: number;
3223
- e: number;
3224
- }
3222
+ id: string;
3223
+ name: string;
3224
+ dataType: string;
3225
+ [key: string]: any;
3225
3226
  };
3227
+ value:
3228
+ | string
3229
+ | number
3230
+ | boolean
3231
+ | {
3232
+ v: {
3233
+ s: number;
3234
+ e: number;
3235
+ };
3236
+ };
3226
3237
  }
3227
3238
 
3228
3239
  export interface VizPoint {
3229
- selectedAttributes: ColumnValue[],
3230
- selectedMeasures: ColumnValue[]
3240
+ selectedAttributes: ColumnValue[];
3241
+ selectedMeasures: ColumnValue[];
3231
3242
  }
3232
3243
 
3233
3244
  export interface CustomActionPayload {
3234
3245
  contextMenuPoints?: {
3235
- clickedPoint: VizPoint
3236
- selectedPoints: VizPoint[]
3246
+ clickedPoint: VizPoint;
3247
+ selectedPoints: VizPoint[];
3237
3248
  };
3238
3249
  embedAnswerData: {
3239
- name: string,
3240
- id: string,
3250
+ name: string;
3251
+ id: string;
3241
3252
  sources: {
3242
3253
  header: {
3243
- guid: string
3244
- }
3245
- },
3246
- columns: any[],
3247
- data: any[],
3248
- [key: string]: any
3254
+ guid: string;
3255
+ };
3256
+ };
3257
+ columns: any[];
3258
+ data: any[];
3259
+ [key: string]: any;
3249
3260
  };
3250
3261
  session: SessionInterface;
3251
3262
  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
+ }
@@ -1,7 +1,10 @@
1
1
  import 'jest-fetch-mock';
2
- import { VizPoint } from 'src/types';
2
+ import { AuthType, VizPoint } from '../../../types';
3
3
  import { AnswerService } from './answerService';
4
4
  import { getAnswerData, removeColumns } from './answer-queries';
5
+ import * as authTokenInstance from '../../../authToken';
6
+ import * as tokenizedFetch from '../../../tokenizedFetch';
7
+ import * as embedConfigInstance from '../../../embed/embedConfig';
5
8
 
6
9
  const defaultSession = {
7
10
  sessionId: 'id',
@@ -111,20 +114,29 @@ describe('Answer service tests', () => {
111
114
  test('fetchCSVBlob should call the right API', () => {
112
115
  fetchMock.once('Bla');
113
116
  const answerService = createAnswerService();
117
+
118
+ const mockEmbedConfig = {
119
+ thougthspotHost: '/test',
120
+ authType: AuthType.TrustedAuthTokenCookieless,
121
+ };
122
+ jest.spyOn(embedConfigInstance, 'getEmbedConfig').mockReturnValueOnce(mockEmbedConfig);
123
+ jest.spyOn(authTokenInstance, 'getAuthenticationToken').mockReturnValueOnce(Promise.resolve('token'));
124
+ const mockTokenizedFetch = jest.spyOn(tokenizedFetch, 'tokenizedFetch');
114
125
  answerService.fetchCSVBlob(undefined, true);
115
- expect(fetchMock).toHaveBeenCalledWith(
126
+
127
+ expect(mockTokenizedFetch).toHaveBeenCalledWith(
116
128
  `https://tshost/prism/download/answer/csv?sessionId=${defaultSession.sessionId}&genNo=${defaultSession.genNo}&userLocale=en-us&exportFileName=data&hideCsvHeader=false`,
117
129
  expect.objectContaining({}),
118
130
  );
119
131
 
120
132
  answerService.fetchCSVBlob('en-uk', true);
121
- expect(fetchMock).toHaveBeenCalledWith(
133
+ expect(mockTokenizedFetch).toHaveBeenCalledWith(
122
134
  `https://tshost/prism/download/answer/csv?sessionId=${defaultSession.sessionId}&genNo=${defaultSession.genNo}&userLocale=en-uk&exportFileName=data&hideCsvHeader=false`,
123
135
  expect.objectContaining({}),
124
136
  );
125
137
 
126
138
  answerService.fetchCSVBlob(undefined, false);
127
- expect(fetchMock).toHaveBeenCalledWith(
139
+ expect(mockTokenizedFetch).toHaveBeenCalledWith(
128
140
  `https://tshost/prism/download/answer/csv?sessionId=${defaultSession.sessionId}&genNo=${defaultSession.genNo}&userLocale=en-us&exportFileName=data&hideCsvHeader=true`,
129
141
  expect.objectContaining({}),
130
142
  );