2248 zapier integration implement typeorm eventsubscribers (#3122)

* Add new queue to twenty-server

* Add triggers to zapier

* Rename webhook operation

* Use find one or fail

* Use logger

* Fix typescript templating

* Add dedicated call webhook job

* Update logging

* Fix error handling
This commit is contained in:
martmull
2024-01-03 18:09:57 +01:00
committed by GitHub
parent 4ebaacc306
commit 65250839fb
36 changed files with 1040 additions and 209 deletions

View File

@ -0,0 +1,27 @@
import { Bundle, ZObject } from 'zapier-platform-core';
import { requestSchema } from '../utils/requestDb';
const objectNamesPluralListRequest = async (z: ZObject, bundle: Bundle) => {
const schema = await requestSchema(z, bundle);
const tags: { name: string }[] = schema.tags;
return Object.values(tags)
.filter((tag) => tag.name !== 'General')
.map((tag) => {
return { id: tag.name, namePlural: tag.name };
});
};
export const findObjectNamesPluralKey = 'find_object_names_plural';
export default {
display: {
description: 'Find objects',
label: 'Find objects',
hidden: true,
},
key: findObjectNamesPluralKey,
noun: 'Object',
operation: {
perform: objectNamesPluralListRequest,
},
};

View File

@ -0,0 +1,24 @@
import { Bundle, ZObject } from 'zapier-platform-core';
import { requestSchema } from '../utils/requestDb';
const objectListRequest = async (z: ZObject, bundle: Bundle) => {
const schema = await requestSchema(z, bundle);
return Object.keys(schema.components.schemas).map((schema) => {
return { id: schema, nameSingular: schema };
});
};
export const findObjectNamesSingularKey = 'find_object_names_singular';
export default {
display: {
description: 'Find objects',
label: 'Find objects',
hidden: true,
},
key: findObjectNamesSingularKey,
noun: 'Object',
operation: {
perform: objectListRequest,
},
};

View File

@ -1,22 +0,0 @@
import { Bundle, ZObject } from "zapier-platform-core";
import { requestSchema } from "../utils/requestDb";
const objectListRequest = async (z: ZObject, bundle: Bundle) => {
const schema = await requestSchema(z, bundle)
return Object.keys(schema.components.schemas).map((schema)=> {
return {id: schema, nameSingular: schema}
})
}
export default {
display: {
description: 'Find objects',
label: 'Find objects',
hidden: true,
},
key: 'find_objects',
noun: 'Object',
operation: {
perform: objectListRequest,
},
}

View File

@ -0,0 +1,50 @@
import { findObjectNamesPluralKey } from '../triggers/find_object_names_plural';
import {
listSample,
Operation,
perform,
performUnsubscribe,
subscribe,
} from '../utils/triggers.utils';
import { Bundle, ZObject } from 'zapier-platform-core';
export const triggerRecordCreatedKey = 'trigger_record_created';
const performSubscribe = (z: ZObject, bundle: Bundle) =>
subscribe(z, bundle, Operation.create);
const performList = (z: ZObject, bundle: Bundle) => listSample(z, bundle);
export default {
key: triggerRecordCreatedKey,
noun: 'Record',
display: {
label: 'Record Trigger Created',
description: 'Triggers when a Record is created.',
},
operation: {
inputFields: [
{
key: 'namePlural',
required: true,
label: 'Record Name',
dynamic: `${findObjectNamesPluralKey}.namePlural`,
altersDynamicFields: true,
},
],
type: 'hook',
performSubscribe,
performUnsubscribe,
perform,
performList,
sample: {
id: 'f75f6b2e-9442-4c72-aa95-47d8e5ec8cb3',
createdAt: '2023-10-19T07:37:25.306Z',
workspaceId: 'c8b070fc-c969-4ca5-837a-e7c3735734d2',
},
outputFields: [
{ key: 'id', label: 'ID' },
{ key: 'createdAt', label: 'Created At' },
{ key: 'workspaceId', label: 'Workspace ID' },
],
},
};

View File

@ -0,0 +1,44 @@
import { findObjectNamesPluralKey } from '../triggers/find_object_names_plural';
import {
perform,
listSample,
subscribe,
performUnsubscribe,
Operation,
} from '../utils/triggers.utils';
import { Bundle, ZObject } from 'zapier-platform-core';
export const triggerRecordDeletedKey = 'trigger_record_deleted';
const performSubscribe = (z: ZObject, bundle: Bundle) =>
subscribe(z, bundle, Operation.delete);
const performList = (z: ZObject, bundle: Bundle) => listSample(z, bundle, true);
export default {
key: triggerRecordDeletedKey,
noun: 'Record',
display: {
label: 'Record Trigger Deleted',
description: 'Triggers when a Record is deleted.',
},
operation: {
inputFields: [
{
key: 'namePlural',
required: true,
label: 'Record Name',
dynamic: `${findObjectNamesPluralKey}.namePlural`,
altersDynamicFields: true,
},
],
type: 'hook',
performSubscribe,
performUnsubscribe,
perform,
performList,
sample: {
id: 'f75f6b2e-9442-4c72-aa95-47d8e5ec8cb3',
},
outputFields: [{ key: 'id', label: 'ID' }],
},
};

View File

@ -0,0 +1,50 @@
import { findObjectNamesPluralKey } from '../triggers/find_object_names_plural';
import {
listSample,
Operation,
perform,
performUnsubscribe,
subscribe,
} from '../utils/triggers.utils';
import { Bundle, ZObject } from 'zapier-platform-core';
export const triggerRecordUpdatedKey = 'trigger_record_updated';
const performSubscribe = (z: ZObject, bundle: Bundle) =>
subscribe(z, bundle, Operation.update);
const performList = (z: ZObject, bundle: Bundle) => listSample(z, bundle);
export default {
key: triggerRecordUpdatedKey,
noun: 'Record',
display: {
label: 'Record Trigger Updated',
description: 'Triggers when a Record is updated.',
},
operation: {
inputFields: [
{
key: 'namePlural',
required: true,
label: 'Record Name',
dynamic: `${findObjectNamesPluralKey}.namePlural`,
altersDynamicFields: true,
},
],
type: 'hook',
performSubscribe,
performUnsubscribe,
perform,
performList,
sample: {
id: 'f75f6b2e-9442-4c72-aa95-47d8e5ec8cb3',
createdAt: '2023-10-19T07:37:25.306Z',
workspaceId: 'c8b070fc-c969-4ca5-837a-e7c3735734d2',
},
outputFields: [
{ key: 'id', label: 'ID' },
{ key: 'createdAt', label: 'Created At' },
{ key: 'workspaceId', label: 'Workspace ID' },
],
},
};