@thoughtspot/visual-embed-sdk 1.35.5-hostEvent.5 → 1.35.5-hostEvent.7

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 (79) hide show
  1. package/cjs/package.json +1 -1
  2. package/cjs/src/embed/hostEventClient/contracts.d.ts +27 -31
  3. package/cjs/src/embed/hostEventClient/contracts.d.ts.map +1 -1
  4. package/cjs/src/embed/hostEventClient/contracts.js +10 -10
  5. package/cjs/src/embed/hostEventClient/contracts.js.map +1 -1
  6. package/cjs/src/embed/hostEventClient/host-event-client.d.ts +21 -7
  7. package/cjs/src/embed/hostEventClient/host-event-client.d.ts.map +1 -1
  8. package/cjs/src/embed/hostEventClient/host-event-client.js +61 -27
  9. package/cjs/src/embed/hostEventClient/host-event-client.js.map +1 -1
  10. package/cjs/src/embed/hostEventClient/host-event-client.spec.js +43 -39
  11. package/cjs/src/embed/hostEventClient/host-event-client.spec.js.map +1 -1
  12. package/cjs/src/embed/liveboard.spec.js +4 -2
  13. package/cjs/src/embed/liveboard.spec.js.map +1 -1
  14. package/cjs/src/embed/ts-embed.d.ts +13 -8
  15. package/cjs/src/embed/ts-embed.d.ts.map +1 -1
  16. package/cjs/src/embed/ts-embed.js +22 -14
  17. package/cjs/src/embed/ts-embed.js.map +1 -1
  18. package/cjs/src/embed/ts-embed.spec.js +4 -4
  19. package/cjs/src/embed/ts-embed.spec.js.map +1 -1
  20. package/cjs/src/index.d.ts +2 -2
  21. package/cjs/src/index.js +2 -2
  22. package/cjs/src/react/all-types-export.d.ts +1 -1
  23. package/cjs/src/react/all-types-export.js +2 -2
  24. package/cjs/src/types.d.ts +1 -1
  25. package/cjs/src/types.js +1 -1
  26. package/dist/index-DOIjN0N_.js +7370 -0
  27. package/dist/index-DaLHJaLd.js +7370 -0
  28. package/dist/src/embed/hostEventClient/contracts.d.ts +27 -31
  29. package/dist/src/embed/hostEventClient/contracts.d.ts.map +1 -1
  30. package/dist/src/embed/hostEventClient/host-event-client.d.ts +21 -7
  31. package/dist/src/embed/hostEventClient/host-event-client.d.ts.map +1 -1
  32. package/dist/src/embed/ts-embed.d.ts +13 -8
  33. package/dist/src/embed/ts-embed.d.ts.map +1 -1
  34. package/dist/src/index.d.ts +2 -2
  35. package/dist/src/react/all-types-export.d.ts +1 -1
  36. package/dist/src/types.d.ts +1 -1
  37. package/dist/tsembed-react.es.js +95 -54
  38. package/dist/tsembed-react.js +94 -53
  39. package/dist/tsembed.es.js +96 -55
  40. package/dist/tsembed.js +94 -53
  41. package/dist/visual-embed-sdk-react-full.d.ts +61 -46
  42. package/dist/visual-embed-sdk-react.d.ts +61 -46
  43. package/dist/visual-embed-sdk.d.ts +61 -46
  44. package/lib/package.json +1 -1
  45. package/lib/src/embed/hostEventClient/contracts.d.ts +27 -31
  46. package/lib/src/embed/hostEventClient/contracts.d.ts.map +1 -1
  47. package/lib/src/embed/hostEventClient/contracts.js +9 -9
  48. package/lib/src/embed/hostEventClient/contracts.js.map +1 -1
  49. package/lib/src/embed/hostEventClient/host-event-client.d.ts +21 -7
  50. package/lib/src/embed/hostEventClient/host-event-client.d.ts.map +1 -1
  51. package/lib/src/embed/hostEventClient/host-event-client.js +63 -29
  52. package/lib/src/embed/hostEventClient/host-event-client.js.map +1 -1
  53. package/lib/src/embed/hostEventClient/host-event-client.spec.js +43 -40
  54. package/lib/src/embed/hostEventClient/host-event-client.spec.js.map +1 -1
  55. package/lib/src/embed/liveboard.spec.js +4 -2
  56. package/lib/src/embed/liveboard.spec.js.map +1 -1
  57. package/lib/src/embed/ts-embed.d.ts +13 -8
  58. package/lib/src/embed/ts-embed.d.ts.map +1 -1
  59. package/lib/src/embed/ts-embed.js +22 -14
  60. package/lib/src/embed/ts-embed.js.map +1 -1
  61. package/lib/src/embed/ts-embed.spec.js +5 -5
  62. package/lib/src/embed/ts-embed.spec.js.map +1 -1
  63. package/lib/src/index.d.ts +2 -2
  64. package/lib/src/index.js +2 -2
  65. package/lib/src/react/all-types-export.d.ts +1 -1
  66. package/lib/src/react/all-types-export.js +1 -1
  67. package/lib/src/types.d.ts +1 -1
  68. package/lib/src/types.js +1 -1
  69. package/lib/src/visual-embed-sdk.d.ts +64 -49
  70. package/package.json +1 -1
  71. package/src/embed/hostEventClient/contracts.ts +44 -33
  72. package/src/embed/hostEventClient/host-event-client.spec.ts +58 -54
  73. package/src/embed/hostEventClient/host-event-client.ts +109 -47
  74. package/src/embed/liveboard.spec.ts +4 -2
  75. package/src/embed/ts-embed.spec.ts +6 -6
  76. package/src/embed/ts-embed.ts +38 -27
  77. package/src/index.ts +2 -2
  78. package/src/react/all-types-export.ts +1 -1
  79. package/src/types.ts +1 -1
