fix: review suggestions

This commit is contained in:
Piyush Gupta
2025-11-17 21:05:25 +05:30
parent 055029b5f7
commit d951c40aba
6 changed files with 21 additions and 13 deletions
@@ -7,7 +7,7 @@ import { BadRequestError } from "@app/lib/errors";
import { logger } from "@app/lib/logger";
import { UserAliasType } from "@app/services/user-alias/user-alias-types";
import { TFeatureSet, TLicenseKeyConfig, TOfflineLicenseContents } from "./license-types";
import { LicenseType, TFeatureSet, TLicenseKeyConfig, TOfflineLicenseContents } from "./license-types";
export const isOfflineLicenseKey = (licenseKey: string): boolean => {
try {
@@ -32,10 +32,10 @@ export const getLicenseKeyConfig = (
if (licenseKey) {
if (isOfflineLicenseKey(licenseKey)) {
return { isValid: true, licenseKey, type: "offline" };
return { isValid: true, licenseKey, type: LicenseType.Offline };
}
return { isValid: true, licenseKey, type: "online" };
return { isValid: true, licenseKey, type: LicenseType.Online };
}
const offlineLicenseKey = cfg.LICENSE_KEY_OFFLINE;
@@ -43,7 +43,7 @@ export const getLicenseKeyConfig = (
// backwards compatibility
if (offlineLicenseKey) {
if (isOfflineLicenseKey(offlineLicenseKey)) {
return { isValid: true, licenseKey: offlineLicenseKey, type: "offline" };
return { isValid: true, licenseKey: offlineLicenseKey, type: LicenseType.Offline };
}
return { isValid: false };
@@ -25,6 +25,7 @@ import { TLicenseDALFactory } from "./license-dal";
import { getDefaultOnPremFeatures, getLicenseKeyConfig, setupLicenseRequestWithStore } from "./license-fns";
import {
InstanceType,
LicenseType,
TAddOrgPmtMethodDTO,
TAddOrgTaxIdDTO,
TCreateOrgPortalSession,
@@ -87,7 +88,7 @@ export const licenseServiceFactory = ({
);
const onlineLicenseKey =
licenseKeyConfig.isValid && licenseKeyConfig.type === "online" ? licenseKeyConfig.licenseKey : "";
licenseKeyConfig.isValid && licenseKeyConfig.type === LicenseType.Online ? licenseKeyConfig.licenseKey : "";
const licenseServerOnPremApi = setupLicenseRequestWithStore(
envConfig.LICENSE_SERVER_URL || "",
@@ -135,7 +136,7 @@ export const licenseServiceFactory = ({
return;
}
if (licenseKeyConfig.isValid && licenseKeyConfig.type === "online") {
if (licenseKeyConfig.isValid && licenseKeyConfig.type === LicenseType.Online) {
const token = await licenseServerOnPremApi.refreshLicense();
if (token) {
await syncLicenseKeyOnPremFeatures(true);
@@ -146,7 +147,7 @@ export const licenseServiceFactory = ({
return;
}
if (licenseKeyConfig.isValid && licenseKeyConfig.type === "offline") {
if (licenseKeyConfig.isValid && licenseKeyConfig.type === LicenseType.Offline) {
let isValidOfflineLicense = true;
const contents: TOfflineLicenseContents = JSON.parse(
Buffer.from(licenseKeyConfig.licenseKey, "base64").toString("utf8")
@@ -188,7 +189,7 @@ export const licenseServiceFactory = ({
};
const initializeBackgroundSync = async () => {
if (licenseKeyConfig?.isValid && licenseKeyConfig?.type === "online") {
if (licenseKeyConfig?.isValid && licenseKeyConfig?.type === LicenseType.Online) {
logger.info("Setting up background sync process for refresh onPremFeatures");
const job = new CronJob("*/10 * * * *", syncLicenseKeyOnPremFeatures);
job.start();
@@ -137,6 +137,11 @@ export type TOrgInvoiceDTO = TOrgPermission;
export type TOrgLicensesDTO = TOrgPermission;
export enum LicenseType {
Offline = "offline",
Online = "online"
}
export type TLicenseKeyConfig =
| {
isValid: false;
@@ -144,5 +149,5 @@ export type TLicenseKeyConfig =
| {
isValid: true;
licenseKey: string;
type: "offline" | "online";
type: LicenseType;
};