🚸 Improve parsing preprocessing on typebots
This commit is contained in:
@@ -1,14 +0,0 @@
|
||||
import { Webhook } from '@typebot.io/schemas'
|
||||
import { sendRequest } from '@typebot.io/lib'
|
||||
|
||||
type Props = {
|
||||
typebotId: string
|
||||
data: Partial<Omit<Webhook, 'typebotId'>>
|
||||
}
|
||||
|
||||
export const createWebhookQuery = ({ typebotId, data }: Props) =>
|
||||
sendRequest<{ webhook: Webhook }>({
|
||||
method: 'POST',
|
||||
url: `/api/typebots/${typebotId}/webhooks`,
|
||||
body: { data },
|
||||
})
|
||||
@@ -1,27 +0,0 @@
|
||||
import { Webhook } from '@typebot.io/schemas'
|
||||
import { sendRequest } from '@typebot.io/lib'
|
||||
import { createWebhookQuery } from './createWebhookQuery'
|
||||
|
||||
type Props = {
|
||||
existingIds: { typebotId: string; webhookId: string }
|
||||
newIds: { typebotId: string; webhookId: string }
|
||||
}
|
||||
export const duplicateWebhookQuery = async ({
|
||||
existingIds,
|
||||
newIds,
|
||||
}: Props): Promise<Webhook | undefined> => {
|
||||
const { data } = await sendRequest<{ webhook: Webhook }>(
|
||||
`/api/typebots/${existingIds.typebotId}/webhooks/${existingIds.webhookId}`
|
||||
)
|
||||
if (!data) return
|
||||
const newWebhook = {
|
||||
...data.webhook,
|
||||
id: newIds.webhookId,
|
||||
typebotId: newIds.typebotId,
|
||||
}
|
||||
await createWebhookQuery({
|
||||
typebotId: newIds.typebotId,
|
||||
data: { ...data.webhook, id: newIds.webhookId },
|
||||
})
|
||||
return newWebhook
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
import { Webhook } from '@typebot.io/schemas'
|
||||
import { sendRequest } from '@typebot.io/lib'
|
||||
|
||||
type Props = {
|
||||
typebotId: string
|
||||
webhookId: string
|
||||
data: Partial<Omit<Webhook, 'id' | 'typebotId'>>
|
||||
}
|
||||
|
||||
export const updateWebhookQuery = ({ typebotId, webhookId, data }: Props) =>
|
||||
sendRequest<{ webhook: Webhook }>({
|
||||
method: 'PATCH',
|
||||
url: `/api/typebots/${typebotId}/webhooks/${webhookId}`,
|
||||
body: { data },
|
||||
})
|
||||
@@ -24,7 +24,7 @@ export const getLinkedTypebots = authenticatedProcedure
|
||||
.output(
|
||||
z.object({
|
||||
typebots: z.array(
|
||||
typebotSchema.pick({
|
||||
typebotSchema._def.schema.pick({
|
||||
id: true,
|
||||
groups: true,
|
||||
variables: true,
|
||||
@@ -58,7 +58,7 @@ export const getLinkedTypebots = authenticatedProcedure
|
||||
throw new TRPCError({ code: 'NOT_FOUND', message: 'No typebot found' })
|
||||
|
||||
const linkedTypebotIds =
|
||||
typebotSchema.shape.groups
|
||||
typebotSchema._def.schema.shape.groups
|
||||
.parse(typebot.groups)
|
||||
.flatMap((group) => group.blocks)
|
||||
.reduce<string[]>(
|
||||
@@ -102,8 +102,10 @@ export const getLinkedTypebots = authenticatedProcedure
|
||||
})
|
||||
.map((typebot) => ({
|
||||
...typebot,
|
||||
groups: typebotSchema.shape.groups.parse(typebot.groups),
|
||||
variables: typebotSchema.shape.variables.parse(typebot.variables),
|
||||
groups: typebotSchema._def.schema.shape.groups.parse(typebot.groups),
|
||||
variables: typebotSchema._def.schema.shape.variables.parse(
|
||||
typebot.variables
|
||||
),
|
||||
}))
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user