Improve webhook (#3459)

* Add trigger record

* Merge triggers

* Merge creates

* Fix libraries

* Fix create merged key

* Rename file

* Remove list Record Ids

* Revert "Rename file"

This reverts commit 2e72e05793ced4553eec8d9f890d31beae594c85.

* Revert "Revert "Rename file""

This reverts commit e2d93fa02716093df6d4d6029af9cc324c06f06b.

* Revert "Remove list Record Ids"

This reverts commit 6653fb6ccd4307e3958b70923505034d92cf43bb.

* Remove namePlural field

* Use name singular for webhooks

* Send webhook metadata

* Extract resource from zapier webhook

* Fix package.json

* Fix package.json

* Update payload

* Fix package.json

* Update payload

* Update payload

* Rename file

* Use wildcard in webhook events

* Fix nameSingular

* Code review returns

* Code review returns
This commit is contained in:
martmull
2024-01-16 15:31:09 +01:00
committed by GitHub
parent fb93bb69fb
commit bb91917ff8
32 changed files with 637 additions and 835 deletions

View File

@ -1,27 +0,0 @@
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

@ -1,10 +1,11 @@
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 };
return { id: schema, nameSingular: schema.toLowerCase() };
});
};

View File

@ -1,24 +1,13 @@
import { Bundle, ZObject } from 'zapier-platform-core';
import { capitalize } from '../utils/capitalize';
import requestDb from '../utils/requestDb';
import { ObjectData } from '../utils/data.types';
import { listSample } from '../utils/triggers/triggers.utils';
const listRecordIdsRequest = async (
z: ZObject,
bundle: Bundle,
): Promise<{ id: string }[]> => {
const data = bundle.inputData;
const namePlural = data.namePlural;
const query = `
query List${capitalize(namePlural)}Ids {
${namePlural}{edges{node{id}}}
}`;
const result = await requestDb(z, bundle, query);
return result.data[namePlural]['edges'].map((edge: any) => {
return {
id: edge.node.id,
};
});
): Promise<ObjectData[]> => {
return listSample(z, bundle, true);
};
export const listRecordIdsKey = 'list_record_ids';

View File

@ -1,6 +1,6 @@
import { Bundle, ZObject } from 'zapier-platform-core';
import { findObjectNamesPluralKey } from '../triggers/find_object_names_plural';
import { findObjectNamesSingularKey } from '../triggers/find_object_names_singular';
import {
listSample,
Operation,
@ -9,26 +9,38 @@ import {
subscribe,
} from '../utils/triggers/triggers.utils';
export const triggerRecordCreatedKey = 'trigger_record_created';
export const triggerRecordKey = 'trigger_record';
const performSubscribe = (z: ZObject, bundle: Bundle) =>
subscribe(z, bundle, Operation.create);
const performList = (z: ZObject, bundle: Bundle) => listSample(z, bundle);
subscribe(z, bundle, bundle.inputData.operation);
const performList = (z: ZObject, bundle: Bundle) =>
listSample(z, bundle, bundle.inputData.operation === Operation.delete);
export default {
key: triggerRecordCreatedKey,
key: triggerRecordKey,
noun: 'Record',
display: {
label: 'Record Trigger Created',
description: 'Triggers when a Record is created.',
label: 'Record Trigger',
description: 'Triggers when a Record is created, updated or deleted.',
},
operation: {
inputFields: [
{
key: 'namePlural',
key: 'nameSingular',
required: true,
label: 'Record Name',
dynamic: `${findObjectNamesPluralKey}.namePlural`,
dynamic: `${findObjectNamesSingularKey}.nameSingular`,
altersDynamicFields: true,
},
{
key: 'operation',
required: true,
label: 'Operation',
choices: {
[Operation.create]: Operation.create,
[Operation.update]: Operation.update,
[Operation.delete]: Operation.delete,
},
altersDynamicFields: true,
},
],

View File

@ -1,45 +0,0 @@
import { Bundle, ZObject } from 'zapier-platform-core';
import { findObjectNamesPluralKey } from '../triggers/find_object_names_plural';
import {
listSample,
Operation,
perform,
performUnsubscribe,
subscribe,
} from '../utils/triggers/triggers.utils';
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

@ -1,51 +0,0 @@
import { Bundle, ZObject } from 'zapier-platform-core';
import { findObjectNamesPluralKey } from '../triggers/find_object_names_plural';
import {
listSample,
Operation,
perform,
performUnsubscribe,
subscribe,
} from '../utils/triggers/triggers.utils';
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' },
],
},
};