Skip to content
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

New Components - storeganise #13783

Merged
merged 8 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import storeganise from "../../storeganise.app.mjs";

export default {
key: "storeganise-add-invoice-payment",
name: "Add Invoice Payment",
description: "Adds a payment to the targeted invoice. [See the documentation](https://pipedream-dev-trial.storeganise.com/api/docs/admin/invoices#admin_invoices._invoiceId_payments)",
version: "0.0.1",
type: "action",
props: {
storeganise,
invoiceId: {
propDefinition: [
storeganise,
"invoiceId",
],
},
amount: {
type: "string",
label: "Amount",
description: "The payment amount",
},
method: {
type: "string",
label: "Method",
description: "The payment method",
options: [
"cash",
"card",
"cheque",
"transfer",
"other",
],
},
paymentDate: {
type: "string",
label: "Payment Date",
description: "The date of the payment in YYYY-MM-DD format (e.g., `2018-02-18`)",
},
note: {
type: "string",
label: "Note",
description: "The content of the note",
optional: true,
},
},
async run({ $ }) {
const response = await this.storeganise.addPaymentToInvoice({
$,
invoiceId: this.invoiceId,
data: {
type: "manual",
amount: this.amount,
method: this.method,
date: this.paymentDate,
notes: this.note,
},
});
$.export("$summary", `Successfully added payment to invoice ${this.invoiceId}`);
return response;
},
michelle0927 marked this conversation as resolved.
Show resolved Hide resolved
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import storeganise from "../../storeganise.app.mjs";

export default {
key: "storeganise-mark-invoice-paid",
name: "Mark Invoice as Paid",
description: "Marks the selected invoice as paid in Storeganise. [See the documentation](https://pipedream-dev-trial.storeganise.com/api/docs/admin/invoices#admin_invoices.PUT_invoiceId)",
version: "0.0.1",
type: "action",
props: {
storeganise,
invoiceId: {
propDefinition: [
storeganise,
"invoiceId",
],
},
},
async run({ $ }) {
const response = await this.storeganise.updateInvoice({
$,
invoiceId: this.invoiceId,
data: {
state: "paid",
},
});
$.export("$summary", `Invoice ${this.invoiceId} was marked as paid successfully`);
return response;
},
};
7 changes: 5 additions & 2 deletions components/storeganise/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/storeganise",
"version": "0.0.1",
"version": "0.1.0",
"description": "Pipedream Storeganise Components",
"main": "storeganise.app.mjs",
"keywords": [
Expand All @@ -11,5 +11,8 @@
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.0.1"
}
}
}
78 changes: 78 additions & 0 deletions components/storeganise/sources/common/base.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import storeganise from "../../storeganise.app.mjs";
import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";

