From c337052dd55036c034bef5976a4207b4c97d4e8e Mon Sep 17 00:00:00 2001 From: michelle0927 Date: Thu, 8 May 2025 11:29:00 -0400 Subject: [PATCH 1/5] wip --- .../actions/create-product/create-product.mjs | 17 +++ .../oto/actions/list-orders/list-orders.mjs | 62 +++++++++++ .../actions/track-shipment/track-shipment.mjs | 41 +++++++ components/oto/common/constants.mjs | 70 ++++++++++++ components/oto/oto.app.mjs | 104 +++++++++++++++++- components/oto/package.json | 2 +- components/oto/sources/common/base.mjs | 52 +++++++++ .../new-order-instant/new-order-instant.mjs | 17 +++ .../new-shipment-error-instant.mjs | 17 +++ .../new-order-status-updated.mjs | 17 +++ 10 files changed, 394 insertions(+), 5 deletions(-) create mode 100644 components/oto/actions/create-product/create-product.mjs create mode 100644 components/oto/actions/list-orders/list-orders.mjs create mode 100644 components/oto/actions/track-shipment/track-shipment.mjs create mode 100644 components/oto/common/constants.mjs create mode 100644 components/oto/sources/common/base.mjs create mode 100644 components/oto/sources/new-order-instant/new-order-instant.mjs create mode 100644 components/oto/sources/new-shipment-error-instant/new-shipment-error-instant.mjs create mode 100644 components/oto/sources/order-status-updated-instant/new-order-status-updated.mjs diff --git a/components/oto/actions/create-product/create-product.mjs b/components/oto/actions/create-product/create-product.mjs new file mode 100644 index 0000000000000..dd92451d67470 --- /dev/null +++ b/components/oto/actions/create-product/create-product.mjs @@ -0,0 +1,17 @@ +import oto from "../../oto.app.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.{{ts}}", + type: "action", + props: { + oto, + }, + async run({ $ }) { + const response = await this.oto.createProduct({}); + $.export("$summary", ""); + return response; + }, +}; diff --git a/components/oto/actions/list-orders/list-orders.mjs b/components/oto/actions/list-orders/list-orders.mjs new file mode 100644 index 0000000000000..d1813a11b1dfc --- /dev/null +++ b/components/oto/actions/list-orders/list-orders.mjs @@ -0,0 +1,62 @@ +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.{{ts}}", + 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); + } + + $.export("$summary", `Successfully retrieved ${orders.length} order${orders.length === 1 + ? "" + : "s"}`); + return orders; + }, +}; diff --git a/components/oto/actions/track-shipment/track-shipment.mjs b/components/oto/actions/track-shipment/track-shipment.mjs new file mode 100644 index 0000000000000..f35f31aad19b4 --- /dev/null +++ b/components/oto/actions/track-shipment/track-shipment.mjs @@ -0,0 +1,41 @@ +import oto from "../../oto.app.mjs"; + +export default { + key: "oto-track-shipment", + name: "Track Shipment", + 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)", + version: "0.0.{{ts}}", + type: "action", + props: { + oto, + trackingNumber: { + type: "string", + label: "Tracking Number", + description: "The shipment/ tracking number that you wanna track", + }, + deliveryCompanyName: { + type: "string", + label: "Delivery Company Name", + description: "The name of the delivery company", + }, + brandName: { + propDefinition: [ + oto, + "brandName", + ], + }, + }, + async run({ $ }) { + const response = await this.oto.trackShipment({ + $, + data: { + trackingNumber: this.trackingNumber, + deliveryCompanyName: this.deliveryCompanyName, + brandName: this.brandName, + statusHistory: true, + }, + }); + $.export("$summary", `Successfully tracked shipment with tracking number: ${this.trackingNumber}`); + return response; + }, +}; diff --git a/components/oto/common/constants.mjs b/components/oto/common/constants.mjs new file mode 100644 index 0000000000000..2c034bb610f90 --- /dev/null +++ b/components/oto/common/constants.mjs @@ -0,0 +1,70 @@ +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", + "reverseShipmentCanceled", + "reverseConfirmReturn", + "returnReverseComment", +]; + +export default { + DEFAULT_LIMIT, + STATUSES, +}; diff --git a/components/oto/oto.app.mjs b/components/oto/oto.app.mjs index 41dbdb91de0be..3e41925449a4f 100644 --- a/components/oto/oto.app.mjs +++ b/components/oto/oto.app.mjs @@ -1,11 +1,107 @@ +import { axios } from "@pipedream/platform"; +import constants from "./common/constants.mjs"; + export default { type: "app", app: "oto", - propDefinitions: {}, + propDefinitions: { + brandName: { + type: "string", + label: "Brand Name", + description: "The brand name associated with the shipment", + optional: true, + async options() { + const { clientStores } = await this.listBrands(); + return clientStores?.map(({ storeName }) => storeName) || []; + }, + }, + status: { + type: "string", + label: "Status", + description: "The status of an order", + options: constants.STATUSES, + optional: true, + }, + }, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + _baseUrl() { + return `${this.$auth.api_url}/rest/v2`; + }, + _makeRequest({ + $ = this, path, ...otherOpts + }) { + return axios($, { + ...otherOpts, + url: `${this._baseUrl()}${path}`, + headers: { + Authorization: `Bearer ${this.$auth.oauth_access_token}`, + }, + }); + }, + createWebhook(opts = {}) { + return this._makeRequest({ + method: "POST", + path: "/webhook", + ...opts, + }); + }, + deleteWebhook(opts = {}) { + return this._makeRequest({ + method: "DELETE", + path: "/webhook", + ...opts, + }); + }, + listOrders(opts = {}) { + return this._makeRequest({ + path: "/orders", + ...opts, + }); + }, + listBrands(opts = {}) { + return this._makeRequest({ + path: "/getBrandList", + ...opts, + }); + }, + createProduct(opts = {}) { + return this._makeRequest({ + method: "POST", + path: "/createProduct", + ...opts, + }); + }, + trackShipment(opts = {}) { + return this._makeRequest({ + method: "POST", + path: "/trackShipment", + ...opts, + }); + }, + async *paginate({ + fn, args, resourceKey, max, + }) { + args = { + ...args, + params: { + ...args?.params, + perPage: constants.DEFAULT_LIMIT, + page: 1, + }, + }; + let total, count = 0; + do { + const response = await fn(args); + const items = response[resourceKey]; + for (const item of items) { + yield item; + if (max && ++count >= max) { + return; + } + } + total = items?.length; + args.params.page++; + } while (total === args.params.perPage); }, }, }; diff --git a/components/oto/package.json b/components/oto/package.json index 58cd469742de9..bbd0481882d4e 100644 --- a/components/oto/package.json +++ b/components/oto/package.json @@ -12,4 +12,4 @@ "publishConfig": { "access": "public" } -} \ No newline at end of file +} diff --git a/components/oto/sources/common/base.mjs b/components/oto/sources/common/base.mjs new file mode 100644 index 0000000000000..0369a693b2e21 --- /dev/null +++ b/components/oto/sources/common/base.mjs @@ -0,0 +1,52 @@ +import oto from "../../oto.app.mjs"; + +export default { + props: { + oto, + db: "$.service.db", + http: "$.interface.http", + }, + hooks: { + async activate() { + const { id } = await this.oto.createWebhook({ + data: { + url: this.http.endpoint, + method: "POST", + webhookType: this.getWebhookType(), + }, + }); + this._setHookId(id); + }, + async deactivate() { + const id = this._getHookId(); + if (id) { + await this.oto.deleteWebhook({ + params: { + id, + }, + }); + } + }, + }, + methods: { + _getHookId() { + return this.db.get("hookId"); + }, + _setHookId(hookId) { + this.db.set("hookId", hookId); + }, + getWebhookType() { + throw new Error("getWebhookType is not implemented"); + }, + generateMeta() { + return {}; + }, + }, + async run(event) { + const { body } = event; + if (!body) { + return; + } + console.log(body); + }, +}; diff --git a/components/oto/sources/new-order-instant/new-order-instant.mjs b/components/oto/sources/new-order-instant/new-order-instant.mjs new file mode 100644 index 0000000000000..e705231ba12a3 --- /dev/null +++ b/components/oto/sources/new-order-instant/new-order-instant.mjs @@ -0,0 +1,17 @@ +import common from "../common/base.mjs"; + +export default { + ...common, + key: "oto-new-order-instant", + name: "New Order (Instant)", + description: "Emit new event when a new order is placed. [See the documentation](https://apis.tryoto.com/#9671ca1f-7d06-43fc-8ee9-cf9c336b088d)", + version: "0.0.{{ts}}", + type: "source", + dedupe: "unique", + methods: { + ...common.methods, + getWebhookType() { + return "newOrders"; + }, + }, +}; diff --git a/components/oto/sources/new-shipment-error-instant/new-shipment-error-instant.mjs b/components/oto/sources/new-shipment-error-instant/new-shipment-error-instant.mjs new file mode 100644 index 0000000000000..3dde452509c87 --- /dev/null +++ b/components/oto/sources/new-shipment-error-instant/new-shipment-error-instant.mjs @@ -0,0 +1,17 @@ +import common from "../common/base.mjs"; + +export default { + ...common, + key: "oto-new-shipment-error-instant", + name: "New Shipment Error (Instant)", + description: "Emit new event when an error in a shipment occurs. [See the documentation](https://apis.tryoto.com/#9671ca1f-7d06-43fc-8ee9-cf9c336b088d)", + version: "0.0.{{ts}}", + type: "source", + dedupe: "unique", + methods: { + ...common.methods, + getWebhookType() { + return "shipmentError"; + }, + }, +}; diff --git a/components/oto/sources/order-status-updated-instant/new-order-status-updated.mjs b/components/oto/sources/order-status-updated-instant/new-order-status-updated.mjs new file mode 100644 index 0000000000000..c7affc5549f43 --- /dev/null +++ b/components/oto/sources/order-status-updated-instant/new-order-status-updated.mjs @@ -0,0 +1,17 @@ +import common from "../common/base.mjs"; + +export default { + ...common, + key: "oto-new-order-status-instant", + name: "New Order Status (Instant)", + description: "Emit new event when the status of an order changes. [See the documentation](https://apis.tryoto.com/#9671ca1f-7d06-43fc-8ee9-cf9c336b088d)", + version: "0.0.{{ts}}", + type: "source", + dedupe: "unique", + methods: { + ...common.methods, + getWebhookType() { + return "orderStatus"; + }, + }, +}; From 493b188062c9f52813faf7b793b836e8c26b3f33 Mon Sep 17 00:00:00 2001 From: michelle0927 Date: Thu, 8 May 2025 13:23:55 -0400 Subject: [PATCH 2/5] new components --- .../actions/create-product/create-product.mjs | 106 +++++++++++++++++- .../oto/actions/list-orders/list-orders.mjs | 2 +- .../actions/track-shipment/track-shipment.mjs | 2 +- components/oto/common/utils.mjs | 24 ++++ components/oto/oto.app.mjs | 15 +++ components/oto/package.json | 5 +- components/oto/sources/common/base.mjs | 5 +- .../new-order-instant/new-order-instant.mjs | 11 +- .../sources/new-order-instant/test-event.mjs | 35 ++++++ .../new-shipment-error-instant.mjs | 9 +- .../new-order-status-updated.mjs | 11 +- .../test-event.mjs | 13 +++ 12 files changed, 227 insertions(+), 11 deletions(-) create mode 100644 components/oto/common/utils.mjs create mode 100644 components/oto/sources/new-order-instant/test-event.mjs create mode 100644 components/oto/sources/order-status-updated-instant/test-event.mjs diff --git a/components/oto/actions/create-product/create-product.mjs b/components/oto/actions/create-product/create-product.mjs index dd92451d67470..b2118064621cb 100644 --- a/components/oto/actions/create-product/create-product.mjs +++ b/components/oto/actions/create-product/create-product.mjs @@ -1,17 +1,117 @@ import oto from "../../oto.app.mjs"; +import utils 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.{{ts}}", + 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", + optional: true, + }, + 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, + }, + bundleItems: { + type: "boolean", + label: "Bundle Items", + description: "It can be true/ false", + 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({}); - $.export("$summary", ""); + 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, + bundleItems: this.bundleItems, + customAttributes: utils.parseObject(this.customAttributes), + }, + }); + $.export("$summary", `Successfully created product with ID: ${response.productId}`); return response; }, }; diff --git a/components/oto/actions/list-orders/list-orders.mjs b/components/oto/actions/list-orders/list-orders.mjs index d1813a11b1dfc..40a125a857934 100644 --- a/components/oto/actions/list-orders/list-orders.mjs +++ b/components/oto/actions/list-orders/list-orders.mjs @@ -4,7 +4,7 @@ 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.{{ts}}", + version: "0.0.1", type: "action", props: { oto, diff --git a/components/oto/actions/track-shipment/track-shipment.mjs b/components/oto/actions/track-shipment/track-shipment.mjs index f35f31aad19b4..f7f0d04952aba 100644 --- a/components/oto/actions/track-shipment/track-shipment.mjs +++ b/components/oto/actions/track-shipment/track-shipment.mjs @@ -4,7 +4,7 @@ export default { key: "oto-track-shipment", name: "Track Shipment", 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)", - version: "0.0.{{ts}}", + version: "0.0.1", type: "action", props: { oto, diff --git a/components/oto/common/utils.mjs b/components/oto/common/utils.mjs new file mode 100644 index 0000000000000..78ef2a6bb6834 --- /dev/null +++ b/components/oto/common/utils.mjs @@ -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; +}; diff --git a/components/oto/oto.app.mjs b/components/oto/oto.app.mjs index 3e41925449a4f..906419d6e49a5 100644 --- a/components/oto/oto.app.mjs +++ b/components/oto/oto.app.mjs @@ -15,6 +15,21 @@ export default { return clientStores?.map(({ storeName }) => storeName) || []; }, }, + brandId: { + type: "string", + label: "Brand ID", + description: "The brand ID of the product", + optional: true, + async options() { + const { clientStores } = await this.listBrands(); + return clientStores?.map(({ + ID: value, storeName: label, + }) => ({ + label, + value, + })) || []; + }, + }, status: { type: "string", label: "Status", diff --git a/components/oto/package.json b/components/oto/package.json index bbd0481882d4e..190bf83996cf2 100644 --- a/components/oto/package.json +++ b/components/oto/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/oto", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream OTO Components", "main": "oto.app.mjs", "keywords": [ @@ -11,5 +11,8 @@ "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^3.0.3" } } diff --git a/components/oto/sources/common/base.mjs b/components/oto/sources/common/base.mjs index 0369a693b2e21..79e4bc9831882 100644 --- a/components/oto/sources/common/base.mjs +++ b/components/oto/sources/common/base.mjs @@ -39,7 +39,7 @@ export default { throw new Error("getWebhookType is not implemented"); }, generateMeta() { - return {}; + throw new Error ("generateMeta is not implemented"); }, }, async run(event) { @@ -47,6 +47,7 @@ export default { if (!body) { return; } - console.log(body); + const meta = this.generateMeta(body); + this.$emit(body, meta); }, }; diff --git a/components/oto/sources/new-order-instant/new-order-instant.mjs b/components/oto/sources/new-order-instant/new-order-instant.mjs index e705231ba12a3..780ff9b2a2257 100644 --- a/components/oto/sources/new-order-instant/new-order-instant.mjs +++ b/components/oto/sources/new-order-instant/new-order-instant.mjs @@ -1,11 +1,12 @@ import common from "../common/base.mjs"; +import sampleEmit from "./test-event.mjs"; export default { ...common, key: "oto-new-order-instant", name: "New Order (Instant)", description: "Emit new event when a new order is placed. [See the documentation](https://apis.tryoto.com/#9671ca1f-7d06-43fc-8ee9-cf9c336b088d)", - version: "0.0.{{ts}}", + version: "0.0.1", type: "source", dedupe: "unique", methods: { @@ -13,5 +14,13 @@ export default { getWebhookType() { return "newOrders"; }, + generateMeta(event) { + return { + id: event.orderId, + summary: `New Order with ID: ${event.orderId}`, + ts: event.timestamp, + }; + }, }, + sampleEmit, }; diff --git a/components/oto/sources/new-order-instant/test-event.mjs b/components/oto/sources/new-order-instant/test-event.mjs new file mode 100644 index 0000000000000..76e0238ee9e36 --- /dev/null +++ b/components/oto/sources/new-order-instant/test-event.mjs @@ -0,0 +1,35 @@ +export default { + "orderId": "123", + "order": { + "address": { + "country": "", + "address": "", + "city": "", + "name": "", + "mobile": "", + "state": "", + }, + "orderId": "123", + "grandTotal": 1, + "weight": 1, + "salesChannel": "manual", + "createdDate": "2025-05-08T16:18:03Z", + "warehouseId": 24801, + "otoId": 30911387, + "paymentMethod": "paid", + "currency": "SAR", + "incrementId": "123", + "items": [ + { + "itemId": 14437928, + "productId": 6350018, + "qtyOrdered": 1, + "sku": "1234", + "productName": "product1", + }, + ], + "status": "assignedToWarehouse", + }, + "status": "assignedToWarehouse", + "timestamp": 1746721083000, +}; diff --git a/components/oto/sources/new-shipment-error-instant/new-shipment-error-instant.mjs b/components/oto/sources/new-shipment-error-instant/new-shipment-error-instant.mjs index 3dde452509c87..b19d7770b6eeb 100644 --- a/components/oto/sources/new-shipment-error-instant/new-shipment-error-instant.mjs +++ b/components/oto/sources/new-shipment-error-instant/new-shipment-error-instant.mjs @@ -5,7 +5,7 @@ export default { key: "oto-new-shipment-error-instant", name: "New Shipment Error (Instant)", description: "Emit new event when an error in a shipment occurs. [See the documentation](https://apis.tryoto.com/#9671ca1f-7d06-43fc-8ee9-cf9c336b088d)", - version: "0.0.{{ts}}", + version: "0.0.1", type: "source", dedupe: "unique", methods: { @@ -13,5 +13,12 @@ export default { getWebhookType() { return "shipmentError"; }, + generateMeta(event) { + return { + id: event.timestamp, + summary: "New Shipment Error", + ts: event.timestamp, + }; + }, }, }; diff --git a/components/oto/sources/order-status-updated-instant/new-order-status-updated.mjs b/components/oto/sources/order-status-updated-instant/new-order-status-updated.mjs index c7affc5549f43..de756ca80eaa7 100644 --- a/components/oto/sources/order-status-updated-instant/new-order-status-updated.mjs +++ b/components/oto/sources/order-status-updated-instant/new-order-status-updated.mjs @@ -1,11 +1,12 @@ import common from "../common/base.mjs"; +import sampleEmit from "./test-event.mjs"; export default { ...common, key: "oto-new-order-status-instant", name: "New Order Status (Instant)", description: "Emit new event when the status of an order changes. [See the documentation](https://apis.tryoto.com/#9671ca1f-7d06-43fc-8ee9-cf9c336b088d)", - version: "0.0.{{ts}}", + version: "0.0.1", type: "source", dedupe: "unique", methods: { @@ -13,5 +14,13 @@ export default { getWebhookType() { return "orderStatus"; }, + generateMeta(event) { + return { + id: event.orderId, + summary: `Status Updated for Order with ID: ${event.orderId}`, + ts: event.timestamp, + }; + }, }, + sampleEmit, }; diff --git a/components/oto/sources/order-status-updated-instant/test-event.mjs b/components/oto/sources/order-status-updated-instant/test-event.mjs new file mode 100644 index 0000000000000..b4fb9d547b92f --- /dev/null +++ b/components/oto/sources/order-status-updated-instant/test-event.mjs @@ -0,0 +1,13 @@ +export default { + "dcStatus": "", + "note": "", + "feedbackLink": "", + "shipmentWeight": 1, + "orderId": "123", + "reverseShipment": false, + "brandedTrackingURL": "", + "pickupLocationCode": "DefaultWH", + "trackingNumber": "", + "status": "delivered", + "timestamp": 1746721659000, +}; From 64de5eaa7e89ee2001da4c39a18fdf1b20c40d5e Mon Sep 17 00:00:00 2001 From: michelle0927 Date: Fri, 9 May 2025 14:38:13 -0400 Subject: [PATCH 3/5] updates --- .../actions/create-product/create-product.mjs | 16 +++----- .../get-order-details/get-order-details.mjs | 28 +++++++++++++ .../oto/actions/list-orders/list-orders.mjs | 10 +++-- .../actions/track-shipment/track-shipment.mjs | 41 ------------------- components/oto/oto.app.mjs | 26 ++++++++---- .../new-order-instant/new-order-instant.mjs | 26 ------------ .../sources/new-order-instant/test-event.mjs | 35 ---------------- .../new-shipment-error-instant.mjs | 24 ----------- ...d.mjs => order-status-updated-instant.mjs} | 4 +- 9 files changed, 61 insertions(+), 149 deletions(-) create mode 100644 components/oto/actions/get-order-details/get-order-details.mjs delete mode 100644 components/oto/actions/track-shipment/track-shipment.mjs delete mode 100644 components/oto/sources/new-order-instant/new-order-instant.mjs delete mode 100644 components/oto/sources/new-order-instant/test-event.mjs delete mode 100644 components/oto/sources/new-shipment-error-instant/new-shipment-error-instant.mjs rename components/oto/sources/order-status-updated-instant/{new-order-status-updated.mjs => order-status-updated-instant.mjs} (88%) diff --git a/components/oto/actions/create-product/create-product.mjs b/components/oto/actions/create-product/create-product.mjs index b2118064621cb..dfc21e0807bc2 100644 --- a/components/oto/actions/create-product/create-product.mjs +++ b/components/oto/actions/create-product/create-product.mjs @@ -1,5 +1,5 @@ import oto from "../../oto.app.mjs"; -import utils from "../../common/utils.mjs"; +import { parseObject } from "../../common/utils.mjs"; export default { key: "oto-create-product", @@ -28,7 +28,6 @@ export default { type: "string", label: "Tax Amount", description: "Tax Amount of the product", - optional: true, }, brandId: { propDefinition: [ @@ -78,12 +77,6 @@ export default { description: "Origin of the product", optional: true, }, - bundleItems: { - type: "boolean", - label: "Bundle Items", - description: "It can be true/ false", - optional: true, - }, customAttributes: { type: "object", label: "Custom Attributes", @@ -107,11 +100,12 @@ export default { category: this.category, hsCode: this.hsCode, itemOrigin: this.itemOrigin, - bundleItems: this.bundleItems, - customAttributes: utils.parseObject(this.customAttributes), + customAttributes: parseObject(this.customAttributes), }, }); - $.export("$summary", `Successfully created product with ID: ${response.productId}`); + if (response.productId) { + $.export("$summary", `Successfully created product with ID: ${response.productId}`); + } return response; }, }; diff --git a/components/oto/actions/get-order-details/get-order-details.mjs b/components/oto/actions/get-order-details/get-order-details.mjs new file mode 100644 index 0000000000000..f7f5d7cfe2707 --- /dev/null +++ b/components/oto/actions/get-order-details/get-order-details.mjs @@ -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; + }, +}; diff --git a/components/oto/actions/list-orders/list-orders.mjs b/components/oto/actions/list-orders/list-orders.mjs index 40a125a857934..5710406c59ef5 100644 --- a/components/oto/actions/list-orders/list-orders.mjs +++ b/components/oto/actions/list-orders/list-orders.mjs @@ -54,9 +54,13 @@ export default { orders.push(order); } - $.export("$summary", `Successfully retrieved ${orders.length} order${orders.length === 1 - ? "" - : "s"}`); + if (orders[0].items?.length) { + $.export("$summary", `Successfully retrieved ${orders.length} order${orders.length === 1 + ? "" + : "s"}`); + } else { + $.export("$summary", "No orders found"); + } return orders; }, }; diff --git a/components/oto/actions/track-shipment/track-shipment.mjs b/components/oto/actions/track-shipment/track-shipment.mjs deleted file mode 100644 index f7f0d04952aba..0000000000000 --- a/components/oto/actions/track-shipment/track-shipment.mjs +++ /dev/null @@ -1,41 +0,0 @@ -import oto from "../../oto.app.mjs"; - -export default { - key: "oto-track-shipment", - name: "Track Shipment", - 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)", - version: "0.0.1", - type: "action", - props: { - oto, - trackingNumber: { - type: "string", - label: "Tracking Number", - description: "The shipment/ tracking number that you wanna track", - }, - deliveryCompanyName: { - type: "string", - label: "Delivery Company Name", - description: "The name of the delivery company", - }, - brandName: { - propDefinition: [ - oto, - "brandName", - ], - }, - }, - async run({ $ }) { - const response = await this.oto.trackShipment({ - $, - data: { - trackingNumber: this.trackingNumber, - deliveryCompanyName: this.deliveryCompanyName, - brandName: this.brandName, - statusHistory: true, - }, - }); - $.export("$summary", `Successfully tracked shipment with tracking number: ${this.trackingNumber}`); - return response; - }, -}; diff --git a/components/oto/oto.app.mjs b/components/oto/oto.app.mjs index 906419d6e49a5..a403116c70893 100644 --- a/components/oto/oto.app.mjs +++ b/components/oto/oto.app.mjs @@ -30,6 +30,19 @@ export default { })) || []; }, }, + orderId: { + type: "string", + label: "Order ID", + description: "The ID of an order", + async options({ page }) { + const { orders } = await this.listOrders({ + params: { + page, + }, + }); + return orders?.map(({ orderId }) => orderId ) || []; + }, + }, status: { type: "string", label: "Status", @@ -67,6 +80,12 @@ export default { ...opts, }); }, + getOrderDetails(opts = {}) { + return this._makeRequest({ + path: "/orderDetails", + ...opts, + }); + }, listOrders(opts = {}) { return this._makeRequest({ path: "/orders", @@ -86,13 +105,6 @@ export default { ...opts, }); }, - trackShipment(opts = {}) { - return this._makeRequest({ - method: "POST", - path: "/trackShipment", - ...opts, - }); - }, async *paginate({ fn, args, resourceKey, max, }) { diff --git a/components/oto/sources/new-order-instant/new-order-instant.mjs b/components/oto/sources/new-order-instant/new-order-instant.mjs deleted file mode 100644 index 780ff9b2a2257..0000000000000 --- a/components/oto/sources/new-order-instant/new-order-instant.mjs +++ /dev/null @@ -1,26 +0,0 @@ -import common from "../common/base.mjs"; -import sampleEmit from "./test-event.mjs"; - -export default { - ...common, - key: "oto-new-order-instant", - name: "New Order (Instant)", - description: "Emit new event when a new order is placed. [See the documentation](https://apis.tryoto.com/#9671ca1f-7d06-43fc-8ee9-cf9c336b088d)", - version: "0.0.1", - type: "source", - dedupe: "unique", - methods: { - ...common.methods, - getWebhookType() { - return "newOrders"; - }, - generateMeta(event) { - return { - id: event.orderId, - summary: `New Order with ID: ${event.orderId}`, - ts: event.timestamp, - }; - }, - }, - sampleEmit, -}; diff --git a/components/oto/sources/new-order-instant/test-event.mjs b/components/oto/sources/new-order-instant/test-event.mjs deleted file mode 100644 index 76e0238ee9e36..0000000000000 --- a/components/oto/sources/new-order-instant/test-event.mjs +++ /dev/null @@ -1,35 +0,0 @@ -export default { - "orderId": "123", - "order": { - "address": { - "country": "", - "address": "", - "city": "", - "name": "", - "mobile": "", - "state": "", - }, - "orderId": "123", - "grandTotal": 1, - "weight": 1, - "salesChannel": "manual", - "createdDate": "2025-05-08T16:18:03Z", - "warehouseId": 24801, - "otoId": 30911387, - "paymentMethod": "paid", - "currency": "SAR", - "incrementId": "123", - "items": [ - { - "itemId": 14437928, - "productId": 6350018, - "qtyOrdered": 1, - "sku": "1234", - "productName": "product1", - }, - ], - "status": "assignedToWarehouse", - }, - "status": "assignedToWarehouse", - "timestamp": 1746721083000, -}; diff --git a/components/oto/sources/new-shipment-error-instant/new-shipment-error-instant.mjs b/components/oto/sources/new-shipment-error-instant/new-shipment-error-instant.mjs deleted file mode 100644 index b19d7770b6eeb..0000000000000 --- a/components/oto/sources/new-shipment-error-instant/new-shipment-error-instant.mjs +++ /dev/null @@ -1,24 +0,0 @@ -import common from "../common/base.mjs"; - -export default { - ...common, - key: "oto-new-shipment-error-instant", - name: "New Shipment Error (Instant)", - description: "Emit new event when an error in a shipment occurs. [See the documentation](https://apis.tryoto.com/#9671ca1f-7d06-43fc-8ee9-cf9c336b088d)", - version: "0.0.1", - type: "source", - dedupe: "unique", - methods: { - ...common.methods, - getWebhookType() { - return "shipmentError"; - }, - generateMeta(event) { - return { - id: event.timestamp, - summary: "New Shipment Error", - ts: event.timestamp, - }; - }, - }, -}; diff --git a/components/oto/sources/order-status-updated-instant/new-order-status-updated.mjs b/components/oto/sources/order-status-updated-instant/order-status-updated-instant.mjs similarity index 88% rename from components/oto/sources/order-status-updated-instant/new-order-status-updated.mjs rename to components/oto/sources/order-status-updated-instant/order-status-updated-instant.mjs index de756ca80eaa7..decb991f65f0a 100644 --- a/components/oto/sources/order-status-updated-instant/new-order-status-updated.mjs +++ b/components/oto/sources/order-status-updated-instant/order-status-updated-instant.mjs @@ -3,8 +3,8 @@ import sampleEmit from "./test-event.mjs"; export default { ...common, - key: "oto-new-order-status-instant", - name: "New Order Status (Instant)", + key: "oto-order-status-updated-instant", + name: "Order Status Updated (Instant)", description: "Emit new event when the status of an order changes. [See the documentation](https://apis.tryoto.com/#9671ca1f-7d06-43fc-8ee9-cf9c336b088d)", version: "0.0.1", type: "source", From cae8bf76ba1dde81e2108079de1d86d94afdeb4e Mon Sep 17 00:00:00 2001 From: michelle0927 Date: Fri, 9 May 2025 14:41:50 -0400 Subject: [PATCH 4/5] pnpm-lock.yaml --- pnpm-lock.yaml | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4dc8f6929af50..57ebaf4c9cab9 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -9228,7 +9228,11 @@ importers: components/osu: {} - components/oto: {} + components/oto: + dependencies: + '@pipedream/platform': + specifier: ^3.0.3 + version: 3.0.3 components/otter_waiver: dependencies: @@ -15313,14 +15317,6 @@ importers: specifier: ^6.0.0 version: 6.2.0 - modelcontextprotocol/node_modules2/@modelcontextprotocol/sdk/dist/cjs: {} - - modelcontextprotocol/node_modules2/@modelcontextprotocol/sdk/dist/esm: {} - - modelcontextprotocol/node_modules2/zod-to-json-schema/dist/cjs: {} - - modelcontextprotocol/node_modules2/zod-to-json-schema/dist/esm: {} - packages/browsers: dependencies: '@sparticuz/chromium': From 2ab4e4bcbd8f58771686f744b1ab06fb61dd32ae Mon Sep 17 00:00:00 2001 From: michelle0927 Date: Fri, 9 May 2025 14:57:40 -0400 Subject: [PATCH 5/5] updates --- components/oto/common/constants.mjs | 2 -- components/oto/oto.app.mjs | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/components/oto/common/constants.mjs b/components/oto/common/constants.mjs index 2c034bb610f90..3bf20ef23847b 100644 --- a/components/oto/common/constants.mjs +++ b/components/oto/common/constants.mjs @@ -59,8 +59,6 @@ const STATUSES = [ "confirmedReturn", "approved", "rejected", - "reverseShipmentCanceled", - "reverseConfirmReturn", "returnReverseComment", ]; diff --git a/components/oto/oto.app.mjs b/components/oto/oto.app.mjs index a403116c70893..5b809da7096c7 100644 --- a/components/oto/oto.app.mjs +++ b/components/oto/oto.app.mjs @@ -119,14 +119,14 @@ export default { let total, count = 0; do { const response = await fn(args); - const items = response[resourceKey]; + const items = response[resourceKey] ?? []; for (const item of items) { yield item; if (max && ++count >= max) { return; } } - total = items?.length; + total = items.length; args.params.page++; } while (total === args.params.perPage); },