@thoughtspot/visual-embed-sdk 1.20.0-alpha.2 → 1.20.0-prerender.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 (184) hide show
  1. package/dist/src/auth.d.ts +75 -5
  2. package/dist/src/auth.d.ts.map +1 -1
  3. package/dist/src/config.d.ts +1 -0
  4. package/dist/src/config.d.ts.map +1 -1
  5. package/dist/src/embed/app.d.ts +19 -7
  6. package/dist/src/embed/app.d.ts.map +1 -1
  7. package/dist/src/embed/base.d.ts +39 -19
  8. package/dist/src/embed/base.d.ts.map +1 -1
  9. package/dist/src/embed/liveboard.d.ts +19 -7
  10. package/dist/src/embed/liveboard.d.ts.map +1 -1
  11. package/dist/src/embed/search-bar.d.ts +7 -1
  12. package/dist/src/embed/search-bar.d.ts.map +1 -1
  13. package/dist/src/embed/search.d.ts +11 -3
  14. package/dist/src/embed/search.d.ts.map +1 -1
  15. package/dist/src/embed/ts-embed.d.ts +76 -5
  16. package/dist/src/embed/ts-embed.d.ts.map +1 -1
  17. package/dist/src/errors.d.ts.map +1 -1
  18. package/dist/src/index.d.ts +3 -3
  19. package/dist/src/index.d.ts.map +1 -1
  20. package/dist/src/mixpanel-service.d.ts +8 -0
  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 +4 -0
  24. package/dist/src/react/util.d.ts.map +1 -1
  25. package/dist/src/test/test-utils.d.ts +11 -2
  26. package/dist/src/test/test-utils.d.ts.map +1 -1
  27. package/dist/src/types.d.ts +429 -97
  28. package/dist/src/types.d.ts.map +1 -1
  29. package/dist/src/utils/answerService.d.ts +7 -0
  30. package/dist/src/utils/answerService.d.ts.map +1 -1
  31. package/dist/src/utils/authService.d.ts +30 -0
  32. package/dist/src/utils/authService.d.ts.map +1 -1
  33. package/dist/src/utils/processData.d.ts +12 -0
  34. package/dist/src/utils/processData.d.ts.map +1 -1
  35. package/dist/src/utils/processTrigger.d.ts +7 -0
  36. package/dist/src/utils/processTrigger.d.ts.map +1 -1
  37. package/dist/src/utils.d.ts +12 -0
  38. package/dist/src/utils.d.ts.map +1 -1
  39. package/dist/tsembed.es.js +818 -285
  40. package/dist/tsembed.js +791 -284
  41. package/lib/package.json +4 -3
  42. package/lib/src/auth.d.ts +75 -5
  43. package/lib/src/auth.d.ts.map +1 -1
  44. package/lib/src/auth.js +86 -26
  45. package/lib/src/auth.js.map +1 -1
  46. package/lib/src/auth.spec.js +14 -5
  47. package/lib/src/auth.spec.js.map +1 -1
  48. package/lib/src/config.d.ts +1 -0
  49. package/lib/src/config.d.ts.map +1 -1
  50. package/lib/src/config.js +5 -3
  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 +19 -7
  54. package/lib/src/embed/app.d.ts.map +1 -1
  55. package/lib/src/embed/app.js +26 -16
  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 +39 -19
  60. package/lib/src/embed/base.d.ts.map +1 -1
  61. package/lib/src/embed/base.js +49 -15
  62. package/lib/src/embed/base.js.map +1 -1
  63. package/lib/src/embed/base.spec.js +2 -2
  64. package/lib/src/embed/base.spec.js.map +1 -1
  65. package/lib/src/embed/embed.spec.js +1 -1
  66. package/lib/src/embed/embed.spec.js.map +1 -1
  67. package/lib/src/embed/liveboard.d.ts +19 -7
  68. package/lib/src/embed/liveboard.d.ts.map +1 -1
  69. package/lib/src/embed/liveboard.js +50 -38
  70. package/lib/src/embed/liveboard.js.map +1 -1
  71. package/lib/src/embed/liveboard.spec.js +37 -30
  72. package/lib/src/embed/liveboard.spec.js.map +1 -1
  73. package/lib/src/embed/pinboard.spec.js +14 -26
  74. package/lib/src/embed/pinboard.spec.js.map +1 -1
  75. package/lib/src/embed/search-bar.d.ts +7 -1
  76. package/lib/src/embed/search-bar.d.ts.map +1 -1
  77. package/lib/src/embed/search-bar.js +6 -7
  78. package/lib/src/embed/search-bar.js.map +1 -1
  79. package/lib/src/embed/search.d.ts +11 -3
  80. package/lib/src/embed/search.d.ts.map +1 -1
  81. package/lib/src/embed/search.js +19 -15
  82. package/lib/src/embed/search.js.map +1 -1
  83. package/lib/src/embed/search.spec.js +16 -19
  84. package/lib/src/embed/search.spec.js.map +1 -1
  85. package/lib/src/embed/searchEmbed-basic-auth.spec.js +4 -0
  86. package/lib/src/embed/searchEmbed-basic-auth.spec.js.map +1 -1
  87. package/lib/src/embed/ts-embed.d.ts +76 -5
  88. package/lib/src/embed/ts-embed.d.ts.map +1 -1
  89. package/lib/src/embed/ts-embed.js +150 -72
  90. package/lib/src/embed/ts-embed.js.map +1 -1
  91. package/lib/src/embed/ts-embed.spec.js +23 -24
  92. package/lib/src/embed/ts-embed.spec.js.map +1 -1
  93. package/lib/src/errors.d.ts.map +1 -1
  94. package/lib/src/errors.js.map +1 -1
  95. package/lib/src/index.d.ts +3 -3
  96. package/lib/src/index.d.ts.map +1 -1
  97. package/lib/src/index.js +3 -3
  98. package/lib/src/index.js.map +1 -1
  99. package/lib/src/mixpanel-service.d.ts +8 -0
  100. package/lib/src/mixpanel-service.d.ts.map +1 -1
  101. package/lib/src/mixpanel-service.js +13 -1
  102. package/lib/src/mixpanel-service.js.map +1 -1
  103. package/lib/src/mixpanel-service.spec.js.map +1 -1
  104. package/lib/src/react/index.d.ts.map +1 -1
  105. package/lib/src/react/index.js +4 -6
  106. package/lib/src/react/index.js.map +1 -1
  107. package/lib/src/react/index.spec.js +3 -6
  108. package/lib/src/react/index.spec.js.map +1 -1
  109. package/lib/src/react/util.d.ts +4 -0
  110. package/lib/src/react/util.d.ts.map +1 -1
  111. package/lib/src/react/util.js +4 -0
  112. package/lib/src/react/util.js.map +1 -1
  113. package/lib/src/test/test-utils.d.ts +11 -2
  114. package/lib/src/test/test-utils.d.ts.map +1 -1
  115. package/lib/src/test/test-utils.js +36 -25
  116. package/lib/src/test/test-utils.js.map +1 -1
  117. package/lib/src/types.d.ts +429 -97
  118. package/lib/src/types.d.ts.map +1 -1
  119. package/lib/src/types.js +310 -72
  120. package/lib/src/types.js.map +1 -1
  121. package/lib/src/utils/answerService.d.ts +7 -0
  122. package/lib/src/utils/answerService.d.ts.map +1 -1
  123. package/lib/src/utils/answerService.js +7 -0
  124. package/lib/src/utils/answerService.js.map +1 -1
  125. package/lib/src/utils/answerService.spec.js.map +1 -1
  126. package/lib/src/utils/authService.d.ts +30 -0
  127. package/lib/src/utils/authService.d.ts.map +1 -1
  128. package/lib/src/utils/authService.js +39 -2
  129. package/lib/src/utils/authService.js.map +1 -1
  130. package/lib/src/utils/authService.spec.js.map +1 -1
  131. package/lib/src/utils/processData.d.ts +12 -0
  132. package/lib/src/utils/processData.d.ts.map +1 -1
  133. package/lib/src/utils/processData.js +33 -5
  134. package/lib/src/utils/processData.js.map +1 -1
  135. package/lib/src/utils/processData.spec.js.map +1 -1
  136. package/lib/src/utils/processTrigger.d.ts +7 -0
  137. package/lib/src/utils/processTrigger.d.ts.map +1 -1
  138. package/lib/src/utils/processTrigger.js +17 -3
  139. package/lib/src/utils/processTrigger.js.map +1 -1
  140. package/lib/src/utils/processTrigger.spec.js.map +1 -1
  141. package/lib/src/utils.d.ts +12 -0
  142. package/lib/src/utils.d.ts.map +1 -1
  143. package/lib/src/utils.js +24 -19
  144. package/lib/src/utils.js.map +1 -1
  145. package/lib/src/utils.spec.js.map +1 -1
  146. package/lib/src/visual-embed-sdk.d.ts +664 -141
  147. package/package.json +4 -3
  148. package/src/auth.spec.ts +68 -150
  149. package/src/auth.ts +141 -101
  150. package/src/config.spec.ts +2 -4
  151. package/src/config.ts +5 -3
  152. package/src/embed/app.spec.ts +25 -14
  153. package/src/embed/app.ts +49 -37
  154. package/src/embed/base.spec.ts +6 -12
  155. package/src/embed/base.ts +74 -57
  156. package/src/embed/embed.spec.ts +5 -6
  157. package/src/embed/liveboard.spec.ts +56 -37
  158. package/src/embed/liveboard.ts +67 -65
  159. package/src/embed/pinboard.spec.ts +26 -29
  160. package/src/embed/search-bar.tsx +14 -9
  161. package/src/embed/search.spec.ts +31 -21
  162. package/src/embed/search.ts +28 -22
  163. package/src/embed/searchEmbed-basic-auth.spec.ts +22 -28
  164. package/src/embed/ts-embed.spec.ts +70 -148
  165. package/src/embed/ts-embed.ts +180 -157
  166. package/src/errors.ts +3 -6
  167. package/src/index.ts +23 -7
  168. package/src/mixpanel-service.spec.ts +1 -3
  169. package/src/mixpanel-service.ts +13 -1
  170. package/src/react/index.spec.tsx +11 -20
  171. package/src/react/index.tsx +40 -71
  172. package/src/react/util.ts +8 -4
  173. package/src/test/test-utils.ts +43 -39
  174. package/src/types.ts +427 -97
  175. package/src/utils/answerService.spec.ts +3 -5
  176. package/src/utils/answerService.ts +21 -17
  177. package/src/utils/authService.spec.ts +26 -41
  178. package/src/utils/authService.ts +47 -21
  179. package/src/utils/processData.spec.ts +26 -59
  180. package/src/utils/processData.ts +36 -14
  181. package/src/utils/processTrigger.spec.ts +1 -6
  182. package/src/utils/processTrigger.ts +18 -9
  183. package/src/utils.spec.ts +8 -12
  184. package/src/utils.ts +25 -26
package/src/embed/app.ts CHANGED
@@ -11,11 +11,7 @@
11
11
 
12
12
  import { getFilterQuery, getQueryParamString } from '../utils';
13
13
  import {
14
- Param,
15
- RuntimeFilter,
16
- DOMSelector,
17
- HostEvent,
18
- ViewConfig,
14
+ Param, RuntimeFilter, DOMSelector, HostEvent, ViewConfig,
19
15
  } from '../types';
20
16
  import { V1Embed } from './ts-embed';
21
17
 
@@ -56,7 +52,8 @@ export enum Page {
56
52
 
57
53
  /**
58
54
  * The view configuration for full app embedding.
59
- * @Category App Embed
55
+ *
56
+ * @group Embed components
60
57
  */
61
58
  export interface AppViewConfig extends ViewConfig {
62
59
  /**
@@ -81,8 +78,9 @@ export interface AppViewConfig extends ViewConfig {
81
78
  */
82
79
  pageId?: Page;
83
80
  /**
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.
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.
86
84
  */
87
85
  tag?: string;
88
86
  /**
@@ -92,12 +90,14 @@ export interface AppViewConfig extends ViewConfig {
92
90
  /**
93
91
  * Render liveboards using the new v2 rendering mode
94
92
  * This is a transient flag which is primarily meant for internal use
93
+ *
95
94
  * @version SDK: 1.11.0 | ThoughtSpot: 8.3.0.cl, 8.4.1-sw
96
95
  * @hidden
97
96
  */
98
97
  liveboardV2?: boolean;
99
98
  /**
100
99
  * 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,8 @@ export interface AppViewConfig extends ViewConfig {
105
105
 
106
106
  /**
107
107
  * Embeds full ThoughtSpot experience in a host application.
108
- * @Category App Embed
108
+ *
109
+ * @group Embed components
109
110
  */
110
111
  export class AppEmbed extends V1Embed {
111
112
  protected viewConfig: AppViewConfig;
@@ -119,9 +120,22 @@ export class AppEmbed extends V1Embed {
119
120
  * Constructs a map of parameters to be passed on to the
120
121
  * embedded Liveboard or visualization.
121
122
  */
122
- private getEmbedParams() {
123
- const params = this.getBaseQueryParams();
124
- const { tag, hideObjects, liveboardV2 } = this.viewConfig;
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);
125
139
 
126
140
  if (tag) {
127
141
  params[Param.Tag] = tag;
@@ -133,6 +147,10 @@ export class AppEmbed extends V1Embed {
133
147
  params[Param.LiveboardV2Enabled] = liveboardV2;
134
148
  }
135
149
 
150
+ if (enableSearchAssist !== undefined) {
151
+ params[Param.EnableSearchAssist] = enableSearchAssist;
152
+ }
153
+
136
154
  const queryParams = getQueryParamString(params, true);
137
155
 
138
156
  return queryParams;
@@ -140,21 +158,13 @@ export class AppEmbed extends V1Embed {
140
158
 
141
159
  /**
142
160
  * Constructs the URL of the ThoughtSpot app page to be rendered.
161
+ *
143
162
  * @param pageId The ID of the page to be embedded.
144
163
  */
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}`;
164
+ private getIFrameSrc() {
165
+ const { pageId, path } = this.viewConfig;
166
+ const pageRoute = this.formatPath(path) || this.getPageRoute(pageId);
167
+ let url = `${this.getRootIframeSrc()}/${pageRoute}`;
158
168
 
159
169
  const tsPostHashParams = this.getThoughtSpotPostUrlParams();
160
170
  url = `${url}${tsPostHashParams}`;
@@ -164,6 +174,7 @@ export class AppEmbed extends V1Embed {
164
174
 
165
175
  /**
166
176
  * Gets the ThoughtSpot route of the page for a particular page ID.
177
+ *
167
178
  * @param pageId The identifier for a page in the ThoughtSpot app.
168
179
  */
169
180
  private getPageRoute(pageId: Page) {
@@ -188,6 +199,7 @@ export class AppEmbed extends V1Embed {
188
199
 
189
200
  /**
190
201
  * Formats the path provided by the user.
202
+ *
191
203
  * @param path The URL path.
192
204
  * @returns The URL path that the embedded app understands.
193
205
  */
@@ -206,10 +218,13 @@ export class AppEmbed extends V1Embed {
206
218
 
207
219
  /**
208
220
  * Navigate to particular page for app embed. eg:answers/pinboards/home
209
- * This is used for embedding answers, pinboards, visualizations and full application only.
221
+ * This is used for embedding answers, pinboards, visualizations and full application
222
+ * only.
223
+ *
210
224
  * @param path string | number The string, set to iframe src and navigate to new page
211
225
  * eg: appEmbed.navigateToPage('pinboards')
212
- * When used with `noReload` this can also be a number like 1/-1 to go forward/back.
226
+ * When used with `noReload` (default: true) this can also be a number
227
+ * like 1/-1 to go forward/back.
213
228
  * @param noReload boolean Trigger the navigation without reloading the page
214
229
  * @version SDK: 1.12.0 | ThoughtSpot: 8.4.0.cl, 8.4.1-sw
215
230
  */
@@ -222,31 +237,28 @@ export class AppEmbed extends V1Embed {
222
237
  this.trigger(HostEvent.Navigate, path);
223
238
  } else {
224
239
  if (typeof path !== 'string') {
225
- console.warn(
226
- 'Path can only by a string when triggered without noReload',
227
- );
240
+ console.warn('Path can only by a string when triggered without noReload');
228
241
  return;
229
242
  }
230
243
  const iframeSrc = this.iFrame.src;
231
244
  const embedPath = '#/embed';
232
245
  const currentPath = iframeSrc.includes(embedPath) ? embedPath : '#';
233
- this.iFrame.src = `${
234
- iframeSrc.split(currentPath)[0]
235
- }${currentPath}/${path.replace(/^\/?#?\//, '')}`;
246
+ this.iFrame.src = `${iframeSrc.split(currentPath)[0]}${currentPath}/${path.replace(
247
+ /^\/?#?\//,
248
+ '',
249
+ )}`;
236
250
  }
237
251
  }
238
252
 
239
253
  /**
240
254
  * Renders the embedded application pages in the ThoughtSpot app.
255
+ *
241
256
  * @param renderOptions An object containing the page ID
242
257
  * to be embedded.
243
258
  */
244
259
  public render(): AppEmbed {
245
260
  super.render();
246
-
247
- const { pageId, runtimeFilters, path } = this.viewConfig;
248
- const pageRoute = this.formatPath(path) || this.getPageRoute(pageId);
249
- const src = this.getIFrameSrc(pageRoute, runtimeFilters);
261
+ const src = this.getIFrameSrc();
250
262
  this.renderV1Embed(src);
251
263
 
252
264
  return this;
@@ -20,7 +20,7 @@ describe('Base TS Embed', () => {
20
20
  authEE = index.init({
21
21
  thoughtSpotHost,
22
22
  authType: index.AuthType.None,
23
- });
23
+ }) as EventEmitter;
24
24
  });
25
25
 
26
26
  beforeEach(() => {
@@ -62,9 +62,7 @@ describe('Base TS Embed', () => {
62
62
  callPrefetch: true,
63
63
  });
64
64
  expect(getAllIframeEl().length).toBe(1);
65
- const prefetchIframe = document.querySelectorAll<HTMLIFrameElement>(
66
- '.prefetchIframe',
67
- );
65
+ const prefetchIframe = document.querySelectorAll<HTMLIFrameElement>('.prefetchIframe');
68
66
  expect(prefetchIframe.length).toBe(1);
69
67
  const firstIframe = <HTMLIFrameElement>prefetchIframe[0];
70
68
  expect(firstIframe.src).toBe(url);
@@ -79,9 +77,7 @@ describe('Base TS Embed', () => {
79
77
  index.PrefetchFeatures.LiveboardEmbed,
80
78
  ]);
81
79
  expect(getAllIframeEl().length).toBe(2);
82
- const prefetchIframe = document.querySelectorAll<HTMLIFrameElement>(
83
- '.prefetchIframe',
84
- );
80
+ const prefetchIframe = document.querySelectorAll<HTMLIFrameElement>('.prefetchIframe');
85
81
  expect(prefetchIframe.length).toBe(2);
86
82
  const firstIframe = <HTMLIFrameElement>prefetchIframe[0];
87
83
  expect(firstIframe.src).toBe(searchUrl);
@@ -93,9 +89,7 @@ describe('Base TS Embed', () => {
93
89
  const url = '';
94
90
  index.prefetch(url);
95
91
  expect(getAllIframeEl().length).toBe(0);
96
- const prefetchIframe = document.querySelectorAll<HTMLIFrameElement>(
97
- '.prefetchIframe',
98
- );
92
+ const prefetchIframe = document.querySelectorAll<HTMLIFrameElement>('.prefetchIframe');
99
93
  expect(prefetchIframe.length).toBe(0);
100
94
  });
101
95
 
@@ -148,9 +142,9 @@ describe('Base TS Embed', () => {
148
142
  });
149
143
 
150
144
  authEmitter.on(auth.AuthStatus.FAILURE, failureCallback);
151
- authEmitter.on(auth.AuthStatus.SDK_SUCCESS, (reason) => {
145
+ authEmitter.on(auth.AuthStatus.SDK_SUCCESS, (...args) => {
152
146
  expect(failureCallback).not.toBeCalled();
153
- expect(reason).toBe(undefined);
147
+ expect(args.length).toBe(0);
154
148
  done();
155
149
  });
156
150
  });
package/src/embed/base.ts CHANGED
@@ -16,11 +16,13 @@ import {
16
16
  logout as _logout,
17
17
  AuthFailureType,
18
18
  AuthStatus,
19
+ AuthEvent,
19
20
  notifyAuthFailure,
20
21
  notifyAuthSDKSuccess,
21
22
  notifyAuthSuccess,
22
23
  notifyLogout,
23
24
  setAuthEE,
25
+ AuthEventEmitter,
24
26
  } from '../auth';
25
27
  import { uploadMixpanelEvent, MIXPANEL_EVENT } from '../mixpanel-service';
26
28
 
@@ -32,16 +34,19 @@ const CONFIG_DEFAULTS: Partial<EmbedConfig> = {
32
34
  };
33
35
 
34
36
  export let authPromise: Promise<boolean>;
35
-
37
+ /**
38
+ * Gets the configuration embed was initialized with.
39
+ *
40
+ * @returns {@link EmbedConfig} The configuration embed was initialized with.
41
+ * @version SDK: 1.19.0 | ThoughtSpot: *
42
+ * @group Global methods
43
+ */
36
44
  export const getEmbedConfig = (): EmbedConfig => config;
37
45
 
38
46
  export const getAuthPromise = (): Promise<boolean> => authPromise;
39
47
 
40
48
  export {
41
- notifyAuthFailure,
42
- notifyAuthSDKSuccess,
43
- notifyAuthSuccess,
44
- notifyLogout,
49
+ notifyAuthFailure, notifyAuthSDKSuccess, notifyAuthSuccess, notifyLogout,
45
50
  };
46
51
 
47
52
  /**
@@ -72,15 +77,16 @@ const hostUrlToFeatureUrl = {
72
77
  };
73
78
 
74
79
  /**
75
- * 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.
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
+ *
76
84
  * @param url The URL provided for prefetch
77
85
  * @param prefetchFeatures Specify features which needs to be prefetched.
78
86
  * @version SDK: 1.4.0 | ThoughtSpot: ts7.sep.cl, 7.2.1
87
+ * @group Global methods
79
88
  */
80
- export const prefetch = (
81
- url?: string,
82
- prefetchFeatures?: PrefetchFeatures[],
83
- ): void => {
89
+ export const prefetch = (url?: string, prefetchFeatures?: PrefetchFeatures[]): void => {
84
90
  if (url === '') {
85
91
  // eslint-disable-next-line no-console
86
92
  console.warn('The prefetch method does not have a valid URL');
@@ -88,21 +94,25 @@ export const prefetch = (
88
94
  const features = prefetchFeatures || [PrefetchFeatures.FullApp];
89
95
  let hostUrl = url || config.thoughtSpotHost;
90
96
  hostUrl = hostUrl[hostUrl.length - 1] === '/' ? hostUrl : `${hostUrl}/`;
91
- uniq(
92
- features.map((feature) => hostUrlToFeatureUrl[feature](hostUrl)),
93
- ).forEach((prefetchUrl, index) => {
94
- const iFrame = document.createElement('iframe');
95
- iFrame.src = prefetchUrl;
96
- iFrame.style.width = '0';
97
- iFrame.style.height = '0';
98
- iFrame.style.border = '0';
99
- iFrame.classList.add('prefetchIframe');
100
- iFrame.classList.add(`prefetchIframeNum-${index}`);
101
- document.body.appendChild(iFrame);
102
- });
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
+ );
103
109
  }
104
110
  };
105
111
 
112
+ /**
113
+ *
114
+ * @param embedConfig
115
+ */
106
116
  function sanity(embedConfig: EmbedConfig) {
107
117
  if (embedConfig.thoughtSpotHost === undefined) {
108
118
  throw new Error('ThoughtSpot host not provided');
@@ -112,23 +122,19 @@ function sanity(embedConfig: EmbedConfig) {
112
122
  throw new Error('Username not provided with Trusted auth');
113
123
  }
114
124
 
115
- if (
116
- !embedConfig.authEndpoint &&
117
- typeof embedConfig.getAuthToken !== 'function'
118
- ) {
119
- throw new Error(
120
- 'Trusted auth should provide either authEndpoint or getAuthToken',
121
- );
125
+ if (!embedConfig.authEndpoint && typeof embedConfig.getAuthToken !== 'function') {
126
+ throw new Error('Trusted auth should provide either authEndpoint or getAuthToken');
122
127
  }
123
128
  }
124
129
  }
125
130
 
131
+ /**
132
+ *
133
+ * @param embedConfig
134
+ */
126
135
  function backwardCompat(embedConfig: EmbedConfig): EmbedConfig {
127
136
  const newConfig = { ...embedConfig };
128
- if (
129
- embedConfig.noRedirect !== undefined &&
130
- embedConfig.inPopup === undefined
131
- ) {
137
+ if (embedConfig.noRedirect !== undefined && embedConfig.inPopup === undefined) {
132
138
  newConfig.inPopup = embedConfig.noRedirect;
133
139
  }
134
140
  return newConfig;
@@ -137,14 +143,23 @@ function backwardCompat(embedConfig: EmbedConfig): EmbedConfig {
137
143
  /**
138
144
  * Initializes the Visual Embed SDK globally and perform
139
145
  * authentication if applicable.
146
+ *
140
147
  * @param embedConfig The configuration object containing ThoughtSpot host,
141
148
  * authentication mechanism and so on.
142
- * example: authStatus = init(config);
143
- * authStatus.on(AuthStatus.FAILURE, (reason) => { // do something here });
144
- * @returns event emitter which emits events on authentication success, failure and logout. See {@link AuthStatus}
149
+ * @example
150
+ * ```js
151
+ * const authStatus = init({
152
+ * thoughtSpotHost: 'https://my.thoughtspot.cloud',
153
+ * authType: AuthType.None,
154
+ * });
155
+ * authStatus.on(AuthStatus.FAILURE, (reason) => { // do something here });
156
+ * ```
157
+ * @returns {@link AuthEventEmitter} event emitter which emits events on authentication success,
158
+ * failure and logout. See {@link AuthStatus}
145
159
  * @version SDK: 1.0.0 | ThoughtSpot ts7.april.cl, 7.2.1
160
+ * @group Authentication / Init
146
161
  */
147
- export const init = (embedConfig: EmbedConfig): EventEmitter => {
162
+ export const init = (embedConfig: EmbedConfig): AuthEventEmitter => {
148
163
  sanity(embedConfig);
149
164
  config = {
150
165
  ...CONFIG_DEFAULTS,
@@ -152,46 +167,45 @@ export const init = (embedConfig: EmbedConfig): EventEmitter => {
152
167
  thoughtSpotHost: getThoughtSpotHost(embedConfig),
153
168
  };
154
169
  config = backwardCompat(config);
155
- const authEE = new EventEmitter();
170
+ const authEE = new EventEmitter<AuthStatus | AuthEvent>();
156
171
  setAuthEE(authEE);
157
172
  handleAuth();
158
173
 
159
174
  uploadMixpanelEvent(MIXPANEL_EVENT.VISUAL_SDK_CALLED_INIT, {
160
175
  authType: config.authType,
161
176
  host: config.thoughtSpotHost,
162
- usedCustomizationSheet:
163
- embedConfig.customizations?.style?.customCSSUrl != null,
164
- usedCustomizationVariables:
165
- embedConfig.customizations?.style?.customCSS?.variables != null,
177
+ usedCustomizationSheet: embedConfig.customizations?.style?.customCSSUrl != null,
178
+ usedCustomizationVariables: embedConfig.customizations?.style?.customCSS?.variables != null,
166
179
  usedCustomizationRules:
167
- embedConfig.customizations?.style?.customCSS?.rules_UNSTABLE !=
168
- null,
169
- usedCustomizationStrings: !!embedConfig.customizations?.content
170
- ?.strings,
171
- usedCustomizationIconSprite: !!embedConfig.customizations
172
- ?.iconSpriteUrl,
180
+ embedConfig.customizations?.style?.customCSS?.rules_UNSTABLE != null,
181
+ usedCustomizationStrings: !!embedConfig.customizations?.content?.strings,
182
+ usedCustomizationIconSprite: !!embedConfig.customizations?.iconSpriteUrl,
173
183
  });
174
184
 
175
185
  if (config.callPrefetch) {
176
186
  prefetch(config.thoughtSpotHost);
177
187
  }
178
- return authEE;
188
+ return authEE as AuthEventEmitter;
179
189
  };
180
190
 
191
+ /**
192
+ *
193
+ */
181
194
  export function disableAutoLogin(): void {
182
195
  config.autoLogin = false;
183
196
  }
184
197
 
185
198
  /**
186
- * Logs out from ThoughtSpot. This also sets the autoLogin flag to false, to prevent
187
- * the SDK from automatically logging in again.
199
+ * Logs out from ThoughtSpot. This also sets the autoLogin flag to false, to
200
+ * prevent the SDK from automatically logging in again.
188
201
  *
189
- * You can call the `init` method again to re login, if autoLogin is set to true in this
190
- * second call it will be honored.
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.
191
204
  *
192
205
  * @param doNotDisableAutoLogin This flag when passed will not disable autoLogin
193
206
  * @returns Promise which resolves when logout completes.
194
207
  * @version SDK: 1.10.1 | ThoughtSpot: 8.2.0.cl, 8.4.1-sw
208
+ * @group Global methods
195
209
  */
196
210
  export const logout = (doNotDisableAutoLogin = false): Promise<boolean> => {
197
211
  if (!doNotDisableAutoLogin) {
@@ -206,12 +220,12 @@ export const logout = (doNotDisableAutoLogin = false): Promise<boolean> => {
206
220
  let renderQueue: Promise<any> = Promise.resolve();
207
221
 
208
222
  /**
209
- * Renders functions in a queue, resolves to next function only after the callback next is called
223
+ * Renders functions in a queue, resolves to next function only after the callback next
224
+ * is called
225
+ *
210
226
  * @param fn The function being registered
211
227
  */
212
- export const renderInQueue = (
213
- fn: (next?: (val?: any) => void) => Promise<any>,
214
- ): Promise<any> => {
228
+ export const renderInQueue = (fn: (next?: (val?: any) => void) => Promise<any>): Promise<any> => {
215
229
  const { queueMultiRenders = false } = config;
216
230
  if (queueMultiRenders) {
217
231
  renderQueue = renderQueue.then(() => new Promise((res) => fn(res)));
@@ -222,6 +236,9 @@ export const renderInQueue = (
222
236
  };
223
237
 
224
238
  // For testing purposes only
239
+ /**
240
+ *
241
+ */
225
242
  export function reset(): void {
226
243
  config = {} as any;
227
244
  setAuthEE(null);
@@ -1,4 +1,6 @@
1
- import { init, AuthType, SearchEmbed, EmbedEvent } from '../index';
1
+ import {
2
+ init, AuthType, SearchEmbed, EmbedEvent,
3
+ } from '../index';
2
4
  import {
3
5
  EVENT_WAIT_TIME,
4
6
  executeAfterWait,
@@ -59,8 +61,7 @@ describe('test view config', () => {
59
61
  await executeAfterWait(() => {
60
62
  expect(onErrorSpy).toHaveBeenCalledWith(
61
63
  {
62
- error:
63
- 'Please register event handlers before calling render',
64
+ error: 'Please register event handlers before calling render',
64
65
  },
65
66
  expect.any(Function),
66
67
  );
@@ -84,9 +85,7 @@ describe('Custom CSS Url', () => {
84
85
  embed.render();
85
86
  executeAfterWait(() => {
86
87
  const iframe = getIFrameEl();
87
- expect(iframe.src.includes('customCssUrl=bla.com/foo.css')).toBe(
88
- true,
89
- );
88
+ expect(iframe.src.includes('customCssUrl=bla.com/foo.css')).toBe(true);
90
89
  done();
91
90
  });
92
91
  });