feat: Convert all app files to JS
This commit is contained in:
@@ -1,14 +1,13 @@
|
||||
import { IField, IGlobalVariable } from '@automatisch/types';
|
||||
import { URLSearchParams } from 'url';
|
||||
import authScope from '../common/auth-scope';
|
||||
import authScope from '../common/auth-scope.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 redirectUri = oauthRedirectUrlField.value as string;
|
||||
const redirectUri = oauthRedirectUrlField.value;
|
||||
const searchParams = new URLSearchParams({
|
||||
client_id: $.auth.data.clientId as string,
|
||||
client_id: $.auth.data.clientId,
|
||||
redirect_uri: redirectUri,
|
||||
prompt: 'select_account',
|
||||
scope: authScope.join(' '),
|
@@ -1,14 +1,14 @@
|
||||
import generateAuthUrl from './generate-auth-url';
|
||||
import verifyCredentials from './verify-credentials';
|
||||
import refreshToken from './refresh-token';
|
||||
import isStillVerified from './is-still-verified';
|
||||
import generateAuthUrl from './generate-auth-url.js';
|
||||
import verifyCredentials from './verify-credentials.js';
|
||||
import refreshToken from './refresh-token.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/google-drive/connections/add',
|
||||
@@ -20,7 +20,7 @@ export default {
|
||||
{
|
||||
key: 'clientId',
|
||||
label: 'Client ID',
|
||||
type: 'string' as const,
|
||||
type: 'string',
|
||||
required: true,
|
||||
readOnly: false,
|
||||
value: null,
|
||||
@@ -31,7 +31,7 @@ export default {
|
||||
{
|
||||
key: 'clientSecret',
|
||||
label: 'Client Secret',
|
||||
type: 'string' as const,
|
||||
type: 'string',
|
||||
required: true,
|
||||
readOnly: false,
|
||||
value: null,
|
@@ -0,0 +1,8 @@
|
||||
import getCurrentUser from '../common/get-current-user.js';
|
||||
|
||||
const isStillVerified = async ($) => {
|
||||
const currentUser = await getCurrentUser($);
|
||||
return !!currentUser.resourceName;
|
||||
};
|
||||
|
||||
export default isStillVerified;
|
@@ -1,9 +0,0 @@
|
||||
import { IGlobalVariable } from '@automatisch/types';
|
||||
import getCurrentUser from '../common/get-current-user';
|
||||
|
||||
const isStillVerified = async ($: IGlobalVariable) => {
|
||||
const currentUser = await getCurrentUser($);
|
||||
return !!currentUser.resourceName;
|
||||
};
|
||||
|
||||
export default isStillVerified;
|
@@ -1,13 +1,13 @@
|
||||
import { URLSearchParams } from 'node:url';
|
||||
import { IGlobalVariable } from '@automatisch/types';
|
||||
import authScope from '../common/auth-scope';
|
||||
|
||||
const refreshToken = async ($: IGlobalVariable) => {
|
||||
import authScope from '../common/auth-scope.js';
|
||||
|
||||
const refreshToken = async ($) => {
|
||||
const params = new URLSearchParams({
|
||||
client_id: $.auth.data.clientId as string,
|
||||
client_secret: $.auth.data.clientSecret as string,
|
||||
client_id: $.auth.data.clientId,
|
||||
client_secret: $.auth.data.clientSecret,
|
||||
grant_type: 'refresh_token',
|
||||
refresh_token: $.auth.data.refreshToken as string,
|
||||
refresh_token: $.auth.data.refreshToken,
|
||||
});
|
||||
|
||||
const { data } = await $.http.post(
|
@@ -1,25 +1,10 @@
|
||||
import { IField, IGlobalVariable } from '@automatisch/types';
|
||||
import getCurrentUser from '../common/get-current-user';
|
||||
import getCurrentUser from '../common/get-current-user.js';
|
||||
|
||||
type TUser = {
|
||||
displayName: string;
|
||||
metadata: {
|
||||
primary: boolean;
|
||||
};
|
||||
};
|
||||
|
||||
type TEmailAddress = {
|
||||
value: string;
|
||||
metadata: {
|
||||
primary: boolean;
|
||||
};
|
||||
};
|
||||
|
||||
const verifyCredentials = async ($: IGlobalVariable) => {
|
||||
const verifyCredentials = async ($) => {
|
||||
const oauthRedirectUrlField = $.app.auth.fields.find(
|
||||
(field: IField) => field.key == 'oAuthRedirectUrl'
|
||||
(field) => field.key == 'oAuthRedirectUrl'
|
||||
);
|
||||
const redirectUri = oauthRedirectUrlField.value as string;
|
||||
const redirectUri = oauthRedirectUrlField.value;
|
||||
const { data } = await $.http.post(`https://oauth2.googleapis.com/token`, {
|
||||
client_id: $.auth.data.clientId,
|
||||
client_secret: $.auth.data.clientSecret,
|
||||
@@ -36,10 +21,10 @@ const verifyCredentials = async ($: IGlobalVariable) => {
|
||||
const currentUser = await getCurrentUser($);
|
||||
|
||||
const { displayName } = currentUser.names.find(
|
||||
(name: TUser) => name.metadata.primary
|
||||
(name) => name.metadata.primary
|
||||
);
|
||||
const { value: email } = currentUser.emailAddresses.find(
|
||||
(emailAddress: TEmailAddress) => emailAddress.metadata.primary
|
||||
(emailAddress) => emailAddress.metadata.primary
|
||||
);
|
||||
|
||||
await $.auth.set({
|
@@ -1,6 +1,4 @@
|
||||
import { TBeforeRequest } from '@automatisch/types';
|
||||
|
||||
const addAuthHeader: TBeforeRequest = ($, requestConfig) => {
|
||||
const addAuthHeader = ($, requestConfig) => {
|
||||
if ($.auth.data?.accessToken) {
|
||||
requestConfig.headers.Authorization = `${$.auth.data.tokenType} ${$.auth.data.accessToken}`;
|
||||
}
|
@@ -1,4 +1,4 @@
|
||||
const authScope: string[] = [
|
||||
const authScope = [
|
||||
'https://www.googleapis.com/auth/drive',
|
||||
'https://www.googleapis.com/auth/userinfo.email',
|
||||
'https://www.googleapis.com/auth/userinfo.profile',
|
@@ -1,6 +1,4 @@
|
||||
import { IGlobalVariable } from '@automatisch/types';
|
||||
|
||||
const getCurrentUser = async ($: IGlobalVariable) => {
|
||||
const getCurrentUser = async ($) => {
|
||||
const { data: currentUser } = await $.http.get(
|
||||
'https://people.googleapis.com/v1/people/me?personFields=names,emailAddresses'
|
||||
);
|
@@ -0,0 +1,4 @@
|
||||
import listFolders from './list-folders/index.js';
|
||||
import listDrives from './list-drives/index.js';
|
||||
|
||||
export default [listFolders, listDrives];
|
@@ -1,4 +0,0 @@
|
||||
import listFolders from './list-folders';
|
||||
import listDrives from './list-drives';
|
||||
|
||||
export default [listFolders, listDrives];
|
@@ -1,19 +1,15 @@
|
||||
import { IGlobalVariable, IJSONObject } from '@automatisch/types';
|
||||
|
||||
export default {
|
||||
name: 'List drives',
|
||||
key: 'listDrives',
|
||||
|
||||
async run($: IGlobalVariable) {
|
||||
const drives: {
|
||||
data: IJSONObject[];
|
||||
} = {
|
||||
async run($) {
|
||||
const drives = {
|
||||
data: [{ value: null, name: 'My Google Drive' }],
|
||||
};
|
||||
|
||||
const params = {
|
||||
pageSize: 100,
|
||||
pageToken: undefined as unknown as string,
|
||||
pageToken: undefined,
|
||||
};
|
||||
|
||||
do {
|
@@ -1,20 +1,16 @@
|
||||
import { IGlobalVariable, IJSONObject } from '@automatisch/types';
|
||||
|
||||
export default {
|
||||
name: 'List folders',
|
||||
key: 'listFolders',
|
||||
|
||||
async run($: IGlobalVariable) {
|
||||
const folders: {
|
||||
data: IJSONObject[];
|
||||
} = {
|
||||
async run($) {
|
||||
const folders = {
|
||||
data: [],
|
||||
};
|
||||
|
||||
const params: Record<string, unknown> = {
|
||||
const params = {
|
||||
q: `mimeType='application/vnd.google-apps.folder'`,
|
||||
orderBy: 'createdTime desc',
|
||||
pageToken: undefined as unknown as string,
|
||||
pageToken: undefined,
|
||||
pageSize: 1000,
|
||||
driveId: $.step.parameters.driveId,
|
||||
supportsAllDrives: true,
|
@@ -1,8 +1,8 @@
|
||||
import defineApp from '../../helpers/define-app';
|
||||
import addAuthHeader from './common/add-auth-header';
|
||||
import auth from './auth';
|
||||
import triggers from './triggers';
|
||||
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 dynamicData from './dynamic-data/index.js';
|
||||
|
||||
export default defineApp({
|
||||
name: 'Google Drive',
|
6
packages/backend/src/apps/google-drive/triggers/index.js
Normal file
6
packages/backend/src/apps/google-drive/triggers/index.js
Normal file
@@ -0,0 +1,6 @@
|
||||
import newFiles from './new-files/index.js';
|
||||
import newFilesInFolder from './new-files-in-folder/index.js';
|
||||
import newFolders from './new-folders/index.js';
|
||||
import updatedFiles from './updated-files/index.js';
|
||||
|
||||
export default [newFiles, newFilesInFolder, newFolders, updatedFiles];
|
@@ -1,6 +0,0 @@
|
||||
import newFiles from './new-files';
|
||||
import newFilesInFolder from './new-files-in-folder';
|
||||
import newFolders from './new-folders';
|
||||
import updatedFiles from './updated-files';
|
||||
|
||||
export default [newFiles, newFilesInFolder, newFolders, updatedFiles];
|
@@ -1,5 +1,5 @@
|
||||
import defineTrigger from '../../../../helpers/define-trigger';
|
||||
import newFilesInFolder from './new-files-in-folder';
|
||||
import defineTrigger from '../../../../helpers/define-trigger.js';
|
||||
import newFilesInFolder from './new-files-in-folder.js';
|
||||
|
||||
export default defineTrigger({
|
||||
name: 'New files in folder',
|
||||
@@ -11,7 +11,7 @@ export default defineTrigger({
|
||||
{
|
||||
label: 'Drive',
|
||||
key: 'driveId',
|
||||
type: 'dropdown' as const,
|
||||
type: 'dropdown',
|
||||
required: false,
|
||||
description:
|
||||
'The Google Drive where your file resides. If nothing is selected, then your personal Google Drive will be used.',
|
||||
@@ -30,7 +30,7 @@ export default defineTrigger({
|
||||
{
|
||||
label: 'Folder',
|
||||
key: 'folderId',
|
||||
type: 'dropdown' as const,
|
||||
type: 'dropdown',
|
||||
required: false,
|
||||
dependsOn: ['parameters.driveId'],
|
||||
description:
|
@@ -1,14 +1,12 @@
|
||||
import { IGlobalVariable } from '@automatisch/types';
|
||||
|
||||
const newFilesInFolder = async ($: IGlobalVariable) => {
|
||||
const newFilesInFolder = async ($) => {
|
||||
let q = "mimeType!='application/vnd.google-apps.folder'";
|
||||
if ($.step.parameters.folderId) {
|
||||
q += ` and '${$.step.parameters.folderId}' in parents`;
|
||||
} else {
|
||||
q += ` and parents in 'root'`;
|
||||
}
|
||||
const params: Record<string, unknown> = {
|
||||
pageToken: undefined as unknown as string,
|
||||
const params = {
|
||||
pageToken: undefined,
|
||||
orderBy: 'createdTime desc',
|
||||
fields: '*',
|
||||
pageSize: 1000,
|
@@ -1,5 +1,5 @@
|
||||
import defineTrigger from '../../../../helpers/define-trigger';
|
||||
import newFiles from './new-files';
|
||||
import defineTrigger from '../../../../helpers/define-trigger.js';
|
||||
import newFiles from './new-files.js';
|
||||
|
||||
export default defineTrigger({
|
||||
name: 'New files',
|
||||
@@ -10,7 +10,7 @@ export default defineTrigger({
|
||||
{
|
||||
label: 'Drive',
|
||||
key: 'driveId',
|
||||
type: 'dropdown' as const,
|
||||
type: 'dropdown',
|
||||
required: false,
|
||||
description:
|
||||
'The Google Drive where your file resides. If nothing is selected, then your personal Google Drive will be used.',
|
@@ -1,8 +1,6 @@
|
||||
import { IGlobalVariable } from '@automatisch/types';
|
||||
|
||||
const newFiles = async ($: IGlobalVariable) => {
|
||||
const params: Record<string, unknown> = {
|
||||
pageToken: undefined as unknown as string,
|
||||
const newFiles = async ($) => {
|
||||
const params = {
|
||||
pageToken: undefined,
|
||||
orderBy: 'createdTime desc',
|
||||
fields: '*',
|
||||
pageSize: 1000,
|
@@ -1,5 +1,5 @@
|
||||
import defineTrigger from '../../../../helpers/define-trigger';
|
||||
import newFolders from './new-folders';
|
||||
import defineTrigger from '../../../../helpers/define-trigger.js';
|
||||
import newFolders from './new-folders.js';
|
||||
|
||||
export default defineTrigger({
|
||||
name: 'New folders',
|
||||
@@ -11,7 +11,7 @@ export default defineTrigger({
|
||||
{
|
||||
label: 'Drive',
|
||||
key: 'driveId',
|
||||
type: 'dropdown' as const,
|
||||
type: 'dropdown',
|
||||
required: false,
|
||||
description:
|
||||
'The Google Drive where your file resides. If nothing is selected, then your personal Google Drive will be used.',
|
||||
@@ -30,7 +30,7 @@ export default defineTrigger({
|
||||
{
|
||||
label: 'Folder',
|
||||
key: 'folderId',
|
||||
type: 'dropdown' as const,
|
||||
type: 'dropdown',
|
||||
required: false,
|
||||
dependsOn: ['parameters.driveId'],
|
||||
description:
|
@@ -1,6 +1,4 @@
|
||||
import { IGlobalVariable } from '@automatisch/types';
|
||||
|
||||
const newFolders = async ($: IGlobalVariable) => {
|
||||
const newFolders = async ($) => {
|
||||
let q = "mimeType='application/vnd.google-apps.folder'";
|
||||
if ($.step.parameters.folderId) {
|
||||
q += ` and '${$.step.parameters.folderId}' in parents`;
|
||||
@@ -8,8 +6,8 @@ const newFolders = async ($: IGlobalVariable) => {
|
||||
q += ` and parents in 'root'`;
|
||||
}
|
||||
|
||||
const params: Record<string, unknown> = {
|
||||
pageToken: undefined as unknown as string,
|
||||
const params = {
|
||||
pageToken: undefined,
|
||||
orderBy: 'createdTime desc',
|
||||
fields: '*',
|
||||
pageSize: 1000,
|
@@ -1,5 +1,5 @@
|
||||
import defineTrigger from '../../../../helpers/define-trigger';
|
||||
import updatedFiles from './updated-files';
|
||||
import defineTrigger from '../../../../helpers/define-trigger.js';
|
||||
import updatedFiles from './updated-files.js';
|
||||
|
||||
export default defineTrigger({
|
||||
name: 'Updated files',
|
||||
@@ -11,7 +11,7 @@ export default defineTrigger({
|
||||
{
|
||||
label: 'Drive',
|
||||
key: 'driveId',
|
||||
type: 'dropdown' as const,
|
||||
type: 'dropdown',
|
||||
required: false,
|
||||
description:
|
||||
'The Google Drive where your file resides. If nothing is selected, then your personal Google Drive will be used.',
|
||||
@@ -30,7 +30,7 @@ export default defineTrigger({
|
||||
{
|
||||
label: 'Folder',
|
||||
key: 'folderId',
|
||||
type: 'dropdown' as const,
|
||||
type: 'dropdown',
|
||||
required: false,
|
||||
dependsOn: ['parameters.driveId'],
|
||||
description:
|
||||
@@ -53,7 +53,7 @@ export default defineTrigger({
|
||||
{
|
||||
label: 'Include Deleted',
|
||||
key: 'includeDeleted',
|
||||
type: 'dropdown' as const,
|
||||
type: 'dropdown',
|
||||
required: true,
|
||||
value: true,
|
||||
description: 'Should this trigger also on files that are deleted?',
|
@@ -1,6 +1,4 @@
|
||||
import { IGlobalVariable } from '@automatisch/types';
|
||||
|
||||
const updatedFiles = async ($: IGlobalVariable) => {
|
||||
const updatedFiles = async ($) => {
|
||||
let q = `mimeType!='application/vnd.google-apps.folder'`;
|
||||
if ($.step.parameters.includeDeleted === false) {
|
||||
q += ` and trashed=${$.step.parameters.includeDeleted}`;
|
||||
@@ -12,8 +10,8 @@ const updatedFiles = async ($: IGlobalVariable) => {
|
||||
q += ` and parents in 'root'`;
|
||||
}
|
||||
|
||||
const params: Record<string, unknown> = {
|
||||
pageToken: undefined as unknown as string,
|
||||
const params = {
|
||||
pageToken: undefined,
|
||||
orderBy: 'modifiedTime desc',
|
||||
fields: '*',
|
||||
pageSize: 1000,
|
Reference in New Issue
Block a user