@thoughtspot/visual-embed-sdk 1.27.0-alpha.0 → 1.27.0-loggers

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 (178) hide show
  1. package/cjs/package.json +1 -1
  2. package/cjs/src/auth.d.ts.map +1 -1
  3. package/cjs/src/auth.js +5 -4
  4. package/cjs/src/auth.js.map +1 -1
  5. package/cjs/src/embed/app.d.ts +1 -1
  6. package/cjs/src/embed/app.d.ts.map +1 -1
  7. package/cjs/src/embed/app.js +3 -2
  8. package/cjs/src/embed/app.js.map +1 -1
  9. package/cjs/src/embed/app.spec.js +5 -4
  10. package/cjs/src/embed/app.spec.js.map +1 -1
  11. package/cjs/src/embed/base.d.ts.map +1 -1
  12. package/cjs/src/embed/base.js +5 -2
  13. package/cjs/src/embed/base.js.map +1 -1
  14. package/cjs/src/embed/base.spec.js +3 -2
  15. package/cjs/src/embed/base.spec.js.map +1 -1
  16. package/cjs/src/embed/embed.spec.js +2 -1
  17. package/cjs/src/embed/embed.spec.js.map +1 -1
  18. package/cjs/src/embed/embedConfig.d.ts +2 -1
  19. package/cjs/src/embed/embedConfig.d.ts.map +1 -1
  20. package/cjs/src/embed/embedConfig.js +2 -0
  21. package/cjs/src/embed/embedConfig.js.map +1 -1
  22. package/cjs/src/embed/events.spec.js +3 -2
  23. package/cjs/src/embed/events.spec.js.map +1 -1
  24. package/cjs/src/embed/liveboard.d.ts.map +1 -1
  25. package/cjs/src/embed/liveboard.js.map +1 -1
  26. package/cjs/src/embed/sage.d.ts +1 -1
  27. package/cjs/src/embed/sage.d.ts.map +1 -1
  28. package/cjs/src/embed/sage.js.map +1 -1
  29. package/cjs/src/embed/search.d.ts +1 -1
  30. package/cjs/src/embed/search.d.ts.map +1 -1
  31. package/cjs/src/embed/search.js +2 -3
  32. package/cjs/src/embed/search.js.map +1 -1
  33. package/cjs/src/embed/ts-embed.d.ts +0 -1
  34. package/cjs/src/embed/ts-embed.d.ts.map +1 -1
  35. package/cjs/src/embed/ts-embed.js +13 -13
  36. package/cjs/src/embed/ts-embed.js.map +1 -1
  37. package/cjs/src/embed/ts-embed.spec.js +27 -26
  38. package/cjs/src/embed/ts-embed.spec.js.map +1 -1
  39. package/cjs/src/mixpanel-service.d.ts.map +1 -1
  40. package/cjs/src/mixpanel-service.js +2 -1
  41. package/cjs/src/mixpanel-service.js.map +1 -1
  42. package/cjs/src/react/index.spec.js +2 -2
  43. package/cjs/src/react/index.spec.js.map +1 -1
  44. package/cjs/src/types.d.ts +25 -1
  45. package/cjs/src/types.d.ts.map +1 -1
  46. package/cjs/src/types.js +12 -1
  47. package/cjs/src/types.js.map +1 -1
  48. package/cjs/src/utils/authService/authService.d.ts.map +1 -1
  49. package/cjs/src/utils/authService/authService.js +3 -2
  50. package/cjs/src/utils/authService/authService.js.map +1 -1
  51. package/cjs/src/utils/authService/authService.spec.js +3 -2
  52. package/cjs/src/utils/authService/authService.spec.js.map +1 -1
  53. package/cjs/src/utils/authService/tokenizedAuthService.d.ts.map +1 -1
  54. package/cjs/src/utils/authService/tokenizedAuthService.js +2 -1
  55. package/cjs/src/utils/authService/tokenizedAuthService.js.map +1 -1
  56. package/cjs/src/utils/logger.d.ts +18 -0
  57. package/cjs/src/utils/logger.d.ts.map +1 -0
  58. package/cjs/src/utils/logger.js +78 -0
  59. package/cjs/src/utils/logger.js.map +1 -0
  60. package/cjs/src/utils/logger.spec.d.ts +25 -0
  61. package/cjs/src/utils/logger.spec.d.ts.map +1 -0
  62. package/cjs/src/utils/logger.spec.js +80 -0
  63. package/cjs/src/utils/logger.spec.js.map +1 -0
  64. package/dist/src/auth.d.ts.map +1 -1
  65. package/dist/src/embed/app.d.ts +1 -1
  66. package/dist/src/embed/app.d.ts.map +1 -1
  67. package/dist/src/embed/base.d.ts.map +1 -1
  68. package/dist/src/embed/embedConfig.d.ts +2 -1
  69. package/dist/src/embed/embedConfig.d.ts.map +1 -1
  70. package/dist/src/embed/liveboard.d.ts.map +1 -1
  71. package/dist/src/embed/sage.d.ts +1 -1
  72. package/dist/src/embed/sage.d.ts.map +1 -1
  73. package/dist/src/embed/search.d.ts +1 -1
  74. package/dist/src/embed/search.d.ts.map +1 -1
  75. package/dist/src/embed/ts-embed.d.ts +0 -1
  76. package/dist/src/embed/ts-embed.d.ts.map +1 -1
  77. package/dist/src/mixpanel-service.d.ts.map +1 -1
  78. package/dist/src/types.d.ts +25 -1
  79. package/dist/src/types.d.ts.map +1 -1
  80. package/dist/src/utils/authService/authService.d.ts.map +1 -1
  81. package/dist/src/utils/authService/tokenizedAuthService.d.ts.map +1 -1
  82. package/dist/src/utils/logger.d.ts +18 -0
  83. package/dist/src/utils/logger.d.ts.map +1 -0
  84. package/dist/src/utils/logger.spec.d.ts +25 -0
  85. package/dist/src/utils/logger.spec.d.ts.map +1 -0
  86. package/dist/tsembed-react.es.js +17309 -33
  87. package/dist/tsembed-react.js +17309 -33
  88. package/dist/tsembed.es.js +17635 -353
  89. package/dist/tsembed.js +32458 -15176
  90. package/dist/visual-embed-sdk-react-full.d.ts +27 -24
  91. package/dist/visual-embed-sdk-react.d.ts +27 -24
  92. package/dist/visual-embed-sdk.d.ts +27 -24
  93. package/lib/package.json +1 -1
  94. package/lib/src/auth.d.ts.map +1 -1
  95. package/lib/src/auth.js +5 -4
  96. package/lib/src/auth.js.map +1 -1
  97. package/lib/src/embed/app.d.ts +1 -1
  98. package/lib/src/embed/app.d.ts.map +1 -1
  99. package/lib/src/embed/app.js +3 -2
  100. package/lib/src/embed/app.js.map +1 -1
  101. package/lib/src/embed/app.spec.js +5 -4
  102. package/lib/src/embed/app.spec.js.map +1 -1
  103. package/lib/src/embed/base.d.ts.map +1 -1
  104. package/lib/src/embed/base.js +6 -3
  105. package/lib/src/embed/base.js.map +1 -1
  106. package/lib/src/embed/base.spec.js +3 -2
  107. package/lib/src/embed/base.spec.js.map +1 -1
  108. package/lib/src/embed/embed.spec.js +2 -1
  109. package/lib/src/embed/embed.spec.js.map +1 -1
  110. package/lib/src/embed/embedConfig.d.ts +2 -1
  111. package/lib/src/embed/embedConfig.d.ts.map +1 -1
  112. package/lib/src/embed/embedConfig.js +2 -0
  113. package/lib/src/embed/embedConfig.js.map +1 -1
  114. package/lib/src/embed/events.spec.js +3 -2
  115. package/lib/src/embed/events.spec.js.map +1 -1
  116. package/lib/src/embed/liveboard.d.ts.map +1 -1
  117. package/lib/src/embed/liveboard.js.map +1 -1
  118. package/lib/src/embed/sage.d.ts +1 -1
  119. package/lib/src/embed/sage.d.ts.map +1 -1
  120. package/lib/src/embed/sage.js.map +1 -1
  121. package/lib/src/embed/search.d.ts +1 -1
  122. package/lib/src/embed/search.d.ts.map +1 -1
  123. package/lib/src/embed/search.js +2 -3
  124. package/lib/src/embed/search.js.map +1 -1
  125. package/lib/src/embed/ts-embed.d.ts +0 -1
  126. package/lib/src/embed/ts-embed.d.ts.map +1 -1
  127. package/lib/src/embed/ts-embed.js +13 -13
  128. package/lib/src/embed/ts-embed.js.map +1 -1
  129. package/lib/src/embed/ts-embed.spec.js +27 -26
  130. package/lib/src/embed/ts-embed.spec.js.map +1 -1
  131. package/lib/src/mixpanel-service.d.ts.map +1 -1
  132. package/lib/src/mixpanel-service.js +2 -1
  133. package/lib/src/mixpanel-service.js.map +1 -1
  134. package/lib/src/react/index.spec.js +2 -2
  135. package/lib/src/react/index.spec.js.map +1 -1
  136. package/lib/src/types.d.ts +25 -1
  137. package/lib/src/types.d.ts.map +1 -1
  138. package/lib/src/types.js +11 -0
  139. package/lib/src/types.js.map +1 -1
  140. package/lib/src/utils/authService/authService.d.ts.map +1 -1
  141. package/lib/src/utils/authService/authService.js +3 -2
  142. package/lib/src/utils/authService/authService.js.map +1 -1
  143. package/lib/src/utils/authService/authService.spec.js +3 -2
  144. package/lib/src/utils/authService/authService.spec.js.map +1 -1
  145. package/lib/src/utils/authService/tokenizedAuthService.d.ts.map +1 -1
  146. package/lib/src/utils/authService/tokenizedAuthService.js +2 -1
  147. package/lib/src/utils/authService/tokenizedAuthService.js.map +1 -1
  148. package/lib/src/utils/logger.d.ts +18 -0
  149. package/lib/src/utils/logger.d.ts.map +1 -0
  150. package/lib/src/utils/logger.js +73 -0
  151. package/lib/src/utils/logger.js.map +1 -0
  152. package/lib/src/utils/logger.spec.d.ts +25 -0
  153. package/lib/src/utils/logger.spec.d.ts.map +1 -0
  154. package/lib/src/utils/logger.spec.js +57 -0
  155. package/lib/src/utils/logger.spec.js.map +1 -0
  156. package/lib/src/visual-embed-sdk.d.ts +27 -24
  157. package/package.json +1 -1
  158. package/src/auth.ts +5 -4
  159. package/src/embed/app.spec.ts +5 -4
  160. package/src/embed/app.ts +4 -3
  161. package/src/embed/base.spec.ts +3 -2
  162. package/src/embed/base.ts +10 -3
  163. package/src/embed/embed.spec.ts +2 -1
  164. package/src/embed/embedConfig.ts +2 -0
  165. package/src/embed/events.spec.ts +3 -2
  166. package/src/embed/liveboard.ts +4 -4
  167. package/src/embed/sage.ts +1 -1
  168. package/src/embed/search.ts +3 -4
  169. package/src/embed/ts-embed.spec.ts +27 -26
  170. package/src/embed/ts-embed.ts +19 -19
  171. package/src/mixpanel-service.ts +2 -1
  172. package/src/react/index.spec.tsx +2 -2
  173. package/src/types.ts +26 -0
  174. package/src/utils/authService/authService.spec.ts +3 -2
  175. package/src/utils/authService/authService.ts +4 -2
  176. package/src/utils/authService/tokenizedAuthService.ts +2 -1
  177. package/src/utils/logger.spec.ts +67 -0
  178. package/src/utils/logger.ts +87 -0
