From fa1cfcf321ecaecf6bfe0f31724328e18ee2327b Mon Sep 17 00:00:00 2001 From: Lucas Caresia Date: Wed, 30 Oct 2024 12:08:45 -0300 Subject: [PATCH 1/6] Added actions --- .../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 | 126 +++++++++++++++++- components/gainsight_px/package.json | 7 +- 6 files changed, 302 insertions(+), 6 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..a0a2ca42c82de --- /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 Memory", + 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..16337ab619357 --- /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..887d97a0f5657 --- /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..f05add1532b3c --- /dev/null +++ b/components/gainsight_px/common/contants.mjs @@ -0,0 +1,8 @@ +export default { + USER_TYPES: [ + "LEAD", + "USER", + "VISITOR", + "EMPTY_USER_TYPE", + ], +} \ No newline at end of file diff --git a/components/gainsight_px/gainsight_px.app.mjs b/components/gainsight_px/gainsight_px.app.mjs index a871bea2efb9a..5585396389792 100644 --- a/components/gainsight_px/gainsight_px.app.mjs +++ b/components/gainsight_px/gainsight_px.app.mjs @@ -1,11 +1,129 @@ +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 property key. The key can be found by clicking on `Administration`, `Set Up` and `Products`", + }, + 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 +} From 5661df60f3004d139f4e1657c3c652d27365f7bb Mon Sep 17 00:00:00 2001 From: Leo Vu Date: Thu, 31 Oct 2024 09:09:29 +0700 Subject: [PATCH 2/6] Update components/gainsight_px/gainsight_px.app.mjs --- components/gainsight_px/gainsight_px.app.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/gainsight_px/gainsight_px.app.mjs b/components/gainsight_px/gainsight_px.app.mjs index 5585396389792..1a6842d4ee18f 100644 --- a/components/gainsight_px/gainsight_px.app.mjs +++ b/components/gainsight_px/gainsight_px.app.mjs @@ -18,7 +18,7 @@ export default { propertyKeys: { type: "string[]", label: "Property Keys", - description: "At least one property key. The key can be found by clicking on `Administration`, `Set Up` and `Products`", + 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", From 8b1ef6d07986129a90dca171f483e089fe4309cd Mon Sep 17 00:00:00 2001 From: Leo Vu Date: Thu, 31 Oct 2024 09:11:37 +0700 Subject: [PATCH 3/6] Update components/gainsight_px/actions/create-account/create-account.mjs --- .../gainsight_px/actions/create-account/create-account.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/gainsight_px/actions/create-account/create-account.mjs b/components/gainsight_px/actions/create-account/create-account.mjs index a0a2ca42c82de..9f7007d55121a 100644 --- a/components/gainsight_px/actions/create-account/create-account.mjs +++ b/components/gainsight_px/actions/create-account/create-account.mjs @@ -2,7 +2,7 @@ import app from "../../gainsight_px.app.mjs"; export default { key: "gainsight_px-create-account", - name: "Create Memory", + 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", From 17ba9a542ea7e61e8afe59ed28b2c0dc4fcc971b Mon Sep 17 00:00:00 2001 From: Lucas Caresia Date: Tue, 5 Nov 2024 13:00:03 -0300 Subject: [PATCH 4/6] pnpm-lock --- pnpm-lock.yaml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index dfc0fe9556e70..731a9ae7ae3bd 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -3816,7 +3816,10 @@ importers: specifiers: {} components/gainsight_px: - specifiers: {} + specifiers: + '@pipedream/platform': ^3.0.3 + dependencies: + '@pipedream/platform': 3.0.3 components/gami5d: specifiers: @@ -23952,7 +23955,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==} @@ -36639,7 +36642,7 @@ packages: dev: false /verror/1.10.0: - resolution: {integrity: sha1-OhBcoXBTr1XW4nDB+CiGguGNpAA=} + resolution: {integrity: sha512-ZZKSmDAEFOijERBLkmYfJ+vmk3w+7hOLYDNkRCuRuMJGEmqYNCNLyBBFwWKVMhfwaEF3WOd0Zlw86U/WC/+nYw==} engines: {'0': node >=0.6.0} dependencies: assert-plus: 1.0.0 From 6d27cdc3e9b50f4008cdddeb86e81a12b4a37736 Mon Sep 17 00:00:00 2001 From: Lucas Caresia Date: Tue, 5 Nov 2024 13:00:03 -0300 Subject: [PATCH 5/6] pnpm-lock --- .../actions/create-account/create-account.mjs | 28 +++++++++---------- .../actions/create-user/create-user.mjs | 22 +++++++-------- .../actions/delete-user/delete-user.mjs | 2 +- components/gainsight_px/gainsight_px.app.mjs | 16 ++++++----- pnpm-lock.yaml | 9 ++++-- 5 files changed, 41 insertions(+), 36 deletions(-) diff --git a/components/gainsight_px/actions/create-account/create-account.mjs b/components/gainsight_px/actions/create-account/create-account.mjs index 9f7007d55121a..02d48e1979306 100644 --- a/components/gainsight_px/actions/create-account/create-account.mjs +++ b/components/gainsight_px/actions/create-account/create-account.mjs @@ -11,38 +11,38 @@ export default { id: { propDefinition: [ app, - "id" - ] + "id", + ], }, name: { propDefinition: [ app, - "name" - ] + "name", + ], }, propertyKeys: { propDefinition: [ app, - "propertyKeys" - ] + "propertyKeys", + ], }, countryName: { propDefinition: [ app, - "countryName" - ] + "countryName", + ], }, stateName: { propDefinition: [ app, - "stateName" - ] + "stateName", + ], }, city: { propDefinition: [ app, - "city" - ] + "city", + ], }, }, @@ -57,8 +57,8 @@ export default { countryName: this.countryName, stateName: this.stateName, city: this.city, - } - } + }, + }, }); $.export("$summary", `Successfully created account with the name '${this.name}'`); diff --git a/components/gainsight_px/actions/create-user/create-user.mjs b/components/gainsight_px/actions/create-user/create-user.mjs index 16337ab619357..1112a0987d22f 100644 --- a/components/gainsight_px/actions/create-user/create-user.mjs +++ b/components/gainsight_px/actions/create-user/create-user.mjs @@ -19,32 +19,32 @@ export default { propertyKeys: { propDefinition: [ app, - "propertyKeys" - ] + "propertyKeys", + ], }, type: { propDefinition: [ app, - "type" - ] + "type", + ], }, email: { propDefinition: [ app, - "email" - ] + "email", + ], }, firstName: { propDefinition: [ app, - "firstName" - ] + "firstName", + ], }, lastName: { propDefinition: [ app, - "lastName" - ] + "lastName", + ], }, }, @@ -58,7 +58,7 @@ export default { email: this.email, firstName: this.firstName, lastName: this.lastName, - } + }, }); $.export("$summary", `Successfully created user with ID '${this.id}'`); diff --git a/components/gainsight_px/actions/delete-user/delete-user.mjs b/components/gainsight_px/actions/delete-user/delete-user.mjs index 887d97a0f5657..2e5471c93770f 100644 --- a/components/gainsight_px/actions/delete-user/delete-user.mjs +++ b/components/gainsight_px/actions/delete-user/delete-user.mjs @@ -21,7 +21,7 @@ export default { $, data: { identifyId: this.identifyId, - } + }, }); $.export("$summary", `Successfully deleted user with ID ${this.identifyId}`); diff --git a/components/gainsight_px/gainsight_px.app.mjs b/components/gainsight_px/gainsight_px.app.mjs index 1a6842d4ee18f..ba14f54206449 100644 --- a/components/gainsight_px/gainsight_px.app.mjs +++ b/components/gainsight_px/gainsight_px.app.mjs @@ -45,11 +45,13 @@ export default { async options() { const response = await this.listUsers(); const userIds = response.users; - return userIds.map(({ identifyId, email }) => ({ + return userIds.map(({ + identifyId, email, + }) => ({ label: email, value: identifyId, })); - } + }, }, type: { type: "string", @@ -94,34 +96,34 @@ export default { headers: { ...headers, "X-APTRINSIC-API-KEY": `${this.$auth.api_key}`, - "Accept": `application/json`, + "Accept": "application/json", }, }); }, async createAccount(args = {}) { return this._makeRequest({ - path: `/accounts`, + path: "/accounts", method: "post", ...args, }); }, async deleteUser(args = {}) { return this._makeRequest({ - path: `/users/delete`, + path: "/users/delete", method: "delete", ...args, }); }, async createUser(args = {}) { return this._makeRequest({ - path: `/users`, + path: "/users", method: "post", ...args, }); }, async listUsers(args = {}) { return this._makeRequest({ - path: `/users`, + path: "/users", ...args, }); }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index dfc0fe9556e70..731a9ae7ae3bd 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -3816,7 +3816,10 @@ importers: specifiers: {} components/gainsight_px: - specifiers: {} + specifiers: + '@pipedream/platform': ^3.0.3 + dependencies: + '@pipedream/platform': 3.0.3 components/gami5d: specifiers: @@ -23952,7 +23955,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==} @@ -36639,7 +36642,7 @@ packages: dev: false /verror/1.10.0: - resolution: {integrity: sha1-OhBcoXBTr1XW4nDB+CiGguGNpAA=} + resolution: {integrity: sha512-ZZKSmDAEFOijERBLkmYfJ+vmk3w+7hOLYDNkRCuRuMJGEmqYNCNLyBBFwWKVMhfwaEF3WOd0Zlw86U/WC/+nYw==} engines: {'0': node >=0.6.0} dependencies: assert-plus: 1.0.0 From 97b96f621976ff6c17d1bd497f7a6fb2bd306ec3 Mon Sep 17 00:00:00 2001 From: Lucas Caresia Date: Tue, 5 Nov 2024 13:30:55 -0300 Subject: [PATCH 6/6] Fixing action name --- components/gainsight_px/common/contants.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/gainsight_px/common/contants.mjs b/components/gainsight_px/common/contants.mjs index f05add1532b3c..b642cd32c903a 100644 --- a/components/gainsight_px/common/contants.mjs +++ b/components/gainsight_px/common/contants.mjs @@ -5,4 +5,4 @@ export default { "VISITOR", "EMPTY_USER_TYPE", ], -} \ No newline at end of file +};