From f2d4cf40874dafcc51ecbd0c909fafb9be8a4a72 Mon Sep 17 00:00:00 2001 From: Matti Nannt Date: Mon, 16 Oct 2023 14:44:06 +0200 Subject: [PATCH] fix: formbricks-surveys not compiling correctly leads to formbricks-js throwing error in action creation (#1223) --- packages/js/vite.config.js | 2 + packages/lib/survey/service.ts | 102 +++++++---------------------- packages/surveys/package.json | 5 +- packages/surveys/postcss.config.js | 2 +- packages/surveys/vite.config.ts | 3 +- turbo.json | 14 ++++ 6 files changed, 45 insertions(+), 83 deletions(-) diff --git a/packages/js/vite.config.js b/packages/js/vite.config.js index 8e9558bf2e..51ba39a738 100644 --- a/packages/js/vite.config.js +++ b/packages/js/vite.config.js @@ -4,6 +4,8 @@ import dts from "vite-plugin-dts"; export default defineConfig({ build: { + emptyOutDir: false, // keep the dist folder to avoid errors with pnpm go when folder is empty during build + minify: "terser", lib: { // Could also be a dictionary or array of multiple entry points entry: resolve(__dirname, "src/index.ts"), diff --git a/packages/lib/survey/service.ts b/packages/lib/survey/service.ts index 1a6a83c73d..8a0793dc22 100644 --- a/packages/lib/survey/service.ts +++ b/packages/lib/survey/service.ts @@ -10,7 +10,6 @@ import { TSurveyInput, TSurveyWithAnalytics, ZSurvey, - ZSurveyWithAnalytics, } from "@formbricks/types/v1/surveys"; import { Prisma } from "@prisma/client"; import { revalidateTag, unstable_cache } from "next/cache"; @@ -141,18 +140,7 @@ export const getSurveyWithAnalytics = async (surveyId: string): Promise => { triggers: surveyPrisma.triggers.map((trigger) => trigger.eventClass.name), }; - try { - const survey = ZSurvey.parse(transformedSurvey); - return survey; - } catch (error) { - if (error instanceof Error) { - console.error(error.message); - } - if (error instanceof z.ZodError) { - console.error(JSON.stringify(error.errors, null, 2)); // log the detailed error information - } - throw new ValidationError("Data validation of survey failed"); - } + return transformedSurvey; }, [`surveys-${surveyId}`], { @@ -249,25 +226,14 @@ export const getSurveysByAttributeClassId = async (attributeClassId: string): Pr const surveys: TSurvey[] = []; - try { - for (const surveyPrisma of surveysPrisma) { - const transformedSurvey = { - ...surveyPrisma, - triggers: surveyPrisma.triggers.map((trigger) => trigger.eventClass.name), - }; - const survey = ZSurvey.parse(transformedSurvey); - surveys.push(survey); - } - return surveys; - } catch (error) { - if (error instanceof Error) { - console.error(error.message); - } - if (error instanceof z.ZodError) { - console.error(JSON.stringify(error.errors, null, 2)); // log the detailed error information - } - throw new ValidationError("Data validation of survey failed"); + for (const surveyPrisma of surveysPrisma) { + const transformedSurvey = { + ...surveyPrisma, + triggers: surveyPrisma.triggers.map((trigger) => trigger.eventClass.name), + }; + surveys.push(transformedSurvey); } + return surveys; }; export const getSurveysByActionClassId = async (actionClassId: string): Promise => { @@ -286,25 +252,14 @@ export const getSurveysByActionClassId = async (actionClassId: string): Promise< const surveys: TSurvey[] = []; - try { - for (const surveyPrisma of surveysPrisma) { - const transformedSurvey = { - ...surveyPrisma, - triggers: surveyPrisma.triggers.map((trigger) => trigger.eventClass.name), - }; - const survey = ZSurvey.parse(transformedSurvey); - surveys.push(survey); - } - return surveys; - } catch (error) { - if (error instanceof Error) { - console.error(error.message); - } - if (error instanceof z.ZodError) { - console.error(JSON.stringify(error.errors, null, 2)); // log the detailed error information - } - throw new ValidationError("Data validation of survey failed"); + for (const surveyPrisma of surveysPrisma) { + const transformedSurvey = { + ...surveyPrisma, + triggers: surveyPrisma.triggers.map((trigger) => trigger.eventClass.name), + }; + surveys.push(transformedSurvey); } + return surveys; }; export const getSurveys = async (environmentId: string): Promise => { @@ -330,22 +285,14 @@ export const getSurveys = async (environmentId: string): Promise => { const surveys: TSurvey[] = []; - try { - for (const surveyPrisma of surveysPrisma) { - const transformedSurvey = { - ...surveyPrisma, - triggers: surveyPrisma.triggers.map((trigger) => trigger.eventClass.name), - }; - const survey = ZSurvey.parse(transformedSurvey); - surveys.push(survey); - } - return surveys; - } catch (error) { - if (error instanceof z.ZodError) { - console.error(JSON.stringify(error.errors, null, 2)); // log the detailed error information - } - throw new ValidationError("Data validation of survey failed"); + for (const surveyPrisma of surveysPrisma) { + const transformedSurvey = { + ...surveyPrisma, + triggers: surveyPrisma.triggers.map((trigger) => trigger.eventClass.name), + }; + surveys.push(transformedSurvey); } + return surveys; }, [`environments-${environmentId}-surveys`], { @@ -402,8 +349,7 @@ export const getSurveysWithAnalytics = async (environmentId: string): Promise