mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 08:13:56 +10:00
36 lines
1003 B
TypeScript
36 lines
1003 B
TypeScript
import { NEXT_PUBLIC_WEBAPP_URL } from '@documenso/lib/constants/app';
|
|
|
|
import { DEFAULT_MINIMUM_ENVELOPE_ITEM_COUNT, FREE_PLAN_LIMITS } from './constants';
|
|
import type { TLimitsResponseSchema } from './schema';
|
|
import { ZLimitsResponseSchema } from './schema';
|
|
|
|
export type GetLimitsOptions = {
|
|
headers?: Record<string, string>;
|
|
teamId: number;
|
|
};
|
|
|
|
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,
|
|
maximumEnvelopeItemCount: DEFAULT_MINIMUM_ENVELOPE_ITEM_COUNT,
|
|
} satisfies TLimitsResponseSchema;
|
|
});
|
|
};
|