@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.
Files changed (229) hide show
  1. package/cjs/package.json +1 -1
  2. package/cjs/src/auth.d.ts +14 -17
  3. package/cjs/src/auth.d.ts.map +1 -1
  4. package/cjs/src/auth.js +45 -59
  5. package/cjs/src/auth.js.map +1 -1
  6. package/cjs/src/auth.spec.d.ts +12 -0
  7. package/cjs/src/auth.spec.d.ts.map +1 -1
  8. package/cjs/src/auth.spec.js +89 -67
  9. package/cjs/src/auth.spec.js.map +1 -1
  10. package/cjs/src/authToken.d.ts +1 -1
  11. package/cjs/src/authToken.d.ts.map +1 -1
  12. package/cjs/src/authToken.js +10 -4
  13. package/cjs/src/authToken.js.map +1 -1
  14. package/cjs/src/embed/app.spec.js +4 -2
  15. package/cjs/src/embed/app.spec.js.map +1 -1
  16. package/cjs/src/embed/base.d.ts.map +1 -1
  17. package/cjs/src/embed/base.js +2 -0
  18. package/cjs/src/embed/base.js.map +1 -1
  19. package/cjs/src/embed/base.spec.js +1 -0
  20. package/cjs/src/embed/base.spec.js.map +1 -1
  21. package/cjs/src/embed/embed.spec.js +3 -0
  22. package/cjs/src/embed/embed.spec.js.map +1 -1
  23. package/cjs/src/embed/events.spec.js +3 -0
  24. package/cjs/src/embed/events.spec.js.map +1 -1
  25. package/cjs/src/embed/liveboard.spec.js +2 -0
  26. package/cjs/src/embed/liveboard.spec.js.map +1 -1
  27. package/cjs/src/embed/pinboard.spec.js +3 -0
  28. package/cjs/src/embed/pinboard.spec.js.map +1 -1
  29. package/cjs/src/embed/sage.spec.js +3 -0
  30. package/cjs/src/embed/sage.spec.js.map +1 -1
  31. package/cjs/src/embed/search.spec.js +1 -0
  32. package/cjs/src/embed/search.spec.js.map +1 -1
  33. package/cjs/src/embed/ts-embed-trigger.spec.js +3 -0
  34. package/cjs/src/embed/ts-embed-trigger.spec.js.map +1 -1
  35. package/cjs/src/embed/ts-embed.d.ts.map +1 -1
  36. package/cjs/src/embed/ts-embed.js +7 -0
  37. package/cjs/src/embed/ts-embed.js.map +1 -1
  38. package/cjs/src/embed/ts-embed.spec.js +7 -0
  39. package/cjs/src/embed/ts-embed.spec.js.map +1 -1
  40. package/cjs/src/index.d.ts +2 -1
  41. package/cjs/src/index.d.ts.map +1 -1
  42. package/cjs/src/index.js +2 -1
  43. package/cjs/src/index.js.map +1 -1
  44. package/cjs/src/mixpanel-service.d.ts +2 -1
  45. package/cjs/src/mixpanel-service.d.ts.map +1 -1
  46. package/cjs/src/mixpanel-service.js +1 -0
  47. package/cjs/src/mixpanel-service.js.map +1 -1
  48. package/cjs/src/mixpanel-service.spec.js +7 -0
  49. package/cjs/src/mixpanel-service.spec.js.map +1 -1
  50. package/cjs/src/react/index.d.ts +1 -1
  51. package/cjs/src/react/index.d.ts.map +1 -1
  52. package/cjs/src/react/index.js +2 -1
  53. package/cjs/src/react/index.js.map +1 -1
  54. package/cjs/src/react/index.spec.js +6 -0
  55. package/cjs/src/react/index.spec.js.map +1 -1
  56. package/cjs/src/types.d.ts +1 -1
  57. package/cjs/src/types.js +1 -1
  58. package/cjs/src/utils/authService/authService.d.ts +1 -0
  59. package/cjs/src/utils/authService/authService.d.ts.map +1 -1
  60. package/cjs/src/utils/authService/authService.js +1 -0
  61. package/cjs/src/utils/authService/authService.js.map +1 -1
  62. package/cjs/src/utils/authService/authService.spec.js +18 -5
  63. package/cjs/src/utils/authService/authService.spec.js.map +1 -1
  64. package/cjs/src/utils/authService/tokenizedAuthService.d.ts +15 -2
  65. package/cjs/src/utils/authService/tokenizedAuthService.d.ts.map +1 -1
  66. package/cjs/src/utils/authService/tokenizedAuthService.js +39 -9
  67. package/cjs/src/utils/authService/tokenizedAuthService.js.map +1 -1
  68. package/cjs/src/utils/authService/tokenizedAuthService.spec.d.ts +2 -0
  69. package/cjs/src/utils/authService/tokenizedAuthService.spec.d.ts.map +1 -0
  70. package/cjs/src/utils/authService/tokenizedAuthService.spec.js +32 -0
  71. package/cjs/src/utils/authService/tokenizedAuthService.spec.js.map +1 -0
  72. package/cjs/src/utils/graphql/answerService/answerService.d.ts +10 -0
  73. package/cjs/src/utils/graphql/answerService/answerService.d.ts.map +1 -1
  74. package/cjs/src/utils/graphql/answerService/answerService.js +10 -0
  75. package/cjs/src/utils/graphql/answerService/answerService.js.map +1 -1
  76. package/cjs/src/utils/processData.js +2 -2
  77. package/cjs/src/utils/processData.js.map +1 -1
  78. package/cjs/src/utils/processData.spec.js +3 -2
  79. package/cjs/src/utils/processData.spec.js.map +1 -1
  80. package/cjs/src/utils/sessionInfoService.d.ts +66 -0
  81. package/cjs/src/utils/sessionInfoService.d.ts.map +1 -0
  82. package/cjs/src/utils/sessionInfoService.js +92 -0
  83. package/cjs/src/utils/sessionInfoService.js.map +1 -0
  84. package/dist/src/auth.d.ts +14 -17
  85. package/dist/src/auth.d.ts.map +1 -1
  86. package/dist/src/auth.spec.d.ts +12 -0
  87. package/dist/src/auth.spec.d.ts.map +1 -1
  88. package/dist/src/authToken.d.ts +1 -1
  89. package/dist/src/authToken.d.ts.map +1 -1
  90. package/dist/src/embed/base.d.ts.map +1 -1
  91. package/dist/src/embed/ts-embed.d.ts.map +1 -1
  92. package/dist/src/index.d.ts +2 -1
  93. package/dist/src/index.d.ts.map +1 -1
  94. package/dist/src/mixpanel-service.d.ts +2 -1
  95. package/dist/src/mixpanel-service.d.ts.map +1 -1
  96. package/dist/src/react/index.d.ts +1 -1
  97. package/dist/src/react/index.d.ts.map +1 -1
  98. package/dist/src/types.d.ts +1 -1
  99. package/dist/src/utils/authService/authService.d.ts +1 -0
  100. package/dist/src/utils/authService/authService.d.ts.map +1 -1
  101. package/dist/src/utils/authService/tokenizedAuthService.d.ts +15 -2
  102. package/dist/src/utils/authService/tokenizedAuthService.d.ts.map +1 -1
  103. package/dist/src/utils/authService/tokenizedAuthService.spec.d.ts +2 -0
  104. package/dist/src/utils/authService/tokenizedAuthService.spec.d.ts.map +1 -0
  105. package/dist/src/utils/graphql/answerService/answerService.d.ts +10 -0
  106. package/dist/src/utils/graphql/answerService/answerService.d.ts.map +1 -1
  107. package/dist/src/utils/sessionInfoService.d.ts +66 -0
  108. package/dist/src/utils/sessionInfoService.d.ts.map +1 -0
  109. package/dist/tsembed-react.es.js +154 -58
  110. package/dist/tsembed-react.js +154 -57
  111. package/dist/tsembed.es.js +162 -69
  112. package/dist/tsembed.js +162 -69
  113. package/dist/visual-embed-sdk-react-full.d.ts +93 -20
  114. package/dist/visual-embed-sdk-react.d.ts +93 -20
  115. package/dist/visual-embed-sdk.d.ts +93 -20
  116. package/lib/package.json +1 -1
  117. package/lib/src/auth.d.ts +14 -17
  118. package/lib/src/auth.d.ts.map +1 -1
  119. package/lib/src/auth.js +44 -56
  120. package/lib/src/auth.js.map +1 -1
  121. package/lib/src/auth.spec.d.ts +12 -0
  122. package/lib/src/auth.spec.d.ts.map +1 -1
  123. package/lib/src/auth.spec.js +88 -66
  124. package/lib/src/auth.spec.js.map +1 -1
  125. package/lib/src/authToken.d.ts +1 -1
  126. package/lib/src/authToken.d.ts.map +1 -1
  127. package/lib/src/authToken.js +10 -4
  128. package/lib/src/authToken.js.map +1 -1
  129. package/lib/src/embed/app.spec.js +4 -2
  130. package/lib/src/embed/app.spec.js.map +1 -1
  131. package/lib/src/embed/base.d.ts.map +1 -1
  132. package/lib/src/embed/base.js +3 -1
  133. package/lib/src/embed/base.js.map +1 -1
  134. package/lib/src/embed/base.spec.js +1 -0
  135. package/lib/src/embed/base.spec.js.map +1 -1
  136. package/lib/src/embed/embed.spec.js +2 -0
  137. package/lib/src/embed/embed.spec.js.map +1 -1
  138. package/lib/src/embed/events.spec.js +2 -0
  139. package/lib/src/embed/events.spec.js.map +1 -1
  140. package/lib/src/embed/liveboard.spec.js +2 -0
  141. package/lib/src/embed/liveboard.spec.js.map +1 -1
  142. package/lib/src/embed/pinboard.spec.js +2 -0
  143. package/lib/src/embed/pinboard.spec.js.map +1 -1
  144. package/lib/src/embed/sage.spec.js +2 -0
  145. package/lib/src/embed/sage.spec.js.map +1 -1
  146. package/lib/src/embed/search.spec.js +1 -0
  147. package/lib/src/embed/search.spec.js.map +1 -1
  148. package/lib/src/embed/ts-embed-trigger.spec.js +2 -0
  149. package/lib/src/embed/ts-embed-trigger.spec.js.map +1 -1
  150. package/lib/src/embed/ts-embed.d.ts.map +1 -1
  151. package/lib/src/embed/ts-embed.js +7 -0
  152. package/lib/src/embed/ts-embed.js.map +1 -1
  153. package/lib/src/embed/ts-embed.spec.js +7 -0
  154. package/lib/src/embed/ts-embed.spec.js.map +1 -1
  155. package/lib/src/index.d.ts +2 -1
  156. package/lib/src/index.d.ts.map +1 -1
  157. package/lib/src/index.js +2 -1
  158. package/lib/src/index.js.map +1 -1
  159. package/lib/src/mixpanel-service.d.ts +2 -1
  160. package/lib/src/mixpanel-service.d.ts.map +1 -1
  161. package/lib/src/mixpanel-service.js +1 -0
  162. package/lib/src/mixpanel-service.js.map +1 -1
  163. package/lib/src/mixpanel-service.spec.js +7 -0
  164. package/lib/src/mixpanel-service.spec.js.map +1 -1
  165. package/lib/src/react/index.d.ts +1 -1
  166. package/lib/src/react/index.d.ts.map +1 -1
  167. package/lib/src/react/index.js +1 -1
  168. package/lib/src/react/index.js.map +1 -1
  169. package/lib/src/react/index.spec.js +6 -0
  170. package/lib/src/react/index.spec.js.map +1 -1
  171. package/lib/src/types.d.ts +1 -1
  172. package/lib/src/types.js +1 -1
  173. package/lib/src/utils/authService/authService.d.ts +1 -0
  174. package/lib/src/utils/authService/authService.d.ts.map +1 -1
  175. package/lib/src/utils/authService/authService.js +1 -0
  176. package/lib/src/utils/authService/authService.js.map +1 -1
  177. package/lib/src/utils/authService/authService.spec.js +18 -5
  178. package/lib/src/utils/authService/authService.spec.js.map +1 -1
  179. package/lib/src/utils/authService/tokenizedAuthService.d.ts +15 -2
  180. package/lib/src/utils/authService/tokenizedAuthService.d.ts.map +1 -1
  181. package/lib/src/utils/authService/tokenizedAuthService.js +37 -8
  182. package/lib/src/utils/authService/tokenizedAuthService.js.map +1 -1
  183. package/lib/src/utils/authService/tokenizedAuthService.spec.d.ts +2 -0
  184. package/lib/src/utils/authService/tokenizedAuthService.spec.d.ts.map +1 -0
  185. package/lib/src/utils/authService/tokenizedAuthService.spec.js +29 -0
  186. package/lib/src/utils/authService/tokenizedAuthService.spec.js.map +1 -0
  187. package/lib/src/utils/graphql/answerService/answerService.d.ts +10 -0
  188. package/lib/src/utils/graphql/answerService/answerService.d.ts.map +1 -1
  189. package/lib/src/utils/graphql/answerService/answerService.js +10 -0
  190. package/lib/src/utils/graphql/answerService/answerService.js.map +1 -1
  191. package/lib/src/utils/processData.js +3 -3
  192. package/lib/src/utils/processData.js.map +1 -1
  193. package/lib/src/utils/processData.spec.js +3 -2
  194. package/lib/src/utils/processData.spec.js.map +1 -1
  195. package/lib/src/utils/sessionInfoService.d.ts +66 -0
  196. package/lib/src/utils/sessionInfoService.d.ts.map +1 -0
  197. package/lib/src/utils/sessionInfoService.js +85 -0
  198. package/lib/src/utils/sessionInfoService.js.map +1 -0
  199. package/lib/src/visual-embed-sdk.d.ts +98 -21
  200. package/package.json +1 -1
  201. package/src/auth.spec.ts +92 -72
  202. package/src/auth.ts +46 -68
  203. package/src/authToken.ts +9 -4
  204. package/src/embed/app.spec.ts +4 -2
  205. package/src/embed/base.spec.ts +1 -0
  206. package/src/embed/base.ts +3 -0
  207. package/src/embed/embed.spec.ts +2 -0
  208. package/src/embed/events.spec.ts +2 -0
  209. package/src/embed/liveboard.spec.ts +2 -0
  210. package/src/embed/pinboard.spec.ts +2 -0
  211. package/src/embed/sage.spec.ts +3 -0
  212. package/src/embed/search.spec.ts +1 -0
  213. package/src/embed/ts-embed-trigger.spec.ts +3 -0
  214. package/src/embed/ts-embed.spec.ts +8 -0
  215. package/src/embed/ts-embed.ts +7 -0
  216. package/src/index.ts +2 -1
  217. package/src/mixpanel-service.spec.ts +12 -3
  218. package/src/mixpanel-service.ts +3 -1
  219. package/src/react/index.spec.tsx +7 -0
  220. package/src/react/index.tsx +1 -0
  221. package/src/types.ts +1 -1
  222. package/src/utils/authService/authService.spec.ts +18 -5
  223. package/src/utils/authService/authService.ts +1 -0
  224. package/src/utils/authService/tokenizedAuthService.spec.ts +36 -0
  225. package/src/utils/authService/tokenizedAuthService.ts +38 -8
  226. package/src/utils/graphql/answerService/answerService.ts +10 -0
  227. package/src/utils/processData.spec.ts +3 -2
  228. package/src/utils/processData.ts +3 -3
  229. 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, getSessionInfo } from '@thoughtspot/visual-embed-sdk/auth';
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
- * Return releaseVersion if available
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 getReleaseVersion(): string;
1526
+ export function postLoginService(): Promise<void>;
1525
1527
  /**
1526
- * Return a promise that resolves with the session information when
1527
- * authentication is successful. And info is available.
1528
- *
1529
- * @group Global methods
1528
+ * Return releaseVersion if available
1530
1529
  */
