From a03c60bd902e787c8cfad6a49bf4ed168a69bb69 Mon Sep 17 00:00:00 2001 From: Ali BARIN Date: Wed, 2 Nov 2022 21:32:40 +0100 Subject: [PATCH 1/2] refactor: remove step property out of app auth --- packages/backend/src/apps/discord/auth/index.ts | 11 ----------- packages/backend/src/apps/flickr/auth/index.ts | 11 ----------- packages/backend/src/apps/github/auth/index.ts | 11 ----------- packages/backend/src/apps/slack/auth/index.ts | 11 ----------- packages/backend/src/apps/smtp/auth/index.ts | 5 ----- packages/backend/src/apps/twilio/auth/index.ts | 5 ----- packages/backend/src/apps/twitter/auth/index.ts | 11 ----------- 7 files changed, 65 deletions(-) diff --git a/packages/backend/src/apps/discord/auth/index.ts b/packages/backend/src/apps/discord/auth/index.ts index fc3d2fde..8ebc550c 100644 --- a/packages/backend/src/apps/discord/auth/index.ts +++ b/packages/backend/src/apps/discord/auth/index.ts @@ -55,7 +55,6 @@ export default { ], authenticationSteps: [ { - step: 1, type: 'mutation' as const, name: 'createConnection', arguments: [ @@ -84,7 +83,6 @@ export default { ] }, { - step: 2, type: 'mutation' as const, name: 'createAuthData', arguments: [ @@ -95,7 +93,6 @@ export default { ] }, { - step: 3, type: 'openWithPopup' as const, name: 'openAuthPopup', arguments: [ @@ -106,7 +103,6 @@ export default { ] }, { - step: 4, type: 'mutation' as const, name: 'updateConnection', arguments: [ @@ -127,7 +123,6 @@ export default { ] }, { - step: 5, type: 'mutation' as const, name: 'verifyConnection', arguments: [ @@ -140,7 +135,6 @@ export default { ], reconnectionSteps: [ { - step: 1, type: 'mutation' as const, name: 'resetConnection', arguments: [ @@ -151,7 +145,6 @@ export default { ] }, { - step: 2, type: 'mutation' as const, name: 'updateConnection', arguments: [ @@ -180,7 +173,6 @@ export default { ] }, { - step: 3, type: 'mutation' as const, name: 'createAuthData', arguments: [ @@ -191,7 +183,6 @@ export default { ] }, { - step: 4, type: 'openWithPopup' as const, name: 'openAuthPopup', arguments: [ @@ -202,7 +193,6 @@ export default { ] }, { - step: 5, type: 'mutation' as const, name: 'updateConnection', arguments: [ @@ -223,7 +213,6 @@ export default { ] }, { - step: 6, type: 'mutation' as const, name: 'verifyConnection', arguments: [ diff --git a/packages/backend/src/apps/flickr/auth/index.ts b/packages/backend/src/apps/flickr/auth/index.ts index 33aeb02c..4b78c335 100644 --- a/packages/backend/src/apps/flickr/auth/index.ts +++ b/packages/backend/src/apps/flickr/auth/index.ts @@ -43,7 +43,6 @@ export default { ], authenticationSteps: [ { - step: 1, type: 'mutation' as const, name: 'createConnection', arguments: [ @@ -68,7 +67,6 @@ export default { ] }, { - step: 2, type: 'mutation' as const, name: 'createAuthData', arguments: [ @@ -79,7 +77,6 @@ export default { ] }, { - step: 3, type: 'openWithPopup' as const, name: 'openAuthPopup', arguments: [ @@ -90,7 +87,6 @@ export default { ] }, { - step: 4, type: 'mutation' as const, name: 'updateConnection', arguments: [ @@ -111,7 +107,6 @@ export default { ] }, { - step: 5, type: 'mutation' as const, name: 'verifyConnection', arguments: [ @@ -124,7 +119,6 @@ export default { ], reconnectionSteps: [ { - step: 1, type: 'mutation' as const, name: 'resetConnection', arguments: [ @@ -135,7 +129,6 @@ export default { ] }, { - step: 2, type: 'mutation' as const, name: 'updateConnection', arguments: [ @@ -160,7 +153,6 @@ export default { ] }, { - step: 3, type: 'mutation' as const, name: 'createAuthData', arguments: [ @@ -171,7 +163,6 @@ export default { ] }, { - step: 4, type: 'openWithPopup' as const, name: 'openAuthPopup', arguments: [ @@ -182,7 +173,6 @@ export default { ] }, { - step: 5, type: 'mutation' as const, name: 'updateConnection', arguments: [ @@ -203,7 +193,6 @@ export default { ] }, { - step: 6, type: 'mutation' as const, name: 'verifyConnection', arguments: [ diff --git a/packages/backend/src/apps/github/auth/index.ts b/packages/backend/src/apps/github/auth/index.ts index 5f4637ce..5cfc9f59 100644 --- a/packages/backend/src/apps/github/auth/index.ts +++ b/packages/backend/src/apps/github/auth/index.ts @@ -43,7 +43,6 @@ export default { ], authenticationSteps: [ { - step: 1, type: 'mutation' as const, name: 'createConnection', arguments: [ @@ -68,7 +67,6 @@ export default { ] }, { - step: 2, type: 'mutation' as const, name: 'createAuthData', arguments: [ @@ -79,7 +77,6 @@ export default { ] }, { - step: 3, type: 'openWithPopup' as const, name: 'openAuthPopup', arguments: [ @@ -90,7 +87,6 @@ export default { ] }, { - step: 4, type: 'mutation' as const, name: 'updateConnection', arguments: [ @@ -111,7 +107,6 @@ export default { ] }, { - step: 5, type: 'mutation' as const, name: 'verifyConnection', arguments: [ @@ -124,7 +119,6 @@ export default { ], reconnectionSteps: [ { - step: 1, type: 'mutation' as const, name: 'resetConnection', arguments: [ @@ -135,7 +129,6 @@ export default { ] }, { - step: 2, type: 'mutation' as const, name: 'updateConnection', arguments: [ @@ -160,7 +153,6 @@ export default { ] }, { - step: 3, type: 'mutation' as const, name: 'createAuthData', arguments: [ @@ -171,7 +163,6 @@ export default { ] }, { - step: 4, type: 'openWithPopup' as const, name: 'openAuthPopup', arguments: [ @@ -182,7 +173,6 @@ export default { ] }, { - step: 5, type: 'mutation' as const, name: 'updateConnection', arguments: [ @@ -203,7 +193,6 @@ export default { ] }, { - step: 6, type: 'mutation' as const, name: 'verifyConnection', arguments: [ diff --git a/packages/backend/src/apps/slack/auth/index.ts b/packages/backend/src/apps/slack/auth/index.ts index 88569ba0..a4d02952 100644 --- a/packages/backend/src/apps/slack/auth/index.ts +++ b/packages/backend/src/apps/slack/auth/index.ts @@ -41,7 +41,6 @@ export default { ], authenticationSteps: [ { - step: 1, type: 'mutation' as const, name: 'createConnection', arguments: [ @@ -66,7 +65,6 @@ export default { ], }, { - step: 2, type: 'mutation' as const, name: 'createAuthData', arguments: [ @@ -77,7 +75,6 @@ export default { ], }, { - step: 3, type: 'openWithPopup' as const, name: 'openAuthPopup', arguments: [ @@ -88,7 +85,6 @@ export default { ], }, { - step: 4, type: 'mutation' as const, name: 'updateConnection', arguments: [ @@ -113,7 +109,6 @@ export default { ], }, { - step: 5, type: 'mutation' as const, name: 'verifyConnection', arguments: [ @@ -126,7 +121,6 @@ export default { ], reconnectionSteps: [ { - step: 1, type: 'mutation' as const, name: 'resetConnection', arguments: [ @@ -137,7 +131,6 @@ export default { ], }, { - step: 2, type: 'mutation' as const, name: 'updateConnection', arguments: [ @@ -162,7 +155,6 @@ export default { ], }, { - step: 3, type: 'mutation' as const, name: 'createAuthData', arguments: [ @@ -173,7 +165,6 @@ export default { ], }, { - step: 4, type: 'openWithPopup' as const, name: 'openAuthPopup', arguments: [ @@ -184,7 +175,6 @@ export default { ], }, { - step: 5, type: 'mutation' as const, name: 'updateConnection', arguments: [ @@ -209,7 +199,6 @@ export default { ], }, { - step: 6, type: 'mutation' as const, name: 'verifyConnection', arguments: [ diff --git a/packages/backend/src/apps/smtp/auth/index.ts b/packages/backend/src/apps/smtp/auth/index.ts index fa41d608..0a4ad9e0 100644 --- a/packages/backend/src/apps/smtp/auth/index.ts +++ b/packages/backend/src/apps/smtp/auth/index.ts @@ -88,7 +88,6 @@ export default { ], authenticationSteps: [ { - step: 1, type: 'mutation' as const, name: 'createConnection', arguments: [ @@ -129,7 +128,6 @@ export default { ], }, { - step: 2, type: 'mutation' as const, name: 'verifyConnection', arguments: [ @@ -142,7 +140,6 @@ export default { ], reconnectionSteps: [ { - step: 1, type: 'mutation' as const, name: 'resetConnection', arguments: [ @@ -153,7 +150,6 @@ export default { ], }, { - step: 2, type: 'mutation' as const, name: 'updateConnection', arguments: [ @@ -194,7 +190,6 @@ export default { ], }, { - step: 3, type: 'mutation' as const, name: 'verifyConnection', arguments: [ diff --git a/packages/backend/src/apps/twilio/auth/index.ts b/packages/backend/src/apps/twilio/auth/index.ts index 8df9da7c..d33548ba 100644 --- a/packages/backend/src/apps/twilio/auth/index.ts +++ b/packages/backend/src/apps/twilio/auth/index.ts @@ -29,7 +29,6 @@ export default { ], authenticationSteps: [ { - step: 1, type: 'mutation' as const, name: 'createConnection', arguments: [ @@ -54,7 +53,6 @@ export default { ], }, { - step: 2, type: 'mutation' as const, name: 'verifyConnection', arguments: [ @@ -67,7 +65,6 @@ export default { ], reconnectionSteps: [ { - step: 1, type: 'mutation' as const, name: 'resetConnection', arguments: [ @@ -78,7 +75,6 @@ export default { ], }, { - step: 2, type: 'mutation' as const, name: 'updateConnection', arguments: [ @@ -103,7 +99,6 @@ export default { ], }, { - step: 3, type: 'mutation' as const, name: 'verifyConnection', arguments: [ diff --git a/packages/backend/src/apps/twitter/auth/index.ts b/packages/backend/src/apps/twitter/auth/index.ts index 98d04eee..ecf5ae3f 100644 --- a/packages/backend/src/apps/twitter/auth/index.ts +++ b/packages/backend/src/apps/twitter/auth/index.ts @@ -41,7 +41,6 @@ export default { ], authenticationSteps: [ { - step: 1, type: 'mutation' as const, name: 'createConnection', arguments: [ @@ -66,7 +65,6 @@ export default { ], }, { - step: 2, type: 'mutation' as const, name: 'createAuthData', arguments: [ @@ -77,7 +75,6 @@ export default { ], }, { - step: 3, type: 'openWithPopup' as const, name: 'openAuthPopup', arguments: [ @@ -88,7 +85,6 @@ export default { ], }, { - step: 4, type: 'mutation' as const, name: 'updateConnection', arguments: [ @@ -109,7 +105,6 @@ export default { ], }, { - step: 5, type: 'mutation' as const, name: 'verifyConnection', arguments: [ @@ -122,7 +117,6 @@ export default { ], reconnectionSteps: [ { - step: 1, type: 'mutation' as const, name: 'resetConnection', arguments: [ @@ -133,7 +127,6 @@ export default { ], }, { - step: 2, type: 'mutation' as const, name: 'updateConnection', arguments: [ @@ -158,7 +151,6 @@ export default { ], }, { - step: 3, type: 'mutation' as const, name: 'createAuthData', arguments: [ @@ -169,7 +161,6 @@ export default { ], }, { - step: 4, type: 'openWithPopup' as const, name: 'openAuthPopup', arguments: [ @@ -180,7 +171,6 @@ export default { ], }, { - step: 5, type: 'mutation' as const, name: 'updateConnection', arguments: [ @@ -201,7 +191,6 @@ export default { ], }, { - step: 6, type: 'mutation' as const, name: 'verifyConnection', arguments: [ From 6a33636d9d97173d98e098523c0fee637f0750c9 Mon Sep 17 00:00:00 2001 From: Ali BARIN Date: Wed, 2 Nov 2022 22:11:50 +0100 Subject: [PATCH 2/2] refactor: compute reconnectionSteps out of auth steps --- .../backend/src/apps/discord/auth/index.ts | 90 ------------------- .../backend/src/apps/flickr/auth/index.ts | 86 ------------------ .../backend/src/apps/github/auth/index.ts | 86 ------------------ packages/backend/src/apps/slack/auth/index.ts | 90 ------------------- packages/backend/src/apps/smtp/auth/index.ts | 62 ------------- .../backend/src/apps/twilio/auth/index.ts | 46 ---------- .../backend/src/apps/twitter/auth/index.ts | 86 ------------------ packages/backend/src/graphql/schema.graphql | 2 - .../src/helpers/add-reconnection-steps.ts | 81 +++++++++++++++++ packages/backend/src/helpers/get-app.ts | 7 +- packages/types/index.d.ts | 3 +- .../src/components/AppConnectionRow/index.tsx | 2 +- packages/web/src/graphql/queries/get-app.ts | 2 - packages/web/src/graphql/queries/get-apps.ts | 2 - 14 files changed, 89 insertions(+), 556 deletions(-) create mode 100644 packages/backend/src/helpers/add-reconnection-steps.ts diff --git a/packages/backend/src/apps/discord/auth/index.ts b/packages/backend/src/apps/discord/auth/index.ts index 8ebc550c..88499b86 100644 --- a/packages/backend/src/apps/discord/auth/index.ts +++ b/packages/backend/src/apps/discord/auth/index.ts @@ -133,96 +133,6 @@ export default { ] } ], - reconnectionSteps: [ - { - type: 'mutation' as const, - name: 'resetConnection', - arguments: [ - { - name: 'id', - value: '{connection.id}' - } - ] - }, - { - type: 'mutation' as const, - name: 'updateConnection', - arguments: [ - { - name: 'id', - value: '{connection.id}' - }, - { - 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: '{connection.id}' - } - ] - }, - { - type: 'openWithPopup' as const, - name: 'openAuthPopup', - arguments: [ - { - name: 'url', - value: '{createAuthData.url}' - } - ] - }, - { - type: 'mutation' as const, - name: 'updateConnection', - arguments: [ - { - name: 'id', - value: '{connection.id}' - }, - { - name: 'formattedData', - value: null, - properties: [ - { - name: 'oauthVerifier', - value: '{openAuthPopup.code}' - } - ] - } - ] - }, - { - type: 'mutation' as const, - name: 'verifyConnection', - arguments: [ - { - name: 'id', - value: '{connection.id}' - } - ] - } - ], createAuthData, verifyCredentials, diff --git a/packages/backend/src/apps/flickr/auth/index.ts b/packages/backend/src/apps/flickr/auth/index.ts index 4b78c335..0ee4a0b5 100644 --- a/packages/backend/src/apps/flickr/auth/index.ts +++ b/packages/backend/src/apps/flickr/auth/index.ts @@ -117,92 +117,6 @@ export default { ] } ], - reconnectionSteps: [ - { - type: 'mutation' as const, - name: 'resetConnection', - arguments: [ - { - name: 'id', - value: '{connection.id}' - } - ] - }, - { - type: 'mutation' as const, - name: 'updateConnection', - arguments: [ - { - name: 'id', - value: '{connection.id}' - }, - { - 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: '{connection.id}' - } - ] - }, - { - type: 'openWithPopup' as const, - name: 'openAuthPopup', - arguments: [ - { - name: 'url', - value: '{createAuthData.url}' - } - ] - }, - { - type: 'mutation' as const, - name: 'updateConnection', - arguments: [ - { - name: 'id', - value: '{connection.id}' - }, - { - name: 'formattedData', - value: null, - properties: [ - { - name: 'oauthVerifier', - value: '{openAuthPopup.oauth_verifier}' - } - ] - } - ] - }, - { - type: 'mutation' as const, - name: 'verifyConnection', - arguments: [ - { - name: 'id', - value: '{connection.id}' - } - ] - } - ], createAuthData, verifyCredentials, diff --git a/packages/backend/src/apps/github/auth/index.ts b/packages/backend/src/apps/github/auth/index.ts index 5cfc9f59..f49c4dd5 100644 --- a/packages/backend/src/apps/github/auth/index.ts +++ b/packages/backend/src/apps/github/auth/index.ts @@ -117,92 +117,6 @@ export default { ] } ], - reconnectionSteps: [ - { - type: 'mutation' as const, - name: 'resetConnection', - arguments: [ - { - name: 'id', - value: '{connection.id}' - } - ] - }, - { - type: 'mutation' as const, - name: 'updateConnection', - arguments: [ - { - name: 'id', - value: '{connection.id}' - }, - { - 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: '{connection.id}' - } - ] - }, - { - type: 'openWithPopup' as const, - name: 'openAuthPopup', - arguments: [ - { - name: 'url', - value: '{createAuthData.url}' - } - ] - }, - { - type: 'mutation' as const, - name: 'updateConnection', - arguments: [ - { - name: 'id', - value: '{connection.id}' - }, - { - name: 'formattedData', - value: null, - properties: [ - { - name: 'oauthVerifier', - value: '{openAuthPopup.code}' - } - ] - } - ] - }, - { - type: 'mutation' as const, - name: 'verifyConnection', - arguments: [ - { - name: 'id', - value: '{connection.id}' - } - ] - } - ], createAuthData, verifyCredentials, diff --git a/packages/backend/src/apps/slack/auth/index.ts b/packages/backend/src/apps/slack/auth/index.ts index a4d02952..d6d95165 100644 --- a/packages/backend/src/apps/slack/auth/index.ts +++ b/packages/backend/src/apps/slack/auth/index.ts @@ -119,96 +119,6 @@ export default { ], }, ], - reconnectionSteps: [ - { - type: 'mutation' as const, - name: 'resetConnection', - arguments: [ - { - name: 'id', - value: '{connection.id}', - }, - ], - }, - { - type: 'mutation' as const, - name: 'updateConnection', - arguments: [ - { - name: 'id', - value: '{connection.id}', - }, - { - 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: '{connection.id}', - }, - ], - }, - { - type: 'openWithPopup' as const, - name: 'openAuthPopup', - arguments: [ - { - name: 'url', - value: '{createAuthData.url}', - }, - ], - }, - { - type: 'mutation' as const, - name: 'updateConnection', - arguments: [ - { - name: 'id', - value: '{connection.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: '{connection.id}', - }, - ], - }, - ], createAuthData, verifyCredentials, diff --git a/packages/backend/src/apps/smtp/auth/index.ts b/packages/backend/src/apps/smtp/auth/index.ts index 0a4ad9e0..2868abad 100644 --- a/packages/backend/src/apps/smtp/auth/index.ts +++ b/packages/backend/src/apps/smtp/auth/index.ts @@ -138,68 +138,6 @@ export default { ], }, ], - reconnectionSteps: [ - { - type: 'mutation' as const, - name: 'resetConnection', - arguments: [ - { - name: 'id', - value: '{connection.id}', - }, - ], - }, - { - type: 'mutation' as const, - name: 'updateConnection', - arguments: [ - { - name: 'id', - value: '{connection.id}', - }, - { - 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: '{connection.id}', - }, - ], - }, - ], verifyCredentials, isStillVerified, }; diff --git a/packages/backend/src/apps/twilio/auth/index.ts b/packages/backend/src/apps/twilio/auth/index.ts index d33548ba..40e67615 100644 --- a/packages/backend/src/apps/twilio/auth/index.ts +++ b/packages/backend/src/apps/twilio/auth/index.ts @@ -63,52 +63,6 @@ export default { ], }, ], - reconnectionSteps: [ - { - type: 'mutation' as const, - name: 'resetConnection', - arguments: [ - { - name: 'id', - value: '{connection.id}', - }, - ], - }, - { - type: 'mutation' as const, - name: 'updateConnection', - arguments: [ - { - name: 'id', - value: '{connection.id}', - }, - { - 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: '{connection.id}', - }, - ], - }, - ], verifyCredentials, isStillVerified, diff --git a/packages/backend/src/apps/twitter/auth/index.ts b/packages/backend/src/apps/twitter/auth/index.ts index ecf5ae3f..972504eb 100644 --- a/packages/backend/src/apps/twitter/auth/index.ts +++ b/packages/backend/src/apps/twitter/auth/index.ts @@ -115,92 +115,6 @@ export default { ], }, ], - reconnectionSteps: [ - { - type: 'mutation' as const, - name: 'resetConnection', - arguments: [ - { - name: 'id', - value: '{connection.id}', - }, - ], - }, - { - type: 'mutation' as const, - name: 'updateConnection', - arguments: [ - { - name: 'id', - value: '{connection.id}', - }, - { - 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: '{connection.id}', - }, - ], - }, - { - type: 'openWithPopup' as const, - name: 'openAuthPopup', - arguments: [ - { - name: 'url', - value: '{createAuthData.url}', - }, - ], - }, - { - type: 'mutation' as const, - name: 'updateConnection', - arguments: [ - { - name: 'id', - value: '{connection.id}', - }, - { - name: 'formattedData', - value: null, - properties: [ - { - name: 'oauthVerifier', - value: '{openAuthPopup.oauth_verifier}', - }, - ], - }, - ], - }, - { - type: 'mutation' as const, - name: 'verifyConnection', - arguments: [ - { - name: 'id', - value: '{connection.id}', - }, - ], - }, - ], createAuthData, verifyCredentials, diff --git a/packages/backend/src/graphql/schema.graphql b/packages/backend/src/graphql/schema.graphql index 2808552f..b928b995 100644 --- a/packages/backend/src/graphql/schema.graphql +++ b/packages/backend/src/graphql/schema.graphql @@ -126,7 +126,6 @@ type Auth { } type AuthenticationStep { - step: Int type: String name: String arguments: [AuthenticationStepArgument] @@ -316,7 +315,6 @@ input PreviousStepInput { } type ReconnectionStep { - step: Int type: String name: String arguments: [ReconnectionStepArgument] diff --git a/packages/backend/src/helpers/add-reconnection-steps.ts b/packages/backend/src/helpers/add-reconnection-steps.ts new file mode 100644 index 00000000..5110c5b4 --- /dev/null +++ b/packages/backend/src/helpers/add-reconnection-steps.ts @@ -0,0 +1,81 @@ +import { IApp, IAuthenticationStep, IAuthenticationStepField } from '@automatisch/types'; +import cloneDeep from 'lodash/cloneDeep'; + +const connectionIdArgument = { + name: 'id', + value: '{connection.id}', +}; + +const resetConnectionStep = { + type: 'mutation' as const, + name: 'resetConnection', + arguments: [ + connectionIdArgument, + ], +}; + +function replaceCreateConnection(string: string) { + return string.replace( + '{createConnection.id}', + '{connection.id}' + ); +} + +function removeAppKeyArgument(args: IAuthenticationStepField[]) { + return args.filter((argument) => argument.name !== 'key'); +} + +function addConnectionId(step: IAuthenticationStep) { + step.arguments = step.arguments.map((argument) => { + if (typeof argument.value === 'string') { + argument.value = replaceCreateConnection(argument.value); + } + + if (argument.properties) { + argument.properties = argument.properties.map((property) => { + return { + name: property.name, + value: replaceCreateConnection(property.value), + } + }); + } + + return argument; + }); + + return step; +} + +function replaceCreateConnectionsWithUpdate(steps: IAuthenticationStep[]) { + const updatedSteps = cloneDeep(steps); + return updatedSteps.map((step) => { + const updatedStep = addConnectionId(step); + + if (step.name === 'createConnection') { + updatedStep.name = 'updateConnection'; + updatedStep.arguments = removeAppKeyArgument(updatedStep.arguments); + updatedStep.arguments.unshift(connectionIdArgument); + + return updatedStep; + } + + return step; + }) +} + +function addReconnectionSteps(app: IApp): IApp { + const hasReconnectionSteps = app.auth.reconnectionSteps; + + if (hasReconnectionSteps) return app; + + const updatedSteps = replaceCreateConnectionsWithUpdate(app.auth.authenticationSteps); + + app.auth.reconnectionSteps = [ + resetConnectionStep, + ...updatedSteps, + ] + + return app; +} + +export default addReconnectionSteps; diff --git a/packages/backend/src/helpers/get-app.ts b/packages/backend/src/helpers/get-app.ts index c3217d72..be42581e 100644 --- a/packages/backend/src/helpers/get-app.ts +++ b/packages/backend/src/helpers/get-app.ts @@ -6,6 +6,7 @@ import { ITrigger, } from '@automatisch/types'; import { omit, cloneDeep } from 'lodash'; +import addReconnectionSteps from './add-reconnection-steps'; async function getDefaultExport(path: string) { return (await import(path)).default; @@ -16,7 +17,11 @@ function stripFunctions(data: C): C { } const getApp = async (appKey: string, stripFuncs = true) => { - const appData: IApp = cloneDeep(await getDefaultExport(`../apps/${appKey}`)); + let appData: IApp = cloneDeep(await getDefaultExport(`../apps/${appKey}`)); + + if (appData.auth) { + appData = addReconnectionSteps(appData); + } appData.triggers = appData?.triggers?.map((trigger: IRawTrigger) => { return addStaticSubsteps('trigger', appData, trigger); diff --git a/packages/types/index.d.ts b/packages/types/index.d.ts index 639d33a7..09513629 100644 --- a/packages/types/index.d.ts +++ b/packages/types/index.d.ts @@ -143,7 +143,6 @@ export interface IAuthenticationStepField { } export interface IAuthenticationStep { - step: number; type: 'mutation' | 'openWithPopup'; name: string; arguments: IAuthenticationStepField[]; @@ -183,7 +182,7 @@ export interface IAuth { isStillVerified($: IGlobalVariable): Promise; fields: IField[]; authenticationSteps: IAuthenticationStep[]; - reconnectionSteps: IAuthenticationStep[]; + reconnectionSteps?: IAuthenticationStep[]; } export interface IService { diff --git a/packages/web/src/components/AppConnectionRow/index.tsx b/packages/web/src/components/AppConnectionRow/index.tsx index 55a82904..090de246 100644 --- a/packages/web/src/components/AppConnectionRow/index.tsx +++ b/packages/web/src/components/AppConnectionRow/index.tsx @@ -87,7 +87,7 @@ function AppConnectionRow(props: AppConnectionRowProps): React.ReactElement { alignItems="flex-start" spacing={1} > - + {formattedData?.screenName} diff --git a/packages/web/src/graphql/queries/get-app.ts b/packages/web/src/graphql/queries/get-app.ts index bacb5f0f..b0f49df5 100644 --- a/packages/web/src/graphql/queries/get-app.ts +++ b/packages/web/src/graphql/queries/get-app.ts @@ -27,7 +27,6 @@ export const GET_APP = gql` } } authenticationSteps { - step type name arguments { @@ -41,7 +40,6 @@ export const GET_APP = gql` } } reconnectionSteps { - step type name arguments { diff --git a/packages/web/src/graphql/queries/get-apps.ts b/packages/web/src/graphql/queries/get-apps.ts index 6c6df728..59cf4c79 100644 --- a/packages/web/src/graphql/queries/get-apps.ts +++ b/packages/web/src/graphql/queries/get-apps.ts @@ -24,7 +24,6 @@ export const GET_APPS = gql` clickToCopy } authenticationSteps { - step type name arguments { @@ -38,7 +37,6 @@ export const GET_APPS = gql` } } reconnectionSteps { - step type name arguments {