Compare commits

...

23 Commits

Author SHA1 Message Date
Piyush Gupta
d46d92dd11 Merge branch 'main' of https://github.com/formbricks/formbricks into 322-bug-too-many-enterprise-license-checks-on-the-ee-server 2024-09-20 15:45:07 +05:30
Piyush Gupta
09b856699f feat: adds reactCache to fetchLicense servicwe 2024-09-20 15:34:39 +05:30
Piyush Gupta
20e107d7cd Merge branch 'main' of https://github.com/formbricks/formbricks 2024-09-20 11:49:29 +05:30
Piyush Gupta
4e630ad27f Merge branch 'main' of https://github.com/formbricks/formbricks 2024-09-20 10:32:02 +05:30
Piyush Gupta
d7258aab23 Merge branch 'main' of https://github.com/formbricks/formbricks 2024-09-18 16:49:54 +05:30
Piyush Gupta
5b633bb311 Merge branch 'main' of https://github.com/formbricks/formbricks 2024-09-18 11:05:01 +05:30
Piyush Gupta
d1cc021417 fix: version check API calls 2024-09-17 12:31:59 +05:30
Piyush Gupta
942236287a Merge branch 'main' of https://github.com/rajugangitla/formbricks 2024-09-17 11:53:52 +05:30
pandeymangg
57135d167b fix: github api call cache 2024-09-13 11:49:53 +05:30
Anshuman Pandey
916e47c55d Merge branch 'main' into main 2024-09-13 10:35:30 +05:30
RajuGangitla
5faccf1063 resolve merge conflicts 2024-09-11 10:22:45 +00:00
RajuGangitla
ebbc5abd3c IS_FORMBRICKS_CLOUD condtion added 2024-09-11 10:21:46 +00:00
Johannes
ad445d1915 tweaks 2024-09-11 11:35:52 +02:00
RajuGangitla
756d0c84af Merge branch 'formbricks:main' into main 2024-09-11 11:07:13 +05:30
RajuGangitla
8f6b356870 Merge branch 'main' of https://github.com/RajuGangitla/formbricks 2024-09-11 05:35:33 +00:00
RajuGangitla
e0ba9cb998 feat: info about new formbricks version 2024-09-11 05:34:36 +00:00
RajuGangitla
c6f1e9e7d5 Merge branch 'formbricks:main' into main 2024-09-11 09:58:58 +05:30
Anshuman Pandey
f025a70d20 Merge branch 'main' into main 2024-09-09 17:44:12 +05:30
pandeymangg
ba1e478d68 Merge remote-tracking branch 'origin/main' into raju-gangitla 2024-09-09 16:42:35 +05:30
Johannes
8e57082376 Merge branch 'main' into main 2024-09-08 15:25:29 +02:00
Johannes
2681d03e15 move loading to StatCard, parallelize API calls 2024-09-08 15:23:31 +02:00
RajuGangitla
72e023c530 Merge branch 'main' of https://github.com/RajuGangitla/formbricks 2024-09-06 07:40:34 +00:00
RajuGangitla
7088f9bd26 fix :Loading Skeleton for survey summary page #3085 2024-09-06 07:36:06 +00:00

View File

@@ -1,6 +1,7 @@
import "server-only";
import { HttpsProxyAgent } from "https-proxy-agent";
import fetch from "node-fetch";
import { cache as reactCache } from "react";
import { prisma } from "@formbricks/database";
import { cache, revalidateTag } from "@formbricks/lib/cache";
import {
@@ -184,53 +185,55 @@ export const getLicenseFeatures = async (): Promise<TEnterpriseLicenseFeatures |
}
};
export const fetchLicense = async (): Promise<TEnterpriseLicenseDetails | null> =>
await cache(
async () => {
if (!env.ENTERPRISE_LICENSE_KEY) return null;
try {
const now = new Date();
const startOfYear = new Date(now.getFullYear(), 0, 1); // January 1st of the current year
const endOfYear = new Date(now.getFullYear() + 1, 0, 0); // December 31st of the current year
export const fetchLicense = reactCache(
(): Promise<TEnterpriseLicenseDetails | null> =>
cache(
async () => {
if (!env.ENTERPRISE_LICENSE_KEY) return null;
try {
const now = new Date();
const startOfYear = new Date(now.getFullYear(), 0, 1); // January 1st of the current year
const endOfYear = new Date(now.getFullYear() + 1, 0, 0); // December 31st of the current year
const responseCount = await prisma.response.count({
where: {
createdAt: {
gte: startOfYear,
lt: endOfYear,
const responseCount = await prisma.response.count({
where: {
createdAt: {
gte: startOfYear,
lt: endOfYear,
},
},
},
});
});
const proxyUrl = env.HTTPS_PROXY || env.HTTP_PROXY;
const agent = proxyUrl ? new HttpsProxyAgent(proxyUrl) : undefined;
const proxyUrl = env.HTTPS_PROXY || env.HTTP_PROXY;
const agent = proxyUrl ? new HttpsProxyAgent(proxyUrl) : undefined;
const res = await fetch("https://ee.formbricks.com/api/licenses/check", {
body: JSON.stringify({
licenseKey: ENTERPRISE_LICENSE_KEY,
usage: { responseCount: responseCount },
}),
headers: { "Content-Type": "application/json" },
method: "POST",
agent,
});
const res = await fetch("https://ee.formbricks.com/api/licenses/check", {
body: JSON.stringify({
licenseKey: ENTERPRISE_LICENSE_KEY,
usage: { responseCount: responseCount },
}),
headers: { "Content-Type": "application/json" },
method: "POST",
agent,
});
if (res.ok) {
const responseJson = (await res.json()) as {
data: TEnterpriseLicenseDetails;
};
return responseJson.data;
if (res.ok) {
const responseJson = (await res.json()) as {
data: TEnterpriseLicenseDetails;
};
return responseJson.data;
}
return null;
} catch (error) {
console.error("Error while checking license: ", error);
return null;
}
return null;
} catch (error) {
console.error("Error while checking license: ", error);
return null;
}
},
[`fetchLicense-${hashedKey}`],
{ revalidate: 60 * 60 * 24 }
)();
},
[`fetchLicense-${hashedKey}`],
{ revalidate: 60 * 60 * 24 }
)()
);
export const getRemoveInAppBrandingPermission = (organization: TOrganization): boolean => {
if (IS_FORMBRICKS_CLOUD) return organization.billing.plan !== PRODUCT_FEATURE_KEYS.FREE;