6071 return only updated fields of records in zapier update trigger (#8193)
- move webhook triggers into `entity-events-to-db.listener.ts` - refactor event management - add a `@OnDatabaseEvent` decorator to manage database events - add updatedFields in updated events - update openApi webhooks docs - update zapier integration
This commit is contained in:
@ -16,6 +16,7 @@ import {
|
||||
WorkflowVersionWorkspaceEntity,
|
||||
} from 'src/modules/workflow/common/standard-objects/workflow-version.workspace-entity';
|
||||
import { WorkflowWorkspaceEntity } from 'src/modules/workflow/common/standard-objects/workflow.workspace-entity';
|
||||
import { DatabaseEventAction } from 'src/engine/api/graphql/graphql-query-runner/enums/database-event-action';
|
||||
|
||||
@WorkspaceQueryHook({
|
||||
key: `workflow.createMany`,
|
||||
@ -62,7 +63,7 @@ export class WorkflowCreateManyPostQueryHook
|
||||
});
|
||||
|
||||
this.workspaceEventEmitter.emit(
|
||||
`workflowVersion.created`,
|
||||
`workflowVersion.${DatabaseEventAction.CREATED}`,
|
||||
workflowVersionsToCreate.map((workflowVersionToCreate) => {
|
||||
return {
|
||||
userId: authContext.user?.id,
|
||||
|
||||
@ -16,6 +16,7 @@ import {
|
||||
WorkflowVersionWorkspaceEntity,
|
||||
} from 'src/modules/workflow/common/standard-objects/workflow-version.workspace-entity';
|
||||
import { WorkflowWorkspaceEntity } from 'src/modules/workflow/common/standard-objects/workflow.workspace-entity';
|
||||
import { DatabaseEventAction } from 'src/engine/api/graphql/graphql-query-runner/enums/database-event-action';
|
||||
|
||||
@WorkspaceQueryHook({
|
||||
key: `workflow.createOne`,
|
||||
@ -58,7 +59,7 @@ export class WorkflowCreateOnePostQueryHook
|
||||
});
|
||||
|
||||
this.workspaceEventEmitter.emit(
|
||||
`workflowVersion.created`,
|
||||
`workflowVersion.${DatabaseEventAction.CREATED}`,
|
||||
[
|
||||
{
|
||||
userId: authContext.user?.id,
|
||||
|
||||
@ -6,10 +6,11 @@ import { ObjectRecordDestroyEvent } from 'src/engine/core-modules/event-emitter/
|
||||
import { ObjectRecordUpdateEvent } from 'src/engine/core-modules/event-emitter/types/object-record-update.event';
|
||||
import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity';
|
||||
import { generateFakeObjectRecord } from 'src/modules/workflow/workflow-builder/utils/generate-fake-object-record';
|
||||
import { DatabaseEventAction } from 'src/engine/api/graphql/graphql-query-runner/enums/database-event-action';
|
||||
|
||||
export const generateFakeObjectRecordEvent = <Entity>(
|
||||
objectMetadataEntity: ObjectMetadataEntity,
|
||||
action: 'created' | 'updated' | 'deleted' | 'destroyed',
|
||||
action: DatabaseEventAction,
|
||||
):
|
||||
| ObjectRecordCreateEvent<Entity>
|
||||
| ObjectRecordUpdateEvent<Entity>
|
||||
@ -21,7 +22,7 @@ export const generateFakeObjectRecordEvent = <Entity>(
|
||||
|
||||
const after = generateFakeObjectRecord<Entity>(objectMetadataEntity);
|
||||
|
||||
if (action === 'created') {
|
||||
if (action === DatabaseEventAction.CREATED) {
|
||||
return {
|
||||
recordId,
|
||||
userId,
|
||||
@ -35,7 +36,7 @@ export const generateFakeObjectRecordEvent = <Entity>(
|
||||
|
||||
const before = generateFakeObjectRecord<Entity>(objectMetadataEntity);
|
||||
|
||||
if (action === 'updated') {
|
||||
if (action === DatabaseEventAction.UPDATED) {
|
||||
return {
|
||||
recordId,
|
||||
userId,
|
||||
@ -44,12 +45,11 @@ export const generateFakeObjectRecordEvent = <Entity>(
|
||||
properties: {
|
||||
before,
|
||||
after,
|
||||
diff: after,
|
||||
},
|
||||
} satisfies ObjectRecordUpdateEvent<Entity>;
|
||||
}
|
||||
|
||||
if (action === 'deleted') {
|
||||
if (action === DatabaseEventAction.DELETED) {
|
||||
return {
|
||||
recordId,
|
||||
userId,
|
||||
@ -61,7 +61,7 @@ export const generateFakeObjectRecordEvent = <Entity>(
|
||||
} satisfies ObjectRecordDeleteEvent<Entity>;
|
||||
}
|
||||
|
||||
if (action === 'destroyed') {
|
||||
if (action === DatabaseEventAction.DESTROYED) {
|
||||
return {
|
||||
recordId,
|
||||
userId,
|
||||
|
||||
@ -5,7 +5,6 @@ import { join } from 'path';
|
||||
|
||||
import { Repository } from 'typeorm';
|
||||
|
||||
import { generateFakeObjectRecordEvent } from 'src/engine/core-modules/event-emitter/utils/generate-fake-object-record-event';
|
||||
import { INDEX_FILE_NAME } from 'src/engine/core-modules/serverless/drivers/constants/index-file-name';
|
||||
import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity';
|
||||
import { ServerlessFunctionService } from 'src/engine/metadata-modules/serverless-function/serverless-function.service';
|
||||
@ -21,6 +20,9 @@ import {
|
||||
WorkflowTriggerType,
|
||||
} from 'src/modules/workflow/workflow-trigger/types/workflow-trigger.type';
|
||||
import { isDefined } from 'src/utils/is-defined';
|
||||
import { checkStringIsDatabaseEventAction } from 'src/engine/api/graphql/graphql-query-runner/utils/check-string-is-database-event-action';
|
||||
import { generateFakeObjectRecordEvent } from 'src/modules/workflow/workflow-builder/utils/generate-fake-object-record-event';
|
||||
import { DatabaseEventAction } from 'src/engine/api/graphql/graphql-query-runner/enums/database-event-action';
|
||||
|
||||
@Injectable()
|
||||
export class WorkflowBuilderService {
|
||||
@ -92,7 +94,7 @@ export class WorkflowBuilderService {
|
||||
}) {
|
||||
const [nameSingular, action] = eventName.split('.');
|
||||
|
||||
if (!['created', 'updated', 'deleted', 'destroyed'].includes(action)) {
|
||||
if (!checkStringIsDatabaseEventAction(action)) {
|
||||
return {};
|
||||
}
|
||||
|
||||
@ -110,7 +112,7 @@ export class WorkflowBuilderService {
|
||||
|
||||
return generateFakeObjectRecordEvent(
|
||||
objectMetadata,
|
||||
action as 'created' | 'updated' | 'deleted' | 'destroyed',
|
||||
action as DatabaseEventAction,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { OnEvent } from '@nestjs/event-emitter';
|
||||
|
||||
import { ObjectRecordCreateEvent } from 'src/engine/core-modules/event-emitter/types/object-record-create.event';
|
||||
import { ObjectRecordDeleteEvent } from 'src/engine/core-modules/event-emitter/types/object-record-delete.event';
|
||||
@ -17,6 +16,8 @@ import {
|
||||
WorkflowVersionEventType,
|
||||
WorkflowVersionStatusUpdate,
|
||||
} from 'src/modules/workflow/workflow-status/jobs/workflow-statuses-update.job';
|
||||
import { OnDatabaseEvent } from 'src/engine/api/graphql/graphql-query-runner/decorators/on-database-event.decorator';
|
||||
import { DatabaseEventAction } from 'src/engine/api/graphql/graphql-query-runner/enums/database-event-action';
|
||||
|
||||
@Injectable()
|
||||
export class WorkflowVersionStatusListener {
|
||||
@ -25,7 +26,7 @@ export class WorkflowVersionStatusListener {
|
||||
private readonly messageQueueService: MessageQueueService,
|
||||
) {}
|
||||
|
||||
@OnEvent('workflowVersion.created')
|
||||
@OnDatabaseEvent('workflowVersion', DatabaseEventAction.CREATED)
|
||||
async handleWorkflowVersionCreated(
|
||||
payload: WorkspaceEventBatch<
|
||||
ObjectRecordCreateEvent<WorkflowVersionWorkspaceEntity>
|
||||
@ -53,7 +54,7 @@ export class WorkflowVersionStatusListener {
|
||||
);
|
||||
}
|
||||
|
||||
@OnEvent('workflowVersion.statusUpdated')
|
||||
@OnDatabaseEvent('workflowVersion', DatabaseEventAction.UPDATED)
|
||||
async handleWorkflowVersionUpdated(
|
||||
payload: WorkspaceEventBatch<WorkflowVersionStatusUpdate>,
|
||||
): Promise<void> {
|
||||
@ -67,7 +68,7 @@ export class WorkflowVersionStatusListener {
|
||||
);
|
||||
}
|
||||
|
||||
@OnEvent('workflowVersion.deleted')
|
||||
@OnDatabaseEvent('workflowVersion', DatabaseEventAction.DELETED)
|
||||
async handleWorkflowVersionDeleted(
|
||||
payload: WorkspaceEventBatch<
|
||||
ObjectRecordDeleteEvent<WorkflowVersionWorkspaceEntity>
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
import { Injectable, Logger } from '@nestjs/common';
|
||||
import { OnEvent } from '@nestjs/event-emitter';
|
||||
|
||||
import { ObjectRecordCreateEvent } from 'src/engine/core-modules/event-emitter/types/object-record-create.event';
|
||||
import { ObjectRecordDeleteEvent } from 'src/engine/core-modules/event-emitter/types/object-record-delete.event';
|
||||
@ -17,6 +16,8 @@ import {
|
||||
WorkflowEventTriggerJob,
|
||||
WorkflowEventTriggerJobData,
|
||||
} from 'src/modules/workflow/workflow-trigger/jobs/workflow-event-trigger.job';
|
||||
import { OnDatabaseEvent } from 'src/engine/api/graphql/graphql-query-runner/decorators/on-database-event.decorator';
|
||||
import { DatabaseEventAction } from 'src/engine/api/graphql/graphql-query-runner/enums/database-event-action';
|
||||
|
||||
@Injectable()
|
||||
export class DatabaseEventTriggerListener {
|
||||
@ -29,28 +30,28 @@ export class DatabaseEventTriggerListener {
|
||||
private readonly isFeatureFlagEnabledService: FeatureFlagService,
|
||||
) {}
|
||||
|
||||
@OnEvent('*.created')
|
||||
@OnDatabaseEvent('*', DatabaseEventAction.CREATED)
|
||||
async handleObjectRecordCreateEvent(
|
||||
payload: WorkspaceEventBatch<ObjectRecordCreateEvent<any>>,
|
||||
) {
|
||||
await this.handleEvent(payload);
|
||||
}
|
||||
|
||||
@OnEvent('*.updated')
|
||||
@OnDatabaseEvent('*', DatabaseEventAction.UPDATED)
|
||||
async handleObjectRecordUpdateEvent(
|
||||
payload: WorkspaceEventBatch<ObjectRecordUpdateEvent<any>>,
|
||||
) {
|
||||
await this.handleEvent(payload);
|
||||
}
|
||||
|
||||
@OnEvent('*.deleted')
|
||||
@OnDatabaseEvent('*', DatabaseEventAction.DELETED)
|
||||
async handleObjectRecordDeleteEvent(
|
||||
payload: WorkspaceEventBatch<ObjectRecordDeleteEvent<any>>,
|
||||
) {
|
||||
await this.handleEvent(payload);
|
||||
}
|
||||
|
||||
@OnEvent('*.destroyed')
|
||||
@OnDatabaseEvent('*', DatabaseEventAction.DESTROYED)
|
||||
async handleObjectRecordDestroyEvent(
|
||||
payload: WorkspaceEventBatch<ObjectRecordDestroyEvent<any>>,
|
||||
) {
|
||||
|
||||
@ -25,6 +25,7 @@ import {
|
||||
import { WorkflowTriggerType } from 'src/modules/workflow/workflow-trigger/types/workflow-trigger.type';
|
||||
import { assertVersionCanBeActivated } from 'src/modules/workflow/workflow-trigger/utils/assert-version-can-be-activated.util';
|
||||
import { assertNever } from 'src/utils/assert';
|
||||
import { DatabaseEventAction } from 'src/engine/api/graphql/graphql-query-runner/enums/database-event-action';
|
||||
|
||||
@Injectable()
|
||||
export class WorkflowTriggerWorkspaceService {
|
||||
@ -362,7 +363,7 @@ export class WorkflowTriggerWorkspaceService {
|
||||
}
|
||||
|
||||
this.workspaceEventEmitter.emit(
|
||||
'workflowVersion.statusUpdated',
|
||||
`workflowVersion.${DatabaseEventAction.UPDATED}`,
|
||||
[
|
||||
{
|
||||
workflowId,
|
||||
|
||||
Reference in New Issue
Block a user