- 
                Notifications
    You must be signed in to change notification settings 
- Fork 5.5k
[Components] engage #13410 #15656
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Components] engage #13410 #15656
Changes from all commits
bd32636
              5f4d07e
              3a17f66
              5cc90e5
              42f25ed
              7bfead4
              80ddaaf
              File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -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; | ||
| }, | ||
| }; | ||
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -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; | ||
| }, | ||
| }; | 
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -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; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 
      Comment on lines
    
      +48
     to 
      +62
    
   There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add input validation and error handling. The   async run({ $ }) {
+  // Validate required fields
+  if (!this.userId || !this.email) {
+    throw new Error("User ID and email are required fields");
+  }
+
+  try {
     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;
+  } catch (error) {
+    throw new Error(`Failed to create user: ${error.message}`);
+  }
 }📝 Committable suggestion
 
        Suggested change
       
 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
This file was deleted.
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -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}`, | ||
| }, | ||
| }); | ||
| }, | ||
| 
      Comment on lines
    
      +94
     to 
      +110
    
   There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Consider adding error handling and request validation. The  
  async _makeRequest(opts = {}) {
   const {
     $ = this,
     path,
     auth,
     ...otherOpts
   } = opts;
+  if (!path) {
+    throw new Error("Path is required");
+  }
+  try {
     return axios($, {
       ...otherOpts,
       url: this._baseUrl() + path,
       auth: {
         ...auth,
         username: `${this.$auth.public_key}`,
         password: `${this.$auth.secret_key}`,
       },
     });
+  } catch (error) {
+    const errorMessage = error.response?.data?.message || error.message;
+    throw new Error(`Request failed: ${errorMessage}`);
+  }
 }
 | ||
| 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, | ||
| }); | ||
| }, | ||
| }, | ||
| }; | ||
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -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 <[email protected]> (https://pipedream.com/)", | ||
| "publishConfig": { | ||
| "access": "public" | ||
| }, | ||
| "dependencies": { | ||
| "@pipedream/platform": "^3.0.3" | ||
| } | ||
| } | 
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add validation for customer ID and improve error handling.
The
runmethod should validate inputs and handle potential errors from the API call.async run({ $ }) { + if (!this.uid || !this.customerId) { + throw new Error("User ID and Customer ID are required"); + } + + try { const response = await this.app.addCustomer({ $, uid: this.uid, data: { accounts: [ { id: this.customerId, }, ], }, }); $.export("$summary", "add-customer executed successfully"); return response; + } catch (error) { + throw new Error(`Failed to add customer: ${error.message}`); + } }📝 Committable suggestion