Skip to content

Commit 493b188

Browse files
committed
new components
1 parent c337052 commit 493b188

File tree

12 files changed

+227
-11
lines changed

12 files changed

+227
-11
lines changed
Lines changed: 103 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,117 @@
11
import oto from "../../oto.app.mjs";
2+
import utils from "../../common/utils.mjs";
23

34
export default {
45
key: "oto-create-product",
56
name: "Create Product",
67
description: "Creates a new product. [See the documentation](https://apis.tryoto.com/#21b289bc-04c1-49b1-993e-23e928d57f56)",
7-
version: "0.0.{{ts}}",
8+
version: "0.0.1",
89
type: "action",
910
props: {
1011
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+
optional: true,
32+
},
33+
brandId: {
34+
propDefinition: [
35+
oto,
36+
"brandId",
37+
],
38+
},
39+
description: {
40+
type: "string",
41+
label: "Description",
42+
description: "Description of the product",
43+
optional: true,
44+
},
45+
barcode: {
46+
type: "string",
47+
label: "Barcode",
48+
description: "Barcode of the product",
49+
optional: true,
50+
},
51+
secondBarcode: {
52+
type: "string",
53+
label: "Second Barcode",
54+
description: "Second Barcode of the product",
55+
optional: true,
56+
},
57+
productImage: {
58+
type: "string",
59+
label: "Product Image",
60+
description: "Image Link of the product",
61+
optional: true,
62+
},
63+
category: {
64+
type: "string",
65+
label: "Category",
66+
description: "Category of the product",
67+
optional: true,
68+
},
69+
hsCode: {
70+
type: "string",
71+
label: "HS Code",
72+
description: "A standardized numerical method of classifying traded products",
73+
optional: true,
74+
},
75+
itemOrigin: {
76+
type: "string",
77+
label: "Item Origin",
78+
description: "Origin of the product",
79+
optional: true,
80+
},
81+
bundleItems: {
82+
type: "boolean",
83+
label: "Bundle Items",
84+
description: "It can be true/ false",
85+
optional: true,
86+
},
87+
customAttributes: {
88+
type: "object",
89+
label: "Custom Attributes",
90+
description: "Custom attributes of the product specified as a JSON Array of objects with keys `attributeName` and `attributeValue`. Example: `[{ \"attributeName\": \"112\", \"attributeValue\": \"test product\"}]`",
91+
optional: true,
92+
},
1193
},
1294
async run({ $ }) {
13-
const response = await this.oto.createProduct({});
14-
$.export("$summary", "");
95+
const response = await this.oto.createProduct({
96+
$,
97+
data: {
98+
sku: this.sku,
99+
productName: this.productName,
100+
price: this.price,
101+
taxAmount: this.taxAmount,
102+
brandId: this.brandId,
103+
description: this.description,
104+
barcode: this.barcode,
105+
secondBarcode: this.secondBarcode,
106+
productImage: this.productImage,
107+
category: this.category,
108+
hsCode: this.hsCode,
109+
itemOrigin: this.itemOrigin,
110+
bundleItems: this.bundleItems,
111+
customAttributes: utils.parseObject(this.customAttributes),
112+
},
113+
});
114+
$.export("$summary", `Successfully created product with ID: ${response.productId}`);
15115
return response;
16116
},
17117
};

