2
0

(credentials) Add credentials management menu in workspace settings

Closes #1567
This commit is contained in:
Baptiste Arnaud
2024-07-16 15:11:48 +02:00
parent db628cd051
commit c6005c49a2
81 changed files with 3582 additions and 1704 deletions

View File

@ -1,6 +1,10 @@
// Do not edit this file manually
import { parseBlockCredentials, parseBlockSchema } from '@typebot.io/forge'
import { anthropicBlock } from '.'
import { auth } from './auth'
export const anthropicBlockSchema = parseBlockSchema(anthropicBlock)
export const anthropicCredentialsSchema = parseBlockCredentials(anthropicBlock)
export const anthropicCredentialsSchema = parseBlockCredentials(
anthropicBlock.id,
auth.schema
)

View File

@ -1,6 +1,5 @@
// Do not edit this file manually
import { parseBlockCredentials, parseBlockSchema } from '@typebot.io/forge'
import { parseBlockSchema } from '@typebot.io/forge'
import { calComBlock } from '.'
export const calComBlockSchema = parseBlockSchema(calComBlock)
export const calComCredentialsSchema = parseBlockCredentials(calComBlock)

View File

@ -1,6 +1,10 @@
// Do not edit this file manually
import { parseBlockCredentials, parseBlockSchema } from '@typebot.io/forge'
import { chatNodeBlock } from '.'
import { auth } from './auth'
export const chatNodeBlockSchema = parseBlockSchema(chatNodeBlock)
export const chatNodeCredentialsSchema = parseBlockCredentials(chatNodeBlock)
export const chatNodeCredentialsSchema = parseBlockCredentials(
chatNodeBlock.id,
auth.schema
)

View File

@ -1,6 +1,10 @@
// Do not edit this file manually
import { parseBlockCredentials, parseBlockSchema } from '@typebot.io/forge'
import { difyAiBlock } from '.'
import { auth } from './auth'
export const difyAiBlockSchema = parseBlockSchema(difyAiBlock)
export const difyAiCredentialsSchema = parseBlockCredentials(difyAiBlock)
export const difyAiCredentialsSchema = parseBlockCredentials(
difyAiBlock.id,
auth.schema
)

View File

@ -1,7 +1,10 @@
// Do not edit this file manually
import { parseBlockCredentials, parseBlockSchema } from '@typebot.io/forge'
import { elevenlabsBlock } from '.'
import { auth } from './auth'
export const elevenlabsBlockSchema = parseBlockSchema(elevenlabsBlock)
export const elevenlabsCredentialsSchema =
parseBlockCredentials(elevenlabsBlock)
export const elevenlabsCredentialsSchema = parseBlockCredentials(
elevenlabsBlock.id,
auth.schema
)

View File

@ -1,6 +1,10 @@
// Do not edit this file manually
import { parseBlockCredentials, parseBlockSchema } from '@typebot.io/forge'
import { mistralBlock } from '.'
import { auth } from './auth'
export const mistralBlockSchema = parseBlockSchema(mistralBlock)
export const mistralCredentialsSchema = parseBlockCredentials(mistralBlock)
export const mistralCredentialsSchema = parseBlockCredentials(
mistralBlock.id,
auth.schema
)

View File

@ -1,6 +1,10 @@
// Do not edit this file manually
import { parseBlockCredentials, parseBlockSchema } from '@typebot.io/forge'
import { nocodbBlock } from '.'
import { auth } from './auth'
export const nocodbBlockSchema = parseBlockSchema(nocodbBlock)
export const nocodbCredentialsSchema = parseBlockCredentials(nocodbBlock)
export const nocodbCredentialsSchema = parseBlockCredentials(
nocodbBlock.id,
auth.schema
)

View File

@ -1,7 +1,10 @@
// Do not edit this file manually
import { parseBlockCredentials, parseBlockSchema } from '@typebot.io/forge'
import { openRouterBlock } from '.'
import { auth } from './auth'
export const openRouterBlockSchema = parseBlockSchema(openRouterBlock)
export const openRouterCredentialsSchema =
parseBlockCredentials(openRouterBlock)
export const openRouterCredentialsSchema = parseBlockCredentials(
openRouterBlock.id,
auth.schema
)

View File

@ -1,6 +1,10 @@
// Do not edit this file manually
import { parseBlockCredentials, parseBlockSchema } from '@typebot.io/forge'
import { openAIBlock } from '.'
import { auth } from './auth'
export const openAIBlockSchema = parseBlockSchema(openAIBlock)
export const openAICredentialsSchema = parseBlockCredentials(openAIBlock)
export const openAICredentialsSchema = parseBlockCredentials(
openAIBlock.id,
auth.schema
)

View File

@ -1,6 +1,5 @@
// Do not edit this file manually
import { parseBlockCredentials, parseBlockSchema } from '@typebot.io/forge'
import { parseBlockSchema } from '@typebot.io/forge'
import { qrCodeBlock } from '.'
export const qrCodeBlockSchema = parseBlockSchema(qrCodeBlock)
export const qrCodeCredentialsSchema = parseBlockCredentials(qrCodeBlock)

