2052 zapier integration 5 deploy twenty zapier app into the public repository (#2101)
* Add create_company Zap action * Add testing for that action * Core review returns
This commit is contained in:
7
packages/twenty-zapier/src/utils/getBundle.ts
Normal file
7
packages/twenty-zapier/src/utils/getBundle.ts
Normal file
@ -0,0 +1,7 @@
|
||||
const getBundle = (inputData?: object) => {
|
||||
return {
|
||||
authData: { apiKey: String(process.env.API_KEY) },
|
||||
inputData,
|
||||
};
|
||||
};
|
||||
export default getBundle;
|
||||
11
packages/twenty-zapier/src/utils/handleQueryParams.ts
Normal file
11
packages/twenty-zapier/src/utils/handleQueryParams.ts
Normal file
@ -0,0 +1,11 @@
|
||||
const handleQueryParams = (inputData: { [x: string]: any }): string => {
|
||||
let result = '';
|
||||
Object.keys(inputData).forEach((key) => {
|
||||
let quote = '';
|
||||
if (typeof inputData[key] === 'string') quote = '"';
|
||||
result = result.concat(`${key}: ${quote}${inputData[key]}${quote}, `);
|
||||
});
|
||||
if (result.length) result = result.slice(0, -2); // Remove the last ', '
|
||||
return result;
|
||||
};
|
||||
export default handleQueryParams;
|
||||
38
packages/twenty-zapier/src/utils/requestDb.ts
Normal file
38
packages/twenty-zapier/src/utils/requestDb.ts
Normal file
@ -0,0 +1,38 @@
|
||||
import { Bundle, HttpRequestOptions, ZObject } from 'zapier-platform-core';
|
||||
|
||||
const requestDb = async (z: ZObject, bundle: Bundle, query: string) => {
|
||||
const options = {
|
||||
url: `${process.env.SERVER_BASE_URL}/graphql`,
|
||||
method: 'POST',
|
||||
headers: {
|
||||
Authorization: `Bearer ${bundle.authData.apiKey}`,
|
||||
},
|
||||
body: {
|
||||
query,
|
||||
},
|
||||
} satisfies HttpRequestOptions;
|
||||
|
||||
return z
|
||||
.request(options)
|
||||
.then((response) => {
|
||||
const results = response.json;
|
||||
if (results.errors) {
|
||||
throw new z.errors.Error(
|
||||
'The API Key you supplied is incorrect',
|
||||
'AuthenticationError',
|
||||
results.errors,
|
||||
);
|
||||
}
|
||||
response.throwForStatus();
|
||||
return results;
|
||||
})
|
||||
.catch((err) => {
|
||||
throw new z.errors.Error(
|
||||
'The API Key you supplied is incorrect',
|
||||
'AuthenticationError',
|
||||
err.message,
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
export default requestDb;
|
||||
Reference in New Issue
Block a user