• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

thoughtspot / visual-embed-sdk / #3894

26 May 2026 07:10AM UTC coverage: 90.679% (-3.9%) from 94.556%
#3894

push

web-flow
Merge f341d998b into 59702dc2b

1852 of 2199 branches covered (84.22%)

Branch coverage included in aggregate %.

0 of 1 new or added line in 1 file covered. (0.0%)

115 existing lines in 3 files now uncovered.

3528 of 3734 relevant lines covered (94.48%)

103.95 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.86
/src/utils/sessionInfoService.ts
1
import { getEmbedConfig } from '../embed/embedConfig';
18✔
2
import { fetchSessionInfoService, fetchPreauthInfoService } from './authService';
18✔
3

4
export type SessionInfo = {
5
    releaseVersion: string;
6
    userGUID: string;
7
    currentOrgId: number;
8
    privileges: string[];
9
    mixpanelToken: string;
10
    isPublicUser: boolean;
11
    clusterId: string;
12
    clusterName: string;
13
    [key: string]: any;
14
};
15

16
export type PreauthInfo = {
17
    info?: SessionInfo;
18
    headers: Record<string, string>;
19
    status: number;
20
    [key: string]: any;
21
};
22

23
let sessionInfo: null | SessionInfo = null;
18✔
24
let preauthInfo: null | PreauthInfo = null;
18✔
25

26
/**
27
 * Processes the session info response and returns the session info object.
28
 *  @param preauthInfoResp {any} Response from the session info API.
29
 *  @returns {PreauthInfo} The session info object.
30
 *  @example ```js
31
 *  const preauthInfoResp = await fetch(sessionInfoPath);
32
 *  const sessionInfo = await formatPreauthInfo(preauthInfoResp);
33
 *  console.log(sessionInfo);
34
 *  ```
35
 * @version SDK: 1.28.3 | ThoughtSpot: *
36
 */
37
export const formatPreauthInfo = async (preauthInfoResp: any): Promise<PreauthInfo> => {
18✔
38
    try {
17✔
39
        // Convert Headers to a plain object
40
        const headers: Record<string, string> = {};
17✔
41
        preauthInfoResp?.headers?.forEach((value: string, key: string) => {
17!
42
            headers[key] = value;
17✔
43
        });
44
        const data = await preauthInfoResp.json();
17✔
UNCOV
45
        return {
×
46
            ...data,
47
            status: 200,
48
            headers,
49
        };
50
    } catch (error) {
51
        return null;
17✔
52
    }
53
};
54

55
/**
56
 * Returns the session info object and caches it for future use.
57
 * Once fetched the session info object is cached and returned from the cache on
58
 * subsequent calls.
59
 * @example ```js
60
 * const preauthInfo = await getPreauthInfo();
61
 * console.log(preauthInfo);
62
 * ```
63
 * @version SDK: 1.28.3 | ThoughtSpot: *
64
 * @returns {Promise<SessionInfo>} The session info object.
65
 */
66
export async function getPreauthInfo(allowCache = true): Promise<PreauthInfo> {
18✔
67
    if (!allowCache || !preauthInfo) {
22!
68
        try {
22✔
69
            const host = getEmbedConfig().thoughtSpotHost;
22✔
70
            const sessionResponse = await fetchPreauthInfoService(host);
22✔
71
            const processedPreauthInfo = await formatPreauthInfo(sessionResponse);
17✔
72
            preauthInfo = processedPreauthInfo;
17✔
73
        } catch (error) {
74
            return null;
5✔
75
        }
76
    }
77

78
    return preauthInfo;
17✔
79
}
80

81
/**
82
 * Returns the cached session info object and caches it for future use.
83
 * Once fetched the session info object is cached and returned from the cache on
84
 * subsequent calls.
85
 * This cache is cleared when inti is called OR resetCachedSessionInfo is called.
86
 * @example ```js
87
 * const sessionInfo = await getSessionInfo();
88
 * console.log(sessionInfo);
89
 * ```
90
 * @version SDK: 1.28.3 | ThoughtSpot: *
91
 * @returns {Promise<SessionInfo>} The session info object.
92
 */
