diff --git a/src/features/executions/components/zoho-crm/actions.ts b/src/features/executions/components/zoho-crm/actions.ts index 468b133..a2963a8 100644 --- a/src/features/executions/components/zoho-crm/actions.ts +++ b/src/features/executions/components/zoho-crm/actions.ts @@ -2,16 +2,16 @@ import { inngest } from "@/inngest/client" import { getSubscriptionToken, Realtime } from "@inngest/realtime" -import { zohoCrmChannel } from "./channels" +import { zohoCrmChannel, zohoCrmChannelName } from "./channels" export type ZohoCrmToken = Realtime.Token< ReturnType, ["status"] > -export async function fetchZohoCrmRealtimeToken(nodeId: string): Promise { +export async function fetchZohoCrmRealtimeToken(nodeId: string) { const token = await getSubscriptionToken(inngest, { - channel: zohoCrmChannel(nodeId), + channel: zohoCrmChannelName(nodeId), topics: ["status"], }) return token diff --git a/src/features/executions/components/zoho-crm/channels.ts b/src/features/executions/components/zoho-crm/channels.ts index c0a6f1b..62e9aa0 100644 --- a/src/features/executions/components/zoho-crm/channels.ts +++ b/src/features/executions/components/zoho-crm/channels.ts @@ -2,10 +2,12 @@ import { channel, topic } from "@inngest/realtime" export const ZOHO_CRM_CHANNEL = "zoho-crm" -export const zohoCrmChannel = (nodeId?: string) => - channel(`${ZOHO_CRM_CHANNEL}${nodeId ? `:${nodeId}` : ""}`).addTopic( - topic("status").type<{ - status: "loading" | "success" | "error" - nodeId: string - }>() - ) +export const zohoCrmChannelName = (nodeId?: string): `zoho-crm${string}` => + `${ZOHO_CRM_CHANNEL}${nodeId ? `:${nodeId}` : ""}` + +export const zohoCrmChannel = channel(() => ZOHO_CRM_CHANNEL).addTopic( + topic("status").type<{ + status: "loading" | "success" | "error" + nodeId: string + }>() +) diff --git a/src/features/executions/components/zoho-crm/executor.ts b/src/features/executions/components/zoho-crm/executor.ts index 2e743f5..668a476 100644 --- a/src/features/executions/components/zoho-crm/executor.ts +++ b/src/features/executions/components/zoho-crm/executor.ts @@ -194,7 +194,7 @@ export const zohoCrmExecutor: NodeExecutor = async ({ nodeId, context, step, pub }) return await step.run(`zoho-crm-${nodeId}-execute`, async () => { - await publish(zohoCrmChannel(nodeId).topic("status").data({ status: "loading", nodeId })) + await publish(zohoCrmChannel().status({ status: "loading", nodeId })) try { const { clientId, clientSecret, refreshToken, region } = JSON.parse(decrypt(config!.credential!.value)) as { @@ -796,11 +796,11 @@ export const zohoCrmExecutor: NodeExecutor = async ({ nodeId, context, step, pub } // end switch - await publish(zohoCrmChannel(nodeId).topic("status").data({ status: "success", nodeId })) + await publish(zohoCrmChannel().status({ status: "success", nodeId })) return { ...context, [variableName]: result } } catch (err) { - await publish(zohoCrmChannel(nodeId).topic("status").data({ status: "error", nodeId })) + await publish(zohoCrmChannel().status({ status: "error", nodeId })) if (config?.continueOnFail) { return { diff --git a/src/server/routers/zoho-crm.router.ts b/src/server/routers/zoho-crm.router.ts index 6069dbb..e6ef2df 100644 --- a/src/server/routers/zoho-crm.router.ts +++ b/src/server/routers/zoho-crm.router.ts @@ -5,7 +5,7 @@ import prisma from "@/lib/db" import { ZohoCrmOperation } from "@/generated/prisma" import { inngest } from "@/inngest/client" import { getSubscriptionToken } from "@inngest/realtime" -import { zohoCrmChannel } from "@/features/executions/components/zoho-crm/channels" +import { zohoCrmChannel, zohoCrmChannelName } from "@/features/executions/components/zoho-crm/channels" export const zohoCrmRouter = createTRPCRouter({ upsert: protectedProcedure @@ -149,7 +149,7 @@ export const zohoCrmRouter = createTRPCRouter({ .input(z.object({ nodeId: z.string() })) .query(async ({ input }) => { const token = await getSubscriptionToken(inngest, { - channel: zohoCrmChannel(input.nodeId), + channel: zohoCrmChannelName(input.nodeId), topics: ["status"], }) return { token }