-
Notifications
You must be signed in to change notification settings - Fork 5.5k
17699 components rewiser #17771
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
17699 components rewiser #17771
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6eab05d
[Components] Rewiser #17699
luancazarine 8bcedcb
pnpm update
luancazarine 48a397d
Update components/rewiser/actions/create-transaction/create-transacti…
luancazarine 94a1e4c
Add new source for Rewiser: New Transaction Created
luancazarine fe86261
Update components/rewiser/actions/create-transaction/create-transacti…
luancazarine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
107 changes: 107 additions & 0 deletions
107
components/rewiser/actions/create-transaction/create-transaction.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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; | ||
| }, | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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"; | ||
| } | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 <[email protected]> (https://pipedream.com/)", | ||
| "publishConfig": { | ||
| "access": "public" | ||
| }, | ||
| "dependencies": { | ||
| "@pipedream/platform": "^3.1.0" | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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, | ||
| }); | ||
| }, | ||
| }, | ||
| }; |
60 changes: 60 additions & 0 deletions
60
components/rewiser/sources/new-transaction-created/new-transaction-created.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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: { | ||
|
Check warning on line 21 in components/rewiser/sources/new-transaction-created/new-transaction-created.mjs
|
||
| 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, | ||
| }; | ||
11 changes: 11 additions & 0 deletions
11
components/rewiser/sources/new-transaction-created/test-event.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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", | ||
| }; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.