feat(core): add self host team plan (#9569)

This commit is contained in:
JimmFly
2025-02-07 03:35:24 +00:00
parent 5710e8c639
commit e68bdbde3e
37 changed files with 1702 additions and 72 deletions

View File

@@ -105,7 +105,7 @@ export class LicenseService implements OnModuleInit {
throw new WorkspaceLicenseAlreadyExists();
}
const data = await this.fetch<License>(
const data = await this.fetchAffinePro<License>(
`/api/team/licenses/${licenseKey}/activate`,
{
method: 'POST',
@@ -155,7 +155,7 @@ export class LicenseService implements OnModuleInit {
throw new LicenseNotFound();
}
await this.fetch(`/api/team/licenses/${license.key}/deactivate`, {
await this.fetchAffinePro(`/api/team/licenses/${license.key}/deactivate`, {
method: 'POST',
});
@@ -170,10 +170,11 @@ export class LicenseService implements OnModuleInit {
plan: SubscriptionPlan.SelfHostedTeam,
recurring: SubscriptionRecurring.Monthly,
});
return true;
}
async updateTeamRecurring(key: string, recurring: SubscriptionRecurring) {
await this.fetch(`/api/team/licenses/${key}/recurring`, {
await this.fetchAffinePro(`/api/team/licenses/${key}/recurring`, {
method: 'POST',
body: JSON.stringify({
recurring,
@@ -192,7 +193,7 @@ export class LicenseService implements OnModuleInit {
throw new LicenseNotFound();
}
return this.fetch<{ url: string }>(
return this.fetchAffinePro<{ url: string }>(
`/api/team/licenses/${license.key}/create-customer-portal`,
{
method: 'POST',
@@ -218,7 +219,7 @@ export class LicenseService implements OnModuleInit {
return;
}
await this.fetch(`/api/team/licenses/${license.key}/seats`, {
await this.fetchAffinePro(`/api/team/licenses/${license.key}/seats`, {
method: 'POST',
body: JSON.stringify({
quantity: count,
@@ -276,7 +277,7 @@ export class LicenseService implements OnModuleInit {
private async revalidateLicense(license: InstalledLicense) {
try {
const res = await this.fetch<License>(
const res = await this.fetchAffinePro<License>(
`/api/team/licenses/${license.key}/health`,
{
headers: {
@@ -325,7 +326,7 @@ export class LicenseService implements OnModuleInit {
}
}
private async fetch<T = any>(
private async fetchAffinePro<T = any>(
path: string,
init?: RequestInit
): Promise<T & { res: Response }> {

View File

@@ -196,7 +196,7 @@ class CreateCheckoutSessionInput implements z.infer<typeof CheckoutParams> {
idempotencyKey?: string;
@Field(() => GraphQLJSONObject, { nullable: true })
args!: { workspaceId?: string; quantity?: number };
args!: { workspaceId?: string; quantity?: number } | null;
}
@Resolver(() => SubscriptionType)
@@ -278,7 +278,7 @@ export class SubscriptionResolver {
if (input.plan === SubscriptionPlan.SelfHostedTeam) {
session = await this.service.checkout(input, {
plan: input.plan as any,
quantity: input.args.quantity ?? 10,
quantity: input.args?.quantity ?? 10,
});
} else {
if (!user) {