Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
32 changes: 32 additions & 0 deletions components/epsy/actions/email-lookup/email-lookup.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import app from "../../epsy.app.mjs";

export default {
key: "epsy-email-lookup",
name: "Email Lookup",
description: "Request a lookup for the provided email. [See the documentation](https://irbis.espysys.com/developer/)",
version: "0.0.1",
type: "action",
props: {
app,
value: {
propDefinition: [
app,
"value",
],
},
},

async run({ $ }) {
const response = await this.app.emailLookup({
$,
params: {
value: this.value,
lookupId: "67",
},
});

$.export("$summary", `Successfully sent request. Use the ID to get the results: '${response.id}'`);

return response;
},
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 and make lookupId configurable

Several improvements are recommended for the run method:

  1. The lookupId should be configurable through props rather than hardcoded
  2. Add error handling for failed requests
  3. Add input validation for the value parameter
  4. Add type checking for the response

Here's a suggested implementation:

   props: {
     app,
     value: {
       propDefinition: [
         app,
         "value",
       ],
     },
+    lookupId: {
+      type: "string",
+      label: "Lookup ID",
+      description: "The ID of the lookup to perform",
+      default: "67",
+    },
   },

   async run({ $ }) {
+    if (!this.value) {
+      throw new Error("Value is required");
+    }
+
+    try {
       const response = await this.app.emailLookup({
         $,
         params: {
           value: this.value,
-          lookupId: "67",
+          lookupId: this.lookupId,
         },
       });
+
+      if (!response?.id) {
+        throw new Error("Invalid response from API");
+      }

       $.export("$summary", `Successfully sent request. Use the ID to get the results: '${response.id}'`);

       return response;
+    } catch (error) {
+      throw new Error(`Email lookup failed: ${error.message}`);
+    }
   },
📝 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.emailLookup({
$,
params: {
value: this.value,
lookupId: "67",
},
});
$.export("$summary", `Successfully sent request. Use the ID to get the results: '${response.id}'`);
return response;
},
props: {
app,
value: {
propDefinition: [
app,
"value",
],
},
lookupId: {
type: "string",
label: "Lookup ID",
description: "The ID of the lookup to perform",
default: "67",
},
},
async run({ $ }) {
if (!this.value) {
throw new Error("Value is required");
}
try {
const response = await this.app.emailLookup({
$,
params: {
value: this.value,
lookupId: this.lookupId,
},
});
if (!response?.id) {
throw new Error("Invalid response from API");
}
$.export("$summary", `Successfully sent request. Use the ID to get the results: '${response.id}'`);
return response;
} catch (error) {
throw new Error(`Email lookup failed: ${error.message}`);
}
},

};
38 changes: 38 additions & 0 deletions components/epsy/actions/get-lookup-results/get-lookup-results.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import app from "../../epsy.app.mjs";

export default {
key: "epsy-get-lookup-results",
name: "Get Lookup Results",
description: "Get the results of the lookup with the provided ID. [See the documentation](https://irbis.espysys.com/developer/)",
version: "0.0.1",
type: "action",
props: {
app,
value: {
propDefinition: [
app,
"value",
],
},
searchId: {
propDefinition: [
app,
"searchId",
],
},
},

async run({ $ }) {
const response = await this.app.getLookupResults({
$,
searchId: this.searchId,
params: {
value: this.value,
},
});

$.export("$summary", `Successfully retrieved the details of the request with ID: '${this.searchId}'`);

return response;
},
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 and improve response handling

The current implementation could be more robust. Consider these essential improvements:

  1. Add try-catch block for API call error handling
  2. Validate inputs before making the request
  3. Add type checking for the response
  4. Include meaningful details in the success message (e.g., number of results)
 async run({ $ }) {
+    if (!this.searchId?.trim()) {
+      throw new Error("searchId is required");
+    }
+
+    try {
       const response = await this.app.getLookupResults({
         $,
         searchId: this.searchId,
         params: {
           value: this.value,
         },
       });
 
-      $.export("$summary", `Successfully retrieved the details of the request with ID: '${this.searchId}'`);
+      const resultCount = Array.isArray(response?.results) ? response.results.length : 0;
+      $.export("$summary", `Successfully retrieved ${resultCount} result(s) for request ID: '${this.searchId}'`);
 
+      if (!response?.results) {
+        throw new Error("Unexpected response format");
+      }
+
       return response;
+    } catch (error) {
+      throw new Error(`Failed to get lookup results: ${error.message}`);
+    }
   },
📝 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.getLookupResults({
$,
searchId: this.searchId,
params: {
value: this.value,
},
});
$.export("$summary", `Successfully retrieved the details of the request with ID: '${this.searchId}'`);
return response;
},
async run({ $ }) {
if (!this.searchId?.trim()) {
throw new Error("searchId is required");
}
try {
const response = await this.app.getLookupResults({
$,
searchId: this.searchId,
params: {
value: this.value,
},
});
const resultCount = Array.isArray(response?.results) ? response.results.length : 0;
$.export("$summary", `Successfully retrieved ${resultCount} result(s) for request ID: '${this.searchId}'`);
if (!response?.results) {
throw new Error("Unexpected response format");
}
return response;
} catch (error) {
throw new Error(`Failed to get lookup results: ${error.message}`);
}
},

};
32 changes: 32 additions & 0 deletions components/epsy/actions/name-lookup/name-lookup.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import app from "../../epsy.app.mjs";

