@thoughtspot/visual-embed-sdk 1.20.0-prerender.2 → 1.20.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (182) hide show
  1. package/README.md +1 -1
  2. package/dist/src/auth.d.ts +2 -38
  3. package/dist/src/auth.d.ts.map +1 -1
  4. package/dist/src/config.d.ts +0 -1
  5. package/dist/src/config.d.ts.map +1 -1
  6. package/dist/src/embed/app.d.ts +5 -17
  7. package/dist/src/embed/app.d.ts.map +1 -1
  8. package/dist/src/embed/base.d.ts +9 -20
  9. package/dist/src/embed/base.d.ts.map +1 -1
  10. package/dist/src/embed/liveboard.d.ts +5 -17
  11. package/dist/src/embed/liveboard.d.ts.map +1 -1
  12. package/dist/src/embed/search-bar.d.ts +0 -3
  13. package/dist/src/embed/search-bar.d.ts.map +1 -1
  14. package/dist/src/embed/search.d.ts +5 -9
  15. package/dist/src/embed/search.d.ts.map +1 -1
  16. package/dist/src/embed/ts-embed.d.ts +6 -43
  17. package/dist/src/embed/ts-embed.d.ts.map +1 -1
  18. package/dist/src/errors.d.ts.map +1 -1
  19. package/dist/src/index.d.ts.map +1 -1
  20. package/dist/src/mixpanel-service.d.ts +0 -8
  21. package/dist/src/mixpanel-service.d.ts.map +1 -1
  22. package/dist/src/react/index.d.ts.map +1 -1
  23. package/dist/src/react/util.d.ts +0 -4
  24. package/dist/src/react/util.d.ts.map +1 -1
  25. package/dist/src/test/test-utils.d.ts +2 -11
  26. package/dist/src/test/test-utils.d.ts.map +1 -1
  27. package/dist/src/types.d.ts +76 -273
  28. package/dist/src/types.d.ts.map +1 -1
  29. package/dist/src/utils/answerService.d.ts +0 -7
  30. package/dist/src/utils/answerService.d.ts.map +1 -1
  31. package/dist/src/utils/authService.d.ts +0 -30
  32. package/dist/src/utils/authService.d.ts.map +1 -1
  33. package/dist/src/utils/processData.d.ts +0 -12
  34. package/dist/src/utils/processData.d.ts.map +1 -1
  35. package/dist/src/utils/processTrigger.d.ts +0 -7
  36. package/dist/src/utils/processTrigger.d.ts.map +1 -1
  37. package/dist/src/utils.d.ts +0 -12
  38. package/dist/src/utils.d.ts.map +1 -1
  39. package/dist/tsembed.es.js +262 -637
  40. package/dist/tsembed.js +261 -629
  41. package/lib/package.json +8 -3
  42. package/lib/src/auth.d.ts +2 -38
  43. package/lib/src/auth.d.ts.map +1 -1
  44. package/lib/src/auth.js +25 -70
  45. package/lib/src/auth.js.map +1 -1
  46. package/lib/src/auth.spec.js +5 -14
  47. package/lib/src/auth.spec.js.map +1 -1
  48. package/lib/src/config.d.ts +0 -1
  49. package/lib/src/config.d.ts.map +1 -1
  50. package/lib/src/config.js +3 -5
  51. package/lib/src/config.js.map +1 -1
  52. package/lib/src/config.spec.js.map +1 -1
  53. package/lib/src/embed/app.d.ts +5 -17
  54. package/lib/src/embed/app.d.ts.map +1 -1
  55. package/lib/src/embed/app.js +15 -25
  56. package/lib/src/embed/app.js.map +1 -1
  57. package/lib/src/embed/app.spec.js +12 -12
  58. package/lib/src/embed/app.spec.js.map +1 -1
  59. package/lib/src/embed/base.d.ts +9 -20
  60. package/lib/src/embed/base.d.ts.map +1 -1
  61. package/lib/src/embed/base.js +15 -31
  62. package/lib/src/embed/base.js.map +1 -1
  63. package/lib/src/embed/base.spec.js.map +1 -1
  64. package/lib/src/embed/embed.spec.js +1 -1
  65. package/lib/src/embed/embed.spec.js.map +1 -1
  66. package/lib/src/embed/liveboard.d.ts +5 -17
  67. package/lib/src/embed/liveboard.d.ts.map +1 -1
  68. package/lib/src/embed/liveboard.js +37 -49
  69. package/lib/src/embed/liveboard.js.map +1 -1
  70. package/lib/src/embed/liveboard.spec.js +30 -37
  71. package/lib/src/embed/liveboard.spec.js.map +1 -1
  72. package/lib/src/embed/pinboard.spec.js +26 -14
  73. package/lib/src/embed/pinboard.spec.js.map +1 -1
  74. package/lib/src/embed/search-bar.d.ts +0 -3
  75. package/lib/src/embed/search-bar.d.ts.map +1 -1
  76. package/lib/src/embed/search-bar.js +6 -5
  77. package/lib/src/embed/search-bar.js.map +1 -1
  78. package/lib/src/embed/search.d.ts +5 -9
  79. package/lib/src/embed/search.d.ts.map +1 -1
  80. package/lib/src/embed/search.js +14 -18
  81. package/lib/src/embed/search.js.map +1 -1
  82. package/lib/src/embed/search.spec.js +19 -16
  83. package/lib/src/embed/search.spec.js.map +1 -1
  84. package/lib/src/embed/searchEmbed-basic-auth.spec.js +0 -4
  85. package/lib/src/embed/searchEmbed-basic-auth.spec.js.map +1 -1
  86. package/lib/src/embed/ts-embed.d.ts +6 -43
  87. package/lib/src/embed/ts-embed.d.ts.map +1 -1
  88. package/lib/src/embed/ts-embed.js +72 -117
  89. package/lib/src/embed/ts-embed.js.map +1 -1
  90. package/lib/src/embed/ts-embed.spec.js +24 -23
  91. package/lib/src/embed/ts-embed.spec.js.map +1 -1
  92. package/lib/src/errors.d.ts.map +1 -1
  93. package/lib/src/errors.js.map +1 -1
  94. package/lib/src/index.d.ts.map +1 -1
  95. package/lib/src/index.js +2 -2
  96. package/lib/src/index.js.map +1 -1
  97. package/lib/src/mixpanel-service.d.ts +0 -8
  98. package/lib/src/mixpanel-service.d.ts.map +1 -1
  99. package/lib/src/mixpanel-service.js +1 -13
  100. package/lib/src/mixpanel-service.js.map +1 -1
  101. package/lib/src/mixpanel-service.spec.js.map +1 -1
  102. package/lib/src/react/index.d.ts.map +1 -1
  103. package/lib/src/react/index.js +6 -6
  104. package/lib/src/react/index.js.map +1 -1
  105. package/lib/src/react/index.spec.js +6 -15
  106. package/lib/src/react/index.spec.js.map +1 -1
  107. package/lib/src/react/util.d.ts +0 -4
  108. package/lib/src/react/util.d.ts.map +1 -1
  109. package/lib/src/react/util.js +0 -4
  110. package/lib/src/react/util.js.map +1 -1
  111. package/lib/src/test/test-utils.d.ts +2 -11
  112. package/lib/src/test/test-utils.d.ts.map +1 -1
  113. package/lib/src/test/test-utils.js +25 -36
  114. package/lib/src/test/test-utils.js.map +1 -1
  115. package/lib/src/types.d.ts +76 -273
  116. package/lib/src/types.d.ts.map +1 -1
  117. package/lib/src/types.js +54 -200
  118. package/lib/src/types.js.map +1 -1
  119. package/lib/src/utils/answerService.d.ts +0 -7
  120. package/lib/src/utils/answerService.d.ts.map +1 -1
  121. package/lib/src/utils/answerService.js +0 -7
  122. package/lib/src/utils/answerService.js.map +1 -1
  123. package/lib/src/utils/answerService.spec.js.map +1 -1
  124. package/lib/src/utils/authService.d.ts +0 -30
  125. package/lib/src/utils/authService.d.ts.map +1 -1
  126. package/lib/src/utils/authService.js +2 -39
  127. package/lib/src/utils/authService.js.map +1 -1
  128. package/lib/src/utils/authService.spec.js.map +1 -1
  129. package/lib/src/utils/processData.d.ts +0 -12
  130. package/lib/src/utils/processData.d.ts.map +1 -1
  131. package/lib/src/utils/processData.js +5 -33
  132. package/lib/src/utils/processData.js.map +1 -1
  133. package/lib/src/utils/processData.spec.js.map +1 -1
  134. package/lib/src/utils/processTrigger.d.ts +0 -7
  135. package/lib/src/utils/processTrigger.d.ts.map +1 -1
  136. package/lib/src/utils/processTrigger.js +3 -17
  137. package/lib/src/utils/processTrigger.js.map +1 -1
  138. package/lib/src/utils/processTrigger.spec.js.map +1 -1
  139. package/lib/src/utils.d.ts +0 -12
  140. package/lib/src/utils.d.ts.map +1 -1
  141. package/lib/src/utils.js +19 -24
  142. package/lib/src/utils.js.map +1 -1
  143. package/lib/src/utils.spec.js.map +1 -1
  144. package/lib/src/visual-embed-sdk.d.ts +102 -406
  145. package/package.json +8 -3
  146. package/src/auth.spec.ts +150 -68
  147. package/src/auth.ts +108 -102
  148. package/src/config.spec.ts +4 -2
  149. package/src/config.ts +3 -5
  150. package/src/embed/app.spec.ts +14 -25
  151. package/src/embed/app.ts +35 -47
  152. package/src/embed/base.spec.ts +9 -3
  153. package/src/embed/base.ts +53 -51
  154. package/src/embed/embed.spec.ts +6 -5
  155. package/src/embed/liveboard.spec.ts +37 -56
  156. package/src/embed/liveboard.ts +64 -66
  157. package/src/embed/pinboard.spec.ts +29 -26
  158. package/src/embed/search-bar.tsx +8 -10
  159. package/src/embed/search.spec.ts +21 -31
  160. package/src/embed/search.ts +25 -26
  161. package/src/embed/searchEmbed-basic-auth.spec.ts +28 -22
  162. package/src/embed/ts-embed.spec.ts +148 -70
  163. package/src/embed/ts-embed.ts +157 -147
  164. package/src/errors.ts +6 -3
  165. package/src/index.ts +10 -4
  166. package/src/mixpanel-service.spec.ts +3 -1
  167. package/src/mixpanel-service.ts +1 -13
  168. package/src/react/index.spec.tsx +13 -37
  169. package/src/react/index.tsx +57 -38
  170. package/src/react/util.ts +4 -8
  171. package/src/test/test-utils.ts +39 -43
  172. package/src/types.ts +78 -270
  173. package/src/utils/answerService.spec.ts +5 -3
  174. package/src/utils/answerService.ts +17 -21
  175. package/src/utils/authService.spec.ts +41 -26
  176. package/src/utils/authService.ts +21 -47
  177. package/src/utils/processData.spec.ts +59 -26
  178. package/src/utils/processData.ts +14 -36
  179. package/src/utils/processTrigger.spec.ts +6 -1
  180. package/src/utils/processTrigger.ts +9 -18
  181. package/src/utils.spec.ts +12 -8
  182. package/src/utils.ts +26 -25
