Closes #1039 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Workspaces now include additional status indicator: `isPastDue`. - New pages for handling workspaces that are past due. Meaning, an invoice is unpaid. - **Bug Fixes** - Fixed issues with workspace status checks and redirections for suspended workspaces. - **Refactor** - Refactored workspace-related API functions to accommodate new status fields. - Improved permission checks for reading and writing typebots based on workspace status. - **Chores** - Database schema updated to include `isPastDue` field for workspaces. - Implemented new webhook event handling for subscription and invoice updates. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
59 lines
1.8 KiB
TypeScript
59 lines
1.8 KiB
TypeScript
import { z } from 'zod'
|
|
import {
|
|
Workspace as WorkspacePrisma,
|
|
Plan,
|
|
MemberInWorkspace as MemberInWorkspacePrisma,
|
|
WorkspaceRole,
|
|
User as UserPrisma,
|
|
WorkspaceInvitation as WorkspaceInvitationPrisma,
|
|
} from '@typebot.io/prisma'
|
|
|
|
export const workspaceMemberSchema = z.object({
|
|
workspaceId: z.string(),
|
|
user: z.object({
|
|
name: z.string().nullable(),
|
|
email: z.string().nullable(),
|
|
image: z.string().nullable(),
|
|
}),
|
|
role: z.nativeEnum(WorkspaceRole),
|
|
}) satisfies z.ZodType<
|
|
Omit<MemberInWorkspacePrisma, 'userId' | 'createdAt' | 'updatedAt'> & {
|
|
user: Pick<UserPrisma, 'name' | 'email' | 'image'>
|
|
}
|
|
>
|
|
|
|
export const workspaceInvitationSchema = z.object({
|
|
createdAt: z.date(),
|
|
updatedAt: z.date(),
|
|
email: z.string(),
|
|
type: z.nativeEnum(WorkspaceRole),
|
|
}) satisfies z.ZodType<
|
|
Omit<WorkspaceInvitationPrisma, 'workspaceId' | 'userId' | 'id'>
|
|
>
|
|
|
|
export const workspaceSchema = z.object({
|
|
id: z.string(),
|
|
createdAt: z.date(),
|
|
updatedAt: z.date(),
|
|
name: z.string(),
|
|
icon: z.string().nullable(),
|
|
plan: z.nativeEnum(Plan),
|
|
stripeId: z.string().nullable(),
|
|
additionalChatsIndex: z.number(),
|
|
additionalStorageIndex: z.number(),
|
|
chatsLimitFirstEmailSentAt: z.date().nullable(),
|
|
chatsLimitSecondEmailSentAt: z.date().nullable(),
|
|
storageLimitFirstEmailSentAt: z.date().nullable(),
|
|
storageLimitSecondEmailSentAt: z.date().nullable(),
|
|
customChatsLimit: z.number().nullable(),
|
|
customStorageLimit: z.number().nullable(),
|
|
customSeatsLimit: z.number().nullable(),
|
|
isQuarantined: z.boolean(),
|
|
isSuspended: z.boolean(),
|
|
isPastDue: z.boolean(),
|
|
}) satisfies z.ZodType<WorkspacePrisma>
|
|
|
|
export type Workspace = z.infer<typeof workspaceSchema>
|
|
export type WorkspaceMember = z.infer<typeof workspaceMemberSchema>
|
|
export type WorkspaceInvitation = z.infer<typeof workspaceInvitationSchema>
|