View File

@ -1,7 +1,10 @@
// Do not edit this file manually
import { parseBlockCredentials, parseBlockSchema } from '@typebot.io/forge'
import { togetherAiBlock } from '.'
import { auth } from './auth'
export const togetherAiBlockSchema = parseBlockSchema(togetherAiBlock)
export const togetherAiCredentialsSchema =
parseBlockCredentials(togetherAiBlock)
export const togetherAiCredentialsSchema = parseBlockCredentials(
togetherAiBlock.id,
auth.schema
)

View File

@ -1,7 +1,10 @@
// Do not edit this file manually
import { parseBlockCredentials, parseBlockSchema } from '@typebot.io/forge'
import { zemanticAiBlock } from '.'
import { auth } from './auth'
export const zemanticAiBlockSchema = parseBlockSchema(zemanticAiBlock)
export const zemanticAiCredentialsSchema =
parseBlockCredentials(zemanticAiBlock)
export const zemanticAiCredentialsSchema = parseBlockCredentials(
zemanticAiBlock.id,
auth.schema
)

View File

@ -273,6 +273,7 @@ const createSchemasFile = async (
path: string,
{
id,
auth,
}: { id: string; name: string; auth: 'apiKey' | 'encryptedData' | 'none' }
) => {
const camelCaseName = camelize(id as string)
@ -280,11 +281,19 @@ const createSchemasFile = async (
join(path, 'schemas.ts'),
await prettier.format(
`// Do not edit this file manually
import { parseBlockCredentials, parseBlockSchema } from '@typebot.io/forge'
import { ${camelCaseName}Block } from '.'
import { ${
auth !== 'none' ? 'parseBlockCredentials,' : ''
} parseBlockSchema } from '@typebot.io/forge'
import { ${camelCaseName}Block } from '.'${
auth !== 'none' ? `\nimport { auth } from './auth'` : ''
}
export const ${camelCaseName}BlockSchema = parseBlockSchema(${camelCaseName}Block)
export const ${camelCaseName}CredentialsSchema = parseBlockCredentials(${camelCaseName}Block)`,
${
auth !== 'none'
? `export const ${camelCaseName}CredentialsSchema = parseBlockCredentials(${camelCaseName}Block.id, auth.schema)`
: ''
}`,
{ parser: 'typescript', ...prettierRc }
)
)

View File

@ -82,22 +82,18 @@ export const parseBlockSchema = <
})
}
export const parseBlockCredentials = <
I extends string,
A extends AuthDefinition,
O extends z.ZodObject<any>
>(
blockDefinition: BlockDefinition<I, A, O>
export const parseBlockCredentials = <I extends string>(
blockId: I,
authSchema: z.ZodObject<any>
) => {
if (!blockDefinition.auth) return null
return z.object({
id: z.string(),
type: z.literal(blockDefinition.id),
type: z.literal(blockId),
createdAt: z.date(),
workspaceId: z.string(),
name: z.string(),
iv: z.string(),
data: blockDefinition.auth.schema,
data: authSchema,
})
}

View File

@ -1,7 +1,5 @@
import { anthropicBlock } from '@typebot.io/anthropic-block'
import { anthropicCredentialsSchema } from '@typebot.io/anthropic-block/schemas'
import { calComBlock } from '@typebot.io/cal-com-block'
import { calComCredentialsSchema } from '@typebot.io/cal-com-block/schemas'
import { chatNodeBlock } from '@typebot.io/chat-node-block'
import { chatNodeCredentialsSchema } from '@typebot.io/chat-node-block/schemas'
import { difyAiBlock } from '@typebot.io/dify-ai-block'
@ -14,8 +12,6 @@ import { openRouterBlock } from '@typebot.io/open-router-block'
import { openRouterCredentialsSchema } from '@typebot.io/open-router-block/schemas'
import { openAIBlock } from '@typebot.io/openai-block'
import { openAICredentialsSchema } from '@typebot.io/openai-block/schemas'
import { qrCodeBlock } from '@typebot.io/qrcode-block'
import { qrCodeCredentialsSchema } from '@typebot.io/qrcode-block/schemas'
import { togetherAiBlock } from '@typebot.io/together-ai-block'
import { togetherAiCredentialsSchema } from '@typebot.io/together-ai-block/schemas'
import { zemanticAiBlock } from '@typebot.io/zemantic-ai-block'
@ -26,9 +22,7 @@ import { nocodbCredentialsSchema } from '@typebot.io/nocodb-block/schemas'
export const forgedCredentialsSchemas = {
[openAIBlock.id]: openAICredentialsSchema,
[zemanticAiBlock.id]: zemanticAiCredentialsSchema,
[calComBlock.id]: calComCredentialsSchema,
[chatNodeBlock.id]: chatNodeCredentialsSchema,
[qrCodeBlock.id]: qrCodeCredentialsSchema,
[difyAiBlock.id]: difyAiCredentialsSchema,
[mistralBlock.id]: mistralCredentialsSchema,
[elevenlabsBlock.id]: elevenlabsCredentialsSchema,