Skip to content

Commit ffb4497

Browse files
committed
new components
1 parent c40e92e commit ffb4497

File tree

12 files changed

+770
-7
lines changed

12 files changed

+770
-7
lines changed
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
import returnless from "../../returnless.app.mjs";
2+
import { parseObject } from "../../common/utils.mjs";
3+
4+
export default {
5+
key: "returnless-create-return-order",
6+
name: "Create Return Order",
7+
description: "Create a return order. [See the documentation](https://docs.returnless.com/docs/api-rest-reference/1fce50b07484b-creates-a-return-order-from-a-return-order-intent)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
returnless,
12+
formId: {
13+
propDefinition: [
14+
returnless,
15+
"formId",
16+
],
17+
},
18+
locale: {
19+
type: "string",
20+
label: "Locale",
21+
description: "The locale of the form to create the return-order intent for",
22+
},
23+
input: {
24+
type: "string",
25+
label: "Input",
26+
description: "The input for the order. This could be an email address or postalcode or something else.",
27+
},
28+
orderId: {
29+
propDefinition: [
30+
returnless,
31+
"orderId",
32+
],
33+
},
34+
customerHouseNumber: {
35+
type: "string",
36+
label: "Customer House Number",
37+
description: "The house number of the customer",
38+
},
39+
customerStreet: {
40+
type: "string",
41+
label: "Customer Street",
42+
description: "The street of the customer",
43+
},
44+
customerPostalCode: {
45+
type: "string",
46+
label: "Customer Postal Code",
47+
description: "The postal code of the customer",
48+
},
49+
customerCity: {
50+
type: "string",
51+
label: "Customer City",
52+
description: "The city of the customer",
53+
},
54+
customerCountryId: {
55+
propDefinition: [
56+
returnless,
57+
"countryId",
58+
],
59+
},
60+
itemIds: {
61+
propDefinition: [
62+
returnless,
63+
"itemIds",
64+
(c) => ({
65+
orderId: c.orderId,
66+
}),
67+
],
68+
reloadProps: true,
69+
},
70+
metadata: {
71+
type: "object",
72+
label: "Metadata",
73+
description: "Metadata key/value pairs to add to the return order",
74+
optional: true,
75+
},
76+
},
77+
async additionalProps() {
78+
const props = {};
79+
if (!this.itemIds) {
80+
return props;
81+
}
82+
const { data: items } = await this.returnless.listSalesOrderItems({
83+
orderId: this.orderId,
84+
});
85+
for (const item of items) {
86+
props[`item${item.id}Quantity`] = {
87+
type: "string",
88+
label: `Item ${item.id} Quantity`,
89+
description: `The quantity of item ${item.id} to return`,
90+
};
91+
props[`item${item.id}ReturnReasonId`] = {
92+
type: "string",
93+
label: `Item ${item.id} Return Reason ID`,
94+
description: `The return reason for item ${item.id}`,
95+
options: async () => {
96+
const { data: returnReasons } = await this.returnless.listReturnReasons();
97+
return returnReasons.map(({
98+
id, label,
99+
}) => ({
100+
value: id,
101+
label,
102+
}));
103+
},
104+
};
105+
}
106+
return props;
107+
},
108+
async run({ $ }) {
109+
const { data: order } = await this.returnless.getOrder({
110+
$,
111+
orderId: this.orderId,
112+
});
113+
114+
const { data: intent } = await this.returnless.createReturnOrderIntent({
115+
$,
116+
data: {
117+
form_id: this.formId,
118+
locale: this.locale,
119+
input: this.input,
120+
order_number: order.order_number,
121+
},
122+
});
123+
124+
const { data: returnOrder } = await this.returnless.createReturnOrder({
125+
$,
126+
data: {
127+
return_order_intent_id: intent.id,
128+
customer: {
129+
house_number: this.customerHouseNumber,
130+
street: this.customerStreet,
131+
postal_code: this.customerPostalCode,
132+
city: this.customerCity,
133+
country_id: this.customerCountryId,
134+
},
135+
items: this.itemIds.map((itemId) => ({
136+
id: itemId,
137+
quantity: this[`item${itemId}Quantity`],
138+
return_reason_id: this[`item${itemId}ReturnReasonId`],
139+
})),
140+
metadata: parseObject(this.metadata),
141+
},
142+
});
143+
144+
$.export("$summary", `Return order created: ${returnOrder.id}`);
145+
return returnOrder;
146+
},
147+
};
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import returnless from "../../returnless.app.mjs";
2+
3+
export default {
4+
key: "returnless-list-return-orders",
5+
name: "List Return Orders",
6+
description: "Retrieve a list of return orders. [See the documentation](https://docs.returnless.com/docs/api-rest-reference/0640e3c064cdc-list-all-return-orders)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
returnless,
11+
returnType: {
12+
type: "string",
13+
label: "Return Type",
14+
description: "The type of return orders to retrieve",
15+
options: [
16+
"request",
17+
"return",
18+
],
19+
},
20+
createdAfter: {
21+
type: "string",
22+
label: "Created After",
23+
description: "Only return return-orders that were created after the given date",
24+
optional: true,
25+
},
26+
createdBefore: {
27+
type: "string",
28+
label: "Created Before",
29+
description: "Only return return-orders that were created before the given date",
30+
optional: true,
31+
},
32+
maxResults: {
33+
propDefinition: [
34+
returnless,
35+
"maxResults",
36+
],
37+
},
38+
},
39+
async run({ $ }) {
40+
const returnOrders = await this.returnless.getPaginatedResources({
41+
fn: this.returnless.listReturnOrders,
42+
args: {
43+
$,
44+
params: {
45+
filter: {
46+
return_type: this.returnType,
47+
created_at: {
48+
gt: this.createdAfter,
49+
lt: this.createdBefore,
50+
},
51+
},
52+
sort: "-created_at",
53+
},
54+
},
55+
max: this.maxResults,
56+
});
57+
58+
$.export("$summary", `Found ${returnOrders.length} return order${returnOrders.length === 1
59+
? ""
60+
: "s"}`);
61+
return returnOrders;
62+
},
63+
};
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import returnless from "../../returnless.app.mjs";
2+
3+
export default {
4+
key: "returnless-list-sales-orders",
5+
name: "List Sales Orders",
6+
description: "Retrieve a list of sales orders sorted by creation date, with the most recent sales orders appearing first. [See the documentation](https://docs.returnless.com/docs/api-rest-reference/ce6a0e3d66378-list-all-sales-orders)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
returnless,
11+
maxResults: {
12+
propDefinition: [
13+
returnless,
14+
"maxResults",
15+
],
16+
},
17+
},
18+
async run({ $ }) {
19+
const salesOrders = await this.returnless.getPaginatedResources({
20+
fn: this.returnless.listSalesOrders,
21+
args: {
22+
$,
23+
},
24+
max: this.maxResults,
25+
});
26+
27+
$.export("$summary", `Found ${salesOrders.length} sales order${salesOrders.length === 1
28+
? ""
29+
: "s"}`);
30+
return salesOrders;
31+
},
32+
};
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import returnless from "../../returnless.app.mjs";
2+
3+
export default {
4+
key: "returnless-update-return-order-status",
5+
name: "Update Return Order Status",
6+
description: "Update the status of a return order. [See the documentation](https://docs.returnless.com/docs/api-rest-reference/1d07e272437a4-update-a-return-order-status)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
returnless,
11+
returnOrderId: {
12+
propDefinition: [
13+
returnless,
14+
"returnOrderId",
15+
],
16+
},
17+
returnStatusId: {
18+
propDefinition: [
19+
returnless,
20+
"returnStatusId",
21+
],
22+
},
23+
},
24+
async run({ $ }) {
25+
const { data } = await this.returnless.updateReturnOrderStatus({
26+
$,
27+
returnOrderId: this.returnOrderId,
28+
data: {
29+
status_id: this.returnStatusId,
30+
},
31+
});
32+
33+
$.export("$summary", `Return Order Status Updated: ${data.id}`);
34+
return data;
35+
},
36+
};
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
export const parseObject = (obj) => {
2+
if (!obj) {
3+
return undefined;
4+
}
5+
if (typeof obj === "string") {
6+
try {
7+
return JSON.parse(obj);
8+
} catch (e) {
9+
return obj;
10+
}
11+
}
12+
if (Array.isArray(obj)) {
13+
return obj.map(parseObject);
14+
}
15+
if (typeof obj === "object") {
16+
return Object.fromEntries(
17+
Object.entries(obj).map(([
18+
key,
19+
value,
20+
]) => [
21+
key,
22+
parseObject(value),
23+
]),
24+
);
25+
}
26+
return obj;
27+
};

components/returnless/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/returnless",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream Returnless Components",
55
"main": "returnless.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.1.0"
1417
}
15-
}
18+
}

0 commit comments

Comments
 (0)