feat: Convert all app files to JS
This commit is contained in:
@@ -1,15 +1,14 @@
|
||||
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({
|
||||
response_type: 'code',
|
||||
client_id: $.auth.data.clientId as string,
|
||||
client_id: $.auth.data.clientId,
|
||||
scope: authScope.join(' '),
|
||||
redirect_uri: redirectUri,
|
||||
});
|
@@ -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/xero/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,
|
8
packages/backend/src/apps/xero/auth/is-still-verified.js
Normal file
8
packages/backend/src/apps/xero/auth/is-still-verified.js
Normal file
@@ -0,0 +1,8 @@
|
||||
import getCurrentUser from '../common/get-current-user.js';
|
||||
|
||||
const isStillVerified = async ($) => {
|
||||
const currentUser = await getCurrentUser($);
|
||||
return !!currentUser.tenantName;
|
||||
};
|
||||
|
||||
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.tenantName;
|
||||
};
|
||||
|
||||
export default isStillVerified;
|
@@ -1,8 +1,8 @@
|
||||
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 headers = {
|
||||
Authorization: `Basic ${Buffer.from(
|
||||
$.auth.data.clientId + ':' + $.auth.data.clientSecret
|
||||
@@ -12,7 +12,7 @@ const refreshToken = async ($: IGlobalVariable) => {
|
||||
|
||||
const params = new URLSearchParams({
|
||||
grant_type: 'refresh_token',
|
||||
refresh_token: $.auth.data.refreshToken as string,
|
||||
refresh_token: $.auth.data.refreshToken,
|
||||
});
|
||||
|
||||
const { data } = await $.http.post(
|
@@ -1,12 +1,11 @@
|
||||
import { IField, IGlobalVariable } from '@automatisch/types';
|
||||
import getCurrentUser from '../common/get-current-user';
|
||||
import getCurrentUser from '../common/get-current-user.js';
|
||||
import { URLSearchParams } from 'url';
|
||||
|
||||
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 headers = {
|
||||
Authorization: `Basic ${Buffer.from(
|
||||
$.auth.data.clientId + ':' + $.auth.data.clientSecret
|
||||
@@ -15,7 +14,7 @@ const verifyCredentials = async ($: IGlobalVariable) => {
|
||||
};
|
||||
const params = new URLSearchParams({
|
||||
grant_type: 'authorization_code',
|
||||
code: $.auth.data.code as string,
|
||||
code: $.auth.data.code,
|
||||
redirect_uri: redirectUri,
|
||||
});
|
||||
|
@@ -1,6 +1,4 @@
|
||||
import { TBeforeRequest } from '@automatisch/types';
|
||||
|
||||
const addAuthHeader: TBeforeRequest = ($, requestConfig) => {
|
||||
const addAuthHeader = ($, requestConfig) => {
|
||||
if (requestConfig.additionalProperties?.skipAddingAuthHeader)
|
||||
return requestConfig;
|
||||
|
||||
@@ -9,7 +7,7 @@ const addAuthHeader: TBeforeRequest = ($, requestConfig) => {
|
||||
}
|
||||
|
||||
if ($.auth.data?.tenantId) {
|
||||
requestConfig.headers['Xero-tenant-id'] = $.auth.data.tenantId as string;
|
||||
requestConfig.headers['Xero-tenant-id'] = $.auth.data.tenantId;
|
||||
}
|
||||
|
||||
return requestConfig;
|
@@ -1,4 +1,4 @@
|
||||
const authScope: string[] = [
|
||||
const authScope = [
|
||||
'offline_access',
|
||||
'openid',
|
||||
'profile',
|
@@ -1,6 +1,4 @@
|
||||
import { IGlobalVariable } from '@automatisch/types';
|
||||
|
||||
const getCurrentUser = async ($: IGlobalVariable) => {
|
||||
const getCurrentUser = async ($) => {
|
||||
const { data: currentUser } = await $.http.get('/connections');
|
||||
return currentUser[0];
|
||||
};
|
3
packages/backend/src/apps/xero/dynamic-data/index.js
Normal file
3
packages/backend/src/apps/xero/dynamic-data/index.js
Normal file
@@ -0,0 +1,3 @@
|
||||
import listOrganizations from './list-organizations/index.js';
|
||||
|
||||
export default [listOrganizations];
|
@@ -1,3 +0,0 @@
|
||||
import listOrganizations from './list-organizations';
|
||||
|
||||
export default [listOrganizations];
|
@@ -1,13 +1,9 @@
|
||||
import { IGlobalVariable, IJSONObject } from '@automatisch/types';
|
||||
|
||||
export default {
|
||||
name: 'List organizations',
|
||||
key: 'listOrganizations',
|
||||
|
||||
async run($: IGlobalVariable) {
|
||||
const organizations: {
|
||||
data: IJSONObject[];
|
||||
} = {
|
||||
async run($) {
|
||||
const organizations = {
|
||||
data: [],
|
||||
};
|
||||
|
@@ -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: 'Xero',
|
4
packages/backend/src/apps/xero/triggers/index.js
Normal file
4
packages/backend/src/apps/xero/triggers/index.js
Normal file
@@ -0,0 +1,4 @@
|
||||
import newBankTransactions from './new-bank-transactions/index.js';
|
||||
import newPayments from './new-payments/index.js';
|
||||
|
||||
export default [newBankTransactions, newPayments];
|
@@ -1,4 +0,0 @@
|
||||
import newBankTransactions from './new-bank-transactions';
|
||||
import newPayments from './new-payments';
|
||||
|
||||
export default [newBankTransactions, newPayments];
|
@@ -1,4 +1,4 @@
|
||||
import defineTrigger from '../../../../helpers/define-trigger';
|
||||
import defineTrigger from '../../../../helpers/define-trigger.js';
|
||||
|
||||
export default defineTrigger({
|
||||
name: 'New bank transactions',
|
||||
@@ -9,7 +9,7 @@ export default defineTrigger({
|
||||
{
|
||||
label: 'Organization',
|
||||
key: 'organizationId',
|
||||
type: 'dropdown' as const,
|
||||
type: 'dropdown',
|
||||
required: true,
|
||||
description: '',
|
||||
variables: true,
|
@@ -1,10 +1,4 @@
|
||||
import defineTrigger from '../../../../helpers/define-trigger';
|
||||
|
||||
type Params = {
|
||||
page: number;
|
||||
order: string;
|
||||
where?: string;
|
||||
};
|
||||
import defineTrigger from '../../../../helpers/define-trigger.js';
|
||||
|
||||
export default defineTrigger({
|
||||
name: 'New payments',
|
||||
@@ -15,7 +9,7 @@ export default defineTrigger({
|
||||
{
|
||||
label: 'Organization',
|
||||
key: 'organizationId',
|
||||
type: 'dropdown' as const,
|
||||
type: 'dropdown',
|
||||
required: true,
|
||||
description: '',
|
||||
variables: true,
|
||||
@@ -33,7 +27,7 @@ export default defineTrigger({
|
||||
{
|
||||
label: 'Payment Type',
|
||||
key: 'paymentType',
|
||||
type: 'dropdown' as const,
|
||||
type: 'dropdown',
|
||||
required: false,
|
||||
description: '',
|
||||
variables: true,
|
||||
@@ -72,7 +66,7 @@ export default defineTrigger({
|
||||
async run($) {
|
||||
const paymentType = $.step.parameters.paymentType;
|
||||
|
||||
const params: Params = {
|
||||
const params = {
|
||||
page: 1,
|
||||
order: 'Date DESC',
|
||||
};
|
Reference in New Issue
Block a user