fix: formbricks-surveys not compiling correctly leads to formbricks-js throwing error in action creation (#1223)

This commit is contained in:
Matti Nannt
2023-10-16 14:44:06 +02:00
committed by GitHub
parent 029e97468b
commit f2d4cf4087
6 changed files with 45 additions and 83 deletions

View File

@@ -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"),

View File

@@ -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<TSurveyW
},
};
try {
const survey: TSurveyWithAnalytics = ZSurveyWithAnalytics.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;
},
[`surveyWithAnalytics-${surveyId}`],
{
@@ -203,18 +191,7 @@ export const getSurvey = async (surveyId: string): Promise<TSurvey | null> => {
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<TSurvey[]> => {
@@ -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<TSurvey[]> => {
@@ -330,22 +285,14 @@ export const getSurveys = async (environmentId: string): Promise<TSurvey[]> => {
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<TS
numResponses: _count.responses,
},
};
const survey = ZSurveyWithAnalytics.parse(transformedSurvey);
surveys.push(survey);
surveys.push(transformedSurvey);
}
return surveys;
} catch (error) {

View File

@@ -3,12 +3,11 @@
"private": true,
"license": "MIT",
"version": "0.0.0",
"type": "module",
"sideEffects": false,
"exports": {
".": {
"import": "./dist/index.js",
"require": "./dist/index.umd.cjs"
"import": "./dist/index.mjs",
"require": "./dist/index.umd.js"
}
},
"main": "./dist/index.js",

View File

@@ -1,4 +1,4 @@
export default {
module.exports = {
plugins: {
tailwindcss: {},
autoprefixer: {},

View File

@@ -6,6 +6,7 @@ import dts from "vite-plugin-dts";
// https://vitejs.dev/config/
export default defineConfig({
build: {
emptyOutDir: false, // keep the dist folder to avoid errors with pnpm go when folder is empty during build
minify: "terser",
sourcemap: true,
lib: {
@@ -17,5 +18,5 @@ export default defineConfig({
fileName: "index",
},
},
plugins: [preact(), dts()],
plugins: [preact(), dts({ rollupTypes: true })],
});

View File

@@ -23,6 +23,20 @@
"outputs": ["dist/**"],
"dependsOn": ["^build"]
},
"@formbricks/surveys#build": {
"outputs": ["dist/**"],
"dependsOn": ["^build"]
},
"@formbricks/surveys#go": {
"cache": false,
"persistent": true,
"dependsOn": ["@formbricks/surveys#build"]
},
"@formbricks/js#go": {
"cache": false,
"persistent": true,
"dependsOn": ["@formbricks/js#build"]
},
"build": {
"dependsOn": ["^build"],
"outputs": ["dist/**", ".next/**"],