diff --git a/packages/backend/src/apps/carbone/assets/favicon.svg b/packages/backend/src/apps/carbone/assets/favicon.svg new file mode 100644 index 00000000..cadf2c90 --- /dev/null +++ b/packages/backend/src/apps/carbone/assets/favicon.svg @@ -0,0 +1,444 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/packages/backend/src/apps/carbone/auth/index.ts b/packages/backend/src/apps/carbone/auth/index.ts new file mode 100644 index 00000000..0242bc91 --- /dev/null +++ b/packages/backend/src/apps/carbone/auth/index.ts @@ -0,0 +1,33 @@ +import verifyCredentials from './verify-credentials'; +import isStillVerified from './is-still-verified'; + +export default { + fields: [ + { + key: 'screenName', + label: 'Screen Name', + type: 'string' as const, + 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' as const, + required: true, + readOnly: false, + value: null, + placeholder: null, + description: 'Carbone API key of your account.', + clickToCopy: false, + }, + ], + + verifyCredentials, + isStillVerified, +}; diff --git a/packages/backend/src/apps/carbone/auth/is-still-verified.ts b/packages/backend/src/apps/carbone/auth/is-still-verified.ts new file mode 100644 index 00000000..66bb963e --- /dev/null +++ b/packages/backend/src/apps/carbone/auth/is-still-verified.ts @@ -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; diff --git a/packages/backend/src/apps/carbone/auth/verify-credentials.ts b/packages/backend/src/apps/carbone/auth/verify-credentials.ts new file mode 100644 index 00000000..3c5d01e3 --- /dev/null +++ b/packages/backend/src/apps/carbone/auth/verify-credentials.ts @@ -0,0 +1,12 @@ +import { IGlobalVariable } from '@automatisch/types'; + +const verifyCredentials = async ($: IGlobalVariable) => { + await $.http.get('/templates'); + + await $.auth.set({ + screenName: $.auth.data.screenName, + apiKey: $.auth.data.apiKey, + }); +}; + +export default verifyCredentials; diff --git a/packages/backend/src/apps/carbone/common/add-auth-header.ts b/packages/backend/src/apps/carbone/common/add-auth-header.ts new file mode 100644 index 00000000..615acdcd --- /dev/null +++ b/packages/backend/src/apps/carbone/common/add-auth-header.ts @@ -0,0 +1,12 @@ +import { TBeforeRequest } from '@automatisch/types'; + +const addAuthHeader: TBeforeRequest = ($, requestConfig) => { + if ($.auth.data?.apiKey) { + requestConfig.headers.Authorization = `Bearer ${$.auth.data.apiKey}`; + requestConfig.headers['carbone-version'] = '4'; + } + + return requestConfig; +}; + +export default addAuthHeader; diff --git a/packages/backend/src/apps/carbone/index.d.ts b/packages/backend/src/apps/carbone/index.d.ts new file mode 100644 index 00000000..e69de29b diff --git a/packages/backend/src/apps/carbone/index.ts b/packages/backend/src/apps/carbone/index.ts new file mode 100644 index 00000000..d24d1670 --- /dev/null +++ b/packages/backend/src/apps/carbone/index.ts @@ -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: 'Carbone', + key: 'carbone', + iconUrl: '{BASE_URL}/apps/carbone/assets/favicon.svg', + authDocUrl: 'https://automatisch.io/docs/apps/carbone/connection', + supportsConnections: true, + baseUrl: 'https://carbone.io', + apiBaseUrl: 'https://api.carbone.io', + primaryColor: '6f42c1', + beforeRequest: [addAuthHeader], + auth, +}); diff --git a/packages/docs/pages/.vitepress/config.js b/packages/docs/pages/.vitepress/config.js index f28b037d..94a0394e 100644 --- a/packages/docs/pages/.vitepress/config.js +++ b/packages/docs/pages/.vitepress/config.js @@ -32,6 +32,12 @@ export default defineConfig({ ], sidebar: { '/apps/': [ + { + text: 'Carbone', + collapsible: true, + collapsed: true, + items: [{ text: 'Connection', link: '/apps/carbone/connection' }], + }, { text: 'DeepL', collapsible: true, diff --git a/packages/docs/pages/apps/carbone/connection.md b/packages/docs/pages/apps/carbone/connection.md new file mode 100644 index 00000000..598e4dfa --- /dev/null +++ b/packages/docs/pages/apps/carbone/connection.md @@ -0,0 +1,10 @@ +# Carbone + +:::info +This page explains the steps you need to follow to set up the Carbone +connection in Automatisch. If any of the steps are outdated, please let us know! +::: + +1. Login to your Carbone account: [https://account.carbone.io/](https://account.carbone.io/). +2. Copy either `Test API key` or `Production API key` from the page to the `API Key` field on Automatisch. +3. Now, you can start using the Carbone connection with Automatisch. diff --git a/packages/docs/pages/public/favicons/carbone.svg b/packages/docs/pages/public/favicons/carbone.svg new file mode 100644 index 00000000..cadf2c90 --- /dev/null +++ b/packages/docs/pages/public/favicons/carbone.svg @@ -0,0 +1,444 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/packages/e2e-tests/tests/apps/list-apps.spec.js b/packages/e2e-tests/tests/apps/list-apps.spec.js index 83ecd362..50303d5e 100644 --- a/packages/e2e-tests/tests/apps/list-apps.spec.js +++ b/packages/e2e-tests/tests/apps/list-apps.spec.js @@ -54,7 +54,7 @@ test.describe('Apps page', () => { test.setTimeout(60000); await applicationsPage.page.getByTestId('app-list-item').first().click(); - await expect(applicationsPage.page).toHaveURL('/app/deepl/connections/add?shared=false'); + await expect(applicationsPage.page).toHaveURL('/app/carbone/connections/add?shared=false'); await expect(applicationsPage.page.getByTestId('add-app-connection-dialog')).toBeVisible(); await applicationsPage.clickAway(); @@ -64,10 +64,10 @@ test.describe('Apps page', () => { applicationsPage, }) => { await applicationsPage.page.getByTestId('app-list-item').first().click(); - await expect(applicationsPage.page).toHaveURL('/app/deepl/connections/add?shared=false'); + await expect(applicationsPage.page).toHaveURL('/app/carbone/connections/add?shared=false'); await expect(applicationsPage.page.getByTestId('add-app-connection-dialog')).toBeVisible(); await applicationsPage.clickAway(); - await expect(applicationsPage.page).toHaveURL('/app/deepl/connections'); + await expect(applicationsPage.page).toHaveURL('/app/carbone/connections'); await expect(applicationsPage.page.getByTestId('add-app-connection-dialog')).toBeHidden(); }); });