-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New Components - returnless #17629
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
New Components - returnless #17629
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
147 changes: 147 additions & 0 deletions
147
components/returnless/actions/create-return-order/create-return-order.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| }, | ||
| }; | ||
63 changes: 63 additions & 0 deletions
63
components/returnless/actions/list-return-orders/list-return-orders.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| }, | ||
| }; |
32 changes: 32 additions & 0 deletions
32
components/returnless/actions/list-sales-orders/list-sales-orders.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| }, | ||
| }; |
36 changes: 36 additions & 0 deletions
36
components/returnless/actions/update-return-order-status/update-return-order-status.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| }, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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": [ | ||
|
|
@@ -11,5 +11,8 @@ | |
| "author": "Pipedream <[email protected]> (https://pipedream.com/)", | ||
| "publishConfig": { | ||
| "access": "public" | ||
| }, | ||
| "dependencies": { | ||
| "@pipedream/platform": "^3.1.0" | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.