feat(placetel): Implement app structure with authentication
This commit is contained in:
6
packages/backend/src/apps/placetel/assets/favicon.svg
Normal file
6
packages/backend/src/apps/placetel/assets/favicon.svg
Normal 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 |
21
packages/backend/src/apps/placetel/auth/index.ts
Normal file
21
packages/backend/src/apps/placetel/auth/index.ts
Normal 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,
|
||||||
|
};
|
@@ -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;
|
@@ -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;
|
11
packages/backend/src/apps/placetel/common/add-auth-header.ts
Normal file
11
packages/backend/src/apps/placetel/common/add-auth-header.ts
Normal 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;
|
16
packages/backend/src/apps/placetel/index.ts
Normal file
16
packages/backend/src/apps/placetel/index.ts
Normal 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,
|
||||||
|
});
|
Reference in New Issue
Block a user