Skip to content

Commit d926afb

Browse files
authored
New Components - oto (#16621)
* wip * new components * updates * pnpm-lock.yaml * updates
1 parent 016a21a commit d926afb

File tree

11 files changed

+526
-7
lines changed

11 files changed

+526
-7
lines changed
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
import oto from "../../oto.app.mjs";
2+
import { parseObject } from "../../common/utils.mjs";
3+
4+
export default {
5+
key: "oto-create-product",
6+
name: "Create Product",
7+
description: "Creates a new product. [See the documentation](https://apis.tryoto.com/#21b289bc-04c1-49b1-993e-23e928d57f56)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
oto,
12+
sku: {
13+
type: "string",
14+
label: "Sku",
15+
description: "SKU of the product",
16+
},
17+
productName: {
18+
type: "string",
19+
label: "Product Name",
20+
description: "Name of the product",
21+
},
22+
price: {
23+
type: "string",
24+
label: "Price",
25+
description: "Price of the product",
26+
},
27+
taxAmount: {
28+
type: "string",
29+
label: "Tax Amount",
30+
description: "Tax Amount of the product",
31+
},
32+
brandId: {
33+
propDefinition: [
34+
oto,
35+
"brandId",
36+
],
37+
},
38+
description: {
39+
type: "string",
40+
label: "Description",
41+
description: "Description of the product",
42+
optional: true,
43+
},
44+
barcode: {
45+
type: "string",
46+
label: "Barcode",
47+
description: "Barcode of the product",
48+
optional: true,
49+
},
50+
secondBarcode: {
51+
type: "string",
52+
label: "Second Barcode",
53+
description: "Second Barcode of the product",
54+
optional: true,
55+
},
56+
productImage: {
57+
type: "string",
58+
label: "Product Image",
59+
description: "Image Link of the product",
60+
optional: true,
61+
},
62+
category: {
63+
type: "string",
64+
label: "Category",
65+
description: "Category of the product",
66+
optional: true,
67+
},
68+
hsCode: {
69+
type: "string",
70+
label: "HS Code",
71+
description: "A standardized numerical method of classifying traded products",
72+
optional: true,
73+
},
74+
itemOrigin: {
75+
type: "string",
76+
label: "Item Origin",
77+
description: "Origin of the product",
78+
optional: true,
79+
},
80+
customAttributes: {
81+
type: "object",
82+
label: "Custom Attributes",
83+
description: "Custom attributes of the product specified as a JSON Array of objects with keys `attributeName` and `attributeValue`. Example: `[{ \"attributeName\": \"112\", \"attributeValue\": \"test product\"}]`",
84+
optional: true,
85+
},
86+
},
87+
async run({ $ }) {
88+
const response = await this.oto.createProduct({
89+
$,
90+
data: {
91+
sku: this.sku,
92+
productName: this.productName,
93+
price: this.price,
94+
taxAmount: this.taxAmount,
95+
brandId: this.brandId,
96+
description: this.description,
97+
barcode: this.barcode,
98+
secondBarcode: this.secondBarcode,
99+
productImage: this.productImage,
100+
category: this.category,
101+
hsCode: this.hsCode,
102+
itemOrigin: this.itemOrigin,
103+
customAttributes: parseObject(this.customAttributes),
104+
},
105+
});
106+
if (response.productId) {
107+
$.export("$summary", `Successfully created product with ID: ${response.productId}`);
108+
}
109+
return response;
110+
},
111+
};
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import oto from "../../oto.app.mjs";
2+
3+
export default {
4+
key: "oto-get-order-details",
5+
name: "Get Order Details",
6+
description: "Provides detailed information about a specific order. [See the documentation](https://apis.tryoto.com/#53964419-2d64-4c07-b39d-b26a92b379c9)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
oto,
11+
orderId: {
12+
propDefinition: [
13+
oto,
14+
"orderId",
15+
],
16+
},
17+
},
18+
async run({ $ }) {
19+
const response = await this.oto.getOrderDetails({
20+
$,
21+
params: {
22+
orderId: this.orderId,
23+
},
24+
});
25+
$.export("$summary", `Successfully retrieved details for order with ID: ${this.orderId}`);
26+
return response;
27+
},
28+
};
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import oto from "../../oto.app.mjs";
2+
3+
export default {
4+
key: "oto-list-orders",
5+
name: "List Orders",
6+
description: "Retrieves a list of orders. [See the documentation](https://apis.tryoto.com/#c2e94027-5214-456d-b653-0a66c038e3a4)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
oto,
11+
status: {
12+
propDefinition: [
13+
oto,
14+
"status",
15+
],
16+
},
17+
minDate: {
18+
type: "string",
19+
label: "Min Date",
20+
description: "Starting \"Order Creation Date\" of your orders in \"yyyy-mm-dd\" format",
21+
optional: true,
22+
},
23+
maxDate: {
24+
type: "string",
25+
label: "Max Date",
26+
description: "Ending \"Order Creation Date\" of your orders in \"yyyy-mm-dd\" format",
27+
optional: true,
28+
},
29+
maxResults: {
30+
type: "integer",
31+
label: "Max Results",
32+
description: "The maximum number of orders to return",
33+
default: 100,
34+
optional: true,
35+
},
36+
},
37+
async run({ $ }) {
38+
const results = this.oto.paginate({
39+
fn: this.oto.listOrders,
40+
args: {
41+
$,
42+
params: {
43+
minDate: this.minDate,
44+
maxDate: this.maxDate,
45+
status: this.status,
46+
},
47+
},
48+
resourceKey: "orders",
49+
max: this.maxResults,
50+
});
51+
52+
const orders = [];
53+
for await (const order of results) {
54+
orders.push(order);
55+
}
56+
57+
if (orders[0].items?.length) {
58+
$.export("$summary", `Successfully retrieved ${orders.length} order${orders.length === 1
59+
? ""
60+
: "s"}`);
61+
} else {
62+
$.export("$summary", "No orders found");
63+
}
64+
return orders;
65+
},
66+
};
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
const DEFAULT_LIMIT = 100;
2+
3+
const STATUSES = [
4+
"new",
5+
"paymentConfirmed",
6+
"waitingAddressConfirmation",
7+
"addressConfirmed",
8+
"needConfirmation",
9+
"paymentTypeConfirmed",
10+
"codOrderConfirmed",
11+
"orderConfirmed",
12+
"pickupFromStore",
13+
"interDepotTransfer",
14+
"canceled",
15+
"deleted",
16+
"readyForCollection",
17+
"branchAssigned",
18+
"assignedToWarehouse",
19+
"shipmentOnHoldWarehouse",
20+
"shipmentOnHoldToCancel",
21+
"notAvailableBR",
22+
"notAvailableWH",
23+
"picked",
24+
"packed",
25+
"searchingDriver",
26+
"shipmentCreated",
27+
"goingToPickup",
28+
"arrivedPickup",
29+
"pickedUp",
30+
"arrivedDestinationTerminal",
31+
"arrivedTerminal",
32+
"departedTerminal",
33+
"inTransit",
34+
"arrivedOriginTerminal",
35+
"outForDelivery",
36+
"arrivedDestination",
37+
"shipmentInProgress",
38+
"undeliveredAttempt",
39+
"shipmentOnHold",
40+
"delivered",
41+
"returned",
42+
"returnProcessing",
43+
"returnShipmentProcessing",
44+
"reverseShipmentProcessing",
45+
"reverseShipmentCreated",
46+
"reverseShipmentCanceled",
47+
"reverseGoingToPickup",
48+
"reversePickedUp",
49+
"reverseOutForDelivery",
50+
"reverseArrivedTerminal",
51+
"reverseDepartedTerminal",
52+
"reverseArrivedDestinationTerminal",
53+
"reverseUndeliveredAttempt",
54+
"reverseShipmentOnHold",
55+
"reverseReturned",
56+
"reverseConfirmReturn",
57+
"shipmentCanceled",
58+
"lostOrDamaged",
59+
"confirmedReturn",
60+
"approved",
61+
"rejected",
62+
"returnReverseComment",
63+
];
64+
65+
export default {
66+
DEFAULT_LIMIT,
67+
STATUSES,
68+
};

components/oto/common/utils.mjs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
export function parseObject(obj) {
2+
if (!obj) return undefined;
3+
4+
if (Array.isArray(obj)) {
5+
return obj.map((item) => {
6+
if (typeof item === "string") {
7+
try {
8+
return JSON.parse(item);
9+
} catch (e) {
10+
return item;
11+
}
12+
}
13+
return item;
14+
});
15+
}
16+
if (typeof obj === "string") {
17+
try {
18+
return JSON.parse(obj);
19+
} catch (e) {
20+
return obj;
21+
}
22+
}
23+
return obj;
24+
};

0 commit comments

Comments
 (0)