mirror of
https://github.com/formbricks/formbricks.git
synced 2026-02-08 23:59:38 -06:00
* add uniqueResponseId to link survey * add uniqueResponseId to survey response * add singUseId to database and link survey * add singleUseId to api * add single use option in survey response options * add single use to getSurvey * add getResponseBySingleUseId * add ZSurveySingleUse schema to survey schema * add logic to check if link with suid has response * pass singleUseId as props, revert SWR changes * generation of single-use url in LinkSurveyModal * add singleUseId to SingleResponseCard * update SurveyInactive for invalid link * add suId to ZResponse schema * fix typo in SurveyInactive * update ResponseOptionCard * add suId to response select * add default message for SurveyLinkUsed * update logic to render SurveyLinkUsed * add comment for suId in prisma schema * fix types * refresh server component on save survey * update logic * fix build errors * fix prisma schema * add db migration * update wording * add singleUseId to localstorage * fix survey link used over thank you * add suid to people responses * fix preview and copy link on surveys page. * update text and icon for link survey modal * check survey not finished before setting question * update show surveylink used logic * add zodtype to prisma * fix logic to render last question answered/stored * add better comments * update default message for single use surveys * add LinkSingleUseSurveyModal * add guard before getting response with suid * fix build error * add default message for link used page * add key and group imports * add suId encryption and validation * make survey url encryption optional * fix build errors * move singleUseId to server side in surveyList * added validation to getResponseBySingleUseId service * restored env var names * import FORMBRICKS_ENCRYPTION_KEY from constants * check if encryption environment variable is set, add length validation for env variable --------- Co-authored-by: Ty Kerr <tykerr@Tys-MacBook-Pro.local> Co-authored-by: Johannes <johannes@formbricks.com> Co-authored-by: Matthias Nannt <mail@matthiasnannt.com> Co-authored-by: Dhruwang <dhruwangjariwala18@gmail.com>
34 lines
1.1 KiB
TypeScript
34 lines
1.1 KiB
TypeScript
import { FORMBRICKS_ENCRYPTION_KEY } from "@formbricks/lib/constants";
|
|
import { decryptAES128, encryptAES128 } from "@formbricks/lib/crypto";
|
|
import cuid2 from "@paralleldrive/cuid2";
|
|
|
|
// generate encrypted single use id for the survey
|
|
export const generateSurveySingleUseId = (isEncrypted: boolean): string => {
|
|
const cuid = cuid2.createId();
|
|
if (!isEncrypted) {
|
|
return cuid;
|
|
}
|
|
if (!FORMBRICKS_ENCRYPTION_KEY) {
|
|
throw new Error("FORMBRICKS_ENCRYPTION_KEY is not defined");
|
|
}
|
|
const encryptedCuid = encryptAES128(FORMBRICKS_ENCRYPTION_KEY, cuid);
|
|
return encryptedCuid;
|
|
};
|
|
|
|
// validate the survey single use id
|
|
export const validateSurveySingleUseId = (surveySingleUseId: string): string | undefined => {
|
|
if (!FORMBRICKS_ENCRYPTION_KEY) {
|
|
throw new Error("FORMBRICKS_ENCRYPTION_KEY is not defined");
|
|
}
|
|
try {
|
|
const decryptedCuid = decryptAES128(FORMBRICKS_ENCRYPTION_KEY!, surveySingleUseId);
|
|
if (cuid2.isCuid(decryptedCuid)) {
|
|
return decryptedCuid;
|
|
} else {
|
|
return undefined;
|
|
}
|
|
} catch (error) {
|
|
return undefined;
|
|
}
|
|
};
|