@thoughtspot/visual-embed-sdk 1.10.0-alpha.4 → 1.11.0-alpha.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 (78) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/README.md +1 -1
  3. package/dist/src/auth.d.ts +18 -5
  4. package/dist/src/embed/base.d.ts +21 -5
  5. package/dist/src/embed/pinboard.d.ts +6 -0
  6. package/dist/src/embed/ts-embed.d.ts +1 -1
  7. package/dist/src/index.d.ts +3 -2
  8. package/dist/src/types.d.ts +21 -0
  9. package/dist/src/utils/authService.d.ts +1 -0
  10. package/dist/src/utils/plugin.d.ts +0 -0
  11. package/dist/src/utils/processData.d.ts +1 -1
  12. package/dist/src/v1/api.d.ts +19 -0
  13. package/dist/tsembed.es.js +536 -36
  14. package/dist/tsembed.js +534 -35
  15. package/lib/package.json +2 -1
  16. package/lib/src/auth.d.ts +18 -5
  17. package/lib/src/auth.js +48 -9
  18. package/lib/src/auth.js.map +1 -1
  19. package/lib/src/auth.spec.js +69 -11
  20. package/lib/src/auth.spec.js.map +1 -1
  21. package/lib/src/embed/base.d.ts +21 -5
  22. package/lib/src/embed/base.js +64 -10
  23. package/lib/src/embed/base.js.map +1 -1
  24. package/lib/src/embed/base.spec.js +49 -3
  25. package/lib/src/embed/base.spec.js.map +1 -1
  26. package/lib/src/embed/embed.spec.js +1 -1
  27. package/lib/src/embed/embed.spec.js.map +1 -1
  28. package/lib/src/embed/events.spec.js +30 -1
  29. package/lib/src/embed/events.spec.js.map +1 -1
  30. package/lib/src/embed/pinboard.d.ts +6 -0
  31. package/lib/src/embed/pinboard.js +4 -1
  32. package/lib/src/embed/pinboard.js.map +1 -1
  33. package/lib/src/embed/ts-embed.d.ts +1 -1
  34. package/lib/src/embed/ts-embed.js +18 -14
  35. package/lib/src/embed/ts-embed.js.map +1 -1
  36. package/lib/src/embed/ts-embed.spec.js +16 -6
  37. package/lib/src/embed/ts-embed.spec.js.map +1 -1
  38. package/lib/src/index.d.ts +3 -2
  39. package/lib/src/index.js +3 -2
  40. package/lib/src/index.js.map +1 -1
  41. package/lib/src/test/test-utils.js +1 -1
  42. package/lib/src/test/test-utils.js.map +1 -1
  43. package/lib/src/types.d.ts +21 -0
  44. package/lib/src/types.js +16 -0
  45. package/lib/src/types.js.map +1 -1
  46. package/lib/src/utils/authService.d.ts +1 -0
  47. package/lib/src/utils/authService.js +21 -3
  48. package/lib/src/utils/authService.js.map +1 -1
  49. package/lib/src/utils/authService.spec.js +21 -5
  50. package/lib/src/utils/authService.spec.js.map +1 -1
  51. package/lib/src/utils/plugin.d.ts +0 -0
  52. package/lib/src/utils/plugin.js +1 -0
  53. package/lib/src/utils/plugin.js.map +1 -0
  54. package/lib/src/utils/processData.d.ts +1 -1
  55. package/lib/src/utils/processData.js +37 -3
  56. package/lib/src/utils/processData.js.map +1 -1
  57. package/lib/src/utils/processData.spec.js +106 -4
  58. package/lib/src/utils/processData.spec.js.map +1 -1
  59. package/lib/src/visual-embed-sdk.d.ts +107 -8
  60. package/package.json +2 -1
  61. package/src/auth.spec.ts +90 -11
  62. package/src/auth.ts +63 -13
  63. package/src/embed/base.spec.ts +56 -4
  64. package/src/embed/base.ts +83 -16
  65. package/src/embed/embed.spec.ts +1 -1
  66. package/src/embed/events.spec.ts +32 -0
  67. package/src/embed/ts-embed.spec.ts +19 -9
  68. package/src/embed/ts-embed.ts +24 -15
  69. package/src/index.ts +5 -1
  70. package/src/test/test-utils.ts +1 -1
  71. package/src/types.ts +22 -0
  72. package/src/utils/authService.spec.ts +31 -5
  73. package/src/utils/authService.ts +27 -3
  74. package/src/utils/processData.spec.ts +139 -4
  75. package/src/utils/processData.ts +54 -4
  76. package/lib/src/utils/fetchAnswers.d.ts +0 -3
  77. package/lib/src/utils/fetchAnswers.js +0 -49
  78. package/lib/src/utils/fetchAnswers.js.map +0 -1
