Skip to content

Commit be99e3c

Browse files
authored
New Components - storeganise (#13783)
* storeganise init * new components * removing actions due to lack of permissions * pnpm-lock.yaml * updates, actions * add doc link * remove console.log
1 parent 5daee28 commit be99e3c

File tree

12 files changed

+3160
-8
lines changed

12 files changed

+3160
-8
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import storeganise from "../../storeganise.app.mjs";
2+
3+
export default {
4+
key: "storeganise-add-invoice-payment",
5+
name: "Add Invoice Payment",
6+
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)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
storeganise,
11+
invoiceId: {
12+
propDefinition: [
13+
storeganise,
14+
"invoiceId",
15+
],
16+
},
17+
amount: {
18+
type: "string",
19+
label: "Amount",
20+
description: "The payment amount",
21+
},
22+
method: {
23+
type: "string",
24+
label: "Method",
25+
description: "The payment method",
26+
options: [
27+
"cash",
28+
"card",
29+
"cheque",
30+
"transfer",
31+
"other",
32+
],
33+
},
34+
paymentDate: {
35+
type: "string",
36+
label: "Payment Date",
37+
description: "The date of the payment in YYYY-MM-DD format (e.g., `2018-02-18`)",
38+
},
39+
note: {
40+
type: "string",
41+
label: "Note",
42+
description: "The content of the note",
43+
optional: true,
44+
},
45+
},
46+
async run({ $ }) {
47+
const response = await this.storeganise.addPaymentToInvoice({
48+
$,
49+
invoiceId: this.invoiceId,
50+
data: {
51+
type: "manual",
52+
amount: this.amount,
53+
method: this.method,
54+
date: this.paymentDate,
55+
notes: this.note,
56+
},
57+
});
58+
$.export("$summary", `Successfully added payment to invoice ${this.invoiceId}`);
59+
return response;
60+
},
61+
};
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import storeganise from "../../storeganise.app.mjs";
2+
3+
export default {
4+
key: "storeganise-mark-invoice-paid",
5+
name: "Mark Invoice as Paid",
6+
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)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
storeganise,
11+
invoiceId: {
12+
propDefinition: [
13+
storeganise,
14+
"invoiceId",
15+
],
16+
},
17+
},
18+
async run({ $ }) {
19+
const response = await this.storeganise.updateInvoice({
20+
$,
21+
invoiceId: this.invoiceId,
22+
data: {
23+
state: "paid",
24+
},
25+
});
26+
$.export("$summary", `Invoice ${this.invoiceId} was marked as paid successfully`);
27+
return response;
28+
},
29+
};

