From 03b97fdb512d6cd8a34cb912badee9d7db2f3f87 Mon Sep 17 00:00:00 2001 From: sean-brydon <55134778+sean-brydon@users.noreply.github.com> Date: Fri, 2 Aug 2024 18:10:58 +0100 Subject: [PATCH] fix: typo in license service + move to a noop (#16029) * fix/typoe * use noop * Update packages/features/ee/common/server/LicenseKeyService.ts * wip - try unbork e2e * update conditional * use e2e value for NOOP resolve value --------- Co-authored-by: Udit Takkar <53316345+Udit-takkar@users.noreply.github.com> Co-authored-by: Alex van Andel --- .../ee/common/server/LicenseKeyService.ts | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/packages/features/ee/common/server/LicenseKeyService.ts b/packages/features/ee/common/server/LicenseKeyService.ts index 596805a692..099579edcc 100644 --- a/packages/features/ee/common/server/LicenseKeyService.ts +++ b/packages/features/ee/common/server/LicenseKeyService.ts @@ -11,7 +11,12 @@ export enum UsageEvent { USER = "user", } -class LicenseKeyService { +interface ILicenseKeyService { + incrementUsage(usageEvent?: UsageEvent): Promise; + checkLicense(): Promise; +} + +class LicenseKeyService implements ILicenseKeyService { private readonly baseUrl = CALCOM_PRIVATE_API_ROUTE; private readonly licenseKey: string; public readonly CACHING_TIME = 86_400_000; // 24 hours in milliseconds @@ -23,9 +28,10 @@ class LicenseKeyService { } // Static async factory method - public static async create(): Promise { + public static async create(): Promise { const licenseKey = await getDeploymentKey(prisma); - return new LicenseKeyService(licenseKey); + const useNoop = !licenseKey || process.env.NEXT_PUBLIC_IS_E2E === "1"; + return !useNoop ? new LicenseKeyService(licenseKey) : new NoopLicenseKeyService(); } private async fetcher({ @@ -85,7 +91,7 @@ class LicenseKeyService { try { const response = await this.fetcher({ url, options: { mode: "cors" } }); const data = await response.json(); - cache.put(url, data.stauts, this.CACHING_TIME); + cache.put(url, data.status, this.CACHING_TIME); return data.status; } catch (error) { console.error("Check license failed:", error); @@ -94,4 +100,15 @@ class LicenseKeyService { } } +export class NoopLicenseKeyService implements ILicenseKeyService { + async incrementUsage(_usageEvent?: UsageEvent): Promise { + // No operation + return Promise.resolve(); + } + + async checkLicense(): Promise { + return Promise.resolve(process.env.NEXT_PUBLIC_IS_E2E === "1"); + } +} + export default LicenseKeyService;