Add authentication optional api url parameter (#5803)
This commit is contained in:
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "twenty-zapier",
|
"name": "twenty-zapier",
|
||||||
"version": "1.0.0",
|
"version": "1.0.1",
|
||||||
"description": "Effortlessly sync Twenty with 3000+ apps. Automate tasks, boost productivity, and supercharge your customer relationships!",
|
"description": "Effortlessly sync Twenty with 3000+ apps. Automate tasks, boost productivity, and supercharge your customer relationships!",
|
||||||
"main": "src/index.ts",
|
"main": "src/index.ts",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@ -10,6 +10,7 @@
|
|||||||
"build": "yarn clean && tsc",
|
"build": "yarn clean && tsc",
|
||||||
"deploy": "yarn build && zapier push",
|
"deploy": "yarn build && zapier push",
|
||||||
"validate": "yarn build && zapier validate",
|
"validate": "yarn build && zapier validate",
|
||||||
|
"versions": "yarn build && zapier versions",
|
||||||
"clean": "rimraf ./lib ./build",
|
"clean": "rimraf ./lib ./build",
|
||||||
"watch": "yarn clean && tsc --watch",
|
"watch": "yarn clean && tsc --watch",
|
||||||
"_zapier-build": "yarn build"
|
"_zapier-build": "yarn build"
|
||||||
|
|||||||
@ -23,6 +23,16 @@ export default {
|
|||||||
helpText:
|
helpText:
|
||||||
'Create an API key in [your twenty workspace](https://app.twenty.com/settings/developers)',
|
'Create an API key in [your twenty workspace](https://app.twenty.com/settings/developers)',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
computed: false,
|
||||||
|
key: 'apiUrl',
|
||||||
|
required: false,
|
||||||
|
label: 'Api Url',
|
||||||
|
type: 'string',
|
||||||
|
placeholder: 'https://api.twenty.com',
|
||||||
|
helpText:
|
||||||
|
'Set this only if you self-host Twenty. Use the same value as `REACT_APP_SERVER_BASE_URL` in https://docs.twenty.com/start/self-hosting/',
|
||||||
|
},
|
||||||
],
|
],
|
||||||
connectionLabel: '{{data.currentWorkspace.displayName}}',
|
connectionLabel: '{{data.currentWorkspace.displayName}}',
|
||||||
customConfig: {},
|
customConfig: {},
|
||||||
|
|||||||
@ -37,6 +37,35 @@ describe('custom auth', () => {
|
|||||||
expect(response.data.currentWorkspace).toHaveProperty('displayName');
|
expect(response.data.currentWorkspace).toHaveProperty('displayName');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('passes authentication with api url and returns json', async () => {
|
||||||
|
const bundle = getBundle();
|
||||||
|
const bundleWithApiUrl = {
|
||||||
|
...bundle,
|
||||||
|
authData: { ...bundle.authData, apiUrl: 'http://localhost:3000' },
|
||||||
|
};
|
||||||
|
const response = await appTester(App.authentication.test, bundleWithApiUrl);
|
||||||
|
expect(response.data).toHaveProperty('currentWorkspace');
|
||||||
|
expect(response.data.currentWorkspace).toHaveProperty('displayName');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('fail authentication with bad api url', async () => {
|
||||||
|
const bundle = getBundle();
|
||||||
|
const bundleWithApiUrl = {
|
||||||
|
...bundle,
|
||||||
|
authData: { ...bundle.authData, apiUrl: 'http://invalid' },
|
||||||
|
};
|
||||||
|
try {
|
||||||
|
const response = await appTester(
|
||||||
|
App.authentication.test,
|
||||||
|
bundleWithApiUrl,
|
||||||
|
);
|
||||||
|
expect(response.data).toHaveProperty('currentWorkspace');
|
||||||
|
expect(response.data.currentWorkspace).toHaveProperty('displayName');
|
||||||
|
} catch (error: any) {
|
||||||
|
expect(error.message).toContain('ENOTFOUND');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
it('fails on bad auth token format', async () => {
|
it('fails on bad auth token format', async () => {
|
||||||
const bundle = getBundle();
|
const bundle = getBundle();
|
||||||
bundle.authData.apiKey = 'bad';
|
bundle.authData.apiKey = 'bad';
|
||||||
@ -44,7 +73,7 @@ describe('custom auth', () => {
|
|||||||
try {
|
try {
|
||||||
await appTester(App.authentication.test, bundle);
|
await appTester(App.authentication.test, bundle);
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
expect(error.message).toContain('Unauthenticated');
|
expect(error.message).toContain('UNAUTHENTICATED');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
throw new Error('appTester should have thrown');
|
throw new Error('appTester should have thrown');
|
||||||
@ -71,7 +100,7 @@ describe('custom auth', () => {
|
|||||||
try {
|
try {
|
||||||
await appTester(App.authentication.test, bundleWithExpiredApiKey);
|
await appTester(App.authentication.test, bundleWithExpiredApiKey);
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
expect(error.message).toContain('Unauthenticated');
|
expect(error.message).toContain('UNAUTHENTICATED');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
throw new Error('appTester should have thrown');
|
throw new Error('appTester should have thrown');
|
||||||
|
|||||||
@ -40,7 +40,7 @@ const requestDb = async (
|
|||||||
endpoint = 'graphql',
|
endpoint = 'graphql',
|
||||||
) => {
|
) => {
|
||||||
const options = {
|
const options = {
|
||||||
url: `${process.env.SERVER_BASE_URL}/${endpoint}`,
|
url: `${bundle.authData.apiUrl || process.env.SERVER_BASE_URL}/${endpoint}`,
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
@ -81,7 +81,9 @@ export const requestDbViaRestApi = (
|
|||||||
objectNamePlural: string,
|
objectNamePlural: string,
|
||||||
) => {
|
) => {
|
||||||
const options = {
|
const options = {
|
||||||
url: `${process.env.SERVER_BASE_URL}/rest/${objectNamePlural}?limit:3`,
|
url: `${
|
||||||
|
bundle.authData.apiUrl || process.env.SERVER_BASE_URL
|
||||||
|
}/rest/${objectNamePlural}?limit:3`,
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
|
|||||||
Reference in New Issue
Block a user