export default {
props: {
storeganise,
db: "$.service.db",
timer: {
type: "$.interface.timer",
default: {
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
},
},
},
hooks: {
async deploy() {
await this.processEvent(25);
},
},
methods: {
_getLastCreated() {
return this.db.get("lastCreated");
},
_setLastCreated(lastCreated) {
this.db.set("lastCreated", lastCreated);
},
getParams() {
return {};
},
getResourceFn() {
throw new Error("getResourceFn is not implemented");
},
generateMeta() {
throw new Error("generateMeta is not implemented");
},
async processEvent(max) {
const lastCreated = this._getLastCreated();
let maxCreated = lastCreated;
const resourceFn = this.getResourceFn();
const params = {
...this.getParams(lastCreated),
limit: max || 50,
offset: 0,
};
let total, done, count = 0;

do {
const items = await resourceFn({
params,
});
total = items?.length;
if (!total) {
break;
}
for (const item of items) {
if (!lastCreated || (Date.parse(item.created) >= Date.parse(lastCreated))) {
const meta = this.generateMeta(item);
this.$emit(item, meta);
if (!maxCreated || (Date.parse(item.created) > Date.parse(maxCreated))) {
maxCreated = item.created;
}
count++;
if (max && count >= max) {
done = true;
break;
}
}
}
params.offset += params.limit;
} while (total === params.limit && !done);

this._setLastCreated(maxCreated);
},
michelle0927 marked this conversation as resolved.
Show resolved Hide resolved
},
async run() {
await this.processEvent();
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import common from "../common/base.mjs";
import sampleEmit from "./test-event.mjs";

export default {
...common,
key: "storeganise-new-invoice-created",
name: "New Invoice Created",
description: "Emit new event when a new invoice is created in Storeganise.",
version: "0.0.1",
type: "source",
dedupe: "unique",
methods: {
...common.methods,
getResourceFn() {
return this.storeganise.listInvoices;
},
getParams(lastCreated) {
return {
include: [
"billing",
"customFields",
],
updatedAfter: lastCreated,
};
},
generateMeta(invoice) {
return {
id: invoice.id,
summary: `New Invoice Created: ${invoice.id}`,
ts: Date.parse(invoice.created),
};
},
},
sampleEmit,
};
105 changes: 105 additions & 0 deletions components/storeganise/sources/new-invoice-created/test-event.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
export default {
"created": "2024-09-04T06:43:39.749Z",
"creditApplied": 0,
"endDate": "2024-11-01",
"id": "66d8019b88e79a0015dc969d",
"items": [],
"owner": {
"id": "66ce753e7405aa00158ba554",
"name": "Homer Simpson"
},
"payments": [],
"sid": "cen000041",
"sent": "2024-09-04T06:43:39.984Z",
"siteId": "66ce753e7405aa00158ba679",
"unitRentalId": "66d8019b88e79a0015dc9677",
"startDate": "2024-10-01",
"state": "sent",
"tags": [
"moveIn",
"month"
],
"taxPercent": 20,
"type": "unit",
"labels": [],
"updated": "2024-09-04T06:43:39.985Z",
"entries": [
{
"id": "66d8019b88e79a0015dc96a2",
"desc": "Deposit",
"date": "2024-09-04",
"code": "deposit",
"created": "2024-09-04T06:43:39.769Z",
"tags": [
"deposit"
],
"amount": 99,
"qty": 1,
"subtotal": 99,
"tax": 0,
"total": 99,
"type": "deposit"
},
{
"id": "66d8019b88e79a0015dc96a3",
"desc": "Prorated rent",
"date": "2024-09-04",
"endDate": "2024-10-01",
"code": "rent",
"created": "2024-09-04T06:43:39.769Z",
"tags": [
"rent",
"prorated"
],
"amount": 87.75,
"qty": 1,
"subtotal": 87.75,
"taxPct": 20,
"tax": 17.55,
"total": 105.3,
"type": "revenue"
},
{
"id": "66d8019b88e79a0015dc96a4",
"desc": "Rent",
"date": "2024-10-01",
"endDate": "2024-11-01",
"code": "rent",
"created": "2024-09-04T06:43:39.769Z",
"tags": [
"rent"
],
"amount": 99,
"qty": 1,
"subtotal": 99,
"taxPct": 20,
"tax": 19.8,
"total": 118.8,
"type": "revenue"
},
{
"id": "66d8019b88e79a0015dc96a5",
"desc": "Admin fee",
"date": "2024-10-01",
"code": "products",
"created": "2024-09-04T06:43:39.769Z",
"tags": [
"charge"
],
"amount": 10,
"qty": 1,
"subtotal": 10,
"taxPct": 10,
"tax": 1,
"total": 11,
"type": "revenue"
}
],
"subtotal": 295.75,
"tax": 38.35,
"total": 334.1,
"amountPaid": 0,
"balance": 334.1,
"customFields": {},
"billing": null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import common from "../common/base.mjs";
import sampleEmit from "./test-event.mjs";

export default {
...common,
key: "storeganise-new-unit-rental-created",
name: "New Unit Rental Created",
description: "Emit new event when a unit rental is created in Storeganise",
version: "0.0.1",
type: "source",
dedupe: "unique",
methods: {
...common.methods,
getResourceFn() {
return this.storeganise.listUnitRentals;
},
getParams(lastCreated) {
return {
include: [
"unit",
"owner",
"agreementUrl",
"customFields",
],
updatedAfter: lastCreated,
};
},
generateMeta(unitRental) {
return {
id: unitRental.id,
summary: `New Unit Rental Created: ${unitRental.id}`,
ts: Date.parse(unitRental.created),
};
},
},
sampleEmit,
};
Loading
Loading