2114 timebox make sure the zapier integrations supports custom objects (#3091)
* Fix build command * Add hidden trigger to fetch object names * Remove useless actions * Rename createObject to createRecord
This commit is contained in:
3
packages/twenty-zapier/src/utils/capitalize.ts
Normal file
3
packages/twenty-zapier/src/utils/capitalize.ts
Normal file
@ -0,0 +1,3 @@
|
||||
export const capitalize = (word: string): string => {
|
||||
return word.charAt(0).toUpperCase() + word.slice(1)
|
||||
}
|
||||
54
packages/twenty-zapier/src/utils/computeInputFields.ts
Normal file
54
packages/twenty-zapier/src/utils/computeInputFields.ts
Normal file
@ -0,0 +1,54 @@
|
||||
import { labelling } from "../utils/labelling";
|
||||
|
||||
type Infos = {
|
||||
properties: {
|
||||
[field: string]: {
|
||||
type: string;
|
||||
properties?: { [field: string]: { type: string } }
|
||||
items?: { [$ref: string]: string }
|
||||
}
|
||||
},
|
||||
example: object,
|
||||
required: string[]
|
||||
}
|
||||
|
||||
export const computeInputFields = (infos: Infos): object[] => {
|
||||
const result = []
|
||||
|
||||
for (const fieldName of Object.keys(infos.properties)) {
|
||||
switch (infos.properties[fieldName].type) {
|
||||
case 'array':
|
||||
break;
|
||||
case 'object':
|
||||
if (!infos.properties[fieldName].properties) {
|
||||
break;
|
||||
}
|
||||
for (const subFieldName of Object.keys(infos.properties[fieldName].properties || {})) {
|
||||
const field = {
|
||||
key: `${fieldName}__${subFieldName}`,
|
||||
label: `${labelling(fieldName)}: ${labelling(subFieldName)}`,
|
||||
type: infos.properties[fieldName].properties?.[subFieldName].type,
|
||||
required: false,
|
||||
}
|
||||
if (infos.required?.includes(fieldName)) {
|
||||
field.required = true
|
||||
}
|
||||
result.push(field)
|
||||
}
|
||||
break;
|
||||
default:
|
||||
const field = {
|
||||
key: fieldName,
|
||||
label: labelling(fieldName),
|
||||
type: infos.properties[fieldName].type,
|
||||
required: false,
|
||||
}
|
||||
if (infos.required?.includes(fieldName)) {
|
||||
field.required = true
|
||||
}
|
||||
result.push(field)
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
9
packages/twenty-zapier/src/utils/labelling.ts
Normal file
9
packages/twenty-zapier/src/utils/labelling.ts
Normal file
@ -0,0 +1,9 @@
|
||||
import { capitalize } from "../utils/capitalize";
|
||||
|
||||
export const labelling = (str: string): string => {
|
||||
return str
|
||||
.replace(/[A-Z]/g, letter => ` ${letter.toLowerCase()}`)
|
||||
.split(' ')
|
||||
.map((word)=> capitalize(word))
|
||||
.join(' ');
|
||||
}
|
||||
@ -1,5 +1,20 @@
|
||||
import { Bundle, HttpRequestOptions, ZObject } from 'zapier-platform-core';
|
||||
|
||||
export const requestSchema = async (z: ZObject, bundle: Bundle) => {
|
||||
const options = {
|
||||
url: `${process.env.SERVER_BASE_URL}/open-api`,
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Accept: 'application/json',
|
||||
Authorization: `Bearer ${bundle.authData.apiKey}`,
|
||||
},
|
||||
} satisfies HttpRequestOptions;
|
||||
|
||||
return z.request(options)
|
||||
.then((response) => response.json)
|
||||
}
|
||||
|
||||
const requestDb = async (z: ZObject, bundle: Bundle, query: string) => {
|
||||
const options = {
|
||||
url: `${process.env.SERVER_BASE_URL}/graphql`,
|
||||
|
||||
Reference in New Issue
Block a user