@@ -227,12 +227,6 @@ declare module '@thoughtspot/visual-embed-sdk/embed/app' {
227
227
  * embedded Liveboard or visualization.
228
228
  */
229
229
  protected getEmbedParams(): string;
230
- /**
231
- * Constructs the URL of the ThoughtSpot app page to be rendered.
232
- *
233
- * @param pageId The ID of the page to be embedded.
234
- */
235
- getIFrameSrc(): string;
236
230
  /**
237
231
  * Set the iframe height as per the computed height received
238
232
  * from the ThoughtSpot app.
@@ -729,14 +723,6 @@ declare module '@thoughtspot/visual-embed-sdk/embed/search' {
729
723
  protected embedComponentType: string;
730
724
  constructor(domSelector: DOMSelector, viewConfig: SearchViewConfig);
731
725
  protected getEmbedParams(): string;
732
- /**
733
- * Construct the URL of the embedded ThoughtSpot search to be
734
- * loaded in the iframe
735
- *
736
- * @param answerId The GUID of a saved answer
737
- * @param dataSources A list of data source GUIDs
738
- */
739
- getIFrameSrc(): string;
740
726
  /**
741
727
  * Render the embedded ThoughtSpot search
742
728
  */
@@ -1512,6 +1498,20 @@ declare module '@thoughtspot/visual-embed-sdk/types' {
1512
1498
  * @version SDK: 1.26.2 | ThoughtSpot: *
1513
1499
  */
1514
1500
  suppressErrorAlerts?: boolean;
1501
+ /**
1502
+ * Log level for the SDK.
1503
+ * @default LogLevel.ERROR
1504
+ *
1505
+ * @example
1506
+ * ```js
1507
+ * init({
1508
+ * ...embedConfig,
1509
+ * logLevel: LogLevel.SILENT
1510
+ * })
1511
+ * ```
1512
+ * @version SDK: 1.26.3 | ThoughtSpot: 9.10.0.cl
1513
+ */
1514
+ logLevel?: LogLevel;
1515
1515
  }
1516
1516
  export interface LayoutConfig {
1517
1517
  }
@@ -3755,7 +3755,9 @@ declare module '@thoughtspot/visual-embed-sdk/types' {
3755
3755
  IsProductTour = "isProductTour",
3756
3756
  HideSearchBarTitle = "hideSearchBarTitle",
3757
3757
  HideSageAnswerHeader = "hideSageAnswerHeader",
3758
- HideSearchBar = "hideSearchBar"
3758
+ HideSearchBar = "hideSearchBar",
3759
+ ClientLogLevel = "clientLogLevel",
3760
+ OverrideNativeConsole = "overrideConsoleLogs"
3759
3761
  }
3760
3762
  /**
3761
3763
  * ThoughtSpot application pages include actions and menu commands
@@ -4670,6 +4672,14 @@ declare module '@thoughtspot/visual-embed-sdk/types' {
4670
4672
  session: SessionInterface;
4671
4673
  vizId?: string;
4672
4674
  }
4675
+ export enum LogLevel {
4676
+ SILENT = "SILENT",
4677
+ ERROR = "ERROR",
4678
+ WARN = "WARN",
4679
+ INFO = "INFO",
4680
+ DEBUG = "DEBUG",
4681
+ TRACE = "TRACE"
4682
+ }
4673
4683
  }
4674
4684
 
4675
4685
  declare module '@thoughtspot/visual-embed-sdk/css-variables' {
@@ -5166,13 +5176,6 @@ declare module '@thoughtspot/visual-embed-sdk/embed/sage' {
5166
5176
  * @returns {string} query string
5167
5177
  */
5168
5178
  protected getEmbedParams(): string;
5169
- /**
5170
- * Construct the URL of the embedded ThoughtSpot sage to be
5171
- * loaded in the iframe
5172
- *
5173
- * @returns {string} iframe url
5174
- */
5175
- getIFrameSrc(): string;
5176
5179
  /**
5177
5180
  * Render the embedded ThoughtSpot Sage
5178
5181
  *
@@ -5270,12 +5273,13 @@ declare module '@thoughtspot/visual-embed-sdk/embed/embedConfig' {
5270
5273
  export const getEmbedConfig: () => EmbedConfig;
5271
5274
  /**
5272
5275
  * Sets the configuration embed was initialized with.
5276
+ * And returns the new configuration.
5273
5277
  *
5274
5278
  * @param newConfig The configuration to set.
5275
5279
  * @version SDK: 1.27.0 | ThoughtSpot: *
5276
5280
  * @group Global methods
5277
5281
  */
5278
- export const setEmbedConfig: (newConfig: EmbedConfig) => void;
5282
+ export const setEmbedConfig: (newConfig: EmbedConfig) => EmbedConfig;
5279
5283
  }