@@ -29,8 +29,8 @@ declare module '@thoughtspot/visual-embed-sdk' {
29
29
  import { tokenizedFetch } from '@thoughtspot/visual-embed-sdk/tokenizedFetch';
30
30
  import { getAnswerFromQuery } from '@thoughtspot/visual-embed-sdk/utils/graphql/nlsService/nls-answer-service';
31
31
  import { createLiveboardWithAnswers } from '@thoughtspot/visual-embed-sdk/utils/liveboardService/liveboardService';
32
- import { UiPassthroughEvent } from '@thoughtspot/visual-embed-sdk/embed/hostEventClient/contracts';
33
- export { init, logout, prefetch, executeTML, exportTML, executeTMLInput, exportTMLInput, getEmbedConfig as getInitConfig, getSessionInfo, tokenizedFetch, getAnswerFromQuery, createLiveboardWithAnswers, SearchEmbed, SearchBarEmbed, PinboardEmbed, LiveboardEmbed, SageEmbed, AppEmbed, BodylessConversation, BodylessConversationViewConfig, ConversationEmbed, ConversationViewConfig, AuthFailureType, AuthStatus, AuthEvent, AuthEventEmitter, AnswerService, SessionInterface, UnderlyingDataPoint, Page, AuthType, RuntimeFilter, RuntimeFilterOp, EmbedEvent, HostEvent, DataSourceVisualMode, Action, ContextMenuTriggerOptions, EmbedConfig, SearchViewConfig, SearchBarViewConfig, LiveboardViewConfig, SageViewConfig, AppViewConfig, PrefetchFeatures, FrameParams, HomeLeftNavItem, HomepageModule, DOMSelector, MessageOptions, MessageCallback, MessagePayload, CustomisationsInterface, CustomStyles, customCssInterface, CustomCssVariables, RuntimeParameter, LogLevel, uploadMixpanelEvent, MIXPANEL_EVENT, HomePageSearchBarMode, VizPoint, CustomActionPayload, UiPassthroughEvent, };
32
+ import { UIPassthroughEvent } from '@thoughtspot/visual-embed-sdk/embed/hostEventClient/contracts';
33
+ export { init, logout, prefetch, executeTML, exportTML, executeTMLInput, exportTMLInput, getEmbedConfig as getInitConfig, getSessionInfo, tokenizedFetch, getAnswerFromQuery, createLiveboardWithAnswers, SearchEmbed, SearchBarEmbed, PinboardEmbed, LiveboardEmbed, SageEmbed, AppEmbed, BodylessConversation, BodylessConversationViewConfig, ConversationEmbed, ConversationViewConfig, AuthFailureType, AuthStatus, AuthEvent, AuthEventEmitter, AnswerService, SessionInterface, UnderlyingDataPoint, Page, AuthType, RuntimeFilter, RuntimeFilterOp, EmbedEvent, HostEvent, DataSourceVisualMode, Action, ContextMenuTriggerOptions, EmbedConfig, SearchViewConfig, SearchBarViewConfig, LiveboardViewConfig, SageViewConfig, AppViewConfig, PrefetchFeatures, FrameParams, HomeLeftNavItem, HomepageModule, DOMSelector, MessageOptions, MessageCallback, MessagePayload, CustomisationsInterface, CustomStyles, customCssInterface, CustomCssVariables, RuntimeParameter, LogLevel, uploadMixpanelEvent, MIXPANEL_EVENT, HomePageSearchBarMode, VizPoint, CustomActionPayload, UIPassthroughEvent, };
34
34
  export { resetCachedAuthToken } from '@thoughtspot/visual-embed-sdk/authToken';
35
35
  }
36
36
 
@@ -4960,7 +4960,7 @@ declare module '@thoughtspot/visual-embed-sdk/types' {
4960
4960
  * EmbedApi
4961
4961
  * @hidden
4962
4962
  */
4963
- UiPassthrough = "UiPassthrough"
4963
+ UIPassthrough = "UiPassthrough"
4964
4964
  }
