@thoughtspot/visual-embed-sdk 1.29.0-alpha.8 → 1.29.0-alpha.SCAL-205893-1
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/cjs/package.json +1 -1
- package/cjs/src/auth.d.ts +14 -17
- package/cjs/src/auth.d.ts.map +1 -1
- package/cjs/src/auth.js +45 -59
- package/cjs/src/auth.js.map +1 -1
- package/cjs/src/auth.spec.d.ts +12 -0
- package/cjs/src/auth.spec.d.ts.map +1 -1
- package/cjs/src/auth.spec.js +89 -67
- package/cjs/src/auth.spec.js.map +1 -1
- package/cjs/src/authToken.d.ts +1 -1
- package/cjs/src/authToken.d.ts.map +1 -1
- package/cjs/src/authToken.js +10 -4
- package/cjs/src/authToken.js.map +1 -1
- package/cjs/src/embed/app.spec.js +4 -2
- package/cjs/src/embed/app.spec.js.map +1 -1
- package/cjs/src/embed/base.d.ts.map +1 -1
- package/cjs/src/embed/base.js +2 -0
- package/cjs/src/embed/base.js.map +1 -1
- package/cjs/src/embed/base.spec.js +1 -0
- package/cjs/src/embed/base.spec.js.map +1 -1
- package/cjs/src/embed/embed.spec.js +3 -0
- package/cjs/src/embed/embed.spec.js.map +1 -1
- package/cjs/src/embed/events.spec.js +3 -0
- package/cjs/src/embed/events.spec.js.map +1 -1
- package/cjs/src/embed/liveboard.spec.js +2 -0
- package/cjs/src/embed/liveboard.spec.js.map +1 -1
- package/cjs/src/embed/pinboard.spec.js +3 -0
- package/cjs/src/embed/pinboard.spec.js.map +1 -1
- package/cjs/src/embed/sage.spec.js +3 -0
- package/cjs/src/embed/sage.spec.js.map +1 -1
- package/cjs/src/embed/search.spec.js +1 -0
- package/cjs/src/embed/search.spec.js.map +1 -1
- package/cjs/src/embed/ts-embed-trigger.spec.js +3 -0
- package/cjs/src/embed/ts-embed-trigger.spec.js.map +1 -1
- package/cjs/src/embed/ts-embed.d.ts.map +1 -1
- package/cjs/src/embed/ts-embed.js +7 -0
- package/cjs/src/embed/ts-embed.js.map +1 -1
- package/cjs/src/embed/ts-embed.spec.js +7 -0
- package/cjs/src/embed/ts-embed.spec.js.map +1 -1
- package/cjs/src/index.d.ts +2 -1
- package/cjs/src/index.d.ts.map +1 -1
- package/cjs/src/index.js +2 -1
- package/cjs/src/index.js.map +1 -1
- package/cjs/src/mixpanel-service.d.ts +2 -1
- package/cjs/src/mixpanel-service.d.ts.map +1 -1
- package/cjs/src/mixpanel-service.js +1 -0
- package/cjs/src/mixpanel-service.js.map +1 -1
- package/cjs/src/mixpanel-service.spec.js +7 -0
- package/cjs/src/mixpanel-service.spec.js.map +1 -1
- package/cjs/src/react/index.d.ts +1 -1
- package/cjs/src/react/index.d.ts.map +1 -1
- package/cjs/src/react/index.js +2 -1
- package/cjs/src/react/index.js.map +1 -1
- package/cjs/src/react/index.spec.js +6 -0
- package/cjs/src/react/index.spec.js.map +1 -1
- package/cjs/src/types.d.ts +1 -1
- package/cjs/src/types.js +1 -1
- package/cjs/src/utils/authService/authService.d.ts +1 -0
- package/cjs/src/utils/authService/authService.d.ts.map +1 -1
- package/cjs/src/utils/authService/authService.js +1 -0
- package/cjs/src/utils/authService/authService.js.map +1 -1
- package/cjs/src/utils/authService/authService.spec.js +18 -5
- package/cjs/src/utils/authService/authService.spec.js.map +1 -1
- package/cjs/src/utils/authService/tokenizedAuthService.d.ts +15 -2
- package/cjs/src/utils/authService/tokenizedAuthService.d.ts.map +1 -1
- package/cjs/src/utils/authService/tokenizedAuthService.js +39 -9
- package/cjs/src/utils/authService/tokenizedAuthService.js.map +1 -1
- package/cjs/src/utils/authService/tokenizedAuthService.spec.d.ts +2 -0
- package/cjs/src/utils/authService/tokenizedAuthService.spec.d.ts.map +1 -0
- package/cjs/src/utils/authService/tokenizedAuthService.spec.js +32 -0
- package/cjs/src/utils/authService/tokenizedAuthService.spec.js.map +1 -0
- package/cjs/src/utils/graphql/answerService/answerService.d.ts +10 -0
- package/cjs/src/utils/graphql/answerService/answerService.d.ts.map +1 -1
- package/cjs/src/utils/graphql/answerService/answerService.js +10 -0
- package/cjs/src/utils/graphql/answerService/answerService.js.map +1 -1
- package/cjs/src/utils/processData.js +2 -2
- package/cjs/src/utils/processData.js.map +1 -1
- package/cjs/src/utils/processData.spec.js +3 -2
- package/cjs/src/utils/processData.spec.js.map +1 -1
- package/cjs/src/utils/sessionInfoService.d.ts +66 -0
- package/cjs/src/utils/sessionInfoService.d.ts.map +1 -0
- package/cjs/src/utils/sessionInfoService.js +92 -0
- package/cjs/src/utils/sessionInfoService.js.map +1 -0
- package/dist/src/auth.d.ts +14 -17
- package/dist/src/auth.d.ts.map +1 -1
- package/dist/src/auth.spec.d.ts +12 -0
- package/dist/src/auth.spec.d.ts.map +1 -1
- package/dist/src/authToken.d.ts +1 -1
- package/dist/src/authToken.d.ts.map +1 -1
- package/dist/src/embed/base.d.ts.map +1 -1
- package/dist/src/embed/ts-embed.d.ts.map +1 -1
- package/dist/src/index.d.ts +2 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/mixpanel-service.d.ts +2 -1
- package/dist/src/mixpanel-service.d.ts.map +1 -1
- package/dist/src/react/index.d.ts +1 -1
- package/dist/src/react/index.d.ts.map +1 -1
- package/dist/src/types.d.ts +1 -1
- package/dist/src/utils/authService/authService.d.ts +1 -0
- package/dist/src/utils/authService/authService.d.ts.map +1 -1
- package/dist/src/utils/authService/tokenizedAuthService.d.ts +15 -2
- package/dist/src/utils/authService/tokenizedAuthService.d.ts.map +1 -1
- package/dist/src/utils/authService/tokenizedAuthService.spec.d.ts +2 -0
- package/dist/src/utils/authService/tokenizedAuthService.spec.d.ts.map +1 -0
- package/dist/src/utils/graphql/answerService/answerService.d.ts +10 -0
- package/dist/src/utils/graphql/answerService/answerService.d.ts.map +1 -1
- package/dist/src/utils/sessionInfoService.d.ts +66 -0
- package/dist/src/utils/sessionInfoService.d.ts.map +1 -0
- package/dist/tsembed-react.es.js +154 -58
- package/dist/tsembed-react.js +154 -57
- package/dist/tsembed.es.js +162 -69
- package/dist/tsembed.js +162 -69
- package/dist/visual-embed-sdk-react-full.d.ts +93 -20
- package/dist/visual-embed-sdk-react.d.ts +93 -20
- package/dist/visual-embed-sdk.d.ts +93 -20
- package/lib/package.json +1 -1
- package/lib/src/auth.d.ts +14 -17
- package/lib/src/auth.d.ts.map +1 -1
- package/lib/src/auth.js +44 -56
- package/lib/src/auth.js.map +1 -1
- package/lib/src/auth.spec.d.ts +12 -0
- package/lib/src/auth.spec.d.ts.map +1 -1
- package/lib/src/auth.spec.js +88 -66
- package/lib/src/auth.spec.js.map +1 -1
- package/lib/src/authToken.d.ts +1 -1
- package/lib/src/authToken.d.ts.map +1 -1
- package/lib/src/authToken.js +10 -4
- package/lib/src/authToken.js.map +1 -1
- package/lib/src/embed/app.spec.js +4 -2
- package/lib/src/embed/app.spec.js.map +1 -1
- package/lib/src/embed/base.d.ts.map +1 -1
- package/lib/src/embed/base.js +3 -1
- package/lib/src/embed/base.js.map +1 -1
- package/lib/src/embed/base.spec.js +1 -0
- package/lib/src/embed/base.spec.js.map +1 -1
- package/lib/src/embed/embed.spec.js +2 -0
- package/lib/src/embed/embed.spec.js.map +1 -1
- package/lib/src/embed/events.spec.js +2 -0
- package/lib/src/embed/events.spec.js.map +1 -1
- package/lib/src/embed/liveboard.spec.js +2 -0
- package/lib/src/embed/liveboard.spec.js.map +1 -1
- package/lib/src/embed/pinboard.spec.js +2 -0
- package/lib/src/embed/pinboard.spec.js.map +1 -1
- package/lib/src/embed/sage.spec.js +2 -0
- package/lib/src/embed/sage.spec.js.map +1 -1
- package/lib/src/embed/search.spec.js +1 -0
- package/lib/src/embed/search.spec.js.map +1 -1
- package/lib/src/embed/ts-embed-trigger.spec.js +2 -0
- package/lib/src/embed/ts-embed-trigger.spec.js.map +1 -1
- package/lib/src/embed/ts-embed.d.ts.map +1 -1
- package/lib/src/embed/ts-embed.js +7 -0
- package/lib/src/embed/ts-embed.js.map +1 -1
- package/lib/src/embed/ts-embed.spec.js +7 -0
- package/lib/src/embed/ts-embed.spec.js.map +1 -1
- package/lib/src/index.d.ts +2 -1
- package/lib/src/index.d.ts.map +1 -1
- package/lib/src/index.js +2 -1
- package/lib/src/index.js.map +1 -1
- package/lib/src/mixpanel-service.d.ts +2 -1
- package/lib/src/mixpanel-service.d.ts.map +1 -1
- package/lib/src/mixpanel-service.js +1 -0
- package/lib/src/mixpanel-service.js.map +1 -1
- package/lib/src/mixpanel-service.spec.js +7 -0
- package/lib/src/mixpanel-service.spec.js.map +1 -1
- package/lib/src/react/index.d.ts +1 -1
- package/lib/src/react/index.d.ts.map +1 -1
- package/lib/src/react/index.js +1 -1
- package/lib/src/react/index.js.map +1 -1
- package/lib/src/react/index.spec.js +6 -0
- package/lib/src/react/index.spec.js.map +1 -1
- package/lib/src/types.d.ts +1 -1
- package/lib/src/types.js +1 -1
- package/lib/src/utils/authService/authService.d.ts +1 -0
- package/lib/src/utils/authService/authService.d.ts.map +1 -1
- package/lib/src/utils/authService/authService.js +1 -0
- package/lib/src/utils/authService/authService.js.map +1 -1
- package/lib/src/utils/authService/authService.spec.js +18 -5
- package/lib/src/utils/authService/authService.spec.js.map +1 -1
- package/lib/src/utils/authService/tokenizedAuthService.d.ts +15 -2
- package/lib/src/utils/authService/tokenizedAuthService.d.ts.map +1 -1
- package/lib/src/utils/authService/tokenizedAuthService.js +37 -8
- package/lib/src/utils/authService/tokenizedAuthService.js.map +1 -1
- package/lib/src/utils/authService/tokenizedAuthService.spec.d.ts +2 -0
- package/lib/src/utils/authService/tokenizedAuthService.spec.d.ts.map +1 -0
- package/lib/src/utils/authService/tokenizedAuthService.spec.js +29 -0
- package/lib/src/utils/authService/tokenizedAuthService.spec.js.map +1 -0
- package/lib/src/utils/graphql/answerService/answerService.d.ts +10 -0
- package/lib/src/utils/graphql/answerService/answerService.d.ts.map +1 -1
- package/lib/src/utils/graphql/answerService/answerService.js +10 -0
- package/lib/src/utils/graphql/answerService/answerService.js.map +1 -1
- package/lib/src/utils/processData.js +3 -3
- package/lib/src/utils/processData.js.map +1 -1
- package/lib/src/utils/processData.spec.js +3 -2
- package/lib/src/utils/processData.spec.js.map +1 -1
- package/lib/src/utils/sessionInfoService.d.ts +66 -0
- package/lib/src/utils/sessionInfoService.d.ts.map +1 -0
- package/lib/src/utils/sessionInfoService.js +85 -0
- package/lib/src/utils/sessionInfoService.js.map +1 -0
- package/lib/src/visual-embed-sdk.d.ts +98 -21
- package/package.json +1 -1
- package/src/auth.spec.ts +92 -72
- package/src/auth.ts +46 -68
- package/src/authToken.ts +9 -4
- package/src/embed/app.spec.ts +4 -2
- package/src/embed/base.spec.ts +1 -0
- package/src/embed/base.ts +3 -0
- package/src/embed/embed.spec.ts +2 -0
- package/src/embed/events.spec.ts +2 -0
- package/src/embed/liveboard.spec.ts +2 -0
- package/src/embed/pinboard.spec.ts +2 -0
- package/src/embed/sage.spec.ts +3 -0
- package/src/embed/search.spec.ts +1 -0
- package/src/embed/ts-embed-trigger.spec.ts +3 -0
- package/src/embed/ts-embed.spec.ts +8 -0
- package/src/embed/ts-embed.ts +7 -0
- package/src/index.ts +2 -1
- package/src/mixpanel-service.spec.ts +12 -3
- package/src/mixpanel-service.ts +3 -1
- package/src/react/index.spec.tsx +7 -0
- package/src/react/index.tsx +1 -0
- package/src/types.ts +1 -1
- package/src/utils/authService/authService.spec.ts +18 -5
- package/src/utils/authService/authService.ts +1 -0
- package/src/utils/authService/tokenizedAuthService.spec.ts +36 -0
- package/src/utils/authService/tokenizedAuthService.ts +38 -8
- package/src/utils/graphql/answerService/answerService.ts +10 -0
- package/src/utils/processData.spec.ts +3 -2
- package/src/utils/processData.ts +3 -3
- package/src/utils/sessionInfoService.ts +101 -0
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { getEmbedConfig } from '../embed/embedConfig';
|
|
2
|
+
import { fetchSessionInfoService } from './authService';
|
|
3
|
+
let sessionInfo = null;
|
|
4
|
+
/**
|
|
5
|
+
* Returns the session info object and caches it for future use.
|
|
6
|
+
* Once fetched the session info object is cached and returned from the cache on
|
|
7
|
+
* subsequent calls.
|
|
8
|
+
*
|
|
9
|
+
* @example ```js
|
|
10
|
+
* const sessionInfo = await getSessionInfo();
|
|
11
|
+
* console.log(sessionInfo);
|
|
12
|
+
* ```
|
|
13
|
+
* @version SDK: 1.28.3 | ThoughtSpot: *
|
|
14
|
+
* @returns {Promise<SessionInfo>} The session info object.
|
|
15
|
+
*/
|
|
16
|
+
export async function getSessionInfo() {
|
|
17
|
+
if (!sessionInfo) {
|
|
18
|
+
const host = getEmbedConfig().thoughtSpotHost;
|
|
19
|
+
const sessionResponse = await fetchSessionInfoService(host);
|
|
20
|
+
const processedSessionInfo = getSessionDetails(sessionResponse);
|
|
21
|
+
sessionInfo = processedSessionInfo;
|
|
22
|
+
}
|
|
23
|
+
return sessionInfo;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Returns the cached session info object. If the client is not authenticated the
|
|
27
|
+
* function will return null.
|
|
28
|
+
*
|
|
29
|
+
* @example ```js
|
|
30
|
+
* const sessionInfo = getCachedSessionInfo();
|
|
31
|
+
* if (sessionInfo) {
|
|
32
|
+
* console.log(sessionInfo);
|
|
33
|
+
* } else {
|
|
34
|
+
* console.log('Not authenticated');
|
|
35
|
+
* }
|
|
36
|
+
* ```
|
|
37
|
+
* @returns {SessionInfo | null} The session info object.
|
|
38
|
+
* @version SDK: 1.28.3 | ThoughtSpot: *
|
|
39
|
+
*/
|
|
40
|
+
export function getCachedSessionInfo() {
|
|
41
|
+
return sessionInfo;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Processes the session info response and returns the session info object.
|
|
45
|
+
*
|
|
46
|
+
* @param sessionInfoResp {any} Response from the session info API.
|
|
47
|
+
* @returns {SessionInfo} The session info object.
|
|
48
|
+
* @example ```js
|
|
49
|
+
* const sessionInfoResp = await fetch(sessionInfoPath);
|
|
50
|
+
* const sessionInfo = getSessionDetails(sessionInfoResp);
|
|
51
|
+
* console.log(sessionInfo);
|
|
52
|
+
* ```
|
|
53
|
+
* @version SDK: 1.28.3 | ThoughtSpot: *
|
|
54
|
+
*/
|
|
55
|
+
export const getSessionDetails = (sessionInfoResp) => {
|
|
56
|
+
const devMixpanelToken = sessionInfoResp.configInfo.mixpanelConfig.devSdkKey;
|
|
57
|
+
const prodMixpanelToken = sessionInfoResp.configInfo.mixpanelConfig.prodSdkKey;
|
|
58
|
+
const mixpanelToken = sessionInfoResp.configInfo.mixpanelConfig.production
|
|
59
|
+
? prodMixpanelToken
|
|
60
|
+
: devMixpanelToken;
|
|
61
|
+
return {
|
|
62
|
+
userGUID: sessionInfoResp.userGUID,
|
|
63
|
+
mixpanelToken,
|
|
64
|
+
isPublicUser: sessionInfoResp.configInfo.isPublicUser,
|
|
65
|
+
releaseVersion: sessionInfoResp.releaseVersion,
|
|
66
|
+
clusterId: sessionInfoResp.configInfo.selfClusterId,
|
|
67
|
+
clusterName: sessionInfoResp.configInfo.selfClusterName,
|
|
68
|
+
...sessionInfoResp,
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* Resets the cached session info object and forces a new fetch on the next call.
|
|
73
|
+
*
|
|
74
|
+
* @example ```js
|
|
75
|
+
* resetCachedSessionInfo();
|
|
76
|
+
* const sessionInfo = await getSessionInfo();
|
|
77
|
+
* console.log(sessionInfo);
|
|
78
|
+
* ```
|
|
79
|
+
* @version SDK: 1.28.3 | ThoughtSpot ts7.april.cl, 7.2.1
|
|
80
|
+
* @returns {void}
|
|
81
|
+
*/
|
|
82
|
+
export function resetCachedSessionInfo() {
|
|
83
|
+
sessionInfo = null;
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=sessionInfoService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sessionInfoService.js","sourceRoot":"","sources":["../../../src/utils/sessionInfoService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AAcxD,IAAI,WAAW,GAAuB,IAAI,CAAC;AAE3C;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc;IAChC,IAAI,CAAC,WAAW,EAAE;QACd,MAAM,IAAI,GAAG,cAAc,EAAE,CAAC,eAAe,CAAC;QAC9C,MAAM,eAAe,GAAG,MAAM,uBAAuB,CAAC,IAAI,CAAC,CAAC;QAC5D,MAAM,oBAAoB,GAAG,iBAAiB,CAAC,eAAe,CAAC,CAAC;QAChE,WAAW,GAAG,oBAAoB,CAAC;KACtC;IACD,OAAO,WAAW,CAAC;AACvB,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,oBAAoB;IAChC,OAAO,WAAW,CAAC;AACvB,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,eAAoB,EAAe,EAAE;IACnE,MAAM,gBAAgB,GAAG,eAAe,CAAC,UAAU,CAAC,cAAc,CAAC,SAAS,CAAC;IAC7E,MAAM,iBAAiB,GAAG,eAAe,CAAC,UAAU,CAAC,cAAc,CAAC,UAAU,CAAC;IAC/E,MAAM,aAAa,GAAG,eAAe,CAAC,UAAU,CAAC,cAAc,CAAC,UAAU;QACtE,CAAC,CAAC,iBAAiB;QACnB,CAAC,CAAC,gBAAgB,CAAC;IACvB,OAAO;QACH,QAAQ,EAAE,eAAe,CAAC,QAAQ;QAClC,aAAa;QACb,YAAY,EAAE,eAAe,CAAC,UAAU,CAAC,YAAY;QACrD,cAAc,EAAE,eAAe,CAAC,cAAc;QAC9C,SAAS,EAAE,eAAe,CAAC,UAAU,CAAC,aAAa;QACnD,WAAW,EAAE,eAAe,CAAC,UAAU,CAAC,eAAe;QACvD,GAAG,eAAe;KACrB,CAAC;AACN,CAAC,CAAC;AAEF;;;;;;;;;;GAUG;AACH,MAAM,UAAU,sBAAsB;IAClC,WAAW,GAAG,IAAI,CAAC;AACvB,CAAC"}
|
|
@@ -17,7 +17,8 @@ declare module '@thoughtspot/visual-embed-sdk' {
|
|
|
17
17
|
import { PinboardEmbed, LiveboardViewConfig, LiveboardEmbed } from '@thoughtspot/visual-embed-sdk/embed/liveboard';
|
|
18
18
|
import { SearchEmbed, SearchViewConfig } from '@thoughtspot/visual-embed-sdk/embed/search';
|
|
19
19
|
import { SearchBarEmbed, SearchBarViewConfig } from '@thoughtspot/visual-embed-sdk/embed/search-bar';
|
|
20
|
-
import { AuthFailureType, AuthStatus, AuthEvent, AuthEventEmitter
|
|
20
|
+
import { AuthFailureType, AuthStatus, AuthEvent, AuthEventEmitter } from '@thoughtspot/visual-embed-sdk/auth';
|
|
21
|
+
import { getSessionInfo } from '@thoughtspot/visual-embed-sdk/utils/sessionInfoService';
|
|
21
22
|
import { AuthType, RuntimeFilter, RuntimeFilterOp, EmbedEvent, HostEvent, DataSourceVisualMode, Action, EmbedConfig, PrefetchFeatures, FrameParams, DOMSelector, HomeLeftNavItem, HomepageModule, MessageOptions, MessageCallback, MessagePayload, CustomisationsInterface, CustomStyles, customCssInterface, ContextMenuTriggerOptions, RuntimeParameter, LogLevel, VizPoint, CustomActionPayload } from '@thoughtspot/visual-embed-sdk/types';
|
|
22
23
|
import { CustomCssVariables } from '@thoughtspot/visual-embed-sdk/css-variables';
|
|
23
24
|
import { SageEmbed, SageViewConfig } from '@thoughtspot/visual-embed-sdk/embed/sage';
|
|
@@ -1383,12 +1384,6 @@ declare module '@thoughtspot/visual-embed-sdk/auth' {
|
|
|
1383
1384
|
export let samlAuthWindow: Window;
|
|
1384
1385
|
export let samlCompletionPromise: Promise<void>;
|
|
1385
1386
|
export const SSO_REDIRECTION_MARKER_GUID = "5e16222e-ef02-43e9-9fbd-24226bf3ce5b";
|
|
1386
|
-
interface sessionInfoInterface {
|
|
1387
|
-
userGUID: any;
|
|
1388
|
-
isPublicUser: any;
|
|
1389
|
-
mixpanelToken: any;
|
|
1390
|
-
[key: string]: any;
|
|
1391
|
-
}
|
|
1392
1387
|
/**
|
|
1393
1388
|
* Enum for auth failure types. This is the parameter passed to the listner
|
|
1394
1389
|
* of {@link AuthStatus.FAILURE}.
|
|
@@ -1506,7 +1501,7 @@ declare module '@thoughtspot/visual-embed-sdk/auth' {
|
|
|
1506
1501
|
/**
|
|
1507
1502
|
*
|
|
1508
1503
|
*/
|
|
1509
|
-
export function notifyAuthSuccess(): void
|
|
1504
|
+
export function notifyAuthSuccess(): Promise<void>;
|
|
1510
1505
|
/**
|
|
1511
1506
|
*
|
|
1512
1507
|
* @param failureType
|
|
@@ -1516,19 +1511,23 @@ declare module '@thoughtspot/visual-embed-sdk/auth' {
|
|
|
1516
1511
|
*
|
|
1517
1512
|
*/
|
|
1518
1513
|
export function notifyLogout(): void;
|
|
1519
|
-
export const initSession: (sessionDetails: sessionInfoInterface) => void;
|
|
1520
|
-
export const getSessionDetails: (sessionInfoResp: any) => sessionInfoInterface;
|
|
1521
1514
|
/**
|
|
1522
|
-
*
|
|
1515
|
+
* Services to be called after the login is successful,
|
|
1516
|
+
* This should be called after the cookie is set for cookie auth or
|
|
1517
|
+
* after the token is set for cookieless.
|
|
1518
|
+
*
|
|
1519
|
+
* @return {Promise<void>}
|
|
1520
|
+
* @example
|
|
1521
|
+
* ```js
|
|
1522
|
+
* await postLoginService();
|
|
1523
|
+
* ```
|
|
1524
|
+
* @version SDK: 1.28.3 | ThoughtSpot: *
|
|
1523
1525
|
*/
|
|
1524
|
-
export function
|
|
1526
|
+
export function postLoginService(): Promise<void>;
|
|
1525
1527
|
/**
|
|
1526
|
-
* Return
|
|
1527
|
-
* authentication is successful. And info is available.
|
|
1528
|
-
*
|
|
1529
|
-
* @group Global methods
|
|
1528
|
+
* Return releaseVersion if available
|
|
1530
1529
|
*/
|
|
1531
|
-
export function
|
|
1530
|
+
export function getReleaseVersion(): string;
|
|
1532
1531
|
/**
|
|
1533
1532
|
* Perform token based authentication
|
|
1534
1533
|
*
|
|
@@ -1564,7 +1563,74 @@ declare module '@thoughtspot/visual-embed-sdk/auth' {
|
|
|
1564
1563
|
* Check if we are authenticated to the ThoughtSpot cluster
|
|
1565
1564
|
*/
|
|
1566
1565
|
export const isAuthenticated: () => boolean;
|
|
1567
|
-
|
|
1566
|
+
}
|
|
1567
|
+
|
|
1568
|
+
declare module '@thoughtspot/visual-embed-sdk/utils/sessionInfoService' {
|
|
1569
|
+
export type SessionInfo = {
|
|
1570
|
+
releaseVersion: string;
|
|
1571
|
+
userGUID: string;
|
|
1572
|
+
currentOrgId: number;
|
|
1573
|
+
privileges: string[];
|
|
1574
|
+
mixpanelToken: string;
|
|
1575
|
+
isPublicUser: boolean;
|
|
1576
|
+
clusterId: string;
|
|
1577
|
+
clusterName: string;
|
|
1578
|
+
[key: string]: any;
|
|
1579
|
+
};
|
|
1580
|
+
/**
|
|
1581
|
+
* Returns the session info object and caches it for future use.
|
|
1582
|
+
* Once fetched the session info object is cached and returned from the cache on
|
|
1583
|
+
* subsequent calls.
|
|
1584
|
+
*
|
|
1585
|
+
* @example ```js
|
|
1586
|
+
* const sessionInfo = await getSessionInfo();
|
|
1587
|
+
* console.log(sessionInfo);
|
|
1588
|
+
* ```
|
|
1589
|
+
* @version SDK: 1.28.3 | ThoughtSpot: *
|
|
1590
|
+
* @returns {Promise<SessionInfo>} The session info object.
|
|
1591
|
+
*/
|
|
1592
|
+
export function getSessionInfo(): Promise<SessionInfo>;
|
|
1593
|
+
/**
|
|
1594
|
+
* Returns the cached session info object. If the client is not authenticated the
|
|
1595
|
+
* function will return null.
|
|
1596
|
+
*
|
|
1597
|
+
* @example ```js
|
|
1598
|
+
* const sessionInfo = getCachedSessionInfo();
|
|
1599
|
+
* if (sessionInfo) {
|
|
1600
|
+
* console.log(sessionInfo);
|
|
1601
|
+
* } else {
|
|
1602
|
+
* console.log('Not authenticated');
|
|
1603
|
+
* }
|
|
1604
|
+
* ```
|
|
1605
|
+
* @returns {SessionInfo | null} The session info object.
|
|
1606
|
+
* @version SDK: 1.28.3 | ThoughtSpot: *
|
|
1607
|
+
*/
|
|
1608
|
+
export function getCachedSessionInfo(): SessionInfo | null;
|
|
1609
|
+
/**
|
|
1610
|
+
* Processes the session info response and returns the session info object.
|
|
1611
|
+
*
|
|
1612
|
+
* @param sessionInfoResp {any} Response from the session info API.
|
|
1613
|
+
* @returns {SessionInfo} The session info object.
|
|
1614
|
+
* @example ```js
|
|
1615
|
+
* const sessionInfoResp = await fetch(sessionInfoPath);
|
|
1616
|
+
* const sessionInfo = getSessionDetails(sessionInfoResp);
|
|
1617
|
+
* console.log(sessionInfo);
|
|
1618
|
+
* ```
|
|
1619
|
+
* @version SDK: 1.28.3 | ThoughtSpot: *
|
|
1620
|
+
*/
|
|
1621
|
+
export const getSessionDetails: (sessionInfoResp: any) => SessionInfo;
|
|
1622
|
+
/**
|
|
1623
|
+
* Resets the cached session info object and forces a new fetch on the next call.
|
|
1624
|
+
*
|
|
1625
|
+
* @example ```js
|
|
1626
|
+
* resetCachedSessionInfo();
|
|
1627
|
+
* const sessionInfo = await getSessionInfo();
|
|
1628
|
+
* console.log(sessionInfo);
|
|
1629
|
+
* ```
|
|
1630
|
+
* @version SDK: 1.28.3 | ThoughtSpot ts7.april.cl, 7.2.1
|
|
1631
|
+
* @returns {void}
|
|
1632
|
+
*/
|
|
1633
|
+
export function resetCachedSessionInfo(): void;
|
|
1568
1634
|
}
|
|
1569
1635
|
|
|
1570
1636
|
declare module '@thoughtspot/visual-embed-sdk/types' {
|
|
@@ -4003,7 +4069,7 @@ declare module '@thoughtspot/visual-embed-sdk/types' {
|
|
|
4003
4069
|
*
|
|
4004
4070
|
* @example
|
|
4005
4071
|
* ```js
|
|
4006
|
-
* liveboardEmbed.trigger(HostEvent.
|
|
4072
|
+
* liveboardEmbed.trigger(HostEvent.getExportRequestForCurrentPinboard).then(
|
|
4007
4073
|
* data=>console.log(data))
|
|
4008
4074
|
* ```
|
|
4009
4075
|
* @version SDK: 1.13.0 | ThoughtSpot: 8.5.0.cl, 8.8.1.sw
|
|
@@ -6362,6 +6428,16 @@ declare module '@thoughtspot/visual-embed-sdk/utils/graphql/answerService/answer
|
|
|
6362
6428
|
* const data = await underlying.fetchData(0, 100);
|
|
6363
6429
|
* })
|
|
6364
6430
|
* ```
|
|
6431
|
+
* @example
|
|
6432
|
+
* ```js
|
|
6433
|
+
* embed.on(EmbedEvent.Data, async (e) => {
|
|
6434
|
+
* const service = await embed.getAnswerService();
|
|
6435
|
+
* await service.addColumns([
|
|
6436
|
+
* "<column guid>"
|
|
6437
|
+
* ]);
|
|
6438
|
+
* console.log(await service.fetchData());
|
|
6439
|
+
* });
|
|
6440
|
+
* ```
|
|
6365
6441
|
* @version SDK: 1.25.0| ThoughtSpot: 9.10.0.cl
|
|
6366
6442
|
* @group Events
|
|
6367
6443
|
*/
|
|
@@ -6481,6 +6557,7 @@ declare module '@thoughtspot/visual-embed-sdk/embed/embedConfig' {
|
|
|
6481
6557
|
}
|
|
6482
6558
|
|
|
6483
6559
|
declare module '@thoughtspot/visual-embed-sdk/mixpanel-service' {
|
|
6560
|
+
import { SessionInfo } from '@thoughtspot/visual-embed-sdk/utils/sessionInfoService';
|
|
6484
6561
|
export const EndPoints: {
|
|
6485
6562
|
CONFIG: string;
|
|
6486
6563
|
};
|
|
@@ -6506,7 +6583,7 @@ declare module '@thoughtspot/visual-embed-sdk/mixpanel-service' {
|
|
|
6506
6583
|
*
|
|
6507
6584
|
* @param sessionInfo
|
|
6508
6585
|
*/
|
|
6509
|
-
export function initMixpanel(sessionInfo:
|
|
6586
|
+
export function initMixpanel(sessionInfo: SessionInfo): void;
|
|
6510
6587
|
/**
|
|
6511
6588
|
*
|
|
6512
6589
|
*/
|
|
@@ -6528,7 +6605,7 @@ declare module '@thoughtspot/visual-embed-sdk/tokenizedFetch' {
|
|
|
6528
6605
|
|
|
6529
6606
|
declare module '@thoughtspot/visual-embed-sdk/authToken' {
|
|
6530
6607
|
import { EmbedConfig } from '@thoughtspot/visual-embed-sdk/types';
|
|
6531
|
-
export
|
|
6608
|
+
export function getAuthenticationToken(embedConfig: EmbedConfig): Promise<string>;
|
|
6532
6609
|
/**
|
|
6533
6610
|
* Resets the auth token and a new token will be fetched on the next request.
|
|
6534
6611
|
*
|
package/package.json
CHANGED
package/src/auth.spec.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import * as authInstance from './auth';
|
|
2
|
-
import * as
|
|
3
|
-
import * as tokenAuthService from './utils/authService/tokenizedAuthService';
|
|
4
|
-
import * as checkReleaseVersionInBetaInstance from './utils';
|
|
5
|
-
import * as mixPanelService from './mixpanel-service';
|
|
2
|
+
import * as authTokenService from './authToken';
|
|
6
3
|
import * as EmbedConfig from './embed/embedConfig';
|
|
7
|
-
import
|
|
4
|
+
import * as mixPanelService from './mixpanel-service';
|
|
8
5
|
import { executeAfterWait } from './test/test-utils';
|
|
9
|
-
import {
|
|
6
|
+
import { AuthType, EmbedEvent } from './types';
|
|
7
|
+
import * as checkReleaseVersionInBetaInstance from './utils';
|
|
8
|
+
import * as authService from './utils/authService/authService';
|
|
9
|
+
import * as tokenAuthService from './utils/authService/tokenizedAuthService';
|
|
10
|
+
import { logger } from './utils/logger';
|
|
11
|
+
import * as SessionService from './utils/sessionInfoService';
|
|
10
12
|
|
|
11
13
|
const thoughtSpotHost = 'http://localhost:3000';
|
|
12
14
|
const username = 'tsuser';
|
|
@@ -18,7 +20,7 @@ export const embedConfig: any = {
|
|
|
18
20
|
thoughtSpotHost,
|
|
19
21
|
username,
|
|
20
22
|
authEndpoint: 'auth',
|
|
21
|
-
authType: AuthType.
|
|
23
|
+
authType: AuthType.TrustedAuthToken,
|
|
22
24
|
getAuthToken: jest.fn(() => Promise.resolve(token)),
|
|
23
25
|
}),
|
|
24
26
|
doTokenAuthWithCookieDetect: {
|
|
@@ -112,31 +114,47 @@ export const mockSessionInfo = {
|
|
|
112
114
|
},
|
|
113
115
|
};
|
|
114
116
|
|
|
117
|
+
export const mockSessionInfoApiResponse = {
|
|
118
|
+
userGUID: '1234',
|
|
119
|
+
releaseVersion: 'test',
|
|
120
|
+
configInfo: {
|
|
121
|
+
isPublicUser: false,
|
|
122
|
+
mixpanelConfig: {
|
|
123
|
+
production: true,
|
|
124
|
+
devSdkKey: 'devKey',
|
|
125
|
+
prodSdkKey: 'prodKey',
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
};
|
|
129
|
+
|
|
115
130
|
describe('Unit test for auth', () => {
|
|
116
131
|
beforeEach(() => {
|
|
132
|
+
jest.resetAllMocks();
|
|
117
133
|
global.fetch = window.fetch;
|
|
118
134
|
});
|
|
119
135
|
afterEach(() => {
|
|
120
|
-
resetCachedAuthToken();
|
|
136
|
+
authTokenService.resetCachedAuthToken();
|
|
137
|
+
SessionService.resetCachedSessionInfo();
|
|
121
138
|
});
|
|
122
139
|
test('endpoints, SAML_LOGIN_TEMPLATE', () => {
|
|
123
140
|
const ssoTemplateUrl = authService.EndPoints.SAML_LOGIN_TEMPLATE(thoughtSpotHost);
|
|
124
141
|
expect(ssoTemplateUrl).toBe(`/callosum/v1/saml/login?targetURLPath=${thoughtSpotHost}`);
|
|
125
142
|
});
|
|
126
143
|
|
|
127
|
-
test('when session info giving response', async () => {
|
|
128
|
-
jest.spyOn(
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
expect(sessionInfo).
|
|
144
|
+
test('when session info giving response, it is cached', async () => {
|
|
145
|
+
jest.spyOn(tokenAuthService, 'fetchSessionInfoService').mockResolvedValueOnce(mockSessionInfoApiResponse);
|
|
146
|
+
const sessionInfo = await SessionService.getSessionInfo();
|
|
147
|
+
expect(sessionInfo.mixpanelToken).toEqual('prodKey');
|
|
148
|
+
expect(sessionInfo.isPublicUser).toEqual(false);
|
|
149
|
+
await SessionService.getSessionInfo();
|
|
150
|
+
expect(tokenAuthService.fetchSessionInfoService).toHaveBeenCalledTimes(1);
|
|
132
151
|
});
|
|
133
152
|
|
|
134
153
|
test('Disable mixpanel when disableSDKTracking flag is set', () => {
|
|
135
|
-
jest.clearAllMocks();
|
|
136
|
-
jest.resetAllMocks();
|
|
137
154
|
jest.spyOn(mixPanelService, 'initMixpanel');
|
|
155
|
+
jest.spyOn(SessionService, 'getSessionInfo').mockReturnValue(mockSessionInfo);
|
|
138
156
|
jest.spyOn(EmbedConfig, 'getEmbedConfig').mockReturnValue({ disableSDKTracking: true });
|
|
139
|
-
authInstance.
|
|
157
|
+
authInstance.postLoginService();
|
|
140
158
|
expect(mixPanelService.initMixpanel).not.toBeCalled();
|
|
141
159
|
});
|
|
142
160
|
|
|
@@ -163,28 +181,22 @@ describe('Unit test for auth', () => {
|
|
|
163
181
|
});
|
|
164
182
|
|
|
165
183
|
test('doTokenAuth: when user is loggedIn', async () => {
|
|
166
|
-
jest.spyOn(
|
|
167
|
-
|
|
168
|
-
status: 200,
|
|
169
|
-
}));
|
|
170
|
-
jest.spyOn(authInstance, 'getSessionDetails').mockReturnValue(mockSessionInfo);
|
|
171
|
-
jest.spyOn(authInstance, 'initSession').mockReturnValue(null);
|
|
184
|
+
const getAuthenticationTokenMock = jest.spyOn(authTokenService, 'getAuthenticationToken');
|
|
185
|
+
jest.spyOn(tokenAuthService, 'isActiveService').mockImplementation(async () => true);
|
|
172
186
|
await authInstance.doTokenAuth(embedConfig.doTokenAuthSuccess('authToken'));
|
|
173
|
-
expect(
|
|
187
|
+
expect(authTokenService.getAuthenticationToken).not.toBeCalled();
|
|
174
188
|
expect(authInstance.loggedInStatus).toBe(true);
|
|
189
|
+
getAuthenticationTokenMock.mockRestore();
|
|
175
190
|
});
|
|
176
191
|
|
|
177
192
|
test('doTokenAuth: when user is not loggedIn & getAuthToken have response', async () => {
|
|
178
|
-
jest.spyOn(tokenAuthService, '
|
|
179
|
-
jest.spyOn(authService, 'fetchAuthTokenService').mockImplementation(() => ({
|
|
180
|
-
text: () => Promise.resolve('abc'),
|
|
181
|
-
}));
|
|
193
|
+
jest.spyOn(tokenAuthService, 'isActiveService').mockImplementation(async () => false);
|
|
182
194
|
jest.spyOn(authService, 'fetchAuthService').mockImplementation(() => Promise.resolve({
|
|
183
195
|
status: 200,
|
|
196
|
+
ok: true,
|
|
184
197
|
}));
|
|
185
198
|
jest.spyOn(authService, 'verifyTokenService').mockResolvedValueOnce(true);
|
|
186
199
|
await authInstance.doTokenAuth(embedConfig.doTokenAuthSuccess('authToken2'));
|
|
187
|
-
expect(tokenAuthService.fetchSessionInfoService).toBeCalled();
|
|
188
200
|
expect(authService.fetchAuthService).toBeCalledWith(
|
|
189
201
|
thoughtSpotHost,
|
|
190
202
|
username,
|
|
@@ -193,26 +205,25 @@ describe('Unit test for auth', () => {
|
|
|
193
205
|
});
|
|
194
206
|
|
|
195
207
|
test('doTokenAuth: when user is not loggedIn & getAuthToken not present, isLoggedIn should called', async () => {
|
|
196
|
-
jest.spyOn(tokenAuthService, '
|
|
197
|
-
jest.spyOn(authService, 'fetchAuthTokenService').mockImplementation(() =>
|
|
208
|
+
jest.spyOn(tokenAuthService, 'isActiveService').mockImplementation(async () => false);
|
|
209
|
+
jest.spyOn(authService, 'fetchAuthTokenService').mockImplementation(() => ({
|
|
210
|
+
text: () => Promise.resolve('abc'),
|
|
211
|
+
}));
|
|
198
212
|
jest.spyOn(authService, 'fetchAuthService').mockImplementation(() => Promise.resolve({
|
|
199
213
|
status: 200,
|
|
200
214
|
ok: true,
|
|
201
215
|
}));
|
|
202
216
|
jest.spyOn(authService, 'verifyTokenService').mockResolvedValueOnce(true);
|
|
203
217
|
await authInstance.doTokenAuth(embedConfig.doTokenAuthFailureWithoutGetAuthToken);
|
|
218
|
+
expect(authService.fetchAuthTokenService).toBeCalledWith('auth');
|
|
204
219
|
await executeAfterWait(() => {
|
|
205
220
|
expect(authInstance.loggedInStatus).toBe(true);
|
|
206
|
-
expect(
|
|
207
|
-
expect(authService.fetchAuthService).toBeCalledWith(
|
|
208
|
-
thoughtSpotHost,
|
|
209
|
-
username,
|
|
210
|
-
'authToken2',
|
|
211
|
-
);
|
|
221
|
+
expect(authService.fetchAuthService).toBeCalledWith(thoughtSpotHost, username, 'abc');
|
|
212
222
|
});
|
|
213
223
|
});
|
|
214
224
|
|
|
215
225
|
test('doTokenAuth: Should raise error when duplicate token is used', async () => {
|
|
226
|
+
jest.spyOn(tokenAuthService, 'isActiveService').mockImplementation(async () => false);
|
|
216
227
|
jest.spyOn(tokenAuthService, 'fetchSessionInfoService').mockResolvedValue({
|
|
217
228
|
status: 401,
|
|
218
229
|
});
|
|
@@ -254,8 +265,10 @@ describe('Unit test for auth', () => {
|
|
|
254
265
|
ok: true,
|
|
255
266
|
}));
|
|
256
267
|
jest.spyOn(authService, 'verifyTokenService').mockResolvedValueOnce(true);
|
|
268
|
+
jest.spyOn(tokenAuthService, 'isActiveService').mockResolvedValueOnce(false);
|
|
269
|
+
jest.spyOn(tokenAuthService, 'isActiveService').mockResolvedValueOnce(false);
|
|
257
270
|
const isLoggedIn = await authInstance.doTokenAuth(embedConfig.doTokenAuthWithCookieDetect);
|
|
258
|
-
expect(tokenAuthService.
|
|
271
|
+
expect(tokenAuthService.isActiveService).toHaveBeenCalledTimes(2);
|
|
259
272
|
expect(isLoggedIn).toBe(false);
|
|
260
273
|
});
|
|
261
274
|
|
|
@@ -278,7 +291,6 @@ describe('Unit test for auth', () => {
|
|
|
278
291
|
expect(await authInstance.doTokenAuth(embedConfig.doTokenAuthSuccess('authToken2'))).toBe(
|
|
279
292
|
true,
|
|
280
293
|
);
|
|
281
|
-
expect(tokenAuthService.fetchSessionInfoService).toBeCalled();
|
|
282
294
|
expect(authService.fetchAuthPostService).toBeCalledWith(
|
|
283
295
|
thoughtSpotHost,
|
|
284
296
|
username,
|
|
@@ -297,20 +309,9 @@ describe('Unit test for auth', () => {
|
|
|
297
309
|
});
|
|
298
310
|
|
|
299
311
|
it('when user is loggedIn', async () => {
|
|
300
|
-
spyOn(
|
|
301
|
-
jest.spyOn(authInstance, 'getSessionDetails').mockReturnValue(mockSessionInfo);
|
|
302
|
-
jest.spyOn(authInstance, 'initSession').mockReturnValue(null);
|
|
303
|
-
jest.spyOn(tokenAuthService, 'fetchSessionInfoService').mockImplementation(
|
|
304
|
-
async () => ({
|
|
305
|
-
json: () => mockSessionInfo,
|
|
306
|
-
status: 200,
|
|
307
|
-
}),
|
|
308
|
-
);
|
|
312
|
+
jest.spyOn(tokenAuthService, 'isActiveService').mockResolvedValueOnce(true);
|
|
309
313
|
await authInstance.doBasicAuth(embedConfig.doBasicAuth);
|
|
310
|
-
expect(tokenAuthService.fetchSessionInfoService).toBeCalled();
|
|
311
314
|
expect(authInstance.loggedInStatus).toBe(true);
|
|
312
|
-
expect(authInstance.getSessionDetails).toBeCalled();
|
|
313
|
-
expect(authInstance.initSession).toBeCalled();
|
|
314
315
|
});
|
|
315
316
|
|
|
316
317
|
it('when user is not loggedIn', async () => {
|
|
@@ -321,7 +322,7 @@ describe('Unit test for auth', () => {
|
|
|
321
322
|
}));
|
|
322
323
|
|
|
323
324
|
await authInstance.doBasicAuth(embedConfig.doBasicAuth);
|
|
324
|
-
expect(tokenAuthService.fetchSessionInfoService).toBeCalled();
|
|
325
|
+
// expect(tokenAuthService.fetchSessionInfoService).toBeCalled();
|
|
325
326
|
expect(authService.fetchBasicAuthService).toBeCalled();
|
|
326
327
|
expect(authInstance.loggedInStatus).toBe(true);
|
|
327
328
|
});
|
|
@@ -349,10 +350,8 @@ describe('Unit test for auth', () => {
|
|
|
349
350
|
status: 200,
|
|
350
351
|
}),
|
|
351
352
|
);
|
|
352
|
-
jest.spyOn(
|
|
353
|
-
jest.spyOn(authInstance, 'initSession').mockReturnValue(null);
|
|
353
|
+
jest.spyOn(tokenAuthService, 'isActiveService').mockReturnValue(true);
|
|
354
354
|
await authInstance.doSamlAuth(embedConfig.doSamlAuth);
|
|
355
|
-
expect(tokenAuthService.fetchSessionInfoService).toBeCalled();
|
|
356
355
|
expect(window.location.hash).toBe('');
|
|
357
356
|
expect(authInstance.loggedInStatus).toBe(true);
|
|
358
357
|
});
|
|
@@ -360,7 +359,6 @@ describe('Unit test for auth', () => {
|
|
|
360
359
|
it('when user is not loggedIn & isAtSSORedirectUrl is true', async () => {
|
|
361
360
|
jest.spyOn(tokenAuthService, 'fetchSessionInfoService').mockImplementation(() => Promise.reject());
|
|
362
361
|
await authInstance.doSamlAuth(embedConfig.doSamlAuth);
|
|
363
|
-
expect(tokenAuthService.fetchSessionInfoService).toBeCalled();
|
|
364
362
|
expect(window.location.hash).toBe('');
|
|
365
363
|
expect(authInstance.loggedInStatus).toBe(false);
|
|
366
364
|
});
|
|
@@ -374,7 +372,6 @@ describe('Unit test for auth', () => {
|
|
|
374
372
|
});
|
|
375
373
|
jest.spyOn(tokenAuthService, 'fetchSessionInfoService').mockImplementation(() => Promise.reject());
|
|
376
374
|
await authInstance.doSamlAuth(embedConfig.doSamlAuth);
|
|
377
|
-
expect(tokenAuthService.fetchSessionInfoService).toBeCalled();
|
|
378
375
|
expect(global.window.location.href).toBe(samalLoginUrl);
|
|
379
376
|
});
|
|
380
377
|
|
|
@@ -387,14 +384,9 @@ describe('Unit test for auth', () => {
|
|
|
387
384
|
});
|
|
388
385
|
spyOn(authInstance, 'samlCompletionPromise');
|
|
389
386
|
global.window.open = jest.fn();
|
|
390
|
-
jest.spyOn(tokenAuthService, '
|
|
391
|
-
.
|
|
392
|
-
.
|
|
393
|
-
json: () => mockSessionInfo,
|
|
394
|
-
status: 200,
|
|
395
|
-
}));
|
|
396
|
-
jest.spyOn(authInstance, 'getSessionDetails').mockReturnValue(mockSessionInfo);
|
|
397
|
-
jest.spyOn(authInstance, 'initSession').mockReturnValue(null);
|
|
387
|
+
jest.spyOn(tokenAuthService, 'isActiveService')
|
|
388
|
+
.mockReturnValueOnce(false)
|
|
389
|
+
.mockReturnValueOnce(true);
|
|
398
390
|
expect(await authInstance.samlCompletionPromise).not.toBe(null);
|
|
399
391
|
expect(
|
|
400
392
|
await authInstance.doSamlAuth({
|
|
@@ -404,15 +396,13 @@ describe('Unit test for auth', () => {
|
|
|
404
396
|
document.getElementById('ts-auth-btn').click();
|
|
405
397
|
window.postMessage({ type: EmbedEvent.SAMLComplete }, '*');
|
|
406
398
|
await authInstance.samlCompletionPromise;
|
|
407
|
-
expect(
|
|
408
|
-
expect(authInstance.getSessionDetails).toBeCalled();
|
|
409
|
-
expect(authInstance.initSession).toBeCalled();
|
|
399
|
+
expect(authInstance.loggedInStatus).toBe(true);
|
|
410
400
|
});
|
|
411
401
|
});
|
|
412
402
|
|
|
413
403
|
describe('doOIDCAuth', () => {
|
|
414
404
|
afterEach(() => {
|
|
415
|
-
resetCachedAuthToken();
|
|
405
|
+
authTokenService.resetCachedAuthToken();
|
|
416
406
|
delete global.window;
|
|
417
407
|
global.window = Object.create(originalWindow);
|
|
418
408
|
global.window.open = jest.fn();
|
|
@@ -422,7 +412,6 @@ describe('Unit test for auth', () => {
|
|
|
422
412
|
it('when user is not loggedIn & isAtSSORedirectUrl is true', async () => {
|
|
423
413
|
jest.spyOn(tokenAuthService, 'fetchSessionInfoService').mockImplementation(() => Promise.reject());
|
|
424
414
|
await authInstance.doOIDCAuth(embedConfig.doOidcAuth);
|
|
425
|
-
expect(tokenAuthService.fetchSessionInfoService).toBeCalled();
|
|
426
415
|
expect(window.location.hash).toBe('');
|
|
427
416
|
expect(authInstance.loggedInStatus).toBe(false);
|
|
428
417
|
});
|
|
@@ -465,6 +454,7 @@ describe('Unit test for auth', () => {
|
|
|
465
454
|
|
|
466
455
|
it('authenticate: when authType is Basic', async () => {
|
|
467
456
|
jest.spyOn(authInstance, 'doBasicAuth');
|
|
457
|
+
jest.spyOn(authService, 'fetchBasicAuthService').mockImplementation(() => Promise.resolve({ status: 200, ok: true }));
|
|
468
458
|
await authInstance.authenticate(embedConfig.basicAuthSuccess);
|
|
469
459
|
expect(authInstance.doBasicAuth).toBeCalled();
|
|
470
460
|
expect(authInstance.loggedInStatus).toBe(true);
|
|
@@ -481,6 +471,7 @@ describe('Unit test for auth', () => {
|
|
|
481
471
|
});
|
|
482
472
|
|
|
483
473
|
it('doCookielessTokenAuth should resolve to true if valid token is passed', async () => {
|
|
474
|
+
jest.clearAllMocks();
|
|
484
475
|
jest.spyOn(authService, 'verifyTokenService').mockResolvedValueOnce(true);
|
|
485
476
|
const isLoggedIn = await authInstance.doCookielessTokenAuth(
|
|
486
477
|
embedConfig.doCookielessAuth('testToken'),
|
|
@@ -500,11 +491,11 @@ describe('Unit test for auth', () => {
|
|
|
500
491
|
authInstance.setAuthEE(testObject as any);
|
|
501
492
|
expect(authInstance.getAuthEE()).toBe(testObject);
|
|
502
493
|
});
|
|
503
|
-
it('getSessionDetails returns the correct details given sessionInfo', () => {
|
|
494
|
+
it('getSessionDetails returns the correct details given sessionInfo', async () => {
|
|
504
495
|
jest.clearAllMocks();
|
|
505
496
|
jest.restoreAllMocks();
|
|
506
497
|
|
|
507
|
-
|
|
498
|
+
jest.spyOn(tokenAuthService, 'fetchSessionInfoService').mockReturnValue({
|
|
508
499
|
userGUID: '1234',
|
|
509
500
|
releaseVersion: '1',
|
|
510
501
|
configInfo: {
|
|
@@ -515,13 +506,14 @@ describe('Unit test for auth', () => {
|
|
|
515
506
|
},
|
|
516
507
|
},
|
|
517
508
|
});
|
|
509
|
+
const details = await SessionService.getSessionInfo();
|
|
518
510
|
expect(details).toEqual(
|
|
519
511
|
expect.objectContaining({
|
|
520
512
|
mixpanelToken: 'devKey',
|
|
521
513
|
}),
|
|
522
514
|
);
|
|
523
515
|
|
|
524
|
-
|
|
516
|
+
jest.spyOn(tokenAuthService, 'fetchSessionInfoService').mockReturnValue({
|
|
525
517
|
configInfo: {
|
|
526
518
|
mixpanelConfig: {
|
|
527
519
|
devSdkKey: 'devKey',
|
|
@@ -530,10 +522,38 @@ describe('Unit test for auth', () => {
|
|
|
530
522
|
},
|
|
531
523
|
},
|
|
532
524
|
});
|
|
525
|
+
|
|
526
|
+
SessionService.resetCachedSessionInfo();
|
|
527
|
+
const details2 = await SessionService.getSessionInfo();
|
|
533
528
|
expect(details2).toEqual(
|
|
534
529
|
expect.objectContaining({
|
|
535
530
|
mixpanelToken: 'prodKey',
|
|
536
531
|
}),
|
|
537
532
|
);
|
|
538
533
|
});
|
|
534
|
+
|
|
535
|
+
test('notifyAuthSuccess if getSessionInfo returns data', async () => {
|
|
536
|
+
const dummyInfo = { test: 'dummy' };
|
|
537
|
+
jest.spyOn(SessionService, 'getSessionInfo').mockResolvedValueOnce(dummyInfo);
|
|
538
|
+
jest.spyOn(logger, 'error').mockResolvedValueOnce(true);
|
|
539
|
+
const emitSpy = jest.fn();
|
|
540
|
+
authInstance.setAuthEE({ emit: emitSpy } as any);
|
|
541
|
+
await authInstance.notifyAuthSuccess();
|
|
542
|
+
expect(logger.error).not.toBeCalled();
|
|
543
|
+
expect(emitSpy).toBeCalledWith(authInstance.AuthStatus.SUCCESS, dummyInfo);
|
|
544
|
+
authInstance.setAuthEE(null);
|
|
545
|
+
});
|
|
546
|
+
|
|
547
|
+
test('notifyAuthSuccess if getSessionInfo fails', async () => {
|
|
548
|
+
jest.spyOn(SessionService, 'getSessionInfo').mockImplementation(() => {
|
|
549
|
+
throw new Error('error');
|
|
550
|
+
});
|
|
551
|
+
jest.spyOn(logger, 'error');
|
|
552
|
+
const emitSpy = jest.fn();
|
|
553
|
+
authInstance.setAuthEE({ emit: emitSpy } as any);
|
|
554
|
+
await authInstance.notifyAuthSuccess();
|
|
555
|
+
expect(logger.error).toBeCalled();
|
|
556
|
+
expect(emitSpy).not.toBeCalled();
|
|
557
|
+
authInstance.setAuthEE(null);
|
|
558
|
+
});
|
|
539
559
|
});
|