5280
5284
 
5281
5285
  declare module '@thoughtspot/visual-embed-sdk/embed/ts-embed' {
@@ -5475,7 +5479,6 @@ declare module '@thoughtspot/visual-embed-sdk/embed/ts-embed' {
5475
5479
  * @param args
5476
5480
  */
5477
5481
  render(): TsEmbed;
5478
- getIframeSrc(): string;
5479
5482
  protected handleRenderForPrerender(): void;
5480
5483
  /**
5481
5484
  * Creates the preRender shell
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thoughtspot/visual-embed-sdk",
3
- "version": "1.27.0-alpha.0",
3
+ "version": "1.27.0-loggers",
4
4
  "description": "ThoughtSpot Embed SDK",
5
5
  "module": "lib/src/index.js",
6
6
  "main": "dist/tsembed.js",
package/src/auth.ts CHANGED
@@ -13,6 +13,7 @@ import {
13
13
  EndPoints,
14
14
  } from './utils/authService';
15
15
  import { getAuthenticationToken, resetCachedAuthToken } from './authToken';
16
+ import { logger } from './utils/logger';
16
17
 
17
18
  // eslint-disable-next-line import/no-mutable-exports
18
19
  export let loggedInStatus = false;
@@ -154,7 +155,7 @@ export function setAuthEE(eventEmitter: EventEmitter<AuthStatus | AuthEvent>): v
154
155
  */
155
156
  export function notifyAuthSDKSuccess(): void {
156
157
  if (!authEE) {
157
- console.error('SDK not initialized');
158
+ logger.error('SDK not initialized');
158
159
  return;
159
160
  }
160
161
  authEE.emit(AuthStatus.SDK_SUCCESS);
@@ -165,7 +166,7 @@ export function notifyAuthSDKSuccess(): void {
165
166
  */
166
167
  export function notifyAuthSuccess(): void {
167
168
  if (!authEE) {
168
- console.error('SDK not initialized');
169
+ logger.error('SDK not initialized');
169
170
  return;
170
171
  }
171
172
  authEE.emit(AuthStatus.SUCCESS, sessionInfo);
@@ -177,7 +178,7 @@ export function notifyAuthSuccess(): void {
177
178
  */
178
179
  export function notifyAuthFailure(failureType: AuthFailureType): void {
179
180
  if (!authEE) {
180
- console.error('SDK not initialized');
181
+ logger.error('SDK not initialized');
181
182
  return;
182
183
  }
183
184
  authEE.emit(AuthStatus.FAILURE, failureType);
@@ -188,7 +189,7 @@ export function notifyAuthFailure(failureType: AuthFailureType): void {
188
189
  */
189
190
  export function notifyLogout(): void {
190
191
  if (!authEE) {
191
- console.error('SDK not initialized');
192
+ logger.error('SDK not initialized');
192
193
  return;
193
194
  }
194
195
  authEE.emit(AuthStatus.LOGOUT);
@@ -18,6 +18,7 @@ import {
18
18
  import { version } from '../../package.json';
19
19
  import * as config from '../config';
20
20
  import { TsEmbed, V1Embed } from './ts-embed';
21
+ import { logger } from '../utils/logger';
21
22
 
22
23
  const defaultViewConfig = {
23
24
  frameParams: {
@@ -463,15 +464,15 @@ describe('App embed tests', () => {
463
464
  },
464
465
  });
465
466
  await appEmbed.render();
466
- spyOn(console, 'warn');
467
+ spyOn(logger, 'warn');
467
468
  appEmbed.navigateToPage(-1);
468
- expect(console.warn).toHaveBeenCalledWith(
469
+ expect(logger.warn).toHaveBeenCalledWith(
469
470
  'Path can only by a string when triggered without noReload',
470
471
  );
471
472
  });
472
473
 
473
474
  test('navigateToPage function use before render', async () => {
474
- spyOn(console, 'log');
475
+ spyOn(logger, 'log');
475
476
  const appEmbed = new AppEmbed(getRootEl(), {
476
477
  frameParams: {
477
478
  width: '100%',
@@ -480,7 +481,7 @@ describe('App embed tests', () => {
480
481
  });
481
482
  appEmbed.navigateToPage(path);
482
483
  await appEmbed.render();
483
- expect(console.log).toHaveBeenCalledWith(
484
+ expect(logger.log).toHaveBeenCalledWith(
484
485
  'Please call render before invoking this method',
485
486
  );
486
487
  });
package/src/embed/app.ts CHANGED
@@ -9,6 +9,7 @@
9
9
  * @author Ayon Ghosh <ayon.ghosh@thoughtspot.com>
10
10
  */
11
11
 
12
+ import { logger } from '../utils/logger';
12
13
  import { getQueryParamString } from '../utils';
13
14
  import {
14
15
  Param, DOMSelector, HostEvent, ViewConfig, EmbedEvent, MessagePayload,
@@ -282,7 +283,7 @@ export class AppEmbed extends V1Embed {
282
283
  *
283
284
  * @param pageId The ID of the page to be embedded.
284
285
  */
285
- public getIFrameSrc(): string {
286
+ private getIFrameSrc() {
286
287
  const {
287
288
  pageId, path, modularHomeExperience,
288
289
  } = this.viewConfig;
@@ -376,14 +377,14 @@ export class AppEmbed extends V1Embed {
376
377
  */
377
378
  public navigateToPage(path: string | number, noReload = false): void {
378
379
  if (!this.iFrame) {
379
- console.log('Please call render before invoking this method');
380
+ logger.log('Please call render before invoking this method');
380
381
  return;
381
382
  }
382
383
  if (noReload) {
383
384
  this.trigger(HostEvent.Navigate, path);
384
385
  } else {
385
386
  if (typeof path !== 'string') {
386
- console.warn('Path can only by a string when triggered without noReload');
387
+ logger.warn('Path can only by a string when triggered without noReload');
387
388
  return;
388
389
  }
389
390
  const iframeSrc = this.iFrame.src;
@@ -17,6 +17,7 @@ import {
17
17
  getIFrameSrc,
18
18
  } from '../test/test-utils';
19
19
  import * as tokenizedFetchInstance from '../tokenizedFetch';
20
+ import { logger } from '../utils/logger';
20
21
 
21
22
  const thoughtSpotHost = 'tshost';
22
23
  let authEE: EventEmitter;
@@ -412,11 +413,11 @@ describe('Base TS Embed', () => {
412
413
  describe('Base without init', () => {
413
414
  test('notify should error when called without init', () => {
414
415
  base.reset();
415
- jest.spyOn(global.console, 'error').mockImplementation(() => undefined);
416
+ jest.spyOn(logger, 'error').mockImplementation(() => undefined);
416
417
  base.notifyAuthSuccess();
417
418
  base.notifyAuthFailure(auth.AuthFailureType.SDK);
418
419
  base.notifyLogout();
419
420
  base.notifyAuthSDKSuccess();
420
- expect(global.console.error).toHaveBeenCalledTimes(4);
421
+ expect(logger.error).toHaveBeenCalledTimes(4);
421
422
  });
422
423
  });
package/src/embed/base.ts CHANGED
@@ -10,10 +10,13 @@
10
10
  */
11
11
  import EventEmitter from 'eventemitter3';
12
12
  import uniq from 'lodash/uniq';
13
+ import { logger, setGlobalLogLevelOverride } from '../utils/logger';
13
14
  import { tokenizedFetch } from '../tokenizedFetch';
14
15
  import { EndPoints } from '../utils/authService/authService';
15
16
  import { getThoughtSpotHost } from '../config';
16
- import { AuthType, EmbedConfig, PrefetchFeatures } from '../types';
17
+ import {
18
+ AuthType, EmbedConfig, LogLevel, PrefetchFeatures,
19
+ } from '../types';
17
20
  import {
18
21
  authenticate,
19
22
  logout as _logout,
@@ -34,6 +37,7 @@ const CONFIG_DEFAULTS: Partial<EmbedConfig> = {
34
37
  loginFailedMessage: 'Not logged in',
35
38
  authTriggerText: 'Authorize',
36
39
  authType: AuthType.None,
40
+ logLevel: LogLevel.ERROR,
37
41
  };
38
42
 
39
43
  export interface executeTMLInput {
@@ -100,7 +104,7 @@ const hostUrlToFeatureUrl = {
100
104
  export const prefetch = (url?: string, prefetchFeatures?: PrefetchFeatures[]): void => {
101
105
  if (url === '') {
102
106
  // eslint-disable-next-line no-console
103
- console.warn('The prefetch method does not have a valid URL');
107
+ logger.warn('The prefetch method does not have a valid URL');
104
108
  } else {
105
109
  const features = prefetchFeatures || [PrefetchFeatures.FullApp];
106
110
  let hostUrl = url || getEmbedConfig().thoughtSpotHost;
@@ -174,13 +178,16 @@ function backwardCompat(embedConfig: EmbedConfig): EmbedConfig {
174
178
  */
175
179
  export const init = (embedConfig: EmbedConfig): AuthEventEmitter => {
176
180
  sanity(embedConfig);
177
- setEmbedConfig(
181
+ embedConfig = setEmbedConfig(
178
182
  backwardCompat({
179
183
  ...CONFIG_DEFAULTS,
180
184
  ...embedConfig,
181
185
  thoughtSpotHost: getThoughtSpotHost(embedConfig),
182
186
  }),
183
187
  );
188
+
189
+ setGlobalLogLevelOverride(embedConfig.logLevel);
190
+
184
191
  const authEE = new EventEmitter<AuthStatus | AuthEvent>();
185
192
  setAuthEE(authEE);
186
193
  handleAuth();
@@ -1,3 +1,4 @@
1
+ import { logger } from '../utils/logger';
1
2
  import {
2
3
  init, AuthType, SearchEmbed, EmbedEvent,
3
4
  } from '../index';
@@ -51,7 +52,7 @@ describe('test view config', () => {
51
52
  });
52
53
 
53
54
  test('trying to register event handler after render should throw error', async () => {
54
- spyOn(console, 'error');
55
+ spyOn(logger, 'error');
55
56
  const onErrorSpy = jest.fn();
56
57
  const searchEmbed = new SearchEmbed(getRootEl(), defaultViewConfig);
57
58
  searchEmbed
@@ -13,6 +13,7 @@ export const getEmbedConfig = (): EmbedConfig => config;
13
13
 
14
14
  /**
15
15
  * Sets the configuration embed was initialized with.
16
+ * And returns the new configuration.
16
17
  *
17
18
  * @param newConfig The configuration to set.
18
19
  * @version SDK: 1.27.0 | ThoughtSpot: *
@@ -20,4 +21,5 @@ export const getEmbedConfig = (): EmbedConfig => config;
20
21
  */
21
22
  export const setEmbedConfig = (newConfig: EmbedConfig) => {
22
23
  config = newConfig;
24
+ return newConfig;
23
25
  };
@@ -1,3 +1,4 @@
1
+ import { logger } from '../utils/logger';
1
2
  import {
2
3
  init,
3
4
  AuthType,
@@ -155,7 +156,7 @@ describe('test communication between host app and ThoughtSpot', () => {
155
156
  pinboardId: 'eca215d4-0d2c-4a55-90e3-d81ef6848ae0',
156
157
  } as LiveboardViewConfig);
157
158
  liveboardEmbed.render();
158
- const spy1 = jest.spyOn(global.console, 'log');
159
+ const spy1 = jest.spyOn(logger, 'log');
159
160
 
160
161
  await executeAfterWait(() => {
161
162
  const iframe = getIFrameEl();
@@ -173,7 +174,7 @@ describe('test communication between host app and ThoughtSpot', () => {
173
174
  pinboardId: 'eca215d4-0d2c-4a55-90e3-d81ef6848ae0',
174
175
  } as LiveboardViewConfig);
175
176
  pinboardEmbed.render();
176
- const spy1 = jest.spyOn(global.console, 'log');
177
+ const spy1 = jest.spyOn(logger, 'log');
177
178
 
178
179
  await executeAfterWait(() => {
179
180
  const iframe = getIFrameEl();
@@ -28,7 +28,7 @@ import { V1Embed } from './ts-embed';
28
28
  *
29
29
  * @group Embed components
30
30
  */
31
- export interface LiveboardViewConfig extends Omit<ViewConfig, 'hiddenHomepageModules' | 'hiddenHomeLeftNavItems' | 'reorderedHomepageModules'> {
31
+ export interface LiveboardViewConfig extends Omit<ViewConfig, 'hiddenHomepageModules' | 'hiddenHomeLeftNavItems'| 'reorderedHomepageModules'> {
32
32
  /**
33
33
  * If set to true, the embedded object container dynamically resizes
34
34
  * according to the height of the Liveboard.
@@ -263,7 +263,7 @@ export class LiveboardEmbed extends V1Embed {
263
263
  * Construct the URL of the embedded ThoughtSpot Liveboard or visualization
264
264
  * to be loaded within the iFrame.
265
265
  */
266
- private getIFrameSrc(): string {
266
+ private getIFrameSrc() {
267
267
  const { vizId, activeTabId } = this.viewConfig;
268
268
  const liveboardId = this.viewConfig.liveboardId ?? this.viewConfig.pinboardId;
269
269
 
@@ -312,7 +312,7 @@ export class LiveboardEmbed extends V1Embed {
312
312
  if (isUndefined(embedObj)) return;
313
313
 
314
314
  const showDifferentLib = this.viewConfig.liveboardId
315
- && embedObj.viewConfig.liveboardId !== this.viewConfig.liveboardId;
315
+ && embedObj.viewConfig.liveboardId !== this.viewConfig.liveboardId;
316
316
 
317
317
  if (showDifferentLib) {
318
318
  const libId = this.viewConfig.liveboardId;
@@ -379,4 +379,4 @@ export class LiveboardEmbed extends V1Embed {
379
379
  /**
380
380
  * @hidden
381
381
  */
382
- export class PinboardEmbed extends LiveboardEmbed { }
382
+ export class PinboardEmbed extends LiveboardEmbed {}
package/src/embed/sage.ts CHANGED
@@ -212,7 +212,7 @@ export class SageEmbed extends V1Embed {
212
212
  *
213
213
  * @returns {string} iframe url
214
214
  */
215
- public getIFrameSrc(): string {
215
+ private getIFrameSrc() {
216
216
  const path = 'eureka';
217
217
  const postHashObj = {};
218
218
  const tsPostHashParams = this.getThoughtSpotPostUrlParams();
@@ -272,8 +272,7 @@ export class SearchEmbed extends TsEmbed {
272
272
  * @param answerId The GUID of a saved answer
273
273
  * @param dataSources A list of data source GUIDs
274
274
  */
275
- public getIFrameSrc(): string {
276
- const { answerId } = this.viewConfig;
275
+ private getIFrameSrc(answerId: string) {
277
276
  const answerPath = answerId ? `saved-answer/${answerId}` : 'answer';
278
277
  const tsPostHashParams = this.getThoughtSpotPostUrlParams();
279
278
 
@@ -287,14 +286,14 @@ export class SearchEmbed extends TsEmbed {
287
286
  super.render();
288
287
  const { answerId } = this.viewConfig;
289
288
 
290
- const src = this.getIFrameSrc();
289
+ const src = this.getIFrameSrc(answerId);
291
290
  this.renderIFrame(src);
292
291
  getAuthPromise().then(() => {
293
292
  if (
294
293
  checkReleaseVersionInBeta(
295
294
  getReleaseVersion(),
296
295
  getEmbedConfig().suppressSearchEmbedBetaWarning
297
- || getEmbedConfig().suppressErrorAlerts,
296
+ || getEmbedConfig().suppressErrorAlerts,
298
297
  )
299
298
  ) {
300
299
  alert(ERROR_MESSAGE.SEARCHEMBED_BETA_WRANING_MESSAGE);
@@ -32,6 +32,7 @@ import * as authInstance from '../auth';
32
32
  import * as baseInstance from './base';
33
33
  import { MIXPANEL_EVENT } from '../mixpanel-service';
34
34
  import * as authService from '../utils/authService/authService';
35
+ import { logger } from '../utils/logger';
35
36
 
36
37
  const defaultViewConfig = {
37
38
  frameParams: {
@@ -425,7 +426,7 @@ describe('Unit test case for ts embed', () => {
425
426
  const searchEmbed = new SearchEmbed(getRootEl(), defaultViewConfig);
426
427
  searchEmbed
427
428
  .on(EmbedEvent.Save, () => {
428
- console.log('non callable');
429
+ logger.log('non callable');
429
430
  })
430
431
  .render();
431
432
 
@@ -468,7 +469,7 @@ describe('Unit test case for ts embed', () => {
468
469
  .on(
469
470
  EmbedEvent.Save,
470
471
  () => {
471
- console.log('non callable');
472
+ logger.log('non callable');
472
473
  },
473
474
  { start: true },
474
475
  )
@@ -830,7 +831,7 @@ describe('Unit test case for ts embed', () => {
830
831
  const iFrame: any = document.createElement('div');
831
832
  iFrame.contentWindow = null;
832
833
  jest.spyOn(document, 'createElement').mockReturnValueOnce(iFrame);
833
- spyOn(console, 'error');
834
+ spyOn(logger, 'error');
834
835
  tsEmbed.render();
835
836
  });
836
837
 
@@ -844,7 +845,7 @@ describe('Unit test case for ts embed', () => {
844
845
 
845
846
  describe('when visible actions are set', () => {
846
847
  test('should throw error when there are both visible and hidden actions - pinboard', async () => {
847
- spyOn(console, 'error');
848
+ spyOn(logger, 'error');
848
849
  const pinboardEmbed = new PinboardEmbed(getRootEl(), {
849
850
  hiddenActions: [Action.DownloadAsCsv],
850
851
  visibleActions: [Action.DownloadAsCsv],
@@ -853,7 +854,7 @@ describe('Unit test case for ts embed', () => {
853
854
  } as LiveboardViewConfig);
854
855
  await pinboardEmbed.render();
855
856
  expect(pinboardEmbed['isError']).toBe(true);
856
- expect(console.error).toHaveBeenCalledWith(
857
+ expect(logger.error).toHaveBeenCalledWith(
857
858
  'You cannot have both hidden actions and visible actions',
858
859
  );
859
860
  });
@@ -876,7 +877,7 @@ describe('Unit test case for ts embed', () => {
876
877
  hiddenActions: Array<Action>,
877
878
  visibleActions: Array<Action>,
878
879
  ) {
879
- spyOn(console, 'error');
880
+ spyOn(logger, 'error');
880
881
  const liveboardEmbed = new LiveboardEmbed(getRootEl(), {
881
882
  hiddenActions,
882
883
  visibleActions,
@@ -885,7 +886,7 @@ describe('Unit test case for ts embed', () => {
885
886
  } as LiveboardViewConfig);
886
887
  await liveboardEmbed.render();
887
888
  expect(liveboardEmbed['isError']).toBe(true);
888
- expect(console.error).toHaveBeenCalledWith(
889
+ expect(logger.error).toHaveBeenCalledWith(
889
890
  'You cannot have both hidden actions and visible actions',
890
891
  );
891
892
  }
@@ -921,7 +922,7 @@ describe('Unit test case for ts embed', () => {
921
922
 
922
923
  describe('when visible Tabs are set', () => {
923
924
  test('should throw error when there are both visible and hidden Tabs - pinboard', async () => {
924
- spyOn(console, 'error');
925
+ spyOn(logger, 'error');
925
926
  const pinboardEmbed = new PinboardEmbed(getRootEl(), {
926
927
  visibleTabs: [tabId1],
927
928
  hiddenTabs: [tabId2],
@@ -930,7 +931,7 @@ describe('Unit test case for ts embed', () => {
930
931
  } as LiveboardViewConfig);
931
932
  await pinboardEmbed.render();
932
933
  expect(pinboardEmbed['isError']).toBe(true);
933
- expect(console.error).toHaveBeenCalledWith(
934
+ expect(logger.error).toHaveBeenCalledWith(
934
935
  'You cannot have both hidden Tabs and visible Tabs',
935
936
  );
936
937
  });
@@ -953,7 +954,7 @@ describe('Unit test case for ts embed', () => {
953
954
  hiddenTabs: Array<string>,
954
955
  visibleTabs: Array<string>,
955
956
  ) {
956
- spyOn(console, 'error');
957
+ spyOn(logger, 'error');
957
958
  const liveboardEmbed = new LiveboardEmbed(getRootEl(), {
958
959
  hiddenTabs,
959
960
  visibleTabs,
@@ -962,7 +963,7 @@ describe('Unit test case for ts embed', () => {
962
963
  } as LiveboardViewConfig);
963
964
  await liveboardEmbed.render();
964
965
  expect(liveboardEmbed['isError']).toBe(true);
965
- expect(console.error).toHaveBeenCalledWith(
966
+ expect(logger.error).toHaveBeenCalledWith(
966
967
  'You cannot have both hidden Tabs and visible Tabs',
967
968
  );
968
969
  }
@@ -1006,11 +1007,11 @@ describe('Unit test case for ts embed', () => {
1006
1007
  });
1007
1008
 
1008
1009
  test('Error should be true', async () => {
1009
- spyOn(console, 'error');
1010
+ spyOn(logger, 'error');
1010
1011
  const tsEmbed = new SearchEmbed(getRootEl(), {});
1011
1012
  tsEmbed.render();
1012
1013
  expect(tsEmbed['isError']).toBe(true);
1013
- expect(console.error).toHaveBeenCalledWith(
1014
+ expect(logger.error).toHaveBeenCalledWith(
1014
1015
  'You need to init the ThoughtSpot SDK module first',
1015
1016
  );
1016
1017
  });
@@ -1018,13 +1019,13 @@ describe('Unit test case for ts embed', () => {
1018
1019
 
1019
1020
  describe('V1Embed ', () => {
1020
1021
  test('when isRendered is true than isError will be true', () => {
1021
- spyOn(console, 'error');
1022
+ spyOn(logger, 'error');
1022
1023
  const viEmbedIns = new tsEmbedInstance.V1Embed(getRootEl(), defaultViewConfig);
1023
1024
  expect(viEmbedIns['isError']).toBe(false);
1024
1025
  viEmbedIns.render();
1025
1026
  viEmbedIns.on(EmbedEvent.CustomAction, jest.fn()).render();
1026
1027
  expect(viEmbedIns['isError']).toBe(true);
1027
- expect(console.error).toHaveBeenCalledWith(
1028
+ expect(logger.error).toHaveBeenCalledWith(
1028
1029
  'Please register event handlers before calling render',
1029
1030
  );
1030
1031
  });
@@ -1065,7 +1066,7 @@ describe('Unit test case for ts embed', () => {
1065
1066
  });
1066
1067
 
1067
1068
  test('navigateToPage function use before render', async () => {
1068
- spyOn(console, 'log');
1069
+ spyOn(logger, 'log');
1069
1070
  const appEmbed = new AppEmbed(getRootEl(), {
1070
1071
  frameParams: {
1071
1072
  width: '100%',
@@ -1074,7 +1075,7 @@ describe('Unit test case for ts embed', () => {
1074
1075
  });
1075
1076
  appEmbed.navigateToPage(path, false);
1076
1077
  await appEmbed.render();
1077
- expect(console.log).toHaveBeenCalledWith(
1078
+ expect(logger.log).toHaveBeenCalledWith(
1078
1079
  'Please call render before invoking this method',
1079
1080
  );
1080
1081
  });
@@ -1462,7 +1463,7 @@ describe('Unit test case for ts embed', () => {
1462
1463
  });
1463
1464
 
1464
1465
  // show preRender
1465
- const warnSpy = spyOn(console, 'warn');
1466
+ const warnSpy = spyOn(logger, 'warn');
1466
1467
  libEmbed.showPreRender();
1467
1468
  expect(warnSpy).toHaveBeenCalledTimes(0);
1468
1469
 
@@ -1492,13 +1493,13 @@ describe('Unit test case for ts embed', () => {
1492
1493
  it('preRender called without preRenderId should log error ', () => {
1493
1494
  createRootEleForEmbed();
1494
1495
 
1495
- spyOn(console, 'error');
1496
+ spyOn(logger, 'error');
1496
1497
  const libEmbed = new LiveboardEmbed('#tsEmbedDiv', {
1497
1498
  liveboardId: 'myLiveboardId',
1498
1499
  });
1499
1500
  libEmbed.preRender();
1500
1501
 
1501
- expect(console.error).toHaveBeenCalledWith('PreRender id is required for preRender');
1502
+ expect(logger.error).toHaveBeenCalledWith('PreRender id is required for preRender');
1502
1503
  });
1503
1504
 
1504
1505
  it('showPreRender should preRender if not available', async () => {
@@ -1546,7 +1547,7 @@ describe('Unit test case for ts embed', () => {
1546
1547
 
1547
1548
  libEmbed.preRender();
1548
1549
  await waitFor(() => !!getIFrameEl());
1549
- const warnSpy = jest.spyOn(console, 'warn');
1550
+ const warnSpy = jest.spyOn(logger, 'warn');
1550
1551
  const newEmbed = new LiveboardEmbed('#tsEmbedDiv', {
1551
1552
  preRenderId: 'i-am-preRendered',
1552
1553
  liveboardId: 'awdawda',
@@ -1565,10 +1566,10 @@ describe('Unit test case for ts embed', () => {
1565
1566
  liveboardId: 'myLiveboardId',
1566
1567
  });
1567
1568
  spyOn(libEmbed, 'preRender');
1568
- spyOn(console, 'error');
1569
+ spyOn(logger, 'error');
1569
1570
  libEmbed.showPreRender();
1570
1571
  expect(libEmbed.preRender).toHaveBeenCalledTimes(0);
1571
- expect(console.error).toHaveBeenCalledTimes(1);
1572
+ expect(logger.error).toHaveBeenCalledTimes(1);
1572
1573
  });
1573
1574
 
1574
1575
  it('should get underlying iframe', async () => {
@@ -1596,16 +1597,16 @@ describe('Unit test case for ts embed', () => {
1596
1597
  );
1597
1598
  });
1598
1599
  it('should log error if sync is called before preRender', async () => {
1599
- jest.spyOn(console, 'error').mockImplementation(jest.fn());
1600
+ jest.spyOn(logger, 'error').mockImplementation(jest.fn());
1600
1601
  const libEmbed = new LiveboardEmbed('#tsEmbedDiv', {
1601
1602
  liveboardId: 'myLiveboardId',
1602
1603
  preRenderId: 'test',
1603
1604
  });
1604
1605
  await libEmbed.syncPreRenderStyle();
1605
- expect(console.error).toBeCalledWith(
1606
+ expect(logger.error).toBeCalledWith(
1606
1607
  'PreRender should be called before using syncPreRenderStyle',
1607
1608
  );
1608
- (console.error as any).mockClear();
1609
+ (logger.error as any).mockClear();
1609
1610
  });
1610
1611
  });
1611
1612
  });