From 6eab05d3456353689e9b86f4d15eb2120b70690a Mon Sep 17 00:00:00 2001 From: Luan Cazarine Date: Thu, 24 Jul 2025 13:22:33 -0300 Subject: [PATCH 1/5] [Components] Rewiser #17699 Actions - Create Transaction Sources - New Transaction --- .../create-transaction/create-transaction.mjs | 107 ++++++++++++++++++ components/rewiser/common/utils.mjs | 25 ++++ components/rewiser/package.json | 7 +- components/rewiser/rewiser.app.mjs | 59 +++++++++- .../new-transaction/new-transaction.mjs | 60 ++++++++++ .../sources/new-transaction/test-event.mjs | 11 ++ 6 files changed, 263 insertions(+), 6 deletions(-) create mode 100644 components/rewiser/actions/create-transaction/create-transaction.mjs create mode 100644 components/rewiser/common/utils.mjs create mode 100644 components/rewiser/sources/new-transaction/new-transaction.mjs create mode 100644 components/rewiser/sources/new-transaction/test-event.mjs diff --git a/components/rewiser/actions/create-transaction/create-transaction.mjs b/components/rewiser/actions/create-transaction/create-transaction.mjs new file mode 100644 index 0000000000000..c76a18ce5f10c --- /dev/null +++ b/components/rewiser/actions/create-transaction/create-transaction.mjs @@ -0,0 +1,107 @@ +import { getSummary } from "../../common/utils.mjs"; +import rewiser from "../../rewiser.app.mjs"; + +export default { + key: "rewiser-create-transaction", + name: "Create Transaction", + description: "Create a financial transaction in Rewiser. [See the documentation](https://rewiser.io/api)", + version: "0.0.1", + type: "action", + props: { + rewiser, + folderId: { + propDefinition: [ + rewiser, + "folderId", + ], + }, + type: { + type: "string", + label: "Type", + description: "The type of transaction.", + options: [ + { + label: "Income", + value: "income", + }, + { + label: "Expense", + value: "expense", + }, + ], + }, + name: { + type: "string", + label: "Name", + description: "The name/description of the transaction.", + }, + amount: { + type: "string", + label: "Amount", + description: "The amount of the transaction.", + }, + plannedDate: { + type: "string", + label: "Planned Date", + description: "The planned date for the transaction Format: YYYY-MM-DD. E.g. 2025-01-01", + }, + isPaid: { + type: "boolean", + label: "Is Paid", + description: "Whether the transaction is paid.", + optional: true, + }, + note: { + type: "string", + label: "Note", + description: "Additional notes for the transaction.", + optional: true, + }, + repeatType: { + type: "string", + label: "Repeat Type", + description: "The repeat type for recurring transactions.", + options: [ + { + label: "Daily", + value: "daily", + }, + { + label: "Weekly", + value: "weekly", + }, + { + label: "Monthly", + value: "monthly", + }, + { + label: "Yearly", + value: "yearly", + }, + ], + optional: true, + }, + }, + async run({ $ }) { + const response = await this.rewiser.createTransaction({ + $, + data: { + transactions: [ + { + folder_id: this.folderId, + type: this.type, + name: this.name, + amount: parseFloat(this.amount), + planned_date: this.plannedDate, + is_paid: this.isPaid, + note: this.note, + repeat_type: this.repeatType, + }, + ], + }, + }); + + $.export("$summary", getSummary(response)); + return response; + }, +}; diff --git a/components/rewiser/common/utils.mjs b/components/rewiser/common/utils.mjs new file mode 100644 index 0000000000000..8978d601f84e4 --- /dev/null +++ b/components/rewiser/common/utils.mjs @@ -0,0 +1,25 @@ +export const getSummary = ({ + inserted, errors, duplicates, skipped, +}) => { + const actions = { + inserted, + errors, + duplicates, + skipped, + }; + + const [ + action, + ] = Object.keys(actions).filter((key) => actions[key].length > 0); + + switch (action) { + case "inserted": + return "Inserted transaction"; + case "errors": + return "Transaction creation failed"; + case "duplicates": + return "Transaction creation duplicate"; + case "skipped": + return "Transaction creation skipped"; + } +}; diff --git a/components/rewiser/package.json b/components/rewiser/package.json index 2f0d746753821..3ef0af763dceb 100644 --- a/components/rewiser/package.json +++ b/components/rewiser/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/rewiser", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream Rewiser Components", "main": "rewiser.app.mjs", "keywords": [ @@ -11,5 +11,8 @@ "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^3.1.0" } -} \ No newline at end of file +} diff --git a/components/rewiser/rewiser.app.mjs b/components/rewiser/rewiser.app.mjs index ca620607b3660..430f4498dedd4 100644 --- a/components/rewiser/rewiser.app.mjs +++ b/components/rewiser/rewiser.app.mjs @@ -1,11 +1,62 @@ +import { axios } from "@pipedream/platform"; + export default { type: "app", app: "rewiser", - propDefinitions: {}, + propDefinitions: { + folderId: { + type: "string", + label: "Folder ID", + description: "The folder ID for the transaction.", + async options() { + const folders = await this.listFolders(); + + return folders.map(({ + key: value, label, + }) => ({ + label, + value, + })); + }, + }, + }, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + _baseUrl() { + return "https://nzkqapsaeatytqrnitpj.supabase.co/functions/v1"; + }, + _headers() { + return { + "Authorization": `Bearer ${this.$auth.api_key}`, + "content-type": "application/json", + }; + }, + _makeRequest({ + $ = this, path, ...opts + }) { + return axios($, { + url: this._baseUrl() + path, + headers: this._headers(), + ...opts, + }); + }, + listFolders(opts = {}) { + return this._makeRequest({ + path: "/get-folders", + ...opts, + }); + }, + getRecentTransactions(opts = {}) { + return this._makeRequest({ + path: "/get-recent-transactions", + ...opts, + }); + }, + createTransaction(opts = {}) { + return this._makeRequest({ + method: "POST", + path: "/create_multiple_transactions", + ...opts, + }); }, }, }; diff --git a/components/rewiser/sources/new-transaction/new-transaction.mjs b/components/rewiser/sources/new-transaction/new-transaction.mjs new file mode 100644 index 0000000000000..2a6df49aaa0c4 --- /dev/null +++ b/components/rewiser/sources/new-transaction/new-transaction.mjs @@ -0,0 +1,60 @@ +import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform"; +import rewiser from "../../rewiser.app.mjs"; +import sampleEmit from "./test-event.mjs"; + +export default { + key: "rewiser-new-transaction", + name: "New Transaction", + description: "Emit new event when a new transaction is created in Rewiser. [See the documentation](https://rewiser.io/api)", + version: "0.0.1", + type: "source", + dedupe: "unique", + props: { + rewiser, + timer: { + type: "$.interface.timer", + default: { + intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL, + }, + }, + db: "$.service.db", + alert: { + type: "alert", + alertType: "info", + content: "This endpoint automatically returns only transactions created within the last 1 hour (maximum 100 records) to optimize polling and prevent duplicate triggers.", + }, + }, + methods: { + getLastDate() { + return this.db.get("lastDate") || "1970-01-01T00:00:00.000Z"; + }, + setLastDate(date) { + return this.db.set("lastDate", date); + }, + }, + async run() { + const responseArray = []; + let lastDate = this.getLastDate(); + const { data: transactions } = await this.rewiser.getRecentTransactions(); + + for (const transaction of transactions) { + if (Date.parse(transaction.created_at) < Date.parse(lastDate)) { + break; + } + responseArray.push(transaction); + } + + if (responseArray.length > 0) { + this.setLastDate(responseArray[0].created_at); + } + + for (const transaction of responseArray.reverse()) { + this.$emit(transaction, { + id: transaction.id, + summary: `New Transaction: ${transaction.name} (${transaction.amount})`, + ts: Date.parse(transaction.created_at), + }); + } + }, + sampleEmit, +}; diff --git a/components/rewiser/sources/new-transaction/test-event.mjs b/components/rewiser/sources/new-transaction/test-event.mjs new file mode 100644 index 0000000000000..8ff20a9751629 --- /dev/null +++ b/components/rewiser/sources/new-transaction/test-event.mjs @@ -0,0 +1,11 @@ +export default { + id: "transaction_uuid_here", + name: "Notion Subscription", + amount: 19.99, + type: "Expense", + created_at: "2025-06-11T19:44:44.109694+00:00", + folder_id: "folder_uuid_here", + is_paid: false, + planned_date: "2025-06-15T22:44:00.000Z", + note: "Monthly subscription", +}; \ No newline at end of file From 8bcedcbf6952d2a5d80d7c10fcc364cfb8f53d08 Mon Sep 17 00:00:00 2001 From: Luan Cazarine Date: Thu, 24 Jul 2025 13:23:59 -0300 Subject: [PATCH 2/5] pnpm update --- pnpm-lock.yaml | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 914682d319f4c..9d557326e55b9 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -11527,7 +11527,11 @@ importers: components/rewardful: {} - components/rewiser: {} + components/rewiser: + dependencies: + '@pipedream/platform': + specifier: ^3.1.0 + version: 3.1.0 components/rex: dependencies: @@ -29979,22 +29983,22 @@ packages: superagent@3.8.1: resolution: {integrity: sha512-VMBFLYgFuRdfeNQSMLbxGSLfmXL/xc+OO+BZp41Za/NRDBet/BNbkRJrYzCUu0u4GU0i/ml2dtT8b9qgkw9z6Q==} engines: {node: '>= 4.0'} - deprecated: Please upgrade to superagent v10.2.2+, see release notes at https://github.com/forwardemail/superagent/releases/tag/v10.2.2 - maintenance is supported by Forward Email @ https://forwardemail.net + deprecated: Please upgrade to v9.0.0+ as we have fixed a public vulnerability with formidable dependency. Note that v9.0.0+ requires Node.js v14.18.0+. See https://github.com/ladjs/superagent/pull/1800 for insight. This project is supported and maintained by the team at Forward Email @ https://forwardemail.net superagent@4.1.0: resolution: {integrity: sha512-FT3QLMasz0YyCd4uIi5HNe+3t/onxMyEho7C3PSqmti3Twgy2rXT4fmkTz6wRL6bTF4uzPcfkUCa8u4JWHw8Ag==} engines: {node: '>= 6.0'} - deprecated: Please upgrade to superagent v10.2.2+, see release notes at https://github.com/forwardemail/superagent/releases/tag/v10.2.2 - maintenance is supported by Forward Email @ https://forwardemail.net + deprecated: Please upgrade to v9.0.0+ as we have fixed a public vulnerability with formidable dependency. Note that v9.0.0+ requires Node.js v14.18.0+. See https://github.com/ladjs/superagent/pull/1800 for insight. This project is supported and maintained by the team at Forward Email @ https://forwardemail.net superagent@5.3.1: resolution: {integrity: sha512-wjJ/MoTid2/RuGCOFtlacyGNxN9QLMgcpYLDQlWFIhhdJ93kNscFonGvrpAHSCVjRVj++DGCglocF7Aej1KHvQ==} engines: {node: '>= 7.0.0'} - deprecated: Please upgrade to superagent v10.2.2+, see release notes at https://github.com/forwardemail/superagent/releases/tag/v10.2.2 - maintenance is supported by Forward Email @ https://forwardemail.net + deprecated: Please upgrade to v9.0.0+ as we have fixed a public vulnerability with formidable dependency. Note that v9.0.0+ requires Node.js v14.18.0+. See https://github.com/ladjs/superagent/pull/1800 for insight. This project is supported and maintained by the team at Forward Email @ https://forwardemail.net superagent@7.1.6: resolution: {integrity: sha512-gZkVCQR1gy/oUXr+kxJMLDjla434KmSOKbx5iGD30Ql+AkJQ/YlPKECJy2nhqOsHLjGHzoDTXNSjhnvWhzKk7g==} engines: {node: '>=6.4.0 <13 || >=14'} - deprecated: Please upgrade to superagent v10.2.2+, see release notes at https://github.com/forwardemail/superagent/releases/tag/v10.2.2 - maintenance is supported by Forward Email @ https://forwardemail.net + deprecated: Please upgrade to v9.0.0+ as we have fixed a public vulnerability with formidable dependency. Note that v9.0.0+ requires Node.js v14.18.0+. See https://github.com/ladjs/superagent/pull/1800 for insight. This project is supported and maintained by the team at Forward Email @ https://forwardemail.net supports-color@2.0.0: resolution: {integrity: sha512-KKNVtd6pCYgPIKU4cp2733HWYCpplQhddZLBUryaAHou723x+FRzQ5Df824Fj+IyyuiQTRoub4SnIFfIcrp70g==} From 48a397db19542f8a47c6ff0cb5c3607f2ecc7827 Mon Sep 17 00:00:00 2001 From: Luan Cazarine Date: Fri, 25 Jul 2025 11:57:36 -0300 Subject: [PATCH 3/5] Update components/rewiser/actions/create-transaction/create-transaction.mjs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Guilherme Falcão <48412907+GTFalcao@users.noreply.github.com> --- .../rewiser/actions/create-transaction/create-transaction.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/rewiser/actions/create-transaction/create-transaction.mjs b/components/rewiser/actions/create-transaction/create-transaction.mjs index c76a18ce5f10c..d0daeba03c568 100644 --- a/components/rewiser/actions/create-transaction/create-transaction.mjs +++ b/components/rewiser/actions/create-transaction/create-transaction.mjs @@ -43,7 +43,7 @@ export default { plannedDate: { type: "string", label: "Planned Date", - description: "The planned date for the transaction Format: YYYY-MM-DD. E.g. 2025-01-01", + description: "The planned date for the transaction, in the format `YYYY-MM-DD` (e.g. `2025-01-01`"), }, isPaid: { type: "boolean", From 94a1e4cae587badb689887e0d367da07ff3dc2dc Mon Sep 17 00:00:00 2001 From: Luan Cazarine Date: Fri, 25 Jul 2025 12:00:13 -0300 Subject: [PATCH 4/5] Add new source for Rewiser: New Transaction Created - Implemented a new source that emits events when a new transaction is created in Rewiser. - Added methods to manage the last processed transaction date and emit new transactions. - Included a sample event for testing purposes. --- .../new-transaction-created.mjs} | 4 ++-- .../test-event.mjs | 0 2 files changed, 2 insertions(+), 2 deletions(-) rename components/rewiser/sources/{new-transaction/new-transaction.mjs => new-transaction-created/new-transaction-created.mjs} (95%) rename components/rewiser/sources/{new-transaction => new-transaction-created}/test-event.mjs (100%) diff --git a/components/rewiser/sources/new-transaction/new-transaction.mjs b/components/rewiser/sources/new-transaction-created/new-transaction-created.mjs similarity index 95% rename from components/rewiser/sources/new-transaction/new-transaction.mjs rename to components/rewiser/sources/new-transaction-created/new-transaction-created.mjs index 2a6df49aaa0c4..6547051c1d75f 100644 --- a/components/rewiser/sources/new-transaction/new-transaction.mjs +++ b/components/rewiser/sources/new-transaction-created/new-transaction-created.mjs @@ -3,8 +3,8 @@ import rewiser from "../../rewiser.app.mjs"; import sampleEmit from "./test-event.mjs"; export default { - key: "rewiser-new-transaction", - name: "New Transaction", + key: "rewiser-new-transaction-created", + name: "New Transaction Created", description: "Emit new event when a new transaction is created in Rewiser. [See the documentation](https://rewiser.io/api)", version: "0.0.1", type: "source", diff --git a/components/rewiser/sources/new-transaction/test-event.mjs b/components/rewiser/sources/new-transaction-created/test-event.mjs similarity index 100% rename from components/rewiser/sources/new-transaction/test-event.mjs rename to components/rewiser/sources/new-transaction-created/test-event.mjs From fe86261ec2d32dbfa5e76c77a9382f781db093ed Mon Sep 17 00:00:00 2001 From: Luan Cazarine Date: Fri, 25 Jul 2025 12:03:14 -0300 Subject: [PATCH 5/5] Update components/rewiser/actions/create-transaction/create-transaction.mjs Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- .../rewiser/actions/create-transaction/create-transaction.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/rewiser/actions/create-transaction/create-transaction.mjs b/components/rewiser/actions/create-transaction/create-transaction.mjs index d0daeba03c568..dff87dabd7a95 100644 --- a/components/rewiser/actions/create-transaction/create-transaction.mjs +++ b/components/rewiser/actions/create-transaction/create-transaction.mjs @@ -43,7 +43,7 @@ export default { plannedDate: { type: "string", label: "Planned Date", - description: "The planned date for the transaction, in the format `YYYY-MM-DD` (e.g. `2025-01-01`"), + description: "The planned date for the transaction, in the format `YYYY-MM-DD` (e.g. `2025-01-01`)", }, isPaid: { type: "boolean",