@thoughtspot/visual-embed-sdk 1.26.2 → 1.27.0-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 (216) hide show
  1. package/README.md +1 -1
  2. package/cjs/package.json +1 -1
  3. package/cjs/src/auth.d.ts +4 -4
  4. package/cjs/src/auth.d.ts.map +1 -1
  5. package/cjs/src/auth.js +10 -4
  6. package/cjs/src/auth.js.map +1 -1
  7. package/cjs/src/embed/app.d.ts +15 -15
  8. package/cjs/src/embed/app.d.ts.map +1 -1
  9. package/cjs/src/embed/app.js +1 -1
  10. package/cjs/src/embed/app.js.map +1 -1
  11. package/cjs/src/embed/liveboard.d.ts +28 -23
  12. package/cjs/src/embed/liveboard.d.ts.map +1 -1
  13. package/cjs/src/embed/liveboard.js +4 -3
  14. package/cjs/src/embed/liveboard.js.map +1 -1
  15. package/cjs/src/embed/sage.d.ts +48 -30
  16. package/cjs/src/embed/sage.d.ts.map +1 -1
  17. package/cjs/src/embed/sage.js +1 -1
  18. package/cjs/src/embed/sage.js.map +1 -1
  19. package/cjs/src/embed/search-bar.d.ts +22 -6
  20. package/cjs/src/embed/search-bar.d.ts.map +1 -1
  21. package/cjs/src/embed/search-bar.js.map +1 -1
  22. package/cjs/src/embed/search.d.ts +34 -19
  23. package/cjs/src/embed/search.d.ts.map +1 -1
  24. package/cjs/src/embed/search.js +7 -3
  25. package/cjs/src/embed/search.js.map +1 -1
  26. package/cjs/src/embed/search.spec.js +10 -0
  27. package/cjs/src/embed/search.spec.js.map +1 -1
  28. package/cjs/src/embed/ts-embed.d.ts +1 -0
  29. package/cjs/src/embed/ts-embed.d.ts.map +1 -1
  30. package/cjs/src/embed/ts-embed.js +27 -7
  31. package/cjs/src/embed/ts-embed.js.map +1 -1
  32. package/cjs/src/embed/ts-embed.spec.js +114 -0
  33. package/cjs/src/embed/ts-embed.spec.js.map +1 -1
  34. package/cjs/src/react/index.spec.js +0 -12
  35. package/cjs/src/react/index.spec.js.map +1 -1
  36. package/cjs/src/types.d.ts +727 -242
  37. package/cjs/src/types.d.ts.map +1 -1
  38. package/cjs/src/types.js +653 -175
  39. package/cjs/src/types.js.map +1 -1
  40. package/cjs/src/utils/graphql/answerService/answerService.d.ts +2 -4
  41. package/cjs/src/utils/graphql/answerService/answerService.d.ts.map +1 -1
  42. package/cjs/src/utils/graphql/answerService/answerService.js +2 -4
  43. package/cjs/src/utils/graphql/answerService/answerService.js.map +1 -1
  44. package/cjs/src/utils/processData.d.ts +6 -0
  45. package/cjs/src/utils/processData.d.ts.map +1 -1
  46. package/cjs/src/utils/processData.js +5 -1
  47. package/cjs/src/utils/processData.js.map +1 -1
  48. package/cjs/src/utils/processTrigger.js +1 -1
  49. package/dist/src/auth.d.ts +4 -4
  50. package/dist/src/auth.d.ts.map +1 -1
  51. package/dist/src/embed/app.d.ts +15 -15
  52. package/dist/src/embed/app.d.ts.map +1 -1
  53. package/dist/src/embed/liveboard.d.ts +28 -23
  54. package/dist/src/embed/liveboard.d.ts.map +1 -1
  55. package/dist/src/embed/sage.d.ts +48 -30
  56. package/dist/src/embed/sage.d.ts.map +1 -1
  57. package/dist/src/embed/search-bar.d.ts +22 -6
  58. package/dist/src/embed/search-bar.d.ts.map +1 -1
  59. package/dist/src/embed/search.d.ts +34 -19
  60. package/dist/src/embed/search.d.ts.map +1 -1
  61. package/dist/src/embed/ts-embed.d.ts +1 -0
  62. package/dist/src/embed/ts-embed.d.ts.map +1 -1
  63. package/dist/src/types.d.ts +727 -242
  64. package/dist/src/types.d.ts.map +1 -1
  65. package/dist/src/utils/graphql/answerService/answerService.d.ts +2 -4
  66. package/dist/src/utils/graphql/answerService/answerService.d.ts.map +1 -1
  67. package/dist/src/utils/processData.d.ts +6 -0
  68. package/dist/src/utils/processData.d.ts.map +1 -1
  69. package/dist/tsembed-react.es.js +706 -200
  70. package/dist/tsembed-react.js +705 -199
  71. package/dist/tsembed.es.js +709 -200
  72. package/dist/tsembed.js +707 -198
  73. package/dist/visual-embed-sdk-react-full.d.ts +898 -339
  74. package/dist/visual-embed-sdk-react.d.ts +898 -339
  75. package/dist/visual-embed-sdk.d.ts +898 -339
  76. package/lib/package.json +1 -1
  77. package/lib/src/auth.d.ts +4 -4
  78. package/lib/src/auth.d.ts.map +1 -1
  79. package/lib/src/auth.js +10 -4
  80. package/lib/src/auth.js.map +1 -1
  81. package/lib/src/embed/app.d.ts +15 -15
  82. package/lib/src/embed/app.d.ts.map +1 -1
  83. package/lib/src/embed/app.js +1 -1
  84. package/lib/src/embed/app.js.map +1 -1
  85. package/lib/src/embed/liveboard.d.ts +28 -23
  86. package/lib/src/embed/liveboard.d.ts.map +1 -1
  87. package/lib/src/embed/liveboard.js +4 -3
  88. package/lib/src/embed/liveboard.js.map +1 -1
  89. package/lib/src/embed/sage.d.ts +48 -30
  90. package/lib/src/embed/sage.d.ts.map +1 -1
  91. package/lib/src/embed/sage.js +1 -1
  92. package/lib/src/embed/sage.js.map +1 -1
  93. package/lib/src/embed/search-bar.d.ts +22 -6
  94. package/lib/src/embed/search-bar.d.ts.map +1 -1
  95. package/lib/src/embed/search-bar.js.map +1 -1
  96. package/lib/src/embed/search.d.ts +34 -19
  97. package/lib/src/embed/search.d.ts.map +1 -1
  98. package/lib/src/embed/search.js +7 -3
  99. package/lib/src/embed/search.js.map +1 -1
  100. package/lib/src/embed/search.spec.js +10 -0
  101. package/lib/src/embed/search.spec.js.map +1 -1
  102. package/lib/src/embed/ts-embed.d.ts +1 -0
  103. package/lib/src/embed/ts-embed.d.ts.map +1 -1
  104. package/lib/src/embed/ts-embed.js +28 -8
  105. package/lib/src/embed/ts-embed.js.map +1 -1
  106. package/lib/src/embed/ts-embed.spec.js +114 -0
  107. package/lib/src/embed/ts-embed.spec.js.map +1 -1
  108. package/lib/src/react/index.spec.js +0 -12
  109. package/lib/src/react/index.spec.js.map +1 -1
  110. package/lib/src/types.d.ts +727 -242
  111. package/lib/src/types.d.ts.map +1 -1
  112. package/lib/src/types.js +653 -175
  113. package/lib/src/types.js.map +1 -1
  114. package/lib/src/utils/graphql/answerService/answerService.d.ts +2 -4
  115. package/lib/src/utils/graphql/answerService/answerService.d.ts.map +1 -1
  116. package/lib/src/utils/graphql/answerService/answerService.js +2 -4
  117. package/lib/src/utils/graphql/answerService/answerService.js.map +1 -1
  118. package/lib/src/utils/processData.d.ts +6 -0
  119. package/lib/src/utils/processData.d.ts.map +1 -1
  120. package/lib/src/utils/processData.js +4 -1
  121. package/lib/src/utils/processData.js.map +1 -1
  122. package/lib/src/utils/processTrigger.js +1 -1
  123. package/lib/src/visual-embed-sdk.d.ts +898 -339
  124. package/package.json +1 -1
  125. package/src/auth.ts +10 -4
  126. package/src/embed/app.ts +20 -20
  127. package/src/embed/liveboard.ts +32 -27
  128. package/src/embed/sage.ts +48 -30
  129. package/src/embed/search-bar.tsx +22 -6
  130. package/src/embed/search.spec.ts +13 -0
  131. package/src/embed/search.ts +42 -22
  132. package/src/embed/ts-embed.spec.ts +132 -0
  133. package/src/embed/ts-embed.ts +32 -14
  134. package/src/react/index.spec.tsx +0 -29
  135. package/src/types.ts +727 -243
  136. package/src/utils/graphql/answerService/answerService.ts +2 -4
  137. package/src/utils/processData.ts +4 -1
  138. package/src/utils/processTrigger.ts +1 -1
  139. package/cjs/src/embed/TsEmbed.d.ts +0 -302
  140. package/cjs/src/embed/TsEmbed.d.ts.map +0 -1
  141. package/cjs/src/embed/TsEmbed.js +0 -851
  142. package/cjs/src/embed/TsEmbed.js.map +0 -1
  143. package/cjs/src/utils/answerService.d.ts +0 -10
  144. package/cjs/src/utils/answerService.d.ts.map +0 -1
  145. package/cjs/src/utils/answerService.js +0 -61
  146. package/cjs/src/utils/answerService.js.map +0 -1
  147. package/cjs/src/utils/answerService.spec.d.ts +0 -2
  148. package/cjs/src/utils/answerService.spec.d.ts.map +0 -1
  149. package/cjs/src/utils/answerService.spec.js +0 -31
  150. package/cjs/src/utils/answerService.spec.js.map +0 -1
  151. package/cjs/src/utils/authService/tokenisedAuthSerice.d.ts +0 -11
  152. package/cjs/src/utils/authService/tokenisedAuthSerice.d.ts.map +0 -1
  153. package/cjs/src/utils/authService/tokenisedAuthSerice.js +0 -44
  154. package/cjs/src/utils/authService/tokenisedAuthSerice.js.map +0 -1
  155. package/cjs/src/utils/authService.d.ts +0 -55
  156. package/cjs/src/utils/authService.d.ts.map +0 -1
  157. package/cjs/src/utils/authService.js +0 -139
  158. package/cjs/src/utils/authService.js.map +0 -1
  159. package/cjs/src/utils/authService.spec.d.ts +0 -2
  160. package/cjs/src/utils/authService.spec.d.ts.map +0 -1
  161. package/cjs/src/utils/authService.spec.js +0 -82
  162. package/cjs/src/utils/authService.spec.js.map +0 -1
  163. package/cjs/src/utils/graphql/graphql-request.spec.d.ts +0 -2
  164. package/cjs/src/utils/graphql/graphql-request.spec.d.ts.map +0 -1
  165. package/cjs/src/utils/graphql/graphql-request.spec.js +0 -39
  166. package/cjs/src/utils/graphql/graphql-request.spec.js.map +0 -1
  167. package/cjs/src/utils/logger.d.ts +0 -28
  168. package/cjs/src/utils/logger.d.ts.map +0 -1
  169. package/cjs/src/utils/logger.js +0 -82
  170. package/cjs/src/utils/logger.js.map +0 -1
  171. package/dist/src/utils/answerService.d.ts +0 -10
  172. package/dist/src/utils/answerService.d.ts.map +0 -1
  173. package/dist/src/utils/answerService.spec.d.ts +0 -2
  174. package/dist/src/utils/answerService.spec.d.ts.map +0 -1
  175. package/dist/src/utils/authService/tokenisedAuthSerice.d.ts +0 -11
  176. package/dist/src/utils/authService/tokenisedAuthSerice.d.ts.map +0 -1
  177. package/dist/src/utils/authService.d.ts +0 -55
  178. package/dist/src/utils/authService.d.ts.map +0 -1
  179. package/dist/src/utils/authService.spec.d.ts +0 -2
  180. package/dist/src/utils/authService.spec.d.ts.map +0 -1
  181. package/dist/src/utils/graphql/graphql-request.spec.d.ts +0 -2
  182. package/dist/src/utils/graphql/graphql-request.spec.d.ts.map +0 -1
  183. package/dist/src/utils/logger.d.ts +0 -28
  184. package/dist/src/utils/logger.d.ts.map +0 -1
  185. package/lib/src/embed/TsEmbed.d.ts +0 -302
  186. package/lib/src/embed/TsEmbed.d.ts.map +0 -1
  187. package/lib/src/embed/TsEmbed.js +0 -847
  188. package/lib/src/embed/TsEmbed.js.map +0 -1
  189. package/lib/src/utils/answerService.d.ts +0 -10
  190. package/lib/src/utils/answerService.d.ts.map +0 -1
  191. package/lib/src/utils/answerService.js +0 -57
  192. package/lib/src/utils/answerService.js.map +0 -1
  193. package/lib/src/utils/answerService.spec.d.ts +0 -2
  194. package/lib/src/utils/answerService.spec.d.ts.map +0 -1
  195. package/lib/src/utils/answerService.spec.js +0 -29
  196. package/lib/src/utils/answerService.spec.js.map +0 -1
  197. package/lib/src/utils/authService/tokenisedAuthSerice.d.ts +0 -11
  198. package/lib/src/utils/authService/tokenisedAuthSerice.d.ts.map +0 -1
  199. package/lib/src/utils/authService/tokenisedAuthSerice.js +0 -39
  200. package/lib/src/utils/authService/tokenisedAuthSerice.js.map +0 -1
  201. package/lib/src/utils/authService.d.ts +0 -55
  202. package/lib/src/utils/authService.d.ts.map +0 -1
  203. package/lib/src/utils/authService.js +0 -129
  204. package/lib/src/utils/authService.js.map +0 -1
  205. package/lib/src/utils/authService.spec.d.ts +0 -2
  206. package/lib/src/utils/authService.spec.d.ts.map +0 -1
  207. package/lib/src/utils/authService.spec.js +0 -80
  208. package/lib/src/utils/authService.spec.js.map +0 -1
  209. package/lib/src/utils/graphql/graphql-request.spec.d.ts +0 -2
  210. package/lib/src/utils/graphql/graphql-request.spec.d.ts.map +0 -1
  211. package/lib/src/utils/graphql/graphql-request.spec.js +0 -36
  212. package/lib/src/utils/graphql/graphql-request.spec.js.map +0 -1
  213. package/lib/src/utils/logger.d.ts +0 -28
  214. package/lib/src/utils/logger.d.ts.map +0 -1
  215. package/lib/src/utils/logger.js +0 -75
  216. package/lib/src/utils/logger.js.map +0 -1
