🐛 (forge) Fix incompatible auth schemas when finding fetchers
Closes #1758
This commit is contained in:
@ -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: [] }
|
||||
|
||||
|
@ -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,
|
||||
|
7
apps/builder/src/features/forge/helpers/findFetcher.ts
Normal file
7
apps/builder/src/features/forge/helpers/findFetcher.ts
Normal 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)
|
9
apps/builder/src/features/forge/helpers/getFetchers.ts
Normal file
9
apps/builder/src/features/forge/helpers/getFetchers.ts
Normal 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>[]
|
||||
)
|
||||
) ?? []
|
Reference in New Issue
Block a user