From 9230bf1fa53ed48d97480f8e72958edc0c503670 Mon Sep 17 00:00:00 2001 From: Lucas Caresia Date: Thu, 7 Nov 2024 11:41:39 -0300 Subject: [PATCH] [Components] gainsight_px #14359 (#14467) * Added actions * Update components/gainsight_px/gainsight_px.app.mjs * Update components/gainsight_px/actions/create-account/create-account.mjs * pnpm-lock * pnpm-lock * Fixing action name --------- Co-authored-by: Leo Vu --- .../actions/create-account/create-account.mjs | 68 ++++++++++ .../actions/create-user/create-user.mjs | 68 ++++++++++ .../actions/delete-user/delete-user.mjs | 31 +++++ components/gainsight_px/common/contants.mjs | 8 ++ components/gainsight_px/gainsight_px.app.mjs | 128 +++++++++++++++++- components/gainsight_px/package.json | 7 +- pnpm-lock.yaml | 7 +- 7 files changed, 309 insertions(+), 8 deletions(-) create mode 100644 components/gainsight_px/actions/create-account/create-account.mjs create mode 100644 components/gainsight_px/actions/create-user/create-user.mjs create mode 100644 components/gainsight_px/actions/delete-user/delete-user.mjs create mode 100644 components/gainsight_px/common/contants.mjs diff --git a/components/gainsight_px/actions/create-account/create-account.mjs b/components/gainsight_px/actions/create-account/create-account.mjs new file mode 100644 index 0000000000000..02d48e1979306 --- /dev/null +++ b/components/gainsight_px/actions/create-account/create-account.mjs @@ -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; + }, +}; diff --git a/components/gainsight_px/actions/create-user/create-user.mjs b/components/gainsight_px/actions/create-user/create-user.mjs new file mode 100644 index 0000000000000..1112a0987d22f --- /dev/null +++ b/components/gainsight_px/actions/create-user/create-user.mjs @@ -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; + }, +}; diff --git a/components/gainsight_px/actions/delete-user/delete-user.mjs b/components/gainsight_px/actions/delete-user/delete-user.mjs new file mode 100644 index 0000000000000..2e5471c93770f --- /dev/null +++ b/components/gainsight_px/actions/delete-user/delete-user.mjs @@ -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", + 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; + }, +}; diff --git a/components/gainsight_px/common/contants.mjs b/components/gainsight_px/common/contants.mjs new file mode 100644 index 0000000000000..b642cd32c903a --- /dev/null +++ b/components/gainsight_px/common/contants.mjs @@ -0,0 +1,8 @@ +export default { + USER_TYPES: [ + "LEAD", + "USER", + "VISITOR", + "EMPTY_USER_TYPE", + ], +}; diff --git a/components/gainsight_px/gainsight_px.app.mjs b/components/gainsight_px/gainsight_px.app.mjs index a871bea2efb9a..ba14f54206449 100644 --- a/components/gainsight_px/gainsight_px.app.mjs +++ b/components/gainsight_px/gainsight_px.app.mjs @@ -1,11 +1,131 @@ +import { axios } from "@pipedream/platform"; +import contants from "./common/contants.mjs"; + 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", + 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, + })); + }, + }, + type: { + type: "string", + label: "User Type", + description: "Type of the user", + options: contants.USER_TYPES, + 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", + }, + }); + }, + 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, + }); }, }, }; diff --git a/components/gainsight_px/package.json b/components/gainsight_px/package.json index d206532557469..0e0afb17bbd18 100644 --- a/components/gainsight_px/package.json +++ b/components/gainsight_px/package.json @@ -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": [ @@ -11,5 +11,8 @@ "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^3.0.3" } -} \ No newline at end of file +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index eafc2172e580d..5cc3b372e7b90 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -3845,7 +3845,10 @@ importers: '@pipedream/platform': 3.0.3 components/gainsight_px: - specifiers: {} + specifiers: + '@pipedream/platform': ^3.0.3 + dependencies: + '@pipedream/platform': 3.0.3 components/gami5d: specifiers: @@ -24020,7 +24023,7 @@ packages: dev: false /concat-map/0.0.1: - resolution: {integrity: sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=} + resolution: {integrity: sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==} /concat-stream/2.0.0: resolution: {integrity: sha512-MWufYdFw53ccGjCA+Ol7XJYpAlW6/prSMzuPOTRnJGcGzuhLn4Scrz7qf6o8bROZ514ltazcIFJZevcfbo0x7A==}