4965
4965
  /**
4966
4966
  * The different visual modes that the data sources panel within
@@ -7145,16 +7145,16 @@ declare module '@thoughtspot/visual-embed-sdk/utils/liveboardService/liveboardSe
7145
7145
 
7146
7146
  declare module '@thoughtspot/visual-embed-sdk/embed/hostEventClient/contracts' {
7147
7147
  import { HostEvent } from '@thoughtspot/visual-embed-sdk/types';
7148
- export enum UiPassthroughEvent {
7149
- addVizToPinboard = "addVizToPinboard",
7150
- saveAnswer = "saveAnswer",
7151
- getDiscoverabilityStatus = "getDiscoverabilityStatus",
7152
- getAvailableUiPassthroughs = "getAvailableUiPassthroughs",
7153
- getAnswerPageConfig = "getAnswerPageConfig",
7154
- getPinboardPageConfig = "getPinboardPageConfig"
7148
+ export enum UIPassthroughEvent {
7149
+ PinAnswerToLiveboard = "addVizToPinboard",
7150
+ SaveAnswer = "saveAnswer",
7151
+ GetDiscoverabilityStatus = "getDiscoverabilityStatus",
7152
+ GetAvailableUIPassthroughs = "getAvailableUIPassthroughs",
7153
+ GetAnswerConfig = "getAnswerPageConfig",
7154
+ GetLiveboardConfig = "getPinboardPageConfig"
7155
7155
  }
7156
- export type UiPassthroughContractBase = {
7157
- [UiPassthroughEvent.addVizToPinboard]: {
7156
+ export type UIPassthroughContractBase = {
7157
+ [UIPassthroughEvent.PinAnswerToLiveboard]: {
7158
7158
  request: {
7159
7159
  vizId?: string;
7160
7160
  newVizName: string;
@@ -7170,62 +7170,58 @@ declare module '@thoughtspot/visual-embed-sdk/embed/hostEventClient/contracts' {
7170
7170
  vizId: string;
7171
7171
  };
7172
7172
  };
7173
- [UiPassthroughEvent.saveAnswer]: {
7173
+ [UIPassthroughEvent.SaveAnswer]: {
7174
7174
  request: {
7175
7175
  name: string;
7176
7176
  description: string;
7177
- vizId: string;
7177
+ vizId?: string;
7178
7178
  isDiscoverable?: boolean;
7179
7179
  };
7180
7180
  response: {
7181
7181
  answerId: string;
7182
- saveResponse: any;
7182
+ saveResponse?: any;
7183
7183
  shareResponse?: any;
7184
- errors?: any;
7185
7184
  };
7186
7185
  };
7187
- [UiPassthroughEvent.getDiscoverabilityStatus]: {
7186
+ [UIPassthroughEvent.GetDiscoverabilityStatus]: {
7188
7187
  request: any;
7189
7188
  response: {
7190
7189
  shouldShowDiscoverability: boolean;
7191
7190
  isDiscoverabilityCheckboxUnselectedPerOrg: boolean;
7192
7191
  };
7193
7192
  };
7194
- [UiPassthroughEvent.getAvailableUiPassthroughs]: {
7193
+ [UIPassthroughEvent.GetAvailableUIPassthroughs]: {
7195
7194
  request: any;
7196
7195
  response: {
7197
7196
  keys: string[];
7198
7197
  };
7199
7198
  };
7200
- [UiPassthroughEvent.getAnswerPageConfig]: {
7199
+ [UIPassthroughEvent.GetAnswerConfig]: {
7201
7200
  request: {
7202
7201
  vizId?: string;
7203
7202
  };
7204
7203
  response: any;
7205
7204
  };
7206
- [UiPassthroughEvent.getPinboardPageConfig]: {
7205
+ [UIPassthroughEvent.GetLiveboardConfig]: {
7207
7206
  request: any;
7208
7207
  response: any;
7209
7208
  };
7210
7209
  };
7211
- export type FlattenType<T> = T extends infer R ? {
7212
- [K in keyof R]: R[K];
7213
- } : never;
7214
- export type UiPassthroughRequest<T extends keyof UiPassthroughContractBase> = FlattenType<UiPassthroughContractBase[T]['request']>;
7215
- export type UiPassthroughResponse<T extends keyof UiPassthroughContractBase> = FlattenType<UiPassthroughContractBase[T]['response']>;
7216
- export type UiPassthroughArrayResponse<ApiName extends keyof UiPassthroughContractBase> = Promise<Array<{
7210
+ export type UIPassthroughRequest<T extends keyof UIPassthroughContractBase> = UIPassthroughContractBase[T]['request'];
7211
+ export type UIPassthroughResponse<T extends keyof UIPassthroughContractBase> = UIPassthroughContractBase[T]['response'];
7212
+ export type UIPassthroughArrayResponse<ApiName extends keyof UIPassthroughContractBase> = Array<{
7217
7213
  redId?: string;
7218
- value?: UiPassthroughResponse<ApiName>;
7214
+ value?: UIPassthroughResponse<ApiName>;
7219
7215
  error?: any;
7220
- }>>;
7216
+ }>;
7221
7217
  export type EmbedApiHostEventMapping = {
7222
- [HostEvent.Pin]: UiPassthroughEvent.addVizToPinboard;
7223
- [HostEvent.SaveAnswer]: UiPassthroughEvent.saveAnswer;
7218
+ [HostEvent.Pin]: UIPassthroughEvent.PinAnswerToLiveboard;
7219
+ [HostEvent.SaveAnswer]: UIPassthroughEvent.SaveAnswer;
7224
7220
  };
7225
- export type HostEventRequest<HostEventT extends HostEvent> = HostEventT extends keyof EmbedApiHostEventMapping ? FlattenType<UiPassthroughRequest<EmbedApiHostEventMapping[HostEventT]>> : any;
7226
- export type HostEventResponse<HostEventT extends HostEvent> = HostEventT extends keyof EmbedApiHostEventMapping ? {
7227
- value?: UiPassthroughResponse<EmbedApiHostEventMapping[HostEventT]>;
7228
- } : any;
7221
+ export type HostEventRequest<HostEventT extends HostEvent> = HostEventT extends keyof EmbedApiHostEventMapping ? UIPassthroughRequest<EmbedApiHostEventMapping[HostEventT]> : any;
7222
+ export type HostEventResponse<HostEventT extends HostEvent> = HostEventT extends keyof EmbedApiHostEventMapping ? UIPassthroughResponse<EmbedApiHostEventMapping[HostEventT]> : any;
7223
+ export type TriggerPayload<PayloadT, HostEventT extends HostEvent> = PayloadT | HostEventRequest<HostEventT>;
7224
+ export type TriggerResponse<PayloadT, HostEventT extends HostEvent> = PayloadT extends HostEventRequest<HostEventT> ? HostEventResponse<HostEventT> : any;
7229
7225
  }
7230
7226
 
7231
7227
  declare module '@thoughtspot/visual-embed-sdk/authToken' {
@@ -7255,7 +7251,7 @@ declare module '@thoughtspot/visual-embed-sdk/embed/ts-embed' {
7255
7251
  * @summary Base classes
7256
7252
  * @author Ayon Ghosh <ayon.ghosh@thoughtspot.com>
7257
7253
  */
