diff --git a/packages/core/src/libraries/quota.ts b/packages/core/src/libraries/quota.ts index c3f0823d6706..16cfab50f5c3 100644 --- a/packages/core/src/libraries/quota.ts +++ b/packages/core/src/libraries/quota.ts @@ -23,6 +23,11 @@ const notNumber = (): never => { throw new Error('Only support usage query for numeric quota'); }; +const shouldReportSubscriptionUpdates = (planId: string, key: keyof SubscriptionQuota): boolean => + EnvSet.values.isDevFeaturesEnabled && + planId === ReservedPlanId.Pro && + isReportSubscriptionUpdatesUsageKey(key); + export const createQuotaLibrary = ( queries: Queries, cloudConnection: CloudConnectionLibrary, @@ -165,11 +170,7 @@ export const createQuotaLibrary = ( } = await getTenantSubscriptionData(cloudConnection); // Do not block Pro plan from adding add-on resources. - if ( - isDevFeaturesEnabled && - planId === ReservedPlanId.Pro && - isReportSubscriptionUpdatesUsageKey(key) - ) { + if (shouldReportSubscriptionUpdates(planId, key)) { return; } @@ -276,7 +277,7 @@ export const createQuotaLibrary = ( }; const reportSubscriptionUpdatesUsage = async (key: keyof SubscriptionQuota) => { - const { isCloud, isIntegrationTest, isDevFeaturesEnabled } = EnvSet.values; + const { isCloud, isIntegrationTest } = EnvSet.values; // Cloud only feature, skip in non-cloud environments if (!isCloud) { @@ -290,12 +291,7 @@ export const createQuotaLibrary = ( const { planId } = await getTenantSubscriptionData(cloudConnection); - // Do not block Pro plan from adding add-on resources. - if ( - isDevFeaturesEnabled && - planId === ReservedPlanId.Pro && - isReportSubscriptionUpdatesUsageKey(key) - ) { + if (shouldReportSubscriptionUpdates(planId, key)) { await reportSubscriptionUpdates(cloudConnection, key); } }; diff --git a/packages/core/src/utils/subscription/index.ts b/packages/core/src/utils/subscription/index.ts index 6f5e97e81aca..303cb8a95ddc 100644 --- a/packages/core/src/utils/subscription/index.ts +++ b/packages/core/src/utils/subscription/index.ts @@ -69,8 +69,12 @@ export const getTenantSubscriptionScopeUsage = async ( export const reportSubscriptionUpdates = async ( cloudConnection: CloudConnectionLibrary, - usageKey: ReportSubscriptionUpdatesUsageKey + usageKey: keyof SubscriptionQuota ): Promise => { + if (!isReportSubscriptionUpdatesUsageKey(usageKey)) { + return; + } + const client = await cloudConnection.getClient(); // We only report to the Cloud to notify the resource usage updates, and do not care the response. We will see error logs on the Cloud side if there is any issue. await trySafe(