@thoughtspot/visual-embed-sdk 1.24.0-dev → 1.24.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 (231) hide show
  1. package/cjs/package.json +2 -3
  2. package/cjs/src/embed/app.d.ts +3 -1
  3. package/cjs/src/embed/app.d.ts.map +1 -1
  4. package/cjs/src/embed/app.js +8 -2
  5. package/cjs/src/embed/app.js.map +1 -1
  6. package/cjs/src/embed/base.d.ts +2 -0
  7. package/cjs/src/embed/base.d.ts.map +1 -1
  8. package/cjs/src/embed/base.js +2 -0
  9. package/cjs/src/embed/base.js.map +1 -1
  10. package/cjs/src/embed/liveboard.d.ts +3 -2
  11. package/cjs/src/embed/liveboard.d.ts.map +1 -1
  12. package/cjs/src/embed/liveboard.js +6 -5
  13. package/cjs/src/embed/liveboard.js.map +1 -1
  14. package/cjs/src/embed/sage.d.ts +4 -1
  15. package/cjs/src/embed/sage.d.ts.map +1 -1
  16. package/cjs/src/embed/sage.js +9 -2
  17. package/cjs/src/embed/sage.js.map +1 -1
  18. package/cjs/src/embed/search-bar.d.ts +1 -0
  19. package/cjs/src/embed/search-bar.d.ts.map +1 -1
  20. package/cjs/src/embed/search-bar.js +1 -0
  21. package/cjs/src/embed/search-bar.js.map +1 -1
  22. package/cjs/src/embed/search.d.ts +5 -1
  23. package/cjs/src/embed/search.d.ts.map +1 -1
  24. package/cjs/src/embed/search.js +10 -2
  25. package/cjs/src/embed/search.js.map +1 -1
  26. package/cjs/src/embed/ts-embed.d.ts +9 -3
  27. package/cjs/src/embed/ts-embed.d.ts.map +1 -1
  28. package/cjs/src/embed/ts-embed.js +50 -20
  29. package/cjs/src/embed/ts-embed.js.map +1 -1
  30. package/cjs/src/embed/ts-embed.spec.js +47 -0
  31. package/cjs/src/embed/ts-embed.spec.js.map +1 -1
  32. package/cjs/src/index.d.ts +3 -2
  33. package/cjs/src/index.d.ts.map +1 -1
  34. package/cjs/src/index.js +3 -1
  35. package/cjs/src/index.js.map +1 -1
  36. package/cjs/src/mixpanel-service.d.ts.map +1 -1
  37. package/cjs/src/mixpanel-service.js +2 -0
  38. package/cjs/src/mixpanel-service.js.map +1 -1
  39. package/cjs/src/mixpanel-service.spec.js +1 -0
  40. package/cjs/src/mixpanel-service.spec.js.map +1 -1
  41. package/cjs/src/react/index.d.ts +5 -1
  42. package/cjs/src/react/index.d.ts.map +1 -1
  43. package/cjs/src/react/index.js +8 -8
  44. package/cjs/src/react/index.js.map +1 -1
  45. package/cjs/src/types.d.ts +46 -18
  46. package/cjs/src/types.d.ts.map +1 -1
  47. package/cjs/src/types.js +7 -13
  48. package/cjs/src/types.js.map +1 -1
  49. package/cjs/src/utils/graphql/answerService/answer-queries.d.ts +5 -0
  50. package/cjs/src/utils/graphql/answerService/answer-queries.d.ts.map +1 -0
  51. package/cjs/src/utils/graphql/answerService/answer-queries.js +80 -0
  52. package/cjs/src/utils/graphql/answerService/answer-queries.js.map +1 -0
  53. package/cjs/src/utils/graphql/answerService/answerService.d.ts +61 -0
  54. package/cjs/src/utils/graphql/answerService/answerService.d.ts.map +1 -0
  55. package/cjs/src/utils/graphql/answerService/answerService.js +182 -0
  56. package/cjs/src/utils/graphql/answerService/answerService.js.map +1 -0
  57. package/cjs/src/utils/graphql/answerService/answerService.spec.d.ts +2 -0
  58. package/cjs/src/utils/graphql/answerService/answerService.spec.d.ts.map +1 -0
  59. package/cjs/src/utils/graphql/answerService/answerService.spec.js +201 -0
  60. package/cjs/src/utils/graphql/answerService/answerService.spec.js.map +1 -0
  61. package/cjs/src/utils/graphql/graphql-request.d.ts +15 -0
  62. package/cjs/src/utils/graphql/graphql-request.d.ts.map +1 -0
  63. package/cjs/src/utils/graphql/graphql-request.js +40 -0
  64. package/cjs/src/utils/graphql/graphql-request.js.map +1 -0
  65. package/cjs/src/utils/graphql/sourceService.d.ts +8 -0
  66. package/cjs/src/utils/graphql/sourceService.d.ts.map +1 -0
  67. package/cjs/src/utils/graphql/sourceService.js +69 -0
  68. package/cjs/src/utils/graphql/sourceService.js.map +1 -0
  69. package/cjs/src/utils/graphql/sourceService.spec.d.ts +2 -0
  70. package/cjs/src/utils/graphql/sourceService.spec.d.ts.map +1 -0
  71. package/cjs/src/utils/graphql/sourceService.spec.js +12 -0
  72. package/cjs/src/utils/graphql/sourceService.spec.js.map +1 -0
  73. package/cjs/src/utils/processData.d.ts.map +1 -1
  74. package/cjs/src/utils/processData.js +7 -11
  75. package/cjs/src/utils/processData.js.map +1 -1
  76. package/cjs/src/utils/processData.spec.js +13 -17
  77. package/cjs/src/utils/processData.spec.js.map +1 -1
  78. package/cjs/src/utils.d.ts +6 -0
  79. package/cjs/src/utils.d.ts.map +1 -1
  80. package/cjs/src/utils.js +26 -1
  81. package/cjs/src/utils.js.map +1 -1
  82. package/dist/src/embed/app.d.ts +3 -1
  83. package/dist/src/embed/app.d.ts.map +1 -1
  84. package/dist/src/embed/base.d.ts +2 -0
  85. package/dist/src/embed/base.d.ts.map +1 -1
  86. package/dist/src/embed/liveboard.d.ts +3 -2
  87. package/dist/src/embed/liveboard.d.ts.map +1 -1
  88. package/dist/src/embed/sage.d.ts +4 -1
  89. package/dist/src/embed/sage.d.ts.map +1 -1
  90. package/dist/src/embed/search-bar.d.ts +1 -0
  91. package/dist/src/embed/search-bar.d.ts.map +1 -1
  92. package/dist/src/embed/search.d.ts +5 -1
  93. package/dist/src/embed/search.d.ts.map +1 -1
  94. package/dist/src/embed/ts-embed.d.ts +9 -3
  95. package/dist/src/embed/ts-embed.d.ts.map +1 -1
  96. package/dist/src/index.d.ts +3 -2
  97. package/dist/src/index.d.ts.map +1 -1
  98. package/dist/src/mixpanel-service.d.ts.map +1 -1
  99. package/dist/src/react/index.d.ts +5 -1
  100. package/dist/src/react/index.d.ts.map +1 -1
  101. package/dist/src/types.d.ts +46 -18
  102. package/dist/src/types.d.ts.map +1 -1
  103. package/dist/src/utils/graphql/answerService/answer-queries.d.ts +5 -0
  104. package/dist/src/utils/graphql/answerService/answer-queries.d.ts.map +1 -0
  105. package/dist/src/utils/graphql/answerService/answerService.d.ts +61 -0
  106. package/dist/src/utils/graphql/answerService/answerService.d.ts.map +1 -0
  107. package/dist/src/utils/graphql/answerService/answerService.spec.d.ts +2 -0
  108. package/dist/src/utils/graphql/answerService/answerService.spec.d.ts.map +1 -0
  109. package/dist/src/utils/graphql/graphql-request.d.ts +15 -0
  110. package/dist/src/utils/graphql/graphql-request.d.ts.map +1 -0
  111. package/dist/src/utils/graphql/sourceService.d.ts +8 -0
  112. package/dist/src/utils/graphql/sourceService.d.ts.map +1 -0
  113. package/dist/src/utils/graphql/sourceService.spec.d.ts +2 -0
  114. package/dist/src/utils/graphql/sourceService.spec.d.ts.map +1 -0
  115. package/dist/src/utils/processData.d.ts.map +1 -1
  116. package/dist/src/utils.d.ts +6 -0
  117. package/dist/src/utils.d.ts.map +1 -1
  118. package/dist/tsembed-react.es.js +468 -107
  119. package/dist/tsembed-react.js +471 -106
  120. package/dist/tsembed.es.js +511 -103
  121. package/dist/tsembed.js +511 -102
  122. package/dist/visual-embed-sdk-react-full.d.ts +132 -28
  123. package/dist/visual-embed-sdk-react.d.ts +132 -28
  124. package/dist/visual-embed-sdk.d.ts +127 -27
  125. package/lib/package.json +2 -3
  126. package/lib/src/embed/app.d.ts +3 -1
  127. package/lib/src/embed/app.d.ts.map +1 -1
  128. package/lib/src/embed/app.js +8 -2
  129. package/lib/src/embed/app.js.map +1 -1
  130. package/lib/src/embed/base.d.ts +2 -0
  131. package/lib/src/embed/base.d.ts.map +1 -1
  132. package/lib/src/embed/base.js +2 -0
  133. package/lib/src/embed/base.js.map +1 -1
  134. package/lib/src/embed/liveboard.d.ts +3 -2
  135. package/lib/src/embed/liveboard.d.ts.map +1 -1
  136. package/lib/src/embed/liveboard.js +6 -5
  137. package/lib/src/embed/liveboard.js.map +1 -1
  138. package/lib/src/embed/sage.d.ts +4 -1
  139. package/lib/src/embed/sage.d.ts.map +1 -1
  140. package/lib/src/embed/sage.js +9 -2
  141. package/lib/src/embed/sage.js.map +1 -1
  142. package/lib/src/embed/search-bar.d.ts +1 -0
  143. package/lib/src/embed/search-bar.d.ts.map +1 -1
  144. package/lib/src/embed/search-bar.js +1 -0
  145. package/lib/src/embed/search-bar.js.map +1 -1
  146. package/lib/src/embed/search.d.ts +5 -1
  147. package/lib/src/embed/search.d.ts.map +1 -1
  148. package/lib/src/embed/search.js +10 -2
  149. package/lib/src/embed/search.js.map +1 -1
  150. package/lib/src/embed/ts-embed.d.ts +9 -3
  151. package/lib/src/embed/ts-embed.d.ts.map +1 -1
  152. package/lib/src/embed/ts-embed.js +50 -20
  153. package/lib/src/embed/ts-embed.js.map +1 -1
  154. package/lib/src/embed/ts-embed.spec.js +47 -0
  155. package/lib/src/embed/ts-embed.spec.js.map +1 -1
  156. package/lib/src/index.d.ts +3 -2
  157. package/lib/src/index.d.ts.map +1 -1
  158. package/lib/src/index.js +2 -1
  159. package/lib/src/index.js.map +1 -1
  160. package/lib/src/mixpanel-service.d.ts.map +1 -1
  161. package/lib/src/mixpanel-service.js +2 -0
  162. package/lib/src/mixpanel-service.js.map +1 -1
  163. package/lib/src/mixpanel-service.spec.js +1 -0
  164. package/lib/src/mixpanel-service.spec.js.map +1 -1
  165. package/lib/src/react/index.d.ts +5 -1
  166. package/lib/src/react/index.d.ts.map +1 -1
  167. package/lib/src/react/index.js +7 -7
  168. package/lib/src/react/index.js.map +1 -1
  169. package/lib/src/types.d.ts +46 -18
  170. package/lib/src/types.d.ts.map +1 -1
  171. package/lib/src/types.js +6 -12
  172. package/lib/src/types.js.map +1 -1
  173. package/lib/src/utils/graphql/answerService/answer-queries.d.ts +5 -0
  174. package/lib/src/utils/graphql/answerService/answer-queries.d.ts.map +1 -0
  175. package/lib/src/utils/graphql/answerService/answer-queries.js +77 -0
  176. package/lib/src/utils/graphql/answerService/answer-queries.js.map +1 -0
  177. package/lib/src/utils/graphql/answerService/answerService.d.ts +61 -0
  178. package/lib/src/utils/graphql/answerService/answerService.d.ts.map +1 -0
  179. package/lib/src/utils/graphql/answerService/answerService.js +177 -0
  180. package/lib/src/utils/graphql/answerService/answerService.js.map +1 -0
  181. package/lib/src/utils/graphql/answerService/answerService.spec.d.ts +2 -0
  182. package/lib/src/utils/graphql/answerService/answerService.spec.d.ts.map +1 -0
  183. package/lib/src/utils/graphql/answerService/answerService.spec.js +199 -0
  184. package/lib/src/utils/graphql/answerService/answerService.spec.js.map +1 -0
  185. package/lib/src/utils/graphql/graphql-request.d.ts +15 -0
  186. package/lib/src/utils/graphql/graphql-request.d.ts.map +1 -0
  187. package/lib/src/utils/graphql/graphql-request.js +36 -0
  188. package/lib/src/utils/graphql/graphql-request.js.map +1 -0
  189. package/lib/src/utils/graphql/sourceService.d.ts +8 -0
  190. package/lib/src/utils/graphql/sourceService.d.ts.map +1 -0
  191. package/lib/src/utils/graphql/sourceService.js +65 -0
  192. package/lib/src/utils/graphql/sourceService.js.map +1 -0
  193. package/lib/src/utils/graphql/sourceService.spec.d.ts +2 -0
  194. package/lib/src/utils/graphql/sourceService.spec.d.ts.map +1 -0
  195. package/lib/src/utils/graphql/sourceService.spec.js +10 -0
  196. package/lib/src/utils/graphql/sourceService.spec.js.map +1 -0
  197. package/lib/src/utils/processData.d.ts.map +1 -1
  198. package/lib/src/utils/processData.js +8 -12
  199. package/lib/src/utils/processData.js.map +1 -1
  200. package/lib/src/utils/processData.spec.js +14 -18
  201. package/lib/src/utils/processData.spec.js.map +1 -1
  202. package/lib/src/utils.d.ts +6 -0
  203. package/lib/src/utils.d.ts.map +1 -1
  204. package/lib/src/utils.js +23 -0
  205. package/lib/src/utils.js.map +1 -1
  206. package/lib/src/visual-embed-sdk.d.ts +133 -28
  207. package/package.json +2 -3
  208. package/src/embed/app.ts +12 -2
  209. package/src/embed/base.ts +2 -0
  210. package/src/embed/liveboard.ts +7 -5
  211. package/src/embed/sage.ts +13 -2
  212. package/src/embed/search-bar.tsx +2 -0
  213. package/src/embed/search.ts +14 -2
  214. package/src/embed/ts-embed.spec.ts +49 -0
  215. package/src/embed/ts-embed.ts +61 -22
  216. package/src/index.ts +5 -0
  217. package/src/mixpanel-service.spec.ts +1 -0
  218. package/src/mixpanel-service.ts +1 -0
  219. package/src/react/index.tsx +40 -37
  220. package/src/types.ts +50 -19
  221. package/src/utils/graphql/answerService/answer-queries.ts +80 -0
  222. package/src/utils/graphql/answerService/answerService.spec.ts +231 -0
  223. package/src/utils/graphql/answerService/answerService.ts +234 -0
  224. package/src/utils/graphql/graphql-request.ts +45 -0
  225. package/src/utils/graphql/sourceService.spec.ts +10 -0
  226. package/src/utils/graphql/sourceService.ts +71 -0
  227. package/src/utils/processData.spec.ts +15 -25
  228. package/src/utils/processData.ts +13 -15
  229. package/src/utils.ts +25 -0
  230. package/src/utils/answerService.spec.ts +0 -41
  231. package/src/utils/answerService.ts +0 -63
