Files
documenso/packages/lib/utils/billing.ts
T
ephraimduncan 138d663c25 chore: merge main, resolve biome formatting conflicts
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.
2026-05-12 11:46:11 +00:00

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;
};