Skip to content

Commit 92daa9f

Browse files
authored
Monta - new components (#18985)
* new components * pnpm-lock.yaml * fix typo & doc link * pnpm-lock.yaml
1 parent bd60b98 commit 92daa9f

File tree

6 files changed

+267
-91
lines changed

6 files changed

+267
-91
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import monta from "../../monta.app.mjs";
2+
3+
export default {
4+
key: "monta-get-order",
5+
name: "Get Order",
6+
description: "Get an order by ID. [See the documentation](https://api-v6.monta.nl/index.html#tag/Order/paths/~1order~1%7Bwebshoporderid%7D/get)",
7+
version: "0.0.1",
8+
type: "action",
9+
annotations: {
10+
destructiveHint: false,
11+
openWorldHint: true,
12+
readOnlyHint: true,
13+
},
14+
props: {
15+
monta,
16+
orderId: {
17+
propDefinition: [
18+
monta,
19+
"orderId",
20+
],
21+
},
22+
channel: {
23+
type: "string",
24+
label: "Channel",
25+
description: "The channel name if multiple order IDs are available between channels",
26+
optional: true,
27+
},
28+
},
29+
async run({ $ }) {
30+
const response = await this.monta.getOrder({
31+
$,
32+
orderId: this.orderId,
33+
params: {
34+
channel: this.channel,
35+
},
36+
});
37+
38+
$.export("$summary", `Successfully retrieved order with ID \`${this.orderId}\`.`);
39+
40+
return response;
41+
},
42+
};
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import monta from "../../monta.app.mjs";
2+
3+
export default {
4+
key: "monta-get-return",
5+
name: "Get Return",
6+
description: "Get a return by ID. [See the documentation](https://api-v6.monta.nl/index.html#tag/Return/paths/~1return~1%7Bid%7D/get)",
7+
version: "0.0.1",
8+
type: "action",
9+
annotations: {
10+
destructiveHint: false,
11+
openWorldHint: true,
12+
readOnlyHint: true,
13+
},
14+
props: {
15+
monta,
16+
orderId: {
17+
propDefinition: [
18+
monta,
19+
"orderId",
20+
],
21+
},
22+
returnId: {
23+
propDefinition: [
24+
monta,
25+
"returnId",
26+
({ orderId }) => ({
27+
orderId,
28+
}),
29+
],
30+
},
31+
},
32+
async run({ $ }) {
33+
const response = await this.monta.getReturn({
34+
$,
35+
returnId: this.returnId,
36+
});
37+
38+
$.export("$summary", `Successfully retrieved return with ID \`${this.returnId}\`.`);
39+
return response;
40+
},
41+
};
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import monta from "../../monta.app.mjs";
2+
3+
export default {
4+
key: "monta-list-order-events",
5+
name: "List Order Events",
6+
description: "List order events for an order. [See the documentation](https://api-v6.monta.nl/index.html#tag/Order/paths/~1order~1%7Bwebshoporderid%7D~1events/get)",
7+
version: "0.0.1",
8+
type: "action",
9+
annotations: {
10+
destructiveHint: false,
11+
openWorldHint: true,
12+
readOnlyHint: true,
13+
},
14+
props: {
15+
monta,
16+
orderId: {
17+
propDefinition: [
18+
monta,
19+
"orderId",
20+
],
21+
},
22+
},
23+
async run({ $ }) {
24+
let events = await this.monta.listOrderEvents({
25+
$,
26+
orderId: this.orderId,
27+
});
28+
29+
$.export("$summary", `Successfully retrieved ${events.length} event${events.length === 1
30+
? ""
31+
: "s"}`);
32+
33+
return events;
34+
},
35+
};

components/monta/monta.app.mjs

Lines changed: 87 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,93 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "monta",
4-
propDefinitions: {},
6+
propDefinitions: {
7+
orderId: {
8+
type: "string",
9+
label: "Order ID",
10+
description: "The ID of an order",
11+
async options({ page }) {
12+
const orders = await this.listOrders({
13+
params: {
14+
page,
15+
},
16+
});
17+
return orders.map(({ Id: id }) => ({
18+
label: `Order ID: ${id}`,
19+
value: id,
20+
}));
21+
},
22+
},
23+
returnId: {
24+
type: "string",
25+
label: "Return ID",
26+
description: "The ID of a return",
27+
async options({ orderId }) {
28+
const { Returns: returns } = await this.listReturns({
29+
orderId,
30+
});
31+
return returns.map(({ Id: id }) => ({
32+
label: `Return ID: ${id}`,
33+
value: id,
34+
}));
35+
},
36+
},
37+
},
538
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
39+
_baseUrl() {
40+
return "https://api-v6.monta.nl";
41+
},
42+
_makeRequest({
43+
$ = this, path, ...opts
44+
}) {
45+
return axios($, {
46+
...opts,
47+
url: `${this._baseUrl()}${path}`,
48+
auth: {
49+
username: this.$auth.username,
50+
password: this.$auth.password,
51+
},
52+
});
53+
},
54+
getOrder({
55+
orderId, ...opts
56+
}) {
57+
return this._makeRequest({
58+
path: `/orders/${orderId}`,
59+
...opts,
60+
});
61+
},
62+
getReturn({
63+
returnId, ...opts
64+
}) {
65+
return this._makeRequest({
66+
path: `/returns/${returnId}`,
67+
...opts,
68+
});
69+
},
70+
listOrders(opts = {}) {
71+
return this._makeRequest({
72+
path: "/orders",
73+
...opts,
74+
});
75+
},
76+
listReturns({
77+
orderId, ...opts
78+
}) {
79+
return this._makeRequest({
80+
path: `/order/${orderId}/return`,
81+
...opts,
82+
});
83+
},
84+
listOrderEvents({
85+
orderId, ...opts
86+
}) {
87+
return this._makeRequest({
88+
path: `/order/${orderId}/events`,
89+
...opts,
90+
});
991
},
1092
},
11-
};
93+
};

components/monta/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/monta",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream Monta Components",
55
"main": "monta.app.mjs",
66
"keywords": [
@@ -11,5 +11,8 @@
1111
"author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.1.0"
1417
}
15-
}
18+
}

0 commit comments

Comments
 (0)