Skip to content
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
68 changes: 68 additions & 0 deletions components/gainsight_px/actions/create-account/create-account.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import app from "../../gainsight_px.app.mjs";

export default {
key: "gainsight_px-create-account",
name: "Create Account",
description: "Create a new account with the given data. [See the documentation](https://gainsightpx.docs.apiary.io/#reference/accounts/v1accounts/create-account)",
version: "0.0.1",
type: "action",
props: {
app,
id: {
propDefinition: [
app,
"id",
],
},
name: {
propDefinition: [
app,
"name",
],
},
propertyKeys: {
propDefinition: [
app,
"propertyKeys",
],
},
countryName: {
propDefinition: [
app,
"countryName",
],
},
stateName: {
propDefinition: [
app,
"stateName",
],
},
city: {
propDefinition: [
app,
"city",
],
},
},

async run({ $ }) {
const response = await this.app.createAccount({
$,
data: {
id: this.id,
name: this.name,
propertyKeys: this.propertyKeys,
location: {
countryName: this.countryName,
stateName: this.stateName,
city: this.city,
},
},
});

$.export("$summary", `Successfully created account with the name '${this.name}'`);

return response;
},
Comment on lines +49 to +67
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 input validation.

While the implementation is functionally correct, consider adding:

  1. Basic error handling to provide clear error messages
  2. Input validation for the propertyKeys array
 async run({ $ }) {
+  // Validate propertyKeys if provided
+  if (this.propertyKeys && !Array.isArray(this.propertyKeys)) {
+    throw new Error("propertyKeys must be an array");
+  }
+
+  try {
     const response = await this.app.createAccount({
       $,
       data: {
         id: this.id,
         name: this.name,
         propertyKeys: this.propertyKeys,
         location: {
           countryName: this.countryName,
           stateName: this.stateName,
           city: this.city,
         },
       },
     });

     $.export("$summary", `Successfully created account with the name '${this.name}'`);

     return response;
+  } catch (error) {
+    throw new Error(`Failed to create account: ${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.createAccount({
$,
data: {
id: this.id,
name: this.name,
propertyKeys: this.propertyKeys,
location: {
countryName: this.countryName,
stateName: this.stateName,
city: this.city,
},
},
});
$.export("$summary", `Successfully created account with the name '${this.name}'`);
return response;
},
async run({ $ }) {
// Validate propertyKeys if provided
if (this.propertyKeys && !Array.isArray(this.propertyKeys)) {
throw new Error("propertyKeys must be an array");
}
try {
const response = await this.app.createAccount({
$,
data: {
id: this.id,
name: this.name,
propertyKeys: this.propertyKeys,
location: {
countryName: this.countryName,
stateName: this.stateName,
city: this.city,
},
},
});
$.export("$summary", `Successfully created account with the name '${this.name}'`);
return response;
} catch (error) {
throw new Error(`Failed to create account: ${error.message}`);
}
},

};
68 changes: 68 additions & 0 deletions components/gainsight_px/actions/create-user/create-user.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import app from "../../gainsight_px.app.mjs";

export default {
key: "gainsight_px-create-user",
name: "Create User",
description: "Creates a new user with the given data. [See the documentation](https://gainsightpx.docs.apiary.io/#reference/users/v1users/create-user)",
version: "0.0.1",
type: "action",
props: {
app,
id: {
propDefinition: [
app,
"id",
],
label: "Identify ID",
description: "Identifier of the user",
},
propertyKeys: {
propDefinition: [
app,
"propertyKeys",
],
},
type: {
propDefinition: [
app,
"type",
],
},
email: {
propDefinition: [
app,
"email",
],
},
firstName: {
propDefinition: [
app,
"firstName",
],
},
lastName: {
propDefinition: [
app,
"lastName",
],
},
},

async run({ $ }) {
const response = await this.app.createUser({
$,
data: {
identifyId: this.id,
propertyKeys: this.propertyKeys,
type: this.type,
email: this.email,
firstName: this.firstName,
lastName: this.lastName,
},
});

$.export("$summary", `Successfully created user with ID '${this.id}'`);

return response;
},
};
31 changes: 31 additions & 0 deletions components/gainsight_px/actions/delete-user/delete-user.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import app from "../../gainsight_px.app.mjs";

export default {
key: "gainsight_px-delete-user",
name: "Delete User",
description: "Deletes a user with he specified identifyId. [See the documentation](https://gainsightpx.docs.apiary.io/#reference/users/v1usersdelete/delete-user)",
version: "0.0.1",
type: "action",
Comment on lines +3 to +8
Copy link
Contributor

@coderabbitai coderabbitai bot Oct 30, 2024

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix typo in description

There's a typo in the description where "he" should be "the".

-  description: "Deletes a user with he specified identifyId. [See the documentation](https://gainsightpx.docs.apiary.io/#reference/users/v1usersdelete/delete-user)",
+  description: "Deletes a user with the specified identifyId. [See the documentation](https://gainsightpx.docs.apiary.io/#reference/users/v1usersdelete/delete-user)",
📝 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
export default {
key: "gainsight_px-delete-user",
name: "Delete User",
description: "Deletes a user with he specified identifyId. [See the documentation](https://gainsightpx.docs.apiary.io/#reference/users/v1usersdelete/delete-user)",
version: "0.0.1",
type: "action",
export default {
key: "gainsight_px-delete-user",
name: "Delete User",
description: "Deletes a user with the specified identifyId. [See the documentation](https://gainsightpx.docs.apiary.io/#reference/users/v1usersdelete/delete-user)",
version: "0.0.1",
type: "action",

Copy link
Collaborator

Choose a reason for hiding this comment

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

Fix the typo

Copy link
Contributor

Choose a reason for hiding this comment

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

@jcortes, here's the corrected description with the typo fixed:

description: "Deletes a user with the specified identifyId. [See the documentation](https://gainsightpx.docs.apiary.io/#reference/users/v1usersdelete/delete-user)",

Please update your code accordingly.

props: {
app,
identifyId: {
propDefinition: [
app,
"identifyId",
],
},
},

async run({ $ }) {
const response = await this.app.deleteUser({
$,
data: {
identifyId: this.identifyId,
},
});

$.export("$summary", `Successfully deleted user with ID ${this.identifyId}`);

return response;
},
};
8 changes: 8 additions & 0 deletions components/gainsight_px/common/contants.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export default {
USER_TYPES: [
"LEAD",
"USER",
"VISITOR",
"EMPTY_USER_TYPE",
],
};
128 changes: 124 additions & 4 deletions components/gainsight_px/gainsight_px.app.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,131 @@
import { axios } from "@pipedream/platform";
import contants from "./common/contants.mjs";
Copy link
Contributor

@coderabbitai coderabbitai bot Oct 30, 2024

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix typo in import statement: 'contants' should be 'constants'.

There is a typo in the import statement on line 2. The module name "contants" should be "constants" to correctly import the module.

Apply this diff to correct the import:

-import contants from "./common/contants.mjs";
+import constants from "./common/constants.mjs";
📝 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
import contants from "./common/contants.mjs";
import constants from "./common/constants.mjs";

Copy link
Collaborator

Choose a reason for hiding this comment

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

Fix the typo

Copy link
Contributor

Choose a reason for hiding this comment

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

@jcortes, thank you for fixing the typo!

(^• ω •^)


If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!


export default {
type: "app",
app: "gainsight_px",
propDefinitions: {},
propDefinitions: {
id: {
type: "string",
label: "ID",
description: "Unique identifier for the account",
},
name: {
type: "string",
label: "Name",
description: "Name associated with the account",
},
propertyKeys: {
type: "string[]",
label: "Property Keys",
description: "At least one tag key. The key can be found by clicking on `Administration` >`Set Up` > `Products` > Tag Key. For example: AP-xxx-1",
},
countryName: {
type: "string",
label: "County Name",
Copy link
Contributor

@coderabbitai coderabbitai bot Oct 30, 2024

Choose a reason for hiding this comment

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

⚠️ Potential issue

Correct label typo: 'County Name' should be 'Country Name'.

In the countryName property definition, the label is misspelled as "County Name" instead of "Country Name".

Apply this diff to fix the label:

label: "County Name",
+label: "Country Name",

Committable suggestion was skipped due to low confidence.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Fix typo

Copy link
Contributor

Choose a reason for hiding this comment

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

@jcortes Thanks for fixing the typo!

(^o^)/


If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!

description: "Name of the country associated with the account",
optional: true,
},
stateName: {
type: "string",
label: "State Name",
description: "Name of the State associated with the account",
optional: true,
},
city: {
type: "string",
label: "City",
description: "City associated with the account",
optional: true,
},
identifyId: {
type: "string",
label: "Identify ID",
description: "Identifier of the user",
async options() {
const response = await this.listUsers();
const userIds = response.users;
return userIds.map(({
identifyId, email,
}) => ({
label: email,
value: identifyId,
}));
},
Comment on lines +41 to +54
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 validation and error handling to identifyId options method.

The async options method for identifyId could fail silently if the API request fails. Consider adding validation for the response data and proper error handling.

 async options() {
+  try {
     const response = await this.listUsers();
+    if (!response?.users) {
+      console.log("Invalid response format from listUsers");
+      return [];
+    }
     const userIds = response.users;
     return userIds.map(({
       identifyId, email,
     }) => ({
       label: email,
       value: identifyId,
     }));
+  } catch (error) {
+    console.log("Error fetching user options:", error);
+    return [];
+  }
 }
📝 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
identifyId: {
type: "string",
label: "Identify ID",
description: "Identifier of the user",
async options() {
const response = await this.listUsers();
const userIds = response.users;
return userIds.map(({
identifyId, email,
}) => ({
label: email,
value: identifyId,
}));
},
identifyId: {
type: "string",
label: "Identify ID",
description: "Identifier of the user",
async options() {
try {
const response = await this.listUsers();
if (!response?.users) {
console.log("Invalid response format from listUsers");
return [];
}
const userIds = response.users;
return userIds.map(({
identifyId, email,
}) => ({
label: email,
value: identifyId,
}));
} catch (error) {
console.log("Error fetching user options:", error);
return [];
}
},

},
type: {
type: "string",
label: "User Type",
description: "Type of the user",
options: contants.USER_TYPES,
Copy link
Contributor

@coderabbitai coderabbitai bot Oct 30, 2024

Choose a reason for hiding this comment

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

⚠️ Potential issue

Update variable reference: 'contants.USER_TYPES' should be 'constants.USER_TYPES'.

The options for the type property are referencing contants.USER_TYPES, but "contants" is misspelled. It should be constants.USER_TYPES to correctly access the user types.

Apply this diff to correct the variable reference:

options: contants.USER_TYPES,
+options: constants.USER_TYPES,

Committable suggestion was skipped due to low confidence.

Copy link
Collaborator

Choose a reason for hiding this comment

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

fix typo

Copy link
Contributor

Choose a reason for hiding this comment

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

@jcortes, thanks for fixing the typo!

((^_^)/)


If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!

optional: true,
},
email: {
type: "string",
label: "Email",
description: "Email of the user",
optional: true,
},
firstName: {
type: "string",
label: "First Name",
description: "First Name of the user",
optional: true,
},
lastName: {
type: "string",
label: "Last Name",
description: "Last Name of the user",
optional: true,
},
},
methods: {
// this.$auth contains connected account data
authKeys() {
console.log(Object.keys(this.$auth));
_baseUrl() {
return this.$auth.base_endpoint;
},
async _makeRequest(opts = {}) {
const {
$ = this,
path,
headers,
...otherOpts
} = opts;
return axios($, {
...otherOpts,
url: this._baseUrl() + path,
headers: {
...headers,
"X-APTRINSIC-API-KEY": `${this.$auth.api_key}`,
"Accept": "application/json",
},
});
},
Comment on lines +86 to +102
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

Enhance request handling with proper headers and error management.

The _makeRequest method needs improvements for better request handling:

  1. Add Content-Type header for POST/DELETE requests
  2. Add proper error handling
  3. Validate the base URL
 async _makeRequest(opts = {}) {
+  if (!this._baseUrl()) {
+    throw new Error("Base endpoint is not configured");
+  }
   const {
     $ = this,
     path,
     headers,
     ...otherOpts
   } = opts;
+  const method = otherOpts.method?.toLowerCase();
+  try {
     return axios($, {
       ...otherOpts,
       url: this._baseUrl() + path,
       headers: {
         ...headers,
         "X-APTRINSIC-API-KEY": `${this.$auth.api_key}`,
         "Accept": "application/json",
+        ...(["post", "delete"].includes(method) && {
+          "Content-Type": "application/json"
+        }),
       },
     });
+  } catch (error) {
+    console.error("API request failed:", 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 _makeRequest(opts = {}) {
const {
$ = this,
path,
headers,
...otherOpts
} = opts;
return axios($, {
...otherOpts,
url: this._baseUrl() + path,
headers: {
...headers,
"X-APTRINSIC-API-KEY": `${this.$auth.api_key}`,
"Accept": "application/json",
},
});
},
async _makeRequest(opts = {}) {
if (!this._baseUrl()) {
throw new Error("Base endpoint is not configured");
}
const {
$ = this,
path,
headers,
...otherOpts
} = opts;
const method = otherOpts.method?.toLowerCase();
try {
return axios($, {
...otherOpts,
url: this._baseUrl() + path,
headers: {
...headers,
"X-APTRINSIC-API-KEY": `${this.$auth.api_key}`,
"Accept": "application/json",
...(["post", "delete"].includes(method) && {
"Content-Type": "application/json"
}),
},
});
} catch (error) {
console.error("API request failed:", error.message);
throw error;
}
},

async createAccount(args = {}) {
return this._makeRequest({
path: "/accounts",
method: "post",
...args,
});
},
async deleteUser(args = {}) {
return this._makeRequest({
path: "/users/delete",
method: "delete",
...args,
});
},
async createUser(args = {}) {
return this._makeRequest({
path: "/users",
method: "post",
...args,
});
},
async listUsers(args = {}) {
return this._makeRequest({
path: "/users",
...args,
});
},
},
};
7 changes: 5 additions & 2 deletions components/gainsight_px/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/gainsight_px",
"version": "0.0.1",
"version": "0.1.0",
"description": "Pipedream Gainsight PX Components",
"main": "gainsight_px.app.mjs",
"keywords": [
Expand All @@ -11,5 +11,8 @@
"author": "Pipedream <support@pipedream.com> (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