export default {
key: "epsy-name-lookup",
name: "Name Lookup",
description: "Request a lookup for the provided name. [See the documentation](https://irbis.espysys.com/developer/)",
version: "0.0.1",
type: "action",
props: {
app,
value: {
propDefinition: [
app,
"value",
],
},
},

async run({ $ }) {
const response = await this.app.nameLookup({
$,
params: {
value: this.value,
lookupId: "149",
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

Move hardcoded lookupId to configuration

The lookupId: "149" is hardcoded. This should be moved to a configuration file or environment variable for better maintainability.

},
});
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

API integration appears to be properly implemented but lacks explicit error handling

The verification reveals:

  1. The API endpoint /developer/combined_name is properly implemented in epsy.app.mjs
  2. The request is handled through a common _makeRequest method using axios
  3. However, there's no explicit error handling at either the app level or in the name-lookup action

Recommendations:

  • Add try-catch block in the name-lookup action to handle potential API errors
  • Consider implementing error handling in the _makeRequest method to standardize error responses
  • Document the expected response structure for better maintainability
🔗 Analysis chain

Verify API integration and response handling

Please verify:

  1. The API endpoint implementation in the app file
  2. The expected response structure
  3. Error handling in the app.nameLookup method
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check app.nameLookup implementation
ast-grep --pattern 'nameLookup({ $_, params }) {
  $$$
}'

# Check for error handling in app file
rg -A 5 "throw new Error" "components/epsy/"

Length of output: 104


Script:

#!/bin/bash
# Search for nameLookup method implementation with broader pattern
ast-grep --pattern 'nameLookup($$$) {
  $$$
}'

# Search for files containing nameLookup references
rg "nameLookup" -A 5

# Search for API-related error handling patterns
rg "catch|throw" -A 3 "components/epsy/"

# Look for any configuration or type definitions related to nameLookup
fd "nameLookup" --type f

Length of output: 925


Script:

#!/bin/bash
# Check the _makeRequest implementation for error handling
ast-grep --pattern '_makeRequest($$$) {
  $$$
}'

# Look for base request handling or HTTP client setup
rg "_makeRequest" -A 10 "components/epsy/"

# Check if there's any common error handling
rg "class EpsyError|class ApiError" "components/epsy/"

Length of output: 2185


$.export("$summary", `Successfully sent request. Use the ID to get the results: '${response.id}'`);

return response;
},
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 several improvements:

  1. Add try-catch block for API call error handling
  2. Validate input before making the API call
  3. Add type checking for the response

Here's a suggested implementation:

  async run({ $ }) {
+   if (!this.value?.trim()) {
+     throw new Error("Name value cannot be empty");
+   }
+
+   try {
      const response = await this.app.nameLookup({
        $,
        params: {
          value: this.value,
-         lookupId: "149",
+         lookupId: process.env.EPSY_LOOKUP_ID,
        },
      });

+     if (!response?.id) {
+       throw new Error("Invalid response from API");
+     }

      $.export("$summary", `Successfully sent request. Use the ID to get the results: '${response.id}'`);

      return response;
+   } catch (error) {
+     throw new Error(`Name lookup failed: ${error.message}`);
+   }
  },
