- 
                Notifications
    You must be signed in to change notification settings 
- Fork 5.5k
[Components] remote_retrieval #12998 #13716
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 7 commits
4175f31
              de7e522
              ea6be31
              5f8b0c0
              9b029bf
              d3f634d
              339d4f5
              b9276cf
              2723091
              a2eabaf
              e758e3a
              c6d0022
              File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,200 @@ | ||
| 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-documentation/#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({ $ }) { | ||
| console.log({ | ||
| typeOfEquipment: this.typeOfEquipment, | ||
| orderType: this.orderType, | ||
| email: this.email, | ||
| name: this.name, | ||
| addressLine1: this.addressLine1, | ||
| addressLine2: this.addressLine2, | ||
| addressCity: this.addressCity, | ||
| addressState: this.addressState, | ||
| addressCountry: this.addressCountry, | ||
| addressZip: this.addressZip, | ||
| phone: this.phone, | ||
| returnPersonName: this.returnPersonName, | ||
| returnCompanyName: this.returnCompanyName, | ||
| returnAddressLine1: this.returnAddressLine1, | ||
| returnAddressLine2: this.returnAddressLine2, | ||
| returnAddressCity: this.returnAddressCity, | ||
| returnAddressState: this.returnAddressState, | ||
| returnAddressCountry: this.returnAddressCountry, | ||
| returnAddressZip: this.returnAddressZip, | ||
| companyEmail: this.companyEmail, | ||
| companyPhone: this.companyPhone, | ||
| }); | ||
| 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
    
   There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add input validation and error handling The order creation lacks proper validation and error handling: 
  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;
+  }
 },
 | ||
| $.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-completed-orders", | ||
| name: "Get Completed Orders", | ||
| description: "Get a list of orders where payment has already been completed. [See the documentation](https://www.remoteretrieval.com/api-documentation/#completed-orders)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| app, | ||
| page: { | ||
| propDefinition: [ | ||
| app, | ||
| "page", | ||
| ], | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const response = await this.app.getCompletedOrders({ | ||
| $, | ||
| params: { | ||
| page: this.page, | ||
| }, | ||
| }); | ||
| $.export("$summary", `Successfully sent request. Response: '${response.message}'`); | ||
| 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-new-orders", | ||
| name: "Get New Orders", | ||
| description: "Get a list of new orders. [See the documentation](https://www.remoteretrieval.com/api-documentation/#new-orders)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| app, | ||
| page: { | ||
| propDefinition: [ | ||
| app, | ||
| "page", | ||
| ], | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const response = await this.app.getNewOrders({ | ||
| $, | ||
| params: { | ||
| page: this.page, | ||
| }, | ||
| }); | ||
| $.export("$summary", `Successfully sent request. Response: '${response.message}'`); | ||
| 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-documentation/#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
    
   There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add error handling and input validation The run method needs proper error handling and input validation: 
  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
 
        Suggested change
       
 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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-documentation/#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
    
   There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
 
        Suggested change
       
 | ||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||
| 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", | ||
| ], | ||
| }; | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove debug console.log statement
The console.log statement contains sensitive PII (email, phone, address) and should be removed from production code. Consider using proper logging levels if debugging is needed.