Merge branch 'main' into issue-553
This commit is contained in:
@@ -2,6 +2,7 @@ import fs from 'fs';
|
||||
import { join } from 'path';
|
||||
import { IApp } from '@automatisch/types';
|
||||
import appInfoConverter from '../helpers/app-info-converter';
|
||||
import getApp from '../helpers/get-app';
|
||||
|
||||
class App {
|
||||
static folderPath = join(__dirname, '../apps');
|
||||
@@ -11,28 +12,30 @@ class App {
|
||||
// their actions/triggers are implemented!
|
||||
static temporaryList = ['slack', 'twitter', 'scheduler'];
|
||||
|
||||
static findAll(name?: string): IApp[] {
|
||||
static async findAll(name?: string, stripFuncs = true): Promise<IApp[]> {
|
||||
if (!name)
|
||||
return this.temporaryList.map((name) => this.findOneByName(name));
|
||||
return Promise.all(
|
||||
this.temporaryList.map(
|
||||
async (name) => await this.findOneByName(name, stripFuncs)
|
||||
)
|
||||
);
|
||||
|
||||
return this.temporaryList
|
||||
.filter((app) => app.includes(name.toLowerCase()))
|
||||
.map((name) => this.findOneByName(name));
|
||||
return Promise.all(
|
||||
this.temporaryList
|
||||
.filter((app) => app.includes(name.toLowerCase()))
|
||||
.map((name) => this.findOneByName(name, stripFuncs))
|
||||
);
|
||||
}
|
||||
|
||||
static findOneByName(name: string): IApp {
|
||||
const rawAppData = fs.readFileSync(
|
||||
this.folderPath + `/${name}/info.json`,
|
||||
'utf-8'
|
||||
);
|
||||
static async findOneByName(name: string, stripFuncs = false): Promise<IApp> {
|
||||
const rawAppData = await getApp(name.toLocaleLowerCase(), stripFuncs);
|
||||
|
||||
return appInfoConverter(rawAppData);
|
||||
}
|
||||
|
||||
static findOneByKey(key: string): IApp {
|
||||
const rawAppData = fs.readFileSync(
|
||||
this.folderPath + `/${key}/info.json`,
|
||||
'utf-8'
|
||||
);
|
||||
static async findOneByKey(key: string, stripFuncs = false): Promise<IApp> {
|
||||
const rawAppData = await getApp(key, stripFuncs);
|
||||
|
||||
return appInfoConverter(rawAppData);
|
||||
}
|
||||
}
|
||||
|
@@ -12,7 +12,7 @@ import Telemetry from '../helpers/telemetry';
|
||||
class Connection extends Base {
|
||||
id!: string;
|
||||
key!: string;
|
||||
data = '';
|
||||
data: string;
|
||||
formattedData?: IJSONObject;
|
||||
userId!: string;
|
||||
verified = false;
|
||||
@@ -56,10 +56,6 @@ class Connection extends Base {
|
||||
},
|
||||
});
|
||||
|
||||
get appData() {
|
||||
return App.findOneByKey(this.key);
|
||||
}
|
||||
|
||||
encryptData(): void {
|
||||
if (!this.eligibleForEncryption()) return;
|
||||
|
||||
|
@@ -3,14 +3,15 @@ import Base from './base';
|
||||
import Execution from './execution';
|
||||
import Step from './step';
|
||||
import Telemetry from '../helpers/telemetry';
|
||||
import { IJSONObject } from '@automatisch/types';
|
||||
|
||||
class ExecutionStep extends Base {
|
||||
id!: string;
|
||||
executionId!: string;
|
||||
stepId!: string;
|
||||
dataIn!: Record<string, unknown>;
|
||||
dataOut!: Record<string, unknown>;
|
||||
errorDetails: Record<string, unknown>;
|
||||
dataIn!: IJSONObject;
|
||||
dataOut!: IJSONObject;
|
||||
errorDetails: IJSONObject;
|
||||
status = 'failure';
|
||||
step: Step;
|
||||
|
||||
@@ -23,7 +24,7 @@ class ExecutionStep extends Base {
|
||||
id: { type: 'string', format: 'uuid' },
|
||||
executionId: { type: 'string', format: 'uuid' },
|
||||
stepId: { type: 'string' },
|
||||
dataIn: { type: 'object' },
|
||||
dataIn: { type: ['object', 'null'] },
|
||||
dataOut: { type: ['object', 'null'] },
|
||||
status: { type: 'string', enum: ['success', 'failure'] },
|
||||
errorDetails: { type: ['object', 'null'] },
|
||||
|
@@ -11,7 +11,7 @@ class Flow extends Base {
|
||||
name!: string;
|
||||
userId!: string;
|
||||
active: boolean;
|
||||
steps?: [Step];
|
||||
steps: Step[];
|
||||
published_at: string;
|
||||
|
||||
static tableName = 'flows';
|
||||
|
@@ -4,7 +4,7 @@ import App from './app';
|
||||
import Flow from './flow';
|
||||
import Connection from './connection';
|
||||
import ExecutionStep from './execution-step';
|
||||
import type { IStep } from '@automatisch/types';
|
||||
import type { IJSONObject, IStep } from '@automatisch/types';
|
||||
import Telemetry from '../helpers/telemetry';
|
||||
import appConfig from '../config/app';
|
||||
|
||||
@@ -17,10 +17,10 @@ class Step extends Base {
|
||||
connectionId?: string;
|
||||
status = 'incomplete';
|
||||
position!: number;
|
||||
parameters: Record<string, unknown>;
|
||||
parameters: IJSONObject;
|
||||
connection?: Connection;
|
||||
flow: Flow;
|
||||
executionSteps?: [ExecutionStep];
|
||||
executionSteps: ExecutionStep[];
|
||||
|
||||
static tableName = 'steps';
|
||||
|
||||
@@ -78,10 +78,6 @@ class Step extends Base {
|
||||
return `${appConfig.baseUrl}/apps/${this.appKey}/assets/favicon.svg`;
|
||||
}
|
||||
|
||||
get appData() {
|
||||
return App.findOneByKey(this.appKey);
|
||||
}
|
||||
|
||||
async $afterInsert(queryContext: QueryContext) {
|
||||
await super.$afterInsert(queryContext);
|
||||
Telemetry.stepCreated(this);
|
||||
@@ -101,12 +97,8 @@ class Step extends Base {
|
||||
|
||||
const { appKey, key } = this;
|
||||
|
||||
const connection = await this.$relatedQuery('connection');
|
||||
const flow = await this.$relatedQuery('flow');
|
||||
|
||||
const AppClass = (await import(`../apps/${appKey}`)).default;
|
||||
const appInstance = new AppClass(connection, flow, this);
|
||||
const command = appInstance.triggers[key];
|
||||
const app = await App.findOneByKey(appKey);
|
||||
const command = app.triggers.find((trigger) => trigger.key === key);
|
||||
|
||||
return command;
|
||||
}
|
||||
|
@@ -10,10 +10,10 @@ class User extends Base {
|
||||
id!: string;
|
||||
email!: string;
|
||||
password!: string;
|
||||
connections?: [Connection];
|
||||
flows?: [Flow];
|
||||
steps?: [Step];
|
||||
executions?: [Execution];
|
||||
connections?: Connection[];
|
||||
flows?: Flow[];
|
||||
steps?: Step[];
|
||||
executions?: Execution[];
|
||||
|
||||
static tableName = 'users';
|
||||
|
||||
|
Reference in New Issue
Block a user