@@ -23,18 +23,19 @@ import { getReleaseVersion } from '../auth';
23
23
  import { getEmbedConfig } from './embedConfig';
24
24
 
25
25
  /**
26
- * Configuration for search options
26
+ * Configuration for search options.
27
+ *
27
28
  */
28
29
  export interface SearchOptions {
29
30
  /**
30
- * The tml string to load the answer
31
+ * Search tokens to pass in the query.
31
32
  */
32
33
  searchTokenString: string;
33
34
  /**
34
- * Boolean to determine if the search should be executed or not.
35
- * if it is executed, put the focus on the results.
36
- * if it’s not executed, put the focus in the search bar - at the end of
37
- * the tokens
35
+ * Boolean to define if the search should be executed or not.
36
+ * If it is executed, the focus is placed on the results.
37
+ * If it’s not executed, the focus is placed at the end of
38
+ * the token string in the search bar.
38
39
  */
39
40
  executeSearch?: boolean;
40
41
  }
@@ -59,19 +60,15 @@ export interface SearchViewConfig
59
60
  */
60
61
  collapseDataSources?: boolean;
61
62
  /**
62
- * If set to true, hides the data sources panel.
63
+ * Show or hide the data sources panel.
63
64
  */
64
65
  hideDataSources?: boolean;
65
66
  /**
66
- * If set to true, hides the charts and tables in search answers.
67
+ * Show or hide the charts and tables in search answers.
67
68
  * This attribute can be used to create a custom visualization
68
69
  * using raw answer data.
69
70
  */
70
71
  hideResults?: boolean;
71
- /**
72
- * If set to true, expands all the data sources panel.
73
- */
74
- expandAllDataSource?: boolean;
75
72
  /**
76
73
  * If set to true, the Search Assist feature is enabled.
77
74
  *
@@ -85,9 +82,9 @@ export interface SearchViewConfig
85
82
  forceTable?: boolean;
86
83
  /**
87
84
  * The array of data source GUIDs to set on load.
88
- * Only a single dataSource supported currently.
85
+ * Only a single data source is supported currently.
89
86
  *
90
- * @deprecated Use dataSource instead
87
+ * @deprecated Use `dataSource` instead.
91
88
  */
92
89
  dataSources?: string[];
93
90
  /**
@@ -99,11 +96,29 @@ export interface SearchViewConfig
99
96
  /**
100
97
  * The initial search query to load the answer with.
101
98
  *
102
- * @deprecated Use {@link searchOptions} instead
99
+ * @deprecated
100
+ *
101
+ * Use {@link searchOptions} instead.
103
102
  */
