@thoughtspot/visual-embed-sdk 1.27.8 → 1.28.0-alpha.2

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 (142) hide show
  1. package/README.md +1 -1
  2. package/cjs/package.json +1 -1
  3. package/cjs/src/auth.d.ts.map +1 -1
  4. package/cjs/src/auth.js +2 -2
  5. package/cjs/src/auth.js.map +1 -1
  6. package/cjs/src/embed/base.d.ts +1 -1
  7. package/cjs/src/embed/base.d.ts.map +1 -1
  8. package/cjs/src/embed/base.js +5 -5
  9. package/cjs/src/embed/base.js.map +1 -1
  10. package/cjs/src/embed/base.spec.js +1 -1
  11. package/cjs/src/embed/base.spec.js.map +1 -1
  12. package/cjs/src/embed/sage.d.ts +5 -5
  13. package/cjs/src/embed/sage.d.ts.map +1 -1
  14. package/cjs/src/embed/sage.js +1 -16
  15. package/cjs/src/embed/sage.js.map +1 -1
  16. package/cjs/src/embed/sage.spec.js +11 -11
  17. package/cjs/src/embed/sage.spec.js.map +1 -1
  18. package/cjs/src/embed/search.d.ts +1 -5
  19. package/cjs/src/embed/search.d.ts.map +1 -1
  20. package/cjs/src/embed/search.js +4 -4
  21. package/cjs/src/embed/search.js.map +1 -1
  22. package/cjs/src/embed/ts-embed.d.ts +1 -1
  23. package/cjs/src/embed/ts-embed.d.ts.map +1 -1
  24. package/cjs/src/embed/ts-embed.js +6 -6
  25. package/cjs/src/embed/ts-embed.js.map +1 -1
  26. package/cjs/src/embed/ts-embed.spec.js +8 -14
  27. package/cjs/src/embed/ts-embed.spec.js.map +1 -1
  28. package/cjs/src/index.d.ts +4 -3
  29. package/cjs/src/index.d.ts.map +1 -1
  30. package/cjs/src/index.js +4 -1
  31. package/cjs/src/index.js.map +1 -1
  32. package/cjs/src/mixpanel-service.d.ts +1 -0
  33. package/cjs/src/mixpanel-service.d.ts.map +1 -1
  34. package/cjs/src/mixpanel-service.js +1 -0
  35. package/cjs/src/mixpanel-service.js.map +1 -1
  36. package/cjs/src/react/all-types-export.d.ts +1 -1
  37. package/cjs/src/react/all-types-export.d.ts.map +1 -1
  38. package/cjs/src/react/all-types-export.js +2 -1
  39. package/cjs/src/react/all-types-export.js.map +1 -1
  40. package/cjs/src/react/index.spec.js +0 -12
  41. package/cjs/src/react/index.spec.js.map +1 -1
  42. package/cjs/src/types.d.ts +43 -13
  43. package/cjs/src/types.d.ts.map +1 -1
  44. package/cjs/src/types.js +37 -10
  45. package/cjs/src/types.js.map +1 -1
  46. package/cjs/src/utils/graphql/answerService/answerService.d.ts +56 -2
  47. package/cjs/src/utils/graphql/answerService/answerService.d.ts.map +1 -1
  48. package/cjs/src/utils/graphql/answerService/answerService.js +55 -0
  49. package/cjs/src/utils/graphql/answerService/answerService.js.map +1 -1
  50. package/dist/src/auth.d.ts.map +1 -1
  51. package/dist/src/embed/base.d.ts +1 -1
  52. package/dist/src/embed/base.d.ts.map +1 -1
  53. package/dist/src/embed/sage.d.ts +5 -5
  54. package/dist/src/embed/sage.d.ts.map +1 -1
  55. package/dist/src/embed/search.d.ts +1 -5
  56. package/dist/src/embed/search.d.ts.map +1 -1
  57. package/dist/src/embed/ts-embed.d.ts +1 -1
  58. package/dist/src/embed/ts-embed.d.ts.map +1 -1
  59. package/dist/src/index.d.ts +4 -3
  60. package/dist/src/index.d.ts.map +1 -1
  61. package/dist/src/mixpanel-service.d.ts +1 -0
  62. package/dist/src/mixpanel-service.d.ts.map +1 -1
  63. package/dist/src/react/all-types-export.d.ts +1 -1
  64. package/dist/src/react/all-types-export.d.ts.map +1 -1
  65. package/dist/src/types.d.ts +43 -13
  66. package/dist/src/types.d.ts.map +1 -1
  67. package/dist/src/utils/graphql/answerService/answerService.d.ts +56 -2
  68. package/dist/src/utils/graphql/answerService/answerService.d.ts.map +1 -1
  69. package/dist/tsembed-react.es.js +2800 -2732
  70. package/dist/tsembed-react.js +1525 -1457
  71. package/dist/tsembed.es.js +1768 -1700
  72. package/dist/tsembed.js +1674 -1604
  73. package/dist/visual-embed-sdk-react-full.d.ts +135 -24
  74. package/dist/visual-embed-sdk-react.d.ts +135 -24
  75. package/dist/visual-embed-sdk.d.ts +135 -24
  76. package/lib/package.json +1 -1
  77. package/lib/src/auth.d.ts.map +1 -1
  78. package/lib/src/auth.js +3 -3
  79. package/lib/src/auth.js.map +1 -1
  80. package/lib/src/embed/base.d.ts +1 -1
  81. package/lib/src/embed/base.d.ts.map +1 -1
  82. package/lib/src/embed/base.js +5 -5
  83. package/lib/src/embed/base.js.map +1 -1
  84. package/lib/src/embed/base.spec.js +2 -2
  85. package/lib/src/embed/base.spec.js.map +1 -1
  86. package/lib/src/embed/sage.d.ts +5 -5
  87. package/lib/src/embed/sage.d.ts.map +1 -1
  88. package/lib/src/embed/sage.js +1 -16
  89. package/lib/src/embed/sage.js.map +1 -1
  90. package/lib/src/embed/sage.spec.js +11 -11
  91. package/lib/src/embed/sage.spec.js.map +1 -1
  92. package/lib/src/embed/search.d.ts +1 -5
  93. package/lib/src/embed/search.d.ts.map +1 -1
  94. package/lib/src/embed/search.js +5 -5
  95. package/lib/src/embed/search.js.map +1 -1
  96. package/lib/src/embed/ts-embed.d.ts +1 -1
  97. package/lib/src/embed/ts-embed.d.ts.map +1 -1
  98. package/lib/src/embed/ts-embed.js +9 -9
  99. package/lib/src/embed/ts-embed.js.map +1 -1
  100. package/lib/src/embed/ts-embed.spec.js +8 -14
  101. package/lib/src/embed/ts-embed.spec.js.map +1 -1
  102. package/lib/src/index.d.ts +4 -3
  103. package/lib/src/index.d.ts.map +1 -1
  104. package/lib/src/index.js +2 -3
  105. package/lib/src/index.js.map +1 -1
  106. package/lib/src/mixpanel-service.d.ts +1 -0
  107. package/lib/src/mixpanel-service.d.ts.map +1 -1
  108. package/lib/src/mixpanel-service.js +1 -0
  109. package/lib/src/mixpanel-service.js.map +1 -1
  110. package/lib/src/react/all-types-export.d.ts +1 -1
  111. package/lib/src/react/all-types-export.d.ts.map +1 -1
  112. package/lib/src/react/all-types-export.js +1 -1
  113. package/lib/src/react/all-types-export.js.map +1 -1
  114. package/lib/src/react/index.spec.js +0 -12
  115. package/lib/src/react/index.spec.js.map +1 -1
  116. package/lib/src/types.d.ts +43 -13
  117. package/lib/src/types.d.ts.map +1 -1
  118. package/lib/src/types.js +37 -10
  119. package/lib/src/types.js.map +1 -1
  120. package/lib/src/utils/authService/authService.spec.js +1 -1
  121. package/lib/src/utils/authService/authService.spec.js.map +1 -1
  122. package/lib/src/utils/graphql/answerService/answerService.d.ts +56 -2
  123. package/lib/src/utils/graphql/answerService/answerService.d.ts.map +1 -1
  124. package/lib/src/utils/graphql/answerService/answerService.js +55 -0
  125. package/lib/src/utils/graphql/answerService/answerService.js.map +1 -1
  126. package/lib/src/visual-embed-sdk.d.ts +144 -30
  127. package/package.json +1 -1
  128. package/src/auth.ts +6 -6
  129. package/src/embed/base.spec.ts +3 -3
  130. package/src/embed/base.ts +12 -12
  131. package/src/embed/sage.spec.ts +11 -11
  132. package/src/embed/sage.ts +4 -17
  133. package/src/embed/search.ts +6 -11
  134. package/src/embed/ts-embed.spec.ts +19 -25
  135. package/src/embed/ts-embed.ts +37 -34
  136. package/src/index.ts +10 -1
  137. package/src/mixpanel-service.ts +1 -0
  138. package/src/react/all-types-export.ts +1 -0
  139. package/src/react/index.spec.tsx +0 -29
  140. package/src/types.ts +53 -24
  141. package/src/utils/authService/authService.spec.ts +4 -4
  142. package/src/utils/graphql/answerService/answerService.ts +56 -1
package/dist/tsembed.js CHANGED
@@ -181,6 +181,7 @@
181
181
  * .then((response) => response.json())
182
182
  * .then((data) => data.token);
183
183
  * }
184
+ * });
184
185
  * ```
185
186
  */
186
187
  AuthType["TrustedAuthToken"] = "AuthServer";
@@ -443,7 +444,8 @@
443
444
  * A custom action has been triggered.
444
445
  *
445
446
  * @returns actionId - ID of the custom action
446
- * @returns data - Response payload with the Answer or Liveboard data
447
+ * @returns payload {@link CustomActionPayload} - Response payload with the
448
+ * Answer or Liveboard data
447
449
  * @example
448
450
  * ```js
449
451
  * appEmbed.on(EmbedEvent.customAction, payload => {
@@ -463,7 +465,7 @@
463
465
  * @example
464
466
  * ```js
465
467
  * livebaordEmbed.on(EmbedEvent.VizPointDoubleClick, payload => {
466
- * console.log('VizPointDoubleClick', payload)
468
+ * console.log('VizPointDoubleClick', payload);
467
469
  * })
468
470
  * ```
469
471
  */
@@ -489,15 +491,40 @@
489
491
  */
490
492
  EmbedEvent["VizPointClick"] = "vizPointClick";
491
493
  /**
492
- * An error has occurred.
494
+ * An error has occurred. This event is fired for the following error types:
495
+ *
496
+ * `API` - API call failure error.
497
+ *
498
+ * `FULLSCREEN` - Error when presenting a Liveboard or visualization in full screen mode.
499
+ *
500
+ * `SINGLE_VALUE_FILTER` - Error due to multiple values in the single value filter.
493
501
  *
502
+ * `NON_EXIST_FILTER` - Error due to a non-existent filter.
503
+ *
504
+ * `INVALID_DATE_VALUE` - Invalid date value error.
505
+ *
506
+ * `INVALID_OPERATOR` - Use of invalid operator during filter application.
507
+ *
508
+ * For more information, see [Developer Documentation](https://developers.thoughtspot.com/docs/events-app-integration#errorType)
494
509
  * @returns error - An error object or message
495
510
  * @example
496
511
  * ```js
497
- * SearchEmbed.on(EmbedEvent.Error, showErrorMsg)
498
- * //show error messaage
499
- * function showErrorMsg() {
500
- * document.getElementById("error");
512
+ * // API error
513
+ * SearchEmbed.on(EmbedEvent.Error, (error) => {
514
+ * console.log(error);
515
+ * // { type: "Error", data: { errorType: "API", error: { message: '...', error: '...' } } }
516
+ * });
517
+ * ```
518
+ * @example
519
+ * ```js
520
+ * // Fullscreen error (Errors during presenting of a liveboard)
521
+ * LiveboardEmbed.on(EmbedEvent.Error, (error) => {
522
+ * console.log(error);
523
+ * // { type: "Error", data: { errorType: "FULLSCREEN", error: {
524
+ * // message: "Fullscreen API is not enabled",
525
+ * // stack: "..."
526
+ * // } }}
527
+ * })
501
528
  * ```
502
529
  */
503
530
  EmbedEvent["Error"] = "Error";
@@ -1207,7 +1234,7 @@
1207
1234
  /**
1208
1235
  * Emitted when a LB/viz is renamed
1209
1236
  *
1210
- * @version SDK : 1.28.0 | ThoughtSpot: 9.11.0.cl
1237
+ * @version SDK : 1.28.0 | ThoughtSpot: 9.10.5.cl
1211
1238
  */
1212
1239
  EmbedEvent["Rename"] = "rename";
1213
1240
  })(exports.EmbedEvent || (exports.EmbedEvent = {}));
@@ -1858,7 +1885,7 @@
1858
1885
  */
1859
1886
  HostEvent["ResetSearch"] = "resetSearch";
1860
1887
  /**
1861
- * @hidden
1888
+ *
1862
1889
  * Get the currents visible and runtime filters applied on a Liveboard
1863
1890
  * @example
1864
1891
  * liveboardEmbed.trigger(HostEvent.GetFilters)
@@ -1866,7 +1893,7 @@
1866
1893
  */
1867
1894
  HostEvent["GetFilters"] = "getFilters";