📝 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.nameLookup({
$,
params: {
value: this.value,
lookupId: "149",
},
});
$.export("$summary", `Successfully sent request. Use the ID to get the results: '${response.id}'`);
return response;
},
async run({ $ }) {
if (!this.value?.trim()) {
throw new Error("Name value cannot be empty");
}
try {
const response = await this.app.nameLookup({
$,
params: {
value: this.value,
lookupId: process.env.EPSY_LOOKUP_ID,
},
});
if (!response?.id) {
throw new Error("Invalid response from API");
}
$.export("$summary", `Successfully sent request. Use the ID to get the results: '${response.id}'`);
return response;
} catch (error) {
throw new Error(`Name lookup failed: ${error.message}`);
}
},

};
81 changes: 76 additions & 5 deletions components/epsy/epsy.app.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,82 @@
import { axios } from "@pipedream/platform";

export default {
type: "app",
app: "epsy",
propDefinitions: {},
propDefinitions: {
value: {
type: "string",
label: "Value",
description: "Value to lookup",
},
searchId: {
type: "string",
label: "Search ID",
description: "ID of the search",
async options() {
const searchIds = await this.getSearchIds();
return searchIds.map(({
id, type,
}) => ({
label: type,
value: id,
}));
},
},
},
methods: {
// this.$auth contains connected account data
authKeys() {
console.log(Object.keys(this.$auth));
_baseUrl() {
return "https://irbis.espysys.com/api";
},
async _makeRequest(opts = {}) {
const {
$ = this,
path,
headers,
params,
...otherOpts
} = opts;
return axios($, {
...otherOpts,
url: this._baseUrl() + path,
headers: {
...headers,
"accept": "application/json",
"content-type": "application/json",
},
params: {
...params,
key: `${this.$auth.api_key}`,
},
});
},
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 in the _makeRequest method

Currently, the _makeRequest method does not include error handling. Consider adding error handling to manage API request failures gracefully, ensuring that errors are caught and meaningful feedback is provided.

Apply this diff to add basic error handling:

async _makeRequest(opts = {}) {
  const {
    $ = this,
    path,
    headers,
    params,
    ...otherOpts
  } = opts;
- return axios($, {
-   ...otherOpts,
-   url: this._baseUrl() + path,
-   headers: {
-     ...headers,
-     "accept": "application/json",
-     "content-type": "application/json",
-   },
-   params: {
-     ...params,
-     key: `${this.$auth.api_key}`,
-   },
- });
+ try {
+   return await axios($, {
+     ...otherOpts,
+     url: this._baseUrl() + path,
+     headers: {
+       ...headers,
+       "accept": "application/json",
+       "content-type": "application/json",
+     },
+     params: {
+       ...params,
+       key: `${this.$auth.api_key}`,
+     },
+   });
+ } catch (error) {
+   $.emit("error", error);
+   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 _makeRequest(opts = {}) {
const {
$ = this,
path,
headers,
params,
...otherOpts
} = opts;
return axios($, {
...otherOpts,
url: this._baseUrl() + path,
headers: {
...headers,
"accept": "application/json",
"content-type": "application/json",
},
params: {
...params,
key: `${this.$auth.api_key}`,
},
});
},
async _makeRequest(opts = {}) {
const {
$ = this,
path,
headers,
params,
...otherOpts
} = opts;
try {
return await axios($, {
...otherOpts,
url: this._baseUrl() + path,
headers: {
...headers,
"accept": "application/json",
"content-type": "application/json",
},
params: {
...params,
key: `${this.$auth.api_key}`,
},
});
} catch (error) {
$.emit("error", error);
throw error;
}
},

async emailLookup(args = {}) {
return this._makeRequest({
path: "/developer/combined_email",
method: "post",
...args,
});
},
async nameLookup(args = {}) {
return this._makeRequest({
path: "/developer/combined_name",
method: "post",
...args,
});
},
async getLookupResults({
searchId, ...args
}) {
return this._makeRequest({
path: `/request-monitor/api-usage/${searchId}`,
...args,
});
},
async getSearchIds(args = {}) {
return this._makeRequest({
path: "/request-monitor/api-usage",
...args,
});
},
},
};
};
7 changes: 5 additions & 2 deletions components/epsy/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/epsy",
"version": "0.0.1",
"version": "0.1.0",
"description": "Pipedream Epsy Components",
"main": "epsy.app.mjs",
"keywords": [
Expand All @@ -11,5 +11,8 @@
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.0.3"
}
}
}
9 changes: 6 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading