2
0

♻️ Re-organize workspace folders

This commit is contained in:
Baptiste Arnaud
2023-03-15 08:35:16 +01:00
parent 25c367901f
commit cbc8194f19
987 changed files with 2716 additions and 2770 deletions

View File

@ -0,0 +1,90 @@
import { Plan } from '@typebot.io/prisma'
import { z } from 'zod'
const userEvent = z.object({
userId: z.string(),
})
const workspaceEvent = userEvent.merge(
z.object({
workspaceId: z.string(),
})
)
const typebotEvent = workspaceEvent.merge(
z.object({
typebotId: z.string(),
})
)
const workspaceCreatedEventSchema = workspaceEvent.merge(
z.object({
name: z.literal('Workspace created'),
data: z.object({
name: z.string().optional(),
plan: z.nativeEnum(Plan),
}),
})
)
const userCreatedEventSchema = userEvent.merge(
z.object({
name: z.literal('User created'),
data: z.object({
email: z.string(),
name: z.string().optional(),
}),
})
)
const typebotCreatedEventSchema = typebotEvent.merge(
z.object({
name: z.literal('Typebot created'),
data: z.object({
name: z.string(),
template: z.string().optional(),
}),
})
)
const publishedTypebotEventSchema = typebotEvent.merge(
z.object({
name: z.literal('Typebot published'),
data: z.object({
name: z.string(),
isFirstPublish: z.literal(true).optional(),
}),
})
)
const subscriptionUpdatedEventSchema = workspaceEvent.merge(
z.object({
name: z.literal('Subscription updated'),
data: z.object({
plan: z.nativeEnum(Plan),
additionalChatsIndex: z.number(),
additionalStorageIndex: z.number(),
}),
})
)
const newResultsCollectedEventSchema = typebotEvent.merge(
z.object({
name: z.literal('New results collected'),
data: z.object({
total: z.number(),
isFirstOfKind: z.literal(true).optional(),
}),
})
)
export const eventSchema = z.discriminatedUnion('name', [
workspaceCreatedEventSchema,
userCreatedEventSchema,
typebotCreatedEventSchema,
publishedTypebotEventSchema,
subscriptionUpdatedEventSchema,
newResultsCollectedEventSchema,
])
export type TelemetryEvent = z.infer<typeof eventSchema>