Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

Preparation for moving sdk code to oss folder (#65428)

Nicolò Pretto679170b8326f
diff --git a/enterprise/frontend/src/embedding-sdk-bundle/components/public/CreateDashboardModal/CreateDashboardModal.tsx b/enterprise/frontend/src/embedding-sdk-bundle/components/public/CreateDashboardModal/CreateDashboardModal.tsx
index 766035470ea..aac95f4cf67 100644
--- a/enterprise/frontend/src/embedding-sdk-bundle/components/public/CreateDashboardModal/CreateDashboardModal.tsx
+++ b/enterprise/frontend/src/embedding-sdk-bundle/components/public/CreateDashboardModal/CreateDashboardModal.tsx
@@ -3,7 +3,10 @@ import {
getCollectionIdSlugFromReference,
getCollectionIdValueFromReference,
} from "embedding-sdk-bundle/store/collections";
-import type { MetabaseDashboard, SdkCollectionId } from "embedding-sdk-package";
+import type {
+ MetabaseDashboard,
+ SdkCollectionId,
+} from "embedding-sdk-bundle/types";
import { useCollectionQuery, useLocale } from "metabase/common/hooks";
import { CreateDashboardModal as CreateDashboardModalCore } from "metabase/dashboard/containers/CreateDashboardModal";
import { useSelector } from "metabase/lib/redux";
diff --git a/enterprise/frontend/src/embedding-sdk-bundle/components/public/MetabotQuestion/MetabotQuestion.tsx b/enterprise/frontend/src/embedding-sdk-bundle/components/public/MetabotQuestion/MetabotQuestion.tsx
index b5260eb95cb..66c3f086848 100644
--- a/enterprise/frontend/src/embedding-sdk-bundle/components/public/MetabotQuestion/MetabotQuestion.tsx
+++ b/enterprise/frontend/src/embedding-sdk-bundle/components/public/MetabotQuestion/MetabotQuestion.tsx
@@ -1,135 +1,21 @@
-import { useElementSize } from "@mantine/hooks";
-import { useId, useMemo } from "react";
-import { P, match } from "ts-pattern";
+import type { ReactNode } from "react";
-import { FlexibleSizeComponent } from "embedding-sdk-bundle/components/private/FlexibleSizeComponent";
-import { withPublicComponentWrapper } from "embedding-sdk-bundle/components/private/PublicComponentWrapper";
-import { SdkAdHocQuestion } from "embedding-sdk-bundle/components/private/SdkAdHocQuestion";
-import { SdkQuestionDefaultView } from "embedding-sdk-bundle/components/private/SdkQuestionDefaultView";
-import { EnsureSingleInstance } from "embedding-sdk-shared/components/EnsureSingleInstance/EnsureSingleInstance";
-import { useLocale } from "metabase/common/hooks/use-locale";
-import { Stack } from "metabase/ui";
-import { useMetabotReactions } from "metabase-enterprise/metabot/hooks/use-metabot-reactions";
+import type { FunctionSchema } from "embedding-sdk-bundle/types/schema";
-import { MetabotChatHistory } from "./MetabotChatHistory";
-import { MetabotChatInput } from "./MetabotChatInput";
-import { MetabotChatSuggestions } from "./MetabotChatSuggestions";
-import S from "./MetabotQuestion.module.css";
-import { metabotQuestionSchema } from "./MetabotQuestion.schema";
-import { MetabotQuestionEmptyState } from "./MetabotQuestionEmptyState";
-import { QuestionDetails } from "./QuestionDetails";
-import { QuestionTitle } from "./QuestionTitle";
-import { SidebarHeader } from "./SidebarHeader";
import type { MetabotQuestionProps } from "./types";
-/**
- * If the Metabot component's container size is smaller
- * than this, use the stacked layout.
- **/
-const MAX_MOBILE_CONTAINER_WIDTH = 700;
-
-const MetabotQuestionInner = ({
- height,
- width,
- className,
- style,
- layout = "auto",
-}: MetabotQuestionProps) => {
- const { isLocaleLoading } = useLocale();
- const { navigateToPath } = useMetabotReactions();
- const { ref: containerRef, width: containerWidth } = useElementSize();
-
- const hasQuestion = !!navigateToPath;
-
- const derivedLayout = useMemo(() => {
- return match(layout)
- .with(P.union("stacked", "sidebar"), (layout) => layout)
- .otherwise((layout) => {
- if (layout !== "auto") {
- console.warn(
- `Invalid layout for MetabotQuestion: ${layout}. Valid values are "stacked", "sidebar", or "auto"`,
- );
- }
-
- return containerWidth <= MAX_MOBILE_CONTAINER_WIDTH
- ? "stacked"
- : "sidebar";
- });
- }, [layout, containerWidth]);
-
- function renderQuestion() {
- if (!hasQuestion || isLocaleLoading) {
- return <MetabotQuestionEmptyState />;
- }
-
- return (
- <SdkAdHocQuestion
- questionPath={navigateToPath}
- title={false}
- isSaveEnabled={false}
- >
- <SdkQuestionDefaultView
- height="100%"
- withChartTypeSelector
- title={
- <Stack gap="sm" mb="1rem">
- <QuestionTitle />
- <QuestionDetails />
- </Stack>
- }
- />
- </SdkAdHocQuestion>
- );
- }
-
- return (
- <FlexibleSizeComponent
- height={height}
- width={width}
- className={className}
- style={style}
- >
- <div
- ref={containerRef}
- className={S.container}
- data-layout={derivedLayout}
- data-testid="metabot-question-container"
- >
- <div className={S.question}>{renderQuestion()}</div>
-
- <div className={S.chat}>
- <Stack w="100%" h="100%" pos="relative" gap={0}>
- <SidebarHeader />
- <MetabotChatHistory />
-
- <Stack gap={0}>
- <MetabotChatSuggestions />
- <MetabotChatInput />
- </Stack>
- </Stack>
- </div>
- </div>
- </FlexibleSizeComponent>
- );
+type MetabotQuestionComponent = ((props: MetabotQuestionProps) => ReactNode) & {
+ schema?: FunctionSchema;
};
-const MetabotQuestionWrapped = (props: MetabotQuestionProps) => {
- const ensureSingleInstanceId = useId();
-
- return (
- <EnsureSingleInstance
- groupId="metabot-question"
- instanceId={ensureSingleInstanceId}
- multipleRegisteredInstancesWarningMessage={
- "Multiple instances of MetabotQuestion detected. Ensure only one instance of MetabotQuestion is rendered at a time."
- }
- >
- <MetabotQuestionInner {...props} />
- </EnsureSingleInstance>
- );
+export const METABOT_SDK_EE_PLUGIN: {
+ MetabotQuestion: MetabotQuestionComponent;
+} = {
+ // Placeholder implementation – replaced by EE plugin at runtime
+ MetabotQuestion: ((_props: MetabotQuestionProps) =>
+ null) as MetabotQuestionComponent,
};
-export const MetabotQuestion = Object.assign(
- withPublicComponentWrapper(MetabotQuestionWrapped),
- { schema: metabotQuestionSchema },
-);
+export const MetabotQuestion = (props: MetabotQuestionProps) => {
+ return <METABOT_SDK_EE_PLUGIN.MetabotQuestion {...props} />;
+};
diff --git a/enterprise/frontend/src/embedding-sdk-bundle/hooks/private/use-init-data/test/jwt.unit.spec.tsx b/enterprise/frontend/src/embedding-sdk-bundle/hooks/private/use-init-data/test/jwt.unit.spec.tsx
index a2e89feba60..c71175ab748 100644
--- a/enterprise/frontend/src/embedding-sdk-bundle/hooks/private/use-init-data/test/jwt.unit.spec.tsx
+++ b/enterprise/frontend/src/embedding-sdk-bundle/hooks/private/use-init-data/test/jwt.unit.spec.tsx
@@ -8,6 +8,8 @@ import {
setupMockJwtEndpoints,
} from "embedding-sdk-bundle/test/mocks/sso";
+import "metabase-enterprise/sdk-plugins";
+
import { type MetabaseConfigProps, TestComponent, setup } from "./setup";
const setupJwt = ({
diff --git a/enterprise/frontend/src/embedding-sdk-bundle/hooks/private/use-init-data/test/setup.tsx b/enterprise/frontend/src/embedding-sdk-bundle/hooks/private/use-init-data/test/setup.tsx
index a768ffc9bdd..63ccb625854 100644
--- a/enterprise/frontend/src/embedding-sdk-bundle/hooks/private/use-init-data/test/setup.tsx
+++ b/enterprise/frontend/src/embedding-sdk-bundle/hooks/private/use-init-data/test/setup.tsx
@@ -1,5 +1,8 @@
/* eslint-disable i18next/no-literal-string */
+// Activates the plugins needed for the tests before any SDK code
+import "metabase-enterprise/sdk-plugins";
+
import { renderWithProviders } from "__support__/ui";
import {
sdkReducers,
diff --git a/enterprise/frontend/src/embedding-sdk-bundle/hooks/private/use-sdk-usage-problem.ts b/enterprise/frontend/src/embedding-sdk-bundle/hooks/private/use-sdk-usage-problem.ts
index b45ad915b3e..92bef0182c3 100644
--- a/enterprise/frontend/src/embedding-sdk-bundle/hooks/private/use-sdk-usage-problem.ts
+++ b/enterprise/frontend/src/embedding-sdk-bundle/hooks/private/use-sdk-usage-problem.ts
@@ -5,9 +5,9 @@ import { getSdkUsageProblem } from "embedding-sdk-bundle/lib/usage-problem";
import { useSdkDispatch, useSdkSelector } from "embedding-sdk-bundle/store";
import { setUsageProblem } from "embedding-sdk-bundle/store/reducer";
import type { MetabaseAuthConfig } from "embedding-sdk-bundle/types/auth-config";
-import type { MetabaseEmbeddingSessionToken } from "embedding-sdk-package";
import { useSetting } from "metabase/common/hooks";
import { EMBEDDING_SDK_CONFIG } from "metabase/embedding-sdk/config";
+import type { MetabaseEmbeddingSessionToken } from "metabase/embedding-sdk/types/refresh-token";
import { getTokenFeature } from "metabase/setup/selectors";
export function useSdkUsageProblem({
diff --git a/enterprise/frontend/src/embedding-sdk-bundle/lib/create-dashboard.ts b/enterprise/frontend/src/embedding-sdk-bundle/lib/create-dashboard.ts
index e22cbab136f..5e3be0060b5 100644
--- a/enterprise/frontend/src/embedding-sdk-bundle/lib/create-dashboard.ts
+++ b/enterprise/frontend/src/embedding-sdk-bundle/lib/create-dashboard.ts
@@ -3,7 +3,7 @@ import type { SdkStore } from "embedding-sdk-bundle/store/types";
import type {
CreateDashboardValues,
MetabaseDashboard,
-} from "embedding-sdk-package";
+} from "embedding-sdk-bundle/types";
import { createDashboard as createDashboardMutation } from "metabase/api/dashboard";
export const createDashboard =
diff --git a/enterprise/frontend/src/embedding-sdk-bundle/lib/usage-problem.ts b/enterprise/frontend/src/embedding-sdk-bundle/lib/usage-problem.ts
index 78defcb0200..2280c22dac6 100644
--- a/enterprise/frontend/src/embedding-sdk-bundle/lib/usage-problem.ts
+++ b/enterprise/frontend/src/embedding-sdk-bundle/lib/usage-problem.ts
@@ -5,8 +5,8 @@ import type {
SdkUsageProblem,
SdkUsageProblemKey,
} from "embedding-sdk-bundle/types/usage-problem";
-import type { MetabaseEmbeddingSessionToken } from "embedding-sdk-package";
import { EMBEDDING_SDK_IFRAME_EMBEDDING_CONFIG } from "metabase/embedding-sdk/config";
+import type { MetabaseEmbeddingSessionToken } from "metabase/embedding-sdk/types/refresh-token";
import { getIsLocalhost } from "./get-is-localhost";
diff --git a/enterprise/frontend/src/embedding-sdk-bundle/store/auth/auth.ts b/enterprise/frontend/src/embedding-sdk-bundle/store/auth/auth.ts
index cacd866bb76..9720efec66c 100644
--- a/enterprise/frontend/src/embedding-sdk-bundle/store/auth/auth.ts
+++ b/enterprise/frontend/src/embedding-sdk-bundle/store/auth/auth.ts
@@ -1,27 +1,22 @@
-import { EMBEDDING_SDK_PACKAGE_UNKNOWN_VERSION } from "build-configs/embedding-sdk/constants/versions";
-import {
- connectToInstanceAuthSso,
- jwtDefaultRefreshTokenFunction,
- openSamlLoginPopup,
- samlTokenStorage,
- validateSession,
-} from "embedding/auth-common";
-import * as MetabaseError from "embedding-sdk-bundle/errors";
-import { getIsLocalhost } from "embedding-sdk-bundle/lib/get-is-localhost";
-import type { SdkStoreState } from "embedding-sdk-bundle/store/types";
+import type { Dispatch } from "@reduxjs/toolkit";
+
import type { MetabaseAuthConfig } from "embedding-sdk-bundle/types/auth-config";
-import type { MetabaseEmbeddingSessionToken } from "embedding-sdk-bundle/types/refresh-token";
-import { getBuildInfo } from "embedding-sdk-shared/lib/get-build-info";
-import { EMBEDDING_SDK_IFRAME_EMBEDDING_CONFIG } from "metabase/embedding-sdk/config";
-import api from "metabase/lib/api";
+import type { MetabaseEmbeddingSessionToken } from "metabase/embedding-sdk/types/refresh-token";
import { createAsyncThunk } from "metabase/lib/redux";
-import { PLUGIN_EMBEDDING_SDK } from "metabase/plugins";
-import { refreshSiteSettings } from "metabase/redux/settings";
-import { refreshCurrentUser } from "metabase/redux/user";
-import { requestSessionTokenFromEmbedJs } from "metabase-enterprise/embedding_iframe_sdk/utils";
-import { getOrRefreshSession } from "../reducer";
-import { getFetchRefreshTokenFn } from "../selectors";
+// This is an SDK-only plugin and we co-locate it with its OSS usage for convenience and better three-shaking.
+export const PLUGIN_EMBEDDING_SDK_AUTH = {
+ initAuth: async (
+ _config: any, // should be `MetabaseAuthConfig & { isLocalHost?: boolean }` but we can't import it for now (it's EE code)
+ _dispatch: { dispatch: Dispatch },
+ ): Promise<void> => {},
+ refreshTokenAsync: async (
+ _config: any,
+ _getState: any,
+ ): Promise<any | null> => {
+ return null;
+ },
+};
export const initAuth = createAsyncThunk(
"sdk/token/INIT_AUTH",
@@ -34,69 +29,15 @@ export const initAuth = createAsyncThunk(
}: MetabaseAuthConfig & { isLocalHost?: boolean },
{ dispatch },
) => {
- // remove any stale tokens that might be there from a previous session=
- samlTokenStorage.remove();
-
- // Setup JWT or API key
- const isValidInstanceUrl =
- metabaseInstanceUrl && metabaseInstanceUrl?.length > 0;
- const isValidApiKeyConfig = apiKey && (isLocalHost || getIsLocalhost());
-
- if (isValidApiKeyConfig) {
- // API key setup
- api.apiKey = apiKey;
- } else if (EMBEDDING_SDK_IFRAME_EMBEDDING_CONFIG.useExistingUserSession) {
- // Use existing user session. Do nothing.
- } else if (isValidInstanceUrl) {
- // SSO setup
- PLUGIN_EMBEDDING_SDK.onBeforeRequestHandlers.getOrRefreshSessionHandler =
- async () => {
- const session = await dispatch(
- getOrRefreshSession({
- metabaseInstanceUrl,
- preferredAuthMethod,
- }),
- ).unwrap();
- if (session?.id) {
- api.sessionToken = session.id;
- }
- };
-
- try {
- // verify that the session is actually valid before proceeding
- await dispatch(
- getOrRefreshSession({
- metabaseInstanceUrl,
- preferredAuthMethod,
- }),
- ).unwrap();
- } catch (e) {
- // TODO: Fix this. For some reason the instanceof check keeps returning `false`. I'd rather not do this
- // but due to time constraints this is what we have to do to make sure tests pass.
- // eslint-disable-next-line no-literal-metabase-strings -- error checking for better errors. should be improved in the future.
- if ((e as Error).name === "MetabaseError") {
- throw e;
- }
- throw MetabaseError.REFRESH_TOKEN_BACKEND_ERROR(e as Error);
- }
- }
-
- // Fetch user and site settings
- const [user, siteSettings] = await Promise.all([
- dispatch(refreshCurrentUser()),
- dispatch(refreshSiteSettings()),
- ]);
-
- if (!user.payload) {
- if (EMBEDDING_SDK_IFRAME_EMBEDDING_CONFIG.useExistingUserSession) {
- throw MetabaseError.EXISTING_USER_SESSION_FAILED();
- }
-
- throw MetabaseError.USER_FETCH_FAILED();
- }
- if (!siteSettings.payload) {
- throw MetabaseError.USER_FETCH_FAILED();
- }
+ return await PLUGIN_EMBEDDING_SDK_AUTH.initAuth(
+ {
+ metabaseInstanceUrl,
+ preferredAuthMethod,
+ apiKey,
+ isLocalHost,
+ },
+ { dispatch },
+ );
},
);
@@ -109,64 +50,12 @@ export const refreshTokenAsync = createAsyncThunk(
}: Pick<MetabaseAuthConfig, "metabaseInstanceUrl" | "preferredAuthMethod">,
{ getState },
): Promise<MetabaseEmbeddingSessionToken | null> => {
- const state = getState() as SdkStoreState;
-
- if (EMBEDDING_SDK_IFRAME_EMBEDDING_CONFIG.isSimpleEmbedding) {
- return requestSessionTokenFromEmbedJs();
- }
-
- const customGetRefreshToken = getFetchRefreshTokenFn(state) ?? undefined;
-
- const session = await getRefreshToken({
- metabaseInstanceUrl,
- preferredAuthMethod,
- fetchRequestToken: customGetRefreshToken,
- });
- validateSession(session);
-
- return session;
+ return await PLUGIN_EMBEDDING_SDK_AUTH.refreshTokenAsync(
+ {
+ metabaseInstanceUrl,
+ preferredAuthMethod,
+ },
+ { getState },
+ );
},
);
-
-const getRefreshToken = async ({
- metabaseInstanceUrl,
- preferredAuthMethod,
- fetchRequestToken: customGetRequestToken,
-}: Pick<
- MetabaseAuthConfig,
- "metabaseInstanceUrl" | "fetchRequestToken" | "preferredAuthMethod"
->) => {
- const urlResponseJson = await connectToInstanceAuthSso(metabaseInstanceUrl, {
- preferredAuthMethod,
- headers: getSdkRequestHeaders(),
- });
- const { method, url: responseUrl, hash } = urlResponseJson || {};
- if (method === "saml") {
- const token = await openSamlLoginPopup(responseUrl);
- samlTokenStorage.set(token);
-
- return token;
- }
- if (method === "jwt") {
- return jwtDefaultRefreshTokenFunction(
- responseUrl,
- metabaseInstanceUrl,
- getSdkRequestHeaders(hash),
- customGetRequestToken,
- );
- }
- throw MetabaseError.INVALID_AUTH_METHOD({ method });
-};
-
-export function getSdkRequestHeaders(hash?: string): Record<string, string> {
- return {
- // eslint-disable-next-line no-literal-metabase-strings -- header name
- "X-Metabase-Client": "embedding-sdk-react",
- // eslint-disable-next-line no-literal-metabase-strings -- header name
- "X-Metabase-Client-Version":
- getBuildInfo("METABASE_EMBEDDING_SDK_PACKAGE_BUILD_INFO").version ??
- EMBEDDING_SDK_PACKAGE_UNKNOWN_VERSION,
- // eslint-disable-next-line no-literal-metabase-strings -- header name
- ...(hash && { "X-Metabase-SDK-JWT-Hash": hash }),
- };
-}
diff --git a/enterprise/frontend/src/embedding-sdk-bundle/store/auth/index.ts b/enterprise/frontend/src/embedding-sdk-bundle/store/auth/index.ts
index 171c444848e..97ccf76494a 100644
--- a/enterprise/frontend/src/embedding-sdk-bundle/store/auth/index.ts
+++ b/enterprise/frontend/src/embedding-sdk-bundle/store/auth/index.ts
@@ -1,2 +1 @@
export * from "./auth";
-export * from "../../../embedding/auth-common/saml-token-storage";
diff --git a/enterprise/frontend/src/embedding-sdk-bundle/store/reducer.ts b/enterprise/frontend/src/embedding-sdk-bundle/store/reducer.ts
index 07f9bc24438..ec2571133e8 100644
--- a/enterprise/frontend/src/embedding-sdk-bundle/store/reducer.ts
+++ b/enterprise/frontend/src/embedding-sdk-bundle/store/reducer.ts
@@ -1,27 +1,16 @@
-import {
- type AsyncThunkAction,
- createAction,
- createReducer,
-} from "@reduxjs/toolkit";
-
-import { samlTokenStorage } from "embedding/auth-common";
-import type { SdkState, SdkStoreState } from "embedding-sdk-bundle/store/types";
-import type { MetabaseAuthConfig } from "embedding-sdk-bundle/types/auth-config";
+import { createAction, createReducer } from "@reduxjs/toolkit";
+
+import type { SdkState } from "embedding-sdk-bundle/store/types";
import type { SdkEventHandlersConfig } from "embedding-sdk-bundle/types/events";
import type { MetabasePluginsConfig } from "embedding-sdk-bundle/types/plugins";
-import type {
- MetabaseEmbeddingSessionToken,
- MetabaseFetchRequestTokenFn,
-} from "embedding-sdk-bundle/types/refresh-token";
import type {
SdkErrorComponent,
SdkLoadingError,
} from "embedding-sdk-bundle/types/ui";
import type { SdkUsageProblem } from "embedding-sdk-bundle/types/usage-problem";
-import { createAsyncThunk } from "metabase/lib/redux";
+import type { MetabaseFetchRequestTokenFn } from "metabase/embedding-sdk/types/refresh-token";
import { initAuth, refreshTokenAsync } from "./auth";
-import { getSessionTokenState } from "./selectors";
const SET_METABASE_INSTANCE_VERSION = "sdk/SET_METABASE_INSTANCE_VERSION";
const SET_METABASE_CLIENT_URL = "sdk/SET_METABASE_CLIENT_URL";
const SET_LOADER_COMPONENT = "sdk/SET_LOADER_COMPONENT";
@@ -45,52 +34,6 @@ export const setError = createAction<SdkLoadingError | null>(SET_ERROR);
export const setFetchRefreshTokenFn =
createAction<null | MetabaseFetchRequestTokenFn>(SET_FETCH_REQUEST_TOKEN_FN);
-const GET_OR_REFRESH_SESSION = "sdk/token/GET_OR_REFRESH_SESSION";
-
-let refreshTokenPromise: ReturnType<
- AsyncThunkAction<MetabaseEmbeddingSessionToken | null, unknown, any>
-> | null = null;
-
-export const getOrRefreshSession = createAsyncThunk(
- GET_OR_REFRESH_SESSION,
- async (
- authConfig: Pick<
- MetabaseAuthConfig,
- "metabaseInstanceUrl" | "preferredAuthMethod"
- >,
- { dispatch, getState },
- ) => {
- // necessary to ensure that we don't use a popup every time the user
- // refreshes the page
- const storedAuthToken = samlTokenStorage.get();
- const state = getSessionTokenState(getState() as SdkStoreState);
- /**
- * @see {@link https://github.com/metabase/metabase/pull/64238#discussion_r2394229266}
- *
- * TODO: I think this should be called session overall e.g. state.session
- */
- const session = storedAuthToken ?? state?.token;
-
- const shouldRefreshToken =
- !session ||
- (typeof session?.exp === "number" && session.exp * 1000 < Date.now());
- if (!shouldRefreshToken) {
- return session;
- }
-
- if (refreshTokenPromise) {
- return refreshTokenPromise.unwrap();
- }
-
- refreshTokenPromise = dispatch(refreshTokenAsync(authConfig));
- refreshTokenPromise.finally(() => {
- refreshTokenPromise = null;
- });
-
- return refreshTokenPromise.unwrap();
- },
-);
-
const SET_PLUGINS = "sdk/SET_PLUGINS";
export const setPlugins = createAction<MetabasePluginsConfig | null>(
SET_PLUGINS,
diff --git a/enterprise/frontend/src/embedding-sdk-bundle/store/types.ts b/enterprise/frontend/src/embedding-sdk-bundle/store/types.ts
index e617f0465ec..5bffa13cddc 100644
--- a/enterprise/frontend/src/embedding-sdk-bundle/store/types.ts
+++ b/enterprise/frontend/src/embedding-sdk-bundle/store/types.ts
@@ -10,13 +10,13 @@ import type { JSX } from "react";
import type { MetabaseAuthConfig } from "embedding-sdk-bundle/types/auth-config";
import type { SdkEventHandlersConfig } from "embedding-sdk-bundle/types/events";
import type { MetabasePluginsConfig } from "embedding-sdk-bundle/types/plugins";
-import type { MetabaseEmbeddingSessionToken } from "embedding-sdk-bundle/types/refresh-token";
import type {
SdkErrorComponent,
SdkLoadingError,
} from "embedding-sdk-bundle/types/ui";
import type { SdkUsageProblem } from "embedding-sdk-bundle/types/usage-problem";
import type { LoginStatus } from "embedding-sdk-bundle/types/user";
+import type { MetabaseEmbeddingSessionToken } from "metabase/embedding-sdk/types/refresh-token";
import type { State } from "metabase-types/store";
export type EmbeddingSessionTokenState = {
diff --git a/enterprise/frontend/src/embedding-sdk-bundle/stories/mapQuestionClickActions.stories.tsx b/enterprise/frontend/src/embedding-sdk-bundle/stories/mapQuestionClickActions.stories.tsx
index d5e997b11ef..2acb61bbe9e 100644
--- a/enterprise/frontend/src/embedding-sdk-bundle/stories/mapQuestionClickActions.stories.tsx
+++ b/enterprise/frontend/src/embedding-sdk-bundle/stories/mapQuestionClickActions.stories.tsx
@@ -2,7 +2,7 @@ import { useState } from "react";
import { InteractiveDashboard } from "embedding-sdk-bundle/components/public/dashboard";
import { CommonSdkStoryWrapper } from "embedding-sdk-bundle/test/CommonSdkStoryWrapper";
-import type { MetabaseDataPointObject } from "embedding-sdk-package";
+import type { MetabaseDataPointObject } from "embedding-sdk-bundle/types";
export default {
title: "EmbeddingSDK/Map Question Click Actions",
diff --git a/enterprise/frontend/src/embedding-sdk-bundle/test/auth-flow/api-key.unit.spec.tsx b/enterprise/frontend/src/embedding-sdk-bundle/test/auth-flow/api-key.unit.spec.tsx
index 4a4f837f581..e01aa08d39a 100644
--- a/enterprise/frontend/src/embedding-sdk-bundle/test/auth-flow/api-key.unit.spec.tsx
+++ b/enterprise/frontend/src/embedding-sdk-bundle/test/auth-flow/api-key.unit.spec.tsx
@@ -5,6 +5,9 @@ import { MOCK_API_KEY, MOCK_INSTANCE_URL } from "../mocks/sso";
import { setup } from "./setup";
+// Activates the plugins needed for the tests before any SDK code
+import "metabase-enterprise/sdk-plugins";
+
describe("Auth Flow - API Key", () => {
it("should send the api key as 'X-Api-Key' header", async () => {
const authConfig = defineMetabaseAuthConfig({
diff --git a/enterprise/frontend/src/embedding-sdk-bundle/test/auth-flow/jwt.unit.spec.tsx b/enterprise/frontend/src/embedding-sdk-bundle/test/auth-flow/jwt.unit.spec.tsx
index e7f0d63a6f1..b4e291bca9c 100644
--- a/enterprise/frontend/src/embedding-sdk-bundle/test/auth-flow/jwt.unit.spec.tsx
+++ b/enterprise/frontend/src/embedding-sdk-bundle/test/auth-flow/jwt.unit.spec.tsx
@@ -23,6 +23,9 @@ import {
import { setup as baseSetup } from "./setup";
+// Activates the plugins needed for the tests before any SDK code
+import "metabase-enterprise/sdk-plugins";
+
const setup = ({
authConfig,
locale,
diff --git a/enterprise/frontend/src/embedding-sdk-bundle/test/auth-flow/saml.unit.spec.tsx b/enterprise/frontend/src/embedding-sdk-bundle/test/auth-flow/saml.unit.spec.tsx
index 9948b83ba78..dec824579a8 100644
--- a/enterprise/frontend/src/embedding-sdk-bundle/test/auth-flow/saml.unit.spec.tsx
+++ b/enterprise/frontend/src/embedding-sdk-bundle/test/auth-flow/saml.unit.spec.tsx
@@ -17,6 +17,9 @@ import {
import { setup as baseSetup } from "./setup";
+// Activates the plugins needed for the tests before any SDK code
+import "metabase-enterprise/sdk-plugins";
+
const setup = ({
authConfig,
locale,
diff --git a/enterprise/frontend/src/embedding-sdk-bundle/test/sdk-config-errors/sdk-config-errors.unit.spec.tsx b/enterprise/frontend/src/embedding-sdk-bundle/test/sdk-config-errors/sdk-config-errors.unit.spec.tsx
index dda08967a9a..e3052c0dc55 100644
--- a/enterprise/frontend/src/embedding-sdk-bundle/test/sdk-config-errors/sdk-config-errors.unit.spec.tsx
+++ b/enterprise/frontend/src/embedding-sdk-bundle/test/sdk-config-errors/sdk-config-errors.unit.spec.tsx
@@ -1,3 +1,6 @@
+// Activates the plugins needed for the tests before any SDK code
+import "metabase-enterprise/sdk-plugins";
+
import { render, screen, waitFor } from "@testing-library/react";
import {
diff --git a/enterprise/frontend/src/embedding-sdk-bundle/types/auth-config.ts b/enterprise/frontend/src/embedding-sdk-bundle/types/auth-config.ts
index 032a2717fb0..a66ab81fb7d 100644
--- a/enterprise/frontend/src/embedding-sdk-bundle/types/auth-config.ts
+++ b/enterprise/frontend/src/embedding-sdk-bundle/types/auth-config.ts
@@ -1,4 +1,4 @@
-import type { MetabaseFetchRequestTokenFn } from "embedding-sdk-bundle/types/refresh-token";
+import type { MetabaseFetchRequestTokenFn } from "metabase/embedding-sdk/types/refresh-token";
/**
* @inline
diff --git a/enterprise/frontend/src/embedding-sdk-ee/auth/auth.ts b/enterprise/frontend/src/embedding-sdk-ee/auth/auth.ts
new file mode 100644
index 00000000000..9a738db009f
--- /dev/null
+++ b/enterprise/frontend/src/embedding-sdk-ee/auth/auth.ts
@@ -0,0 +1,230 @@
+// This file contains plugins that are needed to make the sdk bundle work.
+
+import type { AsyncThunkAction } from "@reduxjs/toolkit";
+
+import { EMBEDDING_SDK_PACKAGE_UNKNOWN_VERSION } from "build-configs/embedding-sdk/constants/versions";
+import {
+ connectToInstanceAuthSso,
+ jwtDefaultRefreshTokenFunction,
+ openSamlLoginPopup,
+ validateSession,
+} from "embedding/auth-common";
+import * as MetabaseError from "embedding-sdk-bundle/errors";
+import { getIsLocalhost } from "embedding-sdk-bundle/lib/get-is-localhost";
+import { PLUGIN_EMBEDDING_SDK_AUTH } from "embedding-sdk-bundle/store/auth";
+import {
+ getFetchRefreshTokenFn,
+ getSessionTokenState,
+} from "embedding-sdk-bundle/store/selectors";
+import type {
+ SdkDispatch,
+ SdkStoreState,
+} from "embedding-sdk-bundle/store/types";
+import type { MetabaseAuthConfig } from "embedding-sdk-bundle/types/auth-config";
+import { getBuildInfo } from "embedding-sdk-shared/lib/get-build-info";
+import { EMBEDDING_SDK_IFRAME_EMBEDDING_CONFIG } from "metabase/embedding-sdk/config";
+import { samlTokenStorage } from "metabase/embedding-sdk/lib/saml-token-storage";
+import type { MetabaseEmbeddingSessionToken } from "metabase/embedding-sdk/types/refresh-token";
+import api from "metabase/lib/api";
+import { createAsyncThunk } from "metabase/lib/redux";
+import { PLUGIN_EMBEDDING_SDK } from "metabase/plugins";
+import { refreshSiteSettings } from "metabase/redux/settings";
+import { refreshCurrentUser } from "metabase/redux/user";
+import { requestSessionTokenFromEmbedJs } from "metabase-enterprise/embedding_iframe_sdk/utils";
+
+const GET_OR_REFRESH_SESSION = "sdk/token/GET_OR_REFRESH_SESSION";
+
+let refreshTokenPromise: ReturnType<
+ AsyncThunkAction<MetabaseEmbeddingSessionToken | null, unknown, any>
+> | null = null;
+
+// Side effect happening here.
+PLUGIN_EMBEDDING_SDK_AUTH.initAuth = async (
+ {
+ metabaseInstanceUrl,
+ preferredAuthMethod,
+ apiKey,
+ isLocalHost,
+ }: MetabaseAuthConfig & { isLocalHost?: boolean },
+ { dispatch }: { dispatch: SdkDispatch },
+) => {
+ // remove any stale tokens that might be there from a previous session=
+ samlTokenStorage.remove();
+
+ // Setup JWT or API key
+ const isValidInstanceUrl =
+ metabaseInstanceUrl && metabaseInstanceUrl?.length > 0;
+ const isValidApiKeyConfig = apiKey && (isLocalHost || getIsLocalhost());
+
+ if (isValidApiKeyConfig) {
+ // API key setup
+ api.apiKey = apiKey;
+ } else if (EMBEDDING_SDK_IFRAME_EMBEDDING_CONFIG.useExistingUserSession) {
+ // Use existing user session. Do nothing.
+ } else if (isValidInstanceUrl) {
+ // SSO setup
+ PLUGIN_EMBEDDING_SDK.onBeforeRequestHandlers.getOrRefreshSessionHandler =
+ async () => {
+ const session = await dispatch(
+ getOrRefreshSession({
+ metabaseInstanceUrl,
+ preferredAuthMethod,
+ }),
+ ).unwrap();
+ if (session?.id) {
+ api.sessionToken = session.id;
+ }
+ };
+ try {
+ // verify that the session is actually valid before proceeding
+ await dispatch(
+ getOrRefreshSession({
+ metabaseInstanceUrl,
+ preferredAuthMethod,
+ }),
+ ).unwrap();
+ } catch (e) {
+ // TODO: Fix this. For some reason the instanceof check keeps returning `false`. I'd rather not do this
+ // but due to time constraints this is what we have to do to make sure tests pass.
+ // eslint-disable-next-line no-literal-metabase-strings -- error checking for better errors. should be improved in the future.
+ if ((e as Error).name === "MetabaseError") {
+ throw e;
+ }
+ throw MetabaseError.REFRESH_TOKEN_BACKEND_ERROR(e as Error);
+ }
+ }
+
+ // Fetch user and site settings
+ const [user, siteSettings] = await Promise.all([
+ dispatch(refreshCurrentUser()),
+ dispatch(refreshSiteSettings()),
+ ]);
+
+ if (!user.payload) {
+ if (EMBEDDING_SDK_IFRAME_EMBEDDING_CONFIG.useExistingUserSession) {
+ throw MetabaseError.EXISTING_USER_SESSION_FAILED();
+ }
+
+ throw MetabaseError.USER_FETCH_FAILED();
+ }
+ if (!siteSettings.payload) {
+ throw MetabaseError.USER_FETCH_FAILED();
+ }
+};
+
+const refreshTokenImpl = async (
+ {
+ metabaseInstanceUrl,
+ preferredAuthMethod,
+ }: Pick<MetabaseAuthConfig, "metabaseInstanceUrl" | "preferredAuthMethod">,
+ { getState }: { getState: () => unknown },
+): Promise<MetabaseEmbeddingSessionToken | null> => {
+ const state = getState() as SdkStoreState;
+
+ if (EMBEDDING_SDK_IFRAME_EMBEDDING_CONFIG.isSimpleEmbedding) {
+ return requestSessionTokenFromEmbedJs();
+ }
+
+ const customGetRefreshToken = getFetchRefreshTokenFn(state) ?? undefined;
+
+ const session = await getRefreshToken({
+ metabaseInstanceUrl,
+ preferredAuthMethod,
+ fetchRequestToken: customGetRefreshToken,
+ });
+ validateSession(session);
+
+ return session;
+};
+
+// Thunk used locally in this file, NOT exported
+const refreshTokenAsync = createAsyncThunk(
+ "sdk/token/REFRESH_TOKEN",
+ refreshTokenImpl,
+);
+
+// implementation used by the OSS thunk wrapper
+PLUGIN_EMBEDDING_SDK_AUTH.refreshTokenAsync = refreshTokenImpl;
+
+export const getOrRefreshSession = createAsyncThunk(
+ GET_OR_REFRESH_SESSION,
+ async (
+ authConfig: Pick<
+ MetabaseAuthConfig,
+ "metabaseInstanceUrl" | "preferredAuthMethod"
+ >,
+ { dispatch, getState },
+ ) => {
+ // necessary to ensure that we don't use a popup every time the user
+ // refreshes the page
+ const storedAuthToken = samlTokenStorage.get();
+ const state = getSessionTokenState(getState() as SdkStoreState);
+ /**
+ * @see {@link https://github.com/metabase/metabase/pull/64238#discussion_r2394229266}
+ *
+ * TODO: I think this should be called session overall e.g. state.session
+ */
+ const session = storedAuthToken ?? state?.token;
+
+ const shouldRefreshToken =
+ !session ||
+ (typeof session?.exp === "number" && session.exp * 1000 < Date.now());
+ if (!shouldRefreshToken) {
+ return session;
+ }
+
+ if (refreshTokenPromise) {
+ return refreshTokenPromise.unwrap();
+ }
+
+ refreshTokenPromise = dispatch(refreshTokenAsync(authConfig));
+ refreshTokenPromise.finally(() => {
+ refreshTokenPromise = null;
+ });
+
+ return refreshTokenPromise.unwrap();
+ },
+);
+
+const getRefreshToken = async ({
+ metabaseInstanceUrl,
+ preferredAuthMethod,
+ fetchRequestToken: customGetRequestToken,
+}: Pick<
+ MetabaseAuthConfig,
+ "metabaseInstanceUrl" | "fetchRequestToken" | "preferredAuthMethod"
+>) => {
+ const urlResponseJson = await connectToInstanceAuthSso(metabaseInstanceUrl, {
+ preferredAuthMethod,
+ headers: getSdkRequestHeaders(),
+ });
+ const { method, url: responseUrl, hash } = urlResponseJson || {};
+ if (method === "saml") {
+ const token = await openSamlLoginPopup(responseUrl);
+ samlTokenStorage.set(token);
+
+ return token;
+ }
+ if (method === "jwt") {
+ return jwtDefaultRefreshTokenFunction(
+ responseUrl,
+ metabaseInstanceUrl,
+ getSdkRequestHeaders(hash),
+ customGetRequestToken,
+ );
+ }
+ throw MetabaseError.INVALID_AUTH_METHOD({ method });
+};
+
+function getSdkRequestHeaders(hash?: string): Record<string, string> {
+ return {
+ // eslint-disable-next-line no-literal-metabase-strings -- header name
+ "X-Metabase-Client": "embedding-sdk-react",
+ // eslint-disable-next-line no-literal-metabase-strings -- header name
+ "X-Metabase-Client-Version":
+ getBuildInfo("METABASE_EMBEDDING_SDK_PACKAGE_BUILD_INFO").version ??
+ EMBEDDING_SDK_PACKAGE_UNKNOWN_VERSION,
+ // eslint-disable-next-line no-literal-metabase-strings -- header name
+ ...(hash && { "X-Metabase-SDK-JWT-Hash": hash }),
+ };
+}
diff --git a/enterprise/frontend/src/embedding-sdk-ee/auth/index.ts b/enterprise/frontend/src/embedding-sdk-ee/auth/index.ts
new file mode 100644
index 00000000000..97207be90da
--- /dev/null
+++ b/enterprise/frontend/src/embedding-sdk-ee/auth/index.ts
@@ -0,0 +1,2 @@
+// side effect inside `./auth.ts`
+import "./auth";
diff --git a/enterprise/frontend/src/embedding-sdk-bundle/components/public/MetabotQuestion/MetabotChatHistory.tsx b/enterprise/frontend/src/embedding-sdk-ee/metabot/MetabotChatHistory.tsx
similarity index 100%
rename from enterprise/frontend/src/embedding-sdk-bundle/components/public/MetabotQuestion/MetabotChatHistory.tsx
rename to enterprise/frontend/src/embedding-sdk-ee/metabot/MetabotChatHistory.tsx
diff --git a/enterprise/frontend/src/embedding-sdk-bundle/components/public/MetabotQuestion/MetabotChatInput.tsx b/enterprise/frontend/src/embedding-sdk-ee/metabot/MetabotChatInput.tsx
similarity index 100%
rename from enterprise/frontend/src/embedding-sdk-bundle/components/public/MetabotQuestion/MetabotChatInput.tsx
rename to enterprise/frontend/src/embedding-sdk-ee/metabot/MetabotChatInput.tsx
diff --git a/enterprise/frontend/src/embedding-sdk-bundle/components/public/MetabotQuestion/MetabotChatSuggestions.tsx b/enterprise/frontend/src/embedding-sdk-ee/metabot/MetabotChatSuggestions.tsx
similarity index 100%
rename from enterprise/frontend/src/embedding-sdk-bundle/components/public/MetabotQuestion/MetabotChatSuggestions.tsx
rename to enterprise/frontend/src/embedding-sdk-ee/metabot/MetabotChatSuggestions.tsx
diff --git a/enterprise/frontend/src/embedding-sdk-bundle/components/public/MetabotQuestion/MetabotQuestion.module.css b/enterprise/frontend/src/embedding-sdk-ee/metabot/MetabotQuestion.module.css
similarity index 100%
rename from enterprise/frontend/src/embedding-sdk-bundle/components/public/MetabotQuestion/MetabotQuestion.module.css
rename to enterprise/frontend/src/embedding-sdk-ee/metabot/MetabotQuestion.module.css
diff --git a/enterprise/frontend/src/embedding-sdk-bundle/components/public/MetabotQuestion/MetabotQuestion.schema.ts b/enterprise/frontend/src/embedding-sdk-ee/metabot/MetabotQuestion.schema.ts
similarity index 90%
rename from enterprise/frontend/src/embedding-sdk-bundle/components/public/MetabotQuestion/MetabotQuestion.schema.ts
rename to enterprise/frontend/src/embedding-sdk-ee/metabot/MetabotQuestion.schema.ts
index 8ef186e3a57..48213b1bcaa 100644
--- a/enterprise/frontend/src/embedding-sdk-bundle/components/public/MetabotQuestion/MetabotQuestion.schema.ts
+++ b/enterprise/frontend/src/embedding-sdk-ee/metabot/MetabotQuestion.schema.ts
@@ -2,7 +2,7 @@ import * as Yup from "yup";
import type { FunctionSchema } from "embedding-sdk-bundle/types/schema";
-import type { MetabotQuestionProps } from "./types";
+import type { MetabotQuestionProps } from ".";
const propsSchema: Yup.SchemaOf<MetabotQuestionProps> = Yup.object({
height: Yup.mixed().optional(),
diff --git a/enterprise/frontend/src/embedding-sdk-bundle/components/public/MetabotQuestion/MetabotQuestion.stories.tsx b/enterprise/frontend/src/embedding-sdk-ee/metabot/MetabotQuestion.stories.tsx
similarity index 95%
rename from enterprise/frontend/src/embedding-sdk-bundle/components/public/MetabotQuestion/MetabotQuestion.stories.tsx
rename to enterprise/frontend/src/embedding-sdk-ee/metabot/MetabotQuestion.stories.tsx
index b1ab1e2990e..8b93f207550 100644
--- a/enterprise/frontend/src/embedding-sdk-bundle/components/public/MetabotQuestion/MetabotQuestion.stories.tsx
+++ b/enterprise/frontend/src/embedding-sdk-ee/metabot/MetabotQuestion.stories.tsx
@@ -3,13 +3,15 @@ import { HttpResponse, http } from "msw";
import type { ComponentProps } from "react";
import { CommonSdkStoryWrapper } from "embedding-sdk-bundle/test/CommonSdkStoryWrapper";
+import { MetabotQuestion } from "embedding-sdk-package";
import {
MOCK_AD_HOC_QUESTION_ID,
mockStreamResponse,
} from "embedding-sdk-shared/test/mocks/mock-metabot-response";
import { Flex, Stack } from "metabase/ui";
-import { MetabotQuestion } from "./MetabotQuestion";
+// side effect to activate the plugin
+import "./MetabotQuestion";
type MetabotQuestionProps = ComponentProps<typeof MetabotQuestion>;
diff --git a/enterprise/frontend/src/embedding-sdk-ee/metabot/MetabotQuestion.tsx b/enterprise/frontend/src/embedding-sdk-ee/metabot/MetabotQuestion.tsx
new file mode 100644
index 00000000000..3632b1fb8d8
--- /dev/null
+++ b/enterprise/frontend/src/embedding-sdk-ee/metabot/MetabotQuestion.tsx
@@ -0,0 +1,138 @@
+import { useElementSize } from "@mantine/hooks";
+import { useId, useMemo } from "react";
+import { P, match } from "ts-pattern";
+
+import { FlexibleSizeComponent } from "embedding-sdk-bundle/components/private/FlexibleSizeComponent";
+import { withPublicComponentWrapper } from "embedding-sdk-bundle/components/private/PublicComponentWrapper";
+import { SdkAdHocQuestion } from "embedding-sdk-bundle/components/private/SdkAdHocQuestion";
+import { SdkQuestionDefaultView } from "embedding-sdk-bundle/components/private/SdkQuestionDefaultView";
+import { METABOT_SDK_EE_PLUGIN } from "embedding-sdk-bundle/components/public/MetabotQuestion/MetabotQuestion";
+import { EnsureSingleInstance } from "embedding-sdk-shared/components/EnsureSingleInstance/EnsureSingleInstance";
+import { useLocale } from "metabase/common/hooks/use-locale";
+import { Stack } from "metabase/ui";
+import { useMetabotReactions } from "metabase-enterprise/metabot/hooks/use-metabot-reactions";
+
+import { MetabotChatHistory } from "./MetabotChatHistory";
+import { MetabotChatInput } from "./MetabotChatInput";
+import { MetabotChatSuggestions } from "./MetabotChatSuggestions";
+import S from "./MetabotQuestion.module.css";
+import { metabotQuestionSchema } from "./MetabotQuestion.schema";
+import { MetabotQuestionEmptyState } from "./MetabotQuestionEmptyState";
+import { QuestionDetails } from "./QuestionDetails";
+import { QuestionTitle } from "./QuestionTitle";
+import { SidebarHeader } from "./SidebarHeader";
+
+import type { MetabotQuestionProps } from ".";
+
+/**
+ * If the Metabot component's container size is smaller
+ * than this, use the stacked layout.
+ **/
+const MAX_MOBILE_CONTAINER_WIDTH = 700;
+
+const MetabotQuestionInner = ({
+ height,
+ width,
+ className,
+ style,
+ layout = "auto",
+}: MetabotQuestionProps) => {
+ const { isLocaleLoading } = useLocale();
+ const { navigateToPath } = useMetabotReactions();
+ const { ref: containerRef, width: containerWidth } = useElementSize();
+
+ const hasQuestion = !!navigateToPath;
+
+ const derivedLayout = useMemo(() => {
+ return match(layout)
+ .with(P.union("stacked", "sidebar"), (layout) => layout)
+ .otherwise((layout) => {
+ if (layout !== "auto") {
+ console.warn(
+ `Invalid layout for MetabotQuestion: ${layout}. Valid values are "stacked", "sidebar", or "auto"`,
+ );
+ }
+
+ return containerWidth <= MAX_MOBILE_CONTAINER_WIDTH
+ ? "stacked"
+ : "sidebar";
+ });
+ }, [layout, containerWidth]);
+
+ function renderQuestion() {
+ if (!hasQuestion || isLocaleLoading) {
+ return <MetabotQuestionEmptyState />;
+ }
+
+ return (
+ <SdkAdHocQuestion
+ questionPath={navigateToPath}
+ title={false}
+ isSaveEnabled={false}
+ >
+ <SdkQuestionDefaultView
+ height="100%"
+ withChartTypeSelector
+ title={
+ <Stack gap="sm" mb="1rem">
+ <QuestionTitle />
+ <QuestionDetails />
+ </Stack>
+ }
+ />
+ </SdkAdHocQuestion>
+ );
+ }
+
+ return (
+ <FlexibleSizeComponent
+ height={height}
+ width={width}
+ className={className}
+ style={style}
+ >
+ <div
+ ref={containerRef}
+ className={S.container}
+ data-layout={derivedLayout}
+ data-testid="metabot-question-container"
+ >
+ <div className={S.question}>{renderQuestion()}</div>
+
+ <div className={S.chat}>
+ <Stack w="100%" h="100%" pos="relative" gap={0}>
+ <SidebarHeader />
+ <MetabotChatHistory />
+
+ <Stack gap={0}>
+ <MetabotChatSuggestions />
+ <MetabotChatInput />
+ </Stack>
+ </Stack>
+ </div>
+ </div>
+ </FlexibleSizeComponent>
+ );
+};
+
+const MetabotQuestionWrapped = (props: MetabotQuestionProps) => {
+ const ensureSingleInstanceId = useId();
+
+ return (
+ <EnsureSingleInstance
+ groupId="metabot-question"
+ instanceId={ensureSingleInstanceId}
+ multipleRegisteredInstancesWarningMessage={
+ "Multiple instances of MetabotQuestion detected. Ensure only one instance of MetabotQuestion is rendered at a time."
+ }
+ >
+ <MetabotQuestionInner {...props} />
+ </EnsureSingleInstance>
+ );
+};
+
+// side effect that activates the plugin
+METABOT_SDK_EE_PLUGIN.MetabotQuestion = Object.assign(
+ withPublicComponentWrapper(MetabotQuestionWrapped),
+ { schema: metabotQuestionSchema },
+);
diff --git a/enterprise/frontend/src/embedding-sdk-bundle/components/public/MetabotQuestion/MetabotQuestionEmptyState.tsx b/enterprise/frontend/src/embedding-sdk-ee/metabot/MetabotQuestionEmptyState.tsx
similarity index 100%
rename from enterprise/frontend/src/embedding-sdk-bundle/components/public/MetabotQuestion/MetabotQuestionEmptyState.tsx
rename to enterprise/frontend/src/embedding-sdk-ee/metabot/MetabotQuestionEmptyState.tsx
diff --git a/enterprise/frontend/src/embedding-sdk-bundle/components/public/MetabotQuestion/QuestionDetails.tsx b/enterprise/frontend/src/embedding-sdk-ee/metabot/QuestionDetails.tsx
similarity index 100%
rename from enterprise/frontend/src/embedding-sdk-bundle/components/public/MetabotQuestion/QuestionDetails.tsx
rename to enterprise/frontend/src/embedding-sdk-ee/metabot/QuestionDetails.tsx
diff --git a/enterprise/frontend/src/embedding-sdk-bundle/components/public/MetabotQuestion/QuestionTitle.tsx b/enterprise/frontend/src/embedding-sdk-ee/metabot/QuestionTitle.tsx
similarity index 100%
rename from enterprise/frontend/src/embedding-sdk-bundle/components/public/MetabotQuestion/QuestionTitle.tsx
rename to enterprise/frontend/src/embedding-sdk-ee/metabot/QuestionTitle.tsx
diff --git a/enterprise/frontend/src/embedding-sdk-bundle/components/public/MetabotQuestion/SidebarHeader.tsx b/enterprise/frontend/src/embedding-sdk-ee/metabot/SidebarHeader.tsx
similarity index 100%
rename from enterprise/frontend/src/embedding-sdk-bundle/components/public/MetabotQuestion/SidebarHeader.tsx
rename to enterprise/frontend/src/embedding-sdk-ee/metabot/SidebarHeader.tsx
diff --git a/enterprise/frontend/src/embedding-sdk-ee/metabot/index.ts b/enterprise/frontend/src/embedding-sdk-ee/metabot/index.ts
new file mode 100644
index 00000000000..ed39a678ad4
--- /dev/null
+++ b/enterprise/frontend/src/embedding-sdk-ee/metabot/index.ts
@@ -0,0 +1,5 @@
+// Contains side effects that activate the plugin
+import "./MetabotQuestion";
+
+// the types are in the OSS code, but we're re-exporting them here for convenience to not have to import from two places
+export type { MetabotQuestionProps } from "embedding-sdk-bundle/components/public/MetabotQuestion/types";
diff --git a/enterprise/frontend/src/embedding-sdk-package/index.ts b/enterprise/frontend/src/embedding-sdk-package/index.ts
index 5f8f52310ea..67db58bbc76 100644
--- a/enterprise/frontend/src/embedding-sdk-package/index.ts
+++ b/enterprise/frontend/src/embedding-sdk-package/index.ts
@@ -122,13 +122,12 @@ export type {
SqlParameterValues,
} from "embedding-sdk-bundle/types";
-export type {
- UserBackendJwtResponse,
- MetabaseFetchRequestTokenFn,
- MetabaseEmbeddingSessionToken,
-} from "embedding-sdk-bundle/types/refresh-token";
-
export type { EmbeddingEntityType } from "metabase-types/store/embedding-data-picker";
export type { ParameterValues } from "metabase/embedding-sdk/types/dashboard";
export type { IconName } from "metabase/embedding-sdk/types/icon";
+
+export type {
+ UserBackendJwtResponse,
+ MetabaseFetchRequestTokenFn,
+} from "metabase/embedding-sdk/types/refresh-token";
diff --git a/enterprise/frontend/src/embedding/auth-common/index.ts b/enterprise/frontend/src/embedding/auth-common/index.ts
index 9740c31db44..ecc15a199f7 100644
--- a/enterprise/frontend/src/embedding/auth-common/index.ts
+++ b/enterprise/frontend/src/embedding/auth-common/index.ts
@@ -2,4 +2,3 @@ export { connectToInstanceAuthSso } from "./connect-to-instance-auth-sso";
export { jwtDefaultRefreshTokenFunction } from "./jwt";
export { openSamlLoginPopup } from "./saml";
export { validateSession } from "./validate-session-token";
-export { samlTokenStorage } from "./saml-token-storage";
diff --git a/enterprise/frontend/src/embedding/auth-common/saml.ts b/enterprise/frontend/src/embedding/auth-common/saml.ts
index 8b3038844f9..7c16be9a654 100644
--- a/enterprise/frontend/src/embedding/auth-common/saml.ts
+++ b/enterprise/frontend/src/embedding/auth-common/saml.ts
@@ -1,5 +1,6 @@
import * as MetabaseError from "embedding-sdk-bundle/errors";
-import type { MetabaseEmbeddingSessionToken } from "embedding-sdk-bundle/types/refresh-token";
+// eslint-disable-next-line no-restricted-imports -- import type
+import type { MetabaseEmbeddingSessionToken } from "metabase/embedding-sdk/types/refresh-token";
/*
* For the markup for the popup (nice rhyme), visit
diff --git a/enterprise/frontend/src/metabase-enterprise/embedding_iframe_sdk/types/embed.ts b/enterprise/frontend/src/metabase-enterprise/embedding_iframe_sdk/types/embed.ts
index 4e3b08bac06..b57bfa73ae2 100644
--- a/enterprise/frontend/src/metabase-enterprise/embedding_iframe_sdk/types/embed.ts
+++ b/enterprise/frontend/src/metabase-enterprise/embedding_iframe_sdk/types/embed.ts
@@ -1,10 +1,6 @@
import type { MetabaseError } from "embedding-sdk-bundle/errors";
import type { MetabaseErrorCode } from "embedding-sdk-bundle/errors/error-code";
import type { MetabaseAuthMethod } from "embedding-sdk-bundle/types";
-import type {
- MetabaseEmbeddingSessionToken,
- MetabaseFetchRequestTokenFn,
-} from "embedding-sdk-bundle/types/refresh-token";
import type {
CollectionBrowserListColumns,
EmbeddingEntityType,
@@ -13,6 +9,10 @@ import type {
SqlParameterValues,
} from "embedding-sdk-package";
import type { ParameterValues } from "metabase/embedding-sdk/types/dashboard";
+import type {
+ MetabaseEmbeddingSessionToken,
+ MetabaseFetchRequestTokenFn,
+} from "metabase/embedding-sdk/types/refresh-token";
import type { EmbeddedAnalyticsJsEventSchema } from "metabase-types/analytics/embedded-analytics-js";
import type { CollectionId } from "metabase-types/api";
diff --git a/enterprise/frontend/src/metabase-enterprise/embedding_iframe_sdk/utils/request-session-token.ts b/enterprise/frontend/src/metabase-enterprise/embedding_iframe_sdk/utils/request-session-token.ts
index 9685dada7d7..a39f8e0a2b2 100644
--- a/enterprise/frontend/src/metabase-enterprise/embedding_iframe_sdk/utils/request-session-token.ts
+++ b/enterprise/frontend/src/metabase-enterprise/embedding_iframe_sdk/utils/request-session-token.ts
@@ -1,6 +1,6 @@
-import { samlTokenStorage } from "embedding/auth-common";
import { AUTH_TIMEOUT } from "embedding-sdk-bundle/errors";
-import type { MetabaseEmbeddingSessionToken } from "embedding-sdk-bundle/types/refresh-token";
+import { samlTokenStorage } from "metabase/embedding-sdk/lib/saml-token-storage";
+import type { MetabaseEmbeddingSessionToken } from "metabase/embedding-sdk/types/refresh-token";
import { isWithinIframe } from "metabase/lib/dom";
import { WAIT_FOR_SESSION_TOKEN_TIMEOUT } from "../constants";
diff --git a/enterprise/frontend/src/metabase-enterprise/sdk-plugins.ts b/enterprise/frontend/src/metabase-enterprise/sdk-plugins.ts
index 9dd0b86b72f..d61a072672d 100644
--- a/enterprise/frontend/src/metabase-enterprise/sdk-plugins.ts
+++ b/enterprise/frontend/src/metabase-enterprise/sdk-plugins.ts
@@ -5,7 +5,7 @@ PLUGIN_IS_EE_BUILD.isEEBuild = () => true;
import "./shared";
-// SDK PLUGINS THAT USE hasPremiumFeature (import initialization functions):
+// CORE APP PLUGINS THAT USE hasPremiumFeature (import initialization functions):
import { initializePlugin as initializeEmbedding } from "./embedding";
import { initializePlugin as initializeEmbeddingSdk } from "./embedding-sdk";
import { initializePlugin as initializeMetabot } from "./metabot";
@@ -23,3 +23,8 @@ export function initializePlugins() {
initializeWhitelabelPlugin?.();
initializeWhitelabelOverridePlugin?.();
}
+
+// "SDK EE-plugins", that are specific to the embedding sdk.
+// These only apply to the SDK, not to the core app
+import "../embedding-sdk-ee/auth";
+import "../embedding-sdk-ee/metabot";
diff --git a/enterprise/frontend/src/embedding/auth-common/saml-token-storage.ts b/frontend/src/metabase/embedding-sdk/lib/saml-token-storage.ts
similarity index 91%
rename from enterprise/frontend/src/embedding/auth-common/saml-token-storage.ts
rename to frontend/src/metabase/embedding-sdk/lib/saml-token-storage.ts
index 468fabfaa53..e30ddcd4401 100644
--- a/enterprise/frontend/src/embedding/auth-common/saml-token-storage.ts
+++ b/frontend/src/metabase/embedding-sdk/lib/saml-token-storage.ts
@@ -1,4 +1,4 @@
-import type { MetabaseEmbeddingSessionToken } from "embedding-sdk-bundle/types/refresh-token";
+import type { MetabaseEmbeddingSessionToken } from "metabase/embedding-sdk/types/refresh-token";
class TypedStorage<T> {
constructor(private key: string) {}
diff --git a/enterprise/frontend/src/embedding-sdk-bundle/types/refresh-token.ts b/frontend/src/metabase/embedding-sdk/types/refresh-token.ts
similarity index 100%
rename from enterprise/frontend/src/embedding-sdk-bundle/types/refresh-token.ts
rename to frontend/src/metabase/embedding-sdk/types/refresh-token.ts