feat(placetel): Implement app structure with authentication

This commit is contained in:
Faruk AYDIN
2023-10-05 17:26:39 +02:00
parent 57bba90091
commit 712bee297a
6 changed files with 74 additions and 0 deletions

View File

@@ -0,0 +1,6 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 90 90">
<g fill="none" fill-rule="evenodd">
<path d="M45 15c13.807 0 25 11.193 25 25S58.807 65 45 65 20 53.807 20 40s11.193-25 25-25Zm0 14c-6.075 0-11 4.925-11 11s4.925 11 11 11 11-4.925 11-11-4.925-11-11-11Z" fill="#069DD9" fill-rule="nonzero"/>
<path fill="#69B52A" d="M20 41h14v33H20z"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 368 B

View File

@@ -0,0 +1,21 @@
import verifyCredentials from './verify-credentials';
import isStillVerified from './is-still-verified';
export default {
fields: [
{
key: 'apiToken',
label: 'API Token',
type: 'string' as const,
required: true,
readOnly: false,
value: null,
placeholder: null,
description: 'Placetel API Token of your account.',
clickToCopy: false,
},
],
verifyCredentials,
isStillVerified,
};

View File

@@ -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;

View File

@@ -0,0 +1,11 @@
import { IGlobalVariable } from '@automatisch/types';
const verifyCredentials = async ($: IGlobalVariable) => {
const { data } = await $.http.get('/v2/me');
await $.auth.set({
screenName: `${data.name} @ ${data.company}`,
});
};
export default verifyCredentials;

View File

@@ -0,0 +1,11 @@
import { TBeforeRequest } from '@automatisch/types';
const addAuthHeader: TBeforeRequest = ($, requestConfig) => {
if ($.auth.data?.apiToken) {
requestConfig.headers.Authorization = `Bearer ${$.auth.data.apiToken}`;
}
return requestConfig;
};
export default addAuthHeader;

View 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: 'Placetel',
key: 'placetel',
iconUrl: '{BASE_URL}/apps/placetel/assets/favicon.svg',
authDocUrl: 'https://automatisch.io/docs/apps/placetel/connection',
supportsConnections: true,
baseUrl: 'https://placetel.de',
apiBaseUrl: 'https://api.placetel.de',
primaryColor: '069dd9',
beforeRequest: [addAuthHeader],
auth,
});