🐛 (webhook) Fix saving invalid webhook when duplicated
This commit is contained in:
@ -1,10 +1,11 @@
|
||||
import prisma from '@/lib/prisma'
|
||||
import { authenticatedProcedure } from '@/helpers/server/trpc'
|
||||
import { TRPCError } from '@trpc/server'
|
||||
import { typebotSchema } from '@typebot.io/schemas'
|
||||
import { InputBlockType, typebotSchema } from '@typebot.io/schemas'
|
||||
import { z } from 'zod'
|
||||
import { isWriteTypebotForbidden } from '../helpers/isWriteTypebotForbidden'
|
||||
import { sendTelemetryEvents } from '@typebot.io/lib/telemetry/sendTelemetryEvent'
|
||||
import { Plan } from '@typebot.io/prisma'
|
||||
|
||||
export const publishTypebot = authenticatedProcedure
|
||||
.meta({
|
||||
@ -34,6 +35,11 @@ export const publishTypebot = authenticatedProcedure
|
||||
include: {
|
||||
collaborators: true,
|
||||
publishedTypebot: true,
|
||||
workspace: {
|
||||
select: {
|
||||
plan: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
if (
|
||||
@ -42,6 +48,20 @@ export const publishTypebot = authenticatedProcedure
|
||||
)
|
||||
throw new TRPCError({ code: 'NOT_FOUND', message: 'Typebot not found' })
|
||||
|
||||
if (existingTypebot.workspace.plan === Plan.FREE) {
|
||||
const hasFileUploadBlocks = typebotSchema._def.schema.shape.groups
|
||||
.parse(existingTypebot.groups)
|
||||
.some((group) =>
|
||||
group.blocks.some((block) => block.type === InputBlockType.FILE)
|
||||
)
|
||||
|
||||
if (hasFileUploadBlocks)
|
||||
throw new TRPCError({
|
||||
code: 'BAD_REQUEST',
|
||||
message: "File upload blocks can't be published on the free plan",
|
||||
})
|
||||
}
|
||||
|
||||
if (existingTypebot.publishedTypebot)
|
||||
await prisma.publicTypebot.updateMany({
|
||||
where: {
|
||||
|
@ -5,11 +5,7 @@ import {
|
||||
InputBlockType,
|
||||
IntegrationBlockType,
|
||||
Typebot,
|
||||
Webhook,
|
||||
WebhookBlock,
|
||||
defaultWebhookAttributes,
|
||||
} from '@typebot.io/schemas'
|
||||
import { HttpMethod } from '@typebot.io/schemas/features/blocks/integrations/webhook/enums'
|
||||
|
||||
export const sanitizeSettings = (
|
||||
settings: Typebot['settings'],
|
||||
@ -47,8 +43,6 @@ const sanitizeBlock =
|
||||
),
|
||||
},
|
||||
}
|
||||
case IntegrationBlockType.WEBHOOK:
|
||||
return await sanitizeWebhookBlock(block)
|
||||
case IntegrationBlockType.GOOGLE_SHEETS:
|
||||
return {
|
||||
...block,
|
||||
@ -85,37 +79,6 @@ const sanitizeBlock =
|
||||
}
|
||||
}
|
||||
|
||||
const sanitizeWebhookBlock = async (
|
||||
block: WebhookBlock
|
||||
): Promise<WebhookBlock> => {
|
||||
if (!block.webhookId) return block
|
||||
const webhook = await prisma.webhook.findFirst({
|
||||
where: {
|
||||
id: block.webhookId,
|
||||
},
|
||||
})
|
||||
return {
|
||||
...block,
|
||||
webhookId: undefined,
|
||||
options: {
|
||||
...block.options,
|
||||
webhook: webhook
|
||||
? {
|
||||
id: webhook.id,
|
||||
url: webhook.url ?? undefined,
|
||||
method: (webhook.method as Webhook['method']) ?? HttpMethod.POST,
|
||||
headers: (webhook.headers as Webhook['headers']) ?? [],
|
||||
queryParams: (webhook.queryParams as Webhook['headers']) ?? [],
|
||||
body: webhook.body ?? undefined,
|
||||
}
|
||||
: {
|
||||
...defaultWebhookAttributes,
|
||||
id: block.webhookId ?? '',
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
const sanitizeCredentialsId =
|
||||
(workspaceId: string) =>
|
||||
async (credentialsId?: string): Promise<string | undefined> => {
|
||||
|
Reference in New Issue
Block a user