From bbace2b2c127a0055622311906948b9fd59c5faa Mon Sep 17 00:00:00 2001 From: Ali BARIN Date: Thu, 10 Nov 2022 00:12:09 +0100 Subject: [PATCH 1/4] feat: add .all support in auth arguments --- packages/web/src/helpers/computeAuthStepVariables.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/web/src/helpers/computeAuthStepVariables.ts b/packages/web/src/helpers/computeAuthStepVariables.ts index caffad03..6db45a49 100644 --- a/packages/web/src/helpers/computeAuthStepVariables.ts +++ b/packages/web/src/helpers/computeAuthStepVariables.ts @@ -27,6 +27,13 @@ const computeAuthStepVariables = ( } if (variable.value) { + if (variable.value.endsWith('.all}')) { + const key = variable.value.replace('{', '').replace('.all}', ''); + variables[variable.name] = aggregatedData[key]; + + continue; + } + const computedVariable = template(variable.value, { interpolate })( aggregatedData ); From 6d3606abf0daa6e33819528c2ed33da3ec90689a Mon Sep 17 00:00:00 2001 From: Ali BARIN Date: Thu, 10 Nov 2022 00:12:26 +0100 Subject: [PATCH 2/4] refactor(twitter): use .all in auth args --- packages/backend/src/apps/twitter/auth/index.ts | 8 +------- .../backend/src/apps/twitter/auth/verify-credentials.ts | 2 +- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/packages/backend/src/apps/twitter/auth/index.ts b/packages/backend/src/apps/twitter/auth/index.ts index 972504eb..c81e9c96 100644 --- a/packages/backend/src/apps/twitter/auth/index.ts +++ b/packages/backend/src/apps/twitter/auth/index.ts @@ -94,13 +94,7 @@ export default { }, { name: 'formattedData', - value: null, - properties: [ - { - name: 'oauthVerifier', - value: '{openAuthPopup.oauth_verifier}', - }, - ], + value: '{openAuthPopup.all}', }, ], }, diff --git a/packages/backend/src/apps/twitter/auth/verify-credentials.ts b/packages/backend/src/apps/twitter/auth/verify-credentials.ts index 583135fe..6be0ed25 100644 --- a/packages/backend/src/apps/twitter/auth/verify-credentials.ts +++ b/packages/backend/src/apps/twitter/auth/verify-credentials.ts @@ -3,7 +3,7 @@ import { URLSearchParams } from 'url'; const verifyCredentials = async ($: IGlobalVariable) => { const response = await $.http.post( - `/oauth/access_token?oauth_verifier=${$.auth.data.oauthVerifier}&oauth_token=${$.auth.data.accessToken}`, + `/oauth/access_token?oauth_verifier=${$.auth.data.oauth_verifier}&oauth_token=${$.auth.data.accessToken}`, null ); From 10e2794ff9cc365bd6012db7f4ed4c386fd0ce8b Mon Sep 17 00:00:00 2001 From: Faruk AYDIN Date: Thu, 10 Nov 2022 18:49:49 +0100 Subject: [PATCH 3/4] refactor: Generate authentication steps from auth properties --- packages/backend/src/apps/deepl/auth/index.ts | 36 ------- .../backend/src/apps/discord/auth/index.ts | 81 +------------- .../apps/discord/auth/verify-credentials.ts | 2 +- .../backend/src/apps/flickr/auth/index.ts | 77 +------------ .../apps/flickr/auth/verify-credentials.ts | 2 +- .../backend/src/apps/github/auth/index.ts | 77 +------------ .../apps/github/auth/verify-credentials.ts | 2 +- .../backend/src/apps/salesforce/auth/index.ts | 86 +-------------- packages/backend/src/apps/slack/auth/index.ts | 81 +------------- packages/backend/src/apps/smtp/auth/index.ts | 52 --------- .../backend/src/apps/twilio/auth/index.ts | 36 ------- .../backend/src/apps/twitter/auth/index.ts | 71 +----------- .../src/helpers/add-authentication-steps.ts | 101 ++++++++++++++++++ packages/backend/src/helpers/get-app.ts | 7 +- packages/types/index.d.ts | 3 +- 15 files changed, 115 insertions(+), 599 deletions(-) create mode 100644 packages/backend/src/helpers/add-authentication-steps.ts diff --git a/packages/backend/src/apps/deepl/auth/index.ts b/packages/backend/src/apps/deepl/auth/index.ts index 29b49a0c..ed02f1bc 100644 --- a/packages/backend/src/apps/deepl/auth/index.ts +++ b/packages/backend/src/apps/deepl/auth/index.ts @@ -27,42 +27,6 @@ export default { clickToCopy: false, }, ], - authenticationSteps: [ - { - type: 'mutation' as const, - name: 'createConnection', - arguments: [ - { - name: 'key', - value: '{key}', - }, - { - name: 'formattedData', - value: null, - properties: [ - { - name: 'screenName', - value: '{fields.screenName}', - }, - { - name: 'authenticationKey', - value: '{fields.authenticationKey}', - }, - ], - }, - ], - }, - { - type: 'mutation' as const, - name: 'verifyConnection', - arguments: [ - { - name: 'id', - value: '{createConnection.id}', - }, - ], - }, - ], verifyCredentials, isStillVerified, diff --git a/packages/backend/src/apps/discord/auth/index.ts b/packages/backend/src/apps/discord/auth/index.ts index 52be17b0..8466e1f0 100644 --- a/packages/backend/src/apps/discord/auth/index.ts +++ b/packages/backend/src/apps/discord/auth/index.ts @@ -3,6 +3,7 @@ import verifyCredentials from './verify-credentials'; import isStillVerified from './is-still-verified'; export default { + generateAuthUrl: true, fields: [ { key: 'oAuthRedirectUrl', @@ -54,86 +55,6 @@ export default { clickToCopy: false, }, ], - authenticationSteps: [ - { - type: 'mutation' as const, - name: 'createConnection', - arguments: [ - { - name: 'key', - value: '{key}', - }, - { - name: 'formattedData', - value: null, - properties: [ - { - name: 'consumerKey', - value: '{fields.consumerKey}', - }, - { - name: 'consumerSecret', - value: '{fields.consumerSecret}', - }, - { - name: 'botToken', - value: '{fields.botToken}', - }, - ], - }, - ], - }, - { - type: 'mutation' as const, - name: 'createAuthData', - arguments: [ - { - name: 'id', - value: '{createConnection.id}', - }, - ], - }, - { - type: 'openWithPopup' as const, - name: 'openAuthPopup', - arguments: [ - { - name: 'url', - value: '{createAuthData.url}', - }, - ], - }, - { - type: 'mutation' as const, - name: 'updateConnection', - arguments: [ - { - name: 'id', - value: '{createConnection.id}', - }, - { - name: 'formattedData', - value: null, - properties: [ - { - name: 'oauthVerifier', - value: '{openAuthPopup.code}', - }, - ], - }, - ], - }, - { - type: 'mutation' as const, - name: 'verifyConnection', - arguments: [ - { - name: 'id', - value: '{createConnection.id}', - }, - ], - }, - ], createAuthData, verifyCredentials, diff --git a/packages/backend/src/apps/discord/auth/verify-credentials.ts b/packages/backend/src/apps/discord/auth/verify-credentials.ts index 491f4e84..13d012e6 100644 --- a/packages/backend/src/apps/discord/auth/verify-credentials.ts +++ b/packages/backend/src/apps/discord/auth/verify-credentials.ts @@ -14,7 +14,7 @@ const verifyCredentials = async ($: IGlobalVariable) => { response_type: 'code', scope: scopes.join(' '), client_secret: $.auth.data.consumerSecret as string, - code: $.auth.data.oauthVerifier as string, + code: $.auth.data.code as string, grant_type: 'authorization_code', }); const { data: verifiedCredentials } = await $.http.post( diff --git a/packages/backend/src/apps/flickr/auth/index.ts b/packages/backend/src/apps/flickr/auth/index.ts index ecdef330..1c3c8b2f 100644 --- a/packages/backend/src/apps/flickr/auth/index.ts +++ b/packages/backend/src/apps/flickr/auth/index.ts @@ -3,6 +3,7 @@ import verifyCredentials from './verify-credentials'; import isStillVerified from './is-still-verified'; export default { + generateAuthUrl: true, fields: [ { key: 'oAuthRedirectUrl', @@ -42,82 +43,6 @@ export default { clickToCopy: false, }, ], - authenticationSteps: [ - { - type: 'mutation' as const, - name: 'createConnection', - arguments: [ - { - name: 'key', - value: '{key}', - }, - { - name: 'formattedData', - value: null, - properties: [ - { - name: 'consumerKey', - value: '{fields.consumerKey}', - }, - { - name: 'consumerSecret', - value: '{fields.consumerSecret}', - }, - ], - }, - ], - }, - { - type: 'mutation' as const, - name: 'createAuthData', - arguments: [ - { - name: 'id', - value: '{createConnection.id}', - }, - ], - }, - { - type: 'openWithPopup' as const, - name: 'openAuthPopup', - arguments: [ - { - name: 'url', - value: '{createAuthData.url}', - }, - ], - }, - { - type: 'mutation' as const, - name: 'updateConnection', - arguments: [ - { - name: 'id', - value: '{createConnection.id}', - }, - { - name: 'formattedData', - value: null, - properties: [ - { - name: 'oauthVerifier', - value: '{openAuthPopup.oauth_verifier}', - }, - ], - }, - ], - }, - { - type: 'mutation' as const, - name: 'verifyConnection', - arguments: [ - { - name: 'id', - value: '{createConnection.id}', - }, - ], - }, - ], createAuthData, verifyCredentials, diff --git a/packages/backend/src/apps/flickr/auth/verify-credentials.ts b/packages/backend/src/apps/flickr/auth/verify-credentials.ts index 4539dc26..4a42af8f 100644 --- a/packages/backend/src/apps/flickr/auth/verify-credentials.ts +++ b/packages/backend/src/apps/flickr/auth/verify-credentials.ts @@ -3,7 +3,7 @@ import { URLSearchParams } from 'url'; const verifyCredentials = async ($: IGlobalVariable) => { const response = await $.http.post( - `/oauth/access_token?oauth_verifier=${$.auth.data.oauthVerifier}&oauth_token=${$.auth.data.accessToken}`, + `/oauth/access_token?oauth_verifier=${$.auth.data.oauth_verifier}&oauth_token=${$.auth.data.accessToken}`, null ); diff --git a/packages/backend/src/apps/github/auth/index.ts b/packages/backend/src/apps/github/auth/index.ts index 5f6a9f21..d95dbd2e 100644 --- a/packages/backend/src/apps/github/auth/index.ts +++ b/packages/backend/src/apps/github/auth/index.ts @@ -3,6 +3,7 @@ import verifyCredentials from './verify-credentials'; import isStillVerified from './is-still-verified'; export default { + generateAuthUrl: true, fields: [ { key: 'oAuthRedirectUrl', @@ -42,82 +43,6 @@ export default { clickToCopy: false, }, ], - authenticationSteps: [ - { - type: 'mutation' as const, - name: 'createConnection', - arguments: [ - { - name: 'key', - value: '{key}', - }, - { - name: 'formattedData', - value: null, - properties: [ - { - name: 'consumerKey', - value: '{fields.consumerKey}', - }, - { - name: 'consumerSecret', - value: '{fields.consumerSecret}', - }, - ], - }, - ], - }, - { - type: 'mutation' as const, - name: 'createAuthData', - arguments: [ - { - name: 'id', - value: '{createConnection.id}', - }, - ], - }, - { - type: 'openWithPopup' as const, - name: 'openAuthPopup', - arguments: [ - { - name: 'url', - value: '{createAuthData.url}', - }, - ], - }, - { - type: 'mutation' as const, - name: 'updateConnection', - arguments: [ - { - name: 'id', - value: '{createConnection.id}', - }, - { - name: 'formattedData', - value: null, - properties: [ - { - name: 'oauthVerifier', - value: '{openAuthPopup.code}', - }, - ], - }, - ], - }, - { - type: 'mutation' as const, - name: 'verifyConnection', - arguments: [ - { - name: 'id', - value: '{createConnection.id}', - }, - ], - }, - ], createAuthData, verifyCredentials, diff --git a/packages/backend/src/apps/github/auth/verify-credentials.ts b/packages/backend/src/apps/github/auth/verify-credentials.ts index 53950337..d6407ed0 100644 --- a/packages/backend/src/apps/github/auth/verify-credentials.ts +++ b/packages/backend/src/apps/github/auth/verify-credentials.ts @@ -7,7 +7,7 @@ const verifyCredentials = async ($: IGlobalVariable) => { { client_id: $.auth.data.consumerKey, client_secret: $.auth.data.consumerSecret, - code: $.auth.data.oauthVerifier, + code: $.auth.data.code, }, { headers: { diff --git a/packages/backend/src/apps/salesforce/auth/index.ts b/packages/backend/src/apps/salesforce/auth/index.ts index fdbd6cb8..5fdd460c 100644 --- a/packages/backend/src/apps/salesforce/auth/index.ts +++ b/packages/backend/src/apps/salesforce/auth/index.ts @@ -3,6 +3,7 @@ import verifyCredentials from './verify-credentials'; import isStillVerified from './is-still-verified'; export default { + generateAuthUrl: true, fields: [ { key: 'oAuthRedirectUrl', @@ -60,91 +61,6 @@ export default { clickToCopy: false, }, ], - authenticationSteps: [ - { - step: 1, - type: 'mutation' as const, - name: 'createConnection', - arguments: [ - { - name: 'key', - value: '{key}', - }, - { - name: 'formattedData', - value: null, - properties: [ - { - name: 'oauth2Url', - value: '{fields.oauth2Url}', - }, - { - name: 'consumerKey', - value: '{fields.consumerKey}', - }, - { - name: 'consumerSecret', - value: '{fields.consumerSecret}', - }, - ], - }, - ], - }, - { - step: 2, - type: 'mutation' as const, - name: 'createAuthData', - arguments: [ - { - name: 'id', - value: '{createConnection.id}', - }, - ], - }, - { - step: 3, - type: 'openWithPopup' as const, - name: 'openAuthPopup', - arguments: [ - { - name: 'url', - value: '{createAuthData.url}', - }, - ], - }, - { - step: 4, - type: 'mutation' as const, - name: 'updateConnection', - arguments: [ - { - name: 'id', - value: '{createConnection.id}', - }, - { - name: 'formattedData', - value: null, - properties: [ - { - name: 'code', - value: '{openAuthPopup.code}', - }, - ], - }, - ], - }, - { - step: 5, - type: 'mutation' as const, - name: 'verifyConnection', - arguments: [ - { - name: 'id', - value: '{createConnection.id}', - }, - ], - }, - ], createAuthData, verifyCredentials, diff --git a/packages/backend/src/apps/slack/auth/index.ts b/packages/backend/src/apps/slack/auth/index.ts index d6d95165..a30ff8a4 100644 --- a/packages/backend/src/apps/slack/auth/index.ts +++ b/packages/backend/src/apps/slack/auth/index.ts @@ -3,6 +3,7 @@ import verifyCredentials from './verify-credentials'; import isStillVerified from './is-still-verified'; export default { + generateAuthUrl: true, fields: [ { key: 'oAuthRedirectUrl', @@ -39,86 +40,6 @@ export default { clickToCopy: false, }, ], - authenticationSteps: [ - { - type: 'mutation' as const, - name: 'createConnection', - arguments: [ - { - name: 'key', - value: '{key}', - }, - { - name: 'formattedData', - value: null, - properties: [ - { - name: 'consumerKey', - value: '{fields.consumerKey}', - }, - { - name: 'consumerSecret', - value: '{fields.consumerSecret}', - }, - ], - }, - ], - }, - { - type: 'mutation' as const, - name: 'createAuthData', - arguments: [ - { - name: 'id', - value: '{createConnection.id}', - }, - ], - }, - { - type: 'openWithPopup' as const, - name: 'openAuthPopup', - arguments: [ - { - name: 'url', - value: '{createAuthData.url}', - }, - ], - }, - { - type: 'mutation' as const, - name: 'updateConnection', - arguments: [ - { - name: 'id', - value: '{createConnection.id}', - }, - { - name: 'formattedData', - value: null, - properties: [ - { - name: 'code', - value: '{openAuthPopup.code}', - }, - { - name: 'state', - value: '{openAuthPopup.state}', - }, - ], - }, - ], - }, - { - type: 'mutation' as const, - name: 'verifyConnection', - arguments: [ - { - name: 'id', - value: '{createConnection.id}', - }, - ], - }, - ], createAuthData, verifyCredentials, diff --git a/packages/backend/src/apps/smtp/auth/index.ts b/packages/backend/src/apps/smtp/auth/index.ts index 2868abad..369aa411 100644 --- a/packages/backend/src/apps/smtp/auth/index.ts +++ b/packages/backend/src/apps/smtp/auth/index.ts @@ -86,58 +86,6 @@ export default { clickToCopy: false, }, ], - authenticationSteps: [ - { - type: 'mutation' as const, - name: 'createConnection', - arguments: [ - { - name: 'key', - value: '{key}', - }, - { - name: 'formattedData', - value: null, - properties: [ - { - name: 'host', - value: '{fields.host}', - }, - { - name: 'username', - value: '{fields.username}', - }, - { - name: 'password', - value: '{fields.password}', - }, - { - name: 'useTLS', - value: '{fields.useTls}', - }, - { - name: 'port', - value: '{fields.port}', - }, - { - name: 'fromEmail', - value: '{fields.fromEmail}', - }, - ], - }, - ], - }, - { - type: 'mutation' as const, - name: 'verifyConnection', - arguments: [ - { - name: 'id', - value: '{createConnection.id}', - }, - ], - }, - ], verifyCredentials, isStillVerified, }; diff --git a/packages/backend/src/apps/twilio/auth/index.ts b/packages/backend/src/apps/twilio/auth/index.ts index 40e67615..645e8874 100644 --- a/packages/backend/src/apps/twilio/auth/index.ts +++ b/packages/backend/src/apps/twilio/auth/index.ts @@ -27,42 +27,6 @@ export default { clickToCopy: false, }, ], - authenticationSteps: [ - { - type: 'mutation' as const, - name: 'createConnection', - arguments: [ - { - name: 'key', - value: '{key}', - }, - { - name: 'formattedData', - value: null, - properties: [ - { - name: 'accountSid', - value: '{fields.accountSid}', - }, - { - name: 'authToken', - value: '{fields.authToken}', - }, - ], - }, - ], - }, - { - type: 'mutation' as const, - name: 'verifyConnection', - arguments: [ - { - name: 'id', - value: '{createConnection.id}', - }, - ], - }, - ], verifyCredentials, isStillVerified, diff --git a/packages/backend/src/apps/twitter/auth/index.ts b/packages/backend/src/apps/twitter/auth/index.ts index c81e9c96..680dafb5 100644 --- a/packages/backend/src/apps/twitter/auth/index.ts +++ b/packages/backend/src/apps/twitter/auth/index.ts @@ -3,6 +3,7 @@ import verifyCredentials from './verify-credentials'; import isStillVerified from './is-still-verified'; export default { + generateAuthUrl: true, fields: [ { key: 'oAuthRedirectUrl', @@ -39,76 +40,6 @@ export default { clickToCopy: false, }, ], - authenticationSteps: [ - { - type: 'mutation' as const, - name: 'createConnection', - arguments: [ - { - name: 'key', - value: '{key}', - }, - { - name: 'formattedData', - value: null, - properties: [ - { - name: 'consumerKey', - value: '{fields.consumerKey}', - }, - { - name: 'consumerSecret', - value: '{fields.consumerSecret}', - }, - ], - }, - ], - }, - { - type: 'mutation' as const, - name: 'createAuthData', - arguments: [ - { - name: 'id', - value: '{createConnection.id}', - }, - ], - }, - { - type: 'openWithPopup' as const, - name: 'openAuthPopup', - arguments: [ - { - name: 'url', - value: '{createAuthData.url}', - }, - ], - }, - { - type: 'mutation' as const, - name: 'updateConnection', - arguments: [ - { - name: 'id', - value: '{createConnection.id}', - }, - { - name: 'formattedData', - value: '{openAuthPopup.all}', - }, - ], - }, - { - type: 'mutation' as const, - name: 'verifyConnection', - arguments: [ - { - name: 'id', - value: '{createConnection.id}', - }, - ], - }, - ], createAuthData, verifyCredentials, diff --git a/packages/backend/src/helpers/add-authentication-steps.ts b/packages/backend/src/helpers/add-authentication-steps.ts new file mode 100644 index 00000000..fec5e5e9 --- /dev/null +++ b/packages/backend/src/helpers/add-authentication-steps.ts @@ -0,0 +1,101 @@ +import { IApp } from '@automatisch/types'; + +function addAuthenticationSteps(app: IApp): IApp { + if (app.auth.generateAuthUrl) { + app.auth.authenticationSteps = authenticationStepsWithAuthUrl; + } else { + app.auth.authenticationSteps = authenticationStepsWithoutAuthUrl; + } + + return app; +} + +const authenticationStepsWithoutAuthUrl = [ + { + type: 'mutation' as const, + name: 'createConnection', + arguments: [ + { + name: 'key', + value: '{key}', + }, + { + name: 'formattedData', + value: '{fields.all}', + }, + ], + }, + { + type: 'mutation' as const, + name: 'verifyConnection', + arguments: [ + { + name: 'id', + value: '{createConnection.id}', + }, + ], + }, +]; + +const authenticationStepsWithAuthUrl = [ + { + type: 'mutation' as const, + name: 'createConnection', + arguments: [ + { + name: 'key', + value: '{key}', + }, + { + name: 'formattedData', + value: '{fields.all}', + }, + ], + }, + { + type: 'mutation' as const, + name: 'createAuthData', + arguments: [ + { + name: 'id', + value: '{createConnection.id}', + }, + ], + }, + { + type: 'openWithPopup' as const, + name: 'openAuthPopup', + arguments: [ + { + name: 'url', + value: '{createAuthData.url}', + }, + ], + }, + { + type: 'mutation' as const, + name: 'updateConnection', + arguments: [ + { + name: 'id', + value: '{createConnection.id}', + }, + { + name: 'formattedData', + value: '{openAuthPopup.all}', + }, + ], + }, + { + type: 'mutation' as const, + name: 'verifyConnection', + arguments: [ + { + name: 'id', + value: '{createConnection.id}', + }, + ], + }, +]; + +export default addAuthenticationSteps; diff --git a/packages/backend/src/helpers/get-app.ts b/packages/backend/src/helpers/get-app.ts index 2dcea731..52f73894 100644 --- a/packages/backend/src/helpers/get-app.ts +++ b/packages/backend/src/helpers/get-app.ts @@ -8,14 +8,12 @@ import { ITrigger, } from '@automatisch/types'; import { omit, cloneDeep } from 'lodash'; +import addAuthenticationSteps from './add-authentication-steps'; import addReconnectionSteps from './add-reconnection-steps'; type TApps = Record>; const apps = fs - .readdirSync( - path.resolve(__dirname, `../apps/`), - { withFileTypes: true } - ) + .readdirSync(path.resolve(__dirname, `../apps/`), { withFileTypes: true }) .reduce((apps, dirent) => { if (!dirent.isDirectory()) return apps; @@ -36,6 +34,7 @@ const getApp = async (appKey: string, stripFuncs = true) => { let appData: IApp = cloneDeep(await getDefaultExport(appKey)); if (appData.auth) { + appData = addAuthenticationSteps(appData); appData = addReconnectionSteps(appData); } diff --git a/packages/types/index.d.ts b/packages/types/index.d.ts index 6701a7c5..fa169201 100644 --- a/packages/types/index.d.ts +++ b/packages/types/index.d.ts @@ -181,8 +181,9 @@ export interface IAuth { createAuthData?($: IGlobalVariable): Promise; verifyCredentials($: IGlobalVariable): Promise; isStillVerified($: IGlobalVariable): Promise; + generateAuthUrl?: boolean; fields: IField[]; - authenticationSteps: IAuthenticationStep[]; + authenticationSteps?: IAuthenticationStep[]; reconnectionSteps?: IAuthenticationStep[]; } From 81c41ef5eeaddd28f201304700f4bdfa4e939af0 Mon Sep 17 00:00:00 2001 From: Faruk AYDIN Date: Thu, 10 Nov 2022 18:50:36 +0100 Subject: [PATCH 4/4] refactor: Use generateAuthUrl method instead of createAuthData --- .../auth/{create-auth-data.ts => generate-auth-url.ts} | 2 +- packages/backend/src/apps/discord/auth/index.ts | 5 ++--- .../auth/{create-auth-data.ts => generate-auth-url.ts} | 2 +- packages/backend/src/apps/flickr/auth/index.ts | 6 ++---- .../auth/{create-auth-data.ts => generate-auth-url.ts} | 2 +- packages/backend/src/apps/github/auth/index.ts | 5 ++--- .../auth/{create-auth-data.ts => generate-auth-url.ts} | 2 +- packages/backend/src/apps/salesforce/auth/index.ts | 5 ++--- .../auth/{create-auth-data.ts => generate-auth-url.ts} | 2 +- packages/backend/src/apps/slack/auth/index.ts | 5 ++--- .../auth/{create-auth-data.ts => generate-auth-url.ts} | 2 +- packages/backend/src/apps/twitter/auth/index.ts | 5 ++--- .../{create-auth-data.ts => generate-auth-url.ts} | 2 +- packages/backend/src/graphql/mutation-resolvers.ts | 4 ++-- .../{create-auth-data.ts => generate-auth-url.ts} | 10 +++++----- packages/backend/src/graphql/schema.graphql | 4 ++-- .../backend/src/helpers/add-authentication-steps.ts | 4 ++-- packages/types/index.d.ts | 3 +-- packages/web/src/graphql/mutations/create-auth-data.ts | 9 --------- .../web/src/graphql/mutations/generate-auth-url.ts | 9 +++++++++ packages/web/src/graphql/mutations/index.ts | 4 ++-- 21 files changed, 42 insertions(+), 50 deletions(-) rename packages/backend/src/apps/discord/auth/{create-auth-data.ts => generate-auth-url.ts} (90%) rename packages/backend/src/apps/flickr/auth/{create-auth-data.ts => generate-auth-url.ts} (91%) rename packages/backend/src/apps/github/auth/{create-auth-data.ts => generate-auth-url.ts} (90%) rename packages/backend/src/apps/salesforce/auth/{create-auth-data.ts => generate-auth-url.ts} (87%) rename packages/backend/src/apps/slack/auth/{create-auth-data.ts => generate-auth-url.ts} (94%) rename packages/backend/src/apps/twitter/auth/{create-auth-data.ts => generate-auth-url.ts} (91%) rename packages/backend/src/errors/{create-auth-data.ts => generate-auth-url.ts} (84%) rename packages/backend/src/graphql/mutations/{create-auth-data.ts => generate-auth-url.ts} (79%) delete mode 100644 packages/web/src/graphql/mutations/create-auth-data.ts create mode 100644 packages/web/src/graphql/mutations/generate-auth-url.ts diff --git a/packages/backend/src/apps/discord/auth/create-auth-data.ts b/packages/backend/src/apps/discord/auth/generate-auth-url.ts similarity index 90% rename from packages/backend/src/apps/discord/auth/create-auth-data.ts rename to packages/backend/src/apps/discord/auth/generate-auth-url.ts index 25b83887..d912967b 100644 --- a/packages/backend/src/apps/discord/auth/create-auth-data.ts +++ b/packages/backend/src/apps/discord/auth/generate-auth-url.ts @@ -2,7 +2,7 @@ import { IField, IGlobalVariable } from '@automatisch/types'; import { URLSearchParams } from 'url'; import scopes from '../common/scopes'; -export default async function createAuthData($: IGlobalVariable) { +export default async function generateAuthUrl($: IGlobalVariable) { const oauthRedirectUrlField = $.app.auth.fields.find( (field: IField) => field.key == 'oAuthRedirectUrl' ); diff --git a/packages/backend/src/apps/discord/auth/index.ts b/packages/backend/src/apps/discord/auth/index.ts index 8466e1f0..158077df 100644 --- a/packages/backend/src/apps/discord/auth/index.ts +++ b/packages/backend/src/apps/discord/auth/index.ts @@ -1,9 +1,8 @@ -import createAuthData from './create-auth-data'; +import generateAuthUrl from './generate-auth-url'; import verifyCredentials from './verify-credentials'; import isStillVerified from './is-still-verified'; export default { - generateAuthUrl: true, fields: [ { key: 'oAuthRedirectUrl', @@ -56,7 +55,7 @@ export default { }, ], - createAuthData, + generateAuthUrl, verifyCredentials, isStillVerified, }; diff --git a/packages/backend/src/apps/flickr/auth/create-auth-data.ts b/packages/backend/src/apps/flickr/auth/generate-auth-url.ts similarity index 91% rename from packages/backend/src/apps/flickr/auth/create-auth-data.ts rename to packages/backend/src/apps/flickr/auth/generate-auth-url.ts index 383363bd..f3eea3fd 100644 --- a/packages/backend/src/apps/flickr/auth/create-auth-data.ts +++ b/packages/backend/src/apps/flickr/auth/generate-auth-url.ts @@ -1,7 +1,7 @@ import { IField, IGlobalVariable } from '@automatisch/types'; import { URLSearchParams } from 'url'; -export default async function createAuthData($: IGlobalVariable) { +export default async function generateAuthUrl($: IGlobalVariable) { const oauthRedirectUrlField = $.app.auth.fields.find( (field: IField) => field.key == 'oAuthRedirectUrl' ); diff --git a/packages/backend/src/apps/flickr/auth/index.ts b/packages/backend/src/apps/flickr/auth/index.ts index 1c3c8b2f..5cc50871 100644 --- a/packages/backend/src/apps/flickr/auth/index.ts +++ b/packages/backend/src/apps/flickr/auth/index.ts @@ -1,9 +1,8 @@ -import createAuthData from './create-auth-data'; +import generateAuthUrl from './generate-auth-url'; import verifyCredentials from './verify-credentials'; import isStillVerified from './is-still-verified'; export default { - generateAuthUrl: true, fields: [ { key: 'oAuthRedirectUrl', @@ -43,8 +42,7 @@ export default { clickToCopy: false, }, ], - - createAuthData, + generateAuthUrl, verifyCredentials, isStillVerified, }; diff --git a/packages/backend/src/apps/github/auth/create-auth-data.ts b/packages/backend/src/apps/github/auth/generate-auth-url.ts similarity index 90% rename from packages/backend/src/apps/github/auth/create-auth-data.ts rename to packages/backend/src/apps/github/auth/generate-auth-url.ts index 26648ce3..32587ecc 100644 --- a/packages/backend/src/apps/github/auth/create-auth-data.ts +++ b/packages/backend/src/apps/github/auth/generate-auth-url.ts @@ -1,7 +1,7 @@ import { IField, IGlobalVariable } from '@automatisch/types'; import { URLSearchParams } from 'url'; -export default async function createAuthData($: IGlobalVariable) { +export default async function generateAuthUrl($: IGlobalVariable) { const scopes = ['read:org', 'repo', 'user']; const oauthRedirectUrlField = $.app.auth.fields.find( (field: IField) => field.key == 'oAuthRedirectUrl' diff --git a/packages/backend/src/apps/github/auth/index.ts b/packages/backend/src/apps/github/auth/index.ts index d95dbd2e..72389a80 100644 --- a/packages/backend/src/apps/github/auth/index.ts +++ b/packages/backend/src/apps/github/auth/index.ts @@ -1,9 +1,8 @@ -import createAuthData from './create-auth-data'; +import generateAuthUrl from './generate-auth-url'; import verifyCredentials from './verify-credentials'; import isStillVerified from './is-still-verified'; export default { - generateAuthUrl: true, fields: [ { key: 'oAuthRedirectUrl', @@ -44,7 +43,7 @@ export default { }, ], - createAuthData, + generateAuthUrl, verifyCredentials, isStillVerified, }; diff --git a/packages/backend/src/apps/salesforce/auth/create-auth-data.ts b/packages/backend/src/apps/salesforce/auth/generate-auth-url.ts similarity index 87% rename from packages/backend/src/apps/salesforce/auth/create-auth-data.ts rename to packages/backend/src/apps/salesforce/auth/generate-auth-url.ts index b38f422e..a798dbef 100644 --- a/packages/backend/src/apps/salesforce/auth/create-auth-data.ts +++ b/packages/backend/src/apps/salesforce/auth/generate-auth-url.ts @@ -1,7 +1,7 @@ import { IField, IGlobalVariable } from '@automatisch/types'; import qs from 'qs'; -export default async function createAuthData($: IGlobalVariable) { +export default async function generateAuthUrl($: IGlobalVariable) { const oauthRedirectUrlField = $.app.auth.fields.find( (field: IField) => field.key == 'oAuthRedirectUrl' ); diff --git a/packages/backend/src/apps/salesforce/auth/index.ts b/packages/backend/src/apps/salesforce/auth/index.ts index 5fdd460c..04b31160 100644 --- a/packages/backend/src/apps/salesforce/auth/index.ts +++ b/packages/backend/src/apps/salesforce/auth/index.ts @@ -1,9 +1,8 @@ -import createAuthData from './create-auth-data'; +import generateAuthUrl from './generate-auth-url'; import verifyCredentials from './verify-credentials'; import isStillVerified from './is-still-verified'; export default { - generateAuthUrl: true, fields: [ { key: 'oAuthRedirectUrl', @@ -62,7 +61,7 @@ export default { }, ], - createAuthData, + generateAuthUrl, verifyCredentials, isStillVerified, }; diff --git a/packages/backend/src/apps/slack/auth/create-auth-data.ts b/packages/backend/src/apps/slack/auth/generate-auth-url.ts similarity index 94% rename from packages/backend/src/apps/slack/auth/create-auth-data.ts rename to packages/backend/src/apps/slack/auth/generate-auth-url.ts index 9aff18fb..76282180 100644 --- a/packages/backend/src/apps/slack/auth/create-auth-data.ts +++ b/packages/backend/src/apps/slack/auth/generate-auth-url.ts @@ -42,7 +42,7 @@ const userScopes = [ 'users:read.email', ]; -export default async function createAuthData($: IGlobalVariable) { +export default async function generateAuthUrl($: IGlobalVariable) { const oauthRedirectUrlField = $.app.auth.fields.find( (field: IField) => field.key == 'oAuthRedirectUrl' ); diff --git a/packages/backend/src/apps/slack/auth/index.ts b/packages/backend/src/apps/slack/auth/index.ts index a30ff8a4..b5430c86 100644 --- a/packages/backend/src/apps/slack/auth/index.ts +++ b/packages/backend/src/apps/slack/auth/index.ts @@ -1,9 +1,8 @@ -import createAuthData from './create-auth-data'; +import generateAuthUrl from './generate-auth-url'; import verifyCredentials from './verify-credentials'; import isStillVerified from './is-still-verified'; export default { - generateAuthUrl: true, fields: [ { key: 'oAuthRedirectUrl', @@ -41,7 +40,7 @@ export default { }, ], - createAuthData, + generateAuthUrl, verifyCredentials, isStillVerified, }; diff --git a/packages/backend/src/apps/twitter/auth/create-auth-data.ts b/packages/backend/src/apps/twitter/auth/generate-auth-url.ts similarity index 91% rename from packages/backend/src/apps/twitter/auth/create-auth-data.ts rename to packages/backend/src/apps/twitter/auth/generate-auth-url.ts index d7ea1571..dfe2a58f 100644 --- a/packages/backend/src/apps/twitter/auth/create-auth-data.ts +++ b/packages/backend/src/apps/twitter/auth/generate-auth-url.ts @@ -1,7 +1,7 @@ import { IField, IGlobalVariable } from '@automatisch/types'; import { URLSearchParams } from 'url'; -export default async function createAuthData($: IGlobalVariable) { +export default async function generateAuthUrl($: IGlobalVariable) { const oauthRedirectUrlField = $.app.auth.fields.find( (field: IField) => field.key == 'oAuthRedirectUrl' ); diff --git a/packages/backend/src/apps/twitter/auth/index.ts b/packages/backend/src/apps/twitter/auth/index.ts index 680dafb5..bdea0b6f 100644 --- a/packages/backend/src/apps/twitter/auth/index.ts +++ b/packages/backend/src/apps/twitter/auth/index.ts @@ -1,9 +1,8 @@ -import createAuthData from './create-auth-data'; +import generateAuthUrl from './generate-auth-url'; import verifyCredentials from './verify-credentials'; import isStillVerified from './is-still-verified'; export default { - generateAuthUrl: true, fields: [ { key: 'oAuthRedirectUrl', @@ -41,7 +40,7 @@ export default { }, ], - createAuthData, + generateAuthUrl, verifyCredentials, isStillVerified, }; diff --git a/packages/backend/src/errors/create-auth-data.ts b/packages/backend/src/errors/generate-auth-url.ts similarity index 84% rename from packages/backend/src/errors/create-auth-data.ts rename to packages/backend/src/errors/generate-auth-url.ts index 871c44eb..630f2bcf 100644 --- a/packages/backend/src/errors/create-auth-data.ts +++ b/packages/backend/src/errors/generate-auth-url.ts @@ -1,7 +1,7 @@ import { IJSONObject } from '@automatisch/types'; import BaseError from './base'; -export default class CreateAuthDataError extends BaseError { +export default class GenerateAuthUrlError extends BaseError { constructor(error: IJSONObject) { const computedError = ((error.response as IJSONObject)?.data as IJSONObject) || diff --git a/packages/backend/src/graphql/mutation-resolvers.ts b/packages/backend/src/graphql/mutation-resolvers.ts index fab7aa0b..97cec0a4 100644 --- a/packages/backend/src/graphql/mutation-resolvers.ts +++ b/packages/backend/src/graphql/mutation-resolvers.ts @@ -1,5 +1,5 @@ import createConnection from './mutations/create-connection'; -import createAuthData from './mutations/create-auth-data'; +import generateAuthUrl from './mutations/generate-auth-url'; import updateConnection from './mutations/update-connection'; import resetConnection from './mutations/reset-connection'; import verifyConnection from './mutations/verify-connection'; @@ -17,7 +17,7 @@ import login from './mutations/login'; const mutationResolvers = { createConnection, - createAuthData, + generateAuthUrl, updateConnection, resetConnection, verifyConnection, diff --git a/packages/backend/src/graphql/mutations/create-auth-data.ts b/packages/backend/src/graphql/mutations/generate-auth-url.ts similarity index 79% rename from packages/backend/src/graphql/mutations/create-auth-data.ts rename to packages/backend/src/graphql/mutations/generate-auth-url.ts index ecf5737e..9606da6a 100644 --- a/packages/backend/src/graphql/mutations/create-auth-data.ts +++ b/packages/backend/src/graphql/mutations/generate-auth-url.ts @@ -2,7 +2,7 @@ import Context from '../../types/express/context'; import axios from 'axios'; import globalVariable from '../../helpers/global-variable'; import App from '../../models/app'; -import CreateAuthDataError from '../../errors/create-auth-data'; +import GenerateAuthUrlError from '../../errors/generate-auth-url'; type Params = { input: { @@ -10,7 +10,7 @@ type Params = { }; }; -const createAuthData = async ( +const generateAuthUrl = async ( _parent: unknown, params: Params, context: Context @@ -32,13 +32,13 @@ const createAuthData = async ( const $ = await globalVariable({ connection, app }); try { - await authInstance.createAuthData($); + await authInstance.generateAuthUrl($); await axios.get(connection.formattedData.url as string); } catch (error) { - throw new CreateAuthDataError(error); + throw new GenerateAuthUrlError(error); } return connection.formattedData; }; -export default createAuthData; +export default generateAuthUrl; diff --git a/packages/backend/src/graphql/schema.graphql b/packages/backend/src/graphql/schema.graphql index b928b995..147aa17b 100644 --- a/packages/backend/src/graphql/schema.graphql +++ b/packages/backend/src/graphql/schema.graphql @@ -30,7 +30,7 @@ type Query { type Mutation { createConnection(input: CreateConnectionInput): Connection - createAuthData(input: CreateAuthDataInput): AuthLink + generateAuthUrl(input: GenerateAuthUrlInput): AuthLink updateConnection(input: UpdateConnectionInput): Connection resetConnection(input: ResetConnectionInput): Connection verifyConnection(input: VerifyConnectionInput): Connection @@ -225,7 +225,7 @@ input CreateConnectionInput { formattedData: JSONObject! } -input CreateAuthDataInput { +input GenerateAuthUrlInput { id: String! } diff --git a/packages/backend/src/helpers/add-authentication-steps.ts b/packages/backend/src/helpers/add-authentication-steps.ts index fec5e5e9..1cf44846 100644 --- a/packages/backend/src/helpers/add-authentication-steps.ts +++ b/packages/backend/src/helpers/add-authentication-steps.ts @@ -54,7 +54,7 @@ const authenticationStepsWithAuthUrl = [ }, { type: 'mutation' as const, - name: 'createAuthData', + name: 'generateAuthUrl', arguments: [ { name: 'id', @@ -68,7 +68,7 @@ const authenticationStepsWithAuthUrl = [ arguments: [ { name: 'url', - value: '{createAuthData.url}', + value: '{generateAuthUrl.url}', }, ], }, diff --git a/packages/types/index.d.ts b/packages/types/index.d.ts index fa169201..a74d0f88 100644 --- a/packages/types/index.d.ts +++ b/packages/types/index.d.ts @@ -178,10 +178,9 @@ export interface IData { } export interface IAuth { - createAuthData?($: IGlobalVariable): Promise; + generateAuthUrl?($: IGlobalVariable): Promise; verifyCredentials($: IGlobalVariable): Promise; isStillVerified($: IGlobalVariable): Promise; - generateAuthUrl?: boolean; fields: IField[]; authenticationSteps?: IAuthenticationStep[]; reconnectionSteps?: IAuthenticationStep[]; diff --git a/packages/web/src/graphql/mutations/create-auth-data.ts b/packages/web/src/graphql/mutations/create-auth-data.ts deleted file mode 100644 index e8b416b2..00000000 --- a/packages/web/src/graphql/mutations/create-auth-data.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { gql } from '@apollo/client'; - -export const CREATE_AUTH_DATA = gql` - mutation CreateAuthData($input: CreateAuthDataInput) { - createAuthData(input: $input) { - url - } - } -`; diff --git a/packages/web/src/graphql/mutations/generate-auth-url.ts b/packages/web/src/graphql/mutations/generate-auth-url.ts new file mode 100644 index 00000000..6077710d --- /dev/null +++ b/packages/web/src/graphql/mutations/generate-auth-url.ts @@ -0,0 +1,9 @@ +import { gql } from '@apollo/client'; + +export const GENERATE_AUTH_URL = gql` + mutation generateAuthUrl($input: GenerateAuthUrlInput) { + generateAuthUrl(input: $input) { + url + } + } +`; diff --git a/packages/web/src/graphql/mutations/index.ts b/packages/web/src/graphql/mutations/index.ts index d30fb9bf..d6340cf2 100644 --- a/packages/web/src/graphql/mutations/index.ts +++ b/packages/web/src/graphql/mutations/index.ts @@ -3,7 +3,7 @@ import { UPDATE_CONNECTION } from './update-connection'; import { VERIFY_CONNECTION } from './verify-connection'; import { RESET_CONNECTION } from './reset-connection'; import { DELETE_CONNECTION } from './delete-connection'; -import { CREATE_AUTH_DATA } from './create-auth-data'; +import { GENERATE_AUTH_URL } from './generate-auth-url'; type Mutations = { [key: string]: any; @@ -15,7 +15,7 @@ const mutations: Mutations = { verifyConnection: VERIFY_CONNECTION, resetConnection: RESET_CONNECTION, deleteConnection: DELETE_CONNECTION, - createAuthData: CREATE_AUTH_DATA, + generateAuthUrl: GENERATE_AUTH_URL, }; export default mutations;