mirror of
https://github.com/formbricks/formbricks.git
synced 2026-04-20 11:22:55 -05:00
refactor
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import {
|
||||
OPTIONS,
|
||||
PUT,
|
||||
} from "@/modules/ee/contacts/api/client/[environmentId]/contacts/[userId]/attributes/route";
|
||||
} from "@/modules/ee/contacts/api/v1/client/[environmentId]/contacts/[userId]/attributes/route";
|
||||
|
||||
export { OPTIONS, PUT };
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import {
|
||||
GET,
|
||||
OPTIONS,
|
||||
} from "@/modules/ee/contacts/api/client/[environmentId]/identify/contacts/[userId]/route";
|
||||
} from "@/modules/ee/contacts/api/v1/client/[environmentId]/identify/contacts/[userId]/route";
|
||||
|
||||
export { GET, OPTIONS };
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
import { OPTIONS, POST } from "@/modules/ee/contacts/api/client/[environmentId]/user/route";
|
||||
import { OPTIONS, POST } from "@/modules/ee/contacts/api/v1/client/[environmentId]/user/route";
|
||||
|
||||
export { POST, OPTIONS };
|
||||
|
||||
@@ -2,6 +2,6 @@ import {
|
||||
DELETE,
|
||||
GET,
|
||||
PUT,
|
||||
} from "@/modules/ee/contacts/api/management/contact-attribute-keys/[contactAttributeKeyId]/route";
|
||||
} from "@/modules/ee/contacts/api/v1/management/contact-attribute-keys/[contactAttributeKeyId]/route";
|
||||
|
||||
export { DELETE, GET, PUT };
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
import { GET, POST } from "@/modules/ee/contacts/api/management/contact-attribute-keys/route";
|
||||
import { GET, POST } from "@/modules/ee/contacts/api/v1/management/contact-attribute-keys/route";
|
||||
|
||||
export { GET, POST };
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
import { GET } from "@/modules/ee/contacts/api/management/contact-attributes/route";
|
||||
import { GET } from "@/modules/ee/contacts/api/v1/management/contact-attributes/route";
|
||||
|
||||
export { GET };
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
import { DELETE, GET } from "@/modules/ee/contacts/api/management/contacts/[contactId]/route";
|
||||
import { DELETE, GET } from "@/modules/ee/contacts/api/v1/management/contacts/[contactId]/route";
|
||||
|
||||
export { DELETE, GET };
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { GET } from "@/modules/ee/contacts/api/management/contacts/route";
|
||||
import { GET } from "@/modules/ee/contacts/api/v1/management/contacts/route";
|
||||
|
||||
export { GET };
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import {
|
||||
OPTIONS,
|
||||
PUT,
|
||||
} from "@/modules/ee/contacts/api/client/[environmentId]/contacts/[userId]/attributes/route";
|
||||
} from "@/modules/ee/contacts/api/v1/client/[environmentId]/contacts/[userId]/attributes/route";
|
||||
|
||||
export { OPTIONS, PUT };
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import {
|
||||
GET,
|
||||
OPTIONS,
|
||||
} from "@/modules/ee/contacts/api/client/[environmentId]/identify/contacts/[userId]/route";
|
||||
} from "@/modules/ee/contacts/api/v1/client/[environmentId]/identify/contacts/[userId]/route";
|
||||
|
||||
export { GET, OPTIONS };
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
import { OPTIONS, POST } from "@/modules/ee/contacts/api/client/[environmentId]/user/route";
|
||||
import { OPTIONS, POST } from "@/modules/ee/contacts/api/v1/client/[environmentId]/user/route";
|
||||
|
||||
export { POST, OPTIONS };
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
import { PUT } from "@/modules/ee/contacts/api/bulk/route";
|
||||
|
||||
export { PUT };
|
||||
3
apps/web/app/api/v2/management/contacts/bulk/route.ts
Normal file
3
apps/web/app/api/v2/management/contacts/bulk/route.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
import { PUT } from "@/modules/ee/contacts/api/v2/management/contacts/bulk/route";
|
||||
|
||||
export { PUT };
|
||||
@@ -19,11 +19,6 @@ export const isManagementApiRoute = (url: string): boolean => {
|
||||
return regex.test(url);
|
||||
};
|
||||
|
||||
export const isContactsBulkApiRoute = (url: string): boolean => {
|
||||
const regex = /^\/api\/v2\/contacts\/bulk$/;
|
||||
return regex.test(url);
|
||||
};
|
||||
|
||||
export const isShareUrlRoute = (url: string): boolean => {
|
||||
const regex = /\/share\/[A-Za-z0-9]+\/(?:summary|responses)/;
|
||||
return regex.test(url);
|
||||
|
||||
@@ -10,7 +10,6 @@ import {
|
||||
import {
|
||||
isAuthProtectedRoute,
|
||||
isClientSideApiRoute,
|
||||
isContactsBulkApiRoute,
|
||||
isForgotPasswordRoute,
|
||||
isLoginRoute,
|
||||
isManagementApiRoute,
|
||||
@@ -101,7 +100,7 @@ export const middleware = async (originalRequest: NextRequest) => {
|
||||
});
|
||||
|
||||
// Enforce HTTPS for management endpoints
|
||||
if (isManagementApiRoute(request.nextUrl.pathname) || isContactsBulkApiRoute(request.nextUrl.pathname)) {
|
||||
if (isManagementApiRoute(request.nextUrl.pathname)) {
|
||||
const httpsResponse = enforceHttps(request);
|
||||
if (httpsResponse) return httpsResponse;
|
||||
}
|
||||
@@ -153,6 +152,5 @@ export const config = {
|
||||
"/auth/forgot-password",
|
||||
"/api/v1/management/:path*",
|
||||
"/api/v2/management/:path*",
|
||||
"/api/v2/contacts/bulk",
|
||||
],
|
||||
};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { contactCache } from "@/lib/cache/contact";
|
||||
import { contactAttributeCache } from "@/lib/cache/contact-attribute";
|
||||
import { getContactByUserId } from "@/modules/ee/contacts/api/client/[environmentId]/identify/contacts/[userId]/lib/contact";
|
||||
import { getContactByUserId } from "@/modules/ee/contacts/api/v1/client/[environmentId]/identify/contacts/[userId]/lib/contact";
|
||||
import { prisma } from "@formbricks/database";
|
||||
import { cache } from "@formbricks/lib/cache";
|
||||
import { segmentCache } from "@formbricks/lib/cache/segment";
|
||||
@@ -1,5 +1,5 @@
|
||||
import { contactAttributeCache } from "@/lib/cache/contact-attribute";
|
||||
import { getContactAttributes } from "@/modules/ee/contacts/api/client/[environmentId]/identify/contacts/[userId]/lib/attributes";
|
||||
import { getContactAttributes } from "@/modules/ee/contacts/api/v1/client/[environmentId]/identify/contacts/[userId]/lib/attributes";
|
||||
import { evaluateSegment } from "@/modules/ee/contacts/segments/lib/segments";
|
||||
import { Prisma } from "@prisma/client";
|
||||
import { cache as reactCache } from "react";
|
||||
@@ -59,7 +59,7 @@ export const upsertBulkContacts = async (
|
||||
};
|
||||
}
|
||||
|
||||
const emailKey = "email";
|
||||
const emailAttributeKey = "email";
|
||||
|
||||
// Get unique attribute keys from the payload
|
||||
const keys = Array.from(
|
||||
@@ -95,7 +95,7 @@ export const upsertBulkContacts = async (
|
||||
environmentId,
|
||||
attributes: {
|
||||
some: {
|
||||
attributeKey: { key: emailKey },
|
||||
attributeKey: { key: emailAttributeKey },
|
||||
value: { in: parsedEmails },
|
||||
},
|
||||
},
|
||||
@@ -120,7 +120,7 @@ export const upsertBulkContacts = async (
|
||||
>();
|
||||
|
||||
existingContacts.forEach((contact) => {
|
||||
const emailAttr = contact.attributes.find((attr) => attr.attributeKey.key === emailKey);
|
||||
const emailAttr = contact.attributes.find((attr) => attr.attributeKey.key === emailAttributeKey);
|
||||
|
||||
if (emailAttr) {
|
||||
contactMap.set(emailAttr.value, {
|
||||
@@ -157,7 +157,7 @@ export const upsertBulkContacts = async (
|
||||
}[] = [];
|
||||
|
||||
for (const contact of filteredContacts) {
|
||||
const emailAttr = contact.attributes.find((attr) => attr.attributeKey.key === emailKey);
|
||||
const emailAttr = contact.attributes.find((attr) => attr.attributeKey.key === emailAttributeKey);
|
||||
|
||||
if (emailAttr && contactMap.has(emailAttr.value)) {
|
||||
contactsToUpdate.push({
|
||||
@@ -1,7 +1,7 @@
|
||||
import { contactCache } from "@/lib/cache/contact";
|
||||
import { contactAttributeCache } from "@/lib/cache/contact-attribute";
|
||||
import { contactAttributeKeyCache } from "@/lib/cache/contact-attribute-key";
|
||||
import { upsertBulkContacts } from "@/modules/ee/contacts/api/bulk/lib/contact";
|
||||
import { upsertBulkContacts } from "@/modules/ee/contacts/api/v2/management/contacts/bulk/lib/contact";
|
||||
import { beforeEach, describe, expect, test, vi } from "vitest";
|
||||
import { prisma } from "@formbricks/database";
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { responses } from "@/modules/api/v2/lib/response";
|
||||
import { handleApiError } from "@/modules/api/v2/lib/utils";
|
||||
import { authenticatedApiClient } from "@/modules/api/v2/management/auth/authenticated-api-client";
|
||||
import { upsertBulkContacts } from "@/modules/ee/contacts/api/bulk/lib/contact";
|
||||
import { upsertBulkContacts } from "@/modules/ee/contacts/api/v2/management/contacts/bulk/lib/contact";
|
||||
import { ZContactBulkUploadRequest } from "@/modules/ee/contacts/types/contact";
|
||||
import { getIsContactsEnabled } from "@/modules/ee/license-check/lib/utils";
|
||||
|
||||
@@ -45,7 +45,7 @@ export default defineConfig({
|
||||
"modules/survey/lib/client-utils.ts",
|
||||
"modules/survey/list/components/survey-card.tsx",
|
||||
"modules/survey/list/components/survey-dropdown-menu.tsx",
|
||||
"modules/ee/contacts/api/bulk/lib/contact.ts",
|
||||
"modules/ee/contacts/api/v2/management/contacts/bulk/lib/contact.ts",
|
||||
],
|
||||
exclude: [
|
||||
"**/.next/**",
|
||||
|
||||
Reference in New Issue
Block a user