7258
- import { HostEventRequest, HostEventResponse, UiPassthroughArrayResponse, UiPassthroughEvent, UiPassthroughRequest } from '@thoughtspot/visual-embed-sdk/embed/hostEventClient/contracts';
7254
+ import { TriggerPayload, TriggerResponse, UIPassthroughArrayResponse, UIPassthroughEvent, UIPassthroughRequest } from '@thoughtspot/visual-embed-sdk/embed/hostEventClient/contracts';
7259
7255
  import { AnswerService } from '@thoughtspot/visual-embed-sdk/utils/graphql/answerService/answerService';
7260
7256
  import { DOMSelector, HostEvent, EmbedEvent, MessageCallback, EmbedConfig, MessageOptions, ViewConfig } from '@thoughtspot/visual-embed-sdk/types';
7261
7257
  import { HostEventClient } from '@thoughtspot/visual-embed-sdk/embed/hostEventClient/host-event-client';
@@ -7290,6 +7286,11 @@ declare module '@thoughtspot/visual-embed-sdk/embed/ts-embed' {
7290
7286
  * will be rendered.
7291
7287
  */
7292
7288
  protected iFrame: HTMLIFrameElement;
7289
+ /**
7290
+ * Setter for the iframe element
7291
+ * @param {HTMLIFrameElement} iFrame HTMLIFrameElement
7292
+ */
7293
+ protected setIframeElement(iFrame: HTMLIFrameElement): void;
7293
7294
  protected viewConfig: ViewConfig;
7294
7295
  protected embedConfig: EmbedConfig;
7295
7296
  /**
@@ -7421,19 +7422,19 @@ declare module '@thoughtspot/visual-embed-sdk/embed/ts-embed' {
7421
7422
  off(messageType: EmbedEvent, callback: MessageCallback): typeof TsEmbed.prototype;
7422
7423
  /**
7423
7424
  * Triggers an event to the embedded app
7424
- * @param messageType The event type
7425
- * @param data The payload to send with the message
7425
+ * @param {HostEvent} messageType The event type
7426
+ * @param {any} data The payload to send with the message
7426
7427
  * @returns A promise that resolves with the response from the embedded app
7427
7428
  */
7428
- trigger<HostEventT extends HostEvent>(messageType: HostEventT, data?: HostEventRequest<HostEventT>): Promise<HostEventResponse<HostEventT>>;
7429
+ trigger<HostEventT extends HostEvent, PayloadT>(messageType: HostEventT, data?: TriggerPayload<PayloadT, HostEventT>): Promise<TriggerResponse<PayloadT, HostEventT>>;
7429
7430
  /**
7430
7431
  * Triggers an event to the embedded app, skipping the UI flow.
7431
- * @param {UiPassthroughEvent} apiName - The name of the API to be triggered.
7432
- * @param {UiPassthroughRequest} parameters - The parameters to be passed to the API.
7433
- * @returns {Promise<UiPassthroughRequest>} - A promise that resolves with the response
7432
+ * @param {UIPassthroughEvent} apiName - The name of the API to be triggered.
7433
+ * @param {UIPassthroughRequest} parameters - The parameters to be passed to the API.
7434
+ * @returns {Promise<UIPassthroughRequest>} - A promise that resolves with the response
7434
7435
  * from the embedded app.
7435
7436
  */
7436
- triggerUiPassThrough<UiPassthroughEventT extends UiPassthroughEvent>(apiName: UiPassthroughEventT, parameters: UiPassthroughRequest<UiPassthroughEventT>): UiPassthroughArrayResponse<UiPassthroughEventT>;
7437
+ triggerUIPassThrough<UIPassthroughEventT extends UIPassthroughEvent>(apiName: UIPassthroughEventT, parameters: UIPassthroughRequest<UIPassthroughEventT>): Promise<UIPassthroughArrayResponse<UIPassthroughEventT>>;
7437
7438
  /**
7438
7439
  * Marks the ThoughtSpot object to have been rendered
7439
7440
  * Needs to be overridden by subclasses to do the actual
@@ -7555,14 +7556,28 @@ declare module '@thoughtspot/visual-embed-sdk/embed/ts-embed' {
7555
7556
 
7556
7557
  declare module '@thoughtspot/visual-embed-sdk/embed/hostEventClient/host-event-client' {
7557
7558
  import { HostEvent } from '@thoughtspot/visual-embed-sdk/types';
7558
- import { UiPassthroughArrayResponse, UiPassthroughEvent, HostEventRequest, HostEventResponse, UiPassthroughRequest, UiPassthroughResponse } from '@thoughtspot/visual-embed-sdk/embed/hostEventClient/contracts';
7559
+ import { UIPassthroughArrayResponse, UIPassthroughEvent, HostEventRequest, HostEventResponse, UIPassthroughRequest, UIPassthroughResponse, TriggerPayload, TriggerResponse } from '@thoughtspot/visual-embed-sdk/embed/hostEventClient/contracts';
7559
7560
  export class HostEventClient {
7560
- thoughtSpotHost: string;
7561
- constructor(thoughtSpotHost: string);
7562
- executeUiPassthroughApi<UiPassthroughEventT extends UiPassthroughEvent>(iFrame: HTMLIFrameElement, apiName: UiPassthroughEventT, parameters: UiPassthroughRequest<UiPassthroughEventT>): UiPassthroughArrayResponse<UiPassthroughEventT>;
7563
- handleUiPassthroughForHostEvent<UiPassthroughEventT extends UiPassthroughEvent>(iFrame: HTMLIFrameElement, apiName: UiPassthroughEventT, parameters: UiPassthroughRequest<UiPassthroughEventT>): Promise<UiPassthroughResponse<UiPassthroughEventT>>;
7564
- hostEventFallback(iFrame: HTMLIFrameElement, hostEvent: HostEvent, data: any): Promise<any>;
7565
- executeHostEvent<T extends HostEvent>(iFrame: HTMLIFrameElement, hostEvent: HostEvent, payload?: HostEventRequest<T>): Promise<HostEventResponse<HostEvent>>;
7561
+ iFrame: HTMLIFrameElement;
7562
+ constructor(iFrame?: HTMLIFrameElement);
7563
+ /**
7564
+ * A wrapper over process trigger to
7565
+ * @param {HostEvent} message Host event to send
7566
+ * @param {any} data Data to send with the host event
7567
+ * @returns {Promise<any>} - the response from the process trigger
7568
+ */
7569
+ protected processTrigger(message: HostEvent, data: any): Promise<any>;
7570
+ handleHostEventWithParam<UIPassthroughEventT extends UIPassthroughEvent>(apiName: UIPassthroughEventT, parameters: UIPassthroughRequest<UIPassthroughEventT>): Promise<UIPassthroughResponse<UIPassthroughEventT>>;
7571
+ hostEventFallback(hostEvent: HostEvent, data: any): Promise<any>;
7572
+ /**
7573
+ * Setter for the iframe element used for host events
7574
+ * @param {HTMLIFrameElement} iFrame - the iframe element to set
7575
+ */
7576
+ setIframeElement(iFrame: HTMLIFrameElement): void;
7577
+ triggerUIPassthroughApi<UIPassthroughEventT extends UIPassthroughEvent>(apiName: UIPassthroughEventT, parameters: UIPassthroughRequest<UIPassthroughEventT>): Promise<UIPassthroughArrayResponse<UIPassthroughEventT>>;
7578
+ protected handlePinEvent(payload: HostEventRequest<HostEvent.Pin>): Promise<HostEventResponse<HostEvent.Pin>>;
7579
+ protected handleSaveAnswerEvent(payload: HostEventRequest<HostEvent.SaveAnswer>): Promise<any>;
7580
+ triggerHostEvent<HostEventT extends HostEvent, PayloadT>(hostEvent: HostEventT, payload?: TriggerPayload<PayloadT, HostEventT>): Promise<TriggerResponse<PayloadT, HostEventT>>;
7566
7581
  }
