The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
fix(enterprise): keep self-hosted licenses valid while Stripe retries a failed payment (#25515)
Marie5d0914ca496d
diff --git a/packages/twenty-front/src/pages/settings/enterprise/SettingsEnterprise.tsx b/packages/twenty-front/src/pages/settings/enterprise/SettingsEnterprise.tsxindex 379abbeb8df..5a9ae52a463 100644--- a/packages/twenty-front/src/pages/settings/enterprise/SettingsEnterprise.tsx+++ b/packages/twenty-front/src/pages/settings/enterprise/SettingsEnterprise.tsx@@ -62,9 +62,16 @@ type SubscriptionStatus = {isCancellationScheduled: boolean;};-const StyledStatusDot = styled.div<{ isActive: boolean }>`- background-color: ${({ isActive }) =>- isActive ? themeCssVariables.color.green : themeCssVariables.color.red};+type StatusDotVariant = 'active' | 'warning' | 'inactive';++const STATUS_DOT_COLOR: Record<StatusDotVariant, string> = {+ active: themeCssVariables.color.green,+ warning: themeCssVariables.color.orange,+ inactive: themeCssVariables.color.red,+};++const StyledStatusDot = styled.div<{ variant: StatusDotVariant }>`+ background-color: ${({ variant }) => STATUS_DOT_COLOR[variant]};border-radius: 50%;corner-shape: round;height: 8px;@@ -232,6 +239,14 @@ export const SettingsEnterprise = ({? new Date(subscriptionStatus.currentPeriodEnd): null;+ const licenseExpiresAt = isDefined(subscriptionStatus?.expiresAt)+ ? new Date(subscriptionStatus.expiresAt)+ : null;++ const licenseExpiresAtDate = isDefined(licenseExpiresAt)+ ? licenseExpiresAt.toLocaleDateString()+ : '';+const cancelAtDate =isCancelScheduled && isDefined(cancelAt)? cancelAt.toLocaleDateString()@@ -686,7 +701,7 @@ export const SettingsEnterprise = ({Icon={IconCheck}currentValue={<StyledStatusContainer>- <StyledStatusDot isActive={true} />+ <StyledStatusDot variant="active" />{stripeStatus === 'trialing' ? (<Trans>Trial</Trans>) : (@@ -746,7 +761,9 @@ export const SettingsEnterprise = ({Icon={IconCheck}currentValue={<StyledStatusContainer>- <StyledStatusDot isActive={!isCancelScheduled} />+ <StyledStatusDot+ variant={isCancelScheduled ? 'inactive' : 'active'}+ />{isCancelScheduled ? (<Trans>Cancelling</Trans>) : stripeStatus === 'trialing' ? (@@ -823,7 +840,7 @@ export const SettingsEnterprise = ({Icon={IconCheck}currentValue={<StyledStatusContainer>- <StyledStatusDot isActive={false} />+ <StyledStatusDot variant="inactive" /><Trans>Canceled</Trans></StyledStatusContainer>}@@ -865,7 +882,11 @@ export const SettingsEnterprise = ({<Section><H2Titletitle={t`Enterprise License`}- description={t`There is a payment issue with your subscription. Please update your payment method.`}+ description={+ hasValidityToken+ ? t`A payment on your subscription failed. Your enterprise features stay active while we retry it.`+ : t`There is a payment issue with your subscription. Your enterprise features are disabled. Settle the outstanding invoice to restore them, before the subscription is cancelled: a cancelled subscription cannot be reactivated and you would need to start a new one.`+ }/><SubscriptionInfoContainer><SubscriptionInfoRowContainer@@ -873,17 +894,47 @@ export const SettingsEnterprise = ({Icon={IconCheck}currentValue={<StyledStatusContainer>- <StyledStatusDot isActive={false} />+ <StyledStatusDot+ variant={hasValidityToken ? 'warning' : 'inactive'}+ /><Trans>Payment issue</Trans></StyledStatusContainer>}/>+ {hasValidityToken && isDefined(licenseExpiresAt) && (+ <SubscriptionInfoRowContainer+ label={t`Features active until`}+ Icon={IconCalendarRepeat}+ currentValue={licenseExpiresAtDate}+ />+ )}+ <SubscriptionInfoRowContainer+ label={t`Billing history`}+ Icon={IconCreditCard}+ currentValue={+ <Button+ title={t`View invoices`}+ variant="secondary"+ size="small"+ onClick={openBillingPortal}+ />+ }+ /></SubscriptionInfoContainer>+ {hasValidityToken && isDefined(licenseExpiresAt) && (+ <StyledCancellationNotice>+ {t`Update your payment method before ${licenseExpiresAtDate} to avoid losing access.`}+ </StyledCancellationNotice>+ )}</Section><Section><H2Titletitle={t`Update payment method`}- description={t`Fix the payment issue to keep your enterprise features active.`}+ description={+ hasValidityToken+ ? t`Fix the payment issue to keep your enterprise features active.`+ : t`Fix the payment issue to restore your enterprise features.`+ }/><ButtonIcon={IconCreditCard}@@ -911,7 +962,7 @@ export const SettingsEnterprise = ({Icon={IconCheck}currentValue={<StyledStatusContainer>- <StyledStatusDot isActive={false} />+ <StyledStatusDot variant="inactive" /><Trans>Incomplete</Trans></StyledStatusContainer>}diff --git a/packages/twenty-website/.env.example b/packages/twenty-website/.env.exampleindex ee27185e157..114263f5366 100644--- a/packages/twenty-website/.env.example+++ b/packages/twenty-website/.env.example@@ -33,7 +33,7 @@ STRIPE_ENTERPRISE_YEARLY_PRICE_ID=ENTERPRISE_JWT_PRIVATE_KEY=ENTERPRISE_JWT_PUBLIC_KEY=-# Optional: enterprise validity token lifetime in days (default 30).+# Optional: enterprise validity token lifetime in days (default 7).# ENTERPRISE_VALIDITY_TOKEN_DURATION_DAYS=# Shared secret guarding the internal enterprise key reissue endpointdiff --git a/packages/twenty-website/src/app/api/enterprise/validate/route.ts b/packages/twenty-website/src/app/api/enterprise/validate/route.tsindex f0b26fb2ad8..5ce02e3564b 100644--- a/packages/twenty-website/src/app/api/enterprise/validate/route.ts+++ b/packages/twenty-website/src/app/api/enterprise/validate/route.ts@@ -4,21 +4,23 @@ import {ENTERPRISE_RATE_LIMIT_CODE,EnterpriseInstanceType,evaluateValidityTokenEmissionRateLimit,+ findNextPaymentAttempt,getAutoReleaseDays,getEnterpriseConfigError,getStripeClient,getSubscriptionCurrentPeriodEnd,parseInstanceType,resolveServerBinding,+ resolveSubscriptionLicenseState,SERVER_BINDING_OUTCOME,signValidityToken,+ SUBSCRIPTION_GRACE_STATUSES,+ SUBSCRIPTION_LICENSE_OUTCOME,verifyEnterpriseKey,} from '@/platform/enterprise';export const dynamic = 'force-dynamic';-const ACTIVATABLE_STATUSES = new Set(['active', 'trialing']);-type InstanceMetadata = {serverId?: string;instanceType?: EnterpriseInstanceType;@@ -65,7 +67,21 @@ export async function POST(request: Request) {const stripe = getStripeClient();const subscription = await stripe.subscriptions.retrieve(payload.sub);- if (!ACTIVATABLE_STATUSES.has(subscription.status)) {+ const nextPaymentAttempt = SUBSCRIPTION_GRACE_STATUSES.has(+ subscription.status,+ )+ ? await findNextPaymentAttempt({+ stripe,+ subscriptionId: subscription.id,+ })+ : null;++ const licenseState = resolveSubscriptionLicenseState({+ status: subscription.status,+ nextPaymentAttempt,+ });++ if (licenseState.outcome === SUBSCRIPTION_LICENSE_OUTCOME.REJECTED) {return NextResponse.json({ error: 'Subscription is not active', status: subscription.status },{ status: 403 },@@ -130,6 +146,7 @@ export async function POST(request: Request) {const validityToken = signValidityToken(payload.sub, {subscriptionCancelAt: effectiveCancelAt,+ graceExpiresAt: licenseState.graceExpiresAt,});return NextResponse.json({diff --git a/packages/twenty-website/src/platform/enterprise/find-next-payment-attempt.test.ts b/packages/twenty-website/src/platform/enterprise/find-next-payment-attempt.test.tsnew file mode 100644index 00000000000..09337c9377a--- /dev/null+++ b/packages/twenty-website/src/platform/enterprise/find-next-payment-attempt.test.ts@@ -0,0 +1,63 @@+import type Stripe from 'stripe';++import { findNextPaymentAttempt } from './find-next-payment-attempt';++const RETRY_AT = 1786363200;++const stripeWithOpenInvoices = (invoices: unknown[]) => {+ const list = jest.fn().mockResolvedValue({ data: invoices });++ return { stripe: { invoices: { list } } as unknown as Stripe, list };+};++describe('findNextPaymentAttempt', () => {+ it('lists the open invoices of the subscription', async () => {+ const { stripe, list } = stripeWithOpenInvoices([]);++ await findNextPaymentAttempt({ stripe, subscriptionId: 'sub_123' });++ expect(list).toHaveBeenCalledWith({+ subscription: 'sub_123',+ status: 'open',+ limit: 100,+ });+ });++ it('finds the retry on an older open invoice when a newer one carries none', async () => {+ const { stripe } = stripeWithOpenInvoices([+ { next_payment_attempt: null },+ { next_payment_attempt: RETRY_AT },+ ]);++ await expect(+ findNextPaymentAttempt({ stripe, subscriptionId: 'sub_123' }),+ ).resolves.toBe(RETRY_AT);+ });++ it('returns the latest retry when several invoices are being retried', async () => {+ const { stripe } = stripeWithOpenInvoices([+ { next_payment_attempt: RETRY_AT },+ { next_payment_attempt: RETRY_AT + 3600 },+ ]);++ await expect(+ findNextPaymentAttempt({ stripe, subscriptionId: 'sub_123' }),+ ).resolves.toBe(RETRY_AT + 3600);+ });++ it('returns null when no open invoice has a retry scheduled', async () => {+ const { stripe } = stripeWithOpenInvoices([{ next_payment_attempt: null }]);++ await expect(+ findNextPaymentAttempt({ stripe, subscriptionId: 'sub_123' }),+ ).resolves.toBeNull();+ });++ it('returns null when the subscription has no open invoice', async () => {+ const { stripe } = stripeWithOpenInvoices([]);++ await expect(+ findNextPaymentAttempt({ stripe, subscriptionId: 'sub_123' }),+ ).resolves.toBeNull();+ });+});diff --git a/packages/twenty-website/src/platform/enterprise/find-next-payment-attempt.ts b/packages/twenty-website/src/platform/enterprise/find-next-payment-attempt.tsnew file mode 100644index 00000000000..d01ac1f28ec--- /dev/null+++ b/packages/twenty-website/src/platform/enterprise/find-next-payment-attempt.ts@@ -0,0 +1,21 @@+import type Stripe from 'stripe';++export async function findNextPaymentAttempt({+ stripe,+ subscriptionId,+}: {+ stripe: Stripe;+ subscriptionId: string;+}): Promise<number | null> {+ const openInvoices = await stripe.invoices.list({+ subscription: subscriptionId,+ status: 'open',+ limit: 100,+ });++ const scheduledAttempts = openInvoices.data+ .map((invoice) => invoice.next_payment_attempt)+ .filter((attempt): attempt is number => typeof attempt === 'number');++ return scheduledAttempts.length > 0 ? Math.max(...scheduledAttempts) : null;+}diff --git a/packages/twenty-website/src/platform/enterprise/index.ts b/packages/twenty-website/src/platform/enterprise/index.tsindex 2a15f82e4c0..4c6d1780144 100644--- a/packages/twenty-website/src/platform/enterprise/index.ts+++ b/packages/twenty-website/src/platform/enterprise/index.ts@@ -3,6 +3,8 @@ export { getEnterprisePriceId } from './enterprise-price-id';export { getLicenseeFromStripeCustomer } from './get-licensee-from-stripe-customer';export { getStripeClient } from './stripe-client';export { getSubscriptionCurrentPeriodEnd } from './subscription-current-period-end';+export { findNextPaymentAttempt } from './find-next-payment-attempt';+export { SUBSCRIPTION_GRACE_STATUSES } from './subscription-grace-statuses';export {ENTERPRISE_INSTANCE_TYPE,type EnterpriseInstanceType,@@ -20,6 +22,15 @@ export { VALIDITY_TOKEN_EMISSIONS_KEY_BY_INSTANCE_TYPE } from './validity-token-export { ENTERPRISE_RATE_LIMIT_CODE } from './enterprise-rate-limit-code';export { type StripeMetadata } from './stripe-metadata';export { getAutoReleaseDays } from './get-auto-release-days';+export {+ SUBSCRIPTION_LICENSE_OUTCOME,+ type SubscriptionLicenseOutcome,+} from './subscription-license-outcome';+export {+ resolveSubscriptionLicenseState,+ type ResolveSubscriptionLicenseStateInput,+ type SubscriptionLicenseState,+} from './resolve-subscription-license-state';export { getReleaseLimitPerWindow } from './get-release-limit-per-window';export { getValidityTokenEmissionLimitPerWindow } from './get-validity-token-emission-limit-per-window';export {diff --git a/packages/twenty-website/src/platform/enterprise/resolve-subscription-license-state.test.ts b/packages/twenty-website/src/platform/enterprise/resolve-subscription-license-state.test.tsnew file mode 100644index 00000000000..4c682a5a9e9--- /dev/null+++ b/packages/twenty-website/src/platform/enterprise/resolve-subscription-license-state.test.ts@@ -0,0 +1,77 @@+import { resolveSubscriptionLicenseState } from './resolve-subscription-license-state';++const SECONDS_PER_DAY = 24 * 60 * 60;++const NOW = new Date('2026-08-15T00:00:00.000Z');+const NOW_SECONDS = Math.floor(NOW.getTime() / 1000);++const resolve = (+ status: string,+ nextPaymentAttempt: number | null = NOW_SECONDS + SECONDS_PER_DAY,+) => resolveSubscriptionLicenseState({ status, nextPaymentAttempt });++describe('resolveSubscriptionLicenseState', () => {+ beforeEach(() => {+ jest.useFakeTimers().setSystemTime(NOW);+ });++ afterEach(() => {+ jest.useRealTimers();+ });++ it.each(['active', 'trialing'])('licenses a %s subscription', (status) => {+ expect(resolve(status)).toEqual({+ outcome: 'licensed',+ graceExpiresAt: null,+ });+ });++ it.each(['canceled', 'unpaid', 'incomplete', 'incomplete_expired', 'paused'])(+ 'rejects a %s subscription',+ (status) => {+ expect(resolve(status)).toEqual({+ outcome: 'rejected',+ graceExpiresAt: null,+ });+ },+ );++ it('grants grace while Stripe still has a retry scheduled', () => {+ const nextAttempt = NOW_SECONDS + 2 * SECONDS_PER_DAY;++ expect(resolve('past_due', nextAttempt)).toEqual({+ outcome: 'grace',+ graceExpiresAt: nextAttempt + SECONDS_PER_DAY,+ });+ });++ it('refuses grace once Stripe has stopped retrying', () => {+ expect(resolve('past_due', null)).toEqual({+ outcome: 'rejected',+ graceExpiresAt: null,+ });+ });++ it('keeps the license through a retry that has just fired', () => {+ expect(resolve('past_due', NOW_SECONDS - 60).outcome).toBe('grace');+ });++ it('refuses grace when the scheduled retry has gone stale', () => {+ expect(resolve('past_due', NOW_SECONDS - 2 * SECONDS_PER_DAY)).toEqual({+ outcome: 'rejected',+ graceExpiresAt: null,+ });+ });++ it('follows the dunning schedule forward instead of the billing period', () => {+ const firstRetry = NOW_SECONDS + SECONDS_PER_DAY;+ const rescheduled = NOW_SECONDS + 5 * SECONDS_PER_DAY;++ expect(resolve('past_due', firstRetry).graceExpiresAt).toBe(+ firstRetry + SECONDS_PER_DAY,+ );+ expect(resolve('past_due', rescheduled).graceExpiresAt).toBe(+ rescheduled + SECONDS_PER_DAY,+ );+ });+});diff --git a/packages/twenty-website/src/platform/enterprise/resolve-subscription-license-state.ts b/packages/twenty-website/src/platform/enterprise/resolve-subscription-license-state.tsnew file mode 100644index 00000000000..6df0ac17adf--- /dev/null+++ b/packages/twenty-website/src/platform/enterprise/resolve-subscription-license-state.ts@@ -0,0 +1,67 @@+import { SUBSCRIPTION_GRACE_STATUSES } from './subscription-grace-statuses';+import { SUBSCRIPTION_LICENSE_OUTCOME } from './subscription-license-outcome';++const SECONDS_PER_DAY = 24 * 60 * 60;+const GRACE_MARGIN_SECONDS = SECONDS_PER_DAY;++const LICENSED_STATUSES = new Set(['active', 'trialing']);++export type ResolveSubscriptionLicenseStateInput = {+ status: string;+ nextPaymentAttempt: number | null;+};++export type SubscriptionLicenseState =+ | {+ outcome: typeof SUBSCRIPTION_LICENSE_OUTCOME.LICENSED;+ graceExpiresAt: null;+ }+ | {+ outcome: typeof SUBSCRIPTION_LICENSE_OUTCOME.GRACE;+ graceExpiresAt: number;+ }+ | {+ outcome: typeof SUBSCRIPTION_LICENSE_OUTCOME.REJECTED;+ graceExpiresAt: null;+ };++const licensed = (): SubscriptionLicenseState => ({+ outcome: SUBSCRIPTION_LICENSE_OUTCOME.LICENSED,+ graceExpiresAt: null,+});++const rejected = (): SubscriptionLicenseState => ({+ outcome: SUBSCRIPTION_LICENSE_OUTCOME.REJECTED,+ graceExpiresAt: null,+});++const grace = (graceExpiresAt: number): SubscriptionLicenseState => ({+ outcome: SUBSCRIPTION_LICENSE_OUTCOME.GRACE,+ graceExpiresAt,+});++export function resolveSubscriptionLicenseState({+ status,+ nextPaymentAttempt,+}: ResolveSubscriptionLicenseStateInput): SubscriptionLicenseState {+ if (LICENSED_STATUSES.has(status)) {+ return licensed();+ }++ if (SUBSCRIPTION_GRACE_STATUSES.has(status)) {+ if (typeof nextPaymentAttempt !== 'number' || nextPaymentAttempt <= 0) {+ return rejected();+ }++ const nowSeconds = Math.floor(Date.now() / 1000);+ const graceExpiresAt = nextPaymentAttempt + GRACE_MARGIN_SECONDS;++ if (graceExpiresAt <= nowSeconds) {+ return rejected();+ }++ return grace(graceExpiresAt);+ }++ return rejected();+}diff --git a/packages/twenty-website/src/platform/enterprise/sign-validity-token.test.ts b/packages/twenty-website/src/platform/enterprise/sign-validity-token.test.tsindex 8accc9a7f41..8c60b35b57a 100644--- a/packages/twenty-website/src/platform/enterprise/sign-validity-token.test.ts+++ b/packages/twenty-website/src/platform/enterprise/sign-validity-token.test.ts@@ -79,4 +79,40 @@ describe('signValidityToken', () => {DEFAULT_DURATION_DAYS * SECONDS_PER_DAY,);});++ it('caps the token at the end of the grace period', () => {+ const graceExpiresAt = Math.floor(Date.now() / 1000) + 2 * SECONDS_PER_DAY;+ const claims = verifiedClaims(+ signValidityToken('sub_grace', {+ subscriptionCancelAt: null,+ graceExpiresAt,+ }),+ );++ expect(claims.exp).toBe(graceExpiresAt);+ });++ it('keeps the earliest of a cancellation and a grace deadline', () => {+ const graceExpiresAt = Math.floor(Date.now() / 1000) + 5 * SECONDS_PER_DAY;+ const cancelAt = Math.floor(Date.now() / 1000) + 3 * SECONDS_PER_DAY;+ const claims = verifiedClaims(+ signValidityToken('sub_both', {+ subscriptionCancelAt: cancelAt,+ graceExpiresAt,+ }),+ );++ expect(claims.exp).toBe(cancelAt);+ });++ it('signs a grace token with the standard valid status', () => {+ const claims = verifiedClaims(+ signValidityToken('sub_grace_status', {+ subscriptionCancelAt: null,+ graceExpiresAt: Math.floor(Date.now() / 1000) + SECONDS_PER_DAY,+ }),+ );++ expect(claims.status).toBe('valid');+ });});diff --git a/packages/twenty-website/src/platform/enterprise/sign-validity-token.ts b/packages/twenty-website/src/platform/enterprise/sign-validity-token.tsindex f111bd2af3b..b0b23a558a5 100644--- a/packages/twenty-website/src/platform/enterprise/sign-validity-token.ts+++ b/packages/twenty-website/src/platform/enterprise/sign-validity-token.ts@@ -12,6 +12,7 @@ type EnterpriseValidityPayload = {type SignValidityTokenOptions = {subscriptionCancelAt: number | null;+ graceExpiresAt?: number | null;};function getValidityTokenDurationDays(): number {@@ -33,15 +34,14 @@ function getValidityTokenDurationDays(): number {function computeValidityExp(nowSeconds: number,durationDays: number,- subscriptionCancelAt: number | null,+ caps: (number | null | undefined)[],): number {const defaultExp = nowSeconds + durationDays * SECONDS_PER_DAY;+ const applicableCaps = caps.filter(+ (cap): cap is number => typeof cap === 'number' && cap > 0,+ );- if (subscriptionCancelAt === null || subscriptionCancelAt <= 0) {- return defaultExp;- }-- return Math.min(defaultExp, subscriptionCancelAt);+ return Math.min(defaultExp, ...applicableCaps);}export function signValidityToken(@@ -50,8 +50,10 @@ export function signValidityToken(): string {const now = Math.floor(Date.now() / 1000);const durationDays = getValidityTokenDurationDays();- const subscriptionCancelAt = options?.subscriptionCancelAt ?? null;- const exp = computeValidityExp(now, durationDays, subscriptionCancelAt);+ const exp = computeValidityExp(now, durationDays, [+ options?.subscriptionCancelAt,+ options?.graceExpiresAt,+ ]);const payload: EnterpriseValidityPayload = {exp,diff --git a/packages/twenty-website/src/platform/enterprise/subscription-current-period-end.ts b/packages/twenty-website/src/platform/enterprise/subscription-current-period-end.tsindex 7a46831cb1e..a7952f6ac12 100644--- a/packages/twenty-website/src/platform/enterprise/subscription-current-period-end.ts+++ b/packages/twenty-website/src/platform/enterprise/subscription-current-period-end.ts@@ -1,15 +1,9 @@import type Stripe from 'stripe';-type SubscriptionWithPeriodBounds = Stripe.Subscription & {- current_period_end?: number;-};-export function getSubscriptionCurrentPeriodEnd(subscription: Stripe.Response<Stripe.Subscription>,): number | null {- const extended =- subscription as Stripe.Response<SubscriptionWithPeriodBounds>;- const end = extended.current_period_end;+ const end = subscription.items?.data?.[0]?.current_period_end;return typeof end === 'number' ? end : null;}diff --git a/packages/twenty-website/src/platform/enterprise/subscription-current-period.test.ts b/packages/twenty-website/src/platform/enterprise/subscription-current-period.test.tsnew file mode 100644index 00000000000..68d4c93fc6e--- /dev/null+++ b/packages/twenty-website/src/platform/enterprise/subscription-current-period.test.ts@@ -0,0 +1,41 @@+import type Stripe from 'stripe';++import { getSubscriptionCurrentPeriodEnd } from './subscription-current-period-end';++const PERIOD_END = 1788955200;++const subscriptionWith = (+ shape: Record<string, unknown>,+): Stripe.Response<Stripe.Subscription> =>+ shape as unknown as Stripe.Response<Stripe.Subscription>;++describe('getSubscriptionCurrentPeriodEnd', () => {+ it('reads the period bounds from the subscription item', () => {+ const subscription = subscriptionWith({+ items: {+ data: [+ {+ current_period_end: PERIOD_END,+ },+ ],+ },+ });++ expect(getSubscriptionCurrentPeriodEnd(subscription)).toBe(PERIOD_END);+ });++ it('ignores period bounds sitting on the subscription itself', () => {+ const subscription = subscriptionWith({+ items: { data: [] },+ current_period_end: PERIOD_END,+ });++ expect(getSubscriptionCurrentPeriodEnd(subscription)).toBeNull();+ });++ it('returns null when the item carries no bounds', () => {+ const subscription = subscriptionWith({ items: { data: [{}] } });++ expect(getSubscriptionCurrentPeriodEnd(subscription)).toBeNull();+ });+});diff --git a/packages/twenty-website/src/platform/enterprise/subscription-grace-statuses.ts b/packages/twenty-website/src/platform/enterprise/subscription-grace-statuses.tsnew file mode 100644index 00000000000..45fdd3ebfde--- /dev/null+++ b/packages/twenty-website/src/platform/enterprise/subscription-grace-statuses.ts@@ -0,0 +1 @@+export const SUBSCRIPTION_GRACE_STATUSES = new Set<string>(['past_due']);diff --git a/packages/twenty-website/src/platform/enterprise/subscription-license-outcome.ts b/packages/twenty-website/src/platform/enterprise/subscription-license-outcome.tsnew file mode 100644index 00000000000..4ecde77cc13--- /dev/null+++ b/packages/twenty-website/src/platform/enterprise/subscription-license-outcome.ts@@ -0,0 +1,8 @@+export const SUBSCRIPTION_LICENSE_OUTCOME = {+ LICENSED: 'licensed',+ GRACE: 'grace',+ REJECTED: 'rejected',+} as const;++export type SubscriptionLicenseOutcome =+ (typeof SUBSCRIPTION_LICENSE_OUTCOME)[keyof typeof SUBSCRIPTION_LICENSE_OUTCOME];