🧑💻 (forge) Make credentials in fetch function optionnal
This commit is contained in:
@@ -21,8 +21,6 @@ export const fetchSelectItems = authenticatedProcedure
|
|||||||
input: { workspaceId, integrationId, fetcherId, options },
|
input: { workspaceId, integrationId, fetcherId, options },
|
||||||
ctx: { user },
|
ctx: { user },
|
||||||
}) => {
|
}) => {
|
||||||
if (!options.credentialsId) return { items: [] }
|
|
||||||
|
|
||||||
const workspace = await prisma.workspace.findFirst({
|
const workspace = await prisma.workspace.findFirst({
|
||||||
where: { id: workspaceId },
|
where: { id: workspaceId },
|
||||||
select: {
|
select: {
|
||||||
@@ -31,16 +29,18 @@ export const fetchSelectItems = authenticatedProcedure
|
|||||||
userId: true,
|
userId: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
credentials: {
|
credentials: options.credentialsId
|
||||||
where: {
|
? {
|
||||||
id: options.credentialsId,
|
where: {
|
||||||
},
|
id: options.credentialsId,
|
||||||
select: {
|
},
|
||||||
id: true,
|
select: {
|
||||||
data: true,
|
id: true,
|
||||||
iv: true,
|
data: true,
|
||||||
},
|
iv: true,
|
||||||
},
|
},
|
||||||
|
}
|
||||||
|
: undefined,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -50,11 +50,11 @@ export const fetchSelectItems = authenticatedProcedure
|
|||||||
message: 'No workspace found',
|
message: 'No workspace found',
|
||||||
})
|
})
|
||||||
|
|
||||||
const credentials = workspace.credentials.at(0)
|
const credentials = workspace.credentials?.at(0)
|
||||||
|
|
||||||
if (!credentials) return { items: [] }
|
const credentialsData = credentials
|
||||||
|
? await decrypt(credentials.data, credentials.iv)
|
||||||
const credentialsData = await decrypt(credentials.data, credentials.iv)
|
: undefined
|
||||||
|
|
||||||
const blockDef = forgedBlocks[integrationId]
|
const blockDef = forgedBlocks[integrationId]
|
||||||
|
|
||||||
@@ -67,7 +67,8 @@ export const fetchSelectItems = authenticatedProcedure
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
items: await fetcher.fetch({
|
items: await fetcher.fetch({
|
||||||
credentials: credentialsData,
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
credentials: credentialsData as any,
|
||||||
options,
|
options,
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user