104
103
  searchQuery?: string;
105
104
  /**
106
- * Configuration for search options
105
+ * Configuration for search options.
106
+ * Includes the following properties:
107
+ *
108
+ * `searchTokenString`: Search tokens to pass in the query.
109
+ *
110
+ * `executeSearch`: Boolean to define if the search should be executed or not.
111
+ * If it is executed, the focus is placed on the results.
112
+ * If it’s not executed, the focus is placed at the end of
113
+ * the token string in the search bar.
114
+ *
115
+ * @example
116
+ * ```js
117
+ * searchOptions: {
118
+ * searchTokenString: '[quantity purchased] [region]',
119
+ * executeSearch: true,
120
+ * }
121
+ * ```
107
122
  */
108
123
  searchOptions?: SearchOptions;
109
124
  /**
@@ -111,10 +126,10 @@ export interface SearchViewConfig
111
126
  */
112
127
  answerId?: string;
113
128
  /**
114
- * If set to true, search page will render without the Search Bar
129
+ * If set to true, the search page will render without the Search Bar
115
130
  * The chart/table should still be visible.
116
131
  *
117
- * @version SDK: 1.21.0 | ThoughtSpot: 9.2.0.cl
132
+ * @version SDK: 1.21.0 | ThoughtSpot: 9.2.0.cl, 9.5.0.sw
118
133
  */
