The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
chore(billing): clean up the leftovers of the credit allowance migration (#26475)
Etiennec8783aaf712b
diff --git a/packages/twenty-front/src/modules/ai/hooks/__tests__/useHasReachedAiChatCreditsCap.test.tsx b/packages/twenty-front/src/modules/ai/hooks/__tests__/useHasReachedAiChatCreditsCap.test.tsxindex 3f972e8a477..7fec6d5639f 100644--- a/packages/twenty-front/src/modules/ai/hooks/__tests__/useHasReachedAiChatCreditsCap.test.tsx+++ b/packages/twenty-front/src/modules/ai/hooks/__tests__/useHasReachedAiChatCreditsCap.test.tsx@@ -1,4 +1,4 @@-import { CombinedGraphQLErrors } from '@apollo/client/errors';+import { type CombinedGraphQLErrors } from '@apollo/client/errors';import { renderHook } from '@testing-library/react';import { Provider as JotaiProvider } from 'jotai';import { type ReactNode } from 'react';@@ -7,6 +7,8 @@ import { AgentChatComponentInstanceContext } from '@/ai/contexts/AgentChatComponimport { useHasReachedAiChatCreditsCap } from '@/ai/hooks/useHasReachedAiChatCreditsCap';import { agentChatDisplayedThreadState } from '@/ai/states/agentChatDisplayedThreadState';import { agentChatErrorComponentFamilyState } from '@/ai/states/agentChatErrorComponentFamilyState';+import { AiChatErrorCode } from '@/ai/utils/aiChatErrorCode';+import { createAiChatCodedError } from '@/ai/utils/createAiChatCodedError';import { currentWorkspaceState } from '@/auth/states/currentWorkspaceState';import {jotaiStore,@@ -61,18 +63,10 @@ const setWorkspaceWithoutBillingSubscription = () => {};const creditsExhaustedError = () =>- new CombinedGraphQLErrors({- errors: [- {- message: 'Credits exhausted',- extensions: {- code: 'FORBIDDEN',- subCode: 'BILLING_CREDITS_EXHAUSTED',- },- },- ],- data: null,- });+ createAiChatCodedError(+ 'Chat stopped: no more available credits.',+ AiChatErrorCode.CREDITS_EXHAUSTED,+ );const renderHasReachedAiChatCreditsCap = () =>renderHook(() => useHasReachedAiChatCreditsCap(), { wrapper: Wrapper });diff --git a/packages/twenty-front/src/modules/ai/hooks/useAgentChatSubscription.ts b/packages/twenty-front/src/modules/ai/hooks/useAgentChatSubscription.tsindex 09b536c67a1..be7924c980d 100644--- a/packages/twenty-front/src/modules/ai/hooks/useAgentChatSubscription.ts+++ b/packages/twenty-front/src/modules/ai/hooks/useAgentChatSubscription.ts@@ -385,7 +385,7 @@ export const useAgentChatSubscription = (threadId: string | null) => {errorAtom,createAiChatCodedError('Chat stopped: no more available credits.',- AiChatErrorCode.BILLING_CREDITS_EXHAUSTED,+ AiChatErrorCode.CREDITS_EXHAUSTED,),);diff --git a/packages/twenty-front/src/modules/ai/utils/__tests__/isAiChatCreditsExhaustedError.test.ts b/packages/twenty-front/src/modules/ai/utils/__tests__/isAiChatCreditsExhaustedError.test.tsindex dd2c0ad2dbc..eb25431e9da 100644--- a/packages/twenty-front/src/modules/ai/utils/__tests__/isAiChatCreditsExhaustedError.test.ts+++ b/packages/twenty-front/src/modules/ai/utils/__tests__/isAiChatCreditsExhaustedError.test.ts@@ -1,5 +1,7 @@import { CombinedGraphQLErrors } from '@apollo/client/errors';+import { AiChatErrorCode } from '@/ai/utils/aiChatErrorCode';+import { createAiChatCodedError } from '@/ai/utils/createAiChatCodedError';import { isAiChatCreditsExhaustedError } from '@/ai/utils/isAiChatCreditsExhaustedError';const buildError = (extensions: Record<string, unknown>) =>@@ -9,10 +11,10 @@ const buildError = (extensions: Record<string, unknown>) =>});describe('isAiChatCreditsExhaustedError', () => {- it('covers both ways the server reports spent credits', () => {+ it('covers both ways spent credits reach the client', () => {expect(isAiChatCreditsExhaustedError(- buildError({ code: 'BILLING_CREDITS_EXHAUSTED' }),+ createAiChatCodedError('refused', AiChatErrorCode.CREDITS_EXHAUSTED),),).toBe(true);diff --git a/packages/twenty-front/src/modules/ai/utils/aiChatErrorCode.ts b/packages/twenty-front/src/modules/ai/utils/aiChatErrorCode.tsindex f57bd4be093..8ae6e79c057 100644--- a/packages/twenty-front/src/modules/ai/utils/aiChatErrorCode.ts+++ b/packages/twenty-front/src/modules/ai/utils/aiChatErrorCode.ts@@ -1,5 +1,5 @@export const AiChatErrorCode = {- BILLING_CREDITS_EXHAUSTED: 'BILLING_CREDITS_EXHAUSTED',+ CREDITS_EXHAUSTED: 'CREDITS_EXHAUSTED',CONTEXT_WINDOW_EXCEEDED: 'CONTEXT_WINDOW_EXCEEDED',API_KEY_NOT_CONFIGURED: 'API_KEY_NOT_CONFIGURED',CONNECTION_LOST: 'CONNECTION_LOST',diff --git a/packages/twenty-front/src/modules/ai/utils/isAiChatCreditsExhaustedError.ts b/packages/twenty-front/src/modules/ai/utils/isAiChatCreditsExhaustedError.tsindex 12b8b066a77..e113beef470 100644--- a/packages/twenty-front/src/modules/ai/utils/isAiChatCreditsExhaustedError.ts+++ b/packages/twenty-front/src/modules/ai/utils/isAiChatCreditsExhaustedError.ts@@ -3,5 +3,5 @@ import { getAiChatQuotaExhaustedKind } from '@/ai/utils/getAiChatQuotaExhaustedKimport { isGraphqlErrorOfType } from '~/utils/is-graphql-error-of-type.util';export const isAiChatCreditsExhaustedError = (error: unknown): boolean =>- isGraphqlErrorOfType(error, AiChatErrorCode.BILLING_CREDITS_EXHAUSTED) ||+ isGraphqlErrorOfType(error, AiChatErrorCode.CREDITS_EXHAUSTED) ||getAiChatQuotaExhaustedKind(error) === 'allowance';diff --git a/packages/twenty-front/src/utils/__tests__/is-graphql-error-of-type.util.test.ts b/packages/twenty-front/src/utils/__tests__/is-graphql-error-of-type.util.test.tsindex 6813425f209..7e1089c698b 100644--- a/packages/twenty-front/src/utils/__tests__/is-graphql-error-of-type.util.test.ts+++ b/packages/twenty-front/src/utils/__tests__/is-graphql-error-of-type.util.test.ts@@ -13,15 +13,17 @@ describe('isGraphqlErrorOfType', () => {it('matches a subCode from an Apollo GraphQL error', () => {const error = createCombinedGraphQLError([{- message: 'Credits exhausted',+ message: 'No active subscription',extensions: {code: 'FORBIDDEN',- subCode: 'BILLING_CREDITS_EXHAUSTED',+ subCode: 'BILLING_SUBSCRIPTION_INACTIVE',},},]);- expect(isGraphqlErrorOfType(error, 'BILLING_CREDITS_EXHAUSTED')).toBe(true);+ expect(isGraphqlErrorOfType(error, 'BILLING_SUBSCRIPTION_INACTIVE')).toBe(+ true,+ );});it('matches the GraphQL code when no subCode is present', () => {diff --git a/packages/twenty-server/src/engine/core-modules/billing/app-billing/app-billing.module.ts b/packages/twenty-server/src/engine/core-modules/billing/app-billing/app-billing.module.tsindex abe74a3590f..5aed1f03b54 100644--- a/packages/twenty-server/src/engine/core-modules/billing/app-billing/app-billing.module.ts+++ b/packages/twenty-server/src/engine/core-modules/billing/app-billing/app-billing.module.ts@@ -10,6 +10,7 @@ import { BillingModule } from 'src/engine/core-modules/billing/billing.module';import { ThrottlerModule } from 'src/engine/core-modules/throttler/throttler.module';import { TwentyConfigModule } from 'src/engine/core-modules/twenty-config/twenty-config.module';import { UserWorkspaceEntity } from 'src/engine/core-modules/user-workspace/user-workspace.entity';+import { UsageLimitModule } from 'src/engine/core-modules/usage-limit/usage-limit.module';import { UsageModule } from 'src/engine/core-modules/usage/usage.module';import { WorkspaceCacheStorageModule } from 'src/engine/workspace-cache-storage/workspace-cache-storage.module';import { WorkspaceCacheModule } from 'src/engine/workspace-cache/workspace-cache.module';@@ -22,6 +23,7 @@ import { WorkspaceEventEmitterModule } from 'src/engine/workspace-event-emitter/ThrottlerModule,TwentyConfigModule,TypeOrmModule.forFeature([UserWorkspaceEntity]),+ UsageLimitModule,UsageModule,WorkspaceCacheModule,WorkspaceCacheStorageModule,diff --git a/packages/twenty-server/src/engine/core-modules/billing/app-billing/app-billing.service.ts b/packages/twenty-server/src/engine/core-modules/billing/app-billing/app-billing.service.tsindex a81b2b78e35..fa2a72de562 100644--- a/packages/twenty-server/src/engine/core-modules/billing/app-billing/app-billing.service.ts+++ b/packages/twenty-server/src/engine/core-modules/billing/app-billing/app-billing.service.ts@@ -9,8 +9,8 @@ import { type Repository } from 'typeorm';import { findActiveFlatApplicationById } from 'src/engine/core-modules/application/utils/find-active-flat-application-by-id.util';import { type ChargeDto } from 'src/engine/core-modules/billing/app-billing/dtos/charge.dto';-import { BillingUsageService } from 'src/engine/core-modules/billing/services/billing-usage.service';import { UserWorkspaceEntity } from 'src/engine/core-modules/user-workspace/user-workspace.entity';+import { UsageLimitQuotaService } from 'src/engine/core-modules/usage-limit/services/usage-limit-quota.service';import { UsageOperationType } from 'src/engine/core-modules/usage/enums/usage-operation-type.enum';import { UsageResourceType } from 'src/engine/core-modules/usage/enums/usage-resource-type.enum';import { UsageUnit } from 'src/engine/core-modules/usage/enums/usage-unit.enum';@@ -48,7 +48,7 @@ export class AppBillingService {constructor(private readonly usageRecorderService: UsageRecorderService,- private readonly billingUsageService: BillingUsageService,+ private readonly usageLimitQuotaService: UsageLimitQuotaService,private readonly workspaceCacheService: WorkspaceCacheService,@InjectRepository(UserWorkspaceEntity)private readonly userWorkspaceRepository: Repository<UserWorkspaceEntity>,@@ -83,7 +83,7 @@ export class AppBillingService {applicationId,};- await this.billingUsageService.consumeUsageQuota({+ await this.usageLimitQuotaService.consumeQuota({workspaceId,resourceType: UsageResourceType.APP,operationType,diff --git a/packages/twenty-server/src/engine/core-modules/billing/billing.exception.ts b/packages/twenty-server/src/engine/core-modules/billing/billing.exception.tsindex cd7a51e65d4..dacde47e371 100644--- a/packages/twenty-server/src/engine/core-modules/billing/billing.exception.ts+++ b/packages/twenty-server/src/engine/core-modules/billing/billing.exception.ts@@ -12,28 +12,21 @@ export enum BillingExceptionCode {BILLING_PLAN_NOT_FOUND = 'BILLING_PLAN_NOT_FOUND',BILLING_PRODUCT_NOT_FOUND = 'BILLING_PRODUCT_NOT_FOUND',BILLING_PRICE_NOT_FOUND = 'BILLING_PRICE_NOT_FOUND',- BILLING_METER_NOT_FOUND = 'BILLING_METER_NOT_FOUND',BILLING_SUBSCRIPTION_NOT_FOUND = 'BILLING_SUBSCRIPTION_NOT_FOUND',BILLING_SUBSCRIPTION_ITEM_NOT_FOUND = 'BILLING_SUBSCRIPTION_ITEM_NOT_FOUND',BILLING_SUBSCRIPTION_INVALID = 'BILLING_SUBSCRIPTION_INVALID',BILLING_SUBSCRIPTION_ALREADY_EXISTS = 'BILLING_SUBSCRIPTION_ALREADY_EXISTS',BILLING_SUBSCRIPTION_EVENT_WORKSPACE_NOT_FOUND = 'BILLING_SUBSCRIPTION_EVENT_WORKSPACE_NOT_FOUND',BILLING_CUSTOMER_EVENT_WORKSPACE_NOT_FOUND = 'BILLING_CUSTOMER_EVENT_WORKSPACE_NOT_FOUND',- BILLING_ACTIVE_SUBSCRIPTION_NOT_FOUND = 'BILLING_ACTIVE_SUBSCRIPTION_NOT_FOUND',- BILLING_METER_EVENT_FAILED = 'BILLING_METER_EVENT_FAILED',BILLING_MISSING_REQUEST_BODY = 'BILLING_MISSING_REQUEST_BODY',BILLING_UNHANDLED_ERROR = 'BILLING_UNHANDLED_ERROR',BILLING_STRIPE_ERROR = 'BILLING_STRIPE_ERROR',BILLING_SUBSCRIPTION_NOT_IN_TRIAL_PERIOD = 'BILLING_SUBSCRIPTION_NOT_IN_TRIAL_PERIOD',- BILLING_SUBSCRIPTION_INTERVAL_NOT_SWITCHABLE = 'BILLING_SUBSCRIPTION_INTERVAL_NOT_SWITCHABLE',- BILLING_SUBSCRIPTION_INTERVAL_INVALID = 'BILLING_SUBSCRIPTION_INTERVAL_INVALID',- BILLING_SUBSCRIPTION_PLAN_NOT_SWITCHABLE = 'BILLING_SUBSCRIPTION_PLAN_NOT_SWITCHABLE',BILLING_SUBSCRIPTION_ITEM_INVALID = 'BILLING_SUBSCRIPTION_ITEM_INVALID',BILLING_PRICE_INVALID_TIERS = 'BILLING_PRICE_INVALID_TIERS',BILLING_PRICE_INVALID = 'BILLING_PRICE_INVALID',BILLING_SUBSCRIPTION_PHASE_NOT_FOUND = 'BILLING_SUBSCRIPTION_PHASE_NOT_FOUND',BILLING_TOO_MUCH_SUBSCRIPTIONS_FOUND = 'BILLING_TOO_MUCH_SUBSCRIPTIONS_FOUND',- BILLING_CREDITS_EXHAUSTED = 'BILLING_CREDITS_EXHAUSTED',BILLING_SUBSCRIPTION_INACTIVE = 'BILLING_SUBSCRIPTION_INACTIVE',BILLING_SUBSCRIPTION_NOT_CANCELED = 'BILLING_SUBSCRIPTION_NOT_CANCELED',BILLING_CREDIT_AMOUNT_INVALID = 'BILLING_CREDIT_AMOUNT_INVALID',@@ -55,8 +48,6 @@ const getBillingExceptionUserFriendlyMessage = (code: BillingExceptionCode) => {return msg`Billing product not found.`;case BillingExceptionCode.BILLING_PRICE_NOT_FOUND:return msg`Billing price not found.`;- case BillingExceptionCode.BILLING_METER_NOT_FOUND:- return msg`Billing meter not found.`;case BillingExceptionCode.BILLING_SUBSCRIPTION_NOT_FOUND:return msg`Subscription not found.`;case BillingExceptionCode.BILLING_SUBSCRIPTION_ITEM_NOT_FOUND:@@ -69,10 +60,6 @@ const getBillingExceptionUserFriendlyMessage = (code: BillingExceptionCode) => {return msg`Workspace not found for subscription event.`;case BillingExceptionCode.BILLING_CUSTOMER_EVENT_WORKSPACE_NOT_FOUND:return msg`Workspace not found for customer event.`;- case BillingExceptionCode.BILLING_ACTIVE_SUBSCRIPTION_NOT_FOUND:- return msg`No active subscription found.`;- case BillingExceptionCode.BILLING_METER_EVENT_FAILED:- return msg`Failed to record billing event.`;case BillingExceptionCode.BILLING_MISSING_REQUEST_BODY:return msg`Missing request body.`;case BillingExceptionCode.BILLING_UNHANDLED_ERROR:@@ -81,12 +68,6 @@ const getBillingExceptionUserFriendlyMessage = (code: BillingExceptionCode) => {return msg`A payment processing error occurred.`;case BillingExceptionCode.BILLING_SUBSCRIPTION_NOT_IN_TRIAL_PERIOD:return msg`Subscription is not in trial period.`;- case BillingExceptionCode.BILLING_SUBSCRIPTION_INTERVAL_NOT_SWITCHABLE:- return msg`Cannot switch subscription interval.`;- case BillingExceptionCode.BILLING_SUBSCRIPTION_INTERVAL_INVALID:- return msg`Invalid subscription interval.`;- case BillingExceptionCode.BILLING_SUBSCRIPTION_PLAN_NOT_SWITCHABLE:- return msg`Cannot switch subscription plan.`;case BillingExceptionCode.BILLING_SUBSCRIPTION_ITEM_INVALID:return msg`Invalid subscription item.`;case BillingExceptionCode.BILLING_PRICE_INVALID_TIERS:@@ -97,8 +78,6 @@ const getBillingExceptionUserFriendlyMessage = (code: BillingExceptionCode) => {return msg`Subscription phase not found.`;case BillingExceptionCode.BILLING_TOO_MUCH_SUBSCRIPTIONS_FOUND:return msg`Multiple subscriptions found where one was expected.`;- case BillingExceptionCode.BILLING_CREDITS_EXHAUSTED:- return msg`You have exhausted your credits. Please upgrade your plan to continue.`;case BillingExceptionCode.BILLING_SUBSCRIPTION_INACTIVE:return msg`This workspace has no active subscription.`;case BillingExceptionCode.BILLING_SUBSCRIPTION_NOT_CANCELED:diff --git a/packages/twenty-server/src/engine/core-modules/billing/services/billing-usage.service.ts b/packages/twenty-server/src/engine/core-modules/billing/services/billing-usage.service.tsindex 54801008219..af52351cb44 100644--- a/packages/twenty-server/src/engine/core-modules/billing/services/billing-usage.service.ts+++ b/packages/twenty-server/src/engine/core-modules/billing/services/billing-usage.service.ts@@ -28,7 +28,6 @@ import { buildUsageRefusalException } from 'src/engine/core-modules/billing/utilimport { getBillingSubscriptionPeriod } from 'src/engine/core-modules/billing/utils/get-billing-subscription-period.util';import { TwentyConfigService } from 'src/engine/core-modules/twenty-config/twenty-config.service';import { UsageLimitQuotaService } from 'src/engine/core-modules/usage-limit/services/usage-limit-quota.service';-import { type QuotaCost } from 'src/engine/core-modules/usage-limit/types/quota-cost.type';import { type UsageOperationType } from 'src/engine/core-modules/usage/enums/usage-operation-type.enum';import { type UsageResourceType } from 'src/engine/core-modules/usage/enums/usage-resource-type.enum';import { type UsageSpenders } from 'src/engine/core-modules/usage/types/usage-spenders.type';@@ -96,30 +95,6 @@ export class BillingUsageService {: null;}- async consumeUsageQuota({- workspaceId,- resourceType,- operationType,- spenders,- cost,- }: UsageQuotaScope & { cost: QuotaCost }): Promise<{- hasNoMoreAvailableCredits: boolean;- }> {- const { exhausted } = await this.usageLimitQuotaService.consumeQuota({- workspaceId,- resourceType,- operationType,- spenders,- cost,- });-- const isAllowanceExhausted = exhausted.some(- (scope) => scope.exhaustedKind === 'allowance',- );-- return { hasNoMoreAvailableCredits: isAllowanceExhausted };- }-async getSubscriptionInactiveReason(workspaceId: string,): Promise<SubscriptionInactiveReason | null> {diff --git a/packages/twenty-server/src/engine/core-modules/billing/stripe/constants/stripe-billing-meter-event-name.constant.ts b/packages/twenty-server/src/engine/core-modules/billing/stripe/constants/stripe-billing-meter-event-name.constant.tsdeleted file mode 100644index 69c0f2fe446..00000000000--- a/packages/twenty-server/src/engine/core-modules/billing/stripe/constants/stripe-billing-meter-event-name.constant.ts+++ /dev/null@@ -1 +0,0 @@-export const STRIPE_BILLING_METER_EVENT_NAME = 'WORKFLOW_NODE_RUN';diff --git a/packages/twenty-server/src/engine/core-modules/billing/stripe/services/stripe-billing-meter-event.service.ts b/packages/twenty-server/src/engine/core-modules/billing/stripe/services/stripe-billing-meter-event.service.tsdeleted file mode 100644index d091dff77d8..00000000000--- a/packages/twenty-server/src/engine/core-modules/billing/stripe/services/stripe-billing-meter-event.service.ts+++ /dev/null@@ -1,114 +0,0 @@-/* @license Enterprise */--import { Injectable, Logger } from '@nestjs/common';--import type Stripe from 'stripe';--import { STRIPE_BILLING_METER_EVENT_NAME } from 'src/engine/core-modules/billing/stripe/constants/stripe-billing-meter-event-name.constant';-import { StripeSDKService } from 'src/engine/core-modules/billing/stripe/stripe-sdk/services/stripe-sdk.service';-import { type UsageEvent } from 'src/engine/core-modules/usage/types/usage-event.type';-import { TwentyConfigService } from 'src/engine/core-modules/twenty-config/twenty-config.service';--@Injectable()-export class StripeBillingMeterEventService {- protected readonly logger = new Logger(StripeBillingMeterEventService.name);- private readonly stripe: Stripe;-- constructor(- private readonly twentyConfigService: TwentyConfigService,- private readonly stripeSDKService: StripeSDKService,- ) {- if (!this.twentyConfigService.get('IS_BILLING_ENABLED')) {- return;- }- this.stripe = this.stripeSDKService.getStripe(- this.twentyConfigService.get('BILLING_STRIPE_API_KEY'),- );- }-- async sendBillingMeterEvent({- usageEvent,- stripeCustomerId,- }: {- usageEvent: UsageEvent;- stripeCustomerId: string;- }) {- const payload: Record<string, string> = {- value: usageEvent.creditsUsedMicro.toString(),- stripe_customer_id: stripeCustomerId,- execution_type: usageEvent.operationType.toLowerCase(),- };-- if (usageEvent.resourceId) {- payload.resource_id = usageEvent.resourceId;- }-- if (usageEvent.resourceContext) {- payload.execution_context_1 = usageEvent.resourceContext;- }-- await this.stripe.billing.meterEvents.create({- event_name: STRIPE_BILLING_METER_EVENT_NAME,- payload,- });- }-- async sumMeterEvents(- stripeMeterId: string,- stripeCustomerId: string,- startTime: Date,- endTime: Date,- ) {- const eventSummaries = await this.stripe.billing.meters.listEventSummaries(- stripeMeterId,- {- customer: stripeCustomerId,- start_time: Math.floor(startTime.getTime() / (1000 * 60)) * 60,- end_time: Math.ceil(endTime.getTime() / (1000 * 60)) * 60,- },- );-- return eventSummaries.data.reduce((acc, eventSummary) => {- return acc + eventSummary.aggregated_value;- }, 0);- }-- async getTotalCumulativeUsage(- stripeMeterId: string,- stripeCustomerId: string,- ): Promise<number> {- const startTime = this.getMinimumMeterStartTime();- const endTime = new Date();-- return this.sumMeterEvents(- stripeMeterId,- stripeCustomerId,- startTime,- endTime,- );- }-- async getCumulativeUsageAtTime(- stripeMeterId: string,- stripeCustomerId: string,- atTime: Date,- ): Promise<number> {- const startTime = this.getMinimumMeterStartTime();-- return this.sumMeterEvents(- stripeMeterId,- stripeCustomerId,- startTime,- atTime,- );- }-- /**- * Returns a reasonable minimum start time for meter queries.- * Stripe's billing meters API doesn't accept timestamps from 1970 (epoch).- * Using 2020-01-01 as a safe minimum since Stripe Billing Meters is a recent feature.- */- private getMinimumMeterStartTime(): Date {- return new Date('2020-01-01T00:00:00Z');- }-}diff --git a/packages/twenty-server/src/engine/core-modules/billing/stripe/stripe.module.ts b/packages/twenty-server/src/engine/core-modules/billing/stripe/stripe.module.tsindex 756b74eedf2..1e703ac0c1a 100644--- a/packages/twenty-server/src/engine/core-modules/billing/stripe/stripe.module.ts+++ b/packages/twenty-server/src/engine/core-modules/billing/stripe/stripe.module.ts@@ -3,7 +3,6 @@import { Module } from '@nestjs/common';import { TypeOrmModule } from '@nestjs/typeorm';-import { StripeBillingMeterEventService } from 'src/engine/core-modules/billing/stripe/services/stripe-billing-meter-event.service';import { StripeBillingMeterService } from 'src/engine/core-modules/billing/stripe/services/stripe-billing-meter.service';import { StripeBillingPortalService } from 'src/engine/core-modules/billing/stripe/services/stripe-billing-portal.service';import { StripeCheckoutService } from 'src/engine/core-modules/billing/stripe/services/stripe-checkout.service';@@ -38,7 +37,6 @@ import { provideWorkspaceScopedRepository } from 'src/engine/twenty-orm/workspacStripeEntitlementService,StripePriceService,StripeProductService,- StripeBillingMeterEventService,StripeInvoiceService,provideWorkspaceScopedRepository(BillingCustomerEntity),],@@ -53,7 +51,6 @@ import { provideWorkspaceScopedRepository } from 'src/engine/twenty-orm/workspacStripeSubscriptionItemService,StripeSubscriptionService,StripeProductService,- StripeBillingMeterEventService,StripeSubscriptionScheduleService,StripeInvoiceService,],diff --git a/packages/twenty-server/src/engine/core-modules/billing/utils/__tests__/billing-graphql-api-exception-handler.util.spec.ts b/packages/twenty-server/src/engine/core-modules/billing/utils/__tests__/billing-graphql-api-exception-handler.util.spec.tsindex 7d0b4ca3901..1c9b87f3065 100644--- a/packages/twenty-server/src/engine/core-modules/billing/utils/__tests__/billing-graphql-api-exception-handler.util.spec.ts+++ b/packages/twenty-server/src/engine/core-modules/billing/utils/__tests__/billing-graphql-api-exception-handler.util.spec.ts@@ -20,17 +20,17 @@ const catchGraphqlError = (error: Error): BaseGraphQLError => {};describe('billingGraphqlApiExceptionHandler', () => {- it('maps credits exhausted to a GraphQL error with the billing subCode', () => {+ it('maps an inactive subscription to a GraphQL error with the billing subCode', () => {const error = new BillingException(- 'Credits exhausted',- BillingExceptionCode.BILLING_CREDITS_EXHAUSTED,+ 'No active subscription',+ BillingExceptionCode.BILLING_SUBSCRIPTION_INACTIVE,);const graphqlError = catchGraphqlError(error);expect(graphqlError.extensions.code).toBe(ErrorCode.FORBIDDEN);expect(graphqlError.extensions.subCode).toBe(- BillingExceptionCode.BILLING_CREDITS_EXHAUSTED,+ BillingExceptionCode.BILLING_SUBSCRIPTION_INACTIVE,);expect(graphqlError.extensions.userFriendlyMessage).toBeDefined();});diff --git a/packages/twenty-server/src/engine/core-modules/billing/utils/__tests__/is-usage-refused-error.util.spec.ts b/packages/twenty-server/src/engine/core-modules/billing/utils/__tests__/is-usage-refused-error.util.spec.tsindex 11f8ceeeeba..6d89479d722 100644--- a/packages/twenty-server/src/engine/core-modules/billing/utils/__tests__/is-usage-refused-error.util.spec.ts+++ b/packages/twenty-server/src/engine/core-modules/billing/utils/__tests__/is-usage-refused-error.util.spec.ts@@ -11,17 +11,6 @@ import {} from 'src/engine/core-modules/usage-limit/exceptions/usage-limit.exception';describe('isUsageRefusedError', () => {- it('recognizes an exhausted credit allowance', () => {- expect(- isUsageRefusedError(- new BillingException(- 'Credits exhausted',- BillingExceptionCode.BILLING_CREDITS_EXHAUSTED,- ),- ),- ).toBe(true);- });-it('recognizes an exhausted quota', () => {expect(isUsageRefusedError(diff --git a/packages/twenty-server/src/engine/core-modules/billing/utils/get-billing-exception-status-code.util.ts b/packages/twenty-server/src/engine/core-modules/billing/utils/get-billing-exception-status-code.util.tsindex a3bb7e7636b..339462cc770 100644--- a/packages/twenty-server/src/engine/core-modules/billing/utils/get-billing-exception-status-code.util.ts+++ b/packages/twenty-server/src/engine/core-modules/billing/utils/get-billing-exception-status-code.util.ts@@ -12,25 +12,19 @@ export const getBillingExceptionStatusCode = (): 400 | 402 | 404 | 500 => {switch (exception.code) {case BillingExceptionCode.BILLING_CUSTOMER_NOT_FOUND:- case BillingExceptionCode.BILLING_ACTIVE_SUBSCRIPTION_NOT_FOUND:case BillingExceptionCode.BILLING_PRODUCT_NOT_FOUND:case BillingExceptionCode.BILLING_PLAN_NOT_FOUND:- case BillingExceptionCode.BILLING_METER_NOT_FOUND:case BillingExceptionCode.BILLING_SUBSCRIPTION_ITEM_NOT_FOUND:case BillingExceptionCode.BILLING_SUBSCRIPTION_NOT_FOUND:case BillingExceptionCode.BILLING_CREDIT_GRANT_NOT_FOUND:return 404;- case BillingExceptionCode.BILLING_METER_EVENT_FAILED:case BillingExceptionCode.BILLING_SUBSCRIPTION_NOT_IN_TRIAL_PERIOD:- case BillingExceptionCode.BILLING_SUBSCRIPTION_INTERVAL_NOT_SWITCHABLE:- case BillingExceptionCode.BILLING_SUBSCRIPTION_PLAN_NOT_SWITCHABLE:case BillingExceptionCode.BILLING_MISSING_REQUEST_BODY:case BillingExceptionCode.BILLING_CREDIT_AMOUNT_INVALID:case BillingExceptionCode.BILLING_CREDIT_GRANT_VALIDITY_INVALID:case BillingExceptionCode.BILLING_CREDIT_GRANT_TYPE_NOT_GRANTABLE:case BillingExceptionCode.BILLING_SUBSCRIPTION_ALREADY_EXISTS:return 400;- case BillingExceptionCode.BILLING_CREDITS_EXHAUSTED:case BillingExceptionCode.BILLING_SUBSCRIPTION_INACTIVE:case BillingExceptionCode.BILLING_UPGRADE_INVOICE_PAYMENT_FAILED:return 402;@@ -40,7 +34,6 @@ export const getBillingExceptionStatusCode = (case BillingExceptionCode.BILLING_SUBSCRIPTION_EVENT_WORKSPACE_NOT_FOUND:case BillingExceptionCode.BILLING_UNHANDLED_ERROR:case BillingExceptionCode.BILLING_STRIPE_ERROR:- case BillingExceptionCode.BILLING_SUBSCRIPTION_INTERVAL_INVALID:case BillingExceptionCode.BILLING_SUBSCRIPTION_ITEM_INVALID:case BillingExceptionCode.BILLING_PRICE_INVALID_TIERS:case BillingExceptionCode.BILLING_PRICE_INVALID:diff --git a/packages/twenty-server/src/engine/core-modules/billing/utils/is-usage-refused-error.util.ts b/packages/twenty-server/src/engine/core-modules/billing/utils/is-usage-refused-error.util.tsindex 11d67e6190b..67a7740daa5 100644--- a/packages/twenty-server/src/engine/core-modules/billing/utils/is-usage-refused-error.util.ts+++ b/packages/twenty-server/src/engine/core-modules/billing/utils/is-usage-refused-error.util.ts@@ -10,7 +10,6 @@ import {} from 'src/engine/core-modules/usage-limit/exceptions/usage-limit.exception';const BILLING_REFUSAL_EXCEPTION_CODES = [- BillingExceptionCode.BILLING_CREDITS_EXHAUSTED,BillingExceptionCode.BILLING_SUBSCRIPTION_INACTIVE,];diff --git a/packages/twenty-server/src/engine/core-modules/logic-function/logic-function-executor/logic-function-executor.module.ts b/packages/twenty-server/src/engine/core-modules/logic-function/logic-function-executor/logic-function-executor.module.tsindex 37105cf5727..fe97c6617a1 100644--- a/packages/twenty-server/src/engine/core-modules/logic-function/logic-function-executor/logic-function-executor.module.ts+++ b/packages/twenty-server/src/engine/core-modules/logic-function/logic-function-executor/logic-function-executor.module.ts@@ -13,6 +13,7 @@ import { FeatureFlagModule } from 'src/engine/core-modules/feature-flag/feature-import { LogicFunctionExecutorService } from 'src/engine/core-modules/logic-function/logic-function-executor/logic-function-executor.service';import { SecretEncryptionModule } from 'src/engine/core-modules/secret-encryption/secret-encryption.module';import { ThrottlerModule } from 'src/engine/core-modules/throttler/throttler.module';+import { UsageLimitModule } from 'src/engine/core-modules/usage-limit/usage-limit.module';import { UsageModule } from 'src/engine/core-modules/usage/usage.module';import { WorkspaceEntity } from 'src/engine/core-modules/workspace/workspace.entity';import { SubscriptionsModule } from 'src/engine/subscriptions/subscriptions.module';@@ -34,6 +35,7 @@ import { WorkspaceCacheModule } from 'src/engine/workspace-cache/workspace-cacheWorkspaceDomainsModule,ApplicationModule,ApplicationVariableEntityModule,+ UsageLimitModule,UsageModule,TypeOrmModule.forFeature([ApplicationRegistrationVariableEntity,diff --git a/packages/twenty-server/src/engine/core-modules/logic-function/logic-function-executor/logic-function-executor.service.ts b/packages/twenty-server/src/engine/core-modules/logic-function/logic-function-executor/logic-function-executor.service.tsindex d24a4bdd214..333808b5afa 100644--- a/packages/twenty-server/src/engine/core-modules/logic-function/logic-function-executor/logic-function-executor.service.ts+++ b/packages/twenty-server/src/engine/core-modules/logic-function/logic-function-executor/logic-function-executor.service.ts@@ -34,6 +34,7 @@ import { ApplicationService } from 'src/engine/core-modules/application/applicatimport { FlatApplication } from 'src/engine/core-modules/application/types/flat-application.type';import { ApplicationTokenService } from 'src/engine/core-modules/auth/token/services/application-token.service';import { BillingUsageService } from 'src/engine/core-modules/billing/services/billing-usage.service';+import { UsageLimitQuotaService } from 'src/engine/core-modules/usage-limit/services/usage-limit-quota.service';import { WorkspaceDomainsService } from 'src/engine/core-modules/domain/workspace-domains/services/workspace-domains.service';import { EventLogEmitterService } from 'src/engine/core-modules/event-logs/emit/event-log-emitter.service';import { LOGIC_FUNCTION_EXECUTED_EVENT } from 'src/engine/core-modules/event-logs/emit/events/workspace-event/logic-function/logic-function-executed';@@ -114,6 +115,7 @@ export class LogicFunctionExecutorService {private readonly eventLogEmitterService: EventLogEmitterService,private readonly usageRecorderService: UsageRecorderService,private readonly billingUsageService: BillingUsageService,+ private readonly usageLimitQuotaService: UsageLimitQuotaService,private readonly featureFlagService: FeatureFlagService,private readonly workspaceDomainsService: WorkspaceDomainsService,private readonly applicationService: ApplicationService,@@ -670,7 +672,7 @@ export class LogicFunctionExecutorService {};if (totalCreditsMicro > 0) {- await this.billingUsageService.consumeUsageQuota({+ await this.usageLimitQuotaService.consumeQuota({workspaceId,resourceType: UsageResourceType.LOGIC_FUNCTION,operationType: UsageOperationType.CODE_EXECUTION,diff --git a/packages/twenty-server/src/engine/metadata-modules/ai/ai-billing/ai-billing.module.ts b/packages/twenty-server/src/engine/metadata-modules/ai/ai-billing/ai-billing.module.tsindex 69c75fbf3f6..d00efdd0908 100644--- a/packages/twenty-server/src/engine/metadata-modules/ai/ai-billing/ai-billing.module.ts+++ b/packages/twenty-server/src/engine/metadata-modules/ai/ai-billing/ai-billing.module.ts@@ -1,12 +1,13 @@import { Module } from '@nestjs/common';import { BillingModule } from 'src/engine/core-modules/billing/billing.module';+import { UsageLimitModule } from 'src/engine/core-modules/usage-limit/usage-limit.module';import { UsageModule } from 'src/engine/core-modules/usage/usage.module';import { AiBillingService } from 'src/engine/metadata-modules/ai/ai-billing/services/ai-billing.service';import { AiModelsModule } from 'src/engine/metadata-modules/ai/ai-models/ai-models.module';@Module({- imports: [AiModelsModule, BillingModule, UsageModule],+ imports: [AiModelsModule, BillingModule, UsageLimitModule, UsageModule],providers: [AiBillingService],exports: [AiBillingService],})diff --git a/packages/twenty-server/src/engine/metadata-modules/ai/ai-billing/services/ai-billing.service.ts b/packages/twenty-server/src/engine/metadata-modules/ai/ai-billing/services/ai-billing.service.tsindex fb88fcb29dc..5a101505d23 100644--- a/packages/twenty-server/src/engine/metadata-modules/ai/ai-billing/services/ai-billing.service.ts+++ b/packages/twenty-server/src/engine/metadata-modules/ai/ai-billing/services/ai-billing.service.ts@@ -1,6 +1,7 @@import { Injectable, Logger } from '@nestjs/common';import { BillingUsageService } from 'src/engine/core-modules/billing/services/billing-usage.service';+import { UsageLimitQuotaService } from 'src/engine/core-modules/usage-limit/services/usage-limit-quota.service';import { type QuotaCost } from 'src/engine/core-modules/usage-limit/types/quota-cost.type';import { UsageOperationType } from 'src/engine/core-modules/usage/enums/usage-operation-type.enum';import { UsageResourceType } from 'src/engine/core-modules/usage/enums/usage-resource-type.enum';@@ -28,6 +29,7 @@ export class AiBillingService {private readonly usageRecorderService: UsageRecorderService,private readonly aiModelRegistryService: AiModelRegistryService,private readonly billingUsageService: BillingUsageService,+ private readonly usageLimitQuotaService: UsageLimitQuotaService,) {}async assertAiExecutionAllowed({@@ -58,13 +60,19 @@ export class AiBillingService {spenders: UsageSpenders;cost: QuotaCost;}): Promise<{ hasNoMoreAvailableCredits: boolean }> {- return this.billingUsageService.consumeUsageQuota({+ const { exhausted } = await this.usageLimitQuotaService.consumeQuota({workspaceId,resourceType: UsageResourceType.AI,operationType,spenders,cost,});++ return {+ hasNoMoreAvailableCredits: exhausted.some(+ (scope) => scope.exhaustedKind === 'allowance',+ ),+ };}// Evaluation models are looked up first: they price like a language modeldiff --git a/packages/twenty-server/src/engine/metadata-modules/ai/utils/__tests__/ai-graphql-api-exception-handler.util.spec.ts b/packages/twenty-server/src/engine/metadata-modules/ai/utils/__tests__/ai-graphql-api-exception-handler.util.spec.tsindex 7498e89e770..47e0c73bd19 100644--- a/packages/twenty-server/src/engine/metadata-modules/ai/utils/__tests__/ai-graphql-api-exception-handler.util.spec.ts+++ b/packages/twenty-server/src/engine/metadata-modules/ai/utils/__tests__/ai-graphql-api-exception-handler.util.spec.ts@@ -39,8 +39,8 @@ describe('aiGraphqlApiExceptionHandler', () => {it('leaves billing exceptions to the billing filter', () => {const exception = new BillingException(- 'Credits exhausted',- BillingExceptionCode.BILLING_CREDITS_EXHAUSTED,+ 'No active subscription',+ BillingExceptionCode.BILLING_SUBSCRIPTION_INACTIVE,);expect(() => aiGraphqlApiExceptionHandler(exception)).toThrow(exception);diff --git a/packages/twenty-server/src/modules/emailing/services/email-billing.service.ts b/packages/twenty-server/src/modules/emailing/services/email-billing.service.tsindex 4fef30095e5..50c7d7f3937 100644--- a/packages/twenty-server/src/modules/emailing/services/email-billing.service.ts+++ b/packages/twenty-server/src/modules/emailing/services/email-billing.service.ts@@ -2,6 +2,7 @@ import { Injectable } from '@nestjs/common';import { BillingUsageService } from 'src/engine/core-modules/billing/services/billing-usage.service';import { type UsageRefusal } from 'src/engine/core-modules/billing/types/usage-refusal.type';+import { UsageLimitQuotaService } from 'src/engine/core-modules/usage-limit/services/usage-limit-quota.service';import { UsageOperationType } from 'src/engine/core-modules/usage/enums/usage-operation-type.enum';import { UsageResourceType } from 'src/engine/core-modules/usage/enums/usage-resource-type.enum';import { UsageUnit } from 'src/engine/core-modules/usage/enums/usage-unit.enum';@@ -19,6 +20,7 @@ export class EmailBillingService {constructor(private readonly usageRecorderService: UsageRecorderService,private readonly billingUsageService: BillingUsageService,+ private readonly usageLimitQuotaService: UsageLimitQuotaService,) {}async validateEmailSendOrThrow({@@ -56,7 +58,7 @@ export class EmailBillingService {const creditsUsedMicro = computeEmailCreditsUsedMicro(sentEmailCount);- await this.billingUsageService.consumeUsageQuota({+ await this.usageLimitQuotaService.consumeQuota({workspaceId,resourceType: UsageResourceType.EMAIL,operationType: UsageOperationType.EMAIL_SEND,diff --git a/packages/twenty-server/src/modules/workflow/workflow-executor/utils/__tests__/is-user-facing-workflow-executor-error.util.spec.ts b/packages/twenty-server/src/modules/workflow/workflow-executor/utils/__tests__/is-user-facing-workflow-executor-error.util.spec.tsindex 58279aa0c46..b9c4c0ef720 100644--- a/packages/twenty-server/src/modules/workflow/workflow-executor/utils/__tests__/is-user-facing-workflow-executor-error.util.spec.ts+++ b/packages/twenty-server/src/modules/workflow/workflow-executor/utils/__tests__/is-user-facing-workflow-executor-error.util.spec.ts@@ -17,15 +17,6 @@ import {import { isUserFacingWorkflowExecutorError } from 'src/modules/workflow/workflow-executor/utils/is-user-facing-workflow-executor-error.util';describe('isUserFacingWorkflowExecutorError', () => {- it('returns true for exhausted billing credits', () => {- const error = new BillingException(- 'Credits exhausted',- BillingExceptionCode.BILLING_CREDITS_EXHAUSTED,- );-- expect(isUserFacingWorkflowExecutorError(error)).toBe(true);- });-it('returns true for an inactive subscription', () => {const error = new BillingException('No active subscription',diff --git a/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-executor.module.ts b/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-executor.module.tsindex 1257e7600db..ec241f4ddef 100644--- a/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-executor.module.ts+++ b/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-executor.module.ts@@ -5,6 +5,7 @@ import { BillingModule } from 'src/engine/core-modules/billing/billing.module';import { WorkspaceCacheModule } from 'src/engine/workspace-cache/workspace-cache.module';import { FeatureFlagModule } from 'src/engine/core-modules/feature-flag/feature-flag.module';import { MetricsModule } from 'src/engine/core-modules/metrics/metrics.module';+import { UsageLimitModule } from 'src/engine/core-modules/usage-limit/usage-limit.module';import { UsageModule } from 'src/engine/core-modules/usage/usage.module';import { WorkflowCommonModule } from 'src/modules/workflow/common/workflow-common.module';import { WorkflowActionFactory } from 'src/modules/workflow/workflow-executor/factories/workflow-action.factory';@@ -48,6 +49,7 @@ import { WorkflowRunModule } from 'src/modules/workflow/workflow-runner/workflowMailSenderActionModule,CreateCalendarEventActionModule,MetricsModule,+ UsageLimitModule,UsageModule,],providers: [WorkflowExecutorWorkspaceService, WorkflowActionFactory],diff --git a/packages/twenty-server/src/modules/workflow/workflow-executor/workspace-services/workflow-executor.workspace-service.ts b/packages/twenty-server/src/modules/workflow/workflow-executor/workspace-services/workflow-executor.workspace-service.tsindex 7bb4d79c484..3207c571dd6 100644--- a/packages/twenty-server/src/modules/workflow/workflow-executor/workspace-services/workflow-executor.workspace-service.ts+++ b/packages/twenty-server/src/modules/workflow/workflow-executor/workspace-services/workflow-executor.workspace-service.ts@@ -11,6 +11,7 @@ import {} from 'twenty-shared/workflow';import { BillingUsageService } from 'src/engine/core-modules/billing/services/billing-usage.service';+import { UsageLimitQuotaService } from 'src/engine/core-modules/usage-limit/services/usage-limit-quota.service';import { isUsageRefusedError } from 'src/engine/core-modules/billing/utils/is-usage-refused-error.util';import { ExceptionHandlerService } from 'src/engine/core-modules/exception-handler/exception-handler.service';import { FeatureFlagService } from 'src/engine/core-modules/feature-flag/services/feature-flag.service';@@ -68,6 +69,7 @@ export class WorkflowExecutorWorkspaceService {private readonly usageRecorderService: UsageRecorderService,private readonly workflowRunWorkspaceService: WorkflowRunWorkspaceService,private readonly billingUsageService: BillingUsageService,+ private readonly usageLimitQuotaService: UsageLimitQuotaService,private readonly featureFlagService: FeatureFlagService,private readonly exceptionHandlerService: ExceptionHandlerService,private readonly metricsService: MetricsService,@@ -411,7 +413,7 @@ export class WorkflowExecutorWorkspaceService {workspaceId: string,billingSpenders: WorkflowBillingSpenders,) {- await this.billingUsageService.consumeUsageQuota({+ await this.usageLimitQuotaService.consumeQuota({workspaceId,resourceType: UsageResourceType.WORKFLOW,operationType: UsageOperationType.WORKFLOW_EXECUTION,diff --git a/packages/twenty-server/test/integration/graphql/suites/workflow/core-workflow-execution.integration-spec.ts b/packages/twenty-server/test/integration/graphql/suites/workflow/core-workflow-execution.integration-spec.tsindex 65be6da6beb..6812fdfbda2 100644--- a/packages/twenty-server/test/integration/graphql/suites/workflow/core-workflow-execution.integration-spec.ts+++ b/packages/twenty-server/test/integration/graphql/suites/workflow/core-workflow-execution.integration-spec.ts@@ -355,8 +355,8 @@ describe('core workflow execution and queue compatibility (e2e)', () => {async (mirrorless) => {const fixture = await createFixture({ mirrorless });const consume = jest.spyOn(- global.workflowTestServices.billing,- 'consumeUsageQuota',+ global.workflowTestServices.quota,+ 'consumeQuota',);await waitForRun(await runFixture(fixture), 'COMPLETED');diff --git a/packages/twenty-server/test/integration/utils/create-workflow-test-services.ts b/packages/twenty-server/test/integration/utils/create-workflow-test-services.tsindex b1e39d9fd6c..3053cc69693 100644--- a/packages/twenty-server/test/integration/utils/create-workflow-test-services.ts+++ b/packages/twenty-server/test/integration/utils/create-workflow-test-services.ts@@ -8,6 +8,7 @@ import { FeatureFlagService } from 'src/engine/core-modules/feature-flag/serviceimport { type INestApplication } from '@nestjs/common';import { BillingUsageService } from 'src/engine/core-modules/billing/services/billing-usage.service';+import { UsageLimitQuotaService } from 'src/engine/core-modules/usage-limit/services/usage-limit-quota.service';import { WorkspaceCacheService } from 'src/engine/workspace-cache/services/workspace-cache.service';import { BackfillWorkflowExecutionCoreIdsCommand } from 'src/database/commands/upgrade-version-command/2-42/2-42-workspace-command-1789719131001-backfill-workflow-execution-core-ids.command';import { WorkflowTriggerJob } from 'src/modules/workflow/workflow-trigger/jobs/workflow-trigger.job';@@ -18,6 +19,7 @@ import { UpgradeAwareRepositoryState } from 'src/engine/twenty-orm/upgrade-awareexport const createWorkflowTestServices = (app: INestApplication) => ({billing: app.get(BillingUsageService),+ quota: app.get(UsageLimitQuotaService),coreDataSource: app.get<DataSource>(getDataSourceToken()),workspace: app.get(WorkspaceService),application: app.get(ApplicationService),