1
10import { FatalError } from "./classify.js";
11import { adapterFor } from "./integration-registry.js";
12import type { ActionExecutor, ActionResult } from "./types.js";
13
14const executor: ActionExecutor = {
15 type: "CALL_INTEGRATION",
16 async execute(cfg, ctx, deps): Promise<ActionResult> {
17 const integrationId = cfg.integrationId as string;
18 const integration = await deps.prisma.integration.findFirst({
19 where: { id: integrationId, workspaceId: ctx.workspaceId },
20 select: { id: true, provider: true, status: true }
21 });
22 if (!integration) throw new FatalError("INTEGRATION_NOT_FOUND", `integration ${integrationId} not found`);
23
24 const adapter = adapterFor(integration.provider);
25 if (!adapter) {
26 throw new FatalError("INTEGRATION_NOT_AVAILABLE", `no adapter for provider "${integration.provider}" (Phase 13)`);
27 }
28
29 const result = await adapter.execute(cfg as never, ctx, deps);
30 return result;
31 }
32};
33
34export default executor;
35