refactor: Generate authentication steps from auth properties
This commit is contained in:
101
packages/backend/src/helpers/add-authentication-steps.ts
Normal file
101
packages/backend/src/helpers/add-authentication-steps.ts
Normal file
@@ -0,0 +1,101 @@
|
||||
import { IApp } from '@automatisch/types';
|
||||
|
||||
function addAuthenticationSteps(app: IApp): IApp {
|
||||
if (app.auth.generateAuthUrl) {
|
||||
app.auth.authenticationSteps = authenticationStepsWithAuthUrl;
|
||||
} else {
|
||||
app.auth.authenticationSteps = authenticationStepsWithoutAuthUrl;
|
||||
}
|
||||
|
||||
return app;
|
||||
}
|
||||
|
||||
const authenticationStepsWithoutAuthUrl = [
|
||||
{
|
||||
type: 'mutation' as const,
|
||||
name: 'createConnection',
|
||||
arguments: [
|
||||
{
|
||||
name: 'key',
|
||||
value: '{key}',
|
||||
},
|
||||
{
|
||||
name: 'formattedData',
|
||||
value: '{fields.all}',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
type: 'mutation' as const,
|
||||
name: 'verifyConnection',
|
||||
arguments: [
|
||||
{
|
||||
name: 'id',
|
||||
value: '{createConnection.id}',
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
const authenticationStepsWithAuthUrl = [
|
||||
{
|
||||
type: 'mutation' as const,
|
||||
name: 'createConnection',
|
||||
arguments: [
|
||||
{
|
||||
name: 'key',
|
||||
value: '{key}',
|
||||
},
|
||||
{
|
||||
name: 'formattedData',
|
||||
value: '{fields.all}',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
type: 'mutation' as const,
|
||||
name: 'createAuthData',
|
||||
arguments: [
|
||||
{
|
||||
name: 'id',
|
||||
value: '{createConnection.id}',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
type: 'openWithPopup' as const,
|
||||
name: 'openAuthPopup',
|
||||
arguments: [
|
||||
{
|
||||
name: 'url',
|
||||
value: '{createAuthData.url}',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
type: 'mutation' as const,
|
||||
name: 'updateConnection',
|
||||
arguments: [
|
||||
{
|
||||
name: 'id',
|
||||
value: '{createConnection.id}',
|
||||
},
|
||||
{
|
||||
name: 'formattedData',
|
||||
value: '{openAuthPopup.all}',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
type: 'mutation' as const,
|
||||
name: 'verifyConnection',
|
||||
arguments: [
|
||||
{
|
||||
name: 'id',
|
||||
value: '{createConnection.id}',
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
export default addAuthenticationSteps;
|
@@ -8,14 +8,12 @@ import {
|
||||
ITrigger,
|
||||
} from '@automatisch/types';
|
||||
import { omit, cloneDeep } from 'lodash';
|
||||
import addAuthenticationSteps from './add-authentication-steps';
|
||||
import addReconnectionSteps from './add-reconnection-steps';
|
||||
|
||||
type TApps = Record<string, Promise<{ default: IApp }>>;
|
||||
const apps = fs
|
||||
.readdirSync(
|
||||
path.resolve(__dirname, `../apps/`),
|
||||
{ withFileTypes: true }
|
||||
)
|
||||
.readdirSync(path.resolve(__dirname, `../apps/`), { withFileTypes: true })
|
||||
.reduce((apps, dirent) => {
|
||||
if (!dirent.isDirectory()) return apps;
|
||||
|
||||
@@ -36,6 +34,7 @@ const getApp = async (appKey: string, stripFuncs = true) => {
|
||||
let appData: IApp = cloneDeep(await getDefaultExport(appKey));
|
||||
|
||||
if (appData.auth) {
|
||||
appData = addAuthenticationSteps(appData);
|
||||
appData = addReconnectionSteps(appData);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user