Skip to content

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 5 commits into from
May 13, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
111 changes: 111 additions & 0 deletions components/oto/actions/create-product/create-product.mjs
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 components/oto/actions/get-order-details/get-order-details.mjs
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;
},
};
66 changes: 66 additions & 0 deletions components/oto/actions/list-orders/list-orders.mjs
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;
},
};
68 changes: 68 additions & 0 deletions components/oto/common/constants.mjs
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,
};
24 changes: 24 additions & 0 deletions components/oto/common/utils.mjs
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;
};
Loading
Loading