Merge pull request #1419 from automatisch/AUT-391
feat(xero): add new bank transactions trigger
This commit is contained in:
@@ -4,6 +4,7 @@ const authScope: string[] = [
|
|||||||
'profile',
|
'profile',
|
||||||
'email',
|
'email',
|
||||||
'accounting.transactions',
|
'accounting.transactions',
|
||||||
|
'accounting.settings',
|
||||||
];
|
];
|
||||||
|
|
||||||
export default authScope;
|
export default authScope;
|
||||||
|
3
packages/backend/src/apps/xero/dynamic-data/index.ts
Normal file
3
packages/backend/src/apps/xero/dynamic-data/index.ts
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
import listOrganizations from './list-organizations';
|
||||||
|
|
||||||
|
export default [listOrganizations];
|
@@ -0,0 +1,27 @@
|
|||||||
|
import { IGlobalVariable, IJSONObject } from '@automatisch/types';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'List organizations',
|
||||||
|
key: 'listOrganizations',
|
||||||
|
|
||||||
|
async run($: IGlobalVariable) {
|
||||||
|
const organizations: {
|
||||||
|
data: IJSONObject[];
|
||||||
|
} = {
|
||||||
|
data: [],
|
||||||
|
};
|
||||||
|
|
||||||
|
const { data } = await $.http.get('/api.xro/2.0/Organisation');
|
||||||
|
|
||||||
|
if (data.Organisations?.length) {
|
||||||
|
for (const organization of data.Organisations) {
|
||||||
|
organizations.data.push({
|
||||||
|
value: organization.OrganisationID,
|
||||||
|
name: organization.Name,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return organizations;
|
||||||
|
},
|
||||||
|
};
|
@@ -1,6 +1,8 @@
|
|||||||
import defineApp from '../../helpers/define-app';
|
import defineApp from '../../helpers/define-app';
|
||||||
import addAuthHeader from './common/add-auth-header';
|
import addAuthHeader from './common/add-auth-header';
|
||||||
import auth from './auth';
|
import auth from './auth';
|
||||||
|
import triggers from './triggers';
|
||||||
|
import dynamicData from './dynamic-data';
|
||||||
|
|
||||||
export default defineApp({
|
export default defineApp({
|
||||||
name: 'Xero',
|
name: 'Xero',
|
||||||
@@ -13,4 +15,6 @@ export default defineApp({
|
|||||||
supportsConnections: true,
|
supportsConnections: true,
|
||||||
beforeRequest: [addAuthHeader],
|
beforeRequest: [addAuthHeader],
|
||||||
auth,
|
auth,
|
||||||
|
triggers,
|
||||||
|
dynamicData,
|
||||||
});
|
});
|
||||||
|
3
packages/backend/src/apps/xero/triggers/index.ts
Normal file
3
packages/backend/src/apps/xero/triggers/index.ts
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
import newBankTransactions from './new-bank-transactions';
|
||||||
|
|
||||||
|
export default [newBankTransactions];
|
@@ -0,0 +1,60 @@
|
|||||||
|
import defineTrigger from '../../../../helpers/define-trigger';
|
||||||
|
|
||||||
|
export default defineTrigger({
|
||||||
|
name: 'New bank transactions',
|
||||||
|
key: 'newBankTransactions',
|
||||||
|
pollInterval: 15,
|
||||||
|
description: 'Triggers when a new bank transaction occurs.',
|
||||||
|
arguments: [
|
||||||
|
{
|
||||||
|
label: 'Organization',
|
||||||
|
key: 'organizationId',
|
||||||
|
type: 'dropdown' as const,
|
||||||
|
required: true,
|
||||||
|
description: '',
|
||||||
|
variables: true,
|
||||||
|
source: {
|
||||||
|
type: 'query',
|
||||||
|
name: 'getDynamicData',
|
||||||
|
arguments: [
|
||||||
|
{
|
||||||
|
name: 'key',
|
||||||
|
value: 'listOrganizations',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
|
||||||
|
async run($) {
|
||||||
|
const params = {
|
||||||
|
page: 1,
|
||||||
|
order: 'Date DESC',
|
||||||
|
};
|
||||||
|
|
||||||
|
let nextPage = false;
|
||||||
|
do {
|
||||||
|
const { data } = await $.http.get('/api.xro/2.0/BankTransactions', {
|
||||||
|
params,
|
||||||
|
});
|
||||||
|
params.page = params.page + 1;
|
||||||
|
|
||||||
|
if (data.BankTransactions?.length) {
|
||||||
|
for (const bankTransaction of data.BankTransactions) {
|
||||||
|
$.pushTriggerItem({
|
||||||
|
raw: bankTransaction,
|
||||||
|
meta: {
|
||||||
|
internalId: bankTransaction.BankTransactionID,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.BankTransactions?.length === 100) {
|
||||||
|
nextPage = true;
|
||||||
|
} else {
|
||||||
|
nextPage = false;
|
||||||
|
}
|
||||||
|
} while (nextPage);
|
||||||
|
},
|
||||||
|
});
|
12
packages/docs/pages/apps/xero/triggers.md
Normal file
12
packages/docs/pages/apps/xero/triggers.md
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
---
|
||||||
|
favicon: /favicons/xero.svg
|
||||||
|
items:
|
||||||
|
- name: New bank transactions
|
||||||
|
desc: Triggers when a new bank transaction occurs.
|
||||||
|
---
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import CustomListing from '../../components/CustomListing.vue'
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<CustomListing />
|
Reference in New Issue
Block a user