feat: Convert all app files to JS
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import defineAction from '../../../../helpers/define-action';
|
||||
import defineAction from '../../../../helpers/define-action.js';
|
||||
|
||||
export default defineAction({
|
||||
name: 'Create task',
|
||||
@@ -8,7 +8,7 @@ export default defineAction({
|
||||
{
|
||||
label: 'Project ID',
|
||||
key: 'projectId',
|
||||
type: 'dropdown' as const,
|
||||
type: 'dropdown',
|
||||
required: false,
|
||||
variables: true,
|
||||
source: {
|
||||
@@ -25,7 +25,7 @@ export default defineAction({
|
||||
{
|
||||
label: 'Section ID',
|
||||
key: 'sectionId',
|
||||
type: 'dropdown' as const,
|
||||
type: 'dropdown',
|
||||
required: false,
|
||||
variables: true,
|
||||
dependsOn: ['parameters.projectId'],
|
||||
@@ -47,7 +47,7 @@ export default defineAction({
|
||||
{
|
||||
label: 'Labels',
|
||||
key: 'labels',
|
||||
type: 'string' as const,
|
||||
type: 'string',
|
||||
required: false,
|
||||
variables: true,
|
||||
description:
|
||||
@@ -56,7 +56,7 @@ export default defineAction({
|
||||
{
|
||||
label: 'Content',
|
||||
key: 'content',
|
||||
type: 'string' as const,
|
||||
type: 'string',
|
||||
required: true,
|
||||
variables: true,
|
||||
description: 'Task content, may be markdown. Example: "Foo"',
|
||||
@@ -64,7 +64,7 @@ export default defineAction({
|
||||
{
|
||||
label: 'Description',
|
||||
key: 'description',
|
||||
type: 'string' as const,
|
||||
type: 'string',
|
||||
required: false,
|
||||
variables: true,
|
||||
description: 'Task description, may be markdown. Example: "Foo"',
|
||||
@@ -76,7 +76,7 @@ export default defineAction({
|
||||
const { projectId, sectionId, labels, content, description } =
|
||||
$.step.parameters;
|
||||
|
||||
const labelsArray = (labels as string).split(',');
|
||||
const labelsArray = labels.split(',');
|
||||
|
||||
const payload = {
|
||||
content,
|
3
packages/backend/src/apps/todoist/actions/index.js
Normal file
3
packages/backend/src/apps/todoist/actions/index.js
Normal file
@@ -0,0 +1,3 @@
|
||||
import createTask from './create-task/index.js';
|
||||
|
||||
export default [createTask];
|
@@ -1,3 +0,0 @@
|
||||
import createTask from './create-task';
|
||||
|
||||
export default [createTask];
|
15
packages/backend/src/apps/todoist/auth/generate-auth-url.js
Normal file
15
packages/backend/src/apps/todoist/auth/generate-auth-url.js
Normal file
@@ -0,0 +1,15 @@
|
||||
import { URLSearchParams } from 'url';
|
||||
|
||||
export default async function generateAuthUrl($) {
|
||||
const scopes = ['data:read_write'];
|
||||
const searchParams = new URLSearchParams({
|
||||
client_id: $.auth.data.clientId,
|
||||
scope: scopes.join(','),
|
||||
});
|
||||
|
||||
const url = `${$.app.baseUrl}/oauth/authorize?${searchParams.toString()}`;
|
||||
|
||||
await $.auth.set({
|
||||
url,
|
||||
});
|
||||
}
|
@@ -1,17 +0,0 @@
|
||||
import { IGlobalVariable } from '@automatisch/types';
|
||||
import { URLSearchParams } from 'url';
|
||||
|
||||
export default async function generateAuthUrl($: IGlobalVariable) {
|
||||
const scopes = ['data:read_write'];
|
||||
const searchParams = new URLSearchParams({
|
||||
client_id: $.auth.data.clientId as string,
|
||||
scope: scopes.join(','),
|
||||
});
|
||||
|
||||
const url = `${$.app.baseUrl
|
||||
}/oauth/authorize?${searchParams.toString()}`;
|
||||
|
||||
await $.auth.set({
|
||||
url,
|
||||
});
|
||||
}
|
@@ -1,13 +1,13 @@
|
||||
import generateAuthUrl from './generate-auth-url';
|
||||
import verifyCredentials from './verify-credentials';
|
||||
import isStillVerified from './is-still-verified';
|
||||
import generateAuthUrl from './generate-auth-url.js';
|
||||
import verifyCredentials from './verify-credentials.js';
|
||||
import isStillVerified from './is-still-verified.js';
|
||||
|
||||
export default {
|
||||
fields: [
|
||||
{
|
||||
key: 'oAuthRedirectUrl',
|
||||
label: 'OAuth Redirect URL',
|
||||
type: 'string' as const,
|
||||
type: 'string',
|
||||
required: true,
|
||||
readOnly: true,
|
||||
value: '{WEB_APP_URL}/app/todoist/connections/add',
|
||||
@@ -20,7 +20,7 @@ export default {
|
||||
{
|
||||
key: 'screenName',
|
||||
label: 'Screen Name',
|
||||
type: 'string' as const,
|
||||
type: 'string',
|
||||
required: true,
|
||||
readOnly: false,
|
||||
value: null,
|
||||
@@ -31,7 +31,7 @@ export default {
|
||||
{
|
||||
key: 'clientId',
|
||||
label: 'Client ID',
|
||||
type: 'string' as const,
|
||||
type: 'string',
|
||||
required: true,
|
||||
readOnly: false,
|
||||
value: null,
|
||||
@@ -42,7 +42,7 @@ export default {
|
||||
{
|
||||
key: 'clientSecret',
|
||||
label: 'Client Secret',
|
||||
type: 'string' as const,
|
||||
type: 'string',
|
||||
required: true,
|
||||
readOnly: false,
|
||||
value: null,
|
@@ -0,0 +1,6 @@
|
||||
const isStillVerified = async ($) => {
|
||||
await $.http.get('/projects');
|
||||
return true;
|
||||
};
|
||||
|
||||
export default isStillVerified;
|
@@ -1,8 +0,0 @@
|
||||
import { IGlobalVariable } from '@automatisch/types';
|
||||
|
||||
const isStillVerified = async ($: IGlobalVariable) => {
|
||||
await $.http.get('/projects');
|
||||
return true;
|
||||
};
|
||||
|
||||
export default isStillVerified;
|
14
packages/backend/src/apps/todoist/auth/verify-credentials.js
Normal file
14
packages/backend/src/apps/todoist/auth/verify-credentials.js
Normal file
@@ -0,0 +1,14 @@
|
||||
const verifyCredentials = async ($) => {
|
||||
const { data } = await $.http.post(`${$.app.baseUrl}/oauth/access_token`, {
|
||||
client_id: $.auth.data.clientId,
|
||||
client_secret: $.auth.data.clientSecret,
|
||||
code: $.auth.data.code,
|
||||
});
|
||||
|
||||
await $.auth.set({
|
||||
tokenType: data.token_type,
|
||||
accessToken: data.access_token,
|
||||
});
|
||||
};
|
||||
|
||||
export default verifyCredentials;
|
@@ -1,19 +0,0 @@
|
||||
import { IGlobalVariable } from '@automatisch/types';
|
||||
|
||||
const verifyCredentials = async ($: IGlobalVariable) => {
|
||||
const { data } = await $.http.post(
|
||||
`${$.app.baseUrl}/oauth/access_token`,
|
||||
{
|
||||
client_id: $.auth.data.clientId,
|
||||
client_secret: $.auth.data.clientSecret,
|
||||
code: $.auth.data.code,
|
||||
},
|
||||
);
|
||||
|
||||
await $.auth.set({
|
||||
tokenType: data.token_type,
|
||||
accessToken: data.access_token,
|
||||
});
|
||||
};
|
||||
|
||||
export default verifyCredentials;
|
@@ -1,6 +1,4 @@
|
||||
import { TBeforeRequest } from '@automatisch/types';
|
||||
|
||||
const addAuthHeader: TBeforeRequest = ($, requestConfig) => {
|
||||
const addAuthHeader = ($, requestConfig) => {
|
||||
const authData = $.auth.data;
|
||||
if (authData?.accessToken && authData?.tokenType) {
|
||||
const authorizationHeader = `${authData.tokenType} ${authData.accessToken}`;
|
5
packages/backend/src/apps/todoist/dynamic-data/index.js
Normal file
5
packages/backend/src/apps/todoist/dynamic-data/index.js
Normal file
@@ -0,0 +1,5 @@
|
||||
import listProjects from './list-projects/index.js';
|
||||
import listSections from './list-sections/index.js';
|
||||
import listLabels from './list-labels/index.js';
|
||||
|
||||
export default [listProjects, listSections, listLabels];
|
@@ -1,5 +0,0 @@
|
||||
import listProjects from './list-projects';
|
||||
import listSections from './list-sections';
|
||||
import listLabels from './list-labels';
|
||||
|
||||
export default [listProjects, listSections, listLabels];
|
@@ -1,13 +1,11 @@
|
||||
import { IGlobalVariable } from '@automatisch/types';
|
||||
|
||||
export default {
|
||||
name: 'List labels',
|
||||
key: 'listLabels',
|
||||
|
||||
async run($: IGlobalVariable) {
|
||||
async run($) {
|
||||
const response = await $.http.get('/labels');
|
||||
|
||||
response.data = response.data.map((label: { name: string }) => {
|
||||
response.data = response.data.map((label) => {
|
||||
return {
|
||||
value: label.name,
|
||||
name: label.name,
|
@@ -1,13 +1,11 @@
|
||||
import { IGlobalVariable } from '@automatisch/types';
|
||||
|
||||
export default {
|
||||
name: 'List projects',
|
||||
key: 'listProjects',
|
||||
|
||||
async run($: IGlobalVariable) {
|
||||
async run($) {
|
||||
const response = await $.http.get('/projects');
|
||||
|
||||
response.data = response.data.map((project: { id: string, name: string }) => {
|
||||
response.data = response.data.map((project) => {
|
||||
return {
|
||||
value: project.id,
|
||||
name: project.name,
|
@@ -0,0 +1,21 @@
|
||||
export default {
|
||||
name: 'List sections',
|
||||
key: 'listSections',
|
||||
|
||||
async run($) {
|
||||
const params = {
|
||||
project_id: $.step.parameters.projectId,
|
||||
};
|
||||
|
||||
const response = await $.http.get('/sections', { params });
|
||||
|
||||
response.data = response.data.map((section) => {
|
||||
return {
|
||||
value: section.id,
|
||||
name: section.name,
|
||||
};
|
||||
});
|
||||
|
||||
return response;
|
||||
},
|
||||
};
|
@@ -1,23 +0,0 @@
|
||||
import { IGlobalVariable } from '@automatisch/types';
|
||||
|
||||
export default {
|
||||
name: 'List sections',
|
||||
key: 'listSections',
|
||||
|
||||
async run($: IGlobalVariable) {
|
||||
const params = {
|
||||
project_id: ($.step.parameters.projectId as string),
|
||||
};
|
||||
|
||||
const response = await $.http.get('/sections', {params});
|
||||
|
||||
response.data = response.data.map((section: { id: string, name: string }) => {
|
||||
return {
|
||||
value: section.id,
|
||||
name: section.name,
|
||||
};
|
||||
});
|
||||
|
||||
return response;
|
||||
},
|
||||
};
|
@@ -1,9 +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 dynamicData from './dynamic-data';
|
||||
import defineApp from '../../helpers/define-app.js';
|
||||
import addAuthHeader from './common/add-auth-header.js';
|
||||
import auth from './auth/index.js';
|
||||
import triggers from './triggers/index.js';
|
||||
import actions from './actions/index.js';
|
||||
import dynamicData from './dynamic-data/index.js';
|
||||
|
||||
export default defineApp({
|
||||
name: 'Todoist',
|
@@ -0,0 +1,26 @@
|
||||
const getActiveTasks = async ($) => {
|
||||
const params = {
|
||||
project_id: $.step.parameters.projectId?.trim(),
|
||||
section_id: $.step.parameters.sectionId?.trim(),
|
||||
label: $.step.parameters.label?.trim(),
|
||||
filter: $.step.parameters.filter?.trim(),
|
||||
};
|
||||
|
||||
const response = await $.http.get('/tasks', { params });
|
||||
|
||||
// todoist api doesn't offer sorting, so we inverse sort on id here
|
||||
response.data.sort((a, b) => {
|
||||
return b.id - a.id;
|
||||
});
|
||||
|
||||
for (const task of response.data) {
|
||||
$.pushTriggerItem({
|
||||
raw: task,
|
||||
meta: {
|
||||
internalId: task.id,
|
||||
},
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export default getActiveTasks;
|
@@ -1,30 +0,0 @@
|
||||
import { IGlobalVariable } from '@automatisch/types';
|
||||
|
||||
const getActiveTasks = async ($: IGlobalVariable) => {
|
||||
|
||||
const params = {
|
||||
project_id: ($.step.parameters.projectId as string)?.trim(),
|
||||
section_id: ($.step.parameters.sectionId as string)?.trim(),
|
||||
label: ($.step.parameters.label as string)?.trim(),
|
||||
filter: ($.step.parameters.filter as string)?.trim(),
|
||||
};
|
||||
|
||||
const response = await $.http.get('/tasks', { params });
|
||||
|
||||
// todoist api doesn't offer sorting, so we inverse sort on id here
|
||||
response.data.sort((a: { id: number; }, b: { id: number; }) => {
|
||||
return b.id - a.id;
|
||||
})
|
||||
|
||||
for (const task of response.data) {
|
||||
$.pushTriggerItem({
|
||||
raw: task,
|
||||
meta:{
|
||||
internalId: task.id as string,
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
export default getActiveTasks;
|
@@ -1,5 +1,5 @@
|
||||
import defineTrigger from '../../../../helpers/define-trigger';
|
||||
import getActiveTasks from './get-tasks';
|
||||
import defineTrigger from '../../../../helpers/define-trigger.js';
|
||||
import getActiveTasks from './get-tasks.js';
|
||||
|
||||
export default defineTrigger({
|
||||
name: 'Get active tasks',
|
||||
@@ -10,7 +10,7 @@ export default defineTrigger({
|
||||
{
|
||||
label: 'Project ID',
|
||||
key: 'projectId',
|
||||
type: 'dropdown' as const,
|
||||
type: 'dropdown',
|
||||
required: false,
|
||||
variables: false,
|
||||
source: {
|
||||
@@ -27,7 +27,7 @@ export default defineTrigger({
|
||||
{
|
||||
label: 'Section ID',
|
||||
key: 'sectionId',
|
||||
type: 'dropdown' as const,
|
||||
type: 'dropdown',
|
||||
required: false,
|
||||
variables: false,
|
||||
dependsOn: ['parameters.projectId'],
|
||||
@@ -49,7 +49,7 @@ export default defineTrigger({
|
||||
{
|
||||
label: 'Label',
|
||||
key: 'label',
|
||||
type: 'dropdown' as const,
|
||||
type: 'dropdown',
|
||||
required: false,
|
||||
variables: false,
|
||||
source: {
|
||||
@@ -66,7 +66,7 @@ export default defineTrigger({
|
||||
{
|
||||
label: 'Filter',
|
||||
key: 'filter',
|
||||
type: 'string' as const,
|
||||
type: 'string',
|
||||
required: false,
|
||||
variables: false,
|
||||
description:
|
3
packages/backend/src/apps/todoist/triggers/index.js
Normal file
3
packages/backend/src/apps/todoist/triggers/index.js
Normal file
@@ -0,0 +1,3 @@
|
||||
import getTasks from './get-tasks/index.js';
|
||||
|
||||
export default [getTasks];
|
@@ -1,3 +0,0 @@
|
||||
import getTasks from './get-tasks';
|
||||
|
||||
export default [getTasks];
|
Reference in New Issue
Block a user