119
134
  hideSearchBar?: boolean;
120
135
  /**
@@ -177,7 +192,6 @@ export class SearchEmbed extends TsEmbed {
177
192
  protected getEmbedParams(): string {
178
193
  const {
179
194
  hideResults,
180
- expandAllDataSource,
181
195
  enableSearchAssist,
182
196
  forceTable,
183
197
  searchOptions,
@@ -185,6 +199,7 @@ export class SearchEmbed extends TsEmbed {
185
199
  dataSource,
186
200
  dataSources,
187
201
  excludeRuntimeFiltersfromURL,
202
+ hideSearchBar,
188
203
  dataPanelV2 = false,
189
204
  useLastSelectedSources = false,
190
205
  runtimeParameters,
@@ -221,6 +236,10 @@ export class SearchEmbed extends TsEmbed {
221
236
  queryParams[Param.ForceTable] = true;
222
237
  }
223
238
 
239
+ if (hideSearchBar) {
240
+ queryParams[Param.HideSearchBar] = true;
241
+ }
242
+
224
243
  queryParams[Param.DataPanelV2Enabled] = dataPanelV2;
225
244
  queryParams[Param.DataSourceMode] = this.getDataSourceMode();
226
245
 
@@ -253,7 +272,8 @@ export class SearchEmbed extends TsEmbed {
253
272
  * @param answerId The GUID of a saved answer
254
273
  * @param dataSources A list of data source GUIDs
255
274
  */
