Skip to content

Commit 193253f

Browse files
authored
[APP] implement new tool for sevdesk - findInvoice, getInvoice (#17830)
1 parent 2138df9 commit 193253f

File tree

12 files changed

+171
-10
lines changed

12 files changed

+171
-10
lines changed

components/sevdesk/actions/cancel-invoice/cancel-invoice.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default {
55
key: "sevdesk-cancel-invoice",
66
name: "Cancel Invoice",
77
description: "Cancels an existing invoice in sevDesk. [See the documentation](https://api.sevdesk.de/#tag/Invoice/operation/cancelInvoice)",
8-
version: "0.0.1",
8+
version: "0.0.2",
99
type: "action",
1010
props: {
1111
sevdesk,

components/sevdesk/actions/create-contact/create-contact.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default {
55
key: "sevdesk-create-contact",
66
name: "Create Contact",
77
description: "Create a new contact. [See the documentation](https://api.sevdesk.de/#tag/Contact/operation/createContact)",
8-
version: "0.0.1",
8+
version: "0.0.2",
99
type: "action",
1010
props: {
1111
sevdesk,

components/sevdesk/actions/create-invoice/create-invoice.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export default {
1212
key: "sevdesk-create-invoice",
1313
name: "Create Invoice",
1414
description: "Creates a new invoice with optional details like invoice date, due date, discount amount, and invoice items. [See the documentation](https://api.sevdesk.de/)",
15-
version: "0.0.1",
15+
version: "0.0.2",
1616
type: "action",
1717
props: {
1818
sevdesk,
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import app from "../../sevdesk.app.mjs";
2+
3+
export default {
4+
key: "sevdesk-get-invoice",
5+
name: "Get Invoice",
6+
description: "Find and retrieve a single invoice by its ID. [See the documentation](https://api.sevdesk.de/#tag/Invoice/operation/getInvoiceById)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
invoiceId: {
12+
propDefinition: [
13+
app,
14+
"invoiceId",
15+
],
16+
description: "ID of the invoice to retrieve",
17+
},
18+
},
19+
async run({ $ }) {
20+
const {
21+
app,
22+
invoiceId,
23+
} = this;
24+
25+
const response = await app.getInvoice({
26+
$,
27+
invoiceId,
28+
});
29+
30+
$.export("$summary", `Successfully retrieved invoice with ID ${invoiceId}`);
31+
return response;
32+
},
33+
};
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
import app from "../../sevdesk.app.mjs";
2+
3+
export default {
4+
key: "sevdesk-get-invoices",
5+
name: "Get Invoices",
6+
description: "Retrieve invoices with optional filtering by status, invoice number, date range, and contact. [See the documentation](https://api.sevdesk.de/#tag/Invoice/operation/getInvoices)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
status: {
12+
type: "string",
13+
label: "Status",
14+
description: "Status of the invoices to filter by",
15+
options: [
16+
{
17+
label: "Draft",
18+
value: "100",
19+
},
20+
{
21+
label: "Open",
22+
value: "200",
23+
},
24+
{
25+
label: "Paid",
26+
value: "1000",
27+
},
28+
],
29+
optional: true,
30+
},
31+
invoiceNumber: {
32+
type: "string",
33+
label: "Invoice Number",
34+
description: "Retrieve all invoices with this invoice number",
35+
optional: true,
36+
},
37+
startDate: {
38+
type: "string",
39+
label: "Start Date",
40+
description: "Retrieve all invoices with a date equal or higher (ISO 8601 format: YYYY-MM-DD or YYYY-MM-DDTHH:MM:SS)",
41+
optional: true,
42+
},
43+
endDate: {
44+
type: "string",
45+
label: "End Date",
46+
description: "Retrieve all invoices with a date equal or lower (ISO 8601 format: YYYY-MM-DD or YYYY-MM-DDTHH:MM:SS)",
47+
optional: true,
48+
},
49+
contactId: {
50+
propDefinition: [
51+
app,
52+
"contactId",
53+
],
54+
optional: true,
55+
},
56+
limit: {
57+
type: "integer",
58+
label: "Limit",
59+
description: "Maximum number of invoices to retrieve",
60+
optional: true,
61+
min: 1,
62+
max: 999,
63+
},
64+
},
65+
methods: {
66+
convertDateToTimestamp(dateString) {
67+
if (!dateString) return undefined;
68+
69+
const date = new Date(dateString);
70+
if (isNaN(date.getTime())) {
71+
throw new Error(`Invalid date format: ${dateString}. Please use ISO 8601 format (YYYY-MM-DD or YYYY-MM-DDTHH:MM:SS)`);
72+
}
73+
74+
return Math.floor(date.getTime() / 1000);
75+
},
76+
},
77+
async run({ $ }) {
78+
const {
79+
app,
80+
status,
81+
invoiceNumber,
82+
startDate,
83+
endDate,
84+
contactId,
85+
limit,
86+
} = this;
87+
88+
let startTimestamp, endTimestamp;
89+
90+
try {
91+
startTimestamp = this.convertDateToTimestamp(startDate);
92+
endTimestamp = this.convertDateToTimestamp(endDate);
93+
} catch (error) {
94+
throw new Error(`Date validation error: ${error.message}`);
95+
}
96+
97+
if (startTimestamp && endTimestamp && startTimestamp > endTimestamp) {
98+
throw new Error("Start date cannot be later than end date");
99+
}
100+
101+
const response = await app.listInvoices({
102+
$,
103+
params: {
104+
status,
105+
invoiceNumber,
106+
startDate: startTimestamp,
107+
endDate: endTimestamp,
108+
...(contactId
109+
? {
110+
"contact[id]": contactId,
111+
"contact[objectName]": "Contact",
112+
}
113+
: {}
114+
),
115+
limit,
116+
},
117+
});
118+
119+
$.export("$summary", `Successfully retrieved ${response.objects?.length || 0} invoice(s)`);
120+
return response;
121+
},
122+
};

components/sevdesk/actions/send-invoice-email/send-invoice-email.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default {
55
key: "sevdesk-send-invoice-email",
66
name: "Send Invoice Email",
77
description: "Sends an invoice via email. [See the documentation](https://api.sevdesk.de/#tag/Invoice/operation/sendInvoiceViaEMail)",
8-
version: "0.0.1",
8+
version: "0.0.2",
99
type: "action",
1010
props: {
1111
sevdesk,

components/sevdesk/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/sevdesk",
3-
"version": "0.2.0",
3+
"version": "0.3.0",
44
"description": "Pipedream sevDesk Components",
55
"main": "sevdesk.app.mjs",
66
"keywords": [

components/sevdesk/sevdesk.app.mjs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,14 @@ export default {
159159
...opts,
160160
});
161161
},
162+
getInvoice({
163+
invoiceId, ...opts
164+
}) {
165+
return this._makeRequest({
166+
path: `/Invoice/${invoiceId}`,
167+
...opts,
168+
});
169+
},
162170
listOrders(opts = {}) {
163171
return this._makeRequest({
164172
path: "/Order",

components/sevdesk/sources/new-contact/new-contact.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default {
66
key: "sevdesk-new-contact",
77
name: "New Contact Created",
88
description: "Emit new event when a contact is created in SevDesk.",
9-
version: "0.0.1",
9+
version: "0.0.2",
1010
type: "source",
1111
dedupe: "unique",
1212
methods: {

components/sevdesk/sources/new-order/new-order.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default {
66
key: "sevdesk-new-order",
77
name: "New Order Created",
88
description: "Emit new event for each new order created in SevDesk.",
9-
version: "0.0.1",
9+
version: "0.0.2",
1010
type: "source",
1111
dedupe: "unique",
1212
methods: {

0 commit comments

Comments
 (0)