Compare commits

...

3 Commits

Author SHA1 Message Date
Rıdvan Akca
d085e0f979 feat(firefly-iii): add transaction deleted trigger 2024-05-21 15:09:07 +02:00
Rıdvan Akca
db084d12e4 feat(firefly-iii): add transaction updated trigger 2024-05-21 15:05:59 +02:00
Rıdvan Akca
1c76b02c78 feat(firefly-iii): add transaction created trigger 2024-05-21 15:04:32 +02:00
8 changed files with 293 additions and 1 deletions

View File

@@ -2,6 +2,7 @@ import defineApp from '../../helpers/define-app.js';
import addAuthHeader from './common/add-auth-header.js';
import auth from './auth/index.js';
import setBaseUrl from './common/set-base-url.js';
import triggers from './triggers/index.js';
export default defineApp({
name: 'Firefly III',
@@ -14,4 +15,5 @@ export default defineApp({
supportsConnections: true,
beforeRequest: [setBaseUrl, addAuthHeader],
auth,
triggers,
});

View File

@@ -0,0 +1,5 @@
import transactionCreated from './transaction-created/index.js';
import transactionDeleted from './transaction-deleted/index.js';
import transactionUpdated from './transaction-updated/index.js';
export default [transactionCreated, transactionDeleted, transactionUpdated];

View File

@@ -0,0 +1,89 @@
import Crypto from 'crypto';
import defineTrigger from '../../../../helpers/define-trigger.js';
export default defineTrigger({
name: 'Transaction created',
key: 'transactionCreated',
type: 'webhook',
description: 'Triggers when a new transaction is created.',
arguments: [
{
label: 'Title of the webhook',
key: 'title',
type: 'string',
required: false,
description: '',
variables: true,
},
],
async run($) {
const dataItem = {
raw: $.request.body,
meta: {
internalId: Crypto.randomUUID(),
},
};
$.pushTriggerItem(dataItem);
},
async testRun($) {
const { data: transactions } = await $.http.get(`/api/v1/transactions`);
if (transactions.data.length === 0) {
return;
}
const { data: transaction } = await $.http.get(
`/api/v1/transactions/${transactions.data[0].id}`
);
const lastTransaction = transaction.data;
if (!lastTransaction) {
return;
}
const computedWebhookEvent = {
url: '',
uuid: Crypto.randomUUID(),
content: lastTransaction.attributes,
trigger: 'STORE_TRANSACTION',
user_id: lastTransaction.attributes.user,
version: '',
response: 'TRANSACTIONS',
};
const dataItem = {
raw: computedWebhookEvent,
meta: {
internalId: computedWebhookEvent.uuid,
},
};
$.pushTriggerItem(dataItem);
},
async registerHook($) {
const title = $.step.parameters.title;
const payload = {
active: true,
title: title || `Flow ID: ${$.flow.id}`,
trigger: 'STORE_TRANSACTION',
response: 'TRANSACTIONS',
delivery: 'JSON',
url: $.webhookUrl,
};
const response = await $.http.post('/api/v1/webhooks', payload);
const id = response.data.data.id;
await $.flow.setRemoteWebhookId(id);
},
async unregisterHook($) {
await $.http.delete(`/api/v1/webhooks/${$.flow.remoteWebhookId}`);
},
});

View File

@@ -0,0 +1,89 @@
import Crypto from 'crypto';
import defineTrigger from '../../../../helpers/define-trigger.js';
export default defineTrigger({
name: 'Transaction deleted',
key: 'transactionDeleted',
type: 'webhook',
description: 'Triggers when a transaction is deleted.',
arguments: [
{
label: 'Title of the webhook',
key: 'title',
type: 'string',
required: false,
description: '',
variables: true,
},
],
async run($) {
const dataItem = {
raw: $.request.body,
meta: {
internalId: Crypto.randomUUID(),
},
};
$.pushTriggerItem(dataItem);
},
async testRun($) {
const { data: transactions } = await $.http.get(`/api/v1/transactions`);
if (transactions.data.length === 0) {
return;
}
const { data: transaction } = await $.http.get(
`/api/v1/transactions/${transactions.data[0].id}`
);
const lastTransaction = transaction.data;
if (!lastTransaction) {
return;
}
const computedWebhookEvent = {
url: '',
uuid: Crypto.randomUUID(),
content: lastTransaction.attributes,
trigger: 'DESTROY_TRANSACTION',
user_id: lastTransaction.attributes.user,
version: '',
response: 'TRANSACTIONS',
};
const dataItem = {
raw: computedWebhookEvent,
meta: {
internalId: computedWebhookEvent.uuid,
},
};
$.pushTriggerItem(dataItem);
},
async registerHook($) {
const title = $.step.parameters.title;
const payload = {
active: true,
title: title || `Flow ID: ${$.flow.id}`,
trigger: 'DESTROY_TRANSACTION',
response: 'TRANSACTIONS',
delivery: 'JSON',
url: $.webhookUrl,
};
const response = await $.http.post('/api/v1/webhooks', payload);
const id = response.data.data.id;
await $.flow.setRemoteWebhookId(id);
},
async unregisterHook($) {
await $.http.delete(`/api/v1/webhooks/${$.flow.remoteWebhookId}`);
},
});

View File

@@ -0,0 +1,89 @@
import Crypto from 'crypto';
import defineTrigger from '../../../../helpers/define-trigger.js';
export default defineTrigger({
name: 'Transaction updated',
key: 'transactionUpdated',
type: 'webhook',
description: 'Triggers when a transaction is updated.',
arguments: [
{
label: 'Title of the webhook',
key: 'title',
type: 'string',
required: false,
description: '',
variables: true,
},
],
async run($) {
const dataItem = {
raw: $.request.body,
meta: {
internalId: Crypto.randomUUID(),
},
};
$.pushTriggerItem(dataItem);
},
async testRun($) {
const { data: transactions } = await $.http.get(`/api/v1/transactions`);
if (transactions.data.length === 0) {
return;
}
const { data: transaction } = await $.http.get(
`/api/v1/transactions/${transactions.data[0].id}`
);
const lastTransaction = transaction.data;
if (!lastTransaction) {
return;
}
const computedWebhookEvent = {
url: '',
uuid: Crypto.randomUUID(),
content: lastTransaction.attributes,
trigger: 'UPDATE_TRANSACTION',
user_id: lastTransaction.attributes.user,
version: '',
response: 'TRANSACTIONS',
};
const dataItem = {
raw: computedWebhookEvent,
meta: {
internalId: computedWebhookEvent.uuid,
},
};
$.pushTriggerItem(dataItem);
},
async registerHook($) {
const title = $.step.parameters.title;
const payload = {
active: true,
title: title || `Flow ID: ${$.flow.id}`,
trigger: 'UPDATE_TRANSACTION',
response: 'TRANSACTIONS',
delivery: 'JSON',
url: $.webhookUrl,
};
const response = await $.http.post('/api/v1/webhooks', payload);
const id = response.data.data.id;
await $.flow.setRemoteWebhookId(id);
},
async unregisterHook($) {
await $.http.delete(`/api/v1/webhooks/${$.flow.remoteWebhookId}`);
},
});

View File

@@ -126,7 +126,10 @@ export default defineConfig({
text: 'Firefly III',
collapsible: true,
collapsed: true,
items: [{ text: 'Connection', link: '/apps/firefly-iii/connection' }],
items: [
{ text: 'Triggers', link: '/apps/firefly-iii/triggers' },
{ text: 'Connection', link: '/apps/firefly-iii/connection' },
],
},
{
text: 'Flickr',

View File

@@ -0,0 +1,14 @@
---
favicon: /favicons/firefly-iii.svg
items:
- name: Transaction created
desc: Triggers when a new transaction is created.
- name: Transaction updated
desc: Triggers when a transaction is updated.
---
<script setup>
import CustomListing from '../../components/CustomListing.vue'
</script>
<CustomListing />

View File

@@ -12,6 +12,7 @@ The following integrations are currently supported by Automatisch.
- [Disqus](/apps/disqus/triggers)
- [Dropbox](/apps/dropbox/actions)
- [Filter](/apps/filter/actions)
- [Firefly III](/apps/firefly-iii/triggers)
- [Flickr](/apps/flickr/triggers)
- [Formatter](/apps/formatter/actions)
- [Ghost](/apps/ghost/triggers)