1
import { cloneDeep } from 'lodash'
2
import { StatusCodes } from 'http-status-codes'
3
import { getRunningExpressApp } from '../../utils/getRunningExpressApp'
4
import { InternalFlowiseError } from '../../errors/internalFlowiseError'
5
import { getErrorMessage } from '../../errors/utils'
7
// Get all component credentials
8
const getAllComponentsCredentials = async (): Promise<any> => {
10
const appServer = getRunningExpressApp()
12
for (const credName in appServer.nodesPool.componentCredentials) {
13
const clonedCred = cloneDeep(appServer.nodesPool.componentCredentials[credName])
14
dbResponse.push(clonedCred)
18
throw new InternalFlowiseError(
19
StatusCodes.INTERNAL_SERVER_ERROR,
20
`Error: componentsCredentialsService.getAllComponentsCredentials - ${getErrorMessage(error)}`
25
const getComponentByName = async (credentialName: string) => {
27
const appServer = getRunningExpressApp()
28
if (!credentialName.includes('&')) {
29
if (Object.prototype.hasOwnProperty.call(appServer.nodesPool.componentCredentials, credentialName)) {
30
return appServer.nodesPool.componentCredentials[credentialName]
32
throw new InternalFlowiseError(
33
StatusCodes.NOT_FOUND,
34
`Error: componentsCredentialsService.getSingleComponentsCredential - Credential ${credentialName} not found`
39
for (const name of credentialName.split('&')) {
40
if (Object.prototype.hasOwnProperty.call(appServer.nodesPool.componentCredentials, name)) {
41
dbResponse.push(appServer.nodesPool.componentCredentials[name])
43
throw new InternalFlowiseError(
44
StatusCodes.NOT_FOUND,
45
`Error: componentsCredentialsService.getSingleComponentsCredential - Credential ${name} not found`
52
throw new InternalFlowiseError(
53
StatusCodes.INTERNAL_SERVER_ERROR,
54
`Error: componentsCredentialsService.getSingleComponentsCredential - ${getErrorMessage(error)}`
59
// Returns specific component credential icon via name
60
const getSingleComponentsCredentialIcon = async (credentialName: string) => {
62
const appServer = getRunningExpressApp()
63
if (Object.prototype.hasOwnProperty.call(appServer.nodesPool.componentCredentials, credentialName)) {
64
const credInstance = appServer.nodesPool.componentCredentials[credentialName]
65
if (credInstance.icon === undefined) {
66
throw new InternalFlowiseError(StatusCodes.NOT_FOUND, `Credential ${credentialName} icon not found`)
69
if (credInstance.icon.endsWith('.svg') || credInstance.icon.endsWith('.png') || credInstance.icon.endsWith('.jpg')) {
70
const filepath = credInstance.icon
73
throw new InternalFlowiseError(StatusCodes.INTERNAL_SERVER_ERROR, `Credential ${credentialName} icon is missing icon`)
76
throw new InternalFlowiseError(StatusCodes.NOT_FOUND, `Credential ${credentialName} not found`)
79
throw new InternalFlowiseError(
80
StatusCodes.INTERNAL_SERVER_ERROR,
81
`Error: componentsCredentialsService.getSingleComponentsCredentialIcon - ${getErrorMessage(error)}`
87
getAllComponentsCredentials,
89
getSingleComponentsCredentialIcon