feat(trello): add trello integration (#1380)
This commit is contained in:
1
packages/backend/src/apps/trello/assets/favicon.svg
Normal file
1
packages/backend/src/apps/trello/assets/favicon.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg xmlns:xlink="http://www.w3.org/1999/xlink" width="24" height="24" role="presentation" focusable="false" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M3 5C3 3.89543 3.89543 3 5 3H19C20.1046 3 21 3.89543 21 5V19C21 20.1046 20.1046 21 19 21H5C3.89543 21 3 20.1046 3 19V5ZM5 6C5 5.44772 5.44772 5 6 5H10C10.5523 5 11 5.44772 11 6V16C11 16.5523 10.5523 17 10 17H6C5.44772 17 5 16.5523 5 16V6ZM14 5C13.4477 5 13 5.44772 13 6V12C13 12.5523 13.4477 13 14 13H18C18.5523 13 19 12.5523 19 12V6C19 5.44772 18.5523 5 18 5H14Z" fill="#0079bf"></path></svg>
|
After Width: | Height: | Size: 606 B |
23
packages/backend/src/apps/trello/auth/generate-auth-url.ts
Normal file
23
packages/backend/src/apps/trello/auth/generate-auth-url.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { IField, IGlobalVariable } from '@automatisch/types';
|
||||
import { URLSearchParams } from 'url';
|
||||
import authScope from '../common/auth-scope';
|
||||
|
||||
export default async function generateAuthUrl($: IGlobalVariable) {
|
||||
const oauthRedirectUrlField = $.app.auth.fields.find(
|
||||
(field: IField) => field.key == 'oAuthRedirectUrl'
|
||||
);
|
||||
const redirectUri = oauthRedirectUrlField.value as string;
|
||||
const searchParams = new URLSearchParams({
|
||||
return_url: redirectUri,
|
||||
scope: authScope.join(','),
|
||||
expiration: 'never',
|
||||
key: $.auth.data.apiKey as string,
|
||||
response_type: 'token',
|
||||
});
|
||||
|
||||
const url = `https://trello.com/1/authorize?${searchParams.toString()}`;
|
||||
|
||||
await $.auth.set({
|
||||
url,
|
||||
});
|
||||
}
|
34
packages/backend/src/apps/trello/auth/index.ts
Normal file
34
packages/backend/src/apps/trello/auth/index.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import generateAuthUrl from './generate-auth-url';
|
||||
import verifyCredentials from './verify-credentials';
|
||||
import isStillVerified from './is-still-verified';
|
||||
|
||||
export default {
|
||||
fields: [
|
||||
{
|
||||
key: 'oAuthRedirectUrl',
|
||||
label: 'OAuth Redirect URL',
|
||||
type: 'string' as const,
|
||||
required: true,
|
||||
readOnly: true,
|
||||
value: '{WEB_APP_URL}/app/trello/connections/add',
|
||||
placeholder: null,
|
||||
description: '',
|
||||
clickToCopy: true,
|
||||
},
|
||||
{
|
||||
key: 'apiKey',
|
||||
label: 'API Key',
|
||||
type: 'string' as const,
|
||||
required: true,
|
||||
readOnly: false,
|
||||
value: null,
|
||||
placeholder: null,
|
||||
description: 'API Key for your Trello account',
|
||||
clickToCopy: false,
|
||||
},
|
||||
],
|
||||
|
||||
generateAuthUrl,
|
||||
verifyCredentials,
|
||||
isStillVerified,
|
||||
};
|
@@ -0,0 +1,9 @@
|
||||
import { IGlobalVariable } from '@automatisch/types';
|
||||
import verifyCredentials from './verify-credentials';
|
||||
|
||||
const isStillVerified = async ($: IGlobalVariable) => {
|
||||
await verifyCredentials($);
|
||||
return true;
|
||||
};
|
||||
|
||||
export default isStillVerified;
|
15
packages/backend/src/apps/trello/auth/verify-credentials.ts
Normal file
15
packages/backend/src/apps/trello/auth/verify-credentials.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { IGlobalVariable } from '@automatisch/types';
|
||||
import getCurrentUser from '../common/get-current-user';
|
||||
|
||||
const verifyCredentials = async ($: IGlobalVariable) => {
|
||||
const currentUser = await getCurrentUser($);
|
||||
const screenName = [currentUser.username, currentUser.email]
|
||||
.filter(Boolean)
|
||||
.join(' @ ');
|
||||
|
||||
await $.auth.set({
|
||||
screenName,
|
||||
});
|
||||
};
|
||||
|
||||
export default verifyCredentials;
|
11
packages/backend/src/apps/trello/common/add-auth-header.ts
Normal file
11
packages/backend/src/apps/trello/common/add-auth-header.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { TBeforeRequest } from '@automatisch/types';
|
||||
|
||||
const addAuthHeader: TBeforeRequest = ($, requestConfig) => {
|
||||
if ($.auth.data?.token) {
|
||||
requestConfig.headers.Authorization = `OAuth oauth_consumer_key="${$.auth.data.apiKey}", oauth_token="${$.auth.data.token}"`;
|
||||
}
|
||||
|
||||
return requestConfig;
|
||||
};
|
||||
|
||||
export default addAuthHeader;
|
3
packages/backend/src/apps/trello/common/auth-scope.ts
Normal file
3
packages/backend/src/apps/trello/common/auth-scope.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
const authScope: string[] = ['read', 'write', 'account'];
|
||||
|
||||
export default authScope;
|
10
packages/backend/src/apps/trello/common/get-current-user.ts
Normal file
10
packages/backend/src/apps/trello/common/get-current-user.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { IGlobalVariable, IJSONObject } from '@automatisch/types';
|
||||
|
||||
const getCurrentUser = async ($: IGlobalVariable): Promise<IJSONObject> => {
|
||||
const response = await $.http.get('/1/members/me/');
|
||||
const currentUser = response.data;
|
||||
|
||||
return currentUser;
|
||||
};
|
||||
|
||||
export default getCurrentUser;
|
0
packages/backend/src/apps/trello/index.d.ts
vendored
Normal file
0
packages/backend/src/apps/trello/index.d.ts
vendored
Normal file
16
packages/backend/src/apps/trello/index.ts
Normal file
16
packages/backend/src/apps/trello/index.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import defineApp from '../../helpers/define-app';
|
||||
import addAuthHeader from './common/add-auth-header';
|
||||
import auth from './auth';
|
||||
|
||||
export default defineApp({
|
||||
name: 'Trello',
|
||||
key: 'trello',
|
||||
baseUrl: 'https://trello.com/',
|
||||
apiBaseUrl: 'https://api.trello.com',
|
||||
iconUrl: '{BASE_URL}/apps/trello/assets/favicon.svg',
|
||||
authDocUrl: 'https://automatisch.io/docs/apps/trello/connection',
|
||||
supportsConnections: true,
|
||||
primaryColor: '0079bf',
|
||||
beforeRequest: [addAuthHeader],
|
||||
auth,
|
||||
});
|
Reference in New Issue
Block a user