@thoughtspot/visual-embed-sdk 1.11.0-auth.9 → 1.11.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.
Files changed (97) hide show
  1. package/CHANGELOG.md +24 -2
  2. package/README.md +15 -2
  3. package/dist/src/auth.d.ts +13 -0
  4. package/dist/src/embed/base.d.ts +34 -4
  5. package/dist/src/embed/search.d.ts +4 -0
  6. package/dist/src/embed/ts-embed.d.ts +2 -2
  7. package/dist/src/index.d.ts +3 -2
  8. package/dist/src/types.d.ts +32 -1
  9. package/dist/src/utils/authService.d.ts +1 -0
  10. package/dist/src/utils/processData.d.ts +1 -1
  11. package/dist/src/utils.d.ts +1 -0
  12. package/dist/tsembed.es.js +1483 -2869
  13. package/dist/tsembed.js +1481 -2868
  14. package/lib/package.json +3 -2
  15. package/lib/src/auth.d.ts +13 -0
  16. package/lib/src/auth.js +35 -9
  17. package/lib/src/auth.js.map +1 -1
  18. package/lib/src/auth.spec.js +76 -1
  19. package/lib/src/auth.spec.js.map +1 -1
  20. package/lib/src/embed/app.spec.js +4 -3
  21. package/lib/src/embed/app.spec.js.map +1 -1
  22. package/lib/src/embed/base.d.ts +34 -4
  23. package/lib/src/embed/base.js +79 -11
  24. package/lib/src/embed/base.js.map +1 -1
  25. package/lib/src/embed/base.spec.js +50 -2
  26. package/lib/src/embed/base.spec.js.map +1 -1
  27. package/lib/src/embed/embed.spec.js +1 -1
  28. package/lib/src/embed/embed.spec.js.map +1 -1
  29. package/lib/src/embed/liveboard.spec.js +4 -3
  30. package/lib/src/embed/liveboard.spec.js.map +1 -1
  31. package/lib/src/embed/pinboard.spec.js +4 -3
  32. package/lib/src/embed/pinboard.spec.js.map +1 -1
  33. package/lib/src/embed/search.d.ts +4 -0
  34. package/lib/src/embed/search.js +1 -1
  35. package/lib/src/embed/search.js.map +1 -1
  36. package/lib/src/embed/search.spec.js +6 -1
  37. package/lib/src/embed/search.spec.js.map +1 -1
  38. package/lib/src/embed/ts-embed.d.ts +2 -2
  39. package/lib/src/embed/ts-embed.js +11 -20
  40. package/lib/src/embed/ts-embed.js.map +1 -1
  41. package/lib/src/embed/ts-embed.spec.js +1 -1
  42. package/lib/src/embed/ts-embed.spec.js.map +1 -1
  43. package/lib/src/index.d.ts +3 -2
  44. package/lib/src/index.js +3 -2
  45. package/lib/src/index.js.map +1 -1
  46. package/lib/src/react/index.spec.js +2 -2
  47. package/lib/src/react/index.spec.js.map +1 -1
  48. package/lib/src/types.d.ts +32 -1
  49. package/lib/src/types.js +14 -0
  50. package/lib/src/types.js.map +1 -1
  51. package/lib/src/utils/authService.d.ts +1 -0
  52. package/lib/src/utils/authService.js +12 -2
  53. package/lib/src/utils/authService.js.map +1 -1
  54. package/lib/src/utils/authService.spec.js +10 -0
  55. package/lib/src/utils/authService.spec.js.map +1 -1
  56. package/lib/src/utils/processData.d.ts +1 -1
  57. package/lib/src/utils/processData.js +37 -3
  58. package/lib/src/utils/processData.js.map +1 -1
  59. package/lib/src/utils/processData.spec.js +106 -4
  60. package/lib/src/utils/processData.spec.js.map +1 -1
  61. package/lib/src/utils.d.ts +1 -0
  62. package/lib/src/utils.js +4 -0
  63. package/lib/src/utils.js.map +1 -1
  64. package/lib/src/utils.spec.js +14 -1
  65. package/lib/src/utils.spec.js.map +1 -1
  66. package/lib/src/visual-embed-sdk.d.ts +135 -8
  67. package/package.json +3 -2
  68. package/src/auth.spec.ts +98 -2
  69. package/src/auth.ts +44 -7
  70. package/src/embed/app.spec.ts +4 -3
  71. package/src/embed/base.spec.ts +57 -3
  72. package/src/embed/base.ts +96 -15
  73. package/src/embed/embed.spec.ts +1 -1
  74. package/src/embed/liveboard.spec.ts +4 -3
  75. package/src/embed/pinboard.spec.ts +4 -3
  76. package/src/embed/search.spec.ts +6 -1
  77. package/src/embed/search.ts +5 -0
  78. package/src/embed/ts-embed.spec.ts +1 -1
  79. package/src/embed/ts-embed.ts +17 -23
  80. package/src/index.ts +5 -1
  81. package/src/react/index.spec.tsx +3 -2
  82. package/src/types.ts +32 -0
  83. package/src/utils/authService.spec.ts +13 -0
  84. package/src/utils/authService.ts +14 -2
  85. package/src/utils/processData.spec.ts +139 -4
  86. package/src/utils/processData.ts +54 -4
  87. package/src/utils.spec.ts +26 -0
  88. package/src/utils.ts +5 -0
  89. package/dist/src/embed/pinboard.d.ts +0 -91
  90. package/dist/src/utils/plugin.d.ts +0 -0
  91. package/dist/src/v1/api.d.ts +0 -19
  92. package/lib/src/embed/pinboard.d.ts +0 -91
  93. package/lib/src/embed/pinboard.js +0 -110
  94. package/lib/src/embed/pinboard.js.map +0 -1
  95. package/lib/src/utils/plugin.d.ts +0 -0
  96. package/lib/src/utils/plugin.js +0 -1
  97. package/lib/src/utils/plugin.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;
