Skip to content

Commit 6eab05d

Browse files
committed
[Components] Rewiser #17699
Actions - Create Transaction Sources - New Transaction
1 parent 4a2b1bc commit 6eab05d

File tree

6 files changed

+263
-6
lines changed

6 files changed

+263
-6
lines changed
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
import { getSummary } from "../../common/utils.mjs";
2+
import rewiser from "../../rewiser.app.mjs";
3+
4+
export default {
5+
key: "rewiser-create-transaction",
6+
name: "Create Transaction",
7+
description: "Create a financial transaction in Rewiser. [See the documentation](https://rewiser.io/api)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
rewiser,
12+
folderId: {
13+
propDefinition: [
14+
rewiser,
15+
"folderId",
16+
],
17+
},
18+
type: {
19+
type: "string",
20+
label: "Type",
21+
description: "The type of transaction.",
22+
options: [
23+
{
24+
label: "Income",
25+
value: "income",
26+
},
27+
{
28+
label: "Expense",
29+
value: "expense",
30+
},
31+
],
32+
},
33+
name: {
34+
type: "string",
35+
label: "Name",
36+
description: "The name/description of the transaction.",
37+
},
38+
amount: {
39+
type: "string",
40+
label: "Amount",
41+
description: "The amount of the transaction.",
42+
},
43+
plannedDate: {
44+
type: "string",
45+
label: "Planned Date",
46+
description: "The planned date for the transaction Format: YYYY-MM-DD. E.g. 2025-01-01",
47+
},
48+
isPaid: {
49+
type: "boolean",
50+
label: "Is Paid",
51+
description: "Whether the transaction is paid.",
52+
optional: true,
53+
},
54+
note: {
55+
type: "string",
56+
label: "Note",
57+
description: "Additional notes for the transaction.",
58+
optional: true,
59+
},
60+
repeatType: {
61+
type: "string",
62+
label: "Repeat Type",
63+
description: "The repeat type for recurring transactions.",
64+
options: [
65+
{
66+
label: "Daily",
67+
value: "daily",
68+
},
69+
{
70+
label: "Weekly",
71+
value: "weekly",
72+
},
73+
{
74+
label: "Monthly",
75+
value: "monthly",
76+
},
77+
{
78+
label: "Yearly",
79+
value: "yearly",
80+
},
81+
],
82+
optional: true,
83+
},
84+
},
85+
async run({ $ }) {
86+
const response = await this.rewiser.createTransaction({
87+
$,
88+
data: {
89+
transactions: [
90+
{
91+
folder_id: this.folderId,
92+
type: this.type,
93+
name: this.name,
94+
amount: parseFloat(this.amount),
95+
planned_date: this.plannedDate,
96+
is_paid: this.isPaid,
97+
note: this.note,
98+
repeat_type: this.repeatType,
99+
},
100+
],
101+
},
102+
});
103+
104+
$.export("$summary", getSummary(response));
105+
return response;
106+
},
107+
};
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
export const getSummary = ({
2+
inserted, errors, duplicates, skipped,
3+
}) => {
4+
const actions = {
5+
inserted,
6+
errors,
7+
duplicates,
8+
skipped,
9+
};
10+
11+
const [
12+
action,
13+
] = Object.keys(actions).filter((key) => actions[key].length > 0);
14+
15+
switch (action) {
16+
case "inserted":
17+
return "Inserted transaction";
18+
case "errors":
19+
return "Transaction creation failed";
20+
case "duplicates":
21+
return "Transaction creation duplicate";
22+
case "skipped":
23+
return "Transaction creation skipped";
24+
}
25+
};

components/rewiser/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/rewiser",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream Rewiser Components",
55
"main": "rewiser.app.mjs",
66
"keywords": [
@@ -11,5 +11,8 @@
1111
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.1.0"
1417
}
15-
}
18+
}

