Skip to content

Commit 2edcb55

Browse files
authored
New Components - returnless (#17629)
* new components * pnpm-lock.yaml * updates
1 parent 50c8bfe commit 2edcb55

File tree

13 files changed

+790
-7
lines changed

13 files changed

+790
-7
lines changed
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
import returnless from "../../returnless.app.mjs";
2+
import { parseObject } from "../../common/utils.mjs";
3+
import { ConfigurationError } from "@pipedream/platform";
4+
5+
export default {
6+
key: "returnless-create-return-order",
7+
name: "Create Return Order",
8+
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)",
9+
version: "0.0.1",
10+
type: "action",
11+
props: {
12+
returnless,
13+
formId: {
14+
propDefinition: [
15+
returnless,
16+
"formId",
17+
],
18+
},
19+
locale: {
20+
propDefinition: [
21+
returnless,
22+
"locale",
23+
(c) => ({
24+
formId: c.formId,
25+
}),
26+
],
27+
},
28+
input: {
29+
type: "string",
30+
label: "Input",
31+
description: "The input for the order. This could be an email address or postalcode or something else.",
32+
},
33+
orderId: {
34+
propDefinition: [
35+
returnless,
36+
"orderId",
37+
],
38+
},
39+
customerHouseNumber: {
40+
type: "string",
41+
label: "Customer House Number",
42+
description: "The house number of the customer",
43+
},
44+
customerStreet: {
45+
type: "string",
46+
label: "Customer Street",
47+
description: "The street of the customer",
48+
},
49+
customerPostalCode: {
50+
type: "string",
51+
label: "Customer Postal Code",
52+
description: "The postal code of the customer",
53+
},
54+
customerCity: {
55+
type: "string",
56+
label: "Customer City",
57+
description: "The city of the customer",
58+
},
59+
customerCountryId: {
60+
propDefinition: [
61+
returnless,
62+
"countryId",
63+
],
64+
},
65+
itemIds: {
66+
propDefinition: [
67+
returnless,
68+
"itemIds",
69+
(c) => ({
70+
orderId: c.orderId,
71+
}),
72+
],
73+
reloadProps: true,
74+
},
75+
metadata: {
76+
type: "object",
77+
label: "Metadata",
78+
description: "Metadata key/value pairs to add to the return order",
79+
optional: true,
80+
},
81+
},
82+
async additionalProps() {
83+
const props = {};
84+
if (!this.itemIds) {
85+
return props;
86+
}
87+
const { data: items } = await this.returnless.listSalesOrderItems({
88+
orderId: this.orderId,
89+
});
90+
for (const item of items) {
91+
props[`item${item.id}Quantity`] = {
92+
type: "integer",
93+
label: `Item ${item.id} Quantity`,
94+
description: `The quantity of item ${item.id} to return`,
95+
};
96+
props[`item${item.id}ReturnReasonId`] = {
97+
type: "string",
98+
label: `Item ${item.id} Return Reason ID`,
99+
description: `The return reason for item ${item.id}`,
100+
options: async () => {
101+
const { data: returnReasons } = await this.returnless.listReturnReasons();
102+
return returnReasons.map(({
103+
id, label,
104+
}) => ({
105+
value: id,
106+
label,
107+
}));
108+
},
109+
};
110+
}
111+
return props;
112+
},
113+
async run({ $ }) {
114+
const { data: order } = await this.returnless.getOrder({
115+
$,
116+
orderId: this.orderId,
117+
});
118+
119+
const { data: intent } = await this.returnless.createReturnOrderIntent({
120+
$,
121+
data: {
122+
form_id: this.formId,
123+
locale: this.locale,
124+
input: this.input,
125+
order_number: order.order_number,
126+
},
127+
});
128+
if (intent.status === "failed") {
129+
throw new ConfigurationError(intent.status_message);
130+
}
131+
132+
const { data: returnOrder } = await this.returnless.createReturnOrder({
133+
$,
134+
data: {
135+
return_order_intent_id: intent.id,
136+
customer: {
137+
house_number: this.customerHouseNumber,
138+
street: this.customerStreet,
139+
postcode: this.customerPostalCode,
140+
city: this.customerCity,
141+
country_id: this.customerCountryId,
142+
},
143+
items: this.itemIds.map((itemId) => ({
144+
id: itemId,
145+
quantity: this[`item${itemId}Quantity`],
146+
return_reason_id: this[`item${itemId}ReturnReasonId`],
147+
})),
148+
metadata: parseObject(this.metadata),
149+
},
150+
});
151+
152+
$.export("$summary", `Return order created: ${returnOrder.id}`);
153+
return returnOrder;
154+
},
155+
};
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)