Merge branch 'main' into issue-553
This commit is contained in:
43
packages/backend/src/helpers/compute-parameters.ts
Normal file
43
packages/backend/src/helpers/compute-parameters.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import Step from '../models/step';
|
||||
import ExecutionStep from '../models/execution-step';
|
||||
import get from 'lodash.get';
|
||||
|
||||
const variableRegExp = /({{step\.[\da-zA-Z-]+(?:\.[\da-zA-Z-]+)+}})/g;
|
||||
|
||||
export default function computeParameters(
|
||||
parameters: Step['parameters'],
|
||||
executionSteps: ExecutionStep[]
|
||||
): Step['parameters'] {
|
||||
const entries = Object.entries(parameters);
|
||||
return entries.reduce((result, [key, value]: [string, unknown]) => {
|
||||
if (typeof value === 'string') {
|
||||
const parts = value.split(variableRegExp);
|
||||
|
||||
const computedValue = parts
|
||||
.map((part: string) => {
|
||||
const isVariable = part.match(variableRegExp);
|
||||
if (isVariable) {
|
||||
const stepIdAndKeyPath = part.replace(/{{step.|}}/g, '') as string;
|
||||
const [stepId, ...keyPaths] = stepIdAndKeyPath.split('.');
|
||||
const keyPath = keyPaths.join('.');
|
||||
const executionStep = executionSteps.find((executionStep) => {
|
||||
return executionStep.stepId === stepId;
|
||||
});
|
||||
const data = executionStep?.dataOut;
|
||||
const dataValue = get(data, keyPath);
|
||||
return dataValue;
|
||||
}
|
||||
|
||||
return part;
|
||||
})
|
||||
.join('');
|
||||
|
||||
return {
|
||||
...result,
|
||||
[key]: computedValue,
|
||||
};
|
||||
}
|
||||
|
||||
return result;
|
||||
}, {});
|
||||
}
|
@@ -1,13 +1,19 @@
|
||||
import { ExpressAdapter } from '@bull-board/express';
|
||||
import { createBullBoard } from '@bull-board/api';
|
||||
import { BullMQAdapter } from '@bull-board/api/bullMQAdapter';
|
||||
import processorQueue from '../queues/processor';
|
||||
import flowQueue from '../queues/flow';
|
||||
import triggerQueue from '../queues/trigger';
|
||||
import actionQueue from '../queues/action';
|
||||
|
||||
const serverAdapter = new ExpressAdapter();
|
||||
|
||||
const createBullBoardHandler = async (serverAdapter: ExpressAdapter) => {
|
||||
createBullBoard({
|
||||
queues: [new BullMQAdapter(processorQueue)],
|
||||
queues: [
|
||||
new BullMQAdapter(flowQueue),
|
||||
new BullMQAdapter(triggerQueue),
|
||||
new BullMQAdapter(actionQueue),
|
||||
],
|
||||
serverAdapter: serverAdapter,
|
||||
});
|
||||
};
|
||||
|
@@ -2,17 +2,29 @@ import createHttpClient from './http-client';
|
||||
import Connection from '../models/connection';
|
||||
import Flow from '../models/flow';
|
||||
import Step from '../models/step';
|
||||
import Execution from '../models/execution';
|
||||
import { IJSONObject, IApp, IGlobalVariable } from '@automatisch/types';
|
||||
|
||||
type GlobalVariableOptions = {
|
||||
connection?: Connection;
|
||||
app: IApp;
|
||||
flow?: Flow;
|
||||
step?: Step;
|
||||
execution?: Execution;
|
||||
testRun?: boolean;
|
||||
};
|
||||
|
||||
const globalVariable = async (
|
||||
connection: Connection,
|
||||
appData: IApp,
|
||||
flow?: Flow,
|
||||
currentStep?: Step
|
||||
options: GlobalVariableOptions
|
||||
): Promise<IGlobalVariable> => {
|
||||
const { connection, app, flow, step, execution, testRun = false } = options;
|
||||
|
||||
const lastInternalId = await flow?.lastInternalId();
|
||||
|
||||
return {
|
||||
const trigger = await step?.getTriggerCommand();
|
||||
const nextStep = await step?.getNextStep();
|
||||
|
||||
const variable: IGlobalVariable = {
|
||||
auth: {
|
||||
set: async (args: IJSONObject) => {
|
||||
if (connection) {
|
||||
@@ -28,17 +40,39 @@ const globalVariable = async (
|
||||
},
|
||||
data: connection?.formattedData,
|
||||
},
|
||||
app: appData,
|
||||
http: createHttpClient({ baseURL: appData.baseUrl }),
|
||||
db: {
|
||||
flow: {
|
||||
lastInternalId,
|
||||
},
|
||||
step: {
|
||||
parameters: currentStep?.parameters || {},
|
||||
},
|
||||
app: app,
|
||||
http: createHttpClient({ baseURL: app.baseUrl }),
|
||||
flow: {
|
||||
id: flow?.id,
|
||||
lastInternalId,
|
||||
},
|
||||
step: {
|
||||
id: step?.id,
|
||||
appKey: step?.appKey,
|
||||
parameters: step?.parameters || {},
|
||||
},
|
||||
nextStep: {
|
||||
id: nextStep?.id,
|
||||
appKey: nextStep?.appKey,
|
||||
parameters: nextStep?.parameters || {},
|
||||
},
|
||||
execution: {
|
||||
id: execution?.id,
|
||||
testRun,
|
||||
},
|
||||
};
|
||||
|
||||
if (trigger && trigger.dedupeStrategy === 'unique') {
|
||||
const lastInternalIds = await flow?.lastInternalIds();
|
||||
|
||||
const isAlreadyProcessed = (internalId: string) => {
|
||||
return lastInternalIds?.includes(internalId);
|
||||
};
|
||||
|
||||
variable.flow.isAlreadyProcessed = isAlreadyProcessed;
|
||||
}
|
||||
|
||||
return variable;
|
||||
};
|
||||
|
||||
export default globalVariable;
|
||||
|
Reference in New Issue
Block a user