7567
7582
  }
7568
7583
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thoughtspot/visual-embed-sdk",
3
- "version": "1.35.5-hostEvent.5",
3
+ "version": "1.35.5-hostEvent.7",
4
4
  "description": "ThoughtSpot Embed SDK",
5
5
  "module": "lib/src/index.js",
6
6
  "main": "dist/tsembed.js",
@@ -1,16 +1,17 @@
1
1
  import { HostEvent } from '../../types';
2
2
 
3
- export enum UiPassthroughEvent {
4
- addVizToPinboard = 'addVizToPinboard',
5
- saveAnswer = 'saveAnswer',
6
- getDiscoverabilityStatus = 'getDiscoverabilityStatus',
7
- getAvailableUiPassthroughs = 'getAvailableUiPassthroughs',
8
- getAnswerPageConfig = 'getAnswerPageConfig',
9
- getPinboardPageConfig = 'getPinboardPageConfig',
3
+ export enum UIPassthroughEvent {
4
+ PinAnswerToLiveboard = 'addVizToPinboard',
5
+ SaveAnswer = 'saveAnswer',
6
+ GetDiscoverabilityStatus = 'getDiscoverabilityStatus',
7
+ GetAvailableUIPassthroughs = 'getAvailableUIPassthroughs',
8
+ GetAnswerConfig = 'getAnswerPageConfig',
9
+ GetLiveboardConfig = 'getPinboardPageConfig',
10
10
  }
11
11
 
12
- export type UiPassthroughContractBase = {
13
- [UiPassthroughEvent.addVizToPinboard]: {
12
+ // UI Passthrough Contract
13
+ export type UIPassthroughContractBase = {
14
+ [UIPassthroughEvent.PinAnswerToLiveboard]: {
14
15
  request: {
15
16
  vizId?: string;
16
17
  newVizName: string;
@@ -26,69 +27,79 @@ export type UiPassthroughContractBase = {
26
27
  vizId: string;
27
28
  };
28
29
  };
29
- [UiPassthroughEvent.saveAnswer]: {
30
+ [UIPassthroughEvent.SaveAnswer]: {
30
31
  request: {
31
32
  name: string;
32
33
  description: string;
33
- vizId: string;
34
+ vizId?: string;
34
35
  isDiscoverable?: boolean;
35
36
  };
36
37
  response: {
37
38
  answerId: string,
38
- saveResponse: any;
39
+ saveResponse?: any;
39
40
  shareResponse?: any;
40
- errors?: any;
41
41
  };
42
42
  };
43
- [UiPassthroughEvent.getDiscoverabilityStatus]: {
43
+ [UIPassthroughEvent.GetDiscoverabilityStatus]: {
44
44
  request: any;
45
45
  response: {
46
46
  shouldShowDiscoverability: boolean;
47
47
  isDiscoverabilityCheckboxUnselectedPerOrg: boolean;
48
48
  };
49
49
  };
50
- [UiPassthroughEvent.getAvailableUiPassthroughs]: {
50
+ [UIPassthroughEvent.GetAvailableUIPassthroughs]: {
51
51
  request: any;
52
52
  response: {
53
53
  keys: string[];
54
54
  };
55
55
  };
56
- [UiPassthroughEvent.getAnswerPageConfig]: {
56
+ [UIPassthroughEvent.GetAnswerConfig]: {
57
57
  request: {
58
58
  vizId?: string;
59
59
  };
60
60
  response: any;
61
61
  };
62
- [UiPassthroughEvent.getPinboardPageConfig]: {
62
+ [UIPassthroughEvent.GetLiveboardConfig]: {
63
63
  request: any;
64
64
  response: any;
65
65
  };
66
66
  };
67
67
 
68
- export type FlattenType<T> = T extends infer R ? { [K in keyof R]: R[K] } : never;
68
+ // UI Passthrough Request and Response
69
+ export type UIPassthroughRequest<T
70
+ extends keyof UIPassthroughContractBase
71
+ > = UIPassthroughContractBase[T]['request'];
69
72
 
70
- export type UiPassthroughRequest<T extends keyof UiPassthroughContractBase> = FlattenType<UiPassthroughContractBase[T]['request']>;
71
- export type UiPassthroughResponse<T extends keyof UiPassthroughContractBase> = FlattenType<UiPassthroughContractBase[T]['response']>;
73
+ export type UIPassthroughResponse<
74
+ T extends keyof UIPassthroughContractBase
75
+ > = UIPassthroughContractBase[T]['response'];
72
76
 
73
- export type UiPassthroughArrayResponse<ApiName extends keyof UiPassthroughContractBase> =
74
- Promise<Array<{
77
+ export type UIPassthroughArrayResponse<ApiName extends keyof UIPassthroughContractBase> =
78
+ Array<{
75
79
  redId?: string;
76
- value?: UiPassthroughResponse<ApiName>;
80
+ value?: UIPassthroughResponse<ApiName>;
77
81
  error?: any;
78
- }>>
82
+ }>
79
83
 
84
+ // Host event and UI Passthrough Event Mapping
80
85
  export type EmbedApiHostEventMapping = {
81
- [HostEvent.Pin]: UiPassthroughEvent.addVizToPinboard;
82
- [HostEvent.SaveAnswer]: UiPassthroughEvent.saveAnswer;
86
+ [HostEvent.Pin]: UIPassthroughEvent.PinAnswerToLiveboard;
87
+ [HostEvent.SaveAnswer]: UIPassthroughEvent.SaveAnswer;
83
88
  }
84
89
 
90
+ // Host Event Request and Response
85
91
  export type HostEventRequest<HostEventT extends HostEvent> =
86
- HostEventT extends keyof EmbedApiHostEventMapping ?
87
- FlattenType<UiPassthroughRequest<EmbedApiHostEventMapping[HostEventT]>> : any;
92
+ HostEventT extends keyof EmbedApiHostEventMapping
93
+ ? UIPassthroughRequest<EmbedApiHostEventMapping[HostEventT]>
94
+ : any;
88
95
 
89
96
  export type HostEventResponse<HostEventT extends HostEvent> =
90
- HostEventT extends keyof EmbedApiHostEventMapping ?
91
- {
92
- value?: UiPassthroughResponse<EmbedApiHostEventMapping[HostEventT]>
93
- }
94
- : any;
97
+ HostEventT extends keyof EmbedApiHostEventMapping
98
+ ? UIPassthroughResponse<EmbedApiHostEventMapping[HostEventT]>
99
+ : any;
100
+
101
+ // trigger response and request
102
+ export type TriggerPayload<PayloadT, HostEventT extends HostEvent> =
103
+ PayloadT | HostEventRequest<HostEventT>;
104
+ export type TriggerResponse<PayloadT, HostEventT extends HostEvent> =
105
+ PayloadT extends HostEventRequest<HostEventT> ? HostEventResponse<HostEventT> : any;
@@ -1,10 +1,11 @@
1
- import { getIFrameEl } from '../../test/test-utils';
1
+ import { getIFrameEl, getRootEl } from '../../test/test-utils';
2
2
  import { HostEvent } from '../../types';
3
3
  import { processTrigger } from '../../utils/processTrigger';
4
+ import * as EmbedConfigService from '../embedConfig';
4
5
  import {
5
- UiPassthroughEvent,
6
- UiPassthroughRequest,
7
- UiPassthroughArrayResponse,
6
+ UIPassthroughEvent,
7
+ UIPassthroughRequest,
8
+ UIPassthroughArrayResponse,
8
9
  HostEventRequest,
9
10
  } from './contracts';
10
11
  import { HostEventClient } from './host-event-client';
@@ -14,23 +15,27 @@ jest.mock('../../utils/processTrigger');
14
15
  const mockProcessTrigger = processTrigger as jest.Mock;
15
16
 
16
17
  const createHostEventClient = () => {
17
- const mockIframe = getIFrameEl();
18
- const mockThoughtSpotHost = 'http://localhost';
19
- const client = new HostEventClient(mockThoughtSpotHost);
20
- return { client, mockIframe, mockThoughtSpotHost };
18
+ const mockIframe = document.createElement('iframe');
19
+ const client = new HostEventClient(mockIframe);
20
+ return { client, mockIframe };
21
21
  };
22
22
 
23
23
  describe('HostEventClient', () => {
24
+ const mockThoughtSpotHost = 'http://localhost';
25
+ beforeEach(() => {
26
+ jest.spyOn(EmbedConfigService, 'getEmbedConfig').mockReturnValue({ thoughtSpotHost: mockThoughtSpotHost });
27
+ });
28
+
24
29
  afterEach(() => {
25
30
  jest.clearAllMocks();
26
31
  });
27
32
 
28
- describe('executeUiPassthroughApi', () => {
33
+ describe('executeUIPassthroughApi', () => {
29
34
  it('should call processTrigger with correct parameters and return response', async () => {
30
- const { client, mockIframe, mockThoughtSpotHost } = createHostEventClient();
35
+ const { client, mockIframe } = createHostEventClient();
31
36
 
32
- const apiName = UiPassthroughEvent.addVizToPinboard;
33
- const parameters: UiPassthroughRequest<typeof apiName> = {
37
+ const apiName = UIPassthroughEvent.PinAnswerToLiveboard;
38
+ const parameters: UIPassthroughRequest<typeof apiName> = {
34
39
  newVizName: 'testViz',
35
40
  };
36
41
  const triggerResponse = Promise.resolve([
@@ -39,11 +44,11 @@ describe('HostEventClient', () => {
39
44
 
40
45
  mockProcessTrigger.mockResolvedValue(triggerResponse);
41
46
 
42
- const result = await client.executeUiPassthroughApi(getIFrameEl(), apiName, parameters);
47
+ const result = await client.triggerUIPassthroughApi(apiName, parameters);
43
48
 
44
49
  expect(mockProcessTrigger).toHaveBeenCalledWith(
45
50
  mockIframe,
46
- HostEvent.UiPassthrough,
51
+ HostEvent.UIPassthrough,
47
52
  mockThoughtSpotHost,
48
53
  {
49
54
  type: apiName,
@@ -54,11 +59,11 @@ describe('HostEventClient', () => {
54
59
  });
55
60
  });
56
61
 
57
- describe('handleUiPassthroughForHostEvent', () => {
62
+ describe('handleUIPassthroughForHostEvent', () => {
58
63
  it('should return the value from the first valid response', async () => {
59
64
  const { client } = createHostEventClient();
60
- const apiName = UiPassthroughEvent.addVizToPinboard;
61
- const parameters: UiPassthroughRequest<typeof apiName> = {
65
+ const apiName = UIPassthroughEvent.PinAnswerToLiveboard;
66
+ const parameters: UIPassthroughRequest<typeof apiName> = {
62
67
  newVizName: 'testViz',
63
68
  };
64
69
  const triggerResponse = Promise.resolve([
@@ -66,8 +71,7 @@ describe('HostEventClient', () => {
66
71
  ]);
67
72
  mockProcessTrigger.mockResolvedValue(triggerResponse);
68
73
 
69
- const result = await client.handleUiPassthroughForHostEvent(getIFrameEl(),
70
- apiName, parameters);
74
+ const result = await client.handleHostEventWithParam(apiName, parameters);
71
75
 
72
76
  expect(result).toEqual({
73
77
  pinboardId: 'testPinboard',
@@ -78,50 +82,50 @@ describe('HostEventClient', () => {
78
82
 
79
83
  it('should throw an error if no valid response is found', async () => {
80
84
  const { client } = createHostEventClient();
81
- const apiName = UiPassthroughEvent.addVizToPinboard;
82
- const parameters: UiPassthroughRequest<typeof apiName> = {
85
+ const apiName = UIPassthroughEvent.PinAnswerToLiveboard;
86
+ const parameters: UIPassthroughRequest<typeof apiName> = {
83
87
  newVizName: 'testViz',
84
88
  };
85
- const triggerResponse: UiPassthroughArrayResponse<typeof apiName> = Promise.resolve([]);
89
+ const triggerResponse: UIPassthroughArrayResponse<typeof apiName> = [];
86
90
  mockProcessTrigger.mockResolvedValue(triggerResponse);
87
91
 
88
- await expect(client.handleUiPassthroughForHostEvent(getIFrameEl(), apiName, parameters))
92
+ await expect(client.handleHostEventWithParam(apiName, parameters))
89
93
  .rejects.toEqual({ error: 'No answer found.' });
90
94
  });
91
95
 
92
96
  it('should throw an error if no valid response is found for vizId', async () => {
93
97
  const { client } = createHostEventClient();
94
- const apiName = UiPassthroughEvent.addVizToPinboard;
95
- const parameters: UiPassthroughRequest<typeof apiName> = {
98
+ const apiName = UIPassthroughEvent.PinAnswerToLiveboard;
99
+ const parameters: UIPassthroughRequest<typeof apiName> = {
96
100
  newVizName: 'testViz',
97
101
  vizId: 'testVizId',
98
102
  };
99
- const triggerResponse: UiPassthroughArrayResponse<typeof apiName> = Promise.resolve([]);
103
+ const triggerResponse: UIPassthroughArrayResponse<typeof apiName> = [];
100
104
  mockProcessTrigger.mockResolvedValue(triggerResponse);
101
105
 
102
- await expect(client.handleUiPassthroughForHostEvent(getIFrameEl(), apiName, parameters))
106
+ await expect(client.handleHostEventWithParam(apiName, parameters))
103
107
  .rejects.toEqual({ error: 'No answer found for vizId: testVizId.' });
104
108
  });
105
109
 
106
110
  it('should throw an error if the response contains errors', async () => {
107
111
  const { client } = createHostEventClient();
108
- const apiName = UiPassthroughEvent.addVizToPinboard;
109
- const parameters: UiPassthroughRequest<typeof apiName> = {
112
+ const apiName = UIPassthroughEvent.PinAnswerToLiveboard;
113
+ const parameters: UIPassthroughRequest<typeof apiName> = {
110
114
  newVizName: 'testViz',
111
115
  };
112
- const triggerResponse: UiPassthroughArrayResponse<typeof apiName> = Promise.resolve([
116
+ const triggerResponse: UIPassthroughArrayResponse<typeof apiName> = [
113
117
  { error: 'Some error' },
114
- ]);
118
+ ];
115
119
  mockProcessTrigger.mockResolvedValue(triggerResponse);
116
120
 
117
- await expect(client.handleUiPassthroughForHostEvent(getIFrameEl(), apiName, parameters))
121
+ await expect(client.handleHostEventWithParam(apiName, parameters))
118
122
  .rejects.toEqual({ error: 'Some error' });
119
123
  });
120
124
  });
121
125
 
122
126
  describe('executeHostEvent', () => {
123
- it('should call handleUiPassthroughForHostEvent for Pin event', async () => {
124
- const { client } = createHostEventClient();
127
+ it('should call handleUIPassthroughForHostEvent for Pin event', async () => {
128
+ const { client, mockIframe } = createHostEventClient();
125
129
  const hostEvent = HostEvent.Pin;
126
130
  const payload: HostEventRequest<typeof hostEvent> = {
127
131
  newVizName: 'testViz',
@@ -136,19 +140,19 @@ describe('HostEventClient', () => {
136
140
 
137
141
  mockProcessTrigger.mockResolvedValue([mockResponse]);
138
142
 
139
- const result = await client.executeHostEvent(getIFrameEl(), hostEvent, payload);
143
+ const result = await client.triggerHostEvent(hostEvent, payload);
140
144
 
141
145
  expect(mockProcessTrigger).toHaveBeenCalledWith(
142
- getIFrameEl(),
143
- HostEvent.UiPassthrough,
146
+ mockIframe,
147
+ HostEvent.UIPassthrough,
144
148
  'http://localhost',
145
- { parameters: payload, type: UiPassthroughEvent.addVizToPinboard },
149
+ { parameters: payload, type: UIPassthroughEvent.PinAnswerToLiveboard },
146
150
  );
147
151
  expect(result).toEqual(mockResponse.value);
148
152
  });
149
153
 
150
- it('should call handleUiPassthroughForHostEvent for SaveAnswer event', async () => {
151
- const { client } = createHostEventClient();
154
+ it('should call handleUIPassthroughForHostEvent for SaveAnswer event', async () => {
155
+ const { client, mockIframe } = createHostEventClient();
152
156
  const hostEvent = HostEvent.SaveAnswer;
153
157
  const payload: HostEventRequest<typeof hostEvent> = {
154
158
  name: 'Test Answer',
@@ -170,12 +174,12 @@ describe('HostEventClient', () => {
170
174
  refId: 'testVizId',
171
175
  }];
172
176
  mockProcessTrigger.mockResolvedValue(mockResponse);
173
- const result = await client.executeHostEvent(getIFrameEl(), hostEvent, payload);
177
+ const result = await client.triggerHostEvent(hostEvent, payload);
174
178
 
175
179
  expect(mockProcessTrigger).toHaveBeenCalledWith(
176
- null,
177
- 'UiPassthrough',
178
- 'http://localhost',
180
+ mockIframe,
181
+ HostEvent.UIPassthrough,
182
+ mockThoughtSpotHost,
179
183
  {
180
184
  parameters: payload,
181
185
  type: 'saveAnswer',
@@ -191,14 +195,14 @@ describe('HostEventClient', () => {
191
195
  const mockResponse = { fallbackResponse: 'data' };
192
196
  jest.spyOn(client, 'hostEventFallback').mockResolvedValue(mockResponse);
193
197
 
194
- const result = await client.executeHostEvent(getIFrameEl(), hostEvent, payload);
198
+ const result = await client.triggerHostEvent(hostEvent, payload);
195
199
 
196
- expect(client.hostEventFallback).toHaveBeenCalledWith(null, hostEvent, payload);
200
+ expect(client.hostEventFallback).toHaveBeenCalledWith(hostEvent, payload);
197
201
  expect(result).toEqual(mockResponse);
198
202
  });
199
203
 
200
204
  it('should call fallback for Pin event', async () => {
201
- const { client } = createHostEventClient();
205
+ const { client, mockIframe } = createHostEventClient();
202
206
  const hostEvent = HostEvent.Pin;
203
207
  const payload: HostEventRequest<typeof hostEvent> = {} as any;
204
208
  const mockResponse = {
@@ -211,19 +215,19 @@ describe('HostEventClient', () => {
211
215
 
212
216
  mockProcessTrigger.mockResolvedValue([mockResponse]);
213
217
 
214
- const result = await client.executeHostEvent(getIFrameEl(), hostEvent, payload);
218
+ const result = await client.triggerHostEvent(hostEvent, payload);
215
219
 
216
220
  expect(mockProcessTrigger).toHaveBeenCalledWith(
217
- getIFrameEl(),
221
+ mockIframe,
218
222
  HostEvent.Pin,
219
- 'http://localhost',
223
+ mockThoughtSpotHost,
220
224
  {},
221
225
  );
222
226
  expect(result).toEqual([mockResponse]);
223
227
  });
224
228
 
225
229
  it('should call fallback for SaveAnswer event', async () => {
226
- const { client } = createHostEventClient();
230
+ const { client, mockIframe } = createHostEventClient();
227
231
  const hostEvent = HostEvent.SaveAnswer;
228
232
  const payload: HostEventRequest<typeof hostEvent> = {} as any;
229
233
  const mockResponse = {
@@ -236,12 +240,12 @@ describe('HostEventClient', () => {
236
240
 
237
241
  mockProcessTrigger.mockResolvedValue([mockResponse]);
238
242
 
239
- const result = await client.executeHostEvent(getIFrameEl(), hostEvent, payload);
243
+ const result = await client.triggerHostEvent(hostEvent, payload);
240
244
 
241
245
  expect(mockProcessTrigger).toHaveBeenCalledWith(
242
- getIFrameEl(),
246
+ mockIframe,
243
247
  HostEvent.Save,
244
- 'http://localhost',
248
+ mockThoughtSpotHost,
245
249
  {},
246
250
  );
247
251
  expect(result).toEqual([mockResponse]);