@@ -353,6 +353,24 @@ function getDOMNode(domSelector) {
353
353
  return typeof domSelector === 'string' ? document.querySelector(domSelector) : domSelector;
354
354
  }
355
355
  const deepMerge = (target, source) => merge(target, source);
356
+ /**
357
+ *
358
+ * @param obj
359
+ */
360
+ function removeTypename(obj) {
361
+ if (!obj || typeof obj !== 'object')
362
+ return obj;
363
+ // eslint-disable-next-line no-restricted-syntax
364
+ for (const key in obj) {
365
+ if (key === '__typename') {
366
+ delete obj[key];
367
+ }
368
+ else if (typeof obj[key] === 'object') {
369
+ removeTypename(obj[key]);
370
+ }
371
+ }
372
+ return obj;
373
+ }
356
374
  const setStyleProperties = (element, styleProperties) => {
357
375
  if (!element || !styleProperties)
358
376
  return;
@@ -366,6 +384,11 @@ const removeStyleProperties = (element, styleProperties) => {
366
384
  styleProperties.forEach((styleProperty) => {
367
385
  element.style.removeProperty(styleProperty);
368
386
  });
387
+ };
388
+ const getOperationNameFromQuery = (query) => {
389
+ const regex = /(?:query|mutation)\s+(\w+)/;
390
+ const matches = query.match(regex);
391
+ return matches === null || matches === void 0 ? void 0 : matches[1];
369
392
  };
370
393
 
371
394
  /**
@@ -629,27 +652,27 @@ var HomepageModule;
629
652
  /**
630
653
  * Search bar
631
654
  */
632
- HomepageModule["Search"] = "search";
655
+ HomepageModule["Search"] = "SEARCH";
633
656
  /**
634
657
  * kPI watchlist module
635
658
  */
636
- HomepageModule["Watchlist"] = "watchlist";
659
+ HomepageModule["Watchlist"] = "WATCHLIST";
637
660
  /**
638
661
  * favorite objects
639
662
  */
640
- HomepageModule["Favorite"] = "favorite";
663
+ HomepageModule["Favorite"] = "FAVORITE";
641
664
  /**
642
665
  * List of answers and liveboards
643
666
  */
644
- HomepageModule["MyLibrary"] = "mylibrary";
667
+ HomepageModule["MyLibrary"] = "MY_LIBRARY";
645
668
  /**
646
669
  * Trending list
647
670
  */
648
- HomepageModule["Trending"] = "trending";
671
+ HomepageModule["Trending"] = "TRENDING";
649
672
  /**
650
673
  * Learning videos
651
674
  */
652
- HomepageModule["Learning"] = "learning";
675
+ HomepageModule["Learning"] = "LEARNING";
653
676
  })(HomepageModule || (HomepageModule = {}));
