feat: Convert all app files to JS
This commit is contained in:
@@ -1,23 +1,25 @@
|
||||
import path from 'node:path';
|
||||
import defineAction from '../../../../helpers/define-action';
|
||||
import defineAction from '../../../../helpers/define-action.js';
|
||||
|
||||
export default defineAction({
|
||||
name: 'Create folder',
|
||||
key: 'createFolder',
|
||||
description: 'Create a new folder with the given parent folder and folder name',
|
||||
description:
|
||||
'Create a new folder with the given parent folder and folder name',
|
||||
arguments: [
|
||||
{
|
||||
label: 'Folder',
|
||||
key: 'parentFolder',
|
||||
type: 'string' as const,
|
||||
type: 'string',
|
||||
required: true,
|
||||
description: 'Enter the parent folder path, like /TextFiles/ or /Documents/Taxes/',
|
||||
description:
|
||||
'Enter the parent folder path, like /TextFiles/ or /Documents/Taxes/',
|
||||
variables: true,
|
||||
},
|
||||
{
|
||||
label: 'Folder Name',
|
||||
key: 'folderName',
|
||||
type: 'string' as const,
|
||||
type: 'string',
|
||||
required: true,
|
||||
description: 'Enter the name for the new folder',
|
||||
variables: true,
|
||||
@@ -25,11 +27,13 @@ export default defineAction({
|
||||
],
|
||||
|
||||
async run($) {
|
||||
const parentFolder = $.step.parameters.parentFolder as string;
|
||||
const folderName = $.step.parameters.folderName as string;
|
||||
const parentFolder = $.step.parameters.parentFolder;
|
||||
const folderName = $.step.parameters.folderName;
|
||||
const folderPath = path.join(parentFolder, folderName);
|
||||
|
||||
const response = await $.http.post('/2/files/create_folder_v2', { path: folderPath });
|
||||
const response = await $.http.post('/2/files/create_folder_v2', {
|
||||
path: folderPath,
|
||||
});
|
||||
|
||||
$.setActionItem({ raw: response.data });
|
||||
},
|
4
packages/backend/src/apps/dropbox/actions/index.js
Normal file
4
packages/backend/src/apps/dropbox/actions/index.js
Normal file
@@ -0,0 +1,4 @@
|
||||
import createFolder from './create-folder/index.js';
|
||||
import renameFile from './rename-file/index.js';
|
||||
|
||||
export default [createFolder, renameFile];
|
@@ -1,4 +0,0 @@
|
||||
import createFolder from "./create-folder";
|
||||
import renameFile from "./rename-file";
|
||||
|
||||
export default [createFolder, renameFile];
|
@@ -1,5 +1,5 @@
|
||||
import path from 'node:path';
|
||||
import defineAction from '../../../../helpers/define-action';
|
||||
import defineAction from '../../../../helpers/define-action.js';
|
||||
|
||||
export default defineAction({
|
||||
name: 'Rename file',
|
||||
@@ -9,25 +9,25 @@ export default defineAction({
|
||||
{
|
||||
label: 'File Path',
|
||||
key: 'filePath',
|
||||
type: 'string' as const,
|
||||
type: 'string',
|
||||
required: true,
|
||||
description:
|
||||
'Write the full path to the file such as /Folder1/File.pdf',
|
||||
description: 'Write the full path to the file such as /Folder1/File.pdf',
|
||||
variables: true,
|
||||
},
|
||||
{
|
||||
label: 'New Name',
|
||||
key: 'newName',
|
||||
type: 'string' as const,
|
||||
type: 'string',
|
||||
required: true,
|
||||
description: "Enter the new name for the file (without the extension, e.g., '.pdf')",
|
||||
description:
|
||||
"Enter the new name for the file (without the extension, e.g., '.pdf')",
|
||||
variables: true,
|
||||
},
|
||||
],
|
||||
|
||||
async run($) {
|
||||
const filePath = $.step.parameters.filePath as string;
|
||||
const newName = $.step.parameters.newName as string;
|
||||
const filePath = $.step.parameters.filePath;
|
||||
const newName = $.step.parameters.newName;
|
||||
const fileObject = path.parse(filePath);
|
||||
const newPath = path.format({
|
||||
dir: fileObject.dir,
|
@@ -1,15 +1,15 @@
|
||||
import { URLSearchParams } from 'url';
|
||||
import { IField, IGlobalVariable } from '@automatisch/types';
|
||||
import scopes from '../common/scopes';
|
||||
import scopes from '../common/scopes.js';
|
||||
|
||||
export default async function generateAuthUrl($: IGlobalVariable) {
|
||||
export default async function generateAuthUrl($) {
|
||||
const oauthRedirectUrlField = $.app.auth.fields.find(
|
||||
(field: IField) => field.key == 'oAuthRedirectUrl'
|
||||
(field) => field.key == 'oAuthRedirectUrl'
|
||||
);
|
||||
const callbackUrl = oauthRedirectUrlField.value as string;
|
||||
|
||||
const callbackUrl = oauthRedirectUrlField.value;
|
||||
|
||||
const searchParams = new URLSearchParams({
|
||||
client_id: $.auth.data.clientId as string,
|
||||
client_id: $.auth.data.clientId,
|
||||
redirect_uri: callbackUrl,
|
||||
response_type: 'code',
|
||||
scope: scopes.join(' '),
|
@@ -1,14 +1,14 @@
|
||||
import generateAuthUrl from './generate-auth-url';
|
||||
import verifyCredentials from './verify-credentials';
|
||||
import isStillVerified from './is-still-verified';
|
||||
import refreshToken from './refresh-token';
|
||||
import generateAuthUrl from './generate-auth-url.js';
|
||||
import verifyCredentials from './verify-credentials.js';
|
||||
import isStillVerified from './is-still-verified.js';
|
||||
import refreshToken from './refresh-token.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/dropbox/connections/add',
|
||||
@@ -20,7 +20,7 @@ export default {
|
||||
{
|
||||
key: 'clientId',
|
||||
label: 'App Key',
|
||||
type: 'string' as const,
|
||||
type: 'string',
|
||||
required: true,
|
||||
readOnly: false,
|
||||
value: null,
|
||||
@@ -31,7 +31,7 @@ export default {
|
||||
{
|
||||
key: 'clientSecret',
|
||||
label: 'App Secret',
|
||||
type: 'string' as const,
|
||||
type: 'string',
|
||||
required: true,
|
||||
readOnly: false,
|
||||
value: null,
|
@@ -0,0 +1,8 @@
|
||||
import getCurrentAccount from '../common/get-current-account.js';
|
||||
|
||||
const isStillVerified = async ($) => {
|
||||
const account = await getCurrentAccount($);
|
||||
return !!account;
|
||||
};
|
||||
|
||||
export default isStillVerified;
|
@@ -1,9 +0,0 @@
|
||||
import { IGlobalVariable } from '@automatisch/types';
|
||||
import getCurrentAccount from '../common/get-current-account';
|
||||
|
||||
const isStillVerified = async ($: IGlobalVariable) => {
|
||||
const account = await getCurrentAccount($);
|
||||
return !!account;
|
||||
};
|
||||
|
||||
export default isStillVerified;
|
36
packages/backend/src/apps/dropbox/auth/refresh-token.js
Normal file
36
packages/backend/src/apps/dropbox/auth/refresh-token.js
Normal file
@@ -0,0 +1,36 @@
|
||||
import { Buffer } from 'node:buffer';
|
||||
|
||||
const refreshToken = async ($) => {
|
||||
const params = {
|
||||
grant_type: 'refresh_token',
|
||||
refresh_token: $.auth.data.refreshToken,
|
||||
};
|
||||
|
||||
const basicAuthToken = Buffer.from(
|
||||
`${$.auth.data.clientId}:${$.auth.data.clientSecret}`
|
||||
).toString('base64');
|
||||
|
||||
const { data } = await $.http.post('oauth2/token', null, {
|
||||
params,
|
||||
headers: {
|
||||
Authorization: `Basic ${basicAuthToken}`,
|
||||
},
|
||||
additionalProperties: {
|
||||
skipAddingAuthHeader: true,
|
||||
},
|
||||
});
|
||||
|
||||
const {
|
||||
access_token: accessToken,
|
||||
expires_in: expiresIn,
|
||||
token_type: tokenType,
|
||||
} = data;
|
||||
|
||||
await $.auth.set({
|
||||
accessToken,
|
||||
expiresIn,
|
||||
tokenType,
|
||||
});
|
||||
};
|
||||
|
||||
export default refreshToken;
|
@@ -1,41 +0,0 @@
|
||||
import { Buffer } from 'node:buffer';
|
||||
import { IGlobalVariable } from '@automatisch/types';
|
||||
|
||||
const refreshToken = async ($: IGlobalVariable) => {
|
||||
const params = {
|
||||
grant_type: 'refresh_token',
|
||||
refresh_token: $.auth.data.refreshToken as string,
|
||||
};
|
||||
|
||||
const basicAuthToken = Buffer
|
||||
.from(`${$.auth.data.clientId}:${$.auth.data.clientSecret}`)
|
||||
.toString('base64');
|
||||
|
||||
const { data } = await $.http.post(
|
||||
'oauth2/token',
|
||||
null,
|
||||
{
|
||||
params,
|
||||
headers: {
|
||||
Authorization: `Basic ${basicAuthToken}`
|
||||
},
|
||||
additionalProperties: {
|
||||
skipAddingAuthHeader: true
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
const {
|
||||
access_token: accessToken,
|
||||
expires_in: expiresIn,
|
||||
token_type: tokenType,
|
||||
} = data;
|
||||
|
||||
await $.auth.set({
|
||||
accessToken,
|
||||
expiresIn,
|
||||
tokenType,
|
||||
});
|
||||
};
|
||||
|
||||
export default refreshToken;
|
@@ -1,44 +1,20 @@
|
||||
import { IGlobalVariable, IField } from '@automatisch/types';
|
||||
import getCurrentAccount from '../common/get-current-account';
|
||||
import getCurrentAccount from '../common/get-current-account.js';
|
||||
|
||||
type TAccount = {
|
||||
account_id: string,
|
||||
name: {
|
||||
given_name: string,
|
||||
surname: string,
|
||||
familiar_name: string,
|
||||
display_name: string,
|
||||
abbreviated_name: string,
|
||||
},
|
||||
email: string,
|
||||
email_verified: boolean,
|
||||
disabled: boolean,
|
||||
country: string,
|
||||
locale: string,
|
||||
referral_link: string,
|
||||
is_paired: boolean,
|
||||
account_type: {
|
||||
".tag": string,
|
||||
},
|
||||
root_info: {
|
||||
".tag": string,
|
||||
root_namespace_id: string,
|
||||
home_namespace_id: string,
|
||||
},
|
||||
}
|
||||
|
||||
const verifyCredentials = async ($: IGlobalVariable) => {
|
||||
const verifyCredentials = async ($) => {
|
||||
const oauthRedirectUrlField = $.app.auth.fields.find(
|
||||
(field: IField) => field.key == 'oAuthRedirectUrl'
|
||||
(field) => field.key == 'oAuthRedirectUrl'
|
||||
);
|
||||
const redirectUrl = oauthRedirectUrlField.value as string;
|
||||
|
||||
const redirectUrl = oauthRedirectUrlField.value;
|
||||
|
||||
const params = {
|
||||
client_id: $.auth.data.clientId as string,
|
||||
client_id: $.auth.data.clientId,
|
||||
redirect_uri: redirectUrl,
|
||||
client_secret: $.auth.data.clientSecret as string,
|
||||
code: $.auth.data.code as string,
|
||||
client_secret: $.auth.data.clientSecret,
|
||||
code: $.auth.data.code,
|
||||
grant_type: 'authorization_code',
|
||||
}
|
||||
};
|
||||
|
||||
const { data: verifiedCredentials } = await $.http.post(
|
||||
'/oauth2/token',
|
||||
null,
|
||||
@@ -66,10 +42,10 @@ const verifyCredentials = async ($: IGlobalVariable) => {
|
||||
accountId,
|
||||
teamId,
|
||||
idToken,
|
||||
uid
|
||||
uid,
|
||||
});
|
||||
|
||||
const account = await getCurrentAccount($) as TAccount;
|
||||
const account = await getCurrentAccount($);
|
||||
|
||||
await $.auth.set({
|
||||
accountId: account.account_id,
|
||||
@@ -88,10 +64,10 @@ const verifyCredentials = async ($: IGlobalVariable) => {
|
||||
referralLink: account.referral_link,
|
||||
isPaired: account.is_paired,
|
||||
accountType: {
|
||||
".tag": account.account_type['.tag'],
|
||||
'.tag': account.account_type['.tag'],
|
||||
},
|
||||
rootInfo: {
|
||||
".tag": account.root_info['.tag'],
|
||||
'.tag': account.root_info['.tag'],
|
||||
rootNamespaceId: account.root_info.root_namespace_id,
|
||||
homeNamespaceId: account.root_info.home_namespace_id,
|
||||
},
|
14
packages/backend/src/apps/dropbox/common/add-auth-header.js
Normal file
14
packages/backend/src/apps/dropbox/common/add-auth-header.js
Normal file
@@ -0,0 +1,14 @@
|
||||
const addAuthHeader = ($, requestConfig) => {
|
||||
requestConfig.headers['Content-Type'] = 'application/json';
|
||||
|
||||
if (
|
||||
!requestConfig.additionalProperties?.skipAddingAuthHeader &&
|
||||
$.auth.data?.accessToken
|
||||
) {
|
||||
requestConfig.headers.Authorization = `Bearer ${$.auth.data.accessToken}`;
|
||||
}
|
||||
|
||||
return requestConfig;
|
||||
};
|
||||
|
||||
export default addAuthHeader;
|
@@ -1,13 +0,0 @@
|
||||
import { TBeforeRequest } from '@automatisch/types';
|
||||
|
||||
const addAuthHeader: TBeforeRequest = ($, requestConfig) => {
|
||||
requestConfig.headers['Content-Type'] = 'application/json';
|
||||
|
||||
if (!requestConfig.additionalProperties?.skipAddingAuthHeader && $.auth.data?.accessToken) {
|
||||
requestConfig.headers.Authorization = `Bearer ${$.auth.data.accessToken}`;
|
||||
}
|
||||
|
||||
return requestConfig;
|
||||
};
|
||||
|
||||
export default addAuthHeader;
|
@@ -0,0 +1,6 @@
|
||||
const getCurrentAccount = async ($) => {
|
||||
const response = await $.http.post('/2/users/get_current_account', null);
|
||||
return response.data;
|
||||
};
|
||||
|
||||
export default getCurrentAccount;
|
@@ -1,8 +0,0 @@
|
||||
import { IGlobalVariable, IJSONObject } from '@automatisch/types';
|
||||
|
||||
const getCurrentAccount = async ($: IGlobalVariable): Promise<IJSONObject> => {
|
||||
const response = await $.http.post('/2/users/get_current_account', null);
|
||||
return response.data;
|
||||
};
|
||||
|
||||
export default getCurrentAccount;
|
@@ -1,7 +1,7 @@
|
||||
import defineApp from '../../helpers/define-app';
|
||||
import addAuthHeader from './common/add-auth-header';
|
||||
import auth from './auth';
|
||||
import actions from './actions';
|
||||
import defineApp from '../../helpers/define-app.js';
|
||||
import addAuthHeader from './common/add-auth-header.js';
|
||||
import auth from './auth/index.js';
|
||||
import actions from './actions/index.js';
|
||||
|
||||
export default defineApp({
|
||||
name: 'Dropbox',
|
Reference in New Issue
Block a user