/** * Signal sources CRUD export. * * @example * import sources from 'kody:@kody/kody-factory/signals/sources' * await sources({ action: 'list' }) * await sources({ action: 'create', id: 'my-sentry', name: 'Sentry alerts', kind: 'sentry', projectScope: ['kody'] }) * await sources({ action: 'get', id: 'my-sentry' }) * await sources({ action: 'update', id: 'my-sentry', enabled: false }) * await sources({ action: 'delete', id: 'my-sentry', confirm: true }) */ import { listSources, getSource, createSource, updateSource, deleteSourceById } from '../../signals/sources/index.ts' import type { SourceKind } from '../../signals/sources/types.ts' type SourcesInput = | { action: 'list'; enabled?: boolean; kind?: string; limit?: number } | { action: 'get'; id: string } | { action: 'create'; id: string; name: string; kind: SourceKind; projectScope?: string[]; note?: string; signingHeader?: string; enabled?: boolean; dryRun?: boolean } | { action: 'update'; id: string; name?: string; kind?: SourceKind; projectScope?: string[]; note?: string; signingHeader?: string; enabled?: boolean; dryRun?: boolean } | { action: 'delete'; id: string; confirm?: boolean } export default async function sources(input: SourcesInput) { switch (input.action) { case 'list': return { sources: await listSources({ enabled: input.enabled, kind: input.kind, limit: input.limit }) } case 'get': { const source = await getSource(input.id) if (!source) return { found: false, source: null } return { found: true, source } } case 'create': return createSource(input) case 'update': return updateSource(input) case 'delete': return deleteSourceById(input.id, { confirm: input.confirm }) default: throw new Error(`Unknown action: ${(input as { action: string }).action}`) } }