654
677
  /**
655
678
  * Event types emitted by the embedded ThoughtSpot application.
@@ -2797,12 +2820,6 @@ var Action;
2797
2820
  */
2798
2821
  Action["PersonalisedViewsDropdown"] = "personalisedViewsDropdown";
2799
2822
  })(Action || (Action = {}));
2800
- // eslint-disable-next-line no-shadow
2801
- var OperationType;
2802
- (function (OperationType) {
2803
- OperationType["GetChartWithData"] = "GetChartWithData";
2804
- OperationType["GetTableWithHeadlineData"] = "GetTableWithHeadlineData";
2805
- })(OperationType || (OperationType = {}));
2806
2823
  var PrefetchFeatures;
2807
2824
  (function (PrefetchFeatures) {
2808
2825
  PrefetchFeatures["FullApp"] = "FullApp";
@@ -8918,6 +8935,7 @@ function emptyQueue() {
8918
8935
  * @param sessionInfo
8919
8936
  */
8920
8937
  function initMixpanel(sessionInfo) {
8938
+ var _a;
8921
8939
  if (!sessionInfo || !sessionInfo.mixpanelToken) {
8922
8940
  return;
8923
8941
  }
@@ -8935,6 +8953,7 @@ function initMixpanel(sessionInfo) {
8935
8953
  clusterId: sessionInfo.clusterId,
8936
8954
  clusterName: sessionInfo.clusterName,
8937
8955
  releaseVersion: sessionInfo.releaseVersion,
8956
+ hostAppUrl: ((_a = window === null || window === void 0 ? void 0 : window.location) === null || _a === void 0 ? void 0 : _a.host) || '',
8938
8957
  });
8939
8958
  isMixpanelInitialized = true;
8940
8959
  emptyQueue();
@@ -10196,58 +10215,351 @@ const renderInQueue = (fn) => {
10196
10215
 
10197
10216
  /**
10198
10217
  *
10199
- * @param session
10200
- * @param query
10201
- * @param operation
10218
+ * @param root0
10219
+ * @param root0.query
10220
+ * @param root0.variables
10221
+ * @param root0.thoughtSpotHost
10222
+ * @param root0.isCompositeQuery
10223
+ */
10224
+ async function graphqlQuery({ query, variables, thoughtSpotHost, isCompositeQuery = false, }) {
10225
+ const operationName = getOperationNameFromQuery(query);
10226
+ try {
10227
+ const response = await fetch(`${thoughtSpotHost}/prism/?op=${operationName}`, {
10228
+ method: 'POST',
10229
+ headers: {
10230
+ 'content-type': 'application/json;charset=UTF-8',
10231
+ 'x-requested-by': 'ThoughtSpot',
10232
+ accept: '*/*',
10233
+ 'accept-language': 'en-us',
10234
+ },
10235
+ body: JSON.stringify({
10236
+ operationName,
10237
+ query,
10238
+ variables,
10239
+ }),
10240
+ credentials: 'include',
10241
+ });
10242
+ const result = await response.json();
10243
+ const dataValues = Object.values(result.data);
10244
+ return (isCompositeQuery) ? result.data : dataValues[0];
10245
+ }
10246
+ catch (error) {
10247
+ return error;
10248
+ }
10249
+ }
10250
+
10251
+ const getSourceDetailQuery = `
10252
+ query GetSourceDetail($ids: [GUID!]!) {
10253
+ getSourceDetailById(ids: $ids, type: LOGICAL_TABLE) {
10254
+ id
10255
+ name
10256
+ description
10257
+ authorName
10258
+ authorDisplayName
10259
+ isExternal
10260
+ type
10261
+ created
10262
+ modified
10263
+ columns {
10264
+ id
10265
+ name
10266
+ author
10267
+ authorDisplayName
10268
+ description
10269
+ dataType
10270
+ type
10271
+ modified
10272
+ ownerName
10273
+ owner
10274
+ dataRecency
10275
+ sources {
10276
+ tableId
10277
+ tableName
10278
+ columnId
10279
+ columnName
10280
+ __typename
10281
+ }
10282
+ synonyms
10283
+ cohortAnswerId
10284
+ __typename
10285
+ }
10286
+ relationships
10287
+ destinationRelationships
10288
+ dataSourceId
10289
+ __typename
10290
+ }
10291
+ }
10292
+ `;
10293
+ const sourceDetailCache = new Map();
10294
+ /**
10295
+ *
10202
10296
  * @param thoughtSpotHost
10297
+ * @param sourceId
10203
10298
  */
10204
- function getAnswerServiceInstance(session, query, operation, thoughtSpotHost) {
10205
- let variable;
10206
- const fetchQuery = async (variables) => {
10207
- try {
10208
- const response = await fetch(`${thoughtSpotHost}/prism/?op=${operation}`, {
10209
- method: 'POST',
10210
- headers: {
10211
- 'content-type': 'application/json;charset=UTF-8',
10212
- 'x-requested-by': 'ThoughtSpot',
10213
- accept: '*/*',
10214
- 'accept-language': 'en-us',
10215
- },
10216
- body: JSON.stringify({
10217
- operationName: operation,
10218
- query,
10219
- variables,
10220
- }),
10221
- credentials: 'include',
10222
- });
10223
- const result = await response.json();
10224
- return result.data;
10299
+ async function getSourceDetail(thoughtSpotHost, sourceId) {
10300
+ if (sourceDetailCache.has(sourceId)) {
10301
+ return sourceDetailCache.get(sourceId);
10302
+ }
10303
+ const details = await graphqlQuery({
10304
+ query: getSourceDetailQuery,
10305
+ variables: {
10306
+ ids: [sourceId],
10307
+ },
10308
+ thoughtSpotHost,
10309
+ });
10310
+ const souceDetails = details[0];
10311
+ sourceDetailCache.set(sourceId, souceDetails);
10312
+ return souceDetails;
10313
+ }
10314
+
10315
+ const bachSessionId = `
10316
+ id {
10317
+ sessionId
10318
+ genNo
10319
+ acSession {
10320
+ sessionId
10321
+ genNo
10322
+ }
10323
+ }
10324
+ `;
10325
+ const getUnaggregatedAnswerSession = `
10326
+ mutation GetUnAggregatedAnswerSession($session: BachSessionIdInput!, $columns: [UserPointSelectionInput!]!) {
10327
+ Answer__getUnaggregatedAnswer(session: $session, columns: $columns) {
10328
+ ${bachSessionId}
10329
+ answer {
10330
+ visualizations {
10331
+ ... on TableViz {
10332
+ columns {
10333
+ column {
10334
+ id
10335
+ name
10336
+ referencedColumns {
10337
+ guid
10338
+ displayName
10339
+ }
10340
+ }
10341
+ }
10342
+ }
10343
+ }
10344
+ }
10345
+ }
10346
+ }
10347
+ `;
10348
+ const removeColumns = `
10349
+ mutation RemoveColumns($session: BachSessionIdInput!, $logicalColumnIds: [GUID!], $columnIds: [GUID!]) {
10350
+ Answer__removeColumns(
10351
+ session: $session
10352
+ logicalColumnIds: $logicalColumnIds
10353
+ columnIds: $columnIds
10354
+ ) {
10355
+ ${bachSessionId}
10356
+ }
10357
+ }
10358
+ `;
10359
+ const addColumns = `
10360
+ mutation AddColumns($session: BachSessionIdInput!, $columns: [AnswerColumnInfo!]!) {
10361
+ Answer__addColumn(session: $session, columns: $columns) {
10362
+ ${bachSessionId}
10363
+ }
10364
+ }
10365
+ `;
10366
+ const getAnswerData = `
10367
+ query GetTableWithHeadlineData($session: BachSessionIdInput!, $deadline: Int!, $dataPaginationParams: DataPaginationParamsInput!) {
10368
+ getAnswer(session: $session) {
10369
+ ${bachSessionId}
10370
+ answer {
10371
+ id
10372
+ visualizations {
10373
+ id
10374
+ ... on TableViz {
10375
+ columns {
10376
+ column {
10377
+ id
10378
+ name
10379
+ type
10380
+ aggregationType
10381
+ dataType
10382
+ }
10383
+ }
10384
+ data(deadline: $deadline, pagination: $dataPaginationParams)
10385
+ }
10386
+ }
10387
+ }
10388
+ }
10389
+ }
10390
+ `;
10391
+
10392
+ // eslint-disable-next-line no-shadow
10393
+ var OperationType;
10394
+ (function (OperationType) {
10395
+ OperationType["GetChartWithData"] = "GetChartWithData";
10396
+ OperationType["GetTableWithHeadlineData"] = "GetTableWithHeadlineData";
10397
+ })(OperationType || (OperationType = {}));
10398
+ /**
10399
+ * Class representing the answer service provided with the
10400
+ * custom action payload. This service could be used to run
10401
+ * graphql queries in the context of the answer on which the
10402
+ * custom action was triggered.
10403
+ *
10404
+ * @example
10405
+ * ```js
10406
+ * embed.on(EmbedEvent.CustomAction, e => {
10407
+ * const underlying = await e.answerService.getUnderlyingDataForPoint([
10408
+ * 'col name 1'
10409
+ * ]);
10410
+ * const data = await underlying.fetchData(0, 100);
10411
+ * })
10412
+ * ```
10413
+ * @version
10414
+ * ThoughtSpot: 9.9.0.cl / SDK: 1.25.0
10415
+ */
10416
+ class AnswerService {
10417
+ constructor(session, answer, thoughtSpotHost, selectedPoints) {
10418
+ this.session = session;
10419
+ this.answer = answer;
10420
+ this.thoughtSpotHost = thoughtSpotHost;
10421
+ this.selectedPoints = selectedPoints;
10422
+ this.session = removeTypename(session);
10423
+ }
10424
+ async getSourceDetail() {
10425
+ const sourceId = this.answer.sources[0].header.guid;
10426
+ return getSourceDetail(this.thoughtSpotHost, sourceId);
10427
+ }
10428
+ async removeColumns(columnIds) {
10429
+ return this.executeQuery(removeColumns, {
10430
+ logicalColumnIds: columnIds,
10431
+ });
10432
+ }
10433
+ async addColumns(columnIds) {
10434
+ return this.executeQuery(addColumns, {
10435
+ columns: columnIds.map((colId) => ({ logicalColumnId: colId })),
10436
+ });
10437
+ }
10438
+ async fetchData(offset = 0, size = 1000) {
10439
+ const { answer } = await this.executeQuery(getAnswerData, {
10440
+ deadline: 0,
10441
+ dataPaginationParams: {
10442
+ isClientPaginated: true,
10443
+ offset,
10444
+ size,
10445
+ },
10446
+ });
10447
+ const { columns, data } = answer.visualizations[0];
10448
+ return {
10449
+ columns,
10450
+ data,
10451
+ };
10452
+ }
10453
+ /**
10454
+ *
10455
+ * @param userLocale
10456
+ * @param omitInfo Omit the download Info on top of the CSV
10457
+ * @returns Response
10458
+ */
10459
+ async fetchCSVBlob(userLocale = 'en-us', omitInfo = false) {
10460
+ if (omitInfo) {
10461
+ console.warn('omitInfo not supported yet.');
10225
10462
  }
10226
- catch (error) {
10227
- return error;
10463
+ const fetchUrl = `${this.thoughtSpotHost}/prism/download/answer/csv?sessionId=${this.session.sessionId}&genNo=${this.session.genNo}&userLocale=${userLocale}&exportFileName=data&omitInfo=${omitInfo}`;
10464
+ return fetch(fetchUrl, {
10465
+ credentials: 'include',
10466
+ });
10467
+ }
10468
+ async getUnderlyingDataForPoint(outputColumnNames, selectedPoints) {
10469
+ if (!selectedPoints && !this.selectedPoints) {
10470
+ throw new Error('Needs to be triggered in context of a point');
10228
10471
  }
10229
- };
10230
- const fetchData = (offset, batchSize) => {
10231
- if (operation === OperationType.GetChartWithData) {
10232
- variable = { batchSize, offset: offset * batchSize };
10472
+ if (!selectedPoints) {
10473
+ selectedPoints = getSelectedPointsForUnderlyingDataQuery(this.selectedPoints);
10474
+ }
10475
+ const sourceDetail = await this.getSourceDetail();
10476
+ const ouputColumnGuids = getGuidsFromColumnNames(sourceDetail, outputColumnNames);
10477
+ const unAggAnswer = await graphqlQuery({
10478
+ query: getUnaggregatedAnswerSession,
10479
+ variables: {
10480
+ session: this.session,
10481
+ columns: selectedPoints,
10482
+ },
10483
+ thoughtSpotHost: this.thoughtSpotHost,
10484
+ });
10485
+ const unaggAnswerSession = new AnswerService(unAggAnswer.id, unAggAnswer.answer, this.thoughtSpotHost);
10486
+ const currentColumns = new Set(unAggAnswer.answer.visualizations[0].columns
10487
+ .map((c) => c.column.referencedColumns[0].guid));
10488
+ const columnsToAdd = [...ouputColumnGuids].filter((col) => !currentColumns.has(col));
10489
+ if (columnsToAdd.length) {
10490
+ await unaggAnswerSession.addColumns(columnsToAdd);
10491
+ }
10492
+ const columnsToRemove = [...currentColumns].filter((col) => !ouputColumnGuids.has(col));
10493
+ if (columnsToRemove.length) {
10494
+ await unaggAnswerSession.removeColumns(columnsToRemove);
10495
+ }
10496
+ return unaggAnswerSession;
10497
+ }
10498
+ async executeQuery(query, variables) {
10499
+ const data = await graphqlQuery({
10500
+ query,
10501
+ variables: {
10502
+ session: this.session,
10503
+ ...variables,
10504
+ },
10505
+ thoughtSpotHost: this.thoughtSpotHost,
10506
+ isCompositeQuery: false,
10507
+ });
10508
+ this.session = deepMerge(this.session, (data === null || data === void 0 ? void 0 : data.id) || {});
10509
+ return data;
10510
+ }
10511
+ getSession() {
10512
+ return this.session;
10513
+ }
10514
+ }
10515
+ /**
10516
+ *
10517
+ * @param sourceDetail
10518
+ * @param colNames
10519
+ */
10520
+ function getGuidsFromColumnNames(sourceDetail, colNames) {
10521
+ const cols = sourceDetail.columns.reduce((colSet, col) => {
10522
+ colSet[col.name] = col;
10523
+ return colSet;
10524
+ }, {});
10525
+ return new Set(colNames.map((colName) => {
10526
+ const col = cols[colName];
10527
+ return col.id;
10528
+ }));
10529
+ }
10530
+ /**
10531
+ *
10532
+ * @param selectedPoints
10533
+ */
10534
+ function getSelectedPointsForUnderlyingDataQuery(selectedPoints) {
10535
+ const underlyingDataPoint = [];
10536
+ /**
10537
+ *
10538
+ * @param colVal
10539
+ */
10540
+ function addPointFromColVal(colVal) {
10541
+ const dataType = colVal.column.dataType;
10542
+ const id = colVal.column.id;
10543
+ let dataValue;
10544
+ if (dataType === 'DATE') {
10545
+ dataValue = [{
10546
+ epochRange: {
10547
+ startEpoch: colVal.value,
10548
+ },
10549
+ }];
10233
10550
  }
10234
10551
  else {
10235
- variable = {
10236
- dataPaginationParams: {
10237
- isClientPaginated: true,
10238
- offset: offset * batchSize,
10239
- size: batchSize,
10240
- },
10241
- };
10552
+ dataValue = [{ value: colVal.value }];
10242
10553
  }
10243
- return fetchQuery({
10244
- session,
10245
- ...variable,
10554
+ underlyingDataPoint.push({
10555
+ columnId: colVal.column.id,
10556
+ dataValue,
10246
10557
  });
10247
- };
10248
- return {
10249
- fetchData,
10250
- };
10558
+ }
10559
+ selectedPoints.forEach((p) => {
10560
+ p.selectedAttributes.forEach(addPointFromColVal);
10561
+ });
10562
+ return underlyingDataPoint;
10251
10563
  }
10252
10564
 
10253
10565
  /**
@@ -10256,16 +10568,12 @@ function getAnswerServiceInstance(session, query, operation, thoughtSpotHost) {
10256
10568
  * @param thoughtSpotHost
10257
10569
  */
10258
10570
  function processCustomAction(e, thoughtSpotHost) {
10259
- var _a;
10260
- if ([OperationType.GetChartWithData, OperationType.GetTableWithHeadlineData].includes((_a = e.data) === null || _a === void 0 ? void 0 : _a.operation)) {
10261
- const { session, query, operation } = e.data;
10262
- const answerService = getAnswerServiceInstance(session, query, operation, thoughtSpotHost);
10263
- return {
10264
- ...e,
10265
- answerService,
10266
- };
10267
- }
10268
- return e;
10571
+ const { session, embedAnswerData, contextMenuPoints } = e.data;
10572
+ const answerService = new AnswerService(session, embedAnswerData, thoughtSpotHost, contextMenuPoints === null || contextMenuPoints === void 0 ? void 0 : contextMenuPoints.selectedPoints);
10573
+ return {
10574
+ ...e,
10575
+ answerService,
10576
+ };
10269
10577
  }
10270
10578
  /**
10271
10579
  *
@@ -10410,7 +10718,7 @@ function processTrigger(iFrame, messageType, thoughtSpotHost, data) {
10410
10718
  });
10411
10719
  }
10412
10720
 
10413
- var name="@thoughtspot/visual-embed-sdk";var version="1.24.0-dev";var description="ThoughtSpot Embed SDK";var module="lib/src/index.js";var main="dist/tsembed.js";var types="lib/src/index.d.ts";var files=["dist/**","lib/**","src/**","cjs/**"];var exports={".":{"import":"./lib/src/index.js",require:"./cjs/src/index.js",types:"./lib/src/index.d.ts"},"./react":{"import":"./lib/src/react/all-types-export.js",require:"./cjs/src/react/all-types-export.js",types:"./lib/src/react/all-types-export.d.ts"},"./lib/src/react":{"import":"./lib/src/react/all-types-export.js",require:"./cjs/src/react/all-types-export.js",types:"./lib/src/react/all-types-export.d.ts"}};var typesVersions={"*":{react:["./lib/src/react/all-types-export.d.ts"]}};var scripts={lint:"eslint 'src/**'","lint:fix":"eslint 'src/**/*.*' --fix",tsc:"tsc -p . --incremental false; tsc -p . --incremental false --module commonjs --outDir cjs",start:"gatsby develop","build:gatsby":"npm run clean:gatsby && gatsby build --prefix-paths","build:gatsby:noprefix":"npm run clean:gatsby && gatsby build","serve:gatsby":"gatsby serve","clean:gatsby":"gatsby clean","build-and-publish":"npm run build:gatsby && npm run publish","bundle-dts-file":"dts-bundle --name @thoughtspot/visual-embed-sdk --out visual-embed-sdk.d.ts --main lib/src/index.d.ts","bundle-dts":"dts-bundle --name ../../dist/visual-embed-sdk --main lib/src/index.d.ts --outputAsModuleFolder=true","bundle-dts-react":"dts-bundle --name ../../../dist/visual-embed-sdk-react --main lib/src/react/index.d.ts --outputAsModuleFolder=true","bundle-dts-react-full":"dts-bundle --name ../../../dist/visual-embed-sdk-react-full --main lib/src/react/all-types-export.d.ts --outputAsModuleFolder=true",build:"rollup -c",watch:"rollup -cw","docs-cmd":"node scripts/gatsby-commands.js",docgen:"typedoc --tsconfig tsconfig.json --theme typedoc-theme","test-sdk":"jest -c jest.config.sdk.js --runInBand","test-docs":"jest -c jest.config.docs.js",test:"npm run test-sdk && npm run test-docs",posttest:"cat ./coverage/sdk/lcov.info | coveralls","is-publish-allowed":"node scripts/is-publish-allowed.js",prepublishOnly:"npm run tsc && npm run bundle-dts-file && npm run bundle-dts && npm run bundle-dts-react && npm run bundle-dts-react-full && npm run build","check-size":"npm run build && size-limit","publish-dev":"npm publish --tag dev","publish-prod":"npm publish --tag latest"};var peerDependencies={react:"> 16.8.0","react-dom":"> 16.8.0"};var dependencies={algoliasearch:"^4.10.5",classnames:"^2.3.1",dompurify:"^2.3.4","eslint-plugin-comment-length":"^0.9.2","eslint-plugin-jsdoc":"^40.1.0",eventemitter3:"^4.0.7","gatsby-plugin-vercel":"^1.0.3","html-react-parser":"^1.4.12",lodash:"^4.17.21","mixpanel-browser":"^2.45.0","ts-deepmerge":"^6.0.2",tslib:"^2.5.3","use-deep-compare-effect":"^1.8.1"};var devDependencies={"@mdx-js/mdx":"^1.6.22","@mdx-js/react":"^1.6.22","@react-icons/all-files":"^4.1.0","@rollup/plugin-commonjs":"^18.0.0","@rollup/plugin-json":"^4.1.0","@rollup/plugin-node-resolve":"^11.2.1","@rollup/plugin-replace":"^5.0.2","@size-limit/preset-big-lib":"^8.2.6","@testing-library/dom":"^7.31.0","@testing-library/jest-dom":"^5.14.1","@testing-library/react":"^11.2.7","@testing-library/user-event":"^13.1.8","@types/jest":"^22.2.3","@types/mixpanel-browser":"^2.35.6","@types/react-test-renderer":"^17.0.1","@typescript-eslint/eslint-plugin":"^4.6.0","@typescript-eslint/parser":"^4.6.0",asciidoctor:"^2.2.1","babel-jest":"^26.6.3","babel-preset-gatsby":"^1.10.0","command-line-args":"^5.1.1",coveralls:"^3.1.0","current-git-branch":"^1.1.0","dts-bundle":"^0.7.3",eslint:"^7.12.1","eslint-config-airbnb-base":"^14.2.0","eslint-config-prettier":"^6.15.0","eslint-import-resolver-typescript":"^2.3.0","eslint-plugin-import":"^2.22.1","eslint-plugin-prettier":"^3.1.4","eslint-plugin-react-hooks":"^4.2.0","fs-extra":"^10.0.0",gatsby:"3.13.1","gatsby-plugin-algolia":"^0.22.2","gatsby-plugin-catch-links":"^3.1.0","gatsby-plugin-env-variables":"^2.1.0","gatsby-plugin-intl":"^0.3.3","gatsby-plugin-manifest":"^3.2.0","gatsby-plugin-output":"^0.1.3","gatsby-plugin-sass":"6.7.0","gatsby-plugin-sitemap":"^4.10.0","gatsby-source-filesystem":"3.1.0","gatsby-transformer-asciidoc":"2.1.0","gatsby-transformer-rehype":"2.0.0","gh-pages":"^3.1.0","highlight.js":"^10.6.0","html-to-text":"^8.0.0","identity-obj-proxy":"^3.0.0","istanbul-merge":"^1.1.1",jest:"^26.6.3","jest-puppeteer":"^4.4.0",jsdom:"^17.0.0","node-sass":"^8.0.0",prettier:"2.1.2",puppeteer:"^7.0.1",react:"^16.14.0","react-dom":"^16.14.0","react-resizable":"^1.11.0","react-resize-detector":"^6.6.0","react-test-renderer":"^17.0.2","react-use-flexsearch":"^0.1.1",rollup:"2.30.0","rollup-plugin-typescript2":"0.27.3","ts-jest":"^26.5.5","ts-loader":"8.0.4",typedoc:"0.21.6","typedoc-plugin-toc-group":"thoughtspot/typedoc-plugin-toc-group",typescript:"^4.9.4","url-search-params-polyfill":"^8.1.0",util:"^0.12.4"};var author="ThoughtSpot";var email="support@thoughtspot.com";var license="ThoughtSpot Development Tools End User License Agreement";var directories={lib:"lib"};var repository={type:"git",url:"git+https://github.com/thoughtspot/visual-embed-sdk.git"};var publishConfig={registry:"https://registry.npmjs.org"};var keywords=["thoughtspot","everywhere","embed","sdk","analytics"];var bugs={url:"https://github.com/thoughtspot/visual-embed-sdk/issues"};var homepage="https://github.com/thoughtspot/visual-embed-sdk#readme";var globals={window:{}};var pkgInfo = {name:name,version:version,description:description,module:module,main:main,types:types,files:files,exports:exports,typesVersions:typesVersions,"size-limit":[{path:"dist/tsembed.js",limit:"40 kB"}],scripts:scripts,peerDependencies:peerDependencies,dependencies:dependencies,devDependencies:devDependencies,author:author,email:email,license:license,directories:directories,repository:repository,publishConfig:publishConfig,keywords:keywords,bugs:bugs,homepage:homepage,globals:globals};
10721
+ var name="@thoughtspot/visual-embed-sdk";var version="1.24.0-preRender.0";var description="ThoughtSpot Embed SDK";var module="lib/src/index.js";var main="dist/tsembed.js";var types="lib/src/index.d.ts";var files=["dist/**","lib/**","src/**","cjs/**"];var exports={".":{"import":"./lib/src/index.js",require:"./cjs/src/index.js",types:"./lib/src/index.d.ts"},"./react":{"import":"./lib/src/react/all-types-export.js",require:"./cjs/src/react/all-types-export.js",types:"./lib/src/react/all-types-export.d.ts"},"./lib/src/react":{"import":"./lib/src/react/all-types-export.js",require:"./cjs/src/react/all-types-export.js",types:"./lib/src/react/all-types-export.d.ts"}};var typesVersions={"*":{react:["./lib/src/react/all-types-export.d.ts"]}};var scripts={lint:"eslint 'src/**'","lint:fix":"eslint 'src/**/*.*' --fix",tsc:"tsc -p . --incremental false; tsc -p . --incremental false --module commonjs --outDir cjs",start:"gatsby develop","build:gatsby":"npm run clean:gatsby && gatsby build --prefix-paths","build:gatsby:noprefix":"npm run clean:gatsby && gatsby build","serve:gatsby":"gatsby serve","clean:gatsby":"gatsby clean","build-and-publish":"npm run build:gatsby && npm run publish","bundle-dts-file":"dts-bundle --name @thoughtspot/visual-embed-sdk --out visual-embed-sdk.d.ts --main lib/src/index.d.ts","bundle-dts":"dts-bundle --name ../../dist/visual-embed-sdk --main lib/src/index.d.ts --outputAsModuleFolder=true","bundle-dts-react":"dts-bundle --name ../../../dist/visual-embed-sdk-react --main lib/src/react/index.d.ts --outputAsModuleFolder=true","bundle-dts-react-full":"dts-bundle --name ../../../dist/visual-embed-sdk-react-full --main lib/src/react/all-types-export.d.ts --outputAsModuleFolder=true",build:"rollup -c",watch:"rollup -cw","docs-cmd":"node scripts/gatsby-commands.js",docgen:"typedoc --tsconfig tsconfig.json --theme typedoc-theme","test-sdk":"jest -c jest.config.sdk.js --runInBand","test-docs":"jest -c jest.config.docs.js",test:"npm run test-sdk && npm run test-docs",posttest:"cat ./coverage/sdk/lcov.info | coveralls","is-publish-allowed":"node scripts/is-publish-allowed.js",prepublishOnly:"npm run tsc && npm run bundle-dts-file && npm run bundle-dts && npm run bundle-dts-react && npm run bundle-dts-react-full && npm run build","check-size":"npm run build && size-limit","publish-dev":"npm publish --tag dev","publish-prod":"npm publish --tag latest"};var peerDependencies={react:"> 16.8.0","react-dom":"> 16.8.0"};var dependencies={algoliasearch:"^4.10.5",classnames:"^2.3.1",dompurify:"^2.3.4","eslint-plugin-comment-length":"^0.9.2","eslint-plugin-jsdoc":"^40.1.0",eventemitter3:"^4.0.7","gatsby-plugin-vercel":"^1.0.3","html-react-parser":"^1.4.12",lodash:"^4.17.21","mixpanel-browser":"^2.45.0","ts-deepmerge":"^6.0.2",tslib:"^2.5.3","use-deep-compare-effect":"^1.8.1"};var devDependencies={"@mdx-js/mdx":"^1.6.22","@mdx-js/react":"^1.6.22","@react-icons/all-files":"^4.1.0","@rollup/plugin-commonjs":"^18.0.0","@rollup/plugin-json":"^4.1.0","@rollup/plugin-node-resolve":"^11.2.1","@rollup/plugin-replace":"^5.0.2","@size-limit/preset-big-lib":"^8.2.6","@testing-library/dom":"^7.31.0","@testing-library/jest-dom":"^5.14.1","@testing-library/react":"^11.2.7","@testing-library/user-event":"^13.1.8","@types/jest":"^22.2.3","@types/mixpanel-browser":"^2.35.6","@types/react-test-renderer":"^17.0.1","@typescript-eslint/eslint-plugin":"^4.6.0","@typescript-eslint/parser":"^4.6.0",asciidoctor:"^2.2.1","babel-jest":"^26.6.3","babel-preset-gatsby":"^1.10.0","command-line-args":"^5.1.1",coveralls:"^3.1.0","current-git-branch":"^1.1.0","dts-bundle":"^0.7.3",eslint:"^7.12.1","eslint-config-airbnb-base":"^14.2.0","eslint-config-prettier":"^6.15.0","eslint-import-resolver-typescript":"^2.3.0","eslint-plugin-import":"^2.22.1","eslint-plugin-prettier":"^3.1.4","eslint-plugin-react-hooks":"^4.2.0","fs-extra":"^10.0.0",gatsby:"3.13.1","gatsby-plugin-algolia":"^0.22.2","gatsby-plugin-catch-links":"^3.1.0","gatsby-plugin-env-variables":"^2.1.0","gatsby-plugin-intl":"^0.3.3","gatsby-plugin-manifest":"^3.2.0","gatsby-plugin-output":"^0.1.3","gatsby-plugin-sass":"6.7.0","gatsby-plugin-sitemap":"^4.10.0","gatsby-source-filesystem":"3.1.0","gatsby-transformer-asciidoc":"2.1.0","gatsby-transformer-rehype":"2.0.0","gh-pages":"^3.1.0","highlight.js":"^10.6.0","html-to-text":"^8.0.0","identity-obj-proxy":"^3.0.0","istanbul-merge":"^1.1.1",jest:"^26.6.3","jest-fetch-mock":"^3.0.3",jsdom:"^17.0.0","node-sass":"^8.0.0",prettier:"2.1.2",react:"^16.14.0","react-dom":"^16.14.0","react-resizable":"^1.11.0","react-resize-detector":"^6.6.0","react-test-renderer":"^17.0.2","react-use-flexsearch":"^0.1.1",rollup:"2.30.0","rollup-plugin-typescript2":"0.27.3","ts-jest":"^26.5.5","ts-loader":"8.0.4",typedoc:"0.21.6","typedoc-plugin-toc-group":"thoughtspot/typedoc-plugin-toc-group",typescript:"^4.9.4","url-search-params-polyfill":"^8.1.0",util:"^0.12.4"};var author="ThoughtSpot";var email="support@thoughtspot.com";var license="ThoughtSpot Development Tools End User License Agreement";var directories={lib:"lib"};var repository={type:"git",url:"git+https://github.com/thoughtspot/visual-embed-sdk.git"};var publishConfig={registry:"https://registry.npmjs.org"};var keywords=["thoughtspot","everywhere","embed","sdk","analytics"];var bugs={url:"https://github.com/thoughtspot/visual-embed-sdk/issues"};var homepage="https://github.com/thoughtspot/visual-embed-sdk#readme";var globals={window:{}};var pkgInfo = {name:name,version:version,description:description,module:module,main:main,types:types,files:files,exports:exports,typesVersions:typesVersions,"size-limit":[{path:"dist/tsembed.js",limit:"40 kB"}],scripts:scripts,peerDependencies:peerDependencies,dependencies:dependencies,devDependencies:devDependencies,author:author,email:email,license:license,directories:directories,repository:repository,publishConfig:publishConfig,keywords:keywords,bugs:bugs,homepage:homepage,globals:globals};
10414
10722
 
10415
10723
  /**
10416
10724
  * Copyright (c) 2022
@@ -10442,6 +10750,7 @@ const V1EventMap = {};
10442
10750
  class TsEmbed {
10443
10751
  constructor(domSelector, viewConfig) {
10444
10752
  this.isAppInitialized = false;
10753
+ this.embedComponentType = 'TsEmbed';
10445
10754
  /**
10446
10755
  * Should we encode URL Query Params using base64 encoding which thoughtspot
10447
10756
  * will generate for embedding. This provides additional security to
@@ -10451,6 +10760,7 @@ class TsEmbed {
10451
10760
  */
10452
10761
  this.shouldEncodeUrlQueryParams = false;
10453
10762
  this.defaultHiddenActions = [Action.ReportError];
10763
+ this.subscribedListeners = {};
10454
10764
  /**
10455
10765
  * Send Custom style as part of payload of APP_INIT
10456
10766
  *
@@ -10473,6 +10783,7 @@ class TsEmbed {
10473
10783
  ? getRuntimeFilters(this.viewConfig.runtimeFilters)
10474
10784
  : null,
10475
10785
  hiddenHomepageModules: this.viewConfig.hiddenHomepageModules || [],
10786
+ reorderedHomepageModules: this.viewConfig.reorderedHomepageModules || [],
10476
10787
  hostConfig: this.embedConfig.hostConfig,
10477
10788
  hiddenHomeLeftNavItems: ((_a = this.viewConfig) === null || _a === void 0 ? void 0 : _a.hiddenHomeLeftNavItems)
10478
10789
  ? (_b = this.viewConfig) === null || _b === void 0 ? void 0 : _b.hiddenHomeLeftNavItems
@@ -10522,6 +10833,7 @@ class TsEmbed {
10522
10833
  this.registerAppInit();
10523
10834
  uploadMixpanelEvent(MIXPANEL_EVENT.VISUAL_SDK_EMBED_CREATE, {
10524
10835
  ...viewConfig,
10836
+ embedComponentType: this.embedComponentType,
10525
10837
  });
10526
10838
  }
10527
10839
  /**
@@ -10590,23 +10902,36 @@ class TsEmbed {
10590
10902
  * and executes the registered callbacks accordingly.
10591
10903
  */
10592
10904
  subscribeToEvents() {
10593
- window.addEventListener('message', (event) => {
10905
+ const messageEventListener = (event) => {
10594
10906
  const eventType = this.getEventType(event);
10595
10907
  const eventPort = this.getEventPort(event);
10596
10908
  const eventData = this.formatEventData(event, eventType);
10597
10909
  if (event.source === this.iFrame.contentWindow) {
10598
10910
  this.executeCallbacks(eventType, processEventData(eventType, eventData, this.thoughtSpotHost, this.el), eventPort);
10599
10911
  }
10600
- });
10601
- window.addEventListener('online', (e) => {
10912
+ };
10913
+ window.addEventListener('message', messageEventListener);
10914
+ const onlineEventListener = (e) => {
10602
10915
  this.trigger(HostEvent.Reload);
10603
- });
10604
- window.addEventListener('offline', (e) => {
10916
+ };
10917
+ window.addEventListener('online', onlineEventListener);
10918
+ const offlineEventListener = (e) => {
10605
10919
  const offlineWarning = 'Network not Detected. Embed is offline. Please reconnect and refresh';
10606
10920
  this.executeCallbacks(EmbedEvent.Error, {
10607
10921
  offlineWarning,
10608
10922
  });
10609
10923
  console.warn(offlineWarning);
10924
+ };
10925
+ window.addEventListener('offline', offlineEventListener);
10926
+ this.subscribedListeners = {
10927
+ message: messageEventListener,
10928
+ online: onlineEventListener,
10929
+ offline: offlineEventListener,
10930
+ };
10931
+ }
10932
+ unsubscribeToEvents() {
10933
+ Object.keys(this.subscribedListeners).forEach((key) => {
10934
+ window.removeEventListener(key, this.subscribedListeners[key]);
10610
10935
  });
10611
10936
  }
10612
10937
  /**
@@ -10784,8 +11109,10 @@ class TsEmbed {
10784
11109
  *
10785
11110
  * @param url
10786
11111
  * @param frameOptions
11112
+ * @param showPreRender
11113
+ * @param showPreRenderByDefault
10787
11114
  */
10788
- async renderIFrame(url) {
11115
+ async renderIFrame(url, showPreRenderByDefault = false) {
10789
11116
  if (this.isError) {
10790
11117
  return null;
10791
11118
  }
@@ -10834,6 +11161,9 @@ class TsEmbed {
10834
11161
  });
10835
11162
  if (this.isPreRendered) {
10836
11163
  this.insertIntoDOMForPreRender(this.iFrame);
11164
+ if (showPreRenderByDefault) {
11165
+ this.showPreRender();
11166
+ }
10837
11167
  }
10838
11168
  else {
10839
11169
  this.insertIntoDOM(this.iFrame);
@@ -10872,11 +11202,10 @@ class TsEmbed {
10872
11202
  throw new Error('Pre render id is required');
10873
11203
  }
10874
11204
  const preRenderIds = this.getPreRenderIds();
10875
- const stalePreRenderWrapper = document.getElementById(preRenderIds.wrapper);
10876
- if (stalePreRenderWrapper) {
10877
- console.log('Found stale wrapper , removing');
10878
- stalePreRenderWrapper.remove();
10879
- }
11205
+ [preRenderIds.wrapper, preRenderIds.shield, preRenderIds.child]
11206
+ .map((id) => document.getElementById(id))
11207
+ .filter((element) => element)
11208
+ .forEach((existingElement) => existingElement.remove());
10880
11209
  const preRenderWrapper = document.createElement('div');
10881
11210
  preRenderWrapper.id = preRenderIds.wrapper;
10882
11211
  setStyleProperties(preRenderWrapper, { position: 'absolute', width: '100vw', height: '100vh' });
@@ -10891,7 +11220,7 @@ class TsEmbed {
10891
11220
  this.preRenderChild = child;
10892
11221
  return preRenderWrapper;
10893
11222
  }
10894
- isPreRenderAvailable() {
11223
+ connectPreRendered() {
10895
11224
  const preRenderIds = this.getPreRenderIds();
10896
11225
  this.preRenderWrapper = this.preRenderWrapper
10897
11226
  || document.getElementById(preRenderIds.wrapper);
@@ -10899,6 +11228,10 @@ class TsEmbed {
10899
11228
  || document.getElementById(preRenderIds.shield);
10900
11229
  this.preRenderChild = this.preRenderChild
10901
11230
  || document.getElementById(preRenderIds.child);
11231
+ this.iFrame = this.preRenderChild;
11232
+ return this.isPreRenderAvailable();
11233
+ }
11234
+ isPreRenderAvailable() {
10902
11235
  return !!this.preRenderWrapper && !!this.preRenderShield
10903
11236
  && !!this.preRenderChild;
10904
11237
  }
@@ -10941,18 +11274,23 @@ class TsEmbed {
10941
11274
  top: '0',
10942
11275
  left: '0',
10943
11276
  });
11277
+ this.unsubscribeToEvents();
10944
11278
  }
10945
11279
  showPreRender() {
10946
11280
  if (!this.isPreRenderAvailable()) {
10947
- // if the Embed component is nor preRendered , Render it now and
10948
- // show it (hide is defalt behaviour)
10949
- console.log('No preRender found, creating new ');
10950
- this.render();
10951
- return;
11281
+ const isAvailable = this.connectPreRendered();
11282
+ if (!isAvailable) {
11283
+ // if the Embed component is nor preRendered , Render it now and
11284
+ // show it (hide is defalt behaviour)
11285
+ console.log('No preRender found, creating new ');
11286
+ this.preRender(true);
11287
+ return;
11288
+ }
10952
11289
  }
10953
11290
  this.syncPreRenderStyle();
10954
11291
  removeStyleProperties(this.preRenderWrapper, ['z-index', 'opacity', 'pointer-events']);
10955
11292
  setStyleProperties(this.preRenderShield, { zIndex: '-1' });
11293
+ this.subscribeToEvents();
10956
11294
  }
10957
11295
  syncPreRenderStyle() {
10958
11296
  if (!this.el) {
@@ -11180,7 +11518,7 @@ class TsEmbed {
11180
11518
  /**
11181
11519
  * Creates the preRender shell
11182
11520
  */
11183
- preRender() {
11521
+ preRender(showPreRenderByDefault = false) {
11184
11522
  this.isPreRendered = true;
11185
11523
  return this;
11186
11524
  }
@@ -11257,8 +11595,8 @@ class V1Embed extends TsEmbed {
11257
11595
  *
11258
11596
  * @param iframeSrc
11259
11597
  */
11260
- renderV1Embed(iframeSrc) {
11261
- return this.renderIFrame(iframeSrc);
11598
+ renderV1Embed(iframeSrc, showPreRenderByDefault = false) {
11599
+ return this.renderIFrame(iframeSrc, showPreRenderByDefault);
11262
11600
  }
11263
11601
  getRootIframeSrc() {
11264
11602
  const queryParams = this.getEmbedParams();
@@ -11304,6 +11642,7 @@ class V1Embed extends TsEmbed {
11304
11642
  class SearchBarEmbed extends TsEmbed {
11305
11643
  constructor(domSelector, viewConfig) {
11306
11644
  super(domSelector);
11645
+ this.embedComponentType = 'SearchBarEmbed';
11307
11646
  this.viewConfig = viewConfig;
11308
11647
  }
11309
11648
  /**
@@ -11382,6 +11721,7 @@ class SageEmbed extends V1Embed {
11382
11721
  // eslint-disable-next-line no-useless-constructor
11383
11722
  constructor(domSelector, viewConfig) {
11384
11723
  super(domSelector, viewConfig);
11724
+ this.embedComponentType = 'SageEmbed';
11385
11725
  }
11386
11726
  /**
11387
11727
  * Constructs a map of parameters to be passed on to the
@@ -11433,12 +11773,18 @@ class SageEmbed extends V1Embed {
11433
11773
  /**
11434
11774
  * Render the embedded ThoughtSpot Sage
11435
11775
  *
11776
+ * @param showPreRenderByDefault
11436
11777
  * @returns {SageEmbed} Eureka/Sage embed
11437
11778
  */
11438
- render() {
11779
+ render(showPreRenderByDefault = false) {
11439
11780
  super.render();
11440
11781
  const src = this.getIFrameSrc();
11441
- this.renderV1Embed(src);
11782
+ this.renderV1Embed(src, showPreRenderByDefault);
11783
+ return this;
11784
+ }
11785
+ preRender(showPreRenderByDefault = false) {
11786
+ super.preRender(showPreRenderByDefault);
11787
+ this.render(showPreRenderByDefault);
11442
11788
  return this;
11443
11789
  }
11444
11790
  }
@@ -11466,6 +11812,7 @@ const HiddenActionItemByDefaultForSearchEmbed = [
11466
11812
  class SearchEmbed extends TsEmbed {
11467
11813
  constructor(domSelector, viewConfig) {
11468
11814
  super(domSelector);
11815
+ this.embedComponentType = 'SearchEmbed';
11469
11816
  this.viewConfig = viewConfig;
11470
11817
  }
11471
11818
  /**
@@ -11546,12 +11893,14 @@ class SearchEmbed extends TsEmbed {
11546
11893
  }
11547
11894
  /**
11548
11895
  * Render the embedded ThoughtSpot search
11896
+ *
11897
+ * @param showPreRenderByDefault
11549
11898
  */
11550
- render() {
11899
+ render(showPreRenderByDefault = false) {
11551
11900
  super.render();
11552
11901
  const { answerId } = this.viewConfig;
11553
11902
  const src = this.getIFrameSrc(answerId);
11554
- this.renderIFrame(src);
11903
+ this.renderIFrame(src, showPreRenderByDefault);
11555
11904
  getAuthPromise().then(() => {
11556
11905
  if (checkReleaseVersionInBeta(getReleaseVersion(), getEmbedConfig().suppressSearchEmbedBetaWarning)) {
11557
11906
  alert(ERROR_MESSAGE.SEARCHEMBED_BETA_WRANING_MESSAGE);
@@ -11559,6 +11908,11 @@ class SearchEmbed extends TsEmbed {
11559
11908
  });
11560
11909
  return this;
11561
11910
  }
11911
+ preRender(showPreRenderByDefault = false) {
11912
+ super.preRender(showPreRenderByDefault);
11913
+ this.render(showPreRenderByDefault);
11914
+ return this;
11915
+ }
11562
11916
  }
11563
11917
 
11564
11918
  /**
@@ -11616,6 +11970,7 @@ class AppEmbed extends V1Embed {
11616
11970
  constructor(domSelector, viewConfig) {
11617
11971
  super(domSelector, viewConfig);
11618
11972
  this.defaultHeight = '100%';
11973
+ this.embedComponentType = 'AppEmbed';
11619
11974
  /**
11620
11975
  * Set the iframe height as per the computed height received
11621
11976
  * from the ThoughtSpot app.
@@ -11767,10 +12122,15 @@ class AppEmbed extends V1Embed {
11767
12122
  * @param renderOptions An object containing the page ID
11768
12123
  * to be embedded.
11769
12124
  */
11770
- render() {
12125
+ render(showPreRenderByDefault = false) {
11771
12126
  super.render();
11772
12127
  const src = this.getIFrameSrc();
11773
- this.renderV1Embed(src);
12128
+ this.renderV1Embed(src, showPreRenderByDefault);
12129
+ return this;
12130
+ }
12131
+ preRender(showPreRenderByDefault = false) {
12132
+ super.preRender(showPreRenderByDefault);
12133
+ this.render(showPreRenderByDefault);
11774
12134
  return this;
11775
12135
  }
11776
12136
  }
@@ -11805,6 +12165,7 @@ class LiveboardEmbed extends V1Embed {
11805
12165
  constructor(domSelector, viewConfig) {
11806
12166
  super(domSelector, viewConfig);
11807
12167
  this.defaultHeight = 500;
12168
+ this.embedComponentType = 'LiveboardEmbed';
11808
12169
  /**
11809
12170
  * Set the iframe height as per the computed height received
11810
12171
  * from the ThoughtSpot app.
@@ -11926,15 +12287,15 @@ class LiveboardEmbed extends V1Embed {
11926
12287
  * @param renderOptions An object specifying the Liveboard ID,
11927
12288
  * visualization ID and the runtime filters.
11928
12289
  */
11929
- render() {
12290
+ render(showPreRenderByDefault = false) {
11930
12291
  super.render();
11931
12292
  const src = this.getIFrameSrc();
11932
- this.renderV1Embed(src);
12293
+ this.renderV1Embed(src, showPreRenderByDefault);
11933
12294
  return this;
11934
12295
  }
11935
- preRender() {
11936
- super.preRender();
11937
- this.render();
12296
+ preRender(showPreRenderByDefault = false) {
12297
+ super.preRender(showPreRenderByDefault);
12298
+ this.render(showPreRenderByDefault);
11938
12299
  return this;
11939
12300
  }
11940
12301
  navigateToLiveboard(liveboardId, vizId, activeTabId) {
@@ -11979,9 +12340,7 @@ const componentFactory = (EmbedConstructor, isPreRenderedComponent = false) => R
11979
12340
  const tsEmbed = new EmbedConstructor(ref.current, deepMerge({
11980
12341
  insertAsSibling: viewConfig.insertAsSibling,
11981
12342
  frameParams: {
11982
- class: viewConfig.insertAsSibling
11983
- ? className || ''
11984
- : '',
12343
+ class: viewConfig.insertAsSibling ? className || '' : '',
11985
12344
  },
11986
12345
  }, viewConfig));
11987
12346
  Object.keys(listeners).forEach((eventName) => {
@@ -12009,9 +12368,7 @@ const componentFactory = (EmbedConstructor, isPreRenderedComponent = false) => R
12009
12368
  }
12010
12369
  };
12011
12370
  }, [viewConfig, listeners]);
12012
- return ((viewConfig.insertAsSibling)
12013
- ? React.createElement("span", { "data-testid": "tsEmbed", ref: ref, style: { position: 'absolute' } })
12014
- : React.createElement("div", { "data-testid": "tsEmbed", ref: ref, className: className }));
12371
+ return viewConfig.insertAsSibling ? (React.createElement("span", { "data-testid": "tsEmbed", ref: ref, style: { position: 'absolute' } })) : (React.createElement("div", { "data-testid": "tsEmbed", ref: ref, className: className }));
12015
12372
  });
12016
12373
  /**
12017
12374
  * React component for Search Embed.
@@ -12042,6 +12399,7 @@ const SearchEmbed$1 = componentFactory(SearchEmbed);
12042
12399
  * ```
12043
12400
  */
12044
12401
  const AppEmbed$1 = componentFactory(AppEmbed);
12402
+ const PreRenderedAppEmbed = componentFactory(AppEmbed, true);
12045
12403
  /**
12046
12404
  * React component for Liveboard embed.
12047
12405
  *
@@ -12059,6 +12417,8 @@ const AppEmbed$1 = componentFactory(AppEmbed);
12059
12417
  */
12060
12418
  const LiveboardEmbed$1 = componentFactory(LiveboardEmbed);
12061
12419
  const PinboardEmbed = LiveboardEmbed$1;
12420
+ const PreRenderedLiveboardEmbed = componentFactory(LiveboardEmbed, true);
12421
+ const PreRenderedPinboardEmbed = PreRenderedLiveboardEmbed;
12062
12422
  /**
12063
12423
  * React component for Search bar embed.
12064
12424
  *
@@ -12073,6 +12433,7 @@ const PinboardEmbed = LiveboardEmbed$1;
12073
12433
  * ```
12074
12434
  */
12075
12435
  const SearchBarEmbed$1 = componentFactory(SearchBarEmbed);
12436
+ const PreRenderedSearchBarEmbed = componentFactory(SearchBarEmbed, true);
12076
12437
  /**
12077
12438
  * React component for LLM based search Sage embed.
12078
12439
  *
@@ -12087,6 +12448,7 @@ const SearchBarEmbed$1 = componentFactory(SearchBarEmbed);
12087
12448
  * ```
12088
12449
  */
12089
12450
  const SageEmbed$1 = componentFactory(SageEmbed);
12451
+ const PreRenderedSageEmbed = componentFactory(SageEmbed, true);
12090
12452
  /**
12091
12453
  * Get a reference to the embed component to trigger events on the component.
12092
12454
  *
@@ -12106,7 +12468,6 @@ const SageEmbed$1 = componentFactory(SageEmbed);
12106
12468
  */
12107
12469
  function useEmbedRef() {
12108
12470
  return React.useRef(null);
12109
- }
12110
- const PreRenderedLiveboardEmbed = componentFactory(LiveboardEmbed, true);
12471
+ }
12111
12472
 
12112
- export { Action, AppEmbed$1 as AppEmbed, EmbedEvent, HomeLeftNavItem, HomepageModule, HostEvent, LiveboardEmbed$1 as LiveboardEmbed, Page, PinboardEmbed, PreRenderedLiveboardEmbed, RuntimeFilterOp, SageEmbed$1 as SageEmbed, SearchBarEmbed$1 as SearchBarEmbed, SearchEmbed$1 as SearchEmbed, useEmbedRef };
12473
+ export { Action, AppEmbed$1 as AppEmbed, EmbedEvent, HomeLeftNavItem, HomepageModule, HostEvent, LiveboardEmbed$1 as LiveboardEmbed, Page, PinboardEmbed, PreRenderedAppEmbed, PreRenderedLiveboardEmbed, PreRenderedPinboardEmbed, PreRenderedSageEmbed, PreRenderedSearchBarEmbed, RuntimeFilterOp, SageEmbed$1 as SageEmbed, SearchBarEmbed$1 as SearchBarEmbed, SearchEmbed$1 as SearchEmbed, useEmbedRef };