mirror of
https://github.com/formbricks/formbricks.git
synced 2026-01-07 14:20:31 -06:00
fix: formbricks-surveys not compiling correctly leads to formbricks-js throwing error in action creation (#1223)
This commit is contained in:
@@ -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"),
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
export default {
|
||||
module.exports = {
|
||||
plugins: {
|
||||
tailwindcss: {},
|
||||
autoprefixer: {},
|
||||
|
||||
@@ -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 })],
|
||||
});
|
||||
|
||||
14
turbo.json
14
turbo.json
@@ -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/**"],
|
||||
|
||||
Reference in New Issue
Block a user