2
0

🚸 (webhook) Improve header and query params parsing

This commit is contained in:
Baptiste Arnaud
2023-12-24 11:02:48 +01:00
parent 6e076e9fb8
commit 3bbaf670a2
2 changed files with 6 additions and 18 deletions

View File

@ -1,5 +1,4 @@
import { import {
KeyValue,
PublicTypebot, PublicTypebot,
ResultValues, ResultValues,
Typebot, Typebot,
@ -28,6 +27,7 @@ import {
} from '@typebot.io/schemas/features/blocks/integrations/webhook/constants' } from '@typebot.io/schemas/features/blocks/integrations/webhook/constants'
import { getBlockById } from '@typebot.io/lib/getBlockById' import { getBlockById } from '@typebot.io/lib/getBlockById'
import { import {
convertKeyValueTableToObject,
longReqTimeoutWhitelist, longReqTimeoutWhitelist,
longRequestTimeout, longRequestTimeout,
responseDefaultTimeout, responseDefaultTimeout,
@ -280,20 +280,6 @@ const getBodyContent =
: body ?? undefined : body ?? undefined
} }
const convertKeyValueTableToObject = (
keyValues: KeyValue[] | undefined,
variables: Variable[]
) => {
if (!keyValues) return
return keyValues.reduce((object, item) => {
if (!item.key) return {}
return {
...object,
[item.key]: parseVariables(variables)(item.value ?? ''),
}
}, {})
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any // eslint-disable-next-line @typescript-eslint/no-explicit-any
const safeJsonParse = (json: string): { data: any; isJson: boolean } => { const safeJsonParse = (json: string): { data: any; isJson: boolean } => {
try { try {

View File

@ -265,16 +265,18 @@ const getBodyContent = async ({
: body ?? undefined : body ?? undefined
} }
const convertKeyValueTableToObject = ( export const convertKeyValueTableToObject = (
keyValues: KeyValue[] | undefined, keyValues: KeyValue[] | undefined,
variables: Variable[] variables: Variable[]
) => { ) => {
if (!keyValues) return if (!keyValues) return
return keyValues.reduce((object, item) => { return keyValues.reduce((object, item) => {
if (!item.key) return {} const key = parseVariables(variables)(item.key)
const value = parseVariables(variables)(item.value)
if (isEmpty(key) || isEmpty(value)) return object
return { return {
...object, ...object,
[item.key]: parseVariables(variables)(item.value ?? ''), [key]: value,
} }
}, {}) }, {})
} }