@thoughtspot/visual-embed-sdk 1.35.5-hostEvent.6 → 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.
- package/cjs/package.json +1 -1
- package/cjs/src/embed/hostEventClient/contracts.d.ts +26 -30
- package/cjs/src/embed/hostEventClient/contracts.d.ts.map +1 -1
- package/cjs/src/embed/hostEventClient/contracts.js +10 -10
- package/cjs/src/embed/hostEventClient/contracts.js.map +1 -1
- package/cjs/src/embed/hostEventClient/host-event-client.d.ts +21 -7
- package/cjs/src/embed/hostEventClient/host-event-client.d.ts.map +1 -1
- package/cjs/src/embed/hostEventClient/host-event-client.js +61 -27
- package/cjs/src/embed/hostEventClient/host-event-client.js.map +1 -1
- package/cjs/src/embed/hostEventClient/host-event-client.spec.js +43 -39
- package/cjs/src/embed/hostEventClient/host-event-client.spec.js.map +1 -1
- package/cjs/src/embed/liveboard.spec.js +4 -2
- package/cjs/src/embed/liveboard.spec.js.map +1 -1
- package/cjs/src/embed/ts-embed.d.ts +13 -8
- package/cjs/src/embed/ts-embed.d.ts.map +1 -1
- package/cjs/src/embed/ts-embed.js +22 -14
- package/cjs/src/embed/ts-embed.js.map +1 -1
- package/cjs/src/embed/ts-embed.spec.js +4 -4
- package/cjs/src/embed/ts-embed.spec.js.map +1 -1
- package/cjs/src/index.d.ts +2 -2
- package/cjs/src/index.js +2 -2
- package/cjs/src/react/all-types-export.d.ts +1 -1
- package/cjs/src/react/all-types-export.js +2 -2
- package/cjs/src/types.d.ts +1 -1
- package/cjs/src/types.js +1 -1
- package/dist/index-DaLHJaLd.js +7370 -0
- package/dist/src/embed/hostEventClient/contracts.d.ts +26 -30
- package/dist/src/embed/hostEventClient/contracts.d.ts.map +1 -1
- package/dist/src/embed/hostEventClient/host-event-client.d.ts +21 -7
- package/dist/src/embed/hostEventClient/host-event-client.d.ts.map +1 -1
- package/dist/src/embed/ts-embed.d.ts +13 -8
- package/dist/src/embed/ts-embed.d.ts.map +1 -1
- package/dist/src/index.d.ts +2 -2
- package/dist/src/react/all-types-export.d.ts +1 -1
- package/dist/src/types.d.ts +1 -1
- package/dist/tsembed-react.es.js +95 -54
- package/dist/tsembed-react.js +94 -53
- package/dist/tsembed.es.js +96 -55
- package/dist/tsembed.js +94 -53
- package/dist/visual-embed-sdk-react-full.d.ts +60 -45
- package/dist/visual-embed-sdk-react.d.ts +60 -45
- package/dist/visual-embed-sdk.d.ts +60 -45
- package/lib/package.json +1 -1
- package/lib/src/embed/hostEventClient/contracts.d.ts +26 -30
- package/lib/src/embed/hostEventClient/contracts.d.ts.map +1 -1
- package/lib/src/embed/hostEventClient/contracts.js +9 -9
- package/lib/src/embed/hostEventClient/contracts.js.map +1 -1
- package/lib/src/embed/hostEventClient/host-event-client.d.ts +21 -7
- package/lib/src/embed/hostEventClient/host-event-client.d.ts.map +1 -1
- package/lib/src/embed/hostEventClient/host-event-client.js +63 -29
- package/lib/src/embed/hostEventClient/host-event-client.js.map +1 -1
- package/lib/src/embed/hostEventClient/host-event-client.spec.js +43 -40
- package/lib/src/embed/hostEventClient/host-event-client.spec.js.map +1 -1
- package/lib/src/embed/liveboard.spec.js +4 -2
- package/lib/src/embed/liveboard.spec.js.map +1 -1
- package/lib/src/embed/ts-embed.d.ts +13 -8
- package/lib/src/embed/ts-embed.d.ts.map +1 -1
- package/lib/src/embed/ts-embed.js +22 -14
- package/lib/src/embed/ts-embed.js.map +1 -1
- package/lib/src/embed/ts-embed.spec.js +5 -5
- package/lib/src/embed/ts-embed.spec.js.map +1 -1
- package/lib/src/index.d.ts +2 -2
- package/lib/src/index.js +2 -2
- package/lib/src/react/all-types-export.d.ts +1 -1
- package/lib/src/react/all-types-export.js +1 -1
- package/lib/src/types.d.ts +1 -1
- package/lib/src/types.js +1 -1
- package/lib/src/visual-embed-sdk.d.ts +63 -48
- package/package.json +1 -1
- package/src/embed/hostEventClient/contracts.ts +43 -32
- package/src/embed/hostEventClient/host-event-client.spec.ts +58 -54
- package/src/embed/hostEventClient/host-event-client.ts +109 -47
- package/src/embed/liveboard.spec.ts +4 -2
- package/src/embed/ts-embed.spec.ts +6 -6
- package/src/embed/ts-embed.ts +38 -27
- package/src/index.ts +2 -2
- package/src/react/all-types-export.ts +1 -1
- 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 {
|
|
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,
|
|
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
|
-
|
|
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
|
|
7149
|
-
|
|
7150
|
-
|
|
7151
|
-
|
|
7152
|
-
|
|
7153
|
-
|
|
7154
|
-
|
|
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
|
|
7157
|
-
[
|
|
7156
|
+
export type UIPassthroughContractBase = {
|
|
7157
|
+
[UIPassthroughEvent.PinAnswerToLiveboard]: {
|
|
7158
7158
|
request: {
|
|
7159
7159
|
vizId?: string;
|
|
7160
7160
|
newVizName: string;
|
|
@@ -7170,7 +7170,7 @@ declare module '@thoughtspot/visual-embed-sdk/embed/hostEventClient/contracts' {
|
|
|
7170
7170
|
vizId: string;
|
|
7171
7171
|
};
|
|
7172
7172
|
};
|
|
7173
|
-
[
|
|
7173
|
+
[UIPassthroughEvent.SaveAnswer]: {
|
|
7174
7174
|
request: {
|
|
7175
7175
|
name: string;
|
|
7176
7176
|
description: string;
|
|
@@ -7179,53 +7179,49 @@ declare module '@thoughtspot/visual-embed-sdk/embed/hostEventClient/contracts' {
|
|
|
7179
7179
|
};
|
|
7180
7180
|
response: {
|
|
7181
7181
|
answerId: string;
|
|
7182
|
-
saveResponse
|
|
7182
|
+
saveResponse?: any;
|
|
7183
7183
|
shareResponse?: any;
|
|
7184
|
-
errors?: any;
|
|
7185
7184
|
};
|
|
7186
7185
|
};
|
|
7187
|
-
[
|
|
7186
|
+
[UIPassthroughEvent.GetDiscoverabilityStatus]: {
|
|
7188
7187
|
request: any;
|
|
7189
7188
|
response: {
|
|
7190
7189
|
shouldShowDiscoverability: boolean;
|
|
7191
7190
|
isDiscoverabilityCheckboxUnselectedPerOrg: boolean;
|
|
7192
7191
|
};
|
|
7193
7192
|
};
|
|
7194
|
-
[
|
|
7193
|
+
[UIPassthroughEvent.GetAvailableUIPassthroughs]: {
|
|
7195
7194
|
request: any;
|
|
7196
7195
|
response: {
|
|
7197
7196
|
keys: string[];
|
|
7198
7197
|
};
|
|
7199
7198
|
};
|
|
7200
|
-
[
|
|
7199
|
+
[UIPassthroughEvent.GetAnswerConfig]: {
|
|
7201
7200
|
request: {
|
|
7202
7201
|
vizId?: string;
|
|
7203
7202
|
};
|
|
7204
7203
|
response: any;
|
|
7205
7204
|
};
|
|
7206
|
-
[
|
|
7205
|
+
[UIPassthroughEvent.GetLiveboardConfig]: {
|
|
7207
7206
|
request: any;
|
|
7208
7207
|
response: any;
|
|
7209
7208
|
};
|
|
7210
7209
|
};
|
|
7211
|
-
export type
|
|
7212
|
-
|
|
7213
|
-
|
|
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?:
|
|
7214
|
+
value?: UIPassthroughResponse<ApiName>;
|
|
7219
7215
|
error?: any;
|
|
7220
|
-
}
|
|
7216
|
+
}>;
|
|
7221
7217
|
export type EmbedApiHostEventMapping = {
|
|
7222
|
-
[HostEvent.Pin]:
|
|
7223
|
-
[HostEvent.SaveAnswer]:
|
|
7218
|
+
[HostEvent.Pin]: UIPassthroughEvent.PinAnswerToLiveboard;
|
|
7219
|
+
[HostEvent.SaveAnswer]: UIPassthroughEvent.SaveAnswer;
|
|
7224
7220
|
};
|
|
7225
|
-
export type HostEventRequest<HostEventT extends HostEvent> = HostEventT extends keyof EmbedApiHostEventMapping ?
|
|
7226
|
-
export type HostEventResponse<HostEventT extends HostEvent> = HostEventT extends keyof EmbedApiHostEventMapping ?
|
|
7227
|
-
|
|
7228
|
-
|
|
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 {
|
|
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?:
|
|
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 {
|
|
7432
|
-
* @param {
|
|
7433
|
-
* @returns {Promise<
|
|
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
|
-
|
|
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 {
|
|
7559
|
+
import { UIPassthroughArrayResponse, UIPassthroughEvent, HostEventRequest, HostEventResponse, UIPassthroughRequest, UIPassthroughResponse, TriggerPayload, TriggerResponse } from '@thoughtspot/visual-embed-sdk/embed/hostEventClient/contracts';
|
|
7559
7560
|
export class HostEventClient {
|
|
7560
|
-
|
|
7561
|
-
|
|
7562
|
-
|
|
7563
|
-
|
|
7564
|
-
|
|
7565
|
-
|
|
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,16 +1,17 @@
|
|
|
1
1
|
import { HostEvent } from '../../types';
|
|
2
2
|
|
|
3
|
-
export enum
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
13
|
-
|
|
12
|
+
// UI Passthrough Contract
|
|
13
|
+
export type UIPassthroughContractBase = {
|
|
14
|
+
[UIPassthroughEvent.PinAnswerToLiveboard]: {
|
|
14
15
|
request: {
|
|
15
16
|
vizId?: string;
|
|
16
17
|
newVizName: string;
|
|
@@ -26,7 +27,7 @@ export type UiPassthroughContractBase = {
|
|
|
26
27
|
vizId: string;
|
|
27
28
|
};
|
|
28
29
|
};
|
|
29
|
-
[
|
|
30
|
+
[UIPassthroughEvent.SaveAnswer]: {
|
|
30
31
|
request: {
|
|
31
32
|
name: string;
|
|
32
33
|
description: string;
|
|
@@ -35,60 +36,70 @@ export type UiPassthroughContractBase = {
|
|
|
35
36
|
};
|
|
36
37
|
response: {
|
|
37
38
|
answerId: string,
|
|
38
|
-
saveResponse
|
|
39
|
+
saveResponse?: any;
|
|
39
40
|
shareResponse?: any;
|
|
40
|
-
errors?: any;
|
|
41
41
|
};
|
|
42
42
|
};
|
|
43
|
-
[
|
|
43
|
+
[UIPassthroughEvent.GetDiscoverabilityStatus]: {
|
|
44
44
|
request: any;
|
|
45
45
|
response: {
|
|
46
46
|
shouldShowDiscoverability: boolean;
|
|
47
47
|
isDiscoverabilityCheckboxUnselectedPerOrg: boolean;
|
|
48
48
|
};
|
|
49
49
|
};
|
|
50
|
-
[
|
|
50
|
+
[UIPassthroughEvent.GetAvailableUIPassthroughs]: {
|
|
51
51
|
request: any;
|
|
52
52
|
response: {
|
|
53
53
|
keys: string[];
|
|
54
54
|
};
|
|
55
55
|
};
|
|
56
|
-
[
|
|
56
|
+
[UIPassthroughEvent.GetAnswerConfig]: {
|
|
57
57
|
request: {
|
|
58
58
|
vizId?: string;
|
|
59
59
|
};
|
|
60
60
|
response: any;
|
|
61
61
|
};
|
|
62
|
-
[
|
|
62
|
+
[UIPassthroughEvent.GetLiveboardConfig]: {
|
|
63
63
|
request: any;
|
|
64
64
|
response: any;
|
|
65
65
|
};
|
|
66
66
|
};
|
|
67
67
|
|
|
68
|
-
|
|
68
|
+
// UI Passthrough Request and Response
|
|
69
|
+
export type UIPassthroughRequest<T
|
|
70
|
+
extends keyof UIPassthroughContractBase
|
|
71
|
+
> = UIPassthroughContractBase[T]['request'];
|
|
69
72
|
|
|
70
|
-
export type
|
|
71
|
-
|
|
73
|
+
export type UIPassthroughResponse<
|
|
74
|
+
T extends keyof UIPassthroughContractBase
|
|
75
|
+
> = UIPassthroughContractBase[T]['response'];
|
|
72
76
|
|
|
73
|
-
export type
|
|
74
|
-
|
|
77
|
+
export type UIPassthroughArrayResponse<ApiName extends keyof UIPassthroughContractBase> =
|
|
78
|
+
Array<{
|
|
75
79
|
redId?: string;
|
|
76
|
-
value?:
|
|
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]:
|
|
82
|
-
[HostEvent.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
|
-
|
|
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
|
-
|
|
93
|
-
|
|
94
|
-
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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 =
|
|
18
|
-
const
|
|
19
|
-
|
|
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('
|
|
33
|
+
describe('executeUIPassthroughApi', () => {
|
|
29
34
|
it('should call processTrigger with correct parameters and return response', async () => {
|
|
30
|
-
const { client, mockIframe
|
|
35
|
+
const { client, mockIframe } = createHostEventClient();
|
|
31
36
|
|
|
32
|
-
const apiName =
|
|
33
|
-
const parameters:
|
|
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.
|
|
47
|
+
const result = await client.triggerUIPassthroughApi(apiName, parameters);
|
|
43
48
|
|
|
44
49
|
expect(mockProcessTrigger).toHaveBeenCalledWith(
|
|
45
50
|
mockIframe,
|
|
46
|
-
HostEvent.
|
|
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('
|
|
62
|
+
describe('handleUIPassthroughForHostEvent', () => {
|
|
58
63
|
it('should return the value from the first valid response', async () => {
|
|
59
64
|
const { client } = createHostEventClient();
|
|
60
|
-
const apiName =
|
|
61
|
-
const parameters:
|
|
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.
|
|
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 =
|
|
82
|
-
const parameters:
|
|
85
|
+
const apiName = UIPassthroughEvent.PinAnswerToLiveboard;
|
|
86
|
+
const parameters: UIPassthroughRequest<typeof apiName> = {
|
|
83
87
|
newVizName: 'testViz',
|
|
84
88
|
};
|
|
85
|
-
const triggerResponse:
|
|
89
|
+
const triggerResponse: UIPassthroughArrayResponse<typeof apiName> = [];
|
|
86
90
|
mockProcessTrigger.mockResolvedValue(triggerResponse);
|
|
87
91
|
|
|
88
|
-
await expect(client.
|
|
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 =
|
|
95
|
-
const parameters:
|
|
98
|
+
const apiName = UIPassthroughEvent.PinAnswerToLiveboard;
|
|
99
|
+
const parameters: UIPassthroughRequest<typeof apiName> = {
|
|
96
100
|
newVizName: 'testViz',
|
|
97
101
|
vizId: 'testVizId',
|
|
98
102
|
};
|
|
99
|
-
const triggerResponse:
|
|
103
|
+
const triggerResponse: UIPassthroughArrayResponse<typeof apiName> = [];
|
|
100
104
|
mockProcessTrigger.mockResolvedValue(triggerResponse);
|
|
101
105
|
|
|
102
|
-
await expect(client.
|
|
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 =
|
|
109
|
-
const parameters:
|
|
112
|
+
const apiName = UIPassthroughEvent.PinAnswerToLiveboard;
|
|
113
|
+
const parameters: UIPassthroughRequest<typeof apiName> = {
|
|
110
114
|
newVizName: 'testViz',
|
|
111
115
|
};
|
|
112
|
-
const triggerResponse:
|
|
116
|
+
const triggerResponse: UIPassthroughArrayResponse<typeof apiName> = [
|
|
113
117
|
{ error: 'Some error' },
|
|
114
|
-
]
|
|
118
|
+
];
|
|
115
119
|
mockProcessTrigger.mockResolvedValue(triggerResponse);
|
|
116
120
|
|
|
117
|
-
await expect(client.
|
|
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
|
|
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.
|
|
143
|
+
const result = await client.triggerHostEvent(hostEvent, payload);
|
|
140
144
|
|
|
141
145
|
expect(mockProcessTrigger).toHaveBeenCalledWith(
|
|
142
|
-
|
|
143
|
-
HostEvent.
|
|
146
|
+
mockIframe,
|
|
147
|
+
HostEvent.UIPassthrough,
|
|
144
148
|
'http://localhost',
|
|
145
|
-
{ parameters: payload, type:
|
|
149
|
+
{ parameters: payload, type: UIPassthroughEvent.PinAnswerToLiveboard },
|
|
146
150
|
);
|
|
147
151
|
expect(result).toEqual(mockResponse.value);
|
|
148
152
|
});
|
|
149
153
|
|
|
150
|
-
it('should call
|
|
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.
|
|
177
|
+
const result = await client.triggerHostEvent(hostEvent, payload);
|
|
174
178
|
|
|
175
179
|
expect(mockProcessTrigger).toHaveBeenCalledWith(
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
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.
|
|
198
|
+
const result = await client.triggerHostEvent(hostEvent, payload);
|
|
195
199
|
|
|
196
|
-
expect(client.hostEventFallback).toHaveBeenCalledWith(
|
|
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.
|
|
218
|
+
const result = await client.triggerHostEvent(hostEvent, payload);
|
|
215
219
|
|
|
216
220
|
expect(mockProcessTrigger).toHaveBeenCalledWith(
|
|
217
|
-
|
|
221
|
+
mockIframe,
|
|
218
222
|
HostEvent.Pin,
|
|
219
|
-
|
|
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.
|
|
243
|
+
const result = await client.triggerHostEvent(hostEvent, payload);
|
|
240
244
|
|
|
241
245
|
expect(mockProcessTrigger).toHaveBeenCalledWith(
|
|
242
|
-
|
|
246
|
+
mockIframe,
|
|
243
247
|
HostEvent.Save,
|
|
244
|
-
|
|
248
|
+
mockThoughtSpotHost,
|
|
245
249
|
{},
|
|
246
250
|
);
|
|
247
251
|
expect(result).toEqual([mockResponse]);
|