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:
@ -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,
|
||||
},
|
||||
};
|
||||
@ -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,
|
||||
},
|
||||
};
|
||||
@ -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,
|
||||
},
|
||||
}
|
||||
@ -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' },
|
||||
],
|
||||
},
|
||||
};
|
||||
@ -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' }],
|
||||
},
|
||||
};
|
||||
@ -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' },
|
||||
],
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user