components/storeganise/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/storeganise",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream Storeganise Components",
55
"main": "storeganise.app.mjs",
66
"keywords": [
@@ -11,5 +11,8 @@
1111
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.0.1"
1417
}
15-
}
18+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import storeganise from "../../storeganise.app.mjs";
2+
import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";
3+
4+
export default {
5+
props: {
6+
storeganise,
7+
db: "$.service.db",
8+
timer: {
9+
type: "$.interface.timer",
10+
default: {
11+
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
12+
},
13+
},
14+
},
15+
hooks: {
16+
async deploy() {
17+
await this.processEvent(25);
18+
},
19+
},
20+
methods: {
21+
_getLastCreated() {
22+
return this.db.get("lastCreated");
23+
},
24+
_setLastCreated(lastCreated) {
25+
this.db.set("lastCreated", lastCreated);
26+
},
27+
getParams() {
28+
return {};
29+
},
30+
getResourceFn() {
31+
throw new Error("getResourceFn is not implemented");
32+
},
33+
generateMeta() {
34+
throw new Error("generateMeta is not implemented");
35+
},
36+
async processEvent(max) {
37+
const lastCreated = this._getLastCreated();
38+
let maxCreated = lastCreated;
39+
const resourceFn = this.getResourceFn();
40+
const params = {
41+
...this.getParams(lastCreated),
42+
limit: max || 50,
43+
offset: 0,
44+
};
45+
let total, done, count = 0;
46+
47+
do {
48+
const items = await resourceFn({
49+
params,
50+
});
51+
total = items?.length;
52+
if (!total) {
53+
break;
54+
}
55+
for (const item of items) {
56+
if (!lastCreated || (Date.parse(item.created) >= Date.parse(lastCreated))) {
57+
const meta = this.generateMeta(item);
58+
this.$emit(item, meta);
59+
if (!maxCreated || (Date.parse(item.created) > Date.parse(maxCreated))) {
60+
maxCreated = item.created;
61+
}
62+
count++;
63+
if (max && count >= max) {
64+
done = true;
65+
break;
66+
}
67+
}
68+
}
69+
params.offset += params.limit;
70+
} while (total === params.limit && !done);
71+
72+
this._setLastCreated(maxCreated);
73+
},
74+
},
75+
async run() {
76+
await this.processEvent();
77+
},
78+
};
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import common from "../common/base.mjs";
2+
import sampleEmit from "./test-event.mjs";
3+
4+
export default {
5+
...common,
6+
key: "storeganise-new-invoice-created",
7+
name: "New Invoice Created",
8+
description: "Emit new event when a new invoice is created in Storeganise.",
9+
version: "0.0.1",
10+
type: "source",
11+
dedupe: "unique",
12+
methods: {
13+
...common.methods,
14+
getResourceFn() {
15+
return this.storeganise.listInvoices;
16+
},
17+
getParams(lastCreated) {
18+
return {
19+
include: [
20+
"billing",
21+
"customFields",
22+
],
23+
updatedAfter: lastCreated,
24+
};
25+
},
26+
generateMeta(invoice) {
27+
return {
28+
id: invoice.id,
29+
summary: `New Invoice Created: ${invoice.id}`,
30+
ts: Date.parse(invoice.created),
31+
};
32+
},
33+
},
34+
sampleEmit,
35+
};
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
export default {
2+
"created": "2024-09-04T06:43:39.749Z",
3+
"creditApplied": 0,
4+
"endDate": "2024-11-01",
5+
"id": "66d8019b88e79a0015dc969d",
6+
"items": [],
7+
"owner": {
8+
"id": "66ce753e7405aa00158ba554",
9+
"name": "Homer Simpson"
10+
},
11+
"payments": [],
12+
"sid": "cen000041",
13+
"sent": "2024-09-04T06:43:39.984Z",
14+
"siteId": "66ce753e7405aa00158ba679",
15+
"unitRentalId": "66d8019b88e79a0015dc9677",
16+
"startDate": "2024-10-01",
17+
"state": "sent",
18+
"tags": [
19+
"moveIn",
20+
"month"
21+
],
22+
"taxPercent": 20,
23+
"type": "unit",
24+
"labels": [],
25+
"updated": "2024-09-04T06:43:39.985Z",
26+
"entries": [
27+
{
28+
"id": "66d8019b88e79a0015dc96a2",
29+
"desc": "Deposit",
30+
"date": "2024-09-04",
31+
"code": "deposit",
32+
"created": "2024-09-04T06:43:39.769Z",
33+
"tags": [
34+
"deposit"
35+
],
36+
"amount": 99,
37+
"qty": 1,
38+
"subtotal": 99,
39+
"tax": 0,
40+
"total": 99,
41+
"type": "deposit"
42+
},
43+
{
44+
"id": "66d8019b88e79a0015dc96a3",
45+
"desc": "Prorated rent",
46+
"date": "2024-09-04",
47+
"endDate": "2024-10-01",
48+
"code": "rent",
49+
"created": "2024-09-04T06:43:39.769Z",
50+
"tags": [
51+
"rent",
52+
"prorated"
53+
],
54+
"amount": 87.75,
55+
"qty": 1,
56+
"subtotal": 87.75,
57+
"taxPct": 20,
58+
"tax": 17.55,
59+
"total": 105.3,
60+
"type": "revenue"
61+
},
62+
{
63+
"id": "66d8019b88e79a0015dc96a4",
64+
"desc": "Rent",
65+
"date": "2024-10-01",
66+
"endDate": "2024-11-01",
67+
"code": "rent",
68+
"created": "2024-09-04T06:43:39.769Z",
69+
"tags": [
70+
"rent"
71+
],
72+
"amount": 99,
73+
"qty": 1,
74+
"subtotal": 99,
75+
"taxPct": 20,
76+
"tax": 19.8,
77+
"total": 118.8,
78+
"type": "revenue"
79+
},
80+
{
81+
"id": "66d8019b88e79a0015dc96a5",
82+
"desc": "Admin fee",
83+
"date": "2024-10-01",
84+
"code": "products",
85+
"created": "2024-09-04T06:43:39.769Z",
86+
"tags": [
87+
"charge"
88+
],
89+
"amount": 10,
90+
"qty": 1,
91+
"subtotal": 10,
92+
"taxPct": 10,
93+
"tax": 1,
94+
"total": 11,
95+
"type": "revenue"
96+
}
97+
],
98+
"subtotal": 295.75,
99+
"tax": 38.35,
100+
"total": 334.1,
101+
"amountPaid": 0,
102+
"balance": 334.1,
103+
"customFields": {},
104+
"billing": null
105+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import common from "../common/base.mjs";
2+
import sampleEmit from "./test-event.mjs";
3+
4+
export default {
5+
...common,
6+
key: "storeganise-new-unit-rental-created",
7+
name: "New Unit Rental Created",
8+
description: "Emit new event when a unit rental is created in Storeganise",
9+
version: "0.0.1",
10+
type: "source",
11+
dedupe: "unique",
12+
methods: {
13+
...common.methods,
14+
getResourceFn() {
15+
return this.storeganise.listUnitRentals;
16+
},
17+
getParams(lastCreated) {
18+
return {
19+
include: [
20+
"unit",
21+
"owner",
22+
"agreementUrl",
23+
"customFields",
24+
],
25+
updatedAfter: lastCreated,
26+
};
27+
},
28+
generateMeta(unitRental) {
29+
return {
30+
id: unitRental.id,
31+
summary: `New Unit Rental Created: ${unitRental.id}`,
32+
ts: Date.parse(unitRental.created),
33+
};
34+
},
35+
},
36+
sampleEmit,
37+
};

0 commit comments

Comments
 (0)