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 <[email protected]> Co-authored-by: Alex van Andel <[email protected]>
This commit is contained in:
1 file changed
+21
-4
@@ -11,7 +11,12 @@ export enum UsageEvent {
|
|||||||
USER = "user",
|
USER = "user",
|
||||||
}
|
}
|
||||||
|
|
||||||
class LicenseKeyService {
|
interface ILicenseKeyService {
|
||||||
|
incrementUsage(usageEvent?: UsageEvent): Promise<any>;
|
||||||
|
checkLicense(): Promise<boolean>;
|
||||||
|
}
|
||||||
|
|
||||||
|
class LicenseKeyService implements ILicenseKeyService {
|
||||||
private readonly baseUrl = CALCOM_PRIVATE_API_ROUTE;
|
private readonly baseUrl = CALCOM_PRIVATE_API_ROUTE;
|
||||||
private readonly licenseKey: string;
|
private readonly licenseKey: string;
|
||||||
public readonly CACHING_TIME = 86_400_000; // 24 hours in milliseconds
|
public readonly CACHING_TIME = 86_400_000; // 24 hours in milliseconds
|
||||||
@@ -23,9 +28,10 @@ class LicenseKeyService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Static async factory method
|
// Static async factory method
|
||||||
public static async create(): Promise<LicenseKeyService> {
|
public static async create(): Promise<ILicenseKeyService> {
|
||||||
const licenseKey = await getDeploymentKey(prisma);
|
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({
|
private async fetcher({
|
||||||
@@ -85,7 +91,7 @@ class LicenseKeyService {
|
|||||||
try {
|
try {
|
||||||
const response = await this.fetcher({ url, options: { mode: "cors" } });
|
const response = await this.fetcher({ url, options: { mode: "cors" } });
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
cache.put(url, data.stauts, this.CACHING_TIME);
|
cache.put(url, data.status, this.CACHING_TIME);
|
||||||
return data.status;
|
return data.status;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Check license failed:", error);
|
console.error("Check license failed:", error);
|
||||||
@@ -94,4 +100,15 @@ class LicenseKeyService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class NoopLicenseKeyService implements ILicenseKeyService {
|
||||||
|
async incrementUsage(_usageEvent?: UsageEvent): Promise<any> {
|
||||||
|
// No operation
|
||||||
|
return Promise.resolve();
|
||||||
|
}
|
||||||
|
|
||||||
|
async checkLicense(): Promise<boolean> {
|
||||||
|
return Promise.resolve(process.env.NEXT_PUBLIC_IS_E2E === "1");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export default LicenseKeyService;
|
export default LicenseKeyService;
|
||||||
Reference in new issue
Block a user