Compare commits

...

10 Commits

Author SHA1 Message Date
Jakob Schott
7320524c22 Included the contributers changes 2025-06-16 14:50:30 +02:00
Matti Nannt
e358104f7c chore: fast return ping endpoint when telemetry is disabled (#5893)
Co-authored-by: Piyush Gupta <piyushguptaa2z123@gmail.com>
2025-06-16 12:14:07 +00:00
Dhruwang Jariwala
c8e9194ab6 fix: broken email embed for rating question (#5890)
Co-authored-by: Piyush Gupta <piyushguptaa2z123@gmail.com>
2025-06-16 11:49:19 +00:00
Matti Nannt
bebe29815d feat: domain based access control (#5985)
Co-authored-by: Piyush Gupta <56182734+gupta-piyush19@users.noreply.github.com>
Co-authored-by: Piyush Gupta <piyushguptaa2z123@gmail.com>
Co-authored-by: Dhruwang <dhruwangjariwala18@gmail.com>
Co-authored-by: pandeymangg <anshuman.pandey9999@gmail.com>
2025-06-16 11:37:02 +00:00
victorvhs017
7f40502c94 fix: Removed footer on follow-up email if white labelling enabled (#5984) 2025-06-16 10:59:57 +00:00
Dhruwang Jariwala
5fb5215680 fix: email enumeration via signup page (#5853)
Co-authored-by: Victor Santos <victor@formbricks.com>
2025-06-13 16:25:40 +00:00
Varun Singh
19b80ff042 fix: misplaced button text for 'preview survey' (#5972) 2025-06-13 05:29:41 -07:00
Jakob Schott
2dfdba2acf chore: Optimize text sizing and alignment for Drop-Off table (#5914)
Co-authored-by: Johannes <johannes@formbricks.com>
2025-06-13 11:21:45 +00:00
Johannes
f7842789de docs: tweak API wording (#5978) 2025-06-12 03:45:41 -07:00
Johannes
59bdd5f065 docs: add recall info to variables (#5977) 2025-06-12 03:21:53 -07:00
131 changed files with 1677 additions and 1197 deletions

View File

@@ -80,8 +80,8 @@ S3_ENDPOINT_URL=
# Force path style for S3 compatible storage (0 for disabled, 1 for enabled)
S3_FORCE_PATH_STYLE=0
# Set this URL to add a custom domain to your survey links(default is WEBAPP_URL)
# SURVEY_URL=https://survey.example.com
# Set this URL to add a public domain for all your client facing routes(default is WEBAPP_URL)
# PUBLIC_URL=https://survey.example.com
#####################
# Disable Features #

1
.gitignore vendored
View File

@@ -73,3 +73,4 @@ infra/terraform/.terraform/
/.idea/
/*.iml
packages/ios/FormbricksSDK/FormbricksSDK.xcodeproj/project.xcworkspace/xcuserdata
.cursorrules

View File

@@ -27,7 +27,7 @@ describe("ConnectWithFormbricks", () => {
render(
<ConnectWithFormbricks
environment={environment}
webAppUrl={webAppUrl}
publicDomain={webAppUrl}
widgetSetupCompleted={false}
channel={channel}
/>
@@ -40,7 +40,7 @@ describe("ConnectWithFormbricks", () => {
render(
<ConnectWithFormbricks
environment={environment}
webAppUrl={webAppUrl}
publicDomain={webAppUrl}
widgetSetupCompleted={true}
channel={channel}
/>
@@ -53,7 +53,7 @@ describe("ConnectWithFormbricks", () => {
render(
<ConnectWithFormbricks
environment={environment}
webAppUrl={webAppUrl}
publicDomain={webAppUrl}
widgetSetupCompleted={true}
channel={channel}
/>
@@ -67,7 +67,7 @@ describe("ConnectWithFormbricks", () => {
render(
<ConnectWithFormbricks
environment={environment}
webAppUrl={webAppUrl}
publicDomain={webAppUrl}
widgetSetupCompleted={false}
channel={channel}
/>

View File

@@ -12,14 +12,14 @@ import { OnboardingSetupInstructions } from "./OnboardingSetupInstructions";
interface ConnectWithFormbricksProps {
environment: TEnvironment;
webAppUrl: string;
publicDomain: string;
widgetSetupCompleted: boolean;
channel: TProjectConfigChannel;
}
export const ConnectWithFormbricks = ({
environment,
webAppUrl,
publicDomain,
widgetSetupCompleted,
channel,
}: ConnectWithFormbricksProps) => {
@@ -49,7 +49,7 @@ export const ConnectWithFormbricks = ({
<div className="flex w-1/2 flex-col space-y-4">
<OnboardingSetupInstructions
environmentId={environment.id}
webAppUrl={webAppUrl}
publicDomain={publicDomain}
channel={channel}
widgetSetupCompleted={widgetSetupCompleted}
/>

View File

@@ -33,7 +33,7 @@ describe("OnboardingSetupInstructions", () => {
// Provide some default props for testing
const defaultProps = {
environmentId: "env-123",
webAppUrl: "https://example.com",
publicDomain: "https://example.com",
channel: "app" as const, // Assuming channel is either "app" or "website"
widgetSetupCompleted: false,
};

View File

@@ -18,14 +18,14 @@ const tabs = [
interface OnboardingSetupInstructionsProps {
environmentId: string;
webAppUrl: string;
publicDomain: string;
channel: TProjectConfigChannel;
widgetSetupCompleted: boolean;
}
export const OnboardingSetupInstructions = ({
environmentId,
webAppUrl,
publicDomain,
channel,
widgetSetupCompleted,
}: OnboardingSetupInstructionsProps) => {
@@ -34,7 +34,7 @@ export const OnboardingSetupInstructions = ({
const htmlSnippetForAppSurveys = `<!-- START Formbricks Surveys -->
<script type="text/javascript">
!function(){
var appUrl = "${webAppUrl}";
var appUrl = "${publicDomain}";
var environmentId = "${environmentId}";
var t=document.createElement("script");t.type="text/javascript",t.async=!0,t.src=appUrl+"/js/formbricks.umd.cjs",t.onload=function(){window.formbricks?window.formbricks.setup({environmentId:environmentId,appUrl:appUrl}):console.error("Formbricks library failed to load properly. The formbricks object is not available.");};var e=document.getElementsByTagName("script")[0];e.parentNode.insertBefore(t,e)}();
</script>
@@ -44,7 +44,7 @@ export const OnboardingSetupInstructions = ({
const htmlSnippetForWebsiteSurveys = `<!-- START Formbricks Surveys -->
<script type="text/javascript">
!function(){
var appUrl = "${webAppUrl}";
var appUrl = "${publicDomain}";
var environmentId = "${environmentId}";
var t=document.createElement("script");t.type="text/javascript",t.async=!0,t.src=appUrl+"/js/formbricks.umd.cjs",t.onload=function(){window.formbricks?window.formbricks.setup({environmentId:environmentId,appUrl:appUrl}):console.error("Formbricks library failed to load properly. The formbricks object is not available.");};var e=document.getElementsByTagName("script")[0];e.parentNode.insertBefore(t,e)}();
</script>
@@ -57,7 +57,7 @@ export const OnboardingSetupInstructions = ({
if (typeof window !== "undefined") {
formbricks.setup({
environmentId: "${environmentId}",
appUrl: "${webAppUrl}",
appUrl: "${publicDomain}",
});
}
@@ -75,7 +75,7 @@ export const OnboardingSetupInstructions = ({
if (typeof window !== "undefined") {
formbricks.setup({
environmentId: "${environmentId}",
appUrl: "${webAppUrl}",
appUrl: "${publicDomain}",
});
}

View File

@@ -1,6 +1,6 @@
import { ConnectWithFormbricks } from "@/app/(app)/(onboarding)/environments/[environmentId]/connect/components/ConnectWithFormbricks";
import { WEBAPP_URL } from "@/lib/constants";
import { getEnvironment } from "@/lib/environment/service";
import { getPublicDomain } from "@/lib/getPublicUrl";
import { getProjectByEnvironmentId } from "@/lib/project/service";
import { Button } from "@/modules/ui/components/button";
import { Header } from "@/modules/ui/components/header";
@@ -30,6 +30,8 @@ const Page = async (props: ConnectPageProps) => {
const channel = project.config.channel || null;
const publicDomain = getPublicDomain();
return (
<div className="flex min-h-full flex-col items-center justify-center py-10">
<Header title={t("environments.connect.headline")} subtitle={t("environments.connect.subtitle")} />
@@ -39,7 +41,7 @@ const Page = async (props: ConnectPageProps) => {
</div>
<ConnectWithFormbricks
environment={environment}
webAppUrl={WEBAPP_URL}
publicDomain={publicDomain}
widgetSetupCompleted={environment.appSetupCompleted}
channel={channel}
/>

View File

@@ -11,7 +11,7 @@ vi.mock("@/lib/constants", () => ({
IS_DEVELOPMENT: true,
E2E_TESTING: false,
WEBAPP_URL: "http://localhost:3000",
SURVEY_URL: "http://localhost:3000/survey",
PUBLIC_URL: "http://localhost:3000/survey",
ENCRYPTION_KEY: "mock-encryption-key",
CRON_SECRET: "mock-cron-secret",
DEFAULT_BRAND_COLOR: "#64748b",

View File

@@ -14,7 +14,7 @@ vi.mock("@/lib/constants", () => ({
IS_DEVELOPMENT: true,
E2E_TESTING: false,
WEBAPP_URL: "http://localhost:3000",
SURVEY_URL: "http://localhost:3000/survey",
PUBLIC_URL: "http://localhost:3000/survey",
ENCRYPTION_KEY: "mock-encryption-key",
CRON_SECRET: "mock-cron-secret",
DEFAULT_BRAND_COLOR: "#64748b",

View File

@@ -23,7 +23,6 @@ vi.mock("@/lib/constants", () => ({
IS_DEVELOPMENT: true,
E2E_TESTING: false,
WEBAPP_URL: "http://localhost:3000",
SURVEY_URL: "http://localhost:3000/survey",
ENCRYPTION_KEY: "mock-encryption-key",
CRON_SECRET: "mock-cron-secret",
DEFAULT_BRAND_COLOR: "#64748b",

View File

@@ -30,6 +30,12 @@ vi.mock("@/lib/constants", () => ({
REDIS_URL: "redis://localhost:6379",
}));
vi.mock("@/lib/env", () => ({
env: {
PUBLIC_URL: "https://public-domain.com",
},
}));
describe("Contact Page Re-export", () => {
test("should re-export SingleContactPage", () => {
expect(Page).toBe(SingleContactPage);

View File

@@ -29,6 +29,12 @@ vi.mock("@/lib/constants", () => ({
AUDIT_LOG_ENABLED: true,
}));
vi.mock("@/lib/env", () => ({
env: {
PUBLIC_URL: "https://example.com",
},
}));
describe("AppConnectionPage Re-export", () => {
test("should re-export AppConnectionPage correctly", () => {
expect(AppConnectionPage).toBe(OriginalAppConnectionPage);

View File

@@ -29,6 +29,12 @@ vi.mock("@/lib/constants", () => ({
AUDIT_LOG_ENABLED: 1,
}));
vi.mock("@/lib/env", () => ({
env: {
PUBLIC_URL: "https://public-domain.com",
},
}));
describe("GeneralSettingsPage re-export", () => {
test("should re-export GeneralSettingsPage component", () => {
expect(Page).toBe(GeneralSettingsPage);

View File

@@ -29,6 +29,12 @@ vi.mock("@/lib/constants", () => ({
AUDIT_LOG_ENABLED: 1,
}));
vi.mock("@/lib/env", () => ({
env: {
PUBLIC_URL: "https://public-domain.com",
},
}));
describe("ProjectLookSettingsPage re-export", () => {
test("should re-export ProjectLookSettingsPage component", () => {
expect(Page).toBe(ProjectLookSettingsPage);

View File

@@ -34,6 +34,12 @@ vi.mock("@/lib/constants", () => ({
AUDIT_LOG_ENABLED: 1,
}));
vi.mock("@/lib/env", () => ({
env: {
PUBLIC_URL: "https://public-domain.com",
},
}));
describe("TeamsPage re-export", () => {
test("should re-export TeamsPage component", () => {
expect(Page).toBe(TeamsPage);

View File

@@ -49,6 +49,12 @@ vi.mock("@/lib/constants", () => ({
AUDIT_LOG_ENABLED: true,
}));
vi.mock("@/lib/env", () => ({
env: {
PUBLIC_URL: "https://public-domain.com",
},
}));
vi.mock("@/app/(app)/environments/[environmentId]/components/ResponseFilterContext");
vi.mock("@/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/actions");
vi.mock("@/app/lib/surveys/surveys");

View File

@@ -20,7 +20,7 @@ interface ResponsePageProps {
environment: TEnvironment;
survey: TSurvey;
surveyId: string;
webAppUrl: string;
publicDomain: string;
user?: TUser;
environmentTags: TTag[];
responsesPerPage: number;
@@ -32,7 +32,7 @@ export const ResponsePage = ({
environment,
survey,
surveyId,
webAppUrl,
publicDomain,
user,
environmentTags,
responsesPerPage,
@@ -155,7 +155,7 @@ export const ResponsePage = ({
<>
<div className="flex gap-1.5">
<CustomFilter survey={surveyMemoized} />
{!isReadOnly && !isSharingPage && <ResultsShareButton survey={survey} webAppUrl={webAppUrl} />}
{!isReadOnly && !isSharingPage && <ResultsShareButton survey={survey} publicDomain={publicDomain} />}
</div>
<ResponseDataView
survey={survey}

View File

@@ -3,7 +3,7 @@ import { SurveyAnalysisNavigation } from "@/app/(app)/environments/[environmentI
import { ResponsePage } from "@/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/responses/components/ResponsePage";
import Page from "@/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/responses/page";
import { SurveyAnalysisCTA } from "@/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/SurveyAnalysisCTA";
import { getSurveyDomain } from "@/lib/getSurveyUrl";
import { getPublicDomain } from "@/lib/getPublicUrl";
import { getResponseCountBySurveyId } from "@/lib/response/service";
import { getSurvey } from "@/lib/survey/service";
import { getTagsByEnvironmentId } from "@/lib/tag/service";
@@ -65,8 +65,8 @@ vi.mock("@/lib/constants", () => ({
SESSION_MAX_AGE: 1000,
}));
vi.mock("@/lib/getSurveyUrl", () => ({
getSurveyDomain: vi.fn(),
vi.mock("@/lib/getPublicUrl", () => ({
getPublicDomain: vi.fn(),
}));
vi.mock("@/lib/response/service", () => ({
@@ -160,7 +160,7 @@ const mockEnvironment = {
const mockTags: TTag[] = [{ id: "tag1", name: "Tag 1", environmentId: mockEnvironmentId } as unknown as TTag];
const mockLocale: TUserLocale = "en-US";
const mockSurveyDomain = "http://customdomain.com";
const mockPublicDomain = "http://customdomain.com";
const mockParams = {
environmentId: mockEnvironmentId,
@@ -179,7 +179,7 @@ describe("ResponsesPage", () => {
vi.mocked(getTagsByEnvironmentId).mockResolvedValue(mockTags);
vi.mocked(getResponseCountBySurveyId).mockResolvedValue(10);
vi.mocked(findMatchingLocale).mockResolvedValue(mockLocale);
vi.mocked(getSurveyDomain).mockReturnValue(mockSurveyDomain);
vi.mocked(getPublicDomain).mockReturnValue(mockPublicDomain);
});
afterEach(() => {
@@ -205,7 +205,7 @@ describe("ResponsesPage", () => {
survey: mockSurvey,
isReadOnly: false,
user: mockUser,
surveyDomain: mockSurveyDomain,
publicDomain: mockPublicDomain,
}),
undefined
);
@@ -224,7 +224,7 @@ describe("ResponsesPage", () => {
environment: mockEnvironment,
survey: mockSurvey,
surveyId: mockSurveyId,
webAppUrl: "http://localhost:3000",
publicDomain: mockPublicDomain,
environmentTags: mockTags,
user: mockUser,
responsesPerPage: 10,

View File

@@ -1,8 +1,8 @@
import { SurveyAnalysisNavigation } from "@/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/components/SurveyAnalysisNavigation";
import { ResponsePage } from "@/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/responses/components/ResponsePage";
import { SurveyAnalysisCTA } from "@/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/SurveyAnalysisCTA";
import { RESPONSES_PER_PAGE, WEBAPP_URL } from "@/lib/constants";
import { getSurveyDomain } from "@/lib/getSurveyUrl";
import { RESPONSES_PER_PAGE } from "@/lib/constants";
import { getPublicDomain } from "@/lib/getPublicUrl";
import { getResponseCountBySurveyId } from "@/lib/response/service";
import { getSurvey } from "@/lib/survey/service";
import { getTagsByEnvironmentId } from "@/lib/tag/service";
@@ -37,7 +37,7 @@ const Page = async (props) => {
const responseCount = await getResponseCountBySurveyId(params.surveyId);
const locale = await findMatchingLocale();
const surveyDomain = getSurveyDomain();
const publicDomain = getPublicDomain();
return (
<PageContentWrapper>
@@ -49,7 +49,7 @@ const Page = async (props) => {
survey={survey}
isReadOnly={isReadOnly}
user={user}
surveyDomain={surveyDomain}
publicDomain={publicDomain}
responseCount={responseCount}
/>
}>
@@ -59,7 +59,7 @@ const Page = async (props) => {
environment={environment}
survey={survey}
surveyId={params.surveyId}
webAppUrl={WEBAPP_URL}
publicDomain={publicDomain}
environmentTags={tags}
user={user}
responsesPerPage={RESPONSES_PER_PAGE}

View File

@@ -149,7 +149,7 @@ describe("ShareEmbedSurvey", () => {
const defaultProps = {
survey: mockSurveyWeb,
surveyDomain: "test.com",
publicDomain: "https://public-domain.com",
open: true,
modalView: "start" as "start" | "embed" | "panel",
setOpen: mockSetOpen,
@@ -158,7 +158,7 @@ describe("ShareEmbedSurvey", () => {
beforeEach(() => {
mockEmbedViewComponent.mockImplementation(
({ handleInitialPageButton, tabs, activeId, survey, email, surveyUrl, surveyDomain, locale }) => (
({ handleInitialPageButton, tabs, activeId, survey, email, surveyUrl, publicDomain, locale }) => (
<div>
<button onClick={() => handleInitialPageButton()}>EmbedViewMockContent</button>
<div data-testid="embedview-tabs">{JSON.stringify(tabs)}</div>
@@ -166,7 +166,7 @@ describe("ShareEmbedSurvey", () => {
<div data-testid="embedview-survey-id">{survey.id}</div>
<div data-testid="embedview-email">{email}</div>
<div data-testid="embedview-surveyUrl">{surveyUrl}</div>
<div data-testid="embedview-surveyDomain">{surveyDomain}</div>
<div data-testid="embedview-publicDomain">{publicDomain}</div>
<div data-testid="embedview-locale">{locale}</div>
</div>
)

View File

@@ -24,7 +24,7 @@ import { PanelInfoView } from "./shareEmbedModal/PanelInfoView";
interface ShareEmbedSurveyProps {
survey: TSurvey;
surveyDomain: string;
publicDomain: string;
open: boolean;
modalView: "start" | "embed" | "panel";
setOpen: React.Dispatch<React.SetStateAction<boolean>>;
@@ -33,7 +33,7 @@ interface ShareEmbedSurveyProps {
export const ShareEmbedSurvey = ({
survey,
surveyDomain,
publicDomain,
open,
modalView,
setOpen,
@@ -66,16 +66,16 @@ export const ShareEmbedSurvey = ({
useEffect(() => {
const fetchSurveyUrl = async () => {
try {
const url = await getSurveyUrl(survey, surveyDomain, "default");
const url = await getSurveyUrl(survey, publicDomain, "default");
setSurveyUrl(url);
} catch (error) {
console.error("Failed to fetch survey URL:", error);
// Fallback to a default URL if fetching fails
setSurveyUrl(`${surveyDomain}/s/${survey.id}`);
setSurveyUrl(`${publicDomain}/s/${survey.id}`);
}
};
fetchSurveyUrl();
}, [survey, surveyDomain]);
}, [survey, publicDomain]);
useEffect(() => {
if (survey.type !== "link") {
@@ -120,7 +120,7 @@ export const ShareEmbedSurvey = ({
<ShareSurveyLink
survey={survey}
surveyUrl={surveyUrl}
surveyDomain={surveyDomain}
publicDomain={publicDomain}
setSurveyUrl={setSurveyUrl}
locale={user.locale}
/>
@@ -174,7 +174,7 @@ export const ShareEmbedSurvey = ({
survey={survey}
email={email}
surveyUrl={surveyUrl}
surveyDomain={surveyDomain}
publicDomain={publicDomain}
setSurveyUrl={setSurveyUrl}
locale={user.locale}
/>

View File

@@ -104,13 +104,15 @@ describe("SummaryDropOffs", () => {
// Check drop-off counts and percentages
expect(screen.getByText("20")).toBeInTheDocument();
expect(screen.getByText("(20%)")).toBeInTheDocument();
expect(screen.getByText("15")).toBeInTheDocument();
expect(screen.getByText("(19%)")).toBeInTheDocument(); // 18.75% rounded to 19%
expect(screen.getByText("10")).toBeInTheDocument();
expect(screen.getByText("(15%)")).toBeInTheDocument(); // 15.38% rounded to 15%
// Check percentage values
const percentageElements = screen.getAllByText(/\d+%/);
expect(percentageElements).toHaveLength(3);
expect(percentageElements[0]).toHaveTextContent("20%");
expect(percentageElements[1]).toHaveTextContent("19%");
expect(percentageElements[2]).toHaveTextContent("15%");
});
test("renders empty state when dropOff array is empty", () => {

View File

@@ -23,9 +23,9 @@ export const SummaryDropOffs = ({ dropOff, survey }: SummaryDropOffsProps) => {
return (
<div className="rounded-xl border border-slate-200 bg-white shadow-sm">
<div className="">
<div className="grid h-10 grid-cols-6 items-center border-y border-slate-200 bg-slate-100 text-sm font-semibold text-slate-600">
<div className="col-span-3 pl-4 md:pl-6">{t("common.questions")}</div>
<div className="flex justify-center">
<div className="grid min-h-10 grid-cols-6 items-center rounded-t-xl border-b border-slate-200 bg-slate-100 text-sm font-semibold text-slate-600">
<div className="col-span-3 px-4 md:px-6">{t("common.questions")}</div>
<div className="flex justify-end px-4 md:px-6">
<TooltipProvider delayDuration={50}>
<Tooltip>
<TooltipTrigger>
@@ -37,14 +37,16 @@ export const SummaryDropOffs = ({ dropOff, survey }: SummaryDropOffsProps) => {
</Tooltip>
</TooltipProvider>
</div>
<div className="px-4 text-center md:px-6">{t("environments.surveys.summary.impressions")}</div>
<div className="pr-6 text-center md:pl-6">{t("environments.surveys.summary.drop_offs")}</div>
<div className="px-4 text-right md:px-6">{t("environments.surveys.summary.impressions")}</div>
<div className="px-4 text-right md:mr-1 md:pl-6 md:pr-6">
{t("environments.surveys.summary.drop_offs")}
</div>
</div>
{dropOff.map((quesDropOff) => (
<div
key={quesDropOff.questionId}
className="grid grid-cols-6 items-center border-b border-slate-100 py-2 text-sm text-slate-800 md:text-base">
<div className="col-span-3 flex gap-3 pl-4 md:pl-6">
className="grid grid-cols-6 items-start border-b border-slate-100 text-xs text-slate-800 md:text-sm">
<div className="col-span-3 flex gap-3 px-4 py-2 md:px-6">
{getIcon(quesDropOff.questionType)}
<p>
{formatTextWithSlashes(
@@ -57,17 +59,21 @@ export const SummaryDropOffs = ({ dropOff, survey }: SummaryDropOffsProps) => {
"default"
)["default"],
"@",
["text-lg"]
["text-sm"]
)}
</p>
</div>
<div className="whitespace-pre-wrap text-center font-semibold">
<div className="whitespace-pre-wrap px-4 py-2 text-right font-mono font-medium md:px-6">
{quesDropOff.ttc > 0 ? (quesDropOff.ttc / 1000).toFixed(2) + "s" : "N/A"}
</div>
<div className="whitespace-pre-wrap text-center font-semibold">{quesDropOff.impressions}</div>
<div className="pl-6 text-center md:px-6">
<span className="mr-1.5 font-semibold">{quesDropOff.dropOffCount}</span>
<span>({Math.round(quesDropOff.dropOffPercentage)}%)</span>
<div className="whitespace-pre-wrap px-4 py-2 text-right font-mono font-medium md:px-6">
{quesDropOff.impressions}
</div>
<div className="px-4 py-2 text-right md:px-6">
<span className="mr-1 inline-block w-fit rounded-xl bg-slate-100 px-2 py-1 text-left text-xs">
{Math.round(quesDropOff.dropOffPercentage)}%
</span>
<span className="mr-1 font-mono font-medium">{quesDropOff.dropOffCount}</span>
</div>
</div>
))}

View File

@@ -36,7 +36,7 @@ interface SummaryPageProps {
environment: TEnvironment;
survey: TSurvey;
surveyId: string;
webAppUrl: string;
publicDomain: string;
locale: TUserLocale;
isReadOnly: boolean;
initialSurveySummary?: TSurveySummary;
@@ -46,7 +46,7 @@ export const SummaryPage = ({
environment,
survey,
surveyId,
webAppUrl,
publicDomain,
locale,
isReadOnly,
initialSurveySummary,
@@ -133,7 +133,7 @@ export const SummaryPage = ({
<div className="flex gap-1.5">
<CustomFilter survey={surveyMemoized} />
{!isReadOnly && !isSharingPage && (
<ResultsShareButton survey={surveyMemoized} webAppUrl={webAppUrl} />
<ResultsShareButton survey={surveyMemoized} publicDomain={publicDomain} />
)}
</div>
<ScrollToTop containerId="mainContent" />

View File

@@ -21,6 +21,8 @@ vi.mock("@/modules/ee/audit-logs/lib/utils", () => ({
}),
}));
const mockPublicDomain = "https://public-domain.com";
// Mock constants
vi.mock("@/lib/constants", () => ({
IS_FORMBRICKS_CLOUD: false,
@@ -49,6 +51,12 @@ vi.mock("@/lib/constants", () => ({
REDIS_URL: "mock-url",
}));
vi.mock("@/lib/env", () => ({
env: {
PUBLIC_URL: "https://public-domain.com",
},
}));
// Create a spy for refreshSingleUseId so we can override it in tests
const refreshSingleUseIdSpy = vi.fn(() => Promise.resolve("newSingleUseId"));
@@ -72,7 +80,7 @@ vi.mock("next/navigation", () => ({
// Mock copySurveyLink to return a predictable string
vi.mock("@/modules/survey/lib/client-utils", () => ({
copySurveyLink: vi.fn((url: string, id: string) => `${url}?id=${id}`),
copySurveyLink: vi.fn((url: string, suId: string) => `${url}?suId=${suId}`),
}));
// Mock the copy survey action
@@ -103,6 +111,10 @@ vi.mock("@/app/share/[sharingKey]/actions", () => ({
getResponseCountBySurveySharingKeyAction: vi.fn(() => Promise.resolve({ data: 5 })),
}));
vi.mock("@/lib/getPublicUrl", () => ({
getPublicDomain: vi.fn(() => mockPublicDomain),
}));
vi.spyOn(toast, "success");
vi.spyOn(toast, "error");
@@ -123,7 +135,6 @@ const dummySurvey = {
} as unknown as TSurvey;
const dummyEnvironment = { id: "env123", appSetupCompleted: true } as TEnvironment;
const dummyUser = { id: "user123", name: "Test User" } as TUser;
const surveyDomain = "https://surveys.test.formbricks.com";
describe("SurveyAnalysisCTA - handleCopyLink", () => {
afterEach(() => {
@@ -136,7 +147,7 @@ describe("SurveyAnalysisCTA - handleCopyLink", () => {
survey={dummySurvey}
environment={dummyEnvironment}
isReadOnly={false}
surveyDomain={surveyDomain}
publicDomain={mockPublicDomain}
user={dummyUser}
responseCount={5}
/>
@@ -147,9 +158,7 @@ describe("SurveyAnalysisCTA - handleCopyLink", () => {
await waitFor(() => {
expect(refreshSingleUseIdSpy).toHaveBeenCalled();
expect(writeTextMock).toHaveBeenCalledWith(
"https://surveys.test.formbricks.com/s/survey123?id=newSingleUseId"
);
expect(writeTextMock).toHaveBeenCalledWith("https://public-domain.com/s/survey123?suId=newSingleUseId");
expect(toast.success).toHaveBeenCalledWith("common.copied_to_clipboard");
});
});
@@ -161,7 +170,7 @@ describe("SurveyAnalysisCTA - handleCopyLink", () => {
survey={dummySurvey}
environment={dummyEnvironment}
isReadOnly={false}
surveyDomain={surveyDomain}
publicDomain={mockPublicDomain}
user={dummyUser}
responseCount={5}
/>
@@ -194,7 +203,7 @@ describe("SurveyAnalysisCTA - Edit functionality", () => {
survey={dummySurvey}
environment={dummyEnvironment}
isReadOnly={false}
surveyDomain={surveyDomain}
publicDomain={mockPublicDomain}
user={dummyUser}
responseCount={5}
/>
@@ -215,7 +224,7 @@ describe("SurveyAnalysisCTA - Edit functionality", () => {
survey={dummySurvey}
environment={dummyEnvironment}
isReadOnly={false}
surveyDomain={surveyDomain}
publicDomain={mockPublicDomain}
user={dummyUser}
responseCount={0}
/>
@@ -237,7 +246,7 @@ describe("SurveyAnalysisCTA - Edit functionality", () => {
survey={dummySurvey}
environment={dummyEnvironment}
isReadOnly={true}
surveyDomain={surveyDomain}
publicDomain={mockPublicDomain}
user={dummyUser}
responseCount={5}
/>
@@ -266,7 +275,7 @@ describe("SurveyAnalysisCTA - duplicateSurveyAndRoute and EditPublicSurveyAlertD
survey={dummySurvey}
environment={dummyEnvironment}
isReadOnly={false}
surveyDomain={surveyDomain}
publicDomain={mockPublicDomain}
user={dummyUser}
responseCount={5}
/>
@@ -309,7 +318,7 @@ describe("SurveyAnalysisCTA - duplicateSurveyAndRoute and EditPublicSurveyAlertD
survey={dummySurvey}
environment={dummyEnvironment}
isReadOnly={false}
surveyDomain={surveyDomain}
publicDomain={mockPublicDomain}
user={dummyUser}
responseCount={5}
/>
@@ -335,7 +344,7 @@ describe("SurveyAnalysisCTA - duplicateSurveyAndRoute and EditPublicSurveyAlertD
survey={dummySurvey}
environment={dummyEnvironment}
isReadOnly={false}
surveyDomain={surveyDomain}
publicDomain={mockPublicDomain}
user={dummyUser}
responseCount={5}
/>
@@ -369,7 +378,7 @@ describe("SurveyAnalysisCTA - duplicateSurveyAndRoute and EditPublicSurveyAlertD
survey={dummySurvey}
environment={dummyEnvironment}
isReadOnly={false}
surveyDomain={surveyDomain}
publicDomain={mockPublicDomain}
user={dummyUser}
responseCount={5}
/>

View File

@@ -24,7 +24,7 @@ interface SurveyAnalysisCTAProps {
environment: TEnvironment;
isReadOnly: boolean;
user: TUser;
surveyDomain: string;
publicDomain: string;
responseCount: number;
}
@@ -40,7 +40,7 @@ export const SurveyAnalysisCTA = ({
environment,
isReadOnly,
user,
surveyDomain,
publicDomain,
responseCount,
}: SurveyAnalysisCTAProps) => {
const { t } = useTranslate();
@@ -56,7 +56,7 @@ export const SurveyAnalysisCTA = ({
dropdown: false,
});
const surveyUrl = useMemo(() => `${surveyDomain}/s/${survey.id}`, [survey.id, surveyDomain]);
const surveyUrl = useMemo(() => `${publicDomain}/s/${survey.id}`, [survey.id, publicDomain]);
const { refreshSingleUseId } = useSingleUseId(survey);
const widgetSetupCompleted = survey.type === "app" && environment.appSetupCompleted;
@@ -202,7 +202,7 @@ export const SurveyAnalysisCTA = ({
<ShareEmbedSurvey
key={key}
survey={survey}
surveyDomain={surveyDomain}
publicDomain={publicDomain}
open={modalState[key as keyof ModalState]}
setOpen={setOpen}
user={user}

View File

@@ -64,7 +64,7 @@ const defaultProps = {
survey: mockSurveyLink,
email: "test@example.com",
surveyUrl: "http://example.com/survey1",
surveyDomain: "http://example.com",
publicDomain: "http://example.com",
setSurveyUrl: vi.fn(),
locale: "en" as any,
disableBack: false,

View File

@@ -20,7 +20,7 @@ interface EmbedViewProps {
survey: any;
email: string;
surveyUrl: string;
surveyDomain: string;
publicDomain: string;
setSurveyUrl: React.Dispatch<React.SetStateAction<string>>;
locale: TUserLocale;
}
@@ -35,7 +35,7 @@ export const EmbedView = ({
survey,
email,
surveyUrl,
surveyDomain,
publicDomain,
setSurveyUrl,
locale,
}: EmbedViewProps) => {
@@ -83,7 +83,7 @@ export const EmbedView = ({
<LinkTab
survey={survey}
surveyUrl={surveyUrl}
surveyDomain={surveyDomain}
publicDomain={publicDomain}
setSurveyUrl={setSurveyUrl}
locale={locale}
/>

View File

@@ -6,12 +6,12 @@ import { LinkTab } from "./LinkTab";
// Mock ShareSurveyLink
vi.mock("@/modules/analysis/components/ShareSurveyLink", () => ({
ShareSurveyLink: vi.fn(({ survey, surveyUrl, surveyDomain, locale }) => (
ShareSurveyLink: vi.fn(({ survey, surveyUrl, publicDomain, locale }) => (
<div data-testid="share-survey-link">
Mocked ShareSurveyLink
<span data-testid="survey-id">{survey.id}</span>
<span data-testid="survey-url">{surveyUrl}</span>
<span data-testid="survey-domain">{surveyDomain}</span>
<span data-testid="public-domain">{publicDomain}</span>
<span data-testid="locale">{locale}</span>
</div>
)),
@@ -49,7 +49,7 @@ const mockSurvey: TSurvey = {
} as unknown as TSurvey;
const mockSurveyUrl = "https://app.formbricks.com/s/survey1";
const mockSurveyDomain = "https://app.formbricks.com";
const mockPublicDomain = "https://app.formbricks.com";
const mockSetSurveyUrl = vi.fn();
const mockLocale: TUserLocale = "en-US";
@@ -82,7 +82,7 @@ describe("LinkTab", () => {
<LinkTab
survey={mockSurvey}
surveyUrl={mockSurveyUrl}
surveyDomain={mockSurveyDomain}
publicDomain={mockPublicDomain}
setSurveyUrl={mockSetSurveyUrl}
locale={mockLocale}
/>
@@ -97,7 +97,7 @@ describe("LinkTab", () => {
<LinkTab
survey={mockSurvey}
surveyUrl={mockSurveyUrl}
surveyDomain={mockSurveyDomain}
publicDomain={mockPublicDomain}
setSurveyUrl={mockSetSurveyUrl}
locale={mockLocale}
/>
@@ -105,7 +105,7 @@ describe("LinkTab", () => {
expect(screen.getByTestId("share-survey-link")).toBeInTheDocument();
expect(screen.getByTestId("survey-id")).toHaveTextContent(mockSurvey.id);
expect(screen.getByTestId("survey-url")).toHaveTextContent(mockSurveyUrl);
expect(screen.getByTestId("survey-domain")).toHaveTextContent(mockSurveyDomain);
expect(screen.getByTestId("public-domain")).toHaveTextContent(mockPublicDomain);
expect(screen.getByTestId("locale")).toHaveTextContent(mockLocale);
});
@@ -114,7 +114,7 @@ describe("LinkTab", () => {
<LinkTab
survey={mockSurvey}
surveyUrl={mockSurveyUrl}
surveyDomain={mockSurveyDomain}
publicDomain={mockPublicDomain}
setSurveyUrl={mockSetSurveyUrl}
locale={mockLocale}
/>
@@ -129,7 +129,7 @@ describe("LinkTab", () => {
<LinkTab
survey={mockSurvey}
surveyUrl={mockSurveyUrl}
surveyDomain={mockSurveyDomain}
publicDomain={mockPublicDomain}
setSurveyUrl={mockSetSurveyUrl}
locale={mockLocale}
/>

View File

@@ -9,12 +9,12 @@ import { TUserLocale } from "@formbricks/types/user";
interface LinkTabProps {
survey: TSurvey;
surveyUrl: string;
surveyDomain: string;
publicDomain: string;
setSurveyUrl: (url: string) => void;
locale: TUserLocale;
}
export const LinkTab = ({ survey, surveyUrl, surveyDomain, setSurveyUrl, locale }: LinkTabProps) => {
export const LinkTab = ({ survey, surveyUrl, publicDomain, setSurveyUrl, locale }: LinkTabProps) => {
const { t } = useTranslate();
const docsLinks = [
@@ -44,7 +44,7 @@ export const LinkTab = ({ survey, surveyUrl, surveyDomain, setSurveyUrl, locale
<ShareSurveyLink
survey={survey}
surveyUrl={surveyUrl}
surveyDomain={surveyDomain}
publicDomain={publicDomain}
setSurveyUrl={setSurveyUrl}
locale={locale}
/>

View File

@@ -1,9 +1,8 @@
import { getSurveyDomain } from "@/lib/getSurveyUrl";
import { getPublicDomain } from "@/lib/getPublicUrl";
import { getProjectByEnvironmentId } from "@/lib/project/service";
import { getSurvey } from "@/lib/survey/service";
import { getStyling } from "@/lib/utils/styling";
import { getPreviewEmailTemplateHtml } from "@/modules/email/components/preview-email-template";
import { getTranslate } from "@/tolgee/server";
import { cleanup } from "@testing-library/react";
import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
import { TEnvironment } from "@formbricks/types/environment";
@@ -35,7 +34,16 @@ vi.mock("@/lib/constants", () => ({
SENTRY_DSN: "mock-sentry-dsn",
}));
vi.mock("@/lib/getSurveyUrl");
vi.mock("@/lib/env", () => ({
env: {
PUBLIC_URL: "https://public-domain.com",
},
}));
vi.mock("@/lib/getPublicUrl", () => ({
getPublicDomain: vi.fn().mockReturnValue("https://public-domain.com"),
}));
vi.mock("@/lib/project/service");
vi.mock("@/lib/survey/service");
vi.mock("@/lib/utils/styling");
@@ -121,7 +129,7 @@ const mockComputedStyling = {
thankYouCardIconBgColor: "#DDDDDD",
} as any;
const mockSurveyDomain = "https://app.formbricks.com";
const mockPublicDomain = "https://app.formbricks.com";
const mockRawHtml = `${doctype}<html><body>Test Email Content for ${mockSurvey.name}</body></html>`;
const mockCleanedHtml = `<html><body>Test Email Content for ${mockSurvey.name}</body></html>`;
@@ -136,7 +144,7 @@ describe("getEmailTemplateHtml", () => {
vi.mocked(getSurvey).mockResolvedValue(mockSurvey);
vi.mocked(getProjectByEnvironmentId).mockResolvedValue(mockProject);
vi.mocked(getStyling).mockReturnValue(mockComputedStyling);
vi.mocked(getSurveyDomain).mockReturnValue(mockSurveyDomain);
vi.mocked(getPublicDomain).mockReturnValue(mockPublicDomain);
vi.mocked(getPreviewEmailTemplateHtml).mockResolvedValue(mockRawHtml);
});
@@ -147,8 +155,8 @@ describe("getEmailTemplateHtml", () => {
expect(getSurvey).toHaveBeenCalledWith(mockSurveyId);
expect(getProjectByEnvironmentId).toHaveBeenCalledWith(mockSurvey.environmentId);
expect(getStyling).toHaveBeenCalledWith(mockProject, mockSurvey);
expect(getSurveyDomain).toHaveBeenCalledTimes(1);
const expectedSurveyUrl = `${mockSurveyDomain}/s/${mockSurvey.id}`;
expect(getPublicDomain).toHaveBeenCalledTimes(1);
const expectedSurveyUrl = `${mockPublicDomain}/s/${mockSurvey.id}`;
expect(getPreviewEmailTemplateHtml).toHaveBeenCalledWith(
mockSurvey,
expectedSurveyUrl,

View File

@@ -1,4 +1,4 @@
import { getSurveyDomain } from "@/lib/getSurveyUrl";
import { getPublicDomain } from "@/lib/getPublicUrl";
import { getProjectByEnvironmentId } from "@/lib/project/service";
import { getSurvey } from "@/lib/survey/service";
import { getStyling } from "@/lib/utils/styling";
@@ -17,7 +17,7 @@ export const getEmailTemplateHtml = async (surveyId: string, locale: string) =>
}
const styling = getStyling(project, survey);
const surveyUrl = getSurveyDomain() + "/s/" + survey.id;
const surveyUrl = getPublicDomain() + "/s/" + survey.id;
const html = await getPreviewEmailTemplateHtml(survey, surveyUrl, styling, locale, t);
const doctype =
'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';

View File

@@ -3,8 +3,8 @@ import { SurveyAnalysisNavigation } from "@/app/(app)/environments/[environmentI
import { SummaryPage } from "@/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/SummaryPage";
import { getSurveySummary } from "@/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/lib/surveySummary";
import SurveyPage from "@/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/page";
import { DEFAULT_LOCALE, WEBAPP_URL } from "@/lib/constants";
import { getSurveyDomain } from "@/lib/getSurveyUrl";
import { DEFAULT_LOCALE } from "@/lib/constants";
import { getPublicDomain } from "@/lib/getPublicUrl";
import { getResponseCountBySurveyId } from "@/lib/response/service";
import { getSurvey } from "@/lib/survey/service";
import { getUser } from "@/lib/user/service";
@@ -38,7 +38,6 @@ vi.mock("@/lib/constants", () => ({
OIDC_SIGNING_ALGORITHM: "test-oidc-signing-algorithm",
IS_PRODUCTION: false,
SENTRY_DSN: "mock-sentry-dsn",
WEBAPP_URL: "http://localhost:3000",
RESPONSES_PER_PAGE: 10,
SESSION_MAX_AGE: 1000,
}));
@@ -64,8 +63,8 @@ vi.mock(
})
);
vi.mock("@/lib/getSurveyUrl", () => ({
getSurveyDomain: vi.fn(),
vi.mock("@/lib/getPublicUrl", () => ({
getPublicDomain: vi.fn(),
}));
vi.mock("@/lib/response/service", () => ({
@@ -211,7 +210,7 @@ describe("SurveyPage", () => {
vi.mocked(getSurvey).mockResolvedValue(mockSurvey);
vi.mocked(getUser).mockResolvedValue(mockUser);
vi.mocked(getResponseCountBySurveyId).mockResolvedValue(10);
vi.mocked(getSurveyDomain).mockReturnValue("test.domain.com");
vi.mocked(getPublicDomain).mockReturnValue("http://localhost:3000");
vi.mocked(getSurveySummary).mockResolvedValue(mockSurveySummary);
vi.mocked(notFound).mockClear();
});
@@ -235,7 +234,7 @@ describe("SurveyPage", () => {
expect(vi.mocked(getEnvironmentAuth)).toHaveBeenCalledWith(mockEnvironmentId);
expect(vi.mocked(getSurvey)).toHaveBeenCalledWith(mockSurveyId);
expect(vi.mocked(getUser)).toHaveBeenCalledWith(mockUserId);
expect(vi.mocked(getSurveyDomain)).toHaveBeenCalled();
expect(vi.mocked(getPublicDomain)).toHaveBeenCalled();
expect(vi.mocked(SurveyAnalysisNavigation).mock.calls[0][0]).toEqual(
expect.objectContaining({
@@ -250,7 +249,7 @@ describe("SurveyPage", () => {
environment: mockEnvironment,
survey: mockSurvey,
surveyId: mockSurveyId,
webAppUrl: WEBAPP_URL,
publicDomain: "http://localhost:3000",
isReadOnly: false,
locale: mockUser.locale ?? DEFAULT_LOCALE,
initialSurveySummary: mockSurveySummary,

View File

@@ -2,8 +2,8 @@ import { SurveyAnalysisNavigation } from "@/app/(app)/environments/[environmentI
import { SummaryPage } from "@/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/SummaryPage";
import { SurveyAnalysisCTA } from "@/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/SurveyAnalysisCTA";
import { getSurveySummary } from "@/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/lib/surveySummary";
import { DEFAULT_LOCALE, WEBAPP_URL } from "@/lib/constants";
import { getSurveyDomain } from "@/lib/getSurveyUrl";
import { DEFAULT_LOCALE } from "@/lib/constants";
import { getPublicDomain } from "@/lib/getPublicUrl";
import { getSurvey } from "@/lib/survey/service";
import { getUser } from "@/lib/user/service";
import { getEnvironmentAuth } from "@/modules/environments/lib/utils";
@@ -40,7 +40,7 @@ const SurveyPage = async (props: { params: Promise<{ environmentId: string; surv
// Fetch initial survey summary data on the server to prevent duplicate API calls during hydration
const initialSurveySummary = await getSurveySummary(surveyId);
const surveyDomain = getSurveyDomain();
const publicDomain = getPublicDomain();
return (
<PageContentWrapper>
@@ -52,7 +52,7 @@ const SurveyPage = async (props: { params: Promise<{ environmentId: string; surv
survey={survey}
isReadOnly={isReadOnly}
user={user}
surveyDomain={surveyDomain}
publicDomain={publicDomain}
responseCount={initialSurveySummary?.meta.totalResponses ?? 0}
/>
}>
@@ -62,7 +62,7 @@ const SurveyPage = async (props: { params: Promise<{ environmentId: string; surv
environment={environment}
survey={survey}
surveyId={params.surveyId}
webAppUrl={WEBAPP_URL}
publicDomain={publicDomain}
isReadOnly={isReadOnly}
locale={user.locale ?? DEFAULT_LOCALE}
initialSurveySummary={initialSurveySummary}

View File

@@ -138,7 +138,7 @@ describe("ResultsShareButton", () => {
test("renders initial state and fetches sharing key (no existing key)", async () => {
mockGetResultShareUrlAction.mockResolvedValue({ data: null });
render(<ResultsShareButton survey={mockSurvey} webAppUrl={webAppUrl} />);
render(<ResultsShareButton survey={mockSurvey} publicDomain={webAppUrl} />);
expect(screen.getByTestId("dropdown-menu-trigger")).toBeInTheDocument();
expect(screen.getByTestId("link-icon")).toBeInTheDocument();
@@ -150,7 +150,7 @@ describe("ResultsShareButton", () => {
test("handles copy private link to clipboard", async () => {
mockGetResultShareUrlAction.mockResolvedValue({ data: null });
render(<ResultsShareButton survey={mockSurvey} webAppUrl={webAppUrl} />);
render(<ResultsShareButton survey={mockSurvey} publicDomain={webAppUrl} />);
fireEvent.click(screen.getByTestId("dropdown-menu-trigger")); // Open dropdown
const copyLinkButton = (await screen.findAllByTestId("dropdown-menu-item")).find((item) =>
@@ -166,7 +166,9 @@ describe("ResultsShareButton", () => {
test("handles copy public link to clipboard", async () => {
const shareKey = "publicShareKey";
mockGetResultShareUrlAction.mockResolvedValue({ data: shareKey });
render(<ResultsShareButton survey={{ ...mockSurvey, resultShareKey: shareKey }} webAppUrl={webAppUrl} />);
render(
<ResultsShareButton survey={{ ...mockSurvey, resultShareKey: shareKey }} publicDomain={webAppUrl} />
);
fireEvent.click(screen.getByTestId("dropdown-menu-trigger")); // Open dropdown
const copyPublicLinkButton = (await screen.findAllByTestId("dropdown-menu-item")).find((item) =>
@@ -184,7 +186,7 @@ describe("ResultsShareButton", () => {
test("handles publish to web successfully", async () => {
mockGetResultShareUrlAction.mockResolvedValue({ data: null });
mockGenerateResultShareUrlAction.mockResolvedValue({ data: "newShareKey" });
render(<ResultsShareButton survey={mockSurvey} webAppUrl={webAppUrl} />);
render(<ResultsShareButton survey={mockSurvey} publicDomain={webAppUrl} />);
fireEvent.click(screen.getByTestId("dropdown-menu-trigger"));
const publishButton = (await screen.findAllByTestId("dropdown-menu-item")).find((item) =>
@@ -210,7 +212,9 @@ describe("ResultsShareButton", () => {
const shareKey = "toUnpublishKey";
mockGetResultShareUrlAction.mockResolvedValue({ data: shareKey });
mockDeleteResultShareUrlAction.mockResolvedValue({ data: { id: mockSurvey.id } });
render(<ResultsShareButton survey={{ ...mockSurvey, resultShareKey: shareKey }} webAppUrl={webAppUrl} />);
render(
<ResultsShareButton survey={{ ...mockSurvey, resultShareKey: shareKey }} publicDomain={webAppUrl} />
);
fireEvent.click(screen.getByTestId("dropdown-menu-trigger"));
const unpublishButton = (await screen.findAllByTestId("dropdown-menu-item")).find((item) =>
@@ -234,7 +238,7 @@ describe("ResultsShareButton", () => {
test("opens and closes ShareSurveyResults modal", async () => {
mockGetResultShareUrlAction.mockResolvedValue({ data: null });
render(<ResultsShareButton survey={mockSurvey} webAppUrl={webAppUrl} />);
render(<ResultsShareButton survey={mockSurvey} publicDomain={webAppUrl} />);
fireEvent.click(screen.getByTestId("dropdown-menu-trigger"));
const publishButton = (await screen.findAllByTestId("dropdown-menu-item")).find((item) =>

View File

@@ -21,10 +21,10 @@ import { ShareSurveyResults } from "../(analysis)/summary/components/ShareSurvey
interface ResultsShareButtonProps {
survey: TSurvey;
webAppUrl: string;
publicDomain: string;
}
export const ResultsShareButton = ({ survey, webAppUrl }: ResultsShareButtonProps) => {
export const ResultsShareButton = ({ survey, publicDomain }: ResultsShareButtonProps) => {
const { t } = useTranslate();
const [showResultsLinkModal, setShowResultsLinkModal] = useState(false);
@@ -34,7 +34,7 @@ export const ResultsShareButton = ({ survey, webAppUrl }: ResultsShareButtonProp
const handlePublish = async () => {
const resultShareKeyResponse = await generateResultShareUrlAction({ surveyId: survey.id });
if (resultShareKeyResponse?.data) {
setSurveyUrl(webAppUrl + "/share/" + resultShareKeyResponse.data);
setSurveyUrl(publicDomain + "/share/" + resultShareKeyResponse.data);
setShowPublishModal(true);
} else {
const errorMessage = getFormattedErrorMessage(resultShareKeyResponse);
@@ -58,13 +58,13 @@ export const ResultsShareButton = ({ survey, webAppUrl }: ResultsShareButtonProp
const fetchSharingKey = async () => {
const resultShareUrlResponse = await getResultShareUrlAction({ surveyId: survey.id });
if (resultShareUrlResponse?.data) {
setSurveyUrl(webAppUrl + "/share/" + resultShareUrlResponse.data);
setSurveyUrl(publicDomain + "/share/" + resultShareUrlResponse.data);
setShowPublishModal(true);
}
};
fetchSharingKey();
}, [survey.id, webAppUrl]);
}, [survey.id, publicDomain]);
const copyUrlToClipboard = () => {
if (typeof window !== "undefined") {

View File

@@ -1,5 +1,6 @@
import { responses } from "@/app/lib/api/response";
import { CRON_SECRET } from "@/lib/constants";
import { env } from "@/lib/env";
import { captureTelemetry } from "@/lib/telemetry";
import packageJson from "@/package.json";
import { headers } from "next/headers";
@@ -13,6 +14,10 @@ export const POST = async () => {
return responses.notAuthenticatedResponse();
}
if (env.TELEMETRY_DISABLED === "1") {
return responses.successResponse({}, true);
}
const [surveyCount, responseCount, userCount] = await Promise.all([
prisma.survey.count(),
prisma.response.count(),

View File

@@ -1,6 +1,6 @@
import { authenticateRequest, handleErrorResponse } from "@/app/api/v1/auth";
import { responses } from "@/app/lib/api/response";
import { getSurveyDomain } from "@/lib/getSurveyUrl";
import { getPublicDomain } from "@/lib/getPublicUrl";
import { getSurvey } from "@/lib/survey/service";
import { generateSurveySingleUseIds } from "@/lib/utils/single-use-surveys";
import { hasPermission } from "@/modules/organization/settings/api-keys/lib/utils";
@@ -42,10 +42,10 @@ export const GET = async (
const singleUseIds = generateSurveySingleUseIds(limit, survey.singleUse.isEncrypted);
const surveyDomain = getSurveyDomain();
const publicDomain = getPublicDomain();
// map single use ids to survey links
const surveyLinks = singleUseIds.map(
(singleUseId) => `${surveyDomain}/s/${survey.id}?suId=${singleUseId}`
(singleUseId) => `${publicDomain}/s/${survey.id}?suId=${singleUseId}`
);
return responses.successResponse(surveyLinks);

View File

@@ -0,0 +1,85 @@
import { NextRequest } from "next/server";
import { beforeEach, describe, expect, test, vi } from "vitest";
import { getPublicDomainHost, isPublicDomainConfigured, isRequestFromPublicDomain } from "./domain-utils";
// Mock the env module
vi.mock("@/lib/env", () => ({
env: {
get PUBLIC_URL() {
return process.env.PUBLIC_URL || "";
},
},
}));
describe("Domain Utils", () => {
beforeEach(() => {
process.env.PUBLIC_URL = "";
});
describe("getPublicDomain", () => {
test("should return null when PUBLIC_URL is empty", () => {
expect(getPublicDomainHost()).toBeNull();
});
test("should return the host from a valid PUBLIC_URL", () => {
process.env.PUBLIC_URL = "https://example.com";
expect(getPublicDomainHost()).toBe("example.com");
});
test("should handle URLs with paths", () => {
process.env.PUBLIC_URL = "https://example.com/path";
expect(getPublicDomainHost()).toBe("example.com");
});
test("should handle URLs with ports", () => {
process.env.PUBLIC_URL = "https://example.com:3000";
expect(getPublicDomainHost()).toBe("example.com:3000");
});
});
describe("isPublicDomainConfigured", () => {
test("should return false when PUBLIC_URL is empty", () => {
process.env.PUBLIC_URL = "";
expect(isPublicDomainConfigured()).toBe(false);
});
test("should return true when PUBLIC_URL is valid", () => {
process.env.PUBLIC_URL = "https://example.com";
expect(isPublicDomainConfigured()).toBe(true);
});
});
describe("isRequestFromPublicDomain", () => {
test("should return false when public domain is not configured", () => {
process.env.PUBLIC_URL = "";
const request = new NextRequest("https://example.com");
expect(isRequestFromPublicDomain(request)).toBe(false);
});
test("should return false when host doesn't match public domain", () => {
process.env.PUBLIC_URL = "https://example.com";
const request = new NextRequest("https://different-domain.com");
expect(isRequestFromPublicDomain(request)).toBe(false);
});
test("should return true when host matches public domain", () => {
process.env.PUBLIC_URL = "https://example.com";
const request = new NextRequest("https://example.com", {
headers: {
host: "example.com",
},
});
expect(isRequestFromPublicDomain(request)).toBe(true);
});
test("should handle domains with ports", () => {
process.env.PUBLIC_URL = "https://example.com:3000";
const request = new NextRequest("https://example.com:3000", {
headers: {
host: "example.com:3000",
},
});
expect(isRequestFromPublicDomain(request)).toBe(true);
});
});
});

View File

@@ -0,0 +1,31 @@
import { env } from "@/lib/env";
import { NextRequest } from "next/server";
/**
* Get the public domain from PUBLIC_URL environment variable
*/
export const getPublicDomainHost = (): string | null => {
const PUBLIC_URL = env.PUBLIC_URL;
if (!PUBLIC_URL) return null;
return new URL(PUBLIC_URL).host;
};
/**
* Check if PUBLIC_URL is configured (has a valid public domain)
*/
export const isPublicDomainConfigured = (): boolean => {
return getPublicDomainHost() !== null;
};
/**
* Check if the current request is coming from the public domain
*/
export const isRequestFromPublicDomain = (request: NextRequest): boolean => {
const host = request.headers.get("host");
const publicDomainHost = getPublicDomainHost();
if (!publicDomainHost) return false;
return host === publicDomainHost;
};

View File

@@ -1,10 +1,13 @@
import { describe, expect, test } from "vitest";
import {
isAdminDomainRoute,
isAuthProtectedRoute,
isClientSideApiRoute,
isForgotPasswordRoute,
isLoginRoute,
isManagementApiRoute,
isPublicDomainRoute,
isRouteAllowedForDomain,
isShareUrlRoute,
isSignupRoute,
isSyncWithUserIdentificationEndpoint,
@@ -69,6 +72,9 @@ describe("endpoint-validator", () => {
expect(isClientSideApiRoute("/api/v1/management/something")).toBe(false);
expect(isClientSideApiRoute("/api/something")).toBe(false);
expect(isClientSideApiRoute("/auth/login")).toBe(false);
// exception for open graph image generation route, it should not be rate limited
expect(isClientSideApiRoute("/api/v1/client/og")).toBe(false);
});
});
@@ -136,4 +142,138 @@ describe("endpoint-validator", () => {
expect(isSyncWithUserIdentificationEndpoint("/api/something")).toBe(false);
});
});
describe("isPublicDomainRoute", () => {
test("should return true for health endpoint", () => {
expect(isPublicDomainRoute("/health")).toBe(true);
});
// Static assets are not handled by domain routing - middleware doesn't run on them
test("should return true for survey routes", () => {
expect(isPublicDomainRoute("/s/survey123")).toBe(true);
expect(isPublicDomainRoute("/s/survey-id-with-dashes")).toBe(true);
});
test("should return true for contact survey routes", () => {
expect(isPublicDomainRoute("/c/jwt-token")).toBe(true);
expect(isPublicDomainRoute("/c/very-long-jwt-token-123")).toBe(true);
});
test("should return true for client API routes", () => {
expect(isPublicDomainRoute("/api/v1/client/something")).toBe(true);
expect(isPublicDomainRoute("/api/v2/client/other")).toBe(true);
});
test("should return true for share routes", () => {
expect(isPublicDomainRoute("/share/abc123/summary")).toBe(true);
expect(isPublicDomainRoute("/share/xyz789/responses")).toBe(true);
expect(isPublicDomainRoute("/share/anything")).toBe(true);
});
test("should return false for admin-only routes", () => {
expect(isPublicDomainRoute("/")).toBe(false);
expect(isPublicDomainRoute("/environments/123")).toBe(false);
expect(isPublicDomainRoute("/auth/login")).toBe(false);
expect(isPublicDomainRoute("/setup/organization")).toBe(false);
expect(isPublicDomainRoute("/organizations/123")).toBe(false);
expect(isPublicDomainRoute("/product/settings")).toBe(false);
expect(isPublicDomainRoute("/api/v1/management/users")).toBe(false);
expect(isPublicDomainRoute("/api/v2/management/surveys")).toBe(false);
});
});
describe("isAdminDomainRoute", () => {
test("should return true for health endpoint (backward compatibility)", () => {
expect(isAdminDomainRoute("/health")).toBe(true);
expect(isAdminDomainRoute("/health")).toBe(true);
});
// Static assets are not handled by domain routing - middleware doesn't run on them
test("should return true for admin routes", () => {
expect(isAdminDomainRoute("/")).toBe(true);
expect(isAdminDomainRoute("/environments/123")).toBe(true);
expect(isAdminDomainRoute("/environments/123/surveys")).toBe(true);
expect(isAdminDomainRoute("/auth/login")).toBe(true);
expect(isAdminDomainRoute("/auth/signup")).toBe(true);
expect(isAdminDomainRoute("/setup/organization")).toBe(true);
expect(isAdminDomainRoute("/setup/team")).toBe(true);
expect(isAdminDomainRoute("/organizations/123")).toBe(true);
expect(isAdminDomainRoute("/organizations/123/settings")).toBe(true);
expect(isAdminDomainRoute("/product/settings")).toBe(true);
expect(isAdminDomainRoute("/product/features")).toBe(true);
expect(isAdminDomainRoute("/api/v1/management/users")).toBe(true);
expect(isAdminDomainRoute("/api/v2/management/surveys")).toBe(true);
expect(isAdminDomainRoute("/pipeline/jobs")).toBe(true);
expect(isAdminDomainRoute("/cron/tasks")).toBe(true);
expect(isAdminDomainRoute("/random/route")).toBe(true);
expect(isAdminDomainRoute("/s/survey123")).toBe(false);
expect(isAdminDomainRoute("/c/jwt-token")).toBe(false);
expect(isAdminDomainRoute("/api/v1/client/test")).toBe(false);
});
});
describe("isRouteAllowedForDomain", () => {
test("should allow public routes on public domain", () => {
expect(isRouteAllowedForDomain("/s/survey123", true)).toBe(true);
expect(isRouteAllowedForDomain("/c/jwt-token", true)).toBe(true);
expect(isRouteAllowedForDomain("/api/v1/client/test", true)).toBe(true);
expect(isRouteAllowedForDomain("/share/abc/summary", true)).toBe(true);
expect(isRouteAllowedForDomain("/health", true)).toBe(true);
// Static assets not tested - middleware doesn't run on them
});
test("should block admin routes on public domain", () => {
expect(isRouteAllowedForDomain("/", true)).toBe(false);
expect(isRouteAllowedForDomain("/environments/123", true)).toBe(false);
expect(isRouteAllowedForDomain("/auth/login", true)).toBe(false);
expect(isRouteAllowedForDomain("/api/v1/management/users", true)).toBe(false);
});
test("should block public routes on admin domain when PUBLIC_URL is configured", () => {
// Admin routes should be allowed
expect(isRouteAllowedForDomain("/", false)).toBe(true);
expect(isRouteAllowedForDomain("/environments/123", false)).toBe(true);
expect(isRouteAllowedForDomain("/auth/login", false)).toBe(true);
expect(isRouteAllowedForDomain("/api/v1/management/users", false)).toBe(true);
expect(isRouteAllowedForDomain("/health", false)).toBe(true);
expect(isRouteAllowedForDomain("/pipeline/jobs", false)).toBe(true);
expect(isRouteAllowedForDomain("/cron/tasks", false)).toBe(true);
// Public routes should be blocked on admin domain
expect(isRouteAllowedForDomain("/s/survey123", false)).toBe(false);
expect(isRouteAllowedForDomain("/c/jwt-token", false)).toBe(false);
expect(isRouteAllowedForDomain("/api/v1/client/test", false)).toBe(false);
expect(isRouteAllowedForDomain("/share/abc/summary", false)).toBe(false);
});
});
describe("edge cases", () => {
test("should handle empty paths", () => {
expect(isPublicDomainRoute("")).toBe(false);
expect(isAdminDomainRoute("")).toBe(true);
expect(isAdminDomainRoute("")).toBe(true);
});
test("should handle paths with query parameters", () => {
expect(isPublicDomainRoute("/s/survey123?param=value")).toBe(true);
expect(isPublicDomainRoute("/environments/123?tab=settings")).toBe(false);
});
test("should handle paths with fragments", () => {
expect(isPublicDomainRoute("/s/survey123#section")).toBe(true);
expect(isPublicDomainRoute("/environments/123#overview")).toBe(false);
});
test("should handle nested survey routes", () => {
expect(isPublicDomainRoute("/s/survey123/preview")).toBe(true);
expect(isPublicDomainRoute("/s/survey123/embed")).toBe(true);
});
test("should handle nested client API routes", () => {
expect(isPublicDomainRoute("/api/v1/client/env123/actions")).toBe(true);
expect(isPublicDomainRoute("/api/v2/client/env456/responses")).toBe(true);
});
});
});

View File

@@ -1,3 +1,9 @@
import {
getAllPubliclyAccessibleRoutePatterns,
getPublicDomainRoutePatterns,
matchesAnyPattern,
} from "./route-config";
export const isLoginRoute = (url: string) =>
url === "/api/auth/callback/credentials" || url === "/auth/login";
@@ -8,6 +14,9 @@ export const isVerifyEmailRoute = (url: string) => url === "/auth/verify-email";
export const isForgotPasswordRoute = (url: string) => url === "/auth/forgot-password";
export const isClientSideApiRoute = (url: string): boolean => {
// Open Graph image generation route is a client side API route but it should not be rate limited
if (url.includes("/api/v1/client/og")) return false;
if (url.includes("/api/v1/js/actions")) return true;
if (url.includes("/api/v1/client/storage")) return true;
const regex = /^\/api\/v\d+\/client\//;
@@ -38,3 +47,39 @@ export const isSyncWithUserIdentificationEndpoint = (
const match = url.match(regex);
return match ? { environmentId: match.groups!.environmentId, userId: match.groups!.userId } : false;
};
/**
* Check if the route should be accessible on the public domain (PUBLIC_URL)
* Uses whitelist approach - only explicitly allowed routes are accessible
*/
export const isPublicDomainRoute = (url: string): boolean => {
const publicRoutePatterns = getAllPubliclyAccessibleRoutePatterns();
return matchesAnyPattern(url, publicRoutePatterns);
};
/**
* Check if the route should be accessible on the admin domain (WEBAPP_URL)
* When PUBLIC_URL is configured, admin domain should only allow admin-specific routes + health
*/
export const isAdminDomainRoute = (url: string): boolean => {
const publicOnlyRoutePatterns = getPublicDomainRoutePatterns();
const isPublicRoute = matchesAnyPattern(url, publicOnlyRoutePatterns);
if (isPublicRoute) {
return false;
}
// For non-public routes, allow them (includes known admin routes and unknown routes like pipeline, cron)
return true;
};
/**
* Determine if a request should be allowed based on domain and route
*/
export const isRouteAllowedForDomain = (url: string, isPublicDomain: boolean): boolean => {
if (isPublicDomain) {
return isPublicDomainRoute(url);
}
return isAdminDomainRoute(url);
};

View File

@@ -0,0 +1,54 @@
/**
* Routes that should be accessible on the public domain (PUBLIC_URL)
* Uses whitelist approach - only these routes are allowed on public domain
*/
const PUBLIC_ROUTES = {
// Survey routes
SURVEY_ROUTES: [
/^\/s\/[^/]+/, // /s/[surveyId] - survey pages
/^\/c\/[^/]+/, // /c/[jwt] - contact survey pages
],
// API routes accessible from public domain
API_ROUTES: [
/^\/api\/v[12]\/client\//, // /api/v1/client/** and /api/v2/client/**
],
// Share routes
SHARE_ROUTES: [
/^\/share\//, // /share/** - shared survey results
],
} as const;
const COMMON_ROUTES = {
HEALTH_ROUTES: [/^\/health$/], // /health endpoint
PUBLIC_STORAGE_ROUTES: [
/^\/storage\/[^/]+\/public\//, // /storage/[environmentId]/public/** - public storage
],
} as const;
/**
* Get public only route patterns as a flat array
*/
export const getPublicDomainRoutePatterns = (): RegExp[] => {
return Object.values(PUBLIC_ROUTES).flat();
};
/**
* Get all public route patterns as a flat array
*/
export const getAllPubliclyAccessibleRoutePatterns = (): RegExp[] => {
const routes = {
...PUBLIC_ROUTES,
...COMMON_ROUTES,
};
return Object.values(routes).flat();
};
/**
* Check if a URL matches any of the given route patterns
*/
export const matchesAnyPattern = (url: string, patterns: RegExp[]): boolean => {
return patterns.some((pattern) => pattern.test(url));
};

View File

@@ -1,7 +1,8 @@
import { SurveyAnalysisNavigation } from "@/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/components/SurveyAnalysisNavigation";
import { ResponsePage } from "@/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/responses/components/ResponsePage";
import { RESPONSES_PER_PAGE, WEBAPP_URL } from "@/lib/constants";
import { RESPONSES_PER_PAGE } from "@/lib/constants";
import { getEnvironment } from "@/lib/environment/service";
import { getPublicDomain } from "@/lib/getPublicUrl";
import { getProjectByEnvironmentId } from "@/lib/project/service";
import { getSurvey, getSurveyIdByResultShareKey } from "@/lib/survey/service";
import { getTagsByEnvironmentId } from "@/lib/tag/service";
@@ -46,6 +47,7 @@ const Page = async (props: ResponsesPageProps) => {
}
const locale = await findMatchingLocale();
const publicDomain = getPublicDomain();
return (
<div className="flex w-full justify-center">
@@ -57,7 +59,7 @@ const Page = async (props: ResponsesPageProps) => {
environment={environment}
survey={survey}
surveyId={surveyId}
webAppUrl={WEBAPP_URL}
publicDomain={publicDomain}
environmentTags={tags}
responsesPerPage={RESPONSES_PER_PAGE}
locale={locale}

View File

@@ -1,8 +1,9 @@
import { SurveyAnalysisNavigation } from "@/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/components/SurveyAnalysisNavigation";
import { SummaryPage } from "@/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/SummaryPage";
import { getSurveySummary } from "@/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/lib/surveySummary";
import { DEFAULT_LOCALE, WEBAPP_URL } from "@/lib/constants";
import { DEFAULT_LOCALE } from "@/lib/constants";
import { getEnvironment } from "@/lib/environment/service";
import { getPublicDomain } from "@/lib/getPublicUrl";
import { getProjectByEnvironmentId } from "@/lib/project/service";
import { getSurvey, getSurveyIdByResultShareKey } from "@/lib/survey/service";
import { PageContentWrapper } from "@/modules/ui/components/page-content-wrapper";
@@ -50,6 +51,8 @@ const Page = async (props: SummaryPageProps) => {
// Fetch initial survey summary data on the server to prevent duplicate API calls during hydration
const initialSurveySummary = await getSurveySummary(surveyId);
const publicDomain = getPublicDomain();
return (
<div className="flex w-full justify-center">
<PageContentWrapper className="w-full">
@@ -60,7 +63,7 @@ const Page = async (props: SummaryPageProps) => {
environment={environment}
survey={survey}
surveyId={survey.id}
webAppUrl={WEBAPP_URL}
publicDomain={publicDomain}
isReadOnly={true}
locale={DEFAULT_LOCALE}
initialSurveySummary={initialSurveySummary}

View File

@@ -13,8 +13,6 @@ export const E2E_TESTING = env.E2E_TESTING === "1";
export const WEBAPP_URL =
env.WEBAPP_URL || (env.VERCEL_URL ? `https://${env.VERCEL_URL}` : false) || "http://localhost:3000";
export const SURVEY_URL = env.SURVEY_URL;
// encryption keys
export const ENCRYPTION_KEY = env.ENCRYPTION_KEY;

View File

@@ -85,7 +85,23 @@ export const env = createEnv({
SMTP_REJECT_UNAUTHORIZED_TLS: z.enum(["1", "0"]).optional(),
STRIPE_SECRET_KEY: z.string().optional(),
STRIPE_WEBHOOK_SECRET: z.string().optional(),
SURVEY_URL: z.string().optional(),
PUBLIC_URL: z
.string()
.url()
.refine(
(url) => {
try {
const parsed = new URL(url);
return parsed.host && parsed.host.length > 0;
} catch {
return false;
}
},
{
message: "PUBLIC_URL must be a valid URL with a proper host (e.g., https://example.com)",
}
)
.optional(),
TELEMETRY_DISABLED: z.enum(["1", "0"]).optional(),
TERMS_URL: z
.string()
@@ -190,7 +206,7 @@ export const env = createEnv({
SMTP_AUTHENTICATED: process.env.SMTP_AUTHENTICATED,
STRIPE_SECRET_KEY: process.env.STRIPE_SECRET_KEY,
STRIPE_WEBHOOK_SECRET: process.env.STRIPE_WEBHOOK_SECRET,
SURVEY_URL: process.env.SURVEY_URL,
PUBLIC_URL: process.env.PUBLIC_URL,
TELEMETRY_DISABLED: process.env.TELEMETRY_DISABLED,
TURNSTILE_SECRET_KEY: process.env.TURNSTILE_SECRET_KEY,
TURNSTILE_SITE_KEY: process.env.TURNSTILE_SITE_KEY,

View File

@@ -0,0 +1,44 @@
import { beforeEach, describe, expect, test, vi } from "vitest";
// Mock constants module
const envMock = {
env: {
WEBAPP_URL: "http://localhost:3000",
PUBLIC_URL: undefined as string | undefined,
},
};
vi.mock("@/lib/env", () => envMock);
describe("getPublicDomain", () => {
beforeEach(() => {
vi.resetModules();
});
test("should return WEBAPP_URL when PUBLIC_URL is not set", async () => {
const { getPublicDomain } = await import("./getPublicUrl");
const domain = getPublicDomain();
expect(domain).toBe("http://localhost:3000");
});
test("should return PUBLIC_URL when it is set", async () => {
envMock.env.PUBLIC_URL = "https://surveys.example.com";
const { getPublicDomain } = await import("./getPublicUrl");
const domain = getPublicDomain();
expect(domain).toBe("https://surveys.example.com");
});
test("should handle empty string PUBLIC_URL by returning WEBAPP_URL", async () => {
envMock.env.PUBLIC_URL = "";
const { getPublicDomain } = await import("./getPublicUrl");
const domain = getPublicDomain();
expect(domain).toBe("http://localhost:3000");
});
test("should handle undefined PUBLIC_URL by returning WEBAPP_URL", async () => {
envMock.env.PUBLIC_URL = undefined;
const { getPublicDomain } = await import("./getPublicUrl");
const domain = getPublicDomain();
expect(domain).toBe("http://localhost:3000");
});
});

View File

@@ -0,0 +1,13 @@
import "server-only";
import { env } from "./env";
const WEBAPP_URL =
env.WEBAPP_URL ?? (env.VERCEL_URL ? `https://${env.VERCEL_URL}` : "") ?? "http://localhost:3000";
/**
* Returns the public domain URL
* Uses PUBLIC_URL if set, otherwise falls back to WEBAPP_URL
*/
export const getPublicDomain = (): string => {
return env.PUBLIC_URL && env.PUBLIC_URL.trim() !== "" ? env.PUBLIC_URL : WEBAPP_URL;
};

View File

@@ -1,46 +0,0 @@
import { beforeEach, describe, expect, test, vi } from "vitest";
// Create a mock module for constants with proper types
const constantsMock = {
SURVEY_URL: undefined as string | undefined,
WEBAPP_URL: "http://localhost:3000" as string,
};
// Mock the constants module
vi.mock("./constants", () => constantsMock);
describe("getSurveyDomain", () => {
beforeEach(() => {
// Reset the mock values before each test
constantsMock.SURVEY_URL = undefined;
constantsMock.WEBAPP_URL = "http://localhost:3000";
vi.resetModules();
});
test("should return WEBAPP_URL when SURVEY_URL is not set", async () => {
const { getSurveyDomain } = await import("./getSurveyUrl");
const domain = getSurveyDomain();
expect(domain).toBe("http://localhost:3000");
});
test("should return SURVEY_URL when it is set", async () => {
constantsMock.SURVEY_URL = "https://surveys.example.com";
const { getSurveyDomain } = await import("./getSurveyUrl");
const domain = getSurveyDomain();
expect(domain).toBe("https://surveys.example.com");
});
test("should handle empty string SURVEY_URL by returning WEBAPP_URL", async () => {
constantsMock.SURVEY_URL = "";
const { getSurveyDomain } = await import("./getSurveyUrl");
const domain = getSurveyDomain();
expect(domain).toBe("http://localhost:3000");
});
test("should handle undefined SURVEY_URL by returning WEBAPP_URL", async () => {
constantsMock.SURVEY_URL = undefined;
const { getSurveyDomain } = await import("./getSurveyUrl");
const domain = getSurveyDomain();
expect(domain).toBe("http://localhost:3000");
});
});

View File

@@ -1,10 +0,0 @@
import "server-only";
import { SURVEY_URL, WEBAPP_URL } from "./constants";
/**
* Returns the base URL for public surveys
* Uses SURVEY_URL if set, otherwise falls back to WEBAPP_URL
*/
export const getSurveyDomain = (): string => {
return SURVEY_URL || WEBAPP_URL;
};

View File

@@ -15,6 +15,15 @@ vi.mock("@aws-sdk/client-s3", () => ({
GetObjectCommand: vi.fn(),
}));
vi.mock("@aws-sdk/s3-presigned-post", () => ({
createPresignedPost: vi.fn(() =>
Promise.resolve({
url: "https://test-bucket.s3.test-region.amazonaws.com",
fields: { key: "test-key", policy: "test-policy" },
})
),
}));
// Mock environment variables
vi.mock("../constants", () => ({
S3_ACCESS_KEY: "test-access-key",
@@ -34,11 +43,32 @@ vi.mock("../constants", () => ({
UPLOADS_DIR: "/tmp/uploads",
}));
// Mock getPublicDomain
vi.mock("../getPublicUrl", () => ({
getPublicDomain: () => "https://public-domain.com",
}));
// Mock crypto functions
vi.mock("crypto", () => ({
randomUUID: () => "test-uuid",
}));
// Mock local signed url generation
vi.mock("../crypto", () => ({
generateLocalSignedUrl: () => ({
signature: "test-signature",
timestamp: 123456789,
uuid: "test-uuid",
}),
}));
// Mock env
vi.mock("../env", () => ({
env: {
S3_BUCKET_NAME: "test-bucket",
},
}));
describe("Storage Service", () => {
beforeEach(() => {
vi.clearAllMocks();
@@ -131,4 +161,38 @@ describe("Storage Service", () => {
await expect(putFile(fileName, fileBuffer, accessType, environmentId)).rejects.toThrow("Upload failed");
});
});
describe("getUploadSignedUrl", () => {
let getUploadSignedUrl: any;
beforeEach(async () => {
const serviceModule = await import("./service");
getUploadSignedUrl = serviceModule.getUploadSignedUrl;
});
test("should use PUBLIC_URL for public files with S3", async () => {
const result = await getUploadSignedUrl("test.jpg", "env123", "image/jpeg", "public");
expect(result.fileUrl).toContain("https://public-domain.com");
expect(result.fileUrl).toMatch(
/https:\/\/public-domain\.com\/storage\/env123\/public\/test--fid--test-uuid\.jpg/
);
});
test("should use WEBAPP_URL for private files with S3", async () => {
const result = await getUploadSignedUrl("test.jpg", "env123", "image/jpeg", "private");
expect(result.fileUrl).toContain("http://test-webapp");
expect(result.fileUrl).toMatch(
/http:\/\/test-webapp\/storage\/env123\/private\/test--fid--test-uuid\.jpg/
);
});
test("should contain signed URL and presigned fields for S3", async () => {
const result = await getUploadSignedUrl("test.jpg", "env123", "image/jpeg", "public");
expect(result.signedUrl).toBe("https://test-bucket.s3.test-region.amazonaws.com");
expect(result.presignedFields).toEqual({ key: "test-key", policy: "test-policy" });
});
});
});

View File

@@ -31,6 +31,7 @@ import {
} from "../constants";
import { generateLocalSignedUrl } from "../crypto";
import { env } from "../env";
import { getPublicDomain } from "../getPublicUrl";
// S3Client Singleton
let s3ClientInstance: S3Client | null = null;
@@ -165,6 +166,10 @@ export const getUploadSignedUrl = async (
const updatedFileName = `${fileNameWithoutExtension}--fid--${randomUUID()}.${fileExtension}`;
// Use PUBLIC_URL for public files, WEBAPP_URL for private files
const publicDomain = getPublicDomain();
const baseUrl = accessType === "public" ? getPublicDomain() : WEBAPP_URL;
// handle the local storage case first
if (!isS3Configured()) {
try {
@@ -173,7 +178,7 @@ export const getUploadSignedUrl = async (
return {
signedUrl:
accessType === "private"
? new URL(`${WEBAPP_URL}/api/v1/client/${environmentId}/storage/local`).href
? new URL(`${publicDomain}/api/v1/client/${environmentId}/storage/local`).href
: new URL(`${WEBAPP_URL}/api/v1/management/storage/local`).href,
signingData: {
signature,
@@ -181,7 +186,7 @@ export const getUploadSignedUrl = async (
uuid,
},
updatedFileName,
fileUrl: new URL(`${WEBAPP_URL}/storage/${environmentId}/${accessType}/${updatedFileName}`).href,
fileUrl: new URL(`${baseUrl}/storage/${environmentId}/${accessType}/${updatedFileName}`).href,
};
} catch (err) {
throw err;
@@ -200,7 +205,7 @@ export const getUploadSignedUrl = async (
return {
signedUrl,
presignedFields,
fileUrl: new URL(`${WEBAPP_URL}/storage/${environmentId}/${accessType}/${updatedFileName}`).href,
fileUrl: new URL(`${baseUrl}/storage/${environmentId}/${accessType}/${updatedFileName}`).href,
};
} catch (err) {
throw err;

View File

@@ -79,7 +79,7 @@
},
"signup_without_verification_success": {
"user_successfully_created": "Benutzer erfolgreich erstellt",
"user_successfully_created_description": "Dein neuer Benutzer wurde erfolgreich erstellt. Bitte klicke auf den untenstehenden Button und melde Dich in deinem Konto an."
"user_successfully_created_info": "Wir haben nach einem Konto gesucht, das mit {email} verknüpft ist. Wenn keines existierte, haben wir eines für Dich erstellt. Wenn bereits ein Konto existierte, wurden keine Änderungen vorgenommen. Bitte melde Dich unten an, um fortzufahren."
},
"testimonial_1": "Als open-source Firma ist uns Datenschutz extrem wichtig! Formbricks bietet die perfekte Mischung aus modernster Technologie und solidem Datenschutz.",
"testimonial_all_features_included": "Alle Funktionen enthalten",
@@ -91,11 +91,10 @@
"invalid_token": "Ungültiges Token ☹️",
"new_email_verification_success": "Wenn die Adresse gültig ist, wurde eine Bestätigungs-E-Mail gesendet.",
"no_email_provided": "Keine E-Mail bereitgestellt",
"please_click_the_link_in_the_email_to_activate_your_account": "Bitte klicke auf den Link in der E-Mail, um dein Konto zu aktivieren.",
"please_confirm_your_email_address": "Bitte bestätige deine E-Mail-Adresse",
"resend_verification_email": "Bestätigungs-E-Mail erneut senden",
"verification_email_resent_successfully": "Bestätigungs-E-Mail gesendet! Bitte überprüfe dein Postfach.",
"we_sent_an_email_to": "Wir haben eine E-Mail an {email} gesendet",
"verification_email_successfully_sent_info": "Wenn ein Konto mit {email} verknüpft ist, haben wir einen Bestätigungslink an diese Adresse gesendet. Bitte überprüfe dein Postfach, um die Anmeldung abzuschließen.",
"you_didnt_receive_an_email_or_your_link_expired": "Hast Du keine E-Mail erhalten oder ist dein Link abgelaufen?"
},
"verify": {

View File

@@ -79,7 +79,7 @@
},
"signup_without_verification_success": {
"user_successfully_created": "User successfully created",
"user_successfully_created_description": "Your new user has been created successfully. Please click the button below and sign in to your account."
"user_successfully_created_info": "Weve checked for an account associated with {email}. If none existed, weve created one for you. If an account already existed, no changes were made. Please log in below to continue."
},
"testimonial_1": "We measure the clarity of our docs and learn from churn all on one platform. Great product, very responsive team!",
"testimonial_all_features_included": "All features included",
@@ -91,11 +91,10 @@
"invalid_token": "Invalid token ☹️",
"new_email_verification_success": "If the address is valid, a verification email has been sent.",
"no_email_provided": "No email provided",
"please_click_the_link_in_the_email_to_activate_your_account": "Please click the link in the email to activate your account.",
"please_confirm_your_email_address": "Please confirm your email address",
"resend_verification_email": "Resend verification email",
"verification_email_resent_successfully": "Verification email sent! Please check your inbox.",
"we_sent_an_email_to": "We sent an email to {email}. ",
"verification_email_successfully_sent_info": "If theres an account associated with {email}, weve sent a verification link to that address. Please check your inbox to complete the sign-up.",
"you_didnt_receive_an_email_or_your_link_expired": "You didn't receive an email or your link expired?"
},
"verify": {

View File

@@ -79,7 +79,7 @@
},
"signup_without_verification_success": {
"user_successfully_created": "Utilisateur créé avec succès",
"user_successfully_created_description": "Votre nouvel utilisateur a été créé avec succès. Veuillez cliquer sur le bouton ci-dessous et vous connecter à votre compte."
"user_successfully_created_info": "Nous avons vérifié s'il existait un compte associé à {email}. Si aucun n'existait, nous en avons créé un pour vous. Si un compte existait déjà, aucune modification n'a été apportée. Veuillez vous connecter ci-dessous pour continuer."
},
"testimonial_1": "Nous mesurons la clarté de nos documents et apprenons des abandons, le tout sur une seule plateforme. Excellent produit, équipe très réactive !",
"testimonial_all_features_included": "Toutes les fonctionnalités incluses",
@@ -91,11 +91,10 @@
"invalid_token": "Jeton non valide ☹️",
"new_email_verification_success": "Si l'adresse est valide, un email de vérification a été envoyé.",
"no_email_provided": "Aucun e-mail fourni",
"please_click_the_link_in_the_email_to_activate_your_account": "Veuillez cliquer sur le lien dans l'e-mail pour activer votre compte.",
"please_confirm_your_email_address": "Veuillez confirmer votre adresse e-mail.",
"resend_verification_email": "Renvoyer l'email de vérification",
"verification_email_resent_successfully": "E-mail de vérification envoyé ! Veuillez vérifier votre boîte de réception.",
"we_sent_an_email_to": "Nous avons envoyé un email à {email}",
"verification_email_successfully_sent_info": "Si un compte est associé à {email}, nous avons envoyé un lien de vérification à cette adresse. Veuillez vérifier votre boîte de réception pour terminer l'inscription.",
"you_didnt_receive_an_email_or_your_link_expired": "Vous n'avez pas reçu d'email ou votre lien a expiré ?"
},
"verify": {

View File

@@ -79,7 +79,7 @@
},
"signup_without_verification_success": {
"user_successfully_created": "Usuário criado com sucesso",
"user_successfully_created_description": "Seu novo usuário foi criado com sucesso. Por favor, clique no botão abaixo e faça login na sua conta."
"user_successfully_created_info": "Verificamos se há uma conta associada a {email}. Se não existia, criamos uma para você. Se uma conta já existia, nenhuma alteração foi feita. Por favor, faça login abaixo para continuar."
},
"testimonial_1": "Mediamos a clareza dos nossos documentos e aprendemos com a rotatividade tudo em uma única plataforma. Ótimo produto, equipe muito atenciosa!",
"testimonial_all_features_included": "Todas as funcionalidades incluídas",
@@ -91,11 +91,10 @@
"invalid_token": "Token inválido ☹️",
"new_email_verification_success": "Se o endereço for válido, um email de verificação foi enviado.",
"no_email_provided": "Nenhum e-mail fornecido",
"please_click_the_link_in_the_email_to_activate_your_account": "Por favor, clica no link do e-mail pra ativar sua conta.",
"please_confirm_your_email_address": "Por favor, confirme seu endereço de e-mail",
"resend_verification_email": "Reenviar e-mail de verificação",
"verification_email_resent_successfully": "E-mail de verificação enviado! Por favor, verifique sua caixa de entrada.",
"we_sent_an_email_to": "Enviamos um email para {email}",
"verification_email_successfully_sent_info": "Se houver uma conta associada a {email}, enviamos um link de verificação para esse endereço. Por favor, verifique sua caixa de entrada para completar o cadastro.",
"you_didnt_receive_an_email_or_your_link_expired": "Você não recebeu um e-mail ou seu link expirou?"
},
"verify": {

View File

@@ -79,7 +79,7 @@
},
"signup_without_verification_success": {
"user_successfully_created": "Utilizador criado com sucesso",
"user_successfully_created_description": "O seu novo utilizador foi criado com sucesso. Por favor, clique no botão abaixo e inicie sessão na sua conta."
"user_successfully_created_info": "Verificámos a existência de uma conta associada a {email}. Se não existia, criámos uma para si. Se já existia uma conta, não foram feitas alterações. Por favor, inicie sessão abaixo para continuar."
},
"testimonial_1": "Medimos a clareza dos nossos documentos e aprendemos com a rotatividade, tudo numa só plataforma. Ótimo produto, equipa muito responsiva!",
"testimonial_all_features_included": "Todas as funcionalidades incluídas",
@@ -91,11 +91,10 @@
"invalid_token": "Token inválido ☹️",
"new_email_verification_success": "Se o endereço for válido, um email de verificação foi enviado.",
"no_email_provided": "Nenhum email fornecido",
"please_click_the_link_in_the_email_to_activate_your_account": "Por favor, clique no link no email para ativar a sua conta.",
"please_confirm_your_email_address": "Por favor, confirme o seu endereço de email",
"resend_verification_email": "Reenviar email de verificação",
"verification_email_resent_successfully": "Email de verificação enviado! Por favor, verifique a sua caixa de entrada.",
"we_sent_an_email_to": "Enviámos um email para {email}. ",
"verification_email_successfully_sent_info": "Se houver uma conta associada a {email}, enviámos um link de verificação para esse endereço. Por favor, verifique a sua caixa de entrada para completar o registo.",
"you_didnt_receive_an_email_or_your_link_expired": "Não recebeu um email ou o seu link expirou?"
},
"verify": {

View File

@@ -79,7 +79,7 @@
},
"signup_without_verification_success": {
"user_successfully_created": "使用者建立成功",
"user_successfully_created_description": "您的新使用者已成功建立。請點擊下方按鈕並登入您的帳戶。"
"user_successfully_created_info": "我們已檢查與 {email} 相關聯的帳戶。如果不存在,我們已為您建立一個。如果帳戶已存在,則未進行任何更改。請在下方登入以繼續。"
},
"testimonial_1": "我們在同一個平台上測量文件的清晰度,並從客戶流失中學習。很棒的產品,團隊反應非常迅速!",
"testimonial_all_features_included": "包含所有功能",
@@ -91,11 +91,10 @@
"invalid_token": "無效的權杖 ☹️",
"new_email_verification_success": "如果地址有效,驗證電子郵件已發送。",
"no_email_provided": "未提供電子郵件",
"please_click_the_link_in_the_email_to_activate_your_account": "請點擊電子郵件中的連結以啟用您的帳戶。",
"please_confirm_your_email_address": "請確認您的電子郵件地址",
"resend_verification_email": "重新發送驗證電子郵件",
"verification_email_resent_successfully": "驗證電子郵件已發送!請檢查您的收件箱。",
"we_sent_an_email_to": "我們已發送一封電子郵件至 <email>'{'email'}'</email>。",
"verification_email_successfully_sent_info": "如果有一個帳戶與 {email} 相關聯,我們已發送驗證連結至該地址。請檢查您的收件箱以完成註冊。",
"you_didnt_receive_an_email_or_your_link_expired": "您沒有收到電子郵件或您的連結已過期?"
},
"verify": {

View File

@@ -7,17 +7,19 @@ import {
syncUserIdentificationLimiter,
verifyEmailLimiter,
} from "@/app/middleware/bucket";
import { isPublicDomainConfigured, isRequestFromPublicDomain } from "@/app/middleware/domain-utils";
import {
isAuthProtectedRoute,
isClientSideApiRoute,
isForgotPasswordRoute,
isLoginRoute,
isRouteAllowedForDomain,
isShareUrlRoute,
isSignupRoute,
isSyncWithUserIdentificationEndpoint,
isVerifyEmailRoute,
} from "@/app/middleware/endpoint-validator";
import { IS_PRODUCTION, RATE_LIMITING_DISABLED, SURVEY_URL, WEBAPP_URL } from "@/lib/constants";
import { IS_PRODUCTION, RATE_LIMITING_DISABLED, WEBAPP_URL } from "@/lib/constants";
import { getClientIpFromHeaders } from "@/lib/utils/client-ip";
import { isValidCallbackUrl } from "@/lib/utils/url";
import { logApiErrorEdge } from "@/modules/api/v2/lib/utils-edge";
@@ -69,33 +71,38 @@ const applyRateLimiting = async (request: NextRequest, ip: string) => {
}
};
const handleSurveyDomain = (request: NextRequest): Response | null => {
/**
* Handle domain-aware routing based on PUBLIC_URL and WEBAPP_URL
*/
const handleDomainAwareRouting = (request: NextRequest): Response | null => {
try {
if (!SURVEY_URL) return null;
const publicDomainConfigured = isPublicDomainConfigured();
const host = request.headers.get("host") || "";
const surveyDomain = SURVEY_URL ? new URL(SURVEY_URL).host : "";
if (host !== surveyDomain) return null;
// When PUBLIC_URL is not configured, admin domain allows all routes (backward compatibility)
if (!publicDomainConfigured) return null;
return new NextResponse(null, { status: 404 });
const isPublicDomain = isRequestFromPublicDomain(request);
const pathname = request.nextUrl.pathname;
// Check if the route is allowed for the current domain
const isAllowed = isRouteAllowedForDomain(pathname, isPublicDomain);
if (!isAllowed) {
return new NextResponse(null, { status: 404 });
}
return null; // Allow the request to continue
} catch (error) {
logger.error(error, "Error handling survey domain");
logger.error(error, "Error handling domain-aware routing");
return new NextResponse(null, { status: 404 });
}
};
const isSurveyRoute = (request: NextRequest) => {
return request.nextUrl.pathname.startsWith("/c/") || request.nextUrl.pathname.startsWith("/s/");
};
export const middleware = async (originalRequest: NextRequest) => {
if (isSurveyRoute(originalRequest)) {
return NextResponse.next();
}
// Handle survey domain routing.
const surveyResponse = handleSurveyDomain(originalRequest);
if (surveyResponse) return surveyResponse;
// Handle domain-aware routing first
const domainResponse = handleDomainAwareRouting(originalRequest);
if (domainResponse) return domainResponse;
// Create a new Request object to override headers and add a unique request ID header
const request = new NextRequest(originalRequest, {
@@ -142,6 +149,6 @@ export const middleware = async (originalRequest: NextRequest) => {
export const config = {
matcher: [
"/((?!_next/static|_next/image|favicon.ico|sitemap.xml|robots.txt|js|css|images|fonts|icons|public|api/v1/og).*)", // Exclude the Open Graph image generation route from middleware
"/((?!_next/static|_next/image|favicon.ico|sitemap.xml|robots.txt|js|css|images|fonts|icons|public).*)",
],
};

View File

@@ -61,20 +61,20 @@ describe("RatingSmiley", () => {
cleanup();
});
const activeClass = "fill-rating-fill";
const activeClass = "bg-rating-fill";
// Test branch: range === 10 => iconsIdx = [0,1,2,...,9]
test("renders correct icon for range 10 when active", () => {
// For idx 0, iconsIdx[0] === 0, which corresponds to TiredFace.
const { getByTestId } = render(<RatingSmiley active={true} idx={0} range={10} addColors={true} />);
const icon = getByTestId("TiredFace");
const icon = getByTestId("tired");
expect(icon).toBeDefined();
expect(icon.className).toContain(activeClass);
});
test("renders correct icon for range 10 when inactive", () => {
const { getByTestId } = render(<RatingSmiley active={false} idx={0} range={10} />);
const icon = getByTestId("TiredFace");
const icon = getByTestId("tired");
expect(icon).toBeDefined();
expect(icon.className).toContain("fill-none");
});
@@ -83,7 +83,7 @@ describe("RatingSmiley", () => {
test("renders correct icon for range 7 when active", () => {
// For idx 0, iconsIdx[0] === 1, which corresponds to WearyFace.
const { getByTestId } = render(<RatingSmiley active={true} idx={0} range={7} addColors={true} />);
const icon = getByTestId("WearyFace");
const icon = getByTestId("weary");
expect(icon).toBeDefined();
expect(icon.className).toContain(activeClass);
});
@@ -92,7 +92,7 @@ describe("RatingSmiley", () => {
test("renders correct icon for range 5 when active", () => {
// For idx 0, iconsIdx[0] === 3, which corresponds to FrowningFace.
const { getByTestId } = render(<RatingSmiley active={true} idx={0} range={5} addColors={true} />);
const icon = getByTestId("FrowningFace");
const icon = getByTestId("frowning");
expect(icon).toBeDefined();
expect(icon.className).toContain(activeClass);
});
@@ -101,7 +101,7 @@ describe("RatingSmiley", () => {
test("renders correct icon for range 4 when active", () => {
// For idx 0, iconsIdx[0] === 4, corresponding to ConfusedFace.
const { getByTestId } = render(<RatingSmiley active={true} idx={0} range={4} addColors={true} />);
const icon = getByTestId("ConfusedFace");
const icon = getByTestId("confused");
expect(icon).toBeDefined();
expect(icon.className).toContain(activeClass);
});
@@ -110,7 +110,7 @@ describe("RatingSmiley", () => {
test("renders correct icon for range 3 when active", () => {
// For idx 0, iconsIdx[0] === 4, corresponding to ConfusedFace.
const { getByTestId } = render(<RatingSmiley active={true} idx={0} range={3} addColors={true} />);
const icon = getByTestId("ConfusedFace");
const icon = getByTestId("confused");
expect(icon).toBeDefined();
expect(icon.className).toContain(activeClass);
});

View File

@@ -1,93 +1,89 @@
import type { JSX } from "react";
import {
ConfusedFace,
FrowningFace,
GrinningFaceWithSmilingEyes,
GrinningSquintingFace,
NeutralFace,
PerseveringFace,
SlightlySmilingFace,
SmilingFaceWithSmilingEyes,
TiredFace,
WearyFace,
} from "../SingleResponseCard/components/Smileys";
interface RatingSmileyProps {
active: boolean;
idx: number;
range: number;
addColors?: boolean;
baseUrl?: string;
}
const getSmileyColor = (range: number, idx: number) => {
if (range > 5) {
if (range - idx < 3) return "fill-emerald-100";
if (range - idx < 5) return "fill-orange-100";
return "fill-rose-100";
if (range - idx < 3) return "bg-emerald-100";
if (range - idx < 5) return "bg-orange-100";
return "bg-rose-100";
} else if (range < 5) {
if (range - idx < 2) return "fill-emerald-100";
if (range - idx < 3) return "fill-orange-100";
return "fill-rose-100";
if (range - idx < 2) return "bg-emerald-100";
if (range - idx < 3) return "bg-orange-100";
return "bg-rose-100";
} else {
if (range - idx < 3) return "fill-emerald-100";
if (range - idx < 4) return "fill-orange-100";
return "fill-rose-100";
if (range - idx < 3) return "bg-emerald-100";
if (range - idx < 4) return "bg-orange-100";
return "bg-rose-100";
}
};
const getSmiley = (iconIdx: number, idx: number, range: number, active: boolean, addColors: boolean) => {
const activeColor = "fill-rating-fill";
const inactiveColor = addColors ? getSmileyColor(range, idx) : "fill-none";
// Helper function to get smiley image URL based on index and range
const getSmiley = (
iconIdx: number,
idx: number,
range: number,
active: boolean,
addColors: boolean,
baseUrl?: string
): JSX.Element => {
const activeColor = "bg-rating-fill";
const inactiveColor = addColors ? getSmileyColor(range, idx) : "bg-fill-none";
const icons = [
<TiredFace className={active ? activeColor : inactiveColor} data-testid="TiredFace" key="tired-face" />,
<WearyFace className={active ? activeColor : inactiveColor} data-testid="WearyFace" key="weary-face" />,
<PerseveringFace
className={active ? activeColor : inactiveColor}
data-testid="PerseveringFace"
key="perserving-face"
/>,
<FrowningFace
className={active ? activeColor : inactiveColor}
data-testid="FrowningFace"
key="frowning-face"
/>,
<ConfusedFace
className={active ? activeColor : inactiveColor}
data-testid="ConfusedFace"
key="confused-face"
/>,
<NeutralFace
className={active ? activeColor : inactiveColor}
data-testid="NeutralFace"
key="neutral-face"
/>,
<SlightlySmilingFace
className={active ? activeColor : inactiveColor}
data-testid="SlightlySmilingFace"
key="slightly-smiling-face"
/>,
<SmilingFaceWithSmilingEyes
className={active ? activeColor : inactiveColor}
data-testid="SmilingFaceWithSmilingEyes"
key="smiling-face-with-smiling-eyes"
/>,
<GrinningFaceWithSmilingEyes
className={active ? activeColor : inactiveColor}
data-testid="GrinningFaceWithSmilingEyes"
key="grinning-face-with-smiling-eyes"
/>,
<GrinningSquintingFace
className={active ? activeColor : inactiveColor}
data-testid="GrinningSquintingFace"
key="grinning-squinting-face"
/>,
const faceIcons = [
"tired",
"weary",
"persevering",
"frowning",
"confused",
"neutral",
"slightly-smiling",
"smiling-face-with-smiling-eyes",
"grinning-face-with-smiling-eyes",
"grinning-squinting",
];
return icons[iconIdx];
const icon = (
<img
data-testid={faceIcons[iconIdx]}
src={
baseUrl
? `${baseUrl}/smiley-icons/${faceIcons[iconIdx]}-face.png`
: `/smiley-icons/${faceIcons[iconIdx]}-face.png`
}
alt={faceIcons[iconIdx]}
width={24}
height={24}
className={`${active ? activeColor : inactiveColor} rounded-full`}
/>
);
return (
<table style={{ width: "48px", height: "48px" }}>
{" "}
{/* NOSONAR S5256 - Need table layout for email compatibility (gmail) */}
<tr>
<td align="center" valign="middle">
{icon}
</td>
</tr>
</table>
);
};
export const RatingSmiley = ({ active, idx, range, addColors = false }: RatingSmileyProps): JSX.Element => {
export const RatingSmiley = ({
active,
idx,
range,
addColors = false,
baseUrl,
}: RatingSmileyProps): JSX.Element => {
let iconsIdx: number[] = [];
if (range === 10) iconsIdx = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
else if (range === 7) iconsIdx = [1, 3, 4, 5, 6, 8, 9];
@@ -96,5 +92,5 @@ export const RatingSmiley = ({ active, idx, range, addColors = false }: RatingSm
else if (range === 4) iconsIdx = [4, 5, 6, 7];
else if (range === 3) iconsIdx = [4, 5, 7];
return getSmiley(iconsIdx[idx], idx, range, active, addColors);
return getSmiley(iconsIdx[idx], idx, range, active, addColors, baseUrl);
};

View File

@@ -13,7 +13,7 @@ const dummySurvey = {
type: "link",
status: "completed",
} as any;
const dummySurveyDomain = "http://dummy.com";
const dummyPublicDomain = "http://dummy.com";
const dummyLocale = "en-US";
vi.mock("@/lib/constants", () => ({
@@ -93,7 +93,7 @@ describe("ShareSurveyLink", () => {
render(
<ShareSurveyLink
survey={dummySurvey}
surveyDomain={dummySurveyDomain}
publicDomain={dummyPublicDomain}
surveyUrl=""
setSurveyUrl={setSurveyUrl}
locale={dummyLocale}
@@ -103,7 +103,7 @@ describe("ShareSurveyLink", () => {
expect(setSurveyUrl).toHaveBeenCalled();
});
const url = setSurveyUrl.mock.calls[0][0];
expect(url).toContain(`${dummySurveyDomain}/s/${dummySurvey.id}?suId=dummySuId`);
expect(url).toContain(`${dummyPublicDomain}/s/${dummySurvey.id}?suId=dummySuId`);
expect(url).not.toContain("lang=");
});
@@ -114,7 +114,7 @@ describe("ShareSurveyLink", () => {
const DummyWrapper = () => (
<ShareSurveyLink
survey={dummySurvey}
surveyDomain={dummySurveyDomain}
publicDomain={dummyPublicDomain}
surveyUrl="initial"
setSurveyUrl={setSurveyUrl}
locale="fr-FR"
@@ -130,12 +130,12 @@ describe("ShareSurveyLink", () => {
test("preview button opens new window with preview query", async () => {
vi.mocked(generateSingleUseIdAction).mockResolvedValue({ data: "dummySuId" });
const setSurveyUrl = vi.fn().mockReturnValue(`${dummySurveyDomain}/s/${dummySurvey.id}?suId=dummySuId`);
const setSurveyUrl = vi.fn().mockReturnValue(`${dummyPublicDomain}/s/${dummySurvey.id}?suId=dummySuId`);
render(
<ShareSurveyLink
survey={dummySurvey}
surveyDomain={dummySurveyDomain}
surveyUrl={`${dummySurveyDomain}/s/${dummySurvey.id}?suId=dummySuId`}
publicDomain={dummyPublicDomain}
surveyUrl={`${dummyPublicDomain}/s/${dummySurvey.id}?suId=dummySuId`}
setSurveyUrl={setSurveyUrl}
locale={dummyLocale}
/>
@@ -156,11 +156,11 @@ describe("ShareSurveyLink", () => {
vi.mocked(copySurveyLink).mockImplementation((url: string, newId: string) => `${url}?suId=${newId}`);
const setSurveyUrl = vi.fn();
const surveyUrl = `${dummySurveyDomain}/s/${dummySurvey.id}?suId=dummySuId`;
const surveyUrl = `${dummyPublicDomain}/s/${dummySurvey.id}?suId=dummySuId`;
render(
<ShareSurveyLink
survey={dummySurvey}
surveyDomain={dummySurveyDomain}
publicDomain={dummyPublicDomain}
surveyUrl={surveyUrl}
setSurveyUrl={setSurveyUrl}
locale={dummyLocale}
@@ -185,8 +185,8 @@ describe("ShareSurveyLink", () => {
render(
<ShareSurveyLink
survey={dummySurvey}
surveyDomain={dummySurveyDomain}
surveyUrl={`${dummySurveyDomain}/s/${dummySurvey.id}?suId=dummySuId`}
publicDomain={dummyPublicDomain}
surveyUrl={`${dummyPublicDomain}/s/${dummySurvey.id}?suId=dummySuId`}
setSurveyUrl={setSurveyUrl}
locale={dummyLocale}
/>
@@ -205,8 +205,8 @@ describe("ShareSurveyLink", () => {
render(
<ShareSurveyLink
survey={dummySurvey}
surveyDomain={dummySurveyDomain}
surveyUrl={`${dummySurveyDomain}/s/${dummySurvey.id}?suId=dummySuId`}
publicDomain={dummyPublicDomain}
surveyUrl={`${dummyPublicDomain}/s/${dummySurvey.id}?suId=dummySuId`}
setSurveyUrl={setSurveyUrl}
locale={dummyLocale}
/>
@@ -227,7 +227,7 @@ describe("ShareSurveyLink", () => {
render(
<ShareSurveyLink
survey={dummySurvey}
surveyDomain={dummySurveyDomain}
publicDomain={dummyPublicDomain}
surveyUrl=""
setSurveyUrl={setSurveyUrl}
locale={dummyLocale}

View File

@@ -15,7 +15,7 @@ import { SurveyLinkDisplay } from "./components/SurveyLinkDisplay";
interface ShareSurveyLinkProps {
survey: TSurvey;
surveyDomain: string;
publicDomain: string;
surveyUrl: string;
setSurveyUrl: (url: string) => void;
locale: TUserLocale;
@@ -24,7 +24,7 @@ interface ShareSurveyLinkProps {
export const ShareSurveyLink = ({
survey,
surveyUrl,
surveyDomain,
publicDomain,
setSurveyUrl,
locale,
}: ShareSurveyLinkProps) => {
@@ -34,7 +34,7 @@ export const ShareSurveyLink = ({
useEffect(() => {
const fetchSurveyUrl = async () => {
try {
const url = await getSurveyUrl(survey, surveyDomain, language);
const url = await getSurveyUrl(survey, publicDomain, language);
setSurveyUrl(url);
} catch (error) {
const errorMessage = getFormattedErrorMessage(error);
@@ -42,11 +42,11 @@ export const ShareSurveyLink = ({
}
};
fetchSurveyUrl();
}, [survey, language, surveyDomain, setSurveyUrl]);
}, [survey, language, publicDomain, setSurveyUrl]);
const generateNewSingleUseLink = async () => {
try {
const newUrl = await getSurveyUrl(survey, surveyDomain, language);
const newUrl = await getSurveyUrl(survey, publicDomain, language);
setSurveyUrl(newUrl);
toast.success(t("environments.surveys.new_single_use_link_generated"));
} catch (error) {

View File

@@ -1,60 +0,0 @@
import { cleanup, render } from "@testing-library/react";
import { afterEach, describe, expect, test } from "vitest";
import {
ConfusedFace,
FrowningFace,
GrinningFaceWithSmilingEyes,
GrinningSquintingFace,
NeutralFace,
PerseveringFace,
SlightlySmilingFace,
SmilingFaceWithSmilingEyes,
TiredFace,
WearyFace,
} from "./Smileys";
const checkSvg = (Component: React.FC<React.SVGProps<SVGElement>>) => {
const { container } = render(<Component />);
const svg = container.querySelector("svg");
expect(svg).toBeTruthy();
expect(svg).toHaveAttribute("viewBox", "0 0 72 72");
expect(svg).toHaveAttribute("width", "36");
expect(svg).toHaveAttribute("height", "36");
};
describe("Smileys", () => {
afterEach(() => {
cleanup();
});
test("renders TiredFace", () => {
checkSvg(TiredFace);
});
test("renders WearyFace", () => {
checkSvg(WearyFace);
});
test("renders PerseveringFace", () => {
checkSvg(PerseveringFace);
});
test("renders FrowningFace", () => {
checkSvg(FrowningFace);
});
test("renders ConfusedFace", () => {
checkSvg(ConfusedFace);
});
test("renders NeutralFace", () => {
checkSvg(NeutralFace);
});
test("renders SlightlySmilingFace", () => {
checkSvg(SlightlySmilingFace);
});
test("renders SmilingFaceWithSmilingEyes", () => {
checkSvg(SmilingFaceWithSmilingEyes);
});
test("renders GrinningFaceWithSmilingEyes", () => {
checkSvg(GrinningFaceWithSmilingEyes);
});
test("renders GrinningSquintingFace", () => {
checkSvg(GrinningSquintingFace);
});
});

View File

@@ -1,462 +0,0 @@
export const TiredFace: React.FC<React.SVGProps<SVGCircleElement>> = (props) => {
return (
<svg viewBox="0 0 72 72" xmlns="http://www.w3.org/2000/svg" width={36} height={36}>
<g id="line">
<circle
cx="36"
cy="36"
r="23"
fill="none"
stroke="currentColor"
strokeMiterlimit="10"
strokeWidth="2"
{...props}
/>
<path
fill="none"
stroke="currentColor"
strokeLinecap="round"
strokeLinejoin="round"
strokeMiterlimit="10"
strokeWidth="2"
d="m21.88 23.92c5.102-0.06134 7.273-1.882 8.383-3.346"
/>
<path
stroke="currentColor"
strokeMiterlimit="10"
strokeWidth="2"
d="m46.24 47.56c0-2.592-2.867-7.121-10.25-6.93-6.974 0.1812-10.22 4.518-10.22 7.111s4.271-1.611 10.05-1.492c6.317 0.13 10.43 3.903 10.43 1.311z"
/>
<path
fill="none"
stroke="currentColor"
strokeLinecap="round"
strokeLinejoin="round"
strokeMiterlimit="10"
strokeWidth="2"
d="m23.16 28.47c5.215 1.438 5.603 0.9096 8.204 1.207 1.068 0.1221-2.03 2.67-7.282 4.397"
/>
<path
fill="none"
stroke="currentColor"
strokeLinecap="round"
strokeLinejoin="round"
strokeMiterlimit="10"
strokeWidth="2"
d="m50.12 23.92c-5.102-0.06134-7.273-1.882-8.383-3.346"
/>
<path
fill="none"
stroke="currentColor"
strokeLinecap="round"
strokeLinejoin="round"
strokeMiterlimit="10"
strokeWidth="2"
d="m48.84 28.47c-5.215 1.438-5.603 0.9096-8.204 1.207-1.068 0.1221 2.03 2.67 7.282 4.397"
/>
</g>
</svg>
);
};
export const WearyFace: React.FC<React.SVGProps<SVGCircleElement>> = (props) => {
return (
<svg viewBox="0 0 72 72" xmlns="http://www.w3.org/2000/svg" width={36} height={36}>
<g id="line">
<circle
cx="36"
cy="36"
r="23"
fill="none"
stroke="currentColor"
strokeMiterlimit="10"
strokeWidth="2"
{...props}
/>
<path
fill="none"
stroke="currentColor"
strokeLinecap="round"
strokeLinejoin="round"
strokeMiterlimit="10"
strokeWidth="2"
d="m22.88 23.92c5.102-0.06134 7.273-1.882 8.383-3.346"
/>
<path
stroke="currentColor"
strokeMiterlimit="10"
strokeWidth="2"
d="m46.24 47.56c0-2.592-2.867-7.121-10.25-6.93-6.974 0.1812-10.22 4.518-10.22 7.111s4.271-1.611 10.05-1.492c6.317 0.13 10.43 3.903 10.43 1.311z"
/>
<path
fill="none"
stroke="currentColor"
strokeLinecap="round"
strokeLinejoin="round"
strokeMiterlimit="10"
strokeWidth="2"
d="m49.12 23.92c-5.102-0.06134-7.273-1.882-8.383-3.346"
/>
<path
fill="none"
stroke="currentColor"
strokeLinecap="round"
strokeLinejoin="round"
strokeMiterlimit="10"
strokeWidth="2"
d="m48.24 30.51c-6.199 1.47-7.079 1.059-8.868-1.961"
/>
<path
fill="none"
stroke="currentColor"
strokeLinecap="round"
strokeLinejoin="round"
strokeMiterlimit="10"
strokeWidth="2"
d="m23.76 30.51c6.199 1.47 7.079 1.059 8.868-1.961"
/>
</g>
</svg>
);
};
export const PerseveringFace: React.FC<React.SVGProps<SVGCircleElement>> = (props) => {
return (
<svg viewBox="0 0 72 72" xmlns="http://www.w3.org/2000/svg" width={36} height={36}>
<g id="line">
<circle
cx="36"
cy="36"
r="23"
fill="none"
stroke="currentColor"
strokeMiterlimit="10"
strokeWidth="2"
{...props}
/>
<line
x1="44.5361"
x2="50.9214"
y1="21.4389"
y2="24.7158"
fill="none"
stroke="currentColor"
strokeLinecap="round"
strokeLinejoin="round"
strokeMiterlimit="10"
strokeWidth="2"
/>
<line
x1="26.9214"
x2="20.5361"
y1="21.4389"
y2="24.7158"
fill="none"
stroke="currentColor"
strokeLinecap="round"
strokeLinejoin="round"
strokeMiterlimit="10"
strokeWidth="2"
/>
<path
fill="none"
stroke="currentColor"
strokeLinecap="round"
strokeLinejoin="round"
strokeMiterlimit="10"
strokeWidth="2"
d="M24,28c2.3334,1.3333,4.6666,2.6667,7,4c-2.3334,1.3333-4.6666,2.6667-7,4"
/>
<path
fill="none"
stroke="currentColor"
strokeLinecap="round"
strokeLinejoin="round"
strokeMiterlimit="10"
strokeWidth="2"
d="M48,28c-2.3334,1.3333-4.6666,2.6667-7,4c2.3334,1.3333,4.6666,2.6667,7,4"
/>
<path
fill="none"
stroke="currentColor"
strokeLinecap="round"
strokeLinejoin="round"
strokeMiterlimit="10"
strokeWidth="2"
d="M28,51c0.2704-0.3562,1-8,8.4211-8.0038C43,42.9929,43.6499,50.5372,44,51C38.6667,51,33.3333,51,28,51z"
/>
</g>
</svg>
);
};
export const FrowningFace: React.FC<React.SVGProps<SVGCircleElement>> = (props) => {
return (
<svg viewBox="0 0 72 72" xmlns="http://www.w3.org/2000/svg" width={36} height={36}>
<g id="line">
<circle
cx="36"
cy="36"
r="23"
fill="none"
stroke="currentColor"
strokeMiterlimit="10"
strokeWidth="2"
{...props}
/>
<path
fill="none"
stroke="currentColor"
strokeLinecap="round"
strokeLinejoin="round"
strokeMiterlimit="10"
strokeWidth="2"
d="M26.5,48c1.8768-3.8326,5.8239-6.1965,10-6c3.8343,0.1804,7.2926,2.4926,9,6"
/>
<path d="M30,31c0,1.6568-1.3448,3-3,3c-1.6553,0-3-1.3433-3-3c0-1.6552,1.3447-3,3-3C28.6552,28,30,29.3448,30,31" />
<path d="M48,31c0,1.6568-1.3447,3-3,3s-3-1.3433-3-3c0-1.6552,1.3447-3,3-3S48,29.3448,48,31" />
</g>
</svg>
);
};
export const ConfusedFace: React.FC<React.SVGProps<SVGCircleElement>> = (props) => {
return (
<svg viewBox="0 0 72 72" xmlns="http://www.w3.org/2000/svg" width={36} height={36}>
<g id="line">
<circle
cx="36"
cy="36"
r="23"
fill="none"
stroke="currentColor"
strokeMiterlimit="10"
strokeWidth="2"
{...props}
/>
<path
fill="none"
stroke="currentColor"
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth="2"
d="m44.7 43.92c-6.328-1.736-11.41-0.906-17.4 1.902"
/>
<path d="M30,31c0,1.6568-1.3448,3-3,3c-1.6553,0-3-1.3433-3-3c0-1.6552,1.3447-3,3-3C28.6552,28,30,29.3448,30,31" />
<path d="M48,31c0,1.6568-1.3447,3-3,3s-3-1.3433-3-3c0-1.6552,1.3447-3,3-3S48,29.3448,48,31" />
</g>
</svg>
);
};
export const NeutralFace: React.FC<React.SVGProps<SVGCircleElement>> = (props) => {
return (
<svg viewBox="0 0 72 72" xmlns="http://www.w3.org/2000/svg" width={36} height={36}>
<g id="line">
<circle
cx="36"
cy="36"
r="23"
fill="none"
stroke="currentColor"
strokeMiterlimit="10"
strokeWidth="2"
{...props}
/>
<line
x1="27"
x2="45"
y1="43"
y2="43"
fill="none"
stroke="currentColor"
strokeLinecap="round"
strokeLinejoin="round"
strokeMiterlimit="10"
strokeWidth="2"
/>
<path d="M30,31c0,1.6568-1.3448,3-3,3c-1.6553,0-3-1.3433-3-3c0-1.6552,1.3447-3,3-3C28.6552,28,30,29.3448,30,31" />
<path d="M48,31c0,1.6568-1.3447,3-3,3s-3-1.3433-3-3c0-1.6552,1.3447-3,3-3S48,29.3448,48,31" />
</g>
</svg>
);
};
export const SlightlySmilingFace: React.FC<React.SVGProps<SVGCircleElement>> = (props) => {
return (
<svg viewBox="0 0 72 72" xmlns="http://www.w3.org/2000/svg" width={36} height={36}>
<g id="line">
<circle
cx="36"
cy="36"
r="23"
fill="none"
stroke="currentColor"
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth="2"
{...props}
/>
<path
fill="none"
stroke="currentColor"
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth="2"
d="M45.8149,44.9293 c-2.8995,1.6362-6.2482,2.5699-9.8149,2.5699s-6.9153-0.9336-9.8149-2.5699"
/>
<path d="M30,31c0,1.6568-1.3448,3-3,3c-1.6553,0-3-1.3433-3-3c0-1.6552,1.3447-3,3-3C28.6552,28,30,29.3448,30,31" />
<path d="M48,31c0,1.6568-1.3447,3-3,3s-3-1.3433-3-3c0-1.6552,1.3447-3,3-3S48,29.3448,48,31" />
</g>
</svg>
);
};
export const SmilingFaceWithSmilingEyes: React.FC<React.SVGProps<SVGCircleElement>> = (props) => {
return (
<svg viewBox="0 0 72 72" xmlns="http://www.w3.org/2000/svg" width={36} height={36}>
<g id="line">
<circle
cx="36"
cy="36"
r="23"
fill="none"
stroke="currentColor"
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth="2"
{...props}
/>
<path
fill="none"
stroke="currentColor"
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth="2"
d="M45.8147,45.2268a15.4294,15.4294,0,0,1-19.6294,0"
/>
<path
fill="none"
stroke="currentColor"
strokeLinecap="round"
strokeMiterlimit="10"
strokeWidth="2"
d="M31.6941,33.4036a4.7262,4.7262,0,0,0-8.6382,0"
/>
<path
fill="none"
stroke="currentColor"
strokeLinecap="round"
strokeMiterlimit="10"
strokeWidth="2"
d="M48.9441,33.4036a4.7262,4.7262,0,0,0-8.6382,0"
/>
</g>
</svg>
);
};
export const GrinningFaceWithSmilingEyes: React.FC<React.SVGProps<SVGCircleElement>> = (props) => {
return (
<svg viewBox="0 0 72 72" xmlns="http://www.w3.org/2000/svg" width={36} height={36}>
<g id="line">
<circle
cx="36"
cy="36"
r="23"
fill="none"
stroke="currentColor"
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth="2"
{...props}
/>
<path
fill="none"
stroke="currentColor"
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth="2"
d="M50.595,41.64a11.5554,11.5554,0,0,1-.87,4.49c-12.49,3.03-25.43.34-27.49-.13a11.4347,11.4347,0,0,1-.83-4.36h.11s14.8,3.59,28.89.07Z"
/>
<path
fill="none"
stroke="currentColor"
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth="2"
d="M49.7251,46.13c-1.79,4.27-6.35,7.23-13.69,7.23-7.41,0-12.03-3.03-13.8-7.36C24.2951,46.47,37.235,49.16,49.7251,46.13Z"
/>
<path
fill="none"
stroke="currentColor"
strokeLinecap="round"
strokeMiterlimit="10"
strokeWidth="2"
d="M31.6941,32.4036a4.7262,4.7262,0,0,0-8.6382,0"
/>
<path
fill="none"
stroke="currentColor"
strokeLinecap="round"
strokeMiterlimit="10"
strokeWidth="2"
d="M48.9441,32.4036a4.7262,4.7262,0,0,0-8.6382,0"
/>
</g>
</svg>
);
};
export const GrinningSquintingFace: React.FC<React.SVGProps<SVGCircleElement>> = (props) => {
return (
<svg viewBox="0 0 72 72" xmlns="http://www.w3.org/2000/svg" width={36} height={36}>
<g id="line">
<circle
cx="36"
cy="36"
r="23"
fill="none"
stroke="currentColor"
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth="2"
{...props}
/>
<polyline
fill="none"
stroke="currentColor"
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth="2"
points="25.168 27.413 31.755 31.427 25.168 35.165"
/>
<polyline
fill="none"
stroke="currentColor"
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth="2"
points="46.832 27.413 40.245 31.427 46.832 35.165"
/>
<path
fill="none"
stroke="currentColor"
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth="2"
d="M50.595,41.64a11.5554,11.5554,0,0,1-.87,4.49c-12.49,3.03-25.43.34-27.49-.13a11.4347,11.4347,0,0,1-.83-4.36h.11s14.8,3.59,28.89.07Z"
/>
<path
fill="none"
stroke="currentColor"
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth="2"
d="M49.7251,46.13c-1.79,4.27-6.35,7.23-13.69,7.23-7.41,0-12.03-3.03-13.8-7.36C24.2951,46.47,37.235,49.16,49.7251,46.13Z"
/>
</g>
</svg>
);
};

View File

@@ -32,10 +32,10 @@ export const renderHyperlinkedContent = (data: string): JSX.Element[] => {
export const getSurveyUrl = async (
survey: TSurvey,
surveyDomain: string,
publicDomain: string,
language: string
): Promise<string> => {
let url = `${surveyDomain}/s/${survey.id}`;
let url = `${publicDomain}/s/${survey.id}`;
const queryParams: string[] = [];
if (survey.singleUse?.enabled) {

View File

@@ -29,6 +29,12 @@ vi.mock("@/lib/constants", () => ({
AUDIT_LOG_ENABLED: true,
}));
vi.mock("@/lib/env", () => ({
env: {
PUBLIC_URL: "https://public-domain.com",
},
}));
vi.mock("next-auth", () => ({
getServerSession: vi.fn(),
}));

View File

@@ -0,0 +1,83 @@
import { getEmailFromEmailToken } from "@/lib/jwt";
import { SignupWithoutVerificationSuccessPage } from "@/modules/auth/signup-without-verification-success/page";
import "@testing-library/jest-dom/vitest";
import { cleanup, render, screen } from "@testing-library/react";
import { afterEach, describe, expect, test, vi } from "vitest";
vi.mock("@/tolgee/server", () => ({
getTranslate: async () => (key: string) => key,
T: ({ keyName, params }) => {
if (params && params.email) {
return `${keyName} ${params.email}`;
}
return keyName;
},
}));
vi.mock("@/lib/constants", () => ({
INTERCOM_SECRET_KEY: "test-secret-key",
IS_INTERCOM_CONFIGURED: true,
INTERCOM_APP_ID: "test-app-id",
ENCRYPTION_KEY: "test-encryption-key",
ENTERPRISE_LICENSE_KEY: "test-enterprise-license-key",
GITHUB_ID: "test-github-id",
GITHUB_SECRET: "test-githubID",
GOOGLE_CLIENT_ID: "test-google-client-id",
GOOGLE_CLIENT_SECRET: "test-google-client-secret",
AZUREAD_CLIENT_ID: "test-azuread-client-id",
AZUREAD_CLIENT_SECRET: "test-azure",
AZUREAD_TENANT_ID: "test-azuread-tenant-id",
OIDC_DISPLAY_NAME: "test-oidc-display-name",
OIDC_CLIENT_ID: "test-oidc-client-id",
OIDC_ISSUER: "test-oidc-issuer",
OIDC_CLIENT_SECRET: "test-oidc-client-secret",
OIDC_SIGNING_ALGORITHM: "test-oidc-signing-algorithm",
WEBAPP_URL: "test-webapp-url",
IS_POSTHOG_CONFIGURED: true,
POSTHOG_API_HOST: "test-posthog-api-host",
POSTHOG_API_KEY: "test-posthog-api-key",
FORMBRICKS_ENVIRONMENT_ID: "mock-formbricks-environment-id",
IS_FORMBRICKS_ENABLED: true,
SESSION_MAX_AGE: 1000,
AVAILABLE_LOCALES: ["en-US", "de-DE", "pt-BR", "fr-FR", "zh-Hant-TW", "pt-PT"],
}));
vi.mock("@/modules/auth/components/back-to-login-button", () => ({
BackToLoginButton: () => <div>Mocked BackToLoginButton</div>,
}));
vi.mock("@/modules/auth/components/form-wrapper", () => ({
FormWrapper: ({ children }) => <div>{children}</div>,
}));
vi.mock("@/modules/ui/components/alert", () => ({
Alert: ({ children }) => <div>{children}</div>,
}));
vi.mock("@/lib/jwt", () => ({
getEmailFromEmailToken: vi.fn(),
}));
describe("SignupWithoutVerificationSuccessPage", () => {
afterEach(() => {
cleanup();
vi.resetAllMocks();
});
test("renders the success page correctly", async () => {
vi.mocked(getEmailFromEmailToken).mockReturnValue("test@example.com");
const Page = await SignupWithoutVerificationSuccessPage({ searchParams: { token: "test-token" } });
render(Page);
expect(
screen.getByText("auth.signup_without_verification_success.user_successfully_created")
).toBeInTheDocument();
expect(
screen.getByText(
"auth.signup_without_verification_success.user_successfully_created_info test@example.com"
)
).toBeInTheDocument();
expect(screen.getByText("Mocked BackToLoginButton")).toBeInTheDocument();
});
});

View File

@@ -1,16 +1,23 @@
import { getEmailFromEmailToken } from "@/lib/jwt";
import { BackToLoginButton } from "@/modules/auth/components/back-to-login-button";
import { FormWrapper } from "@/modules/auth/components/form-wrapper";
import { getTranslate } from "@/tolgee/server";
import { T, getTranslate } from "@/tolgee/server";
export const SignupWithoutVerificationSuccessPage = async () => {
export const SignupWithoutVerificationSuccessPage = async ({ searchParams }) => {
const t = await getTranslate();
const { token } = await searchParams;
const email = getEmailFromEmailToken(token);
return (
<FormWrapper>
<h1 className="leading-2 mb-4 text-center font-bold">
{t("auth.signup_without_verification_success.user_successfully_created")}
</h1>
<p className="text-center text-sm">
{t("auth.signup_without_verification_success.user_successfully_created_description")}
<T
keyName="auth.signup_without_verification_success.user_successfully_created_info"
params={{ email, span: <span /> }}
/>
</p>
<hr className="my-4" />
<BackToLoginButton />

View File

@@ -15,8 +15,18 @@ import { withAuditLogging } from "@/modules/ee/audit-logs/lib/handler";
import { getIsMultiOrgEnabled } from "@/modules/ee/license-check/lib/utils";
import { sendInviteAcceptedEmail, sendVerificationEmail } from "@/modules/email";
import { z } from "zod";
import { UnknownError } from "@formbricks/types/errors";
import { ZUserEmail, ZUserLocale, ZUserName, ZUserPassword } from "@formbricks/types/user";
import { InvalidInputError, UnknownError } from "@formbricks/types/errors";
import { ZUser, ZUserEmail, ZUserLocale, ZUserName, ZUserPassword } from "@formbricks/types/user";
const ZCreatedUser = ZUser.pick({
name: true,
email: true,
locale: true,
id: true,
notificationSettings: true,
});
type TCreatedUser = z.infer<typeof ZCreatedUser>;
const ZCreateUserAction = z.object({
name: ZUserName,
@@ -34,100 +44,166 @@ const ZCreateUserAction = z.object({
),
});
async function verifyTurnstileIfConfigured(
turnstileToken: string | undefined,
email: string,
name: string
): Promise<void> {
if (!IS_TURNSTILE_CONFIGURED) return;
if (!turnstileToken || !TURNSTILE_SECRET_KEY) {
captureFailedSignup(email, name);
throw new UnknownError("Server configuration error");
}
const isHuman = await verifyTurnstileToken(TURNSTILE_SECRET_KEY, turnstileToken);
if (!isHuman) {
captureFailedSignup(email, name);
throw new UnknownError("reCAPTCHA verification failed");
}
}
async function createUserSafely(
email: string,
name: string,
hashedPassword: string,
userLocale: z.infer<typeof ZUserLocale> | undefined
): Promise<{ user: TCreatedUser | undefined; userAlreadyExisted: boolean }> {
let user: TCreatedUser | undefined = undefined;
let userAlreadyExisted = false;
try {
user = await createUser({
email: email.toLowerCase(),
name,
password: hashedPassword,
locale: userLocale,
});
} catch (error) {
if (error instanceof InvalidInputError) {
userAlreadyExisted = true;
} else {
throw error;
}
}
return { user, userAlreadyExisted };
}
async function handleInviteAcceptance(
ctx: ActionClientCtx,
inviteToken: string,
user: TCreatedUser
): Promise<void> {
const inviteTokenData = verifyInviteToken(inviteToken);
const invite = await getInvite(inviteTokenData.inviteId);
if (!invite) {
throw new Error("Invalid invite ID");
}
ctx.auditLoggingCtx.organizationId = invite.organizationId;
await createMembership(invite.organizationId, user.id, {
accepted: true,
role: invite.role,
});
if (invite.teamIds) {
await createTeamMembership(
{
organizationId: invite.organizationId,
role: invite.role,
teamIds: invite.teamIds,
},
user.id
);
}
await updateUser(user.id, {
notificationSettings: {
alert: {},
weeklySummary: {},
unsubscribedOrganizationIds: [invite.organizationId],
},
});
await sendInviteAcceptedEmail(invite.creator.name ?? "", user.name, invite.creator.email);
await deleteInvite(invite.id);
}
async function handleOrganizationCreation(ctx: ActionClientCtx, user: TCreatedUser): Promise<void> {
const isMultiOrgEnabled = await getIsMultiOrgEnabled();
if (!isMultiOrgEnabled) return;
const organization = await createOrganization({ name: `${user.name}'s Organization` });
ctx.auditLoggingCtx.organizationId = organization.id;
await createMembership(organization.id, user.id, {
role: "owner",
accepted: true,
});
await updateUser(user.id, {
notificationSettings: {
...user.notificationSettings,
alert: { ...user.notificationSettings?.alert },
weeklySummary: { ...user.notificationSettings?.weeklySummary },
unsubscribedOrganizationIds: Array.from(
new Set([...(user.notificationSettings?.unsubscribedOrganizationIds ?? []), organization.id])
),
},
});
}
async function handlePostUserCreation(
ctx: ActionClientCtx,
user: TCreatedUser,
inviteToken: string | undefined,
emailVerificationDisabled: boolean | undefined
): Promise<void> {
if (inviteToken) {
await handleInviteAcceptance(ctx, inviteToken, user);
} else {
await handleOrganizationCreation(ctx, user);
}
if (!emailVerificationDisabled) {
await sendVerificationEmail(user);
}
}
export const createUserAction = actionClient.schema(ZCreateUserAction).action(
withAuditLogging(
"created",
"user",
async ({ ctx, parsedInput }: { ctx: ActionClientCtx; parsedInput: Record<string, any> }) => {
if (IS_TURNSTILE_CONFIGURED) {
if (!parsedInput.turnstileToken || !TURNSTILE_SECRET_KEY) {
captureFailedSignup(parsedInput.email, parsedInput.name);
throw new UnknownError("Server configuration error");
}
await verifyTurnstileIfConfigured(parsedInput.turnstileToken, parsedInput.email, parsedInput.name);
const isHuman = await verifyTurnstileToken(TURNSTILE_SECRET_KEY, parsedInput.turnstileToken);
if (!isHuman) {
captureFailedSignup(parsedInput.email, parsedInput.name);
throw new UnknownError("reCAPTCHA verification failed");
}
}
const { inviteToken, emailVerificationDisabled } = parsedInput;
const hashedPassword = await hashPassword(parsedInput.password);
const user = await createUser({
email: parsedInput.email.toLowerCase(),
name: parsedInput.name,
password: hashedPassword,
locale: parsedInput.userLocale,
});
const { user, userAlreadyExisted } = await createUserSafely(
parsedInput.email,
parsedInput.name,
hashedPassword,
parsedInput.userLocale
);
// Handle invite flow
if (inviteToken) {
const inviteTokenData = verifyInviteToken(inviteToken);
const invite = await getInvite(inviteTokenData.inviteId);
if (!invite) {
throw new Error("Invalid invite ID");
}
await createMembership(invite.organizationId, user.id, {
accepted: true,
role: invite.role,
});
if (invite.teamIds) {
await createTeamMembership(
{
organizationId: invite.organizationId,
role: invite.role,
teamIds: invite.teamIds,
},
user.id
);
}
await updateUser(user.id, {
notificationSettings: {
alert: {},
weeklySummary: {},
unsubscribedOrganizationIds: [invite.organizationId],
},
});
ctx.auditLoggingCtx.organizationId = invite.organizationId;
await sendInviteAcceptedEmail(invite.creator.name ?? "", user.name, invite.creator.email);
await deleteInvite(invite.id);
} else {
const isMultiOrgEnabled = await getIsMultiOrgEnabled();
if (isMultiOrgEnabled) {
const organization = await createOrganization({ name: `${user.name}'s Organization` });
await createMembership(organization.id, user.id, {
role: "owner",
accepted: true,
});
await updateUser(user.id, {
notificationSettings: {
...user.notificationSettings,
alert: { ...user.notificationSettings?.alert },
weeklySummary: { ...user.notificationSettings?.weeklySummary },
unsubscribedOrganizationIds: Array.from(
new Set([...(user.notificationSettings?.unsubscribedOrganizationIds || []), organization.id])
),
},
});
ctx.auditLoggingCtx.organizationId = organization.id;
}
if (!userAlreadyExisted && user) {
await handlePostUserCreation(
ctx,
user,
parsedInput.inviteToken,
parsedInput.emailVerificationDisabled
);
}
// Send verification email if enabled
if (!emailVerificationDisabled) {
await sendVerificationEmail(user);
if (user) {
ctx.auditLoggingCtx.userId = user.id;
ctx.auditLoggingCtx.newObject = user;
}
ctx.auditLoggingCtx.userId = user.id;
ctx.auditLoggingCtx.newObject = user;
return user;
return {
success: true,
};
}
)
);

View File

@@ -125,6 +125,7 @@ const defaultProps = {
describe("SignupForm", () => {
afterEach(() => {
cleanup();
vi.clearAllMocks();
});
test("toggles the signup form on button click", () => {
@@ -237,7 +238,7 @@ describe("SignupForm", () => {
expect(createEmailTokenAction).toHaveBeenCalledWith({ email: "test@example.com" });
});
expect(pushMock).toHaveBeenCalledWith("/auth/signup-without-verification-success");
expect(pushMock).toHaveBeenCalledWith("/auth/signup-without-verification-success?token=token123");
});
test("submits the form successfully when turnstile is configured, but createEmailTokenAction don't return data", async () => {
@@ -364,4 +365,42 @@ describe("SignupForm", () => {
expect(pushMock).toHaveBeenCalledWith("/auth/verification-requested?token=token123");
});
test("shows an error message when createUserAction fails", async () => {
// Set up mocks for the API actions
vi.mocked(createUserAction).mockResolvedValue(undefined);
vi.mocked(createEmailTokenAction).mockResolvedValue({ data: "token123" });
vi.mocked(getFormattedErrorMessage).mockReturnValue("user creation failed");
render(<SignupForm {...defaultProps} />);
// Click the button to reveal the signup form
const toggleButton = screen.getByTestId("signup-show-login");
fireEvent.click(toggleButton);
// Fill out the form fields
fireEvent.change(screen.getByTestId("signup-name"), { target: { value: "Test User" } });
fireEvent.change(screen.getByTestId("signup-email"), { target: { value: "test@example.com" } });
fireEvent.change(screen.getByTestId("signup-password"), { target: { value: "Password123" } });
// Submit the form.
const submitButton = screen.getByTestId("signup-submit");
fireEvent.submit(submitButton);
await waitFor(() => {
expect(createUserAction).toHaveBeenCalled();
});
await waitFor(() => {
expect(createEmailTokenAction).toHaveBeenCalledWith({ email: "test@example.com" });
});
// An error message should be shown.
await waitFor(() => {
expect(toast.error).toHaveBeenCalledWith("user creation failed");
});
// router.push should not have been called.
expect(pushMock).not.toHaveBeenCalled();
});
});

View File

@@ -12,8 +12,7 @@ import { PasswordInput } from "@/modules/ui/components/password-input";
import { zodResolver } from "@hookform/resolvers/zod";
import { useTranslate } from "@tolgee/react";
import Link from "next/link";
import { useRouter } from "next/navigation";
import { useSearchParams } from "next/navigation";
import { useRouter, useSearchParams } from "next/navigation";
import { useMemo, useState } from "react";
import { FormProvider, useForm } from "react-hook-form";
import toast from "react-hot-toast";
@@ -109,21 +108,22 @@ export const SignupForm = ({
email: data.email,
password: data.password,
userLocale,
inviteToken: inviteToken || "",
inviteToken: inviteToken ?? "",
emailVerificationDisabled,
turnstileToken,
});
if (createUserResponse?.data) {
const emailTokenActionResponse = await createEmailTokenAction({ email: data.email });
if (emailTokenActionResponse?.data) {
const token = emailTokenActionResponse?.data;
const url = emailVerificationDisabled
? `/auth/signup-without-verification-success`
: `/auth/verification-requested?token=${token}`;
const emailTokenActionResponse = await createEmailTokenAction({ email: data.email });
const token = emailTokenActionResponse?.data;
router.push(url);
} else {
const url = emailVerificationDisabled
? `/auth/signup-without-verification-success?token=${token}`
: `/auth/verification-requested?token=${token}`;
if (createUserResponse?.data) {
router.push(url);
if (!emailTokenActionResponse?.data) {
if (isTurnstileConfigured) {
setTurnstileToken(undefined);
turnstile.reset();

View File

@@ -6,7 +6,7 @@ import { getUserByEmail } from "@/modules/auth/lib/user";
import { withAuditLogging } from "@/modules/ee/audit-logs/lib/handler";
import { sendVerificationEmail } from "@/modules/email";
import { z } from "zod";
import { InvalidInputError, ResourceNotFoundError } from "@formbricks/types/errors";
import { ResourceNotFoundError } from "@formbricks/types/errors";
import { ZUserEmail } from "@formbricks/types/user";
const ZResendVerificationEmailAction = z.object({
@@ -23,10 +23,15 @@ export const resendVerificationEmailAction = actionClient.schema(ZResendVerifica
throw new ResourceNotFoundError("user", parsedInput.email);
}
if (user.emailVerified) {
throw new InvalidInputError("Email address has already been verified");
return {
success: true,
};
}
ctx.auditLoggingCtx.userId = user.id;
return await sendVerificationEmail(user);
await sendVerificationEmail(user);
return {
success: true,
};
}
)
);

View File

@@ -0,0 +1,138 @@
import { getEmailFromEmailToken } from "@/lib/jwt";
import { VerificationRequestedPage } from "@/modules/auth/verification-requested/page";
import "@testing-library/jest-dom/vitest";
import { cleanup, render, screen } from "@testing-library/react";
import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
vi.mock("@/lib/jwt", () => ({
getEmailFromEmailToken: vi.fn(),
}));
vi.mock("@formbricks/logger", () => ({
logger: {
error: vi.fn(),
},
}));
vi.mock("@/tolgee/server", () => ({
getTranslate: async () => (key: string) => key,
T: ({ keyName, params }) => {
if (params && params.email) {
return `${keyName} ${params.email}`;
}
return keyName;
},
}));
vi.mock("@/lib/constants", () => ({
INTERCOM_SECRET_KEY: "test-secret-key",
IS_INTERCOM_CONFIGURED: true,
INTERCOM_APP_ID: "test-app-id",
ENCRYPTION_KEY: "test-encryption-key",
ENTERPRISE_LICENSE_KEY: "test-enterprise-license-key",
GITHUB_ID: "test-github-id",
GITHUB_SECRET: "test-githubID",
GOOGLE_CLIENT_ID: "test-google-client-id",
GOOGLE_CLIENT_SECRET: "test-google-client-secret",
AZUREAD_CLIENT_ID: "test-azuread-client-id",
AZUREAD_CLIENT_SECRET: "test-azure",
AZUREAD_TENANT_ID: "test-azuread-tenant-id",
OIDC_DISPLAY_NAME: "test-oidc-display-name",
OIDC_CLIENT_ID: "test-oidc-client-id",
OIDC_ISSUER: "test-oidc-issuer",
OIDC_CLIENT_SECRET: "test-oidc-client-secret",
OIDC_SIGNING_ALGORITHM: "test-oidc-signing-algorithm",
WEBAPP_URL: "test-webapp-url",
IS_POSTHOG_CONFIGURED: true,
POSTHOG_API_HOST: "test-posthog-api-host",
POSTHOG_API_KEY: "test-posthog-api-key",
FORMBRICKS_ENVIRONMENT_ID: "mock-formbricks-environment-id",
IS_FORMBRICKS_ENABLED: true,
SESSION_MAX_AGE: 1000,
AVAILABLE_LOCALES: ["en-US", "de-DE", "pt-BR", "fr-FR", "zh-Hant-TW", "pt-PT"],
}));
vi.mock("@/modules/auth/components/form-wrapper", () => ({
FormWrapper: ({ children }) => <div>{children}</div>,
}));
vi.mock("@/modules/auth/verification-requested/components/request-verification-email", () => ({
RequestVerificationEmail: ({ email }) => <div>Mocked RequestVerificationEmail: {email}</div>,
}));
vi.mock("@/modules/ui/components/alert", () => ({
Alert: ({ children }) => <div>{children}</div>,
}));
describe("VerificationRequestedPage", () => {
afterEach(() => {
cleanup();
});
beforeEach(() => {
vi.clearAllMocks();
});
test("renders the page with valid email", async () => {
const mockEmail = "test@example.com";
vi.mocked(getEmailFromEmailToken).mockReturnValue(mockEmail);
const searchParams = { token: "valid-token" };
const Page = await VerificationRequestedPage({ searchParams });
render(Page);
expect(
screen.getByText("auth.verification-requested.please_confirm_your_email_address")
).toBeInTheDocument();
expect(screen.getAllByText(/test@example\.com/)).toHaveLength(2);
expect(
screen.getByText(
"auth.verification-requested.verification_email_successfully_sent_info test@example.com"
)
).toBeInTheDocument();
expect(
screen.getByText(`Mocked RequestVerificationEmail: ${mockEmail.toLowerCase()}`)
).toBeInTheDocument();
});
test("renders invalid email message when email parsing fails", async () => {
vi.mocked(getEmailFromEmailToken).mockReturnValue("invalid-email");
const searchParams = { token: "valid-token" };
const Page = await VerificationRequestedPage({ searchParams });
render(Page);
expect(screen.getByText("auth.verification-requested.invalid_email_address")).toBeInTheDocument();
});
test("renders invalid token message when token is invalid", async () => {
const mockError = new Error("Invalid token");
const { logger } = await import("@formbricks/logger");
vi.mocked(getEmailFromEmailToken).mockImplementation(() => {
throw mockError;
});
const searchParams = { token: "invalid-token" };
const Page = await VerificationRequestedPage({ searchParams });
render(Page);
expect(logger.error).toHaveBeenCalledWith(mockError, "Invalid token");
expect(screen.getByText("auth.verification-requested.invalid_token")).toBeInTheDocument();
});
test("calls logger.error when token parsing throws an error", async () => {
const mockError = new Error("JWT malformed");
const { logger } = await import("@formbricks/logger");
vi.mocked(getEmailFromEmailToken).mockImplementation(() => {
throw mockError;
});
const searchParams = { token: "malformed-token" };
await VerificationRequestedPage({ searchParams });
expect(logger.error).toHaveBeenCalledWith(mockError, "Invalid token");
expect(logger.error).toHaveBeenCalledTimes(1);
});
});

View File

@@ -2,6 +2,7 @@ import { getEmailFromEmailToken } from "@/lib/jwt";
import { FormWrapper } from "@/modules/auth/components/form-wrapper";
import { RequestVerificationEmail } from "@/modules/auth/verification-requested/components/request-verification-email";
import { T, getTranslate } from "@/tolgee/server";
import { logger } from "@formbricks/logger";
import { ZUserEmail } from "@formbricks/types/user";
export const VerificationRequestedPage = async ({ searchParams }) => {
@@ -19,10 +20,9 @@ export const VerificationRequestedPage = async ({ searchParams }) => {
</h1>
<p className="text-center text-sm text-slate-700">
<T
keyName="auth.verification-requested.we_sent_an_email_to"
keyName="auth.verification-requested.verification_email_successfully_sent_info"
params={{ email, span: <span /> }}
/>
{t("auth.verification-requested.please_click_the_link_in_the_email_to_activate_your_account")}
</p>
<hr className="my-4" />
<p className="text-center text-xs text-slate-500">
@@ -42,6 +42,7 @@ export const VerificationRequestedPage = async ({ searchParams }) => {
);
}
} catch (error) {
logger.error(error, "Invalid token");
return (
<FormWrapper>
<p className="text-center">{t("auth.verification-requested.invalid_token")}</p>

View File

@@ -1,5 +1,6 @@
import { ENCRYPTION_KEY, SURVEY_URL } from "@/lib/constants";
import { ENCRYPTION_KEY } from "@/lib/constants";
import * as crypto from "@/lib/crypto";
import { getPublicDomain } from "@/lib/getPublicUrl";
import jwt from "jsonwebtoken";
import { beforeEach, describe, expect, test, vi } from "vitest";
import * as contactSurveyLink from "./contact-survey-link";
@@ -15,7 +16,10 @@ vi.mock("jsonwebtoken", () => ({
// Mock constants - MUST be a literal object without using variables
vi.mock("@/lib/constants", () => ({
ENCRYPTION_KEY: "test-encryption-key-32-chars-long!",
SURVEY_URL: "https://test.formbricks.com",
}));
vi.mock("@/lib/getPublicUrl", () => ({
getPublicDomain: vi.fn().mockReturnValue("https://test.formbricks.com"),
}));
vi.mock("@/lib/crypto", () => ({
@@ -73,7 +77,7 @@ describe("Contact Survey Link", () => {
// Verify the returned URL
expect(result).toEqual({
ok: true,
data: `${SURVEY_URL}/c/${mockToken}`,
data: `${getPublicDomain()}/c/${mockToken}`,
});
});
@@ -98,7 +102,7 @@ describe("Contact Survey Link", () => {
// Remock constants to simulate missing ENCRYPTION_KEY
vi.doMock("@/lib/constants", () => ({
ENCRYPTION_KEY: undefined,
SURVEY_URL: "https://test.formbricks.com",
PUBLIC_URL: "https://test.formbricks.com",
}));
// Reimport the modules so they pick up the new mock
const { getContactSurveyLink } = await import("./contact-survey-link");
@@ -172,7 +176,6 @@ describe("Contact Survey Link", () => {
vi.resetModules();
vi.doMock("@/lib/constants", () => ({
ENCRYPTION_KEY: undefined,
SURVEY_URL: "https://test.formbricks.com",
}));
const { verifyContactSurveyToken } = await import("./contact-survey-link");
const result = verifyContactSurveyToken(mockToken);

View File

@@ -1,6 +1,6 @@
import { ENCRYPTION_KEY } from "@/lib/constants";
import { symmetricDecrypt, symmetricEncrypt } from "@/lib/crypto";
import { getSurveyDomain } from "@/lib/getSurveyUrl";
import { getPublicDomain } from "@/lib/getPublicUrl";
import { ApiErrorResponseV2 } from "@/modules/api/v2/types/api-error";
import jwt from "jsonwebtoken";
import { Result, err, ok } from "@formbricks/types/error-handlers";
@@ -42,7 +42,7 @@ export const getContactSurveyLink = (
const token = jwt.sign(payload, ENCRYPTION_KEY, tokenOptions);
// Return the personalized URL
return ok(`${getSurveyDomain()}/c/${token}`);
return ok(`${getPublicDomain()}/c/${token}`);
};
// Validates and decrypts a contact survey JWT token

View File

@@ -1,4 +1,5 @@
import { cn } from "@/lib/cn";
import { WEBAPP_URL } from "@/lib/constants";
import { getLocalizedValue } from "@/lib/i18n/utils";
import { COLOR_DEFAULTS } from "@/lib/styling/constants";
import { isLight, mixColor } from "@/lib/utils/colors";
@@ -46,6 +47,31 @@ export const getPreviewEmailTemplateHtml = async (
);
};
const getRatingContent = (scale: string, i: number, range: number, isColorCodingEnabled: boolean) => {
if (scale === "smiley") {
return (
<RatingSmiley
active={false}
idx={i}
range={range}
addColors={isColorCodingEnabled}
baseUrl={WEBAPP_URL}
/>
);
}
if (scale === "number") {
return (
<Text className="m-0 h-[44px] text-center text-[14px] leading-[44px]">
{i + 1}
</Text>
);
}
if (scale === "star") {
return <Text className="m-auto text-3xl"></Text>;
}
return null;
};
export async function PreviewEmailTemplate({
survey,
surveyUrl,
@@ -124,16 +150,13 @@ export async function PreviewEmailTemplate({
href={`${urlWithPrefilling}${firstQuestion.id}=${i.toString()}`}
key={i}
className={cn(
firstQuestion.isColorCodingEnabled ? "h-[46px]" : "h-10",
firstQuestion.isColorCodingEnabled && firstQuestion.scale === "number"
? `h-[46px] border border-t-[6px] border-t-${getNPSOptionColor(i + 1).replace("bg-", "")}`
: "h-10",
"relative m-0 w-full overflow-hidden border border-l-0 border-solid border-slate-200 p-0 text-center align-middle leading-10 text-slate-800",
{ "rounded-l-lg border-l": i === 0 },
{ "rounded-r-lg": i === 10 }
)}>
{firstQuestion.isColorCodingEnabled ? (
<Section
className={`absolute left-0 top-0 h-[6px] w-full ${getNPSOptionColor(i)}`}
/>
) : null}
{i}
</EmailButton>
))}
@@ -204,36 +227,23 @@ export async function PreviewEmailTemplate({
{Array.from({ length: firstQuestion.range }, (_, i) => (
<EmailButton
className={cn(
"relative m-0 flex w-full items-center justify-center overflow-hidden border border-l-0 border-solid border-gray-200 p-0 text-center align-middle leading-10 text-slate-800",
"relative m-0 h-[48px] w-full overflow-hidden border border-l-0 border-solid border-gray-200 p-0 text-center align-middle leading-10 text-slate-800",
{ "rounded-l-lg border-l": i === 0 },
{ "rounded-r-lg": i === firstQuestion.range - 1 },
firstQuestion.isColorCodingEnabled && firstQuestion.scale === "number"
? "h-[46px]"
: "h-10",
firstQuestion.scale === "star" ? "h-12" : "h-10"
firstQuestion.isColorCodingEnabled &&
firstQuestion.scale === "number" &&
`border border-t-[6px] border-t-${getRatingNumberOptionColor(firstQuestion.range, i + 1)}`,
firstQuestion.scale === "star" && "border-transparent"
)}
href={`${urlWithPrefilling}${firstQuestion.id}=${(i + 1).toString()}`}
key={i}>
{firstQuestion.scale === "smiley" && (
<RatingSmiley
active={false}
idx={i}
range={firstQuestion.range}
addColors={firstQuestion.isColorCodingEnabled}
/>
{getRatingContent(
firstQuestion.scale,
i,
firstQuestion.range,
firstQuestion.isColorCodingEnabled
)}
{firstQuestion.scale === "number" && (
<>
{firstQuestion.isColorCodingEnabled ? (
<Section
className={`absolute left-0 top-0 h-[6px] w-full ${getRatingNumberOptionColor(firstQuestion.range, i + 1)}`}
/>
) : null}
<Text className="m-0 flex h-10 items-center">{i + 1}</Text>
</>
)}
{firstQuestion.scale === "star" && <Text className="m-0 text-3xl"></Text>}
</EmailButton>
))}
</Column>

View File

@@ -11,7 +11,7 @@ import {
SMTP_USER,
WEBAPP_URL,
} from "@/lib/constants";
import { getSurveyDomain } from "@/lib/getSurveyUrl";
import { getPublicDomain } from "@/lib/getPublicUrl";
import { createEmailChangeToken, createInviteToken, createToken, createTokenForLinkSurvey } from "@/lib/jwt";
import { getOrganizationByEnvironmentId } from "@/lib/organization/service";
import NewEmailVerification from "@/modules/email/emails/auth/new-email-verification";
@@ -294,9 +294,9 @@ export const sendLinkSurveyToVerifiedEmail = async (data: TLinkSurveyEmailData):
const t = await getTranslate();
const getSurveyLink = (): string => {
if (singleUseId) {
return `${getSurveyDomain()}/s/${surveyId}?verify=${encodeURIComponent(token)}&suId=${singleUseId}`;
return `${getPublicDomain()}/s/${surveyId}?verify=${encodeURIComponent(token)}&suId=${singleUseId}`;
}
return `${getSurveyDomain()}/s/${surveyId}?verify=${encodeURIComponent(token)}`;
return `${getPublicDomain()}/s/${surveyId}?verify=${encodeURIComponent(token)}`;
};
const surveyLink = getSurveyLink();

View File

@@ -6,17 +6,17 @@ export const getNPSOptionColor = (idx: number): string => {
export const getRatingNumberOptionColor = (range: number, idx: number): string => {
if (range > 5) {
if (range - idx < 2) return "bg-emerald-100";
if (range - idx < 4) return "bg-orange-100";
return "bg-rose-100";
if (range - idx < 2) return "emerald-100";
if (range - idx < 4) return "orange-100";
return "rose-100";
} else if (range < 5) {
if (range - idx < 1) return "bg-emerald-100";
if (range - idx < 2) return "bg-orange-100";
return "bg-rose-100";
if (range - idx < 1) return "emerald-100";
if (range - idx < 2) return "orange-100";
return "rose-100";
}
if (range - idx < 2) return "bg-emerald-100";
if (range - idx < 3) return "bg-orange-100";
return "bg-rose-100";
if (range - idx < 2) return "emerald-100";
if (range - idx < 3) return "orange-100";
return "rose-100";
};
const defaultLocale = "en-US";

View File

@@ -40,9 +40,9 @@ vi.mock("@/app/(app)/environments/[environmentId]/components/WidgetStatusIndicat
),
}));
vi.mock("@/modules/projects/settings/(setup)/components/setup-instructions", () => ({
SetupInstructions: ({ environmentId, webAppUrl }: any) => (
SetupInstructions: ({ environmentId, publicDomain }: any) => (
<div data-testid="setup-instructions">
{environmentId} {webAppUrl}
{environmentId} {publicDomain}
</div>
),
}));
@@ -68,6 +68,12 @@ vi.mock("@/lib/constants", () => ({
},
}));
vi.mock("@/lib/env", () => ({
env: {
PUBLIC_URL: "https://example.com",
},
}));
describe("AppConnectionPage", () => {
afterEach(() => {
cleanup();
@@ -89,7 +95,6 @@ describe("AppConnectionPage", () => {
expect(cards[1]).toHaveTextContent("environments.project.app-connection.how_to_setup");
expect(cards[1]).toHaveTextContent("environments.project.app-connection.how_to_setup_description");
expect(cards[1]).toHaveTextContent("env-123"); // SetupInstructions
expect(cards[1]).toHaveTextContent(mockWebappUrl);
expect(cards[2]).toHaveTextContent("environments.project.app-connection.environment_id");
expect(cards[2]).toHaveTextContent("environments.project.app-connection.environment_id_description");
expect(cards[2]).toHaveTextContent("env-123"); // EnvironmentIdField

View File

@@ -1,6 +1,6 @@
import { WidgetStatusIndicator } from "@/app/(app)/environments/[environmentId]/components/WidgetStatusIndicator";
import { SettingsCard } from "@/app/(app)/environments/[environmentId]/settings/components/SettingsCard";
import { WEBAPP_URL } from "@/lib/constants";
import { getPublicDomain } from "@/lib/getPublicUrl";
import { getEnvironmentAuth } from "@/modules/environments/lib/utils";
import { EnvironmentIdField } from "@/modules/projects/settings/(setup)/components/environment-id-field";
import { SetupInstructions } from "@/modules/projects/settings/(setup)/components/setup-instructions";
@@ -16,6 +16,7 @@ export const AppConnectionPage = async (props) => {
const { environment } = await getEnvironmentAuth(params.environmentId);
const publicDomain = getPublicDomain();
return (
<PageContentWrapper>
<PageHeader pageTitle={t("common.project_configuration")}>
@@ -32,7 +33,7 @@ export const AppConnectionPage = async (props) => {
title={t("environments.project.app-connection.how_to_setup")}
description={t("environments.project.app-connection.how_to_setup_description")}
noPadding>
<SetupInstructions environmentId={params.environmentId} webAppUrl={WEBAPP_URL} />
<SetupInstructions environmentId={params.environmentId} publicDomain={publicDomain} />
</SettingsCard>
<SettingsCard
title={t("environments.project.app-connection.environment_id")}

View File

@@ -42,6 +42,7 @@ vi.mock("next/link", () => {
describe("SetupInstructions Component", () => {
const environmentId = "env123";
const webAppUrl = "https://example.com";
const publicDomain = "https://example.com";
beforeEach(() => {
// Optionally reset mocks if needed
@@ -49,7 +50,7 @@ describe("SetupInstructions Component", () => {
});
test("renders npm instructions by default", () => {
render(<SetupInstructions environmentId={environmentId} webAppUrl={webAppUrl} />);
render(<SetupInstructions environmentId={environmentId} publicDomain={publicDomain} />);
// Verify that the npm tab is active by default by checking for a code block with npm install instructions.
expect(screen.getByText("pnpm install @formbricks/js")).toBeInTheDocument();
@@ -60,7 +61,7 @@ describe("SetupInstructions Component", () => {
});
test("switches to html tab and displays html instructions", async () => {
render(<SetupInstructions environmentId="env123" webAppUrl="https://example.com" />);
render(<SetupInstructions environmentId="env123" publicDomain="https://example.com" />);
// Instead of getByRole (which finds multiple buttons), use getAllByRole and select the first HTML tab.
const htmlTabButtons = screen.getAllByRole("button", { name: /HTML/i });
@@ -76,7 +77,7 @@ describe("SetupInstructions Component", () => {
});
test("npm instructions code block contains environmentId and webAppUrl", async () => {
render(<SetupInstructions environmentId={environmentId} webAppUrl={webAppUrl} />);
render(<SetupInstructions environmentId={environmentId} publicDomain={publicDomain} />);
// The NPM tab is the default view.
// Find all code block elements.
@@ -88,6 +89,6 @@ describe("SetupInstructions Component", () => {
);
expect(setupCodeBlock).toBeDefined();
expect(setupCodeBlock?.textContent).toContain(environmentId);
expect(setupCodeBlock?.textContent).toContain(webAppUrl);
expect(setupCodeBlock?.textContent).toContain(publicDomain);
});
});

View File

@@ -19,10 +19,10 @@ const tabs = [
interface SetupInstructionsProps {
environmentId: string;
webAppUrl: string;
publicDomain: string;
}
export const SetupInstructions = ({ environmentId, webAppUrl }: SetupInstructionsProps) => {
export const SetupInstructions = ({ environmentId, publicDomain }: SetupInstructionsProps) => {
const { t } = useTranslate();
const [activeTab, setActiveTab] = useState(tabs[0].id);
@@ -45,7 +45,7 @@ export const SetupInstructions = ({ environmentId, webAppUrl }: SetupInstruction
if (typeof window !== "undefined") {
formbricks.setup({
environmentId: "${environmentId}",
appUrl: "${webAppUrl}",
appUrl: "${publicDomain}",
});
}`}
</CodeBlock>
@@ -129,7 +129,7 @@ if (typeof window !== "undefined") {
</p>
<CodeBlock language="js">{`<!-- START Formbricks Surveys -->
<script type="text/javascript">
!function(){var t=document.createElement("script");t.type="text/javascript",t.async=!0,t.src="${webAppUrl}/js/formbricks.umd.cjs",t.onload=function(){window.formbricks?window.formbricks.setup({environmentId:"${environmentId}",appUrl:"${window.location.protocol}//${window.location.host}"}):console.error("Formbricks library failed to load properly. The formbricks object is not available.");};var e=document.getElementsByTagName("script")[0];e.parentNode.insertBefore(t,e)}();
!function(){var t=document.createElement("script");t.type="text/javascript",t.async=!0,t.src="${publicDomain}/js/formbricks.umd.cjs",t.onload=function(){window.formbricks?window.formbricks.setup({environmentId:"${environmentId}",appUrl:"${window.location.protocol}//${window.location.host}"}):console.error("Formbricks library failed to load properly. The formbricks object is not available.");};var e=document.getElementsByTagName("script")[0];e.parentNode.insertBefore(t,e)}();
</script>
<!-- END Formbricks Surveys -->`}</CodeBlock>
<h4>Step 2: Debug mode</h4>

View File

@@ -123,28 +123,48 @@ describe("FollowUpEmail", () => {
expect(screen.getByText("Test HTML Content")).toBeInTheDocument();
});
test("renders the imprint and privacy policy links if provided", async () => {
test("renders the footer with imprint and privacy policy links when using default logo", async () => {
const followUpEmailElement = await FollowUpEmail({
...defaultProps,
logoUrl: undefined, // Using default logo
});
render(followUpEmailElement);
expect(screen.getByText("emails.imprint")).toBeInTheDocument();
expect(screen.getByText("emails.privacy_policy")).toBeInTheDocument();
expect(screen.getByText("emails.email_template_text_1")).toBeInTheDocument();
expect(screen.getByText("Imprint Address")).toBeInTheDocument();
});
test("renders the imprint address if provided", async () => {
test("renders the footer with imprint and privacy policy links when using FB_LOGO_URL", async () => {
const followUpEmailElement = await FollowUpEmail({
...defaultProps,
logoUrl: "https://example.com/mock-logo.png", // Using FB_LOGO_URL
});
render(followUpEmailElement);
expect(screen.getByText("emails.imprint")).toBeInTheDocument();
expect(screen.getByText("emails.privacy_policy")).toBeInTheDocument();
expect(screen.getByText("emails.email_template_text_1")).toBeInTheDocument();
expect(screen.getByText("Imprint Address")).toBeInTheDocument();
});
test("does not render the footer when using custom logo (white labeling)", async () => {
const followUpEmailElement = await FollowUpEmail({
...defaultProps,
logoUrl: "https://example.com/custom-logo.png", // Using custom logo
});
render(followUpEmailElement);
expect(screen.queryByText("emails.imprint")).not.toBeInTheDocument();
expect(screen.queryByText("emails.privacy_policy")).not.toBeInTheDocument();
expect(screen.queryByText("emails.email_template_text_1")).not.toBeInTheDocument();
expect(screen.queryByText("Imprint Address")).not.toBeInTheDocument();
});
test("renders the response data if attachResponseData is true", async () => {
const followUpEmailElement = await FollowUpEmail({
...defaultProps,

View File

@@ -38,6 +38,7 @@ export async function FollowUpEmail(props: FollowUpEmailProps): Promise<React.JS
const questions = props.attachResponseData ? getQuestionResponseMapping(props.survey, props.response) : [];
const t = await getTranslate();
// If the logo is not set, we are not using white labeling
const isDefaultLogo = !props.logoUrl || props.logoUrl === fbLogoUrl;
return (
@@ -84,31 +85,42 @@ export async function FollowUpEmail(props: FollowUpEmailProps): Promise<React.JS
})}
</Container>
<Section className="mt-4 text-center text-sm">
<Link
className="m-0 font-normal text-slate-500"
href="https://formbricks.com/?utm_source=email_header&utm_medium=email"
target="_blank"
rel="noopener noreferrer">
{t("emails.email_template_text_1")}
</Link>
{IMPRINT_ADDRESS && (
<Text className="m-0 font-normal text-slate-500 opacity-50">{IMPRINT_ADDRESS}</Text>
)}
<Text className="m-0 font-normal text-slate-500 opacity-50">
{IMPRINT_URL && (
<Link href={IMPRINT_URL} target="_blank" rel="noopener noreferrer" className="text-slate-500">
{t("emails.imprint")}
</Link>
{/* If the logo is not set, we are not using white labeling */}
{isDefaultLogo ? (
<Section className="mt-4 text-center text-sm">
<Link
className="m-0 font-normal text-slate-500"
href="https://formbricks.com/?utm_source=email_header&utm_medium=email"
target="_blank"
rel="noopener noreferrer">
{t("emails.email_template_text_1")}
</Link>
{IMPRINT_ADDRESS && (
<Text className="m-0 font-normal text-slate-500 opacity-50">{IMPRINT_ADDRESS}</Text>
)}
{IMPRINT_URL && PRIVACY_URL && " • "}
{PRIVACY_URL && (
<Link href={PRIVACY_URL} target="_blank" rel="noopener noreferrer" className="text-slate-500">
{t("emails.privacy_policy")}
</Link>
)}
</Text>
</Section>
<Text className="m-0 font-normal text-slate-500 opacity-50">
{IMPRINT_URL && (
<Link
href={IMPRINT_URL}
target="_blank"
rel="noopener noreferrer"
className="text-slate-500">
{t("emails.imprint")}
</Link>
)}
{IMPRINT_URL && PRIVACY_URL && " • "}
{PRIVACY_URL && (
<Link
href={PRIVACY_URL}
target="_blank"
rel="noopener noreferrer"
className="text-slate-500">
{t("emails.privacy_policy")}
</Link>
)}
</Text>
</Section>
) : null}
</Body>
</Tailwind>
</Html>

View File

@@ -82,7 +82,7 @@ describe("LinkSurveyWrapper", () => {
IMPRINT_URL: "https://imprint.url",
PRIVACY_URL: "https://privacy.url",
IS_FORMBRICKS_CLOUD: true,
surveyDomain: "https://survey.domain",
publicDomain: "https://public-domain.com",
isBrandingEnabled: true,
} as any;
@@ -107,7 +107,7 @@ describe("LinkSurveyWrapper", () => {
expect(screen.getByTestId("client-logo")).toBeInTheDocument();
expect(screen.getByTestId("survey-content")).toBeInTheDocument();
expect(screen.getByTestId("legal-footer")).toBeInTheDocument();
expect(screen.getByTestId("legal-footer")).toHaveTextContent("https://survey.domain/s/survey123");
expect(screen.getByTestId("legal-footer")).toHaveTextContent("https://public-domain.com/s/survey123");
});
test("handles background loaded state correctly", async () => {

View File

@@ -22,7 +22,7 @@ interface LinkSurveyWrapperProps {
IMPRINT_URL?: string;
PRIVACY_URL?: string;
IS_FORMBRICKS_CLOUD: boolean;
surveyDomain: string;
publicDomain: string;
isBrandingEnabled: boolean;
}
@@ -39,7 +39,7 @@ export const LinkSurveyWrapper = ({
IMPRINT_URL,
PRIVACY_URL,
IS_FORMBRICKS_CLOUD,
surveyDomain,
publicDomain,
isBrandingEnabled,
}: LinkSurveyWrapperProps) => {
//for embedded survey strip away all surrounding css
@@ -96,7 +96,7 @@ export const LinkSurveyWrapper = ({
IMPRINT_URL={IMPRINT_URL}
PRIVACY_URL={PRIVACY_URL}
IS_FORMBRICKS_CLOUD={IS_FORMBRICKS_CLOUD}
surveyUrl={surveyDomain + "/s/" + surveyId}
surveyUrl={publicDomain + "/s/" + surveyId}
/>
</div>
);

View File

@@ -20,8 +20,7 @@ interface LinkSurveyProps {
emailVerificationStatus?: string;
singleUseId?: string;
singleUseResponse?: Pick<Response, "id" | "finished">;
surveyDomain: string;
webAppUrl: string;
publicDomain: string;
responseCount?: number;
verifiedEmail?: string;
languageCode: string;
@@ -42,8 +41,7 @@ export const LinkSurvey = ({
emailVerificationStatus,
singleUseId,
singleUseResponse,
surveyDomain,
webAppUrl,
publicDomain,
responseCount,
verifiedEmail,
languageCode,
@@ -172,13 +170,13 @@ export const LinkSurvey = ({
handleResetSurvey={handleResetSurvey}
determineStyling={determineStyling}
isEmbed={isEmbed}
surveyDomain={surveyDomain}
publicDomain={publicDomain}
IS_FORMBRICKS_CLOUD={IS_FORMBRICKS_CLOUD}
IMPRINT_URL={IMPRINT_URL}
PRIVACY_URL={PRIVACY_URL}
isBrandingEnabled={project.linkSurveyBranding}>
<SurveyInline
appUrl={webAppUrl}
appUrl={publicDomain}
environmentId={survey.environmentId}
isPreviewMode={isPreview}
survey={survey}

View File

@@ -27,7 +27,7 @@ describe("PinScreen", () => {
logo: "logo.png",
linkSurveyBranding: true,
},
surveyDomain: "survey.example.com",
publicDomain: "survey.example.com",
webAppUrl: "https://app.example.com",
IS_FORMBRICKS_CLOUD: false,
languageCode: "en",

View File

@@ -16,8 +16,7 @@ interface PinScreenProps {
emailVerificationStatus?: string;
singleUseId?: string;
singleUseResponse?: Pick<Response, "id" | "finished">;
surveyDomain: string;
webAppUrl: string;
publicDomain: string;
IMPRINT_URL?: string;
PRIVACY_URL?: string;
IS_FORMBRICKS_CLOUD: boolean;
@@ -35,8 +34,7 @@ export const PinScreen = (props: PinScreenProps) => {
const {
surveyId,
project,
surveyDomain,
webAppUrl,
publicDomain,
emailVerificationStatus,
singleUseId,
singleUseResponse,
@@ -124,8 +122,7 @@ export const PinScreen = (props: PinScreenProps) => {
emailVerificationStatus={emailVerificationStatus}
singleUseId={singleUseId}
singleUseResponse={singleUseResponse}
surveyDomain={surveyDomain}
webAppUrl={webAppUrl}
publicDomain={publicDomain}
verifiedEmail={verifiedEmail}
languageCode={languageCode}
isEmbed={isEmbed}

View File

@@ -49,8 +49,8 @@ vi.mock("@/lib/utils/locale", () => ({
findMatchingLocale: vi.fn().mockResolvedValue("en"),
}));
vi.mock("@/lib/getSurveyUrl", () => ({
getSurveyDomain: vi.fn().mockReturnValue("https://survey-domain.com"),
vi.mock("@/lib/getPublicUrl", () => ({
getPublicDomain: vi.fn().mockReturnValue("https://public-domain.com"),
}));
vi.mock("@/modules/ee/license-check/lib/utils", () => ({

View File

@@ -4,9 +4,8 @@ import {
IS_RECAPTCHA_CONFIGURED,
PRIVACY_URL,
RECAPTCHA_SITE_KEY,
WEBAPP_URL,
} from "@/lib/constants";
import { getSurveyDomain } from "@/lib/getSurveyUrl";
import { getPublicDomain } from "@/lib/getPublicUrl";
import { findMatchingLocale } from "@/lib/utils/locale";
import { getMultiLanguagePermission } from "@/modules/ee/license-check/lib/utils";
import { getOrganizationIdFromEnvironmentId } from "@/modules/survey/lib/organization";
@@ -108,18 +107,17 @@ export const renderSurvey = async ({
const languageCode = getLanguageCode();
const isSurveyPinProtected = Boolean(survey.pin);
const responseCount = await getResponseCountBySurveyId(survey.id);
const surveyDomain = getSurveyDomain();
const publicDomain = getPublicDomain();
if (isSurveyPinProtected) {
return (
<PinScreen
surveyId={survey.id}
surveyDomain={surveyDomain}
publicDomain={publicDomain}
project={project}
emailVerificationStatus={emailVerificationStatus}
singleUseId={singleUseId}
singleUseResponse={singleUseResponse}
webAppUrl={WEBAPP_URL}
IMPRINT_URL={IMPRINT_URL}
PRIVACY_URL={PRIVACY_URL}
IS_FORMBRICKS_CLOUD={IS_FORMBRICKS_CLOUD}
@@ -139,11 +137,10 @@ export const renderSurvey = async ({
<LinkSurvey
survey={survey}
project={project}
surveyDomain={surveyDomain}
publicDomain={publicDomain}
emailVerificationStatus={emailVerificationStatus}
singleUseId={singleUseId}
singleUseResponse={singleUseResponse}
webAppUrl={WEBAPP_URL}
responseCount={survey.welcomeCard.showResponseCount ? responseCount : undefined}
verifiedEmail={verifiedEmail}
languageCode={languageCode}

View File

@@ -42,6 +42,12 @@ vi.mock("@/lib/constants", () => ({
AUDIT_LOG_ENABLED: true,
}));
vi.mock("@/lib/env", () => ({
env: {
PUBLIC_URL: "https://public-domain.com",
},
}));
vi.mock("@/modules/survey/link/actions");
vi.mock("react-hot-toast", () => ({

View File

@@ -41,6 +41,12 @@ vi.mock("@/lib/constants", () => ({
SMTP_PASSWORD: "password",
}));
vi.mock("@/lib/env", () => ({
env: {
PUBLIC_URL: "https://public-domain.com",
},
}));
vi.mock("@/modules/ee/contacts/lib/contact-survey-link");
vi.mock("@/modules/survey/link/lib/metadata-utils");
vi.mock("@/modules/survey/link/lib/data", () => ({

View File

@@ -1,4 +1,5 @@
import { IS_FORMBRICKS_CLOUD, SURVEY_URL } from "@/lib/constants";
import { IS_FORMBRICKS_CLOUD } from "@/lib/constants";
import { getPublicDomain } from "@/lib/getPublicUrl";
import { COLOR_DEFAULTS } from "@/lib/styling/constants";
import { getSurvey } from "@/modules/survey/lib/survey";
import { getProjectByEnvironmentId } from "@/modules/survey/link/lib/project";
@@ -24,7 +25,6 @@ vi.mock("@/modules/survey/link/lib/project", () => ({
vi.mock("@/lib/constants", () => ({
IS_FORMBRICKS_CLOUD: vi.fn(() => false),
WEBAPP_URL: "https://test.formbricks.com",
SURVEY_URL: "https://surveys.test.formbricks.com",
}));
vi.mock("@/lib/styling/constants", () => ({
@@ -171,13 +171,13 @@ describe("Metadata Utils", () => {
const result = getSurveyOpenGraphMetadata(surveyId, surveyName);
expect(result).toEqual({
metadataBase: new URL(SURVEY_URL as any),
metadataBase: new URL(getPublicDomain() as any),
openGraph: {
title: surveyName,
description: "Thanks a lot for your time 🙏",
url: `/s/${surveyId}`,
siteName: "",
images: [`/api/v1/og?brandColor=${brandColor}&name=${encodedName}`],
images: [`/api/v1/client/og?brandColor=${brandColor}&name=${encodedName}`],
locale: "en_US",
type: "website",
},
@@ -185,7 +185,7 @@ describe("Metadata Utils", () => {
card: "summary_large_image",
title: surveyName,
description: "Thanks a lot for your time 🙏",
images: [`/api/v1/og?brandColor=${brandColor}&name=${encodedName}`],
images: [`/api/v1/client/og?brandColor=${brandColor}&name=${encodedName}`],
},
});
});

View File

@@ -1,5 +1,5 @@
import { IS_FORMBRICKS_CLOUD } from "@/lib/constants";
import { getSurveyDomain } from "@/lib/getSurveyUrl";
import { getPublicDomain } from "@/lib/getPublicUrl";
import { COLOR_DEFAULTS } from "@/lib/styling/constants";
import { getSurvey } from "@/modules/survey/lib/survey";
import { getProjectByEnvironmentId } from "@/modules/survey/link/lib/project";
@@ -70,10 +70,10 @@ export const getSurveyOpenGraphMetadata = (surveyId: string, surveyName: string)
const brandColor = getBrandColorForURL(COLOR_DEFAULTS.brandColor); // Default color
const encodedName = getNameForURL(surveyName);
const ogImgURL = `/api/v1/og?brandColor=${brandColor}&name=${encodedName}`;
const ogImgURL = `/api/v1/client/og?brandColor=${brandColor}&name=${encodedName}`;
return {
metadataBase: new URL(getSurveyDomain()),
metadataBase: new URL(getPublicDomain()),
openGraph: {
title: surveyName,
description: "Thanks a lot for your time 🙏",

View File

@@ -25,7 +25,7 @@ describe("getMetadataForLinkSurvey", () => {
const mockBrandColor = "#123456";
const mockEncodedBrandColor = "123456";
const mockEncodedName = "Test-Survey";
const mockOgImageUrl = `/api/v1/og?brandColor=${mockEncodedBrandColor}&name=${mockEncodedName}`;
const mockOgImageUrl = `/api/v1/client/og?brandColor=${mockEncodedBrandColor}&name=${mockEncodedName}`;
beforeEach(() => {
vi.resetAllMocks();

Some files were not shown because too many files have changed in this diff Show More