From 8ef2bd3b8d355249bd85fb1b6466c7778fb9326a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C4=B1dvan=20Akca?= Date: Fri, 26 Jan 2024 13:44:34 +0300 Subject: [PATCH] feat(mailerlite): add mailerlite integration --- .../src/apps/mailerlite/assets/favicon.svg | 1 + .../backend/src/apps/mailerlite/auth/index.js | 33 +++++++++++++++++++ .../apps/mailerlite/auth/is-still-verified.js | 8 +++++ .../mailerlite/auth/verify-credentials.js | 10 ++++++ .../apps/mailerlite/common/add-auth-header.js | 9 +++++ packages/backend/src/apps/mailerlite/index.js | 16 +++++++++ packages/docs/pages/.vitepress/config.js | 8 ++++- .../docs/pages/apps/mailerlite/connection.md | 15 +++++++++ .../docs/pages/public/favicons/mailerlite.svg | 1 + 9 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 packages/backend/src/apps/mailerlite/assets/favicon.svg create mode 100644 packages/backend/src/apps/mailerlite/auth/index.js create mode 100644 packages/backend/src/apps/mailerlite/auth/is-still-verified.js create mode 100644 packages/backend/src/apps/mailerlite/auth/verify-credentials.js create mode 100644 packages/backend/src/apps/mailerlite/common/add-auth-header.js create mode 100644 packages/backend/src/apps/mailerlite/index.js create mode 100644 packages/docs/pages/apps/mailerlite/connection.md create mode 100644 packages/docs/pages/public/favicons/mailerlite.svg diff --git a/packages/backend/src/apps/mailerlite/assets/favicon.svg b/packages/backend/src/apps/mailerlite/assets/favicon.svg new file mode 100644 index 00000000..b3824538 --- /dev/null +++ b/packages/backend/src/apps/mailerlite/assets/favicon.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/packages/backend/src/apps/mailerlite/auth/index.js b/packages/backend/src/apps/mailerlite/auth/index.js new file mode 100644 index 00000000..0c244e3d --- /dev/null +++ b/packages/backend/src/apps/mailerlite/auth/index.js @@ -0,0 +1,33 @@ +import verifyCredentials from './verify-credentials.js'; +import isStillVerified from './is-still-verified.js'; + +export default { + fields: [ + { + key: 'screenName', + label: 'Screen Name', + type: 'string', + required: true, + readOnly: false, + value: null, + placeholder: null, + description: + 'Screen name of your connection to be used on Automatisch UI.', + clickToCopy: false, + }, + { + key: 'apiKey', + label: 'API Key', + type: 'string', + required: true, + readOnly: false, + value: null, + placeholder: null, + description: 'MailerLite API key of your account.', + clickToCopy: false, + }, + ], + + verifyCredentials, + isStillVerified, +}; diff --git a/packages/backend/src/apps/mailerlite/auth/is-still-verified.js b/packages/backend/src/apps/mailerlite/auth/is-still-verified.js new file mode 100644 index 00000000..6663679a --- /dev/null +++ b/packages/backend/src/apps/mailerlite/auth/is-still-verified.js @@ -0,0 +1,8 @@ +import verifyCredentials from './verify-credentials.js'; + +const isStillVerified = async ($) => { + await verifyCredentials($); + return true; +}; + +export default isStillVerified; diff --git a/packages/backend/src/apps/mailerlite/auth/verify-credentials.js b/packages/backend/src/apps/mailerlite/auth/verify-credentials.js new file mode 100644 index 00000000..8e9d002c --- /dev/null +++ b/packages/backend/src/apps/mailerlite/auth/verify-credentials.js @@ -0,0 +1,10 @@ +const verifyCredentials = async ($) => { + await $.http.get('/campaigns'); + + await $.auth.set({ + screenName: $.auth.data.screenName, + apiKey: $.auth.data.apiKey, + }); +}; + +export default verifyCredentials; diff --git a/packages/backend/src/apps/mailerlite/common/add-auth-header.js b/packages/backend/src/apps/mailerlite/common/add-auth-header.js new file mode 100644 index 00000000..f9f5acba --- /dev/null +++ b/packages/backend/src/apps/mailerlite/common/add-auth-header.js @@ -0,0 +1,9 @@ +const addAuthHeader = ($, requestConfig) => { + if ($.auth.data?.apiKey) { + requestConfig.headers.Authorization = `Bearer ${$.auth.data.apiKey}`; + } + + return requestConfig; +}; + +export default addAuthHeader; diff --git a/packages/backend/src/apps/mailerlite/index.js b/packages/backend/src/apps/mailerlite/index.js new file mode 100644 index 00000000..285964b4 --- /dev/null +++ b/packages/backend/src/apps/mailerlite/index.js @@ -0,0 +1,16 @@ +import defineApp from '../../helpers/define-app.js'; +import addAuthHeader from './common/add-auth-header.js'; +import auth from './auth/index.js'; + +export default defineApp({ + name: 'MailerLite', + key: 'mailerlite', + iconUrl: '{BASE_URL}/apps/mailerlite/assets/favicon.svg', + authDocUrl: 'https://automatisch.io/docs/apps/mailerlite/connection', + supportsConnections: true, + baseUrl: 'https://www.mailerlite.com', + apiBaseUrl: 'https://connect.mailerlite.com/api', + primaryColor: '09C269', + beforeRequest: [addAuthHeader], + auth, +}); diff --git a/packages/docs/pages/.vitepress/config.js b/packages/docs/pages/.vitepress/config.js index 04d3fdcf..10d060db 100644 --- a/packages/docs/pages/.vitepress/config.js +++ b/packages/docs/pages/.vitepress/config.js @@ -197,6 +197,12 @@ export default defineConfig({ { text: 'Connection', link: '/apps/invoice-ninja/connection' }, ], }, + { + text: 'MailerLite', + collapsible: true, + collapsed: true, + items: [{ text: 'Connection', link: '/apps/mailerlite/connection' }], + }, { text: 'Mattermost', collapsible: true, @@ -305,7 +311,7 @@ export default defineConfig({ collapsed: true, items: [ { text: 'Actions', link: '/apps/removebg/actions' }, - { text: 'Connection', link: '/apps/removebg/connection' } + { text: 'Connection', link: '/apps/removebg/connection' }, ], }, { diff --git a/packages/docs/pages/apps/mailerlite/connection.md b/packages/docs/pages/apps/mailerlite/connection.md new file mode 100644 index 00000000..d49c0667 --- /dev/null +++ b/packages/docs/pages/apps/mailerlite/connection.md @@ -0,0 +1,15 @@ +# MailerLite + +:::info +This page explains the steps you need to follow to set up the MailerLite +connection in Automatisch. If any of the steps are outdated, please let us know! +::: + +1. Login to your MailerLite account: [https://www.mailerlite.com/](https://www.mailerlite.com/). +2. Click on the **Integrations** tab on the left. +3. Click on the **Use** button in the MailerLite API section. +4. Click on the **Generate new token** button. +5. Fill the form and click on the **Create token** button. +6. Copy the token from the popup to the `API Key` field on Automatisch. +7. Write any screen name to be displayed in Automatisch. +8. Now, you can start using the MailerLite connection with Automatisch. diff --git a/packages/docs/pages/public/favicons/mailerlite.svg b/packages/docs/pages/public/favicons/mailerlite.svg new file mode 100644 index 00000000..b3824538 --- /dev/null +++ b/packages/docs/pages/public/favicons/mailerlite.svg @@ -0,0 +1 @@ + \ No newline at end of file