-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New Components - oto #16621
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 - oto #16621
Changes from all commits
Commits
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
111 changes: 111 additions & 0 deletions
111
components/oto/actions/create-product/create-product.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,111 @@ | ||
| import oto from "../../oto.app.mjs"; | ||
| import { parseObject } from "../../common/utils.mjs"; | ||
|
|
||
| export default { | ||
| key: "oto-create-product", | ||
| name: "Create Product", | ||
| description: "Creates a new product. [See the documentation](https://apis.tryoto.com/#21b289bc-04c1-49b1-993e-23e928d57f56)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| oto, | ||
| sku: { | ||
| type: "string", | ||
| label: "Sku", | ||
| description: "SKU of the product", | ||
| }, | ||
| productName: { | ||
| type: "string", | ||
| label: "Product Name", | ||
| description: "Name of the product", | ||
| }, | ||
| price: { | ||
| type: "string", | ||
| label: "Price", | ||
| description: "Price of the product", | ||
| }, | ||
| taxAmount: { | ||
| type: "string", | ||
| label: "Tax Amount", | ||
| description: "Tax Amount of the product", | ||
| }, | ||
| brandId: { | ||
| propDefinition: [ | ||
| oto, | ||
| "brandId", | ||
| ], | ||
| }, | ||
| description: { | ||
| type: "string", | ||
| label: "Description", | ||
| description: "Description of the product", | ||
| optional: true, | ||
| }, | ||
| barcode: { | ||
| type: "string", | ||
| label: "Barcode", | ||
| description: "Barcode of the product", | ||
| optional: true, | ||
| }, | ||
| secondBarcode: { | ||
| type: "string", | ||
| label: "Second Barcode", | ||
| description: "Second Barcode of the product", | ||
| optional: true, | ||
| }, | ||
| productImage: { | ||
| type: "string", | ||
| label: "Product Image", | ||
| description: "Image Link of the product", | ||
| optional: true, | ||
| }, | ||
| category: { | ||
| type: "string", | ||
| label: "Category", | ||
| description: "Category of the product", | ||
| optional: true, | ||
| }, | ||
| hsCode: { | ||
| type: "string", | ||
| label: "HS Code", | ||
| description: "A standardized numerical method of classifying traded products", | ||
| optional: true, | ||
| }, | ||
| itemOrigin: { | ||
| type: "string", | ||
| label: "Item Origin", | ||
| description: "Origin of the product", | ||
| optional: true, | ||
| }, | ||
| customAttributes: { | ||
| type: "object", | ||
| label: "Custom Attributes", | ||
| description: "Custom attributes of the product specified as a JSON Array of objects with keys `attributeName` and `attributeValue`. Example: `[{ \"attributeName\": \"112\", \"attributeValue\": \"test product\"}]`", | ||
| optional: true, | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const response = await this.oto.createProduct({ | ||
| $, | ||
| data: { | ||
| sku: this.sku, | ||
| productName: this.productName, | ||
| price: this.price, | ||
| taxAmount: this.taxAmount, | ||
| brandId: this.brandId, | ||
| description: this.description, | ||
| barcode: this.barcode, | ||
| secondBarcode: this.secondBarcode, | ||
| productImage: this.productImage, | ||
| category: this.category, | ||
| hsCode: this.hsCode, | ||
| itemOrigin: this.itemOrigin, | ||
| customAttributes: parseObject(this.customAttributes), | ||
| }, | ||
| }); | ||
| if (response.productId) { | ||
| $.export("$summary", `Successfully created product with ID: ${response.productId}`); | ||
| } | ||
| return response; | ||
| }, | ||
| }; |
28 changes: 28 additions & 0 deletions
28
components/oto/actions/get-order-details/get-order-details.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,28 @@ | ||
| import oto from "../../oto.app.mjs"; | ||
|
|
||
| export default { | ||
| key: "oto-get-order-details", | ||
| name: "Get Order Details", | ||
| description: "Provides detailed information about a specific order. [See the documentation](https://apis.tryoto.com/#53964419-2d64-4c07-b39d-b26a92b379c9)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| oto, | ||
| orderId: { | ||
| propDefinition: [ | ||
| oto, | ||
| "orderId", | ||
| ], | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const response = await this.oto.getOrderDetails({ | ||
| $, | ||
| params: { | ||
| orderId: this.orderId, | ||
| }, | ||
| }); | ||
| $.export("$summary", `Successfully retrieved details for order with ID: ${this.orderId}`); | ||
| return response; | ||
| }, | ||
| }; |
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,66 @@ | ||
| import oto from "../../oto.app.mjs"; | ||
|
|
||
| export default { | ||
| key: "oto-list-orders", | ||
| name: "List Orders", | ||
| description: "Retrieves a list of orders. [See the documentation](https://apis.tryoto.com/#c2e94027-5214-456d-b653-0a66c038e3a4)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| oto, | ||
| status: { | ||
| propDefinition: [ | ||
| oto, | ||
| "status", | ||
| ], | ||
| }, | ||
| minDate: { | ||
| type: "string", | ||
| label: "Min Date", | ||
| description: "Starting \"Order Creation Date\" of your orders in \"yyyy-mm-dd\" format", | ||
| optional: true, | ||
| }, | ||
| maxDate: { | ||
| type: "string", | ||
| label: "Max Date", | ||
| description: "Ending \"Order Creation Date\" of your orders in \"yyyy-mm-dd\" format", | ||
| optional: true, | ||
| }, | ||
| maxResults: { | ||
| type: "integer", | ||
| label: "Max Results", | ||
| description: "The maximum number of orders to return", | ||
| default: 100, | ||
| optional: true, | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const results = this.oto.paginate({ | ||
| fn: this.oto.listOrders, | ||
| args: { | ||
| $, | ||
| params: { | ||
| minDate: this.minDate, | ||
| maxDate: this.maxDate, | ||
| status: this.status, | ||
| }, | ||
| }, | ||
| resourceKey: "orders", | ||
| max: this.maxResults, | ||
| }); | ||
|
|
||
| const orders = []; | ||
| for await (const order of results) { | ||
| orders.push(order); | ||
| } | ||
|
|
||
| if (orders[0].items?.length) { | ||
| $.export("$summary", `Successfully retrieved ${orders.length} order${orders.length === 1 | ||
| ? "" | ||
| : "s"}`); | ||
| } else { | ||
| $.export("$summary", "No orders found"); | ||
| } | ||
| return orders; | ||
| }, | ||
| }; | ||
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,68 @@ | ||
| const DEFAULT_LIMIT = 100; | ||
|
|
||
| const STATUSES = [ | ||
| "new", | ||
| "paymentConfirmed", | ||
| "waitingAddressConfirmation", | ||
| "addressConfirmed", | ||
| "needConfirmation", | ||
| "paymentTypeConfirmed", | ||
| "codOrderConfirmed", | ||
| "orderConfirmed", | ||
| "pickupFromStore", | ||
| "interDepotTransfer", | ||
| "canceled", | ||
| "deleted", | ||
| "readyForCollection", | ||
| "branchAssigned", | ||
| "assignedToWarehouse", | ||
| "shipmentOnHoldWarehouse", | ||
| "shipmentOnHoldToCancel", | ||
| "notAvailableBR", | ||
| "notAvailableWH", | ||
| "picked", | ||
| "packed", | ||
| "searchingDriver", | ||
| "shipmentCreated", | ||
| "goingToPickup", | ||
| "arrivedPickup", | ||
| "pickedUp", | ||
| "arrivedDestinationTerminal", | ||
| "arrivedTerminal", | ||
| "departedTerminal", | ||
| "inTransit", | ||
| "arrivedOriginTerminal", | ||
| "outForDelivery", | ||
| "arrivedDestination", | ||
| "shipmentInProgress", | ||
| "undeliveredAttempt", | ||
| "shipmentOnHold", | ||
| "delivered", | ||
| "returned", | ||
| "returnProcessing", | ||
| "returnShipmentProcessing", | ||
| "reverseShipmentProcessing", | ||
| "reverseShipmentCreated", | ||
| "reverseShipmentCanceled", | ||
| "reverseGoingToPickup", | ||
| "reversePickedUp", | ||
| "reverseOutForDelivery", | ||
| "reverseArrivedTerminal", | ||
| "reverseDepartedTerminal", | ||
| "reverseArrivedDestinationTerminal", | ||
| "reverseUndeliveredAttempt", | ||
| "reverseShipmentOnHold", | ||
| "reverseReturned", | ||
| "reverseConfirmReturn", | ||
| "shipmentCanceled", | ||
| "lostOrDamaged", | ||
| "confirmedReturn", | ||
| "approved", | ||
| "rejected", | ||
| "returnReverseComment", | ||
| ]; | ||
|
|
||
| export default { | ||
| DEFAULT_LIMIT, | ||
| STATUSES, | ||
| }; |
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,24 @@ | ||
| export function parseObject(obj) { | ||
| if (!obj) return undefined; | ||
|
|
||
| if (Array.isArray(obj)) { | ||
| return obj.map((item) => { | ||
| if (typeof item === "string") { | ||
| try { | ||
| return JSON.parse(item); | ||
| } catch (e) { | ||
| return item; | ||
| } | ||
| } | ||
| return item; | ||
| }); | ||
| } | ||
| if (typeof obj === "string") { | ||
| try { | ||
| return JSON.parse(obj); | ||
| } catch (e) { | ||
| return obj; | ||
| } | ||
| } | ||
| return obj; | ||
| }; |
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.