components/rewiser/rewiser.app.mjs

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,62 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "rewiser",
4-
propDefinitions: {},
6+
propDefinitions: {
7+
folderId: {
8+
type: "string",
9+
label: "Folder ID",
10+
description: "The folder ID for the transaction.",
11+
async options() {
12+
const folders = await this.listFolders();
13+
14+
return folders.map(({
15+
key: value, label,
16+
}) => ({
17+
label,
18+
value,
19+
}));
20+
},
21+
},
22+
},
523
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
24+
_baseUrl() {
25+
return "https://nzkqapsaeatytqrnitpj.supabase.co/functions/v1";
26+
},
27+
_headers() {
28+
return {
29+
"Authorization": `Bearer ${this.$auth.api_key}`,
30+
"content-type": "application/json",
31+
};
32+
},
33+
_makeRequest({
34+
$ = this, path, ...opts
35+
}) {
36+
return axios($, {
37+
url: this._baseUrl() + path,
38+
headers: this._headers(),
39+
...opts,
40+
});
41+
},
42+
listFolders(opts = {}) {
43+
return this._makeRequest({
44+
path: "/get-folders",
45+
...opts,
46+
});
47+
},
48+
getRecentTransactions(opts = {}) {
49+
return this._makeRequest({
50+
path: "/get-recent-transactions",
51+
...opts,
52+
});
53+
},
54+
createTransaction(opts = {}) {
55+
return this._makeRequest({
56+
method: "POST",
57+
path: "/create_multiple_transactions",
58+
...opts,
59+
});
960
},
1061
},
1162
};
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";
2+
import rewiser from "../../rewiser.app.mjs";
3+
import sampleEmit from "./test-event.mjs";
4+
5+
export default {
6+
key: "rewiser-new-transaction",
7+
name: "New Transaction",
8+
description: "Emit new event when a new transaction is created in Rewiser. [See the documentation](https://rewiser.io/api)",
9+
version: "0.0.1",
10+
type: "source",
11+
dedupe: "unique",
12+
props: {
13+
rewiser,
14+
timer: {
15+
type: "$.interface.timer",
16+
default: {
17+
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
18+
},
19+
},
20+
db: "$.service.db",
21+
alert: {
22+
type: "alert",
23+
alertType: "info",
24+
content: "This endpoint automatically returns only transactions created within the last 1 hour (maximum 100 records) to optimize polling and prevent duplicate triggers.",
25+
},
26+
},
27+
methods: {
28+
getLastDate() {
29+
return this.db.get("lastDate") || "1970-01-01T00:00:00.000Z";
30+
},
31+
setLastDate(date) {
32+
return this.db.set("lastDate", date);
33+
},
34+
},
35+
async run() {
36+
const responseArray = [];
37+
let lastDate = this.getLastDate();
38+
const { data: transactions } = await this.rewiser.getRecentTransactions();
39+
40+
for (const transaction of transactions) {
41+
if (Date.parse(transaction.created_at) < Date.parse(lastDate)) {
42+
break;
43+
}
44+
responseArray.push(transaction);
45+
}
46+
47+
if (responseArray.length > 0) {
48+
this.setLastDate(responseArray[0].created_at);
49+
}
50+
51+
for (const transaction of responseArray.reverse()) {
52+
this.$emit(transaction, {
53+
id: transaction.id,
54+
summary: `New Transaction: ${transaction.name} (${transaction.amount})`,
55+
ts: Date.parse(transaction.created_at),
56+
});
57+
}
58+
},
59+
sampleEmit,
60+
};
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export default {
2+
id: "transaction_uuid_here",
3+
name: "Notion Subscription",
4+
amount: 19.99,
5+
type: "Expense",
6+
created_at: "2025-06-11T19:44:44.109694+00:00",
7+
folder_id: "folder_uuid_here",
8+
is_paid: false,
9+
planned_date: "2025-06-15T22:44:00.000Z",
10+
note: "Monthly subscription",
11+
};

0 commit comments

Comments
 (0)