diff --git a/components/remote_retrieval/actions/create-order/create-order.mjs b/components/remote_retrieval/actions/create-order/create-order.mjs new file mode 100644 index 0000000000000..012f9a10ea381 --- /dev/null +++ b/components/remote_retrieval/actions/create-order/create-order.mjs @@ -0,0 +1,177 @@ +import app from "../../remote_retrieval.app.mjs"; + +export default { + key: "remote_retrieval-create-order", + name: "Create Order", + description: "Create order in Remote Retrieval. [See the documentation](https://www.remoteretrieval.com/api-integration/#create-order)", + version: "0.0.1", + type: "action", + props: { + app, + typeOfEquipment: { + propDefinition: [ + app, + "typeOfEquipment", + ], + }, + orderType: { + propDefinition: [ + app, + "orderType", + ], + }, + email: { + propDefinition: [ + app, + "email", + ], + }, + name: { + propDefinition: [ + app, + "name", + ], + }, + addressLine1: { + propDefinition: [ + app, + "addressLine1", + ], + }, + addressLine2: { + propDefinition: [ + app, + "addressLine2", + ], + }, + addressCity: { + propDefinition: [ + app, + "addressCity", + ], + }, + addressState: { + propDefinition: [ + app, + "addressState", + ], + }, + addressCountry: { + propDefinition: [ + app, + "addressCountry", + ], + }, + addressZip: { + propDefinition: [ + app, + "addressZip", + ], + }, + phone: { + propDefinition: [ + app, + "phone", + ], + }, + returnPersonName: { + propDefinition: [ + app, + "returnPersonName", + ], + }, + returnCompanyName: { + propDefinition: [ + app, + "returnCompanyName", + ], + }, + returnAddressLine1: { + propDefinition: [ + app, + "returnAddressLine1", + ], + }, + returnAddressLine2: { + propDefinition: [ + app, + "returnAddressLine2", + ], + }, + returnAddressCity: { + propDefinition: [ + app, + "returnAddressCity", + ], + }, + returnAddressState: { + propDefinition: [ + app, + "returnAddressState", + ], + }, + returnAddressCountry: { + propDefinition: [ + app, + "returnAddressCountry", + ], + }, + returnAddressZip: { + propDefinition: [ + app, + "returnAddressZip", + ], + }, + companyEmail: { + propDefinition: [ + app, + "companyEmail", + ], + }, + companyPhone: { + propDefinition: [ + app, + "companyPhone", + ], + }, + }, + + async run({ $ }) { + const response = await this.app.createOrder({ + $, + data: { + orders: [ + { + type_of_equipment: this.typeOfEquipment, + order_type: this.orderType, + employee_info: { + email: this.email, + name: this.name, + address_line_1: this.addressLine1, + address_line_2: this.addressLine2 || "", + address_city: this.addressCity, + address_state: this.addressState, + address_country: this.addressCountry, + address_zip: this.addressZip, + phone: this.phone, + }, + company_info: { + return_person_name: this.returnPersonName, + return_company_name: this.returnCompanyName, + return_address_line_1: this.returnAddressLine1, + return_address_line_2: this.returnAddressLine2 || "", + return_address_city: this.returnAddressCity, + return_address_state: this.returnAddressState, + return_address_country: this.returnAddressCountry, + return_address_zip: this.returnAddressZip, + email: this.companyEmail, + phone: this.companyPhone, + }, + }, + ], + }, + }); + $.export("$summary", "Successfully created order"); + return response; + }, +}; diff --git a/components/remote_retrieval/actions/get-order-details/get-order-details.mjs b/components/remote_retrieval/actions/get-order-details/get-order-details.mjs new file mode 100644 index 0000000000000..388bd0ea4d602 --- /dev/null +++ b/components/remote_retrieval/actions/get-order-details/get-order-details.mjs @@ -0,0 +1,28 @@ +import app from "../../remote_retrieval.app.mjs"; + +export default { + key: "remote_retrieval-get-order-details", + name: "Get Order Details", + description: "Get the details of the specified order. [See the documentation](https://www.remoteretrieval.com/api-integration/#order-detail)", + version: "0.0.1", + type: "action", + props: { + app, + orderId: { + propDefinition: [ + app, + "orderId", + ], + }, + }, + async run({ $ }) { + const response = await this.app.getOrderDetails({ + $, + params: { + ORDER_ID: this.orderId, + }, + }); + $.export("$summary", `Successfully retrieved details of order with ID '${this.orderId}'`); + return response; + }, +}; diff --git a/components/remote_retrieval/actions/get-orders/get-orders.mjs b/components/remote_retrieval/actions/get-orders/get-orders.mjs new file mode 100644 index 0000000000000..a44211f7b3588 --- /dev/null +++ b/components/remote_retrieval/actions/get-orders/get-orders.mjs @@ -0,0 +1,19 @@ +import app from "../../remote_retrieval.app.mjs"; + +export default { + key: "remote_retrieval-get-orders", + name: "Get Orders", + description: "Get a list of all orders. [See the documentation](https://www.remoteretrieval.com/api-integration/#all-orders)", + version: "0.0.1", + type: "action", + props: { + app, + }, + async run({ $ }) { + const response = await this.app.getOrders({ + $, + }); + $.export("$summary", `Successfully retrieved ${response.results.length} orders`); + return response; + }, +}; diff --git a/components/remote_retrieval/actions/get-pending-orders/get-pending-orders.mjs b/components/remote_retrieval/actions/get-pending-orders/get-pending-orders.mjs deleted file mode 100644 index 72c99b820af89..0000000000000 --- a/components/remote_retrieval/actions/get-pending-orders/get-pending-orders.mjs +++ /dev/null @@ -1,27 +0,0 @@ -import app from "../../remote_retrieval.app.mjs"; -import utils from "../../common/utils.mjs"; - -export default { - key: "remote_retrieval-get-pending-orders", - name: "Get Pending Orders", - description: "Retrieve a list of the orders for which the payment process has not been completed.[See the documentation](https://www.remoteretrieval.com/api-documentation/#pending-orders)", - type: "action", - version: "0.0.1", - props: { - app, - }, - methods: {}, - async run({ $ }) { - const results = this.app.getResourcesStream({ - resourceFn: this.app.getPendingOrders, - resourceFnArgs: { - $, - }, - }); - const orders = await utils.streamIterator(results); - - $.export("$summary", `Successfully retrieved ${orders.length} pending order(s).`); - - return orders; - }, -}; diff --git a/components/remote_retrieval/actions/get-specific-order/get-specific-order.mjs b/components/remote_retrieval/actions/get-specific-order/get-specific-order.mjs deleted file mode 100644 index fdc1c862a2c06..0000000000000 --- a/components/remote_retrieval/actions/get-specific-order/get-specific-order.mjs +++ /dev/null @@ -1,29 +0,0 @@ -import app from "../../remote_retrieval.app.mjs"; - -export default { - key: "remote_retrieval-get-specific-order", - name: "Get Specific Order", - description: "Fetches a single device return order. [See the documentation](https://www.remoteretrieval.com/api-documentation/#order-detail)", - type: "action", - version: "0.0.1", - props: { - app, - oid: { - propDefinition: [ - app, - "oid", - ], - }, - }, - async run({ $ }) { - const { oid } = this; - const response = await this.app.getOrder({ - $, - oid, - }); - - $.export("$summary", `Successfully retrieved order with ID \`${this.oid}\`.`); - - return response; - }, -}; diff --git a/components/remote_retrieval/common/constants.mjs b/components/remote_retrieval/common/constants.mjs index fb66a7441649c..80516c5465c3b 100644 --- a/components/remote_retrieval/common/constants.mjs +++ b/components/remote_retrieval/common/constants.mjs @@ -1,9 +1,10 @@ -const BASE_URL = "https://remoteretrieval.com/RR-enterprise/remoteretrieval/public/index.php"; -const VERSION_PATH = "/api/v1"; -const DEFAULT_MAX = 600; - -export default { - BASE_URL, - VERSION_PATH, - DEFAULT_MAX, +export default { + EQUIPMENT_TYPES: [ + "Laptop", + "Monitor", + ], + ORDER_TYPES: [ + "Return To Company", + "Sell this Equipment", + ], }; diff --git a/components/remote_retrieval/package.json b/components/remote_retrieval/package.json index e386b5aa7437b..d9242dd25524c 100644 --- a/components/remote_retrieval/package.json +++ b/components/remote_retrieval/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/remote_retrieval", - "version": "0.1.0", + "version": "0.1.1", "description": "Pipedream Remote Retrieval Components", "main": "remote_retrieval.app.mjs", "keywords": [ @@ -13,6 +13,6 @@ "access": "public" }, "dependencies": { - "@pipedream/platform": "^3.0.0" + "@pipedream/platform": "^3.0.1" } } diff --git a/components/remote_retrieval/remote_retrieval.app.mjs b/components/remote_retrieval/remote_retrieval.app.mjs index f5a22fabde358..aa16fc59bca2c 100644 --- a/components/remote_retrieval/remote_retrieval.app.mjs +++ b/components/remote_retrieval/remote_retrieval.app.mjs @@ -5,114 +5,169 @@ export default { type: "app", app: "remote_retrieval", propDefinitions: { - oid: { + orderId: { type: "string", label: "Order ID", - description: "The ID of the order to retrieve.", - async options({ page }) { - const orders = await this.getDeviceReturnOrders({ - params: { - page: page + 1, - }, - }); - if (orders.message === "Data not found!") { - return []; - } - return orders?.map(({ - order_id: value, shipments, + description: "ID of the Order", + async options() { + const response = await this.getOrders(); + const orderIds = response.results; + return orderIds.map(({ + order_id, employee_info, }) => ({ - value, - label: `Order ID: ${value} - ${shipments.device_type}`, - })) || []; + value: order_id, + label: employee_info.name, + })); }, }, + typeOfEquipment: { + type: "string", + label: "Type of Equipment", + description: "The type of equipment", + options: constants.EQUIPMENT_TYPES, + }, + orderType: { + type: "string", + label: "Order Type", + description: "The type of order", + options: constants.ORDER_TYPES, + }, + email: { + type: "string", + label: "Employee Email", + description: "Employee email address", + }, + name: { + type: "string", + label: "Employee Name", + description: "Employee full name", + }, + addressLine1: { + type: "string", + label: "Employee Address Line 1", + description: "Employee Address in line 1", + }, + addressLine2: { + type: "string", + label: "Employee Address Line 2", + description: "Employee Address in line 2, it is not a mandatory field", + optional: true, + }, + addressCity: { + type: "string", + label: "Employee City", + description: "Employee city", + }, + addressState: { + type: "string", + label: "Employee State", + description: "Employee state", + }, + addressCountry: { + type: "string", + label: "Employee Country", + description: "Employee country", + }, + addressZip: { + type: "string", + label: "Employee Zip", + description: "Employee zip", + }, + phone: { + type: "string", + label: "Employee Phone", + description: "Employee phone", + }, + returnPersonName: { + type: "string", + label: "Return Person Name", + description: "Company person name", + }, + returnCompanyName: { + type: "string", + label: "Return Company Name", + description: "Company name", + }, + returnAddressLine1: { + type: "string", + label: "Return Address Line 1", + description: "Company address in line 1", + }, + returnAddressLine2: { + type: "string", + label: "Return Address Line 2", + description: "Company address in line 2, it is not a mandatory field", + optional: true, + }, + returnAddressCity: { + type: "string", + label: "Return Address City", + description: "Company city", + }, + returnAddressState: { + type: "string", + label: "Return Address State", + description: "Company state", + }, + returnAddressCountry: { + type: "string", + label: "Return Address Country", + description: "Company country", + }, + returnAddressZip: { + type: "string", + label: "Return Address Zip", + description: "Company zip", + }, + companyEmail: { + type: "string", + label: "Company Email", + description: "Company email", + }, + companyPhone: { + type: "string", + label: "Company Phone", + description: "Company phone", + }, }, methods: { - getBaseUrl() { - return `${constants.BASE_URL}${constants.VERSION_PATH}`; - }, - getUrl(path, url) { - return url || `${this.getBaseUrl()}${path}`; - }, - getHeaders(headers) { - return { - "Content-Type": "application/json", - "Authorization": `Bearer ${this.$auth.api_key}`, - ...headers, - }; - }, - makeRequest({ - step = this, path, headers, url, ...args - } = {}) { - - const config = { - headers: this.getHeaders(headers), - url: this.getUrl(path, url), - ...args, - }; - - return axios(step, config); + _baseUrl() { + return "https://remoteretrieval.com/RR-enterprise/remoteretrieval/public/index.php/api/v1"; }, - post(args = {}) { - return this.makeRequest({ - method: "post", - ...args, + async _makeRequest(opts = {}) { + const { + $ = this, + path, + headers, + ...otherOpts + } = opts; + return axios($, { + ...otherOpts, + url: this._baseUrl() + path, + headers: { + ...headers, + Authorization: `Bearer ${this.$auth.api_key}`, + }, }); }, - getOrder({ - oid, ...args - } = {}) { - return this.makeRequest({ - path: `/device_returns?oid=${oid}/`, + async createOrder(args = {}) { + return this._makeRequest({ + path: "/create-order", + method: "post", ...args, }); }, - getDeviceReturnOrders(args = {}) { - return this.makeRequest({ - path: "/device_returns", + async getOrders(args = {}) { + return this._makeRequest({ + path: "/orders", ...args, }); }, - getPendingOrders(args = {}) { - return this.makeRequest({ - path: "/pending-orders/", + async getOrderDetails(args = {}) { + return this._makeRequest({ + path: "/device_returns", ...args, }); }, - async *getResourcesStream({ - resourceFn, - resourceFnArgs, - max = constants.DEFAULT_MAX, - }) { - let page = 1; - let resourcesCount = 0; - - while (true) { - const response = - await resourceFn({ - ...resourceFnArgs, - params: { - page, - ...resourceFnArgs?.params, - }, - }); - - if (!response || response.message === "Data not found!") { - console.log("No more resources found"); - return; - } - - for (const resource of response) { - yield resource; - resourcesCount += 1; - - if (resourcesCount >= max) { - return; - } - } - - page++; - } - }, }, }; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 351f394949037..4ee35fc6bd2ed 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -8429,7 +8429,7 @@ importers: components/remote_retrieval: dependencies: '@pipedream/platform': - specifier: ^3.0.0 + specifier: ^3.0.1 version: 3.0.3 components/render: {} @@ -44172,4 +44172,4 @@ snapshots: zwitch@1.0.5: {} - zwitch@2.0.4: {} + zwitch@2.0.4: {} \ No newline at end of file