1868
1895
  /**
1869
- * @hidden
1896
+ *
1870
1897
  * Update the visible filters on the Liveboard.
1871
1898
  * @param - filter: filter object containing column name and filter operation and values
1872
1899
  * @example
@@ -5571,8 +5598,6 @@
5571
5598
 
5572
5599
  var isEqual_1 = isEqual;
5573
5600
 
5574
- var name="@thoughtspot/visual-embed-sdk";var version="1.27.8";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$1={".":{"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 is-publish-allowed && npm run test && 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":"^46.9.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$1,typesVersions:typesVersions,"size-limit":[{path:"dist/tsembed.js",limit:"44 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};
5575
-
5576
5601
  const EndPoints = {
5577
5602
  AUTH_VERIFICATION: '/callosum/v1/session/info',
5578
5603
  SAML_LOGIN_TEMPLATE: (targetUrl) => `/callosum/v1/saml/login?targetURLPath=${targetUrl}`,
@@ -5735,386 +5760,930 @@
5735
5760
  cachedAuthToken = null;
5736
5761
  };
5737
5762
 
5738
- var Config = {
5739
- DEBUG: false,
5740
- LIB_VERSION: '2.45.0'
5741
- };
5742
-
5743
- // since es6 imports are static and we run unit tests from the console, window won't be defined when importing this file
5744
- var window$1;
5745
- if (typeof(window) === 'undefined') {
5746
- var loc = {
5747
- hostname: ''
5748
- };
5749
- window$1 = {
5750
- navigator: { userAgent: '' },
5751
- document: {
5752
- location: loc,
5753
- referrer: ''
5754
- },
5755
- screen: { width: 0, height: 0 },
5756
- location: loc
5757
- };
5758
- } else {
5759
- window$1 = window;
5760
- }
5761
-
5762
- /*
5763
- * Saved references to long variable names, so that closure compiler can
5764
- * minimize file size.
5765
- */
5766
-
5767
- var ArrayProto = Array.prototype;
5768
- var FuncProto = Function.prototype;
5769
- var ObjProto = Object.prototype;
5770
- var slice = ArrayProto.slice;
5771
- var toString = ObjProto.toString;
5772
- var hasOwnProperty$9 = ObjProto.hasOwnProperty;
5773
- var windowConsole = window$1.console;
5774
- var navigator = window$1.navigator;
5775
- var document$1 = window$1.document;
5776
- var windowOpera = window$1.opera;
5777
- var screen = window$1.screen;
5778
- var userAgent = navigator.userAgent;
5779
- var nativeBind = FuncProto.bind;
5780
- var nativeForEach = ArrayProto.forEach;
5781
- var nativeIndexOf = ArrayProto.indexOf;
5782
- var nativeMap = ArrayProto.map;
5783
- var nativeIsArray = Array.isArray;
5784
- var breaker = {};
5785
- var _ = {
5786
- trim: function(str) {
5787
- // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/Trim#Polyfill
5788
- return str.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
5789
- }
5790
- };
5791
-
5792
- // Console override
5793
- var console$1 = {
5794
- /** @type {function(...*)} */
5795
- log: function() {
5796
- if (Config.DEBUG && !_.isUndefined(windowConsole) && windowConsole) {
5797
- try {
5798
- windowConsole.log.apply(windowConsole, arguments);
5799
- } catch (err) {
5800
- _.each(arguments, function(arg) {
5801
- windowConsole.log(arg);
5802
- });
5803
- }
5804
- }
5805
- },
5806
- /** @type {function(...*)} */
5807
- warn: function() {
5808
- if (Config.DEBUG && !_.isUndefined(windowConsole) && windowConsole) {
5809
- var args = ['Mixpanel warning:'].concat(_.toArray(arguments));
5810
- try {
5811
- windowConsole.warn.apply(windowConsole, args);
5812
- } catch (err) {
5813
- _.each(args, function(arg) {
5814
- windowConsole.warn(arg);
5815
- });
5816
- }
5817
- }
5818
- },
5819
- /** @type {function(...*)} */
5820
- error: function() {
5821
- if (Config.DEBUG && !_.isUndefined(windowConsole) && windowConsole) {
5822
- var args = ['Mixpanel error:'].concat(_.toArray(arguments));
5823
- try {
5824
- windowConsole.error.apply(windowConsole, args);
5825
- } catch (err) {
5826
- _.each(args, function(arg) {
5827
- windowConsole.error(arg);
5828
- });
5829
- }
5830
- }
5831
- },
5832
- /** @type {function(...*)} */
5833
- critical: function() {
5834
- if (!_.isUndefined(windowConsole) && windowConsole) {
5835
- var args = ['Mixpanel error:'].concat(_.toArray(arguments));
5836
- try {
5837
- windowConsole.error.apply(windowConsole, args);
5838
- } catch (err) {
5839
- _.each(args, function(arg) {
5840
- windowConsole.error(arg);
5841
- });
5842
- }
5843
- }
5844
- }
5763
+ let config = {};
5764
+ /**
5765
+ * Gets the configuration embed was initialized with.
5766
+ *
5767
+ * @returns {@link EmbedConfig} The configuration embed was initialized with.
5768
+ * @version SDK: 1.19.0 | ThoughtSpot: *
5769
+ * @group Global methods
5770
+ */
5771
+ const getEmbedConfig = () => config;
5772
+ /**
5773
+ * Sets the configuration embed was initialized with.
5774
+ * And returns the new configuration.
5775
+ *
5776
+ * @param newConfig The configuration to set.
5777
+ * @version SDK: 1.27.0 | ThoughtSpot: *
5778
+ * @group Global methods
5779
+ */
5780
+ const setEmbedConfig = (newConfig) => {
5781
+ config = newConfig;
5782
+ return newConfig;
5845
5783
  };
5846
5784
 
5847
- var log_func_with_prefix = function(func, prefix) {
5848
- return function() {
5849
- arguments[0] = '[' + prefix + '] ' + arguments[0];
5850
- return func.apply(console$1, arguments);
5851
- };
5852
- };
5853
- var console_with_prefix = function(prefix) {
5854
- return {
5855
- log: log_func_with_prefix(console$1.log, prefix),
5856
- error: log_func_with_prefix(console$1.error, prefix),
5857
- critical: log_func_with_prefix(console$1.critical, prefix)
5858
- };
5785
+ const tokenizedFetch = async (input, init) => {
5786
+ const embedConfig = getEmbedConfig();
5787
+ if (embedConfig.authType !== exports.AuthType.TrustedAuthTokenCookieless) {
5788
+ return fetch(input, init);
5789
+ }
5790
+ const req = new Request(input, init);
5791
+ const authToken = await getAuthenticationToken(embedConfig);
5792
+ if (authToken) {
5793
+ req.headers.append('Authorization', `Bearer ${authToken}`);
5794
+ }
5795
+ return fetch(req);
5859
5796
  };
5860
5797
 
5798
+ /**
5799
+ *
5800
+ * @param root0
5801
+ * @param root0.query
5802
+ * @param root0.variables
5803
+ * @param root0.thoughtSpotHost
5804
+ * @param root0.isCompositeQuery
5805
+ */
5806
+ async function graphqlQuery({ query, variables, thoughtSpotHost, isCompositeQuery = false, }) {
5807
+ const operationName = getOperationNameFromQuery(query);
5808
+ try {
5809
+ const response = await fetch(`${thoughtSpotHost}/prism/?op=${operationName}`, {
5810
+ method: 'POST',
5811
+ headers: {
5812
+ 'content-type': 'application/json;charset=UTF-8',
5813
+ 'x-requested-by': 'ThoughtSpot',
5814
+ accept: '*/*',
5815
+ 'accept-language': 'en-us',
5816
+ },
5817
+ body: JSON.stringify({
5818
+ operationName,
5819
+ query,
5820
+ variables,
5821
+ }),
5822
+ credentials: 'include',
5823
+ });
5824
+ const result = await response.json();
5825
+ const dataValues = Object.values(result.data);
5826
+ return (isCompositeQuery) ? result.data : dataValues[0];
5827
+ }
5828
+ catch (error) {
5829
+ return error;
5830
+ }
5831
+ }
5861
5832
 
5862
- // UNDERSCORE
5863
- // Embed part of the Underscore Library
5864
- _.bind = function(func, context) {
5865
- var args, bound;
5866
- if (nativeBind && func.bind === nativeBind) {
5867
- return nativeBind.apply(func, slice.call(arguments, 1));
5868
- }
5869
- if (!_.isFunction(func)) {
5870
- throw new TypeError();
5871
- }
5872
- args = slice.call(arguments, 2);
5873
- bound = function() {
5874
- if (!(this instanceof bound)) {
5875
- return func.apply(context, args.concat(slice.call(arguments)));
5876
- }
5877
- var ctor = {};
5878
- ctor.prototype = func.prototype;
5879
- var self = new ctor();
5880
- ctor.prototype = null;
5881
- var result = func.apply(self, args.concat(slice.call(arguments)));
5882
- if (Object(result) === result) {
5883
- return result;
5884
- }
5885
- return self;
5886
- };
5887
- return bound;
5888
- };
5889
-
5890
- /**
5891
- * @param {*=} obj
5892
- * @param {function(...*)=} iterator
5893
- * @param {Object=} context
5894
- */
5895
- _.each = function(obj, iterator, context) {
5896
- if (obj === null || obj === undefined) {
5897
- return;
5898
- }
5899
- if (nativeForEach && obj.forEach === nativeForEach) {
5900
- obj.forEach(iterator, context);
5901
- } else if (obj.length === +obj.length) {
5902
- for (var i = 0, l = obj.length; i < l; i++) {
5903
- if (i in obj && iterator.call(context, obj[i], i, obj) === breaker) {
5904
- return;
5905
- }
5906
- }
5907
- } else {
5908
- for (var key in obj) {
5909
- if (hasOwnProperty$9.call(obj, key)) {
5910
- if (iterator.call(context, obj[key], key, obj) === breaker) {
5911
- return;
5912
- }
5913
- }
5914
- }
5915
- }
5916
- };
5917
-
5918
- _.extend = function(obj) {
5919
- _.each(slice.call(arguments, 1), function(source) {
5920
- for (var prop in source) {
5921
- if (source[prop] !== void 0) {
5922
- obj[prop] = source[prop];
5923
- }
5924
- }
5925
- });
5926
- return obj;
5927
- };
5928
-
5929
- _.isArray = nativeIsArray || function(obj) {
5930
- return toString.call(obj) === '[object Array]';
5931
- };
5932
-
5933
- // from a comment on http://dbj.org/dbj/?p=286
5934
- // fails on only one very rare and deliberate custom object:
5935
- // var bomb = { toString : undefined, valueOf: function(o) { return "function BOMBA!"; }};
5936
- _.isFunction = function(f) {
5937
- try {
5938
- return /^\s*\bfunction\b/.test(f);
5939
- } catch (x) {
5940
- return false;
5941
- }
5942
- };
5943
-
5944
- _.isArguments = function(obj) {
5945
- return !!(obj && hasOwnProperty$9.call(obj, 'callee'));
5946
- };
5947
-
5948
- _.toArray = function(iterable) {
5949
- if (!iterable) {
5950
- return [];
5951
- }
5952
- if (iterable.toArray) {
5953
- return iterable.toArray();
5954
- }
5955
- if (_.isArray(iterable)) {
5956
- return slice.call(iterable);
5957
- }
5958
- if (_.isArguments(iterable)) {
5959
- return slice.call(iterable);
5960
- }
5961
- return _.values(iterable);
5962
- };
5963
-
5964
- _.map = function(arr, callback, context) {
5965
- if (nativeMap && arr.map === nativeMap) {
5966
- return arr.map(callback, context);
5967
- } else {
5968
- var results = [];
5969
- _.each(arr, function(item) {
5970
- results.push(callback.call(context, item));
5971
- });
5972
- return results;
5973
- }
5974
- };
5975
-
5976
- _.keys = function(obj) {
5977
- var results = [];
5978
- if (obj === null) {
5979
- return results;
5980
- }
5981
- _.each(obj, function(value, key) {
5982
- results[results.length] = key;
5983
- });
5984
- return results;
5985
- };
5986
-
5987
- _.values = function(obj) {
5988
- var results = [];
5989
- if (obj === null) {
5990
- return results;
5991
- }
5992
- _.each(obj, function(value) {
5993
- results[results.length] = value;
5994
- });
5995
- return results;
5996
- };
5997
-
5998
- _.include = function(obj, target) {
5999
- var found = false;
6000
- if (obj === null) {
6001
- return found;
6002
- }
6003
- if (nativeIndexOf && obj.indexOf === nativeIndexOf) {
6004
- return obj.indexOf(target) != -1;
6005
- }
6006
- _.each(obj, function(value) {
6007
- if (found || (found = (value === target))) {
6008
- return breaker;
6009
- }
6010
- });
6011
- return found;
6012
- };
6013
-
6014
- _.includes = function(str, needle) {
6015
- return str.indexOf(needle) !== -1;
6016
- };
6017
-
6018
- // Underscore Addons
6019
- _.inherit = function(subclass, superclass) {
6020
- subclass.prototype = new superclass();
6021
- subclass.prototype.constructor = subclass;
6022
- subclass.superclass = superclass.prototype;
6023
- return subclass;
6024
- };
5833
+ const getSourceDetailQuery = `
5834
+ query GetSourceDetail($ids: [GUID!]!) {
5835
+ getSourceDetailById(ids: $ids, type: LOGICAL_TABLE) {
5836
+ id
5837
+ name
5838
+ description
5839
+ authorName
5840
+ authorDisplayName
5841
+ isExternal
5842
+ type
5843
+ created
5844
+ modified
5845
+ columns {
5846
+ id
5847
+ name
5848
+ author
5849
+ authorDisplayName
5850
+ description
5851
+ dataType
5852
+ type
5853
+ modified
5854
+ ownerName
5855
+ owner
5856
+ dataRecency
5857
+ sources {
5858
+ tableId
5859
+ tableName
5860
+ columnId
5861
+ columnName
5862
+ __typename
5863
+ }
5864
+ synonyms
5865
+ cohortAnswerId
5866
+ __typename
5867
+ }
5868
+ relationships
5869
+ destinationRelationships
5870
+ dataSourceId
5871
+ __typename
5872
+ }
5873
+ }
5874
+ `;
5875
+ const sourceDetailCache = new Map();
5876
+ /**
5877
+ *
5878
+ * @param thoughtSpotHost
5879
+ * @param sourceId
5880
+ */
5881
+ async function getSourceDetail(thoughtSpotHost, sourceId) {
5882
+ if (sourceDetailCache.get(sourceId)) {
5883
+ return sourceDetailCache.get(sourceId);
5884
+ }
5885
+ const details = await graphqlQuery({
5886
+ query: getSourceDetailQuery,
5887
+ variables: {
5888
+ ids: [sourceId],
5889
+ },
5890
+ thoughtSpotHost,
5891
+ });
5892
+ const souceDetails = details[0];
5893
+ if (souceDetails) {
5894
+ sourceDetailCache.set(sourceId, souceDetails);
5895
+ }
5896
+ return souceDetails;
5897
+ }
6025
5898
 
6026
- _.isObject = function(obj) {
6027
- return (obj === Object(obj) && !_.isArray(obj));
6028
- };
5899
+ const bachSessionId = `
5900
+ id {
5901
+ sessionId
5902
+ genNo
5903
+ acSession {
5904
+ sessionId
5905
+ genNo
5906
+ }
5907
+ }
5908
+ `;
5909
+ const getUnaggregatedAnswerSession = `
5910
+ mutation GetUnAggregatedAnswerSession($session: BachSessionIdInput!, $columns: [UserPointSelectionInput!]!) {
5911
+ Answer__getUnaggregatedAnswer(session: $session, columns: $columns) {
5912
+ ${bachSessionId}
5913
+ answer {
5914
+ visualizations {
5915
+ ... on TableViz {
5916
+ columns {
5917
+ column {
5918
+ id
5919
+ name
5920
+ referencedColumns {
5921
+ guid
5922
+ displayName
5923
+ }
5924
+ }
5925
+ }
5926
+ }
5927
+ }
5928
+ }
5929
+ }
5930
+ }
5931
+ `;
5932
+ const removeColumns = `
5933
+ mutation RemoveColumns($session: BachSessionIdInput!, $logicalColumnIds: [GUID!], $columnIds: [GUID!]) {
5934
+ Answer__removeColumns(
5935
+ session: $session
5936
+ logicalColumnIds: $logicalColumnIds
5937
+ columnIds: $columnIds
5938
+ ) {
5939
+ ${bachSessionId}
5940
+ }
5941
+ }
5942
+ `;
5943
+ const addColumns = `
5944
+ mutation AddColumns($session: BachSessionIdInput!, $columns: [AnswerColumnInfo!]!) {
5945
+ Answer__addColumn(session: $session, columns: $columns) {
5946
+ ${bachSessionId}
5947
+ }
5948
+ }
5949
+ `;
5950
+ const getAnswerData = `
5951
+ query GetTableWithHeadlineData($session: BachSessionIdInput!, $deadline: Int!, $dataPaginationParams: DataPaginationParamsInput!) {
5952
+ getAnswer(session: $session) {
5953
+ ${bachSessionId}
5954
+ answer {
5955
+ id
5956
+ visualizations {
5957
+ id
5958
+ ... on TableViz {
5959
+ columns {
5960
+ column {
5961
+ id
5962
+ name
5963
+ type
5964
+ aggregationType
5965
+ dataType
5966
+ }
5967
+ }
5968
+ data(deadline: $deadline, pagination: $dataPaginationParams)
5969
+ }
5970
+ }
5971
+ }
5972
+ }
5973
+ }
5974
+ `;
6029
5975
 
6030
- _.isEmptyObject = function(obj) {
6031
- if (_.isObject(obj)) {
6032
- for (var key in obj) {
6033
- if (hasOwnProperty$9.call(obj, key)) {
6034
- return false;
6035
- }
6036
- }
6037
- return true;
6038
- }
6039
- return false;
6040
- };
6041
-
6042
- _.isUndefined = function(obj) {
6043
- return obj === void 0;
6044
- };
6045
-
6046
- _.isString = function(obj) {
6047
- return toString.call(obj) == '[object String]';
6048
- };
5976
+ // eslint-disable-next-line no-shadow
5977
+ var OperationType;
5978
+ (function (OperationType) {
5979
+ OperationType["GetChartWithData"] = "GetChartWithData";
5980
+ OperationType["GetTableWithHeadlineData"] = "GetTableWithHeadlineData";
5981
+ })(OperationType || (OperationType = {}));
5982
+ /**
5983
+ * Class representing the answer service provided with the
5984
+ * custom action payload. This service could be used to run
5985
+ * graphql queries in the context of the answer on which the
5986
+ * custom action was triggered.
5987
+ *
5988
+ * @example
5989
+ * ```js
5990
+ * embed.on(EmbedEvent.CustomAction, e => {
5991
+ * const underlying = await e.answerService.getUnderlyingDataForPoint([
5992
+ * 'col name 1'
5993
+ * ]);
5994
+ * const data = await underlying.fetchData(0, 100);
5995
+ * })
5996
+ * ```
5997
+ * @version SDK: 1.25.0| ThoughtSpot: 9.10.0.cl
5998
+ * @group Events
5999
+ */
6000
+ class AnswerService {
6001
+ /**
6002
+ * Should not need to be called directly.
6003
+ *
6004
+ * @param session
6005
+ * @param answer
6006
+ * @param thoughtSpotHost
6007
+ * @param selectedPoints
6008
+ */
6009
+ constructor(session, answer, thoughtSpotHost, selectedPoints) {
6010
+ this.session = session;
6011
+ this.answer = answer;
6012
+ this.thoughtSpotHost = thoughtSpotHost;
6013
+ this.selectedPoints = selectedPoints;
6014
+ this.session = removeTypename(session);
6015
+ }
6016
+ /**
6017
+ * Get the details about the source used in the answer.
6018
+ * This can be used to get the list of all columns in the data source for example.
6019
+ */
6020
+ async getSourceDetail() {
6021
+ const sourceId = this.answer.sources[0].header.guid;
6022
+ return getSourceDetail(this.thoughtSpotHost, sourceId);
6023
+ }
6024
+ /**
6025
+ * Remove columnIds and return updated answer session.
6026
+ *
6027
+ * @param columnIds
6028
+ * @returns
6029
+ */
6030
+ async removeColumns(columnIds) {
6031
+ return this.executeQuery(removeColumns, {
6032
+ logicalColumnIds: columnIds,
6033
+ });
6034
+ }
6035
+ /**
6036
+ * Add columnIds and return updated answer session.
6037
+ *
6038
+ * @param columnIds
6039
+ * @returns
6040
+ */
6041
+ async addColumns(columnIds) {
6042
+ return this.executeQuery(addColumns, {
6043
+ columns: columnIds.map((colId) => ({ logicalColumnId: colId })),
6044
+ });
6045
+ }
6046
+ /**
6047
+ * Fetch data from the answer.
6048
+ *
6049
+ * @param offset
6050
+ * @param size
6051
+ * @returns
6052
+ */
6053
+ async fetchData(offset = 0, size = 1000) {
6054
+ const { answer } = await this.executeQuery(getAnswerData, {
6055
+ deadline: 0,
6056
+ dataPaginationParams: {
6057
+ isClientPaginated: true,
6058
+ offset,
6059
+ size,
6060
+ },
6061
+ });
6062
+ const { columns, data } = answer.visualizations.find((viz) => !!viz.data) || {};
6063
+ return {
6064
+ columns,
6065
+ data,
6066
+ };
6067
+ }
6068
+ /**
6069
+ * Fetch the data for the answer as a CSV blob. This might be
6070
+ * quicker for larger data.
6071
+ *
6072
+ * @param userLocale
6073
+ * @param includeInfo Include the CSV header in the output
6074
+ * @returns Response
6075
+ */
6076
+ async fetchCSVBlob(userLocale = 'en-us', includeInfo = false) {
6077
+ const fetchUrl = this.getFetchCSVBlobUrl(userLocale, includeInfo);
6078
+ return tokenizedFetch(fetchUrl, {
6079
+ credentials: 'include',
6080
+ });
6081
+ }
6082
+ /**
6083
+ * Just get the internal URL for this answer's data
6084
+ * as a CSV blob.
6085
+ *
6086
+ * @param userLocale
6087
+ * @param includeInfo
6088
+ * @returns
6089
+ */
6090
+ getFetchCSVBlobUrl(userLocale = 'en-us', includeInfo = false) {
6091
+ return `${this.thoughtSpotHost}/prism/download/answer/csv?sessionId=${this.session.sessionId}&genNo=${this.session.genNo}&userLocale=${userLocale}&exportFileName=data&hideCsvHeader=${!includeInfo}`;
6092
+ }
6093
+ /**
6094
+ * Get underlying data given a point and the output column names.
6095
+ * In case of a context menu action, the selectedPoints are
6096
+ * automatically passed.
6097
+ *
6098
+ * @param outputColumnNames
6099
+ * @param selectedPoints
6100
+ * @example
6101
+ * ```js
6102
+ * embed.on(EmbedEvent.CustomAction, e => {
6103
+ * const underlying = await e.answerService.getUnderlyingDataForPoint([
6104
+ * 'col name 1' // The column should exist in the data source.
6105
+ * ]);
6106
+ * const data = await underlying.fetchData(0, 100);
6107
+ * })
6108
+ * ```
6109
+ * @version SDK: 1.25.0| ThoughtSpot: 9.10.0.cl
6110
+ */
6111
+ async getUnderlyingDataForPoint(outputColumnNames, selectedPoints) {
6112
+ if (!selectedPoints && !this.selectedPoints) {
6113
+ throw new Error('Needs to be triggered in context of a point');
6114
+ }
6115
+ if (!selectedPoints) {
6116
+ selectedPoints = getSelectedPointsForUnderlyingDataQuery(this.selectedPoints);
6117
+ }
6118
+ const sourceDetail = await this.getSourceDetail();
6119
+ const ouputColumnGuids = getGuidsFromColumnNames(sourceDetail, outputColumnNames);
6120
+ const unAggAnswer = await graphqlQuery({
6121
+ query: getUnaggregatedAnswerSession,
6122
+ variables: {
6123
+ session: this.session,
6124
+ columns: selectedPoints,
6125
+ },
6126
+ thoughtSpotHost: this.thoughtSpotHost,
6127
+ });
6128
+ const unaggAnswerSession = new AnswerService(unAggAnswer.id, unAggAnswer.answer, this.thoughtSpotHost);
6129
+ const currentColumns = new Set(unAggAnswer.answer.visualizations[0].columns
6130
+ .map((c) => c.column.referencedColumns[0].guid));
6131
+ const columnsToAdd = [...ouputColumnGuids].filter((col) => !currentColumns.has(col));
6132
+ if (columnsToAdd.length) {
6133
+ await unaggAnswerSession.addColumns(columnsToAdd);
6134
+ }
6135
+ const columnsToRemove = [...currentColumns].filter((col) => !ouputColumnGuids.has(col));
6136
+ if (columnsToRemove.length) {
6137
+ await unaggAnswerSession.removeColumns(columnsToRemove);
6138
+ }
6139
+ return unaggAnswerSession;
6140
+ }
6141
+ /**
6142
+ * Execute a custom graphql query in the context of the answer.
6143
+ *
6144
+ * @param query graphql query
6145
+ * @param variables graphql variables
6146
+ * @returns
6147
+ */
6148
+ async executeQuery(query, variables) {
6149
+ const data = await graphqlQuery({
6150
+ query,
6151
+ variables: {
6152
+ session: this.session,
6153
+ ...variables,
6154
+ },
6155
+ thoughtSpotHost: this.thoughtSpotHost,
6156
+ isCompositeQuery: false,
6157
+ });
6158
+ this.session = deepMerge(this.session, (data === null || data === void 0 ? void 0 : data.id) || {});
6159
+ return data;
6160
+ }
6161
+ /**
6162
+ * Get the internal session details for the answer.
6163
+ *
6164
+ * @returns
6165
+ */
6166
+ getSession() {
6167
+ return this.session;
6168
+ }
6169
+ }
6170
+ /**
6171
+ *
6172
+ * @param sourceDetail
6173
+ * @param colNames
6174
+ */
6175
+ function getGuidsFromColumnNames(sourceDetail, colNames) {
6176
+ const cols = sourceDetail.columns.reduce((colSet, col) => {
6177
+ colSet[col.name] = col;
6178
+ return colSet;
6179
+ }, {});
6180
+ return new Set(colNames.map((colName) => {
6181
+ const col = cols[colName];
6182
+ return col.id;
6183
+ }));
6184
+ }
6185
+ /**
6186
+ *
6187
+ * @param selectedPoints
6188
+ */
6189
+ function getSelectedPointsForUnderlyingDataQuery(selectedPoints) {
6190
+ const underlyingDataPoint = [];
6191
+ /**
6192
+ *
6193
+ * @param colVal
6194
+ */
6195
+ function addPointFromColVal(colVal) {
6196
+ var _a;
6197
+ const dataType = colVal.column.dataType;
6198
+ const id = colVal.column.id;
6199
+ let dataValue;
6200
+ if (dataType === 'DATE') {
6201
+ if (Number.isFinite(colVal.value)) {
6202
+ dataValue = [{
6203
+ epochRange: {
6204
+ startEpoch: colVal.value,
6205
+ },
6206
+ }];
6207
+ // Case for custom calendar.
6208
+ }
6209
+ else if ((_a = colVal.value) === null || _a === void 0 ? void 0 : _a.v) {
6210
+ dataValue = [{
6211
+ epochRange: {
6212
+ startEpoch: colVal.value.v.s,
6213
+ endEpoch: colVal.value.v.e,
6214
+ },
6215
+ }];
6216
+ }
6217
+ }
6218
+ else {
6219
+ dataValue = [{ value: colVal.value }];
6220
+ }
6221
+ underlyingDataPoint.push({
6222
+ columnId: colVal.column.id,
6223
+ dataValue,
6224
+ });
6225
+ }
6226
+ selectedPoints.forEach((p) => {
6227
+ p.selectedAttributes.forEach(addPointFromColVal);
6228
+ });
6229
+ return underlyingDataPoint;
6230
+ }
6049
6231
 
6050
- _.isDate = function(obj) {
6051
- return toString.call(obj) == '[object Date]';
6232
+ const ERROR_MESSAGE = {
6233
+ INVALID_THOUGHTSPOT_HOST: 'Error parsing ThoughtSpot host. Please provide a valid URL.',
6234
+ LIVEBOARD_VIZ_ID_VALIDATION: 'Please provide either liveboardId or pinboardId',
6235
+ TRIGGER_TIMED_OUT: 'Trigger timedout in getting response',
6236
+ SEARCHEMBED_BETA_WRANING_MESSAGE: 'Search Embed is in Beta in this release.',
6237
+ SAGE_EMBED_BETA_WARNING_MESSAGE: 'Sage Embed is in Beta in this release.',
6052
6238
  };
6053
6239
 
6054
- _.isNumber = function(obj) {
6055
- return toString.call(obj) == '[object Number]';
6240
+ /**
6241
+ * Copyright (c) 2023
6242
+ *
6243
+ * Utilities related to reading configuration objects
6244
+ *
6245
+ * @summary Config-related utils
6246
+ * @author Ayon Ghosh <ayon.ghosh@thoughtspot.com>
6247
+ */
6248
+ const urlRegex = new RegExp([
6249
+ '(^(https?:)//)?',
6250
+ '(([^:/?#]*)(?::([0-9]+))?)',
6251
+ '(/{0,1}[^?#]*)',
6252
+ '(\\?[^#]*|)',
6253
+ '(#.*|)$', // hash
6254
+ ].join(''));
6255
+ /**
6256
+ * Parse and construct the ThoughtSpot hostname or IP address
6257
+ * from the embed configuration object.
6258
+ *
6259
+ * @param config
6260
+ */
6261
+ const getThoughtSpotHost = (config) => {
6262
+ if (!config.thoughtSpotHost) {
6263
+ throw new Error(ERROR_MESSAGE.INVALID_THOUGHTSPOT_HOST);
6264
+ }
6265
+ const urlParts = config.thoughtSpotHost.match(urlRegex);
6266
+ if (!urlParts) {
6267
+ throw new Error(ERROR_MESSAGE.INVALID_THOUGHTSPOT_HOST);
6268
+ }
6269
+ const protocol = urlParts[2] || window.location.protocol;
6270
+ const host = urlParts[3];
6271
+ let path = urlParts[6];
6272
+ // Lose the trailing / if any
6273
+ if (path.charAt(path.length - 1) === '/') {
6274
+ path = path.substring(0, path.length - 1);
6275
+ }
6276
+ // const urlParams = urlParts[7];
6277
+ // const hash = urlParts[8];
6278
+ return `${protocol}//${host}${path}`;
6279
+ };
6280
+ const getV2BasePath = (config) => {
6281
+ if (config.basepath) {
6282
+ return config.basepath;
6283
+ }
6284
+ const tsHost = getThoughtSpotHost(config);
6285
+ // This is to handle when e2e's. Search is run on pods for
6286
+ // comp-blink-test-pipeline with baseUrl=https://localhost:8443.
6287
+ // This is to handle when the developer is developing in their local
6288
+ // environment.
6289
+ if (tsHost.includes('://localhost') && !tsHost.includes(':8443')) {
6290
+ return '';
6291
+ }
6292
+ return 'v2';
6293
+ };
6294
+ /**
6295
+ * It is a good idea to keep URLs under 2000 chars.
6296
+ * If this is ever breached, since we pass view configuration through
6297
+ * URL params, we would like to log a warning.
6298
+ * Reference: https://stackoverflow.com/questions/417142/what-is-the-maximum-length-of-a-url-in-different-browsers
6299
+ */
6300
+ const URL_MAX_LENGTH = 2000;
6301
+ /**
6302
+ * The default CSS dimensions of the embedded app
6303
+ */
6304
+ const DEFAULT_EMBED_WIDTH = '100%';
6305
+ const DEFAULT_EMBED_HEIGHT = '100%';
6306
+
6307
+ var Config = {
6308
+ DEBUG: false,
6309
+ LIB_VERSION: '2.45.0'
6056
6310
  };
6057
6311
 
6058
- _.isElement = function(obj) {
6059
- return !!(obj && obj.nodeType === 1);
6312
+ // since es6 imports are static and we run unit tests from the console, window won't be defined when importing this file
6313
+ var window$1;
6314
+ if (typeof(window) === 'undefined') {
6315
+ var loc = {
6316
+ hostname: ''
6317
+ };
6318
+ window$1 = {
6319
+ navigator: { userAgent: '' },
6320
+ document: {
6321
+ location: loc,
6322
+ referrer: ''
6323
+ },
6324
+ screen: { width: 0, height: 0 },
6325
+ location: loc
6326
+ };
6327
+ } else {
6328
+ window$1 = window;
6329
+ }
6330
+
6331
+ /*
6332
+ * Saved references to long variable names, so that closure compiler can
6333
+ * minimize file size.
6334
+ */
6335
+
6336
+ var ArrayProto = Array.prototype;
6337
+ var FuncProto = Function.prototype;
6338
+ var ObjProto = Object.prototype;
6339
+ var slice = ArrayProto.slice;
6340
+ var toString = ObjProto.toString;
6341
+ var hasOwnProperty$9 = ObjProto.hasOwnProperty;
6342
+ var windowConsole = window$1.console;
6343
+ var navigator = window$1.navigator;
6344
+ var document$1 = window$1.document;
6345
+ var windowOpera = window$1.opera;
6346
+ var screen = window$1.screen;
6347
+ var userAgent = navigator.userAgent;
6348
+ var nativeBind = FuncProto.bind;
6349
+ var nativeForEach = ArrayProto.forEach;
6350
+ var nativeIndexOf = ArrayProto.indexOf;
6351
+ var nativeMap = ArrayProto.map;
6352
+ var nativeIsArray = Array.isArray;
6353
+ var breaker = {};
6354
+ var _ = {
6355
+ trim: function(str) {
6356
+ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/Trim#Polyfill
6357
+ return str.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
6358
+ }
6060
6359
  };
6061
6360
 
6062
- _.encodeDates = function(obj) {
6063
- _.each(obj, function(v, k) {
6064
- if (_.isDate(v)) {
6065
- obj[k] = _.formatDate(v);
6066
- } else if (_.isObject(v)) {
6067
- obj[k] = _.encodeDates(v); // recurse
6361
+ // Console override
6362
+ var console$1 = {
6363
+ /** @type {function(...*)} */
6364
+ log: function() {
6365
+ if (Config.DEBUG && !_.isUndefined(windowConsole) && windowConsole) {
6366
+ try {
6367
+ windowConsole.log.apply(windowConsole, arguments);
6368
+ } catch (err) {
6369
+ _.each(arguments, function(arg) {
6370
+ windowConsole.log(arg);
6371
+ });
6372
+ }
6068
6373
  }
6069
- });
6070
- return obj;
6374
+ },
6375
+ /** @type {function(...*)} */
6376
+ warn: function() {
6377
+ if (Config.DEBUG && !_.isUndefined(windowConsole) && windowConsole) {
6378
+ var args = ['Mixpanel warning:'].concat(_.toArray(arguments));
6379
+ try {
6380
+ windowConsole.warn.apply(windowConsole, args);
6381
+ } catch (err) {
6382
+ _.each(args, function(arg) {
6383
+ windowConsole.warn(arg);
6384
+ });
6385
+ }
6386
+ }
6387
+ },
6388
+ /** @type {function(...*)} */
6389
+ error: function() {
6390
+ if (Config.DEBUG && !_.isUndefined(windowConsole) && windowConsole) {
6391
+ var args = ['Mixpanel error:'].concat(_.toArray(arguments));
6392
+ try {
6393
+ windowConsole.error.apply(windowConsole, args);
6394
+ } catch (err) {
6395
+ _.each(args, function(arg) {
6396
+ windowConsole.error(arg);
6397
+ });
6398
+ }
6399
+ }
6400
+ },
6401
+ /** @type {function(...*)} */
6402
+ critical: function() {
6403
+ if (!_.isUndefined(windowConsole) && windowConsole) {
6404
+ var args = ['Mixpanel error:'].concat(_.toArray(arguments));
6405
+ try {
6406
+ windowConsole.error.apply(windowConsole, args);
6407
+ } catch (err) {
6408
+ _.each(args, function(arg) {
6409
+ windowConsole.error(arg);
6410
+ });
6411
+ }
6412
+ }
6413
+ }
6071
6414
  };
6072
6415
 
6073
- _.timestamp = function() {
6074
- Date.now = Date.now || function() {
6075
- return +new Date;
6416
+ var log_func_with_prefix = function(func, prefix) {
6417
+ return function() {
6418
+ arguments[0] = '[' + prefix + '] ' + arguments[0];
6419
+ return func.apply(console$1, arguments);
6076
6420
  };
6077
- return Date.now();
6078
6421
  };
6079
-
6080
- _.formatDate = function(d) {
6081
- // YYYY-MM-DDTHH:MM:SS in UTC
6082
- function pad(n) {
6083
- return n < 10 ? '0' + n : n;
6084
- }
6085
- return d.getUTCFullYear() + '-' +
6086
- pad(d.getUTCMonth() + 1) + '-' +
6087
- pad(d.getUTCDate()) + 'T' +
6088
- pad(d.getUTCHours()) + ':' +
6089
- pad(d.getUTCMinutes()) + ':' +
6090
- pad(d.getUTCSeconds());
6422
+ var console_with_prefix = function(prefix) {
6423
+ return {
6424
+ log: log_func_with_prefix(console$1.log, prefix),
6425
+ error: log_func_with_prefix(console$1.error, prefix),
6426
+ critical: log_func_with_prefix(console$1.critical, prefix)
6427
+ };
6091
6428
  };
6092
6429
 
6093
- _.strip_empty_properties = function(p) {
6094
- var ret = {};
6095
- _.each(p, function(v, k) {
6096
- if (_.isString(v) && v.length > 0) {
6097
- ret[k] = v;
6430
+
6431
+ // UNDERSCORE
6432
+ // Embed part of the Underscore Library
6433
+ _.bind = function(func, context) {
6434
+ var args, bound;
6435
+ if (nativeBind && func.bind === nativeBind) {
6436
+ return nativeBind.apply(func, slice.call(arguments, 1));
6437
+ }
6438
+ if (!_.isFunction(func)) {
6439
+ throw new TypeError();
6440
+ }
6441
+ args = slice.call(arguments, 2);
6442
+ bound = function() {
6443
+ if (!(this instanceof bound)) {
6444
+ return func.apply(context, args.concat(slice.call(arguments)));
6098
6445
  }
6099
- });
6100
- return ret;
6446
+ var ctor = {};
6447
+ ctor.prototype = func.prototype;
6448
+ var self = new ctor();
6449
+ ctor.prototype = null;
6450
+ var result = func.apply(self, args.concat(slice.call(arguments)));
6451
+ if (Object(result) === result) {
6452
+ return result;
6453
+ }
6454
+ return self;
6455
+ };
6456
+ return bound;
6101
6457
  };
6102
6458
 
6103
- /*
6104
- * this function returns a copy of object after truncating it. If
6105
- * passed an Array or Object it will iterate through obj and
6106
- * truncate all the values recursively.
6459
+ /**
6460
+ * @param {*=} obj
6461
+ * @param {function(...*)=} iterator
6462
+ * @param {Object=} context
6107
6463
  */
6108
- _.truncate = function(obj, length) {
6109
- var ret;
6110
-
6111
- if (typeof(obj) === 'string') {
6112
- ret = obj.slice(0, length);
6113
- } else if (_.isArray(obj)) {
6114
- ret = [];
6115
- _.each(obj, function(val) {
6116
- ret.push(_.truncate(val, length));
6117
- });
6464
+ _.each = function(obj, iterator, context) {
6465
+ if (obj === null || obj === undefined) {
6466
+ return;
6467
+ }
6468
+ if (nativeForEach && obj.forEach === nativeForEach) {
6469
+ obj.forEach(iterator, context);
6470
+ } else if (obj.length === +obj.length) {
6471
+ for (var i = 0, l = obj.length; i < l; i++) {
6472
+ if (i in obj && iterator.call(context, obj[i], i, obj) === breaker) {
6473
+ return;
6474
+ }
6475
+ }
6476
+ } else {
6477
+ for (var key in obj) {
6478
+ if (hasOwnProperty$9.call(obj, key)) {
6479
+ if (iterator.call(context, obj[key], key, obj) === breaker) {
6480
+ return;
6481
+ }
6482
+ }
6483
+ }
6484
+ }
6485
+ };
6486
+
6487
+ _.extend = function(obj) {
6488
+ _.each(slice.call(arguments, 1), function(source) {
6489
+ for (var prop in source) {
6490
+ if (source[prop] !== void 0) {
6491
+ obj[prop] = source[prop];
6492
+ }
6493
+ }
6494
+ });
6495
+ return obj;
6496
+ };
6497
+
6498
+ _.isArray = nativeIsArray || function(obj) {
6499
+ return toString.call(obj) === '[object Array]';
6500
+ };
6501
+
6502
+ // from a comment on http://dbj.org/dbj/?p=286
6503
+ // fails on only one very rare and deliberate custom object:
6504
+ // var bomb = { toString : undefined, valueOf: function(o) { return "function BOMBA!"; }};
6505
+ _.isFunction = function(f) {
6506
+ try {
6507
+ return /^\s*\bfunction\b/.test(f);
6508
+ } catch (x) {
6509
+ return false;
6510
+ }
6511
+ };
6512
+
6513
+ _.isArguments = function(obj) {
6514
+ return !!(obj && hasOwnProperty$9.call(obj, 'callee'));
6515
+ };
6516
+
6517
+ _.toArray = function(iterable) {
6518
+ if (!iterable) {
6519
+ return [];
6520
+ }
6521
+ if (iterable.toArray) {
6522
+ return iterable.toArray();
6523
+ }
6524
+ if (_.isArray(iterable)) {
6525
+ return slice.call(iterable);
6526
+ }
6527
+ if (_.isArguments(iterable)) {
6528
+ return slice.call(iterable);
6529
+ }
6530
+ return _.values(iterable);
6531
+ };
6532
+
6533
+ _.map = function(arr, callback, context) {
6534
+ if (nativeMap && arr.map === nativeMap) {
6535
+ return arr.map(callback, context);
6536
+ } else {
6537
+ var results = [];
6538
+ _.each(arr, function(item) {
6539
+ results.push(callback.call(context, item));
6540
+ });
6541
+ return results;
6542
+ }
6543
+ };
6544
+
6545
+ _.keys = function(obj) {
6546
+ var results = [];
6547
+ if (obj === null) {
6548
+ return results;
6549
+ }
6550
+ _.each(obj, function(value, key) {
6551
+ results[results.length] = key;
6552
+ });
6553
+ return results;
6554
+ };
6555
+
6556
+ _.values = function(obj) {
6557
+ var results = [];
6558
+ if (obj === null) {
6559
+ return results;
6560
+ }
6561
+ _.each(obj, function(value) {
6562
+ results[results.length] = value;
6563
+ });
6564
+ return results;
6565
+ };
6566
+
6567
+ _.include = function(obj, target) {
6568
+ var found = false;
6569
+ if (obj === null) {
6570
+ return found;
6571
+ }
6572
+ if (nativeIndexOf && obj.indexOf === nativeIndexOf) {
6573
+ return obj.indexOf(target) != -1;
6574
+ }
6575
+ _.each(obj, function(value) {
6576
+ if (found || (found = (value === target))) {
6577
+ return breaker;
6578
+ }
6579
+ });
6580
+ return found;
6581
+ };
6582
+
6583
+ _.includes = function(str, needle) {
6584
+ return str.indexOf(needle) !== -1;
6585
+ };
6586
+
6587
+ // Underscore Addons
6588
+ _.inherit = function(subclass, superclass) {
6589
+ subclass.prototype = new superclass();
6590
+ subclass.prototype.constructor = subclass;
6591
+ subclass.superclass = superclass.prototype;
6592
+ return subclass;
6593
+ };
6594
+
6595
+ _.isObject = function(obj) {
6596
+ return (obj === Object(obj) && !_.isArray(obj));
6597
+ };
6598
+
6599
+ _.isEmptyObject = function(obj) {
6600
+ if (_.isObject(obj)) {
6601
+ for (var key in obj) {
6602
+ if (hasOwnProperty$9.call(obj, key)) {
6603
+ return false;
6604
+ }
6605
+ }
6606
+ return true;
6607
+ }
6608
+ return false;
6609
+ };
6610
+
6611
+ _.isUndefined = function(obj) {
6612
+ return obj === void 0;
6613
+ };
6614
+
6615
+ _.isString = function(obj) {
6616
+ return toString.call(obj) == '[object String]';
6617
+ };
6618
+
6619
+ _.isDate = function(obj) {
6620
+ return toString.call(obj) == '[object Date]';
6621
+ };
6622
+
6623
+ _.isNumber = function(obj) {
6624
+ return toString.call(obj) == '[object Number]';
6625
+ };
6626
+
6627
+ _.isElement = function(obj) {
6628
+ return !!(obj && obj.nodeType === 1);
6629
+ };
6630
+
6631
+ _.encodeDates = function(obj) {
6632
+ _.each(obj, function(v, k) {
6633
+ if (_.isDate(v)) {
6634
+ obj[k] = _.formatDate(v);
6635
+ } else if (_.isObject(v)) {
6636
+ obj[k] = _.encodeDates(v); // recurse
6637
+ }
6638
+ });
6639
+ return obj;
6640
+ };
6641
+
6642
+ _.timestamp = function() {
6643
+ Date.now = Date.now || function() {
6644
+ return +new Date;
6645
+ };
6646
+ return Date.now();
6647
+ };
6648
+
6649
+ _.formatDate = function(d) {
6650
+ // YYYY-MM-DDTHH:MM:SS in UTC
6651
+ function pad(n) {
6652
+ return n < 10 ? '0' + n : n;
6653
+ }
6654
+ return d.getUTCFullYear() + '-' +
6655
+ pad(d.getUTCMonth() + 1) + '-' +
6656
+ pad(d.getUTCDate()) + 'T' +
6657
+ pad(d.getUTCHours()) + ':' +
6658
+ pad(d.getUTCMinutes()) + ':' +
6659
+ pad(d.getUTCSeconds());
6660
+ };
6661
+
6662
+ _.strip_empty_properties = function(p) {
6663
+ var ret = {};
6664
+ _.each(p, function(v, k) {
6665
+ if (_.isString(v) && v.length > 0) {
6666
+ ret[k] = v;
6667
+ }
6668
+ });
6669
+ return ret;
6670
+ };
6671
+
6672
+ /*
6673
+ * this function returns a copy of object after truncating it. If
6674
+ * passed an Array or Object it will iterate through obj and
6675
+ * truncate all the values recursively.
6676
+ */
6677
+ _.truncate = function(obj, length) {
6678
+ var ret;
6679
+
6680
+ if (typeof(obj) === 'string') {
6681
+ ret = obj.slice(0, length);
6682
+ } else if (_.isArray(obj)) {
6683
+ ret = [];
6684
+ _.each(obj, function(val) {
6685
+ ret.push(_.truncate(val, length));
6686
+ });
6118
6687
  } else if (_.isObject(obj)) {
6119
6688
  ret = {};
6120
6689
  _.each(obj, function(val, key) {
@@ -11563,1141 +12132,233 @@
11563
12132
  MixpanelLib.prototype['time_event'] = MixpanelLib.prototype.time_event;
11564
12133
  MixpanelLib.prototype['track'] = MixpanelLib.prototype.track;
11565
12134
  MixpanelLib.prototype['track_links'] = MixpanelLib.prototype.track_links;
11566
- MixpanelLib.prototype['track_forms'] = MixpanelLib.prototype.track_forms;
11567
- MixpanelLib.prototype['track_pageview'] = MixpanelLib.prototype.track_pageview;
11568
- MixpanelLib.prototype['register'] = MixpanelLib.prototype.register;
11569
- MixpanelLib.prototype['register_once'] = MixpanelLib.prototype.register_once;
11570
- MixpanelLib.prototype['unregister'] = MixpanelLib.prototype.unregister;
11571
- MixpanelLib.prototype['identify'] = MixpanelLib.prototype.identify;
11572
- MixpanelLib.prototype['alias'] = MixpanelLib.prototype.alias;
11573
- MixpanelLib.prototype['name_tag'] = MixpanelLib.prototype.name_tag;
11574
- MixpanelLib.prototype['set_config'] = MixpanelLib.prototype.set_config;
11575
- MixpanelLib.prototype['get_config'] = MixpanelLib.prototype.get_config;
11576
- MixpanelLib.prototype['get_property'] = MixpanelLib.prototype.get_property;
11577
- MixpanelLib.prototype['get_distinct_id'] = MixpanelLib.prototype.get_distinct_id;
11578
- MixpanelLib.prototype['toString'] = MixpanelLib.prototype.toString;
11579
- MixpanelLib.prototype['opt_out_tracking'] = MixpanelLib.prototype.opt_out_tracking;
11580
- MixpanelLib.prototype['opt_in_tracking'] = MixpanelLib.prototype.opt_in_tracking;
11581
- MixpanelLib.prototype['has_opted_out_tracking'] = MixpanelLib.prototype.has_opted_out_tracking;
11582
- MixpanelLib.prototype['has_opted_in_tracking'] = MixpanelLib.prototype.has_opted_in_tracking;
11583
- MixpanelLib.prototype['clear_opt_in_out_tracking'] = MixpanelLib.prototype.clear_opt_in_out_tracking;
11584
- MixpanelLib.prototype['get_group'] = MixpanelLib.prototype.get_group;
11585
- MixpanelLib.prototype['set_group'] = MixpanelLib.prototype.set_group;
11586
- MixpanelLib.prototype['add_group'] = MixpanelLib.prototype.add_group;
11587
- MixpanelLib.prototype['remove_group'] = MixpanelLib.prototype.remove_group;
11588
- MixpanelLib.prototype['track_with_groups'] = MixpanelLib.prototype.track_with_groups;
11589
- MixpanelLib.prototype['start_batch_senders'] = MixpanelLib.prototype.start_batch_senders;
11590
- MixpanelLib.prototype['stop_batch_senders'] = MixpanelLib.prototype.stop_batch_senders;
11591
-
11592
- // MixpanelPersistence Exports
11593
- MixpanelPersistence.prototype['properties'] = MixpanelPersistence.prototype.properties;
11594
- MixpanelPersistence.prototype['update_search_keyword'] = MixpanelPersistence.prototype.update_search_keyword;
11595
- MixpanelPersistence.prototype['update_referrer_info'] = MixpanelPersistence.prototype.update_referrer_info;
11596
- MixpanelPersistence.prototype['get_cross_subdomain'] = MixpanelPersistence.prototype.get_cross_subdomain;
11597
- MixpanelPersistence.prototype['clear'] = MixpanelPersistence.prototype.clear;
11598
-
11599
-
11600
- var instances = {};
11601
- var extend_mp = function() {
11602
- // add all the sub mixpanel instances
11603
- _.each(instances, function(instance, name) {
11604
- if (name !== PRIMARY_INSTANCE_NAME) { mixpanel_master[name] = instance; }
11605
- });
11606
-
11607
- // add private functions as _
11608
- mixpanel_master['_'] = _;
11609
- };
11610
-
11611
- var override_mp_init_func = function() {
11612
- // we override the snippets init function to handle the case where a
11613
- // user initializes the mixpanel library after the script loads & runs
11614
- mixpanel_master['init'] = function(token, config, name) {
11615
- if (name) {
11616
- // initialize a sub library
11617
- if (!mixpanel_master[name]) {
11618
- mixpanel_master[name] = instances[name] = create_mplib(token, config, name);
11619
- mixpanel_master[name]._loaded();
11620
- }
11621
- return mixpanel_master[name];
11622
- } else {
11623
- var instance = mixpanel_master;
11624
-
11625
- if (instances[PRIMARY_INSTANCE_NAME]) {
11626
- // main mixpanel lib already initialized
11627
- instance = instances[PRIMARY_INSTANCE_NAME];
11628
- } else if (token) {
11629
- // intialize the main mixpanel lib
11630
- instance = create_mplib(token, config, PRIMARY_INSTANCE_NAME);
11631
- instance._loaded();
11632
- instances[PRIMARY_INSTANCE_NAME] = instance;
11633
- }
11634
-
11635
- mixpanel_master = instance;
11636
- if (init_type === INIT_SNIPPET) {
11637
- window$1[PRIMARY_INSTANCE_NAME] = mixpanel_master;
11638
- }
11639
- extend_mp();
11640
- }
11641
- };
11642
- };
11643
-
11644
- var add_dom_loaded_handler = function() {
11645
- // Cross browser DOM Loaded support
11646
- function dom_loaded_handler() {
11647
- // function flag since we only want to execute this once
11648
- if (dom_loaded_handler.done) { return; }
11649
- dom_loaded_handler.done = true;
11650
-
11651
- DOM_LOADED = true;
11652
- ENQUEUE_REQUESTS = false;
11653
-
11654
- _.each(instances, function(inst) {
11655
- inst._dom_loaded();
11656
- });
11657
- }
11658
-
11659
- function do_scroll_check() {
11660
- try {
11661
- document$1.documentElement.doScroll('left');
11662
- } catch(e) {
11663
- setTimeout(do_scroll_check, 1);
11664
- return;
11665
- }
11666
-
11667
- dom_loaded_handler();
11668
- }
11669
-
11670
- if (document$1.addEventListener) {
11671
- if (document$1.readyState === 'complete') {
11672
- // safari 4 can fire the DOMContentLoaded event before loading all
11673
- // external JS (including this file). you will see some copypasta
11674
- // on the internet that checks for 'complete' and 'loaded', but
11675
- // 'loaded' is an IE thing
11676
- dom_loaded_handler();
11677
- } else {
11678
- document$1.addEventListener('DOMContentLoaded', dom_loaded_handler, false);
11679
- }
11680
- } else if (document$1.attachEvent) {
11681
- // IE
11682
- document$1.attachEvent('onreadystatechange', dom_loaded_handler);
11683
-
11684
- // check to make sure we arn't in a frame
11685
- var toplevel = false;
11686
- try {
11687
- toplevel = window$1.frameElement === null;
11688
- } catch(e) {
11689
- // noop
11690
- }
11691
-
11692
- if (document$1.documentElement.doScroll && toplevel) {
11693
- do_scroll_check();
11694
- }
11695
- }
11696
-
11697
- // fallback handler, always will work
11698
- _.register_event(window$1, 'load', dom_loaded_handler, true);
11699
- };
11700
-
11701
- function init_as_module() {
11702
- init_type = INIT_MODULE;
11703
- mixpanel_master = new MixpanelLib();
11704
-
11705
- override_mp_init_func();
11706
- mixpanel_master['init']();
11707
- add_dom_loaded_handler();
11708
-
11709
- return mixpanel_master;
11710
- }
11711
-
11712
- var mixpanel = init_as_module();
11713
-
11714
- var mixpanel_cjs = mixpanel;
11715
-
11716
- var mixpanel$1 = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.assign(/*#__PURE__*/Object.create(null), mixpanel_cjs, {
11717
- 'default': mixpanel_cjs
11718
- }));
11719
-
11720
- // Needed to avoid error in CJS builds on some bundlers.
11721
- const mixpanelLib = mixpanel_cjs || mixpanel$1;
11722
- let mixpanelInstance;
11723
- const MIXPANEL_EVENT = {
11724
- VISUAL_SDK_RENDER_START: 'visual-sdk-render-start',
11725
- VISUAL_SDK_CALLED_INIT: 'visual-sdk-called-init',
11726
- VISUAL_SDK_RENDER_COMPLETE: 'visual-sdk-render-complete',
11727
- VISUAL_SDK_RENDER_FAILED: 'visual-sdk-render-failed',
11728
- VISUAL_SDK_TRIGGER: 'visual-sdk-trigger',
11729
- VISUAL_SDK_ON: 'visual-sdk-on',
11730
- VISUAL_SDK_IFRAME_LOAD_PERFORMANCE: 'visual-sdk-iframe-load-performance',
11731
- VISUAL_SDK_EMBED_CREATE: 'visual-sdk-embed-create',
11732
- };
11733
- let isMixpanelInitialized = false;
11734
- let eventQueue = [];
11735
- /**
11736
- * Pushes the event with its Property key-value map to mixpanel.
11737
- *
11738
- * @param eventId
11739
- * @param eventProps
11740
- */
11741
- function uploadMixpanelEvent(eventId, eventProps = {}) {
11742
- if (!isMixpanelInitialized) {
11743
- eventQueue.push({ eventId, eventProps });
11744
- return;
11745
- }
11746
- mixpanelInstance.track(eventId, eventProps);
11747
- }
11748
- /**
11749
- *
11750
- */
11751
- function emptyQueue() {
11752
- if (!isMixpanelInitialized) {
11753
- return;
11754
- }
11755
- eventQueue.forEach((event) => {
11756
- uploadMixpanelEvent(event.eventId, event.eventProps);
11757
- });
11758
- eventQueue = [];
11759
- }
11760
- /**
11761
- *
11762
- * @param sessionInfo
11763
- */
11764
- function initMixpanel(sessionInfo) {
11765
- var _a;
11766
- if (!sessionInfo || !sessionInfo.mixpanelToken) {
11767
- return;
11768
- }
11769
- // On a public cluster the user is anonymous, so don't set the identify to
11770
- // userGUID
11771
- const isPublicCluster = !!sessionInfo.isPublicUser;
11772
- const token = sessionInfo.mixpanelToken;
11773
- try {
11774
- if (token) {
11775
- mixpanelInstance = mixpanelLib.init(token, undefined, 'tsEmbed');
11776
- if (!isPublicCluster) {
11777
- mixpanelInstance.identify(sessionInfo.userGUID);
11778
- }
11779
- mixpanelInstance.register_once({
11780
- clusterId: sessionInfo.clusterId,
11781
- clusterName: sessionInfo.clusterName,
11782
- releaseVersion: sessionInfo.releaseVersion,
11783
- hostAppUrl: ((_a = window === null || window === void 0 ? void 0 : window.location) === null || _a === void 0 ? void 0 : _a.host) || '',
11784
- });
11785
- isMixpanelInitialized = true;
11786
- emptyQueue();
11787
- }
11788
- }
11789
- catch (e) {
11790
- logger.error('Error initializing mixpanel', e);
11791
- }
11792
- }
11793
-
11794
- let config = {};
11795
- /**
11796
- * Gets the configuration embed was initialized with.
11797
- *
11798
- * @returns {@link EmbedConfig} The configuration embed was initialized with.
11799
- * @version SDK: 1.19.0 | ThoughtSpot: *
11800
- * @group Global methods
11801
- */
11802
- const getEmbedConfig = () => config;
11803
- /**
11804
- * Sets the configuration embed was initialized with.
11805
- * And returns the new configuration.
11806
- *
11807
- * @param newConfig The configuration to set.
11808
- * @version SDK: 1.27.0 | ThoughtSpot: *
11809
- * @group Global methods
11810
- */
11811
- const setEmbedConfig = (newConfig) => {
11812
- config = newConfig;
11813
- return newConfig;
11814
- };
11815
-
11816
- const tokenizedFetch = async (input, init) => {
11817
- const embedConfig = getEmbedConfig();
11818
- if (embedConfig.authType !== exports.AuthType.TrustedAuthTokenCookieless) {
11819
- return fetch(input, init);
11820
- }
11821
- const req = new Request(input, init);
11822
- const authToken = await getAuthenticationToken(embedConfig);
11823
- if (authToken) {
11824
- req.headers.append('Authorization', `Bearer ${authToken}`);
11825
- }
11826
- return fetch(req);
11827
- };
11828
-
11829
- /**
11830
- *
11831
- * @param url
11832
- * @param options
11833
- */
11834
- function tokenisedFailureLoggedFetch(url, options = {}) {
11835
- return tokenizedFetch(url, options).then(async (r) => {
11836
- var _a;
11837
- if (!r.ok && r.type !== 'opaqueredirect' && r.type !== 'opaque') {
11838
- logger.error('Failure', await ((_a = r.text) === null || _a === void 0 ? void 0 : _a.call(r)));
11839
- }
11840
- return r;
11841
- });
11842
- }
11843
- /**
11844
- *
11845
- * @param authVerificationUrl
11846
- */
11847
- function fetchSessionInfoService(authVerificationUrl) {
11848
- return tokenisedFailureLoggedFetch(authVerificationUrl, {
11849
- credentials: 'include',
11850
- });
11851
- }
11852
- /**
11853
- *
11854
- * @param thoughtSpotHost
11855
- */
11856
- async function fetchLogoutService(thoughtSpotHost) {
11857
- return tokenisedFailureLoggedFetch(`${thoughtSpotHost}${EndPoints.LOGOUT}`, {
11858
- credentials: 'include',
11859
- method: 'POST',
11860
- headers: {
11861
- 'x-requested-by': 'ThoughtSpot',
11862
- },
11863
- });
11864
- }
11865
-
11866
- // eslint-disable-next-line import/no-mutable-exports
11867
- let loggedInStatus = false;
11868
- // eslint-disable-next-line import/no-mutable-exports
11869
- let samlAuthWindow = null;
11870
- // eslint-disable-next-line import/no-mutable-exports
11871
- let samlCompletionPromise = null;
11872
- let sessionInfo = null;
11873
- let sessionInfoResolver = null;
11874
- const sessionInfoPromise = new Promise((resolve) => {
11875
- sessionInfoResolver = resolve;
11876
- });
11877
- let releaseVersion = '';
11878
- const SSO_REDIRECTION_MARKER_GUID = '5e16222e-ef02-43e9-9fbd-24226bf3ce5b';
11879
- (function (AuthFailureType) {
11880
- AuthFailureType["SDK"] = "SDK";
11881
- AuthFailureType["NO_COOKIE_ACCESS"] = "NO_COOKIE_ACCESS";
11882
- AuthFailureType["EXPIRY"] = "EXPIRY";
11883
- AuthFailureType["OTHER"] = "OTHER";
11884
- })(exports.AuthFailureType || (exports.AuthFailureType = {}));
11885
- (function (AuthStatus) {
11886
- /**
11887
- * Emits when the SDK fails to authenticate
11888
- */
11889
- AuthStatus["FAILURE"] = "FAILURE";
11890
- /**
11891
- * Emits when the SDK authenticates successfully
11892
- */
11893
- AuthStatus["SDK_SUCCESS"] = "SDK_SUCCESS";
11894
- /**
11895
- * Emits when the app sends an authentication success message
11896
- */
11897
- AuthStatus["SUCCESS"] = "SUCCESS";
11898
- /**
11899
- * Emits when a user logs out
11900
- */
11901
- AuthStatus["LOGOUT"] = "LOGOUT";
11902
- /**
11903
- * Emitted when inPopup is true in the SAMLRedirect flow and the
11904
- * popup is waiting to be triggered either programmatically
11905
- * or by the trigger button.
11906
- *
11907
- * @version SDK: 1.19.0
11908
- */
11909
- AuthStatus["WAITING_FOR_POPUP"] = "WAITING_FOR_POPUP";
11910
- })(exports.AuthStatus || (exports.AuthStatus = {}));
11911
- (function (AuthEvent) {
11912
- /**
11913
- * Manually trigger the SSO popup. This is useful when
11914
- * authStatus is SAMLRedirect/OIDCRedirect and inPopup is set to true
11915
- */
11916
- AuthEvent["TRIGGER_SSO_POPUP"] = "TRIGGER_SSO_POPUP";
11917
- })(exports.AuthEvent || (exports.AuthEvent = {}));
11918
- let authEE;
11919
- /**
11920
- *
11921
- * @param eventEmitter
11922
- */
11923
- function setAuthEE(eventEmitter) {
11924
- authEE = eventEmitter;
11925
- }
11926
- /**
11927
- *
11928
- */
11929
- function notifyAuthSDKSuccess() {
11930
- if (!authEE) {
11931
- logger.error('SDK not initialized');
11932
- return;
11933
- }
11934
- authEE.emit(exports.AuthStatus.SDK_SUCCESS);
11935
- }
11936
- /**
11937
- *
11938
- */
11939
- function notifyAuthSuccess() {
11940
- if (!authEE) {
11941
- logger.error('SDK not initialized');
11942
- return;
11943
- }
11944
- authEE.emit(exports.AuthStatus.SUCCESS, sessionInfo);
11945
- }
11946
- /**
11947
- *
11948
- * @param failureType
11949
- */
11950
- function notifyAuthFailure(failureType) {
11951
- if (!authEE) {
11952
- logger.error('SDK not initialized');
11953
- return;
11954
- }
11955
- authEE.emit(exports.AuthStatus.FAILURE, failureType);
11956
- }
11957
- /**
11958
- *
11959
- */
11960
- function notifyLogout() {
11961
- if (!authEE) {
11962
- logger.error('SDK not initialized');
11963
- return;
11964
- }
11965
- authEE.emit(exports.AuthStatus.LOGOUT);
11966
- }
11967
- const initSession = (sessionDetails) => {
11968
- if (sessionInfo == null) {
11969
- sessionInfo = sessionDetails;
11970
- initMixpanel(sessionInfo);
11971
- sessionInfoResolver(sessionInfo);
11972
- }
11973
- };
11974
- const getSessionDetails = (sessionInfoResp) => {
11975
- const devMixpanelToken = sessionInfoResp.configInfo.mixpanelConfig.devSdkKey;
11976
- const prodMixpanelToken = sessionInfoResp.configInfo.mixpanelConfig.prodSdkKey;
11977
- const mixpanelToken = sessionInfoResp.configInfo.mixpanelConfig.production
11978
- ? prodMixpanelToken
11979
- : devMixpanelToken;
11980
- return {
11981
- userGUID: sessionInfoResp.userGUID,
11982
- mixpanelToken,
11983
- isPublicUser: sessionInfoResp.configInfo.isPublicUser,
11984
- releaseVersion: sessionInfoResp.releaseVersion,
11985
- clusterId: sessionInfoResp.configInfo.selfClusterId,
11986
- clusterName: sessionInfoResp.configInfo.selfClusterName,
11987
- ...sessionInfoResp,
11988
- };
11989
- };
11990
- /**
11991
- * Check if we are logged into the ThoughtSpot cluster
11992
- *
11993
- * @param thoughtSpotHost The ThoughtSpot cluster hostname or IP
11994
- */
11995
- async function isLoggedIn(thoughtSpotHost) {
11996
- const authVerificationUrl = `${thoughtSpotHost}${EndPoints.AUTH_VERIFICATION}`;
11997
- let response = null;
11998
- try {
11999
- response = await fetchSessionInfoService(authVerificationUrl);
12000
- const sessionInfoResp = await response.json();
12001
- const sessionDetails = getSessionDetails(sessionInfoResp);
12002
- // Store user session details from session info
12003
- initSession(sessionDetails);
12004
- releaseVersion = sessionInfoResp.releaseVersion;
12005
- }
12006
- catch (e) {
12007
- return false;
12008
- }
12009
- return response.status === 200;
12010
- }
12011
- /**
12012
- * Return releaseVersion if available
12013
- */
12014
- function getReleaseVersion() {
12015
- return releaseVersion;
12016
- }
12017
- /**
12018
- * Return a promise that resolves with the session information when
12019
- * authentication is successful. And info is available.
12020
- *
12021
- * @group Global methods
12022
- */
12023
- function getSessionInfo() {
12024
- return sessionInfoPromise;
12025
- }
12026
- /**
12027
- * Check if we are stuck at the SSO redirect URL
12028
- */
12029
- function isAtSSORedirectUrl() {
12030
- return window.location.href.indexOf(SSO_REDIRECTION_MARKER_GUID) >= 0;
12031
- }
12032
- /**
12033
- * Remove the SSO redirect URL marker
12034
- */
12035
- function removeSSORedirectUrlMarker() {
12036
- // Note (sunny): This will leave a # around even if it was not in the URL
12037
- // to begin with. Trying to remove the hash by changing window.location will
12038
- // reload the page which we don't want. We'll live with adding an
12039
- // unnecessary hash to the parent page URL until we find any use case where
12040
- // that creates an issue.
12041
- window.location.hash = window.location.hash.replace(SSO_REDIRECTION_MARKER_GUID, '');
12042
- }
12043
- /**
12044
- * Perform token based authentication
12045
- *
12046
- * @param embedConfig The embed configuration
12047
- */
12048
- const doTokenAuth = async (embedConfig) => {
12049
- const { thoughtSpotHost, username, authEndpoint, getAuthToken, } = embedConfig;
12050
- if (!authEndpoint && !getAuthToken) {
12051
- throw new Error('Either auth endpoint or getAuthToken function must be provided');
12052
- }
12053
- loggedInStatus = await isLoggedIn(thoughtSpotHost);
12054
- if (!loggedInStatus) {
12055
- const authToken = await getAuthenticationToken(embedConfig);
12056
- let resp;
12057
- try {
12058
- resp = await fetchAuthPostService(thoughtSpotHost, username, authToken);
12059
- }
12060
- catch (e) {
12061
- resp = await fetchAuthService(thoughtSpotHost, username, authToken);
12062
- }
12063
- // token login issues a 302 when successful
12064
- loggedInStatus = resp.ok || resp.type === 'opaqueredirect';
12065
- if (loggedInStatus && embedConfig.detectCookieAccessSlow) {
12066
- // When 3rd party cookie access is blocked, this will fail because
12067
- // cookies will not be sent with the call.
12068
- loggedInStatus = await isLoggedIn(thoughtSpotHost);
12069
- }
12070
- }
12071
- return loggedInStatus;
12072
- };
12073
- /**
12074
- * Validate embedConfig parameters required for cookielessTokenAuth
12075
- *
12076
- * @param embedConfig The embed configuration
12077
- */
12078
- const doCookielessTokenAuth = async (embedConfig) => {
12079
- const { authEndpoint, getAuthToken } = embedConfig;
12080
- if (!authEndpoint && !getAuthToken) {
12081
- throw new Error('Either auth endpoint or getAuthToken function must be provided');
12082
- }
12083
- let authSuccess = false;
12084
- try {
12085
- const authToken = await getAuthenticationToken(embedConfig);
12086
- if (authToken) {
12087
- authSuccess = true;
12088
- }
12089
- }
12090
- catch {
12091
- authSuccess = false;
12092
- }
12093
- return authSuccess;
12094
- };
12095
- /**
12096
- * Perform basic authentication to the ThoughtSpot cluster using the cluster
12097
- * credentials.
12098
- *
12099
- * Warning: This feature is primarily intended for developer testing. It is
12100
- * strongly advised not to use this authentication method in production.
12101
- *
12102
- * @param embedConfig The embed configuration
12103
- */
12104
- const doBasicAuth = async (embedConfig) => {
12105
- const { thoughtSpotHost, username, password } = embedConfig;
12106
- const loggedIn = await isLoggedIn(thoughtSpotHost);
12107
- if (!loggedIn) {
12108
- const response = await fetchBasicAuthService(thoughtSpotHost, username, password);
12109
- loggedInStatus = response.ok;
12110
- if (embedConfig.detectCookieAccessSlow) {
12111
- loggedInStatus = await isLoggedIn(thoughtSpotHost);
12112
- }
12113
- }
12114
- else {
12115
- loggedInStatus = true;
12116
- }
12117
- return loggedInStatus;
12118
- };
12119
- /**
12120
- *
12121
- * @param ssoURL
12122
- * @param triggerContainer
12123
- * @param triggerText
12124
- */
12125
- async function samlPopupFlow(ssoURL, triggerContainer, triggerText) {
12126
- const openPopup = () => {
12127
- if (samlAuthWindow === null || samlAuthWindow.closed) {
12128
- samlAuthWindow = window.open(ssoURL, '_blank', 'location=no,height=570,width=520,scrollbars=yes,status=yes');
12129
- }
12130
- else {
12131
- samlAuthWindow.focus();
12132
- }
12133
- };
12134
- authEE === null || authEE === void 0 ? void 0 : authEE.emit(exports.AuthStatus.WAITING_FOR_POPUP);
12135
- const containerEl = getDOMNode(triggerContainer);
12136
- if (containerEl) {
12137
- containerEl.innerHTML = '<button id="ts-auth-btn" class="ts-auth-btn" style="margin: auto;"></button>';
12138
- const authElem = document.getElementById('ts-auth-btn');
12139
- authElem.textContent = triggerText;
12140
- authElem.addEventListener('click', openPopup, { once: true });
12141
- }
12142
- samlCompletionPromise = samlCompletionPromise
12143
- || new Promise((resolve, reject) => {
12144
- window.addEventListener('message', (e) => {
12145
- if (e.data.type === exports.EmbedEvent.SAMLComplete) {
12146
- e.source.close();
12147
- resolve();
12148
- }
12149
- });
12150
- });
12151
- authEE === null || authEE === void 0 ? void 0 : authEE.once(exports.AuthEvent.TRIGGER_SSO_POPUP, openPopup);
12152
- return samlCompletionPromise;
12153
- }
12154
- /**
12155
- * Perform SAML authentication
12156
- *
12157
- * @param embedConfig The embed configuration
12158
- * @param ssoEndPoint
12159
- */
12160
- const doSSOAuth = async (embedConfig, ssoEndPoint) => {
12161
- const { thoughtSpotHost } = embedConfig;
12162
- const loggedIn = await isLoggedIn(thoughtSpotHost);
12163
- if (loggedIn) {
12164
- if (isAtSSORedirectUrl()) {
12165
- removeSSORedirectUrlMarker();
12166
- }
12167
- loggedInStatus = true;
12168
- return;
12169
- }
12170
- // we have already tried authentication and it did not succeed, restore
12171
- // the current URL to the original one and invoke the callback.
12172
- if (isAtSSORedirectUrl()) {
12173
- removeSSORedirectUrlMarker();
12174
- loggedInStatus = false;
12175
- return;
12176
- }
12177
- const ssoURL = `${thoughtSpotHost}${ssoEndPoint}`;
12178
- if (embedConfig.inPopup) {
12179
- await samlPopupFlow(ssoURL, embedConfig.authTriggerContainer, embedConfig.authTriggerText);
12180
- loggedInStatus = await isLoggedIn(thoughtSpotHost);
12181
- return;
12182
- }
12183
- window.location.href = ssoURL;
12184
- };
12185
- const doSamlAuth = async (embedConfig) => {
12186
- const { thoughtSpotHost } = embedConfig;
12187
- // redirect for SSO, when the SSO authentication is done, this page will be
12188
- // loaded again and the same JS will execute again.
12189
- const ssoRedirectUrl = embedConfig.inPopup
12190
- ? `${thoughtSpotHost}/v2/#/embed/saml-complete`
12191
- : getRedirectUrl(window.location.href, SSO_REDIRECTION_MARKER_GUID, embedConfig.redirectPath);
12192
- // bring back the page to the same URL
12193
- const ssoEndPoint = `${EndPoints.SAML_LOGIN_TEMPLATE(encodeURIComponent(ssoRedirectUrl))}`;
12194
- await doSSOAuth(embedConfig, ssoEndPoint);
12195
- return loggedInStatus;
12196
- };
12197
- const doOIDCAuth = async (embedConfig) => {
12198
- const { thoughtSpotHost } = embedConfig;
12199
- // redirect for SSO, when the SSO authentication is done, this page will be
12200
- // loaded again and the same JS will execute again.
12201
- const ssoRedirectUrl = embedConfig.noRedirect || embedConfig.inPopup
12202
- ? `${thoughtSpotHost}/v2/#/embed/saml-complete`
12203
- : getRedirectUrl(window.location.href, SSO_REDIRECTION_MARKER_GUID, embedConfig.redirectPath);
12204
- // bring back the page to the same URL
12205
- const ssoEndPoint = `${EndPoints.OIDC_LOGIN_TEMPLATE(encodeURIComponent(ssoRedirectUrl))}`;
12206
- await doSSOAuth(embedConfig, ssoEndPoint);
12207
- return loggedInStatus;
12208
- };
12209
- const logout = async (embedConfig) => {
12210
- const { thoughtSpotHost } = embedConfig;
12211
- await fetchLogoutService(thoughtSpotHost);
12212
- resetCachedAuthToken();
12213
- const thoughtspotIframes = document.querySelectorAll("[data-ts-iframe='true']");
12214
- if (thoughtspotIframes === null || thoughtspotIframes === void 0 ? void 0 : thoughtspotIframes.length) {
12215
- thoughtspotIframes.forEach((el) => {
12216
- el.parentElement.innerHTML = embedConfig.loginFailedMessage;
12217
- });
12218
- }
12219
- loggedInStatus = false;
12220
- return loggedInStatus;
12221
- };
12222
- /**
12223
- * Perform authentication on the ThoughtSpot cluster
12224
- *
12225
- * @param embedConfig The embed configuration
12226
- */
12227
- const authenticate = async (embedConfig) => {
12228
- const { authType } = embedConfig;
12229
- switch (authType) {
12230
- case exports.AuthType.SSO:
12231
- case exports.AuthType.SAMLRedirect:
12232
- case exports.AuthType.SAML:
12233
- return doSamlAuth(embedConfig);
12234
- case exports.AuthType.OIDC:
12235
- case exports.AuthType.OIDCRedirect:
12236
- return doOIDCAuth(embedConfig);
12237
- case exports.AuthType.AuthServer:
12238
- case exports.AuthType.TrustedAuthToken:
12239
- return doTokenAuth(embedConfig);
12240
- case exports.AuthType.TrustedAuthTokenCookieless:
12241
- return doCookielessTokenAuth(embedConfig);
12242
- case exports.AuthType.Basic:
12243
- return doBasicAuth(embedConfig);
12244
- default:
12245
- return Promise.resolve(true);
12246
- }
12135
+ MixpanelLib.prototype['track_forms'] = MixpanelLib.prototype.track_forms;
12136
+ MixpanelLib.prototype['track_pageview'] = MixpanelLib.prototype.track_pageview;
12137
+ MixpanelLib.prototype['register'] = MixpanelLib.prototype.register;
12138
+ MixpanelLib.prototype['register_once'] = MixpanelLib.prototype.register_once;
12139
+ MixpanelLib.prototype['unregister'] = MixpanelLib.prototype.unregister;
12140
+ MixpanelLib.prototype['identify'] = MixpanelLib.prototype.identify;
12141
+ MixpanelLib.prototype['alias'] = MixpanelLib.prototype.alias;
12142
+ MixpanelLib.prototype['name_tag'] = MixpanelLib.prototype.name_tag;
12143
+ MixpanelLib.prototype['set_config'] = MixpanelLib.prototype.set_config;
12144
+ MixpanelLib.prototype['get_config'] = MixpanelLib.prototype.get_config;
12145
+ MixpanelLib.prototype['get_property'] = MixpanelLib.prototype.get_property;
12146
+ MixpanelLib.prototype['get_distinct_id'] = MixpanelLib.prototype.get_distinct_id;
12147
+ MixpanelLib.prototype['toString'] = MixpanelLib.prototype.toString;
12148
+ MixpanelLib.prototype['opt_out_tracking'] = MixpanelLib.prototype.opt_out_tracking;
12149
+ MixpanelLib.prototype['opt_in_tracking'] = MixpanelLib.prototype.opt_in_tracking;
12150
+ MixpanelLib.prototype['has_opted_out_tracking'] = MixpanelLib.prototype.has_opted_out_tracking;
12151
+ MixpanelLib.prototype['has_opted_in_tracking'] = MixpanelLib.prototype.has_opted_in_tracking;
12152
+ MixpanelLib.prototype['clear_opt_in_out_tracking'] = MixpanelLib.prototype.clear_opt_in_out_tracking;
12153
+ MixpanelLib.prototype['get_group'] = MixpanelLib.prototype.get_group;
12154
+ MixpanelLib.prototype['set_group'] = MixpanelLib.prototype.set_group;
12155
+ MixpanelLib.prototype['add_group'] = MixpanelLib.prototype.add_group;
12156
+ MixpanelLib.prototype['remove_group'] = MixpanelLib.prototype.remove_group;
12157
+ MixpanelLib.prototype['track_with_groups'] = MixpanelLib.prototype.track_with_groups;
12158
+ MixpanelLib.prototype['start_batch_senders'] = MixpanelLib.prototype.start_batch_senders;
12159
+ MixpanelLib.prototype['stop_batch_senders'] = MixpanelLib.prototype.stop_batch_senders;
12160
+
12161
+ // MixpanelPersistence Exports
12162
+ MixpanelPersistence.prototype['properties'] = MixpanelPersistence.prototype.properties;
12163
+ MixpanelPersistence.prototype['update_search_keyword'] = MixpanelPersistence.prototype.update_search_keyword;
12164
+ MixpanelPersistence.prototype['update_referrer_info'] = MixpanelPersistence.prototype.update_referrer_info;
12165
+ MixpanelPersistence.prototype['get_cross_subdomain'] = MixpanelPersistence.prototype.get_cross_subdomain;
12166
+ MixpanelPersistence.prototype['clear'] = MixpanelPersistence.prototype.clear;
12167
+
12168
+
12169
+ var instances = {};
12170
+ var extend_mp = function() {
12171
+ // add all the sub mixpanel instances
12172
+ _.each(instances, function(instance, name) {
12173
+ if (name !== PRIMARY_INSTANCE_NAME) { mixpanel_master[name] = instance; }
12174
+ });
12175
+
12176
+ // add private functions as _
12177
+ mixpanel_master['_'] = _;
12247
12178
  };
12248
12179
 
12249
- const ERROR_MESSAGE = {
12250
- INVALID_THOUGHTSPOT_HOST: 'Error parsing ThoughtSpot host. Please provide a valid URL.',
12251
- LIVEBOARD_VIZ_ID_VALIDATION: 'Please provide either liveboardId or pinboardId',
12252
- TRIGGER_TIMED_OUT: 'Trigger timedout in getting response',
12253
- SEARCHEMBED_BETA_WRANING_MESSAGE: 'Search Embed is in Beta in this release.',
12254
- SAGE_EMBED_BETA_WARNING_MESSAGE: 'Sage Embed is in Beta in this release.',
12180
+ var override_mp_init_func = function() {
12181
+ // we override the snippets init function to handle the case where a
12182
+ // user initializes the mixpanel library after the script loads & runs
12183
+ mixpanel_master['init'] = function(token, config, name) {
12184
+ if (name) {
12185
+ // initialize a sub library
12186
+ if (!mixpanel_master[name]) {
12187
+ mixpanel_master[name] = instances[name] = create_mplib(token, config, name);
12188
+ mixpanel_master[name]._loaded();
12189
+ }
12190
+ return mixpanel_master[name];
12191
+ } else {
12192
+ var instance = mixpanel_master;
12193
+
12194
+ if (instances[PRIMARY_INSTANCE_NAME]) {
12195
+ // main mixpanel lib already initialized
12196
+ instance = instances[PRIMARY_INSTANCE_NAME];
12197
+ } else if (token) {
12198
+ // intialize the main mixpanel lib
12199
+ instance = create_mplib(token, config, PRIMARY_INSTANCE_NAME);
12200
+ instance._loaded();
12201
+ instances[PRIMARY_INSTANCE_NAME] = instance;
12202
+ }
12203
+
12204
+ mixpanel_master = instance;
12205
+ if (init_type === INIT_SNIPPET) {
12206
+ window$1[PRIMARY_INSTANCE_NAME] = mixpanel_master;
12207
+ }
12208
+ extend_mp();
12209
+ }
12210
+ };
12255
12211
  };
12256
12212
 
12257
- /**
12258
- * Copyright (c) 2023
12259
- *
12260
- * Utilities related to reading configuration objects
12261
- *
12262
- * @summary Config-related utils
12263
- * @author Ayon Ghosh <ayon.ghosh@thoughtspot.com>
12264
- */
12265
- const urlRegex = new RegExp([
12266
- '(^(https?:)//)?',
12267
- '(([^:/?#]*)(?::([0-9]+))?)',
12268
- '(/{0,1}[^?#]*)',
12269
- '(\\?[^#]*|)',
12270
- '(#.*|)$', // hash
12271
- ].join(''));
12272
- /**
12273
- * Parse and construct the ThoughtSpot hostname or IP address
12274
- * from the embed configuration object.
12275
- *
12276
- * @param config
12277
- */
12278
- const getThoughtSpotHost = (config) => {
12279
- if (!config.thoughtSpotHost) {
12280
- throw new Error(ERROR_MESSAGE.INVALID_THOUGHTSPOT_HOST);
12281
- }
12282
- const urlParts = config.thoughtSpotHost.match(urlRegex);
12283
- if (!urlParts) {
12284
- throw new Error(ERROR_MESSAGE.INVALID_THOUGHTSPOT_HOST);
12285
- }
12286
- const protocol = urlParts[2] || window.location.protocol;
12287
- const host = urlParts[3];
12288
- let path = urlParts[6];
12289
- // Lose the trailing / if any
12290
- if (path.charAt(path.length - 1) === '/') {
12291
- path = path.substring(0, path.length - 1);
12292
- }
12293
- // const urlParams = urlParts[7];
12294
- // const hash = urlParts[8];
12295
- return `${protocol}//${host}${path}`;
12296
- };
12297
- const getV2BasePath = (config) => {
12298
- if (config.basepath) {
12299
- return config.basepath;
12300
- }
12301
- const tsHost = getThoughtSpotHost(config);
12302
- // This is to handle when e2e's. Search is run on pods for
12303
- // comp-blink-test-pipeline with baseUrl=https://localhost:8443.
12304
- // This is to handle when the developer is developing in their local
12305
- // environment.
12306
- if (tsHost.includes('://localhost') && !tsHost.includes(':8443')) {
12307
- return '';
12308
- }
12309
- return 'v2';
12310
- };
12311
- /**
12312
- * It is a good idea to keep URLs under 2000 chars.
12313
- * If this is ever breached, since we pass view configuration through
12314
- * URL params, we would like to log a warning.
12315
- * Reference: https://stackoverflow.com/questions/417142/what-is-the-maximum-length-of-a-url-in-different-browsers
12316
- */
12317
- const URL_MAX_LENGTH = 2000;
12318
- /**
12319
- * The default CSS dimensions of the embedded app
12320
- */
12321
- const DEFAULT_EMBED_WIDTH = '100%';
12322
- const DEFAULT_EMBED_HEIGHT = '100%';
12213
+ var add_dom_loaded_handler = function() {
12214
+ // Cross browser DOM Loaded support
12215
+ function dom_loaded_handler() {
12216
+ // function flag since we only want to execute this once
12217
+ if (dom_loaded_handler.done) { return; }
12218
+ dom_loaded_handler.done = true;
12323
12219
 
12324
- /**
12325
- *
12326
- * @param root0
12327
- * @param root0.query
12328
- * @param root0.variables
12329
- * @param root0.thoughtSpotHost
12330
- * @param root0.isCompositeQuery
12331
- */
12332
- async function graphqlQuery({ query, variables, thoughtSpotHost, isCompositeQuery = false, }) {
12333
- const operationName = getOperationNameFromQuery(query);
12334
- try {
12335
- const response = await fetch(`${thoughtSpotHost}/prism/?op=${operationName}`, {
12336
- method: 'POST',
12337
- headers: {
12338
- 'content-type': 'application/json;charset=UTF-8',
12339
- 'x-requested-by': 'ThoughtSpot',
12340
- accept: '*/*',
12341
- 'accept-language': 'en-us',
12342
- },
12343
- body: JSON.stringify({
12344
- operationName,
12345
- query,
12346
- variables,
12347
- }),
12348
- credentials: 'include',
12349
- });
12350
- const result = await response.json();
12351
- const dataValues = Object.values(result.data);
12352
- return (isCompositeQuery) ? result.data : dataValues[0];
12353
- }
12354
- catch (error) {
12355
- return error;
12356
- }
12357
- }
12220
+ DOM_LOADED = true;
12221
+ ENQUEUE_REQUESTS = false;
12358
12222
 
12359
- const getSourceDetailQuery = `
12360
- query GetSourceDetail($ids: [GUID!]!) {
12361
- getSourceDetailById(ids: $ids, type: LOGICAL_TABLE) {
12362
- id
12363
- name
12364
- description
12365
- authorName
12366
- authorDisplayName
12367
- isExternal
12368
- type
12369
- created
12370
- modified
12371
- columns {
12372
- id
12373
- name
12374
- author
12375
- authorDisplayName
12376
- description
12377
- dataType
12378
- type
12379
- modified
12380
- ownerName
12381
- owner
12382
- dataRecency
12383
- sources {
12384
- tableId
12385
- tableName
12386
- columnId
12387
- columnName
12388
- __typename
12389
- }
12390
- synonyms
12391
- cohortAnswerId
12392
- __typename
12393
- }
12394
- relationships
12395
- destinationRelationships
12396
- dataSourceId
12397
- __typename
12398
- }
12399
- }
12400
- `;
12401
- const sourceDetailCache = new Map();
12402
- /**
12403
- *
12404
- * @param thoughtSpotHost
12405
- * @param sourceId
12406
- */
12407
- async function getSourceDetail(thoughtSpotHost, sourceId) {
12408
- if (sourceDetailCache.get(sourceId)) {
12409
- return sourceDetailCache.get(sourceId);
12410
- }
12411
- const details = await graphqlQuery({
12412
- query: getSourceDetailQuery,
12413
- variables: {
12414
- ids: [sourceId],
12415
- },
12416
- thoughtSpotHost,
12417
- });
12418
- const souceDetails = details[0];
12419
- if (souceDetails) {
12420
- sourceDetailCache.set(sourceId, souceDetails);
12421
- }
12422
- return souceDetails;
12423
- }
12223
+ _.each(instances, function(inst) {
12224
+ inst._dom_loaded();
12225
+ });
12226
+ }
12424
12227
 
12425
- const bachSessionId = `
12426
- id {
12427
- sessionId
12428
- genNo
12429
- acSession {
12430
- sessionId
12431
- genNo
12432
- }
12433
- }
12434
- `;
12435
- const getUnaggregatedAnswerSession = `
12436
- mutation GetUnAggregatedAnswerSession($session: BachSessionIdInput!, $columns: [UserPointSelectionInput!]!) {
12437
- Answer__getUnaggregatedAnswer(session: $session, columns: $columns) {
12438
- ${bachSessionId}
12439
- answer {
12440
- visualizations {
12441
- ... on TableViz {
12442
- columns {
12443
- column {
12444
- id
12445
- name
12446
- referencedColumns {
12447
- guid
12448
- displayName
12449
- }
12450
- }
12451
- }
12452
- }
12453
- }
12454
- }
12455
- }
12456
- }
12457
- `;
12458
- const removeColumns = `
12459
- mutation RemoveColumns($session: BachSessionIdInput!, $logicalColumnIds: [GUID!], $columnIds: [GUID!]) {
12460
- Answer__removeColumns(
12461
- session: $session
12462
- logicalColumnIds: $logicalColumnIds
12463
- columnIds: $columnIds
12464
- ) {
12465
- ${bachSessionId}
12466
- }
12467
- }
12468
- `;
12469
- const addColumns = `
12470
- mutation AddColumns($session: BachSessionIdInput!, $columns: [AnswerColumnInfo!]!) {
12471
- Answer__addColumn(session: $session, columns: $columns) {
12472
- ${bachSessionId}
12473
- }
12474
- }
12475
- `;
12476
- const getAnswerData = `
12477
- query GetTableWithHeadlineData($session: BachSessionIdInput!, $deadline: Int!, $dataPaginationParams: DataPaginationParamsInput!) {
12478
- getAnswer(session: $session) {
12479
- ${bachSessionId}
12480
- answer {
12481
- id
12482
- visualizations {
12483
- id
12484
- ... on TableViz {
12485
- columns {
12486
- column {
12487
- id
12488
- name
12489
- type
12490
- aggregationType
12491
- dataType
12492
- }
12493
- }
12494
- data(deadline: $deadline, pagination: $dataPaginationParams)
12495
- }
12496
- }
12497
- }
12498
- }
12499
- }
12500
- `;
12228
+ function do_scroll_check() {
12229
+ try {
12230
+ document$1.documentElement.doScroll('left');
12231
+ } catch(e) {
12232
+ setTimeout(do_scroll_check, 1);
12233
+ return;
12234
+ }
12501
12235
 
12502
- // eslint-disable-next-line no-shadow
12503
- var OperationType;
12504
- (function (OperationType) {
12505
- OperationType["GetChartWithData"] = "GetChartWithData";
12506
- OperationType["GetTableWithHeadlineData"] = "GetTableWithHeadlineData";
12507
- })(OperationType || (OperationType = {}));
12508
- /**
12509
- * Class representing the answer service provided with the
12510
- * custom action payload. This service could be used to run
12511
- * graphql queries in the context of the answer on which the
12512
- * custom action was triggered.
12513
- *
12514
- * @example
12515
- * ```js
12516
- * embed.on(EmbedEvent.CustomAction, e => {
12517
- * const underlying = await e.answerService.getUnderlyingDataForPoint([
12518
- * 'col name 1'
12519
- * ]);
12520
- * const data = await underlying.fetchData(0, 100);
12521
- * })
12522
- * ```
12523
- * @version SDK: 1.25.0| ThoughtSpot: 9.10.0.cl
12524
- * @group Events
12525
- */
12526
- class AnswerService {
12527
- constructor(session, answer, thoughtSpotHost, selectedPoints) {
12528
- this.session = session;
12529
- this.answer = answer;
12530
- this.thoughtSpotHost = thoughtSpotHost;
12531
- this.selectedPoints = selectedPoints;
12532
- this.session = removeTypename(session);
12533
- }
12534
- async getSourceDetail() {
12535
- const sourceId = this.answer.sources[0].header.guid;
12536
- return getSourceDetail(this.thoughtSpotHost, sourceId);
12537
- }
12538
- async removeColumns(columnIds) {
12539
- return this.executeQuery(removeColumns, {
12540
- logicalColumnIds: columnIds,
12541
- });
12542
- }
12543
- async addColumns(columnIds) {
12544
- return this.executeQuery(addColumns, {
12545
- columns: columnIds.map((colId) => ({ logicalColumnId: colId })),
12546
- });
12547
- }
12548
- async fetchData(offset = 0, size = 1000) {
12549
- const { answer } = await this.executeQuery(getAnswerData, {
12550
- deadline: 0,
12551
- dataPaginationParams: {
12552
- isClientPaginated: true,
12553
- offset,
12554
- size,
12555
- },
12556
- });
12557
- const { columns, data } = answer.visualizations.find((viz) => !!viz.data) || {};
12558
- return {
12559
- columns,
12560
- data,
12561
- };
12562
- }
12563
- /**
12564
- *
12565
- * @param userLocale
12566
- * @param includeInfo Include the CSV header in the output
12567
- * @returns Response
12568
- */
12569
- async fetchCSVBlob(userLocale = 'en-us', includeInfo = false) {
12570
- const fetchUrl = this.getFetchCSVBlobUrl(userLocale, includeInfo);
12571
- return tokenizedFetch(fetchUrl, {
12572
- credentials: 'include',
12573
- });
12574
- }
12575
- getFetchCSVBlobUrl(userLocale = 'en-us', includeInfo = false) {
12576
- return `${this.thoughtSpotHost}/prism/download/answer/csv?sessionId=${this.session.sessionId}&genNo=${this.session.genNo}&userLocale=${userLocale}&exportFileName=data&hideCsvHeader=${!includeInfo}`;
12577
- }
12578
- /**
12579
- * Get underlying data given a point and the output column names.
12580
- *
12581
- * @param outputColumnNames
12582
- * @param selectedPoints
12583
- * @example
12584
- * ```js
12585
- * embed.on(EmbedEvent.CustomAction, e => {
12586
- * const underlying = await e.answerService.getUnderlyingDataForPoint([
12587
- * 'col name 1' // The column should exist in the data source.
12588
- * ]);
12589
- * const data = await underlying.fetchData(0, 100);
12590
- * })
12591
- * ```
12592
- * @version SDK: 1.25.0| ThoughtSpot: 9.10.0.cl
12593
- */
12594
- async getUnderlyingDataForPoint(outputColumnNames, selectedPoints) {
12595
- if (!selectedPoints && !this.selectedPoints) {
12596
- throw new Error('Needs to be triggered in context of a point');
12597
- }
12598
- if (!selectedPoints) {
12599
- selectedPoints = getSelectedPointsForUnderlyingDataQuery(this.selectedPoints);
12600
- }
12601
- const sourceDetail = await this.getSourceDetail();
12602
- const ouputColumnGuids = getGuidsFromColumnNames(sourceDetail, outputColumnNames);
12603
- const unAggAnswer = await graphqlQuery({
12604
- query: getUnaggregatedAnswerSession,
12605
- variables: {
12606
- session: this.session,
12607
- columns: selectedPoints,
12608
- },
12609
- thoughtSpotHost: this.thoughtSpotHost,
12610
- });
12611
- const unaggAnswerSession = new AnswerService(unAggAnswer.id, unAggAnswer.answer, this.thoughtSpotHost);
12612
- const currentColumns = new Set(unAggAnswer.answer.visualizations[0].columns
12613
- .map((c) => c.column.referencedColumns[0].guid));
12614
- const columnsToAdd = [...ouputColumnGuids].filter((col) => !currentColumns.has(col));
12615
- if (columnsToAdd.length) {
12616
- await unaggAnswerSession.addColumns(columnsToAdd);
12617
- }
12618
- const columnsToRemove = [...currentColumns].filter((col) => !ouputColumnGuids.has(col));
12619
- if (columnsToRemove.length) {
12620
- await unaggAnswerSession.removeColumns(columnsToRemove);
12621
- }
12622
- return unaggAnswerSession;
12623
- }
12624
- async executeQuery(query, variables) {
12625
- const data = await graphqlQuery({
12626
- query,
12627
- variables: {
12628
- session: this.session,
12629
- ...variables,
12630
- },
12631
- thoughtSpotHost: this.thoughtSpotHost,
12632
- isCompositeQuery: false,
12633
- });
12634
- this.session = deepMerge(this.session, (data === null || data === void 0 ? void 0 : data.id) || {});
12635
- return data;
12636
- }
12637
- getSession() {
12638
- return this.session;
12236
+ dom_loaded_handler();
12237
+ }
12238
+
12239
+ if (document$1.addEventListener) {
12240
+ if (document$1.readyState === 'complete') {
12241
+ // safari 4 can fire the DOMContentLoaded event before loading all
12242
+ // external JS (including this file). you will see some copypasta
12243
+ // on the internet that checks for 'complete' and 'loaded', but
12244
+ // 'loaded' is an IE thing
12245
+ dom_loaded_handler();
12246
+ } else {
12247
+ document$1.addEventListener('DOMContentLoaded', dom_loaded_handler, false);
12248
+ }
12249
+ } else if (document$1.attachEvent) {
12250
+ // IE
12251
+ document$1.attachEvent('onreadystatechange', dom_loaded_handler);
12252
+
12253
+ // check to make sure we arn't in a frame
12254
+ var toplevel = false;
12255
+ try {
12256
+ toplevel = window$1.frameElement === null;
12257
+ } catch(e) {
12258
+ // noop
12259
+ }
12260
+
12261
+ if (document$1.documentElement.doScroll && toplevel) {
12262
+ do_scroll_check();
12263
+ }
12264
+ }
12265
+
12266
+ // fallback handler, always will work
12267
+ _.register_event(window$1, 'load', dom_loaded_handler, true);
12268
+ };
12269
+
12270
+ function init_as_module() {
12271
+ init_type = INIT_MODULE;
12272
+ mixpanel_master = new MixpanelLib();
12273
+
12274
+ override_mp_init_func();
12275
+ mixpanel_master['init']();
12276
+ add_dom_loaded_handler();
12277
+
12278
+ return mixpanel_master;
12279
+ }
12280
+
12281
+ var mixpanel = init_as_module();
12282
+
12283
+ var mixpanel_cjs = mixpanel;
12284
+
12285
+ var mixpanel$1 = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.assign(/*#__PURE__*/Object.create(null), mixpanel_cjs, {
12286
+ 'default': mixpanel_cjs
12287
+ }));
12288
+
12289
+ // Needed to avoid error in CJS builds on some bundlers.
12290
+ const mixpanelLib = mixpanel_cjs || mixpanel$1;
12291
+ let mixpanelInstance;
12292
+ const MIXPANEL_EVENT = {
12293
+ VISUAL_SDK_RENDER_START: 'visual-sdk-render-start',
12294
+ VISUAL_SDK_CALLED_INIT: 'visual-sdk-called-init',
12295
+ VISUAL_SDK_RENDER_COMPLETE: 'visual-sdk-render-complete',
12296
+ VISUAL_SDK_RENDER_FAILED: 'visual-sdk-render-failed',
12297
+ VISUAL_SDK_TRIGGER: 'visual-sdk-trigger',
12298
+ VISUAL_SDK_ON: 'visual-sdk-on',
12299
+ VISUAL_SDK_IFRAME_LOAD_PERFORMANCE: 'visual-sdk-iframe-load-performance',
12300
+ VISUAL_SDK_EMBED_CREATE: 'visual-sdk-embed-create',
12301
+ VERCEL_INTEGRATION_COMPLETED: 'vercel-integration-completed',
12302
+ };
12303
+ let isMixpanelInitialized = false;
12304
+ let eventQueue = [];
12305
+ /**
12306
+ * Pushes the event with its Property key-value map to mixpanel.
12307
+ *
12308
+ * @param eventId
12309
+ * @param eventProps
12310
+ */
12311
+ function uploadMixpanelEvent(eventId, eventProps = {}) {
12312
+ if (!isMixpanelInitialized) {
12313
+ eventQueue.push({ eventId, eventProps });
12314
+ return;
12639
12315
  }
12316
+ mixpanelInstance.track(eventId, eventProps);
12640
12317
  }
12641
12318
  /**
12642
12319
  *
12643
- * @param sourceDetail
12644
- * @param colNames
12645
12320
  */
12646
- function getGuidsFromColumnNames(sourceDetail, colNames) {
12647
- const cols = sourceDetail.columns.reduce((colSet, col) => {
12648
- colSet[col.name] = col;
12649
- return colSet;
12650
- }, {});
12651
- return new Set(colNames.map((colName) => {
12652
- const col = cols[colName];
12653
- return col.id;
12654
- }));
12321
+ function emptyQueue() {
12322
+ if (!isMixpanelInitialized) {
12323
+ return;
12324
+ }
12325
+ eventQueue.forEach((event) => {
12326
+ uploadMixpanelEvent(event.eventId, event.eventProps);
12327
+ });
12328
+ eventQueue = [];
12655
12329
  }
12656
12330
  /**
12657
12331
  *
12658
- * @param selectedPoints
12332
+ * @param sessionInfo
12659
12333
  */
12660
- function getSelectedPointsForUnderlyingDataQuery(selectedPoints) {
12661
- const underlyingDataPoint = [];
12662
- /**
12663
- *
12664
- * @param colVal
12665
- */
12666
- function addPointFromColVal(colVal) {
12667
- var _a;
12668
- const dataType = colVal.column.dataType;
12669
- const id = colVal.column.id;
12670
- let dataValue;
12671
- if (dataType === 'DATE') {
12672
- if (Number.isFinite(colVal.value)) {
12673
- dataValue = [{
12674
- epochRange: {
12675
- startEpoch: colVal.value,
12676
- },
12677
- }];
12678
- // Case for custom calendar.
12679
- }
12680
- else if ((_a = colVal.value) === null || _a === void 0 ? void 0 : _a.v) {
12681
- dataValue = [{
12682
- epochRange: {
12683
- startEpoch: colVal.value.v.s,
12684
- endEpoch: colVal.value.v.e,
12685
- },
12686
- }];
12334
+ function initMixpanel(sessionInfo) {
12335
+ var _a;
12336
+ if (!sessionInfo || !sessionInfo.mixpanelToken) {
12337
+ return;
12338
+ }
12339
+ // On a public cluster the user is anonymous, so don't set the identify to
12340
+ // userGUID
12341
+ const isPublicCluster = !!sessionInfo.isPublicUser;
12342
+ const token = sessionInfo.mixpanelToken;
12343
+ try {
12344
+ if (token) {
12345
+ mixpanelInstance = mixpanelLib.init(token, undefined, 'tsEmbed');
12346
+ if (!isPublicCluster) {
12347
+ mixpanelInstance.identify(sessionInfo.userGUID);
12687
12348
  }
12349
+ mixpanelInstance.register_once({
12350
+ clusterId: sessionInfo.clusterId,
12351
+ clusterName: sessionInfo.clusterName,
12352
+ releaseVersion: sessionInfo.releaseVersion,
12353
+ hostAppUrl: ((_a = window === null || window === void 0 ? void 0 : window.location) === null || _a === void 0 ? void 0 : _a.host) || '',
12354
+ });
12355
+ isMixpanelInitialized = true;
12356
+ emptyQueue();
12688
12357
  }
12689
- else {
12690
- dataValue = [{ value: colVal.value }];
12691
- }
12692
- underlyingDataPoint.push({
12693
- columnId: colVal.column.id,
12694
- dataValue,
12695
- });
12696
12358
  }
12697
- selectedPoints.forEach((p) => {
12698
- p.selectedAttributes.forEach(addPointFromColVal);
12699
- });
12700
- return underlyingDataPoint;
12359
+ catch (e) {
12360
+ logger.error('Error initializing mixpanel', e);
12361
+ }
12701
12362
  }
12702
12363
 
12703
12364
  var eventemitter3 = createCommonjsModule(function (module) {
@@ -13154,114 +12815,534 @@ mutation RemoveColumns($session: BachSessionIdInput!, $logicalColumnIds: [GUID!]
13154
12815
  return false;
13155
12816
  }
13156
12817
 
13157
- var _arrayIncludesWith = arrayIncludesWith;
13158
-
13159
- /** Used as references for various `Number` constants. */
13160
- var INFINITY = 1 / 0;
13161
-
13162
- /**
13163
- * Creates a set object of `values`.
13164
- *
13165
- * @private
13166
- * @param {Array} values The values to add to the set.
13167
- * @returns {Object} Returns the new set.
13168
- */
13169
- var createSet = !(_Set && (1 / _setToArray(new _Set([,-0]))[1]) == INFINITY) ? noop_1 : function(values) {
13170
- return new _Set(values);
12818
+ var _arrayIncludesWith = arrayIncludesWith;
12819
+
12820
+ /** Used as references for various `Number` constants. */
12821
+ var INFINITY = 1 / 0;
12822
+
12823
+ /**
12824
+ * Creates a set object of `values`.
12825
+ *
12826
+ * @private
12827
+ * @param {Array} values The values to add to the set.
12828
+ * @returns {Object} Returns the new set.
12829
+ */
12830
+ var createSet = !(_Set && (1 / _setToArray(new _Set([,-0]))[1]) == INFINITY) ? noop_1 : function(values) {
12831
+ return new _Set(values);
12832
+ };
12833
+
12834
+ var _createSet = createSet;
12835
+
12836
+ /** Used as the size to enable large array optimizations. */
12837
+ var LARGE_ARRAY_SIZE$1 = 200;
12838
+
12839
+ /**
12840
+ * The base implementation of `_.uniqBy` without support for iteratee shorthands.
12841
+ *
12842
+ * @private
12843
+ * @param {Array} array The array to inspect.
12844
+ * @param {Function} [iteratee] The iteratee invoked per element.
12845
+ * @param {Function} [comparator] The comparator invoked per element.
12846
+ * @returns {Array} Returns the new duplicate free array.
12847
+ */
12848
+ function baseUniq(array, iteratee, comparator) {
12849
+ var index = -1,
12850
+ includes = _arrayIncludes,
12851
+ length = array.length,
12852
+ isCommon = true,
12853
+ result = [],
12854
+ seen = result;
12855
+
12856
+ if (comparator) {
12857
+ isCommon = false;
12858
+ includes = _arrayIncludesWith;
12859
+ }
12860
+ else if (length >= LARGE_ARRAY_SIZE$1) {
12861
+ var set = iteratee ? null : _createSet(array);
12862
+ if (set) {
12863
+ return _setToArray(set);
12864
+ }
12865
+ isCommon = false;
12866
+ includes = _cacheHas;
12867
+ seen = new _SetCache;
12868
+ }
12869
+ else {
12870
+ seen = iteratee ? [] : result;
12871
+ }
12872
+ outer:
12873
+ while (++index < length) {
12874
+ var value = array[index],
12875
+ computed = iteratee ? iteratee(value) : value;
12876
+
12877
+ value = (comparator || value !== 0) ? value : 0;
12878
+ if (isCommon && computed === computed) {
12879
+ var seenIndex = seen.length;
12880
+ while (seenIndex--) {
12881
+ if (seen[seenIndex] === computed) {
12882
+ continue outer;
12883
+ }
12884
+ }
12885
+ if (iteratee) {
12886
+ seen.push(computed);
12887
+ }
12888
+ result.push(value);
12889
+ }
12890
+ else if (!includes(seen, computed, comparator)) {
12891
+ if (seen !== result) {
12892
+ seen.push(computed);
12893
+ }
12894
+ result.push(value);
12895
+ }
12896
+ }
12897
+ return result;
12898
+ }
12899
+
12900
+ var _baseUniq = baseUniq;
12901
+
12902
+ /**
12903
+ * Creates a duplicate-free version of an array, using
12904
+ * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
12905
+ * for equality comparisons, in which only the first occurrence of each element
12906
+ * is kept. The order of result values is determined by the order they occur
12907
+ * in the array.
12908
+ *
12909
+ * @static
12910
+ * @memberOf _
12911
+ * @since 0.1.0
12912
+ * @category Array
12913
+ * @param {Array} array The array to inspect.
12914
+ * @returns {Array} Returns the new duplicate free array.
12915
+ * @example
12916
+ *
12917
+ * _.uniq([2, 1, 2]);
12918
+ * // => [2, 1]
12919
+ */
12920
+ function uniq(array) {
12921
+ return (array && array.length) ? _baseUniq(array) : [];
12922
+ }
12923
+
12924
+ var uniq_1 = uniq;
12925
+
12926
+ /**
12927
+ *
12928
+ * @param url
12929
+ * @param options
12930
+ */
12931
+ function tokenisedFailureLoggedFetch(url, options = {}) {
12932
+ return tokenizedFetch(url, options).then(async (r) => {
12933
+ var _a;
12934
+ if (!r.ok && r.type !== 'opaqueredirect' && r.type !== 'opaque') {
12935
+ logger.error('Failure', await ((_a = r.text) === null || _a === void 0 ? void 0 : _a.call(r)));
12936
+ }
12937
+ return r;
12938
+ });
12939
+ }
12940
+ /**
12941
+ *
12942
+ * @param authVerificationUrl
12943
+ */
12944
+ function fetchSessionInfoService(authVerificationUrl) {
12945
+ return tokenisedFailureLoggedFetch(authVerificationUrl, {
12946
+ credentials: 'include',
12947
+ });
12948
+ }
12949
+ /**
12950
+ *
12951
+ * @param thoughtSpotHost
12952
+ */
12953
+ async function fetchLogoutService(thoughtSpotHost) {
12954
+ return tokenisedFailureLoggedFetch(`${thoughtSpotHost}${EndPoints.LOGOUT}`, {
12955
+ credentials: 'include',
12956
+ method: 'POST',
12957
+ headers: {
12958
+ 'x-requested-by': 'ThoughtSpot',
12959
+ },
12960
+ });
12961
+ }
12962
+
12963
+ // eslint-disable-next-line import/no-mutable-exports
12964
+ let loggedInStatus = false;
12965
+ // eslint-disable-next-line import/no-mutable-exports
12966
+ let samlAuthWindow = null;
12967
+ // eslint-disable-next-line import/no-mutable-exports
12968
+ let samlCompletionPromise = null;
12969
+ let sessionInfo = null;
12970
+ let sessionInfoResolver = null;
12971
+ const sessionInfoPromise = new Promise((resolve) => {
12972
+ sessionInfoResolver = resolve;
12973
+ });
12974
+ let releaseVersion = '';
12975
+ const SSO_REDIRECTION_MARKER_GUID = '5e16222e-ef02-43e9-9fbd-24226bf3ce5b';
12976
+ (function (AuthFailureType) {
12977
+ AuthFailureType["SDK"] = "SDK";
12978
+ AuthFailureType["NO_COOKIE_ACCESS"] = "NO_COOKIE_ACCESS";
12979
+ AuthFailureType["EXPIRY"] = "EXPIRY";
12980
+ AuthFailureType["OTHER"] = "OTHER";
12981
+ })(exports.AuthFailureType || (exports.AuthFailureType = {}));
12982
+ (function (AuthStatus) {
12983
+ /**
12984
+ * Emits when the SDK fails to authenticate
12985
+ */
12986
+ AuthStatus["FAILURE"] = "FAILURE";
12987
+ /**
12988
+ * Emits when the SDK authenticates successfully
12989
+ */
12990
+ AuthStatus["SDK_SUCCESS"] = "SDK_SUCCESS";
12991
+ /**
12992
+ * Emits when the app sends an authentication success message
12993
+ */
12994
+ AuthStatus["SUCCESS"] = "SUCCESS";
12995
+ /**
12996
+ * Emits when a user logs out
12997
+ */
12998
+ AuthStatus["LOGOUT"] = "LOGOUT";
12999
+ /**
13000
+ * Emitted when inPopup is true in the SAMLRedirect flow and the
13001
+ * popup is waiting to be triggered either programmatically
13002
+ * or by the trigger button.
13003
+ *
13004
+ * @version SDK: 1.19.0
13005
+ */
13006
+ AuthStatus["WAITING_FOR_POPUP"] = "WAITING_FOR_POPUP";
13007
+ })(exports.AuthStatus || (exports.AuthStatus = {}));
13008
+ (function (AuthEvent) {
13009
+ /**
13010
+ * Manually trigger the SSO popup. This is useful when
13011
+ * authStatus is SAMLRedirect/OIDCRedirect and inPopup is set to true
13012
+ */
13013
+ AuthEvent["TRIGGER_SSO_POPUP"] = "TRIGGER_SSO_POPUP";
13014
+ })(exports.AuthEvent || (exports.AuthEvent = {}));
13015
+ let authEE;
13016
+ /**
13017
+ *
13018
+ * @param eventEmitter
13019
+ */
13020
+ function setAuthEE(eventEmitter) {
13021
+ authEE = eventEmitter;
13022
+ }
13023
+ /**
13024
+ *
13025
+ */
13026
+ function notifyAuthSDKSuccess() {
13027
+ if (!authEE) {
13028
+ logger.error('SDK not initialized');
13029
+ return;
13030
+ }
13031
+ authEE.emit(exports.AuthStatus.SDK_SUCCESS);
13032
+ }
13033
+ /**
13034
+ *
13035
+ */
13036
+ function notifyAuthSuccess() {
13037
+ if (!authEE) {
13038
+ logger.error('SDK not initialized');
13039
+ return;
13040
+ }
13041
+ authEE.emit(exports.AuthStatus.SUCCESS, sessionInfo);
13042
+ }
13043
+ /**
13044
+ *
13045
+ * @param failureType
13046
+ */
13047
+ function notifyAuthFailure(failureType) {
13048
+ if (!authEE) {
13049
+ logger.error('SDK not initialized');
13050
+ return;
13051
+ }
13052
+ authEE.emit(exports.AuthStatus.FAILURE, failureType);
13053
+ }
13054
+ /**
13055
+ *
13056
+ */
13057
+ function notifyLogout() {
13058
+ if (!authEE) {
13059
+ logger.error('SDK not initialized');
13060
+ return;
13061
+ }
13062
+ authEE.emit(exports.AuthStatus.LOGOUT);
13063
+ }
13064
+ const initSession = (sessionDetails) => {
13065
+ if (sessionInfo == null) {
13066
+ sessionInfo = sessionDetails;
13067
+ initMixpanel(sessionInfo);
13068
+ sessionInfoResolver(sessionInfo);
13069
+ }
13070
+ };
13071
+ const getSessionDetails = (sessionInfoResp) => {
13072
+ const devMixpanelToken = sessionInfoResp.configInfo.mixpanelConfig.devSdkKey;
13073
+ const prodMixpanelToken = sessionInfoResp.configInfo.mixpanelConfig.prodSdkKey;
13074
+ const mixpanelToken = sessionInfoResp.configInfo.mixpanelConfig.production
13075
+ ? prodMixpanelToken
13076
+ : devMixpanelToken;
13077
+ return {
13078
+ userGUID: sessionInfoResp.userGUID,
13079
+ mixpanelToken,
13080
+ isPublicUser: sessionInfoResp.configInfo.isPublicUser,
13081
+ releaseVersion: sessionInfoResp.releaseVersion,
13082
+ clusterId: sessionInfoResp.configInfo.selfClusterId,
13083
+ clusterName: sessionInfoResp.configInfo.selfClusterName,
13084
+ ...sessionInfoResp,
13085
+ };
13086
+ };
13087
+ /**
13088
+ * Check if we are logged into the ThoughtSpot cluster
13089
+ *
13090
+ * @param thoughtSpotHost The ThoughtSpot cluster hostname or IP
13091
+ */
13092
+ async function isLoggedIn(thoughtSpotHost) {
13093
+ const authVerificationUrl = `${thoughtSpotHost}${EndPoints.AUTH_VERIFICATION}`;
13094
+ let response = null;
13095
+ try {
13096
+ response = await fetchSessionInfoService(authVerificationUrl);
13097
+ const sessionInfoResp = await response.json();
13098
+ const sessionDetails = getSessionDetails(sessionInfoResp);
13099
+ // Store user session details from session info
13100
+ initSession(sessionDetails);
13101
+ releaseVersion = sessionInfoResp.releaseVersion;
13102
+ }
13103
+ catch (e) {
13104
+ return false;
13105
+ }
13106
+ return response.status === 200;
13107
+ }
13108
+ /**
13109
+ * Return releaseVersion if available
13110
+ */
13111
+ function getReleaseVersion() {
13112
+ return releaseVersion;
13113
+ }
13114
+ /**
13115
+ * Return a promise that resolves with the session information when
13116
+ * authentication is successful. And info is available.
13117
+ *
13118
+ * @group Global methods
13119
+ */
13120
+ function getSessionInfo() {
13121
+ return sessionInfoPromise;
13122
+ }
13123
+ /**
13124
+ * Check if we are stuck at the SSO redirect URL
13125
+ */
13126
+ function isAtSSORedirectUrl() {
13127
+ return window.location.href.indexOf(SSO_REDIRECTION_MARKER_GUID) >= 0;
13128
+ }
13129
+ /**
13130
+ * Remove the SSO redirect URL marker
13131
+ */
13132
+ function removeSSORedirectUrlMarker() {
13133
+ // Note (sunny): This will leave a # around even if it was not in the URL
13134
+ // to begin with. Trying to remove the hash by changing window.location will
13135
+ // reload the page which we don't want. We'll live with adding an
13136
+ // unnecessary hash to the parent page URL until we find any use case where
13137
+ // that creates an issue.
13138
+ window.location.hash = window.location.hash.replace(SSO_REDIRECTION_MARKER_GUID, '');
13139
+ }
13140
+ /**
13141
+ * Perform token based authentication
13142
+ *
13143
+ * @param embedConfig The embed configuration
13144
+ */
13145
+ const doTokenAuth = async (embedConfig) => {
13146
+ const { thoughtSpotHost, username, authEndpoint, getAuthToken, } = embedConfig;
13147
+ if (!authEndpoint && !getAuthToken) {
13148
+ throw new Error('Either auth endpoint or getAuthToken function must be provided');
13149
+ }
13150
+ loggedInStatus = await isLoggedIn(thoughtSpotHost);
13151
+ if (!loggedInStatus) {
13152
+ const authToken = await getAuthenticationToken(embedConfig);
13153
+ let resp;
13154
+ try {
13155
+ resp = await fetchAuthPostService(thoughtSpotHost, username, authToken);
13156
+ }
13157
+ catch (e) {
13158
+ resp = await fetchAuthService(thoughtSpotHost, username, authToken);
13159
+ }
13160
+ // token login issues a 302 when successful
13161
+ loggedInStatus = resp.ok || resp.type === 'opaqueredirect';
13162
+ if (loggedInStatus && embedConfig.detectCookieAccessSlow) {
13163
+ // When 3rd party cookie access is blocked, this will fail because
13164
+ // cookies will not be sent with the call.
13165
+ loggedInStatus = await isLoggedIn(thoughtSpotHost);
13166
+ }
13167
+ }
13168
+ return loggedInStatus;
13169
+ };
13170
+ /**
13171
+ * Validate embedConfig parameters required for cookielessTokenAuth
13172
+ *
13173
+ * @param embedConfig The embed configuration
13174
+ */
13175
+ const doCookielessTokenAuth = async (embedConfig) => {
13176
+ const { authEndpoint, getAuthToken } = embedConfig;
13177
+ if (!authEndpoint && !getAuthToken) {
13178
+ throw new Error('Either auth endpoint or getAuthToken function must be provided');
13179
+ }
13180
+ let authSuccess = false;
13181
+ try {
13182
+ const authToken = await getAuthenticationToken(embedConfig);
13183
+ if (authToken) {
13184
+ authSuccess = true;
13185
+ }
13186
+ }
13187
+ catch {
13188
+ authSuccess = false;
13189
+ }
13190
+ return authSuccess;
13191
+ };
13192
+ /**
13193
+ * Perform basic authentication to the ThoughtSpot cluster using the cluster
13194
+ * credentials.
13195
+ *
13196
+ * Warning: This feature is primarily intended for developer testing. It is
13197
+ * strongly advised not to use this authentication method in production.
13198
+ *
13199
+ * @param embedConfig The embed configuration
13200
+ */
13201
+ const doBasicAuth = async (embedConfig) => {
13202
+ const { thoughtSpotHost, username, password } = embedConfig;
13203
+ const loggedIn = await isLoggedIn(thoughtSpotHost);
13204
+ if (!loggedIn) {
13205
+ const response = await fetchBasicAuthService(thoughtSpotHost, username, password);
13206
+ loggedInStatus = response.ok;
13207
+ if (embedConfig.detectCookieAccessSlow) {
13208
+ loggedInStatus = await isLoggedIn(thoughtSpotHost);
13209
+ }
13210
+ }
13211
+ else {
13212
+ loggedInStatus = true;
13213
+ }
13214
+ return loggedInStatus;
13215
+ };
13216
+ /**
13217
+ *
13218
+ * @param ssoURL
13219
+ * @param triggerContainer
13220
+ * @param triggerText
13221
+ */
13222
+ async function samlPopupFlow(ssoURL, triggerContainer, triggerText) {
13223
+ const openPopup = () => {
13224
+ if (samlAuthWindow === null || samlAuthWindow.closed) {
13225
+ samlAuthWindow = window.open(ssoURL, '_blank', 'location=no,height=570,width=520,scrollbars=yes,status=yes');
13226
+ }
13227
+ else {
13228
+ samlAuthWindow.focus();
13229
+ }
13230
+ };
13231
+ authEE === null || authEE === void 0 ? void 0 : authEE.emit(exports.AuthStatus.WAITING_FOR_POPUP);
13232
+ const containerEl = getDOMNode(triggerContainer);
13233
+ if (containerEl) {
13234
+ containerEl.innerHTML = '<button id="ts-auth-btn" class="ts-auth-btn" style="margin: auto;"></button>';
13235
+ const authElem = document.getElementById('ts-auth-btn');
13236
+ authElem.textContent = triggerText;
13237
+ authElem.addEventListener('click', openPopup, { once: true });
13238
+ }
13239
+ samlCompletionPromise = samlCompletionPromise
13240
+ || new Promise((resolve, reject) => {
13241
+ window.addEventListener('message', (e) => {
13242
+ if (e.data.type === exports.EmbedEvent.SAMLComplete) {
13243
+ e.source.close();
13244
+ resolve();
13245
+ }
13246
+ });
13247
+ });
13248
+ authEE === null || authEE === void 0 ? void 0 : authEE.once(exports.AuthEvent.TRIGGER_SSO_POPUP, openPopup);
13249
+ return samlCompletionPromise;
13250
+ }
13251
+ /**
13252
+ * Perform SAML authentication
13253
+ *
13254
+ * @param embedConfig The embed configuration
13255
+ * @param ssoEndPoint
13256
+ */
13257
+ const doSSOAuth = async (embedConfig, ssoEndPoint) => {
13258
+ const { thoughtSpotHost } = embedConfig;
13259
+ const loggedIn = await isLoggedIn(thoughtSpotHost);
13260
+ if (loggedIn) {
13261
+ if (isAtSSORedirectUrl()) {
13262
+ removeSSORedirectUrlMarker();
13263
+ }
13264
+ loggedInStatus = true;
13265
+ return;
13266
+ }
13267
+ // we have already tried authentication and it did not succeed, restore
13268
+ // the current URL to the original one and invoke the callback.
13269
+ if (isAtSSORedirectUrl()) {
13270
+ removeSSORedirectUrlMarker();
13271
+ loggedInStatus = false;
13272
+ return;
13273
+ }
13274
+ const ssoURL = `${thoughtSpotHost}${ssoEndPoint}`;
13275
+ if (embedConfig.inPopup) {
13276
+ await samlPopupFlow(ssoURL, embedConfig.authTriggerContainer, embedConfig.authTriggerText);
13277
+ loggedInStatus = await isLoggedIn(thoughtSpotHost);
13278
+ return;
13279
+ }
13280
+ window.location.href = ssoURL;
13281
+ };
13282
+ const doSamlAuth = async (embedConfig) => {
13283
+ const { thoughtSpotHost } = embedConfig;
13284
+ // redirect for SSO, when the SSO authentication is done, this page will be
13285
+ // loaded again and the same JS will execute again.
13286
+ const ssoRedirectUrl = embedConfig.inPopup
13287
+ ? `${thoughtSpotHost}/v2/#/embed/saml-complete`
13288
+ : getRedirectUrl(window.location.href, SSO_REDIRECTION_MARKER_GUID, embedConfig.redirectPath);
13289
+ // bring back the page to the same URL
13290
+ const ssoEndPoint = `${EndPoints.SAML_LOGIN_TEMPLATE(encodeURIComponent(ssoRedirectUrl))}`;
13291
+ await doSSOAuth(embedConfig, ssoEndPoint);
13292
+ return loggedInStatus;
13293
+ };
13294
+ const doOIDCAuth = async (embedConfig) => {
13295
+ const { thoughtSpotHost } = embedConfig;
13296
+ // redirect for SSO, when the SSO authentication is done, this page will be
13297
+ // loaded again and the same JS will execute again.
13298
+ const ssoRedirectUrl = embedConfig.noRedirect || embedConfig.inPopup
13299
+ ? `${thoughtSpotHost}/v2/#/embed/saml-complete`
13300
+ : getRedirectUrl(window.location.href, SSO_REDIRECTION_MARKER_GUID, embedConfig.redirectPath);
13301
+ // bring back the page to the same URL
13302
+ const ssoEndPoint = `${EndPoints.OIDC_LOGIN_TEMPLATE(encodeURIComponent(ssoRedirectUrl))}`;
13303
+ await doSSOAuth(embedConfig, ssoEndPoint);
13304
+ return loggedInStatus;
13305
+ };
13306
+ const logout = async (embedConfig) => {
13307
+ const { thoughtSpotHost } = embedConfig;
13308
+ await fetchLogoutService(thoughtSpotHost);
13309
+ resetCachedAuthToken();
13310
+ const thoughtspotIframes = document.querySelectorAll('[data-ts-iframe=\'true\']');
13311
+ if (thoughtspotIframes === null || thoughtspotIframes === void 0 ? void 0 : thoughtspotIframes.length) {
13312
+ thoughtspotIframes.forEach((el) => {
13313
+ el.parentElement.innerHTML = embedConfig.loginFailedMessage;
13314
+ });
13315
+ }
13316
+ loggedInStatus = false;
13317
+ return loggedInStatus;
13318
+ };
13319
+ /**
13320
+ * Perform authentication on the ThoughtSpot cluster
13321
+ *
13322
+ * @param embedConfig The embed configuration
13323
+ */
13324
+ const authenticate = async (embedConfig) => {
13325
+ const { authType } = embedConfig;
13326
+ switch (authType) {
13327
+ case exports.AuthType.SSO:
13328
+ case exports.AuthType.SAMLRedirect:
13329
+ case exports.AuthType.SAML:
13330
+ return doSamlAuth(embedConfig);
13331
+ case exports.AuthType.OIDC:
13332
+ case exports.AuthType.OIDCRedirect:
13333
+ return doOIDCAuth(embedConfig);
13334
+ case exports.AuthType.AuthServer:
13335
+ case exports.AuthType.TrustedAuthToken:
13336
+ return doTokenAuth(embedConfig);
13337
+ case exports.AuthType.TrustedAuthTokenCookieless:
13338
+ return doCookielessTokenAuth(embedConfig);
13339
+ case exports.AuthType.Basic:
13340
+ return doBasicAuth(embedConfig);
13341
+ default:
13342
+ return Promise.resolve(true);
13343
+ }
13171
13344
  };
13172
13345
 
13173
- var _createSet = createSet;
13174
-
13175
- /** Used as the size to enable large array optimizations. */
13176
- var LARGE_ARRAY_SIZE$1 = 200;
13177
-
13178
- /**
13179
- * The base implementation of `_.uniqBy` without support for iteratee shorthands.
13180
- *
13181
- * @private
13182
- * @param {Array} array The array to inspect.
13183
- * @param {Function} [iteratee] The iteratee invoked per element.
13184
- * @param {Function} [comparator] The comparator invoked per element.
13185
- * @returns {Array} Returns the new duplicate free array.
13186
- */
13187
- function baseUniq(array, iteratee, comparator) {
13188
- var index = -1,
13189
- includes = _arrayIncludes,
13190
- length = array.length,
13191
- isCommon = true,
13192
- result = [],
13193
- seen = result;
13194
-
13195
- if (comparator) {
13196
- isCommon = false;
13197
- includes = _arrayIncludesWith;
13198
- }
13199
- else if (length >= LARGE_ARRAY_SIZE$1) {
13200
- var set = iteratee ? null : _createSet(array);
13201
- if (set) {
13202
- return _setToArray(set);
13203
- }
13204
- isCommon = false;
13205
- includes = _cacheHas;
13206
- seen = new _SetCache;
13207
- }
13208
- else {
13209
- seen = iteratee ? [] : result;
13210
- }
13211
- outer:
13212
- while (++index < length) {
13213
- var value = array[index],
13214
- computed = iteratee ? iteratee(value) : value;
13215
-
13216
- value = (comparator || value !== 0) ? value : 0;
13217
- if (isCommon && computed === computed) {
13218
- var seenIndex = seen.length;
13219
- while (seenIndex--) {
13220
- if (seen[seenIndex] === computed) {
13221
- continue outer;
13222
- }
13223
- }
13224
- if (iteratee) {
13225
- seen.push(computed);
13226
- }
13227
- result.push(value);
13228
- }
13229
- else if (!includes(seen, computed, comparator)) {
13230
- if (seen !== result) {
13231
- seen.push(computed);
13232
- }
13233
- result.push(value);
13234
- }
13235
- }
13236
- return result;
13237
- }
13238
-
13239
- var _baseUniq = baseUniq;
13240
-
13241
- /**
13242
- * Creates a duplicate-free version of an array, using
13243
- * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
13244
- * for equality comparisons, in which only the first occurrence of each element
13245
- * is kept. The order of result values is determined by the order they occur
13246
- * in the array.
13247
- *
13248
- * @static
13249
- * @memberOf _
13250
- * @since 0.1.0
13251
- * @category Array
13252
- * @param {Array} array The array to inspect.
13253
- * @returns {Array} Returns the new duplicate free array.
13254
- * @example
13255
- *
13256
- * _.uniq([2, 1, 2]);
13257
- * // => [2, 1]
13258
- */
13259
- function uniq(array) {
13260
- return (array && array.length) ? _baseUniq(array) : [];
13261
- }
13262
-
13263
- var uniq_1 = uniq;
13264
-
13265
13346
  /* eslint-disable camelcase */
13266
13347
  const CONFIG_DEFAULTS = {
13267
13348
  loginFailedMessage: 'Not logged in',
@@ -13722,6 +13803,8 @@ mutation RemoveColumns($session: BachSessionIdInput!, $logicalColumnIds: [GUID!]
13722
13803
  });
13723
13804
  }
13724
13805
 
13806
+ var name="@thoughtspot/visual-embed-sdk";var version="1.28.0-alpha.2";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$1={".":{"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 is-publish-allowed && npm run test && 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":"^46.9.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$1,typesVersions:typesVersions,"size-limit":[{path:"dist/tsembed.js",limit:"44 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};
13807
+
13725
13808
  /**
13726
13809
  * Copyright (c) 2022
13727
13810
  *
@@ -15221,7 +15304,7 @@ mutation RemoveColumns($session: BachSessionIdInput!, $logicalColumnIds: [GUID!]
15221
15304
  }
15222
15305
  getEmbedParams() {
15223
15306
  var _a;
15224
- const { hideResults, expandAllDataSource, enableSearchAssist, forceTable, searchOptions, runtimeFilters, dataSource, dataSources, excludeRuntimeFiltersfromURL, hideSearchBar, dataPanelV2 = false, useLastSelectedSources = false, runtimeParameters, } = this.viewConfig;
15307
+ const { hideResults, enableSearchAssist, forceTable, searchOptions, runtimeFilters, dataSource, dataSources, excludeRuntimeFiltersfromURL, hideSearchBar, dataPanelV2 = false, useLastSelectedSources = false, runtimeParameters, } = this.viewConfig;
15225
15308
  const queryParams = this.getBaseQueryParams();
15226
15309
  queryParams[Param.HideActions] = [
15227
15310
  ...((_a = queryParams[Param.HideActions]) !== null && _a !== void 0 ? _a : []),
@@ -15371,16 +15454,6 @@ mutation RemoveColumns($session: BachSessionIdInput!, $logicalColumnIds: [GUID!]
15371
15454
  * @summary TS Sage embed
15372
15455
  * @author Mourya Balabhadra <mourya.balabhadra@thoughtspot.com>
15373
15456
  */
15374
- const HiddenActionItemByDefaultForSageEmbed = [
15375
- exports.Action.Save,
15376
- exports.Action.Pin,
15377
- exports.Action.EditACopy,
15378
- exports.Action.SaveAsView,
15379
- exports.Action.UpdateTML,
15380
- exports.Action.EditTML,
15381
- exports.Action.AnswerDelete,
15382
- exports.Action.Share,
15383
- ];
15384
15457
  /**
15385
15458
  * Embed ThoughtSpot LLM and GPT-based Natural Language Search component.
15386
15459
  *
@@ -15400,7 +15473,6 @@ mutation RemoveColumns($session: BachSessionIdInput!, $logicalColumnIds: [GUID!]
15400
15473
  * @returns {string} query string
15401
15474
  */
15402
15475
  getEmbedParams() {
15403
- var _a;
15404
15476
  const { disableWorksheetChange, hideWorksheetSelector, showObjectSuggestions, hideSampleQuestions, isProductTour, hideSearchBarTitle, hideSageAnswerHeader, hideAutocompleteSuggestions, } = this.viewConfig;
15405
15477
  const params = this.getBaseQueryParams();
15406
15478
  params[Param.EmbedApp] = true;
@@ -15416,10 +15488,6 @@ mutation RemoveColumns($session: BachSessionIdInput!, $logicalColumnIds: [GUID!]
15416
15488
  params[Param.IsProductTour] = !!isProductTour;
15417
15489
  params[Param.HideSearchBarTitle] = !!hideSearchBarTitle;
15418
15490
  params[Param.HideSageAnswerHeader] = !!hideSageAnswerHeader;
15419
- params[Param.HideActions] = [
15420
- ...((_a = params[Param.HideActions]) !== null && _a !== void 0 ? _a : []),
15421
- ...HiddenActionItemByDefaultForSageEmbed,
15422
- ];
15423
15491
  return getQueryParamString(params, true);
15424
15492
  }
15425
15493
  /**
@@ -15463,6 +15531,7 @@ mutation RemoveColumns($session: BachSessionIdInput!, $logicalColumnIds: [GUID!]
15463
15531
  exports.AnswerService = AnswerService;
15464
15532
  exports.AppEmbed = AppEmbed;
15465
15533
  exports.LiveboardEmbed = LiveboardEmbed;
15534
+ exports.MIXPANEL_EVENT = MIXPANEL_EVENT;
15466
15535
  exports.PinboardEmbed = PinboardEmbed;
15467
15536
  exports.SageEmbed = SageEmbed;
15468
15537
  exports.SearchBarEmbed = SearchBarEmbed;
@@ -15474,6 +15543,7 @@ mutation RemoveColumns($session: BachSessionIdInput!, $logicalColumnIds: [GUID!]
15474
15543
  exports.init = init;
15475
15544
  exports.logout = logout$1;
15476
15545
  exports.prefetch = prefetch;
15546
+ exports.uploadMixpanelEvent = uploadMixpanelEvent;
15477
15547
 
15478
15548
  Object.defineProperty(exports, '__esModule', { value: true });
15479
15549