93
export async function getSessionInfo(): Promise<SessionInfo> {
18✔
94
    if (!sessionInfo) {
10✔
95
        const host = getEmbedConfig().thoughtSpotHost;
9✔
96
        const sessionResponse = await fetchSessionInfoService(host);
9✔
97
        const processedSessionInfo = getSessionDetails(sessionResponse);
3✔
98
        sessionInfo = processedSessionInfo;
3✔
99
    }
100
    return sessionInfo;
4✔
101
}
102

103
/**
104
 * Returns the cached session info object. If the client is not authenticated the
105
 * function will return null.
106
 * @example ```js
107
 * const sessionInfo = getCachedSessionInfo();
108
 * if (sessionInfo) {
109
 *   console.log(sessionInfo);
110
 * } else {
111
 *   console.log('Not authenticated');
112
 * }
113
 * ```
114
 * @returns {SessionInfo | null} The session info object.
115
 * @version SDK: 1.28.3 | ThoughtSpot: *
116
 */
117
export function getCachedSessionInfo(): SessionInfo | null {
18✔
118
    return sessionInfo;
1✔
119
}
120

121
/**
122
 * Processes the session info response and returns the session info object.
123
 *  @param sessionInfoResp {any} Response from the session info API.
124
 *  @returns {SessionInfo} The session info object.
125
 *  @example ```js
126
 *  const sessionInfoResp = await fetch(sessionInfoPath);
127
 *  const sessionInfo = getSessionDetails(sessionInfoResp);
128
 *  console.log(sessionInfo);
129
 *  ```
130
 * @version SDK: 1.28.3 | ThoughtSpot: *
131
 */
132
export const getSessionDetails = (sessionInfoResp: any): SessionInfo => {
18✔
133
    const devMixpanelToken = sessionInfoResp.configInfo.mixpanelConfig.devSdkKey;
3✔
134
    const prodMixpanelToken = sessionInfoResp.configInfo.mixpanelConfig.prodSdkKey;
3✔
135
    const mixpanelToken = sessionInfoResp.configInfo.mixpanelConfig.production
3✔
136
        ? prodMixpanelToken
137
        : devMixpanelToken;
138
    return {
3✔
139
        userGUID: sessionInfoResp.userGUID,
140
        mixpanelToken,
141
        isPublicUser: sessionInfoResp.configInfo.isPublicUser,
142
        releaseVersion: sessionInfoResp.releaseVersion,
143
        clusterId: sessionInfoResp.configInfo.selfClusterId,
144
        clusterName: sessionInfoResp.configInfo.selfClusterName,
145
        ...sessionInfoResp,
146
    };
147
};
148

149
/**
150
 * Resets the cached session info object and forces a new fetch on the next call.
151
 * @example ```js
152
 * resetCachedSessionInfo();
153
 * const sessionInfo = await getSessionInfo();
154
 * console.log(sessionInfo);
155
 * ```
156
 * @version SDK: 1.28.3 | ThoughtSpot: *
157
 * @returns {void}
158
 */
159
export function resetCachedSessionInfo(): void {
18✔
160
    sessionInfo = null;
88✔
161
}
162

163
/**
164
 * Resets the cached preauth info object and forces a new fetch on the next call.
165
 * @example ```js
166
 * resetCachedPreauthInfo();
167
 * const preauthInfo = await getPreauthInfo();
168
 * console.log(preauthInfo);
169
 * ```
170
 * @version SDK: 1.28.3 | ThoughtSpot: *
171
 * @returns {void}
172
 */
173
export function resetCachedPreauthInfo(): void {
18✔
174
    preauthInfo = null;
50✔
175
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc