2049 timebox 1j zapier integration 4 define and implement a first trigger for zapier app (#2132)

* Add create company trigger

* Refactor

* Add operation in subscribe

* Add create hook api endpoint

* Add import of hook module

* Add a test for hook subscribe

* Add delete hook api endpoint

* Add delete hook test

* Add findMany hook route

---------

Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
martmull
2023-10-19 22:48:34 +02:00
committed by GitHub
parent 5ce8b4c73c
commit e9092162e0
17 changed files with 413 additions and 62 deletions

View File

@ -7,33 +7,22 @@ import {
ZObject,
} from 'zapier-platform-core';
import getBundle from '../utils/getBundle';
import handleQueryParams from '../utils/handleQueryParams';
import requestDb from '../utils/requestDb';
const appTester = createAppTester(App);
tools.env.inject();
const generateKey = async (z: ZObject, bundle: Bundle) => {
const options = {
url: `${process.env.SERVER_BASE_URL}/graphql`,
method: 'POST',
headers: {
Authorization: `Bearer ${bundle.authData.apiKey}`,
},
body: {
query: `mutation
CreateApiKey {
createOneApiKey(data:{
name:"${bundle.inputData.name}",
expiresAt: "${bundle.inputData.expiresAt}"
}) {token}}`,
},
} satisfies HttpRequestOptions;
return z.request(options).then((response) => {
const results = response.json;
return results.data.createOneApiKey.token;
});
const query = `
mutation CreateApiKey {
createOneApiKey(
data:{${handleQueryParams(bundle.inputData)}}
)
{token}
}`;
return (await requestDb(z, bundle, query)).data.createOneApiKey.token;
};
const apiKey = String(process.env.API_KEY);
describe('custom auth', () => {
it('passes authentication and returns json', async () => {
const bundle = getBundle();