Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/features/executions/components/zoho-crm/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof zohoCrmChannel>,
["status"]
>

export async function fetchZohoCrmRealtimeToken(nodeId: string): Promise<ZohoCrmToken> {
export async function fetchZohoCrmRealtimeToken(nodeId: string) {
const token = await getSubscriptionToken(inngest, {
channel: zohoCrmChannel(nodeId),
channel: zohoCrmChannelName(nodeId),
topics: ["status"],
})
return token
Expand Down
16 changes: 9 additions & 7 deletions src/features/executions/components/zoho-crm/channels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}>()
)
6 changes: 3 additions & 3 deletions src/features/executions/components/zoho-crm/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions src/server/routers/zoho-crm.router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 }
Expand Down
Loading