Skip to content

[Components] remote_retrieval #12998 #13716

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 12 commits into from
Dec 10, 2024
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
177 changes: 177 additions & 0 deletions components/remote_retrieval/actions/create-order/create-order.mjs
Original file line number Diff line number Diff line change
@@ -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,
},
},
],
},
});
Comment on lines +140 to +173
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Add input validation and error handling

The order creation lacks proper validation and error handling:

  1. Required fields should be validated
  2. Address format should be validated
  3. Email and phone formats should be verified
  4. API errors should be handled gracefully
 async run({ $ }) {
+  // Validate required fields
+  const requiredFields = ['email', 'name', 'addressLine1', 'addressCity', 'addressState'];
+  for (const field of requiredFields) {
+    if (!this[field]) {
+      throw new Error(`${field} is required`);
+    }
+  }
+
+  // Validate email format
+  if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(this.email)) {
+    throw new Error('Invalid email format');
+  }
+
+  try {
     const response = await this.app.createOrder({
       // ... existing code
     });
     $.export("$summary", "Successfully created order");
     return response;
+  } catch (error) {
+    $.export("$summary", `Failed to create order: ${error.message}`);
+    throw error;
+  }
 },

Committable suggestion skipped: line range outside the PR's diff.

$.export("$summary", "Successfully created order");
return response;
},
};
Original file line number Diff line number Diff line change
@@ -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;
},
Comment on lines +18 to +27
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Add error handling and input validation

The run method needs proper error handling and input validation:

  1. Validate orderId format before API call
  2. Handle API errors gracefully
  3. Consider adding request timeout
 async run({ $ }) {
+  if (!this.orderId) {
+    throw new Error("Order ID is required");
+  }
+  try {
     const response = await this.app.getOrderDetails({
       $,
       params: {
         ORDER_ID: this.orderId,
       },
     });
     $.export("$summary", `Successfully retrieved details of order with ID '${this.orderId}'`);
     return response;
+  } catch (error) {
+    $.export("$summary", `Failed to retrieve order details: ${error.message}`);
+    throw error;
+  }
 },
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
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;
},
async run({ $ }) {
if (!this.orderId) {
throw new Error("Order ID is required");
}
try {
const response = await this.app.getOrderDetails({
$,
params: {
ORDER_ID: this.orderId,
},
});
$.export("$summary", `Successfully retrieved details of order with ID '${this.orderId}'`);
return response;
} catch (error) {
$.export("$summary", `Failed to retrieve order details: ${error.message}`);
throw error;
}
},

};
19 changes: 19 additions & 0 deletions components/remote_retrieval/actions/get-orders/get-orders.mjs
Original file line number Diff line number Diff line change
@@ -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;
},
Comment on lines +12 to +18
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add error handling

The run method should include proper error handling to provide meaningful feedback when API calls fail.

 async run({ $ }) {
+  try {
     const response = await this.app.getOrders({
       $,
     });
     $.export("$summary", `Successfully retrieved ${response.results.length} orders`);
     return response;
+  } catch (error) {
+    $.export("$summary", `Failed to retrieve orders: ${error.message}`);
+    throw error;
+  }
 },
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
async run({ $ }) {
const response = await this.app.getOrders({
$,
});
$.export("$summary", `Successfully retrieved ${response.results.length} orders`);
return response;
},
async run({ $ }) {
try {
const response = await this.app.getOrders({
$,
});
$.export("$summary", `Successfully retrieved ${response.results.length} orders`);
return response;
} catch (error) {
$.export("$summary", `Failed to retrieve orders: ${error.message}`);
throw error;
}
},

};

This file was deleted.

This file was deleted.

17 changes: 9 additions & 8 deletions components/remote_retrieval/common/constants.mjs
Original file line number Diff line number Diff line change
@@ -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",
],
};
4 changes: 2 additions & 2 deletions components/remote_retrieval/package.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand All @@ -13,6 +13,6 @@
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.0.0"
"@pipedream/platform": "^3.0.1"
}
}
Loading
Loading