mirror of
https://github.com/documenso/documenso.git
synced 2025-11-16 01:32:06 +10:00
feat: wip
This commit is contained in:
26
packages/lib/utils/billing.ts
Normal file
26
packages/lib/utils/billing.ts
Normal file
@ -0,0 +1,26 @@
|
||||
import { AppError } from '../errors/app-error';
|
||||
import type { Subscription } from '.prisma/client';
|
||||
import { SubscriptionStatus } from '.prisma/client';
|
||||
|
||||
export const isPriceIdCommunityPlan = (priceId: string) =>
|
||||
priceId === process.env.NEXT_PUBLIC_STRIPE_COMMUNITY_PLAN_MONTHLY_PRICE_ID ||
|
||||
priceId === process.env.NEXT_PUBLIC_STRIPE_COMMUNITY_PLAN_YEARLY_PRICE_ID;
|
||||
|
||||
/**
|
||||
* Returns true if there is a subscription that is active and is a community plan.
|
||||
*/
|
||||
export const isSomeSubscriptionsActiveAndCommunityPlan = (subscriptions: Subscription[]) => {
|
||||
return subscriptions.some(
|
||||
(subscription) =>
|
||||
subscription.status === SubscriptionStatus.ACTIVE &&
|
||||
isPriceIdCommunityPlan(subscription.planId),
|
||||
);
|
||||
};
|
||||
|
||||
export const getTeamSeatPriceId = () => {
|
||||
if (!process.env.NEXT_PUBLIC_STRIPE_TEAM_SEAT_PRICE_ID) {
|
||||
throw new AppError('MISSING_STRIPE_TEAM_SEAT_PRICE_ID');
|
||||
}
|
||||
|
||||
return process.env.NEXT_PUBLIC_STRIPE_TEAM_SEAT_PRICE_ID;
|
||||
};
|
||||
17
packages/lib/utils/params.ts
Normal file
17
packages/lib/utils/params.ts
Normal file
@ -0,0 +1,17 @@
|
||||
// Common util functions for parsing params.
|
||||
|
||||
/**
|
||||
* From an unknown string, parse it into a number array.
|
||||
*
|
||||
* Filter out unknown values.
|
||||
*/
|
||||
export const parseToNumberArray = (value: unknown): number[] => {
|
||||
if (typeof value !== 'string') {
|
||||
return [];
|
||||
}
|
||||
|
||||
return value
|
||||
.split(',')
|
||||
.map((value) => parseInt(value, 10))
|
||||
.filter((value) => !isNaN(value));
|
||||
};
|
||||
7
packages/lib/utils/teams.ts
Normal file
7
packages/lib/utils/teams.ts
Normal file
@ -0,0 +1,7 @@
|
||||
import { WEBAPP_BASE_URL } from '../constants/app';
|
||||
|
||||
export const formatTeamUrl = (teamUrl: string, baseUrl?: string) => {
|
||||
const formattedBaseUrl = (baseUrl ?? WEBAPP_BASE_URL).replace(/https?:\/\//, '');
|
||||
|
||||
return `${formattedBaseUrl}/t/${teamUrl}`;
|
||||
};
|
||||
21
packages/lib/utils/token-verification.ts
Normal file
21
packages/lib/utils/token-verification.ts
Normal file
@ -0,0 +1,21 @@
|
||||
import type { DurationLike } from 'luxon';
|
||||
import { DateTime } from 'luxon';
|
||||
import { nanoid } from 'nanoid';
|
||||
|
||||
/**
|
||||
* Create a token verification object.
|
||||
*
|
||||
* @param expiry The date the token expires, or the duration until the token expires.
|
||||
*/
|
||||
export const createTokenVerification = (expiry: Date | DurationLike) => {
|
||||
const expiresAt = expiry instanceof Date ? expiry : DateTime.now().plus(expiry).toJSDate();
|
||||
|
||||
return {
|
||||
expiresAt,
|
||||
token: nanoid(32),
|
||||
};
|
||||
};
|
||||
|
||||
export const isTokenExpired = (expiresAt: Date) => {
|
||||
return expiresAt < new Date();
|
||||
};
|
||||
Reference in New Issue
Block a user