diff --git a/components/engage/.gitignore b/components/engage/.gitignore deleted file mode 100644 index ec761ccab7595..0000000000000 --- a/components/engage/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -*.js -*.mjs -dist \ No newline at end of file diff --git a/components/engage/actions/add-customer/add-customer.mjs b/components/engage/actions/add-customer/add-customer.mjs new file mode 100644 index 0000000000000..b0bf73edeacc5 --- /dev/null +++ b/components/engage/actions/add-customer/add-customer.mjs @@ -0,0 +1,39 @@ +import app from "../../engage.app.mjs"; + +export default { + key: "engage-add-customer", + name: "Add Customer", + description: "Adds Customer to Accounts. [See the documentation](https://docs.engage.so/en-us/a/62bbdd015bfea4dca4834042-users#add-customer-to-accounts)", + version: "0.0.1", + type: "action", + props: { + app, + uid: { + propDefinition: [ + app, + "uid", + ], + }, + customerId: { + propDefinition: [ + app, + "customerId", + ], + }, + }, + async run({ $ }) { + const response = await this.app.addCustomer({ + $, + uid: this.uid, + data: { + accounts: [ + { + id: this.customerId, + }, + ], + }, + }); + $.export("$summary", "add-customer executed successfully"); + return response; + }, +}; diff --git a/components/engage/actions/add-event/add-event.mjs b/components/engage/actions/add-event/add-event.mjs new file mode 100644 index 0000000000000..04d718d0b0b97 --- /dev/null +++ b/components/engage/actions/add-event/add-event.mjs @@ -0,0 +1,56 @@ +import app from "../../engage.app.mjs"; + +export default { + key: "engage-add-event", + name: "Add Event", + description: "Adds user events to Engage. [See the documentation](https://docs.engage.so/en-us/a/62bbdd015bfea4dca4834042-users#track-user-event)", + version: "0.0.1", + type: "action", + props: { + app, + uid: { + propDefinition: [ + app, + "uid", + ], + }, + event: { + propDefinition: [ + app, + "event", + ], + }, + value: { + propDefinition: [ + app, + "value", + ], + }, + timestamp: { + propDefinition: [ + app, + "timestamp", + ], + }, + properties: { + propDefinition: [ + app, + "properties", + ], + }, + }, + async run({ $ }) { + const response = await this.app.addEvent({ + $, + uid: this.uid, + data: { + event: this.event, + value: this.value, + timestamp: this.timestamp, + properties: this.properties, + }, + }); + $.export("$summary", `Successfully added event. Status: ${response.status}`); + return response; + }, +}; diff --git a/components/engage/actions/create-user/create-user.mjs b/components/engage/actions/create-user/create-user.mjs new file mode 100644 index 0000000000000..baac26f1dacc1 --- /dev/null +++ b/components/engage/actions/create-user/create-user.mjs @@ -0,0 +1,63 @@ +import app from "../../engage.app.mjs"; + +export default { + key: "engage-create-user", + name: "Create User", + description: "Adds a new user to your Engage account. Use this to sync customer data with Engage. [See the documentation](https://docs.engage.so/en-us/a/62bbdd015bfea4dca4834042-users#create-a-user)", + version: "0.0.1", + type: "action", + props: { + app, + userId: { + propDefinition: [ + app, + "userId", + ], + }, + firstName: { + propDefinition: [ + app, + "firstName", + ], + }, + lastName: { + propDefinition: [ + app, + "lastName", + ], + }, + isAccount: { + propDefinition: [ + app, + "isAccount", + ], + }, + number: { + propDefinition: [ + app, + "number", + ], + }, + email: { + propDefinition: [ + app, + "email", + ], + }, + }, + async run({ $ }) { + const response = await this.app.createUser({ + $, + data: { + id: this.userId, + first_name: this.firstName, + last_name: this.lastName, + is_account: this.isAccount, + number: this.number, + email: this.email, + }, + }); + $.export("$summary", `Successfully created user with ID: ${response.id}`); + return response; + }, +}; diff --git a/components/engage/app/engage.app.ts b/components/engage/app/engage.app.ts deleted file mode 100644 index dae868909a2ed..0000000000000 --- a/components/engage/app/engage.app.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { defineApp } from "@pipedream/types"; - -export default defineApp({ - type: "app", - app: "engage", - propDefinitions: {}, - methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); - }, - }, -}); \ No newline at end of file diff --git a/components/engage/engage.app.mjs b/components/engage/engage.app.mjs new file mode 100644 index 0000000000000..0d0e634031eaa --- /dev/null +++ b/components/engage/engage.app.mjs @@ -0,0 +1,143 @@ +import { axios } from "@pipedream/platform"; + +export default { + type: "app", + app: "engage", + propDefinitions: { + userId: { + type: "string", + label: "User ID", + description: "Unique identifier for the user", + }, + firstName: { + type: "string", + label: "First name", + description: "The user's first name", + }, + lastName: { + type: "string", + label: "Last name", + description: "The user's last name", + }, + isAccount: { + type: "boolean", + label: "Is account", + description: "Indicates whether the user is also an account", + }, + number: { + type: "string", + label: "Number", + description: "A contact number associated with the user", + }, + email: { + type: "string", + label: "Email", + description: "The user's email address", + }, + uid: { + type: "string", + label: "User ID", + description: "ID of the user", + async options() { + const response = await this.getUsers(); + const usersIds = response.data; + return usersIds.map(({ + uid, first_name, last_name, + }) => ({ + label: `${first_name} ${last_name}`, + value: uid, + })); + }, + }, + customerId: { + type: "string", + label: "Customer ID", + description: "ID of the customer that will be added to the user", + async options() { + const response = await this.getUsers(); + const usersIds = response.data; + return usersIds.map(({ + uid, first_name, last_name, + }) => ({ + label: `${first_name} ${last_name}`, + value: uid, + })); + }, + }, + event: { + type: "string", + label: "Event", + description: "The name of the event associated with the user", + }, + timestamp: { + type: "string", + label: "Timestamp", + description: "Timestamp of the event. If none is provided, the current time is used", + optional: true, + }, + properties: { + type: "object", + label: "Properties", + description: "The properties of the event", + optional: true, + }, + value: { + type: "string", + label: "Value", + description: "The event value", + }, + }, + methods: { + _baseUrl() { + return "https://api.engage.so/v1"; + }, + async _makeRequest(opts = {}) { + const { + $ = this, + path, + auth, + ...otherOpts + } = opts; + return axios($, { + ...otherOpts, + url: this._baseUrl() + path, + auth: { + ...auth, + username: `${this.$auth.public_key}`, + password: `${this.$auth.secret_key}`, + }, + }); + }, + async createUser(args = {}) { + return this._makeRequest({ + path: "/users", + method: "post", + ...args, + }); + }, + async addCustomer({ + uid, ...args + }) { + return this._makeRequest({ + path: `/users/${uid}/accounts`, + method: "post", + ...args, + }); + }, + async addEvent({ + uid, ...args + }) { + return this._makeRequest({ + path: `/users/${uid}/events`, + method: "post", + ...args, + }); + }, + async getUsers(args = {}) { + return this._makeRequest({ + path: "/users", + ...args, + }); + }, + }, +}; diff --git a/components/engage/package.json b/components/engage/package.json index db85d0d637477..3b90508d3b9c1 100644 --- a/components/engage/package.json +++ b/components/engage/package.json @@ -1,16 +1,18 @@ { "name": "@pipedream/engage", - "version": "0.0.2", + "version": "0.1.0", "description": "Pipedream Engage Components", - "main": "dist/app/engage.app.mjs", + "main": "engage.app.mjs", "keywords": [ "pipedream", "engage" ], - "files": ["dist"], "homepage": "https://pipedream.com/apps/engage", "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^3.0.3" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 11be3e5e04962..0aba1735b2030 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -4012,7 +4012,11 @@ importers: specifier: ^1.2.1 version: 1.6.6 - components/engage: {} + components/engage: + dependencies: + '@pipedream/platform': + specifier: ^3.0.3 + version: 3.0.3 components/engagebay: dependencies: