mirror of
https://github.com/documenso/documenso.git
synced 2026-07-11 13:35:20 +10:00
138d663c25
Merge origin/main into feat/external-2fa-codes. Resolve formatting conflicts caused by biome rollout; preserve both feature streams: PR's external 2FA token + signing-session 2FA proof additions plus main's RateLimit/RecipientExpired/signingReminders/date-auto-insert. In complete-document-with-token.ts, drop the duplicate early field-fetching block introduced when main moved that logic later with date auto-insert support; keep the EXTERNAL_TWO_FACTOR_AUTH check using derivedRecipientActionAuth.
36 lines
1006 B
TypeScript
36 lines
1006 B
TypeScript
import type { Subscription } from '@documenso/prisma/generated/zod/modelSchema/SubscriptionSchema';
|
|
|
|
import { IS_BILLING_ENABLED } from '../constants/app';
|
|
import { AppError, AppErrorCode } from '../errors/app-error';
|
|
import type { StripeOrganisationCreateMetadata } from '../types/subscription';
|
|
|
|
export const generateStripeOrganisationCreateMetadata = (organisationName: string, userId: number) => {
|
|
const metadata: StripeOrganisationCreateMetadata = {
|
|
organisationName,
|
|
userId,
|
|
};
|
|
|
|
return {
|
|
organisationCreateData: JSON.stringify(metadata),
|
|
};
|
|
};
|
|
|
|
/**
|
|
* Throws an error if billing is enabled and no subscription is found.
|
|
*/
|
|
export const validateIfSubscriptionIsRequired = (subscription?: Subscription | null) => {
|
|
const isBillingEnabled = IS_BILLING_ENABLED();
|
|
|
|
if (!isBillingEnabled) {
|
|
return;
|
|
}
|
|
|
|
if (isBillingEnabled && !subscription) {
|
|
throw new AppError(AppErrorCode.NOT_FOUND, {
|
|
message: 'Subscription not found',
|
|
});
|
|
}
|
|
|
|
return subscription;
|
|
};
|