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

View File

@@ -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 };

View File

@@ -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();

View File

@@ -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;
};

View File

@@ -10,6 +10,7 @@ import {
UsersSchema
} from "@app/db/schemas";
import { getLicenseKeyConfig } from "@app/ee/services/license/license-fns";
import { LicenseType } from "@app/ee/services/license/license-types";
import { getConfig, overridableKeys } from "@app/lib/config/env";
import { crypto } from "@app/lib/crypto/cryptography";
import { BadRequestError } from "@app/lib/errors";
@@ -67,7 +68,7 @@ export const registerAdminRouter = async (server: FastifyZodProvider) => {
const serverEnvs = getConfig();
const licenseKeyConfig = getLicenseKeyConfig();
const hasOfflineLicense = licenseKeyConfig.isValid && licenseKeyConfig.type === "offline";
const hasOfflineLicense = licenseKeyConfig.isValid && licenseKeyConfig.type === LicenseType.Offline;
return {
config: {

View File

@@ -35,7 +35,8 @@ export const offlineUsageReportServiceFactory = ({
if (!hasOfflineLicense) {
throw new BadRequestError({
message: "Offline usage reports are not enabled. An offline license must be configured in LICENSE_KEY."
message:
"Offline usage reports are not enabled. Usage reports are only available for self-hosted offline instances"
});
}

View File

@@ -14,7 +14,7 @@ This guide walks through how you can use these paid features on a self-hosted in
Once purchased, you will be issued a license key.
</Step>
<Step title="Activate the license">
Assign the issued license key to the `LICENSE_KEY` environment variable in your Infisical instance. The system will automatically detect whether the license is online or offline.
Set your license key as the value of the **LICENSE_KEY** environment variable within your Infisical instance.
<Tabs>
<Tab title="Regular License">
@@ -33,7 +33,7 @@ This guide walks through how you can use these paid features on a self-hosted in
- The system will automatically detect that it's an offline license based on the key format.
<Note>
<b>Backwards Compatibility:</b> The `LICENSE_KEY_OFFLINE` environment variable is still supported for backwards compatibility, but we recommend using `LICENSE_KEY` for all license types going forward.
While the LICENSE_KEY_OFFLINE environment variable continues to be supported for compatibility with existing configurations, we recommend transitioning to LICENSE_KEY for all license types going forward.
</Note>
</Tab>
</Tabs>