2
0

🐛 (forge) Fix incompatible auth schemas when finding fetchers

Closes #1758
This commit is contained in:
Baptiste Arnaud
2024-09-04 11:43:02 +02:00
parent 2a767e02b0
commit 18c6381a77
4 changed files with 31 additions and 21 deletions

View File

@ -6,6 +6,7 @@ import { isReadWorkspaceFobidden } from '@/features/workspace/helpers/isReadWork
import { forgedBlocks } from '@typebot.io/forge-repository/definitions'
import { forgedBlockIds } from '@typebot.io/forge-repository/constants'
import { decrypt } from '@typebot.io/lib/api/encryption/decrypt'
import { getFetchers } from '../helpers/getFetchers'
export const fetchSelectItems = authenticatedProcedure
.input(
@ -58,10 +59,9 @@ export const fetchSelectItems = authenticatedProcedure
const blockDef = forgedBlocks[integrationId]
const fetchers = (blockDef?.fetchers ?? []).concat(
blockDef?.actions.flatMap((action) => action.fetchers ?? []) ?? []
const fetcher = getFetchers(blockDef).find(
(fetcher) => fetcher.id === fetcherId
)
const fetcher = fetchers.find((fetcher) => fetcher.id === fetcherId)
if (!fetcher) return { items: [] }

View File

@ -17,6 +17,7 @@ import {
ForgedBlock,
} from '@typebot.io/forge-repository/types'
import { ReactNode, useMemo } from 'react'
import { findFetcher } from '../helpers/findFetcher'
type Props = {
blockDef: ForgedBlockDefinition
@ -51,32 +52,25 @@ export const ForgeSelectInput = ({
const { workspace } = useWorkspace()
const { showToast } = useToast()
const baseFetcher = useMemo(() => {
const fetchers = blockDef.fetchers ?? []
return fetchers.find((fetcher) => fetcher.id === fetcherId)
}, [blockDef.fetchers, fetcherId])
const actionFetcher = useMemo(() => {
if (baseFetcher) return
const fetchers = blockDef.actions.flatMap((action) => action.fetchers ?? [])
return fetchers.find((fetcher) => fetcher.id === fetcherId)
}, [baseFetcher, blockDef.actions, fetcherId])
const fetcher = useMemo(
() => findFetcher(blockDef, fetcherId),
[blockDef, fetcherId]
)
const { data } = trpc.forge.fetchSelectItems.useQuery(
{
integrationId: blockDef.id,
options: pick(options, [
...(actionFetcher ? ['action'] : []),
...(blockDef.auth ? ['credentialsId'] : []),
...((baseFetcher
? baseFetcher.dependencies
: actionFetcher?.dependencies) ?? []),
]),
options: pick(
options,
(blockDef.auth ? ['credentialsId'] : []).concat(
fetcher?.dependencies ?? []
)
),
workspaceId: workspace?.id as string,
fetcherId,
},
{
enabled: !!workspace?.id && (!!baseFetcher || !!actionFetcher),
enabled: !!workspace?.id && !!fetcher,
onError: (error) => {
showToast({
description: error.message,

View File

@ -0,0 +1,7 @@
import { ForgedBlockDefinition } from '@typebot.io/forge-repository/types'
import { getFetchers } from './getFetchers'
export const findFetcher = (
blockDef: ForgedBlockDefinition,
fetcherId: string
) => getFetchers(blockDef).find((fetcher) => fetcher.id === fetcherId)

View File

@ -0,0 +1,9 @@
import { FetcherDefinition, AuthDefinition } from '@typebot.io/forge'
import { ForgedBlockDefinition } from '@typebot.io/forge-repository/types'
export const getFetchers = (blockDef: ForgedBlockDefinition) =>
blockDef.fetchers?.concat(
blockDef.actions.flatMap(
(action) => (action.fetchers ?? []) as FetcherDefinition<AuthDefinition>[]
)
) ?? []