Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@thoughtspot/visual-embed-sdk",
"version": "1.42.1",
"version": "1.42.1-HE2.0.2",
"description": "ThoughtSpot Embed SDK",
"module": "lib/src/index.js",
"main": "dist/tsembed.js",
Expand Down Expand Up @@ -57,7 +57,7 @@
"test": "npm run test-sdk",
"posttest": "cat ./coverage/sdk/lcov.info | npx coveralls-next",
"is-publish-allowed": "node scripts/is-publish-allowed.js",
"prepublishOnly": "npm run is-publish-allowed && npm run test && npm run tsc && npm run bundle-dts-file && npm run bundle-dts && npm run bundle-dts-react && npm run bundle-dts-react-full && npm run build",
"prepublishOnly": "npm run tsc && npm run bundle-dts-file && npm run bundle-dts && npm run bundle-dts-react && npm run bundle-dts-react-full && npm run build",
"check-size": "npm run build && size-limit",
"publish-dev": "npm publish --tag dev",
"publish-prod": "npm publish --tag latest",
Expand Down
7 changes: 7 additions & 0 deletions src/embed/conversation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { ERROR_MESSAGE } from '../errors';
import { Param, BaseViewConfig, RuntimeFilter, RuntimeParameter } from '../types';
import { TsEmbed } from './ts-embed';
import { getQueryParamString, getFilterQuery, getRuntimeParameters } from '../utils';
import { ContextType } from './hostEventClient/contracts';
import { PageContextOptions } from 'visual-embed-sdk';