1531
- export function getSessionInfo(): Promise<sessionInfoInterface>;
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
- export {};
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.getexportrequestforcurrentpinboard).then(
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: any): void;
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 const getAuthenticationToken: (embedConfig: EmbedConfig) => Promise<string>;
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thoughtspot/visual-embed-sdk",
3
- "version": "1.29.0-alpha.8",
3
+ "version": "1.29.0-alpha.SCAL-205893-1",
4
4
  "description": "ThoughtSpot Embed SDK",
5
5
  "module": "lib/src/index.js",
6
6
  "main": "dist/tsembed.js",
package/src/auth.spec.ts CHANGED
@@ -1,12 +1,14 @@
1
1
  import * as authInstance from './auth';
2
- import * as authService from './utils/authService/authService';
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 { AuthType, EmbedEvent } from './types';
4
+ import * as mixPanelService from './mixpanel-service';
8
5
  import { executeAfterWait } from './test/test-utils';
9
- import { resetCachedAuthToken } from './authToken';
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.AuthServer,
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(mixPanelService, 'initMixpanel').mockImplementation(() => Promise.resolve());
129
- authInstance.initSession(mockSessionInfo);
130
- const sessionInfo = await authInstance.getSessionInfo();
131
- expect(sessionInfo).toStrictEqual(mockSessionInfo);
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.initSession(mockSessionInfo);
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(tokenAuthService, 'fetchSessionInfoService').mockImplementation(async () => ({
167
- json: () => mockSessionInfo,
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(tokenAuthService.fetchSessionInfoService).toBeCalled();
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, 'fetchSessionInfoService').mockImplementation(() => false);
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, 'fetchSessionInfoService').mockImplementation(() => false);
197
- jest.spyOn(authService, 'fetchAuthTokenService').mockImplementation(() => Promise.resolve({ text: () => Promise.resolve('abc') }));
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(tokenAuthService.fetchSessionInfoService).toBeCalled();
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.fetchSessionInfoService).toHaveBeenCalledTimes(2);
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(checkReleaseVersionInBetaInstance, 'checkReleaseVersionInBeta');
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(authInstance, 'getSessionDetails').mockReturnValue(mockSessionInfo);
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, 'fetchSessionInfoService')
391
- .mockImplementationOnce(() => Promise.reject())
392
- .mockImplementationOnce(async () => ({
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(tokenAuthService.fetchSessionInfoService).toBeCalled();
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
- const details = authInstance.getSessionDetails({
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
- const details2 = authInstance.getSessionDetails({
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
  });