ashish-sdk
Version:
ThoughtSpot Embed SDK
51 lines • 1.7 kB
JavaScript
import { getEmbedConfig, handleAuth } from '../embed/base';
import { initSession } from '../auth';
import { EmbedEvent, OperationType } from '../types';
import { getAnswerServiceInstance } from './answerService';
export function processCustomAction(e, thoughtSpotHost) {
var _a;
if ([
OperationType.GetChartWithData,
OperationType.GetTableWithHeadlineData,
].includes((_a = e.data) === null || _a === void 0 ? void 0 : _a.operation)) {
const { session, query, operation } = e.data;
const answerService = getAnswerServiceInstance(session, query, operation, thoughtSpotHost);
return {
...e,
answerService,
};
}
return e;
}
function processAuthInit(e) {
var _a, _b;
// Store user session details sent by app.
initSession(e.data);
// Expose only allowed details (eg: userGUID) back to SDK users.
return {
...e,
data: {
userGUID: ((_a = e.data) === null || _a === void 0 ? void 0 : _a.userGUID) || ((_b = e.payload) === null || _b === void 0 ? void 0 : _b.userGUID),
},
};
}
function processAuthExpire(e) {
const { autoLogin = true } = getEmbedConfig(); // Set default to true
if (autoLogin) {
handleAuth();
}
return e;
}
export function getProcessData(type, e, thoughtSpotHost) {
switch (type) {
case EmbedEvent.CustomAction:
return processCustomAction(e, thoughtSpotHost);
case EmbedEvent.AuthInit:
return processAuthInit(e);
case EmbedEvent.AuthExpire:
return processAuthExpire(e);
default:
}
return e;
}
//# sourceMappingURL=processData.js.map