mirror of
https://github.com/formbricks/formbricks.git
synced 2026-01-27 10:40:03 -06:00
* init: rewritten formbricks api package * restrucure: client prepended formbricks api package * feat: cleanup error templating and node-fetch for non browser access * feat: replace package (build error for js packge due to api) * fix: rename methods & move error type * fix: imports of api via js * remove node-fetch --------- Co-authored-by: Matthias Nannt <mail@matthiasnannt.com>
38 lines
896 B
TypeScript
38 lines
896 B
TypeScript
import formbricks from "@formbricks/js";
|
|
import { env } from "@/env.mjs";
|
|
|
|
export const formbricksEnabled =
|
|
typeof env.NEXT_PUBLIC_FORMBRICKS_API_HOST && env.NEXT_PUBLIC_FORMBRICKS_ENVIRONMENT_ID;
|
|
|
|
export const createResponse = async (
|
|
surveyId: string,
|
|
data: { [questionId: string]: any },
|
|
finished: boolean = false
|
|
): Promise<any> => {
|
|
const api = formbricks.getApi();
|
|
const personId = formbricks.getPerson()?.id;
|
|
return await api.client.response.create({
|
|
surveyId,
|
|
personId,
|
|
finished,
|
|
data,
|
|
});
|
|
};
|
|
|
|
export const updateResponse = async (
|
|
responseId: string,
|
|
data: { [questionId: string]: any },
|
|
finished: boolean = false
|
|
): Promise<any> => {
|
|
const api = formbricks.getApi();
|
|
return await api.client.response.update({
|
|
responseId,
|
|
finished,
|
|
data,
|
|
});
|
|
};
|
|
|
|
export const formbricksLogout = async () => {
|
|
return await formbricks.logout();
|
|
};
|