@thoughtspot/visual-embed-sdk 1.26.1 → 1.26.2
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 +2 -2
- package/cjs/src/auth.d.ts +0 -12
- package/cjs/src/auth.d.ts.map +1 -1
- package/cjs/src/auth.js +16 -54
- package/cjs/src/auth.js.map +1 -1
- package/cjs/src/auth.spec.d.ts.map +1 -1
- package/cjs/src/auth.spec.js +42 -32
- package/cjs/src/auth.spec.js.map +1 -1
- package/cjs/src/authToken.d.ts +4 -0
- package/cjs/src/authToken.d.ts.map +1 -0
- package/cjs/src/authToken.js +61 -0
- package/cjs/src/authToken.js.map +1 -0
- package/cjs/src/embed/TsEmbed.d.ts +302 -0
- package/cjs/src/embed/TsEmbed.d.ts.map +1 -0
- package/cjs/src/embed/TsEmbed.js +851 -0
- package/cjs/src/embed/TsEmbed.js.map +1 -0
- package/cjs/src/embed/base.d.ts +0 -9
- package/cjs/src/embed/base.d.ts.map +1 -1
- package/cjs/src/embed/base.js +21 -44
- package/cjs/src/embed/base.js.map +1 -1
- package/cjs/src/embed/base.spec.js +15 -14
- package/cjs/src/embed/base.spec.js.map +1 -1
- package/cjs/src/embed/embedConfig.d.ts +18 -0
- package/cjs/src/embed/embedConfig.d.ts.map +1 -0
- package/cjs/src/embed/embedConfig.js +25 -0
- package/cjs/src/embed/embedConfig.js.map +1 -0
- package/cjs/src/embed/search.d.ts.map +1 -1
- package/cjs/src/embed/search.js +3 -1
- package/cjs/src/embed/search.js.map +1 -1
- package/cjs/src/embed/searchEmbed-basic-auth.spec.js +3 -2
- package/cjs/src/embed/searchEmbed-basic-auth.spec.js.map +1 -1
- package/cjs/src/embed/ts-embed.d.ts.map +1 -1
- package/cjs/src/embed/ts-embed.js +5 -3
- package/cjs/src/embed/ts-embed.js.map +1 -1
- package/cjs/src/embed/ts-embed.spec.js +58 -49
- 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/tokenizedFetch.d.ts +2 -0
- package/cjs/src/tokenizedFetch.d.ts.map +1 -0
- package/cjs/src/tokenizedFetch.js +20 -0
- package/cjs/src/tokenizedFetch.js.map +1 -0
- package/cjs/src/types.d.ts +6 -0
- package/cjs/src/types.d.ts.map +1 -1
- package/cjs/src/types.js.map +1 -1
- package/cjs/src/utils/answerService.d.ts +10 -0
- package/cjs/src/utils/answerService.d.ts.map +1 -0
- package/cjs/src/utils/answerService.js +61 -0
- package/cjs/src/utils/answerService.js.map +1 -0
- package/cjs/src/utils/answerService.spec.d.ts +2 -0
- package/cjs/src/utils/answerService.spec.d.ts.map +1 -0
- package/cjs/src/utils/answerService.spec.js +31 -0
- package/cjs/src/utils/answerService.spec.js.map +1 -0
- package/cjs/src/utils/authService/authService.d.ts +45 -0
- package/cjs/src/utils/authService/authService.d.ts.map +1 -0
- package/cjs/src/utils/authService/authService.js +115 -0
- package/cjs/src/utils/authService/authService.js.map +1 -0
- package/cjs/src/utils/authService/authService.spec.d.ts +2 -0
- package/cjs/src/utils/authService/authService.spec.d.ts.map +1 -0
- package/cjs/src/utils/authService/authService.spec.js +82 -0
- package/cjs/src/utils/authService/authService.spec.js.map +1 -0
- package/cjs/src/utils/authService/index.d.ts +3 -0
- package/cjs/src/utils/authService/index.d.ts.map +1 -0
- package/cjs/src/utils/authService/index.js +14 -0
- package/cjs/src/utils/authService/index.js.map +1 -0
- package/cjs/src/utils/authService/tokenisedAuthSerice.d.ts +11 -0
- package/cjs/src/utils/authService/tokenisedAuthSerice.d.ts.map +1 -0
- package/cjs/src/utils/authService/tokenisedAuthSerice.js +44 -0
- package/cjs/src/utils/authService/tokenisedAuthSerice.js.map +1 -0
- package/cjs/src/utils/authService/tokenizedAuthService.d.ts +11 -0
- package/cjs/src/utils/authService/tokenizedAuthService.d.ts.map +1 -0
- package/cjs/src/utils/authService/tokenizedAuthService.js +44 -0
- package/cjs/src/utils/authService/tokenizedAuthService.js.map +1 -0
- package/cjs/src/utils/authService.d.ts +12 -1
- package/cjs/src/utils/authService.d.ts.map +1 -1
- package/cjs/src/utils/authService.js +32 -16
- package/cjs/src/utils/authService.js.map +1 -1
- package/cjs/src/utils/authService.spec.js +3 -4
- package/cjs/src/utils/authService.spec.js.map +1 -1
- package/cjs/src/utils/graphql/answerService/answerService.d.ts.map +1 -1
- package/cjs/src/utils/graphql/answerService/answerService.js +2 -1
- package/cjs/src/utils/graphql/answerService/answerService.js.map +1 -1
- package/cjs/src/utils/graphql/answerService/answerService.spec.js +15 -3
- package/cjs/src/utils/graphql/answerService/answerService.spec.js.map +1 -1
- package/cjs/src/utils/graphql/graphql-request.spec.d.ts +2 -0
- package/cjs/src/utils/graphql/graphql-request.spec.d.ts.map +1 -0
- package/cjs/src/utils/graphql/graphql-request.spec.js +39 -0
- package/cjs/src/utils/graphql/graphql-request.spec.js.map +1 -0
- package/cjs/src/utils/logger.d.ts +28 -0
- package/cjs/src/utils/logger.d.ts.map +1 -0
- package/cjs/src/utils/logger.js +82 -0
- package/cjs/src/utils/logger.js.map +1 -0
- package/cjs/src/utils/processData.d.ts.map +1 -1
- package/cjs/src/utils/processData.js +5 -4
- package/cjs/src/utils/processData.js.map +1 -1
- package/cjs/src/utils/processData.spec.js +8 -7
- package/cjs/src/utils/processData.spec.js.map +1 -1
- package/dist/src/auth.d.ts +0 -12
- package/dist/src/auth.d.ts.map +1 -1
- package/dist/src/auth.spec.d.ts.map +1 -1
- package/dist/src/authToken.d.ts +4 -0
- package/dist/src/authToken.d.ts.map +1 -0
- package/dist/src/embed/base.d.ts +0 -9
- package/dist/src/embed/base.d.ts.map +1 -1
- package/dist/src/embed/embedConfig.d.ts +18 -0
- package/dist/src/embed/embedConfig.d.ts.map +1 -0
- package/dist/src/embed/search.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/tokenizedFetch.d.ts +2 -0
- package/dist/src/tokenizedFetch.d.ts.map +1 -0
- package/dist/src/types.d.ts +6 -0
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/utils/answerService.d.ts +10 -0
- package/dist/src/utils/answerService.d.ts.map +1 -0
- package/dist/src/utils/answerService.spec.d.ts +2 -0
- package/dist/src/utils/answerService.spec.d.ts.map +1 -0
- package/dist/src/utils/authService/authService.d.ts +45 -0
- package/dist/src/utils/authService/authService.d.ts.map +1 -0
- package/dist/src/utils/authService/authService.spec.d.ts +2 -0
- package/dist/src/utils/authService/authService.spec.d.ts.map +1 -0
- package/dist/src/utils/authService/index.d.ts +3 -0
- package/dist/src/utils/authService/index.d.ts.map +1 -0
- package/dist/src/utils/authService/tokenisedAuthSerice.d.ts +11 -0
- package/dist/src/utils/authService/tokenisedAuthSerice.d.ts.map +1 -0
- package/dist/src/utils/authService/tokenizedAuthService.d.ts +11 -0
- package/dist/src/utils/authService/tokenizedAuthService.d.ts.map +1 -0
- package/dist/src/utils/authService.d.ts +12 -1
- package/dist/src/utils/authService.d.ts.map +1 -1
- package/dist/src/utils/graphql/answerService/answerService.d.ts.map +1 -1
- package/dist/src/utils/graphql/graphql-request.spec.d.ts +2 -0
- package/dist/src/utils/graphql/graphql-request.spec.d.ts.map +1 -0
- package/dist/src/utils/logger.d.ts +28 -0
- package/dist/src/utils/logger.d.ts.map +1 -0
- package/dist/src/utils/processData.d.ts.map +1 -1
- package/dist/tsembed-react.es.js +201 -140
- package/dist/tsembed-react.js +201 -140
- package/dist/tsembed.es.js +230 -171
- package/dist/tsembed.js +230 -171
- package/dist/visual-embed-sdk-react-full.d.ts +23 -21
- package/dist/visual-embed-sdk-react.d.ts +23 -21
- package/dist/visual-embed-sdk.d.ts +23 -21
- package/lib/package.json +2 -2
- package/lib/src/auth.d.ts +0 -12
- package/lib/src/auth.d.ts.map +1 -1
- package/lib/src/auth.js +11 -48
- package/lib/src/auth.js.map +1 -1
- package/lib/src/auth.spec.d.ts.map +1 -1
- package/lib/src/auth.spec.js +42 -32
- package/lib/src/auth.spec.js.map +1 -1
- package/lib/src/authToken.d.ts +4 -0
- package/lib/src/authToken.d.ts.map +1 -0
- package/lib/src/authToken.js +56 -0
- package/lib/src/authToken.js.map +1 -0
- package/lib/src/embed/TsEmbed.d.ts +302 -0
- package/lib/src/embed/TsEmbed.d.ts.map +1 -0
- package/lib/src/embed/TsEmbed.js +847 -0
- package/lib/src/embed/TsEmbed.js.map +1 -0
- package/lib/src/embed/base.d.ts +0 -9
- package/lib/src/embed/base.d.ts.map +1 -1
- package/lib/src/embed/base.js +21 -43
- package/lib/src/embed/base.js.map +1 -1
- package/lib/src/embed/base.spec.js +15 -14
- package/lib/src/embed/base.spec.js.map +1 -1
- package/lib/src/embed/embedConfig.d.ts +18 -0
- package/lib/src/embed/embedConfig.d.ts.map +1 -0
- package/lib/src/embed/embedConfig.js +20 -0
- package/lib/src/embed/embedConfig.js.map +1 -0
- package/lib/src/embed/search.d.ts.map +1 -1
- package/lib/src/embed/search.js +4 -2
- package/lib/src/embed/search.js.map +1 -1
- package/lib/src/embed/searchEmbed-basic-auth.spec.js +3 -2
- package/lib/src/embed/searchEmbed-basic-auth.spec.js.map +1 -1
- package/lib/src/embed/ts-embed.d.ts.map +1 -1
- package/lib/src/embed/ts-embed.js +4 -2
- package/lib/src/embed/ts-embed.js.map +1 -1
- package/lib/src/embed/ts-embed.spec.js +58 -49
- 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/tokenizedFetch.d.ts +2 -0
- package/lib/src/tokenizedFetch.d.ts.map +1 -0
- package/lib/src/tokenizedFetch.js +16 -0
- package/lib/src/tokenizedFetch.js.map +1 -0
- package/lib/src/types.d.ts +6 -0
- package/lib/src/types.d.ts.map +1 -1
- package/lib/src/types.js.map +1 -1
- package/lib/src/utils/answerService.d.ts +10 -0
- package/lib/src/utils/answerService.d.ts.map +1 -0
- package/lib/src/utils/answerService.js +57 -0
- package/lib/src/utils/answerService.js.map +1 -0
- package/lib/src/utils/answerService.spec.d.ts +2 -0
- package/lib/src/utils/answerService.spec.d.ts.map +1 -0
- package/lib/src/utils/answerService.spec.js +29 -0
- package/lib/src/utils/answerService.spec.js.map +1 -0
- package/lib/src/utils/authService/authService.d.ts +45 -0
- package/lib/src/utils/authService/authService.d.ts.map +1 -0
- package/lib/src/utils/authService/authService.js +107 -0
- package/lib/src/utils/authService/authService.js.map +1 -0
- package/lib/src/utils/authService/authService.spec.d.ts +2 -0
- package/lib/src/utils/authService/authService.spec.d.ts.map +1 -0
- package/lib/src/utils/authService/authService.spec.js +80 -0
- package/lib/src/utils/authService/authService.spec.js.map +1 -0
- package/lib/src/utils/authService/index.d.ts +3 -0
- package/lib/src/utils/authService/index.d.ts.map +1 -0
- package/lib/src/utils/authService/index.js +3 -0
- package/lib/src/utils/authService/index.js.map +1 -0
- package/lib/src/utils/authService/tokenisedAuthSerice.d.ts +11 -0
- package/lib/src/utils/authService/tokenisedAuthSerice.d.ts.map +1 -0
- package/lib/src/utils/authService/tokenisedAuthSerice.js +39 -0
- package/lib/src/utils/authService/tokenisedAuthSerice.js.map +1 -0
- package/lib/src/utils/authService/tokenizedAuthService.d.ts +11 -0
- package/lib/src/utils/authService/tokenizedAuthService.d.ts.map +1 -0
- package/lib/src/utils/authService/tokenizedAuthService.js +39 -0
- package/lib/src/utils/authService/tokenizedAuthService.js.map +1 -0
- package/lib/src/utils/authService.d.ts +12 -1
- package/lib/src/utils/authService.d.ts.map +1 -1
- package/lib/src/utils/authService.js +26 -10
- package/lib/src/utils/authService.js.map +1 -1
- package/lib/src/utils/authService.spec.js +1 -2
- package/lib/src/utils/authService.spec.js.map +1 -1
- package/lib/src/utils/graphql/answerService/answerService.d.ts.map +1 -1
- package/lib/src/utils/graphql/answerService/answerService.js +2 -1
- package/lib/src/utils/graphql/answerService/answerService.js.map +1 -1
- package/lib/src/utils/graphql/answerService/answerService.spec.js +14 -3
- package/lib/src/utils/graphql/answerService/answerService.spec.js.map +1 -1
- package/lib/src/utils/graphql/graphql-request.spec.d.ts +2 -0
- package/lib/src/utils/graphql/graphql-request.spec.d.ts.map +1 -0
- package/lib/src/utils/graphql/graphql-request.spec.js +36 -0
- package/lib/src/utils/graphql/graphql-request.spec.js.map +1 -0
- package/lib/src/utils/logger.d.ts +28 -0
- package/lib/src/utils/logger.d.ts.map +1 -0
- package/lib/src/utils/logger.js +75 -0
- package/lib/src/utils/logger.js.map +1 -0
- package/lib/src/utils/processData.d.ts.map +1 -1
- package/lib/src/utils/processData.js +4 -3
- package/lib/src/utils/processData.js.map +1 -1
- package/lib/src/utils/processData.spec.js +8 -7
- package/lib/src/utils/processData.spec.js.map +1 -1
- package/lib/src/visual-embed-sdk.d.ts +28 -22
- package/package.json +2 -2
- package/src/auth.spec.ts +77 -63
- package/src/auth.ts +12 -55
- package/src/authToken.ts +66 -0
- package/src/embed/base.spec.ts +18 -17
- package/src/embed/base.ts +26 -51
- package/src/embed/embedConfig.ts +23 -0
- package/src/embed/search.ts +10 -10
- package/src/embed/searchEmbed-basic-auth.spec.ts +3 -2
- package/src/embed/ts-embed.spec.ts +87 -75
- package/src/embed/ts-embed.ts +11 -20
- package/src/index.ts +8 -2
- package/src/tokenizedFetch.ts +18 -0
- package/src/types.ts +34 -23
- package/src/utils/{authService.spec.ts → authService/authService.spec.ts} +2 -3
- package/src/utils/{authService.ts → authService/authService.ts} +29 -34
- package/src/utils/authService/index.ts +9 -0
- package/src/utils/authService/tokenizedAuthService.ts +40 -0
- package/src/utils/graphql/answerService/answerService.spec.ts +16 -4
- package/src/utils/graphql/answerService/answerService.ts +2 -1
- package/src/utils/processData.spec.ts +19 -16
- package/src/utils/processData.ts +3 -2
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/* eslint-disable dot-notation */
|
|
2
|
+
import { resetCachedAuthToken } from '../authToken';
|
|
2
3
|
import {
|
|
3
4
|
AuthType,
|
|
4
5
|
init,
|
|
@@ -10,11 +11,7 @@ import {
|
|
|
10
11
|
LiveboardEmbed,
|
|
11
12
|
} from '../index';
|
|
12
13
|
import {
|
|
13
|
-
Action,
|
|
14
|
-
HomeLeftNavItem,
|
|
15
|
-
RuntimeFilter,
|
|
16
|
-
RuntimeFilterOp,
|
|
17
|
-
HomepageModule,
|
|
14
|
+
Action, HomeLeftNavItem, RuntimeFilter, RuntimeFilterOp, HomepageModule,
|
|
18
15
|
} from '../types';
|
|
19
16
|
import {
|
|
20
17
|
executeAfterWait,
|
|
@@ -34,6 +31,7 @@ import * as mixpanelInstance from '../mixpanel-service';
|
|
|
34
31
|
import * as authInstance from '../auth';
|
|
35
32
|
import * as baseInstance from './base';
|
|
36
33
|
import { MIXPANEL_EVENT } from '../mixpanel-service';
|
|
34
|
+
import * as authService from '../utils/authService/authService';
|
|
37
35
|
|
|
38
36
|
const defaultViewConfig = {
|
|
39
37
|
frameParams: {
|
|
@@ -89,8 +87,51 @@ describe('Unit test case for ts embed', () => {
|
|
|
89
87
|
|
|
90
88
|
afterEach(() => {
|
|
91
89
|
jest.clearAllMocks();
|
|
90
|
+
resetCachedAuthToken();
|
|
92
91
|
});
|
|
93
92
|
|
|
93
|
+
describe('AuthExpire embedEvent in cookieless authentication authType', () => {
|
|
94
|
+
beforeAll(() => {
|
|
95
|
+
jest.spyOn(authInstance, 'doCookielessTokenAuth').mockResolvedValueOnce(true);
|
|
96
|
+
jest.spyOn(authService, 'verifyTokenService').mockResolvedValueOnce(true);
|
|
97
|
+
init({
|
|
98
|
+
thoughtSpotHost: 'tshost',
|
|
99
|
+
customizations: customisations,
|
|
100
|
+
customCssUrl: 'http://localhost:5000',
|
|
101
|
+
authType: AuthType.TrustedAuthTokenCookieless,
|
|
102
|
+
getAuthToken: () => Promise.resolve('test_auth_token2'),
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
test('check for new authToken based on getAuthToken function', async () => {
|
|
107
|
+
const mockEmbedEventPayload = {
|
|
108
|
+
type: EmbedEvent.AuthExpire,
|
|
109
|
+
data: {},
|
|
110
|
+
};
|
|
111
|
+
const searchEmbed = new SearchEmbed(getRootEl(), defaultViewConfig);
|
|
112
|
+
jest.spyOn(baseInstance, 'notifyAuthFailure');
|
|
113
|
+
jest.spyOn(baseInstance, 'handleAuth');
|
|
114
|
+
|
|
115
|
+
searchEmbed.render();
|
|
116
|
+
const mockPort: any = {
|
|
117
|
+
postMessage: jest.fn(),
|
|
118
|
+
};
|
|
119
|
+
await executeAfterWait(() => {
|
|
120
|
+
const iframe = getIFrameEl();
|
|
121
|
+
postMessageToParent(iframe.contentWindow, mockEmbedEventPayload, mockPort);
|
|
122
|
+
});
|
|
123
|
+
await executeAfterWait(() => {
|
|
124
|
+
expect(baseInstance.notifyAuthFailure).toBeCalledWith(
|
|
125
|
+
authInstance.AuthFailureType.EXPIRY,
|
|
126
|
+
);
|
|
127
|
+
expect(baseInstance.handleAuth).not.toHaveBeenCalled();
|
|
128
|
+
expect(mockPort.postMessage).toHaveBeenCalledWith({
|
|
129
|
+
type: EmbedEvent.AuthExpire,
|
|
130
|
+
data: { authToken: 'test_auth_token2' },
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
});
|
|
94
135
|
describe('Called Embed event status for start and end', () => {
|
|
95
136
|
beforeAll(() => {
|
|
96
137
|
init({
|
|
@@ -193,8 +234,7 @@ describe('Unit test case for ts embed', () => {
|
|
|
193
234
|
hostConfig: undefined,
|
|
194
235
|
runtimeFilterParams: null,
|
|
195
236
|
hiddenHomeLeftNavItems: [],
|
|
196
|
-
hiddenHomepageModules: [HomepageModule.MyLibrary,
|
|
197
|
-
HomepageModule.Learning],
|
|
237
|
+
hiddenHomepageModules: [HomepageModule.MyLibrary, HomepageModule.Learning],
|
|
198
238
|
reorderedHomepageModules: [],
|
|
199
239
|
},
|
|
200
240
|
});
|
|
@@ -231,8 +271,7 @@ describe('Unit test case for ts embed', () => {
|
|
|
231
271
|
runtimeFilterParams: null,
|
|
232
272
|
hiddenHomeLeftNavItems: [],
|
|
233
273
|
hiddenHomepageModules: [],
|
|
234
|
-
reorderedHomepageModules: [HomepageModule.MyLibrary,
|
|
235
|
-
HomepageModule.Watchlist],
|
|
274
|
+
reorderedHomepageModules: [HomepageModule.MyLibrary, HomepageModule.Watchlist],
|
|
236
275
|
},
|
|
237
276
|
});
|
|
238
277
|
});
|
|
@@ -346,8 +385,7 @@ describe('Unit test case for ts embed', () => {
|
|
|
346
385
|
authToken: '',
|
|
347
386
|
hostConfig: undefined,
|
|
348
387
|
runtimeFilterParams: null,
|
|
349
|
-
hiddenHomeLeftNavItems: [HomeLeftNavItem.Home,
|
|
350
|
-
HomeLeftNavItem.Documentation],
|
|
388
|
+
hiddenHomeLeftNavItems: [HomeLeftNavItem.Home, HomeLeftNavItem.Documentation],
|
|
351
389
|
hiddenHomepageModules: [],
|
|
352
390
|
reorderedHomepageModules: [],
|
|
353
391
|
},
|
|
@@ -483,7 +521,15 @@ describe('Unit test case for ts embed', () => {
|
|
|
483
521
|
});
|
|
484
522
|
});
|
|
485
523
|
|
|
524
|
+
afterEach(() => {
|
|
525
|
+
baseInstance.reset();
|
|
526
|
+
});
|
|
527
|
+
|
|
486
528
|
test('check for authToken based on getAuthToken function', async () => {
|
|
529
|
+
const a = jest.spyOn(authService, 'verifyTokenService');
|
|
530
|
+
a.mockResolvedValue(true);
|
|
531
|
+
|
|
532
|
+
// authVerifyMock.mockResolvedValue(true);
|
|
487
533
|
const mockEmbedEventPayload = {
|
|
488
534
|
type: EmbedEvent.APP_INIT,
|
|
489
535
|
data: {},
|
|
@@ -511,47 +557,8 @@ describe('Unit test case for ts embed', () => {
|
|
|
511
557
|
},
|
|
512
558
|
});
|
|
513
559
|
});
|
|
514
|
-
});
|
|
515
|
-
});
|
|
516
560
|
|
|
517
|
-
|
|
518
|
-
beforeAll(() => {
|
|
519
|
-
jest.spyOn(authInstance, 'doCookielessTokenAuth').mockResolvedValueOnce(true);
|
|
520
|
-
init({
|
|
521
|
-
thoughtSpotHost: 'tshost',
|
|
522
|
-
customizations: customisations,
|
|
523
|
-
customCssUrl: 'http://localhost:5000',
|
|
524
|
-
authType: AuthType.TrustedAuthTokenCookieless,
|
|
525
|
-
getAuthToken: () => Promise.resolve('test_auth_token2'),
|
|
526
|
-
});
|
|
527
|
-
});
|
|
528
|
-
|
|
529
|
-
test('check for new authToken based on getAuthToken function', async () => {
|
|
530
|
-
const mockEmbedEventPayload = {
|
|
531
|
-
type: EmbedEvent.AuthExpire,
|
|
532
|
-
data: {},
|
|
533
|
-
};
|
|
534
|
-
const searchEmbed = new SearchEmbed(getRootEl(), defaultViewConfig);
|
|
535
|
-
jest.spyOn(baseInstance, 'notifyAuthFailure');
|
|
536
|
-
jest.spyOn(baseInstance, 'handleAuth');
|
|
537
|
-
searchEmbed.render();
|
|
538
|
-
const mockPort: any = {
|
|
539
|
-
postMessage: jest.fn(),
|
|
540
|
-
};
|
|
541
|
-
await executeAfterWait(() => {
|
|
542
|
-
const iframe = getIFrameEl();
|
|
543
|
-
postMessageToParent(iframe.contentWindow, mockEmbedEventPayload, mockPort);
|
|
544
|
-
});
|
|
545
|
-
await executeAfterWait(() => {
|
|
546
|
-
expect(baseInstance.notifyAuthFailure).toBeCalledWith(
|
|
547
|
-
authInstance.AuthFailureType.EXPIRY,
|
|
548
|
-
);
|
|
549
|
-
expect(baseInstance.handleAuth).not.toHaveBeenCalled();
|
|
550
|
-
expect(mockPort.postMessage).toHaveBeenCalledWith({
|
|
551
|
-
type: EmbedEvent.AuthExpire,
|
|
552
|
-
data: { authToken: 'test_auth_token2' },
|
|
553
|
-
});
|
|
554
|
-
});
|
|
561
|
+
jest.spyOn(authService, 'verifyTokenService').mockClear();
|
|
555
562
|
});
|
|
556
563
|
});
|
|
557
564
|
|
|
@@ -1036,7 +1043,7 @@ describe('Unit test case for ts embed', () => {
|
|
|
1036
1043
|
expectUrlMatchesWithParams(
|
|
1037
1044
|
getIFrameSrc(),
|
|
1038
1045
|
`http://${thoughtSpotHost}/?embedApp=true&primaryNavHidden=true&profileAndHelpInNavBarHidden=false&${defaultParamsForPinboardEmbed}`
|
|
1039
|
-
|
|
1046
|
+
+ `&foo=bar&baz=1&bool=true${defaultParamsPost}#/home`,
|
|
1040
1047
|
);
|
|
1041
1048
|
});
|
|
1042
1049
|
|
|
@@ -1052,7 +1059,7 @@ describe('Unit test case for ts embed', () => {
|
|
|
1052
1059
|
expectUrlMatchesWithParams(
|
|
1053
1060
|
getIFrameSrc(),
|
|
1054
1061
|
`http://${thoughtSpotHost}/?embedApp=true&primaryNavHidden=true&profileAndHelpInNavBarHidden=false&${defaultParamsForPinboardEmbed}`
|
|
1055
|
-
|
|
1062
|
+
+ `&showAlerts=true${defaultParamsPost}#/home`,
|
|
1056
1063
|
);
|
|
1057
1064
|
});
|
|
1058
1065
|
it('Sets the locale param', async () => {
|
|
@@ -1067,7 +1074,7 @@ describe('Unit test case for ts embed', () => {
|
|
|
1067
1074
|
expectUrlMatchesWithParams(
|
|
1068
1075
|
getIFrameSrc(),
|
|
1069
1076
|
`http://${thoughtSpotHost}/?embedApp=true&primaryNavHidden=true&profileAndHelpInNavBarHidden=false&${defaultParamsForPinboardEmbed}`
|
|
1070
|
-
|
|
1077
|
+
+ `&locale=ja-JP${defaultParamsPost}#/home`,
|
|
1071
1078
|
);
|
|
1072
1079
|
});
|
|
1073
1080
|
it('Sets the iconSprite url', async () => {
|
|
@@ -1084,7 +1091,7 @@ describe('Unit test case for ts embed', () => {
|
|
|
1084
1091
|
expectUrlMatchesWithParams(
|
|
1085
1092
|
getIFrameSrc(),
|
|
1086
1093
|
`http://${thoughtSpotHost}/?embedApp=true&primaryNavHidden=true&profileAndHelpInNavBarHidden=false&${defaultParamsForPinboardEmbed}`
|
|
1087
|
-
|
|
1094
|
+
+ `&iconSprite=iconSprite.com${defaultParamsPost}#/home`,
|
|
1088
1095
|
);
|
|
1089
1096
|
});
|
|
1090
1097
|
|
|
@@ -1302,8 +1309,7 @@ describe('Unit test case for ts embed', () => {
|
|
|
1302
1309
|
expect(preRenderWrapper.style.pointerEvents).toBe('none');
|
|
1303
1310
|
expect(preRenderWrapper.style.zIndex).toBe('-1000');
|
|
1304
1311
|
|
|
1305
|
-
const preRenderChild = (
|
|
1306
|
-
.getElementById(preRenderIds.child) as HTMLIFrameElement);
|
|
1312
|
+
const preRenderChild = document.getElementById(preRenderIds.child) as HTMLIFrameElement;
|
|
1307
1313
|
expect(preRenderWrapper.children[0]).toEqual(preRenderChild);
|
|
1308
1314
|
expect(preRenderChild).toBeInstanceOf(HTMLIFrameElement);
|
|
1309
1315
|
expect(preRenderChild.src).toMatch(/^http:\/\/tshost.*\/myLiveboardId/);
|
|
@@ -1314,24 +1320,26 @@ describe('Unit test case for ts embed', () => {
|
|
|
1314
1320
|
|
|
1315
1321
|
let resizeObserverCb: any;
|
|
1316
1322
|
(window as any).ResizeObserver = window.ResizeObserver
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
+
|| jest.fn().mockImplementation((resizeObserverCbParam) => {
|
|
1324
|
+
resizeObserverCb = resizeObserverCbParam;
|
|
1325
|
+
return {
|
|
1326
|
+
disconnect: jest.fn(),
|
|
1327
|
+
observe: jest.fn(),
|
|
1328
|
+
unobserve: jest.fn(),
|
|
1329
|
+
};
|
|
1323
1330
|
});
|
|
1324
|
-
});
|
|
1325
1331
|
|
|
1326
1332
|
// show preRender
|
|
1327
1333
|
const warnSpy = spyOn(console, 'warn');
|
|
1328
1334
|
libEmbed.showPreRender();
|
|
1329
1335
|
expect(warnSpy).toHaveBeenCalledTimes(0);
|
|
1330
1336
|
|
|
1331
|
-
resizeObserverCb([
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1337
|
+
resizeObserverCb([
|
|
1338
|
+
{
|
|
1339
|
+
target: tsEmbedDiv,
|
|
1340
|
+
contentRect: { height: 297, width: 987 },
|
|
1341
|
+
},
|
|
1342
|
+
]);
|
|
1335
1343
|
|
|
1336
1344
|
expect(preRenderWrapper.style.height).toEqual(`${297}px`);
|
|
1337
1345
|
expect(preRenderWrapper.style.width).toEqual(`${987}px`);
|
|
@@ -1394,11 +1402,11 @@ describe('Unit test case for ts embed', () => {
|
|
|
1394
1402
|
createRootEleForEmbed();
|
|
1395
1403
|
mockMessageChannel();
|
|
1396
1404
|
(window as any).ResizeObserver = window.ResizeObserver
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1405
|
+
|| jest.fn().mockImplementation(() => ({
|
|
1406
|
+
disconnect: jest.fn(),
|
|
1407
|
+
observe: jest.fn(),
|
|
1408
|
+
unobserve: jest.fn(),
|
|
1409
|
+
}));
|
|
1402
1410
|
const libEmbed = new LiveboardEmbed('#tsEmbedDiv', {
|
|
1403
1411
|
preRenderId: 'i-am-preRendered',
|
|
1404
1412
|
liveboardId: 'myLiveboardId',
|
|
@@ -1451,7 +1459,9 @@ describe('Unit test case for ts embed', () => {
|
|
|
1451
1459
|
});
|
|
1452
1460
|
await libEmbed.preRender();
|
|
1453
1461
|
|
|
1454
|
-
expect(document.getElementById('tsEmbed-pre-render-child-test').innerHTML).toBe(
|
|
1462
|
+
expect(document.getElementById('tsEmbed-pre-render-child-test').innerHTML).toBe(
|
|
1463
|
+
'Not logged in',
|
|
1464
|
+
);
|
|
1455
1465
|
});
|
|
1456
1466
|
it('should log error if sync is called before preRender', async () => {
|
|
1457
1467
|
jest.spyOn(console, 'error').mockImplementation(jest.fn());
|
|
@@ -1460,7 +1470,9 @@ describe('Unit test case for ts embed', () => {
|
|
|
1460
1470
|
preRenderId: 'test',
|
|
1461
1471
|
});
|
|
1462
1472
|
await libEmbed.syncPreRenderStyle();
|
|
1463
|
-
expect(console.error).toBeCalledWith(
|
|
1473
|
+
expect(console.error).toBeCalledWith(
|
|
1474
|
+
'PreRender should be called before using syncPreRenderStyle',
|
|
1475
|
+
);
|
|
1464
1476
|
(console.error as any).mockClear();
|
|
1465
1477
|
});
|
|
1466
1478
|
});
|
package/src/embed/ts-embed.ts
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
import isEqual from 'lodash/isEqual';
|
|
11
11
|
|
|
12
|
+
import { getAuthenticationToken } from '../authToken';
|
|
12
13
|
import { AnswerService } from '../utils/graphql/answerService/answerService';
|
|
13
14
|
import {
|
|
14
15
|
getEncodedQueryParamsString,
|
|
@@ -55,13 +56,10 @@ import { processEventData } from '../utils/processData';
|
|
|
55
56
|
import { processTrigger } from '../utils/processTrigger';
|
|
56
57
|
import pkgInfo from '../../package.json';
|
|
57
58
|
import {
|
|
58
|
-
getAuthPromise,
|
|
59
|
-
getEmbedConfig,
|
|
60
|
-
renderInQueue,
|
|
61
|
-
handleAuth,
|
|
62
|
-
notifyAuthFailure,
|
|
59
|
+
getAuthPromise, renderInQueue, handleAuth, notifyAuthFailure,
|
|
63
60
|
} from './base';
|
|
64
|
-
import { AuthFailureType
|
|
61
|
+
import { AuthFailureType } from '../auth';
|
|
62
|
+
import { getEmbedConfig } from './embedConfig';
|
|
65
63
|
|
|
66
64
|
const { version } = pkgInfo;
|
|
67
65
|
|
|
@@ -1073,11 +1071,11 @@ export class TsEmbed {
|
|
|
1073
1071
|
) {
|
|
1074
1072
|
console.warn(
|
|
1075
1073
|
`${this.embedComponentType} was pre-rendered with `
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1074
|
+
+ `"${key}" as "${JSON.stringify(preRenderedObject.viewConfig[key])}" `
|
|
1075
|
+
+ `but a different value "${JSON.stringify(viewConfig[key])}" `
|
|
1076
|
+
+ 'was passed to the Embed component. '
|
|
1077
|
+
+ 'The new value provided is ignored, the value provided during '
|
|
1078
|
+
+ 'preRender is used.',
|
|
1081
1079
|
);
|
|
1082
1080
|
}
|
|
1083
1081
|
});
|
|
@@ -1204,15 +1202,8 @@ export class TsEmbed {
|
|
|
1204
1202
|
* @version SDK: 1.25.0 / ThoughtSpot 9.10.0
|
|
1205
1203
|
*/
|
|
1206
1204
|
public async getAnswerService(vizId?: string): Promise<AnswerService> {
|
|
1207
|
-
const { session, embedAnswerData } = await this.trigger(
|
|
1208
|
-
|
|
1209
|
-
vizId,
|
|
1210
|
-
);
|
|
1211
|
-
return new AnswerService(
|
|
1212
|
-
session,
|
|
1213
|
-
embedAnswerData,
|
|
1214
|
-
this.embedConfig.thoughtSpotHost,
|
|
1215
|
-
);
|
|
1205
|
+
const { session, embedAnswerData } = await this.trigger(HostEvent.GetAnswerSession, vizId);
|
|
1206
|
+
return new AnswerService(session, embedAnswerData, this.embedConfig.thoughtSpotHost);
|
|
1216
1207
|
}
|
|
1217
1208
|
}
|
|
1218
1209
|
|
package/src/index.ts
CHANGED
|
@@ -9,8 +9,13 @@
|
|
|
9
9
|
*/
|
|
10
10
|
import { AppEmbed, Page, AppViewConfig } from './embed/app';
|
|
11
11
|
import {
|
|
12
|
-
init,
|
|
13
|
-
|
|
12
|
+
init,
|
|
13
|
+
prefetch,
|
|
14
|
+
logout,
|
|
15
|
+
executeTML,
|
|
16
|
+
exportTML,
|
|
17
|
+
executeTMLInput,
|
|
18
|
+
exportTMLInput,
|
|
14
19
|
} from './embed/base';
|
|
15
20
|
import { PinboardEmbed, LiveboardViewConfig, LiveboardEmbed } from './embed/liveboard';
|
|
16
21
|
import { SearchEmbed, SearchViewConfig } from './embed/search';
|
|
@@ -44,6 +49,7 @@ import {
|
|
|
44
49
|
import { CustomCssVariables } from './css-variables';
|
|
45
50
|
import { SageEmbed, SageViewConfig } from './embed/sage';
|
|
46
51
|
import { AnswerService } from './utils/graphql/answerService/answerService';
|
|
52
|
+
import { getEmbedConfig } from './embed/embedConfig';
|
|
47
53
|
|
|
48
54
|
export {
|
|
49
55
|
init,
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { getAuthenticationToken } from './authToken';
|
|
2
|
+
import { getEmbedConfig } from './embed/embedConfig';
|
|
3
|
+
|
|
4
|
+
import { AuthType } from './types';
|
|
5
|
+
|
|
6
|
+
export const tokenizedFetch: typeof fetch = async (input, init): Promise<Response> => {
|
|
7
|
+
const embedConfig = getEmbedConfig();
|
|
8
|
+
if (embedConfig.authType !== AuthType.TrustedAuthTokenCookieless) {
|
|
9
|
+
return fetch(input, init);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const req = new Request(input, init);
|
|
13
|
+
const authToken = await getAuthenticationToken(embedConfig);
|
|
14
|
+
if (authToken) {
|
|
15
|
+
req.headers.append('Authorization', `Bearer ${authToken}`);
|
|
16
|
+
}
|
|
17
|
+
return fetch(req);
|
|
18
|
+
};
|
package/src/types.ts
CHANGED
|
@@ -531,10 +531,17 @@ export interface EmbedConfig {
|
|
|
531
531
|
* @version SDK: 1.27.0 | ThoughtSpot: 9.8.0.cl
|
|
532
532
|
*/
|
|
533
533
|
pendoTrackingKey?: string;
|
|
534
|
+
|
|
535
|
+
/**
|
|
536
|
+
* If passed as true all alerts will be suppressed in the embedded app.
|
|
537
|
+
*
|
|
538
|
+
* @version SDK: 1.26.2 | ThoughtSpot: *
|
|
539
|
+
*/
|
|
540
|
+
suppressErrorAlerts?: boolean;
|
|
534
541
|
}
|
|
535
542
|
|
|
536
543
|
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
|
537
|
-
export interface LayoutConfig {
|
|
544
|
+
export interface LayoutConfig {}
|
|
538
545
|
|
|
539
546
|
/**
|
|
540
547
|
* Embedded iFrame configuration
|
|
@@ -3212,40 +3219,44 @@ export enum ContextMenuTriggerOptions {
|
|
|
3212
3219
|
|
|
3213
3220
|
export interface ColumnValue {
|
|
3214
3221
|
column: {
|
|
3215
|
-
id: string
|
|
3216
|
-
name: string
|
|
3217
|
-
dataType: string
|
|
3218
|
-
[key: string]: any
|
|
3219
|
-
},
|
|
3220
|
-
value: string | number | boolean | {
|
|
3221
|
-
v: {
|
|
3222
|
-
s: number;
|
|
3223
|
-
e: number;
|
|
3224
|
-
}
|
|
3222
|
+
id: string;
|
|
3223
|
+
name: string;
|
|
3224
|
+
dataType: string;
|
|
3225
|
+
[key: string]: any;
|
|
3225
3226
|
};
|
|
3227
|
+
value:
|
|
3228
|
+
| string
|
|
3229
|
+
| number
|
|
3230
|
+
| boolean
|
|
3231
|
+
| {
|
|
3232
|
+
v: {
|
|
3233
|
+
s: number;
|
|
3234
|
+
e: number;
|
|
3235
|
+
};
|
|
3236
|
+
};
|
|
3226
3237
|
}
|
|
3227
3238
|
|
|
3228
3239
|
export interface VizPoint {
|
|
3229
|
-
selectedAttributes: ColumnValue[]
|
|
3230
|
-
selectedMeasures: ColumnValue[]
|
|
3240
|
+
selectedAttributes: ColumnValue[];
|
|
3241
|
+
selectedMeasures: ColumnValue[];
|
|
3231
3242
|
}
|
|
3232
3243
|
|
|
3233
3244
|
export interface CustomActionPayload {
|
|
3234
3245
|
contextMenuPoints?: {
|
|
3235
|
-
clickedPoint: VizPoint
|
|
3236
|
-
selectedPoints: VizPoint[]
|
|
3246
|
+
clickedPoint: VizPoint;
|
|
3247
|
+
selectedPoints: VizPoint[];
|
|
3237
3248
|
};
|
|
3238
3249
|
embedAnswerData: {
|
|
3239
|
-
name: string
|
|
3240
|
-
id: string
|
|
3250
|
+
name: string;
|
|
3251
|
+
id: string;
|
|
3241
3252
|
sources: {
|
|
3242
3253
|
header: {
|
|
3243
|
-
guid: string
|
|
3244
|
-
}
|
|
3245
|
-
}
|
|
3246
|
-
columns: any[]
|
|
3247
|
-
data: any[]
|
|
3248
|
-
[key: string]: any
|
|
3254
|
+
guid: string;
|
|
3255
|
+
};
|
|
3256
|
+
};
|
|
3257
|
+
columns: any[];
|
|
3258
|
+
data: any[];
|
|
3259
|
+
[key: string]: any;
|
|
3249
3260
|
};
|
|
3250
3261
|
session: SessionInterface;
|
|
3251
3262
|
vizId?: string;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { embedConfig } from 'src/auth.spec';
|
|
2
1
|
import {
|
|
3
2
|
fetchSessionInfoService,
|
|
4
3
|
fetchAuthTokenService,
|
|
@@ -6,8 +5,8 @@ import {
|
|
|
6
5
|
fetchBasicAuthService,
|
|
7
6
|
fetchAuthPostService,
|
|
8
7
|
verifyTokenService,
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
EndPoints,
|
|
9
|
+
} from '.';
|
|
11
10
|
|
|
12
11
|
const thoughtSpotHost = 'http://10.79.135.124:3000';
|
|
13
12
|
|
|
@@ -1,5 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
export const EndPoints = {
|
|
2
|
+
AUTH_VERIFICATION: '/callosum/v1/session/info',
|
|
3
|
+
SAML_LOGIN_TEMPLATE: (targetUrl: string) => `/callosum/v1/saml/login?targetURLPath=${targetUrl}`,
|
|
4
|
+
OIDC_LOGIN_TEMPLATE: (targetUrl: string) => `/callosum/v1/oidc/login?targetURLPath=${targetUrl}`,
|
|
5
|
+
TOKEN_LOGIN: '/callosum/v1/session/login/token',
|
|
6
|
+
BASIC_LOGIN: '/callosum/v1/session/login',
|
|
7
|
+
LOGOUT: '/callosum/v1/session/logout',
|
|
8
|
+
EXECUTE_TML: '/api/rest/2.0/metadata/tml/import',
|
|
9
|
+
EXPORT_TML: '/api/rest/2.0/metadata/tml/export',
|
|
10
|
+
IS_ACTIVE: '/callosum/v1/session/isactive',
|
|
11
|
+
};
|
|
3
12
|
|
|
4
13
|
/**
|
|
5
14
|
*
|
|
@@ -15,31 +24,31 @@ function failureLoggedFetch(url: string, options: RequestInit = {}): Promise<Res
|
|
|
15
24
|
});
|
|
16
25
|
}
|
|
17
26
|
|
|
18
|
-
/**
|
|
19
|
-
*
|
|
20
|
-
* @param authVerificationUrl
|
|
21
|
-
*/
|
|
22
|
-
export function fetchSessionInfoService(authVerificationUrl: string): Promise<any> {
|
|
23
|
-
return failureLoggedFetch(authVerificationUrl, {
|
|
24
|
-
credentials: 'include',
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
|
|
28
27
|
/**
|
|
29
28
|
* Service to validate a auth token against a ThoughtSpot host.
|
|
30
29
|
*
|
|
31
30
|
* @param thoughtSpotHost : ThoughtSpot host to verify the token against.
|
|
32
31
|
* @param authToken : Auth token to verify.
|
|
33
32
|
*/
|
|
34
|
-
export function verifyTokenService(
|
|
33
|
+
export async function verifyTokenService(
|
|
34
|
+
thoughtSpotHost: string,
|
|
35
|
+
authToken: string,
|
|
36
|
+
): Promise<boolean> {
|
|
35
37
|
const authVerificationUrl = `${thoughtSpotHost}${EndPoints.IS_ACTIVE}`;
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
38
|
+
try {
|
|
39
|
+
const res = await fetch(authVerificationUrl, {
|
|
40
|
+
headers: {
|
|
41
|
+
Authorization: `Bearer ${authToken}`,
|
|
42
|
+
'x-requested-by': 'ThoughtSpot',
|
|
43
|
+
},
|
|
44
|
+
credentials: 'omit',
|
|
45
|
+
});
|
|
46
|
+
return res.ok;
|
|
47
|
+
} catch (e) {
|
|
48
|
+
console.error(`Token Verification Service failed : ${e.message}`);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return false;
|
|
43
52
|
}
|
|
44
53
|
|
|
45
54
|
/**
|
|
@@ -120,17 +129,3 @@ export async function fetchBasicAuthService(
|
|
|
120
129
|
credentials: 'include',
|
|
121
130
|
});
|
|
122
131
|
}
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
*
|
|
126
|
-
* @param thoughtSpotHost
|
|
127
|
-
*/
|
|
128
|
-
export async function fetchLogoutService(thoughtSpotHost: string): Promise<any> {
|
|
129
|
-
return failureLoggedFetch(`${thoughtSpotHost}${EndPoints.LOGOUT}`, {
|
|
130
|
-
credentials: 'include',
|
|
131
|
-
method: 'POST',
|
|
132
|
-
headers: {
|
|
133
|
-
'x-requested-by': 'ThoughtSpot',
|
|
134
|
-
},
|
|
135
|
-
});
|
|
136
|
-
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { tokenizedFetch } from '../../tokenizedFetch';
|
|
2
|
+
import { EndPoints } from './authService';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
*
|
|
6
|
+
* @param url
|
|
7
|
+
* @param options
|
|
8
|
+
*/
|
|
9
|
+
function tokenisedFailureLoggedFetch(url: string, options: RequestInit = {}): Promise<Response> {
|
|
10
|
+
return tokenizedFetch(url, options).then(async (r) => {
|
|
11
|
+
if (!r.ok && r.type !== 'opaqueredirect' && r.type !== 'opaque') {
|
|
12
|
+
console.error('Failure', await r.text?.());
|
|
13
|
+
}
|
|
14
|
+
return r;
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
*
|
|
20
|
+
* @param authVerificationUrl
|
|
21
|
+
*/
|
|
22
|
+
export function fetchSessionInfoService(authVerificationUrl: string): Promise<any> {
|
|
23
|
+
return tokenisedFailureLoggedFetch(authVerificationUrl, {
|
|
24
|
+
credentials: 'include',
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
*
|
|
30
|
+
* @param thoughtSpotHost
|
|
31
|
+
*/
|
|
32
|
+
export async function fetchLogoutService(thoughtSpotHost: string): Promise<any> {
|
|
33
|
+
return tokenisedFailureLoggedFetch(`${thoughtSpotHost}${EndPoints.LOGOUT}`, {
|
|
34
|
+
credentials: 'include',
|
|
35
|
+
method: 'POST',
|
|
36
|
+
headers: {
|
|
37
|
+
'x-requested-by': 'ThoughtSpot',
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import 'jest-fetch-mock';
|
|
2
|
-
import { VizPoint } from '
|
|
2
|
+
import { AuthType, VizPoint } from '../../../types';
|
|
3
3
|
import { AnswerService } from './answerService';
|
|
4
4
|
import { getAnswerData, removeColumns } from './answer-queries';
|
|
5
|
+
import * as authTokenInstance from '../../../authToken';
|
|
6
|
+
import * as tokenizedFetch from '../../../tokenizedFetch';
|
|
7
|
+
import * as embedConfigInstance from '../../../embed/embedConfig';
|
|
5
8
|
|
|
6
9
|
const defaultSession = {
|
|
7
10
|
sessionId: 'id',
|
|
@@ -111,20 +114,29 @@ describe('Answer service tests', () => {
|
|
|
111
114
|
test('fetchCSVBlob should call the right API', () => {
|
|
112
115
|
fetchMock.once('Bla');
|
|
113
116
|
const answerService = createAnswerService();
|
|
117
|
+
|
|
118
|
+
const mockEmbedConfig = {
|
|
119
|
+
thougthspotHost: '/test',
|
|
120
|
+
authType: AuthType.TrustedAuthTokenCookieless,
|
|
121
|
+
};
|
|
122
|
+
jest.spyOn(embedConfigInstance, 'getEmbedConfig').mockReturnValueOnce(mockEmbedConfig);
|
|
123
|
+
jest.spyOn(authTokenInstance, 'getAuthenticationToken').mockReturnValueOnce(Promise.resolve('token'));
|
|
124
|
+
const mockTokenizedFetch = jest.spyOn(tokenizedFetch, 'tokenizedFetch');
|
|
114
125
|
answerService.fetchCSVBlob(undefined, true);
|
|
115
|
-
|
|
126
|
+
|
|
127
|
+
expect(mockTokenizedFetch).toHaveBeenCalledWith(
|
|
116
128
|
`https://tshost/prism/download/answer/csv?sessionId=${defaultSession.sessionId}&genNo=${defaultSession.genNo}&userLocale=en-us&exportFileName=data&hideCsvHeader=false`,
|
|
117
129
|
expect.objectContaining({}),
|
|
118
130
|
);
|
|
119
131
|
|
|
120
132
|
answerService.fetchCSVBlob('en-uk', true);
|
|
121
|
-
expect(
|
|
133
|
+
expect(mockTokenizedFetch).toHaveBeenCalledWith(
|
|
122
134
|
`https://tshost/prism/download/answer/csv?sessionId=${defaultSession.sessionId}&genNo=${defaultSession.genNo}&userLocale=en-uk&exportFileName=data&hideCsvHeader=false`,
|
|
123
135
|
expect.objectContaining({}),
|
|
124
136
|
);
|
|
125
137
|
|
|
126
138
|
answerService.fetchCSVBlob(undefined, false);
|
|
127
|
-
expect(
|
|
139
|
+
expect(mockTokenizedFetch).toHaveBeenCalledWith(
|
|
128
140
|
`https://tshost/prism/download/answer/csv?sessionId=${defaultSession.sessionId}&genNo=${defaultSession.genNo}&userLocale=en-us&exportFileName=data&hideCsvHeader=true`,
|
|
129
141
|
expect.objectContaining({}),
|
|
130
142
|
);
|