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..dff87dabd7a95 --- /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, in the 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-created/new-transaction-created.mjs b/components/rewiser/sources/new-transaction-created/new-transaction-created.mjs new file mode 100644 index 0000000000000..6547051c1d75f --- /dev/null +++ b/components/rewiser/sources/new-transaction-created/new-transaction-created.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-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", + 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-created/test-event.mjs b/components/rewiser/sources/new-transaction-created/test-event.mjs new file mode 100644 index 0000000000000..8ff20a9751629 --- /dev/null +++ b/components/rewiser/sources/new-transaction-created/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 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==}