2023-03-15 08:35:16 +01:00
|
|
|
import { Plan } from '@typebot.io/prisma'
|
2023-12-22 09:13:53 +01:00
|
|
|
import { z } from '../zod'
|
2023-03-14 14:18:05 +01:00
|
|
|
|
|
|
|
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(),
|
|
|
|
}),
|
|
|
|
})
|
|
|
|
)
|
|
|
|
|
2024-03-04 10:04:48 +01:00
|
|
|
const userLoggedInEventSchema = userEvent.merge(
|
|
|
|
z.object({
|
|
|
|
name: z.literal('User logged in'),
|
|
|
|
})
|
|
|
|
)
|
|
|
|
|
2024-02-02 11:58:32 +01:00
|
|
|
const userUpdatedEventSchema = userEvent.merge(
|
|
|
|
z.object({
|
|
|
|
name: z.literal('User updated'),
|
|
|
|
data: z.object({
|
|
|
|
name: z.string().optional(),
|
|
|
|
onboardingCategories: z.array(z.string()).optional(),
|
|
|
|
referral: z.string().optional(),
|
|
|
|
company: z.string().optional(),
|
|
|
|
}),
|
|
|
|
})
|
|
|
|
)
|
|
|
|
|
2023-03-14 14:18:05 +01:00
|
|
|
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(),
|
|
|
|
}),
|
|
|
|
})
|
|
|
|
)
|
|
|
|
|
2024-02-02 14:49:41 +01:00
|
|
|
const customDomainAddedEventSchema = workspaceEvent.merge(
|
|
|
|
z.object({
|
|
|
|
name: z.literal('Custom domain added'),
|
|
|
|
data: z.object({
|
|
|
|
domain: z.string(),
|
|
|
|
}),
|
|
|
|
})
|
|
|
|
)
|
|
|
|
|
|
|
|
const whatsAppCredentialsCreatedEventSchema = workspaceEvent.merge(
|
|
|
|
z.object({
|
|
|
|
name: z.literal('WhatsApp credentials created'),
|
|
|
|
})
|
|
|
|
)
|
|
|
|
|
2023-03-14 14:18:05 +01:00
|
|
|
const subscriptionUpdatedEventSchema = workspaceEvent.merge(
|
|
|
|
z.object({
|
|
|
|
name: z.literal('Subscription updated'),
|
|
|
|
data: z.object({
|
|
|
|
plan: z.nativeEnum(Plan),
|
|
|
|
}),
|
|
|
|
})
|
|
|
|
)
|
|
|
|
|
2023-11-14 16:00:10 +01:00
|
|
|
const subscriptionAutoUpdatedEventSchema = workspaceEvent.merge(
|
|
|
|
z.object({
|
|
|
|
name: z.literal('Subscription automatically updated'),
|
|
|
|
data: z.object({
|
|
|
|
plan: z.nativeEnum(Plan),
|
|
|
|
}),
|
|
|
|
})
|
|
|
|
)
|
|
|
|
|
2023-03-14 14:18:05 +01:00
|
|
|
const newResultsCollectedEventSchema = typebotEvent.merge(
|
|
|
|
z.object({
|
|
|
|
name: z.literal('New results collected'),
|
|
|
|
data: z.object({
|
|
|
|
total: z.number(),
|
2023-03-14 21:10:43 +01:00
|
|
|
isFirstOfKind: z.literal(true).optional(),
|
2023-03-14 14:18:05 +01:00
|
|
|
}),
|
|
|
|
})
|
|
|
|
)
|
|
|
|
|
2023-04-17 17:19:44 +02:00
|
|
|
const workspaceLimitReachedEventSchema = workspaceEvent.merge(
|
|
|
|
z.object({
|
|
|
|
name: z.literal('Workspace limit reached'),
|
|
|
|
data: z.object({
|
|
|
|
chatsLimit: z.number(),
|
|
|
|
totalChatsUsed: z.number(),
|
|
|
|
}),
|
|
|
|
})
|
|
|
|
)
|
|
|
|
|
2023-06-06 13:25:13 +02:00
|
|
|
const workspaceAutoQuarantinedEventSchema = workspaceEvent.merge(
|
|
|
|
z.object({
|
|
|
|
name: z.literal('Workspace automatically quarantined'),
|
|
|
|
data: z.object({
|
|
|
|
chatsLimit: z.number(),
|
|
|
|
totalChatsUsed: z.number(),
|
|
|
|
}),
|
|
|
|
})
|
|
|
|
)
|
|
|
|
|
2023-11-23 08:16:23 +01:00
|
|
|
export const workspacePastDueEventSchema = workspaceEvent.merge(
|
|
|
|
z.object({
|
|
|
|
name: z.literal('Workspace past due'),
|
|
|
|
})
|
|
|
|
)
|
|
|
|
|
|
|
|
export const workspaceNotPastDueEventSchema = workspaceEvent.merge(
|
|
|
|
z.object({
|
|
|
|
name: z.literal('Workspace past due status removed'),
|
|
|
|
})
|
|
|
|
)
|
|
|
|
|
:technologist: (folders) Add folder trpc endpoints (#1218)
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
- **New Features**
- Introduced folder management capabilities including creation,
deletion, update, listing, and retrieval within workspaces.
- Added telemetry tracking for client events, Typebot publish events,
and analytics page views.
- Enhanced settings to track client events under specific conditions.
- Implemented server-side logic for analytics tracking with PostHog
integration.
- Added API documentation for folder operations (create, delete, get,
list, update).
- **Refactor**
- Updated `onConfirm` function's return type in `ConfirmModal`.
- Simplified folder creation process in tests.
- Refactored logic for handling file upload blocks and parsing publish
events in Typebot publishing.
- Migrated handler functions to TRPC endpoints for folder operations.
- **Documentation**
- Introduced documentation for new folder and telemetry functionalities.
- **Chores**
- Added new schemas for folders and telemetry events, including event
tracking and folder structure.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2024-02-05 12:14:03 +01:00
|
|
|
export const removedBrandingEventSchema = typebotEvent.merge(
|
|
|
|
z.object({
|
|
|
|
name: z.literal('Branding removed'),
|
|
|
|
})
|
|
|
|
)
|
|
|
|
|
|
|
|
export const createdFolderEventSchema = workspaceEvent.merge(
|
|
|
|
z.object({
|
|
|
|
name: z.literal('Folder created'),
|
|
|
|
})
|
|
|
|
)
|
|
|
|
|
|
|
|
export const publishedFileUploadBlockEventSchema = typebotEvent.merge(
|
|
|
|
z.object({
|
|
|
|
name: z.literal('File upload block published'),
|
|
|
|
})
|
|
|
|
)
|
|
|
|
|
|
|
|
export const visitedAnalyticsEventSchema = typebotEvent.merge(
|
|
|
|
z.object({
|
|
|
|
name: z.literal('Analytics visited'),
|
|
|
|
})
|
|
|
|
)
|
|
|
|
|
|
|
|
export const clientSideEvents = [removedBrandingEventSchema] as const
|
|
|
|
|
2023-03-14 14:18:05 +01:00
|
|
|
export const eventSchema = z.discriminatedUnion('name', [
|
|
|
|
workspaceCreatedEventSchema,
|
|
|
|
userCreatedEventSchema,
|
2024-03-04 10:04:48 +01:00
|
|
|
userLoggedInEventSchema,
|
2023-03-14 14:18:05 +01:00
|
|
|
typebotCreatedEventSchema,
|
|
|
|
publishedTypebotEventSchema,
|
|
|
|
subscriptionUpdatedEventSchema,
|
|
|
|
newResultsCollectedEventSchema,
|
2023-04-17 17:19:44 +02:00
|
|
|
workspaceLimitReachedEventSchema,
|
2023-06-06 13:25:13 +02:00
|
|
|
workspaceAutoQuarantinedEventSchema,
|
2023-11-14 16:00:10 +01:00
|
|
|
subscriptionAutoUpdatedEventSchema,
|
2023-11-23 08:16:23 +01:00
|
|
|
workspacePastDueEventSchema,
|
|
|
|
workspaceNotPastDueEventSchema,
|
2024-02-02 11:58:32 +01:00
|
|
|
userUpdatedEventSchema,
|
2024-02-02 14:49:41 +01:00
|
|
|
customDomainAddedEventSchema,
|
|
|
|
whatsAppCredentialsCreatedEventSchema,
|
:technologist: (folders) Add folder trpc endpoints (#1218)
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
- **New Features**
- Introduced folder management capabilities including creation,
deletion, update, listing, and retrieval within workspaces.
- Added telemetry tracking for client events, Typebot publish events,
and analytics page views.
- Enhanced settings to track client events under specific conditions.
- Implemented server-side logic for analytics tracking with PostHog
integration.
- Added API documentation for folder operations (create, delete, get,
list, update).
- **Refactor**
- Updated `onConfirm` function's return type in `ConfirmModal`.
- Simplified folder creation process in tests.
- Refactored logic for handling file upload blocks and parsing publish
events in Typebot publishing.
- Migrated handler functions to TRPC endpoints for folder operations.
- **Documentation**
- Introduced documentation for new folder and telemetry functionalities.
- **Chores**
- Added new schemas for folders and telemetry events, including event
tracking and folder structure.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2024-02-05 12:14:03 +01:00
|
|
|
createdFolderEventSchema,
|
|
|
|
publishedFileUploadBlockEventSchema,
|
|
|
|
visitedAnalyticsEventSchema,
|
|
|
|
...clientSideEvents,
|
2023-03-14 14:18:05 +01:00
|
|
|
])
|
|
|
|
|
:technologist: (folders) Add folder trpc endpoints (#1218)
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
- **New Features**
- Introduced folder management capabilities including creation,
deletion, update, listing, and retrieval within workspaces.
- Added telemetry tracking for client events, Typebot publish events,
and analytics page views.
- Enhanced settings to track client events under specific conditions.
- Implemented server-side logic for analytics tracking with PostHog
integration.
- Added API documentation for folder operations (create, delete, get,
list, update).
- **Refactor**
- Updated `onConfirm` function's return type in `ConfirmModal`.
- Simplified folder creation process in tests.
- Refactored logic for handling file upload blocks and parsing publish
events in Typebot publishing.
- Migrated handler functions to TRPC endpoints for folder operations.
- **Documentation**
- Introduced documentation for new folder and telemetry functionalities.
- **Chores**
- Added new schemas for folders and telemetry events, including event
tracking and folder structure.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2024-02-05 12:14:03 +01:00
|
|
|
export const clientSideCreateEventSchema = removedBrandingEventSchema.omit({
|
|
|
|
userId: true,
|
|
|
|
})
|
|
|
|
|
2023-03-14 14:18:05 +01:00
|
|
|
export type TelemetryEvent = z.infer<typeof eventSchema>
|