256
- private getIFrameSrc(answerId: string) {
275
+ public getIFrameSrc(): string {
276
+ const { answerId } = this.viewConfig;
257
277
  const answerPath = answerId ? `saved-answer/${answerId}` : 'answer';
258
278
  const tsPostHashParams = this.getThoughtSpotPostUrlParams();
259
279
 
@@ -267,14 +287,14 @@ export class SearchEmbed extends TsEmbed {
267
287
  super.render();
268
288
  const { answerId } = this.viewConfig;
269
289
 
270
- const src = this.getIFrameSrc(answerId);
290
+ const src = this.getIFrameSrc();
271
291
  this.renderIFrame(src);
272
292
  getAuthPromise().then(() => {
273
293
  if (
274
294
  checkReleaseVersionInBeta(
275
295
  getReleaseVersion(),
276
296
  getEmbedConfig().suppressSearchEmbedBetaWarning
277
- || getEmbedConfig().suppressErrorAlerts,
297
+ || getEmbedConfig().suppressErrorAlerts,
278
298
  )
279
299
  ) {
280
300
  alert(ERROR_MESSAGE.SEARCHEMBED_BETA_WRANING_MESSAGE);
@@ -562,6 +562,138 @@ describe('Unit test case for ts embed', () => {
562
562
  });
563
563
  });
564
564
 
565
+ describe('Token fetch fails in cookieless authentication authType', () => {
566
+ beforeEach(() => {
567
+ jest.spyOn(authInstance, 'doCookielessTokenAuth').mockResolvedValueOnce(true);
568
+ init({
569
+ thoughtSpotHost: 'tshost',
570
+ customizations: customisations,
571
+ customCssUrl: 'http://localhost:5000',
572
+ authType: AuthType.TrustedAuthTokenCookieless,
573
+ getAuthToken: () => Promise.reject(),
574
+ });
575
+ });
576
+
577
+ afterEach(() => {
578
+ jest.clearAllMocks();
579
+ baseInstance.reset();
580
+ });
581
+
582
+ test('should show login failure message if token failed during app_init', async () => {
583
+ const a = jest.spyOn(authService, 'verifyTokenService');
584
+ a.mockResolvedValue(true);
585
+
586
+ // authVerifyMock.mockResolvedValue(true);
587
+ const mockEmbedEventPayload = {
588
+ type: EmbedEvent.APP_INIT,
589
+ data: {},
590
+ };
591
+ const searchEmbed = new SearchEmbed(getRootEl(), defaultViewConfig);
592
+ searchEmbed.render();
593
+ const mockPort: any = {
594
+ postMessage: jest.fn(),
595
+ };
596
+ await executeAfterWait(() => {
597
+ const iframe = getIFrameEl();
598
+ postMessageToParent(iframe.contentWindow, mockEmbedEventPayload, mockPort);
599
+ });
600
+ await executeAfterWait(() => {
601
+ expect(mockPort.postMessage).not.toHaveBeenCalled();
602
+ expect(getRootEl().innerHTML).toContain('Not logged in');
603
+ });
604
+
605
+ jest.spyOn(authService, 'verifyTokenService').mockClear();
606
+ });
607
+
608
+ test('should show login failure message if token failed during app_init prerender', async () => {
609
+ const a = jest.spyOn(authService, 'verifyTokenService');
610
+ a.mockResolvedValue(true);
611
+
612
+ // authVerifyMock.mockResolvedValue(true);
613
+ const mockEmbedEventPayload = {
614
+ type: EmbedEvent.APP_INIT,
615
+ data: {},
616
+ };
617
+ const searchEmbed = new SearchEmbed(getRootEl(), { ...defaultViewConfig, preRenderId: 'test' });
618
+ searchEmbed.preRender();
619
+ const mockPort: any = {
620
+ postMessage: jest.fn(),
621
+ };
622
+ await executeAfterWait(() => {
623
+ const iframe = getIFrameEl();
624
+ postMessageToParent(iframe.contentWindow, mockEmbedEventPayload, mockPort);
625
+ });
626
+ const preRenderWrapper = document.getElementById('tsEmbed-pre-render-wrapper-test');
627
+ await executeAfterWait(() => {
628
+ expect(mockPort.postMessage).not.toHaveBeenCalled();
629
+ expect(preRenderWrapper.innerHTML).toContain('Not logged in');
630
+ });
631
+
632
+ jest.spyOn(authService, 'verifyTokenService').mockClear();
633
+ });
634
+
635
+ test('should show login failure message if update token failed', async () => {
636
+ const a = jest.spyOn(authService, 'verifyTokenService');
637
+ a.mockResolvedValue(true);
638
+
639
+ // authVerifyMock.mockResolvedValue(true);
640
+ const mockEmbedEventPayload = {
641
+ type: EmbedEvent.AuthExpire,
642
+ data: {},
643
+ };
644
+ const searchEmbed = new SearchEmbed(getRootEl(), defaultViewConfig);
645
+ jest.spyOn(baseInstance, 'notifyAuthFailure');
646
+ searchEmbed.render();
647
+ const mockPort: any = {
648
+ postMessage: jest.fn(),
649
+ };
650
+ await executeAfterWait(() => {
651
+ const iframe = getIFrameEl();
652
+ postMessageToParent(iframe.contentWindow, mockEmbedEventPayload, mockPort);
653
+ });
654
+ await executeAfterWait(() => {
655
+ expect(getRootEl().innerHTML).toContain('Not logged in');
656
+ expect(baseInstance.notifyAuthFailure).toBeCalledWith(
657
+ authInstance.AuthFailureType.EXPIRY,
658
+ );
659
+ });
660
+
661
+ jest.spyOn(authService, 'verifyTokenService').mockClear();
662
+ jest.spyOn(baseInstance, 'notifyAuthFailure').mockClear();
663
+ });
664
+
665
+ test('should show login failure message if update token failed prerender', async () => {
666
+ const a = jest.spyOn(authService, 'verifyTokenService');
667
+ a.mockResolvedValue(true);
668
+
669
+ // authVerifyMock.mockResolvedValue(true);
670
+ const mockEmbedEventPayload = {
671
+ type: EmbedEvent.AuthExpire,
672
+ data: {},
673
+ };
674
+ const searchEmbed = new SearchEmbed(getRootEl(), { ...defaultViewConfig, preRenderId: 'test' });
675
+ jest.spyOn(baseInstance, 'notifyAuthFailure');
676
+ searchEmbed.preRender();
677
+ const mockPort: any = {
678
+ postMessage: jest.fn(),
679
+ };
680
+ await executeAfterWait(() => {
681
+ const iframe = getIFrameEl();
682
+ postMessageToParent(iframe.contentWindow, mockEmbedEventPayload, mockPort);
683
+ });
684
+ const preRenderWrapper = document.getElementById('tsEmbed-pre-render-wrapper-test');
685
+ await executeAfterWait(() => {
686
+ expect(preRenderWrapper.innerHTML).toContain('Not logged in');
687
+ expect(baseInstance.notifyAuthFailure).toBeCalledWith(
688
+ authInstance.AuthFailureType.EXPIRY,
689
+ );
690
+ });
691
+
692
+ jest.spyOn(authService, 'verifyTokenService').mockClear();
693
+ jest.spyOn(baseInstance, 'notifyAuthFailure').mockClear();
694
+ });
695
+ });
696
+
565
697
  xdescribe('AuthExpire embedEvent in TrustedAuthToken authType', () => {
566
698
  test('AutoLogin true scenario', async () => {
567
699
  init({
@@ -8,7 +8,6 @@
8
8
  */
9
9
 
10
10
  import isEqual from 'lodash/isEqual';
11
-
12
11
  import { getAuthenticationToken } from '../authToken';
13
12
  import { AnswerService } from '../utils/graphql/answerService/answerService';
14
13
  import {
@@ -52,7 +51,7 @@ import {
52
51
  RuntimeFilter,
53
52
  } from '../types';
54
53
  import { uploadMixpanelEvent, MIXPANEL_EVENT } from '../mixpanel-service';
55
- import { processEventData } from '../utils/processData';
54
+ import { processEventData, processAuthFailure } from '../utils/processData';
56
55
  import { processTrigger } from '../utils/processTrigger';
57
56
  import pkgInfo from '../../package.json';
58
57
  import {
@@ -309,7 +308,12 @@ export class TsEmbed {
309
308
  private appInitCb = async (_: any, responder: any) => {
310
309
  let authToken = '';
311
310
  if (this.embedConfig.authType === AuthType.TrustedAuthTokenCookieless) {
312
- authToken = await getAuthenticationToken(this.embedConfig);
311
+ try {
312
+ authToken = await getAuthenticationToken(this.embedConfig);
313
+ } catch (e) {
314
+ processAuthFailure(e, this.isPreRendered ? this.preRenderWrapper : this.el);
315
+ return;
316
+ }
313
317
  }
314
318
  this.isAppInitialized = true;
315
319
  responder({
@@ -339,11 +343,16 @@ export class TsEmbed {
339
343
  private updateAuthToken = async (_: any, responder: any) => {
340
344
  const { autoLogin = false, authType } = this.embedConfig; // Set autoLogin default to false
341
345
  if (authType === AuthType.TrustedAuthTokenCookieless) {
342
- const authToken = await getAuthenticationToken(this.embedConfig);
343
- responder({
344
- type: EmbedEvent.AuthExpire,
345
- data: { authToken },
346
- });
346
+ let authToken = '';
347
+ try {
348
+ authToken = await getAuthenticationToken(this.embedConfig);
349
+ responder({
350
+ type: EmbedEvent.AuthExpire,
351
+ data: { authToken },
352
+ });
353
+ } catch (e) {
354
+ processAuthFailure(e, this.isPreRendered ? this.preRenderWrapper : this.el);
355
+ }
347
356
  } else if (autoLogin) {
348
357
  handleAuth();
349
358
  }
@@ -508,7 +517,11 @@ export class TsEmbed {
508
517
  const queryParams = this.shouldEncodeUrlQueryParams
509
518
  ? `?base64UrlEncodedFlags=${getEncodedQueryParamsString(queryString)}`
510
519
  : `?${queryString}`;
511
- const path = `${this.thoughtSpotHost}/${queryParams}#`;
520
+ let host = this.thoughtSpotHost;
521
+ if (!isUndefined(this.embedConfig.enableReactShell)) {
522
+ host = this.embedConfig.enableReactShell as boolean ? '/v2' : '/v1';
523
+ }
524
+ const path = `${host}/${queryParams}#`;
512
525
  return path;
513
526
  }
514
527
 
@@ -527,6 +540,7 @@ export class TsEmbed {
527
540
 
528
541
  iFrame.src = frameSrc;
529
542
  iFrame.id = TS_EMBED_ID;
543
+ iFrame.setAttribute('data-ts-iframe', 'true');
530
544
 
531
545
  // according to screenfull.js documentation
532
546
  // allowFullscreen, webkitallowfullscreen and mozallowfullscreen must be
@@ -969,6 +983,10 @@ export class TsEmbed {
969
983
  return this;
970
984
  }
971
985
 
986
+ public getIframeSrc(): string {
987
+ return '';
988
+ }
989
+
972
990
  protected handleRenderForPrerender() {
973
991
  this.render();
974
992
  }
@@ -1071,11 +1089,11 @@ export class TsEmbed {
1071
1089
  ) {
1072
1090
  console.warn(
1073
1091
  `${this.embedComponentType} was pre-rendered with `
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.',
1092
+ + `"${key}" as "${JSON.stringify(preRenderedObject.viewConfig[key])}" `
1093
+ + `but a different value "${JSON.stringify(viewConfig[key])}" `
1094
+ + 'was passed to the Embed component. '
1095
+ + 'The new value provided is ignored, the value provided during '
1096
+ + 'preRender is used.',
1079
1097
  );
1080
1098
  }
1081
1099
  });
@@ -199,35 +199,6 @@ describe('React Components', () => {
199
199
  ).toBe(true);
200
200
  expect(containerSibling.querySelector('div')).toBe(null);
201
201
  });
202
-
203
- it('Should have the correct container element', async () => {
204
- const { container } = render(
205
- <LiveboardEmbed liveboardId="abcd" className="def" />,
206
- );
207
-
208
- await waitFor(() => getIFrameEl(container));
209
- expect(container.querySelector('div')).not.toBe(null);
210
- expect(
211
- container.querySelector('div').classList.contains('def'),
212
- ).toBe(true);
213
-
214
- const { container: containerSibling } = render(
215
- <LiveboardEmbed
216
- liveboardId="abcd"
217
- className="def"
218
- insertAsSibling={true}
219
- />,
220
- );
221
- await waitFor(() => getIFrameEl(containerSibling));
222
- expect(containerSibling.querySelector('span')).not.toBe(null);
223
- expect(containerSibling.querySelector('span').style.position).toBe(
224
- 'absolute',
225
- );
226
- expect(
227
- getIFrameEl(containerSibling).classList.contains('def'),
228
- ).toBe(true);
229
- expect(containerSibling.querySelector('div')).toBe(null);
230
- });
231
202
  });
232
203
 
233
204
  describe('SearchBarEmbed', () => {