Update zapier trigger payload (#8464)

- fixes zapier tests
This commit is contained in:
martmull
2024-11-12 17:58:36 +01:00
committed by GitHub
parent 31f03764d6
commit 269eaf4422
7 changed files with 65 additions and 49 deletions

View File

@ -1,7 +1,5 @@
export type InputData = { [x: string]: any };
export type ObjectData = { id: string } | { [x: string]: any };
export type NodeField = {
type: FieldMetadataType;
name: string;

View File

@ -1,6 +1,5 @@
import { Bundle, ZObject } from 'zapier-platform-core';
import { ObjectData } from '../../utils/data.types';
import handleQueryParams from '../../utils/handleQueryParams';
import requestDb, {
requestDbViaRestApi,
@ -11,7 +10,6 @@ export enum DatabaseEventAction {
CREATED = 'created',
UPDATED = 'updated',
DELETED = 'deleted',
DESTROYED = 'destroyed',
}
export const performSubscribe = async (z: ZObject, bundle: Bundle) => {
@ -81,7 +79,7 @@ const getNamePluralFromNameSingular = async (
export const performList = async (
z: ZObject,
bundle: Bundle,
): Promise<ObjectData[]> => {
): Promise<{ record: Record<string, any>; updatedFields?: string[] }[]> => {
const nameSingular = bundle.inputData.nameSingular;
const namePlural = await getNamePluralFromNameSingular(
z,
@ -92,9 +90,9 @@ export const performList = async (
return results.map((result) => ({
record: result,
...(bundle.inputData.operation === DatabaseEventAction.UPDATED && {
updatedFields: Object.keys(result).filter((key) => key !== 'id')?.[0] || [
'updatedField',
],
updatedFields: [
Object.keys(result).filter((key) => key !== 'id')?.[0],
] || ['updatedField'],
}),
}));
};