Skip to content

The open alternative to Salesforce, designed for AI.

Cache billing entitlements in the workspace cache (#26078)

Weiko5cceab71e6f1
diff --git a/packages/twenty-client-sdk/src/metadata/generated/schema.graphql b/packages/twenty-client-sdk/src/metadata/generated/schema.graphql
index 684b838bd32..3c08da44693 100644
--- a/packages/twenty-client-sdk/src/metadata/generated/schema.graphql
+++ b/packages/twenty-client-sdk/src/metadata/generated/schema.graphql
@@ -954,6 +954,128 @@ type ApplicationRegistration {
galleryImagesUrls: [String!]!
}
+type BillingSubscriptionSchedulePhaseItem {
+ price: String!
+ quantity: Float
+}
+
+type BillingSubscriptionSchedulePhase {
+ start_date: Float!
+ end_date: Float!
+ items: [BillingSubscriptionSchedulePhaseItem!]!
+}
+
+type BillingProductMetadata {
+ planKey: BillingPlanKey!
+ priceUsageBased: BillingUsageType!
+ productKey: BillingProductKey!
+ isLegacy: String
+}
+
+"""The different billing plans available"""
+enum BillingPlanKey {
+ PRO
+ ENTERPRISE
+}
+
+enum BillingUsageType {
+ METERED
+ LICENSED
+}
+
+"""The different billing products available"""
+enum BillingProductKey {
+ BASE_PRODUCT
+ RESOURCE_CREDIT
+}
+
+type BillingPriceLicensed {
+ recurringInterval: SubscriptionInterval!
+ unitAmount: Float!
+ stripePriceId: String!
+ priceUsageType: BillingUsageType!
+ creditAmount: Float
+ isSellable: Boolean!
+}
+
+enum SubscriptionInterval {
+ Month
+ Year
+}
+
+type BillingPriceTier {
+ upTo: Float
+ flatAmount: Float
+ unitAmount: Float
+}
+
+type BillingPriceMetered {
+ tiers: [BillingPriceTier!]!
+ recurringInterval: SubscriptionInterval!
+ stripePriceId: String!
+ priceUsageType: BillingUsageType!
+}
+
+type BillingProduct {
+ name: String!
+ description: String!
+ images: [String!]
+ metadata: BillingProductMetadata!
+}
+
+type BillingLicensedProduct implements BillingProductDTO {
+ name: String!
+ description: String!
+ images: [String!]
+ metadata: BillingProductMetadata!
+ prices: [BillingPriceLicensed!]
+}
+
+type BillingMeteredProduct implements BillingProductDTO {
+ name: String!
+ description: String!
+ images: [String!]
+ metadata: BillingProductMetadata!
+ prices: [BillingPriceMetered!]
+}
+
+type BillingSubscriptionItem {
+ id: UUID!
+ hasReachedCurrentPeriodCap: Boolean!
+ quantity: Float
+ stripePriceId: String!
+ unitAmount: Float
+ creditAmount: Float
+ billingProduct: BillingProductDTO!
+}
+
+type BillingSubscription {
+ id: UUID!
+ status: SubscriptionStatus!
+ interval: SubscriptionInterval
+ billingSubscriptionItems: [BillingSubscriptionItem!]
+ currentPeriodEnd: DateTime
+ metadata: JSON!
+ phases: [BillingSubscriptionSchedulePhase!]!
+ cancelAt: DateTime
+}
+
+enum SubscriptionStatus {
+ Active
+ Canceled
+ Incomplete
+ IncompleteExpired
+ PastDue
+ Paused
+ Trialing
+ Unpaid
+}
+
+type BillingCustomer {
+ id: UUID!
+ hasPaymentMethod: Boolean
+}
+
type SdkClientChecksums {
core: String
metadata: String!
@@ -1414,128 +1536,6 @@ type ApplicationConnectionProvider {
logoUrl: String
}
-type BillingSubscriptionSchedulePhaseItem {
- price: String!
- quantity: Float
-}
-
-type BillingSubscriptionSchedulePhase {
- start_date: Float!
- end_date: Float!
- items: [BillingSubscriptionSchedulePhaseItem!]!
-}
-
-type BillingProductMetadata {
- planKey: BillingPlanKey!
- priceUsageBased: BillingUsageType!
- productKey: BillingProductKey!
- isLegacy: String
-}
-
-"""The different billing plans available"""
-enum BillingPlanKey {
- PRO
- ENTERPRISE
-}
-
-enum BillingUsageType {
- METERED
- LICENSED
-}
-
-"""The different billing products available"""
-enum BillingProductKey {
- BASE_PRODUCT
- RESOURCE_CREDIT
-}
-
-type BillingPriceLicensed {
- recurringInterval: SubscriptionInterval!
- unitAmount: Float!
- stripePriceId: String!
- priceUsageType: BillingUsageType!
- creditAmount: Float
- isSellable: Boolean!
-}
-
-enum SubscriptionInterval {
- Month
- Year
-}
-
-type BillingPriceTier {
- upTo: Float
- flatAmount: Float
- unitAmount: Float
-}
-
-type BillingPriceMetered {
- tiers: [BillingPriceTier!]!
- recurringInterval: SubscriptionInterval!
- stripePriceId: String!
- priceUsageType: BillingUsageType!
-}
-
-type BillingProduct {
- name: String!
- description: String!
- images: [String!]
- metadata: BillingProductMetadata!
-}
-
-type BillingLicensedProduct implements BillingProductDTO {
- name: String!
- description: String!
- images: [String!]
- metadata: BillingProductMetadata!
- prices: [BillingPriceLicensed!]
-}
-
-type BillingMeteredProduct implements BillingProductDTO {
- name: String!
- description: String!
- images: [String!]
- metadata: BillingProductMetadata!
- prices: [BillingPriceMetered!]
-}
-
-type BillingSubscriptionItem {
- id: UUID!
- hasReachedCurrentPeriodCap: Boolean!
- quantity: Float
- stripePriceId: String!
- unitAmount: Float
- creditAmount: Float
- billingProduct: BillingProductDTO!
-}
-
-type BillingCustomer {
- id: UUID!
- hasPaymentMethod: Boolean
-}
-
-type BillingSubscription {
- id: UUID!
- status: SubscriptionStatus!
- interval: SubscriptionInterval
- billingSubscriptionItems: [BillingSubscriptionItem!]
- currentPeriodEnd: DateTime
- metadata: JSON!
- phases: [BillingSubscriptionSchedulePhase!]!
- cancelAt: DateTime
-}
-
-enum SubscriptionStatus {
- Active
- Canceled
- Incomplete
- IncompleteExpired
- PastDue
- Paused
- Trialing
- Unpaid
-}
-
type LogicFunctionExecutionResult {
"""Execution result in JSON format"""
data: JSON
diff --git a/packages/twenty-client-sdk/src/metadata/generated/schema.ts b/packages/twenty-client-sdk/src/metadata/generated/schema.ts
index 372c1948a1d..2a5b77b08b6 100644
--- a/packages/twenty-client-sdk/src/metadata/generated/schema.ts
+++ b/packages/twenty-client-sdk/src/metadata/generated/schema.ts
@@ -670,6 +670,121 @@ export interface ApplicationRegistration {
__typename: 'ApplicationRegistration'
}
+export interface BillingSubscriptionSchedulePhaseItem {
+ price: Scalars['String']
+ quantity?: Scalars['Float']
+ __typename: 'BillingSubscriptionSchedulePhaseItem'
+}
+
+export interface BillingSubscriptionSchedulePhase {
+ start_date: Scalars['Float']
+ end_date: Scalars['Float']
+ items: BillingSubscriptionSchedulePhaseItem[]
+ __typename: 'BillingSubscriptionSchedulePhase'
+}
+
+export interface BillingProductMetadata {
+ planKey: BillingPlanKey
+ priceUsageBased: BillingUsageType
+ productKey: BillingProductKey
+ isLegacy?: Scalars['String']
+ __typename: 'BillingProductMetadata'
+}
+
+
+/** The different billing plans available */
+export type BillingPlanKey = 'PRO' | 'ENTERPRISE'
+
+export type BillingUsageType = 'METERED' | 'LICENSED'
+
+
+/** The different billing products available */
+export type BillingProductKey = 'BASE_PRODUCT' | 'RESOURCE_CREDIT'
+
+export interface BillingPriceLicensed {
+ recurringInterval: SubscriptionInterval
+ unitAmount: Scalars['Float']
+ stripePriceId: Scalars['String']
+ priceUsageType: BillingUsageType
+ creditAmount?: Scalars['Float']
+ isSellable: Scalars['Boolean']
+ __typename: 'BillingPriceLicensed'
+}
+
+export type SubscriptionInterval = 'Month' | 'Year'
+
+export interface BillingPriceTier {
+ upTo?: Scalars['Float']
+ flatAmount?: Scalars['Float']
+ unitAmount?: Scalars['Float']
+ __typename: 'BillingPriceTier'
+}
+
+export interface BillingPriceMetered {
+ tiers: BillingPriceTier[]
+ recurringInterval: SubscriptionInterval
+ stripePriceId: Scalars['String']
+ priceUsageType: BillingUsageType
+ __typename: 'BillingPriceMetered'
+}
+
+export interface BillingProduct {
+ name: Scalars['String']
+ description: Scalars['String']
+ images?: Scalars['String'][]
+ metadata: BillingProductMetadata
+ __typename: 'BillingProduct'
+}
+
+export interface BillingLicensedProduct {
+ name: Scalars['String']
+ description: Scalars['String']
+ images?: Scalars['String'][]
+ metadata: BillingProductMetadata
+ prices?: BillingPriceLicensed[]
+ __typename: 'BillingLicensedProduct'
+}
+
+export interface BillingMeteredProduct {
+ name: Scalars['String']
+ description: Scalars['String']
+ images?: Scalars['String'][]
+ metadata: BillingProductMetadata
+ prices?: BillingPriceMetered[]
+ __typename: 'BillingMeteredProduct'
+}
+
+export interface BillingSubscriptionItem {
+ id: Scalars['UUID']
+ hasReachedCurrentPeriodCap: Scalars['Boolean']
+ quantity?: Scalars['Float']
+ stripePriceId: Scalars['String']
+ unitAmount?: Scalars['Float']
+ creditAmount?: Scalars['Float']
+ billingProduct: BillingProductDTO
+ __typename: 'BillingSubscriptionItem'
+}
+
+export interface BillingSubscription {
+ id: Scalars['UUID']
+ status: SubscriptionStatus
+ interval?: SubscriptionInterval
+ billingSubscriptionItems?: BillingSubscriptionItem[]
+ currentPeriodEnd?: Scalars['DateTime']
+ metadata: Scalars['JSON']
+ phases: BillingSubscriptionSchedulePhase[]
+ cancelAt?: Scalars['DateTime']
+ __typename: 'BillingSubscription'
+}
+
+export type SubscriptionStatus = 'Active' | 'Canceled' | 'Incomplete' | 'IncompleteExpired' | 'PastDue' | 'Paused' | 'Trialing' | 'Unpaid'
+
+export interface BillingCustomer {
+ id: Scalars['UUID']
+ hasPaymentMethod?: Scalars['Boolean']
+ __typename: 'BillingCustomer'
+}
+
export interface SdkClientChecksums {
core?: Scalars['String']
metadata: Scalars['String']
@@ -1073,121 +1188,6 @@ export interface ApplicationConnectionProvider {
__typename: 'ApplicationConnectionProvider'
}
-export interface BillingSubscriptionSchedulePhaseItem {
- price: Scalars['String']
- quantity?: Scalars['Float']
- __typename: 'BillingSubscriptionSchedulePhaseItem'
-}
-
-export interface BillingSubscriptionSchedulePhase {
- start_date: Scalars['Float']
- end_date: Scalars['Float']
- items: BillingSubscriptionSchedulePhaseItem[]
- __typename: 'BillingSubscriptionSchedulePhase'
-}
-
-export interface BillingProductMetadata {
- planKey: BillingPlanKey
- priceUsageBased: BillingUsageType
- productKey: BillingProductKey
- isLegacy?: Scalars['String']
- __typename: 'BillingProductMetadata'
-}
-
-
-/** The different billing plans available */
-export type BillingPlanKey = 'PRO' | 'ENTERPRISE'
-
-export type BillingUsageType = 'METERED' | 'LICENSED'
-
-
-/** The different billing products available */
-export type BillingProductKey = 'BASE_PRODUCT' | 'RESOURCE_CREDIT'
-
-export interface BillingPriceLicensed {
- recurringInterval: SubscriptionInterval
- unitAmount: Scalars['Float']
- stripePriceId: Scalars['String']
- priceUsageType: BillingUsageType
- creditAmount?: Scalars['Float']
- isSellable: Scalars['Boolean']
- __typename: 'BillingPriceLicensed'
-}
-
-export type SubscriptionInterval = 'Month' | 'Year'
-
-export interface BillingPriceTier {
- upTo?: Scalars['Float']
- flatAmount?: Scalars['Float']
- unitAmount?: Scalars['Float']
- __typename: 'BillingPriceTier'
-}
-
-export interface BillingPriceMetered {
- tiers: BillingPriceTier[]
- recurringInterval: SubscriptionInterval
- stripePriceId: Scalars['String']
- priceUsageType: BillingUsageType
- __typename: 'BillingPriceMetered'
-}
-
-export interface BillingProduct {
- name: Scalars['String']
- description: Scalars['String']
- images?: Scalars['String'][]
- metadata: BillingProductMetadata
- __typename: 'BillingProduct'
-}
-
-export interface BillingLicensedProduct {
- name: Scalars['String']
- description: Scalars['String']
- images?: Scalars['String'][]
- metadata: BillingProductMetadata
- prices?: BillingPriceLicensed[]
- __typename: 'BillingLicensedProduct'
-}
-
-export interface BillingMeteredProduct {
- name: Scalars['String']
- description: Scalars['String']
- images?: Scalars['String'][]
- metadata: BillingProductMetadata
- prices?: BillingPriceMetered[]
- __typename: 'BillingMeteredProduct'
-}
-
-export interface BillingSubscriptionItem {
- id: Scalars['UUID']
- hasReachedCurrentPeriodCap: Scalars['Boolean']
- quantity?: Scalars['Float']
- stripePriceId: Scalars['String']
- unitAmount?: Scalars['Float']
- creditAmount?: Scalars['Float']
- billingProduct: BillingProductDTO
- __typename: 'BillingSubscriptionItem'
-}
-
-export interface BillingCustomer {
- id: Scalars['UUID']
- hasPaymentMethod?: Scalars['Boolean']
- __typename: 'BillingCustomer'
-}
-
-export interface BillingSubscription {
- id: Scalars['UUID']
- status: SubscriptionStatus
- interval?: SubscriptionInterval
- billingSubscriptionItems?: BillingSubscriptionItem[]
- currentPeriodEnd?: Scalars['DateTime']
- metadata: Scalars['JSON']
- phases: BillingSubscriptionSchedulePhase[]
- cancelAt?: Scalars['DateTime']
- __typename: 'BillingSubscription'
-}
-
-export type SubscriptionStatus = 'Active' | 'Canceled' | 'Incomplete' | 'IncompleteExpired' | 'PastDue' | 'Paused' | 'Trialing' | 'Unpaid'
-
export interface LogicFunctionExecutionResult {
/** Execution result in JSON format */
data?: Scalars['JSON']
@@ -4263,6 +4263,119 @@ export interface ApplicationRegistrationGenqlSelection{
__scalar?: boolean | number
}
+export interface BillingSubscriptionSchedulePhaseItemGenqlSelection{
+ price?: boolean | number
+ quantity?: boolean | number
+ __typename?: boolean | number
+ __scalar?: boolean | number
+}
+
+export interface BillingSubscriptionSchedulePhaseGenqlSelection{
+ start_date?: boolean | number
+ end_date?: boolean | number
+ items?: BillingSubscriptionSchedulePhaseItemGenqlSelection
+ __typename?: boolean | number
+ __scalar?: boolean | number
+}
+
+export interface BillingProductMetadataGenqlSelection{
+ planKey?: boolean | number
+ priceUsageBased?: boolean | number
+ productKey?: boolean | number
+ isLegacy?: boolean | number
+ __typename?: boolean | number
+ __scalar?: boolean | number
+}
+
+export interface BillingPriceLicensedGenqlSelection{
+ recurringInterval?: boolean | number
+ unitAmount?: boolean | number
+ stripePriceId?: boolean | number
+ priceUsageType?: boolean | number
+ creditAmount?: boolean | number
+ isSellable?: boolean | number
+ __typename?: boolean | number
+ __scalar?: boolean | number
+}
+
+export interface BillingPriceTierGenqlSelection{
+ upTo?: boolean | number
+ flatAmount?: boolean | number
+ unitAmount?: boolean | number
+ __typename?: boolean | number
+ __scalar?: boolean | number
+}
+
+export interface BillingPriceMeteredGenqlSelection{
+ tiers?: BillingPriceTierGenqlSelection
+ recurringInterval?: boolean | number
+ stripePriceId?: boolean | number
+ priceUsageType?: boolean | number
+ __typename?: boolean | number
+ __scalar?: boolean | number
+}
+
+export interface BillingProductGenqlSelection{
+ name?: boolean | number
+ description?: boolean | number
+ images?: boolean | number
+ metadata?: BillingProductMetadataGenqlSelection
+ __typename?: boolean | number
+ __scalar?: boolean | number
+}
+
+export interface BillingLicensedProductGenqlSelection{
+ name?: boolean | number
+ description?: boolean | number
+ images?: boolean | number
+ metadata?: BillingProductMetadataGenqlSelection
+ prices?: BillingPriceLicensedGenqlSelection
+ __typename?: boolean | number
+ __scalar?: boolean | number
+}
+
+export interface BillingMeteredProductGenqlSelection{
+ name?: boolean | number
+ description?: boolean | number
+ images?: boolean | number
+ metadata?: BillingProductMetadataGenqlSelection
+ prices?: BillingPriceMeteredGenqlSelection
+ __typename?: boolean | number
+ __scalar?: boolean | number
+}
+
+export interface BillingSubscriptionItemGenqlSelection{
+ id?: boolean | number
+ hasReachedCurrentPeriodCap?: boolean | number
+ quantity?: boolean | number
+ stripePriceId?: boolean | number
+ unitAmount?: boolean | number
+ creditAmount?: boolean | number
+ billingProduct?: BillingProductDTOGenqlSelection
+ __typename?: boolean | number
+ __scalar?: boolean | number
+}
+
+export interface BillingSubscriptionGenqlSelection{
+ id?: boolean | number
+ status?: boolean | number
+ interval?: boolean | number
+ billingSubscriptionItems?: BillingSubscriptionItemGenqlSelection
+ currentPeriodEnd?: boolean | number
+ metadata?: boolean | number
+ phases?: BillingSubscriptionSchedulePhaseGenqlSelection
+ cancelAt?: boolean | number
+ __typename?: boolean | number
+ __scalar?: boolean | number
+}
+
+export interface BillingCustomerGenqlSelection{
+ id?: boolean | number
+ hasPaymentMethod?: boolean | number
+ __typename?: boolean | number
+ __scalar?: boolean | number
+}
+
export interface SdkClientChecksumsGenqlSelection{
core?: boolean | number
metadata?: boolean | number
@@ -4695,121 +4808,8 @@ export interface ApplicationConnectionProviderGenqlSelection{
type?: boolean | number
name?: boolean | number
displayName?: boolean | number
- oauth?: ApplicationConnectionProviderOAuthConfigGenqlSelection
- logoUrl?: boolean | number
- __typename?: boolean | number
- __scalar?: boolean | number
-}
-
-export interface BillingSubscriptionSchedulePhaseItemGenqlSelection{
- price?: boolean | number
- quantity?: boolean | number
- __typename?: boolean | number
- __scalar?: boolean | number
-}
-
-export interface BillingSubscriptionSchedulePhaseGenqlSelection{
- start_date?: boolean | number
- end_date?: boolean | number
- items?: BillingSubscriptionSchedulePhaseItemGenqlSelection
- __typename?: boolean | number
- __scalar?: boolean | number
-}
-
-export interface BillingProductMetadataGenqlSelection{
- planKey?: boolean | number
- priceUsageBased?: boolean | number
- productKey?: boolean | number
- isLegacy?: boolean | number
- __typename?: boolean | number
- __scalar?: boolean | number
-}
-
-export interface BillingPriceLicensedGenqlSelection{
- recurringInterval?: boolean | number
- unitAmount?: boolean | number
- stripePriceId?: boolean | number
- priceUsageType?: boolean | number
- creditAmount?: boolean | number
- isSellable?: boolean | number
- __typename?: boolean | number
- __scalar?: boolean | number
-}
-
-export interface BillingPriceTierGenqlSelection{
- upTo?: boolean | number
- flatAmount?: boolean | number
- unitAmount?: boolean | number
- __typename?: boolean | number
- __scalar?: boolean | number
-}
-
-export interface BillingPriceMeteredGenqlSelection{
- tiers?: BillingPriceTierGenqlSelection
- recurringInterval?: boolean | number
- stripePriceId?: boolean | number
- priceUsageType?: boolean | number
- __typename?: boolean | number
- __scalar?: boolean | number
-}
-
-export interface BillingProductGenqlSelection{
- name?: boolean | number
- description?: boolean | number
- images?: boolean | number
- metadata?: BillingProductMetadataGenqlSelection
- __typename?: boolean | number
- __scalar?: boolean | number
-}
-
-export interface BillingLicensedProductGenqlSelection{
- name?: boolean | number
- description?: boolean | number
- images?: boolean | number
- metadata?: BillingProductMetadataGenqlSelection
- prices?: BillingPriceLicensedGenqlSelection
- __typename?: boolean | number
- __scalar?: boolean | number
-}
-
-export interface BillingMeteredProductGenqlSelection{
- name?: boolean | number
- description?: boolean | number
- images?: boolean | number
- metadata?: BillingProductMetadataGenqlSelection
- prices?: BillingPriceMeteredGenqlSelection
- __typename?: boolean | number
- __scalar?: boolean | number
-}
-
-export interface BillingSubscriptionItemGenqlSelection{
- id?: boolean | number
- hasReachedCurrentPeriodCap?: boolean | number
- quantity?: boolean | number
- stripePriceId?: boolean | number
- unitAmount?: boolean | number
- creditAmount?: boolean | number
- billingProduct?: BillingProductDTOGenqlSelection
- __typename?: boolean | number
- __scalar?: boolean | number
-}
-
-export interface BillingCustomerGenqlSelection{
- id?: boolean | number
- hasPaymentMethod?: boolean | number
- __typename?: boolean | number
- __scalar?: boolean | number
-}
-
-export interface BillingSubscriptionGenqlSelection{
- id?: boolean | number
- status?: boolean | number
- interval?: boolean | number
- billingSubscriptionItems?: BillingSubscriptionItemGenqlSelection
- currentPeriodEnd?: boolean | number
- metadata?: boolean | number
- phases?: BillingSubscriptionSchedulePhaseGenqlSelection
- cancelAt?: boolean | number
+ oauth?: ApplicationConnectionProviderOAuthConfigGenqlSelection
+ logoUrl?: boolean | number
__typename?: boolean | number
__scalar?: boolean | number
}
@@ -8096,6 +8096,102 @@ export interface LogicFunctionLogsInput {applicationId?: (Scalars['UUID'] | null
+ const BillingSubscriptionSchedulePhaseItem_possibleTypes: string[] = ['BillingSubscriptionSchedulePhaseItem']
+ export const isBillingSubscriptionSchedulePhaseItem = (obj?: { __typename?: any } | null): obj is BillingSubscriptionSchedulePhaseItem => {
+ if (!obj?.__typename) throw new Error('__typename is missing in "isBillingSubscriptionSchedulePhaseItem"')
+ return BillingSubscriptionSchedulePhaseItem_possibleTypes.includes(obj.__typename)
+ }
+
+
+
+ const BillingSubscriptionSchedulePhase_possibleTypes: string[] = ['BillingSubscriptionSchedulePhase']
+ export const isBillingSubscriptionSchedulePhase = (obj?: { __typename?: any } | null): obj is BillingSubscriptionSchedulePhase => {
+ if (!obj?.__typename) throw new Error('__typename is missing in "isBillingSubscriptionSchedulePhase"')
+ return BillingSubscriptionSchedulePhase_possibleTypes.includes(obj.__typename)
+ }
+
+
+
+ const BillingProductMetadata_possibleTypes: string[] = ['BillingProductMetadata']
+ export const isBillingProductMetadata = (obj?: { __typename?: any } | null): obj is BillingProductMetadata => {
+ if (!obj?.__typename) throw new Error('__typename is missing in "isBillingProductMetadata"')
+ return BillingProductMetadata_possibleTypes.includes(obj.__typename)
+ }
+
+
+
+ const BillingPriceLicensed_possibleTypes: string[] = ['BillingPriceLicensed']
+ export const isBillingPriceLicensed = (obj?: { __typename?: any } | null): obj is BillingPriceLicensed => {
+ if (!obj?.__typename) throw new Error('__typename is missing in "isBillingPriceLicensed"')
+ return BillingPriceLicensed_possibleTypes.includes(obj.__typename)
+ }
+
+
+
+ const BillingPriceTier_possibleTypes: string[] = ['BillingPriceTier']
+ export const isBillingPriceTier = (obj?: { __typename?: any } | null): obj is BillingPriceTier => {
+ if (!obj?.__typename) throw new Error('__typename is missing in "isBillingPriceTier"')
+ return BillingPriceTier_possibleTypes.includes(obj.__typename)
+ }
+
+
+
+ const BillingPriceMetered_possibleTypes: string[] = ['BillingPriceMetered']
+ export const isBillingPriceMetered = (obj?: { __typename?: any } | null): obj is BillingPriceMetered => {
+ if (!obj?.__typename) throw new Error('__typename is missing in "isBillingPriceMetered"')
+ return BillingPriceMetered_possibleTypes.includes(obj.__typename)
+ }
+
+
+
+ const BillingProduct_possibleTypes: string[] = ['BillingProduct']
+ export const isBillingProduct = (obj?: { __typename?: any } | null): obj is BillingProduct => {
+ if (!obj?.__typename) throw new Error('__typename is missing in "isBillingProduct"')
+ return BillingProduct_possibleTypes.includes(obj.__typename)
+ }
+
+
+
+ const BillingLicensedProduct_possibleTypes: string[] = ['BillingLicensedProduct']
+ export const isBillingLicensedProduct = (obj?: { __typename?: any } | null): obj is BillingLicensedProduct => {
+ if (!obj?.__typename) throw new Error('__typename is missing in "isBillingLicensedProduct"')
+ return BillingLicensedProduct_possibleTypes.includes(obj.__typename)
+ }
+
+
+
+ const BillingMeteredProduct_possibleTypes: string[] = ['BillingMeteredProduct']
+ export const isBillingMeteredProduct = (obj?: { __typename?: any } | null): obj is BillingMeteredProduct => {
+ if (!obj?.__typename) throw new Error('__typename is missing in "isBillingMeteredProduct"')
+ return BillingMeteredProduct_possibleTypes.includes(obj.__typename)
+ }
+
+
+
+ const BillingSubscriptionItem_possibleTypes: string[] = ['BillingSubscriptionItem']
+ export const isBillingSubscriptionItem = (obj?: { __typename?: any } | null): obj is BillingSubscriptionItem => {
+ if (!obj?.__typename) throw new Error('__typename is missing in "isBillingSubscriptionItem"')
+ return BillingSubscriptionItem_possibleTypes.includes(obj.__typename)
+ }
+
+
+
+ const BillingSubscription_possibleTypes: string[] = ['BillingSubscription']
+ export const isBillingSubscription = (obj?: { __typename?: any } | null): obj is BillingSubscription => {
+ if (!obj?.__typename) throw new Error('__typename is missing in "isBillingSubscription"')
+ return BillingSubscription_possibleTypes.includes(obj.__typename)
+ }
+
+
+
+ const BillingCustomer_possibleTypes: string[] = ['BillingCustomer']
+ export const isBillingCustomer = (obj?: { __typename?: any } | null): obj is BillingCustomer => {
+ if (!obj?.__typename) throw new Error('__typename is missing in "isBillingCustomer"')
+ return BillingCustomer_possibleTypes.includes(obj.__typename)
+ }
+
+
+
const SdkClientChecksums_possibleTypes: string[] = ['SdkClientChecksums']
export const isSdkClientChecksums = (obj?: { __typename?: any } | null): obj is SdkClientChecksums => {
if (!obj?.__typename) throw new Error('__typename is missing in "isSdkClientChecksums"')
@@ -8424,102 +8520,6 @@ export interface LogicFunctionLogsInput {applicationId?: (Scalars['UUID'] | null
- const BillingSubscriptionSchedulePhaseItem_possibleTypes: string[] = ['BillingSubscriptionSchedulePhaseItem']
- export const isBillingSubscriptionSchedulePhaseItem = (obj?: { __typename?: any } | null): obj is BillingSubscriptionSchedulePhaseItem => {
- if (!obj?.__typename) throw new Error('__typename is missing in "isBillingSubscriptionSchedulePhaseItem"')
- return BillingSubscriptionSchedulePhaseItem_possibleTypes.includes(obj.__typename)
- }
-
-
-
- const BillingSubscriptionSchedulePhase_possibleTypes: string[] = ['BillingSubscriptionSchedulePhase']
- export const isBillingSubscriptionSchedulePhase = (obj?: { __typename?: any } | null): obj is BillingSubscriptionSchedulePhase => {
- if (!obj?.__typename) throw new Error('__typename is missing in "isBillingSubscriptionSchedulePhase"')
- return BillingSubscriptionSchedulePhase_possibleTypes.includes(obj.__typename)
- }
-
-
-
- const BillingProductMetadata_possibleTypes: string[] = ['BillingProductMetadata']
- export const isBillingProductMetadata = (obj?: { __typename?: any } | null): obj is BillingProductMetadata => {
- if (!obj?.__typename) throw new Error('__typename is missing in "isBillingProductMetadata"')
- return BillingProductMetadata_possibleTypes.includes(obj.__typename)
- }
-
-
-
- const BillingPriceLicensed_possibleTypes: string[] = ['BillingPriceLicensed']
- export const isBillingPriceLicensed = (obj?: { __typename?: any } | null): obj is BillingPriceLicensed => {
- if (!obj?.__typename) throw new Error('__typename is missing in "isBillingPriceLicensed"')
- return BillingPriceLicensed_possibleTypes.includes(obj.__typename)
- }
-
-
-
- const BillingPriceTier_possibleTypes: string[] = ['BillingPriceTier']
- export const isBillingPriceTier = (obj?: { __typename?: any } | null): obj is BillingPriceTier => {
- if (!obj?.__typename) throw new Error('__typename is missing in "isBillingPriceTier"')
- return BillingPriceTier_possibleTypes.includes(obj.__typename)
- }
-
-
-
- const BillingPriceMetered_possibleTypes: string[] = ['BillingPriceMetered']
- export const isBillingPriceMetered = (obj?: { __typename?: any } | null): obj is BillingPriceMetered => {
- if (!obj?.__typename) throw new Error('__typename is missing in "isBillingPriceMetered"')
- return BillingPriceMetered_possibleTypes.includes(obj.__typename)
- }
-
-
-
- const BillingProduct_possibleTypes: string[] = ['BillingProduct']
- export const isBillingProduct = (obj?: { __typename?: any } | null): obj is BillingProduct => {
- if (!obj?.__typename) throw new Error('__typename is missing in "isBillingProduct"')
- return BillingProduct_possibleTypes.includes(obj.__typename)
- }
-
-
-
- const BillingLicensedProduct_possibleTypes: string[] = ['BillingLicensedProduct']
- export const isBillingLicensedProduct = (obj?: { __typename?: any } | null): obj is BillingLicensedProduct => {
- if (!obj?.__typename) throw new Error('__typename is missing in "isBillingLicensedProduct"')
- return BillingLicensedProduct_possibleTypes.includes(obj.__typename)
- }
-
-
-
- const BillingMeteredProduct_possibleTypes: string[] = ['BillingMeteredProduct']
- export const isBillingMeteredProduct = (obj?: { __typename?: any } | null): obj is BillingMeteredProduct => {
- if (!obj?.__typename) throw new Error('__typename is missing in "isBillingMeteredProduct"')
- return BillingMeteredProduct_possibleTypes.includes(obj.__typename)
- }
-
-
-
- const BillingSubscriptionItem_possibleTypes: string[] = ['BillingSubscriptionItem']
- export const isBillingSubscriptionItem = (obj?: { __typename?: any } | null): obj is BillingSubscriptionItem => {
- if (!obj?.__typename) throw new Error('__typename is missing in "isBillingSubscriptionItem"')
- return BillingSubscriptionItem_possibleTypes.includes(obj.__typename)
- }
-
-
-
- const BillingCustomer_possibleTypes: string[] = ['BillingCustomer']
- export const isBillingCustomer = (obj?: { __typename?: any } | null): obj is BillingCustomer => {
- if (!obj?.__typename) throw new Error('__typename is missing in "isBillingCustomer"')
- return BillingCustomer_possibleTypes.includes(obj.__typename)
- }
-
-
-
- const BillingSubscription_possibleTypes: string[] = ['BillingSubscription']
- export const isBillingSubscription = (obj?: { __typename?: any } | null): obj is BillingSubscription => {
- if (!obj?.__typename) throw new Error('__typename is missing in "isBillingSubscription"')
- return BillingSubscription_possibleTypes.includes(obj.__typename)
- }
-
-
-
const LogicFunctionExecutionResult_possibleTypes: string[] = ['LogicFunctionExecutionResult']
export const isLogicFunctionExecutionResult = (obj?: { __typename?: any } | null): obj is LogicFunctionExecutionResult => {
if (!obj?.__typename) throw new Error('__typename is missing in "isLogicFunctionExecutionResult"')
@@ -10513,6 +10513,37 @@ export const enumOnboardingStatus = {
COMPLETED: 'COMPLETED' as const
}
+export const enumBillingPlanKey = {
+ PRO: 'PRO' as const,
+ ENTERPRISE: 'ENTERPRISE' as const
+}
+
+export const enumBillingUsageType = {
+ METERED: 'METERED' as const,
+ LICENSED: 'LICENSED' as const
+}
+
+export const enumBillingProductKey = {
+ BASE_PRODUCT: 'BASE_PRODUCT' as const,
+ RESOURCE_CREDIT: 'RESOURCE_CREDIT' as const
+}
+
+export const enumSubscriptionInterval = {
+ Month: 'Month' as const,
+ Year: 'Year' as const
+}
+
+export const enumSubscriptionStatus = {
+ Active: 'Active' as const,
+ Canceled: 'Canceled' as const,
+ Incomplete: 'Incomplete' as const,
+ IncompleteExpired: 'IncompleteExpired' as const,
+ PastDue: 'PastDue' as const,
+ Paused: 'Paused' as const,
+ Trialing: 'Trialing' as const,
+ Unpaid: 'Unpaid' as const
+}
+
export const enumWidgetType = {
VIEW: 'VIEW' as const,
IFRAME: 'IFRAME' as const,
@@ -10641,37 +10672,6 @@ export const enumPageLayoutType = {
RECORD_FORM: 'RECORD_FORM' as const
}
-export const enumBillingPlanKey = {
- PRO: 'PRO' as const,
- ENTERPRISE: 'ENTERPRISE' as const
-}
-
-export const enumBillingUsageType = {
- METERED: 'METERED' as const,
- LICENSED: 'LICENSED' as const
-}
-
-export const enumBillingProductKey = {
- BASE_PRODUCT: 'BASE_PRODUCT' as const,
- RESOURCE_CREDIT: 'RESOURCE_CREDIT' as const
-}
-
-export const enumSubscriptionInterval = {
- Month: 'Month' as const,
- Year: 'Year' as const
-}
-
-export const enumSubscriptionStatus = {
- Active: 'Active' as const,
- Canceled: 'Canceled' as const,
- Incomplete: 'Incomplete' as const,
- IncompleteExpired: 'IncompleteExpired' as const,
- PastDue: 'PastDue' as const,
- Paused: 'Paused' as const,
- Trialing: 'Trialing' as const,
- Unpaid: 'Unpaid' as const
-}
-
export const enumLogicFunctionExecutionStatus = {
IDLE: 'IDLE' as const,
SUCCESS: 'SUCCESS' as const,
diff --git a/packages/twenty-client-sdk/src/metadata/generated/types.ts b/packages/twenty-client-sdk/src/metadata/generated/types.ts
index 0437e2576bd..47eed29869d 100644
--- a/packages/twenty-client-sdk/src/metadata/generated/types.ts
+++ b/packages/twenty-client-sdk/src/metadata/generated/types.ts
@@ -36,23 +36,23 @@ export default {
72,
74,
75,
+ 80,
+ 81,
82,
- 85,
- 87,
- 91,
+ 84,
92,
- 95,
- 96,
- 98,
- 101,
+ 99,
102,
+ 104,
+ 108,
+ 109,
112,
- 127,
- 133,
- 134,
- 135,
- 137,
- 146,
+ 113,
+ 115,
+ 118,
+ 119,
+ 129,
+ 144,
148,
155,
157,
@@ -117,13 +117,13 @@ export default {
1
],
"metadata": [
- 132
+ 79
],
"on_BillingLicensedProduct": [
- 141
+ 88
],
"on_BillingMeteredProduct": [
- 142
+ 89
],
"__typename": [
1
@@ -1654,16 +1654,16 @@ export default {
195
],
"billingSubscriptions": [
- 145
+ 91
],
"installedApplications": [
49
],
"currentBillingSubscription": [
- 145
+ 91
],
"billingCustomer": [
- 144
+ 93
],
"billingEntitlements": [
267
@@ -1831,6 +1831,230 @@ export default {
1
]
},
+ "BillingSubscriptionSchedulePhaseItem": {
+ "price": [
+ 1
+ ],
+ "quantity": [
+ 15
+ ],
+ "__typename": [
+ 1
+ ]
+ },
+ "BillingSubscriptionSchedulePhase": {
+ "start_date": [
+ 15
+ ],
+ "end_date": [
+ 15
+ ],
+ "items": [
+ 77
+ ],
+ "__typename": [
+ 1
+ ]
+ },
+ "BillingProductMetadata": {
+ "planKey": [
+ 80
+ ],
+ "priceUsageBased": [
+ 81
+ ],
+ "productKey": [
+ 82
+ ],
+ "isLegacy": [
+ 1
+ ],
+ "__typename": [
+ 1
+ ]
+ },
+ "BillingPlanKey": {},
+ "BillingUsageType": {},
+ "BillingProductKey": {},
+ "BillingPriceLicensed": {
+ "recurringInterval": [
+ 84
+ ],
+ "unitAmount": [
+ 15
+ ],
+ "stripePriceId": [
+ 1
+ ],
+ "priceUsageType": [
+ 81
+ ],
+ "creditAmount": [
+ 15
+ ],
+ "isSellable": [
+ 8
+ ],
+ "__typename": [
+ 1
+ ]
+ },
+ "SubscriptionInterval": {},
+ "BillingPriceTier": {
+ "upTo": [
+ 15
+ ],
+ "flatAmount": [
+ 15
+ ],
+ "unitAmount": [
+ 15
+ ],
+ "__typename": [
+ 1
+ ]
+ },
+ "BillingPriceMetered": {
+ "tiers": [
+ 85
+ ],
+ "recurringInterval": [
+ 84
+ ],
+ "stripePriceId": [
+ 1
+ ],
+ "priceUsageType": [
+ 81
+ ],
+ "__typename": [
+ 1
+ ]
+ },
+ "BillingProduct": {
+ "name": [
+ 1
+ ],
+ "description": [
+ 1
+ ],
+ "images": [
+ 1
+ ],
+ "metadata": [
+ 79
+ ],
+ "__typename": [
+ 1
+ ]
+ },
+ "BillingLicensedProduct": {
+ "name": [
+ 1
+ ],
+ "description": [
+ 1
+ ],
+ "images": [
+ 1
+ ],
+ "metadata": [
+ 79
+ ],
+ "prices": [
+ 83
+ ],
+ "__typename": [
+ 1
+ ]
+ },
+ "BillingMeteredProduct": {
+ "name": [
+ 1
+ ],
+ "description": [
+ 1
+ ],
+ "images": [
+ 1
+ ],
+ "metadata": [
+ 79
+ ],
+ "prices": [
+ 86
+ ],
+ "__typename": [
+ 1
+ ]
+ },
+ "BillingSubscriptionItem": {
+ "id": [
+ 3
+ ],
+ "hasReachedCurrentPeriodCap": [
+ 8
+ ],
+ "quantity": [
+ 15
+ ],
+ "stripePriceId": [
+ 1
+ ],
+ "unitAmount": [
+ 15
+ ],
+ "creditAmount": [
+ 15
+ ],
+ "billingProduct": [
+ 0
+ ],
+ "__typename": [
+ 1
+ ]
+ },
+ "BillingSubscription": {
+ "id": [
+ 3
+ ],
+ "status": [
+ 92
+ ],
+ "interval": [
+ 84
+ ],
+ "billingSubscriptionItems": [
+ 90
+ ],
+ "currentPeriodEnd": [
+ 4
+ ],
+ "metadata": [
+ 9
+ ],
+ "phases": [
+ 78
+ ],
+ "cancelAt": [
+ 4
+ ],
+ "__typename": [
+ 1
+ ]
+ },
+ "SubscriptionStatus": {},
+ "BillingCustomer": {
+ "id": [
+ 3
+ ],
+ "hasPaymentMethod": [
+ 8
+ ],
+ "__typename": [
+ 1
+ ]
+ },
"SdkClientChecksums": {
"core": [
1
@@ -1901,19 +2125,19 @@ export default {
1
],
"type": [
- 82
+ 99
],
"objectMetadataId": [
3
],
"gridPosition": [
- 80
+ 97
],
"position": [
- 83
+ 100
],
"configuration": [
- 89
+ 106
],
"conditionalDisplay": [
9
@@ -1943,13 +2167,13 @@ export default {
"WidgetType": {},
"PageLayoutWidgetPosition": {
"on_PageLayoutWidgetGridPosition": [
- 84
+ 101
],
"on_PageLayoutWidgetVerticalListPosition": [
- 86
+ 103
],
"on_PageLayoutWidgetCanvasPosition": [
- 88
+ 105
],
"__typename": [
1
@@ -1957,7 +2181,7 @@ export default {
},
"PageLayoutWidgetGridPosition": {
"layoutMode": [
- 85
+ 102
],
"row": [
28
@@ -1978,13 +2202,13 @@ export default {
"PageLayoutTabLayoutMode": {},
"PageLayoutWidgetVerticalListPosition": {
"layoutMode": [
- 85
+ 102
],
"index": [
28
],
"heightBehavior": [
- 87
+ 104
],
"__typename": [
1
@@ -1993,7 +2217,7 @@ export default {
"PageLayoutWidgetVerticalListHeightBehavior": {},
"PageLayoutWidgetCanvasPosition": {
"layoutMode": [
- 85
+ 102
],
"__typename": [
1
@@ -2001,85 +2225,85 @@ export default {
},
"WidgetConfiguration": {
"on_AggregateChartConfiguration": [
- 90
+ 107
],
"on_StandaloneRichTextConfiguration": [
- 93
+ 110
],
"on_PieChartConfiguration": [
- 94
+ 111
],
"on_LineChartConfiguration": [
- 97
+ 114
],
"on_IframeConfiguration": [
- 99
+ 116
],
"on_BarChartConfiguration": [
- 100
+ 117
],
"on_CalendarConfiguration": [
- 103
+ 120
],
"on_FrontComponentConfiguration": [
- 104
+ 121
],
"on_EmailsConfiguration": [
- 105
+ 122
],
"on_EmailThreadConfiguration": [
- 106
+ 123
],
"on_CallRecordingSummaryConfiguration": [
- 107
+ 124
],
"on_CallRecordingTranscriptConfiguration": [
- 108
+ 125
],
"on_MessageCampaignBodyConfiguration": [
- 109
+ 126
],
"on_MessageCampaignDetailsConfiguration": [
- 110
+ 127
],
"on_FieldConfiguration": [
- 111
+ 128
],
"on_FieldRichTextConfiguration": [
- 113
+ 130
],
"on_FieldsConfiguration": [
- 114
+ 131
],
"on_FormFieldConfiguration": [
- 115
+ 132
],
"on_FilesConfiguration": [
- 116
+ 133
],
"on_NotesConfiguration": [
- 117
+ 134
],
"on_TasksConfiguration": [
- 118
+ 135
],
"on_TimelineConfiguration": [
- 119
+ 136
],
"on_ViewConfiguration": [
- 120
+ 137
],
"on_RecordTableConfiguration": [
- 121
+ 138
],
"on_WorkflowConfiguration": [
- 122
+ 139
],
"on_WorkflowRunConfiguration": [
- 123
+ 140
],
"on_WorkflowVersionConfiguration": [
- 124
+ 141
],
"__typename": [
1
@@ -2087,7 +2311,7 @@ export default {
},
"AggregateChartConfiguration": {
"configurationType": [
- 91
+ 108
],
"aggregateFieldMetadataId": [
3
@@ -2102,7 +2326,7 @@ export default {
8
],
"numberFormat": [
- 92
+ 109
],
"description": [
1
@@ -2123,7 +2347,7 @@ export default {
1
],
"ratioAggregateConfig": [
- 78
+ 95
],
"__typename": [
1
@@ -2133,10 +2357,10 @@ export default {
"ChartNumberFormat": {},
"StandaloneRichTextConfiguration": {
"configurationType": [
- 91
+ 108
],
"body": [
- 79
+ 96
],
"__typename": [
1
@@ -2144,7 +2368,7 @@ export default {
},
"PieChartConfiguration": {
"configurationType": [
- 91
+ 108
],
"aggregateFieldMetadataId": [
3
@@ -2159,10 +2383,10 @@ export default {
1
],
"dateGranularity": [
- 95
+ 112
],
"orderBy": [
- 96
+ 113
],
"manualSortOrder": [
1
@@ -2180,7 +2404,7 @@ export default {
8
],
"numberFormat": [
- 92
+ 109
],
"splitMultiValueFields": [
8
@@ -2208,7 +2432,7 @@ export default {
"GraphOrderBy": {},
"LineChartConfiguration": {
"configurationType": [
- 91
+ 108
],
"aggregateFieldMetadataId": [
3
@@ -2223,10 +2447,10 @@ export default {
1
],
"primaryAxisDateGranularity": [
- 95
+ 112
],
"primaryAxisOrderBy": [
- 96
+ 113
],
"primaryAxisManualSortOrder": [
1
@@ -2238,10 +2462,10 @@ export default {
1
],
"secondaryAxisGroupByDateGranularity": [
- 95
+ 112
],
"secondaryAxisOrderBy": [
- 96
+ 113
],
"secondaryAxisManualSortOrder": [
1
@@ -2253,7 +2477,7 @@ export default {
8
],
"axisNameDisplay": [
- 98
+ 115
],
"displayDataLabel": [
8
@@ -2262,7 +2486,7 @@ export default {
8
],
"numberFormat": [
- 92
+ 109
],
"rangeMin": [
15
@@ -2298,7 +2522,7 @@ export default {
"AxisNameDisplay": {},
"IframeConfiguration": {
"configurationType": [
- 91
+ 108
],
"url": [
1
@@ -2309,7 +2533,7 @@ export default {
},
"BarChartConfiguration": {
"configurationType": [
- 91
+ 108
],
"aggregateFieldMetadataId": [
3
@@ -2324,10 +2548,10 @@ export default {
1
],
"primaryAxisDateGranularity": [
- 95
+ 112
],
"primaryAxisOrderBy": [
- 96
+ 113
],
"primaryAxisManualSortOrder": [
1
@@ -2339,10 +2563,10 @@ export default {
1
],
"secondaryAxisGroupByDateGranularity": [
- 95
+ 112
],
"secondaryAxisOrderBy": [
- 96
+ 113
],
"secondaryAxisManualSortOrder": [
1
@@ -2354,7 +2578,7 @@ export default {
8
],
"axisNameDisplay": [
- 98
+ 115
],
"displayDataLabel": [
8
@@ -2363,7 +2587,7 @@ export default {
8
],
"numberFormat": [
- 92
+ 109
],
"rangeMin": [
15
@@ -2381,10 +2605,10 @@ export default {
9
],
"groupMode": [
- 101
+ 118
],
"layout": [
- 102
+ 119
],
"isCumulative": [
8
@@ -2403,7 +2627,7 @@ export default {
"BarChartLayout": {},
"CalendarConfiguration": {
"configurationType": [
- 91
+ 108
],
"__typename": [
1
@@ -2411,7 +2635,7 @@ export default {
},
"FrontComponentConfiguration": {
"configurationType": [
- 91
+ 108
],
"frontComponentId": [
3
@@ -2425,7 +2649,7 @@ export default {
},
"EmailsConfiguration": {
"configurationType": [
- 91
+ 108
],
"__typename": [
1
@@ -2433,7 +2657,7 @@ export default {
},
"EmailThreadConfiguration": {
"configurationType": [
- 91
+ 108
],
"__typename": [
1
@@ -2441,7 +2665,7 @@ export default {
},
"CallRecordingSummaryConfiguration": {
"configurationType": [
- 91
+ 108
],
"__typename": [
1
@@ -2449,7 +2673,7 @@ export default {
},
"CallRecordingTranscriptConfiguration": {
"configurationType": [
- 91
+ 108
],
"__typename": [
1
@@ -2457,7 +2681,7 @@ export default {
},
"MessageCampaignBodyConfiguration": {
"configurationType": [
- 91
+ 108
],
"__typename": [
1
@@ -2465,7 +2689,7 @@ export default {
},
"MessageCampaignDetailsConfiguration": {
"configurationType": [
- 91
+ 108
],
"__typename": [
1
@@ -2473,13 +2697,13 @@ export default {
},
"FieldConfiguration": {
"configurationType": [
- 91
+ 108
],
"fieldMetadataId": [
1
],
"fieldDisplayMode": [
- 112
+ 129
],
"viewId": [
1
@@ -2497,7 +2721,7 @@ export default {
"FieldDisplayMode": {},
"FieldRichTextConfiguration": {
"configurationType": [
- 91
+ 108
],
"__typename": [
1
@@ -2505,7 +2729,7 @@ export default {
},
"FieldsConfiguration": {
"configurationType": [
- 91
+ 108
],
"viewId": [
1
@@ -2522,7 +2746,7 @@ export default {
},
"FormFieldConfiguration": {
"configurationType": [
- 91
+ 108
],
"fieldMetadataId": [
1
@@ -2533,7 +2757,7 @@ export default {
},
"FilesConfiguration": {
"configurationType": [
- 91
+ 108
],
"__typename": [
1
@@ -2541,7 +2765,7 @@ export default {
},
"NotesConfiguration": {
"configurationType": [
- 91
+ 108
],
"__typename": [
1
@@ -2549,425 +2773,201 @@ export default {
},
"TasksConfiguration": {
"configurationType": [
- 91
- ],
- "__typename": [
- 1
- ]
- },
- "TimelineConfiguration": {
- "configurationType": [
- 91
- ],
- "__typename": [
- 1
- ]
- },
- "ViewConfiguration": {
- "configurationType": [
- 91
- ],
- "__typename": [
- 1
- ]
- },
- "RecordTableConfiguration": {
- "configurationType": [
- 91
- ],
- "viewId": [
- 1
- ],
- "recordLimit": [
- 28
- ],
- "isUIEditable": [
- 8
- ],
- "__typename": [
- 1
- ]
- },
- "WorkflowConfiguration": {
- "configurationType": [
- 91
- ],
- "__typename": [
- 1
- ]
- },
- "WorkflowRunConfiguration": {
- "configurationType": [
- 91
- ],
- "__typename": [
- 1
- ]
- },
- "WorkflowVersionConfiguration": {
- "configurationType": [
- 91
- ],
- "__typename": [
- 1
- ]
- },
- "PageLayoutTab": {
- "id": [
- 3
- ],
- "universalIdentifier": [
- 3
- ],
- "isSystemSideEffect": [
- 8
- ],
- "applicationId": [
- 3
- ],
- "title": [
- 1
- ],
- "position": [
- 15
- ],
- "pageLayoutId": [
- 3
- ],
- "widgets": [
- 81
- ],
- "icon": [
- 1
- ],
- "layoutMode": [
- 85
- ],
- "createdAt": [
- 4
- ],
- "updatedAt": [
- 4
- ],
- "isActive": [
- 8
- ],
- "deletedAt": [
- 4
- ],
- "isOverridden": [
- 8
- ],
- "__typename": [
- 1
- ]
- },
- "PageLayout": {
- "id": [
- 3
- ],
- "name": [
- 1
- ],
- "type": [
- 127
- ],
- "objectMetadataId": [
- 3
- ],
- "tabs": [
- 125
- ],
- "defaultTabToFocusOnMobileAndSidePanelId": [
- 3
- ],
- "universalIdentifier": [
- 3
- ],
- "applicationId": [
- 3
- ],
- "isSystemSideEffect": [
- 8
- ],
- "isFirstTabPinned": [
- 8
- ],
- "createdAt": [
- 4
- ],
- "updatedAt": [
- 4
- ],
- "deletedAt": [
- 4
- ],
- "__typename": [
- 1
- ]
- },
- "PageLayoutType": {},
- "ApplicationConnectionProviderOAuthConfig": {
- "scopes": [
- 1
- ],
- "isClientCredentialsConfigured": [
- 8
- ],
- "__typename": [
- 1
- ]
- },
- "ApplicationConnectionProvider": {
- "id": [
- 3
- ],
- "applicationId": [
- 1
- ],
- "type": [
- 1
- ],
- "name": [
- 1
- ],
- "displayName": [
- 1
- ],
- "oauth": [
- 128
- ],
- "logoUrl": [
- 1
- ],
- "__typename": [
- 1
- ]
- },
- "BillingSubscriptionSchedulePhaseItem": {
- "price": [
- 1
- ],
- "quantity": [
- 15
- ],
- "__typename": [
- 1
- ]
- },
- "BillingSubscriptionSchedulePhase": {
- "start_date": [
- 15
- ],
- "end_date": [
- 15
- ],
- "items": [
- 130
- ],
- "__typename": [
- 1
- ]
- },
- "BillingProductMetadata": {
- "planKey": [
- 133
- ],
- "priceUsageBased": [
- 134
- ],
- "productKey": [
- 135
+ 108
],
- "isLegacy": [
+ "__typename": [
1
+ ]
+ },
+ "TimelineConfiguration": {
+ "configurationType": [
+ 108
],
"__typename": [
1
]
},
- "BillingPlanKey": {},
- "BillingUsageType": {},
- "BillingProductKey": {},
- "BillingPriceLicensed": {
- "recurringInterval": [
- 137
- ],
- "unitAmount": [
- 15
+ "ViewConfiguration": {
+ "configurationType": [
+ 108
],
- "stripePriceId": [
+ "__typename": [
1
+ ]
+ },
+ "RecordTableConfiguration": {
+ "configurationType": [
+ 108
],
- "priceUsageType": [
- 134
+ "viewId": [
+ 1
],
- "creditAmount": [
- 15
+ "recordLimit": [
+ 28
],
- "isSellable": [
+ "isUIEditable": [
8
],
"__typename": [
1
]
},
- "SubscriptionInterval": {},
- "BillingPriceTier": {
- "upTo": [
- 15
- ],
- "flatAmount": [
- 15
- ],
- "unitAmount": [
- 15
+ "WorkflowConfiguration": {
+ "configurationType": [
+ 108
],
"__typename": [
1
]
},
- "BillingPriceMetered": {
- "tiers": [
- 138
- ],
- "recurringInterval": [
- 137
+ "WorkflowRunConfiguration": {
+ "configurationType": [
+ 108
],
- "stripePriceId": [
+ "__typename": [
1
- ],
- "priceUsageType": [
- 134
+ ]
+ },
+ "WorkflowVersionConfiguration": {
+ "configurationType": [
+ 108
],
"__typename": [
1
]
},
- "BillingProduct": {
- "name": [
- 1
+ "PageLayoutTab": {
+ "id": [
+ 3
],
- "description": [
- 1
+ "universalIdentifier": [
+ 3
],
- "images": [
- 1
+ "isSystemSideEffect": [
+ 8
],
- "metadata": [
- 132
+ "applicationId": [
+ 3
],
- "__typename": [
- 1
- ]
- },
- "BillingLicensedProduct": {
- "name": [
+ "title": [
1
],
- "description": [
- 1
+ "position": [
+ 15
],
- "images": [
+ "pageLayoutId": [
+ 3
+ ],
+ "widgets": [
+ 98
+ ],
+ "icon": [
1
],
- "metadata": [
- 132
+ "layoutMode": [
+ 102
],
- "prices": [
- 136
+ "createdAt": [
+ 4
+ ],
+ "updatedAt": [
+ 4
+ ],
+ "isActive": [
+ 8
+ ],
+ "deletedAt": [
+ 4
+ ],
+ "isOverridden": [
+ 8
],
"__typename": [
1
]
},
- "BillingMeteredProduct": {
+ "PageLayout": {
+ "id": [
+ 3
+ ],
"name": [
1
],
- "description": [
- 1
+ "type": [
+ 144
],
- "images": [
- 1
+ "objectMetadataId": [
+ 3
],
- "metadata": [
- 132
+ "tabs": [
+ 142
],
- "prices": [
- 139
+ "defaultTabToFocusOnMobileAndSidePanelId": [
+ 3
],
- "__typename": [
- 1
- ]
- },
- "BillingSubscriptionItem": {
- "id": [
+ "universalIdentifier": [
3
],
- "hasReachedCurrentPeriodCap": [
- 8
+ "applicationId": [
+ 3
],
- "quantity": [
- 15
+ "isSystemSideEffect": [
+ 8
],
- "stripePriceId": [
- 1
+ "isFirstTabPinned": [
+ 8
],
- "unitAmount": [
- 15
+ "createdAt": [
+ 4
],
- "creditAmount": [
- 15
+ "updatedAt": [
+ 4
],
- "billingProduct": [
- 0
+ "deletedAt": [
+ 4
],
"__typename": [
1
]
},
- "BillingCustomer": {
- "id": [
- 3
+ "PageLayoutType": {},
+ "ApplicationConnectionProviderOAuthConfig": {
+ "scopes": [
+ 1
],
- "hasPaymentMethod": [
+ "isClientCredentialsConfigured": [
8
],
"__typename": [
1
]
},
- "BillingSubscription": {
+ "ApplicationConnectionProvider": {
"id": [
3
],
- "status": [
- 146
- ],
- "interval": [
- 137
+ "applicationId": [
+ 1
],
- "billingSubscriptionItems": [
- 143
+ "type": [
+ 1
],
- "currentPeriodEnd": [
- 4
+ "name": [
+ 1
],
- "metadata": [
- 9
+ "displayName": [
+ 1
],
- "phases": [
- 131
+ "oauth": [
+ 145
],
- "cancelAt": [
- 4
+ "logoUrl": [
+ 1
],
"__typename": [
1
]
},
- "SubscriptionStatus": {},
"LogicFunctionExecutionResult": {
"data": [
9
@@ -3291,7 +3291,7 @@ export default {
},
"BillingEndTrialPeriod": {
"status": [
- 146
+ 92
],
"hasPaymentMethod": [
8
@@ -3300,10 +3300,10 @@ export default {
1
],
"currentBillingSubscription": [
- 145
+ 91
],
"billingSubscriptions": [
- 145
+ 91
],
"__typename": [
1
@@ -3311,7 +3311,7 @@ export default {
},
"BillingResourceCreditUsage": {
"productKey": [
- 135
+ 82
],
"periodStart": [
4
@@ -3340,16 +3340,16 @@ export default {
},
"BillingPlan": {
"planKey": [
- 133
+ 80
],
"baseProducts": [
- 141
+ 88
],
"resourceCreditProducts": [
- 141
+ 88
],
"meteredProducts": [
- 142
+ 89
],
"__typename": [
1
@@ -3376,10 +3376,10 @@ export default {
},
"BillingUpdate": {
"currentBillingSubscription": [
- 145
+ 91
],
"billingSubscriptions": [
- 145
+ 91
],
"__typename": [
1
@@ -6303,10 +6303,10 @@ export default {
8
],
"layout": [
- 102
+ 119
],
"groupMode": [
- 101
+ 118
],
"hasTooManyGroups": [
8
@@ -7107,7 +7107,7 @@ export default {
}
],
"applicationSdkClientChecksums": [
- 77,
+ 94,
{
"applicationId": [
3,
@@ -7308,7 +7308,7 @@ export default {
}
],
"applicationConnectionProviders": [
- 129,
+ 146,
{
"applicationId": [
3,
@@ -7343,7 +7343,7 @@ export default {
184
],
"getPageLayoutTabs": [
- 125,
+ 142,
{
"pageLayoutId": [
1,
@@ -7352,7 +7352,7 @@ export default {
}
],
"getPageLayoutTab": [
- 125,
+ 142,
{
"id": [
1,
@@ -7361,18 +7361,18 @@ export default {
}
],
"getPageLayouts": [
- 126,
+ 143,
{
"objectMetadataId": [
1
],
"pageLayoutType": [
- 127
+ 144
]
}
],
"getPageLayout": [
- 126,
+ 143,
{
"id": [
1,
@@ -7381,7 +7381,7 @@ export default {
}
],
"getPageLayoutWidgets": [
- 81,
+ 98,
{
"pageLayoutTabId": [
1,
@@ -7390,7 +7390,7 @@ export default {
}
],
"getPageLayoutWidget": [
- 81,
+ 98,
{
"id": [
1,
@@ -8831,11 +8831,11 @@ export default {
170,
{
"recurringInterval": [
- 137,
+ 84,
"SubscriptionInterval!"
],
"plan": [
- 133,
+ 80,
"BillingPlanKey!"
],
"requirePaymentMethod": [
@@ -8851,11 +8851,11 @@ export default {
169,
{
"recurringInterval": [
- 137,
+ 84,
"SubscriptionInterval!"
],
"plan": [
- 133,
+ 80,
"BillingPlanKey!"
],
"requirePaymentMethod": [
@@ -8997,7 +8997,7 @@ export default {
}
],
"createPageLayoutTab": [
- 125,
+ 142,
{
"input": [
468,
@@ -9006,7 +9006,7 @@ export default {
}
],
"updatePageLayoutTab": [
- 125,
+ 142,
{
"id": [
1,
@@ -9028,7 +9028,7 @@ export default {
}
],
"createPageLayout": [
- 126,
+ 143,
{
"input": [
470,
@@ -9037,7 +9037,7 @@ export default {
}
],
"updatePageLayout": [
- 126,
+ 143,
{
"id": [
1,
@@ -9059,7 +9059,7 @@ export default {
}
],
"updatePageLayoutWithTabsAndWidgets": [
- 126,
+ 143,
{
"id": [
1,
@@ -9072,7 +9072,7 @@ export default {
}
],
"resetPageLayoutToDefault": [
- 126,
+ 143,
{
"id": [
1,
@@ -9081,7 +9081,7 @@ export default {
}
],
"resetPageLayoutWidgetToDefault": [
- 81,
+ 98,
{
"id": [
1,
@@ -9090,7 +9090,7 @@ export default {
}
],
"resetPageLayoutTabToDefault": [
- 125,
+ 142,
{
"id": [
1,
@@ -9099,7 +9099,7 @@ export default {
}
],
"createPageLayoutWidget": [
- 81,
+ 98,
{
"input": [
475,
@@ -9108,7 +9108,7 @@ export default {
}
],
"updatePageLayoutWidget": [
- 81,
+ 98,
{
"id": [
1,
@@ -11738,7 +11738,7 @@ export default {
3
],
"layoutMode": [
- 85
+ 102
],
"__typename": [
1
@@ -11755,7 +11755,7 @@ export default {
1
],
"layoutMode": [
- 85
+ 102
],
"__typename": [
1
@@ -11766,7 +11766,7 @@ export default {
1
],
"type": [
- 127
+ 144
],
"objectMetadataId": [
3
@@ -11780,7 +11780,7 @@ export default {
1
],
"type": [
- 127
+ 144
],
"objectMetadataId": [
3
@@ -11794,7 +11794,7 @@ export default {
1
],
"type": [
- 127
+ 144
],
"objectMetadataId": [
3
@@ -11823,7 +11823,7 @@ export default {
1
],
"layoutMode": [
- 85
+ 102
],
"widgets": [
474
@@ -11843,7 +11843,7 @@ export default {
1
],
"type": [
- 82
+ 99
],
"objectMetadataId": [
3
@@ -11872,7 +11872,7 @@ export default {
1
],
"type": [
- 82
+ 99
],
"objectMetadataId": [
3
@@ -11895,7 +11895,7 @@ export default {
1
],
"type": [
- 82
+ 99
],
"objectMetadataId": [
3
diff --git a/packages/twenty-server/src/engine/core-modules/billing-webhook/services/__tests__/billing-entitlement-sync.service.spec.ts b/packages/twenty-server/src/engine/core-modules/billing-webhook/services/__tests__/billing-entitlement-sync.service.spec.ts
index 5917cb3db8f..c8ab50bfe66 100644
--- a/packages/twenty-server/src/engine/core-modules/billing-webhook/services/__tests__/billing-entitlement-sync.service.spec.ts
+++ b/packages/twenty-server/src/engine/core-modules/billing-webhook/services/__tests__/billing-entitlement-sync.service.spec.ts
@@ -9,6 +9,7 @@ import { CacheLockService } from 'src/engine/core-modules/cache-lock/cache-lock.
import { UsageLimitQuotaService } from 'src/engine/core-modules/usage-limit/services/usage-limit-quota.service';
import { RowLevelPermissionPredicateGroupService } from 'src/engine/metadata-modules/row-level-permission-predicate/services/row-level-permission-predicate-group.service';
import { getWorkspaceScopedRepositoryToken } from 'src/engine/twenty-orm/workspace-scoped-repository/get-workspace-scoped-repository-token.util';
+import { WorkspaceCacheService } from 'src/engine/workspace-cache/services/workspace-cache.service';
const WORKSPACE_ID = '20202020-1c25-4d02-bf25-6aeccf7ea419';
const STRIPE_CUSTOMER_ID = 'cus_test';
@@ -30,6 +31,10 @@ describe('BillingEntitlementSyncService', () => {
dropIntraWorkspaceLimitCounters: jest.fn(),
};
+ const workspaceCacheService = {
+ invalidateAndRecompute: jest.fn(),
+ };
+
// A real single-holder lock rather than a pass-through, so a test that runs
// two syncs concurrently exercises the serialization instead of asserting
// that a stub was called. Queued rather than spin-waiting so ordering is
@@ -67,6 +72,7 @@ describe('BillingEntitlementSyncService', () => {
heldLockKeys.clear();
lockQueueByKey.clear();
billingEntitlementRepository.upsert.mockResolvedValue(undefined);
+ workspaceCacheService.invalidateAndRecompute.mockResolvedValue(undefined);
usageLimitQuotaService.dropIntraWorkspaceLimitCounters.mockResolvedValue(
undefined,
);
@@ -93,6 +99,10 @@ describe('BillingEntitlementSyncService', () => {
provide: CacheLockService,
useValue: cacheLockService,
},
+ {
+ provide: WorkspaceCacheService,
+ useValue: workspaceCacheService,
+ },
],
}).compile();
@@ -216,6 +226,63 @@ describe('BillingEntitlementSyncService', () => {
expect(new Set(heldKeysDuringOtherWorkspaceUpsert).size).toBe(2);
});
+ it('refreshes entitlements after persistence and before RLS cleanup', async () => {
+ givenStoredEntitlements([]);
+
+ await syncEntitlements([]);
+
+ expect(workspaceCacheService.invalidateAndRecompute).toHaveBeenCalledWith(
+ WORKSPACE_ID,
+ ['billingEntitlements'],
+ );
+ expect(
+ workspaceCacheService.invalidateAndRecompute.mock.invocationCallOrder[0],
+ ).toBeGreaterThan(
+ billingEntitlementRepository.upsert.mock.invocationCallOrder[0],
+ );
+ expect(
+ workspaceCacheService.invalidateAndRecompute.mock.invocationCallOrder[0],
+ ).toBeLessThan(
+ rowLevelPermissionPredicateGroupService
+ .deleteAllRowLevelPermissionPredicateGroups.mock.invocationCallOrder[0],
+ );
+ });
+
+ it('retries cache refresh even when the rows already match after a failed refresh', async () => {
+ givenStoredEntitlements([]);
+ billingEntitlementRepository.upsert.mockImplementation(async () => {
+ givenStoredEntitlements([
+ { key: BillingEntitlementKey.USAGE_LIMIT, value: true },
+ ]);
+ });
+ workspaceCacheService.invalidateAndRecompute.mockRejectedValueOnce(
+ new Error('cache unavailable'),
+ );
+
+ await expect(
+ syncEntitlements([BillingEntitlementKey.USAGE_LIMIT]),
+ ).rejects.toThrow('cache unavailable');
+ await syncEntitlements([BillingEntitlementKey.USAGE_LIMIT]);
+
+ expect(workspaceCacheService.invalidateAndRecompute).toHaveBeenCalledTimes(
+ 2,
+ );
+ expect(
+ usageLimitQuotaService.dropIntraWorkspaceLimitCounters,
+ ).toHaveBeenCalledTimes(1);
+ });
+
+ it('does not refresh the cache if persisting entitlements fails', async () => {
+ givenStoredEntitlements([]);
+ billingEntitlementRepository.upsert.mockRejectedValueOnce(
+ new Error('database unavailable'),
+ );
+
+ await expect(syncEntitlements([])).rejects.toThrow('database unavailable');
+
+ expect(workspaceCacheService.invalidateAndRecompute).not.toHaveBeenCalled();
+ });
+
it('holds the lock for the whole transition', async () => {
givenStoredEntitlements([]);
diff --git a/packages/twenty-server/src/engine/core-modules/billing-webhook/services/billing-entitlement-sync.service.ts b/packages/twenty-server/src/engine/core-modules/billing-webhook/services/billing-entitlement-sync.service.ts
index 92da414ee37..c45c1af6296 100644
--- a/packages/twenty-server/src/engine/core-modules/billing-webhook/services/billing-entitlement-sync.service.ts
+++ b/packages/twenty-server/src/engine/core-modules/billing-webhook/services/billing-entitlement-sync.service.ts
@@ -12,6 +12,7 @@ import { UsageLimitQuotaService } from 'src/engine/core-modules/usage-limit/serv
import { RowLevelPermissionPredicateGroupService } from 'src/engine/metadata-modules/row-level-permission-predicate/services/row-level-permission-predicate-group.service';
import { InjectWorkspaceScopedRepository } from 'src/engine/twenty-orm/workspace-scoped-repository/inject-workspace-scoped-repository.decorator';
import { WorkspaceScopedRepository } from 'src/engine/twenty-orm/workspace-scoped-repository/workspace-scoped-repository';
+import { WorkspaceCacheService } from 'src/engine/workspace-cache/services/workspace-cache.service';
type EntitlementTransitionArgs = {
workspaceId: string;
@@ -33,6 +34,7 @@ export class BillingEntitlementSyncService {
private readonly rowLevelPermissionPredicateGroupService: RowLevelPermissionPredicateGroupService,
private readonly usageLimitQuotaService: UsageLimitQuotaService,
private readonly cacheLockService: CacheLockService,
+ private readonly workspaceCacheService: WorkspaceCacheService,
) {}
async syncEntitlements({
@@ -101,6 +103,10 @@ export class BillingEntitlementSyncService {
},
);
+ await this.workspaceCacheService.invalidateAndRecompute(workspaceId, [
+ 'billingEntitlements',
+ ]);
+
// The opposite order to the reset above, because the unsafe direction is
// reversed: predicates deleted while the row still grants RLS would leave
// row filtering on with nothing to filter by. Query-time filtering reads
diff --git a/packages/twenty-server/src/engine/core-modules/billing/billing.module.ts b/packages/twenty-server/src/engine/core-modules/billing/billing.module.ts
index 81131a21efb..f863039d0fe 100644
--- a/packages/twenty-server/src/engine/core-modules/billing/billing.module.ts
+++ b/packages/twenty-server/src/engine/core-modules/billing/billing.module.ts
@@ -40,6 +40,7 @@ import { BillingUsageCacheService } from 'src/engine/core-modules/billing/servic
import { BillingUsageService } from 'src/engine/core-modules/billing/services/billing-usage.service';
import { BillingService } from 'src/engine/core-modules/billing/services/billing.service';
import { ResourceCreditService } from 'src/engine/core-modules/billing/services/resource-credit.service';
+import { WorkspaceBillingEntitlementsCacheModule } from 'src/engine/core-modules/billing/workspace-billing-entitlements-cache.module';
import { WorkspaceCurrentBillingSubscriptionCacheService } from 'src/engine/core-modules/billing/services/workspace-current-billing-subscription-cache.service';
import { StripeModule } from 'src/engine/core-modules/billing/stripe/stripe.module';
import { CacheLockModule } from 'src/engine/core-modules/cache-lock/cache-lock.module';
@@ -66,6 +67,7 @@ import { WorkspaceCacheModule } from 'src/engine/workspace-cache/workspace-cache
MessageQueueModule,
PermissionsModule,
WorkspaceCacheModule,
+ WorkspaceBillingEntitlementsCacheModule,
WorkspaceDomainsModule,
TypeOrmModule.forFeature([
BillingSubscriptionEntity,
diff --git a/packages/twenty-server/src/engine/core-modules/billing/services/__tests__/workspace-billing-entitlements-cache.service.spec.ts b/packages/twenty-server/src/engine/core-modules/billing/services/__tests__/workspace-billing-entitlements-cache.service.spec.ts
new file mode 100644
index 00000000000..f466d63e741
--- /dev/null
+++ b/packages/twenty-server/src/engine/core-modules/billing/services/__tests__/workspace-billing-entitlements-cache.service.spec.ts
@@ -0,0 +1,77 @@
+/* @license Enterprise */
+
+import { Test } from '@nestjs/testing';
+import { DataSource } from 'typeorm';
+
+import { BillingEntitlementKey } from 'src/engine/core-modules/billing/enums/billing-entitlement-key.enum';
+import { WorkspaceBillingEntitlementsCacheService } from 'src/engine/core-modules/billing/services/workspace-billing-entitlements-cache.service';
+import { TwentyConfigService } from 'src/engine/core-modules/twenty-config/twenty-config.service';
+import { WorkspaceCacheRowsBatchLoader } from 'src/engine/workspace-cache/services/workspace-cache-rows-batch-loader';
+
+const WORKSPACE_ID = '20202020-1c25-4d02-bf25-6aeccf7ea419';
+
+describe('WorkspaceBillingEntitlementsCacheService', () => {
+ let service: WorkspaceBillingEntitlementsCacheService;
+ const twentyConfigService = { get: jest.fn() };
+
+ const createService = async (isBillingEnabled: boolean) => {
+ twentyConfigService.get.mockReturnValue(isBillingEnabled);
+ const module = await Test.createTestingModule({
+ providers: [
+ WorkspaceBillingEntitlementsCacheService,
+ { provide: TwentyConfigService, useValue: twentyConfigService },
+ ],
+ }).compile();
+
+ return module.get(WorkspaceBillingEntitlementsCacheService);
+ };
+
+ beforeEach(async () => {
+ service = await createService(true);
+ });
+
+ it('preserves both granted and revoked entitlements', () => {
+ expect(
+ service.computeForCache({
+ workspaceId: WORKSPACE_ID,
+ rows: {
+ billingEntitlement: [
+ { key: BillingEntitlementKey.USAGE_LIMIT, value: true },
+ { key: BillingEntitlementKey.RLS, value: false },
+ ],
+ },
+ }),
+ ).toEqual({
+ [BillingEntitlementKey.USAGE_LIMIT]: true,
+ [BillingEntitlementKey.RLS]: false,
+ });
+ });
+
+ it('returns an empty map for a workspace without entitlement rows', () => {
+ expect(
+ service.computeForCache({
+ workspaceId: WORKSPACE_ID,
+ rows: { billingEntitlement: [] },
+ }),
+ ).toEqual({});
+ });
+
+ it('loads no rows when billing entities are not registered', async () => {
+ service = await createService(false);
+ const dataSource = new DataSource({ type: 'postgres', entities: [] });
+ const rowsBatchLoader = new WorkspaceCacheRowsBatchLoader(
+ dataSource,
+ WORKSPACE_ID,
+ );
+
+ await rowsBatchLoader.loadRows([service.rowsRequirement]);
+
+ expect(service.rowsRequirement).toEqual({});
+ expect(
+ service.computeForCache({
+ workspaceId: WORKSPACE_ID,
+ rows: rowsBatchLoader.readRows(service.rowsRequirement),
+ }),
+ ).toEqual({});
+ });
+});
diff --git a/packages/twenty-server/src/engine/core-modules/billing/services/billing-subscription.service.ts b/packages/twenty-server/src/engine/core-modules/billing/services/billing-subscription.service.ts
index 539fdb5c3c6..7f7915d6de9 100644
--- a/packages/twenty-server/src/engine/core-modules/billing/services/billing-subscription.service.ts
+++ b/packages/twenty-server/src/engine/core-modules/billing/services/billing-subscription.service.ts
@@ -23,7 +23,6 @@ import {
} from 'src/engine/core-modules/billing/billing.exception';
import { BillingEntitlementDTO } from 'src/engine/core-modules/billing/dtos/billing-entitlement.dto';
import { BillingCustomerEntity } from 'src/engine/core-modules/billing/entities/billing-customer.entity';
-import { BillingEntitlementEntity } from 'src/engine/core-modules/billing/entities/billing-entitlement.entity';
import { BillingSubscriptionItemEntity } from 'src/engine/core-modules/billing/entities/billing-subscription-item.entity';
import { BillingSubscriptionEntity } from 'src/engine/core-modules/billing/entities/billing-subscription.entity';
import { BillingEntitlementKey } from 'src/engine/core-modules/billing/enums/billing-entitlement-key.enum';
@@ -54,8 +53,6 @@ export class BillingSubscriptionService {
private readonly coreEntityCacheService: CoreEntityCacheService,
private readonly stripeSubscriptionService: StripeSubscriptionService,
private readonly billingPriceService: BillingPriceService,
- @InjectWorkspaceScopedRepository(BillingEntitlementEntity)
- private readonly billingEntitlementRepository: WorkspaceScopedRepository<BillingEntitlementEntity>,
@InjectWorkspaceScopedRepository(BillingSubscriptionEntity)
private readonly billingSubscriptionRepository: WorkspaceScopedRepository<BillingSubscriptionEntity>,
// Stripe webhooks resolve by stripeCustomerId before any workspaceId
@@ -240,25 +237,18 @@ export class BillingSubscriptionService {
const isBillingEnabled = this.twentyConfigService.get('IS_BILLING_ENABLED');
const hasValidEnterprisePlan = this.enterprisePlanService.isValid();
- const entitlements = isBillingEnabled
- ? await this.billingEntitlementRepository.find(workspaceId)
- : [];
-
- const entitlementsByKey = entitlements.reduce(
- (acc, entitlement) => {
- acc[entitlement.key] = entitlement;
-
- return acc;
- },
- {} as Record<BillingEntitlementKey, BillingEntitlementEntity>,
- );
+ const { billingEntitlements } = isBillingEnabled
+ ? await this.workspaceCacheService.getOrRecompute(workspaceId, [
+ 'billingEntitlements',
+ ])
+ : { billingEntitlements: {} };
return Object.values(BillingEntitlementKey).map((key) => ({
key,
value: isEntitlementActive({
hasValidEnterprisePlan,
isBillingEnabled,
- stripeEntitlementValue: entitlementsByKey[key]?.value ?? false,
+ stripeEntitlementValue: billingEntitlements[key] ?? false,
}),
}));
}
@@ -267,12 +257,12 @@ export class BillingSubscriptionService {
workspaceId: string,
key: BillingEntitlementKey,
): Promise<boolean> {
- const entitlement = await this.billingEntitlementRepository.findOne(
- workspaceId,
- { where: { key, value: true } },
- );
+ const { billingEntitlements } =
+ await this.workspaceCacheService.getOrRecompute(workspaceId, [
+ 'billingEntitlements',
+ ]);
- return entitlement?.value ?? false;
+ return billingEntitlements[key] ?? false;
}
async getWorkspaceEntitlementValue(
diff --git a/packages/twenty-server/src/engine/core-modules/billing/services/workspace-billing-entitlements-cache.service.ts b/packages/twenty-server/src/engine/core-modules/billing/services/workspace-billing-entitlements-cache.service.ts
new file mode 100644
index 00000000000..1cf452e06de
--- /dev/null
+++ b/packages/twenty-server/src/engine/core-modules/billing/services/workspace-billing-entitlements-cache.service.ts
@@ -0,0 +1,47 @@
+/* @license Enterprise */
+
+import { Injectable } from '@nestjs/common';
+
+import { type BillingEntitlements } from 'src/engine/core-modules/billing/types/billing-entitlements.type';
+import { TwentyConfigService } from 'src/engine/core-modules/twenty-config/twenty-config.service';
+import { WorkspaceCache } from 'src/engine/workspace-cache/decorators/workspace-cache.decorator';
+import { WorkspaceCacheProvider } from 'src/engine/workspace-cache/interfaces/workspace-cache-provider.service';
+import { type WorkspaceCacheProviderContext } from 'src/engine/workspace-cache/types/workspace-cache-provider-context.type';
+import { type WorkspaceCacheRowsRequirement } from 'src/engine/workspace-cache/types/workspace-cache-rows-requirement.type';
+
+const BILLING_ENTITLEMENTS_ROWS_REQUIREMENT = {
+ billingEntitlement: ['key', 'value'],
+} as const satisfies WorkspaceCacheRowsRequirement;
+
+@Injectable()
+@WorkspaceCache('billingEntitlements', { packingPonderation: 1 })
+export class WorkspaceBillingEntitlementsCacheService extends WorkspaceCacheProvider<BillingEntitlements> {
+ override readonly rowsRequirement: WorkspaceCacheRowsRequirement;
+
+ constructor(private readonly twentyConfigService: TwentyConfigService) {
+ super();
+
+ this.rowsRequirement = this.twentyConfigService.get('IS_BILLING_ENABLED')
+ ? BILLING_ENTITLEMENTS_ROWS_REQUIREMENT
+ : {};
+ }
+
+ computeForCache({
+ rows,
+ }: WorkspaceCacheProviderContext<
+ typeof BILLING_ENTITLEMENTS_ROWS_REQUIREMENT
+ >): BillingEntitlements {
+ if (!this.twentyConfigService.get('IS_BILLING_ENABLED')) {
+ return {};
+ }
+
+ return rows.billingEntitlement.reduce<BillingEntitlements>(
+ (entitlementsByKey, { key, value }) => {
+ entitlementsByKey[key] = value;
+
+ return entitlementsByKey;
+ },
+ {},
+ );
+ }
+}
diff --git a/packages/twenty-server/src/engine/core-modules/billing/types/billing-entitlements.type.ts b/packages/twenty-server/src/engine/core-modules/billing/types/billing-entitlements.type.ts
new file mode 100644
index 00000000000..b7a576c0891
--- /dev/null
+++ b/packages/twenty-server/src/engine/core-modules/billing/types/billing-entitlements.type.ts
@@ -0,0 +1,7 @@
+/* @license Enterprise */
+
+import { type BillingEntitlementKey } from 'src/engine/core-modules/billing/enums/billing-entitlement-key.enum';
+
+export type BillingEntitlements = Partial<
+ Record<BillingEntitlementKey, boolean>
+>;
diff --git a/packages/twenty-server/src/engine/core-modules/billing/workspace-billing-entitlements-cache.module.ts b/packages/twenty-server/src/engine/core-modules/billing/workspace-billing-entitlements-cache.module.ts
new file mode 100644
index 00000000000..5a30021bd1f
--- /dev/null
+++ b/packages/twenty-server/src/engine/core-modules/billing/workspace-billing-entitlements-cache.module.ts
@@ -0,0 +1,10 @@
+/* @license Enterprise */
+
+import { Module } from '@nestjs/common';
+
+import { WorkspaceBillingEntitlementsCacheService } from 'src/engine/core-modules/billing/services/workspace-billing-entitlements-cache.service';
+
+@Module({
+ providers: [WorkspaceBillingEntitlementsCacheService],
+})
+export class WorkspaceBillingEntitlementsCacheModule {}
diff --git a/packages/twenty-server/src/engine/twenty-orm/datasource/workspace-data-source.service.ts b/packages/twenty-server/src/engine/twenty-orm/datasource/workspace-data-source.service.ts
index c6fda70e984..5e122a473c0 100644
--- a/packages/twenty-server/src/engine/twenty-orm/datasource/workspace-data-source.service.ts
+++ b/packages/twenty-server/src/engine/twenty-orm/datasource/workspace-data-source.service.ts
@@ -119,6 +119,7 @@ export class WorkspaceDataSourceService
workspaceContext.flatRowLevelPermissionPredicateGroupMaps,
objectIdByNameSingular: workspaceContext.objectIdByNameSingular,
featureFlagsMap: workspaceContext.featureFlagsMap,
+ billingEntitlements: workspaceContext.billingEntitlements,
isRecordSharingEnabled: workspaceContext.isRecordSharingEnabled,
userWorkspaceRoleMap: workspaceContext.userWorkspaceRoleMap,
apiKeyRoleMap: workspaceContext.apiKeyRoleMap,
diff --git a/packages/twenty-server/src/engine/twenty-orm/interfaces/workspace-internal-context.interface.ts b/packages/twenty-server/src/engine/twenty-orm/interfaces/workspace-internal-context.interface.ts
index 3a7dfd4ac08..5ca82777cce 100644
--- a/packages/twenty-server/src/engine/twenty-orm/interfaces/workspace-internal-context.interface.ts
+++ b/packages/twenty-server/src/engine/twenty-orm/interfaces/workspace-internal-context.interface.ts
@@ -1,6 +1,7 @@
import { type DataSource } from 'typeorm';
import { type FeatureFlagKey } from 'twenty-shared/types';
+import { type BillingEntitlements } from 'src/engine/core-modules/billing/types/billing-entitlements.type';
import { type FlatEntityMaps } from 'src/engine/metadata-modules/flat-entity/types/flat-entity-maps.type';
import { type OrmFlatFieldMetadata } from 'src/engine/metadata-modules/flat-field-metadata/types/orm-flat-field-metadata.type';
import { type FlatIndexMetadata } from 'src/engine/metadata-modules/flat-index-metadata/types/flat-index-metadata.type';
@@ -19,6 +20,7 @@ export interface WorkspaceInternalContext {
flatRowLevelPermissionPredicateGroupMaps: FlatRowLevelPermissionPredicateGroupMaps;
objectIdByNameSingular: Record<string, string>;
featureFlagsMap: Record<FeatureFlagKey, boolean>;
+ billingEntitlements: BillingEntitlements;
isRecordSharingEnabled: boolean;
userWorkspaceRoleMap: UserWorkspaceRoleMap;
apiKeyRoleMap: Record<string, string>;
diff --git a/packages/twenty-server/src/engine/twenty-orm/storage/orm-workspace-context.storage.ts b/packages/twenty-server/src/engine/twenty-orm/storage/orm-workspace-context.storage.ts
index 18fc4512e13..17e6ae0f1e1 100644
--- a/packages/twenty-server/src/engine/twenty-orm/storage/orm-workspace-context.storage.ts
+++ b/packages/twenty-server/src/engine/twenty-orm/storage/orm-workspace-context.storage.ts
@@ -6,6 +6,7 @@ import {
} from 'twenty-shared/types';
import { type WorkspaceAuthContext } from 'src/engine/core-modules/auth/types/workspace-auth-context.type';
+import { type BillingEntitlements } from 'src/engine/core-modules/billing/types/billing-entitlements.type';
import { type FlatEntityMaps } from 'src/engine/metadata-modules/flat-entity/types/flat-entity-maps.type';
import { type OrmFlatFieldMetadata } from 'src/engine/metadata-modules/flat-field-metadata/types/orm-flat-field-metadata.type';
import { type FlatIndexMetadata } from 'src/engine/metadata-modules/flat-index-metadata/types/flat-index-metadata.type';
@@ -21,6 +22,7 @@ export type ORMWorkspaceContext = {
flatIndexMaps: FlatEntityMaps<FlatIndexMetadata>;
objectIdByNameSingular: Record<string, string>;
featureFlagsMap: Record<FeatureFlagKey, boolean>;
+ billingEntitlements: BillingEntitlements;
isRecordSharingEnabled: boolean;
permissionsPerRoleId: ObjectsPermissionsByRoleId;
userWorkspaceRoleMap: UserWorkspaceRoleMap;
diff --git a/packages/twenty-server/src/engine/twenty-orm/twenty-orm.module.ts b/packages/twenty-server/src/engine/twenty-orm/twenty-orm.module.ts
index 48d8c71bf9f..92fd20e241e 100644
--- a/packages/twenty-server/src/engine/twenty-orm/twenty-orm.module.ts
+++ b/packages/twenty-server/src/engine/twenty-orm/twenty-orm.module.ts
@@ -2,6 +2,7 @@ import { Global, Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { TypeORMModule } from 'src/database/typeorm/typeorm.module';
+import { WorkspaceBillingEntitlementsCacheModule } from 'src/engine/core-modules/billing/workspace-billing-entitlements-cache.module';
import { ApplicationEntity } from 'src/engine/core-modules/application/application.entity';
import { FeatureFlagEntity } from 'src/engine/core-modules/feature-flag/feature-flag.entity';
import { TwentyConfigModule } from 'src/engine/core-modules/twenty-config/twenty-config.module';
@@ -33,6 +34,7 @@ import { WorkspaceEventEmitterModule } from 'src/engine/workspace-event-emitter/
WorkspaceCacheStorageModule,
WorkspaceManyOrAllFlatEntityMapsCacheModule,
WorkspaceFeatureFlagsMapCacheModule,
+ WorkspaceBillingEntitlementsCacheModule,
TwentyConfigModule,
WorkspaceEventEmitterModule,
WorkspaceCacheModule,
diff --git a/packages/twenty-server/src/engine/twenty-orm/workspace-orm.manager.ts b/packages/twenty-server/src/engine/twenty-orm/workspace-orm.manager.ts
index 658ecdf1371..58f077e0278 100644
--- a/packages/twenty-server/src/engine/twenty-orm/workspace-orm.manager.ts
+++ b/packages/twenty-server/src/engine/twenty-orm/workspace-orm.manager.ts
@@ -109,6 +109,7 @@ export class WorkspaceOrmManager {
flatFieldMetadataMapsOrm,
flatIndexMaps,
featureFlagsMap,
+ billingEntitlements,
rolesPermissions: permissionsPerRoleId,
userWorkspaceRoleMap,
apiKeyRoleMap,
@@ -119,6 +120,7 @@ export class WorkspaceOrmManager {
'flatFieldMetadataMapsOrm',
'flatIndexMaps',
'featureFlagsMap',
+ 'billingEntitlements',
'rolesPermissions',
'userWorkspaceRoleMap',
'apiKeyRoleMap',
@@ -138,6 +140,7 @@ export class WorkspaceOrmManager {
flatRowLevelPermissionPredicateGroupMaps,
objectIdByNameSingular,
featureFlagsMap,
+ billingEntitlements,
isRecordSharingEnabled:
await this.recordSharingFeatureService.isRecordSharingEnabled(
workspaceId,
@@ -153,11 +156,15 @@ export class WorkspaceOrmManager {
): Promise<ORMWorkspaceContext> {
const workspaceId = authContext.workspace.id;
- const { flatObjectMetadataMaps, flatFieldMetadataMapsOrm } =
- await this.workspaceCacheService.getOrRecompute(workspaceId, [
- 'flatObjectMetadataMaps',
- 'flatFieldMetadataMapsOrm',
- ]);
+ const {
+ flatObjectMetadataMaps,
+ flatFieldMetadataMapsOrm,
+ billingEntitlements,
+ } = await this.workspaceCacheService.getOrRecompute(workspaceId, [
+ 'flatObjectMetadataMaps',
+ 'flatFieldMetadataMapsOrm',
+ 'billingEntitlements',
+ ]);
const { idByNameSingular: objectIdByNameSingular } =
buildObjectIdByNameMaps(flatObjectMetadataMaps);
@@ -183,6 +190,7 @@ export class WorkspaceOrmManager {
},
objectIdByNameSingular,
featureFlagsMap: {} as ORMWorkspaceContext['featureFlagsMap'],
+ billingEntitlements,
isRecordSharingEnabled: false,
permissionsPerRoleId: {},
userWorkspaceRoleMap: {},
diff --git a/packages/twenty-server/src/engine/workspace-cache/constants/all-workspace-cache-entity-by-name.constant.ts b/packages/twenty-server/src/engine/workspace-cache/constants/all-workspace-cache-entity-by-name.constant.ts
index 97989b5bd68..6bf1df3f6c6 100644
--- a/packages/twenty-server/src/engine/workspace-cache/constants/all-workspace-cache-entity-by-name.constant.ts
+++ b/packages/twenty-server/src/engine/workspace-cache/constants/all-workspace-cache-entity-by-name.constant.ts
@@ -1,5 +1,6 @@
import { ApiKeyEntity } from 'src/engine/core-modules/api-key/api-key.entity';
import { ApplicationEntity } from 'src/engine/core-modules/application/application.entity';
+import { BillingEntitlementEntity } from 'src/engine/core-modules/billing/entities/billing-entitlement.entity';
import { FeatureFlagEntity } from 'src/engine/core-modules/feature-flag/feature-flag.entity';
import { UsageLimitEntity } from 'src/engine/core-modules/usage-limit/usage-limit.entity';
import { ALL_METADATA_ENTITY_BY_METADATA_NAME } from 'src/engine/metadata-modules/flat-entity/constant/all-metadata-entity-by-metadata-name.constant';
@@ -11,5 +12,6 @@ export const ALL_WORKSPACE_CACHE_ENTITY_BY_NAME = {
indexFieldMetadata: IndexFieldMetadataEntity,
apiKey: ApiKeyEntity,
featureFlag: FeatureFlagEntity,
+ billingEntitlement: BillingEntitlementEntity,
usageLimit: UsageLimitEntity,
} as const;
diff --git a/packages/twenty-server/src/engine/workspace-cache/types/workspace-cache-key.type.ts b/packages/twenty-server/src/engine/workspace-cache/types/workspace-cache-key.type.ts
index 58ddb9e13be..7aa085af324 100644
--- a/packages/twenty-server/src/engine/workspace-cache/types/workspace-cache-key.type.ts
+++ b/packages/twenty-server/src/engine/workspace-cache/types/workspace-cache-key.type.ts
@@ -12,6 +12,7 @@ import { type FlatApiKey } from 'src/engine/core-modules/api-key/types/flat-api-
import { type ApplicationVariableCacheMaps } from 'src/engine/core-modules/application/application-variable/types/application-variable-cache-maps.type';
import { type FlatApplicationCacheMaps } from 'src/engine/core-modules/application/types/flat-application-cache-maps.type';
import { type CurrentBillingSubscription } from 'src/engine/core-modules/billing/types/flat-billing-subscription.type';
+import { type BillingEntitlements } from 'src/engine/core-modules/billing/types/billing-entitlements.type';
import { type FlatWorkspaceMemberMaps } from 'src/engine/core-modules/user/types/flat-workspace-member-maps.type';
import { type WorkflowAutomatedTriggerMaps } from 'src/engine/core-modules/workflow/types/workflow-automated-trigger-maps.type';
@@ -38,6 +39,7 @@ export type AdditionalCacheDataMaps = {
applicationVariableMaps: ApplicationVariableCacheMaps;
graphQLResolverNameMap: Record<string, ResolverNameMapEntry>;
currentBillingSubscription: CurrentBillingSubscription;
+ billingEntitlements: BillingEntitlements;
workflowAutomatedTriggerMaps: WorkflowAutomatedTriggerMaps;
usageLimits: UsageLimits;
};
diff --git a/packages/twenty-server/test/integration/workspace-cache/billing-entitlements-cache.integration-spec.ts b/packages/twenty-server/test/integration/workspace-cache/billing-entitlements-cache.integration-spec.ts
new file mode 100644
index 00000000000..860f65cf191
--- /dev/null
+++ b/packages/twenty-server/test/integration/workspace-cache/billing-entitlements-cache.integration-spec.ts
@@ -0,0 +1,218 @@
+import { isDefined } from 'twenty-shared/utils';
+
+import { BillingEntitlementKey } from 'src/engine/core-modules/billing/enums/billing-entitlement-key.enum';
+import { type BillingSubscriptionService } from 'src/engine/core-modules/billing/services/billing-subscription.service';
+import { type BillingUsageLimitEntitlementProvider } from 'src/engine/core-modules/billing/services/billing-usage-limit-entitlement-provider.service';
+import { type EnterprisePlanService } from 'src/engine/core-modules/enterprise/services/enterprise-plan.service';
+import { buildSystemAuthContext } from 'src/engine/twenty-orm/utils/build-system-auth-context.util';
+import { type WorkspaceOrmManager } from 'src/engine/twenty-orm/workspace-orm.manager';
+import { type WorkspaceCacheService } from 'src/engine/workspace-cache/services/workspace-cache.service';
+
+import {
+ getSeededBillingWorkspaceId,
+ TEST_STRIPE_CUSTOMER_ID,
+} from 'test/integration/billing/utils/billing-credit-fixtures.util';
+import { getAppProviderByClassName } from 'test/integration/utils/get-app-provider-by-class-name.util';
+
+const isBillingEnabled = process.env.IS_BILLING_ENABLED === 'true';
+
+(isBillingEnabled ? describe.skip : describe)(
+ 'Billing entitlement cache without billing',
+ () => {
+ const workspaceId = '20202020-1c25-4d02-bf25-6aeccf7ea419';
+
+ it('returns an empty map without loading unregistered billing entities', async () => {
+ const workspaceCacheService =
+ getAppProviderByClassName<WorkspaceCacheService>(
+ 'WorkspaceCacheService',
+ );
+
+ await workspaceCacheService.invalidateAndRecompute(workspaceId, [
+ 'billingEntitlements',
+ ]);
+ expect(
+ await workspaceCacheService.getOrRecompute(workspaceId, [
+ 'billingEntitlements',
+ ]),
+ ).toEqual({ billingEntitlements: {} });
+ });
+
+ it.each([false, true])(
+ 'creates a repository with empty entitlements when billing is disabled (lite: %s)',
+ async (lite) => {
+ const workspaceOrmManager =
+ getAppProviderByClassName<WorkspaceOrmManager>('WorkspaceOrmManager');
+
+ await workspaceOrmManager.executeInWorkspaceContext(
+ () => {
+ const repository = workspaceOrmManager.getRepository('company');
+
+ expect(repository.internalContext.billingEntitlements).toEqual({});
+ },
+ buildSystemAuthContext(workspaceId),
+ { lite },
+ );
+ },
+ );
+ },
+);
+
+(isBillingEnabled ? describe : describe.skip)(
+ 'Billing entitlement cache with billing',
+ () => {
+ let workspaceId: string;
+ let originalEntitlements: { value: boolean }[];
+ let workspaceCacheService: WorkspaceCacheService;
+ let subscriptionService: BillingSubscriptionService;
+ let usageLimitProvider: BillingUsageLimitEntitlementProvider;
+ let enterprisePlanService: EnterprisePlanService;
+
+ const setUsageLimitEntitlement = async (value: boolean) => {
+ await global.testDataSource.query(
+ `INSERT INTO core."billingEntitlement" ("workspaceId", key, value, "stripeCustomerId")
+ VALUES ($1, $2, $3, $4)
+ ON CONFLICT ("workspaceId", key) DO UPDATE SET value = EXCLUDED.value`,
+ [
+ workspaceId,
+ BillingEntitlementKey.USAGE_LIMIT,
+ value,
+ TEST_STRIPE_CUSTOMER_ID,
+ ],
+ );
+ };
+
+ const refreshEntitlements = () =>
+ workspaceCacheService.invalidateAndRecompute(workspaceId, [
+ 'billingEntitlements',
+ ]);
+
+ beforeAll(async () => {
+ workspaceId = await getSeededBillingWorkspaceId();
+ workspaceCacheService = getAppProviderByClassName<WorkspaceCacheService>(
+ 'WorkspaceCacheService',
+ );
+ subscriptionService =
+ getAppProviderByClassName<BillingSubscriptionService>(
+ 'BillingSubscriptionService',
+ );
+ usageLimitProvider =
+ getAppProviderByClassName<BillingUsageLimitEntitlementProvider>(
+ 'BillingUsageLimitEntitlementProvider',
+ );
+ enterprisePlanService = getAppProviderByClassName<EnterprisePlanService>(
+ 'EnterprisePlanService',
+ );
+ originalEntitlements = await global.testDataSource.query(
+ 'SELECT value FROM core."billingEntitlement" WHERE "workspaceId" = $1 AND key = $2',
+ [workspaceId, BillingEntitlementKey.USAGE_LIMIT],
+ );
+ });
+
+ beforeEach(async () => {
+ jest.spyOn(enterprisePlanService, 'isValid').mockReturnValue(true);
+ await setUsageLimitEntitlement(true);
+ await refreshEntitlements();
+ });
+
+ afterEach(() => {
+ jest.restoreAllMocks();
+ });
+
+ afterAll(async () => {
+ const originalEntitlement = originalEntitlements[0];
+
+ if (isDefined(originalEntitlement)) {
+ await setUsageLimitEntitlement(originalEntitlement.value);
+ } else {
+ await global.testDataSource.query(
+ 'DELETE FROM core."billingEntitlement" WHERE "workspaceId" = $1 AND key = $2',
+ [workspaceId, BillingEntitlementKey.USAGE_LIMIT],
+ );
+ }
+ await refreshEntitlements();
+ });
+
+ it('reuses cached rows until invalidation, then exposes a revoked entitlement to all readers', async () => {
+ expect(
+ await usageLimitProvider.hasIntraWorkspaceLimitEntitlement(workspaceId),
+ ).toBe(true);
+ await setUsageLimitEntitlement(false);
+ expect(
+ await usageLimitProvider.hasIntraWorkspaceLimitEntitlement(workspaceId),
+ ).toBe(true);
+
+ await refreshEntitlements();
+
+ expect(
+ await usageLimitProvider.hasIntraWorkspaceLimitEntitlement(workspaceId),
+ ).toBe(false);
+ expect(
+ await subscriptionService.getWorkspaceEntitlements(workspaceId),
+ ).toContainEqual({
+ key: BillingEntitlementKey.USAGE_LIMIT,
+ value: false,
+ });
+ });
+
+ it.each([false, true])(
+ 'keeps the repository snapshot until a new workspace context is created (lite: %s)',
+ async (lite) => {
+ const workspaceOrmManager =
+ getAppProviderByClassName<WorkspaceOrmManager>('WorkspaceOrmManager');
+ const authContext = buildSystemAuthContext(workspaceId);
+
+ await workspaceOrmManager.executeInWorkspaceContext(
+ async () => {
+ const repository = workspaceOrmManager.getRepository('company');
+ const snapshot = repository.internalContext.billingEntitlements;
+
+ expect(snapshot[BillingEntitlementKey.USAGE_LIMIT]).toBe(true);
+ await setUsageLimitEntitlement(false);
+ await refreshEntitlements();
+
+ expect(snapshot[BillingEntitlementKey.USAGE_LIMIT]).toBe(true);
+ expect(
+ workspaceOrmManager.getRepository('company').internalContext
+ .billingEntitlements,
+ ).toBe(snapshot);
+ },
+ authContext,
+ { lite },
+ );
+
+ await workspaceOrmManager.executeInWorkspaceContext(
+ () => {
+ const repository = workspaceOrmManager.getRepository('company');
+
+ expect(
+ repository.internalContext.billingEntitlements[
+ BillingEntitlementKey.USAGE_LIMIT
+ ],
+ ).toBe(false);
+ },
+ authContext,
+ { lite },
+ );
+ },
+ );
+
+ it('evaluates license validity again while the entitlement remains cached', async () => {
+ expect(
+ await usageLimitProvider.hasIntraWorkspaceLimitEntitlement(workspaceId),
+ ).toBe(true);
+ jest.spyOn(enterprisePlanService, 'isValid').mockReturnValue(false);
+ expect(
+ await usageLimitProvider.hasIntraWorkspaceLimitEntitlement(workspaceId),
+ ).toBe(false);
+ });
+
+ it('propagates a cache outage rather than treating it as a missing entitlement', async () => {
+ jest
+ .spyOn(workspaceCacheService, 'getOrRecompute')
+ .mockRejectedValueOnce(new Error('cache unavailable'));
+ await expect(
+ usageLimitProvider.hasIntraWorkspaceLimitEntitlement(workspaceId),
+ ).rejects.toThrow('cache unavailable');
+ });
+ },
+);