@thoughtspot/visual-embed-sdk 1.10.0-alpha.2 → 1.10.0

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 (44) hide show
  1. package/CHANGELOG.md +14 -2
  2. package/README.md +22 -3
  3. package/dist/src/embed/app.d.ts +9 -3
  4. package/dist/src/embed/search.d.ts +4 -0
  5. package/dist/src/embed/ts-embed.d.ts +18 -4
  6. package/dist/src/types.d.ts +139 -3
  7. package/dist/src/utils.d.ts +4 -0
  8. package/dist/tsembed.es.js +179 -21
  9. package/dist/tsembed.js +179 -21
  10. package/lib/package.json +2 -2
  11. package/lib/src/embed/app.d.ts +9 -3
  12. package/lib/src/embed/app.js +23 -7
  13. package/lib/src/embed/app.js.map +1 -1
  14. package/lib/src/embed/app.spec.js +36 -2
  15. package/lib/src/embed/app.spec.js.map +1 -1
  16. package/lib/src/embed/base.spec.js +13 -1
  17. package/lib/src/embed/base.spec.js.map +1 -1
  18. package/lib/src/embed/events.spec.js +30 -1
  19. package/lib/src/embed/events.spec.js.map +1 -1
  20. package/lib/src/embed/search.d.ts +4 -0
  21. package/lib/src/embed/search.js +1 -1
  22. package/lib/src/embed/search.js.map +1 -1
  23. package/lib/src/embed/ts-embed.d.ts +18 -4
  24. package/lib/src/embed/ts-embed.js +36 -14
  25. package/lib/src/embed/ts-embed.js.map +1 -1
  26. package/lib/src/embed/ts-embed.spec.js +123 -14
  27. package/lib/src/embed/ts-embed.spec.js.map +1 -1
  28. package/lib/src/types.d.ts +139 -3
  29. package/lib/src/types.js +116 -0
  30. package/lib/src/types.js.map +1 -1
  31. package/lib/src/utils.d.ts +4 -0
  32. package/lib/src/utils.js +4 -0
  33. package/lib/src/utils.js.map +1 -1
  34. package/lib/src/visual-embed-sdk.d.ts +170 -10
  35. package/package.json +2 -2
  36. package/src/embed/app.spec.ts +49 -1
  37. package/src/embed/app.ts +24 -6
  38. package/src/embed/base.spec.ts +14 -0
  39. package/src/embed/events.spec.ts +32 -0
  40. package/src/embed/search.ts +5 -0
  41. package/src/embed/ts-embed.spec.ts +166 -14
  42. package/src/embed/ts-embed.ts +56 -16
  43. package/src/types.ts +148 -1
  44. package/src/utils.ts +5 -0
package/CHANGELOG.md CHANGED
@@ -8,14 +8,26 @@ This project follows Semantic Versioning.
8
8
  ### New Features
9
9
  - Events for all actions on Search Embed
10
10
 
11
+ ## 1.9.5 (04-06-2022)
12
+
13
+ ### New Features
14
+ - `locale` param to set Locale/language for the embedded view.
15
+
16
+
17
+ ## 1.9.4 (04-06-2022)
18
+
19
+ ### Fixed
20
+ - [React] `className` should be forwarded to the iframe container div.
21
+
22
+
11
23
  ## 1.9.3 (03-22-2022)
12
24
 
13
- ### New Features
25
+ ### New Features
14
26
  - `disableLoginRedirect` option in `EmbedConfig`
15
27
 
16
28
  ## 1.9.2 (03-17-2022)
17
29
 
18
- ### New Features
30
+ ### New Features
19
31
  - Ability to trigger events on React components
20
32
  - Added new `useEmbedRef` hook, check README for usage.
21
33
 
package/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  <br/>
6
6
 
7
- # ThoughtSpot Visual Embed SDK [![Coverage Status](https://coveralls.io/repos/github/ts-blink/embed-sdk/badge.svg?branch=main)](https://coveralls.io/github/ts-blink/embed-sdk?branch=main) ![npm (scoped with tag)](https://img.shields.io/npm/v/@thoughtspot/visual-embed-sdk) [![](https://data.jsdelivr.com/v1/package/npm/@thoughtspot/visual-embed-sdk/badge?style=rounded)](https://www.jsdelivr.com/package/npm/@thoughtspot/visual-embed-sdk)
7
+ # ThoughtSpot Visual Embed SDK <br/> [![Coverage Status](https://coveralls.io/repos/github/ts-blink/embed-sdk/badge.svg?branch=main)](https://coveralls.io/github/ts-blink/embed-sdk?branch=main) ![npm (scoped with tag)](https://img.shields.io/npm/v/@thoughtspot/visual-embed-sdk) [![](https://data.jsdelivr.com/v1/package/npm/@thoughtspot/visual-embed-sdk/badge?style=rounded)](https://www.jsdelivr.com/package/npm/@thoughtspot/visual-embed-sdk) ![npm](https://img.shields.io/npm/dm/@thoughtspot/visual-embed-sdk?label=npm%20downloads&style=flat-square)
8
8
 
9
9
  SDK to embed ThoughtSpot into your web apps.
10
10
 
@@ -25,6 +25,8 @@ The SDK is written in TypeScript and is also provided both as ES Module (ESM) an
25
25
  ```js
26
26
  // ESM via NPM
27
27
  import * as TsEmbedSDK from '@thoughtspot/visual-embed-sdk';
28
+ // OR
29
+ import { LiveboardEmbed } from '@thoughtspot/visual-embed-sdk';
28
30
 
29
31
  // NPM <script>
30
32
  <script src="https://cdn.jsdelivr.net/npm/@thoughtspot/visual-embed-sdk/dist/tsembed.js"></script>;
@@ -41,7 +43,8 @@ import {
41
43
 
42
44
  ## Live Playground
43
45
 
44
- Visit our [code playground](https://try-everywhere.thoughtspot.cloud/v2/#/everywhere).
46
+ Visit our [code playground](https://try-everywhere.thoughtspot.cloud/v2/#/everywhere). <br/><br/>
47
+ Start a [free trial](https://www.thoughtspot.com/trial?tsref=trialtse) on your own data.
45
48
 
46
49
  <br/>
47
50
 
@@ -132,10 +135,26 @@ const appEmbed = new AppEmbed(document.getElementById('ts-embed'), {
132
135
  appEmbed.render();
133
136
  ```
134
137
 
138
+ ### Triggering and Listening to events
139
+ ```js
140
+ // NPM
141
+ import { LiveboardEmbed, Page, AuthType, init, EmbedEvent, HostEvent } from '@thoughtspot/visual-embed-sdk';
142
+
143
+ // .. Do init and create a liveboardEmbed object as above.
144
+
145
+ liveboardEmbed.render();
146
+
147
+ liveboardEmbed.on(EmbedEvent.LiveboardRendered, () => {
148
+ liveboardEmbed.trigger(HostEvent.SetVisibleVizs, ['viz1', 'viz2']);
149
+ });
150
+ ```
151
+
135
152
  ## React Components
136
153
 
137
154
  All the above flavors of embedding are also provided as React components for your convenience.
138
155
  The constructor options are passed as props and the event listeners can be attached using `on<EventName>` convention.
