Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

Update isPaid telemetry accounting to be tier-based instead of via slug

Tuan Dang7812061e66ac
diff --git a/backend/src/controllers/v2/secretsController.ts b/backend/src/controllers/v2/secretsController.ts
index 4e0bd04881..5c5140587a 100644
--- a/backend/src/controllers/v2/secretsController.ts
+++ b/backend/src/controllers/v2/secretsController.ts
@@ -51,7 +51,7 @@ export const batchSecrets = async (req: Request, res: Response) => {
if (!workspace) throw WorkspaceNotFoundError();
const orgPlan = await EELicenseService.getOrganizationPlan(workspace.organization.toString());
- const isPaid = orgPlan.tier < 1;
+ const isPaid = orgPlan.tier >= 1;
const createSecrets: BatchSecret[] = [];
const updateSecrets: BatchSecret[] = [];
@@ -387,7 +387,7 @@ export const createSecrets = async (req: Request, res: Response) => {
if (!workspace) throw WorkspaceNotFoundError();
const orgPlan = await EELicenseService.getOrganizationPlan(workspace.organization.toString());
- const isPaid = orgPlan.tier < 1;
+ const isPaid = orgPlan.tier >= 1;
let listOfSecretsToCreate;
if (Array.isArray(req.body.secrets)) {
@@ -613,7 +613,7 @@ export const getSecrets = async (req: Request, res: Response) => {
if (!workspace) throw WorkspaceNotFoundError();
const orgPlan = await EELicenseService.getOrganizationPlan(workspace.organization.toString());
- const isPaid = orgPlan.tier < 1;
+ const isPaid = orgPlan.tier >= 1;
// secrets to return
let secrets: ISecret[] = [];
@@ -963,7 +963,7 @@ export const updateSecrets = async (req: Request, res: Response) => {
if (!workspace) throw WorkspaceNotFoundError();
const orgPlan = await EELicenseService.getOrganizationPlan(workspace.organization.toString());
- const isPaid = orgPlan.tier < 1;
+ const isPaid = orgPlan.tier >= 1;
const postHogClient = await TelemetryService.getPostHogClient();
if (postHogClient) {
@@ -1100,13 +1100,11 @@ export const deleteSecrets = async (req: Request, res: Response) => {
workspaceId: new Types.ObjectId(key)
});
- const organizationId = (
- await Workspace.findOne({
- _id: key
- })
- )?.organization?.toString();
- const orgPlan = await EELicenseService.getOrganizationPlan(organizationId || '');
- const isPaid = orgPlan.slug != 'starter';
+ const workspace = await Workspace.findById(key);
+ if (!workspace) throw WorkspaceNotFoundError();
+
+ const orgPlan = await EELicenseService.getOrganizationPlan(workspace.organization.toString());
+ const isPaid = orgPlan.tier >= 1;
const postHogClient = await TelemetryService.getPostHogClient();
if (postHogClient) {
diff --git a/backend/src/ee/controllers/v1/organizationsController.ts b/backend/src/ee/controllers/v1/organizationsController.ts
index 0bdf6e4358..2dd212e771 100644
--- a/backend/src/ee/controllers/v1/organizationsController.ts
+++ b/backend/src/ee/controllers/v1/organizationsController.ts
@@ -7,13 +7,12 @@ import { EELicenseService } from '../../services';
* Return the organization's current plan and allowed feature set
*/
export const getOrganizationPlan = async (req: Request, res: Response) => {
- const plan = await EELicenseService.getOrganizationPlan(req.organization._id.toString());
+ const { organizationId } = req.params;
- // cache fetched plan for organization
- EELicenseService.localFeatureSet.set(req.organization._id.toString(), plan);
+ const plan = await EELicenseService.getOrganizationPlan(organizationId);
return res.status(200).send({
- plan
+ plan,
});
}
diff --git a/backend/src/ee/services/EELicenseService.ts b/backend/src/ee/services/EELicenseService.ts
index 38530dfa00..d8a11e49b1 100644
--- a/backend/src/ee/services/EELicenseService.ts
+++ b/backend/src/ee/services/EELicenseService.ts
@@ -17,7 +17,7 @@ import { OrganizationNotFoundError } from '../../utils/errors';
interface FeatureSet {
_id: string | null;
slug: 'starter' | 'team' | 'pro' | 'enterprise' | null;
- tier: number | null;
+ tier: number;
projectLimit: number | null;
memberLimit: number | null;
secretVersioning: boolean;
@@ -63,11 +63,13 @@ class EELicenseService {
});
}
- public async getOrganizationPlan(organizationId: string) {
+ public async getOrganizationPlan(organizationId: string): Promise<FeatureSet> {
try {
if (this.instanceType === 'cloud') {
- const cachedPlan = this.localFeatureSet.get(organizationId);
- if (cachedPlan) return cachedPlan;
+ const cachedPlan = this.localFeatureSet.get<FeatureSet>(organizationId);
+ if (cachedPlan) {
+ return cachedPlan;
+ }
const organization = await Organization.findById(organizationId);
if (!organization) throw OrganizationNotFoundError();
@@ -76,6 +78,9 @@ class EELicenseService {
`${await getLicenseServerUrl()}/api/license-server/v1/customers/${organization.customerId}/cloud-plan`
);
+ // cache fetched plan for organization
+ this.localFeatureSet.set(organizationId, currentPlan);
+
return currentPlan;
}
} catch (err) {
diff --git a/backend/src/helpers/organization.ts b/backend/src/helpers/organization.ts
index 43b1bea830..54f050a368 100644
--- a/backend/src/helpers/organization.ts
+++ b/backend/src/helpers/organization.ts
@@ -251,6 +251,8 @@ const updateSubscriptionOrgQuantity = async ({
quantity
}
);
+
+ EELicenseService.localFeatureSet.del(organizationId);
}
if (EELicenseService.instanceType === 'enterprise-self-hosted') {