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

thoughtspot / visual-embed-sdk / #1283

16 Dec 2024 01:12PM UTC coverage: 93.407% (-0.3%) from 93.732%
#1283

Pull #66

ajeet-lakhani-ts
SCAL-233969: InfoSucces declaration correction
Pull Request #66: SCAL-233969: Optimise info call (WIP)

880 of 1011 branches covered (87.04%)

Branch coverage included in aggregate %.

24 of 30 new or added lines in 5 files covered. (80.0%)

19 existing lines in 2 files now uncovered.

2322 of 2417 relevant lines covered (96.07%)

55.04 hits per line

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

77.05
/src/utils/authService/tokenizedAuthService.ts
1
import { tokenizedFetch } from '../../tokenizedFetch';
19✔
2
import { logger } from '../logger';
19✔
3
import { EndPoints } from './authService';
19✔
4

5
/**
6
 *
7
 * @param url
8
 * @param options
9
 */
10
function tokenizedFailureLoggedFetch(url: string, options: RequestInit = {}): Promise<Response> {
2✔
11
    return tokenizedFetch(url, options).then(async (r) => {
3✔
12
        if (!r.ok && r.type !== 'opaqueredirect' && r.type !== 'opaque') {
3✔
13
            logger.error(`Failed to fetch ${url}`, await r.text?.());
1!
14
        }
15
        return r;
3✔
16
    });
17
}
18

19
/**
20
 * Fetches the session info from the ThoughtSpot server.
21
 * @param thoughtspotHost
22
 * @returns {Promise<any>}
23
 * @example
24
 * ```js
25
 *  const response = await sessionInfoService();
26
 * ```
27
 */
28
export async function fetchPreauthInfoService(thoughtspotHost: string): Promise<any> {
19✔
29
    const sessionInfoPath = `${thoughtspotHost}${EndPoints.PREAUTH_INFO}`;
2✔
30
    const response = await tokenizedFailureLoggedFetch(sessionInfoPath);
2✔
31
    if (!response.ok) {
2✔
32
        throw new Error(`Failed to fetch auth info: ${response.statusText}`);
1✔
33
    }
34

35
    return response;
1✔
36
}
37

38
/**
39
 * Fetches the session info from the ThoughtSpot server.
40
 * @param thoughtspotHost
41
 * @returns {Promise<any>}
42
 * @example
43
 * ```js
44
 *  const response = await sessionInfoService();
45
 * ```
46
 */
47
export async function fetchV1InfoService(thoughtspotHost: string): Promise<any> {
19✔
UNCOV
48
    const sessionInfoPath = `${thoughtspotHost}${EndPoints.SESSION_INFO}`;
×
UNCOV
49
    const response = await tokenizedFailureLoggedFetch(sessionInfoPath);
×
UNCOV
50
    if (!response.ok) {
×
UNCOV
51
        throw new Error(`Failed to fetch session info: ${response.statusText}`);
×
52
    }
53

NEW
54
    return response;
×
55
}
56

57
/**
58
 * Fetches the session info from the ThoughtSpot server.
59
 * @param thoughtspotHost
60
 * @returns {Promise<any>}
61
 * @example
62
 * ```js
63
 *  const response = await sessionInfoService();
64
 * ```
65
 */
66
export async function fetchSessionInfoService(thoughtspotHost: string): Promise<any> {
19✔
67
    try {
2✔
68
        const response = await fetchPreauthInfoService(thoughtspotHost);
2✔
69

70
        // Convert Headers to a plain object
71
        const headers: Record<string, string> = {};
1✔
72
        response?.headers?.forEach((value: string, key: string) => {
1!
NEW
73
            headers[key] = value;
×
74
        });
75
        const data = await response.json();
1✔
76

77
        return {
1✔
78
            ...data,
79
            status: 200,
80
            headers,
81
        };
82
    } catch (error) {
83
        if (error.status === 404) {
1!
NEW
84
            const response = await fetchV1InfoService(thoughtspotHost);
×
NEW
85
            const data = await response.json();
×
86

NEW
87
            return data;
×
88
        }
89

90
        return {};
1✔
91
    }
92
}
93

94
/**
95
 *
96
 * @param thoughtSpotHost
97
 */
98
export async function fetchLogoutService(thoughtSpotHost: string): Promise<any> {
19✔
99
    return tokenizedFailureLoggedFetch(`${thoughtSpotHost}${EndPoints.LOGOUT}`, {
1✔
100
        credentials: 'include',
101
        method: 'POST',
102
        headers: {
103
            'x-requested-by': 'ThoughtSpot',
104
        },
105
    });
106
}
107

108
/**
109
 * Is active service to check if the user is logged in.
110
 * @param thoughtSpotHost
111
 * @version SDK: 1.28.4 | ThoughtSpot: *
112
 */
113
export async function isActiveService(thoughtSpotHost: string): Promise<boolean> {
19✔
114
    const isActiveUrl = `${thoughtSpotHost}${EndPoints.IS_ACTIVE}`;
3✔
115
    try {
3✔
116
        const res = await tokenizedFetch(isActiveUrl, {
3✔
117
            credentials: 'include',
118
        });
119
        return res.ok;
2✔
120
    } catch (e) {
121
        logger.warn(`Is Logged In Service failed : ${e.message}`);
1✔
122
    }
123

124
    return false;
1✔
125
}
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

© 2025 Coveralls, Inc