diff --git a/packages/server/src/api/controllers/row/index.ts b/packages/server/src/api/controllers/row/index.ts index 4d40476b7c..d3b1d3d5b2 100644 --- a/packages/server/src/api/controllers/row/index.ts +++ b/packages/server/src/api/controllers/row/index.ts @@ -7,6 +7,7 @@ import * as internal from "./internal" import * as external from "./external" import { isExternalTableID } from "../../../integrations/utils" import { + AutomationEventType, Ctx, DeleteRow, DeleteRowRequest, @@ -64,15 +65,15 @@ export async function patch( ctx.throw(404, "Row not found") } ctx.status = 200 - ctx.eventEmitter && - ctx.eventEmitter.emitRow({ - eventName: `row:update`, - appId, - row, - table, - oldRow, - user: sdk.users.getUserContextBindings(ctx.user), - }) + + ctx.eventEmitter?.emitRow({ + eventName: AutomationEventType.ROW_UPDATE, + appId, + row, + table, + oldRow, + user: sdk.users.getUserContextBindings(ctx.user), + }) ctx.message = `${table.name} updated successfully.` ctx.body = row gridSocket?.emitRowUpdate(ctx, row) diff --git a/packages/server/src/events/AutomationEmitter.ts b/packages/server/src/events/AutomationEmitter.ts index a63273bdc0..ec1ea7f28c 100644 --- a/packages/server/src/events/AutomationEmitter.ts +++ b/packages/server/src/events/AutomationEmitter.ts @@ -1,12 +1,12 @@ import { rowEmission, tableEmission } from "./utils" import mainEmitter from "./index" import env from "../environment" -import { Table, Row, DocumentType, App } from "@budibase/types" +import { Table, Row, DocumentType, App, ContextEmitter } from "@budibase/types" import { context } from "@budibase/backend-core" const MAX_AUTOMATIONS_ALLOWED = 5 -class AutomationEmitter { +class AutomationEmitter implements ContextEmitter { chainCount: number metadata: { automationChainCount: number } diff --git a/packages/types/src/sdk/koa.ts b/packages/types/src/sdk/koa.ts index a7df701171..8add047c0b 100644 --- a/packages/types/src/sdk/koa.ts +++ b/packages/types/src/sdk/koa.ts @@ -1,5 +1,14 @@ import { Context, Request } from "koa" -import { User, Role, UserRoles, Account, ConfigType } from "../documents" +import { + User, + Role, + UserRoles, + Account, + ConfigType, + Row, + Table, + AutomationEventType, +} from "../documents" import { FeatureFlag, License } from "../sdk" import { Files } from "formidable" @@ -40,6 +49,7 @@ export interface UserCtx extends Ctx { user: ContextUser roleId?: string + eventEmitter?: ContextEmitter } /** @@ -49,3 +59,12 @@ export interface UserCtx export interface BBContext extends Ctx { user?: ContextUser } + +export interface ContextEmitter { + emitRow: (params: { + eventName: AutomationEventType + appId: string + row: Row + table?: Table + }) => Promise +}