@@ -1,9 +1,20 @@
1
1
  import * as processDataInstance from './processData';
2
2
  import * as answerServiceInstance from './answerService';
3
3
  import * as auth from '../auth';
4
- import { EmbedEvent, OperationType } from '../types';
4
+ import * as base from '../embed/base';
5
+ import { EmbedEvent, OperationType, AuthType } from '../types';
5
6
 
6
7
  describe('Unit test for process data', () => {
8
+ beforeAll(() => {
9
+ base.init({
10
+ thoughtSpotHost: '',
11
+ authType: AuthType.None,
12
+ });
13
+ });
14
+ afterEach(() => {
15
+ jest.resetAllMocks();
16
+ });
17
+
7
18
  const thoughtSpotHost = 'http://localhost';
8
19
  test('processDataInstance, when operation is GetChartWithData', () => {
9
20
  const answerService = {};
@@ -34,10 +45,11 @@ describe('Unit test for process data', () => {
34
45
  'processCustomAction',
35
46
  ).mockImplementation(async () => ({}));
36
47
  expect(
37
- processDataInstance.getProcessData(
48
+ processDataInstance.processEventData(
38
49
  EmbedEvent.CustomAction,
39
50
  processedData,
40
51
  thoughtSpotHost,
52
+ null,
41
53
  ),
42
54
  ).toStrictEqual(processedData);
43
55
  });
@@ -52,10 +64,11 @@ describe('Unit test for process data', () => {
52
64
  answerServiceInstance,
53
65
  'getAnswerServiceInstance',
54
66
  ).mockImplementation(async () => ({}));
55
- processDataInstance.getProcessData(
67
+ processDataInstance.processEventData(
56
68
  EmbedEvent.Data,
57
69
  processedData,
58
70
  thoughtSpotHost,
71
+ null,
59
72
  );
60
73
  expect(processDataInstance.processCustomAction).not.toBeCalled();
61
74
  });
@@ -68,12 +81,134 @@ describe('Unit test for process data', () => {
68
81
  };
69
82
  const e = { type: EmbedEvent.AuthInit, data: sessionInfo };
70
83
  jest.spyOn(auth, 'initSession').mockReturnValue(null);
71
- expect(processDataInstance.getProcessData(e.type, e, '')).toEqual({
84
+ jest.spyOn(base, 'notifyAuthSuccess');
85
+ expect(
86
+ processDataInstance.processEventData(e.type, e, '', null),
87
+ ).toEqual({
72
88
  type: e.type,
73
89
  data: {
74
90
  userGUID: sessionInfo.userGUID,
75
91
  },
76
92
  });
77
93
  expect(auth.initSession).toBeCalledWith(sessionInfo);
94
+ expect(base.notifyAuthSuccess).toBeCalled();
95
+ });
96
+
97
+ test('AuthExpire autoLogin false', () => {
98
+ const e = { type: EmbedEvent.AuthExpire };
99
+ jest.spyOn(base, 'notifyAuthFailure');
100
+ jest.spyOn(base, 'handleAuth');
101
+ jest.spyOn(base, 'getEmbedConfig').mockReturnValue({
102
+ autoLogin: false,
103
+ });
104
+ expect(
105
+ processDataInstance.processEventData(e.type, e, '', null),
106
+ ).toEqual({
107
+ type: e.type,
108
+ });
109
+ expect(base.notifyAuthFailure).toBeCalledWith(
110
+ auth.AuthFailureType.EXPIRY,
111
+ );
112
+ expect(base.handleAuth).not.toHaveBeenCalled();
113
+ });
114
+
115
+ test('AuthExpire autoLogin true', () => {
116
+ const e = { type: EmbedEvent.AuthExpire };
117
+ jest.spyOn(base, 'notifyAuthFailure');
118
+ jest.spyOn(base, 'handleAuth').mockResolvedValue(true);
119
+ jest.spyOn(base, 'getEmbedConfig').mockReturnValue({
120
+ autoLogin: true,
121
+ });
122
+ expect(
123
+ processDataInstance.processEventData(e.type, e, '', null),
124
+ ).toEqual({
125
+ type: e.type,
126
+ });
127
+ expect(base.notifyAuthFailure).toBeCalledWith(
128
+ auth.AuthFailureType.EXPIRY,
129
+ );
130
+ expect(base.handleAuth).toBeCalled();
131
+ });
132
+
133
+ test('NoCookieAccess no suppress alert', () => {
134
+ const e = { type: EmbedEvent.NoCookieAccess };
135
+ jest.spyOn(base, 'notifyAuthFailure');
136
+ jest.spyOn(base, 'getEmbedConfig').mockReturnValue({
137
+ loginFailedMessage: 'Hello',
138
+ suppressNoCookieAccessAlert: false,
139
+ });
140
+ jest.spyOn(window, 'alert').mockImplementation(() => undefined);
141
+ const el: any = {};
142
+ expect(processDataInstance.processEventData(e.type, e, '', el)).toEqual(
143
+ {
144
+ type: e.type,
145
+ },
146
+ );
147
+ expect(base.notifyAuthFailure).toBeCalledWith(
148
+ auth.AuthFailureType.NO_COOKIE_ACCESS,
149
+ );
150
+ expect(window.alert).toBeCalled();
151
+ expect(el.innerHTML).toBe('Hello');
152
+ });
153
+
154
+ test('NoCookieAccess suppressAlert=true', () => {
155
+ const e = { type: EmbedEvent.NoCookieAccess };
156
+ jest.spyOn(base, 'notifyAuthFailure');
157
+ jest.spyOn(base, 'getEmbedConfig').mockReturnValue({
158
+ loginFailedMessage: 'Hello',
159
+ suppressNoCookieAccessAlert: true,
160
+ });
161
+ jest.spyOn(window, 'alert').mockReset();
162
+ jest.spyOn(window, 'alert').mockImplementation(() => undefined);
163
+ const el: any = {};
164
+ expect(processDataInstance.processEventData(e.type, e, '', el)).toEqual(
165
+ {
166
+ type: e.type,
167
+ },
168
+ );
169
+ expect(base.notifyAuthFailure).toBeCalledWith(
170
+ auth.AuthFailureType.NO_COOKIE_ACCESS,
171
+ );
172
+ expect(window.alert).not.toBeCalled();
173
+ expect(el.innerHTML).toBe('Hello');
174
+ });
175
+
176
+ test('process authFailure', () => {
177
+ const e = { type: EmbedEvent.AuthFailure };
178
+ jest.spyOn(base, 'notifyAuthFailure');
179
+ jest.spyOn(base, 'getEmbedConfig').mockReturnValue({
180
+ loginFailedMessage: 'Hello',
181
+ });
182
+ const el: any = {};
183
+ expect(processDataInstance.processEventData(e.type, e, '', el)).toEqual(
184
+ {
185
+ type: e.type,
186
+ },
187
+ );
188
+ expect(base.notifyAuthFailure).toBeCalledWith(
189
+ auth.AuthFailureType.OTHER,
190
+ );
191
+ expect(el.innerHTML).toBe('Hello');
192
+ });
193
+
194
+ test('process authLogout', () => {
195
+ base.init({
196
+ loginFailedMessage: 'Hello',
197
+ autoLogin: true,
198
+ thoughtSpotHost: '',
199
+ authType: AuthType.None,
200
+ });
201
+ jest.spyOn(base, 'getEmbedConfig').mockRestore();
202
+ const e = { type: EmbedEvent.AuthLogout };
203
+ jest.spyOn(base, 'notifyLogout');
204
+ const el: any = {};
205
+ expect(processDataInstance.processEventData(e.type, e, '', el)).toEqual(
206
+ {
207
+ type: e.type,
208
+ },
209
+ );
210
+ expect(base.notifyLogout).toBeCalled();
211
+ expect(el.innerHTML).toBe('Hello');
212
+ expect(base.getEmbedConfig().autoLogin).toBe(false);
78
213
  });
79
214
  });
@@ -1,5 +1,12 @@
1
- import { getEmbedConfig, handleAuth } from '../embed/base';
2
- import { initSession } from '../auth';
1
+ import {
2
+ disableAutoLogin,
3
+ getEmbedConfig,
4
+ handleAuth,
5
+ notifyAuthFailure,
6
+ notifyAuthSuccess,
7
+ notifyLogout,
8
+ } from '../embed/base';
9
+ import { AuthFailureType, initSession } from '../auth';
3
10
  import { EmbedEvent, OperationType } from '../types';
4
11
  import { getAnswerServiceInstance } from './answerService';
5
12
 
@@ -28,6 +35,7 @@ export function processCustomAction(e: any, thoughtSpotHost: string) {
28
35
  function processAuthInit(e: any) {
29
36
  // Store user session details sent by app.
30
37
  initSession(e.data);
38
+ notifyAuthSuccess();
31
39
 
32
40
  // Expose only allowed details (eg: userGUID) back to SDK users.
33
41
  return {
@@ -43,14 +51,50 @@ function processAuthExpire(e: any) {
43
51
  if (autoLogin) {
44
52
  handleAuth();
45
53
  }
54
+ notifyAuthFailure(AuthFailureType.EXPIRY);
46
55
  return e;
47
56
  }
48
57
 
49
- export function getProcessData(
58
+ function processNoCookieAccess(e: any, containerEl: Element) {
59
+ const {
60
+ loginFailedMessage,
61
+ suppressNoCookieAccessAlert,
62
+ } = getEmbedConfig();
63
+ if (!suppressNoCookieAccessAlert) {
64
+ // eslint-disable-next-line no-alert
65
+ alert(
66
+ 'Third party cookie access is blocked on this browser, please allow third party cookies for this to work properly. \nYou can use `suppressNoCookieAccessAlert` to suppress this message.',
67
+ );
68
+ }
69
+ // eslint-disable-next-line no-param-reassign
70
+ containerEl.innerHTML = loginFailedMessage;
71
+ notifyAuthFailure(AuthFailureType.NO_COOKIE_ACCESS);
72
+ return e;
73
+ }
74
+
75
+ function processAuthFailure(e: any, containerEl: Element) {
76
+ const { loginFailedMessage } = getEmbedConfig();
77
+ // eslint-disable-next-line no-param-reassign
78
+ containerEl.innerHTML = loginFailedMessage;
79
+ notifyAuthFailure(AuthFailureType.OTHER);
80
+ return e;
81
+ }
82
+
83
+ function processAuthLogout(e: any, containerEl: Element) {
84
+ const { loginFailedMessage } = getEmbedConfig();
85
+ // eslint-disable-next-line no-param-reassign
86
+ containerEl.innerHTML = loginFailedMessage;
87
+ disableAutoLogin();
88
+ notifyLogout();
89
+ return e;
90
+ }
91
+
92
+ export function processEventData(
50
93
  type: EmbedEvent,
51
94
  e: any,
52
95
  thoughtSpotHost: string,
53
- ) {
96
+ containerEl: Element,
97
+ ): any {
54
98
  switch (type) {
55
99
  case EmbedEvent.CustomAction:
56
100
  return processCustomAction(e, thoughtSpotHost);
@@ -58,6 +102,12 @@ export function getProcessData(
58
102
  return processAuthInit(e);
59
103
  case EmbedEvent.AuthExpire:
60
104
  return processAuthExpire(e);
105
+ case EmbedEvent.NoCookieAccess:
106
+ return processNoCookieAccess(e, containerEl);
107
+ case EmbedEvent.AuthFailure:
108
+ return processAuthFailure(e, containerEl);
109
+ case EmbedEvent.AuthLogout:
110
+ return processAuthLogout(e, containerEl);
61
111
  default:
62
112
  }
63
113
  return e;
@@ -1,3 +0,0 @@
1
- import { SessionInterface } from '../types';
2
- declare function FetchAnswers(session: SessionInterface, query: string, operation: string, thoughtSpotHost: string): any;
3
- export default FetchAnswers;
@@ -1,49 +0,0 @@
1
- import { OperationType } from '../types';
2
- function FetchAnswers(session, query, operation, thoughtSpotHost) {
3
- let variable;
4
- const fetchQuery = async (variables) => {
5
- try {
6
- const response = await fetch(`${thoughtSpotHost}/prism/?op=${operation}`, {
7
- method: 'POST',
8
- headers: {
9
- 'content-type': 'application/json;charset=UTF-8',
10
- 'x-requested-by': 'ThoughtSpot',
11
- accept: '*/*',
12
- 'accept-language': 'en-us',
13
- },
14
- body: JSON.stringify({
15
- operationName: operation,
16
- query,
17
- variables,
18
- }),
19
- credentials: 'include'
20
- });
21
- const result = await response.json();
22
- return result.data;
23
- }
24
- catch (error) {
25
- return error;
26
- }
27
- };
28
- const getAnswer = (offset, batchSize) => {
29
- if (operation === OperationType.GetChartWithData) {
30
- variable = { batchSize, offset };
31
- }
32
- else {
33
- variable = {
34
- dataPaginationParams: {
35
- isClientPaginated: true,
36
- offset,
37
- size: batchSize,
38
- },
39
- };
40
- }
41
- return fetchQuery({
42
- session,
43
- ...variable,
44
- });
45
- };
46
- return getAnswer;
47
- }
48
- export default FetchAnswers;
49
- //# sourceMappingURL=fetchAnswers.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"fetchAnswers.js","sourceRoot":"","sources":["../../../src/utils/fetchAnswers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,aAAa,EAAE,MAAM,UAAU,CAAC;AAE3D,SAAS,YAAY,CACjB,OAAyB,EACzB,KAAa,EACb,SAAiB,EACjB,eAAuB;IAEvB,IAAI,QAAa,CAAC;IAElB,MAAM,UAAU,GAAG,KAAK,EAAE,SAAc,EAAE,EAAE;QACxC,IAAI;YACA,MAAM,QAAQ,GAAG,MAAM,KAAK,CACxB,GAAG,eAAe,cAAc,SAAS,EAAE,EAC3C;gBACI,MAAM,EAAE,MAAM;gBACd,OAAO,EAAE;oBACL,cAAc,EAAE,gCAAgC;oBAChD,gBAAgB,EAAE,aAAa;oBAC/B,MAAM,EAAE,KAAK;oBACb,iBAAiB,EAAE,OAAO;iBAC7B;gBACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;oBACjB,aAAa,EAAE,SAAS;oBACxB,KAAK;oBACL,SAAS;iBACZ,CAAC;gBACF,WAAW,EAAE,SAAS;aACzB,CACA,CAAC;YACF,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;YACrC,OAAO,MAAM,CAAC,IAAI,CAAC;SACtB;QAAC,OAAO,KAAK,EAAE;YACZ,OAAO,KAAK,CAAC;SAChB;IACL,CAAC,CAAC;IAEF,MAAM,SAAS,GAAG,CAAC,MAAc,EAAE,SAAiB,EAAE,EAAE;QACpD,IAAI,SAAS,KAAK,aAAa,CAAC,gBAAgB,EAAE;YAC9C,QAAQ,GAAG,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC;SACpC;aAAM;YACH,QAAQ,GAAG;gBACP,oBAAoB,EAAE;oBAClB,iBAAiB,EAAE,IAAI;oBACvB,MAAM;oBACN,IAAI,EAAE,SAAS;iBAClB;aACJ,CAAC;SACL;QACD,OAAO,UAAU,CAAC;YACd,OAAO;YACP,GAAG,QAAQ;SACd,CAAC,CAAC;IACP,CAAC,CAAC;IAEF,OAAO,SAAS,CAAC;AACrB,CAAC;AAED,eAAe,YAAY,CAAC"}