156
+ <br/><br/>
157
+ Checkout a comprehensive working demo [here](https://codesandbox.io/s/github/ashubham/big-react-demo)
139
158
 
140
159
  ### Search Component
141
160
 
@@ -166,7 +185,7 @@ const MyComponent = ({ dataSources }) => {
166
185
  };
167
186
  ```
168
187
 
169
- ### Triggering events on React components
188
+ ### Triggering events on React components (> version 1.9.2)
170
189
 
171
190
  ```jsx
172
191
  import { HostEvent } from '@thoughtspot/visual-embed-sdk';
@@ -37,7 +37,11 @@ export declare enum Page {
37
37
  /**
38
38
  * Data management page
39
39
  */
40
- Data = "data"
40
+ Data = "data",
41
+ /**
42
+ * SpotIQ listing page
43
+ */
44
+ SpotIQ = "spotiq"
41
45
  }
42
46
  /**
43
47
  * The view configuration for full app embedding.
@@ -114,10 +118,12 @@ export declare class AppEmbed extends V1Embed {
114
118
  /**
115
119
  * Navigate to particular page for app embed. eg:answers/pinboards/home
116
120
  * This is used for embedding answers, pinboards, visualizations and full application only.
117
- * @param path The string, set to iframe src and navigate to new page
121
+ * @param path string | number The string, set to iframe src and navigate to new page
118
122
  * eg: appEmbed.navigateToPage('pinboards')
123
+ * When used with `noReload` this can also be a number like 1/-1 to go forward/back.
124
+ * @param noReload boolean Trigger the navigation without reloading the page (version: 1.12.0 | 8.4.0.cl)
119
125
  */
120
- navigateToPage(path: string): void;
126
+ navigateToPage(path: string | number, noReload?: boolean): void;
121
127
  /**
122
128
  * Renders the embedded application pages in the ThoughtSpot app.
123
129
  * @param renderOptions An object containing the page ID
@@ -44,6 +44,10 @@ export interface SearchViewConfig extends ViewConfig {
44
44
  * using raw answer data.
45
45
  */
46
46
  hideResults?: boolean;
47
+ /**
48
+ * If set to true, expands all the data sources panel.
49
+ */
50
+ expandAllDataSource?: boolean;
47
51
  /**
48
52
  * If set to true, the Search Assist feature is enabled.
49
53
  */
@@ -6,7 +6,7 @@
6
6
  * @summary Base classes
7
7
  * @author Ayon Ghosh <ayon.ghosh@thoughtspot.com>
8
8
  */
9
- import { DOMSelector, HostEvent, EmbedEvent, MessageCallback, Action, RuntimeFilter, EmbedConfig } from '../types';
9
+ import { DOMSelector, HostEvent, EmbedEvent, MessageCallback, Action, RuntimeFilter, EmbedConfig, MessageOptions } from '../types';
10
10
  /**
11
11
  * Global prefix for all Thoughtspot postHash Params.
12
12
  */
@@ -71,15 +71,28 @@ export interface ViewConfig {
71
71
  * @version 1.6.0 or later
72
72
  */
73
73
  visibleActions?: Action[];
74
+ /**
75
+ * Show alert messages and toast messages in the embedded view.
76
+ * @version 1.11.0 | ThoughtSpot: 8.3.0.cl
77
+ */
78
+ showAlerts?: boolean;
74
79
  /**
75
80
  * The list of runtime filters to apply to a search answer,
76
81
  * visualization, or Liveboard.
77
82
  */
78
83
  runtimeFilters?: RuntimeFilter[];
84
+ /**
85
+ * The locale/language to use for the embedded view.
86
+ * @version 1.9.4 or later
87
+ */
88
+ locale?: string;
79
89
  /**
80
90
  * This is an object (key/val) of override flags which will be applied
81
91
  * to the internal embedded object. This can be used to add any
82
92
  * URL flag.
93
+ * Warning: This option is for advanced use only and is used internally
94
+ * to control embed behavior in non-regular ways. We do not publish the
95
+ * list of supported keys and values associated with each.
83
96
  * @version SDK: 1.9.0 | ThoughtSpot: 8.1.0.cl
84
97
  */
85
98
  additionalFlags?: {
@@ -236,9 +249,10 @@ export declare class TsEmbed {
236
249
  * sends an event of a particular message type to the host application.
237
250
  *
238
251
  * @param messageType The message type
239
- * @param callback A callback function
252
+ * @param callback A callback as a function
253
+ * @param options The message options
240
254
  */
241
- on(messageType: EmbedEvent, callback: MessageCallback): typeof TsEmbed.prototype;
255
+ on(messageType: EmbedEvent, callback: MessageCallback, options?: MessageOptions): typeof TsEmbed.prototype;
242
256
  /**
243
257
  * Triggers an event on specific Port registered against
244
258
  * for the EmbedEvent
@@ -279,5 +293,5 @@ export declare class V1Embed extends TsEmbed {
279
293
  * @param iframeSrc
280
294
  */
281
295
  protected renderV1Embed(iframeSrc: string): void;
282
- on(messageType: EmbedEvent, callback: MessageCallback): typeof TsEmbed.prototype;
296
+ on(messageType: EmbedEvent, callback: MessageCallback, options?: MessageOptions): typeof TsEmbed.prototype;
283
297
  }
@@ -140,11 +140,31 @@ export interface EmbedConfig {
140
140
  */
141
141
  customCssUrl?: string;
142
142
  }
143
+ /**
144
+ * MessagePayload: Embed event payload: message type, data and status (start/end)
145
+ */
143
146
  export declare type MessagePayload = {
144
147
  type: string;
145
148
  data: any;
149
+ status?: string;
150
+ };
151
+ /**
152
+ * MessageOptions: By Providing options, getting specific event start / end based on option
153
+ */
154
+ export declare type MessageOptions = {
155
+ start?: boolean;
146
156
  };
157
+ /**
158
+ * MessageCallback: Embed event message callback
159
+ */
147
160
  export declare type MessageCallback = (payload: MessagePayload, responder?: (data: any) => void) => void;
161
+ /**
162
+ * MessageCallbackObj: contains message options & callback function
163
+ */
164
+ export declare type MessageCallbackObj = {
165
+ options: MessageOptions;
166
+ callback: MessageCallback;
167
+ };
148
168
  export declare type GenericCallbackFn = (...args: any[]) => any;
149
169
  export declare type QueryParams = {
150
170
  [key: string]: string;
@@ -292,6 +312,12 @@ export declare enum EmbedEvent {
292
312
  * @version 1.5.0 or later
293
313
  */
294
314
  VizPointDoubleClick = "vizPointDoubleClick",
315
+ /**
316
+ * A click has been triggered on table/chart
317
+ * @return ContextMenuInputPoints - data point that is clicked
318
+ * @version SDK: 1.11.0 | ThoughtSpot: 8.3.0.cl
319
+ */
320
+ VizPointClick = "vizPointClick",
295
321
  /**
296
322
  * An error has occurred.
297
323
  * @return error - An error object or message
@@ -356,7 +382,108 @@ export declare enum EmbedEvent {
356
382
  * rendered liveboard
357
383
  * @version 1.9.1 or later
358
384
  */
359
- LiveboardRendered = "PinboardRendered"
385
+ LiveboardRendered = "PinboardRendered",
386
+ /**
387
+ * This can be used to register an event listener which
388
+ * is triggered on all events.
389
+ * @version SDK: 1.10.0 | ThoughtSpot: any
390
+ */
391
+ ALL = "*",
392
+ /**
393
+ * Emitted when answer is saved in the app
394
+ * @version SDK: 1.11.0 | ThoughtSpot: 8.3.0.cl
395
+ */
396
+ Save = "save",
397
+ /**
398
+ * Emitted when the download action is triggered on an answer
399
+ * @version SDK: 1.11.0 | ThoughtSpot: 8.3.0.cl
400
+ */
401
+ Download = "download",
402
+ /**
403
+ * Emitted when the Download as PDF action is triggered on an answer
404
+ * @version SDK: 1.11.0 | ThoughtSpot: 8.3.0.cl
405
+ */
406
+ DownloadAsPdf = "downloadAsPdf",
407
+ /**
408
+ * Emitted when the Download as CSV action is triggered on an answer
409
+ * @version SDK: 1.11.0 | ThoughtSpot: 8.3.0.cl
410
+ */
411
+ DownloadAsCsv = "downloadAsCsv",
412
+ /**
413
+ * Emitted when the Download as XLSX action is triggered on an answer
414
+ * @version SDK: 1.11.0 | ThoughtSpot: 8.3.0.cl
415
+ */
416
+ DownloadAsXlsx = "downloadAsXlsx",
417
+ /**
418
+ * Emitted when an answer is deleted in the app
419
+ * @version SDK: 1.11.0 | ThoughtSpot: 8.3.0.cl
420
+ */
421
+ AnswerDelete = "answerDelete",
422
+ /**
423
+ * Emitted when an answer is pinned to a Liveboard
424
+ * @version SDK: 1.11.0 | ThoughtSpot: 8.3.0.cl
425
+ */
426
+ Pin = "pin",
427
+ /**
428
+ * Emitted when SpotIQ analysis is triggered
429
+ * @version SDK: 1.11.0 | ThoughtSpot: 8.3.0.cl
430
+ */
431
+ SpotIQAnalyze = "spotIQAnalyze",
432
+ /**
433
+ * Emitted when a user shares an object with another user or group
434
+ * @version SDK: 1.11.0 | ThoughtSpot: 8.3.0.cl
435
+ */
436
+ Share = "share",
437
+ /**
438
+ * Emitted when a user clicks the Include action to include a specific value or data on a chart or table
439
+ * @version SDK: 1.11.0 | ThoughtSpot: 8.3.0.cl
440
+ */
441
+ DrillInclude = "context-menu-item-include",
442
+ /**
443
+ * Emitted when a user clicks the Exclude action to exclude a specific value or data on a chart or table
444
+ * @version SDK: 1.11.0 | ThoughtSpot: 8.3.0.cl
445
+ */
446
+ DrillExclude = "context-menu-item-exclude",
447
+ /**
448
+ * Emitted when copied column value on the app
449
+ * @version SDK: 1.11.0 | ThoughtSpot: 8.3.0.cl
450
+ */
451
+ CopyToClipboard = "context-menu-item-copy-to-clipboard",
452
+ /**
453
+ * Emitted when a user clicks the Update TML action
454
+ * @version SDK: 1.11.0 | ThoughtSpot: 8.3.0.cl
455
+ */
456
+ UpdateTML = "updateTSL",
457
+ /**
458
+ * Emitted when a user clicks the Edit TML action
459
+ * @version SDK: 1.11.0 | ThoughtSpot: 8.3.0.cl
460
+ */
461
+ EditTML = "editTSL",
462
+ /**
463
+ * Emitted when ExportTML trigger in answer on the app
464
+ * @version SDK: 1.11.0 | ThoughtSpot: 8.3.0.cl
465
+ */
466
+ ExportTML = "exportTSL",
467
+ /**
468
+ * Emitted when an answer is saved as a view
469
+ * @version SDK: 1.11.0 | ThoughtSpot: 8.3.0.cl
470
+ */
471
+ SaveAsView = "saveAsView",
472
+ /**
473
+ * Emitted when copy of existing answer on the app
474
+ * @version SDK: 1.11.0 | ThoughtSpot: 8.3.0.cl
475
+ */
476
+ CopyAEdit = "copyAEdit",
477
+ /**
478
+ * Emitted when a user clicks Show underlying data on an answe
479
+ * @version SDK: 1.11.0 | ThoughtSpot: 8.3.0.cl
480
+ */
481
+ ShowUnderlyingData = "showUnderlyingData",
482
+ /**
483
+ * Emitted when an answer is switched to a chart or table view
484
+ * @version SDK: 1.11.0 | ThoughtSpot: 8.3.0.cl
485
+ */
486
+ AnswerChartSwitcher = "answerChartSwitcher"
360
487
  }
361
488
  /**
362
489
  * Event types that can be triggered by the host application
@@ -404,7 +531,14 @@ export declare enum HostEvent {
404
531
  * @param - {@link RuntimeFilter}[] an array of {@link RuntimeFilter} Types.
405
532
  * @version SDK: 1.9.0 | ThoughtSpot: 8.1.0.cl
406
533
  */
407
- UpdateRuntimeFilters = "UpdateRuntimeFilters"
534
+ UpdateRuntimeFilters = "UpdateRuntimeFilters",
535
+ /**
536
+ * Navigate to a specific page in App embed without any reload.
537
+ * This is the same as calling `appEmbed.navigateToPage(path, true)`
538
+ * @param path - the path to navigate to (can be a number[1/-1] to go forward/back)
539
+ * @version SDK: 1.12.0 | ThoughtSpot: 8.4.0.cl
540
+ */
541
+ Navigate = "Navigate"
408
542
  }
409
543
  /**
410
544
  * The different visual modes that the data sources panel within
@@ -456,7 +590,9 @@ export declare enum Param {
456
590
  CustomCSSUrl = "customCssUrl",
457
591
  DisableLoginRedirect = "disableLoginRedirect",
458
592
  visibleVizs = "pinboardVisibleVizs",
459
- LiveboardV2Enabled = "isPinboardV2Enabled"
593
+ LiveboardV2Enabled = "isPinboardV2Enabled",
594
+ ShowAlerts = "showAlerts",
595
+ Locale = "locale"
460
596
  }
461
597
  /**
462
598
  * The list of actions that can be performed on visual ThoughtSpot
@@ -34,6 +34,10 @@ export declare const getCssDimension: (value: number | string) => string;
34
34
  export declare const appendToUrlHash: (url: string, stringToAppend: string) => string;
35
35
  export declare const getEncodedQueryParamsString: (queryString: string) => string;
36
36
  export declare const getOffsetTop: (element: any) => any;
37
+ export declare const embedEventStatus: {
38
+ START: string;
39
+ END: string;
40
+ };
37
41
  export declare const setAttributes: (element: HTMLElement, attributes: {
38
42
  [key: string]: string | number | boolean;
39
43
  }) => void;