2
0
Files
bot/packages/schemas/features/telemetry.ts
Baptiste Arnaud 797751b418 (billing) Automatic usage-based billing (#924)
BREAKING CHANGE: Stripe environment variables simplified. Check out the
new configs to adapt your existing system.

Closes #906





<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
### Summary by CodeRabbit

**New Features:**
- Introduced a usage-based billing system, providing more flexibility
and options for users.
- Integrated with Stripe for a smoother and more secure payment process.
- Enhanced the user interface with improvements to the billing,
workspace, and pricing pages for a more intuitive experience.

**Improvements:**
- Simplified the billing logic, removing additional chats and yearly
billing for a more streamlined user experience.
- Updated email notifications to keep users informed about their usage
and limits.
- Improved pricing and currency formatting for better clarity and
understanding.

**Testing:**
- Updated tests and specifications to ensure the reliability of new
features and improvements.

**Note:** These changes aim to provide a more flexible and user-friendly
billing system, with clearer pricing and improved notifications. Users
should find the new system more intuitive and easier to navigate.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2023-10-17 08:03:30 +02:00

111 lines
2.3 KiB
TypeScript

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),
}),
})
)
const newResultsCollectedEventSchema = typebotEvent.merge(
z.object({
name: z.literal('New results collected'),
data: z.object({
total: z.number(),
isFirstOfKind: z.literal(true).optional(),
}),
})
)
const workspaceLimitReachedEventSchema = workspaceEvent.merge(
z.object({
name: z.literal('Workspace limit reached'),
data: z.object({
chatsLimit: z.number(),
totalChatsUsed: z.number(),
}),
})
)
const workspaceAutoQuarantinedEventSchema = workspaceEvent.merge(
z.object({
name: z.literal('Workspace automatically quarantined'),
data: z.object({
chatsLimit: z.number(),
totalChatsUsed: z.number(),
}),
})
)
export const eventSchema = z.discriminatedUnion('name', [
workspaceCreatedEventSchema,
userCreatedEventSchema,
typebotCreatedEventSchema,
publishedTypebotEventSchema,
subscriptionUpdatedEventSchema,
newResultsCollectedEventSchema,
workspaceLimitReachedEventSchema,
workspaceAutoQuarantinedEventSchema,
])
export type TelemetryEvent = z.infer<typeof eventSchema>