Files
formbricks/apps/web/lib/formbricks.ts
Shubham Palriwala 769ceb1fc2 refactor: @formbricks/api package (#782)
* 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>
2023-10-01 11:50:29 +02:00

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();
};