@thoughtspot/visual-embed-sdk 1.35.14 → 1.36.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 (127) hide show
  1. package/cjs/package.json +2 -3
  2. package/cjs/src/auth.d.ts +5 -0
  3. package/cjs/src/auth.d.ts.map +1 -1
  4. package/cjs/src/auth.js +7 -0
  5. package/cjs/src/auth.js.map +1 -1
  6. package/cjs/src/css-variables.d.ts +8 -0
  7. package/cjs/src/css-variables.d.ts.map +1 -1
  8. package/cjs/src/embed/hostEventClient/host-event-client.d.ts.map +1 -1
  9. package/cjs/src/embed/hostEventClient/host-event-client.js +8 -3
  10. package/cjs/src/embed/hostEventClient/host-event-client.js.map +1 -1
  11. package/cjs/src/embed/hostEventClient/host-event-client.spec.js +54 -0
  12. package/cjs/src/embed/hostEventClient/host-event-client.spec.js.map +1 -1
  13. package/cjs/src/embed/ts-embed.d.ts +6 -0
  14. package/cjs/src/embed/ts-embed.d.ts.map +1 -1
  15. package/cjs/src/embed/ts-embed.js +27 -0
  16. package/cjs/src/embed/ts-embed.js.map +1 -1
  17. package/cjs/src/embed/ts-embed.spec.d.ts.map +1 -1
  18. package/cjs/src/embed/ts-embed.spec.js +73 -1
  19. package/cjs/src/embed/ts-embed.spec.js.map +1 -1
  20. package/cjs/src/react/index.spec.js +2 -2
  21. package/cjs/src/react/index.spec.js.map +1 -1
  22. package/cjs/src/types.d.ts +82 -7
  23. package/cjs/src/types.d.ts.map +1 -1
  24. package/cjs/src/types.js +81 -7
  25. package/cjs/src/types.js.map +1 -1
  26. package/cjs/src/utils/authService/authService.d.ts +1 -0
  27. package/cjs/src/utils/authService/authService.d.ts.map +1 -1
  28. package/cjs/src/utils/authService/authService.js +1 -0
  29. package/cjs/src/utils/authService/authService.js.map +1 -1
  30. package/cjs/src/utils/authService/index.d.ts +1 -1
  31. package/cjs/src/utils/authService/index.d.ts.map +1 -1
  32. package/cjs/src/utils/authService/index.js +2 -1
  33. package/cjs/src/utils/authService/index.js.map +1 -1
  34. package/cjs/src/utils/authService/tokenizedAuthService.d.ts +10 -0
  35. package/cjs/src/utils/authService/tokenizedAuthService.d.ts.map +1 -1
  36. package/cjs/src/utils/authService/tokenizedAuthService.js +27 -1
  37. package/cjs/src/utils/authService/tokenizedAuthService.js.map +1 -1
  38. package/cjs/src/utils/authService/tokenizedAuthService.spec.js +58 -1
  39. package/cjs/src/utils/authService/tokenizedAuthService.spec.js.map +1 -1
  40. package/cjs/src/utils/sessionInfoService.d.ts +30 -0
  41. package/cjs/src/utils/sessionInfoService.d.ts.map +1 -1
  42. package/cjs/src/utils/sessionInfoService.js +59 -1
  43. package/cjs/src/utils/sessionInfoService.js.map +1 -1
  44. package/dist/index-CR5u7BMC.js +7370 -0
  45. package/dist/src/auth.d.ts +5 -0
  46. package/dist/src/auth.d.ts.map +1 -1
  47. package/dist/src/css-variables.d.ts +8 -0
  48. package/dist/src/css-variables.d.ts.map +1 -1
  49. package/dist/src/embed/hostEventClient/host-event-client.d.ts.map +1 -1
  50. package/dist/src/embed/ts-embed.d.ts +6 -0
  51. package/dist/src/embed/ts-embed.d.ts.map +1 -1
  52. package/dist/src/embed/ts-embed.spec.d.ts.map +1 -1
  53. package/dist/src/types.d.ts +82 -7
  54. package/dist/src/types.d.ts.map +1 -1
  55. package/dist/src/utils/authService/authService.d.ts +1 -0
  56. package/dist/src/utils/authService/authService.d.ts.map +1 -1
  57. package/dist/src/utils/authService/index.d.ts +1 -1
  58. package/dist/src/utils/authService/index.d.ts.map +1 -1
  59. package/dist/src/utils/authService/tokenizedAuthService.d.ts +10 -0
  60. package/dist/src/utils/authService/tokenizedAuthService.d.ts.map +1 -1
  61. package/dist/src/utils/sessionInfoService.d.ts +30 -0
  62. package/dist/src/utils/sessionInfoService.d.ts.map +1 -1
  63. package/dist/tsembed-react.es.js +206 -13
  64. package/dist/tsembed-react.js +205 -12
  65. package/dist/tsembed.es.js +207 -13
  66. package/dist/tsembed.js +206 -12
  67. package/dist/visual-embed-sdk-react-full.d.ts +125 -7
  68. package/dist/visual-embed-sdk-react.d.ts +125 -7
  69. package/dist/visual-embed-sdk.d.ts +125 -7
  70. package/lib/package.json +2 -3
  71. package/lib/src/auth.d.ts +5 -0
  72. package/lib/src/auth.d.ts.map +1 -1
  73. package/lib/src/auth.js +8 -1
  74. package/lib/src/auth.js.map +1 -1
  75. package/lib/src/css-variables.d.ts +8 -0
  76. package/lib/src/css-variables.d.ts.map +1 -1
  77. package/lib/src/embed/hostEventClient/host-event-client.d.ts.map +1 -1
  78. package/lib/src/embed/hostEventClient/host-event-client.js +8 -3
  79. package/lib/src/embed/hostEventClient/host-event-client.js.map +1 -1
  80. package/lib/src/embed/hostEventClient/host-event-client.spec.js +54 -0
  81. package/lib/src/embed/hostEventClient/host-event-client.spec.js.map +1 -1
  82. package/lib/src/embed/ts-embed.d.ts +6 -0
  83. package/lib/src/embed/ts-embed.d.ts.map +1 -1
  84. package/lib/src/embed/ts-embed.js +27 -0
  85. package/lib/src/embed/ts-embed.js.map +1 -1
  86. package/lib/src/embed/ts-embed.spec.d.ts.map +1 -1
  87. package/lib/src/embed/ts-embed.spec.js +73 -1
  88. package/lib/src/embed/ts-embed.spec.js.map +1 -1
  89. package/lib/src/react/index.spec.js +2 -2
  90. package/lib/src/react/index.spec.js.map +1 -1
  91. package/lib/src/types.d.ts +82 -7
  92. package/lib/src/types.d.ts.map +1 -1
  93. package/lib/src/types.js +81 -7
  94. package/lib/src/types.js.map +1 -1
  95. package/lib/src/utils/authService/authService.d.ts +1 -0
  96. package/lib/src/utils/authService/authService.d.ts.map +1 -1
  97. package/lib/src/utils/authService/authService.js +1 -0
  98. package/lib/src/utils/authService/authService.js.map +1 -1
  99. package/lib/src/utils/authService/index.d.ts +1 -1
  100. package/lib/src/utils/authService/index.d.ts.map +1 -1
  101. package/lib/src/utils/authService/index.js +1 -1
  102. package/lib/src/utils/authService/index.js.map +1 -1
  103. package/lib/src/utils/authService/tokenizedAuthService.d.ts +10 -0
  104. package/lib/src/utils/authService/tokenizedAuthService.d.ts.map +1 -1
  105. package/lib/src/utils/authService/tokenizedAuthService.js +25 -0
  106. package/lib/src/utils/authService/tokenizedAuthService.js.map +1 -1
  107. package/lib/src/utils/authService/tokenizedAuthService.spec.js +59 -2
  108. package/lib/src/utils/authService/tokenizedAuthService.spec.js.map +1 -1
  109. package/lib/src/utils/sessionInfoService.d.ts +30 -0
  110. package/lib/src/utils/sessionInfoService.d.ts.map +1 -1
  111. package/lib/src/utils/sessionInfoService.js +57 -1
  112. package/lib/src/utils/sessionInfoService.js.map +1 -1
  113. package/lib/src/visual-embed-sdk.d.ts +125 -7
  114. package/package.json +2 -3
  115. package/src/auth.ts +8 -1
  116. package/src/css-variables.ts +10 -0
  117. package/src/embed/hostEventClient/host-event-client.spec.ts +61 -0
  118. package/src/embed/hostEventClient/host-event-client.ts +8 -3
  119. package/src/embed/ts-embed.spec.ts +95 -1
  120. package/src/embed/ts-embed.ts +31 -0
  121. package/src/react/index.spec.tsx +2 -2
  122. package/src/types.ts +83 -7
  123. package/src/utils/authService/authService.ts +1 -0
  124. package/src/utils/authService/index.ts +5 -1
  125. package/src/utils/authService/tokenizedAuthService.spec.ts +66 -2
  126. package/src/utils/authService/tokenizedAuthService.ts +26 -0
  127. package/src/utils/sessionInfoService.ts +64 -1