/**
* Configuration for search options
Expand Down Expand Up @@ -280,6 +282,11 @@ export class SpotterEmbed extends TsEmbed {
await this.renderIFrame(src);
return this;
}

public async getCurrentContext(): Promise<PageContextOptions> {
const context = await super.getCurrentContext();
return context;
}
}

/**
Expand Down
19 changes: 16 additions & 3 deletions src/embed/hostEventClient/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,26 @@ export type HostEventRequest<HostEventT extends HostEvent> =
? UIPassthroughRequest<EmbedApiHostEventMapping[HostEventT]>
: any;

export type HostEventResponse<HostEventT extends HostEvent> =
export type HostEventResponse<HostEventT extends HostEvent, ContextT extends ContextType> =
HostEventT extends keyof EmbedApiHostEventMapping
? UIPassthroughResponse<EmbedApiHostEventMapping[HostEventT]>
: any;

// trigger response and request
export type TriggerPayload<PayloadT, HostEventT extends HostEvent> =
PayloadT | HostEventRequest<HostEventT>;
export type TriggerResponse<PayloadT, HostEventT extends HostEvent> =
PayloadT extends HostEventRequest<HostEventT> ? HostEventResponse<HostEventT> : any;
export type TriggerResponse<PayloadT, HostEventT extends HostEvent, ContextT extends ContextType> =
PayloadT extends HostEventRequest<HostEventT> ? HostEventResponse<HostEventT, ContextT> : any;

export enum ContextType {
Search = 'search',
Liveboard = 'liveboard',
Answer = 'answer',
Spotter = 'spotter',
Default = 'default',
}

export enum PageType {
PAGE = 'page',
DIALOG = 'dialog',
}
15 changes: 10 additions & 5 deletions src/embed/hostEventClient/host-event-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
UIPassthroughResponse,
TriggerPayload,
TriggerResponse,
ContextType,
} from './contracts';

export class HostEventClient {
Expand All @@ -23,7 +24,7 @@ export class HostEventClient {
* @param {any} data Data to send with the host event
* @returns {Promise<any>} - the response from the process trigger
*/
protected async processTrigger(message: HostEvent, data: any): Promise<any> {
protected async processTrigger(message: HostEvent, data: any, context?: ContextType): Promise<any> {
if (!this.iFrame) {
throw new Error('Iframe element is not set');
}
Expand All @@ -34,6 +35,7 @@ export class HostEventClient {
message,
thoughtspotHost,
data,
context,
);
}

Expand Down Expand Up @@ -65,8 +67,9 @@ export class HostEventClient {
public async hostEventFallback(
hostEvent: HostEvent,
data: any,
context?: ContextType,
): Promise<any> {
return this.processTrigger(hostEvent, data);
return this.processTrigger(hostEvent, data, context);
}

/**
Expand All @@ -91,7 +94,7 @@ export class HostEventClient {

protected async handlePinEvent(
payload: HostEventRequest<HostEvent.Pin>,
): Promise<HostEventResponse<HostEvent.Pin>> {
): Promise<HostEventResponse<HostEvent.Pin, ContextType>> {
if (!payload || !('newVizName' in payload)) {
return this.hostEventFallback(HostEvent.Pin, payload);
}
Expand Down Expand Up @@ -132,10 +135,12 @@ export class HostEventClient {
public async triggerHostEvent<
HostEventT extends HostEvent,
PayloadT,
ContextT extends ContextType,
>(
hostEvent: HostEventT,
payload?: TriggerPayload<PayloadT, HostEventT>,
): Promise<TriggerResponse<PayloadT, HostEventT>> {
context?: ContextT,
): Promise<TriggerResponse<PayloadT, HostEventT, ContextType>> {
switch (hostEvent) {
case HostEvent.Pin:
return this.handlePinEvent(payload as HostEventRequest<HostEvent.Pin>) as any;
Expand All @@ -144,7 +149,7 @@ export class HostEventClient {
payload as HostEventRequest<HostEvent.SaveAnswer>,
) as any;
default:
return this.hostEventFallback(hostEvent, payload);
return this.hostEventFallback(hostEvent, payload, context);
}
}
}
15 changes: 11 additions & 4 deletions src/embed/liveboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ import { calculateVisibleElementData, getQueryParamString, isUndefined } from '.
import { getAuthPromise } from './base';
import { TsEmbed, V1Embed } from './ts-embed';
import { addPreviewStylesIfNotPresent } from '../utils/global-styles';
import { TriggerPayload, TriggerResponse } from './hostEventClient/contracts';
import { ContextType, TriggerPayload, TriggerResponse } from './hostEventClient/contracts';
import { logger } from '../utils/logger';
import { PageContextOptions } from 'visual-embed-sdk';


/**
Expand Down Expand Up @@ -738,10 +739,11 @@ export class LiveboardEmbed extends V1Embed {
* @param {any} data The payload to send with the message
* @returns A promise that resolves with the response from the embedded app
*/
public trigger<HostEventT extends HostEvent, PayloadT>(
public trigger<HostEventT extends HostEvent, PayloadT, ContextT extends ContextType>(
messageType: HostEventT,
data: TriggerPayload<PayloadT, HostEventT> = ({} as any),
): Promise<TriggerResponse<PayloadT, HostEventT>> {
context?: ContextT,
): Promise<TriggerResponse<PayloadT, HostEventT, ContextT>> {
const dataWithVizId: any = data;
if (messageType === HostEvent.SetActiveTab) {
this.setActiveTab(data as { tabId: string });
Expand All @@ -750,7 +752,7 @@ export class LiveboardEmbed extends V1Embed {
if (typeof dataWithVizId === 'object' && this.viewConfig.vizId) {
dataWithVizId.vizId = this.viewConfig.vizId;
}
return super.trigger(messageType, dataWithVizId);
return super.trigger(messageType, dataWithVizId, context);
}
/**
* Destroys the ThoughtSpot embed, and remove any nodes from the DOM.
Expand Down Expand Up @@ -827,6 +829,11 @@ export class LiveboardEmbed extends V1Embed {

return url;
}

public async getCurrentContext(): Promise<PageContextOptions> {
const context = await super.getCurrentContext();
return context;
}
}

/**
Expand Down
6 changes: 6 additions & 0 deletions src/embed/sage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* @author Mourya Balabhadra <[email protected]>
*/

import { PageContextOptions } from 'visual-embed-sdk';
import { DOMSelector, Param, BaseViewConfig, SearchLiveboardCommonViewConfig } from '../types';
import { getQueryParamString } from '../utils';
import { V1Embed } from './ts-embed';
Expand Down Expand Up @@ -229,4 +230,9 @@ export class SageEmbed extends V1Embed {

return this;
}

public async getCurrentContext(): Promise<PageContextOptions> {
const context = await super.getCurrentContext();
return context;
}
}
6 changes: 6 additions & 0 deletions src/embed/search-bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { SearchLiveboardCommonViewConfig, BaseViewConfig, DefaultAppInitData, Pa
import { getQueryParamString } from '../utils';
import { TsEmbed } from './ts-embed';
import { SearchOptions } from './search';
import { PageContextOptions } from 'visual-embed-sdk';

/**
* @group Embed components
Expand Down Expand Up @@ -198,4 +199,9 @@ export class SearchBarEmbed extends TsEmbed {
const defaultAppInitData = await super.getAppInitData();
return { ...defaultAppInitData, ...this.getSearchInitData() };
}

public async getCurrentContext(): Promise<PageContextOptions> {
const context = await super.getCurrentContext();
return context;
}
}
7 changes: 7 additions & 0 deletions src/embed/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import { ERROR_MESSAGE } from '../errors';
import { getAuthPromise } from './base';
import { getReleaseVersion } from '../auth';
import { getEmbedConfig } from './embedConfig';
import { PageContextOptions } from 'visual-embed-sdk';
import { ContextType, PageType } from './hostEventClient/contracts';

/**
* Configuration for search options.
Expand Down Expand Up @@ -536,4 +538,9 @@ export class SearchEmbed extends TsEmbed {
});
return this;
}

public async getCurrentContext(): Promise<PageContextOptions> {
const context = await super.getCurrentContext();
return context;
}
}
17 changes: 14 additions & 3 deletions src/embed/ts-embed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ import isEqual from 'lodash/isEqual';
import isEmpty from 'lodash/isEmpty';
import isObject from 'lodash/isObject';
import {
ContextType,
TriggerPayload,
TriggerResponse,
UIPassthroughArrayResponse,
UIPassthroughEvent,
UIPassthroughRequest,
PageType,
} from './hostEventClient/contracts';
import { logger } from '../utils/logger';
import { getAuthenticationToken } from '../authToken';
Expand Down Expand Up @@ -71,6 +73,7 @@ import { getEmbedConfig } from './embedConfig';
import { ERROR_MESSAGE } from '../errors';
import { getPreauthInfo } from '../utils/sessionInfoService';
import { HostEventClient } from './hostEventClient/host-event-client';
import { PageContextOptions } from '../../visual-embed-sdk';

const { version } = pkgInfo;

Expand Down Expand Up @@ -1268,10 +1271,11 @@ export class TsEmbed {
* @param {any} data The payload to send with the message
* @returns A promise that resolves with the response from the embedded app
*/
public async trigger<HostEventT extends HostEvent, PayloadT>(
public async trigger<HostEventT extends HostEvent, PayloadT, ContextT extends ContextType>(
messageType: HostEventT,
data: TriggerPayload<PayloadT, HostEventT> = {} as any,
): Promise<TriggerResponse<PayloadT, HostEventT>> {
context?: ContextT,
): Promise<TriggerResponse<PayloadT, HostEventT, ContextT>> {
uploadMixpanelEvent(`${MIXPANEL_EVENT.VISUAL_SDK_TRIGGER}-${messageType}`);

if (!this.isRendered) {
Expand All @@ -1294,7 +1298,7 @@ export class TsEmbed {
}

// send an empty object, this is needed for liveboard default handlers
return this.hostEventClient.triggerHostEvent(messageType, data);
return this.hostEventClient.triggerHostEvent(messageType, data, context);
}

/**
Expand Down Expand Up @@ -1336,6 +1340,13 @@ export class TsEmbed {
return this.render();
}

public async getCurrentContext(): Promise<any> {
this.executeAfterEmbedContainerLoaded(async () => {
const context = await this.trigger(HostEvent.GetPageContext, {});
return context;
});
}

/**
* Creates the preRender shell
* @param showPreRenderByDefault - Show the preRender after render, hidden by default
Expand Down
Loading