Files
sign/packages/ee/server-only/limits/client.ts

35 lines
915 B
TypeScript
Raw Normal View History

2023-10-15 20:26:32 +11:00
import { APP_BASE_URL } from '@documenso/lib/constants/app';
import { FREE_PLAN_LIMITS } from './constants';
2024-01-25 10:48:20 +02:00
import type { TLimitsResponseSchema } from './schema';
import { ZLimitsResponseSchema } from './schema';
2023-10-15 20:26:32 +11:00
export type GetLimitsOptions = {
headers?: Record<string, string>;
teamId?: number | null;
2023-10-15 20:26:32 +11:00
};
export const getLimits = async ({ headers, teamId }: GetLimitsOptions = {}) => {
2023-10-15 20:26:32 +11:00
const requestHeaders = headers ?? {};
const url = new URL('/api/limits', APP_BASE_URL() ?? 'http://localhost:3000');
2023-10-15 20:26:32 +11:00
if (teamId) {
requestHeaders['team-id'] = teamId.toString();
}
2023-10-15 20:26:32 +11:00
return fetch(url, {
headers: {
...requestHeaders,
},
})
.then(async (res) => res.json())
.then((res) => ZLimitsResponseSchema.parse(res))
.catch((_err) => {
2023-10-15 20:26:32 +11:00
return {
quota: FREE_PLAN_LIMITS,
remaining: FREE_PLAN_LIMITS,
} satisfies TLimitsResponseSchema;
});
};