components/oto/actions/list-orders/list-orders.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default {
44
key: "oto-list-orders",
55
name: "List Orders",
66
description: "Retrieves a list of orders. [See the documentation](https://apis.tryoto.com/#c2e94027-5214-456d-b653-0a66c038e3a4)",
7-
version: "0.0.{{ts}}",
7+
version: "0.0.1",
88
type: "action",
99
props: {
1010
oto,

components/oto/actions/track-shipment/track-shipment.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default {
44
key: "oto-track-shipment",
55
name: "Track Shipment",
66
description: "track a shipment by providing the tracking number and delivery company name. [See the documentation](https://apis.tryoto.com/#3b8d84ec-7769-41d4-adf2-6d2d8c1189a4)",
7-
version: "0.0.{{ts}}",
7+
version: "0.0.1",
88
type: "action",
99
props: {
1010
oto,

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+
};

components/oto/oto.app.mjs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,21 @@ export default {
1515
return clientStores?.map(({ storeName }) => storeName) || [];
1616
},
1717
},
18+
brandId: {
19+
type: "string",
20+
label: "Brand ID",
21+
description: "The brand ID of the product",
22+
optional: true,
23+
async options() {
24+
const { clientStores } = await this.listBrands();
25+
return clientStores?.map(({
26+
ID: value, storeName: label,
27+
}) => ({
28+
label,
29+
value,
30+
})) || [];
31+
},
32+
},
1833
status: {
1934
type: "string",
2035
label: "Status",

components/oto/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/oto",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream OTO Components",
55
"main": "oto.app.mjs",
66
"keywords": [
@@ -11,5 +11,8 @@
1111
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.0.3"
1417
}
1518
}

components/oto/sources/common/base.mjs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,15 @@ export default {
3939
throw new Error("getWebhookType is not implemented");
4040
},
4141
generateMeta() {
42-
return {};
42+
throw new Error ("generateMeta is not implemented");
4343
},
4444
},
4545
async run(event) {
4646
const { body } = event;
4747
if (!body) {
4848
return;
4949
}
50-
console.log(body);
50+
const meta = this.generateMeta(body);
51+
this.$emit(body, meta);
5152
},
5253
};
Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
11
import common from "../common/base.mjs";
2+
import sampleEmit from "./test-event.mjs";
23

34
export default {
45
...common,
56
key: "oto-new-order-instant",
67
name: "New Order (Instant)",
78
description: "Emit new event when a new order is placed. [See the documentation](https://apis.tryoto.com/#9671ca1f-7d06-43fc-8ee9-cf9c336b088d)",
8-
version: "0.0.{{ts}}",
9+
version: "0.0.1",
910
type: "source",
1011
dedupe: "unique",
1112
methods: {
1213
...common.methods,
1314
getWebhookType() {
1415
return "newOrders";
1516
},
17+
generateMeta(event) {
18+
return {
19+
id: event.orderId,
20+
summary: `New Order with ID: ${event.orderId}`,
21+
ts: event.timestamp,
22+
};
23+
},
1624
},
25+
sampleEmit,
1726
};
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
export default {
2+
"orderId": "123",
3+
"order": {
4+
"address": {
5+
"country": "",
6+
"address": "",
7+
"city": "",
8+
"name": "",
9+
"mobile": "",
10+
"state": "",
11+
},
12+
"orderId": "123",
13+
"grandTotal": 1,
14+
"weight": 1,
15+
"salesChannel": "manual",
16+
"createdDate": "2025-05-08T16:18:03Z",
17+
"warehouseId": 24801,
18+
"otoId": 30911387,
19+
"paymentMethod": "paid",
20+
"currency": "SAR",
21+
"incrementId": "123",
22+
"items": [
23+
{
24+
"itemId": 14437928,
25+
"productId": 6350018,
26+
"qtyOrdered": 1,
27+
"sku": "1234",
28+
"productName": "product1",
29+
},
30+
],
31+
"status": "assignedToWarehouse",
32+
},
33+
"status": "assignedToWarehouse",
34+
"timestamp": 1746721083000,
35+
};

components/oto/sources/new-shipment-error-instant/new-shipment-error-instant.mjs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,20 @@ export default {
55
key: "oto-new-shipment-error-instant",
66
name: "New Shipment Error (Instant)",
77
description: "Emit new event when an error in a shipment occurs. [See the documentation](https://apis.tryoto.com/#9671ca1f-7d06-43fc-8ee9-cf9c336b088d)",
8-
version: "0.0.{{ts}}",
8+
version: "0.0.1",
99
type: "source",
1010
dedupe: "unique",
1111
methods: {
1212
...common.methods,
1313
getWebhookType() {
1414
return "shipmentError";
1515
},
16+
generateMeta(event) {
17+
return {
18+
id: event.timestamp,
19+
summary: "New Shipment Error",
20+
ts: event.timestamp,
21+
};
22+
},
1623
},
1724
};

0 commit comments

Comments
 (0)