package/src/utils.spec.ts CHANGED
@@ -8,6 +8,7 @@ import {
8
8
  getCssDimension,
9
9
  getEncodedQueryParamsString,
10
10
  appendToUrlHash,
11
+ getRedirectUrl,
11
12
  } from './utils';
12
13
  import { RuntimeFilterOp } from './types';
13
14
 
@@ -80,6 +81,31 @@ describe('unit test for utils', () => {
80
81
  );
81
82
  });
82
83
 
84
+ describe('getRedirectURL', () => {
85
+ test('Should return correct value when path is undefined', () => {
86
+ expect(getRedirectUrl('http://myhost:3000', 'hashFrag')).toBe(
87
+ 'http://myhost:3000#hashFrag',
88
+ );
89
+ expect(getRedirectUrl('http://xyz.com/#foo', 'bar')).toBe(
90
+ 'http://xyz.com/#foobar',
91
+ );
92
+ });
93
+
94
+ test('Should return correct value when path is set', () => {
95
+ Object.defineProperty(window.location, 'origin', {
96
+ get: () => 'http://myhost:3000',
97
+ });
98
+
99
+ expect(
100
+ getRedirectUrl('http://myhost:3000/', 'hashFrag', '/bar'),
101
+ ).toBe('http://myhost:3000/bar#hashFrag');
102
+
103
+ expect(
104
+ getRedirectUrl('http://myhost:3000/#/foo', 'hashFrag', '#/bar'),
105
+ ).toBe('http://myhost:3000/#/barhashFrag');
106
+ });
107
+ });
108
+
83
109
  test('getEncodedQueryParamsString', () => {
84
110
  expect(getEncodedQueryParamsString('')).toBe('');
85
111
  expect(getEncodedQueryParamsString('test')).toBe('dGVzdA');
package/src/utils.ts CHANGED
@@ -121,6 +121,11 @@ export const appendToUrlHash = (url: string, stringToAppend: string) => {
121
121
  return outputUrl;
122
122
  };
123
123
 
124
+ export function getRedirectUrl(url: string, stringToAppend: string, path = '') {
125
+ const targetUrl = path ? new URL(path, window.location.origin).href : url;
126
+ return appendToUrlHash(targetUrl, stringToAppend);
127
+ }
128
+
124
129
  export const getEncodedQueryParamsString = (queryString: string) => {
125
130
  if (!queryString) {
126
131
  return queryString;
@@ -1,91 +0,0 @@
1
- /**
2
- * Copyright (c) 2021
3
- *
4
- * Embed a ThoughtSpot pinboard or visualization
5
- * https://developers.thoughtspot.com/docs/?pageid=embed-pinboard
6
- * https://developers.thoughtspot.com/docs/?pageid=embed-a-viz
7
- *
8
- * @summary Pinboard & visualization embed
9
- * @author Ayon Ghosh <ayon.ghosh@thoughtspot.com>
10
- */
11
- import { DOMSelector } from '../types';
12
- import { V1Embed, ViewConfig } from './ts-embed';
13
- /**
14
- * The configuration for the embedded pinboard or visualization page view.
15
- * @Category Pinboards and Charts
16
- */
17
- export interface PinboardViewConfig extends ViewConfig {
18
- /**
19
- * If set to true, the embedded object container dynamically resizes
20
- * according to the height of the pinboard.
21
- */
22
- fullHeight?: boolean;
23
- /**
24
- * This is the minimum height(in pixels) for a full height pinboard.
25
- * Setting this height helps resolves issues with empty pinboards and
26
- * other screens navigable from a pinboard.
27
- * @default 500
28
- * * _since 1.5.0_
29
- */
30
- defaultHeight?: number;
31
- /**
32
- * If set to true, the context menu in visualizations will be enabled.
33
- */
34
- enableVizTransformations?: boolean;
35
- /**
36
- * The pinboard to display in the embedded view.
37
- */
38
- pinboardId: string;
39
- /**
40
- * The visualization within the pinboard to display.
41
- */
42
- vizId?: string;
43
- /**
44
- * If set to true, all filter chips from a
45
- * pinboard page will be read-only (no X buttons)
46
- */
47
- preventPinboardFilterRemoval?: boolean;
48
- /**
49
- * An array of vizids which should be visible when this pinboard loads.
50
- * The ids not in this array are hidden from the pinboard.
51
- * _since: 1.6.0_
52
- */
53
- pinboardVisibleVizs?: string[];
54
- }
55
- /**
56
- * Embed a ThoughtSpot pinboard or visualization
57
- * @Category Pinboards and Charts
58
- */
59
- export declare class PinboardEmbed extends V1Embed {
60
- protected viewConfig: PinboardViewConfig;
61
- private defaultHeight;
62
- constructor(domSelector: DOMSelector, viewConfig: PinboardViewConfig);
63
- /**
64
- * Construct a map of params to be passed on to the
65
- * embedded pinboard or visualization.
66
- */
67
- private getEmbedParams;
68
- /**
69
- * Construct the URL of the embedded ThoughtSpot pinboard or visualization
70
- * to be loaded within the iframe.
71
- * @param pinboardId The GUID of the pinboard.
72
- * @param vizId The optional GUID of a visualization within the pinboard.
73
- * @param runtimeFilters A list of runtime filters to be applied to
74
- * the pinboard or visualization on load.
75
- */
76
- private getIFrameSrc;
77
- /**
78
- * Set the iframe height as per the computed height received
79
- * from the ThoughtSpot app.
80
- * @param data The event payload
81
- */
82
- private updateIFrameHeight;
83
- private embedIframeCenter;
84
- private handleRouteChangeFullHeightPinboard;
85
- /**
86
- * Render an embedded ThoughtSpot pinboard or visualization
87
- * @param renderOptions An object specifying the pinboard ID,
88
- * visualization ID and the runtime filters.
89
- */
90
- render(): PinboardEmbed;
91
- }
File without changes
@@ -1,19 +0,0 @@
1
- /**
2
- * Copyright: ThoughtSpot Inc. 2012-2016
3
- * Author: Shashank Singh (sunny@thoughtspot.com)
4
- *
5
- * @fileoverview ThoughtSpot Javascript API for use of ThoughtSpot in external webpages.
6
- */
7
- import { AuthType } from '../types';
8
- export declare enum Events {
9
- THOUGHTSPOT_AUTH_EXPIRED = "ThoughtspotAuthExpired",
10
- EXPORT_VIZ_DATA_TO_PARENT = "exportVizDataToParent",
11
- ALERT = "alert",
12
- EXPORT_VIZ_DATA_TO_CHILD = "exportVizDataToChild",
13
- GET_DATA = "getData"
14
- }
15
- declare type Callback = (...args: any[]) => void;
16
- declare function checkIfLoggedIn(tsHost: string, callback: Callback): void;
17
- declare function initialize(onInitialized: Callback, onAuthExpiration: Callback, _thoughtspotHost: string, authType: AuthType): void;
18
- declare function notifyOnAuthExpiration(): void;
19
- export { initialize, checkIfLoggedIn, notifyOnAuthExpiration };
@@ -1,91 +0,0 @@
1
- /**
2
- * Copyright (c) 2021
3
- *
4
- * Embed a ThoughtSpot pinboard or visualization
5
- * https://developers.thoughtspot.com/docs/?pageid=embed-pinboard
6
- * https://developers.thoughtspot.com/docs/?pageid=embed-a-viz
7
- *
8
- * @summary Pinboard & visualization embed
9
- * @author Ayon Ghosh <ayon.ghosh@thoughtspot.com>
10
- */
11
- import { DOMSelector } from '../types';
12
- import { V1Embed, ViewConfig } from './ts-embed';
13
- /**
14
- * The configuration for the embedded pinboard or visualization page view.
15
- * @Category Pinboards and Charts
16
- */
17
- export interface PinboardViewConfig extends ViewConfig {
18
- /**
19
- * If set to true, the embedded object container dynamically resizes
20
- * according to the height of the pinboard.
21
- */
22
- fullHeight?: boolean;
23
- /**
24
- * This is the minimum height(in pixels) for a full height pinboard.
25
- * Setting this height helps resolves issues with empty pinboards and
26
- * other screens navigable from a pinboard.
27
- * @default 500
28
- * * _since 1.5.0_
29
- */
30
- defaultHeight?: number;
31
- /**
32
- * If set to true, the context menu in visualizations will be enabled.
33
- */
34
- enableVizTransformations?: boolean;
35
- /**
36
- * The pinboard to display in the embedded view.
37
- */
38
- pinboardId: string;
39
- /**
40
- * The visualization within the pinboard to display.
41
- */
42
- vizId?: string;
43
- /**
44
- * If set to true, all filter chips from a
45
- * pinboard page will be read-only (no X buttons)
46
- */
47
- preventPinboardFilterRemoval?: boolean;
48
- /**
49
- * An array of vizids which should be visible when this pinboard loads.
50
- * The ids not in this array are hidden from the pinboard.
51
- * _since: 1.6.0_
52
- */
53
- pinboardVisibleVizs?: string[];
54
- }
55
- /**
56
- * Embed a ThoughtSpot pinboard or visualization
57
- * @Category Pinboards and Charts
58
- */
59
- export declare class PinboardEmbed extends V1Embed {
60
- protected viewConfig: PinboardViewConfig;
61
- private defaultHeight;
62
- constructor(domSelector: DOMSelector, viewConfig: PinboardViewConfig);
63
- /**
64
- * Construct a map of params to be passed on to the
65
- * embedded pinboard or visualization.
66
- */
67
- private getEmbedParams;
68
- /**
69
- * Construct the URL of the embedded ThoughtSpot pinboard or visualization
70
- * to be loaded within the iframe.
71
- * @param pinboardId The GUID of the pinboard.
72
- * @param vizId The optional GUID of a visualization within the pinboard.
73
- * @param runtimeFilters A list of runtime filters to be applied to
74
- * the pinboard or visualization on load.
75
- */
76
- private getIFrameSrc;
77
- /**
78
- * Set the iframe height as per the computed height received
79
- * from the ThoughtSpot app.
80
- * @param data The event payload
81
- */
82
- private updateIFrameHeight;
83
- private embedIframeCenter;
84
- private handleRouteChangeFullHeightPinboard;
85
- /**
86
- * Render an embedded ThoughtSpot pinboard or visualization
87
- * @param renderOptions An object specifying the pinboard ID,
88
- * visualization ID and the runtime filters.
89
- */
90
- render(): PinboardEmbed;
91
- }
@@ -1,110 +0,0 @@
1
- /**
2
- * Copyright (c) 2021
3
- *
4
- * Embed a ThoughtSpot pinboard or visualization
5
- * https://developers.thoughtspot.com/docs/?pageid=embed-pinboard
6
- * https://developers.thoughtspot.com/docs/?pageid=embed-a-viz
7
- *
8
- * @summary Pinboard & visualization embed
9
- * @author Ayon Ghosh <ayon.ghosh@thoughtspot.com>
10
- */
11
- import { ERROR_MESSAGE } from '../errors';
12
- import { EmbedEvent, Param, } from '../types';
13
- import { getFilterQuery, getQueryParamString } from '../utils';
14
- import { V1Embed } from './ts-embed';
15
- /**
16
- * Embed a ThoughtSpot pinboard or visualization
17
- * @Category Pinboards and Charts
18
- */
19
- export class PinboardEmbed extends V1Embed {
20
- // eslint-disable-next-line no-useless-constructor
21
- constructor(domSelector, viewConfig) {
22
- super(domSelector, viewConfig);
23
- this.defaultHeight = 500;
24
- /**
25
- * Set the iframe height as per the computed height received
26
- * from the ThoughtSpot app.
27
- * @param data The event payload
28
- */
29
- this.updateIFrameHeight = (data) => {
30
- this.setIFrameHeight(Math.max(data.data, this.defaultHeight));
31
- };
32
- this.embedIframeCenter = (data, responder) => {
33
- const obj = this.getIframeCenter();
34
- responder({ type: EmbedEvent.EmbedIframeCenter, data: obj });
35
- };
36
- this.handleRouteChangeFullHeightPinboard = (data) => {
37
- if (data.data.canvasState !== 'EMBED' &&
38
- data.data.canvasState !== 'pinboard') {
39
- this.setIFrameHeight(this.defaultHeight);
40
- }
41
- };
42
- }
43
- /**
44
- * Construct a map of params to be passed on to the
45
- * embedded pinboard or visualization.
46
- */
47
- getEmbedParams() {
48
- const params = this.getBaseQueryParams();
49
- const { enableVizTransformations, fullHeight, preventPinboardFilterRemoval, defaultHeight, pinboardVisibleVizs, } = this.viewConfig;
50
- if (fullHeight === true) {
51
- params[Param.fullHeight] = true;
52
- }
53
- if (defaultHeight) {
54
- this.defaultHeight = defaultHeight;
55
- }
56
- if (enableVizTransformations !== undefined) {
57
- params[Param.EnableVizTransformations] = enableVizTransformations.toString();
58
- }
59
- if (preventPinboardFilterRemoval) {
60
- params[Param.preventPinboardFilterRemoval] = true;
61
- }
62
- if (pinboardVisibleVizs) {
63
- params[Param.PinboardVisibleVizs] = pinboardVisibleVizs;
64
- }
65
- params[Param.livedBoardEmbed] = true;
66
- const queryParams = getQueryParamString(params, true);
67
- return queryParams;
68
- }
69
- /**
70
- * Construct the URL of the embedded ThoughtSpot pinboard or visualization
71
- * to be loaded within the iframe.
72
- * @param pinboardId The GUID of the pinboard.
73
- * @param vizId The optional GUID of a visualization within the pinboard.
74
- * @param runtimeFilters A list of runtime filters to be applied to
75
- * the pinboard or visualization on load.
76
- */
77
- getIFrameSrc(pinboardId, vizId, runtimeFilters) {
78
- const filterQuery = getFilterQuery(runtimeFilters || []);
79
- const queryParams = this.getEmbedParams();
80
- const queryString = [filterQuery, queryParams]
81
- .filter(Boolean)
82
- .join('&');
83
- let url = `${this.getV1EmbedBasePath(queryString, true, false, false)}/viz/${pinboardId}`;
84
- if (vizId) {
85
- url = `${url}/${vizId}`;
86
- }
87
- return url;
88
- }
89
- /**
90
- * Render an embedded ThoughtSpot pinboard or visualization
91
- * @param renderOptions An object specifying the pinboard ID,
92
- * visualization ID and the runtime filters.
93
- */
94
- render() {
95
- const { pinboardId, vizId, runtimeFilters } = this.viewConfig;
96
- if (!pinboardId && !vizId) {
97
- this.handleError(ERROR_MESSAGE.PINBOARD_VIZ_ID_VALIDATION);
98
- }
99
- if (this.viewConfig.fullHeight === true) {
100
- this.on(EmbedEvent.RouteChange, this.handleRouteChangeFullHeightPinboard);
101
- this.on(EmbedEvent.EmbedHeight, this.updateIFrameHeight);
102
- this.on(EmbedEvent.EmbedIframeCenter, this.embedIframeCenter);
103
- }
104
- super.render();
105
- const src = this.getIFrameSrc(pinboardId, vizId, runtimeFilters);
106
- this.renderV1Embed(src);
107
- return this;
108
- }
109
- }
110
- //# sourceMappingURL=pinboard.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"pinboard.js","sourceRoot":"","sources":["../../../src/embed/pinboard.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EACH,UAAU,EAEV,KAAK,GAIR,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAC/D,OAAO,EAAE,OAAO,EAAc,MAAM,YAAY,CAAC;AA6CjD;;;GAGG;AACH,MAAM,OAAO,aAAc,SAAQ,OAAO;IAKtC,kDAAkD;IAClD,YAAY,WAAwB,EAAE,UAA8B;QAChE,KAAK,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC;QAJ3B,kBAAa,GAAG,GAAG,CAAC;QA2E5B;;;;WAIG;QACK,uBAAkB,GAAG,CAAC,IAAoB,EAAE,EAAE;YAClD,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC;QAClE,CAAC,CAAC;QAEM,sBAAiB,GAAG,CAAC,IAAoB,EAAE,SAAc,EAAE,EAAE;YACjE,MAAM,GAAG,GAAG,IAAI,CAAC,eAAe,EAAE,CAAC;YACnC,SAAS,CAAC,EAAE,IAAI,EAAE,UAAU,CAAC,iBAAiB,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC;QACjE,CAAC,CAAC;QAEM,wCAAmC,GAAG,CAAC,IAAoB,EAAE,EAAE;YACnE,IACI,IAAI,CAAC,IAAI,CAAC,WAAW,KAAK,OAAO;gBACjC,IAAI,CAAC,IAAI,CAAC,WAAW,KAAK,UAAU,EACtC;gBACE,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;aAC5C;QACL,CAAC,CAAC;IA3FF,CAAC;IAED;;;OAGG;IACK,cAAc;QAClB,MAAM,MAAM,GAAG,IAAI,CAAC,kBAAkB,EAAE,CAAC;QACzC,MAAM,EACF,wBAAwB,EACxB,UAAU,EACV,4BAA4B,EAC5B,aAAa,EACb,mBAAmB,GACtB,GAAG,IAAI,CAAC,UAAU,CAAC;QAEpB,IAAI,UAAU,KAAK,IAAI,EAAE;YACrB,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,IAAI,CAAC;SACnC;QACD,IAAI,aAAa,EAAE;YACf,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;SACtC;QACD,IAAI,wBAAwB,KAAK,SAAS,EAAE;YACxC,MAAM,CACF,KAAK,CAAC,wBAAwB,CACjC,GAAG,wBAAwB,CAAC,QAAQ,EAAE,CAAC;SAC3C;QACD,IAAI,4BAA4B,EAAE;YAC9B,MAAM,CAAC,KAAK,CAAC,4BAA4B,CAAC,GAAG,IAAI,CAAC;SACrD;QACD,IAAI,mBAAmB,EAAE;YACrB,MAAM,CAAC,KAAK,CAAC,mBAAmB,CAAC,GAAG,mBAAmB,CAAC;SAC3D;QACD,MAAM,CAAC,KAAK,CAAC,eAAe,CAAC,GAAG,IAAI,CAAC;QACrC,MAAM,WAAW,GAAG,mBAAmB,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QAEtD,OAAO,WAAW,CAAC;IACvB,CAAC;IAED;;;;;;;OAOG;IACK,YAAY,CAChB,UAAkB,EAClB,KAAc,EACd,cAAgC;QAEhC,MAAM,WAAW,GAAG,cAAc,CAAC,cAAc,IAAI,EAAE,CAAC,CAAC;QACzD,MAAM,WAAW,GAAG,IAAI,CAAC,cAAc,EAAE,CAAC;QAC1C,MAAM,WAAW,GAAG,CAAC,WAAW,EAAE,WAAW,CAAC;aACzC,MAAM,CAAC,OAAO,CAAC;aACf,IAAI,CAAC,GAAG,CAAC,CAAC;QACf,IAAI,GAAG,GAAG,GAAG,IAAI,CAAC,kBAAkB,CAChC,WAAW,EACX,IAAI,EACJ,KAAK,EACL,KAAK,CACR,QAAQ,UAAU,EAAE,CAAC;QACtB,IAAI,KAAK,EAAE;YACP,GAAG,GAAG,GAAG,GAAG,IAAI,KAAK,EAAE,CAAC;SAC3B;QAED,OAAO,GAAG,CAAC;IACf,CAAC;IAyBD;;;;OAIG;IACI,MAAM;QACT,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,cAAc,EAAE,GAAG,IAAI,CAAC,UAAU,CAAC;QAE9D,IAAI,CAAC,UAAU,IAAI,CAAC,KAAK,EAAE;YACvB,IAAI,CAAC,WAAW,CAAC,aAAa,CAAC,0BAA0B,CAAC,CAAC;SAC9D;QAED,IAAI,IAAI,CAAC,UAAU,CAAC,UAAU,KAAK,IAAI,EAAE;YACrC,IAAI,CAAC,EAAE,CACH,UAAU,CAAC,WAAW,EACtB,IAAI,CAAC,mCAAmC,CAC3C,CAAC;YACF,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,WAAW,EAAE,IAAI,CAAC,kBAAkB,CAAC,CAAC;YACzD,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,iBAAiB,EAAE,IAAI,CAAC,iBAAiB,CAAC,CAAC;SACjE;QAED,KAAK,CAAC,MAAM,EAAE,CAAC;QAEf,MAAM,GAAG,GAAG,IAAI,CAAC,YAAY,CAAC,UAAU,EAAE,KAAK,EAAE,cAAc,CAAC,CAAC;QACjE,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;QAExB,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ"}
File without changes
@@ -1 +0,0 @@
1
- //# sourceMappingURL=plugin.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../../src/utils/plugin.ts"],"names":[],"mappings":""}