Skip to content

AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents

1.2 KB
Raw Blame
import { assertNotNullOrUndefined } from '@activepieces/core-utils'
import { EnginePrincipal, GetVariableForWorkerRequestParams, RevealVariableResponse } from '@activepieces/shared'
import { FastifyPluginAsyncZod } from 'fastify-type-provider-zod'
import { StatusCodes } from 'http-status-codes'
import { securityAccess } from '../core/security/authorization/fastify-security'
import { variableService } from './variable.service'

export const variableWorkerController: FastifyPluginAsyncZod = async (app) => {
    app.get('/:name', GetVariableRequest, async (request): Promise<RevealVariableResponse> => {
        const enginePrincipal = (request.principal as EnginePrincipal)
        assertNotNullOrUndefined(enginePrincipal.projectId, 'projectId')
        const value = await variableService(request.log).getDecryptedValueForWorker({
            projectId: enginePrincipal.projectId,
            name: request.params.name,
        })
        return { value }
    })
}

const GetVariableRequest = {
    config: {
        security: securityAccess.engine(),
    },
    schema: {
        params: GetVariableForWorkerRequestParams,
        response: {
            [StatusCodes.OK]: RevealVariableResponse,
        },
    },
}