package/src/embed/app.ts CHANGED
@@ -11,7 +11,11 @@
11
11
 
12
12
  import { getFilterQuery, getQueryParamString } from '../utils';
13
13
  import {
14
- Param, RuntimeFilter, DOMSelector, HostEvent, ViewConfig,
14
+ Param,
15
+ RuntimeFilter,
16
+ DOMSelector,
17
+ HostEvent,
18
+ ViewConfig,
15
19
  } from '../types';
16
20
  import { V1Embed } from './ts-embed';
17
21
 
@@ -52,7 +56,6 @@ export enum Page {
52
56
 
53
57
  /**
54
58
  * The view configuration for full app embedding.
55
- *
56
59
  * @group Embed components
57
60
  */
58
61
  export interface AppViewConfig extends ViewConfig {
@@ -78,9 +81,8 @@ export interface AppViewConfig extends ViewConfig {
78
81
  */
79
82
  pageId?: Page;
80
83
  /**
81
- * This puts a filter tag on the application. All metadata lists in the
82
- * application, such as Liveboards and answers, would be filtered by this
83
- * tag.
84
+ * This puts a filter tag on the application. All metadata lists in the application, such as
85
+ * Liveboards and answers, would be filtered by this tag.
84
86
  */
85
87
  tag?: string;
86
88
  /**
@@ -90,14 +92,12 @@ export interface AppViewConfig extends ViewConfig {
90
92
  /**
91
93
  * Render liveboards using the new v2 rendering mode
92
94
  * This is a transient flag which is primarily meant for internal use
93
- *
94
95
  * @version SDK: 1.11.0 | ThoughtSpot: 8.3.0.cl, 8.4.1-sw
95
96
  * @hidden
96
97
  */
97
98
  liveboardV2?: boolean;
98
99
  /**
99
100
  * If set to true, the Search Assist feature is enabled.
100
- *
101
101
  * @version SDK: 1.13.0 | ThoughtSpot: 8.5.0.cl, 8.8.1-sw
102
102
  */
103
103
  enableSearchAssist?: boolean;
@@ -105,7 +105,6 @@ export interface AppViewConfig extends ViewConfig {
105
105
 
106
106
  /**
107
107
  * Embeds full ThoughtSpot experience in a host application.
108
- *
109
108
  * @group Embed components
110
109
  */
111
110
  export class AppEmbed extends V1Embed {
@@ -120,22 +119,9 @@ export class AppEmbed extends V1Embed {
120
119
  * Constructs a map of parameters to be passed on to the
121
120
  * embedded Liveboard or visualization.
122
121
  */
123
- protected getEmbedParams() {
124
- const {
125
- tag,
126
- hideObjects,
127
- liveboardV2,
128
- showPrimaryNavbar,
129
- disableProfileAndHelp,
130
- enableSearchAssist,
131
- } = this.viewConfig;
132
-
133
- let params = {};
134
- params[Param.EmbedApp] = true;
135
- params[Param.PrimaryNavHidden] = !showPrimaryNavbar;
136
- params[Param.HideProfleAndHelp] = !!disableProfileAndHelp;
137
-
138
- params = this.getBaseQueryParams(params);
122
+ private getEmbedParams() {
123
+ const params = this.getBaseQueryParams();
124
+ const { tag, hideObjects, liveboardV2 } = this.viewConfig;
139
125
 
140
126
  if (tag) {
141
127
  params[Param.Tag] = tag;
@@ -147,10 +133,6 @@ export class AppEmbed extends V1Embed {
147
133
  params[Param.LiveboardV2Enabled] = liveboardV2;
148
134
  }
149
135
 
150
- if (enableSearchAssist !== undefined) {
151
- params[Param.EnableSearchAssist] = enableSearchAssist;
152
- }
153
-
154
136
  const queryParams = getQueryParamString(params, true);
155
137
 
156
138
  return queryParams;
@@ -158,13 +140,21 @@ export class AppEmbed extends V1Embed {
158
140
 
159
141
  /**
160
142
  * Constructs the URL of the ThoughtSpot app page to be rendered.
161
- *
162
143
  * @param pageId The ID of the page to be embedded.
163
144
  */
164
- private getIFrameSrc() {
165
- const { pageId, path } = this.viewConfig;
166
- const pageRoute = this.formatPath(path) || this.getPageRoute(pageId);
167
- let url = `${this.getRootIframeSrc()}/${pageRoute}`;
145
+ private getIFrameSrc(pageId: string, runtimeFilters: RuntimeFilter[]) {
146
+ const filterQuery = getFilterQuery(runtimeFilters || []);
147
+ const queryParams = this.getEmbedParams();
148
+ const queryString = [filterQuery, queryParams]
149
+ .filter(Boolean)
150
+ .join('&');
151
+ let url = `${this.getV1EmbedBasePath(
152
+ queryString,
153
+ this.viewConfig.showPrimaryNavbar,
154
+ this.viewConfig.disableProfileAndHelp,
155
+ true,
156
+ this.viewConfig.enableSearchAssist,
157
+ )}/${pageId}`;
168
158
 
169
159
  const tsPostHashParams = this.getThoughtSpotPostUrlParams();
170
160
  url = `${url}${tsPostHashParams}`;
@@ -174,7 +164,6 @@ export class AppEmbed extends V1Embed {
174
164
 
175
165
  /**
176
166
  * Gets the ThoughtSpot route of the page for a particular page ID.
177
- *
178
167
  * @param pageId The identifier for a page in the ThoughtSpot app.
179
168
  */
180
169
  private getPageRoute(pageId: Page) {
@@ -199,7 +188,6 @@ export class AppEmbed extends V1Embed {
199
188
 
200
189
  /**
201
190
  * Formats the path provided by the user.
202
- *
203
191
  * @param path The URL path.
204
192
  * @returns The URL path that the embedded app understands.
205
193
  */
@@ -218,13 +206,10 @@ export class AppEmbed extends V1Embed {
218
206
 
219
207
  /**
220
208
  * Navigate to particular page for app embed. eg:answers/pinboards/home
221
- * This is used for embedding answers, pinboards, visualizations and full application
222
- * only.
223
- *
209
+ * This is used for embedding answers, pinboards, visualizations and full application only.
224
210
  * @param path string | number The string, set to iframe src and navigate to new page
225
211
  * eg: appEmbed.navigateToPage('pinboards')
226
- * When used with `noReload` (default: true) this can also be a number
227
- * like 1/-1 to go forward/back.
212
+ * When used with `noReload` this can also be a number like 1/-1 to go forward/back.
228
213
  * @param noReload boolean Trigger the navigation without reloading the page
229
214
  * @version SDK: 1.12.0 | ThoughtSpot: 8.4.0.cl, 8.4.1-sw
230
215
  */
@@ -237,28 +222,31 @@ export class AppEmbed extends V1Embed {
237
222
  this.trigger(HostEvent.Navigate, path);
238
223
  } else {
239
224
  if (typeof path !== 'string') {
240
- console.warn('Path can only by a string when triggered without noReload');
225
+ console.warn(
226
+ 'Path can only by a string when triggered without noReload',
227
+ );
241
228
  return;
242
229
  }
243
230
  const iframeSrc = this.iFrame.src;
244
231
  const embedPath = '#/embed';
245
232
  const currentPath = iframeSrc.includes(embedPath) ? embedPath : '#';
246
- this.iFrame.src = `${iframeSrc.split(currentPath)[0]}${currentPath}/${path.replace(
247
- /^\/?#?\//,
248
- '',
249
- )}`;
233
+ this.iFrame.src = `${
234
+ iframeSrc.split(currentPath)[0]
235
+ }${currentPath}/${path.replace(/^\/?#?\//, '')}`;
250
236
  }
251
237
  }
252
238
 
253
239
  /**
254
240
  * Renders the embedded application pages in the ThoughtSpot app.
255
- *
256
241
  * @param renderOptions An object containing the page ID
257
242
  * to be embedded.
258
243
  */
259
244
  public render(): AppEmbed {
260
245
  super.render();
261
- const src = this.getIFrameSrc();
246
+
247
+ const { pageId, runtimeFilters, path } = this.viewConfig;
248
+ const pageRoute = this.formatPath(path) || this.getPageRoute(pageId);
249
+ const src = this.getIFrameSrc(pageRoute, runtimeFilters);
262
250
  this.renderV1Embed(src);
263
251
 
264
252
  return this;
@@ -62,7 +62,9 @@ describe('Base TS Embed', () => {
62
62
  callPrefetch: true,
63
63
  });
64
64
  expect(getAllIframeEl().length).toBe(1);
65
- const prefetchIframe = document.querySelectorAll<HTMLIFrameElement>('.prefetchIframe');
65
+ const prefetchIframe = document.querySelectorAll<HTMLIFrameElement>(
66
+ '.prefetchIframe',
67
+ );
66
68
  expect(prefetchIframe.length).toBe(1);
67
69
  const firstIframe = <HTMLIFrameElement>prefetchIframe[0];
68
70
  expect(firstIframe.src).toBe(url);
@@ -77,7 +79,9 @@ describe('Base TS Embed', () => {
77
79
  index.PrefetchFeatures.LiveboardEmbed,
78
80
  ]);
79
81
  expect(getAllIframeEl().length).toBe(2);
80
- const prefetchIframe = document.querySelectorAll<HTMLIFrameElement>('.prefetchIframe');
82
+ const prefetchIframe = document.querySelectorAll<HTMLIFrameElement>(
83
+ '.prefetchIframe',
84
+ );
81
85
  expect(prefetchIframe.length).toBe(2);
82
86
  const firstIframe = <HTMLIFrameElement>prefetchIframe[0];
83
87
  expect(firstIframe.src).toBe(searchUrl);
@@ -89,7 +93,9 @@ describe('Base TS Embed', () => {
89
93
  const url = '';
90
94
  index.prefetch(url);
91
95
  expect(getAllIframeEl().length).toBe(0);
92
- const prefetchIframe = document.querySelectorAll<HTMLIFrameElement>('.prefetchIframe');
96
+ const prefetchIframe = document.querySelectorAll<HTMLIFrameElement>(
97
+ '.prefetchIframe',
98
+ );
93
99
  expect(prefetchIframe.length).toBe(0);
94
100
  });
95
101
 
package/src/embed/base.ts CHANGED
@@ -46,7 +46,10 @@ export const getEmbedConfig = (): EmbedConfig => config;
46
46
  export const getAuthPromise = (): Promise<boolean> => authPromise;
47
47
 
48
48
  export {
49
- notifyAuthFailure, notifyAuthSDKSuccess, notifyAuthSuccess, notifyLogout,
49
+ notifyAuthFailure,
50
+ notifyAuthSDKSuccess,
51
+ notifyAuthSuccess,
52
+ notifyLogout,
50
53
  };
51
54
 
52
55
  /**
@@ -77,16 +80,16 @@ const hostUrlToFeatureUrl = {
77
80
  };
78
81
 
79
82
  /**
80
- * Prefetches static resources from the specified URL. Web browsers can then cache the
81
- * prefetched resources and serve them from the user's local disk to provide faster access
82
- * to your app.
83
- *
83
+ * Prefetches static resources from the specified URL. Web browsers can then cache the prefetched resources and serve them from the user's local disk to provide faster access to your app.
84
84
  * @param url The URL provided for prefetch
85
85
  * @param prefetchFeatures Specify features which needs to be prefetched.
86
86
  * @version SDK: 1.4.0 | ThoughtSpot: ts7.sep.cl, 7.2.1
87
87
  * @group Global methods
88
88
  */
89
- export const prefetch = (url?: string, prefetchFeatures?: PrefetchFeatures[]): void => {
89
+ export const prefetch = (
90
+ url?: string,
91
+ prefetchFeatures?: PrefetchFeatures[],
92
+ ): void => {
90
93
  if (url === '') {
91
94
  // eslint-disable-next-line no-console
92
95
  console.warn('The prefetch method does not have a valid URL');
@@ -94,25 +97,21 @@ export const prefetch = (url?: string, prefetchFeatures?: PrefetchFeatures[]): v
94
97
  const features = prefetchFeatures || [PrefetchFeatures.FullApp];
95
98
  let hostUrl = url || config.thoughtSpotHost;
96
99
  hostUrl = hostUrl[hostUrl.length - 1] === '/' ? hostUrl : `${hostUrl}/`;
97
- uniq(features.map((feature) => hostUrlToFeatureUrl[feature](hostUrl))).forEach(
98
- (prefetchUrl, index) => {
99
- const iFrame = document.createElement('iframe');
100
- iFrame.src = prefetchUrl;
101
- iFrame.style.width = '0';
102
- iFrame.style.height = '0';
103
- iFrame.style.border = '0';
104
- iFrame.classList.add('prefetchIframe');
105
- iFrame.classList.add(`prefetchIframeNum-${index}`);
106
- document.body.appendChild(iFrame);
107
- },
108
- );
100
+ uniq(
101
+ features.map((feature) => hostUrlToFeatureUrl[feature](hostUrl)),
102
+ ).forEach((prefetchUrl, index) => {
103
+ const iFrame = document.createElement('iframe');
104
+ iFrame.src = prefetchUrl;
105
+ iFrame.style.width = '0';
106
+ iFrame.style.height = '0';
107
+ iFrame.style.border = '0';
108
+ iFrame.classList.add('prefetchIframe');
109
+ iFrame.classList.add(`prefetchIframeNum-${index}`);
110
+ document.body.appendChild(iFrame);
111
+ });
109
112
  }
110
113
  };
111
114
 
112
- /**
113
- *
114
- * @param embedConfig
115
- */
116
115
  function sanity(embedConfig: EmbedConfig) {
117
116
  if (embedConfig.thoughtSpotHost === undefined) {
118
117
  throw new Error('ThoughtSpot host not provided');
@@ -122,19 +121,23 @@ function sanity(embedConfig: EmbedConfig) {
122
121
  throw new Error('Username not provided with Trusted auth');
123
122
  }
124
123
 
125
- if (!embedConfig.authEndpoint && typeof embedConfig.getAuthToken !== 'function') {
126
- throw new Error('Trusted auth should provide either authEndpoint or getAuthToken');
124
+ if (
125
+ !embedConfig.authEndpoint &&
126
+ typeof embedConfig.getAuthToken !== 'function'
127
+ ) {
128
+ throw new Error(
129
+ 'Trusted auth should provide either authEndpoint or getAuthToken',
130
+ );
127
131
  }
128
132
  }
129
133
  }
130
134
 
131
- /**
132
- *
133
- * @param embedConfig
134
- */
135
135
  function backwardCompat(embedConfig: EmbedConfig): EmbedConfig {
136
136
  const newConfig = { ...embedConfig };
137
- if (embedConfig.noRedirect !== undefined && embedConfig.inPopup === undefined) {
137
+ if (
138
+ embedConfig.noRedirect !== undefined &&
139
+ embedConfig.inPopup === undefined
140
+ ) {
138
141
  newConfig.inPopup = embedConfig.noRedirect;
139
142
  }
140
143
  return newConfig;
@@ -143,9 +146,9 @@ function backwardCompat(embedConfig: EmbedConfig): EmbedConfig {
143
146
  /**
144
147
  * Initializes the Visual Embed SDK globally and perform
145
148
  * authentication if applicable.
146
- *
147
149
  * @param embedConfig The configuration object containing ThoughtSpot host,
148
150
  * authentication mechanism and so on.
151
+ *
149
152
  * @example
150
153
  * ```js
151
154
  * const authStatus = init({
@@ -154,8 +157,8 @@ function backwardCompat(embedConfig: EmbedConfig): EmbedConfig {
154
157
  * });
155
158
  * authStatus.on(AuthStatus.FAILURE, (reason) => { // do something here });
156
159
  * ```
157
- * @returns {@link AuthEventEmitter} event emitter which emits events on authentication success,
158
- * failure and logout. See {@link AuthStatus}
160
+ *
161
+ * @returns {@link AuthEventEmitter} event emitter which emits events on authentication success, failure and logout. See {@link AuthStatus}
159
162
  * @version SDK: 1.0.0 | ThoughtSpot ts7.april.cl, 7.2.1
160
163
  * @group Authentication / Init
161
164
  */
@@ -174,12 +177,17 @@ export const init = (embedConfig: EmbedConfig): AuthEventEmitter => {
174
177
  uploadMixpanelEvent(MIXPANEL_EVENT.VISUAL_SDK_CALLED_INIT, {
175
178
  authType: config.authType,
176
179
  host: config.thoughtSpotHost,
177
- usedCustomizationSheet: embedConfig.customizations?.style?.customCSSUrl != null,
178
- usedCustomizationVariables: embedConfig.customizations?.style?.customCSS?.variables != null,
180
+ usedCustomizationSheet:
181
+ embedConfig.customizations?.style?.customCSSUrl != null,
182
+ usedCustomizationVariables:
183
+ embedConfig.customizations?.style?.customCSS?.variables != null,
179
184
  usedCustomizationRules:
180
- embedConfig.customizations?.style?.customCSS?.rules_UNSTABLE != null,
181
- usedCustomizationStrings: !!embedConfig.customizations?.content?.strings,
182
- usedCustomizationIconSprite: !!embedConfig.customizations?.iconSpriteUrl,
185
+ embedConfig.customizations?.style?.customCSS?.rules_UNSTABLE !=
186
+ null,
187
+ usedCustomizationStrings: !!embedConfig.customizations?.content
188
+ ?.strings,
189
+ usedCustomizationIconSprite: !!embedConfig.customizations
190
+ ?.iconSpriteUrl,
183
191
  });
184
192
 
185
193
  if (config.callPrefetch) {
@@ -188,19 +196,16 @@ export const init = (embedConfig: EmbedConfig): AuthEventEmitter => {
188
196
  return authEE as AuthEventEmitter;
189
197
  };
190
198
 
191
- /**
192
- *
193
- */
194
199
  export function disableAutoLogin(): void {
195
200
  config.autoLogin = false;
196
201
  }
197
202
 
198
203
  /**
199
- * Logs out from ThoughtSpot. This also sets the autoLogin flag to false, to
200
- * prevent the SDK from automatically logging in again.
204
+ * Logs out from ThoughtSpot. This also sets the autoLogin flag to false, to prevent
205
+ * the SDK from automatically logging in again.
201
206
  *
202
- * You can call the `init` method again to re login, if autoLogin is set to
203
- * true in this second call it will be honored.
207
+ * You can call the `init` method again to re login, if autoLogin is set to true in this
208
+ * second call it will be honored.
204
209
  *
205
210
  * @param doNotDisableAutoLogin This flag when passed will not disable autoLogin
206
211
  * @returns Promise which resolves when logout completes.
@@ -220,12 +225,12 @@ export const logout = (doNotDisableAutoLogin = false): Promise<boolean> => {
220
225
  let renderQueue: Promise<any> = Promise.resolve();
221
226
 
222
227
  /**
223
- * Renders functions in a queue, resolves to next function only after the callback next
224
- * is called
225
- *
228
+ * Renders functions in a queue, resolves to next function only after the callback next is called
226
229
  * @param fn The function being registered
227
230
  */
228
- export const renderInQueue = (fn: (next?: (val?: any) => void) => Promise<any>): Promise<any> => {
231
+ export const renderInQueue = (
232
+ fn: (next?: (val?: any) => void) => Promise<any>,
233
+ ): Promise<any> => {
229
234
  const { queueMultiRenders = false } = config;
230
235
  if (queueMultiRenders) {
231
236
  renderQueue = renderQueue.then(() => new Promise((res) => fn(res)));
@@ -236,9 +241,6 @@ export const renderInQueue = (fn: (next?: (val?: any) => void) => Promise<any>):
236
241
  };
237
242
 
238
243
  // For testing purposes only
239
- /**
240
- *
241
- */
242
244
  export function reset(): void {
243
245
  config = {} as any;
244
246
  setAuthEE(null);
@@ -1,6 +1,4 @@
1
- import {
2
- init, AuthType, SearchEmbed, EmbedEvent,
3
- } from '../index';
1
+ import { init, AuthType, SearchEmbed, EmbedEvent } from '../index';
4
2
  import {
5
3
  EVENT_WAIT_TIME,
6
4
  executeAfterWait,
@@ -61,7 +59,8 @@ describe('test view config', () => {
61
59
  await executeAfterWait(() => {
62
60
  expect(onErrorSpy).toHaveBeenCalledWith(
63
61
  {
64
- error: 'Please register event handlers before calling render',
62
+ error:
63
+ 'Please register event handlers before calling render',
65
64
  },
66
65
  expect.any(Function),
67
66
  );
@@ -85,7 +84,9 @@ describe('Custom CSS Url', () => {
85
84
  embed.render();
86
85
  executeAfterWait(() => {
87
86
  const iframe = getIFrameEl();
88
- expect(iframe.src.includes('customCssUrl=bla.com/foo.css')).toBe(true);
87
+ expect(iframe.src.includes('customCssUrl=bla.com/foo.css')).toBe(
88
+ true,
89
+ );
89
90
  done();
90
91
  });
91
92
  });
@@ -15,10 +15,6 @@ import {
15
15
  getRootEl,
16
16
  defaultParams,
17
17
  defaultParamsWithoutHiddenActions,
18
- expectUrlMatchesWithParams,
19
- postMessageToParent,
20
- getIFrameEl,
21
- mockMessageChannel,
22
18
  } from '../test/test-utils';
23
19
  import { version } from '../../package.json';
24
20
  import * as processTriggerInstance from '../utils/processTrigger';
@@ -55,8 +51,7 @@ describe('Liveboard/viz embed tests', () => {
55
51
  } as LiveboardViewConfig);
56
52
  liveboardEmbed.render();
57
53
  await executeAfterWait(() => {
58
- expectUrlMatchesWithParams(
59
- getIFrameSrc(),
54
+ expect(getIFrameSrc()).toBe(
60
55
  `http://${thoughtSpotHost}/?embedApp=true${defaultParams}${prefixParams}#/embed/viz/${liveboardId}`,
61
56
  );
62
57
  });
@@ -64,15 +59,18 @@ describe('Liveboard/viz embed tests', () => {
64
59
 
65
60
  test('should set disabled actions', async () => {
66
61
  const liveboardEmbed = new LiveboardEmbed(getRootEl(), {
67
- disabledActions: [Action.DownloadAsCsv, Action.DownloadAsPdf, Action.DownloadAsXlsx],
62
+ disabledActions: [
63
+ Action.DownloadAsCsv,
64
+ Action.DownloadAsPdf,
65
+ Action.DownloadAsXlsx,
66
+ ],
68
67
  disabledActionReason: 'Action denied',
69
68
  ...defaultViewConfig,
70
69
  liveboardId,
71
70
  } as LiveboardViewConfig);
72
71
  liveboardEmbed.render();
73
72
  await executeAfterWait(() => {
74
- expectUrlMatchesWithParams(
75
- getIFrameSrc(),
73
+ expect(getIFrameSrc()).toBe(
76
74
  `http://${thoughtSpotHost}/?embedApp=true&${defaultParamsWithoutHiddenActions}&disableAction=[%22${Action.DownloadAsCsv}%22,%22${Action.DownloadAsPdf}%22,%22${Action.DownloadAsXlsx}%22]&disableHint=Action%20denied&hideAction=[%22${Action.ReportError}%22]${prefixParams}#/embed/viz/${liveboardId}`,
77
75
  );
78
76
  });
@@ -80,14 +78,17 @@ describe('Liveboard/viz embed tests', () => {
80
78
 
81
79
  test('should set hidden actions', async () => {
82
80
  const liveboardEmbed = new LiveboardEmbed(getRootEl(), {
83
- hiddenActions: [Action.DownloadAsCsv, Action.DownloadAsPdf, Action.DownloadAsXlsx],
81
+ hiddenActions: [
82
+ Action.DownloadAsCsv,
83
+ Action.DownloadAsPdf,
84
+ Action.DownloadAsXlsx,
85
+ ],
84
86
  ...defaultViewConfig,
85
87
  liveboardId,
86
88
  } as LiveboardViewConfig);
87
89
  liveboardEmbed.render();
88
90
  await executeAfterWait(() => {
89
- expectUrlMatchesWithParams(
90
- getIFrameSrc(),
91
+ expect(getIFrameSrc()).toBe(
91
92
  `http://${thoughtSpotHost}/?embedApp=true&${defaultParamsWithoutHiddenActions}&hideAction=[%22${Action.ReportError}%22,%22${Action.DownloadAsCsv}%22,%22${Action.DownloadAsPdf}%22,%22${Action.DownloadAsXlsx}%22]${prefixParams}#/embed/viz/${liveboardId}`,
92
93
  );
93
94
  });
@@ -95,14 +96,17 @@ describe('Liveboard/viz embed tests', () => {
95
96
 
96
97
  test('should set visible actions', async () => {
97
98
  const liveboardEmbed = new LiveboardEmbed(getRootEl(), {
98
- visibleActions: [Action.DownloadAsCsv, Action.DownloadAsPdf, Action.DownloadAsXlsx],
99
+ visibleActions: [
100
+ Action.DownloadAsCsv,
101
+ Action.DownloadAsPdf,
102
+ Action.DownloadAsXlsx,
103
+ ],
99
104
  ...defaultViewConfig,
100
105
  liveboardId,
101
106
  } as LiveboardViewConfig);
102
107
  liveboardEmbed.render();
103
108
  await executeAfterWait(() => {
104
- expectUrlMatchesWithParams(
105
- getIFrameSrc(),
109
+ expect(getIFrameSrc()).toBe(
106
110
  `http://${thoughtSpotHost}/?embedApp=true${defaultParams}&visibleAction=[%22${Action.DownloadAsCsv}%22,%22${Action.DownloadAsPdf}%22,%22${Action.DownloadAsXlsx}%22]${prefixParams}#/embed/viz/${liveboardId}`,
107
111
  );
108
112
  });
@@ -116,8 +120,7 @@ describe('Liveboard/viz embed tests', () => {
116
120
  } as LiveboardViewConfig);
117
121
  liveboardEmbed.render();
118
122
  await executeAfterWait(() => {
119
- expectUrlMatchesWithParams(
120
- getIFrameSrc(),
123
+ expect(getIFrameSrc()).toBe(
121
124
  `http://${thoughtSpotHost}/?embedApp=true${defaultParams}&visibleAction=[]${prefixParams}#/embed/viz/${liveboardId}`,
122
125
  );
123
126
  });
@@ -131,8 +134,7 @@ describe('Liveboard/viz embed tests', () => {
131
134
  } as LiveboardViewConfig);
132
135
  liveboardEmbed.render();
133
136
  await executeAfterWait(() => {
134
- expectUrlMatchesWithParams(
135
- getIFrameSrc(),
137
+ expect(getIFrameSrc()).toBe(
136
138
  `http://${thoughtSpotHost}/?embedApp=true${defaultParams}&enableVizTransform=true${prefixParams}#/embed/viz/${liveboardId}`,
137
139
  );
138
140
  });
@@ -146,8 +148,7 @@ describe('Liveboard/viz embed tests', () => {
146
148
  } as LiveboardViewConfig);
147
149
  liveboardEmbed.render();
148
150
  await executeAfterWait(() => {
149
- expectUrlMatchesWithParams(
150
- getIFrameSrc(),
151
+ expect(getIFrameSrc()).toBe(
151
152
  `http://${thoughtSpotHost}/?embedApp=true${defaultParams}&enableVizTransform=false${prefixParams}#/embed/viz/${liveboardId}`,
152
153
  );
153
154
  });
@@ -161,8 +162,7 @@ describe('Liveboard/viz embed tests', () => {
161
162
  } as LiveboardViewConfig);
162
163
  liveboardEmbed.render();
163
164
  await executeAfterWait(() => {
164
- expectUrlMatchesWithParams(
165
- getIFrameSrc(),
165
+ expect(getIFrameSrc()).toBe(
166
166
  `http://${thoughtSpotHost}/?embedApp=true${defaultParams}${prefixParamsVizEmbed}#/embed/viz/${liveboardId}/${vizId}`,
167
167
  );
168
168
  });
@@ -183,15 +183,13 @@ describe('Liveboard/viz embed tests', () => {
183
183
  } as LiveboardViewConfig);
184
184
  liveboardEmbed.render();
185
185
  await executeAfterWait(() => {
186
- expectUrlMatchesWithParams(
187
- getIFrameSrc(),
186
+ expect(getIFrameSrc()).toBe(
188
187
  `http://${thoughtSpotHost}/?embedApp=true&col1=sales&op1=EQ&val1=1000${defaultParams}${prefixParamsVizEmbed}#/embed/viz/${liveboardId}/${vizId}`,
189
188
  );
190
189
  });
191
190
  });
192
191
 
193
192
  test('should register event handler to adjust iframe height', async () => {
194
- const onSpy = jest.spyOn(LiveboardEmbed.prototype, 'on');
195
193
  const liveboardEmbed = new LiveboardEmbed(getRootEl(), {
196
194
  ...defaultViewConfig,
197
195
  fullHeight: true,
@@ -199,10 +197,14 @@ describe('Liveboard/viz embed tests', () => {
199
197
  vizId,
200
198
  } as LiveboardViewConfig);
201
199
 
200
+ const onSpy = jest.spyOn(liveboardEmbed, 'on');
202
201
  liveboardEmbed.render();
203
202
 
204
203
  executeAfterWait(() => {
205
- expect(onSpy).toHaveBeenCalledWith(EmbedEvent.EmbedHeight, expect.anything());
204
+ expect(onSpy).toHaveBeenCalledWith(
205
+ EmbedEvent.EmbedHeight,
206
+ expect.anything(),
207
+ );
206
208
  });
207
209
  });
208
210
  test('Should set the visible vizs', async () => {
@@ -213,14 +215,16 @@ describe('Liveboard/viz embed tests', () => {
213
215
  } as LiveboardViewConfig);
214
216
  liveboardEmbed.render();
215
217
  await executeAfterWait(() => {
216
- expectUrlMatchesWithParams(
217
- getIFrameSrc(),
218
+ expect(getIFrameSrc()).toBe(
218
219
  `http://${thoughtSpotHost}/?embedApp=true${defaultParams}&pinboardVisibleVizs=[%22abcd%22,%22pqrs%22]${prefixParams}#/embed/viz/${liveboardId}`,
219
220
  );
220
221
  });
221
222
  });
222
223
  test('should process the trigger, for vizEmbed', async () => {
223
- const mockProcessTrigger = spyOn(processTriggerInstance, 'processTrigger');
224
+ const mockProcessTrigger = spyOn(
225
+ processTriggerInstance,
226
+ 'processTrigger',
227
+ );
224
228
  const liveboardEmbed = new LiveboardEmbed(getRootEl(), {
225
229
  enableVizTransformations: true,
226
230
  ...defaultViewConfig,
@@ -240,8 +244,7 @@ describe('Liveboard/viz embed tests', () => {
240
244
  } as LiveboardViewConfig);
241
245
  liveboardEmbed.render();
242
246
  await executeAfterWait(() => {
243
- expectUrlMatchesWithParams(
244
- getIFrameSrc(),
247
+ expect(getIFrameSrc()).toBe(
245
248
  `http://${thoughtSpotHost}/?embedApp=true${defaultParams}&isLiveboardEmbed=true&isPinboardV2Enabled=true#/embed/viz/${liveboardId}/tab/${activeTabId}`,
246
249
  );
247
250
  });
@@ -256,8 +259,7 @@ describe('Liveboard/viz embed tests', () => {
256
259
  } as LiveboardViewConfig);
257
260
  liveboardEmbed.render();
258
261
  await executeAfterWait(() => {
259
- expectUrlMatchesWithParams(
260
- getIFrameSrc(),
262
+ expect(getIFrameSrc()).toBe(
261
263
  `http://${thoughtSpotHost}/?embedApp=true${defaultParams}&preventPinboardFilterRemoval=true&isLiveboardEmbed=true&isPinboardV2Enabled=true#/embed/viz/${liveboardId}/tab/${activeTabId}`,
262
264
  );
263
265
  });
@@ -271,30 +273,9 @@ describe('Liveboard/viz embed tests', () => {
271
273
  } as LiveboardViewConfig);
272
274
  liveboardEmbed.render();
273
275
  await executeAfterWait(() => {
274
- expectUrlMatchesWithParams(
275
- getIFrameSrc(),
276
+ expect(getIFrameSrc()).toBe(
276
277
  `http://${thoughtSpotHost}/?embedApp=true${defaultParams}&isContextMenuEnabledOnLeftClick=true&isLiveboardEmbed=true&isPinboardV2Enabled=true#/embed/viz/${liveboardId}/tab/${activeTabId}`,
277
278
  );
278
279
  });
279
280
  });
280
-
281
- test('navigateToLiveboard should trigger the navigate event with the correct path', (done) => {
282
- mockMessageChannel();
283
- const liveboardEmbed = new LiveboardEmbed(getRootEl(), {
284
- ...defaultViewConfig,
285
- } as LiveboardViewConfig);
286
- const onSpy = jest.spyOn(liveboardEmbed, 'trigger');
287
- liveboardEmbed.prerenderGeneric();
288
- executeAfterWait(() => {
289
- const iframe = getIFrameEl();
290
- postMessageToParent(iframe.contentWindow, {
291
- type: EmbedEvent.APP_INIT,
292
- });
293
- });
294
- executeAfterWait(() => {
295
- liveboardEmbed.navigateToLiveboard('lb1', 'viz1');
296
- expect(onSpy).toHaveBeenCalledWith(HostEvent.Navigate, '/embed/viz/lb1/viz1');
297
- done();
298
- });
299
- });
300
281
  });