@thoughtspot/visual-embed-sdk 1.28.1 → 1.29.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.
- package/README.md +1 -1
- package/cjs/package.json +1 -1
- package/cjs/src/auth.d.ts.map +1 -1
- package/cjs/src/auth.js +2 -2
- package/cjs/src/auth.js.map +1 -1
- package/cjs/src/authToken.d.ts +10 -0
- package/cjs/src/authToken.d.ts.map +1 -1
- package/cjs/src/authToken.js +10 -0
- package/cjs/src/authToken.js.map +1 -1
- package/cjs/src/embed/app.d.ts +19 -6
- package/cjs/src/embed/app.d.ts.map +1 -1
- package/cjs/src/embed/app.js +4 -3
- package/cjs/src/embed/app.js.map +1 -1
- package/cjs/src/embed/base.d.ts +1 -1
- package/cjs/src/embed/base.d.ts.map +1 -1
- package/cjs/src/embed/base.js +7 -5
- package/cjs/src/embed/base.js.map +1 -1
- package/cjs/src/embed/base.spec.js +1 -1
- package/cjs/src/embed/base.spec.js.map +1 -1
- package/cjs/src/embed/liveboard.d.ts +8 -2
- package/cjs/src/embed/liveboard.d.ts.map +1 -1
- package/cjs/src/embed/liveboard.js.map +1 -1
- package/cjs/src/embed/search.d.ts +18 -5
- package/cjs/src/embed/search.d.ts.map +1 -1
- package/cjs/src/embed/search.js +5 -4
- package/cjs/src/embed/search.js.map +1 -1
- package/cjs/src/embed/search.spec.js +2 -1
- package/cjs/src/embed/search.spec.js.map +1 -1
- package/cjs/src/embed/ts-embed.d.ts +1 -1
- package/cjs/src/embed/ts-embed.d.ts.map +1 -1
- package/cjs/src/embed/ts-embed.js +6 -6
- package/cjs/src/embed/ts-embed.js.map +1 -1
- package/cjs/src/embed/ts-embed.spec.js +9 -18
- package/cjs/src/embed/ts-embed.spec.js.map +1 -1
- package/cjs/src/index.d.ts +1 -0
- package/cjs/src/index.d.ts.map +1 -1
- package/cjs/src/index.js +3 -1
- package/cjs/src/index.js.map +1 -1
- package/cjs/src/react/all-types-export.d.ts +1 -1
- package/cjs/src/react/all-types-export.d.ts.map +1 -1
- package/cjs/src/react/all-types-export.js +2 -1
- package/cjs/src/react/all-types-export.js.map +1 -1
- package/cjs/src/react/index.spec.js +1 -13
- package/cjs/src/react/index.spec.js.map +1 -1
- package/cjs/src/types.d.ts +99 -15
- package/cjs/src/types.d.ts.map +1 -1
- package/cjs/src/types.js +88 -3
- package/cjs/src/types.js.map +1 -1
- package/dist/src/auth.d.ts.map +1 -1
- package/dist/src/authToken.d.ts +10 -0
- package/dist/src/authToken.d.ts.map +1 -1
- package/dist/src/embed/app.d.ts +19 -6
- package/dist/src/embed/app.d.ts.map +1 -1
- package/dist/src/embed/base.d.ts +1 -1
- package/dist/src/embed/base.d.ts.map +1 -1
- package/dist/src/embed/liveboard.d.ts +8 -2
- package/dist/src/embed/liveboard.d.ts.map +1 -1
- package/dist/src/embed/search.d.ts +18 -5
- package/dist/src/embed/search.d.ts.map +1 -1
- package/dist/src/embed/ts-embed.d.ts +1 -1
- package/dist/src/embed/ts-embed.d.ts.map +1 -1
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/react/all-types-export.d.ts +1 -1
- package/dist/src/react/all-types-export.d.ts.map +1 -1
- package/dist/src/types.d.ts +99 -15
- package/dist/src/types.d.ts.map +1 -1
- package/dist/tsembed-react.es.js +7004 -6907
- package/dist/tsembed-react.js +1735 -1638
- package/dist/tsembed.es.js +7352 -7254
- package/dist/tsembed.js +15445 -15346
- package/dist/visual-embed-sdk-react-full.d.ts +155 -26
- package/dist/visual-embed-sdk-react.d.ts +155 -26
- package/dist/visual-embed-sdk.d.ts +155 -26
- package/lib/package.json +1 -1
- package/lib/src/auth.d.ts.map +1 -1
- package/lib/src/auth.js +3 -3
- package/lib/src/auth.js.map +1 -1
- package/lib/src/authToken.d.ts +10 -0
- package/lib/src/authToken.d.ts.map +1 -1
- package/lib/src/authToken.js +10 -0
- package/lib/src/authToken.js.map +1 -1
- package/lib/src/embed/app.d.ts +19 -6
- package/lib/src/embed/app.d.ts.map +1 -1
- package/lib/src/embed/app.js +4 -3
- package/lib/src/embed/app.js.map +1 -1
- package/lib/src/embed/base.d.ts +1 -1
- package/lib/src/embed/base.d.ts.map +1 -1
- package/lib/src/embed/base.js +7 -5
- package/lib/src/embed/base.js.map +1 -1
- package/lib/src/embed/base.spec.js +2 -2
- package/lib/src/embed/base.spec.js.map +1 -1
- package/lib/src/embed/liveboard.d.ts +8 -2
- package/lib/src/embed/liveboard.d.ts.map +1 -1
- package/lib/src/embed/liveboard.js +1 -1
- package/lib/src/embed/liveboard.js.map +1 -1
- package/lib/src/embed/search.d.ts +18 -5
- package/lib/src/embed/search.d.ts.map +1 -1
- package/lib/src/embed/search.js +6 -5
- package/lib/src/embed/search.js.map +1 -1
- package/lib/src/embed/search.spec.js +2 -1
- package/lib/src/embed/search.spec.js.map +1 -1
- package/lib/src/embed/ts-embed.d.ts +1 -1
- package/lib/src/embed/ts-embed.d.ts.map +1 -1
- package/lib/src/embed/ts-embed.js +9 -9
- package/lib/src/embed/ts-embed.js.map +1 -1
- package/lib/src/embed/ts-embed.spec.js +9 -18
- package/lib/src/embed/ts-embed.spec.js.map +1 -1
- package/lib/src/index.d.ts +1 -0
- package/lib/src/index.d.ts.map +1 -1
- package/lib/src/index.js +1 -0
- package/lib/src/index.js.map +1 -1
- package/lib/src/react/all-types-export.d.ts +1 -1
- package/lib/src/react/all-types-export.d.ts.map +1 -1
- package/lib/src/react/all-types-export.js +1 -1
- package/lib/src/react/all-types-export.js.map +1 -1
- package/lib/src/react/index.spec.js +1 -13
- package/lib/src/react/index.spec.js.map +1 -1
- package/lib/src/types.d.ts +99 -15
- package/lib/src/types.d.ts.map +1 -1
- package/lib/src/types.js +88 -3
- package/lib/src/types.js.map +1 -1
- package/lib/src/utils/authService/authService.spec.js +1 -1
- package/lib/src/utils/authService/authService.spec.js.map +1 -1
- package/lib/src/visual-embed-sdk.d.ts +163 -30
- package/package.json +1 -1
- package/src/auth.ts +6 -6
- package/src/authToken.ts +10 -0
- package/src/embed/app.ts +28 -8
- package/src/embed/base.spec.ts +3 -3
- package/src/embed/base.ts +14 -12
- package/src/embed/liveboard.ts +16 -3
- package/src/embed/search.spec.ts +2 -1
- package/src/embed/search.ts +28 -10
- package/src/embed/ts-embed.spec.ts +26 -34
- package/src/embed/ts-embed.ts +43 -39
- package/src/index.ts +2 -0
- package/src/react/all-types-export.ts +1 -0
- package/src/react/index.spec.tsx +1 -30
- package/src/types.ts +100 -15
- package/src/utils/authService/authService.spec.ts +4 -4
package/dist/tsembed-react.js
CHANGED
|
@@ -572,7 +572,6 @@
|
|
|
572
572
|
* .then((data) => data.token);
|
|
573
573
|
* }
|
|
574
574
|
* });
|
|
575
|
-
* });
|
|
576
575
|
* ```
|
|
577
576
|
*/
|
|
578
577
|
AuthType["TrustedAuthToken"] = "AuthServer";
|
|
@@ -901,8 +900,7 @@
|
|
|
901
900
|
*
|
|
902
901
|
* API - API call failure error.
|
|
903
902
|
*
|
|
904
|
-
* FULLSCREEN - Error when presenting a Liveboard or visualization in full screen
|
|
905
|
-
* mode.
|
|
903
|
+
* FULLSCREEN - Error when presenting a Liveboard or visualization in full screen mode.
|
|
906
904
|
*
|
|
907
905
|
* SINGLE_VALUE_FILTER - Error due to multiple values in the single value filter.
|
|
908
906
|
*
|
|
@@ -2527,6 +2525,7 @@
|
|
|
2527
2525
|
Param["ClientLogLevel"] = "clientLogLevel";
|
|
2528
2526
|
Param["OverrideNativeConsole"] = "overrideConsoleLogs";
|
|
2529
2527
|
Param["enableAskSage"] = "enableAskSage";
|
|
2528
|
+
Param["CollapseSearchBarInitially"] = "collapseSearchBarInitially";
|
|
2530
2529
|
})(Param || (Param = {}));
|
|
2531
2530
|
(function (Action) {
|
|
2532
2531
|
/**
|
|
@@ -2635,6 +2634,18 @@
|
|
|
2635
2634
|
* ```
|
|
2636
2635
|
*/
|
|
2637
2636
|
Action["AddFilter"] = "addFilter";
|
|
2637
|
+
/**
|
|
2638
|
+
* The **Add Data Panel Objects** action on the data panel v2.
|
|
2639
|
+
* Allows to show action menu to add different objects (like
|
|
2640
|
+
* formulas, parameters) in data panel v2.
|
|
2641
|
+
*
|
|
2642
|
+
* @example
|
|
2643
|
+
* ```js
|
|
2644
|
+
* disabledActions: [Action.AddDataPanelObjects]
|
|
2645
|
+
* ```
|
|
2646
|
+
* @version SDK: 1.32.0 | Thoughtspot: 10.0.0.cl
|
|
2647
|
+
*/
|
|
2648
|
+
Action["AddDataPanelObjects"] = "addDataPanelObjects";
|
|
2638
2649
|
/**
|
|
2639
2650
|
* Filter configuration options on a Liveboard and Search page.
|
|
2640
2651
|
* Allows configuring filter options when adding filters to a
|
|
@@ -2677,6 +2688,28 @@
|
|
|
2677
2688
|
* ```
|
|
2678
2689
|
*/
|
|
2679
2690
|
Action["AddParameter"] = "addParameter";
|
|
2691
|
+
/**
|
|
2692
|
+
* The **Add Column Set** action on a Answer.
|
|
2693
|
+
* Allows adding column sets to a Answer.
|
|
2694
|
+
*
|
|
2695
|
+
* @example
|
|
2696
|
+
* ```js
|
|
2697
|
+
* disabledActions: [Action.AddColumnSet]
|
|
2698
|
+
* ```
|
|
2699
|
+
* @version SDK: 1.32.0 | Thoughtspot: 10.0.0.cl
|
|
2700
|
+
*/
|
|
2701
|
+
Action["AddColumnSet"] = "addSimpleCohort";
|
|
2702
|
+
/**
|
|
2703
|
+
* The **Add Query Set** action on a Answer.
|
|
2704
|
+
* Allows adding query sets to a Answer.
|
|
2705
|
+
*
|
|
2706
|
+
* @example
|
|
2707
|
+
* ```js
|
|
2708
|
+
* disabledActions: [Action.AddQuerySet]
|
|
2709
|
+
* ```
|
|
2710
|
+
* @version SDK: 1.32.0 | Thoughtspot: 10.0.0.cl
|
|
2711
|
+
*/
|
|
2712
|
+
Action["AddQuerySet"] = "addAdvancedCohort";
|
|
2680
2713
|
/**
|
|
2681
2714
|
* @hidden
|
|
2682
2715
|
*/
|
|
@@ -3108,6 +3141,28 @@
|
|
|
3108
3141
|
* @version SDK: 1.21.0 | ThoughtSpot: 9.2.0.cl
|
|
3109
3142
|
*/
|
|
3110
3143
|
Action["CrossFilter"] = "context-menu-item-cross-filter";
|
|
3144
|
+
/**
|
|
3145
|
+
* The **Sync to Slack** action on Liveboard visualizations.
|
|
3146
|
+
* Allows sending data to third-party apps Slack
|
|
3147
|
+
*
|
|
3148
|
+
* @example
|
|
3149
|
+
* ```js
|
|
3150
|
+
* disabledActions: [Action.SyncToSlack]
|
|
3151
|
+
* ```
|
|
3152
|
+
* @version @version SDK : 1.32.0 | Thoughtspot: 10.1.0.cl
|
|
3153
|
+
*/
|
|
3154
|
+
Action["SyncToSlack"] = "syncToSlack";
|
|
3155
|
+
/**
|
|
3156
|
+
* The **Sync to Teams** action on Liveboard visualizations.
|
|
3157
|
+
* Allows sending data to third-party apps Team
|
|
3158
|
+
*
|
|
3159
|
+
* @example
|
|
3160
|
+
* ```js
|
|
3161
|
+
* disabledActions: [Action.SyncToTeams]
|
|
3162
|
+
* ```
|
|
3163
|
+
* @version @version SDK : 1.32.0 | Thoughtspot: 10.1.0.cl
|
|
3164
|
+
*/
|
|
3165
|
+
Action["SyncToTeams"] = "syncToTeams";
|
|
3111
3166
|
/**
|
|
3112
3167
|
* The **Remove** action that appears when cross filters are applied
|
|
3113
3168
|
* on a Liveboard.
|
|
@@ -3349,6 +3404,26 @@
|
|
|
3349
3404
|
* @version SDK : 1.26.0 | Thoughtspot: 9.7.0.cl
|
|
3350
3405
|
*/
|
|
3351
3406
|
Action["LiveboardUsers"] = "liveboardUsers";
|
|
3407
|
+
/**
|
|
3408
|
+
* Action ID for the Parent TML action
|
|
3409
|
+
* The parent action **TML** must be included to access TML-related options
|
|
3410
|
+
* within the cascading menu (specific to the answer page)
|
|
3411
|
+
*
|
|
3412
|
+
* @example
|
|
3413
|
+
* ```js
|
|
3414
|
+
* // to include specific TML actions
|
|
3415
|
+
* visibleActions: [Action.TML, Action.ExportTML, Action.EditTML]
|
|
3416
|
+
*
|
|
3417
|
+
* ```
|
|
3418
|
+
* @example
|
|
3419
|
+
* ```js
|
|
3420
|
+
* hiddenAction: [Action.TML] // hide all TML actions
|
|
3421
|
+
* disabledActions: [Action.TML] // to disable all TML actions
|
|
3422
|
+
* ```
|
|
3423
|
+
*
|
|
3424
|
+
* @version SDK : 1.28.2 | Thoughtspot: 9.10.5.cl
|
|
3425
|
+
*/
|
|
3426
|
+
Action["TML"] = "tml";
|
|
3352
3427
|
/**
|
|
3353
3428
|
* Action ID for to hide Verified Liveboard Banner
|
|
3354
3429
|
*
|
|
@@ -3399,6 +3474,16 @@
|
|
|
3399
3474
|
* @version SDK : 1.27.9 | Thoughtspot: 9.12.5.cl
|
|
3400
3475
|
*/
|
|
3401
3476
|
Action["CopyKpiLink"] = "copyKpiLink";
|
|
3477
|
+
/**
|
|
3478
|
+
* The **Organise Favourites** action on Homepage Favourite Module.
|
|
3479
|
+
*
|
|
3480
|
+
* @example
|
|
3481
|
+
* ```js
|
|
3482
|
+
* disabledActions: [Action.OrganiseFavourites]
|
|
3483
|
+
* ```
|
|
3484
|
+
* @version SDK : 1.32.0 | Thoughtspot: 10.0.0.cl
|
|
3485
|
+
*/
|
|
3486
|
+
Action["OrganiseFavourites"] = "organiseFavourites";
|
|
3402
3487
|
/**
|
|
3403
3488
|
* Action ID for AI Highlights button
|
|
3404
3489
|
*
|
|
@@ -5711,8 +5796,6 @@
|
|
|
5711
5796
|
|
|
5712
5797
|
var isEqual_1 = isEqual;
|
|
5713
5798
|
|
|
5714
|
-
var name="@thoughtspot/visual-embed-sdk";var version="1.28.1";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:"45 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};
|
|
5715
|
-
|
|
5716
5799
|
/**
|
|
5717
5800
|
* Checks if `value` is `undefined`.
|
|
5718
5801
|
*
|
|
@@ -5985,335 +6068,886 @@
|
|
|
5985
6068
|
throw new Error(INVALID_TOKEN_ERR);
|
|
5986
6069
|
}
|
|
5987
6070
|
};
|
|
6071
|
+
/**
|
|
6072
|
+
* Resets the auth token and a new token will be fetched on the next request.
|
|
6073
|
+
*
|
|
6074
|
+
* @example
|
|
6075
|
+
* ```js
|
|
6076
|
+
* resetCachedAuthToken();
|
|
6077
|
+
* ```
|
|
6078
|
+
* @version SDK: 1.28.0 | ThoughtSpot: *
|
|
6079
|
+
* @group Authentication / Init
|
|
6080
|
+
*/
|
|
5988
6081
|
const resetCachedAuthToken = () => {
|
|
5989
6082
|
cachedAuthToken = null;
|
|
5990
6083
|
};
|
|
5991
6084
|
|
|
5992
|
-
|
|
5993
|
-
|
|
5994
|
-
|
|
6085
|
+
let config = {};
|
|
6086
|
+
/**
|
|
6087
|
+
* Gets the configuration embed was initialized with.
|
|
6088
|
+
*
|
|
6089
|
+
* @returns {@link EmbedConfig} The configuration embed was initialized with.
|
|
6090
|
+
* @version SDK: 1.19.0 | ThoughtSpot: *
|
|
6091
|
+
* @group Global methods
|
|
6092
|
+
*/
|
|
6093
|
+
const getEmbedConfig = () => config;
|
|
6094
|
+
|
|
6095
|
+
/**
|
|
6096
|
+
* Fetch wrapper that adds the authentication token to the request.
|
|
6097
|
+
* Use this to call the ThoughtSpot APIs when using the visual embed sdk.
|
|
6098
|
+
*
|
|
6099
|
+
* @param input
|
|
6100
|
+
* @param init
|
|
6101
|
+
* @version SDK: 1.28.0
|
|
6102
|
+
* @group Global methods
|
|
6103
|
+
*/
|
|
6104
|
+
const tokenizedFetch = async (input, init) => {
|
|
6105
|
+
const embedConfig = getEmbedConfig();
|
|
6106
|
+
if (embedConfig.authType !== AuthType.TrustedAuthTokenCookieless) {
|
|
6107
|
+
return fetch(input, init);
|
|
6108
|
+
}
|
|
6109
|
+
const req = new Request(input, init);
|
|
6110
|
+
const authToken = await getAuthenticationToken(embedConfig);
|
|
6111
|
+
if (authToken) {
|
|
6112
|
+
req.headers.append('Authorization', `Bearer ${authToken}`);
|
|
6113
|
+
}
|
|
6114
|
+
return fetch(req);
|
|
5995
6115
|
};
|
|
5996
6116
|
|
|
5997
|
-
|
|
5998
|
-
|
|
5999
|
-
|
|
6000
|
-
|
|
6001
|
-
|
|
6002
|
-
|
|
6003
|
-
|
|
6004
|
-
|
|
6005
|
-
|
|
6006
|
-
|
|
6007
|
-
|
|
6008
|
-
}
|
|
6009
|
-
|
|
6010
|
-
|
|
6011
|
-
|
|
6012
|
-
|
|
6013
|
-
|
|
6117
|
+
/**
|
|
6118
|
+
*
|
|
6119
|
+
* @param root0
|
|
6120
|
+
* @param root0.query
|
|
6121
|
+
* @param root0.variables
|
|
6122
|
+
* @param root0.thoughtSpotHost
|
|
6123
|
+
* @param root0.isCompositeQuery
|
|
6124
|
+
*/
|
|
6125
|
+
async function graphqlQuery({ query, variables, thoughtSpotHost, isCompositeQuery = false, }) {
|
|
6126
|
+
const operationName = getOperationNameFromQuery(query);
|
|
6127
|
+
try {
|
|
6128
|
+
const response = await fetch(`${thoughtSpotHost}/prism/?op=${operationName}`, {
|
|
6129
|
+
method: 'POST',
|
|
6130
|
+
headers: {
|
|
6131
|
+
'content-type': 'application/json;charset=UTF-8',
|
|
6132
|
+
'x-requested-by': 'ThoughtSpot',
|
|
6133
|
+
accept: '*/*',
|
|
6134
|
+
'accept-language': 'en-us',
|
|
6135
|
+
},
|
|
6136
|
+
body: JSON.stringify({
|
|
6137
|
+
operationName,
|
|
6138
|
+
query,
|
|
6139
|
+
variables,
|
|
6140
|
+
}),
|
|
6141
|
+
credentials: 'include',
|
|
6142
|
+
});
|
|
6143
|
+
const result = await response.json();
|
|
6144
|
+
const dataValues = Object.values(result.data);
|
|
6145
|
+
return (isCompositeQuery) ? result.data : dataValues[0];
|
|
6146
|
+
}
|
|
6147
|
+
catch (error) {
|
|
6148
|
+
return error;
|
|
6149
|
+
}
|
|
6014
6150
|
}
|
|
6015
6151
|
|
|
6016
|
-
|
|
6017
|
-
|
|
6018
|
-
|
|
6019
|
-
|
|
6020
|
-
|
|
6021
|
-
|
|
6022
|
-
|
|
6023
|
-
|
|
6024
|
-
|
|
6025
|
-
|
|
6026
|
-
|
|
6027
|
-
|
|
6028
|
-
|
|
6029
|
-
|
|
6030
|
-
|
|
6031
|
-
|
|
6032
|
-
|
|
6033
|
-
|
|
6034
|
-
|
|
6035
|
-
|
|
6036
|
-
|
|
6037
|
-
|
|
6038
|
-
|
|
6039
|
-
|
|
6040
|
-
|
|
6041
|
-
|
|
6042
|
-
|
|
6043
|
-
|
|
6044
|
-
|
|
6152
|
+
const getSourceDetailQuery = `
|
|
6153
|
+
query GetSourceDetail($ids: [GUID!]!) {
|
|
6154
|
+
getSourceDetailById(ids: $ids, type: LOGICAL_TABLE) {
|
|
6155
|
+
id
|
|
6156
|
+
name
|
|
6157
|
+
description
|
|
6158
|
+
authorName
|
|
6159
|
+
authorDisplayName
|
|
6160
|
+
isExternal
|
|
6161
|
+
type
|
|
6162
|
+
created
|
|
6163
|
+
modified
|
|
6164
|
+
columns {
|
|
6165
|
+
id
|
|
6166
|
+
name
|
|
6167
|
+
author
|
|
6168
|
+
authorDisplayName
|
|
6169
|
+
description
|
|
6170
|
+
dataType
|
|
6171
|
+
type
|
|
6172
|
+
modified
|
|
6173
|
+
ownerName
|
|
6174
|
+
owner
|
|
6175
|
+
dataRecency
|
|
6176
|
+
sources {
|
|
6177
|
+
tableId
|
|
6178
|
+
tableName
|
|
6179
|
+
columnId
|
|
6180
|
+
columnName
|
|
6181
|
+
__typename
|
|
6182
|
+
}
|
|
6183
|
+
synonyms
|
|
6184
|
+
cohortAnswerId
|
|
6185
|
+
__typename
|
|
6186
|
+
}
|
|
6187
|
+
relationships
|
|
6188
|
+
destinationRelationships
|
|
6189
|
+
dataSourceId
|
|
6190
|
+
__typename
|
|
6191
|
+
}
|
|
6192
|
+
}
|
|
6193
|
+
`;
|
|
6194
|
+
const sourceDetailCache = new Map();
|
|
6195
|
+
/**
|
|
6196
|
+
*
|
|
6197
|
+
* @param thoughtSpotHost
|
|
6198
|
+
* @param sourceId
|
|
6199
|
+
*/
|
|
6200
|
+
async function getSourceDetail(thoughtSpotHost, sourceId) {
|
|
6201
|
+
if (sourceDetailCache.get(sourceId)) {
|
|
6202
|
+
return sourceDetailCache.get(sourceId);
|
|
6203
|
+
}
|
|
6204
|
+
const details = await graphqlQuery({
|
|
6205
|
+
query: getSourceDetailQuery,
|
|
6206
|
+
variables: {
|
|
6207
|
+
ids: [sourceId],
|
|
6208
|
+
},
|
|
6209
|
+
thoughtSpotHost,
|
|
6210
|
+
});
|
|
6211
|
+
const souceDetails = details[0];
|
|
6212
|
+
if (souceDetails) {
|
|
6213
|
+
sourceDetailCache.set(sourceId, souceDetails);
|
|
6214
|
+
}
|
|
6215
|
+
return souceDetails;
|
|
6216
|
+
}
|
|
6045
6217
|
|
|
6046
|
-
|
|
6047
|
-
|
|
6048
|
-
|
|
6049
|
-
|
|
6050
|
-
|
|
6051
|
-
|
|
6052
|
-
|
|
6053
|
-
|
|
6054
|
-
|
|
6055
|
-
|
|
6056
|
-
|
|
6057
|
-
|
|
6058
|
-
|
|
6059
|
-
|
|
6060
|
-
|
|
6061
|
-
|
|
6062
|
-
|
|
6063
|
-
|
|
6064
|
-
|
|
6065
|
-
|
|
6066
|
-
|
|
6067
|
-
|
|
6068
|
-
|
|
6069
|
-
|
|
6070
|
-
|
|
6071
|
-
|
|
6072
|
-
|
|
6073
|
-
|
|
6074
|
-
|
|
6075
|
-
|
|
6076
|
-
|
|
6077
|
-
|
|
6078
|
-
|
|
6079
|
-
|
|
6080
|
-
|
|
6081
|
-
|
|
6082
|
-
|
|
6083
|
-
|
|
6084
|
-
|
|
6085
|
-
|
|
6086
|
-
|
|
6087
|
-
|
|
6088
|
-
|
|
6089
|
-
|
|
6090
|
-
|
|
6091
|
-
|
|
6092
|
-
|
|
6093
|
-
|
|
6094
|
-
|
|
6095
|
-
|
|
6096
|
-
|
|
6097
|
-
|
|
6098
|
-
|
|
6099
|
-
|
|
6100
|
-
|
|
6101
|
-
|
|
6102
|
-
|
|
6103
|
-
|
|
6104
|
-
|
|
6105
|
-
|
|
6106
|
-
|
|
6107
|
-
|
|
6108
|
-
|
|
6109
|
-
|
|
6110
|
-
|
|
6111
|
-
|
|
6112
|
-
|
|
6113
|
-
|
|
6114
|
-
|
|
6115
|
-
|
|
6116
|
-
|
|
6117
|
-
|
|
6118
|
-
|
|
6119
|
-
|
|
6120
|
-
|
|
6121
|
-
|
|
6122
|
-
}
|
|
6123
|
-
if (!_.isFunction(func)) {
|
|
6124
|
-
throw new TypeError();
|
|
6125
|
-
}
|
|
6126
|
-
args = slice.call(arguments, 2);
|
|
6127
|
-
bound = function() {
|
|
6128
|
-
if (!(this instanceof bound)) {
|
|
6129
|
-
return func.apply(context, args.concat(slice.call(arguments)));
|
|
6130
|
-
}
|
|
6131
|
-
var ctor = {};
|
|
6132
|
-
ctor.prototype = func.prototype;
|
|
6133
|
-
var self = new ctor();
|
|
6134
|
-
ctor.prototype = null;
|
|
6135
|
-
var result = func.apply(self, args.concat(slice.call(arguments)));
|
|
6136
|
-
if (Object(result) === result) {
|
|
6137
|
-
return result;
|
|
6138
|
-
}
|
|
6139
|
-
return self;
|
|
6140
|
-
};
|
|
6141
|
-
return bound;
|
|
6142
|
-
};
|
|
6143
|
-
|
|
6144
|
-
/**
|
|
6145
|
-
* @param {*=} obj
|
|
6146
|
-
* @param {function(...*)=} iterator
|
|
6147
|
-
* @param {Object=} context
|
|
6148
|
-
*/
|
|
6149
|
-
_.each = function(obj, iterator, context) {
|
|
6150
|
-
if (obj === null || obj === undefined) {
|
|
6151
|
-
return;
|
|
6152
|
-
}
|
|
6153
|
-
if (nativeForEach && obj.forEach === nativeForEach) {
|
|
6154
|
-
obj.forEach(iterator, context);
|
|
6155
|
-
} else if (obj.length === +obj.length) {
|
|
6156
|
-
for (var i = 0, l = obj.length; i < l; i++) {
|
|
6157
|
-
if (i in obj && iterator.call(context, obj[i], i, obj) === breaker) {
|
|
6158
|
-
return;
|
|
6159
|
-
}
|
|
6160
|
-
}
|
|
6161
|
-
} else {
|
|
6162
|
-
for (var key in obj) {
|
|
6163
|
-
if (hasOwnProperty$9.call(obj, key)) {
|
|
6164
|
-
if (iterator.call(context, obj[key], key, obj) === breaker) {
|
|
6165
|
-
return;
|
|
6166
|
-
}
|
|
6167
|
-
}
|
|
6168
|
-
}
|
|
6169
|
-
}
|
|
6170
|
-
};
|
|
6171
|
-
|
|
6172
|
-
_.extend = function(obj) {
|
|
6173
|
-
_.each(slice.call(arguments, 1), function(source) {
|
|
6174
|
-
for (var prop in source) {
|
|
6175
|
-
if (source[prop] !== void 0) {
|
|
6176
|
-
obj[prop] = source[prop];
|
|
6177
|
-
}
|
|
6178
|
-
}
|
|
6179
|
-
});
|
|
6180
|
-
return obj;
|
|
6181
|
-
};
|
|
6182
|
-
|
|
6183
|
-
_.isArray = nativeIsArray || function(obj) {
|
|
6184
|
-
return toString.call(obj) === '[object Array]';
|
|
6185
|
-
};
|
|
6186
|
-
|
|
6187
|
-
// from a comment on http://dbj.org/dbj/?p=286
|
|
6188
|
-
// fails on only one very rare and deliberate custom object:
|
|
6189
|
-
// var bomb = { toString : undefined, valueOf: function(o) { return "function BOMBA!"; }};
|
|
6190
|
-
_.isFunction = function(f) {
|
|
6191
|
-
try {
|
|
6192
|
-
return /^\s*\bfunction\b/.test(f);
|
|
6193
|
-
} catch (x) {
|
|
6194
|
-
return false;
|
|
6195
|
-
}
|
|
6196
|
-
};
|
|
6197
|
-
|
|
6198
|
-
_.isArguments = function(obj) {
|
|
6199
|
-
return !!(obj && hasOwnProperty$9.call(obj, 'callee'));
|
|
6200
|
-
};
|
|
6201
|
-
|
|
6202
|
-
_.toArray = function(iterable) {
|
|
6203
|
-
if (!iterable) {
|
|
6204
|
-
return [];
|
|
6205
|
-
}
|
|
6206
|
-
if (iterable.toArray) {
|
|
6207
|
-
return iterable.toArray();
|
|
6208
|
-
}
|
|
6209
|
-
if (_.isArray(iterable)) {
|
|
6210
|
-
return slice.call(iterable);
|
|
6211
|
-
}
|
|
6212
|
-
if (_.isArguments(iterable)) {
|
|
6213
|
-
return slice.call(iterable);
|
|
6214
|
-
}
|
|
6215
|
-
return _.values(iterable);
|
|
6216
|
-
};
|
|
6217
|
-
|
|
6218
|
-
_.map = function(arr, callback, context) {
|
|
6219
|
-
if (nativeMap && arr.map === nativeMap) {
|
|
6220
|
-
return arr.map(callback, context);
|
|
6221
|
-
} else {
|
|
6222
|
-
var results = [];
|
|
6223
|
-
_.each(arr, function(item) {
|
|
6224
|
-
results.push(callback.call(context, item));
|
|
6225
|
-
});
|
|
6226
|
-
return results;
|
|
6227
|
-
}
|
|
6228
|
-
};
|
|
6229
|
-
|
|
6230
|
-
_.keys = function(obj) {
|
|
6231
|
-
var results = [];
|
|
6232
|
-
if (obj === null) {
|
|
6233
|
-
return results;
|
|
6234
|
-
}
|
|
6235
|
-
_.each(obj, function(value, key) {
|
|
6236
|
-
results[results.length] = key;
|
|
6237
|
-
});
|
|
6238
|
-
return results;
|
|
6239
|
-
};
|
|
6218
|
+
const bachSessionId = `
|
|
6219
|
+
id {
|
|
6220
|
+
sessionId
|
|
6221
|
+
genNo
|
|
6222
|
+
acSession {
|
|
6223
|
+
sessionId
|
|
6224
|
+
genNo
|
|
6225
|
+
}
|
|
6226
|
+
}
|
|
6227
|
+
`;
|
|
6228
|
+
const getUnaggregatedAnswerSession = `
|
|
6229
|
+
mutation GetUnAggregatedAnswerSession($session: BachSessionIdInput!, $columns: [UserPointSelectionInput!]!) {
|
|
6230
|
+
Answer__getUnaggregatedAnswer(session: $session, columns: $columns) {
|
|
6231
|
+
${bachSessionId}
|
|
6232
|
+
answer {
|
|
6233
|
+
visualizations {
|
|
6234
|
+
... on TableViz {
|
|
6235
|
+
columns {
|
|
6236
|
+
column {
|
|
6237
|
+
id
|
|
6238
|
+
name
|
|
6239
|
+
referencedColumns {
|
|
6240
|
+
guid
|
|
6241
|
+
displayName
|
|
6242
|
+
}
|
|
6243
|
+
}
|
|
6244
|
+
}
|
|
6245
|
+
}
|
|
6246
|
+
}
|
|
6247
|
+
}
|
|
6248
|
+
}
|
|
6249
|
+
}
|
|
6250
|
+
`;
|
|
6251
|
+
const removeColumns = `
|
|
6252
|
+
mutation RemoveColumns($session: BachSessionIdInput!, $logicalColumnIds: [GUID!], $columnIds: [GUID!]) {
|
|
6253
|
+
Answer__removeColumns(
|
|
6254
|
+
session: $session
|
|
6255
|
+
logicalColumnIds: $logicalColumnIds
|
|
6256
|
+
columnIds: $columnIds
|
|
6257
|
+
) {
|
|
6258
|
+
${bachSessionId}
|
|
6259
|
+
}
|
|
6260
|
+
}
|
|
6261
|
+
`;
|
|
6262
|
+
const addColumns = `
|
|
6263
|
+
mutation AddColumns($session: BachSessionIdInput!, $columns: [AnswerColumnInfo!]!) {
|
|
6264
|
+
Answer__addColumn(session: $session, columns: $columns) {
|
|
6265
|
+
${bachSessionId}
|
|
6266
|
+
}
|
|
6267
|
+
}
|
|
6268
|
+
`;
|
|
6269
|
+
const getAnswerData = `
|
|
6270
|
+
query GetTableWithHeadlineData($session: BachSessionIdInput!, $deadline: Int!, $dataPaginationParams: DataPaginationParamsInput!) {
|
|
6271
|
+
getAnswer(session: $session) {
|
|
6272
|
+
${bachSessionId}
|
|
6273
|
+
answer {
|
|
6274
|
+
id
|
|
6275
|
+
visualizations {
|
|
6276
|
+
id
|
|
6277
|
+
... on TableViz {
|
|
6278
|
+
columns {
|
|
6279
|
+
column {
|
|
6280
|
+
id
|
|
6281
|
+
name
|
|
6282
|
+
type
|
|
6283
|
+
aggregationType
|
|
6284
|
+
dataType
|
|
6285
|
+
}
|
|
6286
|
+
}
|
|
6287
|
+
data(deadline: $deadline, pagination: $dataPaginationParams)
|
|
6288
|
+
}
|
|
6289
|
+
}
|
|
6290
|
+
}
|
|
6291
|
+
}
|
|
6292
|
+
}
|
|
6293
|
+
`;
|
|
6240
6294
|
|
|
6241
|
-
|
|
6242
|
-
|
|
6243
|
-
|
|
6244
|
-
|
|
6245
|
-
|
|
6246
|
-
|
|
6247
|
-
|
|
6248
|
-
|
|
6249
|
-
|
|
6250
|
-
|
|
6295
|
+
// eslint-disable-next-line no-shadow
|
|
6296
|
+
var OperationType;
|
|
6297
|
+
(function (OperationType) {
|
|
6298
|
+
OperationType["GetChartWithData"] = "GetChartWithData";
|
|
6299
|
+
OperationType["GetTableWithHeadlineData"] = "GetTableWithHeadlineData";
|
|
6300
|
+
})(OperationType || (OperationType = {}));
|
|
6301
|
+
/**
|
|
6302
|
+
* Class representing the answer service provided with the
|
|
6303
|
+
* custom action payload. This service could be used to run
|
|
6304
|
+
* graphql queries in the context of the answer on which the
|
|
6305
|
+
* custom action was triggered.
|
|
6306
|
+
*
|
|
6307
|
+
* @example
|
|
6308
|
+
* ```js
|
|
6309
|
+
* embed.on(EmbedEvent.CustomAction, e => {
|
|
6310
|
+
* const underlying = await e.answerService.getUnderlyingDataForPoint([
|
|
6311
|
+
* 'col name 1'
|
|
6312
|
+
* ]);
|
|
6313
|
+
* const data = await underlying.fetchData(0, 100);
|
|
6314
|
+
* })
|
|
6315
|
+
* ```
|
|
6316
|
+
* @version SDK: 1.25.0| ThoughtSpot: 9.10.0.cl
|
|
6317
|
+
* @group Events
|
|
6318
|
+
*/
|
|
6319
|
+
class AnswerService {
|
|
6320
|
+
/**
|
|
6321
|
+
* Should not need to be called directly.
|
|
6322
|
+
*
|
|
6323
|
+
* @param session
|
|
6324
|
+
* @param answer
|
|
6325
|
+
* @param thoughtSpotHost
|
|
6326
|
+
* @param selectedPoints
|
|
6327
|
+
*/
|
|
6328
|
+
constructor(session, answer, thoughtSpotHost, selectedPoints) {
|
|
6329
|
+
this.session = session;
|
|
6330
|
+
this.answer = answer;
|
|
6331
|
+
this.thoughtSpotHost = thoughtSpotHost;
|
|
6332
|
+
this.selectedPoints = selectedPoints;
|
|
6333
|
+
this.session = removeTypename(session);
|
|
6334
|
+
}
|
|
6335
|
+
/**
|
|
6336
|
+
* Get the details about the source used in the answer.
|
|
6337
|
+
* This can be used to get the list of all columns in the data source for example.
|
|
6338
|
+
*/
|
|
6339
|
+
async getSourceDetail() {
|
|
6340
|
+
const sourceId = this.answer.sources[0].header.guid;
|
|
6341
|
+
return getSourceDetail(this.thoughtSpotHost, sourceId);
|
|
6342
|
+
}
|
|
6343
|
+
/**
|
|
6344
|
+
* Remove columnIds and return updated answer session.
|
|
6345
|
+
*
|
|
6346
|
+
* @param columnIds
|
|
6347
|
+
* @returns
|
|
6348
|
+
*/
|
|
6349
|
+
async removeColumns(columnIds) {
|
|
6350
|
+
return this.executeQuery(removeColumns, {
|
|
6351
|
+
logicalColumnIds: columnIds,
|
|
6352
|
+
});
|
|
6353
|
+
}
|
|
6354
|
+
/**
|
|
6355
|
+
* Add columnIds and return updated answer session.
|
|
6356
|
+
*
|
|
6357
|
+
* @param columnIds
|
|
6358
|
+
* @returns
|
|
6359
|
+
*/
|
|
6360
|
+
async addColumns(columnIds) {
|
|
6361
|
+
return this.executeQuery(addColumns, {
|
|
6362
|
+
columns: columnIds.map((colId) => ({ logicalColumnId: colId })),
|
|
6363
|
+
});
|
|
6364
|
+
}
|
|
6365
|
+
/**
|
|
6366
|
+
* Fetch data from the answer.
|
|
6367
|
+
*
|
|
6368
|
+
* @param offset
|
|
6369
|
+
* @param size
|
|
6370
|
+
* @returns
|
|
6371
|
+
*/
|
|
6372
|
+
async fetchData(offset = 0, size = 1000) {
|
|
6373
|
+
const { answer } = await this.executeQuery(getAnswerData, {
|
|
6374
|
+
deadline: 0,
|
|
6375
|
+
dataPaginationParams: {
|
|
6376
|
+
isClientPaginated: true,
|
|
6377
|
+
offset,
|
|
6378
|
+
size,
|
|
6379
|
+
},
|
|
6380
|
+
});
|
|
6381
|
+
const { columns, data } = answer.visualizations.find((viz) => !!viz.data) || {};
|
|
6382
|
+
return {
|
|
6383
|
+
columns,
|
|
6384
|
+
data,
|
|
6385
|
+
};
|
|
6386
|
+
}
|
|
6387
|
+
/**
|
|
6388
|
+
* Fetch the data for the answer as a CSV blob. This might be
|
|
6389
|
+
* quicker for larger data.
|
|
6390
|
+
*
|
|
6391
|
+
* @param userLocale
|
|
6392
|
+
* @param includeInfo Include the CSV header in the output
|
|
6393
|
+
* @returns Response
|
|
6394
|
+
*/
|
|
6395
|
+
async fetchCSVBlob(userLocale = 'en-us', includeInfo = false) {
|
|
6396
|
+
const fetchUrl = this.getFetchCSVBlobUrl(userLocale, includeInfo);
|
|
6397
|
+
return tokenizedFetch(fetchUrl, {
|
|
6398
|
+
credentials: 'include',
|
|
6399
|
+
});
|
|
6400
|
+
}
|
|
6401
|
+
/**
|
|
6402
|
+
* Just get the internal URL for this answer's data
|
|
6403
|
+
* as a CSV blob.
|
|
6404
|
+
*
|
|
6405
|
+
* @param userLocale
|
|
6406
|
+
* @param includeInfo
|
|
6407
|
+
* @returns
|
|
6408
|
+
*/
|
|
6409
|
+
getFetchCSVBlobUrl(userLocale = 'en-us', includeInfo = false) {
|
|
6410
|
+
return `${this.thoughtSpotHost}/prism/download/answer/csv?sessionId=${this.session.sessionId}&genNo=${this.session.genNo}&userLocale=${userLocale}&exportFileName=data&hideCsvHeader=${!includeInfo}`;
|
|
6411
|
+
}
|
|
6412
|
+
/**
|
|
6413
|
+
* Get underlying data given a point and the output column names.
|
|
6414
|
+
* In case of a context menu action, the selectedPoints are
|
|
6415
|
+
* automatically passed.
|
|
6416
|
+
*
|
|
6417
|
+
* @param outputColumnNames
|
|
6418
|
+
* @param selectedPoints
|
|
6419
|
+
* @example
|
|
6420
|
+
* ```js
|
|
6421
|
+
* embed.on(EmbedEvent.CustomAction, e => {
|
|
6422
|
+
* const underlying = await e.answerService.getUnderlyingDataForPoint([
|
|
6423
|
+
* 'col name 1' // The column should exist in the data source.
|
|
6424
|
+
* ]);
|
|
6425
|
+
* const data = await underlying.fetchData(0, 100);
|
|
6426
|
+
* })
|
|
6427
|
+
* ```
|
|
6428
|
+
* @version SDK: 1.25.0| ThoughtSpot: 9.10.0.cl
|
|
6429
|
+
*/
|
|
6430
|
+
async getUnderlyingDataForPoint(outputColumnNames, selectedPoints) {
|
|
6431
|
+
if (!selectedPoints && !this.selectedPoints) {
|
|
6432
|
+
throw new Error('Needs to be triggered in context of a point');
|
|
6433
|
+
}
|
|
6434
|
+
if (!selectedPoints) {
|
|
6435
|
+
selectedPoints = getSelectedPointsForUnderlyingDataQuery(this.selectedPoints);
|
|
6436
|
+
}
|
|
6437
|
+
const sourceDetail = await this.getSourceDetail();
|
|
6438
|
+
const ouputColumnGuids = getGuidsFromColumnNames(sourceDetail, outputColumnNames);
|
|
6439
|
+
const unAggAnswer = await graphqlQuery({
|
|
6440
|
+
query: getUnaggregatedAnswerSession,
|
|
6441
|
+
variables: {
|
|
6442
|
+
session: this.session,
|
|
6443
|
+
columns: selectedPoints,
|
|
6444
|
+
},
|
|
6445
|
+
thoughtSpotHost: this.thoughtSpotHost,
|
|
6446
|
+
});
|
|
6447
|
+
const unaggAnswerSession = new AnswerService(unAggAnswer.id, unAggAnswer.answer, this.thoughtSpotHost);
|
|
6448
|
+
const currentColumns = new Set(unAggAnswer.answer.visualizations[0].columns
|
|
6449
|
+
.map((c) => c.column.referencedColumns[0].guid));
|
|
6450
|
+
const columnsToAdd = [...ouputColumnGuids].filter((col) => !currentColumns.has(col));
|
|
6451
|
+
if (columnsToAdd.length) {
|
|
6452
|
+
await unaggAnswerSession.addColumns(columnsToAdd);
|
|
6453
|
+
}
|
|
6454
|
+
const columnsToRemove = [...currentColumns].filter((col) => !ouputColumnGuids.has(col));
|
|
6455
|
+
if (columnsToRemove.length) {
|
|
6456
|
+
await unaggAnswerSession.removeColumns(columnsToRemove);
|
|
6457
|
+
}
|
|
6458
|
+
return unaggAnswerSession;
|
|
6459
|
+
}
|
|
6460
|
+
/**
|
|
6461
|
+
* Execute a custom graphql query in the context of the answer.
|
|
6462
|
+
*
|
|
6463
|
+
* @param query graphql query
|
|
6464
|
+
* @param variables graphql variables
|
|
6465
|
+
* @returns
|
|
6466
|
+
*/
|
|
6467
|
+
async executeQuery(query, variables) {
|
|
6468
|
+
const data = await graphqlQuery({
|
|
6469
|
+
query,
|
|
6470
|
+
variables: {
|
|
6471
|
+
session: this.session,
|
|
6472
|
+
...variables,
|
|
6473
|
+
},
|
|
6474
|
+
thoughtSpotHost: this.thoughtSpotHost,
|
|
6475
|
+
isCompositeQuery: false,
|
|
6476
|
+
});
|
|
6477
|
+
this.session = deepMerge(this.session, (data === null || data === void 0 ? void 0 : data.id) || {});
|
|
6478
|
+
return data;
|
|
6479
|
+
}
|
|
6480
|
+
/**
|
|
6481
|
+
* Get the internal session details for the answer.
|
|
6482
|
+
*
|
|
6483
|
+
* @returns
|
|
6484
|
+
*/
|
|
6485
|
+
getSession() {
|
|
6486
|
+
return this.session;
|
|
6487
|
+
}
|
|
6488
|
+
}
|
|
6489
|
+
/**
|
|
6490
|
+
*
|
|
6491
|
+
* @param sourceDetail
|
|
6492
|
+
* @param colNames
|
|
6493
|
+
*/
|
|
6494
|
+
function getGuidsFromColumnNames(sourceDetail, colNames) {
|
|
6495
|
+
const cols = sourceDetail.columns.reduce((colSet, col) => {
|
|
6496
|
+
colSet[col.name] = col;
|
|
6497
|
+
return colSet;
|
|
6498
|
+
}, {});
|
|
6499
|
+
return new Set(colNames.map((colName) => {
|
|
6500
|
+
const col = cols[colName];
|
|
6501
|
+
return col.id;
|
|
6502
|
+
}));
|
|
6503
|
+
}
|
|
6504
|
+
/**
|
|
6505
|
+
*
|
|
6506
|
+
* @param selectedPoints
|
|
6507
|
+
*/
|
|
6508
|
+
function getSelectedPointsForUnderlyingDataQuery(selectedPoints) {
|
|
6509
|
+
const underlyingDataPoint = [];
|
|
6510
|
+
/**
|
|
6511
|
+
*
|
|
6512
|
+
* @param colVal
|
|
6513
|
+
*/
|
|
6514
|
+
function addPointFromColVal(colVal) {
|
|
6515
|
+
var _a;
|
|
6516
|
+
const dataType = colVal.column.dataType;
|
|
6517
|
+
const id = colVal.column.id;
|
|
6518
|
+
let dataValue;
|
|
6519
|
+
if (dataType === 'DATE') {
|
|
6520
|
+
if (Number.isFinite(colVal.value)) {
|
|
6521
|
+
dataValue = [{
|
|
6522
|
+
epochRange: {
|
|
6523
|
+
startEpoch: colVal.value,
|
|
6524
|
+
},
|
|
6525
|
+
}];
|
|
6526
|
+
// Case for custom calendar.
|
|
6527
|
+
}
|
|
6528
|
+
else if ((_a = colVal.value) === null || _a === void 0 ? void 0 : _a.v) {
|
|
6529
|
+
dataValue = [{
|
|
6530
|
+
epochRange: {
|
|
6531
|
+
startEpoch: colVal.value.v.s,
|
|
6532
|
+
endEpoch: colVal.value.v.e,
|
|
6533
|
+
},
|
|
6534
|
+
}];
|
|
6535
|
+
}
|
|
6536
|
+
}
|
|
6537
|
+
else {
|
|
6538
|
+
dataValue = [{ value: colVal.value }];
|
|
6539
|
+
}
|
|
6540
|
+
underlyingDataPoint.push({
|
|
6541
|
+
columnId: colVal.column.id,
|
|
6542
|
+
dataValue,
|
|
6543
|
+
});
|
|
6544
|
+
}
|
|
6545
|
+
selectedPoints.forEach((p) => {
|
|
6546
|
+
p.selectedAttributes.forEach(addPointFromColVal);
|
|
6547
|
+
});
|
|
6548
|
+
return underlyingDataPoint;
|
|
6549
|
+
}
|
|
6251
6550
|
|
|
6252
|
-
|
|
6253
|
-
|
|
6254
|
-
|
|
6255
|
-
|
|
6256
|
-
|
|
6257
|
-
|
|
6258
|
-
return obj.indexOf(target) != -1;
|
|
6259
|
-
}
|
|
6260
|
-
_.each(obj, function(value) {
|
|
6261
|
-
if (found || (found = (value === target))) {
|
|
6262
|
-
return breaker;
|
|
6263
|
-
}
|
|
6264
|
-
});
|
|
6265
|
-
return found;
|
|
6551
|
+
const ERROR_MESSAGE = {
|
|
6552
|
+
INVALID_THOUGHTSPOT_HOST: 'Error parsing ThoughtSpot host. Please provide a valid URL.',
|
|
6553
|
+
LIVEBOARD_VIZ_ID_VALIDATION: 'Please provide either liveboardId or pinboardId',
|
|
6554
|
+
TRIGGER_TIMED_OUT: 'Trigger timedout in getting response',
|
|
6555
|
+
SEARCHEMBED_BETA_WRANING_MESSAGE: 'Search Embed is in Beta in this release.',
|
|
6556
|
+
SAGE_EMBED_BETA_WARNING_MESSAGE: 'Sage Embed is in Beta in this release.',
|
|
6266
6557
|
};
|
|
6267
6558
|
|
|
6268
|
-
|
|
6269
|
-
|
|
6270
|
-
|
|
6559
|
+
/**
|
|
6560
|
+
* Copyright (c) 2023
|
|
6561
|
+
*
|
|
6562
|
+
* Utilities related to reading configuration objects
|
|
6563
|
+
*
|
|
6564
|
+
* @summary Config-related utils
|
|
6565
|
+
* @author Ayon Ghosh <ayon.ghosh@thoughtspot.com>
|
|
6566
|
+
*/
|
|
6567
|
+
const urlRegex = new RegExp([
|
|
6568
|
+
'(^(https?:)//)?',
|
|
6569
|
+
'(([^:/?#]*)(?::([0-9]+))?)',
|
|
6570
|
+
'(/{0,1}[^?#]*)',
|
|
6571
|
+
'(\\?[^#]*|)',
|
|
6572
|
+
'(#.*|)$', // hash
|
|
6573
|
+
].join(''));
|
|
6574
|
+
/**
|
|
6575
|
+
* Parse and construct the ThoughtSpot hostname or IP address
|
|
6576
|
+
* from the embed configuration object.
|
|
6577
|
+
*
|
|
6578
|
+
* @param config
|
|
6579
|
+
*/
|
|
6580
|
+
const getThoughtSpotHost = (config) => {
|
|
6581
|
+
if (!config.thoughtSpotHost) {
|
|
6582
|
+
throw new Error(ERROR_MESSAGE.INVALID_THOUGHTSPOT_HOST);
|
|
6583
|
+
}
|
|
6584
|
+
const urlParts = config.thoughtSpotHost.match(urlRegex);
|
|
6585
|
+
if (!urlParts) {
|
|
6586
|
+
throw new Error(ERROR_MESSAGE.INVALID_THOUGHTSPOT_HOST);
|
|
6587
|
+
}
|
|
6588
|
+
const protocol = urlParts[2] || window.location.protocol;
|
|
6589
|
+
const host = urlParts[3];
|
|
6590
|
+
let path = urlParts[6];
|
|
6591
|
+
// Lose the trailing / if any
|
|
6592
|
+
if (path.charAt(path.length - 1) === '/') {
|
|
6593
|
+
path = path.substring(0, path.length - 1);
|
|
6594
|
+
}
|
|
6595
|
+
// const urlParams = urlParts[7];
|
|
6596
|
+
// const hash = urlParts[8];
|
|
6597
|
+
return `${protocol}//${host}${path}`;
|
|
6598
|
+
};
|
|
6599
|
+
const getV2BasePath = (config) => {
|
|
6600
|
+
if (config.basepath) {
|
|
6601
|
+
return config.basepath;
|
|
6602
|
+
}
|
|
6603
|
+
const tsHost = getThoughtSpotHost(config);
|
|
6604
|
+
// This is to handle when e2e's. Search is run on pods for
|
|
6605
|
+
// comp-blink-test-pipeline with baseUrl=https://localhost:8443.
|
|
6606
|
+
// This is to handle when the developer is developing in their local
|
|
6607
|
+
// environment.
|
|
6608
|
+
if (tsHost.includes('://localhost') && !tsHost.includes(':8443')) {
|
|
6609
|
+
return '';
|
|
6610
|
+
}
|
|
6611
|
+
return 'v2';
|
|
6612
|
+
};
|
|
6613
|
+
/**
|
|
6614
|
+
* It is a good idea to keep URLs under 2000 chars.
|
|
6615
|
+
* If this is ever breached, since we pass view configuration through
|
|
6616
|
+
* URL params, we would like to log a warning.
|
|
6617
|
+
* Reference: https://stackoverflow.com/questions/417142/what-is-the-maximum-length-of-a-url-in-different-browsers
|
|
6618
|
+
*/
|
|
6619
|
+
const URL_MAX_LENGTH = 2000;
|
|
6620
|
+
/**
|
|
6621
|
+
* The default CSS dimensions of the embedded app
|
|
6622
|
+
*/
|
|
6623
|
+
const DEFAULT_EMBED_WIDTH = '100%';
|
|
6624
|
+
const DEFAULT_EMBED_HEIGHT = '100%';
|
|
6271
6625
|
|
|
6272
|
-
|
|
6273
|
-
|
|
6274
|
-
|
|
6275
|
-
subclass.prototype.constructor = subclass;
|
|
6276
|
-
subclass.superclass = superclass.prototype;
|
|
6277
|
-
return subclass;
|
|
6626
|
+
var Config = {
|
|
6627
|
+
DEBUG: false,
|
|
6628
|
+
LIB_VERSION: '2.45.0'
|
|
6278
6629
|
};
|
|
6279
6630
|
|
|
6280
|
-
|
|
6281
|
-
|
|
6631
|
+
// since es6 imports are static and we run unit tests from the console, window won't be defined when importing this file
|
|
6632
|
+
var window$1;
|
|
6633
|
+
if (typeof(window) === 'undefined') {
|
|
6634
|
+
var loc = {
|
|
6635
|
+
hostname: ''
|
|
6636
|
+
};
|
|
6637
|
+
window$1 = {
|
|
6638
|
+
navigator: { userAgent: '' },
|
|
6639
|
+
document: {
|
|
6640
|
+
location: loc,
|
|
6641
|
+
referrer: ''
|
|
6642
|
+
},
|
|
6643
|
+
screen: { width: 0, height: 0 },
|
|
6644
|
+
location: loc
|
|
6645
|
+
};
|
|
6646
|
+
} else {
|
|
6647
|
+
window$1 = window;
|
|
6648
|
+
}
|
|
6649
|
+
|
|
6650
|
+
/*
|
|
6651
|
+
* Saved references to long variable names, so that closure compiler can
|
|
6652
|
+
* minimize file size.
|
|
6653
|
+
*/
|
|
6654
|
+
|
|
6655
|
+
var ArrayProto = Array.prototype;
|
|
6656
|
+
var FuncProto = Function.prototype;
|
|
6657
|
+
var ObjProto = Object.prototype;
|
|
6658
|
+
var slice = ArrayProto.slice;
|
|
6659
|
+
var toString = ObjProto.toString;
|
|
6660
|
+
var hasOwnProperty$9 = ObjProto.hasOwnProperty;
|
|
6661
|
+
var windowConsole = window$1.console;
|
|
6662
|
+
var navigator = window$1.navigator;
|
|
6663
|
+
var document$1 = window$1.document;
|
|
6664
|
+
var windowOpera = window$1.opera;
|
|
6665
|
+
var screen = window$1.screen;
|
|
6666
|
+
var userAgent = navigator.userAgent;
|
|
6667
|
+
var nativeBind = FuncProto.bind;
|
|
6668
|
+
var nativeForEach = ArrayProto.forEach;
|
|
6669
|
+
var nativeIndexOf = ArrayProto.indexOf;
|
|
6670
|
+
var nativeMap = ArrayProto.map;
|
|
6671
|
+
var nativeIsArray = Array.isArray;
|
|
6672
|
+
var breaker = {};
|
|
6673
|
+
var _ = {
|
|
6674
|
+
trim: function(str) {
|
|
6675
|
+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/Trim#Polyfill
|
|
6676
|
+
return str.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
|
|
6677
|
+
}
|
|
6282
6678
|
};
|
|
6283
6679
|
|
|
6284
|
-
|
|
6285
|
-
|
|
6286
|
-
|
|
6287
|
-
|
|
6288
|
-
|
|
6680
|
+
// Console override
|
|
6681
|
+
var console$1 = {
|
|
6682
|
+
/** @type {function(...*)} */
|
|
6683
|
+
log: function() {
|
|
6684
|
+
if (Config.DEBUG && !_.isUndefined(windowConsole) && windowConsole) {
|
|
6685
|
+
try {
|
|
6686
|
+
windowConsole.log.apply(windowConsole, arguments);
|
|
6687
|
+
} catch (err) {
|
|
6688
|
+
_.each(arguments, function(arg) {
|
|
6689
|
+
windowConsole.log(arg);
|
|
6690
|
+
});
|
|
6691
|
+
}
|
|
6692
|
+
}
|
|
6693
|
+
},
|
|
6694
|
+
/** @type {function(...*)} */
|
|
6695
|
+
warn: function() {
|
|
6696
|
+
if (Config.DEBUG && !_.isUndefined(windowConsole) && windowConsole) {
|
|
6697
|
+
var args = ['Mixpanel warning:'].concat(_.toArray(arguments));
|
|
6698
|
+
try {
|
|
6699
|
+
windowConsole.warn.apply(windowConsole, args);
|
|
6700
|
+
} catch (err) {
|
|
6701
|
+
_.each(args, function(arg) {
|
|
6702
|
+
windowConsole.warn(arg);
|
|
6703
|
+
});
|
|
6704
|
+
}
|
|
6705
|
+
}
|
|
6706
|
+
},
|
|
6707
|
+
/** @type {function(...*)} */
|
|
6708
|
+
error: function() {
|
|
6709
|
+
if (Config.DEBUG && !_.isUndefined(windowConsole) && windowConsole) {
|
|
6710
|
+
var args = ['Mixpanel error:'].concat(_.toArray(arguments));
|
|
6711
|
+
try {
|
|
6712
|
+
windowConsole.error.apply(windowConsole, args);
|
|
6713
|
+
} catch (err) {
|
|
6714
|
+
_.each(args, function(arg) {
|
|
6715
|
+
windowConsole.error(arg);
|
|
6716
|
+
});
|
|
6717
|
+
}
|
|
6718
|
+
}
|
|
6719
|
+
},
|
|
6720
|
+
/** @type {function(...*)} */
|
|
6721
|
+
critical: function() {
|
|
6722
|
+
if (!_.isUndefined(windowConsole) && windowConsole) {
|
|
6723
|
+
var args = ['Mixpanel error:'].concat(_.toArray(arguments));
|
|
6724
|
+
try {
|
|
6725
|
+
windowConsole.error.apply(windowConsole, args);
|
|
6726
|
+
} catch (err) {
|
|
6727
|
+
_.each(args, function(arg) {
|
|
6728
|
+
windowConsole.error(arg);
|
|
6729
|
+
});
|
|
6289
6730
|
}
|
|
6290
6731
|
}
|
|
6291
|
-
return true;
|
|
6292
6732
|
}
|
|
6293
|
-
return false;
|
|
6294
|
-
};
|
|
6295
|
-
|
|
6296
|
-
_.isUndefined = function(obj) {
|
|
6297
|
-
return obj === void 0;
|
|
6298
6733
|
};
|
|
6299
6734
|
|
|
6300
|
-
|
|
6301
|
-
return
|
|
6735
|
+
var log_func_with_prefix = function(func, prefix) {
|
|
6736
|
+
return function() {
|
|
6737
|
+
arguments[0] = '[' + prefix + '] ' + arguments[0];
|
|
6738
|
+
return func.apply(console$1, arguments);
|
|
6739
|
+
};
|
|
6302
6740
|
};
|
|
6303
|
-
|
|
6304
|
-
|
|
6305
|
-
|
|
6741
|
+
var console_with_prefix = function(prefix) {
|
|
6742
|
+
return {
|
|
6743
|
+
log: log_func_with_prefix(console$1.log, prefix),
|
|
6744
|
+
error: log_func_with_prefix(console$1.error, prefix),
|
|
6745
|
+
critical: log_func_with_prefix(console$1.critical, prefix)
|
|
6746
|
+
};
|
|
6306
6747
|
};
|
|
6307
6748
|
|
|
6308
|
-
_.isNumber = function(obj) {
|
|
6309
|
-
return toString.call(obj) == '[object Number]';
|
|
6310
|
-
};
|
|
6311
6749
|
|
|
6312
|
-
|
|
6313
|
-
|
|
6750
|
+
// UNDERSCORE
|
|
6751
|
+
// Embed part of the Underscore Library
|
|
6752
|
+
_.bind = function(func, context) {
|
|
6753
|
+
var args, bound;
|
|
6754
|
+
if (nativeBind && func.bind === nativeBind) {
|
|
6755
|
+
return nativeBind.apply(func, slice.call(arguments, 1));
|
|
6756
|
+
}
|
|
6757
|
+
if (!_.isFunction(func)) {
|
|
6758
|
+
throw new TypeError();
|
|
6759
|
+
}
|
|
6760
|
+
args = slice.call(arguments, 2);
|
|
6761
|
+
bound = function() {
|
|
6762
|
+
if (!(this instanceof bound)) {
|
|
6763
|
+
return func.apply(context, args.concat(slice.call(arguments)));
|
|
6764
|
+
}
|
|
6765
|
+
var ctor = {};
|
|
6766
|
+
ctor.prototype = func.prototype;
|
|
6767
|
+
var self = new ctor();
|
|
6768
|
+
ctor.prototype = null;
|
|
6769
|
+
var result = func.apply(self, args.concat(slice.call(arguments)));
|
|
6770
|
+
if (Object(result) === result) {
|
|
6771
|
+
return result;
|
|
6772
|
+
}
|
|
6773
|
+
return self;
|
|
6774
|
+
};
|
|
6775
|
+
return bound;
|
|
6314
6776
|
};
|
|
6315
6777
|
|
|
6316
|
-
|
|
6778
|
+
/**
|
|
6779
|
+
* @param {*=} obj
|
|
6780
|
+
* @param {function(...*)=} iterator
|
|
6781
|
+
* @param {Object=} context
|
|
6782
|
+
*/
|
|
6783
|
+
_.each = function(obj, iterator, context) {
|
|
6784
|
+
if (obj === null || obj === undefined) {
|
|
6785
|
+
return;
|
|
6786
|
+
}
|
|
6787
|
+
if (nativeForEach && obj.forEach === nativeForEach) {
|
|
6788
|
+
obj.forEach(iterator, context);
|
|
6789
|
+
} else if (obj.length === +obj.length) {
|
|
6790
|
+
for (var i = 0, l = obj.length; i < l; i++) {
|
|
6791
|
+
if (i in obj && iterator.call(context, obj[i], i, obj) === breaker) {
|
|
6792
|
+
return;
|
|
6793
|
+
}
|
|
6794
|
+
}
|
|
6795
|
+
} else {
|
|
6796
|
+
for (var key in obj) {
|
|
6797
|
+
if (hasOwnProperty$9.call(obj, key)) {
|
|
6798
|
+
if (iterator.call(context, obj[key], key, obj) === breaker) {
|
|
6799
|
+
return;
|
|
6800
|
+
}
|
|
6801
|
+
}
|
|
6802
|
+
}
|
|
6803
|
+
}
|
|
6804
|
+
};
|
|
6805
|
+
|
|
6806
|
+
_.extend = function(obj) {
|
|
6807
|
+
_.each(slice.call(arguments, 1), function(source) {
|
|
6808
|
+
for (var prop in source) {
|
|
6809
|
+
if (source[prop] !== void 0) {
|
|
6810
|
+
obj[prop] = source[prop];
|
|
6811
|
+
}
|
|
6812
|
+
}
|
|
6813
|
+
});
|
|
6814
|
+
return obj;
|
|
6815
|
+
};
|
|
6816
|
+
|
|
6817
|
+
_.isArray = nativeIsArray || function(obj) {
|
|
6818
|
+
return toString.call(obj) === '[object Array]';
|
|
6819
|
+
};
|
|
6820
|
+
|
|
6821
|
+
// from a comment on http://dbj.org/dbj/?p=286
|
|
6822
|
+
// fails on only one very rare and deliberate custom object:
|
|
6823
|
+
// var bomb = { toString : undefined, valueOf: function(o) { return "function BOMBA!"; }};
|
|
6824
|
+
_.isFunction = function(f) {
|
|
6825
|
+
try {
|
|
6826
|
+
return /^\s*\bfunction\b/.test(f);
|
|
6827
|
+
} catch (x) {
|
|
6828
|
+
return false;
|
|
6829
|
+
}
|
|
6830
|
+
};
|
|
6831
|
+
|
|
6832
|
+
_.isArguments = function(obj) {
|
|
6833
|
+
return !!(obj && hasOwnProperty$9.call(obj, 'callee'));
|
|
6834
|
+
};
|
|
6835
|
+
|
|
6836
|
+
_.toArray = function(iterable) {
|
|
6837
|
+
if (!iterable) {
|
|
6838
|
+
return [];
|
|
6839
|
+
}
|
|
6840
|
+
if (iterable.toArray) {
|
|
6841
|
+
return iterable.toArray();
|
|
6842
|
+
}
|
|
6843
|
+
if (_.isArray(iterable)) {
|
|
6844
|
+
return slice.call(iterable);
|
|
6845
|
+
}
|
|
6846
|
+
if (_.isArguments(iterable)) {
|
|
6847
|
+
return slice.call(iterable);
|
|
6848
|
+
}
|
|
6849
|
+
return _.values(iterable);
|
|
6850
|
+
};
|
|
6851
|
+
|
|
6852
|
+
_.map = function(arr, callback, context) {
|
|
6853
|
+
if (nativeMap && arr.map === nativeMap) {
|
|
6854
|
+
return arr.map(callback, context);
|
|
6855
|
+
} else {
|
|
6856
|
+
var results = [];
|
|
6857
|
+
_.each(arr, function(item) {
|
|
6858
|
+
results.push(callback.call(context, item));
|
|
6859
|
+
});
|
|
6860
|
+
return results;
|
|
6861
|
+
}
|
|
6862
|
+
};
|
|
6863
|
+
|
|
6864
|
+
_.keys = function(obj) {
|
|
6865
|
+
var results = [];
|
|
6866
|
+
if (obj === null) {
|
|
6867
|
+
return results;
|
|
6868
|
+
}
|
|
6869
|
+
_.each(obj, function(value, key) {
|
|
6870
|
+
results[results.length] = key;
|
|
6871
|
+
});
|
|
6872
|
+
return results;
|
|
6873
|
+
};
|
|
6874
|
+
|
|
6875
|
+
_.values = function(obj) {
|
|
6876
|
+
var results = [];
|
|
6877
|
+
if (obj === null) {
|
|
6878
|
+
return results;
|
|
6879
|
+
}
|
|
6880
|
+
_.each(obj, function(value) {
|
|
6881
|
+
results[results.length] = value;
|
|
6882
|
+
});
|
|
6883
|
+
return results;
|
|
6884
|
+
};
|
|
6885
|
+
|
|
6886
|
+
_.include = function(obj, target) {
|
|
6887
|
+
var found = false;
|
|
6888
|
+
if (obj === null) {
|
|
6889
|
+
return found;
|
|
6890
|
+
}
|
|
6891
|
+
if (nativeIndexOf && obj.indexOf === nativeIndexOf) {
|
|
6892
|
+
return obj.indexOf(target) != -1;
|
|
6893
|
+
}
|
|
6894
|
+
_.each(obj, function(value) {
|
|
6895
|
+
if (found || (found = (value === target))) {
|
|
6896
|
+
return breaker;
|
|
6897
|
+
}
|
|
6898
|
+
});
|
|
6899
|
+
return found;
|
|
6900
|
+
};
|
|
6901
|
+
|
|
6902
|
+
_.includes = function(str, needle) {
|
|
6903
|
+
return str.indexOf(needle) !== -1;
|
|
6904
|
+
};
|
|
6905
|
+
|
|
6906
|
+
// Underscore Addons
|
|
6907
|
+
_.inherit = function(subclass, superclass) {
|
|
6908
|
+
subclass.prototype = new superclass();
|
|
6909
|
+
subclass.prototype.constructor = subclass;
|
|
6910
|
+
subclass.superclass = superclass.prototype;
|
|
6911
|
+
return subclass;
|
|
6912
|
+
};
|
|
6913
|
+
|
|
6914
|
+
_.isObject = function(obj) {
|
|
6915
|
+
return (obj === Object(obj) && !_.isArray(obj));
|
|
6916
|
+
};
|
|
6917
|
+
|
|
6918
|
+
_.isEmptyObject = function(obj) {
|
|
6919
|
+
if (_.isObject(obj)) {
|
|
6920
|
+
for (var key in obj) {
|
|
6921
|
+
if (hasOwnProperty$9.call(obj, key)) {
|
|
6922
|
+
return false;
|
|
6923
|
+
}
|
|
6924
|
+
}
|
|
6925
|
+
return true;
|
|
6926
|
+
}
|
|
6927
|
+
return false;
|
|
6928
|
+
};
|
|
6929
|
+
|
|
6930
|
+
_.isUndefined = function(obj) {
|
|
6931
|
+
return obj === void 0;
|
|
6932
|
+
};
|
|
6933
|
+
|
|
6934
|
+
_.isString = function(obj) {
|
|
6935
|
+
return toString.call(obj) == '[object String]';
|
|
6936
|
+
};
|
|
6937
|
+
|
|
6938
|
+
_.isDate = function(obj) {
|
|
6939
|
+
return toString.call(obj) == '[object Date]';
|
|
6940
|
+
};
|
|
6941
|
+
|
|
6942
|
+
_.isNumber = function(obj) {
|
|
6943
|
+
return toString.call(obj) == '[object Number]';
|
|
6944
|
+
};
|
|
6945
|
+
|
|
6946
|
+
_.isElement = function(obj) {
|
|
6947
|
+
return !!(obj && obj.nodeType === 1);
|
|
6948
|
+
};
|
|
6949
|
+
|
|
6950
|
+
_.encodeDates = function(obj) {
|
|
6317
6951
|
_.each(obj, function(v, k) {
|
|
6318
6952
|
if (_.isDate(v)) {
|
|
6319
6953
|
obj[k] = _.formatDate(v);
|
|
@@ -11627,1357 +12261,423 @@
|
|
|
11627
12261
|
'ignore_dnt': this.get_config('ignore_dnt')
|
|
11628
12262
|
}, options);
|
|
11629
12263
|
|
|
11630
|
-
// check if localStorage can be used for recording opt out status, fall back to cookie if not
|
|
11631
|
-
if (!_.localStorage.is_supported()) {
|
|
11632
|
-
options['persistence_type'] = 'cookie';
|
|
11633
|
-
}
|
|
11634
|
-
|
|
11635
|
-
return func(this.get_config('token'), {
|
|
11636
|
-
track: options['track'],
|
|
11637
|
-
trackEventName: options['track_event_name'],
|
|
11638
|
-
trackProperties: options['track_properties'],
|
|
11639
|
-
persistenceType: options['persistence_type'],
|
|
11640
|
-
persistencePrefix: options['cookie_prefix'],
|
|
11641
|
-
cookieDomain: options['cookie_domain'],
|
|
11642
|
-
cookieExpiration: options['cookie_expiration'],
|
|
11643
|
-
crossSiteCookie: options['cross_site_cookie'],
|
|
11644
|
-
crossSubdomainCookie: options['cross_subdomain_cookie'],
|
|
11645
|
-
secureCookie: options['secure_cookie'],
|
|
11646
|
-
ignoreDnt: options['ignore_dnt']
|
|
11647
|
-
});
|
|
11648
|
-
};
|
|
11649
|
-
|
|
11650
|
-
/**
|
|
11651
|
-
* Opt the user in to data tracking and cookies/localstorage for this Mixpanel instance
|
|
11652
|
-
*
|
|
11653
|
-
* ### Usage
|
|
11654
|
-
*
|
|
11655
|
-
* // opt user in
|
|
11656
|
-
* mixpanel.opt_in_tracking();
|
|
11657
|
-
*
|
|
11658
|
-
* // opt user in with specific event name, properties, cookie configuration
|
|
11659
|
-
* mixpanel.opt_in_tracking({
|
|
11660
|
-
* track_event_name: 'User opted in',
|
|
11661
|
-
* track_event_properties: {
|
|
11662
|
-
* 'Email': 'jdoe@example.com'
|
|
11663
|
-
* },
|
|
11664
|
-
* cookie_expiration: 30,
|
|
11665
|
-
* secure_cookie: true
|
|
11666
|
-
* });
|
|
11667
|
-
*
|
|
11668
|
-
* @param {Object} [options] A dictionary of config options to override
|
|
11669
|
-
* @param {function} [options.track] Function used for tracking a Mixpanel event to record the opt-in action (default is this Mixpanel instance's track method)
|
|
11670
|
-
* @param {string} [options.track_event_name=$opt_in] Event name to be used for tracking the opt-in action
|
|
11671
|
-
* @param {Object} [options.track_properties] Set of properties to be tracked along with the opt-in action
|
|
11672
|
-
* @param {boolean} [options.enable_persistence=true] If true, will re-enable sdk persistence
|
|
11673
|
-
* @param {string} [options.persistence_type=localStorage] Persistence mechanism used - cookie or localStorage - falls back to cookie if localStorage is unavailable
|
|
11674
|
-
* @param {string} [options.cookie_prefix=__mp_opt_in_out] Custom prefix to be used in the cookie/localstorage name
|
|
11675
|
-
* @param {Number} [options.cookie_expiration] Number of days until the opt-in cookie expires (overrides value specified in this Mixpanel instance's config)
|
|
11676
|
-
* @param {string} [options.cookie_domain] Custom cookie domain (overrides value specified in this Mixpanel instance's config)
|
|
11677
|
-
* @param {boolean} [options.cross_site_cookie] Whether the opt-in cookie is set as cross-site-enabled (overrides value specified in this Mixpanel instance's config)
|
|
11678
|
-
* @param {boolean} [options.cross_subdomain_cookie] Whether the opt-in cookie is set as cross-subdomain or not (overrides value specified in this Mixpanel instance's config)
|
|
11679
|
-
* @param {boolean} [options.secure_cookie] Whether the opt-in cookie is set as secure or not (overrides value specified in this Mixpanel instance's config)
|
|
11680
|
-
*/
|
|
11681
|
-
MixpanelLib.prototype.opt_in_tracking = function(options) {
|
|
11682
|
-
options = _.extend({
|
|
11683
|
-
'enable_persistence': true
|
|
11684
|
-
}, options);
|
|
11685
|
-
|
|
11686
|
-
this._gdpr_call_func(optIn, options);
|
|
11687
|
-
this._gdpr_update_persistence(options);
|
|
11688
|
-
};
|
|
11689
|
-
|
|
11690
|
-
/**
|
|
11691
|
-
* Opt the user out of data tracking and cookies/localstorage for this Mixpanel instance
|
|
11692
|
-
*
|
|
11693
|
-
* ### Usage
|
|
11694
|
-
*
|
|
11695
|
-
* // opt user out
|
|
11696
|
-
* mixpanel.opt_out_tracking();
|
|
11697
|
-
*
|
|
11698
|
-
* // opt user out with different cookie configuration from Mixpanel instance
|
|
11699
|
-
* mixpanel.opt_out_tracking({
|
|
11700
|
-
* cookie_expiration: 30,
|
|
11701
|
-
* secure_cookie: true
|
|
11702
|
-
* });
|
|
11703
|
-
*
|
|
11704
|
-
* @param {Object} [options] A dictionary of config options to override
|
|
11705
|
-
* @param {boolean} [options.delete_user=true] If true, will delete the currently identified user's profile and clear all charges after opting the user out
|
|
11706
|
-
* @param {boolean} [options.clear_persistence=true] If true, will delete all data stored by the sdk in persistence
|
|
11707
|
-
* @param {string} [options.persistence_type=localStorage] Persistence mechanism used - cookie or localStorage - falls back to cookie if localStorage is unavailable
|
|
11708
|
-
* @param {string} [options.cookie_prefix=__mp_opt_in_out] Custom prefix to be used in the cookie/localstorage name
|
|
11709
|
-
* @param {Number} [options.cookie_expiration] Number of days until the opt-in cookie expires (overrides value specified in this Mixpanel instance's config)
|
|
11710
|
-
* @param {string} [options.cookie_domain] Custom cookie domain (overrides value specified in this Mixpanel instance's config)
|
|
11711
|
-
* @param {boolean} [options.cross_site_cookie] Whether the opt-in cookie is set as cross-site-enabled (overrides value specified in this Mixpanel instance's config)
|
|
11712
|
-
* @param {boolean} [options.cross_subdomain_cookie] Whether the opt-in cookie is set as cross-subdomain or not (overrides value specified in this Mixpanel instance's config)
|
|
11713
|
-
* @param {boolean} [options.secure_cookie] Whether the opt-in cookie is set as secure or not (overrides value specified in this Mixpanel instance's config)
|
|
11714
|
-
*/
|
|
11715
|
-
MixpanelLib.prototype.opt_out_tracking = function(options) {
|
|
11716
|
-
options = _.extend({
|
|
11717
|
-
'clear_persistence': true,
|
|
11718
|
-
'delete_user': true
|
|
11719
|
-
}, options);
|
|
11720
|
-
|
|
11721
|
-
// delete user and clear charges since these methods may be disabled by opt-out
|
|
11722
|
-
if (options['delete_user'] && this['people'] && this['people']._identify_called()) {
|
|
11723
|
-
this['people'].delete_user();
|
|
11724
|
-
this['people'].clear_charges();
|
|
11725
|
-
}
|
|
11726
|
-
|
|
11727
|
-
this._gdpr_call_func(optOut, options);
|
|
11728
|
-
this._gdpr_update_persistence(options);
|
|
11729
|
-
};
|
|
11730
|
-
|
|
11731
|
-
/**
|
|
11732
|
-
* Check whether the user has opted in to data tracking and cookies/localstorage for this Mixpanel instance
|
|
11733
|
-
*
|
|
11734
|
-
* ### Usage
|
|
11735
|
-
*
|
|
11736
|
-
* var has_opted_in = mixpanel.has_opted_in_tracking();
|
|
11737
|
-
* // use has_opted_in value
|
|
11738
|
-
*
|
|
11739
|
-
* @param {Object} [options] A dictionary of config options to override
|
|
11740
|
-
* @param {string} [options.persistence_type=localStorage] Persistence mechanism used - cookie or localStorage - falls back to cookie if localStorage is unavailable
|
|
11741
|
-
* @param {string} [options.cookie_prefix=__mp_opt_in_out] Custom prefix to be used in the cookie/localstorage name
|
|
11742
|
-
* @returns {boolean} current opt-in status
|
|
11743
|
-
*/
|
|
11744
|
-
MixpanelLib.prototype.has_opted_in_tracking = function(options) {
|
|
11745
|
-
return this._gdpr_call_func(hasOptedIn, options);
|
|
11746
|
-
};
|
|
11747
|
-
|
|
11748
|
-
/**
|
|
11749
|
-
* Check whether the user has opted out of data tracking and cookies/localstorage for this Mixpanel instance
|
|
11750
|
-
*
|
|
11751
|
-
* ### Usage
|
|
11752
|
-
*
|
|
11753
|
-
* var has_opted_out = mixpanel.has_opted_out_tracking();
|
|
11754
|
-
* // use has_opted_out value
|
|
11755
|
-
*
|
|
11756
|
-
* @param {Object} [options] A dictionary of config options to override
|
|
11757
|
-
* @param {string} [options.persistence_type=localStorage] Persistence mechanism used - cookie or localStorage - falls back to cookie if localStorage is unavailable
|
|
11758
|
-
* @param {string} [options.cookie_prefix=__mp_opt_in_out] Custom prefix to be used in the cookie/localstorage name
|
|
11759
|
-
* @returns {boolean} current opt-out status
|
|
11760
|
-
*/
|
|
11761
|
-
MixpanelLib.prototype.has_opted_out_tracking = function(options) {
|
|
11762
|
-
return this._gdpr_call_func(hasOptedOut, options);
|
|
11763
|
-
};
|
|
11764
|
-
|
|
11765
|
-
/**
|
|
11766
|
-
* Clear the user's opt in/out status of data tracking and cookies/localstorage for this Mixpanel instance
|
|
11767
|
-
*
|
|
11768
|
-
* ### Usage
|
|
11769
|
-
*
|
|
11770
|
-
* // clear user's opt-in/out status
|
|
11771
|
-
* mixpanel.clear_opt_in_out_tracking();
|
|
11772
|
-
*
|
|
11773
|
-
* // clear user's opt-in/out status with specific cookie configuration - should match
|
|
11774
|
-
* // configuration used when opt_in_tracking/opt_out_tracking methods were called.
|
|
11775
|
-
* mixpanel.clear_opt_in_out_tracking({
|
|
11776
|
-
* cookie_expiration: 30,
|
|
11777
|
-
* secure_cookie: true
|
|
11778
|
-
* });
|
|
11779
|
-
*
|
|
11780
|
-
* @param {Object} [options] A dictionary of config options to override
|
|
11781
|
-
* @param {boolean} [options.enable_persistence=true] If true, will re-enable sdk persistence
|
|
11782
|
-
* @param {string} [options.persistence_type=localStorage] Persistence mechanism used - cookie or localStorage - falls back to cookie if localStorage is unavailable
|
|
11783
|
-
* @param {string} [options.cookie_prefix=__mp_opt_in_out] Custom prefix to be used in the cookie/localstorage name
|
|
11784
|
-
* @param {Number} [options.cookie_expiration] Number of days until the opt-in cookie expires (overrides value specified in this Mixpanel instance's config)
|
|
11785
|
-
* @param {string} [options.cookie_domain] Custom cookie domain (overrides value specified in this Mixpanel instance's config)
|
|
11786
|
-
* @param {boolean} [options.cross_site_cookie] Whether the opt-in cookie is set as cross-site-enabled (overrides value specified in this Mixpanel instance's config)
|
|
11787
|
-
* @param {boolean} [options.cross_subdomain_cookie] Whether the opt-in cookie is set as cross-subdomain or not (overrides value specified in this Mixpanel instance's config)
|
|
11788
|
-
* @param {boolean} [options.secure_cookie] Whether the opt-in cookie is set as secure or not (overrides value specified in this Mixpanel instance's config)
|
|
11789
|
-
*/
|
|
11790
|
-
MixpanelLib.prototype.clear_opt_in_out_tracking = function(options) {
|
|
11791
|
-
options = _.extend({
|
|
11792
|
-
'enable_persistence': true
|
|
11793
|
-
}, options);
|
|
11794
|
-
|
|
11795
|
-
this._gdpr_call_func(clearOptInOut, options);
|
|
11796
|
-
this._gdpr_update_persistence(options);
|
|
11797
|
-
};
|
|
11798
|
-
|
|
11799
|
-
MixpanelLib.prototype.report_error = function(msg, err) {
|
|
11800
|
-
console$1.error.apply(console$1.error, arguments);
|
|
11801
|
-
try {
|
|
11802
|
-
if (!err && !(msg instanceof Error)) {
|
|
11803
|
-
msg = new Error(msg);
|
|
11804
|
-
}
|
|
11805
|
-
this.get_config('error_reporter')(msg, err);
|
|
11806
|
-
} catch(err) {
|
|
11807
|
-
console$1.error(err);
|
|
11808
|
-
}
|
|
11809
|
-
};
|
|
11810
|
-
|
|
11811
|
-
// EXPORTS (for closure compiler)
|
|
11812
|
-
|
|
11813
|
-
// MixpanelLib Exports
|
|
11814
|
-
MixpanelLib.prototype['init'] = MixpanelLib.prototype.init;
|
|
11815
|
-
MixpanelLib.prototype['reset'] = MixpanelLib.prototype.reset;
|
|
11816
|
-
MixpanelLib.prototype['disable'] = MixpanelLib.prototype.disable;
|
|
11817
|
-
MixpanelLib.prototype['time_event'] = MixpanelLib.prototype.time_event;
|
|
11818
|
-
MixpanelLib.prototype['track'] = MixpanelLib.prototype.track;
|
|
11819
|
-
MixpanelLib.prototype['track_links'] = MixpanelLib.prototype.track_links;
|
|
11820
|
-
MixpanelLib.prototype['track_forms'] = MixpanelLib.prototype.track_forms;
|
|
11821
|
-
MixpanelLib.prototype['track_pageview'] = MixpanelLib.prototype.track_pageview;
|
|
11822
|
-
MixpanelLib.prototype['register'] = MixpanelLib.prototype.register;
|
|
11823
|
-
MixpanelLib.prototype['register_once'] = MixpanelLib.prototype.register_once;
|
|
11824
|
-
MixpanelLib.prototype['unregister'] = MixpanelLib.prototype.unregister;
|
|
11825
|
-
MixpanelLib.prototype['identify'] = MixpanelLib.prototype.identify;
|
|
11826
|
-
MixpanelLib.prototype['alias'] = MixpanelLib.prototype.alias;
|
|
11827
|
-
MixpanelLib.prototype['name_tag'] = MixpanelLib.prototype.name_tag;
|
|
11828
|
-
MixpanelLib.prototype['set_config'] = MixpanelLib.prototype.set_config;
|
|
11829
|
-
MixpanelLib.prototype['get_config'] = MixpanelLib.prototype.get_config;
|
|
11830
|
-
MixpanelLib.prototype['get_property'] = MixpanelLib.prototype.get_property;
|
|
11831
|
-
MixpanelLib.prototype['get_distinct_id'] = MixpanelLib.prototype.get_distinct_id;
|
|
11832
|
-
MixpanelLib.prototype['toString'] = MixpanelLib.prototype.toString;
|
|
11833
|
-
MixpanelLib.prototype['opt_out_tracking'] = MixpanelLib.prototype.opt_out_tracking;
|
|
11834
|
-
MixpanelLib.prototype['opt_in_tracking'] = MixpanelLib.prototype.opt_in_tracking;
|
|
11835
|
-
MixpanelLib.prototype['has_opted_out_tracking'] = MixpanelLib.prototype.has_opted_out_tracking;
|
|
11836
|
-
MixpanelLib.prototype['has_opted_in_tracking'] = MixpanelLib.prototype.has_opted_in_tracking;
|
|
11837
|
-
MixpanelLib.prototype['clear_opt_in_out_tracking'] = MixpanelLib.prototype.clear_opt_in_out_tracking;
|
|
11838
|
-
MixpanelLib.prototype['get_group'] = MixpanelLib.prototype.get_group;
|
|
11839
|
-
MixpanelLib.prototype['set_group'] = MixpanelLib.prototype.set_group;
|
|
11840
|
-
MixpanelLib.prototype['add_group'] = MixpanelLib.prototype.add_group;
|
|
11841
|
-
MixpanelLib.prototype['remove_group'] = MixpanelLib.prototype.remove_group;
|
|
11842
|
-
MixpanelLib.prototype['track_with_groups'] = MixpanelLib.prototype.track_with_groups;
|
|
11843
|
-
MixpanelLib.prototype['start_batch_senders'] = MixpanelLib.prototype.start_batch_senders;
|
|
11844
|
-
MixpanelLib.prototype['stop_batch_senders'] = MixpanelLib.prototype.stop_batch_senders;
|
|
11845
|
-
|
|
11846
|
-
// MixpanelPersistence Exports
|
|
11847
|
-
MixpanelPersistence.prototype['properties'] = MixpanelPersistence.prototype.properties;
|
|
11848
|
-
MixpanelPersistence.prototype['update_search_keyword'] = MixpanelPersistence.prototype.update_search_keyword;
|
|
11849
|
-
MixpanelPersistence.prototype['update_referrer_info'] = MixpanelPersistence.prototype.update_referrer_info;
|
|
11850
|
-
MixpanelPersistence.prototype['get_cross_subdomain'] = MixpanelPersistence.prototype.get_cross_subdomain;
|
|
11851
|
-
MixpanelPersistence.prototype['clear'] = MixpanelPersistence.prototype.clear;
|
|
11852
|
-
|
|
11853
|
-
|
|
11854
|
-
var instances = {};
|
|
11855
|
-
var extend_mp = function() {
|
|
11856
|
-
// add all the sub mixpanel instances
|
|
11857
|
-
_.each(instances, function(instance, name) {
|
|
11858
|
-
if (name !== PRIMARY_INSTANCE_NAME) { mixpanel_master[name] = instance; }
|
|
11859
|
-
});
|
|
11860
|
-
|
|
11861
|
-
// add private functions as _
|
|
11862
|
-
mixpanel_master['_'] = _;
|
|
11863
|
-
};
|
|
11864
|
-
|
|
11865
|
-
var override_mp_init_func = function() {
|
|
11866
|
-
// we override the snippets init function to handle the case where a
|
|
11867
|
-
// user initializes the mixpanel library after the script loads & runs
|
|
11868
|
-
mixpanel_master['init'] = function(token, config, name) {
|
|
11869
|
-
if (name) {
|
|
11870
|
-
// initialize a sub library
|
|
11871
|
-
if (!mixpanel_master[name]) {
|
|
11872
|
-
mixpanel_master[name] = instances[name] = create_mplib(token, config, name);
|
|
11873
|
-
mixpanel_master[name]._loaded();
|
|
11874
|
-
}
|
|
11875
|
-
return mixpanel_master[name];
|
|
11876
|
-
} else {
|
|
11877
|
-
var instance = mixpanel_master;
|
|
11878
|
-
|
|
11879
|
-
if (instances[PRIMARY_INSTANCE_NAME]) {
|
|
11880
|
-
// main mixpanel lib already initialized
|
|
11881
|
-
instance = instances[PRIMARY_INSTANCE_NAME];
|
|
11882
|
-
} else if (token) {
|
|
11883
|
-
// intialize the main mixpanel lib
|
|
11884
|
-
instance = create_mplib(token, config, PRIMARY_INSTANCE_NAME);
|
|
11885
|
-
instance._loaded();
|
|
11886
|
-
instances[PRIMARY_INSTANCE_NAME] = instance;
|
|
11887
|
-
}
|
|
11888
|
-
|
|
11889
|
-
mixpanel_master = instance;
|
|
11890
|
-
if (init_type === INIT_SNIPPET) {
|
|
11891
|
-
window$1[PRIMARY_INSTANCE_NAME] = mixpanel_master;
|
|
11892
|
-
}
|
|
11893
|
-
extend_mp();
|
|
11894
|
-
}
|
|
11895
|
-
};
|
|
11896
|
-
};
|
|
11897
|
-
|
|
11898
|
-
var add_dom_loaded_handler = function() {
|
|
11899
|
-
// Cross browser DOM Loaded support
|
|
11900
|
-
function dom_loaded_handler() {
|
|
11901
|
-
// function flag since we only want to execute this once
|
|
11902
|
-
if (dom_loaded_handler.done) { return; }
|
|
11903
|
-
dom_loaded_handler.done = true;
|
|
11904
|
-
|
|
11905
|
-
DOM_LOADED = true;
|
|
11906
|
-
ENQUEUE_REQUESTS = false;
|
|
11907
|
-
|
|
11908
|
-
_.each(instances, function(inst) {
|
|
11909
|
-
inst._dom_loaded();
|
|
11910
|
-
});
|
|
11911
|
-
}
|
|
11912
|
-
|
|
11913
|
-
function do_scroll_check() {
|
|
11914
|
-
try {
|
|
11915
|
-
document$1.documentElement.doScroll('left');
|
|
11916
|
-
} catch(e) {
|
|
11917
|
-
setTimeout(do_scroll_check, 1);
|
|
11918
|
-
return;
|
|
11919
|
-
}
|
|
11920
|
-
|
|
11921
|
-
dom_loaded_handler();
|
|
11922
|
-
}
|
|
11923
|
-
|
|
11924
|
-
if (document$1.addEventListener) {
|
|
11925
|
-
if (document$1.readyState === 'complete') {
|
|
11926
|
-
// safari 4 can fire the DOMContentLoaded event before loading all
|
|
11927
|
-
// external JS (including this file). you will see some copypasta
|
|
11928
|
-
// on the internet that checks for 'complete' and 'loaded', but
|
|
11929
|
-
// 'loaded' is an IE thing
|
|
11930
|
-
dom_loaded_handler();
|
|
11931
|
-
} else {
|
|
11932
|
-
document$1.addEventListener('DOMContentLoaded', dom_loaded_handler, false);
|
|
11933
|
-
}
|
|
11934
|
-
} else if (document$1.attachEvent) {
|
|
11935
|
-
// IE
|
|
11936
|
-
document$1.attachEvent('onreadystatechange', dom_loaded_handler);
|
|
11937
|
-
|
|
11938
|
-
// check to make sure we arn't in a frame
|
|
11939
|
-
var toplevel = false;
|
|
11940
|
-
try {
|
|
11941
|
-
toplevel = window$1.frameElement === null;
|
|
11942
|
-
} catch(e) {
|
|
11943
|
-
// noop
|
|
11944
|
-
}
|
|
11945
|
-
|
|
11946
|
-
if (document$1.documentElement.doScroll && toplevel) {
|
|
11947
|
-
do_scroll_check();
|
|
11948
|
-
}
|
|
11949
|
-
}
|
|
11950
|
-
|
|
11951
|
-
// fallback handler, always will work
|
|
11952
|
-
_.register_event(window$1, 'load', dom_loaded_handler, true);
|
|
11953
|
-
};
|
|
11954
|
-
|
|
11955
|
-
function init_as_module() {
|
|
11956
|
-
init_type = INIT_MODULE;
|
|
11957
|
-
mixpanel_master = new MixpanelLib();
|
|
11958
|
-
|
|
11959
|
-
override_mp_init_func();
|
|
11960
|
-
mixpanel_master['init']();
|
|
11961
|
-
add_dom_loaded_handler();
|
|
11962
|
-
|
|
11963
|
-
return mixpanel_master;
|
|
11964
|
-
}
|
|
11965
|
-
|
|
11966
|
-
var mixpanel = init_as_module();
|
|
11967
|
-
|
|
11968
|
-
var mixpanel_cjs = mixpanel;
|
|
11969
|
-
|
|
11970
|
-
var mixpanel$1 = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.assign(/*#__PURE__*/Object.create(null), mixpanel_cjs, {
|
|
11971
|
-
'default': mixpanel_cjs
|
|
11972
|
-
}));
|
|
11973
|
-
|
|
11974
|
-
// Needed to avoid error in CJS builds on some bundlers.
|
|
11975
|
-
const mixpanelLib = mixpanel_cjs || mixpanel$1;
|
|
11976
|
-
let mixpanelInstance;
|
|
11977
|
-
const MIXPANEL_EVENT = {
|
|
11978
|
-
VISUAL_SDK_RENDER_START: 'visual-sdk-render-start',
|
|
11979
|
-
VISUAL_SDK_CALLED_INIT: 'visual-sdk-called-init',
|
|
11980
|
-
VISUAL_SDK_RENDER_COMPLETE: 'visual-sdk-render-complete',
|
|
11981
|
-
VISUAL_SDK_RENDER_FAILED: 'visual-sdk-render-failed',
|
|
11982
|
-
VISUAL_SDK_TRIGGER: 'visual-sdk-trigger',
|
|
11983
|
-
VISUAL_SDK_ON: 'visual-sdk-on',
|
|
11984
|
-
VISUAL_SDK_IFRAME_LOAD_PERFORMANCE: 'visual-sdk-iframe-load-performance',
|
|
11985
|
-
VISUAL_SDK_EMBED_CREATE: 'visual-sdk-embed-create',
|
|
11986
|
-
VERCEL_INTEGRATION_COMPLETED: 'vercel-integration-completed',
|
|
11987
|
-
};
|
|
11988
|
-
let isMixpanelInitialized = false;
|
|
11989
|
-
let eventQueue = [];
|
|
11990
|
-
/**
|
|
11991
|
-
* Pushes the event with its Property key-value map to mixpanel.
|
|
11992
|
-
*
|
|
11993
|
-
* @param eventId
|
|
11994
|
-
* @param eventProps
|
|
11995
|
-
*/
|
|
11996
|
-
function uploadMixpanelEvent(eventId, eventProps = {}) {
|
|
11997
|
-
if (!isMixpanelInitialized) {
|
|
11998
|
-
eventQueue.push({ eventId, eventProps });
|
|
11999
|
-
return;
|
|
12000
|
-
}
|
|
12001
|
-
mixpanelInstance.track(eventId, eventProps);
|
|
12002
|
-
}
|
|
12003
|
-
/**
|
|
12004
|
-
*
|
|
12005
|
-
*/
|
|
12006
|
-
function emptyQueue() {
|
|
12007
|
-
if (!isMixpanelInitialized) {
|
|
12008
|
-
return;
|
|
12009
|
-
}
|
|
12010
|
-
eventQueue.forEach((event) => {
|
|
12011
|
-
uploadMixpanelEvent(event.eventId, event.eventProps);
|
|
12012
|
-
});
|
|
12013
|
-
eventQueue = [];
|
|
12014
|
-
}
|
|
12015
|
-
/**
|
|
12016
|
-
*
|
|
12017
|
-
* @param sessionInfo
|
|
12018
|
-
*/
|
|
12019
|
-
function initMixpanel(sessionInfo) {
|
|
12020
|
-
var _a;
|
|
12021
|
-
if (!sessionInfo || !sessionInfo.mixpanelToken) {
|
|
12022
|
-
return;
|
|
12023
|
-
}
|
|
12024
|
-
// On a public cluster the user is anonymous, so don't set the identify to
|
|
12025
|
-
// userGUID
|
|
12026
|
-
const isPublicCluster = !!sessionInfo.isPublicUser;
|
|
12027
|
-
const token = sessionInfo.mixpanelToken;
|
|
12028
|
-
try {
|
|
12029
|
-
if (token) {
|
|
12030
|
-
mixpanelInstance = mixpanelLib.init(token, undefined, 'tsEmbed');
|
|
12031
|
-
if (!isPublicCluster) {
|
|
12032
|
-
mixpanelInstance.identify(sessionInfo.userGUID);
|
|
12033
|
-
}
|
|
12034
|
-
mixpanelInstance.register_once({
|
|
12035
|
-
clusterId: sessionInfo.clusterId,
|
|
12036
|
-
clusterName: sessionInfo.clusterName,
|
|
12037
|
-
releaseVersion: sessionInfo.releaseVersion,
|
|
12038
|
-
hostAppUrl: ((_a = window === null || window === void 0 ? void 0 : window.location) === null || _a === void 0 ? void 0 : _a.host) || '',
|
|
12039
|
-
});
|
|
12040
|
-
isMixpanelInitialized = true;
|
|
12041
|
-
emptyQueue();
|
|
12042
|
-
}
|
|
12043
|
-
}
|
|
12044
|
-
catch (e) {
|
|
12045
|
-
logger.error('Error initializing mixpanel', e);
|
|
12046
|
-
}
|
|
12047
|
-
}
|
|
12048
|
-
|
|
12049
|
-
let config = {};
|
|
12050
|
-
/**
|
|
12051
|
-
* Gets the configuration embed was initialized with.
|
|
12052
|
-
*
|
|
12053
|
-
* @returns {@link EmbedConfig} The configuration embed was initialized with.
|
|
12054
|
-
* @version SDK: 1.19.0 | ThoughtSpot: *
|
|
12055
|
-
* @group Global methods
|
|
12056
|
-
*/
|
|
12057
|
-
const getEmbedConfig = () => config;
|
|
12058
|
-
|
|
12059
|
-
/**
|
|
12060
|
-
* Fetch wrapper that adds the authentication token to the request.
|
|
12061
|
-
* Use this to call the ThoughtSpot APIs when using the visual embed sdk.
|
|
12062
|
-
*
|
|
12063
|
-
* @param input
|
|
12064
|
-
* @param init
|
|
12065
|
-
* @version SDK: 1.28.0
|
|
12066
|
-
* @group Global methods
|
|
12067
|
-
*/
|
|
12068
|
-
const tokenizedFetch = async (input, init) => {
|
|
12069
|
-
const embedConfig = getEmbedConfig();
|
|
12070
|
-
if (embedConfig.authType !== AuthType.TrustedAuthTokenCookieless) {
|
|
12071
|
-
return fetch(input, init);
|
|
12072
|
-
}
|
|
12073
|
-
const req = new Request(input, init);
|
|
12074
|
-
const authToken = await getAuthenticationToken(embedConfig);
|
|
12075
|
-
if (authToken) {
|
|
12076
|
-
req.headers.append('Authorization', `Bearer ${authToken}`);
|
|
12077
|
-
}
|
|
12078
|
-
return fetch(req);
|
|
12079
|
-
};
|
|
12080
|
-
|
|
12081
|
-
/**
|
|
12082
|
-
*
|
|
12083
|
-
* @param url
|
|
12084
|
-
* @param options
|
|
12085
|
-
*/
|
|
12086
|
-
function tokenisedFailureLoggedFetch(url, options = {}) {
|
|
12087
|
-
return tokenizedFetch(url, options).then(async (r) => {
|
|
12088
|
-
var _a;
|
|
12089
|
-
if (!r.ok && r.type !== 'opaqueredirect' && r.type !== 'opaque') {
|
|
12090
|
-
logger.error('Failure', await ((_a = r.text) === null || _a === void 0 ? void 0 : _a.call(r)));
|
|
12091
|
-
}
|
|
12092
|
-
return r;
|
|
12093
|
-
});
|
|
12094
|
-
}
|
|
12095
|
-
/**
|
|
12096
|
-
*
|
|
12097
|
-
* @param authVerificationUrl
|
|
12098
|
-
*/
|
|
12099
|
-
function fetchSessionInfoService(authVerificationUrl) {
|
|
12100
|
-
return tokenisedFailureLoggedFetch(authVerificationUrl, {
|
|
12101
|
-
credentials: 'include',
|
|
12102
|
-
});
|
|
12103
|
-
}
|
|
12104
|
-
|
|
12105
|
-
// eslint-disable-next-line import/no-mutable-exports
|
|
12106
|
-
let loggedInStatus = false;
|
|
12107
|
-
// eslint-disable-next-line import/no-mutable-exports
|
|
12108
|
-
let samlAuthWindow = null;
|
|
12109
|
-
// eslint-disable-next-line import/no-mutable-exports
|
|
12110
|
-
let samlCompletionPromise = null;
|
|
12111
|
-
let sessionInfo = null;
|
|
12112
|
-
let sessionInfoResolver = null;
|
|
12113
|
-
const sessionInfoPromise = new Promise((resolve) => {
|
|
12114
|
-
sessionInfoResolver = resolve;
|
|
12115
|
-
});
|
|
12116
|
-
let releaseVersion = '';
|
|
12117
|
-
const SSO_REDIRECTION_MARKER_GUID = '5e16222e-ef02-43e9-9fbd-24226bf3ce5b';
|
|
12118
|
-
/**
|
|
12119
|
-
* Enum for auth failure types. This is the parameter passed to the listner
|
|
12120
|
-
* of {@link AuthStatus.FAILURE}.
|
|
12121
|
-
*
|
|
12122
|
-
* @group Authentication / Init
|
|
12123
|
-
*/
|
|
12124
|
-
var AuthFailureType;
|
|
12125
|
-
(function (AuthFailureType) {
|
|
12126
|
-
AuthFailureType["SDK"] = "SDK";
|
|
12127
|
-
AuthFailureType["NO_COOKIE_ACCESS"] = "NO_COOKIE_ACCESS";
|
|
12128
|
-
AuthFailureType["EXPIRY"] = "EXPIRY";
|
|
12129
|
-
AuthFailureType["OTHER"] = "OTHER";
|
|
12130
|
-
})(AuthFailureType || (AuthFailureType = {}));
|
|
12131
|
-
/**
|
|
12132
|
-
* Enum for auth status emitted by the emitter returned from {@link init}.
|
|
12133
|
-
*
|
|
12134
|
-
* @group Authentication / Init
|
|
12135
|
-
*/
|
|
12136
|
-
var AuthStatus;
|
|
12137
|
-
(function (AuthStatus) {
|
|
12138
|
-
/**
|
|
12139
|
-
* Emits when the SDK fails to authenticate
|
|
12140
|
-
*/
|
|
12141
|
-
AuthStatus["FAILURE"] = "FAILURE";
|
|
12142
|
-
/**
|
|
12143
|
-
* Emits when the SDK authenticates successfully
|
|
12144
|
-
*/
|
|
12145
|
-
AuthStatus["SDK_SUCCESS"] = "SDK_SUCCESS";
|
|
12146
|
-
/**
|
|
12147
|
-
* Emits when the app sends an authentication success message
|
|
12148
|
-
*/
|
|
12149
|
-
AuthStatus["SUCCESS"] = "SUCCESS";
|
|
12150
|
-
/**
|
|
12151
|
-
* Emits when a user logs out
|
|
12152
|
-
*/
|
|
12153
|
-
AuthStatus["LOGOUT"] = "LOGOUT";
|
|
12154
|
-
/**
|
|
12155
|
-
* Emitted when inPopup is true in the SAMLRedirect flow and the
|
|
12156
|
-
* popup is waiting to be triggered either programmatically
|
|
12157
|
-
* or by the trigger button.
|
|
12158
|
-
*
|
|
12159
|
-
* @version SDK: 1.19.0
|
|
12160
|
-
*/
|
|
12161
|
-
AuthStatus["WAITING_FOR_POPUP"] = "WAITING_FOR_POPUP";
|
|
12162
|
-
})(AuthStatus || (AuthStatus = {}));
|
|
12163
|
-
/**
|
|
12164
|
-
* Events which can be triggered on the emitter returned from {@link init}.
|
|
12165
|
-
*
|
|
12166
|
-
* @group Authentication / Init
|
|
12167
|
-
*/
|
|
12168
|
-
var AuthEvent;
|
|
12169
|
-
(function (AuthEvent) {
|
|
12170
|
-
/**
|
|
12171
|
-
* Manually trigger the SSO popup. This is useful when
|
|
12172
|
-
* authStatus is SAMLRedirect/OIDCRedirect and inPopup is set to true
|
|
12173
|
-
*/
|
|
12174
|
-
AuthEvent["TRIGGER_SSO_POPUP"] = "TRIGGER_SSO_POPUP";
|
|
12175
|
-
})(AuthEvent || (AuthEvent = {}));
|
|
12176
|
-
/**
|
|
12177
|
-
*
|
|
12178
|
-
*/
|
|
12179
|
-
function notifyAuthSDKSuccess() {
|
|
12180
|
-
{
|
|
12181
|
-
logger.error('SDK not initialized');
|
|
12182
|
-
return;
|
|
12183
|
-
}
|
|
12184
|
-
}
|
|
12185
|
-
/**
|
|
12186
|
-
*
|
|
12187
|
-
*/
|
|
12188
|
-
function notifyAuthSuccess() {
|
|
12189
|
-
{
|
|
12190
|
-
logger.error('SDK not initialized');
|
|
12191
|
-
return;
|
|
12192
|
-
}
|
|
12193
|
-
}
|
|
12194
|
-
/**
|
|
12195
|
-
*
|
|
12196
|
-
* @param failureType
|
|
12197
|
-
*/
|
|
12198
|
-
function notifyAuthFailure(failureType) {
|
|
12199
|
-
{
|
|
12200
|
-
logger.error('SDK not initialized');
|
|
12201
|
-
return;
|
|
12202
|
-
}
|
|
12203
|
-
}
|
|
12204
|
-
/**
|
|
12205
|
-
*
|
|
12206
|
-
*/
|
|
12207
|
-
function notifyLogout() {
|
|
12208
|
-
{
|
|
12209
|
-
logger.error('SDK not initialized');
|
|
12210
|
-
return;
|
|
12211
|
-
}
|
|
12212
|
-
}
|
|
12213
|
-
const initSession = (sessionDetails) => {
|
|
12214
|
-
const embedConfig = getEmbedConfig();
|
|
12215
|
-
if (sessionInfo == null) {
|
|
12216
|
-
sessionInfo = sessionDetails;
|
|
12217
|
-
if (!embedConfig.disableSDKTracking) {
|
|
12218
|
-
initMixpanel(sessionInfo);
|
|
12219
|
-
}
|
|
12220
|
-
sessionInfoResolver(sessionInfo);
|
|
12221
|
-
}
|
|
12222
|
-
};
|
|
12223
|
-
const getSessionDetails = (sessionInfoResp) => {
|
|
12224
|
-
const devMixpanelToken = sessionInfoResp.configInfo.mixpanelConfig.devSdkKey;
|
|
12225
|
-
const prodMixpanelToken = sessionInfoResp.configInfo.mixpanelConfig.prodSdkKey;
|
|
12226
|
-
const mixpanelToken = sessionInfoResp.configInfo.mixpanelConfig.production
|
|
12227
|
-
? prodMixpanelToken
|
|
12228
|
-
: devMixpanelToken;
|
|
12229
|
-
return {
|
|
12230
|
-
userGUID: sessionInfoResp.userGUID,
|
|
12231
|
-
mixpanelToken,
|
|
12232
|
-
isPublicUser: sessionInfoResp.configInfo.isPublicUser,
|
|
12233
|
-
releaseVersion: sessionInfoResp.releaseVersion,
|
|
12234
|
-
clusterId: sessionInfoResp.configInfo.selfClusterId,
|
|
12235
|
-
clusterName: sessionInfoResp.configInfo.selfClusterName,
|
|
12236
|
-
...sessionInfoResp,
|
|
12237
|
-
};
|
|
12238
|
-
};
|
|
12239
|
-
/**
|
|
12240
|
-
* Check if we are logged into the ThoughtSpot cluster
|
|
12241
|
-
*
|
|
12242
|
-
* @param thoughtSpotHost The ThoughtSpot cluster hostname or IP
|
|
12243
|
-
*/
|
|
12244
|
-
async function isLoggedIn(thoughtSpotHost) {
|
|
12245
|
-
const authVerificationUrl = `${thoughtSpotHost}${EndPoints.AUTH_VERIFICATION}`;
|
|
12246
|
-
let response = null;
|
|
12247
|
-
try {
|
|
12248
|
-
response = await fetchSessionInfoService(authVerificationUrl);
|
|
12249
|
-
const sessionInfoResp = await response.json();
|
|
12250
|
-
const sessionDetails = getSessionDetails(sessionInfoResp);
|
|
12251
|
-
// Store user session details from session info
|
|
12252
|
-
initSession(sessionDetails);
|
|
12253
|
-
releaseVersion = sessionInfoResp.releaseVersion;
|
|
12254
|
-
}
|
|
12255
|
-
catch (e) {
|
|
12256
|
-
return false;
|
|
12257
|
-
}
|
|
12258
|
-
return response.status === 200;
|
|
12259
|
-
}
|
|
12260
|
-
/**
|
|
12261
|
-
* Return releaseVersion if available
|
|
12262
|
-
*/
|
|
12263
|
-
function getReleaseVersion() {
|
|
12264
|
-
return releaseVersion;
|
|
12265
|
-
}
|
|
12266
|
-
/**
|
|
12267
|
-
* Check if we are stuck at the SSO redirect URL
|
|
12268
|
-
*/
|
|
12269
|
-
function isAtSSORedirectUrl() {
|
|
12270
|
-
return window.location.href.indexOf(SSO_REDIRECTION_MARKER_GUID) >= 0;
|
|
12271
|
-
}
|
|
12272
|
-
/**
|
|
12273
|
-
* Remove the SSO redirect URL marker
|
|
12274
|
-
*/
|
|
12275
|
-
function removeSSORedirectUrlMarker() {
|
|
12276
|
-
// Note (sunny): This will leave a # around even if it was not in the URL
|
|
12277
|
-
// to begin with. Trying to remove the hash by changing window.location will
|
|
12278
|
-
// reload the page which we don't want. We'll live with adding an
|
|
12279
|
-
// unnecessary hash to the parent page URL until we find any use case where
|
|
12280
|
-
// that creates an issue.
|
|
12281
|
-
window.location.hash = window.location.hash.replace(SSO_REDIRECTION_MARKER_GUID, '');
|
|
12282
|
-
}
|
|
12283
|
-
/**
|
|
12284
|
-
* Perform token based authentication
|
|
12285
|
-
*
|
|
12286
|
-
* @param embedConfig The embed configuration
|
|
12287
|
-
*/
|
|
12288
|
-
const doTokenAuth = async (embedConfig) => {
|
|
12289
|
-
const { thoughtSpotHost, username, authEndpoint, getAuthToken, } = embedConfig;
|
|
12290
|
-
if (!authEndpoint && !getAuthToken) {
|
|
12291
|
-
throw new Error('Either auth endpoint or getAuthToken function must be provided');
|
|
12292
|
-
}
|
|
12293
|
-
loggedInStatus = await isLoggedIn(thoughtSpotHost);
|
|
12294
|
-
if (!loggedInStatus) {
|
|
12295
|
-
const authToken = await getAuthenticationToken(embedConfig);
|
|
12296
|
-
let resp;
|
|
12297
|
-
try {
|
|
12298
|
-
resp = await fetchAuthPostService(thoughtSpotHost, username, authToken);
|
|
12299
|
-
}
|
|
12300
|
-
catch (e) {
|
|
12301
|
-
resp = await fetchAuthService(thoughtSpotHost, username, authToken);
|
|
12302
|
-
}
|
|
12303
|
-
// token login issues a 302 when successful
|
|
12304
|
-
loggedInStatus = resp.ok || resp.type === 'opaqueredirect';
|
|
12305
|
-
if (loggedInStatus && embedConfig.detectCookieAccessSlow) {
|
|
12306
|
-
// When 3rd party cookie access is blocked, this will fail because
|
|
12307
|
-
// cookies will not be sent with the call.
|
|
12308
|
-
loggedInStatus = await isLoggedIn(thoughtSpotHost);
|
|
12309
|
-
}
|
|
12310
|
-
}
|
|
12311
|
-
return loggedInStatus;
|
|
12312
|
-
};
|
|
12313
|
-
/**
|
|
12314
|
-
* Validate embedConfig parameters required for cookielessTokenAuth
|
|
12315
|
-
*
|
|
12316
|
-
* @param embedConfig The embed configuration
|
|
12317
|
-
*/
|
|
12318
|
-
const doCookielessTokenAuth = async (embedConfig) => {
|
|
12319
|
-
const { authEndpoint, getAuthToken } = embedConfig;
|
|
12320
|
-
if (!authEndpoint && !getAuthToken) {
|
|
12321
|
-
throw new Error('Either auth endpoint or getAuthToken function must be provided');
|
|
12322
|
-
}
|
|
12323
|
-
let authSuccess = false;
|
|
12324
|
-
try {
|
|
12325
|
-
const authToken = await getAuthenticationToken(embedConfig);
|
|
12326
|
-
if (authToken) {
|
|
12327
|
-
authSuccess = true;
|
|
12328
|
-
}
|
|
12329
|
-
}
|
|
12330
|
-
catch {
|
|
12331
|
-
authSuccess = false;
|
|
12332
|
-
}
|
|
12333
|
-
return authSuccess;
|
|
12334
|
-
};
|
|
12335
|
-
/**
|
|
12336
|
-
* Perform basic authentication to the ThoughtSpot cluster using the cluster
|
|
12337
|
-
* credentials.
|
|
12338
|
-
*
|
|
12339
|
-
* Warning: This feature is primarily intended for developer testing. It is
|
|
12340
|
-
* strongly advised not to use this authentication method in production.
|
|
12341
|
-
*
|
|
12342
|
-
* @param embedConfig The embed configuration
|
|
12343
|
-
*/
|
|
12344
|
-
const doBasicAuth = async (embedConfig) => {
|
|
12345
|
-
const { thoughtSpotHost, username, password } = embedConfig;
|
|
12346
|
-
const loggedIn = await isLoggedIn(thoughtSpotHost);
|
|
12347
|
-
if (!loggedIn) {
|
|
12348
|
-
const response = await fetchBasicAuthService(thoughtSpotHost, username, password);
|
|
12349
|
-
loggedInStatus = response.ok;
|
|
12350
|
-
if (embedConfig.detectCookieAccessSlow) {
|
|
12351
|
-
loggedInStatus = await isLoggedIn(thoughtSpotHost);
|
|
12352
|
-
}
|
|
12353
|
-
}
|
|
12354
|
-
else {
|
|
12355
|
-
loggedInStatus = true;
|
|
12356
|
-
}
|
|
12357
|
-
return loggedInStatus;
|
|
12358
|
-
};
|
|
12359
|
-
/**
|
|
12360
|
-
*
|
|
12361
|
-
* @param ssoURL
|
|
12362
|
-
* @param triggerContainer
|
|
12363
|
-
* @param triggerText
|
|
12364
|
-
*/
|
|
12365
|
-
async function samlPopupFlow(ssoURL, triggerContainer, triggerText) {
|
|
12366
|
-
const openPopup = () => {
|
|
12367
|
-
if (samlAuthWindow === null || samlAuthWindow.closed) {
|
|
12368
|
-
samlAuthWindow = window.open(ssoURL, '_blank', 'location=no,height=570,width=520,scrollbars=yes,status=yes');
|
|
12369
|
-
}
|
|
12370
|
-
else {
|
|
12371
|
-
samlAuthWindow.focus();
|
|
12372
|
-
}
|
|
12373
|
-
};
|
|
12374
|
-
const containerEl = getDOMNode(triggerContainer);
|
|
12375
|
-
if (containerEl) {
|
|
12376
|
-
containerEl.innerHTML = '<button id="ts-auth-btn" class="ts-auth-btn" style="margin: auto;"></button>';
|
|
12377
|
-
const authElem = document.getElementById('ts-auth-btn');
|
|
12378
|
-
authElem.textContent = triggerText;
|
|
12379
|
-
authElem.addEventListener('click', openPopup, { once: true });
|
|
12380
|
-
}
|
|
12381
|
-
samlCompletionPromise = samlCompletionPromise
|
|
12382
|
-
|| new Promise((resolve, reject) => {
|
|
12383
|
-
window.addEventListener('message', (e) => {
|
|
12384
|
-
if (e.data.type === exports.EmbedEvent.SAMLComplete) {
|
|
12385
|
-
e.source.close();
|
|
12386
|
-
resolve();
|
|
12387
|
-
}
|
|
12388
|
-
});
|
|
12389
|
-
});
|
|
12390
|
-
return samlCompletionPromise;
|
|
12391
|
-
}
|
|
12392
|
-
/**
|
|
12393
|
-
* Perform SAML authentication
|
|
12394
|
-
*
|
|
12395
|
-
* @param embedConfig The embed configuration
|
|
12396
|
-
* @param ssoEndPoint
|
|
12397
|
-
*/
|
|
12398
|
-
const doSSOAuth = async (embedConfig, ssoEndPoint) => {
|
|
12399
|
-
const { thoughtSpotHost } = embedConfig;
|
|
12400
|
-
const loggedIn = await isLoggedIn(thoughtSpotHost);
|
|
12401
|
-
if (loggedIn) {
|
|
12402
|
-
if (isAtSSORedirectUrl()) {
|
|
12403
|
-
removeSSORedirectUrlMarker();
|
|
12404
|
-
}
|
|
12405
|
-
loggedInStatus = true;
|
|
12406
|
-
return;
|
|
12407
|
-
}
|
|
12408
|
-
// we have already tried authentication and it did not succeed, restore
|
|
12409
|
-
// the current URL to the original one and invoke the callback.
|
|
12410
|
-
if (isAtSSORedirectUrl()) {
|
|
12411
|
-
removeSSORedirectUrlMarker();
|
|
12412
|
-
loggedInStatus = false;
|
|
12413
|
-
return;
|
|
12414
|
-
}
|
|
12415
|
-
const ssoURL = `${thoughtSpotHost}${ssoEndPoint}`;
|
|
12416
|
-
if (embedConfig.inPopup) {
|
|
12417
|
-
await samlPopupFlow(ssoURL, embedConfig.authTriggerContainer, embedConfig.authTriggerText);
|
|
12418
|
-
loggedInStatus = await isLoggedIn(thoughtSpotHost);
|
|
12419
|
-
return;
|
|
12420
|
-
}
|
|
12421
|
-
window.location.href = ssoURL;
|
|
12422
|
-
};
|
|
12423
|
-
const doSamlAuth = async (embedConfig) => {
|
|
12424
|
-
const { thoughtSpotHost } = embedConfig;
|
|
12425
|
-
// redirect for SSO, when the SSO authentication is done, this page will be
|
|
12426
|
-
// loaded again and the same JS will execute again.
|
|
12427
|
-
const ssoRedirectUrl = embedConfig.inPopup
|
|
12428
|
-
? `${thoughtSpotHost}/v2/#/embed/saml-complete`
|
|
12429
|
-
: getRedirectUrl(window.location.href, SSO_REDIRECTION_MARKER_GUID, embedConfig.redirectPath);
|
|
12430
|
-
// bring back the page to the same URL
|
|
12431
|
-
const ssoEndPoint = `${EndPoints.SAML_LOGIN_TEMPLATE(encodeURIComponent(ssoRedirectUrl))}`;
|
|
12432
|
-
await doSSOAuth(embedConfig, ssoEndPoint);
|
|
12433
|
-
return loggedInStatus;
|
|
12434
|
-
};
|
|
12435
|
-
const doOIDCAuth = async (embedConfig) => {
|
|
12436
|
-
const { thoughtSpotHost } = embedConfig;
|
|
12437
|
-
// redirect for SSO, when the SSO authentication is done, this page will be
|
|
12438
|
-
// loaded again and the same JS will execute again.
|
|
12439
|
-
const ssoRedirectUrl = embedConfig.noRedirect || embedConfig.inPopup
|
|
12440
|
-
? `${thoughtSpotHost}/v2/#/embed/saml-complete`
|
|
12441
|
-
: getRedirectUrl(window.location.href, SSO_REDIRECTION_MARKER_GUID, embedConfig.redirectPath);
|
|
12442
|
-
// bring back the page to the same URL
|
|
12443
|
-
const ssoEndPoint = `${EndPoints.OIDC_LOGIN_TEMPLATE(encodeURIComponent(ssoRedirectUrl))}`;
|
|
12444
|
-
await doSSOAuth(embedConfig, ssoEndPoint);
|
|
12445
|
-
return loggedInStatus;
|
|
12446
|
-
};
|
|
12447
|
-
/**
|
|
12448
|
-
* Perform authentication on the ThoughtSpot cluster
|
|
12449
|
-
*
|
|
12450
|
-
* @param embedConfig The embed configuration
|
|
12451
|
-
*/
|
|
12452
|
-
const authenticate = async (embedConfig) => {
|
|
12453
|
-
const { authType } = embedConfig;
|
|
12454
|
-
switch (authType) {
|
|
12455
|
-
case AuthType.SSO:
|
|
12456
|
-
case AuthType.SAMLRedirect:
|
|
12457
|
-
case AuthType.SAML:
|
|
12458
|
-
return doSamlAuth(embedConfig);
|
|
12459
|
-
case AuthType.OIDC:
|
|
12460
|
-
case AuthType.OIDCRedirect:
|
|
12461
|
-
return doOIDCAuth(embedConfig);
|
|
12462
|
-
case AuthType.AuthServer:
|
|
12463
|
-
case AuthType.TrustedAuthToken:
|
|
12464
|
-
return doTokenAuth(embedConfig);
|
|
12465
|
-
case AuthType.TrustedAuthTokenCookieless:
|
|
12466
|
-
return doCookielessTokenAuth(embedConfig);
|
|
12467
|
-
case AuthType.Basic:
|
|
12468
|
-
return doBasicAuth(embedConfig);
|
|
12469
|
-
default:
|
|
12470
|
-
return Promise.resolve(true);
|
|
12471
|
-
}
|
|
12264
|
+
// check if localStorage can be used for recording opt out status, fall back to cookie if not
|
|
12265
|
+
if (!_.localStorage.is_supported()) {
|
|
12266
|
+
options['persistence_type'] = 'cookie';
|
|
12267
|
+
}
|
|
12268
|
+
|
|
12269
|
+
return func(this.get_config('token'), {
|
|
12270
|
+
track: options['track'],
|
|
12271
|
+
trackEventName: options['track_event_name'],
|
|
12272
|
+
trackProperties: options['track_properties'],
|
|
12273
|
+
persistenceType: options['persistence_type'],
|
|
12274
|
+
persistencePrefix: options['cookie_prefix'],
|
|
12275
|
+
cookieDomain: options['cookie_domain'],
|
|
12276
|
+
cookieExpiration: options['cookie_expiration'],
|
|
12277
|
+
crossSiteCookie: options['cross_site_cookie'],
|
|
12278
|
+
crossSubdomainCookie: options['cross_subdomain_cookie'],
|
|
12279
|
+
secureCookie: options['secure_cookie'],
|
|
12280
|
+
ignoreDnt: options['ignore_dnt']
|
|
12281
|
+
});
|
|
12472
12282
|
};
|
|
12473
12283
|
|
|
12474
|
-
|
|
12475
|
-
|
|
12476
|
-
|
|
12477
|
-
|
|
12478
|
-
|
|
12479
|
-
|
|
12284
|
+
/**
|
|
12285
|
+
* Opt the user in to data tracking and cookies/localstorage for this Mixpanel instance
|
|
12286
|
+
*
|
|
12287
|
+
* ### Usage
|
|
12288
|
+
*
|
|
12289
|
+
* // opt user in
|
|
12290
|
+
* mixpanel.opt_in_tracking();
|
|
12291
|
+
*
|
|
12292
|
+
* // opt user in with specific event name, properties, cookie configuration
|
|
12293
|
+
* mixpanel.opt_in_tracking({
|
|
12294
|
+
* track_event_name: 'User opted in',
|
|
12295
|
+
* track_event_properties: {
|
|
12296
|
+
* 'Email': 'jdoe@example.com'
|
|
12297
|
+
* },
|
|
12298
|
+
* cookie_expiration: 30,
|
|
12299
|
+
* secure_cookie: true
|
|
12300
|
+
* });
|
|
12301
|
+
*
|
|
12302
|
+
* @param {Object} [options] A dictionary of config options to override
|
|
12303
|
+
* @param {function} [options.track] Function used for tracking a Mixpanel event to record the opt-in action (default is this Mixpanel instance's track method)
|
|
12304
|
+
* @param {string} [options.track_event_name=$opt_in] Event name to be used for tracking the opt-in action
|
|
12305
|
+
* @param {Object} [options.track_properties] Set of properties to be tracked along with the opt-in action
|
|
12306
|
+
* @param {boolean} [options.enable_persistence=true] If true, will re-enable sdk persistence
|
|
12307
|
+
* @param {string} [options.persistence_type=localStorage] Persistence mechanism used - cookie or localStorage - falls back to cookie if localStorage is unavailable
|
|
12308
|
+
* @param {string} [options.cookie_prefix=__mp_opt_in_out] Custom prefix to be used in the cookie/localstorage name
|
|
12309
|
+
* @param {Number} [options.cookie_expiration] Number of days until the opt-in cookie expires (overrides value specified in this Mixpanel instance's config)
|
|
12310
|
+
* @param {string} [options.cookie_domain] Custom cookie domain (overrides value specified in this Mixpanel instance's config)
|
|
12311
|
+
* @param {boolean} [options.cross_site_cookie] Whether the opt-in cookie is set as cross-site-enabled (overrides value specified in this Mixpanel instance's config)
|
|
12312
|
+
* @param {boolean} [options.cross_subdomain_cookie] Whether the opt-in cookie is set as cross-subdomain or not (overrides value specified in this Mixpanel instance's config)
|
|
12313
|
+
* @param {boolean} [options.secure_cookie] Whether the opt-in cookie is set as secure or not (overrides value specified in this Mixpanel instance's config)
|
|
12314
|
+
*/
|
|
12315
|
+
MixpanelLib.prototype.opt_in_tracking = function(options) {
|
|
12316
|
+
options = _.extend({
|
|
12317
|
+
'enable_persistence': true
|
|
12318
|
+
}, options);
|
|
12319
|
+
|
|
12320
|
+
this._gdpr_call_func(optIn, options);
|
|
12321
|
+
this._gdpr_update_persistence(options);
|
|
12480
12322
|
};
|
|
12481
12323
|
|
|
12482
|
-
/**
|
|
12483
|
-
*
|
|
12484
|
-
*
|
|
12485
|
-
*
|
|
12486
|
-
*
|
|
12487
|
-
*
|
|
12488
|
-
*
|
|
12489
|
-
|
|
12490
|
-
|
|
12491
|
-
|
|
12492
|
-
|
|
12493
|
-
|
|
12494
|
-
|
|
12495
|
-
|
|
12496
|
-
|
|
12497
|
-
|
|
12498
|
-
*
|
|
12499
|
-
*
|
|
12500
|
-
*
|
|
12501
|
-
* @param config
|
|
12502
|
-
|
|
12503
|
-
|
|
12504
|
-
|
|
12505
|
-
|
|
12506
|
-
|
|
12507
|
-
|
|
12508
|
-
|
|
12509
|
-
|
|
12510
|
-
|
|
12511
|
-
|
|
12512
|
-
|
|
12513
|
-
|
|
12514
|
-
|
|
12515
|
-
|
|
12516
|
-
|
|
12517
|
-
}
|
|
12518
|
-
|
|
12519
|
-
|
|
12520
|
-
|
|
12521
|
-
};
|
|
12522
|
-
|
|
12523
|
-
|
|
12524
|
-
|
|
12525
|
-
|
|
12526
|
-
|
|
12527
|
-
|
|
12528
|
-
|
|
12529
|
-
|
|
12530
|
-
|
|
12531
|
-
|
|
12532
|
-
|
|
12533
|
-
|
|
12534
|
-
|
|
12535
|
-
|
|
12536
|
-
|
|
12537
|
-
|
|
12538
|
-
|
|
12539
|
-
|
|
12540
|
-
|
|
12541
|
-
|
|
12542
|
-
|
|
12543
|
-
|
|
12544
|
-
*
|
|
12545
|
-
|
|
12546
|
-
|
|
12547
|
-
|
|
12324
|
+
/**
|
|
12325
|
+
* Opt the user out of data tracking and cookies/localstorage for this Mixpanel instance
|
|
12326
|
+
*
|
|
12327
|
+
* ### Usage
|
|
12328
|
+
*
|
|
12329
|
+
* // opt user out
|
|
12330
|
+
* mixpanel.opt_out_tracking();
|
|
12331
|
+
*
|
|
12332
|
+
* // opt user out with different cookie configuration from Mixpanel instance
|
|
12333
|
+
* mixpanel.opt_out_tracking({
|
|
12334
|
+
* cookie_expiration: 30,
|
|
12335
|
+
* secure_cookie: true
|
|
12336
|
+
* });
|
|
12337
|
+
*
|
|
12338
|
+
* @param {Object} [options] A dictionary of config options to override
|
|
12339
|
+
* @param {boolean} [options.delete_user=true] If true, will delete the currently identified user's profile and clear all charges after opting the user out
|
|
12340
|
+
* @param {boolean} [options.clear_persistence=true] If true, will delete all data stored by the sdk in persistence
|
|
12341
|
+
* @param {string} [options.persistence_type=localStorage] Persistence mechanism used - cookie or localStorage - falls back to cookie if localStorage is unavailable
|
|
12342
|
+
* @param {string} [options.cookie_prefix=__mp_opt_in_out] Custom prefix to be used in the cookie/localstorage name
|
|
12343
|
+
* @param {Number} [options.cookie_expiration] Number of days until the opt-in cookie expires (overrides value specified in this Mixpanel instance's config)
|
|
12344
|
+
* @param {string} [options.cookie_domain] Custom cookie domain (overrides value specified in this Mixpanel instance's config)
|
|
12345
|
+
* @param {boolean} [options.cross_site_cookie] Whether the opt-in cookie is set as cross-site-enabled (overrides value specified in this Mixpanel instance's config)
|
|
12346
|
+
* @param {boolean} [options.cross_subdomain_cookie] Whether the opt-in cookie is set as cross-subdomain or not (overrides value specified in this Mixpanel instance's config)
|
|
12347
|
+
* @param {boolean} [options.secure_cookie] Whether the opt-in cookie is set as secure or not (overrides value specified in this Mixpanel instance's config)
|
|
12348
|
+
*/
|
|
12349
|
+
MixpanelLib.prototype.opt_out_tracking = function(options) {
|
|
12350
|
+
options = _.extend({
|
|
12351
|
+
'clear_persistence': true,
|
|
12352
|
+
'delete_user': true
|
|
12353
|
+
}, options);
|
|
12354
|
+
|
|
12355
|
+
// delete user and clear charges since these methods may be disabled by opt-out
|
|
12356
|
+
if (options['delete_user'] && this['people'] && this['people']._identify_called()) {
|
|
12357
|
+
this['people'].delete_user();
|
|
12358
|
+
this['people'].clear_charges();
|
|
12359
|
+
}
|
|
12360
|
+
|
|
12361
|
+
this._gdpr_call_func(optOut, options);
|
|
12362
|
+
this._gdpr_update_persistence(options);
|
|
12363
|
+
};
|
|
12364
|
+
|
|
12365
|
+
/**
|
|
12366
|
+
* Check whether the user has opted in to data tracking and cookies/localstorage for this Mixpanel instance
|
|
12367
|
+
*
|
|
12368
|
+
* ### Usage
|
|
12369
|
+
*
|
|
12370
|
+
* var has_opted_in = mixpanel.has_opted_in_tracking();
|
|
12371
|
+
* // use has_opted_in value
|
|
12372
|
+
*
|
|
12373
|
+
* @param {Object} [options] A dictionary of config options to override
|
|
12374
|
+
* @param {string} [options.persistence_type=localStorage] Persistence mechanism used - cookie or localStorage - falls back to cookie if localStorage is unavailable
|
|
12375
|
+
* @param {string} [options.cookie_prefix=__mp_opt_in_out] Custom prefix to be used in the cookie/localstorage name
|
|
12376
|
+
* @returns {boolean} current opt-in status
|
|
12377
|
+
*/
|
|
12378
|
+
MixpanelLib.prototype.has_opted_in_tracking = function(options) {
|
|
12379
|
+
return this._gdpr_call_func(hasOptedIn, options);
|
|
12380
|
+
};
|
|
12381
|
+
|
|
12382
|
+
/**
|
|
12383
|
+
* Check whether the user has opted out of data tracking and cookies/localstorage for this Mixpanel instance
|
|
12384
|
+
*
|
|
12385
|
+
* ### Usage
|
|
12386
|
+
*
|
|
12387
|
+
* var has_opted_out = mixpanel.has_opted_out_tracking();
|
|
12388
|
+
* // use has_opted_out value
|
|
12389
|
+
*
|
|
12390
|
+
* @param {Object} [options] A dictionary of config options to override
|
|
12391
|
+
* @param {string} [options.persistence_type=localStorage] Persistence mechanism used - cookie or localStorage - falls back to cookie if localStorage is unavailable
|
|
12392
|
+
* @param {string} [options.cookie_prefix=__mp_opt_in_out] Custom prefix to be used in the cookie/localstorage name
|
|
12393
|
+
* @returns {boolean} current opt-out status
|
|
12394
|
+
*/
|
|
12395
|
+
MixpanelLib.prototype.has_opted_out_tracking = function(options) {
|
|
12396
|
+
return this._gdpr_call_func(hasOptedOut, options);
|
|
12397
|
+
};
|
|
12398
|
+
|
|
12399
|
+
/**
|
|
12400
|
+
* Clear the user's opt in/out status of data tracking and cookies/localstorage for this Mixpanel instance
|
|
12401
|
+
*
|
|
12402
|
+
* ### Usage
|
|
12403
|
+
*
|
|
12404
|
+
* // clear user's opt-in/out status
|
|
12405
|
+
* mixpanel.clear_opt_in_out_tracking();
|
|
12406
|
+
*
|
|
12407
|
+
* // clear user's opt-in/out status with specific cookie configuration - should match
|
|
12408
|
+
* // configuration used when opt_in_tracking/opt_out_tracking methods were called.
|
|
12409
|
+
* mixpanel.clear_opt_in_out_tracking({
|
|
12410
|
+
* cookie_expiration: 30,
|
|
12411
|
+
* secure_cookie: true
|
|
12412
|
+
* });
|
|
12413
|
+
*
|
|
12414
|
+
* @param {Object} [options] A dictionary of config options to override
|
|
12415
|
+
* @param {boolean} [options.enable_persistence=true] If true, will re-enable sdk persistence
|
|
12416
|
+
* @param {string} [options.persistence_type=localStorage] Persistence mechanism used - cookie or localStorage - falls back to cookie if localStorage is unavailable
|
|
12417
|
+
* @param {string} [options.cookie_prefix=__mp_opt_in_out] Custom prefix to be used in the cookie/localstorage name
|
|
12418
|
+
* @param {Number} [options.cookie_expiration] Number of days until the opt-in cookie expires (overrides value specified in this Mixpanel instance's config)
|
|
12419
|
+
* @param {string} [options.cookie_domain] Custom cookie domain (overrides value specified in this Mixpanel instance's config)
|
|
12420
|
+
* @param {boolean} [options.cross_site_cookie] Whether the opt-in cookie is set as cross-site-enabled (overrides value specified in this Mixpanel instance's config)
|
|
12421
|
+
* @param {boolean} [options.cross_subdomain_cookie] Whether the opt-in cookie is set as cross-subdomain or not (overrides value specified in this Mixpanel instance's config)
|
|
12422
|
+
* @param {boolean} [options.secure_cookie] Whether the opt-in cookie is set as secure or not (overrides value specified in this Mixpanel instance's config)
|
|
12423
|
+
*/
|
|
12424
|
+
MixpanelLib.prototype.clear_opt_in_out_tracking = function(options) {
|
|
12425
|
+
options = _.extend({
|
|
12426
|
+
'enable_persistence': true
|
|
12427
|
+
}, options);
|
|
12428
|
+
|
|
12429
|
+
this._gdpr_call_func(clearOptInOut, options);
|
|
12430
|
+
this._gdpr_update_persistence(options);
|
|
12431
|
+
};
|
|
12432
|
+
|
|
12433
|
+
MixpanelLib.prototype.report_error = function(msg, err) {
|
|
12434
|
+
console$1.error.apply(console$1.error, arguments);
|
|
12435
|
+
try {
|
|
12436
|
+
if (!err && !(msg instanceof Error)) {
|
|
12437
|
+
msg = new Error(msg);
|
|
12438
|
+
}
|
|
12439
|
+
this.get_config('error_reporter')(msg, err);
|
|
12440
|
+
} catch(err) {
|
|
12441
|
+
console$1.error(err);
|
|
12442
|
+
}
|
|
12443
|
+
};
|
|
12444
|
+
|
|
12445
|
+
// EXPORTS (for closure compiler)
|
|
12446
|
+
|
|
12447
|
+
// MixpanelLib Exports
|
|
12448
|
+
MixpanelLib.prototype['init'] = MixpanelLib.prototype.init;
|
|
12449
|
+
MixpanelLib.prototype['reset'] = MixpanelLib.prototype.reset;
|
|
12450
|
+
MixpanelLib.prototype['disable'] = MixpanelLib.prototype.disable;
|
|
12451
|
+
MixpanelLib.prototype['time_event'] = MixpanelLib.prototype.time_event;
|
|
12452
|
+
MixpanelLib.prototype['track'] = MixpanelLib.prototype.track;
|
|
12453
|
+
MixpanelLib.prototype['track_links'] = MixpanelLib.prototype.track_links;
|
|
12454
|
+
MixpanelLib.prototype['track_forms'] = MixpanelLib.prototype.track_forms;
|
|
12455
|
+
MixpanelLib.prototype['track_pageview'] = MixpanelLib.prototype.track_pageview;
|
|
12456
|
+
MixpanelLib.prototype['register'] = MixpanelLib.prototype.register;
|
|
12457
|
+
MixpanelLib.prototype['register_once'] = MixpanelLib.prototype.register_once;
|
|
12458
|
+
MixpanelLib.prototype['unregister'] = MixpanelLib.prototype.unregister;
|
|
12459
|
+
MixpanelLib.prototype['identify'] = MixpanelLib.prototype.identify;
|
|
12460
|
+
MixpanelLib.prototype['alias'] = MixpanelLib.prototype.alias;
|
|
12461
|
+
MixpanelLib.prototype['name_tag'] = MixpanelLib.prototype.name_tag;
|
|
12462
|
+
MixpanelLib.prototype['set_config'] = MixpanelLib.prototype.set_config;
|
|
12463
|
+
MixpanelLib.prototype['get_config'] = MixpanelLib.prototype.get_config;
|
|
12464
|
+
MixpanelLib.prototype['get_property'] = MixpanelLib.prototype.get_property;
|
|
12465
|
+
MixpanelLib.prototype['get_distinct_id'] = MixpanelLib.prototype.get_distinct_id;
|
|
12466
|
+
MixpanelLib.prototype['toString'] = MixpanelLib.prototype.toString;
|
|
12467
|
+
MixpanelLib.prototype['opt_out_tracking'] = MixpanelLib.prototype.opt_out_tracking;
|
|
12468
|
+
MixpanelLib.prototype['opt_in_tracking'] = MixpanelLib.prototype.opt_in_tracking;
|
|
12469
|
+
MixpanelLib.prototype['has_opted_out_tracking'] = MixpanelLib.prototype.has_opted_out_tracking;
|
|
12470
|
+
MixpanelLib.prototype['has_opted_in_tracking'] = MixpanelLib.prototype.has_opted_in_tracking;
|
|
12471
|
+
MixpanelLib.prototype['clear_opt_in_out_tracking'] = MixpanelLib.prototype.clear_opt_in_out_tracking;
|
|
12472
|
+
MixpanelLib.prototype['get_group'] = MixpanelLib.prototype.get_group;
|
|
12473
|
+
MixpanelLib.prototype['set_group'] = MixpanelLib.prototype.set_group;
|
|
12474
|
+
MixpanelLib.prototype['add_group'] = MixpanelLib.prototype.add_group;
|
|
12475
|
+
MixpanelLib.prototype['remove_group'] = MixpanelLib.prototype.remove_group;
|
|
12476
|
+
MixpanelLib.prototype['track_with_groups'] = MixpanelLib.prototype.track_with_groups;
|
|
12477
|
+
MixpanelLib.prototype['start_batch_senders'] = MixpanelLib.prototype.start_batch_senders;
|
|
12478
|
+
MixpanelLib.prototype['stop_batch_senders'] = MixpanelLib.prototype.stop_batch_senders;
|
|
12548
12479
|
|
|
12549
|
-
|
|
12550
|
-
|
|
12551
|
-
|
|
12552
|
-
|
|
12553
|
-
|
|
12554
|
-
|
|
12555
|
-
* @param root0.isCompositeQuery
|
|
12556
|
-
*/
|
|
12557
|
-
async function graphqlQuery({ query, variables, thoughtSpotHost, isCompositeQuery = false, }) {
|
|
12558
|
-
const operationName = getOperationNameFromQuery(query);
|
|
12559
|
-
try {
|
|
12560
|
-
const response = await fetch(`${thoughtSpotHost}/prism/?op=${operationName}`, {
|
|
12561
|
-
method: 'POST',
|
|
12562
|
-
headers: {
|
|
12563
|
-
'content-type': 'application/json;charset=UTF-8',
|
|
12564
|
-
'x-requested-by': 'ThoughtSpot',
|
|
12565
|
-
accept: '*/*',
|
|
12566
|
-
'accept-language': 'en-us',
|
|
12567
|
-
},
|
|
12568
|
-
body: JSON.stringify({
|
|
12569
|
-
operationName,
|
|
12570
|
-
query,
|
|
12571
|
-
variables,
|
|
12572
|
-
}),
|
|
12573
|
-
credentials: 'include',
|
|
12574
|
-
});
|
|
12575
|
-
const result = await response.json();
|
|
12576
|
-
const dataValues = Object.values(result.data);
|
|
12577
|
-
return (isCompositeQuery) ? result.data : dataValues[0];
|
|
12578
|
-
}
|
|
12579
|
-
catch (error) {
|
|
12580
|
-
return error;
|
|
12581
|
-
}
|
|
12582
|
-
}
|
|
12480
|
+
// MixpanelPersistence Exports
|
|
12481
|
+
MixpanelPersistence.prototype['properties'] = MixpanelPersistence.prototype.properties;
|
|
12482
|
+
MixpanelPersistence.prototype['update_search_keyword'] = MixpanelPersistence.prototype.update_search_keyword;
|
|
12483
|
+
MixpanelPersistence.prototype['update_referrer_info'] = MixpanelPersistence.prototype.update_referrer_info;
|
|
12484
|
+
MixpanelPersistence.prototype['get_cross_subdomain'] = MixpanelPersistence.prototype.get_cross_subdomain;
|
|
12485
|
+
MixpanelPersistence.prototype['clear'] = MixpanelPersistence.prototype.clear;
|
|
12583
12486
|
|
|
12584
|
-
const getSourceDetailQuery = `
|
|
12585
|
-
query GetSourceDetail($ids: [GUID!]!) {
|
|
12586
|
-
getSourceDetailById(ids: $ids, type: LOGICAL_TABLE) {
|
|
12587
|
-
id
|
|
12588
|
-
name
|
|
12589
|
-
description
|
|
12590
|
-
authorName
|
|
12591
|
-
authorDisplayName
|
|
12592
|
-
isExternal
|
|
12593
|
-
type
|
|
12594
|
-
created
|
|
12595
|
-
modified
|
|
12596
|
-
columns {
|
|
12597
|
-
id
|
|
12598
|
-
name
|
|
12599
|
-
author
|
|
12600
|
-
authorDisplayName
|
|
12601
|
-
description
|
|
12602
|
-
dataType
|
|
12603
|
-
type
|
|
12604
|
-
modified
|
|
12605
|
-
ownerName
|
|
12606
|
-
owner
|
|
12607
|
-
dataRecency
|
|
12608
|
-
sources {
|
|
12609
|
-
tableId
|
|
12610
|
-
tableName
|
|
12611
|
-
columnId
|
|
12612
|
-
columnName
|
|
12613
|
-
__typename
|
|
12614
|
-
}
|
|
12615
|
-
synonyms
|
|
12616
|
-
cohortAnswerId
|
|
12617
|
-
__typename
|
|
12618
|
-
}
|
|
12619
|
-
relationships
|
|
12620
|
-
destinationRelationships
|
|
12621
|
-
dataSourceId
|
|
12622
|
-
__typename
|
|
12623
|
-
}
|
|
12624
|
-
}
|
|
12625
|
-
`;
|
|
12626
|
-
const sourceDetailCache = new Map();
|
|
12627
|
-
/**
|
|
12628
|
-
*
|
|
12629
|
-
* @param thoughtSpotHost
|
|
12630
|
-
* @param sourceId
|
|
12631
|
-
*/
|
|
12632
|
-
async function getSourceDetail(thoughtSpotHost, sourceId) {
|
|
12633
|
-
if (sourceDetailCache.get(sourceId)) {
|
|
12634
|
-
return sourceDetailCache.get(sourceId);
|
|
12635
|
-
}
|
|
12636
|
-
const details = await graphqlQuery({
|
|
12637
|
-
query: getSourceDetailQuery,
|
|
12638
|
-
variables: {
|
|
12639
|
-
ids: [sourceId],
|
|
12640
|
-
},
|
|
12641
|
-
thoughtSpotHost,
|
|
12642
|
-
});
|
|
12643
|
-
const souceDetails = details[0];
|
|
12644
|
-
if (souceDetails) {
|
|
12645
|
-
sourceDetailCache.set(sourceId, souceDetails);
|
|
12646
|
-
}
|
|
12647
|
-
return souceDetails;
|
|
12648
|
-
}
|
|
12649
12487
|
|
|
12650
|
-
|
|
12651
|
-
|
|
12652
|
-
|
|
12653
|
-
|
|
12654
|
-
|
|
12655
|
-
|
|
12656
|
-
|
|
12657
|
-
|
|
12658
|
-
|
|
12659
|
-
|
|
12660
|
-
|
|
12661
|
-
|
|
12662
|
-
|
|
12663
|
-
|
|
12664
|
-
|
|
12665
|
-
|
|
12666
|
-
|
|
12667
|
-
|
|
12668
|
-
|
|
12669
|
-
|
|
12670
|
-
|
|
12671
|
-
|
|
12672
|
-
|
|
12673
|
-
|
|
12674
|
-
|
|
12675
|
-
|
|
12676
|
-
|
|
12677
|
-
|
|
12678
|
-
|
|
12679
|
-
|
|
12680
|
-
|
|
12681
|
-
|
|
12682
|
-
|
|
12683
|
-
|
|
12684
|
-
|
|
12685
|
-
|
|
12686
|
-
|
|
12687
|
-
|
|
12688
|
-
|
|
12689
|
-
|
|
12690
|
-
|
|
12691
|
-
|
|
12692
|
-
}
|
|
12693
|
-
|
|
12694
|
-
|
|
12695
|
-
|
|
12696
|
-
|
|
12697
|
-
|
|
12698
|
-
|
|
12699
|
-
|
|
12700
|
-
`;
|
|
12701
|
-
const getAnswerData = `
|
|
12702
|
-
query GetTableWithHeadlineData($session: BachSessionIdInput!, $deadline: Int!, $dataPaginationParams: DataPaginationParamsInput!) {
|
|
12703
|
-
getAnswer(session: $session) {
|
|
12704
|
-
${bachSessionId}
|
|
12705
|
-
answer {
|
|
12706
|
-
id
|
|
12707
|
-
visualizations {
|
|
12708
|
-
id
|
|
12709
|
-
... on TableViz {
|
|
12710
|
-
columns {
|
|
12711
|
-
column {
|
|
12712
|
-
id
|
|
12713
|
-
name
|
|
12714
|
-
type
|
|
12715
|
-
aggregationType
|
|
12716
|
-
dataType
|
|
12717
|
-
}
|
|
12718
|
-
}
|
|
12719
|
-
data(deadline: $deadline, pagination: $dataPaginationParams)
|
|
12720
|
-
}
|
|
12721
|
-
}
|
|
12722
|
-
}
|
|
12723
|
-
}
|
|
12724
|
-
}
|
|
12725
|
-
`;
|
|
12488
|
+
var instances = {};
|
|
12489
|
+
var extend_mp = function() {
|
|
12490
|
+
// add all the sub mixpanel instances
|
|
12491
|
+
_.each(instances, function(instance, name) {
|
|
12492
|
+
if (name !== PRIMARY_INSTANCE_NAME) { mixpanel_master[name] = instance; }
|
|
12493
|
+
});
|
|
12494
|
+
|
|
12495
|
+
// add private functions as _
|
|
12496
|
+
mixpanel_master['_'] = _;
|
|
12497
|
+
};
|
|
12498
|
+
|
|
12499
|
+
var override_mp_init_func = function() {
|
|
12500
|
+
// we override the snippets init function to handle the case where a
|
|
12501
|
+
// user initializes the mixpanel library after the script loads & runs
|
|
12502
|
+
mixpanel_master['init'] = function(token, config, name) {
|
|
12503
|
+
if (name) {
|
|
12504
|
+
// initialize a sub library
|
|
12505
|
+
if (!mixpanel_master[name]) {
|
|
12506
|
+
mixpanel_master[name] = instances[name] = create_mplib(token, config, name);
|
|
12507
|
+
mixpanel_master[name]._loaded();
|
|
12508
|
+
}
|
|
12509
|
+
return mixpanel_master[name];
|
|
12510
|
+
} else {
|
|
12511
|
+
var instance = mixpanel_master;
|
|
12512
|
+
|
|
12513
|
+
if (instances[PRIMARY_INSTANCE_NAME]) {
|
|
12514
|
+
// main mixpanel lib already initialized
|
|
12515
|
+
instance = instances[PRIMARY_INSTANCE_NAME];
|
|
12516
|
+
} else if (token) {
|
|
12517
|
+
// intialize the main mixpanel lib
|
|
12518
|
+
instance = create_mplib(token, config, PRIMARY_INSTANCE_NAME);
|
|
12519
|
+
instance._loaded();
|
|
12520
|
+
instances[PRIMARY_INSTANCE_NAME] = instance;
|
|
12521
|
+
}
|
|
12522
|
+
|
|
12523
|
+
mixpanel_master = instance;
|
|
12524
|
+
if (init_type === INIT_SNIPPET) {
|
|
12525
|
+
window$1[PRIMARY_INSTANCE_NAME] = mixpanel_master;
|
|
12526
|
+
}
|
|
12527
|
+
extend_mp();
|
|
12528
|
+
}
|
|
12529
|
+
};
|
|
12530
|
+
};
|
|
12531
|
+
|
|
12532
|
+
var add_dom_loaded_handler = function() {
|
|
12533
|
+
// Cross browser DOM Loaded support
|
|
12534
|
+
function dom_loaded_handler() {
|
|
12535
|
+
// function flag since we only want to execute this once
|
|
12536
|
+
if (dom_loaded_handler.done) { return; }
|
|
12537
|
+
dom_loaded_handler.done = true;
|
|
12726
12538
|
|
|
12727
|
-
|
|
12728
|
-
|
|
12729
|
-
|
|
12730
|
-
|
|
12731
|
-
|
|
12732
|
-
|
|
12733
|
-
|
|
12734
|
-
|
|
12735
|
-
|
|
12736
|
-
|
|
12737
|
-
|
|
12738
|
-
|
|
12739
|
-
|
|
12740
|
-
|
|
12741
|
-
|
|
12742
|
-
|
|
12743
|
-
|
|
12744
|
-
|
|
12745
|
-
|
|
12746
|
-
|
|
12747
|
-
|
|
12748
|
-
|
|
12749
|
-
|
|
12750
|
-
|
|
12751
|
-
|
|
12752
|
-
|
|
12753
|
-
|
|
12754
|
-
|
|
12755
|
-
|
|
12756
|
-
|
|
12757
|
-
|
|
12758
|
-
|
|
12759
|
-
|
|
12760
|
-
|
|
12761
|
-
|
|
12762
|
-
|
|
12763
|
-
|
|
12764
|
-
|
|
12765
|
-
|
|
12766
|
-
|
|
12767
|
-
|
|
12768
|
-
|
|
12769
|
-
|
|
12770
|
-
|
|
12771
|
-
|
|
12772
|
-
|
|
12773
|
-
|
|
12774
|
-
|
|
12775
|
-
|
|
12776
|
-
|
|
12777
|
-
|
|
12778
|
-
|
|
12779
|
-
|
|
12780
|
-
|
|
12781
|
-
|
|
12782
|
-
|
|
12783
|
-
|
|
12784
|
-
|
|
12785
|
-
|
|
12786
|
-
|
|
12787
|
-
|
|
12788
|
-
|
|
12789
|
-
|
|
12790
|
-
|
|
12791
|
-
|
|
12792
|
-
|
|
12793
|
-
|
|
12794
|
-
|
|
12795
|
-
|
|
12796
|
-
|
|
12797
|
-
|
|
12798
|
-
|
|
12799
|
-
|
|
12800
|
-
|
|
12801
|
-
|
|
12802
|
-
|
|
12803
|
-
|
|
12804
|
-
|
|
12805
|
-
|
|
12806
|
-
|
|
12807
|
-
|
|
12808
|
-
|
|
12809
|
-
|
|
12810
|
-
|
|
12811
|
-
|
|
12812
|
-
|
|
12813
|
-
|
|
12814
|
-
|
|
12815
|
-
|
|
12816
|
-
|
|
12817
|
-
|
|
12818
|
-
|
|
12819
|
-
|
|
12820
|
-
|
|
12821
|
-
|
|
12822
|
-
*
|
|
12823
|
-
* @param userLocale
|
|
12824
|
-
* @param includeInfo Include the CSV header in the output
|
|
12825
|
-
* @returns Response
|
|
12826
|
-
*/
|
|
12827
|
-
async fetchCSVBlob(userLocale = 'en-us', includeInfo = false) {
|
|
12828
|
-
const fetchUrl = this.getFetchCSVBlobUrl(userLocale, includeInfo);
|
|
12829
|
-
return tokenizedFetch(fetchUrl, {
|
|
12830
|
-
credentials: 'include',
|
|
12831
|
-
});
|
|
12832
|
-
}
|
|
12833
|
-
/**
|
|
12834
|
-
* Just get the internal URL for this answer's data
|
|
12835
|
-
* as a CSV blob.
|
|
12836
|
-
*
|
|
12837
|
-
* @param userLocale
|
|
12838
|
-
* @param includeInfo
|
|
12839
|
-
* @returns
|
|
12840
|
-
*/
|
|
12841
|
-
getFetchCSVBlobUrl(userLocale = 'en-us', includeInfo = false) {
|
|
12842
|
-
return `${this.thoughtSpotHost}/prism/download/answer/csv?sessionId=${this.session.sessionId}&genNo=${this.session.genNo}&userLocale=${userLocale}&exportFileName=data&hideCsvHeader=${!includeInfo}`;
|
|
12843
|
-
}
|
|
12844
|
-
/**
|
|
12845
|
-
* Get underlying data given a point and the output column names.
|
|
12846
|
-
* In case of a context menu action, the selectedPoints are
|
|
12847
|
-
* automatically passed.
|
|
12848
|
-
*
|
|
12849
|
-
* @param outputColumnNames
|
|
12850
|
-
* @param selectedPoints
|
|
12851
|
-
* @example
|
|
12852
|
-
* ```js
|
|
12853
|
-
* embed.on(EmbedEvent.CustomAction, e => {
|
|
12854
|
-
* const underlying = await e.answerService.getUnderlyingDataForPoint([
|
|
12855
|
-
* 'col name 1' // The column should exist in the data source.
|
|
12856
|
-
* ]);
|
|
12857
|
-
* const data = await underlying.fetchData(0, 100);
|
|
12858
|
-
* })
|
|
12859
|
-
* ```
|
|
12860
|
-
* @version SDK: 1.25.0| ThoughtSpot: 9.10.0.cl
|
|
12861
|
-
*/
|
|
12862
|
-
async getUnderlyingDataForPoint(outputColumnNames, selectedPoints) {
|
|
12863
|
-
if (!selectedPoints && !this.selectedPoints) {
|
|
12864
|
-
throw new Error('Needs to be triggered in context of a point');
|
|
12865
|
-
}
|
|
12866
|
-
if (!selectedPoints) {
|
|
12867
|
-
selectedPoints = getSelectedPointsForUnderlyingDataQuery(this.selectedPoints);
|
|
12868
|
-
}
|
|
12869
|
-
const sourceDetail = await this.getSourceDetail();
|
|
12870
|
-
const ouputColumnGuids = getGuidsFromColumnNames(sourceDetail, outputColumnNames);
|
|
12871
|
-
const unAggAnswer = await graphqlQuery({
|
|
12872
|
-
query: getUnaggregatedAnswerSession,
|
|
12873
|
-
variables: {
|
|
12874
|
-
session: this.session,
|
|
12875
|
-
columns: selectedPoints,
|
|
12876
|
-
},
|
|
12877
|
-
thoughtSpotHost: this.thoughtSpotHost,
|
|
12878
|
-
});
|
|
12879
|
-
const unaggAnswerSession = new AnswerService(unAggAnswer.id, unAggAnswer.answer, this.thoughtSpotHost);
|
|
12880
|
-
const currentColumns = new Set(unAggAnswer.answer.visualizations[0].columns
|
|
12881
|
-
.map((c) => c.column.referencedColumns[0].guid));
|
|
12882
|
-
const columnsToAdd = [...ouputColumnGuids].filter((col) => !currentColumns.has(col));
|
|
12883
|
-
if (columnsToAdd.length) {
|
|
12884
|
-
await unaggAnswerSession.addColumns(columnsToAdd);
|
|
12885
|
-
}
|
|
12886
|
-
const columnsToRemove = [...currentColumns].filter((col) => !ouputColumnGuids.has(col));
|
|
12887
|
-
if (columnsToRemove.length) {
|
|
12888
|
-
await unaggAnswerSession.removeColumns(columnsToRemove);
|
|
12889
|
-
}
|
|
12890
|
-
return unaggAnswerSession;
|
|
12891
|
-
}
|
|
12892
|
-
/**
|
|
12893
|
-
* Execute a custom graphql query in the context of the answer.
|
|
12894
|
-
*
|
|
12895
|
-
* @param query graphql query
|
|
12896
|
-
* @param variables graphql variables
|
|
12897
|
-
* @returns
|
|
12898
|
-
*/
|
|
12899
|
-
async executeQuery(query, variables) {
|
|
12900
|
-
const data = await graphqlQuery({
|
|
12901
|
-
query,
|
|
12902
|
-
variables: {
|
|
12903
|
-
session: this.session,
|
|
12904
|
-
...variables,
|
|
12905
|
-
},
|
|
12906
|
-
thoughtSpotHost: this.thoughtSpotHost,
|
|
12907
|
-
isCompositeQuery: false,
|
|
12908
|
-
});
|
|
12909
|
-
this.session = deepMerge(this.session, (data === null || data === void 0 ? void 0 : data.id) || {});
|
|
12910
|
-
return data;
|
|
12911
|
-
}
|
|
12912
|
-
/**
|
|
12913
|
-
* Get the internal session details for the answer.
|
|
12914
|
-
*
|
|
12915
|
-
* @returns
|
|
12916
|
-
*/
|
|
12917
|
-
getSession() {
|
|
12918
|
-
return this.session;
|
|
12539
|
+
DOM_LOADED = true;
|
|
12540
|
+
ENQUEUE_REQUESTS = false;
|
|
12541
|
+
|
|
12542
|
+
_.each(instances, function(inst) {
|
|
12543
|
+
inst._dom_loaded();
|
|
12544
|
+
});
|
|
12545
|
+
}
|
|
12546
|
+
|
|
12547
|
+
function do_scroll_check() {
|
|
12548
|
+
try {
|
|
12549
|
+
document$1.documentElement.doScroll('left');
|
|
12550
|
+
} catch(e) {
|
|
12551
|
+
setTimeout(do_scroll_check, 1);
|
|
12552
|
+
return;
|
|
12553
|
+
}
|
|
12554
|
+
|
|
12555
|
+
dom_loaded_handler();
|
|
12556
|
+
}
|
|
12557
|
+
|
|
12558
|
+
if (document$1.addEventListener) {
|
|
12559
|
+
if (document$1.readyState === 'complete') {
|
|
12560
|
+
// safari 4 can fire the DOMContentLoaded event before loading all
|
|
12561
|
+
// external JS (including this file). you will see some copypasta
|
|
12562
|
+
// on the internet that checks for 'complete' and 'loaded', but
|
|
12563
|
+
// 'loaded' is an IE thing
|
|
12564
|
+
dom_loaded_handler();
|
|
12565
|
+
} else {
|
|
12566
|
+
document$1.addEventListener('DOMContentLoaded', dom_loaded_handler, false);
|
|
12567
|
+
}
|
|
12568
|
+
} else if (document$1.attachEvent) {
|
|
12569
|
+
// IE
|
|
12570
|
+
document$1.attachEvent('onreadystatechange', dom_loaded_handler);
|
|
12571
|
+
|
|
12572
|
+
// check to make sure we arn't in a frame
|
|
12573
|
+
var toplevel = false;
|
|
12574
|
+
try {
|
|
12575
|
+
toplevel = window$1.frameElement === null;
|
|
12576
|
+
} catch(e) {
|
|
12577
|
+
// noop
|
|
12578
|
+
}
|
|
12579
|
+
|
|
12580
|
+
if (document$1.documentElement.doScroll && toplevel) {
|
|
12581
|
+
do_scroll_check();
|
|
12582
|
+
}
|
|
12583
|
+
}
|
|
12584
|
+
|
|
12585
|
+
// fallback handler, always will work
|
|
12586
|
+
_.register_event(window$1, 'load', dom_loaded_handler, true);
|
|
12587
|
+
};
|
|
12588
|
+
|
|
12589
|
+
function init_as_module() {
|
|
12590
|
+
init_type = INIT_MODULE;
|
|
12591
|
+
mixpanel_master = new MixpanelLib();
|
|
12592
|
+
|
|
12593
|
+
override_mp_init_func();
|
|
12594
|
+
mixpanel_master['init']();
|
|
12595
|
+
add_dom_loaded_handler();
|
|
12596
|
+
|
|
12597
|
+
return mixpanel_master;
|
|
12598
|
+
}
|
|
12599
|
+
|
|
12600
|
+
var mixpanel = init_as_module();
|
|
12601
|
+
|
|
12602
|
+
var mixpanel_cjs = mixpanel;
|
|
12603
|
+
|
|
12604
|
+
var mixpanel$1 = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.assign(/*#__PURE__*/Object.create(null), mixpanel_cjs, {
|
|
12605
|
+
'default': mixpanel_cjs
|
|
12606
|
+
}));
|
|
12607
|
+
|
|
12608
|
+
// Needed to avoid error in CJS builds on some bundlers.
|
|
12609
|
+
const mixpanelLib = mixpanel_cjs || mixpanel$1;
|
|
12610
|
+
let mixpanelInstance;
|
|
12611
|
+
const MIXPANEL_EVENT = {
|
|
12612
|
+
VISUAL_SDK_RENDER_START: 'visual-sdk-render-start',
|
|
12613
|
+
VISUAL_SDK_CALLED_INIT: 'visual-sdk-called-init',
|
|
12614
|
+
VISUAL_SDK_RENDER_COMPLETE: 'visual-sdk-render-complete',
|
|
12615
|
+
VISUAL_SDK_RENDER_FAILED: 'visual-sdk-render-failed',
|
|
12616
|
+
VISUAL_SDK_TRIGGER: 'visual-sdk-trigger',
|
|
12617
|
+
VISUAL_SDK_ON: 'visual-sdk-on',
|
|
12618
|
+
VISUAL_SDK_IFRAME_LOAD_PERFORMANCE: 'visual-sdk-iframe-load-performance',
|
|
12619
|
+
VISUAL_SDK_EMBED_CREATE: 'visual-sdk-embed-create',
|
|
12620
|
+
VERCEL_INTEGRATION_COMPLETED: 'vercel-integration-completed',
|
|
12621
|
+
};
|
|
12622
|
+
let isMixpanelInitialized = false;
|
|
12623
|
+
let eventQueue = [];
|
|
12624
|
+
/**
|
|
12625
|
+
* Pushes the event with its Property key-value map to mixpanel.
|
|
12626
|
+
*
|
|
12627
|
+
* @param eventId
|
|
12628
|
+
* @param eventProps
|
|
12629
|
+
*/
|
|
12630
|
+
function uploadMixpanelEvent(eventId, eventProps = {}) {
|
|
12631
|
+
if (!isMixpanelInitialized) {
|
|
12632
|
+
eventQueue.push({ eventId, eventProps });
|
|
12633
|
+
return;
|
|
12919
12634
|
}
|
|
12635
|
+
mixpanelInstance.track(eventId, eventProps);
|
|
12920
12636
|
}
|
|
12921
12637
|
/**
|
|
12922
12638
|
*
|
|
12923
|
-
* @param sourceDetail
|
|
12924
|
-
* @param colNames
|
|
12925
12639
|
*/
|
|
12926
|
-
function
|
|
12927
|
-
|
|
12928
|
-
|
|
12929
|
-
|
|
12930
|
-
|
|
12931
|
-
|
|
12932
|
-
|
|
12933
|
-
|
|
12934
|
-
}));
|
|
12640
|
+
function emptyQueue() {
|
|
12641
|
+
if (!isMixpanelInitialized) {
|
|
12642
|
+
return;
|
|
12643
|
+
}
|
|
12644
|
+
eventQueue.forEach((event) => {
|
|
12645
|
+
uploadMixpanelEvent(event.eventId, event.eventProps);
|
|
12646
|
+
});
|
|
12647
|
+
eventQueue = [];
|
|
12935
12648
|
}
|
|
12936
12649
|
/**
|
|
12937
12650
|
*
|
|
12938
|
-
* @param
|
|
12651
|
+
* @param sessionInfo
|
|
12939
12652
|
*/
|
|
12940
|
-
function
|
|
12941
|
-
|
|
12942
|
-
|
|
12943
|
-
|
|
12944
|
-
|
|
12945
|
-
|
|
12946
|
-
|
|
12947
|
-
|
|
12948
|
-
|
|
12949
|
-
|
|
12950
|
-
|
|
12951
|
-
|
|
12952
|
-
if (
|
|
12953
|
-
|
|
12954
|
-
epochRange: {
|
|
12955
|
-
startEpoch: colVal.value,
|
|
12956
|
-
},
|
|
12957
|
-
}];
|
|
12958
|
-
// Case for custom calendar.
|
|
12959
|
-
}
|
|
12960
|
-
else if ((_a = colVal.value) === null || _a === void 0 ? void 0 : _a.v) {
|
|
12961
|
-
dataValue = [{
|
|
12962
|
-
epochRange: {
|
|
12963
|
-
startEpoch: colVal.value.v.s,
|
|
12964
|
-
endEpoch: colVal.value.v.e,
|
|
12965
|
-
},
|
|
12966
|
-
}];
|
|
12653
|
+
function initMixpanel(sessionInfo) {
|
|
12654
|
+
var _a;
|
|
12655
|
+
if (!sessionInfo || !sessionInfo.mixpanelToken) {
|
|
12656
|
+
return;
|
|
12657
|
+
}
|
|
12658
|
+
// On a public cluster the user is anonymous, so don't set the identify to
|
|
12659
|
+
// userGUID
|
|
12660
|
+
const isPublicCluster = !!sessionInfo.isPublicUser;
|
|
12661
|
+
const token = sessionInfo.mixpanelToken;
|
|
12662
|
+
try {
|
|
12663
|
+
if (token) {
|
|
12664
|
+
mixpanelInstance = mixpanelLib.init(token, undefined, 'tsEmbed');
|
|
12665
|
+
if (!isPublicCluster) {
|
|
12666
|
+
mixpanelInstance.identify(sessionInfo.userGUID);
|
|
12967
12667
|
}
|
|
12668
|
+
mixpanelInstance.register_once({
|
|
12669
|
+
clusterId: sessionInfo.clusterId,
|
|
12670
|
+
clusterName: sessionInfo.clusterName,
|
|
12671
|
+
releaseVersion: sessionInfo.releaseVersion,
|
|
12672
|
+
hostAppUrl: ((_a = window === null || window === void 0 ? void 0 : window.location) === null || _a === void 0 ? void 0 : _a.host) || '',
|
|
12673
|
+
});
|
|
12674
|
+
isMixpanelInitialized = true;
|
|
12675
|
+
emptyQueue();
|
|
12968
12676
|
}
|
|
12969
|
-
else {
|
|
12970
|
-
dataValue = [{ value: colVal.value }];
|
|
12971
|
-
}
|
|
12972
|
-
underlyingDataPoint.push({
|
|
12973
|
-
columnId: colVal.column.id,
|
|
12974
|
-
dataValue,
|
|
12975
|
-
});
|
|
12976
12677
|
}
|
|
12977
|
-
|
|
12978
|
-
|
|
12979
|
-
}
|
|
12980
|
-
return underlyingDataPoint;
|
|
12678
|
+
catch (e) {
|
|
12679
|
+
logger.error('Error initializing mixpanel', e);
|
|
12680
|
+
}
|
|
12981
12681
|
}
|
|
12982
12682
|
|
|
12983
12683
|
var eventemitter3 = createCommonjsModule(function (module) {
|
|
@@ -13332,6 +13032,399 @@ mutation RemoveColumns($session: BachSessionIdInput!, $logicalColumnIds: [GUID!]
|
|
|
13332
13032
|
return new _Set(values);
|
|
13333
13033
|
};
|
|
13334
13034
|
|
|
13035
|
+
/**
|
|
13036
|
+
*
|
|
13037
|
+
* @param url
|
|
13038
|
+
* @param options
|
|
13039
|
+
*/
|
|
13040
|
+
function tokenisedFailureLoggedFetch(url, options = {}) {
|
|
13041
|
+
return tokenizedFetch(url, options).then(async (r) => {
|
|
13042
|
+
var _a;
|
|
13043
|
+
if (!r.ok && r.type !== 'opaqueredirect' && r.type !== 'opaque') {
|
|
13044
|
+
logger.error('Failure', await ((_a = r.text) === null || _a === void 0 ? void 0 : _a.call(r)));
|
|
13045
|
+
}
|
|
13046
|
+
return r;
|
|
13047
|
+
});
|
|
13048
|
+
}
|
|
13049
|
+
/**
|
|
13050
|
+
*
|
|
13051
|
+
* @param authVerificationUrl
|
|
13052
|
+
*/
|
|
13053
|
+
function fetchSessionInfoService(authVerificationUrl) {
|
|
13054
|
+
return tokenisedFailureLoggedFetch(authVerificationUrl, {
|
|
13055
|
+
credentials: 'include',
|
|
13056
|
+
});
|
|
13057
|
+
}
|
|
13058
|
+
|
|
13059
|
+
// eslint-disable-next-line import/no-mutable-exports
|
|
13060
|
+
let loggedInStatus = false;
|
|
13061
|
+
// eslint-disable-next-line import/no-mutable-exports
|
|
13062
|
+
let samlAuthWindow = null;
|
|
13063
|
+
// eslint-disable-next-line import/no-mutable-exports
|
|
13064
|
+
let samlCompletionPromise = null;
|
|
13065
|
+
let sessionInfo = null;
|
|
13066
|
+
let sessionInfoResolver = null;
|
|
13067
|
+
const sessionInfoPromise = new Promise((resolve) => {
|
|
13068
|
+
sessionInfoResolver = resolve;
|
|
13069
|
+
});
|
|
13070
|
+
let releaseVersion = '';
|
|
13071
|
+
const SSO_REDIRECTION_MARKER_GUID = '5e16222e-ef02-43e9-9fbd-24226bf3ce5b';
|
|
13072
|
+
/**
|
|
13073
|
+
* Enum for auth failure types. This is the parameter passed to the listner
|
|
13074
|
+
* of {@link AuthStatus.FAILURE}.
|
|
13075
|
+
*
|
|
13076
|
+
* @group Authentication / Init
|
|
13077
|
+
*/
|
|
13078
|
+
var AuthFailureType;
|
|
13079
|
+
(function (AuthFailureType) {
|
|
13080
|
+
AuthFailureType["SDK"] = "SDK";
|
|
13081
|
+
AuthFailureType["NO_COOKIE_ACCESS"] = "NO_COOKIE_ACCESS";
|
|
13082
|
+
AuthFailureType["EXPIRY"] = "EXPIRY";
|
|
13083
|
+
AuthFailureType["OTHER"] = "OTHER";
|
|
13084
|
+
})(AuthFailureType || (AuthFailureType = {}));
|
|
13085
|
+
/**
|
|
13086
|
+
* Enum for auth status emitted by the emitter returned from {@link init}.
|
|
13087
|
+
*
|
|
13088
|
+
* @group Authentication / Init
|
|
13089
|
+
*/
|
|
13090
|
+
var AuthStatus;
|
|
13091
|
+
(function (AuthStatus) {
|
|
13092
|
+
/**
|
|
13093
|
+
* Emits when the SDK fails to authenticate
|
|
13094
|
+
*/
|
|
13095
|
+
AuthStatus["FAILURE"] = "FAILURE";
|
|
13096
|
+
/**
|
|
13097
|
+
* Emits when the SDK authenticates successfully
|
|
13098
|
+
*/
|
|
13099
|
+
AuthStatus["SDK_SUCCESS"] = "SDK_SUCCESS";
|
|
13100
|
+
/**
|
|
13101
|
+
* Emits when the app sends an authentication success message
|
|
13102
|
+
*/
|
|
13103
|
+
AuthStatus["SUCCESS"] = "SUCCESS";
|
|
13104
|
+
/**
|
|
13105
|
+
* Emits when a user logs out
|
|
13106
|
+
*/
|
|
13107
|
+
AuthStatus["LOGOUT"] = "LOGOUT";
|
|
13108
|
+
/**
|
|
13109
|
+
* Emitted when inPopup is true in the SAMLRedirect flow and the
|
|
13110
|
+
* popup is waiting to be triggered either programmatically
|
|
13111
|
+
* or by the trigger button.
|
|
13112
|
+
*
|
|
13113
|
+
* @version SDK: 1.19.0
|
|
13114
|
+
*/
|
|
13115
|
+
AuthStatus["WAITING_FOR_POPUP"] = "WAITING_FOR_POPUP";
|
|
13116
|
+
})(AuthStatus || (AuthStatus = {}));
|
|
13117
|
+
/**
|
|
13118
|
+
* Events which can be triggered on the emitter returned from {@link init}.
|
|
13119
|
+
*
|
|
13120
|
+
* @group Authentication / Init
|
|
13121
|
+
*/
|
|
13122
|
+
var AuthEvent;
|
|
13123
|
+
(function (AuthEvent) {
|
|
13124
|
+
/**
|
|
13125
|
+
* Manually trigger the SSO popup. This is useful when
|
|
13126
|
+
* authStatus is SAMLRedirect/OIDCRedirect and inPopup is set to true
|
|
13127
|
+
*/
|
|
13128
|
+
AuthEvent["TRIGGER_SSO_POPUP"] = "TRIGGER_SSO_POPUP";
|
|
13129
|
+
})(AuthEvent || (AuthEvent = {}));
|
|
13130
|
+
/**
|
|
13131
|
+
*
|
|
13132
|
+
*/
|
|
13133
|
+
function notifyAuthSDKSuccess() {
|
|
13134
|
+
{
|
|
13135
|
+
logger.error('SDK not initialized');
|
|
13136
|
+
return;
|
|
13137
|
+
}
|
|
13138
|
+
}
|
|
13139
|
+
/**
|
|
13140
|
+
*
|
|
13141
|
+
*/
|
|
13142
|
+
function notifyAuthSuccess() {
|
|
13143
|
+
{
|
|
13144
|
+
logger.error('SDK not initialized');
|
|
13145
|
+
return;
|
|
13146
|
+
}
|
|
13147
|
+
}
|
|
13148
|
+
/**
|
|
13149
|
+
*
|
|
13150
|
+
* @param failureType
|
|
13151
|
+
*/
|
|
13152
|
+
function notifyAuthFailure(failureType) {
|
|
13153
|
+
{
|
|
13154
|
+
logger.error('SDK not initialized');
|
|
13155
|
+
return;
|
|
13156
|
+
}
|
|
13157
|
+
}
|
|
13158
|
+
/**
|
|
13159
|
+
*
|
|
13160
|
+
*/
|
|
13161
|
+
function notifyLogout() {
|
|
13162
|
+
{
|
|
13163
|
+
logger.error('SDK not initialized');
|
|
13164
|
+
return;
|
|
13165
|
+
}
|
|
13166
|
+
}
|
|
13167
|
+
const initSession = (sessionDetails) => {
|
|
13168
|
+
const embedConfig = getEmbedConfig();
|
|
13169
|
+
if (sessionInfo == null) {
|
|
13170
|
+
sessionInfo = sessionDetails;
|
|
13171
|
+
if (!embedConfig.disableSDKTracking) {
|
|
13172
|
+
initMixpanel(sessionInfo);
|
|
13173
|
+
}
|
|
13174
|
+
sessionInfoResolver(sessionInfo);
|
|
13175
|
+
}
|
|
13176
|
+
};
|
|
13177
|
+
const getSessionDetails = (sessionInfoResp) => {
|
|
13178
|
+
const devMixpanelToken = sessionInfoResp.configInfo.mixpanelConfig.devSdkKey;
|
|
13179
|
+
const prodMixpanelToken = sessionInfoResp.configInfo.mixpanelConfig.prodSdkKey;
|
|
13180
|
+
const mixpanelToken = sessionInfoResp.configInfo.mixpanelConfig.production
|
|
13181
|
+
? prodMixpanelToken
|
|
13182
|
+
: devMixpanelToken;
|
|
13183
|
+
return {
|
|
13184
|
+
userGUID: sessionInfoResp.userGUID,
|
|
13185
|
+
mixpanelToken,
|
|
13186
|
+
isPublicUser: sessionInfoResp.configInfo.isPublicUser,
|
|
13187
|
+
releaseVersion: sessionInfoResp.releaseVersion,
|
|
13188
|
+
clusterId: sessionInfoResp.configInfo.selfClusterId,
|
|
13189
|
+
clusterName: sessionInfoResp.configInfo.selfClusterName,
|
|
13190
|
+
...sessionInfoResp,
|
|
13191
|
+
};
|
|
13192
|
+
};
|
|
13193
|
+
/**
|
|
13194
|
+
* Check if we are logged into the ThoughtSpot cluster
|
|
13195
|
+
*
|
|
13196
|
+
* @param thoughtSpotHost The ThoughtSpot cluster hostname or IP
|
|
13197
|
+
*/
|
|
13198
|
+
async function isLoggedIn(thoughtSpotHost) {
|
|
13199
|
+
const authVerificationUrl = `${thoughtSpotHost}${EndPoints.AUTH_VERIFICATION}`;
|
|
13200
|
+
let response = null;
|
|
13201
|
+
try {
|
|
13202
|
+
response = await fetchSessionInfoService(authVerificationUrl);
|
|
13203
|
+
const sessionInfoResp = await response.json();
|
|
13204
|
+
const sessionDetails = getSessionDetails(sessionInfoResp);
|
|
13205
|
+
// Store user session details from session info
|
|
13206
|
+
initSession(sessionDetails);
|
|
13207
|
+
releaseVersion = sessionInfoResp.releaseVersion;
|
|
13208
|
+
}
|
|
13209
|
+
catch (e) {
|
|
13210
|
+
return false;
|
|
13211
|
+
}
|
|
13212
|
+
return response.status === 200;
|
|
13213
|
+
}
|
|
13214
|
+
/**
|
|
13215
|
+
* Return releaseVersion if available
|
|
13216
|
+
*/
|
|
13217
|
+
function getReleaseVersion() {
|
|
13218
|
+
return releaseVersion;
|
|
13219
|
+
}
|
|
13220
|
+
/**
|
|
13221
|
+
* Check if we are stuck at the SSO redirect URL
|
|
13222
|
+
*/
|
|
13223
|
+
function isAtSSORedirectUrl() {
|
|
13224
|
+
return window.location.href.indexOf(SSO_REDIRECTION_MARKER_GUID) >= 0;
|
|
13225
|
+
}
|
|
13226
|
+
/**
|
|
13227
|
+
* Remove the SSO redirect URL marker
|
|
13228
|
+
*/
|
|
13229
|
+
function removeSSORedirectUrlMarker() {
|
|
13230
|
+
// Note (sunny): This will leave a # around even if it was not in the URL
|
|
13231
|
+
// to begin with. Trying to remove the hash by changing window.location will
|
|
13232
|
+
// reload the page which we don't want. We'll live with adding an
|
|
13233
|
+
// unnecessary hash to the parent page URL until we find any use case where
|
|
13234
|
+
// that creates an issue.
|
|
13235
|
+
window.location.hash = window.location.hash.replace(SSO_REDIRECTION_MARKER_GUID, '');
|
|
13236
|
+
}
|
|
13237
|
+
/**
|
|
13238
|
+
* Perform token based authentication
|
|
13239
|
+
*
|
|
13240
|
+
* @param embedConfig The embed configuration
|
|
13241
|
+
*/
|
|
13242
|
+
const doTokenAuth = async (embedConfig) => {
|
|
13243
|
+
const { thoughtSpotHost, username, authEndpoint, getAuthToken, } = embedConfig;
|
|
13244
|
+
if (!authEndpoint && !getAuthToken) {
|
|
13245
|
+
throw new Error('Either auth endpoint or getAuthToken function must be provided');
|
|
13246
|
+
}
|
|
13247
|
+
loggedInStatus = await isLoggedIn(thoughtSpotHost);
|
|
13248
|
+
if (!loggedInStatus) {
|
|
13249
|
+
const authToken = await getAuthenticationToken(embedConfig);
|
|
13250
|
+
let resp;
|
|
13251
|
+
try {
|
|
13252
|
+
resp = await fetchAuthPostService(thoughtSpotHost, username, authToken);
|
|
13253
|
+
}
|
|
13254
|
+
catch (e) {
|
|
13255
|
+
resp = await fetchAuthService(thoughtSpotHost, username, authToken);
|
|
13256
|
+
}
|
|
13257
|
+
// token login issues a 302 when successful
|
|
13258
|
+
loggedInStatus = resp.ok || resp.type === 'opaqueredirect';
|
|
13259
|
+
if (loggedInStatus && embedConfig.detectCookieAccessSlow) {
|
|
13260
|
+
// When 3rd party cookie access is blocked, this will fail because
|
|
13261
|
+
// cookies will not be sent with the call.
|
|
13262
|
+
loggedInStatus = await isLoggedIn(thoughtSpotHost);
|
|
13263
|
+
}
|
|
13264
|
+
}
|
|
13265
|
+
return loggedInStatus;
|
|
13266
|
+
};
|
|
13267
|
+
/**
|
|
13268
|
+
* Validate embedConfig parameters required for cookielessTokenAuth
|
|
13269
|
+
*
|
|
13270
|
+
* @param embedConfig The embed configuration
|
|
13271
|
+
*/
|
|
13272
|
+
const doCookielessTokenAuth = async (embedConfig) => {
|
|
13273
|
+
const { authEndpoint, getAuthToken } = embedConfig;
|
|
13274
|
+
if (!authEndpoint && !getAuthToken) {
|
|
13275
|
+
throw new Error('Either auth endpoint or getAuthToken function must be provided');
|
|
13276
|
+
}
|
|
13277
|
+
let authSuccess = false;
|
|
13278
|
+
try {
|
|
13279
|
+
const authToken = await getAuthenticationToken(embedConfig);
|
|
13280
|
+
if (authToken) {
|
|
13281
|
+
authSuccess = true;
|
|
13282
|
+
}
|
|
13283
|
+
}
|
|
13284
|
+
catch {
|
|
13285
|
+
authSuccess = false;
|
|
13286
|
+
}
|
|
13287
|
+
return authSuccess;
|
|
13288
|
+
};
|
|
13289
|
+
/**
|
|
13290
|
+
* Perform basic authentication to the ThoughtSpot cluster using the cluster
|
|
13291
|
+
* credentials.
|
|
13292
|
+
*
|
|
13293
|
+
* Warning: This feature is primarily intended for developer testing. It is
|
|
13294
|
+
* strongly advised not to use this authentication method in production.
|
|
13295
|
+
*
|
|
13296
|
+
* @param embedConfig The embed configuration
|
|
13297
|
+
*/
|
|
13298
|
+
const doBasicAuth = async (embedConfig) => {
|
|
13299
|
+
const { thoughtSpotHost, username, password } = embedConfig;
|
|
13300
|
+
const loggedIn = await isLoggedIn(thoughtSpotHost);
|
|
13301
|
+
if (!loggedIn) {
|
|
13302
|
+
const response = await fetchBasicAuthService(thoughtSpotHost, username, password);
|
|
13303
|
+
loggedInStatus = response.ok;
|
|
13304
|
+
if (embedConfig.detectCookieAccessSlow) {
|
|
13305
|
+
loggedInStatus = await isLoggedIn(thoughtSpotHost);
|
|
13306
|
+
}
|
|
13307
|
+
}
|
|
13308
|
+
else {
|
|
13309
|
+
loggedInStatus = true;
|
|
13310
|
+
}
|
|
13311
|
+
return loggedInStatus;
|
|
13312
|
+
};
|
|
13313
|
+
/**
|
|
13314
|
+
*
|
|
13315
|
+
* @param ssoURL
|
|
13316
|
+
* @param triggerContainer
|
|
13317
|
+
* @param triggerText
|
|
13318
|
+
*/
|
|
13319
|
+
async function samlPopupFlow(ssoURL, triggerContainer, triggerText) {
|
|
13320
|
+
const openPopup = () => {
|
|
13321
|
+
if (samlAuthWindow === null || samlAuthWindow.closed) {
|
|
13322
|
+
samlAuthWindow = window.open(ssoURL, '_blank', 'location=no,height=570,width=520,scrollbars=yes,status=yes');
|
|
13323
|
+
}
|
|
13324
|
+
else {
|
|
13325
|
+
samlAuthWindow.focus();
|
|
13326
|
+
}
|
|
13327
|
+
};
|
|
13328
|
+
const containerEl = getDOMNode(triggerContainer);
|
|
13329
|
+
if (containerEl) {
|
|
13330
|
+
containerEl.innerHTML = '<button id="ts-auth-btn" class="ts-auth-btn" style="margin: auto;"></button>';
|
|
13331
|
+
const authElem = document.getElementById('ts-auth-btn');
|
|
13332
|
+
authElem.textContent = triggerText;
|
|
13333
|
+
authElem.addEventListener('click', openPopup, { once: true });
|
|
13334
|
+
}
|
|
13335
|
+
samlCompletionPromise = samlCompletionPromise
|
|
13336
|
+
|| new Promise((resolve, reject) => {
|
|
13337
|
+
window.addEventListener('message', (e) => {
|
|
13338
|
+
if (e.data.type === exports.EmbedEvent.SAMLComplete) {
|
|
13339
|
+
e.source.close();
|
|
13340
|
+
resolve();
|
|
13341
|
+
}
|
|
13342
|
+
});
|
|
13343
|
+
});
|
|
13344
|
+
return samlCompletionPromise;
|
|
13345
|
+
}
|
|
13346
|
+
/**
|
|
13347
|
+
* Perform SAML authentication
|
|
13348
|
+
*
|
|
13349
|
+
* @param embedConfig The embed configuration
|
|
13350
|
+
* @param ssoEndPoint
|
|
13351
|
+
*/
|
|
13352
|
+
const doSSOAuth = async (embedConfig, ssoEndPoint) => {
|
|
13353
|
+
const { thoughtSpotHost } = embedConfig;
|
|
13354
|
+
const loggedIn = await isLoggedIn(thoughtSpotHost);
|
|
13355
|
+
if (loggedIn) {
|
|
13356
|
+
if (isAtSSORedirectUrl()) {
|
|
13357
|
+
removeSSORedirectUrlMarker();
|
|
13358
|
+
}
|
|
13359
|
+
loggedInStatus = true;
|
|
13360
|
+
return;
|
|
13361
|
+
}
|
|
13362
|
+
// we have already tried authentication and it did not succeed, restore
|
|
13363
|
+
// the current URL to the original one and invoke the callback.
|
|
13364
|
+
if (isAtSSORedirectUrl()) {
|
|
13365
|
+
removeSSORedirectUrlMarker();
|
|
13366
|
+
loggedInStatus = false;
|
|
13367
|
+
return;
|
|
13368
|
+
}
|
|
13369
|
+
const ssoURL = `${thoughtSpotHost}${ssoEndPoint}`;
|
|
13370
|
+
if (embedConfig.inPopup) {
|
|
13371
|
+
await samlPopupFlow(ssoURL, embedConfig.authTriggerContainer, embedConfig.authTriggerText);
|
|
13372
|
+
loggedInStatus = await isLoggedIn(thoughtSpotHost);
|
|
13373
|
+
return;
|
|
13374
|
+
}
|
|
13375
|
+
window.location.href = ssoURL;
|
|
13376
|
+
};
|
|
13377
|
+
const doSamlAuth = async (embedConfig) => {
|
|
13378
|
+
const { thoughtSpotHost } = embedConfig;
|
|
13379
|
+
// redirect for SSO, when the SSO authentication is done, this page will be
|
|
13380
|
+
// loaded again and the same JS will execute again.
|
|
13381
|
+
const ssoRedirectUrl = embedConfig.inPopup
|
|
13382
|
+
? `${thoughtSpotHost}/v2/#/embed/saml-complete`
|
|
13383
|
+
: getRedirectUrl(window.location.href, SSO_REDIRECTION_MARKER_GUID, embedConfig.redirectPath);
|
|
13384
|
+
// bring back the page to the same URL
|
|
13385
|
+
const ssoEndPoint = `${EndPoints.SAML_LOGIN_TEMPLATE(encodeURIComponent(ssoRedirectUrl))}`;
|
|
13386
|
+
await doSSOAuth(embedConfig, ssoEndPoint);
|
|
13387
|
+
return loggedInStatus;
|
|
13388
|
+
};
|
|
13389
|
+
const doOIDCAuth = async (embedConfig) => {
|
|
13390
|
+
const { thoughtSpotHost } = embedConfig;
|
|
13391
|
+
// redirect for SSO, when the SSO authentication is done, this page will be
|
|
13392
|
+
// loaded again and the same JS will execute again.
|
|
13393
|
+
const ssoRedirectUrl = embedConfig.noRedirect || embedConfig.inPopup
|
|
13394
|
+
? `${thoughtSpotHost}/v2/#/embed/saml-complete`
|
|
13395
|
+
: getRedirectUrl(window.location.href, SSO_REDIRECTION_MARKER_GUID, embedConfig.redirectPath);
|
|
13396
|
+
// bring back the page to the same URL
|
|
13397
|
+
const ssoEndPoint = `${EndPoints.OIDC_LOGIN_TEMPLATE(encodeURIComponent(ssoRedirectUrl))}`;
|
|
13398
|
+
await doSSOAuth(embedConfig, ssoEndPoint);
|
|
13399
|
+
return loggedInStatus;
|
|
13400
|
+
};
|
|
13401
|
+
/**
|
|
13402
|
+
* Perform authentication on the ThoughtSpot cluster
|
|
13403
|
+
*
|
|
13404
|
+
* @param embedConfig The embed configuration
|
|
13405
|
+
*/
|
|
13406
|
+
const authenticate = async (embedConfig) => {
|
|
13407
|
+
const { authType } = embedConfig;
|
|
13408
|
+
switch (authType) {
|
|
13409
|
+
case AuthType.SSO:
|
|
13410
|
+
case AuthType.SAMLRedirect:
|
|
13411
|
+
case AuthType.SAML:
|
|
13412
|
+
return doSamlAuth(embedConfig);
|
|
13413
|
+
case AuthType.OIDC:
|
|
13414
|
+
case AuthType.OIDCRedirect:
|
|
13415
|
+
return doOIDCAuth(embedConfig);
|
|
13416
|
+
case AuthType.AuthServer:
|
|
13417
|
+
case AuthType.TrustedAuthToken:
|
|
13418
|
+
return doTokenAuth(embedConfig);
|
|
13419
|
+
case AuthType.TrustedAuthTokenCookieless:
|
|
13420
|
+
return doCookielessTokenAuth(embedConfig);
|
|
13421
|
+
case AuthType.Basic:
|
|
13422
|
+
return doBasicAuth(embedConfig);
|
|
13423
|
+
default:
|
|
13424
|
+
return Promise.resolve(true);
|
|
13425
|
+
}
|
|
13426
|
+
};
|
|
13427
|
+
|
|
13335
13428
|
/* eslint-disable camelcase */
|
|
13336
13429
|
const CONFIG_DEFAULTS = {
|
|
13337
13430
|
loginFailedMessage: 'Not logged in',
|
|
@@ -13545,6 +13638,8 @@ mutation RemoveColumns($session: BachSessionIdInput!, $logicalColumnIds: [GUID!]
|
|
|
13545
13638
|
});
|
|
13546
13639
|
}
|
|
13547
13640
|
|
|
13641
|
+
var name="@thoughtspot/visual-embed-sdk";var version="1.29.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:"45 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};
|
|
13642
|
+
|
|
13548
13643
|
/**
|
|
13549
13644
|
* Copyright (c) 2022
|
|
13550
13645
|
*
|
|
@@ -14777,7 +14872,7 @@ mutation RemoveColumns($session: BachSessionIdInput!, $logicalColumnIds: [GUID!]
|
|
|
14777
14872
|
}
|
|
14778
14873
|
getEmbedParams() {
|
|
14779
14874
|
var _a;
|
|
14780
|
-
const { hideResults,
|
|
14875
|
+
const { hideResults, enableSearchAssist, forceTable, searchOptions, runtimeFilters, dataSource, dataSources, excludeRuntimeFiltersfromURL, hideSearchBar, dataPanelV2 = false, useLastSelectedSources = false, runtimeParameters, collapseSearchBarInitially = false, } = this.viewConfig;
|
|
14781
14876
|
const queryParams = this.getBaseQueryParams();
|
|
14782
14877
|
queryParams[Param.HideActions] = [
|
|
14783
14878
|
...((_a = queryParams[Param.HideActions]) !== null && _a !== void 0 ? _a : []),
|
|
@@ -14814,6 +14909,7 @@ mutation RemoveColumns($session: BachSessionIdInput!, $logicalColumnIds: [GUID!]
|
|
|
14814
14909
|
queryParams[Param.UseLastSelectedDataSource] = false;
|
|
14815
14910
|
}
|
|
14816
14911
|
queryParams[Param.searchEmbed] = true;
|
|
14912
|
+
queryParams[Param.CollapseSearchBarInitially] = collapseSearchBarInitially;
|
|
14817
14913
|
let query = '';
|
|
14818
14914
|
const queryParamsString = getQueryParamString(queryParams, true);
|
|
14819
14915
|
if (queryParamsString) {
|
|
@@ -14941,7 +15037,7 @@ mutation RemoveColumns($session: BachSessionIdInput!, $logicalColumnIds: [GUID!]
|
|
|
14941
15037
|
* embedded Liveboard or visualization.
|
|
14942
15038
|
*/
|
|
14943
15039
|
getEmbedParams() {
|
|
14944
|
-
const { tag, hideObjects, liveboardV2, showPrimaryNavbar, disableProfileAndHelp, hideApplicationSwitcher, hideOrgSwitcher, enableSearchAssist, fullHeight, dataPanelV2 = false, hideLiveboardHeader = false, showLiveboardTitle = true, showLiveboardDescription = true, hideHomepageLeftNav = false, modularHomeExperience = false, isLiveboardHeaderSticky = true, enableAskSage, } = this.viewConfig;
|
|
15040
|
+
const { tag, hideObjects, liveboardV2, showPrimaryNavbar, disableProfileAndHelp, hideApplicationSwitcher, hideOrgSwitcher, enableSearchAssist, fullHeight, dataPanelV2 = false, hideLiveboardHeader = false, showLiveboardTitle = true, showLiveboardDescription = true, hideHomepageLeftNav = false, modularHomeExperience = false, isLiveboardHeaderSticky = true, enableAskSage, collapseSearchBarInitially = false, } = this.viewConfig;
|
|
14945
15041
|
let params = {};
|
|
14946
15042
|
params[Param.EmbedApp] = true;
|
|
14947
15043
|
params[Param.PrimaryNavHidden] = !showPrimaryNavbar;
|
|
@@ -14974,6 +15070,7 @@ mutation RemoveColumns($session: BachSessionIdInput!, $logicalColumnIds: [GUID!]
|
|
|
14974
15070
|
params[Param.DataPanelV2Enabled] = dataPanelV2;
|
|
14975
15071
|
params[Param.HideHomepageLeftNav] = hideHomepageLeftNav;
|
|
14976
15072
|
params[Param.ModularHomeExperienceEnabled] = modularHomeExperience;
|
|
15073
|
+
params[Param.CollapseSearchBarInitially] = collapseSearchBarInitially;
|
|
14977
15074
|
const queryParams = getQueryParamString(params, true);
|
|
14978
15075
|
return queryParams;
|
|
14979
15076
|
}
|