Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 107 additions & 0 deletions components/rewiser/actions/create-transaction/create-transaction.mjs
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;
},
};
25 changes: 25 additions & 0 deletions components/rewiser/common/utils.mjs
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";
}
};
7 changes: 5 additions & 2 deletions components/rewiser/package.json
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": [
Expand All @@ -11,5 +11,8 @@
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.1.0"
}
}
}
59 changes: 55 additions & 4 deletions components/rewiser/rewiser.app.mjs
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 components/rewiser/sources/new-transaction/new-transaction.mjs
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",
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: {

Check warning on line 21 in components/rewiser/sources/new-transaction/new-transaction.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

Component prop alert must have a description. See https://pipedream.com/docs/components/guidelines/#props

Check warning on line 21 in components/rewiser/sources/new-transaction/new-transaction.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

Component prop alert must have a label. See https://pipedream.com/docs/components/guidelines/#props
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 components/rewiser/sources/new-transaction/test-event.mjs
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",
};
14 changes: 9 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading