The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
feat(sdk): Use `zod` schemas to validate exposed from SDK bundle Components and their props (#63188)
Timofey Kachalov0e42be191403
diff --git a/docs/embedding/sdk/next-js.md b/docs/embedding/sdk/next-js.mdindex 3983aa636cf..a42d8e8ebe4 100644--- a/docs/embedding/sdk/next-js.md+++ b/docs/embedding/sdk/next-js.md@@ -14,11 +14,11 @@ See a [sample Next.js app that uses the SDK](https://github.com/metabase/metabas## SDK components with Server Side Rendering (SSR) or React Server Components-As of Embedding Analytics SDK v57, SDK components automatically skip server-side rendering (SSR) and render only on the client.+As of Embedded Analytics SDK v57, SDK components automatically skip server-side rendering (SSR) and render only on the client.### Compatibility layer for Server Side Rendering (SSR) (DEPRECATED)-As of Embedding analytics SDK 57, the compatibility layer for server-side rendering (SSR) is deprecated and no longer required. If you use the compatibility layer, change your imports from `@metabase/embedding-sdk-react/next` to `@metabase/embedding-sdk-react`.+As of Embedded Analytics SDK 57, the compatibility layer for server-side rendering (SSR) is deprecated and no longer required. If you use the compatibility layer, change your imports from `@metabase/embedding-sdk-react/next` to `@metabase/embedding-sdk-react`.## Handling authenticationdiff --git a/e2e/test-component/scenarios/embedding-sdk/sdk-bundle.cy.spec.tsx b/e2e/test-component/scenarios/embedding-sdk/sdk-bundle.cy.spec.tsxindex 2f64aab30fc..d5b7e20fa07 100644--- a/e2e/test-component/scenarios/embedding-sdk/sdk-bundle.cy.spec.tsx+++ b/e2e/test-component/scenarios/embedding-sdk/sdk-bundle.cy.spec.tsx@@ -43,10 +43,6 @@ describe([{ strictMode: false }, { strictMode: true }].forEach(({ strictMode }) => {describe(`Common cases ${strictMode ? "with" : "without"} strict mode`, () => {it("should display an SDK question", () => {- cy.window().then((win) => {- cy.spy(win.console, "warn").as("consoleWarn");- });-mountSdkContent(<InteractiveQuestion questionId={ORDERS_QUESTION_ID} />,{ strictMode },@@ -291,7 +287,7 @@ describe(describe("Components", () => {it("should display an SDK question with custom layout components", () => {cy.window().then((win) => {- cy.spy(win.console, "warn").as("consoleWarn");+ cy.spy(win.console, "error").as("consoleError");});mountSdkContent(@@ -309,15 +305,13 @@ describe(cy.findByTestId("visualization-root").should("be.visible");});++ cy.get("@consoleError").should("not.be.called");});it("should show an error on a component level if SDK components are not wrapped within the MetabaseProvider", () => {sdkBundleCleanup();- cy.window().then((win) => {- cy.spy(win.console, "warn").as("consoleWarn");- });-cy.mount(<InteractiveQuestion questionId={ORDERS_QUESTION_ID} />);getSdkRoot().within(() => {@@ -326,6 +320,41 @@ describe().should("exist");});});++ it("should show a console error if SDK Package component uses a prop that is not yet available in SDK bundle", () => {+ sdkBundleCleanup();++ cy.window().then((win) => {+ cy.spy(win.console, "error").as("consoleError");+ });++ mountSdkContent(+ <InteractiveQuestion+ questionId={ORDERS_QUESTION_ID}+ {...{ foo: "bar" }}+ />,+ );++ cy.get("@consoleError").should(+ "be.calledWithMatch",+ "this property is not recognized by the component",+ );+ });++ it("should show a console error if SDK Package component does not use a prop that is still expected by SDK bundle", () => {+ sdkBundleCleanup();++ cy.window().then((win) => {+ cy.spy(win.console, "error").as("consoleError");+ });++ mountSdkContent(<InteractiveQuestion />);++ cy.get("@consoleError").should(+ "be.calledWithMatch",+ "this property is required by the component",+ );+ });});describe("Error handling", { retries: 3 }, () => {@@ -350,7 +379,7 @@ describe(cy.findByTestId("sdk-error-container").should("contain.text",- "Error loading the Embedding Analytics SDK",+ "Error loading the Embedded Analytics SDK",);});@@ -369,7 +398,7 @@ describe(cy.findByTestId("sdk-error-container").should("contain.text",- "Custom error: Error loading the Embedding Analytics SDK",+ "Custom error: Error loading the Embedded Analytics SDK",);});});diff --git a/enterprise/frontend/src/.eslintrc.js b/enterprise/frontend/src/.eslintrc.jsindex 0e922bd1f58..566f7b41028 100644--- a/enterprise/frontend/src/.eslintrc.js+++ b/enterprise/frontend/src/.eslintrc.js@@ -58,6 +58,10 @@ module.exports = {...baseRestrictredConfig,paths: [...baseRestrictredConfig.paths,+ {+ name: "zod",+ message: "Please import from `zod/mini` instead.",+ },{name: "metabase/lib/redux",importNames: ["useStore", "useDispatch"],diff --git a/enterprise/frontend/src/embedding-sdk-bundle/components/public/CollectionBrowser/CollectionBrowser.schema.ts b/enterprise/frontend/src/embedding-sdk-bundle/components/public/CollectionBrowser/CollectionBrowser.schema.tsnew file mode 100644index 00000000000..1238c8defe0--- /dev/null+++ b/enterprise/frontend/src/embedding-sdk-bundle/components/public/CollectionBrowser/CollectionBrowser.schema.ts@@ -0,0 +1,30 @@+import {+ any,+ function as functionSchema,+ optional,+ strictObject,+} from "zod/mini";+import type { infer as zInfer } from "zod/v4/core/core";++import type { ValidateInferredSchema } from "embedding-sdk-bundle/types/schema";++import type { CollectionBrowserProps } from "./CollectionBrowser";++const rawPropsSchema = strictObject({+ EmptyContentComponent: optional(any()),+ className: optional(any()),+ collectionId: optional(any()),+ onClick: optional(any()),+ pageSize: optional(any()),+ style: optional(any()),+ visibleColumns: optional(any()),+ visibleEntityTypes: optional(any()),+});+const propsSchema: ValidateInferredSchema<+ CollectionBrowserProps,+ zInfer<typeof rawPropsSchema>+> = rawPropsSchema;++export const collectionBrowserPropsSchema = functionSchema({+ input: [propsSchema],+});diff --git a/enterprise/frontend/src/embedding-sdk-bundle/components/public/CollectionBrowser/CollectionBrowser.tsx b/enterprise/frontend/src/embedding-sdk-bundle/components/public/CollectionBrowser/CollectionBrowser.tsxindex f8319c57823..fa7abe47f61 100644--- a/enterprise/frontend/src/embedding-sdk-bundle/components/public/CollectionBrowser/CollectionBrowser.tsx+++ b/enterprise/frontend/src/embedding-sdk-bundle/components/public/CollectionBrowser/CollectionBrowser.tsx@@ -22,6 +22,8 @@ import CollectionBreadcrumbs from "metabase/nav/containers/CollectionBreadcrumbsimport { Stack } from "metabase/ui";import type { CollectionId, CollectionItemModel } from "metabase-types/api";+import { collectionBrowserPropsSchema } from "./CollectionBrowser.schema";+const USER_FACING_ENTITY_NAMES = ["collection","dashboard",@@ -200,6 +202,7 @@ const CollectionBrowserWrapper = ({return <CollectionBrowserInner collectionId={collectionId} {...restProps} />;};-export const CollectionBrowser = withPublicComponentWrapper(- CollectionBrowserWrapper,+export const CollectionBrowser = Object.assign(+ withPublicComponentWrapper(CollectionBrowserWrapper),+ { schema: collectionBrowserPropsSchema },);diff --git a/enterprise/frontend/src/embedding-sdk-bundle/components/public/CreateDashboardModal/CreateDashboardModal.schema.ts b/enterprise/frontend/src/embedding-sdk-bundle/components/public/CreateDashboardModal/CreateDashboardModal.schema.tsnew file mode 100644index 00000000000..14cb6337afd--- /dev/null+++ b/enterprise/frontend/src/embedding-sdk-bundle/components/public/CreateDashboardModal/CreateDashboardModal.schema.ts@@ -0,0 +1,27 @@+import {+ any,+ function as functionSchema,+ nonoptional,+ optional,+ strictObject,+} from "zod/mini";+import type { infer as zInfer } from "zod/v4/core/core";++import type { ValidateInferredSchema } from "embedding-sdk-bundle/types/schema";++import type { CreateDashboardModalProps } from "./CreateDashboardModal";++const rawPropsSchema = strictObject({+ initialCollectionId: optional(any()),+ isOpen: optional(any()),+ onClose: optional(any()),+ onCreate: nonoptional(any()),+});+const propsSchema: ValidateInferredSchema<+ CreateDashboardModalProps,+ zInfer<typeof rawPropsSchema>+> = rawPropsSchema;++export const createDashboardModalSchema = functionSchema({+ input: [propsSchema],+});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.tsxindex c92794c7c8e..766035470ea 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@@ -8,6 +8,8 @@ import { useCollectionQuery, useLocale } from "metabase/common/hooks";import { CreateDashboardModal as CreateDashboardModalCore } from "metabase/dashboard/containers/CreateDashboardModal";import { useSelector } from "metabase/lib/redux";+import { createDashboardModalSchema } from "./CreateDashboardModal.schema";+/*** @expand* @category CreateDashboardModal@@ -68,6 +70,7 @@ const CreateDashboardModalInner = ({);};-export const CreateDashboardModal = withPublicComponentWrapper(- CreateDashboardModalInner,+export const CreateDashboardModal = Object.assign(+ withPublicComponentWrapper(CreateDashboardModalInner),+ { schema: createDashboardModalSchema },);diff --git a/enterprise/frontend/src/embedding-sdk-bundle/components/public/InteractiveQuestion/InteractiveQuestion.schema.ts b/enterprise/frontend/src/embedding-sdk-bundle/components/public/InteractiveQuestion/InteractiveQuestion.schema.tsnew file mode 100644index 00000000000..f4fcc67b5a9--- /dev/null+++ b/enterprise/frontend/src/embedding-sdk-bundle/components/public/InteractiveQuestion/InteractiveQuestion.schema.ts@@ -0,0 +1,56 @@+import {+ any,+ function as functionSchema,+ nonoptional,+ optional,+ strictObject,+ type infer as zInfer,+} from "zod/mini";++import type { ValidateInferredSchema } from "embedding-sdk-bundle/types/schema";++import type { InteractiveQuestionProps } from "./InteractiveQuestion";++const rawPropsSchema = strictObject({+ children: optional(any()),+ className: optional(any()),+ componentPlugins: optional(+ strictObject({+ mapQuestionClickActions: optional(any()),+ dashboard: optional(any()),+ }),+ ),+ deserializedCard: optional(any()),+ entityTypes: optional(any()),+ height: optional(any()),+ initialSqlParameters: optional(any()),+ isSaveEnabled: optional(any()),+ onBeforeSave: optional(any()),+ onNavigateBack: optional(any()),+ onRun: optional(any()),+ onSave: optional(any()),+ options: optional(any()),+ plugins: optional(+ strictObject({+ mapQuestionClickActions: optional(any()),+ dashboard: optional(any()),+ }),+ ),+ questionId: nonoptional(any()),+ style: optional(any()),+ targetCollection: optional(any()),+ targetDashboardId: optional(any()),+ title: optional(any()),+ width: optional(any()),+ withChartTypeSelector: optional(any()),+ withDownloads: optional(any()),+ withResetButton: optional(any()),+});+const propsSchema: ValidateInferredSchema<+ InteractiveQuestionProps,+ zInfer<typeof rawPropsSchema>+> = rawPropsSchema;++export const interactiveQuestionSchema = functionSchema({+ input: [propsSchema],+});diff --git a/enterprise/frontend/src/embedding-sdk-bundle/components/public/InteractiveQuestion/InteractiveQuestion.tsx b/enterprise/frontend/src/embedding-sdk-bundle/components/public/InteractiveQuestion/InteractiveQuestion.tsxindex 129ae3b1b6c..7c5a3cc86f0 100644--- a/enterprise/frontend/src/embedding-sdk-bundle/components/public/InteractiveQuestion/InteractiveQuestion.tsx+++ b/enterprise/frontend/src/embedding-sdk-bundle/components/public/InteractiveQuestion/InteractiveQuestion.tsx@@ -26,6 +26,8 @@ import {type SdkQuestionProps,} from "embedding-sdk-bundle/components/public/SdkQuestion/SdkQuestion";+import { interactiveQuestionSchema } from "./InteractiveQuestion.schema";+/*** @interface* @expand@@ -100,4 +102,5 @@ const subComponents: InteractiveQuestionComponents = {export const InteractiveQuestion = Object.assign(_InteractiveQuestion,subComponents,+ { schema: interactiveQuestionSchema },);diff --git a/enterprise/frontend/src/embedding-sdk-bundle/components/public/MetabotQuestion/MetabotQuestion.schema.ts b/enterprise/frontend/src/embedding-sdk-bundle/components/public/MetabotQuestion/MetabotQuestion.schema.tsnew file mode 100644index 00000000000..310326280ff--- /dev/null+++ b/enterprise/frontend/src/embedding-sdk-bundle/components/public/MetabotQuestion/MetabotQuestion.schema.ts@@ -0,0 +1,5 @@+import { function as functionSchema } from "zod/mini";++export const metabotQuestionSchema = functionSchema({+ input: [],+});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.tsxindex b3766c18214..50e215e8a03 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@@ -19,6 +19,7 @@ import {import { useMetabotReactions } from "metabase-enterprise/metabot/hooks/use-metabot-reactions";import { MetabotChatEmbedding } from "./MetabotChatEmbedding";+import { metabotQuestionSchema } from "./MetabotQuestion.schema";import { QuestionDetails } from "./QuestionDetails";import { QuestionTitle } from "./QuestionTitle";@@ -109,6 +110,7 @@ const MetabotQuestionWrapped = () => {);};-export const MetabotQuestion = withPublicComponentWrapper(- MetabotQuestionWrapped,+export const MetabotQuestion = Object.assign(+ withPublicComponentWrapper(MetabotQuestionWrapped),+ { schema: metabotQuestionSchema },);diff --git a/enterprise/frontend/src/embedding-sdk-bundle/components/public/debug/SdkDebugInfo.module.css b/enterprise/frontend/src/embedding-sdk-bundle/components/public/SdkDebugInfo/SdkDebugInfo.module.csssimilarity index 100%rename from enterprise/frontend/src/embedding-sdk-bundle/components/public/debug/SdkDebugInfo.module.cssrename to enterprise/frontend/src/embedding-sdk-bundle/components/public/SdkDebugInfo/SdkDebugInfo.module.cssdiff --git a/enterprise/frontend/src/embedding-sdk-bundle/components/public/SdkDebugInfo/SdkDebugInfo.schema.ts b/enterprise/frontend/src/embedding-sdk-bundle/components/public/SdkDebugInfo/SdkDebugInfo.schema.tsnew file mode 100644index 00000000000..974a8439184--- /dev/null+++ b/enterprise/frontend/src/embedding-sdk-bundle/components/public/SdkDebugInfo/SdkDebugInfo.schema.ts@@ -0,0 +1,5 @@+import { function as functionSchema } from "zod/mini";++export const sdkDebugInfoSchema = functionSchema({+ input: [],+});diff --git a/enterprise/frontend/src/embedding-sdk-bundle/components/public/debug/SdkDebugInfo.tsx b/enterprise/frontend/src/embedding-sdk-bundle/components/public/SdkDebugInfo/SdkDebugInfo.tsxsimilarity index 91%rename from enterprise/frontend/src/embedding-sdk-bundle/components/public/debug/SdkDebugInfo.tsxrename to enterprise/frontend/src/embedding-sdk-bundle/components/public/SdkDebugInfo/SdkDebugInfo.tsxindex 3e508501ada..8f295e69c51 100644--- a/enterprise/frontend/src/embedding-sdk-bundle/components/public/debug/SdkDebugInfo.tsx+++ b/enterprise/frontend/src/embedding-sdk-bundle/components/public/SdkDebugInfo/SdkDebugInfo.tsx@@ -7,6 +7,7 @@ import { getBuildInfo } from "embedding-sdk-shared/lib/get-build-info";import type { BuildInfo } from "metabase/embedding-sdk/types/build-info";import S from "./SdkDebugInfo.module.css";+import { sdkDebugInfoSchema } from "./SdkDebugInfo.schema";type BuildTimeData = {formattedDate: string;@@ -88,7 +89,7 @@ const DebugTable = ({</table>);-export const SdkDebugInfo = (props: HTMLAttributes<HTMLDivElement>) => {+const SdkDebugInfoInner = (props: HTMLAttributes<HTMLDivElement>) => {const sdkPackageDebugInfoData = getDebugInfoData(getBuildInfo("METABASE_EMBEDDING_SDK_PACKAGE_BUILD_INFO"),);@@ -108,3 +109,7 @@ export const SdkDebugInfo = (props: HTMLAttributes<HTMLDivElement>) => {</div>);};++export const SdkDebugInfo = Object.assign(SdkDebugInfoInner, {+ schema: sdkDebugInfoSchema,+});diff --git a/enterprise/frontend/src/embedding-sdk-bundle/components/public/SdkDebugInfo/index.ts b/enterprise/frontend/src/embedding-sdk-bundle/components/public/SdkDebugInfo/index.tsnew file mode 100644index 00000000000..749474c3a85--- /dev/null+++ b/enterprise/frontend/src/embedding-sdk-bundle/components/public/SdkDebugInfo/index.ts@@ -0,0 +1 @@+export { SdkDebugInfo } from "./SdkDebugInfo";diff --git a/enterprise/frontend/src/embedding-sdk-bundle/components/public/StaticQuestion/StaticQuestion.schema.ts b/enterprise/frontend/src/embedding-sdk-bundle/components/public/StaticQuestion/StaticQuestion.schema.tsnew file mode 100644index 00000000000..637b58eaa16--- /dev/null+++ b/enterprise/frontend/src/embedding-sdk-bundle/components/public/StaticQuestion/StaticQuestion.schema.ts@@ -0,0 +1,33 @@+import {+ any,+ function as functionSchema,+ nonoptional,+ optional,+ strictObject,+} from "zod/mini";+import type { infer as zInfer } from "zod/v4/core/core";++import type { ValidateInferredSchema } from "embedding-sdk-bundle/types/schema";++import type { StaticQuestionProps } from "./StaticQuestion";++const rawPropsSchema = strictObject({+ children: optional(any()),+ className: optional(any()),+ height: optional(any()),+ initialSqlParameters: optional(any()),+ questionId: nonoptional(any()),+ style: optional(any()),+ title: optional(any()),+ width: optional(any()),+ withChartTypeSelector: optional(any()),+ withDownloads: optional(any()),+});+const propsSchema: ValidateInferredSchema<+ StaticQuestionProps,+ zInfer<typeof rawPropsSchema>+> = rawPropsSchema;++export const staticQuestionSchema = functionSchema({+ input: [propsSchema],+});diff --git a/enterprise/frontend/src/embedding-sdk-bundle/components/public/StaticQuestion/StaticQuestion.tsx b/enterprise/frontend/src/embedding-sdk-bundle/components/public/StaticQuestion/StaticQuestion.tsxindex d0680a5ff7c..c3de9dad4be 100644--- a/enterprise/frontend/src/embedding-sdk-bundle/components/public/StaticQuestion/StaticQuestion.tsx+++ b/enterprise/frontend/src/embedding-sdk-bundle/components/public/StaticQuestion/StaticQuestion.tsx@@ -29,6 +29,8 @@ import { getEmbeddingMode } from "metabase/visualizations/click-actions/lib/modeimport type { ClickActionModeGetter } from "metabase/visualizations/types";import type Question from "metabase-lib/v1/Question";+import { staticQuestionSchema } from "./StaticQuestion.schema";+/*** @interface* @expand@@ -152,4 +154,6 @@ const subComponents: StaticQuestionComponents = {DownloadWidgetDropdown: DownloadWidgetDropdown,};-export const StaticQuestion = Object.assign(_StaticQuestion, subComponents);+export const StaticQuestion = Object.assign(_StaticQuestion, subComponents, {+ schema: staticQuestionSchema,+});diff --git a/enterprise/frontend/src/embedding-sdk-bundle/components/public/dashboard/EditableDashboard/EditableDashboard.schema.ts b/enterprise/frontend/src/embedding-sdk-bundle/components/public/dashboard/EditableDashboard/EditableDashboard.schema.tsnew file mode 100644index 00000000000..b700cf4fef0--- /dev/null+++ b/enterprise/frontend/src/embedding-sdk-bundle/components/public/dashboard/EditableDashboard/EditableDashboard.schema.ts@@ -0,0 +1,68 @@+import {+ any,+ function as functionSchema,+ nonoptional,+ optional,+ strictObject,+} from "zod/mini";+import type { infer as zInfer } from "zod/v4/core/core";++import type { ValidateInferredSchema } from "embedding-sdk-bundle/types/schema";++import type { EditableDashboardProps } from "./EditableDashboard";++const rawPropsSchema = strictObject({+ children: optional(any()),+ className: optional(any()),+ dashboardId: nonoptional(any()),+ dataPickerProps: optional(+ strictObject({+ entityTypes: optional(any()),+ }),+ ),+ drillThroughQuestionHeight: optional(any()),+ drillThroughQuestionProps: optional(+ strictObject({+ children: optional(any()),+ className: optional(any()),+ entityTypes: optional(any()),+ height: optional(any()),+ initialSqlParameters: optional(any()),+ isSaveEnabled: optional(any()),+ onBeforeSave: optional(any()),+ onRun: optional(any()),+ onSave: optional(any()),+ plugins: optional(any()),+ style: optional(any()),+ targetCollection: optional(any()),+ title: optional(any()),+ width: optional(any()),+ withChartTypeSelector: optional(any()),+ withDownloads: optional(any()),+ withResetButton: optional(any()),+ }),+ ),+ hiddenParameters: optional(any()),+ initialParameters: optional(any()),+ onLoad: optional(any()),+ onLoadWithoutCards: optional(any()),+ plugins: optional(+ strictObject({+ mapQuestionClickActions: optional(any()),+ dashboard: optional(any()),+ }),+ ),+ renderDrillThroughQuestion: optional(any()),+ style: optional(any()),+ withCardTitle: optional(any()),+ withDownloads: optional(any()),+ withTitle: optional(any()),+});+const propsSchema: ValidateInferredSchema<+ EditableDashboardProps,+ zInfer<typeof rawPropsSchema>+> = rawPropsSchema;++export const editableDashboardSchema = functionSchema({+ input: [propsSchema],+});diff --git a/enterprise/frontend/src/embedding-sdk-bundle/components/public/dashboard/EditableDashboard/EditableDashboard.tsx b/enterprise/frontend/src/embedding-sdk-bundle/components/public/dashboard/EditableDashboard/EditableDashboard.tsxindex ceeac4abbab..5c65b2f94e1 100644--- a/enterprise/frontend/src/embedding-sdk-bundle/components/public/dashboard/EditableDashboard/EditableDashboard.tsx+++ b/enterprise/frontend/src/embedding-sdk-bundle/components/public/dashboard/EditableDashboard/EditableDashboard.tsx@@ -11,6 +11,8 @@ import {type SdkDashboardProps,} from "../SdkDashboard";+import { editableDashboardSchema } from "./EditableDashboard.schema";+/*** @interface* @expand@@ -19,7 +21,7 @@ import {export type EditableDashboardProps = SdkDashboardProps &EditableDashboardOwnProps;-export const EditableDashboard = (props: EditableDashboardProps) => {+export const EditableDashboardInner = (props: EditableDashboardProps) => {const dashboardActions: SdkDashboardInnerProps["dashboardActions"] = ({isEditing,downloadsEnabled,@@ -48,3 +50,7 @@ export const EditableDashboard = (props: EditableDashboardProps) => {/>);};++export const EditableDashboard = Object.assign(EditableDashboardInner, {+ schema: editableDashboardSchema,+});diff --git a/enterprise/frontend/src/embedding-sdk-bundle/components/public/dashboard/InteractiveDashboard/InteractiveDashboard.schema.ts b/enterprise/frontend/src/embedding-sdk-bundle/components/public/dashboard/InteractiveDashboard/InteractiveDashboard.schema.tsnew file mode 100644index 00000000000..51e2057e43f--- /dev/null+++ b/enterprise/frontend/src/embedding-sdk-bundle/components/public/dashboard/InteractiveDashboard/InteractiveDashboard.schema.ts@@ -0,0 +1,68 @@+import {+ any,+ function as functionSchema,+ nonoptional,+ optional,+ strictObject,+} from "zod/mini";+import type { infer as zInfer } from "zod/v4/core/core";++import type { ValidateInferredSchema } from "embedding-sdk-bundle/types/schema";++import type { InteractiveDashboardProps } from "./InteractiveDashboard";++const rawPropsSchema = strictObject({+ children: optional(any()),+ className: optional(any()),+ dashboardId: nonoptional(any()),+ dataPickerProps: optional(+ strictObject({+ entityTypes: optional(any()),+ }),+ ),+ drillThroughQuestionHeight: optional(any()),+ drillThroughQuestionProps: optional(+ strictObject({+ children: optional(any()),+ className: optional(any()),+ entityTypes: optional(any()),+ height: optional(any()),+ initialSqlParameters: optional(any()),+ isSaveEnabled: optional(any()),+ onBeforeSave: optional(any()),+ onRun: optional(any()),+ onSave: optional(any()),+ plugins: optional(any()),+ style: optional(any()),+ targetCollection: optional(any()),+ title: optional(any()),+ width: optional(any()),+ withChartTypeSelector: optional(any()),+ withDownloads: optional(any()),+ withResetButton: optional(any()),+ }),+ ),+ hiddenParameters: optional(any()),+ initialParameters: optional(any()),+ onLoad: optional(any()),+ onLoadWithoutCards: optional(any()),+ plugins: optional(+ strictObject({+ mapQuestionClickActions: optional(any()),+ dashboard: optional(any()),+ }),+ ),+ renderDrillThroughQuestion: optional(any()),+ style: optional(any()),+ withCardTitle: optional(any()),+ withDownloads: optional(any()),+ withTitle: optional(any()),+});+const propsSchema: ValidateInferredSchema<+ InteractiveDashboardProps,+ zInfer<typeof rawPropsSchema>+> = rawPropsSchema;++export const interactiveDashboardSchema = functionSchema({+ input: [propsSchema],+});diff --git a/enterprise/frontend/src/embedding-sdk-bundle/components/public/dashboard/InteractiveDashboard/InteractiveDashboard.tsx b/enterprise/frontend/src/embedding-sdk-bundle/components/public/dashboard/InteractiveDashboard/InteractiveDashboard.tsxindex f3e06fdcbd6..2732e09b487 100644--- a/enterprise/frontend/src/embedding-sdk-bundle/components/public/dashboard/InteractiveDashboard/InteractiveDashboard.tsx+++ b/enterprise/frontend/src/embedding-sdk-bundle/components/public/dashboard/InteractiveDashboard/InteractiveDashboard.tsx@@ -10,6 +10,8 @@ import type { ClickActionModeGetter } from "metabase/visualizations/types";import { SdkDashboard, type SdkDashboardProps } from "../SdkDashboard";+import { interactiveDashboardSchema } from "./InteractiveDashboard.schema";+/*** @interface* @expand@@ -17,7 +19,7 @@ import { SdkDashboard, type SdkDashboardProps } from "../SdkDashboard";*/export type InteractiveDashboardProps = SdkDashboardProps;-export const InteractiveDashboard = (props: InteractiveDashboardProps) => {+const InteractiveDashboardInner = (props: InteractiveDashboardProps) => {const getClickActionMode: ClickActionModeGetter = useCallback(({ question }) =>getEmbeddingMode({@@ -46,3 +48,7 @@ export const InteractiveDashboard = (props: InteractiveDashboardProps) => {/>);};++export const InteractiveDashboard = Object.assign(InteractiveDashboardInner, {+ schema: interactiveDashboardSchema,+});diff --git a/enterprise/frontend/src/embedding-sdk-bundle/components/public/dashboard/StaticDashboard/StaticDashboard.schema.ts b/enterprise/frontend/src/embedding-sdk-bundle/components/public/dashboard/StaticDashboard/StaticDashboard.schema.tsnew file mode 100644index 00000000000..3012de8efc4--- /dev/null+++ b/enterprise/frontend/src/embedding-sdk-bundle/components/public/dashboard/StaticDashboard/StaticDashboard.schema.ts@@ -0,0 +1,45 @@+import {+ any,+ function as functionSchema,+ nonoptional,+ optional,+ strictObject,+} from "zod/mini";+import type { infer as zInfer } from "zod/v4/core/core";++import type { ValidateInferredSchema } from "embedding-sdk-bundle/types/schema";++import type { StaticDashboardProps } from "./StaticDashboard";++const rawPropsSchema = strictObject({+ children: optional(any()),+ className: optional(any()),+ dashboardId: nonoptional(any()),+ dataPickerProps: optional(+ strictObject({+ entityTypes: optional(any()),+ }),+ ),+ hiddenParameters: optional(any()),+ initialParameters: optional(any()),+ onLoad: optional(any()),+ onLoadWithoutCards: optional(any()),+ plugins: optional(+ strictObject({+ mapQuestionClickActions: optional(any()),+ dashboard: optional(any()),+ }),+ ),+ style: optional(any()),+ withCardTitle: optional(any()),+ withDownloads: optional(any()),+ withTitle: optional(any()),+});+const propsSchema: ValidateInferredSchema<+ StaticDashboardProps,+ zInfer<typeof rawPropsSchema>+> = rawPropsSchema;++export const staticDashboardSchema = functionSchema({+ input: [propsSchema],+});diff --git a/enterprise/frontend/src/embedding-sdk-bundle/components/public/dashboard/StaticDashboard/StaticDashboard.tsx b/enterprise/frontend/src/embedding-sdk-bundle/components/public/dashboard/StaticDashboard/StaticDashboard.tsxindex 92bb581c80e..50b8ed17c78 100644--- a/enterprise/frontend/src/embedding-sdk-bundle/components/public/dashboard/StaticDashboard/StaticDashboard.tsx+++ b/enterprise/frontend/src/embedding-sdk-bundle/components/public/dashboard/StaticDashboard/StaticDashboard.tsx@@ -7,14 +7,21 @@ import type { ClickActionModeGetter } from "metabase/visualizations/types";import { StaticQuestionSdkMode } from "../../StaticQuestion/mode";import { SdkDashboard, type SdkDashboardProps } from "../SdkDashboard";+import { staticDashboardSchema } from "./StaticDashboard.schema";+/*** @interface* @expand* @category Dashboard*/-export type StaticDashboardProps = SdkDashboardProps;+export type StaticDashboardProps = Omit<+ SdkDashboardProps,+ | "drillThroughQuestionProps"+ | "drillThroughQuestionHeight"+ | "renderDrillThroughQuestion"+>;-export const StaticDashboard = (props: StaticDashboardProps) => {+const StaticDashboardInner = (props: StaticDashboardProps) => {const getClickActionMode: ClickActionModeGetter = ({ question }) =>getEmbeddingMode({question,@@ -40,3 +47,7 @@ export const StaticDashboard = (props: StaticDashboardProps) => {/>);};++export const StaticDashboard = Object.assign(StaticDashboardInner, {+ schema: staticDashboardSchema,+});diff --git a/enterprise/frontend/src/embedding-sdk-bundle/index.ts b/enterprise/frontend/src/embedding-sdk-bundle/index.tsindex f26e69d33cb..be7dbcb5eed 100644--- a/enterprise/frontend/src/embedding-sdk-bundle/index.ts+++ b/enterprise/frontend/src/embedding-sdk-bundle/index.ts@@ -29,7 +29,7 @@ import {InteractiveDashboard,StaticDashboard,} from "./components/public/dashboard";-import { SdkDebugInfo } from "./components/public/debug/SdkDebugInfo";+import { SdkDebugInfo } from "./components/public/SdkDebugInfo";import { getApplicationName } from "metabase/selectors/whitelabel";import { getSdkStore } from "./store/index";import {@@ -41,6 +41,7 @@ import { useInitData } from "./hooks/private/use-init-data";import { useLogVersionInfo } from "embedding-sdk-bundle/hooks/private/use-log-version-info";import { createDashboard } from "embedding-sdk-bundle/lib/create-dashboard";import { defineBuildInfo } from "metabase/embedding-sdk/lib/define-build-info";+import { validateFunctionSchema } from "embedding-sdk-bundle/lib/validate-function-schema";defineBuildInfo("METABASE_EMBEDDING_SDK_BUNDLE_BUILD_INFO");@@ -69,6 +70,7 @@ const sdkBundleExports: MetabaseEmbeddingSdkBundleExports = {getUser,useInitData,useLogVersionInfo,+ validateFunctionSchema,};window.METABASE_EMBEDDING_SDK_BUNDLE = sdkBundleExports;diff --git a/enterprise/frontend/src/embedding-sdk-bundle/lib/validate-function-schema.ts b/enterprise/frontend/src/embedding-sdk-bundle/lib/validate-function-schema.tsnew file mode 100644index 00000000000..abfb28c1c62--- /dev/null+++ b/enterprise/frontend/src/embedding-sdk-bundle/lib/validate-function-schema.ts@@ -0,0 +1,105 @@+import type { ZodMiniFunction, ZodMiniTuple, core } from "zod/mini";+import { safeParse } from "zod/mini";++import type {+ FunctionParametersSchemaValidationErrorMetadata,+ FunctionSchemaValidationResult,+ SchemaValidationErrorMetadata,+} from "embedding-sdk-shared/types/validation";++type FunctionSchema = ZodMiniFunction<ZodMiniTuple<any, null> | never, any>;++const getErrorMetadata = <+ TMetadata extends+ | SchemaValidationErrorMetadata+ | FunctionParametersSchemaValidationErrorMetadata,+>({+ error,+ parameterIndex,+}: {+ error: core.$ZodError;+ parameterIndex?: number;+}): TMetadata | null => {+ for (const issue of error.issues) {+ switch (issue.code) {+ case "invalid_type":+ if (issue.expected !== "nonoptional") {+ break;+ }++ return {+ errorCode: "missing_required_property",+ data: issue.path[0]?.toString() ?? "",+ parameterIndex,+ } as TMetadata;+ case "unrecognized_keys":+ return {+ errorCode: "unrecognized_keys",+ data: issue.keys[0]?.toString() ?? "",+ parameterIndex,+ } as TMetadata;+ }+ }++ return null;+};++export const validateFunctionSchema = <+ TSchema extends FunctionSchema,+ TParameters extends unknown[],+ TReturnValue,+>(+ schema: TSchema,+): FunctionSchemaValidationResult<TParameters, TReturnValue> => {+ const parameterSchemas = schema.def.input.def.items;+ const returnValueSchema = schema.def.output.def;++ const validateParameters = (parameters: TParameters) => {+ for (let i = 0; i < parameterSchemas.length; i++) {+ const parameter = parameters[i];+ const parameterSchema = parameterSchemas[i];++ const parseResult = safeParse(parameterSchema, parameter);++ if (!parseResult.success) {+ const errorMetadata =+ getErrorMetadata<FunctionParametersSchemaValidationErrorMetadata>({+ error: parseResult.error,+ parameterIndex: i,+ });++ if (errorMetadata) {+ return {+ success: false,+ errorMetadata,+ };+ }+ }+ }++ return { success: true };+ };+ const validateReturnValue = (returnValue: TReturnValue) => {+ const parseResult = safeParse(returnValueSchema, returnValue);++ if (!parseResult.success) {+ const errorMetadata = getErrorMetadata<SchemaValidationErrorMetadata>({+ error: parseResult.error,+ });++ if (errorMetadata) {+ return {+ success: false,+ errorMetadata,+ };+ }+ }++ return { success: true };+ };++ return {+ validateParameters,+ validateReturnValue,+ };+};diff --git a/enterprise/frontend/src/embedding-sdk-bundle/types/schema.ts b/enterprise/frontend/src/embedding-sdk-bundle/types/schema.tsnew file mode 100644index 00000000000..204ad3cb675--- /dev/null+++ b/enterprise/frontend/src/embedding-sdk-bundle/types/schema.ts@@ -0,0 +1,19 @@+type ValidateTypeAgainstInferredSchema<TType, TSchemaInferType> =+ Required<TType> extends Required<TSchemaInferType>+ ? TType+ : Required<TSchemaInferType>;++type ValidateInferredSchemaAgainstType<TType, TSchemaInferType> =+ Required<TSchemaInferType> extends Required<TType>+ ? TSchemaInferType+ : Required<TType>;++export type ValidateInferredSchema<+ TType extends ValidateTypeAgainstInferredSchema<_TType, _TSchemaInferType>,+ TSchemaInferType extends ValidateInferredSchemaAgainstType<+ _TType,+ _TSchemaInferType+ >,+ _TType = TType,+ _TSchemaInferType = TSchemaInferType,+> = any;diff --git a/enterprise/frontend/src/embedding-sdk-bundle/types/sdk-bundle.ts b/enterprise/frontend/src/embedding-sdk-bundle/types/sdk-bundle.tsindex e4246b59c5b..a4dc5ef0a56 100644--- a/enterprise/frontend/src/embedding-sdk-bundle/types/sdk-bundle.ts+++ b/enterprise/frontend/src/embedding-sdk-bundle/types/sdk-bundle.ts@@ -1,22 +1,27 @@+import type { JSXElementConstructor } from "react";+import type { CollectionBrowser } from "embedding-sdk-bundle/components/public/CollectionBrowser";import type { ComponentProvider } from "embedding-sdk-bundle/components/public/ComponentProvider";import type { CreateDashboardModal } from "embedding-sdk-bundle/components/public/CreateDashboardModal";import type { CreateQuestion } from "embedding-sdk-bundle/components/public/CreateQuestion";import type { InteractiveQuestion } from "embedding-sdk-bundle/components/public/InteractiveQuestion/InteractiveQuestion";import type { MetabotQuestion } from "embedding-sdk-bundle/components/public/MetabotQuestion";+import type { SdkDebugInfo } from "embedding-sdk-bundle/components/public/SdkDebugInfo/SdkDebugInfo";import type { StaticQuestion } from "embedding-sdk-bundle/components/public/StaticQuestion/StaticQuestion";import type { EditableDashboard } from "embedding-sdk-bundle/components/public/dashboard/EditableDashboard";import type { InteractiveDashboard } from "embedding-sdk-bundle/components/public/dashboard/InteractiveDashboard";import type { StaticDashboard } from "embedding-sdk-bundle/components/public/dashboard/StaticDashboard";-import type { SdkDebugInfo } from "embedding-sdk-bundle/components/public/debug/SdkDebugInfo";import type { SdkStore, SdkStoreState } from "embedding-sdk-bundle/store/types";-import type { LoginStatus } from "embedding-sdk-bundle/types/user";import type {CreateDashboardValues,MetabaseDashboard,-} from "embedding-sdk-package";+} from "embedding-sdk-bundle/types";+import type { LoginStatus } from "embedding-sdk-bundle/types/user";+import type { FunctionSchemaValidationResult } from "embedding-sdk-shared/types/validation";import type { User } from "metabase-types/api";+export type InternalComponent<TComponent extends JSXElementConstructor<any>> =+ TComponent & { schema?: any };type InternalHook = () => void;type ReduxStoreFactory = () => SdkStore;type ReduxStoreSelector<T> = (state: SdkStoreState) => T;@@ -33,33 +38,34 @@ export type MetabaseEmbeddingSdkBundleExports = PublicExports &ReduxStoreExports &ReduxStoreUtilityFunctionExports &ReduxStoreSelectorsExports &- InternalHooksExports;+ InternalHooksExports &+ SchemaValidationUtils;-type PublicExports = {- CollectionBrowser: typeof CollectionBrowser;- CreateDashboardModal: typeof CreateDashboardModal;- CreateQuestion: typeof CreateQuestion;- EditableDashboard: typeof EditableDashboard;- InteractiveDashboard: typeof InteractiveDashboard;- InteractiveQuestion: typeof InteractiveQuestion;- ComponentProvider: typeof ComponentProvider;- MetabotQuestion: typeof MetabotQuestion;- SdkDebugInfo: typeof SdkDebugInfo;- StaticDashboard: typeof StaticDashboard;- StaticQuestion: typeof StaticQuestion;+export type PublicExports = {+ CollectionBrowser: InternalComponent<typeof CollectionBrowser>;+ CreateDashboardModal: InternalComponent<typeof CreateDashboardModal>;+ CreateQuestion: InternalComponent<typeof CreateQuestion>;+ EditableDashboard: InternalComponent<typeof EditableDashboard>;+ InteractiveDashboard: InternalComponent<typeof InteractiveDashboard>;+ InteractiveQuestion: InternalComponent<typeof InteractiveQuestion>;+ ComponentProvider: InternalComponent<typeof ComponentProvider>;+ MetabotQuestion: InternalComponent<typeof MetabotQuestion>;+ SdkDebugInfo: InternalComponent<typeof SdkDebugInfo>;+ StaticDashboard: InternalComponent<typeof StaticDashboard>;+ StaticQuestion: InternalComponent<typeof StaticQuestion>;};-type ReduxStoreExports = {+export type ReduxStoreExports = {getSdkStore: ReduxStoreFactory;};-type ReduxStoreUtilityFunctionExports = {+export type ReduxStoreUtilityFunctionExports = {createDashboard: ReduxStoreUtilityFunction<(params: CreateDashboardValues) => Promise<MetabaseDashboard>>;};-type ReduxStoreSelectorsExports = {+export type ReduxStoreSelectorsExports = {getApplicationName: ReduxStoreSelector<string>;getAvailableFonts: ReduxStoreSelector<string[]>;getLoginStatus: ReduxStoreSelector<LoginStatus>;@@ -70,3 +76,9 @@ export type InternalHooksExports = {useInitData: InternalHook;useLogVersionInfo: InternalHook;};++export type SchemaValidationUtils = {+ validateFunctionSchema: (+ schema: any,+ ) => FunctionSchemaValidationResult<unknown[], unknown>;+};diff --git a/enterprise/frontend/src/embedding-sdk-package/components/private/ComponentWrapper/ComponentWrapper.tsx b/enterprise/frontend/src/embedding-sdk-package/components/private/ComponentWrapper/ComponentWrapper.tsxindex fb3428827d9..29aab070ff5 100644--- a/enterprise/frontend/src/embedding-sdk-package/components/private/ComponentWrapper/ComponentWrapper.tsx+++ b/enterprise/frontend/src/embedding-sdk-package/components/private/ComponentWrapper/ComponentWrapper.tsx@@ -1,10 +1,21 @@-import { type FunctionComponent, useEffect, useId, useRef } from "react";-+import {+ type ComponentProps,+ type JSX,+ type JSXElementConstructor,+ type PropsWithChildren,+ useEffect,+ useId,+ useRef,+} from "react";++import type { InternalComponent } from "embedding-sdk-bundle/types/sdk-bundle";import { ClientSideOnlyWrapper } from "embedding-sdk-package/components/private/ClientSideOnlyWrapper/ClientSideOnlyWrapper";import { Error } from "embedding-sdk-package/components/private/Error/Error";import { Loader } from "embedding-sdk-package/components/private/Loader/Loader";import {+ SDK_COMPONENT_MISSING_REQUIRED_PROPERTY_MESSAGE,SDK_COMPONENT_NOT_YET_AVAILABLE_MESSAGE,+ SDK_COMPONENT_UNRECOGNIZED_PROPERTY_MESSAGE,SDK_LOADING_ERROR_MESSAGE,SDK_NOT_LOADED_YET_MESSAGE,SDK_NOT_STARTED_LOADING_MESSAGE,@@ -18,9 +29,13 @@ import {SdkLoadingError,SdkLoadingState,} from "embedding-sdk-shared/types/sdk-loading";+import type { FunctionParametersSchemaValidationErrorMetadata } from "embedding-sdk-shared/types/validation";type Props<TComponentProps> = {- getComponent: () => FunctionComponent<TComponentProps> | null | undefined;+ getComponent: () =>+ | InternalComponent<JSXElementConstructor<TComponentProps>>+ | null+ | undefined;componentProps: TComponentProps | undefined;};@@ -55,6 +70,74 @@ const NotStartedLoadingTrigger = () => {return null;};+const getValidationErrorMessage = (+ errorMetadata: FunctionParametersSchemaValidationErrorMetadata | undefined,+) => {+ if (!errorMetadata) {+ return null;+ }++ const { errorCode, data } = errorMetadata;++ switch (errorCode) {+ case "missing_required_property":+ return `"${data}": ${SDK_COMPONENT_MISSING_REQUIRED_PROPERTY_MESSAGE}`;+ case "unrecognized_keys":+ return `"${data}": ${SDK_COMPONENT_UNRECOGNIZED_PROPERTY_MESSAGE}`;+ }++ return null;+};++const RenderComponentWithValidation = <+ TComponent extends InternalComponent<JSXElementConstructor<any>>,+>({+ $component: Component,+ ...props+}: PropsWithChildren<+ {+ $component: TComponent;+ } & ComponentProps<TComponent>+>) => {+ const validateFunctionSchema =+ getWindow()?.METABASE_EMBEDDING_SDK_BUNDLE?.validateFunctionSchema;+ const schema = Component.schema;++ // We validate only initial props currently+ const propsToValidateRef = useRef(props);++ useEffect(() => {+ if (!validateFunctionSchema || !schema) {+ return;+ }++ const validateAsync = async () => {+ try {+ const { validateParameters } = validateFunctionSchema(schema);+ const validationResult = validateParameters([+ propsToValidateRef.current,+ ]);++ if (!validationResult.success) {+ const error = getValidationErrorMessage(+ validationResult.errorMetadata,+ );++ if (error) {+ console.error(error);+ }+ }+ } catch (error) {+ console.warn(`Error during component schema validation: ${error}`);+ }+ };++ validateAsync();+ }, [schema, validateFunctionSchema]);++ return <Component {...props}>{props.children}</Component>;+};+const ComponentWrapperInner = <TComponentProps,>({getComponent,componentProps,@@ -98,14 +181,16 @@ const ComponentWrapperInner = <TComponentProps,>({}return (- <ComponentProvider+ <RenderComponentWithValidation+ $component={ComponentProvider}{...metabaseProviderProps}reduxStore={metabaseProviderInternalProps.reduxStore}>- <Component- {...(componentProps as JSX.IntrinsicAttributes & TComponentProps)}+ <RenderComponentWithValidation+ $component={Component as InternalComponent<JSXElementConstructor<any>>}+ {...componentProps}/>- </ComponentProvider>+ </RenderComponentWithValidation>);};@@ -118,7 +203,10 @@ type ComponentWrapperFunction<P> = [P] extends [never]export const createComponent = <TComponentProps extends Record<any, any> | undefined | never = never,>(- getComponent: () => FunctionComponent<TComponentProps> | null | undefined,+ getComponent: () =>+ | InternalComponent<JSXElementConstructor<TComponentProps>>+ | null+ | undefined,): ComponentWrapperFunction<TComponentProps> => {return function ComponentWrapper(props: TComponentProps) {const ensureSingleInstanceId = useId();diff --git a/enterprise/frontend/src/embedding-sdk-package/constants/error-messages.ts b/enterprise/frontend/src/embedding-sdk-package/constants/error-messages.tsindex c627c8d4623..eff839930b7 100644--- a/enterprise/frontend/src/embedding-sdk-package/constants/error-messages.ts+++ b/enterprise/frontend/src/embedding-sdk-package/constants/error-messages.ts@@ -1,11 +1,19 @@export const SDK_NOT_STARTED_LOADING_MESSAGE =- "Error loading the Embedding Analytics SDK. Ensure all SDK components are wrapped in the Provider component.";+ "Error loading the Embedded Analytics SDK. Ensure all SDK components are wrapped in the Provider component.";export const SDK_LOADING_ERROR_MESSAGE =- "Error loading the Embedding Analytics SDK. Verify the instance URL is correct and reachable.";+ "Error loading the Embedded Analytics SDK. Verify the instance URL is correct and reachable.";export const SDK_NOT_LOADED_YET_MESSAGE =- "Error loading the Embedding Analytics SDK. The loading state is `Loaded` but the SDK bundle is not loaded yet.";+ "Error loading the Embedded Analytics SDK. The loading state is `Loaded` but the SDK bundle is not loaded yet.";export const SDK_COMPONENT_NOT_YET_AVAILABLE_MESSAGE =- "The component is not available in the Embedding Analytics SDK bundle. Update the analytics server to serve the correct bundle.";+ "The component is not available in the Embedded Analytics SDK bundle. Update your analytics server to access the component.";++export const SDK_COMPONENT_MISSING_REQUIRED_PROPERTY_MESSAGE =+ // eslint-disable-next-line no-literal-metabase-strings -- console.error message+ "this property is required by the component. Your Embedded Analytics SDK and Metabase instance are out of sync. Update them to matching versions and adjust props based on the updated TypeScript types.";++export const SDK_COMPONENT_UNRECOGNIZED_PROPERTY_MESSAGE =+ // eslint-disable-next-line no-literal-metabase-strings -- console.error message+ "this property is not recognized by the component and will be ignored. Your Embedded Analytics SDK and Metabase instance are out of sync. Update them to matching versions and adjust props based on the updated TypeScript types.";diff --git a/enterprise/frontend/src/embedding-sdk-package/dev.md b/enterprise/frontend/src/embedding-sdk-package/dev.mdindex cfdb1f7643f..9b2894c9322 100644--- a/enterprise/frontend/src/embedding-sdk-package/dev.md+++ b/enterprise/frontend/src/embedding-sdk-package/dev.md@@ -84,7 +84,7 @@ TEST_SUITE=metabase-nodejs-react-sdk-embedding-sample-e2e OPEN_UI=false EMBEDDIN```##### :warning: Obtaining the Shoppy's Metabase App DB Dump locally-For the Shoppy's Sample App Tests (`TEST_SUITE=shoppy-e2e`) locally, a proper App DB dump of the Shoppy's Metabase Instance must be placed to the `./e2e/tmp/db_dumps/shoppy_metabase_app_db_dump.sql`+For the Shoppy's Sample App Tests (`TEST_SUITE=shoppy-e2e`) locally, a proper App DB dump of the Shoppy's Metabase instance must be placed to the `./e2e/tmp/db_dumps/shoppy_metabase_app_db_dump.sql`You can get it by:- Enabling the `Tailscale` and logging in using your work email address.diff --git a/enterprise/frontend/src/embedding-sdk-shared/types/validation.ts b/enterprise/frontend/src/embedding-sdk-shared/types/validation.tsnew file mode 100644index 00000000000..aee549aa2d9--- /dev/null+++ b/enterprise/frontend/src/embedding-sdk-shared/types/validation.ts@@ -0,0 +1,27 @@+export type SchemaValidationErrorCode =+ | "missing_required_property"+ | "unrecognized_keys";++export type SchemaValidationErrorMetadata = {+ errorCode: SchemaValidationErrorCode;+ data: string;+};++export type FunctionParametersSchemaValidationErrorMetadata =+ SchemaValidationErrorMetadata & {+ parameterIndex: number;+ };++export type FunctionSchemaValidationResult<+ TParameters extends unknown[],+ TReturnValue,+> = {+ validateParameters: (parameters: TParameters) => {+ success: boolean;+ errorMetadata?: FunctionParametersSchemaValidationErrorMetadata;+ };+ validateReturnValue: (returnValue: TReturnValue) => {+ success: boolean;+ errorMetadata?: SchemaValidationErrorMetadata;+ };+};diff --git a/package.json b/package.jsonindex 8cbeb27b4c7..515c4447f67 100644--- a/package.json+++ b/package.json@@ -147,7 +147,8 @@"ttag": "1.7.21","typescript": "^5.4.5","underscore": "~1.13.3",- "yup": "^0.32.11"+ "yup": "^0.32.11",+ "zod": "^4.1.5"},"devDependencies": {"@babel/cli": "^7.23.0",diff --git a/yarn.lock b/yarn.lockindex 3bab13e90a6..6a78263fc64 100644--- a/yarn.lock+++ b/yarn.lock@@ -22356,6 +22356,11 @@ yup@^0.32.11:property-expr "^2.0.4"toposort "^2.0.2"+zod@^4.1.5:+ version "4.1.5"+ resolved "https://registry.yarnpkg.com/zod/-/zod-4.1.5.tgz#7a21fc3178928ede50a28f7d0db4414c4cdb0161"+ integrity sha512-rcUUZqlLJgBC33IT3PNMgsCq6TzLQEG/Ei/KTCU0PedSWRMAXoOUN+4t/0H+Q8bdnLPdqUYnvboJT0bn/229qg==+version "5.6.0"resolved "https://registry.yarnpkg.com/zrender/-/zrender-5.6.0.tgz#01325b0bb38332dd5e87a8dbee7336cafc0f4a5b"