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-forms/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 (requestConfig.headers && $.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/forms.body.readonly',
|
||||
'https://www.googleapis.com/auth/forms.responses.readonly',
|
||||
'https://www.googleapis.com/auth/drive.readonly',
|
@@ -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,3 @@
|
||||
import listForms from './list-forms/index.js';
|
||||
|
||||
export default [listForms];
|
@@ -1,3 +0,0 @@
|
||||
import listForms from './list-forms';
|
||||
|
||||
export default [listForms];
|
@@ -1,24 +1,23 @@
|
||||
import { IGlobalVariable, IJSONObject } from '@automatisch/types';
|
||||
|
||||
export default {
|
||||
name: 'List forms',
|
||||
key: 'listForms',
|
||||
|
||||
async run($: IGlobalVariable) {
|
||||
const forms: {
|
||||
data: IJSONObject[];
|
||||
} = {
|
||||
async run($) {
|
||||
const forms = {
|
||||
data: [],
|
||||
};
|
||||
|
||||
const params = {
|
||||
q: `mimeType='application/vnd.google-apps.form'`,
|
||||
spaces: 'drive',
|
||||
pageToken: undefined as unknown as string,
|
||||
pageToken: undefined,
|
||||
};
|
||||
|
||||
do {
|
||||
const { data } = await $.http.get(`https://www.googleapis.com/drive/v3/files`, { params });
|
||||
const { data } = await $.http.get(
|
||||
`https://www.googleapis.com/drive/v3/files`,
|
||||
{ params }
|
||||
);
|
||||
params.pageToken = data.nextPageToken;
|
||||
|
||||
for (const file of data.files) {
|
@@ -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 Forms',
|
3
packages/backend/src/apps/google-forms/triggers/index.js
Normal file
3
packages/backend/src/apps/google-forms/triggers/index.js
Normal file
@@ -0,0 +1,3 @@
|
||||
import newFormResponses from './new-form-responses/index.js';
|
||||
|
||||
export default [newFormResponses];
|
@@ -1,3 +0,0 @@
|
||||
import newFormResponses from './new-form-responses';
|
||||
|
||||
export default [newFormResponses];
|
@@ -1,5 +1,5 @@
|
||||
import defineTrigger from '../../../../helpers/define-trigger';
|
||||
import newFormResponses from './new-form-responses';
|
||||
import defineTrigger from '../../../../helpers/define-trigger.js';
|
||||
import newFormResponses from './new-form-responses.js';
|
||||
|
||||
export default defineTrigger({
|
||||
name: 'New form responses',
|
||||
@@ -10,7 +10,7 @@ export default defineTrigger({
|
||||
{
|
||||
label: 'Form',
|
||||
key: 'formId',
|
||||
type: 'dropdown' as const,
|
||||
type: 'dropdown',
|
||||
required: true,
|
||||
description: 'Pick a form to receive form responses.',
|
||||
variables: false,
|
@@ -1,8 +1,6 @@
|
||||
import { IGlobalVariable } from '@automatisch/types';
|
||||
|
||||
const newResponses = async ($: IGlobalVariable) => {
|
||||
const newResponses = async ($) => {
|
||||
const params = {
|
||||
pageToken: undefined as unknown as string,
|
||||
pageToken: undefined,
|
||||
};
|
||||
|
||||
do {
|
Reference in New Issue
Block a user