mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 16:23:06 +10:00
35 lines
908 B
TypeScript
35 lines
908 B
TypeScript
import { NEXT_PUBLIC_WEBAPP_URL } from '@documenso/lib/constants/app';
|
|
|
|
import { FREE_PLAN_LIMITS } from './constants';
|
|
import type { TLimitsResponseSchema } from './schema';
|
|
import { ZLimitsResponseSchema } from './schema';
|
|
|
|
export type GetLimitsOptions = {
|
|
headers?: Record<string, string>;
|
|
teamId?: number | null;
|
|
};
|
|
|
|
export const getLimits = async ({ headers, teamId }: GetLimitsOptions = {}) => {
|
|
const requestHeaders = headers ?? {};
|
|
|
|
const url = new URL('/api/limits', NEXT_PUBLIC_WEBAPP_URL());
|
|
|
|
if (teamId) {
|
|
requestHeaders['team-id'] = teamId.toString();
|
|
}
|
|
|
|
return fetch(url, {
|
|
headers: {
|
|
...requestHeaders,
|
|
},
|
|
})
|
|
.then(async (res) => res.json())
|
|
.then((res) => ZLimitsResponseSchema.parse(res))
|
|
.catch((_err) => {
|
|
return {
|
|
quota: FREE_PLAN_LIMITS,
|
|
remaining: FREE_PLAN_LIMITS,
|
|
} satisfies TLimitsResponseSchema;
|
|
});
|
|
};
|