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

2.8 KB
Raw Blame
import { EventDestination, EventDestinationFormat, EventDestinationScope, Platform, Project } from '@activepieces/shared'
import { EntitySchema } from 'typeorm'
import { z } from 'zod'
import { ApIdSchema, BaseColumnSchemaPart } from '../database/database-common'
import { EncryptedObject } from '../helper/encryption'

type WithoutHeaders<T> = T extends unknown ? Omit<T, 'headers'> : never

export const StoredEventDestinationHeaders = z.object({
    url: z.string(),
    values: z.record(z.string(), EncryptedObject),
})

export type StoredEventDestinationHeaders = z.infer<typeof StoredEventDestinationHeaders>

export type EventDestinationRow = WithoutHeaders<EventDestination> & {
    headers: StoredEventDestinationHeaders | null
}

export type EventDestinationSchema = EventDestinationRow & {
    platform: Platform
    project: Project
}

export const EventDestinationEntity = new EntitySchema<EventDestinationSchema>({
    name: 'event_destination',
    columns: {
        ...BaseColumnSchemaPart,
        platformId: {
            ...ApIdSchema,
            nullable: false,
        },
        projectId: {
            ...ApIdSchema,
            nullable: true,
        },
        scope: {
            type: String,
            nullable: false,
        },
        events: {
            type: String,
            array: true,
            nullable: false,
        },
        url: {
            type: String,
            nullable: false,
        },
        enabled: {
            type: Boolean,
            nullable: false,
            default: true,
        },
        headers: {
            type: 'jsonb',
            nullable: true,
        },
        format: {
            type: String,
            nullable: false,
            default: EventDestinationFormat.RAW,
        },
    },
    indices: [
        {
            name: 'idx_event_destination_platform_scope',
            columns: ['platformId'],
            where: `scope = '${EventDestinationScope.PLATFORM}'`,
        },
        {
            name: 'idx_event_destination_project_scope',
            columns: ['projectId'],
            where: `scope = '${EventDestinationScope.PROJECT}'`,
        },
    ],
    relations: {
        platform: {
            type: 'many-to-one',
            target: 'platform',
            cascade: true,
            onDelete: 'CASCADE',
            joinColumn: {
                name: 'platformId',
                foreignKeyConstraintName: 'fk_event_destination_platform_id',
            },
        },
        project: {
            type: 'many-to-one',
            target: 'project',
            cascade: true,
            onDelete: 'CASCADE',
            joinColumn: {
                name: 'projectId',
                foreignKeyConstraintName: 'fk_event_destination_project_id',
            },
        },
    },
})