@thoughtspot/visual-embed-sdk
Version:
ThoughtSpot Embed SDK
60 lines • 2.9 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.buildSpotterSidebarAppInitData = exports.resolveEnablePastConversationsSidebar = void 0;
const types_1 = require("../types");
const utils_1 = require("../utils");
const errors_1 = require("../errors");
/**
* Resolves enablePastConversationsSidebar with
* spotterSidebarConfig taking precedence over the
* standalone flag.
*/
const resolveEnablePastConversationsSidebar = (params) => (params.spotterSidebarConfigValue !== undefined
? params.spotterSidebarConfigValue
: params.standaloneValue);
exports.resolveEnablePastConversationsSidebar = resolveEnablePastConversationsSidebar;
function buildSpotterSidebarAppInitData(defaultAppInitData, viewConfig, handleError) {
const { spotterSidebarConfig, enablePastConversationsSidebar, visualOverrides } = viewConfig;
const resolvedEnablePastConversations = (0, exports.resolveEnablePastConversationsSidebar)({
spotterSidebarConfigValue: spotterSidebarConfig === null || spotterSidebarConfig === void 0 ? void 0 : spotterSidebarConfig.enablePastConversationsSidebar,
standaloneValue: enablePastConversationsSidebar,
});
const hasConfig = spotterSidebarConfig || resolvedEnablePastConversations !== undefined;
if (!hasConfig) {
if (visualOverrides === undefined) {
return defaultAppInitData;
}
return {
...defaultAppInitData,
embedParams: { visualOverridesParams: visualOverrides },
};
}
const resolvedSidebarConfig = {
...spotterSidebarConfig,
...(resolvedEnablePastConversations !== undefined && {
enablePastConversationsSidebar: resolvedEnablePastConversations,
}),
};
if (resolvedSidebarConfig.spotterDocumentationUrl !== undefined) {
const [isValid, validationError] = (0, utils_1.validateHttpUrl)(resolvedSidebarConfig.spotterDocumentationUrl);
if (!isValid) {
handleError({
errorType: types_1.ErrorDetailsTypes.VALIDATION_ERROR,
message: errors_1.ERROR_MESSAGE.INVALID_SPOTTER_DOCUMENTATION_URL,
code: types_1.EmbedErrorCodes.INVALID_URL,
error: (validationError === null || validationError === void 0 ? void 0 : validationError.message) || errors_1.ERROR_MESSAGE.INVALID_SPOTTER_DOCUMENTATION_URL,
});
delete resolvedSidebarConfig.spotterDocumentationUrl;
}
}
return {
...defaultAppInitData,
embedParams: {
...(defaultAppInitData.embedParams || {}),
spotterSidebarConfig: resolvedSidebarConfig,
...(visualOverrides !== undefined ? { visualOverridesParams: visualOverrides } : {}),
},
};
}
exports.buildSpotterSidebarAppInitData = buildSpotterSidebarAppInitData;
//# sourceMappingURL=spotter-utils.js.map