@@ -3,6 +3,7 @@ import { logger } from '../logger';
3
3
  export const EndPoints = {
4
4
  AUTH_VERIFICATION: '/callosum/v1/session/info',
5
5
  SESSION_INFO: '/callosum/v1/session/info',
6
+ PREAUTH_INFO: '/prism/preauth/info',
6
7
  SAML_LOGIN_TEMPLATE: (targetUrl: string) => `/callosum/v1/saml/login?targetURLPath=${targetUrl}`,
7
8
  OIDC_LOGIN_TEMPLATE: (targetUrl: string) => `/callosum/v1/oidc/login?targetURLPath=${targetUrl}`,
8
9
  TOKEN_LOGIN: '/callosum/v1/session/login/token',
@@ -6,4 +6,8 @@ export {
6
6
  fetchBasicAuthService,
7
7
  verifyTokenService,
8
8
  } from './authService';
9
- export { fetchLogoutService, fetchSessionInfoService } from './tokenizedAuthService';
9
+ export {
10
+ fetchLogoutService,
11
+ fetchSessionInfoService,
12
+ fetchPreauthInfoService,
13
+ } from './tokenizedAuthService';
@@ -1,9 +1,16 @@
1
1
  import * as tokenizedFetchModule from '../../tokenizedFetch';
2
- import { isActiveService } from './tokenizedAuthService';
2
+ import { isActiveService, fetchSessionInfoService, fetchPreauthInfoService } from './tokenizedAuthService';
3
3
  import { logger } from '../logger';
4
+ import { EndPoints } from './authService';
5
+
6
+ const thoughtspotHost = 'http://thoughtspotHost';
4
7
 
5
8
  describe('tokenizedAuthService', () => {
6
- test('isActiveService is fetch returns ok', async () => {
9
+ afterEach(() => {
10
+ jest.clearAllMocks();
11
+ jest.restoreAllMocks();
12
+ });
13
+ test('isActiveService if fetch returns ok', async () => {
7
14
  jest.spyOn(tokenizedFetchModule, 'tokenizedFetch').mockResolvedValueOnce({
8
15
  ok: true,
9
16
  });
@@ -34,3 +41,60 @@ describe('tokenizedAuthService', () => {
34
41
  expect(logger.warn).toHaveBeenCalled();
35
42
  });
36
43
  });
44
+
45
+ describe('fetchPreauthInfoService', () => {
46
+ afterEach(() => {
47
+ jest.clearAllMocks();
48
+ jest.restoreAllMocks();
49
+ });
50
+
51
+ test('fetchPreauthInfoService if fetch returns ok', async () => {
52
+ const mockFetch = jest.spyOn(tokenizedFetchModule, 'tokenizedFetch');
53
+
54
+ // Mock for fetchPreauthInfoService
55
+ mockFetch
56
+ .mockResolvedValueOnce({
57
+ ok: true,
58
+ headers: new Headers({ 'content-type': 'application/json' }), // Mock headers correctly
59
+ status: 200,
60
+ statusText: 'Ok',
61
+ json: jest.fn().mockResolvedValue({
62
+ info: {
63
+ configInfo: {
64
+ mixpanelConfig: {
65
+ devSdkKey: 'devSdkKey',
66
+ },
67
+ },
68
+ userGUID: 'userGUID',
69
+ },
70
+ }),
71
+ });
72
+
73
+ const result = await fetchPreauthInfoService(thoughtspotHost);
74
+ const response = await result.json();
75
+
76
+ expect(mockFetch).toHaveBeenCalledTimes(1);
77
+ expect(mockFetch).toHaveBeenNthCalledWith(1, `${thoughtspotHost}${EndPoints.PREAUTH_INFO}`, {});
78
+ expect(response).toHaveProperty('info');
79
+ });
80
+ it('fetchPreauthInfoService if fetch fails', async () => {
81
+ const mockFetch = jest.spyOn(tokenizedFetchModule, 'tokenizedFetch');
82
+
83
+ // Mock for fetchPreauthInfoService
84
+ mockFetch.mockResolvedValueOnce({
85
+ ok: false,
86
+ status: 500,
87
+ statusText: 'Internal Server Error',
88
+ json: jest.fn().mockResolvedValue({}),
89
+ text: jest.fn().mockResolvedValue('Internal Server Error'),
90
+ });
91
+
92
+ try {
93
+ await fetchPreauthInfoService(thoughtspotHost);
94
+ } catch (e) {
95
+ expect(e.message).toContain(`Failed to fetch ${thoughtspotHost}${EndPoints.PREAUTH_INFO}`);
96
+ }
97
+ expect(mockFetch).toHaveBeenCalledTimes(1);
98
+ expect(mockFetch).toHaveBeenCalledWith(`${thoughtspotHost}${EndPoints.PREAUTH_INFO}`, {});
99
+ });
100
+ });
@@ -16,6 +16,32 @@ function tokenizedFailureLoggedFetch(url: string, options: RequestInit = {}): Pr
16
16
  });
17
17
  }
18
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> {
29
+ const sessionInfoPath = `${thoughtspotHost}${EndPoints.PREAUTH_INFO}`;
30
+ const handleError = (e: any) => {
31
+ const error: any = new Error(`Failed to fetch auth info: ${e.message || e.statusText}`);
32
+ error.status = e.status; // Attach the status code to the error object
33
+ throw error;
34
+ };
35
+
36
+ try {
37
+ const response = await tokenizedFailureLoggedFetch(sessionInfoPath);
38
+ return response;
39
+ } catch (e) {
40
+ handleError(e);
41
+ return null;
42
+ }
43
+ }
44
+
19
45
  /**
20
46
  * Fetches the session info from the ThoughtSpot server.
21
47
  * @param thoughtspotHost
@@ -1,5 +1,5 @@
1
1
  import { getEmbedConfig } from '../embed/embedConfig';
2
- import { fetchSessionInfoService } from './authService';
2
+ import { fetchSessionInfoService, fetchPreauthInfoService } from './authService';
3
3
 
4
4
  export type SessionInfo = {
5
5
  releaseVersion: string;
@@ -13,7 +13,70 @@ export type SessionInfo = {
13
13
  [key: string]: any;
14
14
  };
15
15
 
16
+ export type PreauthInfo = {
17
+ info?: SessionInfo;
18
+ headers: Record<string, string>;
19
+ status: number;
20
+ [key: string]: any;
21
+ };
22
+
16
23
  let sessionInfo: null | SessionInfo = null;
24
+ let preauthInfo: null | PreauthInfo = null;
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> => {
38
+ try {
39
+ // Convert Headers to a plain object
40
+ const headers: Record<string, string> = {};
41
+ preauthInfoResp?.headers?.forEach((value: string, key: string) => {
42
+ headers[key] = value;
43
+ });
44
+ const data = await preauthInfoResp.json();
45
+ return {
46
+ ...data,
47
+ status: 200,
48
+ headers,
49
+ };
50
+ } catch (error) {
51
+ return null;
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> {
67
+ if (!allowCache || !preauthInfo) {
68
+ try {
69
+ const host = getEmbedConfig().thoughtSpotHost;
70
+ const sessionResponse = await fetchPreauthInfoService(host);
71
+ const processedPreauthInfo = await formatPreauthInfo(sessionResponse);
72
+ preauthInfo = processedPreauthInfo;
73
+ } catch (error) {
74
+ return null;
75
+ }
76
+ }
77
+
78
+ return preauthInfo;
79
+ }
17
80
 
18
81
  /**
19
82
  * Returns the session info object and caches it for future use.