refactor(server): config system (#11081)

This commit is contained in:
forehalo
2025-03-27 12:32:28 +00:00
parent 7091111f85
commit 0ea38680fa
274 changed files with 7583 additions and 5841 deletions
@@ -4,6 +4,7 @@ import { z } from 'zod';
import { UserNotFound } from '../../../base';
import { ScheduleManager } from '../schedule';
import { StripeFactory } from '../stripe';
import {
encodeLookupKey,
KnownStripeInvoice,
@@ -55,12 +56,16 @@ export const CheckoutParams = z.object({
});
export abstract class SubscriptionManager {
protected readonly scheduleManager = new ScheduleManager(this.stripe);
protected readonly scheduleManager = new ScheduleManager(this.stripeProvider);
constructor(
protected readonly stripe: Stripe,
protected readonly stripeProvider: StripeFactory,
protected readonly db: PrismaClient
) {}
get stripe() {
return this.stripeProvider.stripe;
}
abstract filterPrices(
prices: KnownStripePrice[],
customer?: UserStripeCustomer
@@ -3,11 +3,11 @@ import { randomUUID } from 'node:crypto';
import { Injectable } from '@nestjs/common';
import { PrismaClient, UserStripeCustomer } from '@prisma/client';
import { pick } from 'lodash-es';
import Stripe from 'stripe';
import { z } from 'zod';
import { SubscriptionPlanNotFound, URLHelper } from '../../../base';
import { Mailer } from '../../../core/mail';
import { StripeFactory } from '../stripe';
import {
KnownStripeInvoice,
KnownStripePrice,
@@ -43,12 +43,12 @@ export const SelfhostTeamSubscriptionIdentity = z.object({
@Injectable()
export class SelfhostTeamSubscriptionManager extends SubscriptionManager {
constructor(
stripe: Stripe,
stripeProvider: StripeFactory,
db: PrismaClient,
private readonly url: URLHelper,
private readonly mailer: Mailer
) {
super(stripe, db);
super(stripeProvider, db);
}
filterPrices(
@@ -5,17 +5,18 @@ import Stripe from 'stripe';
import { z } from 'zod';
import {
Config,
EventBus,
InternalServerError,
InvalidCheckoutParameters,
Mutex,
Runtime,
SubscriptionAlreadyExists,
SubscriptionPlanNotFound,
TooManyRequest,
URLHelper,
} from '../../../base';
import { EarlyAccessType, FeatureService } from '../../../core/features';
import { StripeFactory } from '../stripe';
import {
CouponType,
KnownStripeInvoice,
@@ -53,15 +54,15 @@ export const UserSubscriptionCheckoutArgs = z.object({
@Injectable()
export class UserSubscriptionManager extends SubscriptionManager {
constructor(
stripe: Stripe,
stripeProvider: StripeFactory,
db: PrismaClient,
private readonly runtime: Runtime,
private readonly config: Config,
private readonly feature: FeatureService,
private readonly event: EventBus,
private readonly url: URLHelper,
private readonly mutex: Mutex
) {
super(stripe, db);
super(stripeProvider, db);
}
async filterPrices(
@@ -588,7 +589,7 @@ export class UserSubscriptionManager extends SubscriptionManager {
{ proEarlyAccess, proSubscribed, onetime }: PriceStrategyStatus
) {
if (lookupKey.recurring === SubscriptionRecurring.Lifetime) {
return this.runtime.fetch('plugins.payment/showLifetimePrice');
return this.config.payment.showLifetimePrice;
}
if (lookupKey.variant === SubscriptionVariant.Onetime) {
@@ -1,7 +1,6 @@
import { Injectable } from '@nestjs/common';
import { PrismaClient, UserStripeCustomer } from '@prisma/client';
import { omit, pick } from 'lodash-es';
import Stripe from 'stripe';
import { z } from 'zod';
import {
@@ -12,6 +11,7 @@ import {
URLHelper,
} from '../../../base';
import { Models } from '../../../models';
import { StripeFactory } from '../stripe';
import {
KnownStripeInvoice,
KnownStripePrice,
@@ -46,13 +46,13 @@ export const WorkspaceSubscriptionCheckoutArgs = z.object({
@Injectable()
export class WorkspaceSubscriptionManager extends SubscriptionManager {
constructor(
stripe: Stripe,
stripeProvider: StripeFactory,
db: PrismaClient,
private readonly url: URLHelper,
private readonly event: EventBus,
private readonly models: Models
) {
super(stripe, db);
super(stripeProvider, db);
}
filterPrices(