Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
import returnless from "../../returnless.app.mjs";
import { parseObject } from "../../common/utils.mjs";

export default {
key: "returnless-create-return-order",
name: "Create Return Order",
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)",
version: "0.0.1",
type: "action",
props: {
returnless,
formId: {
propDefinition: [
returnless,
"formId",
],
},
locale: {
type: "string",
label: "Locale",
description: "The locale of the form to create the return-order intent for",
},
input: {
type: "string",
label: "Input",
description: "The input for the order. This could be an email address or postalcode or something else.",
},
orderId: {
propDefinition: [
returnless,
"orderId",
],
},
customerHouseNumber: {
type: "string",
label: "Customer House Number",
description: "The house number of the customer",
},
customerStreet: {
type: "string",
label: "Customer Street",
description: "The street of the customer",
},
customerPostalCode: {
type: "string",
label: "Customer Postal Code",
description: "The postal code of the customer",
},
customerCity: {
type: "string",
label: "Customer City",
description: "The city of the customer",
},
customerCountryId: {
propDefinition: [
returnless,
"countryId",
],
},
itemIds: {
propDefinition: [
returnless,
"itemIds",
(c) => ({
orderId: c.orderId,
}),
],
reloadProps: true,
},
metadata: {
type: "object",
label: "Metadata",
description: "Metadata key/value pairs to add to the return order",
optional: true,
},
},
async additionalProps() {
const props = {};
if (!this.itemIds) {
return props;
}
const { data: items } = await this.returnless.listSalesOrderItems({
orderId: this.orderId,
});
for (const item of items) {
props[`item${item.id}Quantity`] = {
type: "string",
label: `Item ${item.id} Quantity`,
description: `The quantity of item ${item.id} to return`,
};
props[`item${item.id}ReturnReasonId`] = {
type: "string",
label: `Item ${item.id} Return Reason ID`,
description: `The return reason for item ${item.id}`,
options: async () => {
const { data: returnReasons } = await this.returnless.listReturnReasons();
return returnReasons.map(({
id, label,
}) => ({
value: id,
label,
}));
},
};
}
return props;
},
async run({ $ }) {
const { data: order } = await this.returnless.getOrder({
$,
orderId: this.orderId,
});

const { data: intent } = await this.returnless.createReturnOrderIntent({
$,
data: {
form_id: this.formId,
locale: this.locale,
input: this.input,
order_number: order.order_number,
},
});

const { data: returnOrder } = await this.returnless.createReturnOrder({
$,
data: {
return_order_intent_id: intent.id,
customer: {
house_number: this.customerHouseNumber,
street: this.customerStreet,
postal_code: this.customerPostalCode,
city: this.customerCity,
country_id: this.customerCountryId,
},
items: this.itemIds.map((itemId) => ({
id: itemId,
quantity: this[`item${itemId}Quantity`],
return_reason_id: this[`item${itemId}ReturnReasonId`],
})),
metadata: parseObject(this.metadata),
},
});

$.export("$summary", `Return order created: ${returnOrder.id}`);
return returnOrder;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import returnless from "../../returnless.app.mjs";

export default {
key: "returnless-list-return-orders",
name: "List Return Orders",
description: "Retrieve a list of return orders. [See the documentation](https://docs.returnless.com/docs/api-rest-reference/0640e3c064cdc-list-all-return-orders)",
version: "0.0.1",
type: "action",
props: {
returnless,
returnType: {
type: "string",
label: "Return Type",
description: "The type of return orders to retrieve",
options: [
"request",
"return",
],
},
createdAfter: {
type: "string",
label: "Created After",
description: "Only return return-orders that were created after the given date",
optional: true,
},
createdBefore: {
type: "string",
label: "Created Before",
description: "Only return return-orders that were created before the given date",
optional: true,
},
maxResults: {
propDefinition: [
returnless,
"maxResults",
],
},
},
async run({ $ }) {
const returnOrders = await this.returnless.getPaginatedResources({
fn: this.returnless.listReturnOrders,
args: {
$,
params: {
filter: {
return_type: this.returnType,
created_at: {
gt: this.createdAfter,
lt: this.createdBefore,
},
},
sort: "-created_at",
},
},
max: this.maxResults,
});

$.export("$summary", `Found ${returnOrders.length} return order${returnOrders.length === 1
? ""
: "s"}`);
return returnOrders;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import returnless from "../../returnless.app.mjs";

export default {
key: "returnless-list-sales-orders",
name: "List Sales Orders",
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)",
version: "0.0.1",
type: "action",
props: {
returnless,
maxResults: {
propDefinition: [
returnless,
"maxResults",
],
},
},
async run({ $ }) {
const salesOrders = await this.returnless.getPaginatedResources({
fn: this.returnless.listSalesOrders,
args: {
$,
},
max: this.maxResults,
});

$.export("$summary", `Found ${salesOrders.length} sales order${salesOrders.length === 1
? ""
: "s"}`);
return salesOrders;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import returnless from "../../returnless.app.mjs";

export default {
key: "returnless-update-return-order-status",
name: "Update Return Order Status",
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)",
version: "0.0.1",
type: "action",
props: {
returnless,
returnOrderId: {
propDefinition: [
returnless,
"returnOrderId",
],
},
returnStatusId: {
propDefinition: [
returnless,
"returnStatusId",
],
},
},
async run({ $ }) {
const { data } = await this.returnless.updateReturnOrderStatus({
$,
returnOrderId: this.returnOrderId,
data: {
status_id: this.returnStatusId,
},
});

$.export("$summary", `Return Order Status Updated: ${data.id}`);
return data;
},
};
27 changes: 27 additions & 0 deletions components/returnless/common/utils.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
export const parseObject = (obj) => {
if (!obj) {
return undefined;
}
if (typeof obj === "string") {
try {
return JSON.parse(obj);
} catch (e) {
return obj;
}
}
if (Array.isArray(obj)) {
return obj.map(parseObject);
}
if (typeof obj === "object") {
return Object.fromEntries(
Object.entries(obj).map(([
key,
value,
]) => [
key,
parseObject(value),
]),
);
}
return obj;
};
7 changes: 5 additions & 2 deletions components/returnless/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/returnless",
"version": "0.0.1",
"version": "0.1.0",
"description": "Pipedream Returnless Components",
"main": "returnless.app.mjs",
"keywords": [
Expand All @@ -11,5 +11,8 @@
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.1.0"
}
}
}
Loading
Loading