feat: add defineTrigger and defineAction
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
"license": "AGPL-3.0",
|
||||
"description": "The open source Zapier alternative. Build workflow automation without spending time and money.",
|
||||
"scripts": {
|
||||
"dev": "ts-node-dev src/server.ts",
|
||||
"dev": "ts-node-dev --exit-child src/server.ts",
|
||||
"worker": "nodemon --watch 'src/**/*.ts' --exec 'ts-node' src/worker.ts",
|
||||
"build": "tsc && yarn copy-statics",
|
||||
"build:watch": "nodemon --watch 'src/**/*.ts' --watch 'bin/**/*.ts' --exec yarn build --ext ts",
|
||||
@@ -134,4 +134,4 @@
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,4 +1,5 @@
|
||||
import { DateTime } from 'luxon';
|
||||
import { IJSONObject } from '@automatisch/types';
|
||||
|
||||
export default function getDateTimeObjectRepresentation(dateTime: DateTime) {
|
||||
const defaults = dateTime.toObject();
|
||||
@@ -10,5 +11,5 @@ export default function getDateTimeObjectRepresentation(dateTime: DateTime) {
|
||||
pretty_time: dateTime.toLocaleString(DateTime.TIME_WITH_SECONDS),
|
||||
pretty_day_of_week: dateTime.toFormat('cccc'),
|
||||
day_of_week: dateTime.weekday,
|
||||
};
|
||||
} as IJSONObject;
|
||||
}
|
||||
|
@@ -6,5 +6,4 @@ export default {
|
||||
authDocUrl: "https://automatisch.io/docs/connections/scheduler",
|
||||
primaryColor: "0059F7",
|
||||
supportsConnections: false,
|
||||
requiresAuthentication: false,
|
||||
};
|
||||
|
@@ -1,10 +1,11 @@
|
||||
import { DateTime } from 'luxon';
|
||||
import { IGlobalVariable, IJSONValue } from '@automatisch/types';
|
||||
import defineTrigger from '../../../../helpers/define-trigger';
|
||||
import cronTimes from '../../common/cron-times';
|
||||
import getNextCronDateTime from '../../common/get-next-cron-date-time';
|
||||
import getDateTimeObjectRepresentation from '../../common/get-date-time-object';
|
||||
|
||||
export default {
|
||||
export default defineTrigger({
|
||||
name: 'Every day',
|
||||
key: 'everyDay',
|
||||
description: 'Triggers every day.',
|
||||
@@ -154,14 +155,14 @@ export default {
|
||||
return cronTimes.everyDayExcludingWeekendsAt(parameters.hour as number);
|
||||
},
|
||||
|
||||
async run($: IGlobalVariable) {
|
||||
async run($) {
|
||||
const nextCronDateTime = getNextCronDateTime(
|
||||
this.getInterval($.step.parameters)
|
||||
);
|
||||
const dateTime = DateTime.now();
|
||||
const dateTimeObjectRepresentation = getDateTimeObjectRepresentation(
|
||||
$.execution.testRun ? nextCronDateTime : dateTime
|
||||
) as IJSONValue;
|
||||
);
|
||||
|
||||
const dataItem = {
|
||||
raw: dateTimeObjectRepresentation,
|
||||
@@ -172,4 +173,4 @@ export default {
|
||||
|
||||
return { data: [dataItem] };
|
||||
},
|
||||
};
|
||||
});
|
||||
|
@@ -1,10 +1,11 @@
|
||||
import { DateTime } from 'luxon';
|
||||
import { IGlobalVariable, IJSONValue } from '@automatisch/types';
|
||||
import { IGlobalVariable } from '@automatisch/types';
|
||||
import defineTrigger from '../../../../helpers/define-trigger';
|
||||
import cronTimes from '../../common/cron-times';
|
||||
import getNextCronDateTime from '../../common/get-next-cron-date-time';
|
||||
import getDateTimeObjectRepresentation from '../../common/get-date-time-object';
|
||||
|
||||
export default {
|
||||
export default defineTrigger({
|
||||
name: 'Every hour',
|
||||
key: 'everyHour',
|
||||
description: 'Triggers every hour.',
|
||||
@@ -48,14 +49,14 @@ export default {
|
||||
return cronTimes.everyHourExcludingWeekends;
|
||||
},
|
||||
|
||||
async run($: IGlobalVariable) {
|
||||
async run($) {
|
||||
const nextCronDateTime = getNextCronDateTime(
|
||||
this.getInterval($.step.parameters)
|
||||
);
|
||||
const dateTime = DateTime.now();
|
||||
const dateTimeObjectRepresentation = getDateTimeObjectRepresentation(
|
||||
$.execution.testRun ? nextCronDateTime : dateTime
|
||||
) as IJSONValue;
|
||||
);
|
||||
|
||||
const dataItem = {
|
||||
raw: dateTimeObjectRepresentation,
|
||||
@@ -66,4 +67,4 @@ export default {
|
||||
|
||||
return { data: [dataItem] };
|
||||
},
|
||||
};
|
||||
});
|
||||
|
@@ -1,10 +1,11 @@
|
||||
import { DateTime } from 'luxon';
|
||||
import { IGlobalVariable, IJSONValue } from '@automatisch/types';
|
||||
import { IGlobalVariable } from '@automatisch/types';
|
||||
import defineTrigger from '../../../../helpers/define-trigger';
|
||||
import cronTimes from '../../common/cron-times';
|
||||
import getNextCronDateTime from '../../common/get-next-cron-date-time';
|
||||
import getDateTimeObjectRepresentation from '../../common/get-date-time-object';
|
||||
|
||||
export default {
|
||||
export default defineTrigger({
|
||||
name: 'Every month',
|
||||
key: 'everyMonth',
|
||||
description: 'Triggers every month.',
|
||||
@@ -22,127 +23,127 @@ export default {
|
||||
variables: false,
|
||||
options: [
|
||||
{
|
||||
label: 1,
|
||||
label: '1',
|
||||
value: 1,
|
||||
},
|
||||
{
|
||||
label: 2,
|
||||
label: '2',
|
||||
value: 2,
|
||||
},
|
||||
{
|
||||
label: 3,
|
||||
label: '3',
|
||||
value: 3,
|
||||
},
|
||||
{
|
||||
label: 4,
|
||||
label: '4',
|
||||
value: 4,
|
||||
},
|
||||
{
|
||||
label: 5,
|
||||
label: '5',
|
||||
value: 5,
|
||||
},
|
||||
{
|
||||
label: 6,
|
||||
label: '6',
|
||||
value: 6,
|
||||
},
|
||||
{
|
||||
label: 7,
|
||||
label: '7',
|
||||
value: 7,
|
||||
},
|
||||
{
|
||||
label: 8,
|
||||
label: '8',
|
||||
value: 8,
|
||||
},
|
||||
{
|
||||
label: 9,
|
||||
label: '9',
|
||||
value: 9,
|
||||
},
|
||||
{
|
||||
label: 10,
|
||||
label: '10',
|
||||
value: 10,
|
||||
},
|
||||
{
|
||||
label: 11,
|
||||
label: '11',
|
||||
value: 11,
|
||||
},
|
||||
{
|
||||
label: 12,
|
||||
label: '12',
|
||||
value: 12,
|
||||
},
|
||||
{
|
||||
label: 13,
|
||||
label: '13',
|
||||
value: 13,
|
||||
},
|
||||
{
|
||||
label: 14,
|
||||
label: '14',
|
||||
value: 14,
|
||||
},
|
||||
{
|
||||
label: 15,
|
||||
label: '15',
|
||||
value: 15,
|
||||
},
|
||||
{
|
||||
label: 16,
|
||||
label: '16',
|
||||
value: 16,
|
||||
},
|
||||
{
|
||||
label: 17,
|
||||
label: '17',
|
||||
value: 17,
|
||||
},
|
||||
{
|
||||
label: 18,
|
||||
label: '18',
|
||||
value: 18,
|
||||
},
|
||||
{
|
||||
label: 19,
|
||||
label: '19',
|
||||
value: 19,
|
||||
},
|
||||
{
|
||||
label: 20,
|
||||
label: '20',
|
||||
value: 20,
|
||||
},
|
||||
{
|
||||
label: 21,
|
||||
label: '21',
|
||||
value: 21,
|
||||
},
|
||||
{
|
||||
label: 22,
|
||||
label: '22',
|
||||
value: 22,
|
||||
},
|
||||
{
|
||||
label: 23,
|
||||
label: '23',
|
||||
value: 23,
|
||||
},
|
||||
{
|
||||
label: 24,
|
||||
label: '24',
|
||||
value: 24,
|
||||
},
|
||||
{
|
||||
label: 25,
|
||||
label: '25',
|
||||
value: 25,
|
||||
},
|
||||
{
|
||||
label: 26,
|
||||
label: '26',
|
||||
value: 26,
|
||||
},
|
||||
{
|
||||
label: 27,
|
||||
label: '27',
|
||||
value: 27,
|
||||
},
|
||||
{
|
||||
label: 28,
|
||||
label: '28',
|
||||
value: 28,
|
||||
},
|
||||
{
|
||||
label: 29,
|
||||
label: '29',
|
||||
value: 29,
|
||||
},
|
||||
{
|
||||
label: 30,
|
||||
label: '30',
|
||||
value: 30,
|
||||
},
|
||||
{
|
||||
label: 31,
|
||||
label: '31',
|
||||
value: 31,
|
||||
},
|
||||
],
|
||||
@@ -270,14 +271,14 @@ export default {
|
||||
return interval;
|
||||
},
|
||||
|
||||
async run($: IGlobalVariable) {
|
||||
async run($) {
|
||||
const nextCronDateTime = getNextCronDateTime(
|
||||
this.getInterval($.step.parameters)
|
||||
);
|
||||
const dateTime = DateTime.now();
|
||||
const dateTimeObjectRepresentation = getDateTimeObjectRepresentation(
|
||||
$.execution.testRun ? nextCronDateTime : dateTime
|
||||
) as IJSONValue;
|
||||
);
|
||||
|
||||
const dataItem = {
|
||||
raw: dateTimeObjectRepresentation,
|
||||
@@ -288,4 +289,4 @@ export default {
|
||||
|
||||
return { data: [dataItem] };
|
||||
},
|
||||
};
|
||||
});
|
||||
|
@@ -1,10 +1,11 @@
|
||||
import { DateTime } from 'luxon';
|
||||
import { IGlobalVariable, IJSONValue } from '@automatisch/types';
|
||||
import defineTrigger from '../../../../helpers/define-trigger';
|
||||
import cronTimes from '../../common/cron-times';
|
||||
import getNextCronDateTime from '../../common/get-next-cron-date-time';
|
||||
import getDateTimeObjectRepresentation from '../../common/get-date-time-object';
|
||||
|
||||
export default {
|
||||
export default defineTrigger({
|
||||
name: 'Every week',
|
||||
key: 'everyWeek',
|
||||
description: 'Triggers every week.',
|
||||
@@ -174,14 +175,14 @@ export default {
|
||||
return interval;
|
||||
},
|
||||
|
||||
async run($: IGlobalVariable) {
|
||||
async run($) {
|
||||
const nextCronDateTime = getNextCronDateTime(
|
||||
this.getInterval($.step.parameters)
|
||||
);
|
||||
const dateTime = DateTime.now();
|
||||
const dateTimeObjectRepresentation = getDateTimeObjectRepresentation(
|
||||
$.execution.testRun ? nextCronDateTime : dateTime
|
||||
) as IJSONValue;
|
||||
);
|
||||
|
||||
const dataItem = {
|
||||
raw: dateTimeObjectRepresentation,
|
||||
@@ -192,4 +193,4 @@ export default {
|
||||
|
||||
return { data: [dataItem] };
|
||||
},
|
||||
};
|
||||
});
|
||||
|
@@ -28,7 +28,7 @@ const findMessage = async ($: IGlobalVariable, options: FindMessageOptions) => {
|
||||
|
||||
const message: IActionOutput = {
|
||||
data: {
|
||||
raw: data?.data?.messages.matches[0],
|
||||
raw: data?.messages.matches[0],
|
||||
},
|
||||
error: response?.integrationError || (!data.ok && data),
|
||||
};
|
||||
|
@@ -1,7 +1,7 @@
|
||||
import { IGlobalVariable } from '@automatisch/types';
|
||||
import defineAction from '../../../../helpers/define-action';
|
||||
import findMessage from './find-message';
|
||||
|
||||
export default {
|
||||
export default defineAction({
|
||||
name: 'Find message',
|
||||
key: 'findMessage',
|
||||
description: 'Find a Slack message using the Slack Search feature.',
|
||||
@@ -71,7 +71,7 @@ export default {
|
||||
},
|
||||
],
|
||||
|
||||
async run($: IGlobalVariable) {
|
||||
async run($) {
|
||||
const parameters = $.step.parameters;
|
||||
const query = parameters.query as string;
|
||||
const sortBy = parameters.sortBy as string;
|
||||
@@ -87,4 +87,4 @@ export default {
|
||||
|
||||
return messages;
|
||||
},
|
||||
};
|
||||
});
|
||||
|
@@ -1,7 +1,7 @@
|
||||
import { IGlobalVariable } from '@automatisch/types';
|
||||
import defineAction from '../../../../helpers/define-action';
|
||||
import postMessage from './post-message';
|
||||
|
||||
export default {
|
||||
export default defineAction({
|
||||
name: 'Send a message to channel',
|
||||
key: 'sendMessageToChannel',
|
||||
description: 'Send a message to a specific channel you specify.',
|
||||
@@ -48,7 +48,7 @@ export default {
|
||||
},
|
||||
],
|
||||
|
||||
async run($: IGlobalVariable) {
|
||||
async run($) {
|
||||
const channelId = $.step.parameters.channel as string;
|
||||
const text = $.step.parameters.message as string;
|
||||
|
||||
@@ -56,4 +56,4 @@ export default {
|
||||
|
||||
return message;
|
||||
},
|
||||
};
|
||||
});
|
||||
|
@@ -1,7 +1,7 @@
|
||||
import { IGlobalVariable } from '@automatisch/types';
|
||||
import defineTrigger from '../../../../helpers/define-trigger';
|
||||
import getUserTweets from '../../common/get-user-tweets';
|
||||
|
||||
export default {
|
||||
export default defineTrigger({
|
||||
name: 'My Tweets',
|
||||
key: 'myTweets',
|
||||
pollInterval: 15,
|
||||
@@ -17,9 +17,9 @@ export default {
|
||||
},
|
||||
],
|
||||
|
||||
async run($: IGlobalVariable) {
|
||||
async run($) {
|
||||
return await getUserTweets($, {
|
||||
currentUser: true,
|
||||
});
|
||||
},
|
||||
};
|
||||
});
|
||||
|
@@ -1,7 +1,7 @@
|
||||
import { IGlobalVariable } from '@automatisch/types';
|
||||
import defineTrigger from '../../../../helpers/define-trigger';
|
||||
import myFollowers from './my-followers';
|
||||
|
||||
export default {
|
||||
export default defineTrigger({
|
||||
name: 'New follower of me',
|
||||
key: 'myFollowers',
|
||||
pollInterval: 15,
|
||||
@@ -17,7 +17,7 @@ export default {
|
||||
},
|
||||
],
|
||||
|
||||
async run($: IGlobalVariable) {
|
||||
async run($) {
|
||||
return await myFollowers($, $.flow.lastInternalId);
|
||||
},
|
||||
};
|
||||
});
|
||||
|
@@ -1,7 +1,7 @@
|
||||
import { IGlobalVariable } from '@automatisch/types';
|
||||
import defineTrigger from '../../../../helpers/define-trigger';
|
||||
import searchTweets from './search-tweets';
|
||||
|
||||
export default {
|
||||
export default defineTrigger({
|
||||
name: 'Search Tweets',
|
||||
key: 'searchTweets',
|
||||
pollInterval: 15,
|
||||
@@ -30,7 +30,7 @@ export default {
|
||||
},
|
||||
],
|
||||
|
||||
async run($: IGlobalVariable) {
|
||||
async run($) {
|
||||
return await searchTweets($);
|
||||
},
|
||||
};
|
||||
});
|
||||
|
@@ -1,7 +1,7 @@
|
||||
import { IGlobalVariable } from '@automatisch/types';
|
||||
import defineTrigger from '../../../../helpers/define-trigger';
|
||||
import getUserTweets from '../../common/get-user-tweets';
|
||||
|
||||
export default {
|
||||
export default defineTrigger({
|
||||
name: 'User Tweets',
|
||||
key: 'userTweets',
|
||||
pollInterval: 15,
|
||||
@@ -29,9 +29,9 @@ export default {
|
||||
},
|
||||
],
|
||||
|
||||
async run($: IGlobalVariable) {
|
||||
async run($) {
|
||||
return await getUserTweets($, {
|
||||
currentUser: false,
|
||||
});
|
||||
},
|
||||
};
|
||||
});
|
||||
|
@@ -9,10 +9,14 @@ const appInfoConverter = (rawAppData: IApp) => {
|
||||
|
||||
if (rawAppData.auth?.fields) {
|
||||
rawAppData.auth.fields = rawAppData.auth.fields.map((field) => {
|
||||
return {
|
||||
...field,
|
||||
value: field.value?.replace('{WEB_APP_URL}', appConfig.webAppUrl),
|
||||
};
|
||||
if (typeof field.value === 'string') {
|
||||
return {
|
||||
...field,
|
||||
value: field.value.replace('{WEB_APP_URL}', appConfig.webAppUrl),
|
||||
};
|
||||
}
|
||||
|
||||
return field
|
||||
});
|
||||
}
|
||||
|
||||
|
5
packages/backend/src/helpers/define-action.ts
Normal file
5
packages/backend/src/helpers/define-action.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import { IAction } from '@automatisch/types';
|
||||
|
||||
export default function defineAction(actionDefinition: IAction): IAction {
|
||||
return actionDefinition;
|
||||
}
|
5
packages/backend/src/helpers/define-trigger.ts
Normal file
5
packages/backend/src/helpers/define-trigger.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import { ITrigger } from '@automatisch/types';
|
||||
|
||||
export default function defineTrigger(triggerDefinition: ITrigger): ITrigger {
|
||||
return triggerDefinition;
|
||||
}
|
@@ -16,17 +16,13 @@ async function getFileContent<C>(
|
||||
path: string,
|
||||
stripFuncs: boolean
|
||||
): Promise<C> {
|
||||
try {
|
||||
const fileContent = await getDefaultExport(path);
|
||||
const fileContent = await getDefaultExport(path);
|
||||
|
||||
if (stripFuncs) {
|
||||
return stripFunctions(fileContent);
|
||||
}
|
||||
|
||||
return fileContent;
|
||||
} catch (err) {
|
||||
return null;
|
||||
if (stripFuncs) {
|
||||
return stripFunctions(fileContent);
|
||||
}
|
||||
|
||||
return fileContent;
|
||||
}
|
||||
|
||||
async function getChildrenContentInDirectory<C>(
|
||||
@@ -55,10 +51,12 @@ async function getChildrenContentInDirectory<C>(
|
||||
const getApp = async (appKey: string, stripFuncs = true) => {
|
||||
const appData: IApp = await getDefaultExport(`../apps/${appKey}`);
|
||||
|
||||
appData.auth = await getFileContent<IAuth>(
|
||||
`../apps/${appKey}/auth`,
|
||||
stripFuncs
|
||||
);
|
||||
if (appData.supportsConnections) {
|
||||
appData.auth = await getFileContent<IAuth>(
|
||||
`../apps/${appKey}/auth`,
|
||||
stripFuncs
|
||||
);
|
||||
}
|
||||
appData.triggers = await getChildrenContentInDirectory<ITrigger>(
|
||||
`${appKey}/triggers`,
|
||||
stripFuncs
|
||||
|
@@ -48,7 +48,7 @@ export const processAction = async (options: ProcessActionOptions) => {
|
||||
status: actionOutput.error ? 'failure' : 'success',
|
||||
dataIn: computedParameters,
|
||||
dataOut: actionOutput.error ? null : actionOutput.data.raw,
|
||||
errorDetails: actionOutput.error,
|
||||
errorDetails: actionOutput.error ? actionOutput.error : null,
|
||||
});
|
||||
|
||||
return { flowId, stepId, executionId, executionStep };
|
||||
|
Reference in New Issue
Block a user