From 9a973c8257a4ae4d7ae6fc81ef096f14a6f7d2af Mon Sep 17 00:00:00 2001 From: Ali BARIN Date: Fri, 28 Oct 2022 15:48:39 +0200 Subject: [PATCH] refactor: inline auth, data, triggers and actions in apps --- .../backend/src/apps/flickr/auth/index.ts | 28 ++++----- .../backend/src/apps/flickr/data/index.ts | 3 + packages/backend/src/apps/flickr/index.ts | 6 ++ .../backend/src/apps/flickr/triggers/index.ts | 11 ++++ .../triggers/new-photos-in-album/index.ts | 2 +- .../apps/github/actions/create-issue/index.ts | 6 +- .../backend/src/apps/github/actions/index.ts | 3 + .../backend/src/apps/github/auth/index.ts | 28 ++++----- .../backend/src/apps/github/data/index.ts | 7 +++ packages/backend/src/apps/github/index.ts | 8 +++ .../backend/src/apps/github/triggers/index.ts | 11 ++++ .../apps/github/triggers/new-issues/index.ts | 6 +- .../triggers/new-pull-requests/index.ts | 2 +- .../github/triggers/new-stargazers/index.ts | 2 +- .../github/triggers/new-watchers/index.ts | 2 +- packages/backend/src/apps/rss/index.ts | 2 + .../backend/src/apps/rss/triggers/index.ts | 3 + .../rss/triggers/new-items-in-feed/index.ts | 2 +- packages/backend/src/apps/scheduler/index.ts | 11 +++- .../scheduler/triggers/every-day/index.ts | 4 +- .../scheduler/triggers/every-hour/index.ts | 2 +- .../scheduler/triggers/every-month/index.ts | 4 +- .../scheduler/triggers/every-week/index.ts | 4 +- .../src/apps/scheduler/triggers/index.ts | 11 ++++ .../apps/slack/actions/find-message/index.ts | 6 +- .../backend/src/apps/slack/actions/index.ts | 7 +++ .../send-a-message-to-channel/index.ts | 4 +- packages/backend/src/apps/slack/auth/index.ts | 12 ++-- packages/backend/src/apps/slack/data/index.ts | 3 + packages/backend/src/apps/slack/index.ts | 6 ++ .../backend/src/apps/smtp/actions/index.ts | 3 + .../src/apps/smtp/actions/send-email/index.ts | 16 ++--- packages/backend/src/apps/smtp/auth/index.ts | 24 ++++---- packages/backend/src/apps/smtp/index.ts | 4 ++ .../backend/src/apps/twilio/actions/index.ts | 3 + .../src/apps/twilio/actions/send-sms/index.ts | 6 +- .../backend/src/apps/twilio/auth/index.ts | 14 ++--- packages/backend/src/apps/twilio/index.ts | 4 ++ .../twitter/actions/create-tweet/index.ts | 3 +- .../backend/src/apps/twitter/actions/index.ts | 3 + .../backend/src/apps/twitter/auth/index.ts | 28 ++++----- packages/backend/src/apps/twitter/index.ts | 6 ++ .../src/apps/twitter/triggers/index.ts | 11 ++++ .../twitter/triggers/search-tweets/index.ts | 2 +- .../twitter/triggers/user-tweets/index.ts | 2 +- packages/backend/src/helpers/get-app.ts | 61 +------------------ packages/types/index.d.ts | 4 +- 47 files changed, 233 insertions(+), 167 deletions(-) create mode 100644 packages/backend/src/apps/flickr/data/index.ts create mode 100644 packages/backend/src/apps/flickr/triggers/index.ts create mode 100644 packages/backend/src/apps/github/actions/index.ts create mode 100644 packages/backend/src/apps/github/data/index.ts create mode 100644 packages/backend/src/apps/github/triggers/index.ts create mode 100644 packages/backend/src/apps/rss/triggers/index.ts create mode 100644 packages/backend/src/apps/scheduler/triggers/index.ts create mode 100644 packages/backend/src/apps/slack/actions/index.ts create mode 100644 packages/backend/src/apps/slack/data/index.ts create mode 100644 packages/backend/src/apps/smtp/actions/index.ts create mode 100644 packages/backend/src/apps/twilio/actions/index.ts create mode 100644 packages/backend/src/apps/twitter/actions/index.ts create mode 100644 packages/backend/src/apps/twitter/triggers/index.ts diff --git a/packages/backend/src/apps/flickr/auth/index.ts b/packages/backend/src/apps/flickr/auth/index.ts index 6f0e4d0e..33aeb02c 100644 --- a/packages/backend/src/apps/flickr/auth/index.ts +++ b/packages/backend/src/apps/flickr/auth/index.ts @@ -7,7 +7,7 @@ export default { { key: 'oAuthRedirectUrl', label: 'OAuth Redirect URL', - type: 'string', + type: 'string' as const, required: true, readOnly: true, value: '{WEB_APP_URL}/app/flickr/connections/add', @@ -19,7 +19,7 @@ export default { { key: 'consumerKey', label: 'Consumer Key', - type: 'string', + type: 'string' as const, required: true, readOnly: false, value: null, @@ -31,7 +31,7 @@ export default { { key: 'consumerSecret', label: 'Consumer Secret', - type: 'string', + type: 'string' as const, required: true, readOnly: false, value: null, @@ -44,7 +44,7 @@ export default { authenticationSteps: [ { step: 1, - type: 'mutation', + type: 'mutation' as const, name: 'createConnection', arguments: [ { @@ -69,7 +69,7 @@ export default { }, { step: 2, - type: 'mutation', + type: 'mutation' as const, name: 'createAuthData', arguments: [ { @@ -80,7 +80,7 @@ export default { }, { step: 3, - type: 'openWithPopup', + type: 'openWithPopup' as const, name: 'openAuthPopup', arguments: [ { @@ -91,7 +91,7 @@ export default { }, { step: 4, - type: 'mutation', + type: 'mutation' as const, name: 'updateConnection', arguments: [ { @@ -112,7 +112,7 @@ export default { }, { step: 5, - type: 'mutation', + type: 'mutation' as const, name: 'verifyConnection', arguments: [ { @@ -125,7 +125,7 @@ export default { reconnectionSteps: [ { step: 1, - type: 'mutation', + type: 'mutation' as const, name: 'resetConnection', arguments: [ { @@ -136,7 +136,7 @@ export default { }, { step: 2, - type: 'mutation', + type: 'mutation' as const, name: 'updateConnection', arguments: [ { @@ -161,7 +161,7 @@ export default { }, { step: 3, - type: 'mutation', + type: 'mutation' as const, name: 'createAuthData', arguments: [ { @@ -172,7 +172,7 @@ export default { }, { step: 4, - type: 'openWithPopup', + type: 'openWithPopup' as const, name: 'openAuthPopup', arguments: [ { @@ -183,7 +183,7 @@ export default { }, { step: 5, - type: 'mutation', + type: 'mutation' as const, name: 'updateConnection', arguments: [ { @@ -204,7 +204,7 @@ export default { }, { step: 6, - type: 'mutation', + type: 'mutation' as const, name: 'verifyConnection', arguments: [ { diff --git a/packages/backend/src/apps/flickr/data/index.ts b/packages/backend/src/apps/flickr/data/index.ts new file mode 100644 index 00000000..b4d81ec4 --- /dev/null +++ b/packages/backend/src/apps/flickr/data/index.ts @@ -0,0 +1,3 @@ +import listAlbums from './list-albums'; + +export default [listAlbums]; diff --git a/packages/backend/src/apps/flickr/index.ts b/packages/backend/src/apps/flickr/index.ts index ca71f2af..8fe47623 100644 --- a/packages/backend/src/apps/flickr/index.ts +++ b/packages/backend/src/apps/flickr/index.ts @@ -1,5 +1,8 @@ import defineApp from '../../helpers/define-app'; import addAuthHeader from './common/add-auth-header'; +import auth from './auth'; +import triggers from './triggers'; +import data from './data'; export default defineApp({ name: 'Flickr', @@ -12,4 +15,7 @@ export default defineApp({ baseUrl: 'https://www.flickr.com/', apiBaseUrl: 'https://www.flickr.com/services', beforeRequest: [addAuthHeader], + auth, + triggers, + data, }); diff --git a/packages/backend/src/apps/flickr/triggers/index.ts b/packages/backend/src/apps/flickr/triggers/index.ts new file mode 100644 index 00000000..c84993e5 --- /dev/null +++ b/packages/backend/src/apps/flickr/triggers/index.ts @@ -0,0 +1,11 @@ +import newAlbums from './new-albums'; +import newFavoritePhotos from './new-favorite-photos'; +import newPhotos from './new-photos'; +import newPhotosInAlbums from './new-photos-in-album'; + +export default [ + newAlbums, + newFavoritePhotos, + newPhotos, + newPhotosInAlbums, +]; diff --git a/packages/backend/src/apps/flickr/triggers/new-photos-in-album/index.ts b/packages/backend/src/apps/flickr/triggers/new-photos-in-album/index.ts index b5332df1..37395b68 100644 --- a/packages/backend/src/apps/flickr/triggers/new-photos-in-album/index.ts +++ b/packages/backend/src/apps/flickr/triggers/new-photos-in-album/index.ts @@ -18,7 +18,7 @@ export default defineTrigger({ { label: 'Album', key: 'album', - type: 'dropdown', + type: 'dropdown' as const, required: true, variables: false, source: { diff --git a/packages/backend/src/apps/github/actions/create-issue/index.ts b/packages/backend/src/apps/github/actions/create-issue/index.ts index 43ee8a12..71bddb71 100644 --- a/packages/backend/src/apps/github/actions/create-issue/index.ts +++ b/packages/backend/src/apps/github/actions/create-issue/index.ts @@ -18,7 +18,7 @@ export default defineAction({ { label: 'Repo', key: 'repo', - type: 'dropdown', + type: 'dropdown' as const, required: false, variables: false, source: { @@ -35,14 +35,14 @@ export default defineAction({ { label: 'Title', key: 'title', - type: 'string', + type: 'string' as const, required: true, variables: true, }, { label: 'Body', key: 'body', - type: 'string', + type: 'string' as const, required: true, variables: true, }, diff --git a/packages/backend/src/apps/github/actions/index.ts b/packages/backend/src/apps/github/actions/index.ts new file mode 100644 index 00000000..06c945f8 --- /dev/null +++ b/packages/backend/src/apps/github/actions/index.ts @@ -0,0 +1,3 @@ +import createIssue from './create-issue'; + +export default [createIssue]; diff --git a/packages/backend/src/apps/github/auth/index.ts b/packages/backend/src/apps/github/auth/index.ts index 2ceb0c5a..5f4637ce 100644 --- a/packages/backend/src/apps/github/auth/index.ts +++ b/packages/backend/src/apps/github/auth/index.ts @@ -7,7 +7,7 @@ export default { { key: 'oAuthRedirectUrl', label: 'OAuth Redirect URL', - type: 'string', + type: 'string' as const, required: true, readOnly: true, value: '{WEB_APP_URL}/app/github/connections/add', @@ -19,7 +19,7 @@ export default { { key: 'consumerKey', label: 'Client ID', - type: 'string', + type: 'string' as const, required: true, readOnly: false, value: null, @@ -31,7 +31,7 @@ export default { { key: 'consumerSecret', label: 'Client Secret', - type: 'string', + type: 'string' as const, required: true, readOnly: false, value: null, @@ -44,7 +44,7 @@ export default { authenticationSteps: [ { step: 1, - type: 'mutation', + type: 'mutation' as const, name: 'createConnection', arguments: [ { @@ -69,7 +69,7 @@ export default { }, { step: 2, - type: 'mutation', + type: 'mutation' as const, name: 'createAuthData', arguments: [ { @@ -80,7 +80,7 @@ export default { }, { step: 3, - type: 'openWithPopup', + type: 'openWithPopup' as const, name: 'openAuthPopup', arguments: [ { @@ -91,7 +91,7 @@ export default { }, { step: 4, - type: 'mutation', + type: 'mutation' as const, name: 'updateConnection', arguments: [ { @@ -112,7 +112,7 @@ export default { }, { step: 5, - type: 'mutation', + type: 'mutation' as const, name: 'verifyConnection', arguments: [ { @@ -125,7 +125,7 @@ export default { reconnectionSteps: [ { step: 1, - type: 'mutation', + type: 'mutation' as const, name: 'resetConnection', arguments: [ { @@ -136,7 +136,7 @@ export default { }, { step: 2, - type: 'mutation', + type: 'mutation' as const, name: 'updateConnection', arguments: [ { @@ -161,7 +161,7 @@ export default { }, { step: 3, - type: 'mutation', + type: 'mutation' as const, name: 'createAuthData', arguments: [ { @@ -172,7 +172,7 @@ export default { }, { step: 4, - type: 'openWithPopup', + type: 'openWithPopup' as const, name: 'openAuthPopup', arguments: [ { @@ -183,7 +183,7 @@ export default { }, { step: 5, - type: 'mutation', + type: 'mutation' as const, name: 'updateConnection', arguments: [ { @@ -204,7 +204,7 @@ export default { }, { step: 6, - type: 'mutation', + type: 'mutation' as const, name: 'verifyConnection', arguments: [ { diff --git a/packages/backend/src/apps/github/data/index.ts b/packages/backend/src/apps/github/data/index.ts new file mode 100644 index 00000000..d48026f2 --- /dev/null +++ b/packages/backend/src/apps/github/data/index.ts @@ -0,0 +1,7 @@ +import listLabels from './list-labels'; +import listRepos from './list-repos'; + +export default [ + listLabels, + listRepos, +]; diff --git a/packages/backend/src/apps/github/index.ts b/packages/backend/src/apps/github/index.ts index 7cf3b2c5..bc6d4e28 100644 --- a/packages/backend/src/apps/github/index.ts +++ b/packages/backend/src/apps/github/index.ts @@ -1,5 +1,9 @@ import defineApp from '../../helpers/define-app'; import addAuthHeader from './common/add-auth-header'; +import auth from './auth'; +import triggers from './triggers'; +import actions from './actions'; +import data from './data'; export default defineApp({ name: 'Github', @@ -11,4 +15,8 @@ export default defineApp({ primaryColor: '000000', supportsConnections: true, beforeRequest: [addAuthHeader], + auth, + triggers, + actions, + data, }); diff --git a/packages/backend/src/apps/github/triggers/index.ts b/packages/backend/src/apps/github/triggers/index.ts new file mode 100644 index 00000000..81c50126 --- /dev/null +++ b/packages/backend/src/apps/github/triggers/index.ts @@ -0,0 +1,11 @@ +import newIssues from './new-issues'; +import newPullRequests from './new-pull-requests'; +import newStargazers from './new-stargazers'; +import newWatchers from './new-watchers'; + +export default [ + newIssues, + newPullRequests, + newStargazers, + newWatchers, +]; diff --git a/packages/backend/src/apps/github/triggers/new-issues/index.ts b/packages/backend/src/apps/github/triggers/new-issues/index.ts index 1166a0f4..52ef224b 100644 --- a/packages/backend/src/apps/github/triggers/new-issues/index.ts +++ b/packages/backend/src/apps/github/triggers/new-issues/index.ts @@ -18,7 +18,7 @@ export default defineTrigger({ { label: 'Repo', key: 'repo', - type: 'dropdown', + type: 'dropdown' as const, required: false, variables: false, source: { @@ -35,7 +35,7 @@ export default defineTrigger({ { label: 'Which types of issues should this trigger on?', key: 'issueType', - type: 'dropdown', + type: 'dropdown' as const, description: 'Defaults to any issue you can see.', required: true, variables: false, @@ -66,7 +66,7 @@ export default defineTrigger({ { label: 'Label', key: 'label', - type: 'dropdown', + type: 'dropdown' as const, description: 'Only trigger on issues when this label is added.', required: false, variables: false, diff --git a/packages/backend/src/apps/github/triggers/new-pull-requests/index.ts b/packages/backend/src/apps/github/triggers/new-pull-requests/index.ts index a6d262e2..c3053e4a 100644 --- a/packages/backend/src/apps/github/triggers/new-pull-requests/index.ts +++ b/packages/backend/src/apps/github/triggers/new-pull-requests/index.ts @@ -18,7 +18,7 @@ export default defineTrigger({ { label: 'Repo', key: 'repo', - type: 'dropdown', + type: 'dropdown' as const, required: true, variables: false, source: { diff --git a/packages/backend/src/apps/github/triggers/new-stargazers/index.ts b/packages/backend/src/apps/github/triggers/new-stargazers/index.ts index 7ebfda63..91d0a373 100644 --- a/packages/backend/src/apps/github/triggers/new-stargazers/index.ts +++ b/packages/backend/src/apps/github/triggers/new-stargazers/index.ts @@ -18,7 +18,7 @@ export default defineTrigger({ { label: 'Repo', key: 'repo', - type: 'dropdown', + type: 'dropdown' as const, required: true, variables: false, source: { diff --git a/packages/backend/src/apps/github/triggers/new-watchers/index.ts b/packages/backend/src/apps/github/triggers/new-watchers/index.ts index a583c1f2..ee3a5f05 100644 --- a/packages/backend/src/apps/github/triggers/new-watchers/index.ts +++ b/packages/backend/src/apps/github/triggers/new-watchers/index.ts @@ -18,7 +18,7 @@ export default defineTrigger({ { label: 'Repo', key: 'repo', - type: 'dropdown', + type: 'dropdown' as const, required: true, variables: false, source: { diff --git a/packages/backend/src/apps/rss/index.ts b/packages/backend/src/apps/rss/index.ts index 6a145dd0..03086902 100644 --- a/packages/backend/src/apps/rss/index.ts +++ b/packages/backend/src/apps/rss/index.ts @@ -1,4 +1,5 @@ import defineApp from '../../helpers/define-app'; +import triggers from './triggers'; export default defineApp({ name: 'RSS', @@ -10,4 +11,5 @@ export default defineApp({ apiBaseUrl: '', primaryColor: 'ff8800', beforeRequest: [], + triggers, }); diff --git a/packages/backend/src/apps/rss/triggers/index.ts b/packages/backend/src/apps/rss/triggers/index.ts new file mode 100644 index 00000000..6d882c22 --- /dev/null +++ b/packages/backend/src/apps/rss/triggers/index.ts @@ -0,0 +1,3 @@ +import newItemsInFeed from './new-items-in-feed'; + +export default [newItemsInFeed]; diff --git a/packages/backend/src/apps/rss/triggers/new-items-in-feed/index.ts b/packages/backend/src/apps/rss/triggers/new-items-in-feed/index.ts index 71728f25..e6758d18 100644 --- a/packages/backend/src/apps/rss/triggers/new-items-in-feed/index.ts +++ b/packages/backend/src/apps/rss/triggers/new-items-in-feed/index.ts @@ -14,7 +14,7 @@ export default defineTrigger({ { label: 'Feed URL', key: 'feedUrl', - type: 'string', + type: 'string' as const, required: true, description: 'Paste your publicly accessible RSS URL here.', variables: false, diff --git a/packages/backend/src/apps/scheduler/index.ts b/packages/backend/src/apps/scheduler/index.ts index 94c6e6bb..5b9c5cde 100644 --- a/packages/backend/src/apps/scheduler/index.ts +++ b/packages/backend/src/apps/scheduler/index.ts @@ -1,9 +1,16 @@ -export default { +import defineApp from "../../helpers/define-app"; +import triggers from './triggers'; + +export default defineApp({ name: "Scheduler", key: "scheduler", iconUrl: "{BASE_URL}/apps/scheduler/assets/favicon.svg", docUrl: "https://automatisch.io/docs/scheduler", authDocUrl: "https://automatisch.io/docs/connections/scheduler", + baseUrl: '', + apiBaseUrl: '', primaryColor: "0059F7", + beforeRequest: [], supportsConnections: false, -}; + triggers, +}); diff --git a/packages/backend/src/apps/scheduler/triggers/every-day/index.ts b/packages/backend/src/apps/scheduler/triggers/every-day/index.ts index 67f923ed..ff1684ee 100644 --- a/packages/backend/src/apps/scheduler/triggers/every-day/index.ts +++ b/packages/backend/src/apps/scheduler/triggers/every-day/index.ts @@ -17,7 +17,7 @@ export default defineTrigger({ { label: 'Trigger on weekends?', key: 'triggersOnWeekend', - type: 'dropdown', + type: 'dropdown' as const, description: 'Should this flow trigger on Saturday and Sunday?', required: true, value: true, @@ -36,7 +36,7 @@ export default defineTrigger({ { label: 'Time of day', key: 'hour', - type: 'dropdown', + type: 'dropdown' as const, required: true, value: null, variables: false, diff --git a/packages/backend/src/apps/scheduler/triggers/every-hour/index.ts b/packages/backend/src/apps/scheduler/triggers/every-hour/index.ts index 81f56571..b73987b6 100644 --- a/packages/backend/src/apps/scheduler/triggers/every-hour/index.ts +++ b/packages/backend/src/apps/scheduler/triggers/every-hour/index.ts @@ -17,7 +17,7 @@ export default defineTrigger({ { label: 'Trigger on weekends?', key: 'triggersOnWeekend', - type: 'dropdown', + type: 'dropdown' as const, description: 'Should this flow trigger on Saturday and Sunday?', required: true, value: true, diff --git a/packages/backend/src/apps/scheduler/triggers/every-month/index.ts b/packages/backend/src/apps/scheduler/triggers/every-month/index.ts index 0e48c3c7..562231a8 100644 --- a/packages/backend/src/apps/scheduler/triggers/every-month/index.ts +++ b/packages/backend/src/apps/scheduler/triggers/every-month/index.ts @@ -17,7 +17,7 @@ export default defineTrigger({ { label: 'Day of the month', key: 'day', - type: 'dropdown', + type: 'dropdown' as const, required: true, value: null, variables: false, @@ -151,7 +151,7 @@ export default defineTrigger({ { label: 'Time of day', key: 'hour', - type: 'dropdown', + type: 'dropdown' as const, required: true, value: null, variables: false, diff --git a/packages/backend/src/apps/scheduler/triggers/every-week/index.ts b/packages/backend/src/apps/scheduler/triggers/every-week/index.ts index 590daa90..ace091eb 100644 --- a/packages/backend/src/apps/scheduler/triggers/every-week/index.ts +++ b/packages/backend/src/apps/scheduler/triggers/every-week/index.ts @@ -17,7 +17,7 @@ export default defineTrigger({ { label: 'Day of the week', key: 'weekday', - type: 'dropdown', + type: 'dropdown' as const, required: true, value: null, variables: false, @@ -55,7 +55,7 @@ export default defineTrigger({ { label: 'Time of day', key: 'hour', - type: 'dropdown', + type: 'dropdown' as const, required: true, value: null, variables: false, diff --git a/packages/backend/src/apps/scheduler/triggers/index.ts b/packages/backend/src/apps/scheduler/triggers/index.ts new file mode 100644 index 00000000..02cfd4e0 --- /dev/null +++ b/packages/backend/src/apps/scheduler/triggers/index.ts @@ -0,0 +1,11 @@ +import everyHour from './every-hour'; +import everyDay from './every-day'; +import everyWeek from './every-week'; +import everyMonth from './every-month'; + +export default [ + everyHour, + everyDay, + everyWeek, + everyMonth, +]; diff --git a/packages/backend/src/apps/slack/actions/find-message/index.ts b/packages/backend/src/apps/slack/actions/find-message/index.ts index 679ce201..01086405 100644 --- a/packages/backend/src/apps/slack/actions/find-message/index.ts +++ b/packages/backend/src/apps/slack/actions/find-message/index.ts @@ -17,7 +17,7 @@ export default defineAction({ { label: 'Search Query', key: 'query', - type: 'string', + type: 'string' as const, required: true, description: 'Search query to use for finding matching messages. See the Slack Search Documentation for more information on constructing a query.', @@ -26,7 +26,7 @@ export default defineAction({ { label: 'Sort by', key: 'sortBy', - type: 'dropdown', + type: 'dropdown' as const, description: 'Sort messages by their match strength or by their date. Default is score.', required: true, @@ -46,7 +46,7 @@ export default defineAction({ { label: 'Sort direction', key: 'sortDirection', - type: 'dropdown', + type: 'dropdown' as const, description: 'Sort matching messages in ascending or descending order. Default is descending.', required: true, diff --git a/packages/backend/src/apps/slack/actions/index.ts b/packages/backend/src/apps/slack/actions/index.ts new file mode 100644 index 00000000..851b5005 --- /dev/null +++ b/packages/backend/src/apps/slack/actions/index.ts @@ -0,0 +1,7 @@ +import findMessage from './find-message'; +import sendMessageToChannel from './send-a-message-to-channel'; + +export default [ + findMessage, + sendMessageToChannel, +]; diff --git a/packages/backend/src/apps/slack/actions/send-a-message-to-channel/index.ts b/packages/backend/src/apps/slack/actions/send-a-message-to-channel/index.ts index 5f7ef5fe..91fe6928 100644 --- a/packages/backend/src/apps/slack/actions/send-a-message-to-channel/index.ts +++ b/packages/backend/src/apps/slack/actions/send-a-message-to-channel/index.ts @@ -17,7 +17,7 @@ export default defineAction({ { label: 'Channel', key: 'channel', - type: 'dropdown', + type: 'dropdown' as const, required: true, description: 'Pick a channel to send the message to.', variables: false, @@ -35,7 +35,7 @@ export default defineAction({ { label: 'Message text', key: 'message', - type: 'string', + type: 'string' as const, required: true, description: 'The content of your new message.', variables: true, diff --git a/packages/backend/src/apps/slack/auth/index.ts b/packages/backend/src/apps/slack/auth/index.ts index 99c3fdf3..0f36afcc 100644 --- a/packages/backend/src/apps/slack/auth/index.ts +++ b/packages/backend/src/apps/slack/auth/index.ts @@ -6,7 +6,7 @@ export default { { key: 'accessToken', label: 'Access Token', - type: 'string', + type: 'string' as const, required: true, readOnly: false, value: null, @@ -18,7 +18,7 @@ export default { authenticationSteps: [ { step: 1, - type: 'mutation', + type: 'mutation' as const, name: 'createConnection', arguments: [ { @@ -39,7 +39,7 @@ export default { }, { step: 2, - type: 'mutation', + type: 'mutation' as const, name: 'verifyConnection', arguments: [ { @@ -52,7 +52,7 @@ export default { reconnectionSteps: [ { step: 1, - type: 'mutation', + type: 'mutation' as const, name: 'resetConnection', arguments: [ { @@ -63,7 +63,7 @@ export default { }, { step: 2, - type: 'mutation', + type: 'mutation' as const, name: 'updateConnection', arguments: [ { @@ -84,7 +84,7 @@ export default { }, { step: 3, - type: 'mutation', + type: 'mutation' as const, name: 'verifyConnection', arguments: [ { diff --git a/packages/backend/src/apps/slack/data/index.ts b/packages/backend/src/apps/slack/data/index.ts new file mode 100644 index 00000000..fae496fc --- /dev/null +++ b/packages/backend/src/apps/slack/data/index.ts @@ -0,0 +1,3 @@ +import listChannels from './list-channels'; + +export default [listChannels]; diff --git a/packages/backend/src/apps/slack/index.ts b/packages/backend/src/apps/slack/index.ts index 000d0deb..8b0a0097 100644 --- a/packages/backend/src/apps/slack/index.ts +++ b/packages/backend/src/apps/slack/index.ts @@ -1,5 +1,8 @@ import defineApp from '../../helpers/define-app'; import addAuthHeader from './common/add-auth-header'; +import actions from './actions'; +import auth from './auth'; +import data from './data'; export default defineApp({ name: 'Slack', @@ -11,4 +14,7 @@ export default defineApp({ apiBaseUrl: 'https://slack.com/api', primaryColor: '4a154b', beforeRequest: [addAuthHeader], + auth, + actions, + data, }); diff --git a/packages/backend/src/apps/smtp/actions/index.ts b/packages/backend/src/apps/smtp/actions/index.ts new file mode 100644 index 00000000..e688be4d --- /dev/null +++ b/packages/backend/src/apps/smtp/actions/index.ts @@ -0,0 +1,3 @@ +import sendEmail from './send-email'; + +export default [sendEmail]; diff --git a/packages/backend/src/apps/smtp/actions/send-email/index.ts b/packages/backend/src/apps/smtp/actions/send-email/index.ts index c46e8c3c..3bc4db27 100644 --- a/packages/backend/src/apps/smtp/actions/send-email/index.ts +++ b/packages/backend/src/apps/smtp/actions/send-email/index.ts @@ -18,7 +18,7 @@ export default defineAction({ { label: 'From name', key: 'fromName', - type: 'string', + type: 'string' as const, required: false, description: 'Display name of the sender.', variables: true, @@ -26,7 +26,7 @@ export default defineAction({ { label: 'From email', key: 'fromEmail', - type: 'string', + type: 'string' as const, required: true, description: 'Email address of the sender.', variables: true, @@ -34,7 +34,7 @@ export default defineAction({ { label: 'Reply to', key: 'replyTo', - type: 'string', + type: 'string' as const, required: false, description: 'Email address to reply to. Defaults to the from email address.', @@ -43,7 +43,7 @@ export default defineAction({ { label: 'To', key: 'to', - type: 'string', + type: 'string' as const, required: true, description: 'Comma seperated list of email addresses to send the email to.', @@ -52,7 +52,7 @@ export default defineAction({ { label: 'Cc', key: 'cc', - type: 'string', + type: 'string' as const, required: false, description: 'Comma seperated list of email addresses.', variables: true, @@ -60,7 +60,7 @@ export default defineAction({ { label: 'Bcc', key: 'bcc', - type: 'string', + type: 'string' as const, required: false, description: 'Comma seperated list of email addresses.', variables: true, @@ -68,7 +68,7 @@ export default defineAction({ { label: 'Subject', key: 'subject', - type: 'string', + type: 'string' as const, required: true, description: 'Subject of the email.', variables: true, @@ -76,7 +76,7 @@ export default defineAction({ { label: 'Body', key: 'body', - type: 'string', + type: 'string' as const, required: true, description: 'Body of the email.', variables: true, diff --git a/packages/backend/src/apps/smtp/auth/index.ts b/packages/backend/src/apps/smtp/auth/index.ts index 7e687f5c..fa41d608 100644 --- a/packages/backend/src/apps/smtp/auth/index.ts +++ b/packages/backend/src/apps/smtp/auth/index.ts @@ -6,7 +6,7 @@ export default { { key: 'host', label: 'Host', - type: 'string', + type: 'string' as const, required: true, readOnly: false, value: null, @@ -18,7 +18,7 @@ export default { { key: 'username', label: 'Email/Username', - type: 'string', + type: 'string' as const, required: true, readOnly: false, value: null, @@ -30,7 +30,7 @@ export default { { key: 'password', label: 'Password', - type: 'string', + type: 'string' as const, required: true, readOnly: false, value: null, @@ -42,7 +42,7 @@ export default { { key: 'useTls', label: 'Use TLS?', - type: 'dropdown', + type: 'dropdown' as const, required: false, readOnly: false, value: false, @@ -64,10 +64,10 @@ export default { { key: 'port', label: 'Port', - type: 'string', + type: 'string' as const, required: false, readOnly: false, - value: 25, + value: '25', placeholder: null, description: null, docUrl: 'https://automatisch.io/docs/smtp#port', @@ -76,7 +76,7 @@ export default { { key: 'fromEmail', label: 'From Email', - type: 'string', + type: 'string' as const, required: false, readOnly: false, value: null, @@ -89,7 +89,7 @@ export default { authenticationSteps: [ { step: 1, - type: 'mutation', + type: 'mutation' as const, name: 'createConnection', arguments: [ { @@ -130,7 +130,7 @@ export default { }, { step: 2, - type: 'mutation', + type: 'mutation' as const, name: 'verifyConnection', arguments: [ { @@ -143,7 +143,7 @@ export default { reconnectionSteps: [ { step: 1, - type: 'mutation', + type: 'mutation' as const, name: 'resetConnection', arguments: [ { @@ -154,7 +154,7 @@ export default { }, { step: 2, - type: 'mutation', + type: 'mutation' as const, name: 'updateConnection', arguments: [ { @@ -195,7 +195,7 @@ export default { }, { step: 3, - type: 'mutation', + type: 'mutation' as const, name: 'verifyConnection', arguments: [ { diff --git a/packages/backend/src/apps/smtp/index.ts b/packages/backend/src/apps/smtp/index.ts index 9a0a7f94..0f72a20c 100644 --- a/packages/backend/src/apps/smtp/index.ts +++ b/packages/backend/src/apps/smtp/index.ts @@ -1,4 +1,6 @@ import defineApp from '../../helpers/define-app'; +import auth from './auth'; +import actions from './actions'; export default defineApp({ name: 'SMTP', @@ -10,4 +12,6 @@ export default defineApp({ apiBaseUrl: '', primaryColor: '2DAAE1', beforeRequest: [], + auth, + actions, }); diff --git a/packages/backend/src/apps/twilio/actions/index.ts b/packages/backend/src/apps/twilio/actions/index.ts new file mode 100644 index 00000000..d1723dc2 --- /dev/null +++ b/packages/backend/src/apps/twilio/actions/index.ts @@ -0,0 +1,3 @@ +import sendSms from './send-sms'; + +export default [sendSms]; diff --git a/packages/backend/src/apps/twilio/actions/send-sms/index.ts b/packages/backend/src/apps/twilio/actions/send-sms/index.ts index 6fcb55a7..319d6606 100644 --- a/packages/backend/src/apps/twilio/actions/send-sms/index.ts +++ b/packages/backend/src/apps/twilio/actions/send-sms/index.ts @@ -16,7 +16,7 @@ export default defineAction({ { label: 'From Number', key: 'fromNumber', - type: 'string', + type: 'string' as const, required: true, description: 'The number to send the SMS from. Include country code. Example: 15551234567', @@ -25,7 +25,7 @@ export default defineAction({ { label: 'To Number', key: 'toNumber', - type: 'string', + type: 'string' as const, required: true, description: 'The number to send the SMS to. Include country code. Example: 15551234567', @@ -34,7 +34,7 @@ export default defineAction({ { label: 'Message', key: 'message', - type: 'string', + type: 'string' as const, required: true, description: 'The message to send.', variables: true, diff --git a/packages/backend/src/apps/twilio/auth/index.ts b/packages/backend/src/apps/twilio/auth/index.ts index 8c35364b..8df9da7c 100644 --- a/packages/backend/src/apps/twilio/auth/index.ts +++ b/packages/backend/src/apps/twilio/auth/index.ts @@ -6,7 +6,7 @@ export default { { key: 'accountSid', label: 'Account SID', - type: 'string', + type: 'string' as const, required: true, readOnly: false, value: null, @@ -18,7 +18,7 @@ export default { { key: 'authToken', label: 'Auth Token', - type: 'string', + type: 'string' as const, required: true, readOnly: false, value: null, @@ -30,7 +30,7 @@ export default { authenticationSteps: [ { step: 1, - type: 'mutation', + type: 'mutation' as const, name: 'createConnection', arguments: [ { @@ -55,7 +55,7 @@ export default { }, { step: 2, - type: 'mutation', + type: 'mutation' as const, name: 'verifyConnection', arguments: [ { @@ -68,7 +68,7 @@ export default { reconnectionSteps: [ { step: 1, - type: 'mutation', + type: 'mutation' as const, name: 'resetConnection', arguments: [ { @@ -79,7 +79,7 @@ export default { }, { step: 2, - type: 'mutation', + type: 'mutation' as const, name: 'updateConnection', arguments: [ { @@ -104,7 +104,7 @@ export default { }, { step: 3, - type: 'mutation', + type: 'mutation' as const, name: 'verifyConnection', arguments: [ { diff --git a/packages/backend/src/apps/twilio/index.ts b/packages/backend/src/apps/twilio/index.ts index 46c3f248..a15c38b1 100644 --- a/packages/backend/src/apps/twilio/index.ts +++ b/packages/backend/src/apps/twilio/index.ts @@ -1,5 +1,7 @@ import defineApp from '../../helpers/define-app'; import addAuthHeader from './common/add-auth-header'; +import auth from './auth'; +import actions from './actions'; export default defineApp({ name: 'Twilio', @@ -11,4 +13,6 @@ export default defineApp({ apiBaseUrl: 'https://api.twilio.com', primaryColor: 'e1000f', beforeRequest: [addAuthHeader], + auth, + actions, }); diff --git a/packages/backend/src/apps/twitter/actions/create-tweet/index.ts b/packages/backend/src/apps/twitter/actions/create-tweet/index.ts index 649f1b98..aecef502 100644 --- a/packages/backend/src/apps/twitter/actions/create-tweet/index.ts +++ b/packages/backend/src/apps/twitter/actions/create-tweet/index.ts @@ -1,4 +1,3 @@ -import { IActionOutput } from '@automatisch/types'; import defineAction from '../../../../helpers/define-action'; export default defineAction({ @@ -17,7 +16,7 @@ export default defineAction({ { label: 'Tweet body', key: 'tweet', - type: 'string', + type: 'string' as const, required: true, description: 'The content of your new tweet.', variables: true, diff --git a/packages/backend/src/apps/twitter/actions/index.ts b/packages/backend/src/apps/twitter/actions/index.ts new file mode 100644 index 00000000..619c7f8b --- /dev/null +++ b/packages/backend/src/apps/twitter/actions/index.ts @@ -0,0 +1,3 @@ +import createTweet from './create-tweet'; + +export default [createTweet]; diff --git a/packages/backend/src/apps/twitter/auth/index.ts b/packages/backend/src/apps/twitter/auth/index.ts index a5690b2f..98d04eee 100644 --- a/packages/backend/src/apps/twitter/auth/index.ts +++ b/packages/backend/src/apps/twitter/auth/index.ts @@ -7,7 +7,7 @@ export default { { key: 'oAuthRedirectUrl', label: 'OAuth Redirect URL', - type: 'string', + type: 'string' as const, required: true, readOnly: true, value: '{WEB_APP_URL}/app/twitter/connections/add', @@ -19,7 +19,7 @@ export default { { key: 'consumerKey', label: 'API Key', - type: 'string', + type: 'string' as const, required: true, readOnly: false, value: null, @@ -30,7 +30,7 @@ export default { { key: 'consumerSecret', label: 'API Secret', - type: 'string', + type: 'string' as const, required: true, readOnly: false, value: null, @@ -42,7 +42,7 @@ export default { authenticationSteps: [ { step: 1, - type: 'mutation', + type: 'mutation' as const, name: 'createConnection', arguments: [ { @@ -67,7 +67,7 @@ export default { }, { step: 2, - type: 'mutation', + type: 'mutation' as const, name: 'createAuthData', arguments: [ { @@ -78,7 +78,7 @@ export default { }, { step: 3, - type: 'openWithPopup', + type: 'openWithPopup' as const, name: 'openAuthPopup', arguments: [ { @@ -89,7 +89,7 @@ export default { }, { step: 4, - type: 'mutation', + type: 'mutation' as const, name: 'updateConnection', arguments: [ { @@ -110,7 +110,7 @@ export default { }, { step: 5, - type: 'mutation', + type: 'mutation' as const, name: 'verifyConnection', arguments: [ { @@ -123,7 +123,7 @@ export default { reconnectionSteps: [ { step: 1, - type: 'mutation', + type: 'mutation' as const, name: 'resetConnection', arguments: [ { @@ -134,7 +134,7 @@ export default { }, { step: 2, - type: 'mutation', + type: 'mutation' as const, name: 'updateConnection', arguments: [ { @@ -159,7 +159,7 @@ export default { }, { step: 3, - type: 'mutation', + type: 'mutation' as const, name: 'createAuthData', arguments: [ { @@ -170,7 +170,7 @@ export default { }, { step: 4, - type: 'openWithPopup', + type: 'openWithPopup' as const, name: 'openAuthPopup', arguments: [ { @@ -181,7 +181,7 @@ export default { }, { step: 5, - type: 'mutation', + type: 'mutation' as const, name: 'updateConnection', arguments: [ { @@ -202,7 +202,7 @@ export default { }, { step: 6, - type: 'mutation', + type: 'mutation' as const, name: 'verifyConnection', arguments: [ { diff --git a/packages/backend/src/apps/twitter/index.ts b/packages/backend/src/apps/twitter/index.ts index f2c39a8e..5b1376b1 100644 --- a/packages/backend/src/apps/twitter/index.ts +++ b/packages/backend/src/apps/twitter/index.ts @@ -1,5 +1,8 @@ import defineApp from '../../helpers/define-app'; import addAuthHeader from './common/add-auth-header'; +import auth from './auth'; +import actions from './actions'; +import triggers from './triggers'; export default defineApp({ name: 'Twitter', @@ -11,4 +14,7 @@ export default defineApp({ apiBaseUrl: 'https://api.twitter.com', primaryColor: '1da1f2', beforeRequest: [addAuthHeader], + auth, + triggers, + actions, }); diff --git a/packages/backend/src/apps/twitter/triggers/index.ts b/packages/backend/src/apps/twitter/triggers/index.ts new file mode 100644 index 00000000..0619545f --- /dev/null +++ b/packages/backend/src/apps/twitter/triggers/index.ts @@ -0,0 +1,11 @@ +import myTweets from './my-tweets'; +import newFollowerOfMe from './new-follower-of-me'; +import searchTweets from './search-tweets'; +import userTweets from './user-tweets'; + +export default [ + myTweets, + newFollowerOfMe, + searchTweets, + userTweets, +]; diff --git a/packages/backend/src/apps/twitter/triggers/search-tweets/index.ts b/packages/backend/src/apps/twitter/triggers/search-tweets/index.ts index d97e565d..062ddc84 100644 --- a/packages/backend/src/apps/twitter/triggers/search-tweets/index.ts +++ b/packages/backend/src/apps/twitter/triggers/search-tweets/index.ts @@ -19,7 +19,7 @@ export default defineTrigger({ { label: 'Search Term', key: 'searchTerm', - type: 'string', + type: 'string' as const, required: true, }, ], diff --git a/packages/backend/src/apps/twitter/triggers/user-tweets/index.ts b/packages/backend/src/apps/twitter/triggers/user-tweets/index.ts index 4e07959b..92ed126c 100644 --- a/packages/backend/src/apps/twitter/triggers/user-tweets/index.ts +++ b/packages/backend/src/apps/twitter/triggers/user-tweets/index.ts @@ -18,7 +18,7 @@ export default defineTrigger({ { label: 'Username', key: 'username', - type: 'string', + type: 'string' as const, required: true, }, ], diff --git a/packages/backend/src/helpers/get-app.ts b/packages/backend/src/helpers/get-app.ts index b3e9f5d4..d9495661 100644 --- a/packages/backend/src/helpers/get-app.ts +++ b/packages/backend/src/helpers/get-app.ts @@ -1,8 +1,4 @@ -import fs from 'fs'; -import { join } from 'path'; -import { IApp, IAuth, IAction, ITrigger, IData } from '@automatisch/types'; - -const appsPath = join(__dirname, '../apps'); +import { IApp } from '@automatisch/types'; async function getDefaultExport(path: string) { return (await import(path)).default; @@ -12,63 +8,12 @@ function stripFunctions(data: C): C { return JSON.parse(JSON.stringify(data)); } -async function getFileContent( - path: string, - stripFuncs: boolean -): Promise { - const fileContent = await getDefaultExport(path); - - if (stripFuncs) { - return stripFunctions(fileContent); - } - - return fileContent; -} - -async function getChildrenContentInDirectory( - path: string, - stripFuncs: boolean -): Promise { - const appSubdirectory = join(appsPath, path); - const childrenContent = []; - - if (fs.existsSync(appSubdirectory)) { - const filesInSubdirectory = fs.readdirSync(appSubdirectory); - - for (const filename of filesInSubdirectory) { - const filePath = join(appSubdirectory, filename); - const fileContent = await getFileContent(filePath, stripFuncs); - - childrenContent.push(fileContent); - } - - return childrenContent; - } - - return []; -} - const getApp = async (appKey: string, stripFuncs = true) => { const appData: IApp = await getDefaultExport(`../apps/${appKey}`); - if (appData.supportsConnections) { - appData.auth = await getFileContent( - `../apps/${appKey}/auth`, - stripFuncs - ); + if (stripFuncs) { + return stripFunctions(appData); } - appData.triggers = await getChildrenContentInDirectory( - `${appKey}/triggers`, - stripFuncs - ); - appData.actions = await getChildrenContentInDirectory( - `${appKey}/actions`, - stripFuncs - ); - appData.data = await getChildrenContentInDirectory( - `${appKey}/data`, - stripFuncs - ); return appData; }; diff --git a/packages/types/index.d.ts b/packages/types/index.d.ts index 16736dfa..49b1b385 100644 --- a/packages/types/index.d.ts +++ b/packages/types/index.d.ts @@ -136,7 +136,7 @@ export type IField = IFieldDropdown | IFieldText; export interface IAuthenticationStepField { name: string; value: string | null; - properties: { + properties?: { name: string; value: string; }[]; @@ -178,7 +178,7 @@ export interface IData { } export interface IAuth { - createAuthData($: IGlobalVariable): Promise; + createAuthData?($: IGlobalVariable): Promise; verifyCredentials($: IGlobalVariable): Promise; isStillVerified($: IGlobalVariable): Promise; fields: IField[];