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:
martmull
2024-11-04 17:44:36 +01:00
committed by GitHub
parent 741020fbb0
commit 695991881f
62 changed files with 547 additions and 578 deletions

View File

@ -37,6 +37,7 @@ import {
import { ObjectMetadataService } from 'src/engine/metadata-modules/object-metadata/object-metadata.service';
import { capitalize } from 'src/utils/capitalize';
import { getServerUrl } from 'src/utils/get-server-url';
import { DatabaseEventAction } from 'src/engine/api/graphql/graphql-query-runner/enums/database-event-action';
@Injectable()
export class OpenApiService {
@ -81,9 +82,18 @@ export class OpenApiService {
schema.webhooks = objectMetadataItems.reduce(
(paths, item) => {
paths[`Create ${item.nameSingular}`] = computeWebhooks('create', item);
paths[`Update ${item.nameSingular}`] = computeWebhooks('update', item);
paths[`Delete ${item.nameSingular}`] = computeWebhooks('delete', item);
paths[`Create ${item.nameSingular}`] = computeWebhooks(
DatabaseEventAction.CREATED,
item,
);
paths[`Update ${item.nameSingular}`] = computeWebhooks(
DatabaseEventAction.UPDATED,
item,
);
paths[`Delete ${item.nameSingular}`] = computeWebhooks(
DatabaseEventAction.DELETED,
item,
);
return paths;
},

View File

@ -2,17 +2,24 @@ import { OpenAPIV3_1 } from 'openapi-types';
import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity';
import { capitalize } from 'src/utils/capitalize';
import { DatabaseEventAction } from 'src/engine/api/graphql/graphql-query-runner/enums/database-event-action';
export const computeWebhooks = (
type: 'create' | 'update' | 'delete',
type: DatabaseEventAction,
item: ObjectMetadataEntity,
): OpenAPIV3_1.PathItemObject => {
const updatedFields = {
type: 'array',
items: {
type: 'string',
},
};
return {
post: {
tags: [item.nameSingular],
security: [],
requestBody: {
description: `*${type}*.**${item.nameSingular}**, ***.**${item.nameSingular}**, ***.*****`,
content: {
'application/json': {
schema: {
@ -22,17 +29,9 @@ export const computeWebhooks = (
type: 'string',
example: 'https://example.com/incomingWebhook',
},
description: {
eventName: {
type: 'string',
example: 'A sample description',
},
eventType: {
type: 'string',
enum: [
'*.*',
'*.' + item.nameSingular,
type + '.' + item.nameSingular,
],
example: `${item.nameSingular}.${type}`,
},
objectMetadata: {
type: 'object',
@ -60,8 +59,9 @@ export const computeWebhooks = (
example: '2024-02-14T11:27:01.779Z',
},
record: {
$ref: `#/components/schemas/${capitalize(item.nameSingular)}`,
$ref: `#/components/schemas/${capitalize(item.nameSingular)} for Response`,
},
...(type === DatabaseEventAction.UPDATED && { updatedFields }),
},
},
},